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; |
Jonny Lamb | 76cf1fe | 2014-08-20 11:27:10 +0200 | [diff] [blame] | 226 | struct weston_touch_grab touch_grab; |
Giulio Camuffo | 5085a75 | 2013-03-25 21:42:45 +0100 | [diff] [blame] | 227 | struct wl_list surfaces_list; |
| 228 | struct wl_client *client; |
| 229 | int32_t initial_up; |
Jonny Lamb | 76cf1fe | 2014-08-20 11:27:10 +0200 | [diff] [blame] | 230 | enum { POINTER, TOUCH } type; |
Giulio Camuffo | 5085a75 | 2013-03-25 21:42:45 +0100 | [diff] [blame] | 231 | } popup_grab; |
| 232 | }; |
| 233 | |
Kristian Høgsberg | 2bff94e | 2014-02-11 12:22:51 -0800 | [diff] [blame] | 234 | struct shell_client { |
| 235 | struct wl_resource *resource; |
| 236 | struct wl_client *client; |
| 237 | struct desktop_shell *shell; |
| 238 | struct wl_listener destroy_listener; |
| 239 | struct wl_event_source *ping_timer; |
| 240 | uint32_t ping_serial; |
| 241 | int unresponsive; |
| 242 | }; |
| 243 | |
Alex Wu | bd3354b | 2012-04-17 17:20:49 +0800 | [diff] [blame] | 244 | static struct desktop_shell * |
| 245 | shell_surface_get_shell(struct shell_surface *shsurf); |
| 246 | |
Kristian Høgsberg | 0c36903 | 2013-02-14 21:31:44 -0500 | [diff] [blame] | 247 | static void |
Kristian Høgsberg | e314875 | 2013-05-06 23:19:49 -0400 | [diff] [blame] | 248 | surface_rotate(struct shell_surface *surface, struct weston_seat *seat); |
Kristian Høgsberg | 0c36903 | 2013-02-14 21:31:44 -0500 | [diff] [blame] | 249 | |
Pekka Paalanen | 79346ab | 2013-05-22 18:03:09 +0300 | [diff] [blame] | 250 | static void |
| 251 | shell_fade_startup(struct desktop_shell *shell); |
| 252 | |
Philip Withnall | becb77e | 2013-11-25 18:01:30 +0000 | [diff] [blame] | 253 | static struct shell_seat * |
| 254 | get_shell_seat(struct weston_seat *seat); |
| 255 | |
Jonny Lamb | d73c694 | 2014-08-20 15:53:20 +0200 | [diff] [blame] | 256 | static void |
| 257 | get_output_panel_size(struct desktop_shell *shell, |
| 258 | struct weston_output *output, |
| 259 | int *width, int *height); |
Kristian Høgsberg | ae356ae | 2014-04-29 16:03:54 -0700 | [diff] [blame] | 260 | |
Philip Withnall | 648a4dd | 2013-11-25 18:01:44 +0000 | [diff] [blame] | 261 | static void |
| 262 | shell_surface_update_child_surface_layers(struct shell_surface *shsurf); |
| 263 | |
Alex Wu | bd3354b | 2012-04-17 17:20:49 +0800 | [diff] [blame] | 264 | static bool |
Rafael Antognolli | e2a3455 | 2013-12-03 15:35:45 -0200 | [diff] [blame] | 265 | shell_surface_is_wl_shell_surface(struct shell_surface *shsurf); |
| 266 | |
| 267 | static bool |
| 268 | shell_surface_is_xdg_surface(struct shell_surface *shsurf); |
| 269 | |
| 270 | static bool |
| 271 | shell_surface_is_xdg_popup(struct shell_surface *shsurf); |
| 272 | |
| 273 | static void |
| 274 | shell_surface_set_parent(struct shell_surface *shsurf, |
| 275 | struct weston_surface *parent); |
| 276 | |
Pekka Paalanen | 8274d90 | 2014-08-06 19:36:51 +0300 | [diff] [blame] | 277 | static int |
| 278 | shell_surface_get_label(struct weston_surface *surface, char *buf, size_t len) |
| 279 | { |
| 280 | struct shell_surface *shsurf; |
| 281 | const char *typestr[] = { |
| 282 | [SHELL_SURFACE_NONE] = "unidentified", |
| 283 | [SHELL_SURFACE_TOPLEVEL] = "top-level", |
| 284 | [SHELL_SURFACE_POPUP] = "popup", |
| 285 | [SHELL_SURFACE_XWAYLAND] = "Xwayland", |
| 286 | }; |
| 287 | const char *t, *c; |
| 288 | |
| 289 | shsurf = get_shell_surface(surface); |
| 290 | if (!shsurf) |
| 291 | return snprintf(buf, len, "unidentified window"); |
| 292 | |
| 293 | t = shsurf->title; |
| 294 | c = shsurf->class; |
| 295 | |
| 296 | return snprintf(buf, len, "%s window%s%s%s%s%s", |
| 297 | typestr[shsurf->type], |
| 298 | t ? " '" : "", t ?: "", t ? "'" : "", |
| 299 | c ? " of " : "", c ?: ""); |
| 300 | } |
| 301 | |
Rafael Antognolli | e2a3455 | 2013-12-03 15:35:45 -0200 | [diff] [blame] | 302 | static bool |
Alex Wu | bd3354b | 2012-04-17 17:20:49 +0800 | [diff] [blame] | 303 | shell_surface_is_top_fullscreen(struct shell_surface *shsurf) |
| 304 | { |
| 305 | struct desktop_shell *shell; |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 306 | struct weston_view *top_fs_ev; |
Alex Wu | bd3354b | 2012-04-17 17:20:49 +0800 | [diff] [blame] | 307 | |
| 308 | shell = shell_surface_get_shell(shsurf); |
Quentin Glidic | c0d79ce | 2013-01-29 14:16:13 +0100 | [diff] [blame] | 309 | |
Giulio Camuffo | 412e6a5 | 2014-07-09 22:12:56 +0300 | [diff] [blame] | 310 | if (wl_list_empty(&shell->fullscreen_layer.view_list.link)) |
Alex Wu | bd3354b | 2012-04-17 17:20:49 +0800 | [diff] [blame] | 311 | return false; |
| 312 | |
Giulio Camuffo | 412e6a5 | 2014-07-09 22:12:56 +0300 | [diff] [blame] | 313 | top_fs_ev = container_of(shell->fullscreen_layer.view_list.link.next, |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 314 | struct weston_view, |
Giulio Camuffo | 412e6a5 | 2014-07-09 22:12:56 +0300 | [diff] [blame] | 315 | layer_link.link); |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 316 | return (shsurf == get_shell_surface(top_fs_ev->surface)); |
Alex Wu | bd3354b | 2012-04-17 17:20:49 +0800 | [diff] [blame] | 317 | } |
| 318 | |
Kristian Høgsberg | 6af8eb9 | 2012-01-25 16:57:11 -0500 | [diff] [blame] | 319 | static void |
Kristian Høgsberg | 27e3052 | 2012-04-11 23:18:23 -0400 | [diff] [blame] | 320 | destroy_shell_grab_shsurf(struct wl_listener *listener, void *data) |
Ander Conselvan de Oliveira | fe0444a | 2012-04-04 17:48:05 +0300 | [diff] [blame] | 321 | { |
| 322 | struct shell_grab *grab; |
| 323 | |
| 324 | grab = container_of(listener, struct shell_grab, |
| 325 | shsurf_destroy_listener); |
| 326 | |
| 327 | grab->shsurf = NULL; |
| 328 | } |
| 329 | |
Kristian Høgsberg | 1ef2313 | 2013-12-04 00:20:01 -0800 | [diff] [blame] | 330 | struct weston_view * |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 331 | get_default_view(struct weston_surface *surface) |
| 332 | { |
| 333 | struct shell_surface *shsurf; |
| 334 | struct weston_view *view; |
| 335 | |
| 336 | if (!surface || wl_list_empty(&surface->views)) |
| 337 | return NULL; |
| 338 | |
| 339 | shsurf = get_shell_surface(surface); |
| 340 | if (shsurf) |
| 341 | return shsurf->view; |
| 342 | |
| 343 | wl_list_for_each(view, &surface->views, surface_link) |
| 344 | if (weston_view_is_mapped(view)) |
| 345 | return view; |
| 346 | |
| 347 | return container_of(surface->views.next, struct weston_view, surface_link); |
| 348 | } |
| 349 | |
Ander Conselvan de Oliveira | fe0444a | 2012-04-04 17:48:05 +0300 | [diff] [blame] | 350 | static void |
Kristian Høgsberg | 02bbabb | 2013-05-06 22:15:05 -0400 | [diff] [blame] | 351 | popup_grab_end(struct weston_pointer *pointer); |
Jonny Lamb | 76cf1fe | 2014-08-20 11:27:10 +0200 | [diff] [blame] | 352 | static void |
| 353 | touch_popup_grab_end(struct weston_touch *touch); |
Kristian Høgsberg | 57e0907 | 2012-10-30 14:07:27 -0400 | [diff] [blame] | 354 | |
| 355 | static void |
Ander Conselvan de Oliveira | b9d2a0f | 2012-06-28 18:08:05 +0300 | [diff] [blame] | 356 | shell_grab_start(struct shell_grab *grab, |
Kristian Høgsberg | 02bbabb | 2013-05-06 22:15:05 -0400 | [diff] [blame] | 357 | const struct weston_pointer_grab_interface *interface, |
Ander Conselvan de Oliveira | b9d2a0f | 2012-06-28 18:08:05 +0300 | [diff] [blame] | 358 | struct shell_surface *shsurf, |
Kristian Høgsberg | 02bbabb | 2013-05-06 22:15:05 -0400 | [diff] [blame] | 359 | struct weston_pointer *pointer, |
Ander Conselvan de Oliveira | b9d2a0f | 2012-06-28 18:08:05 +0300 | [diff] [blame] | 360 | enum desktop_shell_cursor cursor) |
Ander Conselvan de Oliveira | fe0444a | 2012-04-04 17:48:05 +0300 | [diff] [blame] | 361 | { |
Ander Conselvan de Oliveira | b9d2a0f | 2012-06-28 18:08:05 +0300 | [diff] [blame] | 362 | struct desktop_shell *shell = shsurf->shell; |
| 363 | |
Kristian Høgsberg | 57e0907 | 2012-10-30 14:07:27 -0400 | [diff] [blame] | 364 | popup_grab_end(pointer); |
Jonny Lamb | 76cf1fe | 2014-08-20 11:27:10 +0200 | [diff] [blame] | 365 | if (pointer->seat->touch) |
| 366 | touch_popup_grab_end(pointer->seat->touch); |
Kristian Høgsberg | 57e0907 | 2012-10-30 14:07:27 -0400 | [diff] [blame] | 367 | |
Ander Conselvan de Oliveira | fe0444a | 2012-04-04 17:48:05 +0300 | [diff] [blame] | 368 | grab->grab.interface = interface; |
| 369 | grab->shsurf = shsurf; |
Kristian Høgsberg | 27e3052 | 2012-04-11 23:18:23 -0400 | [diff] [blame] | 370 | grab->shsurf_destroy_listener.notify = destroy_shell_grab_shsurf; |
Jason Ekstrand | 651f00e | 2013-06-14 10:07:54 -0500 | [diff] [blame] | 371 | wl_signal_add(&shsurf->destroy_signal, |
Kristian Høgsberg | 27e3052 | 2012-04-11 23:18:23 -0400 | [diff] [blame] | 372 | &grab->shsurf_destroy_listener); |
Ander Conselvan de Oliveira | fe0444a | 2012-04-04 17:48:05 +0300 | [diff] [blame] | 373 | |
Kristian Høgsberg | c85f1d4 | 2013-10-24 16:52:00 -0700 | [diff] [blame] | 374 | shsurf->grabbed = 1; |
Kristian Høgsberg | 02bbabb | 2013-05-06 22:15:05 -0400 | [diff] [blame] | 375 | weston_pointer_start_grab(pointer, &grab->grab); |
Kristian Høgsberg | c9974a0 | 2013-07-03 19:24:57 -0400 | [diff] [blame] | 376 | if (shell->child.desktop_shell) { |
| 377 | desktop_shell_send_grab_cursor(shell->child.desktop_shell, |
| 378 | cursor); |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 379 | weston_pointer_set_focus(pointer, |
| 380 | get_default_view(shell->grab_surface), |
Kristian Høgsberg | c9974a0 | 2013-07-03 19:24:57 -0400 | [diff] [blame] | 381 | wl_fixed_from_int(0), |
| 382 | wl_fixed_from_int(0)); |
| 383 | } |
Ander Conselvan de Oliveira | fe0444a | 2012-04-04 17:48:05 +0300 | [diff] [blame] | 384 | } |
| 385 | |
Jonny Lamb | d73c694 | 2014-08-20 15:53:20 +0200 | [diff] [blame] | 386 | static void |
| 387 | get_output_panel_size(struct desktop_shell *shell, |
| 388 | struct weston_output *output, |
| 389 | int *width, |
| 390 | int *height) |
Jasper St. Pierre | 6458ec3 | 2014-04-11 16:00:31 -0700 | [diff] [blame] | 391 | { |
| 392 | struct weston_view *view; |
Jonny Lamb | d73c694 | 2014-08-20 15:53:20 +0200 | [diff] [blame] | 393 | |
| 394 | *width = 0; |
| 395 | *height = 0; |
Jasper St. Pierre | 6458ec3 | 2014-04-11 16:00:31 -0700 | [diff] [blame] | 396 | |
| 397 | if (!output) |
Jonny Lamb | d73c694 | 2014-08-20 15:53:20 +0200 | [diff] [blame] | 398 | return; |
Jasper St. Pierre | 6458ec3 | 2014-04-11 16:00:31 -0700 | [diff] [blame] | 399 | |
Giulio Camuffo | 412e6a5 | 2014-07-09 22:12:56 +0300 | [diff] [blame] | 400 | 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] | 401 | float x, y; |
| 402 | |
| 403 | if (view->surface->output != output) |
| 404 | continue; |
| 405 | |
| 406 | switch (shell->panel_position) { |
| 407 | case DESKTOP_SHELL_PANEL_POSITION_TOP: |
| 408 | case DESKTOP_SHELL_PANEL_POSITION_BOTTOM: |
| 409 | |
| 410 | weston_view_to_global_float(view, |
| 411 | view->surface->width, 0, |
| 412 | &x, &y); |
| 413 | |
| 414 | *width = (int) x; |
| 415 | *height = view->surface->height + (int) y; |
| 416 | return; |
| 417 | |
| 418 | case DESKTOP_SHELL_PANEL_POSITION_LEFT: |
| 419 | case DESKTOP_SHELL_PANEL_POSITION_RIGHT: |
| 420 | weston_view_to_global_float(view, |
| 421 | 0, view->surface->height, |
| 422 | &x, &y); |
| 423 | |
| 424 | *width = view->surface->width + (int) x; |
| 425 | *height = (int) y; |
| 426 | return; |
| 427 | |
| 428 | default: |
| 429 | /* we've already set width and height to |
| 430 | * fallback values. */ |
Jasper St. Pierre | 6458ec3 | 2014-04-11 16:00:31 -0700 | [diff] [blame] | 431 | break; |
| 432 | } |
| 433 | } |
| 434 | |
Jonny Lamb | d73c694 | 2014-08-20 15:53:20 +0200 | [diff] [blame] | 435 | /* the correct view wasn't found */ |
| 436 | } |
| 437 | |
| 438 | static void |
| 439 | get_output_work_area(struct desktop_shell *shell, |
| 440 | struct weston_output *output, |
| 441 | pixman_rectangle32_t *area) |
| 442 | { |
| 443 | int32_t panel_width = 0, panel_height = 0; |
| 444 | |
| 445 | area->x = 0; |
| 446 | area->y = 0; |
| 447 | |
| 448 | get_output_panel_size(shell, output, &panel_width, &panel_height); |
| 449 | |
| 450 | switch (shell->panel_position) { |
| 451 | case DESKTOP_SHELL_PANEL_POSITION_TOP: |
| 452 | default: |
| 453 | area->y = panel_height; |
| 454 | case DESKTOP_SHELL_PANEL_POSITION_BOTTOM: |
| 455 | area->width = output->width; |
| 456 | area->height = output->height - panel_height; |
| 457 | break; |
| 458 | case DESKTOP_SHELL_PANEL_POSITION_LEFT: |
| 459 | area->x = panel_width; |
| 460 | case DESKTOP_SHELL_PANEL_POSITION_RIGHT: |
| 461 | area->width = output->width - panel_width; |
| 462 | area->height = output->height; |
| 463 | break; |
| 464 | } |
Jasper St. Pierre | 6458ec3 | 2014-04-11 16:00:31 -0700 | [diff] [blame] | 465 | } |
| 466 | |
| 467 | static void |
| 468 | send_configure_for_surface(struct shell_surface *shsurf) |
| 469 | { |
| 470 | int32_t width, height; |
| 471 | struct surface_state *state; |
| 472 | |
| 473 | if (shsurf->state_requested) |
| 474 | state = &shsurf->requested_state; |
| 475 | else if (shsurf->state_changed) |
| 476 | state = &shsurf->next_state; |
| 477 | else |
| 478 | state = &shsurf->state; |
| 479 | |
| 480 | if (state->fullscreen) { |
| 481 | width = shsurf->output->width; |
| 482 | height = shsurf->output->height; |
| 483 | } else if (state->maximized) { |
| 484 | struct desktop_shell *shell; |
Jonny Lamb | d73c694 | 2014-08-20 15:53:20 +0200 | [diff] [blame] | 485 | pixman_rectangle32_t area; |
Jasper St. Pierre | 6458ec3 | 2014-04-11 16:00:31 -0700 | [diff] [blame] | 486 | |
| 487 | shell = shell_surface_get_shell(shsurf); |
Jonny Lamb | d73c694 | 2014-08-20 15:53:20 +0200 | [diff] [blame] | 488 | get_output_work_area(shell, shsurf->output, &area); |
Jasper St. Pierre | 6458ec3 | 2014-04-11 16:00:31 -0700 | [diff] [blame] | 489 | |
Jonny Lamb | d73c694 | 2014-08-20 15:53:20 +0200 | [diff] [blame] | 490 | width = area.width; |
| 491 | height = area.height; |
Jasper St. Pierre | 6458ec3 | 2014-04-11 16:00:31 -0700 | [diff] [blame] | 492 | } else { |
| 493 | width = 0; |
| 494 | height = 0; |
| 495 | } |
| 496 | |
| 497 | shsurf->client->send_configure(shsurf->surface, width, height); |
| 498 | } |
| 499 | |
Ander Conselvan de Oliveira | fe0444a | 2012-04-04 17:48:05 +0300 | [diff] [blame] | 500 | static void |
Jasper St. Pierre | 5befdda | 2014-05-06 08:50:47 -0400 | [diff] [blame] | 501 | shell_surface_state_changed(struct shell_surface *shsurf) |
| 502 | { |
Jasper St. Pierre | 6458ec3 | 2014-04-11 16:00:31 -0700 | [diff] [blame] | 503 | if (shell_surface_is_xdg_surface(shsurf)) |
| 504 | send_configure_for_surface(shsurf); |
Jasper St. Pierre | 5befdda | 2014-05-06 08:50:47 -0400 | [diff] [blame] | 505 | } |
| 506 | |
| 507 | static void |
Ander Conselvan de Oliveira | b9d2a0f | 2012-06-28 18:08:05 +0300 | [diff] [blame] | 508 | shell_grab_end(struct shell_grab *grab) |
Ander Conselvan de Oliveira | fe0444a | 2012-04-04 17:48:05 +0300 | [diff] [blame] | 509 | { |
Kristian Høgsberg | c85f1d4 | 2013-10-24 16:52:00 -0700 | [diff] [blame] | 510 | if (grab->shsurf) { |
Kristian Høgsberg | 47b5dca | 2012-06-07 18:08:04 -0400 | [diff] [blame] | 511 | wl_list_remove(&grab->shsurf_destroy_listener.link); |
Kristian Høgsberg | c85f1d4 | 2013-10-24 16:52:00 -0700 | [diff] [blame] | 512 | grab->shsurf->grabbed = 0; |
Jasper St. Pierre | 5befdda | 2014-05-06 08:50:47 -0400 | [diff] [blame] | 513 | |
| 514 | if (grab->shsurf->resize_edges) { |
| 515 | grab->shsurf->resize_edges = 0; |
| 516 | shell_surface_state_changed(grab->shsurf); |
| 517 | } |
Kristian Høgsberg | c85f1d4 | 2013-10-24 16:52:00 -0700 | [diff] [blame] | 518 | } |
Ander Conselvan de Oliveira | b9d2a0f | 2012-06-28 18:08:05 +0300 | [diff] [blame] | 519 | |
Kristian Høgsberg | 9e5d7d1 | 2013-07-22 16:31:53 -0700 | [diff] [blame] | 520 | weston_pointer_end_grab(grab->grab.pointer); |
Ander Conselvan de Oliveira | fe0444a | 2012-04-04 17:48:05 +0300 | [diff] [blame] | 521 | } |
| 522 | |
| 523 | static void |
Rusty Lynch | 1084da5 | 2013-08-15 09:10:08 -0700 | [diff] [blame] | 524 | shell_touch_grab_start(struct shell_touch_grab *grab, |
| 525 | const struct weston_touch_grab_interface *interface, |
| 526 | struct shell_surface *shsurf, |
| 527 | struct weston_touch *touch) |
| 528 | { |
| 529 | struct desktop_shell *shell = shsurf->shell; |
U. Artie Eoff | cf5737a | 2014-01-17 10:08:25 -0800 | [diff] [blame] | 530 | |
Jonny Lamb | 76cf1fe | 2014-08-20 11:27:10 +0200 | [diff] [blame] | 531 | touch_popup_grab_end(touch); |
Kristian Høgsberg | 74071e0 | 2014-04-29 15:01:16 -0700 | [diff] [blame] | 532 | if (touch->seat->pointer) |
| 533 | popup_grab_end(touch->seat->pointer); |
| 534 | |
Rusty Lynch | 1084da5 | 2013-08-15 09:10:08 -0700 | [diff] [blame] | 535 | grab->grab.interface = interface; |
| 536 | grab->shsurf = shsurf; |
| 537 | grab->shsurf_destroy_listener.notify = destroy_shell_grab_shsurf; |
| 538 | wl_signal_add(&shsurf->destroy_signal, |
| 539 | &grab->shsurf_destroy_listener); |
| 540 | |
| 541 | grab->touch = touch; |
Kristian Høgsberg | c85f1d4 | 2013-10-24 16:52:00 -0700 | [diff] [blame] | 542 | shsurf->grabbed = 1; |
Rusty Lynch | 1084da5 | 2013-08-15 09:10:08 -0700 | [diff] [blame] | 543 | |
| 544 | weston_touch_start_grab(touch, &grab->grab); |
| 545 | if (shell->child.desktop_shell) |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 546 | weston_touch_set_focus(touch->seat, |
| 547 | get_default_view(shell->grab_surface)); |
Rusty Lynch | 1084da5 | 2013-08-15 09:10:08 -0700 | [diff] [blame] | 548 | } |
| 549 | |
| 550 | static void |
| 551 | shell_touch_grab_end(struct shell_touch_grab *grab) |
| 552 | { |
Kristian Høgsberg | c85f1d4 | 2013-10-24 16:52:00 -0700 | [diff] [blame] | 553 | if (grab->shsurf) { |
Rusty Lynch | 1084da5 | 2013-08-15 09:10:08 -0700 | [diff] [blame] | 554 | wl_list_remove(&grab->shsurf_destroy_listener.link); |
Kristian Høgsberg | c85f1d4 | 2013-10-24 16:52:00 -0700 | [diff] [blame] | 555 | grab->shsurf->grabbed = 0; |
| 556 | } |
Rusty Lynch | 1084da5 | 2013-08-15 09:10:08 -0700 | [diff] [blame] | 557 | |
| 558 | weston_touch_end_grab(grab->touch); |
| 559 | } |
| 560 | |
| 561 | static void |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 562 | center_on_output(struct weston_view *view, |
Alex Wu | 4539b08 | 2012-03-01 12:57:46 +0800 | [diff] [blame] | 563 | struct weston_output *output); |
| 564 | |
Daniel Stone | 496ca17 | 2012-05-30 16:31:42 +0100 | [diff] [blame] | 565 | static enum weston_keyboard_modifier |
Tiago Vignatti | 0b52d48 | 2012-04-20 18:54:25 +0300 | [diff] [blame] | 566 | get_modifier(char *modifier) |
| 567 | { |
| 568 | if (!modifier) |
| 569 | return MODIFIER_SUPER; |
| 570 | |
| 571 | if (!strcmp("ctrl", modifier)) |
| 572 | return MODIFIER_CTRL; |
| 573 | else if (!strcmp("alt", modifier)) |
| 574 | return MODIFIER_ALT; |
| 575 | else if (!strcmp("super", modifier)) |
| 576 | return MODIFIER_SUPER; |
| 577 | else |
| 578 | return MODIFIER_SUPER; |
| 579 | } |
| 580 | |
Juan Zhao | e10d279 | 2012-04-25 19:09:52 +0800 | [diff] [blame] | 581 | static enum animation_type |
| 582 | get_animation_type(char *animation) |
| 583 | { |
U. Artie Eoff | b571910 | 2014-01-15 14:26:31 -0800 | [diff] [blame] | 584 | if (!animation) |
| 585 | return ANIMATION_NONE; |
| 586 | |
Juan Zhao | e10d279 | 2012-04-25 19:09:52 +0800 | [diff] [blame] | 587 | if (!strcmp("zoom", animation)) |
| 588 | return ANIMATION_ZOOM; |
| 589 | else if (!strcmp("fade", animation)) |
| 590 | return ANIMATION_FADE; |
Louis-Francis Ratté-Boulianne | b482dbd | 2013-11-19 11:37:11 +0100 | [diff] [blame] | 591 | else if (!strcmp("dim-layer", animation)) |
| 592 | return ANIMATION_DIM_LAYER; |
Juan Zhao | e10d279 | 2012-04-25 19:09:52 +0800 | [diff] [blame] | 593 | else |
| 594 | return ANIMATION_NONE; |
| 595 | } |
| 596 | |
Alex Wu | 4539b08 | 2012-03-01 12:57:46 +0800 | [diff] [blame] | 597 | static void |
Kristian Høgsberg | 14e438c | 2013-05-26 21:48:14 -0400 | [diff] [blame] | 598 | shell_configuration(struct desktop_shell *shell) |
Pekka Paalanen | e955f1e | 2011-12-07 11:49:52 +0200 | [diff] [blame] | 599 | { |
Kristian Høgsberg | 673a889 | 2013-05-23 21:40:56 -0400 | [diff] [blame] | 600 | struct weston_config_section *section; |
| 601 | int duration; |
Derek Foreman | c721043 | 2014-08-21 11:32:38 -0500 | [diff] [blame] | 602 | char *s, *client; |
Pekka Paalanen | 974c094 | 2014-09-05 14:45:09 +0300 | [diff] [blame] | 603 | int ret; |
Pekka Paalanen | e955f1e | 2011-12-07 11:49:52 +0200 | [diff] [blame] | 604 | |
Kristian Høgsberg | 673a889 | 2013-05-23 21:40:56 -0400 | [diff] [blame] | 605 | section = weston_config_get_section(shell->compositor->config, |
| 606 | "screensaver", NULL, NULL); |
| 607 | weston_config_section_get_string(section, |
| 608 | "path", &shell->screensaver.path, NULL); |
| 609 | weston_config_section_get_int(section, "duration", &duration, 60); |
Ander Conselvan de Oliveira | 859e885 | 2013-02-21 18:35:21 +0200 | [diff] [blame] | 610 | shell->screensaver.duration = duration * 1000; |
Kristian Høgsberg | 673a889 | 2013-05-23 21:40:56 -0400 | [diff] [blame] | 611 | |
| 612 | section = weston_config_get_section(shell->compositor->config, |
| 613 | "shell", NULL, NULL); |
Pekka Paalanen | 974c094 | 2014-09-05 14:45:09 +0300 | [diff] [blame] | 614 | ret = asprintf(&client, "%s/%s", weston_config_get_libexec_dir(), |
| 615 | WESTON_SHELL_CLIENT); |
| 616 | if (ret < 0) |
| 617 | client = NULL; |
Kristian Høgsberg | 673a889 | 2013-05-23 21:40:56 -0400 | [diff] [blame] | 618 | weston_config_section_get_string(section, |
Derek Foreman | c721043 | 2014-08-21 11:32:38 -0500 | [diff] [blame] | 619 | "client", &s, client); |
| 620 | free(client); |
Emilio Pozuelo Monfort | 46ce798 | 2013-11-20 13:22:29 +0100 | [diff] [blame] | 621 | shell->client = s; |
| 622 | weston_config_section_get_string(section, |
Kristian Høgsberg | 673a889 | 2013-05-23 21:40:56 -0400 | [diff] [blame] | 623 | "binding-modifier", &s, "super"); |
| 624 | shell->binding_modifier = get_modifier(s); |
Quentin Glidic | 8418c29 | 2013-06-18 09:11:03 +0200 | [diff] [blame] | 625 | free(s); |
Kristian Høgsberg | d56ab4e | 2014-01-16 16:51:52 -0800 | [diff] [blame] | 626 | |
| 627 | weston_config_section_get_string(section, |
| 628 | "exposay-modifier", &s, "none"); |
| 629 | if (strcmp(s, "none") == 0) |
| 630 | shell->exposay_modifier = 0; |
| 631 | else |
| 632 | shell->exposay_modifier = get_modifier(s); |
| 633 | free(s); |
| 634 | |
Kristian Høgsberg | 673a889 | 2013-05-23 21:40:56 -0400 | [diff] [blame] | 635 | weston_config_section_get_string(section, "animation", &s, "none"); |
| 636 | shell->win_animation_type = get_animation_type(s); |
Quentin Glidic | 8418c29 | 2013-06-18 09:11:03 +0200 | [diff] [blame] | 637 | free(s); |
Jonny Lamb | f322f8e | 2014-08-12 15:13:30 +0200 | [diff] [blame] | 638 | weston_config_section_get_string(section, "close-animation", &s, "fade"); |
| 639 | shell->win_close_animation_type = get_animation_type(s); |
| 640 | free(s); |
Kristian Høgsberg | 724c8d9 | 2013-10-16 11:38:24 -0700 | [diff] [blame] | 641 | weston_config_section_get_string(section, |
| 642 | "startup-animation", &s, "fade"); |
| 643 | shell->startup_animation_type = get_animation_type(s); |
| 644 | free(s); |
Kristian Høgsberg | 912e0a1 | 2013-10-30 08:59:55 -0700 | [diff] [blame] | 645 | if (shell->startup_animation_type == ANIMATION_ZOOM) |
| 646 | shell->startup_animation_type = ANIMATION_NONE; |
Louis-Francis Ratté-Boulianne | b482dbd | 2013-11-19 11:37:11 +0100 | [diff] [blame] | 647 | weston_config_section_get_string(section, "focus-animation", &s, "none"); |
| 648 | shell->focus_animation_type = get_animation_type(s); |
| 649 | free(s); |
Kristian Høgsberg | 673a889 | 2013-05-23 21:40:56 -0400 | [diff] [blame] | 650 | weston_config_section_get_uint(section, "num-workspaces", |
| 651 | &shell->workspaces.num, |
| 652 | DEFAULT_NUM_WORKSPACES); |
Jonas Ådahl | e3cddce | 2012-06-13 00:01:22 +0200 | [diff] [blame] | 653 | } |
| 654 | |
Kristian Høgsberg | 1ef2313 | 2013-12-04 00:20:01 -0800 | [diff] [blame] | 655 | struct weston_output * |
Louis-Francis Ratté-Boulianne | b482dbd | 2013-11-19 11:37:11 +0100 | [diff] [blame] | 656 | get_default_output(struct weston_compositor *compositor) |
| 657 | { |
| 658 | return container_of(compositor->output_list.next, |
| 659 | struct weston_output, link); |
| 660 | } |
| 661 | |
Pekka Paalanen | 8274d90 | 2014-08-06 19:36:51 +0300 | [diff] [blame] | 662 | static int |
| 663 | focus_surface_get_label(struct weston_surface *surface, char *buf, size_t len) |
| 664 | { |
| 665 | return snprintf(buf, len, "focus highlight effect for output %s", |
| 666 | surface->output->name); |
| 667 | } |
Louis-Francis Ratté-Boulianne | b482dbd | 2013-11-19 11:37:11 +0100 | [diff] [blame] | 668 | |
| 669 | /* no-op func for checking focus surface */ |
| 670 | static void |
Jason Ekstrand | 918f2dd | 2013-12-02 21:01:53 -0600 | [diff] [blame] | 671 | 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] | 672 | { |
| 673 | } |
| 674 | |
| 675 | static struct focus_surface * |
| 676 | get_focus_surface(struct weston_surface *surface) |
| 677 | { |
| 678 | if (surface->configure == focus_surface_configure) |
| 679 | return surface->configure_private; |
| 680 | else |
| 681 | return NULL; |
| 682 | } |
| 683 | |
| 684 | static bool |
| 685 | is_focus_surface (struct weston_surface *es) |
| 686 | { |
| 687 | return (es->configure == focus_surface_configure); |
| 688 | } |
| 689 | |
| 690 | static bool |
| 691 | is_focus_view (struct weston_view *view) |
| 692 | { |
| 693 | return is_focus_surface (view->surface); |
| 694 | } |
| 695 | |
| 696 | static struct focus_surface * |
| 697 | create_focus_surface(struct weston_compositor *ec, |
| 698 | struct weston_output *output) |
| 699 | { |
| 700 | struct focus_surface *fsurf = NULL; |
| 701 | struct weston_surface *surface = NULL; |
| 702 | |
| 703 | fsurf = malloc(sizeof *fsurf); |
| 704 | if (!fsurf) |
| 705 | return NULL; |
| 706 | |
| 707 | fsurf->surface = weston_surface_create(ec); |
| 708 | surface = fsurf->surface; |
| 709 | if (surface == NULL) { |
| 710 | free(fsurf); |
| 711 | return NULL; |
| 712 | } |
| 713 | |
| 714 | surface->configure = focus_surface_configure; |
| 715 | surface->output = output; |
| 716 | surface->configure_private = fsurf; |
Pekka Paalanen | 8274d90 | 2014-08-06 19:36:51 +0300 | [diff] [blame] | 717 | weston_surface_set_label_func(surface, focus_surface_get_label); |
Louis-Francis Ratté-Boulianne | b482dbd | 2013-11-19 11:37:11 +0100 | [diff] [blame] | 718 | |
U. Artie Eoff | 0b23b2b | 2014-01-15 14:45:59 -0800 | [diff] [blame] | 719 | fsurf->view = weston_view_create(surface); |
| 720 | if (fsurf->view == NULL) { |
| 721 | weston_surface_destroy(surface); |
| 722 | free(fsurf); |
| 723 | return NULL; |
| 724 | } |
Emilio Pozuelo Monfort | da64426 | 2013-11-19 11:37:19 +0100 | [diff] [blame] | 725 | fsurf->view->output = output; |
Louis-Francis Ratté-Boulianne | b482dbd | 2013-11-19 11:37:11 +0100 | [diff] [blame] | 726 | |
Jason Ekstrand | 5c11a33 | 2013-12-04 20:32:03 -0600 | [diff] [blame] | 727 | weston_surface_set_size(surface, output->width, output->height); |
Jason Ekstrand | 918f2dd | 2013-12-02 21:01:53 -0600 | [diff] [blame] | 728 | weston_view_set_position(fsurf->view, output->x, output->y); |
Louis-Francis Ratté-Boulianne | b482dbd | 2013-11-19 11:37:11 +0100 | [diff] [blame] | 729 | weston_surface_set_color(surface, 0.0, 0.0, 0.0, 1.0); |
| 730 | pixman_region32_fini(&surface->opaque); |
| 731 | pixman_region32_init_rect(&surface->opaque, output->x, output->y, |
| 732 | output->width, output->height); |
| 733 | pixman_region32_fini(&surface->input); |
| 734 | pixman_region32_init(&surface->input); |
| 735 | |
| 736 | wl_list_init(&fsurf->workspace_transform.link); |
| 737 | |
| 738 | return fsurf; |
| 739 | } |
| 740 | |
| 741 | static void |
| 742 | focus_surface_destroy(struct focus_surface *fsurf) |
| 743 | { |
| 744 | weston_surface_destroy(fsurf->surface); |
| 745 | free(fsurf); |
| 746 | } |
| 747 | |
| 748 | static void |
| 749 | focus_animation_done(struct weston_view_animation *animation, void *data) |
| 750 | { |
| 751 | struct workspace *ws = data; |
| 752 | |
| 753 | ws->focus_animation = NULL; |
| 754 | } |
| 755 | |
Jonas Ådahl | e3cddce | 2012-06-13 00:01:22 +0200 | [diff] [blame] | 756 | static void |
Jonas Ådahl | 0476974 | 2012-06-13 00:01:24 +0200 | [diff] [blame] | 757 | focus_state_destroy(struct focus_state *state) |
| 758 | { |
| 759 | wl_list_remove(&state->seat_destroy_listener.link); |
| 760 | wl_list_remove(&state->surface_destroy_listener.link); |
| 761 | free(state); |
| 762 | } |
| 763 | |
| 764 | static void |
| 765 | focus_state_seat_destroy(struct wl_listener *listener, void *data) |
| 766 | { |
| 767 | struct focus_state *state = container_of(listener, |
| 768 | struct focus_state, |
| 769 | seat_destroy_listener); |
| 770 | |
| 771 | wl_list_remove(&state->link); |
| 772 | focus_state_destroy(state); |
| 773 | } |
| 774 | |
| 775 | static void |
| 776 | focus_state_surface_destroy(struct wl_listener *listener, void *data) |
| 777 | { |
| 778 | struct focus_state *state = container_of(listener, |
| 779 | struct focus_state, |
Kristian Høgsberg | b8e0d0f | 2012-07-31 10:30:26 -0400 | [diff] [blame] | 780 | surface_destroy_listener); |
Kristian Høgsberg | e377822 | 2012-07-31 17:29:30 -0400 | [diff] [blame] | 781 | struct desktop_shell *shell; |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 782 | struct weston_surface *main_surface, *next; |
| 783 | struct weston_view *view; |
Jonas Ådahl | 0476974 | 2012-06-13 00:01:24 +0200 | [diff] [blame] | 784 | |
Pekka Paalanen | 01388e2 | 2013-04-25 13:57:44 +0300 | [diff] [blame] | 785 | main_surface = weston_surface_get_main_surface(state->keyboard_focus); |
| 786 | |
Kristian Høgsberg | e377822 | 2012-07-31 17:29:30 -0400 | [diff] [blame] | 787 | next = NULL; |
Giulio Camuffo | 412e6a5 | 2014-07-09 22:12:56 +0300 | [diff] [blame] | 788 | wl_list_for_each(view, |
| 789 | &state->ws->layer.view_list.link, layer_link.link) { |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 790 | if (view->surface == main_surface) |
Kristian Høgsberg | e377822 | 2012-07-31 17:29:30 -0400 | [diff] [blame] | 791 | continue; |
Louis-Francis Ratté-Boulianne | b482dbd | 2013-11-19 11:37:11 +0100 | [diff] [blame] | 792 | if (is_focus_view(view)) |
| 793 | continue; |
Kristian Høgsberg | e377822 | 2012-07-31 17:29:30 -0400 | [diff] [blame] | 794 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 795 | next = view->surface; |
Kristian Høgsberg | e377822 | 2012-07-31 17:29:30 -0400 | [diff] [blame] | 796 | break; |
| 797 | } |
| 798 | |
Pekka Paalanen | 01388e2 | 2013-04-25 13:57:44 +0300 | [diff] [blame] | 799 | /* if the focus was a sub-surface, activate its main surface */ |
| 800 | if (main_surface != state->keyboard_focus) |
| 801 | next = main_surface; |
| 802 | |
Louis-Francis Ratté-Boulianne | b482dbd | 2013-11-19 11:37:11 +0100 | [diff] [blame] | 803 | shell = state->seat->compositor->shell_interface.shell; |
Kristian Høgsberg | e377822 | 2012-07-31 17:29:30 -0400 | [diff] [blame] | 804 | if (next) { |
Louis-Francis Ratté-Boulianne | b482dbd | 2013-11-19 11:37:11 +0100 | [diff] [blame] | 805 | state->keyboard_focus = NULL; |
Emilio Pozuelo Monfort | 9e7c759 | 2014-01-30 14:01:10 +0100 | [diff] [blame] | 806 | activate(shell, next, state->seat, true); |
Kristian Høgsberg | e377822 | 2012-07-31 17:29:30 -0400 | [diff] [blame] | 807 | } else { |
Louis-Francis Ratté-Boulianne | b482dbd | 2013-11-19 11:37:11 +0100 | [diff] [blame] | 808 | if (shell->focus_animation_type == ANIMATION_DIM_LAYER) { |
| 809 | if (state->ws->focus_animation) |
| 810 | weston_view_animation_destroy(state->ws->focus_animation); |
| 811 | |
| 812 | state->ws->focus_animation = weston_fade_run( |
| 813 | state->ws->fsurf_front->view, |
| 814 | state->ws->fsurf_front->view->alpha, 0.0, 300, |
| 815 | focus_animation_done, state->ws); |
| 816 | } |
| 817 | |
Kristian Høgsberg | e377822 | 2012-07-31 17:29:30 -0400 | [diff] [blame] | 818 | wl_list_remove(&state->link); |
| 819 | focus_state_destroy(state); |
| 820 | } |
Jonas Ådahl | 0476974 | 2012-06-13 00:01:24 +0200 | [diff] [blame] | 821 | } |
| 822 | |
| 823 | static struct focus_state * |
Kristian Høgsberg | 2f5faff | 2012-07-31 16:36:34 -0400 | [diff] [blame] | 824 | focus_state_create(struct weston_seat *seat, struct workspace *ws) |
Jonas Ådahl | 0476974 | 2012-06-13 00:01:24 +0200 | [diff] [blame] | 825 | { |
Jonas Ådahl | 0476974 | 2012-06-13 00:01:24 +0200 | [diff] [blame] | 826 | struct focus_state *state; |
Jonas Ådahl | 0476974 | 2012-06-13 00:01:24 +0200 | [diff] [blame] | 827 | |
| 828 | state = malloc(sizeof *state); |
| 829 | if (state == NULL) |
| 830 | return NULL; |
| 831 | |
Louis-Francis Ratté-Boulianne | b482dbd | 2013-11-19 11:37:11 +0100 | [diff] [blame] | 832 | state->keyboard_focus = NULL; |
Kristian Høgsberg | 2f5faff | 2012-07-31 16:36:34 -0400 | [diff] [blame] | 833 | state->ws = ws; |
Jonas Ådahl | 0476974 | 2012-06-13 00:01:24 +0200 | [diff] [blame] | 834 | state->seat = seat; |
Kristian Høgsberg | 2f5faff | 2012-07-31 16:36:34 -0400 | [diff] [blame] | 835 | wl_list_insert(&ws->focus_list, &state->link); |
Jonas Ådahl | 0476974 | 2012-06-13 00:01:24 +0200 | [diff] [blame] | 836 | |
| 837 | state->seat_destroy_listener.notify = focus_state_seat_destroy; |
| 838 | state->surface_destroy_listener.notify = focus_state_surface_destroy; |
Kristian Høgsberg | 4912454 | 2013-05-06 22:27:40 -0400 | [diff] [blame] | 839 | wl_signal_add(&seat->destroy_signal, |
Jonas Ådahl | 0476974 | 2012-06-13 00:01:24 +0200 | [diff] [blame] | 840 | &state->seat_destroy_listener); |
Kristian Høgsberg | 2f5faff | 2012-07-31 16:36:34 -0400 | [diff] [blame] | 841 | wl_list_init(&state->surface_destroy_listener.link); |
Jonas Ådahl | 0476974 | 2012-06-13 00:01:24 +0200 | [diff] [blame] | 842 | |
| 843 | return state; |
| 844 | } |
| 845 | |
Jonas Ådahl | 8538b22 | 2012-08-29 22:13:03 +0200 | [diff] [blame] | 846 | static struct focus_state * |
| 847 | ensure_focus_state(struct desktop_shell *shell, struct weston_seat *seat) |
| 848 | { |
| 849 | struct workspace *ws = get_current_workspace(shell); |
| 850 | struct focus_state *state; |
| 851 | |
| 852 | wl_list_for_each(state, &ws->focus_list, link) |
| 853 | if (state->seat == seat) |
| 854 | break; |
| 855 | |
| 856 | if (&state->link == &ws->focus_list) |
| 857 | state = focus_state_create(seat, ws); |
| 858 | |
| 859 | return state; |
| 860 | } |
| 861 | |
Jonas Ådahl | 0476974 | 2012-06-13 00:01:24 +0200 | [diff] [blame] | 862 | static void |
Kristian Høgsberg | d500bf1 | 2014-01-22 12:25:20 -0800 | [diff] [blame] | 863 | focus_state_set_focus(struct focus_state *state, |
| 864 | struct weston_surface *surface) |
| 865 | { |
| 866 | if (state->keyboard_focus) { |
| 867 | wl_list_remove(&state->surface_destroy_listener.link); |
| 868 | wl_list_init(&state->surface_destroy_listener.link); |
| 869 | } |
| 870 | |
| 871 | state->keyboard_focus = surface; |
| 872 | if (surface) |
| 873 | wl_signal_add(&surface->destroy_signal, |
| 874 | &state->surface_destroy_listener); |
| 875 | } |
| 876 | |
| 877 | static void |
Kristian Høgsberg | 2f5faff | 2012-07-31 16:36:34 -0400 | [diff] [blame] | 878 | restore_focus_state(struct desktop_shell *shell, struct workspace *ws) |
Jonas Ådahl | 0476974 | 2012-06-13 00:01:24 +0200 | [diff] [blame] | 879 | { |
| 880 | struct focus_state *state, *next; |
Kristian Høgsberg | fe7aa90 | 2013-05-08 09:54:37 -0400 | [diff] [blame] | 881 | struct weston_surface *surface; |
Neil Roberts | 4237f50 | 2014-04-09 16:33:31 +0100 | [diff] [blame] | 882 | struct wl_list pending_seat_list; |
| 883 | struct weston_seat *seat, *next_seat; |
| 884 | |
| 885 | /* Temporarily steal the list of seats so that we can keep |
| 886 | * track of the seats we've already processed */ |
| 887 | wl_list_init(&pending_seat_list); |
| 888 | wl_list_insert_list(&pending_seat_list, &shell->compositor->seat_list); |
| 889 | wl_list_init(&shell->compositor->seat_list); |
Jonas Ådahl | 0476974 | 2012-06-13 00:01:24 +0200 | [diff] [blame] | 890 | |
| 891 | wl_list_for_each_safe(state, next, &ws->focus_list, link) { |
Neil Roberts | 4237f50 | 2014-04-09 16:33:31 +0100 | [diff] [blame] | 892 | wl_list_remove(&state->seat->link); |
| 893 | wl_list_insert(&shell->compositor->seat_list, |
| 894 | &state->seat->link); |
| 895 | |
Kristian Høgsberg | e61d2f4 | 2014-01-17 12:18:53 -0800 | [diff] [blame] | 896 | if (state->seat->keyboard == NULL) |
| 897 | continue; |
| 898 | |
Kristian Høgsberg | fe7aa90 | 2013-05-08 09:54:37 -0400 | [diff] [blame] | 899 | surface = state->keyboard_focus; |
Jonas Ådahl | 5689944 | 2012-08-29 22:12:59 +0200 | [diff] [blame] | 900 | |
Kristian Høgsberg | e314875 | 2013-05-06 23:19:49 -0400 | [diff] [blame] | 901 | weston_keyboard_set_focus(state->seat->keyboard, surface); |
Jonas Ådahl | 0476974 | 2012-06-13 00:01:24 +0200 | [diff] [blame] | 902 | } |
Neil Roberts | 4237f50 | 2014-04-09 16:33:31 +0100 | [diff] [blame] | 903 | |
| 904 | /* For any remaining seats that we don't have a focus state |
| 905 | * for we'll reset the keyboard focus to NULL */ |
| 906 | wl_list_for_each_safe(seat, next_seat, &pending_seat_list, link) { |
| 907 | wl_list_insert(&shell->compositor->seat_list, &seat->link); |
| 908 | |
Ander Conselvan de Oliveira | 6e56ab4 | 2014-05-07 11:57:28 +0300 | [diff] [blame] | 909 | if (seat->keyboard == NULL) |
Neil Roberts | 4237f50 | 2014-04-09 16:33:31 +0100 | [diff] [blame] | 910 | continue; |
| 911 | |
| 912 | weston_keyboard_set_focus(seat->keyboard, NULL); |
| 913 | } |
Jonas Ådahl | 0476974 | 2012-06-13 00:01:24 +0200 | [diff] [blame] | 914 | } |
| 915 | |
| 916 | static void |
Jonas Ådahl | 8de6a1d | 2012-08-29 22:13:00 +0200 | [diff] [blame] | 917 | replace_focus_state(struct desktop_shell *shell, struct workspace *ws, |
| 918 | struct weston_seat *seat) |
| 919 | { |
| 920 | struct focus_state *state; |
Jonas Ådahl | 8de6a1d | 2012-08-29 22:13:00 +0200 | [diff] [blame] | 921 | |
| 922 | wl_list_for_each(state, &ws->focus_list, link) { |
| 923 | if (state->seat == seat) { |
Kristian Høgsberg | d500bf1 | 2014-01-22 12:25:20 -0800 | [diff] [blame] | 924 | focus_state_set_focus(state, seat->keyboard->focus); |
Jonas Ådahl | 8de6a1d | 2012-08-29 22:13:00 +0200 | [diff] [blame] | 925 | return; |
| 926 | } |
| 927 | } |
| 928 | } |
| 929 | |
| 930 | static void |
| 931 | drop_focus_state(struct desktop_shell *shell, struct workspace *ws, |
| 932 | struct weston_surface *surface) |
| 933 | { |
| 934 | struct focus_state *state; |
| 935 | |
| 936 | wl_list_for_each(state, &ws->focus_list, link) |
| 937 | if (state->keyboard_focus == surface) |
Kristian Høgsberg | d500bf1 | 2014-01-22 12:25:20 -0800 | [diff] [blame] | 938 | focus_state_set_focus(state, NULL); |
Jonas Ådahl | 8de6a1d | 2012-08-29 22:13:00 +0200 | [diff] [blame] | 939 | } |
| 940 | |
| 941 | static void |
Louis-Francis Ratté-Boulianne | b482dbd | 2013-11-19 11:37:11 +0100 | [diff] [blame] | 942 | animate_focus_change(struct desktop_shell *shell, struct workspace *ws, |
| 943 | struct weston_view *from, struct weston_view *to) |
| 944 | { |
| 945 | struct weston_output *output; |
| 946 | bool focus_surface_created = false; |
| 947 | |
| 948 | /* FIXME: Only support dim animation using two layers */ |
| 949 | if (from == to || shell->focus_animation_type != ANIMATION_DIM_LAYER) |
| 950 | return; |
| 951 | |
| 952 | output = get_default_output(shell->compositor); |
| 953 | if (ws->fsurf_front == NULL && (from || to)) { |
| 954 | ws->fsurf_front = create_focus_surface(shell->compositor, output); |
U. Artie Eoff | 0b23b2b | 2014-01-15 14:45:59 -0800 | [diff] [blame] | 955 | if (ws->fsurf_front == NULL) |
| 956 | return; |
Louis-Francis Ratté-Boulianne | b482dbd | 2013-11-19 11:37:11 +0100 | [diff] [blame] | 957 | ws->fsurf_front->view->alpha = 0.0; |
U. Artie Eoff | 0b23b2b | 2014-01-15 14:45:59 -0800 | [diff] [blame] | 958 | |
| 959 | ws->fsurf_back = create_focus_surface(shell->compositor, output); |
| 960 | if (ws->fsurf_back == NULL) { |
| 961 | focus_surface_destroy(ws->fsurf_front); |
| 962 | return; |
| 963 | } |
Louis-Francis Ratté-Boulianne | b482dbd | 2013-11-19 11:37:11 +0100 | [diff] [blame] | 964 | ws->fsurf_back->view->alpha = 0.0; |
U. Artie Eoff | 0b23b2b | 2014-01-15 14:45:59 -0800 | [diff] [blame] | 965 | |
Louis-Francis Ratté-Boulianne | b482dbd | 2013-11-19 11:37:11 +0100 | [diff] [blame] | 966 | focus_surface_created = true; |
| 967 | } else { |
Giulio Camuffo | 412e6a5 | 2014-07-09 22:12:56 +0300 | [diff] [blame] | 968 | weston_layer_entry_remove(&ws->fsurf_front->view->layer_link); |
| 969 | weston_layer_entry_remove(&ws->fsurf_back->view->layer_link); |
Louis-Francis Ratté-Boulianne | b482dbd | 2013-11-19 11:37:11 +0100 | [diff] [blame] | 970 | } |
| 971 | |
| 972 | if (ws->focus_animation) { |
| 973 | weston_view_animation_destroy(ws->focus_animation); |
| 974 | ws->focus_animation = NULL; |
| 975 | } |
| 976 | |
| 977 | if (to) |
Giulio Camuffo | 412e6a5 | 2014-07-09 22:12:56 +0300 | [diff] [blame] | 978 | weston_layer_entry_insert(&to->layer_link, |
| 979 | &ws->fsurf_front->view->layer_link); |
Louis-Francis Ratté-Boulianne | b482dbd | 2013-11-19 11:37:11 +0100 | [diff] [blame] | 980 | else if (from) |
Giulio Camuffo | 412e6a5 | 2014-07-09 22:12:56 +0300 | [diff] [blame] | 981 | weston_layer_entry_insert(&ws->layer.view_list, |
| 982 | &ws->fsurf_front->view->layer_link); |
Louis-Francis Ratté-Boulianne | b482dbd | 2013-11-19 11:37:11 +0100 | [diff] [blame] | 983 | |
| 984 | if (focus_surface_created) { |
| 985 | ws->focus_animation = weston_fade_run( |
| 986 | ws->fsurf_front->view, |
Jonny Lamb | 7e7d485 | 2014-05-22 22:41:34 +0200 | [diff] [blame] | 987 | ws->fsurf_front->view->alpha, 0.4, 300, |
Louis-Francis Ratté-Boulianne | b482dbd | 2013-11-19 11:37:11 +0100 | [diff] [blame] | 988 | focus_animation_done, ws); |
| 989 | } else if (from) { |
Giulio Camuffo | 412e6a5 | 2014-07-09 22:12:56 +0300 | [diff] [blame] | 990 | weston_layer_entry_insert(&from->layer_link, |
| 991 | &ws->fsurf_back->view->layer_link); |
Louis-Francis Ratté-Boulianne | b482dbd | 2013-11-19 11:37:11 +0100 | [diff] [blame] | 992 | ws->focus_animation = weston_stable_fade_run( |
| 993 | ws->fsurf_front->view, 0.0, |
Jonny Lamb | 7e7d485 | 2014-05-22 22:41:34 +0200 | [diff] [blame] | 994 | ws->fsurf_back->view, 0.4, |
Louis-Francis Ratté-Boulianne | b482dbd | 2013-11-19 11:37:11 +0100 | [diff] [blame] | 995 | focus_animation_done, ws); |
| 996 | } else if (to) { |
Giulio Camuffo | 412e6a5 | 2014-07-09 22:12:56 +0300 | [diff] [blame] | 997 | weston_layer_entry_insert(&ws->layer.view_list, |
| 998 | &ws->fsurf_back->view->layer_link); |
Louis-Francis Ratté-Boulianne | b482dbd | 2013-11-19 11:37:11 +0100 | [diff] [blame] | 999 | ws->focus_animation = weston_stable_fade_run( |
| 1000 | ws->fsurf_front->view, 0.0, |
Jonny Lamb | 7e7d485 | 2014-05-22 22:41:34 +0200 | [diff] [blame] | 1001 | ws->fsurf_back->view, 0.4, |
Louis-Francis Ratté-Boulianne | b482dbd | 2013-11-19 11:37:11 +0100 | [diff] [blame] | 1002 | focus_animation_done, ws); |
| 1003 | } |
| 1004 | } |
| 1005 | |
| 1006 | static void |
Jonas Ådahl | e3cddce | 2012-06-13 00:01:22 +0200 | [diff] [blame] | 1007 | workspace_destroy(struct workspace *ws) |
| 1008 | { |
Jonas Ådahl | 0476974 | 2012-06-13 00:01:24 +0200 | [diff] [blame] | 1009 | struct focus_state *state, *next; |
| 1010 | |
| 1011 | wl_list_for_each_safe(state, next, &ws->focus_list, link) |
| 1012 | focus_state_destroy(state); |
| 1013 | |
Louis-Francis Ratté-Boulianne | b482dbd | 2013-11-19 11:37:11 +0100 | [diff] [blame] | 1014 | if (ws->fsurf_front) |
| 1015 | focus_surface_destroy(ws->fsurf_front); |
| 1016 | if (ws->fsurf_back) |
| 1017 | focus_surface_destroy(ws->fsurf_back); |
| 1018 | |
Jonas Ådahl | e3cddce | 2012-06-13 00:01:22 +0200 | [diff] [blame] | 1019 | free(ws); |
| 1020 | } |
| 1021 | |
Jonas Ådahl | 0476974 | 2012-06-13 00:01:24 +0200 | [diff] [blame] | 1022 | static void |
| 1023 | seat_destroyed(struct wl_listener *listener, void *data) |
| 1024 | { |
| 1025 | struct weston_seat *seat = data; |
| 1026 | struct focus_state *state, *next; |
| 1027 | struct workspace *ws = container_of(listener, |
| 1028 | struct workspace, |
| 1029 | seat_destroyed_listener); |
| 1030 | |
| 1031 | wl_list_for_each_safe(state, next, &ws->focus_list, link) |
| 1032 | if (state->seat == seat) |
| 1033 | wl_list_remove(&state->link); |
| 1034 | } |
| 1035 | |
Jonas Ådahl | e3cddce | 2012-06-13 00:01:22 +0200 | [diff] [blame] | 1036 | static struct workspace * |
| 1037 | workspace_create(void) |
| 1038 | { |
| 1039 | struct workspace *ws = malloc(sizeof *ws); |
| 1040 | if (ws == NULL) |
| 1041 | return NULL; |
| 1042 | |
| 1043 | weston_layer_init(&ws->layer, NULL); |
| 1044 | |
Jonas Ådahl | 0476974 | 2012-06-13 00:01:24 +0200 | [diff] [blame] | 1045 | wl_list_init(&ws->focus_list); |
| 1046 | wl_list_init(&ws->seat_destroyed_listener.link); |
| 1047 | ws->seat_destroyed_listener.notify = seat_destroyed; |
Louis-Francis Ratté-Boulianne | b482dbd | 2013-11-19 11:37:11 +0100 | [diff] [blame] | 1048 | ws->fsurf_front = NULL; |
| 1049 | ws->fsurf_back = NULL; |
| 1050 | ws->focus_animation = NULL; |
Jonas Ådahl | 0476974 | 2012-06-13 00:01:24 +0200 | [diff] [blame] | 1051 | |
Jonas Ådahl | e3cddce | 2012-06-13 00:01:22 +0200 | [diff] [blame] | 1052 | return ws; |
| 1053 | } |
| 1054 | |
Jonas Ådahl | 62fcd04 | 2012-06-13 00:01:23 +0200 | [diff] [blame] | 1055 | static int |
| 1056 | workspace_is_empty(struct workspace *ws) |
| 1057 | { |
Giulio Camuffo | 412e6a5 | 2014-07-09 22:12:56 +0300 | [diff] [blame] | 1058 | return wl_list_empty(&ws->layer.view_list.link); |
Jonas Ådahl | 62fcd04 | 2012-06-13 00:01:23 +0200 | [diff] [blame] | 1059 | } |
| 1060 | |
Jonas Ådahl | e3cddce | 2012-06-13 00:01:22 +0200 | [diff] [blame] | 1061 | static struct workspace * |
| 1062 | get_workspace(struct desktop_shell *shell, unsigned int index) |
| 1063 | { |
| 1064 | struct workspace **pws = shell->workspaces.array.data; |
Philipp Brüschweiler | 067abf6 | 2012-09-01 16:03:05 +0200 | [diff] [blame] | 1065 | assert(index < shell->workspaces.num); |
Jonas Ådahl | e3cddce | 2012-06-13 00:01:22 +0200 | [diff] [blame] | 1066 | pws += index; |
| 1067 | return *pws; |
| 1068 | } |
| 1069 | |
Kristian Høgsberg | 1ef2313 | 2013-12-04 00:20:01 -0800 | [diff] [blame] | 1070 | struct workspace * |
Jonas Ådahl | e3cddce | 2012-06-13 00:01:22 +0200 | [diff] [blame] | 1071 | get_current_workspace(struct desktop_shell *shell) |
| 1072 | { |
| 1073 | return get_workspace(shell, shell->workspaces.current); |
| 1074 | } |
| 1075 | |
| 1076 | static void |
| 1077 | activate_workspace(struct desktop_shell *shell, unsigned int index) |
| 1078 | { |
| 1079 | struct workspace *ws; |
| 1080 | |
| 1081 | ws = get_workspace(shell, index); |
| 1082 | wl_list_insert(&shell->panel_layer.link, &ws->layer.link); |
| 1083 | |
| 1084 | shell->workspaces.current = index; |
| 1085 | } |
| 1086 | |
Jonas Ådahl | 62fcd04 | 2012-06-13 00:01:23 +0200 | [diff] [blame] | 1087 | static unsigned int |
| 1088 | get_output_height(struct weston_output *output) |
| 1089 | { |
| 1090 | return abs(output->region.extents.y1 - output->region.extents.y2); |
| 1091 | } |
| 1092 | |
| 1093 | static void |
Louis-Francis Ratté-Boulianne | b482dbd | 2013-11-19 11:37:11 +0100 | [diff] [blame] | 1094 | view_translate(struct workspace *ws, struct weston_view *view, double d) |
Jonas Ådahl | 62fcd04 | 2012-06-13 00:01:23 +0200 | [diff] [blame] | 1095 | { |
Jonas Ådahl | 62fcd04 | 2012-06-13 00:01:23 +0200 | [diff] [blame] | 1096 | struct weston_transform *transform; |
| 1097 | |
Louis-Francis Ratté-Boulianne | b482dbd | 2013-11-19 11:37:11 +0100 | [diff] [blame] | 1098 | if (is_focus_view(view)) { |
| 1099 | struct focus_surface *fsurf = get_focus_surface(view->surface); |
| 1100 | transform = &fsurf->workspace_transform; |
| 1101 | } else { |
| 1102 | struct shell_surface *shsurf = get_shell_surface(view->surface); |
| 1103 | transform = &shsurf->workspace_transform; |
| 1104 | } |
| 1105 | |
Jonas Ådahl | 62fcd04 | 2012-06-13 00:01:23 +0200 | [diff] [blame] | 1106 | if (wl_list_empty(&transform->link)) |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 1107 | wl_list_insert(view->geometry.transformation_list.prev, |
Louis-Francis Ratté-Boulianne | b482dbd | 2013-11-19 11:37:11 +0100 | [diff] [blame] | 1108 | &transform->link); |
Jonas Ådahl | 62fcd04 | 2012-06-13 00:01:23 +0200 | [diff] [blame] | 1109 | |
Louis-Francis Ratté-Boulianne | b482dbd | 2013-11-19 11:37:11 +0100 | [diff] [blame] | 1110 | weston_matrix_init(&transform->matrix); |
| 1111 | weston_matrix_translate(&transform->matrix, |
Jonas Ådahl | 62fcd04 | 2012-06-13 00:01:23 +0200 | [diff] [blame] | 1112 | 0.0, d, 0.0); |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 1113 | weston_view_geometry_dirty(view); |
Jonas Ådahl | 62fcd04 | 2012-06-13 00:01:23 +0200 | [diff] [blame] | 1114 | } |
| 1115 | |
| 1116 | static void |
| 1117 | workspace_translate_out(struct workspace *ws, double fraction) |
| 1118 | { |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 1119 | struct weston_view *view; |
Jonas Ådahl | 62fcd04 | 2012-06-13 00:01:23 +0200 | [diff] [blame] | 1120 | unsigned int height; |
| 1121 | double d; |
| 1122 | |
Giulio Camuffo | 412e6a5 | 2014-07-09 22:12:56 +0300 | [diff] [blame] | 1123 | 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] | 1124 | height = get_output_height(view->surface->output); |
Jonas Ådahl | 62fcd04 | 2012-06-13 00:01:23 +0200 | [diff] [blame] | 1125 | d = height * fraction; |
| 1126 | |
Louis-Francis Ratté-Boulianne | b482dbd | 2013-11-19 11:37:11 +0100 | [diff] [blame] | 1127 | view_translate(ws, view, d); |
Jonas Ådahl | 62fcd04 | 2012-06-13 00:01:23 +0200 | [diff] [blame] | 1128 | } |
| 1129 | } |
| 1130 | |
| 1131 | static void |
| 1132 | workspace_translate_in(struct workspace *ws, double fraction) |
| 1133 | { |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 1134 | struct weston_view *view; |
Jonas Ådahl | 62fcd04 | 2012-06-13 00:01:23 +0200 | [diff] [blame] | 1135 | unsigned int height; |
| 1136 | double d; |
| 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) { |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 1139 | height = get_output_height(view->surface->output); |
Jonas Ådahl | 62fcd04 | 2012-06-13 00:01:23 +0200 | [diff] [blame] | 1140 | |
| 1141 | if (fraction > 0) |
| 1142 | d = -(height - height * fraction); |
| 1143 | else |
| 1144 | d = height + height * fraction; |
| 1145 | |
Louis-Francis Ratté-Boulianne | b482dbd | 2013-11-19 11:37:11 +0100 | [diff] [blame] | 1146 | view_translate(ws, view, d); |
Jonas Ådahl | 62fcd04 | 2012-06-13 00:01:23 +0200 | [diff] [blame] | 1147 | } |
| 1148 | } |
| 1149 | |
| 1150 | static void |
Jonas Ådahl | e9d2250 | 2012-08-29 22:13:01 +0200 | [diff] [blame] | 1151 | broadcast_current_workspace_state(struct desktop_shell *shell) |
| 1152 | { |
Kristian Høgsberg | 2e3c396 | 2013-09-11 12:00:47 -0700 | [diff] [blame] | 1153 | struct wl_resource *resource; |
Jonas Ådahl | e9d2250 | 2012-08-29 22:13:01 +0200 | [diff] [blame] | 1154 | |
Kristian Høgsberg | 2e3c396 | 2013-09-11 12:00:47 -0700 | [diff] [blame] | 1155 | wl_resource_for_each(resource, &shell->workspaces.client_list) |
| 1156 | workspace_manager_send_state(resource, |
Jonas Ådahl | e9d2250 | 2012-08-29 22:13:01 +0200 | [diff] [blame] | 1157 | shell->workspaces.current, |
| 1158 | shell->workspaces.num); |
| 1159 | } |
| 1160 | |
| 1161 | static void |
Jonas Ådahl | 62fcd04 | 2012-06-13 00:01:23 +0200 | [diff] [blame] | 1162 | reverse_workspace_change_animation(struct desktop_shell *shell, |
| 1163 | unsigned int index, |
| 1164 | struct workspace *from, |
| 1165 | struct workspace *to) |
| 1166 | { |
| 1167 | shell->workspaces.current = index; |
| 1168 | |
| 1169 | shell->workspaces.anim_to = to; |
| 1170 | shell->workspaces.anim_from = from; |
| 1171 | shell->workspaces.anim_dir = -1 * shell->workspaces.anim_dir; |
| 1172 | shell->workspaces.anim_timestamp = 0; |
| 1173 | |
Scott Moreau | 4272e63 | 2012-08-13 09:58:41 -0600 | [diff] [blame] | 1174 | weston_compositor_schedule_repaint(shell->compositor); |
Jonas Ådahl | 62fcd04 | 2012-06-13 00:01:23 +0200 | [diff] [blame] | 1175 | } |
| 1176 | |
| 1177 | static void |
| 1178 | workspace_deactivate_transforms(struct workspace *ws) |
| 1179 | { |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 1180 | struct weston_view *view; |
Louis-Francis Ratté-Boulianne | b482dbd | 2013-11-19 11:37:11 +0100 | [diff] [blame] | 1181 | struct weston_transform *transform; |
Jonas Ådahl | 62fcd04 | 2012-06-13 00:01:23 +0200 | [diff] [blame] | 1182 | |
Giulio Camuffo | 412e6a5 | 2014-07-09 22:12:56 +0300 | [diff] [blame] | 1183 | 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] | 1184 | if (is_focus_view(view)) { |
| 1185 | struct focus_surface *fsurf = get_focus_surface(view->surface); |
| 1186 | transform = &fsurf->workspace_transform; |
| 1187 | } else { |
| 1188 | struct shell_surface *shsurf = get_shell_surface(view->surface); |
| 1189 | transform = &shsurf->workspace_transform; |
| 1190 | } |
| 1191 | |
| 1192 | if (!wl_list_empty(&transform->link)) { |
| 1193 | wl_list_remove(&transform->link); |
| 1194 | wl_list_init(&transform->link); |
Jonas Ådahl | 8de6a1d | 2012-08-29 22:13:00 +0200 | [diff] [blame] | 1195 | } |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 1196 | weston_view_geometry_dirty(view); |
Jonas Ådahl | 62fcd04 | 2012-06-13 00:01:23 +0200 | [diff] [blame] | 1197 | } |
| 1198 | } |
| 1199 | |
| 1200 | static void |
| 1201 | finish_workspace_change_animation(struct desktop_shell *shell, |
| 1202 | struct workspace *from, |
| 1203 | struct workspace *to) |
| 1204 | { |
Ander Conselvan de Oliveira | 9c6217e | 2014-05-07 11:57:26 +0300 | [diff] [blame] | 1205 | struct weston_view *view; |
| 1206 | |
Scott Moreau | 4272e63 | 2012-08-13 09:58:41 -0600 | [diff] [blame] | 1207 | weston_compositor_schedule_repaint(shell->compositor); |
Jonas Ådahl | 62fcd04 | 2012-06-13 00:01:23 +0200 | [diff] [blame] | 1208 | |
Ander Conselvan de Oliveira | 9c6217e | 2014-05-07 11:57:26 +0300 | [diff] [blame] | 1209 | /* Views that extend past the bottom of the output are still |
| 1210 | * visible after the workspace animation ends but before its layer |
| 1211 | * is hidden. In that case, we need to damage below those views so |
| 1212 | * that the screen is properly repainted. */ |
Giulio Camuffo | 412e6a5 | 2014-07-09 22:12:56 +0300 | [diff] [blame] | 1213 | 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] | 1214 | weston_view_damage_below(view); |
| 1215 | |
Jonas Ådahl | 62fcd04 | 2012-06-13 00:01:23 +0200 | [diff] [blame] | 1216 | wl_list_remove(&shell->workspaces.animation.link); |
| 1217 | workspace_deactivate_transforms(from); |
| 1218 | workspace_deactivate_transforms(to); |
| 1219 | shell->workspaces.anim_to = NULL; |
| 1220 | |
| 1221 | wl_list_remove(&shell->workspaces.anim_from->layer.link); |
| 1222 | } |
| 1223 | |
| 1224 | static void |
| 1225 | animate_workspace_change_frame(struct weston_animation *animation, |
| 1226 | struct weston_output *output, uint32_t msecs) |
| 1227 | { |
| 1228 | struct desktop_shell *shell = |
| 1229 | container_of(animation, struct desktop_shell, |
| 1230 | workspaces.animation); |
| 1231 | struct workspace *from = shell->workspaces.anim_from; |
| 1232 | struct workspace *to = shell->workspaces.anim_to; |
| 1233 | uint32_t t; |
| 1234 | double x, y; |
| 1235 | |
| 1236 | if (workspace_is_empty(from) && workspace_is_empty(to)) { |
| 1237 | finish_workspace_change_animation(shell, from, to); |
| 1238 | return; |
| 1239 | } |
| 1240 | |
| 1241 | if (shell->workspaces.anim_timestamp == 0) { |
| 1242 | if (shell->workspaces.anim_current == 0.0) |
| 1243 | shell->workspaces.anim_timestamp = msecs; |
| 1244 | else |
| 1245 | shell->workspaces.anim_timestamp = |
| 1246 | msecs - |
| 1247 | /* Invers of movement function 'y' below. */ |
| 1248 | (asin(1.0 - shell->workspaces.anim_current) * |
| 1249 | DEFAULT_WORKSPACE_CHANGE_ANIMATION_LENGTH * |
| 1250 | M_2_PI); |
| 1251 | } |
| 1252 | |
| 1253 | t = msecs - shell->workspaces.anim_timestamp; |
| 1254 | |
| 1255 | /* |
| 1256 | * x = [0, π/2] |
| 1257 | * y(x) = sin(x) |
| 1258 | */ |
| 1259 | x = t * (1.0/DEFAULT_WORKSPACE_CHANGE_ANIMATION_LENGTH) * M_PI_2; |
| 1260 | y = sin(x); |
| 1261 | |
| 1262 | if (t < DEFAULT_WORKSPACE_CHANGE_ANIMATION_LENGTH) { |
Scott Moreau | 4272e63 | 2012-08-13 09:58:41 -0600 | [diff] [blame] | 1263 | weston_compositor_schedule_repaint(shell->compositor); |
Jonas Ådahl | 62fcd04 | 2012-06-13 00:01:23 +0200 | [diff] [blame] | 1264 | |
| 1265 | workspace_translate_out(from, shell->workspaces.anim_dir * y); |
| 1266 | workspace_translate_in(to, shell->workspaces.anim_dir * y); |
| 1267 | shell->workspaces.anim_current = y; |
| 1268 | |
Scott Moreau | 4272e63 | 2012-08-13 09:58:41 -0600 | [diff] [blame] | 1269 | weston_compositor_schedule_repaint(shell->compositor); |
Jonas Ådahl | 62fcd04 | 2012-06-13 00:01:23 +0200 | [diff] [blame] | 1270 | } |
Jonas Ådahl | 0476974 | 2012-06-13 00:01:24 +0200 | [diff] [blame] | 1271 | else |
Jonas Ådahl | 62fcd04 | 2012-06-13 00:01:23 +0200 | [diff] [blame] | 1272 | finish_workspace_change_animation(shell, from, to); |
Jonas Ådahl | 62fcd04 | 2012-06-13 00:01:23 +0200 | [diff] [blame] | 1273 | } |
| 1274 | |
| 1275 | static void |
| 1276 | animate_workspace_change(struct desktop_shell *shell, |
| 1277 | unsigned int index, |
| 1278 | struct workspace *from, |
| 1279 | struct workspace *to) |
| 1280 | { |
| 1281 | struct weston_output *output; |
| 1282 | |
| 1283 | int dir; |
| 1284 | |
| 1285 | if (index > shell->workspaces.current) |
| 1286 | dir = -1; |
| 1287 | else |
| 1288 | dir = 1; |
| 1289 | |
| 1290 | shell->workspaces.current = index; |
| 1291 | |
| 1292 | shell->workspaces.anim_dir = dir; |
| 1293 | shell->workspaces.anim_from = from; |
| 1294 | shell->workspaces.anim_to = to; |
| 1295 | shell->workspaces.anim_current = 0.0; |
| 1296 | shell->workspaces.anim_timestamp = 0; |
| 1297 | |
| 1298 | output = container_of(shell->compositor->output_list.next, |
| 1299 | struct weston_output, link); |
| 1300 | wl_list_insert(&output->animation_list, |
| 1301 | &shell->workspaces.animation.link); |
| 1302 | |
Jonas Ådahl | 8de6a1d | 2012-08-29 22:13:00 +0200 | [diff] [blame] | 1303 | wl_list_insert(from->layer.link.prev, &to->layer.link); |
Jonas Ådahl | 62fcd04 | 2012-06-13 00:01:23 +0200 | [diff] [blame] | 1304 | |
| 1305 | workspace_translate_in(to, 0); |
| 1306 | |
Kristian Høgsberg | 2f5faff | 2012-07-31 16:36:34 -0400 | [diff] [blame] | 1307 | restore_focus_state(shell, to); |
Jonas Ådahl | 0476974 | 2012-06-13 00:01:24 +0200 | [diff] [blame] | 1308 | |
Scott Moreau | 4272e63 | 2012-08-13 09:58:41 -0600 | [diff] [blame] | 1309 | weston_compositor_schedule_repaint(shell->compositor); |
Jonas Ådahl | 62fcd04 | 2012-06-13 00:01:23 +0200 | [diff] [blame] | 1310 | } |
| 1311 | |
Jonas Ådahl | e3cddce | 2012-06-13 00:01:22 +0200 | [diff] [blame] | 1312 | static void |
Jonas Ådahl | 8de6a1d | 2012-08-29 22:13:00 +0200 | [diff] [blame] | 1313 | update_workspace(struct desktop_shell *shell, unsigned int index, |
| 1314 | struct workspace *from, struct workspace *to) |
| 1315 | { |
| 1316 | shell->workspaces.current = index; |
| 1317 | wl_list_insert(&from->layer.link, &to->layer.link); |
| 1318 | wl_list_remove(&from->layer.link); |
| 1319 | } |
| 1320 | |
| 1321 | static void |
Jonas Ådahl | e3cddce | 2012-06-13 00:01:22 +0200 | [diff] [blame] | 1322 | change_workspace(struct desktop_shell *shell, unsigned int index) |
| 1323 | { |
| 1324 | struct workspace *from; |
| 1325 | struct workspace *to; |
Louis-Francis Ratté-Boulianne | b482dbd | 2013-11-19 11:37:11 +0100 | [diff] [blame] | 1326 | struct focus_state *state; |
Jonas Ådahl | e3cddce | 2012-06-13 00:01:22 +0200 | [diff] [blame] | 1327 | |
| 1328 | if (index == shell->workspaces.current) |
| 1329 | return; |
| 1330 | |
| 1331 | /* Don't change workspace when there is any fullscreen surfaces. */ |
Giulio Camuffo | 412e6a5 | 2014-07-09 22:12:56 +0300 | [diff] [blame] | 1332 | if (!wl_list_empty(&shell->fullscreen_layer.view_list.link)) |
Jonas Ådahl | e3cddce | 2012-06-13 00:01:22 +0200 | [diff] [blame] | 1333 | return; |
| 1334 | |
Jonas Ådahl | e3cddce | 2012-06-13 00:01:22 +0200 | [diff] [blame] | 1335 | from = get_current_workspace(shell); |
| 1336 | to = get_workspace(shell, index); |
| 1337 | |
Jonas Ådahl | 62fcd04 | 2012-06-13 00:01:23 +0200 | [diff] [blame] | 1338 | if (shell->workspaces.anim_from == to && |
| 1339 | shell->workspaces.anim_to == from) { |
Jonas Ådahl | 8de6a1d | 2012-08-29 22:13:00 +0200 | [diff] [blame] | 1340 | restore_focus_state(shell, to); |
Jonas Ådahl | 62fcd04 | 2012-06-13 00:01:23 +0200 | [diff] [blame] | 1341 | reverse_workspace_change_animation(shell, index, from, to); |
Jonas Ådahl | e9d2250 | 2012-08-29 22:13:01 +0200 | [diff] [blame] | 1342 | broadcast_current_workspace_state(shell); |
Jonas Ådahl | 62fcd04 | 2012-06-13 00:01:23 +0200 | [diff] [blame] | 1343 | return; |
| 1344 | } |
Jonas Ådahl | e3cddce | 2012-06-13 00:01:22 +0200 | [diff] [blame] | 1345 | |
Jonas Ådahl | 62fcd04 | 2012-06-13 00:01:23 +0200 | [diff] [blame] | 1346 | if (shell->workspaces.anim_to != NULL) |
| 1347 | finish_workspace_change_animation(shell, |
| 1348 | shell->workspaces.anim_from, |
| 1349 | shell->workspaces.anim_to); |
| 1350 | |
Jonas Ådahl | 8de6a1d | 2012-08-29 22:13:00 +0200 | [diff] [blame] | 1351 | restore_focus_state(shell, to); |
Jonas Ådahl | 0476974 | 2012-06-13 00:01:24 +0200 | [diff] [blame] | 1352 | |
Louis-Francis Ratté-Boulianne | b482dbd | 2013-11-19 11:37:11 +0100 | [diff] [blame] | 1353 | if (shell->focus_animation_type != ANIMATION_NONE) { |
| 1354 | wl_list_for_each(state, &from->focus_list, link) |
| 1355 | if (state->keyboard_focus) |
| 1356 | animate_focus_change(shell, from, |
| 1357 | get_default_view(state->keyboard_focus), NULL); |
| 1358 | |
| 1359 | wl_list_for_each(state, &to->focus_list, link) |
| 1360 | if (state->keyboard_focus) |
| 1361 | animate_focus_change(shell, to, |
| 1362 | NULL, get_default_view(state->keyboard_focus)); |
| 1363 | } |
| 1364 | |
Jonas Ådahl | 8de6a1d | 2012-08-29 22:13:00 +0200 | [diff] [blame] | 1365 | if (workspace_is_empty(to) && workspace_is_empty(from)) |
| 1366 | update_workspace(shell, index, from, to); |
Jonas Ådahl | 62fcd04 | 2012-06-13 00:01:23 +0200 | [diff] [blame] | 1367 | else |
| 1368 | animate_workspace_change(shell, index, from, to); |
Jonas Ådahl | e9d2250 | 2012-08-29 22:13:01 +0200 | [diff] [blame] | 1369 | |
| 1370 | broadcast_current_workspace_state(shell); |
Pekka Paalanen | e955f1e | 2011-12-07 11:49:52 +0200 | [diff] [blame] | 1371 | } |
| 1372 | |
Jonas Ådahl | 8de6a1d | 2012-08-29 22:13:00 +0200 | [diff] [blame] | 1373 | static bool |
| 1374 | workspace_has_only(struct workspace *ws, struct weston_surface *surface) |
| 1375 | { |
Giulio Camuffo | 412e6a5 | 2014-07-09 22:12:56 +0300 | [diff] [blame] | 1376 | struct wl_list *list = &ws->layer.view_list.link; |
Jonas Ådahl | 8de6a1d | 2012-08-29 22:13:00 +0200 | [diff] [blame] | 1377 | struct wl_list *e; |
| 1378 | |
| 1379 | if (wl_list_empty(list)) |
| 1380 | return false; |
| 1381 | |
| 1382 | e = list->next; |
| 1383 | |
| 1384 | if (e->next != list) |
| 1385 | return false; |
| 1386 | |
Giulio Camuffo | 412e6a5 | 2014-07-09 22:12:56 +0300 | [diff] [blame] | 1387 | return container_of(e, struct weston_view, layer_link.link)->surface == surface; |
Jonas Ådahl | 8de6a1d | 2012-08-29 22:13:00 +0200 | [diff] [blame] | 1388 | } |
| 1389 | |
| 1390 | static void |
Philip Withnall | 659163d | 2013-11-25 18:01:36 +0000 | [diff] [blame] | 1391 | move_surface_to_workspace(struct desktop_shell *shell, |
| 1392 | struct shell_surface *shsurf, |
| 1393 | uint32_t workspace) |
Jonas Ådahl | e9d2250 | 2012-08-29 22:13:01 +0200 | [diff] [blame] | 1394 | { |
| 1395 | struct workspace *from; |
| 1396 | struct workspace *to; |
| 1397 | struct weston_seat *seat; |
Pekka Paalanen | 01388e2 | 2013-04-25 13:57:44 +0300 | [diff] [blame] | 1398 | struct weston_surface *focus; |
Philip Withnall | 659163d | 2013-11-25 18:01:36 +0000 | [diff] [blame] | 1399 | struct weston_view *view; |
Jonas Ådahl | e9d2250 | 2012-08-29 22:13:01 +0200 | [diff] [blame] | 1400 | |
| 1401 | if (workspace == shell->workspaces.current) |
| 1402 | return; |
| 1403 | |
Philip Withnall | 659163d | 2013-11-25 18:01:36 +0000 | [diff] [blame] | 1404 | view = get_default_view(shsurf->surface); |
| 1405 | if (!view) |
| 1406 | return; |
| 1407 | |
| 1408 | assert(weston_surface_get_main_surface(view->surface) == view->surface); |
| 1409 | |
Philipp Brüschweiler | 067abf6 | 2012-09-01 16:03:05 +0200 | [diff] [blame] | 1410 | if (workspace >= shell->workspaces.num) |
| 1411 | workspace = shell->workspaces.num - 1; |
| 1412 | |
Jonas Ådahl | e9d2250 | 2012-08-29 22:13:01 +0200 | [diff] [blame] | 1413 | from = get_current_workspace(shell); |
| 1414 | to = get_workspace(shell, workspace); |
| 1415 | |
Giulio Camuffo | 412e6a5 | 2014-07-09 22:12:56 +0300 | [diff] [blame] | 1416 | weston_layer_entry_remove(&view->layer_link); |
| 1417 | weston_layer_entry_insert(&to->layer.view_list, &view->layer_link); |
Jonas Ådahl | e9d2250 | 2012-08-29 22:13:01 +0200 | [diff] [blame] | 1418 | |
Philip Withnall | 648a4dd | 2013-11-25 18:01:44 +0000 | [diff] [blame] | 1419 | shell_surface_update_child_surface_layers(shsurf); |
| 1420 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 1421 | drop_focus_state(shell, from, view->surface); |
Pekka Paalanen | 01388e2 | 2013-04-25 13:57:44 +0300 | [diff] [blame] | 1422 | wl_list_for_each(seat, &shell->compositor->seat_list, link) { |
| 1423 | if (!seat->keyboard) |
| 1424 | continue; |
| 1425 | |
| 1426 | focus = weston_surface_get_main_surface(seat->keyboard->focus); |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 1427 | if (focus == view->surface) |
Kristian Høgsberg | e314875 | 2013-05-06 23:19:49 -0400 | [diff] [blame] | 1428 | weston_keyboard_set_focus(seat->keyboard, NULL); |
Pekka Paalanen | 01388e2 | 2013-04-25 13:57:44 +0300 | [diff] [blame] | 1429 | } |
Jonas Ådahl | e9d2250 | 2012-08-29 22:13:01 +0200 | [diff] [blame] | 1430 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 1431 | weston_view_damage_below(view); |
Jonas Ådahl | e9d2250 | 2012-08-29 22:13:01 +0200 | [diff] [blame] | 1432 | } |
| 1433 | |
| 1434 | static void |
Jonas Ådahl | 8de6a1d | 2012-08-29 22:13:00 +0200 | [diff] [blame] | 1435 | take_surface_to_workspace_by_seat(struct desktop_shell *shell, |
Kristian Høgsberg | e314875 | 2013-05-06 23:19:49 -0400 | [diff] [blame] | 1436 | struct weston_seat *seat, |
Jonas Ådahl | 8de6a1d | 2012-08-29 22:13:00 +0200 | [diff] [blame] | 1437 | unsigned int index) |
| 1438 | { |
Pekka Paalanen | 01388e2 | 2013-04-25 13:57:44 +0300 | [diff] [blame] | 1439 | struct weston_surface *surface; |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 1440 | struct weston_view *view; |
Jonas Ådahl | 8de6a1d | 2012-08-29 22:13:00 +0200 | [diff] [blame] | 1441 | struct shell_surface *shsurf; |
| 1442 | struct workspace *from; |
| 1443 | struct workspace *to; |
Jonas Ådahl | 8538b22 | 2012-08-29 22:13:03 +0200 | [diff] [blame] | 1444 | struct focus_state *state; |
Jonas Ådahl | 8de6a1d | 2012-08-29 22:13:00 +0200 | [diff] [blame] | 1445 | |
Pekka Paalanen | 01388e2 | 2013-04-25 13:57:44 +0300 | [diff] [blame] | 1446 | surface = weston_surface_get_main_surface(seat->keyboard->focus); |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 1447 | view = get_default_view(surface); |
| 1448 | if (view == NULL || |
Louis-Francis Ratté-Boulianne | b482dbd | 2013-11-19 11:37:11 +0100 | [diff] [blame] | 1449 | index == shell->workspaces.current || |
| 1450 | is_focus_view(view)) |
Jonas Ådahl | 8de6a1d | 2012-08-29 22:13:00 +0200 | [diff] [blame] | 1451 | return; |
| 1452 | |
| 1453 | from = get_current_workspace(shell); |
| 1454 | to = get_workspace(shell, index); |
| 1455 | |
Giulio Camuffo | 412e6a5 | 2014-07-09 22:12:56 +0300 | [diff] [blame] | 1456 | weston_layer_entry_remove(&view->layer_link); |
| 1457 | weston_layer_entry_insert(&to->layer.view_list, &view->layer_link); |
Jonas Ådahl | 8de6a1d | 2012-08-29 22:13:00 +0200 | [diff] [blame] | 1458 | |
Philip Withnall | 659163d | 2013-11-25 18:01:36 +0000 | [diff] [blame] | 1459 | shsurf = get_shell_surface(surface); |
Philip Withnall | 648a4dd | 2013-11-25 18:01:44 +0000 | [diff] [blame] | 1460 | if (shsurf != NULL) |
| 1461 | shell_surface_update_child_surface_layers(shsurf); |
Philip Withnall | 659163d | 2013-11-25 18:01:36 +0000 | [diff] [blame] | 1462 | |
Jonas Ådahl | e9d2250 | 2012-08-29 22:13:01 +0200 | [diff] [blame] | 1463 | replace_focus_state(shell, to, seat); |
Jonas Ådahl | 8de6a1d | 2012-08-29 22:13:00 +0200 | [diff] [blame] | 1464 | drop_focus_state(shell, from, surface); |
| 1465 | |
| 1466 | if (shell->workspaces.anim_from == to && |
| 1467 | shell->workspaces.anim_to == from) { |
Jonas Ådahl | e9d2250 | 2012-08-29 22:13:01 +0200 | [diff] [blame] | 1468 | wl_list_remove(&to->layer.link); |
| 1469 | wl_list_insert(from->layer.link.prev, &to->layer.link); |
| 1470 | |
Jonas Ådahl | 8de6a1d | 2012-08-29 22:13:00 +0200 | [diff] [blame] | 1471 | reverse_workspace_change_animation(shell, index, from, to); |
Jonas Ådahl | e9d2250 | 2012-08-29 22:13:01 +0200 | [diff] [blame] | 1472 | broadcast_current_workspace_state(shell); |
| 1473 | |
Jonas Ådahl | 8de6a1d | 2012-08-29 22:13:00 +0200 | [diff] [blame] | 1474 | return; |
| 1475 | } |
| 1476 | |
| 1477 | if (shell->workspaces.anim_to != NULL) |
| 1478 | finish_workspace_change_animation(shell, |
| 1479 | shell->workspaces.anim_from, |
| 1480 | shell->workspaces.anim_to); |
| 1481 | |
| 1482 | if (workspace_is_empty(from) && |
| 1483 | workspace_has_only(to, surface)) |
| 1484 | update_workspace(shell, index, from, to); |
| 1485 | else { |
Philip Withnall | 2c3849b | 2013-11-25 18:01:45 +0000 | [diff] [blame] | 1486 | if (shsurf != NULL && |
| 1487 | wl_list_empty(&shsurf->workspace_transform.link)) |
Jonas Ådahl | 8de6a1d | 2012-08-29 22:13:00 +0200 | [diff] [blame] | 1488 | wl_list_insert(&shell->workspaces.anim_sticky_list, |
| 1489 | &shsurf->workspace_transform.link); |
| 1490 | |
| 1491 | animate_workspace_change(shell, index, from, to); |
| 1492 | } |
Jonas Ådahl | e9d2250 | 2012-08-29 22:13:01 +0200 | [diff] [blame] | 1493 | |
| 1494 | broadcast_current_workspace_state(shell); |
Jonas Ådahl | 8538b22 | 2012-08-29 22:13:03 +0200 | [diff] [blame] | 1495 | |
| 1496 | state = ensure_focus_state(shell, seat); |
| 1497 | if (state != NULL) |
Kristian Høgsberg | d500bf1 | 2014-01-22 12:25:20 -0800 | [diff] [blame] | 1498 | focus_state_set_focus(state, surface); |
Jonas Ådahl | e9d2250 | 2012-08-29 22:13:01 +0200 | [diff] [blame] | 1499 | } |
| 1500 | |
| 1501 | static void |
| 1502 | workspace_manager_move_surface(struct wl_client *client, |
| 1503 | struct wl_resource *resource, |
| 1504 | struct wl_resource *surface_resource, |
| 1505 | uint32_t workspace) |
| 1506 | { |
Jason Ekstrand | 651f00e | 2013-06-14 10:07:54 -0500 | [diff] [blame] | 1507 | struct desktop_shell *shell = wl_resource_get_user_data(resource); |
Jonas Ådahl | e9d2250 | 2012-08-29 22:13:01 +0200 | [diff] [blame] | 1508 | struct weston_surface *surface = |
Jason Ekstrand | 0f2ef7e | 2013-06-14 10:07:53 -0500 | [diff] [blame] | 1509 | wl_resource_get_user_data(surface_resource); |
Pekka Paalanen | 01388e2 | 2013-04-25 13:57:44 +0300 | [diff] [blame] | 1510 | struct weston_surface *main_surface; |
Philip Withnall | 659163d | 2013-11-25 18:01:36 +0000 | [diff] [blame] | 1511 | struct shell_surface *shell_surface; |
Jonas Ådahl | e9d2250 | 2012-08-29 22:13:01 +0200 | [diff] [blame] | 1512 | |
Pekka Paalanen | 01388e2 | 2013-04-25 13:57:44 +0300 | [diff] [blame] | 1513 | main_surface = weston_surface_get_main_surface(surface); |
Philip Withnall | 659163d | 2013-11-25 18:01:36 +0000 | [diff] [blame] | 1514 | shell_surface = get_shell_surface(main_surface); |
| 1515 | if (shell_surface == NULL) |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 1516 | return; |
Philip Withnall | 659163d | 2013-11-25 18:01:36 +0000 | [diff] [blame] | 1517 | |
| 1518 | move_surface_to_workspace(shell, shell_surface, workspace); |
Jonas Ådahl | e9d2250 | 2012-08-29 22:13:01 +0200 | [diff] [blame] | 1519 | } |
| 1520 | |
| 1521 | static const struct workspace_manager_interface workspace_manager_implementation = { |
| 1522 | workspace_manager_move_surface, |
| 1523 | }; |
| 1524 | |
| 1525 | static void |
| 1526 | unbind_resource(struct wl_resource *resource) |
| 1527 | { |
Jason Ekstrand | 651f00e | 2013-06-14 10:07:54 -0500 | [diff] [blame] | 1528 | wl_list_remove(wl_resource_get_link(resource)); |
Jonas Ådahl | e9d2250 | 2012-08-29 22:13:01 +0200 | [diff] [blame] | 1529 | } |
| 1530 | |
| 1531 | static void |
| 1532 | bind_workspace_manager(struct wl_client *client, |
| 1533 | void *data, uint32_t version, uint32_t id) |
| 1534 | { |
| 1535 | struct desktop_shell *shell = data; |
| 1536 | struct wl_resource *resource; |
| 1537 | |
Jason Ekstrand | a85118c | 2013-06-27 20:17:02 -0500 | [diff] [blame] | 1538 | resource = wl_resource_create(client, |
| 1539 | &workspace_manager_interface, 1, id); |
Jonas Ådahl | e9d2250 | 2012-08-29 22:13:01 +0200 | [diff] [blame] | 1540 | |
| 1541 | if (resource == NULL) { |
| 1542 | weston_log("couldn't add workspace manager object"); |
| 1543 | return; |
| 1544 | } |
| 1545 | |
Jason Ekstrand | a85118c | 2013-06-27 20:17:02 -0500 | [diff] [blame] | 1546 | wl_resource_set_implementation(resource, |
| 1547 | &workspace_manager_implementation, |
| 1548 | shell, unbind_resource); |
Jason Ekstrand | 651f00e | 2013-06-14 10:07:54 -0500 | [diff] [blame] | 1549 | wl_list_insert(&shell->workspaces.client_list, |
| 1550 | wl_resource_get_link(resource)); |
Jonas Ådahl | e9d2250 | 2012-08-29 22:13:01 +0200 | [diff] [blame] | 1551 | |
| 1552 | workspace_manager_send_state(resource, |
| 1553 | shell->workspaces.current, |
| 1554 | shell->workspaces.num); |
Jonas Ådahl | 8de6a1d | 2012-08-29 22:13:00 +0200 | [diff] [blame] | 1555 | } |
| 1556 | |
Pekka Paalanen | 56cdea9 | 2011-11-23 16:14:12 +0200 | [diff] [blame] | 1557 | static void |
Rusty Lynch | 1084da5 | 2013-08-15 09:10:08 -0700 | [diff] [blame] | 1558 | touch_move_grab_down(struct weston_touch_grab *grab, uint32_t time, |
| 1559 | int touch_id, wl_fixed_t sx, wl_fixed_t sy) |
| 1560 | { |
| 1561 | } |
| 1562 | |
| 1563 | static void |
| 1564 | touch_move_grab_up(struct weston_touch_grab *grab, uint32_t time, int touch_id) |
| 1565 | { |
Jonas Ådahl | 1c6e63e | 2013-10-25 23:18:04 +0200 | [diff] [blame] | 1566 | struct weston_touch_move_grab *move = |
| 1567 | (struct weston_touch_move_grab *) container_of( |
| 1568 | grab, struct shell_touch_grab, grab); |
Neil Roberts | e14aa4f | 2013-10-03 16:43:07 +0100 | [diff] [blame] | 1569 | |
Kristian Høgsberg | 8e80a31 | 2014-01-17 15:18:10 -0800 | [diff] [blame] | 1570 | if (touch_id == 0) |
| 1571 | move->active = 0; |
| 1572 | |
Jonas Ådahl | 9484b69 | 2013-12-02 22:05:03 +0100 | [diff] [blame] | 1573 | if (grab->touch->num_tp == 0) { |
Jonas Ådahl | 1c6e63e | 2013-10-25 23:18:04 +0200 | [diff] [blame] | 1574 | shell_touch_grab_end(&move->base); |
| 1575 | free(move); |
| 1576 | } |
Rusty Lynch | 1084da5 | 2013-08-15 09:10:08 -0700 | [diff] [blame] | 1577 | } |
| 1578 | |
| 1579 | static void |
| 1580 | touch_move_grab_motion(struct weston_touch_grab *grab, uint32_t time, |
| 1581 | int touch_id, wl_fixed_t sx, wl_fixed_t sy) |
| 1582 | { |
| 1583 | struct weston_touch_move_grab *move = (struct weston_touch_move_grab *) grab; |
| 1584 | struct shell_surface *shsurf = move->base.shsurf; |
| 1585 | struct weston_surface *es; |
| 1586 | int dx = wl_fixed_to_int(grab->touch->grab_x + move->dx); |
| 1587 | int dy = wl_fixed_to_int(grab->touch->grab_y + move->dy); |
| 1588 | |
Kristian Høgsberg | 8e80a31 | 2014-01-17 15:18:10 -0800 | [diff] [blame] | 1589 | if (!shsurf || !move->active) |
Rusty Lynch | 1084da5 | 2013-08-15 09:10:08 -0700 | [diff] [blame] | 1590 | return; |
| 1591 | |
| 1592 | es = shsurf->surface; |
| 1593 | |
Jason Ekstrand | 918f2dd | 2013-12-02 21:01:53 -0600 | [diff] [blame] | 1594 | weston_view_set_position(shsurf->view, dx, dy); |
Rusty Lynch | 1084da5 | 2013-08-15 09:10:08 -0700 | [diff] [blame] | 1595 | |
| 1596 | weston_compositor_schedule_repaint(es->compositor); |
| 1597 | } |
| 1598 | |
Jonas Ådahl | 1ea343e | 2013-10-25 23:18:05 +0200 | [diff] [blame] | 1599 | static void |
Jonas Ådahl | 1679f23 | 2014-04-12 09:39:51 +0200 | [diff] [blame] | 1600 | touch_move_grab_frame(struct weston_touch_grab *grab) |
| 1601 | { |
| 1602 | } |
| 1603 | |
| 1604 | static void |
Jonas Ådahl | 1ea343e | 2013-10-25 23:18:05 +0200 | [diff] [blame] | 1605 | touch_move_grab_cancel(struct weston_touch_grab *grab) |
| 1606 | { |
| 1607 | struct weston_touch_move_grab *move = |
| 1608 | (struct weston_touch_move_grab *) container_of( |
| 1609 | grab, struct shell_touch_grab, grab); |
| 1610 | |
| 1611 | shell_touch_grab_end(&move->base); |
| 1612 | free(move); |
| 1613 | } |
| 1614 | |
Rusty Lynch | 1084da5 | 2013-08-15 09:10:08 -0700 | [diff] [blame] | 1615 | static const struct weston_touch_grab_interface touch_move_grab_interface = { |
| 1616 | touch_move_grab_down, |
| 1617 | touch_move_grab_up, |
| 1618 | touch_move_grab_motion, |
Jonas Ådahl | 1679f23 | 2014-04-12 09:39:51 +0200 | [diff] [blame] | 1619 | touch_move_grab_frame, |
Jonas Ådahl | 1ea343e | 2013-10-25 23:18:05 +0200 | [diff] [blame] | 1620 | touch_move_grab_cancel, |
Rusty Lynch | 1084da5 | 2013-08-15 09:10:08 -0700 | [diff] [blame] | 1621 | }; |
| 1622 | |
| 1623 | static int |
| 1624 | surface_touch_move(struct shell_surface *shsurf, struct weston_seat *seat) |
| 1625 | { |
| 1626 | struct weston_touch_move_grab *move; |
| 1627 | |
| 1628 | if (!shsurf) |
| 1629 | return -1; |
| 1630 | |
Ander Conselvan de Oliveira | 6d43f04 | 2014-05-07 14:22:23 +0300 | [diff] [blame] | 1631 | if (shsurf->state.fullscreen || shsurf->state.maximized) |
Rusty Lynch | 1084da5 | 2013-08-15 09:10:08 -0700 | [diff] [blame] | 1632 | return 0; |
| 1633 | |
| 1634 | move = malloc(sizeof *move); |
| 1635 | if (!move) |
| 1636 | return -1; |
| 1637 | |
Kristian Høgsberg | 8e80a31 | 2014-01-17 15:18:10 -0800 | [diff] [blame] | 1638 | move->active = 1; |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 1639 | move->dx = wl_fixed_from_double(shsurf->view->geometry.x) - |
Rusty Lynch | 1084da5 | 2013-08-15 09:10:08 -0700 | [diff] [blame] | 1640 | seat->touch->grab_x; |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 1641 | move->dy = wl_fixed_from_double(shsurf->view->geometry.y) - |
Rusty Lynch | 1084da5 | 2013-08-15 09:10:08 -0700 | [diff] [blame] | 1642 | seat->touch->grab_y; |
| 1643 | |
| 1644 | shell_touch_grab_start(&move->base, &touch_move_grab_interface, shsurf, |
| 1645 | seat->touch); |
| 1646 | |
| 1647 | return 0; |
| 1648 | } |
| 1649 | |
| 1650 | static void |
Kristian Høgsberg | 6848c25 | 2013-05-08 22:02:59 -0400 | [diff] [blame] | 1651 | noop_grab_focus(struct weston_pointer_grab *grab) |
Kristian Høgsberg | 9ddb826 | 2012-01-04 21:30:29 -0500 | [diff] [blame] | 1652 | { |
Kristian Høgsberg | 9ddb826 | 2012-01-04 21:30:29 -0500 | [diff] [blame] | 1653 | } |
| 1654 | |
| 1655 | static void |
Kristian Høgsberg | ae356ae | 2014-04-29 16:03:54 -0700 | [diff] [blame] | 1656 | constrain_position(struct weston_move_grab *move, int *cx, int *cy) |
| 1657 | { |
| 1658 | struct shell_surface *shsurf = move->base.shsurf; |
| 1659 | struct weston_pointer *pointer = move->base.grab.pointer; |
Jonny Lamb | d73c694 | 2014-08-20 15:53:20 +0200 | [diff] [blame] | 1660 | int x, y, panel_width, panel_height, bottom; |
Kristian Høgsberg | ae356ae | 2014-04-29 16:03:54 -0700 | [diff] [blame] | 1661 | const int safety = 50; |
| 1662 | |
| 1663 | x = wl_fixed_to_int(pointer->x + move->dx); |
| 1664 | y = wl_fixed_to_int(pointer->y + move->dy); |
| 1665 | |
Jonny Lamb | d73c694 | 2014-08-20 15:53:20 +0200 | [diff] [blame] | 1666 | if (shsurf->shell->panel_position == DESKTOP_SHELL_PANEL_POSITION_TOP) { |
| 1667 | get_output_panel_size(shsurf->shell, shsurf->surface->output, |
| 1668 | &panel_width, &panel_height); |
Kristian Høgsberg | ae356ae | 2014-04-29 16:03:54 -0700 | [diff] [blame] | 1669 | |
Jonny Lamb | d73c694 | 2014-08-20 15:53:20 +0200 | [diff] [blame] | 1670 | bottom = y + shsurf->geometry.height; |
| 1671 | if (bottom - panel_height < safety) |
| 1672 | y = panel_height + safety - |
| 1673 | shsurf->geometry.height; |
| 1674 | |
| 1675 | if (move->client_initiated && |
| 1676 | y + shsurf->geometry.y < panel_height) |
| 1677 | y = panel_height - shsurf->geometry.y; |
| 1678 | } |
Kristian Høgsberg | ae356ae | 2014-04-29 16:03:54 -0700 | [diff] [blame] | 1679 | |
| 1680 | *cx = x; |
| 1681 | *cy = y; |
| 1682 | } |
| 1683 | |
| 1684 | static void |
Giulio Camuffo | 1959ab8 | 2013-11-14 23:42:52 +0100 | [diff] [blame] | 1685 | move_grab_motion(struct weston_pointer_grab *grab, uint32_t time, |
| 1686 | wl_fixed_t x, wl_fixed_t y) |
Kristian Høgsberg | 4cca349 | 2011-01-18 07:53:49 -0500 | [diff] [blame] | 1687 | { |
Kristian Høgsberg | 8334bc1 | 2012-01-03 10:29:47 -0500 | [diff] [blame] | 1688 | struct weston_move_grab *move = (struct weston_move_grab *) grab; |
Kristian Høgsberg | 02bbabb | 2013-05-06 22:15:05 -0400 | [diff] [blame] | 1689 | struct weston_pointer *pointer = grab->pointer; |
Ander Conselvan de Oliveira | fe0444a | 2012-04-04 17:48:05 +0300 | [diff] [blame] | 1690 | struct shell_surface *shsurf = move->base.shsurf; |
Kristian Høgsberg | ae356ae | 2014-04-29 16:03:54 -0700 | [diff] [blame] | 1691 | int cx, cy; |
Giulio Camuffo | 1959ab8 | 2013-11-14 23:42:52 +0100 | [diff] [blame] | 1692 | |
| 1693 | weston_pointer_move(pointer, x, y); |
Ander Conselvan de Oliveira | fe0444a | 2012-04-04 17:48:05 +0300 | [diff] [blame] | 1694 | if (!shsurf) |
| 1695 | return; |
| 1696 | |
Kristian Høgsberg | ae356ae | 2014-04-29 16:03:54 -0700 | [diff] [blame] | 1697 | constrain_position(move, &cx, &cy); |
| 1698 | |
| 1699 | weston_view_set_position(shsurf->view, cx, cy); |
Kristian Høgsberg | 4cca349 | 2011-01-18 07:53:49 -0500 | [diff] [blame] | 1700 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 1701 | weston_compositor_schedule_repaint(shsurf->surface->compositor); |
Kristian Høgsberg | 4cca349 | 2011-01-18 07:53:49 -0500 | [diff] [blame] | 1702 | } |
| 1703 | |
| 1704 | static void |
Kristian Høgsberg | 02bbabb | 2013-05-06 22:15:05 -0400 | [diff] [blame] | 1705 | move_grab_button(struct weston_pointer_grab *grab, |
Daniel Stone | 4dbadb1 | 2012-05-30 16:31:51 +0100 | [diff] [blame] | 1706 | uint32_t time, uint32_t button, uint32_t state_w) |
Kristian Høgsberg | 4cca349 | 2011-01-18 07:53:49 -0500 | [diff] [blame] | 1707 | { |
Ander Conselvan de Oliveira | fe0444a | 2012-04-04 17:48:05 +0300 | [diff] [blame] | 1708 | struct shell_grab *shell_grab = container_of(grab, struct shell_grab, |
| 1709 | grab); |
Kristian Høgsberg | 02bbabb | 2013-05-06 22:15:05 -0400 | [diff] [blame] | 1710 | struct weston_pointer *pointer = grab->pointer; |
Daniel Stone | 4dbadb1 | 2012-05-30 16:31:51 +0100 | [diff] [blame] | 1711 | enum wl_pointer_button_state state = state_w; |
Kristian Høgsberg | 4cca349 | 2011-01-18 07:53:49 -0500 | [diff] [blame] | 1712 | |
Daniel Stone | 4dbadb1 | 2012-05-30 16:31:51 +0100 | [diff] [blame] | 1713 | if (pointer->button_count == 0 && |
| 1714 | state == WL_POINTER_BUTTON_STATE_RELEASED) { |
Ander Conselvan de Oliveira | b9d2a0f | 2012-06-28 18:08:05 +0300 | [diff] [blame] | 1715 | shell_grab_end(shell_grab); |
Kristian Høgsberg | 9ddb826 | 2012-01-04 21:30:29 -0500 | [diff] [blame] | 1716 | free(grab); |
| 1717 | } |
Kristian Høgsberg | 4cca349 | 2011-01-18 07:53:49 -0500 | [diff] [blame] | 1718 | } |
| 1719 | |
Jonas Ådahl | 1ea343e | 2013-10-25 23:18:05 +0200 | [diff] [blame] | 1720 | static void |
| 1721 | move_grab_cancel(struct weston_pointer_grab *grab) |
| 1722 | { |
| 1723 | struct shell_grab *shell_grab = |
| 1724 | container_of(grab, struct shell_grab, grab); |
| 1725 | |
| 1726 | shell_grab_end(shell_grab); |
| 1727 | free(grab); |
| 1728 | } |
| 1729 | |
Kristian Høgsberg | 02bbabb | 2013-05-06 22:15:05 -0400 | [diff] [blame] | 1730 | static const struct weston_pointer_grab_interface move_grab_interface = { |
Kristian Høgsberg | 9ddb826 | 2012-01-04 21:30:29 -0500 | [diff] [blame] | 1731 | noop_grab_focus, |
Kristian Høgsberg | 4cca349 | 2011-01-18 07:53:49 -0500 | [diff] [blame] | 1732 | move_grab_motion, |
| 1733 | move_grab_button, |
Jonas Ådahl | 1ea343e | 2013-10-25 23:18:05 +0200 | [diff] [blame] | 1734 | move_grab_cancel, |
Kristian Høgsberg | 4cca349 | 2011-01-18 07:53:49 -0500 | [diff] [blame] | 1735 | }; |
| 1736 | |
Kristian Høgsberg | 9e31bff | 2012-08-01 00:08:07 -0400 | [diff] [blame] | 1737 | static int |
Kristian Høgsberg | ae356ae | 2014-04-29 16:03:54 -0700 | [diff] [blame] | 1738 | surface_move(struct shell_surface *shsurf, struct weston_seat *seat, |
| 1739 | int client_initiated) |
Kristian Høgsberg | 9e31bff | 2012-08-01 00:08:07 -0400 | [diff] [blame] | 1740 | { |
| 1741 | struct weston_move_grab *move; |
| 1742 | |
| 1743 | if (!shsurf) |
| 1744 | return -1; |
| 1745 | |
Kristian Høgsberg | a4b620e | 2014-04-30 16:05:49 -0700 | [diff] [blame] | 1746 | if (shsurf->grabbed || |
| 1747 | shsurf->state.fullscreen || shsurf->state.maximized) |
Kristian Høgsberg | 9e31bff | 2012-08-01 00:08:07 -0400 | [diff] [blame] | 1748 | return 0; |
| 1749 | |
| 1750 | move = malloc(sizeof *move); |
| 1751 | if (!move) |
| 1752 | return -1; |
| 1753 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 1754 | move->dx = wl_fixed_from_double(shsurf->view->geometry.x) - |
Kristian Høgsberg | e314875 | 2013-05-06 23:19:49 -0400 | [diff] [blame] | 1755 | seat->pointer->grab_x; |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 1756 | move->dy = wl_fixed_from_double(shsurf->view->geometry.y) - |
Kristian Høgsberg | e314875 | 2013-05-06 23:19:49 -0400 | [diff] [blame] | 1757 | seat->pointer->grab_y; |
Kristian Høgsberg | ae356ae | 2014-04-29 16:03:54 -0700 | [diff] [blame] | 1758 | move->client_initiated = client_initiated; |
Kristian Høgsberg | 9e31bff | 2012-08-01 00:08:07 -0400 | [diff] [blame] | 1759 | |
| 1760 | shell_grab_start(&move->base, &move_grab_interface, shsurf, |
Kristian Høgsberg | e314875 | 2013-05-06 23:19:49 -0400 | [diff] [blame] | 1761 | seat->pointer, DESKTOP_SHELL_CURSOR_MOVE); |
Kristian Høgsberg | 9e31bff | 2012-08-01 00:08:07 -0400 | [diff] [blame] | 1762 | |
| 1763 | return 0; |
| 1764 | } |
| 1765 | |
| 1766 | static void |
Rafael Antognolli | e2a3455 | 2013-12-03 15:35:45 -0200 | [diff] [blame] | 1767 | common_surface_move(struct wl_resource *resource, |
| 1768 | struct wl_resource *seat_resource, uint32_t serial) |
Kristian Høgsberg | 9e31bff | 2012-08-01 00:08:07 -0400 | [diff] [blame] | 1769 | { |
Jason Ekstrand | 44a3863 | 2013-06-14 10:08:00 -0500 | [diff] [blame] | 1770 | struct weston_seat *seat = wl_resource_get_user_data(seat_resource); |
Jason Ekstrand | 651f00e | 2013-06-14 10:07:54 -0500 | [diff] [blame] | 1771 | struct shell_surface *shsurf = wl_resource_get_user_data(resource); |
Giulio Camuffo | 61da3fc | 2013-04-25 13:57:45 +0300 | [diff] [blame] | 1772 | struct weston_surface *surface; |
Kristian Høgsberg | 9e31bff | 2012-08-01 00:08:07 -0400 | [diff] [blame] | 1773 | |
Kristian Høgsberg | e1b655d | 2013-08-28 23:16:20 -0700 | [diff] [blame] | 1774 | if (seat->pointer && |
Kristian Høgsberg | 70f2901 | 2014-01-09 15:43:17 -0800 | [diff] [blame] | 1775 | seat->pointer->focus && |
Kristian Høgsberg | e1b655d | 2013-08-28 23:16:20 -0700 | [diff] [blame] | 1776 | seat->pointer->button_count > 0 && |
| 1777 | seat->pointer->grab_serial == serial) { |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 1778 | surface = weston_surface_get_main_surface(seat->pointer->focus->surface); |
U. Artie Eoff | cf5737a | 2014-01-17 10:08:25 -0800 | [diff] [blame] | 1779 | if ((surface == shsurf->surface) && |
Kristian Høgsberg | ae356ae | 2014-04-29 16:03:54 -0700 | [diff] [blame] | 1780 | (surface_move(shsurf, seat, 1) < 0)) |
Rusty Lynch | 1084da5 | 2013-08-15 09:10:08 -0700 | [diff] [blame] | 1781 | wl_resource_post_no_memory(resource); |
Kristian Høgsberg | e1b655d | 2013-08-28 23:16:20 -0700 | [diff] [blame] | 1782 | } else if (seat->touch && |
Kristian Høgsberg | 70f2901 | 2014-01-09 15:43:17 -0800 | [diff] [blame] | 1783 | seat->touch->focus && |
Kristian Høgsberg | e1b655d | 2013-08-28 23:16:20 -0700 | [diff] [blame] | 1784 | seat->touch->grab_serial == serial) { |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 1785 | surface = weston_surface_get_main_surface(seat->touch->focus->surface); |
U. Artie Eoff | cf5737a | 2014-01-17 10:08:25 -0800 | [diff] [blame] | 1786 | if ((surface == shsurf->surface) && |
Rusty Lynch | 1084da5 | 2013-08-15 09:10:08 -0700 | [diff] [blame] | 1787 | (surface_touch_move(shsurf, seat) < 0)) |
| 1788 | wl_resource_post_no_memory(resource); |
| 1789 | } |
Kristian Høgsberg | 9e31bff | 2012-08-01 00:08:07 -0400 | [diff] [blame] | 1790 | } |
| 1791 | |
Rafael Antognolli | e2a3455 | 2013-12-03 15:35:45 -0200 | [diff] [blame] | 1792 | static void |
| 1793 | shell_surface_move(struct wl_client *client, struct wl_resource *resource, |
| 1794 | struct wl_resource *seat_resource, uint32_t serial) |
| 1795 | { |
| 1796 | common_surface_move(resource, seat_resource, serial); |
| 1797 | } |
| 1798 | |
Kristian Høgsberg | 9e31bff | 2012-08-01 00:08:07 -0400 | [diff] [blame] | 1799 | struct weston_resize_grab { |
| 1800 | struct shell_grab base; |
| 1801 | uint32_t edges; |
| 1802 | int32_t width, height; |
| 1803 | }; |
| 1804 | |
| 1805 | static void |
Giulio Camuffo | 1959ab8 | 2013-11-14 23:42:52 +0100 | [diff] [blame] | 1806 | resize_grab_motion(struct weston_pointer_grab *grab, uint32_t time, |
| 1807 | wl_fixed_t x, wl_fixed_t y) |
Kristian Høgsberg | 9e31bff | 2012-08-01 00:08:07 -0400 | [diff] [blame] | 1808 | { |
| 1809 | struct weston_resize_grab *resize = (struct weston_resize_grab *) grab; |
Kristian Høgsberg | 02bbabb | 2013-05-06 22:15:05 -0400 | [diff] [blame] | 1810 | struct weston_pointer *pointer = grab->pointer; |
Kristian Høgsberg | 9e31bff | 2012-08-01 00:08:07 -0400 | [diff] [blame] | 1811 | struct shell_surface *shsurf = resize->base.shsurf; |
| 1812 | int32_t width, height; |
| 1813 | wl_fixed_t from_x, from_y; |
| 1814 | wl_fixed_t to_x, to_y; |
| 1815 | |
Giulio Camuffo | 1959ab8 | 2013-11-14 23:42:52 +0100 | [diff] [blame] | 1816 | weston_pointer_move(pointer, x, y); |
| 1817 | |
Kristian Høgsberg | e0b9d5b | 2014-04-30 13:45:49 -0700 | [diff] [blame] | 1818 | if (!shsurf) |
Kristian Høgsberg | 9e31bff | 2012-08-01 00:08:07 -0400 | [diff] [blame] | 1819 | return; |
| 1820 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 1821 | weston_view_from_global_fixed(shsurf->view, |
| 1822 | pointer->grab_x, pointer->grab_y, |
| 1823 | &from_x, &from_y); |
| 1824 | weston_view_from_global_fixed(shsurf->view, |
| 1825 | pointer->x, pointer->y, &to_x, &to_y); |
Kristian Høgsberg | 9e31bff | 2012-08-01 00:08:07 -0400 | [diff] [blame] | 1826 | |
| 1827 | width = resize->width; |
| 1828 | if (resize->edges & WL_SHELL_SURFACE_RESIZE_LEFT) { |
| 1829 | width += wl_fixed_to_int(from_x - to_x); |
| 1830 | } else if (resize->edges & WL_SHELL_SURFACE_RESIZE_RIGHT) { |
| 1831 | width += wl_fixed_to_int(to_x - from_x); |
| 1832 | } |
| 1833 | |
| 1834 | height = resize->height; |
| 1835 | if (resize->edges & WL_SHELL_SURFACE_RESIZE_TOP) { |
| 1836 | height += wl_fixed_to_int(from_y - to_y); |
| 1837 | } else if (resize->edges & WL_SHELL_SURFACE_RESIZE_BOTTOM) { |
| 1838 | height += wl_fixed_to_int(to_y - from_y); |
| 1839 | } |
| 1840 | |
Jasper St. Pierre | ac985be | 2014-04-28 11:19:28 -0400 | [diff] [blame] | 1841 | shsurf->client->send_configure(shsurf->surface, width, height); |
Kristian Høgsberg | 9e31bff | 2012-08-01 00:08:07 -0400 | [diff] [blame] | 1842 | } |
| 1843 | |
| 1844 | static void |
Jasper St. Pierre | ac985be | 2014-04-28 11:19:28 -0400 | [diff] [blame] | 1845 | 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] | 1846 | { |
| 1847 | struct shell_surface *shsurf = get_shell_surface(surface); |
| 1848 | |
U. Artie Eoff | cf5737a | 2014-01-17 10:08:25 -0800 | [diff] [blame] | 1849 | assert(shsurf); |
| 1850 | |
Kristian Høgsberg | e0b9d5b | 2014-04-30 13:45:49 -0700 | [diff] [blame] | 1851 | if (shsurf->resource) |
| 1852 | wl_shell_surface_send_configure(shsurf->resource, |
Jasper St. Pierre | ac985be | 2014-04-28 11:19:28 -0400 | [diff] [blame] | 1853 | shsurf->resize_edges, |
| 1854 | width, height); |
Kristian Høgsberg | 9e31bff | 2012-08-01 00:08:07 -0400 | [diff] [blame] | 1855 | } |
| 1856 | |
| 1857 | static const struct weston_shell_client shell_client = { |
| 1858 | send_configure |
| 1859 | }; |
| 1860 | |
| 1861 | static void |
Kristian Høgsberg | 02bbabb | 2013-05-06 22:15:05 -0400 | [diff] [blame] | 1862 | resize_grab_button(struct weston_pointer_grab *grab, |
Kristian Høgsberg | 9e31bff | 2012-08-01 00:08:07 -0400 | [diff] [blame] | 1863 | uint32_t time, uint32_t button, uint32_t state_w) |
| 1864 | { |
| 1865 | struct weston_resize_grab *resize = (struct weston_resize_grab *) grab; |
Kristian Høgsberg | 02bbabb | 2013-05-06 22:15:05 -0400 | [diff] [blame] | 1866 | struct weston_pointer *pointer = grab->pointer; |
Kristian Høgsberg | 9e31bff | 2012-08-01 00:08:07 -0400 | [diff] [blame] | 1867 | enum wl_pointer_button_state state = state_w; |
| 1868 | |
| 1869 | if (pointer->button_count == 0 && |
| 1870 | state == WL_POINTER_BUTTON_STATE_RELEASED) { |
| 1871 | shell_grab_end(&resize->base); |
| 1872 | free(grab); |
| 1873 | } |
| 1874 | } |
| 1875 | |
Jonas Ådahl | 1ea343e | 2013-10-25 23:18:05 +0200 | [diff] [blame] | 1876 | static void |
| 1877 | resize_grab_cancel(struct weston_pointer_grab *grab) |
| 1878 | { |
| 1879 | struct weston_resize_grab *resize = (struct weston_resize_grab *) grab; |
| 1880 | |
| 1881 | shell_grab_end(&resize->base); |
| 1882 | free(grab); |
| 1883 | } |
| 1884 | |
Kristian Høgsberg | 02bbabb | 2013-05-06 22:15:05 -0400 | [diff] [blame] | 1885 | static const struct weston_pointer_grab_interface resize_grab_interface = { |
Kristian Høgsberg | 9e31bff | 2012-08-01 00:08:07 -0400 | [diff] [blame] | 1886 | noop_grab_focus, |
| 1887 | resize_grab_motion, |
| 1888 | resize_grab_button, |
Jonas Ådahl | 1ea343e | 2013-10-25 23:18:05 +0200 | [diff] [blame] | 1889 | resize_grab_cancel, |
Kristian Høgsberg | 9e31bff | 2012-08-01 00:08:07 -0400 | [diff] [blame] | 1890 | }; |
| 1891 | |
Giulio Camuffo | b836664 | 2013-04-25 13:57:46 +0300 | [diff] [blame] | 1892 | /* |
| 1893 | * Returns the bounding box of a surface and all its sub-surfaces, |
| 1894 | * in the surface coordinates system. */ |
| 1895 | static void |
| 1896 | surface_subsurfaces_boundingbox(struct weston_surface *surface, int32_t *x, |
| 1897 | int32_t *y, int32_t *w, int32_t *h) { |
| 1898 | pixman_region32_t region; |
| 1899 | pixman_box32_t *box; |
| 1900 | struct weston_subsurface *subsurface; |
| 1901 | |
| 1902 | pixman_region32_init_rect(®ion, 0, 0, |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 1903 | surface->width, |
| 1904 | surface->height); |
Giulio Camuffo | b836664 | 2013-04-25 13:57:46 +0300 | [diff] [blame] | 1905 | |
| 1906 | wl_list_for_each(subsurface, &surface->subsurface_list, parent_link) { |
| 1907 | pixman_region32_union_rect(®ion, ®ion, |
| 1908 | subsurface->position.x, |
| 1909 | subsurface->position.y, |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 1910 | subsurface->surface->width, |
| 1911 | subsurface->surface->height); |
Giulio Camuffo | b836664 | 2013-04-25 13:57:46 +0300 | [diff] [blame] | 1912 | } |
| 1913 | |
| 1914 | box = pixman_region32_extents(®ion); |
| 1915 | if (x) |
| 1916 | *x = box->x1; |
| 1917 | if (y) |
| 1918 | *y = box->y1; |
| 1919 | if (w) |
| 1920 | *w = box->x2 - box->x1; |
| 1921 | if (h) |
| 1922 | *h = box->y2 - box->y1; |
| 1923 | |
| 1924 | pixman_region32_fini(®ion); |
| 1925 | } |
| 1926 | |
Kristian Høgsberg | 9e31bff | 2012-08-01 00:08:07 -0400 | [diff] [blame] | 1927 | static int |
| 1928 | surface_resize(struct shell_surface *shsurf, |
Kristian Høgsberg | e314875 | 2013-05-06 23:19:49 -0400 | [diff] [blame] | 1929 | struct weston_seat *seat, uint32_t edges) |
Kristian Høgsberg | 9e31bff | 2012-08-01 00:08:07 -0400 | [diff] [blame] | 1930 | { |
| 1931 | struct weston_resize_grab *resize; |
Ondřej Majerech | ae9c4fc | 2014-08-21 15:47:22 +0200 | [diff] [blame] | 1932 | const unsigned resize_topbottom = |
| 1933 | WL_SHELL_SURFACE_RESIZE_TOP | WL_SHELL_SURFACE_RESIZE_BOTTOM; |
| 1934 | const unsigned resize_leftright = |
| 1935 | WL_SHELL_SURFACE_RESIZE_LEFT | WL_SHELL_SURFACE_RESIZE_RIGHT; |
| 1936 | const unsigned resize_any = resize_topbottom | resize_leftright; |
Kristian Høgsberg | 9e31bff | 2012-08-01 00:08:07 -0400 | [diff] [blame] | 1937 | |
Kristian Høgsberg | a4b620e | 2014-04-30 16:05:49 -0700 | [diff] [blame] | 1938 | if (shsurf->grabbed || |
| 1939 | shsurf->state.fullscreen || shsurf->state.maximized) |
Kristian Høgsberg | 9e31bff | 2012-08-01 00:08:07 -0400 | [diff] [blame] | 1940 | return 0; |
| 1941 | |
Ondřej Majerech | ae9c4fc | 2014-08-21 15:47:22 +0200 | [diff] [blame] | 1942 | /* Check for invalid edge combinations. */ |
| 1943 | if (edges == WL_SHELL_SURFACE_RESIZE_NONE || edges > resize_any || |
| 1944 | (edges & resize_topbottom) == resize_topbottom || |
| 1945 | (edges & resize_leftright) == resize_leftright) |
Kristian Høgsberg | 9e31bff | 2012-08-01 00:08:07 -0400 | [diff] [blame] | 1946 | return 0; |
| 1947 | |
| 1948 | resize = malloc(sizeof *resize); |
| 1949 | if (!resize) |
| 1950 | return -1; |
| 1951 | |
| 1952 | resize->edges = edges; |
Kristian Høgsberg | 9e31bff | 2012-08-01 00:08:07 -0400 | [diff] [blame] | 1953 | |
Jasper St. Pierre | ccf48fb | 2014-05-02 10:21:38 -0400 | [diff] [blame] | 1954 | resize->width = shsurf->geometry.width; |
| 1955 | resize->height = shsurf->geometry.height; |
Jasper St. Pierre | bd65e50 | 2014-07-14 16:28:48 -0400 | [diff] [blame] | 1956 | |
Kristian Høgsberg | 44cd196 | 2014-02-05 21:36:04 -0800 | [diff] [blame] | 1957 | shsurf->resize_edges = edges; |
Jasper St. Pierre | 5befdda | 2014-05-06 08:50:47 -0400 | [diff] [blame] | 1958 | shell_surface_state_changed(shsurf); |
Kristian Høgsberg | 9e31bff | 2012-08-01 00:08:07 -0400 | [diff] [blame] | 1959 | shell_grab_start(&resize->base, &resize_grab_interface, shsurf, |
Kristian Høgsberg | e314875 | 2013-05-06 23:19:49 -0400 | [diff] [blame] | 1960 | seat->pointer, edges); |
Kristian Høgsberg | 9e31bff | 2012-08-01 00:08:07 -0400 | [diff] [blame] | 1961 | |
| 1962 | return 0; |
| 1963 | } |
| 1964 | |
| 1965 | static void |
Rafael Antognolli | e2a3455 | 2013-12-03 15:35:45 -0200 | [diff] [blame] | 1966 | common_surface_resize(struct wl_resource *resource, |
| 1967 | struct wl_resource *seat_resource, uint32_t serial, |
| 1968 | uint32_t edges) |
Kristian Høgsberg | 9e31bff | 2012-08-01 00:08:07 -0400 | [diff] [blame] | 1969 | { |
Jason Ekstrand | 44a3863 | 2013-06-14 10:08:00 -0500 | [diff] [blame] | 1970 | struct weston_seat *seat = wl_resource_get_user_data(seat_resource); |
Jason Ekstrand | 651f00e | 2013-06-14 10:07:54 -0500 | [diff] [blame] | 1971 | struct shell_surface *shsurf = wl_resource_get_user_data(resource); |
Giulio Camuffo | 61da3fc | 2013-04-25 13:57:45 +0300 | [diff] [blame] | 1972 | struct weston_surface *surface; |
Kristian Høgsberg | 9e31bff | 2012-08-01 00:08:07 -0400 | [diff] [blame] | 1973 | |
Emilio Pozuelo Monfort | 5872b68 | 2014-06-18 17:48:58 +0200 | [diff] [blame] | 1974 | if (seat->pointer == NULL || |
| 1975 | seat->pointer->button_count == 0 || |
Kristian Høgsberg | e314875 | 2013-05-06 23:19:49 -0400 | [diff] [blame] | 1976 | seat->pointer->grab_serial != serial || |
Kristian Høgsberg | 70f2901 | 2014-01-09 15:43:17 -0800 | [diff] [blame] | 1977 | seat->pointer->focus == NULL) |
| 1978 | return; |
| 1979 | |
| 1980 | surface = weston_surface_get_main_surface(seat->pointer->focus->surface); |
| 1981 | if (surface != shsurf->surface) |
Kristian Høgsberg | 9e31bff | 2012-08-01 00:08:07 -0400 | [diff] [blame] | 1982 | return; |
| 1983 | |
Kristian Høgsberg | e314875 | 2013-05-06 23:19:49 -0400 | [diff] [blame] | 1984 | if (surface_resize(shsurf, seat, edges) < 0) |
Kristian Høgsberg | 9e31bff | 2012-08-01 00:08:07 -0400 | [diff] [blame] | 1985 | wl_resource_post_no_memory(resource); |
| 1986 | } |
| 1987 | |
Scott Moreau | c3e54eb | 2012-04-17 19:06:20 -0600 | [diff] [blame] | 1988 | static void |
Rafael Antognolli | e2a3455 | 2013-12-03 15:35:45 -0200 | [diff] [blame] | 1989 | shell_surface_resize(struct wl_client *client, struct wl_resource *resource, |
| 1990 | struct wl_resource *seat_resource, uint32_t serial, |
| 1991 | uint32_t edges) |
| 1992 | { |
| 1993 | common_surface_resize(resource, seat_resource, serial, edges); |
| 1994 | } |
| 1995 | |
| 1996 | static void |
Kristian Høgsberg | 6848c25 | 2013-05-08 22:02:59 -0400 | [diff] [blame] | 1997 | busy_cursor_grab_focus(struct weston_pointer_grab *base) |
Scott Moreau | c3e54eb | 2012-04-17 19:06:20 -0600 | [diff] [blame] | 1998 | { |
Kristian Høgsberg | d56bd90 | 2012-06-05 09:58:51 -0400 | [diff] [blame] | 1999 | struct shell_grab *grab = (struct shell_grab *) base; |
Kristian Høgsberg | 6848c25 | 2013-05-08 22:02:59 -0400 | [diff] [blame] | 2000 | struct weston_pointer *pointer = base->pointer; |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 2001 | struct weston_view *view; |
Kristian Høgsberg | 6848c25 | 2013-05-08 22:02:59 -0400 | [diff] [blame] | 2002 | wl_fixed_t sx, sy; |
| 2003 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 2004 | view = weston_compositor_pick_view(pointer->seat->compositor, |
| 2005 | pointer->x, pointer->y, |
| 2006 | &sx, &sy); |
Scott Moreau | c3e54eb | 2012-04-17 19:06:20 -0600 | [diff] [blame] | 2007 | |
Kristian Høgsberg | 2bff94e | 2014-02-11 12:22:51 -0800 | [diff] [blame] | 2008 | if (!grab->shsurf || grab->shsurf->surface != view->surface) { |
| 2009 | shell_grab_end(grab); |
| 2010 | free(grab); |
| 2011 | } |
Scott Moreau | c3e54eb | 2012-04-17 19:06:20 -0600 | [diff] [blame] | 2012 | } |
| 2013 | |
| 2014 | static void |
Giulio Camuffo | 1959ab8 | 2013-11-14 23:42:52 +0100 | [diff] [blame] | 2015 | busy_cursor_grab_motion(struct weston_pointer_grab *grab, uint32_t time, |
| 2016 | wl_fixed_t x, wl_fixed_t y) |
Scott Moreau | c3e54eb | 2012-04-17 19:06:20 -0600 | [diff] [blame] | 2017 | { |
Giulio Camuffo | 1959ab8 | 2013-11-14 23:42:52 +0100 | [diff] [blame] | 2018 | weston_pointer_move(grab->pointer, x, y); |
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 | 02bbabb | 2013-05-06 22:15:05 -0400 | [diff] [blame] | 2022 | busy_cursor_grab_button(struct weston_pointer_grab *base, |
Kristian Høgsberg | d56bd90 | 2012-06-05 09:58:51 -0400 | [diff] [blame] | 2023 | uint32_t time, uint32_t button, uint32_t state) |
| 2024 | { |
Kristian Høgsberg | bbe9839 | 2012-08-01 00:20:21 -0400 | [diff] [blame] | 2025 | struct shell_grab *grab = (struct shell_grab *) base; |
Kristian Høgsberg | e122b7b | 2013-05-08 16:47:00 -0400 | [diff] [blame] | 2026 | struct shell_surface *shsurf = grab->shsurf; |
Kristian Høgsberg | e314875 | 2013-05-06 23:19:49 -0400 | [diff] [blame] | 2027 | struct weston_seat *seat = grab->grab.pointer->seat; |
Kristian Høgsberg | bbe9839 | 2012-08-01 00:20:21 -0400 | [diff] [blame] | 2028 | |
Kristian Høgsberg | bbe9839 | 2012-08-01 00:20:21 -0400 | [diff] [blame] | 2029 | if (shsurf && button == BTN_LEFT && state) { |
Emilio Pozuelo Monfort | 9e7c759 | 2014-01-30 14:01:10 +0100 | [diff] [blame] | 2030 | activate(shsurf->shell, shsurf->surface, seat, true); |
Kristian Høgsberg | ae356ae | 2014-04-29 16:03:54 -0700 | [diff] [blame] | 2031 | surface_move(shsurf, seat, 0); |
Kristian Høgsberg | 0c36903 | 2013-02-14 21:31:44 -0500 | [diff] [blame] | 2032 | } else if (shsurf && button == BTN_RIGHT && state) { |
Emilio Pozuelo Monfort | 9e7c759 | 2014-01-30 14:01:10 +0100 | [diff] [blame] | 2033 | activate(shsurf->shell, shsurf->surface, seat, true); |
Kristian Høgsberg | e314875 | 2013-05-06 23:19:49 -0400 | [diff] [blame] | 2034 | surface_rotate(shsurf, seat); |
Kristian Høgsberg | bbe9839 | 2012-08-01 00:20:21 -0400 | [diff] [blame] | 2035 | } |
Kristian Høgsberg | d56bd90 | 2012-06-05 09:58:51 -0400 | [diff] [blame] | 2036 | } |
| 2037 | |
Jonas Ådahl | 1ea343e | 2013-10-25 23:18:05 +0200 | [diff] [blame] | 2038 | static void |
| 2039 | busy_cursor_grab_cancel(struct weston_pointer_grab *base) |
| 2040 | { |
| 2041 | struct shell_grab *grab = (struct shell_grab *) base; |
| 2042 | |
| 2043 | shell_grab_end(grab); |
| 2044 | free(grab); |
| 2045 | } |
| 2046 | |
Kristian Høgsberg | 02bbabb | 2013-05-06 22:15:05 -0400 | [diff] [blame] | 2047 | static const struct weston_pointer_grab_interface busy_cursor_grab_interface = { |
Kristian Høgsberg | d56bd90 | 2012-06-05 09:58:51 -0400 | [diff] [blame] | 2048 | busy_cursor_grab_focus, |
| 2049 | busy_cursor_grab_motion, |
| 2050 | busy_cursor_grab_button, |
Jonas Ådahl | 1ea343e | 2013-10-25 23:18:05 +0200 | [diff] [blame] | 2051 | busy_cursor_grab_cancel, |
Kristian Høgsberg | d56bd90 | 2012-06-05 09:58:51 -0400 | [diff] [blame] | 2052 | }; |
| 2053 | |
| 2054 | static void |
Kristian Høgsberg | 02bbabb | 2013-05-06 22:15:05 -0400 | [diff] [blame] | 2055 | set_busy_cursor(struct shell_surface *shsurf, struct weston_pointer *pointer) |
Kristian Høgsberg | d56bd90 | 2012-06-05 09:58:51 -0400 | [diff] [blame] | 2056 | { |
| 2057 | struct shell_grab *grab; |
Kristian Høgsberg | d56bd90 | 2012-06-05 09:58:51 -0400 | [diff] [blame] | 2058 | |
Kristian Høgsberg | 2bff94e | 2014-02-11 12:22:51 -0800 | [diff] [blame] | 2059 | if (pointer->grab->interface == &busy_cursor_grab_interface) |
| 2060 | return; |
| 2061 | |
Kristian Høgsberg | d56bd90 | 2012-06-05 09:58:51 -0400 | [diff] [blame] | 2062 | grab = malloc(sizeof *grab); |
| 2063 | if (!grab) |
Scott Moreau | c3e54eb | 2012-04-17 19:06:20 -0600 | [diff] [blame] | 2064 | return; |
| 2065 | |
Ander Conselvan de Oliveira | b9d2a0f | 2012-06-28 18:08:05 +0300 | [diff] [blame] | 2066 | shell_grab_start(grab, &busy_cursor_grab_interface, shsurf, pointer, |
| 2067 | DESKTOP_SHELL_CURSOR_BUSY); |
Ander Conselvan de Oliveira | e5a1aee | 2014-04-09 17:39:39 +0300 | [diff] [blame] | 2068 | /* Mark the shsurf as ungrabbed so that button binding is able |
| 2069 | * to move it. */ |
| 2070 | shsurf->grabbed = 0; |
Kristian Høgsberg | d56bd90 | 2012-06-05 09:58:51 -0400 | [diff] [blame] | 2071 | } |
Scott Moreau | c3e54eb | 2012-04-17 19:06:20 -0600 | [diff] [blame] | 2072 | |
Kristian Høgsberg | d56bd90 | 2012-06-05 09:58:51 -0400 | [diff] [blame] | 2073 | static void |
Kristian Høgsberg | 2bff94e | 2014-02-11 12:22:51 -0800 | [diff] [blame] | 2074 | end_busy_cursor(struct weston_compositor *compositor, struct wl_client *client) |
Kristian Høgsberg | d56bd90 | 2012-06-05 09:58:51 -0400 | [diff] [blame] | 2075 | { |
Kristian Høgsberg | 2bff94e | 2014-02-11 12:22:51 -0800 | [diff] [blame] | 2076 | struct shell_grab *grab; |
| 2077 | struct weston_seat *seat; |
Kristian Høgsberg | d56bd90 | 2012-06-05 09:58:51 -0400 | [diff] [blame] | 2078 | |
Kristian Høgsberg | 2bff94e | 2014-02-11 12:22:51 -0800 | [diff] [blame] | 2079 | wl_list_for_each(seat, &compositor->seat_list, link) { |
| 2080 | if (seat->pointer == NULL) |
| 2081 | continue; |
| 2082 | |
| 2083 | grab = (struct shell_grab *) seat->pointer->grab; |
| 2084 | if (grab->grab.interface == &busy_cursor_grab_interface && |
| 2085 | wl_resource_get_client(grab->shsurf->resource) == client) { |
| 2086 | shell_grab_end(grab); |
| 2087 | free(grab); |
| 2088 | } |
Scott Moreau | c3e54eb | 2012-04-17 19:06:20 -0600 | [diff] [blame] | 2089 | } |
Scott Moreau | c3e54eb | 2012-04-17 19:06:20 -0600 | [diff] [blame] | 2090 | } |
| 2091 | |
Scott Moreau | 9521d5e | 2012-04-19 13:06:17 -0600 | [diff] [blame] | 2092 | static void |
Kristian Høgsberg | 2bff94e | 2014-02-11 12:22:51 -0800 | [diff] [blame] | 2093 | handle_shell_client_destroy(struct wl_listener *listener, void *data); |
| 2094 | |
| 2095 | static int |
| 2096 | xdg_ping_timeout_handler(void *data) |
| 2097 | { |
| 2098 | struct shell_client *sc = data; |
| 2099 | struct weston_seat *seat; |
| 2100 | struct shell_surface *shsurf; |
| 2101 | |
| 2102 | /* Client is not responding */ |
| 2103 | sc->unresponsive = 1; |
Kristian Høgsberg | 2bff94e | 2014-02-11 12:22:51 -0800 | [diff] [blame] | 2104 | wl_list_for_each(seat, &sc->shell->compositor->seat_list, link) { |
| 2105 | if (seat->pointer == NULL || seat->pointer->focus == NULL) |
| 2106 | continue; |
| 2107 | if (seat->pointer->focus->surface->resource == NULL) |
| 2108 | continue; |
| 2109 | |
| 2110 | shsurf = get_shell_surface(seat->pointer->focus->surface); |
| 2111 | if (shsurf && |
| 2112 | wl_resource_get_client(shsurf->resource) == sc->client) |
| 2113 | set_busy_cursor(shsurf, seat->pointer); |
| 2114 | } |
| 2115 | |
| 2116 | return 1; |
| 2117 | } |
| 2118 | |
| 2119 | static void |
| 2120 | handle_xdg_ping(struct shell_surface *shsurf, uint32_t serial) |
| 2121 | { |
| 2122 | struct weston_compositor *compositor = shsurf->shell->compositor; |
Jason Ekstrand | 9e9512f | 2014-04-16 21:12:10 -0500 | [diff] [blame] | 2123 | struct shell_client *sc = shsurf->owner; |
Kristian Høgsberg | 2bff94e | 2014-02-11 12:22:51 -0800 | [diff] [blame] | 2124 | struct wl_event_loop *loop; |
Kristian Høgsberg | dd62aba | 2014-02-12 09:56:19 -0800 | [diff] [blame] | 2125 | static const int ping_timeout = 200; |
Kristian Høgsberg | 2bff94e | 2014-02-11 12:22:51 -0800 | [diff] [blame] | 2126 | |
Kristian Høgsberg | 2bff94e | 2014-02-11 12:22:51 -0800 | [diff] [blame] | 2127 | if (sc->unresponsive) { |
| 2128 | xdg_ping_timeout_handler(sc); |
| 2129 | return; |
| 2130 | } |
| 2131 | |
| 2132 | sc->ping_serial = serial; |
| 2133 | loop = wl_display_get_event_loop(compositor->wl_display); |
| 2134 | if (sc->ping_timer == NULL) |
| 2135 | sc->ping_timer = |
| 2136 | wl_event_loop_add_timer(loop, |
| 2137 | xdg_ping_timeout_handler, sc); |
| 2138 | if (sc->ping_timer == NULL) |
| 2139 | return; |
| 2140 | |
| 2141 | wl_event_source_timer_update(sc->ping_timer, ping_timeout); |
| 2142 | |
Kristian Høgsberg | dd62aba | 2014-02-12 09:56:19 -0800 | [diff] [blame] | 2143 | if (shell_surface_is_xdg_surface(shsurf) || |
| 2144 | shell_surface_is_xdg_popup(shsurf)) |
| 2145 | xdg_shell_send_ping(sc->resource, serial); |
| 2146 | else if (shell_surface_is_wl_shell_surface(shsurf)) |
| 2147 | wl_shell_surface_send_ping(shsurf->resource, serial); |
Kristian Høgsberg | 2bff94e | 2014-02-11 12:22:51 -0800 | [diff] [blame] | 2148 | } |
| 2149 | |
Scott Moreau | ff1db4a | 2012-04-17 19:06:18 -0600 | [diff] [blame] | 2150 | static void |
| 2151 | ping_handler(struct weston_surface *surface, uint32_t serial) |
| 2152 | { |
Kristian Høgsberg | b71302e | 2012-05-10 12:28:35 -0400 | [diff] [blame] | 2153 | struct shell_surface *shsurf = get_shell_surface(surface); |
Scott Moreau | ff1db4a | 2012-04-17 19:06:18 -0600 | [diff] [blame] | 2154 | |
| 2155 | if (!shsurf) |
| 2156 | return; |
Jason Ekstrand | 651f00e | 2013-06-14 10:07:54 -0500 | [diff] [blame] | 2157 | if (!shsurf->resource) |
Kristian Høgsberg | ca535c1 | 2012-04-21 23:20:07 -0400 | [diff] [blame] | 2158 | return; |
Ander Conselvan de Oliveira | eac9a46 | 2012-07-16 14:15:48 +0300 | [diff] [blame] | 2159 | if (shsurf->surface == shsurf->shell->grab_surface) |
| 2160 | return; |
| 2161 | |
Kristian Høgsberg | dd62aba | 2014-02-12 09:56:19 -0800 | [diff] [blame] | 2162 | handle_xdg_ping(shsurf, serial); |
Scott Moreau | ff1db4a | 2012-04-17 19:06:18 -0600 | [diff] [blame] | 2163 | } |
| 2164 | |
| 2165 | static void |
Kristian Høgsberg | d56bd90 | 2012-06-05 09:58:51 -0400 | [diff] [blame] | 2166 | handle_pointer_focus(struct wl_listener *listener, void *data) |
| 2167 | { |
Kristian Høgsberg | 02bbabb | 2013-05-06 22:15:05 -0400 | [diff] [blame] | 2168 | struct weston_pointer *pointer = data; |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 2169 | struct weston_view *view = pointer->focus; |
Kristian Høgsberg | d56bd90 | 2012-06-05 09:58:51 -0400 | [diff] [blame] | 2170 | struct weston_compositor *compositor; |
Kristian Høgsberg | d56bd90 | 2012-06-05 09:58:51 -0400 | [diff] [blame] | 2171 | uint32_t serial; |
| 2172 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 2173 | if (!view) |
Kristian Høgsberg | d56bd90 | 2012-06-05 09:58:51 -0400 | [diff] [blame] | 2174 | return; |
| 2175 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 2176 | compositor = view->surface->compositor; |
Kristian Høgsberg | e11ef64 | 2014-02-11 16:35:22 -0800 | [diff] [blame] | 2177 | serial = wl_display_next_serial(compositor->wl_display); |
| 2178 | ping_handler(view->surface, serial); |
Kristian Høgsberg | d56bd90 | 2012-06-05 09:58:51 -0400 | [diff] [blame] | 2179 | } |
| 2180 | |
| 2181 | static void |
Jasper St. Pierre | faf27a9 | 2013-12-09 17:36:28 -0500 | [diff] [blame] | 2182 | shell_surface_lose_keyboard_focus(struct shell_surface *shsurf) |
| 2183 | { |
| 2184 | if (--shsurf->focus_count == 0) |
Jasper St. Pierre | 973d787 | 2014-05-06 08:44:29 -0400 | [diff] [blame] | 2185 | shell_surface_state_changed(shsurf); |
Jasper St. Pierre | faf27a9 | 2013-12-09 17:36:28 -0500 | [diff] [blame] | 2186 | } |
| 2187 | |
| 2188 | static void |
| 2189 | shell_surface_gain_keyboard_focus(struct shell_surface *shsurf) |
| 2190 | { |
| 2191 | if (shsurf->focus_count++ == 0) |
Jasper St. Pierre | 973d787 | 2014-05-06 08:44:29 -0400 | [diff] [blame] | 2192 | shell_surface_state_changed(shsurf); |
Jasper St. Pierre | faf27a9 | 2013-12-09 17:36:28 -0500 | [diff] [blame] | 2193 | } |
| 2194 | |
| 2195 | static void |
| 2196 | handle_keyboard_focus(struct wl_listener *listener, void *data) |
| 2197 | { |
| 2198 | struct weston_keyboard *keyboard = data; |
| 2199 | struct shell_seat *seat = get_shell_seat(keyboard->seat); |
| 2200 | |
| 2201 | if (seat->focused_surface) { |
| 2202 | struct shell_surface *shsurf = get_shell_surface(seat->focused_surface); |
| 2203 | if (shsurf) |
| 2204 | shell_surface_lose_keyboard_focus(shsurf); |
| 2205 | } |
| 2206 | |
| 2207 | seat->focused_surface = keyboard->focus; |
| 2208 | |
| 2209 | if (seat->focused_surface) { |
| 2210 | struct shell_surface *shsurf = get_shell_surface(seat->focused_surface); |
| 2211 | if (shsurf) |
| 2212 | shell_surface_gain_keyboard_focus(shsurf); |
| 2213 | } |
| 2214 | } |
| 2215 | |
| 2216 | static void |
Kristian Høgsberg | dd62aba | 2014-02-12 09:56:19 -0800 | [diff] [blame] | 2217 | shell_client_pong(struct shell_client *sc, uint32_t serial) |
Rafael Antognolli | e2a3455 | 2013-12-03 15:35:45 -0200 | [diff] [blame] | 2218 | { |
Kristian Høgsberg | dd62aba | 2014-02-12 09:56:19 -0800 | [diff] [blame] | 2219 | if (sc->ping_serial != serial) |
| 2220 | return; |
Rafael Antognolli | e2a3455 | 2013-12-03 15:35:45 -0200 | [diff] [blame] | 2221 | |
Kristian Høgsberg | dd62aba | 2014-02-12 09:56:19 -0800 | [diff] [blame] | 2222 | sc->unresponsive = 0; |
| 2223 | end_busy_cursor(sc->shell->compositor, sc->client); |
Rafael Antognolli | e2a3455 | 2013-12-03 15:35:45 -0200 | [diff] [blame] | 2224 | |
Kristian Høgsberg | dd62aba | 2014-02-12 09:56:19 -0800 | [diff] [blame] | 2225 | if (sc->ping_timer) { |
| 2226 | wl_event_source_remove(sc->ping_timer); |
| 2227 | sc->ping_timer = NULL; |
| 2228 | } |
| 2229 | |
| 2230 | } |
| 2231 | |
| 2232 | static void |
| 2233 | shell_surface_pong(struct wl_client *client, |
| 2234 | struct wl_resource *resource, uint32_t serial) |
| 2235 | { |
Jason Ekstrand | 9e9512f | 2014-04-16 21:12:10 -0500 | [diff] [blame] | 2236 | struct shell_surface *shsurf = wl_resource_get_user_data(resource); |
| 2237 | struct shell_client *sc = shsurf->owner; |
Kristian Høgsberg | dd62aba | 2014-02-12 09:56:19 -0800 | [diff] [blame] | 2238 | |
Kristian Høgsberg | dd62aba | 2014-02-12 09:56:19 -0800 | [diff] [blame] | 2239 | shell_client_pong(sc, serial); |
Rafael Antognolli | e2a3455 | 2013-12-03 15:35:45 -0200 | [diff] [blame] | 2240 | } |
| 2241 | |
| 2242 | static void |
Giulio Camuffo | 62942ad | 2013-09-11 18:20:47 +0200 | [diff] [blame] | 2243 | set_title(struct shell_surface *shsurf, const char *title) |
| 2244 | { |
| 2245 | free(shsurf->title); |
| 2246 | shsurf->title = strdup(title); |
Pekka Paalanen | b502654 | 2014-11-12 15:09:24 +0200 | [diff] [blame] | 2247 | shsurf->surface->timeline.force_refresh = 1; |
| 2248 | } |
| 2249 | |
| 2250 | static void |
| 2251 | set_type(struct shell_surface *shsurf, enum shell_surface_type t) |
| 2252 | { |
| 2253 | shsurf->type = t; |
| 2254 | shsurf->surface->timeline.force_refresh = 1; |
Giulio Camuffo | 62942ad | 2013-09-11 18:20:47 +0200 | [diff] [blame] | 2255 | } |
| 2256 | |
| 2257 | static void |
Jasper St. Pierre | ccf48fb | 2014-05-02 10:21:38 -0400 | [diff] [blame] | 2258 | set_window_geometry(struct shell_surface *shsurf, |
| 2259 | 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] | 2260 | { |
Jasper St. Pierre | ccf48fb | 2014-05-02 10:21:38 -0400 | [diff] [blame] | 2261 | shsurf->next_geometry.x = x; |
| 2262 | shsurf->next_geometry.y = y; |
| 2263 | shsurf->next_geometry.width = width; |
| 2264 | shsurf->next_geometry.height = height; |
| 2265 | shsurf->has_next_geometry = true; |
Kristian Høgsberg | e5c1ae9 | 2014-04-30 16:28:41 -0700 | [diff] [blame] | 2266 | } |
| 2267 | |
| 2268 | static void |
Kristian Høgsberg | e7afd91 | 2012-05-02 09:47:44 -0400 | [diff] [blame] | 2269 | shell_surface_set_title(struct wl_client *client, |
| 2270 | struct wl_resource *resource, const char *title) |
| 2271 | { |
Jason Ekstrand | 651f00e | 2013-06-14 10:07:54 -0500 | [diff] [blame] | 2272 | struct shell_surface *shsurf = wl_resource_get_user_data(resource); |
Kristian Høgsberg | e7afd91 | 2012-05-02 09:47:44 -0400 | [diff] [blame] | 2273 | |
Giulio Camuffo | 62942ad | 2013-09-11 18:20:47 +0200 | [diff] [blame] | 2274 | set_title(shsurf, title); |
Kristian Høgsberg | e7afd91 | 2012-05-02 09:47:44 -0400 | [diff] [blame] | 2275 | } |
| 2276 | |
| 2277 | static void |
| 2278 | shell_surface_set_class(struct wl_client *client, |
| 2279 | struct wl_resource *resource, const char *class) |
| 2280 | { |
Jason Ekstrand | 651f00e | 2013-06-14 10:07:54 -0500 | [diff] [blame] | 2281 | struct shell_surface *shsurf = wl_resource_get_user_data(resource); |
Kristian Høgsberg | e7afd91 | 2012-05-02 09:47:44 -0400 | [diff] [blame] | 2282 | |
| 2283 | free(shsurf->class); |
| 2284 | shsurf->class = strdup(class); |
Pekka Paalanen | b502654 | 2014-11-12 15:09:24 +0200 | [diff] [blame] | 2285 | shsurf->surface->timeline.force_refresh = 1; |
Kristian Høgsberg | e7afd91 | 2012-05-02 09:47:44 -0400 | [diff] [blame] | 2286 | } |
| 2287 | |
Alex Wu | 4539b08 | 2012-03-01 12:57:46 +0800 | [diff] [blame] | 2288 | static void |
Alexander Larsson | f82b6ca | 2013-05-28 16:23:39 +0200 | [diff] [blame] | 2289 | restore_output_mode(struct weston_output *output) |
| 2290 | { |
Derek Foreman | 6ae7bc9 | 2014-11-04 10:47:33 -0600 | [diff] [blame] | 2291 | if (output->original_mode) |
| 2292 | weston_output_mode_switch_to_native(output); |
Alexander Larsson | f82b6ca | 2013-05-28 16:23:39 +0200 | [diff] [blame] | 2293 | } |
| 2294 | |
| 2295 | static void |
| 2296 | restore_all_output_modes(struct weston_compositor *compositor) |
| 2297 | { |
| 2298 | struct weston_output *output; |
| 2299 | |
| 2300 | wl_list_for_each(output, &compositor->output_list, link) |
| 2301 | restore_output_mode(output); |
| 2302 | } |
| 2303 | |
Philip Withnall | 07926d9 | 2013-11-25 18:01:40 +0000 | [diff] [blame] | 2304 | /* The surface will be inserted into the list immediately after the link |
| 2305 | * returned by this function (i.e. will be stacked immediately above the |
| 2306 | * returned link). */ |
Giulio Camuffo | 412e6a5 | 2014-07-09 22:12:56 +0300 | [diff] [blame] | 2307 | static struct weston_layer_entry * |
Philip Withnall | 07926d9 | 2013-11-25 18:01:40 +0000 | [diff] [blame] | 2308 | shell_surface_calculate_layer_link (struct shell_surface *shsurf) |
| 2309 | { |
| 2310 | struct workspace *ws; |
Kristian Høgsberg | ead5242 | 2014-01-01 13:51:52 -0800 | [diff] [blame] | 2311 | struct weston_view *parent; |
Philip Withnall | 07926d9 | 2013-11-25 18:01:40 +0000 | [diff] [blame] | 2312 | |
| 2313 | switch (shsurf->type) { |
Ander Conselvan de Oliveira | ef6a7e4 | 2014-04-30 14:15:14 +0300 | [diff] [blame] | 2314 | case SHELL_SURFACE_XWAYLAND: |
| 2315 | return &shsurf->shell->fullscreen_layer.view_list; |
| 2316 | |
| 2317 | case SHELL_SURFACE_NONE: |
| 2318 | return NULL; |
| 2319 | |
Kristian Høgsberg | ead5242 | 2014-01-01 13:51:52 -0800 | [diff] [blame] | 2320 | case SHELL_SURFACE_POPUP: |
| 2321 | case SHELL_SURFACE_TOPLEVEL: |
Emilio Pozuelo Monfort | 9e7c759 | 2014-01-30 14:01:10 +0100 | [diff] [blame] | 2322 | if (shsurf->state.fullscreen && !shsurf->state.lowered) { |
Rafael Antognolli | 03b1659 | 2013-12-03 15:35:42 -0200 | [diff] [blame] | 2323 | return &shsurf->shell->fullscreen_layer.view_list; |
Rafael Antognolli | ed207b4 | 2013-12-03 15:35:43 -0200 | [diff] [blame] | 2324 | } else if (shsurf->parent) { |
Kristian Høgsberg | d55db69 | 2014-01-01 12:26:14 -0800 | [diff] [blame] | 2325 | /* Move the surface to its parent layer so |
| 2326 | * that surfaces which are transient for |
| 2327 | * fullscreen surfaces don't get hidden by the |
| 2328 | * fullscreen surfaces. */ |
Rafael Antognolli | ed207b4 | 2013-12-03 15:35:43 -0200 | [diff] [blame] | 2329 | |
| 2330 | /* TODO: Handle a parent with multiple views */ |
| 2331 | parent = get_default_view(shsurf->parent); |
| 2332 | if (parent) |
Giulio Camuffo | 412e6a5 | 2014-07-09 22:12:56 +0300 | [diff] [blame] | 2333 | return container_of(parent->layer_link.link.prev, |
| 2334 | struct weston_layer_entry, link); |
Rafael Antognolli | ed207b4 | 2013-12-03 15:35:43 -0200 | [diff] [blame] | 2335 | } |
Philip Withnall | 07926d9 | 2013-11-25 18:01:40 +0000 | [diff] [blame] | 2336 | |
Ander Conselvan de Oliveira | ef6a7e4 | 2014-04-30 14:15:14 +0300 | [diff] [blame] | 2337 | /* Move the surface to a normal workspace layer so that surfaces |
| 2338 | * which were previously fullscreen or transient are no longer |
| 2339 | * rendered on top. */ |
| 2340 | ws = get_current_workspace(shsurf->shell); |
| 2341 | return &ws->layer.view_list; |
Philip Withnall | 07926d9 | 2013-11-25 18:01:40 +0000 | [diff] [blame] | 2342 | } |
| 2343 | |
Ander Conselvan de Oliveira | ef6a7e4 | 2014-04-30 14:15:14 +0300 | [diff] [blame] | 2344 | assert(0 && "Unknown shell surface type"); |
Philip Withnall | 07926d9 | 2013-11-25 18:01:40 +0000 | [diff] [blame] | 2345 | } |
| 2346 | |
Philip Withnall | 648a4dd | 2013-11-25 18:01:44 +0000 | [diff] [blame] | 2347 | static void |
| 2348 | shell_surface_update_child_surface_layers (struct shell_surface *shsurf) |
| 2349 | { |
| 2350 | struct shell_surface *child; |
Giulio Camuffo | 412e6a5 | 2014-07-09 22:12:56 +0300 | [diff] [blame] | 2351 | struct weston_layer_entry *prev; |
Philip Withnall | 648a4dd | 2013-11-25 18:01:44 +0000 | [diff] [blame] | 2352 | |
| 2353 | /* Move the child layers to the same workspace as shsurf. They will be |
| 2354 | * stacked above shsurf. */ |
| 2355 | wl_list_for_each_reverse(child, &shsurf->children_list, children_link) { |
Giulio Camuffo | 412e6a5 | 2014-07-09 22:12:56 +0300 | [diff] [blame] | 2356 | 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] | 2357 | weston_view_damage_below(child->view); |
Philip Withnall | 648a4dd | 2013-11-25 18:01:44 +0000 | [diff] [blame] | 2358 | weston_view_geometry_dirty(child->view); |
Giulio Camuffo | 412e6a5 | 2014-07-09 22:12:56 +0300 | [diff] [blame] | 2359 | prev = container_of(shsurf->view->layer_link.link.prev, |
| 2360 | struct weston_layer_entry, link); |
| 2361 | weston_layer_entry_remove(&child->view->layer_link); |
| 2362 | weston_layer_entry_insert(prev, |
| 2363 | &child->view->layer_link); |
Philip Withnall | 648a4dd | 2013-11-25 18:01:44 +0000 | [diff] [blame] | 2364 | weston_view_geometry_dirty(child->view); |
| 2365 | weston_surface_damage(child->surface); |
| 2366 | |
| 2367 | /* Recurse. We don’t expect this to recurse very far (if |
| 2368 | * at all) because that would imply we have transient |
| 2369 | * (or popup) children of transient surfaces, which |
| 2370 | * would be unusual. */ |
| 2371 | shell_surface_update_child_surface_layers(child); |
| 2372 | } |
| 2373 | } |
| 2374 | } |
| 2375 | |
Philip Withnall | e1d75ae | 2013-11-25 18:01:41 +0000 | [diff] [blame] | 2376 | /* 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] | 2377 | * geometry to ensure the changes are redrawn. |
| 2378 | * |
| 2379 | * If any child surfaces exist and are mapped, ensure they’re in the same layer |
| 2380 | * as this surface. */ |
Philip Withnall | e1d75ae | 2013-11-25 18:01:41 +0000 | [diff] [blame] | 2381 | static void |
| 2382 | shell_surface_update_layer(struct shell_surface *shsurf) |
| 2383 | { |
Giulio Camuffo | 412e6a5 | 2014-07-09 22:12:56 +0300 | [diff] [blame] | 2384 | struct weston_layer_entry *new_layer_link; |
Philip Withnall | e1d75ae | 2013-11-25 18:01:41 +0000 | [diff] [blame] | 2385 | |
| 2386 | new_layer_link = shell_surface_calculate_layer_link(shsurf); |
| 2387 | |
Ander Conselvan de Oliveira | ef6a7e4 | 2014-04-30 14:15:14 +0300 | [diff] [blame] | 2388 | if (new_layer_link == NULL) |
| 2389 | return; |
Philip Withnall | e1d75ae | 2013-11-25 18:01:41 +0000 | [diff] [blame] | 2390 | if (new_layer_link == &shsurf->view->layer_link) |
| 2391 | return; |
| 2392 | |
| 2393 | weston_view_geometry_dirty(shsurf->view); |
Giulio Camuffo | 412e6a5 | 2014-07-09 22:12:56 +0300 | [diff] [blame] | 2394 | weston_layer_entry_remove(&shsurf->view->layer_link); |
| 2395 | weston_layer_entry_insert(new_layer_link, &shsurf->view->layer_link); |
Philip Withnall | e1d75ae | 2013-11-25 18:01:41 +0000 | [diff] [blame] | 2396 | weston_view_geometry_dirty(shsurf->view); |
| 2397 | weston_surface_damage(shsurf->surface); |
Philip Withnall | 648a4dd | 2013-11-25 18:01:44 +0000 | [diff] [blame] | 2398 | |
| 2399 | shell_surface_update_child_surface_layers(shsurf); |
Philip Withnall | e1d75ae | 2013-11-25 18:01:41 +0000 | [diff] [blame] | 2400 | } |
| 2401 | |
Alexander Larsson | f82b6ca | 2013-05-28 16:23:39 +0200 | [diff] [blame] | 2402 | static void |
Philip Withnall | dc4332f | 2013-11-25 18:01:38 +0000 | [diff] [blame] | 2403 | shell_surface_set_parent(struct shell_surface *shsurf, |
| 2404 | struct weston_surface *parent) |
| 2405 | { |
| 2406 | shsurf->parent = parent; |
Philip Withnall | 648a4dd | 2013-11-25 18:01:44 +0000 | [diff] [blame] | 2407 | |
| 2408 | wl_list_remove(&shsurf->children_link); |
| 2409 | wl_list_init(&shsurf->children_link); |
| 2410 | |
| 2411 | /* Insert into the parent surface’s child list. */ |
| 2412 | if (parent != NULL) { |
| 2413 | struct shell_surface *parent_shsurf = get_shell_surface(parent); |
| 2414 | if (parent_shsurf != NULL) |
| 2415 | wl_list_insert(&parent_shsurf->children_list, |
| 2416 | &shsurf->children_link); |
| 2417 | } |
Philip Withnall | dc4332f | 2013-11-25 18:01:38 +0000 | [diff] [blame] | 2418 | } |
| 2419 | |
| 2420 | static void |
Philip Withnall | 352e7ed | 2013-11-25 18:01:35 +0000 | [diff] [blame] | 2421 | shell_surface_set_output(struct shell_surface *shsurf, |
| 2422 | struct weston_output *output) |
| 2423 | { |
| 2424 | struct weston_surface *es = shsurf->surface; |
| 2425 | |
| 2426 | /* get the default output, if the client set it as NULL |
| 2427 | check whether the ouput is available */ |
| 2428 | if (output) |
| 2429 | shsurf->output = output; |
| 2430 | else if (es->output) |
| 2431 | shsurf->output = es->output; |
| 2432 | else |
| 2433 | shsurf->output = get_default_output(es->compositor); |
| 2434 | } |
| 2435 | |
| 2436 | static void |
Rafael Antognolli | 03b1659 | 2013-12-03 15:35:42 -0200 | [diff] [blame] | 2437 | surface_clear_next_states(struct shell_surface *shsurf) |
| 2438 | { |
| 2439 | shsurf->next_state.maximized = false; |
| 2440 | shsurf->next_state.fullscreen = false; |
| 2441 | |
| 2442 | if ((shsurf->next_state.maximized != shsurf->state.maximized) || |
| 2443 | (shsurf->next_state.fullscreen != shsurf->state.fullscreen)) |
| 2444 | shsurf->state_changed = true; |
| 2445 | } |
| 2446 | |
| 2447 | static void |
Philip Withnall | becb77e | 2013-11-25 18:01:30 +0000 | [diff] [blame] | 2448 | set_toplevel(struct shell_surface *shsurf) |
| 2449 | { |
Kristian Høgsberg | 41fbf6f | 2013-12-05 22:31:25 -0800 | [diff] [blame] | 2450 | shell_surface_set_parent(shsurf, NULL); |
| 2451 | surface_clear_next_states(shsurf); |
Pekka Paalanen | b502654 | 2014-11-12 15:09:24 +0200 | [diff] [blame] | 2452 | set_type(shsurf, SHELL_SURFACE_TOPLEVEL); |
Philip Withnall | 648a4dd | 2013-11-25 18:01:44 +0000 | [diff] [blame] | 2453 | |
| 2454 | /* The layer_link is updated in set_surface_type(), |
| 2455 | * called from configure. */ |
Philip Withnall | becb77e | 2013-11-25 18:01:30 +0000 | [diff] [blame] | 2456 | } |
| 2457 | |
| 2458 | static void |
| 2459 | shell_surface_set_toplevel(struct wl_client *client, |
| 2460 | struct wl_resource *resource) |
| 2461 | { |
| 2462 | struct shell_surface *surface = wl_resource_get_user_data(resource); |
| 2463 | |
| 2464 | set_toplevel(surface); |
| 2465 | } |
| 2466 | |
| 2467 | static void |
| 2468 | set_transient(struct shell_surface *shsurf, |
| 2469 | struct weston_surface *parent, int x, int y, uint32_t flags) |
| 2470 | { |
Philip Withnall | dc4332f | 2013-11-25 18:01:38 +0000 | [diff] [blame] | 2471 | assert(parent != NULL); |
| 2472 | |
Kristian Høgsberg | 9f7e331 | 2014-01-02 22:40:37 -0800 | [diff] [blame] | 2473 | shell_surface_set_parent(shsurf, parent); |
| 2474 | |
| 2475 | surface_clear_next_states(shsurf); |
| 2476 | |
Philip Withnall | becb77e | 2013-11-25 18:01:30 +0000 | [diff] [blame] | 2477 | shsurf->transient.x = x; |
| 2478 | shsurf->transient.y = y; |
| 2479 | shsurf->transient.flags = flags; |
Philip Withnall | dc4332f | 2013-11-25 18:01:38 +0000 | [diff] [blame] | 2480 | |
Rafael Antognolli | ed207b4 | 2013-12-03 15:35:43 -0200 | [diff] [blame] | 2481 | shsurf->next_state.relative = true; |
Kristian Høgsberg | a1df7ac | 2013-12-31 15:01:01 -0800 | [diff] [blame] | 2482 | shsurf->state_changed = true; |
Pekka Paalanen | b502654 | 2014-11-12 15:09:24 +0200 | [diff] [blame] | 2483 | set_type(shsurf, SHELL_SURFACE_TOPLEVEL); |
Philip Withnall | 648a4dd | 2013-11-25 18:01:44 +0000 | [diff] [blame] | 2484 | |
| 2485 | /* The layer_link is updated in set_surface_type(), |
| 2486 | * called from configure. */ |
Philip Withnall | becb77e | 2013-11-25 18:01:30 +0000 | [diff] [blame] | 2487 | } |
| 2488 | |
| 2489 | static void |
| 2490 | shell_surface_set_transient(struct wl_client *client, |
| 2491 | struct wl_resource *resource, |
| 2492 | struct wl_resource *parent_resource, |
| 2493 | int x, int y, uint32_t flags) |
| 2494 | { |
| 2495 | struct shell_surface *shsurf = wl_resource_get_user_data(resource); |
| 2496 | struct weston_surface *parent = |
| 2497 | wl_resource_get_user_data(parent_resource); |
| 2498 | |
| 2499 | set_transient(shsurf, parent, x, y, flags); |
| 2500 | } |
| 2501 | |
| 2502 | static void |
| 2503 | set_fullscreen(struct shell_surface *shsurf, |
| 2504 | uint32_t method, |
| 2505 | uint32_t framerate, |
| 2506 | struct weston_output *output) |
| 2507 | { |
Philip Withnall | 352e7ed | 2013-11-25 18:01:35 +0000 | [diff] [blame] | 2508 | shell_surface_set_output(shsurf, output); |
Pekka Paalanen | b502654 | 2014-11-12 15:09:24 +0200 | [diff] [blame] | 2509 | set_type(shsurf, SHELL_SURFACE_TOPLEVEL); |
Philip Withnall | becb77e | 2013-11-25 18:01:30 +0000 | [diff] [blame] | 2510 | |
| 2511 | shsurf->fullscreen_output = shsurf->output; |
| 2512 | shsurf->fullscreen.type = method; |
| 2513 | shsurf->fullscreen.framerate = framerate; |
Philip Withnall | dc4332f | 2013-11-25 18:01:38 +0000 | [diff] [blame] | 2514 | |
Jasper St. Pierre | 6458ec3 | 2014-04-11 16:00:31 -0700 | [diff] [blame] | 2515 | send_configure_for_surface(shsurf); |
Philip Withnall | becb77e | 2013-11-25 18:01:30 +0000 | [diff] [blame] | 2516 | } |
| 2517 | |
| 2518 | static void |
Zhang, Xiong Y | 3123693 | 2013-12-13 22:10:57 +0200 | [diff] [blame] | 2519 | weston_view_set_initial_position(struct weston_view *view, |
| 2520 | struct desktop_shell *shell); |
| 2521 | |
| 2522 | static void |
Philip Withnall | becb77e | 2013-11-25 18:01:30 +0000 | [diff] [blame] | 2523 | unset_fullscreen(struct shell_surface *shsurf) |
Alex Wu | 4539b08 | 2012-03-01 12:57:46 +0800 | [diff] [blame] | 2524 | { |
Philip Withnall | f85fe84 | 2013-11-25 18:01:37 +0000 | [diff] [blame] | 2525 | /* Unset the fullscreen output, driver configuration and transforms. */ |
Alex Wu | bd3354b | 2012-04-17 17:20:49 +0800 | [diff] [blame] | 2526 | if (shsurf->fullscreen.type == WL_SHELL_SURFACE_FULLSCREEN_METHOD_DRIVER && |
| 2527 | shell_surface_is_top_fullscreen(shsurf)) { |
Alexander Larsson | f82b6ca | 2013-05-28 16:23:39 +0200 | [diff] [blame] | 2528 | restore_output_mode(shsurf->fullscreen_output); |
Alex Wu | bd3354b | 2012-04-17 17:20:49 +0800 | [diff] [blame] | 2529 | } |
Philip Withnall | f85fe84 | 2013-11-25 18:01:37 +0000 | [diff] [blame] | 2530 | |
Alex Wu | 4539b08 | 2012-03-01 12:57:46 +0800 | [diff] [blame] | 2531 | shsurf->fullscreen.type = WL_SHELL_SURFACE_FULLSCREEN_METHOD_DEFAULT; |
| 2532 | shsurf->fullscreen.framerate = 0; |
Philip Withnall | f85fe84 | 2013-11-25 18:01:37 +0000 | [diff] [blame] | 2533 | |
Alex Wu | 4539b08 | 2012-03-01 12:57:46 +0800 | [diff] [blame] | 2534 | wl_list_remove(&shsurf->fullscreen.transform.link); |
| 2535 | wl_list_init(&shsurf->fullscreen.transform.link); |
Philip Withnall | f85fe84 | 2013-11-25 18:01:37 +0000 | [diff] [blame] | 2536 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 2537 | if (shsurf->fullscreen.black_view) |
| 2538 | weston_surface_destroy(shsurf->fullscreen.black_view->surface); |
| 2539 | shsurf->fullscreen.black_view = NULL; |
Philip Withnall | f85fe84 | 2013-11-25 18:01:37 +0000 | [diff] [blame] | 2540 | |
Zhang, Xiong Y | 3123693 | 2013-12-13 22:10:57 +0200 | [diff] [blame] | 2541 | if (shsurf->saved_position_valid) |
| 2542 | weston_view_set_position(shsurf->view, |
| 2543 | shsurf->saved_x, shsurf->saved_y); |
| 2544 | else |
| 2545 | weston_view_set_initial_position(shsurf->view, shsurf->shell); |
| 2546 | |
Alex Wu | 7bcb8bd | 2012-04-27 09:07:24 +0800 | [diff] [blame] | 2547 | if (shsurf->saved_rotation_valid) { |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 2548 | wl_list_insert(&shsurf->view->geometry.transformation_list, |
Philip Withnall | becb77e | 2013-11-25 18:01:30 +0000 | [diff] [blame] | 2549 | &shsurf->rotation.transform.link); |
Alex Wu | 7bcb8bd | 2012-04-27 09:07:24 +0800 | [diff] [blame] | 2550 | shsurf->saved_rotation_valid = false; |
| 2551 | } |
Rafal Mielniczuk | 3e3862c | 2012-10-07 20:25:36 +0200 | [diff] [blame] | 2552 | |
Philip Withnall | e1d75ae | 2013-11-25 18:01:41 +0000 | [diff] [blame] | 2553 | /* Layer is updated in set_surface_type(). */ |
Alex Wu | 4539b08 | 2012-03-01 12:57:46 +0800 | [diff] [blame] | 2554 | } |
| 2555 | |
Rafal Mielniczuk | fffdcdd | 2013-03-11 19:26:54 +0100 | [diff] [blame] | 2556 | static void |
Philip Withnall | becb77e | 2013-11-25 18:01:30 +0000 | [diff] [blame] | 2557 | shell_surface_set_fullscreen(struct wl_client *client, |
| 2558 | struct wl_resource *resource, |
| 2559 | uint32_t method, |
| 2560 | uint32_t framerate, |
| 2561 | struct wl_resource *output_resource) |
| 2562 | { |
| 2563 | struct shell_surface *shsurf = wl_resource_get_user_data(resource); |
| 2564 | struct weston_output *output; |
| 2565 | |
| 2566 | if (output_resource) |
| 2567 | output = wl_resource_get_user_data(output_resource); |
| 2568 | else |
| 2569 | output = NULL; |
| 2570 | |
Rafael Antognolli | 4b99a40 | 2013-12-03 15:35:44 -0200 | [diff] [blame] | 2571 | shell_surface_set_parent(shsurf, NULL); |
| 2572 | |
Rafael Antognolli | 03b1659 | 2013-12-03 15:35:42 -0200 | [diff] [blame] | 2573 | surface_clear_next_states(shsurf); |
Jasper St. Pierre | 8c6aa45 | 2014-02-08 18:29:49 -0500 | [diff] [blame] | 2574 | shsurf->next_state.fullscreen = true; |
| 2575 | shsurf->state_changed = true; |
Jasper St. Pierre | 6458ec3 | 2014-04-11 16:00:31 -0700 | [diff] [blame] | 2576 | set_fullscreen(shsurf, method, framerate, output); |
Philip Withnall | becb77e | 2013-11-25 18:01:30 +0000 | [diff] [blame] | 2577 | } |
| 2578 | |
| 2579 | static void |
| 2580 | set_popup(struct shell_surface *shsurf, |
| 2581 | struct weston_surface *parent, |
| 2582 | struct weston_seat *seat, |
| 2583 | uint32_t serial, |
| 2584 | int32_t x, |
| 2585 | int32_t y) |
| 2586 | { |
Philip Withnall | dc4332f | 2013-11-25 18:01:38 +0000 | [diff] [blame] | 2587 | assert(parent != NULL); |
| 2588 | |
Philip Withnall | becb77e | 2013-11-25 18:01:30 +0000 | [diff] [blame] | 2589 | shsurf->popup.shseat = get_shell_seat(seat); |
| 2590 | shsurf->popup.serial = serial; |
| 2591 | shsurf->popup.x = x; |
| 2592 | shsurf->popup.y = y; |
Philip Withnall | dc4332f | 2013-11-25 18:01:38 +0000 | [diff] [blame] | 2593 | |
Pekka Paalanen | b502654 | 2014-11-12 15:09:24 +0200 | [diff] [blame] | 2594 | set_type(shsurf, SHELL_SURFACE_POPUP); |
Philip Withnall | becb77e | 2013-11-25 18:01:30 +0000 | [diff] [blame] | 2595 | } |
| 2596 | |
| 2597 | static void |
| 2598 | shell_surface_set_popup(struct wl_client *client, |
| 2599 | struct wl_resource *resource, |
| 2600 | struct wl_resource *seat_resource, |
| 2601 | uint32_t serial, |
| 2602 | struct wl_resource *parent_resource, |
| 2603 | int32_t x, int32_t y, uint32_t flags) |
| 2604 | { |
| 2605 | struct shell_surface *shsurf = wl_resource_get_user_data(resource); |
Rafael Antognolli | 4b99a40 | 2013-12-03 15:35:44 -0200 | [diff] [blame] | 2606 | struct weston_surface *parent = |
| 2607 | wl_resource_get_user_data(parent_resource); |
| 2608 | |
| 2609 | shell_surface_set_parent(shsurf, parent); |
Philip Withnall | becb77e | 2013-11-25 18:01:30 +0000 | [diff] [blame] | 2610 | |
Rafael Antognolli | 03b1659 | 2013-12-03 15:35:42 -0200 | [diff] [blame] | 2611 | surface_clear_next_states(shsurf); |
Philip Withnall | becb77e | 2013-11-25 18:01:30 +0000 | [diff] [blame] | 2612 | set_popup(shsurf, |
Rafael Antognolli | 4b99a40 | 2013-12-03 15:35:44 -0200 | [diff] [blame] | 2613 | parent, |
Philip Withnall | becb77e | 2013-11-25 18:01:30 +0000 | [diff] [blame] | 2614 | wl_resource_get_user_data(seat_resource), |
| 2615 | serial, x, y); |
| 2616 | } |
| 2617 | |
| 2618 | static void |
Philip Withnall | becb77e | 2013-11-25 18:01:30 +0000 | [diff] [blame] | 2619 | unset_maximized(struct shell_surface *shsurf) |
Rafal Mielniczuk | fffdcdd | 2013-03-11 19:26:54 +0100 | [diff] [blame] | 2620 | { |
Rafal Mielniczuk | fffdcdd | 2013-03-11 19:26:54 +0100 | [diff] [blame] | 2621 | /* undo all maximized things here */ |
| 2622 | shsurf->output = get_default_output(shsurf->surface->compositor); |
Zhang, Xiong Y | 3123693 | 2013-12-13 22:10:57 +0200 | [diff] [blame] | 2623 | |
| 2624 | if (shsurf->saved_position_valid) |
| 2625 | weston_view_set_position(shsurf->view, |
| 2626 | shsurf->saved_x, shsurf->saved_y); |
| 2627 | else |
| 2628 | weston_view_set_initial_position(shsurf->view, shsurf->shell); |
Rafal Mielniczuk | fffdcdd | 2013-03-11 19:26:54 +0100 | [diff] [blame] | 2629 | |
| 2630 | if (shsurf->saved_rotation_valid) { |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 2631 | wl_list_insert(&shsurf->view->geometry.transformation_list, |
| 2632 | &shsurf->rotation.transform.link); |
Rafal Mielniczuk | fffdcdd | 2013-03-11 19:26:54 +0100 | [diff] [blame] | 2633 | shsurf->saved_rotation_valid = false; |
| 2634 | } |
| 2635 | |
Philip Withnall | e1d75ae | 2013-11-25 18:01:41 +0000 | [diff] [blame] | 2636 | /* Layer is updated in set_surface_type(). */ |
Rafal Mielniczuk | fffdcdd | 2013-03-11 19:26:54 +0100 | [diff] [blame] | 2637 | } |
| 2638 | |
Philip Withnall | becb77e | 2013-11-25 18:01:30 +0000 | [diff] [blame] | 2639 | static void |
Manuel Bachmann | 50c87db | 2014-02-26 15:52:13 +0100 | [diff] [blame] | 2640 | set_minimized(struct weston_surface *surface, uint32_t is_true) |
| 2641 | { |
| 2642 | struct shell_surface *shsurf; |
| 2643 | struct workspace *current_ws; |
| 2644 | struct weston_seat *seat; |
| 2645 | struct weston_surface *focus; |
| 2646 | struct weston_view *view; |
| 2647 | |
| 2648 | view = get_default_view(surface); |
| 2649 | if (!view) |
| 2650 | return; |
| 2651 | |
| 2652 | assert(weston_surface_get_main_surface(view->surface) == view->surface); |
| 2653 | |
| 2654 | shsurf = get_shell_surface(surface); |
| 2655 | current_ws = get_current_workspace(shsurf->shell); |
| 2656 | |
Giulio Camuffo | 412e6a5 | 2014-07-09 22:12:56 +0300 | [diff] [blame] | 2657 | weston_layer_entry_remove(&view->layer_link); |
Manuel Bachmann | 50c87db | 2014-02-26 15:52:13 +0100 | [diff] [blame] | 2658 | /* hide or show, depending on the state */ |
| 2659 | if (is_true) { |
Giulio Camuffo | 412e6a5 | 2014-07-09 22:12:56 +0300 | [diff] [blame] | 2660 | 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] | 2661 | |
| 2662 | drop_focus_state(shsurf->shell, current_ws, view->surface); |
| 2663 | wl_list_for_each(seat, &shsurf->shell->compositor->seat_list, link) { |
| 2664 | if (!seat->keyboard) |
| 2665 | continue; |
| 2666 | focus = weston_surface_get_main_surface(seat->keyboard->focus); |
| 2667 | if (focus == view->surface) |
| 2668 | weston_keyboard_set_focus(seat->keyboard, NULL); |
| 2669 | } |
| 2670 | } |
| 2671 | else { |
Giulio Camuffo | 412e6a5 | 2014-07-09 22:12:56 +0300 | [diff] [blame] | 2672 | weston_layer_entry_insert(¤t_ws->layer.view_list, &view->layer_link); |
Manuel Bachmann | 50c87db | 2014-02-26 15:52:13 +0100 | [diff] [blame] | 2673 | |
| 2674 | wl_list_for_each(seat, &shsurf->shell->compositor->seat_list, link) { |
| 2675 | if (!seat->keyboard) |
| 2676 | continue; |
Emilio Pozuelo Monfort | 9e7c759 | 2014-01-30 14:01:10 +0100 | [diff] [blame] | 2677 | activate(shsurf->shell, view->surface, seat, true); |
Manuel Bachmann | 50c87db | 2014-02-26 15:52:13 +0100 | [diff] [blame] | 2678 | } |
| 2679 | } |
| 2680 | |
| 2681 | shell_surface_update_child_surface_layers(shsurf); |
| 2682 | |
| 2683 | weston_view_damage_below(view); |
| 2684 | } |
| 2685 | |
| 2686 | static void |
Philip Withnall | becb77e | 2013-11-25 18:01:30 +0000 | [diff] [blame] | 2687 | shell_surface_set_maximized(struct wl_client *client, |
| 2688 | struct wl_resource *resource, |
| 2689 | struct wl_resource *output_resource) |
| 2690 | { |
| 2691 | struct shell_surface *shsurf = wl_resource_get_user_data(resource); |
| 2692 | struct weston_output *output; |
| 2693 | |
Jasper St. Pierre | 9aa8ce6 | 2014-04-11 16:18:54 -0700 | [diff] [blame] | 2694 | surface_clear_next_states(shsurf); |
| 2695 | shsurf->next_state.maximized = true; |
| 2696 | shsurf->state_changed = true; |
| 2697 | |
Pekka Paalanen | b502654 | 2014-11-12 15:09:24 +0200 | [diff] [blame] | 2698 | set_type(shsurf, SHELL_SURFACE_TOPLEVEL); |
Jasper St. Pierre | 9aa8ce6 | 2014-04-11 16:18:54 -0700 | [diff] [blame] | 2699 | shell_surface_set_parent(shsurf, NULL); |
| 2700 | |
Philip Withnall | becb77e | 2013-11-25 18:01:30 +0000 | [diff] [blame] | 2701 | if (output_resource) |
| 2702 | output = wl_resource_get_user_data(output_resource); |
| 2703 | else |
| 2704 | output = NULL; |
| 2705 | |
Jasper St. Pierre | 9aa8ce6 | 2014-04-11 16:18:54 -0700 | [diff] [blame] | 2706 | shell_surface_set_output(shsurf, output); |
Rafael Antognolli | 4b99a40 | 2013-12-03 15:35:44 -0200 | [diff] [blame] | 2707 | |
Jasper St. Pierre | 9aa8ce6 | 2014-04-11 16:18:54 -0700 | [diff] [blame] | 2708 | send_configure_for_surface(shsurf); |
Philip Withnall | becb77e | 2013-11-25 18:01:30 +0000 | [diff] [blame] | 2709 | } |
| 2710 | |
Philip Withnall | e1d75ae | 2013-11-25 18:01:41 +0000 | [diff] [blame] | 2711 | /* This is only ever called from set_surface_type(), so there’s no need to |
| 2712 | * update layer_links here, since they’ll be updated when we return. */ |
Pekka Paalanen | 9826223 | 2011-12-01 10:42:22 +0200 | [diff] [blame] | 2713 | static int |
Philip Withnall | becb77e | 2013-11-25 18:01:30 +0000 | [diff] [blame] | 2714 | reset_surface_type(struct shell_surface *surface) |
Pekka Paalanen | 9826223 | 2011-12-01 10:42:22 +0200 | [diff] [blame] | 2715 | { |
Rafael Antognolli | 03b1659 | 2013-12-03 15:35:42 -0200 | [diff] [blame] | 2716 | if (surface->state.fullscreen) |
Philip Withnall | becb77e | 2013-11-25 18:01:30 +0000 | [diff] [blame] | 2717 | unset_fullscreen(surface); |
Rafael Antognolli | 03b1659 | 2013-12-03 15:35:42 -0200 | [diff] [blame] | 2718 | if (surface->state.maximized) |
Philip Withnall | becb77e | 2013-11-25 18:01:30 +0000 | [diff] [blame] | 2719 | unset_maximized(surface); |
Pekka Paalanen | 9826223 | 2011-12-01 10:42:22 +0200 | [diff] [blame] | 2720 | |
Pekka Paalanen | 9826223 | 2011-12-01 10:42:22 +0200 | [diff] [blame] | 2721 | return 0; |
| 2722 | } |
| 2723 | |
Kristian Høgsberg | 4cca349 | 2011-01-18 07:53:49 -0500 | [diff] [blame] | 2724 | static void |
Rafael Antognolli | 03b1659 | 2013-12-03 15:35:42 -0200 | [diff] [blame] | 2725 | set_full_output(struct shell_surface *shsurf) |
| 2726 | { |
| 2727 | shsurf->saved_x = shsurf->view->geometry.x; |
| 2728 | shsurf->saved_y = shsurf->view->geometry.y; |
Rafael Antognolli | 3c4e3f7 | 2013-12-03 15:35:46 -0200 | [diff] [blame] | 2729 | shsurf->saved_width = shsurf->surface->width; |
| 2730 | shsurf->saved_height = shsurf->surface->height; |
| 2731 | shsurf->saved_size_valid = true; |
Rafael Antognolli | 03b1659 | 2013-12-03 15:35:42 -0200 | [diff] [blame] | 2732 | shsurf->saved_position_valid = true; |
| 2733 | |
| 2734 | if (!wl_list_empty(&shsurf->rotation.transform.link)) { |
| 2735 | wl_list_remove(&shsurf->rotation.transform.link); |
| 2736 | wl_list_init(&shsurf->rotation.transform.link); |
| 2737 | weston_view_geometry_dirty(shsurf->view); |
| 2738 | shsurf->saved_rotation_valid = true; |
| 2739 | } |
| 2740 | } |
| 2741 | |
| 2742 | static void |
Kristian Høgsberg | 7f366e7 | 2012-04-27 17:20:01 -0400 | [diff] [blame] | 2743 | set_surface_type(struct shell_surface *shsurf) |
| 2744 | { |
Kristian Høgsberg | 8150b19 | 2012-06-27 10:22:58 -0400 | [diff] [blame] | 2745 | struct weston_surface *pes = shsurf->parent; |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 2746 | struct weston_view *pev = get_default_view(pes); |
Kristian Høgsberg | 7f366e7 | 2012-04-27 17:20:01 -0400 | [diff] [blame] | 2747 | |
Philip Withnall | becb77e | 2013-11-25 18:01:30 +0000 | [diff] [blame] | 2748 | reset_surface_type(shsurf); |
Kristian Høgsberg | 7f366e7 | 2012-04-27 17:20:01 -0400 | [diff] [blame] | 2749 | |
Rafael Antognolli | 03b1659 | 2013-12-03 15:35:42 -0200 | [diff] [blame] | 2750 | shsurf->state = shsurf->next_state; |
Rafael Antognolli | 03b1659 | 2013-12-03 15:35:42 -0200 | [diff] [blame] | 2751 | shsurf->state_changed = false; |
Kristian Høgsberg | 7f366e7 | 2012-04-27 17:20:01 -0400 | [diff] [blame] | 2752 | |
| 2753 | switch (shsurf->type) { |
| 2754 | case SHELL_SURFACE_TOPLEVEL: |
Rafael Antognolli | ed207b4 | 2013-12-03 15:35:43 -0200 | [diff] [blame] | 2755 | if (shsurf->state.maximized || shsurf->state.fullscreen) { |
Rafael Antognolli | 03b1659 | 2013-12-03 15:35:42 -0200 | [diff] [blame] | 2756 | set_full_output(shsurf); |
Rafael Antognolli | ed207b4 | 2013-12-03 15:35:43 -0200 | [diff] [blame] | 2757 | } else if (shsurf->state.relative && pev) { |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 2758 | weston_view_set_position(shsurf->view, |
| 2759 | pev->geometry.x + shsurf->transient.x, |
| 2760 | pev->geometry.y + shsurf->transient.y); |
Rafael Antognolli | ed207b4 | 2013-12-03 15:35:43 -0200 | [diff] [blame] | 2761 | } |
Rafael Antognolli | 44a3162 | 2013-12-04 18:37:16 -0200 | [diff] [blame] | 2762 | break; |
Kristian Høgsberg | 7f366e7 | 2012-04-27 17:20:01 -0400 | [diff] [blame] | 2763 | |
Tiago Vignatti | fb2adba | 2013-06-12 15:43:21 -0300 | [diff] [blame] | 2764 | case SHELL_SURFACE_XWAYLAND: |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 2765 | weston_view_set_position(shsurf->view, shsurf->transient.x, |
| 2766 | shsurf->transient.y); |
Tiago Vignatti | fb2adba | 2013-06-12 15:43:21 -0300 | [diff] [blame] | 2767 | break; |
| 2768 | |
Philip Withnall | 0f640e2 | 2013-11-25 18:01:31 +0000 | [diff] [blame] | 2769 | case SHELL_SURFACE_POPUP: |
| 2770 | case SHELL_SURFACE_NONE: |
Kristian Høgsberg | 7f366e7 | 2012-04-27 17:20:01 -0400 | [diff] [blame] | 2771 | default: |
| 2772 | break; |
| 2773 | } |
Philip Withnall | e1d75ae | 2013-11-25 18:01:41 +0000 | [diff] [blame] | 2774 | |
| 2775 | /* Update the surface’s layer. */ |
| 2776 | shell_surface_update_layer(shsurf); |
Kristian Høgsberg | 7f366e7 | 2012-04-27 17:20:01 -0400 | [diff] [blame] | 2777 | } |
| 2778 | |
Tiago Vignatti | be14326 | 2012-04-16 17:31:41 +0300 | [diff] [blame] | 2779 | static struct desktop_shell * |
Juan Zhao | 96879df | 2012-02-07 08:45:41 +0800 | [diff] [blame] | 2780 | shell_surface_get_shell(struct shell_surface *shsurf) |
Pekka Paalanen | af0e34c | 2011-12-02 10:59:17 +0200 | [diff] [blame] | 2781 | { |
Kristian Høgsberg | 02e79dc | 2012-04-12 09:55:26 -0400 | [diff] [blame] | 2782 | return shsurf->shell; |
Juan Zhao | 96879df | 2012-02-07 08:45:41 +0800 | [diff] [blame] | 2783 | } |
| 2784 | |
Pekka Paalanen | 8274d90 | 2014-08-06 19:36:51 +0300 | [diff] [blame] | 2785 | static int |
| 2786 | black_surface_get_label(struct weston_surface *surface, char *buf, size_t len) |
| 2787 | { |
| 2788 | struct weston_surface *fs_surface = surface->configure_private; |
| 2789 | int n; |
| 2790 | int rem; |
| 2791 | int ret; |
| 2792 | |
| 2793 | n = snprintf(buf, len, "black background surface for "); |
| 2794 | if (n < 0) |
| 2795 | return n; |
| 2796 | |
| 2797 | rem = (int)len - n; |
| 2798 | if (rem < 0) |
| 2799 | rem = 0; |
| 2800 | |
| 2801 | if (fs_surface->get_label) |
| 2802 | ret = fs_surface->get_label(fs_surface, buf + n, rem); |
| 2803 | else |
| 2804 | ret = snprintf(buf + n, rem, "<unknown>"); |
| 2805 | |
| 2806 | if (ret < 0) |
| 2807 | return n; |
| 2808 | |
| 2809 | return n + ret; |
| 2810 | } |
| 2811 | |
Alex Wu | 2185843 | 2012-04-01 20:13:08 +0800 | [diff] [blame] | 2812 | static void |
Jason Ekstrand | 918f2dd | 2013-12-02 21:01:53 -0600 | [diff] [blame] | 2813 | 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] | 2814 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 2815 | static struct weston_view * |
Alex Wu | 4539b08 | 2012-03-01 12:57:46 +0800 | [diff] [blame] | 2816 | create_black_surface(struct weston_compositor *ec, |
Alex Wu | 2185843 | 2012-04-01 20:13:08 +0800 | [diff] [blame] | 2817 | struct weston_surface *fs_surface, |
John Kåre Alsaker | 490d02a | 2012-09-30 02:57:21 +0200 | [diff] [blame] | 2818 | float x, float y, int w, int h) |
Alex Wu | 4539b08 | 2012-03-01 12:57:46 +0800 | [diff] [blame] | 2819 | { |
| 2820 | struct weston_surface *surface = NULL; |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 2821 | struct weston_view *view; |
Alex Wu | 4539b08 | 2012-03-01 12:57:46 +0800 | [diff] [blame] | 2822 | |
| 2823 | surface = weston_surface_create(ec); |
| 2824 | if (surface == NULL) { |
Martin Minarik | 6d11836 | 2012-06-07 18:01:59 +0200 | [diff] [blame] | 2825 | weston_log("no memory\n"); |
Alex Wu | 4539b08 | 2012-03-01 12:57:46 +0800 | [diff] [blame] | 2826 | return NULL; |
| 2827 | } |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 2828 | view = weston_view_create(surface); |
| 2829 | if (surface == NULL) { |
| 2830 | weston_log("no memory\n"); |
| 2831 | weston_surface_destroy(surface); |
| 2832 | return NULL; |
| 2833 | } |
Alex Wu | 4539b08 | 2012-03-01 12:57:46 +0800 | [diff] [blame] | 2834 | |
Alex Wu | 2185843 | 2012-04-01 20:13:08 +0800 | [diff] [blame] | 2835 | surface->configure = black_surface_configure; |
Giulio Camuffo | 7fe01b1 | 2013-03-28 18:02:42 +0100 | [diff] [blame] | 2836 | surface->configure_private = fs_surface; |
Pekka Paalanen | 8274d90 | 2014-08-06 19:36:51 +0300 | [diff] [blame] | 2837 | weston_surface_set_label_func(surface, black_surface_get_label); |
Alex Wu | 4539b08 | 2012-03-01 12:57:46 +0800 | [diff] [blame] | 2838 | weston_surface_set_color(surface, 0.0, 0.0, 0.0, 1); |
Pekka Paalanen | 71f6f3b | 2012-10-10 12:49:26 +0300 | [diff] [blame] | 2839 | pixman_region32_fini(&surface->opaque); |
Kristian Høgsberg | 61f00f5 | 2012-08-03 16:31:36 -0400 | [diff] [blame] | 2840 | pixman_region32_init_rect(&surface->opaque, 0, 0, w, h); |
Jonas Ådahl | 33619a4 | 2013-01-15 21:25:55 +0100 | [diff] [blame] | 2841 | pixman_region32_fini(&surface->input); |
| 2842 | pixman_region32_init_rect(&surface->input, 0, 0, w, h); |
Jason Ekstrand | 918f2dd | 2013-12-02 21:01:53 -0600 | [diff] [blame] | 2843 | |
Jason Ekstrand | 6228ee2 | 2014-01-01 15:58:57 -0600 | [diff] [blame] | 2844 | weston_surface_set_size(surface, w, h); |
Jason Ekstrand | 918f2dd | 2013-12-02 21:01:53 -0600 | [diff] [blame] | 2845 | weston_view_set_position(view, x, y); |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 2846 | |
| 2847 | return view; |
Alex Wu | 4539b08 | 2012-03-01 12:57:46 +0800 | [diff] [blame] | 2848 | } |
| 2849 | |
Philip Withnall | ed8f1a9 | 2013-11-25 18:01:43 +0000 | [diff] [blame] | 2850 | static void |
| 2851 | shell_ensure_fullscreen_black_view(struct shell_surface *shsurf) |
| 2852 | { |
| 2853 | struct weston_output *output = shsurf->fullscreen_output; |
| 2854 | |
Rafael Antognolli | 03b1659 | 2013-12-03 15:35:42 -0200 | [diff] [blame] | 2855 | assert(shsurf->state.fullscreen); |
Philip Withnall | ed8f1a9 | 2013-11-25 18:01:43 +0000 | [diff] [blame] | 2856 | |
| 2857 | if (!shsurf->fullscreen.black_view) |
| 2858 | shsurf->fullscreen.black_view = |
| 2859 | create_black_surface(shsurf->surface->compositor, |
| 2860 | shsurf->surface, |
| 2861 | output->x, output->y, |
| 2862 | output->width, |
| 2863 | output->height); |
| 2864 | |
| 2865 | weston_view_geometry_dirty(shsurf->fullscreen.black_view); |
Giulio Camuffo | 412e6a5 | 2014-07-09 22:12:56 +0300 | [diff] [blame] | 2866 | weston_layer_entry_remove(&shsurf->fullscreen.black_view->layer_link); |
| 2867 | weston_layer_entry_insert(&shsurf->view->layer_link, |
| 2868 | &shsurf->fullscreen.black_view->layer_link); |
Philip Withnall | ed8f1a9 | 2013-11-25 18:01:43 +0000 | [diff] [blame] | 2869 | weston_view_geometry_dirty(shsurf->fullscreen.black_view); |
| 2870 | weston_surface_damage(shsurf->surface); |
Emilio Pozuelo Monfort | 9e7c759 | 2014-01-30 14:01:10 +0100 | [diff] [blame] | 2871 | |
| 2872 | shsurf->state.lowered = false; |
Philip Withnall | ed8f1a9 | 2013-11-25 18:01:43 +0000 | [diff] [blame] | 2873 | } |
| 2874 | |
Alex Wu | 4539b08 | 2012-03-01 12:57:46 +0800 | [diff] [blame] | 2875 | /* Create black surface and append it to the associated fullscreen surface. |
| 2876 | * Handle size dismatch and positioning according to the method. */ |
| 2877 | static void |
| 2878 | shell_configure_fullscreen(struct shell_surface *shsurf) |
| 2879 | { |
| 2880 | struct weston_output *output = shsurf->fullscreen_output; |
| 2881 | struct weston_surface *surface = shsurf->surface; |
| 2882 | struct weston_matrix *matrix; |
Kristian Høgsberg | 240dfeb | 2012-07-12 12:32:31 -0400 | [diff] [blame] | 2883 | float scale, output_aspect, surface_aspect, x, y; |
Giulio Camuffo | b836664 | 2013-04-25 13:57:46 +0300 | [diff] [blame] | 2884 | int32_t surf_x, surf_y, surf_width, surf_height; |
Alex Wu | 4539b08 | 2012-03-01 12:57:46 +0800 | [diff] [blame] | 2885 | |
Alexander Larsson | f82b6ca | 2013-05-28 16:23:39 +0200 | [diff] [blame] | 2886 | if (shsurf->fullscreen.type != WL_SHELL_SURFACE_FULLSCREEN_METHOD_DRIVER) |
| 2887 | restore_output_mode(output); |
| 2888 | |
Emilio Pozuelo Monfort | 9e7c759 | 2014-01-30 14:01:10 +0100 | [diff] [blame] | 2889 | /* Reverse the effect of lower_fullscreen_layer() */ |
Giulio Camuffo | 412e6a5 | 2014-07-09 22:12:56 +0300 | [diff] [blame] | 2890 | weston_layer_entry_remove(&shsurf->view->layer_link); |
| 2891 | 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] | 2892 | |
Philip Withnall | ed8f1a9 | 2013-11-25 18:01:43 +0000 | [diff] [blame] | 2893 | shell_ensure_fullscreen_black_view(shsurf); |
Alex Wu | 4539b08 | 2012-03-01 12:57:46 +0800 | [diff] [blame] | 2894 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 2895 | surface_subsurfaces_boundingbox(shsurf->surface, &surf_x, &surf_y, |
Giulio Camuffo | b836664 | 2013-04-25 13:57:46 +0300 | [diff] [blame] | 2896 | &surf_width, &surf_height); |
| 2897 | |
Alex Wu | 4539b08 | 2012-03-01 12:57:46 +0800 | [diff] [blame] | 2898 | switch (shsurf->fullscreen.type) { |
| 2899 | case WL_SHELL_SURFACE_FULLSCREEN_METHOD_DEFAULT: |
Pekka Paalanen | de685b8 | 2012-12-04 15:58:12 +0200 | [diff] [blame] | 2900 | if (surface->buffer_ref.buffer) |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 2901 | center_on_output(shsurf->view, shsurf->fullscreen_output); |
Alex Wu | 4539b08 | 2012-03-01 12:57:46 +0800 | [diff] [blame] | 2902 | break; |
| 2903 | case WL_SHELL_SURFACE_FULLSCREEN_METHOD_SCALE: |
Rob Bradford | 9f3dd15 | 2013-02-12 11:53:47 +0000 | [diff] [blame] | 2904 | /* 1:1 mapping between surface and output dimensions */ |
Giulio Camuffo | b836664 | 2013-04-25 13:57:46 +0300 | [diff] [blame] | 2905 | if (output->width == surf_width && |
| 2906 | output->height == surf_height) { |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 2907 | weston_view_set_position(shsurf->view, |
| 2908 | output->x - surf_x, |
| 2909 | output->y - surf_y); |
Rob Bradford | 9f3dd15 | 2013-02-12 11:53:47 +0000 | [diff] [blame] | 2910 | break; |
| 2911 | } |
| 2912 | |
Alex Wu | 4539b08 | 2012-03-01 12:57:46 +0800 | [diff] [blame] | 2913 | matrix = &shsurf->fullscreen.transform.matrix; |
| 2914 | weston_matrix_init(matrix); |
Kristian Høgsberg | 240dfeb | 2012-07-12 12:32:31 -0400 | [diff] [blame] | 2915 | |
Scott Moreau | 1bad5db | 2012-08-18 01:04:05 -0600 | [diff] [blame] | 2916 | output_aspect = (float) output->width / |
| 2917 | (float) output->height; |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 2918 | /* XXX: Use surf_width and surf_height here? */ |
| 2919 | surface_aspect = (float) surface->width / |
| 2920 | (float) surface->height; |
Kristian Høgsberg | 240dfeb | 2012-07-12 12:32:31 -0400 | [diff] [blame] | 2921 | if (output_aspect < surface_aspect) |
Scott Moreau | 1bad5db | 2012-08-18 01:04:05 -0600 | [diff] [blame] | 2922 | scale = (float) output->width / |
Giulio Camuffo | b836664 | 2013-04-25 13:57:46 +0300 | [diff] [blame] | 2923 | (float) surf_width; |
Kristian Høgsberg | 240dfeb | 2012-07-12 12:32:31 -0400 | [diff] [blame] | 2924 | else |
Scott Moreau | 1bad5db | 2012-08-18 01:04:05 -0600 | [diff] [blame] | 2925 | scale = (float) output->height / |
Giulio Camuffo | b836664 | 2013-04-25 13:57:46 +0300 | [diff] [blame] | 2926 | (float) surf_height; |
Kristian Høgsberg | 240dfeb | 2012-07-12 12:32:31 -0400 | [diff] [blame] | 2927 | |
Alex Wu | 4539b08 | 2012-03-01 12:57:46 +0800 | [diff] [blame] | 2928 | weston_matrix_scale(matrix, scale, scale, 1); |
| 2929 | wl_list_remove(&shsurf->fullscreen.transform.link); |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 2930 | wl_list_insert(&shsurf->view->geometry.transformation_list, |
Alex Wu | 4539b08 | 2012-03-01 12:57:46 +0800 | [diff] [blame] | 2931 | &shsurf->fullscreen.transform.link); |
Giulio Camuffo | b836664 | 2013-04-25 13:57:46 +0300 | [diff] [blame] | 2932 | x = output->x + (output->width - surf_width * scale) / 2 - surf_x; |
| 2933 | y = output->y + (output->height - surf_height * scale) / 2 - surf_y; |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 2934 | weston_view_set_position(shsurf->view, x, y); |
Kristian Høgsberg | 240dfeb | 2012-07-12 12:32:31 -0400 | [diff] [blame] | 2935 | |
Alex Wu | 4539b08 | 2012-03-01 12:57:46 +0800 | [diff] [blame] | 2936 | break; |
| 2937 | case WL_SHELL_SURFACE_FULLSCREEN_METHOD_DRIVER: |
Alex Wu | bd3354b | 2012-04-17 17:20:49 +0800 | [diff] [blame] | 2938 | if (shell_surface_is_top_fullscreen(shsurf)) { |
Quentin Glidic | c0d79ce | 2013-01-29 14:16:13 +0100 | [diff] [blame] | 2939 | struct weston_mode mode = {0, |
Pekka Paalanen | 952b6c8 | 2014-03-14 14:38:15 +0200 | [diff] [blame] | 2940 | surf_width * surface->buffer_viewport.buffer.scale, |
| 2941 | surf_height * surface->buffer_viewport.buffer.scale, |
Alex Wu | bd3354b | 2012-04-17 17:20:49 +0800 | [diff] [blame] | 2942 | shsurf->fullscreen.framerate}; |
| 2943 | |
Derek Foreman | 6ae7bc9 | 2014-11-04 10:47:33 -0600 | [diff] [blame] | 2944 | if (weston_output_mode_switch_to_temporary(output, &mode, |
| 2945 | surface->buffer_viewport.buffer.scale) == 0) { |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 2946 | weston_view_set_position(shsurf->view, |
| 2947 | output->x - surf_x, |
| 2948 | output->y - surf_y); |
Jason Ekstrand | 918f2dd | 2013-12-02 21:01:53 -0600 | [diff] [blame] | 2949 | shsurf->fullscreen.black_view->surface->width = output->width; |
| 2950 | shsurf->fullscreen.black_view->surface->height = output->height; |
| 2951 | weston_view_set_position(shsurf->fullscreen.black_view, |
| 2952 | output->x - surf_x, |
| 2953 | output->y - surf_y); |
Alex Wu | bd3354b | 2012-04-17 17:20:49 +0800 | [diff] [blame] | 2954 | break; |
Alexander Larsson | d622ed3 | 2013-05-28 16:23:40 +0200 | [diff] [blame] | 2955 | } else { |
Alexander Larsson | f82b6ca | 2013-05-28 16:23:39 +0200 | [diff] [blame] | 2956 | restore_output_mode(output); |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 2957 | center_on_output(shsurf->view, output); |
Alexander Larsson | d622ed3 | 2013-05-28 16:23:40 +0200 | [diff] [blame] | 2958 | } |
Alex Wu | bd3354b | 2012-04-17 17:20:49 +0800 | [diff] [blame] | 2959 | } |
Alex Wu | 4539b08 | 2012-03-01 12:57:46 +0800 | [diff] [blame] | 2960 | break; |
| 2961 | case WL_SHELL_SURFACE_FULLSCREEN_METHOD_FILL: |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 2962 | center_on_output(shsurf->view, output); |
Alex Wu | 4539b08 | 2012-03-01 12:57:46 +0800 | [diff] [blame] | 2963 | break; |
| 2964 | default: |
| 2965 | break; |
| 2966 | } |
| 2967 | } |
| 2968 | |
Alex Wu | 4539b08 | 2012-03-01 12:57:46 +0800 | [diff] [blame] | 2969 | static void |
| 2970 | shell_map_fullscreen(struct shell_surface *shsurf) |
| 2971 | { |
Alex Wu | bd3354b | 2012-04-17 17:20:49 +0800 | [diff] [blame] | 2972 | shell_configure_fullscreen(shsurf); |
Alex Wu | 4539b08 | 2012-03-01 12:57:46 +0800 | [diff] [blame] | 2973 | } |
| 2974 | |
Kristian Høgsberg | 7a5c979 | 2011-06-18 06:12:54 -0400 | [diff] [blame] | 2975 | static void |
Tiago Vignatti | fb2adba | 2013-06-12 15:43:21 -0300 | [diff] [blame] | 2976 | set_xwayland(struct shell_surface *shsurf, int x, int y, uint32_t flags) |
| 2977 | { |
| 2978 | /* XXX: using the same fields for transient type */ |
Rafael Antognolli | 03b1659 | 2013-12-03 15:35:42 -0200 | [diff] [blame] | 2979 | surface_clear_next_states(shsurf); |
Tiago Vignatti | fb2adba | 2013-06-12 15:43:21 -0300 | [diff] [blame] | 2980 | shsurf->transient.x = x; |
| 2981 | shsurf->transient.y = y; |
| 2982 | shsurf->transient.flags = flags; |
Philip Withnall | dc4332f | 2013-11-25 18:01:38 +0000 | [diff] [blame] | 2983 | |
| 2984 | shell_surface_set_parent(shsurf, NULL); |
| 2985 | |
Pekka Paalanen | b502654 | 2014-11-12 15:09:24 +0200 | [diff] [blame] | 2986 | set_type(shsurf, SHELL_SURFACE_XWAYLAND); |
Kristian Høgsberg | 8bc525c | 2014-01-01 22:34:49 -0800 | [diff] [blame] | 2987 | shsurf->state_changed = true; |
Tiago Vignatti | fb2adba | 2013-06-12 15:43:21 -0300 | [diff] [blame] | 2988 | } |
| 2989 | |
Kristian Høgsberg | 4779241 | 2014-05-04 13:47:06 -0700 | [diff] [blame] | 2990 | static void |
| 2991 | shell_interface_set_fullscreen(struct shell_surface *shsurf, |
| 2992 | uint32_t method, |
| 2993 | uint32_t framerate, |
| 2994 | struct weston_output *output) |
| 2995 | { |
| 2996 | surface_clear_next_states(shsurf); |
Kristian Høgsberg | 4779241 | 2014-05-04 13:47:06 -0700 | [diff] [blame] | 2997 | shsurf->next_state.fullscreen = true; |
| 2998 | shsurf->state_changed = true; |
Marek Chalupa | e9fe467 | 2014-10-29 13:44:44 +0100 | [diff] [blame] | 2999 | |
| 3000 | set_fullscreen(shsurf, method, framerate, output); |
Kristian Høgsberg | 4779241 | 2014-05-04 13:47:06 -0700 | [diff] [blame] | 3001 | } |
| 3002 | |
Giulio Camuffo | 6b4b241 | 2015-01-29 19:06:49 +0200 | [diff] [blame] | 3003 | static struct weston_output * |
| 3004 | get_focused_output(struct weston_compositor *compositor) |
| 3005 | { |
| 3006 | struct weston_seat *seat; |
| 3007 | struct weston_output *output = NULL; |
| 3008 | |
| 3009 | wl_list_for_each(seat, &compositor->seat_list, link) { |
| 3010 | /* Priority has touch focus, then pointer and |
| 3011 | * then keyboard focus. We should probably have |
| 3012 | * three for loops and check frist for touch, |
| 3013 | * then for pointer, etc. but unless somebody has some |
| 3014 | * objections, I think this is sufficient. */ |
| 3015 | if (seat->touch && seat->touch->focus) |
| 3016 | output = seat->touch->focus->output; |
| 3017 | else if (seat->pointer && seat->pointer->focus) |
| 3018 | output = seat->pointer->focus->output; |
| 3019 | else if (seat->keyboard && seat->keyboard->focus) |
| 3020 | output = seat->keyboard->focus->output; |
| 3021 | |
| 3022 | if (output) |
| 3023 | break; |
| 3024 | } |
| 3025 | |
| 3026 | return output; |
| 3027 | } |
| 3028 | |
| 3029 | static void |
| 3030 | shell_interface_set_maximized(struct shell_surface *shsurf) |
| 3031 | { |
| 3032 | struct weston_output *output; |
| 3033 | |
| 3034 | surface_clear_next_states(shsurf); |
| 3035 | shsurf->next_state.maximized = true; |
| 3036 | shsurf->state_changed = true; |
| 3037 | shsurf->type = SHELL_SURFACE_TOPLEVEL; |
| 3038 | |
| 3039 | if (!weston_surface_is_mapped(shsurf->surface)) |
| 3040 | output = get_focused_output(shsurf->surface->compositor); |
| 3041 | else |
| 3042 | output = shsurf->surface->output; |
| 3043 | |
| 3044 | shell_surface_set_output(shsurf, output); |
| 3045 | send_configure_for_surface(shsurf); |
| 3046 | } |
| 3047 | |
Kristian Høgsberg | ae356ae | 2014-04-29 16:03:54 -0700 | [diff] [blame] | 3048 | static int |
| 3049 | shell_interface_move(struct shell_surface *shsurf, struct weston_seat *ws) |
| 3050 | { |
| 3051 | return surface_move(shsurf, ws, 1); |
| 3052 | } |
| 3053 | |
Kristian Høgsberg | 02bbabb | 2013-05-06 22:15:05 -0400 | [diff] [blame] | 3054 | static const struct weston_pointer_grab_interface popup_grab_interface; |
Giulio Camuffo | 5085a75 | 2013-03-25 21:42:45 +0100 | [diff] [blame] | 3055 | |
| 3056 | static void |
| 3057 | destroy_shell_seat(struct wl_listener *listener, void *data) |
| 3058 | { |
| 3059 | struct shell_seat *shseat = |
| 3060 | container_of(listener, |
| 3061 | struct shell_seat, seat_destroy_listener); |
Jonas Ådahl | c2b1011 | 2015-02-13 14:01:53 +0800 | [diff] [blame] | 3062 | struct shell_surface *shsurf, *next; |
Giulio Camuffo | 5085a75 | 2013-03-25 21:42:45 +0100 | [diff] [blame] | 3063 | |
| 3064 | if (shseat->popup_grab.grab.interface == &popup_grab_interface) { |
Kristian Høgsberg | 02bbabb | 2013-05-06 22:15:05 -0400 | [diff] [blame] | 3065 | weston_pointer_end_grab(shseat->popup_grab.grab.pointer); |
Giulio Camuffo | 5085a75 | 2013-03-25 21:42:45 +0100 | [diff] [blame] | 3066 | shseat->popup_grab.client = NULL; |
| 3067 | |
Jonas Ådahl | c2b1011 | 2015-02-13 14:01:53 +0800 | [diff] [blame] | 3068 | wl_list_for_each_safe(shsurf, next, |
| 3069 | &shseat->popup_grab.surfaces_list, |
| 3070 | popup.grab_link) { |
Giulio Camuffo | 5085a75 | 2013-03-25 21:42:45 +0100 | [diff] [blame] | 3071 | shsurf->popup.shseat = NULL; |
Jonas Ådahl | c2b1011 | 2015-02-13 14:01:53 +0800 | [diff] [blame] | 3072 | wl_list_init(&shsurf->popup.grab_link); |
Giulio Camuffo | 5085a75 | 2013-03-25 21:42:45 +0100 | [diff] [blame] | 3073 | } |
Giulio Camuffo | 5085a75 | 2013-03-25 21:42:45 +0100 | [diff] [blame] | 3074 | } |
| 3075 | |
| 3076 | wl_list_remove(&shseat->seat_destroy_listener.link); |
| 3077 | free(shseat); |
| 3078 | } |
| 3079 | |
Jason Ekstrand | 024177c | 2014-04-21 19:42:58 -0500 | [diff] [blame] | 3080 | static void |
| 3081 | shell_seat_caps_changed(struct wl_listener *listener, void *data) |
| 3082 | { |
| 3083 | struct shell_seat *seat; |
| 3084 | |
| 3085 | seat = container_of(listener, struct shell_seat, caps_changed_listener); |
| 3086 | |
| 3087 | if (seat->seat->keyboard && |
| 3088 | wl_list_empty(&seat->keyboard_focus_listener.link)) { |
| 3089 | wl_signal_add(&seat->seat->keyboard->focus_signal, |
| 3090 | &seat->keyboard_focus_listener); |
| 3091 | } else if (!seat->seat->keyboard) { |
| 3092 | wl_list_init(&seat->keyboard_focus_listener.link); |
| 3093 | } |
| 3094 | |
| 3095 | if (seat->seat->pointer && |
| 3096 | wl_list_empty(&seat->pointer_focus_listener.link)) { |
| 3097 | wl_signal_add(&seat->seat->pointer->focus_signal, |
| 3098 | &seat->pointer_focus_listener); |
| 3099 | } else if (!seat->seat->pointer) { |
| 3100 | wl_list_init(&seat->pointer_focus_listener.link); |
| 3101 | } |
| 3102 | } |
| 3103 | |
Giulio Camuffo | 5085a75 | 2013-03-25 21:42:45 +0100 | [diff] [blame] | 3104 | static struct shell_seat * |
| 3105 | create_shell_seat(struct weston_seat *seat) |
| 3106 | { |
| 3107 | struct shell_seat *shseat; |
| 3108 | |
| 3109 | shseat = calloc(1, sizeof *shseat); |
| 3110 | if (!shseat) { |
| 3111 | weston_log("no memory to allocate shell seat\n"); |
| 3112 | return NULL; |
| 3113 | } |
| 3114 | |
| 3115 | shseat->seat = seat; |
| 3116 | wl_list_init(&shseat->popup_grab.surfaces_list); |
| 3117 | |
| 3118 | shseat->seat_destroy_listener.notify = destroy_shell_seat; |
| 3119 | wl_signal_add(&seat->destroy_signal, |
| 3120 | &shseat->seat_destroy_listener); |
| 3121 | |
Jason Ekstrand | 024177c | 2014-04-21 19:42:58 -0500 | [diff] [blame] | 3122 | shseat->keyboard_focus_listener.notify = handle_keyboard_focus; |
| 3123 | wl_list_init(&shseat->keyboard_focus_listener.link); |
| 3124 | |
| 3125 | shseat->pointer_focus_listener.notify = handle_pointer_focus; |
| 3126 | wl_list_init(&shseat->pointer_focus_listener.link); |
| 3127 | |
| 3128 | shseat->caps_changed_listener.notify = shell_seat_caps_changed; |
| 3129 | wl_signal_add(&seat->updated_caps_signal, |
| 3130 | &shseat->caps_changed_listener); |
| 3131 | shell_seat_caps_changed(&shseat->caps_changed_listener, NULL); |
| 3132 | |
Giulio Camuffo | 5085a75 | 2013-03-25 21:42:45 +0100 | [diff] [blame] | 3133 | return shseat; |
| 3134 | } |
| 3135 | |
| 3136 | static struct shell_seat * |
| 3137 | get_shell_seat(struct weston_seat *seat) |
| 3138 | { |
| 3139 | struct wl_listener *listener; |
| 3140 | |
| 3141 | listener = wl_signal_get(&seat->destroy_signal, destroy_shell_seat); |
Jason Ekstrand | 024177c | 2014-04-21 19:42:58 -0500 | [diff] [blame] | 3142 | assert(listener != NULL); |
Giulio Camuffo | 5085a75 | 2013-03-25 21:42:45 +0100 | [diff] [blame] | 3143 | |
| 3144 | return container_of(listener, |
| 3145 | struct shell_seat, seat_destroy_listener); |
| 3146 | } |
| 3147 | |
Kristian Høgsberg | b810eb5 | 2013-02-12 20:07:05 -0500 | [diff] [blame] | 3148 | static void |
Kristian Høgsberg | 6848c25 | 2013-05-08 22:02:59 -0400 | [diff] [blame] | 3149 | popup_grab_focus(struct weston_pointer_grab *grab) |
Kristian Høgsberg | b3cca0a | 2012-01-04 22:19:14 -0500 | [diff] [blame] | 3150 | { |
Kristian Høgsberg | 02bbabb | 2013-05-06 22:15:05 -0400 | [diff] [blame] | 3151 | struct weston_pointer *pointer = grab->pointer; |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 3152 | struct weston_view *view; |
Giulio Camuffo | 5085a75 | 2013-03-25 21:42:45 +0100 | [diff] [blame] | 3153 | struct shell_seat *shseat = |
| 3154 | container_of(grab, struct shell_seat, popup_grab.grab); |
| 3155 | struct wl_client *client = shseat->popup_grab.client; |
Kristian Høgsberg | 6848c25 | 2013-05-08 22:02:59 -0400 | [diff] [blame] | 3156 | wl_fixed_t sx, sy; |
| 3157 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 3158 | view = weston_compositor_pick_view(pointer->seat->compositor, |
| 3159 | pointer->x, pointer->y, |
| 3160 | &sx, &sy); |
Kristian Høgsberg | b3cca0a | 2012-01-04 22:19:14 -0500 | [diff] [blame] | 3161 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 3162 | if (view && view->surface->resource && |
| 3163 | wl_resource_get_client(view->surface->resource) == client) { |
| 3164 | weston_pointer_set_focus(pointer, view, sx, sy); |
Kristian Høgsberg | b3cca0a | 2012-01-04 22:19:14 -0500 | [diff] [blame] | 3165 | } else { |
Kristian Høgsberg | 02bbabb | 2013-05-06 22:15:05 -0400 | [diff] [blame] | 3166 | weston_pointer_set_focus(pointer, NULL, |
| 3167 | wl_fixed_from_int(0), |
| 3168 | wl_fixed_from_int(0)); |
Kristian Høgsberg | b3cca0a | 2012-01-04 22:19:14 -0500 | [diff] [blame] | 3169 | } |
| 3170 | } |
| 3171 | |
| 3172 | static void |
Giulio Camuffo | 1959ab8 | 2013-11-14 23:42:52 +0100 | [diff] [blame] | 3173 | popup_grab_motion(struct weston_pointer_grab *grab, uint32_t time, |
| 3174 | wl_fixed_t x, wl_fixed_t y) |
Kristian Høgsberg | b3cca0a | 2012-01-04 22:19:14 -0500 | [diff] [blame] | 3175 | { |
Kristian Høgsberg | be6403e | 2013-05-08 21:03:21 -0400 | [diff] [blame] | 3176 | struct weston_pointer *pointer = grab->pointer; |
Neil Roberts | 96d790e | 2013-09-19 17:32:00 +0100 | [diff] [blame] | 3177 | struct wl_resource *resource; |
Kristian Høgsberg | be6403e | 2013-05-08 21:03:21 -0400 | [diff] [blame] | 3178 | wl_fixed_t sx, sy; |
Kristian Høgsberg | b3cca0a | 2012-01-04 22:19:14 -0500 | [diff] [blame] | 3179 | |
Jonas Ådahl | 61917c8 | 2014-08-11 22:44:02 +0200 | [diff] [blame] | 3180 | if (pointer->focus) { |
| 3181 | weston_view_from_global_fixed(pointer->focus, x, y, |
| 3182 | &pointer->sx, &pointer->sy); |
| 3183 | } |
| 3184 | |
Giulio Camuffo | 1959ab8 | 2013-11-14 23:42:52 +0100 | [diff] [blame] | 3185 | weston_pointer_move(pointer, x, y); |
| 3186 | |
Neil Roberts | 96d790e | 2013-09-19 17:32:00 +0100 | [diff] [blame] | 3187 | wl_resource_for_each(resource, &pointer->focus_resource_list) { |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 3188 | weston_view_from_global_fixed(pointer->focus, |
| 3189 | pointer->x, pointer->y, |
| 3190 | &sx, &sy); |
Neil Roberts | 96d790e | 2013-09-19 17:32:00 +0100 | [diff] [blame] | 3191 | wl_pointer_send_motion(resource, time, sx, sy); |
Kristian Høgsberg | be6403e | 2013-05-08 21:03:21 -0400 | [diff] [blame] | 3192 | } |
Kristian Høgsberg | b3cca0a | 2012-01-04 22:19:14 -0500 | [diff] [blame] | 3193 | } |
| 3194 | |
| 3195 | static void |
Kristian Høgsberg | 02bbabb | 2013-05-06 22:15:05 -0400 | [diff] [blame] | 3196 | popup_grab_button(struct weston_pointer_grab *grab, |
Daniel Stone | 4dbadb1 | 2012-05-30 16:31:51 +0100 | [diff] [blame] | 3197 | uint32_t time, uint32_t button, uint32_t state_w) |
Kristian Høgsberg | b3cca0a | 2012-01-04 22:19:14 -0500 | [diff] [blame] | 3198 | { |
| 3199 | struct wl_resource *resource; |
Giulio Camuffo | 5085a75 | 2013-03-25 21:42:45 +0100 | [diff] [blame] | 3200 | struct shell_seat *shseat = |
| 3201 | container_of(grab, struct shell_seat, popup_grab.grab); |
Rob Bradford | 880ebc7 | 2013-07-22 17:31:38 +0100 | [diff] [blame] | 3202 | struct wl_display *display = shseat->seat->compositor->wl_display; |
Daniel Stone | 4dbadb1 | 2012-05-30 16:31:51 +0100 | [diff] [blame] | 3203 | enum wl_pointer_button_state state = state_w; |
Kristian Høgsberg | eae5de7 | 2012-04-11 22:42:15 -0400 | [diff] [blame] | 3204 | uint32_t serial; |
Neil Roberts | 96d790e | 2013-09-19 17:32:00 +0100 | [diff] [blame] | 3205 | struct wl_list *resource_list; |
Kristian Høgsberg | b3cca0a | 2012-01-04 22:19:14 -0500 | [diff] [blame] | 3206 | |
Neil Roberts | 96d790e | 2013-09-19 17:32:00 +0100 | [diff] [blame] | 3207 | resource_list = &grab->pointer->focus_resource_list; |
| 3208 | if (!wl_list_empty(resource_list)) { |
Kristian Høgsberg | eae5de7 | 2012-04-11 22:42:15 -0400 | [diff] [blame] | 3209 | serial = wl_display_get_serial(display); |
Neil Roberts | 96d790e | 2013-09-19 17:32:00 +0100 | [diff] [blame] | 3210 | wl_resource_for_each(resource, resource_list) { |
| 3211 | wl_pointer_send_button(resource, serial, |
| 3212 | time, button, state); |
| 3213 | } |
Daniel Stone | 4dbadb1 | 2012-05-30 16:31:51 +0100 | [diff] [blame] | 3214 | } else if (state == WL_POINTER_BUTTON_STATE_RELEASED && |
Giulio Camuffo | 5085a75 | 2013-03-25 21:42:45 +0100 | [diff] [blame] | 3215 | (shseat->popup_grab.initial_up || |
Kristian Høgsberg | e314875 | 2013-05-06 23:19:49 -0400 | [diff] [blame] | 3216 | time - shseat->seat->pointer->grab_time > 500)) { |
Kristian Høgsberg | 57e0907 | 2012-10-30 14:07:27 -0400 | [diff] [blame] | 3217 | popup_grab_end(grab->pointer); |
Kristian Høgsberg | b3cca0a | 2012-01-04 22:19:14 -0500 | [diff] [blame] | 3218 | } |
| 3219 | |
Daniel Stone | 4dbadb1 | 2012-05-30 16:31:51 +0100 | [diff] [blame] | 3220 | if (state == WL_POINTER_BUTTON_STATE_RELEASED) |
Giulio Camuffo | 5085a75 | 2013-03-25 21:42:45 +0100 | [diff] [blame] | 3221 | shseat->popup_grab.initial_up = 1; |
Kristian Høgsberg | b3cca0a | 2012-01-04 22:19:14 -0500 | [diff] [blame] | 3222 | } |
| 3223 | |
Jonas Ådahl | 1ea343e | 2013-10-25 23:18:05 +0200 | [diff] [blame] | 3224 | static void |
| 3225 | popup_grab_cancel(struct weston_pointer_grab *grab) |
| 3226 | { |
| 3227 | popup_grab_end(grab->pointer); |
| 3228 | } |
| 3229 | |
Kristian Høgsberg | 02bbabb | 2013-05-06 22:15:05 -0400 | [diff] [blame] | 3230 | static const struct weston_pointer_grab_interface popup_grab_interface = { |
Kristian Høgsberg | b3cca0a | 2012-01-04 22:19:14 -0500 | [diff] [blame] | 3231 | popup_grab_focus, |
| 3232 | popup_grab_motion, |
| 3233 | popup_grab_button, |
Jonas Ådahl | 1ea343e | 2013-10-25 23:18:05 +0200 | [diff] [blame] | 3234 | popup_grab_cancel, |
Kristian Høgsberg | b3cca0a | 2012-01-04 22:19:14 -0500 | [diff] [blame] | 3235 | }; |
| 3236 | |
| 3237 | static void |
Jonny Lamb | 76cf1fe | 2014-08-20 11:27:10 +0200 | [diff] [blame] | 3238 | touch_popup_grab_down(struct weston_touch_grab *grab, uint32_t time, |
| 3239 | int touch_id, wl_fixed_t sx, wl_fixed_t sy) |
| 3240 | { |
| 3241 | struct wl_resource *resource; |
| 3242 | struct shell_seat *shseat = |
| 3243 | container_of(grab, struct shell_seat, popup_grab.touch_grab); |
| 3244 | struct wl_display *display = shseat->seat->compositor->wl_display; |
| 3245 | uint32_t serial; |
| 3246 | struct wl_list *resource_list; |
| 3247 | |
| 3248 | resource_list = &grab->touch->focus_resource_list; |
| 3249 | if (!wl_list_empty(resource_list)) { |
| 3250 | serial = wl_display_get_serial(display); |
| 3251 | wl_resource_for_each(resource, resource_list) { |
| 3252 | wl_touch_send_down(resource, serial, time, |
| 3253 | grab->touch->focus->surface->resource, |
| 3254 | touch_id, sx, sy); |
| 3255 | } |
| 3256 | } |
| 3257 | } |
| 3258 | |
| 3259 | static void |
| 3260 | touch_popup_grab_up(struct weston_touch_grab *grab, uint32_t time, int touch_id) |
| 3261 | { |
| 3262 | struct wl_resource *resource; |
| 3263 | struct shell_seat *shseat = |
| 3264 | container_of(grab, struct shell_seat, popup_grab.touch_grab); |
| 3265 | struct wl_display *display = shseat->seat->compositor->wl_display; |
| 3266 | uint32_t serial; |
| 3267 | struct wl_list *resource_list; |
| 3268 | |
| 3269 | resource_list = &grab->touch->focus_resource_list; |
| 3270 | if (!wl_list_empty(resource_list)) { |
| 3271 | serial = wl_display_get_serial(display); |
| 3272 | wl_resource_for_each(resource, resource_list) { |
| 3273 | wl_touch_send_up(resource, serial, time, touch_id); |
| 3274 | } |
| 3275 | } |
| 3276 | } |
| 3277 | |
| 3278 | static void |
| 3279 | touch_popup_grab_motion(struct weston_touch_grab *grab, uint32_t time, |
| 3280 | int touch_id, wl_fixed_t sx, wl_fixed_t sy) |
| 3281 | { |
| 3282 | struct wl_resource *resource; |
| 3283 | struct wl_list *resource_list; |
| 3284 | |
| 3285 | resource_list = &grab->touch->focus_resource_list; |
| 3286 | if (!wl_list_empty(resource_list)) { |
| 3287 | wl_resource_for_each(resource, resource_list) { |
| 3288 | wl_touch_send_motion(resource, time, touch_id, sx, sy); |
| 3289 | } |
| 3290 | } |
| 3291 | } |
| 3292 | |
| 3293 | static void |
| 3294 | touch_popup_grab_frame(struct weston_touch_grab *grab) |
| 3295 | { |
| 3296 | } |
| 3297 | |
| 3298 | static void |
| 3299 | touch_popup_grab_cancel(struct weston_touch_grab *grab) |
| 3300 | { |
| 3301 | touch_popup_grab_end(grab->touch); |
| 3302 | } |
| 3303 | |
| 3304 | static const struct weston_touch_grab_interface touch_popup_grab_interface = { |
| 3305 | touch_popup_grab_down, |
| 3306 | touch_popup_grab_up, |
| 3307 | touch_popup_grab_motion, |
| 3308 | touch_popup_grab_frame, |
| 3309 | touch_popup_grab_cancel, |
| 3310 | }; |
| 3311 | |
| 3312 | static void |
Rafael Antognolli | e2a3455 | 2013-12-03 15:35:45 -0200 | [diff] [blame] | 3313 | shell_surface_send_popup_done(struct shell_surface *shsurf) |
| 3314 | { |
| 3315 | if (shell_surface_is_wl_shell_surface(shsurf)) |
| 3316 | wl_shell_surface_send_popup_done(shsurf->resource); |
| 3317 | else if (shell_surface_is_xdg_popup(shsurf)) |
| 3318 | xdg_popup_send_popup_done(shsurf->resource, |
| 3319 | shsurf->popup.serial); |
| 3320 | } |
| 3321 | |
| 3322 | static void |
Kristian Høgsberg | 02bbabb | 2013-05-06 22:15:05 -0400 | [diff] [blame] | 3323 | popup_grab_end(struct weston_pointer *pointer) |
Kristian Høgsberg | 57e0907 | 2012-10-30 14:07:27 -0400 | [diff] [blame] | 3324 | { |
Kristian Høgsberg | 02bbabb | 2013-05-06 22:15:05 -0400 | [diff] [blame] | 3325 | struct weston_pointer_grab *grab = pointer->grab; |
Giulio Camuffo | 5085a75 | 2013-03-25 21:42:45 +0100 | [diff] [blame] | 3326 | struct shell_seat *shseat = |
| 3327 | container_of(grab, struct shell_seat, popup_grab.grab); |
| 3328 | struct shell_surface *shsurf; |
Jonas Ådahl | c2b1011 | 2015-02-13 14:01:53 +0800 | [diff] [blame] | 3329 | struct shell_surface *next; |
Kristian Høgsberg | 57e0907 | 2012-10-30 14:07:27 -0400 | [diff] [blame] | 3330 | |
| 3331 | if (pointer->grab->interface == &popup_grab_interface) { |
Kristian Høgsberg | 02bbabb | 2013-05-06 22:15:05 -0400 | [diff] [blame] | 3332 | weston_pointer_end_grab(grab->pointer); |
Giulio Camuffo | 5085a75 | 2013-03-25 21:42:45 +0100 | [diff] [blame] | 3333 | shseat->popup_grab.client = NULL; |
Philipp Brüschweiler | 63e7be6 | 2013-04-15 21:09:54 +0200 | [diff] [blame] | 3334 | shseat->popup_grab.grab.interface = NULL; |
| 3335 | assert(!wl_list_empty(&shseat->popup_grab.surfaces_list)); |
Giulio Camuffo | 5085a75 | 2013-03-25 21:42:45 +0100 | [diff] [blame] | 3336 | /* Send the popup_done event to all the popups open */ |
Jonas Ådahl | c2b1011 | 2015-02-13 14:01:53 +0800 | [diff] [blame] | 3337 | wl_list_for_each_safe(shsurf, next, |
| 3338 | &shseat->popup_grab.surfaces_list, |
| 3339 | popup.grab_link) { |
Rafael Antognolli | e2a3455 | 2013-12-03 15:35:45 -0200 | [diff] [blame] | 3340 | shell_surface_send_popup_done(shsurf); |
Giulio Camuffo | 5085a75 | 2013-03-25 21:42:45 +0100 | [diff] [blame] | 3341 | shsurf->popup.shseat = NULL; |
Jonas Ådahl | c2b1011 | 2015-02-13 14:01:53 +0800 | [diff] [blame] | 3342 | wl_list_init(&shsurf->popup.grab_link); |
Giulio Camuffo | 5085a75 | 2013-03-25 21:42:45 +0100 | [diff] [blame] | 3343 | } |
Giulio Camuffo | 5085a75 | 2013-03-25 21:42:45 +0100 | [diff] [blame] | 3344 | wl_list_init(&shseat->popup_grab.surfaces_list); |
| 3345 | } |
| 3346 | } |
| 3347 | |
| 3348 | static void |
Jonny Lamb | 76cf1fe | 2014-08-20 11:27:10 +0200 | [diff] [blame] | 3349 | touch_popup_grab_end(struct weston_touch *touch) |
| 3350 | { |
| 3351 | struct weston_touch_grab *grab = touch->grab; |
| 3352 | struct shell_seat *shseat = |
| 3353 | container_of(grab, struct shell_seat, popup_grab.touch_grab); |
| 3354 | struct shell_surface *shsurf; |
Jonas Ådahl | c2b1011 | 2015-02-13 14:01:53 +0800 | [diff] [blame] | 3355 | struct shell_surface *next; |
Jonny Lamb | 76cf1fe | 2014-08-20 11:27:10 +0200 | [diff] [blame] | 3356 | |
| 3357 | if (touch->grab->interface == &touch_popup_grab_interface) { |
| 3358 | weston_touch_end_grab(grab->touch); |
| 3359 | shseat->popup_grab.client = NULL; |
| 3360 | shseat->popup_grab.touch_grab.interface = NULL; |
| 3361 | assert(!wl_list_empty(&shseat->popup_grab.surfaces_list)); |
| 3362 | /* Send the popup_done event to all the popups open */ |
Jonas Ådahl | c2b1011 | 2015-02-13 14:01:53 +0800 | [diff] [blame] | 3363 | wl_list_for_each_safe(shsurf, next, |
| 3364 | &shseat->popup_grab.surfaces_list, |
| 3365 | popup.grab_link) { |
Jonny Lamb | 76cf1fe | 2014-08-20 11:27:10 +0200 | [diff] [blame] | 3366 | shell_surface_send_popup_done(shsurf); |
| 3367 | shsurf->popup.shseat = NULL; |
Jonas Ådahl | c2b1011 | 2015-02-13 14:01:53 +0800 | [diff] [blame] | 3368 | wl_list_init(&shsurf->popup.grab_link); |
Jonny Lamb | 76cf1fe | 2014-08-20 11:27:10 +0200 | [diff] [blame] | 3369 | } |
Jonny Lamb | 76cf1fe | 2014-08-20 11:27:10 +0200 | [diff] [blame] | 3370 | wl_list_init(&shseat->popup_grab.surfaces_list); |
| 3371 | } |
| 3372 | } |
| 3373 | |
| 3374 | static void |
Jonas Ådahl | 01193ae | 2015-02-13 14:01:54 +0800 | [diff] [blame^] | 3375 | add_popup_grab(struct shell_surface *shsurf, |
| 3376 | struct shell_seat *shseat, |
| 3377 | int32_t type) |
Giulio Camuffo | 5085a75 | 2013-03-25 21:42:45 +0100 | [diff] [blame] | 3378 | { |
Kristian Høgsberg | e314875 | 2013-05-06 23:19:49 -0400 | [diff] [blame] | 3379 | struct weston_seat *seat = shseat->seat; |
Giulio Camuffo | 5085a75 | 2013-03-25 21:42:45 +0100 | [diff] [blame] | 3380 | |
| 3381 | if (wl_list_empty(&shseat->popup_grab.surfaces_list)) { |
Jonny Lamb | 76cf1fe | 2014-08-20 11:27:10 +0200 | [diff] [blame] | 3382 | shseat->popup_grab.type = type; |
Jonas Ådahl | 01193ae | 2015-02-13 14:01:54 +0800 | [diff] [blame^] | 3383 | shseat->popup_grab.client = |
| 3384 | wl_resource_get_client(shsurf->resource); |
Jonny Lamb | 76cf1fe | 2014-08-20 11:27:10 +0200 | [diff] [blame] | 3385 | |
| 3386 | if (type == POINTER) { |
Jonas Ådahl | 01193ae | 2015-02-13 14:01:54 +0800 | [diff] [blame^] | 3387 | shseat->popup_grab.grab.interface = |
| 3388 | &popup_grab_interface; |
| 3389 | |
| 3390 | /* We must make sure here that this popup was opened |
| 3391 | * after a mouse press, and not just by moving around |
| 3392 | * with other popups already open. */ |
Jonny Lamb | 76cf1fe | 2014-08-20 11:27:10 +0200 | [diff] [blame] | 3393 | if (shseat->seat->pointer->button_count > 0) |
| 3394 | shseat->popup_grab.initial_up = 0; |
| 3395 | } else if (type == TOUCH) { |
Jonas Ådahl | 01193ae | 2015-02-13 14:01:54 +0800 | [diff] [blame^] | 3396 | shseat->popup_grab.touch_grab.interface = |
| 3397 | &touch_popup_grab_interface; |
Jonny Lamb | 76cf1fe | 2014-08-20 11:27:10 +0200 | [diff] [blame] | 3398 | } |
Giulio Camuffo | 5085a75 | 2013-03-25 21:42:45 +0100 | [diff] [blame] | 3399 | |
Jonas Ådahl | 01193ae | 2015-02-13 14:01:54 +0800 | [diff] [blame^] | 3400 | wl_list_insert(&shseat->popup_grab.surfaces_list, |
| 3401 | &shsurf->popup.grab_link); |
Jonny Lamb | 76cf1fe | 2014-08-20 11:27:10 +0200 | [diff] [blame] | 3402 | |
Jonas Ådahl | 01193ae | 2015-02-13 14:01:54 +0800 | [diff] [blame^] | 3403 | if (type == POINTER) { |
| 3404 | weston_pointer_start_grab(seat->pointer, |
| 3405 | &shseat->popup_grab.grab); |
| 3406 | } else if (type == TOUCH) { |
| 3407 | weston_touch_start_grab(seat->touch, |
| 3408 | &shseat->popup_grab.touch_grab); |
| 3409 | } |
Rob Bradford | dfe3105 | 2013-06-26 19:49:11 +0100 | [diff] [blame] | 3410 | } else { |
Jonas Ådahl | 01193ae | 2015-02-13 14:01:54 +0800 | [diff] [blame^] | 3411 | wl_list_insert(&shseat->popup_grab.surfaces_list, |
| 3412 | &shsurf->popup.grab_link); |
Giulio Camuffo | 5085a75 | 2013-03-25 21:42:45 +0100 | [diff] [blame] | 3413 | } |
Giulio Camuffo | 5085a75 | 2013-03-25 21:42:45 +0100 | [diff] [blame] | 3414 | } |
| 3415 | |
| 3416 | static void |
| 3417 | remove_popup_grab(struct shell_surface *shsurf) |
| 3418 | { |
| 3419 | struct shell_seat *shseat = shsurf->popup.shseat; |
| 3420 | |
| 3421 | wl_list_remove(&shsurf->popup.grab_link); |
| 3422 | wl_list_init(&shsurf->popup.grab_link); |
| 3423 | if (wl_list_empty(&shseat->popup_grab.surfaces_list)) { |
Jonny Lamb | 76cf1fe | 2014-08-20 11:27:10 +0200 | [diff] [blame] | 3424 | if (shseat->popup_grab.type == POINTER) { |
| 3425 | weston_pointer_end_grab(shseat->popup_grab.grab.pointer); |
| 3426 | shseat->popup_grab.grab.interface = NULL; |
| 3427 | } else if (shseat->popup_grab.type == TOUCH) { |
| 3428 | weston_touch_end_grab(shseat->popup_grab.touch_grab.touch); |
| 3429 | shseat->popup_grab.touch_grab.interface = NULL; |
| 3430 | } |
Kristian Høgsberg | 57e0907 | 2012-10-30 14:07:27 -0400 | [diff] [blame] | 3431 | } |
| 3432 | } |
| 3433 | |
| 3434 | static void |
Kristian Høgsberg | 3730f36 | 2012-04-13 12:40:07 -0400 | [diff] [blame] | 3435 | shell_map_popup(struct shell_surface *shsurf) |
Kristian Høgsberg | b3cca0a | 2012-01-04 22:19:14 -0500 | [diff] [blame] | 3436 | { |
Giulio Camuffo | 5085a75 | 2013-03-25 21:42:45 +0100 | [diff] [blame] | 3437 | struct shell_seat *shseat = shsurf->popup.shseat; |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 3438 | struct weston_view *parent_view = get_default_view(shsurf->parent); |
Kristian Høgsberg | b3cca0a | 2012-01-04 22:19:14 -0500 | [diff] [blame] | 3439 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 3440 | shsurf->surface->output = parent_view->output; |
| 3441 | shsurf->view->output = parent_view->output; |
Kristian Høgsberg | b3cca0a | 2012-01-04 22:19:14 -0500 | [diff] [blame] | 3442 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 3443 | weston_view_set_transform_parent(shsurf->view, parent_view); |
| 3444 | weston_view_set_position(shsurf->view, shsurf->popup.x, shsurf->popup.y); |
| 3445 | weston_view_update_transform(shsurf->view); |
Kristian Høgsberg | b3cca0a | 2012-01-04 22:19:14 -0500 | [diff] [blame] | 3446 | |
Jonny Lamb | e84ab4e | 2014-08-06 11:50:12 +0200 | [diff] [blame] | 3447 | if (shseat->seat->pointer && |
| 3448 | shseat->seat->pointer->grab_serial == shsurf->popup.serial) { |
Jonny Lamb | 76cf1fe | 2014-08-20 11:27:10 +0200 | [diff] [blame] | 3449 | add_popup_grab(shsurf, shseat, POINTER); |
| 3450 | } else if (shseat->seat->touch && |
| 3451 | shseat->seat->touch->grab_serial == shsurf->popup.serial) { |
| 3452 | add_popup_grab(shsurf, shseat, TOUCH); |
Kristian Høgsberg | 3730f36 | 2012-04-13 12:40:07 -0400 | [diff] [blame] | 3453 | } else { |
Rafael Antognolli | e2a3455 | 2013-12-03 15:35:45 -0200 | [diff] [blame] | 3454 | shell_surface_send_popup_done(shsurf); |
Giulio Camuffo | 5085a75 | 2013-03-25 21:42:45 +0100 | [diff] [blame] | 3455 | shseat->popup_grab.client = NULL; |
Kristian Høgsberg | 3730f36 | 2012-04-13 12:40:07 -0400 | [diff] [blame] | 3456 | } |
Kristian Høgsberg | b3cca0a | 2012-01-04 22:19:14 -0500 | [diff] [blame] | 3457 | } |
| 3458 | |
Pekka Paalanen | 9d1613e | 2011-11-25 12:09:16 +0200 | [diff] [blame] | 3459 | static const struct wl_shell_surface_interface shell_surface_implementation = { |
Scott Moreau | ff1db4a | 2012-04-17 19:06:18 -0600 | [diff] [blame] | 3460 | shell_surface_pong, |
Pekka Paalanen | 9d1613e | 2011-11-25 12:09:16 +0200 | [diff] [blame] | 3461 | shell_surface_move, |
| 3462 | shell_surface_resize, |
| 3463 | shell_surface_set_toplevel, |
| 3464 | shell_surface_set_transient, |
Kristian Høgsberg | b3cca0a | 2012-01-04 22:19:14 -0500 | [diff] [blame] | 3465 | shell_surface_set_fullscreen, |
Juan Zhao | 96879df | 2012-02-07 08:45:41 +0800 | [diff] [blame] | 3466 | shell_surface_set_popup, |
Kristian Høgsberg | e7afd91 | 2012-05-02 09:47:44 -0400 | [diff] [blame] | 3467 | shell_surface_set_maximized, |
| 3468 | shell_surface_set_title, |
| 3469 | shell_surface_set_class |
Pekka Paalanen | 9d1613e | 2011-11-25 12:09:16 +0200 | [diff] [blame] | 3470 | }; |
| 3471 | |
| 3472 | static void |
Tiago Vignatti | bc052c9 | 2012-04-19 16:18:18 +0300 | [diff] [blame] | 3473 | destroy_shell_surface(struct shell_surface *shsurf) |
Pekka Paalanen | 9d1613e | 2011-11-25 12:09:16 +0200 | [diff] [blame] | 3474 | { |
Kristian Høgsberg | 9046d24 | 2014-01-10 00:25:30 -0800 | [diff] [blame] | 3475 | struct shell_surface *child, *next; |
| 3476 | |
Jason Ekstrand | 651f00e | 2013-06-14 10:07:54 -0500 | [diff] [blame] | 3477 | wl_signal_emit(&shsurf->destroy_signal, shsurf); |
| 3478 | |
Giulio Camuffo | 5085a75 | 2013-03-25 21:42:45 +0100 | [diff] [blame] | 3479 | if (!wl_list_empty(&shsurf->popup.grab_link)) { |
| 3480 | remove_popup_grab(shsurf); |
| 3481 | } |
Kristian Høgsberg | b3cca0a | 2012-01-04 22:19:14 -0500 | [diff] [blame] | 3482 | |
Alex Wu | bd3354b | 2012-04-17 17:20:49 +0800 | [diff] [blame] | 3483 | if (shsurf->fullscreen.type == WL_SHELL_SURFACE_FULLSCREEN_METHOD_DRIVER && |
Alexander Larsson | f82b6ca | 2013-05-28 16:23:39 +0200 | [diff] [blame] | 3484 | shell_surface_is_top_fullscreen(shsurf)) |
| 3485 | restore_output_mode (shsurf->fullscreen_output); |
Pekka Paalanen | 9d1613e | 2011-11-25 12:09:16 +0200 | [diff] [blame] | 3486 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 3487 | if (shsurf->fullscreen.black_view) |
| 3488 | weston_surface_destroy(shsurf->fullscreen.black_view->surface); |
Alex Wu | aa08e2d | 2012-03-05 11:01:40 +0800 | [diff] [blame] | 3489 | |
Alex Wu | bd3354b | 2012-04-17 17:20:49 +0800 | [diff] [blame] | 3490 | /* As destroy_resource() use wl_list_for_each_safe(), |
| 3491 | * we can always remove the listener. |
| 3492 | */ |
| 3493 | wl_list_remove(&shsurf->surface_destroy_listener.link); |
| 3494 | shsurf->surface->configure = NULL; |
Pekka Paalanen | 8274d90 | 2014-08-06 19:36:51 +0300 | [diff] [blame] | 3495 | weston_surface_set_label_func(shsurf->surface, NULL); |
Scott Moreau | 976a050 | 2013-03-07 10:15:17 -0700 | [diff] [blame] | 3496 | free(shsurf->title); |
Alex Wu | bd3354b | 2012-04-17 17:20:49 +0800 | [diff] [blame] | 3497 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 3498 | weston_view_destroy(shsurf->view); |
| 3499 | |
Philip Withnall | 648a4dd | 2013-11-25 18:01:44 +0000 | [diff] [blame] | 3500 | wl_list_remove(&shsurf->children_link); |
Emilio Pozuelo Monfort | adaa20c | 2014-01-28 13:54:16 +0100 | [diff] [blame] | 3501 | wl_list_for_each_safe(child, next, &shsurf->children_list, children_link) |
| 3502 | shell_surface_set_parent(child, NULL); |
Philip Withnall | 648a4dd | 2013-11-25 18:01:44 +0000 | [diff] [blame] | 3503 | |
Pekka Paalanen | 9d1613e | 2011-11-25 12:09:16 +0200 | [diff] [blame] | 3504 | wl_list_remove(&shsurf->link); |
| 3505 | free(shsurf); |
| 3506 | } |
| 3507 | |
| 3508 | static void |
Tiago Vignatti | bc052c9 | 2012-04-19 16:18:18 +0300 | [diff] [blame] | 3509 | shell_destroy_shell_surface(struct wl_resource *resource) |
| 3510 | { |
Jason Ekstrand | 651f00e | 2013-06-14 10:07:54 -0500 | [diff] [blame] | 3511 | struct shell_surface *shsurf = wl_resource_get_user_data(resource); |
Tiago Vignatti | bc052c9 | 2012-04-19 16:18:18 +0300 | [diff] [blame] | 3512 | |
Bryan Cain | a46b946 | 2014-04-04 17:41:24 -0500 | [diff] [blame] | 3513 | if (!wl_list_empty(&shsurf->popup.grab_link)) |
| 3514 | remove_popup_grab(shsurf); |
Kristian Høgsberg | 160fe75 | 2014-03-11 10:19:10 -0700 | [diff] [blame] | 3515 | shsurf->resource = NULL; |
Tiago Vignatti | bc052c9 | 2012-04-19 16:18:18 +0300 | [diff] [blame] | 3516 | } |
| 3517 | |
| 3518 | static void |
Kristian Høgsberg | 27e3052 | 2012-04-11 23:18:23 -0400 | [diff] [blame] | 3519 | shell_handle_surface_destroy(struct wl_listener *listener, void *data) |
Pekka Paalanen | 9d1613e | 2011-11-25 12:09:16 +0200 | [diff] [blame] | 3520 | { |
| 3521 | struct shell_surface *shsurf = container_of(listener, |
| 3522 | struct shell_surface, |
| 3523 | surface_destroy_listener); |
| 3524 | |
Jason Ekstrand | 651f00e | 2013-06-14 10:07:54 -0500 | [diff] [blame] | 3525 | if (shsurf->resource) |
| 3526 | wl_resource_destroy(shsurf->resource); |
Ander Conselvan de Oliveira | 15f9a26 | 2014-04-29 17:54:02 +0300 | [diff] [blame] | 3527 | |
| 3528 | destroy_shell_surface(shsurf); |
Pekka Paalanen | 9d1613e | 2011-11-25 12:09:16 +0200 | [diff] [blame] | 3529 | } |
| 3530 | |
Kristian Høgsberg | d813445 | 2012-06-21 12:49:02 -0400 | [diff] [blame] | 3531 | static void |
Kristian Høgsberg | 160fe75 | 2014-03-11 10:19:10 -0700 | [diff] [blame] | 3532 | fade_out_done(struct weston_view_animation *animation, void *data) |
| 3533 | { |
| 3534 | struct shell_surface *shsurf = data; |
| 3535 | |
| 3536 | weston_surface_destroy(shsurf->surface); |
| 3537 | } |
| 3538 | |
| 3539 | static void |
| 3540 | handle_resource_destroy(struct wl_listener *listener, void *data) |
| 3541 | { |
| 3542 | struct shell_surface *shsurf = |
| 3543 | container_of(listener, struct shell_surface, |
| 3544 | resource_destroy_listener); |
| 3545 | |
Ander Conselvan de Oliveira | 15f9a26 | 2014-04-29 17:54:02 +0300 | [diff] [blame] | 3546 | if (!weston_surface_is_mapped(shsurf->surface)) |
| 3547 | return; |
| 3548 | |
Kristian Høgsberg | 160fe75 | 2014-03-11 10:19:10 -0700 | [diff] [blame] | 3549 | shsurf->surface->ref_count++; |
| 3550 | |
| 3551 | pixman_region32_fini(&shsurf->surface->pending.input); |
| 3552 | pixman_region32_init(&shsurf->surface->pending.input); |
| 3553 | pixman_region32_fini(&shsurf->surface->input); |
| 3554 | pixman_region32_init(&shsurf->surface->input); |
Jonny Lamb | f322f8e | 2014-08-12 15:13:30 +0200 | [diff] [blame] | 3555 | if (shsurf->shell->win_close_animation_type == ANIMATION_FADE) { |
| 3556 | weston_fade_run(shsurf->view, 1.0, 0.0, 300.0, |
| 3557 | fade_out_done, shsurf); |
| 3558 | } else { |
| 3559 | weston_surface_destroy(shsurf->surface); |
| 3560 | } |
Kristian Høgsberg | 160fe75 | 2014-03-11 10:19:10 -0700 | [diff] [blame] | 3561 | } |
| 3562 | |
| 3563 | static void |
Jason Ekstrand | 918f2dd | 2013-12-02 21:01:53 -0600 | [diff] [blame] | 3564 | shell_surface_configure(struct weston_surface *, int32_t, int32_t); |
Kristian Høgsberg | d813445 | 2012-06-21 12:49:02 -0400 | [diff] [blame] | 3565 | |
Kristian Høgsberg | 1ef2313 | 2013-12-04 00:20:01 -0800 | [diff] [blame] | 3566 | struct shell_surface * |
Kristian Høgsberg | 8334bc1 | 2012-01-03 10:29:47 -0500 | [diff] [blame] | 3567 | get_shell_surface(struct weston_surface *surface) |
Pekka Paalanen | ec2b32f | 2011-11-28 15:12:34 +0200 | [diff] [blame] | 3568 | { |
Kristian Høgsberg | d813445 | 2012-06-21 12:49:02 -0400 | [diff] [blame] | 3569 | if (surface->configure == shell_surface_configure) |
Giulio Camuffo | 7fe01b1 | 2013-03-28 18:02:42 +0100 | [diff] [blame] | 3570 | return surface->configure_private; |
Kristian Høgsberg | d813445 | 2012-06-21 12:49:02 -0400 | [diff] [blame] | 3571 | else |
| 3572 | return NULL; |
Pekka Paalanen | ec2b32f | 2011-11-28 15:12:34 +0200 | [diff] [blame] | 3573 | } |
| 3574 | |
Rafael Antognolli | e2a3455 | 2013-12-03 15:35:45 -0200 | [diff] [blame] | 3575 | static struct shell_surface * |
Jason Ekstrand | 9e9512f | 2014-04-16 21:12:10 -0500 | [diff] [blame] | 3576 | create_common_surface(struct shell_client *owner, void *shell, |
| 3577 | struct weston_surface *surface, |
Rafael Antognolli | e2a3455 | 2013-12-03 15:35:45 -0200 | [diff] [blame] | 3578 | const struct weston_shell_client *client) |
Pekka Paalanen | 9d1613e | 2011-11-25 12:09:16 +0200 | [diff] [blame] | 3579 | { |
Pekka Paalanen | 9d1613e | 2011-11-25 12:09:16 +0200 | [diff] [blame] | 3580 | struct shell_surface *shsurf; |
| 3581 | |
Pekka Paalanen | 50b6747 | 2014-10-01 15:02:41 +0300 | [diff] [blame] | 3582 | assert(surface->configure == NULL); |
Ander Conselvan de Oliveira | 093bfa3 | 2012-03-27 17:36:41 +0300 | [diff] [blame] | 3583 | |
Pekka Paalanen | 9d1613e | 2011-11-25 12:09:16 +0200 | [diff] [blame] | 3584 | shsurf = calloc(1, sizeof *shsurf); |
| 3585 | if (!shsurf) { |
Martin Minarik | 6d11836 | 2012-06-07 18:01:59 +0200 | [diff] [blame] | 3586 | weston_log("no memory to allocate shell surface\n"); |
Kristian Høgsberg | 45ba869 | 2012-05-21 14:27:33 -0400 | [diff] [blame] | 3587 | return NULL; |
Pekka Paalanen | 9d1613e | 2011-11-25 12:09:16 +0200 | [diff] [blame] | 3588 | } |
| 3589 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 3590 | shsurf->view = weston_view_create(surface); |
| 3591 | if (!shsurf->view) { |
| 3592 | weston_log("no memory to allocate shell surface\n"); |
| 3593 | free(shsurf); |
| 3594 | return NULL; |
| 3595 | } |
| 3596 | |
Ander Conselvan de Oliveira | 093bfa3 | 2012-03-27 17:36:41 +0300 | [diff] [blame] | 3597 | surface->configure = shell_surface_configure; |
Giulio Camuffo | 7fe01b1 | 2013-03-28 18:02:42 +0100 | [diff] [blame] | 3598 | surface->configure_private = shsurf; |
Pekka Paalanen | 8274d90 | 2014-08-06 19:36:51 +0300 | [diff] [blame] | 3599 | weston_surface_set_label_func(surface, shell_surface_get_label); |
Ander Conselvan de Oliveira | 093bfa3 | 2012-03-27 17:36:41 +0300 | [diff] [blame] | 3600 | |
Kristian Høgsberg | 160fe75 | 2014-03-11 10:19:10 -0700 | [diff] [blame] | 3601 | shsurf->resource_destroy_listener.notify = handle_resource_destroy; |
| 3602 | wl_resource_add_destroy_listener(surface->resource, |
| 3603 | &shsurf->resource_destroy_listener); |
Jason Ekstrand | 9e9512f | 2014-04-16 21:12:10 -0500 | [diff] [blame] | 3604 | shsurf->owner = owner; |
Kristian Høgsberg | 160fe75 | 2014-03-11 10:19:10 -0700 | [diff] [blame] | 3605 | |
Tiago Vignatti | bc052c9 | 2012-04-19 16:18:18 +0300 | [diff] [blame] | 3606 | shsurf->shell = (struct desktop_shell *) shell; |
Scott Moreau | ff1db4a | 2012-04-17 19:06:18 -0600 | [diff] [blame] | 3607 | shsurf->unresponsive = 0; |
Alex Wu | 4539b08 | 2012-03-01 12:57:46 +0800 | [diff] [blame] | 3608 | shsurf->saved_position_valid = false; |
Rafael Antognolli | 3c4e3f7 | 2013-12-03 15:35:46 -0200 | [diff] [blame] | 3609 | shsurf->saved_size_valid = false; |
Alex Wu | 7bcb8bd | 2012-04-27 09:07:24 +0800 | [diff] [blame] | 3610 | shsurf->saved_rotation_valid = false; |
Pekka Paalanen | 9d1613e | 2011-11-25 12:09:16 +0200 | [diff] [blame] | 3611 | shsurf->surface = surface; |
Alex Wu | 4539b08 | 2012-03-01 12:57:46 +0800 | [diff] [blame] | 3612 | shsurf->fullscreen.type = WL_SHELL_SURFACE_FULLSCREEN_METHOD_DEFAULT; |
| 3613 | shsurf->fullscreen.framerate = 0; |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 3614 | shsurf->fullscreen.black_view = NULL; |
Alex Wu | 4539b08 | 2012-03-01 12:57:46 +0800 | [diff] [blame] | 3615 | wl_list_init(&shsurf->fullscreen.transform.link); |
| 3616 | |
Jasper St. Pierre | 9aa8ce6 | 2014-04-11 16:18:54 -0700 | [diff] [blame] | 3617 | shsurf->output = get_default_output(shsurf->shell->compositor); |
| 3618 | |
Jason Ekstrand | 651f00e | 2013-06-14 10:07:54 -0500 | [diff] [blame] | 3619 | wl_signal_init(&shsurf->destroy_signal); |
Kristian Høgsberg | 27e3052 | 2012-04-11 23:18:23 -0400 | [diff] [blame] | 3620 | shsurf->surface_destroy_listener.notify = shell_handle_surface_destroy; |
Jason Ekstrand | 26ed73c | 2013-06-06 22:34:41 -0500 | [diff] [blame] | 3621 | wl_signal_add(&surface->destroy_signal, |
Kristian Høgsberg | 27e3052 | 2012-04-11 23:18:23 -0400 | [diff] [blame] | 3622 | &shsurf->surface_destroy_listener); |
Pekka Paalanen | 9d1613e | 2011-11-25 12:09:16 +0200 | [diff] [blame] | 3623 | |
| 3624 | /* init link so its safe to always remove it in destroy_shell_surface */ |
| 3625 | wl_list_init(&shsurf->link); |
Giulio Camuffo | 5085a75 | 2013-03-25 21:42:45 +0100 | [diff] [blame] | 3626 | wl_list_init(&shsurf->popup.grab_link); |
Pekka Paalanen | 9d1613e | 2011-11-25 12:09:16 +0200 | [diff] [blame] | 3627 | |
Pekka Paalanen | 460099f | 2012-01-20 16:48:25 +0200 | [diff] [blame] | 3628 | /* empty when not in use */ |
| 3629 | wl_list_init(&shsurf->rotation.transform.link); |
Kristian Høgsberg | 765e27b | 2012-01-27 13:36:13 -0500 | [diff] [blame] | 3630 | weston_matrix_init(&shsurf->rotation.rotation); |
Pekka Paalanen | 460099f | 2012-01-20 16:48:25 +0200 | [diff] [blame] | 3631 | |
Jonas Ådahl | 62fcd04 | 2012-06-13 00:01:23 +0200 | [diff] [blame] | 3632 | wl_list_init(&shsurf->workspace_transform.link); |
| 3633 | |
Philip Withnall | 648a4dd | 2013-11-25 18:01:44 +0000 | [diff] [blame] | 3634 | wl_list_init(&shsurf->children_link); |
| 3635 | wl_list_init(&shsurf->children_list); |
| 3636 | shsurf->parent = NULL; |
| 3637 | |
Pekka Paalanen | b502654 | 2014-11-12 15:09:24 +0200 | [diff] [blame] | 3638 | set_type(shsurf, SHELL_SURFACE_NONE); |
Pekka Paalanen | 9d1613e | 2011-11-25 12:09:16 +0200 | [diff] [blame] | 3639 | |
Kristian Høgsberg | a61ca06 | 2012-05-22 16:05:52 -0400 | [diff] [blame] | 3640 | shsurf->client = client; |
| 3641 | |
Kristian Høgsberg | 45ba869 | 2012-05-21 14:27:33 -0400 | [diff] [blame] | 3642 | return shsurf; |
Tiago Vignatti | bc052c9 | 2012-04-19 16:18:18 +0300 | [diff] [blame] | 3643 | } |
| 3644 | |
Rafael Antognolli | e2a3455 | 2013-12-03 15:35:45 -0200 | [diff] [blame] | 3645 | static struct shell_surface * |
| 3646 | create_shell_surface(void *shell, struct weston_surface *surface, |
| 3647 | const struct weston_shell_client *client) |
| 3648 | { |
Jason Ekstrand | 9e9512f | 2014-04-16 21:12:10 -0500 | [diff] [blame] | 3649 | return create_common_surface(NULL, shell, surface, client); |
Rafael Antognolli | e2a3455 | 2013-12-03 15:35:45 -0200 | [diff] [blame] | 3650 | } |
| 3651 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 3652 | static struct weston_view * |
| 3653 | get_primary_view(void *shell, struct shell_surface *shsurf) |
| 3654 | { |
| 3655 | return shsurf->view; |
| 3656 | } |
| 3657 | |
Tiago Vignatti | bc052c9 | 2012-04-19 16:18:18 +0300 | [diff] [blame] | 3658 | static void |
| 3659 | shell_get_shell_surface(struct wl_client *client, |
| 3660 | struct wl_resource *resource, |
| 3661 | uint32_t id, |
| 3662 | struct wl_resource *surface_resource) |
| 3663 | { |
Jason Ekstrand | 0f2ef7e | 2013-06-14 10:07:53 -0500 | [diff] [blame] | 3664 | struct weston_surface *surface = |
| 3665 | wl_resource_get_user_data(surface_resource); |
Jason Ekstrand | 9e9512f | 2014-04-16 21:12:10 -0500 | [diff] [blame] | 3666 | struct shell_client *sc = wl_resource_get_user_data(resource); |
| 3667 | struct desktop_shell *shell = sc->shell; |
Tiago Vignatti | bc052c9 | 2012-04-19 16:18:18 +0300 | [diff] [blame] | 3668 | struct shell_surface *shsurf; |
| 3669 | |
Pekka Paalanen | 50b6747 | 2014-10-01 15:02:41 +0300 | [diff] [blame] | 3670 | if (weston_surface_set_role(surface, "wl_shell_surface", |
| 3671 | resource, WL_SHELL_ERROR_ROLE) < 0) |
Tiago Vignatti | bc052c9 | 2012-04-19 16:18:18 +0300 | [diff] [blame] | 3672 | return; |
Tiago Vignatti | bc052c9 | 2012-04-19 16:18:18 +0300 | [diff] [blame] | 3673 | |
Jason Ekstrand | 9e9512f | 2014-04-16 21:12:10 -0500 | [diff] [blame] | 3674 | shsurf = create_common_surface(sc, shell, surface, &shell_client); |
Kristian Høgsberg | 9540ea6 | 2012-05-21 14:28:57 -0400 | [diff] [blame] | 3675 | if (!shsurf) { |
Pekka Paalanen | 50b6747 | 2014-10-01 15:02:41 +0300 | [diff] [blame] | 3676 | wl_resource_post_no_memory(surface_resource); |
Kristian Høgsberg | 9540ea6 | 2012-05-21 14:28:57 -0400 | [diff] [blame] | 3677 | return; |
| 3678 | } |
Tiago Vignatti | bc052c9 | 2012-04-19 16:18:18 +0300 | [diff] [blame] | 3679 | |
Jason Ekstrand | a85118c | 2013-06-27 20:17:02 -0500 | [diff] [blame] | 3680 | shsurf->resource = |
| 3681 | wl_resource_create(client, |
| 3682 | &wl_shell_surface_interface, 1, id); |
| 3683 | wl_resource_set_implementation(shsurf->resource, |
| 3684 | &shell_surface_implementation, |
| 3685 | shsurf, shell_destroy_shell_surface); |
Pekka Paalanen | 9d1613e | 2011-11-25 12:09:16 +0200 | [diff] [blame] | 3686 | } |
| 3687 | |
Rafael Antognolli | e2a3455 | 2013-12-03 15:35:45 -0200 | [diff] [blame] | 3688 | static bool |
| 3689 | shell_surface_is_wl_shell_surface(struct shell_surface *shsurf) |
| 3690 | { |
Kristian Høgsberg | 0b7d995 | 2014-02-03 15:50:38 -0800 | [diff] [blame] | 3691 | /* A shell surface without a resource is created from xwayland |
| 3692 | * and is considered a wl_shell surface for now. */ |
| 3693 | |
| 3694 | return shsurf->resource == NULL || |
| 3695 | wl_resource_instance_of(shsurf->resource, |
| 3696 | &wl_shell_surface_interface, |
| 3697 | &shell_surface_implementation); |
Rafael Antognolli | e2a3455 | 2013-12-03 15:35:45 -0200 | [diff] [blame] | 3698 | } |
| 3699 | |
Pekka Paalanen | 9d1613e | 2011-11-25 12:09:16 +0200 | [diff] [blame] | 3700 | static const struct wl_shell_interface shell_implementation = { |
Pekka Paalanen | 4622967 | 2011-11-29 15:49:31 +0200 | [diff] [blame] | 3701 | shell_get_shell_surface |
Kristian Høgsberg | 4cca349 | 2011-01-18 07:53:49 -0500 | [diff] [blame] | 3702 | }; |
| 3703 | |
Rafael Antognolli | e2a3455 | 2013-12-03 15:35:45 -0200 | [diff] [blame] | 3704 | /**************************** |
| 3705 | * xdg-shell implementation */ |
| 3706 | |
| 3707 | static void |
| 3708 | xdg_surface_destroy(struct wl_client *client, |
| 3709 | struct wl_resource *resource) |
| 3710 | { |
| 3711 | wl_resource_destroy(resource); |
| 3712 | } |
| 3713 | |
| 3714 | static void |
Jasper St. Pierre | c815d62 | 2014-04-10 18:37:54 -0700 | [diff] [blame] | 3715 | xdg_surface_set_parent(struct wl_client *client, |
| 3716 | struct wl_resource *resource, |
| 3717 | struct wl_resource *parent_resource) |
Jasper St. Pierre | 63a9c33 | 2014-02-01 18:35:15 -0500 | [diff] [blame] | 3718 | { |
| 3719 | struct shell_surface *shsurf = wl_resource_get_user_data(resource); |
| 3720 | struct weston_surface *parent; |
| 3721 | |
| 3722 | if (parent_resource) |
| 3723 | parent = wl_resource_get_user_data(parent_resource); |
| 3724 | else |
| 3725 | parent = NULL; |
| 3726 | |
| 3727 | shell_surface_set_parent(shsurf, parent); |
| 3728 | } |
| 3729 | |
| 3730 | static void |
Rafael Antognolli | e2a3455 | 2013-12-03 15:35:45 -0200 | [diff] [blame] | 3731 | xdg_surface_set_app_id(struct wl_client *client, |
| 3732 | struct wl_resource *resource, |
| 3733 | const char *app_id) |
| 3734 | { |
| 3735 | struct shell_surface *shsurf = wl_resource_get_user_data(resource); |
| 3736 | |
| 3737 | free(shsurf->class); |
| 3738 | shsurf->class = strdup(app_id); |
Pekka Paalanen | b502654 | 2014-11-12 15:09:24 +0200 | [diff] [blame] | 3739 | shsurf->surface->timeline.force_refresh = 1; |
Rafael Antognolli | e2a3455 | 2013-12-03 15:35:45 -0200 | [diff] [blame] | 3740 | } |
| 3741 | |
| 3742 | static void |
Jasper St. Pierre | 81ff075 | 2014-03-13 11:04:53 -0400 | [diff] [blame] | 3743 | xdg_surface_show_window_menu(struct wl_client *client, |
| 3744 | struct wl_resource *surface_resource, |
| 3745 | struct wl_resource *seat_resource, |
| 3746 | uint32_t serial, |
| 3747 | int32_t x, |
| 3748 | int32_t y) |
| 3749 | { |
| 3750 | /* TODO */ |
| 3751 | } |
| 3752 | |
| 3753 | static void |
Rafael Antognolli | e2a3455 | 2013-12-03 15:35:45 -0200 | [diff] [blame] | 3754 | xdg_surface_set_title(struct wl_client *client, |
| 3755 | struct wl_resource *resource, const char *title) |
| 3756 | { |
| 3757 | struct shell_surface *shsurf = wl_resource_get_user_data(resource); |
| 3758 | |
| 3759 | set_title(shsurf, title); |
| 3760 | } |
| 3761 | |
| 3762 | static void |
| 3763 | xdg_surface_move(struct wl_client *client, struct wl_resource *resource, |
| 3764 | struct wl_resource *seat_resource, uint32_t serial) |
| 3765 | { |
| 3766 | common_surface_move(resource, seat_resource, serial); |
| 3767 | } |
| 3768 | |
| 3769 | static void |
| 3770 | xdg_surface_resize(struct wl_client *client, struct wl_resource *resource, |
| 3771 | struct wl_resource *seat_resource, uint32_t serial, |
| 3772 | uint32_t edges) |
| 3773 | { |
| 3774 | common_surface_resize(resource, seat_resource, serial, edges); |
| 3775 | } |
| 3776 | |
| 3777 | static void |
Jasper St. Pierre | ab2c108 | 2014-04-10 10:41:46 -0700 | [diff] [blame] | 3778 | xdg_surface_ack_configure(struct wl_client *client, |
| 3779 | struct wl_resource *resource, |
| 3780 | uint32_t serial) |
Rafael Antognolli | e2a3455 | 2013-12-03 15:35:45 -0200 | [diff] [blame] | 3781 | { |
| 3782 | struct shell_surface *shsurf = wl_resource_get_user_data(resource); |
| 3783 | |
Jasper St. Pierre | 8c6aa45 | 2014-02-08 18:29:49 -0500 | [diff] [blame] | 3784 | if (shsurf->state_requested) { |
| 3785 | shsurf->next_state = shsurf->requested_state; |
| 3786 | shsurf->state_changed = true; |
| 3787 | shsurf->state_requested = false; |
Rafael Antognolli | 3c4e3f7 | 2013-12-03 15:35:46 -0200 | [diff] [blame] | 3788 | } |
Rafael Antognolli | e2a3455 | 2013-12-03 15:35:45 -0200 | [diff] [blame] | 3789 | } |
| 3790 | |
Manuel Bachmann | 50c87db | 2014-02-26 15:52:13 +0100 | [diff] [blame] | 3791 | static void |
Jasper St. Pierre | ccf48fb | 2014-05-02 10:21:38 -0400 | [diff] [blame] | 3792 | xdg_surface_set_window_geometry(struct wl_client *client, |
| 3793 | struct wl_resource *resource, |
| 3794 | int32_t x, |
| 3795 | int32_t y, |
| 3796 | int32_t width, |
| 3797 | int32_t height) |
| 3798 | { |
| 3799 | struct shell_surface *shsurf = wl_resource_get_user_data(resource); |
| 3800 | |
| 3801 | set_window_geometry(shsurf, x, y, width, height); |
| 3802 | } |
| 3803 | |
| 3804 | static void |
Jasper St. Pierre | ab2c108 | 2014-04-10 10:41:46 -0700 | [diff] [blame] | 3805 | xdg_surface_set_maximized(struct wl_client *client, |
| 3806 | struct wl_resource *resource) |
| 3807 | { |
| 3808 | struct shell_surface *shsurf = wl_resource_get_user_data(resource); |
Marek Chalupa | bfbb64b | 2014-09-08 12:34:20 +0200 | [diff] [blame] | 3809 | struct weston_output *output; |
Jasper St. Pierre | ab2c108 | 2014-04-10 10:41:46 -0700 | [diff] [blame] | 3810 | |
| 3811 | shsurf->state_requested = true; |
| 3812 | shsurf->requested_state.maximized = true; |
Marek Chalupa | bfbb64b | 2014-09-08 12:34:20 +0200 | [diff] [blame] | 3813 | |
| 3814 | if (!weston_surface_is_mapped(shsurf->surface)) |
| 3815 | output = get_focused_output(shsurf->surface->compositor); |
| 3816 | else |
| 3817 | output = shsurf->surface->output; |
| 3818 | |
| 3819 | shell_surface_set_output(shsurf, output); |
Jasper St. Pierre | 9aa8ce6 | 2014-04-11 16:18:54 -0700 | [diff] [blame] | 3820 | send_configure_for_surface(shsurf); |
Jasper St. Pierre | ab2c108 | 2014-04-10 10:41:46 -0700 | [diff] [blame] | 3821 | } |
| 3822 | |
| 3823 | static void |
| 3824 | xdg_surface_unset_maximized(struct wl_client *client, |
| 3825 | struct wl_resource *resource) |
| 3826 | { |
| 3827 | struct shell_surface *shsurf = wl_resource_get_user_data(resource); |
| 3828 | |
| 3829 | shsurf->state_requested = true; |
| 3830 | shsurf->requested_state.maximized = false; |
Jasper St. Pierre | 6458ec3 | 2014-04-11 16:00:31 -0700 | [diff] [blame] | 3831 | send_configure_for_surface(shsurf); |
Jasper St. Pierre | ab2c108 | 2014-04-10 10:41:46 -0700 | [diff] [blame] | 3832 | } |
| 3833 | |
| 3834 | static void |
| 3835 | xdg_surface_set_fullscreen(struct wl_client *client, |
| 3836 | struct wl_resource *resource, |
| 3837 | struct wl_resource *output_resource) |
| 3838 | { |
| 3839 | struct shell_surface *shsurf = wl_resource_get_user_data(resource); |
| 3840 | struct weston_output *output; |
| 3841 | |
| 3842 | shsurf->state_requested = true; |
| 3843 | shsurf->requested_state.fullscreen = true; |
| 3844 | |
| 3845 | if (output_resource) |
| 3846 | output = wl_resource_get_user_data(output_resource); |
| 3847 | else |
| 3848 | output = NULL; |
| 3849 | |
Marek Chalupa | 052917a | 2014-09-02 11:35:12 +0200 | [diff] [blame] | 3850 | /* handle clients launching in fullscreen */ |
| 3851 | if (output == NULL && !weston_surface_is_mapped(shsurf->surface)) { |
| 3852 | /* Set the output to the one that has focus currently. */ |
| 3853 | assert(shsurf->surface); |
| 3854 | output = get_focused_output(shsurf->surface->compositor); |
| 3855 | } |
| 3856 | |
Jasper St. Pierre | 9aa8ce6 | 2014-04-11 16:18:54 -0700 | [diff] [blame] | 3857 | shell_surface_set_output(shsurf, output); |
| 3858 | shsurf->fullscreen_output = shsurf->output; |
Jasper St. Pierre | ab2c108 | 2014-04-10 10:41:46 -0700 | [diff] [blame] | 3859 | |
Jasper St. Pierre | 9aa8ce6 | 2014-04-11 16:18:54 -0700 | [diff] [blame] | 3860 | send_configure_for_surface(shsurf); |
Jasper St. Pierre | ab2c108 | 2014-04-10 10:41:46 -0700 | [diff] [blame] | 3861 | } |
| 3862 | |
| 3863 | static void |
| 3864 | xdg_surface_unset_fullscreen(struct wl_client *client, |
| 3865 | struct wl_resource *resource) |
| 3866 | { |
| 3867 | struct shell_surface *shsurf = wl_resource_get_user_data(resource); |
| 3868 | |
| 3869 | shsurf->state_requested = true; |
| 3870 | shsurf->requested_state.fullscreen = false; |
Jasper St. Pierre | 6458ec3 | 2014-04-11 16:00:31 -0700 | [diff] [blame] | 3871 | send_configure_for_surface(shsurf); |
Jasper St. Pierre | ab2c108 | 2014-04-10 10:41:46 -0700 | [diff] [blame] | 3872 | } |
| 3873 | |
| 3874 | static void |
Manuel Bachmann | 50c87db | 2014-02-26 15:52:13 +0100 | [diff] [blame] | 3875 | xdg_surface_set_minimized(struct wl_client *client, |
| 3876 | struct wl_resource *resource) |
| 3877 | { |
| 3878 | struct shell_surface *shsurf = wl_resource_get_user_data(resource); |
| 3879 | |
| 3880 | if (shsurf->type != SHELL_SURFACE_TOPLEVEL) |
| 3881 | return; |
| 3882 | |
| 3883 | /* apply compositor's own minimization logic (hide) */ |
| 3884 | set_minimized(shsurf->surface, 1); |
| 3885 | } |
| 3886 | |
Rafael Antognolli | e2a3455 | 2013-12-03 15:35:45 -0200 | [diff] [blame] | 3887 | static const struct xdg_surface_interface xdg_surface_implementation = { |
| 3888 | xdg_surface_destroy, |
Jasper St. Pierre | c815d62 | 2014-04-10 18:37:54 -0700 | [diff] [blame] | 3889 | xdg_surface_set_parent, |
Rafael Antognolli | e2a3455 | 2013-12-03 15:35:45 -0200 | [diff] [blame] | 3890 | xdg_surface_set_title, |
| 3891 | xdg_surface_set_app_id, |
Jasper St. Pierre | 81ff075 | 2014-03-13 11:04:53 -0400 | [diff] [blame] | 3892 | xdg_surface_show_window_menu, |
Rafael Antognolli | e2a3455 | 2013-12-03 15:35:45 -0200 | [diff] [blame] | 3893 | xdg_surface_move, |
| 3894 | xdg_surface_resize, |
Jasper St. Pierre | ab2c108 | 2014-04-10 10:41:46 -0700 | [diff] [blame] | 3895 | xdg_surface_ack_configure, |
Jasper St. Pierre | ccf48fb | 2014-05-02 10:21:38 -0400 | [diff] [blame] | 3896 | xdg_surface_set_window_geometry, |
Jasper St. Pierre | ab2c108 | 2014-04-10 10:41:46 -0700 | [diff] [blame] | 3897 | xdg_surface_set_maximized, |
| 3898 | xdg_surface_unset_maximized, |
| 3899 | xdg_surface_set_fullscreen, |
| 3900 | xdg_surface_unset_fullscreen, |
| 3901 | xdg_surface_set_minimized, |
Rafael Antognolli | e2a3455 | 2013-12-03 15:35:45 -0200 | [diff] [blame] | 3902 | }; |
| 3903 | |
| 3904 | static void |
| 3905 | xdg_send_configure(struct weston_surface *surface, |
Jasper St. Pierre | ac985be | 2014-04-28 11:19:28 -0400 | [diff] [blame] | 3906 | int32_t width, int32_t height) |
Rafael Antognolli | e2a3455 | 2013-12-03 15:35:45 -0200 | [diff] [blame] | 3907 | { |
| 3908 | struct shell_surface *shsurf = get_shell_surface(surface); |
Jasper St. Pierre | ab2c108 | 2014-04-10 10:41:46 -0700 | [diff] [blame] | 3909 | uint32_t *s; |
| 3910 | struct wl_array states; |
| 3911 | uint32_t serial; |
Rafael Antognolli | e2a3455 | 2013-12-03 15:35:45 -0200 | [diff] [blame] | 3912 | |
U. Artie Eoff | cf5737a | 2014-01-17 10:08:25 -0800 | [diff] [blame] | 3913 | assert(shsurf); |
| 3914 | |
Jasper St. Pierre | ab2c108 | 2014-04-10 10:41:46 -0700 | [diff] [blame] | 3915 | if (!shsurf->resource) |
| 3916 | return; |
| 3917 | |
| 3918 | wl_array_init(&states); |
| 3919 | if (shsurf->requested_state.fullscreen) { |
| 3920 | s = wl_array_add(&states, sizeof *s); |
| 3921 | *s = XDG_SURFACE_STATE_FULLSCREEN; |
| 3922 | } else if (shsurf->requested_state.maximized) { |
| 3923 | s = wl_array_add(&states, sizeof *s); |
| 3924 | *s = XDG_SURFACE_STATE_MAXIMIZED; |
| 3925 | } |
Jasper St. Pierre | 5befdda | 2014-05-06 08:50:47 -0400 | [diff] [blame] | 3926 | if (shsurf->resize_edges != 0) { |
| 3927 | s = wl_array_add(&states, sizeof *s); |
| 3928 | *s = XDG_SURFACE_STATE_RESIZING; |
| 3929 | } |
Jasper St. Pierre | 973d787 | 2014-05-06 08:44:29 -0400 | [diff] [blame] | 3930 | if (shsurf->focus_count > 0) { |
| 3931 | s = wl_array_add(&states, sizeof *s); |
| 3932 | *s = XDG_SURFACE_STATE_ACTIVATED; |
| 3933 | } |
Jasper St. Pierre | ab2c108 | 2014-04-10 10:41:46 -0700 | [diff] [blame] | 3934 | |
| 3935 | serial = wl_display_next_serial(shsurf->surface->compositor->wl_display); |
| 3936 | xdg_surface_send_configure(shsurf->resource, width, height, &states, serial); |
| 3937 | |
| 3938 | wl_array_release(&states); |
Rafael Antognolli | e2a3455 | 2013-12-03 15:35:45 -0200 | [diff] [blame] | 3939 | } |
| 3940 | |
| 3941 | static const struct weston_shell_client xdg_client = { |
| 3942 | xdg_send_configure |
| 3943 | }; |
| 3944 | |
| 3945 | static void |
| 3946 | xdg_use_unstable_version(struct wl_client *client, |
| 3947 | struct wl_resource *resource, |
| 3948 | int32_t version) |
| 3949 | { |
| 3950 | if (version > 1) { |
| 3951 | wl_resource_post_error(resource, |
| 3952 | 1, |
| 3953 | "xdg-shell:: version not implemented yet."); |
| 3954 | return; |
| 3955 | } |
| 3956 | } |
| 3957 | |
| 3958 | static struct shell_surface * |
Jason Ekstrand | 9e9512f | 2014-04-16 21:12:10 -0500 | [diff] [blame] | 3959 | create_xdg_surface(struct shell_client *owner, void *shell, |
| 3960 | struct weston_surface *surface, |
Rafael Antognolli | e2a3455 | 2013-12-03 15:35:45 -0200 | [diff] [blame] | 3961 | const struct weston_shell_client *client) |
| 3962 | { |
| 3963 | struct shell_surface *shsurf; |
Rafael Antognolli | e2a3455 | 2013-12-03 15:35:45 -0200 | [diff] [blame] | 3964 | |
Jason Ekstrand | 9e9512f | 2014-04-16 21:12:10 -0500 | [diff] [blame] | 3965 | shsurf = create_common_surface(owner, shell, surface, client); |
Pekka Paalanen | e972b27 | 2014-10-01 14:03:56 +0300 | [diff] [blame] | 3966 | if (!shsurf) |
| 3967 | return NULL; |
| 3968 | |
Pekka Paalanen | b502654 | 2014-11-12 15:09:24 +0200 | [diff] [blame] | 3969 | set_type(shsurf, SHELL_SURFACE_TOPLEVEL); |
Rafael Antognolli | e2a3455 | 2013-12-03 15:35:45 -0200 | [diff] [blame] | 3970 | |
| 3971 | return shsurf; |
| 3972 | } |
| 3973 | |
| 3974 | static void |
| 3975 | xdg_get_xdg_surface(struct wl_client *client, |
| 3976 | struct wl_resource *resource, |
| 3977 | uint32_t id, |
| 3978 | struct wl_resource *surface_resource) |
| 3979 | { |
| 3980 | struct weston_surface *surface = |
| 3981 | wl_resource_get_user_data(surface_resource); |
Kristian Høgsberg | 2bff94e | 2014-02-11 12:22:51 -0800 | [diff] [blame] | 3982 | struct shell_client *sc = wl_resource_get_user_data(resource); |
| 3983 | struct desktop_shell *shell = sc->shell; |
Rafael Antognolli | e2a3455 | 2013-12-03 15:35:45 -0200 | [diff] [blame] | 3984 | struct shell_surface *shsurf; |
| 3985 | |
Jonas Ådahl | bf48e21 | 2015-02-06 10:15:28 +0800 | [diff] [blame] | 3986 | shsurf = get_shell_surface(surface); |
| 3987 | if (shsurf && shell_surface_is_xdg_surface(shsurf)) { |
| 3988 | wl_resource_post_error(resource, XDG_SHELL_ERROR_ROLE, |
| 3989 | "This wl_surface is already an " |
| 3990 | "xdg_surface"); |
| 3991 | return; |
| 3992 | } |
| 3993 | |
Pekka Paalanen | 50b6747 | 2014-10-01 15:02:41 +0300 | [diff] [blame] | 3994 | if (weston_surface_set_role(surface, "xdg_surface", |
| 3995 | resource, XDG_SHELL_ERROR_ROLE) < 0) |
Rafael Antognolli | e2a3455 | 2013-12-03 15:35:45 -0200 | [diff] [blame] | 3996 | return; |
Rafael Antognolli | e2a3455 | 2013-12-03 15:35:45 -0200 | [diff] [blame] | 3997 | |
Jason Ekstrand | 9e9512f | 2014-04-16 21:12:10 -0500 | [diff] [blame] | 3998 | shsurf = create_xdg_surface(sc, shell, surface, &xdg_client); |
Rafael Antognolli | e2a3455 | 2013-12-03 15:35:45 -0200 | [diff] [blame] | 3999 | if (!shsurf) { |
Pekka Paalanen | 50b6747 | 2014-10-01 15:02:41 +0300 | [diff] [blame] | 4000 | wl_resource_post_no_memory(surface_resource); |
Rafael Antognolli | e2a3455 | 2013-12-03 15:35:45 -0200 | [diff] [blame] | 4001 | return; |
| 4002 | } |
| 4003 | |
| 4004 | shsurf->resource = |
| 4005 | wl_resource_create(client, |
| 4006 | &xdg_surface_interface, 1, id); |
| 4007 | wl_resource_set_implementation(shsurf->resource, |
| 4008 | &xdg_surface_implementation, |
| 4009 | shsurf, shell_destroy_shell_surface); |
| 4010 | } |
| 4011 | |
| 4012 | static bool |
| 4013 | shell_surface_is_xdg_surface(struct shell_surface *shsurf) |
| 4014 | { |
Kristian Høgsberg | 0b7d995 | 2014-02-03 15:50:38 -0800 | [diff] [blame] | 4015 | return shsurf->resource && |
| 4016 | wl_resource_instance_of(shsurf->resource, |
| 4017 | &xdg_surface_interface, |
| 4018 | &xdg_surface_implementation); |
Rafael Antognolli | e2a3455 | 2013-12-03 15:35:45 -0200 | [diff] [blame] | 4019 | } |
| 4020 | |
| 4021 | /* xdg-popup implementation */ |
| 4022 | |
| 4023 | static void |
| 4024 | xdg_popup_destroy(struct wl_client *client, |
| 4025 | struct wl_resource *resource) |
| 4026 | { |
| 4027 | wl_resource_destroy(resource); |
| 4028 | } |
| 4029 | |
Rafael Antognolli | e2a3455 | 2013-12-03 15:35:45 -0200 | [diff] [blame] | 4030 | static const struct xdg_popup_interface xdg_popup_implementation = { |
| 4031 | xdg_popup_destroy, |
Rafael Antognolli | e2a3455 | 2013-12-03 15:35:45 -0200 | [diff] [blame] | 4032 | }; |
| 4033 | |
| 4034 | static void |
| 4035 | xdg_popup_send_configure(struct weston_surface *surface, |
Jasper St. Pierre | ac985be | 2014-04-28 11:19:28 -0400 | [diff] [blame] | 4036 | int32_t width, int32_t height) |
Rafael Antognolli | e2a3455 | 2013-12-03 15:35:45 -0200 | [diff] [blame] | 4037 | { |
| 4038 | } |
| 4039 | |
| 4040 | static const struct weston_shell_client xdg_popup_client = { |
| 4041 | xdg_popup_send_configure |
| 4042 | }; |
| 4043 | |
| 4044 | static struct shell_surface * |
Jason Ekstrand | 9e9512f | 2014-04-16 21:12:10 -0500 | [diff] [blame] | 4045 | create_xdg_popup(struct shell_client *owner, void *shell, |
| 4046 | struct weston_surface *surface, |
Rafael Antognolli | e2a3455 | 2013-12-03 15:35:45 -0200 | [diff] [blame] | 4047 | const struct weston_shell_client *client, |
| 4048 | struct weston_surface *parent, |
| 4049 | struct shell_seat *seat, |
| 4050 | uint32_t serial, |
| 4051 | int32_t x, int32_t y) |
| 4052 | { |
| 4053 | struct shell_surface *shsurf; |
Rafael Antognolli | e2a3455 | 2013-12-03 15:35:45 -0200 | [diff] [blame] | 4054 | |
Jason Ekstrand | 9e9512f | 2014-04-16 21:12:10 -0500 | [diff] [blame] | 4055 | shsurf = create_common_surface(owner, shell, surface, client); |
Pekka Paalanen | e972b27 | 2014-10-01 14:03:56 +0300 | [diff] [blame] | 4056 | if (!shsurf) |
| 4057 | return NULL; |
| 4058 | |
Pekka Paalanen | b502654 | 2014-11-12 15:09:24 +0200 | [diff] [blame] | 4059 | set_type(shsurf, SHELL_SURFACE_POPUP); |
Rafael Antognolli | e2a3455 | 2013-12-03 15:35:45 -0200 | [diff] [blame] | 4060 | shsurf->popup.shseat = seat; |
| 4061 | shsurf->popup.serial = serial; |
| 4062 | shsurf->popup.x = x; |
| 4063 | shsurf->popup.y = y; |
| 4064 | shell_surface_set_parent(shsurf, parent); |
| 4065 | |
| 4066 | return shsurf; |
| 4067 | } |
| 4068 | |
| 4069 | static void |
| 4070 | xdg_get_xdg_popup(struct wl_client *client, |
| 4071 | struct wl_resource *resource, |
| 4072 | uint32_t id, |
| 4073 | struct wl_resource *surface_resource, |
| 4074 | struct wl_resource *parent_resource, |
| 4075 | struct wl_resource *seat_resource, |
| 4076 | uint32_t serial, |
| 4077 | int32_t x, int32_t y, uint32_t flags) |
| 4078 | { |
| 4079 | struct weston_surface *surface = |
| 4080 | wl_resource_get_user_data(surface_resource); |
Kristian Høgsberg | 2bff94e | 2014-02-11 12:22:51 -0800 | [diff] [blame] | 4081 | struct shell_client *sc = wl_resource_get_user_data(resource); |
| 4082 | struct desktop_shell *shell = sc->shell; |
Rafael Antognolli | e2a3455 | 2013-12-03 15:35:45 -0200 | [diff] [blame] | 4083 | struct shell_surface *shsurf; |
| 4084 | struct weston_surface *parent; |
| 4085 | struct shell_seat *seat; |
| 4086 | |
Jonas Ådahl | bf48e21 | 2015-02-06 10:15:28 +0800 | [diff] [blame] | 4087 | shsurf = get_shell_surface(surface); |
| 4088 | if (shsurf && shell_surface_is_xdg_popup(shsurf)) { |
| 4089 | wl_resource_post_error(resource, XDG_SHELL_ERROR_ROLE, |
| 4090 | "This wl_surface is already an " |
| 4091 | "xdg_popup"); |
| 4092 | return; |
| 4093 | } |
| 4094 | |
Pekka Paalanen | 50b6747 | 2014-10-01 15:02:41 +0300 | [diff] [blame] | 4095 | if (weston_surface_set_role(surface, "xdg_popup", |
| 4096 | resource, XDG_SHELL_ERROR_ROLE) < 0) |
Rafael Antognolli | e2a3455 | 2013-12-03 15:35:45 -0200 | [diff] [blame] | 4097 | return; |
Rafael Antognolli | e2a3455 | 2013-12-03 15:35:45 -0200 | [diff] [blame] | 4098 | |
| 4099 | if (!parent_resource) { |
| 4100 | wl_resource_post_error(surface_resource, |
| 4101 | WL_DISPLAY_ERROR_INVALID_OBJECT, |
| 4102 | "xdg_shell::get_xdg_popup requires a parent shell surface"); |
Jasper St. Pierre | 666bc92 | 2014-08-07 16:43:13 -0400 | [diff] [blame] | 4103 | return; |
Rafael Antognolli | e2a3455 | 2013-12-03 15:35:45 -0200 | [diff] [blame] | 4104 | } |
| 4105 | |
| 4106 | parent = wl_resource_get_user_data(parent_resource); |
| 4107 | seat = get_shell_seat(wl_resource_get_user_data(seat_resource));; |
| 4108 | |
Jason Ekstrand | 9e9512f | 2014-04-16 21:12:10 -0500 | [diff] [blame] | 4109 | shsurf = create_xdg_popup(sc, shell, surface, &xdg_popup_client, |
Rafael Antognolli | e2a3455 | 2013-12-03 15:35:45 -0200 | [diff] [blame] | 4110 | parent, seat, serial, x, y); |
| 4111 | if (!shsurf) { |
Pekka Paalanen | 50b6747 | 2014-10-01 15:02:41 +0300 | [diff] [blame] | 4112 | wl_resource_post_no_memory(surface_resource); |
Rafael Antognolli | e2a3455 | 2013-12-03 15:35:45 -0200 | [diff] [blame] | 4113 | return; |
| 4114 | } |
| 4115 | |
| 4116 | shsurf->resource = |
| 4117 | wl_resource_create(client, |
| 4118 | &xdg_popup_interface, 1, id); |
| 4119 | wl_resource_set_implementation(shsurf->resource, |
| 4120 | &xdg_popup_implementation, |
| 4121 | shsurf, shell_destroy_shell_surface); |
| 4122 | } |
| 4123 | |
Kristian Høgsberg | 2bff94e | 2014-02-11 12:22:51 -0800 | [diff] [blame] | 4124 | static void |
| 4125 | xdg_pong(struct wl_client *client, |
| 4126 | struct wl_resource *resource, uint32_t serial) |
| 4127 | { |
| 4128 | struct shell_client *sc = wl_resource_get_user_data(resource); |
Kristian Høgsberg | 2bff94e | 2014-02-11 12:22:51 -0800 | [diff] [blame] | 4129 | |
Kristian Høgsberg | dd62aba | 2014-02-12 09:56:19 -0800 | [diff] [blame] | 4130 | shell_client_pong(sc, serial); |
Kristian Høgsberg | 2bff94e | 2014-02-11 12:22:51 -0800 | [diff] [blame] | 4131 | } |
| 4132 | |
Rafael Antognolli | e2a3455 | 2013-12-03 15:35:45 -0200 | [diff] [blame] | 4133 | static bool |
| 4134 | shell_surface_is_xdg_popup(struct shell_surface *shsurf) |
| 4135 | { |
| 4136 | return wl_resource_instance_of(shsurf->resource, |
| 4137 | &xdg_popup_interface, |
| 4138 | &xdg_popup_implementation); |
| 4139 | } |
| 4140 | |
| 4141 | static const struct xdg_shell_interface xdg_implementation = { |
| 4142 | xdg_use_unstable_version, |
| 4143 | xdg_get_xdg_surface, |
Kristian Høgsberg | 2bff94e | 2014-02-11 12:22:51 -0800 | [diff] [blame] | 4144 | xdg_get_xdg_popup, |
| 4145 | xdg_pong |
Rafael Antognolli | e2a3455 | 2013-12-03 15:35:45 -0200 | [diff] [blame] | 4146 | }; |
| 4147 | |
| 4148 | static int |
| 4149 | xdg_shell_unversioned_dispatch(const void *implementation, |
| 4150 | void *_target, uint32_t opcode, |
| 4151 | const struct wl_message *message, |
| 4152 | union wl_argument *args) |
| 4153 | { |
| 4154 | struct wl_resource *resource = _target; |
Kristian Høgsberg | 2bff94e | 2014-02-11 12:22:51 -0800 | [diff] [blame] | 4155 | struct shell_client *sc = wl_resource_get_user_data(resource); |
Rafael Antognolli | e2a3455 | 2013-12-03 15:35:45 -0200 | [diff] [blame] | 4156 | |
| 4157 | if (opcode != 0) { |
| 4158 | wl_resource_post_error(resource, |
| 4159 | WL_DISPLAY_ERROR_INVALID_OBJECT, |
| 4160 | "must call use_unstable_version first"); |
| 4161 | return 0; |
| 4162 | } |
| 4163 | |
Pekka Paalanen | 71182ae | 2014-08-21 17:47:20 +0300 | [diff] [blame] | 4164 | #define XDG_SERVER_VERSION 4 |
Rafael Antognolli | e2a3455 | 2013-12-03 15:35:45 -0200 | [diff] [blame] | 4165 | |
Kristian Høgsberg | 8d344a0 | 2013-12-08 22:27:11 -0800 | [diff] [blame] | 4166 | static_assert(XDG_SERVER_VERSION == XDG_SHELL_VERSION_CURRENT, |
| 4167 | "shell implementation doesn't match protocol version"); |
| 4168 | |
Rafael Antognolli | e2a3455 | 2013-12-03 15:35:45 -0200 | [diff] [blame] | 4169 | if (args[0].i != XDG_SERVER_VERSION) { |
| 4170 | wl_resource_post_error(resource, |
| 4171 | WL_DISPLAY_ERROR_INVALID_OBJECT, |
| 4172 | "incompatible version, server is %d " |
| 4173 | "client wants %d", |
| 4174 | XDG_SERVER_VERSION, args[0].i); |
| 4175 | return 0; |
| 4176 | } |
| 4177 | |
| 4178 | wl_resource_set_implementation(resource, &xdg_implementation, |
Kristian Høgsberg | 2bff94e | 2014-02-11 12:22:51 -0800 | [diff] [blame] | 4179 | sc, NULL); |
Rafael Antognolli | e2a3455 | 2013-12-03 15:35:45 -0200 | [diff] [blame] | 4180 | |
| 4181 | return 1; |
| 4182 | } |
| 4183 | |
| 4184 | /* end of xdg-shell implementation */ |
| 4185 | /***********************************/ |
| 4186 | |
Kristian Høgsberg | 0793756 | 2011-04-12 17:25:42 -0400 | [diff] [blame] | 4187 | static void |
Ander Conselvan de Oliveira | 859e885 | 2013-02-21 18:35:21 +0200 | [diff] [blame] | 4188 | shell_fade(struct desktop_shell *shell, enum fade_type type); |
| 4189 | |
| 4190 | static int |
| 4191 | screensaver_timeout(void *data) |
| 4192 | { |
| 4193 | struct desktop_shell *shell = data; |
| 4194 | |
| 4195 | shell_fade(shell, FADE_OUT); |
| 4196 | |
| 4197 | return 1; |
| 4198 | } |
| 4199 | |
| 4200 | static void |
Kristian Høgsberg | 8334bc1 | 2012-01-03 10:29:47 -0500 | [diff] [blame] | 4201 | handle_screensaver_sigchld(struct weston_process *proc, int status) |
Pekka Paalanen | 18027e5 | 2011-12-02 16:31:49 +0200 | [diff] [blame] | 4202 | { |
Ander Conselvan de Oliveira | 18639f8 | 2013-02-15 18:44:19 +0200 | [diff] [blame] | 4203 | struct desktop_shell *shell = |
| 4204 | container_of(proc, struct desktop_shell, screensaver.process); |
Ander Conselvan de Oliveira | 18639f8 | 2013-02-15 18:44:19 +0200 | [diff] [blame] | 4205 | |
Pekka Paalanen | 18027e5 | 2011-12-02 16:31:49 +0200 | [diff] [blame] | 4206 | proc->pid = 0; |
Ander Conselvan de Oliveira | 18639f8 | 2013-02-15 18:44:19 +0200 | [diff] [blame] | 4207 | |
| 4208 | if (shell->locked) |
Ander Conselvan de Oliveira | b17537e | 2013-02-22 14:16:18 +0200 | [diff] [blame] | 4209 | weston_compositor_sleep(shell->compositor); |
Pekka Paalanen | 18027e5 | 2011-12-02 16:31:49 +0200 | [diff] [blame] | 4210 | } |
| 4211 | |
| 4212 | static void |
Tiago Vignatti | be14326 | 2012-04-16 17:31:41 +0300 | [diff] [blame] | 4213 | launch_screensaver(struct desktop_shell *shell) |
Pekka Paalanen | 77346a6 | 2011-11-30 16:26:35 +0200 | [diff] [blame] | 4214 | { |
| 4215 | if (shell->screensaver.binding) |
| 4216 | return; |
| 4217 | |
Ander Conselvan de Oliveira | dda9d78 | 2013-02-22 14:16:19 +0200 | [diff] [blame] | 4218 | if (!shell->screensaver.path) { |
| 4219 | weston_compositor_sleep(shell->compositor); |
Pekka Paalanen | e955f1e | 2011-12-07 11:49:52 +0200 | [diff] [blame] | 4220 | return; |
Ander Conselvan de Oliveira | dda9d78 | 2013-02-22 14:16:19 +0200 | [diff] [blame] | 4221 | } |
Pekka Paalanen | e955f1e | 2011-12-07 11:49:52 +0200 | [diff] [blame] | 4222 | |
Kristian Høgsberg | 32bed57 | 2012-03-01 17:11:36 -0500 | [diff] [blame] | 4223 | if (shell->screensaver.process.pid != 0) { |
Martin Minarik | 6d11836 | 2012-06-07 18:01:59 +0200 | [diff] [blame] | 4224 | weston_log("old screensaver still running\n"); |
Kristian Høgsberg | 32bed57 | 2012-03-01 17:11:36 -0500 | [diff] [blame] | 4225 | return; |
| 4226 | } |
| 4227 | |
Kristian Høgsberg | 8334bc1 | 2012-01-03 10:29:47 -0500 | [diff] [blame] | 4228 | weston_client_launch(shell->compositor, |
Pekka Paalanen | 18027e5 | 2011-12-02 16:31:49 +0200 | [diff] [blame] | 4229 | &shell->screensaver.process, |
Pekka Paalanen | e955f1e | 2011-12-07 11:49:52 +0200 | [diff] [blame] | 4230 | shell->screensaver.path, |
Pekka Paalanen | 18027e5 | 2011-12-02 16:31:49 +0200 | [diff] [blame] | 4231 | handle_screensaver_sigchld); |
Pekka Paalanen | 77346a6 | 2011-11-30 16:26:35 +0200 | [diff] [blame] | 4232 | } |
| 4233 | |
| 4234 | static void |
Tiago Vignatti | be14326 | 2012-04-16 17:31:41 +0300 | [diff] [blame] | 4235 | terminate_screensaver(struct desktop_shell *shell) |
Pekka Paalanen | 77346a6 | 2011-11-30 16:26:35 +0200 | [diff] [blame] | 4236 | { |
Pekka Paalanen | 18027e5 | 2011-12-02 16:31:49 +0200 | [diff] [blame] | 4237 | if (shell->screensaver.process.pid == 0) |
| 4238 | return; |
| 4239 | |
Ander Conselvan de Oliveira | 4e20e9b | 2014-04-10 14:49:35 +0300 | [diff] [blame] | 4240 | /* Disarm the screensaver timer, otherwise it may fire when the |
| 4241 | * compositor is not in the idle state. In that case, the screen will |
| 4242 | * be locked, but the wake_signal won't fire on user input, making the |
| 4243 | * system unresponsive. */ |
| 4244 | wl_event_source_timer_update(shell->screensaver.timer, 0); |
| 4245 | |
Pekka Paalanen | 18027e5 | 2011-12-02 16:31:49 +0200 | [diff] [blame] | 4246 | kill(shell->screensaver.process.pid, SIGTERM); |
Pekka Paalanen | 77346a6 | 2011-11-30 16:26:35 +0200 | [diff] [blame] | 4247 | } |
| 4248 | |
| 4249 | static void |
Jason Ekstrand | 918f2dd | 2013-12-02 21:01:53 -0600 | [diff] [blame] | 4250 | configure_static_view(struct weston_view *ev, struct weston_layer *layer) |
Kristian Høgsberg | 962342c | 2012-06-26 16:29:50 -0400 | [diff] [blame] | 4251 | { |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 4252 | struct weston_view *v, *next; |
Kristian Høgsberg | 962342c | 2012-06-26 16:29:50 -0400 | [diff] [blame] | 4253 | |
Giulio Camuffo | 412e6a5 | 2014-07-09 22:12:56 +0300 | [diff] [blame] | 4254 | 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] | 4255 | if (v->output == ev->output && v != ev) { |
| 4256 | weston_view_unmap(v); |
| 4257 | v->surface->configure = NULL; |
Pekka Paalanen | 8274d90 | 2014-08-06 19:36:51 +0300 | [diff] [blame] | 4258 | weston_surface_set_label_func(v->surface, NULL); |
Kristian Høgsberg | 962342c | 2012-06-26 16:29:50 -0400 | [diff] [blame] | 4259 | } |
| 4260 | } |
| 4261 | |
Jason Ekstrand | 918f2dd | 2013-12-02 21:01:53 -0600 | [diff] [blame] | 4262 | weston_view_set_position(ev, ev->output->x, ev->output->y); |
Kristian Høgsberg | 962342c | 2012-06-26 16:29:50 -0400 | [diff] [blame] | 4263 | |
Giulio Camuffo | 412e6a5 | 2014-07-09 22:12:56 +0300 | [diff] [blame] | 4264 | if (wl_list_empty(&ev->layer_link.link)) { |
| 4265 | weston_layer_entry_insert(&layer->view_list, &ev->layer_link); |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 4266 | weston_compositor_schedule_repaint(ev->surface->compositor); |
Kristian Høgsberg | 962342c | 2012-06-26 16:29:50 -0400 | [diff] [blame] | 4267 | } |
| 4268 | } |
| 4269 | |
Pekka Paalanen | 8274d90 | 2014-08-06 19:36:51 +0300 | [diff] [blame] | 4270 | static int |
| 4271 | background_get_label(struct weston_surface *surface, char *buf, size_t len) |
| 4272 | { |
| 4273 | return snprintf(buf, len, "background for output %s", |
| 4274 | surface->output->name); |
| 4275 | } |
| 4276 | |
Kristian Høgsberg | 962342c | 2012-06-26 16:29:50 -0400 | [diff] [blame] | 4277 | static void |
Jason Ekstrand | 918f2dd | 2013-12-02 21:01:53 -0600 | [diff] [blame] | 4278 | 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] | 4279 | { |
Giulio Camuffo | 7fe01b1 | 2013-03-28 18:02:42 +0100 | [diff] [blame] | 4280 | struct desktop_shell *shell = es->configure_private; |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 4281 | struct weston_view *view; |
Kristian Høgsberg | af7b1ff | 2012-06-26 21:19:23 -0400 | [diff] [blame] | 4282 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 4283 | view = container_of(es->views.next, struct weston_view, surface_link); |
| 4284 | |
Jason Ekstrand | 918f2dd | 2013-12-02 21:01:53 -0600 | [diff] [blame] | 4285 | configure_static_view(view, &shell->background_layer); |
Kristian Høgsberg | af7b1ff | 2012-06-26 21:19:23 -0400 | [diff] [blame] | 4286 | } |
| 4287 | |
| 4288 | static void |
Kristian Høgsberg | 7584062 | 2011-09-06 13:48:16 -0400 | [diff] [blame] | 4289 | desktop_shell_set_background(struct wl_client *client, |
| 4290 | struct wl_resource *resource, |
Benjamin Franzke | d0f79ab | 2011-11-22 12:43:52 +0100 | [diff] [blame] | 4291 | struct wl_resource *output_resource, |
Kristian Høgsberg | 7584062 | 2011-09-06 13:48:16 -0400 | [diff] [blame] | 4292 | struct wl_resource *surface_resource) |
| 4293 | { |
Jason Ekstrand | 651f00e | 2013-06-14 10:07:54 -0500 | [diff] [blame] | 4294 | struct desktop_shell *shell = wl_resource_get_user_data(resource); |
Jason Ekstrand | 0f2ef7e | 2013-06-14 10:07:53 -0500 | [diff] [blame] | 4295 | struct weston_surface *surface = |
| 4296 | wl_resource_get_user_data(surface_resource); |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 4297 | struct weston_view *view, *next; |
Kristian Høgsberg | 7584062 | 2011-09-06 13:48:16 -0400 | [diff] [blame] | 4298 | |
Kristian Høgsberg | 962342c | 2012-06-26 16:29:50 -0400 | [diff] [blame] | 4299 | if (surface->configure) { |
| 4300 | wl_resource_post_error(surface_resource, |
| 4301 | WL_DISPLAY_ERROR_INVALID_OBJECT, |
| 4302 | "surface role already assigned"); |
| 4303 | return; |
| 4304 | } |
Benjamin Franzke | d0f79ab | 2011-11-22 12:43:52 +0100 | [diff] [blame] | 4305 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 4306 | wl_list_for_each_safe(view, next, &surface->views, surface_link) |
| 4307 | weston_view_destroy(view); |
| 4308 | view = weston_view_create(surface); |
| 4309 | |
Kristian Høgsberg | 962342c | 2012-06-26 16:29:50 -0400 | [diff] [blame] | 4310 | surface->configure = background_configure; |
Giulio Camuffo | 7fe01b1 | 2013-03-28 18:02:42 +0100 | [diff] [blame] | 4311 | surface->configure_private = shell; |
Pekka Paalanen | 8274d90 | 2014-08-06 19:36:51 +0300 | [diff] [blame] | 4312 | weston_surface_set_label_func(surface, background_get_label); |
Jason Ekstrand | a0d2dde | 2013-06-14 10:08:01 -0500 | [diff] [blame] | 4313 | surface->output = wl_resource_get_user_data(output_resource); |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 4314 | view->output = surface->output; |
Kristian Høgsberg | eae5de7 | 2012-04-11 22:42:15 -0400 | [diff] [blame] | 4315 | desktop_shell_send_configure(resource, 0, |
Kristian Høgsberg | 0b5cd0c | 2012-03-04 21:57:37 -0500 | [diff] [blame] | 4316 | surface_resource, |
Scott Moreau | 1bad5db | 2012-08-18 01:04:05 -0600 | [diff] [blame] | 4317 | surface->output->width, |
| 4318 | surface->output->height); |
Kristian Høgsberg | 7584062 | 2011-09-06 13:48:16 -0400 | [diff] [blame] | 4319 | } |
| 4320 | |
Pekka Paalanen | 8274d90 | 2014-08-06 19:36:51 +0300 | [diff] [blame] | 4321 | static int |
| 4322 | panel_get_label(struct weston_surface *surface, char *buf, size_t len) |
| 4323 | { |
| 4324 | return snprintf(buf, len, "panel for output %s", |
| 4325 | surface->output->name); |
| 4326 | } |
| 4327 | |
Kristian Høgsberg | 7584062 | 2011-09-06 13:48:16 -0400 | [diff] [blame] | 4328 | static void |
Jason Ekstrand | 918f2dd | 2013-12-02 21:01:53 -0600 | [diff] [blame] | 4329 | 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] | 4330 | { |
Giulio Camuffo | 7fe01b1 | 2013-03-28 18:02:42 +0100 | [diff] [blame] | 4331 | struct desktop_shell *shell = es->configure_private; |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 4332 | struct weston_view *view; |
Kristian Høgsberg | af7b1ff | 2012-06-26 21:19:23 -0400 | [diff] [blame] | 4333 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 4334 | view = container_of(es->views.next, struct weston_view, surface_link); |
| 4335 | |
Jason Ekstrand | 918f2dd | 2013-12-02 21:01:53 -0600 | [diff] [blame] | 4336 | configure_static_view(view, &shell->panel_layer); |
Kristian Høgsberg | af7b1ff | 2012-06-26 21:19:23 -0400 | [diff] [blame] | 4337 | } |
| 4338 | |
| 4339 | static void |
Kristian Høgsberg | 7584062 | 2011-09-06 13:48:16 -0400 | [diff] [blame] | 4340 | desktop_shell_set_panel(struct wl_client *client, |
| 4341 | struct wl_resource *resource, |
Benjamin Franzke | d0f79ab | 2011-11-22 12:43:52 +0100 | [diff] [blame] | 4342 | struct wl_resource *output_resource, |
Kristian Høgsberg | 7584062 | 2011-09-06 13:48:16 -0400 | [diff] [blame] | 4343 | struct wl_resource *surface_resource) |
| 4344 | { |
Jason Ekstrand | 651f00e | 2013-06-14 10:07:54 -0500 | [diff] [blame] | 4345 | struct desktop_shell *shell = wl_resource_get_user_data(resource); |
Jason Ekstrand | 0f2ef7e | 2013-06-14 10:07:53 -0500 | [diff] [blame] | 4346 | struct weston_surface *surface = |
| 4347 | wl_resource_get_user_data(surface_resource); |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 4348 | struct weston_view *view, *next; |
Kristian Høgsberg | 7584062 | 2011-09-06 13:48:16 -0400 | [diff] [blame] | 4349 | |
Kristian Høgsberg | af7b1ff | 2012-06-26 21:19:23 -0400 | [diff] [blame] | 4350 | if (surface->configure) { |
| 4351 | wl_resource_post_error(surface_resource, |
| 4352 | WL_DISPLAY_ERROR_INVALID_OBJECT, |
| 4353 | "surface role already assigned"); |
| 4354 | return; |
| 4355 | } |
Benjamin Franzke | d0f79ab | 2011-11-22 12:43:52 +0100 | [diff] [blame] | 4356 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 4357 | wl_list_for_each_safe(view, next, &surface->views, surface_link) |
| 4358 | weston_view_destroy(view); |
| 4359 | view = weston_view_create(surface); |
| 4360 | |
Kristian Høgsberg | af7b1ff | 2012-06-26 21:19:23 -0400 | [diff] [blame] | 4361 | surface->configure = panel_configure; |
Giulio Camuffo | 7fe01b1 | 2013-03-28 18:02:42 +0100 | [diff] [blame] | 4362 | surface->configure_private = shell; |
Pekka Paalanen | 8274d90 | 2014-08-06 19:36:51 +0300 | [diff] [blame] | 4363 | weston_surface_set_label_func(surface, panel_get_label); |
Jason Ekstrand | a0d2dde | 2013-06-14 10:08:01 -0500 | [diff] [blame] | 4364 | surface->output = wl_resource_get_user_data(output_resource); |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 4365 | view->output = surface->output; |
Kristian Høgsberg | eae5de7 | 2012-04-11 22:42:15 -0400 | [diff] [blame] | 4366 | desktop_shell_send_configure(resource, 0, |
Kristian Høgsberg | af7b1ff | 2012-06-26 21:19:23 -0400 | [diff] [blame] | 4367 | surface_resource, |
Scott Moreau | 1bad5db | 2012-08-18 01:04:05 -0600 | [diff] [blame] | 4368 | surface->output->width, |
| 4369 | surface->output->height); |
Kristian Høgsberg | 7584062 | 2011-09-06 13:48:16 -0400 | [diff] [blame] | 4370 | } |
| 4371 | |
Pekka Paalanen | 8274d90 | 2014-08-06 19:36:51 +0300 | [diff] [blame] | 4372 | static int |
| 4373 | lock_surface_get_label(struct weston_surface *surface, char *buf, size_t len) |
| 4374 | { |
| 4375 | return snprintf(buf, len, "lock window"); |
| 4376 | } |
| 4377 | |
Pekka Paalanen | 9ef3e01 | 2011-11-15 13:34:48 +0200 | [diff] [blame] | 4378 | static void |
Jason Ekstrand | 918f2dd | 2013-12-02 21:01:53 -0600 | [diff] [blame] | 4379 | 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] | 4380 | { |
Giulio Camuffo | 7fe01b1 | 2013-03-28 18:02:42 +0100 | [diff] [blame] | 4381 | struct desktop_shell *shell = surface->configure_private; |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 4382 | struct weston_view *view; |
| 4383 | |
| 4384 | view = container_of(surface->views.next, struct weston_view, surface_link); |
Kristian Høgsberg | 730c94d | 2012-06-26 21:44:35 -0400 | [diff] [blame] | 4385 | |
Jason Ekstrand | 918f2dd | 2013-12-02 21:01:53 -0600 | [diff] [blame] | 4386 | if (surface->width == 0) |
Giulio Camuffo | 184df50 | 2013-02-21 11:29:21 +0100 | [diff] [blame] | 4387 | return; |
| 4388 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 4389 | center_on_output(view, get_default_output(shell->compositor)); |
Kristian Høgsberg | 730c94d | 2012-06-26 21:44:35 -0400 | [diff] [blame] | 4390 | |
| 4391 | if (!weston_surface_is_mapped(surface)) { |
Giulio Camuffo | 412e6a5 | 2014-07-09 22:12:56 +0300 | [diff] [blame] | 4392 | weston_layer_entry_insert(&shell->lock_layer.view_list, |
| 4393 | &view->layer_link); |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 4394 | weston_view_update_transform(view); |
Ander Conselvan de Oliveira | 87524b6 | 2013-02-21 18:35:22 +0200 | [diff] [blame] | 4395 | shell_fade(shell, FADE_IN); |
Kristian Høgsberg | 730c94d | 2012-06-26 21:44:35 -0400 | [diff] [blame] | 4396 | } |
| 4397 | } |
| 4398 | |
| 4399 | static void |
Kristian Høgsberg | 27e3052 | 2012-04-11 23:18:23 -0400 | [diff] [blame] | 4400 | handle_lock_surface_destroy(struct wl_listener *listener, void *data) |
Kristian Høgsberg | 1ec0c31 | 2011-11-15 16:39:55 -0500 | [diff] [blame] | 4401 | { |
Tiago Vignatti | be14326 | 2012-04-16 17:31:41 +0300 | [diff] [blame] | 4402 | struct desktop_shell *shell = |
| 4403 | container_of(listener, struct desktop_shell, lock_surface_listener); |
Kristian Høgsberg | 1ec0c31 | 2011-11-15 16:39:55 -0500 | [diff] [blame] | 4404 | |
Martin Minarik | 6d11836 | 2012-06-07 18:01:59 +0200 | [diff] [blame] | 4405 | weston_log("lock surface gone\n"); |
Kristian Høgsberg | 1ec0c31 | 2011-11-15 16:39:55 -0500 | [diff] [blame] | 4406 | shell->lock_surface = NULL; |
| 4407 | } |
| 4408 | |
| 4409 | static void |
Pekka Paalanen | 9ef3e01 | 2011-11-15 13:34:48 +0200 | [diff] [blame] | 4410 | desktop_shell_set_lock_surface(struct wl_client *client, |
| 4411 | struct wl_resource *resource, |
| 4412 | struct wl_resource *surface_resource) |
| 4413 | { |
Jason Ekstrand | 651f00e | 2013-06-14 10:07:54 -0500 | [diff] [blame] | 4414 | struct desktop_shell *shell = wl_resource_get_user_data(resource); |
Jason Ekstrand | 0f2ef7e | 2013-06-14 10:07:53 -0500 | [diff] [blame] | 4415 | struct weston_surface *surface = |
| 4416 | wl_resource_get_user_data(surface_resource); |
Pekka Paalanen | 9826223 | 2011-12-01 10:42:22 +0200 | [diff] [blame] | 4417 | |
Pekka Paalanen | f0fc70d | 2011-11-15 13:34:54 +0200 | [diff] [blame] | 4418 | shell->prepare_event_sent = false; |
Kristian Høgsberg | af867cc | 2011-11-15 13:34:49 +0200 | [diff] [blame] | 4419 | |
Pekka Paalanen | f0fc70d | 2011-11-15 13:34:54 +0200 | [diff] [blame] | 4420 | if (!shell->locked) |
| 4421 | return; |
| 4422 | |
Pekka Paalanen | 9826223 | 2011-12-01 10:42:22 +0200 | [diff] [blame] | 4423 | shell->lock_surface = surface; |
Pekka Paalanen | f0fc70d | 2011-11-15 13:34:54 +0200 | [diff] [blame] | 4424 | |
Kristian Høgsberg | 27e3052 | 2012-04-11 23:18:23 -0400 | [diff] [blame] | 4425 | shell->lock_surface_listener.notify = handle_lock_surface_destroy; |
Jason Ekstrand | 651f00e | 2013-06-14 10:07:54 -0500 | [diff] [blame] | 4426 | wl_signal_add(&surface->destroy_signal, |
Kristian Høgsberg | 27e3052 | 2012-04-11 23:18:23 -0400 | [diff] [blame] | 4427 | &shell->lock_surface_listener); |
Pekka Paalanen | 57da4a8 | 2011-11-23 16:42:16 +0200 | [diff] [blame] | 4428 | |
Kristian Høgsberg | aa2ee8b | 2013-10-30 15:49:45 -0700 | [diff] [blame] | 4429 | weston_view_create(surface); |
Kristian Høgsberg | 730c94d | 2012-06-26 21:44:35 -0400 | [diff] [blame] | 4430 | surface->configure = lock_surface_configure; |
Giulio Camuffo | 7fe01b1 | 2013-03-28 18:02:42 +0100 | [diff] [blame] | 4431 | surface->configure_private = shell; |
Pekka Paalanen | 8274d90 | 2014-08-06 19:36:51 +0300 | [diff] [blame] | 4432 | weston_surface_set_label_func(surface, lock_surface_get_label); |
Pekka Paalanen | f0fc70d | 2011-11-15 13:34:54 +0200 | [diff] [blame] | 4433 | } |
| 4434 | |
| 4435 | static void |
Tiago Vignatti | be14326 | 2012-04-16 17:31:41 +0300 | [diff] [blame] | 4436 | resume_desktop(struct desktop_shell *shell) |
Pekka Paalanen | f0fc70d | 2011-11-15 13:34:54 +0200 | [diff] [blame] | 4437 | { |
Kristian Høgsberg | 4476aaf | 2012-06-25 14:03:13 -0400 | [diff] [blame] | 4438 | struct workspace *ws = get_current_workspace(shell); |
Pekka Paalanen | 77346a6 | 2011-11-30 16:26:35 +0200 | [diff] [blame] | 4439 | |
Pekka Paalanen | 77346a6 | 2011-11-30 16:26:35 +0200 | [diff] [blame] | 4440 | terminate_screensaver(shell); |
Pekka Paalanen | f0fc70d | 2011-11-15 13:34:54 +0200 | [diff] [blame] | 4441 | |
Kristian Høgsberg | 3be2ce9 | 2012-02-29 12:42:35 -0500 | [diff] [blame] | 4442 | wl_list_remove(&shell->lock_layer.link); |
Philipp Brüschweiler | 711fda8 | 2012-08-09 18:50:43 +0200 | [diff] [blame] | 4443 | if (shell->showing_input_panels) { |
Manuel Bachmann | 805d2f5 | 2014-03-05 12:21:34 +0100 | [diff] [blame] | 4444 | wl_list_insert(&shell->compositor->cursor_layer.link, |
Philipp Brüschweiler | 711fda8 | 2012-08-09 18:50:43 +0200 | [diff] [blame] | 4445 | &shell->input_panel_layer.link); |
| 4446 | wl_list_insert(&shell->input_panel_layer.link, |
Manuel Bachmann | 805d2f5 | 2014-03-05 12:21:34 +0100 | [diff] [blame] | 4447 | &shell->fullscreen_layer.link); |
Philipp Brüschweiler | 711fda8 | 2012-08-09 18:50:43 +0200 | [diff] [blame] | 4448 | } else { |
Manuel Bachmann | 805d2f5 | 2014-03-05 12:21:34 +0100 | [diff] [blame] | 4449 | wl_list_insert(&shell->compositor->cursor_layer.link, |
| 4450 | &shell->fullscreen_layer.link); |
Philipp Brüschweiler | 711fda8 | 2012-08-09 18:50:43 +0200 | [diff] [blame] | 4451 | } |
Manuel Bachmann | 805d2f5 | 2014-03-05 12:21:34 +0100 | [diff] [blame] | 4452 | wl_list_insert(&shell->fullscreen_layer.link, |
| 4453 | &shell->panel_layer.link); |
| 4454 | wl_list_insert(&shell->panel_layer.link, |
| 4455 | &ws->layer.link), |
Pekka Paalanen | f0fc70d | 2011-11-15 13:34:54 +0200 | [diff] [blame] | 4456 | |
Kristian Høgsberg | 2f5faff | 2012-07-31 16:36:34 -0400 | [diff] [blame] | 4457 | restore_focus_state(shell, get_current_workspace(shell)); |
Jonas Ådahl | 0476974 | 2012-06-13 00:01:24 +0200 | [diff] [blame] | 4458 | |
Pekka Paalanen | f0fc70d | 2011-11-15 13:34:54 +0200 | [diff] [blame] | 4459 | shell->locked = false; |
Ander Conselvan de Oliveira | 87524b6 | 2013-02-21 18:35:22 +0200 | [diff] [blame] | 4460 | shell_fade(shell, FADE_IN); |
Pekka Paalanen | fc6d91a | 2012-02-10 15:33:10 +0200 | [diff] [blame] | 4461 | weston_compositor_damage_all(shell->compositor); |
Pekka Paalanen | 9ef3e01 | 2011-11-15 13:34:48 +0200 | [diff] [blame] | 4462 | } |
| 4463 | |
| 4464 | static void |
| 4465 | desktop_shell_unlock(struct wl_client *client, |
| 4466 | struct wl_resource *resource) |
| 4467 | { |
Jason Ekstrand | 651f00e | 2013-06-14 10:07:54 -0500 | [diff] [blame] | 4468 | struct desktop_shell *shell = wl_resource_get_user_data(resource); |
Pekka Paalanen | 9ef3e01 | 2011-11-15 13:34:48 +0200 | [diff] [blame] | 4469 | |
Pekka Paalanen | 9ef3e01 | 2011-11-15 13:34:48 +0200 | [diff] [blame] | 4470 | shell->prepare_event_sent = false; |
Pekka Paalanen | f0fc70d | 2011-11-15 13:34:54 +0200 | [diff] [blame] | 4471 | |
| 4472 | if (shell->locked) |
| 4473 | resume_desktop(shell); |
Pekka Paalanen | 9ef3e01 | 2011-11-15 13:34:48 +0200 | [diff] [blame] | 4474 | } |
| 4475 | |
Kristian Høgsberg | d56bd90 | 2012-06-05 09:58:51 -0400 | [diff] [blame] | 4476 | static void |
Ander Conselvan de Oliveira | b9d2a0f | 2012-06-28 18:08:05 +0300 | [diff] [blame] | 4477 | desktop_shell_set_grab_surface(struct wl_client *client, |
Kristian Høgsberg | d56bd90 | 2012-06-05 09:58:51 -0400 | [diff] [blame] | 4478 | struct wl_resource *resource, |
| 4479 | struct wl_resource *surface_resource) |
| 4480 | { |
Jason Ekstrand | 651f00e | 2013-06-14 10:07:54 -0500 | [diff] [blame] | 4481 | struct desktop_shell *shell = wl_resource_get_user_data(resource); |
Kristian Høgsberg | d56bd90 | 2012-06-05 09:58:51 -0400 | [diff] [blame] | 4482 | |
Jason Ekstrand | 0f2ef7e | 2013-06-14 10:07:53 -0500 | [diff] [blame] | 4483 | shell->grab_surface = wl_resource_get_user_data(surface_resource); |
Kristian Høgsberg | 48588f8 | 2013-10-24 15:51:35 -0700 | [diff] [blame] | 4484 | weston_view_create(shell->grab_surface); |
Kristian Høgsberg | d56bd90 | 2012-06-05 09:58:51 -0400 | [diff] [blame] | 4485 | } |
| 4486 | |
Pekka Paalanen | 79346ab | 2013-05-22 18:03:09 +0300 | [diff] [blame] | 4487 | static void |
| 4488 | desktop_shell_desktop_ready(struct wl_client *client, |
| 4489 | struct wl_resource *resource) |
| 4490 | { |
Jason Ekstrand | 651f00e | 2013-06-14 10:07:54 -0500 | [diff] [blame] | 4491 | struct desktop_shell *shell = wl_resource_get_user_data(resource); |
Pekka Paalanen | 79346ab | 2013-05-22 18:03:09 +0300 | [diff] [blame] | 4492 | |
| 4493 | shell_fade_startup(shell); |
| 4494 | } |
| 4495 | |
Jonny Lamb | 765760d | 2014-08-20 15:53:19 +0200 | [diff] [blame] | 4496 | static void |
| 4497 | desktop_shell_set_panel_position(struct wl_client *client, |
| 4498 | struct wl_resource *resource, |
| 4499 | uint32_t position) |
| 4500 | { |
| 4501 | struct desktop_shell *shell = wl_resource_get_user_data(resource); |
| 4502 | |
| 4503 | if (position != DESKTOP_SHELL_PANEL_POSITION_TOP && |
| 4504 | position != DESKTOP_SHELL_PANEL_POSITION_BOTTOM && |
| 4505 | position != DESKTOP_SHELL_PANEL_POSITION_LEFT && |
| 4506 | position != DESKTOP_SHELL_PANEL_POSITION_RIGHT) { |
| 4507 | wl_resource_post_error(resource, |
| 4508 | DESKTOP_SHELL_ERROR_INVALID_ARGUMENT, |
| 4509 | "bad position argument"); |
| 4510 | return; |
| 4511 | } |
| 4512 | |
| 4513 | shell->panel_position = position; |
| 4514 | } |
| 4515 | |
Kristian Høgsberg | 7584062 | 2011-09-06 13:48:16 -0400 | [diff] [blame] | 4516 | static const struct desktop_shell_interface desktop_shell_implementation = { |
| 4517 | desktop_shell_set_background, |
Pekka Paalanen | 9ef3e01 | 2011-11-15 13:34:48 +0200 | [diff] [blame] | 4518 | desktop_shell_set_panel, |
| 4519 | desktop_shell_set_lock_surface, |
Kristian Høgsberg | d56bd90 | 2012-06-05 09:58:51 -0400 | [diff] [blame] | 4520 | desktop_shell_unlock, |
Pekka Paalanen | 79346ab | 2013-05-22 18:03:09 +0300 | [diff] [blame] | 4521 | desktop_shell_set_grab_surface, |
Jonny Lamb | 765760d | 2014-08-20 15:53:19 +0200 | [diff] [blame] | 4522 | desktop_shell_desktop_ready, |
| 4523 | desktop_shell_set_panel_position |
Kristian Høgsberg | 7584062 | 2011-09-06 13:48:16 -0400 | [diff] [blame] | 4524 | }; |
| 4525 | |
Pekka Paalanen | 92a0dc4 | 2011-11-28 15:34:13 +0200 | [diff] [blame] | 4526 | static enum shell_surface_type |
Kristian Høgsberg | 8334bc1 | 2012-01-03 10:29:47 -0500 | [diff] [blame] | 4527 | get_shell_surface_type(struct weston_surface *surface) |
Pekka Paalanen | 92a0dc4 | 2011-11-28 15:34:13 +0200 | [diff] [blame] | 4528 | { |
| 4529 | struct shell_surface *shsurf; |
| 4530 | |
| 4531 | shsurf = get_shell_surface(surface); |
| 4532 | if (!shsurf) |
Pekka Paalanen | 9826223 | 2011-12-01 10:42:22 +0200 | [diff] [blame] | 4533 | return SHELL_SURFACE_NONE; |
Pekka Paalanen | 92a0dc4 | 2011-11-28 15:34:13 +0200 | [diff] [blame] | 4534 | return shsurf->type; |
| 4535 | } |
| 4536 | |
Kristian Høgsberg | 7584062 | 2011-09-06 13:48:16 -0400 | [diff] [blame] | 4537 | static void |
Kristian Høgsberg | e314875 | 2013-05-06 23:19:49 -0400 | [diff] [blame] | 4538 | 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] | 4539 | { |
Rafal Mielniczuk | b2917a2 | 2014-01-05 20:04:59 +0100 | [diff] [blame] | 4540 | struct weston_surface *focus; |
Pekka Paalanen | 01388e2 | 2013-04-25 13:57:44 +0300 | [diff] [blame] | 4541 | struct weston_surface *surface; |
Kristian Høgsberg | 938b8fa | 2012-05-18 13:46:27 -0400 | [diff] [blame] | 4542 | struct shell_surface *shsurf; |
Kristian Høgsberg | d2abb83 | 2011-11-23 10:52:40 -0500 | [diff] [blame] | 4543 | |
Rafal Mielniczuk | b2917a2 | 2014-01-05 20:04:59 +0100 | [diff] [blame] | 4544 | if (seat->pointer->focus == NULL) |
| 4545 | return; |
| 4546 | |
| 4547 | focus = seat->pointer->focus->surface; |
| 4548 | |
Pekka Paalanen | 01388e2 | 2013-04-25 13:57:44 +0300 | [diff] [blame] | 4549 | surface = weston_surface_get_main_surface(focus); |
Benjamin Franzke | d0f79ab | 2011-11-22 12:43:52 +0100 | [diff] [blame] | 4550 | if (surface == NULL) |
| 4551 | return; |
Kristian Høgsberg | 0793756 | 2011-04-12 17:25:42 -0400 | [diff] [blame] | 4552 | |
Kristian Høgsberg | 938b8fa | 2012-05-18 13:46:27 -0400 | [diff] [blame] | 4553 | shsurf = get_shell_surface(surface); |
Rafael Antognolli | 03b1659 | 2013-12-03 15:35:42 -0200 | [diff] [blame] | 4554 | if (shsurf == NULL || shsurf->state.fullscreen || |
| 4555 | shsurf->state.maximized) |
Kristian Høgsberg | 938b8fa | 2012-05-18 13:46:27 -0400 | [diff] [blame] | 4556 | return; |
| 4557 | |
Derek Foreman | 8aeeac8 | 2015-01-30 13:24:36 -0600 | [diff] [blame] | 4558 | surface_move(shsurf, seat, 0); |
Kristian Høgsberg | 0793756 | 2011-04-12 17:25:42 -0400 | [diff] [blame] | 4559 | } |
| 4560 | |
| 4561 | static void |
Rafael Antognolli | ea997ac | 2013-12-03 15:35:48 -0200 | [diff] [blame] | 4562 | maximize_binding(struct weston_seat *seat, uint32_t time, uint32_t button, void *data) |
| 4563 | { |
Emilio Pozuelo Monfort | 38b58eb | 2014-01-29 11:11:12 +0100 | [diff] [blame] | 4564 | struct weston_surface *focus = seat->keyboard->focus; |
Rafael Antognolli | ea997ac | 2013-12-03 15:35:48 -0200 | [diff] [blame] | 4565 | struct weston_surface *surface; |
| 4566 | struct shell_surface *shsurf; |
| 4567 | |
| 4568 | surface = weston_surface_get_main_surface(focus); |
| 4569 | if (surface == NULL) |
| 4570 | return; |
| 4571 | |
| 4572 | shsurf = get_shell_surface(surface); |
| 4573 | if (shsurf == NULL) |
| 4574 | return; |
| 4575 | |
| 4576 | if (!shell_surface_is_xdg_surface(shsurf)) |
| 4577 | return; |
| 4578 | |
Jasper St. Pierre | ab2c108 | 2014-04-10 10:41:46 -0700 | [diff] [blame] | 4579 | shsurf->state_requested = true; |
| 4580 | shsurf->requested_state.maximized = !shsurf->state.maximized; |
Jasper St. Pierre | 9aa8ce6 | 2014-04-11 16:18:54 -0700 | [diff] [blame] | 4581 | send_configure_for_surface(shsurf); |
Rafael Antognolli | ea997ac | 2013-12-03 15:35:48 -0200 | [diff] [blame] | 4582 | } |
| 4583 | |
| 4584 | static void |
| 4585 | fullscreen_binding(struct weston_seat *seat, uint32_t time, uint32_t button, void *data) |
| 4586 | { |
Emilio Pozuelo Monfort | 38b58eb | 2014-01-29 11:11:12 +0100 | [diff] [blame] | 4587 | struct weston_surface *focus = seat->keyboard->focus; |
Rafael Antognolli | ea997ac | 2013-12-03 15:35:48 -0200 | [diff] [blame] | 4588 | struct weston_surface *surface; |
| 4589 | struct shell_surface *shsurf; |
| 4590 | |
| 4591 | surface = weston_surface_get_main_surface(focus); |
| 4592 | if (surface == NULL) |
| 4593 | return; |
| 4594 | |
| 4595 | shsurf = get_shell_surface(surface); |
| 4596 | if (shsurf == NULL) |
| 4597 | return; |
| 4598 | |
| 4599 | if (!shell_surface_is_xdg_surface(shsurf)) |
| 4600 | return; |
| 4601 | |
Jasper St. Pierre | ab2c108 | 2014-04-10 10:41:46 -0700 | [diff] [blame] | 4602 | shsurf->state_requested = true; |
| 4603 | shsurf->requested_state.fullscreen = !shsurf->state.fullscreen; |
Boyan Ding | 32abdbb | 2014-06-26 10:19:32 +0800 | [diff] [blame] | 4604 | shsurf->fullscreen_output = shsurf->output; |
Jasper St. Pierre | 9aa8ce6 | 2014-04-11 16:18:54 -0700 | [diff] [blame] | 4605 | send_configure_for_surface(shsurf); |
Rafael Antognolli | ea997ac | 2013-12-03 15:35:48 -0200 | [diff] [blame] | 4606 | } |
| 4607 | |
| 4608 | static void |
Neil Roberts | aba0f25 | 2013-10-03 16:43:05 +0100 | [diff] [blame] | 4609 | touch_move_binding(struct weston_seat *seat, uint32_t time, void *data) |
| 4610 | { |
Derek Foreman | 362656b | 2014-09-04 10:23:05 -0500 | [diff] [blame] | 4611 | struct weston_surface *focus; |
Neil Roberts | aba0f25 | 2013-10-03 16:43:05 +0100 | [diff] [blame] | 4612 | struct weston_surface *surface; |
| 4613 | struct shell_surface *shsurf; |
| 4614 | |
Derek Foreman | 362656b | 2014-09-04 10:23:05 -0500 | [diff] [blame] | 4615 | if (seat->touch->focus == NULL) |
| 4616 | return; |
| 4617 | |
| 4618 | focus = seat->touch->focus->surface; |
Neil Roberts | aba0f25 | 2013-10-03 16:43:05 +0100 | [diff] [blame] | 4619 | surface = weston_surface_get_main_surface(focus); |
| 4620 | if (surface == NULL) |
| 4621 | return; |
| 4622 | |
| 4623 | shsurf = get_shell_surface(surface); |
Rafael Antognolli | 03b1659 | 2013-12-03 15:35:42 -0200 | [diff] [blame] | 4624 | if (shsurf == NULL || shsurf->state.fullscreen || |
| 4625 | shsurf->state.maximized) |
Neil Roberts | aba0f25 | 2013-10-03 16:43:05 +0100 | [diff] [blame] | 4626 | return; |
| 4627 | |
Derek Foreman | 8aeeac8 | 2015-01-30 13:24:36 -0600 | [diff] [blame] | 4628 | surface_touch_move(shsurf, seat); |
Neil Roberts | aba0f25 | 2013-10-03 16:43:05 +0100 | [diff] [blame] | 4629 | } |
| 4630 | |
| 4631 | static void |
Kristian Høgsberg | e314875 | 2013-05-06 23:19:49 -0400 | [diff] [blame] | 4632 | 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] | 4633 | { |
Rafal Mielniczuk | b2917a2 | 2014-01-05 20:04:59 +0100 | [diff] [blame] | 4634 | struct weston_surface *focus; |
Pekka Paalanen | 01388e2 | 2013-04-25 13:57:44 +0300 | [diff] [blame] | 4635 | struct weston_surface *surface; |
Kristian Høgsberg | 0793756 | 2011-04-12 17:25:42 -0400 | [diff] [blame] | 4636 | uint32_t edges = 0; |
| 4637 | int32_t x, y; |
Pekka Paalanen | 9d1613e | 2011-11-25 12:09:16 +0200 | [diff] [blame] | 4638 | struct shell_surface *shsurf; |
Kristian Høgsberg | d2abb83 | 2011-11-23 10:52:40 -0500 | [diff] [blame] | 4639 | |
Rafal Mielniczuk | b2917a2 | 2014-01-05 20:04:59 +0100 | [diff] [blame] | 4640 | if (seat->pointer->focus == NULL) |
| 4641 | return; |
| 4642 | |
| 4643 | focus = seat->pointer->focus->surface; |
| 4644 | |
Pekka Paalanen | 01388e2 | 2013-04-25 13:57:44 +0300 | [diff] [blame] | 4645 | surface = weston_surface_get_main_surface(focus); |
Benjamin Franzke | d0f79ab | 2011-11-22 12:43:52 +0100 | [diff] [blame] | 4646 | if (surface == NULL) |
| 4647 | return; |
Pekka Paalanen | 92a0dc4 | 2011-11-28 15:34:13 +0200 | [diff] [blame] | 4648 | |
Pekka Paalanen | 9d1613e | 2011-11-25 12:09:16 +0200 | [diff] [blame] | 4649 | shsurf = get_shell_surface(surface); |
Rafael Antognolli | 03b1659 | 2013-12-03 15:35:42 -0200 | [diff] [blame] | 4650 | if (shsurf == NULL || shsurf->state.fullscreen || |
| 4651 | shsurf->state.maximized) |
Pekka Paalanen | 92a0dc4 | 2011-11-28 15:34:13 +0200 | [diff] [blame] | 4652 | return; |
| 4653 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 4654 | weston_view_from_global(shsurf->view, |
| 4655 | wl_fixed_to_int(seat->pointer->grab_x), |
| 4656 | wl_fixed_to_int(seat->pointer->grab_y), |
| 4657 | &x, &y); |
Kristian Høgsberg | 0793756 | 2011-04-12 17:25:42 -0400 | [diff] [blame] | 4658 | |
Jason Ekstrand | 918f2dd | 2013-12-02 21:01:53 -0600 | [diff] [blame] | 4659 | if (x < shsurf->surface->width / 3) |
Pekka Paalanen | 9d1613e | 2011-11-25 12:09:16 +0200 | [diff] [blame] | 4660 | edges |= WL_SHELL_SURFACE_RESIZE_LEFT; |
Jason Ekstrand | 918f2dd | 2013-12-02 21:01:53 -0600 | [diff] [blame] | 4661 | else if (x < 2 * shsurf->surface->width / 3) |
Kristian Høgsberg | 0793756 | 2011-04-12 17:25:42 -0400 | [diff] [blame] | 4662 | edges |= 0; |
| 4663 | else |
Pekka Paalanen | 9d1613e | 2011-11-25 12:09:16 +0200 | [diff] [blame] | 4664 | edges |= WL_SHELL_SURFACE_RESIZE_RIGHT; |
Kristian Høgsberg | 0793756 | 2011-04-12 17:25:42 -0400 | [diff] [blame] | 4665 | |
Jason Ekstrand | 918f2dd | 2013-12-02 21:01:53 -0600 | [diff] [blame] | 4666 | if (y < shsurf->surface->height / 3) |
Pekka Paalanen | 9d1613e | 2011-11-25 12:09:16 +0200 | [diff] [blame] | 4667 | edges |= WL_SHELL_SURFACE_RESIZE_TOP; |
Jason Ekstrand | 918f2dd | 2013-12-02 21:01:53 -0600 | [diff] [blame] | 4668 | else if (y < 2 * shsurf->surface->height / 3) |
Kristian Høgsberg | 0793756 | 2011-04-12 17:25:42 -0400 | [diff] [blame] | 4669 | edges |= 0; |
| 4670 | else |
Pekka Paalanen | 9d1613e | 2011-11-25 12:09:16 +0200 | [diff] [blame] | 4671 | edges |= WL_SHELL_SURFACE_RESIZE_BOTTOM; |
Kristian Høgsberg | 0793756 | 2011-04-12 17:25:42 -0400 | [diff] [blame] | 4672 | |
Derek Foreman | 8aeeac8 | 2015-01-30 13:24:36 -0600 | [diff] [blame] | 4673 | surface_resize(shsurf, seat, edges); |
Kristian Høgsberg | 02ec0a5 | 2011-04-23 13:04:11 -0400 | [diff] [blame] | 4674 | } |
| 4675 | |
| 4676 | static void |
Kristian Høgsberg | e314875 | 2013-05-06 23:19:49 -0400 | [diff] [blame] | 4677 | 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] | 4678 | wl_fixed_t value, void *data) |
Scott Moreau | a3aa9c9 | 2012-03-22 11:01:03 -0600 | [diff] [blame] | 4679 | { |
Jonas Ådahl | b0b87ba | 2012-09-27 18:40:42 +0200 | [diff] [blame] | 4680 | float step = 0.005; |
Scott Moreau | a3aa9c9 | 2012-03-22 11:01:03 -0600 | [diff] [blame] | 4681 | struct shell_surface *shsurf; |
Kristian Høgsberg | 7ab139c | 2013-10-24 16:21:39 -0700 | [diff] [blame] | 4682 | struct weston_surface *focus = seat->pointer->focus->surface; |
Pekka Paalanen | 01388e2 | 2013-04-25 13:57:44 +0300 | [diff] [blame] | 4683 | struct weston_surface *surface; |
Scott Moreau | a3aa9c9 | 2012-03-22 11:01:03 -0600 | [diff] [blame] | 4684 | |
Pekka Paalanen | 01388e2 | 2013-04-25 13:57:44 +0300 | [diff] [blame] | 4685 | /* XXX: broken for windows containing sub-surfaces */ |
| 4686 | surface = weston_surface_get_main_surface(focus); |
Scott Moreau | a3aa9c9 | 2012-03-22 11:01:03 -0600 | [diff] [blame] | 4687 | if (surface == NULL) |
| 4688 | return; |
| 4689 | |
| 4690 | shsurf = get_shell_surface(surface); |
| 4691 | if (!shsurf) |
| 4692 | return; |
| 4693 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 4694 | shsurf->view->alpha -= wl_fixed_to_double(value) * step; |
Scott Moreau | a3aa9c9 | 2012-03-22 11:01:03 -0600 | [diff] [blame] | 4695 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 4696 | if (shsurf->view->alpha > 1.0) |
| 4697 | shsurf->view->alpha = 1.0; |
| 4698 | if (shsurf->view->alpha < step) |
| 4699 | shsurf->view->alpha = step; |
Scott Moreau | a3aa9c9 | 2012-03-22 11:01:03 -0600 | [diff] [blame] | 4700 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 4701 | weston_view_geometry_dirty(shsurf->view); |
Scott Moreau | a3aa9c9 | 2012-03-22 11:01:03 -0600 | [diff] [blame] | 4702 | weston_surface_damage(surface); |
| 4703 | } |
| 4704 | |
| 4705 | static void |
Kristian Høgsberg | e314875 | 2013-05-06 23:19:49 -0400 | [diff] [blame] | 4706 | 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] | 4707 | wl_fixed_t value) |
Scott Moreau | ccbf29d | 2012-02-22 14:21:41 -0700 | [diff] [blame] | 4708 | { |
Derek Foreman | 8aeeac8 | 2015-01-30 13:24:36 -0600 | [diff] [blame] | 4709 | struct weston_compositor *compositor = seat->compositor; |
Scott Moreau | ccbf29d | 2012-02-22 14:21:41 -0700 | [diff] [blame] | 4710 | struct weston_output *output; |
Scott Moreau | e660398 | 2012-06-11 13:07:51 -0600 | [diff] [blame] | 4711 | float increment; |
Scott Moreau | ccbf29d | 2012-02-22 14:21:41 -0700 | [diff] [blame] | 4712 | |
Derek Foreman | 7ef3bed | 2015-01-06 14:28:13 -0600 | [diff] [blame] | 4713 | if (!seat->pointer) { |
| 4714 | weston_log("Zoom hotkey pressed but seat '%s' contains no pointer.\n", seat->seat_name); |
| 4715 | return; |
| 4716 | } |
| 4717 | |
Scott Moreau | ccbf29d | 2012-02-22 14:21:41 -0700 | [diff] [blame] | 4718 | wl_list_for_each(output, &compositor->output_list, link) { |
| 4719 | if (pixman_region32_contains_point(&output->region, |
Daniel Stone | 37816df | 2012-05-16 18:45:18 +0100 | [diff] [blame] | 4720 | wl_fixed_to_double(seat->pointer->x), |
| 4721 | wl_fixed_to_double(seat->pointer->y), |
Daniel Stone | 103db7f | 2012-05-08 17:17:55 +0100 | [diff] [blame] | 4722 | NULL)) { |
Daniel Stone | 325fc2d | 2012-05-30 16:31:58 +0100 | [diff] [blame] | 4723 | if (key == KEY_PAGEUP) |
Kristian Høgsberg | 9b68af0 | 2012-05-22 12:55:18 -0400 | [diff] [blame] | 4724 | increment = output->zoom.increment; |
Daniel Stone | 325fc2d | 2012-05-30 16:31:58 +0100 | [diff] [blame] | 4725 | else if (key == KEY_PAGEDOWN) |
Kristian Høgsberg | 9b68af0 | 2012-05-22 12:55:18 -0400 | [diff] [blame] | 4726 | increment = -output->zoom.increment; |
| 4727 | else if (axis == WL_POINTER_AXIS_VERTICAL_SCROLL) |
Jonas Ådahl | b0b87ba | 2012-09-27 18:40:42 +0200 | [diff] [blame] | 4728 | /* For every pixel zoom 20th of a step */ |
Daniel Stone | 0c1e46e | 2012-05-30 16:31:59 +0100 | [diff] [blame] | 4729 | increment = output->zoom.increment * |
Jonas Ådahl | b0b87ba | 2012-09-27 18:40:42 +0200 | [diff] [blame] | 4730 | -wl_fixed_to_double(value) / 20.0; |
Kristian Høgsberg | 9b68af0 | 2012-05-22 12:55:18 -0400 | [diff] [blame] | 4731 | else |
| 4732 | increment = 0; |
| 4733 | |
Kristian Høgsberg | 9b68af0 | 2012-05-22 12:55:18 -0400 | [diff] [blame] | 4734 | output->zoom.level += increment; |
Scott Moreau | c6d7f60 | 2012-02-23 22:28:37 -0700 | [diff] [blame] | 4735 | |
Scott Moreau | e660398 | 2012-06-11 13:07:51 -0600 | [diff] [blame] | 4736 | if (output->zoom.level < 0.0) |
Scott Moreau | 850ca42 | 2012-05-21 15:21:25 -0600 | [diff] [blame] | 4737 | output->zoom.level = 0.0; |
Scott Moreau | e660398 | 2012-06-11 13:07:51 -0600 | [diff] [blame] | 4738 | else if (output->zoom.level > output->zoom.max_level) |
| 4739 | output->zoom.level = output->zoom.max_level; |
Ville Syrjälä | aa628d0 | 2012-11-16 11:48:47 +0200 | [diff] [blame] | 4740 | else if (!output->zoom.active) { |
Giulio Camuffo | 412b024 | 2013-11-14 23:42:51 +0100 | [diff] [blame] | 4741 | weston_output_activate_zoom(output); |
Kristian Høgsberg | 79af73e | 2012-08-03 15:45:23 -0400 | [diff] [blame] | 4742 | } |
Scott Moreau | ccbf29d | 2012-02-22 14:21:41 -0700 | [diff] [blame] | 4743 | |
Scott Moreau | e660398 | 2012-06-11 13:07:51 -0600 | [diff] [blame] | 4744 | output->zoom.spring_z.target = output->zoom.level; |
Scott Moreau | ccbf29d | 2012-02-22 14:21:41 -0700 | [diff] [blame] | 4745 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 4746 | weston_output_update_zoom(output); |
Scott Moreau | ccbf29d | 2012-02-22 14:21:41 -0700 | [diff] [blame] | 4747 | } |
| 4748 | } |
| 4749 | } |
| 4750 | |
Scott Moreau | ccbf29d | 2012-02-22 14:21:41 -0700 | [diff] [blame] | 4751 | static void |
Kristian Høgsberg | e314875 | 2013-05-06 23:19:49 -0400 | [diff] [blame] | 4752 | 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] | 4753 | wl_fixed_t value, void *data) |
Daniel Stone | 325fc2d | 2012-05-30 16:31:58 +0100 | [diff] [blame] | 4754 | { |
| 4755 | do_zoom(seat, time, 0, axis, value); |
| 4756 | } |
| 4757 | |
| 4758 | static void |
Kristian Høgsberg | e314875 | 2013-05-06 23:19:49 -0400 | [diff] [blame] | 4759 | 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] | 4760 | void *data) |
| 4761 | { |
| 4762 | do_zoom(seat, time, key, 0, 0); |
| 4763 | } |
| 4764 | |
| 4765 | static void |
Kristian Høgsberg | e314875 | 2013-05-06 23:19:49 -0400 | [diff] [blame] | 4766 | terminate_binding(struct weston_seat *seat, uint32_t time, uint32_t key, |
Daniel Stone | 325fc2d | 2012-05-30 16:31:58 +0100 | [diff] [blame] | 4767 | void *data) |
Kristian Høgsberg | e1a850e | 2011-12-19 15:18:05 -0500 | [diff] [blame] | 4768 | { |
Kristian Høgsberg | 8334bc1 | 2012-01-03 10:29:47 -0500 | [diff] [blame] | 4769 | struct weston_compositor *compositor = data; |
Kristian Høgsberg | e1a850e | 2011-12-19 15:18:05 -0500 | [diff] [blame] | 4770 | |
Daniel Stone | 325fc2d | 2012-05-30 16:31:58 +0100 | [diff] [blame] | 4771 | wl_display_terminate(compositor->wl_display); |
Kristian Høgsberg | e1a850e | 2011-12-19 15:18:05 -0500 | [diff] [blame] | 4772 | } |
| 4773 | |
Emilio Pozuelo Monfort | 03251b6 | 2013-11-19 11:37:16 +0100 | [diff] [blame] | 4774 | static void |
Giulio Camuffo | 1959ab8 | 2013-11-14 23:42:52 +0100 | [diff] [blame] | 4775 | rotate_grab_motion(struct weston_pointer_grab *grab, uint32_t time, |
| 4776 | wl_fixed_t x, wl_fixed_t y) |
Pekka Paalanen | 460099f | 2012-01-20 16:48:25 +0200 | [diff] [blame] | 4777 | { |
| 4778 | struct rotate_grab *rotate = |
Ander Conselvan de Oliveira | fe0444a | 2012-04-04 17:48:05 +0300 | [diff] [blame] | 4779 | container_of(grab, struct rotate_grab, base.grab); |
Kristian Høgsberg | 02bbabb | 2013-05-06 22:15:05 -0400 | [diff] [blame] | 4780 | struct weston_pointer *pointer = grab->pointer; |
Ander Conselvan de Oliveira | fe0444a | 2012-04-04 17:48:05 +0300 | [diff] [blame] | 4781 | struct shell_surface *shsurf = rotate->base.shsurf; |
John Kåre Alsaker | 490d02a | 2012-09-30 02:57:21 +0200 | [diff] [blame] | 4782 | float cx, cy, dx, dy, cposx, cposy, dposx, dposy, r; |
Ander Conselvan de Oliveira | fe0444a | 2012-04-04 17:48:05 +0300 | [diff] [blame] | 4783 | |
Giulio Camuffo | 1959ab8 | 2013-11-14 23:42:52 +0100 | [diff] [blame] | 4784 | weston_pointer_move(pointer, x, y); |
| 4785 | |
Ander Conselvan de Oliveira | fe0444a | 2012-04-04 17:48:05 +0300 | [diff] [blame] | 4786 | if (!shsurf) |
| 4787 | return; |
| 4788 | |
Jason Ekstrand | 918f2dd | 2013-12-02 21:01:53 -0600 | [diff] [blame] | 4789 | cx = 0.5f * shsurf->surface->width; |
| 4790 | cy = 0.5f * shsurf->surface->height; |
Pekka Paalanen | 460099f | 2012-01-20 16:48:25 +0200 | [diff] [blame] | 4791 | |
Daniel Stone | 37816df | 2012-05-16 18:45:18 +0100 | [diff] [blame] | 4792 | dx = wl_fixed_to_double(pointer->x) - rotate->center.x; |
| 4793 | dy = wl_fixed_to_double(pointer->y) - rotate->center.y; |
Pekka Paalanen | 460099f | 2012-01-20 16:48:25 +0200 | [diff] [blame] | 4794 | r = sqrtf(dx * dx + dy * dy); |
| 4795 | |
Ander Conselvan de Oliveira | fe0444a | 2012-04-04 17:48:05 +0300 | [diff] [blame] | 4796 | wl_list_remove(&shsurf->rotation.transform.link); |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 4797 | weston_view_geometry_dirty(shsurf->view); |
Pekka Paalanen | 460099f | 2012-01-20 16:48:25 +0200 | [diff] [blame] | 4798 | |
| 4799 | if (r > 20.0f) { |
Pekka Paalanen | 460099f | 2012-01-20 16:48:25 +0200 | [diff] [blame] | 4800 | struct weston_matrix *matrix = |
Ander Conselvan de Oliveira | fe0444a | 2012-04-04 17:48:05 +0300 | [diff] [blame] | 4801 | &shsurf->rotation.transform.matrix; |
Pekka Paalanen | 460099f | 2012-01-20 16:48:25 +0200 | [diff] [blame] | 4802 | |
Kristian Høgsberg | 765e27b | 2012-01-27 13:36:13 -0500 | [diff] [blame] | 4803 | weston_matrix_init(&rotate->rotation); |
Vasily Khoruzhick | 1bbf372 | 2013-01-28 22:40:28 +0300 | [diff] [blame] | 4804 | weston_matrix_rotate_xy(&rotate->rotation, dx / r, dy / r); |
Pekka Paalanen | 460099f | 2012-01-20 16:48:25 +0200 | [diff] [blame] | 4805 | |
| 4806 | weston_matrix_init(matrix); |
Pekka Paalanen | 7b3bd3d | 2012-01-30 14:16:34 +0200 | [diff] [blame] | 4807 | weston_matrix_translate(matrix, -cx, -cy, 0.0f); |
Ander Conselvan de Oliveira | fe0444a | 2012-04-04 17:48:05 +0300 | [diff] [blame] | 4808 | weston_matrix_multiply(matrix, &shsurf->rotation.rotation); |
Kristian Høgsberg | 765e27b | 2012-01-27 13:36:13 -0500 | [diff] [blame] | 4809 | weston_matrix_multiply(matrix, &rotate->rotation); |
Pekka Paalanen | 7b3bd3d | 2012-01-30 14:16:34 +0200 | [diff] [blame] | 4810 | weston_matrix_translate(matrix, cx, cy, 0.0f); |
Pekka Paalanen | 460099f | 2012-01-20 16:48:25 +0200 | [diff] [blame] | 4811 | |
Pekka Paalanen | bc0b7e7 | 2012-01-24 09:53:37 +0200 | [diff] [blame] | 4812 | wl_list_insert( |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 4813 | &shsurf->view->geometry.transformation_list, |
Ander Conselvan de Oliveira | fe0444a | 2012-04-04 17:48:05 +0300 | [diff] [blame] | 4814 | &shsurf->rotation.transform.link); |
Pekka Paalanen | 460099f | 2012-01-20 16:48:25 +0200 | [diff] [blame] | 4815 | } else { |
Ander Conselvan de Oliveira | fe0444a | 2012-04-04 17:48:05 +0300 | [diff] [blame] | 4816 | wl_list_init(&shsurf->rotation.transform.link); |
| 4817 | weston_matrix_init(&shsurf->rotation.rotation); |
Kristian Høgsberg | 765e27b | 2012-01-27 13:36:13 -0500 | [diff] [blame] | 4818 | weston_matrix_init(&rotate->rotation); |
Pekka Paalanen | 460099f | 2012-01-20 16:48:25 +0200 | [diff] [blame] | 4819 | } |
Pekka Paalanen | b45ac5e | 2012-02-09 15:58:44 +0200 | [diff] [blame] | 4820 | |
Rafal Mielniczuk | 2d7ab82 | 2012-03-22 22:22:04 +0100 | [diff] [blame] | 4821 | /* We need to adjust the position of the surface |
| 4822 | * in case it was resized in a rotated state before */ |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 4823 | cposx = shsurf->view->geometry.x + cx; |
| 4824 | cposy = shsurf->view->geometry.y + cy; |
Rafal Mielniczuk | 2d7ab82 | 2012-03-22 22:22:04 +0100 | [diff] [blame] | 4825 | dposx = rotate->center.x - cposx; |
| 4826 | dposy = rotate->center.y - cposy; |
| 4827 | if (dposx != 0.0f || dposy != 0.0f) { |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 4828 | weston_view_set_position(shsurf->view, |
| 4829 | shsurf->view->geometry.x + dposx, |
| 4830 | shsurf->view->geometry.y + dposy); |
Rafal Mielniczuk | 2d7ab82 | 2012-03-22 22:22:04 +0100 | [diff] [blame] | 4831 | } |
| 4832 | |
Derek Foreman | 4b1a0a1 | 2014-09-10 15:37:33 -0500 | [diff] [blame] | 4833 | /* Repaint implies weston_view_update_transform(), which |
Pekka Paalanen | b45ac5e | 2012-02-09 15:58:44 +0200 | [diff] [blame] | 4834 | * lazily applies the damage due to rotation update. |
| 4835 | */ |
Ander Conselvan de Oliveira | fe0444a | 2012-04-04 17:48:05 +0300 | [diff] [blame] | 4836 | weston_compositor_schedule_repaint(shsurf->surface->compositor); |
Pekka Paalanen | 460099f | 2012-01-20 16:48:25 +0200 | [diff] [blame] | 4837 | } |
| 4838 | |
| 4839 | static void |
Kristian Høgsberg | 02bbabb | 2013-05-06 22:15:05 -0400 | [diff] [blame] | 4840 | rotate_grab_button(struct weston_pointer_grab *grab, |
| 4841 | uint32_t time, uint32_t button, uint32_t state_w) |
Pekka Paalanen | 460099f | 2012-01-20 16:48:25 +0200 | [diff] [blame] | 4842 | { |
| 4843 | struct rotate_grab *rotate = |
Ander Conselvan de Oliveira | fe0444a | 2012-04-04 17:48:05 +0300 | [diff] [blame] | 4844 | container_of(grab, struct rotate_grab, base.grab); |
Kristian Høgsberg | 02bbabb | 2013-05-06 22:15:05 -0400 | [diff] [blame] | 4845 | struct weston_pointer *pointer = grab->pointer; |
Ander Conselvan de Oliveira | fe0444a | 2012-04-04 17:48:05 +0300 | [diff] [blame] | 4846 | struct shell_surface *shsurf = rotate->base.shsurf; |
Daniel Stone | 4dbadb1 | 2012-05-30 16:31:51 +0100 | [diff] [blame] | 4847 | enum wl_pointer_button_state state = state_w; |
Pekka Paalanen | 460099f | 2012-01-20 16:48:25 +0200 | [diff] [blame] | 4848 | |
Daniel Stone | 4dbadb1 | 2012-05-30 16:31:51 +0100 | [diff] [blame] | 4849 | if (pointer->button_count == 0 && |
| 4850 | state == WL_POINTER_BUTTON_STATE_RELEASED) { |
Ander Conselvan de Oliveira | fe0444a | 2012-04-04 17:48:05 +0300 | [diff] [blame] | 4851 | if (shsurf) |
| 4852 | weston_matrix_multiply(&shsurf->rotation.rotation, |
| 4853 | &rotate->rotation); |
Ander Conselvan de Oliveira | b9d2a0f | 2012-06-28 18:08:05 +0300 | [diff] [blame] | 4854 | shell_grab_end(&rotate->base); |
Pekka Paalanen | 460099f | 2012-01-20 16:48:25 +0200 | [diff] [blame] | 4855 | free(rotate); |
| 4856 | } |
| 4857 | } |
| 4858 | |
Jonas Ådahl | 1ea343e | 2013-10-25 23:18:05 +0200 | [diff] [blame] | 4859 | static void |
| 4860 | rotate_grab_cancel(struct weston_pointer_grab *grab) |
| 4861 | { |
| 4862 | struct rotate_grab *rotate = |
| 4863 | container_of(grab, struct rotate_grab, base.grab); |
| 4864 | |
| 4865 | shell_grab_end(&rotate->base); |
| 4866 | free(rotate); |
| 4867 | } |
| 4868 | |
Kristian Høgsberg | 02bbabb | 2013-05-06 22:15:05 -0400 | [diff] [blame] | 4869 | static const struct weston_pointer_grab_interface rotate_grab_interface = { |
Pekka Paalanen | 460099f | 2012-01-20 16:48:25 +0200 | [diff] [blame] | 4870 | noop_grab_focus, |
| 4871 | rotate_grab_motion, |
| 4872 | rotate_grab_button, |
Jonas Ådahl | 1ea343e | 2013-10-25 23:18:05 +0200 | [diff] [blame] | 4873 | rotate_grab_cancel, |
Pekka Paalanen | 460099f | 2012-01-20 16:48:25 +0200 | [diff] [blame] | 4874 | }; |
| 4875 | |
| 4876 | static void |
Kristian Høgsberg | e314875 | 2013-05-06 23:19:49 -0400 | [diff] [blame] | 4877 | surface_rotate(struct shell_surface *surface, struct weston_seat *seat) |
Pekka Paalanen | 460099f | 2012-01-20 16:48:25 +0200 | [diff] [blame] | 4878 | { |
Pekka Paalanen | 460099f | 2012-01-20 16:48:25 +0200 | [diff] [blame] | 4879 | struct rotate_grab *rotate; |
John Kåre Alsaker | 490d02a | 2012-09-30 02:57:21 +0200 | [diff] [blame] | 4880 | float dx, dy; |
| 4881 | float r; |
Pekka Paalanen | 460099f | 2012-01-20 16:48:25 +0200 | [diff] [blame] | 4882 | |
Pekka Paalanen | 460099f | 2012-01-20 16:48:25 +0200 | [diff] [blame] | 4883 | rotate = malloc(sizeof *rotate); |
| 4884 | if (!rotate) |
| 4885 | return; |
| 4886 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 4887 | weston_view_to_global_float(surface->view, |
Jason Ekstrand | 918f2dd | 2013-12-02 21:01:53 -0600 | [diff] [blame] | 4888 | surface->surface->width * 0.5f, |
| 4889 | surface->surface->height * 0.5f, |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 4890 | &rotate->center.x, &rotate->center.y); |
Pekka Paalanen | 460099f | 2012-01-20 16:48:25 +0200 | [diff] [blame] | 4891 | |
Daniel Stone | 37816df | 2012-05-16 18:45:18 +0100 | [diff] [blame] | 4892 | dx = wl_fixed_to_double(seat->pointer->x) - rotate->center.x; |
| 4893 | dy = wl_fixed_to_double(seat->pointer->y) - rotate->center.y; |
Kristian Høgsberg | 765e27b | 2012-01-27 13:36:13 -0500 | [diff] [blame] | 4894 | r = sqrtf(dx * dx + dy * dy); |
| 4895 | if (r > 20.0f) { |
| 4896 | struct weston_matrix inverse; |
| 4897 | |
| 4898 | weston_matrix_init(&inverse); |
Vasily Khoruzhick | 1bbf372 | 2013-01-28 22:40:28 +0300 | [diff] [blame] | 4899 | weston_matrix_rotate_xy(&inverse, dx / r, -dy / r); |
Kristian Høgsberg | 765e27b | 2012-01-27 13:36:13 -0500 | [diff] [blame] | 4900 | weston_matrix_multiply(&surface->rotation.rotation, &inverse); |
Rafal Mielniczuk | 2d7ab82 | 2012-03-22 22:22:04 +0100 | [diff] [blame] | 4901 | |
| 4902 | weston_matrix_init(&rotate->rotation); |
Vasily Khoruzhick | 1bbf372 | 2013-01-28 22:40:28 +0300 | [diff] [blame] | 4903 | weston_matrix_rotate_xy(&rotate->rotation, dx / r, dy / r); |
Kristian Høgsberg | 765e27b | 2012-01-27 13:36:13 -0500 | [diff] [blame] | 4904 | } else { |
| 4905 | weston_matrix_init(&surface->rotation.rotation); |
| 4906 | weston_matrix_init(&rotate->rotation); |
| 4907 | } |
| 4908 | |
Ander Conselvan de Oliveira | b9d2a0f | 2012-06-28 18:08:05 +0300 | [diff] [blame] | 4909 | shell_grab_start(&rotate->base, &rotate_grab_interface, surface, |
| 4910 | seat->pointer, DESKTOP_SHELL_CURSOR_ARROW); |
Pekka Paalanen | 460099f | 2012-01-20 16:48:25 +0200 | [diff] [blame] | 4911 | } |
| 4912 | |
| 4913 | static void |
Kristian Høgsberg | e314875 | 2013-05-06 23:19:49 -0400 | [diff] [blame] | 4914 | 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] | 4915 | void *data) |
| 4916 | { |
Rafal Mielniczuk | b2917a2 | 2014-01-05 20:04:59 +0100 | [diff] [blame] | 4917 | struct weston_surface *focus; |
Pekka Paalanen | 01388e2 | 2013-04-25 13:57:44 +0300 | [diff] [blame] | 4918 | struct weston_surface *base_surface; |
Kristian Høgsberg | 0c36903 | 2013-02-14 21:31:44 -0500 | [diff] [blame] | 4919 | struct shell_surface *surface; |
| 4920 | |
Rafal Mielniczuk | b2917a2 | 2014-01-05 20:04:59 +0100 | [diff] [blame] | 4921 | if (seat->pointer->focus == NULL) |
| 4922 | return; |
| 4923 | |
| 4924 | focus = seat->pointer->focus->surface; |
| 4925 | |
Pekka Paalanen | 01388e2 | 2013-04-25 13:57:44 +0300 | [diff] [blame] | 4926 | base_surface = weston_surface_get_main_surface(focus); |
Kristian Høgsberg | 0c36903 | 2013-02-14 21:31:44 -0500 | [diff] [blame] | 4927 | if (base_surface == NULL) |
| 4928 | return; |
| 4929 | |
| 4930 | surface = get_shell_surface(base_surface); |
Rafael Antognolli | 03b1659 | 2013-12-03 15:35:42 -0200 | [diff] [blame] | 4931 | if (surface == NULL || surface->state.fullscreen || |
| 4932 | surface->state.maximized) |
Kristian Høgsberg | 0c36903 | 2013-02-14 21:31:44 -0500 | [diff] [blame] | 4933 | return; |
| 4934 | |
| 4935 | surface_rotate(surface, seat); |
| 4936 | } |
| 4937 | |
Emilio Pozuelo Monfort | 9e7c759 | 2014-01-30 14:01:10 +0100 | [diff] [blame] | 4938 | /* Move all fullscreen layers down to the current workspace and hide their |
| 4939 | * black views. The surfaces' state is set to both fullscreen and lowered, |
| 4940 | * and this is reversed when such a surface is re-configured, see |
| 4941 | * shell_configure_fullscreen() and shell_ensure_fullscreen_black_view(). |
| 4942 | * |
| 4943 | * This should be used when implementing shell-wide overlays, such as |
Philip Withnall | 83ffd9d | 2013-11-25 18:01:42 +0000 | [diff] [blame] | 4944 | * the alt-tab switcher, which need to de-promote fullscreen layers. */ |
Kristian Høgsberg | 1ef2313 | 2013-12-04 00:20:01 -0800 | [diff] [blame] | 4945 | void |
Kristian Høgsberg | b0d8e77 | 2012-06-18 16:34:58 -0400 | [diff] [blame] | 4946 | lower_fullscreen_layer(struct desktop_shell *shell) |
| 4947 | { |
| 4948 | struct workspace *ws; |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 4949 | struct weston_view *view, *prev; |
Kristian Høgsberg | b0d8e77 | 2012-06-18 16:34:58 -0400 | [diff] [blame] | 4950 | |
| 4951 | ws = get_current_workspace(shell); |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 4952 | wl_list_for_each_reverse_safe(view, prev, |
Giulio Camuffo | 412e6a5 | 2014-07-09 22:12:56 +0300 | [diff] [blame] | 4953 | &shell->fullscreen_layer.view_list.link, |
| 4954 | layer_link.link) { |
Emilio Pozuelo Monfort | 9e7c759 | 2014-01-30 14:01:10 +0100 | [diff] [blame] | 4955 | struct shell_surface *shsurf = get_shell_surface(view->surface); |
| 4956 | |
| 4957 | if (!shsurf) |
| 4958 | continue; |
| 4959 | |
| 4960 | /* We can have a non-fullscreen popup for a fullscreen surface |
| 4961 | * in the fullscreen layer. */ |
| 4962 | if (shsurf->state.fullscreen) { |
| 4963 | /* Hide the black view */ |
Giulio Camuffo | 412e6a5 | 2014-07-09 22:12:56 +0300 | [diff] [blame] | 4964 | weston_layer_entry_remove(&shsurf->fullscreen.black_view->layer_link); |
| 4965 | wl_list_init(&shsurf->fullscreen.black_view->layer_link.link); |
Kristian Høgsberg | c991513 | 2014-05-09 16:24:07 -0700 | [diff] [blame] | 4966 | weston_view_damage_below(shsurf->fullscreen.black_view); |
| 4967 | |
Emilio Pozuelo Monfort | 9e7c759 | 2014-01-30 14:01:10 +0100 | [diff] [blame] | 4968 | } |
| 4969 | |
| 4970 | /* Lower the view to the workspace layer */ |
Giulio Camuffo | 412e6a5 | 2014-07-09 22:12:56 +0300 | [diff] [blame] | 4971 | weston_layer_entry_remove(&view->layer_link); |
| 4972 | weston_layer_entry_insert(&ws->layer.view_list, &view->layer_link); |
Philip Withnall | 83ffd9d | 2013-11-25 18:01:42 +0000 | [diff] [blame] | 4973 | weston_view_damage_below(view); |
| 4974 | weston_surface_damage(view->surface); |
Emilio Pozuelo Monfort | 9e7c759 | 2014-01-30 14:01:10 +0100 | [diff] [blame] | 4975 | |
| 4976 | shsurf->state.lowered = true; |
Philip Withnall | 83ffd9d | 2013-11-25 18:01:42 +0000 | [diff] [blame] | 4977 | } |
Kristian Høgsberg | b0d8e77 | 2012-06-18 16:34:58 -0400 | [diff] [blame] | 4978 | } |
| 4979 | |
Kristian Høgsberg | 1ef2313 | 2013-12-04 00:20:01 -0800 | [diff] [blame] | 4980 | void |
Tiago Vignatti | be14326 | 2012-04-16 17:31:41 +0300 | [diff] [blame] | 4981 | activate(struct desktop_shell *shell, struct weston_surface *es, |
Emilio Pozuelo Monfort | 9e7c759 | 2014-01-30 14:01:10 +0100 | [diff] [blame] | 4982 | struct weston_seat *seat, bool configure) |
Kristian Høgsberg | 7584062 | 2011-09-06 13:48:16 -0400 | [diff] [blame] | 4983 | { |
Pekka Paalanen | 01388e2 | 2013-04-25 13:57:44 +0300 | [diff] [blame] | 4984 | struct weston_surface *main_surface; |
Kristian Høgsberg | 2f5faff | 2012-07-31 16:36:34 -0400 | [diff] [blame] | 4985 | struct focus_state *state; |
Jonas Ådahl | 8538b22 | 2012-08-29 22:13:03 +0200 | [diff] [blame] | 4986 | struct workspace *ws; |
Louis-Francis Ratté-Boulianne | b482dbd | 2013-11-19 11:37:11 +0100 | [diff] [blame] | 4987 | struct weston_surface *old_es; |
Rafael Antognolli | 03b1659 | 2013-12-03 15:35:42 -0200 | [diff] [blame] | 4988 | struct shell_surface *shsurf; |
Kristian Høgsberg | 7584062 | 2011-09-06 13:48:16 -0400 | [diff] [blame] | 4989 | |
Kristian Høgsberg | 6110d07 | 2014-04-29 15:15:45 -0700 | [diff] [blame] | 4990 | lower_fullscreen_layer(shell); |
| 4991 | |
Pekka Paalanen | 01388e2 | 2013-04-25 13:57:44 +0300 | [diff] [blame] | 4992 | main_surface = weston_surface_get_main_surface(es); |
| 4993 | |
Daniel Stone | 37816df | 2012-05-16 18:45:18 +0100 | [diff] [blame] | 4994 | weston_surface_activate(es, seat); |
Kristian Høgsberg | 7584062 | 2011-09-06 13:48:16 -0400 | [diff] [blame] | 4995 | |
Jonas Ådahl | 8538b22 | 2012-08-29 22:13:03 +0200 | [diff] [blame] | 4996 | state = ensure_focus_state(shell, seat); |
| 4997 | if (state == NULL) |
| 4998 | return; |
Kristian Høgsberg | 2f5faff | 2012-07-31 16:36:34 -0400 | [diff] [blame] | 4999 | |
Louis-Francis Ratté-Boulianne | b482dbd | 2013-11-19 11:37:11 +0100 | [diff] [blame] | 5000 | old_es = state->keyboard_focus; |
Kristian Høgsberg | d500bf1 | 2014-01-22 12:25:20 -0800 | [diff] [blame] | 5001 | focus_state_set_focus(state, es); |
Kristian Høgsberg | 2f5faff | 2012-07-31 16:36:34 -0400 | [diff] [blame] | 5002 | |
Rafael Antognolli | 03b1659 | 2013-12-03 15:35:42 -0200 | [diff] [blame] | 5003 | shsurf = get_shell_surface(main_surface); |
U. Artie Eoff | cf5737a | 2014-01-17 10:08:25 -0800 | [diff] [blame] | 5004 | assert(shsurf); |
| 5005 | |
Emilio Pozuelo Monfort | 9e7c759 | 2014-01-30 14:01:10 +0100 | [diff] [blame] | 5006 | if (shsurf->state.fullscreen && configure) |
Rafael Antognolli | 03b1659 | 2013-12-03 15:35:42 -0200 | [diff] [blame] | 5007 | shell_configure_fullscreen(shsurf); |
| 5008 | else |
Alexander Larsson | f82b6ca | 2013-05-28 16:23:39 +0200 | [diff] [blame] | 5009 | restore_all_output_modes(shell->compositor); |
Louis-Francis Ratté-Boulianne | b482dbd | 2013-11-19 11:37:11 +0100 | [diff] [blame] | 5010 | |
Emilio Pozuelo Monfort | 7908bff | 2014-01-30 13:49:39 +0100 | [diff] [blame] | 5011 | /* Update the surface’s layer. This brings it to the top of the stacking |
| 5012 | * order as appropriate. */ |
| 5013 | shell_surface_update_layer(shsurf); |
| 5014 | |
Philip Withnall | 83ffd9d | 2013-11-25 18:01:42 +0000 | [diff] [blame] | 5015 | if (shell->focus_animation_type != ANIMATION_NONE) { |
| 5016 | ws = get_current_workspace(shell); |
Louis-Francis Ratté-Boulianne | b482dbd | 2013-11-19 11:37:11 +0100 | [diff] [blame] | 5017 | 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] | 5018 | } |
Kristian Høgsberg | 7584062 | 2011-09-06 13:48:16 -0400 | [diff] [blame] | 5019 | } |
| 5020 | |
Alex Wu | 2185843 | 2012-04-01 20:13:08 +0800 | [diff] [blame] | 5021 | /* no-op func for checking black surface */ |
| 5022 | static void |
Jason Ekstrand | 918f2dd | 2013-12-02 21:01:53 -0600 | [diff] [blame] | 5023 | 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] | 5024 | { |
| 5025 | } |
| 5026 | |
Quentin Glidic | c0d79ce | 2013-01-29 14:16:13 +0100 | [diff] [blame] | 5027 | static bool |
Alex Wu | 2185843 | 2012-04-01 20:13:08 +0800 | [diff] [blame] | 5028 | is_black_surface (struct weston_surface *es, struct weston_surface **fs_surface) |
| 5029 | { |
| 5030 | if (es->configure == black_surface_configure) { |
| 5031 | if (fs_surface) |
Giulio Camuffo | 7fe01b1 | 2013-03-28 18:02:42 +0100 | [diff] [blame] | 5032 | *fs_surface = (struct weston_surface *)es->configure_private; |
Alex Wu | 2185843 | 2012-04-01 20:13:08 +0800 | [diff] [blame] | 5033 | return true; |
| 5034 | } |
| 5035 | return false; |
| 5036 | } |
| 5037 | |
Kristian Høgsberg | 7584062 | 2011-09-06 13:48:16 -0400 | [diff] [blame] | 5038 | static void |
Neil Roberts | a28c693 | 2013-10-03 16:43:04 +0100 | [diff] [blame] | 5039 | activate_binding(struct weston_seat *seat, |
| 5040 | struct desktop_shell *shell, |
| 5041 | struct weston_surface *focus) |
Kristian Høgsberg | e1a850e | 2011-12-19 15:18:05 -0500 | [diff] [blame] | 5042 | { |
Pekka Paalanen | 01388e2 | 2013-04-25 13:57:44 +0300 | [diff] [blame] | 5043 | struct weston_surface *main_surface; |
Kristian Høgsberg | e1a850e | 2011-12-19 15:18:05 -0500 | [diff] [blame] | 5044 | |
Alex Wu | 9c35e6b | 2012-03-05 14:13:13 +0800 | [diff] [blame] | 5045 | if (!focus) |
| 5046 | return; |
| 5047 | |
Pekka Paalanen | 01388e2 | 2013-04-25 13:57:44 +0300 | [diff] [blame] | 5048 | if (is_black_surface(focus, &main_surface)) |
| 5049 | focus = main_surface; |
Alex Wu | 4539b08 | 2012-03-01 12:57:46 +0800 | [diff] [blame] | 5050 | |
Pekka Paalanen | 01388e2 | 2013-04-25 13:57:44 +0300 | [diff] [blame] | 5051 | main_surface = weston_surface_get_main_surface(focus); |
| 5052 | if (get_shell_surface_type(main_surface) == SHELL_SURFACE_NONE) |
Kristian Høgsberg | 0636ac3 | 2012-06-27 10:22:15 -0400 | [diff] [blame] | 5053 | return; |
Kristian Høgsberg | 85b2e4b | 2012-06-21 16:49:42 -0400 | [diff] [blame] | 5054 | |
Emilio Pozuelo Monfort | 9e7c759 | 2014-01-30 14:01:10 +0100 | [diff] [blame] | 5055 | activate(shell, focus, seat, true); |
Neil Roberts | a28c693 | 2013-10-03 16:43:04 +0100 | [diff] [blame] | 5056 | } |
| 5057 | |
| 5058 | static void |
| 5059 | click_to_activate_binding(struct weston_seat *seat, uint32_t time, uint32_t button, |
| 5060 | void *data) |
| 5061 | { |
| 5062 | if (seat->pointer->grab != &seat->pointer->default_grab) |
| 5063 | return; |
Kristian Høgsberg | 7c4f6cc | 2014-01-01 16:28:32 -0800 | [diff] [blame] | 5064 | if (seat->pointer->focus == NULL) |
| 5065 | return; |
Neil Roberts | a28c693 | 2013-10-03 16:43:04 +0100 | [diff] [blame] | 5066 | |
Kristian Høgsberg | 7ab139c | 2013-10-24 16:21:39 -0700 | [diff] [blame] | 5067 | activate_binding(seat, data, seat->pointer->focus->surface); |
Neil Roberts | a28c693 | 2013-10-03 16:43:04 +0100 | [diff] [blame] | 5068 | } |
| 5069 | |
| 5070 | static void |
| 5071 | touch_to_activate_binding(struct weston_seat *seat, uint32_t time, void *data) |
| 5072 | { |
| 5073 | if (seat->touch->grab != &seat->touch->default_grab) |
| 5074 | return; |
Kristian Høgsberg | 0ed6750 | 2014-01-02 23:00:11 -0800 | [diff] [blame] | 5075 | if (seat->touch->focus == NULL) |
| 5076 | return; |
Neil Roberts | a28c693 | 2013-10-03 16:43:04 +0100 | [diff] [blame] | 5077 | |
Kristian Høgsberg | 7ab139c | 2013-10-24 16:21:39 -0700 | [diff] [blame] | 5078 | activate_binding(seat, data, seat->touch->focus->surface); |
Kristian Høgsberg | e1a850e | 2011-12-19 15:18:05 -0500 | [diff] [blame] | 5079 | } |
| 5080 | |
| 5081 | static void |
Neil Roberts | b4a9170 | 2014-04-09 16:33:32 +0100 | [diff] [blame] | 5082 | unfocus_all_seats(struct desktop_shell *shell) |
| 5083 | { |
| 5084 | struct weston_seat *seat, *next; |
| 5085 | |
| 5086 | wl_list_for_each_safe(seat, next, &shell->compositor->seat_list, link) { |
| 5087 | if (seat->keyboard == NULL) |
| 5088 | continue; |
| 5089 | |
| 5090 | weston_keyboard_set_focus(seat->keyboard, NULL); |
| 5091 | } |
| 5092 | } |
| 5093 | |
| 5094 | static void |
Ander Conselvan de Oliveira | 19d10ef | 2013-02-21 18:35:20 +0200 | [diff] [blame] | 5095 | lock(struct desktop_shell *shell) |
Kristian Høgsberg | 02ec0a5 | 2011-04-23 13:04:11 -0400 | [diff] [blame] | 5096 | { |
Kristian Høgsberg | 4476aaf | 2012-06-25 14:03:13 -0400 | [diff] [blame] | 5097 | struct workspace *ws = get_current_workspace(shell); |
Pekka Paalanen | f0fc70d | 2011-11-15 13:34:54 +0200 | [diff] [blame] | 5098 | |
Tiago Vignatti | 8e53c7f | 2012-02-29 19:53:50 +0200 | [diff] [blame] | 5099 | if (shell->locked) { |
Ander Conselvan de Oliveira | 87524b6 | 2013-02-21 18:35:22 +0200 | [diff] [blame] | 5100 | weston_compositor_sleep(shell->compositor); |
Pekka Paalanen | f0fc70d | 2011-11-15 13:34:54 +0200 | [diff] [blame] | 5101 | return; |
Tiago Vignatti | 8e53c7f | 2012-02-29 19:53:50 +0200 | [diff] [blame] | 5102 | } |
Pekka Paalanen | 9ef3e01 | 2011-11-15 13:34:48 +0200 | [diff] [blame] | 5103 | |
| 5104 | shell->locked = true; |
Pekka Paalanen | f0fc70d | 2011-11-15 13:34:54 +0200 | [diff] [blame] | 5105 | |
Kristian Høgsberg | 3be2ce9 | 2012-02-29 12:42:35 -0500 | [diff] [blame] | 5106 | /* Hide all surfaces by removing the fullscreen, panel and |
| 5107 | * toplevel layers. This way nothing else can show or receive |
| 5108 | * input events while we are locked. */ |
Pekka Paalanen | f0fc70d | 2011-11-15 13:34:54 +0200 | [diff] [blame] | 5109 | |
Kristian Høgsberg | 3be2ce9 | 2012-02-29 12:42:35 -0500 | [diff] [blame] | 5110 | wl_list_remove(&shell->panel_layer.link); |
Kristian Høgsberg | 3be2ce9 | 2012-02-29 12:42:35 -0500 | [diff] [blame] | 5111 | wl_list_remove(&shell->fullscreen_layer.link); |
Philipp Brüschweiler | 711fda8 | 2012-08-09 18:50:43 +0200 | [diff] [blame] | 5112 | if (shell->showing_input_panels) |
| 5113 | wl_list_remove(&shell->input_panel_layer.link); |
Kristian Høgsberg | 4476aaf | 2012-06-25 14:03:13 -0400 | [diff] [blame] | 5114 | wl_list_remove(&ws->layer.link); |
Kristian Høgsberg | 3be2ce9 | 2012-02-29 12:42:35 -0500 | [diff] [blame] | 5115 | wl_list_insert(&shell->compositor->cursor_layer.link, |
| 5116 | &shell->lock_layer.link); |
Pekka Paalanen | f0fc70d | 2011-11-15 13:34:54 +0200 | [diff] [blame] | 5117 | |
Pekka Paalanen | 77346a6 | 2011-11-30 16:26:35 +0200 | [diff] [blame] | 5118 | launch_screensaver(shell); |
| 5119 | |
Neil Roberts | b4a9170 | 2014-04-09 16:33:32 +0100 | [diff] [blame] | 5120 | /* Remove the keyboard focus on all seats. This will be |
| 5121 | * restored to the workspace's saved state via |
| 5122 | * restore_focus_state when the compositor is unlocked */ |
| 5123 | unfocus_all_seats(shell); |
| 5124 | |
Pekka Paalanen | f0fc70d | 2011-11-15 13:34:54 +0200 | [diff] [blame] | 5125 | /* TODO: disable bindings that should not work while locked. */ |
| 5126 | |
| 5127 | /* All this must be undone in resume_desktop(). */ |
Pekka Paalanen | 9ef3e01 | 2011-11-15 13:34:48 +0200 | [diff] [blame] | 5128 | } |
| 5129 | |
| 5130 | static void |
Ander Conselvan de Oliveira | 19d10ef | 2013-02-21 18:35:20 +0200 | [diff] [blame] | 5131 | unlock(struct desktop_shell *shell) |
Pekka Paalanen | 9ef3e01 | 2011-11-15 13:34:48 +0200 | [diff] [blame] | 5132 | { |
Pekka Paalanen | d81c216 | 2011-11-16 13:47:34 +0200 | [diff] [blame] | 5133 | if (!shell->locked || shell->lock_surface) { |
Ander Conselvan de Oliveira | 87524b6 | 2013-02-21 18:35:22 +0200 | [diff] [blame] | 5134 | shell_fade(shell, FADE_IN); |
Pekka Paalanen | 9ef3e01 | 2011-11-15 13:34:48 +0200 | [diff] [blame] | 5135 | return; |
| 5136 | } |
| 5137 | |
| 5138 | /* If desktop-shell client has gone away, unlock immediately. */ |
| 5139 | if (!shell->child.desktop_shell) { |
Pekka Paalanen | f0fc70d | 2011-11-15 13:34:54 +0200 | [diff] [blame] | 5140 | resume_desktop(shell); |
Pekka Paalanen | 9ef3e01 | 2011-11-15 13:34:48 +0200 | [diff] [blame] | 5141 | return; |
| 5142 | } |
| 5143 | |
| 5144 | if (shell->prepare_event_sent) |
| 5145 | return; |
| 5146 | |
Kristian Høgsberg | 0b5cd0c | 2012-03-04 21:57:37 -0500 | [diff] [blame] | 5147 | desktop_shell_send_prepare_lock_surface(shell->child.desktop_shell); |
Pekka Paalanen | 9ef3e01 | 2011-11-15 13:34:48 +0200 | [diff] [blame] | 5148 | shell->prepare_event_sent = true; |
Kristian Høgsberg | 02ec0a5 | 2011-04-23 13:04:11 -0400 | [diff] [blame] | 5149 | } |
| 5150 | |
| 5151 | static void |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 5152 | shell_fade_done(struct weston_view_animation *animation, void *data) |
Ander Conselvan de Oliveira | 19d10ef | 2013-02-21 18:35:20 +0200 | [diff] [blame] | 5153 | { |
| 5154 | struct desktop_shell *shell = data; |
| 5155 | |
| 5156 | shell->fade.animation = NULL; |
| 5157 | |
| 5158 | switch (shell->fade.type) { |
| 5159 | case FADE_IN: |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 5160 | weston_surface_destroy(shell->fade.view->surface); |
| 5161 | shell->fade.view = NULL; |
Ander Conselvan de Oliveira | 19d10ef | 2013-02-21 18:35:20 +0200 | [diff] [blame] | 5162 | break; |
| 5163 | case FADE_OUT: |
Ander Conselvan de Oliveira | 19d10ef | 2013-02-21 18:35:20 +0200 | [diff] [blame] | 5164 | lock(shell); |
| 5165 | break; |
Philip Withnall | 4a86a0a | 2013-11-25 18:01:32 +0000 | [diff] [blame] | 5166 | default: |
| 5167 | break; |
Ander Conselvan de Oliveira | 19d10ef | 2013-02-21 18:35:20 +0200 | [diff] [blame] | 5168 | } |
| 5169 | } |
| 5170 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 5171 | static struct weston_view * |
Pekka Paalanen | 79346ab | 2013-05-22 18:03:09 +0300 | [diff] [blame] | 5172 | shell_fade_create_surface(struct desktop_shell *shell) |
Ander Conselvan de Oliveira | 19d10ef | 2013-02-21 18:35:20 +0200 | [diff] [blame] | 5173 | { |
| 5174 | struct weston_compositor *compositor = shell->compositor; |
| 5175 | struct weston_surface *surface; |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 5176 | struct weston_view *view; |
Pekka Paalanen | 79346ab | 2013-05-22 18:03:09 +0300 | [diff] [blame] | 5177 | |
| 5178 | surface = weston_surface_create(compositor); |
| 5179 | if (!surface) |
| 5180 | return NULL; |
| 5181 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 5182 | view = weston_view_create(surface); |
| 5183 | if (!view) { |
| 5184 | weston_surface_destroy(surface); |
| 5185 | return NULL; |
| 5186 | } |
| 5187 | |
Jason Ekstrand | 5c11a33 | 2013-12-04 20:32:03 -0600 | [diff] [blame] | 5188 | weston_surface_set_size(surface, 8192, 8192); |
Jason Ekstrand | 918f2dd | 2013-12-02 21:01:53 -0600 | [diff] [blame] | 5189 | weston_view_set_position(view, 0, 0); |
Pekka Paalanen | 79346ab | 2013-05-22 18:03:09 +0300 | [diff] [blame] | 5190 | 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] | 5191 | weston_layer_entry_insert(&compositor->fade_layer.view_list, |
| 5192 | &view->layer_link); |
Pekka Paalanen | 79346ab | 2013-05-22 18:03:09 +0300 | [diff] [blame] | 5193 | pixman_region32_init(&surface->input); |
| 5194 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 5195 | return view; |
Pekka Paalanen | 79346ab | 2013-05-22 18:03:09 +0300 | [diff] [blame] | 5196 | } |
| 5197 | |
| 5198 | static void |
| 5199 | shell_fade(struct desktop_shell *shell, enum fade_type type) |
| 5200 | { |
Ander Conselvan de Oliveira | 19d10ef | 2013-02-21 18:35:20 +0200 | [diff] [blame] | 5201 | float tint; |
| 5202 | |
| 5203 | switch (type) { |
| 5204 | case FADE_IN: |
| 5205 | tint = 0.0; |
| 5206 | break; |
| 5207 | case FADE_OUT: |
| 5208 | tint = 1.0; |
| 5209 | break; |
| 5210 | default: |
| 5211 | weston_log("shell: invalid fade type\n"); |
| 5212 | return; |
| 5213 | } |
| 5214 | |
| 5215 | shell->fade.type = type; |
| 5216 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 5217 | if (shell->fade.view == NULL) { |
| 5218 | shell->fade.view = shell_fade_create_surface(shell); |
| 5219 | if (!shell->fade.view) |
Ander Conselvan de Oliveira | 19d10ef | 2013-02-21 18:35:20 +0200 | [diff] [blame] | 5220 | return; |
| 5221 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 5222 | shell->fade.view->alpha = 1.0 - tint; |
| 5223 | weston_view_update_transform(shell->fade.view); |
Ander Conselvan de Oliveira | 19d10ef | 2013-02-21 18:35:20 +0200 | [diff] [blame] | 5224 | } |
| 5225 | |
Kristian Høgsberg | 87d3b61 | 2014-01-19 21:48:10 -0800 | [diff] [blame] | 5226 | if (shell->fade.view->output == NULL) { |
| 5227 | /* If the black view gets a NULL output, we lost the |
| 5228 | * last output and we'll just cancel the fade. This |
| 5229 | * happens when you close the last window under the |
| 5230 | * X11 or Wayland backends. */ |
| 5231 | shell->locked = false; |
| 5232 | weston_surface_destroy(shell->fade.view->surface); |
| 5233 | shell->fade.view = NULL; |
| 5234 | } else if (shell->fade.animation) { |
Kristian Høgsberg | 5281fb1 | 2013-06-17 10:10:28 -0400 | [diff] [blame] | 5235 | weston_fade_update(shell->fade.animation, tint); |
Kristian Høgsberg | 87d3b61 | 2014-01-19 21:48:10 -0800 | [diff] [blame] | 5236 | } else { |
Ander Conselvan de Oliveira | 19d10ef | 2013-02-21 18:35:20 +0200 | [diff] [blame] | 5237 | shell->fade.animation = |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 5238 | weston_fade_run(shell->fade.view, |
Kristian Høgsberg | 5281fb1 | 2013-06-17 10:10:28 -0400 | [diff] [blame] | 5239 | 1.0 - tint, tint, 300.0, |
Ander Conselvan de Oliveira | 19d10ef | 2013-02-21 18:35:20 +0200 | [diff] [blame] | 5240 | shell_fade_done, shell); |
Kristian Høgsberg | 87d3b61 | 2014-01-19 21:48:10 -0800 | [diff] [blame] | 5241 | } |
Ander Conselvan de Oliveira | 19d10ef | 2013-02-21 18:35:20 +0200 | [diff] [blame] | 5242 | } |
| 5243 | |
| 5244 | static void |
Pekka Paalanen | 79346ab | 2013-05-22 18:03:09 +0300 | [diff] [blame] | 5245 | do_shell_fade_startup(void *data) |
| 5246 | { |
| 5247 | struct desktop_shell *shell = data; |
| 5248 | |
Kristian Høgsberg | 724c8d9 | 2013-10-16 11:38:24 -0700 | [diff] [blame] | 5249 | if (shell->startup_animation_type == ANIMATION_FADE) |
| 5250 | shell_fade(shell, FADE_IN); |
| 5251 | else if (shell->startup_animation_type == ANIMATION_NONE) { |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 5252 | weston_surface_destroy(shell->fade.view->surface); |
| 5253 | shell->fade.view = NULL; |
Kristian Høgsberg | 724c8d9 | 2013-10-16 11:38:24 -0700 | [diff] [blame] | 5254 | } |
Pekka Paalanen | 79346ab | 2013-05-22 18:03:09 +0300 | [diff] [blame] | 5255 | } |
| 5256 | |
| 5257 | static void |
| 5258 | shell_fade_startup(struct desktop_shell *shell) |
| 5259 | { |
| 5260 | struct wl_event_loop *loop; |
| 5261 | |
| 5262 | if (!shell->fade.startup_timer) |
| 5263 | return; |
| 5264 | |
| 5265 | wl_event_source_remove(shell->fade.startup_timer); |
| 5266 | shell->fade.startup_timer = NULL; |
| 5267 | |
| 5268 | loop = wl_display_get_event_loop(shell->compositor->wl_display); |
| 5269 | wl_event_loop_add_idle(loop, do_shell_fade_startup, shell); |
| 5270 | } |
| 5271 | |
| 5272 | static int |
| 5273 | fade_startup_timeout(void *data) |
| 5274 | { |
| 5275 | struct desktop_shell *shell = data; |
| 5276 | |
| 5277 | shell_fade_startup(shell); |
| 5278 | return 0; |
| 5279 | } |
| 5280 | |
| 5281 | static void |
| 5282 | shell_fade_init(struct desktop_shell *shell) |
| 5283 | { |
| 5284 | /* Make compositor output all black, and wait for the desktop-shell |
| 5285 | * client to signal it is ready, then fade in. The timer triggers a |
| 5286 | * fade-in, in case the desktop-shell client takes too long. |
| 5287 | */ |
| 5288 | |
| 5289 | struct wl_event_loop *loop; |
| 5290 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 5291 | if (shell->fade.view != NULL) { |
Pekka Paalanen | 79346ab | 2013-05-22 18:03:09 +0300 | [diff] [blame] | 5292 | weston_log("%s: warning: fade surface already exists\n", |
| 5293 | __func__); |
| 5294 | return; |
| 5295 | } |
| 5296 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 5297 | shell->fade.view = shell_fade_create_surface(shell); |
| 5298 | if (!shell->fade.view) |
Pekka Paalanen | 79346ab | 2013-05-22 18:03:09 +0300 | [diff] [blame] | 5299 | return; |
| 5300 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 5301 | weston_view_update_transform(shell->fade.view); |
| 5302 | weston_surface_damage(shell->fade.view->surface); |
Pekka Paalanen | 79346ab | 2013-05-22 18:03:09 +0300 | [diff] [blame] | 5303 | |
| 5304 | loop = wl_display_get_event_loop(shell->compositor->wl_display); |
| 5305 | shell->fade.startup_timer = |
| 5306 | wl_event_loop_add_timer(loop, fade_startup_timeout, shell); |
| 5307 | wl_event_source_timer_update(shell->fade.startup_timer, 15000); |
| 5308 | } |
| 5309 | |
| 5310 | static void |
Ander Conselvan de Oliveira | a457563 | 2013-02-21 18:35:23 +0200 | [diff] [blame] | 5311 | idle_handler(struct wl_listener *listener, void *data) |
Ander Conselvan de Oliveira | 19d10ef | 2013-02-21 18:35:20 +0200 | [diff] [blame] | 5312 | { |
| 5313 | struct desktop_shell *shell = |
Ander Conselvan de Oliveira | a457563 | 2013-02-21 18:35:23 +0200 | [diff] [blame] | 5314 | container_of(listener, struct desktop_shell, idle_listener); |
Kristian Høgsberg | 27d5fa8 | 2014-01-17 16:22:50 -0800 | [diff] [blame] | 5315 | struct weston_seat *seat; |
| 5316 | |
Jonny Lamb | 76cf1fe | 2014-08-20 11:27:10 +0200 | [diff] [blame] | 5317 | wl_list_for_each(seat, &shell->compositor->seat_list, link) { |
Kristian Høgsberg | 27d5fa8 | 2014-01-17 16:22:50 -0800 | [diff] [blame] | 5318 | if (seat->pointer) |
| 5319 | popup_grab_end(seat->pointer); |
Jonny Lamb | 76cf1fe | 2014-08-20 11:27:10 +0200 | [diff] [blame] | 5320 | if (seat->touch) |
| 5321 | touch_popup_grab_end(seat->touch); |
| 5322 | } |
Ander Conselvan de Oliveira | 19d10ef | 2013-02-21 18:35:20 +0200 | [diff] [blame] | 5323 | |
| 5324 | shell_fade(shell, FADE_OUT); |
| 5325 | /* lock() is called from shell_fade_done() */ |
| 5326 | } |
| 5327 | |
| 5328 | static void |
Ander Conselvan de Oliveira | a457563 | 2013-02-21 18:35:23 +0200 | [diff] [blame] | 5329 | wake_handler(struct wl_listener *listener, void *data) |
Ander Conselvan de Oliveira | 19d10ef | 2013-02-21 18:35:20 +0200 | [diff] [blame] | 5330 | { |
| 5331 | struct desktop_shell *shell = |
Ander Conselvan de Oliveira | a457563 | 2013-02-21 18:35:23 +0200 | [diff] [blame] | 5332 | container_of(listener, struct desktop_shell, wake_listener); |
Ander Conselvan de Oliveira | 19d10ef | 2013-02-21 18:35:20 +0200 | [diff] [blame] | 5333 | |
Ander Conselvan de Oliveira | 19d10ef | 2013-02-21 18:35:20 +0200 | [diff] [blame] | 5334 | unlock(shell); |
| 5335 | } |
| 5336 | |
| 5337 | static void |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 5338 | center_on_output(struct weston_view *view, struct weston_output *output) |
Pekka Paalanen | 77346a6 | 2011-11-30 16:26:35 +0200 | [diff] [blame] | 5339 | { |
Giulio Camuffo | b836664 | 2013-04-25 13:57:46 +0300 | [diff] [blame] | 5340 | int32_t surf_x, surf_y, width, height; |
Ander Conselvan de Oliveira | 012b4c7 | 2012-11-27 17:03:42 +0200 | [diff] [blame] | 5341 | float x, y; |
Pekka Paalanen | 77346a6 | 2011-11-30 16:26:35 +0200 | [diff] [blame] | 5342 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 5343 | surface_subsurfaces_boundingbox(view->surface, &surf_x, &surf_y, &width, &height); |
Giulio Camuffo | b836664 | 2013-04-25 13:57:46 +0300 | [diff] [blame] | 5344 | |
| 5345 | x = output->x + (output->width - width) / 2 - surf_x / 2; |
| 5346 | y = output->y + (output->height - height) / 2 - surf_y / 2; |
Ander Conselvan de Oliveira | 012b4c7 | 2012-11-27 17:03:42 +0200 | [diff] [blame] | 5347 | |
Jason Ekstrand | 918f2dd | 2013-12-02 21:01:53 -0600 | [diff] [blame] | 5348 | weston_view_set_position(view, x, y); |
Pekka Paalanen | 77346a6 | 2011-11-30 16:26:35 +0200 | [diff] [blame] | 5349 | } |
| 5350 | |
| 5351 | static void |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 5352 | weston_view_set_initial_position(struct weston_view *view, |
| 5353 | struct desktop_shell *shell) |
Rob Bradford | ac63e5b | 2012-08-13 14:07:52 +0100 | [diff] [blame] | 5354 | { |
| 5355 | struct weston_compositor *compositor = shell->compositor; |
| 5356 | int ix = 0, iy = 0; |
Jonny Lamb | d73c694 | 2014-08-20 15:53:20 +0200 | [diff] [blame] | 5357 | int32_t range_x, range_y; |
| 5358 | int32_t dx, dy, x, y; |
Rob Bradford | ac63e5b | 2012-08-13 14:07:52 +0100 | [diff] [blame] | 5359 | struct weston_output *output, *target_output = NULL; |
| 5360 | struct weston_seat *seat; |
Jonny Lamb | d73c694 | 2014-08-20 15:53:20 +0200 | [diff] [blame] | 5361 | pixman_rectangle32_t area; |
Rob Bradford | ac63e5b | 2012-08-13 14:07:52 +0100 | [diff] [blame] | 5362 | |
| 5363 | /* As a heuristic place the new window on the same output as the |
| 5364 | * pointer. Falling back to the output containing 0, 0. |
| 5365 | * |
| 5366 | * TODO: Do something clever for touch too? |
| 5367 | */ |
| 5368 | wl_list_for_each(seat, &compositor->seat_list, link) { |
Kristian Høgsberg | 2bf8762 | 2013-05-07 23:17:41 -0400 | [diff] [blame] | 5369 | if (seat->pointer) { |
Kristian Høgsberg | e314875 | 2013-05-06 23:19:49 -0400 | [diff] [blame] | 5370 | ix = wl_fixed_to_int(seat->pointer->x); |
| 5371 | iy = wl_fixed_to_int(seat->pointer->y); |
Rob Bradford | ac63e5b | 2012-08-13 14:07:52 +0100 | [diff] [blame] | 5372 | break; |
| 5373 | } |
| 5374 | } |
| 5375 | |
| 5376 | wl_list_for_each(output, &compositor->output_list, link) { |
| 5377 | if (pixman_region32_contains_point(&output->region, ix, iy, NULL)) { |
| 5378 | target_output = output; |
| 5379 | break; |
| 5380 | } |
| 5381 | } |
| 5382 | |
| 5383 | if (!target_output) { |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 5384 | weston_view_set_position(view, 10 + random() % 400, |
| 5385 | 10 + random() % 400); |
Rob Bradford | ac63e5b | 2012-08-13 14:07:52 +0100 | [diff] [blame] | 5386 | return; |
| 5387 | } |
| 5388 | |
| 5389 | /* Valid range within output where the surface will still be onscreen. |
| 5390 | * If this is negative it means that the surface is bigger than |
| 5391 | * output. |
| 5392 | */ |
Jonny Lamb | d73c694 | 2014-08-20 15:53:20 +0200 | [diff] [blame] | 5393 | get_output_work_area(shell, target_output, &area); |
| 5394 | |
| 5395 | dx = area.x; |
| 5396 | dy = area.y; |
| 5397 | range_x = area.width - view->surface->width; |
| 5398 | range_y = area.height - view->surface->height; |
Rob Bradford | ac63e5b | 2012-08-13 14:07:52 +0100 | [diff] [blame] | 5399 | |
Rob Bradford | 4cb88c7 | 2012-08-13 15:18:44 +0100 | [diff] [blame] | 5400 | if (range_x > 0) |
Jonny Lamb | d73c694 | 2014-08-20 15:53:20 +0200 | [diff] [blame] | 5401 | dx += random() % range_x; |
Rob Bradford | 4cb88c7 | 2012-08-13 15:18:44 +0100 | [diff] [blame] | 5402 | |
| 5403 | if (range_y > 0) |
Jonny Lamb | d73c694 | 2014-08-20 15:53:20 +0200 | [diff] [blame] | 5404 | dy += random() % range_y; |
Rob Bradford | ac63e5b | 2012-08-13 14:07:52 +0100 | [diff] [blame] | 5405 | |
| 5406 | x = target_output->x + dx; |
| 5407 | y = target_output->y + dy; |
| 5408 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 5409 | weston_view_set_position(view, x, y); |
Rob Bradford | ac63e5b | 2012-08-13 14:07:52 +0100 | [diff] [blame] | 5410 | } |
| 5411 | |
| 5412 | static void |
Jonny Lamb | d73c694 | 2014-08-20 15:53:20 +0200 | [diff] [blame] | 5413 | set_maximized_position(struct desktop_shell *shell, |
| 5414 | struct shell_surface *shsurf) |
| 5415 | { |
| 5416 | int32_t surf_x, surf_y; |
| 5417 | pixman_rectangle32_t area; |
Marek Chalupa | 8b771af | 2014-09-01 17:20:33 +0200 | [diff] [blame] | 5418 | pixman_box32_t *e; |
Jonny Lamb | d73c694 | 2014-08-20 15:53:20 +0200 | [diff] [blame] | 5419 | |
Jonny Lamb | d73c694 | 2014-08-20 15:53:20 +0200 | [diff] [blame] | 5420 | get_output_work_area(shell, shsurf->output, &area); |
Giulio Camuffo | 7a8d67d | 2015-01-09 20:10:45 +0200 | [diff] [blame] | 5421 | if (shsurf->has_set_geometry) { |
| 5422 | surf_x = shsurf->geometry.x; |
| 5423 | surf_y = shsurf->geometry.y; |
| 5424 | } else { |
| 5425 | surface_subsurfaces_boundingbox(shsurf->surface, |
| 5426 | &surf_x, &surf_y, NULL, NULL); |
| 5427 | } |
Marek Chalupa | 8b771af | 2014-09-01 17:20:33 +0200 | [diff] [blame] | 5428 | e = pixman_region32_extents(&shsurf->output->region); |
Jonny Lamb | d73c694 | 2014-08-20 15:53:20 +0200 | [diff] [blame] | 5429 | |
| 5430 | weston_view_set_position(shsurf->view, |
Marek Chalupa | 8b771af | 2014-09-01 17:20:33 +0200 | [diff] [blame] | 5431 | e->x1 + area.x - surf_x, |
| 5432 | e->y1 + area.y - surf_y); |
Jonny Lamb | d73c694 | 2014-08-20 15:53:20 +0200 | [diff] [blame] | 5433 | } |
| 5434 | |
| 5435 | static void |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 5436 | map(struct desktop_shell *shell, struct shell_surface *shsurf, |
Jason Ekstrand | 918f2dd | 2013-12-02 21:01:53 -0600 | [diff] [blame] | 5437 | int32_t sx, int32_t sy) |
Kristian Høgsberg | 02ec0a5 | 2011-04-23 13:04:11 -0400 | [diff] [blame] | 5438 | { |
Kristian Høgsberg | 8334bc1 | 2012-01-03 10:29:47 -0500 | [diff] [blame] | 5439 | struct weston_compositor *compositor = shell->compositor; |
Daniel Stone | b210468 | 2012-05-30 16:31:56 +0100 | [diff] [blame] | 5440 | struct weston_seat *seat; |
Pekka Paalanen | 57da4a8 | 2011-11-23 16:42:16 +0200 | [diff] [blame] | 5441 | |
Pekka Paalanen | 77346a6 | 2011-11-30 16:26:35 +0200 | [diff] [blame] | 5442 | /* initial positioning, see also configure() */ |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 5443 | switch (shsurf->type) { |
Rafael Antognolli | ed207b4 | 2013-12-03 15:35:43 -0200 | [diff] [blame] | 5444 | case SHELL_SURFACE_TOPLEVEL: |
Rafael Antognolli | 03b1659 | 2013-12-03 15:35:42 -0200 | [diff] [blame] | 5445 | if (shsurf->state.fullscreen) { |
| 5446 | center_on_output(shsurf->view, shsurf->fullscreen_output); |
| 5447 | shell_map_fullscreen(shsurf); |
| 5448 | } else if (shsurf->state.maximized) { |
Jonny Lamb | d73c694 | 2014-08-20 15:53:20 +0200 | [diff] [blame] | 5449 | set_maximized_position(shell, shsurf); |
Rafael Antognolli | ed207b4 | 2013-12-03 15:35:43 -0200 | [diff] [blame] | 5450 | } else if (!shsurf->state.relative) { |
Rafael Antognolli | 03b1659 | 2013-12-03 15:35:42 -0200 | [diff] [blame] | 5451 | weston_view_set_initial_position(shsurf->view, shell); |
| 5452 | } |
Juan Zhao | 96879df | 2012-02-07 08:45:41 +0800 | [diff] [blame] | 5453 | break; |
Tiago Vignatti | 0f99701 | 2012-02-10 16:17:23 +0200 | [diff] [blame] | 5454 | case SHELL_SURFACE_POPUP: |
Kristian Høgsberg | 3730f36 | 2012-04-13 12:40:07 -0400 | [diff] [blame] | 5455 | shell_map_popup(shsurf); |
Rob Bradford | db99938 | 2012-12-06 12:07:48 +0000 | [diff] [blame] | 5456 | break; |
Ander Conselvan de Oliveira | e9e0515 | 2012-02-15 17:02:56 +0200 | [diff] [blame] | 5457 | case SHELL_SURFACE_NONE: |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 5458 | weston_view_set_position(shsurf->view, |
| 5459 | shsurf->view->geometry.x + sx, |
| 5460 | shsurf->view->geometry.y + sy); |
Tiago Vignatti | 0f99701 | 2012-02-10 16:17:23 +0200 | [diff] [blame] | 5461 | break; |
Philip Withnall | 0f640e2 | 2013-11-25 18:01:31 +0000 | [diff] [blame] | 5462 | case SHELL_SURFACE_XWAYLAND: |
Pekka Paalanen | 77346a6 | 2011-11-30 16:26:35 +0200 | [diff] [blame] | 5463 | default: |
| 5464 | ; |
| 5465 | } |
Kristian Høgsberg | 7584062 | 2011-09-06 13:48:16 -0400 | [diff] [blame] | 5466 | |
Philip Withnall | e1d75ae | 2013-11-25 18:01:41 +0000 | [diff] [blame] | 5467 | /* Surface stacking order, see also activate(). */ |
| 5468 | shell_surface_update_layer(shsurf); |
Pekka Paalanen | f0fc70d | 2011-11-15 13:34:54 +0200 | [diff] [blame] | 5469 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 5470 | if (shsurf->type != SHELL_SURFACE_NONE) { |
| 5471 | weston_view_update_transform(shsurf->view); |
Rafael Antognolli | 03b1659 | 2013-12-03 15:35:42 -0200 | [diff] [blame] | 5472 | if (shsurf->state.maximized) { |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 5473 | shsurf->surface->output = shsurf->output; |
| 5474 | shsurf->view->output = shsurf->output; |
| 5475 | } |
Ander Conselvan de Oliveira | de56c31 | 2012-03-05 15:39:23 +0200 | [diff] [blame] | 5476 | } |
Kristian Høgsberg | 2f88a40 | 2011-12-04 15:32:59 -0500 | [diff] [blame] | 5477 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 5478 | switch (shsurf->type) { |
Tiago Vignatti | fb2adba | 2013-06-12 15:43:21 -0300 | [diff] [blame] | 5479 | /* XXX: xwayland's using the same fields for transient type */ |
| 5480 | case SHELL_SURFACE_XWAYLAND: |
Tiago Vignatti | 99aeb1e | 2012-05-23 22:06:26 +0300 | [diff] [blame] | 5481 | if (shsurf->transient.flags == |
| 5482 | WL_SHELL_SURFACE_TRANSIENT_INACTIVE) |
| 5483 | break; |
| 5484 | case SHELL_SURFACE_TOPLEVEL: |
Rafael Antognolli | ed207b4 | 2013-12-03 15:35:43 -0200 | [diff] [blame] | 5485 | if (shsurf->state.relative && |
| 5486 | shsurf->transient.flags == WL_SHELL_SURFACE_TRANSIENT_INACTIVE) |
| 5487 | break; |
Rafael Antognolli | ba5d2d7 | 2013-12-04 17:49:55 -0200 | [diff] [blame] | 5488 | if (shell->locked) |
Rafael Antognolli | ed207b4 | 2013-12-03 15:35:43 -0200 | [diff] [blame] | 5489 | break; |
| 5490 | wl_list_for_each(seat, &compositor->seat_list, link) |
Emilio Pozuelo Monfort | 9e7c759 | 2014-01-30 14:01:10 +0100 | [diff] [blame] | 5491 | activate(shell, shsurf->surface, seat, true); |
Juan Zhao | 7bb92f0 | 2011-12-15 11:31:51 -0500 | [diff] [blame] | 5492 | break; |
Philip Withnall | 0f640e2 | 2013-11-25 18:01:31 +0000 | [diff] [blame] | 5493 | case SHELL_SURFACE_POPUP: |
| 5494 | case SHELL_SURFACE_NONE: |
Juan Zhao | 7bb92f0 | 2011-12-15 11:31:51 -0500 | [diff] [blame] | 5495 | default: |
| 5496 | break; |
| 5497 | } |
| 5498 | |
Rafael Antognolli | 03b1659 | 2013-12-03 15:35:42 -0200 | [diff] [blame] | 5499 | if (shsurf->type == SHELL_SURFACE_TOPLEVEL && |
| 5500 | !shsurf->state.maximized && !shsurf->state.fullscreen) |
Juan Zhao | e10d279 | 2012-04-25 19:09:52 +0800 | [diff] [blame] | 5501 | { |
| 5502 | switch (shell->win_animation_type) { |
| 5503 | case ANIMATION_FADE: |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 5504 | 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] | 5505 | break; |
| 5506 | case ANIMATION_ZOOM: |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 5507 | weston_zoom_run(shsurf->view, 0.5, 1.0, NULL, NULL); |
Juan Zhao | e10d279 | 2012-04-25 19:09:52 +0800 | [diff] [blame] | 5508 | break; |
Philip Withnall | 4a86a0a | 2013-11-25 18:01:32 +0000 | [diff] [blame] | 5509 | case ANIMATION_NONE: |
Juan Zhao | e10d279 | 2012-04-25 19:09:52 +0800 | [diff] [blame] | 5510 | default: |
| 5511 | break; |
| 5512 | } |
| 5513 | } |
Kristian Høgsberg | 32e24cc | 2011-11-09 12:07:35 -0500 | [diff] [blame] | 5514 | } |
| 5515 | |
| 5516 | static void |
Tiago Vignatti | be14326 | 2012-04-16 17:31:41 +0300 | [diff] [blame] | 5517 | configure(struct desktop_shell *shell, struct weston_surface *surface, |
Jason Ekstrand | 918f2dd | 2013-12-02 21:01:53 -0600 | [diff] [blame] | 5518 | float x, float y) |
Kristian Høgsberg | 32e24cc | 2011-11-09 12:07:35 -0500 | [diff] [blame] | 5519 | { |
Pekka Paalanen | 77346a6 | 2011-11-30 16:26:35 +0200 | [diff] [blame] | 5520 | struct shell_surface *shsurf; |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 5521 | struct weston_view *view; |
Kristian Høgsberg | 32e24cc | 2011-11-09 12:07:35 -0500 | [diff] [blame] | 5522 | |
Pekka Paalanen | 77346a6 | 2011-11-30 16:26:35 +0200 | [diff] [blame] | 5523 | shsurf = get_shell_surface(surface); |
Pekka Paalanen | 77346a6 | 2011-11-30 16:26:35 +0200 | [diff] [blame] | 5524 | |
U. Artie Eoff | cf5737a | 2014-01-17 10:08:25 -0800 | [diff] [blame] | 5525 | assert(shsurf); |
| 5526 | |
Rafael Antognolli | 03b1659 | 2013-12-03 15:35:42 -0200 | [diff] [blame] | 5527 | if (shsurf->state.fullscreen) |
Alex Wu | 4539b08 | 2012-03-01 12:57:46 +0800 | [diff] [blame] | 5528 | shell_configure_fullscreen(shsurf); |
Rafael Antognolli | 03b1659 | 2013-12-03 15:35:42 -0200 | [diff] [blame] | 5529 | else if (shsurf->state.maximized) { |
Jonny Lamb | d73c694 | 2014-08-20 15:53:20 +0200 | [diff] [blame] | 5530 | set_maximized_position(shell, shsurf); |
Rafael Antognolli | 03b1659 | 2013-12-03 15:35:42 -0200 | [diff] [blame] | 5531 | } else { |
Jason Ekstrand | 918f2dd | 2013-12-02 21:01:53 -0600 | [diff] [blame] | 5532 | weston_view_set_position(shsurf->view, x, y); |
Kristian Høgsberg | 7a5c979 | 2011-06-18 06:12:54 -0400 | [diff] [blame] | 5533 | } |
Kristian Høgsberg | 32e24cc | 2011-11-09 12:07:35 -0500 | [diff] [blame] | 5534 | |
Alex Wu | 4539b08 | 2012-03-01 12:57:46 +0800 | [diff] [blame] | 5535 | /* XXX: would a fullscreen surface need the same handling? */ |
Kristian Høgsberg | 6a8b553 | 2012-02-16 23:43:59 -0500 | [diff] [blame] | 5536 | if (surface->output) { |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 5537 | wl_list_for_each(view, &surface->views, surface_link) |
| 5538 | weston_view_update_transform(view); |
Pekka Paalanen | 77346a6 | 2011-11-30 16:26:35 +0200 | [diff] [blame] | 5539 | |
Rafael Antognolli | 03b1659 | 2013-12-03 15:35:42 -0200 | [diff] [blame] | 5540 | if (shsurf->state.maximized) |
Juan Zhao | 96879df | 2012-02-07 08:45:41 +0800 | [diff] [blame] | 5541 | surface->output = shsurf->output; |
Pekka Paalanen | 77346a6 | 2011-11-30 16:26:35 +0200 | [diff] [blame] | 5542 | } |
Kristian Høgsberg | 0793756 | 2011-04-12 17:25:42 -0400 | [diff] [blame] | 5543 | } |
| 5544 | |
Ander Conselvan de Oliveira | 093bfa3 | 2012-03-27 17:36:41 +0300 | [diff] [blame] | 5545 | static void |
Jason Ekstrand | 918f2dd | 2013-12-02 21:01:53 -0600 | [diff] [blame] | 5546 | 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] | 5547 | { |
Ander Conselvan de Oliveira | 7fb9f95 | 2012-03-27 17:36:42 +0300 | [diff] [blame] | 5548 | struct shell_surface *shsurf = get_shell_surface(es); |
U. Artie Eoff | cf5737a | 2014-01-17 10:08:25 -0800 | [diff] [blame] | 5549 | struct desktop_shell *shell; |
Tiago Vignatti | 70e5c9c | 2012-05-07 15:23:07 +0300 | [diff] [blame] | 5550 | int type_changed = 0; |
Ander Conselvan de Oliveira | 093bfa3 | 2012-03-27 17:36:41 +0300 | [diff] [blame] | 5551 | |
U. Artie Eoff | cf5737a | 2014-01-17 10:08:25 -0800 | [diff] [blame] | 5552 | assert(shsurf); |
| 5553 | |
| 5554 | shell = shsurf->shell; |
| 5555 | |
Kristian Høgsberg | 8eb0f4f | 2013-06-17 10:33:14 -0400 | [diff] [blame] | 5556 | if (!weston_surface_is_mapped(es) && |
| 5557 | !wl_list_empty(&shsurf->popup.grab_link)) { |
Giulio Camuffo | 5085a75 | 2013-03-25 21:42:45 +0100 | [diff] [blame] | 5558 | remove_popup_grab(shsurf); |
| 5559 | } |
| 5560 | |
Jason Ekstrand | 918f2dd | 2013-12-02 21:01:53 -0600 | [diff] [blame] | 5561 | if (es->width == 0) |
Giulio Camuffo | 184df50 | 2013-02-21 11:29:21 +0100 | [diff] [blame] | 5562 | return; |
| 5563 | |
Jasper St. Pierre | ccf48fb | 2014-05-02 10:21:38 -0400 | [diff] [blame] | 5564 | if (shsurf->has_next_geometry) { |
| 5565 | shsurf->geometry = shsurf->next_geometry; |
| 5566 | shsurf->has_next_geometry = false; |
| 5567 | shsurf->has_set_geometry = true; |
| 5568 | } else if (!shsurf->has_set_geometry) { |
| 5569 | surface_subsurfaces_boundingbox(shsurf->surface, |
| 5570 | &shsurf->geometry.x, |
| 5571 | &shsurf->geometry.y, |
| 5572 | &shsurf->geometry.width, |
| 5573 | &shsurf->geometry.height); |
Jasper St. Pierre | 851799e | 2014-05-02 10:14:07 -0400 | [diff] [blame] | 5574 | } |
| 5575 | |
Kristian Høgsberg | c8f8dd8 | 2013-12-05 23:20:33 -0800 | [diff] [blame] | 5576 | if (shsurf->state_changed) { |
Kristian Høgsberg | 7f366e7 | 2012-04-27 17:20:01 -0400 | [diff] [blame] | 5577 | set_surface_type(shsurf); |
Kristian Høgsberg | f7e23d5 | 2012-04-27 17:51:59 -0400 | [diff] [blame] | 5578 | type_changed = 1; |
| 5579 | } |
Kristian Høgsberg | 7f366e7 | 2012-04-27 17:20:01 -0400 | [diff] [blame] | 5580 | |
Ander Conselvan de Oliveira | 093bfa3 | 2012-03-27 17:36:41 +0300 | [diff] [blame] | 5581 | if (!weston_surface_is_mapped(es)) { |
Jason Ekstrand | 918f2dd | 2013-12-02 21:01:53 -0600 | [diff] [blame] | 5582 | map(shell, shsurf, sx, sy); |
Kristian Høgsberg | f7e23d5 | 2012-04-27 17:51:59 -0400 | [diff] [blame] | 5583 | } else if (type_changed || sx != 0 || sy != 0 || |
Jason Ekstrand | 918f2dd | 2013-12-02 21:01:53 -0600 | [diff] [blame] | 5584 | shsurf->last_width != es->width || |
| 5585 | shsurf->last_height != es->height) { |
John Kåre Alsaker | 490d02a | 2012-09-30 02:57:21 +0200 | [diff] [blame] | 5586 | float from_x, from_y; |
| 5587 | float to_x, to_y; |
Ander Conselvan de Oliveira | 093bfa3 | 2012-03-27 17:36:41 +0300 | [diff] [blame] | 5588 | |
Kristian Høgsberg | 44cd196 | 2014-02-05 21:36:04 -0800 | [diff] [blame] | 5589 | if (shsurf->resize_edges) { |
| 5590 | sx = 0; |
| 5591 | sy = 0; |
| 5592 | } |
| 5593 | |
| 5594 | if (shsurf->resize_edges & WL_SHELL_SURFACE_RESIZE_LEFT) |
| 5595 | sx = shsurf->last_width - es->width; |
| 5596 | if (shsurf->resize_edges & WL_SHELL_SURFACE_RESIZE_TOP) |
| 5597 | sy = shsurf->last_height - es->height; |
| 5598 | |
| 5599 | shsurf->last_width = es->width; |
| 5600 | shsurf->last_height = es->height; |
| 5601 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 5602 | weston_view_to_global_float(shsurf->view, 0, 0, &from_x, &from_y); |
| 5603 | 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] | 5604 | configure(shell, es, |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 5605 | shsurf->view->geometry.x + to_x - from_x, |
Jason Ekstrand | 918f2dd | 2013-12-02 21:01:53 -0600 | [diff] [blame] | 5606 | shsurf->view->geometry.y + to_y - from_y); |
Ander Conselvan de Oliveira | 093bfa3 | 2012-03-27 17:36:41 +0300 | [diff] [blame] | 5607 | } |
| 5608 | } |
| 5609 | |
Pekka Paalanen | 2e62e4a | 2014-08-28 11:41:26 +0300 | [diff] [blame] | 5610 | static bool |
| 5611 | check_desktop_shell_crash_too_early(struct desktop_shell *shell) |
| 5612 | { |
| 5613 | struct timespec now; |
| 5614 | |
| 5615 | if (clock_gettime(CLOCK_MONOTONIC, &now) < 0) |
| 5616 | return false; |
| 5617 | |
| 5618 | /* |
| 5619 | * If the shell helper client dies before the session has been |
| 5620 | * up for roughly 30 seconds, better just make Weston shut down, |
| 5621 | * because the user likely has no way to interact with the desktop |
| 5622 | * anyway. |
| 5623 | */ |
| 5624 | if (now.tv_sec - shell->startup_time.tv_sec < 30) { |
| 5625 | weston_log("Error: %s apparently cannot run at all.\n", |
| 5626 | shell->client); |
| 5627 | weston_log_continue(STAMP_SPACE "Quitting..."); |
| 5628 | wl_display_terminate(shell->compositor->wl_display); |
| 5629 | |
| 5630 | return true; |
| 5631 | } |
| 5632 | |
| 5633 | return false; |
| 5634 | } |
| 5635 | |
Tiago Vignatti | b7dbbd6 | 2012-09-25 17:57:01 +0300 | [diff] [blame] | 5636 | static void launch_desktop_shell_process(void *data); |
Pekka Paalanen | 4d733ee | 2012-01-17 14:36:27 +0200 | [diff] [blame] | 5637 | |
Kristian Høgsberg | 97d44aa | 2011-08-26 17:21:20 -0400 | [diff] [blame] | 5638 | static void |
Pekka Paalanen | 826dc14 | 2014-08-27 12:11:53 +0300 | [diff] [blame] | 5639 | respawn_desktop_shell_process(struct desktop_shell *shell) |
Pekka Paalanen | 6cd281a | 2011-11-03 14:11:32 +0200 | [diff] [blame] | 5640 | { |
Pekka Paalanen | 4d733ee | 2012-01-17 14:36:27 +0200 | [diff] [blame] | 5641 | uint32_t time; |
Pekka Paalanen | 4d733ee | 2012-01-17 14:36:27 +0200 | [diff] [blame] | 5642 | |
| 5643 | /* if desktop-shell dies more than 5 times in 30 seconds, give up */ |
| 5644 | time = weston_compositor_get_time(); |
Kristian Høgsberg | f03a616 | 2012-01-17 11:07:42 -0500 | [diff] [blame] | 5645 | if (time - shell->child.deathstamp > 30000) { |
Pekka Paalanen | 4d733ee | 2012-01-17 14:36:27 +0200 | [diff] [blame] | 5646 | shell->child.deathstamp = time; |
| 5647 | shell->child.deathcount = 0; |
| 5648 | } |
| 5649 | |
| 5650 | shell->child.deathcount++; |
| 5651 | if (shell->child.deathcount > 5) { |
Pekka Paalanen | 826dc14 | 2014-08-27 12:11:53 +0300 | [diff] [blame] | 5652 | weston_log("%s disconnected, giving up.\n", shell->client); |
Pekka Paalanen | 4d733ee | 2012-01-17 14:36:27 +0200 | [diff] [blame] | 5653 | return; |
| 5654 | } |
| 5655 | |
Pekka Paalanen | 826dc14 | 2014-08-27 12:11:53 +0300 | [diff] [blame] | 5656 | weston_log("%s disconnected, respawning...\n", shell->client); |
Pekka Paalanen | 4d733ee | 2012-01-17 14:36:27 +0200 | [diff] [blame] | 5657 | launch_desktop_shell_process(shell); |
Pekka Paalanen | 6cd281a | 2011-11-03 14:11:32 +0200 | [diff] [blame] | 5658 | } |
| 5659 | |
Tiago Vignatti | b7dbbd6 | 2012-09-25 17:57:01 +0300 | [diff] [blame] | 5660 | static void |
Ander Conselvan de Oliveira | 312ea4c | 2013-12-20 21:07:01 +0200 | [diff] [blame] | 5661 | desktop_shell_client_destroy(struct wl_listener *listener, void *data) |
| 5662 | { |
| 5663 | struct desktop_shell *shell; |
| 5664 | |
| 5665 | shell = container_of(listener, struct desktop_shell, |
| 5666 | child.client_destroy_listener); |
| 5667 | |
Pekka Paalanen | 826dc14 | 2014-08-27 12:11:53 +0300 | [diff] [blame] | 5668 | wl_list_remove(&shell->child.client_destroy_listener.link); |
Ander Conselvan de Oliveira | 312ea4c | 2013-12-20 21:07:01 +0200 | [diff] [blame] | 5669 | shell->child.client = NULL; |
Pekka Paalanen | 826dc14 | 2014-08-27 12:11:53 +0300 | [diff] [blame] | 5670 | /* |
| 5671 | * unbind_desktop_shell() will reset shell->child.desktop_shell |
| 5672 | * before the respawned process has a chance to create a new |
| 5673 | * desktop_shell object, because we are being called from the |
| 5674 | * wl_client destructor which destroys all wl_resources before |
| 5675 | * returning. |
| 5676 | */ |
| 5677 | |
Pekka Paalanen | 2e62e4a | 2014-08-28 11:41:26 +0300 | [diff] [blame] | 5678 | if (!check_desktop_shell_crash_too_early(shell)) |
| 5679 | respawn_desktop_shell_process(shell); |
| 5680 | |
Pekka Paalanen | 826dc14 | 2014-08-27 12:11:53 +0300 | [diff] [blame] | 5681 | shell_fade_startup(shell); |
Ander Conselvan de Oliveira | 312ea4c | 2013-12-20 21:07:01 +0200 | [diff] [blame] | 5682 | } |
| 5683 | |
| 5684 | static void |
Tiago Vignatti | b7dbbd6 | 2012-09-25 17:57:01 +0300 | [diff] [blame] | 5685 | launch_desktop_shell_process(void *data) |
Pekka Paalanen | 6cd281a | 2011-11-03 14:11:32 +0200 | [diff] [blame] | 5686 | { |
Tiago Vignatti | b7dbbd6 | 2012-09-25 17:57:01 +0300 | [diff] [blame] | 5687 | struct desktop_shell *shell = data; |
Pekka Paalanen | 6cd281a | 2011-11-03 14:11:32 +0200 | [diff] [blame] | 5688 | |
Pekka Paalanen | 826dc14 | 2014-08-27 12:11:53 +0300 | [diff] [blame] | 5689 | shell->child.client = weston_client_start(shell->compositor, |
| 5690 | shell->client); |
Pekka Paalanen | 409ef0a | 2011-12-02 15:30:21 +0200 | [diff] [blame] | 5691 | |
Arnaud Vrac | 4263119 | 2014-08-25 20:56:46 +0200 | [diff] [blame] | 5692 | if (!shell->child.client) { |
Emilio Pozuelo Monfort | 46ce798 | 2013-11-20 13:22:29 +0100 | [diff] [blame] | 5693 | weston_log("not able to start %s\n", shell->client); |
Arnaud Vrac | 4263119 | 2014-08-25 20:56:46 +0200 | [diff] [blame] | 5694 | return; |
| 5695 | } |
Ander Conselvan de Oliveira | 312ea4c | 2013-12-20 21:07:01 +0200 | [diff] [blame] | 5696 | |
| 5697 | shell->child.client_destroy_listener.notify = |
| 5698 | desktop_shell_client_destroy; |
| 5699 | wl_client_add_destroy_listener(shell->child.client, |
| 5700 | &shell->child.client_destroy_listener); |
Pekka Paalanen | 6cd281a | 2011-11-03 14:11:32 +0200 | [diff] [blame] | 5701 | } |
| 5702 | |
| 5703 | static void |
Kristian Høgsberg | 2bff94e | 2014-02-11 12:22:51 -0800 | [diff] [blame] | 5704 | handle_shell_client_destroy(struct wl_listener *listener, void *data) |
| 5705 | { |
| 5706 | struct shell_client *sc = |
| 5707 | container_of(listener, struct shell_client, destroy_listener); |
| 5708 | |
| 5709 | if (sc->ping_timer) |
| 5710 | wl_event_source_remove(sc->ping_timer); |
| 5711 | free(sc); |
| 5712 | } |
| 5713 | |
Kristian Høgsberg | dd62aba | 2014-02-12 09:56:19 -0800 | [diff] [blame] | 5714 | static struct shell_client * |
| 5715 | shell_client_create(struct wl_client *client, struct desktop_shell *shell, |
| 5716 | const struct wl_interface *interface, uint32_t id) |
Rafael Antognolli | e2a3455 | 2013-12-03 15:35:45 -0200 | [diff] [blame] | 5717 | { |
Kristian Høgsberg | 2bff94e | 2014-02-11 12:22:51 -0800 | [diff] [blame] | 5718 | struct shell_client *sc; |
Rafael Antognolli | e2a3455 | 2013-12-03 15:35:45 -0200 | [diff] [blame] | 5719 | |
Kristian Høgsberg | 2bff94e | 2014-02-11 12:22:51 -0800 | [diff] [blame] | 5720 | sc = zalloc(sizeof *sc); |
| 5721 | if (sc == NULL) { |
| 5722 | wl_client_post_no_memory(client); |
Kristian Høgsberg | dd62aba | 2014-02-12 09:56:19 -0800 | [diff] [blame] | 5723 | return NULL; |
Kristian Høgsberg | 2bff94e | 2014-02-11 12:22:51 -0800 | [diff] [blame] | 5724 | } |
Kristian Høgsberg | dd62aba | 2014-02-12 09:56:19 -0800 | [diff] [blame] | 5725 | |
| 5726 | sc->resource = wl_resource_create(client, interface, 1, id); |
Kristian Høgsberg | 2bff94e | 2014-02-11 12:22:51 -0800 | [diff] [blame] | 5727 | if (sc->resource == NULL) { |
| 5728 | free(sc); |
| 5729 | wl_client_post_no_memory(client); |
Kristian Høgsberg | dd62aba | 2014-02-12 09:56:19 -0800 | [diff] [blame] | 5730 | return NULL; |
Kristian Høgsberg | 2bff94e | 2014-02-11 12:22:51 -0800 | [diff] [blame] | 5731 | } |
| 5732 | |
| 5733 | sc->client = client; |
| 5734 | sc->shell = shell; |
| 5735 | sc->destroy_listener.notify = handle_shell_client_destroy; |
| 5736 | wl_client_add_destroy_listener(client, &sc->destroy_listener); |
| 5737 | |
Kristian Høgsberg | dd62aba | 2014-02-12 09:56:19 -0800 | [diff] [blame] | 5738 | return sc; |
| 5739 | } |
| 5740 | |
| 5741 | static void |
| 5742 | bind_shell(struct wl_client *client, void *data, uint32_t version, uint32_t id) |
| 5743 | { |
| 5744 | struct desktop_shell *shell = data; |
| 5745 | struct shell_client *sc; |
| 5746 | |
| 5747 | sc = shell_client_create(client, shell, &wl_shell_interface, id); |
| 5748 | if (sc) |
| 5749 | wl_resource_set_implementation(sc->resource, |
| 5750 | &shell_implementation, |
Jason Ekstrand | 9e9512f | 2014-04-16 21:12:10 -0500 | [diff] [blame] | 5751 | sc, NULL); |
Kristian Høgsberg | dd62aba | 2014-02-12 09:56:19 -0800 | [diff] [blame] | 5752 | } |
| 5753 | |
| 5754 | static void |
| 5755 | bind_xdg_shell(struct wl_client *client, void *data, uint32_t version, uint32_t id) |
| 5756 | { |
| 5757 | struct desktop_shell *shell = data; |
| 5758 | struct shell_client *sc; |
| 5759 | |
| 5760 | sc = shell_client_create(client, shell, &xdg_shell_interface, id); |
| 5761 | if (sc) |
| 5762 | wl_resource_set_dispatcher(sc->resource, |
| 5763 | xdg_shell_unversioned_dispatch, |
| 5764 | NULL, sc, NULL); |
Rafael Antognolli | e2a3455 | 2013-12-03 15:35:45 -0200 | [diff] [blame] | 5765 | } |
| 5766 | |
| 5767 | static void |
Pekka Paalanen | 9ef3e01 | 2011-11-15 13:34:48 +0200 | [diff] [blame] | 5768 | unbind_desktop_shell(struct wl_resource *resource) |
| 5769 | { |
Jason Ekstrand | 651f00e | 2013-06-14 10:07:54 -0500 | [diff] [blame] | 5770 | struct desktop_shell *shell = wl_resource_get_user_data(resource); |
Kristian Høgsberg | 1ec0c31 | 2011-11-15 16:39:55 -0500 | [diff] [blame] | 5771 | |
| 5772 | if (shell->locked) |
| 5773 | resume_desktop(shell); |
| 5774 | |
Pekka Paalanen | 9ef3e01 | 2011-11-15 13:34:48 +0200 | [diff] [blame] | 5775 | shell->child.desktop_shell = NULL; |
| 5776 | shell->prepare_event_sent = false; |
Pekka Paalanen | 9ef3e01 | 2011-11-15 13:34:48 +0200 | [diff] [blame] | 5777 | } |
| 5778 | |
| 5779 | static void |
Kristian Høgsberg | 7584062 | 2011-09-06 13:48:16 -0400 | [diff] [blame] | 5780 | bind_desktop_shell(struct wl_client *client, |
| 5781 | void *data, uint32_t version, uint32_t id) |
| 5782 | { |
Tiago Vignatti | be14326 | 2012-04-16 17:31:41 +0300 | [diff] [blame] | 5783 | struct desktop_shell *shell = data; |
Pekka Paalanen | bbe6052 | 2011-11-03 14:11:33 +0200 | [diff] [blame] | 5784 | struct wl_resource *resource; |
Kristian Høgsberg | 7584062 | 2011-09-06 13:48:16 -0400 | [diff] [blame] | 5785 | |
Jason Ekstrand | a85118c | 2013-06-27 20:17:02 -0500 | [diff] [blame] | 5786 | resource = wl_resource_create(client, &desktop_shell_interface, |
Jonny Lamb | 765760d | 2014-08-20 15:53:19 +0200 | [diff] [blame] | 5787 | MIN(version, 3), id); |
Pekka Paalanen | bbe6052 | 2011-11-03 14:11:33 +0200 | [diff] [blame] | 5788 | |
Pekka Paalanen | 9ef3e01 | 2011-11-15 13:34:48 +0200 | [diff] [blame] | 5789 | if (client == shell->child.client) { |
Jason Ekstrand | a85118c | 2013-06-27 20:17:02 -0500 | [diff] [blame] | 5790 | wl_resource_set_implementation(resource, |
| 5791 | &desktop_shell_implementation, |
| 5792 | shell, unbind_desktop_shell); |
Pekka Paalanen | 9ef3e01 | 2011-11-15 13:34:48 +0200 | [diff] [blame] | 5793 | shell->child.desktop_shell = resource; |
Pekka Paalanen | 79346ab | 2013-05-22 18:03:09 +0300 | [diff] [blame] | 5794 | |
| 5795 | if (version < 2) |
| 5796 | shell_fade_startup(shell); |
| 5797 | |
Pekka Paalanen | bbe6052 | 2011-11-03 14:11:33 +0200 | [diff] [blame] | 5798 | return; |
Pekka Paalanen | 9ef3e01 | 2011-11-15 13:34:48 +0200 | [diff] [blame] | 5799 | } |
Pekka Paalanen | bbe6052 | 2011-11-03 14:11:33 +0200 | [diff] [blame] | 5800 | |
| 5801 | wl_resource_post_error(resource, WL_DISPLAY_ERROR_INVALID_OBJECT, |
| 5802 | "permission to bind desktop_shell denied"); |
Kristian Høgsberg | 7584062 | 2011-09-06 13:48:16 -0400 | [diff] [blame] | 5803 | } |
| 5804 | |
Pekka Paalanen | 8274d90 | 2014-08-06 19:36:51 +0300 | [diff] [blame] | 5805 | static int |
| 5806 | screensaver_get_label(struct weston_surface *surface, char *buf, size_t len) |
| 5807 | { |
| 5808 | return snprintf(buf, len, "screensaver for output %s", |
| 5809 | surface->output->name); |
| 5810 | } |
| 5811 | |
Pekka Paalanen | 6e16811 | 2011-11-24 11:34:05 +0200 | [diff] [blame] | 5812 | static void |
Jason Ekstrand | 918f2dd | 2013-12-02 21:01:53 -0600 | [diff] [blame] | 5813 | 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] | 5814 | { |
Giulio Camuffo | 7fe01b1 | 2013-03-28 18:02:42 +0100 | [diff] [blame] | 5815 | struct desktop_shell *shell = surface->configure_private; |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 5816 | struct weston_view *view; |
Giulio Camuffo | 412e6a5 | 2014-07-09 22:12:56 +0300 | [diff] [blame] | 5817 | struct weston_layer_entry *prev; |
Kristian Høgsberg | 1a73a63 | 2012-06-26 22:15:53 -0400 | [diff] [blame] | 5818 | |
Jason Ekstrand | 918f2dd | 2013-12-02 21:01:53 -0600 | [diff] [blame] | 5819 | if (surface->width == 0) |
Giulio Camuffo | 184df50 | 2013-02-21 11:29:21 +0100 | [diff] [blame] | 5820 | return; |
| 5821 | |
Pekka Paalanen | 3a1d07d | 2012-12-20 14:02:13 +0200 | [diff] [blame] | 5822 | /* XXX: starting weston-screensaver beforehand does not work */ |
Kristian Høgsberg | 1a73a63 | 2012-06-26 22:15:53 -0400 | [diff] [blame] | 5823 | if (!shell->locked) |
| 5824 | return; |
| 5825 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 5826 | view = container_of(surface->views.next, struct weston_view, surface_link); |
| 5827 | center_on_output(view, surface->output); |
Kristian Høgsberg | 1a73a63 | 2012-06-26 22:15:53 -0400 | [diff] [blame] | 5828 | |
Giulio Camuffo | 412e6a5 | 2014-07-09 22:12:56 +0300 | [diff] [blame] | 5829 | if (wl_list_empty(&view->layer_link.link)) { |
| 5830 | prev = container_of(shell->lock_layer.view_list.link.prev, |
| 5831 | struct weston_layer_entry, link); |
| 5832 | weston_layer_entry_insert(prev, &view->layer_link); |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 5833 | weston_view_update_transform(view); |
Ander Conselvan de Oliveira | 859e885 | 2013-02-21 18:35:21 +0200 | [diff] [blame] | 5834 | wl_event_source_timer_update(shell->screensaver.timer, |
| 5835 | shell->screensaver.duration); |
Ander Conselvan de Oliveira | 19d10ef | 2013-02-21 18:35:20 +0200 | [diff] [blame] | 5836 | shell_fade(shell, FADE_IN); |
Kristian Høgsberg | 1a73a63 | 2012-06-26 22:15:53 -0400 | [diff] [blame] | 5837 | } |
| 5838 | } |
| 5839 | |
| 5840 | static void |
Pekka Paalanen | 6e16811 | 2011-11-24 11:34:05 +0200 | [diff] [blame] | 5841 | screensaver_set_surface(struct wl_client *client, |
| 5842 | struct wl_resource *resource, |
Kristian Høgsberg | 1a73a63 | 2012-06-26 22:15:53 -0400 | [diff] [blame] | 5843 | struct wl_resource *surface_resource, |
Pekka Paalanen | 6e16811 | 2011-11-24 11:34:05 +0200 | [diff] [blame] | 5844 | struct wl_resource *output_resource) |
| 5845 | { |
Jason Ekstrand | 651f00e | 2013-06-14 10:07:54 -0500 | [diff] [blame] | 5846 | struct desktop_shell *shell = wl_resource_get_user_data(resource); |
Jason Ekstrand | 0f2ef7e | 2013-06-14 10:07:53 -0500 | [diff] [blame] | 5847 | struct weston_surface *surface = |
| 5848 | wl_resource_get_user_data(surface_resource); |
Jason Ekstrand | a0d2dde | 2013-06-14 10:08:01 -0500 | [diff] [blame] | 5849 | struct weston_output *output = wl_resource_get_user_data(output_resource); |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 5850 | struct weston_view *view, *next; |
| 5851 | |
| 5852 | /* Make sure we only have one view */ |
| 5853 | wl_list_for_each_safe(view, next, &surface->views, surface_link) |
| 5854 | weston_view_destroy(view); |
| 5855 | weston_view_create(surface); |
Pekka Paalanen | 6e16811 | 2011-11-24 11:34:05 +0200 | [diff] [blame] | 5856 | |
Kristian Høgsberg | 1a73a63 | 2012-06-26 22:15:53 -0400 | [diff] [blame] | 5857 | surface->configure = screensaver_configure; |
Giulio Camuffo | 7fe01b1 | 2013-03-28 18:02:42 +0100 | [diff] [blame] | 5858 | surface->configure_private = shell; |
Pekka Paalanen | 8274d90 | 2014-08-06 19:36:51 +0300 | [diff] [blame] | 5859 | weston_surface_set_label_func(surface, screensaver_get_label); |
Pekka Paalanen | 77346a6 | 2011-11-30 16:26:35 +0200 | [diff] [blame] | 5860 | surface->output = output; |
Pekka Paalanen | 6e16811 | 2011-11-24 11:34:05 +0200 | [diff] [blame] | 5861 | } |
| 5862 | |
| 5863 | static const struct screensaver_interface screensaver_implementation = { |
| 5864 | screensaver_set_surface |
| 5865 | }; |
| 5866 | |
| 5867 | static void |
| 5868 | unbind_screensaver(struct wl_resource *resource) |
| 5869 | { |
Jason Ekstrand | 651f00e | 2013-06-14 10:07:54 -0500 | [diff] [blame] | 5870 | struct desktop_shell *shell = wl_resource_get_user_data(resource); |
Pekka Paalanen | 6e16811 | 2011-11-24 11:34:05 +0200 | [diff] [blame] | 5871 | |
Pekka Paalanen | 77346a6 | 2011-11-30 16:26:35 +0200 | [diff] [blame] | 5872 | shell->screensaver.binding = NULL; |
Pekka Paalanen | 6e16811 | 2011-11-24 11:34:05 +0200 | [diff] [blame] | 5873 | } |
| 5874 | |
| 5875 | static void |
| 5876 | bind_screensaver(struct wl_client *client, |
| 5877 | void *data, uint32_t version, uint32_t id) |
| 5878 | { |
Tiago Vignatti | be14326 | 2012-04-16 17:31:41 +0300 | [diff] [blame] | 5879 | struct desktop_shell *shell = data; |
Pekka Paalanen | 6e16811 | 2011-11-24 11:34:05 +0200 | [diff] [blame] | 5880 | struct wl_resource *resource; |
| 5881 | |
Jason Ekstrand | a85118c | 2013-06-27 20:17:02 -0500 | [diff] [blame] | 5882 | resource = wl_resource_create(client, &screensaver_interface, 1, id); |
Pekka Paalanen | 6e16811 | 2011-11-24 11:34:05 +0200 | [diff] [blame] | 5883 | |
Pekka Paalanen | 77346a6 | 2011-11-30 16:26:35 +0200 | [diff] [blame] | 5884 | if (shell->screensaver.binding == NULL) { |
Jason Ekstrand | a85118c | 2013-06-27 20:17:02 -0500 | [diff] [blame] | 5885 | wl_resource_set_implementation(resource, |
| 5886 | &screensaver_implementation, |
| 5887 | shell, unbind_screensaver); |
Pekka Paalanen | 77346a6 | 2011-11-30 16:26:35 +0200 | [diff] [blame] | 5888 | shell->screensaver.binding = resource; |
Pekka Paalanen | 6e16811 | 2011-11-24 11:34:05 +0200 | [diff] [blame] | 5889 | return; |
| 5890 | } |
| 5891 | |
| 5892 | wl_resource_post_error(resource, WL_DISPLAY_ERROR_INVALID_OBJECT, |
| 5893 | "interface object already bound"); |
Pekka Paalanen | 6e16811 | 2011-11-24 11:34:05 +0200 | [diff] [blame] | 5894 | } |
| 5895 | |
Kristian Høgsberg | 0704539 | 2012-02-19 18:52:44 -0500 | [diff] [blame] | 5896 | struct switcher { |
Tiago Vignatti | be14326 | 2012-04-16 17:31:41 +0300 | [diff] [blame] | 5897 | struct desktop_shell *shell; |
Kristian Høgsberg | 0704539 | 2012-02-19 18:52:44 -0500 | [diff] [blame] | 5898 | struct weston_surface *current; |
| 5899 | struct wl_listener listener; |
Kristian Høgsberg | 29139d4 | 2013-04-18 15:25:39 -0400 | [diff] [blame] | 5900 | struct weston_keyboard_grab grab; |
Manuel Bachmann | c1ae2e8 | 2014-02-26 15:53:11 +0100 | [diff] [blame] | 5901 | struct wl_array minimized_array; |
Kristian Høgsberg | 0704539 | 2012-02-19 18:52:44 -0500 | [diff] [blame] | 5902 | }; |
| 5903 | |
| 5904 | static void |
| 5905 | switcher_next(struct switcher *switcher) |
| 5906 | { |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 5907 | struct weston_view *view; |
Kristian Høgsberg | 0704539 | 2012-02-19 18:52:44 -0500 | [diff] [blame] | 5908 | struct weston_surface *first = NULL, *prev = NULL, *next = NULL; |
Kristian Høgsberg | 32e5686 | 2012-04-02 22:18:58 -0400 | [diff] [blame] | 5909 | struct shell_surface *shsurf; |
Kristian Høgsberg | b0d8e77 | 2012-06-18 16:34:58 -0400 | [diff] [blame] | 5910 | struct workspace *ws = get_current_workspace(switcher->shell); |
Kristian Høgsberg | 0704539 | 2012-02-19 18:52:44 -0500 | [diff] [blame] | 5911 | |
Manuel Bachmann | c1ae2e8 | 2014-02-26 15:53:11 +0100 | [diff] [blame] | 5912 | /* temporary re-display minimized surfaces */ |
| 5913 | struct weston_view *tmp; |
| 5914 | struct weston_view **minimized; |
Giulio Camuffo | 412e6a5 | 2014-07-09 22:12:56 +0300 | [diff] [blame] | 5915 | wl_list_for_each_safe(view, tmp, &switcher->shell->minimized_layer.view_list.link, layer_link.link) { |
| 5916 | weston_layer_entry_remove(&view->layer_link); |
| 5917 | weston_layer_entry_insert(&ws->layer.view_list, &view->layer_link); |
Manuel Bachmann | c1ae2e8 | 2014-02-26 15:53:11 +0100 | [diff] [blame] | 5918 | minimized = wl_array_add(&switcher->minimized_array, sizeof *minimized); |
| 5919 | *minimized = view; |
| 5920 | } |
| 5921 | |
Giulio Camuffo | 412e6a5 | 2014-07-09 22:12:56 +0300 | [diff] [blame] | 5922 | 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] | 5923 | shsurf = get_shell_surface(view->surface); |
Rafael Antognolli | 5031cbe | 2013-12-05 19:01:21 -0200 | [diff] [blame] | 5924 | if (shsurf && |
| 5925 | shsurf->type == SHELL_SURFACE_TOPLEVEL && |
| 5926 | shsurf->parent == NULL) { |
Kristian Høgsberg | 0704539 | 2012-02-19 18:52:44 -0500 | [diff] [blame] | 5927 | if (first == NULL) |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 5928 | first = view->surface; |
Kristian Høgsberg | 0704539 | 2012-02-19 18:52:44 -0500 | [diff] [blame] | 5929 | if (prev == switcher->current) |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 5930 | next = view->surface; |
| 5931 | prev = view->surface; |
| 5932 | view->alpha = 0.25; |
| 5933 | weston_view_geometry_dirty(view); |
| 5934 | weston_surface_damage(view->surface); |
Kristian Høgsberg | 0704539 | 2012-02-19 18:52:44 -0500 | [diff] [blame] | 5935 | } |
Alex Wu | 1659daa | 2012-04-01 20:13:09 +0800 | [diff] [blame] | 5936 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 5937 | if (is_black_surface(view->surface, NULL)) { |
| 5938 | view->alpha = 0.25; |
| 5939 | weston_view_geometry_dirty(view); |
| 5940 | weston_surface_damage(view->surface); |
Alex Wu | 1659daa | 2012-04-01 20:13:09 +0800 | [diff] [blame] | 5941 | } |
Kristian Høgsberg | 0704539 | 2012-02-19 18:52:44 -0500 | [diff] [blame] | 5942 | } |
| 5943 | |
| 5944 | if (next == NULL) |
| 5945 | next = first; |
| 5946 | |
Alex Wu | 07b2606 | 2012-03-12 16:06:01 +0800 | [diff] [blame] | 5947 | if (next == NULL) |
| 5948 | return; |
| 5949 | |
Kristian Høgsberg | 0704539 | 2012-02-19 18:52:44 -0500 | [diff] [blame] | 5950 | wl_list_remove(&switcher->listener.link); |
Jason Ekstrand | 26ed73c | 2013-06-06 22:34:41 -0500 | [diff] [blame] | 5951 | wl_signal_add(&next->destroy_signal, &switcher->listener); |
Kristian Høgsberg | 0704539 | 2012-02-19 18:52:44 -0500 | [diff] [blame] | 5952 | |
| 5953 | switcher->current = next; |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 5954 | wl_list_for_each(view, &next->views, surface_link) |
| 5955 | view->alpha = 1.0; |
Alex Wu | 1659daa | 2012-04-01 20:13:09 +0800 | [diff] [blame] | 5956 | |
Kristian Høgsberg | 32e5686 | 2012-04-02 22:18:58 -0400 | [diff] [blame] | 5957 | shsurf = get_shell_surface(switcher->current); |
Rafael Antognolli | 03b1659 | 2013-12-03 15:35:42 -0200 | [diff] [blame] | 5958 | if (shsurf && shsurf->state.fullscreen) |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 5959 | shsurf->fullscreen.black_view->alpha = 1.0; |
Kristian Høgsberg | 0704539 | 2012-02-19 18:52:44 -0500 | [diff] [blame] | 5960 | } |
| 5961 | |
| 5962 | static void |
Kristian Høgsberg | 27e3052 | 2012-04-11 23:18:23 -0400 | [diff] [blame] | 5963 | switcher_handle_surface_destroy(struct wl_listener *listener, void *data) |
Kristian Høgsberg | 0704539 | 2012-02-19 18:52:44 -0500 | [diff] [blame] | 5964 | { |
| 5965 | struct switcher *switcher = |
| 5966 | container_of(listener, struct switcher, listener); |
| 5967 | |
| 5968 | switcher_next(switcher); |
| 5969 | } |
| 5970 | |
| 5971 | static void |
Daniel Stone | 351eb61 | 2012-05-31 15:27:47 -0400 | [diff] [blame] | 5972 | switcher_destroy(struct switcher *switcher) |
Kristian Høgsberg | 0704539 | 2012-02-19 18:52:44 -0500 | [diff] [blame] | 5973 | { |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 5974 | struct weston_view *view; |
Kristian Høgsberg | 29139d4 | 2013-04-18 15:25:39 -0400 | [diff] [blame] | 5975 | struct weston_keyboard *keyboard = switcher->grab.keyboard; |
Kristian Høgsberg | b0d8e77 | 2012-06-18 16:34:58 -0400 | [diff] [blame] | 5976 | struct workspace *ws = get_current_workspace(switcher->shell); |
Kristian Høgsberg | 0704539 | 2012-02-19 18:52:44 -0500 | [diff] [blame] | 5977 | |
Giulio Camuffo | 412e6a5 | 2014-07-09 22:12:56 +0300 | [diff] [blame] | 5978 | 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] | 5979 | if (is_focus_view(view)) |
| 5980 | continue; |
| 5981 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 5982 | view->alpha = 1.0; |
| 5983 | weston_surface_damage(view->surface); |
Kristian Høgsberg | 0704539 | 2012-02-19 18:52:44 -0500 | [diff] [blame] | 5984 | } |
| 5985 | |
Alex Wu | 07b2606 | 2012-03-12 16:06:01 +0800 | [diff] [blame] | 5986 | if (switcher->current) |
Daniel Stone | 37816df | 2012-05-16 18:45:18 +0100 | [diff] [blame] | 5987 | activate(switcher->shell, switcher->current, |
Derek Foreman | 8aeeac8 | 2015-01-30 13:24:36 -0600 | [diff] [blame] | 5988 | keyboard->seat, true); |
Kristian Høgsberg | 0704539 | 2012-02-19 18:52:44 -0500 | [diff] [blame] | 5989 | wl_list_remove(&switcher->listener.link); |
Kristian Høgsberg | 29139d4 | 2013-04-18 15:25:39 -0400 | [diff] [blame] | 5990 | weston_keyboard_end_grab(keyboard); |
| 5991 | if (keyboard->input_method_resource) |
| 5992 | keyboard->grab = &keyboard->input_method_grab; |
Manuel Bachmann | c1ae2e8 | 2014-02-26 15:53:11 +0100 | [diff] [blame] | 5993 | |
| 5994 | /* re-hide surfaces that were temporary shown during the switch */ |
| 5995 | struct weston_view **minimized; |
| 5996 | wl_array_for_each(minimized, &switcher->minimized_array) { |
| 5997 | /* with the exception of the current selected */ |
| 5998 | if ((*minimized)->surface != switcher->current) { |
Giulio Camuffo | 412e6a5 | 2014-07-09 22:12:56 +0300 | [diff] [blame] | 5999 | weston_layer_entry_remove(&(*minimized)->layer_link); |
| 6000 | 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] | 6001 | weston_view_damage_below(*minimized); |
| 6002 | } |
| 6003 | } |
| 6004 | wl_array_release(&switcher->minimized_array); |
| 6005 | |
Kristian Høgsberg | 0704539 | 2012-02-19 18:52:44 -0500 | [diff] [blame] | 6006 | free(switcher); |
| 6007 | } |
| 6008 | |
| 6009 | static void |
Kristian Høgsberg | 29139d4 | 2013-04-18 15:25:39 -0400 | [diff] [blame] | 6010 | switcher_key(struct weston_keyboard_grab *grab, |
Daniel Stone | c9785ea | 2012-05-30 16:31:52 +0100 | [diff] [blame] | 6011 | uint32_t time, uint32_t key, uint32_t state_w) |
Kristian Høgsberg | 0704539 | 2012-02-19 18:52:44 -0500 | [diff] [blame] | 6012 | { |
| 6013 | struct switcher *switcher = container_of(grab, struct switcher, grab); |
Daniel Stone | c9785ea | 2012-05-30 16:31:52 +0100 | [diff] [blame] | 6014 | enum wl_keyboard_key_state state = state_w; |
Daniel Stone | 351eb61 | 2012-05-31 15:27:47 -0400 | [diff] [blame] | 6015 | |
Daniel Stone | c9785ea | 2012-05-30 16:31:52 +0100 | [diff] [blame] | 6016 | if (key == KEY_TAB && state == WL_KEYBOARD_KEY_STATE_PRESSED) |
Daniel Stone | 351eb61 | 2012-05-31 15:27:47 -0400 | [diff] [blame] | 6017 | switcher_next(switcher); |
| 6018 | } |
| 6019 | |
| 6020 | static void |
Kristian Høgsberg | 29139d4 | 2013-04-18 15:25:39 -0400 | [diff] [blame] | 6021 | switcher_modifier(struct weston_keyboard_grab *grab, uint32_t serial, |
Daniel Stone | 351eb61 | 2012-05-31 15:27:47 -0400 | [diff] [blame] | 6022 | uint32_t mods_depressed, uint32_t mods_latched, |
| 6023 | uint32_t mods_locked, uint32_t group) |
| 6024 | { |
| 6025 | struct switcher *switcher = container_of(grab, struct switcher, grab); |
Derek Foreman | 8aeeac8 | 2015-01-30 13:24:36 -0600 | [diff] [blame] | 6026 | struct weston_seat *seat = grab->keyboard->seat; |
Kristian Høgsberg | 0704539 | 2012-02-19 18:52:44 -0500 | [diff] [blame] | 6027 | |
Daniel Stone | 351eb61 | 2012-05-31 15:27:47 -0400 | [diff] [blame] | 6028 | if ((seat->modifier_state & switcher->shell->binding_modifier) == 0) |
| 6029 | switcher_destroy(switcher); |
Kristian Høgsberg | b71302e | 2012-05-10 12:28:35 -0400 | [diff] [blame] | 6030 | } |
Kristian Høgsberg | 0704539 | 2012-02-19 18:52:44 -0500 | [diff] [blame] | 6031 | |
Jonas Ådahl | 1ea343e | 2013-10-25 23:18:05 +0200 | [diff] [blame] | 6032 | static void |
| 6033 | switcher_cancel(struct weston_keyboard_grab *grab) |
| 6034 | { |
| 6035 | struct switcher *switcher = container_of(grab, struct switcher, grab); |
| 6036 | |
| 6037 | switcher_destroy(switcher); |
| 6038 | } |
| 6039 | |
Kristian Høgsberg | 29139d4 | 2013-04-18 15:25:39 -0400 | [diff] [blame] | 6040 | static const struct weston_keyboard_grab_interface switcher_grab = { |
Daniel Stone | 351eb61 | 2012-05-31 15:27:47 -0400 | [diff] [blame] | 6041 | switcher_key, |
| 6042 | switcher_modifier, |
Jonas Ådahl | 1ea343e | 2013-10-25 23:18:05 +0200 | [diff] [blame] | 6043 | switcher_cancel, |
Kristian Høgsberg | 0704539 | 2012-02-19 18:52:44 -0500 | [diff] [blame] | 6044 | }; |
| 6045 | |
| 6046 | static void |
Kristian Høgsberg | e314875 | 2013-05-06 23:19:49 -0400 | [diff] [blame] | 6047 | switcher_binding(struct weston_seat *seat, uint32_t time, uint32_t key, |
Daniel Stone | 325fc2d | 2012-05-30 16:31:58 +0100 | [diff] [blame] | 6048 | void *data) |
Kristian Høgsberg | 0704539 | 2012-02-19 18:52:44 -0500 | [diff] [blame] | 6049 | { |
Tiago Vignatti | be14326 | 2012-04-16 17:31:41 +0300 | [diff] [blame] | 6050 | struct desktop_shell *shell = data; |
Kristian Høgsberg | 0704539 | 2012-02-19 18:52:44 -0500 | [diff] [blame] | 6051 | struct switcher *switcher; |
| 6052 | |
| 6053 | switcher = malloc(sizeof *switcher); |
Kristian Høgsberg | 02e79dc | 2012-04-12 09:55:26 -0400 | [diff] [blame] | 6054 | switcher->shell = shell; |
Kristian Høgsberg | 0704539 | 2012-02-19 18:52:44 -0500 | [diff] [blame] | 6055 | switcher->current = NULL; |
Kristian Høgsberg | 27e3052 | 2012-04-11 23:18:23 -0400 | [diff] [blame] | 6056 | switcher->listener.notify = switcher_handle_surface_destroy; |
Kristian Høgsberg | 0704539 | 2012-02-19 18:52:44 -0500 | [diff] [blame] | 6057 | wl_list_init(&switcher->listener.link); |
Manuel Bachmann | c1ae2e8 | 2014-02-26 15:53:11 +0100 | [diff] [blame] | 6058 | wl_array_init(&switcher->minimized_array); |
Kristian Høgsberg | 0704539 | 2012-02-19 18:52:44 -0500 | [diff] [blame] | 6059 | |
Alexander Larsson | f82b6ca | 2013-05-28 16:23:39 +0200 | [diff] [blame] | 6060 | restore_all_output_modes(shell->compositor); |
Kristian Høgsberg | b0d8e77 | 2012-06-18 16:34:58 -0400 | [diff] [blame] | 6061 | lower_fullscreen_layer(switcher->shell); |
Kristian Høgsberg | 0704539 | 2012-02-19 18:52:44 -0500 | [diff] [blame] | 6062 | switcher->grab.interface = &switcher_grab; |
Kristian Høgsberg | 29139d4 | 2013-04-18 15:25:39 -0400 | [diff] [blame] | 6063 | weston_keyboard_start_grab(seat->keyboard, &switcher->grab); |
| 6064 | weston_keyboard_set_focus(seat->keyboard, NULL); |
Kristian Høgsberg | 0704539 | 2012-02-19 18:52:44 -0500 | [diff] [blame] | 6065 | switcher_next(switcher); |
| 6066 | } |
| 6067 | |
Pekka Paalanen | 3c64723 | 2011-12-22 13:43:43 +0200 | [diff] [blame] | 6068 | static void |
Kristian Høgsberg | e314875 | 2013-05-06 23:19:49 -0400 | [diff] [blame] | 6069 | backlight_binding(struct weston_seat *seat, uint32_t time, uint32_t key, |
Daniel Stone | 325fc2d | 2012-05-30 16:31:58 +0100 | [diff] [blame] | 6070 | void *data) |
Tiago Vignatti | 8e53c7f | 2012-02-29 19:53:50 +0200 | [diff] [blame] | 6071 | { |
| 6072 | struct weston_compositor *compositor = data; |
| 6073 | struct weston_output *output; |
Tiago Vignatti | 5ab91ad | 2012-03-12 19:40:09 -0300 | [diff] [blame] | 6074 | long backlight_new = 0; |
Tiago Vignatti | 8e53c7f | 2012-02-29 19:53:50 +0200 | [diff] [blame] | 6075 | |
| 6076 | /* TODO: we're limiting to simple use cases, where we assume just |
| 6077 | * control on the primary display. We'd have to extend later if we |
| 6078 | * ever get support for setting backlights on random desktop LCD |
| 6079 | * panels though */ |
| 6080 | output = get_default_output(compositor); |
| 6081 | if (!output) |
| 6082 | return; |
| 6083 | |
| 6084 | if (!output->set_backlight) |
| 6085 | return; |
| 6086 | |
Tiago Vignatti | 5ab91ad | 2012-03-12 19:40:09 -0300 | [diff] [blame] | 6087 | if (key == KEY_F9 || key == KEY_BRIGHTNESSDOWN) |
| 6088 | backlight_new = output->backlight_current - 25; |
| 6089 | else if (key == KEY_F10 || key == KEY_BRIGHTNESSUP) |
| 6090 | backlight_new = output->backlight_current + 25; |
Tiago Vignatti | 8e53c7f | 2012-02-29 19:53:50 +0200 | [diff] [blame] | 6091 | |
Tiago Vignatti | 5ab91ad | 2012-03-12 19:40:09 -0300 | [diff] [blame] | 6092 | if (backlight_new < 5) |
| 6093 | backlight_new = 5; |
| 6094 | if (backlight_new > 255) |
| 6095 | backlight_new = 255; |
| 6096 | |
| 6097 | output->backlight_current = backlight_new; |
Tiago Vignatti | 8e53c7f | 2012-02-29 19:53:50 +0200 | [diff] [blame] | 6098 | output->set_backlight(output, output->backlight_current); |
| 6099 | } |
| 6100 | |
Ander Conselvan de Oliveira | c509d2b | 2012-11-08 17:20:45 +0200 | [diff] [blame] | 6101 | struct debug_binding_grab { |
Kristian Høgsberg | 29139d4 | 2013-04-18 15:25:39 -0400 | [diff] [blame] | 6102 | struct weston_keyboard_grab grab; |
Ander Conselvan de Oliveira | c509d2b | 2012-11-08 17:20:45 +0200 | [diff] [blame] | 6103 | struct weston_seat *seat; |
| 6104 | uint32_t key[2]; |
| 6105 | int key_released[2]; |
| 6106 | }; |
| 6107 | |
| 6108 | static void |
Kristian Høgsberg | 29139d4 | 2013-04-18 15:25:39 -0400 | [diff] [blame] | 6109 | 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] | 6110 | uint32_t key, uint32_t state) |
| 6111 | { |
| 6112 | struct debug_binding_grab *db = (struct debug_binding_grab *) grab; |
Rob Bradford | 880ebc7 | 2013-07-22 17:31:38 +0100 | [diff] [blame] | 6113 | struct weston_compositor *ec = db->seat->compositor; |
| 6114 | struct wl_display *display = ec->wl_display; |
Ander Conselvan de Oliveira | c509d2b | 2012-11-08 17:20:45 +0200 | [diff] [blame] | 6115 | struct wl_resource *resource; |
Ander Conselvan de Oliveira | c509d2b | 2012-11-08 17:20:45 +0200 | [diff] [blame] | 6116 | uint32_t serial; |
| 6117 | int send = 0, terminate = 0; |
| 6118 | int check_binding = 1; |
| 6119 | int i; |
Neil Roberts | 96d790e | 2013-09-19 17:32:00 +0100 | [diff] [blame] | 6120 | struct wl_list *resource_list; |
Ander Conselvan de Oliveira | c509d2b | 2012-11-08 17:20:45 +0200 | [diff] [blame] | 6121 | |
| 6122 | if (state == WL_KEYBOARD_KEY_STATE_RELEASED) { |
| 6123 | /* Do not run bindings on key releases */ |
| 6124 | check_binding = 0; |
| 6125 | |
| 6126 | for (i = 0; i < 2; i++) |
| 6127 | if (key == db->key[i]) |
| 6128 | db->key_released[i] = 1; |
| 6129 | |
| 6130 | if (db->key_released[0] && db->key_released[1]) { |
| 6131 | /* All key releases been swalled so end the grab */ |
| 6132 | terminate = 1; |
| 6133 | } else if (key != db->key[0] && key != db->key[1]) { |
| 6134 | /* Should not swallow release of other keys */ |
| 6135 | send = 1; |
| 6136 | } |
| 6137 | } else if (key == db->key[0] && !db->key_released[0]) { |
| 6138 | /* Do not check bindings for the first press of the binding |
| 6139 | * key. This allows it to be used as a debug shortcut. |
| 6140 | * We still need to swallow this event. */ |
| 6141 | check_binding = 0; |
| 6142 | } else if (db->key[1]) { |
| 6143 | /* If we already ran a binding don't process another one since |
| 6144 | * we can't keep track of all the binding keys that were |
| 6145 | * pressed in order to swallow the release events. */ |
| 6146 | send = 1; |
| 6147 | check_binding = 0; |
| 6148 | } |
| 6149 | |
| 6150 | if (check_binding) { |
Ander Conselvan de Oliveira | c509d2b | 2012-11-08 17:20:45 +0200 | [diff] [blame] | 6151 | if (weston_compositor_run_debug_binding(ec, db->seat, time, |
| 6152 | key, state)) { |
| 6153 | /* We ran a binding so swallow the press and keep the |
| 6154 | * grab to swallow the released too. */ |
| 6155 | send = 0; |
| 6156 | terminate = 0; |
| 6157 | db->key[1] = key; |
| 6158 | } else { |
| 6159 | /* Terminate the grab since the key pressed is not a |
| 6160 | * debug binding key. */ |
| 6161 | send = 1; |
| 6162 | terminate = 1; |
| 6163 | } |
| 6164 | } |
| 6165 | |
| 6166 | if (send) { |
Neil Roberts | 96d790e | 2013-09-19 17:32:00 +0100 | [diff] [blame] | 6167 | serial = wl_display_next_serial(display); |
| 6168 | resource_list = &grab->keyboard->focus_resource_list; |
| 6169 | wl_resource_for_each(resource, resource_list) { |
Ander Conselvan de Oliveira | c509d2b | 2012-11-08 17:20:45 +0200 | [diff] [blame] | 6170 | wl_keyboard_send_key(resource, serial, time, key, state); |
| 6171 | } |
| 6172 | } |
| 6173 | |
| 6174 | if (terminate) { |
Kristian Høgsberg | 29139d4 | 2013-04-18 15:25:39 -0400 | [diff] [blame] | 6175 | weston_keyboard_end_grab(grab->keyboard); |
| 6176 | if (grab->keyboard->input_method_resource) |
| 6177 | grab->keyboard->grab = &grab->keyboard->input_method_grab; |
Ander Conselvan de Oliveira | c509d2b | 2012-11-08 17:20:45 +0200 | [diff] [blame] | 6178 | free(db); |
| 6179 | } |
| 6180 | } |
| 6181 | |
| 6182 | static void |
Kristian Høgsberg | 29139d4 | 2013-04-18 15:25:39 -0400 | [diff] [blame] | 6183 | 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] | 6184 | uint32_t mods_depressed, uint32_t mods_latched, |
| 6185 | uint32_t mods_locked, uint32_t group) |
| 6186 | { |
| 6187 | struct wl_resource *resource; |
Neil Roberts | 96d790e | 2013-09-19 17:32:00 +0100 | [diff] [blame] | 6188 | struct wl_list *resource_list; |
Ander Conselvan de Oliveira | c509d2b | 2012-11-08 17:20:45 +0200 | [diff] [blame] | 6189 | |
Neil Roberts | 96d790e | 2013-09-19 17:32:00 +0100 | [diff] [blame] | 6190 | resource_list = &grab->keyboard->focus_resource_list; |
Ander Conselvan de Oliveira | c509d2b | 2012-11-08 17:20:45 +0200 | [diff] [blame] | 6191 | |
Neil Roberts | 96d790e | 2013-09-19 17:32:00 +0100 | [diff] [blame] | 6192 | wl_resource_for_each(resource, resource_list) { |
| 6193 | wl_keyboard_send_modifiers(resource, serial, mods_depressed, |
| 6194 | mods_latched, mods_locked, group); |
| 6195 | } |
Ander Conselvan de Oliveira | c509d2b | 2012-11-08 17:20:45 +0200 | [diff] [blame] | 6196 | } |
| 6197 | |
Jonas Ådahl | 1ea343e | 2013-10-25 23:18:05 +0200 | [diff] [blame] | 6198 | static void |
| 6199 | debug_binding_cancel(struct weston_keyboard_grab *grab) |
| 6200 | { |
| 6201 | struct debug_binding_grab *db = (struct debug_binding_grab *) grab; |
| 6202 | |
| 6203 | weston_keyboard_end_grab(grab->keyboard); |
| 6204 | free(db); |
| 6205 | } |
| 6206 | |
Kristian Høgsberg | 29139d4 | 2013-04-18 15:25:39 -0400 | [diff] [blame] | 6207 | struct weston_keyboard_grab_interface debug_binding_keyboard_grab = { |
Ander Conselvan de Oliveira | c509d2b | 2012-11-08 17:20:45 +0200 | [diff] [blame] | 6208 | debug_binding_key, |
Jonas Ådahl | 1ea343e | 2013-10-25 23:18:05 +0200 | [diff] [blame] | 6209 | debug_binding_modifiers, |
| 6210 | debug_binding_cancel, |
Ander Conselvan de Oliveira | c509d2b | 2012-11-08 17:20:45 +0200 | [diff] [blame] | 6211 | }; |
| 6212 | |
| 6213 | static void |
Kristian Høgsberg | e314875 | 2013-05-06 23:19:49 -0400 | [diff] [blame] | 6214 | 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] | 6215 | { |
| 6216 | struct debug_binding_grab *grab; |
| 6217 | |
| 6218 | grab = calloc(1, sizeof *grab); |
| 6219 | if (!grab) |
| 6220 | return; |
| 6221 | |
Derek Foreman | 8aeeac8 | 2015-01-30 13:24:36 -0600 | [diff] [blame] | 6222 | grab->seat = seat; |
Ander Conselvan de Oliveira | c509d2b | 2012-11-08 17:20:45 +0200 | [diff] [blame] | 6223 | grab->key[0] = key; |
| 6224 | grab->grab.interface = &debug_binding_keyboard_grab; |
Kristian Høgsberg | 29139d4 | 2013-04-18 15:25:39 -0400 | [diff] [blame] | 6225 | weston_keyboard_start_grab(seat->keyboard, &grab->grab); |
Ander Conselvan de Oliveira | c509d2b | 2012-11-08 17:20:45 +0200 | [diff] [blame] | 6226 | } |
| 6227 | |
Kristian Høgsberg | b41c081 | 2012-03-04 14:53:40 -0500 | [diff] [blame] | 6228 | static void |
Kristian Høgsberg | e314875 | 2013-05-06 23:19:49 -0400 | [diff] [blame] | 6229 | 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] | 6230 | void *data) |
Kristian Høgsberg | 92a57db | 2012-05-26 13:41:06 -0400 | [diff] [blame] | 6231 | { |
Kristian Høgsberg | fe7aa90 | 2013-05-08 09:54:37 -0400 | [diff] [blame] | 6232 | struct weston_surface *focus_surface; |
Kristian Høgsberg | 92a57db | 2012-05-26 13:41:06 -0400 | [diff] [blame] | 6233 | struct wl_client *client; |
Tiago Vignatti | 1d01b01 | 2012-09-27 17:48:36 +0300 | [diff] [blame] | 6234 | struct desktop_shell *shell = data; |
| 6235 | struct weston_compositor *compositor = shell->compositor; |
Kristian Høgsberg | 92a57db | 2012-05-26 13:41:06 -0400 | [diff] [blame] | 6236 | pid_t pid; |
Kristian Høgsberg | 92a57db | 2012-05-26 13:41:06 -0400 | [diff] [blame] | 6237 | |
Philipp Brüschweiler | 6cef009 | 2012-08-13 21:27:27 +0200 | [diff] [blame] | 6238 | focus_surface = seat->keyboard->focus; |
| 6239 | if (!focus_surface) |
| 6240 | return; |
| 6241 | |
Tiago Vignatti | 1d01b01 | 2012-09-27 17:48:36 +0300 | [diff] [blame] | 6242 | wl_signal_emit(&compositor->kill_signal, focus_surface); |
| 6243 | |
Jason Ekstrand | 26ed73c | 2013-06-06 22:34:41 -0500 | [diff] [blame] | 6244 | client = wl_resource_get_client(focus_surface->resource); |
Tiago Vignatti | 920f197 | 2012-09-27 17:48:35 +0300 | [diff] [blame] | 6245 | wl_client_get_credentials(client, &pid, NULL, NULL); |
| 6246 | |
| 6247 | /* Skip clients that we launched ourselves (the credentials of |
| 6248 | * the socketpair is ours) */ |
| 6249 | if (pid == getpid()) |
| 6250 | return; |
Kristian Høgsberg | 92a57db | 2012-05-26 13:41:06 -0400 | [diff] [blame] | 6251 | |
Daniel Stone | 325fc2d | 2012-05-30 16:31:58 +0100 | [diff] [blame] | 6252 | kill(pid, SIGKILL); |
Kristian Høgsberg | 92a57db | 2012-05-26 13:41:06 -0400 | [diff] [blame] | 6253 | } |
| 6254 | |
| 6255 | static void |
Kristian Høgsberg | e314875 | 2013-05-06 23:19:49 -0400 | [diff] [blame] | 6256 | workspace_up_binding(struct weston_seat *seat, uint32_t time, |
Jonas Ådahl | e3cddce | 2012-06-13 00:01:22 +0200 | [diff] [blame] | 6257 | uint32_t key, void *data) |
| 6258 | { |
| 6259 | struct desktop_shell *shell = data; |
| 6260 | unsigned int new_index = shell->workspaces.current; |
| 6261 | |
Kristian Høgsberg | ce345b0 | 2012-06-25 21:35:29 -0400 | [diff] [blame] | 6262 | if (shell->locked) |
Kristian Høgsberg | 4476aaf | 2012-06-25 14:03:13 -0400 | [diff] [blame] | 6263 | return; |
Jonas Ådahl | e3cddce | 2012-06-13 00:01:22 +0200 | [diff] [blame] | 6264 | if (new_index != 0) |
| 6265 | new_index--; |
| 6266 | |
| 6267 | change_workspace(shell, new_index); |
| 6268 | } |
| 6269 | |
| 6270 | static void |
Kristian Høgsberg | e314875 | 2013-05-06 23:19:49 -0400 | [diff] [blame] | 6271 | workspace_down_binding(struct weston_seat *seat, uint32_t time, |
Jonas Ådahl | e3cddce | 2012-06-13 00:01:22 +0200 | [diff] [blame] | 6272 | uint32_t key, void *data) |
| 6273 | { |
| 6274 | struct desktop_shell *shell = data; |
| 6275 | unsigned int new_index = shell->workspaces.current; |
| 6276 | |
Kristian Høgsberg | ce345b0 | 2012-06-25 21:35:29 -0400 | [diff] [blame] | 6277 | if (shell->locked) |
Kristian Høgsberg | 4476aaf | 2012-06-25 14:03:13 -0400 | [diff] [blame] | 6278 | return; |
Jonas Ådahl | e3cddce | 2012-06-13 00:01:22 +0200 | [diff] [blame] | 6279 | if (new_index < shell->workspaces.num - 1) |
| 6280 | new_index++; |
| 6281 | |
| 6282 | change_workspace(shell, new_index); |
| 6283 | } |
| 6284 | |
| 6285 | static void |
Kristian Høgsberg | e314875 | 2013-05-06 23:19:49 -0400 | [diff] [blame] | 6286 | workspace_f_binding(struct weston_seat *seat, uint32_t time, |
Jonas Ådahl | e3cddce | 2012-06-13 00:01:22 +0200 | [diff] [blame] | 6287 | uint32_t key, void *data) |
| 6288 | { |
| 6289 | struct desktop_shell *shell = data; |
| 6290 | unsigned int new_index; |
| 6291 | |
Kristian Høgsberg | ce345b0 | 2012-06-25 21:35:29 -0400 | [diff] [blame] | 6292 | if (shell->locked) |
Kristian Høgsberg | 4476aaf | 2012-06-25 14:03:13 -0400 | [diff] [blame] | 6293 | return; |
Jonas Ådahl | e3cddce | 2012-06-13 00:01:22 +0200 | [diff] [blame] | 6294 | new_index = key - KEY_F1; |
| 6295 | if (new_index >= shell->workspaces.num) |
| 6296 | new_index = shell->workspaces.num - 1; |
| 6297 | |
| 6298 | change_workspace(shell, new_index); |
| 6299 | } |
| 6300 | |
Jonas Ådahl | 8de6a1d | 2012-08-29 22:13:00 +0200 | [diff] [blame] | 6301 | static void |
Kristian Høgsberg | e314875 | 2013-05-06 23:19:49 -0400 | [diff] [blame] | 6302 | workspace_move_surface_up_binding(struct weston_seat *seat, uint32_t time, |
Jonas Ådahl | 8de6a1d | 2012-08-29 22:13:00 +0200 | [diff] [blame] | 6303 | uint32_t key, void *data) |
| 6304 | { |
| 6305 | struct desktop_shell *shell = data; |
| 6306 | unsigned int new_index = shell->workspaces.current; |
| 6307 | |
| 6308 | if (shell->locked) |
| 6309 | return; |
| 6310 | |
| 6311 | if (new_index != 0) |
| 6312 | new_index--; |
| 6313 | |
| 6314 | take_surface_to_workspace_by_seat(shell, seat, new_index); |
| 6315 | } |
| 6316 | |
| 6317 | static void |
Kristian Høgsberg | e314875 | 2013-05-06 23:19:49 -0400 | [diff] [blame] | 6318 | workspace_move_surface_down_binding(struct weston_seat *seat, uint32_t time, |
Jonas Ådahl | 8de6a1d | 2012-08-29 22:13:00 +0200 | [diff] [blame] | 6319 | uint32_t key, void *data) |
| 6320 | { |
| 6321 | struct desktop_shell *shell = data; |
| 6322 | unsigned int new_index = shell->workspaces.current; |
| 6323 | |
| 6324 | if (shell->locked) |
| 6325 | return; |
| 6326 | |
| 6327 | if (new_index < shell->workspaces.num - 1) |
| 6328 | new_index++; |
| 6329 | |
| 6330 | take_surface_to_workspace_by_seat(shell, seat, new_index); |
| 6331 | } |
Jonas Ådahl | e3cddce | 2012-06-13 00:01:22 +0200 | [diff] [blame] | 6332 | |
| 6333 | static void |
Ander Conselvan de Oliveira | c94d622 | 2014-01-29 18:47:54 +0200 | [diff] [blame] | 6334 | shell_reposition_view_on_output_destroy(struct weston_view *view) |
| 6335 | { |
| 6336 | struct weston_output *output, *first_output; |
| 6337 | struct weston_compositor *ec = view->surface->compositor; |
| 6338 | struct shell_surface *shsurf; |
| 6339 | float x, y; |
| 6340 | int visible; |
| 6341 | |
| 6342 | x = view->geometry.x; |
| 6343 | y = view->geometry.y; |
| 6344 | |
| 6345 | /* At this point the destroyed output is not in the list anymore. |
| 6346 | * If the view is still visible somewhere, we leave where it is, |
| 6347 | * otherwise, move it to the first output. */ |
| 6348 | visible = 0; |
| 6349 | wl_list_for_each(output, &ec->output_list, link) { |
| 6350 | if (pixman_region32_contains_point(&output->region, |
| 6351 | x, y, NULL)) { |
| 6352 | visible = 1; |
| 6353 | break; |
| 6354 | } |
| 6355 | } |
| 6356 | |
| 6357 | if (!visible) { |
| 6358 | first_output = container_of(ec->output_list.next, |
| 6359 | struct weston_output, link); |
| 6360 | |
| 6361 | x = first_output->x + first_output->width / 4; |
| 6362 | y = first_output->y + first_output->height / 4; |
Xiong Zhang | 62899f5 | 2014-03-07 16:27:19 +0800 | [diff] [blame] | 6363 | |
| 6364 | weston_view_set_position(view, x, y); |
| 6365 | } else { |
| 6366 | weston_view_geometry_dirty(view); |
Ander Conselvan de Oliveira | c94d622 | 2014-01-29 18:47:54 +0200 | [diff] [blame] | 6367 | } |
| 6368 | |
Ander Conselvan de Oliveira | c94d622 | 2014-01-29 18:47:54 +0200 | [diff] [blame] | 6369 | |
| 6370 | shsurf = get_shell_surface(view->surface); |
| 6371 | |
| 6372 | if (shsurf) { |
| 6373 | shsurf->saved_position_valid = false; |
| 6374 | shsurf->next_state.maximized = false; |
| 6375 | shsurf->next_state.fullscreen = false; |
| 6376 | shsurf->state_changed = true; |
| 6377 | } |
| 6378 | } |
| 6379 | |
Ander Conselvan de Oliveira | 304996d | 2014-04-11 13:57:15 +0300 | [diff] [blame] | 6380 | void |
| 6381 | shell_for_each_layer(struct desktop_shell *shell, |
| 6382 | shell_for_each_layer_func_t func, void *data) |
Ander Conselvan de Oliveira | c94d622 | 2014-01-29 18:47:54 +0200 | [diff] [blame] | 6383 | { |
Ander Conselvan de Oliveira | 304996d | 2014-04-11 13:57:15 +0300 | [diff] [blame] | 6384 | struct workspace **ws; |
| 6385 | |
| 6386 | func(shell, &shell->fullscreen_layer, data); |
| 6387 | func(shell, &shell->panel_layer, data); |
| 6388 | func(shell, &shell->background_layer, data); |
| 6389 | func(shell, &shell->lock_layer, data); |
| 6390 | func(shell, &shell->input_panel_layer, data); |
| 6391 | |
| 6392 | wl_array_for_each(ws, &shell->workspaces.array) |
| 6393 | func(shell, &(*ws)->layer, data); |
| 6394 | } |
| 6395 | |
| 6396 | static void |
| 6397 | shell_output_destroy_move_layer(struct desktop_shell *shell, |
| 6398 | struct weston_layer *layer, |
| 6399 | void *data) |
| 6400 | { |
| 6401 | struct weston_output *output = data; |
Ander Conselvan de Oliveira | c94d622 | 2014-01-29 18:47:54 +0200 | [diff] [blame] | 6402 | struct weston_view *view; |
| 6403 | |
Giulio Camuffo | 412e6a5 | 2014-07-09 22:12:56 +0300 | [diff] [blame] | 6404 | 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] | 6405 | if (view->output != output) |
| 6406 | continue; |
Ander Conselvan de Oliveira | c94d622 | 2014-01-29 18:47:54 +0200 | [diff] [blame] | 6407 | |
Ander Conselvan de Oliveira | 304996d | 2014-04-11 13:57:15 +0300 | [diff] [blame] | 6408 | shell_reposition_view_on_output_destroy(view); |
Ander Conselvan de Oliveira | c94d622 | 2014-01-29 18:47:54 +0200 | [diff] [blame] | 6409 | } |
| 6410 | } |
| 6411 | |
| 6412 | static void |
Xiong Zhang | 6b48142 | 2013-10-23 13:58:32 +0800 | [diff] [blame] | 6413 | handle_output_destroy(struct wl_listener *listener, void *data) |
| 6414 | { |
| 6415 | struct shell_output *output_listener = |
| 6416 | container_of(listener, struct shell_output, destroy_listener); |
Ander Conselvan de Oliveira | 304996d | 2014-04-11 13:57:15 +0300 | [diff] [blame] | 6417 | struct weston_output *output = output_listener->output; |
| 6418 | struct desktop_shell *shell = output_listener->shell; |
Xiong Zhang | 6b48142 | 2013-10-23 13:58:32 +0800 | [diff] [blame] | 6419 | |
Ander Conselvan de Oliveira | 304996d | 2014-04-11 13:57:15 +0300 | [diff] [blame] | 6420 | 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] | 6421 | |
Xiong Zhang | 6b48142 | 2013-10-23 13:58:32 +0800 | [diff] [blame] | 6422 | wl_list_remove(&output_listener->destroy_listener.link); |
| 6423 | wl_list_remove(&output_listener->link); |
| 6424 | free(output_listener); |
| 6425 | } |
| 6426 | |
| 6427 | static void |
| 6428 | create_shell_output(struct desktop_shell *shell, |
| 6429 | struct weston_output *output) |
| 6430 | { |
| 6431 | struct shell_output *shell_output; |
| 6432 | |
| 6433 | shell_output = zalloc(sizeof *shell_output); |
| 6434 | if (shell_output == NULL) |
| 6435 | return; |
| 6436 | |
| 6437 | shell_output->output = output; |
| 6438 | shell_output->shell = shell; |
| 6439 | shell_output->destroy_listener.notify = handle_output_destroy; |
| 6440 | wl_signal_add(&output->destroy_signal, |
| 6441 | &shell_output->destroy_listener); |
Kristian Høgsberg | a3a0e18 | 2013-10-23 23:36:04 -0700 | [diff] [blame] | 6442 | wl_list_insert(shell->output_list.prev, &shell_output->link); |
Xiong Zhang | 6b48142 | 2013-10-23 13:58:32 +0800 | [diff] [blame] | 6443 | } |
| 6444 | |
| 6445 | static void |
| 6446 | handle_output_create(struct wl_listener *listener, void *data) |
| 6447 | { |
| 6448 | struct desktop_shell *shell = |
| 6449 | container_of(listener, struct desktop_shell, output_create_listener); |
| 6450 | struct weston_output *output = (struct weston_output *)data; |
| 6451 | |
| 6452 | create_shell_output(shell, output); |
| 6453 | } |
| 6454 | |
| 6455 | static void |
Ander Conselvan de Oliveira | 304996d | 2014-04-11 13:57:15 +0300 | [diff] [blame] | 6456 | handle_output_move_layer(struct desktop_shell *shell, |
| 6457 | struct weston_layer *layer, void *data) |
Ander Conselvan de Oliveira | a8a9baf | 2014-01-29 18:47:52 +0200 | [diff] [blame] | 6458 | { |
Ander Conselvan de Oliveira | 304996d | 2014-04-11 13:57:15 +0300 | [diff] [blame] | 6459 | struct weston_output *output = data; |
Ander Conselvan de Oliveira | a8a9baf | 2014-01-29 18:47:52 +0200 | [diff] [blame] | 6460 | struct weston_view *view; |
| 6461 | float x, y; |
| 6462 | |
Giulio Camuffo | 412e6a5 | 2014-07-09 22:12:56 +0300 | [diff] [blame] | 6463 | 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] | 6464 | if (view->output != output) |
| 6465 | continue; |
| 6466 | |
| 6467 | x = view->geometry.x + output->move_x; |
| 6468 | y = view->geometry.y + output->move_y; |
| 6469 | weston_view_set_position(view, x, y); |
| 6470 | } |
| 6471 | } |
| 6472 | |
| 6473 | static void |
| 6474 | handle_output_move(struct wl_listener *listener, void *data) |
| 6475 | { |
| 6476 | struct desktop_shell *shell; |
| 6477 | |
Ander Conselvan de Oliveira | a8a9baf | 2014-01-29 18:47:52 +0200 | [diff] [blame] | 6478 | shell = container_of(listener, struct desktop_shell, |
| 6479 | output_move_listener); |
Ander Conselvan de Oliveira | a8a9baf | 2014-01-29 18:47:52 +0200 | [diff] [blame] | 6480 | |
Ander Conselvan de Oliveira | 304996d | 2014-04-11 13:57:15 +0300 | [diff] [blame] | 6481 | shell_for_each_layer(shell, handle_output_move_layer, data); |
Ander Conselvan de Oliveira | a8a9baf | 2014-01-29 18:47:52 +0200 | [diff] [blame] | 6482 | } |
| 6483 | |
| 6484 | static void |
Xiong Zhang | 6b48142 | 2013-10-23 13:58:32 +0800 | [diff] [blame] | 6485 | setup_output_destroy_handler(struct weston_compositor *ec, |
| 6486 | struct desktop_shell *shell) |
| 6487 | { |
| 6488 | struct weston_output *output; |
| 6489 | |
| 6490 | wl_list_init(&shell->output_list); |
| 6491 | wl_list_for_each(output, &ec->output_list, link) |
| 6492 | create_shell_output(shell, output); |
| 6493 | |
| 6494 | shell->output_create_listener.notify = handle_output_create; |
| 6495 | wl_signal_add(&ec->output_created_signal, |
| 6496 | &shell->output_create_listener); |
Ander Conselvan de Oliveira | a8a9baf | 2014-01-29 18:47:52 +0200 | [diff] [blame] | 6497 | |
| 6498 | shell->output_move_listener.notify = handle_output_move; |
| 6499 | wl_signal_add(&ec->output_moved_signal, &shell->output_move_listener); |
Xiong Zhang | 6b48142 | 2013-10-23 13:58:32 +0800 | [diff] [blame] | 6500 | } |
| 6501 | |
| 6502 | static void |
Kristian Høgsberg | 02e79dc | 2012-04-12 09:55:26 -0400 | [diff] [blame] | 6503 | shell_destroy(struct wl_listener *listener, void *data) |
Pekka Paalanen | 3c64723 | 2011-12-22 13:43:43 +0200 | [diff] [blame] | 6504 | { |
Tiago Vignatti | be14326 | 2012-04-16 17:31:41 +0300 | [diff] [blame] | 6505 | struct desktop_shell *shell = |
| 6506 | container_of(listener, struct desktop_shell, destroy_listener); |
Jonas Ådahl | e3cddce | 2012-06-13 00:01:22 +0200 | [diff] [blame] | 6507 | struct workspace **ws; |
Xiong Zhang | 6b48142 | 2013-10-23 13:58:32 +0800 | [diff] [blame] | 6508 | struct shell_output *shell_output, *tmp; |
Pekka Paalanen | 3c64723 | 2011-12-22 13:43:43 +0200 | [diff] [blame] | 6509 | |
Kristian Høgsberg | 17bccae | 2014-01-16 16:46:28 -0800 | [diff] [blame] | 6510 | /* Force state to unlocked so we don't try to fade */ |
| 6511 | shell->locked = false; |
Pekka Paalanen | 826dc14 | 2014-08-27 12:11:53 +0300 | [diff] [blame] | 6512 | |
| 6513 | if (shell->child.client) { |
| 6514 | /* disable respawn */ |
| 6515 | wl_list_remove(&shell->child.client_destroy_listener.link); |
Pekka Paalanen | 9cf5cc8 | 2012-01-02 16:00:24 +0200 | [diff] [blame] | 6516 | wl_client_destroy(shell->child.client); |
Pekka Paalanen | 826dc14 | 2014-08-27 12:11:53 +0300 | [diff] [blame] | 6517 | } |
Pekka Paalanen | 9cf5cc8 | 2012-01-02 16:00:24 +0200 | [diff] [blame] | 6518 | |
Ander Conselvan de Oliveira | a457563 | 2013-02-21 18:35:23 +0200 | [diff] [blame] | 6519 | wl_list_remove(&shell->idle_listener.link); |
| 6520 | wl_list_remove(&shell->wake_listener.link); |
Kristian Høgsberg | 677a5f5 | 2013-12-04 11:00:19 -0800 | [diff] [blame] | 6521 | |
| 6522 | input_panel_destroy(shell); |
Kristian Høgsberg | 88c1607 | 2012-05-16 08:04:19 -0400 | [diff] [blame] | 6523 | |
Xiong Zhang | 6b48142 | 2013-10-23 13:58:32 +0800 | [diff] [blame] | 6524 | wl_list_for_each_safe(shell_output, tmp, &shell->output_list, link) { |
| 6525 | wl_list_remove(&shell_output->destroy_listener.link); |
| 6526 | wl_list_remove(&shell_output->link); |
| 6527 | free(shell_output); |
| 6528 | } |
| 6529 | |
| 6530 | wl_list_remove(&shell->output_create_listener.link); |
Kristian Høgsberg | 6d50b0f | 2014-04-30 20:46:25 -0700 | [diff] [blame] | 6531 | wl_list_remove(&shell->output_move_listener.link); |
Xiong Zhang | 6b48142 | 2013-10-23 13:58:32 +0800 | [diff] [blame] | 6532 | |
Jonas Ådahl | e3cddce | 2012-06-13 00:01:22 +0200 | [diff] [blame] | 6533 | wl_array_for_each(ws, &shell->workspaces.array) |
| 6534 | workspace_destroy(*ws); |
| 6535 | wl_array_release(&shell->workspaces.array); |
| 6536 | |
Pekka Paalanen | 3c64723 | 2011-12-22 13:43:43 +0200 | [diff] [blame] | 6537 | free(shell->screensaver.path); |
Emilio Pozuelo Monfort | 46ce798 | 2013-11-20 13:22:29 +0100 | [diff] [blame] | 6538 | free(shell->client); |
Pekka Paalanen | 3c64723 | 2011-12-22 13:43:43 +0200 | [diff] [blame] | 6539 | free(shell); |
| 6540 | } |
| 6541 | |
Tiago Vignatti | 0b52d48 | 2012-04-20 18:54:25 +0300 | [diff] [blame] | 6542 | static void |
| 6543 | shell_add_bindings(struct weston_compositor *ec, struct desktop_shell *shell) |
| 6544 | { |
| 6545 | uint32_t mod; |
Jonas Ådahl | e3cddce | 2012-06-13 00:01:22 +0200 | [diff] [blame] | 6546 | int i, num_workspace_bindings; |
Tiago Vignatti | 0b52d48 | 2012-04-20 18:54:25 +0300 | [diff] [blame] | 6547 | |
| 6548 | /* fixed bindings */ |
Daniel Stone | 325fc2d | 2012-05-30 16:31:58 +0100 | [diff] [blame] | 6549 | weston_compositor_add_key_binding(ec, KEY_BACKSPACE, |
| 6550 | MODIFIER_CTRL | MODIFIER_ALT, |
| 6551 | terminate_binding, ec); |
| 6552 | weston_compositor_add_button_binding(ec, BTN_LEFT, 0, |
| 6553 | click_to_activate_binding, |
| 6554 | shell); |
Kristian Høgsberg | f0ce581 | 2014-04-07 11:52:17 -0700 | [diff] [blame] | 6555 | weston_compositor_add_button_binding(ec, BTN_RIGHT, 0, |
| 6556 | click_to_activate_binding, |
| 6557 | shell); |
Neil Roberts | a28c693 | 2013-10-03 16:43:04 +0100 | [diff] [blame] | 6558 | weston_compositor_add_touch_binding(ec, 0, |
| 6559 | touch_to_activate_binding, |
| 6560 | shell); |
Daniel Stone | 325fc2d | 2012-05-30 16:31:58 +0100 | [diff] [blame] | 6561 | weston_compositor_add_axis_binding(ec, WL_POINTER_AXIS_VERTICAL_SCROLL, |
| 6562 | MODIFIER_SUPER | MODIFIER_ALT, |
| 6563 | surface_opacity_binding, NULL); |
| 6564 | weston_compositor_add_axis_binding(ec, WL_POINTER_AXIS_VERTICAL_SCROLL, |
| 6565 | MODIFIER_SUPER, zoom_axis_binding, |
| 6566 | NULL); |
Tiago Vignatti | 0b52d48 | 2012-04-20 18:54:25 +0300 | [diff] [blame] | 6567 | |
| 6568 | /* configurable bindings */ |
| 6569 | mod = shell->binding_modifier; |
Daniel Stone | 325fc2d | 2012-05-30 16:31:58 +0100 | [diff] [blame] | 6570 | weston_compositor_add_key_binding(ec, KEY_PAGEUP, mod, |
| 6571 | zoom_key_binding, NULL); |
| 6572 | weston_compositor_add_key_binding(ec, KEY_PAGEDOWN, mod, |
| 6573 | zoom_key_binding, NULL); |
Kristian Høgsberg | 211b517 | 2014-01-11 13:10:21 -0800 | [diff] [blame] | 6574 | weston_compositor_add_key_binding(ec, KEY_M, mod | MODIFIER_SHIFT, |
| 6575 | maximize_binding, NULL); |
| 6576 | weston_compositor_add_key_binding(ec, KEY_F, mod | MODIFIER_SHIFT, |
| 6577 | fullscreen_binding, NULL); |
Daniel Stone | 325fc2d | 2012-05-30 16:31:58 +0100 | [diff] [blame] | 6578 | weston_compositor_add_button_binding(ec, BTN_LEFT, mod, move_binding, |
| 6579 | shell); |
Neil Roberts | aba0f25 | 2013-10-03 16:43:05 +0100 | [diff] [blame] | 6580 | weston_compositor_add_touch_binding(ec, mod, touch_move_binding, shell); |
Daniel Stone | 325fc2d | 2012-05-30 16:31:58 +0100 | [diff] [blame] | 6581 | weston_compositor_add_button_binding(ec, BTN_MIDDLE, mod, |
| 6582 | resize_binding, shell); |
Kristian Høgsberg | 0837fa9 | 2014-01-20 10:35:26 -0800 | [diff] [blame] | 6583 | weston_compositor_add_button_binding(ec, BTN_LEFT, |
| 6584 | mod | MODIFIER_SHIFT, |
| 6585 | resize_binding, shell); |
Pekka Paalanen | 7bb6510 | 2013-05-22 18:03:04 +0300 | [diff] [blame] | 6586 | |
| 6587 | if (ec->capabilities & WESTON_CAP_ROTATION_ANY) |
| 6588 | weston_compositor_add_button_binding(ec, BTN_RIGHT, mod, |
| 6589 | rotate_binding, NULL); |
| 6590 | |
Daniel Stone | 325fc2d | 2012-05-30 16:31:58 +0100 | [diff] [blame] | 6591 | weston_compositor_add_key_binding(ec, KEY_TAB, mod, switcher_binding, |
| 6592 | shell); |
| 6593 | weston_compositor_add_key_binding(ec, KEY_F9, mod, backlight_binding, |
| 6594 | ec); |
| 6595 | weston_compositor_add_key_binding(ec, KEY_BRIGHTNESSDOWN, 0, |
| 6596 | backlight_binding, ec); |
| 6597 | weston_compositor_add_key_binding(ec, KEY_F10, mod, backlight_binding, |
| 6598 | ec); |
| 6599 | weston_compositor_add_key_binding(ec, KEY_BRIGHTNESSUP, 0, |
| 6600 | backlight_binding, ec); |
Daniel Stone | 325fc2d | 2012-05-30 16:31:58 +0100 | [diff] [blame] | 6601 | weston_compositor_add_key_binding(ec, KEY_K, mod, |
| 6602 | force_kill_binding, shell); |
Jonas Ådahl | e3cddce | 2012-06-13 00:01:22 +0200 | [diff] [blame] | 6603 | weston_compositor_add_key_binding(ec, KEY_UP, mod, |
| 6604 | workspace_up_binding, shell); |
| 6605 | weston_compositor_add_key_binding(ec, KEY_DOWN, mod, |
| 6606 | workspace_down_binding, shell); |
Jonas Ådahl | 8de6a1d | 2012-08-29 22:13:00 +0200 | [diff] [blame] | 6607 | weston_compositor_add_key_binding(ec, KEY_UP, mod | MODIFIER_SHIFT, |
| 6608 | workspace_move_surface_up_binding, |
| 6609 | shell); |
| 6610 | weston_compositor_add_key_binding(ec, KEY_DOWN, mod | MODIFIER_SHIFT, |
| 6611 | workspace_move_surface_down_binding, |
| 6612 | shell); |
Jonas Ådahl | e3cddce | 2012-06-13 00:01:22 +0200 | [diff] [blame] | 6613 | |
Kristian Høgsberg | d56ab4e | 2014-01-16 16:51:52 -0800 | [diff] [blame] | 6614 | if (shell->exposay_modifier) |
| 6615 | weston_compositor_add_modifier_binding(ec, shell->exposay_modifier, |
| 6616 | exposay_binding, shell); |
Daniel Stone | df8133b | 2013-11-19 11:37:14 +0100 | [diff] [blame] | 6617 | |
Jonas Ådahl | e3cddce | 2012-06-13 00:01:22 +0200 | [diff] [blame] | 6618 | /* Add bindings for mod+F[1-6] for workspace 1 to 6. */ |
| 6619 | if (shell->workspaces.num > 1) { |
| 6620 | num_workspace_bindings = shell->workspaces.num; |
| 6621 | if (num_workspace_bindings > 6) |
| 6622 | num_workspace_bindings = 6; |
| 6623 | for (i = 0; i < num_workspace_bindings; i++) |
| 6624 | weston_compositor_add_key_binding(ec, KEY_F1 + i, mod, |
| 6625 | workspace_f_binding, |
| 6626 | shell); |
| 6627 | } |
Ander Conselvan de Oliveira | c509d2b | 2012-11-08 17:20:45 +0200 | [diff] [blame] | 6628 | |
| 6629 | /* Debug bindings */ |
| 6630 | weston_compositor_add_key_binding(ec, KEY_SPACE, mod | MODIFIER_SHIFT, |
| 6631 | debug_binding, shell); |
Tiago Vignatti | 0b52d48 | 2012-04-20 18:54:25 +0300 | [diff] [blame] | 6632 | } |
| 6633 | |
Jason Ekstrand | 024177c | 2014-04-21 19:42:58 -0500 | [diff] [blame] | 6634 | static void |
| 6635 | handle_seat_created(struct wl_listener *listener, void *data) |
| 6636 | { |
| 6637 | struct weston_seat *seat = data; |
| 6638 | |
| 6639 | create_shell_seat(seat); |
| 6640 | } |
| 6641 | |
Kristian Høgsberg | 1c56218 | 2011-05-02 22:09:20 -0400 | [diff] [blame] | 6642 | WL_EXPORT int |
Kristian Høgsberg | cb4685b | 2013-02-20 15:37:49 -0500 | [diff] [blame] | 6643 | module_init(struct weston_compositor *ec, |
Ossama Othman | a50e6e4 | 2013-05-14 09:48:26 -0700 | [diff] [blame] | 6644 | int *argc, char *argv[]) |
Kristian Høgsberg | 4cca349 | 2011-01-18 07:53:49 -0500 | [diff] [blame] | 6645 | { |
Kristian Høgsberg | f4d2f23 | 2012-08-10 10:05:39 -0400 | [diff] [blame] | 6646 | struct weston_seat *seat; |
Tiago Vignatti | be14326 | 2012-04-16 17:31:41 +0300 | [diff] [blame] | 6647 | struct desktop_shell *shell; |
Jonas Ådahl | e3cddce | 2012-06-13 00:01:22 +0200 | [diff] [blame] | 6648 | struct workspace **pws; |
| 6649 | unsigned int i; |
Tiago Vignatti | b7dbbd6 | 2012-09-25 17:57:01 +0300 | [diff] [blame] | 6650 | struct wl_event_loop *loop; |
Kristian Høgsberg | 02ec0a5 | 2011-04-23 13:04:11 -0400 | [diff] [blame] | 6651 | |
Peter Hutterer | f3d6227 | 2013-08-08 11:57:05 +1000 | [diff] [blame] | 6652 | shell = zalloc(sizeof *shell); |
Kristian Høgsberg | 02ec0a5 | 2011-04-23 13:04:11 -0400 | [diff] [blame] | 6653 | if (shell == NULL) |
| 6654 | return -1; |
| 6655 | |
Kristian Høgsberg | 7584062 | 2011-09-06 13:48:16 -0400 | [diff] [blame] | 6656 | shell->compositor = ec; |
Kristian Høgsberg | 02e79dc | 2012-04-12 09:55:26 -0400 | [diff] [blame] | 6657 | |
| 6658 | shell->destroy_listener.notify = shell_destroy; |
| 6659 | wl_signal_add(&ec->destroy_signal, &shell->destroy_listener); |
Ander Conselvan de Oliveira | a457563 | 2013-02-21 18:35:23 +0200 | [diff] [blame] | 6660 | shell->idle_listener.notify = idle_handler; |
| 6661 | wl_signal_add(&ec->idle_signal, &shell->idle_listener); |
| 6662 | shell->wake_listener.notify = wake_handler; |
| 6663 | wl_signal_add(&ec->wake_signal, &shell->wake_listener); |
Kristian Høgsberg | 677a5f5 | 2013-12-04 11:00:19 -0800 | [diff] [blame] | 6664 | |
Kristian Høgsberg | 82a1d11 | 2012-07-19 14:02:00 -0400 | [diff] [blame] | 6665 | ec->shell_interface.shell = shell; |
Tiago Vignatti | bc052c9 | 2012-04-19 16:18:18 +0300 | [diff] [blame] | 6666 | ec->shell_interface.create_shell_surface = create_shell_surface; |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 6667 | ec->shell_interface.get_primary_view = get_primary_view; |
Tiago Vignatti | bc052c9 | 2012-04-19 16:18:18 +0300 | [diff] [blame] | 6668 | ec->shell_interface.set_toplevel = set_toplevel; |
Tiago Vignatti | 491bac1 | 2012-05-18 16:37:43 -0400 | [diff] [blame] | 6669 | ec->shell_interface.set_transient = set_transient; |
Kristian Høgsberg | 4779241 | 2014-05-04 13:47:06 -0700 | [diff] [blame] | 6670 | ec->shell_interface.set_fullscreen = shell_interface_set_fullscreen; |
Tiago Vignatti | fb2adba | 2013-06-12 15:43:21 -0300 | [diff] [blame] | 6671 | ec->shell_interface.set_xwayland = set_xwayland; |
Kristian Høgsberg | ae356ae | 2014-04-29 16:03:54 -0700 | [diff] [blame] | 6672 | ec->shell_interface.move = shell_interface_move; |
Kristian Høgsberg | c1693f2 | 2012-05-22 16:56:23 -0400 | [diff] [blame] | 6673 | ec->shell_interface.resize = surface_resize; |
Giulio Camuffo | 62942ad | 2013-09-11 18:20:47 +0200 | [diff] [blame] | 6674 | ec->shell_interface.set_title = set_title; |
Jasper St. Pierre | ccf48fb | 2014-05-02 10:21:38 -0400 | [diff] [blame] | 6675 | ec->shell_interface.set_window_geometry = set_window_geometry; |
Giulio Camuffo | 6b4b241 | 2015-01-29 19:06:49 +0200 | [diff] [blame] | 6676 | ec->shell_interface.set_maximized = shell_interface_set_maximized; |
Kristian Høgsberg | 4cca349 | 2011-01-18 07:53:49 -0500 | [diff] [blame] | 6677 | |
Kristian Høgsberg | 3be2ce9 | 2012-02-29 12:42:35 -0500 | [diff] [blame] | 6678 | weston_layer_init(&shell->fullscreen_layer, &ec->cursor_layer.link); |
| 6679 | weston_layer_init(&shell->panel_layer, &shell->fullscreen_layer.link); |
Jonas Ådahl | e3cddce | 2012-06-13 00:01:22 +0200 | [diff] [blame] | 6680 | weston_layer_init(&shell->background_layer, &shell->panel_layer.link); |
| 6681 | weston_layer_init(&shell->lock_layer, NULL); |
Philipp Brüschweiler | 711fda8 | 2012-08-09 18:50:43 +0200 | [diff] [blame] | 6682 | weston_layer_init(&shell->input_panel_layer, NULL); |
Jonas Ådahl | e3cddce | 2012-06-13 00:01:22 +0200 | [diff] [blame] | 6683 | |
| 6684 | wl_array_init(&shell->workspaces.array); |
Jonas Ådahl | e9d2250 | 2012-08-29 22:13:01 +0200 | [diff] [blame] | 6685 | wl_list_init(&shell->workspaces.client_list); |
Kristian Høgsberg | 3be2ce9 | 2012-02-29 12:42:35 -0500 | [diff] [blame] | 6686 | |
Kristian Høgsberg | 677a5f5 | 2013-12-04 11:00:19 -0800 | [diff] [blame] | 6687 | if (input_panel_setup(shell) < 0) |
| 6688 | return -1; |
| 6689 | |
Kristian Høgsberg | 14e438c | 2013-05-26 21:48:14 -0400 | [diff] [blame] | 6690 | shell_configuration(shell); |
Pekka Paalanen | e955f1e | 2011-12-07 11:49:52 +0200 | [diff] [blame] | 6691 | |
Daniel Stone | df8133b | 2013-11-19 11:37:14 +0100 | [diff] [blame] | 6692 | shell->exposay.state_cur = EXPOSAY_LAYOUT_INACTIVE; |
| 6693 | shell->exposay.state_target = EXPOSAY_TARGET_CANCEL; |
| 6694 | |
Jonas Ådahl | e3cddce | 2012-06-13 00:01:22 +0200 | [diff] [blame] | 6695 | for (i = 0; i < shell->workspaces.num; i++) { |
| 6696 | pws = wl_array_add(&shell->workspaces.array, sizeof *pws); |
| 6697 | if (pws == NULL) |
| 6698 | return -1; |
| 6699 | |
| 6700 | *pws = workspace_create(); |
| 6701 | if (*pws == NULL) |
| 6702 | return -1; |
| 6703 | } |
| 6704 | activate_workspace(shell, 0); |
| 6705 | |
Manuel Bachmann | 50c87db | 2014-02-26 15:52:13 +0100 | [diff] [blame] | 6706 | weston_layer_init(&shell->minimized_layer, NULL); |
| 6707 | |
Jonas Ådahl | 8de6a1d | 2012-08-29 22:13:00 +0200 | [diff] [blame] | 6708 | wl_list_init(&shell->workspaces.anim_sticky_list); |
Jonas Ådahl | 62fcd04 | 2012-06-13 00:01:23 +0200 | [diff] [blame] | 6709 | wl_list_init(&shell->workspaces.animation.link); |
| 6710 | shell->workspaces.animation.frame = animate_workspace_change_frame; |
| 6711 | |
Kristian Høgsberg | 919cddb | 2013-07-08 19:03:57 -0400 | [diff] [blame] | 6712 | if (wl_global_create(ec->wl_display, &wl_shell_interface, 1, |
Kristian Høgsberg | 97d44aa | 2011-08-26 17:21:20 -0400 | [diff] [blame] | 6713 | shell, bind_shell) == NULL) |
Kristian Høgsberg | 4cca349 | 2011-01-18 07:53:49 -0500 | [diff] [blame] | 6714 | return -1; |
| 6715 | |
Rafael Antognolli | e2a3455 | 2013-12-03 15:35:45 -0200 | [diff] [blame] | 6716 | if (wl_global_create(ec->wl_display, &xdg_shell_interface, 1, |
| 6717 | shell, bind_xdg_shell) == NULL) |
| 6718 | return -1; |
| 6719 | |
Kristian Høgsberg | 919cddb | 2013-07-08 19:03:57 -0400 | [diff] [blame] | 6720 | if (wl_global_create(ec->wl_display, |
Jonny Lamb | 765760d | 2014-08-20 15:53:19 +0200 | [diff] [blame] | 6721 | &desktop_shell_interface, 3, |
Kristian Høgsberg | 919cddb | 2013-07-08 19:03:57 -0400 | [diff] [blame] | 6722 | shell, bind_desktop_shell) == NULL) |
Kristian Høgsberg | 7584062 | 2011-09-06 13:48:16 -0400 | [diff] [blame] | 6723 | return -1; |
| 6724 | |
Kristian Høgsberg | 919cddb | 2013-07-08 19:03:57 -0400 | [diff] [blame] | 6725 | if (wl_global_create(ec->wl_display, &screensaver_interface, 1, |
| 6726 | shell, bind_screensaver) == NULL) |
Pekka Paalanen | 6e16811 | 2011-11-24 11:34:05 +0200 | [diff] [blame] | 6727 | return -1; |
| 6728 | |
Kristian Høgsberg | 919cddb | 2013-07-08 19:03:57 -0400 | [diff] [blame] | 6729 | if (wl_global_create(ec->wl_display, &workspace_manager_interface, 1, |
| 6730 | shell, bind_workspace_manager) == NULL) |
Jonas Ådahl | e9d2250 | 2012-08-29 22:13:01 +0200 | [diff] [blame] | 6731 | return -1; |
| 6732 | |
Kristian Høgsberg | f03a616 | 2012-01-17 11:07:42 -0500 | [diff] [blame] | 6733 | shell->child.deathstamp = weston_compositor_get_time(); |
Tiago Vignatti | b7dbbd6 | 2012-09-25 17:57:01 +0300 | [diff] [blame] | 6734 | |
Jonny Lamb | 765760d | 2014-08-20 15:53:19 +0200 | [diff] [blame] | 6735 | shell->panel_position = DESKTOP_SHELL_PANEL_POSITION_TOP; |
| 6736 | |
Xiong Zhang | 6b48142 | 2013-10-23 13:58:32 +0800 | [diff] [blame] | 6737 | setup_output_destroy_handler(ec, shell); |
| 6738 | |
Tiago Vignatti | b7dbbd6 | 2012-09-25 17:57:01 +0300 | [diff] [blame] | 6739 | loop = wl_display_get_event_loop(ec->wl_display); |
| 6740 | wl_event_loop_add_idle(loop, launch_desktop_shell_process, shell); |
Pekka Paalanen | 6cd281a | 2011-11-03 14:11:32 +0200 | [diff] [blame] | 6741 | |
Ander Conselvan de Oliveira | 859e885 | 2013-02-21 18:35:21 +0200 | [diff] [blame] | 6742 | shell->screensaver.timer = |
| 6743 | wl_event_loop_add_timer(loop, screensaver_timeout, shell); |
| 6744 | |
Jason Ekstrand | 024177c | 2014-04-21 19:42:58 -0500 | [diff] [blame] | 6745 | wl_list_for_each(seat, &ec->seat_list, link) |
| 6746 | handle_seat_created(NULL, seat); |
| 6747 | shell->seat_create_listener.notify = handle_seat_created; |
| 6748 | wl_signal_add(&ec->seat_created_signal, &shell->seat_create_listener); |
Kristian Høgsberg | d56bd90 | 2012-06-05 09:58:51 -0400 | [diff] [blame] | 6749 | |
Giulio Camuffo | c6ab3d5 | 2013-12-11 23:45:12 +0100 | [diff] [blame] | 6750 | screenshooter_create(ec); |
| 6751 | |
Tiago Vignatti | 0b52d48 | 2012-04-20 18:54:25 +0300 | [diff] [blame] | 6752 | shell_add_bindings(ec, shell); |
Kristian Høgsberg | 0793756 | 2011-04-12 17:25:42 -0400 | [diff] [blame] | 6753 | |
Pekka Paalanen | 79346ab | 2013-05-22 18:03:09 +0300 | [diff] [blame] | 6754 | shell_fade_init(shell); |
Ander Conselvan de Oliveira | 19d10ef | 2013-02-21 18:35:20 +0200 | [diff] [blame] | 6755 | |
Pekka Paalanen | 2e62e4a | 2014-08-28 11:41:26 +0300 | [diff] [blame] | 6756 | clock_gettime(CLOCK_MONOTONIC, &shell->startup_time); |
| 6757 | |
Kristian Høgsberg | 4cca349 | 2011-01-18 07:53:49 -0500 | [diff] [blame] | 6758 | return 0; |
| 6759 | } |