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; |
Pekka Paalanen | 9d1613e | 2011-11-25 12:09:16 +0200 | [diff] [blame] | 110 | |
Kristian Høgsberg | 8334bc1 | 2012-01-03 10:29:47 -0500 | [diff] [blame] | 111 | struct weston_surface *surface; |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 112 | struct weston_view *view; |
Jason Ekstrand | 918f2dd | 2013-12-02 21:01:53 -0600 | [diff] [blame] | 113 | int32_t last_width, last_height; |
Pekka Paalanen | 9d1613e | 2011-11-25 12:09:16 +0200 | [diff] [blame] | 114 | struct wl_listener surface_destroy_listener; |
Kristian Høgsberg | 160fe75 | 2014-03-11 10:19:10 -0700 | [diff] [blame] | 115 | struct wl_listener resource_destroy_listener; |
| 116 | |
Kristian Høgsberg | 8150b19 | 2012-06-27 10:22:58 -0400 | [diff] [blame] | 117 | struct weston_surface *parent; |
Philip Withnall | 648a4dd | 2013-11-25 18:01:44 +0000 | [diff] [blame] | 118 | struct wl_list children_list; /* child surfaces of this one */ |
| 119 | struct wl_list children_link; /* sibling surfaces of this one */ |
Tiago Vignatti | be14326 | 2012-04-16 17:31:41 +0300 | [diff] [blame] | 120 | struct desktop_shell *shell; |
Pekka Paalanen | 57da4a8 | 2011-11-23 16:42:16 +0200 | [diff] [blame] | 121 | |
Kristian Høgsberg | c8f8dd8 | 2013-12-05 23:20:33 -0800 | [diff] [blame] | 122 | enum shell_surface_type type; |
Kristian Høgsberg | e7afd91 | 2012-05-02 09:47:44 -0400 | [diff] [blame] | 123 | char *title, *class; |
Kristian Høgsberg | d2abb83 | 2011-11-23 10:52:40 -0500 | [diff] [blame] | 124 | int32_t saved_x, saved_y; |
Rafael Antognolli | 3c4e3f7 | 2013-12-03 15:35:46 -0200 | [diff] [blame] | 125 | int32_t saved_width, saved_height; |
Alex Wu | 4539b08 | 2012-03-01 12:57:46 +0800 | [diff] [blame] | 126 | bool saved_position_valid; |
Rafael Antognolli | 3c4e3f7 | 2013-12-03 15:35:46 -0200 | [diff] [blame] | 127 | bool saved_size_valid; |
Alex Wu | 7bcb8bd | 2012-04-27 09:07:24 +0800 | [diff] [blame] | 128 | bool saved_rotation_valid; |
Kristian Høgsberg | c85f1d4 | 2013-10-24 16:52:00 -0700 | [diff] [blame] | 129 | int unresponsive, grabbed; |
Kristian Høgsberg | 44cd196 | 2014-02-05 21:36:04 -0800 | [diff] [blame] | 130 | uint32_t resize_edges; |
Benjamin Franzke | d0f79ab | 2011-11-22 12:43:52 +0100 | [diff] [blame] | 131 | |
Kristian Høgsberg | b3cca0a | 2012-01-04 22:19:14 -0500 | [diff] [blame] | 132 | struct { |
Pekka Paalanen | 460099f | 2012-01-20 16:48:25 +0200 | [diff] [blame] | 133 | struct weston_transform transform; |
Kristian Høgsberg | 765e27b | 2012-01-27 13:36:13 -0500 | [diff] [blame] | 134 | struct weston_matrix rotation; |
Pekka Paalanen | 460099f | 2012-01-20 16:48:25 +0200 | [diff] [blame] | 135 | } rotation; |
| 136 | |
| 137 | struct { |
Giulio Camuffo | 5085a75 | 2013-03-25 21:42:45 +0100 | [diff] [blame] | 138 | struct wl_list grab_link; |
Kristian Høgsberg | b3cca0a | 2012-01-04 22:19:14 -0500 | [diff] [blame] | 139 | int32_t x, y; |
Giulio Camuffo | 5085a75 | 2013-03-25 21:42:45 +0100 | [diff] [blame] | 140 | struct shell_seat *shseat; |
Kristian Høgsberg | 3730f36 | 2012-04-13 12:40:07 -0400 | [diff] [blame] | 141 | uint32_t serial; |
Kristian Høgsberg | b3cca0a | 2012-01-04 22:19:14 -0500 | [diff] [blame] | 142 | } popup; |
| 143 | |
Alex Wu | 4539b08 | 2012-03-01 12:57:46 +0800 | [diff] [blame] | 144 | struct { |
Tiago Vignatti | 52e598c | 2012-05-07 15:23:08 +0300 | [diff] [blame] | 145 | int32_t x, y; |
Tiago Vignatti | 491bac1 | 2012-05-18 16:37:43 -0400 | [diff] [blame] | 146 | uint32_t flags; |
Tiago Vignatti | 52e598c | 2012-05-07 15:23:08 +0300 | [diff] [blame] | 147 | } transient; |
| 148 | |
| 149 | struct { |
Alex Wu | 4539b08 | 2012-03-01 12:57:46 +0800 | [diff] [blame] | 150 | enum wl_shell_surface_fullscreen_method type; |
| 151 | struct weston_transform transform; /* matrix from x, y */ |
| 152 | uint32_t framerate; |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 153 | struct weston_view *black_view; |
Alex Wu | 4539b08 | 2012-03-01 12:57:46 +0800 | [diff] [blame] | 154 | } fullscreen; |
| 155 | |
Jonas Ådahl | 62fcd04 | 2012-06-13 00:01:23 +0200 | [diff] [blame] | 156 | struct weston_transform workspace_transform; |
| 157 | |
Kristian Høgsberg | 1cbf326 | 2012-02-17 23:49:07 -0500 | [diff] [blame] | 158 | struct weston_output *fullscreen_output; |
Kristian Høgsberg | 8334bc1 | 2012-01-03 10:29:47 -0500 | [diff] [blame] | 159 | struct weston_output *output; |
Benjamin Franzke | d0f79ab | 2011-11-22 12:43:52 +0100 | [diff] [blame] | 160 | struct wl_list link; |
Kristian Høgsberg | a61ca06 | 2012-05-22 16:05:52 -0400 | [diff] [blame] | 161 | |
| 162 | const struct weston_shell_client *client; |
Rafael Antognolli | 03b1659 | 2013-12-03 15:35:42 -0200 | [diff] [blame] | 163 | |
Jasper St. Pierre | 6458ec3 | 2014-04-11 16:00:31 -0700 | [diff] [blame] | 164 | struct surface_state { |
Rafael Antognolli | 03b1659 | 2013-12-03 15:35:42 -0200 | [diff] [blame] | 165 | bool maximized; |
| 166 | bool fullscreen; |
Rafael Antognolli | ed207b4 | 2013-12-03 15:35:43 -0200 | [diff] [blame] | 167 | bool relative; |
Emilio Pozuelo Monfort | 9e7c759 | 2014-01-30 14:01:10 +0100 | [diff] [blame] | 168 | bool lowered; |
Jasper St. Pierre | 8c6aa45 | 2014-02-08 18:29:49 -0500 | [diff] [blame] | 169 | } state, next_state, requested_state; /* surface states */ |
Rafael Antognolli | 03b1659 | 2013-12-03 15:35:42 -0200 | [diff] [blame] | 170 | bool state_changed; |
Jasper St. Pierre | 8c6aa45 | 2014-02-08 18:29:49 -0500 | [diff] [blame] | 171 | bool state_requested; |
Jasper St. Pierre | faf27a9 | 2013-12-09 17:36:28 -0500 | [diff] [blame] | 172 | |
Kristian Høgsberg | ae356ae | 2014-04-29 16:03:54 -0700 | [diff] [blame] | 173 | struct { |
Jasper St. Pierre | ccf48fb | 2014-05-02 10:21:38 -0400 | [diff] [blame] | 174 | int32_t x, y, width, height; |
| 175 | } geometry, next_geometry; |
| 176 | bool has_set_geometry, has_next_geometry; |
Kristian Høgsberg | ae356ae | 2014-04-29 16:03:54 -0700 | [diff] [blame] | 177 | |
Jasper St. Pierre | faf27a9 | 2013-12-09 17:36:28 -0500 | [diff] [blame] | 178 | int focus_count; |
Pekka Paalanen | 56cdea9 | 2011-11-23 16:14:12 +0200 | [diff] [blame] | 179 | }; |
| 180 | |
Ander Conselvan de Oliveira | fe0444a | 2012-04-04 17:48:05 +0300 | [diff] [blame] | 181 | struct shell_grab { |
Kristian Høgsberg | 02bbabb | 2013-05-06 22:15:05 -0400 | [diff] [blame] | 182 | struct weston_pointer_grab grab; |
Ander Conselvan de Oliveira | fe0444a | 2012-04-04 17:48:05 +0300 | [diff] [blame] | 183 | struct shell_surface *shsurf; |
| 184 | struct wl_listener shsurf_destroy_listener; |
| 185 | }; |
| 186 | |
Rusty Lynch | 1084da5 | 2013-08-15 09:10:08 -0700 | [diff] [blame] | 187 | struct shell_touch_grab { |
| 188 | struct weston_touch_grab grab; |
| 189 | struct shell_surface *shsurf; |
| 190 | struct wl_listener shsurf_destroy_listener; |
| 191 | struct weston_touch *touch; |
| 192 | }; |
| 193 | |
Ander Conselvan de Oliveira | fe0444a | 2012-04-04 17:48:05 +0300 | [diff] [blame] | 194 | struct weston_move_grab { |
| 195 | struct shell_grab base; |
Daniel Stone | 103db7f | 2012-05-08 17:17:55 +0100 | [diff] [blame] | 196 | wl_fixed_t dx, dy; |
Kristian Høgsberg | ae356ae | 2014-04-29 16:03:54 -0700 | [diff] [blame] | 197 | int client_initiated; |
Kristian Høgsberg | 4cca349 | 2011-01-18 07:53:49 -0500 | [diff] [blame] | 198 | }; |
| 199 | |
Rusty Lynch | 1084da5 | 2013-08-15 09:10:08 -0700 | [diff] [blame] | 200 | struct weston_touch_move_grab { |
| 201 | struct shell_touch_grab base; |
Kristian Høgsberg | 8e80a31 | 2014-01-17 15:18:10 -0800 | [diff] [blame] | 202 | int active; |
Rusty Lynch | 1084da5 | 2013-08-15 09:10:08 -0700 | [diff] [blame] | 203 | wl_fixed_t dx, dy; |
| 204 | }; |
| 205 | |
Pekka Paalanen | 460099f | 2012-01-20 16:48:25 +0200 | [diff] [blame] | 206 | struct rotate_grab { |
Ander Conselvan de Oliveira | fe0444a | 2012-04-04 17:48:05 +0300 | [diff] [blame] | 207 | struct shell_grab base; |
Kristian Høgsberg | 765e27b | 2012-01-27 13:36:13 -0500 | [diff] [blame] | 208 | struct weston_matrix rotation; |
Pekka Paalanen | 460099f | 2012-01-20 16:48:25 +0200 | [diff] [blame] | 209 | struct { |
John Kåre Alsaker | 490d02a | 2012-09-30 02:57:21 +0200 | [diff] [blame] | 210 | float x; |
| 211 | float y; |
Pekka Paalanen | 460099f | 2012-01-20 16:48:25 +0200 | [diff] [blame] | 212 | } center; |
| 213 | }; |
| 214 | |
Giulio Camuffo | 5085a75 | 2013-03-25 21:42:45 +0100 | [diff] [blame] | 215 | struct shell_seat { |
| 216 | struct weston_seat *seat; |
| 217 | struct wl_listener seat_destroy_listener; |
Jasper St. Pierre | faf27a9 | 2013-12-09 17:36:28 -0500 | [diff] [blame] | 218 | struct weston_surface *focused_surface; |
Giulio Camuffo | 5085a75 | 2013-03-25 21:42:45 +0100 | [diff] [blame] | 219 | |
Jason Ekstrand | 024177c | 2014-04-21 19:42:58 -0500 | [diff] [blame] | 220 | struct wl_listener caps_changed_listener; |
| 221 | struct wl_listener pointer_focus_listener; |
| 222 | struct wl_listener keyboard_focus_listener; |
| 223 | |
Giulio Camuffo | 5085a75 | 2013-03-25 21:42:45 +0100 | [diff] [blame] | 224 | struct { |
Kristian Høgsberg | 02bbabb | 2013-05-06 22:15:05 -0400 | [diff] [blame] | 225 | struct weston_pointer_grab grab; |
Giulio Camuffo | 5085a75 | 2013-03-25 21:42:45 +0100 | [diff] [blame] | 226 | struct wl_list surfaces_list; |
| 227 | struct wl_client *client; |
| 228 | int32_t initial_up; |
| 229 | } popup_grab; |
| 230 | }; |
| 231 | |
Kristian Høgsberg | 2bff94e | 2014-02-11 12:22:51 -0800 | [diff] [blame] | 232 | struct shell_client { |
| 233 | struct wl_resource *resource; |
| 234 | struct wl_client *client; |
| 235 | struct desktop_shell *shell; |
| 236 | struct wl_listener destroy_listener; |
| 237 | struct wl_event_source *ping_timer; |
| 238 | uint32_t ping_serial; |
| 239 | int unresponsive; |
| 240 | }; |
| 241 | |
Alex Wu | bd3354b | 2012-04-17 17:20:49 +0800 | [diff] [blame] | 242 | static struct desktop_shell * |
| 243 | shell_surface_get_shell(struct shell_surface *shsurf); |
| 244 | |
Kristian Høgsberg | 0c36903 | 2013-02-14 21:31:44 -0500 | [diff] [blame] | 245 | static void |
Kristian Høgsberg | e314875 | 2013-05-06 23:19:49 -0400 | [diff] [blame] | 246 | surface_rotate(struct shell_surface *surface, struct weston_seat *seat); |
Kristian Høgsberg | 0c36903 | 2013-02-14 21:31:44 -0500 | [diff] [blame] | 247 | |
Pekka Paalanen | 79346ab | 2013-05-22 18:03:09 +0300 | [diff] [blame] | 248 | static void |
| 249 | shell_fade_startup(struct desktop_shell *shell); |
| 250 | |
Philip Withnall | becb77e | 2013-11-25 18:01:30 +0000 | [diff] [blame] | 251 | static struct shell_seat * |
| 252 | get_shell_seat(struct weston_seat *seat); |
| 253 | |
Jonny Lamb | d73c694 | 2014-08-20 15:53:20 +0200 | [diff] [blame^] | 254 | static void |
| 255 | get_output_panel_size(struct desktop_shell *shell, |
| 256 | struct weston_output *output, |
| 257 | int *width, int *height); |
Kristian Høgsberg | ae356ae | 2014-04-29 16:03:54 -0700 | [diff] [blame] | 258 | |
Philip Withnall | 648a4dd | 2013-11-25 18:01:44 +0000 | [diff] [blame] | 259 | static void |
| 260 | shell_surface_update_child_surface_layers(struct shell_surface *shsurf); |
| 261 | |
Alex Wu | bd3354b | 2012-04-17 17:20:49 +0800 | [diff] [blame] | 262 | static bool |
Rafael Antognolli | e2a3455 | 2013-12-03 15:35:45 -0200 | [diff] [blame] | 263 | shell_surface_is_wl_shell_surface(struct shell_surface *shsurf); |
| 264 | |
| 265 | static bool |
| 266 | shell_surface_is_xdg_surface(struct shell_surface *shsurf); |
| 267 | |
| 268 | static bool |
| 269 | shell_surface_is_xdg_popup(struct shell_surface *shsurf); |
| 270 | |
| 271 | static void |
| 272 | shell_surface_set_parent(struct shell_surface *shsurf, |
| 273 | struct weston_surface *parent); |
| 274 | |
| 275 | static bool |
Alex Wu | bd3354b | 2012-04-17 17:20:49 +0800 | [diff] [blame] | 276 | shell_surface_is_top_fullscreen(struct shell_surface *shsurf) |
| 277 | { |
| 278 | struct desktop_shell *shell; |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 279 | struct weston_view *top_fs_ev; |
Alex Wu | bd3354b | 2012-04-17 17:20:49 +0800 | [diff] [blame] | 280 | |
| 281 | shell = shell_surface_get_shell(shsurf); |
Quentin Glidic | c0d79ce | 2013-01-29 14:16:13 +0100 | [diff] [blame] | 282 | |
Giulio Camuffo | 412e6a5 | 2014-07-09 22:12:56 +0300 | [diff] [blame] | 283 | if (wl_list_empty(&shell->fullscreen_layer.view_list.link)) |
Alex Wu | bd3354b | 2012-04-17 17:20:49 +0800 | [diff] [blame] | 284 | return false; |
| 285 | |
Giulio Camuffo | 412e6a5 | 2014-07-09 22:12:56 +0300 | [diff] [blame] | 286 | top_fs_ev = container_of(shell->fullscreen_layer.view_list.link.next, |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 287 | struct weston_view, |
Giulio Camuffo | 412e6a5 | 2014-07-09 22:12:56 +0300 | [diff] [blame] | 288 | layer_link.link); |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 289 | return (shsurf == get_shell_surface(top_fs_ev->surface)); |
Alex Wu | bd3354b | 2012-04-17 17:20:49 +0800 | [diff] [blame] | 290 | } |
| 291 | |
Kristian Høgsberg | 6af8eb9 | 2012-01-25 16:57:11 -0500 | [diff] [blame] | 292 | static void |
Kristian Høgsberg | 27e3052 | 2012-04-11 23:18:23 -0400 | [diff] [blame] | 293 | destroy_shell_grab_shsurf(struct wl_listener *listener, void *data) |
Ander Conselvan de Oliveira | fe0444a | 2012-04-04 17:48:05 +0300 | [diff] [blame] | 294 | { |
| 295 | struct shell_grab *grab; |
| 296 | |
| 297 | grab = container_of(listener, struct shell_grab, |
| 298 | shsurf_destroy_listener); |
| 299 | |
| 300 | grab->shsurf = NULL; |
| 301 | } |
| 302 | |
Kristian Høgsberg | 1ef2313 | 2013-12-04 00:20:01 -0800 | [diff] [blame] | 303 | struct weston_view * |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 304 | get_default_view(struct weston_surface *surface) |
| 305 | { |
| 306 | struct shell_surface *shsurf; |
| 307 | struct weston_view *view; |
| 308 | |
| 309 | if (!surface || wl_list_empty(&surface->views)) |
| 310 | return NULL; |
| 311 | |
| 312 | shsurf = get_shell_surface(surface); |
| 313 | if (shsurf) |
| 314 | return shsurf->view; |
| 315 | |
| 316 | wl_list_for_each(view, &surface->views, surface_link) |
| 317 | if (weston_view_is_mapped(view)) |
| 318 | return view; |
| 319 | |
| 320 | return container_of(surface->views.next, struct weston_view, surface_link); |
| 321 | } |
| 322 | |
Ander Conselvan de Oliveira | fe0444a | 2012-04-04 17:48:05 +0300 | [diff] [blame] | 323 | static void |
Kristian Høgsberg | 02bbabb | 2013-05-06 22:15:05 -0400 | [diff] [blame] | 324 | popup_grab_end(struct weston_pointer *pointer); |
Kristian Høgsberg | 57e0907 | 2012-10-30 14:07:27 -0400 | [diff] [blame] | 325 | |
| 326 | static void |
Ander Conselvan de Oliveira | b9d2a0f | 2012-06-28 18:08:05 +0300 | [diff] [blame] | 327 | shell_grab_start(struct shell_grab *grab, |
Kristian Høgsberg | 02bbabb | 2013-05-06 22:15:05 -0400 | [diff] [blame] | 328 | const struct weston_pointer_grab_interface *interface, |
Ander Conselvan de Oliveira | b9d2a0f | 2012-06-28 18:08:05 +0300 | [diff] [blame] | 329 | struct shell_surface *shsurf, |
Kristian Høgsberg | 02bbabb | 2013-05-06 22:15:05 -0400 | [diff] [blame] | 330 | struct weston_pointer *pointer, |
Ander Conselvan de Oliveira | b9d2a0f | 2012-06-28 18:08:05 +0300 | [diff] [blame] | 331 | enum desktop_shell_cursor cursor) |
Ander Conselvan de Oliveira | fe0444a | 2012-04-04 17:48:05 +0300 | [diff] [blame] | 332 | { |
Ander Conselvan de Oliveira | b9d2a0f | 2012-06-28 18:08:05 +0300 | [diff] [blame] | 333 | struct desktop_shell *shell = shsurf->shell; |
| 334 | |
Kristian Høgsberg | 57e0907 | 2012-10-30 14:07:27 -0400 | [diff] [blame] | 335 | popup_grab_end(pointer); |
| 336 | |
Ander Conselvan de Oliveira | fe0444a | 2012-04-04 17:48:05 +0300 | [diff] [blame] | 337 | grab->grab.interface = interface; |
| 338 | grab->shsurf = shsurf; |
Kristian Høgsberg | 27e3052 | 2012-04-11 23:18:23 -0400 | [diff] [blame] | 339 | grab->shsurf_destroy_listener.notify = destroy_shell_grab_shsurf; |
Jason Ekstrand | 651f00e | 2013-06-14 10:07:54 -0500 | [diff] [blame] | 340 | wl_signal_add(&shsurf->destroy_signal, |
Kristian Høgsberg | 27e3052 | 2012-04-11 23:18:23 -0400 | [diff] [blame] | 341 | &grab->shsurf_destroy_listener); |
Ander Conselvan de Oliveira | fe0444a | 2012-04-04 17:48:05 +0300 | [diff] [blame] | 342 | |
Kristian Høgsberg | c85f1d4 | 2013-10-24 16:52:00 -0700 | [diff] [blame] | 343 | shsurf->grabbed = 1; |
Kristian Høgsberg | 02bbabb | 2013-05-06 22:15:05 -0400 | [diff] [blame] | 344 | weston_pointer_start_grab(pointer, &grab->grab); |
Kristian Høgsberg | c9974a0 | 2013-07-03 19:24:57 -0400 | [diff] [blame] | 345 | if (shell->child.desktop_shell) { |
| 346 | desktop_shell_send_grab_cursor(shell->child.desktop_shell, |
| 347 | cursor); |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 348 | weston_pointer_set_focus(pointer, |
| 349 | get_default_view(shell->grab_surface), |
Kristian Høgsberg | c9974a0 | 2013-07-03 19:24:57 -0400 | [diff] [blame] | 350 | wl_fixed_from_int(0), |
| 351 | wl_fixed_from_int(0)); |
| 352 | } |
Ander Conselvan de Oliveira | fe0444a | 2012-04-04 17:48:05 +0300 | [diff] [blame] | 353 | } |
| 354 | |
Jonny Lamb | d73c694 | 2014-08-20 15:53:20 +0200 | [diff] [blame^] | 355 | static void |
| 356 | get_output_panel_size(struct desktop_shell *shell, |
| 357 | struct weston_output *output, |
| 358 | int *width, |
| 359 | int *height) |
Jasper St. Pierre | 6458ec3 | 2014-04-11 16:00:31 -0700 | [diff] [blame] | 360 | { |
| 361 | struct weston_view *view; |
Jonny Lamb | d73c694 | 2014-08-20 15:53:20 +0200 | [diff] [blame^] | 362 | |
| 363 | *width = 0; |
| 364 | *height = 0; |
Jasper St. Pierre | 6458ec3 | 2014-04-11 16:00:31 -0700 | [diff] [blame] | 365 | |
| 366 | if (!output) |
Jonny Lamb | d73c694 | 2014-08-20 15:53:20 +0200 | [diff] [blame^] | 367 | return; |
Jasper St. Pierre | 6458ec3 | 2014-04-11 16:00:31 -0700 | [diff] [blame] | 368 | |
Giulio Camuffo | 412e6a5 | 2014-07-09 22:12:56 +0300 | [diff] [blame] | 369 | 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^] | 370 | float x, y; |
| 371 | |
| 372 | if (view->surface->output != output) |
| 373 | continue; |
| 374 | |
| 375 | switch (shell->panel_position) { |
| 376 | case DESKTOP_SHELL_PANEL_POSITION_TOP: |
| 377 | case DESKTOP_SHELL_PANEL_POSITION_BOTTOM: |
| 378 | |
| 379 | weston_view_to_global_float(view, |
| 380 | view->surface->width, 0, |
| 381 | &x, &y); |
| 382 | |
| 383 | *width = (int) x; |
| 384 | *height = view->surface->height + (int) y; |
| 385 | return; |
| 386 | |
| 387 | case DESKTOP_SHELL_PANEL_POSITION_LEFT: |
| 388 | case DESKTOP_SHELL_PANEL_POSITION_RIGHT: |
| 389 | weston_view_to_global_float(view, |
| 390 | 0, view->surface->height, |
| 391 | &x, &y); |
| 392 | |
| 393 | *width = view->surface->width + (int) x; |
| 394 | *height = (int) y; |
| 395 | return; |
| 396 | |
| 397 | default: |
| 398 | /* we've already set width and height to |
| 399 | * fallback values. */ |
Jasper St. Pierre | 6458ec3 | 2014-04-11 16:00:31 -0700 | [diff] [blame] | 400 | break; |
| 401 | } |
| 402 | } |
| 403 | |
Jonny Lamb | d73c694 | 2014-08-20 15:53:20 +0200 | [diff] [blame^] | 404 | /* the correct view wasn't found */ |
| 405 | } |
| 406 | |
| 407 | static void |
| 408 | get_output_work_area(struct desktop_shell *shell, |
| 409 | struct weston_output *output, |
| 410 | pixman_rectangle32_t *area) |
| 411 | { |
| 412 | int32_t panel_width = 0, panel_height = 0; |
| 413 | |
| 414 | area->x = 0; |
| 415 | area->y = 0; |
| 416 | |
| 417 | get_output_panel_size(shell, output, &panel_width, &panel_height); |
| 418 | |
| 419 | switch (shell->panel_position) { |
| 420 | case DESKTOP_SHELL_PANEL_POSITION_TOP: |
| 421 | default: |
| 422 | area->y = panel_height; |
| 423 | case DESKTOP_SHELL_PANEL_POSITION_BOTTOM: |
| 424 | area->width = output->width; |
| 425 | area->height = output->height - panel_height; |
| 426 | break; |
| 427 | case DESKTOP_SHELL_PANEL_POSITION_LEFT: |
| 428 | area->x = panel_width; |
| 429 | case DESKTOP_SHELL_PANEL_POSITION_RIGHT: |
| 430 | area->width = output->width - panel_width; |
| 431 | area->height = output->height; |
| 432 | break; |
| 433 | } |
Jasper St. Pierre | 6458ec3 | 2014-04-11 16:00:31 -0700 | [diff] [blame] | 434 | } |
| 435 | |
| 436 | static void |
| 437 | send_configure_for_surface(struct shell_surface *shsurf) |
| 438 | { |
| 439 | int32_t width, height; |
| 440 | struct surface_state *state; |
| 441 | |
| 442 | if (shsurf->state_requested) |
| 443 | state = &shsurf->requested_state; |
| 444 | else if (shsurf->state_changed) |
| 445 | state = &shsurf->next_state; |
| 446 | else |
| 447 | state = &shsurf->state; |
| 448 | |
| 449 | if (state->fullscreen) { |
| 450 | width = shsurf->output->width; |
| 451 | height = shsurf->output->height; |
| 452 | } else if (state->maximized) { |
| 453 | struct desktop_shell *shell; |
Jonny Lamb | d73c694 | 2014-08-20 15:53:20 +0200 | [diff] [blame^] | 454 | pixman_rectangle32_t area; |
Jasper St. Pierre | 6458ec3 | 2014-04-11 16:00:31 -0700 | [diff] [blame] | 455 | |
| 456 | shell = shell_surface_get_shell(shsurf); |
Jonny Lamb | d73c694 | 2014-08-20 15:53:20 +0200 | [diff] [blame^] | 457 | get_output_work_area(shell, shsurf->output, &area); |
Jasper St. Pierre | 6458ec3 | 2014-04-11 16:00:31 -0700 | [diff] [blame] | 458 | |
Jonny Lamb | d73c694 | 2014-08-20 15:53:20 +0200 | [diff] [blame^] | 459 | width = area.width; |
| 460 | height = area.height; |
Jasper St. Pierre | 6458ec3 | 2014-04-11 16:00:31 -0700 | [diff] [blame] | 461 | } else { |
| 462 | width = 0; |
| 463 | height = 0; |
| 464 | } |
| 465 | |
| 466 | shsurf->client->send_configure(shsurf->surface, width, height); |
| 467 | } |
| 468 | |
Ander Conselvan de Oliveira | fe0444a | 2012-04-04 17:48:05 +0300 | [diff] [blame] | 469 | static void |
Jasper St. Pierre | 5befdda | 2014-05-06 08:50:47 -0400 | [diff] [blame] | 470 | shell_surface_state_changed(struct shell_surface *shsurf) |
| 471 | { |
Jasper St. Pierre | 6458ec3 | 2014-04-11 16:00:31 -0700 | [diff] [blame] | 472 | if (shell_surface_is_xdg_surface(shsurf)) |
| 473 | send_configure_for_surface(shsurf); |
Jasper St. Pierre | 5befdda | 2014-05-06 08:50:47 -0400 | [diff] [blame] | 474 | } |
| 475 | |
| 476 | static void |
Ander Conselvan de Oliveira | b9d2a0f | 2012-06-28 18:08:05 +0300 | [diff] [blame] | 477 | shell_grab_end(struct shell_grab *grab) |
Ander Conselvan de Oliveira | fe0444a | 2012-04-04 17:48:05 +0300 | [diff] [blame] | 478 | { |
Kristian Høgsberg | c85f1d4 | 2013-10-24 16:52:00 -0700 | [diff] [blame] | 479 | if (grab->shsurf) { |
Kristian Høgsberg | 47b5dca | 2012-06-07 18:08:04 -0400 | [diff] [blame] | 480 | wl_list_remove(&grab->shsurf_destroy_listener.link); |
Kristian Høgsberg | c85f1d4 | 2013-10-24 16:52:00 -0700 | [diff] [blame] | 481 | grab->shsurf->grabbed = 0; |
Jasper St. Pierre | 5befdda | 2014-05-06 08:50:47 -0400 | [diff] [blame] | 482 | |
| 483 | if (grab->shsurf->resize_edges) { |
| 484 | grab->shsurf->resize_edges = 0; |
| 485 | shell_surface_state_changed(grab->shsurf); |
| 486 | } |
Kristian Høgsberg | c85f1d4 | 2013-10-24 16:52:00 -0700 | [diff] [blame] | 487 | } |
Ander Conselvan de Oliveira | b9d2a0f | 2012-06-28 18:08:05 +0300 | [diff] [blame] | 488 | |
Kristian Høgsberg | 9e5d7d1 | 2013-07-22 16:31:53 -0700 | [diff] [blame] | 489 | weston_pointer_end_grab(grab->grab.pointer); |
Ander Conselvan de Oliveira | fe0444a | 2012-04-04 17:48:05 +0300 | [diff] [blame] | 490 | } |
| 491 | |
| 492 | static void |
Rusty Lynch | 1084da5 | 2013-08-15 09:10:08 -0700 | [diff] [blame] | 493 | shell_touch_grab_start(struct shell_touch_grab *grab, |
| 494 | const struct weston_touch_grab_interface *interface, |
| 495 | struct shell_surface *shsurf, |
| 496 | struct weston_touch *touch) |
| 497 | { |
| 498 | struct desktop_shell *shell = shsurf->shell; |
U. Artie Eoff | cf5737a | 2014-01-17 10:08:25 -0800 | [diff] [blame] | 499 | |
Kristian Høgsberg | 74071e0 | 2014-04-29 15:01:16 -0700 | [diff] [blame] | 500 | if (touch->seat->pointer) |
| 501 | popup_grab_end(touch->seat->pointer); |
| 502 | |
Rusty Lynch | 1084da5 | 2013-08-15 09:10:08 -0700 | [diff] [blame] | 503 | grab->grab.interface = interface; |
| 504 | grab->shsurf = shsurf; |
| 505 | grab->shsurf_destroy_listener.notify = destroy_shell_grab_shsurf; |
| 506 | wl_signal_add(&shsurf->destroy_signal, |
| 507 | &grab->shsurf_destroy_listener); |
| 508 | |
| 509 | grab->touch = touch; |
Kristian Høgsberg | c85f1d4 | 2013-10-24 16:52:00 -0700 | [diff] [blame] | 510 | shsurf->grabbed = 1; |
Rusty Lynch | 1084da5 | 2013-08-15 09:10:08 -0700 | [diff] [blame] | 511 | |
| 512 | weston_touch_start_grab(touch, &grab->grab); |
| 513 | if (shell->child.desktop_shell) |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 514 | weston_touch_set_focus(touch->seat, |
| 515 | get_default_view(shell->grab_surface)); |
Rusty Lynch | 1084da5 | 2013-08-15 09:10:08 -0700 | [diff] [blame] | 516 | } |
| 517 | |
| 518 | static void |
| 519 | shell_touch_grab_end(struct shell_touch_grab *grab) |
| 520 | { |
Kristian Høgsberg | c85f1d4 | 2013-10-24 16:52:00 -0700 | [diff] [blame] | 521 | if (grab->shsurf) { |
Rusty Lynch | 1084da5 | 2013-08-15 09:10:08 -0700 | [diff] [blame] | 522 | wl_list_remove(&grab->shsurf_destroy_listener.link); |
Kristian Høgsberg | c85f1d4 | 2013-10-24 16:52:00 -0700 | [diff] [blame] | 523 | grab->shsurf->grabbed = 0; |
| 524 | } |
Rusty Lynch | 1084da5 | 2013-08-15 09:10:08 -0700 | [diff] [blame] | 525 | |
| 526 | weston_touch_end_grab(grab->touch); |
| 527 | } |
| 528 | |
| 529 | static void |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 530 | center_on_output(struct weston_view *view, |
Alex Wu | 4539b08 | 2012-03-01 12:57:46 +0800 | [diff] [blame] | 531 | struct weston_output *output); |
| 532 | |
Daniel Stone | 496ca17 | 2012-05-30 16:31:42 +0100 | [diff] [blame] | 533 | static enum weston_keyboard_modifier |
Tiago Vignatti | 0b52d48 | 2012-04-20 18:54:25 +0300 | [diff] [blame] | 534 | get_modifier(char *modifier) |
| 535 | { |
| 536 | if (!modifier) |
| 537 | return MODIFIER_SUPER; |
| 538 | |
| 539 | if (!strcmp("ctrl", modifier)) |
| 540 | return MODIFIER_CTRL; |
| 541 | else if (!strcmp("alt", modifier)) |
| 542 | return MODIFIER_ALT; |
| 543 | else if (!strcmp("super", modifier)) |
| 544 | return MODIFIER_SUPER; |
| 545 | else |
| 546 | return MODIFIER_SUPER; |
| 547 | } |
| 548 | |
Juan Zhao | e10d279 | 2012-04-25 19:09:52 +0800 | [diff] [blame] | 549 | static enum animation_type |
| 550 | get_animation_type(char *animation) |
| 551 | { |
U. Artie Eoff | b571910 | 2014-01-15 14:26:31 -0800 | [diff] [blame] | 552 | if (!animation) |
| 553 | return ANIMATION_NONE; |
| 554 | |
Juan Zhao | e10d279 | 2012-04-25 19:09:52 +0800 | [diff] [blame] | 555 | if (!strcmp("zoom", animation)) |
| 556 | return ANIMATION_ZOOM; |
| 557 | else if (!strcmp("fade", animation)) |
| 558 | return ANIMATION_FADE; |
Louis-Francis Ratté-Boulianne | b482dbd | 2013-11-19 11:37:11 +0100 | [diff] [blame] | 559 | else if (!strcmp("dim-layer", animation)) |
| 560 | return ANIMATION_DIM_LAYER; |
Juan Zhao | e10d279 | 2012-04-25 19:09:52 +0800 | [diff] [blame] | 561 | else |
| 562 | return ANIMATION_NONE; |
| 563 | } |
| 564 | |
Alex Wu | 4539b08 | 2012-03-01 12:57:46 +0800 | [diff] [blame] | 565 | static void |
Kristian Høgsberg | 14e438c | 2013-05-26 21:48:14 -0400 | [diff] [blame] | 566 | shell_configuration(struct desktop_shell *shell) |
Pekka Paalanen | e955f1e | 2011-12-07 11:49:52 +0200 | [diff] [blame] | 567 | { |
Kristian Høgsberg | 673a889 | 2013-05-23 21:40:56 -0400 | [diff] [blame] | 568 | struct weston_config_section *section; |
| 569 | int duration; |
| 570 | char *s; |
Pekka Paalanen | e955f1e | 2011-12-07 11:49:52 +0200 | [diff] [blame] | 571 | |
Kristian Høgsberg | 673a889 | 2013-05-23 21:40:56 -0400 | [diff] [blame] | 572 | section = weston_config_get_section(shell->compositor->config, |
| 573 | "screensaver", NULL, NULL); |
| 574 | weston_config_section_get_string(section, |
| 575 | "path", &shell->screensaver.path, NULL); |
| 576 | weston_config_section_get_int(section, "duration", &duration, 60); |
Ander Conselvan de Oliveira | 859e885 | 2013-02-21 18:35:21 +0200 | [diff] [blame] | 577 | shell->screensaver.duration = duration * 1000; |
Kristian Høgsberg | 673a889 | 2013-05-23 21:40:56 -0400 | [diff] [blame] | 578 | |
| 579 | section = weston_config_get_section(shell->compositor->config, |
| 580 | "shell", NULL, NULL); |
| 581 | weston_config_section_get_string(section, |
Emilio Pozuelo Monfort | 8a81b83 | 2013-12-02 12:53:32 +0100 | [diff] [blame] | 582 | "client", &s, LIBEXECDIR "/" WESTON_SHELL_CLIENT); |
Emilio Pozuelo Monfort | 46ce798 | 2013-11-20 13:22:29 +0100 | [diff] [blame] | 583 | shell->client = s; |
| 584 | weston_config_section_get_string(section, |
Kristian Høgsberg | 673a889 | 2013-05-23 21:40:56 -0400 | [diff] [blame] | 585 | "binding-modifier", &s, "super"); |
| 586 | shell->binding_modifier = get_modifier(s); |
Quentin Glidic | 8418c29 | 2013-06-18 09:11:03 +0200 | [diff] [blame] | 587 | free(s); |
Kristian Høgsberg | d56ab4e | 2014-01-16 16:51:52 -0800 | [diff] [blame] | 588 | |
| 589 | weston_config_section_get_string(section, |
| 590 | "exposay-modifier", &s, "none"); |
| 591 | if (strcmp(s, "none") == 0) |
| 592 | shell->exposay_modifier = 0; |
| 593 | else |
| 594 | shell->exposay_modifier = get_modifier(s); |
| 595 | free(s); |
| 596 | |
Kristian Høgsberg | 673a889 | 2013-05-23 21:40:56 -0400 | [diff] [blame] | 597 | weston_config_section_get_string(section, "animation", &s, "none"); |
| 598 | shell->win_animation_type = get_animation_type(s); |
Quentin Glidic | 8418c29 | 2013-06-18 09:11:03 +0200 | [diff] [blame] | 599 | free(s); |
Jonny Lamb | f322f8e | 2014-08-12 15:13:30 +0200 | [diff] [blame] | 600 | weston_config_section_get_string(section, "close-animation", &s, "fade"); |
| 601 | shell->win_close_animation_type = get_animation_type(s); |
| 602 | free(s); |
Kristian Høgsberg | 724c8d9 | 2013-10-16 11:38:24 -0700 | [diff] [blame] | 603 | weston_config_section_get_string(section, |
| 604 | "startup-animation", &s, "fade"); |
| 605 | shell->startup_animation_type = get_animation_type(s); |
| 606 | free(s); |
Kristian Høgsberg | 912e0a1 | 2013-10-30 08:59:55 -0700 | [diff] [blame] | 607 | if (shell->startup_animation_type == ANIMATION_ZOOM) |
| 608 | shell->startup_animation_type = ANIMATION_NONE; |
Louis-Francis Ratté-Boulianne | b482dbd | 2013-11-19 11:37:11 +0100 | [diff] [blame] | 609 | weston_config_section_get_string(section, "focus-animation", &s, "none"); |
| 610 | shell->focus_animation_type = get_animation_type(s); |
| 611 | free(s); |
Kristian Høgsberg | 673a889 | 2013-05-23 21:40:56 -0400 | [diff] [blame] | 612 | weston_config_section_get_uint(section, "num-workspaces", |
| 613 | &shell->workspaces.num, |
| 614 | DEFAULT_NUM_WORKSPACES); |
Jonas Ådahl | e3cddce | 2012-06-13 00:01:22 +0200 | [diff] [blame] | 615 | } |
| 616 | |
Kristian Høgsberg | 1ef2313 | 2013-12-04 00:20:01 -0800 | [diff] [blame] | 617 | struct weston_output * |
Louis-Francis Ratté-Boulianne | b482dbd | 2013-11-19 11:37:11 +0100 | [diff] [blame] | 618 | get_default_output(struct weston_compositor *compositor) |
| 619 | { |
| 620 | return container_of(compositor->output_list.next, |
| 621 | struct weston_output, link); |
| 622 | } |
| 623 | |
| 624 | |
| 625 | /* no-op func for checking focus surface */ |
| 626 | static void |
Jason Ekstrand | 918f2dd | 2013-12-02 21:01:53 -0600 | [diff] [blame] | 627 | 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] | 628 | { |
| 629 | } |
| 630 | |
| 631 | static struct focus_surface * |
| 632 | get_focus_surface(struct weston_surface *surface) |
| 633 | { |
| 634 | if (surface->configure == focus_surface_configure) |
| 635 | return surface->configure_private; |
| 636 | else |
| 637 | return NULL; |
| 638 | } |
| 639 | |
| 640 | static bool |
| 641 | is_focus_surface (struct weston_surface *es) |
| 642 | { |
| 643 | return (es->configure == focus_surface_configure); |
| 644 | } |
| 645 | |
| 646 | static bool |
| 647 | is_focus_view (struct weston_view *view) |
| 648 | { |
| 649 | return is_focus_surface (view->surface); |
| 650 | } |
| 651 | |
| 652 | static struct focus_surface * |
| 653 | create_focus_surface(struct weston_compositor *ec, |
| 654 | struct weston_output *output) |
| 655 | { |
| 656 | struct focus_surface *fsurf = NULL; |
| 657 | struct weston_surface *surface = NULL; |
| 658 | |
| 659 | fsurf = malloc(sizeof *fsurf); |
| 660 | if (!fsurf) |
| 661 | return NULL; |
| 662 | |
| 663 | fsurf->surface = weston_surface_create(ec); |
| 664 | surface = fsurf->surface; |
| 665 | if (surface == NULL) { |
| 666 | free(fsurf); |
| 667 | return NULL; |
| 668 | } |
| 669 | |
| 670 | surface->configure = focus_surface_configure; |
| 671 | surface->output = output; |
| 672 | surface->configure_private = fsurf; |
| 673 | |
U. Artie Eoff | 0b23b2b | 2014-01-15 14:45:59 -0800 | [diff] [blame] | 674 | fsurf->view = weston_view_create(surface); |
| 675 | if (fsurf->view == NULL) { |
| 676 | weston_surface_destroy(surface); |
| 677 | free(fsurf); |
| 678 | return NULL; |
| 679 | } |
Emilio Pozuelo Monfort | da64426 | 2013-11-19 11:37:19 +0100 | [diff] [blame] | 680 | fsurf->view->output = output; |
Louis-Francis Ratté-Boulianne | b482dbd | 2013-11-19 11:37:11 +0100 | [diff] [blame] | 681 | |
Jason Ekstrand | 5c11a33 | 2013-12-04 20:32:03 -0600 | [diff] [blame] | 682 | weston_surface_set_size(surface, output->width, output->height); |
Jason Ekstrand | 918f2dd | 2013-12-02 21:01:53 -0600 | [diff] [blame] | 683 | weston_view_set_position(fsurf->view, output->x, output->y); |
Louis-Francis Ratté-Boulianne | b482dbd | 2013-11-19 11:37:11 +0100 | [diff] [blame] | 684 | weston_surface_set_color(surface, 0.0, 0.0, 0.0, 1.0); |
| 685 | pixman_region32_fini(&surface->opaque); |
| 686 | pixman_region32_init_rect(&surface->opaque, output->x, output->y, |
| 687 | output->width, output->height); |
| 688 | pixman_region32_fini(&surface->input); |
| 689 | pixman_region32_init(&surface->input); |
| 690 | |
| 691 | wl_list_init(&fsurf->workspace_transform.link); |
| 692 | |
| 693 | return fsurf; |
| 694 | } |
| 695 | |
| 696 | static void |
| 697 | focus_surface_destroy(struct focus_surface *fsurf) |
| 698 | { |
| 699 | weston_surface_destroy(fsurf->surface); |
| 700 | free(fsurf); |
| 701 | } |
| 702 | |
| 703 | static void |
| 704 | focus_animation_done(struct weston_view_animation *animation, void *data) |
| 705 | { |
| 706 | struct workspace *ws = data; |
| 707 | |
| 708 | ws->focus_animation = NULL; |
| 709 | } |
| 710 | |
Jonas Ådahl | e3cddce | 2012-06-13 00:01:22 +0200 | [diff] [blame] | 711 | static void |
Jonas Ådahl | 0476974 | 2012-06-13 00:01:24 +0200 | [diff] [blame] | 712 | focus_state_destroy(struct focus_state *state) |
| 713 | { |
| 714 | wl_list_remove(&state->seat_destroy_listener.link); |
| 715 | wl_list_remove(&state->surface_destroy_listener.link); |
| 716 | free(state); |
| 717 | } |
| 718 | |
| 719 | static void |
| 720 | focus_state_seat_destroy(struct wl_listener *listener, void *data) |
| 721 | { |
| 722 | struct focus_state *state = container_of(listener, |
| 723 | struct focus_state, |
| 724 | seat_destroy_listener); |
| 725 | |
| 726 | wl_list_remove(&state->link); |
| 727 | focus_state_destroy(state); |
| 728 | } |
| 729 | |
| 730 | static void |
| 731 | focus_state_surface_destroy(struct wl_listener *listener, void *data) |
| 732 | { |
| 733 | struct focus_state *state = container_of(listener, |
| 734 | struct focus_state, |
Kristian Høgsberg | b8e0d0f | 2012-07-31 10:30:26 -0400 | [diff] [blame] | 735 | surface_destroy_listener); |
Kristian Høgsberg | e377822 | 2012-07-31 17:29:30 -0400 | [diff] [blame] | 736 | struct desktop_shell *shell; |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 737 | struct weston_surface *main_surface, *next; |
| 738 | struct weston_view *view; |
Jonas Ådahl | 0476974 | 2012-06-13 00:01:24 +0200 | [diff] [blame] | 739 | |
Pekka Paalanen | 01388e2 | 2013-04-25 13:57:44 +0300 | [diff] [blame] | 740 | main_surface = weston_surface_get_main_surface(state->keyboard_focus); |
| 741 | |
Kristian Høgsberg | e377822 | 2012-07-31 17:29:30 -0400 | [diff] [blame] | 742 | next = NULL; |
Giulio Camuffo | 412e6a5 | 2014-07-09 22:12:56 +0300 | [diff] [blame] | 743 | wl_list_for_each(view, |
| 744 | &state->ws->layer.view_list.link, layer_link.link) { |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 745 | if (view->surface == main_surface) |
Kristian Høgsberg | e377822 | 2012-07-31 17:29:30 -0400 | [diff] [blame] | 746 | continue; |
Louis-Francis Ratté-Boulianne | b482dbd | 2013-11-19 11:37:11 +0100 | [diff] [blame] | 747 | if (is_focus_view(view)) |
| 748 | continue; |
Kristian Høgsberg | e377822 | 2012-07-31 17:29:30 -0400 | [diff] [blame] | 749 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 750 | next = view->surface; |
Kristian Høgsberg | e377822 | 2012-07-31 17:29:30 -0400 | [diff] [blame] | 751 | break; |
| 752 | } |
| 753 | |
Pekka Paalanen | 01388e2 | 2013-04-25 13:57:44 +0300 | [diff] [blame] | 754 | /* if the focus was a sub-surface, activate its main surface */ |
| 755 | if (main_surface != state->keyboard_focus) |
| 756 | next = main_surface; |
| 757 | |
Louis-Francis Ratté-Boulianne | b482dbd | 2013-11-19 11:37:11 +0100 | [diff] [blame] | 758 | shell = state->seat->compositor->shell_interface.shell; |
Kristian Høgsberg | e377822 | 2012-07-31 17:29:30 -0400 | [diff] [blame] | 759 | if (next) { |
Louis-Francis Ratté-Boulianne | b482dbd | 2013-11-19 11:37:11 +0100 | [diff] [blame] | 760 | state->keyboard_focus = NULL; |
Emilio Pozuelo Monfort | 9e7c759 | 2014-01-30 14:01:10 +0100 | [diff] [blame] | 761 | activate(shell, next, state->seat, true); |
Kristian Høgsberg | e377822 | 2012-07-31 17:29:30 -0400 | [diff] [blame] | 762 | } else { |
Louis-Francis Ratté-Boulianne | b482dbd | 2013-11-19 11:37:11 +0100 | [diff] [blame] | 763 | if (shell->focus_animation_type == ANIMATION_DIM_LAYER) { |
| 764 | if (state->ws->focus_animation) |
| 765 | weston_view_animation_destroy(state->ws->focus_animation); |
| 766 | |
| 767 | state->ws->focus_animation = weston_fade_run( |
| 768 | state->ws->fsurf_front->view, |
| 769 | state->ws->fsurf_front->view->alpha, 0.0, 300, |
| 770 | focus_animation_done, state->ws); |
| 771 | } |
| 772 | |
Kristian Høgsberg | e377822 | 2012-07-31 17:29:30 -0400 | [diff] [blame] | 773 | wl_list_remove(&state->link); |
| 774 | focus_state_destroy(state); |
| 775 | } |
Jonas Ådahl | 0476974 | 2012-06-13 00:01:24 +0200 | [diff] [blame] | 776 | } |
| 777 | |
| 778 | static struct focus_state * |
Kristian Høgsberg | 2f5faff | 2012-07-31 16:36:34 -0400 | [diff] [blame] | 779 | focus_state_create(struct weston_seat *seat, struct workspace *ws) |
Jonas Ådahl | 0476974 | 2012-06-13 00:01:24 +0200 | [diff] [blame] | 780 | { |
Jonas Ådahl | 0476974 | 2012-06-13 00:01:24 +0200 | [diff] [blame] | 781 | struct focus_state *state; |
Jonas Ådahl | 0476974 | 2012-06-13 00:01:24 +0200 | [diff] [blame] | 782 | |
| 783 | state = malloc(sizeof *state); |
| 784 | if (state == NULL) |
| 785 | return NULL; |
| 786 | |
Louis-Francis Ratté-Boulianne | b482dbd | 2013-11-19 11:37:11 +0100 | [diff] [blame] | 787 | state->keyboard_focus = NULL; |
Kristian Høgsberg | 2f5faff | 2012-07-31 16:36:34 -0400 | [diff] [blame] | 788 | state->ws = ws; |
Jonas Ådahl | 0476974 | 2012-06-13 00:01:24 +0200 | [diff] [blame] | 789 | state->seat = seat; |
Kristian Høgsberg | 2f5faff | 2012-07-31 16:36:34 -0400 | [diff] [blame] | 790 | wl_list_insert(&ws->focus_list, &state->link); |
Jonas Ådahl | 0476974 | 2012-06-13 00:01:24 +0200 | [diff] [blame] | 791 | |
| 792 | state->seat_destroy_listener.notify = focus_state_seat_destroy; |
| 793 | state->surface_destroy_listener.notify = focus_state_surface_destroy; |
Kristian Høgsberg | 4912454 | 2013-05-06 22:27:40 -0400 | [diff] [blame] | 794 | wl_signal_add(&seat->destroy_signal, |
Jonas Ådahl | 0476974 | 2012-06-13 00:01:24 +0200 | [diff] [blame] | 795 | &state->seat_destroy_listener); |
Kristian Høgsberg | 2f5faff | 2012-07-31 16:36:34 -0400 | [diff] [blame] | 796 | wl_list_init(&state->surface_destroy_listener.link); |
Jonas Ådahl | 0476974 | 2012-06-13 00:01:24 +0200 | [diff] [blame] | 797 | |
| 798 | return state; |
| 799 | } |
| 800 | |
Jonas Ådahl | 8538b22 | 2012-08-29 22:13:03 +0200 | [diff] [blame] | 801 | static struct focus_state * |
| 802 | ensure_focus_state(struct desktop_shell *shell, struct weston_seat *seat) |
| 803 | { |
| 804 | struct workspace *ws = get_current_workspace(shell); |
| 805 | struct focus_state *state; |
| 806 | |
| 807 | wl_list_for_each(state, &ws->focus_list, link) |
| 808 | if (state->seat == seat) |
| 809 | break; |
| 810 | |
| 811 | if (&state->link == &ws->focus_list) |
| 812 | state = focus_state_create(seat, ws); |
| 813 | |
| 814 | return state; |
| 815 | } |
| 816 | |
Jonas Ådahl | 0476974 | 2012-06-13 00:01:24 +0200 | [diff] [blame] | 817 | static void |
Kristian Høgsberg | d500bf1 | 2014-01-22 12:25:20 -0800 | [diff] [blame] | 818 | focus_state_set_focus(struct focus_state *state, |
| 819 | struct weston_surface *surface) |
| 820 | { |
| 821 | if (state->keyboard_focus) { |
| 822 | wl_list_remove(&state->surface_destroy_listener.link); |
| 823 | wl_list_init(&state->surface_destroy_listener.link); |
| 824 | } |
| 825 | |
| 826 | state->keyboard_focus = surface; |
| 827 | if (surface) |
| 828 | wl_signal_add(&surface->destroy_signal, |
| 829 | &state->surface_destroy_listener); |
| 830 | } |
| 831 | |
| 832 | static void |
Kristian Høgsberg | 2f5faff | 2012-07-31 16:36:34 -0400 | [diff] [blame] | 833 | restore_focus_state(struct desktop_shell *shell, struct workspace *ws) |
Jonas Ådahl | 0476974 | 2012-06-13 00:01:24 +0200 | [diff] [blame] | 834 | { |
| 835 | struct focus_state *state, *next; |
Kristian Høgsberg | fe7aa90 | 2013-05-08 09:54:37 -0400 | [diff] [blame] | 836 | struct weston_surface *surface; |
Neil Roberts | 4237f50 | 2014-04-09 16:33:31 +0100 | [diff] [blame] | 837 | struct wl_list pending_seat_list; |
| 838 | struct weston_seat *seat, *next_seat; |
| 839 | |
| 840 | /* Temporarily steal the list of seats so that we can keep |
| 841 | * track of the seats we've already processed */ |
| 842 | wl_list_init(&pending_seat_list); |
| 843 | wl_list_insert_list(&pending_seat_list, &shell->compositor->seat_list); |
| 844 | wl_list_init(&shell->compositor->seat_list); |
Jonas Ådahl | 0476974 | 2012-06-13 00:01:24 +0200 | [diff] [blame] | 845 | |
| 846 | wl_list_for_each_safe(state, next, &ws->focus_list, link) { |
Neil Roberts | 4237f50 | 2014-04-09 16:33:31 +0100 | [diff] [blame] | 847 | wl_list_remove(&state->seat->link); |
| 848 | wl_list_insert(&shell->compositor->seat_list, |
| 849 | &state->seat->link); |
| 850 | |
Kristian Høgsberg | e61d2f4 | 2014-01-17 12:18:53 -0800 | [diff] [blame] | 851 | if (state->seat->keyboard == NULL) |
| 852 | continue; |
| 853 | |
Kristian Høgsberg | fe7aa90 | 2013-05-08 09:54:37 -0400 | [diff] [blame] | 854 | surface = state->keyboard_focus; |
Jonas Ådahl | 5689944 | 2012-08-29 22:12:59 +0200 | [diff] [blame] | 855 | |
Kristian Høgsberg | e314875 | 2013-05-06 23:19:49 -0400 | [diff] [blame] | 856 | weston_keyboard_set_focus(state->seat->keyboard, surface); |
Jonas Ådahl | 0476974 | 2012-06-13 00:01:24 +0200 | [diff] [blame] | 857 | } |
Neil Roberts | 4237f50 | 2014-04-09 16:33:31 +0100 | [diff] [blame] | 858 | |
| 859 | /* For any remaining seats that we don't have a focus state |
| 860 | * for we'll reset the keyboard focus to NULL */ |
| 861 | wl_list_for_each_safe(seat, next_seat, &pending_seat_list, link) { |
| 862 | wl_list_insert(&shell->compositor->seat_list, &seat->link); |
| 863 | |
Ander Conselvan de Oliveira | 6e56ab4 | 2014-05-07 11:57:28 +0300 | [diff] [blame] | 864 | if (seat->keyboard == NULL) |
Neil Roberts | 4237f50 | 2014-04-09 16:33:31 +0100 | [diff] [blame] | 865 | continue; |
| 866 | |
| 867 | weston_keyboard_set_focus(seat->keyboard, NULL); |
| 868 | } |
Jonas Ådahl | 0476974 | 2012-06-13 00:01:24 +0200 | [diff] [blame] | 869 | } |
| 870 | |
| 871 | static void |
Jonas Ådahl | 8de6a1d | 2012-08-29 22:13:00 +0200 | [diff] [blame] | 872 | replace_focus_state(struct desktop_shell *shell, struct workspace *ws, |
| 873 | struct weston_seat *seat) |
| 874 | { |
| 875 | struct focus_state *state; |
Jonas Ådahl | 8de6a1d | 2012-08-29 22:13:00 +0200 | [diff] [blame] | 876 | |
| 877 | wl_list_for_each(state, &ws->focus_list, link) { |
| 878 | if (state->seat == seat) { |
Kristian Høgsberg | d500bf1 | 2014-01-22 12:25:20 -0800 | [diff] [blame] | 879 | focus_state_set_focus(state, seat->keyboard->focus); |
Jonas Ådahl | 8de6a1d | 2012-08-29 22:13:00 +0200 | [diff] [blame] | 880 | return; |
| 881 | } |
| 882 | } |
| 883 | } |
| 884 | |
| 885 | static void |
| 886 | drop_focus_state(struct desktop_shell *shell, struct workspace *ws, |
| 887 | struct weston_surface *surface) |
| 888 | { |
| 889 | struct focus_state *state; |
| 890 | |
| 891 | wl_list_for_each(state, &ws->focus_list, link) |
| 892 | if (state->keyboard_focus == surface) |
Kristian Høgsberg | d500bf1 | 2014-01-22 12:25:20 -0800 | [diff] [blame] | 893 | focus_state_set_focus(state, NULL); |
Jonas Ådahl | 8de6a1d | 2012-08-29 22:13:00 +0200 | [diff] [blame] | 894 | } |
| 895 | |
| 896 | static void |
Louis-Francis Ratté-Boulianne | b482dbd | 2013-11-19 11:37:11 +0100 | [diff] [blame] | 897 | animate_focus_change(struct desktop_shell *shell, struct workspace *ws, |
| 898 | struct weston_view *from, struct weston_view *to) |
| 899 | { |
| 900 | struct weston_output *output; |
| 901 | bool focus_surface_created = false; |
| 902 | |
| 903 | /* FIXME: Only support dim animation using two layers */ |
| 904 | if (from == to || shell->focus_animation_type != ANIMATION_DIM_LAYER) |
| 905 | return; |
| 906 | |
| 907 | output = get_default_output(shell->compositor); |
| 908 | if (ws->fsurf_front == NULL && (from || to)) { |
| 909 | ws->fsurf_front = create_focus_surface(shell->compositor, output); |
U. Artie Eoff | 0b23b2b | 2014-01-15 14:45:59 -0800 | [diff] [blame] | 910 | if (ws->fsurf_front == NULL) |
| 911 | return; |
Louis-Francis Ratté-Boulianne | b482dbd | 2013-11-19 11:37:11 +0100 | [diff] [blame] | 912 | ws->fsurf_front->view->alpha = 0.0; |
U. Artie Eoff | 0b23b2b | 2014-01-15 14:45:59 -0800 | [diff] [blame] | 913 | |
| 914 | ws->fsurf_back = create_focus_surface(shell->compositor, output); |
| 915 | if (ws->fsurf_back == NULL) { |
| 916 | focus_surface_destroy(ws->fsurf_front); |
| 917 | return; |
| 918 | } |
Louis-Francis Ratté-Boulianne | b482dbd | 2013-11-19 11:37:11 +0100 | [diff] [blame] | 919 | ws->fsurf_back->view->alpha = 0.0; |
U. Artie Eoff | 0b23b2b | 2014-01-15 14:45:59 -0800 | [diff] [blame] | 920 | |
Louis-Francis Ratté-Boulianne | b482dbd | 2013-11-19 11:37:11 +0100 | [diff] [blame] | 921 | focus_surface_created = true; |
| 922 | } else { |
Giulio Camuffo | 412e6a5 | 2014-07-09 22:12:56 +0300 | [diff] [blame] | 923 | weston_layer_entry_remove(&ws->fsurf_front->view->layer_link); |
| 924 | weston_layer_entry_remove(&ws->fsurf_back->view->layer_link); |
Louis-Francis Ratté-Boulianne | b482dbd | 2013-11-19 11:37:11 +0100 | [diff] [blame] | 925 | } |
| 926 | |
| 927 | if (ws->focus_animation) { |
| 928 | weston_view_animation_destroy(ws->focus_animation); |
| 929 | ws->focus_animation = NULL; |
| 930 | } |
| 931 | |
| 932 | if (to) |
Giulio Camuffo | 412e6a5 | 2014-07-09 22:12:56 +0300 | [diff] [blame] | 933 | weston_layer_entry_insert(&to->layer_link, |
| 934 | &ws->fsurf_front->view->layer_link); |
Louis-Francis Ratté-Boulianne | b482dbd | 2013-11-19 11:37:11 +0100 | [diff] [blame] | 935 | else if (from) |
Giulio Camuffo | 412e6a5 | 2014-07-09 22:12:56 +0300 | [diff] [blame] | 936 | weston_layer_entry_insert(&ws->layer.view_list, |
| 937 | &ws->fsurf_front->view->layer_link); |
Louis-Francis Ratté-Boulianne | b482dbd | 2013-11-19 11:37:11 +0100 | [diff] [blame] | 938 | |
| 939 | if (focus_surface_created) { |
| 940 | ws->focus_animation = weston_fade_run( |
| 941 | ws->fsurf_front->view, |
Jonny Lamb | 7e7d485 | 2014-05-22 22:41:34 +0200 | [diff] [blame] | 942 | ws->fsurf_front->view->alpha, 0.4, 300, |
Louis-Francis Ratté-Boulianne | b482dbd | 2013-11-19 11:37:11 +0100 | [diff] [blame] | 943 | focus_animation_done, ws); |
| 944 | } else if (from) { |
Giulio Camuffo | 412e6a5 | 2014-07-09 22:12:56 +0300 | [diff] [blame] | 945 | weston_layer_entry_insert(&from->layer_link, |
| 946 | &ws->fsurf_back->view->layer_link); |
Louis-Francis Ratté-Boulianne | b482dbd | 2013-11-19 11:37:11 +0100 | [diff] [blame] | 947 | ws->focus_animation = weston_stable_fade_run( |
| 948 | ws->fsurf_front->view, 0.0, |
Jonny Lamb | 7e7d485 | 2014-05-22 22:41:34 +0200 | [diff] [blame] | 949 | ws->fsurf_back->view, 0.4, |
Louis-Francis Ratté-Boulianne | b482dbd | 2013-11-19 11:37:11 +0100 | [diff] [blame] | 950 | focus_animation_done, ws); |
| 951 | } else if (to) { |
Giulio Camuffo | 412e6a5 | 2014-07-09 22:12:56 +0300 | [diff] [blame] | 952 | weston_layer_entry_insert(&ws->layer.view_list, |
| 953 | &ws->fsurf_back->view->layer_link); |
Louis-Francis Ratté-Boulianne | b482dbd | 2013-11-19 11:37:11 +0100 | [diff] [blame] | 954 | ws->focus_animation = weston_stable_fade_run( |
| 955 | ws->fsurf_front->view, 0.0, |
Jonny Lamb | 7e7d485 | 2014-05-22 22:41:34 +0200 | [diff] [blame] | 956 | ws->fsurf_back->view, 0.4, |
Louis-Francis Ratté-Boulianne | b482dbd | 2013-11-19 11:37:11 +0100 | [diff] [blame] | 957 | focus_animation_done, ws); |
| 958 | } |
| 959 | } |
| 960 | |
| 961 | static void |
Jonas Ådahl | e3cddce | 2012-06-13 00:01:22 +0200 | [diff] [blame] | 962 | workspace_destroy(struct workspace *ws) |
| 963 | { |
Jonas Ådahl | 0476974 | 2012-06-13 00:01:24 +0200 | [diff] [blame] | 964 | struct focus_state *state, *next; |
| 965 | |
| 966 | wl_list_for_each_safe(state, next, &ws->focus_list, link) |
| 967 | focus_state_destroy(state); |
| 968 | |
Louis-Francis Ratté-Boulianne | b482dbd | 2013-11-19 11:37:11 +0100 | [diff] [blame] | 969 | if (ws->fsurf_front) |
| 970 | focus_surface_destroy(ws->fsurf_front); |
| 971 | if (ws->fsurf_back) |
| 972 | focus_surface_destroy(ws->fsurf_back); |
| 973 | |
Jonas Ådahl | e3cddce | 2012-06-13 00:01:22 +0200 | [diff] [blame] | 974 | free(ws); |
| 975 | } |
| 976 | |
Jonas Ådahl | 0476974 | 2012-06-13 00:01:24 +0200 | [diff] [blame] | 977 | static void |
| 978 | seat_destroyed(struct wl_listener *listener, void *data) |
| 979 | { |
| 980 | struct weston_seat *seat = data; |
| 981 | struct focus_state *state, *next; |
| 982 | struct workspace *ws = container_of(listener, |
| 983 | struct workspace, |
| 984 | seat_destroyed_listener); |
| 985 | |
| 986 | wl_list_for_each_safe(state, next, &ws->focus_list, link) |
| 987 | if (state->seat == seat) |
| 988 | wl_list_remove(&state->link); |
| 989 | } |
| 990 | |
Jonas Ådahl | e3cddce | 2012-06-13 00:01:22 +0200 | [diff] [blame] | 991 | static struct workspace * |
| 992 | workspace_create(void) |
| 993 | { |
| 994 | struct workspace *ws = malloc(sizeof *ws); |
| 995 | if (ws == NULL) |
| 996 | return NULL; |
| 997 | |
| 998 | weston_layer_init(&ws->layer, NULL); |
| 999 | |
Jonas Ådahl | 0476974 | 2012-06-13 00:01:24 +0200 | [diff] [blame] | 1000 | wl_list_init(&ws->focus_list); |
| 1001 | wl_list_init(&ws->seat_destroyed_listener.link); |
| 1002 | ws->seat_destroyed_listener.notify = seat_destroyed; |
Louis-Francis Ratté-Boulianne | b482dbd | 2013-11-19 11:37:11 +0100 | [diff] [blame] | 1003 | ws->fsurf_front = NULL; |
| 1004 | ws->fsurf_back = NULL; |
| 1005 | ws->focus_animation = NULL; |
Jonas Ådahl | 0476974 | 2012-06-13 00:01:24 +0200 | [diff] [blame] | 1006 | |
Jonas Ådahl | e3cddce | 2012-06-13 00:01:22 +0200 | [diff] [blame] | 1007 | return ws; |
| 1008 | } |
| 1009 | |
Jonas Ådahl | 62fcd04 | 2012-06-13 00:01:23 +0200 | [diff] [blame] | 1010 | static int |
| 1011 | workspace_is_empty(struct workspace *ws) |
| 1012 | { |
Giulio Camuffo | 412e6a5 | 2014-07-09 22:12:56 +0300 | [diff] [blame] | 1013 | return wl_list_empty(&ws->layer.view_list.link); |
Jonas Ådahl | 62fcd04 | 2012-06-13 00:01:23 +0200 | [diff] [blame] | 1014 | } |
| 1015 | |
Jonas Ådahl | e3cddce | 2012-06-13 00:01:22 +0200 | [diff] [blame] | 1016 | static struct workspace * |
| 1017 | get_workspace(struct desktop_shell *shell, unsigned int index) |
| 1018 | { |
| 1019 | struct workspace **pws = shell->workspaces.array.data; |
Philipp Brüschweiler | 067abf6 | 2012-09-01 16:03:05 +0200 | [diff] [blame] | 1020 | assert(index < shell->workspaces.num); |
Jonas Ådahl | e3cddce | 2012-06-13 00:01:22 +0200 | [diff] [blame] | 1021 | pws += index; |
| 1022 | return *pws; |
| 1023 | } |
| 1024 | |
Kristian Høgsberg | 1ef2313 | 2013-12-04 00:20:01 -0800 | [diff] [blame] | 1025 | struct workspace * |
Jonas Ådahl | e3cddce | 2012-06-13 00:01:22 +0200 | [diff] [blame] | 1026 | get_current_workspace(struct desktop_shell *shell) |
| 1027 | { |
| 1028 | return get_workspace(shell, shell->workspaces.current); |
| 1029 | } |
| 1030 | |
| 1031 | static void |
| 1032 | activate_workspace(struct desktop_shell *shell, unsigned int index) |
| 1033 | { |
| 1034 | struct workspace *ws; |
| 1035 | |
| 1036 | ws = get_workspace(shell, index); |
| 1037 | wl_list_insert(&shell->panel_layer.link, &ws->layer.link); |
| 1038 | |
| 1039 | shell->workspaces.current = index; |
| 1040 | } |
| 1041 | |
Jonas Ådahl | 62fcd04 | 2012-06-13 00:01:23 +0200 | [diff] [blame] | 1042 | static unsigned int |
| 1043 | get_output_height(struct weston_output *output) |
| 1044 | { |
| 1045 | return abs(output->region.extents.y1 - output->region.extents.y2); |
| 1046 | } |
| 1047 | |
| 1048 | static void |
Louis-Francis Ratté-Boulianne | b482dbd | 2013-11-19 11:37:11 +0100 | [diff] [blame] | 1049 | view_translate(struct workspace *ws, struct weston_view *view, double d) |
Jonas Ådahl | 62fcd04 | 2012-06-13 00:01:23 +0200 | [diff] [blame] | 1050 | { |
Jonas Ådahl | 62fcd04 | 2012-06-13 00:01:23 +0200 | [diff] [blame] | 1051 | struct weston_transform *transform; |
| 1052 | |
Louis-Francis Ratté-Boulianne | b482dbd | 2013-11-19 11:37:11 +0100 | [diff] [blame] | 1053 | if (is_focus_view(view)) { |
| 1054 | struct focus_surface *fsurf = get_focus_surface(view->surface); |
| 1055 | transform = &fsurf->workspace_transform; |
| 1056 | } else { |
| 1057 | struct shell_surface *shsurf = get_shell_surface(view->surface); |
| 1058 | transform = &shsurf->workspace_transform; |
| 1059 | } |
| 1060 | |
Jonas Ådahl | 62fcd04 | 2012-06-13 00:01:23 +0200 | [diff] [blame] | 1061 | if (wl_list_empty(&transform->link)) |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 1062 | wl_list_insert(view->geometry.transformation_list.prev, |
Louis-Francis Ratté-Boulianne | b482dbd | 2013-11-19 11:37:11 +0100 | [diff] [blame] | 1063 | &transform->link); |
Jonas Ådahl | 62fcd04 | 2012-06-13 00:01:23 +0200 | [diff] [blame] | 1064 | |
Louis-Francis Ratté-Boulianne | b482dbd | 2013-11-19 11:37:11 +0100 | [diff] [blame] | 1065 | weston_matrix_init(&transform->matrix); |
| 1066 | weston_matrix_translate(&transform->matrix, |
Jonas Ådahl | 62fcd04 | 2012-06-13 00:01:23 +0200 | [diff] [blame] | 1067 | 0.0, d, 0.0); |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 1068 | weston_view_geometry_dirty(view); |
Jonas Ådahl | 62fcd04 | 2012-06-13 00:01:23 +0200 | [diff] [blame] | 1069 | } |
| 1070 | |
| 1071 | static void |
| 1072 | workspace_translate_out(struct workspace *ws, double fraction) |
| 1073 | { |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 1074 | struct weston_view *view; |
Jonas Ådahl | 62fcd04 | 2012-06-13 00:01:23 +0200 | [diff] [blame] | 1075 | unsigned int height; |
| 1076 | double d; |
| 1077 | |
Giulio Camuffo | 412e6a5 | 2014-07-09 22:12:56 +0300 | [diff] [blame] | 1078 | 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] | 1079 | height = get_output_height(view->surface->output); |
Jonas Ådahl | 62fcd04 | 2012-06-13 00:01:23 +0200 | [diff] [blame] | 1080 | d = height * fraction; |
| 1081 | |
Louis-Francis Ratté-Boulianne | b482dbd | 2013-11-19 11:37:11 +0100 | [diff] [blame] | 1082 | view_translate(ws, view, d); |
Jonas Ådahl | 62fcd04 | 2012-06-13 00:01:23 +0200 | [diff] [blame] | 1083 | } |
| 1084 | } |
| 1085 | |
| 1086 | static void |
| 1087 | workspace_translate_in(struct workspace *ws, double fraction) |
| 1088 | { |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 1089 | struct weston_view *view; |
Jonas Ådahl | 62fcd04 | 2012-06-13 00:01:23 +0200 | [diff] [blame] | 1090 | unsigned int height; |
| 1091 | double d; |
| 1092 | |
Giulio Camuffo | 412e6a5 | 2014-07-09 22:12:56 +0300 | [diff] [blame] | 1093 | 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] | 1094 | height = get_output_height(view->surface->output); |
Jonas Ådahl | 62fcd04 | 2012-06-13 00:01:23 +0200 | [diff] [blame] | 1095 | |
| 1096 | if (fraction > 0) |
| 1097 | d = -(height - height * fraction); |
| 1098 | else |
| 1099 | d = height + height * fraction; |
| 1100 | |
Louis-Francis Ratté-Boulianne | b482dbd | 2013-11-19 11:37:11 +0100 | [diff] [blame] | 1101 | view_translate(ws, view, d); |
Jonas Ådahl | 62fcd04 | 2012-06-13 00:01:23 +0200 | [diff] [blame] | 1102 | } |
| 1103 | } |
| 1104 | |
| 1105 | static void |
Jonas Ådahl | e9d2250 | 2012-08-29 22:13:01 +0200 | [diff] [blame] | 1106 | broadcast_current_workspace_state(struct desktop_shell *shell) |
| 1107 | { |
Kristian Høgsberg | 2e3c396 | 2013-09-11 12:00:47 -0700 | [diff] [blame] | 1108 | struct wl_resource *resource; |
Jonas Ådahl | e9d2250 | 2012-08-29 22:13:01 +0200 | [diff] [blame] | 1109 | |
Kristian Høgsberg | 2e3c396 | 2013-09-11 12:00:47 -0700 | [diff] [blame] | 1110 | wl_resource_for_each(resource, &shell->workspaces.client_list) |
| 1111 | workspace_manager_send_state(resource, |
Jonas Ådahl | e9d2250 | 2012-08-29 22:13:01 +0200 | [diff] [blame] | 1112 | shell->workspaces.current, |
| 1113 | shell->workspaces.num); |
| 1114 | } |
| 1115 | |
| 1116 | static void |
Jonas Ådahl | 62fcd04 | 2012-06-13 00:01:23 +0200 | [diff] [blame] | 1117 | reverse_workspace_change_animation(struct desktop_shell *shell, |
| 1118 | unsigned int index, |
| 1119 | struct workspace *from, |
| 1120 | struct workspace *to) |
| 1121 | { |
| 1122 | shell->workspaces.current = index; |
| 1123 | |
| 1124 | shell->workspaces.anim_to = to; |
| 1125 | shell->workspaces.anim_from = from; |
| 1126 | shell->workspaces.anim_dir = -1 * shell->workspaces.anim_dir; |
| 1127 | shell->workspaces.anim_timestamp = 0; |
| 1128 | |
Scott Moreau | 4272e63 | 2012-08-13 09:58:41 -0600 | [diff] [blame] | 1129 | weston_compositor_schedule_repaint(shell->compositor); |
Jonas Ådahl | 62fcd04 | 2012-06-13 00:01:23 +0200 | [diff] [blame] | 1130 | } |
| 1131 | |
| 1132 | static void |
| 1133 | workspace_deactivate_transforms(struct workspace *ws) |
| 1134 | { |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 1135 | struct weston_view *view; |
Louis-Francis Ratté-Boulianne | b482dbd | 2013-11-19 11:37:11 +0100 | [diff] [blame] | 1136 | struct weston_transform *transform; |
Jonas Ådahl | 62fcd04 | 2012-06-13 00:01:23 +0200 | [diff] [blame] | 1137 | |
Giulio Camuffo | 412e6a5 | 2014-07-09 22:12:56 +0300 | [diff] [blame] | 1138 | 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] | 1139 | if (is_focus_view(view)) { |
| 1140 | struct focus_surface *fsurf = get_focus_surface(view->surface); |
| 1141 | transform = &fsurf->workspace_transform; |
| 1142 | } else { |
| 1143 | struct shell_surface *shsurf = get_shell_surface(view->surface); |
| 1144 | transform = &shsurf->workspace_transform; |
| 1145 | } |
| 1146 | |
| 1147 | if (!wl_list_empty(&transform->link)) { |
| 1148 | wl_list_remove(&transform->link); |
| 1149 | wl_list_init(&transform->link); |
Jonas Ådahl | 8de6a1d | 2012-08-29 22:13:00 +0200 | [diff] [blame] | 1150 | } |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 1151 | weston_view_geometry_dirty(view); |
Jonas Ådahl | 62fcd04 | 2012-06-13 00:01:23 +0200 | [diff] [blame] | 1152 | } |
| 1153 | } |
| 1154 | |
| 1155 | static void |
| 1156 | finish_workspace_change_animation(struct desktop_shell *shell, |
| 1157 | struct workspace *from, |
| 1158 | struct workspace *to) |
| 1159 | { |
Ander Conselvan de Oliveira | 9c6217e | 2014-05-07 11:57:26 +0300 | [diff] [blame] | 1160 | struct weston_view *view; |
| 1161 | |
Scott Moreau | 4272e63 | 2012-08-13 09:58:41 -0600 | [diff] [blame] | 1162 | weston_compositor_schedule_repaint(shell->compositor); |
Jonas Ådahl | 62fcd04 | 2012-06-13 00:01:23 +0200 | [diff] [blame] | 1163 | |
Ander Conselvan de Oliveira | 9c6217e | 2014-05-07 11:57:26 +0300 | [diff] [blame] | 1164 | /* Views that extend past the bottom of the output are still |
| 1165 | * visible after the workspace animation ends but before its layer |
| 1166 | * is hidden. In that case, we need to damage below those views so |
| 1167 | * that the screen is properly repainted. */ |
Giulio Camuffo | 412e6a5 | 2014-07-09 22:12:56 +0300 | [diff] [blame] | 1168 | 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] | 1169 | weston_view_damage_below(view); |
| 1170 | |
Jonas Ådahl | 62fcd04 | 2012-06-13 00:01:23 +0200 | [diff] [blame] | 1171 | wl_list_remove(&shell->workspaces.animation.link); |
| 1172 | workspace_deactivate_transforms(from); |
| 1173 | workspace_deactivate_transforms(to); |
| 1174 | shell->workspaces.anim_to = NULL; |
| 1175 | |
| 1176 | wl_list_remove(&shell->workspaces.anim_from->layer.link); |
| 1177 | } |
| 1178 | |
| 1179 | static void |
| 1180 | animate_workspace_change_frame(struct weston_animation *animation, |
| 1181 | struct weston_output *output, uint32_t msecs) |
| 1182 | { |
| 1183 | struct desktop_shell *shell = |
| 1184 | container_of(animation, struct desktop_shell, |
| 1185 | workspaces.animation); |
| 1186 | struct workspace *from = shell->workspaces.anim_from; |
| 1187 | struct workspace *to = shell->workspaces.anim_to; |
| 1188 | uint32_t t; |
| 1189 | double x, y; |
| 1190 | |
| 1191 | if (workspace_is_empty(from) && workspace_is_empty(to)) { |
| 1192 | finish_workspace_change_animation(shell, from, to); |
| 1193 | return; |
| 1194 | } |
| 1195 | |
| 1196 | if (shell->workspaces.anim_timestamp == 0) { |
| 1197 | if (shell->workspaces.anim_current == 0.0) |
| 1198 | shell->workspaces.anim_timestamp = msecs; |
| 1199 | else |
| 1200 | shell->workspaces.anim_timestamp = |
| 1201 | msecs - |
| 1202 | /* Invers of movement function 'y' below. */ |
| 1203 | (asin(1.0 - shell->workspaces.anim_current) * |
| 1204 | DEFAULT_WORKSPACE_CHANGE_ANIMATION_LENGTH * |
| 1205 | M_2_PI); |
| 1206 | } |
| 1207 | |
| 1208 | t = msecs - shell->workspaces.anim_timestamp; |
| 1209 | |
| 1210 | /* |
| 1211 | * x = [0, π/2] |
| 1212 | * y(x) = sin(x) |
| 1213 | */ |
| 1214 | x = t * (1.0/DEFAULT_WORKSPACE_CHANGE_ANIMATION_LENGTH) * M_PI_2; |
| 1215 | y = sin(x); |
| 1216 | |
| 1217 | if (t < DEFAULT_WORKSPACE_CHANGE_ANIMATION_LENGTH) { |
Scott Moreau | 4272e63 | 2012-08-13 09:58:41 -0600 | [diff] [blame] | 1218 | weston_compositor_schedule_repaint(shell->compositor); |
Jonas Ådahl | 62fcd04 | 2012-06-13 00:01:23 +0200 | [diff] [blame] | 1219 | |
| 1220 | workspace_translate_out(from, shell->workspaces.anim_dir * y); |
| 1221 | workspace_translate_in(to, shell->workspaces.anim_dir * y); |
| 1222 | shell->workspaces.anim_current = y; |
| 1223 | |
Scott Moreau | 4272e63 | 2012-08-13 09:58:41 -0600 | [diff] [blame] | 1224 | weston_compositor_schedule_repaint(shell->compositor); |
Jonas Ådahl | 62fcd04 | 2012-06-13 00:01:23 +0200 | [diff] [blame] | 1225 | } |
Jonas Ådahl | 0476974 | 2012-06-13 00:01:24 +0200 | [diff] [blame] | 1226 | else |
Jonas Ådahl | 62fcd04 | 2012-06-13 00:01:23 +0200 | [diff] [blame] | 1227 | finish_workspace_change_animation(shell, from, to); |
Jonas Ådahl | 62fcd04 | 2012-06-13 00:01:23 +0200 | [diff] [blame] | 1228 | } |
| 1229 | |
| 1230 | static void |
| 1231 | animate_workspace_change(struct desktop_shell *shell, |
| 1232 | unsigned int index, |
| 1233 | struct workspace *from, |
| 1234 | struct workspace *to) |
| 1235 | { |
| 1236 | struct weston_output *output; |
| 1237 | |
| 1238 | int dir; |
| 1239 | |
| 1240 | if (index > shell->workspaces.current) |
| 1241 | dir = -1; |
| 1242 | else |
| 1243 | dir = 1; |
| 1244 | |
| 1245 | shell->workspaces.current = index; |
| 1246 | |
| 1247 | shell->workspaces.anim_dir = dir; |
| 1248 | shell->workspaces.anim_from = from; |
| 1249 | shell->workspaces.anim_to = to; |
| 1250 | shell->workspaces.anim_current = 0.0; |
| 1251 | shell->workspaces.anim_timestamp = 0; |
| 1252 | |
| 1253 | output = container_of(shell->compositor->output_list.next, |
| 1254 | struct weston_output, link); |
| 1255 | wl_list_insert(&output->animation_list, |
| 1256 | &shell->workspaces.animation.link); |
| 1257 | |
Jonas Ådahl | 8de6a1d | 2012-08-29 22:13:00 +0200 | [diff] [blame] | 1258 | wl_list_insert(from->layer.link.prev, &to->layer.link); |
Jonas Ådahl | 62fcd04 | 2012-06-13 00:01:23 +0200 | [diff] [blame] | 1259 | |
| 1260 | workspace_translate_in(to, 0); |
| 1261 | |
Kristian Høgsberg | 2f5faff | 2012-07-31 16:36:34 -0400 | [diff] [blame] | 1262 | restore_focus_state(shell, to); |
Jonas Ådahl | 0476974 | 2012-06-13 00:01:24 +0200 | [diff] [blame] | 1263 | |
Scott Moreau | 4272e63 | 2012-08-13 09:58:41 -0600 | [diff] [blame] | 1264 | weston_compositor_schedule_repaint(shell->compositor); |
Jonas Ådahl | 62fcd04 | 2012-06-13 00:01:23 +0200 | [diff] [blame] | 1265 | } |
| 1266 | |
Jonas Ådahl | e3cddce | 2012-06-13 00:01:22 +0200 | [diff] [blame] | 1267 | static void |
Jonas Ådahl | 8de6a1d | 2012-08-29 22:13:00 +0200 | [diff] [blame] | 1268 | update_workspace(struct desktop_shell *shell, unsigned int index, |
| 1269 | struct workspace *from, struct workspace *to) |
| 1270 | { |
| 1271 | shell->workspaces.current = index; |
| 1272 | wl_list_insert(&from->layer.link, &to->layer.link); |
| 1273 | wl_list_remove(&from->layer.link); |
| 1274 | } |
| 1275 | |
| 1276 | static void |
Jonas Ådahl | e3cddce | 2012-06-13 00:01:22 +0200 | [diff] [blame] | 1277 | change_workspace(struct desktop_shell *shell, unsigned int index) |
| 1278 | { |
| 1279 | struct workspace *from; |
| 1280 | struct workspace *to; |
Louis-Francis Ratté-Boulianne | b482dbd | 2013-11-19 11:37:11 +0100 | [diff] [blame] | 1281 | struct focus_state *state; |
Jonas Ådahl | e3cddce | 2012-06-13 00:01:22 +0200 | [diff] [blame] | 1282 | |
| 1283 | if (index == shell->workspaces.current) |
| 1284 | return; |
| 1285 | |
| 1286 | /* Don't change workspace when there is any fullscreen surfaces. */ |
Giulio Camuffo | 412e6a5 | 2014-07-09 22:12:56 +0300 | [diff] [blame] | 1287 | if (!wl_list_empty(&shell->fullscreen_layer.view_list.link)) |
Jonas Ådahl | e3cddce | 2012-06-13 00:01:22 +0200 | [diff] [blame] | 1288 | return; |
| 1289 | |
Jonas Ådahl | e3cddce | 2012-06-13 00:01:22 +0200 | [diff] [blame] | 1290 | from = get_current_workspace(shell); |
| 1291 | to = get_workspace(shell, index); |
| 1292 | |
Jonas Ådahl | 62fcd04 | 2012-06-13 00:01:23 +0200 | [diff] [blame] | 1293 | if (shell->workspaces.anim_from == to && |
| 1294 | shell->workspaces.anim_to == from) { |
Jonas Ådahl | 8de6a1d | 2012-08-29 22:13:00 +0200 | [diff] [blame] | 1295 | restore_focus_state(shell, to); |
Jonas Ådahl | 62fcd04 | 2012-06-13 00:01:23 +0200 | [diff] [blame] | 1296 | reverse_workspace_change_animation(shell, index, from, to); |
Jonas Ådahl | e9d2250 | 2012-08-29 22:13:01 +0200 | [diff] [blame] | 1297 | broadcast_current_workspace_state(shell); |
Jonas Ådahl | 62fcd04 | 2012-06-13 00:01:23 +0200 | [diff] [blame] | 1298 | return; |
| 1299 | } |
Jonas Ådahl | e3cddce | 2012-06-13 00:01:22 +0200 | [diff] [blame] | 1300 | |
Jonas Ådahl | 62fcd04 | 2012-06-13 00:01:23 +0200 | [diff] [blame] | 1301 | if (shell->workspaces.anim_to != NULL) |
| 1302 | finish_workspace_change_animation(shell, |
| 1303 | shell->workspaces.anim_from, |
| 1304 | shell->workspaces.anim_to); |
| 1305 | |
Jonas Ådahl | 8de6a1d | 2012-08-29 22:13:00 +0200 | [diff] [blame] | 1306 | restore_focus_state(shell, to); |
Jonas Ådahl | 0476974 | 2012-06-13 00:01:24 +0200 | [diff] [blame] | 1307 | |
Louis-Francis Ratté-Boulianne | b482dbd | 2013-11-19 11:37:11 +0100 | [diff] [blame] | 1308 | if (shell->focus_animation_type != ANIMATION_NONE) { |
| 1309 | wl_list_for_each(state, &from->focus_list, link) |
| 1310 | if (state->keyboard_focus) |
| 1311 | animate_focus_change(shell, from, |
| 1312 | get_default_view(state->keyboard_focus), NULL); |
| 1313 | |
| 1314 | wl_list_for_each(state, &to->focus_list, link) |
| 1315 | if (state->keyboard_focus) |
| 1316 | animate_focus_change(shell, to, |
| 1317 | NULL, get_default_view(state->keyboard_focus)); |
| 1318 | } |
| 1319 | |
Jonas Ådahl | 8de6a1d | 2012-08-29 22:13:00 +0200 | [diff] [blame] | 1320 | if (workspace_is_empty(to) && workspace_is_empty(from)) |
| 1321 | update_workspace(shell, index, from, to); |
Jonas Ådahl | 62fcd04 | 2012-06-13 00:01:23 +0200 | [diff] [blame] | 1322 | else |
| 1323 | animate_workspace_change(shell, index, from, to); |
Jonas Ådahl | e9d2250 | 2012-08-29 22:13:01 +0200 | [diff] [blame] | 1324 | |
| 1325 | broadcast_current_workspace_state(shell); |
Pekka Paalanen | e955f1e | 2011-12-07 11:49:52 +0200 | [diff] [blame] | 1326 | } |
| 1327 | |
Jonas Ådahl | 8de6a1d | 2012-08-29 22:13:00 +0200 | [diff] [blame] | 1328 | static bool |
| 1329 | workspace_has_only(struct workspace *ws, struct weston_surface *surface) |
| 1330 | { |
Giulio Camuffo | 412e6a5 | 2014-07-09 22:12:56 +0300 | [diff] [blame] | 1331 | struct wl_list *list = &ws->layer.view_list.link; |
Jonas Ådahl | 8de6a1d | 2012-08-29 22:13:00 +0200 | [diff] [blame] | 1332 | struct wl_list *e; |
| 1333 | |
| 1334 | if (wl_list_empty(list)) |
| 1335 | return false; |
| 1336 | |
| 1337 | e = list->next; |
| 1338 | |
| 1339 | if (e->next != list) |
| 1340 | return false; |
| 1341 | |
Giulio Camuffo | 412e6a5 | 2014-07-09 22:12:56 +0300 | [diff] [blame] | 1342 | return container_of(e, struct weston_view, layer_link.link)->surface == surface; |
Jonas Ådahl | 8de6a1d | 2012-08-29 22:13:00 +0200 | [diff] [blame] | 1343 | } |
| 1344 | |
| 1345 | static void |
Philip Withnall | 659163d | 2013-11-25 18:01:36 +0000 | [diff] [blame] | 1346 | move_surface_to_workspace(struct desktop_shell *shell, |
| 1347 | struct shell_surface *shsurf, |
| 1348 | uint32_t workspace) |
Jonas Ådahl | e9d2250 | 2012-08-29 22:13:01 +0200 | [diff] [blame] | 1349 | { |
| 1350 | struct workspace *from; |
| 1351 | struct workspace *to; |
| 1352 | struct weston_seat *seat; |
Pekka Paalanen | 01388e2 | 2013-04-25 13:57:44 +0300 | [diff] [blame] | 1353 | struct weston_surface *focus; |
Philip Withnall | 659163d | 2013-11-25 18:01:36 +0000 | [diff] [blame] | 1354 | struct weston_view *view; |
Jonas Ådahl | e9d2250 | 2012-08-29 22:13:01 +0200 | [diff] [blame] | 1355 | |
| 1356 | if (workspace == shell->workspaces.current) |
| 1357 | return; |
| 1358 | |
Philip Withnall | 659163d | 2013-11-25 18:01:36 +0000 | [diff] [blame] | 1359 | view = get_default_view(shsurf->surface); |
| 1360 | if (!view) |
| 1361 | return; |
| 1362 | |
| 1363 | assert(weston_surface_get_main_surface(view->surface) == view->surface); |
| 1364 | |
Philipp Brüschweiler | 067abf6 | 2012-09-01 16:03:05 +0200 | [diff] [blame] | 1365 | if (workspace >= shell->workspaces.num) |
| 1366 | workspace = shell->workspaces.num - 1; |
| 1367 | |
Jonas Ådahl | e9d2250 | 2012-08-29 22:13:01 +0200 | [diff] [blame] | 1368 | from = get_current_workspace(shell); |
| 1369 | to = get_workspace(shell, workspace); |
| 1370 | |
Giulio Camuffo | 412e6a5 | 2014-07-09 22:12:56 +0300 | [diff] [blame] | 1371 | weston_layer_entry_remove(&view->layer_link); |
| 1372 | weston_layer_entry_insert(&to->layer.view_list, &view->layer_link); |
Jonas Ådahl | e9d2250 | 2012-08-29 22:13:01 +0200 | [diff] [blame] | 1373 | |
Philip Withnall | 648a4dd | 2013-11-25 18:01:44 +0000 | [diff] [blame] | 1374 | shell_surface_update_child_surface_layers(shsurf); |
| 1375 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 1376 | drop_focus_state(shell, from, view->surface); |
Pekka Paalanen | 01388e2 | 2013-04-25 13:57:44 +0300 | [diff] [blame] | 1377 | wl_list_for_each(seat, &shell->compositor->seat_list, link) { |
| 1378 | if (!seat->keyboard) |
| 1379 | continue; |
| 1380 | |
| 1381 | focus = weston_surface_get_main_surface(seat->keyboard->focus); |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 1382 | if (focus == view->surface) |
Kristian Høgsberg | e314875 | 2013-05-06 23:19:49 -0400 | [diff] [blame] | 1383 | weston_keyboard_set_focus(seat->keyboard, NULL); |
Pekka Paalanen | 01388e2 | 2013-04-25 13:57:44 +0300 | [diff] [blame] | 1384 | } |
Jonas Ådahl | e9d2250 | 2012-08-29 22:13:01 +0200 | [diff] [blame] | 1385 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 1386 | weston_view_damage_below(view); |
Jonas Ådahl | e9d2250 | 2012-08-29 22:13:01 +0200 | [diff] [blame] | 1387 | } |
| 1388 | |
| 1389 | static void |
Jonas Ådahl | 8de6a1d | 2012-08-29 22:13:00 +0200 | [diff] [blame] | 1390 | take_surface_to_workspace_by_seat(struct desktop_shell *shell, |
Kristian Høgsberg | e314875 | 2013-05-06 23:19:49 -0400 | [diff] [blame] | 1391 | struct weston_seat *seat, |
Jonas Ådahl | 8de6a1d | 2012-08-29 22:13:00 +0200 | [diff] [blame] | 1392 | unsigned int index) |
| 1393 | { |
Pekka Paalanen | 01388e2 | 2013-04-25 13:57:44 +0300 | [diff] [blame] | 1394 | struct weston_surface *surface; |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 1395 | struct weston_view *view; |
Jonas Ådahl | 8de6a1d | 2012-08-29 22:13:00 +0200 | [diff] [blame] | 1396 | struct shell_surface *shsurf; |
| 1397 | struct workspace *from; |
| 1398 | struct workspace *to; |
Jonas Ådahl | 8538b22 | 2012-08-29 22:13:03 +0200 | [diff] [blame] | 1399 | struct focus_state *state; |
Jonas Ådahl | 8de6a1d | 2012-08-29 22:13:00 +0200 | [diff] [blame] | 1400 | |
Pekka Paalanen | 01388e2 | 2013-04-25 13:57:44 +0300 | [diff] [blame] | 1401 | surface = weston_surface_get_main_surface(seat->keyboard->focus); |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 1402 | view = get_default_view(surface); |
| 1403 | if (view == NULL || |
Louis-Francis Ratté-Boulianne | b482dbd | 2013-11-19 11:37:11 +0100 | [diff] [blame] | 1404 | index == shell->workspaces.current || |
| 1405 | is_focus_view(view)) |
Jonas Ådahl | 8de6a1d | 2012-08-29 22:13:00 +0200 | [diff] [blame] | 1406 | return; |
| 1407 | |
| 1408 | from = get_current_workspace(shell); |
| 1409 | to = get_workspace(shell, index); |
| 1410 | |
Giulio Camuffo | 412e6a5 | 2014-07-09 22:12:56 +0300 | [diff] [blame] | 1411 | weston_layer_entry_remove(&view->layer_link); |
| 1412 | weston_layer_entry_insert(&to->layer.view_list, &view->layer_link); |
Jonas Ådahl | 8de6a1d | 2012-08-29 22:13:00 +0200 | [diff] [blame] | 1413 | |
Philip Withnall | 659163d | 2013-11-25 18:01:36 +0000 | [diff] [blame] | 1414 | shsurf = get_shell_surface(surface); |
Philip Withnall | 648a4dd | 2013-11-25 18:01:44 +0000 | [diff] [blame] | 1415 | if (shsurf != NULL) |
| 1416 | shell_surface_update_child_surface_layers(shsurf); |
Philip Withnall | 659163d | 2013-11-25 18:01:36 +0000 | [diff] [blame] | 1417 | |
Jonas Ådahl | e9d2250 | 2012-08-29 22:13:01 +0200 | [diff] [blame] | 1418 | replace_focus_state(shell, to, seat); |
Jonas Ådahl | 8de6a1d | 2012-08-29 22:13:00 +0200 | [diff] [blame] | 1419 | drop_focus_state(shell, from, surface); |
| 1420 | |
| 1421 | if (shell->workspaces.anim_from == to && |
| 1422 | shell->workspaces.anim_to == from) { |
Jonas Ådahl | e9d2250 | 2012-08-29 22:13:01 +0200 | [diff] [blame] | 1423 | wl_list_remove(&to->layer.link); |
| 1424 | wl_list_insert(from->layer.link.prev, &to->layer.link); |
| 1425 | |
Jonas Ådahl | 8de6a1d | 2012-08-29 22:13:00 +0200 | [diff] [blame] | 1426 | reverse_workspace_change_animation(shell, index, from, to); |
Jonas Ådahl | e9d2250 | 2012-08-29 22:13:01 +0200 | [diff] [blame] | 1427 | broadcast_current_workspace_state(shell); |
| 1428 | |
Jonas Ådahl | 8de6a1d | 2012-08-29 22:13:00 +0200 | [diff] [blame] | 1429 | return; |
| 1430 | } |
| 1431 | |
| 1432 | if (shell->workspaces.anim_to != NULL) |
| 1433 | finish_workspace_change_animation(shell, |
| 1434 | shell->workspaces.anim_from, |
| 1435 | shell->workspaces.anim_to); |
| 1436 | |
| 1437 | if (workspace_is_empty(from) && |
| 1438 | workspace_has_only(to, surface)) |
| 1439 | update_workspace(shell, index, from, to); |
| 1440 | else { |
Philip Withnall | 2c3849b | 2013-11-25 18:01:45 +0000 | [diff] [blame] | 1441 | if (shsurf != NULL && |
| 1442 | wl_list_empty(&shsurf->workspace_transform.link)) |
Jonas Ådahl | 8de6a1d | 2012-08-29 22:13:00 +0200 | [diff] [blame] | 1443 | wl_list_insert(&shell->workspaces.anim_sticky_list, |
| 1444 | &shsurf->workspace_transform.link); |
| 1445 | |
| 1446 | animate_workspace_change(shell, index, from, to); |
| 1447 | } |
Jonas Ådahl | e9d2250 | 2012-08-29 22:13:01 +0200 | [diff] [blame] | 1448 | |
| 1449 | broadcast_current_workspace_state(shell); |
Jonas Ådahl | 8538b22 | 2012-08-29 22:13:03 +0200 | [diff] [blame] | 1450 | |
| 1451 | state = ensure_focus_state(shell, seat); |
| 1452 | if (state != NULL) |
Kristian Høgsberg | d500bf1 | 2014-01-22 12:25:20 -0800 | [diff] [blame] | 1453 | focus_state_set_focus(state, surface); |
Jonas Ådahl | e9d2250 | 2012-08-29 22:13:01 +0200 | [diff] [blame] | 1454 | } |
| 1455 | |
| 1456 | static void |
| 1457 | workspace_manager_move_surface(struct wl_client *client, |
| 1458 | struct wl_resource *resource, |
| 1459 | struct wl_resource *surface_resource, |
| 1460 | uint32_t workspace) |
| 1461 | { |
Jason Ekstrand | 651f00e | 2013-06-14 10:07:54 -0500 | [diff] [blame] | 1462 | struct desktop_shell *shell = wl_resource_get_user_data(resource); |
Jonas Ådahl | e9d2250 | 2012-08-29 22:13:01 +0200 | [diff] [blame] | 1463 | struct weston_surface *surface = |
Jason Ekstrand | 0f2ef7e | 2013-06-14 10:07:53 -0500 | [diff] [blame] | 1464 | wl_resource_get_user_data(surface_resource); |
Pekka Paalanen | 01388e2 | 2013-04-25 13:57:44 +0300 | [diff] [blame] | 1465 | struct weston_surface *main_surface; |
Philip Withnall | 659163d | 2013-11-25 18:01:36 +0000 | [diff] [blame] | 1466 | struct shell_surface *shell_surface; |
Jonas Ådahl | e9d2250 | 2012-08-29 22:13:01 +0200 | [diff] [blame] | 1467 | |
Pekka Paalanen | 01388e2 | 2013-04-25 13:57:44 +0300 | [diff] [blame] | 1468 | main_surface = weston_surface_get_main_surface(surface); |
Philip Withnall | 659163d | 2013-11-25 18:01:36 +0000 | [diff] [blame] | 1469 | shell_surface = get_shell_surface(main_surface); |
| 1470 | if (shell_surface == NULL) |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 1471 | return; |
Philip Withnall | 659163d | 2013-11-25 18:01:36 +0000 | [diff] [blame] | 1472 | |
| 1473 | move_surface_to_workspace(shell, shell_surface, workspace); |
Jonas Ådahl | e9d2250 | 2012-08-29 22:13:01 +0200 | [diff] [blame] | 1474 | } |
| 1475 | |
| 1476 | static const struct workspace_manager_interface workspace_manager_implementation = { |
| 1477 | workspace_manager_move_surface, |
| 1478 | }; |
| 1479 | |
| 1480 | static void |
| 1481 | unbind_resource(struct wl_resource *resource) |
| 1482 | { |
Jason Ekstrand | 651f00e | 2013-06-14 10:07:54 -0500 | [diff] [blame] | 1483 | wl_list_remove(wl_resource_get_link(resource)); |
Jonas Ådahl | e9d2250 | 2012-08-29 22:13:01 +0200 | [diff] [blame] | 1484 | } |
| 1485 | |
| 1486 | static void |
| 1487 | bind_workspace_manager(struct wl_client *client, |
| 1488 | void *data, uint32_t version, uint32_t id) |
| 1489 | { |
| 1490 | struct desktop_shell *shell = data; |
| 1491 | struct wl_resource *resource; |
| 1492 | |
Jason Ekstrand | a85118c | 2013-06-27 20:17:02 -0500 | [diff] [blame] | 1493 | resource = wl_resource_create(client, |
| 1494 | &workspace_manager_interface, 1, id); |
Jonas Ådahl | e9d2250 | 2012-08-29 22:13:01 +0200 | [diff] [blame] | 1495 | |
| 1496 | if (resource == NULL) { |
| 1497 | weston_log("couldn't add workspace manager object"); |
| 1498 | return; |
| 1499 | } |
| 1500 | |
Jason Ekstrand | a85118c | 2013-06-27 20:17:02 -0500 | [diff] [blame] | 1501 | wl_resource_set_implementation(resource, |
| 1502 | &workspace_manager_implementation, |
| 1503 | shell, unbind_resource); |
Jason Ekstrand | 651f00e | 2013-06-14 10:07:54 -0500 | [diff] [blame] | 1504 | wl_list_insert(&shell->workspaces.client_list, |
| 1505 | wl_resource_get_link(resource)); |
Jonas Ådahl | e9d2250 | 2012-08-29 22:13:01 +0200 | [diff] [blame] | 1506 | |
| 1507 | workspace_manager_send_state(resource, |
| 1508 | shell->workspaces.current, |
| 1509 | shell->workspaces.num); |
Jonas Ådahl | 8de6a1d | 2012-08-29 22:13:00 +0200 | [diff] [blame] | 1510 | } |
| 1511 | |
Pekka Paalanen | 56cdea9 | 2011-11-23 16:14:12 +0200 | [diff] [blame] | 1512 | static void |
Rusty Lynch | 1084da5 | 2013-08-15 09:10:08 -0700 | [diff] [blame] | 1513 | touch_move_grab_down(struct weston_touch_grab *grab, uint32_t time, |
| 1514 | int touch_id, wl_fixed_t sx, wl_fixed_t sy) |
| 1515 | { |
| 1516 | } |
| 1517 | |
| 1518 | static void |
| 1519 | touch_move_grab_up(struct weston_touch_grab *grab, uint32_t time, int touch_id) |
| 1520 | { |
Jonas Ådahl | 1c6e63e | 2013-10-25 23:18:04 +0200 | [diff] [blame] | 1521 | struct weston_touch_move_grab *move = |
| 1522 | (struct weston_touch_move_grab *) container_of( |
| 1523 | grab, struct shell_touch_grab, grab); |
Neil Roberts | e14aa4f | 2013-10-03 16:43:07 +0100 | [diff] [blame] | 1524 | |
Kristian Høgsberg | 8e80a31 | 2014-01-17 15:18:10 -0800 | [diff] [blame] | 1525 | if (touch_id == 0) |
| 1526 | move->active = 0; |
| 1527 | |
Jonas Ådahl | 9484b69 | 2013-12-02 22:05:03 +0100 | [diff] [blame] | 1528 | if (grab->touch->num_tp == 0) { |
Jonas Ådahl | 1c6e63e | 2013-10-25 23:18:04 +0200 | [diff] [blame] | 1529 | shell_touch_grab_end(&move->base); |
| 1530 | free(move); |
| 1531 | } |
Rusty Lynch | 1084da5 | 2013-08-15 09:10:08 -0700 | [diff] [blame] | 1532 | } |
| 1533 | |
| 1534 | static void |
| 1535 | touch_move_grab_motion(struct weston_touch_grab *grab, uint32_t time, |
| 1536 | int touch_id, wl_fixed_t sx, wl_fixed_t sy) |
| 1537 | { |
| 1538 | struct weston_touch_move_grab *move = (struct weston_touch_move_grab *) grab; |
| 1539 | struct shell_surface *shsurf = move->base.shsurf; |
| 1540 | struct weston_surface *es; |
| 1541 | int dx = wl_fixed_to_int(grab->touch->grab_x + move->dx); |
| 1542 | int dy = wl_fixed_to_int(grab->touch->grab_y + move->dy); |
| 1543 | |
Kristian Høgsberg | 8e80a31 | 2014-01-17 15:18:10 -0800 | [diff] [blame] | 1544 | if (!shsurf || !move->active) |
Rusty Lynch | 1084da5 | 2013-08-15 09:10:08 -0700 | [diff] [blame] | 1545 | return; |
| 1546 | |
| 1547 | es = shsurf->surface; |
| 1548 | |
Jason Ekstrand | 918f2dd | 2013-12-02 21:01:53 -0600 | [diff] [blame] | 1549 | weston_view_set_position(shsurf->view, dx, dy); |
Rusty Lynch | 1084da5 | 2013-08-15 09:10:08 -0700 | [diff] [blame] | 1550 | |
| 1551 | weston_compositor_schedule_repaint(es->compositor); |
| 1552 | } |
| 1553 | |
Jonas Ådahl | 1ea343e | 2013-10-25 23:18:05 +0200 | [diff] [blame] | 1554 | static void |
Jonas Ådahl | 1679f23 | 2014-04-12 09:39:51 +0200 | [diff] [blame] | 1555 | touch_move_grab_frame(struct weston_touch_grab *grab) |
| 1556 | { |
| 1557 | } |
| 1558 | |
| 1559 | static void |
Jonas Ådahl | 1ea343e | 2013-10-25 23:18:05 +0200 | [diff] [blame] | 1560 | touch_move_grab_cancel(struct weston_touch_grab *grab) |
| 1561 | { |
| 1562 | struct weston_touch_move_grab *move = |
| 1563 | (struct weston_touch_move_grab *) container_of( |
| 1564 | grab, struct shell_touch_grab, grab); |
| 1565 | |
| 1566 | shell_touch_grab_end(&move->base); |
| 1567 | free(move); |
| 1568 | } |
| 1569 | |
Rusty Lynch | 1084da5 | 2013-08-15 09:10:08 -0700 | [diff] [blame] | 1570 | static const struct weston_touch_grab_interface touch_move_grab_interface = { |
| 1571 | touch_move_grab_down, |
| 1572 | touch_move_grab_up, |
| 1573 | touch_move_grab_motion, |
Jonas Ådahl | 1679f23 | 2014-04-12 09:39:51 +0200 | [diff] [blame] | 1574 | touch_move_grab_frame, |
Jonas Ådahl | 1ea343e | 2013-10-25 23:18:05 +0200 | [diff] [blame] | 1575 | touch_move_grab_cancel, |
Rusty Lynch | 1084da5 | 2013-08-15 09:10:08 -0700 | [diff] [blame] | 1576 | }; |
| 1577 | |
| 1578 | static int |
| 1579 | surface_touch_move(struct shell_surface *shsurf, struct weston_seat *seat) |
| 1580 | { |
| 1581 | struct weston_touch_move_grab *move; |
| 1582 | |
| 1583 | if (!shsurf) |
| 1584 | return -1; |
| 1585 | |
Ander Conselvan de Oliveira | 6d43f04 | 2014-05-07 14:22:23 +0300 | [diff] [blame] | 1586 | if (shsurf->state.fullscreen || shsurf->state.maximized) |
Rusty Lynch | 1084da5 | 2013-08-15 09:10:08 -0700 | [diff] [blame] | 1587 | return 0; |
| 1588 | |
| 1589 | move = malloc(sizeof *move); |
| 1590 | if (!move) |
| 1591 | return -1; |
| 1592 | |
Kristian Høgsberg | 8e80a31 | 2014-01-17 15:18:10 -0800 | [diff] [blame] | 1593 | move->active = 1; |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 1594 | move->dx = wl_fixed_from_double(shsurf->view->geometry.x) - |
Rusty Lynch | 1084da5 | 2013-08-15 09:10:08 -0700 | [diff] [blame] | 1595 | seat->touch->grab_x; |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 1596 | move->dy = wl_fixed_from_double(shsurf->view->geometry.y) - |
Rusty Lynch | 1084da5 | 2013-08-15 09:10:08 -0700 | [diff] [blame] | 1597 | seat->touch->grab_y; |
| 1598 | |
| 1599 | shell_touch_grab_start(&move->base, &touch_move_grab_interface, shsurf, |
| 1600 | seat->touch); |
| 1601 | |
| 1602 | return 0; |
| 1603 | } |
| 1604 | |
| 1605 | static void |
Kristian Høgsberg | 6848c25 | 2013-05-08 22:02:59 -0400 | [diff] [blame] | 1606 | noop_grab_focus(struct weston_pointer_grab *grab) |
Kristian Høgsberg | 9ddb826 | 2012-01-04 21:30:29 -0500 | [diff] [blame] | 1607 | { |
Kristian Høgsberg | 9ddb826 | 2012-01-04 21:30:29 -0500 | [diff] [blame] | 1608 | } |
| 1609 | |
| 1610 | static void |
Kristian Høgsberg | ae356ae | 2014-04-29 16:03:54 -0700 | [diff] [blame] | 1611 | constrain_position(struct weston_move_grab *move, int *cx, int *cy) |
| 1612 | { |
| 1613 | struct shell_surface *shsurf = move->base.shsurf; |
| 1614 | struct weston_pointer *pointer = move->base.grab.pointer; |
Jonny Lamb | d73c694 | 2014-08-20 15:53:20 +0200 | [diff] [blame^] | 1615 | int x, y, panel_width, panel_height, bottom; |
Kristian Høgsberg | ae356ae | 2014-04-29 16:03:54 -0700 | [diff] [blame] | 1616 | const int safety = 50; |
| 1617 | |
| 1618 | x = wl_fixed_to_int(pointer->x + move->dx); |
| 1619 | y = wl_fixed_to_int(pointer->y + move->dy); |
| 1620 | |
Jonny Lamb | d73c694 | 2014-08-20 15:53:20 +0200 | [diff] [blame^] | 1621 | if (shsurf->shell->panel_position == DESKTOP_SHELL_PANEL_POSITION_TOP) { |
| 1622 | get_output_panel_size(shsurf->shell, shsurf->surface->output, |
| 1623 | &panel_width, &panel_height); |
Kristian Høgsberg | ae356ae | 2014-04-29 16:03:54 -0700 | [diff] [blame] | 1624 | |
Jonny Lamb | d73c694 | 2014-08-20 15:53:20 +0200 | [diff] [blame^] | 1625 | bottom = y + shsurf->geometry.height; |
| 1626 | if (bottom - panel_height < safety) |
| 1627 | y = panel_height + safety - |
| 1628 | shsurf->geometry.height; |
| 1629 | |
| 1630 | if (move->client_initiated && |
| 1631 | y + shsurf->geometry.y < panel_height) |
| 1632 | y = panel_height - shsurf->geometry.y; |
| 1633 | } |
Kristian Høgsberg | ae356ae | 2014-04-29 16:03:54 -0700 | [diff] [blame] | 1634 | |
| 1635 | *cx = x; |
| 1636 | *cy = y; |
| 1637 | } |
| 1638 | |
| 1639 | static void |
Giulio Camuffo | 1959ab8 | 2013-11-14 23:42:52 +0100 | [diff] [blame] | 1640 | move_grab_motion(struct weston_pointer_grab *grab, uint32_t time, |
| 1641 | wl_fixed_t x, wl_fixed_t y) |
Kristian Høgsberg | 4cca349 | 2011-01-18 07:53:49 -0500 | [diff] [blame] | 1642 | { |
Kristian Høgsberg | 8334bc1 | 2012-01-03 10:29:47 -0500 | [diff] [blame] | 1643 | struct weston_move_grab *move = (struct weston_move_grab *) grab; |
Kristian Høgsberg | 02bbabb | 2013-05-06 22:15:05 -0400 | [diff] [blame] | 1644 | struct weston_pointer *pointer = grab->pointer; |
Ander Conselvan de Oliveira | fe0444a | 2012-04-04 17:48:05 +0300 | [diff] [blame] | 1645 | struct shell_surface *shsurf = move->base.shsurf; |
Kristian Høgsberg | ae356ae | 2014-04-29 16:03:54 -0700 | [diff] [blame] | 1646 | int cx, cy; |
Giulio Camuffo | 1959ab8 | 2013-11-14 23:42:52 +0100 | [diff] [blame] | 1647 | |
| 1648 | weston_pointer_move(pointer, x, y); |
Ander Conselvan de Oliveira | fe0444a | 2012-04-04 17:48:05 +0300 | [diff] [blame] | 1649 | if (!shsurf) |
| 1650 | return; |
| 1651 | |
Kristian Høgsberg | ae356ae | 2014-04-29 16:03:54 -0700 | [diff] [blame] | 1652 | constrain_position(move, &cx, &cy); |
| 1653 | |
| 1654 | weston_view_set_position(shsurf->view, cx, cy); |
Kristian Høgsberg | 4cca349 | 2011-01-18 07:53:49 -0500 | [diff] [blame] | 1655 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 1656 | weston_compositor_schedule_repaint(shsurf->surface->compositor); |
Kristian Høgsberg | 4cca349 | 2011-01-18 07:53:49 -0500 | [diff] [blame] | 1657 | } |
| 1658 | |
| 1659 | static void |
Kristian Høgsberg | 02bbabb | 2013-05-06 22:15:05 -0400 | [diff] [blame] | 1660 | move_grab_button(struct weston_pointer_grab *grab, |
Daniel Stone | 4dbadb1 | 2012-05-30 16:31:51 +0100 | [diff] [blame] | 1661 | uint32_t time, uint32_t button, uint32_t state_w) |
Kristian Høgsberg | 4cca349 | 2011-01-18 07:53:49 -0500 | [diff] [blame] | 1662 | { |
Ander Conselvan de Oliveira | fe0444a | 2012-04-04 17:48:05 +0300 | [diff] [blame] | 1663 | struct shell_grab *shell_grab = container_of(grab, struct shell_grab, |
| 1664 | grab); |
Kristian Høgsberg | 02bbabb | 2013-05-06 22:15:05 -0400 | [diff] [blame] | 1665 | struct weston_pointer *pointer = grab->pointer; |
Daniel Stone | 4dbadb1 | 2012-05-30 16:31:51 +0100 | [diff] [blame] | 1666 | enum wl_pointer_button_state state = state_w; |
Kristian Høgsberg | 4cca349 | 2011-01-18 07:53:49 -0500 | [diff] [blame] | 1667 | |
Daniel Stone | 4dbadb1 | 2012-05-30 16:31:51 +0100 | [diff] [blame] | 1668 | if (pointer->button_count == 0 && |
| 1669 | state == WL_POINTER_BUTTON_STATE_RELEASED) { |
Ander Conselvan de Oliveira | b9d2a0f | 2012-06-28 18:08:05 +0300 | [diff] [blame] | 1670 | shell_grab_end(shell_grab); |
Kristian Høgsberg | 9ddb826 | 2012-01-04 21:30:29 -0500 | [diff] [blame] | 1671 | free(grab); |
| 1672 | } |
Kristian Høgsberg | 4cca349 | 2011-01-18 07:53:49 -0500 | [diff] [blame] | 1673 | } |
| 1674 | |
Jonas Ådahl | 1ea343e | 2013-10-25 23:18:05 +0200 | [diff] [blame] | 1675 | static void |
| 1676 | move_grab_cancel(struct weston_pointer_grab *grab) |
| 1677 | { |
| 1678 | struct shell_grab *shell_grab = |
| 1679 | container_of(grab, struct shell_grab, grab); |
| 1680 | |
| 1681 | shell_grab_end(shell_grab); |
| 1682 | free(grab); |
| 1683 | } |
| 1684 | |
Kristian Høgsberg | 02bbabb | 2013-05-06 22:15:05 -0400 | [diff] [blame] | 1685 | static const struct weston_pointer_grab_interface move_grab_interface = { |
Kristian Høgsberg | 9ddb826 | 2012-01-04 21:30:29 -0500 | [diff] [blame] | 1686 | noop_grab_focus, |
Kristian Høgsberg | 4cca349 | 2011-01-18 07:53:49 -0500 | [diff] [blame] | 1687 | move_grab_motion, |
| 1688 | move_grab_button, |
Jonas Ådahl | 1ea343e | 2013-10-25 23:18:05 +0200 | [diff] [blame] | 1689 | move_grab_cancel, |
Kristian Høgsberg | 4cca349 | 2011-01-18 07:53:49 -0500 | [diff] [blame] | 1690 | }; |
| 1691 | |
Kristian Høgsberg | 9e31bff | 2012-08-01 00:08:07 -0400 | [diff] [blame] | 1692 | static int |
Kristian Høgsberg | ae356ae | 2014-04-29 16:03:54 -0700 | [diff] [blame] | 1693 | surface_move(struct shell_surface *shsurf, struct weston_seat *seat, |
| 1694 | int client_initiated) |
Kristian Høgsberg | 9e31bff | 2012-08-01 00:08:07 -0400 | [diff] [blame] | 1695 | { |
| 1696 | struct weston_move_grab *move; |
| 1697 | |
| 1698 | if (!shsurf) |
| 1699 | return -1; |
| 1700 | |
Kristian Høgsberg | a4b620e | 2014-04-30 16:05:49 -0700 | [diff] [blame] | 1701 | if (shsurf->grabbed || |
| 1702 | shsurf->state.fullscreen || shsurf->state.maximized) |
Kristian Høgsberg | 9e31bff | 2012-08-01 00:08:07 -0400 | [diff] [blame] | 1703 | return 0; |
| 1704 | |
| 1705 | move = malloc(sizeof *move); |
| 1706 | if (!move) |
| 1707 | return -1; |
| 1708 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 1709 | move->dx = wl_fixed_from_double(shsurf->view->geometry.x) - |
Kristian Høgsberg | e314875 | 2013-05-06 23:19:49 -0400 | [diff] [blame] | 1710 | seat->pointer->grab_x; |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 1711 | move->dy = wl_fixed_from_double(shsurf->view->geometry.y) - |
Kristian Høgsberg | e314875 | 2013-05-06 23:19:49 -0400 | [diff] [blame] | 1712 | seat->pointer->grab_y; |
Kristian Høgsberg | ae356ae | 2014-04-29 16:03:54 -0700 | [diff] [blame] | 1713 | move->client_initiated = client_initiated; |
Kristian Høgsberg | 9e31bff | 2012-08-01 00:08:07 -0400 | [diff] [blame] | 1714 | |
| 1715 | shell_grab_start(&move->base, &move_grab_interface, shsurf, |
Kristian Høgsberg | e314875 | 2013-05-06 23:19:49 -0400 | [diff] [blame] | 1716 | seat->pointer, DESKTOP_SHELL_CURSOR_MOVE); |
Kristian Høgsberg | 9e31bff | 2012-08-01 00:08:07 -0400 | [diff] [blame] | 1717 | |
| 1718 | return 0; |
| 1719 | } |
| 1720 | |
| 1721 | static void |
Rafael Antognolli | e2a3455 | 2013-12-03 15:35:45 -0200 | [diff] [blame] | 1722 | common_surface_move(struct wl_resource *resource, |
| 1723 | struct wl_resource *seat_resource, uint32_t serial) |
Kristian Høgsberg | 9e31bff | 2012-08-01 00:08:07 -0400 | [diff] [blame] | 1724 | { |
Jason Ekstrand | 44a3863 | 2013-06-14 10:08:00 -0500 | [diff] [blame] | 1725 | struct weston_seat *seat = wl_resource_get_user_data(seat_resource); |
Jason Ekstrand | 651f00e | 2013-06-14 10:07:54 -0500 | [diff] [blame] | 1726 | struct shell_surface *shsurf = wl_resource_get_user_data(resource); |
Giulio Camuffo | 61da3fc | 2013-04-25 13:57:45 +0300 | [diff] [blame] | 1727 | struct weston_surface *surface; |
Kristian Høgsberg | 9e31bff | 2012-08-01 00:08:07 -0400 | [diff] [blame] | 1728 | |
Kristian Høgsberg | e1b655d | 2013-08-28 23:16:20 -0700 | [diff] [blame] | 1729 | if (seat->pointer && |
Kristian Høgsberg | 70f2901 | 2014-01-09 15:43:17 -0800 | [diff] [blame] | 1730 | seat->pointer->focus && |
Kristian Høgsberg | e1b655d | 2013-08-28 23:16:20 -0700 | [diff] [blame] | 1731 | seat->pointer->button_count > 0 && |
| 1732 | seat->pointer->grab_serial == serial) { |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 1733 | surface = weston_surface_get_main_surface(seat->pointer->focus->surface); |
U. Artie Eoff | cf5737a | 2014-01-17 10:08:25 -0800 | [diff] [blame] | 1734 | if ((surface == shsurf->surface) && |
Kristian Høgsberg | ae356ae | 2014-04-29 16:03:54 -0700 | [diff] [blame] | 1735 | (surface_move(shsurf, seat, 1) < 0)) |
Rusty Lynch | 1084da5 | 2013-08-15 09:10:08 -0700 | [diff] [blame] | 1736 | wl_resource_post_no_memory(resource); |
Kristian Høgsberg | e1b655d | 2013-08-28 23:16:20 -0700 | [diff] [blame] | 1737 | } else if (seat->touch && |
Kristian Høgsberg | 70f2901 | 2014-01-09 15:43:17 -0800 | [diff] [blame] | 1738 | seat->touch->focus && |
Kristian Høgsberg | e1b655d | 2013-08-28 23:16:20 -0700 | [diff] [blame] | 1739 | seat->touch->grab_serial == serial) { |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 1740 | surface = weston_surface_get_main_surface(seat->touch->focus->surface); |
U. Artie Eoff | cf5737a | 2014-01-17 10:08:25 -0800 | [diff] [blame] | 1741 | if ((surface == shsurf->surface) && |
Rusty Lynch | 1084da5 | 2013-08-15 09:10:08 -0700 | [diff] [blame] | 1742 | (surface_touch_move(shsurf, seat) < 0)) |
| 1743 | wl_resource_post_no_memory(resource); |
| 1744 | } |
Kristian Høgsberg | 9e31bff | 2012-08-01 00:08:07 -0400 | [diff] [blame] | 1745 | } |
| 1746 | |
Rafael Antognolli | e2a3455 | 2013-12-03 15:35:45 -0200 | [diff] [blame] | 1747 | static void |
| 1748 | shell_surface_move(struct wl_client *client, struct wl_resource *resource, |
| 1749 | struct wl_resource *seat_resource, uint32_t serial) |
| 1750 | { |
| 1751 | common_surface_move(resource, seat_resource, serial); |
| 1752 | } |
| 1753 | |
Kristian Høgsberg | 9e31bff | 2012-08-01 00:08:07 -0400 | [diff] [blame] | 1754 | struct weston_resize_grab { |
| 1755 | struct shell_grab base; |
| 1756 | uint32_t edges; |
| 1757 | int32_t width, height; |
| 1758 | }; |
| 1759 | |
| 1760 | static void |
Giulio Camuffo | 1959ab8 | 2013-11-14 23:42:52 +0100 | [diff] [blame] | 1761 | resize_grab_motion(struct weston_pointer_grab *grab, uint32_t time, |
| 1762 | wl_fixed_t x, wl_fixed_t y) |
Kristian Høgsberg | 9e31bff | 2012-08-01 00:08:07 -0400 | [diff] [blame] | 1763 | { |
| 1764 | struct weston_resize_grab *resize = (struct weston_resize_grab *) grab; |
Kristian Høgsberg | 02bbabb | 2013-05-06 22:15:05 -0400 | [diff] [blame] | 1765 | struct weston_pointer *pointer = grab->pointer; |
Kristian Høgsberg | 9e31bff | 2012-08-01 00:08:07 -0400 | [diff] [blame] | 1766 | struct shell_surface *shsurf = resize->base.shsurf; |
| 1767 | int32_t width, height; |
| 1768 | wl_fixed_t from_x, from_y; |
| 1769 | wl_fixed_t to_x, to_y; |
| 1770 | |
Giulio Camuffo | 1959ab8 | 2013-11-14 23:42:52 +0100 | [diff] [blame] | 1771 | weston_pointer_move(pointer, x, y); |
| 1772 | |
Kristian Høgsberg | e0b9d5b | 2014-04-30 13:45:49 -0700 | [diff] [blame] | 1773 | if (!shsurf) |
Kristian Høgsberg | 9e31bff | 2012-08-01 00:08:07 -0400 | [diff] [blame] | 1774 | return; |
| 1775 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 1776 | weston_view_from_global_fixed(shsurf->view, |
| 1777 | pointer->grab_x, pointer->grab_y, |
| 1778 | &from_x, &from_y); |
| 1779 | weston_view_from_global_fixed(shsurf->view, |
| 1780 | pointer->x, pointer->y, &to_x, &to_y); |
Kristian Høgsberg | 9e31bff | 2012-08-01 00:08:07 -0400 | [diff] [blame] | 1781 | |
| 1782 | width = resize->width; |
| 1783 | if (resize->edges & WL_SHELL_SURFACE_RESIZE_LEFT) { |
| 1784 | width += wl_fixed_to_int(from_x - to_x); |
| 1785 | } else if (resize->edges & WL_SHELL_SURFACE_RESIZE_RIGHT) { |
| 1786 | width += wl_fixed_to_int(to_x - from_x); |
| 1787 | } |
| 1788 | |
| 1789 | height = resize->height; |
| 1790 | if (resize->edges & WL_SHELL_SURFACE_RESIZE_TOP) { |
| 1791 | height += wl_fixed_to_int(from_y - to_y); |
| 1792 | } else if (resize->edges & WL_SHELL_SURFACE_RESIZE_BOTTOM) { |
| 1793 | height += wl_fixed_to_int(to_y - from_y); |
| 1794 | } |
| 1795 | |
Jasper St. Pierre | ac985be | 2014-04-28 11:19:28 -0400 | [diff] [blame] | 1796 | shsurf->client->send_configure(shsurf->surface, width, height); |
Kristian Høgsberg | 9e31bff | 2012-08-01 00:08:07 -0400 | [diff] [blame] | 1797 | } |
| 1798 | |
| 1799 | static void |
Jasper St. Pierre | ac985be | 2014-04-28 11:19:28 -0400 | [diff] [blame] | 1800 | 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] | 1801 | { |
| 1802 | struct shell_surface *shsurf = get_shell_surface(surface); |
| 1803 | |
U. Artie Eoff | cf5737a | 2014-01-17 10:08:25 -0800 | [diff] [blame] | 1804 | assert(shsurf); |
| 1805 | |
Kristian Høgsberg | e0b9d5b | 2014-04-30 13:45:49 -0700 | [diff] [blame] | 1806 | if (shsurf->resource) |
| 1807 | wl_shell_surface_send_configure(shsurf->resource, |
Jasper St. Pierre | ac985be | 2014-04-28 11:19:28 -0400 | [diff] [blame] | 1808 | shsurf->resize_edges, |
| 1809 | width, height); |
Kristian Høgsberg | 9e31bff | 2012-08-01 00:08:07 -0400 | [diff] [blame] | 1810 | } |
| 1811 | |
| 1812 | static const struct weston_shell_client shell_client = { |
| 1813 | send_configure |
| 1814 | }; |
| 1815 | |
| 1816 | static void |
Kristian Høgsberg | 02bbabb | 2013-05-06 22:15:05 -0400 | [diff] [blame] | 1817 | resize_grab_button(struct weston_pointer_grab *grab, |
Kristian Høgsberg | 9e31bff | 2012-08-01 00:08:07 -0400 | [diff] [blame] | 1818 | uint32_t time, uint32_t button, uint32_t state_w) |
| 1819 | { |
| 1820 | struct weston_resize_grab *resize = (struct weston_resize_grab *) grab; |
Kristian Høgsberg | 02bbabb | 2013-05-06 22:15:05 -0400 | [diff] [blame] | 1821 | struct weston_pointer *pointer = grab->pointer; |
Kristian Høgsberg | 9e31bff | 2012-08-01 00:08:07 -0400 | [diff] [blame] | 1822 | enum wl_pointer_button_state state = state_w; |
| 1823 | |
| 1824 | if (pointer->button_count == 0 && |
| 1825 | state == WL_POINTER_BUTTON_STATE_RELEASED) { |
| 1826 | shell_grab_end(&resize->base); |
| 1827 | free(grab); |
| 1828 | } |
| 1829 | } |
| 1830 | |
Jonas Ådahl | 1ea343e | 2013-10-25 23:18:05 +0200 | [diff] [blame] | 1831 | static void |
| 1832 | resize_grab_cancel(struct weston_pointer_grab *grab) |
| 1833 | { |
| 1834 | struct weston_resize_grab *resize = (struct weston_resize_grab *) grab; |
| 1835 | |
| 1836 | shell_grab_end(&resize->base); |
| 1837 | free(grab); |
| 1838 | } |
| 1839 | |
Kristian Høgsberg | 02bbabb | 2013-05-06 22:15:05 -0400 | [diff] [blame] | 1840 | static const struct weston_pointer_grab_interface resize_grab_interface = { |
Kristian Høgsberg | 9e31bff | 2012-08-01 00:08:07 -0400 | [diff] [blame] | 1841 | noop_grab_focus, |
| 1842 | resize_grab_motion, |
| 1843 | resize_grab_button, |
Jonas Ådahl | 1ea343e | 2013-10-25 23:18:05 +0200 | [diff] [blame] | 1844 | resize_grab_cancel, |
Kristian Høgsberg | 9e31bff | 2012-08-01 00:08:07 -0400 | [diff] [blame] | 1845 | }; |
| 1846 | |
Giulio Camuffo | b836664 | 2013-04-25 13:57:46 +0300 | [diff] [blame] | 1847 | /* |
| 1848 | * Returns the bounding box of a surface and all its sub-surfaces, |
| 1849 | * in the surface coordinates system. */ |
| 1850 | static void |
| 1851 | surface_subsurfaces_boundingbox(struct weston_surface *surface, int32_t *x, |
| 1852 | int32_t *y, int32_t *w, int32_t *h) { |
| 1853 | pixman_region32_t region; |
| 1854 | pixman_box32_t *box; |
| 1855 | struct weston_subsurface *subsurface; |
| 1856 | |
| 1857 | pixman_region32_init_rect(®ion, 0, 0, |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 1858 | surface->width, |
| 1859 | surface->height); |
Giulio Camuffo | b836664 | 2013-04-25 13:57:46 +0300 | [diff] [blame] | 1860 | |
| 1861 | wl_list_for_each(subsurface, &surface->subsurface_list, parent_link) { |
| 1862 | pixman_region32_union_rect(®ion, ®ion, |
| 1863 | subsurface->position.x, |
| 1864 | subsurface->position.y, |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 1865 | subsurface->surface->width, |
| 1866 | subsurface->surface->height); |
Giulio Camuffo | b836664 | 2013-04-25 13:57:46 +0300 | [diff] [blame] | 1867 | } |
| 1868 | |
| 1869 | box = pixman_region32_extents(®ion); |
| 1870 | if (x) |
| 1871 | *x = box->x1; |
| 1872 | if (y) |
| 1873 | *y = box->y1; |
| 1874 | if (w) |
| 1875 | *w = box->x2 - box->x1; |
| 1876 | if (h) |
| 1877 | *h = box->y2 - box->y1; |
| 1878 | |
| 1879 | pixman_region32_fini(®ion); |
| 1880 | } |
| 1881 | |
Kristian Høgsberg | 9e31bff | 2012-08-01 00:08:07 -0400 | [diff] [blame] | 1882 | static int |
| 1883 | surface_resize(struct shell_surface *shsurf, |
Kristian Høgsberg | e314875 | 2013-05-06 23:19:49 -0400 | [diff] [blame] | 1884 | struct weston_seat *seat, uint32_t edges) |
Kristian Høgsberg | 9e31bff | 2012-08-01 00:08:07 -0400 | [diff] [blame] | 1885 | { |
| 1886 | struct weston_resize_grab *resize; |
| 1887 | |
Kristian Høgsberg | a4b620e | 2014-04-30 16:05:49 -0700 | [diff] [blame] | 1888 | if (shsurf->grabbed || |
| 1889 | shsurf->state.fullscreen || shsurf->state.maximized) |
Kristian Høgsberg | 9e31bff | 2012-08-01 00:08:07 -0400 | [diff] [blame] | 1890 | return 0; |
| 1891 | |
| 1892 | if (edges == 0 || edges > 15 || |
| 1893 | (edges & 3) == 3 || (edges & 12) == 12) |
| 1894 | return 0; |
| 1895 | |
| 1896 | resize = malloc(sizeof *resize); |
| 1897 | if (!resize) |
| 1898 | return -1; |
| 1899 | |
| 1900 | resize->edges = edges; |
Kristian Høgsberg | 9e31bff | 2012-08-01 00:08:07 -0400 | [diff] [blame] | 1901 | |
Jasper St. Pierre | ccf48fb | 2014-05-02 10:21:38 -0400 | [diff] [blame] | 1902 | resize->width = shsurf->geometry.width; |
| 1903 | resize->height = shsurf->geometry.height; |
Jasper St. Pierre | bd65e50 | 2014-07-14 16:28:48 -0400 | [diff] [blame] | 1904 | |
Kristian Høgsberg | 44cd196 | 2014-02-05 21:36:04 -0800 | [diff] [blame] | 1905 | shsurf->resize_edges = edges; |
Jasper St. Pierre | 5befdda | 2014-05-06 08:50:47 -0400 | [diff] [blame] | 1906 | shell_surface_state_changed(shsurf); |
Kristian Høgsberg | 9e31bff | 2012-08-01 00:08:07 -0400 | [diff] [blame] | 1907 | shell_grab_start(&resize->base, &resize_grab_interface, shsurf, |
Kristian Høgsberg | e314875 | 2013-05-06 23:19:49 -0400 | [diff] [blame] | 1908 | seat->pointer, edges); |
Kristian Høgsberg | 9e31bff | 2012-08-01 00:08:07 -0400 | [diff] [blame] | 1909 | |
| 1910 | return 0; |
| 1911 | } |
| 1912 | |
| 1913 | static void |
Rafael Antognolli | e2a3455 | 2013-12-03 15:35:45 -0200 | [diff] [blame] | 1914 | common_surface_resize(struct wl_resource *resource, |
| 1915 | struct wl_resource *seat_resource, uint32_t serial, |
| 1916 | uint32_t edges) |
Kristian Høgsberg | 9e31bff | 2012-08-01 00:08:07 -0400 | [diff] [blame] | 1917 | { |
Jason Ekstrand | 44a3863 | 2013-06-14 10:08:00 -0500 | [diff] [blame] | 1918 | struct weston_seat *seat = wl_resource_get_user_data(seat_resource); |
Jason Ekstrand | 651f00e | 2013-06-14 10:07:54 -0500 | [diff] [blame] | 1919 | struct shell_surface *shsurf = wl_resource_get_user_data(resource); |
Giulio Camuffo | 61da3fc | 2013-04-25 13:57:45 +0300 | [diff] [blame] | 1920 | struct weston_surface *surface; |
Kristian Høgsberg | 9e31bff | 2012-08-01 00:08:07 -0400 | [diff] [blame] | 1921 | |
Emilio Pozuelo Monfort | 5872b68 | 2014-06-18 17:48:58 +0200 | [diff] [blame] | 1922 | if (seat->pointer == NULL || |
| 1923 | seat->pointer->button_count == 0 || |
Kristian Høgsberg | e314875 | 2013-05-06 23:19:49 -0400 | [diff] [blame] | 1924 | seat->pointer->grab_serial != serial || |
Kristian Høgsberg | 70f2901 | 2014-01-09 15:43:17 -0800 | [diff] [blame] | 1925 | seat->pointer->focus == NULL) |
| 1926 | return; |
| 1927 | |
| 1928 | surface = weston_surface_get_main_surface(seat->pointer->focus->surface); |
| 1929 | if (surface != shsurf->surface) |
Kristian Høgsberg | 9e31bff | 2012-08-01 00:08:07 -0400 | [diff] [blame] | 1930 | return; |
| 1931 | |
Kristian Høgsberg | e314875 | 2013-05-06 23:19:49 -0400 | [diff] [blame] | 1932 | if (surface_resize(shsurf, seat, edges) < 0) |
Kristian Høgsberg | 9e31bff | 2012-08-01 00:08:07 -0400 | [diff] [blame] | 1933 | wl_resource_post_no_memory(resource); |
| 1934 | } |
| 1935 | |
Scott Moreau | c3e54eb | 2012-04-17 19:06:20 -0600 | [diff] [blame] | 1936 | static void |
Rafael Antognolli | e2a3455 | 2013-12-03 15:35:45 -0200 | [diff] [blame] | 1937 | shell_surface_resize(struct wl_client *client, struct wl_resource *resource, |
| 1938 | struct wl_resource *seat_resource, uint32_t serial, |
| 1939 | uint32_t edges) |
| 1940 | { |
| 1941 | common_surface_resize(resource, seat_resource, serial, edges); |
| 1942 | } |
| 1943 | |
| 1944 | static void |
Kristian Høgsberg | 6848c25 | 2013-05-08 22:02:59 -0400 | [diff] [blame] | 1945 | busy_cursor_grab_focus(struct weston_pointer_grab *base) |
Scott Moreau | c3e54eb | 2012-04-17 19:06:20 -0600 | [diff] [blame] | 1946 | { |
Kristian Høgsberg | d56bd90 | 2012-06-05 09:58:51 -0400 | [diff] [blame] | 1947 | struct shell_grab *grab = (struct shell_grab *) base; |
Kristian Høgsberg | 6848c25 | 2013-05-08 22:02:59 -0400 | [diff] [blame] | 1948 | struct weston_pointer *pointer = base->pointer; |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 1949 | struct weston_view *view; |
Kristian Høgsberg | 6848c25 | 2013-05-08 22:02:59 -0400 | [diff] [blame] | 1950 | wl_fixed_t sx, sy; |
| 1951 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 1952 | view = weston_compositor_pick_view(pointer->seat->compositor, |
| 1953 | pointer->x, pointer->y, |
| 1954 | &sx, &sy); |
Scott Moreau | c3e54eb | 2012-04-17 19:06:20 -0600 | [diff] [blame] | 1955 | |
Kristian Høgsberg | 2bff94e | 2014-02-11 12:22:51 -0800 | [diff] [blame] | 1956 | if (!grab->shsurf || grab->shsurf->surface != view->surface) { |
| 1957 | shell_grab_end(grab); |
| 1958 | free(grab); |
| 1959 | } |
Scott Moreau | c3e54eb | 2012-04-17 19:06:20 -0600 | [diff] [blame] | 1960 | } |
| 1961 | |
| 1962 | static void |
Giulio Camuffo | 1959ab8 | 2013-11-14 23:42:52 +0100 | [diff] [blame] | 1963 | busy_cursor_grab_motion(struct weston_pointer_grab *grab, uint32_t time, |
| 1964 | wl_fixed_t x, wl_fixed_t y) |
Scott Moreau | c3e54eb | 2012-04-17 19:06:20 -0600 | [diff] [blame] | 1965 | { |
Giulio Camuffo | 1959ab8 | 2013-11-14 23:42:52 +0100 | [diff] [blame] | 1966 | weston_pointer_move(grab->pointer, x, y); |
Kristian Høgsberg | d56bd90 | 2012-06-05 09:58:51 -0400 | [diff] [blame] | 1967 | } |
Scott Moreau | c3e54eb | 2012-04-17 19:06:20 -0600 | [diff] [blame] | 1968 | |
Kristian Høgsberg | d56bd90 | 2012-06-05 09:58:51 -0400 | [diff] [blame] | 1969 | static void |
Kristian Høgsberg | 02bbabb | 2013-05-06 22:15:05 -0400 | [diff] [blame] | 1970 | busy_cursor_grab_button(struct weston_pointer_grab *base, |
Kristian Høgsberg | d56bd90 | 2012-06-05 09:58:51 -0400 | [diff] [blame] | 1971 | uint32_t time, uint32_t button, uint32_t state) |
| 1972 | { |
Kristian Høgsberg | bbe9839 | 2012-08-01 00:20:21 -0400 | [diff] [blame] | 1973 | struct shell_grab *grab = (struct shell_grab *) base; |
Kristian Høgsberg | e122b7b | 2013-05-08 16:47:00 -0400 | [diff] [blame] | 1974 | struct shell_surface *shsurf = grab->shsurf; |
Kristian Høgsberg | e314875 | 2013-05-06 23:19:49 -0400 | [diff] [blame] | 1975 | struct weston_seat *seat = grab->grab.pointer->seat; |
Kristian Høgsberg | bbe9839 | 2012-08-01 00:20:21 -0400 | [diff] [blame] | 1976 | |
Kristian Høgsberg | bbe9839 | 2012-08-01 00:20:21 -0400 | [diff] [blame] | 1977 | if (shsurf && button == BTN_LEFT && state) { |
Emilio Pozuelo Monfort | 9e7c759 | 2014-01-30 14:01:10 +0100 | [diff] [blame] | 1978 | activate(shsurf->shell, shsurf->surface, seat, true); |
Kristian Høgsberg | ae356ae | 2014-04-29 16:03:54 -0700 | [diff] [blame] | 1979 | surface_move(shsurf, seat, 0); |
Kristian Høgsberg | 0c36903 | 2013-02-14 21:31:44 -0500 | [diff] [blame] | 1980 | } else if (shsurf && button == BTN_RIGHT && state) { |
Emilio Pozuelo Monfort | 9e7c759 | 2014-01-30 14:01:10 +0100 | [diff] [blame] | 1981 | activate(shsurf->shell, shsurf->surface, seat, true); |
Kristian Høgsberg | e314875 | 2013-05-06 23:19:49 -0400 | [diff] [blame] | 1982 | surface_rotate(shsurf, seat); |
Kristian Høgsberg | bbe9839 | 2012-08-01 00:20:21 -0400 | [diff] [blame] | 1983 | } |
Kristian Høgsberg | d56bd90 | 2012-06-05 09:58:51 -0400 | [diff] [blame] | 1984 | } |
| 1985 | |
Jonas Ådahl | 1ea343e | 2013-10-25 23:18:05 +0200 | [diff] [blame] | 1986 | static void |
| 1987 | busy_cursor_grab_cancel(struct weston_pointer_grab *base) |
| 1988 | { |
| 1989 | struct shell_grab *grab = (struct shell_grab *) base; |
| 1990 | |
| 1991 | shell_grab_end(grab); |
| 1992 | free(grab); |
| 1993 | } |
| 1994 | |
Kristian Høgsberg | 02bbabb | 2013-05-06 22:15:05 -0400 | [diff] [blame] | 1995 | static const struct weston_pointer_grab_interface busy_cursor_grab_interface = { |
Kristian Høgsberg | d56bd90 | 2012-06-05 09:58:51 -0400 | [diff] [blame] | 1996 | busy_cursor_grab_focus, |
| 1997 | busy_cursor_grab_motion, |
| 1998 | busy_cursor_grab_button, |
Jonas Ådahl | 1ea343e | 2013-10-25 23:18:05 +0200 | [diff] [blame] | 1999 | busy_cursor_grab_cancel, |
Kristian Høgsberg | d56bd90 | 2012-06-05 09:58:51 -0400 | [diff] [blame] | 2000 | }; |
| 2001 | |
| 2002 | static void |
Kristian Høgsberg | 02bbabb | 2013-05-06 22:15:05 -0400 | [diff] [blame] | 2003 | set_busy_cursor(struct shell_surface *shsurf, struct weston_pointer *pointer) |
Kristian Høgsberg | d56bd90 | 2012-06-05 09:58:51 -0400 | [diff] [blame] | 2004 | { |
| 2005 | struct shell_grab *grab; |
Kristian Høgsberg | d56bd90 | 2012-06-05 09:58:51 -0400 | [diff] [blame] | 2006 | |
Kristian Høgsberg | 2bff94e | 2014-02-11 12:22:51 -0800 | [diff] [blame] | 2007 | if (pointer->grab->interface == &busy_cursor_grab_interface) |
| 2008 | return; |
| 2009 | |
Kristian Høgsberg | d56bd90 | 2012-06-05 09:58:51 -0400 | [diff] [blame] | 2010 | grab = malloc(sizeof *grab); |
| 2011 | if (!grab) |
Scott Moreau | c3e54eb | 2012-04-17 19:06:20 -0600 | [diff] [blame] | 2012 | return; |
| 2013 | |
Ander Conselvan de Oliveira | b9d2a0f | 2012-06-28 18:08:05 +0300 | [diff] [blame] | 2014 | shell_grab_start(grab, &busy_cursor_grab_interface, shsurf, pointer, |
| 2015 | DESKTOP_SHELL_CURSOR_BUSY); |
Ander Conselvan de Oliveira | e5a1aee | 2014-04-09 17:39:39 +0300 | [diff] [blame] | 2016 | /* Mark the shsurf as ungrabbed so that button binding is able |
| 2017 | * to move it. */ |
| 2018 | shsurf->grabbed = 0; |
Kristian Høgsberg | d56bd90 | 2012-06-05 09:58:51 -0400 | [diff] [blame] | 2019 | } |
Scott Moreau | c3e54eb | 2012-04-17 19:06:20 -0600 | [diff] [blame] | 2020 | |
Kristian Høgsberg | d56bd90 | 2012-06-05 09:58:51 -0400 | [diff] [blame] | 2021 | static void |
Kristian Høgsberg | 2bff94e | 2014-02-11 12:22:51 -0800 | [diff] [blame] | 2022 | end_busy_cursor(struct weston_compositor *compositor, struct wl_client *client) |
Kristian Høgsberg | d56bd90 | 2012-06-05 09:58:51 -0400 | [diff] [blame] | 2023 | { |
Kristian Høgsberg | 2bff94e | 2014-02-11 12:22:51 -0800 | [diff] [blame] | 2024 | struct shell_grab *grab; |
| 2025 | struct weston_seat *seat; |
Kristian Høgsberg | d56bd90 | 2012-06-05 09:58:51 -0400 | [diff] [blame] | 2026 | |
Kristian Høgsberg | 2bff94e | 2014-02-11 12:22:51 -0800 | [diff] [blame] | 2027 | wl_list_for_each(seat, &compositor->seat_list, link) { |
| 2028 | if (seat->pointer == NULL) |
| 2029 | continue; |
| 2030 | |
| 2031 | grab = (struct shell_grab *) seat->pointer->grab; |
| 2032 | if (grab->grab.interface == &busy_cursor_grab_interface && |
| 2033 | wl_resource_get_client(grab->shsurf->resource) == client) { |
| 2034 | shell_grab_end(grab); |
| 2035 | free(grab); |
| 2036 | } |
Scott Moreau | c3e54eb | 2012-04-17 19:06:20 -0600 | [diff] [blame] | 2037 | } |
Scott Moreau | c3e54eb | 2012-04-17 19:06:20 -0600 | [diff] [blame] | 2038 | } |
| 2039 | |
Scott Moreau | 9521d5e | 2012-04-19 13:06:17 -0600 | [diff] [blame] | 2040 | static void |
Kristian Høgsberg | 2bff94e | 2014-02-11 12:22:51 -0800 | [diff] [blame] | 2041 | handle_shell_client_destroy(struct wl_listener *listener, void *data); |
| 2042 | |
| 2043 | static int |
| 2044 | xdg_ping_timeout_handler(void *data) |
| 2045 | { |
| 2046 | struct shell_client *sc = data; |
| 2047 | struct weston_seat *seat; |
| 2048 | struct shell_surface *shsurf; |
| 2049 | |
| 2050 | /* Client is not responding */ |
| 2051 | sc->unresponsive = 1; |
Kristian Høgsberg | 2bff94e | 2014-02-11 12:22:51 -0800 | [diff] [blame] | 2052 | wl_list_for_each(seat, &sc->shell->compositor->seat_list, link) { |
| 2053 | if (seat->pointer == NULL || seat->pointer->focus == NULL) |
| 2054 | continue; |
| 2055 | if (seat->pointer->focus->surface->resource == NULL) |
| 2056 | continue; |
| 2057 | |
| 2058 | shsurf = get_shell_surface(seat->pointer->focus->surface); |
| 2059 | if (shsurf && |
| 2060 | wl_resource_get_client(shsurf->resource) == sc->client) |
| 2061 | set_busy_cursor(shsurf, seat->pointer); |
| 2062 | } |
| 2063 | |
| 2064 | return 1; |
| 2065 | } |
| 2066 | |
| 2067 | static void |
| 2068 | handle_xdg_ping(struct shell_surface *shsurf, uint32_t serial) |
| 2069 | { |
| 2070 | struct weston_compositor *compositor = shsurf->shell->compositor; |
Jason Ekstrand | 9e9512f | 2014-04-16 21:12:10 -0500 | [diff] [blame] | 2071 | struct shell_client *sc = shsurf->owner; |
Kristian Høgsberg | 2bff94e | 2014-02-11 12:22:51 -0800 | [diff] [blame] | 2072 | struct wl_event_loop *loop; |
Kristian Høgsberg | dd62aba | 2014-02-12 09:56:19 -0800 | [diff] [blame] | 2073 | static const int ping_timeout = 200; |
Kristian Høgsberg | 2bff94e | 2014-02-11 12:22:51 -0800 | [diff] [blame] | 2074 | |
Kristian Høgsberg | 2bff94e | 2014-02-11 12:22:51 -0800 | [diff] [blame] | 2075 | if (sc->unresponsive) { |
| 2076 | xdg_ping_timeout_handler(sc); |
| 2077 | return; |
| 2078 | } |
| 2079 | |
| 2080 | sc->ping_serial = serial; |
| 2081 | loop = wl_display_get_event_loop(compositor->wl_display); |
| 2082 | if (sc->ping_timer == NULL) |
| 2083 | sc->ping_timer = |
| 2084 | wl_event_loop_add_timer(loop, |
| 2085 | xdg_ping_timeout_handler, sc); |
| 2086 | if (sc->ping_timer == NULL) |
| 2087 | return; |
| 2088 | |
| 2089 | wl_event_source_timer_update(sc->ping_timer, ping_timeout); |
| 2090 | |
Kristian Høgsberg | dd62aba | 2014-02-12 09:56:19 -0800 | [diff] [blame] | 2091 | if (shell_surface_is_xdg_surface(shsurf) || |
| 2092 | shell_surface_is_xdg_popup(shsurf)) |
| 2093 | xdg_shell_send_ping(sc->resource, serial); |
| 2094 | else if (shell_surface_is_wl_shell_surface(shsurf)) |
| 2095 | wl_shell_surface_send_ping(shsurf->resource, serial); |
Kristian Høgsberg | 2bff94e | 2014-02-11 12:22:51 -0800 | [diff] [blame] | 2096 | } |
| 2097 | |
Scott Moreau | ff1db4a | 2012-04-17 19:06:18 -0600 | [diff] [blame] | 2098 | static void |
| 2099 | ping_handler(struct weston_surface *surface, uint32_t serial) |
| 2100 | { |
Kristian Høgsberg | b71302e | 2012-05-10 12:28:35 -0400 | [diff] [blame] | 2101 | struct shell_surface *shsurf = get_shell_surface(surface); |
Scott Moreau | ff1db4a | 2012-04-17 19:06:18 -0600 | [diff] [blame] | 2102 | |
| 2103 | if (!shsurf) |
| 2104 | return; |
Jason Ekstrand | 651f00e | 2013-06-14 10:07:54 -0500 | [diff] [blame] | 2105 | if (!shsurf->resource) |
Kristian Høgsberg | ca535c1 | 2012-04-21 23:20:07 -0400 | [diff] [blame] | 2106 | return; |
Ander Conselvan de Oliveira | eac9a46 | 2012-07-16 14:15:48 +0300 | [diff] [blame] | 2107 | if (shsurf->surface == shsurf->shell->grab_surface) |
| 2108 | return; |
| 2109 | |
Kristian Høgsberg | dd62aba | 2014-02-12 09:56:19 -0800 | [diff] [blame] | 2110 | handle_xdg_ping(shsurf, serial); |
Scott Moreau | ff1db4a | 2012-04-17 19:06:18 -0600 | [diff] [blame] | 2111 | } |
| 2112 | |
| 2113 | static void |
Kristian Høgsberg | d56bd90 | 2012-06-05 09:58:51 -0400 | [diff] [blame] | 2114 | handle_pointer_focus(struct wl_listener *listener, void *data) |
| 2115 | { |
Kristian Høgsberg | 02bbabb | 2013-05-06 22:15:05 -0400 | [diff] [blame] | 2116 | struct weston_pointer *pointer = data; |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 2117 | struct weston_view *view = pointer->focus; |
Kristian Høgsberg | d56bd90 | 2012-06-05 09:58:51 -0400 | [diff] [blame] | 2118 | struct weston_compositor *compositor; |
Kristian Høgsberg | d56bd90 | 2012-06-05 09:58:51 -0400 | [diff] [blame] | 2119 | uint32_t serial; |
| 2120 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 2121 | if (!view) |
Kristian Høgsberg | d56bd90 | 2012-06-05 09:58:51 -0400 | [diff] [blame] | 2122 | return; |
| 2123 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 2124 | compositor = view->surface->compositor; |
Kristian Høgsberg | e11ef64 | 2014-02-11 16:35:22 -0800 | [diff] [blame] | 2125 | serial = wl_display_next_serial(compositor->wl_display); |
| 2126 | ping_handler(view->surface, serial); |
Kristian Høgsberg | d56bd90 | 2012-06-05 09:58:51 -0400 | [diff] [blame] | 2127 | } |
| 2128 | |
| 2129 | static void |
Jasper St. Pierre | faf27a9 | 2013-12-09 17:36:28 -0500 | [diff] [blame] | 2130 | shell_surface_lose_keyboard_focus(struct shell_surface *shsurf) |
| 2131 | { |
| 2132 | if (--shsurf->focus_count == 0) |
Jasper St. Pierre | 973d787 | 2014-05-06 08:44:29 -0400 | [diff] [blame] | 2133 | shell_surface_state_changed(shsurf); |
Jasper St. Pierre | faf27a9 | 2013-12-09 17:36:28 -0500 | [diff] [blame] | 2134 | } |
| 2135 | |
| 2136 | static void |
| 2137 | shell_surface_gain_keyboard_focus(struct shell_surface *shsurf) |
| 2138 | { |
| 2139 | if (shsurf->focus_count++ == 0) |
Jasper St. Pierre | 973d787 | 2014-05-06 08:44:29 -0400 | [diff] [blame] | 2140 | shell_surface_state_changed(shsurf); |
Jasper St. Pierre | faf27a9 | 2013-12-09 17:36:28 -0500 | [diff] [blame] | 2141 | } |
| 2142 | |
| 2143 | static void |
| 2144 | handle_keyboard_focus(struct wl_listener *listener, void *data) |
| 2145 | { |
| 2146 | struct weston_keyboard *keyboard = data; |
| 2147 | struct shell_seat *seat = get_shell_seat(keyboard->seat); |
| 2148 | |
| 2149 | if (seat->focused_surface) { |
| 2150 | struct shell_surface *shsurf = get_shell_surface(seat->focused_surface); |
| 2151 | if (shsurf) |
| 2152 | shell_surface_lose_keyboard_focus(shsurf); |
| 2153 | } |
| 2154 | |
| 2155 | seat->focused_surface = keyboard->focus; |
| 2156 | |
| 2157 | if (seat->focused_surface) { |
| 2158 | struct shell_surface *shsurf = get_shell_surface(seat->focused_surface); |
| 2159 | if (shsurf) |
| 2160 | shell_surface_gain_keyboard_focus(shsurf); |
| 2161 | } |
| 2162 | } |
| 2163 | |
| 2164 | static void |
Kristian Høgsberg | dd62aba | 2014-02-12 09:56:19 -0800 | [diff] [blame] | 2165 | shell_client_pong(struct shell_client *sc, uint32_t serial) |
Rafael Antognolli | e2a3455 | 2013-12-03 15:35:45 -0200 | [diff] [blame] | 2166 | { |
Kristian Høgsberg | dd62aba | 2014-02-12 09:56:19 -0800 | [diff] [blame] | 2167 | if (sc->ping_serial != serial) |
| 2168 | return; |
Rafael Antognolli | e2a3455 | 2013-12-03 15:35:45 -0200 | [diff] [blame] | 2169 | |
Kristian Høgsberg | dd62aba | 2014-02-12 09:56:19 -0800 | [diff] [blame] | 2170 | sc->unresponsive = 0; |
| 2171 | end_busy_cursor(sc->shell->compositor, sc->client); |
Rafael Antognolli | e2a3455 | 2013-12-03 15:35:45 -0200 | [diff] [blame] | 2172 | |
Kristian Høgsberg | dd62aba | 2014-02-12 09:56:19 -0800 | [diff] [blame] | 2173 | if (sc->ping_timer) { |
| 2174 | wl_event_source_remove(sc->ping_timer); |
| 2175 | sc->ping_timer = NULL; |
| 2176 | } |
| 2177 | |
| 2178 | } |
| 2179 | |
| 2180 | static void |
| 2181 | shell_surface_pong(struct wl_client *client, |
| 2182 | struct wl_resource *resource, uint32_t serial) |
| 2183 | { |
Jason Ekstrand | 9e9512f | 2014-04-16 21:12:10 -0500 | [diff] [blame] | 2184 | struct shell_surface *shsurf = wl_resource_get_user_data(resource); |
| 2185 | struct shell_client *sc = shsurf->owner; |
Kristian Høgsberg | dd62aba | 2014-02-12 09:56:19 -0800 | [diff] [blame] | 2186 | |
Kristian Høgsberg | dd62aba | 2014-02-12 09:56:19 -0800 | [diff] [blame] | 2187 | shell_client_pong(sc, serial); |
Rafael Antognolli | e2a3455 | 2013-12-03 15:35:45 -0200 | [diff] [blame] | 2188 | } |
| 2189 | |
| 2190 | static void |
Giulio Camuffo | 62942ad | 2013-09-11 18:20:47 +0200 | [diff] [blame] | 2191 | set_title(struct shell_surface *shsurf, const char *title) |
| 2192 | { |
| 2193 | free(shsurf->title); |
| 2194 | shsurf->title = strdup(title); |
| 2195 | } |
| 2196 | |
| 2197 | static void |
Jasper St. Pierre | ccf48fb | 2014-05-02 10:21:38 -0400 | [diff] [blame] | 2198 | set_window_geometry(struct shell_surface *shsurf, |
| 2199 | 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] | 2200 | { |
Jasper St. Pierre | ccf48fb | 2014-05-02 10:21:38 -0400 | [diff] [blame] | 2201 | shsurf->next_geometry.x = x; |
| 2202 | shsurf->next_geometry.y = y; |
| 2203 | shsurf->next_geometry.width = width; |
| 2204 | shsurf->next_geometry.height = height; |
| 2205 | shsurf->has_next_geometry = true; |
Kristian Høgsberg | e5c1ae9 | 2014-04-30 16:28:41 -0700 | [diff] [blame] | 2206 | } |
| 2207 | |
| 2208 | static void |
Kristian Høgsberg | e7afd91 | 2012-05-02 09:47:44 -0400 | [diff] [blame] | 2209 | shell_surface_set_title(struct wl_client *client, |
| 2210 | struct wl_resource *resource, const char *title) |
| 2211 | { |
Jason Ekstrand | 651f00e | 2013-06-14 10:07:54 -0500 | [diff] [blame] | 2212 | struct shell_surface *shsurf = wl_resource_get_user_data(resource); |
Kristian Høgsberg | e7afd91 | 2012-05-02 09:47:44 -0400 | [diff] [blame] | 2213 | |
Giulio Camuffo | 62942ad | 2013-09-11 18:20:47 +0200 | [diff] [blame] | 2214 | set_title(shsurf, title); |
Kristian Høgsberg | e7afd91 | 2012-05-02 09:47:44 -0400 | [diff] [blame] | 2215 | } |
| 2216 | |
| 2217 | static void |
| 2218 | shell_surface_set_class(struct wl_client *client, |
| 2219 | struct wl_resource *resource, const char *class) |
| 2220 | { |
Jason Ekstrand | 651f00e | 2013-06-14 10:07:54 -0500 | [diff] [blame] | 2221 | struct shell_surface *shsurf = wl_resource_get_user_data(resource); |
Kristian Høgsberg | e7afd91 | 2012-05-02 09:47:44 -0400 | [diff] [blame] | 2222 | |
| 2223 | free(shsurf->class); |
| 2224 | shsurf->class = strdup(class); |
| 2225 | } |
| 2226 | |
Alex Wu | 4539b08 | 2012-03-01 12:57:46 +0800 | [diff] [blame] | 2227 | static void |
Alexander Larsson | f82b6ca | 2013-05-28 16:23:39 +0200 | [diff] [blame] | 2228 | restore_output_mode(struct weston_output *output) |
| 2229 | { |
Hardening | 57388e4 | 2013-09-18 23:56:36 +0200 | [diff] [blame] | 2230 | if (output->current_mode != output->original_mode || |
| 2231 | (int32_t)output->current_scale != output->original_scale) |
Alexander Larsson | f82b6ca | 2013-05-28 16:23:39 +0200 | [diff] [blame] | 2232 | weston_output_switch_mode(output, |
Hardening | 57388e4 | 2013-09-18 23:56:36 +0200 | [diff] [blame] | 2233 | output->original_mode, |
| 2234 | output->original_scale, |
| 2235 | WESTON_MODE_SWITCH_RESTORE_NATIVE); |
Alexander Larsson | f82b6ca | 2013-05-28 16:23:39 +0200 | [diff] [blame] | 2236 | } |
| 2237 | |
| 2238 | static void |
| 2239 | restore_all_output_modes(struct weston_compositor *compositor) |
| 2240 | { |
| 2241 | struct weston_output *output; |
| 2242 | |
| 2243 | wl_list_for_each(output, &compositor->output_list, link) |
| 2244 | restore_output_mode(output); |
| 2245 | } |
| 2246 | |
Philip Withnall | 07926d9 | 2013-11-25 18:01:40 +0000 | [diff] [blame] | 2247 | /* The surface will be inserted into the list immediately after the link |
| 2248 | * returned by this function (i.e. will be stacked immediately above the |
| 2249 | * returned link). */ |
Giulio Camuffo | 412e6a5 | 2014-07-09 22:12:56 +0300 | [diff] [blame] | 2250 | static struct weston_layer_entry * |
Philip Withnall | 07926d9 | 2013-11-25 18:01:40 +0000 | [diff] [blame] | 2251 | shell_surface_calculate_layer_link (struct shell_surface *shsurf) |
| 2252 | { |
| 2253 | struct workspace *ws; |
Kristian Høgsberg | ead5242 | 2014-01-01 13:51:52 -0800 | [diff] [blame] | 2254 | struct weston_view *parent; |
Philip Withnall | 07926d9 | 2013-11-25 18:01:40 +0000 | [diff] [blame] | 2255 | |
| 2256 | switch (shsurf->type) { |
Ander Conselvan de Oliveira | ef6a7e4 | 2014-04-30 14:15:14 +0300 | [diff] [blame] | 2257 | case SHELL_SURFACE_XWAYLAND: |
| 2258 | return &shsurf->shell->fullscreen_layer.view_list; |
| 2259 | |
| 2260 | case SHELL_SURFACE_NONE: |
| 2261 | return NULL; |
| 2262 | |
Kristian Høgsberg | ead5242 | 2014-01-01 13:51:52 -0800 | [diff] [blame] | 2263 | case SHELL_SURFACE_POPUP: |
| 2264 | case SHELL_SURFACE_TOPLEVEL: |
Emilio Pozuelo Monfort | 9e7c759 | 2014-01-30 14:01:10 +0100 | [diff] [blame] | 2265 | if (shsurf->state.fullscreen && !shsurf->state.lowered) { |
Rafael Antognolli | 03b1659 | 2013-12-03 15:35:42 -0200 | [diff] [blame] | 2266 | return &shsurf->shell->fullscreen_layer.view_list; |
Rafael Antognolli | ed207b4 | 2013-12-03 15:35:43 -0200 | [diff] [blame] | 2267 | } else if (shsurf->parent) { |
Kristian Høgsberg | d55db69 | 2014-01-01 12:26:14 -0800 | [diff] [blame] | 2268 | /* Move the surface to its parent layer so |
| 2269 | * that surfaces which are transient for |
| 2270 | * fullscreen surfaces don't get hidden by the |
| 2271 | * fullscreen surfaces. */ |
Rafael Antognolli | ed207b4 | 2013-12-03 15:35:43 -0200 | [diff] [blame] | 2272 | |
| 2273 | /* TODO: Handle a parent with multiple views */ |
| 2274 | parent = get_default_view(shsurf->parent); |
| 2275 | if (parent) |
Giulio Camuffo | 412e6a5 | 2014-07-09 22:12:56 +0300 | [diff] [blame] | 2276 | return container_of(parent->layer_link.link.prev, |
| 2277 | struct weston_layer_entry, link); |
Rafael Antognolli | ed207b4 | 2013-12-03 15:35:43 -0200 | [diff] [blame] | 2278 | } |
Philip Withnall | 07926d9 | 2013-11-25 18:01:40 +0000 | [diff] [blame] | 2279 | |
Ander Conselvan de Oliveira | ef6a7e4 | 2014-04-30 14:15:14 +0300 | [diff] [blame] | 2280 | /* Move the surface to a normal workspace layer so that surfaces |
| 2281 | * which were previously fullscreen or transient are no longer |
| 2282 | * rendered on top. */ |
| 2283 | ws = get_current_workspace(shsurf->shell); |
| 2284 | return &ws->layer.view_list; |
Philip Withnall | 07926d9 | 2013-11-25 18:01:40 +0000 | [diff] [blame] | 2285 | } |
| 2286 | |
Ander Conselvan de Oliveira | ef6a7e4 | 2014-04-30 14:15:14 +0300 | [diff] [blame] | 2287 | assert(0 && "Unknown shell surface type"); |
Philip Withnall | 07926d9 | 2013-11-25 18:01:40 +0000 | [diff] [blame] | 2288 | } |
| 2289 | |
Philip Withnall | 648a4dd | 2013-11-25 18:01:44 +0000 | [diff] [blame] | 2290 | static void |
| 2291 | shell_surface_update_child_surface_layers (struct shell_surface *shsurf) |
| 2292 | { |
| 2293 | struct shell_surface *child; |
Giulio Camuffo | 412e6a5 | 2014-07-09 22:12:56 +0300 | [diff] [blame] | 2294 | struct weston_layer_entry *prev; |
Philip Withnall | 648a4dd | 2013-11-25 18:01:44 +0000 | [diff] [blame] | 2295 | |
| 2296 | /* Move the child layers to the same workspace as shsurf. They will be |
| 2297 | * stacked above shsurf. */ |
| 2298 | wl_list_for_each_reverse(child, &shsurf->children_list, children_link) { |
Giulio Camuffo | 412e6a5 | 2014-07-09 22:12:56 +0300 | [diff] [blame] | 2299 | 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] | 2300 | weston_view_damage_below(child->view); |
Philip Withnall | 648a4dd | 2013-11-25 18:01:44 +0000 | [diff] [blame] | 2301 | weston_view_geometry_dirty(child->view); |
Giulio Camuffo | 412e6a5 | 2014-07-09 22:12:56 +0300 | [diff] [blame] | 2302 | prev = container_of(shsurf->view->layer_link.link.prev, |
| 2303 | struct weston_layer_entry, link); |
| 2304 | weston_layer_entry_remove(&child->view->layer_link); |
| 2305 | weston_layer_entry_insert(prev, |
| 2306 | &child->view->layer_link); |
Philip Withnall | 648a4dd | 2013-11-25 18:01:44 +0000 | [diff] [blame] | 2307 | weston_view_geometry_dirty(child->view); |
| 2308 | weston_surface_damage(child->surface); |
| 2309 | |
| 2310 | /* Recurse. We don’t expect this to recurse very far (if |
| 2311 | * at all) because that would imply we have transient |
| 2312 | * (or popup) children of transient surfaces, which |
| 2313 | * would be unusual. */ |
| 2314 | shell_surface_update_child_surface_layers(child); |
| 2315 | } |
| 2316 | } |
| 2317 | } |
| 2318 | |
Philip Withnall | e1d75ae | 2013-11-25 18:01:41 +0000 | [diff] [blame] | 2319 | /* 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] | 2320 | * geometry to ensure the changes are redrawn. |
| 2321 | * |
| 2322 | * If any child surfaces exist and are mapped, ensure they’re in the same layer |
| 2323 | * as this surface. */ |
Philip Withnall | e1d75ae | 2013-11-25 18:01:41 +0000 | [diff] [blame] | 2324 | static void |
| 2325 | shell_surface_update_layer(struct shell_surface *shsurf) |
| 2326 | { |
Giulio Camuffo | 412e6a5 | 2014-07-09 22:12:56 +0300 | [diff] [blame] | 2327 | struct weston_layer_entry *new_layer_link; |
Philip Withnall | e1d75ae | 2013-11-25 18:01:41 +0000 | [diff] [blame] | 2328 | |
| 2329 | new_layer_link = shell_surface_calculate_layer_link(shsurf); |
| 2330 | |
Ander Conselvan de Oliveira | ef6a7e4 | 2014-04-30 14:15:14 +0300 | [diff] [blame] | 2331 | if (new_layer_link == NULL) |
| 2332 | return; |
Philip Withnall | e1d75ae | 2013-11-25 18:01:41 +0000 | [diff] [blame] | 2333 | if (new_layer_link == &shsurf->view->layer_link) |
| 2334 | return; |
| 2335 | |
| 2336 | weston_view_geometry_dirty(shsurf->view); |
Giulio Camuffo | 412e6a5 | 2014-07-09 22:12:56 +0300 | [diff] [blame] | 2337 | weston_layer_entry_remove(&shsurf->view->layer_link); |
| 2338 | weston_layer_entry_insert(new_layer_link, &shsurf->view->layer_link); |
Philip Withnall | e1d75ae | 2013-11-25 18:01:41 +0000 | [diff] [blame] | 2339 | weston_view_geometry_dirty(shsurf->view); |
| 2340 | weston_surface_damage(shsurf->surface); |
Philip Withnall | 648a4dd | 2013-11-25 18:01:44 +0000 | [diff] [blame] | 2341 | |
| 2342 | shell_surface_update_child_surface_layers(shsurf); |
Philip Withnall | e1d75ae | 2013-11-25 18:01:41 +0000 | [diff] [blame] | 2343 | } |
| 2344 | |
Alexander Larsson | f82b6ca | 2013-05-28 16:23:39 +0200 | [diff] [blame] | 2345 | static void |
Philip Withnall | dc4332f | 2013-11-25 18:01:38 +0000 | [diff] [blame] | 2346 | shell_surface_set_parent(struct shell_surface *shsurf, |
| 2347 | struct weston_surface *parent) |
| 2348 | { |
| 2349 | shsurf->parent = parent; |
Philip Withnall | 648a4dd | 2013-11-25 18:01:44 +0000 | [diff] [blame] | 2350 | |
| 2351 | wl_list_remove(&shsurf->children_link); |
| 2352 | wl_list_init(&shsurf->children_link); |
| 2353 | |
| 2354 | /* Insert into the parent surface’s child list. */ |
| 2355 | if (parent != NULL) { |
| 2356 | struct shell_surface *parent_shsurf = get_shell_surface(parent); |
| 2357 | if (parent_shsurf != NULL) |
| 2358 | wl_list_insert(&parent_shsurf->children_list, |
| 2359 | &shsurf->children_link); |
| 2360 | } |
Philip Withnall | dc4332f | 2013-11-25 18:01:38 +0000 | [diff] [blame] | 2361 | } |
| 2362 | |
| 2363 | static void |
Philip Withnall | 352e7ed | 2013-11-25 18:01:35 +0000 | [diff] [blame] | 2364 | shell_surface_set_output(struct shell_surface *shsurf, |
| 2365 | struct weston_output *output) |
| 2366 | { |
| 2367 | struct weston_surface *es = shsurf->surface; |
| 2368 | |
| 2369 | /* get the default output, if the client set it as NULL |
| 2370 | check whether the ouput is available */ |
| 2371 | if (output) |
| 2372 | shsurf->output = output; |
| 2373 | else if (es->output) |
| 2374 | shsurf->output = es->output; |
| 2375 | else |
| 2376 | shsurf->output = get_default_output(es->compositor); |
| 2377 | } |
| 2378 | |
| 2379 | static void |
Rafael Antognolli | 03b1659 | 2013-12-03 15:35:42 -0200 | [diff] [blame] | 2380 | surface_clear_next_states(struct shell_surface *shsurf) |
| 2381 | { |
| 2382 | shsurf->next_state.maximized = false; |
| 2383 | shsurf->next_state.fullscreen = false; |
| 2384 | |
| 2385 | if ((shsurf->next_state.maximized != shsurf->state.maximized) || |
| 2386 | (shsurf->next_state.fullscreen != shsurf->state.fullscreen)) |
| 2387 | shsurf->state_changed = true; |
| 2388 | } |
| 2389 | |
| 2390 | static void |
Philip Withnall | becb77e | 2013-11-25 18:01:30 +0000 | [diff] [blame] | 2391 | set_toplevel(struct shell_surface *shsurf) |
| 2392 | { |
Kristian Høgsberg | 41fbf6f | 2013-12-05 22:31:25 -0800 | [diff] [blame] | 2393 | shell_surface_set_parent(shsurf, NULL); |
| 2394 | surface_clear_next_states(shsurf); |
Kristian Høgsberg | c8f8dd8 | 2013-12-05 23:20:33 -0800 | [diff] [blame] | 2395 | shsurf->type = SHELL_SURFACE_TOPLEVEL; |
Philip Withnall | 648a4dd | 2013-11-25 18:01:44 +0000 | [diff] [blame] | 2396 | |
| 2397 | /* The layer_link is updated in set_surface_type(), |
| 2398 | * called from configure. */ |
Philip Withnall | becb77e | 2013-11-25 18:01:30 +0000 | [diff] [blame] | 2399 | } |
| 2400 | |
| 2401 | static void |
| 2402 | shell_surface_set_toplevel(struct wl_client *client, |
| 2403 | struct wl_resource *resource) |
| 2404 | { |
| 2405 | struct shell_surface *surface = wl_resource_get_user_data(resource); |
| 2406 | |
| 2407 | set_toplevel(surface); |
| 2408 | } |
| 2409 | |
| 2410 | static void |
| 2411 | set_transient(struct shell_surface *shsurf, |
| 2412 | struct weston_surface *parent, int x, int y, uint32_t flags) |
| 2413 | { |
Philip Withnall | dc4332f | 2013-11-25 18:01:38 +0000 | [diff] [blame] | 2414 | assert(parent != NULL); |
| 2415 | |
Kristian Høgsberg | 9f7e331 | 2014-01-02 22:40:37 -0800 | [diff] [blame] | 2416 | shell_surface_set_parent(shsurf, parent); |
| 2417 | |
| 2418 | surface_clear_next_states(shsurf); |
| 2419 | |
Philip Withnall | becb77e | 2013-11-25 18:01:30 +0000 | [diff] [blame] | 2420 | shsurf->transient.x = x; |
| 2421 | shsurf->transient.y = y; |
| 2422 | shsurf->transient.flags = flags; |
Philip Withnall | dc4332f | 2013-11-25 18:01:38 +0000 | [diff] [blame] | 2423 | |
Rafael Antognolli | ed207b4 | 2013-12-03 15:35:43 -0200 | [diff] [blame] | 2424 | shsurf->next_state.relative = true; |
Kristian Høgsberg | a1df7ac | 2013-12-31 15:01:01 -0800 | [diff] [blame] | 2425 | shsurf->state_changed = true; |
Kristian Høgsberg | c8f8dd8 | 2013-12-05 23:20:33 -0800 | [diff] [blame] | 2426 | shsurf->type = SHELL_SURFACE_TOPLEVEL; |
Philip Withnall | 648a4dd | 2013-11-25 18:01:44 +0000 | [diff] [blame] | 2427 | |
| 2428 | /* The layer_link is updated in set_surface_type(), |
| 2429 | * called from configure. */ |
Philip Withnall | becb77e | 2013-11-25 18:01:30 +0000 | [diff] [blame] | 2430 | } |
| 2431 | |
| 2432 | static void |
| 2433 | shell_surface_set_transient(struct wl_client *client, |
| 2434 | struct wl_resource *resource, |
| 2435 | struct wl_resource *parent_resource, |
| 2436 | int x, int y, uint32_t flags) |
| 2437 | { |
| 2438 | struct shell_surface *shsurf = wl_resource_get_user_data(resource); |
| 2439 | struct weston_surface *parent = |
| 2440 | wl_resource_get_user_data(parent_resource); |
| 2441 | |
| 2442 | set_transient(shsurf, parent, x, y, flags); |
| 2443 | } |
| 2444 | |
| 2445 | static void |
| 2446 | set_fullscreen(struct shell_surface *shsurf, |
| 2447 | uint32_t method, |
| 2448 | uint32_t framerate, |
| 2449 | struct weston_output *output) |
| 2450 | { |
Philip Withnall | 352e7ed | 2013-11-25 18:01:35 +0000 | [diff] [blame] | 2451 | shell_surface_set_output(shsurf, output); |
Jasper St. Pierre | 6458ec3 | 2014-04-11 16:00:31 -0700 | [diff] [blame] | 2452 | shsurf->type = SHELL_SURFACE_TOPLEVEL; |
Philip Withnall | becb77e | 2013-11-25 18:01:30 +0000 | [diff] [blame] | 2453 | |
| 2454 | shsurf->fullscreen_output = shsurf->output; |
| 2455 | shsurf->fullscreen.type = method; |
| 2456 | shsurf->fullscreen.framerate = framerate; |
Philip Withnall | dc4332f | 2013-11-25 18:01:38 +0000 | [diff] [blame] | 2457 | |
Jasper St. Pierre | 6458ec3 | 2014-04-11 16:00:31 -0700 | [diff] [blame] | 2458 | send_configure_for_surface(shsurf); |
Philip Withnall | becb77e | 2013-11-25 18:01:30 +0000 | [diff] [blame] | 2459 | } |
| 2460 | |
| 2461 | static void |
Zhang, Xiong Y | 3123693 | 2013-12-13 22:10:57 +0200 | [diff] [blame] | 2462 | weston_view_set_initial_position(struct weston_view *view, |
| 2463 | struct desktop_shell *shell); |
| 2464 | |
| 2465 | static void |
Philip Withnall | becb77e | 2013-11-25 18:01:30 +0000 | [diff] [blame] | 2466 | unset_fullscreen(struct shell_surface *shsurf) |
Alex Wu | 4539b08 | 2012-03-01 12:57:46 +0800 | [diff] [blame] | 2467 | { |
Philip Withnall | f85fe84 | 2013-11-25 18:01:37 +0000 | [diff] [blame] | 2468 | /* Unset the fullscreen output, driver configuration and transforms. */ |
Alex Wu | bd3354b | 2012-04-17 17:20:49 +0800 | [diff] [blame] | 2469 | if (shsurf->fullscreen.type == WL_SHELL_SURFACE_FULLSCREEN_METHOD_DRIVER && |
| 2470 | shell_surface_is_top_fullscreen(shsurf)) { |
Alexander Larsson | f82b6ca | 2013-05-28 16:23:39 +0200 | [diff] [blame] | 2471 | restore_output_mode(shsurf->fullscreen_output); |
Alex Wu | bd3354b | 2012-04-17 17:20:49 +0800 | [diff] [blame] | 2472 | } |
Philip Withnall | f85fe84 | 2013-11-25 18:01:37 +0000 | [diff] [blame] | 2473 | |
Alex Wu | 4539b08 | 2012-03-01 12:57:46 +0800 | [diff] [blame] | 2474 | shsurf->fullscreen.type = WL_SHELL_SURFACE_FULLSCREEN_METHOD_DEFAULT; |
| 2475 | shsurf->fullscreen.framerate = 0; |
Philip Withnall | f85fe84 | 2013-11-25 18:01:37 +0000 | [diff] [blame] | 2476 | |
Alex Wu | 4539b08 | 2012-03-01 12:57:46 +0800 | [diff] [blame] | 2477 | wl_list_remove(&shsurf->fullscreen.transform.link); |
| 2478 | wl_list_init(&shsurf->fullscreen.transform.link); |
Philip Withnall | f85fe84 | 2013-11-25 18:01:37 +0000 | [diff] [blame] | 2479 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 2480 | if (shsurf->fullscreen.black_view) |
| 2481 | weston_surface_destroy(shsurf->fullscreen.black_view->surface); |
| 2482 | shsurf->fullscreen.black_view = NULL; |
Philip Withnall | f85fe84 | 2013-11-25 18:01:37 +0000 | [diff] [blame] | 2483 | |
Zhang, Xiong Y | 3123693 | 2013-12-13 22:10:57 +0200 | [diff] [blame] | 2484 | if (shsurf->saved_position_valid) |
| 2485 | weston_view_set_position(shsurf->view, |
| 2486 | shsurf->saved_x, shsurf->saved_y); |
| 2487 | else |
| 2488 | weston_view_set_initial_position(shsurf->view, shsurf->shell); |
| 2489 | |
Alex Wu | 7bcb8bd | 2012-04-27 09:07:24 +0800 | [diff] [blame] | 2490 | if (shsurf->saved_rotation_valid) { |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 2491 | wl_list_insert(&shsurf->view->geometry.transformation_list, |
Philip Withnall | becb77e | 2013-11-25 18:01:30 +0000 | [diff] [blame] | 2492 | &shsurf->rotation.transform.link); |
Alex Wu | 7bcb8bd | 2012-04-27 09:07:24 +0800 | [diff] [blame] | 2493 | shsurf->saved_rotation_valid = false; |
| 2494 | } |
Rafal Mielniczuk | 3e3862c | 2012-10-07 20:25:36 +0200 | [diff] [blame] | 2495 | |
Philip Withnall | e1d75ae | 2013-11-25 18:01:41 +0000 | [diff] [blame] | 2496 | /* Layer is updated in set_surface_type(). */ |
Alex Wu | 4539b08 | 2012-03-01 12:57:46 +0800 | [diff] [blame] | 2497 | } |
| 2498 | |
Rafal Mielniczuk | fffdcdd | 2013-03-11 19:26:54 +0100 | [diff] [blame] | 2499 | static void |
Philip Withnall | becb77e | 2013-11-25 18:01:30 +0000 | [diff] [blame] | 2500 | shell_surface_set_fullscreen(struct wl_client *client, |
| 2501 | struct wl_resource *resource, |
| 2502 | uint32_t method, |
| 2503 | uint32_t framerate, |
| 2504 | struct wl_resource *output_resource) |
| 2505 | { |
| 2506 | struct shell_surface *shsurf = wl_resource_get_user_data(resource); |
| 2507 | struct weston_output *output; |
| 2508 | |
| 2509 | if (output_resource) |
| 2510 | output = wl_resource_get_user_data(output_resource); |
| 2511 | else |
| 2512 | output = NULL; |
| 2513 | |
Rafael Antognolli | 4b99a40 | 2013-12-03 15:35:44 -0200 | [diff] [blame] | 2514 | shell_surface_set_parent(shsurf, NULL); |
| 2515 | |
Rafael Antognolli | 03b1659 | 2013-12-03 15:35:42 -0200 | [diff] [blame] | 2516 | surface_clear_next_states(shsurf); |
Jasper St. Pierre | 8c6aa45 | 2014-02-08 18:29:49 -0500 | [diff] [blame] | 2517 | shsurf->next_state.fullscreen = true; |
| 2518 | shsurf->state_changed = true; |
Jasper St. Pierre | 6458ec3 | 2014-04-11 16:00:31 -0700 | [diff] [blame] | 2519 | set_fullscreen(shsurf, method, framerate, output); |
Philip Withnall | becb77e | 2013-11-25 18:01:30 +0000 | [diff] [blame] | 2520 | } |
| 2521 | |
| 2522 | static void |
| 2523 | set_popup(struct shell_surface *shsurf, |
| 2524 | struct weston_surface *parent, |
| 2525 | struct weston_seat *seat, |
| 2526 | uint32_t serial, |
| 2527 | int32_t x, |
| 2528 | int32_t y) |
| 2529 | { |
Philip Withnall | dc4332f | 2013-11-25 18:01:38 +0000 | [diff] [blame] | 2530 | assert(parent != NULL); |
| 2531 | |
Philip Withnall | becb77e | 2013-11-25 18:01:30 +0000 | [diff] [blame] | 2532 | shsurf->popup.shseat = get_shell_seat(seat); |
| 2533 | shsurf->popup.serial = serial; |
| 2534 | shsurf->popup.x = x; |
| 2535 | shsurf->popup.y = y; |
Philip Withnall | dc4332f | 2013-11-25 18:01:38 +0000 | [diff] [blame] | 2536 | |
Kristian Høgsberg | c8f8dd8 | 2013-12-05 23:20:33 -0800 | [diff] [blame] | 2537 | shsurf->type = SHELL_SURFACE_POPUP; |
Philip Withnall | becb77e | 2013-11-25 18:01:30 +0000 | [diff] [blame] | 2538 | } |
| 2539 | |
| 2540 | static void |
| 2541 | shell_surface_set_popup(struct wl_client *client, |
| 2542 | struct wl_resource *resource, |
| 2543 | struct wl_resource *seat_resource, |
| 2544 | uint32_t serial, |
| 2545 | struct wl_resource *parent_resource, |
| 2546 | int32_t x, int32_t y, uint32_t flags) |
| 2547 | { |
| 2548 | struct shell_surface *shsurf = wl_resource_get_user_data(resource); |
Rafael Antognolli | 4b99a40 | 2013-12-03 15:35:44 -0200 | [diff] [blame] | 2549 | struct weston_surface *parent = |
| 2550 | wl_resource_get_user_data(parent_resource); |
| 2551 | |
| 2552 | shell_surface_set_parent(shsurf, parent); |
Philip Withnall | becb77e | 2013-11-25 18:01:30 +0000 | [diff] [blame] | 2553 | |
Rafael Antognolli | 03b1659 | 2013-12-03 15:35:42 -0200 | [diff] [blame] | 2554 | surface_clear_next_states(shsurf); |
Philip Withnall | becb77e | 2013-11-25 18:01:30 +0000 | [diff] [blame] | 2555 | set_popup(shsurf, |
Rafael Antognolli | 4b99a40 | 2013-12-03 15:35:44 -0200 | [diff] [blame] | 2556 | parent, |
Philip Withnall | becb77e | 2013-11-25 18:01:30 +0000 | [diff] [blame] | 2557 | wl_resource_get_user_data(seat_resource), |
| 2558 | serial, x, y); |
| 2559 | } |
| 2560 | |
| 2561 | static void |
Philip Withnall | becb77e | 2013-11-25 18:01:30 +0000 | [diff] [blame] | 2562 | unset_maximized(struct shell_surface *shsurf) |
Rafal Mielniczuk | fffdcdd | 2013-03-11 19:26:54 +0100 | [diff] [blame] | 2563 | { |
Rafal Mielniczuk | fffdcdd | 2013-03-11 19:26:54 +0100 | [diff] [blame] | 2564 | /* undo all maximized things here */ |
| 2565 | shsurf->output = get_default_output(shsurf->surface->compositor); |
Zhang, Xiong Y | 3123693 | 2013-12-13 22:10:57 +0200 | [diff] [blame] | 2566 | |
| 2567 | if (shsurf->saved_position_valid) |
| 2568 | weston_view_set_position(shsurf->view, |
| 2569 | shsurf->saved_x, shsurf->saved_y); |
| 2570 | else |
| 2571 | weston_view_set_initial_position(shsurf->view, shsurf->shell); |
Rafal Mielniczuk | fffdcdd | 2013-03-11 19:26:54 +0100 | [diff] [blame] | 2572 | |
| 2573 | if (shsurf->saved_rotation_valid) { |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 2574 | wl_list_insert(&shsurf->view->geometry.transformation_list, |
| 2575 | &shsurf->rotation.transform.link); |
Rafal Mielniczuk | fffdcdd | 2013-03-11 19:26:54 +0100 | [diff] [blame] | 2576 | shsurf->saved_rotation_valid = false; |
| 2577 | } |
| 2578 | |
Philip Withnall | e1d75ae | 2013-11-25 18:01:41 +0000 | [diff] [blame] | 2579 | /* Layer is updated in set_surface_type(). */ |
Rafal Mielniczuk | fffdcdd | 2013-03-11 19:26:54 +0100 | [diff] [blame] | 2580 | } |
| 2581 | |
Philip Withnall | becb77e | 2013-11-25 18:01:30 +0000 | [diff] [blame] | 2582 | static void |
Manuel Bachmann | 50c87db | 2014-02-26 15:52:13 +0100 | [diff] [blame] | 2583 | set_minimized(struct weston_surface *surface, uint32_t is_true) |
| 2584 | { |
| 2585 | struct shell_surface *shsurf; |
| 2586 | struct workspace *current_ws; |
| 2587 | struct weston_seat *seat; |
| 2588 | struct weston_surface *focus; |
| 2589 | struct weston_view *view; |
| 2590 | |
| 2591 | view = get_default_view(surface); |
| 2592 | if (!view) |
| 2593 | return; |
| 2594 | |
| 2595 | assert(weston_surface_get_main_surface(view->surface) == view->surface); |
| 2596 | |
| 2597 | shsurf = get_shell_surface(surface); |
| 2598 | current_ws = get_current_workspace(shsurf->shell); |
| 2599 | |
Giulio Camuffo | 412e6a5 | 2014-07-09 22:12:56 +0300 | [diff] [blame] | 2600 | weston_layer_entry_remove(&view->layer_link); |
Manuel Bachmann | 50c87db | 2014-02-26 15:52:13 +0100 | [diff] [blame] | 2601 | /* hide or show, depending on the state */ |
| 2602 | if (is_true) { |
Giulio Camuffo | 412e6a5 | 2014-07-09 22:12:56 +0300 | [diff] [blame] | 2603 | 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] | 2604 | |
| 2605 | drop_focus_state(shsurf->shell, current_ws, view->surface); |
| 2606 | wl_list_for_each(seat, &shsurf->shell->compositor->seat_list, link) { |
| 2607 | if (!seat->keyboard) |
| 2608 | continue; |
| 2609 | focus = weston_surface_get_main_surface(seat->keyboard->focus); |
| 2610 | if (focus == view->surface) |
| 2611 | weston_keyboard_set_focus(seat->keyboard, NULL); |
| 2612 | } |
| 2613 | } |
| 2614 | else { |
Giulio Camuffo | 412e6a5 | 2014-07-09 22:12:56 +0300 | [diff] [blame] | 2615 | weston_layer_entry_insert(¤t_ws->layer.view_list, &view->layer_link); |
Manuel Bachmann | 50c87db | 2014-02-26 15:52:13 +0100 | [diff] [blame] | 2616 | |
| 2617 | wl_list_for_each(seat, &shsurf->shell->compositor->seat_list, link) { |
| 2618 | if (!seat->keyboard) |
| 2619 | continue; |
Emilio Pozuelo Monfort | 9e7c759 | 2014-01-30 14:01:10 +0100 | [diff] [blame] | 2620 | activate(shsurf->shell, view->surface, seat, true); |
Manuel Bachmann | 50c87db | 2014-02-26 15:52:13 +0100 | [diff] [blame] | 2621 | } |
| 2622 | } |
| 2623 | |
| 2624 | shell_surface_update_child_surface_layers(shsurf); |
| 2625 | |
| 2626 | weston_view_damage_below(view); |
| 2627 | } |
| 2628 | |
| 2629 | static void |
Philip Withnall | becb77e | 2013-11-25 18:01:30 +0000 | [diff] [blame] | 2630 | shell_surface_set_maximized(struct wl_client *client, |
| 2631 | struct wl_resource *resource, |
| 2632 | struct wl_resource *output_resource) |
| 2633 | { |
| 2634 | struct shell_surface *shsurf = wl_resource_get_user_data(resource); |
| 2635 | struct weston_output *output; |
| 2636 | |
Jasper St. Pierre | 9aa8ce6 | 2014-04-11 16:18:54 -0700 | [diff] [blame] | 2637 | surface_clear_next_states(shsurf); |
| 2638 | shsurf->next_state.maximized = true; |
| 2639 | shsurf->state_changed = true; |
| 2640 | |
| 2641 | shsurf->type = SHELL_SURFACE_TOPLEVEL; |
| 2642 | shell_surface_set_parent(shsurf, NULL); |
| 2643 | |
Philip Withnall | becb77e | 2013-11-25 18:01:30 +0000 | [diff] [blame] | 2644 | if (output_resource) |
| 2645 | output = wl_resource_get_user_data(output_resource); |
| 2646 | else |
| 2647 | output = NULL; |
| 2648 | |
Jasper St. Pierre | 9aa8ce6 | 2014-04-11 16:18:54 -0700 | [diff] [blame] | 2649 | shell_surface_set_output(shsurf, output); |
Rafael Antognolli | 4b99a40 | 2013-12-03 15:35:44 -0200 | [diff] [blame] | 2650 | |
Jasper St. Pierre | 9aa8ce6 | 2014-04-11 16:18:54 -0700 | [diff] [blame] | 2651 | send_configure_for_surface(shsurf); |
Philip Withnall | becb77e | 2013-11-25 18:01:30 +0000 | [diff] [blame] | 2652 | } |
| 2653 | |
Philip Withnall | e1d75ae | 2013-11-25 18:01:41 +0000 | [diff] [blame] | 2654 | /* This is only ever called from set_surface_type(), so there’s no need to |
| 2655 | * update layer_links here, since they’ll be updated when we return. */ |
Pekka Paalanen | 9826223 | 2011-12-01 10:42:22 +0200 | [diff] [blame] | 2656 | static int |
Philip Withnall | becb77e | 2013-11-25 18:01:30 +0000 | [diff] [blame] | 2657 | reset_surface_type(struct shell_surface *surface) |
Pekka Paalanen | 9826223 | 2011-12-01 10:42:22 +0200 | [diff] [blame] | 2658 | { |
Rafael Antognolli | 03b1659 | 2013-12-03 15:35:42 -0200 | [diff] [blame] | 2659 | if (surface->state.fullscreen) |
Philip Withnall | becb77e | 2013-11-25 18:01:30 +0000 | [diff] [blame] | 2660 | unset_fullscreen(surface); |
Rafael Antognolli | 03b1659 | 2013-12-03 15:35:42 -0200 | [diff] [blame] | 2661 | if (surface->state.maximized) |
Philip Withnall | becb77e | 2013-11-25 18:01:30 +0000 | [diff] [blame] | 2662 | unset_maximized(surface); |
Pekka Paalanen | 9826223 | 2011-12-01 10:42:22 +0200 | [diff] [blame] | 2663 | |
Pekka Paalanen | 9826223 | 2011-12-01 10:42:22 +0200 | [diff] [blame] | 2664 | return 0; |
| 2665 | } |
| 2666 | |
Kristian Høgsberg | 4cca349 | 2011-01-18 07:53:49 -0500 | [diff] [blame] | 2667 | static void |
Rafael Antognolli | 03b1659 | 2013-12-03 15:35:42 -0200 | [diff] [blame] | 2668 | set_full_output(struct shell_surface *shsurf) |
| 2669 | { |
| 2670 | shsurf->saved_x = shsurf->view->geometry.x; |
| 2671 | shsurf->saved_y = shsurf->view->geometry.y; |
Rafael Antognolli | 3c4e3f7 | 2013-12-03 15:35:46 -0200 | [diff] [blame] | 2672 | shsurf->saved_width = shsurf->surface->width; |
| 2673 | shsurf->saved_height = shsurf->surface->height; |
| 2674 | shsurf->saved_size_valid = true; |
Rafael Antognolli | 03b1659 | 2013-12-03 15:35:42 -0200 | [diff] [blame] | 2675 | shsurf->saved_position_valid = true; |
| 2676 | |
| 2677 | if (!wl_list_empty(&shsurf->rotation.transform.link)) { |
| 2678 | wl_list_remove(&shsurf->rotation.transform.link); |
| 2679 | wl_list_init(&shsurf->rotation.transform.link); |
| 2680 | weston_view_geometry_dirty(shsurf->view); |
| 2681 | shsurf->saved_rotation_valid = true; |
| 2682 | } |
| 2683 | } |
| 2684 | |
| 2685 | static void |
Kristian Høgsberg | 7f366e7 | 2012-04-27 17:20:01 -0400 | [diff] [blame] | 2686 | set_surface_type(struct shell_surface *shsurf) |
| 2687 | { |
Kristian Høgsberg | 8150b19 | 2012-06-27 10:22:58 -0400 | [diff] [blame] | 2688 | struct weston_surface *pes = shsurf->parent; |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 2689 | struct weston_view *pev = get_default_view(pes); |
Kristian Høgsberg | 7f366e7 | 2012-04-27 17:20:01 -0400 | [diff] [blame] | 2690 | |
Philip Withnall | becb77e | 2013-11-25 18:01:30 +0000 | [diff] [blame] | 2691 | reset_surface_type(shsurf); |
Kristian Høgsberg | 7f366e7 | 2012-04-27 17:20:01 -0400 | [diff] [blame] | 2692 | |
Rafael Antognolli | 03b1659 | 2013-12-03 15:35:42 -0200 | [diff] [blame] | 2693 | shsurf->state = shsurf->next_state; |
Rafael Antognolli | 03b1659 | 2013-12-03 15:35:42 -0200 | [diff] [blame] | 2694 | shsurf->state_changed = false; |
Kristian Høgsberg | 7f366e7 | 2012-04-27 17:20:01 -0400 | [diff] [blame] | 2695 | |
| 2696 | switch (shsurf->type) { |
| 2697 | case SHELL_SURFACE_TOPLEVEL: |
Rafael Antognolli | ed207b4 | 2013-12-03 15:35:43 -0200 | [diff] [blame] | 2698 | if (shsurf->state.maximized || shsurf->state.fullscreen) { |
Rafael Antognolli | 03b1659 | 2013-12-03 15:35:42 -0200 | [diff] [blame] | 2699 | set_full_output(shsurf); |
Rafael Antognolli | ed207b4 | 2013-12-03 15:35:43 -0200 | [diff] [blame] | 2700 | } else if (shsurf->state.relative && pev) { |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 2701 | weston_view_set_position(shsurf->view, |
| 2702 | pev->geometry.x + shsurf->transient.x, |
| 2703 | pev->geometry.y + shsurf->transient.y); |
Rafael Antognolli | ed207b4 | 2013-12-03 15:35:43 -0200 | [diff] [blame] | 2704 | } |
Rafael Antognolli | 44a3162 | 2013-12-04 18:37:16 -0200 | [diff] [blame] | 2705 | break; |
Kristian Høgsberg | 7f366e7 | 2012-04-27 17:20:01 -0400 | [diff] [blame] | 2706 | |
Tiago Vignatti | fb2adba | 2013-06-12 15:43:21 -0300 | [diff] [blame] | 2707 | case SHELL_SURFACE_XWAYLAND: |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 2708 | weston_view_set_position(shsurf->view, shsurf->transient.x, |
| 2709 | shsurf->transient.y); |
Tiago Vignatti | fb2adba | 2013-06-12 15:43:21 -0300 | [diff] [blame] | 2710 | break; |
| 2711 | |
Philip Withnall | 0f640e2 | 2013-11-25 18:01:31 +0000 | [diff] [blame] | 2712 | case SHELL_SURFACE_POPUP: |
| 2713 | case SHELL_SURFACE_NONE: |
Kristian Høgsberg | 7f366e7 | 2012-04-27 17:20:01 -0400 | [diff] [blame] | 2714 | default: |
| 2715 | break; |
| 2716 | } |
Philip Withnall | e1d75ae | 2013-11-25 18:01:41 +0000 | [diff] [blame] | 2717 | |
| 2718 | /* Update the surface’s layer. */ |
| 2719 | shell_surface_update_layer(shsurf); |
Kristian Høgsberg | 7f366e7 | 2012-04-27 17:20:01 -0400 | [diff] [blame] | 2720 | } |
| 2721 | |
Tiago Vignatti | be14326 | 2012-04-16 17:31:41 +0300 | [diff] [blame] | 2722 | static struct desktop_shell * |
Juan Zhao | 96879df | 2012-02-07 08:45:41 +0800 | [diff] [blame] | 2723 | shell_surface_get_shell(struct shell_surface *shsurf) |
Pekka Paalanen | af0e34c | 2011-12-02 10:59:17 +0200 | [diff] [blame] | 2724 | { |
Kristian Høgsberg | 02e79dc | 2012-04-12 09:55:26 -0400 | [diff] [blame] | 2725 | return shsurf->shell; |
Juan Zhao | 96879df | 2012-02-07 08:45:41 +0800 | [diff] [blame] | 2726 | } |
| 2727 | |
Alex Wu | 2185843 | 2012-04-01 20:13:08 +0800 | [diff] [blame] | 2728 | static void |
Jason Ekstrand | 918f2dd | 2013-12-02 21:01:53 -0600 | [diff] [blame] | 2729 | 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] | 2730 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 2731 | static struct weston_view * |
Alex Wu | 4539b08 | 2012-03-01 12:57:46 +0800 | [diff] [blame] | 2732 | create_black_surface(struct weston_compositor *ec, |
Alex Wu | 2185843 | 2012-04-01 20:13:08 +0800 | [diff] [blame] | 2733 | struct weston_surface *fs_surface, |
John Kåre Alsaker | 490d02a | 2012-09-30 02:57:21 +0200 | [diff] [blame] | 2734 | float x, float y, int w, int h) |
Alex Wu | 4539b08 | 2012-03-01 12:57:46 +0800 | [diff] [blame] | 2735 | { |
| 2736 | struct weston_surface *surface = NULL; |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 2737 | struct weston_view *view; |
Alex Wu | 4539b08 | 2012-03-01 12:57:46 +0800 | [diff] [blame] | 2738 | |
| 2739 | surface = weston_surface_create(ec); |
| 2740 | if (surface == NULL) { |
Martin Minarik | 6d11836 | 2012-06-07 18:01:59 +0200 | [diff] [blame] | 2741 | weston_log("no memory\n"); |
Alex Wu | 4539b08 | 2012-03-01 12:57:46 +0800 | [diff] [blame] | 2742 | return NULL; |
| 2743 | } |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 2744 | view = weston_view_create(surface); |
| 2745 | if (surface == NULL) { |
| 2746 | weston_log("no memory\n"); |
| 2747 | weston_surface_destroy(surface); |
| 2748 | return NULL; |
| 2749 | } |
Alex Wu | 4539b08 | 2012-03-01 12:57:46 +0800 | [diff] [blame] | 2750 | |
Alex Wu | 2185843 | 2012-04-01 20:13:08 +0800 | [diff] [blame] | 2751 | surface->configure = black_surface_configure; |
Giulio Camuffo | 7fe01b1 | 2013-03-28 18:02:42 +0100 | [diff] [blame] | 2752 | surface->configure_private = fs_surface; |
Alex Wu | 4539b08 | 2012-03-01 12:57:46 +0800 | [diff] [blame] | 2753 | weston_surface_set_color(surface, 0.0, 0.0, 0.0, 1); |
Pekka Paalanen | 71f6f3b | 2012-10-10 12:49:26 +0300 | [diff] [blame] | 2754 | pixman_region32_fini(&surface->opaque); |
Kristian Høgsberg | 61f00f5 | 2012-08-03 16:31:36 -0400 | [diff] [blame] | 2755 | pixman_region32_init_rect(&surface->opaque, 0, 0, w, h); |
Jonas Ådahl | 33619a4 | 2013-01-15 21:25:55 +0100 | [diff] [blame] | 2756 | pixman_region32_fini(&surface->input); |
| 2757 | pixman_region32_init_rect(&surface->input, 0, 0, w, h); |
Jason Ekstrand | 918f2dd | 2013-12-02 21:01:53 -0600 | [diff] [blame] | 2758 | |
Jason Ekstrand | 6228ee2 | 2014-01-01 15:58:57 -0600 | [diff] [blame] | 2759 | weston_surface_set_size(surface, w, h); |
Jason Ekstrand | 918f2dd | 2013-12-02 21:01:53 -0600 | [diff] [blame] | 2760 | weston_view_set_position(view, x, y); |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 2761 | |
| 2762 | return view; |
Alex Wu | 4539b08 | 2012-03-01 12:57:46 +0800 | [diff] [blame] | 2763 | } |
| 2764 | |
Philip Withnall | ed8f1a9 | 2013-11-25 18:01:43 +0000 | [diff] [blame] | 2765 | static void |
| 2766 | shell_ensure_fullscreen_black_view(struct shell_surface *shsurf) |
| 2767 | { |
| 2768 | struct weston_output *output = shsurf->fullscreen_output; |
| 2769 | |
Rafael Antognolli | 03b1659 | 2013-12-03 15:35:42 -0200 | [diff] [blame] | 2770 | assert(shsurf->state.fullscreen); |
Philip Withnall | ed8f1a9 | 2013-11-25 18:01:43 +0000 | [diff] [blame] | 2771 | |
| 2772 | if (!shsurf->fullscreen.black_view) |
| 2773 | shsurf->fullscreen.black_view = |
| 2774 | create_black_surface(shsurf->surface->compositor, |
| 2775 | shsurf->surface, |
| 2776 | output->x, output->y, |
| 2777 | output->width, |
| 2778 | output->height); |
| 2779 | |
| 2780 | weston_view_geometry_dirty(shsurf->fullscreen.black_view); |
Giulio Camuffo | 412e6a5 | 2014-07-09 22:12:56 +0300 | [diff] [blame] | 2781 | weston_layer_entry_remove(&shsurf->fullscreen.black_view->layer_link); |
| 2782 | weston_layer_entry_insert(&shsurf->view->layer_link, |
| 2783 | &shsurf->fullscreen.black_view->layer_link); |
Philip Withnall | ed8f1a9 | 2013-11-25 18:01:43 +0000 | [diff] [blame] | 2784 | weston_view_geometry_dirty(shsurf->fullscreen.black_view); |
| 2785 | weston_surface_damage(shsurf->surface); |
Emilio Pozuelo Monfort | 9e7c759 | 2014-01-30 14:01:10 +0100 | [diff] [blame] | 2786 | |
| 2787 | shsurf->state.lowered = false; |
Philip Withnall | ed8f1a9 | 2013-11-25 18:01:43 +0000 | [diff] [blame] | 2788 | } |
| 2789 | |
Alex Wu | 4539b08 | 2012-03-01 12:57:46 +0800 | [diff] [blame] | 2790 | /* Create black surface and append it to the associated fullscreen surface. |
| 2791 | * Handle size dismatch and positioning according to the method. */ |
| 2792 | static void |
| 2793 | shell_configure_fullscreen(struct shell_surface *shsurf) |
| 2794 | { |
| 2795 | struct weston_output *output = shsurf->fullscreen_output; |
| 2796 | struct weston_surface *surface = shsurf->surface; |
| 2797 | struct weston_matrix *matrix; |
Kristian Høgsberg | 240dfeb | 2012-07-12 12:32:31 -0400 | [diff] [blame] | 2798 | float scale, output_aspect, surface_aspect, x, y; |
Giulio Camuffo | b836664 | 2013-04-25 13:57:46 +0300 | [diff] [blame] | 2799 | int32_t surf_x, surf_y, surf_width, surf_height; |
Alex Wu | 4539b08 | 2012-03-01 12:57:46 +0800 | [diff] [blame] | 2800 | |
Alexander Larsson | f82b6ca | 2013-05-28 16:23:39 +0200 | [diff] [blame] | 2801 | if (shsurf->fullscreen.type != WL_SHELL_SURFACE_FULLSCREEN_METHOD_DRIVER) |
| 2802 | restore_output_mode(output); |
| 2803 | |
Emilio Pozuelo Monfort | 9e7c759 | 2014-01-30 14:01:10 +0100 | [diff] [blame] | 2804 | /* Reverse the effect of lower_fullscreen_layer() */ |
Giulio Camuffo | 412e6a5 | 2014-07-09 22:12:56 +0300 | [diff] [blame] | 2805 | weston_layer_entry_remove(&shsurf->view->layer_link); |
| 2806 | 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] | 2807 | |
Philip Withnall | ed8f1a9 | 2013-11-25 18:01:43 +0000 | [diff] [blame] | 2808 | shell_ensure_fullscreen_black_view(shsurf); |
Alex Wu | 4539b08 | 2012-03-01 12:57:46 +0800 | [diff] [blame] | 2809 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 2810 | surface_subsurfaces_boundingbox(shsurf->surface, &surf_x, &surf_y, |
Giulio Camuffo | b836664 | 2013-04-25 13:57:46 +0300 | [diff] [blame] | 2811 | &surf_width, &surf_height); |
| 2812 | |
Alex Wu | 4539b08 | 2012-03-01 12:57:46 +0800 | [diff] [blame] | 2813 | switch (shsurf->fullscreen.type) { |
| 2814 | case WL_SHELL_SURFACE_FULLSCREEN_METHOD_DEFAULT: |
Pekka Paalanen | de685b8 | 2012-12-04 15:58:12 +0200 | [diff] [blame] | 2815 | if (surface->buffer_ref.buffer) |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 2816 | center_on_output(shsurf->view, shsurf->fullscreen_output); |
Alex Wu | 4539b08 | 2012-03-01 12:57:46 +0800 | [diff] [blame] | 2817 | break; |
| 2818 | case WL_SHELL_SURFACE_FULLSCREEN_METHOD_SCALE: |
Rob Bradford | 9f3dd15 | 2013-02-12 11:53:47 +0000 | [diff] [blame] | 2819 | /* 1:1 mapping between surface and output dimensions */ |
Giulio Camuffo | b836664 | 2013-04-25 13:57:46 +0300 | [diff] [blame] | 2820 | if (output->width == surf_width && |
| 2821 | output->height == surf_height) { |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 2822 | weston_view_set_position(shsurf->view, |
| 2823 | output->x - surf_x, |
| 2824 | output->y - surf_y); |
Rob Bradford | 9f3dd15 | 2013-02-12 11:53:47 +0000 | [diff] [blame] | 2825 | break; |
| 2826 | } |
| 2827 | |
Alex Wu | 4539b08 | 2012-03-01 12:57:46 +0800 | [diff] [blame] | 2828 | matrix = &shsurf->fullscreen.transform.matrix; |
| 2829 | weston_matrix_init(matrix); |
Kristian Høgsberg | 240dfeb | 2012-07-12 12:32:31 -0400 | [diff] [blame] | 2830 | |
Scott Moreau | 1bad5db | 2012-08-18 01:04:05 -0600 | [diff] [blame] | 2831 | output_aspect = (float) output->width / |
| 2832 | (float) output->height; |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 2833 | /* XXX: Use surf_width and surf_height here? */ |
| 2834 | surface_aspect = (float) surface->width / |
| 2835 | (float) surface->height; |
Kristian Høgsberg | 240dfeb | 2012-07-12 12:32:31 -0400 | [diff] [blame] | 2836 | if (output_aspect < surface_aspect) |
Scott Moreau | 1bad5db | 2012-08-18 01:04:05 -0600 | [diff] [blame] | 2837 | scale = (float) output->width / |
Giulio Camuffo | b836664 | 2013-04-25 13:57:46 +0300 | [diff] [blame] | 2838 | (float) surf_width; |
Kristian Høgsberg | 240dfeb | 2012-07-12 12:32:31 -0400 | [diff] [blame] | 2839 | else |
Scott Moreau | 1bad5db | 2012-08-18 01:04:05 -0600 | [diff] [blame] | 2840 | scale = (float) output->height / |
Giulio Camuffo | b836664 | 2013-04-25 13:57:46 +0300 | [diff] [blame] | 2841 | (float) surf_height; |
Kristian Høgsberg | 240dfeb | 2012-07-12 12:32:31 -0400 | [diff] [blame] | 2842 | |
Alex Wu | 4539b08 | 2012-03-01 12:57:46 +0800 | [diff] [blame] | 2843 | weston_matrix_scale(matrix, scale, scale, 1); |
| 2844 | wl_list_remove(&shsurf->fullscreen.transform.link); |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 2845 | wl_list_insert(&shsurf->view->geometry.transformation_list, |
Alex Wu | 4539b08 | 2012-03-01 12:57:46 +0800 | [diff] [blame] | 2846 | &shsurf->fullscreen.transform.link); |
Giulio Camuffo | b836664 | 2013-04-25 13:57:46 +0300 | [diff] [blame] | 2847 | x = output->x + (output->width - surf_width * scale) / 2 - surf_x; |
| 2848 | y = output->y + (output->height - surf_height * scale) / 2 - surf_y; |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 2849 | weston_view_set_position(shsurf->view, x, y); |
Kristian Høgsberg | 240dfeb | 2012-07-12 12:32:31 -0400 | [diff] [blame] | 2850 | |
Alex Wu | 4539b08 | 2012-03-01 12:57:46 +0800 | [diff] [blame] | 2851 | break; |
| 2852 | case WL_SHELL_SURFACE_FULLSCREEN_METHOD_DRIVER: |
Alex Wu | bd3354b | 2012-04-17 17:20:49 +0800 | [diff] [blame] | 2853 | if (shell_surface_is_top_fullscreen(shsurf)) { |
Quentin Glidic | c0d79ce | 2013-01-29 14:16:13 +0100 | [diff] [blame] | 2854 | struct weston_mode mode = {0, |
Pekka Paalanen | 952b6c8 | 2014-03-14 14:38:15 +0200 | [diff] [blame] | 2855 | surf_width * surface->buffer_viewport.buffer.scale, |
| 2856 | surf_height * surface->buffer_viewport.buffer.scale, |
Alex Wu | bd3354b | 2012-04-17 17:20:49 +0800 | [diff] [blame] | 2857 | shsurf->fullscreen.framerate}; |
| 2858 | |
Pekka Paalanen | 952b6c8 | 2014-03-14 14:38:15 +0200 | [diff] [blame] | 2859 | if (weston_output_switch_mode(output, &mode, surface->buffer_viewport.buffer.scale, |
Hardening | 57388e4 | 2013-09-18 23:56:36 +0200 | [diff] [blame] | 2860 | WESTON_MODE_SWITCH_SET_TEMPORARY) == 0) { |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 2861 | weston_view_set_position(shsurf->view, |
| 2862 | output->x - surf_x, |
| 2863 | output->y - surf_y); |
Jason Ekstrand | 918f2dd | 2013-12-02 21:01:53 -0600 | [diff] [blame] | 2864 | shsurf->fullscreen.black_view->surface->width = output->width; |
| 2865 | shsurf->fullscreen.black_view->surface->height = output->height; |
| 2866 | weston_view_set_position(shsurf->fullscreen.black_view, |
| 2867 | output->x - surf_x, |
| 2868 | output->y - surf_y); |
Alex Wu | bd3354b | 2012-04-17 17:20:49 +0800 | [diff] [blame] | 2869 | break; |
Alexander Larsson | d622ed3 | 2013-05-28 16:23:40 +0200 | [diff] [blame] | 2870 | } else { |
Alexander Larsson | f82b6ca | 2013-05-28 16:23:39 +0200 | [diff] [blame] | 2871 | restore_output_mode(output); |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 2872 | center_on_output(shsurf->view, output); |
Alexander Larsson | d622ed3 | 2013-05-28 16:23:40 +0200 | [diff] [blame] | 2873 | } |
Alex Wu | bd3354b | 2012-04-17 17:20:49 +0800 | [diff] [blame] | 2874 | } |
Alex Wu | 4539b08 | 2012-03-01 12:57:46 +0800 | [diff] [blame] | 2875 | break; |
| 2876 | case WL_SHELL_SURFACE_FULLSCREEN_METHOD_FILL: |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 2877 | center_on_output(shsurf->view, output); |
Alex Wu | 4539b08 | 2012-03-01 12:57:46 +0800 | [diff] [blame] | 2878 | break; |
| 2879 | default: |
| 2880 | break; |
| 2881 | } |
| 2882 | } |
| 2883 | |
Alex Wu | 4539b08 | 2012-03-01 12:57:46 +0800 | [diff] [blame] | 2884 | static void |
| 2885 | shell_map_fullscreen(struct shell_surface *shsurf) |
| 2886 | { |
Alex Wu | bd3354b | 2012-04-17 17:20:49 +0800 | [diff] [blame] | 2887 | shell_configure_fullscreen(shsurf); |
Alex Wu | 4539b08 | 2012-03-01 12:57:46 +0800 | [diff] [blame] | 2888 | } |
| 2889 | |
Kristian Høgsberg | 7a5c979 | 2011-06-18 06:12:54 -0400 | [diff] [blame] | 2890 | static void |
Tiago Vignatti | fb2adba | 2013-06-12 15:43:21 -0300 | [diff] [blame] | 2891 | set_xwayland(struct shell_surface *shsurf, int x, int y, uint32_t flags) |
| 2892 | { |
| 2893 | /* XXX: using the same fields for transient type */ |
Rafael Antognolli | 03b1659 | 2013-12-03 15:35:42 -0200 | [diff] [blame] | 2894 | surface_clear_next_states(shsurf); |
Tiago Vignatti | fb2adba | 2013-06-12 15:43:21 -0300 | [diff] [blame] | 2895 | shsurf->transient.x = x; |
| 2896 | shsurf->transient.y = y; |
| 2897 | shsurf->transient.flags = flags; |
Philip Withnall | dc4332f | 2013-11-25 18:01:38 +0000 | [diff] [blame] | 2898 | |
| 2899 | shell_surface_set_parent(shsurf, NULL); |
| 2900 | |
Kristian Høgsberg | c8f8dd8 | 2013-12-05 23:20:33 -0800 | [diff] [blame] | 2901 | shsurf->type = SHELL_SURFACE_XWAYLAND; |
Kristian Høgsberg | 8bc525c | 2014-01-01 22:34:49 -0800 | [diff] [blame] | 2902 | shsurf->state_changed = true; |
Tiago Vignatti | fb2adba | 2013-06-12 15:43:21 -0300 | [diff] [blame] | 2903 | } |
| 2904 | |
Kristian Høgsberg | 4779241 | 2014-05-04 13:47:06 -0700 | [diff] [blame] | 2905 | static void |
| 2906 | shell_interface_set_fullscreen(struct shell_surface *shsurf, |
| 2907 | uint32_t method, |
| 2908 | uint32_t framerate, |
| 2909 | struct weston_output *output) |
| 2910 | { |
| 2911 | surface_clear_next_states(shsurf); |
| 2912 | set_fullscreen(shsurf, method, framerate, output); |
| 2913 | |
| 2914 | shsurf->next_state.fullscreen = true; |
| 2915 | shsurf->state_changed = true; |
| 2916 | } |
| 2917 | |
Kristian Høgsberg | ae356ae | 2014-04-29 16:03:54 -0700 | [diff] [blame] | 2918 | static int |
| 2919 | shell_interface_move(struct shell_surface *shsurf, struct weston_seat *ws) |
| 2920 | { |
| 2921 | return surface_move(shsurf, ws, 1); |
| 2922 | } |
| 2923 | |
Kristian Høgsberg | 02bbabb | 2013-05-06 22:15:05 -0400 | [diff] [blame] | 2924 | static const struct weston_pointer_grab_interface popup_grab_interface; |
Giulio Camuffo | 5085a75 | 2013-03-25 21:42:45 +0100 | [diff] [blame] | 2925 | |
| 2926 | static void |
| 2927 | destroy_shell_seat(struct wl_listener *listener, void *data) |
| 2928 | { |
| 2929 | struct shell_seat *shseat = |
| 2930 | container_of(listener, |
| 2931 | struct shell_seat, seat_destroy_listener); |
| 2932 | struct shell_surface *shsurf, *prev = NULL; |
| 2933 | |
| 2934 | if (shseat->popup_grab.grab.interface == &popup_grab_interface) { |
Kristian Høgsberg | 02bbabb | 2013-05-06 22:15:05 -0400 | [diff] [blame] | 2935 | weston_pointer_end_grab(shseat->popup_grab.grab.pointer); |
Giulio Camuffo | 5085a75 | 2013-03-25 21:42:45 +0100 | [diff] [blame] | 2936 | shseat->popup_grab.client = NULL; |
| 2937 | |
| 2938 | wl_list_for_each(shsurf, &shseat->popup_grab.surfaces_list, popup.grab_link) { |
| 2939 | shsurf->popup.shseat = NULL; |
| 2940 | if (prev) { |
| 2941 | wl_list_init(&prev->popup.grab_link); |
| 2942 | } |
| 2943 | prev = shsurf; |
| 2944 | } |
| 2945 | wl_list_init(&prev->popup.grab_link); |
| 2946 | } |
| 2947 | |
| 2948 | wl_list_remove(&shseat->seat_destroy_listener.link); |
| 2949 | free(shseat); |
| 2950 | } |
| 2951 | |
Jason Ekstrand | 024177c | 2014-04-21 19:42:58 -0500 | [diff] [blame] | 2952 | static void |
| 2953 | shell_seat_caps_changed(struct wl_listener *listener, void *data) |
| 2954 | { |
| 2955 | struct shell_seat *seat; |
| 2956 | |
| 2957 | seat = container_of(listener, struct shell_seat, caps_changed_listener); |
| 2958 | |
| 2959 | if (seat->seat->keyboard && |
| 2960 | wl_list_empty(&seat->keyboard_focus_listener.link)) { |
| 2961 | wl_signal_add(&seat->seat->keyboard->focus_signal, |
| 2962 | &seat->keyboard_focus_listener); |
| 2963 | } else if (!seat->seat->keyboard) { |
| 2964 | wl_list_init(&seat->keyboard_focus_listener.link); |
| 2965 | } |
| 2966 | |
| 2967 | if (seat->seat->pointer && |
| 2968 | wl_list_empty(&seat->pointer_focus_listener.link)) { |
| 2969 | wl_signal_add(&seat->seat->pointer->focus_signal, |
| 2970 | &seat->pointer_focus_listener); |
| 2971 | } else if (!seat->seat->pointer) { |
| 2972 | wl_list_init(&seat->pointer_focus_listener.link); |
| 2973 | } |
| 2974 | } |
| 2975 | |
Giulio Camuffo | 5085a75 | 2013-03-25 21:42:45 +0100 | [diff] [blame] | 2976 | static struct shell_seat * |
| 2977 | create_shell_seat(struct weston_seat *seat) |
| 2978 | { |
| 2979 | struct shell_seat *shseat; |
| 2980 | |
| 2981 | shseat = calloc(1, sizeof *shseat); |
| 2982 | if (!shseat) { |
| 2983 | weston_log("no memory to allocate shell seat\n"); |
| 2984 | return NULL; |
| 2985 | } |
| 2986 | |
| 2987 | shseat->seat = seat; |
| 2988 | wl_list_init(&shseat->popup_grab.surfaces_list); |
| 2989 | |
| 2990 | shseat->seat_destroy_listener.notify = destroy_shell_seat; |
| 2991 | wl_signal_add(&seat->destroy_signal, |
| 2992 | &shseat->seat_destroy_listener); |
| 2993 | |
Jason Ekstrand | 024177c | 2014-04-21 19:42:58 -0500 | [diff] [blame] | 2994 | shseat->keyboard_focus_listener.notify = handle_keyboard_focus; |
| 2995 | wl_list_init(&shseat->keyboard_focus_listener.link); |
| 2996 | |
| 2997 | shseat->pointer_focus_listener.notify = handle_pointer_focus; |
| 2998 | wl_list_init(&shseat->pointer_focus_listener.link); |
| 2999 | |
| 3000 | shseat->caps_changed_listener.notify = shell_seat_caps_changed; |
| 3001 | wl_signal_add(&seat->updated_caps_signal, |
| 3002 | &shseat->caps_changed_listener); |
| 3003 | shell_seat_caps_changed(&shseat->caps_changed_listener, NULL); |
| 3004 | |
Giulio Camuffo | 5085a75 | 2013-03-25 21:42:45 +0100 | [diff] [blame] | 3005 | return shseat; |
| 3006 | } |
| 3007 | |
| 3008 | static struct shell_seat * |
| 3009 | get_shell_seat(struct weston_seat *seat) |
| 3010 | { |
| 3011 | struct wl_listener *listener; |
| 3012 | |
| 3013 | listener = wl_signal_get(&seat->destroy_signal, destroy_shell_seat); |
Jason Ekstrand | 024177c | 2014-04-21 19:42:58 -0500 | [diff] [blame] | 3014 | assert(listener != NULL); |
Giulio Camuffo | 5085a75 | 2013-03-25 21:42:45 +0100 | [diff] [blame] | 3015 | |
| 3016 | return container_of(listener, |
| 3017 | struct shell_seat, seat_destroy_listener); |
| 3018 | } |
| 3019 | |
Kristian Høgsberg | b810eb5 | 2013-02-12 20:07:05 -0500 | [diff] [blame] | 3020 | static void |
Kristian Høgsberg | 6848c25 | 2013-05-08 22:02:59 -0400 | [diff] [blame] | 3021 | popup_grab_focus(struct weston_pointer_grab *grab) |
Kristian Høgsberg | b3cca0a | 2012-01-04 22:19:14 -0500 | [diff] [blame] | 3022 | { |
Kristian Høgsberg | 02bbabb | 2013-05-06 22:15:05 -0400 | [diff] [blame] | 3023 | struct weston_pointer *pointer = grab->pointer; |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 3024 | struct weston_view *view; |
Giulio Camuffo | 5085a75 | 2013-03-25 21:42:45 +0100 | [diff] [blame] | 3025 | struct shell_seat *shseat = |
| 3026 | container_of(grab, struct shell_seat, popup_grab.grab); |
| 3027 | struct wl_client *client = shseat->popup_grab.client; |
Kristian Høgsberg | 6848c25 | 2013-05-08 22:02:59 -0400 | [diff] [blame] | 3028 | wl_fixed_t sx, sy; |
| 3029 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 3030 | view = weston_compositor_pick_view(pointer->seat->compositor, |
| 3031 | pointer->x, pointer->y, |
| 3032 | &sx, &sy); |
Kristian Høgsberg | b3cca0a | 2012-01-04 22:19:14 -0500 | [diff] [blame] | 3033 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 3034 | if (view && view->surface->resource && |
| 3035 | wl_resource_get_client(view->surface->resource) == client) { |
| 3036 | weston_pointer_set_focus(pointer, view, sx, sy); |
Kristian Høgsberg | b3cca0a | 2012-01-04 22:19:14 -0500 | [diff] [blame] | 3037 | } else { |
Kristian Høgsberg | 02bbabb | 2013-05-06 22:15:05 -0400 | [diff] [blame] | 3038 | weston_pointer_set_focus(pointer, NULL, |
| 3039 | wl_fixed_from_int(0), |
| 3040 | wl_fixed_from_int(0)); |
Kristian Høgsberg | b3cca0a | 2012-01-04 22:19:14 -0500 | [diff] [blame] | 3041 | } |
| 3042 | } |
| 3043 | |
| 3044 | static void |
Giulio Camuffo | 1959ab8 | 2013-11-14 23:42:52 +0100 | [diff] [blame] | 3045 | popup_grab_motion(struct weston_pointer_grab *grab, uint32_t time, |
| 3046 | wl_fixed_t x, wl_fixed_t y) |
Kristian Høgsberg | b3cca0a | 2012-01-04 22:19:14 -0500 | [diff] [blame] | 3047 | { |
Kristian Høgsberg | be6403e | 2013-05-08 21:03:21 -0400 | [diff] [blame] | 3048 | struct weston_pointer *pointer = grab->pointer; |
Neil Roberts | 96d790e | 2013-09-19 17:32:00 +0100 | [diff] [blame] | 3049 | struct wl_resource *resource; |
Kristian Høgsberg | be6403e | 2013-05-08 21:03:21 -0400 | [diff] [blame] | 3050 | wl_fixed_t sx, sy; |
Kristian Høgsberg | b3cca0a | 2012-01-04 22:19:14 -0500 | [diff] [blame] | 3051 | |
Jonas Ådahl | 61917c8 | 2014-08-11 22:44:02 +0200 | [diff] [blame] | 3052 | if (pointer->focus) { |
| 3053 | weston_view_from_global_fixed(pointer->focus, x, y, |
| 3054 | &pointer->sx, &pointer->sy); |
| 3055 | } |
| 3056 | |
Giulio Camuffo | 1959ab8 | 2013-11-14 23:42:52 +0100 | [diff] [blame] | 3057 | weston_pointer_move(pointer, x, y); |
| 3058 | |
Neil Roberts | 96d790e | 2013-09-19 17:32:00 +0100 | [diff] [blame] | 3059 | wl_resource_for_each(resource, &pointer->focus_resource_list) { |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 3060 | weston_view_from_global_fixed(pointer->focus, |
| 3061 | pointer->x, pointer->y, |
| 3062 | &sx, &sy); |
Neil Roberts | 96d790e | 2013-09-19 17:32:00 +0100 | [diff] [blame] | 3063 | wl_pointer_send_motion(resource, time, sx, sy); |
Kristian Høgsberg | be6403e | 2013-05-08 21:03:21 -0400 | [diff] [blame] | 3064 | } |
Kristian Høgsberg | b3cca0a | 2012-01-04 22:19:14 -0500 | [diff] [blame] | 3065 | } |
| 3066 | |
| 3067 | static void |
Kristian Høgsberg | 02bbabb | 2013-05-06 22:15:05 -0400 | [diff] [blame] | 3068 | popup_grab_button(struct weston_pointer_grab *grab, |
Daniel Stone | 4dbadb1 | 2012-05-30 16:31:51 +0100 | [diff] [blame] | 3069 | uint32_t time, uint32_t button, uint32_t state_w) |
Kristian Høgsberg | b3cca0a | 2012-01-04 22:19:14 -0500 | [diff] [blame] | 3070 | { |
| 3071 | struct wl_resource *resource; |
Giulio Camuffo | 5085a75 | 2013-03-25 21:42:45 +0100 | [diff] [blame] | 3072 | struct shell_seat *shseat = |
| 3073 | container_of(grab, struct shell_seat, popup_grab.grab); |
Rob Bradford | 880ebc7 | 2013-07-22 17:31:38 +0100 | [diff] [blame] | 3074 | struct wl_display *display = shseat->seat->compositor->wl_display; |
Daniel Stone | 4dbadb1 | 2012-05-30 16:31:51 +0100 | [diff] [blame] | 3075 | enum wl_pointer_button_state state = state_w; |
Kristian Høgsberg | eae5de7 | 2012-04-11 22:42:15 -0400 | [diff] [blame] | 3076 | uint32_t serial; |
Neil Roberts | 96d790e | 2013-09-19 17:32:00 +0100 | [diff] [blame] | 3077 | struct wl_list *resource_list; |
Kristian Høgsberg | b3cca0a | 2012-01-04 22:19:14 -0500 | [diff] [blame] | 3078 | |
Neil Roberts | 96d790e | 2013-09-19 17:32:00 +0100 | [diff] [blame] | 3079 | resource_list = &grab->pointer->focus_resource_list; |
| 3080 | if (!wl_list_empty(resource_list)) { |
Kristian Høgsberg | eae5de7 | 2012-04-11 22:42:15 -0400 | [diff] [blame] | 3081 | serial = wl_display_get_serial(display); |
Neil Roberts | 96d790e | 2013-09-19 17:32:00 +0100 | [diff] [blame] | 3082 | wl_resource_for_each(resource, resource_list) { |
| 3083 | wl_pointer_send_button(resource, serial, |
| 3084 | time, button, state); |
| 3085 | } |
Daniel Stone | 4dbadb1 | 2012-05-30 16:31:51 +0100 | [diff] [blame] | 3086 | } else if (state == WL_POINTER_BUTTON_STATE_RELEASED && |
Giulio Camuffo | 5085a75 | 2013-03-25 21:42:45 +0100 | [diff] [blame] | 3087 | (shseat->popup_grab.initial_up || |
Kristian Høgsberg | e314875 | 2013-05-06 23:19:49 -0400 | [diff] [blame] | 3088 | time - shseat->seat->pointer->grab_time > 500)) { |
Kristian Høgsberg | 57e0907 | 2012-10-30 14:07:27 -0400 | [diff] [blame] | 3089 | popup_grab_end(grab->pointer); |
Kristian Høgsberg | b3cca0a | 2012-01-04 22:19:14 -0500 | [diff] [blame] | 3090 | } |
| 3091 | |
Daniel Stone | 4dbadb1 | 2012-05-30 16:31:51 +0100 | [diff] [blame] | 3092 | if (state == WL_POINTER_BUTTON_STATE_RELEASED) |
Giulio Camuffo | 5085a75 | 2013-03-25 21:42:45 +0100 | [diff] [blame] | 3093 | shseat->popup_grab.initial_up = 1; |
Kristian Høgsberg | b3cca0a | 2012-01-04 22:19:14 -0500 | [diff] [blame] | 3094 | } |
| 3095 | |
Jonas Ådahl | 1ea343e | 2013-10-25 23:18:05 +0200 | [diff] [blame] | 3096 | static void |
| 3097 | popup_grab_cancel(struct weston_pointer_grab *grab) |
| 3098 | { |
| 3099 | popup_grab_end(grab->pointer); |
| 3100 | } |
| 3101 | |
Kristian Høgsberg | 02bbabb | 2013-05-06 22:15:05 -0400 | [diff] [blame] | 3102 | static const struct weston_pointer_grab_interface popup_grab_interface = { |
Kristian Høgsberg | b3cca0a | 2012-01-04 22:19:14 -0500 | [diff] [blame] | 3103 | popup_grab_focus, |
| 3104 | popup_grab_motion, |
| 3105 | popup_grab_button, |
Jonas Ådahl | 1ea343e | 2013-10-25 23:18:05 +0200 | [diff] [blame] | 3106 | popup_grab_cancel, |
Kristian Høgsberg | b3cca0a | 2012-01-04 22:19:14 -0500 | [diff] [blame] | 3107 | }; |
| 3108 | |
| 3109 | static void |
Rafael Antognolli | e2a3455 | 2013-12-03 15:35:45 -0200 | [diff] [blame] | 3110 | shell_surface_send_popup_done(struct shell_surface *shsurf) |
| 3111 | { |
| 3112 | if (shell_surface_is_wl_shell_surface(shsurf)) |
| 3113 | wl_shell_surface_send_popup_done(shsurf->resource); |
| 3114 | else if (shell_surface_is_xdg_popup(shsurf)) |
| 3115 | xdg_popup_send_popup_done(shsurf->resource, |
| 3116 | shsurf->popup.serial); |
| 3117 | } |
| 3118 | |
| 3119 | static void |
Kristian Høgsberg | 02bbabb | 2013-05-06 22:15:05 -0400 | [diff] [blame] | 3120 | popup_grab_end(struct weston_pointer *pointer) |
Kristian Høgsberg | 57e0907 | 2012-10-30 14:07:27 -0400 | [diff] [blame] | 3121 | { |
Kristian Høgsberg | 02bbabb | 2013-05-06 22:15:05 -0400 | [diff] [blame] | 3122 | struct weston_pointer_grab *grab = pointer->grab; |
Giulio Camuffo | 5085a75 | 2013-03-25 21:42:45 +0100 | [diff] [blame] | 3123 | struct shell_seat *shseat = |
| 3124 | container_of(grab, struct shell_seat, popup_grab.grab); |
| 3125 | struct shell_surface *shsurf; |
| 3126 | struct shell_surface *prev = NULL; |
Kristian Høgsberg | 57e0907 | 2012-10-30 14:07:27 -0400 | [diff] [blame] | 3127 | |
| 3128 | if (pointer->grab->interface == &popup_grab_interface) { |
Kristian Høgsberg | 02bbabb | 2013-05-06 22:15:05 -0400 | [diff] [blame] | 3129 | weston_pointer_end_grab(grab->pointer); |
Giulio Camuffo | 5085a75 | 2013-03-25 21:42:45 +0100 | [diff] [blame] | 3130 | shseat->popup_grab.client = NULL; |
Philipp Brüschweiler | 63e7be6 | 2013-04-15 21:09:54 +0200 | [diff] [blame] | 3131 | shseat->popup_grab.grab.interface = NULL; |
| 3132 | assert(!wl_list_empty(&shseat->popup_grab.surfaces_list)); |
Giulio Camuffo | 5085a75 | 2013-03-25 21:42:45 +0100 | [diff] [blame] | 3133 | /* Send the popup_done event to all the popups open */ |
| 3134 | wl_list_for_each(shsurf, &shseat->popup_grab.surfaces_list, popup.grab_link) { |
Rafael Antognolli | e2a3455 | 2013-12-03 15:35:45 -0200 | [diff] [blame] | 3135 | shell_surface_send_popup_done(shsurf); |
Giulio Camuffo | 5085a75 | 2013-03-25 21:42:45 +0100 | [diff] [blame] | 3136 | shsurf->popup.shseat = NULL; |
| 3137 | if (prev) { |
| 3138 | wl_list_init(&prev->popup.grab_link); |
| 3139 | } |
| 3140 | prev = shsurf; |
| 3141 | } |
| 3142 | wl_list_init(&prev->popup.grab_link); |
| 3143 | wl_list_init(&shseat->popup_grab.surfaces_list); |
| 3144 | } |
| 3145 | } |
| 3146 | |
| 3147 | static void |
| 3148 | add_popup_grab(struct shell_surface *shsurf, struct shell_seat *shseat) |
| 3149 | { |
Kristian Høgsberg | e314875 | 2013-05-06 23:19:49 -0400 | [diff] [blame] | 3150 | struct weston_seat *seat = shseat->seat; |
Giulio Camuffo | 5085a75 | 2013-03-25 21:42:45 +0100 | [diff] [blame] | 3151 | |
| 3152 | if (wl_list_empty(&shseat->popup_grab.surfaces_list)) { |
Jason Ekstrand | 651f00e | 2013-06-14 10:07:54 -0500 | [diff] [blame] | 3153 | shseat->popup_grab.client = wl_resource_get_client(shsurf->resource); |
Giulio Camuffo | 5085a75 | 2013-03-25 21:42:45 +0100 | [diff] [blame] | 3154 | shseat->popup_grab.grab.interface = &popup_grab_interface; |
Giulio Camuffo | 1b4b61a | 2013-03-27 18:05:26 +0100 | [diff] [blame] | 3155 | /* We must make sure here that this popup was opened after |
| 3156 | * a mouse press, and not just by moving around with other |
| 3157 | * popups already open. */ |
Kristian Høgsberg | e314875 | 2013-05-06 23:19:49 -0400 | [diff] [blame] | 3158 | if (shseat->seat->pointer->button_count > 0) |
Giulio Camuffo | 1b4b61a | 2013-03-27 18:05:26 +0100 | [diff] [blame] | 3159 | shseat->popup_grab.initial_up = 0; |
Giulio Camuffo | 5085a75 | 2013-03-25 21:42:45 +0100 | [diff] [blame] | 3160 | |
Rob Bradford | dfe3105 | 2013-06-26 19:49:11 +0100 | [diff] [blame] | 3161 | wl_list_insert(&shseat->popup_grab.surfaces_list, &shsurf->popup.grab_link); |
Kristian Høgsberg | 02bbabb | 2013-05-06 22:15:05 -0400 | [diff] [blame] | 3162 | weston_pointer_start_grab(seat->pointer, &shseat->popup_grab.grab); |
Rob Bradford | dfe3105 | 2013-06-26 19:49:11 +0100 | [diff] [blame] | 3163 | } else { |
| 3164 | wl_list_insert(&shseat->popup_grab.surfaces_list, &shsurf->popup.grab_link); |
Giulio Camuffo | 5085a75 | 2013-03-25 21:42:45 +0100 | [diff] [blame] | 3165 | } |
Giulio Camuffo | 5085a75 | 2013-03-25 21:42:45 +0100 | [diff] [blame] | 3166 | } |
| 3167 | |
| 3168 | static void |
| 3169 | remove_popup_grab(struct shell_surface *shsurf) |
| 3170 | { |
| 3171 | struct shell_seat *shseat = shsurf->popup.shseat; |
| 3172 | |
| 3173 | wl_list_remove(&shsurf->popup.grab_link); |
| 3174 | wl_list_init(&shsurf->popup.grab_link); |
| 3175 | if (wl_list_empty(&shseat->popup_grab.surfaces_list)) { |
Kristian Høgsberg | 02bbabb | 2013-05-06 22:15:05 -0400 | [diff] [blame] | 3176 | weston_pointer_end_grab(shseat->popup_grab.grab.pointer); |
Philipp Brüschweiler | 63e7be6 | 2013-04-15 21:09:54 +0200 | [diff] [blame] | 3177 | shseat->popup_grab.grab.interface = NULL; |
Kristian Høgsberg | 57e0907 | 2012-10-30 14:07:27 -0400 | [diff] [blame] | 3178 | } |
| 3179 | } |
| 3180 | |
| 3181 | static void |
Kristian Høgsberg | 3730f36 | 2012-04-13 12:40:07 -0400 | [diff] [blame] | 3182 | shell_map_popup(struct shell_surface *shsurf) |
Kristian Høgsberg | b3cca0a | 2012-01-04 22:19:14 -0500 | [diff] [blame] | 3183 | { |
Giulio Camuffo | 5085a75 | 2013-03-25 21:42:45 +0100 | [diff] [blame] | 3184 | struct shell_seat *shseat = shsurf->popup.shseat; |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 3185 | struct weston_view *parent_view = get_default_view(shsurf->parent); |
Kristian Høgsberg | b3cca0a | 2012-01-04 22:19:14 -0500 | [diff] [blame] | 3186 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 3187 | shsurf->surface->output = parent_view->output; |
| 3188 | shsurf->view->output = parent_view->output; |
Kristian Høgsberg | b3cca0a | 2012-01-04 22:19:14 -0500 | [diff] [blame] | 3189 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 3190 | weston_view_set_transform_parent(shsurf->view, parent_view); |
| 3191 | weston_view_set_position(shsurf->view, shsurf->popup.x, shsurf->popup.y); |
| 3192 | weston_view_update_transform(shsurf->view); |
Kristian Høgsberg | b3cca0a | 2012-01-04 22:19:14 -0500 | [diff] [blame] | 3193 | |
Jonny Lamb | e84ab4e | 2014-08-06 11:50:12 +0200 | [diff] [blame] | 3194 | if (shseat->seat->pointer && |
| 3195 | shseat->seat->pointer->grab_serial == shsurf->popup.serial) { |
Giulio Camuffo | 5085a75 | 2013-03-25 21:42:45 +0100 | [diff] [blame] | 3196 | add_popup_grab(shsurf, shseat); |
Kristian Høgsberg | 3730f36 | 2012-04-13 12:40:07 -0400 | [diff] [blame] | 3197 | } else { |
Rafael Antognolli | e2a3455 | 2013-12-03 15:35:45 -0200 | [diff] [blame] | 3198 | shell_surface_send_popup_done(shsurf); |
Giulio Camuffo | 5085a75 | 2013-03-25 21:42:45 +0100 | [diff] [blame] | 3199 | shseat->popup_grab.client = NULL; |
Kristian Høgsberg | 3730f36 | 2012-04-13 12:40:07 -0400 | [diff] [blame] | 3200 | } |
Kristian Høgsberg | b3cca0a | 2012-01-04 22:19:14 -0500 | [diff] [blame] | 3201 | } |
| 3202 | |
Pekka Paalanen | 9d1613e | 2011-11-25 12:09:16 +0200 | [diff] [blame] | 3203 | static const struct wl_shell_surface_interface shell_surface_implementation = { |
Scott Moreau | ff1db4a | 2012-04-17 19:06:18 -0600 | [diff] [blame] | 3204 | shell_surface_pong, |
Pekka Paalanen | 9d1613e | 2011-11-25 12:09:16 +0200 | [diff] [blame] | 3205 | shell_surface_move, |
| 3206 | shell_surface_resize, |
| 3207 | shell_surface_set_toplevel, |
| 3208 | shell_surface_set_transient, |
Kristian Høgsberg | b3cca0a | 2012-01-04 22:19:14 -0500 | [diff] [blame] | 3209 | shell_surface_set_fullscreen, |
Juan Zhao | 96879df | 2012-02-07 08:45:41 +0800 | [diff] [blame] | 3210 | shell_surface_set_popup, |
Kristian Høgsberg | e7afd91 | 2012-05-02 09:47:44 -0400 | [diff] [blame] | 3211 | shell_surface_set_maximized, |
| 3212 | shell_surface_set_title, |
| 3213 | shell_surface_set_class |
Pekka Paalanen | 9d1613e | 2011-11-25 12:09:16 +0200 | [diff] [blame] | 3214 | }; |
| 3215 | |
| 3216 | static void |
Tiago Vignatti | bc052c9 | 2012-04-19 16:18:18 +0300 | [diff] [blame] | 3217 | destroy_shell_surface(struct shell_surface *shsurf) |
Pekka Paalanen | 9d1613e | 2011-11-25 12:09:16 +0200 | [diff] [blame] | 3218 | { |
Kristian Høgsberg | 9046d24 | 2014-01-10 00:25:30 -0800 | [diff] [blame] | 3219 | struct shell_surface *child, *next; |
| 3220 | |
Jason Ekstrand | 651f00e | 2013-06-14 10:07:54 -0500 | [diff] [blame] | 3221 | wl_signal_emit(&shsurf->destroy_signal, shsurf); |
| 3222 | |
Giulio Camuffo | 5085a75 | 2013-03-25 21:42:45 +0100 | [diff] [blame] | 3223 | if (!wl_list_empty(&shsurf->popup.grab_link)) { |
| 3224 | remove_popup_grab(shsurf); |
| 3225 | } |
Kristian Høgsberg | b3cca0a | 2012-01-04 22:19:14 -0500 | [diff] [blame] | 3226 | |
Alex Wu | bd3354b | 2012-04-17 17:20:49 +0800 | [diff] [blame] | 3227 | if (shsurf->fullscreen.type == WL_SHELL_SURFACE_FULLSCREEN_METHOD_DRIVER && |
Alexander Larsson | f82b6ca | 2013-05-28 16:23:39 +0200 | [diff] [blame] | 3228 | shell_surface_is_top_fullscreen(shsurf)) |
| 3229 | restore_output_mode (shsurf->fullscreen_output); |
Pekka Paalanen | 9d1613e | 2011-11-25 12:09:16 +0200 | [diff] [blame] | 3230 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 3231 | if (shsurf->fullscreen.black_view) |
| 3232 | weston_surface_destroy(shsurf->fullscreen.black_view->surface); |
Alex Wu | aa08e2d | 2012-03-05 11:01:40 +0800 | [diff] [blame] | 3233 | |
Alex Wu | bd3354b | 2012-04-17 17:20:49 +0800 | [diff] [blame] | 3234 | /* As destroy_resource() use wl_list_for_each_safe(), |
| 3235 | * we can always remove the listener. |
| 3236 | */ |
| 3237 | wl_list_remove(&shsurf->surface_destroy_listener.link); |
| 3238 | shsurf->surface->configure = NULL; |
Scott Moreau | 976a050 | 2013-03-07 10:15:17 -0700 | [diff] [blame] | 3239 | free(shsurf->title); |
Alex Wu | bd3354b | 2012-04-17 17:20:49 +0800 | [diff] [blame] | 3240 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 3241 | weston_view_destroy(shsurf->view); |
| 3242 | |
Philip Withnall | 648a4dd | 2013-11-25 18:01:44 +0000 | [diff] [blame] | 3243 | wl_list_remove(&shsurf->children_link); |
Emilio Pozuelo Monfort | adaa20c | 2014-01-28 13:54:16 +0100 | [diff] [blame] | 3244 | wl_list_for_each_safe(child, next, &shsurf->children_list, children_link) |
| 3245 | shell_surface_set_parent(child, NULL); |
Philip Withnall | 648a4dd | 2013-11-25 18:01:44 +0000 | [diff] [blame] | 3246 | |
Pekka Paalanen | 9d1613e | 2011-11-25 12:09:16 +0200 | [diff] [blame] | 3247 | wl_list_remove(&shsurf->link); |
| 3248 | free(shsurf); |
| 3249 | } |
| 3250 | |
| 3251 | static void |
Tiago Vignatti | bc052c9 | 2012-04-19 16:18:18 +0300 | [diff] [blame] | 3252 | shell_destroy_shell_surface(struct wl_resource *resource) |
| 3253 | { |
Jason Ekstrand | 651f00e | 2013-06-14 10:07:54 -0500 | [diff] [blame] | 3254 | struct shell_surface *shsurf = wl_resource_get_user_data(resource); |
Tiago Vignatti | bc052c9 | 2012-04-19 16:18:18 +0300 | [diff] [blame] | 3255 | |
Bryan Cain | a46b946 | 2014-04-04 17:41:24 -0500 | [diff] [blame] | 3256 | if (!wl_list_empty(&shsurf->popup.grab_link)) |
| 3257 | remove_popup_grab(shsurf); |
Kristian Høgsberg | 160fe75 | 2014-03-11 10:19:10 -0700 | [diff] [blame] | 3258 | shsurf->resource = NULL; |
Tiago Vignatti | bc052c9 | 2012-04-19 16:18:18 +0300 | [diff] [blame] | 3259 | } |
| 3260 | |
| 3261 | static void |
Kristian Høgsberg | 27e3052 | 2012-04-11 23:18:23 -0400 | [diff] [blame] | 3262 | shell_handle_surface_destroy(struct wl_listener *listener, void *data) |
Pekka Paalanen | 9d1613e | 2011-11-25 12:09:16 +0200 | [diff] [blame] | 3263 | { |
| 3264 | struct shell_surface *shsurf = container_of(listener, |
| 3265 | struct shell_surface, |
| 3266 | surface_destroy_listener); |
| 3267 | |
Jason Ekstrand | 651f00e | 2013-06-14 10:07:54 -0500 | [diff] [blame] | 3268 | if (shsurf->resource) |
| 3269 | wl_resource_destroy(shsurf->resource); |
Ander Conselvan de Oliveira | 15f9a26 | 2014-04-29 17:54:02 +0300 | [diff] [blame] | 3270 | |
| 3271 | destroy_shell_surface(shsurf); |
Pekka Paalanen | 9d1613e | 2011-11-25 12:09:16 +0200 | [diff] [blame] | 3272 | } |
| 3273 | |
Kristian Høgsberg | d813445 | 2012-06-21 12:49:02 -0400 | [diff] [blame] | 3274 | static void |
Kristian Høgsberg | 160fe75 | 2014-03-11 10:19:10 -0700 | [diff] [blame] | 3275 | fade_out_done(struct weston_view_animation *animation, void *data) |
| 3276 | { |
| 3277 | struct shell_surface *shsurf = data; |
| 3278 | |
| 3279 | weston_surface_destroy(shsurf->surface); |
| 3280 | } |
| 3281 | |
| 3282 | static void |
| 3283 | handle_resource_destroy(struct wl_listener *listener, void *data) |
| 3284 | { |
| 3285 | struct shell_surface *shsurf = |
| 3286 | container_of(listener, struct shell_surface, |
| 3287 | resource_destroy_listener); |
| 3288 | |
Ander Conselvan de Oliveira | 15f9a26 | 2014-04-29 17:54:02 +0300 | [diff] [blame] | 3289 | if (!weston_surface_is_mapped(shsurf->surface)) |
| 3290 | return; |
| 3291 | |
Kristian Høgsberg | 160fe75 | 2014-03-11 10:19:10 -0700 | [diff] [blame] | 3292 | shsurf->surface->ref_count++; |
| 3293 | |
| 3294 | pixman_region32_fini(&shsurf->surface->pending.input); |
| 3295 | pixman_region32_init(&shsurf->surface->pending.input); |
| 3296 | pixman_region32_fini(&shsurf->surface->input); |
| 3297 | pixman_region32_init(&shsurf->surface->input); |
Jonny Lamb | f322f8e | 2014-08-12 15:13:30 +0200 | [diff] [blame] | 3298 | if (shsurf->shell->win_close_animation_type == ANIMATION_FADE) { |
| 3299 | weston_fade_run(shsurf->view, 1.0, 0.0, 300.0, |
| 3300 | fade_out_done, shsurf); |
| 3301 | } else { |
| 3302 | weston_surface_destroy(shsurf->surface); |
| 3303 | } |
Kristian Høgsberg | 160fe75 | 2014-03-11 10:19:10 -0700 | [diff] [blame] | 3304 | } |
| 3305 | |
| 3306 | static void |
Jason Ekstrand | 918f2dd | 2013-12-02 21:01:53 -0600 | [diff] [blame] | 3307 | shell_surface_configure(struct weston_surface *, int32_t, int32_t); |
Kristian Høgsberg | d813445 | 2012-06-21 12:49:02 -0400 | [diff] [blame] | 3308 | |
Kristian Høgsberg | 1ef2313 | 2013-12-04 00:20:01 -0800 | [diff] [blame] | 3309 | struct shell_surface * |
Kristian Høgsberg | 8334bc1 | 2012-01-03 10:29:47 -0500 | [diff] [blame] | 3310 | get_shell_surface(struct weston_surface *surface) |
Pekka Paalanen | ec2b32f | 2011-11-28 15:12:34 +0200 | [diff] [blame] | 3311 | { |
Kristian Høgsberg | d813445 | 2012-06-21 12:49:02 -0400 | [diff] [blame] | 3312 | if (surface->configure == shell_surface_configure) |
Giulio Camuffo | 7fe01b1 | 2013-03-28 18:02:42 +0100 | [diff] [blame] | 3313 | return surface->configure_private; |
Kristian Høgsberg | d813445 | 2012-06-21 12:49:02 -0400 | [diff] [blame] | 3314 | else |
| 3315 | return NULL; |
Pekka Paalanen | ec2b32f | 2011-11-28 15:12:34 +0200 | [diff] [blame] | 3316 | } |
| 3317 | |
Rafael Antognolli | e2a3455 | 2013-12-03 15:35:45 -0200 | [diff] [blame] | 3318 | static struct shell_surface * |
Jason Ekstrand | 9e9512f | 2014-04-16 21:12:10 -0500 | [diff] [blame] | 3319 | create_common_surface(struct shell_client *owner, void *shell, |
| 3320 | struct weston_surface *surface, |
Rafael Antognolli | e2a3455 | 2013-12-03 15:35:45 -0200 | [diff] [blame] | 3321 | const struct weston_shell_client *client) |
Pekka Paalanen | 9d1613e | 2011-11-25 12:09:16 +0200 | [diff] [blame] | 3322 | { |
Pekka Paalanen | 9d1613e | 2011-11-25 12:09:16 +0200 | [diff] [blame] | 3323 | struct shell_surface *shsurf; |
| 3324 | |
Ander Conselvan de Oliveira | 093bfa3 | 2012-03-27 17:36:41 +0300 | [diff] [blame] | 3325 | if (surface->configure) { |
Martin Minarik | 6d11836 | 2012-06-07 18:01:59 +0200 | [diff] [blame] | 3326 | weston_log("surface->configure already set\n"); |
Kristian Høgsberg | 45ba869 | 2012-05-21 14:27:33 -0400 | [diff] [blame] | 3327 | return NULL; |
Ander Conselvan de Oliveira | 093bfa3 | 2012-03-27 17:36:41 +0300 | [diff] [blame] | 3328 | } |
| 3329 | |
Pekka Paalanen | 9d1613e | 2011-11-25 12:09:16 +0200 | [diff] [blame] | 3330 | shsurf = calloc(1, sizeof *shsurf); |
| 3331 | if (!shsurf) { |
Martin Minarik | 6d11836 | 2012-06-07 18:01:59 +0200 | [diff] [blame] | 3332 | weston_log("no memory to allocate shell surface\n"); |
Kristian Høgsberg | 45ba869 | 2012-05-21 14:27:33 -0400 | [diff] [blame] | 3333 | return NULL; |
Pekka Paalanen | 9d1613e | 2011-11-25 12:09:16 +0200 | [diff] [blame] | 3334 | } |
| 3335 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 3336 | shsurf->view = weston_view_create(surface); |
| 3337 | if (!shsurf->view) { |
| 3338 | weston_log("no memory to allocate shell surface\n"); |
| 3339 | free(shsurf); |
| 3340 | return NULL; |
| 3341 | } |
| 3342 | |
Ander Conselvan de Oliveira | 093bfa3 | 2012-03-27 17:36:41 +0300 | [diff] [blame] | 3343 | surface->configure = shell_surface_configure; |
Giulio Camuffo | 7fe01b1 | 2013-03-28 18:02:42 +0100 | [diff] [blame] | 3344 | surface->configure_private = shsurf; |
Ander Conselvan de Oliveira | 093bfa3 | 2012-03-27 17:36:41 +0300 | [diff] [blame] | 3345 | |
Kristian Høgsberg | 160fe75 | 2014-03-11 10:19:10 -0700 | [diff] [blame] | 3346 | shsurf->resource_destroy_listener.notify = handle_resource_destroy; |
| 3347 | wl_resource_add_destroy_listener(surface->resource, |
| 3348 | &shsurf->resource_destroy_listener); |
Jason Ekstrand | 9e9512f | 2014-04-16 21:12:10 -0500 | [diff] [blame] | 3349 | shsurf->owner = owner; |
Kristian Høgsberg | 160fe75 | 2014-03-11 10:19:10 -0700 | [diff] [blame] | 3350 | |
Tiago Vignatti | bc052c9 | 2012-04-19 16:18:18 +0300 | [diff] [blame] | 3351 | shsurf->shell = (struct desktop_shell *) shell; |
Scott Moreau | ff1db4a | 2012-04-17 19:06:18 -0600 | [diff] [blame] | 3352 | shsurf->unresponsive = 0; |
Alex Wu | 4539b08 | 2012-03-01 12:57:46 +0800 | [diff] [blame] | 3353 | shsurf->saved_position_valid = false; |
Rafael Antognolli | 3c4e3f7 | 2013-12-03 15:35:46 -0200 | [diff] [blame] | 3354 | shsurf->saved_size_valid = false; |
Alex Wu | 7bcb8bd | 2012-04-27 09:07:24 +0800 | [diff] [blame] | 3355 | shsurf->saved_rotation_valid = false; |
Pekka Paalanen | 9d1613e | 2011-11-25 12:09:16 +0200 | [diff] [blame] | 3356 | shsurf->surface = surface; |
Alex Wu | 4539b08 | 2012-03-01 12:57:46 +0800 | [diff] [blame] | 3357 | shsurf->fullscreen.type = WL_SHELL_SURFACE_FULLSCREEN_METHOD_DEFAULT; |
| 3358 | shsurf->fullscreen.framerate = 0; |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 3359 | shsurf->fullscreen.black_view = NULL; |
Alex Wu | 4539b08 | 2012-03-01 12:57:46 +0800 | [diff] [blame] | 3360 | wl_list_init(&shsurf->fullscreen.transform.link); |
| 3361 | |
Jasper St. Pierre | 9aa8ce6 | 2014-04-11 16:18:54 -0700 | [diff] [blame] | 3362 | shsurf->output = get_default_output(shsurf->shell->compositor); |
| 3363 | |
Jason Ekstrand | 651f00e | 2013-06-14 10:07:54 -0500 | [diff] [blame] | 3364 | wl_signal_init(&shsurf->destroy_signal); |
Kristian Høgsberg | 27e3052 | 2012-04-11 23:18:23 -0400 | [diff] [blame] | 3365 | shsurf->surface_destroy_listener.notify = shell_handle_surface_destroy; |
Jason Ekstrand | 26ed73c | 2013-06-06 22:34:41 -0500 | [diff] [blame] | 3366 | wl_signal_add(&surface->destroy_signal, |
Kristian Høgsberg | 27e3052 | 2012-04-11 23:18:23 -0400 | [diff] [blame] | 3367 | &shsurf->surface_destroy_listener); |
Pekka Paalanen | 9d1613e | 2011-11-25 12:09:16 +0200 | [diff] [blame] | 3368 | |
| 3369 | /* init link so its safe to always remove it in destroy_shell_surface */ |
| 3370 | wl_list_init(&shsurf->link); |
Giulio Camuffo | 5085a75 | 2013-03-25 21:42:45 +0100 | [diff] [blame] | 3371 | wl_list_init(&shsurf->popup.grab_link); |
Pekka Paalanen | 9d1613e | 2011-11-25 12:09:16 +0200 | [diff] [blame] | 3372 | |
Pekka Paalanen | 460099f | 2012-01-20 16:48:25 +0200 | [diff] [blame] | 3373 | /* empty when not in use */ |
| 3374 | wl_list_init(&shsurf->rotation.transform.link); |
Kristian Høgsberg | 765e27b | 2012-01-27 13:36:13 -0500 | [diff] [blame] | 3375 | weston_matrix_init(&shsurf->rotation.rotation); |
Pekka Paalanen | 460099f | 2012-01-20 16:48:25 +0200 | [diff] [blame] | 3376 | |
Jonas Ådahl | 62fcd04 | 2012-06-13 00:01:23 +0200 | [diff] [blame] | 3377 | wl_list_init(&shsurf->workspace_transform.link); |
| 3378 | |
Philip Withnall | 648a4dd | 2013-11-25 18:01:44 +0000 | [diff] [blame] | 3379 | wl_list_init(&shsurf->children_link); |
| 3380 | wl_list_init(&shsurf->children_list); |
| 3381 | shsurf->parent = NULL; |
| 3382 | |
Pekka Paalanen | 9826223 | 2011-12-01 10:42:22 +0200 | [diff] [blame] | 3383 | shsurf->type = SHELL_SURFACE_NONE; |
Pekka Paalanen | 9d1613e | 2011-11-25 12:09:16 +0200 | [diff] [blame] | 3384 | |
Kristian Høgsberg | a61ca06 | 2012-05-22 16:05:52 -0400 | [diff] [blame] | 3385 | shsurf->client = client; |
| 3386 | |
Kristian Høgsberg | 45ba869 | 2012-05-21 14:27:33 -0400 | [diff] [blame] | 3387 | return shsurf; |
Tiago Vignatti | bc052c9 | 2012-04-19 16:18:18 +0300 | [diff] [blame] | 3388 | } |
| 3389 | |
Rafael Antognolli | e2a3455 | 2013-12-03 15:35:45 -0200 | [diff] [blame] | 3390 | static struct shell_surface * |
| 3391 | create_shell_surface(void *shell, struct weston_surface *surface, |
| 3392 | const struct weston_shell_client *client) |
| 3393 | { |
Jason Ekstrand | 9e9512f | 2014-04-16 21:12:10 -0500 | [diff] [blame] | 3394 | return create_common_surface(NULL, shell, surface, client); |
Rafael Antognolli | e2a3455 | 2013-12-03 15:35:45 -0200 | [diff] [blame] | 3395 | } |
| 3396 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 3397 | static struct weston_view * |
| 3398 | get_primary_view(void *shell, struct shell_surface *shsurf) |
| 3399 | { |
| 3400 | return shsurf->view; |
| 3401 | } |
| 3402 | |
Tiago Vignatti | bc052c9 | 2012-04-19 16:18:18 +0300 | [diff] [blame] | 3403 | static void |
| 3404 | shell_get_shell_surface(struct wl_client *client, |
| 3405 | struct wl_resource *resource, |
| 3406 | uint32_t id, |
| 3407 | struct wl_resource *surface_resource) |
| 3408 | { |
Jason Ekstrand | 0f2ef7e | 2013-06-14 10:07:53 -0500 | [diff] [blame] | 3409 | struct weston_surface *surface = |
| 3410 | wl_resource_get_user_data(surface_resource); |
Jason Ekstrand | 9e9512f | 2014-04-16 21:12:10 -0500 | [diff] [blame] | 3411 | struct shell_client *sc = wl_resource_get_user_data(resource); |
| 3412 | struct desktop_shell *shell = sc->shell; |
Tiago Vignatti | bc052c9 | 2012-04-19 16:18:18 +0300 | [diff] [blame] | 3413 | struct shell_surface *shsurf; |
| 3414 | |
| 3415 | if (get_shell_surface(surface)) { |
| 3416 | wl_resource_post_error(surface_resource, |
Kristian Høgsberg | 9540ea6 | 2012-05-21 14:28:57 -0400 | [diff] [blame] | 3417 | WL_DISPLAY_ERROR_INVALID_OBJECT, |
| 3418 | "desktop_shell::get_shell_surface already requested"); |
Tiago Vignatti | bc052c9 | 2012-04-19 16:18:18 +0300 | [diff] [blame] | 3419 | return; |
| 3420 | } |
| 3421 | |
Jason Ekstrand | 9e9512f | 2014-04-16 21:12:10 -0500 | [diff] [blame] | 3422 | shsurf = create_common_surface(sc, shell, surface, &shell_client); |
Kristian Høgsberg | 9540ea6 | 2012-05-21 14:28:57 -0400 | [diff] [blame] | 3423 | if (!shsurf) { |
| 3424 | wl_resource_post_error(surface_resource, |
| 3425 | WL_DISPLAY_ERROR_INVALID_OBJECT, |
| 3426 | "surface->configure already set"); |
| 3427 | return; |
| 3428 | } |
Tiago Vignatti | bc052c9 | 2012-04-19 16:18:18 +0300 | [diff] [blame] | 3429 | |
Jason Ekstrand | a85118c | 2013-06-27 20:17:02 -0500 | [diff] [blame] | 3430 | shsurf->resource = |
| 3431 | wl_resource_create(client, |
| 3432 | &wl_shell_surface_interface, 1, id); |
| 3433 | wl_resource_set_implementation(shsurf->resource, |
| 3434 | &shell_surface_implementation, |
| 3435 | shsurf, shell_destroy_shell_surface); |
Pekka Paalanen | 9d1613e | 2011-11-25 12:09:16 +0200 | [diff] [blame] | 3436 | } |
| 3437 | |
Rafael Antognolli | e2a3455 | 2013-12-03 15:35:45 -0200 | [diff] [blame] | 3438 | static bool |
| 3439 | shell_surface_is_wl_shell_surface(struct shell_surface *shsurf) |
| 3440 | { |
Kristian Høgsberg | 0b7d995 | 2014-02-03 15:50:38 -0800 | [diff] [blame] | 3441 | /* A shell surface without a resource is created from xwayland |
| 3442 | * and is considered a wl_shell surface for now. */ |
| 3443 | |
| 3444 | return shsurf->resource == NULL || |
| 3445 | wl_resource_instance_of(shsurf->resource, |
| 3446 | &wl_shell_surface_interface, |
| 3447 | &shell_surface_implementation); |
Rafael Antognolli | e2a3455 | 2013-12-03 15:35:45 -0200 | [diff] [blame] | 3448 | } |
| 3449 | |
Pekka Paalanen | 9d1613e | 2011-11-25 12:09:16 +0200 | [diff] [blame] | 3450 | static const struct wl_shell_interface shell_implementation = { |
Pekka Paalanen | 4622967 | 2011-11-29 15:49:31 +0200 | [diff] [blame] | 3451 | shell_get_shell_surface |
Kristian Høgsberg | 4cca349 | 2011-01-18 07:53:49 -0500 | [diff] [blame] | 3452 | }; |
| 3453 | |
Rafael Antognolli | e2a3455 | 2013-12-03 15:35:45 -0200 | [diff] [blame] | 3454 | /**************************** |
| 3455 | * xdg-shell implementation */ |
| 3456 | |
| 3457 | static void |
| 3458 | xdg_surface_destroy(struct wl_client *client, |
| 3459 | struct wl_resource *resource) |
| 3460 | { |
| 3461 | wl_resource_destroy(resource); |
| 3462 | } |
| 3463 | |
| 3464 | static void |
Jasper St. Pierre | c815d62 | 2014-04-10 18:37:54 -0700 | [diff] [blame] | 3465 | xdg_surface_set_parent(struct wl_client *client, |
| 3466 | struct wl_resource *resource, |
| 3467 | struct wl_resource *parent_resource) |
Jasper St. Pierre | 63a9c33 | 2014-02-01 18:35:15 -0500 | [diff] [blame] | 3468 | { |
| 3469 | struct shell_surface *shsurf = wl_resource_get_user_data(resource); |
| 3470 | struct weston_surface *parent; |
| 3471 | |
| 3472 | if (parent_resource) |
| 3473 | parent = wl_resource_get_user_data(parent_resource); |
| 3474 | else |
| 3475 | parent = NULL; |
| 3476 | |
| 3477 | shell_surface_set_parent(shsurf, parent); |
| 3478 | } |
| 3479 | |
| 3480 | static void |
Rafael Antognolli | e2a3455 | 2013-12-03 15:35:45 -0200 | [diff] [blame] | 3481 | xdg_surface_set_app_id(struct wl_client *client, |
| 3482 | struct wl_resource *resource, |
| 3483 | const char *app_id) |
| 3484 | { |
| 3485 | struct shell_surface *shsurf = wl_resource_get_user_data(resource); |
| 3486 | |
| 3487 | free(shsurf->class); |
| 3488 | shsurf->class = strdup(app_id); |
| 3489 | } |
| 3490 | |
| 3491 | static void |
Jasper St. Pierre | 81ff075 | 2014-03-13 11:04:53 -0400 | [diff] [blame] | 3492 | xdg_surface_show_window_menu(struct wl_client *client, |
| 3493 | struct wl_resource *surface_resource, |
| 3494 | struct wl_resource *seat_resource, |
| 3495 | uint32_t serial, |
| 3496 | int32_t x, |
| 3497 | int32_t y) |
| 3498 | { |
| 3499 | /* TODO */ |
| 3500 | } |
| 3501 | |
| 3502 | static void |
Rafael Antognolli | e2a3455 | 2013-12-03 15:35:45 -0200 | [diff] [blame] | 3503 | xdg_surface_set_title(struct wl_client *client, |
| 3504 | struct wl_resource *resource, const char *title) |
| 3505 | { |
| 3506 | struct shell_surface *shsurf = wl_resource_get_user_data(resource); |
| 3507 | |
| 3508 | set_title(shsurf, title); |
| 3509 | } |
| 3510 | |
| 3511 | static void |
| 3512 | xdg_surface_move(struct wl_client *client, struct wl_resource *resource, |
| 3513 | struct wl_resource *seat_resource, uint32_t serial) |
| 3514 | { |
| 3515 | common_surface_move(resource, seat_resource, serial); |
| 3516 | } |
| 3517 | |
| 3518 | static void |
| 3519 | xdg_surface_resize(struct wl_client *client, struct wl_resource *resource, |
| 3520 | struct wl_resource *seat_resource, uint32_t serial, |
| 3521 | uint32_t edges) |
| 3522 | { |
| 3523 | common_surface_resize(resource, seat_resource, serial, edges); |
| 3524 | } |
| 3525 | |
| 3526 | static void |
Jasper St. Pierre | ab2c108 | 2014-04-10 10:41:46 -0700 | [diff] [blame] | 3527 | xdg_surface_ack_configure(struct wl_client *client, |
| 3528 | struct wl_resource *resource, |
| 3529 | uint32_t serial) |
Rafael Antognolli | e2a3455 | 2013-12-03 15:35:45 -0200 | [diff] [blame] | 3530 | { |
| 3531 | struct shell_surface *shsurf = wl_resource_get_user_data(resource); |
| 3532 | |
Jasper St. Pierre | 8c6aa45 | 2014-02-08 18:29:49 -0500 | [diff] [blame] | 3533 | if (shsurf->state_requested) { |
| 3534 | shsurf->next_state = shsurf->requested_state; |
| 3535 | shsurf->state_changed = true; |
| 3536 | shsurf->state_requested = false; |
Rafael Antognolli | 3c4e3f7 | 2013-12-03 15:35:46 -0200 | [diff] [blame] | 3537 | } |
Rafael Antognolli | e2a3455 | 2013-12-03 15:35:45 -0200 | [diff] [blame] | 3538 | } |
| 3539 | |
Manuel Bachmann | 50c87db | 2014-02-26 15:52:13 +0100 | [diff] [blame] | 3540 | static void |
Jasper St. Pierre | ccf48fb | 2014-05-02 10:21:38 -0400 | [diff] [blame] | 3541 | xdg_surface_set_window_geometry(struct wl_client *client, |
| 3542 | struct wl_resource *resource, |
| 3543 | int32_t x, |
| 3544 | int32_t y, |
| 3545 | int32_t width, |
| 3546 | int32_t height) |
| 3547 | { |
| 3548 | struct shell_surface *shsurf = wl_resource_get_user_data(resource); |
| 3549 | |
| 3550 | set_window_geometry(shsurf, x, y, width, height); |
| 3551 | } |
| 3552 | |
| 3553 | static void |
Jasper St. Pierre | ab2c108 | 2014-04-10 10:41:46 -0700 | [diff] [blame] | 3554 | xdg_surface_set_maximized(struct wl_client *client, |
| 3555 | struct wl_resource *resource) |
| 3556 | { |
| 3557 | struct shell_surface *shsurf = wl_resource_get_user_data(resource); |
| 3558 | |
| 3559 | shsurf->state_requested = true; |
| 3560 | shsurf->requested_state.maximized = true; |
Jasper St. Pierre | 9aa8ce6 | 2014-04-11 16:18:54 -0700 | [diff] [blame] | 3561 | send_configure_for_surface(shsurf); |
Jasper St. Pierre | ab2c108 | 2014-04-10 10:41:46 -0700 | [diff] [blame] | 3562 | } |
| 3563 | |
| 3564 | static void |
| 3565 | xdg_surface_unset_maximized(struct wl_client *client, |
| 3566 | struct wl_resource *resource) |
| 3567 | { |
| 3568 | struct shell_surface *shsurf = wl_resource_get_user_data(resource); |
| 3569 | |
| 3570 | shsurf->state_requested = true; |
| 3571 | shsurf->requested_state.maximized = false; |
Jasper St. Pierre | 6458ec3 | 2014-04-11 16:00:31 -0700 | [diff] [blame] | 3572 | send_configure_for_surface(shsurf); |
Jasper St. Pierre | ab2c108 | 2014-04-10 10:41:46 -0700 | [diff] [blame] | 3573 | } |
| 3574 | |
| 3575 | static void |
| 3576 | xdg_surface_set_fullscreen(struct wl_client *client, |
| 3577 | struct wl_resource *resource, |
| 3578 | struct wl_resource *output_resource) |
| 3579 | { |
| 3580 | struct shell_surface *shsurf = wl_resource_get_user_data(resource); |
| 3581 | struct weston_output *output; |
| 3582 | |
| 3583 | shsurf->state_requested = true; |
| 3584 | shsurf->requested_state.fullscreen = true; |
| 3585 | |
| 3586 | if (output_resource) |
| 3587 | output = wl_resource_get_user_data(output_resource); |
| 3588 | else |
| 3589 | output = NULL; |
| 3590 | |
Jasper St. Pierre | 9aa8ce6 | 2014-04-11 16:18:54 -0700 | [diff] [blame] | 3591 | shell_surface_set_output(shsurf, output); |
| 3592 | shsurf->fullscreen_output = shsurf->output; |
Jasper St. Pierre | ab2c108 | 2014-04-10 10:41:46 -0700 | [diff] [blame] | 3593 | |
Jasper St. Pierre | 9aa8ce6 | 2014-04-11 16:18:54 -0700 | [diff] [blame] | 3594 | send_configure_for_surface(shsurf); |
Jasper St. Pierre | ab2c108 | 2014-04-10 10:41:46 -0700 | [diff] [blame] | 3595 | } |
| 3596 | |
| 3597 | static void |
| 3598 | xdg_surface_unset_fullscreen(struct wl_client *client, |
| 3599 | struct wl_resource *resource) |
| 3600 | { |
| 3601 | struct shell_surface *shsurf = wl_resource_get_user_data(resource); |
| 3602 | |
| 3603 | shsurf->state_requested = true; |
| 3604 | shsurf->requested_state.fullscreen = false; |
Jasper St. Pierre | 6458ec3 | 2014-04-11 16:00:31 -0700 | [diff] [blame] | 3605 | send_configure_for_surface(shsurf); |
Jasper St. Pierre | ab2c108 | 2014-04-10 10:41:46 -0700 | [diff] [blame] | 3606 | } |
| 3607 | |
| 3608 | static void |
Manuel Bachmann | 50c87db | 2014-02-26 15:52:13 +0100 | [diff] [blame] | 3609 | xdg_surface_set_minimized(struct wl_client *client, |
| 3610 | struct wl_resource *resource) |
| 3611 | { |
| 3612 | struct shell_surface *shsurf = wl_resource_get_user_data(resource); |
| 3613 | |
| 3614 | if (shsurf->type != SHELL_SURFACE_TOPLEVEL) |
| 3615 | return; |
| 3616 | |
| 3617 | /* apply compositor's own minimization logic (hide) */ |
| 3618 | set_minimized(shsurf->surface, 1); |
| 3619 | } |
| 3620 | |
Rafael Antognolli | e2a3455 | 2013-12-03 15:35:45 -0200 | [diff] [blame] | 3621 | static const struct xdg_surface_interface xdg_surface_implementation = { |
| 3622 | xdg_surface_destroy, |
Jasper St. Pierre | c815d62 | 2014-04-10 18:37:54 -0700 | [diff] [blame] | 3623 | xdg_surface_set_parent, |
Rafael Antognolli | e2a3455 | 2013-12-03 15:35:45 -0200 | [diff] [blame] | 3624 | xdg_surface_set_title, |
| 3625 | xdg_surface_set_app_id, |
Jasper St. Pierre | 81ff075 | 2014-03-13 11:04:53 -0400 | [diff] [blame] | 3626 | xdg_surface_show_window_menu, |
Rafael Antognolli | e2a3455 | 2013-12-03 15:35:45 -0200 | [diff] [blame] | 3627 | xdg_surface_move, |
| 3628 | xdg_surface_resize, |
Jasper St. Pierre | ab2c108 | 2014-04-10 10:41:46 -0700 | [diff] [blame] | 3629 | xdg_surface_ack_configure, |
Jasper St. Pierre | ccf48fb | 2014-05-02 10:21:38 -0400 | [diff] [blame] | 3630 | xdg_surface_set_window_geometry, |
Jasper St. Pierre | ab2c108 | 2014-04-10 10:41:46 -0700 | [diff] [blame] | 3631 | xdg_surface_set_maximized, |
| 3632 | xdg_surface_unset_maximized, |
| 3633 | xdg_surface_set_fullscreen, |
| 3634 | xdg_surface_unset_fullscreen, |
| 3635 | xdg_surface_set_minimized, |
Rafael Antognolli | e2a3455 | 2013-12-03 15:35:45 -0200 | [diff] [blame] | 3636 | }; |
| 3637 | |
| 3638 | static void |
| 3639 | xdg_send_configure(struct weston_surface *surface, |
Jasper St. Pierre | ac985be | 2014-04-28 11:19:28 -0400 | [diff] [blame] | 3640 | int32_t width, int32_t height) |
Rafael Antognolli | e2a3455 | 2013-12-03 15:35:45 -0200 | [diff] [blame] | 3641 | { |
| 3642 | struct shell_surface *shsurf = get_shell_surface(surface); |
Jasper St. Pierre | ab2c108 | 2014-04-10 10:41:46 -0700 | [diff] [blame] | 3643 | uint32_t *s; |
| 3644 | struct wl_array states; |
| 3645 | uint32_t serial; |
Rafael Antognolli | e2a3455 | 2013-12-03 15:35:45 -0200 | [diff] [blame] | 3646 | |
U. Artie Eoff | cf5737a | 2014-01-17 10:08:25 -0800 | [diff] [blame] | 3647 | assert(shsurf); |
| 3648 | |
Jasper St. Pierre | ab2c108 | 2014-04-10 10:41:46 -0700 | [diff] [blame] | 3649 | if (!shsurf->resource) |
| 3650 | return; |
| 3651 | |
| 3652 | wl_array_init(&states); |
| 3653 | if (shsurf->requested_state.fullscreen) { |
| 3654 | s = wl_array_add(&states, sizeof *s); |
| 3655 | *s = XDG_SURFACE_STATE_FULLSCREEN; |
| 3656 | } else if (shsurf->requested_state.maximized) { |
| 3657 | s = wl_array_add(&states, sizeof *s); |
| 3658 | *s = XDG_SURFACE_STATE_MAXIMIZED; |
| 3659 | } |
Jasper St. Pierre | 5befdda | 2014-05-06 08:50:47 -0400 | [diff] [blame] | 3660 | if (shsurf->resize_edges != 0) { |
| 3661 | s = wl_array_add(&states, sizeof *s); |
| 3662 | *s = XDG_SURFACE_STATE_RESIZING; |
| 3663 | } |
Jasper St. Pierre | 973d787 | 2014-05-06 08:44:29 -0400 | [diff] [blame] | 3664 | if (shsurf->focus_count > 0) { |
| 3665 | s = wl_array_add(&states, sizeof *s); |
| 3666 | *s = XDG_SURFACE_STATE_ACTIVATED; |
| 3667 | } |
Jasper St. Pierre | ab2c108 | 2014-04-10 10:41:46 -0700 | [diff] [blame] | 3668 | |
| 3669 | serial = wl_display_next_serial(shsurf->surface->compositor->wl_display); |
| 3670 | xdg_surface_send_configure(shsurf->resource, width, height, &states, serial); |
| 3671 | |
| 3672 | wl_array_release(&states); |
Rafael Antognolli | e2a3455 | 2013-12-03 15:35:45 -0200 | [diff] [blame] | 3673 | } |
| 3674 | |
| 3675 | static const struct weston_shell_client xdg_client = { |
| 3676 | xdg_send_configure |
| 3677 | }; |
| 3678 | |
| 3679 | static void |
| 3680 | xdg_use_unstable_version(struct wl_client *client, |
| 3681 | struct wl_resource *resource, |
| 3682 | int32_t version) |
| 3683 | { |
| 3684 | if (version > 1) { |
| 3685 | wl_resource_post_error(resource, |
| 3686 | 1, |
| 3687 | "xdg-shell:: version not implemented yet."); |
| 3688 | return; |
| 3689 | } |
| 3690 | } |
| 3691 | |
| 3692 | static struct shell_surface * |
Jason Ekstrand | 9e9512f | 2014-04-16 21:12:10 -0500 | [diff] [blame] | 3693 | create_xdg_surface(struct shell_client *owner, void *shell, |
| 3694 | struct weston_surface *surface, |
Rafael Antognolli | e2a3455 | 2013-12-03 15:35:45 -0200 | [diff] [blame] | 3695 | const struct weston_shell_client *client) |
| 3696 | { |
| 3697 | struct shell_surface *shsurf; |
Rafael Antognolli | e2a3455 | 2013-12-03 15:35:45 -0200 | [diff] [blame] | 3698 | |
Jason Ekstrand | 9e9512f | 2014-04-16 21:12:10 -0500 | [diff] [blame] | 3699 | shsurf = create_common_surface(owner, shell, surface, client); |
Kristian Høgsberg | c8f8dd8 | 2013-12-05 23:20:33 -0800 | [diff] [blame] | 3700 | shsurf->type = SHELL_SURFACE_TOPLEVEL; |
Rafael Antognolli | e2a3455 | 2013-12-03 15:35:45 -0200 | [diff] [blame] | 3701 | |
| 3702 | return shsurf; |
| 3703 | } |
| 3704 | |
| 3705 | static void |
| 3706 | xdg_get_xdg_surface(struct wl_client *client, |
| 3707 | struct wl_resource *resource, |
| 3708 | uint32_t id, |
| 3709 | struct wl_resource *surface_resource) |
| 3710 | { |
| 3711 | struct weston_surface *surface = |
| 3712 | wl_resource_get_user_data(surface_resource); |
Kristian Høgsberg | 2bff94e | 2014-02-11 12:22:51 -0800 | [diff] [blame] | 3713 | struct shell_client *sc = wl_resource_get_user_data(resource); |
| 3714 | struct desktop_shell *shell = sc->shell; |
Rafael Antognolli | e2a3455 | 2013-12-03 15:35:45 -0200 | [diff] [blame] | 3715 | struct shell_surface *shsurf; |
| 3716 | |
| 3717 | if (get_shell_surface(surface)) { |
| 3718 | wl_resource_post_error(surface_resource, |
| 3719 | WL_DISPLAY_ERROR_INVALID_OBJECT, |
Jasper St. Pierre | fe9671e | 2014-03-25 13:31:44 -0400 | [diff] [blame] | 3720 | "xdg_shell::get_xdg_surface already requested"); |
Rafael Antognolli | e2a3455 | 2013-12-03 15:35:45 -0200 | [diff] [blame] | 3721 | return; |
| 3722 | } |
| 3723 | |
Jason Ekstrand | 9e9512f | 2014-04-16 21:12:10 -0500 | [diff] [blame] | 3724 | shsurf = create_xdg_surface(sc, shell, surface, &xdg_client); |
Rafael Antognolli | e2a3455 | 2013-12-03 15:35:45 -0200 | [diff] [blame] | 3725 | if (!shsurf) { |
| 3726 | wl_resource_post_error(surface_resource, |
| 3727 | WL_DISPLAY_ERROR_INVALID_OBJECT, |
| 3728 | "surface->configure already set"); |
| 3729 | return; |
| 3730 | } |
| 3731 | |
| 3732 | shsurf->resource = |
| 3733 | wl_resource_create(client, |
| 3734 | &xdg_surface_interface, 1, id); |
| 3735 | wl_resource_set_implementation(shsurf->resource, |
| 3736 | &xdg_surface_implementation, |
| 3737 | shsurf, shell_destroy_shell_surface); |
| 3738 | } |
| 3739 | |
| 3740 | static bool |
| 3741 | shell_surface_is_xdg_surface(struct shell_surface *shsurf) |
| 3742 | { |
Kristian Høgsberg | 0b7d995 | 2014-02-03 15:50:38 -0800 | [diff] [blame] | 3743 | return shsurf->resource && |
| 3744 | wl_resource_instance_of(shsurf->resource, |
| 3745 | &xdg_surface_interface, |
| 3746 | &xdg_surface_implementation); |
Rafael Antognolli | e2a3455 | 2013-12-03 15:35:45 -0200 | [diff] [blame] | 3747 | } |
| 3748 | |
| 3749 | /* xdg-popup implementation */ |
| 3750 | |
| 3751 | static void |
| 3752 | xdg_popup_destroy(struct wl_client *client, |
| 3753 | struct wl_resource *resource) |
| 3754 | { |
| 3755 | wl_resource_destroy(resource); |
| 3756 | } |
| 3757 | |
Rafael Antognolli | e2a3455 | 2013-12-03 15:35:45 -0200 | [diff] [blame] | 3758 | static const struct xdg_popup_interface xdg_popup_implementation = { |
| 3759 | xdg_popup_destroy, |
Rafael Antognolli | e2a3455 | 2013-12-03 15:35:45 -0200 | [diff] [blame] | 3760 | }; |
| 3761 | |
| 3762 | static void |
| 3763 | xdg_popup_send_configure(struct weston_surface *surface, |
Jasper St. Pierre | ac985be | 2014-04-28 11:19:28 -0400 | [diff] [blame] | 3764 | int32_t width, int32_t height) |
Rafael Antognolli | e2a3455 | 2013-12-03 15:35:45 -0200 | [diff] [blame] | 3765 | { |
| 3766 | } |
| 3767 | |
| 3768 | static const struct weston_shell_client xdg_popup_client = { |
| 3769 | xdg_popup_send_configure |
| 3770 | }; |
| 3771 | |
| 3772 | static struct shell_surface * |
Jason Ekstrand | 9e9512f | 2014-04-16 21:12:10 -0500 | [diff] [blame] | 3773 | create_xdg_popup(struct shell_client *owner, void *shell, |
| 3774 | struct weston_surface *surface, |
Rafael Antognolli | e2a3455 | 2013-12-03 15:35:45 -0200 | [diff] [blame] | 3775 | const struct weston_shell_client *client, |
| 3776 | struct weston_surface *parent, |
| 3777 | struct shell_seat *seat, |
| 3778 | uint32_t serial, |
| 3779 | int32_t x, int32_t y) |
| 3780 | { |
| 3781 | struct shell_surface *shsurf; |
Rafael Antognolli | e2a3455 | 2013-12-03 15:35:45 -0200 | [diff] [blame] | 3782 | |
Jason Ekstrand | 9e9512f | 2014-04-16 21:12:10 -0500 | [diff] [blame] | 3783 | shsurf = create_common_surface(owner, shell, surface, client); |
Kristian Høgsberg | c8f8dd8 | 2013-12-05 23:20:33 -0800 | [diff] [blame] | 3784 | shsurf->type = SHELL_SURFACE_POPUP; |
Rafael Antognolli | e2a3455 | 2013-12-03 15:35:45 -0200 | [diff] [blame] | 3785 | shsurf->popup.shseat = seat; |
| 3786 | shsurf->popup.serial = serial; |
| 3787 | shsurf->popup.x = x; |
| 3788 | shsurf->popup.y = y; |
| 3789 | shell_surface_set_parent(shsurf, parent); |
| 3790 | |
| 3791 | return shsurf; |
| 3792 | } |
| 3793 | |
| 3794 | static void |
| 3795 | xdg_get_xdg_popup(struct wl_client *client, |
| 3796 | struct wl_resource *resource, |
| 3797 | uint32_t id, |
| 3798 | struct wl_resource *surface_resource, |
| 3799 | struct wl_resource *parent_resource, |
| 3800 | struct wl_resource *seat_resource, |
| 3801 | uint32_t serial, |
| 3802 | int32_t x, int32_t y, uint32_t flags) |
| 3803 | { |
| 3804 | struct weston_surface *surface = |
| 3805 | wl_resource_get_user_data(surface_resource); |
Kristian Høgsberg | 2bff94e | 2014-02-11 12:22:51 -0800 | [diff] [blame] | 3806 | struct shell_client *sc = wl_resource_get_user_data(resource); |
| 3807 | struct desktop_shell *shell = sc->shell; |
Rafael Antognolli | e2a3455 | 2013-12-03 15:35:45 -0200 | [diff] [blame] | 3808 | struct shell_surface *shsurf; |
| 3809 | struct weston_surface *parent; |
| 3810 | struct shell_seat *seat; |
| 3811 | |
| 3812 | if (get_shell_surface(surface)) { |
| 3813 | wl_resource_post_error(surface_resource, |
| 3814 | WL_DISPLAY_ERROR_INVALID_OBJECT, |
Jasper St. Pierre | fe9671e | 2014-03-25 13:31:44 -0400 | [diff] [blame] | 3815 | "xdg_shell::get_xdg_popup already requested"); |
Rafael Antognolli | e2a3455 | 2013-12-03 15:35:45 -0200 | [diff] [blame] | 3816 | return; |
| 3817 | } |
| 3818 | |
| 3819 | if (!parent_resource) { |
| 3820 | wl_resource_post_error(surface_resource, |
| 3821 | WL_DISPLAY_ERROR_INVALID_OBJECT, |
| 3822 | "xdg_shell::get_xdg_popup requires a parent shell surface"); |
Jasper St. Pierre | 666bc92 | 2014-08-07 16:43:13 -0400 | [diff] [blame] | 3823 | return; |
Rafael Antognolli | e2a3455 | 2013-12-03 15:35:45 -0200 | [diff] [blame] | 3824 | } |
| 3825 | |
| 3826 | parent = wl_resource_get_user_data(parent_resource); |
| 3827 | seat = get_shell_seat(wl_resource_get_user_data(seat_resource));; |
| 3828 | |
Jason Ekstrand | 9e9512f | 2014-04-16 21:12:10 -0500 | [diff] [blame] | 3829 | shsurf = create_xdg_popup(sc, shell, surface, &xdg_popup_client, |
Rafael Antognolli | e2a3455 | 2013-12-03 15:35:45 -0200 | [diff] [blame] | 3830 | parent, seat, serial, x, y); |
| 3831 | if (!shsurf) { |
| 3832 | wl_resource_post_error(surface_resource, |
| 3833 | WL_DISPLAY_ERROR_INVALID_OBJECT, |
| 3834 | "surface->configure already set"); |
| 3835 | return; |
| 3836 | } |
| 3837 | |
| 3838 | shsurf->resource = |
| 3839 | wl_resource_create(client, |
| 3840 | &xdg_popup_interface, 1, id); |
| 3841 | wl_resource_set_implementation(shsurf->resource, |
| 3842 | &xdg_popup_implementation, |
| 3843 | shsurf, shell_destroy_shell_surface); |
| 3844 | } |
| 3845 | |
Kristian Høgsberg | 2bff94e | 2014-02-11 12:22:51 -0800 | [diff] [blame] | 3846 | static void |
| 3847 | xdg_pong(struct wl_client *client, |
| 3848 | struct wl_resource *resource, uint32_t serial) |
| 3849 | { |
| 3850 | struct shell_client *sc = wl_resource_get_user_data(resource); |
Kristian Høgsberg | 2bff94e | 2014-02-11 12:22:51 -0800 | [diff] [blame] | 3851 | |
Kristian Høgsberg | dd62aba | 2014-02-12 09:56:19 -0800 | [diff] [blame] | 3852 | shell_client_pong(sc, serial); |
Kristian Høgsberg | 2bff94e | 2014-02-11 12:22:51 -0800 | [diff] [blame] | 3853 | } |
| 3854 | |
Rafael Antognolli | e2a3455 | 2013-12-03 15:35:45 -0200 | [diff] [blame] | 3855 | static bool |
| 3856 | shell_surface_is_xdg_popup(struct shell_surface *shsurf) |
| 3857 | { |
| 3858 | return wl_resource_instance_of(shsurf->resource, |
| 3859 | &xdg_popup_interface, |
| 3860 | &xdg_popup_implementation); |
| 3861 | } |
| 3862 | |
| 3863 | static const struct xdg_shell_interface xdg_implementation = { |
| 3864 | xdg_use_unstable_version, |
| 3865 | xdg_get_xdg_surface, |
Kristian Høgsberg | 2bff94e | 2014-02-11 12:22:51 -0800 | [diff] [blame] | 3866 | xdg_get_xdg_popup, |
| 3867 | xdg_pong |
Rafael Antognolli | e2a3455 | 2013-12-03 15:35:45 -0200 | [diff] [blame] | 3868 | }; |
| 3869 | |
| 3870 | static int |
| 3871 | xdg_shell_unversioned_dispatch(const void *implementation, |
| 3872 | void *_target, uint32_t opcode, |
| 3873 | const struct wl_message *message, |
| 3874 | union wl_argument *args) |
| 3875 | { |
| 3876 | struct wl_resource *resource = _target; |
Kristian Høgsberg | 2bff94e | 2014-02-11 12:22:51 -0800 | [diff] [blame] | 3877 | struct shell_client *sc = wl_resource_get_user_data(resource); |
Rafael Antognolli | e2a3455 | 2013-12-03 15:35:45 -0200 | [diff] [blame] | 3878 | |
| 3879 | if (opcode != 0) { |
| 3880 | wl_resource_post_error(resource, |
| 3881 | WL_DISPLAY_ERROR_INVALID_OBJECT, |
| 3882 | "must call use_unstable_version first"); |
| 3883 | return 0; |
| 3884 | } |
| 3885 | |
Kristian Høgsberg | c7680b0 | 2014-02-19 10:14:46 -0800 | [diff] [blame] | 3886 | #define XDG_SERVER_VERSION 3 |
Rafael Antognolli | e2a3455 | 2013-12-03 15:35:45 -0200 | [diff] [blame] | 3887 | |
Kristian Høgsberg | 8d344a0 | 2013-12-08 22:27:11 -0800 | [diff] [blame] | 3888 | static_assert(XDG_SERVER_VERSION == XDG_SHELL_VERSION_CURRENT, |
| 3889 | "shell implementation doesn't match protocol version"); |
| 3890 | |
Rafael Antognolli | e2a3455 | 2013-12-03 15:35:45 -0200 | [diff] [blame] | 3891 | if (args[0].i != XDG_SERVER_VERSION) { |
| 3892 | wl_resource_post_error(resource, |
| 3893 | WL_DISPLAY_ERROR_INVALID_OBJECT, |
| 3894 | "incompatible version, server is %d " |
| 3895 | "client wants %d", |
| 3896 | XDG_SERVER_VERSION, args[0].i); |
| 3897 | return 0; |
| 3898 | } |
| 3899 | |
| 3900 | wl_resource_set_implementation(resource, &xdg_implementation, |
Kristian Høgsberg | 2bff94e | 2014-02-11 12:22:51 -0800 | [diff] [blame] | 3901 | sc, NULL); |
Rafael Antognolli | e2a3455 | 2013-12-03 15:35:45 -0200 | [diff] [blame] | 3902 | |
| 3903 | return 1; |
| 3904 | } |
| 3905 | |
| 3906 | /* end of xdg-shell implementation */ |
| 3907 | /***********************************/ |
| 3908 | |
Kristian Høgsberg | 0793756 | 2011-04-12 17:25:42 -0400 | [diff] [blame] | 3909 | static void |
Ander Conselvan de Oliveira | 859e885 | 2013-02-21 18:35:21 +0200 | [diff] [blame] | 3910 | shell_fade(struct desktop_shell *shell, enum fade_type type); |
| 3911 | |
| 3912 | static int |
| 3913 | screensaver_timeout(void *data) |
| 3914 | { |
| 3915 | struct desktop_shell *shell = data; |
| 3916 | |
| 3917 | shell_fade(shell, FADE_OUT); |
| 3918 | |
| 3919 | return 1; |
| 3920 | } |
| 3921 | |
| 3922 | static void |
Kristian Høgsberg | 8334bc1 | 2012-01-03 10:29:47 -0500 | [diff] [blame] | 3923 | handle_screensaver_sigchld(struct weston_process *proc, int status) |
Pekka Paalanen | 18027e5 | 2011-12-02 16:31:49 +0200 | [diff] [blame] | 3924 | { |
Ander Conselvan de Oliveira | 18639f8 | 2013-02-15 18:44:19 +0200 | [diff] [blame] | 3925 | struct desktop_shell *shell = |
| 3926 | container_of(proc, struct desktop_shell, screensaver.process); |
Ander Conselvan de Oliveira | 18639f8 | 2013-02-15 18:44:19 +0200 | [diff] [blame] | 3927 | |
Pekka Paalanen | 18027e5 | 2011-12-02 16:31:49 +0200 | [diff] [blame] | 3928 | proc->pid = 0; |
Ander Conselvan de Oliveira | 18639f8 | 2013-02-15 18:44:19 +0200 | [diff] [blame] | 3929 | |
| 3930 | if (shell->locked) |
Ander Conselvan de Oliveira | b17537e | 2013-02-22 14:16:18 +0200 | [diff] [blame] | 3931 | weston_compositor_sleep(shell->compositor); |
Pekka Paalanen | 18027e5 | 2011-12-02 16:31:49 +0200 | [diff] [blame] | 3932 | } |
| 3933 | |
| 3934 | static void |
Tiago Vignatti | be14326 | 2012-04-16 17:31:41 +0300 | [diff] [blame] | 3935 | launch_screensaver(struct desktop_shell *shell) |
Pekka Paalanen | 77346a6 | 2011-11-30 16:26:35 +0200 | [diff] [blame] | 3936 | { |
| 3937 | if (shell->screensaver.binding) |
| 3938 | return; |
| 3939 | |
Ander Conselvan de Oliveira | dda9d78 | 2013-02-22 14:16:19 +0200 | [diff] [blame] | 3940 | if (!shell->screensaver.path) { |
| 3941 | weston_compositor_sleep(shell->compositor); |
Pekka Paalanen | e955f1e | 2011-12-07 11:49:52 +0200 | [diff] [blame] | 3942 | return; |
Ander Conselvan de Oliveira | dda9d78 | 2013-02-22 14:16:19 +0200 | [diff] [blame] | 3943 | } |
Pekka Paalanen | e955f1e | 2011-12-07 11:49:52 +0200 | [diff] [blame] | 3944 | |
Kristian Høgsberg | 32bed57 | 2012-03-01 17:11:36 -0500 | [diff] [blame] | 3945 | if (shell->screensaver.process.pid != 0) { |
Martin Minarik | 6d11836 | 2012-06-07 18:01:59 +0200 | [diff] [blame] | 3946 | weston_log("old screensaver still running\n"); |
Kristian Høgsberg | 32bed57 | 2012-03-01 17:11:36 -0500 | [diff] [blame] | 3947 | return; |
| 3948 | } |
| 3949 | |
Kristian Høgsberg | 8334bc1 | 2012-01-03 10:29:47 -0500 | [diff] [blame] | 3950 | weston_client_launch(shell->compositor, |
Pekka Paalanen | 18027e5 | 2011-12-02 16:31:49 +0200 | [diff] [blame] | 3951 | &shell->screensaver.process, |
Pekka Paalanen | e955f1e | 2011-12-07 11:49:52 +0200 | [diff] [blame] | 3952 | shell->screensaver.path, |
Pekka Paalanen | 18027e5 | 2011-12-02 16:31:49 +0200 | [diff] [blame] | 3953 | handle_screensaver_sigchld); |
Pekka Paalanen | 77346a6 | 2011-11-30 16:26:35 +0200 | [diff] [blame] | 3954 | } |
| 3955 | |
| 3956 | static void |
Tiago Vignatti | be14326 | 2012-04-16 17:31:41 +0300 | [diff] [blame] | 3957 | terminate_screensaver(struct desktop_shell *shell) |
Pekka Paalanen | 77346a6 | 2011-11-30 16:26:35 +0200 | [diff] [blame] | 3958 | { |
Pekka Paalanen | 18027e5 | 2011-12-02 16:31:49 +0200 | [diff] [blame] | 3959 | if (shell->screensaver.process.pid == 0) |
| 3960 | return; |
| 3961 | |
Ander Conselvan de Oliveira | 4e20e9b | 2014-04-10 14:49:35 +0300 | [diff] [blame] | 3962 | /* Disarm the screensaver timer, otherwise it may fire when the |
| 3963 | * compositor is not in the idle state. In that case, the screen will |
| 3964 | * be locked, but the wake_signal won't fire on user input, making the |
| 3965 | * system unresponsive. */ |
| 3966 | wl_event_source_timer_update(shell->screensaver.timer, 0); |
| 3967 | |
Pekka Paalanen | 18027e5 | 2011-12-02 16:31:49 +0200 | [diff] [blame] | 3968 | kill(shell->screensaver.process.pid, SIGTERM); |
Pekka Paalanen | 77346a6 | 2011-11-30 16:26:35 +0200 | [diff] [blame] | 3969 | } |
| 3970 | |
| 3971 | static void |
Jason Ekstrand | 918f2dd | 2013-12-02 21:01:53 -0600 | [diff] [blame] | 3972 | configure_static_view(struct weston_view *ev, struct weston_layer *layer) |
Kristian Høgsberg | 962342c | 2012-06-26 16:29:50 -0400 | [diff] [blame] | 3973 | { |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 3974 | struct weston_view *v, *next; |
Kristian Høgsberg | 962342c | 2012-06-26 16:29:50 -0400 | [diff] [blame] | 3975 | |
Giulio Camuffo | 412e6a5 | 2014-07-09 22:12:56 +0300 | [diff] [blame] | 3976 | 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] | 3977 | if (v->output == ev->output && v != ev) { |
| 3978 | weston_view_unmap(v); |
| 3979 | v->surface->configure = NULL; |
Kristian Høgsberg | 962342c | 2012-06-26 16:29:50 -0400 | [diff] [blame] | 3980 | } |
| 3981 | } |
| 3982 | |
Jason Ekstrand | 918f2dd | 2013-12-02 21:01:53 -0600 | [diff] [blame] | 3983 | weston_view_set_position(ev, ev->output->x, ev->output->y); |
Kristian Høgsberg | 962342c | 2012-06-26 16:29:50 -0400 | [diff] [blame] | 3984 | |
Giulio Camuffo | 412e6a5 | 2014-07-09 22:12:56 +0300 | [diff] [blame] | 3985 | if (wl_list_empty(&ev->layer_link.link)) { |
| 3986 | weston_layer_entry_insert(&layer->view_list, &ev->layer_link); |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 3987 | weston_compositor_schedule_repaint(ev->surface->compositor); |
Kristian Høgsberg | 962342c | 2012-06-26 16:29:50 -0400 | [diff] [blame] | 3988 | } |
| 3989 | } |
| 3990 | |
| 3991 | static void |
Jason Ekstrand | 918f2dd | 2013-12-02 21:01:53 -0600 | [diff] [blame] | 3992 | 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] | 3993 | { |
Giulio Camuffo | 7fe01b1 | 2013-03-28 18:02:42 +0100 | [diff] [blame] | 3994 | struct desktop_shell *shell = es->configure_private; |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 3995 | struct weston_view *view; |
Kristian Høgsberg | af7b1ff | 2012-06-26 21:19:23 -0400 | [diff] [blame] | 3996 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 3997 | view = container_of(es->views.next, struct weston_view, surface_link); |
| 3998 | |
Jason Ekstrand | 918f2dd | 2013-12-02 21:01:53 -0600 | [diff] [blame] | 3999 | configure_static_view(view, &shell->background_layer); |
Kristian Høgsberg | af7b1ff | 2012-06-26 21:19:23 -0400 | [diff] [blame] | 4000 | } |
| 4001 | |
| 4002 | static void |
Kristian Høgsberg | 7584062 | 2011-09-06 13:48:16 -0400 | [diff] [blame] | 4003 | desktop_shell_set_background(struct wl_client *client, |
| 4004 | struct wl_resource *resource, |
Benjamin Franzke | d0f79ab | 2011-11-22 12:43:52 +0100 | [diff] [blame] | 4005 | struct wl_resource *output_resource, |
Kristian Høgsberg | 7584062 | 2011-09-06 13:48:16 -0400 | [diff] [blame] | 4006 | struct wl_resource *surface_resource) |
| 4007 | { |
Jason Ekstrand | 651f00e | 2013-06-14 10:07:54 -0500 | [diff] [blame] | 4008 | struct desktop_shell *shell = wl_resource_get_user_data(resource); |
Jason Ekstrand | 0f2ef7e | 2013-06-14 10:07:53 -0500 | [diff] [blame] | 4009 | struct weston_surface *surface = |
| 4010 | wl_resource_get_user_data(surface_resource); |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 4011 | struct weston_view *view, *next; |
Kristian Høgsberg | 7584062 | 2011-09-06 13:48:16 -0400 | [diff] [blame] | 4012 | |
Kristian Høgsberg | 962342c | 2012-06-26 16:29:50 -0400 | [diff] [blame] | 4013 | if (surface->configure) { |
| 4014 | wl_resource_post_error(surface_resource, |
| 4015 | WL_DISPLAY_ERROR_INVALID_OBJECT, |
| 4016 | "surface role already assigned"); |
| 4017 | return; |
| 4018 | } |
Benjamin Franzke | d0f79ab | 2011-11-22 12:43:52 +0100 | [diff] [blame] | 4019 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 4020 | wl_list_for_each_safe(view, next, &surface->views, surface_link) |
| 4021 | weston_view_destroy(view); |
| 4022 | view = weston_view_create(surface); |
| 4023 | |
Kristian Høgsberg | 962342c | 2012-06-26 16:29:50 -0400 | [diff] [blame] | 4024 | surface->configure = background_configure; |
Giulio Camuffo | 7fe01b1 | 2013-03-28 18:02:42 +0100 | [diff] [blame] | 4025 | surface->configure_private = shell; |
Jason Ekstrand | a0d2dde | 2013-06-14 10:08:01 -0500 | [diff] [blame] | 4026 | surface->output = wl_resource_get_user_data(output_resource); |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 4027 | view->output = surface->output; |
Kristian Høgsberg | eae5de7 | 2012-04-11 22:42:15 -0400 | [diff] [blame] | 4028 | desktop_shell_send_configure(resource, 0, |
Kristian Høgsberg | 0b5cd0c | 2012-03-04 21:57:37 -0500 | [diff] [blame] | 4029 | surface_resource, |
Scott Moreau | 1bad5db | 2012-08-18 01:04:05 -0600 | [diff] [blame] | 4030 | surface->output->width, |
| 4031 | surface->output->height); |
Kristian Høgsberg | 7584062 | 2011-09-06 13:48:16 -0400 | [diff] [blame] | 4032 | } |
| 4033 | |
| 4034 | static void |
Jason Ekstrand | 918f2dd | 2013-12-02 21:01:53 -0600 | [diff] [blame] | 4035 | 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] | 4036 | { |
Giulio Camuffo | 7fe01b1 | 2013-03-28 18:02:42 +0100 | [diff] [blame] | 4037 | struct desktop_shell *shell = es->configure_private; |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 4038 | struct weston_view *view; |
Kristian Høgsberg | af7b1ff | 2012-06-26 21:19:23 -0400 | [diff] [blame] | 4039 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 4040 | view = container_of(es->views.next, struct weston_view, surface_link); |
| 4041 | |
Jason Ekstrand | 918f2dd | 2013-12-02 21:01:53 -0600 | [diff] [blame] | 4042 | configure_static_view(view, &shell->panel_layer); |
Kristian Høgsberg | af7b1ff | 2012-06-26 21:19:23 -0400 | [diff] [blame] | 4043 | } |
| 4044 | |
| 4045 | static void |
Kristian Høgsberg | 7584062 | 2011-09-06 13:48:16 -0400 | [diff] [blame] | 4046 | desktop_shell_set_panel(struct wl_client *client, |
| 4047 | struct wl_resource *resource, |
Benjamin Franzke | d0f79ab | 2011-11-22 12:43:52 +0100 | [diff] [blame] | 4048 | struct wl_resource *output_resource, |
Kristian Høgsberg | 7584062 | 2011-09-06 13:48:16 -0400 | [diff] [blame] | 4049 | struct wl_resource *surface_resource) |
| 4050 | { |
Jason Ekstrand | 651f00e | 2013-06-14 10:07:54 -0500 | [diff] [blame] | 4051 | struct desktop_shell *shell = wl_resource_get_user_data(resource); |
Jason Ekstrand | 0f2ef7e | 2013-06-14 10:07:53 -0500 | [diff] [blame] | 4052 | struct weston_surface *surface = |
| 4053 | wl_resource_get_user_data(surface_resource); |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 4054 | struct weston_view *view, *next; |
Kristian Høgsberg | 7584062 | 2011-09-06 13:48:16 -0400 | [diff] [blame] | 4055 | |
Kristian Høgsberg | af7b1ff | 2012-06-26 21:19:23 -0400 | [diff] [blame] | 4056 | if (surface->configure) { |
| 4057 | wl_resource_post_error(surface_resource, |
| 4058 | WL_DISPLAY_ERROR_INVALID_OBJECT, |
| 4059 | "surface role already assigned"); |
| 4060 | return; |
| 4061 | } |
Benjamin Franzke | d0f79ab | 2011-11-22 12:43:52 +0100 | [diff] [blame] | 4062 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 4063 | wl_list_for_each_safe(view, next, &surface->views, surface_link) |
| 4064 | weston_view_destroy(view); |
| 4065 | view = weston_view_create(surface); |
| 4066 | |
Kristian Høgsberg | af7b1ff | 2012-06-26 21:19:23 -0400 | [diff] [blame] | 4067 | surface->configure = panel_configure; |
Giulio Camuffo | 7fe01b1 | 2013-03-28 18:02:42 +0100 | [diff] [blame] | 4068 | surface->configure_private = shell; |
Jason Ekstrand | a0d2dde | 2013-06-14 10:08:01 -0500 | [diff] [blame] | 4069 | surface->output = wl_resource_get_user_data(output_resource); |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 4070 | view->output = surface->output; |
Kristian Høgsberg | eae5de7 | 2012-04-11 22:42:15 -0400 | [diff] [blame] | 4071 | desktop_shell_send_configure(resource, 0, |
Kristian Høgsberg | af7b1ff | 2012-06-26 21:19:23 -0400 | [diff] [blame] | 4072 | surface_resource, |
Scott Moreau | 1bad5db | 2012-08-18 01:04:05 -0600 | [diff] [blame] | 4073 | surface->output->width, |
| 4074 | surface->output->height); |
Kristian Høgsberg | 7584062 | 2011-09-06 13:48:16 -0400 | [diff] [blame] | 4075 | } |
| 4076 | |
Pekka Paalanen | 9ef3e01 | 2011-11-15 13:34:48 +0200 | [diff] [blame] | 4077 | static void |
Jason Ekstrand | 918f2dd | 2013-12-02 21:01:53 -0600 | [diff] [blame] | 4078 | 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] | 4079 | { |
Giulio Camuffo | 7fe01b1 | 2013-03-28 18:02:42 +0100 | [diff] [blame] | 4080 | struct desktop_shell *shell = surface->configure_private; |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 4081 | struct weston_view *view; |
| 4082 | |
| 4083 | view = container_of(surface->views.next, struct weston_view, surface_link); |
Kristian Høgsberg | 730c94d | 2012-06-26 21:44:35 -0400 | [diff] [blame] | 4084 | |
Jason Ekstrand | 918f2dd | 2013-12-02 21:01:53 -0600 | [diff] [blame] | 4085 | if (surface->width == 0) |
Giulio Camuffo | 184df50 | 2013-02-21 11:29:21 +0100 | [diff] [blame] | 4086 | return; |
| 4087 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 4088 | center_on_output(view, get_default_output(shell->compositor)); |
Kristian Høgsberg | 730c94d | 2012-06-26 21:44:35 -0400 | [diff] [blame] | 4089 | |
| 4090 | if (!weston_surface_is_mapped(surface)) { |
Giulio Camuffo | 412e6a5 | 2014-07-09 22:12:56 +0300 | [diff] [blame] | 4091 | weston_layer_entry_insert(&shell->lock_layer.view_list, |
| 4092 | &view->layer_link); |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 4093 | weston_view_update_transform(view); |
Ander Conselvan de Oliveira | 87524b6 | 2013-02-21 18:35:22 +0200 | [diff] [blame] | 4094 | shell_fade(shell, FADE_IN); |
Kristian Høgsberg | 730c94d | 2012-06-26 21:44:35 -0400 | [diff] [blame] | 4095 | } |
| 4096 | } |
| 4097 | |
| 4098 | static void |
Kristian Høgsberg | 27e3052 | 2012-04-11 23:18:23 -0400 | [diff] [blame] | 4099 | handle_lock_surface_destroy(struct wl_listener *listener, void *data) |
Kristian Høgsberg | 1ec0c31 | 2011-11-15 16:39:55 -0500 | [diff] [blame] | 4100 | { |
Tiago Vignatti | be14326 | 2012-04-16 17:31:41 +0300 | [diff] [blame] | 4101 | struct desktop_shell *shell = |
| 4102 | container_of(listener, struct desktop_shell, lock_surface_listener); |
Kristian Høgsberg | 1ec0c31 | 2011-11-15 16:39:55 -0500 | [diff] [blame] | 4103 | |
Martin Minarik | 6d11836 | 2012-06-07 18:01:59 +0200 | [diff] [blame] | 4104 | weston_log("lock surface gone\n"); |
Kristian Høgsberg | 1ec0c31 | 2011-11-15 16:39:55 -0500 | [diff] [blame] | 4105 | shell->lock_surface = NULL; |
| 4106 | } |
| 4107 | |
| 4108 | static void |
Pekka Paalanen | 9ef3e01 | 2011-11-15 13:34:48 +0200 | [diff] [blame] | 4109 | desktop_shell_set_lock_surface(struct wl_client *client, |
| 4110 | struct wl_resource *resource, |
| 4111 | struct wl_resource *surface_resource) |
| 4112 | { |
Jason Ekstrand | 651f00e | 2013-06-14 10:07:54 -0500 | [diff] [blame] | 4113 | struct desktop_shell *shell = wl_resource_get_user_data(resource); |
Jason Ekstrand | 0f2ef7e | 2013-06-14 10:07:53 -0500 | [diff] [blame] | 4114 | struct weston_surface *surface = |
| 4115 | wl_resource_get_user_data(surface_resource); |
Pekka Paalanen | 9826223 | 2011-12-01 10:42:22 +0200 | [diff] [blame] | 4116 | |
Pekka Paalanen | f0fc70d | 2011-11-15 13:34:54 +0200 | [diff] [blame] | 4117 | shell->prepare_event_sent = false; |
Kristian Høgsberg | af867cc | 2011-11-15 13:34:49 +0200 | [diff] [blame] | 4118 | |
Pekka Paalanen | f0fc70d | 2011-11-15 13:34:54 +0200 | [diff] [blame] | 4119 | if (!shell->locked) |
| 4120 | return; |
| 4121 | |
Pekka Paalanen | 9826223 | 2011-12-01 10:42:22 +0200 | [diff] [blame] | 4122 | shell->lock_surface = surface; |
Pekka Paalanen | f0fc70d | 2011-11-15 13:34:54 +0200 | [diff] [blame] | 4123 | |
Kristian Høgsberg | 27e3052 | 2012-04-11 23:18:23 -0400 | [diff] [blame] | 4124 | shell->lock_surface_listener.notify = handle_lock_surface_destroy; |
Jason Ekstrand | 651f00e | 2013-06-14 10:07:54 -0500 | [diff] [blame] | 4125 | wl_signal_add(&surface->destroy_signal, |
Kristian Høgsberg | 27e3052 | 2012-04-11 23:18:23 -0400 | [diff] [blame] | 4126 | &shell->lock_surface_listener); |
Pekka Paalanen | 57da4a8 | 2011-11-23 16:42:16 +0200 | [diff] [blame] | 4127 | |
Kristian Høgsberg | aa2ee8b | 2013-10-30 15:49:45 -0700 | [diff] [blame] | 4128 | weston_view_create(surface); |
Kristian Høgsberg | 730c94d | 2012-06-26 21:44:35 -0400 | [diff] [blame] | 4129 | surface->configure = lock_surface_configure; |
Giulio Camuffo | 7fe01b1 | 2013-03-28 18:02:42 +0100 | [diff] [blame] | 4130 | surface->configure_private = shell; |
Pekka Paalanen | f0fc70d | 2011-11-15 13:34:54 +0200 | [diff] [blame] | 4131 | } |
| 4132 | |
| 4133 | static void |
Tiago Vignatti | be14326 | 2012-04-16 17:31:41 +0300 | [diff] [blame] | 4134 | resume_desktop(struct desktop_shell *shell) |
Pekka Paalanen | f0fc70d | 2011-11-15 13:34:54 +0200 | [diff] [blame] | 4135 | { |
Kristian Høgsberg | 4476aaf | 2012-06-25 14:03:13 -0400 | [diff] [blame] | 4136 | struct workspace *ws = get_current_workspace(shell); |
Pekka Paalanen | 77346a6 | 2011-11-30 16:26:35 +0200 | [diff] [blame] | 4137 | |
Pekka Paalanen | 77346a6 | 2011-11-30 16:26:35 +0200 | [diff] [blame] | 4138 | terminate_screensaver(shell); |
Pekka Paalanen | f0fc70d | 2011-11-15 13:34:54 +0200 | [diff] [blame] | 4139 | |
Kristian Høgsberg | 3be2ce9 | 2012-02-29 12:42:35 -0500 | [diff] [blame] | 4140 | wl_list_remove(&shell->lock_layer.link); |
Philipp Brüschweiler | 711fda8 | 2012-08-09 18:50:43 +0200 | [diff] [blame] | 4141 | if (shell->showing_input_panels) { |
Manuel Bachmann | 805d2f5 | 2014-03-05 12:21:34 +0100 | [diff] [blame] | 4142 | wl_list_insert(&shell->compositor->cursor_layer.link, |
Philipp Brüschweiler | 711fda8 | 2012-08-09 18:50:43 +0200 | [diff] [blame] | 4143 | &shell->input_panel_layer.link); |
| 4144 | wl_list_insert(&shell->input_panel_layer.link, |
Manuel Bachmann | 805d2f5 | 2014-03-05 12:21:34 +0100 | [diff] [blame] | 4145 | &shell->fullscreen_layer.link); |
Philipp Brüschweiler | 711fda8 | 2012-08-09 18:50:43 +0200 | [diff] [blame] | 4146 | } else { |
Manuel Bachmann | 805d2f5 | 2014-03-05 12:21:34 +0100 | [diff] [blame] | 4147 | wl_list_insert(&shell->compositor->cursor_layer.link, |
| 4148 | &shell->fullscreen_layer.link); |
Philipp Brüschweiler | 711fda8 | 2012-08-09 18:50:43 +0200 | [diff] [blame] | 4149 | } |
Manuel Bachmann | 805d2f5 | 2014-03-05 12:21:34 +0100 | [diff] [blame] | 4150 | wl_list_insert(&shell->fullscreen_layer.link, |
| 4151 | &shell->panel_layer.link); |
| 4152 | wl_list_insert(&shell->panel_layer.link, |
| 4153 | &ws->layer.link), |
Pekka Paalanen | f0fc70d | 2011-11-15 13:34:54 +0200 | [diff] [blame] | 4154 | |
Kristian Høgsberg | 2f5faff | 2012-07-31 16:36:34 -0400 | [diff] [blame] | 4155 | restore_focus_state(shell, get_current_workspace(shell)); |
Jonas Ådahl | 0476974 | 2012-06-13 00:01:24 +0200 | [diff] [blame] | 4156 | |
Pekka Paalanen | f0fc70d | 2011-11-15 13:34:54 +0200 | [diff] [blame] | 4157 | shell->locked = false; |
Ander Conselvan de Oliveira | 87524b6 | 2013-02-21 18:35:22 +0200 | [diff] [blame] | 4158 | shell_fade(shell, FADE_IN); |
Pekka Paalanen | fc6d91a | 2012-02-10 15:33:10 +0200 | [diff] [blame] | 4159 | weston_compositor_damage_all(shell->compositor); |
Pekka Paalanen | 9ef3e01 | 2011-11-15 13:34:48 +0200 | [diff] [blame] | 4160 | } |
| 4161 | |
| 4162 | static void |
| 4163 | desktop_shell_unlock(struct wl_client *client, |
| 4164 | struct wl_resource *resource) |
| 4165 | { |
Jason Ekstrand | 651f00e | 2013-06-14 10:07:54 -0500 | [diff] [blame] | 4166 | struct desktop_shell *shell = wl_resource_get_user_data(resource); |
Pekka Paalanen | 9ef3e01 | 2011-11-15 13:34:48 +0200 | [diff] [blame] | 4167 | |
Pekka Paalanen | 9ef3e01 | 2011-11-15 13:34:48 +0200 | [diff] [blame] | 4168 | shell->prepare_event_sent = false; |
Pekka Paalanen | f0fc70d | 2011-11-15 13:34:54 +0200 | [diff] [blame] | 4169 | |
| 4170 | if (shell->locked) |
| 4171 | resume_desktop(shell); |
Pekka Paalanen | 9ef3e01 | 2011-11-15 13:34:48 +0200 | [diff] [blame] | 4172 | } |
| 4173 | |
Kristian Høgsberg | d56bd90 | 2012-06-05 09:58:51 -0400 | [diff] [blame] | 4174 | static void |
Ander Conselvan de Oliveira | b9d2a0f | 2012-06-28 18:08:05 +0300 | [diff] [blame] | 4175 | desktop_shell_set_grab_surface(struct wl_client *client, |
Kristian Høgsberg | d56bd90 | 2012-06-05 09:58:51 -0400 | [diff] [blame] | 4176 | struct wl_resource *resource, |
| 4177 | struct wl_resource *surface_resource) |
| 4178 | { |
Jason Ekstrand | 651f00e | 2013-06-14 10:07:54 -0500 | [diff] [blame] | 4179 | struct desktop_shell *shell = wl_resource_get_user_data(resource); |
Kristian Høgsberg | d56bd90 | 2012-06-05 09:58:51 -0400 | [diff] [blame] | 4180 | |
Jason Ekstrand | 0f2ef7e | 2013-06-14 10:07:53 -0500 | [diff] [blame] | 4181 | shell->grab_surface = wl_resource_get_user_data(surface_resource); |
Kristian Høgsberg | 48588f8 | 2013-10-24 15:51:35 -0700 | [diff] [blame] | 4182 | weston_view_create(shell->grab_surface); |
Kristian Høgsberg | d56bd90 | 2012-06-05 09:58:51 -0400 | [diff] [blame] | 4183 | } |
| 4184 | |
Pekka Paalanen | 79346ab | 2013-05-22 18:03:09 +0300 | [diff] [blame] | 4185 | static void |
| 4186 | desktop_shell_desktop_ready(struct wl_client *client, |
| 4187 | struct wl_resource *resource) |
| 4188 | { |
Jason Ekstrand | 651f00e | 2013-06-14 10:07:54 -0500 | [diff] [blame] | 4189 | struct desktop_shell *shell = wl_resource_get_user_data(resource); |
Pekka Paalanen | 79346ab | 2013-05-22 18:03:09 +0300 | [diff] [blame] | 4190 | |
| 4191 | shell_fade_startup(shell); |
| 4192 | } |
| 4193 | |
Jonny Lamb | 765760d | 2014-08-20 15:53:19 +0200 | [diff] [blame] | 4194 | static void |
| 4195 | desktop_shell_set_panel_position(struct wl_client *client, |
| 4196 | struct wl_resource *resource, |
| 4197 | uint32_t position) |
| 4198 | { |
| 4199 | struct desktop_shell *shell = wl_resource_get_user_data(resource); |
| 4200 | |
| 4201 | if (position != DESKTOP_SHELL_PANEL_POSITION_TOP && |
| 4202 | position != DESKTOP_SHELL_PANEL_POSITION_BOTTOM && |
| 4203 | position != DESKTOP_SHELL_PANEL_POSITION_LEFT && |
| 4204 | position != DESKTOP_SHELL_PANEL_POSITION_RIGHT) { |
| 4205 | wl_resource_post_error(resource, |
| 4206 | DESKTOP_SHELL_ERROR_INVALID_ARGUMENT, |
| 4207 | "bad position argument"); |
| 4208 | return; |
| 4209 | } |
| 4210 | |
| 4211 | shell->panel_position = position; |
| 4212 | } |
| 4213 | |
Kristian Høgsberg | 7584062 | 2011-09-06 13:48:16 -0400 | [diff] [blame] | 4214 | static const struct desktop_shell_interface desktop_shell_implementation = { |
| 4215 | desktop_shell_set_background, |
Pekka Paalanen | 9ef3e01 | 2011-11-15 13:34:48 +0200 | [diff] [blame] | 4216 | desktop_shell_set_panel, |
| 4217 | desktop_shell_set_lock_surface, |
Kristian Høgsberg | d56bd90 | 2012-06-05 09:58:51 -0400 | [diff] [blame] | 4218 | desktop_shell_unlock, |
Pekka Paalanen | 79346ab | 2013-05-22 18:03:09 +0300 | [diff] [blame] | 4219 | desktop_shell_set_grab_surface, |
Jonny Lamb | 765760d | 2014-08-20 15:53:19 +0200 | [diff] [blame] | 4220 | desktop_shell_desktop_ready, |
| 4221 | desktop_shell_set_panel_position |
Kristian Høgsberg | 7584062 | 2011-09-06 13:48:16 -0400 | [diff] [blame] | 4222 | }; |
| 4223 | |
Pekka Paalanen | 92a0dc4 | 2011-11-28 15:34:13 +0200 | [diff] [blame] | 4224 | static enum shell_surface_type |
Kristian Høgsberg | 8334bc1 | 2012-01-03 10:29:47 -0500 | [diff] [blame] | 4225 | get_shell_surface_type(struct weston_surface *surface) |
Pekka Paalanen | 92a0dc4 | 2011-11-28 15:34:13 +0200 | [diff] [blame] | 4226 | { |
| 4227 | struct shell_surface *shsurf; |
| 4228 | |
| 4229 | shsurf = get_shell_surface(surface); |
| 4230 | if (!shsurf) |
Pekka Paalanen | 9826223 | 2011-12-01 10:42:22 +0200 | [diff] [blame] | 4231 | return SHELL_SURFACE_NONE; |
Pekka Paalanen | 92a0dc4 | 2011-11-28 15:34:13 +0200 | [diff] [blame] | 4232 | return shsurf->type; |
| 4233 | } |
| 4234 | |
Kristian Høgsberg | 7584062 | 2011-09-06 13:48:16 -0400 | [diff] [blame] | 4235 | static void |
Kristian Høgsberg | e314875 | 2013-05-06 23:19:49 -0400 | [diff] [blame] | 4236 | 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] | 4237 | { |
Rafal Mielniczuk | b2917a2 | 2014-01-05 20:04:59 +0100 | [diff] [blame] | 4238 | struct weston_surface *focus; |
Pekka Paalanen | 01388e2 | 2013-04-25 13:57:44 +0300 | [diff] [blame] | 4239 | struct weston_surface *surface; |
Kristian Høgsberg | 938b8fa | 2012-05-18 13:46:27 -0400 | [diff] [blame] | 4240 | struct shell_surface *shsurf; |
Kristian Høgsberg | d2abb83 | 2011-11-23 10:52:40 -0500 | [diff] [blame] | 4241 | |
Rafal Mielniczuk | b2917a2 | 2014-01-05 20:04:59 +0100 | [diff] [blame] | 4242 | if (seat->pointer->focus == NULL) |
| 4243 | return; |
| 4244 | |
| 4245 | focus = seat->pointer->focus->surface; |
| 4246 | |
Pekka Paalanen | 01388e2 | 2013-04-25 13:57:44 +0300 | [diff] [blame] | 4247 | surface = weston_surface_get_main_surface(focus); |
Benjamin Franzke | d0f79ab | 2011-11-22 12:43:52 +0100 | [diff] [blame] | 4248 | if (surface == NULL) |
| 4249 | return; |
Kristian Høgsberg | 0793756 | 2011-04-12 17:25:42 -0400 | [diff] [blame] | 4250 | |
Kristian Høgsberg | 938b8fa | 2012-05-18 13:46:27 -0400 | [diff] [blame] | 4251 | shsurf = get_shell_surface(surface); |
Rafael Antognolli | 03b1659 | 2013-12-03 15:35:42 -0200 | [diff] [blame] | 4252 | if (shsurf == NULL || shsurf->state.fullscreen || |
| 4253 | shsurf->state.maximized) |
Kristian Høgsberg | 938b8fa | 2012-05-18 13:46:27 -0400 | [diff] [blame] | 4254 | return; |
| 4255 | |
Kristian Høgsberg | ae356ae | 2014-04-29 16:03:54 -0700 | [diff] [blame] | 4256 | surface_move(shsurf, (struct weston_seat *) seat, 0); |
Kristian Høgsberg | 0793756 | 2011-04-12 17:25:42 -0400 | [diff] [blame] | 4257 | } |
| 4258 | |
| 4259 | static void |
Rafael Antognolli | ea997ac | 2013-12-03 15:35:48 -0200 | [diff] [blame] | 4260 | maximize_binding(struct weston_seat *seat, uint32_t time, uint32_t button, void *data) |
| 4261 | { |
Emilio Pozuelo Monfort | 38b58eb | 2014-01-29 11:11:12 +0100 | [diff] [blame] | 4262 | struct weston_surface *focus = seat->keyboard->focus; |
Rafael Antognolli | ea997ac | 2013-12-03 15:35:48 -0200 | [diff] [blame] | 4263 | struct weston_surface *surface; |
| 4264 | struct shell_surface *shsurf; |
| 4265 | |
| 4266 | surface = weston_surface_get_main_surface(focus); |
| 4267 | if (surface == NULL) |
| 4268 | return; |
| 4269 | |
| 4270 | shsurf = get_shell_surface(surface); |
| 4271 | if (shsurf == NULL) |
| 4272 | return; |
| 4273 | |
| 4274 | if (!shell_surface_is_xdg_surface(shsurf)) |
| 4275 | return; |
| 4276 | |
Jasper St. Pierre | ab2c108 | 2014-04-10 10:41:46 -0700 | [diff] [blame] | 4277 | shsurf->state_requested = true; |
| 4278 | shsurf->requested_state.maximized = !shsurf->state.maximized; |
Jasper St. Pierre | 9aa8ce6 | 2014-04-11 16:18:54 -0700 | [diff] [blame] | 4279 | send_configure_for_surface(shsurf); |
Rafael Antognolli | ea997ac | 2013-12-03 15:35:48 -0200 | [diff] [blame] | 4280 | } |
| 4281 | |
| 4282 | static void |
| 4283 | fullscreen_binding(struct weston_seat *seat, uint32_t time, uint32_t button, void *data) |
| 4284 | { |
Emilio Pozuelo Monfort | 38b58eb | 2014-01-29 11:11:12 +0100 | [diff] [blame] | 4285 | struct weston_surface *focus = seat->keyboard->focus; |
Rafael Antognolli | ea997ac | 2013-12-03 15:35:48 -0200 | [diff] [blame] | 4286 | struct weston_surface *surface; |
| 4287 | struct shell_surface *shsurf; |
| 4288 | |
| 4289 | surface = weston_surface_get_main_surface(focus); |
| 4290 | if (surface == NULL) |
| 4291 | return; |
| 4292 | |
| 4293 | shsurf = get_shell_surface(surface); |
| 4294 | if (shsurf == NULL) |
| 4295 | return; |
| 4296 | |
| 4297 | if (!shell_surface_is_xdg_surface(shsurf)) |
| 4298 | return; |
| 4299 | |
Jasper St. Pierre | ab2c108 | 2014-04-10 10:41:46 -0700 | [diff] [blame] | 4300 | shsurf->state_requested = true; |
| 4301 | shsurf->requested_state.fullscreen = !shsurf->state.fullscreen; |
Boyan Ding | 32abdbb | 2014-06-26 10:19:32 +0800 | [diff] [blame] | 4302 | shsurf->fullscreen_output = shsurf->output; |
Jasper St. Pierre | 9aa8ce6 | 2014-04-11 16:18:54 -0700 | [diff] [blame] | 4303 | send_configure_for_surface(shsurf); |
Rafael Antognolli | ea997ac | 2013-12-03 15:35:48 -0200 | [diff] [blame] | 4304 | } |
| 4305 | |
| 4306 | static void |
Neil Roberts | aba0f25 | 2013-10-03 16:43:05 +0100 | [diff] [blame] | 4307 | touch_move_binding(struct weston_seat *seat, uint32_t time, void *data) |
| 4308 | { |
Kristian Høgsberg | 7ab139c | 2013-10-24 16:21:39 -0700 | [diff] [blame] | 4309 | struct weston_surface *focus = seat->touch->focus->surface; |
Neil Roberts | aba0f25 | 2013-10-03 16:43:05 +0100 | [diff] [blame] | 4310 | struct weston_surface *surface; |
| 4311 | struct shell_surface *shsurf; |
| 4312 | |
| 4313 | surface = weston_surface_get_main_surface(focus); |
| 4314 | if (surface == NULL) |
| 4315 | return; |
| 4316 | |
| 4317 | shsurf = get_shell_surface(surface); |
Rafael Antognolli | 03b1659 | 2013-12-03 15:35:42 -0200 | [diff] [blame] | 4318 | if (shsurf == NULL || shsurf->state.fullscreen || |
| 4319 | shsurf->state.maximized) |
Neil Roberts | aba0f25 | 2013-10-03 16:43:05 +0100 | [diff] [blame] | 4320 | return; |
| 4321 | |
| 4322 | surface_touch_move(shsurf, (struct weston_seat *) seat); |
| 4323 | } |
| 4324 | |
| 4325 | static void |
Kristian Høgsberg | e314875 | 2013-05-06 23:19:49 -0400 | [diff] [blame] | 4326 | 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] | 4327 | { |
Rafal Mielniczuk | b2917a2 | 2014-01-05 20:04:59 +0100 | [diff] [blame] | 4328 | struct weston_surface *focus; |
Pekka Paalanen | 01388e2 | 2013-04-25 13:57:44 +0300 | [diff] [blame] | 4329 | struct weston_surface *surface; |
Kristian Høgsberg | 0793756 | 2011-04-12 17:25:42 -0400 | [diff] [blame] | 4330 | uint32_t edges = 0; |
| 4331 | int32_t x, y; |
Pekka Paalanen | 9d1613e | 2011-11-25 12:09:16 +0200 | [diff] [blame] | 4332 | struct shell_surface *shsurf; |
Kristian Høgsberg | d2abb83 | 2011-11-23 10:52:40 -0500 | [diff] [blame] | 4333 | |
Rafal Mielniczuk | b2917a2 | 2014-01-05 20:04:59 +0100 | [diff] [blame] | 4334 | if (seat->pointer->focus == NULL) |
| 4335 | return; |
| 4336 | |
| 4337 | focus = seat->pointer->focus->surface; |
| 4338 | |
Pekka Paalanen | 01388e2 | 2013-04-25 13:57:44 +0300 | [diff] [blame] | 4339 | surface = weston_surface_get_main_surface(focus); |
Benjamin Franzke | d0f79ab | 2011-11-22 12:43:52 +0100 | [diff] [blame] | 4340 | if (surface == NULL) |
| 4341 | return; |
Pekka Paalanen | 92a0dc4 | 2011-11-28 15:34:13 +0200 | [diff] [blame] | 4342 | |
Pekka Paalanen | 9d1613e | 2011-11-25 12:09:16 +0200 | [diff] [blame] | 4343 | shsurf = get_shell_surface(surface); |
Rafael Antognolli | 03b1659 | 2013-12-03 15:35:42 -0200 | [diff] [blame] | 4344 | if (shsurf == NULL || shsurf->state.fullscreen || |
| 4345 | shsurf->state.maximized) |
Pekka Paalanen | 92a0dc4 | 2011-11-28 15:34:13 +0200 | [diff] [blame] | 4346 | return; |
| 4347 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 4348 | weston_view_from_global(shsurf->view, |
| 4349 | wl_fixed_to_int(seat->pointer->grab_x), |
| 4350 | wl_fixed_to_int(seat->pointer->grab_y), |
| 4351 | &x, &y); |
Kristian Høgsberg | 0793756 | 2011-04-12 17:25:42 -0400 | [diff] [blame] | 4352 | |
Jason Ekstrand | 918f2dd | 2013-12-02 21:01:53 -0600 | [diff] [blame] | 4353 | if (x < shsurf->surface->width / 3) |
Pekka Paalanen | 9d1613e | 2011-11-25 12:09:16 +0200 | [diff] [blame] | 4354 | edges |= WL_SHELL_SURFACE_RESIZE_LEFT; |
Jason Ekstrand | 918f2dd | 2013-12-02 21:01:53 -0600 | [diff] [blame] | 4355 | else if (x < 2 * shsurf->surface->width / 3) |
Kristian Høgsberg | 0793756 | 2011-04-12 17:25:42 -0400 | [diff] [blame] | 4356 | edges |= 0; |
| 4357 | else |
Pekka Paalanen | 9d1613e | 2011-11-25 12:09:16 +0200 | [diff] [blame] | 4358 | edges |= WL_SHELL_SURFACE_RESIZE_RIGHT; |
Kristian Høgsberg | 0793756 | 2011-04-12 17:25:42 -0400 | [diff] [blame] | 4359 | |
Jason Ekstrand | 918f2dd | 2013-12-02 21:01:53 -0600 | [diff] [blame] | 4360 | if (y < shsurf->surface->height / 3) |
Pekka Paalanen | 9d1613e | 2011-11-25 12:09:16 +0200 | [diff] [blame] | 4361 | edges |= WL_SHELL_SURFACE_RESIZE_TOP; |
Jason Ekstrand | 918f2dd | 2013-12-02 21:01:53 -0600 | [diff] [blame] | 4362 | else if (y < 2 * shsurf->surface->height / 3) |
Kristian Høgsberg | 0793756 | 2011-04-12 17:25:42 -0400 | [diff] [blame] | 4363 | edges |= 0; |
| 4364 | else |
Pekka Paalanen | 9d1613e | 2011-11-25 12:09:16 +0200 | [diff] [blame] | 4365 | edges |= WL_SHELL_SURFACE_RESIZE_BOTTOM; |
Kristian Høgsberg | 0793756 | 2011-04-12 17:25:42 -0400 | [diff] [blame] | 4366 | |
Kristian Høgsberg | c1693f2 | 2012-05-22 16:56:23 -0400 | [diff] [blame] | 4367 | surface_resize(shsurf, (struct weston_seat *) seat, edges); |
Kristian Høgsberg | 02ec0a5 | 2011-04-23 13:04:11 -0400 | [diff] [blame] | 4368 | } |
| 4369 | |
| 4370 | static void |
Kristian Høgsberg | e314875 | 2013-05-06 23:19:49 -0400 | [diff] [blame] | 4371 | 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] | 4372 | wl_fixed_t value, void *data) |
Scott Moreau | a3aa9c9 | 2012-03-22 11:01:03 -0600 | [diff] [blame] | 4373 | { |
Jonas Ådahl | b0b87ba | 2012-09-27 18:40:42 +0200 | [diff] [blame] | 4374 | float step = 0.005; |
Scott Moreau | a3aa9c9 | 2012-03-22 11:01:03 -0600 | [diff] [blame] | 4375 | struct shell_surface *shsurf; |
Kristian Høgsberg | 7ab139c | 2013-10-24 16:21:39 -0700 | [diff] [blame] | 4376 | struct weston_surface *focus = seat->pointer->focus->surface; |
Pekka Paalanen | 01388e2 | 2013-04-25 13:57:44 +0300 | [diff] [blame] | 4377 | struct weston_surface *surface; |
Scott Moreau | a3aa9c9 | 2012-03-22 11:01:03 -0600 | [diff] [blame] | 4378 | |
Pekka Paalanen | 01388e2 | 2013-04-25 13:57:44 +0300 | [diff] [blame] | 4379 | /* XXX: broken for windows containing sub-surfaces */ |
| 4380 | surface = weston_surface_get_main_surface(focus); |
Scott Moreau | a3aa9c9 | 2012-03-22 11:01:03 -0600 | [diff] [blame] | 4381 | if (surface == NULL) |
| 4382 | return; |
| 4383 | |
| 4384 | shsurf = get_shell_surface(surface); |
| 4385 | if (!shsurf) |
| 4386 | return; |
| 4387 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 4388 | shsurf->view->alpha -= wl_fixed_to_double(value) * step; |
Scott Moreau | a3aa9c9 | 2012-03-22 11:01:03 -0600 | [diff] [blame] | 4389 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 4390 | if (shsurf->view->alpha > 1.0) |
| 4391 | shsurf->view->alpha = 1.0; |
| 4392 | if (shsurf->view->alpha < step) |
| 4393 | shsurf->view->alpha = step; |
Scott Moreau | a3aa9c9 | 2012-03-22 11:01:03 -0600 | [diff] [blame] | 4394 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 4395 | weston_view_geometry_dirty(shsurf->view); |
Scott Moreau | a3aa9c9 | 2012-03-22 11:01:03 -0600 | [diff] [blame] | 4396 | weston_surface_damage(surface); |
| 4397 | } |
| 4398 | |
| 4399 | static void |
Kristian Høgsberg | e314875 | 2013-05-06 23:19:49 -0400 | [diff] [blame] | 4400 | 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] | 4401 | wl_fixed_t value) |
Scott Moreau | ccbf29d | 2012-02-22 14:21:41 -0700 | [diff] [blame] | 4402 | { |
Daniel Stone | 37816df | 2012-05-16 18:45:18 +0100 | [diff] [blame] | 4403 | struct weston_seat *ws = (struct weston_seat *) seat; |
| 4404 | struct weston_compositor *compositor = ws->compositor; |
Scott Moreau | ccbf29d | 2012-02-22 14:21:41 -0700 | [diff] [blame] | 4405 | struct weston_output *output; |
Scott Moreau | e660398 | 2012-06-11 13:07:51 -0600 | [diff] [blame] | 4406 | float increment; |
Scott Moreau | ccbf29d | 2012-02-22 14:21:41 -0700 | [diff] [blame] | 4407 | |
| 4408 | wl_list_for_each(output, &compositor->output_list, link) { |
| 4409 | if (pixman_region32_contains_point(&output->region, |
Daniel Stone | 37816df | 2012-05-16 18:45:18 +0100 | [diff] [blame] | 4410 | wl_fixed_to_double(seat->pointer->x), |
| 4411 | wl_fixed_to_double(seat->pointer->y), |
Daniel Stone | 103db7f | 2012-05-08 17:17:55 +0100 | [diff] [blame] | 4412 | NULL)) { |
Daniel Stone | 325fc2d | 2012-05-30 16:31:58 +0100 | [diff] [blame] | 4413 | if (key == KEY_PAGEUP) |
Kristian Høgsberg | 9b68af0 | 2012-05-22 12:55:18 -0400 | [diff] [blame] | 4414 | increment = output->zoom.increment; |
Daniel Stone | 325fc2d | 2012-05-30 16:31:58 +0100 | [diff] [blame] | 4415 | else if (key == KEY_PAGEDOWN) |
Kristian Høgsberg | 9b68af0 | 2012-05-22 12:55:18 -0400 | [diff] [blame] | 4416 | increment = -output->zoom.increment; |
| 4417 | else if (axis == WL_POINTER_AXIS_VERTICAL_SCROLL) |
Jonas Ådahl | b0b87ba | 2012-09-27 18:40:42 +0200 | [diff] [blame] | 4418 | /* For every pixel zoom 20th of a step */ |
Daniel Stone | 0c1e46e | 2012-05-30 16:31:59 +0100 | [diff] [blame] | 4419 | increment = output->zoom.increment * |
Jonas Ådahl | b0b87ba | 2012-09-27 18:40:42 +0200 | [diff] [blame] | 4420 | -wl_fixed_to_double(value) / 20.0; |
Kristian Høgsberg | 9b68af0 | 2012-05-22 12:55:18 -0400 | [diff] [blame] | 4421 | else |
| 4422 | increment = 0; |
| 4423 | |
Kristian Høgsberg | 9b68af0 | 2012-05-22 12:55:18 -0400 | [diff] [blame] | 4424 | output->zoom.level += increment; |
Scott Moreau | c6d7f60 | 2012-02-23 22:28:37 -0700 | [diff] [blame] | 4425 | |
Scott Moreau | e660398 | 2012-06-11 13:07:51 -0600 | [diff] [blame] | 4426 | if (output->zoom.level < 0.0) |
Scott Moreau | 850ca42 | 2012-05-21 15:21:25 -0600 | [diff] [blame] | 4427 | output->zoom.level = 0.0; |
Scott Moreau | e660398 | 2012-06-11 13:07:51 -0600 | [diff] [blame] | 4428 | else if (output->zoom.level > output->zoom.max_level) |
| 4429 | output->zoom.level = output->zoom.max_level; |
Ville Syrjälä | aa628d0 | 2012-11-16 11:48:47 +0200 | [diff] [blame] | 4430 | else if (!output->zoom.active) { |
Giulio Camuffo | 412b024 | 2013-11-14 23:42:51 +0100 | [diff] [blame] | 4431 | weston_output_activate_zoom(output); |
Kristian Høgsberg | 79af73e | 2012-08-03 15:45:23 -0400 | [diff] [blame] | 4432 | } |
Scott Moreau | ccbf29d | 2012-02-22 14:21:41 -0700 | [diff] [blame] | 4433 | |
Scott Moreau | e660398 | 2012-06-11 13:07:51 -0600 | [diff] [blame] | 4434 | output->zoom.spring_z.target = output->zoom.level; |
Scott Moreau | ccbf29d | 2012-02-22 14:21:41 -0700 | [diff] [blame] | 4435 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 4436 | weston_output_update_zoom(output); |
Scott Moreau | ccbf29d | 2012-02-22 14:21:41 -0700 | [diff] [blame] | 4437 | } |
| 4438 | } |
| 4439 | } |
| 4440 | |
Scott Moreau | ccbf29d | 2012-02-22 14:21:41 -0700 | [diff] [blame] | 4441 | static void |
Kristian Høgsberg | e314875 | 2013-05-06 23:19:49 -0400 | [diff] [blame] | 4442 | 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] | 4443 | wl_fixed_t value, void *data) |
Daniel Stone | 325fc2d | 2012-05-30 16:31:58 +0100 | [diff] [blame] | 4444 | { |
| 4445 | do_zoom(seat, time, 0, axis, value); |
| 4446 | } |
| 4447 | |
| 4448 | static void |
Kristian Høgsberg | e314875 | 2013-05-06 23:19:49 -0400 | [diff] [blame] | 4449 | 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] | 4450 | void *data) |
| 4451 | { |
| 4452 | do_zoom(seat, time, key, 0, 0); |
| 4453 | } |
| 4454 | |
| 4455 | static void |
Kristian Høgsberg | e314875 | 2013-05-06 23:19:49 -0400 | [diff] [blame] | 4456 | terminate_binding(struct weston_seat *seat, uint32_t time, uint32_t key, |
Daniel Stone | 325fc2d | 2012-05-30 16:31:58 +0100 | [diff] [blame] | 4457 | void *data) |
Kristian Høgsberg | e1a850e | 2011-12-19 15:18:05 -0500 | [diff] [blame] | 4458 | { |
Kristian Høgsberg | 8334bc1 | 2012-01-03 10:29:47 -0500 | [diff] [blame] | 4459 | struct weston_compositor *compositor = data; |
Kristian Høgsberg | e1a850e | 2011-12-19 15:18:05 -0500 | [diff] [blame] | 4460 | |
Daniel Stone | 325fc2d | 2012-05-30 16:31:58 +0100 | [diff] [blame] | 4461 | wl_display_terminate(compositor->wl_display); |
Kristian Høgsberg | e1a850e | 2011-12-19 15:18:05 -0500 | [diff] [blame] | 4462 | } |
| 4463 | |
Emilio Pozuelo Monfort | 03251b6 | 2013-11-19 11:37:16 +0100 | [diff] [blame] | 4464 | static void |
Giulio Camuffo | 1959ab8 | 2013-11-14 23:42:52 +0100 | [diff] [blame] | 4465 | rotate_grab_motion(struct weston_pointer_grab *grab, uint32_t time, |
| 4466 | wl_fixed_t x, wl_fixed_t y) |
Pekka Paalanen | 460099f | 2012-01-20 16:48:25 +0200 | [diff] [blame] | 4467 | { |
| 4468 | struct rotate_grab *rotate = |
Ander Conselvan de Oliveira | fe0444a | 2012-04-04 17:48:05 +0300 | [diff] [blame] | 4469 | container_of(grab, struct rotate_grab, base.grab); |
Kristian Høgsberg | 02bbabb | 2013-05-06 22:15:05 -0400 | [diff] [blame] | 4470 | struct weston_pointer *pointer = grab->pointer; |
Ander Conselvan de Oliveira | fe0444a | 2012-04-04 17:48:05 +0300 | [diff] [blame] | 4471 | struct shell_surface *shsurf = rotate->base.shsurf; |
John Kåre Alsaker | 490d02a | 2012-09-30 02:57:21 +0200 | [diff] [blame] | 4472 | float cx, cy, dx, dy, cposx, cposy, dposx, dposy, r; |
Ander Conselvan de Oliveira | fe0444a | 2012-04-04 17:48:05 +0300 | [diff] [blame] | 4473 | |
Giulio Camuffo | 1959ab8 | 2013-11-14 23:42:52 +0100 | [diff] [blame] | 4474 | weston_pointer_move(pointer, x, y); |
| 4475 | |
Ander Conselvan de Oliveira | fe0444a | 2012-04-04 17:48:05 +0300 | [diff] [blame] | 4476 | if (!shsurf) |
| 4477 | return; |
| 4478 | |
Jason Ekstrand | 918f2dd | 2013-12-02 21:01:53 -0600 | [diff] [blame] | 4479 | cx = 0.5f * shsurf->surface->width; |
| 4480 | cy = 0.5f * shsurf->surface->height; |
Pekka Paalanen | 460099f | 2012-01-20 16:48:25 +0200 | [diff] [blame] | 4481 | |
Daniel Stone | 37816df | 2012-05-16 18:45:18 +0100 | [diff] [blame] | 4482 | dx = wl_fixed_to_double(pointer->x) - rotate->center.x; |
| 4483 | dy = wl_fixed_to_double(pointer->y) - rotate->center.y; |
Pekka Paalanen | 460099f | 2012-01-20 16:48:25 +0200 | [diff] [blame] | 4484 | r = sqrtf(dx * dx + dy * dy); |
| 4485 | |
Ander Conselvan de Oliveira | fe0444a | 2012-04-04 17:48:05 +0300 | [diff] [blame] | 4486 | wl_list_remove(&shsurf->rotation.transform.link); |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 4487 | weston_view_geometry_dirty(shsurf->view); |
Pekka Paalanen | 460099f | 2012-01-20 16:48:25 +0200 | [diff] [blame] | 4488 | |
| 4489 | if (r > 20.0f) { |
Pekka Paalanen | 460099f | 2012-01-20 16:48:25 +0200 | [diff] [blame] | 4490 | struct weston_matrix *matrix = |
Ander Conselvan de Oliveira | fe0444a | 2012-04-04 17:48:05 +0300 | [diff] [blame] | 4491 | &shsurf->rotation.transform.matrix; |
Pekka Paalanen | 460099f | 2012-01-20 16:48:25 +0200 | [diff] [blame] | 4492 | |
Kristian Høgsberg | 765e27b | 2012-01-27 13:36:13 -0500 | [diff] [blame] | 4493 | weston_matrix_init(&rotate->rotation); |
Vasily Khoruzhick | 1bbf372 | 2013-01-28 22:40:28 +0300 | [diff] [blame] | 4494 | weston_matrix_rotate_xy(&rotate->rotation, dx / r, dy / r); |
Pekka Paalanen | 460099f | 2012-01-20 16:48:25 +0200 | [diff] [blame] | 4495 | |
| 4496 | weston_matrix_init(matrix); |
Pekka Paalanen | 7b3bd3d | 2012-01-30 14:16:34 +0200 | [diff] [blame] | 4497 | weston_matrix_translate(matrix, -cx, -cy, 0.0f); |
Ander Conselvan de Oliveira | fe0444a | 2012-04-04 17:48:05 +0300 | [diff] [blame] | 4498 | weston_matrix_multiply(matrix, &shsurf->rotation.rotation); |
Kristian Høgsberg | 765e27b | 2012-01-27 13:36:13 -0500 | [diff] [blame] | 4499 | weston_matrix_multiply(matrix, &rotate->rotation); |
Pekka Paalanen | 7b3bd3d | 2012-01-30 14:16:34 +0200 | [diff] [blame] | 4500 | weston_matrix_translate(matrix, cx, cy, 0.0f); |
Pekka Paalanen | 460099f | 2012-01-20 16:48:25 +0200 | [diff] [blame] | 4501 | |
Pekka Paalanen | bc0b7e7 | 2012-01-24 09:53:37 +0200 | [diff] [blame] | 4502 | wl_list_insert( |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 4503 | &shsurf->view->geometry.transformation_list, |
Ander Conselvan de Oliveira | fe0444a | 2012-04-04 17:48:05 +0300 | [diff] [blame] | 4504 | &shsurf->rotation.transform.link); |
Pekka Paalanen | 460099f | 2012-01-20 16:48:25 +0200 | [diff] [blame] | 4505 | } else { |
Ander Conselvan de Oliveira | fe0444a | 2012-04-04 17:48:05 +0300 | [diff] [blame] | 4506 | wl_list_init(&shsurf->rotation.transform.link); |
| 4507 | weston_matrix_init(&shsurf->rotation.rotation); |
Kristian Høgsberg | 765e27b | 2012-01-27 13:36:13 -0500 | [diff] [blame] | 4508 | weston_matrix_init(&rotate->rotation); |
Pekka Paalanen | 460099f | 2012-01-20 16:48:25 +0200 | [diff] [blame] | 4509 | } |
Pekka Paalanen | b45ac5e | 2012-02-09 15:58:44 +0200 | [diff] [blame] | 4510 | |
Rafal Mielniczuk | 2d7ab82 | 2012-03-22 22:22:04 +0100 | [diff] [blame] | 4511 | /* We need to adjust the position of the surface |
| 4512 | * in case it was resized in a rotated state before */ |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 4513 | cposx = shsurf->view->geometry.x + cx; |
| 4514 | cposy = shsurf->view->geometry.y + cy; |
Rafal Mielniczuk | 2d7ab82 | 2012-03-22 22:22:04 +0100 | [diff] [blame] | 4515 | dposx = rotate->center.x - cposx; |
| 4516 | dposy = rotate->center.y - cposy; |
| 4517 | if (dposx != 0.0f || dposy != 0.0f) { |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 4518 | weston_view_set_position(shsurf->view, |
| 4519 | shsurf->view->geometry.x + dposx, |
| 4520 | shsurf->view->geometry.y + dposy); |
Rafal Mielniczuk | 2d7ab82 | 2012-03-22 22:22:04 +0100 | [diff] [blame] | 4521 | } |
| 4522 | |
Pekka Paalanen | b45ac5e | 2012-02-09 15:58:44 +0200 | [diff] [blame] | 4523 | /* Repaint implies weston_surface_update_transform(), which |
| 4524 | * lazily applies the damage due to rotation update. |
| 4525 | */ |
Ander Conselvan de Oliveira | fe0444a | 2012-04-04 17:48:05 +0300 | [diff] [blame] | 4526 | weston_compositor_schedule_repaint(shsurf->surface->compositor); |
Pekka Paalanen | 460099f | 2012-01-20 16:48:25 +0200 | [diff] [blame] | 4527 | } |
| 4528 | |
| 4529 | static void |
Kristian Høgsberg | 02bbabb | 2013-05-06 22:15:05 -0400 | [diff] [blame] | 4530 | rotate_grab_button(struct weston_pointer_grab *grab, |
| 4531 | uint32_t time, uint32_t button, uint32_t state_w) |
Pekka Paalanen | 460099f | 2012-01-20 16:48:25 +0200 | [diff] [blame] | 4532 | { |
| 4533 | struct rotate_grab *rotate = |
Ander Conselvan de Oliveira | fe0444a | 2012-04-04 17:48:05 +0300 | [diff] [blame] | 4534 | container_of(grab, struct rotate_grab, base.grab); |
Kristian Høgsberg | 02bbabb | 2013-05-06 22:15:05 -0400 | [diff] [blame] | 4535 | struct weston_pointer *pointer = grab->pointer; |
Ander Conselvan de Oliveira | fe0444a | 2012-04-04 17:48:05 +0300 | [diff] [blame] | 4536 | struct shell_surface *shsurf = rotate->base.shsurf; |
Daniel Stone | 4dbadb1 | 2012-05-30 16:31:51 +0100 | [diff] [blame] | 4537 | enum wl_pointer_button_state state = state_w; |
Pekka Paalanen | 460099f | 2012-01-20 16:48:25 +0200 | [diff] [blame] | 4538 | |
Daniel Stone | 4dbadb1 | 2012-05-30 16:31:51 +0100 | [diff] [blame] | 4539 | if (pointer->button_count == 0 && |
| 4540 | state == WL_POINTER_BUTTON_STATE_RELEASED) { |
Ander Conselvan de Oliveira | fe0444a | 2012-04-04 17:48:05 +0300 | [diff] [blame] | 4541 | if (shsurf) |
| 4542 | weston_matrix_multiply(&shsurf->rotation.rotation, |
| 4543 | &rotate->rotation); |
Ander Conselvan de Oliveira | b9d2a0f | 2012-06-28 18:08:05 +0300 | [diff] [blame] | 4544 | shell_grab_end(&rotate->base); |
Pekka Paalanen | 460099f | 2012-01-20 16:48:25 +0200 | [diff] [blame] | 4545 | free(rotate); |
| 4546 | } |
| 4547 | } |
| 4548 | |
Jonas Ådahl | 1ea343e | 2013-10-25 23:18:05 +0200 | [diff] [blame] | 4549 | static void |
| 4550 | rotate_grab_cancel(struct weston_pointer_grab *grab) |
| 4551 | { |
| 4552 | struct rotate_grab *rotate = |
| 4553 | container_of(grab, struct rotate_grab, base.grab); |
| 4554 | |
| 4555 | shell_grab_end(&rotate->base); |
| 4556 | free(rotate); |
| 4557 | } |
| 4558 | |
Kristian Høgsberg | 02bbabb | 2013-05-06 22:15:05 -0400 | [diff] [blame] | 4559 | static const struct weston_pointer_grab_interface rotate_grab_interface = { |
Pekka Paalanen | 460099f | 2012-01-20 16:48:25 +0200 | [diff] [blame] | 4560 | noop_grab_focus, |
| 4561 | rotate_grab_motion, |
| 4562 | rotate_grab_button, |
Jonas Ådahl | 1ea343e | 2013-10-25 23:18:05 +0200 | [diff] [blame] | 4563 | rotate_grab_cancel, |
Pekka Paalanen | 460099f | 2012-01-20 16:48:25 +0200 | [diff] [blame] | 4564 | }; |
| 4565 | |
| 4566 | static void |
Kristian Høgsberg | e314875 | 2013-05-06 23:19:49 -0400 | [diff] [blame] | 4567 | surface_rotate(struct shell_surface *surface, struct weston_seat *seat) |
Pekka Paalanen | 460099f | 2012-01-20 16:48:25 +0200 | [diff] [blame] | 4568 | { |
Pekka Paalanen | 460099f | 2012-01-20 16:48:25 +0200 | [diff] [blame] | 4569 | struct rotate_grab *rotate; |
John Kåre Alsaker | 490d02a | 2012-09-30 02:57:21 +0200 | [diff] [blame] | 4570 | float dx, dy; |
| 4571 | float r; |
Pekka Paalanen | 460099f | 2012-01-20 16:48:25 +0200 | [diff] [blame] | 4572 | |
Pekka Paalanen | 460099f | 2012-01-20 16:48:25 +0200 | [diff] [blame] | 4573 | rotate = malloc(sizeof *rotate); |
| 4574 | if (!rotate) |
| 4575 | return; |
| 4576 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 4577 | weston_view_to_global_float(surface->view, |
Jason Ekstrand | 918f2dd | 2013-12-02 21:01:53 -0600 | [diff] [blame] | 4578 | surface->surface->width * 0.5f, |
| 4579 | surface->surface->height * 0.5f, |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 4580 | &rotate->center.x, &rotate->center.y); |
Pekka Paalanen | 460099f | 2012-01-20 16:48:25 +0200 | [diff] [blame] | 4581 | |
Daniel Stone | 37816df | 2012-05-16 18:45:18 +0100 | [diff] [blame] | 4582 | dx = wl_fixed_to_double(seat->pointer->x) - rotate->center.x; |
| 4583 | dy = wl_fixed_to_double(seat->pointer->y) - rotate->center.y; |
Kristian Høgsberg | 765e27b | 2012-01-27 13:36:13 -0500 | [diff] [blame] | 4584 | r = sqrtf(dx * dx + dy * dy); |
| 4585 | if (r > 20.0f) { |
| 4586 | struct weston_matrix inverse; |
| 4587 | |
| 4588 | weston_matrix_init(&inverse); |
Vasily Khoruzhick | 1bbf372 | 2013-01-28 22:40:28 +0300 | [diff] [blame] | 4589 | weston_matrix_rotate_xy(&inverse, dx / r, -dy / r); |
Kristian Høgsberg | 765e27b | 2012-01-27 13:36:13 -0500 | [diff] [blame] | 4590 | weston_matrix_multiply(&surface->rotation.rotation, &inverse); |
Rafal Mielniczuk | 2d7ab82 | 2012-03-22 22:22:04 +0100 | [diff] [blame] | 4591 | |
| 4592 | weston_matrix_init(&rotate->rotation); |
Vasily Khoruzhick | 1bbf372 | 2013-01-28 22:40:28 +0300 | [diff] [blame] | 4593 | weston_matrix_rotate_xy(&rotate->rotation, dx / r, dy / r); |
Kristian Høgsberg | 765e27b | 2012-01-27 13:36:13 -0500 | [diff] [blame] | 4594 | } else { |
| 4595 | weston_matrix_init(&surface->rotation.rotation); |
| 4596 | weston_matrix_init(&rotate->rotation); |
| 4597 | } |
| 4598 | |
Ander Conselvan de Oliveira | b9d2a0f | 2012-06-28 18:08:05 +0300 | [diff] [blame] | 4599 | shell_grab_start(&rotate->base, &rotate_grab_interface, surface, |
| 4600 | seat->pointer, DESKTOP_SHELL_CURSOR_ARROW); |
Pekka Paalanen | 460099f | 2012-01-20 16:48:25 +0200 | [diff] [blame] | 4601 | } |
| 4602 | |
| 4603 | static void |
Kristian Høgsberg | e314875 | 2013-05-06 23:19:49 -0400 | [diff] [blame] | 4604 | 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] | 4605 | void *data) |
| 4606 | { |
Rafal Mielniczuk | b2917a2 | 2014-01-05 20:04:59 +0100 | [diff] [blame] | 4607 | struct weston_surface *focus; |
Pekka Paalanen | 01388e2 | 2013-04-25 13:57:44 +0300 | [diff] [blame] | 4608 | struct weston_surface *base_surface; |
Kristian Høgsberg | 0c36903 | 2013-02-14 21:31:44 -0500 | [diff] [blame] | 4609 | struct shell_surface *surface; |
| 4610 | |
Rafal Mielniczuk | b2917a2 | 2014-01-05 20:04:59 +0100 | [diff] [blame] | 4611 | if (seat->pointer->focus == NULL) |
| 4612 | return; |
| 4613 | |
| 4614 | focus = seat->pointer->focus->surface; |
| 4615 | |
Pekka Paalanen | 01388e2 | 2013-04-25 13:57:44 +0300 | [diff] [blame] | 4616 | base_surface = weston_surface_get_main_surface(focus); |
Kristian Høgsberg | 0c36903 | 2013-02-14 21:31:44 -0500 | [diff] [blame] | 4617 | if (base_surface == NULL) |
| 4618 | return; |
| 4619 | |
| 4620 | surface = get_shell_surface(base_surface); |
Rafael Antognolli | 03b1659 | 2013-12-03 15:35:42 -0200 | [diff] [blame] | 4621 | if (surface == NULL || surface->state.fullscreen || |
| 4622 | surface->state.maximized) |
Kristian Høgsberg | 0c36903 | 2013-02-14 21:31:44 -0500 | [diff] [blame] | 4623 | return; |
| 4624 | |
| 4625 | surface_rotate(surface, seat); |
| 4626 | } |
| 4627 | |
Emilio Pozuelo Monfort | 9e7c759 | 2014-01-30 14:01:10 +0100 | [diff] [blame] | 4628 | /* Move all fullscreen layers down to the current workspace and hide their |
| 4629 | * black views. The surfaces' state is set to both fullscreen and lowered, |
| 4630 | * and this is reversed when such a surface is re-configured, see |
| 4631 | * shell_configure_fullscreen() and shell_ensure_fullscreen_black_view(). |
| 4632 | * |
| 4633 | * This should be used when implementing shell-wide overlays, such as |
Philip Withnall | 83ffd9d | 2013-11-25 18:01:42 +0000 | [diff] [blame] | 4634 | * the alt-tab switcher, which need to de-promote fullscreen layers. */ |
Kristian Høgsberg | 1ef2313 | 2013-12-04 00:20:01 -0800 | [diff] [blame] | 4635 | void |
Kristian Høgsberg | b0d8e77 | 2012-06-18 16:34:58 -0400 | [diff] [blame] | 4636 | lower_fullscreen_layer(struct desktop_shell *shell) |
| 4637 | { |
| 4638 | struct workspace *ws; |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 4639 | struct weston_view *view, *prev; |
Kristian Høgsberg | b0d8e77 | 2012-06-18 16:34:58 -0400 | [diff] [blame] | 4640 | |
| 4641 | ws = get_current_workspace(shell); |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 4642 | wl_list_for_each_reverse_safe(view, prev, |
Giulio Camuffo | 412e6a5 | 2014-07-09 22:12:56 +0300 | [diff] [blame] | 4643 | &shell->fullscreen_layer.view_list.link, |
| 4644 | layer_link.link) { |
Emilio Pozuelo Monfort | 9e7c759 | 2014-01-30 14:01:10 +0100 | [diff] [blame] | 4645 | struct shell_surface *shsurf = get_shell_surface(view->surface); |
| 4646 | |
| 4647 | if (!shsurf) |
| 4648 | continue; |
| 4649 | |
| 4650 | /* We can have a non-fullscreen popup for a fullscreen surface |
| 4651 | * in the fullscreen layer. */ |
| 4652 | if (shsurf->state.fullscreen) { |
| 4653 | /* Hide the black view */ |
Giulio Camuffo | 412e6a5 | 2014-07-09 22:12:56 +0300 | [diff] [blame] | 4654 | weston_layer_entry_remove(&shsurf->fullscreen.black_view->layer_link); |
| 4655 | wl_list_init(&shsurf->fullscreen.black_view->layer_link.link); |
Kristian Høgsberg | c991513 | 2014-05-09 16:24:07 -0700 | [diff] [blame] | 4656 | weston_view_damage_below(shsurf->fullscreen.black_view); |
| 4657 | |
Emilio Pozuelo Monfort | 9e7c759 | 2014-01-30 14:01:10 +0100 | [diff] [blame] | 4658 | } |
| 4659 | |
| 4660 | /* Lower the view to the workspace layer */ |
Giulio Camuffo | 412e6a5 | 2014-07-09 22:12:56 +0300 | [diff] [blame] | 4661 | weston_layer_entry_remove(&view->layer_link); |
| 4662 | weston_layer_entry_insert(&ws->layer.view_list, &view->layer_link); |
Philip Withnall | 83ffd9d | 2013-11-25 18:01:42 +0000 | [diff] [blame] | 4663 | weston_view_damage_below(view); |
| 4664 | weston_surface_damage(view->surface); |
Emilio Pozuelo Monfort | 9e7c759 | 2014-01-30 14:01:10 +0100 | [diff] [blame] | 4665 | |
| 4666 | shsurf->state.lowered = true; |
Philip Withnall | 83ffd9d | 2013-11-25 18:01:42 +0000 | [diff] [blame] | 4667 | } |
Kristian Høgsberg | b0d8e77 | 2012-06-18 16:34:58 -0400 | [diff] [blame] | 4668 | } |
| 4669 | |
Kristian Høgsberg | 1ef2313 | 2013-12-04 00:20:01 -0800 | [diff] [blame] | 4670 | void |
Tiago Vignatti | be14326 | 2012-04-16 17:31:41 +0300 | [diff] [blame] | 4671 | activate(struct desktop_shell *shell, struct weston_surface *es, |
Emilio Pozuelo Monfort | 9e7c759 | 2014-01-30 14:01:10 +0100 | [diff] [blame] | 4672 | struct weston_seat *seat, bool configure) |
Kristian Høgsberg | 7584062 | 2011-09-06 13:48:16 -0400 | [diff] [blame] | 4673 | { |
Pekka Paalanen | 01388e2 | 2013-04-25 13:57:44 +0300 | [diff] [blame] | 4674 | struct weston_surface *main_surface; |
Kristian Høgsberg | 2f5faff | 2012-07-31 16:36:34 -0400 | [diff] [blame] | 4675 | struct focus_state *state; |
Jonas Ådahl | 8538b22 | 2012-08-29 22:13:03 +0200 | [diff] [blame] | 4676 | struct workspace *ws; |
Louis-Francis Ratté-Boulianne | b482dbd | 2013-11-19 11:37:11 +0100 | [diff] [blame] | 4677 | struct weston_surface *old_es; |
Rafael Antognolli | 03b1659 | 2013-12-03 15:35:42 -0200 | [diff] [blame] | 4678 | struct shell_surface *shsurf; |
Kristian Høgsberg | 7584062 | 2011-09-06 13:48:16 -0400 | [diff] [blame] | 4679 | |
Kristian Høgsberg | 6110d07 | 2014-04-29 15:15:45 -0700 | [diff] [blame] | 4680 | lower_fullscreen_layer(shell); |
| 4681 | |
Pekka Paalanen | 01388e2 | 2013-04-25 13:57:44 +0300 | [diff] [blame] | 4682 | main_surface = weston_surface_get_main_surface(es); |
| 4683 | |
Daniel Stone | 37816df | 2012-05-16 18:45:18 +0100 | [diff] [blame] | 4684 | weston_surface_activate(es, seat); |
Kristian Høgsberg | 7584062 | 2011-09-06 13:48:16 -0400 | [diff] [blame] | 4685 | |
Jonas Ådahl | 8538b22 | 2012-08-29 22:13:03 +0200 | [diff] [blame] | 4686 | state = ensure_focus_state(shell, seat); |
| 4687 | if (state == NULL) |
| 4688 | return; |
Kristian Høgsberg | 2f5faff | 2012-07-31 16:36:34 -0400 | [diff] [blame] | 4689 | |
Louis-Francis Ratté-Boulianne | b482dbd | 2013-11-19 11:37:11 +0100 | [diff] [blame] | 4690 | old_es = state->keyboard_focus; |
Kristian Høgsberg | d500bf1 | 2014-01-22 12:25:20 -0800 | [diff] [blame] | 4691 | focus_state_set_focus(state, es); |
Kristian Høgsberg | 2f5faff | 2012-07-31 16:36:34 -0400 | [diff] [blame] | 4692 | |
Rafael Antognolli | 03b1659 | 2013-12-03 15:35:42 -0200 | [diff] [blame] | 4693 | shsurf = get_shell_surface(main_surface); |
U. Artie Eoff | cf5737a | 2014-01-17 10:08:25 -0800 | [diff] [blame] | 4694 | assert(shsurf); |
| 4695 | |
Emilio Pozuelo Monfort | 9e7c759 | 2014-01-30 14:01:10 +0100 | [diff] [blame] | 4696 | if (shsurf->state.fullscreen && configure) |
Rafael Antognolli | 03b1659 | 2013-12-03 15:35:42 -0200 | [diff] [blame] | 4697 | shell_configure_fullscreen(shsurf); |
| 4698 | else |
Alexander Larsson | f82b6ca | 2013-05-28 16:23:39 +0200 | [diff] [blame] | 4699 | restore_all_output_modes(shell->compositor); |
Louis-Francis Ratté-Boulianne | b482dbd | 2013-11-19 11:37:11 +0100 | [diff] [blame] | 4700 | |
Emilio Pozuelo Monfort | 7908bff | 2014-01-30 13:49:39 +0100 | [diff] [blame] | 4701 | /* Update the surface’s layer. This brings it to the top of the stacking |
| 4702 | * order as appropriate. */ |
| 4703 | shell_surface_update_layer(shsurf); |
| 4704 | |
Philip Withnall | 83ffd9d | 2013-11-25 18:01:42 +0000 | [diff] [blame] | 4705 | if (shell->focus_animation_type != ANIMATION_NONE) { |
| 4706 | ws = get_current_workspace(shell); |
Louis-Francis Ratté-Boulianne | b482dbd | 2013-11-19 11:37:11 +0100 | [diff] [blame] | 4707 | 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] | 4708 | } |
Kristian Høgsberg | 7584062 | 2011-09-06 13:48:16 -0400 | [diff] [blame] | 4709 | } |
| 4710 | |
Alex Wu | 2185843 | 2012-04-01 20:13:08 +0800 | [diff] [blame] | 4711 | /* no-op func for checking black surface */ |
| 4712 | static void |
Jason Ekstrand | 918f2dd | 2013-12-02 21:01:53 -0600 | [diff] [blame] | 4713 | 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] | 4714 | { |
| 4715 | } |
| 4716 | |
Quentin Glidic | c0d79ce | 2013-01-29 14:16:13 +0100 | [diff] [blame] | 4717 | static bool |
Alex Wu | 2185843 | 2012-04-01 20:13:08 +0800 | [diff] [blame] | 4718 | is_black_surface (struct weston_surface *es, struct weston_surface **fs_surface) |
| 4719 | { |
| 4720 | if (es->configure == black_surface_configure) { |
| 4721 | if (fs_surface) |
Giulio Camuffo | 7fe01b1 | 2013-03-28 18:02:42 +0100 | [diff] [blame] | 4722 | *fs_surface = (struct weston_surface *)es->configure_private; |
Alex Wu | 2185843 | 2012-04-01 20:13:08 +0800 | [diff] [blame] | 4723 | return true; |
| 4724 | } |
| 4725 | return false; |
| 4726 | } |
| 4727 | |
Kristian Høgsberg | 7584062 | 2011-09-06 13:48:16 -0400 | [diff] [blame] | 4728 | static void |
Neil Roberts | a28c693 | 2013-10-03 16:43:04 +0100 | [diff] [blame] | 4729 | activate_binding(struct weston_seat *seat, |
| 4730 | struct desktop_shell *shell, |
| 4731 | struct weston_surface *focus) |
Kristian Høgsberg | e1a850e | 2011-12-19 15:18:05 -0500 | [diff] [blame] | 4732 | { |
Pekka Paalanen | 01388e2 | 2013-04-25 13:57:44 +0300 | [diff] [blame] | 4733 | struct weston_surface *main_surface; |
Kristian Høgsberg | e1a850e | 2011-12-19 15:18:05 -0500 | [diff] [blame] | 4734 | |
Alex Wu | 9c35e6b | 2012-03-05 14:13:13 +0800 | [diff] [blame] | 4735 | if (!focus) |
| 4736 | return; |
| 4737 | |
Pekka Paalanen | 01388e2 | 2013-04-25 13:57:44 +0300 | [diff] [blame] | 4738 | if (is_black_surface(focus, &main_surface)) |
| 4739 | focus = main_surface; |
Alex Wu | 4539b08 | 2012-03-01 12:57:46 +0800 | [diff] [blame] | 4740 | |
Pekka Paalanen | 01388e2 | 2013-04-25 13:57:44 +0300 | [diff] [blame] | 4741 | main_surface = weston_surface_get_main_surface(focus); |
| 4742 | if (get_shell_surface_type(main_surface) == SHELL_SURFACE_NONE) |
Kristian Høgsberg | 0636ac3 | 2012-06-27 10:22:15 -0400 | [diff] [blame] | 4743 | return; |
Kristian Høgsberg | 85b2e4b | 2012-06-21 16:49:42 -0400 | [diff] [blame] | 4744 | |
Emilio Pozuelo Monfort | 9e7c759 | 2014-01-30 14:01:10 +0100 | [diff] [blame] | 4745 | activate(shell, focus, seat, true); |
Neil Roberts | a28c693 | 2013-10-03 16:43:04 +0100 | [diff] [blame] | 4746 | } |
| 4747 | |
| 4748 | static void |
| 4749 | click_to_activate_binding(struct weston_seat *seat, uint32_t time, uint32_t button, |
| 4750 | void *data) |
| 4751 | { |
| 4752 | if (seat->pointer->grab != &seat->pointer->default_grab) |
| 4753 | return; |
Kristian Høgsberg | 7c4f6cc | 2014-01-01 16:28:32 -0800 | [diff] [blame] | 4754 | if (seat->pointer->focus == NULL) |
| 4755 | return; |
Neil Roberts | a28c693 | 2013-10-03 16:43:04 +0100 | [diff] [blame] | 4756 | |
Kristian Høgsberg | 7ab139c | 2013-10-24 16:21:39 -0700 | [diff] [blame] | 4757 | activate_binding(seat, data, seat->pointer->focus->surface); |
Neil Roberts | a28c693 | 2013-10-03 16:43:04 +0100 | [diff] [blame] | 4758 | } |
| 4759 | |
| 4760 | static void |
| 4761 | touch_to_activate_binding(struct weston_seat *seat, uint32_t time, void *data) |
| 4762 | { |
| 4763 | if (seat->touch->grab != &seat->touch->default_grab) |
| 4764 | return; |
Kristian Høgsberg | 0ed6750 | 2014-01-02 23:00:11 -0800 | [diff] [blame] | 4765 | if (seat->touch->focus == NULL) |
| 4766 | return; |
Neil Roberts | a28c693 | 2013-10-03 16:43:04 +0100 | [diff] [blame] | 4767 | |
Kristian Høgsberg | 7ab139c | 2013-10-24 16:21:39 -0700 | [diff] [blame] | 4768 | activate_binding(seat, data, seat->touch->focus->surface); |
Kristian Høgsberg | e1a850e | 2011-12-19 15:18:05 -0500 | [diff] [blame] | 4769 | } |
| 4770 | |
| 4771 | static void |
Neil Roberts | b4a9170 | 2014-04-09 16:33:32 +0100 | [diff] [blame] | 4772 | unfocus_all_seats(struct desktop_shell *shell) |
| 4773 | { |
| 4774 | struct weston_seat *seat, *next; |
| 4775 | |
| 4776 | wl_list_for_each_safe(seat, next, &shell->compositor->seat_list, link) { |
| 4777 | if (seat->keyboard == NULL) |
| 4778 | continue; |
| 4779 | |
| 4780 | weston_keyboard_set_focus(seat->keyboard, NULL); |
| 4781 | } |
| 4782 | } |
| 4783 | |
| 4784 | static void |
Ander Conselvan de Oliveira | 19d10ef | 2013-02-21 18:35:20 +0200 | [diff] [blame] | 4785 | lock(struct desktop_shell *shell) |
Kristian Høgsberg | 02ec0a5 | 2011-04-23 13:04:11 -0400 | [diff] [blame] | 4786 | { |
Kristian Høgsberg | 4476aaf | 2012-06-25 14:03:13 -0400 | [diff] [blame] | 4787 | struct workspace *ws = get_current_workspace(shell); |
Pekka Paalanen | f0fc70d | 2011-11-15 13:34:54 +0200 | [diff] [blame] | 4788 | |
Tiago Vignatti | 8e53c7f | 2012-02-29 19:53:50 +0200 | [diff] [blame] | 4789 | if (shell->locked) { |
Ander Conselvan de Oliveira | 87524b6 | 2013-02-21 18:35:22 +0200 | [diff] [blame] | 4790 | weston_compositor_sleep(shell->compositor); |
Pekka Paalanen | f0fc70d | 2011-11-15 13:34:54 +0200 | [diff] [blame] | 4791 | return; |
Tiago Vignatti | 8e53c7f | 2012-02-29 19:53:50 +0200 | [diff] [blame] | 4792 | } |
Pekka Paalanen | 9ef3e01 | 2011-11-15 13:34:48 +0200 | [diff] [blame] | 4793 | |
| 4794 | shell->locked = true; |
Pekka Paalanen | f0fc70d | 2011-11-15 13:34:54 +0200 | [diff] [blame] | 4795 | |
Kristian Høgsberg | 3be2ce9 | 2012-02-29 12:42:35 -0500 | [diff] [blame] | 4796 | /* Hide all surfaces by removing the fullscreen, panel and |
| 4797 | * toplevel layers. This way nothing else can show or receive |
| 4798 | * input events while we are locked. */ |
Pekka Paalanen | f0fc70d | 2011-11-15 13:34:54 +0200 | [diff] [blame] | 4799 | |
Kristian Høgsberg | 3be2ce9 | 2012-02-29 12:42:35 -0500 | [diff] [blame] | 4800 | wl_list_remove(&shell->panel_layer.link); |
Kristian Høgsberg | 3be2ce9 | 2012-02-29 12:42:35 -0500 | [diff] [blame] | 4801 | wl_list_remove(&shell->fullscreen_layer.link); |
Philipp Brüschweiler | 711fda8 | 2012-08-09 18:50:43 +0200 | [diff] [blame] | 4802 | if (shell->showing_input_panels) |
| 4803 | wl_list_remove(&shell->input_panel_layer.link); |
Kristian Høgsberg | 4476aaf | 2012-06-25 14:03:13 -0400 | [diff] [blame] | 4804 | wl_list_remove(&ws->layer.link); |
Kristian Høgsberg | 3be2ce9 | 2012-02-29 12:42:35 -0500 | [diff] [blame] | 4805 | wl_list_insert(&shell->compositor->cursor_layer.link, |
| 4806 | &shell->lock_layer.link); |
Pekka Paalanen | f0fc70d | 2011-11-15 13:34:54 +0200 | [diff] [blame] | 4807 | |
Pekka Paalanen | 77346a6 | 2011-11-30 16:26:35 +0200 | [diff] [blame] | 4808 | launch_screensaver(shell); |
| 4809 | |
Neil Roberts | b4a9170 | 2014-04-09 16:33:32 +0100 | [diff] [blame] | 4810 | /* Remove the keyboard focus on all seats. This will be |
| 4811 | * restored to the workspace's saved state via |
| 4812 | * restore_focus_state when the compositor is unlocked */ |
| 4813 | unfocus_all_seats(shell); |
| 4814 | |
Pekka Paalanen | f0fc70d | 2011-11-15 13:34:54 +0200 | [diff] [blame] | 4815 | /* TODO: disable bindings that should not work while locked. */ |
| 4816 | |
| 4817 | /* All this must be undone in resume_desktop(). */ |
Pekka Paalanen | 9ef3e01 | 2011-11-15 13:34:48 +0200 | [diff] [blame] | 4818 | } |
| 4819 | |
| 4820 | static void |
Ander Conselvan de Oliveira | 19d10ef | 2013-02-21 18:35:20 +0200 | [diff] [blame] | 4821 | unlock(struct desktop_shell *shell) |
Pekka Paalanen | 9ef3e01 | 2011-11-15 13:34:48 +0200 | [diff] [blame] | 4822 | { |
Pekka Paalanen | d81c216 | 2011-11-16 13:47:34 +0200 | [diff] [blame] | 4823 | if (!shell->locked || shell->lock_surface) { |
Ander Conselvan de Oliveira | 87524b6 | 2013-02-21 18:35:22 +0200 | [diff] [blame] | 4824 | shell_fade(shell, FADE_IN); |
Pekka Paalanen | 9ef3e01 | 2011-11-15 13:34:48 +0200 | [diff] [blame] | 4825 | return; |
| 4826 | } |
| 4827 | |
| 4828 | /* If desktop-shell client has gone away, unlock immediately. */ |
| 4829 | if (!shell->child.desktop_shell) { |
Pekka Paalanen | f0fc70d | 2011-11-15 13:34:54 +0200 | [diff] [blame] | 4830 | resume_desktop(shell); |
Pekka Paalanen | 9ef3e01 | 2011-11-15 13:34:48 +0200 | [diff] [blame] | 4831 | return; |
| 4832 | } |
| 4833 | |
| 4834 | if (shell->prepare_event_sent) |
| 4835 | return; |
| 4836 | |
Kristian Høgsberg | 0b5cd0c | 2012-03-04 21:57:37 -0500 | [diff] [blame] | 4837 | desktop_shell_send_prepare_lock_surface(shell->child.desktop_shell); |
Pekka Paalanen | 9ef3e01 | 2011-11-15 13:34:48 +0200 | [diff] [blame] | 4838 | shell->prepare_event_sent = true; |
Kristian Høgsberg | 02ec0a5 | 2011-04-23 13:04:11 -0400 | [diff] [blame] | 4839 | } |
| 4840 | |
| 4841 | static void |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 4842 | shell_fade_done(struct weston_view_animation *animation, void *data) |
Ander Conselvan de Oliveira | 19d10ef | 2013-02-21 18:35:20 +0200 | [diff] [blame] | 4843 | { |
| 4844 | struct desktop_shell *shell = data; |
| 4845 | |
| 4846 | shell->fade.animation = NULL; |
| 4847 | |
| 4848 | switch (shell->fade.type) { |
| 4849 | case FADE_IN: |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 4850 | weston_surface_destroy(shell->fade.view->surface); |
| 4851 | shell->fade.view = NULL; |
Ander Conselvan de Oliveira | 19d10ef | 2013-02-21 18:35:20 +0200 | [diff] [blame] | 4852 | break; |
| 4853 | case FADE_OUT: |
Ander Conselvan de Oliveira | 19d10ef | 2013-02-21 18:35:20 +0200 | [diff] [blame] | 4854 | lock(shell); |
| 4855 | break; |
Philip Withnall | 4a86a0a | 2013-11-25 18:01:32 +0000 | [diff] [blame] | 4856 | default: |
| 4857 | break; |
Ander Conselvan de Oliveira | 19d10ef | 2013-02-21 18:35:20 +0200 | [diff] [blame] | 4858 | } |
| 4859 | } |
| 4860 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 4861 | static struct weston_view * |
Pekka Paalanen | 79346ab | 2013-05-22 18:03:09 +0300 | [diff] [blame] | 4862 | shell_fade_create_surface(struct desktop_shell *shell) |
Ander Conselvan de Oliveira | 19d10ef | 2013-02-21 18:35:20 +0200 | [diff] [blame] | 4863 | { |
| 4864 | struct weston_compositor *compositor = shell->compositor; |
| 4865 | struct weston_surface *surface; |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 4866 | struct weston_view *view; |
Pekka Paalanen | 79346ab | 2013-05-22 18:03:09 +0300 | [diff] [blame] | 4867 | |
| 4868 | surface = weston_surface_create(compositor); |
| 4869 | if (!surface) |
| 4870 | return NULL; |
| 4871 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 4872 | view = weston_view_create(surface); |
| 4873 | if (!view) { |
| 4874 | weston_surface_destroy(surface); |
| 4875 | return NULL; |
| 4876 | } |
| 4877 | |
Jason Ekstrand | 5c11a33 | 2013-12-04 20:32:03 -0600 | [diff] [blame] | 4878 | weston_surface_set_size(surface, 8192, 8192); |
Jason Ekstrand | 918f2dd | 2013-12-02 21:01:53 -0600 | [diff] [blame] | 4879 | weston_view_set_position(view, 0, 0); |
Pekka Paalanen | 79346ab | 2013-05-22 18:03:09 +0300 | [diff] [blame] | 4880 | 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] | 4881 | weston_layer_entry_insert(&compositor->fade_layer.view_list, |
| 4882 | &view->layer_link); |
Pekka Paalanen | 79346ab | 2013-05-22 18:03:09 +0300 | [diff] [blame] | 4883 | pixman_region32_init(&surface->input); |
| 4884 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 4885 | return view; |
Pekka Paalanen | 79346ab | 2013-05-22 18:03:09 +0300 | [diff] [blame] | 4886 | } |
| 4887 | |
| 4888 | static void |
| 4889 | shell_fade(struct desktop_shell *shell, enum fade_type type) |
| 4890 | { |
Ander Conselvan de Oliveira | 19d10ef | 2013-02-21 18:35:20 +0200 | [diff] [blame] | 4891 | float tint; |
| 4892 | |
| 4893 | switch (type) { |
| 4894 | case FADE_IN: |
| 4895 | tint = 0.0; |
| 4896 | break; |
| 4897 | case FADE_OUT: |
| 4898 | tint = 1.0; |
| 4899 | break; |
| 4900 | default: |
| 4901 | weston_log("shell: invalid fade type\n"); |
| 4902 | return; |
| 4903 | } |
| 4904 | |
| 4905 | shell->fade.type = type; |
| 4906 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 4907 | if (shell->fade.view == NULL) { |
| 4908 | shell->fade.view = shell_fade_create_surface(shell); |
| 4909 | if (!shell->fade.view) |
Ander Conselvan de Oliveira | 19d10ef | 2013-02-21 18:35:20 +0200 | [diff] [blame] | 4910 | return; |
| 4911 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 4912 | shell->fade.view->alpha = 1.0 - tint; |
| 4913 | weston_view_update_transform(shell->fade.view); |
Ander Conselvan de Oliveira | 19d10ef | 2013-02-21 18:35:20 +0200 | [diff] [blame] | 4914 | } |
| 4915 | |
Kristian Høgsberg | 87d3b61 | 2014-01-19 21:48:10 -0800 | [diff] [blame] | 4916 | if (shell->fade.view->output == NULL) { |
| 4917 | /* If the black view gets a NULL output, we lost the |
| 4918 | * last output and we'll just cancel the fade. This |
| 4919 | * happens when you close the last window under the |
| 4920 | * X11 or Wayland backends. */ |
| 4921 | shell->locked = false; |
| 4922 | weston_surface_destroy(shell->fade.view->surface); |
| 4923 | shell->fade.view = NULL; |
| 4924 | } else if (shell->fade.animation) { |
Kristian Høgsberg | 5281fb1 | 2013-06-17 10:10:28 -0400 | [diff] [blame] | 4925 | weston_fade_update(shell->fade.animation, tint); |
Kristian Høgsberg | 87d3b61 | 2014-01-19 21:48:10 -0800 | [diff] [blame] | 4926 | } else { |
Ander Conselvan de Oliveira | 19d10ef | 2013-02-21 18:35:20 +0200 | [diff] [blame] | 4927 | shell->fade.animation = |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 4928 | weston_fade_run(shell->fade.view, |
Kristian Høgsberg | 5281fb1 | 2013-06-17 10:10:28 -0400 | [diff] [blame] | 4929 | 1.0 - tint, tint, 300.0, |
Ander Conselvan de Oliveira | 19d10ef | 2013-02-21 18:35:20 +0200 | [diff] [blame] | 4930 | shell_fade_done, shell); |
Kristian Høgsberg | 87d3b61 | 2014-01-19 21:48:10 -0800 | [diff] [blame] | 4931 | } |
Ander Conselvan de Oliveira | 19d10ef | 2013-02-21 18:35:20 +0200 | [diff] [blame] | 4932 | } |
| 4933 | |
| 4934 | static void |
Pekka Paalanen | 79346ab | 2013-05-22 18:03:09 +0300 | [diff] [blame] | 4935 | do_shell_fade_startup(void *data) |
| 4936 | { |
| 4937 | struct desktop_shell *shell = data; |
| 4938 | |
Kristian Høgsberg | 724c8d9 | 2013-10-16 11:38:24 -0700 | [diff] [blame] | 4939 | if (shell->startup_animation_type == ANIMATION_FADE) |
| 4940 | shell_fade(shell, FADE_IN); |
| 4941 | else if (shell->startup_animation_type == ANIMATION_NONE) { |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 4942 | weston_surface_destroy(shell->fade.view->surface); |
| 4943 | shell->fade.view = NULL; |
Kristian Høgsberg | 724c8d9 | 2013-10-16 11:38:24 -0700 | [diff] [blame] | 4944 | } |
Pekka Paalanen | 79346ab | 2013-05-22 18:03:09 +0300 | [diff] [blame] | 4945 | } |
| 4946 | |
| 4947 | static void |
| 4948 | shell_fade_startup(struct desktop_shell *shell) |
| 4949 | { |
| 4950 | struct wl_event_loop *loop; |
| 4951 | |
| 4952 | if (!shell->fade.startup_timer) |
| 4953 | return; |
| 4954 | |
| 4955 | wl_event_source_remove(shell->fade.startup_timer); |
| 4956 | shell->fade.startup_timer = NULL; |
| 4957 | |
| 4958 | loop = wl_display_get_event_loop(shell->compositor->wl_display); |
| 4959 | wl_event_loop_add_idle(loop, do_shell_fade_startup, shell); |
| 4960 | } |
| 4961 | |
| 4962 | static int |
| 4963 | fade_startup_timeout(void *data) |
| 4964 | { |
| 4965 | struct desktop_shell *shell = data; |
| 4966 | |
| 4967 | shell_fade_startup(shell); |
| 4968 | return 0; |
| 4969 | } |
| 4970 | |
| 4971 | static void |
| 4972 | shell_fade_init(struct desktop_shell *shell) |
| 4973 | { |
| 4974 | /* Make compositor output all black, and wait for the desktop-shell |
| 4975 | * client to signal it is ready, then fade in. The timer triggers a |
| 4976 | * fade-in, in case the desktop-shell client takes too long. |
| 4977 | */ |
| 4978 | |
| 4979 | struct wl_event_loop *loop; |
| 4980 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 4981 | if (shell->fade.view != NULL) { |
Pekka Paalanen | 79346ab | 2013-05-22 18:03:09 +0300 | [diff] [blame] | 4982 | weston_log("%s: warning: fade surface already exists\n", |
| 4983 | __func__); |
| 4984 | return; |
| 4985 | } |
| 4986 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 4987 | shell->fade.view = shell_fade_create_surface(shell); |
| 4988 | if (!shell->fade.view) |
Pekka Paalanen | 79346ab | 2013-05-22 18:03:09 +0300 | [diff] [blame] | 4989 | return; |
| 4990 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 4991 | weston_view_update_transform(shell->fade.view); |
| 4992 | weston_surface_damage(shell->fade.view->surface); |
Pekka Paalanen | 79346ab | 2013-05-22 18:03:09 +0300 | [diff] [blame] | 4993 | |
| 4994 | loop = wl_display_get_event_loop(shell->compositor->wl_display); |
| 4995 | shell->fade.startup_timer = |
| 4996 | wl_event_loop_add_timer(loop, fade_startup_timeout, shell); |
| 4997 | wl_event_source_timer_update(shell->fade.startup_timer, 15000); |
| 4998 | } |
| 4999 | |
| 5000 | static void |
Ander Conselvan de Oliveira | a457563 | 2013-02-21 18:35:23 +0200 | [diff] [blame] | 5001 | idle_handler(struct wl_listener *listener, void *data) |
Ander Conselvan de Oliveira | 19d10ef | 2013-02-21 18:35:20 +0200 | [diff] [blame] | 5002 | { |
| 5003 | struct desktop_shell *shell = |
Ander Conselvan de Oliveira | a457563 | 2013-02-21 18:35:23 +0200 | [diff] [blame] | 5004 | container_of(listener, struct desktop_shell, idle_listener); |
Kristian Høgsberg | 27d5fa8 | 2014-01-17 16:22:50 -0800 | [diff] [blame] | 5005 | struct weston_seat *seat; |
| 5006 | |
| 5007 | wl_list_for_each(seat, &shell->compositor->seat_list, link) |
| 5008 | if (seat->pointer) |
| 5009 | popup_grab_end(seat->pointer); |
Ander Conselvan de Oliveira | 19d10ef | 2013-02-21 18:35:20 +0200 | [diff] [blame] | 5010 | |
| 5011 | shell_fade(shell, FADE_OUT); |
| 5012 | /* lock() is called from shell_fade_done() */ |
| 5013 | } |
| 5014 | |
| 5015 | static void |
Ander Conselvan de Oliveira | a457563 | 2013-02-21 18:35:23 +0200 | [diff] [blame] | 5016 | wake_handler(struct wl_listener *listener, void *data) |
Ander Conselvan de Oliveira | 19d10ef | 2013-02-21 18:35:20 +0200 | [diff] [blame] | 5017 | { |
| 5018 | struct desktop_shell *shell = |
Ander Conselvan de Oliveira | a457563 | 2013-02-21 18:35:23 +0200 | [diff] [blame] | 5019 | container_of(listener, struct desktop_shell, wake_listener); |
Ander Conselvan de Oliveira | 19d10ef | 2013-02-21 18:35:20 +0200 | [diff] [blame] | 5020 | |
Ander Conselvan de Oliveira | 19d10ef | 2013-02-21 18:35:20 +0200 | [diff] [blame] | 5021 | unlock(shell); |
| 5022 | } |
| 5023 | |
| 5024 | static void |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 5025 | center_on_output(struct weston_view *view, struct weston_output *output) |
Pekka Paalanen | 77346a6 | 2011-11-30 16:26:35 +0200 | [diff] [blame] | 5026 | { |
Giulio Camuffo | b836664 | 2013-04-25 13:57:46 +0300 | [diff] [blame] | 5027 | int32_t surf_x, surf_y, width, height; |
Ander Conselvan de Oliveira | 012b4c7 | 2012-11-27 17:03:42 +0200 | [diff] [blame] | 5028 | float x, y; |
Pekka Paalanen | 77346a6 | 2011-11-30 16:26:35 +0200 | [diff] [blame] | 5029 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 5030 | surface_subsurfaces_boundingbox(view->surface, &surf_x, &surf_y, &width, &height); |
Giulio Camuffo | b836664 | 2013-04-25 13:57:46 +0300 | [diff] [blame] | 5031 | |
| 5032 | x = output->x + (output->width - width) / 2 - surf_x / 2; |
| 5033 | y = output->y + (output->height - height) / 2 - surf_y / 2; |
Ander Conselvan de Oliveira | 012b4c7 | 2012-11-27 17:03:42 +0200 | [diff] [blame] | 5034 | |
Jason Ekstrand | 918f2dd | 2013-12-02 21:01:53 -0600 | [diff] [blame] | 5035 | weston_view_set_position(view, x, y); |
Pekka Paalanen | 77346a6 | 2011-11-30 16:26:35 +0200 | [diff] [blame] | 5036 | } |
| 5037 | |
| 5038 | static void |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 5039 | weston_view_set_initial_position(struct weston_view *view, |
| 5040 | struct desktop_shell *shell) |
Rob Bradford | ac63e5b | 2012-08-13 14:07:52 +0100 | [diff] [blame] | 5041 | { |
| 5042 | struct weston_compositor *compositor = shell->compositor; |
| 5043 | int ix = 0, iy = 0; |
Jonny Lamb | d73c694 | 2014-08-20 15:53:20 +0200 | [diff] [blame^] | 5044 | int32_t range_x, range_y; |
| 5045 | int32_t dx, dy, x, y; |
Rob Bradford | ac63e5b | 2012-08-13 14:07:52 +0100 | [diff] [blame] | 5046 | struct weston_output *output, *target_output = NULL; |
| 5047 | struct weston_seat *seat; |
Jonny Lamb | d73c694 | 2014-08-20 15:53:20 +0200 | [diff] [blame^] | 5048 | pixman_rectangle32_t area; |
Rob Bradford | ac63e5b | 2012-08-13 14:07:52 +0100 | [diff] [blame] | 5049 | |
| 5050 | /* As a heuristic place the new window on the same output as the |
| 5051 | * pointer. Falling back to the output containing 0, 0. |
| 5052 | * |
| 5053 | * TODO: Do something clever for touch too? |
| 5054 | */ |
| 5055 | wl_list_for_each(seat, &compositor->seat_list, link) { |
Kristian Høgsberg | 2bf8762 | 2013-05-07 23:17:41 -0400 | [diff] [blame] | 5056 | if (seat->pointer) { |
Kristian Høgsberg | e314875 | 2013-05-06 23:19:49 -0400 | [diff] [blame] | 5057 | ix = wl_fixed_to_int(seat->pointer->x); |
| 5058 | iy = wl_fixed_to_int(seat->pointer->y); |
Rob Bradford | ac63e5b | 2012-08-13 14:07:52 +0100 | [diff] [blame] | 5059 | break; |
| 5060 | } |
| 5061 | } |
| 5062 | |
| 5063 | wl_list_for_each(output, &compositor->output_list, link) { |
| 5064 | if (pixman_region32_contains_point(&output->region, ix, iy, NULL)) { |
| 5065 | target_output = output; |
| 5066 | break; |
| 5067 | } |
| 5068 | } |
| 5069 | |
| 5070 | if (!target_output) { |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 5071 | weston_view_set_position(view, 10 + random() % 400, |
| 5072 | 10 + random() % 400); |
Rob Bradford | ac63e5b | 2012-08-13 14:07:52 +0100 | [diff] [blame] | 5073 | return; |
| 5074 | } |
| 5075 | |
| 5076 | /* Valid range within output where the surface will still be onscreen. |
| 5077 | * If this is negative it means that the surface is bigger than |
| 5078 | * output. |
| 5079 | */ |
Jonny Lamb | d73c694 | 2014-08-20 15:53:20 +0200 | [diff] [blame^] | 5080 | get_output_work_area(shell, target_output, &area); |
| 5081 | |
| 5082 | dx = area.x; |
| 5083 | dy = area.y; |
| 5084 | range_x = area.width - view->surface->width; |
| 5085 | range_y = area.height - view->surface->height; |
Rob Bradford | ac63e5b | 2012-08-13 14:07:52 +0100 | [diff] [blame] | 5086 | |
Rob Bradford | 4cb88c7 | 2012-08-13 15:18:44 +0100 | [diff] [blame] | 5087 | if (range_x > 0) |
Jonny Lamb | d73c694 | 2014-08-20 15:53:20 +0200 | [diff] [blame^] | 5088 | dx += random() % range_x; |
Rob Bradford | 4cb88c7 | 2012-08-13 15:18:44 +0100 | [diff] [blame] | 5089 | |
| 5090 | if (range_y > 0) |
Jonny Lamb | d73c694 | 2014-08-20 15:53:20 +0200 | [diff] [blame^] | 5091 | dy += random() % range_y; |
Rob Bradford | ac63e5b | 2012-08-13 14:07:52 +0100 | [diff] [blame] | 5092 | |
| 5093 | x = target_output->x + dx; |
| 5094 | y = target_output->y + dy; |
| 5095 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 5096 | weston_view_set_position(view, x, y); |
Rob Bradford | ac63e5b | 2012-08-13 14:07:52 +0100 | [diff] [blame] | 5097 | } |
| 5098 | |
| 5099 | static void |
Jonny Lamb | d73c694 | 2014-08-20 15:53:20 +0200 | [diff] [blame^] | 5100 | set_maximized_position(struct desktop_shell *shell, |
| 5101 | struct shell_surface *shsurf) |
| 5102 | { |
| 5103 | int32_t surf_x, surf_y; |
| 5104 | pixman_rectangle32_t area; |
| 5105 | |
| 5106 | /* use surface configure to set the geometry */ |
| 5107 | get_output_work_area(shell, shsurf->output, &area); |
| 5108 | surface_subsurfaces_boundingbox(shsurf->surface, |
| 5109 | &surf_x, &surf_y, NULL, NULL); |
| 5110 | |
| 5111 | weston_view_set_position(shsurf->view, |
| 5112 | area.x - surf_x, |
| 5113 | area.y - surf_y); |
| 5114 | } |
| 5115 | |
| 5116 | static void |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 5117 | map(struct desktop_shell *shell, struct shell_surface *shsurf, |
Jason Ekstrand | 918f2dd | 2013-12-02 21:01:53 -0600 | [diff] [blame] | 5118 | int32_t sx, int32_t sy) |
Kristian Høgsberg | 02ec0a5 | 2011-04-23 13:04:11 -0400 | [diff] [blame] | 5119 | { |
Kristian Høgsberg | 8334bc1 | 2012-01-03 10:29:47 -0500 | [diff] [blame] | 5120 | struct weston_compositor *compositor = shell->compositor; |
Daniel Stone | b210468 | 2012-05-30 16:31:56 +0100 | [diff] [blame] | 5121 | struct weston_seat *seat; |
Pekka Paalanen | 57da4a8 | 2011-11-23 16:42:16 +0200 | [diff] [blame] | 5122 | |
Pekka Paalanen | 77346a6 | 2011-11-30 16:26:35 +0200 | [diff] [blame] | 5123 | /* initial positioning, see also configure() */ |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 5124 | switch (shsurf->type) { |
Rafael Antognolli | ed207b4 | 2013-12-03 15:35:43 -0200 | [diff] [blame] | 5125 | case SHELL_SURFACE_TOPLEVEL: |
Rafael Antognolli | 03b1659 | 2013-12-03 15:35:42 -0200 | [diff] [blame] | 5126 | if (shsurf->state.fullscreen) { |
| 5127 | center_on_output(shsurf->view, shsurf->fullscreen_output); |
| 5128 | shell_map_fullscreen(shsurf); |
| 5129 | } else if (shsurf->state.maximized) { |
Jonny Lamb | d73c694 | 2014-08-20 15:53:20 +0200 | [diff] [blame^] | 5130 | set_maximized_position(shell, shsurf); |
Rafael Antognolli | ed207b4 | 2013-12-03 15:35:43 -0200 | [diff] [blame] | 5131 | } else if (!shsurf->state.relative) { |
Rafael Antognolli | 03b1659 | 2013-12-03 15:35:42 -0200 | [diff] [blame] | 5132 | weston_view_set_initial_position(shsurf->view, shell); |
| 5133 | } |
Juan Zhao | 96879df | 2012-02-07 08:45:41 +0800 | [diff] [blame] | 5134 | break; |
Tiago Vignatti | 0f99701 | 2012-02-10 16:17:23 +0200 | [diff] [blame] | 5135 | case SHELL_SURFACE_POPUP: |
Kristian Høgsberg | 3730f36 | 2012-04-13 12:40:07 -0400 | [diff] [blame] | 5136 | shell_map_popup(shsurf); |
Rob Bradford | db99938 | 2012-12-06 12:07:48 +0000 | [diff] [blame] | 5137 | break; |
Ander Conselvan de Oliveira | e9e0515 | 2012-02-15 17:02:56 +0200 | [diff] [blame] | 5138 | case SHELL_SURFACE_NONE: |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 5139 | weston_view_set_position(shsurf->view, |
| 5140 | shsurf->view->geometry.x + sx, |
| 5141 | shsurf->view->geometry.y + sy); |
Tiago Vignatti | 0f99701 | 2012-02-10 16:17:23 +0200 | [diff] [blame] | 5142 | break; |
Philip Withnall | 0f640e2 | 2013-11-25 18:01:31 +0000 | [diff] [blame] | 5143 | case SHELL_SURFACE_XWAYLAND: |
Pekka Paalanen | 77346a6 | 2011-11-30 16:26:35 +0200 | [diff] [blame] | 5144 | default: |
| 5145 | ; |
| 5146 | } |
Kristian Høgsberg | 7584062 | 2011-09-06 13:48:16 -0400 | [diff] [blame] | 5147 | |
Philip Withnall | e1d75ae | 2013-11-25 18:01:41 +0000 | [diff] [blame] | 5148 | /* Surface stacking order, see also activate(). */ |
| 5149 | shell_surface_update_layer(shsurf); |
Pekka Paalanen | f0fc70d | 2011-11-15 13:34:54 +0200 | [diff] [blame] | 5150 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 5151 | if (shsurf->type != SHELL_SURFACE_NONE) { |
| 5152 | weston_view_update_transform(shsurf->view); |
Rafael Antognolli | 03b1659 | 2013-12-03 15:35:42 -0200 | [diff] [blame] | 5153 | if (shsurf->state.maximized) { |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 5154 | shsurf->surface->output = shsurf->output; |
| 5155 | shsurf->view->output = shsurf->output; |
| 5156 | } |
Ander Conselvan de Oliveira | de56c31 | 2012-03-05 15:39:23 +0200 | [diff] [blame] | 5157 | } |
Kristian Høgsberg | 2f88a40 | 2011-12-04 15:32:59 -0500 | [diff] [blame] | 5158 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 5159 | switch (shsurf->type) { |
Tiago Vignatti | fb2adba | 2013-06-12 15:43:21 -0300 | [diff] [blame] | 5160 | /* XXX: xwayland's using the same fields for transient type */ |
| 5161 | case SHELL_SURFACE_XWAYLAND: |
Tiago Vignatti | 99aeb1e | 2012-05-23 22:06:26 +0300 | [diff] [blame] | 5162 | if (shsurf->transient.flags == |
| 5163 | WL_SHELL_SURFACE_TRANSIENT_INACTIVE) |
| 5164 | break; |
| 5165 | case SHELL_SURFACE_TOPLEVEL: |
Rafael Antognolli | ed207b4 | 2013-12-03 15:35:43 -0200 | [diff] [blame] | 5166 | if (shsurf->state.relative && |
| 5167 | shsurf->transient.flags == WL_SHELL_SURFACE_TRANSIENT_INACTIVE) |
| 5168 | break; |
Rafael Antognolli | ba5d2d7 | 2013-12-04 17:49:55 -0200 | [diff] [blame] | 5169 | if (shell->locked) |
Rafael Antognolli | ed207b4 | 2013-12-03 15:35:43 -0200 | [diff] [blame] | 5170 | break; |
| 5171 | wl_list_for_each(seat, &compositor->seat_list, link) |
Emilio Pozuelo Monfort | 9e7c759 | 2014-01-30 14:01:10 +0100 | [diff] [blame] | 5172 | activate(shell, shsurf->surface, seat, true); |
Juan Zhao | 7bb92f0 | 2011-12-15 11:31:51 -0500 | [diff] [blame] | 5173 | break; |
Philip Withnall | 0f640e2 | 2013-11-25 18:01:31 +0000 | [diff] [blame] | 5174 | case SHELL_SURFACE_POPUP: |
| 5175 | case SHELL_SURFACE_NONE: |
Juan Zhao | 7bb92f0 | 2011-12-15 11:31:51 -0500 | [diff] [blame] | 5176 | default: |
| 5177 | break; |
| 5178 | } |
| 5179 | |
Rafael Antognolli | 03b1659 | 2013-12-03 15:35:42 -0200 | [diff] [blame] | 5180 | if (shsurf->type == SHELL_SURFACE_TOPLEVEL && |
| 5181 | !shsurf->state.maximized && !shsurf->state.fullscreen) |
Juan Zhao | e10d279 | 2012-04-25 19:09:52 +0800 | [diff] [blame] | 5182 | { |
| 5183 | switch (shell->win_animation_type) { |
| 5184 | case ANIMATION_FADE: |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 5185 | 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] | 5186 | break; |
| 5187 | case ANIMATION_ZOOM: |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 5188 | weston_zoom_run(shsurf->view, 0.5, 1.0, NULL, NULL); |
Juan Zhao | e10d279 | 2012-04-25 19:09:52 +0800 | [diff] [blame] | 5189 | break; |
Philip Withnall | 4a86a0a | 2013-11-25 18:01:32 +0000 | [diff] [blame] | 5190 | case ANIMATION_NONE: |
Juan Zhao | e10d279 | 2012-04-25 19:09:52 +0800 | [diff] [blame] | 5191 | default: |
| 5192 | break; |
| 5193 | } |
| 5194 | } |
Kristian Høgsberg | 32e24cc | 2011-11-09 12:07:35 -0500 | [diff] [blame] | 5195 | } |
| 5196 | |
| 5197 | static void |
Tiago Vignatti | be14326 | 2012-04-16 17:31:41 +0300 | [diff] [blame] | 5198 | configure(struct desktop_shell *shell, struct weston_surface *surface, |
Jason Ekstrand | 918f2dd | 2013-12-02 21:01:53 -0600 | [diff] [blame] | 5199 | float x, float y) |
Kristian Høgsberg | 32e24cc | 2011-11-09 12:07:35 -0500 | [diff] [blame] | 5200 | { |
Pekka Paalanen | 77346a6 | 2011-11-30 16:26:35 +0200 | [diff] [blame] | 5201 | struct shell_surface *shsurf; |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 5202 | struct weston_view *view; |
Kristian Høgsberg | 32e24cc | 2011-11-09 12:07:35 -0500 | [diff] [blame] | 5203 | |
Pekka Paalanen | 77346a6 | 2011-11-30 16:26:35 +0200 | [diff] [blame] | 5204 | shsurf = get_shell_surface(surface); |
Pekka Paalanen | 77346a6 | 2011-11-30 16:26:35 +0200 | [diff] [blame] | 5205 | |
U. Artie Eoff | cf5737a | 2014-01-17 10:08:25 -0800 | [diff] [blame] | 5206 | assert(shsurf); |
| 5207 | |
Rafael Antognolli | 03b1659 | 2013-12-03 15:35:42 -0200 | [diff] [blame] | 5208 | if (shsurf->state.fullscreen) |
Alex Wu | 4539b08 | 2012-03-01 12:57:46 +0800 | [diff] [blame] | 5209 | shell_configure_fullscreen(shsurf); |
Rafael Antognolli | 03b1659 | 2013-12-03 15:35:42 -0200 | [diff] [blame] | 5210 | else if (shsurf->state.maximized) { |
Jonny Lamb | d73c694 | 2014-08-20 15:53:20 +0200 | [diff] [blame^] | 5211 | set_maximized_position(shell, shsurf); |
Rafael Antognolli | 03b1659 | 2013-12-03 15:35:42 -0200 | [diff] [blame] | 5212 | } else { |
Jason Ekstrand | 918f2dd | 2013-12-02 21:01:53 -0600 | [diff] [blame] | 5213 | weston_view_set_position(shsurf->view, x, y); |
Kristian Høgsberg | 7a5c979 | 2011-06-18 06:12:54 -0400 | [diff] [blame] | 5214 | } |
Kristian Høgsberg | 32e24cc | 2011-11-09 12:07:35 -0500 | [diff] [blame] | 5215 | |
Alex Wu | 4539b08 | 2012-03-01 12:57:46 +0800 | [diff] [blame] | 5216 | /* XXX: would a fullscreen surface need the same handling? */ |
Kristian Høgsberg | 6a8b553 | 2012-02-16 23:43:59 -0500 | [diff] [blame] | 5217 | if (surface->output) { |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 5218 | wl_list_for_each(view, &surface->views, surface_link) |
| 5219 | weston_view_update_transform(view); |
Pekka Paalanen | 77346a6 | 2011-11-30 16:26:35 +0200 | [diff] [blame] | 5220 | |
Rafael Antognolli | 03b1659 | 2013-12-03 15:35:42 -0200 | [diff] [blame] | 5221 | if (shsurf->state.maximized) |
Juan Zhao | 96879df | 2012-02-07 08:45:41 +0800 | [diff] [blame] | 5222 | surface->output = shsurf->output; |
Pekka Paalanen | 77346a6 | 2011-11-30 16:26:35 +0200 | [diff] [blame] | 5223 | } |
Kristian Høgsberg | 0793756 | 2011-04-12 17:25:42 -0400 | [diff] [blame] | 5224 | } |
| 5225 | |
Ander Conselvan de Oliveira | 093bfa3 | 2012-03-27 17:36:41 +0300 | [diff] [blame] | 5226 | static void |
Jason Ekstrand | 918f2dd | 2013-12-02 21:01:53 -0600 | [diff] [blame] | 5227 | 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] | 5228 | { |
Ander Conselvan de Oliveira | 7fb9f95 | 2012-03-27 17:36:42 +0300 | [diff] [blame] | 5229 | struct shell_surface *shsurf = get_shell_surface(es); |
U. Artie Eoff | cf5737a | 2014-01-17 10:08:25 -0800 | [diff] [blame] | 5230 | struct desktop_shell *shell; |
Tiago Vignatti | 70e5c9c | 2012-05-07 15:23:07 +0300 | [diff] [blame] | 5231 | int type_changed = 0; |
Ander Conselvan de Oliveira | 093bfa3 | 2012-03-27 17:36:41 +0300 | [diff] [blame] | 5232 | |
U. Artie Eoff | cf5737a | 2014-01-17 10:08:25 -0800 | [diff] [blame] | 5233 | assert(shsurf); |
| 5234 | |
| 5235 | shell = shsurf->shell; |
| 5236 | |
Kristian Høgsberg | 8eb0f4f | 2013-06-17 10:33:14 -0400 | [diff] [blame] | 5237 | if (!weston_surface_is_mapped(es) && |
| 5238 | !wl_list_empty(&shsurf->popup.grab_link)) { |
Giulio Camuffo | 5085a75 | 2013-03-25 21:42:45 +0100 | [diff] [blame] | 5239 | remove_popup_grab(shsurf); |
| 5240 | } |
| 5241 | |
Jason Ekstrand | 918f2dd | 2013-12-02 21:01:53 -0600 | [diff] [blame] | 5242 | if (es->width == 0) |
Giulio Camuffo | 184df50 | 2013-02-21 11:29:21 +0100 | [diff] [blame] | 5243 | return; |
| 5244 | |
Jasper St. Pierre | ccf48fb | 2014-05-02 10:21:38 -0400 | [diff] [blame] | 5245 | if (shsurf->has_next_geometry) { |
| 5246 | shsurf->geometry = shsurf->next_geometry; |
| 5247 | shsurf->has_next_geometry = false; |
| 5248 | shsurf->has_set_geometry = true; |
| 5249 | } else if (!shsurf->has_set_geometry) { |
| 5250 | surface_subsurfaces_boundingbox(shsurf->surface, |
| 5251 | &shsurf->geometry.x, |
| 5252 | &shsurf->geometry.y, |
| 5253 | &shsurf->geometry.width, |
| 5254 | &shsurf->geometry.height); |
Jasper St. Pierre | 851799e | 2014-05-02 10:14:07 -0400 | [diff] [blame] | 5255 | } |
| 5256 | |
Kristian Høgsberg | c8f8dd8 | 2013-12-05 23:20:33 -0800 | [diff] [blame] | 5257 | if (shsurf->state_changed) { |
Kristian Høgsberg | 7f366e7 | 2012-04-27 17:20:01 -0400 | [diff] [blame] | 5258 | set_surface_type(shsurf); |
Kristian Høgsberg | f7e23d5 | 2012-04-27 17:51:59 -0400 | [diff] [blame] | 5259 | type_changed = 1; |
| 5260 | } |
Kristian Høgsberg | 7f366e7 | 2012-04-27 17:20:01 -0400 | [diff] [blame] | 5261 | |
Ander Conselvan de Oliveira | 093bfa3 | 2012-03-27 17:36:41 +0300 | [diff] [blame] | 5262 | if (!weston_surface_is_mapped(es)) { |
Jason Ekstrand | 918f2dd | 2013-12-02 21:01:53 -0600 | [diff] [blame] | 5263 | map(shell, shsurf, sx, sy); |
Kristian Høgsberg | f7e23d5 | 2012-04-27 17:51:59 -0400 | [diff] [blame] | 5264 | } else if (type_changed || sx != 0 || sy != 0 || |
Jason Ekstrand | 918f2dd | 2013-12-02 21:01:53 -0600 | [diff] [blame] | 5265 | shsurf->last_width != es->width || |
| 5266 | shsurf->last_height != es->height) { |
John Kåre Alsaker | 490d02a | 2012-09-30 02:57:21 +0200 | [diff] [blame] | 5267 | float from_x, from_y; |
| 5268 | float to_x, to_y; |
Ander Conselvan de Oliveira | 093bfa3 | 2012-03-27 17:36:41 +0300 | [diff] [blame] | 5269 | |
Kristian Høgsberg | 44cd196 | 2014-02-05 21:36:04 -0800 | [diff] [blame] | 5270 | if (shsurf->resize_edges) { |
| 5271 | sx = 0; |
| 5272 | sy = 0; |
| 5273 | } |
| 5274 | |
| 5275 | if (shsurf->resize_edges & WL_SHELL_SURFACE_RESIZE_LEFT) |
| 5276 | sx = shsurf->last_width - es->width; |
| 5277 | if (shsurf->resize_edges & WL_SHELL_SURFACE_RESIZE_TOP) |
| 5278 | sy = shsurf->last_height - es->height; |
| 5279 | |
| 5280 | shsurf->last_width = es->width; |
| 5281 | shsurf->last_height = es->height; |
| 5282 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 5283 | weston_view_to_global_float(shsurf->view, 0, 0, &from_x, &from_y); |
| 5284 | 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] | 5285 | configure(shell, es, |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 5286 | shsurf->view->geometry.x + to_x - from_x, |
Jason Ekstrand | 918f2dd | 2013-12-02 21:01:53 -0600 | [diff] [blame] | 5287 | shsurf->view->geometry.y + to_y - from_y); |
Ander Conselvan de Oliveira | 093bfa3 | 2012-03-27 17:36:41 +0300 | [diff] [blame] | 5288 | } |
| 5289 | } |
| 5290 | |
Tiago Vignatti | b7dbbd6 | 2012-09-25 17:57:01 +0300 | [diff] [blame] | 5291 | static void launch_desktop_shell_process(void *data); |
Pekka Paalanen | 4d733ee | 2012-01-17 14:36:27 +0200 | [diff] [blame] | 5292 | |
Kristian Høgsberg | 97d44aa | 2011-08-26 17:21:20 -0400 | [diff] [blame] | 5293 | static void |
Kristian Høgsberg | 8334bc1 | 2012-01-03 10:29:47 -0500 | [diff] [blame] | 5294 | desktop_shell_sigchld(struct weston_process *process, int status) |
Pekka Paalanen | 6cd281a | 2011-11-03 14:11:32 +0200 | [diff] [blame] | 5295 | { |
Pekka Paalanen | 4d733ee | 2012-01-17 14:36:27 +0200 | [diff] [blame] | 5296 | uint32_t time; |
Tiago Vignatti | be14326 | 2012-04-16 17:31:41 +0300 | [diff] [blame] | 5297 | struct desktop_shell *shell = |
| 5298 | container_of(process, struct desktop_shell, child.process); |
Pekka Paalanen | 6cd281a | 2011-11-03 14:11:32 +0200 | [diff] [blame] | 5299 | |
| 5300 | shell->child.process.pid = 0; |
| 5301 | shell->child.client = NULL; /* already destroyed by wayland */ |
Pekka Paalanen | 4d733ee | 2012-01-17 14:36:27 +0200 | [diff] [blame] | 5302 | |
| 5303 | /* if desktop-shell dies more than 5 times in 30 seconds, give up */ |
| 5304 | time = weston_compositor_get_time(); |
Kristian Høgsberg | f03a616 | 2012-01-17 11:07:42 -0500 | [diff] [blame] | 5305 | if (time - shell->child.deathstamp > 30000) { |
Pekka Paalanen | 4d733ee | 2012-01-17 14:36:27 +0200 | [diff] [blame] | 5306 | shell->child.deathstamp = time; |
| 5307 | shell->child.deathcount = 0; |
| 5308 | } |
| 5309 | |
| 5310 | shell->child.deathcount++; |
| 5311 | if (shell->child.deathcount > 5) { |
Emilio Pozuelo Monfort | 46ce798 | 2013-11-20 13:22:29 +0100 | [diff] [blame] | 5312 | weston_log("%s died, giving up.\n", shell->client); |
Pekka Paalanen | 4d733ee | 2012-01-17 14:36:27 +0200 | [diff] [blame] | 5313 | return; |
| 5314 | } |
| 5315 | |
Emilio Pozuelo Monfort | 46ce798 | 2013-11-20 13:22:29 +0100 | [diff] [blame] | 5316 | weston_log("%s died, respawning...\n", shell->client); |
Pekka Paalanen | 4d733ee | 2012-01-17 14:36:27 +0200 | [diff] [blame] | 5317 | launch_desktop_shell_process(shell); |
Pekka Paalanen | 79346ab | 2013-05-22 18:03:09 +0300 | [diff] [blame] | 5318 | shell_fade_startup(shell); |
Pekka Paalanen | 6cd281a | 2011-11-03 14:11:32 +0200 | [diff] [blame] | 5319 | } |
| 5320 | |
Tiago Vignatti | b7dbbd6 | 2012-09-25 17:57:01 +0300 | [diff] [blame] | 5321 | static void |
Ander Conselvan de Oliveira | 312ea4c | 2013-12-20 21:07:01 +0200 | [diff] [blame] | 5322 | desktop_shell_client_destroy(struct wl_listener *listener, void *data) |
| 5323 | { |
| 5324 | struct desktop_shell *shell; |
| 5325 | |
| 5326 | shell = container_of(listener, struct desktop_shell, |
| 5327 | child.client_destroy_listener); |
| 5328 | |
| 5329 | shell->child.client = NULL; |
| 5330 | } |
| 5331 | |
| 5332 | static void |
Tiago Vignatti | b7dbbd6 | 2012-09-25 17:57:01 +0300 | [diff] [blame] | 5333 | launch_desktop_shell_process(void *data) |
Pekka Paalanen | 6cd281a | 2011-11-03 14:11:32 +0200 | [diff] [blame] | 5334 | { |
Tiago Vignatti | b7dbbd6 | 2012-09-25 17:57:01 +0300 | [diff] [blame] | 5335 | struct desktop_shell *shell = data; |
Pekka Paalanen | 6cd281a | 2011-11-03 14:11:32 +0200 | [diff] [blame] | 5336 | |
Kristian Høgsberg | 8334bc1 | 2012-01-03 10:29:47 -0500 | [diff] [blame] | 5337 | shell->child.client = weston_client_launch(shell->compositor, |
Pekka Paalanen | 409ef0a | 2011-12-02 15:30:21 +0200 | [diff] [blame] | 5338 | &shell->child.process, |
Emilio Pozuelo Monfort | 46ce798 | 2013-11-20 13:22:29 +0100 | [diff] [blame] | 5339 | shell->client, |
Pekka Paalanen | 409ef0a | 2011-12-02 15:30:21 +0200 | [diff] [blame] | 5340 | desktop_shell_sigchld); |
| 5341 | |
| 5342 | if (!shell->child.client) |
Emilio Pozuelo Monfort | 46ce798 | 2013-11-20 13:22:29 +0100 | [diff] [blame] | 5343 | weston_log("not able to start %s\n", shell->client); |
Ander Conselvan de Oliveira | 312ea4c | 2013-12-20 21:07:01 +0200 | [diff] [blame] | 5344 | |
| 5345 | shell->child.client_destroy_listener.notify = |
| 5346 | desktop_shell_client_destroy; |
| 5347 | wl_client_add_destroy_listener(shell->child.client, |
| 5348 | &shell->child.client_destroy_listener); |
Pekka Paalanen | 6cd281a | 2011-11-03 14:11:32 +0200 | [diff] [blame] | 5349 | } |
| 5350 | |
| 5351 | static void |
Kristian Høgsberg | 2bff94e | 2014-02-11 12:22:51 -0800 | [diff] [blame] | 5352 | handle_shell_client_destroy(struct wl_listener *listener, void *data) |
| 5353 | { |
| 5354 | struct shell_client *sc = |
| 5355 | container_of(listener, struct shell_client, destroy_listener); |
| 5356 | |
| 5357 | if (sc->ping_timer) |
| 5358 | wl_event_source_remove(sc->ping_timer); |
| 5359 | free(sc); |
| 5360 | } |
| 5361 | |
Kristian Høgsberg | dd62aba | 2014-02-12 09:56:19 -0800 | [diff] [blame] | 5362 | static struct shell_client * |
| 5363 | shell_client_create(struct wl_client *client, struct desktop_shell *shell, |
| 5364 | const struct wl_interface *interface, uint32_t id) |
Rafael Antognolli | e2a3455 | 2013-12-03 15:35:45 -0200 | [diff] [blame] | 5365 | { |
Kristian Høgsberg | 2bff94e | 2014-02-11 12:22:51 -0800 | [diff] [blame] | 5366 | struct shell_client *sc; |
Rafael Antognolli | e2a3455 | 2013-12-03 15:35:45 -0200 | [diff] [blame] | 5367 | |
Kristian Høgsberg | 2bff94e | 2014-02-11 12:22:51 -0800 | [diff] [blame] | 5368 | sc = zalloc(sizeof *sc); |
| 5369 | if (sc == NULL) { |
| 5370 | wl_client_post_no_memory(client); |
Kristian Høgsberg | dd62aba | 2014-02-12 09:56:19 -0800 | [diff] [blame] | 5371 | return NULL; |
Kristian Høgsberg | 2bff94e | 2014-02-11 12:22:51 -0800 | [diff] [blame] | 5372 | } |
Kristian Høgsberg | dd62aba | 2014-02-12 09:56:19 -0800 | [diff] [blame] | 5373 | |
| 5374 | sc->resource = wl_resource_create(client, interface, 1, id); |
Kristian Høgsberg | 2bff94e | 2014-02-11 12:22:51 -0800 | [diff] [blame] | 5375 | if (sc->resource == NULL) { |
| 5376 | free(sc); |
| 5377 | wl_client_post_no_memory(client); |
Kristian Høgsberg | dd62aba | 2014-02-12 09:56:19 -0800 | [diff] [blame] | 5378 | return NULL; |
Kristian Høgsberg | 2bff94e | 2014-02-11 12:22:51 -0800 | [diff] [blame] | 5379 | } |
| 5380 | |
| 5381 | sc->client = client; |
| 5382 | sc->shell = shell; |
| 5383 | sc->destroy_listener.notify = handle_shell_client_destroy; |
| 5384 | wl_client_add_destroy_listener(client, &sc->destroy_listener); |
| 5385 | |
Kristian Høgsberg | dd62aba | 2014-02-12 09:56:19 -0800 | [diff] [blame] | 5386 | return sc; |
| 5387 | } |
| 5388 | |
| 5389 | static void |
| 5390 | bind_shell(struct wl_client *client, void *data, uint32_t version, uint32_t id) |
| 5391 | { |
| 5392 | struct desktop_shell *shell = data; |
| 5393 | struct shell_client *sc; |
| 5394 | |
| 5395 | sc = shell_client_create(client, shell, &wl_shell_interface, id); |
| 5396 | if (sc) |
| 5397 | wl_resource_set_implementation(sc->resource, |
| 5398 | &shell_implementation, |
Jason Ekstrand | 9e9512f | 2014-04-16 21:12:10 -0500 | [diff] [blame] | 5399 | sc, NULL); |
Kristian Høgsberg | dd62aba | 2014-02-12 09:56:19 -0800 | [diff] [blame] | 5400 | } |
| 5401 | |
| 5402 | static void |
| 5403 | bind_xdg_shell(struct wl_client *client, void *data, uint32_t version, uint32_t id) |
| 5404 | { |
| 5405 | struct desktop_shell *shell = data; |
| 5406 | struct shell_client *sc; |
| 5407 | |
| 5408 | sc = shell_client_create(client, shell, &xdg_shell_interface, id); |
| 5409 | if (sc) |
| 5410 | wl_resource_set_dispatcher(sc->resource, |
| 5411 | xdg_shell_unversioned_dispatch, |
| 5412 | NULL, sc, NULL); |
Rafael Antognolli | e2a3455 | 2013-12-03 15:35:45 -0200 | [diff] [blame] | 5413 | } |
| 5414 | |
| 5415 | static void |
Pekka Paalanen | 9ef3e01 | 2011-11-15 13:34:48 +0200 | [diff] [blame] | 5416 | unbind_desktop_shell(struct wl_resource *resource) |
| 5417 | { |
Jason Ekstrand | 651f00e | 2013-06-14 10:07:54 -0500 | [diff] [blame] | 5418 | struct desktop_shell *shell = wl_resource_get_user_data(resource); |
Kristian Høgsberg | 1ec0c31 | 2011-11-15 16:39:55 -0500 | [diff] [blame] | 5419 | |
| 5420 | if (shell->locked) |
| 5421 | resume_desktop(shell); |
| 5422 | |
Pekka Paalanen | 9ef3e01 | 2011-11-15 13:34:48 +0200 | [diff] [blame] | 5423 | shell->child.desktop_shell = NULL; |
| 5424 | shell->prepare_event_sent = false; |
Pekka Paalanen | 9ef3e01 | 2011-11-15 13:34:48 +0200 | [diff] [blame] | 5425 | } |
| 5426 | |
| 5427 | static void |
Kristian Høgsberg | 7584062 | 2011-09-06 13:48:16 -0400 | [diff] [blame] | 5428 | bind_desktop_shell(struct wl_client *client, |
| 5429 | void *data, uint32_t version, uint32_t id) |
| 5430 | { |
Tiago Vignatti | be14326 | 2012-04-16 17:31:41 +0300 | [diff] [blame] | 5431 | struct desktop_shell *shell = data; |
Pekka Paalanen | bbe6052 | 2011-11-03 14:11:33 +0200 | [diff] [blame] | 5432 | struct wl_resource *resource; |
Kristian Høgsberg | 7584062 | 2011-09-06 13:48:16 -0400 | [diff] [blame] | 5433 | |
Jason Ekstrand | a85118c | 2013-06-27 20:17:02 -0500 | [diff] [blame] | 5434 | resource = wl_resource_create(client, &desktop_shell_interface, |
Jonny Lamb | 765760d | 2014-08-20 15:53:19 +0200 | [diff] [blame] | 5435 | MIN(version, 3), id); |
Pekka Paalanen | bbe6052 | 2011-11-03 14:11:33 +0200 | [diff] [blame] | 5436 | |
Pekka Paalanen | 9ef3e01 | 2011-11-15 13:34:48 +0200 | [diff] [blame] | 5437 | if (client == shell->child.client) { |
Jason Ekstrand | a85118c | 2013-06-27 20:17:02 -0500 | [diff] [blame] | 5438 | wl_resource_set_implementation(resource, |
| 5439 | &desktop_shell_implementation, |
| 5440 | shell, unbind_desktop_shell); |
Pekka Paalanen | 9ef3e01 | 2011-11-15 13:34:48 +0200 | [diff] [blame] | 5441 | shell->child.desktop_shell = resource; |
Pekka Paalanen | 79346ab | 2013-05-22 18:03:09 +0300 | [diff] [blame] | 5442 | |
| 5443 | if (version < 2) |
| 5444 | shell_fade_startup(shell); |
| 5445 | |
Pekka Paalanen | bbe6052 | 2011-11-03 14:11:33 +0200 | [diff] [blame] | 5446 | return; |
Pekka Paalanen | 9ef3e01 | 2011-11-15 13:34:48 +0200 | [diff] [blame] | 5447 | } |
Pekka Paalanen | bbe6052 | 2011-11-03 14:11:33 +0200 | [diff] [blame] | 5448 | |
| 5449 | wl_resource_post_error(resource, WL_DISPLAY_ERROR_INVALID_OBJECT, |
| 5450 | "permission to bind desktop_shell denied"); |
Kristian Høgsberg | 7584062 | 2011-09-06 13:48:16 -0400 | [diff] [blame] | 5451 | } |
| 5452 | |
Pekka Paalanen | 6e16811 | 2011-11-24 11:34:05 +0200 | [diff] [blame] | 5453 | static void |
Jason Ekstrand | 918f2dd | 2013-12-02 21:01:53 -0600 | [diff] [blame] | 5454 | 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] | 5455 | { |
Giulio Camuffo | 7fe01b1 | 2013-03-28 18:02:42 +0100 | [diff] [blame] | 5456 | struct desktop_shell *shell = surface->configure_private; |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 5457 | struct weston_view *view; |
Giulio Camuffo | 412e6a5 | 2014-07-09 22:12:56 +0300 | [diff] [blame] | 5458 | struct weston_layer_entry *prev; |
Kristian Høgsberg | 1a73a63 | 2012-06-26 22:15:53 -0400 | [diff] [blame] | 5459 | |
Jason Ekstrand | 918f2dd | 2013-12-02 21:01:53 -0600 | [diff] [blame] | 5460 | if (surface->width == 0) |
Giulio Camuffo | 184df50 | 2013-02-21 11:29:21 +0100 | [diff] [blame] | 5461 | return; |
| 5462 | |
Pekka Paalanen | 3a1d07d | 2012-12-20 14:02:13 +0200 | [diff] [blame] | 5463 | /* XXX: starting weston-screensaver beforehand does not work */ |
Kristian Høgsberg | 1a73a63 | 2012-06-26 22:15:53 -0400 | [diff] [blame] | 5464 | if (!shell->locked) |
| 5465 | return; |
| 5466 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 5467 | view = container_of(surface->views.next, struct weston_view, surface_link); |
| 5468 | center_on_output(view, surface->output); |
Kristian Høgsberg | 1a73a63 | 2012-06-26 22:15:53 -0400 | [diff] [blame] | 5469 | |
Giulio Camuffo | 412e6a5 | 2014-07-09 22:12:56 +0300 | [diff] [blame] | 5470 | if (wl_list_empty(&view->layer_link.link)) { |
| 5471 | prev = container_of(shell->lock_layer.view_list.link.prev, |
| 5472 | struct weston_layer_entry, link); |
| 5473 | weston_layer_entry_insert(prev, &view->layer_link); |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 5474 | weston_view_update_transform(view); |
Ander Conselvan de Oliveira | 859e885 | 2013-02-21 18:35:21 +0200 | [diff] [blame] | 5475 | wl_event_source_timer_update(shell->screensaver.timer, |
| 5476 | shell->screensaver.duration); |
Ander Conselvan de Oliveira | 19d10ef | 2013-02-21 18:35:20 +0200 | [diff] [blame] | 5477 | shell_fade(shell, FADE_IN); |
Kristian Høgsberg | 1a73a63 | 2012-06-26 22:15:53 -0400 | [diff] [blame] | 5478 | } |
| 5479 | } |
| 5480 | |
| 5481 | static void |
Pekka Paalanen | 6e16811 | 2011-11-24 11:34:05 +0200 | [diff] [blame] | 5482 | screensaver_set_surface(struct wl_client *client, |
| 5483 | struct wl_resource *resource, |
Kristian Høgsberg | 1a73a63 | 2012-06-26 22:15:53 -0400 | [diff] [blame] | 5484 | struct wl_resource *surface_resource, |
Pekka Paalanen | 6e16811 | 2011-11-24 11:34:05 +0200 | [diff] [blame] | 5485 | struct wl_resource *output_resource) |
| 5486 | { |
Jason Ekstrand | 651f00e | 2013-06-14 10:07:54 -0500 | [diff] [blame] | 5487 | struct desktop_shell *shell = wl_resource_get_user_data(resource); |
Jason Ekstrand | 0f2ef7e | 2013-06-14 10:07:53 -0500 | [diff] [blame] | 5488 | struct weston_surface *surface = |
| 5489 | wl_resource_get_user_data(surface_resource); |
Jason Ekstrand | a0d2dde | 2013-06-14 10:08:01 -0500 | [diff] [blame] | 5490 | struct weston_output *output = wl_resource_get_user_data(output_resource); |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 5491 | struct weston_view *view, *next; |
| 5492 | |
| 5493 | /* Make sure we only have one view */ |
| 5494 | wl_list_for_each_safe(view, next, &surface->views, surface_link) |
| 5495 | weston_view_destroy(view); |
| 5496 | weston_view_create(surface); |
Pekka Paalanen | 6e16811 | 2011-11-24 11:34:05 +0200 | [diff] [blame] | 5497 | |
Kristian Høgsberg | 1a73a63 | 2012-06-26 22:15:53 -0400 | [diff] [blame] | 5498 | surface->configure = screensaver_configure; |
Giulio Camuffo | 7fe01b1 | 2013-03-28 18:02:42 +0100 | [diff] [blame] | 5499 | surface->configure_private = shell; |
Pekka Paalanen | 77346a6 | 2011-11-30 16:26:35 +0200 | [diff] [blame] | 5500 | surface->output = output; |
Pekka Paalanen | 6e16811 | 2011-11-24 11:34:05 +0200 | [diff] [blame] | 5501 | } |
| 5502 | |
| 5503 | static const struct screensaver_interface screensaver_implementation = { |
| 5504 | screensaver_set_surface |
| 5505 | }; |
| 5506 | |
| 5507 | static void |
| 5508 | unbind_screensaver(struct wl_resource *resource) |
| 5509 | { |
Jason Ekstrand | 651f00e | 2013-06-14 10:07:54 -0500 | [diff] [blame] | 5510 | struct desktop_shell *shell = wl_resource_get_user_data(resource); |
Pekka Paalanen | 6e16811 | 2011-11-24 11:34:05 +0200 | [diff] [blame] | 5511 | |
Pekka Paalanen | 77346a6 | 2011-11-30 16:26:35 +0200 | [diff] [blame] | 5512 | shell->screensaver.binding = NULL; |
Pekka Paalanen | 6e16811 | 2011-11-24 11:34:05 +0200 | [diff] [blame] | 5513 | } |
| 5514 | |
| 5515 | static void |
| 5516 | bind_screensaver(struct wl_client *client, |
| 5517 | void *data, uint32_t version, uint32_t id) |
| 5518 | { |
Tiago Vignatti | be14326 | 2012-04-16 17:31:41 +0300 | [diff] [blame] | 5519 | struct desktop_shell *shell = data; |
Pekka Paalanen | 6e16811 | 2011-11-24 11:34:05 +0200 | [diff] [blame] | 5520 | struct wl_resource *resource; |
| 5521 | |
Jason Ekstrand | a85118c | 2013-06-27 20:17:02 -0500 | [diff] [blame] | 5522 | resource = wl_resource_create(client, &screensaver_interface, 1, id); |
Pekka Paalanen | 6e16811 | 2011-11-24 11:34:05 +0200 | [diff] [blame] | 5523 | |
Pekka Paalanen | 77346a6 | 2011-11-30 16:26:35 +0200 | [diff] [blame] | 5524 | if (shell->screensaver.binding == NULL) { |
Jason Ekstrand | a85118c | 2013-06-27 20:17:02 -0500 | [diff] [blame] | 5525 | wl_resource_set_implementation(resource, |
| 5526 | &screensaver_implementation, |
| 5527 | shell, unbind_screensaver); |
Pekka Paalanen | 77346a6 | 2011-11-30 16:26:35 +0200 | [diff] [blame] | 5528 | shell->screensaver.binding = resource; |
Pekka Paalanen | 6e16811 | 2011-11-24 11:34:05 +0200 | [diff] [blame] | 5529 | return; |
| 5530 | } |
| 5531 | |
| 5532 | wl_resource_post_error(resource, WL_DISPLAY_ERROR_INVALID_OBJECT, |
| 5533 | "interface object already bound"); |
Pekka Paalanen | 6e16811 | 2011-11-24 11:34:05 +0200 | [diff] [blame] | 5534 | } |
| 5535 | |
Kristian Høgsberg | 0704539 | 2012-02-19 18:52:44 -0500 | [diff] [blame] | 5536 | struct switcher { |
Tiago Vignatti | be14326 | 2012-04-16 17:31:41 +0300 | [diff] [blame] | 5537 | struct desktop_shell *shell; |
Kristian Høgsberg | 0704539 | 2012-02-19 18:52:44 -0500 | [diff] [blame] | 5538 | struct weston_surface *current; |
| 5539 | struct wl_listener listener; |
Kristian Høgsberg | 29139d4 | 2013-04-18 15:25:39 -0400 | [diff] [blame] | 5540 | struct weston_keyboard_grab grab; |
Manuel Bachmann | c1ae2e8 | 2014-02-26 15:53:11 +0100 | [diff] [blame] | 5541 | struct wl_array minimized_array; |
Kristian Høgsberg | 0704539 | 2012-02-19 18:52:44 -0500 | [diff] [blame] | 5542 | }; |
| 5543 | |
| 5544 | static void |
| 5545 | switcher_next(struct switcher *switcher) |
| 5546 | { |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 5547 | struct weston_view *view; |
Kristian Høgsberg | 0704539 | 2012-02-19 18:52:44 -0500 | [diff] [blame] | 5548 | struct weston_surface *first = NULL, *prev = NULL, *next = NULL; |
Kristian Høgsberg | 32e5686 | 2012-04-02 22:18:58 -0400 | [diff] [blame] | 5549 | struct shell_surface *shsurf; |
Kristian Høgsberg | b0d8e77 | 2012-06-18 16:34:58 -0400 | [diff] [blame] | 5550 | struct workspace *ws = get_current_workspace(switcher->shell); |
Kristian Høgsberg | 0704539 | 2012-02-19 18:52:44 -0500 | [diff] [blame] | 5551 | |
Manuel Bachmann | c1ae2e8 | 2014-02-26 15:53:11 +0100 | [diff] [blame] | 5552 | /* temporary re-display minimized surfaces */ |
| 5553 | struct weston_view *tmp; |
| 5554 | struct weston_view **minimized; |
Giulio Camuffo | 412e6a5 | 2014-07-09 22:12:56 +0300 | [diff] [blame] | 5555 | wl_list_for_each_safe(view, tmp, &switcher->shell->minimized_layer.view_list.link, layer_link.link) { |
| 5556 | weston_layer_entry_remove(&view->layer_link); |
| 5557 | weston_layer_entry_insert(&ws->layer.view_list, &view->layer_link); |
Manuel Bachmann | c1ae2e8 | 2014-02-26 15:53:11 +0100 | [diff] [blame] | 5558 | minimized = wl_array_add(&switcher->minimized_array, sizeof *minimized); |
| 5559 | *minimized = view; |
| 5560 | } |
| 5561 | |
Giulio Camuffo | 412e6a5 | 2014-07-09 22:12:56 +0300 | [diff] [blame] | 5562 | 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] | 5563 | shsurf = get_shell_surface(view->surface); |
Rafael Antognolli | 5031cbe | 2013-12-05 19:01:21 -0200 | [diff] [blame] | 5564 | if (shsurf && |
| 5565 | shsurf->type == SHELL_SURFACE_TOPLEVEL && |
| 5566 | shsurf->parent == NULL) { |
Kristian Høgsberg | 0704539 | 2012-02-19 18:52:44 -0500 | [diff] [blame] | 5567 | if (first == NULL) |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 5568 | first = view->surface; |
Kristian Høgsberg | 0704539 | 2012-02-19 18:52:44 -0500 | [diff] [blame] | 5569 | if (prev == switcher->current) |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 5570 | next = view->surface; |
| 5571 | prev = view->surface; |
| 5572 | view->alpha = 0.25; |
| 5573 | weston_view_geometry_dirty(view); |
| 5574 | weston_surface_damage(view->surface); |
Kristian Høgsberg | 0704539 | 2012-02-19 18:52:44 -0500 | [diff] [blame] | 5575 | } |
Alex Wu | 1659daa | 2012-04-01 20:13:09 +0800 | [diff] [blame] | 5576 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 5577 | if (is_black_surface(view->surface, NULL)) { |
| 5578 | view->alpha = 0.25; |
| 5579 | weston_view_geometry_dirty(view); |
| 5580 | weston_surface_damage(view->surface); |
Alex Wu | 1659daa | 2012-04-01 20:13:09 +0800 | [diff] [blame] | 5581 | } |
Kristian Høgsberg | 0704539 | 2012-02-19 18:52:44 -0500 | [diff] [blame] | 5582 | } |
| 5583 | |
| 5584 | if (next == NULL) |
| 5585 | next = first; |
| 5586 | |
Alex Wu | 07b2606 | 2012-03-12 16:06:01 +0800 | [diff] [blame] | 5587 | if (next == NULL) |
| 5588 | return; |
| 5589 | |
Kristian Høgsberg | 0704539 | 2012-02-19 18:52:44 -0500 | [diff] [blame] | 5590 | wl_list_remove(&switcher->listener.link); |
Jason Ekstrand | 26ed73c | 2013-06-06 22:34:41 -0500 | [diff] [blame] | 5591 | wl_signal_add(&next->destroy_signal, &switcher->listener); |
Kristian Høgsberg | 0704539 | 2012-02-19 18:52:44 -0500 | [diff] [blame] | 5592 | |
| 5593 | switcher->current = next; |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 5594 | wl_list_for_each(view, &next->views, surface_link) |
| 5595 | view->alpha = 1.0; |
Alex Wu | 1659daa | 2012-04-01 20:13:09 +0800 | [diff] [blame] | 5596 | |
Kristian Høgsberg | 32e5686 | 2012-04-02 22:18:58 -0400 | [diff] [blame] | 5597 | shsurf = get_shell_surface(switcher->current); |
Rafael Antognolli | 03b1659 | 2013-12-03 15:35:42 -0200 | [diff] [blame] | 5598 | if (shsurf && shsurf->state.fullscreen) |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 5599 | shsurf->fullscreen.black_view->alpha = 1.0; |
Kristian Høgsberg | 0704539 | 2012-02-19 18:52:44 -0500 | [diff] [blame] | 5600 | } |
| 5601 | |
| 5602 | static void |
Kristian Høgsberg | 27e3052 | 2012-04-11 23:18:23 -0400 | [diff] [blame] | 5603 | switcher_handle_surface_destroy(struct wl_listener *listener, void *data) |
Kristian Høgsberg | 0704539 | 2012-02-19 18:52:44 -0500 | [diff] [blame] | 5604 | { |
| 5605 | struct switcher *switcher = |
| 5606 | container_of(listener, struct switcher, listener); |
| 5607 | |
| 5608 | switcher_next(switcher); |
| 5609 | } |
| 5610 | |
| 5611 | static void |
Daniel Stone | 351eb61 | 2012-05-31 15:27:47 -0400 | [diff] [blame] | 5612 | switcher_destroy(struct switcher *switcher) |
Kristian Høgsberg | 0704539 | 2012-02-19 18:52:44 -0500 | [diff] [blame] | 5613 | { |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 5614 | struct weston_view *view; |
Kristian Høgsberg | 29139d4 | 2013-04-18 15:25:39 -0400 | [diff] [blame] | 5615 | struct weston_keyboard *keyboard = switcher->grab.keyboard; |
Kristian Høgsberg | b0d8e77 | 2012-06-18 16:34:58 -0400 | [diff] [blame] | 5616 | struct workspace *ws = get_current_workspace(switcher->shell); |
Kristian Høgsberg | 0704539 | 2012-02-19 18:52:44 -0500 | [diff] [blame] | 5617 | |
Giulio Camuffo | 412e6a5 | 2014-07-09 22:12:56 +0300 | [diff] [blame] | 5618 | 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] | 5619 | if (is_focus_view(view)) |
| 5620 | continue; |
| 5621 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 5622 | view->alpha = 1.0; |
| 5623 | weston_surface_damage(view->surface); |
Kristian Høgsberg | 0704539 | 2012-02-19 18:52:44 -0500 | [diff] [blame] | 5624 | } |
| 5625 | |
Alex Wu | 07b2606 | 2012-03-12 16:06:01 +0800 | [diff] [blame] | 5626 | if (switcher->current) |
Daniel Stone | 37816df | 2012-05-16 18:45:18 +0100 | [diff] [blame] | 5627 | activate(switcher->shell, switcher->current, |
Emilio Pozuelo Monfort | 9e7c759 | 2014-01-30 14:01:10 +0100 | [diff] [blame] | 5628 | (struct weston_seat *) keyboard->seat, true); |
Kristian Høgsberg | 0704539 | 2012-02-19 18:52:44 -0500 | [diff] [blame] | 5629 | wl_list_remove(&switcher->listener.link); |
Kristian Høgsberg | 29139d4 | 2013-04-18 15:25:39 -0400 | [diff] [blame] | 5630 | weston_keyboard_end_grab(keyboard); |
| 5631 | if (keyboard->input_method_resource) |
| 5632 | keyboard->grab = &keyboard->input_method_grab; |
Manuel Bachmann | c1ae2e8 | 2014-02-26 15:53:11 +0100 | [diff] [blame] | 5633 | |
| 5634 | /* re-hide surfaces that were temporary shown during the switch */ |
| 5635 | struct weston_view **minimized; |
| 5636 | wl_array_for_each(minimized, &switcher->minimized_array) { |
| 5637 | /* with the exception of the current selected */ |
| 5638 | if ((*minimized)->surface != switcher->current) { |
Giulio Camuffo | 412e6a5 | 2014-07-09 22:12:56 +0300 | [diff] [blame] | 5639 | weston_layer_entry_remove(&(*minimized)->layer_link); |
| 5640 | 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] | 5641 | weston_view_damage_below(*minimized); |
| 5642 | } |
| 5643 | } |
| 5644 | wl_array_release(&switcher->minimized_array); |
| 5645 | |
Kristian Høgsberg | 0704539 | 2012-02-19 18:52:44 -0500 | [diff] [blame] | 5646 | free(switcher); |
| 5647 | } |
| 5648 | |
| 5649 | static void |
Kristian Høgsberg | 29139d4 | 2013-04-18 15:25:39 -0400 | [diff] [blame] | 5650 | switcher_key(struct weston_keyboard_grab *grab, |
Daniel Stone | c9785ea | 2012-05-30 16:31:52 +0100 | [diff] [blame] | 5651 | uint32_t time, uint32_t key, uint32_t state_w) |
Kristian Høgsberg | 0704539 | 2012-02-19 18:52:44 -0500 | [diff] [blame] | 5652 | { |
| 5653 | struct switcher *switcher = container_of(grab, struct switcher, grab); |
Daniel Stone | c9785ea | 2012-05-30 16:31:52 +0100 | [diff] [blame] | 5654 | enum wl_keyboard_key_state state = state_w; |
Daniel Stone | 351eb61 | 2012-05-31 15:27:47 -0400 | [diff] [blame] | 5655 | |
Daniel Stone | c9785ea | 2012-05-30 16:31:52 +0100 | [diff] [blame] | 5656 | if (key == KEY_TAB && state == WL_KEYBOARD_KEY_STATE_PRESSED) |
Daniel Stone | 351eb61 | 2012-05-31 15:27:47 -0400 | [diff] [blame] | 5657 | switcher_next(switcher); |
| 5658 | } |
| 5659 | |
| 5660 | static void |
Kristian Høgsberg | 29139d4 | 2013-04-18 15:25:39 -0400 | [diff] [blame] | 5661 | switcher_modifier(struct weston_keyboard_grab *grab, uint32_t serial, |
Daniel Stone | 351eb61 | 2012-05-31 15:27:47 -0400 | [diff] [blame] | 5662 | uint32_t mods_depressed, uint32_t mods_latched, |
| 5663 | uint32_t mods_locked, uint32_t group) |
| 5664 | { |
| 5665 | struct switcher *switcher = container_of(grab, struct switcher, grab); |
Daniel Stone | 37816df | 2012-05-16 18:45:18 +0100 | [diff] [blame] | 5666 | struct weston_seat *seat = (struct weston_seat *) grab->keyboard->seat; |
Kristian Høgsberg | 0704539 | 2012-02-19 18:52:44 -0500 | [diff] [blame] | 5667 | |
Daniel Stone | 351eb61 | 2012-05-31 15:27:47 -0400 | [diff] [blame] | 5668 | if ((seat->modifier_state & switcher->shell->binding_modifier) == 0) |
| 5669 | switcher_destroy(switcher); |
Kristian Høgsberg | b71302e | 2012-05-10 12:28:35 -0400 | [diff] [blame] | 5670 | } |
Kristian Høgsberg | 0704539 | 2012-02-19 18:52:44 -0500 | [diff] [blame] | 5671 | |
Jonas Ådahl | 1ea343e | 2013-10-25 23:18:05 +0200 | [diff] [blame] | 5672 | static void |
| 5673 | switcher_cancel(struct weston_keyboard_grab *grab) |
| 5674 | { |
| 5675 | struct switcher *switcher = container_of(grab, struct switcher, grab); |
| 5676 | |
| 5677 | switcher_destroy(switcher); |
| 5678 | } |
| 5679 | |
Kristian Høgsberg | 29139d4 | 2013-04-18 15:25:39 -0400 | [diff] [blame] | 5680 | static const struct weston_keyboard_grab_interface switcher_grab = { |
Daniel Stone | 351eb61 | 2012-05-31 15:27:47 -0400 | [diff] [blame] | 5681 | switcher_key, |
| 5682 | switcher_modifier, |
Jonas Ådahl | 1ea343e | 2013-10-25 23:18:05 +0200 | [diff] [blame] | 5683 | switcher_cancel, |
Kristian Høgsberg | 0704539 | 2012-02-19 18:52:44 -0500 | [diff] [blame] | 5684 | }; |
| 5685 | |
| 5686 | static void |
Kristian Høgsberg | e314875 | 2013-05-06 23:19:49 -0400 | [diff] [blame] | 5687 | switcher_binding(struct weston_seat *seat, uint32_t time, uint32_t key, |
Daniel Stone | 325fc2d | 2012-05-30 16:31:58 +0100 | [diff] [blame] | 5688 | void *data) |
Kristian Høgsberg | 0704539 | 2012-02-19 18:52:44 -0500 | [diff] [blame] | 5689 | { |
Tiago Vignatti | be14326 | 2012-04-16 17:31:41 +0300 | [diff] [blame] | 5690 | struct desktop_shell *shell = data; |
Kristian Høgsberg | 0704539 | 2012-02-19 18:52:44 -0500 | [diff] [blame] | 5691 | struct switcher *switcher; |
| 5692 | |
| 5693 | switcher = malloc(sizeof *switcher); |
Kristian Høgsberg | 02e79dc | 2012-04-12 09:55:26 -0400 | [diff] [blame] | 5694 | switcher->shell = shell; |
Kristian Høgsberg | 0704539 | 2012-02-19 18:52:44 -0500 | [diff] [blame] | 5695 | switcher->current = NULL; |
Kristian Høgsberg | 27e3052 | 2012-04-11 23:18:23 -0400 | [diff] [blame] | 5696 | switcher->listener.notify = switcher_handle_surface_destroy; |
Kristian Høgsberg | 0704539 | 2012-02-19 18:52:44 -0500 | [diff] [blame] | 5697 | wl_list_init(&switcher->listener.link); |
Manuel Bachmann | c1ae2e8 | 2014-02-26 15:53:11 +0100 | [diff] [blame] | 5698 | wl_array_init(&switcher->minimized_array); |
Kristian Høgsberg | 0704539 | 2012-02-19 18:52:44 -0500 | [diff] [blame] | 5699 | |
Alexander Larsson | f82b6ca | 2013-05-28 16:23:39 +0200 | [diff] [blame] | 5700 | restore_all_output_modes(shell->compositor); |
Kristian Høgsberg | b0d8e77 | 2012-06-18 16:34:58 -0400 | [diff] [blame] | 5701 | lower_fullscreen_layer(switcher->shell); |
Kristian Høgsberg | 0704539 | 2012-02-19 18:52:44 -0500 | [diff] [blame] | 5702 | switcher->grab.interface = &switcher_grab; |
Kristian Høgsberg | 29139d4 | 2013-04-18 15:25:39 -0400 | [diff] [blame] | 5703 | weston_keyboard_start_grab(seat->keyboard, &switcher->grab); |
| 5704 | weston_keyboard_set_focus(seat->keyboard, NULL); |
Kristian Høgsberg | 0704539 | 2012-02-19 18:52:44 -0500 | [diff] [blame] | 5705 | switcher_next(switcher); |
| 5706 | } |
| 5707 | |
Pekka Paalanen | 3c64723 | 2011-12-22 13:43:43 +0200 | [diff] [blame] | 5708 | static void |
Kristian Høgsberg | e314875 | 2013-05-06 23:19:49 -0400 | [diff] [blame] | 5709 | backlight_binding(struct weston_seat *seat, uint32_t time, uint32_t key, |
Daniel Stone | 325fc2d | 2012-05-30 16:31:58 +0100 | [diff] [blame] | 5710 | void *data) |
Tiago Vignatti | 8e53c7f | 2012-02-29 19:53:50 +0200 | [diff] [blame] | 5711 | { |
| 5712 | struct weston_compositor *compositor = data; |
| 5713 | struct weston_output *output; |
Tiago Vignatti | 5ab91ad | 2012-03-12 19:40:09 -0300 | [diff] [blame] | 5714 | long backlight_new = 0; |
Tiago Vignatti | 8e53c7f | 2012-02-29 19:53:50 +0200 | [diff] [blame] | 5715 | |
| 5716 | /* TODO: we're limiting to simple use cases, where we assume just |
| 5717 | * control on the primary display. We'd have to extend later if we |
| 5718 | * ever get support for setting backlights on random desktop LCD |
| 5719 | * panels though */ |
| 5720 | output = get_default_output(compositor); |
| 5721 | if (!output) |
| 5722 | return; |
| 5723 | |
| 5724 | if (!output->set_backlight) |
| 5725 | return; |
| 5726 | |
Tiago Vignatti | 5ab91ad | 2012-03-12 19:40:09 -0300 | [diff] [blame] | 5727 | if (key == KEY_F9 || key == KEY_BRIGHTNESSDOWN) |
| 5728 | backlight_new = output->backlight_current - 25; |
| 5729 | else if (key == KEY_F10 || key == KEY_BRIGHTNESSUP) |
| 5730 | backlight_new = output->backlight_current + 25; |
Tiago Vignatti | 8e53c7f | 2012-02-29 19:53:50 +0200 | [diff] [blame] | 5731 | |
Tiago Vignatti | 5ab91ad | 2012-03-12 19:40:09 -0300 | [diff] [blame] | 5732 | if (backlight_new < 5) |
| 5733 | backlight_new = 5; |
| 5734 | if (backlight_new > 255) |
| 5735 | backlight_new = 255; |
| 5736 | |
| 5737 | output->backlight_current = backlight_new; |
Tiago Vignatti | 8e53c7f | 2012-02-29 19:53:50 +0200 | [diff] [blame] | 5738 | output->set_backlight(output, output->backlight_current); |
| 5739 | } |
| 5740 | |
Ander Conselvan de Oliveira | c509d2b | 2012-11-08 17:20:45 +0200 | [diff] [blame] | 5741 | struct debug_binding_grab { |
Kristian Høgsberg | 29139d4 | 2013-04-18 15:25:39 -0400 | [diff] [blame] | 5742 | struct weston_keyboard_grab grab; |
Ander Conselvan de Oliveira | c509d2b | 2012-11-08 17:20:45 +0200 | [diff] [blame] | 5743 | struct weston_seat *seat; |
| 5744 | uint32_t key[2]; |
| 5745 | int key_released[2]; |
| 5746 | }; |
| 5747 | |
| 5748 | static void |
Kristian Høgsberg | 29139d4 | 2013-04-18 15:25:39 -0400 | [diff] [blame] | 5749 | debug_binding_key(struct weston_keyboard_grab *grab, uint32_t time, |
Ander Conselvan de Oliveira | c509d2b | 2012-11-08 17:20:45 +0200 | [diff] [blame] | 5750 | uint32_t key, uint32_t state) |
| 5751 | { |
| 5752 | struct debug_binding_grab *db = (struct debug_binding_grab *) grab; |
Rob Bradford | 880ebc7 | 2013-07-22 17:31:38 +0100 | [diff] [blame] | 5753 | struct weston_compositor *ec = db->seat->compositor; |
| 5754 | struct wl_display *display = ec->wl_display; |
Ander Conselvan de Oliveira | c509d2b | 2012-11-08 17:20:45 +0200 | [diff] [blame] | 5755 | struct wl_resource *resource; |
Ander Conselvan de Oliveira | c509d2b | 2012-11-08 17:20:45 +0200 | [diff] [blame] | 5756 | uint32_t serial; |
| 5757 | int send = 0, terminate = 0; |
| 5758 | int check_binding = 1; |
| 5759 | int i; |
Neil Roberts | 96d790e | 2013-09-19 17:32:00 +0100 | [diff] [blame] | 5760 | struct wl_list *resource_list; |
Ander Conselvan de Oliveira | c509d2b | 2012-11-08 17:20:45 +0200 | [diff] [blame] | 5761 | |
| 5762 | if (state == WL_KEYBOARD_KEY_STATE_RELEASED) { |
| 5763 | /* Do not run bindings on key releases */ |
| 5764 | check_binding = 0; |
| 5765 | |
| 5766 | for (i = 0; i < 2; i++) |
| 5767 | if (key == db->key[i]) |
| 5768 | db->key_released[i] = 1; |
| 5769 | |
| 5770 | if (db->key_released[0] && db->key_released[1]) { |
| 5771 | /* All key releases been swalled so end the grab */ |
| 5772 | terminate = 1; |
| 5773 | } else if (key != db->key[0] && key != db->key[1]) { |
| 5774 | /* Should not swallow release of other keys */ |
| 5775 | send = 1; |
| 5776 | } |
| 5777 | } else if (key == db->key[0] && !db->key_released[0]) { |
| 5778 | /* Do not check bindings for the first press of the binding |
| 5779 | * key. This allows it to be used as a debug shortcut. |
| 5780 | * We still need to swallow this event. */ |
| 5781 | check_binding = 0; |
| 5782 | } else if (db->key[1]) { |
| 5783 | /* If we already ran a binding don't process another one since |
| 5784 | * we can't keep track of all the binding keys that were |
| 5785 | * pressed in order to swallow the release events. */ |
| 5786 | send = 1; |
| 5787 | check_binding = 0; |
| 5788 | } |
| 5789 | |
| 5790 | if (check_binding) { |
Ander Conselvan de Oliveira | c509d2b | 2012-11-08 17:20:45 +0200 | [diff] [blame] | 5791 | if (weston_compositor_run_debug_binding(ec, db->seat, time, |
| 5792 | key, state)) { |
| 5793 | /* We ran a binding so swallow the press and keep the |
| 5794 | * grab to swallow the released too. */ |
| 5795 | send = 0; |
| 5796 | terminate = 0; |
| 5797 | db->key[1] = key; |
| 5798 | } else { |
| 5799 | /* Terminate the grab since the key pressed is not a |
| 5800 | * debug binding key. */ |
| 5801 | send = 1; |
| 5802 | terminate = 1; |
| 5803 | } |
| 5804 | } |
| 5805 | |
| 5806 | if (send) { |
Neil Roberts | 96d790e | 2013-09-19 17:32:00 +0100 | [diff] [blame] | 5807 | serial = wl_display_next_serial(display); |
| 5808 | resource_list = &grab->keyboard->focus_resource_list; |
| 5809 | wl_resource_for_each(resource, resource_list) { |
Ander Conselvan de Oliveira | c509d2b | 2012-11-08 17:20:45 +0200 | [diff] [blame] | 5810 | wl_keyboard_send_key(resource, serial, time, key, state); |
| 5811 | } |
| 5812 | } |
| 5813 | |
| 5814 | if (terminate) { |
Kristian Høgsberg | 29139d4 | 2013-04-18 15:25:39 -0400 | [diff] [blame] | 5815 | weston_keyboard_end_grab(grab->keyboard); |
| 5816 | if (grab->keyboard->input_method_resource) |
| 5817 | grab->keyboard->grab = &grab->keyboard->input_method_grab; |
Ander Conselvan de Oliveira | c509d2b | 2012-11-08 17:20:45 +0200 | [diff] [blame] | 5818 | free(db); |
| 5819 | } |
| 5820 | } |
| 5821 | |
| 5822 | static void |
Kristian Høgsberg | 29139d4 | 2013-04-18 15:25:39 -0400 | [diff] [blame] | 5823 | debug_binding_modifiers(struct weston_keyboard_grab *grab, uint32_t serial, |
Ander Conselvan de Oliveira | c509d2b | 2012-11-08 17:20:45 +0200 | [diff] [blame] | 5824 | uint32_t mods_depressed, uint32_t mods_latched, |
| 5825 | uint32_t mods_locked, uint32_t group) |
| 5826 | { |
| 5827 | struct wl_resource *resource; |
Neil Roberts | 96d790e | 2013-09-19 17:32:00 +0100 | [diff] [blame] | 5828 | struct wl_list *resource_list; |
Ander Conselvan de Oliveira | c509d2b | 2012-11-08 17:20:45 +0200 | [diff] [blame] | 5829 | |
Neil Roberts | 96d790e | 2013-09-19 17:32:00 +0100 | [diff] [blame] | 5830 | resource_list = &grab->keyboard->focus_resource_list; |
Ander Conselvan de Oliveira | c509d2b | 2012-11-08 17:20:45 +0200 | [diff] [blame] | 5831 | |
Neil Roberts | 96d790e | 2013-09-19 17:32:00 +0100 | [diff] [blame] | 5832 | wl_resource_for_each(resource, resource_list) { |
| 5833 | wl_keyboard_send_modifiers(resource, serial, mods_depressed, |
| 5834 | mods_latched, mods_locked, group); |
| 5835 | } |
Ander Conselvan de Oliveira | c509d2b | 2012-11-08 17:20:45 +0200 | [diff] [blame] | 5836 | } |
| 5837 | |
Jonas Ådahl | 1ea343e | 2013-10-25 23:18:05 +0200 | [diff] [blame] | 5838 | static void |
| 5839 | debug_binding_cancel(struct weston_keyboard_grab *grab) |
| 5840 | { |
| 5841 | struct debug_binding_grab *db = (struct debug_binding_grab *) grab; |
| 5842 | |
| 5843 | weston_keyboard_end_grab(grab->keyboard); |
| 5844 | free(db); |
| 5845 | } |
| 5846 | |
Kristian Høgsberg | 29139d4 | 2013-04-18 15:25:39 -0400 | [diff] [blame] | 5847 | struct weston_keyboard_grab_interface debug_binding_keyboard_grab = { |
Ander Conselvan de Oliveira | c509d2b | 2012-11-08 17:20:45 +0200 | [diff] [blame] | 5848 | debug_binding_key, |
Jonas Ådahl | 1ea343e | 2013-10-25 23:18:05 +0200 | [diff] [blame] | 5849 | debug_binding_modifiers, |
| 5850 | debug_binding_cancel, |
Ander Conselvan de Oliveira | c509d2b | 2012-11-08 17:20:45 +0200 | [diff] [blame] | 5851 | }; |
| 5852 | |
| 5853 | static void |
Kristian Høgsberg | e314875 | 2013-05-06 23:19:49 -0400 | [diff] [blame] | 5854 | debug_binding(struct weston_seat *seat, uint32_t time, uint32_t key, void *data) |
Ander Conselvan de Oliveira | c509d2b | 2012-11-08 17:20:45 +0200 | [diff] [blame] | 5855 | { |
| 5856 | struct debug_binding_grab *grab; |
| 5857 | |
| 5858 | grab = calloc(1, sizeof *grab); |
| 5859 | if (!grab) |
| 5860 | return; |
| 5861 | |
| 5862 | grab->seat = (struct weston_seat *) seat; |
| 5863 | grab->key[0] = key; |
| 5864 | grab->grab.interface = &debug_binding_keyboard_grab; |
Kristian Høgsberg | 29139d4 | 2013-04-18 15:25:39 -0400 | [diff] [blame] | 5865 | weston_keyboard_start_grab(seat->keyboard, &grab->grab); |
Ander Conselvan de Oliveira | c509d2b | 2012-11-08 17:20:45 +0200 | [diff] [blame] | 5866 | } |
| 5867 | |
Kristian Høgsberg | b41c081 | 2012-03-04 14:53:40 -0500 | [diff] [blame] | 5868 | static void |
Kristian Høgsberg | e314875 | 2013-05-06 23:19:49 -0400 | [diff] [blame] | 5869 | 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] | 5870 | void *data) |
Kristian Høgsberg | 92a57db | 2012-05-26 13:41:06 -0400 | [diff] [blame] | 5871 | { |
Kristian Høgsberg | fe7aa90 | 2013-05-08 09:54:37 -0400 | [diff] [blame] | 5872 | struct weston_surface *focus_surface; |
Kristian Høgsberg | 92a57db | 2012-05-26 13:41:06 -0400 | [diff] [blame] | 5873 | struct wl_client *client; |
Tiago Vignatti | 1d01b01 | 2012-09-27 17:48:36 +0300 | [diff] [blame] | 5874 | struct desktop_shell *shell = data; |
| 5875 | struct weston_compositor *compositor = shell->compositor; |
Kristian Høgsberg | 92a57db | 2012-05-26 13:41:06 -0400 | [diff] [blame] | 5876 | pid_t pid; |
Kristian Høgsberg | 92a57db | 2012-05-26 13:41:06 -0400 | [diff] [blame] | 5877 | |
Philipp Brüschweiler | 6cef009 | 2012-08-13 21:27:27 +0200 | [diff] [blame] | 5878 | focus_surface = seat->keyboard->focus; |
| 5879 | if (!focus_surface) |
| 5880 | return; |
| 5881 | |
Tiago Vignatti | 1d01b01 | 2012-09-27 17:48:36 +0300 | [diff] [blame] | 5882 | wl_signal_emit(&compositor->kill_signal, focus_surface); |
| 5883 | |
Jason Ekstrand | 26ed73c | 2013-06-06 22:34:41 -0500 | [diff] [blame] | 5884 | client = wl_resource_get_client(focus_surface->resource); |
Tiago Vignatti | 920f197 | 2012-09-27 17:48:35 +0300 | [diff] [blame] | 5885 | wl_client_get_credentials(client, &pid, NULL, NULL); |
| 5886 | |
| 5887 | /* Skip clients that we launched ourselves (the credentials of |
| 5888 | * the socketpair is ours) */ |
| 5889 | if (pid == getpid()) |
| 5890 | return; |
Kristian Høgsberg | 92a57db | 2012-05-26 13:41:06 -0400 | [diff] [blame] | 5891 | |
Daniel Stone | 325fc2d | 2012-05-30 16:31:58 +0100 | [diff] [blame] | 5892 | kill(pid, SIGKILL); |
Kristian Høgsberg | 92a57db | 2012-05-26 13:41:06 -0400 | [diff] [blame] | 5893 | } |
| 5894 | |
| 5895 | static void |
Kristian Høgsberg | e314875 | 2013-05-06 23:19:49 -0400 | [diff] [blame] | 5896 | workspace_up_binding(struct weston_seat *seat, uint32_t time, |
Jonas Ådahl | e3cddce | 2012-06-13 00:01:22 +0200 | [diff] [blame] | 5897 | uint32_t key, void *data) |
| 5898 | { |
| 5899 | struct desktop_shell *shell = data; |
| 5900 | unsigned int new_index = shell->workspaces.current; |
| 5901 | |
Kristian Høgsberg | ce345b0 | 2012-06-25 21:35:29 -0400 | [diff] [blame] | 5902 | if (shell->locked) |
Kristian Høgsberg | 4476aaf | 2012-06-25 14:03:13 -0400 | [diff] [blame] | 5903 | return; |
Jonas Ådahl | e3cddce | 2012-06-13 00:01:22 +0200 | [diff] [blame] | 5904 | if (new_index != 0) |
| 5905 | new_index--; |
| 5906 | |
| 5907 | change_workspace(shell, new_index); |
| 5908 | } |
| 5909 | |
| 5910 | static void |
Kristian Høgsberg | e314875 | 2013-05-06 23:19:49 -0400 | [diff] [blame] | 5911 | workspace_down_binding(struct weston_seat *seat, uint32_t time, |
Jonas Ådahl | e3cddce | 2012-06-13 00:01:22 +0200 | [diff] [blame] | 5912 | uint32_t key, void *data) |
| 5913 | { |
| 5914 | struct desktop_shell *shell = data; |
| 5915 | unsigned int new_index = shell->workspaces.current; |
| 5916 | |
Kristian Høgsberg | ce345b0 | 2012-06-25 21:35:29 -0400 | [diff] [blame] | 5917 | if (shell->locked) |
Kristian Høgsberg | 4476aaf | 2012-06-25 14:03:13 -0400 | [diff] [blame] | 5918 | return; |
Jonas Ådahl | e3cddce | 2012-06-13 00:01:22 +0200 | [diff] [blame] | 5919 | if (new_index < shell->workspaces.num - 1) |
| 5920 | new_index++; |
| 5921 | |
| 5922 | change_workspace(shell, new_index); |
| 5923 | } |
| 5924 | |
| 5925 | static void |
Kristian Høgsberg | e314875 | 2013-05-06 23:19:49 -0400 | [diff] [blame] | 5926 | workspace_f_binding(struct weston_seat *seat, uint32_t time, |
Jonas Ådahl | e3cddce | 2012-06-13 00:01:22 +0200 | [diff] [blame] | 5927 | uint32_t key, void *data) |
| 5928 | { |
| 5929 | struct desktop_shell *shell = data; |
| 5930 | unsigned int new_index; |
| 5931 | |
Kristian Høgsberg | ce345b0 | 2012-06-25 21:35:29 -0400 | [diff] [blame] | 5932 | if (shell->locked) |
Kristian Høgsberg | 4476aaf | 2012-06-25 14:03:13 -0400 | [diff] [blame] | 5933 | return; |
Jonas Ådahl | e3cddce | 2012-06-13 00:01:22 +0200 | [diff] [blame] | 5934 | new_index = key - KEY_F1; |
| 5935 | if (new_index >= shell->workspaces.num) |
| 5936 | new_index = shell->workspaces.num - 1; |
| 5937 | |
| 5938 | change_workspace(shell, new_index); |
| 5939 | } |
| 5940 | |
Jonas Ådahl | 8de6a1d | 2012-08-29 22:13:00 +0200 | [diff] [blame] | 5941 | static void |
Kristian Høgsberg | e314875 | 2013-05-06 23:19:49 -0400 | [diff] [blame] | 5942 | workspace_move_surface_up_binding(struct weston_seat *seat, uint32_t time, |
Jonas Ådahl | 8de6a1d | 2012-08-29 22:13:00 +0200 | [diff] [blame] | 5943 | uint32_t key, void *data) |
| 5944 | { |
| 5945 | struct desktop_shell *shell = data; |
| 5946 | unsigned int new_index = shell->workspaces.current; |
| 5947 | |
| 5948 | if (shell->locked) |
| 5949 | return; |
| 5950 | |
| 5951 | if (new_index != 0) |
| 5952 | new_index--; |
| 5953 | |
| 5954 | take_surface_to_workspace_by_seat(shell, seat, new_index); |
| 5955 | } |
| 5956 | |
| 5957 | static void |
Kristian Høgsberg | e314875 | 2013-05-06 23:19:49 -0400 | [diff] [blame] | 5958 | workspace_move_surface_down_binding(struct weston_seat *seat, uint32_t time, |
Jonas Ådahl | 8de6a1d | 2012-08-29 22:13:00 +0200 | [diff] [blame] | 5959 | uint32_t key, void *data) |
| 5960 | { |
| 5961 | struct desktop_shell *shell = data; |
| 5962 | unsigned int new_index = shell->workspaces.current; |
| 5963 | |
| 5964 | if (shell->locked) |
| 5965 | return; |
| 5966 | |
| 5967 | if (new_index < shell->workspaces.num - 1) |
| 5968 | new_index++; |
| 5969 | |
| 5970 | take_surface_to_workspace_by_seat(shell, seat, new_index); |
| 5971 | } |
Jonas Ådahl | e3cddce | 2012-06-13 00:01:22 +0200 | [diff] [blame] | 5972 | |
| 5973 | static void |
Ander Conselvan de Oliveira | c94d622 | 2014-01-29 18:47:54 +0200 | [diff] [blame] | 5974 | shell_reposition_view_on_output_destroy(struct weston_view *view) |
| 5975 | { |
| 5976 | struct weston_output *output, *first_output; |
| 5977 | struct weston_compositor *ec = view->surface->compositor; |
| 5978 | struct shell_surface *shsurf; |
| 5979 | float x, y; |
| 5980 | int visible; |
| 5981 | |
| 5982 | x = view->geometry.x; |
| 5983 | y = view->geometry.y; |
| 5984 | |
| 5985 | /* At this point the destroyed output is not in the list anymore. |
| 5986 | * If the view is still visible somewhere, we leave where it is, |
| 5987 | * otherwise, move it to the first output. */ |
| 5988 | visible = 0; |
| 5989 | wl_list_for_each(output, &ec->output_list, link) { |
| 5990 | if (pixman_region32_contains_point(&output->region, |
| 5991 | x, y, NULL)) { |
| 5992 | visible = 1; |
| 5993 | break; |
| 5994 | } |
| 5995 | } |
| 5996 | |
| 5997 | if (!visible) { |
| 5998 | first_output = container_of(ec->output_list.next, |
| 5999 | struct weston_output, link); |
| 6000 | |
| 6001 | x = first_output->x + first_output->width / 4; |
| 6002 | y = first_output->y + first_output->height / 4; |
Xiong Zhang | 62899f5 | 2014-03-07 16:27:19 +0800 | [diff] [blame] | 6003 | |
| 6004 | weston_view_set_position(view, x, y); |
| 6005 | } else { |
| 6006 | weston_view_geometry_dirty(view); |
Ander Conselvan de Oliveira | c94d622 | 2014-01-29 18:47:54 +0200 | [diff] [blame] | 6007 | } |
| 6008 | |
Ander Conselvan de Oliveira | c94d622 | 2014-01-29 18:47:54 +0200 | [diff] [blame] | 6009 | |
| 6010 | shsurf = get_shell_surface(view->surface); |
| 6011 | |
| 6012 | if (shsurf) { |
| 6013 | shsurf->saved_position_valid = false; |
| 6014 | shsurf->next_state.maximized = false; |
| 6015 | shsurf->next_state.fullscreen = false; |
| 6016 | shsurf->state_changed = true; |
| 6017 | } |
| 6018 | } |
| 6019 | |
Ander Conselvan de Oliveira | 304996d | 2014-04-11 13:57:15 +0300 | [diff] [blame] | 6020 | void |
| 6021 | shell_for_each_layer(struct desktop_shell *shell, |
| 6022 | shell_for_each_layer_func_t func, void *data) |
Ander Conselvan de Oliveira | c94d622 | 2014-01-29 18:47:54 +0200 | [diff] [blame] | 6023 | { |
Ander Conselvan de Oliveira | 304996d | 2014-04-11 13:57:15 +0300 | [diff] [blame] | 6024 | struct workspace **ws; |
| 6025 | |
| 6026 | func(shell, &shell->fullscreen_layer, data); |
| 6027 | func(shell, &shell->panel_layer, data); |
| 6028 | func(shell, &shell->background_layer, data); |
| 6029 | func(shell, &shell->lock_layer, data); |
| 6030 | func(shell, &shell->input_panel_layer, data); |
| 6031 | |
| 6032 | wl_array_for_each(ws, &shell->workspaces.array) |
| 6033 | func(shell, &(*ws)->layer, data); |
| 6034 | } |
| 6035 | |
| 6036 | static void |
| 6037 | shell_output_destroy_move_layer(struct desktop_shell *shell, |
| 6038 | struct weston_layer *layer, |
| 6039 | void *data) |
| 6040 | { |
| 6041 | struct weston_output *output = data; |
Ander Conselvan de Oliveira | c94d622 | 2014-01-29 18:47:54 +0200 | [diff] [blame] | 6042 | struct weston_view *view; |
| 6043 | |
Giulio Camuffo | 412e6a5 | 2014-07-09 22:12:56 +0300 | [diff] [blame] | 6044 | 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] | 6045 | if (view->output != output) |
| 6046 | continue; |
Ander Conselvan de Oliveira | c94d622 | 2014-01-29 18:47:54 +0200 | [diff] [blame] | 6047 | |
Ander Conselvan de Oliveira | 304996d | 2014-04-11 13:57:15 +0300 | [diff] [blame] | 6048 | shell_reposition_view_on_output_destroy(view); |
Ander Conselvan de Oliveira | c94d622 | 2014-01-29 18:47:54 +0200 | [diff] [blame] | 6049 | } |
| 6050 | } |
| 6051 | |
| 6052 | static void |
Xiong Zhang | 6b48142 | 2013-10-23 13:58:32 +0800 | [diff] [blame] | 6053 | handle_output_destroy(struct wl_listener *listener, void *data) |
| 6054 | { |
| 6055 | struct shell_output *output_listener = |
| 6056 | container_of(listener, struct shell_output, destroy_listener); |
Ander Conselvan de Oliveira | 304996d | 2014-04-11 13:57:15 +0300 | [diff] [blame] | 6057 | struct weston_output *output = output_listener->output; |
| 6058 | struct desktop_shell *shell = output_listener->shell; |
Xiong Zhang | 6b48142 | 2013-10-23 13:58:32 +0800 | [diff] [blame] | 6059 | |
Ander Conselvan de Oliveira | 304996d | 2014-04-11 13:57:15 +0300 | [diff] [blame] | 6060 | 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] | 6061 | |
Xiong Zhang | 6b48142 | 2013-10-23 13:58:32 +0800 | [diff] [blame] | 6062 | wl_list_remove(&output_listener->destroy_listener.link); |
| 6063 | wl_list_remove(&output_listener->link); |
| 6064 | free(output_listener); |
| 6065 | } |
| 6066 | |
| 6067 | static void |
| 6068 | create_shell_output(struct desktop_shell *shell, |
| 6069 | struct weston_output *output) |
| 6070 | { |
| 6071 | struct shell_output *shell_output; |
| 6072 | |
| 6073 | shell_output = zalloc(sizeof *shell_output); |
| 6074 | if (shell_output == NULL) |
| 6075 | return; |
| 6076 | |
| 6077 | shell_output->output = output; |
| 6078 | shell_output->shell = shell; |
| 6079 | shell_output->destroy_listener.notify = handle_output_destroy; |
| 6080 | wl_signal_add(&output->destroy_signal, |
| 6081 | &shell_output->destroy_listener); |
Kristian Høgsberg | a3a0e18 | 2013-10-23 23:36:04 -0700 | [diff] [blame] | 6082 | wl_list_insert(shell->output_list.prev, &shell_output->link); |
Xiong Zhang | 6b48142 | 2013-10-23 13:58:32 +0800 | [diff] [blame] | 6083 | } |
| 6084 | |
| 6085 | static void |
| 6086 | handle_output_create(struct wl_listener *listener, void *data) |
| 6087 | { |
| 6088 | struct desktop_shell *shell = |
| 6089 | container_of(listener, struct desktop_shell, output_create_listener); |
| 6090 | struct weston_output *output = (struct weston_output *)data; |
| 6091 | |
| 6092 | create_shell_output(shell, output); |
| 6093 | } |
| 6094 | |
| 6095 | static void |
Ander Conselvan de Oliveira | 304996d | 2014-04-11 13:57:15 +0300 | [diff] [blame] | 6096 | handle_output_move_layer(struct desktop_shell *shell, |
| 6097 | struct weston_layer *layer, void *data) |
Ander Conselvan de Oliveira | a8a9baf | 2014-01-29 18:47:52 +0200 | [diff] [blame] | 6098 | { |
Ander Conselvan de Oliveira | 304996d | 2014-04-11 13:57:15 +0300 | [diff] [blame] | 6099 | struct weston_output *output = data; |
Ander Conselvan de Oliveira | a8a9baf | 2014-01-29 18:47:52 +0200 | [diff] [blame] | 6100 | struct weston_view *view; |
| 6101 | float x, y; |
| 6102 | |
Giulio Camuffo | 412e6a5 | 2014-07-09 22:12:56 +0300 | [diff] [blame] | 6103 | 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] | 6104 | if (view->output != output) |
| 6105 | continue; |
| 6106 | |
| 6107 | x = view->geometry.x + output->move_x; |
| 6108 | y = view->geometry.y + output->move_y; |
| 6109 | weston_view_set_position(view, x, y); |
| 6110 | } |
| 6111 | } |
| 6112 | |
| 6113 | static void |
| 6114 | handle_output_move(struct wl_listener *listener, void *data) |
| 6115 | { |
| 6116 | struct desktop_shell *shell; |
| 6117 | |
Ander Conselvan de Oliveira | a8a9baf | 2014-01-29 18:47:52 +0200 | [diff] [blame] | 6118 | shell = container_of(listener, struct desktop_shell, |
| 6119 | output_move_listener); |
Ander Conselvan de Oliveira | a8a9baf | 2014-01-29 18:47:52 +0200 | [diff] [blame] | 6120 | |
Ander Conselvan de Oliveira | 304996d | 2014-04-11 13:57:15 +0300 | [diff] [blame] | 6121 | shell_for_each_layer(shell, handle_output_move_layer, data); |
Ander Conselvan de Oliveira | a8a9baf | 2014-01-29 18:47:52 +0200 | [diff] [blame] | 6122 | } |
| 6123 | |
| 6124 | static void |
Xiong Zhang | 6b48142 | 2013-10-23 13:58:32 +0800 | [diff] [blame] | 6125 | setup_output_destroy_handler(struct weston_compositor *ec, |
| 6126 | struct desktop_shell *shell) |
| 6127 | { |
| 6128 | struct weston_output *output; |
| 6129 | |
| 6130 | wl_list_init(&shell->output_list); |
| 6131 | wl_list_for_each(output, &ec->output_list, link) |
| 6132 | create_shell_output(shell, output); |
| 6133 | |
| 6134 | shell->output_create_listener.notify = handle_output_create; |
| 6135 | wl_signal_add(&ec->output_created_signal, |
| 6136 | &shell->output_create_listener); |
Ander Conselvan de Oliveira | a8a9baf | 2014-01-29 18:47:52 +0200 | [diff] [blame] | 6137 | |
| 6138 | shell->output_move_listener.notify = handle_output_move; |
| 6139 | wl_signal_add(&ec->output_moved_signal, &shell->output_move_listener); |
Xiong Zhang | 6b48142 | 2013-10-23 13:58:32 +0800 | [diff] [blame] | 6140 | } |
| 6141 | |
| 6142 | static void |
Kristian Høgsberg | 02e79dc | 2012-04-12 09:55:26 -0400 | [diff] [blame] | 6143 | shell_destroy(struct wl_listener *listener, void *data) |
Pekka Paalanen | 3c64723 | 2011-12-22 13:43:43 +0200 | [diff] [blame] | 6144 | { |
Tiago Vignatti | be14326 | 2012-04-16 17:31:41 +0300 | [diff] [blame] | 6145 | struct desktop_shell *shell = |
| 6146 | container_of(listener, struct desktop_shell, destroy_listener); |
Jonas Ådahl | e3cddce | 2012-06-13 00:01:22 +0200 | [diff] [blame] | 6147 | struct workspace **ws; |
Xiong Zhang | 6b48142 | 2013-10-23 13:58:32 +0800 | [diff] [blame] | 6148 | struct shell_output *shell_output, *tmp; |
Pekka Paalanen | 3c64723 | 2011-12-22 13:43:43 +0200 | [diff] [blame] | 6149 | |
Kristian Høgsberg | 17bccae | 2014-01-16 16:46:28 -0800 | [diff] [blame] | 6150 | /* Force state to unlocked so we don't try to fade */ |
| 6151 | shell->locked = false; |
Pekka Paalanen | 9cf5cc8 | 2012-01-02 16:00:24 +0200 | [diff] [blame] | 6152 | if (shell->child.client) |
| 6153 | wl_client_destroy(shell->child.client); |
| 6154 | |
Ander Conselvan de Oliveira | a457563 | 2013-02-21 18:35:23 +0200 | [diff] [blame] | 6155 | wl_list_remove(&shell->idle_listener.link); |
| 6156 | wl_list_remove(&shell->wake_listener.link); |
Kristian Høgsberg | 677a5f5 | 2013-12-04 11:00:19 -0800 | [diff] [blame] | 6157 | |
| 6158 | input_panel_destroy(shell); |
Kristian Høgsberg | 88c1607 | 2012-05-16 08:04:19 -0400 | [diff] [blame] | 6159 | |
Xiong Zhang | 6b48142 | 2013-10-23 13:58:32 +0800 | [diff] [blame] | 6160 | wl_list_for_each_safe(shell_output, tmp, &shell->output_list, link) { |
| 6161 | wl_list_remove(&shell_output->destroy_listener.link); |
| 6162 | wl_list_remove(&shell_output->link); |
| 6163 | free(shell_output); |
| 6164 | } |
| 6165 | |
| 6166 | wl_list_remove(&shell->output_create_listener.link); |
Kristian Høgsberg | 6d50b0f | 2014-04-30 20:46:25 -0700 | [diff] [blame] | 6167 | wl_list_remove(&shell->output_move_listener.link); |
Xiong Zhang | 6b48142 | 2013-10-23 13:58:32 +0800 | [diff] [blame] | 6168 | |
Jonas Ådahl | e3cddce | 2012-06-13 00:01:22 +0200 | [diff] [blame] | 6169 | wl_array_for_each(ws, &shell->workspaces.array) |
| 6170 | workspace_destroy(*ws); |
| 6171 | wl_array_release(&shell->workspaces.array); |
| 6172 | |
Pekka Paalanen | 3c64723 | 2011-12-22 13:43:43 +0200 | [diff] [blame] | 6173 | free(shell->screensaver.path); |
Emilio Pozuelo Monfort | 46ce798 | 2013-11-20 13:22:29 +0100 | [diff] [blame] | 6174 | free(shell->client); |
Pekka Paalanen | 3c64723 | 2011-12-22 13:43:43 +0200 | [diff] [blame] | 6175 | free(shell); |
| 6176 | } |
| 6177 | |
Tiago Vignatti | 0b52d48 | 2012-04-20 18:54:25 +0300 | [diff] [blame] | 6178 | static void |
| 6179 | shell_add_bindings(struct weston_compositor *ec, struct desktop_shell *shell) |
| 6180 | { |
| 6181 | uint32_t mod; |
Jonas Ådahl | e3cddce | 2012-06-13 00:01:22 +0200 | [diff] [blame] | 6182 | int i, num_workspace_bindings; |
Tiago Vignatti | 0b52d48 | 2012-04-20 18:54:25 +0300 | [diff] [blame] | 6183 | |
| 6184 | /* fixed bindings */ |
Daniel Stone | 325fc2d | 2012-05-30 16:31:58 +0100 | [diff] [blame] | 6185 | weston_compositor_add_key_binding(ec, KEY_BACKSPACE, |
| 6186 | MODIFIER_CTRL | MODIFIER_ALT, |
| 6187 | terminate_binding, ec); |
| 6188 | weston_compositor_add_button_binding(ec, BTN_LEFT, 0, |
| 6189 | click_to_activate_binding, |
| 6190 | shell); |
Kristian Høgsberg | f0ce581 | 2014-04-07 11:52:17 -0700 | [diff] [blame] | 6191 | weston_compositor_add_button_binding(ec, BTN_RIGHT, 0, |
| 6192 | click_to_activate_binding, |
| 6193 | shell); |
Neil Roberts | a28c693 | 2013-10-03 16:43:04 +0100 | [diff] [blame] | 6194 | weston_compositor_add_touch_binding(ec, 0, |
| 6195 | touch_to_activate_binding, |
| 6196 | shell); |
Daniel Stone | 325fc2d | 2012-05-30 16:31:58 +0100 | [diff] [blame] | 6197 | weston_compositor_add_axis_binding(ec, WL_POINTER_AXIS_VERTICAL_SCROLL, |
| 6198 | MODIFIER_SUPER | MODIFIER_ALT, |
| 6199 | surface_opacity_binding, NULL); |
| 6200 | weston_compositor_add_axis_binding(ec, WL_POINTER_AXIS_VERTICAL_SCROLL, |
| 6201 | MODIFIER_SUPER, zoom_axis_binding, |
| 6202 | NULL); |
Tiago Vignatti | 0b52d48 | 2012-04-20 18:54:25 +0300 | [diff] [blame] | 6203 | |
| 6204 | /* configurable bindings */ |
| 6205 | mod = shell->binding_modifier; |
Daniel Stone | 325fc2d | 2012-05-30 16:31:58 +0100 | [diff] [blame] | 6206 | weston_compositor_add_key_binding(ec, KEY_PAGEUP, mod, |
| 6207 | zoom_key_binding, NULL); |
| 6208 | weston_compositor_add_key_binding(ec, KEY_PAGEDOWN, mod, |
| 6209 | zoom_key_binding, NULL); |
Kristian Høgsberg | 211b517 | 2014-01-11 13:10:21 -0800 | [diff] [blame] | 6210 | weston_compositor_add_key_binding(ec, KEY_M, mod | MODIFIER_SHIFT, |
| 6211 | maximize_binding, NULL); |
| 6212 | weston_compositor_add_key_binding(ec, KEY_F, mod | MODIFIER_SHIFT, |
| 6213 | fullscreen_binding, NULL); |
Daniel Stone | 325fc2d | 2012-05-30 16:31:58 +0100 | [diff] [blame] | 6214 | weston_compositor_add_button_binding(ec, BTN_LEFT, mod, move_binding, |
| 6215 | shell); |
Neil Roberts | aba0f25 | 2013-10-03 16:43:05 +0100 | [diff] [blame] | 6216 | weston_compositor_add_touch_binding(ec, mod, touch_move_binding, shell); |
Daniel Stone | 325fc2d | 2012-05-30 16:31:58 +0100 | [diff] [blame] | 6217 | weston_compositor_add_button_binding(ec, BTN_MIDDLE, mod, |
| 6218 | resize_binding, shell); |
Kristian Høgsberg | 0837fa9 | 2014-01-20 10:35:26 -0800 | [diff] [blame] | 6219 | weston_compositor_add_button_binding(ec, BTN_LEFT, |
| 6220 | mod | MODIFIER_SHIFT, |
| 6221 | resize_binding, shell); |
Pekka Paalanen | 7bb6510 | 2013-05-22 18:03:04 +0300 | [diff] [blame] | 6222 | |
| 6223 | if (ec->capabilities & WESTON_CAP_ROTATION_ANY) |
| 6224 | weston_compositor_add_button_binding(ec, BTN_RIGHT, mod, |
| 6225 | rotate_binding, NULL); |
| 6226 | |
Daniel Stone | 325fc2d | 2012-05-30 16:31:58 +0100 | [diff] [blame] | 6227 | weston_compositor_add_key_binding(ec, KEY_TAB, mod, switcher_binding, |
| 6228 | shell); |
| 6229 | weston_compositor_add_key_binding(ec, KEY_F9, mod, backlight_binding, |
| 6230 | ec); |
| 6231 | weston_compositor_add_key_binding(ec, KEY_BRIGHTNESSDOWN, 0, |
| 6232 | backlight_binding, ec); |
| 6233 | weston_compositor_add_key_binding(ec, KEY_F10, mod, backlight_binding, |
| 6234 | ec); |
| 6235 | weston_compositor_add_key_binding(ec, KEY_BRIGHTNESSUP, 0, |
| 6236 | backlight_binding, ec); |
Daniel Stone | 325fc2d | 2012-05-30 16:31:58 +0100 | [diff] [blame] | 6237 | weston_compositor_add_key_binding(ec, KEY_K, mod, |
| 6238 | force_kill_binding, shell); |
Jonas Ådahl | e3cddce | 2012-06-13 00:01:22 +0200 | [diff] [blame] | 6239 | weston_compositor_add_key_binding(ec, KEY_UP, mod, |
| 6240 | workspace_up_binding, shell); |
| 6241 | weston_compositor_add_key_binding(ec, KEY_DOWN, mod, |
| 6242 | workspace_down_binding, shell); |
Jonas Ådahl | 8de6a1d | 2012-08-29 22:13:00 +0200 | [diff] [blame] | 6243 | weston_compositor_add_key_binding(ec, KEY_UP, mod | MODIFIER_SHIFT, |
| 6244 | workspace_move_surface_up_binding, |
| 6245 | shell); |
| 6246 | weston_compositor_add_key_binding(ec, KEY_DOWN, mod | MODIFIER_SHIFT, |
| 6247 | workspace_move_surface_down_binding, |
| 6248 | shell); |
Jonas Ådahl | e3cddce | 2012-06-13 00:01:22 +0200 | [diff] [blame] | 6249 | |
Kristian Høgsberg | d56ab4e | 2014-01-16 16:51:52 -0800 | [diff] [blame] | 6250 | if (shell->exposay_modifier) |
| 6251 | weston_compositor_add_modifier_binding(ec, shell->exposay_modifier, |
| 6252 | exposay_binding, shell); |
Daniel Stone | df8133b | 2013-11-19 11:37:14 +0100 | [diff] [blame] | 6253 | |
Jonas Ådahl | e3cddce | 2012-06-13 00:01:22 +0200 | [diff] [blame] | 6254 | /* Add bindings for mod+F[1-6] for workspace 1 to 6. */ |
| 6255 | if (shell->workspaces.num > 1) { |
| 6256 | num_workspace_bindings = shell->workspaces.num; |
| 6257 | if (num_workspace_bindings > 6) |
| 6258 | num_workspace_bindings = 6; |
| 6259 | for (i = 0; i < num_workspace_bindings; i++) |
| 6260 | weston_compositor_add_key_binding(ec, KEY_F1 + i, mod, |
| 6261 | workspace_f_binding, |
| 6262 | shell); |
| 6263 | } |
Ander Conselvan de Oliveira | c509d2b | 2012-11-08 17:20:45 +0200 | [diff] [blame] | 6264 | |
| 6265 | /* Debug bindings */ |
| 6266 | weston_compositor_add_key_binding(ec, KEY_SPACE, mod | MODIFIER_SHIFT, |
| 6267 | debug_binding, shell); |
Tiago Vignatti | 0b52d48 | 2012-04-20 18:54:25 +0300 | [diff] [blame] | 6268 | } |
| 6269 | |
Jason Ekstrand | 024177c | 2014-04-21 19:42:58 -0500 | [diff] [blame] | 6270 | static void |
| 6271 | handle_seat_created(struct wl_listener *listener, void *data) |
| 6272 | { |
| 6273 | struct weston_seat *seat = data; |
| 6274 | |
| 6275 | create_shell_seat(seat); |
| 6276 | } |
| 6277 | |
Kristian Høgsberg | 1c56218 | 2011-05-02 22:09:20 -0400 | [diff] [blame] | 6278 | WL_EXPORT int |
Kristian Høgsberg | cb4685b | 2013-02-20 15:37:49 -0500 | [diff] [blame] | 6279 | module_init(struct weston_compositor *ec, |
Ossama Othman | a50e6e4 | 2013-05-14 09:48:26 -0700 | [diff] [blame] | 6280 | int *argc, char *argv[]) |
Kristian Høgsberg | 4cca349 | 2011-01-18 07:53:49 -0500 | [diff] [blame] | 6281 | { |
Kristian Høgsberg | f4d2f23 | 2012-08-10 10:05:39 -0400 | [diff] [blame] | 6282 | struct weston_seat *seat; |
Tiago Vignatti | be14326 | 2012-04-16 17:31:41 +0300 | [diff] [blame] | 6283 | struct desktop_shell *shell; |
Jonas Ådahl | e3cddce | 2012-06-13 00:01:22 +0200 | [diff] [blame] | 6284 | struct workspace **pws; |
| 6285 | unsigned int i; |
Tiago Vignatti | b7dbbd6 | 2012-09-25 17:57:01 +0300 | [diff] [blame] | 6286 | struct wl_event_loop *loop; |
Kristian Høgsberg | 02ec0a5 | 2011-04-23 13:04:11 -0400 | [diff] [blame] | 6287 | |
Peter Hutterer | f3d6227 | 2013-08-08 11:57:05 +1000 | [diff] [blame] | 6288 | shell = zalloc(sizeof *shell); |
Kristian Høgsberg | 02ec0a5 | 2011-04-23 13:04:11 -0400 | [diff] [blame] | 6289 | if (shell == NULL) |
| 6290 | return -1; |
| 6291 | |
Kristian Høgsberg | 7584062 | 2011-09-06 13:48:16 -0400 | [diff] [blame] | 6292 | shell->compositor = ec; |
Kristian Høgsberg | 02e79dc | 2012-04-12 09:55:26 -0400 | [diff] [blame] | 6293 | |
| 6294 | shell->destroy_listener.notify = shell_destroy; |
| 6295 | wl_signal_add(&ec->destroy_signal, &shell->destroy_listener); |
Ander Conselvan de Oliveira | a457563 | 2013-02-21 18:35:23 +0200 | [diff] [blame] | 6296 | shell->idle_listener.notify = idle_handler; |
| 6297 | wl_signal_add(&ec->idle_signal, &shell->idle_listener); |
| 6298 | shell->wake_listener.notify = wake_handler; |
| 6299 | wl_signal_add(&ec->wake_signal, &shell->wake_listener); |
Kristian Høgsberg | 677a5f5 | 2013-12-04 11:00:19 -0800 | [diff] [blame] | 6300 | |
Kristian Høgsberg | 82a1d11 | 2012-07-19 14:02:00 -0400 | [diff] [blame] | 6301 | ec->shell_interface.shell = shell; |
Tiago Vignatti | bc052c9 | 2012-04-19 16:18:18 +0300 | [diff] [blame] | 6302 | ec->shell_interface.create_shell_surface = create_shell_surface; |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 6303 | ec->shell_interface.get_primary_view = get_primary_view; |
Tiago Vignatti | bc052c9 | 2012-04-19 16:18:18 +0300 | [diff] [blame] | 6304 | ec->shell_interface.set_toplevel = set_toplevel; |
Tiago Vignatti | 491bac1 | 2012-05-18 16:37:43 -0400 | [diff] [blame] | 6305 | ec->shell_interface.set_transient = set_transient; |
Kristian Høgsberg | 4779241 | 2014-05-04 13:47:06 -0700 | [diff] [blame] | 6306 | ec->shell_interface.set_fullscreen = shell_interface_set_fullscreen; |
Tiago Vignatti | fb2adba | 2013-06-12 15:43:21 -0300 | [diff] [blame] | 6307 | ec->shell_interface.set_xwayland = set_xwayland; |
Kristian Høgsberg | ae356ae | 2014-04-29 16:03:54 -0700 | [diff] [blame] | 6308 | ec->shell_interface.move = shell_interface_move; |
Kristian Høgsberg | c1693f2 | 2012-05-22 16:56:23 -0400 | [diff] [blame] | 6309 | ec->shell_interface.resize = surface_resize; |
Giulio Camuffo | 62942ad | 2013-09-11 18:20:47 +0200 | [diff] [blame] | 6310 | ec->shell_interface.set_title = set_title; |
Jasper St. Pierre | ccf48fb | 2014-05-02 10:21:38 -0400 | [diff] [blame] | 6311 | ec->shell_interface.set_window_geometry = set_window_geometry; |
Kristian Høgsberg | 4cca349 | 2011-01-18 07:53:49 -0500 | [diff] [blame] | 6312 | |
Kristian Høgsberg | 3be2ce9 | 2012-02-29 12:42:35 -0500 | [diff] [blame] | 6313 | weston_layer_init(&shell->fullscreen_layer, &ec->cursor_layer.link); |
| 6314 | weston_layer_init(&shell->panel_layer, &shell->fullscreen_layer.link); |
Jonas Ådahl | e3cddce | 2012-06-13 00:01:22 +0200 | [diff] [blame] | 6315 | weston_layer_init(&shell->background_layer, &shell->panel_layer.link); |
| 6316 | weston_layer_init(&shell->lock_layer, NULL); |
Philipp Brüschweiler | 711fda8 | 2012-08-09 18:50:43 +0200 | [diff] [blame] | 6317 | weston_layer_init(&shell->input_panel_layer, NULL); |
Jonas Ådahl | e3cddce | 2012-06-13 00:01:22 +0200 | [diff] [blame] | 6318 | |
| 6319 | wl_array_init(&shell->workspaces.array); |
Jonas Ådahl | e9d2250 | 2012-08-29 22:13:01 +0200 | [diff] [blame] | 6320 | wl_list_init(&shell->workspaces.client_list); |
Kristian Høgsberg | 3be2ce9 | 2012-02-29 12:42:35 -0500 | [diff] [blame] | 6321 | |
Kristian Høgsberg | 677a5f5 | 2013-12-04 11:00:19 -0800 | [diff] [blame] | 6322 | if (input_panel_setup(shell) < 0) |
| 6323 | return -1; |
| 6324 | |
Kristian Høgsberg | 14e438c | 2013-05-26 21:48:14 -0400 | [diff] [blame] | 6325 | shell_configuration(shell); |
Pekka Paalanen | e955f1e | 2011-12-07 11:49:52 +0200 | [diff] [blame] | 6326 | |
Daniel Stone | df8133b | 2013-11-19 11:37:14 +0100 | [diff] [blame] | 6327 | shell->exposay.state_cur = EXPOSAY_LAYOUT_INACTIVE; |
| 6328 | shell->exposay.state_target = EXPOSAY_TARGET_CANCEL; |
| 6329 | |
Jonas Ådahl | e3cddce | 2012-06-13 00:01:22 +0200 | [diff] [blame] | 6330 | for (i = 0; i < shell->workspaces.num; i++) { |
| 6331 | pws = wl_array_add(&shell->workspaces.array, sizeof *pws); |
| 6332 | if (pws == NULL) |
| 6333 | return -1; |
| 6334 | |
| 6335 | *pws = workspace_create(); |
| 6336 | if (*pws == NULL) |
| 6337 | return -1; |
| 6338 | } |
| 6339 | activate_workspace(shell, 0); |
| 6340 | |
Manuel Bachmann | 50c87db | 2014-02-26 15:52:13 +0100 | [diff] [blame] | 6341 | weston_layer_init(&shell->minimized_layer, NULL); |
| 6342 | |
Jonas Ådahl | 8de6a1d | 2012-08-29 22:13:00 +0200 | [diff] [blame] | 6343 | wl_list_init(&shell->workspaces.anim_sticky_list); |
Jonas Ådahl | 62fcd04 | 2012-06-13 00:01:23 +0200 | [diff] [blame] | 6344 | wl_list_init(&shell->workspaces.animation.link); |
| 6345 | shell->workspaces.animation.frame = animate_workspace_change_frame; |
| 6346 | |
Kristian Høgsberg | 919cddb | 2013-07-08 19:03:57 -0400 | [diff] [blame] | 6347 | if (wl_global_create(ec->wl_display, &wl_shell_interface, 1, |
Kristian Høgsberg | 97d44aa | 2011-08-26 17:21:20 -0400 | [diff] [blame] | 6348 | shell, bind_shell) == NULL) |
Kristian Høgsberg | 4cca349 | 2011-01-18 07:53:49 -0500 | [diff] [blame] | 6349 | return -1; |
| 6350 | |
Rafael Antognolli | e2a3455 | 2013-12-03 15:35:45 -0200 | [diff] [blame] | 6351 | if (wl_global_create(ec->wl_display, &xdg_shell_interface, 1, |
| 6352 | shell, bind_xdg_shell) == NULL) |
| 6353 | return -1; |
| 6354 | |
Kristian Høgsberg | 919cddb | 2013-07-08 19:03:57 -0400 | [diff] [blame] | 6355 | if (wl_global_create(ec->wl_display, |
Jonny Lamb | 765760d | 2014-08-20 15:53:19 +0200 | [diff] [blame] | 6356 | &desktop_shell_interface, 3, |
Kristian Høgsberg | 919cddb | 2013-07-08 19:03:57 -0400 | [diff] [blame] | 6357 | shell, bind_desktop_shell) == NULL) |
Kristian Høgsberg | 7584062 | 2011-09-06 13:48:16 -0400 | [diff] [blame] | 6358 | return -1; |
| 6359 | |
Kristian Høgsberg | 919cddb | 2013-07-08 19:03:57 -0400 | [diff] [blame] | 6360 | if (wl_global_create(ec->wl_display, &screensaver_interface, 1, |
| 6361 | shell, bind_screensaver) == NULL) |
Pekka Paalanen | 6e16811 | 2011-11-24 11:34:05 +0200 | [diff] [blame] | 6362 | return -1; |
| 6363 | |
Kristian Høgsberg | 919cddb | 2013-07-08 19:03:57 -0400 | [diff] [blame] | 6364 | if (wl_global_create(ec->wl_display, &workspace_manager_interface, 1, |
| 6365 | shell, bind_workspace_manager) == NULL) |
Jonas Ådahl | e9d2250 | 2012-08-29 22:13:01 +0200 | [diff] [blame] | 6366 | return -1; |
| 6367 | |
Kristian Høgsberg | f03a616 | 2012-01-17 11:07:42 -0500 | [diff] [blame] | 6368 | shell->child.deathstamp = weston_compositor_get_time(); |
Tiago Vignatti | b7dbbd6 | 2012-09-25 17:57:01 +0300 | [diff] [blame] | 6369 | |
Jonny Lamb | 765760d | 2014-08-20 15:53:19 +0200 | [diff] [blame] | 6370 | shell->panel_position = DESKTOP_SHELL_PANEL_POSITION_TOP; |
| 6371 | |
Xiong Zhang | 6b48142 | 2013-10-23 13:58:32 +0800 | [diff] [blame] | 6372 | setup_output_destroy_handler(ec, shell); |
| 6373 | |
Tiago Vignatti | b7dbbd6 | 2012-09-25 17:57:01 +0300 | [diff] [blame] | 6374 | loop = wl_display_get_event_loop(ec->wl_display); |
| 6375 | wl_event_loop_add_idle(loop, launch_desktop_shell_process, shell); |
Pekka Paalanen | 6cd281a | 2011-11-03 14:11:32 +0200 | [diff] [blame] | 6376 | |
Ander Conselvan de Oliveira | 859e885 | 2013-02-21 18:35:21 +0200 | [diff] [blame] | 6377 | shell->screensaver.timer = |
| 6378 | wl_event_loop_add_timer(loop, screensaver_timeout, shell); |
| 6379 | |
Jason Ekstrand | 024177c | 2014-04-21 19:42:58 -0500 | [diff] [blame] | 6380 | wl_list_for_each(seat, &ec->seat_list, link) |
| 6381 | handle_seat_created(NULL, seat); |
| 6382 | shell->seat_create_listener.notify = handle_seat_created; |
| 6383 | wl_signal_add(&ec->seat_created_signal, &shell->seat_create_listener); |
Kristian Høgsberg | d56bd90 | 2012-06-05 09:58:51 -0400 | [diff] [blame] | 6384 | |
Giulio Camuffo | c6ab3d5 | 2013-12-11 23:45:12 +0100 | [diff] [blame] | 6385 | screenshooter_create(ec); |
| 6386 | |
Tiago Vignatti | 0b52d48 | 2012-04-20 18:54:25 +0300 | [diff] [blame] | 6387 | shell_add_bindings(ec, shell); |
Kristian Høgsberg | 0793756 | 2011-04-12 17:25:42 -0400 | [diff] [blame] | 6388 | |
Pekka Paalanen | 79346ab | 2013-05-22 18:03:09 +0300 | [diff] [blame] | 6389 | shell_fade_init(shell); |
Ander Conselvan de Oliveira | 19d10ef | 2013-02-21 18:35:20 +0200 | [diff] [blame] | 6390 | |
Kristian Høgsberg | 4cca349 | 2011-01-18 07:53:49 -0500 | [diff] [blame] | 6391 | return 0; |
| 6392 | } |