Kristian Høgsberg | 4cca349 | 2011-01-18 07:53:49 -0500 | [diff] [blame] | 1 | /* |
Kristian Høgsberg | 0704539 | 2012-02-19 18:52:44 -0500 | [diff] [blame] | 2 | * Copyright © 2010-2012 Intel Corporation |
Pekka Paalanen | d581a8f | 2012-01-27 16:25:16 +0200 | [diff] [blame] | 3 | * Copyright © 2011-2012 Collabora, Ltd. |
Daniel Stone | df8133b | 2013-11-19 11:37:14 +0100 | [diff] [blame] | 4 | * Copyright © 2013 Raspberry Pi Foundation |
Kristian Høgsberg | 4cca349 | 2011-01-18 07:53:49 -0500 | [diff] [blame] | 5 | * |
| 6 | * Permission to use, copy, modify, distribute, and sell this software and |
| 7 | * its documentation for any purpose is hereby granted without fee, provided |
| 8 | * that the above copyright notice appear in all copies and that both that |
| 9 | * copyright notice and this permission notice appear in supporting |
| 10 | * documentation, and that the name of the copyright holders not be used in |
| 11 | * advertising or publicity pertaining to distribution of the software |
| 12 | * without specific, written prior permission. The copyright holders make |
| 13 | * no representations about the suitability of this software for any |
| 14 | * purpose. It is provided "as is" without express or implied warranty. |
| 15 | * |
| 16 | * THE COPYRIGHT HOLDERS DISCLAIM ALL WARRANTIES WITH REGARD TO THIS |
| 17 | * SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND |
| 18 | * FITNESS, IN NO EVENT SHALL THE COPYRIGHT HOLDERS BE LIABLE FOR ANY |
| 19 | * SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER |
| 20 | * RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF |
| 21 | * CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN |
| 22 | * CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. |
| 23 | */ |
| 24 | |
Daniel Stone | c228e23 | 2013-05-22 18:03:19 +0300 | [diff] [blame] | 25 | #include "config.h" |
| 26 | |
Kristian Høgsberg | 4cca349 | 2011-01-18 07:53:49 -0500 | [diff] [blame] | 27 | #include <stdlib.h> |
Kristian Høgsberg | 7584062 | 2011-09-06 13:48:16 -0400 | [diff] [blame] | 28 | #include <stdio.h> |
Kristian Høgsberg | 4cca349 | 2011-01-18 07:53:49 -0500 | [diff] [blame] | 29 | #include <string.h> |
| 30 | #include <unistd.h> |
Kristian Høgsberg | 0793756 | 2011-04-12 17:25:42 -0400 | [diff] [blame] | 31 | #include <linux/input.h> |
Pekka Paalanen | f0fc70d | 2011-11-15 13:34:54 +0200 | [diff] [blame] | 32 | #include <assert.h> |
Pekka Paalanen | 18027e5 | 2011-12-02 16:31:49 +0200 | [diff] [blame] | 33 | #include <signal.h> |
Pekka Paalanen | 460099f | 2012-01-20 16:48:25 +0200 | [diff] [blame] | 34 | #include <math.h> |
Kristian Høgsberg | 92a57db | 2012-05-26 13:41:06 -0400 | [diff] [blame] | 35 | #include <sys/types.h> |
Kristian Høgsberg | 4cca349 | 2011-01-18 07:53:49 -0500 | [diff] [blame] | 36 | |
Kristian Høgsberg | 1ef2313 | 2013-12-04 00:20:01 -0800 | [diff] [blame] | 37 | #include "shell.h" |
Kristian Høgsberg | 7584062 | 2011-09-06 13:48:16 -0400 | [diff] [blame] | 38 | #include "desktop-shell-server-protocol.h" |
Jonas Ådahl | e9d2250 | 2012-08-29 22:13:01 +0200 | [diff] [blame] | 39 | #include "workspaces-server-protocol.h" |
Pekka Paalanen | e955f1e | 2011-12-07 11:49:52 +0200 | [diff] [blame] | 40 | #include "../shared/config-parser.h" |
Rafael Antognolli | e2a3455 | 2013-12-03 15:35:45 -0200 | [diff] [blame] | 41 | #include "xdg-shell-server-protocol.h" |
Kristian Høgsberg | 4cca349 | 2011-01-18 07:53:49 -0500 | [diff] [blame] | 42 | |
Jonas Ådahl | e3cddce | 2012-06-13 00:01:22 +0200 | [diff] [blame] | 43 | #define DEFAULT_NUM_WORKSPACES 1 |
Jonas Ådahl | 62fcd04 | 2012-06-13 00:01:23 +0200 | [diff] [blame] | 44 | #define DEFAULT_WORKSPACE_CHANGE_ANIMATION_LENGTH 200 |
Jonas Ådahl | e3cddce | 2012-06-13 00:01:22 +0200 | [diff] [blame] | 45 | |
Giulio Camuffo | 1aaf3e4 | 2013-12-09 22:47:58 +0100 | [diff] [blame] | 46 | #ifndef static_assert |
| 47 | #define static_assert(cond, msg) |
| 48 | #endif |
| 49 | |
Jonas Ådahl | 0476974 | 2012-06-13 00:01:24 +0200 | [diff] [blame] | 50 | struct focus_state { |
| 51 | struct weston_seat *seat; |
Kristian Høgsberg | 2f5faff | 2012-07-31 16:36:34 -0400 | [diff] [blame] | 52 | struct workspace *ws; |
Jonas Ådahl | 0476974 | 2012-06-13 00:01:24 +0200 | [diff] [blame] | 53 | struct weston_surface *keyboard_focus; |
| 54 | struct wl_list link; |
| 55 | struct wl_listener seat_destroy_listener; |
| 56 | struct wl_listener surface_destroy_listener; |
| 57 | }; |
| 58 | |
Kristian Høgsberg | d2abb83 | 2011-11-23 10:52:40 -0500 | [diff] [blame] | 59 | enum shell_surface_type { |
Pekka Paalanen | 9826223 | 2011-12-01 10:42:22 +0200 | [diff] [blame] | 60 | SHELL_SURFACE_NONE, |
Kristian Høgsberg | d2abb83 | 2011-11-23 10:52:40 -0500 | [diff] [blame] | 61 | SHELL_SURFACE_TOPLEVEL, |
Tiago Vignatti | fb2adba | 2013-06-12 15:43:21 -0300 | [diff] [blame] | 62 | SHELL_SURFACE_POPUP, |
| 63 | SHELL_SURFACE_XWAYLAND |
Pekka Paalanen | 57da4a8 | 2011-11-23 16:42:16 +0200 | [diff] [blame] | 64 | }; |
| 65 | |
Jason Ekstrand | 9e9512f | 2014-04-16 21:12:10 -0500 | [diff] [blame] | 66 | struct shell_client; |
| 67 | |
Philip Withnall | 648a4dd | 2013-11-25 18:01:44 +0000 | [diff] [blame] | 68 | /* |
| 69 | * Surface stacking and ordering. |
| 70 | * |
| 71 | * This is handled using several linked lists of surfaces, organised into |
| 72 | * ‘layers’. The layers are ordered, and each of the surfaces in one layer are |
| 73 | * above all of the surfaces in the layer below. The set of layers is static and |
| 74 | * in the following order (top-most first): |
| 75 | * • Lock layer (only ever displayed on its own) |
| 76 | * • Cursor layer |
Manuel Bachmann | 805d2f5 | 2014-03-05 12:21:34 +0100 | [diff] [blame] | 77 | * • Input panel layer |
Philip Withnall | 648a4dd | 2013-11-25 18:01:44 +0000 | [diff] [blame] | 78 | * • Fullscreen layer |
| 79 | * • Panel layer |
Philip Withnall | 648a4dd | 2013-11-25 18:01:44 +0000 | [diff] [blame] | 80 | * • Workspace layers |
| 81 | * • Background layer |
| 82 | * |
| 83 | * The list of layers may be manipulated to remove whole layers of surfaces from |
| 84 | * display. For example, when locking the screen, all layers except the lock |
| 85 | * layer are removed. |
| 86 | * |
| 87 | * A surface’s layer is modified on configuring the surface, in |
| 88 | * set_surface_type() (which is only called when the surface’s type change is |
| 89 | * _committed_). If a surface’s type changes (e.g. when making a window |
| 90 | * fullscreen) its layer changes too. |
| 91 | * |
| 92 | * In order to allow popup and transient surfaces to be correctly stacked above |
| 93 | * their parent surfaces, each surface tracks both its parent surface, and a |
| 94 | * linked list of its children. When a surface’s layer is updated, so are the |
| 95 | * layers of its children. Note that child surfaces are *not* the same as |
| 96 | * subsurfaces — child/parent surfaces are purely for maintaining stacking |
| 97 | * order. |
| 98 | * |
| 99 | * The children_link list of siblings of a surface (i.e. those surfaces which |
| 100 | * have the same parent) only contains weston_surfaces which have a |
| 101 | * shell_surface. Stacking is not implemented for non-shell_surface |
| 102 | * weston_surfaces. This means that the following implication does *not* hold: |
| 103 | * (shsurf->parent != NULL) ⇒ !wl_list_is_empty(shsurf->children_link) |
| 104 | */ |
| 105 | |
Pekka Paalanen | 56cdea9 | 2011-11-23 16:14:12 +0200 | [diff] [blame] | 106 | struct shell_surface { |
Jason Ekstrand | 651f00e | 2013-06-14 10:07:54 -0500 | [diff] [blame] | 107 | struct wl_resource *resource; |
| 108 | struct wl_signal destroy_signal; |
Jason Ekstrand | 9e9512f | 2014-04-16 21:12:10 -0500 | [diff] [blame] | 109 | struct shell_client *owner; |
Pekka Paalanen | 9d1613e | 2011-11-25 12:09:16 +0200 | [diff] [blame] | 110 | |
Kristian Høgsberg | 8334bc1 | 2012-01-03 10:29:47 -0500 | [diff] [blame] | 111 | struct weston_surface *surface; |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 112 | struct weston_view *view; |
Jason Ekstrand | 918f2dd | 2013-12-02 21:01:53 -0600 | [diff] [blame] | 113 | int32_t last_width, last_height; |
Pekka Paalanen | 9d1613e | 2011-11-25 12:09:16 +0200 | [diff] [blame] | 114 | struct wl_listener surface_destroy_listener; |
Kristian Høgsberg | 160fe75 | 2014-03-11 10:19:10 -0700 | [diff] [blame] | 115 | struct wl_listener resource_destroy_listener; |
| 116 | |
Kristian Høgsberg | 8150b19 | 2012-06-27 10:22:58 -0400 | [diff] [blame] | 117 | struct weston_surface *parent; |
Philip Withnall | 648a4dd | 2013-11-25 18:01:44 +0000 | [diff] [blame] | 118 | struct wl_list children_list; /* child surfaces of this one */ |
| 119 | struct wl_list children_link; /* sibling surfaces of this one */ |
Tiago Vignatti | be14326 | 2012-04-16 17:31:41 +0300 | [diff] [blame] | 120 | struct desktop_shell *shell; |
Pekka Paalanen | 57da4a8 | 2011-11-23 16:42:16 +0200 | [diff] [blame] | 121 | |
Kristian Høgsberg | c8f8dd8 | 2013-12-05 23:20:33 -0800 | [diff] [blame] | 122 | enum shell_surface_type type; |
Kristian Høgsberg | e7afd91 | 2012-05-02 09:47:44 -0400 | [diff] [blame] | 123 | char *title, *class; |
Kristian Høgsberg | d2abb83 | 2011-11-23 10:52:40 -0500 | [diff] [blame] | 124 | int32_t saved_x, saved_y; |
Rafael Antognolli | 3c4e3f7 | 2013-12-03 15:35:46 -0200 | [diff] [blame] | 125 | int32_t saved_width, saved_height; |
Alex Wu | 4539b08 | 2012-03-01 12:57:46 +0800 | [diff] [blame] | 126 | bool saved_position_valid; |
Rafael Antognolli | 3c4e3f7 | 2013-12-03 15:35:46 -0200 | [diff] [blame] | 127 | bool saved_size_valid; |
Alex Wu | 7bcb8bd | 2012-04-27 09:07:24 +0800 | [diff] [blame] | 128 | bool saved_rotation_valid; |
Kristian Høgsberg | c85f1d4 | 2013-10-24 16:52:00 -0700 | [diff] [blame] | 129 | int unresponsive, grabbed; |
Kristian Høgsberg | 44cd196 | 2014-02-05 21:36:04 -0800 | [diff] [blame] | 130 | uint32_t resize_edges; |
Benjamin Franzke | d0f79ab | 2011-11-22 12:43:52 +0100 | [diff] [blame] | 131 | |
Kristian Høgsberg | b3cca0a | 2012-01-04 22:19:14 -0500 | [diff] [blame] | 132 | struct { |
Pekka Paalanen | 460099f | 2012-01-20 16:48:25 +0200 | [diff] [blame] | 133 | struct weston_transform transform; |
Kristian Høgsberg | 765e27b | 2012-01-27 13:36:13 -0500 | [diff] [blame] | 134 | struct weston_matrix rotation; |
Pekka Paalanen | 460099f | 2012-01-20 16:48:25 +0200 | [diff] [blame] | 135 | } rotation; |
| 136 | |
| 137 | struct { |
Giulio Camuffo | 5085a75 | 2013-03-25 21:42:45 +0100 | [diff] [blame] | 138 | struct wl_list grab_link; |
Kristian Høgsberg | b3cca0a | 2012-01-04 22:19:14 -0500 | [diff] [blame] | 139 | int32_t x, y; |
Giulio Camuffo | 5085a75 | 2013-03-25 21:42:45 +0100 | [diff] [blame] | 140 | struct shell_seat *shseat; |
Kristian Høgsberg | 3730f36 | 2012-04-13 12:40:07 -0400 | [diff] [blame] | 141 | uint32_t serial; |
Kristian Høgsberg | b3cca0a | 2012-01-04 22:19:14 -0500 | [diff] [blame] | 142 | } popup; |
| 143 | |
Alex Wu | 4539b08 | 2012-03-01 12:57:46 +0800 | [diff] [blame] | 144 | struct { |
Tiago Vignatti | 52e598c | 2012-05-07 15:23:08 +0300 | [diff] [blame] | 145 | int32_t x, y; |
Tiago Vignatti | 491bac1 | 2012-05-18 16:37:43 -0400 | [diff] [blame] | 146 | uint32_t flags; |
Tiago Vignatti | 52e598c | 2012-05-07 15:23:08 +0300 | [diff] [blame] | 147 | } transient; |
| 148 | |
| 149 | struct { |
Alex Wu | 4539b08 | 2012-03-01 12:57:46 +0800 | [diff] [blame] | 150 | enum wl_shell_surface_fullscreen_method type; |
| 151 | struct weston_transform transform; /* matrix from x, y */ |
| 152 | uint32_t framerate; |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 153 | struct weston_view *black_view; |
Alex Wu | 4539b08 | 2012-03-01 12:57:46 +0800 | [diff] [blame] | 154 | } fullscreen; |
| 155 | |
Jonas Ådahl | 62fcd04 | 2012-06-13 00:01:23 +0200 | [diff] [blame] | 156 | struct weston_transform workspace_transform; |
| 157 | |
Kristian Høgsberg | 1cbf326 | 2012-02-17 23:49:07 -0500 | [diff] [blame] | 158 | struct weston_output *fullscreen_output; |
Kristian Høgsberg | 8334bc1 | 2012-01-03 10:29:47 -0500 | [diff] [blame] | 159 | struct weston_output *output; |
Benjamin Franzke | d0f79ab | 2011-11-22 12:43:52 +0100 | [diff] [blame] | 160 | struct wl_list link; |
Kristian Høgsberg | a61ca06 | 2012-05-22 16:05:52 -0400 | [diff] [blame] | 161 | |
| 162 | const struct weston_shell_client *client; |
Rafael Antognolli | 03b1659 | 2013-12-03 15:35:42 -0200 | [diff] [blame] | 163 | |
Jasper St. Pierre | 6458ec3 | 2014-04-11 16:00:31 -0700 | [diff] [blame] | 164 | struct surface_state { |
Rafael Antognolli | 03b1659 | 2013-12-03 15:35:42 -0200 | [diff] [blame] | 165 | bool maximized; |
| 166 | bool fullscreen; |
Rafael Antognolli | ed207b4 | 2013-12-03 15:35:43 -0200 | [diff] [blame] | 167 | bool relative; |
Emilio Pozuelo Monfort | 9e7c759 | 2014-01-30 14:01:10 +0100 | [diff] [blame] | 168 | bool lowered; |
Jasper St. Pierre | 8c6aa45 | 2014-02-08 18:29:49 -0500 | [diff] [blame] | 169 | } state, next_state, requested_state; /* surface states */ |
Rafael Antognolli | 03b1659 | 2013-12-03 15:35:42 -0200 | [diff] [blame] | 170 | bool state_changed; |
Jasper St. Pierre | 8c6aa45 | 2014-02-08 18:29:49 -0500 | [diff] [blame] | 171 | bool state_requested; |
Jasper St. Pierre | faf27a9 | 2013-12-09 17:36:28 -0500 | [diff] [blame] | 172 | |
Kristian Høgsberg | ae356ae | 2014-04-29 16:03:54 -0700 | [diff] [blame] | 173 | struct { |
Jasper St. Pierre | ccf48fb | 2014-05-02 10:21:38 -0400 | [diff] [blame] | 174 | int32_t x, y, width, height; |
| 175 | } geometry, next_geometry; |
| 176 | bool has_set_geometry, has_next_geometry; |
Kristian Høgsberg | ae356ae | 2014-04-29 16:03:54 -0700 | [diff] [blame] | 177 | |
Jasper St. Pierre | faf27a9 | 2013-12-09 17:36:28 -0500 | [diff] [blame] | 178 | int focus_count; |
Pekka Paalanen | 56cdea9 | 2011-11-23 16:14:12 +0200 | [diff] [blame] | 179 | }; |
| 180 | |
Ander Conselvan de Oliveira | fe0444a | 2012-04-04 17:48:05 +0300 | [diff] [blame] | 181 | struct shell_grab { |
Kristian Høgsberg | 02bbabb | 2013-05-06 22:15:05 -0400 | [diff] [blame] | 182 | struct weston_pointer_grab grab; |
Ander Conselvan de Oliveira | fe0444a | 2012-04-04 17:48:05 +0300 | [diff] [blame] | 183 | struct shell_surface *shsurf; |
| 184 | struct wl_listener shsurf_destroy_listener; |
| 185 | }; |
| 186 | |
Rusty Lynch | 1084da5 | 2013-08-15 09:10:08 -0700 | [diff] [blame] | 187 | struct shell_touch_grab { |
| 188 | struct weston_touch_grab grab; |
| 189 | struct shell_surface *shsurf; |
| 190 | struct wl_listener shsurf_destroy_listener; |
| 191 | struct weston_touch *touch; |
| 192 | }; |
| 193 | |
Ander Conselvan de Oliveira | fe0444a | 2012-04-04 17:48:05 +0300 | [diff] [blame] | 194 | struct weston_move_grab { |
| 195 | struct shell_grab base; |
Daniel Stone | 103db7f | 2012-05-08 17:17:55 +0100 | [diff] [blame] | 196 | wl_fixed_t dx, dy; |
Kristian Høgsberg | ae356ae | 2014-04-29 16:03:54 -0700 | [diff] [blame] | 197 | int client_initiated; |
Kristian Høgsberg | 4cca349 | 2011-01-18 07:53:49 -0500 | [diff] [blame] | 198 | }; |
| 199 | |
Rusty Lynch | 1084da5 | 2013-08-15 09:10:08 -0700 | [diff] [blame] | 200 | struct weston_touch_move_grab { |
| 201 | struct shell_touch_grab base; |
Kristian Høgsberg | 8e80a31 | 2014-01-17 15:18:10 -0800 | [diff] [blame] | 202 | int active; |
Rusty Lynch | 1084da5 | 2013-08-15 09:10:08 -0700 | [diff] [blame] | 203 | wl_fixed_t dx, dy; |
| 204 | }; |
| 205 | |
Pekka Paalanen | 460099f | 2012-01-20 16:48:25 +0200 | [diff] [blame] | 206 | struct rotate_grab { |
Ander Conselvan de Oliveira | fe0444a | 2012-04-04 17:48:05 +0300 | [diff] [blame] | 207 | struct shell_grab base; |
Kristian Høgsberg | 765e27b | 2012-01-27 13:36:13 -0500 | [diff] [blame] | 208 | struct weston_matrix rotation; |
Pekka Paalanen | 460099f | 2012-01-20 16:48:25 +0200 | [diff] [blame] | 209 | struct { |
John Kåre Alsaker | 490d02a | 2012-09-30 02:57:21 +0200 | [diff] [blame] | 210 | float x; |
| 211 | float y; |
Pekka Paalanen | 460099f | 2012-01-20 16:48:25 +0200 | [diff] [blame] | 212 | } center; |
| 213 | }; |
| 214 | |
Giulio Camuffo | 5085a75 | 2013-03-25 21:42:45 +0100 | [diff] [blame] | 215 | struct shell_seat { |
| 216 | struct weston_seat *seat; |
| 217 | struct wl_listener seat_destroy_listener; |
Jasper St. Pierre | faf27a9 | 2013-12-09 17:36:28 -0500 | [diff] [blame] | 218 | struct weston_surface *focused_surface; |
Giulio Camuffo | 5085a75 | 2013-03-25 21:42:45 +0100 | [diff] [blame] | 219 | |
Jason Ekstrand | 024177c | 2014-04-21 19:42:58 -0500 | [diff] [blame] | 220 | struct wl_listener caps_changed_listener; |
| 221 | struct wl_listener pointer_focus_listener; |
| 222 | struct wl_listener keyboard_focus_listener; |
| 223 | |
Giulio Camuffo | 5085a75 | 2013-03-25 21:42:45 +0100 | [diff] [blame] | 224 | struct { |
Kristian Høgsberg | 02bbabb | 2013-05-06 22:15:05 -0400 | [diff] [blame] | 225 | struct weston_pointer_grab grab; |
Giulio Camuffo | 5085a75 | 2013-03-25 21:42:45 +0100 | [diff] [blame] | 226 | struct wl_list surfaces_list; |
| 227 | struct wl_client *client; |
| 228 | int32_t initial_up; |
| 229 | } popup_grab; |
| 230 | }; |
| 231 | |
Kristian Høgsberg | 2bff94e | 2014-02-11 12:22:51 -0800 | [diff] [blame] | 232 | struct shell_client { |
| 233 | struct wl_resource *resource; |
| 234 | struct wl_client *client; |
| 235 | struct desktop_shell *shell; |
| 236 | struct wl_listener destroy_listener; |
| 237 | struct wl_event_source *ping_timer; |
| 238 | uint32_t ping_serial; |
| 239 | int unresponsive; |
| 240 | }; |
| 241 | |
Alex Wu | bd3354b | 2012-04-17 17:20:49 +0800 | [diff] [blame] | 242 | static struct desktop_shell * |
| 243 | shell_surface_get_shell(struct shell_surface *shsurf); |
| 244 | |
Kristian Høgsberg | 0c36903 | 2013-02-14 21:31:44 -0500 | [diff] [blame] | 245 | static void |
Kristian Høgsberg | e314875 | 2013-05-06 23:19:49 -0400 | [diff] [blame] | 246 | surface_rotate(struct shell_surface *surface, struct weston_seat *seat); |
Kristian Høgsberg | 0c36903 | 2013-02-14 21:31:44 -0500 | [diff] [blame] | 247 | |
Pekka Paalanen | 79346ab | 2013-05-22 18:03:09 +0300 | [diff] [blame] | 248 | static void |
| 249 | shell_fade_startup(struct desktop_shell *shell); |
| 250 | |
Philip Withnall | becb77e | 2013-11-25 18:01:30 +0000 | [diff] [blame] | 251 | static struct shell_seat * |
| 252 | get_shell_seat(struct weston_seat *seat); |
| 253 | |
Jonny Lamb | d73c694 | 2014-08-20 15:53:20 +0200 | [diff] [blame] | 254 | static void |
| 255 | get_output_panel_size(struct desktop_shell *shell, |
| 256 | struct weston_output *output, |
| 257 | int *width, int *height); |
Kristian Høgsberg | ae356ae | 2014-04-29 16:03:54 -0700 | [diff] [blame] | 258 | |
Philip Withnall | 648a4dd | 2013-11-25 18:01:44 +0000 | [diff] [blame] | 259 | static void |
| 260 | shell_surface_update_child_surface_layers(struct shell_surface *shsurf); |
| 261 | |
Alex Wu | bd3354b | 2012-04-17 17:20:49 +0800 | [diff] [blame] | 262 | static bool |
Rafael Antognolli | e2a3455 | 2013-12-03 15:35:45 -0200 | [diff] [blame] | 263 | shell_surface_is_wl_shell_surface(struct shell_surface *shsurf); |
| 264 | |
| 265 | static bool |
| 266 | shell_surface_is_xdg_surface(struct shell_surface *shsurf); |
| 267 | |
| 268 | static bool |
| 269 | shell_surface_is_xdg_popup(struct shell_surface *shsurf); |
| 270 | |
| 271 | static void |
| 272 | shell_surface_set_parent(struct shell_surface *shsurf, |
| 273 | struct weston_surface *parent); |
| 274 | |
| 275 | static bool |
Alex Wu | bd3354b | 2012-04-17 17:20:49 +0800 | [diff] [blame] | 276 | shell_surface_is_top_fullscreen(struct shell_surface *shsurf) |
| 277 | { |
| 278 | struct desktop_shell *shell; |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 279 | struct weston_view *top_fs_ev; |
Alex Wu | bd3354b | 2012-04-17 17:20:49 +0800 | [diff] [blame] | 280 | |
| 281 | shell = shell_surface_get_shell(shsurf); |
Quentin Glidic | c0d79ce | 2013-01-29 14:16:13 +0100 | [diff] [blame] | 282 | |
Giulio Camuffo | 412e6a5 | 2014-07-09 22:12:56 +0300 | [diff] [blame] | 283 | if (wl_list_empty(&shell->fullscreen_layer.view_list.link)) |
Alex Wu | bd3354b | 2012-04-17 17:20:49 +0800 | [diff] [blame] | 284 | return false; |
| 285 | |
Giulio Camuffo | 412e6a5 | 2014-07-09 22:12:56 +0300 | [diff] [blame] | 286 | top_fs_ev = container_of(shell->fullscreen_layer.view_list.link.next, |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 287 | struct weston_view, |
Giulio Camuffo | 412e6a5 | 2014-07-09 22:12:56 +0300 | [diff] [blame] | 288 | layer_link.link); |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 289 | return (shsurf == get_shell_surface(top_fs_ev->surface)); |
Alex Wu | bd3354b | 2012-04-17 17:20:49 +0800 | [diff] [blame] | 290 | } |
| 291 | |
Kristian Høgsberg | 6af8eb9 | 2012-01-25 16:57:11 -0500 | [diff] [blame] | 292 | static void |
Kristian Høgsberg | 27e3052 | 2012-04-11 23:18:23 -0400 | [diff] [blame] | 293 | destroy_shell_grab_shsurf(struct wl_listener *listener, void *data) |
Ander Conselvan de Oliveira | fe0444a | 2012-04-04 17:48:05 +0300 | [diff] [blame] | 294 | { |
| 295 | struct shell_grab *grab; |
| 296 | |
| 297 | grab = container_of(listener, struct shell_grab, |
| 298 | shsurf_destroy_listener); |
| 299 | |
| 300 | grab->shsurf = NULL; |
| 301 | } |
| 302 | |
Kristian Høgsberg | 1ef2313 | 2013-12-04 00:20:01 -0800 | [diff] [blame] | 303 | struct weston_view * |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 304 | get_default_view(struct weston_surface *surface) |
| 305 | { |
| 306 | struct shell_surface *shsurf; |
| 307 | struct weston_view *view; |
| 308 | |
| 309 | if (!surface || wl_list_empty(&surface->views)) |
| 310 | return NULL; |
| 311 | |
| 312 | shsurf = get_shell_surface(surface); |
| 313 | if (shsurf) |
| 314 | return shsurf->view; |
| 315 | |
| 316 | wl_list_for_each(view, &surface->views, surface_link) |
| 317 | if (weston_view_is_mapped(view)) |
| 318 | return view; |
| 319 | |
| 320 | return container_of(surface->views.next, struct weston_view, surface_link); |
| 321 | } |
| 322 | |
Ander Conselvan de Oliveira | fe0444a | 2012-04-04 17:48:05 +0300 | [diff] [blame] | 323 | static void |
Kristian Høgsberg | 02bbabb | 2013-05-06 22:15:05 -0400 | [diff] [blame] | 324 | popup_grab_end(struct weston_pointer *pointer); |
Kristian Høgsberg | 57e0907 | 2012-10-30 14:07:27 -0400 | [diff] [blame] | 325 | |
| 326 | static void |
Ander Conselvan de Oliveira | b9d2a0f | 2012-06-28 18:08:05 +0300 | [diff] [blame] | 327 | shell_grab_start(struct shell_grab *grab, |
Kristian Høgsberg | 02bbabb | 2013-05-06 22:15:05 -0400 | [diff] [blame] | 328 | const struct weston_pointer_grab_interface *interface, |
Ander Conselvan de Oliveira | b9d2a0f | 2012-06-28 18:08:05 +0300 | [diff] [blame] | 329 | struct shell_surface *shsurf, |
Kristian Høgsberg | 02bbabb | 2013-05-06 22:15:05 -0400 | [diff] [blame] | 330 | struct weston_pointer *pointer, |
Ander Conselvan de Oliveira | b9d2a0f | 2012-06-28 18:08:05 +0300 | [diff] [blame] | 331 | enum desktop_shell_cursor cursor) |
Ander Conselvan de Oliveira | fe0444a | 2012-04-04 17:48:05 +0300 | [diff] [blame] | 332 | { |
Ander Conselvan de Oliveira | b9d2a0f | 2012-06-28 18:08:05 +0300 | [diff] [blame] | 333 | struct desktop_shell *shell = shsurf->shell; |
| 334 | |
Kristian Høgsberg | 57e0907 | 2012-10-30 14:07:27 -0400 | [diff] [blame] | 335 | popup_grab_end(pointer); |
| 336 | |
Ander Conselvan de Oliveira | fe0444a | 2012-04-04 17:48:05 +0300 | [diff] [blame] | 337 | grab->grab.interface = interface; |
| 338 | grab->shsurf = shsurf; |
Kristian Høgsberg | 27e3052 | 2012-04-11 23:18:23 -0400 | [diff] [blame] | 339 | grab->shsurf_destroy_listener.notify = destroy_shell_grab_shsurf; |
Jason Ekstrand | 651f00e | 2013-06-14 10:07:54 -0500 | [diff] [blame] | 340 | wl_signal_add(&shsurf->destroy_signal, |
Kristian Høgsberg | 27e3052 | 2012-04-11 23:18:23 -0400 | [diff] [blame] | 341 | &grab->shsurf_destroy_listener); |
Ander Conselvan de Oliveira | fe0444a | 2012-04-04 17:48:05 +0300 | [diff] [blame] | 342 | |
Kristian Høgsberg | c85f1d4 | 2013-10-24 16:52:00 -0700 | [diff] [blame] | 343 | shsurf->grabbed = 1; |
Kristian Høgsberg | 02bbabb | 2013-05-06 22:15:05 -0400 | [diff] [blame] | 344 | weston_pointer_start_grab(pointer, &grab->grab); |
Kristian Høgsberg | c9974a0 | 2013-07-03 19:24:57 -0400 | [diff] [blame] | 345 | if (shell->child.desktop_shell) { |
| 346 | desktop_shell_send_grab_cursor(shell->child.desktop_shell, |
| 347 | cursor); |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 348 | weston_pointer_set_focus(pointer, |
| 349 | get_default_view(shell->grab_surface), |
Kristian Høgsberg | c9974a0 | 2013-07-03 19:24:57 -0400 | [diff] [blame] | 350 | wl_fixed_from_int(0), |
| 351 | wl_fixed_from_int(0)); |
| 352 | } |
Ander Conselvan de Oliveira | fe0444a | 2012-04-04 17:48:05 +0300 | [diff] [blame] | 353 | } |
| 354 | |
Jonny Lamb | d73c694 | 2014-08-20 15:53:20 +0200 | [diff] [blame] | 355 | static void |
| 356 | get_output_panel_size(struct desktop_shell *shell, |
| 357 | struct weston_output *output, |
| 358 | int *width, |
| 359 | int *height) |
Jasper St. Pierre | 6458ec3 | 2014-04-11 16:00:31 -0700 | [diff] [blame] | 360 | { |
| 361 | struct weston_view *view; |
Jonny Lamb | d73c694 | 2014-08-20 15:53:20 +0200 | [diff] [blame] | 362 | |
| 363 | *width = 0; |
| 364 | *height = 0; |
Jasper St. Pierre | 6458ec3 | 2014-04-11 16:00:31 -0700 | [diff] [blame] | 365 | |
| 366 | if (!output) |
Jonny Lamb | d73c694 | 2014-08-20 15:53:20 +0200 | [diff] [blame] | 367 | return; |
Jasper St. Pierre | 6458ec3 | 2014-04-11 16:00:31 -0700 | [diff] [blame] | 368 | |
Giulio Camuffo | 412e6a5 | 2014-07-09 22:12:56 +0300 | [diff] [blame] | 369 | wl_list_for_each(view, &shell->panel_layer.view_list.link, layer_link.link) { |
Jonny Lamb | d73c694 | 2014-08-20 15:53:20 +0200 | [diff] [blame] | 370 | float x, y; |
| 371 | |
| 372 | if (view->surface->output != output) |
| 373 | continue; |
| 374 | |
| 375 | switch (shell->panel_position) { |
| 376 | case DESKTOP_SHELL_PANEL_POSITION_TOP: |
| 377 | case DESKTOP_SHELL_PANEL_POSITION_BOTTOM: |
| 378 | |
| 379 | weston_view_to_global_float(view, |
| 380 | view->surface->width, 0, |
| 381 | &x, &y); |
| 382 | |
| 383 | *width = (int) x; |
| 384 | *height = view->surface->height + (int) y; |
| 385 | return; |
| 386 | |
| 387 | case DESKTOP_SHELL_PANEL_POSITION_LEFT: |
| 388 | case DESKTOP_SHELL_PANEL_POSITION_RIGHT: |
| 389 | weston_view_to_global_float(view, |
| 390 | 0, view->surface->height, |
| 391 | &x, &y); |
| 392 | |
| 393 | *width = view->surface->width + (int) x; |
| 394 | *height = (int) y; |
| 395 | return; |
| 396 | |
| 397 | default: |
| 398 | /* we've already set width and height to |
| 399 | * fallback values. */ |
Jasper St. Pierre | 6458ec3 | 2014-04-11 16:00:31 -0700 | [diff] [blame] | 400 | break; |
| 401 | } |
| 402 | } |
| 403 | |
Jonny Lamb | d73c694 | 2014-08-20 15:53:20 +0200 | [diff] [blame] | 404 | /* the correct view wasn't found */ |
| 405 | } |
| 406 | |
| 407 | static void |
| 408 | get_output_work_area(struct desktop_shell *shell, |
| 409 | struct weston_output *output, |
| 410 | pixman_rectangle32_t *area) |
| 411 | { |
| 412 | int32_t panel_width = 0, panel_height = 0; |
| 413 | |
| 414 | area->x = 0; |
| 415 | area->y = 0; |
| 416 | |
| 417 | get_output_panel_size(shell, output, &panel_width, &panel_height); |
| 418 | |
| 419 | switch (shell->panel_position) { |
| 420 | case DESKTOP_SHELL_PANEL_POSITION_TOP: |
| 421 | default: |
| 422 | area->y = panel_height; |
| 423 | case DESKTOP_SHELL_PANEL_POSITION_BOTTOM: |
| 424 | area->width = output->width; |
| 425 | area->height = output->height - panel_height; |
| 426 | break; |
| 427 | case DESKTOP_SHELL_PANEL_POSITION_LEFT: |
| 428 | area->x = panel_width; |
| 429 | case DESKTOP_SHELL_PANEL_POSITION_RIGHT: |
| 430 | area->width = output->width - panel_width; |
| 431 | area->height = output->height; |
| 432 | break; |
| 433 | } |
Jasper St. Pierre | 6458ec3 | 2014-04-11 16:00:31 -0700 | [diff] [blame] | 434 | } |
| 435 | |
| 436 | static void |
| 437 | send_configure_for_surface(struct shell_surface *shsurf) |
| 438 | { |
| 439 | int32_t width, height; |
| 440 | struct surface_state *state; |
| 441 | |
| 442 | if (shsurf->state_requested) |
| 443 | state = &shsurf->requested_state; |
| 444 | else if (shsurf->state_changed) |
| 445 | state = &shsurf->next_state; |
| 446 | else |
| 447 | state = &shsurf->state; |
| 448 | |
| 449 | if (state->fullscreen) { |
| 450 | width = shsurf->output->width; |
| 451 | height = shsurf->output->height; |
| 452 | } else if (state->maximized) { |
| 453 | struct desktop_shell *shell; |
Jonny Lamb | d73c694 | 2014-08-20 15:53:20 +0200 | [diff] [blame] | 454 | pixman_rectangle32_t area; |
Jasper St. Pierre | 6458ec3 | 2014-04-11 16:00:31 -0700 | [diff] [blame] | 455 | |
| 456 | shell = shell_surface_get_shell(shsurf); |
Jonny Lamb | d73c694 | 2014-08-20 15:53:20 +0200 | [diff] [blame] | 457 | get_output_work_area(shell, shsurf->output, &area); |
Jasper St. Pierre | 6458ec3 | 2014-04-11 16:00:31 -0700 | [diff] [blame] | 458 | |
Jonny Lamb | d73c694 | 2014-08-20 15:53:20 +0200 | [diff] [blame] | 459 | width = area.width; |
| 460 | height = area.height; |
Jasper St. Pierre | 6458ec3 | 2014-04-11 16:00:31 -0700 | [diff] [blame] | 461 | } else { |
| 462 | width = 0; |
| 463 | height = 0; |
| 464 | } |
| 465 | |
| 466 | shsurf->client->send_configure(shsurf->surface, width, height); |
| 467 | } |
| 468 | |
Ander Conselvan de Oliveira | fe0444a | 2012-04-04 17:48:05 +0300 | [diff] [blame] | 469 | static void |
Jasper St. Pierre | 5befdda | 2014-05-06 08:50:47 -0400 | [diff] [blame] | 470 | shell_surface_state_changed(struct shell_surface *shsurf) |
| 471 | { |
Jasper St. Pierre | 6458ec3 | 2014-04-11 16:00:31 -0700 | [diff] [blame] | 472 | if (shell_surface_is_xdg_surface(shsurf)) |
| 473 | send_configure_for_surface(shsurf); |
Jasper St. Pierre | 5befdda | 2014-05-06 08:50:47 -0400 | [diff] [blame] | 474 | } |
| 475 | |
| 476 | static void |
Ander Conselvan de Oliveira | b9d2a0f | 2012-06-28 18:08:05 +0300 | [diff] [blame] | 477 | shell_grab_end(struct shell_grab *grab) |
Ander Conselvan de Oliveira | fe0444a | 2012-04-04 17:48:05 +0300 | [diff] [blame] | 478 | { |
Kristian Høgsberg | c85f1d4 | 2013-10-24 16:52:00 -0700 | [diff] [blame] | 479 | if (grab->shsurf) { |
Kristian Høgsberg | 47b5dca | 2012-06-07 18:08:04 -0400 | [diff] [blame] | 480 | wl_list_remove(&grab->shsurf_destroy_listener.link); |
Kristian Høgsberg | c85f1d4 | 2013-10-24 16:52:00 -0700 | [diff] [blame] | 481 | grab->shsurf->grabbed = 0; |
Jasper St. Pierre | 5befdda | 2014-05-06 08:50:47 -0400 | [diff] [blame] | 482 | |
| 483 | if (grab->shsurf->resize_edges) { |
| 484 | grab->shsurf->resize_edges = 0; |
| 485 | shell_surface_state_changed(grab->shsurf); |
| 486 | } |
Kristian Høgsberg | c85f1d4 | 2013-10-24 16:52:00 -0700 | [diff] [blame] | 487 | } |
Ander Conselvan de Oliveira | b9d2a0f | 2012-06-28 18:08:05 +0300 | [diff] [blame] | 488 | |
Kristian Høgsberg | 9e5d7d1 | 2013-07-22 16:31:53 -0700 | [diff] [blame] | 489 | weston_pointer_end_grab(grab->grab.pointer); |
Ander Conselvan de Oliveira | fe0444a | 2012-04-04 17:48:05 +0300 | [diff] [blame] | 490 | } |
| 491 | |
| 492 | static void |
Rusty Lynch | 1084da5 | 2013-08-15 09:10:08 -0700 | [diff] [blame] | 493 | shell_touch_grab_start(struct shell_touch_grab *grab, |
| 494 | const struct weston_touch_grab_interface *interface, |
| 495 | struct shell_surface *shsurf, |
| 496 | struct weston_touch *touch) |
| 497 | { |
| 498 | struct desktop_shell *shell = shsurf->shell; |
U. Artie Eoff | cf5737a | 2014-01-17 10:08:25 -0800 | [diff] [blame] | 499 | |
Kristian Høgsberg | 74071e0 | 2014-04-29 15:01:16 -0700 | [diff] [blame] | 500 | if (touch->seat->pointer) |
| 501 | popup_grab_end(touch->seat->pointer); |
| 502 | |
Rusty Lynch | 1084da5 | 2013-08-15 09:10:08 -0700 | [diff] [blame] | 503 | grab->grab.interface = interface; |
| 504 | grab->shsurf = shsurf; |
| 505 | grab->shsurf_destroy_listener.notify = destroy_shell_grab_shsurf; |
| 506 | wl_signal_add(&shsurf->destroy_signal, |
| 507 | &grab->shsurf_destroy_listener); |
| 508 | |
| 509 | grab->touch = touch; |
Kristian Høgsberg | c85f1d4 | 2013-10-24 16:52:00 -0700 | [diff] [blame] | 510 | shsurf->grabbed = 1; |
Rusty Lynch | 1084da5 | 2013-08-15 09:10:08 -0700 | [diff] [blame] | 511 | |
| 512 | weston_touch_start_grab(touch, &grab->grab); |
| 513 | if (shell->child.desktop_shell) |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 514 | weston_touch_set_focus(touch->seat, |
| 515 | get_default_view(shell->grab_surface)); |
Rusty Lynch | 1084da5 | 2013-08-15 09:10:08 -0700 | [diff] [blame] | 516 | } |
| 517 | |
| 518 | static void |
| 519 | shell_touch_grab_end(struct shell_touch_grab *grab) |
| 520 | { |
Kristian Høgsberg | c85f1d4 | 2013-10-24 16:52:00 -0700 | [diff] [blame] | 521 | if (grab->shsurf) { |
Rusty Lynch | 1084da5 | 2013-08-15 09:10:08 -0700 | [diff] [blame] | 522 | wl_list_remove(&grab->shsurf_destroy_listener.link); |
Kristian Høgsberg | c85f1d4 | 2013-10-24 16:52:00 -0700 | [diff] [blame] | 523 | grab->shsurf->grabbed = 0; |
| 524 | } |
Rusty Lynch | 1084da5 | 2013-08-15 09:10:08 -0700 | [diff] [blame] | 525 | |
| 526 | weston_touch_end_grab(grab->touch); |
| 527 | } |
| 528 | |
| 529 | static void |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 530 | center_on_output(struct weston_view *view, |
Alex Wu | 4539b08 | 2012-03-01 12:57:46 +0800 | [diff] [blame] | 531 | struct weston_output *output); |
| 532 | |
Daniel Stone | 496ca17 | 2012-05-30 16:31:42 +0100 | [diff] [blame] | 533 | static enum weston_keyboard_modifier |
Tiago Vignatti | 0b52d48 | 2012-04-20 18:54:25 +0300 | [diff] [blame] | 534 | get_modifier(char *modifier) |
| 535 | { |
| 536 | if (!modifier) |
| 537 | return MODIFIER_SUPER; |
| 538 | |
| 539 | if (!strcmp("ctrl", modifier)) |
| 540 | return MODIFIER_CTRL; |
| 541 | else if (!strcmp("alt", modifier)) |
| 542 | return MODIFIER_ALT; |
| 543 | else if (!strcmp("super", modifier)) |
| 544 | return MODIFIER_SUPER; |
| 545 | else |
| 546 | return MODIFIER_SUPER; |
| 547 | } |
| 548 | |
Juan Zhao | e10d279 | 2012-04-25 19:09:52 +0800 | [diff] [blame] | 549 | static enum animation_type |
| 550 | get_animation_type(char *animation) |
| 551 | { |
U. Artie Eoff | b571910 | 2014-01-15 14:26:31 -0800 | [diff] [blame] | 552 | if (!animation) |
| 553 | return ANIMATION_NONE; |
| 554 | |
Juan Zhao | e10d279 | 2012-04-25 19:09:52 +0800 | [diff] [blame] | 555 | if (!strcmp("zoom", animation)) |
| 556 | return ANIMATION_ZOOM; |
| 557 | else if (!strcmp("fade", animation)) |
| 558 | return ANIMATION_FADE; |
Louis-Francis Ratté-Boulianne | b482dbd | 2013-11-19 11:37:11 +0100 | [diff] [blame] | 559 | else if (!strcmp("dim-layer", animation)) |
| 560 | return ANIMATION_DIM_LAYER; |
Juan Zhao | e10d279 | 2012-04-25 19:09:52 +0800 | [diff] [blame] | 561 | else |
| 562 | return ANIMATION_NONE; |
| 563 | } |
| 564 | |
Alex Wu | 4539b08 | 2012-03-01 12:57:46 +0800 | [diff] [blame] | 565 | static void |
Kristian Høgsberg | 14e438c | 2013-05-26 21:48:14 -0400 | [diff] [blame] | 566 | shell_configuration(struct desktop_shell *shell) |
Pekka Paalanen | e955f1e | 2011-12-07 11:49:52 +0200 | [diff] [blame] | 567 | { |
Kristian Høgsberg | 673a889 | 2013-05-23 21:40:56 -0400 | [diff] [blame] | 568 | struct weston_config_section *section; |
| 569 | int duration; |
Derek Foreman | c721043 | 2014-08-21 11:32:38 -0500 | [diff] [blame] | 570 | char *s, *client; |
Pekka Paalanen | e955f1e | 2011-12-07 11:49:52 +0200 | [diff] [blame] | 571 | |
Kristian Høgsberg | 673a889 | 2013-05-23 21:40:56 -0400 | [diff] [blame] | 572 | section = weston_config_get_section(shell->compositor->config, |
| 573 | "screensaver", NULL, NULL); |
| 574 | weston_config_section_get_string(section, |
| 575 | "path", &shell->screensaver.path, NULL); |
| 576 | weston_config_section_get_int(section, "duration", &duration, 60); |
Ander Conselvan de Oliveira | 859e885 | 2013-02-21 18:35:21 +0200 | [diff] [blame] | 577 | shell->screensaver.duration = duration * 1000; |
Kristian Høgsberg | 673a889 | 2013-05-23 21:40:56 -0400 | [diff] [blame] | 578 | |
| 579 | section = weston_config_get_section(shell->compositor->config, |
| 580 | "shell", NULL, NULL); |
Derek Foreman | c721043 | 2014-08-21 11:32:38 -0500 | [diff] [blame] | 581 | asprintf(&client, "%s/%s", weston_config_get_libexec_dir(), |
| 582 | WESTON_SHELL_CLIENT); |
Kristian Høgsberg | 673a889 | 2013-05-23 21:40:56 -0400 | [diff] [blame] | 583 | weston_config_section_get_string(section, |
Derek Foreman | c721043 | 2014-08-21 11:32:38 -0500 | [diff] [blame] | 584 | "client", &s, client); |
| 585 | free(client); |
Emilio Pozuelo Monfort | 46ce798 | 2013-11-20 13:22:29 +0100 | [diff] [blame] | 586 | shell->client = s; |
| 587 | weston_config_section_get_string(section, |
Kristian Høgsberg | 673a889 | 2013-05-23 21:40:56 -0400 | [diff] [blame] | 588 | "binding-modifier", &s, "super"); |
| 589 | shell->binding_modifier = get_modifier(s); |
Quentin Glidic | 8418c29 | 2013-06-18 09:11:03 +0200 | [diff] [blame] | 590 | free(s); |
Kristian Høgsberg | d56ab4e | 2014-01-16 16:51:52 -0800 | [diff] [blame] | 591 | |
| 592 | weston_config_section_get_string(section, |
| 593 | "exposay-modifier", &s, "none"); |
| 594 | if (strcmp(s, "none") == 0) |
| 595 | shell->exposay_modifier = 0; |
| 596 | else |
| 597 | shell->exposay_modifier = get_modifier(s); |
| 598 | free(s); |
| 599 | |
Kristian Høgsberg | 673a889 | 2013-05-23 21:40:56 -0400 | [diff] [blame] | 600 | weston_config_section_get_string(section, "animation", &s, "none"); |
| 601 | shell->win_animation_type = get_animation_type(s); |
Quentin Glidic | 8418c29 | 2013-06-18 09:11:03 +0200 | [diff] [blame] | 602 | free(s); |
Jonny Lamb | f322f8e | 2014-08-12 15:13:30 +0200 | [diff] [blame] | 603 | weston_config_section_get_string(section, "close-animation", &s, "fade"); |
| 604 | shell->win_close_animation_type = get_animation_type(s); |
| 605 | free(s); |
Kristian Høgsberg | 724c8d9 | 2013-10-16 11:38:24 -0700 | [diff] [blame] | 606 | weston_config_section_get_string(section, |
| 607 | "startup-animation", &s, "fade"); |
| 608 | shell->startup_animation_type = get_animation_type(s); |
| 609 | free(s); |
Kristian Høgsberg | 912e0a1 | 2013-10-30 08:59:55 -0700 | [diff] [blame] | 610 | if (shell->startup_animation_type == ANIMATION_ZOOM) |
| 611 | shell->startup_animation_type = ANIMATION_NONE; |
Louis-Francis Ratté-Boulianne | b482dbd | 2013-11-19 11:37:11 +0100 | [diff] [blame] | 612 | weston_config_section_get_string(section, "focus-animation", &s, "none"); |
| 613 | shell->focus_animation_type = get_animation_type(s); |
| 614 | free(s); |
Kristian Høgsberg | 673a889 | 2013-05-23 21:40:56 -0400 | [diff] [blame] | 615 | weston_config_section_get_uint(section, "num-workspaces", |
| 616 | &shell->workspaces.num, |
| 617 | DEFAULT_NUM_WORKSPACES); |
Jonas Ådahl | e3cddce | 2012-06-13 00:01:22 +0200 | [diff] [blame] | 618 | } |
| 619 | |
Kristian Høgsberg | 1ef2313 | 2013-12-04 00:20:01 -0800 | [diff] [blame] | 620 | struct weston_output * |
Louis-Francis Ratté-Boulianne | b482dbd | 2013-11-19 11:37:11 +0100 | [diff] [blame] | 621 | get_default_output(struct weston_compositor *compositor) |
| 622 | { |
| 623 | return container_of(compositor->output_list.next, |
| 624 | struct weston_output, link); |
| 625 | } |
| 626 | |
| 627 | |
| 628 | /* no-op func for checking focus surface */ |
| 629 | static void |
Jason Ekstrand | 918f2dd | 2013-12-02 21:01:53 -0600 | [diff] [blame] | 630 | 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] | 631 | { |
| 632 | } |
| 633 | |
| 634 | static struct focus_surface * |
| 635 | get_focus_surface(struct weston_surface *surface) |
| 636 | { |
| 637 | if (surface->configure == focus_surface_configure) |
| 638 | return surface->configure_private; |
| 639 | else |
| 640 | return NULL; |
| 641 | } |
| 642 | |
| 643 | static bool |
| 644 | is_focus_surface (struct weston_surface *es) |
| 645 | { |
| 646 | return (es->configure == focus_surface_configure); |
| 647 | } |
| 648 | |
| 649 | static bool |
| 650 | is_focus_view (struct weston_view *view) |
| 651 | { |
| 652 | return is_focus_surface (view->surface); |
| 653 | } |
| 654 | |
| 655 | static struct focus_surface * |
| 656 | create_focus_surface(struct weston_compositor *ec, |
| 657 | struct weston_output *output) |
| 658 | { |
| 659 | struct focus_surface *fsurf = NULL; |
| 660 | struct weston_surface *surface = NULL; |
| 661 | |
| 662 | fsurf = malloc(sizeof *fsurf); |
| 663 | if (!fsurf) |
| 664 | return NULL; |
| 665 | |
| 666 | fsurf->surface = weston_surface_create(ec); |
| 667 | surface = fsurf->surface; |
| 668 | if (surface == NULL) { |
| 669 | free(fsurf); |
| 670 | return NULL; |
| 671 | } |
| 672 | |
| 673 | surface->configure = focus_surface_configure; |
| 674 | surface->output = output; |
| 675 | surface->configure_private = fsurf; |
| 676 | |
U. Artie Eoff | 0b23b2b | 2014-01-15 14:45:59 -0800 | [diff] [blame] | 677 | fsurf->view = weston_view_create(surface); |
| 678 | if (fsurf->view == NULL) { |
| 679 | weston_surface_destroy(surface); |
| 680 | free(fsurf); |
| 681 | return NULL; |
| 682 | } |
Emilio Pozuelo Monfort | da64426 | 2013-11-19 11:37:19 +0100 | [diff] [blame] | 683 | fsurf->view->output = output; |
Louis-Francis Ratté-Boulianne | b482dbd | 2013-11-19 11:37:11 +0100 | [diff] [blame] | 684 | |
Jason Ekstrand | 5c11a33 | 2013-12-04 20:32:03 -0600 | [diff] [blame] | 685 | weston_surface_set_size(surface, output->width, output->height); |
Jason Ekstrand | 918f2dd | 2013-12-02 21:01:53 -0600 | [diff] [blame] | 686 | weston_view_set_position(fsurf->view, output->x, output->y); |
Louis-Francis Ratté-Boulianne | b482dbd | 2013-11-19 11:37:11 +0100 | [diff] [blame] | 687 | weston_surface_set_color(surface, 0.0, 0.0, 0.0, 1.0); |
| 688 | pixman_region32_fini(&surface->opaque); |
| 689 | pixman_region32_init_rect(&surface->opaque, output->x, output->y, |
| 690 | output->width, output->height); |
| 691 | pixman_region32_fini(&surface->input); |
| 692 | pixman_region32_init(&surface->input); |
| 693 | |
| 694 | wl_list_init(&fsurf->workspace_transform.link); |
| 695 | |
| 696 | return fsurf; |
| 697 | } |
| 698 | |
| 699 | static void |
| 700 | focus_surface_destroy(struct focus_surface *fsurf) |
| 701 | { |
| 702 | weston_surface_destroy(fsurf->surface); |
| 703 | free(fsurf); |
| 704 | } |
| 705 | |
| 706 | static void |
| 707 | focus_animation_done(struct weston_view_animation *animation, void *data) |
| 708 | { |
| 709 | struct workspace *ws = data; |
| 710 | |
| 711 | ws->focus_animation = NULL; |
| 712 | } |
| 713 | |
Jonas Ådahl | e3cddce | 2012-06-13 00:01:22 +0200 | [diff] [blame] | 714 | static void |
Jonas Ådahl | 0476974 | 2012-06-13 00:01:24 +0200 | [diff] [blame] | 715 | focus_state_destroy(struct focus_state *state) |
| 716 | { |
| 717 | wl_list_remove(&state->seat_destroy_listener.link); |
| 718 | wl_list_remove(&state->surface_destroy_listener.link); |
| 719 | free(state); |
| 720 | } |
| 721 | |
| 722 | static void |
| 723 | focus_state_seat_destroy(struct wl_listener *listener, void *data) |
| 724 | { |
| 725 | struct focus_state *state = container_of(listener, |
| 726 | struct focus_state, |
| 727 | seat_destroy_listener); |
| 728 | |
| 729 | wl_list_remove(&state->link); |
| 730 | focus_state_destroy(state); |
| 731 | } |
| 732 | |
| 733 | static void |
| 734 | focus_state_surface_destroy(struct wl_listener *listener, void *data) |
| 735 | { |
| 736 | struct focus_state *state = container_of(listener, |
| 737 | struct focus_state, |
Kristian Høgsberg | b8e0d0f | 2012-07-31 10:30:26 -0400 | [diff] [blame] | 738 | surface_destroy_listener); |
Kristian Høgsberg | e377822 | 2012-07-31 17:29:30 -0400 | [diff] [blame] | 739 | struct desktop_shell *shell; |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 740 | struct weston_surface *main_surface, *next; |
| 741 | struct weston_view *view; |
Jonas Ådahl | 0476974 | 2012-06-13 00:01:24 +0200 | [diff] [blame] | 742 | |
Pekka Paalanen | 01388e2 | 2013-04-25 13:57:44 +0300 | [diff] [blame] | 743 | main_surface = weston_surface_get_main_surface(state->keyboard_focus); |
| 744 | |
Kristian Høgsberg | e377822 | 2012-07-31 17:29:30 -0400 | [diff] [blame] | 745 | next = NULL; |
Giulio Camuffo | 412e6a5 | 2014-07-09 22:12:56 +0300 | [diff] [blame] | 746 | wl_list_for_each(view, |
| 747 | &state->ws->layer.view_list.link, layer_link.link) { |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 748 | if (view->surface == main_surface) |
Kristian Høgsberg | e377822 | 2012-07-31 17:29:30 -0400 | [diff] [blame] | 749 | continue; |
Louis-Francis Ratté-Boulianne | b482dbd | 2013-11-19 11:37:11 +0100 | [diff] [blame] | 750 | if (is_focus_view(view)) |
| 751 | continue; |
Kristian Høgsberg | e377822 | 2012-07-31 17:29:30 -0400 | [diff] [blame] | 752 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 753 | next = view->surface; |
Kristian Høgsberg | e377822 | 2012-07-31 17:29:30 -0400 | [diff] [blame] | 754 | break; |
| 755 | } |
| 756 | |
Pekka Paalanen | 01388e2 | 2013-04-25 13:57:44 +0300 | [diff] [blame] | 757 | /* if the focus was a sub-surface, activate its main surface */ |
| 758 | if (main_surface != state->keyboard_focus) |
| 759 | next = main_surface; |
| 760 | |
Louis-Francis Ratté-Boulianne | b482dbd | 2013-11-19 11:37:11 +0100 | [diff] [blame] | 761 | shell = state->seat->compositor->shell_interface.shell; |
Kristian Høgsberg | e377822 | 2012-07-31 17:29:30 -0400 | [diff] [blame] | 762 | if (next) { |
Louis-Francis Ratté-Boulianne | b482dbd | 2013-11-19 11:37:11 +0100 | [diff] [blame] | 763 | state->keyboard_focus = NULL; |
Emilio Pozuelo Monfort | 9e7c759 | 2014-01-30 14:01:10 +0100 | [diff] [blame] | 764 | activate(shell, next, state->seat, true); |
Kristian Høgsberg | e377822 | 2012-07-31 17:29:30 -0400 | [diff] [blame] | 765 | } else { |
Louis-Francis Ratté-Boulianne | b482dbd | 2013-11-19 11:37:11 +0100 | [diff] [blame] | 766 | if (shell->focus_animation_type == ANIMATION_DIM_LAYER) { |
| 767 | if (state->ws->focus_animation) |
| 768 | weston_view_animation_destroy(state->ws->focus_animation); |
| 769 | |
| 770 | state->ws->focus_animation = weston_fade_run( |
| 771 | state->ws->fsurf_front->view, |
| 772 | state->ws->fsurf_front->view->alpha, 0.0, 300, |
| 773 | focus_animation_done, state->ws); |
| 774 | } |
| 775 | |
Kristian Høgsberg | e377822 | 2012-07-31 17:29:30 -0400 | [diff] [blame] | 776 | wl_list_remove(&state->link); |
| 777 | focus_state_destroy(state); |
| 778 | } |
Jonas Ådahl | 0476974 | 2012-06-13 00:01:24 +0200 | [diff] [blame] | 779 | } |
| 780 | |
| 781 | static struct focus_state * |
Kristian Høgsberg | 2f5faff | 2012-07-31 16:36:34 -0400 | [diff] [blame] | 782 | focus_state_create(struct weston_seat *seat, struct workspace *ws) |
Jonas Ådahl | 0476974 | 2012-06-13 00:01:24 +0200 | [diff] [blame] | 783 | { |
Jonas Ådahl | 0476974 | 2012-06-13 00:01:24 +0200 | [diff] [blame] | 784 | struct focus_state *state; |
Jonas Ådahl | 0476974 | 2012-06-13 00:01:24 +0200 | [diff] [blame] | 785 | |
| 786 | state = malloc(sizeof *state); |
| 787 | if (state == NULL) |
| 788 | return NULL; |
| 789 | |
Louis-Francis Ratté-Boulianne | b482dbd | 2013-11-19 11:37:11 +0100 | [diff] [blame] | 790 | state->keyboard_focus = NULL; |
Kristian Høgsberg | 2f5faff | 2012-07-31 16:36:34 -0400 | [diff] [blame] | 791 | state->ws = ws; |
Jonas Ådahl | 0476974 | 2012-06-13 00:01:24 +0200 | [diff] [blame] | 792 | state->seat = seat; |
Kristian Høgsberg | 2f5faff | 2012-07-31 16:36:34 -0400 | [diff] [blame] | 793 | wl_list_insert(&ws->focus_list, &state->link); |
Jonas Ådahl | 0476974 | 2012-06-13 00:01:24 +0200 | [diff] [blame] | 794 | |
| 795 | state->seat_destroy_listener.notify = focus_state_seat_destroy; |
| 796 | state->surface_destroy_listener.notify = focus_state_surface_destroy; |
Kristian Høgsberg | 4912454 | 2013-05-06 22:27:40 -0400 | [diff] [blame] | 797 | wl_signal_add(&seat->destroy_signal, |
Jonas Ådahl | 0476974 | 2012-06-13 00:01:24 +0200 | [diff] [blame] | 798 | &state->seat_destroy_listener); |
Kristian Høgsberg | 2f5faff | 2012-07-31 16:36:34 -0400 | [diff] [blame] | 799 | wl_list_init(&state->surface_destroy_listener.link); |
Jonas Ådahl | 0476974 | 2012-06-13 00:01:24 +0200 | [diff] [blame] | 800 | |
| 801 | return state; |
| 802 | } |
| 803 | |
Jonas Ådahl | 8538b22 | 2012-08-29 22:13:03 +0200 | [diff] [blame] | 804 | static struct focus_state * |
| 805 | ensure_focus_state(struct desktop_shell *shell, struct weston_seat *seat) |
| 806 | { |
| 807 | struct workspace *ws = get_current_workspace(shell); |
| 808 | struct focus_state *state; |
| 809 | |
| 810 | wl_list_for_each(state, &ws->focus_list, link) |
| 811 | if (state->seat == seat) |
| 812 | break; |
| 813 | |
| 814 | if (&state->link == &ws->focus_list) |
| 815 | state = focus_state_create(seat, ws); |
| 816 | |
| 817 | return state; |
| 818 | } |
| 819 | |
Jonas Ådahl | 0476974 | 2012-06-13 00:01:24 +0200 | [diff] [blame] | 820 | static void |
Kristian Høgsberg | d500bf1 | 2014-01-22 12:25:20 -0800 | [diff] [blame] | 821 | focus_state_set_focus(struct focus_state *state, |
| 822 | struct weston_surface *surface) |
| 823 | { |
| 824 | if (state->keyboard_focus) { |
| 825 | wl_list_remove(&state->surface_destroy_listener.link); |
| 826 | wl_list_init(&state->surface_destroy_listener.link); |
| 827 | } |
| 828 | |
| 829 | state->keyboard_focus = surface; |
| 830 | if (surface) |
| 831 | wl_signal_add(&surface->destroy_signal, |
| 832 | &state->surface_destroy_listener); |
| 833 | } |
| 834 | |
| 835 | static void |
Kristian Høgsberg | 2f5faff | 2012-07-31 16:36:34 -0400 | [diff] [blame] | 836 | restore_focus_state(struct desktop_shell *shell, struct workspace *ws) |
Jonas Ådahl | 0476974 | 2012-06-13 00:01:24 +0200 | [diff] [blame] | 837 | { |
| 838 | struct focus_state *state, *next; |
Kristian Høgsberg | fe7aa90 | 2013-05-08 09:54:37 -0400 | [diff] [blame] | 839 | struct weston_surface *surface; |
Neil Roberts | 4237f50 | 2014-04-09 16:33:31 +0100 | [diff] [blame] | 840 | struct wl_list pending_seat_list; |
| 841 | struct weston_seat *seat, *next_seat; |
| 842 | |
| 843 | /* Temporarily steal the list of seats so that we can keep |
| 844 | * track of the seats we've already processed */ |
| 845 | wl_list_init(&pending_seat_list); |
| 846 | wl_list_insert_list(&pending_seat_list, &shell->compositor->seat_list); |
| 847 | wl_list_init(&shell->compositor->seat_list); |
Jonas Ådahl | 0476974 | 2012-06-13 00:01:24 +0200 | [diff] [blame] | 848 | |
| 849 | wl_list_for_each_safe(state, next, &ws->focus_list, link) { |
Neil Roberts | 4237f50 | 2014-04-09 16:33:31 +0100 | [diff] [blame] | 850 | wl_list_remove(&state->seat->link); |
| 851 | wl_list_insert(&shell->compositor->seat_list, |
| 852 | &state->seat->link); |
| 853 | |
Kristian Høgsberg | e61d2f4 | 2014-01-17 12:18:53 -0800 | [diff] [blame] | 854 | if (state->seat->keyboard == NULL) |
| 855 | continue; |
| 856 | |
Kristian Høgsberg | fe7aa90 | 2013-05-08 09:54:37 -0400 | [diff] [blame] | 857 | surface = state->keyboard_focus; |
Jonas Ådahl | 5689944 | 2012-08-29 22:12:59 +0200 | [diff] [blame] | 858 | |
Kristian Høgsberg | e314875 | 2013-05-06 23:19:49 -0400 | [diff] [blame] | 859 | weston_keyboard_set_focus(state->seat->keyboard, surface); |
Jonas Ådahl | 0476974 | 2012-06-13 00:01:24 +0200 | [diff] [blame] | 860 | } |
Neil Roberts | 4237f50 | 2014-04-09 16:33:31 +0100 | [diff] [blame] | 861 | |
| 862 | /* For any remaining seats that we don't have a focus state |
| 863 | * for we'll reset the keyboard focus to NULL */ |
| 864 | wl_list_for_each_safe(seat, next_seat, &pending_seat_list, link) { |
| 865 | wl_list_insert(&shell->compositor->seat_list, &seat->link); |
| 866 | |
Ander Conselvan de Oliveira | 6e56ab4 | 2014-05-07 11:57:28 +0300 | [diff] [blame] | 867 | if (seat->keyboard == NULL) |
Neil Roberts | 4237f50 | 2014-04-09 16:33:31 +0100 | [diff] [blame] | 868 | continue; |
| 869 | |
| 870 | weston_keyboard_set_focus(seat->keyboard, NULL); |
| 871 | } |
Jonas Ådahl | 0476974 | 2012-06-13 00:01:24 +0200 | [diff] [blame] | 872 | } |
| 873 | |
| 874 | static void |
Jonas Ådahl | 8de6a1d | 2012-08-29 22:13:00 +0200 | [diff] [blame] | 875 | replace_focus_state(struct desktop_shell *shell, struct workspace *ws, |
| 876 | struct weston_seat *seat) |
| 877 | { |
| 878 | struct focus_state *state; |
Jonas Ådahl | 8de6a1d | 2012-08-29 22:13:00 +0200 | [diff] [blame] | 879 | |
| 880 | wl_list_for_each(state, &ws->focus_list, link) { |
| 881 | if (state->seat == seat) { |
Kristian Høgsberg | d500bf1 | 2014-01-22 12:25:20 -0800 | [diff] [blame] | 882 | focus_state_set_focus(state, seat->keyboard->focus); |
Jonas Ådahl | 8de6a1d | 2012-08-29 22:13:00 +0200 | [diff] [blame] | 883 | return; |
| 884 | } |
| 885 | } |
| 886 | } |
| 887 | |
| 888 | static void |
| 889 | drop_focus_state(struct desktop_shell *shell, struct workspace *ws, |
| 890 | struct weston_surface *surface) |
| 891 | { |
| 892 | struct focus_state *state; |
| 893 | |
| 894 | wl_list_for_each(state, &ws->focus_list, link) |
| 895 | if (state->keyboard_focus == surface) |
Kristian Høgsberg | d500bf1 | 2014-01-22 12:25:20 -0800 | [diff] [blame] | 896 | focus_state_set_focus(state, NULL); |
Jonas Ådahl | 8de6a1d | 2012-08-29 22:13:00 +0200 | [diff] [blame] | 897 | } |
| 898 | |
| 899 | static void |
Louis-Francis Ratté-Boulianne | b482dbd | 2013-11-19 11:37:11 +0100 | [diff] [blame] | 900 | animate_focus_change(struct desktop_shell *shell, struct workspace *ws, |
| 901 | struct weston_view *from, struct weston_view *to) |
| 902 | { |
| 903 | struct weston_output *output; |
| 904 | bool focus_surface_created = false; |
| 905 | |
| 906 | /* FIXME: Only support dim animation using two layers */ |
| 907 | if (from == to || shell->focus_animation_type != ANIMATION_DIM_LAYER) |
| 908 | return; |
| 909 | |
| 910 | output = get_default_output(shell->compositor); |
| 911 | if (ws->fsurf_front == NULL && (from || to)) { |
| 912 | ws->fsurf_front = create_focus_surface(shell->compositor, output); |
U. Artie Eoff | 0b23b2b | 2014-01-15 14:45:59 -0800 | [diff] [blame] | 913 | if (ws->fsurf_front == NULL) |
| 914 | return; |
Louis-Francis Ratté-Boulianne | b482dbd | 2013-11-19 11:37:11 +0100 | [diff] [blame] | 915 | ws->fsurf_front->view->alpha = 0.0; |
U. Artie Eoff | 0b23b2b | 2014-01-15 14:45:59 -0800 | [diff] [blame] | 916 | |
| 917 | ws->fsurf_back = create_focus_surface(shell->compositor, output); |
| 918 | if (ws->fsurf_back == NULL) { |
| 919 | focus_surface_destroy(ws->fsurf_front); |
| 920 | return; |
| 921 | } |
Louis-Francis Ratté-Boulianne | b482dbd | 2013-11-19 11:37:11 +0100 | [diff] [blame] | 922 | ws->fsurf_back->view->alpha = 0.0; |
U. Artie Eoff | 0b23b2b | 2014-01-15 14:45:59 -0800 | [diff] [blame] | 923 | |
Louis-Francis Ratté-Boulianne | b482dbd | 2013-11-19 11:37:11 +0100 | [diff] [blame] | 924 | focus_surface_created = true; |
| 925 | } else { |
Giulio Camuffo | 412e6a5 | 2014-07-09 22:12:56 +0300 | [diff] [blame] | 926 | weston_layer_entry_remove(&ws->fsurf_front->view->layer_link); |
| 927 | weston_layer_entry_remove(&ws->fsurf_back->view->layer_link); |
Louis-Francis Ratté-Boulianne | b482dbd | 2013-11-19 11:37:11 +0100 | [diff] [blame] | 928 | } |
| 929 | |
| 930 | if (ws->focus_animation) { |
| 931 | weston_view_animation_destroy(ws->focus_animation); |
| 932 | ws->focus_animation = NULL; |
| 933 | } |
| 934 | |
| 935 | if (to) |
Giulio Camuffo | 412e6a5 | 2014-07-09 22:12:56 +0300 | [diff] [blame] | 936 | weston_layer_entry_insert(&to->layer_link, |
| 937 | &ws->fsurf_front->view->layer_link); |
Louis-Francis Ratté-Boulianne | b482dbd | 2013-11-19 11:37:11 +0100 | [diff] [blame] | 938 | else if (from) |
Giulio Camuffo | 412e6a5 | 2014-07-09 22:12:56 +0300 | [diff] [blame] | 939 | weston_layer_entry_insert(&ws->layer.view_list, |
| 940 | &ws->fsurf_front->view->layer_link); |
Louis-Francis Ratté-Boulianne | b482dbd | 2013-11-19 11:37:11 +0100 | [diff] [blame] | 941 | |
| 942 | if (focus_surface_created) { |
| 943 | ws->focus_animation = weston_fade_run( |
| 944 | ws->fsurf_front->view, |
Jonny Lamb | 7e7d485 | 2014-05-22 22:41:34 +0200 | [diff] [blame] | 945 | ws->fsurf_front->view->alpha, 0.4, 300, |
Louis-Francis Ratté-Boulianne | b482dbd | 2013-11-19 11:37:11 +0100 | [diff] [blame] | 946 | focus_animation_done, ws); |
| 947 | } else if (from) { |
Giulio Camuffo | 412e6a5 | 2014-07-09 22:12:56 +0300 | [diff] [blame] | 948 | weston_layer_entry_insert(&from->layer_link, |
| 949 | &ws->fsurf_back->view->layer_link); |
Louis-Francis Ratté-Boulianne | b482dbd | 2013-11-19 11:37:11 +0100 | [diff] [blame] | 950 | ws->focus_animation = weston_stable_fade_run( |
| 951 | ws->fsurf_front->view, 0.0, |
Jonny Lamb | 7e7d485 | 2014-05-22 22:41:34 +0200 | [diff] [blame] | 952 | ws->fsurf_back->view, 0.4, |
Louis-Francis Ratté-Boulianne | b482dbd | 2013-11-19 11:37:11 +0100 | [diff] [blame] | 953 | focus_animation_done, ws); |
| 954 | } else if (to) { |
Giulio Camuffo | 412e6a5 | 2014-07-09 22:12:56 +0300 | [diff] [blame] | 955 | weston_layer_entry_insert(&ws->layer.view_list, |
| 956 | &ws->fsurf_back->view->layer_link); |
Louis-Francis Ratté-Boulianne | b482dbd | 2013-11-19 11:37:11 +0100 | [diff] [blame] | 957 | ws->focus_animation = weston_stable_fade_run( |
| 958 | ws->fsurf_front->view, 0.0, |
Jonny Lamb | 7e7d485 | 2014-05-22 22:41:34 +0200 | [diff] [blame] | 959 | ws->fsurf_back->view, 0.4, |
Louis-Francis Ratté-Boulianne | b482dbd | 2013-11-19 11:37:11 +0100 | [diff] [blame] | 960 | focus_animation_done, ws); |
| 961 | } |
| 962 | } |
| 963 | |
| 964 | static void |
Jonas Ådahl | e3cddce | 2012-06-13 00:01:22 +0200 | [diff] [blame] | 965 | workspace_destroy(struct workspace *ws) |
| 966 | { |
Jonas Ådahl | 0476974 | 2012-06-13 00:01:24 +0200 | [diff] [blame] | 967 | struct focus_state *state, *next; |
| 968 | |
| 969 | wl_list_for_each_safe(state, next, &ws->focus_list, link) |
| 970 | focus_state_destroy(state); |
| 971 | |
Louis-Francis Ratté-Boulianne | b482dbd | 2013-11-19 11:37:11 +0100 | [diff] [blame] | 972 | if (ws->fsurf_front) |
| 973 | focus_surface_destroy(ws->fsurf_front); |
| 974 | if (ws->fsurf_back) |
| 975 | focus_surface_destroy(ws->fsurf_back); |
| 976 | |
Jonas Ådahl | e3cddce | 2012-06-13 00:01:22 +0200 | [diff] [blame] | 977 | free(ws); |
| 978 | } |
| 979 | |
Jonas Ådahl | 0476974 | 2012-06-13 00:01:24 +0200 | [diff] [blame] | 980 | static void |
| 981 | seat_destroyed(struct wl_listener *listener, void *data) |
| 982 | { |
| 983 | struct weston_seat *seat = data; |
| 984 | struct focus_state *state, *next; |
| 985 | struct workspace *ws = container_of(listener, |
| 986 | struct workspace, |
| 987 | seat_destroyed_listener); |
| 988 | |
| 989 | wl_list_for_each_safe(state, next, &ws->focus_list, link) |
| 990 | if (state->seat == seat) |
| 991 | wl_list_remove(&state->link); |
| 992 | } |
| 993 | |
Jonas Ådahl | e3cddce | 2012-06-13 00:01:22 +0200 | [diff] [blame] | 994 | static struct workspace * |
| 995 | workspace_create(void) |
| 996 | { |
| 997 | struct workspace *ws = malloc(sizeof *ws); |
| 998 | if (ws == NULL) |
| 999 | return NULL; |
| 1000 | |
| 1001 | weston_layer_init(&ws->layer, NULL); |
| 1002 | |
Jonas Ådahl | 0476974 | 2012-06-13 00:01:24 +0200 | [diff] [blame] | 1003 | wl_list_init(&ws->focus_list); |
| 1004 | wl_list_init(&ws->seat_destroyed_listener.link); |
| 1005 | ws->seat_destroyed_listener.notify = seat_destroyed; |
Louis-Francis Ratté-Boulianne | b482dbd | 2013-11-19 11:37:11 +0100 | [diff] [blame] | 1006 | ws->fsurf_front = NULL; |
| 1007 | ws->fsurf_back = NULL; |
| 1008 | ws->focus_animation = NULL; |
Jonas Ådahl | 0476974 | 2012-06-13 00:01:24 +0200 | [diff] [blame] | 1009 | |
Jonas Ådahl | e3cddce | 2012-06-13 00:01:22 +0200 | [diff] [blame] | 1010 | return ws; |
| 1011 | } |
| 1012 | |
Jonas Ådahl | 62fcd04 | 2012-06-13 00:01:23 +0200 | [diff] [blame] | 1013 | static int |
| 1014 | workspace_is_empty(struct workspace *ws) |
| 1015 | { |
Giulio Camuffo | 412e6a5 | 2014-07-09 22:12:56 +0300 | [diff] [blame] | 1016 | return wl_list_empty(&ws->layer.view_list.link); |
Jonas Ådahl | 62fcd04 | 2012-06-13 00:01:23 +0200 | [diff] [blame] | 1017 | } |
| 1018 | |
Jonas Ådahl | e3cddce | 2012-06-13 00:01:22 +0200 | [diff] [blame] | 1019 | static struct workspace * |
| 1020 | get_workspace(struct desktop_shell *shell, unsigned int index) |
| 1021 | { |
| 1022 | struct workspace **pws = shell->workspaces.array.data; |
Philipp Brüschweiler | 067abf6 | 2012-09-01 16:03:05 +0200 | [diff] [blame] | 1023 | assert(index < shell->workspaces.num); |
Jonas Ådahl | e3cddce | 2012-06-13 00:01:22 +0200 | [diff] [blame] | 1024 | pws += index; |
| 1025 | return *pws; |
| 1026 | } |
| 1027 | |
Kristian Høgsberg | 1ef2313 | 2013-12-04 00:20:01 -0800 | [diff] [blame] | 1028 | struct workspace * |
Jonas Ådahl | e3cddce | 2012-06-13 00:01:22 +0200 | [diff] [blame] | 1029 | get_current_workspace(struct desktop_shell *shell) |
| 1030 | { |
| 1031 | return get_workspace(shell, shell->workspaces.current); |
| 1032 | } |
| 1033 | |
| 1034 | static void |
| 1035 | activate_workspace(struct desktop_shell *shell, unsigned int index) |
| 1036 | { |
| 1037 | struct workspace *ws; |
| 1038 | |
| 1039 | ws = get_workspace(shell, index); |
| 1040 | wl_list_insert(&shell->panel_layer.link, &ws->layer.link); |
| 1041 | |
| 1042 | shell->workspaces.current = index; |
| 1043 | } |
| 1044 | |
Jonas Ådahl | 62fcd04 | 2012-06-13 00:01:23 +0200 | [diff] [blame] | 1045 | static unsigned int |
| 1046 | get_output_height(struct weston_output *output) |
| 1047 | { |
| 1048 | return abs(output->region.extents.y1 - output->region.extents.y2); |
| 1049 | } |
| 1050 | |
| 1051 | static void |
Louis-Francis Ratté-Boulianne | b482dbd | 2013-11-19 11:37:11 +0100 | [diff] [blame] | 1052 | view_translate(struct workspace *ws, struct weston_view *view, double d) |
Jonas Ådahl | 62fcd04 | 2012-06-13 00:01:23 +0200 | [diff] [blame] | 1053 | { |
Jonas Ådahl | 62fcd04 | 2012-06-13 00:01:23 +0200 | [diff] [blame] | 1054 | struct weston_transform *transform; |
| 1055 | |
Louis-Francis Ratté-Boulianne | b482dbd | 2013-11-19 11:37:11 +0100 | [diff] [blame] | 1056 | if (is_focus_view(view)) { |
| 1057 | struct focus_surface *fsurf = get_focus_surface(view->surface); |
| 1058 | transform = &fsurf->workspace_transform; |
| 1059 | } else { |
| 1060 | struct shell_surface *shsurf = get_shell_surface(view->surface); |
| 1061 | transform = &shsurf->workspace_transform; |
| 1062 | } |
| 1063 | |
Jonas Ådahl | 62fcd04 | 2012-06-13 00:01:23 +0200 | [diff] [blame] | 1064 | if (wl_list_empty(&transform->link)) |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 1065 | wl_list_insert(view->geometry.transformation_list.prev, |
Louis-Francis Ratté-Boulianne | b482dbd | 2013-11-19 11:37:11 +0100 | [diff] [blame] | 1066 | &transform->link); |
Jonas Ådahl | 62fcd04 | 2012-06-13 00:01:23 +0200 | [diff] [blame] | 1067 | |
Louis-Francis Ratté-Boulianne | b482dbd | 2013-11-19 11:37:11 +0100 | [diff] [blame] | 1068 | weston_matrix_init(&transform->matrix); |
| 1069 | weston_matrix_translate(&transform->matrix, |
Jonas Ådahl | 62fcd04 | 2012-06-13 00:01:23 +0200 | [diff] [blame] | 1070 | 0.0, d, 0.0); |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 1071 | weston_view_geometry_dirty(view); |
Jonas Ådahl | 62fcd04 | 2012-06-13 00:01:23 +0200 | [diff] [blame] | 1072 | } |
| 1073 | |
| 1074 | static void |
| 1075 | workspace_translate_out(struct workspace *ws, double fraction) |
| 1076 | { |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 1077 | struct weston_view *view; |
Jonas Ådahl | 62fcd04 | 2012-06-13 00:01:23 +0200 | [diff] [blame] | 1078 | unsigned int height; |
| 1079 | double d; |
| 1080 | |
Giulio Camuffo | 412e6a5 | 2014-07-09 22:12:56 +0300 | [diff] [blame] | 1081 | 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] | 1082 | height = get_output_height(view->surface->output); |
Jonas Ådahl | 62fcd04 | 2012-06-13 00:01:23 +0200 | [diff] [blame] | 1083 | d = height * fraction; |
| 1084 | |
Louis-Francis Ratté-Boulianne | b482dbd | 2013-11-19 11:37:11 +0100 | [diff] [blame] | 1085 | view_translate(ws, view, d); |
Jonas Ådahl | 62fcd04 | 2012-06-13 00:01:23 +0200 | [diff] [blame] | 1086 | } |
| 1087 | } |
| 1088 | |
| 1089 | static void |
| 1090 | workspace_translate_in(struct workspace *ws, double fraction) |
| 1091 | { |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 1092 | struct weston_view *view; |
Jonas Ådahl | 62fcd04 | 2012-06-13 00:01:23 +0200 | [diff] [blame] | 1093 | unsigned int height; |
| 1094 | double d; |
| 1095 | |
Giulio Camuffo | 412e6a5 | 2014-07-09 22:12:56 +0300 | [diff] [blame] | 1096 | 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] | 1097 | height = get_output_height(view->surface->output); |
Jonas Ådahl | 62fcd04 | 2012-06-13 00:01:23 +0200 | [diff] [blame] | 1098 | |
| 1099 | if (fraction > 0) |
| 1100 | d = -(height - height * fraction); |
| 1101 | else |
| 1102 | d = height + height * fraction; |
| 1103 | |
Louis-Francis Ratté-Boulianne | b482dbd | 2013-11-19 11:37:11 +0100 | [diff] [blame] | 1104 | view_translate(ws, view, d); |
Jonas Ådahl | 62fcd04 | 2012-06-13 00:01:23 +0200 | [diff] [blame] | 1105 | } |
| 1106 | } |
| 1107 | |
| 1108 | static void |
Jonas Ådahl | e9d2250 | 2012-08-29 22:13:01 +0200 | [diff] [blame] | 1109 | broadcast_current_workspace_state(struct desktop_shell *shell) |
| 1110 | { |
Kristian Høgsberg | 2e3c396 | 2013-09-11 12:00:47 -0700 | [diff] [blame] | 1111 | struct wl_resource *resource; |
Jonas Ådahl | e9d2250 | 2012-08-29 22:13:01 +0200 | [diff] [blame] | 1112 | |
Kristian Høgsberg | 2e3c396 | 2013-09-11 12:00:47 -0700 | [diff] [blame] | 1113 | wl_resource_for_each(resource, &shell->workspaces.client_list) |
| 1114 | workspace_manager_send_state(resource, |
Jonas Ådahl | e9d2250 | 2012-08-29 22:13:01 +0200 | [diff] [blame] | 1115 | shell->workspaces.current, |
| 1116 | shell->workspaces.num); |
| 1117 | } |
| 1118 | |
| 1119 | static void |
Jonas Ådahl | 62fcd04 | 2012-06-13 00:01:23 +0200 | [diff] [blame] | 1120 | reverse_workspace_change_animation(struct desktop_shell *shell, |
| 1121 | unsigned int index, |
| 1122 | struct workspace *from, |
| 1123 | struct workspace *to) |
| 1124 | { |
| 1125 | shell->workspaces.current = index; |
| 1126 | |
| 1127 | shell->workspaces.anim_to = to; |
| 1128 | shell->workspaces.anim_from = from; |
| 1129 | shell->workspaces.anim_dir = -1 * shell->workspaces.anim_dir; |
| 1130 | shell->workspaces.anim_timestamp = 0; |
| 1131 | |
Scott Moreau | 4272e63 | 2012-08-13 09:58:41 -0600 | [diff] [blame] | 1132 | weston_compositor_schedule_repaint(shell->compositor); |
Jonas Ådahl | 62fcd04 | 2012-06-13 00:01:23 +0200 | [diff] [blame] | 1133 | } |
| 1134 | |
| 1135 | static void |
| 1136 | workspace_deactivate_transforms(struct workspace *ws) |
| 1137 | { |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 1138 | struct weston_view *view; |
Louis-Francis Ratté-Boulianne | b482dbd | 2013-11-19 11:37:11 +0100 | [diff] [blame] | 1139 | struct weston_transform *transform; |
Jonas Ådahl | 62fcd04 | 2012-06-13 00:01:23 +0200 | [diff] [blame] | 1140 | |
Giulio Camuffo | 412e6a5 | 2014-07-09 22:12:56 +0300 | [diff] [blame] | 1141 | 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] | 1142 | if (is_focus_view(view)) { |
| 1143 | struct focus_surface *fsurf = get_focus_surface(view->surface); |
| 1144 | transform = &fsurf->workspace_transform; |
| 1145 | } else { |
| 1146 | struct shell_surface *shsurf = get_shell_surface(view->surface); |
| 1147 | transform = &shsurf->workspace_transform; |
| 1148 | } |
| 1149 | |
| 1150 | if (!wl_list_empty(&transform->link)) { |
| 1151 | wl_list_remove(&transform->link); |
| 1152 | wl_list_init(&transform->link); |
Jonas Ådahl | 8de6a1d | 2012-08-29 22:13:00 +0200 | [diff] [blame] | 1153 | } |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 1154 | weston_view_geometry_dirty(view); |
Jonas Ådahl | 62fcd04 | 2012-06-13 00:01:23 +0200 | [diff] [blame] | 1155 | } |
| 1156 | } |
| 1157 | |
| 1158 | static void |
| 1159 | finish_workspace_change_animation(struct desktop_shell *shell, |
| 1160 | struct workspace *from, |
| 1161 | struct workspace *to) |
| 1162 | { |
Ander Conselvan de Oliveira | 9c6217e | 2014-05-07 11:57:26 +0300 | [diff] [blame] | 1163 | struct weston_view *view; |
| 1164 | |
Scott Moreau | 4272e63 | 2012-08-13 09:58:41 -0600 | [diff] [blame] | 1165 | weston_compositor_schedule_repaint(shell->compositor); |
Jonas Ådahl | 62fcd04 | 2012-06-13 00:01:23 +0200 | [diff] [blame] | 1166 | |
Ander Conselvan de Oliveira | 9c6217e | 2014-05-07 11:57:26 +0300 | [diff] [blame] | 1167 | /* Views that extend past the bottom of the output are still |
| 1168 | * visible after the workspace animation ends but before its layer |
| 1169 | * is hidden. In that case, we need to damage below those views so |
| 1170 | * that the screen is properly repainted. */ |
Giulio Camuffo | 412e6a5 | 2014-07-09 22:12:56 +0300 | [diff] [blame] | 1171 | 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] | 1172 | weston_view_damage_below(view); |
| 1173 | |
Jonas Ådahl | 62fcd04 | 2012-06-13 00:01:23 +0200 | [diff] [blame] | 1174 | wl_list_remove(&shell->workspaces.animation.link); |
| 1175 | workspace_deactivate_transforms(from); |
| 1176 | workspace_deactivate_transforms(to); |
| 1177 | shell->workspaces.anim_to = NULL; |
| 1178 | |
| 1179 | wl_list_remove(&shell->workspaces.anim_from->layer.link); |
| 1180 | } |
| 1181 | |
| 1182 | static void |
| 1183 | animate_workspace_change_frame(struct weston_animation *animation, |
| 1184 | struct weston_output *output, uint32_t msecs) |
| 1185 | { |
| 1186 | struct desktop_shell *shell = |
| 1187 | container_of(animation, struct desktop_shell, |
| 1188 | workspaces.animation); |
| 1189 | struct workspace *from = shell->workspaces.anim_from; |
| 1190 | struct workspace *to = shell->workspaces.anim_to; |
| 1191 | uint32_t t; |
| 1192 | double x, y; |
| 1193 | |
| 1194 | if (workspace_is_empty(from) && workspace_is_empty(to)) { |
| 1195 | finish_workspace_change_animation(shell, from, to); |
| 1196 | return; |
| 1197 | } |
| 1198 | |
| 1199 | if (shell->workspaces.anim_timestamp == 0) { |
| 1200 | if (shell->workspaces.anim_current == 0.0) |
| 1201 | shell->workspaces.anim_timestamp = msecs; |
| 1202 | else |
| 1203 | shell->workspaces.anim_timestamp = |
| 1204 | msecs - |
| 1205 | /* Invers of movement function 'y' below. */ |
| 1206 | (asin(1.0 - shell->workspaces.anim_current) * |
| 1207 | DEFAULT_WORKSPACE_CHANGE_ANIMATION_LENGTH * |
| 1208 | M_2_PI); |
| 1209 | } |
| 1210 | |
| 1211 | t = msecs - shell->workspaces.anim_timestamp; |
| 1212 | |
| 1213 | /* |
| 1214 | * x = [0, π/2] |
| 1215 | * y(x) = sin(x) |
| 1216 | */ |
| 1217 | x = t * (1.0/DEFAULT_WORKSPACE_CHANGE_ANIMATION_LENGTH) * M_PI_2; |
| 1218 | y = sin(x); |
| 1219 | |
| 1220 | if (t < DEFAULT_WORKSPACE_CHANGE_ANIMATION_LENGTH) { |
Scott Moreau | 4272e63 | 2012-08-13 09:58:41 -0600 | [diff] [blame] | 1221 | weston_compositor_schedule_repaint(shell->compositor); |
Jonas Ådahl | 62fcd04 | 2012-06-13 00:01:23 +0200 | [diff] [blame] | 1222 | |
| 1223 | workspace_translate_out(from, shell->workspaces.anim_dir * y); |
| 1224 | workspace_translate_in(to, shell->workspaces.anim_dir * y); |
| 1225 | shell->workspaces.anim_current = y; |
| 1226 | |
Scott Moreau | 4272e63 | 2012-08-13 09:58:41 -0600 | [diff] [blame] | 1227 | weston_compositor_schedule_repaint(shell->compositor); |
Jonas Ådahl | 62fcd04 | 2012-06-13 00:01:23 +0200 | [diff] [blame] | 1228 | } |
Jonas Ådahl | 0476974 | 2012-06-13 00:01:24 +0200 | [diff] [blame] | 1229 | else |
Jonas Ådahl | 62fcd04 | 2012-06-13 00:01:23 +0200 | [diff] [blame] | 1230 | finish_workspace_change_animation(shell, from, to); |
Jonas Ådahl | 62fcd04 | 2012-06-13 00:01:23 +0200 | [diff] [blame] | 1231 | } |
| 1232 | |
| 1233 | static void |
| 1234 | animate_workspace_change(struct desktop_shell *shell, |
| 1235 | unsigned int index, |
| 1236 | struct workspace *from, |
| 1237 | struct workspace *to) |
| 1238 | { |
| 1239 | struct weston_output *output; |
| 1240 | |
| 1241 | int dir; |
| 1242 | |
| 1243 | if (index > shell->workspaces.current) |
| 1244 | dir = -1; |
| 1245 | else |
| 1246 | dir = 1; |
| 1247 | |
| 1248 | shell->workspaces.current = index; |
| 1249 | |
| 1250 | shell->workspaces.anim_dir = dir; |
| 1251 | shell->workspaces.anim_from = from; |
| 1252 | shell->workspaces.anim_to = to; |
| 1253 | shell->workspaces.anim_current = 0.0; |
| 1254 | shell->workspaces.anim_timestamp = 0; |
| 1255 | |
| 1256 | output = container_of(shell->compositor->output_list.next, |
| 1257 | struct weston_output, link); |
| 1258 | wl_list_insert(&output->animation_list, |
| 1259 | &shell->workspaces.animation.link); |
| 1260 | |
Jonas Ådahl | 8de6a1d | 2012-08-29 22:13:00 +0200 | [diff] [blame] | 1261 | wl_list_insert(from->layer.link.prev, &to->layer.link); |
Jonas Ådahl | 62fcd04 | 2012-06-13 00:01:23 +0200 | [diff] [blame] | 1262 | |
| 1263 | workspace_translate_in(to, 0); |
| 1264 | |
Kristian Høgsberg | 2f5faff | 2012-07-31 16:36:34 -0400 | [diff] [blame] | 1265 | restore_focus_state(shell, to); |
Jonas Ådahl | 0476974 | 2012-06-13 00:01:24 +0200 | [diff] [blame] | 1266 | |
Scott Moreau | 4272e63 | 2012-08-13 09:58:41 -0600 | [diff] [blame] | 1267 | weston_compositor_schedule_repaint(shell->compositor); |
Jonas Ådahl | 62fcd04 | 2012-06-13 00:01:23 +0200 | [diff] [blame] | 1268 | } |
| 1269 | |
Jonas Ådahl | e3cddce | 2012-06-13 00:01:22 +0200 | [diff] [blame] | 1270 | static void |
Jonas Ådahl | 8de6a1d | 2012-08-29 22:13:00 +0200 | [diff] [blame] | 1271 | update_workspace(struct desktop_shell *shell, unsigned int index, |
| 1272 | struct workspace *from, struct workspace *to) |
| 1273 | { |
| 1274 | shell->workspaces.current = index; |
| 1275 | wl_list_insert(&from->layer.link, &to->layer.link); |
| 1276 | wl_list_remove(&from->layer.link); |
| 1277 | } |
| 1278 | |
| 1279 | static void |
Jonas Ådahl | e3cddce | 2012-06-13 00:01:22 +0200 | [diff] [blame] | 1280 | change_workspace(struct desktop_shell *shell, unsigned int index) |
| 1281 | { |
| 1282 | struct workspace *from; |
| 1283 | struct workspace *to; |
Louis-Francis Ratté-Boulianne | b482dbd | 2013-11-19 11:37:11 +0100 | [diff] [blame] | 1284 | struct focus_state *state; |
Jonas Ådahl | e3cddce | 2012-06-13 00:01:22 +0200 | [diff] [blame] | 1285 | |
| 1286 | if (index == shell->workspaces.current) |
| 1287 | return; |
| 1288 | |
| 1289 | /* Don't change workspace when there is any fullscreen surfaces. */ |
Giulio Camuffo | 412e6a5 | 2014-07-09 22:12:56 +0300 | [diff] [blame] | 1290 | if (!wl_list_empty(&shell->fullscreen_layer.view_list.link)) |
Jonas Ådahl | e3cddce | 2012-06-13 00:01:22 +0200 | [diff] [blame] | 1291 | return; |
| 1292 | |
Jonas Ådahl | e3cddce | 2012-06-13 00:01:22 +0200 | [diff] [blame] | 1293 | from = get_current_workspace(shell); |
| 1294 | to = get_workspace(shell, index); |
| 1295 | |
Jonas Ådahl | 62fcd04 | 2012-06-13 00:01:23 +0200 | [diff] [blame] | 1296 | if (shell->workspaces.anim_from == to && |
| 1297 | shell->workspaces.anim_to == from) { |
Jonas Ådahl | 8de6a1d | 2012-08-29 22:13:00 +0200 | [diff] [blame] | 1298 | restore_focus_state(shell, to); |
Jonas Ådahl | 62fcd04 | 2012-06-13 00:01:23 +0200 | [diff] [blame] | 1299 | reverse_workspace_change_animation(shell, index, from, to); |
Jonas Ådahl | e9d2250 | 2012-08-29 22:13:01 +0200 | [diff] [blame] | 1300 | broadcast_current_workspace_state(shell); |
Jonas Ådahl | 62fcd04 | 2012-06-13 00:01:23 +0200 | [diff] [blame] | 1301 | return; |
| 1302 | } |
Jonas Ådahl | e3cddce | 2012-06-13 00:01:22 +0200 | [diff] [blame] | 1303 | |
Jonas Ådahl | 62fcd04 | 2012-06-13 00:01:23 +0200 | [diff] [blame] | 1304 | if (shell->workspaces.anim_to != NULL) |
| 1305 | finish_workspace_change_animation(shell, |
| 1306 | shell->workspaces.anim_from, |
| 1307 | shell->workspaces.anim_to); |
| 1308 | |
Jonas Ådahl | 8de6a1d | 2012-08-29 22:13:00 +0200 | [diff] [blame] | 1309 | restore_focus_state(shell, to); |
Jonas Ådahl | 0476974 | 2012-06-13 00:01:24 +0200 | [diff] [blame] | 1310 | |
Louis-Francis Ratté-Boulianne | b482dbd | 2013-11-19 11:37:11 +0100 | [diff] [blame] | 1311 | if (shell->focus_animation_type != ANIMATION_NONE) { |
| 1312 | wl_list_for_each(state, &from->focus_list, link) |
| 1313 | if (state->keyboard_focus) |
| 1314 | animate_focus_change(shell, from, |
| 1315 | get_default_view(state->keyboard_focus), NULL); |
| 1316 | |
| 1317 | wl_list_for_each(state, &to->focus_list, link) |
| 1318 | if (state->keyboard_focus) |
| 1319 | animate_focus_change(shell, to, |
| 1320 | NULL, get_default_view(state->keyboard_focus)); |
| 1321 | } |
| 1322 | |
Jonas Ådahl | 8de6a1d | 2012-08-29 22:13:00 +0200 | [diff] [blame] | 1323 | if (workspace_is_empty(to) && workspace_is_empty(from)) |
| 1324 | update_workspace(shell, index, from, to); |
Jonas Ådahl | 62fcd04 | 2012-06-13 00:01:23 +0200 | [diff] [blame] | 1325 | else |
| 1326 | animate_workspace_change(shell, index, from, to); |
Jonas Ådahl | e9d2250 | 2012-08-29 22:13:01 +0200 | [diff] [blame] | 1327 | |
| 1328 | broadcast_current_workspace_state(shell); |
Pekka Paalanen | e955f1e | 2011-12-07 11:49:52 +0200 | [diff] [blame] | 1329 | } |
| 1330 | |
Jonas Ådahl | 8de6a1d | 2012-08-29 22:13:00 +0200 | [diff] [blame] | 1331 | static bool |
| 1332 | workspace_has_only(struct workspace *ws, struct weston_surface *surface) |
| 1333 | { |
Giulio Camuffo | 412e6a5 | 2014-07-09 22:12:56 +0300 | [diff] [blame] | 1334 | struct wl_list *list = &ws->layer.view_list.link; |
Jonas Ådahl | 8de6a1d | 2012-08-29 22:13:00 +0200 | [diff] [blame] | 1335 | struct wl_list *e; |
| 1336 | |
| 1337 | if (wl_list_empty(list)) |
| 1338 | return false; |
| 1339 | |
| 1340 | e = list->next; |
| 1341 | |
| 1342 | if (e->next != list) |
| 1343 | return false; |
| 1344 | |
Giulio Camuffo | 412e6a5 | 2014-07-09 22:12:56 +0300 | [diff] [blame] | 1345 | return container_of(e, struct weston_view, layer_link.link)->surface == surface; |
Jonas Ådahl | 8de6a1d | 2012-08-29 22:13:00 +0200 | [diff] [blame] | 1346 | } |
| 1347 | |
| 1348 | static void |
Philip Withnall | 659163d | 2013-11-25 18:01:36 +0000 | [diff] [blame] | 1349 | move_surface_to_workspace(struct desktop_shell *shell, |
| 1350 | struct shell_surface *shsurf, |
| 1351 | uint32_t workspace) |
Jonas Ådahl | e9d2250 | 2012-08-29 22:13:01 +0200 | [diff] [blame] | 1352 | { |
| 1353 | struct workspace *from; |
| 1354 | struct workspace *to; |
| 1355 | struct weston_seat *seat; |
Pekka Paalanen | 01388e2 | 2013-04-25 13:57:44 +0300 | [diff] [blame] | 1356 | struct weston_surface *focus; |
Philip Withnall | 659163d | 2013-11-25 18:01:36 +0000 | [diff] [blame] | 1357 | struct weston_view *view; |
Jonas Ådahl | e9d2250 | 2012-08-29 22:13:01 +0200 | [diff] [blame] | 1358 | |
| 1359 | if (workspace == shell->workspaces.current) |
| 1360 | return; |
| 1361 | |
Philip Withnall | 659163d | 2013-11-25 18:01:36 +0000 | [diff] [blame] | 1362 | view = get_default_view(shsurf->surface); |
| 1363 | if (!view) |
| 1364 | return; |
| 1365 | |
| 1366 | assert(weston_surface_get_main_surface(view->surface) == view->surface); |
| 1367 | |
Philipp Brüschweiler | 067abf6 | 2012-09-01 16:03:05 +0200 | [diff] [blame] | 1368 | if (workspace >= shell->workspaces.num) |
| 1369 | workspace = shell->workspaces.num - 1; |
| 1370 | |
Jonas Ådahl | e9d2250 | 2012-08-29 22:13:01 +0200 | [diff] [blame] | 1371 | from = get_current_workspace(shell); |
| 1372 | to = get_workspace(shell, workspace); |
| 1373 | |
Giulio Camuffo | 412e6a5 | 2014-07-09 22:12:56 +0300 | [diff] [blame] | 1374 | weston_layer_entry_remove(&view->layer_link); |
| 1375 | weston_layer_entry_insert(&to->layer.view_list, &view->layer_link); |
Jonas Ådahl | e9d2250 | 2012-08-29 22:13:01 +0200 | [diff] [blame] | 1376 | |
Philip Withnall | 648a4dd | 2013-11-25 18:01:44 +0000 | [diff] [blame] | 1377 | shell_surface_update_child_surface_layers(shsurf); |
| 1378 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 1379 | drop_focus_state(shell, from, view->surface); |
Pekka Paalanen | 01388e2 | 2013-04-25 13:57:44 +0300 | [diff] [blame] | 1380 | wl_list_for_each(seat, &shell->compositor->seat_list, link) { |
| 1381 | if (!seat->keyboard) |
| 1382 | continue; |
| 1383 | |
| 1384 | focus = weston_surface_get_main_surface(seat->keyboard->focus); |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 1385 | if (focus == view->surface) |
Kristian Høgsberg | e314875 | 2013-05-06 23:19:49 -0400 | [diff] [blame] | 1386 | weston_keyboard_set_focus(seat->keyboard, NULL); |
Pekka Paalanen | 01388e2 | 2013-04-25 13:57:44 +0300 | [diff] [blame] | 1387 | } |
Jonas Ådahl | e9d2250 | 2012-08-29 22:13:01 +0200 | [diff] [blame] | 1388 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 1389 | weston_view_damage_below(view); |
Jonas Ådahl | e9d2250 | 2012-08-29 22:13:01 +0200 | [diff] [blame] | 1390 | } |
| 1391 | |
| 1392 | static void |
Jonas Ådahl | 8de6a1d | 2012-08-29 22:13:00 +0200 | [diff] [blame] | 1393 | take_surface_to_workspace_by_seat(struct desktop_shell *shell, |
Kristian Høgsberg | e314875 | 2013-05-06 23:19:49 -0400 | [diff] [blame] | 1394 | struct weston_seat *seat, |
Jonas Ådahl | 8de6a1d | 2012-08-29 22:13:00 +0200 | [diff] [blame] | 1395 | unsigned int index) |
| 1396 | { |
Pekka Paalanen | 01388e2 | 2013-04-25 13:57:44 +0300 | [diff] [blame] | 1397 | struct weston_surface *surface; |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 1398 | struct weston_view *view; |
Jonas Ådahl | 8de6a1d | 2012-08-29 22:13:00 +0200 | [diff] [blame] | 1399 | struct shell_surface *shsurf; |
| 1400 | struct workspace *from; |
| 1401 | struct workspace *to; |
Jonas Ådahl | 8538b22 | 2012-08-29 22:13:03 +0200 | [diff] [blame] | 1402 | struct focus_state *state; |
Jonas Ådahl | 8de6a1d | 2012-08-29 22:13:00 +0200 | [diff] [blame] | 1403 | |
Pekka Paalanen | 01388e2 | 2013-04-25 13:57:44 +0300 | [diff] [blame] | 1404 | surface = weston_surface_get_main_surface(seat->keyboard->focus); |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 1405 | view = get_default_view(surface); |
| 1406 | if (view == NULL || |
Louis-Francis Ratté-Boulianne | b482dbd | 2013-11-19 11:37:11 +0100 | [diff] [blame] | 1407 | index == shell->workspaces.current || |
| 1408 | is_focus_view(view)) |
Jonas Ådahl | 8de6a1d | 2012-08-29 22:13:00 +0200 | [diff] [blame] | 1409 | return; |
| 1410 | |
| 1411 | from = get_current_workspace(shell); |
| 1412 | to = get_workspace(shell, index); |
| 1413 | |
Giulio Camuffo | 412e6a5 | 2014-07-09 22:12:56 +0300 | [diff] [blame] | 1414 | weston_layer_entry_remove(&view->layer_link); |
| 1415 | weston_layer_entry_insert(&to->layer.view_list, &view->layer_link); |
Jonas Ådahl | 8de6a1d | 2012-08-29 22:13:00 +0200 | [diff] [blame] | 1416 | |
Philip Withnall | 659163d | 2013-11-25 18:01:36 +0000 | [diff] [blame] | 1417 | shsurf = get_shell_surface(surface); |
Philip Withnall | 648a4dd | 2013-11-25 18:01:44 +0000 | [diff] [blame] | 1418 | if (shsurf != NULL) |
| 1419 | shell_surface_update_child_surface_layers(shsurf); |
Philip Withnall | 659163d | 2013-11-25 18:01:36 +0000 | [diff] [blame] | 1420 | |
Jonas Ådahl | e9d2250 | 2012-08-29 22:13:01 +0200 | [diff] [blame] | 1421 | replace_focus_state(shell, to, seat); |
Jonas Ådahl | 8de6a1d | 2012-08-29 22:13:00 +0200 | [diff] [blame] | 1422 | drop_focus_state(shell, from, surface); |
| 1423 | |
| 1424 | if (shell->workspaces.anim_from == to && |
| 1425 | shell->workspaces.anim_to == from) { |
Jonas Ådahl | e9d2250 | 2012-08-29 22:13:01 +0200 | [diff] [blame] | 1426 | wl_list_remove(&to->layer.link); |
| 1427 | wl_list_insert(from->layer.link.prev, &to->layer.link); |
| 1428 | |
Jonas Ådahl | 8de6a1d | 2012-08-29 22:13:00 +0200 | [diff] [blame] | 1429 | reverse_workspace_change_animation(shell, index, from, to); |
Jonas Ådahl | e9d2250 | 2012-08-29 22:13:01 +0200 | [diff] [blame] | 1430 | broadcast_current_workspace_state(shell); |
| 1431 | |
Jonas Ådahl | 8de6a1d | 2012-08-29 22:13:00 +0200 | [diff] [blame] | 1432 | return; |
| 1433 | } |
| 1434 | |
| 1435 | if (shell->workspaces.anim_to != NULL) |
| 1436 | finish_workspace_change_animation(shell, |
| 1437 | shell->workspaces.anim_from, |
| 1438 | shell->workspaces.anim_to); |
| 1439 | |
| 1440 | if (workspace_is_empty(from) && |
| 1441 | workspace_has_only(to, surface)) |
| 1442 | update_workspace(shell, index, from, to); |
| 1443 | else { |
Philip Withnall | 2c3849b | 2013-11-25 18:01:45 +0000 | [diff] [blame] | 1444 | if (shsurf != NULL && |
| 1445 | wl_list_empty(&shsurf->workspace_transform.link)) |
Jonas Ådahl | 8de6a1d | 2012-08-29 22:13:00 +0200 | [diff] [blame] | 1446 | wl_list_insert(&shell->workspaces.anim_sticky_list, |
| 1447 | &shsurf->workspace_transform.link); |
| 1448 | |
| 1449 | animate_workspace_change(shell, index, from, to); |
| 1450 | } |
Jonas Ådahl | e9d2250 | 2012-08-29 22:13:01 +0200 | [diff] [blame] | 1451 | |
| 1452 | broadcast_current_workspace_state(shell); |
Jonas Ådahl | 8538b22 | 2012-08-29 22:13:03 +0200 | [diff] [blame] | 1453 | |
| 1454 | state = ensure_focus_state(shell, seat); |
| 1455 | if (state != NULL) |
Kristian Høgsberg | d500bf1 | 2014-01-22 12:25:20 -0800 | [diff] [blame] | 1456 | focus_state_set_focus(state, surface); |
Jonas Ådahl | e9d2250 | 2012-08-29 22:13:01 +0200 | [diff] [blame] | 1457 | } |
| 1458 | |
| 1459 | static void |
| 1460 | workspace_manager_move_surface(struct wl_client *client, |
| 1461 | struct wl_resource *resource, |
| 1462 | struct wl_resource *surface_resource, |
| 1463 | uint32_t workspace) |
| 1464 | { |
Jason Ekstrand | 651f00e | 2013-06-14 10:07:54 -0500 | [diff] [blame] | 1465 | struct desktop_shell *shell = wl_resource_get_user_data(resource); |
Jonas Ådahl | e9d2250 | 2012-08-29 22:13:01 +0200 | [diff] [blame] | 1466 | struct weston_surface *surface = |
Jason Ekstrand | 0f2ef7e | 2013-06-14 10:07:53 -0500 | [diff] [blame] | 1467 | wl_resource_get_user_data(surface_resource); |
Pekka Paalanen | 01388e2 | 2013-04-25 13:57:44 +0300 | [diff] [blame] | 1468 | struct weston_surface *main_surface; |
Philip Withnall | 659163d | 2013-11-25 18:01:36 +0000 | [diff] [blame] | 1469 | struct shell_surface *shell_surface; |
Jonas Ådahl | e9d2250 | 2012-08-29 22:13:01 +0200 | [diff] [blame] | 1470 | |
Pekka Paalanen | 01388e2 | 2013-04-25 13:57:44 +0300 | [diff] [blame] | 1471 | main_surface = weston_surface_get_main_surface(surface); |
Philip Withnall | 659163d | 2013-11-25 18:01:36 +0000 | [diff] [blame] | 1472 | shell_surface = get_shell_surface(main_surface); |
| 1473 | if (shell_surface == NULL) |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 1474 | return; |
Philip Withnall | 659163d | 2013-11-25 18:01:36 +0000 | [diff] [blame] | 1475 | |
| 1476 | move_surface_to_workspace(shell, shell_surface, workspace); |
Jonas Ådahl | e9d2250 | 2012-08-29 22:13:01 +0200 | [diff] [blame] | 1477 | } |
| 1478 | |
| 1479 | static const struct workspace_manager_interface workspace_manager_implementation = { |
| 1480 | workspace_manager_move_surface, |
| 1481 | }; |
| 1482 | |
| 1483 | static void |
| 1484 | unbind_resource(struct wl_resource *resource) |
| 1485 | { |
Jason Ekstrand | 651f00e | 2013-06-14 10:07:54 -0500 | [diff] [blame] | 1486 | wl_list_remove(wl_resource_get_link(resource)); |
Jonas Ådahl | e9d2250 | 2012-08-29 22:13:01 +0200 | [diff] [blame] | 1487 | } |
| 1488 | |
| 1489 | static void |
| 1490 | bind_workspace_manager(struct wl_client *client, |
| 1491 | void *data, uint32_t version, uint32_t id) |
| 1492 | { |
| 1493 | struct desktop_shell *shell = data; |
| 1494 | struct wl_resource *resource; |
| 1495 | |
Jason Ekstrand | a85118c | 2013-06-27 20:17:02 -0500 | [diff] [blame] | 1496 | resource = wl_resource_create(client, |
| 1497 | &workspace_manager_interface, 1, id); |
Jonas Ådahl | e9d2250 | 2012-08-29 22:13:01 +0200 | [diff] [blame] | 1498 | |
| 1499 | if (resource == NULL) { |
| 1500 | weston_log("couldn't add workspace manager object"); |
| 1501 | return; |
| 1502 | } |
| 1503 | |
Jason Ekstrand | a85118c | 2013-06-27 20:17:02 -0500 | [diff] [blame] | 1504 | wl_resource_set_implementation(resource, |
| 1505 | &workspace_manager_implementation, |
| 1506 | shell, unbind_resource); |
Jason Ekstrand | 651f00e | 2013-06-14 10:07:54 -0500 | [diff] [blame] | 1507 | wl_list_insert(&shell->workspaces.client_list, |
| 1508 | wl_resource_get_link(resource)); |
Jonas Ådahl | e9d2250 | 2012-08-29 22:13:01 +0200 | [diff] [blame] | 1509 | |
| 1510 | workspace_manager_send_state(resource, |
| 1511 | shell->workspaces.current, |
| 1512 | shell->workspaces.num); |
Jonas Ådahl | 8de6a1d | 2012-08-29 22:13:00 +0200 | [diff] [blame] | 1513 | } |
| 1514 | |
Pekka Paalanen | 56cdea9 | 2011-11-23 16:14:12 +0200 | [diff] [blame] | 1515 | static void |
Rusty Lynch | 1084da5 | 2013-08-15 09:10:08 -0700 | [diff] [blame] | 1516 | touch_move_grab_down(struct weston_touch_grab *grab, uint32_t time, |
| 1517 | int touch_id, wl_fixed_t sx, wl_fixed_t sy) |
| 1518 | { |
| 1519 | } |
| 1520 | |
| 1521 | static void |
| 1522 | touch_move_grab_up(struct weston_touch_grab *grab, uint32_t time, int touch_id) |
| 1523 | { |
Jonas Ådahl | 1c6e63e | 2013-10-25 23:18:04 +0200 | [diff] [blame] | 1524 | struct weston_touch_move_grab *move = |
| 1525 | (struct weston_touch_move_grab *) container_of( |
| 1526 | grab, struct shell_touch_grab, grab); |
Neil Roberts | e14aa4f | 2013-10-03 16:43:07 +0100 | [diff] [blame] | 1527 | |
Kristian Høgsberg | 8e80a31 | 2014-01-17 15:18:10 -0800 | [diff] [blame] | 1528 | if (touch_id == 0) |
| 1529 | move->active = 0; |
| 1530 | |
Jonas Ådahl | 9484b69 | 2013-12-02 22:05:03 +0100 | [diff] [blame] | 1531 | if (grab->touch->num_tp == 0) { |
Jonas Ådahl | 1c6e63e | 2013-10-25 23:18:04 +0200 | [diff] [blame] | 1532 | shell_touch_grab_end(&move->base); |
| 1533 | free(move); |
| 1534 | } |
Rusty Lynch | 1084da5 | 2013-08-15 09:10:08 -0700 | [diff] [blame] | 1535 | } |
| 1536 | |
| 1537 | static void |
| 1538 | touch_move_grab_motion(struct weston_touch_grab *grab, uint32_t time, |
| 1539 | int touch_id, wl_fixed_t sx, wl_fixed_t sy) |
| 1540 | { |
| 1541 | struct weston_touch_move_grab *move = (struct weston_touch_move_grab *) grab; |
| 1542 | struct shell_surface *shsurf = move->base.shsurf; |
| 1543 | struct weston_surface *es; |
| 1544 | int dx = wl_fixed_to_int(grab->touch->grab_x + move->dx); |
| 1545 | int dy = wl_fixed_to_int(grab->touch->grab_y + move->dy); |
| 1546 | |
Kristian Høgsberg | 8e80a31 | 2014-01-17 15:18:10 -0800 | [diff] [blame] | 1547 | if (!shsurf || !move->active) |
Rusty Lynch | 1084da5 | 2013-08-15 09:10:08 -0700 | [diff] [blame] | 1548 | return; |
| 1549 | |
| 1550 | es = shsurf->surface; |
| 1551 | |
Jason Ekstrand | 918f2dd | 2013-12-02 21:01:53 -0600 | [diff] [blame] | 1552 | weston_view_set_position(shsurf->view, dx, dy); |
Rusty Lynch | 1084da5 | 2013-08-15 09:10:08 -0700 | [diff] [blame] | 1553 | |
| 1554 | weston_compositor_schedule_repaint(es->compositor); |
| 1555 | } |
| 1556 | |
Jonas Ådahl | 1ea343e | 2013-10-25 23:18:05 +0200 | [diff] [blame] | 1557 | static void |
Jonas Ådahl | 1679f23 | 2014-04-12 09:39:51 +0200 | [diff] [blame] | 1558 | touch_move_grab_frame(struct weston_touch_grab *grab) |
| 1559 | { |
| 1560 | } |
| 1561 | |
| 1562 | static void |
Jonas Ådahl | 1ea343e | 2013-10-25 23:18:05 +0200 | [diff] [blame] | 1563 | touch_move_grab_cancel(struct weston_touch_grab *grab) |
| 1564 | { |
| 1565 | struct weston_touch_move_grab *move = |
| 1566 | (struct weston_touch_move_grab *) container_of( |
| 1567 | grab, struct shell_touch_grab, grab); |
| 1568 | |
| 1569 | shell_touch_grab_end(&move->base); |
| 1570 | free(move); |
| 1571 | } |
| 1572 | |
Rusty Lynch | 1084da5 | 2013-08-15 09:10:08 -0700 | [diff] [blame] | 1573 | static const struct weston_touch_grab_interface touch_move_grab_interface = { |
| 1574 | touch_move_grab_down, |
| 1575 | touch_move_grab_up, |
| 1576 | touch_move_grab_motion, |
Jonas Ådahl | 1679f23 | 2014-04-12 09:39:51 +0200 | [diff] [blame] | 1577 | touch_move_grab_frame, |
Jonas Ådahl | 1ea343e | 2013-10-25 23:18:05 +0200 | [diff] [blame] | 1578 | touch_move_grab_cancel, |
Rusty Lynch | 1084da5 | 2013-08-15 09:10:08 -0700 | [diff] [blame] | 1579 | }; |
| 1580 | |
| 1581 | static int |
| 1582 | surface_touch_move(struct shell_surface *shsurf, struct weston_seat *seat) |
| 1583 | { |
| 1584 | struct weston_touch_move_grab *move; |
| 1585 | |
| 1586 | if (!shsurf) |
| 1587 | return -1; |
| 1588 | |
Ander Conselvan de Oliveira | 6d43f04 | 2014-05-07 14:22:23 +0300 | [diff] [blame] | 1589 | if (shsurf->state.fullscreen || shsurf->state.maximized) |
Rusty Lynch | 1084da5 | 2013-08-15 09:10:08 -0700 | [diff] [blame] | 1590 | return 0; |
| 1591 | |
| 1592 | move = malloc(sizeof *move); |
| 1593 | if (!move) |
| 1594 | return -1; |
| 1595 | |
Kristian Høgsberg | 8e80a31 | 2014-01-17 15:18:10 -0800 | [diff] [blame] | 1596 | move->active = 1; |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 1597 | move->dx = wl_fixed_from_double(shsurf->view->geometry.x) - |
Rusty Lynch | 1084da5 | 2013-08-15 09:10:08 -0700 | [diff] [blame] | 1598 | seat->touch->grab_x; |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 1599 | move->dy = wl_fixed_from_double(shsurf->view->geometry.y) - |
Rusty Lynch | 1084da5 | 2013-08-15 09:10:08 -0700 | [diff] [blame] | 1600 | seat->touch->grab_y; |
| 1601 | |
| 1602 | shell_touch_grab_start(&move->base, &touch_move_grab_interface, shsurf, |
| 1603 | seat->touch); |
| 1604 | |
| 1605 | return 0; |
| 1606 | } |
| 1607 | |
| 1608 | static void |
Kristian Høgsberg | 6848c25 | 2013-05-08 22:02:59 -0400 | [diff] [blame] | 1609 | noop_grab_focus(struct weston_pointer_grab *grab) |
Kristian Høgsberg | 9ddb826 | 2012-01-04 21:30:29 -0500 | [diff] [blame] | 1610 | { |
Kristian Høgsberg | 9ddb826 | 2012-01-04 21:30:29 -0500 | [diff] [blame] | 1611 | } |
| 1612 | |
| 1613 | static void |
Kristian Høgsberg | ae356ae | 2014-04-29 16:03:54 -0700 | [diff] [blame] | 1614 | constrain_position(struct weston_move_grab *move, int *cx, int *cy) |
| 1615 | { |
| 1616 | struct shell_surface *shsurf = move->base.shsurf; |
| 1617 | struct weston_pointer *pointer = move->base.grab.pointer; |
Jonny Lamb | d73c694 | 2014-08-20 15:53:20 +0200 | [diff] [blame] | 1618 | int x, y, panel_width, panel_height, bottom; |
Kristian Høgsberg | ae356ae | 2014-04-29 16:03:54 -0700 | [diff] [blame] | 1619 | const int safety = 50; |
| 1620 | |
| 1621 | x = wl_fixed_to_int(pointer->x + move->dx); |
| 1622 | y = wl_fixed_to_int(pointer->y + move->dy); |
| 1623 | |
Jonny Lamb | d73c694 | 2014-08-20 15:53:20 +0200 | [diff] [blame] | 1624 | if (shsurf->shell->panel_position == DESKTOP_SHELL_PANEL_POSITION_TOP) { |
| 1625 | get_output_panel_size(shsurf->shell, shsurf->surface->output, |
| 1626 | &panel_width, &panel_height); |
Kristian Høgsberg | ae356ae | 2014-04-29 16:03:54 -0700 | [diff] [blame] | 1627 | |
Jonny Lamb | d73c694 | 2014-08-20 15:53:20 +0200 | [diff] [blame] | 1628 | bottom = y + shsurf->geometry.height; |
| 1629 | if (bottom - panel_height < safety) |
| 1630 | y = panel_height + safety - |
| 1631 | shsurf->geometry.height; |
| 1632 | |
| 1633 | if (move->client_initiated && |
| 1634 | y + shsurf->geometry.y < panel_height) |
| 1635 | y = panel_height - shsurf->geometry.y; |
| 1636 | } |
Kristian Høgsberg | ae356ae | 2014-04-29 16:03:54 -0700 | [diff] [blame] | 1637 | |
| 1638 | *cx = x; |
| 1639 | *cy = y; |
| 1640 | } |
| 1641 | |
| 1642 | static void |
Giulio Camuffo | 1959ab8 | 2013-11-14 23:42:52 +0100 | [diff] [blame] | 1643 | move_grab_motion(struct weston_pointer_grab *grab, uint32_t time, |
| 1644 | wl_fixed_t x, wl_fixed_t y) |
Kristian Høgsberg | 4cca349 | 2011-01-18 07:53:49 -0500 | [diff] [blame] | 1645 | { |
Kristian Høgsberg | 8334bc1 | 2012-01-03 10:29:47 -0500 | [diff] [blame] | 1646 | struct weston_move_grab *move = (struct weston_move_grab *) grab; |
Kristian Høgsberg | 02bbabb | 2013-05-06 22:15:05 -0400 | [diff] [blame] | 1647 | struct weston_pointer *pointer = grab->pointer; |
Ander Conselvan de Oliveira | fe0444a | 2012-04-04 17:48:05 +0300 | [diff] [blame] | 1648 | struct shell_surface *shsurf = move->base.shsurf; |
Kristian Høgsberg | ae356ae | 2014-04-29 16:03:54 -0700 | [diff] [blame] | 1649 | int cx, cy; |
Giulio Camuffo | 1959ab8 | 2013-11-14 23:42:52 +0100 | [diff] [blame] | 1650 | |
| 1651 | weston_pointer_move(pointer, x, y); |
Ander Conselvan de Oliveira | fe0444a | 2012-04-04 17:48:05 +0300 | [diff] [blame] | 1652 | if (!shsurf) |
| 1653 | return; |
| 1654 | |
Kristian Høgsberg | ae356ae | 2014-04-29 16:03:54 -0700 | [diff] [blame] | 1655 | constrain_position(move, &cx, &cy); |
| 1656 | |
| 1657 | weston_view_set_position(shsurf->view, cx, cy); |
Kristian Høgsberg | 4cca349 | 2011-01-18 07:53:49 -0500 | [diff] [blame] | 1658 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 1659 | weston_compositor_schedule_repaint(shsurf->surface->compositor); |
Kristian Høgsberg | 4cca349 | 2011-01-18 07:53:49 -0500 | [diff] [blame] | 1660 | } |
| 1661 | |
| 1662 | static void |
Kristian Høgsberg | 02bbabb | 2013-05-06 22:15:05 -0400 | [diff] [blame] | 1663 | move_grab_button(struct weston_pointer_grab *grab, |
Daniel Stone | 4dbadb1 | 2012-05-30 16:31:51 +0100 | [diff] [blame] | 1664 | uint32_t time, uint32_t button, uint32_t state_w) |
Kristian Høgsberg | 4cca349 | 2011-01-18 07:53:49 -0500 | [diff] [blame] | 1665 | { |
Ander Conselvan de Oliveira | fe0444a | 2012-04-04 17:48:05 +0300 | [diff] [blame] | 1666 | struct shell_grab *shell_grab = container_of(grab, struct shell_grab, |
| 1667 | grab); |
Kristian Høgsberg | 02bbabb | 2013-05-06 22:15:05 -0400 | [diff] [blame] | 1668 | struct weston_pointer *pointer = grab->pointer; |
Daniel Stone | 4dbadb1 | 2012-05-30 16:31:51 +0100 | [diff] [blame] | 1669 | enum wl_pointer_button_state state = state_w; |
Kristian Høgsberg | 4cca349 | 2011-01-18 07:53:49 -0500 | [diff] [blame] | 1670 | |
Daniel Stone | 4dbadb1 | 2012-05-30 16:31:51 +0100 | [diff] [blame] | 1671 | if (pointer->button_count == 0 && |
| 1672 | state == WL_POINTER_BUTTON_STATE_RELEASED) { |
Ander Conselvan de Oliveira | b9d2a0f | 2012-06-28 18:08:05 +0300 | [diff] [blame] | 1673 | shell_grab_end(shell_grab); |
Kristian Høgsberg | 9ddb826 | 2012-01-04 21:30:29 -0500 | [diff] [blame] | 1674 | free(grab); |
| 1675 | } |
Kristian Høgsberg | 4cca349 | 2011-01-18 07:53:49 -0500 | [diff] [blame] | 1676 | } |
| 1677 | |
Jonas Ådahl | 1ea343e | 2013-10-25 23:18:05 +0200 | [diff] [blame] | 1678 | static void |
| 1679 | move_grab_cancel(struct weston_pointer_grab *grab) |
| 1680 | { |
| 1681 | struct shell_grab *shell_grab = |
| 1682 | container_of(grab, struct shell_grab, grab); |
| 1683 | |
| 1684 | shell_grab_end(shell_grab); |
| 1685 | free(grab); |
| 1686 | } |
| 1687 | |
Kristian Høgsberg | 02bbabb | 2013-05-06 22:15:05 -0400 | [diff] [blame] | 1688 | static const struct weston_pointer_grab_interface move_grab_interface = { |
Kristian Høgsberg | 9ddb826 | 2012-01-04 21:30:29 -0500 | [diff] [blame] | 1689 | noop_grab_focus, |
Kristian Høgsberg | 4cca349 | 2011-01-18 07:53:49 -0500 | [diff] [blame] | 1690 | move_grab_motion, |
| 1691 | move_grab_button, |
Jonas Ådahl | 1ea343e | 2013-10-25 23:18:05 +0200 | [diff] [blame] | 1692 | move_grab_cancel, |
Kristian Høgsberg | 4cca349 | 2011-01-18 07:53:49 -0500 | [diff] [blame] | 1693 | }; |
| 1694 | |
Kristian Høgsberg | 9e31bff | 2012-08-01 00:08:07 -0400 | [diff] [blame] | 1695 | static int |
Kristian Høgsberg | ae356ae | 2014-04-29 16:03:54 -0700 | [diff] [blame] | 1696 | surface_move(struct shell_surface *shsurf, struct weston_seat *seat, |
| 1697 | int client_initiated) |
Kristian Høgsberg | 9e31bff | 2012-08-01 00:08:07 -0400 | [diff] [blame] | 1698 | { |
| 1699 | struct weston_move_grab *move; |
| 1700 | |
| 1701 | if (!shsurf) |
| 1702 | return -1; |
| 1703 | |
Kristian Høgsberg | a4b620e | 2014-04-30 16:05:49 -0700 | [diff] [blame] | 1704 | if (shsurf->grabbed || |
| 1705 | shsurf->state.fullscreen || shsurf->state.maximized) |
Kristian Høgsberg | 9e31bff | 2012-08-01 00:08:07 -0400 | [diff] [blame] | 1706 | return 0; |
| 1707 | |
| 1708 | move = malloc(sizeof *move); |
| 1709 | if (!move) |
| 1710 | return -1; |
| 1711 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 1712 | move->dx = wl_fixed_from_double(shsurf->view->geometry.x) - |
Kristian Høgsberg | e314875 | 2013-05-06 23:19:49 -0400 | [diff] [blame] | 1713 | seat->pointer->grab_x; |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 1714 | move->dy = wl_fixed_from_double(shsurf->view->geometry.y) - |
Kristian Høgsberg | e314875 | 2013-05-06 23:19:49 -0400 | [diff] [blame] | 1715 | seat->pointer->grab_y; |
Kristian Høgsberg | ae356ae | 2014-04-29 16:03:54 -0700 | [diff] [blame] | 1716 | move->client_initiated = client_initiated; |
Kristian Høgsberg | 9e31bff | 2012-08-01 00:08:07 -0400 | [diff] [blame] | 1717 | |
| 1718 | shell_grab_start(&move->base, &move_grab_interface, shsurf, |
Kristian Høgsberg | e314875 | 2013-05-06 23:19:49 -0400 | [diff] [blame] | 1719 | seat->pointer, DESKTOP_SHELL_CURSOR_MOVE); |
Kristian Høgsberg | 9e31bff | 2012-08-01 00:08:07 -0400 | [diff] [blame] | 1720 | |
| 1721 | return 0; |
| 1722 | } |
| 1723 | |
| 1724 | static void |
Rafael Antognolli | e2a3455 | 2013-12-03 15:35:45 -0200 | [diff] [blame] | 1725 | common_surface_move(struct wl_resource *resource, |
| 1726 | struct wl_resource *seat_resource, uint32_t serial) |
Kristian Høgsberg | 9e31bff | 2012-08-01 00:08:07 -0400 | [diff] [blame] | 1727 | { |
Jason Ekstrand | 44a3863 | 2013-06-14 10:08:00 -0500 | [diff] [blame] | 1728 | struct weston_seat *seat = wl_resource_get_user_data(seat_resource); |
Jason Ekstrand | 651f00e | 2013-06-14 10:07:54 -0500 | [diff] [blame] | 1729 | struct shell_surface *shsurf = wl_resource_get_user_data(resource); |
Giulio Camuffo | 61da3fc | 2013-04-25 13:57:45 +0300 | [diff] [blame] | 1730 | struct weston_surface *surface; |
Kristian Høgsberg | 9e31bff | 2012-08-01 00:08:07 -0400 | [diff] [blame] | 1731 | |
Kristian Høgsberg | e1b655d | 2013-08-28 23:16:20 -0700 | [diff] [blame] | 1732 | if (seat->pointer && |
Kristian Høgsberg | 70f2901 | 2014-01-09 15:43:17 -0800 | [diff] [blame] | 1733 | seat->pointer->focus && |
Kristian Høgsberg | e1b655d | 2013-08-28 23:16:20 -0700 | [diff] [blame] | 1734 | seat->pointer->button_count > 0 && |
| 1735 | seat->pointer->grab_serial == serial) { |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 1736 | surface = weston_surface_get_main_surface(seat->pointer->focus->surface); |
U. Artie Eoff | cf5737a | 2014-01-17 10:08:25 -0800 | [diff] [blame] | 1737 | if ((surface == shsurf->surface) && |
Kristian Høgsberg | ae356ae | 2014-04-29 16:03:54 -0700 | [diff] [blame] | 1738 | (surface_move(shsurf, seat, 1) < 0)) |
Rusty Lynch | 1084da5 | 2013-08-15 09:10:08 -0700 | [diff] [blame] | 1739 | wl_resource_post_no_memory(resource); |
Kristian Høgsberg | e1b655d | 2013-08-28 23:16:20 -0700 | [diff] [blame] | 1740 | } else if (seat->touch && |
Kristian Høgsberg | 70f2901 | 2014-01-09 15:43:17 -0800 | [diff] [blame] | 1741 | seat->touch->focus && |
Kristian Høgsberg | e1b655d | 2013-08-28 23:16:20 -0700 | [diff] [blame] | 1742 | seat->touch->grab_serial == serial) { |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 1743 | surface = weston_surface_get_main_surface(seat->touch->focus->surface); |
U. Artie Eoff | cf5737a | 2014-01-17 10:08:25 -0800 | [diff] [blame] | 1744 | if ((surface == shsurf->surface) && |
Rusty Lynch | 1084da5 | 2013-08-15 09:10:08 -0700 | [diff] [blame] | 1745 | (surface_touch_move(shsurf, seat) < 0)) |
| 1746 | wl_resource_post_no_memory(resource); |
| 1747 | } |
Kristian Høgsberg | 9e31bff | 2012-08-01 00:08:07 -0400 | [diff] [blame] | 1748 | } |
| 1749 | |
Rafael Antognolli | e2a3455 | 2013-12-03 15:35:45 -0200 | [diff] [blame] | 1750 | static void |
| 1751 | shell_surface_move(struct wl_client *client, struct wl_resource *resource, |
| 1752 | struct wl_resource *seat_resource, uint32_t serial) |
| 1753 | { |
| 1754 | common_surface_move(resource, seat_resource, serial); |
| 1755 | } |
| 1756 | |
Kristian Høgsberg | 9e31bff | 2012-08-01 00:08:07 -0400 | [diff] [blame] | 1757 | struct weston_resize_grab { |
| 1758 | struct shell_grab base; |
| 1759 | uint32_t edges; |
| 1760 | int32_t width, height; |
| 1761 | }; |
| 1762 | |
| 1763 | static void |
Giulio Camuffo | 1959ab8 | 2013-11-14 23:42:52 +0100 | [diff] [blame] | 1764 | resize_grab_motion(struct weston_pointer_grab *grab, uint32_t time, |
| 1765 | wl_fixed_t x, wl_fixed_t y) |
Kristian Høgsberg | 9e31bff | 2012-08-01 00:08:07 -0400 | [diff] [blame] | 1766 | { |
| 1767 | struct weston_resize_grab *resize = (struct weston_resize_grab *) grab; |
Kristian Høgsberg | 02bbabb | 2013-05-06 22:15:05 -0400 | [diff] [blame] | 1768 | struct weston_pointer *pointer = grab->pointer; |
Kristian Høgsberg | 9e31bff | 2012-08-01 00:08:07 -0400 | [diff] [blame] | 1769 | struct shell_surface *shsurf = resize->base.shsurf; |
| 1770 | int32_t width, height; |
| 1771 | wl_fixed_t from_x, from_y; |
| 1772 | wl_fixed_t to_x, to_y; |
| 1773 | |
Giulio Camuffo | 1959ab8 | 2013-11-14 23:42:52 +0100 | [diff] [blame] | 1774 | weston_pointer_move(pointer, x, y); |
| 1775 | |
Kristian Høgsberg | e0b9d5b | 2014-04-30 13:45:49 -0700 | [diff] [blame] | 1776 | if (!shsurf) |
Kristian Høgsberg | 9e31bff | 2012-08-01 00:08:07 -0400 | [diff] [blame] | 1777 | return; |
| 1778 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 1779 | weston_view_from_global_fixed(shsurf->view, |
| 1780 | pointer->grab_x, pointer->grab_y, |
| 1781 | &from_x, &from_y); |
| 1782 | weston_view_from_global_fixed(shsurf->view, |
| 1783 | pointer->x, pointer->y, &to_x, &to_y); |
Kristian Høgsberg | 9e31bff | 2012-08-01 00:08:07 -0400 | [diff] [blame] | 1784 | |
| 1785 | width = resize->width; |
| 1786 | if (resize->edges & WL_SHELL_SURFACE_RESIZE_LEFT) { |
| 1787 | width += wl_fixed_to_int(from_x - to_x); |
| 1788 | } else if (resize->edges & WL_SHELL_SURFACE_RESIZE_RIGHT) { |
| 1789 | width += wl_fixed_to_int(to_x - from_x); |
| 1790 | } |
| 1791 | |
| 1792 | height = resize->height; |
| 1793 | if (resize->edges & WL_SHELL_SURFACE_RESIZE_TOP) { |
| 1794 | height += wl_fixed_to_int(from_y - to_y); |
| 1795 | } else if (resize->edges & WL_SHELL_SURFACE_RESIZE_BOTTOM) { |
| 1796 | height += wl_fixed_to_int(to_y - from_y); |
| 1797 | } |
| 1798 | |
Jasper St. Pierre | ac985be | 2014-04-28 11:19:28 -0400 | [diff] [blame] | 1799 | shsurf->client->send_configure(shsurf->surface, width, height); |
Kristian Høgsberg | 9e31bff | 2012-08-01 00:08:07 -0400 | [diff] [blame] | 1800 | } |
| 1801 | |
| 1802 | static void |
Jasper St. Pierre | ac985be | 2014-04-28 11:19:28 -0400 | [diff] [blame] | 1803 | 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] | 1804 | { |
| 1805 | struct shell_surface *shsurf = get_shell_surface(surface); |
| 1806 | |
U. Artie Eoff | cf5737a | 2014-01-17 10:08:25 -0800 | [diff] [blame] | 1807 | assert(shsurf); |
| 1808 | |
Kristian Høgsberg | e0b9d5b | 2014-04-30 13:45:49 -0700 | [diff] [blame] | 1809 | if (shsurf->resource) |
| 1810 | wl_shell_surface_send_configure(shsurf->resource, |
Jasper St. Pierre | ac985be | 2014-04-28 11:19:28 -0400 | [diff] [blame] | 1811 | shsurf->resize_edges, |
| 1812 | width, height); |
Kristian Høgsberg | 9e31bff | 2012-08-01 00:08:07 -0400 | [diff] [blame] | 1813 | } |
| 1814 | |
| 1815 | static const struct weston_shell_client shell_client = { |
| 1816 | send_configure |
| 1817 | }; |
| 1818 | |
| 1819 | static void |
Kristian Høgsberg | 02bbabb | 2013-05-06 22:15:05 -0400 | [diff] [blame] | 1820 | resize_grab_button(struct weston_pointer_grab *grab, |
Kristian Høgsberg | 9e31bff | 2012-08-01 00:08:07 -0400 | [diff] [blame] | 1821 | uint32_t time, uint32_t button, uint32_t state_w) |
| 1822 | { |
| 1823 | struct weston_resize_grab *resize = (struct weston_resize_grab *) grab; |
Kristian Høgsberg | 02bbabb | 2013-05-06 22:15:05 -0400 | [diff] [blame] | 1824 | struct weston_pointer *pointer = grab->pointer; |
Kristian Høgsberg | 9e31bff | 2012-08-01 00:08:07 -0400 | [diff] [blame] | 1825 | enum wl_pointer_button_state state = state_w; |
| 1826 | |
| 1827 | if (pointer->button_count == 0 && |
| 1828 | state == WL_POINTER_BUTTON_STATE_RELEASED) { |
| 1829 | shell_grab_end(&resize->base); |
| 1830 | free(grab); |
| 1831 | } |
| 1832 | } |
| 1833 | |
Jonas Ådahl | 1ea343e | 2013-10-25 23:18:05 +0200 | [diff] [blame] | 1834 | static void |
| 1835 | resize_grab_cancel(struct weston_pointer_grab *grab) |
| 1836 | { |
| 1837 | struct weston_resize_grab *resize = (struct weston_resize_grab *) grab; |
| 1838 | |
| 1839 | shell_grab_end(&resize->base); |
| 1840 | free(grab); |
| 1841 | } |
| 1842 | |
Kristian Høgsberg | 02bbabb | 2013-05-06 22:15:05 -0400 | [diff] [blame] | 1843 | static const struct weston_pointer_grab_interface resize_grab_interface = { |
Kristian Høgsberg | 9e31bff | 2012-08-01 00:08:07 -0400 | [diff] [blame] | 1844 | noop_grab_focus, |
| 1845 | resize_grab_motion, |
| 1846 | resize_grab_button, |
Jonas Ådahl | 1ea343e | 2013-10-25 23:18:05 +0200 | [diff] [blame] | 1847 | resize_grab_cancel, |
Kristian Høgsberg | 9e31bff | 2012-08-01 00:08:07 -0400 | [diff] [blame] | 1848 | }; |
| 1849 | |
Giulio Camuffo | b836664 | 2013-04-25 13:57:46 +0300 | [diff] [blame] | 1850 | /* |
| 1851 | * Returns the bounding box of a surface and all its sub-surfaces, |
| 1852 | * in the surface coordinates system. */ |
| 1853 | static void |
| 1854 | surface_subsurfaces_boundingbox(struct weston_surface *surface, int32_t *x, |
| 1855 | int32_t *y, int32_t *w, int32_t *h) { |
| 1856 | pixman_region32_t region; |
| 1857 | pixman_box32_t *box; |
| 1858 | struct weston_subsurface *subsurface; |
| 1859 | |
| 1860 | pixman_region32_init_rect(®ion, 0, 0, |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 1861 | surface->width, |
| 1862 | surface->height); |
Giulio Camuffo | b836664 | 2013-04-25 13:57:46 +0300 | [diff] [blame] | 1863 | |
| 1864 | wl_list_for_each(subsurface, &surface->subsurface_list, parent_link) { |
| 1865 | pixman_region32_union_rect(®ion, ®ion, |
| 1866 | subsurface->position.x, |
| 1867 | subsurface->position.y, |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 1868 | subsurface->surface->width, |
| 1869 | subsurface->surface->height); |
Giulio Camuffo | b836664 | 2013-04-25 13:57:46 +0300 | [diff] [blame] | 1870 | } |
| 1871 | |
| 1872 | box = pixman_region32_extents(®ion); |
| 1873 | if (x) |
| 1874 | *x = box->x1; |
| 1875 | if (y) |
| 1876 | *y = box->y1; |
| 1877 | if (w) |
| 1878 | *w = box->x2 - box->x1; |
| 1879 | if (h) |
| 1880 | *h = box->y2 - box->y1; |
| 1881 | |
| 1882 | pixman_region32_fini(®ion); |
| 1883 | } |
| 1884 | |
Kristian Høgsberg | 9e31bff | 2012-08-01 00:08:07 -0400 | [diff] [blame] | 1885 | static int |
| 1886 | surface_resize(struct shell_surface *shsurf, |
Kristian Høgsberg | e314875 | 2013-05-06 23:19:49 -0400 | [diff] [blame] | 1887 | struct weston_seat *seat, uint32_t edges) |
Kristian Høgsberg | 9e31bff | 2012-08-01 00:08:07 -0400 | [diff] [blame] | 1888 | { |
| 1889 | struct weston_resize_grab *resize; |
Ondřej Majerech | ae9c4fc | 2014-08-21 15:47:22 +0200 | [diff] [blame] | 1890 | const unsigned resize_topbottom = |
| 1891 | WL_SHELL_SURFACE_RESIZE_TOP | WL_SHELL_SURFACE_RESIZE_BOTTOM; |
| 1892 | const unsigned resize_leftright = |
| 1893 | WL_SHELL_SURFACE_RESIZE_LEFT | WL_SHELL_SURFACE_RESIZE_RIGHT; |
| 1894 | const unsigned resize_any = resize_topbottom | resize_leftright; |
Kristian Høgsberg | 9e31bff | 2012-08-01 00:08:07 -0400 | [diff] [blame] | 1895 | |
Kristian Høgsberg | a4b620e | 2014-04-30 16:05:49 -0700 | [diff] [blame] | 1896 | if (shsurf->grabbed || |
| 1897 | shsurf->state.fullscreen || shsurf->state.maximized) |
Kristian Høgsberg | 9e31bff | 2012-08-01 00:08:07 -0400 | [diff] [blame] | 1898 | return 0; |
| 1899 | |
Ondřej Majerech | ae9c4fc | 2014-08-21 15:47:22 +0200 | [diff] [blame] | 1900 | /* Check for invalid edge combinations. */ |
| 1901 | if (edges == WL_SHELL_SURFACE_RESIZE_NONE || edges > resize_any || |
| 1902 | (edges & resize_topbottom) == resize_topbottom || |
| 1903 | (edges & resize_leftright) == resize_leftright) |
Kristian Høgsberg | 9e31bff | 2012-08-01 00:08:07 -0400 | [diff] [blame] | 1904 | return 0; |
| 1905 | |
| 1906 | resize = malloc(sizeof *resize); |
| 1907 | if (!resize) |
| 1908 | return -1; |
| 1909 | |
| 1910 | resize->edges = edges; |
Kristian Høgsberg | 9e31bff | 2012-08-01 00:08:07 -0400 | [diff] [blame] | 1911 | |
Jasper St. Pierre | ccf48fb | 2014-05-02 10:21:38 -0400 | [diff] [blame] | 1912 | resize->width = shsurf->geometry.width; |
| 1913 | resize->height = shsurf->geometry.height; |
Jasper St. Pierre | bd65e50 | 2014-07-14 16:28:48 -0400 | [diff] [blame] | 1914 | |
Kristian Høgsberg | 44cd196 | 2014-02-05 21:36:04 -0800 | [diff] [blame] | 1915 | shsurf->resize_edges = edges; |
Jasper St. Pierre | 5befdda | 2014-05-06 08:50:47 -0400 | [diff] [blame] | 1916 | shell_surface_state_changed(shsurf); |
Kristian Høgsberg | 9e31bff | 2012-08-01 00:08:07 -0400 | [diff] [blame] | 1917 | shell_grab_start(&resize->base, &resize_grab_interface, shsurf, |
Kristian Høgsberg | e314875 | 2013-05-06 23:19:49 -0400 | [diff] [blame] | 1918 | seat->pointer, edges); |
Kristian Høgsberg | 9e31bff | 2012-08-01 00:08:07 -0400 | [diff] [blame] | 1919 | |
| 1920 | return 0; |
| 1921 | } |
| 1922 | |
| 1923 | static void |
Rafael Antognolli | e2a3455 | 2013-12-03 15:35:45 -0200 | [diff] [blame] | 1924 | common_surface_resize(struct wl_resource *resource, |
| 1925 | struct wl_resource *seat_resource, uint32_t serial, |
| 1926 | uint32_t edges) |
Kristian Høgsberg | 9e31bff | 2012-08-01 00:08:07 -0400 | [diff] [blame] | 1927 | { |
Jason Ekstrand | 44a3863 | 2013-06-14 10:08:00 -0500 | [diff] [blame] | 1928 | struct weston_seat *seat = wl_resource_get_user_data(seat_resource); |
Jason Ekstrand | 651f00e | 2013-06-14 10:07:54 -0500 | [diff] [blame] | 1929 | struct shell_surface *shsurf = wl_resource_get_user_data(resource); |
Giulio Camuffo | 61da3fc | 2013-04-25 13:57:45 +0300 | [diff] [blame] | 1930 | struct weston_surface *surface; |
Kristian Høgsberg | 9e31bff | 2012-08-01 00:08:07 -0400 | [diff] [blame] | 1931 | |
Emilio Pozuelo Monfort | 5872b68 | 2014-06-18 17:48:58 +0200 | [diff] [blame] | 1932 | if (seat->pointer == NULL || |
| 1933 | seat->pointer->button_count == 0 || |
Kristian Høgsberg | e314875 | 2013-05-06 23:19:49 -0400 | [diff] [blame] | 1934 | seat->pointer->grab_serial != serial || |
Kristian Høgsberg | 70f2901 | 2014-01-09 15:43:17 -0800 | [diff] [blame] | 1935 | seat->pointer->focus == NULL) |
| 1936 | return; |
| 1937 | |
| 1938 | surface = weston_surface_get_main_surface(seat->pointer->focus->surface); |
| 1939 | if (surface != shsurf->surface) |
Kristian Høgsberg | 9e31bff | 2012-08-01 00:08:07 -0400 | [diff] [blame] | 1940 | return; |
| 1941 | |
Kristian Høgsberg | e314875 | 2013-05-06 23:19:49 -0400 | [diff] [blame] | 1942 | if (surface_resize(shsurf, seat, edges) < 0) |
Kristian Høgsberg | 9e31bff | 2012-08-01 00:08:07 -0400 | [diff] [blame] | 1943 | wl_resource_post_no_memory(resource); |
| 1944 | } |
| 1945 | |
Scott Moreau | c3e54eb | 2012-04-17 19:06:20 -0600 | [diff] [blame] | 1946 | static void |
Rafael Antognolli | e2a3455 | 2013-12-03 15:35:45 -0200 | [diff] [blame] | 1947 | shell_surface_resize(struct wl_client *client, struct wl_resource *resource, |
| 1948 | struct wl_resource *seat_resource, uint32_t serial, |
| 1949 | uint32_t edges) |
| 1950 | { |
| 1951 | common_surface_resize(resource, seat_resource, serial, edges); |
| 1952 | } |
| 1953 | |
| 1954 | static void |
Kristian Høgsberg | 6848c25 | 2013-05-08 22:02:59 -0400 | [diff] [blame] | 1955 | busy_cursor_grab_focus(struct weston_pointer_grab *base) |
Scott Moreau | c3e54eb | 2012-04-17 19:06:20 -0600 | [diff] [blame] | 1956 | { |
Kristian Høgsberg | d56bd90 | 2012-06-05 09:58:51 -0400 | [diff] [blame] | 1957 | struct shell_grab *grab = (struct shell_grab *) base; |
Kristian Høgsberg | 6848c25 | 2013-05-08 22:02:59 -0400 | [diff] [blame] | 1958 | struct weston_pointer *pointer = base->pointer; |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 1959 | struct weston_view *view; |
Kristian Høgsberg | 6848c25 | 2013-05-08 22:02:59 -0400 | [diff] [blame] | 1960 | wl_fixed_t sx, sy; |
| 1961 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 1962 | view = weston_compositor_pick_view(pointer->seat->compositor, |
| 1963 | pointer->x, pointer->y, |
| 1964 | &sx, &sy); |
Scott Moreau | c3e54eb | 2012-04-17 19:06:20 -0600 | [diff] [blame] | 1965 | |
Kristian Høgsberg | 2bff94e | 2014-02-11 12:22:51 -0800 | [diff] [blame] | 1966 | if (!grab->shsurf || grab->shsurf->surface != view->surface) { |
| 1967 | shell_grab_end(grab); |
| 1968 | free(grab); |
| 1969 | } |
Scott Moreau | c3e54eb | 2012-04-17 19:06:20 -0600 | [diff] [blame] | 1970 | } |
| 1971 | |
| 1972 | static void |
Giulio Camuffo | 1959ab8 | 2013-11-14 23:42:52 +0100 | [diff] [blame] | 1973 | busy_cursor_grab_motion(struct weston_pointer_grab *grab, uint32_t time, |
| 1974 | wl_fixed_t x, wl_fixed_t y) |
Scott Moreau | c3e54eb | 2012-04-17 19:06:20 -0600 | [diff] [blame] | 1975 | { |
Giulio Camuffo | 1959ab8 | 2013-11-14 23:42:52 +0100 | [diff] [blame] | 1976 | weston_pointer_move(grab->pointer, x, y); |
Kristian Høgsberg | d56bd90 | 2012-06-05 09:58:51 -0400 | [diff] [blame] | 1977 | } |
Scott Moreau | c3e54eb | 2012-04-17 19:06:20 -0600 | [diff] [blame] | 1978 | |
Kristian Høgsberg | d56bd90 | 2012-06-05 09:58:51 -0400 | [diff] [blame] | 1979 | static void |
Kristian Høgsberg | 02bbabb | 2013-05-06 22:15:05 -0400 | [diff] [blame] | 1980 | busy_cursor_grab_button(struct weston_pointer_grab *base, |
Kristian Høgsberg | d56bd90 | 2012-06-05 09:58:51 -0400 | [diff] [blame] | 1981 | uint32_t time, uint32_t button, uint32_t state) |
| 1982 | { |
Kristian Høgsberg | bbe9839 | 2012-08-01 00:20:21 -0400 | [diff] [blame] | 1983 | struct shell_grab *grab = (struct shell_grab *) base; |
Kristian Høgsberg | e122b7b | 2013-05-08 16:47:00 -0400 | [diff] [blame] | 1984 | struct shell_surface *shsurf = grab->shsurf; |
Kristian Høgsberg | e314875 | 2013-05-06 23:19:49 -0400 | [diff] [blame] | 1985 | struct weston_seat *seat = grab->grab.pointer->seat; |
Kristian Høgsberg | bbe9839 | 2012-08-01 00:20:21 -0400 | [diff] [blame] | 1986 | |
Kristian Høgsberg | bbe9839 | 2012-08-01 00:20:21 -0400 | [diff] [blame] | 1987 | if (shsurf && button == BTN_LEFT && state) { |
Emilio Pozuelo Monfort | 9e7c759 | 2014-01-30 14:01:10 +0100 | [diff] [blame] | 1988 | activate(shsurf->shell, shsurf->surface, seat, true); |
Kristian Høgsberg | ae356ae | 2014-04-29 16:03:54 -0700 | [diff] [blame] | 1989 | surface_move(shsurf, seat, 0); |
Kristian Høgsberg | 0c36903 | 2013-02-14 21:31:44 -0500 | [diff] [blame] | 1990 | } else if (shsurf && button == BTN_RIGHT && state) { |
Emilio Pozuelo Monfort | 9e7c759 | 2014-01-30 14:01:10 +0100 | [diff] [blame] | 1991 | activate(shsurf->shell, shsurf->surface, seat, true); |
Kristian Høgsberg | e314875 | 2013-05-06 23:19:49 -0400 | [diff] [blame] | 1992 | surface_rotate(shsurf, seat); |
Kristian Høgsberg | bbe9839 | 2012-08-01 00:20:21 -0400 | [diff] [blame] | 1993 | } |
Kristian Høgsberg | d56bd90 | 2012-06-05 09:58:51 -0400 | [diff] [blame] | 1994 | } |
| 1995 | |
Jonas Ådahl | 1ea343e | 2013-10-25 23:18:05 +0200 | [diff] [blame] | 1996 | static void |
| 1997 | busy_cursor_grab_cancel(struct weston_pointer_grab *base) |
| 1998 | { |
| 1999 | struct shell_grab *grab = (struct shell_grab *) base; |
| 2000 | |
| 2001 | shell_grab_end(grab); |
| 2002 | free(grab); |
| 2003 | } |
| 2004 | |
Kristian Høgsberg | 02bbabb | 2013-05-06 22:15:05 -0400 | [diff] [blame] | 2005 | static const struct weston_pointer_grab_interface busy_cursor_grab_interface = { |
Kristian Høgsberg | d56bd90 | 2012-06-05 09:58:51 -0400 | [diff] [blame] | 2006 | busy_cursor_grab_focus, |
| 2007 | busy_cursor_grab_motion, |
| 2008 | busy_cursor_grab_button, |
Jonas Ådahl | 1ea343e | 2013-10-25 23:18:05 +0200 | [diff] [blame] | 2009 | busy_cursor_grab_cancel, |
Kristian Høgsberg | d56bd90 | 2012-06-05 09:58:51 -0400 | [diff] [blame] | 2010 | }; |
| 2011 | |
| 2012 | static void |
Kristian Høgsberg | 02bbabb | 2013-05-06 22:15:05 -0400 | [diff] [blame] | 2013 | set_busy_cursor(struct shell_surface *shsurf, struct weston_pointer *pointer) |
Kristian Høgsberg | d56bd90 | 2012-06-05 09:58:51 -0400 | [diff] [blame] | 2014 | { |
| 2015 | struct shell_grab *grab; |
Kristian Høgsberg | d56bd90 | 2012-06-05 09:58:51 -0400 | [diff] [blame] | 2016 | |
Kristian Høgsberg | 2bff94e | 2014-02-11 12:22:51 -0800 | [diff] [blame] | 2017 | if (pointer->grab->interface == &busy_cursor_grab_interface) |
| 2018 | return; |
| 2019 | |
Kristian Høgsberg | d56bd90 | 2012-06-05 09:58:51 -0400 | [diff] [blame] | 2020 | grab = malloc(sizeof *grab); |
| 2021 | if (!grab) |
Scott Moreau | c3e54eb | 2012-04-17 19:06:20 -0600 | [diff] [blame] | 2022 | return; |
| 2023 | |
Ander Conselvan de Oliveira | b9d2a0f | 2012-06-28 18:08:05 +0300 | [diff] [blame] | 2024 | shell_grab_start(grab, &busy_cursor_grab_interface, shsurf, pointer, |
| 2025 | DESKTOP_SHELL_CURSOR_BUSY); |
Ander Conselvan de Oliveira | e5a1aee | 2014-04-09 17:39:39 +0300 | [diff] [blame] | 2026 | /* Mark the shsurf as ungrabbed so that button binding is able |
| 2027 | * to move it. */ |
| 2028 | shsurf->grabbed = 0; |
Kristian Høgsberg | d56bd90 | 2012-06-05 09:58:51 -0400 | [diff] [blame] | 2029 | } |
Scott Moreau | c3e54eb | 2012-04-17 19:06:20 -0600 | [diff] [blame] | 2030 | |
Kristian Høgsberg | d56bd90 | 2012-06-05 09:58:51 -0400 | [diff] [blame] | 2031 | static void |
Kristian Høgsberg | 2bff94e | 2014-02-11 12:22:51 -0800 | [diff] [blame] | 2032 | end_busy_cursor(struct weston_compositor *compositor, struct wl_client *client) |
Kristian Høgsberg | d56bd90 | 2012-06-05 09:58:51 -0400 | [diff] [blame] | 2033 | { |
Kristian Høgsberg | 2bff94e | 2014-02-11 12:22:51 -0800 | [diff] [blame] | 2034 | struct shell_grab *grab; |
| 2035 | struct weston_seat *seat; |
Kristian Høgsberg | d56bd90 | 2012-06-05 09:58:51 -0400 | [diff] [blame] | 2036 | |
Kristian Høgsberg | 2bff94e | 2014-02-11 12:22:51 -0800 | [diff] [blame] | 2037 | wl_list_for_each(seat, &compositor->seat_list, link) { |
| 2038 | if (seat->pointer == NULL) |
| 2039 | continue; |
| 2040 | |
| 2041 | grab = (struct shell_grab *) seat->pointer->grab; |
| 2042 | if (grab->grab.interface == &busy_cursor_grab_interface && |
| 2043 | wl_resource_get_client(grab->shsurf->resource) == client) { |
| 2044 | shell_grab_end(grab); |
| 2045 | free(grab); |
| 2046 | } |
Scott Moreau | c3e54eb | 2012-04-17 19:06:20 -0600 | [diff] [blame] | 2047 | } |
Scott Moreau | c3e54eb | 2012-04-17 19:06:20 -0600 | [diff] [blame] | 2048 | } |
| 2049 | |
Scott Moreau | 9521d5e | 2012-04-19 13:06:17 -0600 | [diff] [blame] | 2050 | static void |
Kristian Høgsberg | 2bff94e | 2014-02-11 12:22:51 -0800 | [diff] [blame] | 2051 | handle_shell_client_destroy(struct wl_listener *listener, void *data); |
| 2052 | |
| 2053 | static int |
| 2054 | xdg_ping_timeout_handler(void *data) |
| 2055 | { |
| 2056 | struct shell_client *sc = data; |
| 2057 | struct weston_seat *seat; |
| 2058 | struct shell_surface *shsurf; |
| 2059 | |
| 2060 | /* Client is not responding */ |
| 2061 | sc->unresponsive = 1; |
Kristian Høgsberg | 2bff94e | 2014-02-11 12:22:51 -0800 | [diff] [blame] | 2062 | wl_list_for_each(seat, &sc->shell->compositor->seat_list, link) { |
| 2063 | if (seat->pointer == NULL || seat->pointer->focus == NULL) |
| 2064 | continue; |
| 2065 | if (seat->pointer->focus->surface->resource == NULL) |
| 2066 | continue; |
| 2067 | |
| 2068 | shsurf = get_shell_surface(seat->pointer->focus->surface); |
| 2069 | if (shsurf && |
| 2070 | wl_resource_get_client(shsurf->resource) == sc->client) |
| 2071 | set_busy_cursor(shsurf, seat->pointer); |
| 2072 | } |
| 2073 | |
| 2074 | return 1; |
| 2075 | } |
| 2076 | |
| 2077 | static void |
| 2078 | handle_xdg_ping(struct shell_surface *shsurf, uint32_t serial) |
| 2079 | { |
| 2080 | struct weston_compositor *compositor = shsurf->shell->compositor; |
Jason Ekstrand | 9e9512f | 2014-04-16 21:12:10 -0500 | [diff] [blame] | 2081 | struct shell_client *sc = shsurf->owner; |
Kristian Høgsberg | 2bff94e | 2014-02-11 12:22:51 -0800 | [diff] [blame] | 2082 | struct wl_event_loop *loop; |
Kristian Høgsberg | dd62aba | 2014-02-12 09:56:19 -0800 | [diff] [blame] | 2083 | static const int ping_timeout = 200; |
Kristian Høgsberg | 2bff94e | 2014-02-11 12:22:51 -0800 | [diff] [blame] | 2084 | |
Kristian Høgsberg | 2bff94e | 2014-02-11 12:22:51 -0800 | [diff] [blame] | 2085 | if (sc->unresponsive) { |
| 2086 | xdg_ping_timeout_handler(sc); |
| 2087 | return; |
| 2088 | } |
| 2089 | |
| 2090 | sc->ping_serial = serial; |
| 2091 | loop = wl_display_get_event_loop(compositor->wl_display); |
| 2092 | if (sc->ping_timer == NULL) |
| 2093 | sc->ping_timer = |
| 2094 | wl_event_loop_add_timer(loop, |
| 2095 | xdg_ping_timeout_handler, sc); |
| 2096 | if (sc->ping_timer == NULL) |
| 2097 | return; |
| 2098 | |
| 2099 | wl_event_source_timer_update(sc->ping_timer, ping_timeout); |
| 2100 | |
Kristian Høgsberg | dd62aba | 2014-02-12 09:56:19 -0800 | [diff] [blame] | 2101 | if (shell_surface_is_xdg_surface(shsurf) || |
| 2102 | shell_surface_is_xdg_popup(shsurf)) |
| 2103 | xdg_shell_send_ping(sc->resource, serial); |
| 2104 | else if (shell_surface_is_wl_shell_surface(shsurf)) |
| 2105 | wl_shell_surface_send_ping(shsurf->resource, serial); |
Kristian Høgsberg | 2bff94e | 2014-02-11 12:22:51 -0800 | [diff] [blame] | 2106 | } |
| 2107 | |
Scott Moreau | ff1db4a | 2012-04-17 19:06:18 -0600 | [diff] [blame] | 2108 | static void |
| 2109 | ping_handler(struct weston_surface *surface, uint32_t serial) |
| 2110 | { |
Kristian Høgsberg | b71302e | 2012-05-10 12:28:35 -0400 | [diff] [blame] | 2111 | struct shell_surface *shsurf = get_shell_surface(surface); |
Scott Moreau | ff1db4a | 2012-04-17 19:06:18 -0600 | [diff] [blame] | 2112 | |
| 2113 | if (!shsurf) |
| 2114 | return; |
Jason Ekstrand | 651f00e | 2013-06-14 10:07:54 -0500 | [diff] [blame] | 2115 | if (!shsurf->resource) |
Kristian Høgsberg | ca535c1 | 2012-04-21 23:20:07 -0400 | [diff] [blame] | 2116 | return; |
Ander Conselvan de Oliveira | eac9a46 | 2012-07-16 14:15:48 +0300 | [diff] [blame] | 2117 | if (shsurf->surface == shsurf->shell->grab_surface) |
| 2118 | return; |
| 2119 | |
Kristian Høgsberg | dd62aba | 2014-02-12 09:56:19 -0800 | [diff] [blame] | 2120 | handle_xdg_ping(shsurf, serial); |
Scott Moreau | ff1db4a | 2012-04-17 19:06:18 -0600 | [diff] [blame] | 2121 | } |
| 2122 | |
| 2123 | static void |
Kristian Høgsberg | d56bd90 | 2012-06-05 09:58:51 -0400 | [diff] [blame] | 2124 | handle_pointer_focus(struct wl_listener *listener, void *data) |
| 2125 | { |
Kristian Høgsberg | 02bbabb | 2013-05-06 22:15:05 -0400 | [diff] [blame] | 2126 | struct weston_pointer *pointer = data; |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 2127 | struct weston_view *view = pointer->focus; |
Kristian Høgsberg | d56bd90 | 2012-06-05 09:58:51 -0400 | [diff] [blame] | 2128 | struct weston_compositor *compositor; |
Kristian Høgsberg | d56bd90 | 2012-06-05 09:58:51 -0400 | [diff] [blame] | 2129 | uint32_t serial; |
| 2130 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 2131 | if (!view) |
Kristian Høgsberg | d56bd90 | 2012-06-05 09:58:51 -0400 | [diff] [blame] | 2132 | return; |
| 2133 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 2134 | compositor = view->surface->compositor; |
Kristian Høgsberg | e11ef64 | 2014-02-11 16:35:22 -0800 | [diff] [blame] | 2135 | serial = wl_display_next_serial(compositor->wl_display); |
| 2136 | ping_handler(view->surface, serial); |
Kristian Høgsberg | d56bd90 | 2012-06-05 09:58:51 -0400 | [diff] [blame] | 2137 | } |
| 2138 | |
| 2139 | static void |
Jasper St. Pierre | faf27a9 | 2013-12-09 17:36:28 -0500 | [diff] [blame] | 2140 | shell_surface_lose_keyboard_focus(struct shell_surface *shsurf) |
| 2141 | { |
| 2142 | if (--shsurf->focus_count == 0) |
Jasper St. Pierre | 973d787 | 2014-05-06 08:44:29 -0400 | [diff] [blame] | 2143 | shell_surface_state_changed(shsurf); |
Jasper St. Pierre | faf27a9 | 2013-12-09 17:36:28 -0500 | [diff] [blame] | 2144 | } |
| 2145 | |
| 2146 | static void |
| 2147 | shell_surface_gain_keyboard_focus(struct shell_surface *shsurf) |
| 2148 | { |
| 2149 | if (shsurf->focus_count++ == 0) |
Jasper St. Pierre | 973d787 | 2014-05-06 08:44:29 -0400 | [diff] [blame] | 2150 | shell_surface_state_changed(shsurf); |
Jasper St. Pierre | faf27a9 | 2013-12-09 17:36:28 -0500 | [diff] [blame] | 2151 | } |
| 2152 | |
| 2153 | static void |
| 2154 | handle_keyboard_focus(struct wl_listener *listener, void *data) |
| 2155 | { |
| 2156 | struct weston_keyboard *keyboard = data; |
| 2157 | struct shell_seat *seat = get_shell_seat(keyboard->seat); |
| 2158 | |
| 2159 | if (seat->focused_surface) { |
| 2160 | struct shell_surface *shsurf = get_shell_surface(seat->focused_surface); |
| 2161 | if (shsurf) |
| 2162 | shell_surface_lose_keyboard_focus(shsurf); |
| 2163 | } |
| 2164 | |
| 2165 | seat->focused_surface = keyboard->focus; |
| 2166 | |
| 2167 | if (seat->focused_surface) { |
| 2168 | struct shell_surface *shsurf = get_shell_surface(seat->focused_surface); |
| 2169 | if (shsurf) |
| 2170 | shell_surface_gain_keyboard_focus(shsurf); |
| 2171 | } |
| 2172 | } |
| 2173 | |
| 2174 | static void |
Kristian Høgsberg | dd62aba | 2014-02-12 09:56:19 -0800 | [diff] [blame] | 2175 | shell_client_pong(struct shell_client *sc, uint32_t serial) |
Rafael Antognolli | e2a3455 | 2013-12-03 15:35:45 -0200 | [diff] [blame] | 2176 | { |
Kristian Høgsberg | dd62aba | 2014-02-12 09:56:19 -0800 | [diff] [blame] | 2177 | if (sc->ping_serial != serial) |
| 2178 | return; |
Rafael Antognolli | e2a3455 | 2013-12-03 15:35:45 -0200 | [diff] [blame] | 2179 | |
Kristian Høgsberg | dd62aba | 2014-02-12 09:56:19 -0800 | [diff] [blame] | 2180 | sc->unresponsive = 0; |
| 2181 | end_busy_cursor(sc->shell->compositor, sc->client); |
Rafael Antognolli | e2a3455 | 2013-12-03 15:35:45 -0200 | [diff] [blame] | 2182 | |
Kristian Høgsberg | dd62aba | 2014-02-12 09:56:19 -0800 | [diff] [blame] | 2183 | if (sc->ping_timer) { |
| 2184 | wl_event_source_remove(sc->ping_timer); |
| 2185 | sc->ping_timer = NULL; |
| 2186 | } |
| 2187 | |
| 2188 | } |
| 2189 | |
| 2190 | static void |
| 2191 | shell_surface_pong(struct wl_client *client, |
| 2192 | struct wl_resource *resource, uint32_t serial) |
| 2193 | { |
Jason Ekstrand | 9e9512f | 2014-04-16 21:12:10 -0500 | [diff] [blame] | 2194 | struct shell_surface *shsurf = wl_resource_get_user_data(resource); |
| 2195 | struct shell_client *sc = shsurf->owner; |
Kristian Høgsberg | dd62aba | 2014-02-12 09:56:19 -0800 | [diff] [blame] | 2196 | |
Kristian Høgsberg | dd62aba | 2014-02-12 09:56:19 -0800 | [diff] [blame] | 2197 | shell_client_pong(sc, serial); |
Rafael Antognolli | e2a3455 | 2013-12-03 15:35:45 -0200 | [diff] [blame] | 2198 | } |
| 2199 | |
| 2200 | static void |
Giulio Camuffo | 62942ad | 2013-09-11 18:20:47 +0200 | [diff] [blame] | 2201 | set_title(struct shell_surface *shsurf, const char *title) |
| 2202 | { |
| 2203 | free(shsurf->title); |
| 2204 | shsurf->title = strdup(title); |
| 2205 | } |
| 2206 | |
| 2207 | static void |
Jasper St. Pierre | ccf48fb | 2014-05-02 10:21:38 -0400 | [diff] [blame] | 2208 | set_window_geometry(struct shell_surface *shsurf, |
| 2209 | 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] | 2210 | { |
Jasper St. Pierre | ccf48fb | 2014-05-02 10:21:38 -0400 | [diff] [blame] | 2211 | shsurf->next_geometry.x = x; |
| 2212 | shsurf->next_geometry.y = y; |
| 2213 | shsurf->next_geometry.width = width; |
| 2214 | shsurf->next_geometry.height = height; |
| 2215 | shsurf->has_next_geometry = true; |
Kristian Høgsberg | e5c1ae9 | 2014-04-30 16:28:41 -0700 | [diff] [blame] | 2216 | } |
| 2217 | |
| 2218 | static void |
Kristian Høgsberg | e7afd91 | 2012-05-02 09:47:44 -0400 | [diff] [blame] | 2219 | shell_surface_set_title(struct wl_client *client, |
| 2220 | struct wl_resource *resource, const char *title) |
| 2221 | { |
Jason Ekstrand | 651f00e | 2013-06-14 10:07:54 -0500 | [diff] [blame] | 2222 | struct shell_surface *shsurf = wl_resource_get_user_data(resource); |
Kristian Høgsberg | e7afd91 | 2012-05-02 09:47:44 -0400 | [diff] [blame] | 2223 | |
Giulio Camuffo | 62942ad | 2013-09-11 18:20:47 +0200 | [diff] [blame] | 2224 | set_title(shsurf, title); |
Kristian Høgsberg | e7afd91 | 2012-05-02 09:47:44 -0400 | [diff] [blame] | 2225 | } |
| 2226 | |
| 2227 | static void |
| 2228 | shell_surface_set_class(struct wl_client *client, |
| 2229 | struct wl_resource *resource, const char *class) |
| 2230 | { |
Jason Ekstrand | 651f00e | 2013-06-14 10:07:54 -0500 | [diff] [blame] | 2231 | struct shell_surface *shsurf = wl_resource_get_user_data(resource); |
Kristian Høgsberg | e7afd91 | 2012-05-02 09:47:44 -0400 | [diff] [blame] | 2232 | |
| 2233 | free(shsurf->class); |
| 2234 | shsurf->class = strdup(class); |
| 2235 | } |
| 2236 | |
Alex Wu | 4539b08 | 2012-03-01 12:57:46 +0800 | [diff] [blame] | 2237 | static void |
Alexander Larsson | f82b6ca | 2013-05-28 16:23:39 +0200 | [diff] [blame] | 2238 | restore_output_mode(struct weston_output *output) |
| 2239 | { |
Hardening | 57388e4 | 2013-09-18 23:56:36 +0200 | [diff] [blame] | 2240 | if (output->current_mode != output->original_mode || |
| 2241 | (int32_t)output->current_scale != output->original_scale) |
Alexander Larsson | f82b6ca | 2013-05-28 16:23:39 +0200 | [diff] [blame] | 2242 | weston_output_switch_mode(output, |
Hardening | 57388e4 | 2013-09-18 23:56:36 +0200 | [diff] [blame] | 2243 | output->original_mode, |
| 2244 | output->original_scale, |
| 2245 | WESTON_MODE_SWITCH_RESTORE_NATIVE); |
Alexander Larsson | f82b6ca | 2013-05-28 16:23:39 +0200 | [diff] [blame] | 2246 | } |
| 2247 | |
| 2248 | static void |
| 2249 | restore_all_output_modes(struct weston_compositor *compositor) |
| 2250 | { |
| 2251 | struct weston_output *output; |
| 2252 | |
| 2253 | wl_list_for_each(output, &compositor->output_list, link) |
| 2254 | restore_output_mode(output); |
| 2255 | } |
| 2256 | |
Philip Withnall | 07926d9 | 2013-11-25 18:01:40 +0000 | [diff] [blame] | 2257 | /* The surface will be inserted into the list immediately after the link |
| 2258 | * returned by this function (i.e. will be stacked immediately above the |
| 2259 | * returned link). */ |
Giulio Camuffo | 412e6a5 | 2014-07-09 22:12:56 +0300 | [diff] [blame] | 2260 | static struct weston_layer_entry * |
Philip Withnall | 07926d9 | 2013-11-25 18:01:40 +0000 | [diff] [blame] | 2261 | shell_surface_calculate_layer_link (struct shell_surface *shsurf) |
| 2262 | { |
| 2263 | struct workspace *ws; |
Kristian Høgsberg | ead5242 | 2014-01-01 13:51:52 -0800 | [diff] [blame] | 2264 | struct weston_view *parent; |
Philip Withnall | 07926d9 | 2013-11-25 18:01:40 +0000 | [diff] [blame] | 2265 | |
| 2266 | switch (shsurf->type) { |
Ander Conselvan de Oliveira | ef6a7e4 | 2014-04-30 14:15:14 +0300 | [diff] [blame] | 2267 | case SHELL_SURFACE_XWAYLAND: |
| 2268 | return &shsurf->shell->fullscreen_layer.view_list; |
| 2269 | |
| 2270 | case SHELL_SURFACE_NONE: |
| 2271 | return NULL; |
| 2272 | |
Kristian Høgsberg | ead5242 | 2014-01-01 13:51:52 -0800 | [diff] [blame] | 2273 | case SHELL_SURFACE_POPUP: |
| 2274 | case SHELL_SURFACE_TOPLEVEL: |
Emilio Pozuelo Monfort | 9e7c759 | 2014-01-30 14:01:10 +0100 | [diff] [blame] | 2275 | if (shsurf->state.fullscreen && !shsurf->state.lowered) { |
Rafael Antognolli | 03b1659 | 2013-12-03 15:35:42 -0200 | [diff] [blame] | 2276 | return &shsurf->shell->fullscreen_layer.view_list; |
Rafael Antognolli | ed207b4 | 2013-12-03 15:35:43 -0200 | [diff] [blame] | 2277 | } else if (shsurf->parent) { |
Kristian Høgsberg | d55db69 | 2014-01-01 12:26:14 -0800 | [diff] [blame] | 2278 | /* Move the surface to its parent layer so |
| 2279 | * that surfaces which are transient for |
| 2280 | * fullscreen surfaces don't get hidden by the |
| 2281 | * fullscreen surfaces. */ |
Rafael Antognolli | ed207b4 | 2013-12-03 15:35:43 -0200 | [diff] [blame] | 2282 | |
| 2283 | /* TODO: Handle a parent with multiple views */ |
| 2284 | parent = get_default_view(shsurf->parent); |
| 2285 | if (parent) |
Giulio Camuffo | 412e6a5 | 2014-07-09 22:12:56 +0300 | [diff] [blame] | 2286 | return container_of(parent->layer_link.link.prev, |
| 2287 | struct weston_layer_entry, link); |
Rafael Antognolli | ed207b4 | 2013-12-03 15:35:43 -0200 | [diff] [blame] | 2288 | } |
Philip Withnall | 07926d9 | 2013-11-25 18:01:40 +0000 | [diff] [blame] | 2289 | |
Ander Conselvan de Oliveira | ef6a7e4 | 2014-04-30 14:15:14 +0300 | [diff] [blame] | 2290 | /* Move the surface to a normal workspace layer so that surfaces |
| 2291 | * which were previously fullscreen or transient are no longer |
| 2292 | * rendered on top. */ |
| 2293 | ws = get_current_workspace(shsurf->shell); |
| 2294 | return &ws->layer.view_list; |
Philip Withnall | 07926d9 | 2013-11-25 18:01:40 +0000 | [diff] [blame] | 2295 | } |
| 2296 | |
Ander Conselvan de Oliveira | ef6a7e4 | 2014-04-30 14:15:14 +0300 | [diff] [blame] | 2297 | assert(0 && "Unknown shell surface type"); |
Philip Withnall | 07926d9 | 2013-11-25 18:01:40 +0000 | [diff] [blame] | 2298 | } |
| 2299 | |
Philip Withnall | 648a4dd | 2013-11-25 18:01:44 +0000 | [diff] [blame] | 2300 | static void |
| 2301 | shell_surface_update_child_surface_layers (struct shell_surface *shsurf) |
| 2302 | { |
| 2303 | struct shell_surface *child; |
Giulio Camuffo | 412e6a5 | 2014-07-09 22:12:56 +0300 | [diff] [blame] | 2304 | struct weston_layer_entry *prev; |
Philip Withnall | 648a4dd | 2013-11-25 18:01:44 +0000 | [diff] [blame] | 2305 | |
| 2306 | /* Move the child layers to the same workspace as shsurf. They will be |
| 2307 | * stacked above shsurf. */ |
| 2308 | wl_list_for_each_reverse(child, &shsurf->children_list, children_link) { |
Giulio Camuffo | 412e6a5 | 2014-07-09 22:12:56 +0300 | [diff] [blame] | 2309 | 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] | 2310 | weston_view_damage_below(child->view); |
Philip Withnall | 648a4dd | 2013-11-25 18:01:44 +0000 | [diff] [blame] | 2311 | weston_view_geometry_dirty(child->view); |
Giulio Camuffo | 412e6a5 | 2014-07-09 22:12:56 +0300 | [diff] [blame] | 2312 | prev = container_of(shsurf->view->layer_link.link.prev, |
| 2313 | struct weston_layer_entry, link); |
| 2314 | weston_layer_entry_remove(&child->view->layer_link); |
| 2315 | weston_layer_entry_insert(prev, |
| 2316 | &child->view->layer_link); |
Philip Withnall | 648a4dd | 2013-11-25 18:01:44 +0000 | [diff] [blame] | 2317 | weston_view_geometry_dirty(child->view); |
| 2318 | weston_surface_damage(child->surface); |
| 2319 | |
| 2320 | /* Recurse. We don’t expect this to recurse very far (if |
| 2321 | * at all) because that would imply we have transient |
| 2322 | * (or popup) children of transient surfaces, which |
| 2323 | * would be unusual. */ |
| 2324 | shell_surface_update_child_surface_layers(child); |
| 2325 | } |
| 2326 | } |
| 2327 | } |
| 2328 | |
Philip Withnall | e1d75ae | 2013-11-25 18:01:41 +0000 | [diff] [blame] | 2329 | /* 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] | 2330 | * geometry to ensure the changes are redrawn. |
| 2331 | * |
| 2332 | * If any child surfaces exist and are mapped, ensure they’re in the same layer |
| 2333 | * as this surface. */ |
Philip Withnall | e1d75ae | 2013-11-25 18:01:41 +0000 | [diff] [blame] | 2334 | static void |
| 2335 | shell_surface_update_layer(struct shell_surface *shsurf) |
| 2336 | { |
Giulio Camuffo | 412e6a5 | 2014-07-09 22:12:56 +0300 | [diff] [blame] | 2337 | struct weston_layer_entry *new_layer_link; |
Philip Withnall | e1d75ae | 2013-11-25 18:01:41 +0000 | [diff] [blame] | 2338 | |
| 2339 | new_layer_link = shell_surface_calculate_layer_link(shsurf); |
| 2340 | |
Ander Conselvan de Oliveira | ef6a7e4 | 2014-04-30 14:15:14 +0300 | [diff] [blame] | 2341 | if (new_layer_link == NULL) |
| 2342 | return; |
Philip Withnall | e1d75ae | 2013-11-25 18:01:41 +0000 | [diff] [blame] | 2343 | if (new_layer_link == &shsurf->view->layer_link) |
| 2344 | return; |
| 2345 | |
| 2346 | weston_view_geometry_dirty(shsurf->view); |
Giulio Camuffo | 412e6a5 | 2014-07-09 22:12:56 +0300 | [diff] [blame] | 2347 | weston_layer_entry_remove(&shsurf->view->layer_link); |
| 2348 | weston_layer_entry_insert(new_layer_link, &shsurf->view->layer_link); |
Philip Withnall | e1d75ae | 2013-11-25 18:01:41 +0000 | [diff] [blame] | 2349 | weston_view_geometry_dirty(shsurf->view); |
| 2350 | weston_surface_damage(shsurf->surface); |
Philip Withnall | 648a4dd | 2013-11-25 18:01:44 +0000 | [diff] [blame] | 2351 | |
| 2352 | shell_surface_update_child_surface_layers(shsurf); |
Philip Withnall | e1d75ae | 2013-11-25 18:01:41 +0000 | [diff] [blame] | 2353 | } |
| 2354 | |
Alexander Larsson | f82b6ca | 2013-05-28 16:23:39 +0200 | [diff] [blame] | 2355 | static void |
Philip Withnall | dc4332f | 2013-11-25 18:01:38 +0000 | [diff] [blame] | 2356 | shell_surface_set_parent(struct shell_surface *shsurf, |
| 2357 | struct weston_surface *parent) |
| 2358 | { |
| 2359 | shsurf->parent = parent; |
Philip Withnall | 648a4dd | 2013-11-25 18:01:44 +0000 | [diff] [blame] | 2360 | |
| 2361 | wl_list_remove(&shsurf->children_link); |
| 2362 | wl_list_init(&shsurf->children_link); |
| 2363 | |
| 2364 | /* Insert into the parent surface’s child list. */ |
| 2365 | if (parent != NULL) { |
| 2366 | struct shell_surface *parent_shsurf = get_shell_surface(parent); |
| 2367 | if (parent_shsurf != NULL) |
| 2368 | wl_list_insert(&parent_shsurf->children_list, |
| 2369 | &shsurf->children_link); |
| 2370 | } |
Philip Withnall | dc4332f | 2013-11-25 18:01:38 +0000 | [diff] [blame] | 2371 | } |
| 2372 | |
| 2373 | static void |
Philip Withnall | 352e7ed | 2013-11-25 18:01:35 +0000 | [diff] [blame] | 2374 | shell_surface_set_output(struct shell_surface *shsurf, |
| 2375 | struct weston_output *output) |
| 2376 | { |
| 2377 | struct weston_surface *es = shsurf->surface; |
| 2378 | |
| 2379 | /* get the default output, if the client set it as NULL |
| 2380 | check whether the ouput is available */ |
| 2381 | if (output) |
| 2382 | shsurf->output = output; |
| 2383 | else if (es->output) |
| 2384 | shsurf->output = es->output; |
| 2385 | else |
| 2386 | shsurf->output = get_default_output(es->compositor); |
| 2387 | } |
| 2388 | |
| 2389 | static void |
Rafael Antognolli | 03b1659 | 2013-12-03 15:35:42 -0200 | [diff] [blame] | 2390 | surface_clear_next_states(struct shell_surface *shsurf) |
| 2391 | { |
| 2392 | shsurf->next_state.maximized = false; |
| 2393 | shsurf->next_state.fullscreen = false; |
| 2394 | |
| 2395 | if ((shsurf->next_state.maximized != shsurf->state.maximized) || |
| 2396 | (shsurf->next_state.fullscreen != shsurf->state.fullscreen)) |
| 2397 | shsurf->state_changed = true; |
| 2398 | } |
| 2399 | |
| 2400 | static void |
Philip Withnall | becb77e | 2013-11-25 18:01:30 +0000 | [diff] [blame] | 2401 | set_toplevel(struct shell_surface *shsurf) |
| 2402 | { |
Kristian Høgsberg | 41fbf6f | 2013-12-05 22:31:25 -0800 | [diff] [blame] | 2403 | shell_surface_set_parent(shsurf, NULL); |
| 2404 | surface_clear_next_states(shsurf); |
Kristian Høgsberg | c8f8dd8 | 2013-12-05 23:20:33 -0800 | [diff] [blame] | 2405 | shsurf->type = SHELL_SURFACE_TOPLEVEL; |
Philip Withnall | 648a4dd | 2013-11-25 18:01:44 +0000 | [diff] [blame] | 2406 | |
| 2407 | /* The layer_link is updated in set_surface_type(), |
| 2408 | * called from configure. */ |
Philip Withnall | becb77e | 2013-11-25 18:01:30 +0000 | [diff] [blame] | 2409 | } |
| 2410 | |
| 2411 | static void |
| 2412 | shell_surface_set_toplevel(struct wl_client *client, |
| 2413 | struct wl_resource *resource) |
| 2414 | { |
| 2415 | struct shell_surface *surface = wl_resource_get_user_data(resource); |
| 2416 | |
| 2417 | set_toplevel(surface); |
| 2418 | } |
| 2419 | |
| 2420 | static void |
| 2421 | set_transient(struct shell_surface *shsurf, |
| 2422 | struct weston_surface *parent, int x, int y, uint32_t flags) |
| 2423 | { |
Philip Withnall | dc4332f | 2013-11-25 18:01:38 +0000 | [diff] [blame] | 2424 | assert(parent != NULL); |
| 2425 | |
Kristian Høgsberg | 9f7e331 | 2014-01-02 22:40:37 -0800 | [diff] [blame] | 2426 | shell_surface_set_parent(shsurf, parent); |
| 2427 | |
| 2428 | surface_clear_next_states(shsurf); |
| 2429 | |
Philip Withnall | becb77e | 2013-11-25 18:01:30 +0000 | [diff] [blame] | 2430 | shsurf->transient.x = x; |
| 2431 | shsurf->transient.y = y; |
| 2432 | shsurf->transient.flags = flags; |
Philip Withnall | dc4332f | 2013-11-25 18:01:38 +0000 | [diff] [blame] | 2433 | |
Rafael Antognolli | ed207b4 | 2013-12-03 15:35:43 -0200 | [diff] [blame] | 2434 | shsurf->next_state.relative = true; |
Kristian Høgsberg | a1df7ac | 2013-12-31 15:01:01 -0800 | [diff] [blame] | 2435 | shsurf->state_changed = true; |
Kristian Høgsberg | c8f8dd8 | 2013-12-05 23:20:33 -0800 | [diff] [blame] | 2436 | shsurf->type = SHELL_SURFACE_TOPLEVEL; |
Philip Withnall | 648a4dd | 2013-11-25 18:01:44 +0000 | [diff] [blame] | 2437 | |
| 2438 | /* The layer_link is updated in set_surface_type(), |
| 2439 | * called from configure. */ |
Philip Withnall | becb77e | 2013-11-25 18:01:30 +0000 | [diff] [blame] | 2440 | } |
| 2441 | |
| 2442 | static void |
| 2443 | shell_surface_set_transient(struct wl_client *client, |
| 2444 | struct wl_resource *resource, |
| 2445 | struct wl_resource *parent_resource, |
| 2446 | int x, int y, uint32_t flags) |
| 2447 | { |
| 2448 | struct shell_surface *shsurf = wl_resource_get_user_data(resource); |
| 2449 | struct weston_surface *parent = |
| 2450 | wl_resource_get_user_data(parent_resource); |
| 2451 | |
| 2452 | set_transient(shsurf, parent, x, y, flags); |
| 2453 | } |
| 2454 | |
| 2455 | static void |
| 2456 | set_fullscreen(struct shell_surface *shsurf, |
| 2457 | uint32_t method, |
| 2458 | uint32_t framerate, |
| 2459 | struct weston_output *output) |
| 2460 | { |
Philip Withnall | 352e7ed | 2013-11-25 18:01:35 +0000 | [diff] [blame] | 2461 | shell_surface_set_output(shsurf, output); |
Jasper St. Pierre | 6458ec3 | 2014-04-11 16:00:31 -0700 | [diff] [blame] | 2462 | shsurf->type = SHELL_SURFACE_TOPLEVEL; |
Philip Withnall | becb77e | 2013-11-25 18:01:30 +0000 | [diff] [blame] | 2463 | |
| 2464 | shsurf->fullscreen_output = shsurf->output; |
| 2465 | shsurf->fullscreen.type = method; |
| 2466 | shsurf->fullscreen.framerate = framerate; |
Philip Withnall | dc4332f | 2013-11-25 18:01:38 +0000 | [diff] [blame] | 2467 | |
Jasper St. Pierre | 6458ec3 | 2014-04-11 16:00:31 -0700 | [diff] [blame] | 2468 | send_configure_for_surface(shsurf); |
Philip Withnall | becb77e | 2013-11-25 18:01:30 +0000 | [diff] [blame] | 2469 | } |
| 2470 | |
| 2471 | static void |
Zhang, Xiong Y | 3123693 | 2013-12-13 22:10:57 +0200 | [diff] [blame] | 2472 | weston_view_set_initial_position(struct weston_view *view, |
| 2473 | struct desktop_shell *shell); |
| 2474 | |
| 2475 | static void |
Philip Withnall | becb77e | 2013-11-25 18:01:30 +0000 | [diff] [blame] | 2476 | unset_fullscreen(struct shell_surface *shsurf) |
Alex Wu | 4539b08 | 2012-03-01 12:57:46 +0800 | [diff] [blame] | 2477 | { |
Philip Withnall | f85fe84 | 2013-11-25 18:01:37 +0000 | [diff] [blame] | 2478 | /* Unset the fullscreen output, driver configuration and transforms. */ |
Alex Wu | bd3354b | 2012-04-17 17:20:49 +0800 | [diff] [blame] | 2479 | if (shsurf->fullscreen.type == WL_SHELL_SURFACE_FULLSCREEN_METHOD_DRIVER && |
| 2480 | shell_surface_is_top_fullscreen(shsurf)) { |
Alexander Larsson | f82b6ca | 2013-05-28 16:23:39 +0200 | [diff] [blame] | 2481 | restore_output_mode(shsurf->fullscreen_output); |
Alex Wu | bd3354b | 2012-04-17 17:20:49 +0800 | [diff] [blame] | 2482 | } |
Philip Withnall | f85fe84 | 2013-11-25 18:01:37 +0000 | [diff] [blame] | 2483 | |
Alex Wu | 4539b08 | 2012-03-01 12:57:46 +0800 | [diff] [blame] | 2484 | shsurf->fullscreen.type = WL_SHELL_SURFACE_FULLSCREEN_METHOD_DEFAULT; |
| 2485 | shsurf->fullscreen.framerate = 0; |
Philip Withnall | f85fe84 | 2013-11-25 18:01:37 +0000 | [diff] [blame] | 2486 | |
Alex Wu | 4539b08 | 2012-03-01 12:57:46 +0800 | [diff] [blame] | 2487 | wl_list_remove(&shsurf->fullscreen.transform.link); |
| 2488 | wl_list_init(&shsurf->fullscreen.transform.link); |
Philip Withnall | f85fe84 | 2013-11-25 18:01:37 +0000 | [diff] [blame] | 2489 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 2490 | if (shsurf->fullscreen.black_view) |
| 2491 | weston_surface_destroy(shsurf->fullscreen.black_view->surface); |
| 2492 | shsurf->fullscreen.black_view = NULL; |
Philip Withnall | f85fe84 | 2013-11-25 18:01:37 +0000 | [diff] [blame] | 2493 | |
Zhang, Xiong Y | 3123693 | 2013-12-13 22:10:57 +0200 | [diff] [blame] | 2494 | if (shsurf->saved_position_valid) |
| 2495 | weston_view_set_position(shsurf->view, |
| 2496 | shsurf->saved_x, shsurf->saved_y); |
| 2497 | else |
| 2498 | weston_view_set_initial_position(shsurf->view, shsurf->shell); |
| 2499 | |
Alex Wu | 7bcb8bd | 2012-04-27 09:07:24 +0800 | [diff] [blame] | 2500 | if (shsurf->saved_rotation_valid) { |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 2501 | wl_list_insert(&shsurf->view->geometry.transformation_list, |
Philip Withnall | becb77e | 2013-11-25 18:01:30 +0000 | [diff] [blame] | 2502 | &shsurf->rotation.transform.link); |
Alex Wu | 7bcb8bd | 2012-04-27 09:07:24 +0800 | [diff] [blame] | 2503 | shsurf->saved_rotation_valid = false; |
| 2504 | } |
Rafal Mielniczuk | 3e3862c | 2012-10-07 20:25:36 +0200 | [diff] [blame] | 2505 | |
Philip Withnall | e1d75ae | 2013-11-25 18:01:41 +0000 | [diff] [blame] | 2506 | /* Layer is updated in set_surface_type(). */ |
Alex Wu | 4539b08 | 2012-03-01 12:57:46 +0800 | [diff] [blame] | 2507 | } |
| 2508 | |
Rafal Mielniczuk | fffdcdd | 2013-03-11 19:26:54 +0100 | [diff] [blame] | 2509 | static void |
Philip Withnall | becb77e | 2013-11-25 18:01:30 +0000 | [diff] [blame] | 2510 | shell_surface_set_fullscreen(struct wl_client *client, |
| 2511 | struct wl_resource *resource, |
| 2512 | uint32_t method, |
| 2513 | uint32_t framerate, |
| 2514 | struct wl_resource *output_resource) |
| 2515 | { |
| 2516 | struct shell_surface *shsurf = wl_resource_get_user_data(resource); |
| 2517 | struct weston_output *output; |
| 2518 | |
| 2519 | if (output_resource) |
| 2520 | output = wl_resource_get_user_data(output_resource); |
| 2521 | else |
| 2522 | output = NULL; |
| 2523 | |
Rafael Antognolli | 4b99a40 | 2013-12-03 15:35:44 -0200 | [diff] [blame] | 2524 | shell_surface_set_parent(shsurf, NULL); |
| 2525 | |
Rafael Antognolli | 03b1659 | 2013-12-03 15:35:42 -0200 | [diff] [blame] | 2526 | surface_clear_next_states(shsurf); |
Jasper St. Pierre | 8c6aa45 | 2014-02-08 18:29:49 -0500 | [diff] [blame] | 2527 | shsurf->next_state.fullscreen = true; |
| 2528 | shsurf->state_changed = true; |
Jasper St. Pierre | 6458ec3 | 2014-04-11 16:00:31 -0700 | [diff] [blame] | 2529 | set_fullscreen(shsurf, method, framerate, output); |
Philip Withnall | becb77e | 2013-11-25 18:01:30 +0000 | [diff] [blame] | 2530 | } |
| 2531 | |
| 2532 | static void |
| 2533 | set_popup(struct shell_surface *shsurf, |
| 2534 | struct weston_surface *parent, |
| 2535 | struct weston_seat *seat, |
| 2536 | uint32_t serial, |
| 2537 | int32_t x, |
| 2538 | int32_t y) |
| 2539 | { |
Philip Withnall | dc4332f | 2013-11-25 18:01:38 +0000 | [diff] [blame] | 2540 | assert(parent != NULL); |
| 2541 | |
Philip Withnall | becb77e | 2013-11-25 18:01:30 +0000 | [diff] [blame] | 2542 | shsurf->popup.shseat = get_shell_seat(seat); |
| 2543 | shsurf->popup.serial = serial; |
| 2544 | shsurf->popup.x = x; |
| 2545 | shsurf->popup.y = y; |
Philip Withnall | dc4332f | 2013-11-25 18:01:38 +0000 | [diff] [blame] | 2546 | |
Kristian Høgsberg | c8f8dd8 | 2013-12-05 23:20:33 -0800 | [diff] [blame] | 2547 | shsurf->type = SHELL_SURFACE_POPUP; |
Philip Withnall | becb77e | 2013-11-25 18:01:30 +0000 | [diff] [blame] | 2548 | } |
| 2549 | |
| 2550 | static void |
| 2551 | shell_surface_set_popup(struct wl_client *client, |
| 2552 | struct wl_resource *resource, |
| 2553 | struct wl_resource *seat_resource, |
| 2554 | uint32_t serial, |
| 2555 | struct wl_resource *parent_resource, |
| 2556 | int32_t x, int32_t y, uint32_t flags) |
| 2557 | { |
| 2558 | struct shell_surface *shsurf = wl_resource_get_user_data(resource); |
Rafael Antognolli | 4b99a40 | 2013-12-03 15:35:44 -0200 | [diff] [blame] | 2559 | struct weston_surface *parent = |
| 2560 | wl_resource_get_user_data(parent_resource); |
| 2561 | |
| 2562 | shell_surface_set_parent(shsurf, parent); |
Philip Withnall | becb77e | 2013-11-25 18:01:30 +0000 | [diff] [blame] | 2563 | |
Rafael Antognolli | 03b1659 | 2013-12-03 15:35:42 -0200 | [diff] [blame] | 2564 | surface_clear_next_states(shsurf); |
Philip Withnall | becb77e | 2013-11-25 18:01:30 +0000 | [diff] [blame] | 2565 | set_popup(shsurf, |
Rafael Antognolli | 4b99a40 | 2013-12-03 15:35:44 -0200 | [diff] [blame] | 2566 | parent, |
Philip Withnall | becb77e | 2013-11-25 18:01:30 +0000 | [diff] [blame] | 2567 | wl_resource_get_user_data(seat_resource), |
| 2568 | serial, x, y); |
| 2569 | } |
| 2570 | |
| 2571 | static void |
Philip Withnall | becb77e | 2013-11-25 18:01:30 +0000 | [diff] [blame] | 2572 | unset_maximized(struct shell_surface *shsurf) |
Rafal Mielniczuk | fffdcdd | 2013-03-11 19:26:54 +0100 | [diff] [blame] | 2573 | { |
Rafal Mielniczuk | fffdcdd | 2013-03-11 19:26:54 +0100 | [diff] [blame] | 2574 | /* undo all maximized things here */ |
| 2575 | shsurf->output = get_default_output(shsurf->surface->compositor); |
Zhang, Xiong Y | 3123693 | 2013-12-13 22:10:57 +0200 | [diff] [blame] | 2576 | |
| 2577 | if (shsurf->saved_position_valid) |
| 2578 | weston_view_set_position(shsurf->view, |
| 2579 | shsurf->saved_x, shsurf->saved_y); |
| 2580 | else |
| 2581 | weston_view_set_initial_position(shsurf->view, shsurf->shell); |
Rafal Mielniczuk | fffdcdd | 2013-03-11 19:26:54 +0100 | [diff] [blame] | 2582 | |
| 2583 | if (shsurf->saved_rotation_valid) { |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 2584 | wl_list_insert(&shsurf->view->geometry.transformation_list, |
| 2585 | &shsurf->rotation.transform.link); |
Rafal Mielniczuk | fffdcdd | 2013-03-11 19:26:54 +0100 | [diff] [blame] | 2586 | shsurf->saved_rotation_valid = false; |
| 2587 | } |
| 2588 | |
Philip Withnall | e1d75ae | 2013-11-25 18:01:41 +0000 | [diff] [blame] | 2589 | /* Layer is updated in set_surface_type(). */ |
Rafal Mielniczuk | fffdcdd | 2013-03-11 19:26:54 +0100 | [diff] [blame] | 2590 | } |
| 2591 | |
Philip Withnall | becb77e | 2013-11-25 18:01:30 +0000 | [diff] [blame] | 2592 | static void |
Manuel Bachmann | 50c87db | 2014-02-26 15:52:13 +0100 | [diff] [blame] | 2593 | set_minimized(struct weston_surface *surface, uint32_t is_true) |
| 2594 | { |
| 2595 | struct shell_surface *shsurf; |
| 2596 | struct workspace *current_ws; |
| 2597 | struct weston_seat *seat; |
| 2598 | struct weston_surface *focus; |
| 2599 | struct weston_view *view; |
| 2600 | |
| 2601 | view = get_default_view(surface); |
| 2602 | if (!view) |
| 2603 | return; |
| 2604 | |
| 2605 | assert(weston_surface_get_main_surface(view->surface) == view->surface); |
| 2606 | |
| 2607 | shsurf = get_shell_surface(surface); |
| 2608 | current_ws = get_current_workspace(shsurf->shell); |
| 2609 | |
Giulio Camuffo | 412e6a5 | 2014-07-09 22:12:56 +0300 | [diff] [blame] | 2610 | weston_layer_entry_remove(&view->layer_link); |
Manuel Bachmann | 50c87db | 2014-02-26 15:52:13 +0100 | [diff] [blame] | 2611 | /* hide or show, depending on the state */ |
| 2612 | if (is_true) { |
Giulio Camuffo | 412e6a5 | 2014-07-09 22:12:56 +0300 | [diff] [blame] | 2613 | 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] | 2614 | |
| 2615 | drop_focus_state(shsurf->shell, current_ws, view->surface); |
| 2616 | wl_list_for_each(seat, &shsurf->shell->compositor->seat_list, link) { |
| 2617 | if (!seat->keyboard) |
| 2618 | continue; |
| 2619 | focus = weston_surface_get_main_surface(seat->keyboard->focus); |
| 2620 | if (focus == view->surface) |
| 2621 | weston_keyboard_set_focus(seat->keyboard, NULL); |
| 2622 | } |
| 2623 | } |
| 2624 | else { |
Giulio Camuffo | 412e6a5 | 2014-07-09 22:12:56 +0300 | [diff] [blame] | 2625 | weston_layer_entry_insert(¤t_ws->layer.view_list, &view->layer_link); |
Manuel Bachmann | 50c87db | 2014-02-26 15:52:13 +0100 | [diff] [blame] | 2626 | |
| 2627 | wl_list_for_each(seat, &shsurf->shell->compositor->seat_list, link) { |
| 2628 | if (!seat->keyboard) |
| 2629 | continue; |
Emilio Pozuelo Monfort | 9e7c759 | 2014-01-30 14:01:10 +0100 | [diff] [blame] | 2630 | activate(shsurf->shell, view->surface, seat, true); |
Manuel Bachmann | 50c87db | 2014-02-26 15:52:13 +0100 | [diff] [blame] | 2631 | } |
| 2632 | } |
| 2633 | |
| 2634 | shell_surface_update_child_surface_layers(shsurf); |
| 2635 | |
| 2636 | weston_view_damage_below(view); |
| 2637 | } |
| 2638 | |
| 2639 | static void |
Philip Withnall | becb77e | 2013-11-25 18:01:30 +0000 | [diff] [blame] | 2640 | shell_surface_set_maximized(struct wl_client *client, |
| 2641 | struct wl_resource *resource, |
| 2642 | struct wl_resource *output_resource) |
| 2643 | { |
| 2644 | struct shell_surface *shsurf = wl_resource_get_user_data(resource); |
| 2645 | struct weston_output *output; |
| 2646 | |
Jasper St. Pierre | 9aa8ce6 | 2014-04-11 16:18:54 -0700 | [diff] [blame] | 2647 | surface_clear_next_states(shsurf); |
| 2648 | shsurf->next_state.maximized = true; |
| 2649 | shsurf->state_changed = true; |
| 2650 | |
| 2651 | shsurf->type = SHELL_SURFACE_TOPLEVEL; |
| 2652 | shell_surface_set_parent(shsurf, NULL); |
| 2653 | |
Philip Withnall | becb77e | 2013-11-25 18:01:30 +0000 | [diff] [blame] | 2654 | if (output_resource) |
| 2655 | output = wl_resource_get_user_data(output_resource); |
| 2656 | else |
| 2657 | output = NULL; |
| 2658 | |
Jasper St. Pierre | 9aa8ce6 | 2014-04-11 16:18:54 -0700 | [diff] [blame] | 2659 | shell_surface_set_output(shsurf, output); |
Rafael Antognolli | 4b99a40 | 2013-12-03 15:35:44 -0200 | [diff] [blame] | 2660 | |
Jasper St. Pierre | 9aa8ce6 | 2014-04-11 16:18:54 -0700 | [diff] [blame] | 2661 | send_configure_for_surface(shsurf); |
Philip Withnall | becb77e | 2013-11-25 18:01:30 +0000 | [diff] [blame] | 2662 | } |
| 2663 | |
Philip Withnall | e1d75ae | 2013-11-25 18:01:41 +0000 | [diff] [blame] | 2664 | /* This is only ever called from set_surface_type(), so there’s no need to |
| 2665 | * update layer_links here, since they’ll be updated when we return. */ |
Pekka Paalanen | 9826223 | 2011-12-01 10:42:22 +0200 | [diff] [blame] | 2666 | static int |
Philip Withnall | becb77e | 2013-11-25 18:01:30 +0000 | [diff] [blame] | 2667 | reset_surface_type(struct shell_surface *surface) |
Pekka Paalanen | 9826223 | 2011-12-01 10:42:22 +0200 | [diff] [blame] | 2668 | { |
Rafael Antognolli | 03b1659 | 2013-12-03 15:35:42 -0200 | [diff] [blame] | 2669 | if (surface->state.fullscreen) |
Philip Withnall | becb77e | 2013-11-25 18:01:30 +0000 | [diff] [blame] | 2670 | unset_fullscreen(surface); |
Rafael Antognolli | 03b1659 | 2013-12-03 15:35:42 -0200 | [diff] [blame] | 2671 | if (surface->state.maximized) |
Philip Withnall | becb77e | 2013-11-25 18:01:30 +0000 | [diff] [blame] | 2672 | unset_maximized(surface); |
Pekka Paalanen | 9826223 | 2011-12-01 10:42:22 +0200 | [diff] [blame] | 2673 | |
Pekka Paalanen | 9826223 | 2011-12-01 10:42:22 +0200 | [diff] [blame] | 2674 | return 0; |
| 2675 | } |
| 2676 | |
Kristian Høgsberg | 4cca349 | 2011-01-18 07:53:49 -0500 | [diff] [blame] | 2677 | static void |
Rafael Antognolli | 03b1659 | 2013-12-03 15:35:42 -0200 | [diff] [blame] | 2678 | set_full_output(struct shell_surface *shsurf) |
| 2679 | { |
| 2680 | shsurf->saved_x = shsurf->view->geometry.x; |
| 2681 | shsurf->saved_y = shsurf->view->geometry.y; |
Rafael Antognolli | 3c4e3f7 | 2013-12-03 15:35:46 -0200 | [diff] [blame] | 2682 | shsurf->saved_width = shsurf->surface->width; |
| 2683 | shsurf->saved_height = shsurf->surface->height; |
| 2684 | shsurf->saved_size_valid = true; |
Rafael Antognolli | 03b1659 | 2013-12-03 15:35:42 -0200 | [diff] [blame] | 2685 | shsurf->saved_position_valid = true; |
| 2686 | |
| 2687 | if (!wl_list_empty(&shsurf->rotation.transform.link)) { |
| 2688 | wl_list_remove(&shsurf->rotation.transform.link); |
| 2689 | wl_list_init(&shsurf->rotation.transform.link); |
| 2690 | weston_view_geometry_dirty(shsurf->view); |
| 2691 | shsurf->saved_rotation_valid = true; |
| 2692 | } |
| 2693 | } |
| 2694 | |
| 2695 | static void |
Kristian Høgsberg | 7f366e7 | 2012-04-27 17:20:01 -0400 | [diff] [blame] | 2696 | set_surface_type(struct shell_surface *shsurf) |
| 2697 | { |
Kristian Høgsberg | 8150b19 | 2012-06-27 10:22:58 -0400 | [diff] [blame] | 2698 | struct weston_surface *pes = shsurf->parent; |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 2699 | struct weston_view *pev = get_default_view(pes); |
Kristian Høgsberg | 7f366e7 | 2012-04-27 17:20:01 -0400 | [diff] [blame] | 2700 | |
Philip Withnall | becb77e | 2013-11-25 18:01:30 +0000 | [diff] [blame] | 2701 | reset_surface_type(shsurf); |
Kristian Høgsberg | 7f366e7 | 2012-04-27 17:20:01 -0400 | [diff] [blame] | 2702 | |
Rafael Antognolli | 03b1659 | 2013-12-03 15:35:42 -0200 | [diff] [blame] | 2703 | shsurf->state = shsurf->next_state; |
Rafael Antognolli | 03b1659 | 2013-12-03 15:35:42 -0200 | [diff] [blame] | 2704 | shsurf->state_changed = false; |
Kristian Høgsberg | 7f366e7 | 2012-04-27 17:20:01 -0400 | [diff] [blame] | 2705 | |
| 2706 | switch (shsurf->type) { |
| 2707 | case SHELL_SURFACE_TOPLEVEL: |
Rafael Antognolli | ed207b4 | 2013-12-03 15:35:43 -0200 | [diff] [blame] | 2708 | if (shsurf->state.maximized || shsurf->state.fullscreen) { |
Rafael Antognolli | 03b1659 | 2013-12-03 15:35:42 -0200 | [diff] [blame] | 2709 | set_full_output(shsurf); |
Rafael Antognolli | ed207b4 | 2013-12-03 15:35:43 -0200 | [diff] [blame] | 2710 | } else if (shsurf->state.relative && pev) { |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 2711 | weston_view_set_position(shsurf->view, |
| 2712 | pev->geometry.x + shsurf->transient.x, |
| 2713 | pev->geometry.y + shsurf->transient.y); |
Rafael Antognolli | ed207b4 | 2013-12-03 15:35:43 -0200 | [diff] [blame] | 2714 | } |
Rafael Antognolli | 44a3162 | 2013-12-04 18:37:16 -0200 | [diff] [blame] | 2715 | break; |
Kristian Høgsberg | 7f366e7 | 2012-04-27 17:20:01 -0400 | [diff] [blame] | 2716 | |
Tiago Vignatti | fb2adba | 2013-06-12 15:43:21 -0300 | [diff] [blame] | 2717 | case SHELL_SURFACE_XWAYLAND: |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 2718 | weston_view_set_position(shsurf->view, shsurf->transient.x, |
| 2719 | shsurf->transient.y); |
Tiago Vignatti | fb2adba | 2013-06-12 15:43:21 -0300 | [diff] [blame] | 2720 | break; |
| 2721 | |
Philip Withnall | 0f640e2 | 2013-11-25 18:01:31 +0000 | [diff] [blame] | 2722 | case SHELL_SURFACE_POPUP: |
| 2723 | case SHELL_SURFACE_NONE: |
Kristian Høgsberg | 7f366e7 | 2012-04-27 17:20:01 -0400 | [diff] [blame] | 2724 | default: |
| 2725 | break; |
| 2726 | } |
Philip Withnall | e1d75ae | 2013-11-25 18:01:41 +0000 | [diff] [blame] | 2727 | |
| 2728 | /* Update the surface’s layer. */ |
| 2729 | shell_surface_update_layer(shsurf); |
Kristian Høgsberg | 7f366e7 | 2012-04-27 17:20:01 -0400 | [diff] [blame] | 2730 | } |
| 2731 | |
Tiago Vignatti | be14326 | 2012-04-16 17:31:41 +0300 | [diff] [blame] | 2732 | static struct desktop_shell * |
Juan Zhao | 96879df | 2012-02-07 08:45:41 +0800 | [diff] [blame] | 2733 | shell_surface_get_shell(struct shell_surface *shsurf) |
Pekka Paalanen | af0e34c | 2011-12-02 10:59:17 +0200 | [diff] [blame] | 2734 | { |
Kristian Høgsberg | 02e79dc | 2012-04-12 09:55:26 -0400 | [diff] [blame] | 2735 | return shsurf->shell; |
Juan Zhao | 96879df | 2012-02-07 08:45:41 +0800 | [diff] [blame] | 2736 | } |
| 2737 | |
Alex Wu | 2185843 | 2012-04-01 20:13:08 +0800 | [diff] [blame] | 2738 | static void |
Jason Ekstrand | 918f2dd | 2013-12-02 21:01:53 -0600 | [diff] [blame] | 2739 | 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] | 2740 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 2741 | static struct weston_view * |
Alex Wu | 4539b08 | 2012-03-01 12:57:46 +0800 | [diff] [blame] | 2742 | create_black_surface(struct weston_compositor *ec, |
Alex Wu | 2185843 | 2012-04-01 20:13:08 +0800 | [diff] [blame] | 2743 | struct weston_surface *fs_surface, |
John Kåre Alsaker | 490d02a | 2012-09-30 02:57:21 +0200 | [diff] [blame] | 2744 | float x, float y, int w, int h) |
Alex Wu | 4539b08 | 2012-03-01 12:57:46 +0800 | [diff] [blame] | 2745 | { |
| 2746 | struct weston_surface *surface = NULL; |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 2747 | struct weston_view *view; |
Alex Wu | 4539b08 | 2012-03-01 12:57:46 +0800 | [diff] [blame] | 2748 | |
| 2749 | surface = weston_surface_create(ec); |
| 2750 | if (surface == NULL) { |
Martin Minarik | 6d11836 | 2012-06-07 18:01:59 +0200 | [diff] [blame] | 2751 | weston_log("no memory\n"); |
Alex Wu | 4539b08 | 2012-03-01 12:57:46 +0800 | [diff] [blame] | 2752 | return NULL; |
| 2753 | } |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 2754 | view = weston_view_create(surface); |
| 2755 | if (surface == NULL) { |
| 2756 | weston_log("no memory\n"); |
| 2757 | weston_surface_destroy(surface); |
| 2758 | return NULL; |
| 2759 | } |
Alex Wu | 4539b08 | 2012-03-01 12:57:46 +0800 | [diff] [blame] | 2760 | |
Alex Wu | 2185843 | 2012-04-01 20:13:08 +0800 | [diff] [blame] | 2761 | surface->configure = black_surface_configure; |
Giulio Camuffo | 7fe01b1 | 2013-03-28 18:02:42 +0100 | [diff] [blame] | 2762 | surface->configure_private = fs_surface; |
Alex Wu | 4539b08 | 2012-03-01 12:57:46 +0800 | [diff] [blame] | 2763 | weston_surface_set_color(surface, 0.0, 0.0, 0.0, 1); |
Pekka Paalanen | 71f6f3b | 2012-10-10 12:49:26 +0300 | [diff] [blame] | 2764 | pixman_region32_fini(&surface->opaque); |
Kristian Høgsberg | 61f00f5 | 2012-08-03 16:31:36 -0400 | [diff] [blame] | 2765 | pixman_region32_init_rect(&surface->opaque, 0, 0, w, h); |
Jonas Ådahl | 33619a4 | 2013-01-15 21:25:55 +0100 | [diff] [blame] | 2766 | pixman_region32_fini(&surface->input); |
| 2767 | pixman_region32_init_rect(&surface->input, 0, 0, w, h); |
Jason Ekstrand | 918f2dd | 2013-12-02 21:01:53 -0600 | [diff] [blame] | 2768 | |
Jason Ekstrand | 6228ee2 | 2014-01-01 15:58:57 -0600 | [diff] [blame] | 2769 | weston_surface_set_size(surface, w, h); |
Jason Ekstrand | 918f2dd | 2013-12-02 21:01:53 -0600 | [diff] [blame] | 2770 | weston_view_set_position(view, x, y); |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 2771 | |
| 2772 | return view; |
Alex Wu | 4539b08 | 2012-03-01 12:57:46 +0800 | [diff] [blame] | 2773 | } |
| 2774 | |
Philip Withnall | ed8f1a9 | 2013-11-25 18:01:43 +0000 | [diff] [blame] | 2775 | static void |
| 2776 | shell_ensure_fullscreen_black_view(struct shell_surface *shsurf) |
| 2777 | { |
| 2778 | struct weston_output *output = shsurf->fullscreen_output; |
| 2779 | |
Rafael Antognolli | 03b1659 | 2013-12-03 15:35:42 -0200 | [diff] [blame] | 2780 | assert(shsurf->state.fullscreen); |
Philip Withnall | ed8f1a9 | 2013-11-25 18:01:43 +0000 | [diff] [blame] | 2781 | |
| 2782 | if (!shsurf->fullscreen.black_view) |
| 2783 | shsurf->fullscreen.black_view = |
| 2784 | create_black_surface(shsurf->surface->compositor, |
| 2785 | shsurf->surface, |
| 2786 | output->x, output->y, |
| 2787 | output->width, |
| 2788 | output->height); |
| 2789 | |
| 2790 | weston_view_geometry_dirty(shsurf->fullscreen.black_view); |
Giulio Camuffo | 412e6a5 | 2014-07-09 22:12:56 +0300 | [diff] [blame] | 2791 | weston_layer_entry_remove(&shsurf->fullscreen.black_view->layer_link); |
| 2792 | weston_layer_entry_insert(&shsurf->view->layer_link, |
| 2793 | &shsurf->fullscreen.black_view->layer_link); |
Philip Withnall | ed8f1a9 | 2013-11-25 18:01:43 +0000 | [diff] [blame] | 2794 | weston_view_geometry_dirty(shsurf->fullscreen.black_view); |
| 2795 | weston_surface_damage(shsurf->surface); |
Emilio Pozuelo Monfort | 9e7c759 | 2014-01-30 14:01:10 +0100 | [diff] [blame] | 2796 | |
| 2797 | shsurf->state.lowered = false; |
Philip Withnall | ed8f1a9 | 2013-11-25 18:01:43 +0000 | [diff] [blame] | 2798 | } |
| 2799 | |
Alex Wu | 4539b08 | 2012-03-01 12:57:46 +0800 | [diff] [blame] | 2800 | /* Create black surface and append it to the associated fullscreen surface. |
| 2801 | * Handle size dismatch and positioning according to the method. */ |
| 2802 | static void |
| 2803 | shell_configure_fullscreen(struct shell_surface *shsurf) |
| 2804 | { |
| 2805 | struct weston_output *output = shsurf->fullscreen_output; |
| 2806 | struct weston_surface *surface = shsurf->surface; |
| 2807 | struct weston_matrix *matrix; |
Kristian Høgsberg | 240dfeb | 2012-07-12 12:32:31 -0400 | [diff] [blame] | 2808 | float scale, output_aspect, surface_aspect, x, y; |
Giulio Camuffo | b836664 | 2013-04-25 13:57:46 +0300 | [diff] [blame] | 2809 | int32_t surf_x, surf_y, surf_width, surf_height; |
Alex Wu | 4539b08 | 2012-03-01 12:57:46 +0800 | [diff] [blame] | 2810 | |
Alexander Larsson | f82b6ca | 2013-05-28 16:23:39 +0200 | [diff] [blame] | 2811 | if (shsurf->fullscreen.type != WL_SHELL_SURFACE_FULLSCREEN_METHOD_DRIVER) |
| 2812 | restore_output_mode(output); |
| 2813 | |
Emilio Pozuelo Monfort | 9e7c759 | 2014-01-30 14:01:10 +0100 | [diff] [blame] | 2814 | /* Reverse the effect of lower_fullscreen_layer() */ |
Giulio Camuffo | 412e6a5 | 2014-07-09 22:12:56 +0300 | [diff] [blame] | 2815 | weston_layer_entry_remove(&shsurf->view->layer_link); |
| 2816 | 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] | 2817 | |
Philip Withnall | ed8f1a9 | 2013-11-25 18:01:43 +0000 | [diff] [blame] | 2818 | shell_ensure_fullscreen_black_view(shsurf); |
Alex Wu | 4539b08 | 2012-03-01 12:57:46 +0800 | [diff] [blame] | 2819 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 2820 | surface_subsurfaces_boundingbox(shsurf->surface, &surf_x, &surf_y, |
Giulio Camuffo | b836664 | 2013-04-25 13:57:46 +0300 | [diff] [blame] | 2821 | &surf_width, &surf_height); |
| 2822 | |
Alex Wu | 4539b08 | 2012-03-01 12:57:46 +0800 | [diff] [blame] | 2823 | switch (shsurf->fullscreen.type) { |
| 2824 | case WL_SHELL_SURFACE_FULLSCREEN_METHOD_DEFAULT: |
Pekka Paalanen | de685b8 | 2012-12-04 15:58:12 +0200 | [diff] [blame] | 2825 | if (surface->buffer_ref.buffer) |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 2826 | center_on_output(shsurf->view, shsurf->fullscreen_output); |
Alex Wu | 4539b08 | 2012-03-01 12:57:46 +0800 | [diff] [blame] | 2827 | break; |
| 2828 | case WL_SHELL_SURFACE_FULLSCREEN_METHOD_SCALE: |
Rob Bradford | 9f3dd15 | 2013-02-12 11:53:47 +0000 | [diff] [blame] | 2829 | /* 1:1 mapping between surface and output dimensions */ |
Giulio Camuffo | b836664 | 2013-04-25 13:57:46 +0300 | [diff] [blame] | 2830 | if (output->width == surf_width && |
| 2831 | output->height == surf_height) { |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 2832 | weston_view_set_position(shsurf->view, |
| 2833 | output->x - surf_x, |
| 2834 | output->y - surf_y); |
Rob Bradford | 9f3dd15 | 2013-02-12 11:53:47 +0000 | [diff] [blame] | 2835 | break; |
| 2836 | } |
| 2837 | |
Alex Wu | 4539b08 | 2012-03-01 12:57:46 +0800 | [diff] [blame] | 2838 | matrix = &shsurf->fullscreen.transform.matrix; |
| 2839 | weston_matrix_init(matrix); |
Kristian Høgsberg | 240dfeb | 2012-07-12 12:32:31 -0400 | [diff] [blame] | 2840 | |
Scott Moreau | 1bad5db | 2012-08-18 01:04:05 -0600 | [diff] [blame] | 2841 | output_aspect = (float) output->width / |
| 2842 | (float) output->height; |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 2843 | /* XXX: Use surf_width and surf_height here? */ |
| 2844 | surface_aspect = (float) surface->width / |
| 2845 | (float) surface->height; |
Kristian Høgsberg | 240dfeb | 2012-07-12 12:32:31 -0400 | [diff] [blame] | 2846 | if (output_aspect < surface_aspect) |
Scott Moreau | 1bad5db | 2012-08-18 01:04:05 -0600 | [diff] [blame] | 2847 | scale = (float) output->width / |
Giulio Camuffo | b836664 | 2013-04-25 13:57:46 +0300 | [diff] [blame] | 2848 | (float) surf_width; |
Kristian Høgsberg | 240dfeb | 2012-07-12 12:32:31 -0400 | [diff] [blame] | 2849 | else |
Scott Moreau | 1bad5db | 2012-08-18 01:04:05 -0600 | [diff] [blame] | 2850 | scale = (float) output->height / |
Giulio Camuffo | b836664 | 2013-04-25 13:57:46 +0300 | [diff] [blame] | 2851 | (float) surf_height; |
Kristian Høgsberg | 240dfeb | 2012-07-12 12:32:31 -0400 | [diff] [blame] | 2852 | |
Alex Wu | 4539b08 | 2012-03-01 12:57:46 +0800 | [diff] [blame] | 2853 | weston_matrix_scale(matrix, scale, scale, 1); |
| 2854 | wl_list_remove(&shsurf->fullscreen.transform.link); |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 2855 | wl_list_insert(&shsurf->view->geometry.transformation_list, |
Alex Wu | 4539b08 | 2012-03-01 12:57:46 +0800 | [diff] [blame] | 2856 | &shsurf->fullscreen.transform.link); |
Giulio Camuffo | b836664 | 2013-04-25 13:57:46 +0300 | [diff] [blame] | 2857 | x = output->x + (output->width - surf_width * scale) / 2 - surf_x; |
| 2858 | y = output->y + (output->height - surf_height * scale) / 2 - surf_y; |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 2859 | weston_view_set_position(shsurf->view, x, y); |
Kristian Høgsberg | 240dfeb | 2012-07-12 12:32:31 -0400 | [diff] [blame] | 2860 | |
Alex Wu | 4539b08 | 2012-03-01 12:57:46 +0800 | [diff] [blame] | 2861 | break; |
| 2862 | case WL_SHELL_SURFACE_FULLSCREEN_METHOD_DRIVER: |
Alex Wu | bd3354b | 2012-04-17 17:20:49 +0800 | [diff] [blame] | 2863 | if (shell_surface_is_top_fullscreen(shsurf)) { |
Quentin Glidic | c0d79ce | 2013-01-29 14:16:13 +0100 | [diff] [blame] | 2864 | struct weston_mode mode = {0, |
Pekka Paalanen | 952b6c8 | 2014-03-14 14:38:15 +0200 | [diff] [blame] | 2865 | surf_width * surface->buffer_viewport.buffer.scale, |
| 2866 | surf_height * surface->buffer_viewport.buffer.scale, |
Alex Wu | bd3354b | 2012-04-17 17:20:49 +0800 | [diff] [blame] | 2867 | shsurf->fullscreen.framerate}; |
| 2868 | |
Pekka Paalanen | 952b6c8 | 2014-03-14 14:38:15 +0200 | [diff] [blame] | 2869 | if (weston_output_switch_mode(output, &mode, surface->buffer_viewport.buffer.scale, |
Hardening | 57388e4 | 2013-09-18 23:56:36 +0200 | [diff] [blame] | 2870 | WESTON_MODE_SWITCH_SET_TEMPORARY) == 0) { |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 2871 | weston_view_set_position(shsurf->view, |
| 2872 | output->x - surf_x, |
| 2873 | output->y - surf_y); |
Jason Ekstrand | 918f2dd | 2013-12-02 21:01:53 -0600 | [diff] [blame] | 2874 | shsurf->fullscreen.black_view->surface->width = output->width; |
| 2875 | shsurf->fullscreen.black_view->surface->height = output->height; |
| 2876 | weston_view_set_position(shsurf->fullscreen.black_view, |
| 2877 | output->x - surf_x, |
| 2878 | output->y - surf_y); |
Alex Wu | bd3354b | 2012-04-17 17:20:49 +0800 | [diff] [blame] | 2879 | break; |
Alexander Larsson | d622ed3 | 2013-05-28 16:23:40 +0200 | [diff] [blame] | 2880 | } else { |
Alexander Larsson | f82b6ca | 2013-05-28 16:23:39 +0200 | [diff] [blame] | 2881 | restore_output_mode(output); |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 2882 | center_on_output(shsurf->view, output); |
Alexander Larsson | d622ed3 | 2013-05-28 16:23:40 +0200 | [diff] [blame] | 2883 | } |
Alex Wu | bd3354b | 2012-04-17 17:20:49 +0800 | [diff] [blame] | 2884 | } |
Alex Wu | 4539b08 | 2012-03-01 12:57:46 +0800 | [diff] [blame] | 2885 | break; |
| 2886 | case WL_SHELL_SURFACE_FULLSCREEN_METHOD_FILL: |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 2887 | center_on_output(shsurf->view, output); |
Alex Wu | 4539b08 | 2012-03-01 12:57:46 +0800 | [diff] [blame] | 2888 | break; |
| 2889 | default: |
| 2890 | break; |
| 2891 | } |
| 2892 | } |
| 2893 | |
Alex Wu | 4539b08 | 2012-03-01 12:57:46 +0800 | [diff] [blame] | 2894 | static void |
| 2895 | shell_map_fullscreen(struct shell_surface *shsurf) |
| 2896 | { |
Alex Wu | bd3354b | 2012-04-17 17:20:49 +0800 | [diff] [blame] | 2897 | shell_configure_fullscreen(shsurf); |
Alex Wu | 4539b08 | 2012-03-01 12:57:46 +0800 | [diff] [blame] | 2898 | } |
| 2899 | |
Kristian Høgsberg | 7a5c979 | 2011-06-18 06:12:54 -0400 | [diff] [blame] | 2900 | static void |
Tiago Vignatti | fb2adba | 2013-06-12 15:43:21 -0300 | [diff] [blame] | 2901 | set_xwayland(struct shell_surface *shsurf, int x, int y, uint32_t flags) |
| 2902 | { |
| 2903 | /* XXX: using the same fields for transient type */ |
Rafael Antognolli | 03b1659 | 2013-12-03 15:35:42 -0200 | [diff] [blame] | 2904 | surface_clear_next_states(shsurf); |
Tiago Vignatti | fb2adba | 2013-06-12 15:43:21 -0300 | [diff] [blame] | 2905 | shsurf->transient.x = x; |
| 2906 | shsurf->transient.y = y; |
| 2907 | shsurf->transient.flags = flags; |
Philip Withnall | dc4332f | 2013-11-25 18:01:38 +0000 | [diff] [blame] | 2908 | |
| 2909 | shell_surface_set_parent(shsurf, NULL); |
| 2910 | |
Kristian Høgsberg | c8f8dd8 | 2013-12-05 23:20:33 -0800 | [diff] [blame] | 2911 | shsurf->type = SHELL_SURFACE_XWAYLAND; |
Kristian Høgsberg | 8bc525c | 2014-01-01 22:34:49 -0800 | [diff] [blame] | 2912 | shsurf->state_changed = true; |
Tiago Vignatti | fb2adba | 2013-06-12 15:43:21 -0300 | [diff] [blame] | 2913 | } |
| 2914 | |
Kristian Høgsberg | 4779241 | 2014-05-04 13:47:06 -0700 | [diff] [blame] | 2915 | static void |
| 2916 | shell_interface_set_fullscreen(struct shell_surface *shsurf, |
| 2917 | uint32_t method, |
| 2918 | uint32_t framerate, |
| 2919 | struct weston_output *output) |
| 2920 | { |
| 2921 | surface_clear_next_states(shsurf); |
| 2922 | set_fullscreen(shsurf, method, framerate, output); |
| 2923 | |
| 2924 | shsurf->next_state.fullscreen = true; |
| 2925 | shsurf->state_changed = true; |
| 2926 | } |
| 2927 | |
Kristian Høgsberg | ae356ae | 2014-04-29 16:03:54 -0700 | [diff] [blame] | 2928 | static int |
| 2929 | shell_interface_move(struct shell_surface *shsurf, struct weston_seat *ws) |
| 2930 | { |
| 2931 | return surface_move(shsurf, ws, 1); |
| 2932 | } |
| 2933 | |
Kristian Høgsberg | 02bbabb | 2013-05-06 22:15:05 -0400 | [diff] [blame] | 2934 | static const struct weston_pointer_grab_interface popup_grab_interface; |
Giulio Camuffo | 5085a75 | 2013-03-25 21:42:45 +0100 | [diff] [blame] | 2935 | |
| 2936 | static void |
| 2937 | destroy_shell_seat(struct wl_listener *listener, void *data) |
| 2938 | { |
| 2939 | struct shell_seat *shseat = |
| 2940 | container_of(listener, |
| 2941 | struct shell_seat, seat_destroy_listener); |
| 2942 | struct shell_surface *shsurf, *prev = NULL; |
| 2943 | |
| 2944 | if (shseat->popup_grab.grab.interface == &popup_grab_interface) { |
Kristian Høgsberg | 02bbabb | 2013-05-06 22:15:05 -0400 | [diff] [blame] | 2945 | weston_pointer_end_grab(shseat->popup_grab.grab.pointer); |
Giulio Camuffo | 5085a75 | 2013-03-25 21:42:45 +0100 | [diff] [blame] | 2946 | shseat->popup_grab.client = NULL; |
| 2947 | |
| 2948 | wl_list_for_each(shsurf, &shseat->popup_grab.surfaces_list, popup.grab_link) { |
| 2949 | shsurf->popup.shseat = NULL; |
| 2950 | if (prev) { |
| 2951 | wl_list_init(&prev->popup.grab_link); |
| 2952 | } |
| 2953 | prev = shsurf; |
| 2954 | } |
| 2955 | wl_list_init(&prev->popup.grab_link); |
| 2956 | } |
| 2957 | |
| 2958 | wl_list_remove(&shseat->seat_destroy_listener.link); |
| 2959 | free(shseat); |
| 2960 | } |
| 2961 | |
Jason Ekstrand | 024177c | 2014-04-21 19:42:58 -0500 | [diff] [blame] | 2962 | static void |
| 2963 | shell_seat_caps_changed(struct wl_listener *listener, void *data) |
| 2964 | { |
| 2965 | struct shell_seat *seat; |
| 2966 | |
| 2967 | seat = container_of(listener, struct shell_seat, caps_changed_listener); |
| 2968 | |
| 2969 | if (seat->seat->keyboard && |
| 2970 | wl_list_empty(&seat->keyboard_focus_listener.link)) { |
| 2971 | wl_signal_add(&seat->seat->keyboard->focus_signal, |
| 2972 | &seat->keyboard_focus_listener); |
| 2973 | } else if (!seat->seat->keyboard) { |
| 2974 | wl_list_init(&seat->keyboard_focus_listener.link); |
| 2975 | } |
| 2976 | |
| 2977 | if (seat->seat->pointer && |
| 2978 | wl_list_empty(&seat->pointer_focus_listener.link)) { |
| 2979 | wl_signal_add(&seat->seat->pointer->focus_signal, |
| 2980 | &seat->pointer_focus_listener); |
| 2981 | } else if (!seat->seat->pointer) { |
| 2982 | wl_list_init(&seat->pointer_focus_listener.link); |
| 2983 | } |
| 2984 | } |
| 2985 | |
Giulio Camuffo | 5085a75 | 2013-03-25 21:42:45 +0100 | [diff] [blame] | 2986 | static struct shell_seat * |
| 2987 | create_shell_seat(struct weston_seat *seat) |
| 2988 | { |
| 2989 | struct shell_seat *shseat; |
| 2990 | |
| 2991 | shseat = calloc(1, sizeof *shseat); |
| 2992 | if (!shseat) { |
| 2993 | weston_log("no memory to allocate shell seat\n"); |
| 2994 | return NULL; |
| 2995 | } |
| 2996 | |
| 2997 | shseat->seat = seat; |
| 2998 | wl_list_init(&shseat->popup_grab.surfaces_list); |
| 2999 | |
| 3000 | shseat->seat_destroy_listener.notify = destroy_shell_seat; |
| 3001 | wl_signal_add(&seat->destroy_signal, |
| 3002 | &shseat->seat_destroy_listener); |
| 3003 | |
Jason Ekstrand | 024177c | 2014-04-21 19:42:58 -0500 | [diff] [blame] | 3004 | shseat->keyboard_focus_listener.notify = handle_keyboard_focus; |
| 3005 | wl_list_init(&shseat->keyboard_focus_listener.link); |
| 3006 | |
| 3007 | shseat->pointer_focus_listener.notify = handle_pointer_focus; |
| 3008 | wl_list_init(&shseat->pointer_focus_listener.link); |
| 3009 | |
| 3010 | shseat->caps_changed_listener.notify = shell_seat_caps_changed; |
| 3011 | wl_signal_add(&seat->updated_caps_signal, |
| 3012 | &shseat->caps_changed_listener); |
| 3013 | shell_seat_caps_changed(&shseat->caps_changed_listener, NULL); |
| 3014 | |
Giulio Camuffo | 5085a75 | 2013-03-25 21:42:45 +0100 | [diff] [blame] | 3015 | return shseat; |
| 3016 | } |
| 3017 | |
| 3018 | static struct shell_seat * |
| 3019 | get_shell_seat(struct weston_seat *seat) |
| 3020 | { |
| 3021 | struct wl_listener *listener; |
| 3022 | |
| 3023 | listener = wl_signal_get(&seat->destroy_signal, destroy_shell_seat); |
Jason Ekstrand | 024177c | 2014-04-21 19:42:58 -0500 | [diff] [blame] | 3024 | assert(listener != NULL); |
Giulio Camuffo | 5085a75 | 2013-03-25 21:42:45 +0100 | [diff] [blame] | 3025 | |
| 3026 | return container_of(listener, |
| 3027 | struct shell_seat, seat_destroy_listener); |
| 3028 | } |
| 3029 | |
Kristian Høgsberg | b810eb5 | 2013-02-12 20:07:05 -0500 | [diff] [blame] | 3030 | static void |
Kristian Høgsberg | 6848c25 | 2013-05-08 22:02:59 -0400 | [diff] [blame] | 3031 | popup_grab_focus(struct weston_pointer_grab *grab) |
Kristian Høgsberg | b3cca0a | 2012-01-04 22:19:14 -0500 | [diff] [blame] | 3032 | { |
Kristian Høgsberg | 02bbabb | 2013-05-06 22:15:05 -0400 | [diff] [blame] | 3033 | struct weston_pointer *pointer = grab->pointer; |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 3034 | struct weston_view *view; |
Giulio Camuffo | 5085a75 | 2013-03-25 21:42:45 +0100 | [diff] [blame] | 3035 | struct shell_seat *shseat = |
| 3036 | container_of(grab, struct shell_seat, popup_grab.grab); |
| 3037 | struct wl_client *client = shseat->popup_grab.client; |
Kristian Høgsberg | 6848c25 | 2013-05-08 22:02:59 -0400 | [diff] [blame] | 3038 | wl_fixed_t sx, sy; |
| 3039 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 3040 | view = weston_compositor_pick_view(pointer->seat->compositor, |
| 3041 | pointer->x, pointer->y, |
| 3042 | &sx, &sy); |
Kristian Høgsberg | b3cca0a | 2012-01-04 22:19:14 -0500 | [diff] [blame] | 3043 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 3044 | if (view && view->surface->resource && |
| 3045 | wl_resource_get_client(view->surface->resource) == client) { |
| 3046 | weston_pointer_set_focus(pointer, view, sx, sy); |
Kristian Høgsberg | b3cca0a | 2012-01-04 22:19:14 -0500 | [diff] [blame] | 3047 | } else { |
Kristian Høgsberg | 02bbabb | 2013-05-06 22:15:05 -0400 | [diff] [blame] | 3048 | weston_pointer_set_focus(pointer, NULL, |
| 3049 | wl_fixed_from_int(0), |
| 3050 | wl_fixed_from_int(0)); |
Kristian Høgsberg | b3cca0a | 2012-01-04 22:19:14 -0500 | [diff] [blame] | 3051 | } |
| 3052 | } |
| 3053 | |
| 3054 | static void |
Giulio Camuffo | 1959ab8 | 2013-11-14 23:42:52 +0100 | [diff] [blame] | 3055 | popup_grab_motion(struct weston_pointer_grab *grab, uint32_t time, |
| 3056 | wl_fixed_t x, wl_fixed_t y) |
Kristian Høgsberg | b3cca0a | 2012-01-04 22:19:14 -0500 | [diff] [blame] | 3057 | { |
Kristian Høgsberg | be6403e | 2013-05-08 21:03:21 -0400 | [diff] [blame] | 3058 | struct weston_pointer *pointer = grab->pointer; |
Neil Roberts | 96d790e | 2013-09-19 17:32:00 +0100 | [diff] [blame] | 3059 | struct wl_resource *resource; |
Kristian Høgsberg | be6403e | 2013-05-08 21:03:21 -0400 | [diff] [blame] | 3060 | wl_fixed_t sx, sy; |
Kristian Høgsberg | b3cca0a | 2012-01-04 22:19:14 -0500 | [diff] [blame] | 3061 | |
Jonas Ådahl | 61917c8 | 2014-08-11 22:44:02 +0200 | [diff] [blame] | 3062 | if (pointer->focus) { |
| 3063 | weston_view_from_global_fixed(pointer->focus, x, y, |
| 3064 | &pointer->sx, &pointer->sy); |
| 3065 | } |
| 3066 | |
Giulio Camuffo | 1959ab8 | 2013-11-14 23:42:52 +0100 | [diff] [blame] | 3067 | weston_pointer_move(pointer, x, y); |
| 3068 | |
Neil Roberts | 96d790e | 2013-09-19 17:32:00 +0100 | [diff] [blame] | 3069 | wl_resource_for_each(resource, &pointer->focus_resource_list) { |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 3070 | weston_view_from_global_fixed(pointer->focus, |
| 3071 | pointer->x, pointer->y, |
| 3072 | &sx, &sy); |
Neil Roberts | 96d790e | 2013-09-19 17:32:00 +0100 | [diff] [blame] | 3073 | wl_pointer_send_motion(resource, time, sx, sy); |
Kristian Høgsberg | be6403e | 2013-05-08 21:03:21 -0400 | [diff] [blame] | 3074 | } |
Kristian Høgsberg | b3cca0a | 2012-01-04 22:19:14 -0500 | [diff] [blame] | 3075 | } |
| 3076 | |
| 3077 | static void |
Kristian Høgsberg | 02bbabb | 2013-05-06 22:15:05 -0400 | [diff] [blame] | 3078 | popup_grab_button(struct weston_pointer_grab *grab, |
Daniel Stone | 4dbadb1 | 2012-05-30 16:31:51 +0100 | [diff] [blame] | 3079 | uint32_t time, uint32_t button, uint32_t state_w) |
Kristian Høgsberg | b3cca0a | 2012-01-04 22:19:14 -0500 | [diff] [blame] | 3080 | { |
| 3081 | struct wl_resource *resource; |
Giulio Camuffo | 5085a75 | 2013-03-25 21:42:45 +0100 | [diff] [blame] | 3082 | struct shell_seat *shseat = |
| 3083 | container_of(grab, struct shell_seat, popup_grab.grab); |
Rob Bradford | 880ebc7 | 2013-07-22 17:31:38 +0100 | [diff] [blame] | 3084 | struct wl_display *display = shseat->seat->compositor->wl_display; |
Daniel Stone | 4dbadb1 | 2012-05-30 16:31:51 +0100 | [diff] [blame] | 3085 | enum wl_pointer_button_state state = state_w; |
Kristian Høgsberg | eae5de7 | 2012-04-11 22:42:15 -0400 | [diff] [blame] | 3086 | uint32_t serial; |
Neil Roberts | 96d790e | 2013-09-19 17:32:00 +0100 | [diff] [blame] | 3087 | struct wl_list *resource_list; |
Kristian Høgsberg | b3cca0a | 2012-01-04 22:19:14 -0500 | [diff] [blame] | 3088 | |
Neil Roberts | 96d790e | 2013-09-19 17:32:00 +0100 | [diff] [blame] | 3089 | resource_list = &grab->pointer->focus_resource_list; |
| 3090 | if (!wl_list_empty(resource_list)) { |
Kristian Høgsberg | eae5de7 | 2012-04-11 22:42:15 -0400 | [diff] [blame] | 3091 | serial = wl_display_get_serial(display); |
Neil Roberts | 96d790e | 2013-09-19 17:32:00 +0100 | [diff] [blame] | 3092 | wl_resource_for_each(resource, resource_list) { |
| 3093 | wl_pointer_send_button(resource, serial, |
| 3094 | time, button, state); |
| 3095 | } |
Daniel Stone | 4dbadb1 | 2012-05-30 16:31:51 +0100 | [diff] [blame] | 3096 | } else if (state == WL_POINTER_BUTTON_STATE_RELEASED && |
Giulio Camuffo | 5085a75 | 2013-03-25 21:42:45 +0100 | [diff] [blame] | 3097 | (shseat->popup_grab.initial_up || |
Kristian Høgsberg | e314875 | 2013-05-06 23:19:49 -0400 | [diff] [blame] | 3098 | time - shseat->seat->pointer->grab_time > 500)) { |
Kristian Høgsberg | 57e0907 | 2012-10-30 14:07:27 -0400 | [diff] [blame] | 3099 | popup_grab_end(grab->pointer); |
Kristian Høgsberg | b3cca0a | 2012-01-04 22:19:14 -0500 | [diff] [blame] | 3100 | } |
| 3101 | |
Daniel Stone | 4dbadb1 | 2012-05-30 16:31:51 +0100 | [diff] [blame] | 3102 | if (state == WL_POINTER_BUTTON_STATE_RELEASED) |
Giulio Camuffo | 5085a75 | 2013-03-25 21:42:45 +0100 | [diff] [blame] | 3103 | shseat->popup_grab.initial_up = 1; |
Kristian Høgsberg | b3cca0a | 2012-01-04 22:19:14 -0500 | [diff] [blame] | 3104 | } |
| 3105 | |
Jonas Ådahl | 1ea343e | 2013-10-25 23:18:05 +0200 | [diff] [blame] | 3106 | static void |
| 3107 | popup_grab_cancel(struct weston_pointer_grab *grab) |
| 3108 | { |
| 3109 | popup_grab_end(grab->pointer); |
| 3110 | } |
| 3111 | |
Kristian Høgsberg | 02bbabb | 2013-05-06 22:15:05 -0400 | [diff] [blame] | 3112 | static const struct weston_pointer_grab_interface popup_grab_interface = { |
Kristian Høgsberg | b3cca0a | 2012-01-04 22:19:14 -0500 | [diff] [blame] | 3113 | popup_grab_focus, |
| 3114 | popup_grab_motion, |
| 3115 | popup_grab_button, |
Jonas Ådahl | 1ea343e | 2013-10-25 23:18:05 +0200 | [diff] [blame] | 3116 | popup_grab_cancel, |
Kristian Høgsberg | b3cca0a | 2012-01-04 22:19:14 -0500 | [diff] [blame] | 3117 | }; |
| 3118 | |
| 3119 | static void |
Rafael Antognolli | e2a3455 | 2013-12-03 15:35:45 -0200 | [diff] [blame] | 3120 | shell_surface_send_popup_done(struct shell_surface *shsurf) |
| 3121 | { |
| 3122 | if (shell_surface_is_wl_shell_surface(shsurf)) |
| 3123 | wl_shell_surface_send_popup_done(shsurf->resource); |
| 3124 | else if (shell_surface_is_xdg_popup(shsurf)) |
| 3125 | xdg_popup_send_popup_done(shsurf->resource, |
| 3126 | shsurf->popup.serial); |
| 3127 | } |
| 3128 | |
| 3129 | static void |
Kristian Høgsberg | 02bbabb | 2013-05-06 22:15:05 -0400 | [diff] [blame] | 3130 | popup_grab_end(struct weston_pointer *pointer) |
Kristian Høgsberg | 57e0907 | 2012-10-30 14:07:27 -0400 | [diff] [blame] | 3131 | { |
Kristian Høgsberg | 02bbabb | 2013-05-06 22:15:05 -0400 | [diff] [blame] | 3132 | struct weston_pointer_grab *grab = pointer->grab; |
Giulio Camuffo | 5085a75 | 2013-03-25 21:42:45 +0100 | [diff] [blame] | 3133 | struct shell_seat *shseat = |
| 3134 | container_of(grab, struct shell_seat, popup_grab.grab); |
| 3135 | struct shell_surface *shsurf; |
| 3136 | struct shell_surface *prev = NULL; |
Kristian Høgsberg | 57e0907 | 2012-10-30 14:07:27 -0400 | [diff] [blame] | 3137 | |
| 3138 | if (pointer->grab->interface == &popup_grab_interface) { |
Kristian Høgsberg | 02bbabb | 2013-05-06 22:15:05 -0400 | [diff] [blame] | 3139 | weston_pointer_end_grab(grab->pointer); |
Giulio Camuffo | 5085a75 | 2013-03-25 21:42:45 +0100 | [diff] [blame] | 3140 | shseat->popup_grab.client = NULL; |
Philipp Brüschweiler | 63e7be6 | 2013-04-15 21:09:54 +0200 | [diff] [blame] | 3141 | shseat->popup_grab.grab.interface = NULL; |
| 3142 | assert(!wl_list_empty(&shseat->popup_grab.surfaces_list)); |
Giulio Camuffo | 5085a75 | 2013-03-25 21:42:45 +0100 | [diff] [blame] | 3143 | /* Send the popup_done event to all the popups open */ |
| 3144 | wl_list_for_each(shsurf, &shseat->popup_grab.surfaces_list, popup.grab_link) { |
Rafael Antognolli | e2a3455 | 2013-12-03 15:35:45 -0200 | [diff] [blame] | 3145 | shell_surface_send_popup_done(shsurf); |
Giulio Camuffo | 5085a75 | 2013-03-25 21:42:45 +0100 | [diff] [blame] | 3146 | shsurf->popup.shseat = NULL; |
| 3147 | if (prev) { |
| 3148 | wl_list_init(&prev->popup.grab_link); |
| 3149 | } |
| 3150 | prev = shsurf; |
| 3151 | } |
| 3152 | wl_list_init(&prev->popup.grab_link); |
| 3153 | wl_list_init(&shseat->popup_grab.surfaces_list); |
| 3154 | } |
| 3155 | } |
| 3156 | |
| 3157 | static void |
| 3158 | add_popup_grab(struct shell_surface *shsurf, struct shell_seat *shseat) |
| 3159 | { |
Kristian Høgsberg | e314875 | 2013-05-06 23:19:49 -0400 | [diff] [blame] | 3160 | struct weston_seat *seat = shseat->seat; |
Giulio Camuffo | 5085a75 | 2013-03-25 21:42:45 +0100 | [diff] [blame] | 3161 | |
| 3162 | if (wl_list_empty(&shseat->popup_grab.surfaces_list)) { |
Jason Ekstrand | 651f00e | 2013-06-14 10:07:54 -0500 | [diff] [blame] | 3163 | shseat->popup_grab.client = wl_resource_get_client(shsurf->resource); |
Giulio Camuffo | 5085a75 | 2013-03-25 21:42:45 +0100 | [diff] [blame] | 3164 | shseat->popup_grab.grab.interface = &popup_grab_interface; |
Giulio Camuffo | 1b4b61a | 2013-03-27 18:05:26 +0100 | [diff] [blame] | 3165 | /* We must make sure here that this popup was opened after |
| 3166 | * a mouse press, and not just by moving around with other |
| 3167 | * popups already open. */ |
Kristian Høgsberg | e314875 | 2013-05-06 23:19:49 -0400 | [diff] [blame] | 3168 | if (shseat->seat->pointer->button_count > 0) |
Giulio Camuffo | 1b4b61a | 2013-03-27 18:05:26 +0100 | [diff] [blame] | 3169 | shseat->popup_grab.initial_up = 0; |
Giulio Camuffo | 5085a75 | 2013-03-25 21:42:45 +0100 | [diff] [blame] | 3170 | |
Rob Bradford | dfe3105 | 2013-06-26 19:49:11 +0100 | [diff] [blame] | 3171 | wl_list_insert(&shseat->popup_grab.surfaces_list, &shsurf->popup.grab_link); |
Kristian Høgsberg | 02bbabb | 2013-05-06 22:15:05 -0400 | [diff] [blame] | 3172 | weston_pointer_start_grab(seat->pointer, &shseat->popup_grab.grab); |
Rob Bradford | dfe3105 | 2013-06-26 19:49:11 +0100 | [diff] [blame] | 3173 | } else { |
| 3174 | wl_list_insert(&shseat->popup_grab.surfaces_list, &shsurf->popup.grab_link); |
Giulio Camuffo | 5085a75 | 2013-03-25 21:42:45 +0100 | [diff] [blame] | 3175 | } |
Giulio Camuffo | 5085a75 | 2013-03-25 21:42:45 +0100 | [diff] [blame] | 3176 | } |
| 3177 | |
| 3178 | static void |
| 3179 | remove_popup_grab(struct shell_surface *shsurf) |
| 3180 | { |
| 3181 | struct shell_seat *shseat = shsurf->popup.shseat; |
| 3182 | |
| 3183 | wl_list_remove(&shsurf->popup.grab_link); |
| 3184 | wl_list_init(&shsurf->popup.grab_link); |
| 3185 | if (wl_list_empty(&shseat->popup_grab.surfaces_list)) { |
Kristian Høgsberg | 02bbabb | 2013-05-06 22:15:05 -0400 | [diff] [blame] | 3186 | weston_pointer_end_grab(shseat->popup_grab.grab.pointer); |
Philipp Brüschweiler | 63e7be6 | 2013-04-15 21:09:54 +0200 | [diff] [blame] | 3187 | shseat->popup_grab.grab.interface = NULL; |
Kristian Høgsberg | 57e0907 | 2012-10-30 14:07:27 -0400 | [diff] [blame] | 3188 | } |
| 3189 | } |
| 3190 | |
| 3191 | static void |
Kristian Høgsberg | 3730f36 | 2012-04-13 12:40:07 -0400 | [diff] [blame] | 3192 | shell_map_popup(struct shell_surface *shsurf) |
Kristian Høgsberg | b3cca0a | 2012-01-04 22:19:14 -0500 | [diff] [blame] | 3193 | { |
Giulio Camuffo | 5085a75 | 2013-03-25 21:42:45 +0100 | [diff] [blame] | 3194 | struct shell_seat *shseat = shsurf->popup.shseat; |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 3195 | struct weston_view *parent_view = get_default_view(shsurf->parent); |
Kristian Høgsberg | b3cca0a | 2012-01-04 22:19:14 -0500 | [diff] [blame] | 3196 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 3197 | shsurf->surface->output = parent_view->output; |
| 3198 | shsurf->view->output = parent_view->output; |
Kristian Høgsberg | b3cca0a | 2012-01-04 22:19:14 -0500 | [diff] [blame] | 3199 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 3200 | weston_view_set_transform_parent(shsurf->view, parent_view); |
| 3201 | weston_view_set_position(shsurf->view, shsurf->popup.x, shsurf->popup.y); |
| 3202 | weston_view_update_transform(shsurf->view); |
Kristian Høgsberg | b3cca0a | 2012-01-04 22:19:14 -0500 | [diff] [blame] | 3203 | |
Jonny Lamb | e84ab4e | 2014-08-06 11:50:12 +0200 | [diff] [blame] | 3204 | if (shseat->seat->pointer && |
| 3205 | shseat->seat->pointer->grab_serial == shsurf->popup.serial) { |
Giulio Camuffo | 5085a75 | 2013-03-25 21:42:45 +0100 | [diff] [blame] | 3206 | add_popup_grab(shsurf, shseat); |
Kristian Høgsberg | 3730f36 | 2012-04-13 12:40:07 -0400 | [diff] [blame] | 3207 | } else { |
Rafael Antognolli | e2a3455 | 2013-12-03 15:35:45 -0200 | [diff] [blame] | 3208 | shell_surface_send_popup_done(shsurf); |
Giulio Camuffo | 5085a75 | 2013-03-25 21:42:45 +0100 | [diff] [blame] | 3209 | shseat->popup_grab.client = NULL; |
Kristian Høgsberg | 3730f36 | 2012-04-13 12:40:07 -0400 | [diff] [blame] | 3210 | } |
Kristian Høgsberg | b3cca0a | 2012-01-04 22:19:14 -0500 | [diff] [blame] | 3211 | } |
| 3212 | |
Pekka Paalanen | 9d1613e | 2011-11-25 12:09:16 +0200 | [diff] [blame] | 3213 | static const struct wl_shell_surface_interface shell_surface_implementation = { |
Scott Moreau | ff1db4a | 2012-04-17 19:06:18 -0600 | [diff] [blame] | 3214 | shell_surface_pong, |
Pekka Paalanen | 9d1613e | 2011-11-25 12:09:16 +0200 | [diff] [blame] | 3215 | shell_surface_move, |
| 3216 | shell_surface_resize, |
| 3217 | shell_surface_set_toplevel, |
| 3218 | shell_surface_set_transient, |
Kristian Høgsberg | b3cca0a | 2012-01-04 22:19:14 -0500 | [diff] [blame] | 3219 | shell_surface_set_fullscreen, |
Juan Zhao | 96879df | 2012-02-07 08:45:41 +0800 | [diff] [blame] | 3220 | shell_surface_set_popup, |
Kristian Høgsberg | e7afd91 | 2012-05-02 09:47:44 -0400 | [diff] [blame] | 3221 | shell_surface_set_maximized, |
| 3222 | shell_surface_set_title, |
| 3223 | shell_surface_set_class |
Pekka Paalanen | 9d1613e | 2011-11-25 12:09:16 +0200 | [diff] [blame] | 3224 | }; |
| 3225 | |
| 3226 | static void |
Tiago Vignatti | bc052c9 | 2012-04-19 16:18:18 +0300 | [diff] [blame] | 3227 | destroy_shell_surface(struct shell_surface *shsurf) |
Pekka Paalanen | 9d1613e | 2011-11-25 12:09:16 +0200 | [diff] [blame] | 3228 | { |
Kristian Høgsberg | 9046d24 | 2014-01-10 00:25:30 -0800 | [diff] [blame] | 3229 | struct shell_surface *child, *next; |
| 3230 | |
Jason Ekstrand | 651f00e | 2013-06-14 10:07:54 -0500 | [diff] [blame] | 3231 | wl_signal_emit(&shsurf->destroy_signal, shsurf); |
| 3232 | |
Giulio Camuffo | 5085a75 | 2013-03-25 21:42:45 +0100 | [diff] [blame] | 3233 | if (!wl_list_empty(&shsurf->popup.grab_link)) { |
| 3234 | remove_popup_grab(shsurf); |
| 3235 | } |
Kristian Høgsberg | b3cca0a | 2012-01-04 22:19:14 -0500 | [diff] [blame] | 3236 | |
Alex Wu | bd3354b | 2012-04-17 17:20:49 +0800 | [diff] [blame] | 3237 | if (shsurf->fullscreen.type == WL_SHELL_SURFACE_FULLSCREEN_METHOD_DRIVER && |
Alexander Larsson | f82b6ca | 2013-05-28 16:23:39 +0200 | [diff] [blame] | 3238 | shell_surface_is_top_fullscreen(shsurf)) |
| 3239 | restore_output_mode (shsurf->fullscreen_output); |
Pekka Paalanen | 9d1613e | 2011-11-25 12:09:16 +0200 | [diff] [blame] | 3240 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 3241 | if (shsurf->fullscreen.black_view) |
| 3242 | weston_surface_destroy(shsurf->fullscreen.black_view->surface); |
Alex Wu | aa08e2d | 2012-03-05 11:01:40 +0800 | [diff] [blame] | 3243 | |
Alex Wu | bd3354b | 2012-04-17 17:20:49 +0800 | [diff] [blame] | 3244 | /* As destroy_resource() use wl_list_for_each_safe(), |
| 3245 | * we can always remove the listener. |
| 3246 | */ |
| 3247 | wl_list_remove(&shsurf->surface_destroy_listener.link); |
| 3248 | shsurf->surface->configure = NULL; |
Scott Moreau | 976a050 | 2013-03-07 10:15:17 -0700 | [diff] [blame] | 3249 | free(shsurf->title); |
Alex Wu | bd3354b | 2012-04-17 17:20:49 +0800 | [diff] [blame] | 3250 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 3251 | weston_view_destroy(shsurf->view); |
| 3252 | |
Philip Withnall | 648a4dd | 2013-11-25 18:01:44 +0000 | [diff] [blame] | 3253 | wl_list_remove(&shsurf->children_link); |
Emilio Pozuelo Monfort | adaa20c | 2014-01-28 13:54:16 +0100 | [diff] [blame] | 3254 | wl_list_for_each_safe(child, next, &shsurf->children_list, children_link) |
| 3255 | shell_surface_set_parent(child, NULL); |
Philip Withnall | 648a4dd | 2013-11-25 18:01:44 +0000 | [diff] [blame] | 3256 | |
Pekka Paalanen | 9d1613e | 2011-11-25 12:09:16 +0200 | [diff] [blame] | 3257 | wl_list_remove(&shsurf->link); |
| 3258 | free(shsurf); |
| 3259 | } |
| 3260 | |
| 3261 | static void |
Tiago Vignatti | bc052c9 | 2012-04-19 16:18:18 +0300 | [diff] [blame] | 3262 | shell_destroy_shell_surface(struct wl_resource *resource) |
| 3263 | { |
Jason Ekstrand | 651f00e | 2013-06-14 10:07:54 -0500 | [diff] [blame] | 3264 | struct shell_surface *shsurf = wl_resource_get_user_data(resource); |
Tiago Vignatti | bc052c9 | 2012-04-19 16:18:18 +0300 | [diff] [blame] | 3265 | |
Bryan Cain | a46b946 | 2014-04-04 17:41:24 -0500 | [diff] [blame] | 3266 | if (!wl_list_empty(&shsurf->popup.grab_link)) |
| 3267 | remove_popup_grab(shsurf); |
Kristian Høgsberg | 160fe75 | 2014-03-11 10:19:10 -0700 | [diff] [blame] | 3268 | shsurf->resource = NULL; |
Tiago Vignatti | bc052c9 | 2012-04-19 16:18:18 +0300 | [diff] [blame] | 3269 | } |
| 3270 | |
| 3271 | static void |
Kristian Høgsberg | 27e3052 | 2012-04-11 23:18:23 -0400 | [diff] [blame] | 3272 | shell_handle_surface_destroy(struct wl_listener *listener, void *data) |
Pekka Paalanen | 9d1613e | 2011-11-25 12:09:16 +0200 | [diff] [blame] | 3273 | { |
| 3274 | struct shell_surface *shsurf = container_of(listener, |
| 3275 | struct shell_surface, |
| 3276 | surface_destroy_listener); |
| 3277 | |
Jason Ekstrand | 651f00e | 2013-06-14 10:07:54 -0500 | [diff] [blame] | 3278 | if (shsurf->resource) |
| 3279 | wl_resource_destroy(shsurf->resource); |
Ander Conselvan de Oliveira | 15f9a26 | 2014-04-29 17:54:02 +0300 | [diff] [blame] | 3280 | |
| 3281 | destroy_shell_surface(shsurf); |
Pekka Paalanen | 9d1613e | 2011-11-25 12:09:16 +0200 | [diff] [blame] | 3282 | } |
| 3283 | |
Kristian Høgsberg | d813445 | 2012-06-21 12:49:02 -0400 | [diff] [blame] | 3284 | static void |
Kristian Høgsberg | 160fe75 | 2014-03-11 10:19:10 -0700 | [diff] [blame] | 3285 | fade_out_done(struct weston_view_animation *animation, void *data) |
| 3286 | { |
| 3287 | struct shell_surface *shsurf = data; |
| 3288 | |
| 3289 | weston_surface_destroy(shsurf->surface); |
| 3290 | } |
| 3291 | |
| 3292 | static void |
| 3293 | handle_resource_destroy(struct wl_listener *listener, void *data) |
| 3294 | { |
| 3295 | struct shell_surface *shsurf = |
| 3296 | container_of(listener, struct shell_surface, |
| 3297 | resource_destroy_listener); |
| 3298 | |
Ander Conselvan de Oliveira | 15f9a26 | 2014-04-29 17:54:02 +0300 | [diff] [blame] | 3299 | if (!weston_surface_is_mapped(shsurf->surface)) |
| 3300 | return; |
| 3301 | |
Kristian Høgsberg | 160fe75 | 2014-03-11 10:19:10 -0700 | [diff] [blame] | 3302 | shsurf->surface->ref_count++; |
| 3303 | |
| 3304 | pixman_region32_fini(&shsurf->surface->pending.input); |
| 3305 | pixman_region32_init(&shsurf->surface->pending.input); |
| 3306 | pixman_region32_fini(&shsurf->surface->input); |
| 3307 | pixman_region32_init(&shsurf->surface->input); |
Jonny Lamb | f322f8e | 2014-08-12 15:13:30 +0200 | [diff] [blame] | 3308 | if (shsurf->shell->win_close_animation_type == ANIMATION_FADE) { |
| 3309 | weston_fade_run(shsurf->view, 1.0, 0.0, 300.0, |
| 3310 | fade_out_done, shsurf); |
| 3311 | } else { |
| 3312 | weston_surface_destroy(shsurf->surface); |
| 3313 | } |
Kristian Høgsberg | 160fe75 | 2014-03-11 10:19:10 -0700 | [diff] [blame] | 3314 | } |
| 3315 | |
| 3316 | static void |
Jason Ekstrand | 918f2dd | 2013-12-02 21:01:53 -0600 | [diff] [blame] | 3317 | shell_surface_configure(struct weston_surface *, int32_t, int32_t); |
Kristian Høgsberg | d813445 | 2012-06-21 12:49:02 -0400 | [diff] [blame] | 3318 | |
Kristian Høgsberg | 1ef2313 | 2013-12-04 00:20:01 -0800 | [diff] [blame] | 3319 | struct shell_surface * |
Kristian Høgsberg | 8334bc1 | 2012-01-03 10:29:47 -0500 | [diff] [blame] | 3320 | get_shell_surface(struct weston_surface *surface) |
Pekka Paalanen | ec2b32f | 2011-11-28 15:12:34 +0200 | [diff] [blame] | 3321 | { |
Kristian Høgsberg | d813445 | 2012-06-21 12:49:02 -0400 | [diff] [blame] | 3322 | if (surface->configure == shell_surface_configure) |
Giulio Camuffo | 7fe01b1 | 2013-03-28 18:02:42 +0100 | [diff] [blame] | 3323 | return surface->configure_private; |
Kristian Høgsberg | d813445 | 2012-06-21 12:49:02 -0400 | [diff] [blame] | 3324 | else |
| 3325 | return NULL; |
Pekka Paalanen | ec2b32f | 2011-11-28 15:12:34 +0200 | [diff] [blame] | 3326 | } |
| 3327 | |
Rafael Antognolli | e2a3455 | 2013-12-03 15:35:45 -0200 | [diff] [blame] | 3328 | static struct shell_surface * |
Jason Ekstrand | 9e9512f | 2014-04-16 21:12:10 -0500 | [diff] [blame] | 3329 | create_common_surface(struct shell_client *owner, void *shell, |
| 3330 | struct weston_surface *surface, |
Rafael Antognolli | e2a3455 | 2013-12-03 15:35:45 -0200 | [diff] [blame] | 3331 | const struct weston_shell_client *client) |
Pekka Paalanen | 9d1613e | 2011-11-25 12:09:16 +0200 | [diff] [blame] | 3332 | { |
Pekka Paalanen | 9d1613e | 2011-11-25 12:09:16 +0200 | [diff] [blame] | 3333 | struct shell_surface *shsurf; |
| 3334 | |
Ander Conselvan de Oliveira | 093bfa3 | 2012-03-27 17:36:41 +0300 | [diff] [blame] | 3335 | if (surface->configure) { |
Martin Minarik | 6d11836 | 2012-06-07 18:01:59 +0200 | [diff] [blame] | 3336 | weston_log("surface->configure already set\n"); |
Kristian Høgsberg | 45ba869 | 2012-05-21 14:27:33 -0400 | [diff] [blame] | 3337 | return NULL; |
Ander Conselvan de Oliveira | 093bfa3 | 2012-03-27 17:36:41 +0300 | [diff] [blame] | 3338 | } |
| 3339 | |
Pekka Paalanen | 9d1613e | 2011-11-25 12:09:16 +0200 | [diff] [blame] | 3340 | shsurf = calloc(1, sizeof *shsurf); |
| 3341 | if (!shsurf) { |
Martin Minarik | 6d11836 | 2012-06-07 18:01:59 +0200 | [diff] [blame] | 3342 | weston_log("no memory to allocate shell surface\n"); |
Kristian Høgsberg | 45ba869 | 2012-05-21 14:27:33 -0400 | [diff] [blame] | 3343 | return NULL; |
Pekka Paalanen | 9d1613e | 2011-11-25 12:09:16 +0200 | [diff] [blame] | 3344 | } |
| 3345 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 3346 | shsurf->view = weston_view_create(surface); |
| 3347 | if (!shsurf->view) { |
| 3348 | weston_log("no memory to allocate shell surface\n"); |
| 3349 | free(shsurf); |
| 3350 | return NULL; |
| 3351 | } |
| 3352 | |
Ander Conselvan de Oliveira | 093bfa3 | 2012-03-27 17:36:41 +0300 | [diff] [blame] | 3353 | surface->configure = shell_surface_configure; |
Giulio Camuffo | 7fe01b1 | 2013-03-28 18:02:42 +0100 | [diff] [blame] | 3354 | surface->configure_private = shsurf; |
Ander Conselvan de Oliveira | 093bfa3 | 2012-03-27 17:36:41 +0300 | [diff] [blame] | 3355 | |
Kristian Høgsberg | 160fe75 | 2014-03-11 10:19:10 -0700 | [diff] [blame] | 3356 | shsurf->resource_destroy_listener.notify = handle_resource_destroy; |
| 3357 | wl_resource_add_destroy_listener(surface->resource, |
| 3358 | &shsurf->resource_destroy_listener); |
Jason Ekstrand | 9e9512f | 2014-04-16 21:12:10 -0500 | [diff] [blame] | 3359 | shsurf->owner = owner; |
Kristian Høgsberg | 160fe75 | 2014-03-11 10:19:10 -0700 | [diff] [blame] | 3360 | |
Tiago Vignatti | bc052c9 | 2012-04-19 16:18:18 +0300 | [diff] [blame] | 3361 | shsurf->shell = (struct desktop_shell *) shell; |
Scott Moreau | ff1db4a | 2012-04-17 19:06:18 -0600 | [diff] [blame] | 3362 | shsurf->unresponsive = 0; |
Alex Wu | 4539b08 | 2012-03-01 12:57:46 +0800 | [diff] [blame] | 3363 | shsurf->saved_position_valid = false; |
Rafael Antognolli | 3c4e3f7 | 2013-12-03 15:35:46 -0200 | [diff] [blame] | 3364 | shsurf->saved_size_valid = false; |
Alex Wu | 7bcb8bd | 2012-04-27 09:07:24 +0800 | [diff] [blame] | 3365 | shsurf->saved_rotation_valid = false; |
Pekka Paalanen | 9d1613e | 2011-11-25 12:09:16 +0200 | [diff] [blame] | 3366 | shsurf->surface = surface; |
Alex Wu | 4539b08 | 2012-03-01 12:57:46 +0800 | [diff] [blame] | 3367 | shsurf->fullscreen.type = WL_SHELL_SURFACE_FULLSCREEN_METHOD_DEFAULT; |
| 3368 | shsurf->fullscreen.framerate = 0; |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 3369 | shsurf->fullscreen.black_view = NULL; |
Alex Wu | 4539b08 | 2012-03-01 12:57:46 +0800 | [diff] [blame] | 3370 | wl_list_init(&shsurf->fullscreen.transform.link); |
| 3371 | |
Jasper St. Pierre | 9aa8ce6 | 2014-04-11 16:18:54 -0700 | [diff] [blame] | 3372 | shsurf->output = get_default_output(shsurf->shell->compositor); |
| 3373 | |
Jason Ekstrand | 651f00e | 2013-06-14 10:07:54 -0500 | [diff] [blame] | 3374 | wl_signal_init(&shsurf->destroy_signal); |
Kristian Høgsberg | 27e3052 | 2012-04-11 23:18:23 -0400 | [diff] [blame] | 3375 | shsurf->surface_destroy_listener.notify = shell_handle_surface_destroy; |
Jason Ekstrand | 26ed73c | 2013-06-06 22:34:41 -0500 | [diff] [blame] | 3376 | wl_signal_add(&surface->destroy_signal, |
Kristian Høgsberg | 27e3052 | 2012-04-11 23:18:23 -0400 | [diff] [blame] | 3377 | &shsurf->surface_destroy_listener); |
Pekka Paalanen | 9d1613e | 2011-11-25 12:09:16 +0200 | [diff] [blame] | 3378 | |
| 3379 | /* init link so its safe to always remove it in destroy_shell_surface */ |
| 3380 | wl_list_init(&shsurf->link); |
Giulio Camuffo | 5085a75 | 2013-03-25 21:42:45 +0100 | [diff] [blame] | 3381 | wl_list_init(&shsurf->popup.grab_link); |
Pekka Paalanen | 9d1613e | 2011-11-25 12:09:16 +0200 | [diff] [blame] | 3382 | |
Pekka Paalanen | 460099f | 2012-01-20 16:48:25 +0200 | [diff] [blame] | 3383 | /* empty when not in use */ |
| 3384 | wl_list_init(&shsurf->rotation.transform.link); |
Kristian Høgsberg | 765e27b | 2012-01-27 13:36:13 -0500 | [diff] [blame] | 3385 | weston_matrix_init(&shsurf->rotation.rotation); |
Pekka Paalanen | 460099f | 2012-01-20 16:48:25 +0200 | [diff] [blame] | 3386 | |
Jonas Ådahl | 62fcd04 | 2012-06-13 00:01:23 +0200 | [diff] [blame] | 3387 | wl_list_init(&shsurf->workspace_transform.link); |
| 3388 | |
Philip Withnall | 648a4dd | 2013-11-25 18:01:44 +0000 | [diff] [blame] | 3389 | wl_list_init(&shsurf->children_link); |
| 3390 | wl_list_init(&shsurf->children_list); |
| 3391 | shsurf->parent = NULL; |
| 3392 | |
Pekka Paalanen | 9826223 | 2011-12-01 10:42:22 +0200 | [diff] [blame] | 3393 | shsurf->type = SHELL_SURFACE_NONE; |
Pekka Paalanen | 9d1613e | 2011-11-25 12:09:16 +0200 | [diff] [blame] | 3394 | |
Kristian Høgsberg | a61ca06 | 2012-05-22 16:05:52 -0400 | [diff] [blame] | 3395 | shsurf->client = client; |
| 3396 | |
Kristian Høgsberg | 45ba869 | 2012-05-21 14:27:33 -0400 | [diff] [blame] | 3397 | return shsurf; |
Tiago Vignatti | bc052c9 | 2012-04-19 16:18:18 +0300 | [diff] [blame] | 3398 | } |
| 3399 | |
Rafael Antognolli | e2a3455 | 2013-12-03 15:35:45 -0200 | [diff] [blame] | 3400 | static struct shell_surface * |
| 3401 | create_shell_surface(void *shell, struct weston_surface *surface, |
| 3402 | const struct weston_shell_client *client) |
| 3403 | { |
Jason Ekstrand | 9e9512f | 2014-04-16 21:12:10 -0500 | [diff] [blame] | 3404 | return create_common_surface(NULL, shell, surface, client); |
Rafael Antognolli | e2a3455 | 2013-12-03 15:35:45 -0200 | [diff] [blame] | 3405 | } |
| 3406 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 3407 | static struct weston_view * |
| 3408 | get_primary_view(void *shell, struct shell_surface *shsurf) |
| 3409 | { |
| 3410 | return shsurf->view; |
| 3411 | } |
| 3412 | |
Tiago Vignatti | bc052c9 | 2012-04-19 16:18:18 +0300 | [diff] [blame] | 3413 | static void |
| 3414 | shell_get_shell_surface(struct wl_client *client, |
| 3415 | struct wl_resource *resource, |
| 3416 | uint32_t id, |
| 3417 | struct wl_resource *surface_resource) |
| 3418 | { |
Jason Ekstrand | 0f2ef7e | 2013-06-14 10:07:53 -0500 | [diff] [blame] | 3419 | struct weston_surface *surface = |
| 3420 | wl_resource_get_user_data(surface_resource); |
Jason Ekstrand | 9e9512f | 2014-04-16 21:12:10 -0500 | [diff] [blame] | 3421 | struct shell_client *sc = wl_resource_get_user_data(resource); |
| 3422 | struct desktop_shell *shell = sc->shell; |
Tiago Vignatti | bc052c9 | 2012-04-19 16:18:18 +0300 | [diff] [blame] | 3423 | struct shell_surface *shsurf; |
| 3424 | |
| 3425 | if (get_shell_surface(surface)) { |
| 3426 | wl_resource_post_error(surface_resource, |
Kristian Høgsberg | 9540ea6 | 2012-05-21 14:28:57 -0400 | [diff] [blame] | 3427 | WL_DISPLAY_ERROR_INVALID_OBJECT, |
| 3428 | "desktop_shell::get_shell_surface already requested"); |
Tiago Vignatti | bc052c9 | 2012-04-19 16:18:18 +0300 | [diff] [blame] | 3429 | return; |
| 3430 | } |
| 3431 | |
Jason Ekstrand | 9e9512f | 2014-04-16 21:12:10 -0500 | [diff] [blame] | 3432 | shsurf = create_common_surface(sc, shell, surface, &shell_client); |
Kristian Høgsberg | 9540ea6 | 2012-05-21 14:28:57 -0400 | [diff] [blame] | 3433 | if (!shsurf) { |
| 3434 | wl_resource_post_error(surface_resource, |
| 3435 | WL_DISPLAY_ERROR_INVALID_OBJECT, |
| 3436 | "surface->configure already set"); |
| 3437 | return; |
| 3438 | } |
Tiago Vignatti | bc052c9 | 2012-04-19 16:18:18 +0300 | [diff] [blame] | 3439 | |
Jason Ekstrand | a85118c | 2013-06-27 20:17:02 -0500 | [diff] [blame] | 3440 | shsurf->resource = |
| 3441 | wl_resource_create(client, |
| 3442 | &wl_shell_surface_interface, 1, id); |
| 3443 | wl_resource_set_implementation(shsurf->resource, |
| 3444 | &shell_surface_implementation, |
| 3445 | shsurf, shell_destroy_shell_surface); |
Pekka Paalanen | 9d1613e | 2011-11-25 12:09:16 +0200 | [diff] [blame] | 3446 | } |
| 3447 | |
Rafael Antognolli | e2a3455 | 2013-12-03 15:35:45 -0200 | [diff] [blame] | 3448 | static bool |
| 3449 | shell_surface_is_wl_shell_surface(struct shell_surface *shsurf) |
| 3450 | { |
Kristian Høgsberg | 0b7d995 | 2014-02-03 15:50:38 -0800 | [diff] [blame] | 3451 | /* A shell surface without a resource is created from xwayland |
| 3452 | * and is considered a wl_shell surface for now. */ |
| 3453 | |
| 3454 | return shsurf->resource == NULL || |
| 3455 | wl_resource_instance_of(shsurf->resource, |
| 3456 | &wl_shell_surface_interface, |
| 3457 | &shell_surface_implementation); |
Rafael Antognolli | e2a3455 | 2013-12-03 15:35:45 -0200 | [diff] [blame] | 3458 | } |
| 3459 | |
Pekka Paalanen | 9d1613e | 2011-11-25 12:09:16 +0200 | [diff] [blame] | 3460 | static const struct wl_shell_interface shell_implementation = { |
Pekka Paalanen | 4622967 | 2011-11-29 15:49:31 +0200 | [diff] [blame] | 3461 | shell_get_shell_surface |
Kristian Høgsberg | 4cca349 | 2011-01-18 07:53:49 -0500 | [diff] [blame] | 3462 | }; |
| 3463 | |
Rafael Antognolli | e2a3455 | 2013-12-03 15:35:45 -0200 | [diff] [blame] | 3464 | /**************************** |
| 3465 | * xdg-shell implementation */ |
| 3466 | |
| 3467 | static void |
| 3468 | xdg_surface_destroy(struct wl_client *client, |
| 3469 | struct wl_resource *resource) |
| 3470 | { |
| 3471 | wl_resource_destroy(resource); |
| 3472 | } |
| 3473 | |
| 3474 | static void |
Jasper St. Pierre | c815d62 | 2014-04-10 18:37:54 -0700 | [diff] [blame] | 3475 | xdg_surface_set_parent(struct wl_client *client, |
| 3476 | struct wl_resource *resource, |
| 3477 | struct wl_resource *parent_resource) |
Jasper St. Pierre | 63a9c33 | 2014-02-01 18:35:15 -0500 | [diff] [blame] | 3478 | { |
| 3479 | struct shell_surface *shsurf = wl_resource_get_user_data(resource); |
| 3480 | struct weston_surface *parent; |
| 3481 | |
| 3482 | if (parent_resource) |
| 3483 | parent = wl_resource_get_user_data(parent_resource); |
| 3484 | else |
| 3485 | parent = NULL; |
| 3486 | |
| 3487 | shell_surface_set_parent(shsurf, parent); |
| 3488 | } |
| 3489 | |
| 3490 | static void |
Rafael Antognolli | e2a3455 | 2013-12-03 15:35:45 -0200 | [diff] [blame] | 3491 | xdg_surface_set_app_id(struct wl_client *client, |
| 3492 | struct wl_resource *resource, |
| 3493 | const char *app_id) |
| 3494 | { |
| 3495 | struct shell_surface *shsurf = wl_resource_get_user_data(resource); |
| 3496 | |
| 3497 | free(shsurf->class); |
| 3498 | shsurf->class = strdup(app_id); |
| 3499 | } |
| 3500 | |
| 3501 | static void |
Jasper St. Pierre | 81ff075 | 2014-03-13 11:04:53 -0400 | [diff] [blame] | 3502 | xdg_surface_show_window_menu(struct wl_client *client, |
| 3503 | struct wl_resource *surface_resource, |
| 3504 | struct wl_resource *seat_resource, |
| 3505 | uint32_t serial, |
| 3506 | int32_t x, |
| 3507 | int32_t y) |
| 3508 | { |
| 3509 | /* TODO */ |
| 3510 | } |
| 3511 | |
| 3512 | static void |
Rafael Antognolli | e2a3455 | 2013-12-03 15:35:45 -0200 | [diff] [blame] | 3513 | xdg_surface_set_title(struct wl_client *client, |
| 3514 | struct wl_resource *resource, const char *title) |
| 3515 | { |
| 3516 | struct shell_surface *shsurf = wl_resource_get_user_data(resource); |
| 3517 | |
| 3518 | set_title(shsurf, title); |
| 3519 | } |
| 3520 | |
| 3521 | static void |
| 3522 | xdg_surface_move(struct wl_client *client, struct wl_resource *resource, |
| 3523 | struct wl_resource *seat_resource, uint32_t serial) |
| 3524 | { |
| 3525 | common_surface_move(resource, seat_resource, serial); |
| 3526 | } |
| 3527 | |
| 3528 | static void |
| 3529 | xdg_surface_resize(struct wl_client *client, struct wl_resource *resource, |
| 3530 | struct wl_resource *seat_resource, uint32_t serial, |
| 3531 | uint32_t edges) |
| 3532 | { |
| 3533 | common_surface_resize(resource, seat_resource, serial, edges); |
| 3534 | } |
| 3535 | |
| 3536 | static void |
Jasper St. Pierre | ab2c108 | 2014-04-10 10:41:46 -0700 | [diff] [blame] | 3537 | xdg_surface_ack_configure(struct wl_client *client, |
| 3538 | struct wl_resource *resource, |
| 3539 | uint32_t serial) |
Rafael Antognolli | e2a3455 | 2013-12-03 15:35:45 -0200 | [diff] [blame] | 3540 | { |
| 3541 | struct shell_surface *shsurf = wl_resource_get_user_data(resource); |
| 3542 | |
Jasper St. Pierre | 8c6aa45 | 2014-02-08 18:29:49 -0500 | [diff] [blame] | 3543 | if (shsurf->state_requested) { |
| 3544 | shsurf->next_state = shsurf->requested_state; |
| 3545 | shsurf->state_changed = true; |
| 3546 | shsurf->state_requested = false; |
Rafael Antognolli | 3c4e3f7 | 2013-12-03 15:35:46 -0200 | [diff] [blame] | 3547 | } |
Rafael Antognolli | e2a3455 | 2013-12-03 15:35:45 -0200 | [diff] [blame] | 3548 | } |
| 3549 | |
Manuel Bachmann | 50c87db | 2014-02-26 15:52:13 +0100 | [diff] [blame] | 3550 | static void |
Jasper St. Pierre | ccf48fb | 2014-05-02 10:21:38 -0400 | [diff] [blame] | 3551 | xdg_surface_set_window_geometry(struct wl_client *client, |
| 3552 | struct wl_resource *resource, |
| 3553 | int32_t x, |
| 3554 | int32_t y, |
| 3555 | int32_t width, |
| 3556 | int32_t height) |
| 3557 | { |
| 3558 | struct shell_surface *shsurf = wl_resource_get_user_data(resource); |
| 3559 | |
| 3560 | set_window_geometry(shsurf, x, y, width, height); |
| 3561 | } |
| 3562 | |
| 3563 | static void |
Jasper St. Pierre | ab2c108 | 2014-04-10 10:41:46 -0700 | [diff] [blame] | 3564 | xdg_surface_set_maximized(struct wl_client *client, |
| 3565 | struct wl_resource *resource) |
| 3566 | { |
| 3567 | struct shell_surface *shsurf = wl_resource_get_user_data(resource); |
| 3568 | |
| 3569 | shsurf->state_requested = true; |
| 3570 | shsurf->requested_state.maximized = true; |
Jasper St. Pierre | 9aa8ce6 | 2014-04-11 16:18:54 -0700 | [diff] [blame] | 3571 | send_configure_for_surface(shsurf); |
Jasper St. Pierre | ab2c108 | 2014-04-10 10:41:46 -0700 | [diff] [blame] | 3572 | } |
| 3573 | |
| 3574 | static void |
| 3575 | xdg_surface_unset_maximized(struct wl_client *client, |
| 3576 | struct wl_resource *resource) |
| 3577 | { |
| 3578 | struct shell_surface *shsurf = wl_resource_get_user_data(resource); |
| 3579 | |
| 3580 | shsurf->state_requested = true; |
| 3581 | shsurf->requested_state.maximized = false; |
Jasper St. Pierre | 6458ec3 | 2014-04-11 16:00:31 -0700 | [diff] [blame] | 3582 | send_configure_for_surface(shsurf); |
Jasper St. Pierre | ab2c108 | 2014-04-10 10:41:46 -0700 | [diff] [blame] | 3583 | } |
| 3584 | |
| 3585 | static void |
| 3586 | xdg_surface_set_fullscreen(struct wl_client *client, |
| 3587 | struct wl_resource *resource, |
| 3588 | struct wl_resource *output_resource) |
| 3589 | { |
| 3590 | struct shell_surface *shsurf = wl_resource_get_user_data(resource); |
| 3591 | struct weston_output *output; |
| 3592 | |
| 3593 | shsurf->state_requested = true; |
| 3594 | shsurf->requested_state.fullscreen = true; |
| 3595 | |
| 3596 | if (output_resource) |
| 3597 | output = wl_resource_get_user_data(output_resource); |
| 3598 | else |
| 3599 | output = NULL; |
| 3600 | |
Jasper St. Pierre | 9aa8ce6 | 2014-04-11 16:18:54 -0700 | [diff] [blame] | 3601 | shell_surface_set_output(shsurf, output); |
| 3602 | shsurf->fullscreen_output = shsurf->output; |
Jasper St. Pierre | ab2c108 | 2014-04-10 10:41:46 -0700 | [diff] [blame] | 3603 | |
Jasper St. Pierre | 9aa8ce6 | 2014-04-11 16:18:54 -0700 | [diff] [blame] | 3604 | send_configure_for_surface(shsurf); |
Jasper St. Pierre | ab2c108 | 2014-04-10 10:41:46 -0700 | [diff] [blame] | 3605 | } |
| 3606 | |
| 3607 | static void |
| 3608 | xdg_surface_unset_fullscreen(struct wl_client *client, |
| 3609 | struct wl_resource *resource) |
| 3610 | { |
| 3611 | struct shell_surface *shsurf = wl_resource_get_user_data(resource); |
| 3612 | |
| 3613 | shsurf->state_requested = true; |
| 3614 | shsurf->requested_state.fullscreen = false; |
Jasper St. Pierre | 6458ec3 | 2014-04-11 16:00:31 -0700 | [diff] [blame] | 3615 | send_configure_for_surface(shsurf); |
Jasper St. Pierre | ab2c108 | 2014-04-10 10:41:46 -0700 | [diff] [blame] | 3616 | } |
| 3617 | |
| 3618 | static void |
Manuel Bachmann | 50c87db | 2014-02-26 15:52:13 +0100 | [diff] [blame] | 3619 | xdg_surface_set_minimized(struct wl_client *client, |
| 3620 | struct wl_resource *resource) |
| 3621 | { |
| 3622 | struct shell_surface *shsurf = wl_resource_get_user_data(resource); |
| 3623 | |
| 3624 | if (shsurf->type != SHELL_SURFACE_TOPLEVEL) |
| 3625 | return; |
| 3626 | |
| 3627 | /* apply compositor's own minimization logic (hide) */ |
| 3628 | set_minimized(shsurf->surface, 1); |
| 3629 | } |
| 3630 | |
Rafael Antognolli | e2a3455 | 2013-12-03 15:35:45 -0200 | [diff] [blame] | 3631 | static const struct xdg_surface_interface xdg_surface_implementation = { |
| 3632 | xdg_surface_destroy, |
Jasper St. Pierre | c815d62 | 2014-04-10 18:37:54 -0700 | [diff] [blame] | 3633 | xdg_surface_set_parent, |
Rafael Antognolli | e2a3455 | 2013-12-03 15:35:45 -0200 | [diff] [blame] | 3634 | xdg_surface_set_title, |
| 3635 | xdg_surface_set_app_id, |
Jasper St. Pierre | 81ff075 | 2014-03-13 11:04:53 -0400 | [diff] [blame] | 3636 | xdg_surface_show_window_menu, |
Rafael Antognolli | e2a3455 | 2013-12-03 15:35:45 -0200 | [diff] [blame] | 3637 | xdg_surface_move, |
| 3638 | xdg_surface_resize, |
Jasper St. Pierre | ab2c108 | 2014-04-10 10:41:46 -0700 | [diff] [blame] | 3639 | xdg_surface_ack_configure, |
Jasper St. Pierre | ccf48fb | 2014-05-02 10:21:38 -0400 | [diff] [blame] | 3640 | xdg_surface_set_window_geometry, |
Jasper St. Pierre | ab2c108 | 2014-04-10 10:41:46 -0700 | [diff] [blame] | 3641 | xdg_surface_set_maximized, |
| 3642 | xdg_surface_unset_maximized, |
| 3643 | xdg_surface_set_fullscreen, |
| 3644 | xdg_surface_unset_fullscreen, |
| 3645 | xdg_surface_set_minimized, |
Rafael Antognolli | e2a3455 | 2013-12-03 15:35:45 -0200 | [diff] [blame] | 3646 | }; |
| 3647 | |
| 3648 | static void |
| 3649 | xdg_send_configure(struct weston_surface *surface, |
Jasper St. Pierre | ac985be | 2014-04-28 11:19:28 -0400 | [diff] [blame] | 3650 | int32_t width, int32_t height) |
Rafael Antognolli | e2a3455 | 2013-12-03 15:35:45 -0200 | [diff] [blame] | 3651 | { |
| 3652 | struct shell_surface *shsurf = get_shell_surface(surface); |
Jasper St. Pierre | ab2c108 | 2014-04-10 10:41:46 -0700 | [diff] [blame] | 3653 | uint32_t *s; |
| 3654 | struct wl_array states; |
| 3655 | uint32_t serial; |
Rafael Antognolli | e2a3455 | 2013-12-03 15:35:45 -0200 | [diff] [blame] | 3656 | |
U. Artie Eoff | cf5737a | 2014-01-17 10:08:25 -0800 | [diff] [blame] | 3657 | assert(shsurf); |
| 3658 | |
Jasper St. Pierre | ab2c108 | 2014-04-10 10:41:46 -0700 | [diff] [blame] | 3659 | if (!shsurf->resource) |
| 3660 | return; |
| 3661 | |
| 3662 | wl_array_init(&states); |
| 3663 | if (shsurf->requested_state.fullscreen) { |
| 3664 | s = wl_array_add(&states, sizeof *s); |
| 3665 | *s = XDG_SURFACE_STATE_FULLSCREEN; |
| 3666 | } else if (shsurf->requested_state.maximized) { |
| 3667 | s = wl_array_add(&states, sizeof *s); |
| 3668 | *s = XDG_SURFACE_STATE_MAXIMIZED; |
| 3669 | } |
Jasper St. Pierre | 5befdda | 2014-05-06 08:50:47 -0400 | [diff] [blame] | 3670 | if (shsurf->resize_edges != 0) { |
| 3671 | s = wl_array_add(&states, sizeof *s); |
| 3672 | *s = XDG_SURFACE_STATE_RESIZING; |
| 3673 | } |
Jasper St. Pierre | 973d787 | 2014-05-06 08:44:29 -0400 | [diff] [blame] | 3674 | if (shsurf->focus_count > 0) { |
| 3675 | s = wl_array_add(&states, sizeof *s); |
| 3676 | *s = XDG_SURFACE_STATE_ACTIVATED; |
| 3677 | } |
Jasper St. Pierre | ab2c108 | 2014-04-10 10:41:46 -0700 | [diff] [blame] | 3678 | |
| 3679 | serial = wl_display_next_serial(shsurf->surface->compositor->wl_display); |
| 3680 | xdg_surface_send_configure(shsurf->resource, width, height, &states, serial); |
| 3681 | |
| 3682 | wl_array_release(&states); |
Rafael Antognolli | e2a3455 | 2013-12-03 15:35:45 -0200 | [diff] [blame] | 3683 | } |
| 3684 | |
| 3685 | static const struct weston_shell_client xdg_client = { |
| 3686 | xdg_send_configure |
| 3687 | }; |
| 3688 | |
| 3689 | static void |
| 3690 | xdg_use_unstable_version(struct wl_client *client, |
| 3691 | struct wl_resource *resource, |
| 3692 | int32_t version) |
| 3693 | { |
| 3694 | if (version > 1) { |
| 3695 | wl_resource_post_error(resource, |
| 3696 | 1, |
| 3697 | "xdg-shell:: version not implemented yet."); |
| 3698 | return; |
| 3699 | } |
| 3700 | } |
| 3701 | |
| 3702 | static struct shell_surface * |
Jason Ekstrand | 9e9512f | 2014-04-16 21:12:10 -0500 | [diff] [blame] | 3703 | create_xdg_surface(struct shell_client *owner, void *shell, |
| 3704 | struct weston_surface *surface, |
Rafael Antognolli | e2a3455 | 2013-12-03 15:35:45 -0200 | [diff] [blame] | 3705 | const struct weston_shell_client *client) |
| 3706 | { |
| 3707 | struct shell_surface *shsurf; |
Rafael Antognolli | e2a3455 | 2013-12-03 15:35:45 -0200 | [diff] [blame] | 3708 | |
Jason Ekstrand | 9e9512f | 2014-04-16 21:12:10 -0500 | [diff] [blame] | 3709 | shsurf = create_common_surface(owner, shell, surface, client); |
Kristian Høgsberg | c8f8dd8 | 2013-12-05 23:20:33 -0800 | [diff] [blame] | 3710 | shsurf->type = SHELL_SURFACE_TOPLEVEL; |
Rafael Antognolli | e2a3455 | 2013-12-03 15:35:45 -0200 | [diff] [blame] | 3711 | |
| 3712 | return shsurf; |
| 3713 | } |
| 3714 | |
| 3715 | static void |
| 3716 | xdg_get_xdg_surface(struct wl_client *client, |
| 3717 | struct wl_resource *resource, |
| 3718 | uint32_t id, |
| 3719 | struct wl_resource *surface_resource) |
| 3720 | { |
| 3721 | struct weston_surface *surface = |
| 3722 | wl_resource_get_user_data(surface_resource); |
Kristian Høgsberg | 2bff94e | 2014-02-11 12:22:51 -0800 | [diff] [blame] | 3723 | struct shell_client *sc = wl_resource_get_user_data(resource); |
| 3724 | struct desktop_shell *shell = sc->shell; |
Rafael Antognolli | e2a3455 | 2013-12-03 15:35:45 -0200 | [diff] [blame] | 3725 | struct shell_surface *shsurf; |
| 3726 | |
| 3727 | if (get_shell_surface(surface)) { |
| 3728 | wl_resource_post_error(surface_resource, |
| 3729 | WL_DISPLAY_ERROR_INVALID_OBJECT, |
Jasper St. Pierre | fe9671e | 2014-03-25 13:31:44 -0400 | [diff] [blame] | 3730 | "xdg_shell::get_xdg_surface already requested"); |
Rafael Antognolli | e2a3455 | 2013-12-03 15:35:45 -0200 | [diff] [blame] | 3731 | return; |
| 3732 | } |
| 3733 | |
Jason Ekstrand | 9e9512f | 2014-04-16 21:12:10 -0500 | [diff] [blame] | 3734 | shsurf = create_xdg_surface(sc, shell, surface, &xdg_client); |
Rafael Antognolli | e2a3455 | 2013-12-03 15:35:45 -0200 | [diff] [blame] | 3735 | if (!shsurf) { |
| 3736 | wl_resource_post_error(surface_resource, |
| 3737 | WL_DISPLAY_ERROR_INVALID_OBJECT, |
| 3738 | "surface->configure already set"); |
| 3739 | return; |
| 3740 | } |
| 3741 | |
| 3742 | shsurf->resource = |
| 3743 | wl_resource_create(client, |
| 3744 | &xdg_surface_interface, 1, id); |
| 3745 | wl_resource_set_implementation(shsurf->resource, |
| 3746 | &xdg_surface_implementation, |
| 3747 | shsurf, shell_destroy_shell_surface); |
| 3748 | } |
| 3749 | |
| 3750 | static bool |
| 3751 | shell_surface_is_xdg_surface(struct shell_surface *shsurf) |
| 3752 | { |
Kristian Høgsberg | 0b7d995 | 2014-02-03 15:50:38 -0800 | [diff] [blame] | 3753 | return shsurf->resource && |
| 3754 | wl_resource_instance_of(shsurf->resource, |
| 3755 | &xdg_surface_interface, |
| 3756 | &xdg_surface_implementation); |
Rafael Antognolli | e2a3455 | 2013-12-03 15:35:45 -0200 | [diff] [blame] | 3757 | } |
| 3758 | |
| 3759 | /* xdg-popup implementation */ |
| 3760 | |
| 3761 | static void |
| 3762 | xdg_popup_destroy(struct wl_client *client, |
| 3763 | struct wl_resource *resource) |
| 3764 | { |
| 3765 | wl_resource_destroy(resource); |
| 3766 | } |
| 3767 | |
Rafael Antognolli | e2a3455 | 2013-12-03 15:35:45 -0200 | [diff] [blame] | 3768 | static const struct xdg_popup_interface xdg_popup_implementation = { |
| 3769 | xdg_popup_destroy, |
Rafael Antognolli | e2a3455 | 2013-12-03 15:35:45 -0200 | [diff] [blame] | 3770 | }; |
| 3771 | |
| 3772 | static void |
| 3773 | xdg_popup_send_configure(struct weston_surface *surface, |
Jasper St. Pierre | ac985be | 2014-04-28 11:19:28 -0400 | [diff] [blame] | 3774 | int32_t width, int32_t height) |
Rafael Antognolli | e2a3455 | 2013-12-03 15:35:45 -0200 | [diff] [blame] | 3775 | { |
| 3776 | } |
| 3777 | |
| 3778 | static const struct weston_shell_client xdg_popup_client = { |
| 3779 | xdg_popup_send_configure |
| 3780 | }; |
| 3781 | |
| 3782 | static struct shell_surface * |
Jason Ekstrand | 9e9512f | 2014-04-16 21:12:10 -0500 | [diff] [blame] | 3783 | create_xdg_popup(struct shell_client *owner, void *shell, |
| 3784 | struct weston_surface *surface, |
Rafael Antognolli | e2a3455 | 2013-12-03 15:35:45 -0200 | [diff] [blame] | 3785 | const struct weston_shell_client *client, |
| 3786 | struct weston_surface *parent, |
| 3787 | struct shell_seat *seat, |
| 3788 | uint32_t serial, |
| 3789 | int32_t x, int32_t y) |
| 3790 | { |
| 3791 | struct shell_surface *shsurf; |
Rafael Antognolli | e2a3455 | 2013-12-03 15:35:45 -0200 | [diff] [blame] | 3792 | |
Jason Ekstrand | 9e9512f | 2014-04-16 21:12:10 -0500 | [diff] [blame] | 3793 | shsurf = create_common_surface(owner, shell, surface, client); |
Kristian Høgsberg | c8f8dd8 | 2013-12-05 23:20:33 -0800 | [diff] [blame] | 3794 | shsurf->type = SHELL_SURFACE_POPUP; |
Rafael Antognolli | e2a3455 | 2013-12-03 15:35:45 -0200 | [diff] [blame] | 3795 | shsurf->popup.shseat = seat; |
| 3796 | shsurf->popup.serial = serial; |
| 3797 | shsurf->popup.x = x; |
| 3798 | shsurf->popup.y = y; |
| 3799 | shell_surface_set_parent(shsurf, parent); |
| 3800 | |
| 3801 | return shsurf; |
| 3802 | } |
| 3803 | |
| 3804 | static void |
| 3805 | xdg_get_xdg_popup(struct wl_client *client, |
| 3806 | struct wl_resource *resource, |
| 3807 | uint32_t id, |
| 3808 | struct wl_resource *surface_resource, |
| 3809 | struct wl_resource *parent_resource, |
| 3810 | struct wl_resource *seat_resource, |
| 3811 | uint32_t serial, |
| 3812 | int32_t x, int32_t y, uint32_t flags) |
| 3813 | { |
| 3814 | struct weston_surface *surface = |
| 3815 | wl_resource_get_user_data(surface_resource); |
Kristian Høgsberg | 2bff94e | 2014-02-11 12:22:51 -0800 | [diff] [blame] | 3816 | struct shell_client *sc = wl_resource_get_user_data(resource); |
| 3817 | struct desktop_shell *shell = sc->shell; |
Rafael Antognolli | e2a3455 | 2013-12-03 15:35:45 -0200 | [diff] [blame] | 3818 | struct shell_surface *shsurf; |
| 3819 | struct weston_surface *parent; |
| 3820 | struct shell_seat *seat; |
| 3821 | |
| 3822 | if (get_shell_surface(surface)) { |
| 3823 | wl_resource_post_error(surface_resource, |
| 3824 | WL_DISPLAY_ERROR_INVALID_OBJECT, |
Jasper St. Pierre | fe9671e | 2014-03-25 13:31:44 -0400 | [diff] [blame] | 3825 | "xdg_shell::get_xdg_popup already requested"); |
Rafael Antognolli | e2a3455 | 2013-12-03 15:35:45 -0200 | [diff] [blame] | 3826 | return; |
| 3827 | } |
| 3828 | |
| 3829 | if (!parent_resource) { |
| 3830 | wl_resource_post_error(surface_resource, |
| 3831 | WL_DISPLAY_ERROR_INVALID_OBJECT, |
| 3832 | "xdg_shell::get_xdg_popup requires a parent shell surface"); |
Jasper St. Pierre | 666bc92 | 2014-08-07 16:43:13 -0400 | [diff] [blame] | 3833 | return; |
Rafael Antognolli | e2a3455 | 2013-12-03 15:35:45 -0200 | [diff] [blame] | 3834 | } |
| 3835 | |
| 3836 | parent = wl_resource_get_user_data(parent_resource); |
| 3837 | seat = get_shell_seat(wl_resource_get_user_data(seat_resource));; |
| 3838 | |
Jason Ekstrand | 9e9512f | 2014-04-16 21:12:10 -0500 | [diff] [blame] | 3839 | shsurf = create_xdg_popup(sc, shell, surface, &xdg_popup_client, |
Rafael Antognolli | e2a3455 | 2013-12-03 15:35:45 -0200 | [diff] [blame] | 3840 | parent, seat, serial, x, y); |
| 3841 | if (!shsurf) { |
| 3842 | wl_resource_post_error(surface_resource, |
| 3843 | WL_DISPLAY_ERROR_INVALID_OBJECT, |
| 3844 | "surface->configure already set"); |
| 3845 | return; |
| 3846 | } |
| 3847 | |
| 3848 | shsurf->resource = |
| 3849 | wl_resource_create(client, |
| 3850 | &xdg_popup_interface, 1, id); |
| 3851 | wl_resource_set_implementation(shsurf->resource, |
| 3852 | &xdg_popup_implementation, |
| 3853 | shsurf, shell_destroy_shell_surface); |
| 3854 | } |
| 3855 | |
Kristian Høgsberg | 2bff94e | 2014-02-11 12:22:51 -0800 | [diff] [blame] | 3856 | static void |
| 3857 | xdg_pong(struct wl_client *client, |
| 3858 | struct wl_resource *resource, uint32_t serial) |
| 3859 | { |
| 3860 | struct shell_client *sc = wl_resource_get_user_data(resource); |
Kristian Høgsberg | 2bff94e | 2014-02-11 12:22:51 -0800 | [diff] [blame] | 3861 | |
Kristian Høgsberg | dd62aba | 2014-02-12 09:56:19 -0800 | [diff] [blame] | 3862 | shell_client_pong(sc, serial); |
Kristian Høgsberg | 2bff94e | 2014-02-11 12:22:51 -0800 | [diff] [blame] | 3863 | } |
| 3864 | |
Rafael Antognolli | e2a3455 | 2013-12-03 15:35:45 -0200 | [diff] [blame] | 3865 | static bool |
| 3866 | shell_surface_is_xdg_popup(struct shell_surface *shsurf) |
| 3867 | { |
| 3868 | return wl_resource_instance_of(shsurf->resource, |
| 3869 | &xdg_popup_interface, |
| 3870 | &xdg_popup_implementation); |
| 3871 | } |
| 3872 | |
| 3873 | static const struct xdg_shell_interface xdg_implementation = { |
| 3874 | xdg_use_unstable_version, |
| 3875 | xdg_get_xdg_surface, |
Kristian Høgsberg | 2bff94e | 2014-02-11 12:22:51 -0800 | [diff] [blame] | 3876 | xdg_get_xdg_popup, |
| 3877 | xdg_pong |
Rafael Antognolli | e2a3455 | 2013-12-03 15:35:45 -0200 | [diff] [blame] | 3878 | }; |
| 3879 | |
| 3880 | static int |
| 3881 | xdg_shell_unversioned_dispatch(const void *implementation, |
| 3882 | void *_target, uint32_t opcode, |
| 3883 | const struct wl_message *message, |
| 3884 | union wl_argument *args) |
| 3885 | { |
| 3886 | struct wl_resource *resource = _target; |
Kristian Høgsberg | 2bff94e | 2014-02-11 12:22:51 -0800 | [diff] [blame] | 3887 | struct shell_client *sc = wl_resource_get_user_data(resource); |
Rafael Antognolli | e2a3455 | 2013-12-03 15:35:45 -0200 | [diff] [blame] | 3888 | |
| 3889 | if (opcode != 0) { |
| 3890 | wl_resource_post_error(resource, |
| 3891 | WL_DISPLAY_ERROR_INVALID_OBJECT, |
| 3892 | "must call use_unstable_version first"); |
| 3893 | return 0; |
| 3894 | } |
| 3895 | |
Pekka Paalanen | 71182ae | 2014-08-21 17:47:20 +0300 | [diff] [blame] | 3896 | #define XDG_SERVER_VERSION 4 |
Rafael Antognolli | e2a3455 | 2013-12-03 15:35:45 -0200 | [diff] [blame] | 3897 | |
Kristian Høgsberg | 8d344a0 | 2013-12-08 22:27:11 -0800 | [diff] [blame] | 3898 | static_assert(XDG_SERVER_VERSION == XDG_SHELL_VERSION_CURRENT, |
| 3899 | "shell implementation doesn't match protocol version"); |
| 3900 | |
Rafael Antognolli | e2a3455 | 2013-12-03 15:35:45 -0200 | [diff] [blame] | 3901 | if (args[0].i != XDG_SERVER_VERSION) { |
| 3902 | wl_resource_post_error(resource, |
| 3903 | WL_DISPLAY_ERROR_INVALID_OBJECT, |
| 3904 | "incompatible version, server is %d " |
| 3905 | "client wants %d", |
| 3906 | XDG_SERVER_VERSION, args[0].i); |
| 3907 | return 0; |
| 3908 | } |
| 3909 | |
| 3910 | wl_resource_set_implementation(resource, &xdg_implementation, |
Kristian Høgsberg | 2bff94e | 2014-02-11 12:22:51 -0800 | [diff] [blame] | 3911 | sc, NULL); |
Rafael Antognolli | e2a3455 | 2013-12-03 15:35:45 -0200 | [diff] [blame] | 3912 | |
| 3913 | return 1; |
| 3914 | } |
| 3915 | |
| 3916 | /* end of xdg-shell implementation */ |
| 3917 | /***********************************/ |
| 3918 | |
Kristian Høgsberg | 0793756 | 2011-04-12 17:25:42 -0400 | [diff] [blame] | 3919 | static void |
Ander Conselvan de Oliveira | 859e885 | 2013-02-21 18:35:21 +0200 | [diff] [blame] | 3920 | shell_fade(struct desktop_shell *shell, enum fade_type type); |
| 3921 | |
| 3922 | static int |
| 3923 | screensaver_timeout(void *data) |
| 3924 | { |
| 3925 | struct desktop_shell *shell = data; |
| 3926 | |
| 3927 | shell_fade(shell, FADE_OUT); |
| 3928 | |
| 3929 | return 1; |
| 3930 | } |
| 3931 | |
| 3932 | static void |
Kristian Høgsberg | 8334bc1 | 2012-01-03 10:29:47 -0500 | [diff] [blame] | 3933 | handle_screensaver_sigchld(struct weston_process *proc, int status) |
Pekka Paalanen | 18027e5 | 2011-12-02 16:31:49 +0200 | [diff] [blame] | 3934 | { |
Ander Conselvan de Oliveira | 18639f8 | 2013-02-15 18:44:19 +0200 | [diff] [blame] | 3935 | struct desktop_shell *shell = |
| 3936 | container_of(proc, struct desktop_shell, screensaver.process); |
Ander Conselvan de Oliveira | 18639f8 | 2013-02-15 18:44:19 +0200 | [diff] [blame] | 3937 | |
Pekka Paalanen | 18027e5 | 2011-12-02 16:31:49 +0200 | [diff] [blame] | 3938 | proc->pid = 0; |
Ander Conselvan de Oliveira | 18639f8 | 2013-02-15 18:44:19 +0200 | [diff] [blame] | 3939 | |
| 3940 | if (shell->locked) |
Ander Conselvan de Oliveira | b17537e | 2013-02-22 14:16:18 +0200 | [diff] [blame] | 3941 | weston_compositor_sleep(shell->compositor); |
Pekka Paalanen | 18027e5 | 2011-12-02 16:31:49 +0200 | [diff] [blame] | 3942 | } |
| 3943 | |
| 3944 | static void |
Tiago Vignatti | be14326 | 2012-04-16 17:31:41 +0300 | [diff] [blame] | 3945 | launch_screensaver(struct desktop_shell *shell) |
Pekka Paalanen | 77346a6 | 2011-11-30 16:26:35 +0200 | [diff] [blame] | 3946 | { |
| 3947 | if (shell->screensaver.binding) |
| 3948 | return; |
| 3949 | |
Ander Conselvan de Oliveira | dda9d78 | 2013-02-22 14:16:19 +0200 | [diff] [blame] | 3950 | if (!shell->screensaver.path) { |
| 3951 | weston_compositor_sleep(shell->compositor); |
Pekka Paalanen | e955f1e | 2011-12-07 11:49:52 +0200 | [diff] [blame] | 3952 | return; |
Ander Conselvan de Oliveira | dda9d78 | 2013-02-22 14:16:19 +0200 | [diff] [blame] | 3953 | } |
Pekka Paalanen | e955f1e | 2011-12-07 11:49:52 +0200 | [diff] [blame] | 3954 | |
Kristian Høgsberg | 32bed57 | 2012-03-01 17:11:36 -0500 | [diff] [blame] | 3955 | if (shell->screensaver.process.pid != 0) { |
Martin Minarik | 6d11836 | 2012-06-07 18:01:59 +0200 | [diff] [blame] | 3956 | weston_log("old screensaver still running\n"); |
Kristian Høgsberg | 32bed57 | 2012-03-01 17:11:36 -0500 | [diff] [blame] | 3957 | return; |
| 3958 | } |
| 3959 | |
Kristian Høgsberg | 8334bc1 | 2012-01-03 10:29:47 -0500 | [diff] [blame] | 3960 | weston_client_launch(shell->compositor, |
Pekka Paalanen | 18027e5 | 2011-12-02 16:31:49 +0200 | [diff] [blame] | 3961 | &shell->screensaver.process, |
Pekka Paalanen | e955f1e | 2011-12-07 11:49:52 +0200 | [diff] [blame] | 3962 | shell->screensaver.path, |
Pekka Paalanen | 18027e5 | 2011-12-02 16:31:49 +0200 | [diff] [blame] | 3963 | handle_screensaver_sigchld); |
Pekka Paalanen | 77346a6 | 2011-11-30 16:26:35 +0200 | [diff] [blame] | 3964 | } |
| 3965 | |
| 3966 | static void |
Tiago Vignatti | be14326 | 2012-04-16 17:31:41 +0300 | [diff] [blame] | 3967 | terminate_screensaver(struct desktop_shell *shell) |
Pekka Paalanen | 77346a6 | 2011-11-30 16:26:35 +0200 | [diff] [blame] | 3968 | { |
Pekka Paalanen | 18027e5 | 2011-12-02 16:31:49 +0200 | [diff] [blame] | 3969 | if (shell->screensaver.process.pid == 0) |
| 3970 | return; |
| 3971 | |
Ander Conselvan de Oliveira | 4e20e9b | 2014-04-10 14:49:35 +0300 | [diff] [blame] | 3972 | /* Disarm the screensaver timer, otherwise it may fire when the |
| 3973 | * compositor is not in the idle state. In that case, the screen will |
| 3974 | * be locked, but the wake_signal won't fire on user input, making the |
| 3975 | * system unresponsive. */ |
| 3976 | wl_event_source_timer_update(shell->screensaver.timer, 0); |
| 3977 | |
Pekka Paalanen | 18027e5 | 2011-12-02 16:31:49 +0200 | [diff] [blame] | 3978 | kill(shell->screensaver.process.pid, SIGTERM); |
Pekka Paalanen | 77346a6 | 2011-11-30 16:26:35 +0200 | [diff] [blame] | 3979 | } |
| 3980 | |
| 3981 | static void |
Jason Ekstrand | 918f2dd | 2013-12-02 21:01:53 -0600 | [diff] [blame] | 3982 | configure_static_view(struct weston_view *ev, struct weston_layer *layer) |
Kristian Høgsberg | 962342c | 2012-06-26 16:29:50 -0400 | [diff] [blame] | 3983 | { |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 3984 | struct weston_view *v, *next; |
Kristian Høgsberg | 962342c | 2012-06-26 16:29:50 -0400 | [diff] [blame] | 3985 | |
Giulio Camuffo | 412e6a5 | 2014-07-09 22:12:56 +0300 | [diff] [blame] | 3986 | 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] | 3987 | if (v->output == ev->output && v != ev) { |
| 3988 | weston_view_unmap(v); |
| 3989 | v->surface->configure = NULL; |
Kristian Høgsberg | 962342c | 2012-06-26 16:29:50 -0400 | [diff] [blame] | 3990 | } |
| 3991 | } |
| 3992 | |
Jason Ekstrand | 918f2dd | 2013-12-02 21:01:53 -0600 | [diff] [blame] | 3993 | weston_view_set_position(ev, ev->output->x, ev->output->y); |
Kristian Høgsberg | 962342c | 2012-06-26 16:29:50 -0400 | [diff] [blame] | 3994 | |
Giulio Camuffo | 412e6a5 | 2014-07-09 22:12:56 +0300 | [diff] [blame] | 3995 | if (wl_list_empty(&ev->layer_link.link)) { |
| 3996 | weston_layer_entry_insert(&layer->view_list, &ev->layer_link); |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 3997 | weston_compositor_schedule_repaint(ev->surface->compositor); |
Kristian Høgsberg | 962342c | 2012-06-26 16:29:50 -0400 | [diff] [blame] | 3998 | } |
| 3999 | } |
| 4000 | |
| 4001 | static void |
Jason Ekstrand | 918f2dd | 2013-12-02 21:01:53 -0600 | [diff] [blame] | 4002 | 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] | 4003 | { |
Giulio Camuffo | 7fe01b1 | 2013-03-28 18:02:42 +0100 | [diff] [blame] | 4004 | struct desktop_shell *shell = es->configure_private; |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 4005 | struct weston_view *view; |
Kristian Høgsberg | af7b1ff | 2012-06-26 21:19:23 -0400 | [diff] [blame] | 4006 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 4007 | view = container_of(es->views.next, struct weston_view, surface_link); |
| 4008 | |
Jason Ekstrand | 918f2dd | 2013-12-02 21:01:53 -0600 | [diff] [blame] | 4009 | configure_static_view(view, &shell->background_layer); |
Kristian Høgsberg | af7b1ff | 2012-06-26 21:19:23 -0400 | [diff] [blame] | 4010 | } |
| 4011 | |
| 4012 | static void |
Kristian Høgsberg | 7584062 | 2011-09-06 13:48:16 -0400 | [diff] [blame] | 4013 | desktop_shell_set_background(struct wl_client *client, |
| 4014 | struct wl_resource *resource, |
Benjamin Franzke | d0f79ab | 2011-11-22 12:43:52 +0100 | [diff] [blame] | 4015 | struct wl_resource *output_resource, |
Kristian Høgsberg | 7584062 | 2011-09-06 13:48:16 -0400 | [diff] [blame] | 4016 | struct wl_resource *surface_resource) |
| 4017 | { |
Jason Ekstrand | 651f00e | 2013-06-14 10:07:54 -0500 | [diff] [blame] | 4018 | struct desktop_shell *shell = wl_resource_get_user_data(resource); |
Jason Ekstrand | 0f2ef7e | 2013-06-14 10:07:53 -0500 | [diff] [blame] | 4019 | struct weston_surface *surface = |
| 4020 | wl_resource_get_user_data(surface_resource); |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 4021 | struct weston_view *view, *next; |
Kristian Høgsberg | 7584062 | 2011-09-06 13:48:16 -0400 | [diff] [blame] | 4022 | |
Kristian Høgsberg | 962342c | 2012-06-26 16:29:50 -0400 | [diff] [blame] | 4023 | if (surface->configure) { |
| 4024 | wl_resource_post_error(surface_resource, |
| 4025 | WL_DISPLAY_ERROR_INVALID_OBJECT, |
| 4026 | "surface role already assigned"); |
| 4027 | return; |
| 4028 | } |
Benjamin Franzke | d0f79ab | 2011-11-22 12:43:52 +0100 | [diff] [blame] | 4029 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 4030 | wl_list_for_each_safe(view, next, &surface->views, surface_link) |
| 4031 | weston_view_destroy(view); |
| 4032 | view = weston_view_create(surface); |
| 4033 | |
Kristian Høgsberg | 962342c | 2012-06-26 16:29:50 -0400 | [diff] [blame] | 4034 | surface->configure = background_configure; |
Giulio Camuffo | 7fe01b1 | 2013-03-28 18:02:42 +0100 | [diff] [blame] | 4035 | surface->configure_private = shell; |
Jason Ekstrand | a0d2dde | 2013-06-14 10:08:01 -0500 | [diff] [blame] | 4036 | surface->output = wl_resource_get_user_data(output_resource); |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 4037 | view->output = surface->output; |
Kristian Høgsberg | eae5de7 | 2012-04-11 22:42:15 -0400 | [diff] [blame] | 4038 | desktop_shell_send_configure(resource, 0, |
Kristian Høgsberg | 0b5cd0c | 2012-03-04 21:57:37 -0500 | [diff] [blame] | 4039 | surface_resource, |
Scott Moreau | 1bad5db | 2012-08-18 01:04:05 -0600 | [diff] [blame] | 4040 | surface->output->width, |
| 4041 | surface->output->height); |
Kristian Høgsberg | 7584062 | 2011-09-06 13:48:16 -0400 | [diff] [blame] | 4042 | } |
| 4043 | |
| 4044 | static void |
Jason Ekstrand | 918f2dd | 2013-12-02 21:01:53 -0600 | [diff] [blame] | 4045 | 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] | 4046 | { |
Giulio Camuffo | 7fe01b1 | 2013-03-28 18:02:42 +0100 | [diff] [blame] | 4047 | struct desktop_shell *shell = es->configure_private; |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 4048 | struct weston_view *view; |
Kristian Høgsberg | af7b1ff | 2012-06-26 21:19:23 -0400 | [diff] [blame] | 4049 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 4050 | view = container_of(es->views.next, struct weston_view, surface_link); |
| 4051 | |
Jason Ekstrand | 918f2dd | 2013-12-02 21:01:53 -0600 | [diff] [blame] | 4052 | configure_static_view(view, &shell->panel_layer); |
Kristian Høgsberg | af7b1ff | 2012-06-26 21:19:23 -0400 | [diff] [blame] | 4053 | } |
| 4054 | |
| 4055 | static void |
Kristian Høgsberg | 7584062 | 2011-09-06 13:48:16 -0400 | [diff] [blame] | 4056 | desktop_shell_set_panel(struct wl_client *client, |
| 4057 | struct wl_resource *resource, |
Benjamin Franzke | d0f79ab | 2011-11-22 12:43:52 +0100 | [diff] [blame] | 4058 | struct wl_resource *output_resource, |
Kristian Høgsberg | 7584062 | 2011-09-06 13:48:16 -0400 | [diff] [blame] | 4059 | struct wl_resource *surface_resource) |
| 4060 | { |
Jason Ekstrand | 651f00e | 2013-06-14 10:07:54 -0500 | [diff] [blame] | 4061 | struct desktop_shell *shell = wl_resource_get_user_data(resource); |
Jason Ekstrand | 0f2ef7e | 2013-06-14 10:07:53 -0500 | [diff] [blame] | 4062 | struct weston_surface *surface = |
| 4063 | wl_resource_get_user_data(surface_resource); |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 4064 | struct weston_view *view, *next; |
Kristian Høgsberg | 7584062 | 2011-09-06 13:48:16 -0400 | [diff] [blame] | 4065 | |
Kristian Høgsberg | af7b1ff | 2012-06-26 21:19:23 -0400 | [diff] [blame] | 4066 | if (surface->configure) { |
| 4067 | wl_resource_post_error(surface_resource, |
| 4068 | WL_DISPLAY_ERROR_INVALID_OBJECT, |
| 4069 | "surface role already assigned"); |
| 4070 | return; |
| 4071 | } |
Benjamin Franzke | d0f79ab | 2011-11-22 12:43:52 +0100 | [diff] [blame] | 4072 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 4073 | wl_list_for_each_safe(view, next, &surface->views, surface_link) |
| 4074 | weston_view_destroy(view); |
| 4075 | view = weston_view_create(surface); |
| 4076 | |
Kristian Høgsberg | af7b1ff | 2012-06-26 21:19:23 -0400 | [diff] [blame] | 4077 | surface->configure = panel_configure; |
Giulio Camuffo | 7fe01b1 | 2013-03-28 18:02:42 +0100 | [diff] [blame] | 4078 | surface->configure_private = shell; |
Jason Ekstrand | a0d2dde | 2013-06-14 10:08:01 -0500 | [diff] [blame] | 4079 | surface->output = wl_resource_get_user_data(output_resource); |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 4080 | view->output = surface->output; |
Kristian Høgsberg | eae5de7 | 2012-04-11 22:42:15 -0400 | [diff] [blame] | 4081 | desktop_shell_send_configure(resource, 0, |
Kristian Høgsberg | af7b1ff | 2012-06-26 21:19:23 -0400 | [diff] [blame] | 4082 | surface_resource, |
Scott Moreau | 1bad5db | 2012-08-18 01:04:05 -0600 | [diff] [blame] | 4083 | surface->output->width, |
| 4084 | surface->output->height); |
Kristian Høgsberg | 7584062 | 2011-09-06 13:48:16 -0400 | [diff] [blame] | 4085 | } |
| 4086 | |
Pekka Paalanen | 9ef3e01 | 2011-11-15 13:34:48 +0200 | [diff] [blame] | 4087 | static void |
Jason Ekstrand | 918f2dd | 2013-12-02 21:01:53 -0600 | [diff] [blame] | 4088 | 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] | 4089 | { |
Giulio Camuffo | 7fe01b1 | 2013-03-28 18:02:42 +0100 | [diff] [blame] | 4090 | struct desktop_shell *shell = surface->configure_private; |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 4091 | struct weston_view *view; |
| 4092 | |
| 4093 | view = container_of(surface->views.next, struct weston_view, surface_link); |
Kristian Høgsberg | 730c94d | 2012-06-26 21:44:35 -0400 | [diff] [blame] | 4094 | |
Jason Ekstrand | 918f2dd | 2013-12-02 21:01:53 -0600 | [diff] [blame] | 4095 | if (surface->width == 0) |
Giulio Camuffo | 184df50 | 2013-02-21 11:29:21 +0100 | [diff] [blame] | 4096 | return; |
| 4097 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 4098 | center_on_output(view, get_default_output(shell->compositor)); |
Kristian Høgsberg | 730c94d | 2012-06-26 21:44:35 -0400 | [diff] [blame] | 4099 | |
| 4100 | if (!weston_surface_is_mapped(surface)) { |
Giulio Camuffo | 412e6a5 | 2014-07-09 22:12:56 +0300 | [diff] [blame] | 4101 | weston_layer_entry_insert(&shell->lock_layer.view_list, |
| 4102 | &view->layer_link); |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 4103 | weston_view_update_transform(view); |
Ander Conselvan de Oliveira | 87524b6 | 2013-02-21 18:35:22 +0200 | [diff] [blame] | 4104 | shell_fade(shell, FADE_IN); |
Kristian Høgsberg | 730c94d | 2012-06-26 21:44:35 -0400 | [diff] [blame] | 4105 | } |
| 4106 | } |
| 4107 | |
| 4108 | static void |
Kristian Høgsberg | 27e3052 | 2012-04-11 23:18:23 -0400 | [diff] [blame] | 4109 | handle_lock_surface_destroy(struct wl_listener *listener, void *data) |
Kristian Høgsberg | 1ec0c31 | 2011-11-15 16:39:55 -0500 | [diff] [blame] | 4110 | { |
Tiago Vignatti | be14326 | 2012-04-16 17:31:41 +0300 | [diff] [blame] | 4111 | struct desktop_shell *shell = |
| 4112 | container_of(listener, struct desktop_shell, lock_surface_listener); |
Kristian Høgsberg | 1ec0c31 | 2011-11-15 16:39:55 -0500 | [diff] [blame] | 4113 | |
Martin Minarik | 6d11836 | 2012-06-07 18:01:59 +0200 | [diff] [blame] | 4114 | weston_log("lock surface gone\n"); |
Kristian Høgsberg | 1ec0c31 | 2011-11-15 16:39:55 -0500 | [diff] [blame] | 4115 | shell->lock_surface = NULL; |
| 4116 | } |
| 4117 | |
| 4118 | static void |
Pekka Paalanen | 9ef3e01 | 2011-11-15 13:34:48 +0200 | [diff] [blame] | 4119 | desktop_shell_set_lock_surface(struct wl_client *client, |
| 4120 | struct wl_resource *resource, |
| 4121 | struct wl_resource *surface_resource) |
| 4122 | { |
Jason Ekstrand | 651f00e | 2013-06-14 10:07:54 -0500 | [diff] [blame] | 4123 | struct desktop_shell *shell = wl_resource_get_user_data(resource); |
Jason Ekstrand | 0f2ef7e | 2013-06-14 10:07:53 -0500 | [diff] [blame] | 4124 | struct weston_surface *surface = |
| 4125 | wl_resource_get_user_data(surface_resource); |
Pekka Paalanen | 9826223 | 2011-12-01 10:42:22 +0200 | [diff] [blame] | 4126 | |
Pekka Paalanen | f0fc70d | 2011-11-15 13:34:54 +0200 | [diff] [blame] | 4127 | shell->prepare_event_sent = false; |
Kristian Høgsberg | af867cc | 2011-11-15 13:34:49 +0200 | [diff] [blame] | 4128 | |
Pekka Paalanen | f0fc70d | 2011-11-15 13:34:54 +0200 | [diff] [blame] | 4129 | if (!shell->locked) |
| 4130 | return; |
| 4131 | |
Pekka Paalanen | 9826223 | 2011-12-01 10:42:22 +0200 | [diff] [blame] | 4132 | shell->lock_surface = surface; |
Pekka Paalanen | f0fc70d | 2011-11-15 13:34:54 +0200 | [diff] [blame] | 4133 | |
Kristian Høgsberg | 27e3052 | 2012-04-11 23:18:23 -0400 | [diff] [blame] | 4134 | shell->lock_surface_listener.notify = handle_lock_surface_destroy; |
Jason Ekstrand | 651f00e | 2013-06-14 10:07:54 -0500 | [diff] [blame] | 4135 | wl_signal_add(&surface->destroy_signal, |
Kristian Høgsberg | 27e3052 | 2012-04-11 23:18:23 -0400 | [diff] [blame] | 4136 | &shell->lock_surface_listener); |
Pekka Paalanen | 57da4a8 | 2011-11-23 16:42:16 +0200 | [diff] [blame] | 4137 | |
Kristian Høgsberg | aa2ee8b | 2013-10-30 15:49:45 -0700 | [diff] [blame] | 4138 | weston_view_create(surface); |
Kristian Høgsberg | 730c94d | 2012-06-26 21:44:35 -0400 | [diff] [blame] | 4139 | surface->configure = lock_surface_configure; |
Giulio Camuffo | 7fe01b1 | 2013-03-28 18:02:42 +0100 | [diff] [blame] | 4140 | surface->configure_private = shell; |
Pekka Paalanen | f0fc70d | 2011-11-15 13:34:54 +0200 | [diff] [blame] | 4141 | } |
| 4142 | |
| 4143 | static void |
Tiago Vignatti | be14326 | 2012-04-16 17:31:41 +0300 | [diff] [blame] | 4144 | resume_desktop(struct desktop_shell *shell) |
Pekka Paalanen | f0fc70d | 2011-11-15 13:34:54 +0200 | [diff] [blame] | 4145 | { |
Kristian Høgsberg | 4476aaf | 2012-06-25 14:03:13 -0400 | [diff] [blame] | 4146 | struct workspace *ws = get_current_workspace(shell); |
Pekka Paalanen | 77346a6 | 2011-11-30 16:26:35 +0200 | [diff] [blame] | 4147 | |
Pekka Paalanen | 77346a6 | 2011-11-30 16:26:35 +0200 | [diff] [blame] | 4148 | terminate_screensaver(shell); |
Pekka Paalanen | f0fc70d | 2011-11-15 13:34:54 +0200 | [diff] [blame] | 4149 | |
Kristian Høgsberg | 3be2ce9 | 2012-02-29 12:42:35 -0500 | [diff] [blame] | 4150 | wl_list_remove(&shell->lock_layer.link); |
Philipp Brüschweiler | 711fda8 | 2012-08-09 18:50:43 +0200 | [diff] [blame] | 4151 | if (shell->showing_input_panels) { |
Manuel Bachmann | 805d2f5 | 2014-03-05 12:21:34 +0100 | [diff] [blame] | 4152 | wl_list_insert(&shell->compositor->cursor_layer.link, |
Philipp Brüschweiler | 711fda8 | 2012-08-09 18:50:43 +0200 | [diff] [blame] | 4153 | &shell->input_panel_layer.link); |
| 4154 | wl_list_insert(&shell->input_panel_layer.link, |
Manuel Bachmann | 805d2f5 | 2014-03-05 12:21:34 +0100 | [diff] [blame] | 4155 | &shell->fullscreen_layer.link); |
Philipp Brüschweiler | 711fda8 | 2012-08-09 18:50:43 +0200 | [diff] [blame] | 4156 | } else { |
Manuel Bachmann | 805d2f5 | 2014-03-05 12:21:34 +0100 | [diff] [blame] | 4157 | wl_list_insert(&shell->compositor->cursor_layer.link, |
| 4158 | &shell->fullscreen_layer.link); |
Philipp Brüschweiler | 711fda8 | 2012-08-09 18:50:43 +0200 | [diff] [blame] | 4159 | } |
Manuel Bachmann | 805d2f5 | 2014-03-05 12:21:34 +0100 | [diff] [blame] | 4160 | wl_list_insert(&shell->fullscreen_layer.link, |
| 4161 | &shell->panel_layer.link); |
| 4162 | wl_list_insert(&shell->panel_layer.link, |
| 4163 | &ws->layer.link), |
Pekka Paalanen | f0fc70d | 2011-11-15 13:34:54 +0200 | [diff] [blame] | 4164 | |
Kristian Høgsberg | 2f5faff | 2012-07-31 16:36:34 -0400 | [diff] [blame] | 4165 | restore_focus_state(shell, get_current_workspace(shell)); |
Jonas Ådahl | 0476974 | 2012-06-13 00:01:24 +0200 | [diff] [blame] | 4166 | |
Pekka Paalanen | f0fc70d | 2011-11-15 13:34:54 +0200 | [diff] [blame] | 4167 | shell->locked = false; |
Ander Conselvan de Oliveira | 87524b6 | 2013-02-21 18:35:22 +0200 | [diff] [blame] | 4168 | shell_fade(shell, FADE_IN); |
Pekka Paalanen | fc6d91a | 2012-02-10 15:33:10 +0200 | [diff] [blame] | 4169 | weston_compositor_damage_all(shell->compositor); |
Pekka Paalanen | 9ef3e01 | 2011-11-15 13:34:48 +0200 | [diff] [blame] | 4170 | } |
| 4171 | |
| 4172 | static void |
| 4173 | desktop_shell_unlock(struct wl_client *client, |
| 4174 | struct wl_resource *resource) |
| 4175 | { |
Jason Ekstrand | 651f00e | 2013-06-14 10:07:54 -0500 | [diff] [blame] | 4176 | struct desktop_shell *shell = wl_resource_get_user_data(resource); |
Pekka Paalanen | 9ef3e01 | 2011-11-15 13:34:48 +0200 | [diff] [blame] | 4177 | |
Pekka Paalanen | 9ef3e01 | 2011-11-15 13:34:48 +0200 | [diff] [blame] | 4178 | shell->prepare_event_sent = false; |
Pekka Paalanen | f0fc70d | 2011-11-15 13:34:54 +0200 | [diff] [blame] | 4179 | |
| 4180 | if (shell->locked) |
| 4181 | resume_desktop(shell); |
Pekka Paalanen | 9ef3e01 | 2011-11-15 13:34:48 +0200 | [diff] [blame] | 4182 | } |
| 4183 | |
Kristian Høgsberg | d56bd90 | 2012-06-05 09:58:51 -0400 | [diff] [blame] | 4184 | static void |
Ander Conselvan de Oliveira | b9d2a0f | 2012-06-28 18:08:05 +0300 | [diff] [blame] | 4185 | desktop_shell_set_grab_surface(struct wl_client *client, |
Kristian Høgsberg | d56bd90 | 2012-06-05 09:58:51 -0400 | [diff] [blame] | 4186 | struct wl_resource *resource, |
| 4187 | struct wl_resource *surface_resource) |
| 4188 | { |
Jason Ekstrand | 651f00e | 2013-06-14 10:07:54 -0500 | [diff] [blame] | 4189 | struct desktop_shell *shell = wl_resource_get_user_data(resource); |
Kristian Høgsberg | d56bd90 | 2012-06-05 09:58:51 -0400 | [diff] [blame] | 4190 | |
Jason Ekstrand | 0f2ef7e | 2013-06-14 10:07:53 -0500 | [diff] [blame] | 4191 | shell->grab_surface = wl_resource_get_user_data(surface_resource); |
Kristian Høgsberg | 48588f8 | 2013-10-24 15:51:35 -0700 | [diff] [blame] | 4192 | weston_view_create(shell->grab_surface); |
Kristian Høgsberg | d56bd90 | 2012-06-05 09:58:51 -0400 | [diff] [blame] | 4193 | } |
| 4194 | |
Pekka Paalanen | 79346ab | 2013-05-22 18:03:09 +0300 | [diff] [blame] | 4195 | static void |
| 4196 | desktop_shell_desktop_ready(struct wl_client *client, |
| 4197 | struct wl_resource *resource) |
| 4198 | { |
Jason Ekstrand | 651f00e | 2013-06-14 10:07:54 -0500 | [diff] [blame] | 4199 | struct desktop_shell *shell = wl_resource_get_user_data(resource); |
Pekka Paalanen | 79346ab | 2013-05-22 18:03:09 +0300 | [diff] [blame] | 4200 | |
| 4201 | shell_fade_startup(shell); |
| 4202 | } |
| 4203 | |
Jonny Lamb | 765760d | 2014-08-20 15:53:19 +0200 | [diff] [blame] | 4204 | static void |
| 4205 | desktop_shell_set_panel_position(struct wl_client *client, |
| 4206 | struct wl_resource *resource, |
| 4207 | uint32_t position) |
| 4208 | { |
| 4209 | struct desktop_shell *shell = wl_resource_get_user_data(resource); |
| 4210 | |
| 4211 | if (position != DESKTOP_SHELL_PANEL_POSITION_TOP && |
| 4212 | position != DESKTOP_SHELL_PANEL_POSITION_BOTTOM && |
| 4213 | position != DESKTOP_SHELL_PANEL_POSITION_LEFT && |
| 4214 | position != DESKTOP_SHELL_PANEL_POSITION_RIGHT) { |
| 4215 | wl_resource_post_error(resource, |
| 4216 | DESKTOP_SHELL_ERROR_INVALID_ARGUMENT, |
| 4217 | "bad position argument"); |
| 4218 | return; |
| 4219 | } |
| 4220 | |
| 4221 | shell->panel_position = position; |
| 4222 | } |
| 4223 | |
Kristian Høgsberg | 7584062 | 2011-09-06 13:48:16 -0400 | [diff] [blame] | 4224 | static const struct desktop_shell_interface desktop_shell_implementation = { |
| 4225 | desktop_shell_set_background, |
Pekka Paalanen | 9ef3e01 | 2011-11-15 13:34:48 +0200 | [diff] [blame] | 4226 | desktop_shell_set_panel, |
| 4227 | desktop_shell_set_lock_surface, |
Kristian Høgsberg | d56bd90 | 2012-06-05 09:58:51 -0400 | [diff] [blame] | 4228 | desktop_shell_unlock, |
Pekka Paalanen | 79346ab | 2013-05-22 18:03:09 +0300 | [diff] [blame] | 4229 | desktop_shell_set_grab_surface, |
Jonny Lamb | 765760d | 2014-08-20 15:53:19 +0200 | [diff] [blame] | 4230 | desktop_shell_desktop_ready, |
| 4231 | desktop_shell_set_panel_position |
Kristian Høgsberg | 7584062 | 2011-09-06 13:48:16 -0400 | [diff] [blame] | 4232 | }; |
| 4233 | |
Pekka Paalanen | 92a0dc4 | 2011-11-28 15:34:13 +0200 | [diff] [blame] | 4234 | static enum shell_surface_type |
Kristian Høgsberg | 8334bc1 | 2012-01-03 10:29:47 -0500 | [diff] [blame] | 4235 | get_shell_surface_type(struct weston_surface *surface) |
Pekka Paalanen | 92a0dc4 | 2011-11-28 15:34:13 +0200 | [diff] [blame] | 4236 | { |
| 4237 | struct shell_surface *shsurf; |
| 4238 | |
| 4239 | shsurf = get_shell_surface(surface); |
| 4240 | if (!shsurf) |
Pekka Paalanen | 9826223 | 2011-12-01 10:42:22 +0200 | [diff] [blame] | 4241 | return SHELL_SURFACE_NONE; |
Pekka Paalanen | 92a0dc4 | 2011-11-28 15:34:13 +0200 | [diff] [blame] | 4242 | return shsurf->type; |
| 4243 | } |
| 4244 | |
Kristian Høgsberg | 7584062 | 2011-09-06 13:48:16 -0400 | [diff] [blame] | 4245 | static void |
Kristian Høgsberg | e314875 | 2013-05-06 23:19:49 -0400 | [diff] [blame] | 4246 | 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] | 4247 | { |
Rafal Mielniczuk | b2917a2 | 2014-01-05 20:04:59 +0100 | [diff] [blame] | 4248 | struct weston_surface *focus; |
Pekka Paalanen | 01388e2 | 2013-04-25 13:57:44 +0300 | [diff] [blame] | 4249 | struct weston_surface *surface; |
Kristian Høgsberg | 938b8fa | 2012-05-18 13:46:27 -0400 | [diff] [blame] | 4250 | struct shell_surface *shsurf; |
Kristian Høgsberg | d2abb83 | 2011-11-23 10:52:40 -0500 | [diff] [blame] | 4251 | |
Rafal Mielniczuk | b2917a2 | 2014-01-05 20:04:59 +0100 | [diff] [blame] | 4252 | if (seat->pointer->focus == NULL) |
| 4253 | return; |
| 4254 | |
| 4255 | focus = seat->pointer->focus->surface; |
| 4256 | |
Pekka Paalanen | 01388e2 | 2013-04-25 13:57:44 +0300 | [diff] [blame] | 4257 | surface = weston_surface_get_main_surface(focus); |
Benjamin Franzke | d0f79ab | 2011-11-22 12:43:52 +0100 | [diff] [blame] | 4258 | if (surface == NULL) |
| 4259 | return; |
Kristian Høgsberg | 0793756 | 2011-04-12 17:25:42 -0400 | [diff] [blame] | 4260 | |
Kristian Høgsberg | 938b8fa | 2012-05-18 13:46:27 -0400 | [diff] [blame] | 4261 | shsurf = get_shell_surface(surface); |
Rafael Antognolli | 03b1659 | 2013-12-03 15:35:42 -0200 | [diff] [blame] | 4262 | if (shsurf == NULL || shsurf->state.fullscreen || |
| 4263 | shsurf->state.maximized) |
Kristian Høgsberg | 938b8fa | 2012-05-18 13:46:27 -0400 | [diff] [blame] | 4264 | return; |
| 4265 | |
Kristian Høgsberg | ae356ae | 2014-04-29 16:03:54 -0700 | [diff] [blame] | 4266 | surface_move(shsurf, (struct weston_seat *) seat, 0); |
Kristian Høgsberg | 0793756 | 2011-04-12 17:25:42 -0400 | [diff] [blame] | 4267 | } |
| 4268 | |
| 4269 | static void |
Rafael Antognolli | ea997ac | 2013-12-03 15:35:48 -0200 | [diff] [blame] | 4270 | maximize_binding(struct weston_seat *seat, uint32_t time, uint32_t button, void *data) |
| 4271 | { |
Emilio Pozuelo Monfort | 38b58eb | 2014-01-29 11:11:12 +0100 | [diff] [blame] | 4272 | struct weston_surface *focus = seat->keyboard->focus; |
Rafael Antognolli | ea997ac | 2013-12-03 15:35:48 -0200 | [diff] [blame] | 4273 | struct weston_surface *surface; |
| 4274 | struct shell_surface *shsurf; |
| 4275 | |
| 4276 | surface = weston_surface_get_main_surface(focus); |
| 4277 | if (surface == NULL) |
| 4278 | return; |
| 4279 | |
| 4280 | shsurf = get_shell_surface(surface); |
| 4281 | if (shsurf == NULL) |
| 4282 | return; |
| 4283 | |
| 4284 | if (!shell_surface_is_xdg_surface(shsurf)) |
| 4285 | return; |
| 4286 | |
Jasper St. Pierre | ab2c108 | 2014-04-10 10:41:46 -0700 | [diff] [blame] | 4287 | shsurf->state_requested = true; |
| 4288 | shsurf->requested_state.maximized = !shsurf->state.maximized; |
Jasper St. Pierre | 9aa8ce6 | 2014-04-11 16:18:54 -0700 | [diff] [blame] | 4289 | send_configure_for_surface(shsurf); |
Rafael Antognolli | ea997ac | 2013-12-03 15:35:48 -0200 | [diff] [blame] | 4290 | } |
| 4291 | |
| 4292 | static void |
| 4293 | fullscreen_binding(struct weston_seat *seat, uint32_t time, uint32_t button, void *data) |
| 4294 | { |
Emilio Pozuelo Monfort | 38b58eb | 2014-01-29 11:11:12 +0100 | [diff] [blame] | 4295 | struct weston_surface *focus = seat->keyboard->focus; |
Rafael Antognolli | ea997ac | 2013-12-03 15:35:48 -0200 | [diff] [blame] | 4296 | struct weston_surface *surface; |
| 4297 | struct shell_surface *shsurf; |
| 4298 | |
| 4299 | surface = weston_surface_get_main_surface(focus); |
| 4300 | if (surface == NULL) |
| 4301 | return; |
| 4302 | |
| 4303 | shsurf = get_shell_surface(surface); |
| 4304 | if (shsurf == NULL) |
| 4305 | return; |
| 4306 | |
| 4307 | if (!shell_surface_is_xdg_surface(shsurf)) |
| 4308 | return; |
| 4309 | |
Jasper St. Pierre | ab2c108 | 2014-04-10 10:41:46 -0700 | [diff] [blame] | 4310 | shsurf->state_requested = true; |
| 4311 | shsurf->requested_state.fullscreen = !shsurf->state.fullscreen; |
Boyan Ding | 32abdbb | 2014-06-26 10:19:32 +0800 | [diff] [blame] | 4312 | shsurf->fullscreen_output = shsurf->output; |
Jasper St. Pierre | 9aa8ce6 | 2014-04-11 16:18:54 -0700 | [diff] [blame] | 4313 | send_configure_for_surface(shsurf); |
Rafael Antognolli | ea997ac | 2013-12-03 15:35:48 -0200 | [diff] [blame] | 4314 | } |
| 4315 | |
| 4316 | static void |
Neil Roberts | aba0f25 | 2013-10-03 16:43:05 +0100 | [diff] [blame] | 4317 | touch_move_binding(struct weston_seat *seat, uint32_t time, void *data) |
| 4318 | { |
Kristian Høgsberg | 7ab139c | 2013-10-24 16:21:39 -0700 | [diff] [blame] | 4319 | struct weston_surface *focus = seat->touch->focus->surface; |
Neil Roberts | aba0f25 | 2013-10-03 16:43:05 +0100 | [diff] [blame] | 4320 | struct weston_surface *surface; |
| 4321 | struct shell_surface *shsurf; |
| 4322 | |
| 4323 | surface = weston_surface_get_main_surface(focus); |
| 4324 | if (surface == NULL) |
| 4325 | return; |
| 4326 | |
| 4327 | shsurf = get_shell_surface(surface); |
Rafael Antognolli | 03b1659 | 2013-12-03 15:35:42 -0200 | [diff] [blame] | 4328 | if (shsurf == NULL || shsurf->state.fullscreen || |
| 4329 | shsurf->state.maximized) |
Neil Roberts | aba0f25 | 2013-10-03 16:43:05 +0100 | [diff] [blame] | 4330 | return; |
| 4331 | |
| 4332 | surface_touch_move(shsurf, (struct weston_seat *) seat); |
| 4333 | } |
| 4334 | |
| 4335 | static void |
Kristian Høgsberg | e314875 | 2013-05-06 23:19:49 -0400 | [diff] [blame] | 4336 | 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] | 4337 | { |
Rafal Mielniczuk | b2917a2 | 2014-01-05 20:04:59 +0100 | [diff] [blame] | 4338 | struct weston_surface *focus; |
Pekka Paalanen | 01388e2 | 2013-04-25 13:57:44 +0300 | [diff] [blame] | 4339 | struct weston_surface *surface; |
Kristian Høgsberg | 0793756 | 2011-04-12 17:25:42 -0400 | [diff] [blame] | 4340 | uint32_t edges = 0; |
| 4341 | int32_t x, y; |
Pekka Paalanen | 9d1613e | 2011-11-25 12:09:16 +0200 | [diff] [blame] | 4342 | struct shell_surface *shsurf; |
Kristian Høgsberg | d2abb83 | 2011-11-23 10:52:40 -0500 | [diff] [blame] | 4343 | |
Rafal Mielniczuk | b2917a2 | 2014-01-05 20:04:59 +0100 | [diff] [blame] | 4344 | if (seat->pointer->focus == NULL) |
| 4345 | return; |
| 4346 | |
| 4347 | focus = seat->pointer->focus->surface; |
| 4348 | |
Pekka Paalanen | 01388e2 | 2013-04-25 13:57:44 +0300 | [diff] [blame] | 4349 | surface = weston_surface_get_main_surface(focus); |
Benjamin Franzke | d0f79ab | 2011-11-22 12:43:52 +0100 | [diff] [blame] | 4350 | if (surface == NULL) |
| 4351 | return; |
Pekka Paalanen | 92a0dc4 | 2011-11-28 15:34:13 +0200 | [diff] [blame] | 4352 | |
Pekka Paalanen | 9d1613e | 2011-11-25 12:09:16 +0200 | [diff] [blame] | 4353 | shsurf = get_shell_surface(surface); |
Rafael Antognolli | 03b1659 | 2013-12-03 15:35:42 -0200 | [diff] [blame] | 4354 | if (shsurf == NULL || shsurf->state.fullscreen || |
| 4355 | shsurf->state.maximized) |
Pekka Paalanen | 92a0dc4 | 2011-11-28 15:34:13 +0200 | [diff] [blame] | 4356 | return; |
| 4357 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 4358 | weston_view_from_global(shsurf->view, |
| 4359 | wl_fixed_to_int(seat->pointer->grab_x), |
| 4360 | wl_fixed_to_int(seat->pointer->grab_y), |
| 4361 | &x, &y); |
Kristian Høgsberg | 0793756 | 2011-04-12 17:25:42 -0400 | [diff] [blame] | 4362 | |
Jason Ekstrand | 918f2dd | 2013-12-02 21:01:53 -0600 | [diff] [blame] | 4363 | if (x < shsurf->surface->width / 3) |
Pekka Paalanen | 9d1613e | 2011-11-25 12:09:16 +0200 | [diff] [blame] | 4364 | edges |= WL_SHELL_SURFACE_RESIZE_LEFT; |
Jason Ekstrand | 918f2dd | 2013-12-02 21:01:53 -0600 | [diff] [blame] | 4365 | else if (x < 2 * shsurf->surface->width / 3) |
Kristian Høgsberg | 0793756 | 2011-04-12 17:25:42 -0400 | [diff] [blame] | 4366 | edges |= 0; |
| 4367 | else |
Pekka Paalanen | 9d1613e | 2011-11-25 12:09:16 +0200 | [diff] [blame] | 4368 | edges |= WL_SHELL_SURFACE_RESIZE_RIGHT; |
Kristian Høgsberg | 0793756 | 2011-04-12 17:25:42 -0400 | [diff] [blame] | 4369 | |
Jason Ekstrand | 918f2dd | 2013-12-02 21:01:53 -0600 | [diff] [blame] | 4370 | if (y < shsurf->surface->height / 3) |
Pekka Paalanen | 9d1613e | 2011-11-25 12:09:16 +0200 | [diff] [blame] | 4371 | edges |= WL_SHELL_SURFACE_RESIZE_TOP; |
Jason Ekstrand | 918f2dd | 2013-12-02 21:01:53 -0600 | [diff] [blame] | 4372 | else if (y < 2 * shsurf->surface->height / 3) |
Kristian Høgsberg | 0793756 | 2011-04-12 17:25:42 -0400 | [diff] [blame] | 4373 | edges |= 0; |
| 4374 | else |
Pekka Paalanen | 9d1613e | 2011-11-25 12:09:16 +0200 | [diff] [blame] | 4375 | edges |= WL_SHELL_SURFACE_RESIZE_BOTTOM; |
Kristian Høgsberg | 0793756 | 2011-04-12 17:25:42 -0400 | [diff] [blame] | 4376 | |
Kristian Høgsberg | c1693f2 | 2012-05-22 16:56:23 -0400 | [diff] [blame] | 4377 | surface_resize(shsurf, (struct weston_seat *) seat, edges); |
Kristian Høgsberg | 02ec0a5 | 2011-04-23 13:04:11 -0400 | [diff] [blame] | 4378 | } |
| 4379 | |
| 4380 | static void |
Kristian Høgsberg | e314875 | 2013-05-06 23:19:49 -0400 | [diff] [blame] | 4381 | 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] | 4382 | wl_fixed_t value, void *data) |
Scott Moreau | a3aa9c9 | 2012-03-22 11:01:03 -0600 | [diff] [blame] | 4383 | { |
Jonas Ådahl | b0b87ba | 2012-09-27 18:40:42 +0200 | [diff] [blame] | 4384 | float step = 0.005; |
Scott Moreau | a3aa9c9 | 2012-03-22 11:01:03 -0600 | [diff] [blame] | 4385 | struct shell_surface *shsurf; |
Kristian Høgsberg | 7ab139c | 2013-10-24 16:21:39 -0700 | [diff] [blame] | 4386 | struct weston_surface *focus = seat->pointer->focus->surface; |
Pekka Paalanen | 01388e2 | 2013-04-25 13:57:44 +0300 | [diff] [blame] | 4387 | struct weston_surface *surface; |
Scott Moreau | a3aa9c9 | 2012-03-22 11:01:03 -0600 | [diff] [blame] | 4388 | |
Pekka Paalanen | 01388e2 | 2013-04-25 13:57:44 +0300 | [diff] [blame] | 4389 | /* XXX: broken for windows containing sub-surfaces */ |
| 4390 | surface = weston_surface_get_main_surface(focus); |
Scott Moreau | a3aa9c9 | 2012-03-22 11:01:03 -0600 | [diff] [blame] | 4391 | if (surface == NULL) |
| 4392 | return; |
| 4393 | |
| 4394 | shsurf = get_shell_surface(surface); |
| 4395 | if (!shsurf) |
| 4396 | return; |
| 4397 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 4398 | shsurf->view->alpha -= wl_fixed_to_double(value) * step; |
Scott Moreau | a3aa9c9 | 2012-03-22 11:01:03 -0600 | [diff] [blame] | 4399 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 4400 | if (shsurf->view->alpha > 1.0) |
| 4401 | shsurf->view->alpha = 1.0; |
| 4402 | if (shsurf->view->alpha < step) |
| 4403 | shsurf->view->alpha = step; |
Scott Moreau | a3aa9c9 | 2012-03-22 11:01:03 -0600 | [diff] [blame] | 4404 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 4405 | weston_view_geometry_dirty(shsurf->view); |
Scott Moreau | a3aa9c9 | 2012-03-22 11:01:03 -0600 | [diff] [blame] | 4406 | weston_surface_damage(surface); |
| 4407 | } |
| 4408 | |
| 4409 | static void |
Kristian Høgsberg | e314875 | 2013-05-06 23:19:49 -0400 | [diff] [blame] | 4410 | 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] | 4411 | wl_fixed_t value) |
Scott Moreau | ccbf29d | 2012-02-22 14:21:41 -0700 | [diff] [blame] | 4412 | { |
Daniel Stone | 37816df | 2012-05-16 18:45:18 +0100 | [diff] [blame] | 4413 | struct weston_seat *ws = (struct weston_seat *) seat; |
| 4414 | struct weston_compositor *compositor = ws->compositor; |
Scott Moreau | ccbf29d | 2012-02-22 14:21:41 -0700 | [diff] [blame] | 4415 | struct weston_output *output; |
Scott Moreau | e660398 | 2012-06-11 13:07:51 -0600 | [diff] [blame] | 4416 | float increment; |
Scott Moreau | ccbf29d | 2012-02-22 14:21:41 -0700 | [diff] [blame] | 4417 | |
| 4418 | wl_list_for_each(output, &compositor->output_list, link) { |
| 4419 | if (pixman_region32_contains_point(&output->region, |
Daniel Stone | 37816df | 2012-05-16 18:45:18 +0100 | [diff] [blame] | 4420 | wl_fixed_to_double(seat->pointer->x), |
| 4421 | wl_fixed_to_double(seat->pointer->y), |
Daniel Stone | 103db7f | 2012-05-08 17:17:55 +0100 | [diff] [blame] | 4422 | NULL)) { |
Daniel Stone | 325fc2d | 2012-05-30 16:31:58 +0100 | [diff] [blame] | 4423 | if (key == KEY_PAGEUP) |
Kristian Høgsberg | 9b68af0 | 2012-05-22 12:55:18 -0400 | [diff] [blame] | 4424 | increment = output->zoom.increment; |
Daniel Stone | 325fc2d | 2012-05-30 16:31:58 +0100 | [diff] [blame] | 4425 | else if (key == KEY_PAGEDOWN) |
Kristian Høgsberg | 9b68af0 | 2012-05-22 12:55:18 -0400 | [diff] [blame] | 4426 | increment = -output->zoom.increment; |
| 4427 | else if (axis == WL_POINTER_AXIS_VERTICAL_SCROLL) |
Jonas Ådahl | b0b87ba | 2012-09-27 18:40:42 +0200 | [diff] [blame] | 4428 | /* For every pixel zoom 20th of a step */ |
Daniel Stone | 0c1e46e | 2012-05-30 16:31:59 +0100 | [diff] [blame] | 4429 | increment = output->zoom.increment * |
Jonas Ådahl | b0b87ba | 2012-09-27 18:40:42 +0200 | [diff] [blame] | 4430 | -wl_fixed_to_double(value) / 20.0; |
Kristian Høgsberg | 9b68af0 | 2012-05-22 12:55:18 -0400 | [diff] [blame] | 4431 | else |
| 4432 | increment = 0; |
| 4433 | |
Kristian Høgsberg | 9b68af0 | 2012-05-22 12:55:18 -0400 | [diff] [blame] | 4434 | output->zoom.level += increment; |
Scott Moreau | c6d7f60 | 2012-02-23 22:28:37 -0700 | [diff] [blame] | 4435 | |
Scott Moreau | e660398 | 2012-06-11 13:07:51 -0600 | [diff] [blame] | 4436 | if (output->zoom.level < 0.0) |
Scott Moreau | 850ca42 | 2012-05-21 15:21:25 -0600 | [diff] [blame] | 4437 | output->zoom.level = 0.0; |
Scott Moreau | e660398 | 2012-06-11 13:07:51 -0600 | [diff] [blame] | 4438 | else if (output->zoom.level > output->zoom.max_level) |
| 4439 | output->zoom.level = output->zoom.max_level; |
Ville Syrjälä | aa628d0 | 2012-11-16 11:48:47 +0200 | [diff] [blame] | 4440 | else if (!output->zoom.active) { |
Giulio Camuffo | 412b024 | 2013-11-14 23:42:51 +0100 | [diff] [blame] | 4441 | weston_output_activate_zoom(output); |
Kristian Høgsberg | 79af73e | 2012-08-03 15:45:23 -0400 | [diff] [blame] | 4442 | } |
Scott Moreau | ccbf29d | 2012-02-22 14:21:41 -0700 | [diff] [blame] | 4443 | |
Scott Moreau | e660398 | 2012-06-11 13:07:51 -0600 | [diff] [blame] | 4444 | output->zoom.spring_z.target = output->zoom.level; |
Scott Moreau | ccbf29d | 2012-02-22 14:21:41 -0700 | [diff] [blame] | 4445 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 4446 | weston_output_update_zoom(output); |
Scott Moreau | ccbf29d | 2012-02-22 14:21:41 -0700 | [diff] [blame] | 4447 | } |
| 4448 | } |
| 4449 | } |
| 4450 | |
Scott Moreau | ccbf29d | 2012-02-22 14:21:41 -0700 | [diff] [blame] | 4451 | static void |
Kristian Høgsberg | e314875 | 2013-05-06 23:19:49 -0400 | [diff] [blame] | 4452 | 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] | 4453 | wl_fixed_t value, void *data) |
Daniel Stone | 325fc2d | 2012-05-30 16:31:58 +0100 | [diff] [blame] | 4454 | { |
| 4455 | do_zoom(seat, time, 0, axis, value); |
| 4456 | } |
| 4457 | |
| 4458 | static void |
Kristian Høgsberg | e314875 | 2013-05-06 23:19:49 -0400 | [diff] [blame] | 4459 | 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] | 4460 | void *data) |
| 4461 | { |
| 4462 | do_zoom(seat, time, key, 0, 0); |
| 4463 | } |
| 4464 | |
| 4465 | static void |
Kristian Høgsberg | e314875 | 2013-05-06 23:19:49 -0400 | [diff] [blame] | 4466 | terminate_binding(struct weston_seat *seat, uint32_t time, uint32_t key, |
Daniel Stone | 325fc2d | 2012-05-30 16:31:58 +0100 | [diff] [blame] | 4467 | void *data) |
Kristian Høgsberg | e1a850e | 2011-12-19 15:18:05 -0500 | [diff] [blame] | 4468 | { |
Kristian Høgsberg | 8334bc1 | 2012-01-03 10:29:47 -0500 | [diff] [blame] | 4469 | struct weston_compositor *compositor = data; |
Kristian Høgsberg | e1a850e | 2011-12-19 15:18:05 -0500 | [diff] [blame] | 4470 | |
Daniel Stone | 325fc2d | 2012-05-30 16:31:58 +0100 | [diff] [blame] | 4471 | wl_display_terminate(compositor->wl_display); |
Kristian Høgsberg | e1a850e | 2011-12-19 15:18:05 -0500 | [diff] [blame] | 4472 | } |
| 4473 | |
Emilio Pozuelo Monfort | 03251b6 | 2013-11-19 11:37:16 +0100 | [diff] [blame] | 4474 | static void |
Giulio Camuffo | 1959ab8 | 2013-11-14 23:42:52 +0100 | [diff] [blame] | 4475 | rotate_grab_motion(struct weston_pointer_grab *grab, uint32_t time, |
| 4476 | wl_fixed_t x, wl_fixed_t y) |
Pekka Paalanen | 460099f | 2012-01-20 16:48:25 +0200 | [diff] [blame] | 4477 | { |
| 4478 | struct rotate_grab *rotate = |
Ander Conselvan de Oliveira | fe0444a | 2012-04-04 17:48:05 +0300 | [diff] [blame] | 4479 | container_of(grab, struct rotate_grab, base.grab); |
Kristian Høgsberg | 02bbabb | 2013-05-06 22:15:05 -0400 | [diff] [blame] | 4480 | struct weston_pointer *pointer = grab->pointer; |
Ander Conselvan de Oliveira | fe0444a | 2012-04-04 17:48:05 +0300 | [diff] [blame] | 4481 | struct shell_surface *shsurf = rotate->base.shsurf; |
John Kåre Alsaker | 490d02a | 2012-09-30 02:57:21 +0200 | [diff] [blame] | 4482 | float cx, cy, dx, dy, cposx, cposy, dposx, dposy, r; |
Ander Conselvan de Oliveira | fe0444a | 2012-04-04 17:48:05 +0300 | [diff] [blame] | 4483 | |
Giulio Camuffo | 1959ab8 | 2013-11-14 23:42:52 +0100 | [diff] [blame] | 4484 | weston_pointer_move(pointer, x, y); |
| 4485 | |
Ander Conselvan de Oliveira | fe0444a | 2012-04-04 17:48:05 +0300 | [diff] [blame] | 4486 | if (!shsurf) |
| 4487 | return; |
| 4488 | |
Jason Ekstrand | 918f2dd | 2013-12-02 21:01:53 -0600 | [diff] [blame] | 4489 | cx = 0.5f * shsurf->surface->width; |
| 4490 | cy = 0.5f * shsurf->surface->height; |
Pekka Paalanen | 460099f | 2012-01-20 16:48:25 +0200 | [diff] [blame] | 4491 | |
Daniel Stone | 37816df | 2012-05-16 18:45:18 +0100 | [diff] [blame] | 4492 | dx = wl_fixed_to_double(pointer->x) - rotate->center.x; |
| 4493 | dy = wl_fixed_to_double(pointer->y) - rotate->center.y; |
Pekka Paalanen | 460099f | 2012-01-20 16:48:25 +0200 | [diff] [blame] | 4494 | r = sqrtf(dx * dx + dy * dy); |
| 4495 | |
Ander Conselvan de Oliveira | fe0444a | 2012-04-04 17:48:05 +0300 | [diff] [blame] | 4496 | wl_list_remove(&shsurf->rotation.transform.link); |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 4497 | weston_view_geometry_dirty(shsurf->view); |
Pekka Paalanen | 460099f | 2012-01-20 16:48:25 +0200 | [diff] [blame] | 4498 | |
| 4499 | if (r > 20.0f) { |
Pekka Paalanen | 460099f | 2012-01-20 16:48:25 +0200 | [diff] [blame] | 4500 | struct weston_matrix *matrix = |
Ander Conselvan de Oliveira | fe0444a | 2012-04-04 17:48:05 +0300 | [diff] [blame] | 4501 | &shsurf->rotation.transform.matrix; |
Pekka Paalanen | 460099f | 2012-01-20 16:48:25 +0200 | [diff] [blame] | 4502 | |
Kristian Høgsberg | 765e27b | 2012-01-27 13:36:13 -0500 | [diff] [blame] | 4503 | weston_matrix_init(&rotate->rotation); |
Vasily Khoruzhick | 1bbf372 | 2013-01-28 22:40:28 +0300 | [diff] [blame] | 4504 | weston_matrix_rotate_xy(&rotate->rotation, dx / r, dy / r); |
Pekka Paalanen | 460099f | 2012-01-20 16:48:25 +0200 | [diff] [blame] | 4505 | |
| 4506 | weston_matrix_init(matrix); |
Pekka Paalanen | 7b3bd3d | 2012-01-30 14:16:34 +0200 | [diff] [blame] | 4507 | weston_matrix_translate(matrix, -cx, -cy, 0.0f); |
Ander Conselvan de Oliveira | fe0444a | 2012-04-04 17:48:05 +0300 | [diff] [blame] | 4508 | weston_matrix_multiply(matrix, &shsurf->rotation.rotation); |
Kristian Høgsberg | 765e27b | 2012-01-27 13:36:13 -0500 | [diff] [blame] | 4509 | weston_matrix_multiply(matrix, &rotate->rotation); |
Pekka Paalanen | 7b3bd3d | 2012-01-30 14:16:34 +0200 | [diff] [blame] | 4510 | weston_matrix_translate(matrix, cx, cy, 0.0f); |
Pekka Paalanen | 460099f | 2012-01-20 16:48:25 +0200 | [diff] [blame] | 4511 | |
Pekka Paalanen | bc0b7e7 | 2012-01-24 09:53:37 +0200 | [diff] [blame] | 4512 | wl_list_insert( |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 4513 | &shsurf->view->geometry.transformation_list, |
Ander Conselvan de Oliveira | fe0444a | 2012-04-04 17:48:05 +0300 | [diff] [blame] | 4514 | &shsurf->rotation.transform.link); |
Pekka Paalanen | 460099f | 2012-01-20 16:48:25 +0200 | [diff] [blame] | 4515 | } else { |
Ander Conselvan de Oliveira | fe0444a | 2012-04-04 17:48:05 +0300 | [diff] [blame] | 4516 | wl_list_init(&shsurf->rotation.transform.link); |
| 4517 | weston_matrix_init(&shsurf->rotation.rotation); |
Kristian Høgsberg | 765e27b | 2012-01-27 13:36:13 -0500 | [diff] [blame] | 4518 | weston_matrix_init(&rotate->rotation); |
Pekka Paalanen | 460099f | 2012-01-20 16:48:25 +0200 | [diff] [blame] | 4519 | } |
Pekka Paalanen | b45ac5e | 2012-02-09 15:58:44 +0200 | [diff] [blame] | 4520 | |
Rafal Mielniczuk | 2d7ab82 | 2012-03-22 22:22:04 +0100 | [diff] [blame] | 4521 | /* We need to adjust the position of the surface |
| 4522 | * in case it was resized in a rotated state before */ |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 4523 | cposx = shsurf->view->geometry.x + cx; |
| 4524 | cposy = shsurf->view->geometry.y + cy; |
Rafal Mielniczuk | 2d7ab82 | 2012-03-22 22:22:04 +0100 | [diff] [blame] | 4525 | dposx = rotate->center.x - cposx; |
| 4526 | dposy = rotate->center.y - cposy; |
| 4527 | if (dposx != 0.0f || dposy != 0.0f) { |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 4528 | weston_view_set_position(shsurf->view, |
| 4529 | shsurf->view->geometry.x + dposx, |
| 4530 | shsurf->view->geometry.y + dposy); |
Rafal Mielniczuk | 2d7ab82 | 2012-03-22 22:22:04 +0100 | [diff] [blame] | 4531 | } |
| 4532 | |
Pekka Paalanen | b45ac5e | 2012-02-09 15:58:44 +0200 | [diff] [blame] | 4533 | /* Repaint implies weston_surface_update_transform(), which |
| 4534 | * lazily applies the damage due to rotation update. |
| 4535 | */ |
Ander Conselvan de Oliveira | fe0444a | 2012-04-04 17:48:05 +0300 | [diff] [blame] | 4536 | weston_compositor_schedule_repaint(shsurf->surface->compositor); |
Pekka Paalanen | 460099f | 2012-01-20 16:48:25 +0200 | [diff] [blame] | 4537 | } |
| 4538 | |
| 4539 | static void |
Kristian Høgsberg | 02bbabb | 2013-05-06 22:15:05 -0400 | [diff] [blame] | 4540 | rotate_grab_button(struct weston_pointer_grab *grab, |
| 4541 | uint32_t time, uint32_t button, uint32_t state_w) |
Pekka Paalanen | 460099f | 2012-01-20 16:48:25 +0200 | [diff] [blame] | 4542 | { |
| 4543 | struct rotate_grab *rotate = |
Ander Conselvan de Oliveira | fe0444a | 2012-04-04 17:48:05 +0300 | [diff] [blame] | 4544 | container_of(grab, struct rotate_grab, base.grab); |
Kristian Høgsberg | 02bbabb | 2013-05-06 22:15:05 -0400 | [diff] [blame] | 4545 | struct weston_pointer *pointer = grab->pointer; |
Ander Conselvan de Oliveira | fe0444a | 2012-04-04 17:48:05 +0300 | [diff] [blame] | 4546 | struct shell_surface *shsurf = rotate->base.shsurf; |
Daniel Stone | 4dbadb1 | 2012-05-30 16:31:51 +0100 | [diff] [blame] | 4547 | enum wl_pointer_button_state state = state_w; |
Pekka Paalanen | 460099f | 2012-01-20 16:48:25 +0200 | [diff] [blame] | 4548 | |
Daniel Stone | 4dbadb1 | 2012-05-30 16:31:51 +0100 | [diff] [blame] | 4549 | if (pointer->button_count == 0 && |
| 4550 | state == WL_POINTER_BUTTON_STATE_RELEASED) { |
Ander Conselvan de Oliveira | fe0444a | 2012-04-04 17:48:05 +0300 | [diff] [blame] | 4551 | if (shsurf) |
| 4552 | weston_matrix_multiply(&shsurf->rotation.rotation, |
| 4553 | &rotate->rotation); |
Ander Conselvan de Oliveira | b9d2a0f | 2012-06-28 18:08:05 +0300 | [diff] [blame] | 4554 | shell_grab_end(&rotate->base); |
Pekka Paalanen | 460099f | 2012-01-20 16:48:25 +0200 | [diff] [blame] | 4555 | free(rotate); |
| 4556 | } |
| 4557 | } |
| 4558 | |
Jonas Ådahl | 1ea343e | 2013-10-25 23:18:05 +0200 | [diff] [blame] | 4559 | static void |
| 4560 | rotate_grab_cancel(struct weston_pointer_grab *grab) |
| 4561 | { |
| 4562 | struct rotate_grab *rotate = |
| 4563 | container_of(grab, struct rotate_grab, base.grab); |
| 4564 | |
| 4565 | shell_grab_end(&rotate->base); |
| 4566 | free(rotate); |
| 4567 | } |
| 4568 | |
Kristian Høgsberg | 02bbabb | 2013-05-06 22:15:05 -0400 | [diff] [blame] | 4569 | static const struct weston_pointer_grab_interface rotate_grab_interface = { |
Pekka Paalanen | 460099f | 2012-01-20 16:48:25 +0200 | [diff] [blame] | 4570 | noop_grab_focus, |
| 4571 | rotate_grab_motion, |
| 4572 | rotate_grab_button, |
Jonas Ådahl | 1ea343e | 2013-10-25 23:18:05 +0200 | [diff] [blame] | 4573 | rotate_grab_cancel, |
Pekka Paalanen | 460099f | 2012-01-20 16:48:25 +0200 | [diff] [blame] | 4574 | }; |
| 4575 | |
| 4576 | static void |
Kristian Høgsberg | e314875 | 2013-05-06 23:19:49 -0400 | [diff] [blame] | 4577 | surface_rotate(struct shell_surface *surface, struct weston_seat *seat) |
Pekka Paalanen | 460099f | 2012-01-20 16:48:25 +0200 | [diff] [blame] | 4578 | { |
Pekka Paalanen | 460099f | 2012-01-20 16:48:25 +0200 | [diff] [blame] | 4579 | struct rotate_grab *rotate; |
John Kåre Alsaker | 490d02a | 2012-09-30 02:57:21 +0200 | [diff] [blame] | 4580 | float dx, dy; |
| 4581 | float r; |
Pekka Paalanen | 460099f | 2012-01-20 16:48:25 +0200 | [diff] [blame] | 4582 | |
Pekka Paalanen | 460099f | 2012-01-20 16:48:25 +0200 | [diff] [blame] | 4583 | rotate = malloc(sizeof *rotate); |
| 4584 | if (!rotate) |
| 4585 | return; |
| 4586 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 4587 | weston_view_to_global_float(surface->view, |
Jason Ekstrand | 918f2dd | 2013-12-02 21:01:53 -0600 | [diff] [blame] | 4588 | surface->surface->width * 0.5f, |
| 4589 | surface->surface->height * 0.5f, |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 4590 | &rotate->center.x, &rotate->center.y); |
Pekka Paalanen | 460099f | 2012-01-20 16:48:25 +0200 | [diff] [blame] | 4591 | |
Daniel Stone | 37816df | 2012-05-16 18:45:18 +0100 | [diff] [blame] | 4592 | dx = wl_fixed_to_double(seat->pointer->x) - rotate->center.x; |
| 4593 | dy = wl_fixed_to_double(seat->pointer->y) - rotate->center.y; |
Kristian Høgsberg | 765e27b | 2012-01-27 13:36:13 -0500 | [diff] [blame] | 4594 | r = sqrtf(dx * dx + dy * dy); |
| 4595 | if (r > 20.0f) { |
| 4596 | struct weston_matrix inverse; |
| 4597 | |
| 4598 | weston_matrix_init(&inverse); |
Vasily Khoruzhick | 1bbf372 | 2013-01-28 22:40:28 +0300 | [diff] [blame] | 4599 | weston_matrix_rotate_xy(&inverse, dx / r, -dy / r); |
Kristian Høgsberg | 765e27b | 2012-01-27 13:36:13 -0500 | [diff] [blame] | 4600 | weston_matrix_multiply(&surface->rotation.rotation, &inverse); |
Rafal Mielniczuk | 2d7ab82 | 2012-03-22 22:22:04 +0100 | [diff] [blame] | 4601 | |
| 4602 | weston_matrix_init(&rotate->rotation); |
Vasily Khoruzhick | 1bbf372 | 2013-01-28 22:40:28 +0300 | [diff] [blame] | 4603 | weston_matrix_rotate_xy(&rotate->rotation, dx / r, dy / r); |
Kristian Høgsberg | 765e27b | 2012-01-27 13:36:13 -0500 | [diff] [blame] | 4604 | } else { |
| 4605 | weston_matrix_init(&surface->rotation.rotation); |
| 4606 | weston_matrix_init(&rotate->rotation); |
| 4607 | } |
| 4608 | |
Ander Conselvan de Oliveira | b9d2a0f | 2012-06-28 18:08:05 +0300 | [diff] [blame] | 4609 | shell_grab_start(&rotate->base, &rotate_grab_interface, surface, |
| 4610 | seat->pointer, DESKTOP_SHELL_CURSOR_ARROW); |
Pekka Paalanen | 460099f | 2012-01-20 16:48:25 +0200 | [diff] [blame] | 4611 | } |
| 4612 | |
| 4613 | static void |
Kristian Høgsberg | e314875 | 2013-05-06 23:19:49 -0400 | [diff] [blame] | 4614 | 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] | 4615 | void *data) |
| 4616 | { |
Rafal Mielniczuk | b2917a2 | 2014-01-05 20:04:59 +0100 | [diff] [blame] | 4617 | struct weston_surface *focus; |
Pekka Paalanen | 01388e2 | 2013-04-25 13:57:44 +0300 | [diff] [blame] | 4618 | struct weston_surface *base_surface; |
Kristian Høgsberg | 0c36903 | 2013-02-14 21:31:44 -0500 | [diff] [blame] | 4619 | struct shell_surface *surface; |
| 4620 | |
Rafal Mielniczuk | b2917a2 | 2014-01-05 20:04:59 +0100 | [diff] [blame] | 4621 | if (seat->pointer->focus == NULL) |
| 4622 | return; |
| 4623 | |
| 4624 | focus = seat->pointer->focus->surface; |
| 4625 | |
Pekka Paalanen | 01388e2 | 2013-04-25 13:57:44 +0300 | [diff] [blame] | 4626 | base_surface = weston_surface_get_main_surface(focus); |
Kristian Høgsberg | 0c36903 | 2013-02-14 21:31:44 -0500 | [diff] [blame] | 4627 | if (base_surface == NULL) |
| 4628 | return; |
| 4629 | |
| 4630 | surface = get_shell_surface(base_surface); |
Rafael Antognolli | 03b1659 | 2013-12-03 15:35:42 -0200 | [diff] [blame] | 4631 | if (surface == NULL || surface->state.fullscreen || |
| 4632 | surface->state.maximized) |
Kristian Høgsberg | 0c36903 | 2013-02-14 21:31:44 -0500 | [diff] [blame] | 4633 | return; |
| 4634 | |
| 4635 | surface_rotate(surface, seat); |
| 4636 | } |
| 4637 | |
Emilio Pozuelo Monfort | 9e7c759 | 2014-01-30 14:01:10 +0100 | [diff] [blame] | 4638 | /* Move all fullscreen layers down to the current workspace and hide their |
| 4639 | * black views. The surfaces' state is set to both fullscreen and lowered, |
| 4640 | * and this is reversed when such a surface is re-configured, see |
| 4641 | * shell_configure_fullscreen() and shell_ensure_fullscreen_black_view(). |
| 4642 | * |
| 4643 | * This should be used when implementing shell-wide overlays, such as |
Philip Withnall | 83ffd9d | 2013-11-25 18:01:42 +0000 | [diff] [blame] | 4644 | * the alt-tab switcher, which need to de-promote fullscreen layers. */ |
Kristian Høgsberg | 1ef2313 | 2013-12-04 00:20:01 -0800 | [diff] [blame] | 4645 | void |
Kristian Høgsberg | b0d8e77 | 2012-06-18 16:34:58 -0400 | [diff] [blame] | 4646 | lower_fullscreen_layer(struct desktop_shell *shell) |
| 4647 | { |
| 4648 | struct workspace *ws; |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 4649 | struct weston_view *view, *prev; |
Kristian Høgsberg | b0d8e77 | 2012-06-18 16:34:58 -0400 | [diff] [blame] | 4650 | |
| 4651 | ws = get_current_workspace(shell); |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 4652 | wl_list_for_each_reverse_safe(view, prev, |
Giulio Camuffo | 412e6a5 | 2014-07-09 22:12:56 +0300 | [diff] [blame] | 4653 | &shell->fullscreen_layer.view_list.link, |
| 4654 | layer_link.link) { |
Emilio Pozuelo Monfort | 9e7c759 | 2014-01-30 14:01:10 +0100 | [diff] [blame] | 4655 | struct shell_surface *shsurf = get_shell_surface(view->surface); |
| 4656 | |
| 4657 | if (!shsurf) |
| 4658 | continue; |
| 4659 | |
| 4660 | /* We can have a non-fullscreen popup for a fullscreen surface |
| 4661 | * in the fullscreen layer. */ |
| 4662 | if (shsurf->state.fullscreen) { |
| 4663 | /* Hide the black view */ |
Giulio Camuffo | 412e6a5 | 2014-07-09 22:12:56 +0300 | [diff] [blame] | 4664 | weston_layer_entry_remove(&shsurf->fullscreen.black_view->layer_link); |
| 4665 | wl_list_init(&shsurf->fullscreen.black_view->layer_link.link); |
Kristian Høgsberg | c991513 | 2014-05-09 16:24:07 -0700 | [diff] [blame] | 4666 | weston_view_damage_below(shsurf->fullscreen.black_view); |
| 4667 | |
Emilio Pozuelo Monfort | 9e7c759 | 2014-01-30 14:01:10 +0100 | [diff] [blame] | 4668 | } |
| 4669 | |
| 4670 | /* Lower the view to the workspace layer */ |
Giulio Camuffo | 412e6a5 | 2014-07-09 22:12:56 +0300 | [diff] [blame] | 4671 | weston_layer_entry_remove(&view->layer_link); |
| 4672 | weston_layer_entry_insert(&ws->layer.view_list, &view->layer_link); |
Philip Withnall | 83ffd9d | 2013-11-25 18:01:42 +0000 | [diff] [blame] | 4673 | weston_view_damage_below(view); |
| 4674 | weston_surface_damage(view->surface); |
Emilio Pozuelo Monfort | 9e7c759 | 2014-01-30 14:01:10 +0100 | [diff] [blame] | 4675 | |
| 4676 | shsurf->state.lowered = true; |
Philip Withnall | 83ffd9d | 2013-11-25 18:01:42 +0000 | [diff] [blame] | 4677 | } |
Kristian Høgsberg | b0d8e77 | 2012-06-18 16:34:58 -0400 | [diff] [blame] | 4678 | } |
| 4679 | |
Kristian Høgsberg | 1ef2313 | 2013-12-04 00:20:01 -0800 | [diff] [blame] | 4680 | void |
Tiago Vignatti | be14326 | 2012-04-16 17:31:41 +0300 | [diff] [blame] | 4681 | activate(struct desktop_shell *shell, struct weston_surface *es, |
Emilio Pozuelo Monfort | 9e7c759 | 2014-01-30 14:01:10 +0100 | [diff] [blame] | 4682 | struct weston_seat *seat, bool configure) |
Kristian Høgsberg | 7584062 | 2011-09-06 13:48:16 -0400 | [diff] [blame] | 4683 | { |
Pekka Paalanen | 01388e2 | 2013-04-25 13:57:44 +0300 | [diff] [blame] | 4684 | struct weston_surface *main_surface; |
Kristian Høgsberg | 2f5faff | 2012-07-31 16:36:34 -0400 | [diff] [blame] | 4685 | struct focus_state *state; |
Jonas Ådahl | 8538b22 | 2012-08-29 22:13:03 +0200 | [diff] [blame] | 4686 | struct workspace *ws; |
Louis-Francis Ratté-Boulianne | b482dbd | 2013-11-19 11:37:11 +0100 | [diff] [blame] | 4687 | struct weston_surface *old_es; |
Rafael Antognolli | 03b1659 | 2013-12-03 15:35:42 -0200 | [diff] [blame] | 4688 | struct shell_surface *shsurf; |
Kristian Høgsberg | 7584062 | 2011-09-06 13:48:16 -0400 | [diff] [blame] | 4689 | |
Kristian Høgsberg | 6110d07 | 2014-04-29 15:15:45 -0700 | [diff] [blame] | 4690 | lower_fullscreen_layer(shell); |
| 4691 | |
Pekka Paalanen | 01388e2 | 2013-04-25 13:57:44 +0300 | [diff] [blame] | 4692 | main_surface = weston_surface_get_main_surface(es); |
| 4693 | |
Daniel Stone | 37816df | 2012-05-16 18:45:18 +0100 | [diff] [blame] | 4694 | weston_surface_activate(es, seat); |
Kristian Høgsberg | 7584062 | 2011-09-06 13:48:16 -0400 | [diff] [blame] | 4695 | |
Jonas Ådahl | 8538b22 | 2012-08-29 22:13:03 +0200 | [diff] [blame] | 4696 | state = ensure_focus_state(shell, seat); |
| 4697 | if (state == NULL) |
| 4698 | return; |
Kristian Høgsberg | 2f5faff | 2012-07-31 16:36:34 -0400 | [diff] [blame] | 4699 | |
Louis-Francis Ratté-Boulianne | b482dbd | 2013-11-19 11:37:11 +0100 | [diff] [blame] | 4700 | old_es = state->keyboard_focus; |
Kristian Høgsberg | d500bf1 | 2014-01-22 12:25:20 -0800 | [diff] [blame] | 4701 | focus_state_set_focus(state, es); |
Kristian Høgsberg | 2f5faff | 2012-07-31 16:36:34 -0400 | [diff] [blame] | 4702 | |
Rafael Antognolli | 03b1659 | 2013-12-03 15:35:42 -0200 | [diff] [blame] | 4703 | shsurf = get_shell_surface(main_surface); |
U. Artie Eoff | cf5737a | 2014-01-17 10:08:25 -0800 | [diff] [blame] | 4704 | assert(shsurf); |
| 4705 | |
Emilio Pozuelo Monfort | 9e7c759 | 2014-01-30 14:01:10 +0100 | [diff] [blame] | 4706 | if (shsurf->state.fullscreen && configure) |
Rafael Antognolli | 03b1659 | 2013-12-03 15:35:42 -0200 | [diff] [blame] | 4707 | shell_configure_fullscreen(shsurf); |
| 4708 | else |
Alexander Larsson | f82b6ca | 2013-05-28 16:23:39 +0200 | [diff] [blame] | 4709 | restore_all_output_modes(shell->compositor); |
Louis-Francis Ratté-Boulianne | b482dbd | 2013-11-19 11:37:11 +0100 | [diff] [blame] | 4710 | |
Emilio Pozuelo Monfort | 7908bff | 2014-01-30 13:49:39 +0100 | [diff] [blame] | 4711 | /* Update the surface’s layer. This brings it to the top of the stacking |
| 4712 | * order as appropriate. */ |
| 4713 | shell_surface_update_layer(shsurf); |
| 4714 | |
Philip Withnall | 83ffd9d | 2013-11-25 18:01:42 +0000 | [diff] [blame] | 4715 | if (shell->focus_animation_type != ANIMATION_NONE) { |
| 4716 | ws = get_current_workspace(shell); |
Louis-Francis Ratté-Boulianne | b482dbd | 2013-11-19 11:37:11 +0100 | [diff] [blame] | 4717 | 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] | 4718 | } |
Kristian Høgsberg | 7584062 | 2011-09-06 13:48:16 -0400 | [diff] [blame] | 4719 | } |
| 4720 | |
Alex Wu | 2185843 | 2012-04-01 20:13:08 +0800 | [diff] [blame] | 4721 | /* no-op func for checking black surface */ |
| 4722 | static void |
Jason Ekstrand | 918f2dd | 2013-12-02 21:01:53 -0600 | [diff] [blame] | 4723 | 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] | 4724 | { |
| 4725 | } |
| 4726 | |
Quentin Glidic | c0d79ce | 2013-01-29 14:16:13 +0100 | [diff] [blame] | 4727 | static bool |
Alex Wu | 2185843 | 2012-04-01 20:13:08 +0800 | [diff] [blame] | 4728 | is_black_surface (struct weston_surface *es, struct weston_surface **fs_surface) |
| 4729 | { |
| 4730 | if (es->configure == black_surface_configure) { |
| 4731 | if (fs_surface) |
Giulio Camuffo | 7fe01b1 | 2013-03-28 18:02:42 +0100 | [diff] [blame] | 4732 | *fs_surface = (struct weston_surface *)es->configure_private; |
Alex Wu | 2185843 | 2012-04-01 20:13:08 +0800 | [diff] [blame] | 4733 | return true; |
| 4734 | } |
| 4735 | return false; |
| 4736 | } |
| 4737 | |
Kristian Høgsberg | 7584062 | 2011-09-06 13:48:16 -0400 | [diff] [blame] | 4738 | static void |
Neil Roberts | a28c693 | 2013-10-03 16:43:04 +0100 | [diff] [blame] | 4739 | activate_binding(struct weston_seat *seat, |
| 4740 | struct desktop_shell *shell, |
| 4741 | struct weston_surface *focus) |
Kristian Høgsberg | e1a850e | 2011-12-19 15:18:05 -0500 | [diff] [blame] | 4742 | { |
Pekka Paalanen | 01388e2 | 2013-04-25 13:57:44 +0300 | [diff] [blame] | 4743 | struct weston_surface *main_surface; |
Kristian Høgsberg | e1a850e | 2011-12-19 15:18:05 -0500 | [diff] [blame] | 4744 | |
Alex Wu | 9c35e6b | 2012-03-05 14:13:13 +0800 | [diff] [blame] | 4745 | if (!focus) |
| 4746 | return; |
| 4747 | |
Pekka Paalanen | 01388e2 | 2013-04-25 13:57:44 +0300 | [diff] [blame] | 4748 | if (is_black_surface(focus, &main_surface)) |
| 4749 | focus = main_surface; |
Alex Wu | 4539b08 | 2012-03-01 12:57:46 +0800 | [diff] [blame] | 4750 | |
Pekka Paalanen | 01388e2 | 2013-04-25 13:57:44 +0300 | [diff] [blame] | 4751 | main_surface = weston_surface_get_main_surface(focus); |
| 4752 | if (get_shell_surface_type(main_surface) == SHELL_SURFACE_NONE) |
Kristian Høgsberg | 0636ac3 | 2012-06-27 10:22:15 -0400 | [diff] [blame] | 4753 | return; |
Kristian Høgsberg | 85b2e4b | 2012-06-21 16:49:42 -0400 | [diff] [blame] | 4754 | |
Emilio Pozuelo Monfort | 9e7c759 | 2014-01-30 14:01:10 +0100 | [diff] [blame] | 4755 | activate(shell, focus, seat, true); |
Neil Roberts | a28c693 | 2013-10-03 16:43:04 +0100 | [diff] [blame] | 4756 | } |
| 4757 | |
| 4758 | static void |
| 4759 | click_to_activate_binding(struct weston_seat *seat, uint32_t time, uint32_t button, |
| 4760 | void *data) |
| 4761 | { |
| 4762 | if (seat->pointer->grab != &seat->pointer->default_grab) |
| 4763 | return; |
Kristian Høgsberg | 7c4f6cc | 2014-01-01 16:28:32 -0800 | [diff] [blame] | 4764 | if (seat->pointer->focus == NULL) |
| 4765 | return; |
Neil Roberts | a28c693 | 2013-10-03 16:43:04 +0100 | [diff] [blame] | 4766 | |
Kristian Høgsberg | 7ab139c | 2013-10-24 16:21:39 -0700 | [diff] [blame] | 4767 | activate_binding(seat, data, seat->pointer->focus->surface); |
Neil Roberts | a28c693 | 2013-10-03 16:43:04 +0100 | [diff] [blame] | 4768 | } |
| 4769 | |
| 4770 | static void |
| 4771 | touch_to_activate_binding(struct weston_seat *seat, uint32_t time, void *data) |
| 4772 | { |
| 4773 | if (seat->touch->grab != &seat->touch->default_grab) |
| 4774 | return; |
Kristian Høgsberg | 0ed6750 | 2014-01-02 23:00:11 -0800 | [diff] [blame] | 4775 | if (seat->touch->focus == NULL) |
| 4776 | return; |
Neil Roberts | a28c693 | 2013-10-03 16:43:04 +0100 | [diff] [blame] | 4777 | |
Kristian Høgsberg | 7ab139c | 2013-10-24 16:21:39 -0700 | [diff] [blame] | 4778 | activate_binding(seat, data, seat->touch->focus->surface); |
Kristian Høgsberg | e1a850e | 2011-12-19 15:18:05 -0500 | [diff] [blame] | 4779 | } |
| 4780 | |
| 4781 | static void |
Neil Roberts | b4a9170 | 2014-04-09 16:33:32 +0100 | [diff] [blame] | 4782 | unfocus_all_seats(struct desktop_shell *shell) |
| 4783 | { |
| 4784 | struct weston_seat *seat, *next; |
| 4785 | |
| 4786 | wl_list_for_each_safe(seat, next, &shell->compositor->seat_list, link) { |
| 4787 | if (seat->keyboard == NULL) |
| 4788 | continue; |
| 4789 | |
| 4790 | weston_keyboard_set_focus(seat->keyboard, NULL); |
| 4791 | } |
| 4792 | } |
| 4793 | |
| 4794 | static void |
Ander Conselvan de Oliveira | 19d10ef | 2013-02-21 18:35:20 +0200 | [diff] [blame] | 4795 | lock(struct desktop_shell *shell) |
Kristian Høgsberg | 02ec0a5 | 2011-04-23 13:04:11 -0400 | [diff] [blame] | 4796 | { |
Kristian Høgsberg | 4476aaf | 2012-06-25 14:03:13 -0400 | [diff] [blame] | 4797 | struct workspace *ws = get_current_workspace(shell); |
Pekka Paalanen | f0fc70d | 2011-11-15 13:34:54 +0200 | [diff] [blame] | 4798 | |
Tiago Vignatti | 8e53c7f | 2012-02-29 19:53:50 +0200 | [diff] [blame] | 4799 | if (shell->locked) { |
Ander Conselvan de Oliveira | 87524b6 | 2013-02-21 18:35:22 +0200 | [diff] [blame] | 4800 | weston_compositor_sleep(shell->compositor); |
Pekka Paalanen | f0fc70d | 2011-11-15 13:34:54 +0200 | [diff] [blame] | 4801 | return; |
Tiago Vignatti | 8e53c7f | 2012-02-29 19:53:50 +0200 | [diff] [blame] | 4802 | } |
Pekka Paalanen | 9ef3e01 | 2011-11-15 13:34:48 +0200 | [diff] [blame] | 4803 | |
| 4804 | shell->locked = true; |
Pekka Paalanen | f0fc70d | 2011-11-15 13:34:54 +0200 | [diff] [blame] | 4805 | |
Kristian Høgsberg | 3be2ce9 | 2012-02-29 12:42:35 -0500 | [diff] [blame] | 4806 | /* Hide all surfaces by removing the fullscreen, panel and |
| 4807 | * toplevel layers. This way nothing else can show or receive |
| 4808 | * input events while we are locked. */ |
Pekka Paalanen | f0fc70d | 2011-11-15 13:34:54 +0200 | [diff] [blame] | 4809 | |
Kristian Høgsberg | 3be2ce9 | 2012-02-29 12:42:35 -0500 | [diff] [blame] | 4810 | wl_list_remove(&shell->panel_layer.link); |
Kristian Høgsberg | 3be2ce9 | 2012-02-29 12:42:35 -0500 | [diff] [blame] | 4811 | wl_list_remove(&shell->fullscreen_layer.link); |
Philipp Brüschweiler | 711fda8 | 2012-08-09 18:50:43 +0200 | [diff] [blame] | 4812 | if (shell->showing_input_panels) |
| 4813 | wl_list_remove(&shell->input_panel_layer.link); |
Kristian Høgsberg | 4476aaf | 2012-06-25 14:03:13 -0400 | [diff] [blame] | 4814 | wl_list_remove(&ws->layer.link); |
Kristian Høgsberg | 3be2ce9 | 2012-02-29 12:42:35 -0500 | [diff] [blame] | 4815 | wl_list_insert(&shell->compositor->cursor_layer.link, |
| 4816 | &shell->lock_layer.link); |
Pekka Paalanen | f0fc70d | 2011-11-15 13:34:54 +0200 | [diff] [blame] | 4817 | |
Pekka Paalanen | 77346a6 | 2011-11-30 16:26:35 +0200 | [diff] [blame] | 4818 | launch_screensaver(shell); |
| 4819 | |
Neil Roberts | b4a9170 | 2014-04-09 16:33:32 +0100 | [diff] [blame] | 4820 | /* Remove the keyboard focus on all seats. This will be |
| 4821 | * restored to the workspace's saved state via |
| 4822 | * restore_focus_state when the compositor is unlocked */ |
| 4823 | unfocus_all_seats(shell); |
| 4824 | |
Pekka Paalanen | f0fc70d | 2011-11-15 13:34:54 +0200 | [diff] [blame] | 4825 | /* TODO: disable bindings that should not work while locked. */ |
| 4826 | |
| 4827 | /* All this must be undone in resume_desktop(). */ |
Pekka Paalanen | 9ef3e01 | 2011-11-15 13:34:48 +0200 | [diff] [blame] | 4828 | } |
| 4829 | |
| 4830 | static void |
Ander Conselvan de Oliveira | 19d10ef | 2013-02-21 18:35:20 +0200 | [diff] [blame] | 4831 | unlock(struct desktop_shell *shell) |
Pekka Paalanen | 9ef3e01 | 2011-11-15 13:34:48 +0200 | [diff] [blame] | 4832 | { |
Pekka Paalanen | d81c216 | 2011-11-16 13:47:34 +0200 | [diff] [blame] | 4833 | if (!shell->locked || shell->lock_surface) { |
Ander Conselvan de Oliveira | 87524b6 | 2013-02-21 18:35:22 +0200 | [diff] [blame] | 4834 | shell_fade(shell, FADE_IN); |
Pekka Paalanen | 9ef3e01 | 2011-11-15 13:34:48 +0200 | [diff] [blame] | 4835 | return; |
| 4836 | } |
| 4837 | |
| 4838 | /* If desktop-shell client has gone away, unlock immediately. */ |
| 4839 | if (!shell->child.desktop_shell) { |
Pekka Paalanen | f0fc70d | 2011-11-15 13:34:54 +0200 | [diff] [blame] | 4840 | resume_desktop(shell); |
Pekka Paalanen | 9ef3e01 | 2011-11-15 13:34:48 +0200 | [diff] [blame] | 4841 | return; |
| 4842 | } |
| 4843 | |
| 4844 | if (shell->prepare_event_sent) |
| 4845 | return; |
| 4846 | |
Kristian Høgsberg | 0b5cd0c | 2012-03-04 21:57:37 -0500 | [diff] [blame] | 4847 | desktop_shell_send_prepare_lock_surface(shell->child.desktop_shell); |
Pekka Paalanen | 9ef3e01 | 2011-11-15 13:34:48 +0200 | [diff] [blame] | 4848 | shell->prepare_event_sent = true; |
Kristian Høgsberg | 02ec0a5 | 2011-04-23 13:04:11 -0400 | [diff] [blame] | 4849 | } |
| 4850 | |
| 4851 | static void |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 4852 | shell_fade_done(struct weston_view_animation *animation, void *data) |
Ander Conselvan de Oliveira | 19d10ef | 2013-02-21 18:35:20 +0200 | [diff] [blame] | 4853 | { |
| 4854 | struct desktop_shell *shell = data; |
| 4855 | |
| 4856 | shell->fade.animation = NULL; |
| 4857 | |
| 4858 | switch (shell->fade.type) { |
| 4859 | case FADE_IN: |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 4860 | weston_surface_destroy(shell->fade.view->surface); |
| 4861 | shell->fade.view = NULL; |
Ander Conselvan de Oliveira | 19d10ef | 2013-02-21 18:35:20 +0200 | [diff] [blame] | 4862 | break; |
| 4863 | case FADE_OUT: |
Ander Conselvan de Oliveira | 19d10ef | 2013-02-21 18:35:20 +0200 | [diff] [blame] | 4864 | lock(shell); |
| 4865 | break; |
Philip Withnall | 4a86a0a | 2013-11-25 18:01:32 +0000 | [diff] [blame] | 4866 | default: |
| 4867 | break; |
Ander Conselvan de Oliveira | 19d10ef | 2013-02-21 18:35:20 +0200 | [diff] [blame] | 4868 | } |
| 4869 | } |
| 4870 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 4871 | static struct weston_view * |
Pekka Paalanen | 79346ab | 2013-05-22 18:03:09 +0300 | [diff] [blame] | 4872 | shell_fade_create_surface(struct desktop_shell *shell) |
Ander Conselvan de Oliveira | 19d10ef | 2013-02-21 18:35:20 +0200 | [diff] [blame] | 4873 | { |
| 4874 | struct weston_compositor *compositor = shell->compositor; |
| 4875 | struct weston_surface *surface; |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 4876 | struct weston_view *view; |
Pekka Paalanen | 79346ab | 2013-05-22 18:03:09 +0300 | [diff] [blame] | 4877 | |
| 4878 | surface = weston_surface_create(compositor); |
| 4879 | if (!surface) |
| 4880 | return NULL; |
| 4881 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 4882 | view = weston_view_create(surface); |
| 4883 | if (!view) { |
| 4884 | weston_surface_destroy(surface); |
| 4885 | return NULL; |
| 4886 | } |
| 4887 | |
Jason Ekstrand | 5c11a33 | 2013-12-04 20:32:03 -0600 | [diff] [blame] | 4888 | weston_surface_set_size(surface, 8192, 8192); |
Jason Ekstrand | 918f2dd | 2013-12-02 21:01:53 -0600 | [diff] [blame] | 4889 | weston_view_set_position(view, 0, 0); |
Pekka Paalanen | 79346ab | 2013-05-22 18:03:09 +0300 | [diff] [blame] | 4890 | 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] | 4891 | weston_layer_entry_insert(&compositor->fade_layer.view_list, |
| 4892 | &view->layer_link); |
Pekka Paalanen | 79346ab | 2013-05-22 18:03:09 +0300 | [diff] [blame] | 4893 | pixman_region32_init(&surface->input); |
| 4894 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 4895 | return view; |
Pekka Paalanen | 79346ab | 2013-05-22 18:03:09 +0300 | [diff] [blame] | 4896 | } |
| 4897 | |
| 4898 | static void |
| 4899 | shell_fade(struct desktop_shell *shell, enum fade_type type) |
| 4900 | { |
Ander Conselvan de Oliveira | 19d10ef | 2013-02-21 18:35:20 +0200 | [diff] [blame] | 4901 | float tint; |
| 4902 | |
| 4903 | switch (type) { |
| 4904 | case FADE_IN: |
| 4905 | tint = 0.0; |
| 4906 | break; |
| 4907 | case FADE_OUT: |
| 4908 | tint = 1.0; |
| 4909 | break; |
| 4910 | default: |
| 4911 | weston_log("shell: invalid fade type\n"); |
| 4912 | return; |
| 4913 | } |
| 4914 | |
| 4915 | shell->fade.type = type; |
| 4916 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 4917 | if (shell->fade.view == NULL) { |
| 4918 | shell->fade.view = shell_fade_create_surface(shell); |
| 4919 | if (!shell->fade.view) |
Ander Conselvan de Oliveira | 19d10ef | 2013-02-21 18:35:20 +0200 | [diff] [blame] | 4920 | return; |
| 4921 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 4922 | shell->fade.view->alpha = 1.0 - tint; |
| 4923 | weston_view_update_transform(shell->fade.view); |
Ander Conselvan de Oliveira | 19d10ef | 2013-02-21 18:35:20 +0200 | [diff] [blame] | 4924 | } |
| 4925 | |
Kristian Høgsberg | 87d3b61 | 2014-01-19 21:48:10 -0800 | [diff] [blame] | 4926 | if (shell->fade.view->output == NULL) { |
| 4927 | /* If the black view gets a NULL output, we lost the |
| 4928 | * last output and we'll just cancel the fade. This |
| 4929 | * happens when you close the last window under the |
| 4930 | * X11 or Wayland backends. */ |
| 4931 | shell->locked = false; |
| 4932 | weston_surface_destroy(shell->fade.view->surface); |
| 4933 | shell->fade.view = NULL; |
| 4934 | } else if (shell->fade.animation) { |
Kristian Høgsberg | 5281fb1 | 2013-06-17 10:10:28 -0400 | [diff] [blame] | 4935 | weston_fade_update(shell->fade.animation, tint); |
Kristian Høgsberg | 87d3b61 | 2014-01-19 21:48:10 -0800 | [diff] [blame] | 4936 | } else { |
Ander Conselvan de Oliveira | 19d10ef | 2013-02-21 18:35:20 +0200 | [diff] [blame] | 4937 | shell->fade.animation = |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 4938 | weston_fade_run(shell->fade.view, |
Kristian Høgsberg | 5281fb1 | 2013-06-17 10:10:28 -0400 | [diff] [blame] | 4939 | 1.0 - tint, tint, 300.0, |
Ander Conselvan de Oliveira | 19d10ef | 2013-02-21 18:35:20 +0200 | [diff] [blame] | 4940 | shell_fade_done, shell); |
Kristian Høgsberg | 87d3b61 | 2014-01-19 21:48:10 -0800 | [diff] [blame] | 4941 | } |
Ander Conselvan de Oliveira | 19d10ef | 2013-02-21 18:35:20 +0200 | [diff] [blame] | 4942 | } |
| 4943 | |
| 4944 | static void |
Pekka Paalanen | 79346ab | 2013-05-22 18:03:09 +0300 | [diff] [blame] | 4945 | do_shell_fade_startup(void *data) |
| 4946 | { |
| 4947 | struct desktop_shell *shell = data; |
| 4948 | |
Kristian Høgsberg | 724c8d9 | 2013-10-16 11:38:24 -0700 | [diff] [blame] | 4949 | if (shell->startup_animation_type == ANIMATION_FADE) |
| 4950 | shell_fade(shell, FADE_IN); |
| 4951 | else if (shell->startup_animation_type == ANIMATION_NONE) { |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 4952 | weston_surface_destroy(shell->fade.view->surface); |
| 4953 | shell->fade.view = NULL; |
Kristian Høgsberg | 724c8d9 | 2013-10-16 11:38:24 -0700 | [diff] [blame] | 4954 | } |
Pekka Paalanen | 79346ab | 2013-05-22 18:03:09 +0300 | [diff] [blame] | 4955 | } |
| 4956 | |
| 4957 | static void |
| 4958 | shell_fade_startup(struct desktop_shell *shell) |
| 4959 | { |
| 4960 | struct wl_event_loop *loop; |
| 4961 | |
| 4962 | if (!shell->fade.startup_timer) |
| 4963 | return; |
| 4964 | |
| 4965 | wl_event_source_remove(shell->fade.startup_timer); |
| 4966 | shell->fade.startup_timer = NULL; |
| 4967 | |
| 4968 | loop = wl_display_get_event_loop(shell->compositor->wl_display); |
| 4969 | wl_event_loop_add_idle(loop, do_shell_fade_startup, shell); |
| 4970 | } |
| 4971 | |
| 4972 | static int |
| 4973 | fade_startup_timeout(void *data) |
| 4974 | { |
| 4975 | struct desktop_shell *shell = data; |
| 4976 | |
| 4977 | shell_fade_startup(shell); |
| 4978 | return 0; |
| 4979 | } |
| 4980 | |
| 4981 | static void |
| 4982 | shell_fade_init(struct desktop_shell *shell) |
| 4983 | { |
| 4984 | /* Make compositor output all black, and wait for the desktop-shell |
| 4985 | * client to signal it is ready, then fade in. The timer triggers a |
| 4986 | * fade-in, in case the desktop-shell client takes too long. |
| 4987 | */ |
| 4988 | |
| 4989 | struct wl_event_loop *loop; |
| 4990 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 4991 | if (shell->fade.view != NULL) { |
Pekka Paalanen | 79346ab | 2013-05-22 18:03:09 +0300 | [diff] [blame] | 4992 | weston_log("%s: warning: fade surface already exists\n", |
| 4993 | __func__); |
| 4994 | return; |
| 4995 | } |
| 4996 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 4997 | shell->fade.view = shell_fade_create_surface(shell); |
| 4998 | if (!shell->fade.view) |
Pekka Paalanen | 79346ab | 2013-05-22 18:03:09 +0300 | [diff] [blame] | 4999 | return; |
| 5000 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 5001 | weston_view_update_transform(shell->fade.view); |
| 5002 | weston_surface_damage(shell->fade.view->surface); |
Pekka Paalanen | 79346ab | 2013-05-22 18:03:09 +0300 | [diff] [blame] | 5003 | |
| 5004 | loop = wl_display_get_event_loop(shell->compositor->wl_display); |
| 5005 | shell->fade.startup_timer = |
| 5006 | wl_event_loop_add_timer(loop, fade_startup_timeout, shell); |
| 5007 | wl_event_source_timer_update(shell->fade.startup_timer, 15000); |
| 5008 | } |
| 5009 | |
| 5010 | static void |
Ander Conselvan de Oliveira | a457563 | 2013-02-21 18:35:23 +0200 | [diff] [blame] | 5011 | idle_handler(struct wl_listener *listener, void *data) |
Ander Conselvan de Oliveira | 19d10ef | 2013-02-21 18:35:20 +0200 | [diff] [blame] | 5012 | { |
| 5013 | struct desktop_shell *shell = |
Ander Conselvan de Oliveira | a457563 | 2013-02-21 18:35:23 +0200 | [diff] [blame] | 5014 | container_of(listener, struct desktop_shell, idle_listener); |
Kristian Høgsberg | 27d5fa8 | 2014-01-17 16:22:50 -0800 | [diff] [blame] | 5015 | struct weston_seat *seat; |
| 5016 | |
| 5017 | wl_list_for_each(seat, &shell->compositor->seat_list, link) |
| 5018 | if (seat->pointer) |
| 5019 | popup_grab_end(seat->pointer); |
Ander Conselvan de Oliveira | 19d10ef | 2013-02-21 18:35:20 +0200 | [diff] [blame] | 5020 | |
| 5021 | shell_fade(shell, FADE_OUT); |
| 5022 | /* lock() is called from shell_fade_done() */ |
| 5023 | } |
| 5024 | |
| 5025 | static void |
Ander Conselvan de Oliveira | a457563 | 2013-02-21 18:35:23 +0200 | [diff] [blame] | 5026 | wake_handler(struct wl_listener *listener, void *data) |
Ander Conselvan de Oliveira | 19d10ef | 2013-02-21 18:35:20 +0200 | [diff] [blame] | 5027 | { |
| 5028 | struct desktop_shell *shell = |
Ander Conselvan de Oliveira | a457563 | 2013-02-21 18:35:23 +0200 | [diff] [blame] | 5029 | container_of(listener, struct desktop_shell, wake_listener); |
Ander Conselvan de Oliveira | 19d10ef | 2013-02-21 18:35:20 +0200 | [diff] [blame] | 5030 | |
Ander Conselvan de Oliveira | 19d10ef | 2013-02-21 18:35:20 +0200 | [diff] [blame] | 5031 | unlock(shell); |
| 5032 | } |
| 5033 | |
| 5034 | static void |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 5035 | center_on_output(struct weston_view *view, struct weston_output *output) |
Pekka Paalanen | 77346a6 | 2011-11-30 16:26:35 +0200 | [diff] [blame] | 5036 | { |
Giulio Camuffo | b836664 | 2013-04-25 13:57:46 +0300 | [diff] [blame] | 5037 | int32_t surf_x, surf_y, width, height; |
Ander Conselvan de Oliveira | 012b4c7 | 2012-11-27 17:03:42 +0200 | [diff] [blame] | 5038 | float x, y; |
Pekka Paalanen | 77346a6 | 2011-11-30 16:26:35 +0200 | [diff] [blame] | 5039 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 5040 | surface_subsurfaces_boundingbox(view->surface, &surf_x, &surf_y, &width, &height); |
Giulio Camuffo | b836664 | 2013-04-25 13:57:46 +0300 | [diff] [blame] | 5041 | |
| 5042 | x = output->x + (output->width - width) / 2 - surf_x / 2; |
| 5043 | y = output->y + (output->height - height) / 2 - surf_y / 2; |
Ander Conselvan de Oliveira | 012b4c7 | 2012-11-27 17:03:42 +0200 | [diff] [blame] | 5044 | |
Jason Ekstrand | 918f2dd | 2013-12-02 21:01:53 -0600 | [diff] [blame] | 5045 | weston_view_set_position(view, x, y); |
Pekka Paalanen | 77346a6 | 2011-11-30 16:26:35 +0200 | [diff] [blame] | 5046 | } |
| 5047 | |
| 5048 | static void |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 5049 | weston_view_set_initial_position(struct weston_view *view, |
| 5050 | struct desktop_shell *shell) |
Rob Bradford | ac63e5b | 2012-08-13 14:07:52 +0100 | [diff] [blame] | 5051 | { |
| 5052 | struct weston_compositor *compositor = shell->compositor; |
| 5053 | int ix = 0, iy = 0; |
Jonny Lamb | d73c694 | 2014-08-20 15:53:20 +0200 | [diff] [blame] | 5054 | int32_t range_x, range_y; |
| 5055 | int32_t dx, dy, x, y; |
Rob Bradford | ac63e5b | 2012-08-13 14:07:52 +0100 | [diff] [blame] | 5056 | struct weston_output *output, *target_output = NULL; |
| 5057 | struct weston_seat *seat; |
Jonny Lamb | d73c694 | 2014-08-20 15:53:20 +0200 | [diff] [blame] | 5058 | pixman_rectangle32_t area; |
Rob Bradford | ac63e5b | 2012-08-13 14:07:52 +0100 | [diff] [blame] | 5059 | |
| 5060 | /* As a heuristic place the new window on the same output as the |
| 5061 | * pointer. Falling back to the output containing 0, 0. |
| 5062 | * |
| 5063 | * TODO: Do something clever for touch too? |
| 5064 | */ |
| 5065 | wl_list_for_each(seat, &compositor->seat_list, link) { |
Kristian Høgsberg | 2bf8762 | 2013-05-07 23:17:41 -0400 | [diff] [blame] | 5066 | if (seat->pointer) { |
Kristian Høgsberg | e314875 | 2013-05-06 23:19:49 -0400 | [diff] [blame] | 5067 | ix = wl_fixed_to_int(seat->pointer->x); |
| 5068 | iy = wl_fixed_to_int(seat->pointer->y); |
Rob Bradford | ac63e5b | 2012-08-13 14:07:52 +0100 | [diff] [blame] | 5069 | break; |
| 5070 | } |
| 5071 | } |
| 5072 | |
| 5073 | wl_list_for_each(output, &compositor->output_list, link) { |
| 5074 | if (pixman_region32_contains_point(&output->region, ix, iy, NULL)) { |
| 5075 | target_output = output; |
| 5076 | break; |
| 5077 | } |
| 5078 | } |
| 5079 | |
| 5080 | if (!target_output) { |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 5081 | weston_view_set_position(view, 10 + random() % 400, |
| 5082 | 10 + random() % 400); |
Rob Bradford | ac63e5b | 2012-08-13 14:07:52 +0100 | [diff] [blame] | 5083 | return; |
| 5084 | } |
| 5085 | |
| 5086 | /* Valid range within output where the surface will still be onscreen. |
| 5087 | * If this is negative it means that the surface is bigger than |
| 5088 | * output. |
| 5089 | */ |
Jonny Lamb | d73c694 | 2014-08-20 15:53:20 +0200 | [diff] [blame] | 5090 | get_output_work_area(shell, target_output, &area); |
| 5091 | |
| 5092 | dx = area.x; |
| 5093 | dy = area.y; |
| 5094 | range_x = area.width - view->surface->width; |
| 5095 | range_y = area.height - view->surface->height; |
Rob Bradford | ac63e5b | 2012-08-13 14:07:52 +0100 | [diff] [blame] | 5096 | |
Rob Bradford | 4cb88c7 | 2012-08-13 15:18:44 +0100 | [diff] [blame] | 5097 | if (range_x > 0) |
Jonny Lamb | d73c694 | 2014-08-20 15:53:20 +0200 | [diff] [blame] | 5098 | dx += random() % range_x; |
Rob Bradford | 4cb88c7 | 2012-08-13 15:18:44 +0100 | [diff] [blame] | 5099 | |
| 5100 | if (range_y > 0) |
Jonny Lamb | d73c694 | 2014-08-20 15:53:20 +0200 | [diff] [blame] | 5101 | dy += random() % range_y; |
Rob Bradford | ac63e5b | 2012-08-13 14:07:52 +0100 | [diff] [blame] | 5102 | |
| 5103 | x = target_output->x + dx; |
| 5104 | y = target_output->y + dy; |
| 5105 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 5106 | weston_view_set_position(view, x, y); |
Rob Bradford | ac63e5b | 2012-08-13 14:07:52 +0100 | [diff] [blame] | 5107 | } |
| 5108 | |
| 5109 | static void |
Jonny Lamb | d73c694 | 2014-08-20 15:53:20 +0200 | [diff] [blame] | 5110 | set_maximized_position(struct desktop_shell *shell, |
| 5111 | struct shell_surface *shsurf) |
| 5112 | { |
| 5113 | int32_t surf_x, surf_y; |
| 5114 | pixman_rectangle32_t area; |
| 5115 | |
| 5116 | /* use surface configure to set the geometry */ |
| 5117 | get_output_work_area(shell, shsurf->output, &area); |
| 5118 | surface_subsurfaces_boundingbox(shsurf->surface, |
| 5119 | &surf_x, &surf_y, NULL, NULL); |
| 5120 | |
| 5121 | weston_view_set_position(shsurf->view, |
| 5122 | area.x - surf_x, |
| 5123 | area.y - surf_y); |
| 5124 | } |
| 5125 | |
| 5126 | static void |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 5127 | map(struct desktop_shell *shell, struct shell_surface *shsurf, |
Jason Ekstrand | 918f2dd | 2013-12-02 21:01:53 -0600 | [diff] [blame] | 5128 | int32_t sx, int32_t sy) |
Kristian Høgsberg | 02ec0a5 | 2011-04-23 13:04:11 -0400 | [diff] [blame] | 5129 | { |
Kristian Høgsberg | 8334bc1 | 2012-01-03 10:29:47 -0500 | [diff] [blame] | 5130 | struct weston_compositor *compositor = shell->compositor; |
Daniel Stone | b210468 | 2012-05-30 16:31:56 +0100 | [diff] [blame] | 5131 | struct weston_seat *seat; |
Pekka Paalanen | 57da4a8 | 2011-11-23 16:42:16 +0200 | [diff] [blame] | 5132 | |
Pekka Paalanen | 77346a6 | 2011-11-30 16:26:35 +0200 | [diff] [blame] | 5133 | /* initial positioning, see also configure() */ |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 5134 | switch (shsurf->type) { |
Rafael Antognolli | ed207b4 | 2013-12-03 15:35:43 -0200 | [diff] [blame] | 5135 | case SHELL_SURFACE_TOPLEVEL: |
Rafael Antognolli | 03b1659 | 2013-12-03 15:35:42 -0200 | [diff] [blame] | 5136 | if (shsurf->state.fullscreen) { |
| 5137 | center_on_output(shsurf->view, shsurf->fullscreen_output); |
| 5138 | shell_map_fullscreen(shsurf); |
| 5139 | } else if (shsurf->state.maximized) { |
Jonny Lamb | d73c694 | 2014-08-20 15:53:20 +0200 | [diff] [blame] | 5140 | set_maximized_position(shell, shsurf); |
Rafael Antognolli | ed207b4 | 2013-12-03 15:35:43 -0200 | [diff] [blame] | 5141 | } else if (!shsurf->state.relative) { |
Rafael Antognolli | 03b1659 | 2013-12-03 15:35:42 -0200 | [diff] [blame] | 5142 | weston_view_set_initial_position(shsurf->view, shell); |
| 5143 | } |
Juan Zhao | 96879df | 2012-02-07 08:45:41 +0800 | [diff] [blame] | 5144 | break; |
Tiago Vignatti | 0f99701 | 2012-02-10 16:17:23 +0200 | [diff] [blame] | 5145 | case SHELL_SURFACE_POPUP: |
Kristian Høgsberg | 3730f36 | 2012-04-13 12:40:07 -0400 | [diff] [blame] | 5146 | shell_map_popup(shsurf); |
Rob Bradford | db99938 | 2012-12-06 12:07:48 +0000 | [diff] [blame] | 5147 | break; |
Ander Conselvan de Oliveira | e9e0515 | 2012-02-15 17:02:56 +0200 | [diff] [blame] | 5148 | case SHELL_SURFACE_NONE: |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 5149 | weston_view_set_position(shsurf->view, |
| 5150 | shsurf->view->geometry.x + sx, |
| 5151 | shsurf->view->geometry.y + sy); |
Tiago Vignatti | 0f99701 | 2012-02-10 16:17:23 +0200 | [diff] [blame] | 5152 | break; |
Philip Withnall | 0f640e2 | 2013-11-25 18:01:31 +0000 | [diff] [blame] | 5153 | case SHELL_SURFACE_XWAYLAND: |
Pekka Paalanen | 77346a6 | 2011-11-30 16:26:35 +0200 | [diff] [blame] | 5154 | default: |
| 5155 | ; |
| 5156 | } |
Kristian Høgsberg | 7584062 | 2011-09-06 13:48:16 -0400 | [diff] [blame] | 5157 | |
Philip Withnall | e1d75ae | 2013-11-25 18:01:41 +0000 | [diff] [blame] | 5158 | /* Surface stacking order, see also activate(). */ |
| 5159 | shell_surface_update_layer(shsurf); |
Pekka Paalanen | f0fc70d | 2011-11-15 13:34:54 +0200 | [diff] [blame] | 5160 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 5161 | if (shsurf->type != SHELL_SURFACE_NONE) { |
| 5162 | weston_view_update_transform(shsurf->view); |
Rafael Antognolli | 03b1659 | 2013-12-03 15:35:42 -0200 | [diff] [blame] | 5163 | if (shsurf->state.maximized) { |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 5164 | shsurf->surface->output = shsurf->output; |
| 5165 | shsurf->view->output = shsurf->output; |
| 5166 | } |
Ander Conselvan de Oliveira | de56c31 | 2012-03-05 15:39:23 +0200 | [diff] [blame] | 5167 | } |
Kristian Høgsberg | 2f88a40 | 2011-12-04 15:32:59 -0500 | [diff] [blame] | 5168 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 5169 | switch (shsurf->type) { |
Tiago Vignatti | fb2adba | 2013-06-12 15:43:21 -0300 | [diff] [blame] | 5170 | /* XXX: xwayland's using the same fields for transient type */ |
| 5171 | case SHELL_SURFACE_XWAYLAND: |
Tiago Vignatti | 99aeb1e | 2012-05-23 22:06:26 +0300 | [diff] [blame] | 5172 | if (shsurf->transient.flags == |
| 5173 | WL_SHELL_SURFACE_TRANSIENT_INACTIVE) |
| 5174 | break; |
| 5175 | case SHELL_SURFACE_TOPLEVEL: |
Rafael Antognolli | ed207b4 | 2013-12-03 15:35:43 -0200 | [diff] [blame] | 5176 | if (shsurf->state.relative && |
| 5177 | shsurf->transient.flags == WL_SHELL_SURFACE_TRANSIENT_INACTIVE) |
| 5178 | break; |
Rafael Antognolli | ba5d2d7 | 2013-12-04 17:49:55 -0200 | [diff] [blame] | 5179 | if (shell->locked) |
Rafael Antognolli | ed207b4 | 2013-12-03 15:35:43 -0200 | [diff] [blame] | 5180 | break; |
| 5181 | wl_list_for_each(seat, &compositor->seat_list, link) |
Emilio Pozuelo Monfort | 9e7c759 | 2014-01-30 14:01:10 +0100 | [diff] [blame] | 5182 | activate(shell, shsurf->surface, seat, true); |
Juan Zhao | 7bb92f0 | 2011-12-15 11:31:51 -0500 | [diff] [blame] | 5183 | break; |
Philip Withnall | 0f640e2 | 2013-11-25 18:01:31 +0000 | [diff] [blame] | 5184 | case SHELL_SURFACE_POPUP: |
| 5185 | case SHELL_SURFACE_NONE: |
Juan Zhao | 7bb92f0 | 2011-12-15 11:31:51 -0500 | [diff] [blame] | 5186 | default: |
| 5187 | break; |
| 5188 | } |
| 5189 | |
Rafael Antognolli | 03b1659 | 2013-12-03 15:35:42 -0200 | [diff] [blame] | 5190 | if (shsurf->type == SHELL_SURFACE_TOPLEVEL && |
| 5191 | !shsurf->state.maximized && !shsurf->state.fullscreen) |
Juan Zhao | e10d279 | 2012-04-25 19:09:52 +0800 | [diff] [blame] | 5192 | { |
| 5193 | switch (shell->win_animation_type) { |
| 5194 | case ANIMATION_FADE: |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 5195 | 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] | 5196 | break; |
| 5197 | case ANIMATION_ZOOM: |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 5198 | weston_zoom_run(shsurf->view, 0.5, 1.0, NULL, NULL); |
Juan Zhao | e10d279 | 2012-04-25 19:09:52 +0800 | [diff] [blame] | 5199 | break; |
Philip Withnall | 4a86a0a | 2013-11-25 18:01:32 +0000 | [diff] [blame] | 5200 | case ANIMATION_NONE: |
Juan Zhao | e10d279 | 2012-04-25 19:09:52 +0800 | [diff] [blame] | 5201 | default: |
| 5202 | break; |
| 5203 | } |
| 5204 | } |
Kristian Høgsberg | 32e24cc | 2011-11-09 12:07:35 -0500 | [diff] [blame] | 5205 | } |
| 5206 | |
| 5207 | static void |
Tiago Vignatti | be14326 | 2012-04-16 17:31:41 +0300 | [diff] [blame] | 5208 | configure(struct desktop_shell *shell, struct weston_surface *surface, |
Jason Ekstrand | 918f2dd | 2013-12-02 21:01:53 -0600 | [diff] [blame] | 5209 | float x, float y) |
Kristian Høgsberg | 32e24cc | 2011-11-09 12:07:35 -0500 | [diff] [blame] | 5210 | { |
Pekka Paalanen | 77346a6 | 2011-11-30 16:26:35 +0200 | [diff] [blame] | 5211 | struct shell_surface *shsurf; |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 5212 | struct weston_view *view; |
Kristian Høgsberg | 32e24cc | 2011-11-09 12:07:35 -0500 | [diff] [blame] | 5213 | |
Pekka Paalanen | 77346a6 | 2011-11-30 16:26:35 +0200 | [diff] [blame] | 5214 | shsurf = get_shell_surface(surface); |
Pekka Paalanen | 77346a6 | 2011-11-30 16:26:35 +0200 | [diff] [blame] | 5215 | |
U. Artie Eoff | cf5737a | 2014-01-17 10:08:25 -0800 | [diff] [blame] | 5216 | assert(shsurf); |
| 5217 | |
Rafael Antognolli | 03b1659 | 2013-12-03 15:35:42 -0200 | [diff] [blame] | 5218 | if (shsurf->state.fullscreen) |
Alex Wu | 4539b08 | 2012-03-01 12:57:46 +0800 | [diff] [blame] | 5219 | shell_configure_fullscreen(shsurf); |
Rafael Antognolli | 03b1659 | 2013-12-03 15:35:42 -0200 | [diff] [blame] | 5220 | else if (shsurf->state.maximized) { |
Jonny Lamb | d73c694 | 2014-08-20 15:53:20 +0200 | [diff] [blame] | 5221 | set_maximized_position(shell, shsurf); |
Rafael Antognolli | 03b1659 | 2013-12-03 15:35:42 -0200 | [diff] [blame] | 5222 | } else { |
Jason Ekstrand | 918f2dd | 2013-12-02 21:01:53 -0600 | [diff] [blame] | 5223 | weston_view_set_position(shsurf->view, x, y); |
Kristian Høgsberg | 7a5c979 | 2011-06-18 06:12:54 -0400 | [diff] [blame] | 5224 | } |
Kristian Høgsberg | 32e24cc | 2011-11-09 12:07:35 -0500 | [diff] [blame] | 5225 | |
Alex Wu | 4539b08 | 2012-03-01 12:57:46 +0800 | [diff] [blame] | 5226 | /* XXX: would a fullscreen surface need the same handling? */ |
Kristian Høgsberg | 6a8b553 | 2012-02-16 23:43:59 -0500 | [diff] [blame] | 5227 | if (surface->output) { |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 5228 | wl_list_for_each(view, &surface->views, surface_link) |
| 5229 | weston_view_update_transform(view); |
Pekka Paalanen | 77346a6 | 2011-11-30 16:26:35 +0200 | [diff] [blame] | 5230 | |
Rafael Antognolli | 03b1659 | 2013-12-03 15:35:42 -0200 | [diff] [blame] | 5231 | if (shsurf->state.maximized) |
Juan Zhao | 96879df | 2012-02-07 08:45:41 +0800 | [diff] [blame] | 5232 | surface->output = shsurf->output; |
Pekka Paalanen | 77346a6 | 2011-11-30 16:26:35 +0200 | [diff] [blame] | 5233 | } |
Kristian Høgsberg | 0793756 | 2011-04-12 17:25:42 -0400 | [diff] [blame] | 5234 | } |
| 5235 | |
Ander Conselvan de Oliveira | 093bfa3 | 2012-03-27 17:36:41 +0300 | [diff] [blame] | 5236 | static void |
Jason Ekstrand | 918f2dd | 2013-12-02 21:01:53 -0600 | [diff] [blame] | 5237 | 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] | 5238 | { |
Ander Conselvan de Oliveira | 7fb9f95 | 2012-03-27 17:36:42 +0300 | [diff] [blame] | 5239 | struct shell_surface *shsurf = get_shell_surface(es); |
U. Artie Eoff | cf5737a | 2014-01-17 10:08:25 -0800 | [diff] [blame] | 5240 | struct desktop_shell *shell; |
Tiago Vignatti | 70e5c9c | 2012-05-07 15:23:07 +0300 | [diff] [blame] | 5241 | int type_changed = 0; |
Ander Conselvan de Oliveira | 093bfa3 | 2012-03-27 17:36:41 +0300 | [diff] [blame] | 5242 | |
U. Artie Eoff | cf5737a | 2014-01-17 10:08:25 -0800 | [diff] [blame] | 5243 | assert(shsurf); |
| 5244 | |
| 5245 | shell = shsurf->shell; |
| 5246 | |
Kristian Høgsberg | 8eb0f4f | 2013-06-17 10:33:14 -0400 | [diff] [blame] | 5247 | if (!weston_surface_is_mapped(es) && |
| 5248 | !wl_list_empty(&shsurf->popup.grab_link)) { |
Giulio Camuffo | 5085a75 | 2013-03-25 21:42:45 +0100 | [diff] [blame] | 5249 | remove_popup_grab(shsurf); |
| 5250 | } |
| 5251 | |
Jason Ekstrand | 918f2dd | 2013-12-02 21:01:53 -0600 | [diff] [blame] | 5252 | if (es->width == 0) |
Giulio Camuffo | 184df50 | 2013-02-21 11:29:21 +0100 | [diff] [blame] | 5253 | return; |
| 5254 | |
Jasper St. Pierre | ccf48fb | 2014-05-02 10:21:38 -0400 | [diff] [blame] | 5255 | if (shsurf->has_next_geometry) { |
| 5256 | shsurf->geometry = shsurf->next_geometry; |
| 5257 | shsurf->has_next_geometry = false; |
| 5258 | shsurf->has_set_geometry = true; |
| 5259 | } else if (!shsurf->has_set_geometry) { |
| 5260 | surface_subsurfaces_boundingbox(shsurf->surface, |
| 5261 | &shsurf->geometry.x, |
| 5262 | &shsurf->geometry.y, |
| 5263 | &shsurf->geometry.width, |
| 5264 | &shsurf->geometry.height); |
Jasper St. Pierre | 851799e | 2014-05-02 10:14:07 -0400 | [diff] [blame] | 5265 | } |
| 5266 | |
Kristian Høgsberg | c8f8dd8 | 2013-12-05 23:20:33 -0800 | [diff] [blame] | 5267 | if (shsurf->state_changed) { |
Kristian Høgsberg | 7f366e7 | 2012-04-27 17:20:01 -0400 | [diff] [blame] | 5268 | set_surface_type(shsurf); |
Kristian Høgsberg | f7e23d5 | 2012-04-27 17:51:59 -0400 | [diff] [blame] | 5269 | type_changed = 1; |
| 5270 | } |
Kristian Høgsberg | 7f366e7 | 2012-04-27 17:20:01 -0400 | [diff] [blame] | 5271 | |
Ander Conselvan de Oliveira | 093bfa3 | 2012-03-27 17:36:41 +0300 | [diff] [blame] | 5272 | if (!weston_surface_is_mapped(es)) { |
Jason Ekstrand | 918f2dd | 2013-12-02 21:01:53 -0600 | [diff] [blame] | 5273 | map(shell, shsurf, sx, sy); |
Kristian Høgsberg | f7e23d5 | 2012-04-27 17:51:59 -0400 | [diff] [blame] | 5274 | } else if (type_changed || sx != 0 || sy != 0 || |
Jason Ekstrand | 918f2dd | 2013-12-02 21:01:53 -0600 | [diff] [blame] | 5275 | shsurf->last_width != es->width || |
| 5276 | shsurf->last_height != es->height) { |
John Kåre Alsaker | 490d02a | 2012-09-30 02:57:21 +0200 | [diff] [blame] | 5277 | float from_x, from_y; |
| 5278 | float to_x, to_y; |
Ander Conselvan de Oliveira | 093bfa3 | 2012-03-27 17:36:41 +0300 | [diff] [blame] | 5279 | |
Kristian Høgsberg | 44cd196 | 2014-02-05 21:36:04 -0800 | [diff] [blame] | 5280 | if (shsurf->resize_edges) { |
| 5281 | sx = 0; |
| 5282 | sy = 0; |
| 5283 | } |
| 5284 | |
| 5285 | if (shsurf->resize_edges & WL_SHELL_SURFACE_RESIZE_LEFT) |
| 5286 | sx = shsurf->last_width - es->width; |
| 5287 | if (shsurf->resize_edges & WL_SHELL_SURFACE_RESIZE_TOP) |
| 5288 | sy = shsurf->last_height - es->height; |
| 5289 | |
| 5290 | shsurf->last_width = es->width; |
| 5291 | shsurf->last_height = es->height; |
| 5292 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 5293 | weston_view_to_global_float(shsurf->view, 0, 0, &from_x, &from_y); |
| 5294 | 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] | 5295 | configure(shell, es, |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 5296 | shsurf->view->geometry.x + to_x - from_x, |
Jason Ekstrand | 918f2dd | 2013-12-02 21:01:53 -0600 | [diff] [blame] | 5297 | shsurf->view->geometry.y + to_y - from_y); |
Ander Conselvan de Oliveira | 093bfa3 | 2012-03-27 17:36:41 +0300 | [diff] [blame] | 5298 | } |
| 5299 | } |
| 5300 | |
Tiago Vignatti | b7dbbd6 | 2012-09-25 17:57:01 +0300 | [diff] [blame] | 5301 | static void launch_desktop_shell_process(void *data); |
Pekka Paalanen | 4d733ee | 2012-01-17 14:36:27 +0200 | [diff] [blame] | 5302 | |
Kristian Høgsberg | 97d44aa | 2011-08-26 17:21:20 -0400 | [diff] [blame] | 5303 | static void |
Kristian Høgsberg | 8334bc1 | 2012-01-03 10:29:47 -0500 | [diff] [blame] | 5304 | desktop_shell_sigchld(struct weston_process *process, int status) |
Pekka Paalanen | 6cd281a | 2011-11-03 14:11:32 +0200 | [diff] [blame] | 5305 | { |
Pekka Paalanen | 4d733ee | 2012-01-17 14:36:27 +0200 | [diff] [blame] | 5306 | uint32_t time; |
Tiago Vignatti | be14326 | 2012-04-16 17:31:41 +0300 | [diff] [blame] | 5307 | struct desktop_shell *shell = |
| 5308 | container_of(process, struct desktop_shell, child.process); |
Pekka Paalanen | 6cd281a | 2011-11-03 14:11:32 +0200 | [diff] [blame] | 5309 | |
| 5310 | shell->child.process.pid = 0; |
| 5311 | shell->child.client = NULL; /* already destroyed by wayland */ |
Pekka Paalanen | 4d733ee | 2012-01-17 14:36:27 +0200 | [diff] [blame] | 5312 | |
| 5313 | /* if desktop-shell dies more than 5 times in 30 seconds, give up */ |
| 5314 | time = weston_compositor_get_time(); |
Kristian Høgsberg | f03a616 | 2012-01-17 11:07:42 -0500 | [diff] [blame] | 5315 | if (time - shell->child.deathstamp > 30000) { |
Pekka Paalanen | 4d733ee | 2012-01-17 14:36:27 +0200 | [diff] [blame] | 5316 | shell->child.deathstamp = time; |
| 5317 | shell->child.deathcount = 0; |
| 5318 | } |
| 5319 | |
| 5320 | shell->child.deathcount++; |
| 5321 | if (shell->child.deathcount > 5) { |
Emilio Pozuelo Monfort | 46ce798 | 2013-11-20 13:22:29 +0100 | [diff] [blame] | 5322 | weston_log("%s died, giving up.\n", shell->client); |
Pekka Paalanen | 4d733ee | 2012-01-17 14:36:27 +0200 | [diff] [blame] | 5323 | return; |
| 5324 | } |
| 5325 | |
Emilio Pozuelo Monfort | 46ce798 | 2013-11-20 13:22:29 +0100 | [diff] [blame] | 5326 | weston_log("%s died, respawning...\n", shell->client); |
Pekka Paalanen | 4d733ee | 2012-01-17 14:36:27 +0200 | [diff] [blame] | 5327 | launch_desktop_shell_process(shell); |
Pekka Paalanen | 79346ab | 2013-05-22 18:03:09 +0300 | [diff] [blame] | 5328 | shell_fade_startup(shell); |
Pekka Paalanen | 6cd281a | 2011-11-03 14:11:32 +0200 | [diff] [blame] | 5329 | } |
| 5330 | |
Tiago Vignatti | b7dbbd6 | 2012-09-25 17:57:01 +0300 | [diff] [blame] | 5331 | static void |
Ander Conselvan de Oliveira | 312ea4c | 2013-12-20 21:07:01 +0200 | [diff] [blame] | 5332 | desktop_shell_client_destroy(struct wl_listener *listener, void *data) |
| 5333 | { |
| 5334 | struct desktop_shell *shell; |
| 5335 | |
| 5336 | shell = container_of(listener, struct desktop_shell, |
| 5337 | child.client_destroy_listener); |
| 5338 | |
| 5339 | shell->child.client = NULL; |
| 5340 | } |
| 5341 | |
| 5342 | static void |
Tiago Vignatti | b7dbbd6 | 2012-09-25 17:57:01 +0300 | [diff] [blame] | 5343 | launch_desktop_shell_process(void *data) |
Pekka Paalanen | 6cd281a | 2011-11-03 14:11:32 +0200 | [diff] [blame] | 5344 | { |
Tiago Vignatti | b7dbbd6 | 2012-09-25 17:57:01 +0300 | [diff] [blame] | 5345 | struct desktop_shell *shell = data; |
Pekka Paalanen | 6cd281a | 2011-11-03 14:11:32 +0200 | [diff] [blame] | 5346 | |
Kristian Høgsberg | 8334bc1 | 2012-01-03 10:29:47 -0500 | [diff] [blame] | 5347 | shell->child.client = weston_client_launch(shell->compositor, |
Pekka Paalanen | 409ef0a | 2011-12-02 15:30:21 +0200 | [diff] [blame] | 5348 | &shell->child.process, |
Emilio Pozuelo Monfort | 46ce798 | 2013-11-20 13:22:29 +0100 | [diff] [blame] | 5349 | shell->client, |
Pekka Paalanen | 409ef0a | 2011-12-02 15:30:21 +0200 | [diff] [blame] | 5350 | desktop_shell_sigchld); |
| 5351 | |
Arnaud Vrac | 4263119 | 2014-08-25 20:56:46 +0200 | [diff] [blame^] | 5352 | if (!shell->child.client) { |
Emilio Pozuelo Monfort | 46ce798 | 2013-11-20 13:22:29 +0100 | [diff] [blame] | 5353 | weston_log("not able to start %s\n", shell->client); |
Arnaud Vrac | 4263119 | 2014-08-25 20:56:46 +0200 | [diff] [blame^] | 5354 | return; |
| 5355 | } |
Ander Conselvan de Oliveira | 312ea4c | 2013-12-20 21:07:01 +0200 | [diff] [blame] | 5356 | |
| 5357 | shell->child.client_destroy_listener.notify = |
| 5358 | desktop_shell_client_destroy; |
| 5359 | wl_client_add_destroy_listener(shell->child.client, |
| 5360 | &shell->child.client_destroy_listener); |
Pekka Paalanen | 6cd281a | 2011-11-03 14:11:32 +0200 | [diff] [blame] | 5361 | } |
| 5362 | |
| 5363 | static void |
Kristian Høgsberg | 2bff94e | 2014-02-11 12:22:51 -0800 | [diff] [blame] | 5364 | handle_shell_client_destroy(struct wl_listener *listener, void *data) |
| 5365 | { |
| 5366 | struct shell_client *sc = |
| 5367 | container_of(listener, struct shell_client, destroy_listener); |
| 5368 | |
| 5369 | if (sc->ping_timer) |
| 5370 | wl_event_source_remove(sc->ping_timer); |
| 5371 | free(sc); |
| 5372 | } |
| 5373 | |
Kristian Høgsberg | dd62aba | 2014-02-12 09:56:19 -0800 | [diff] [blame] | 5374 | static struct shell_client * |
| 5375 | shell_client_create(struct wl_client *client, struct desktop_shell *shell, |
| 5376 | const struct wl_interface *interface, uint32_t id) |
Rafael Antognolli | e2a3455 | 2013-12-03 15:35:45 -0200 | [diff] [blame] | 5377 | { |
Kristian Høgsberg | 2bff94e | 2014-02-11 12:22:51 -0800 | [diff] [blame] | 5378 | struct shell_client *sc; |
Rafael Antognolli | e2a3455 | 2013-12-03 15:35:45 -0200 | [diff] [blame] | 5379 | |
Kristian Høgsberg | 2bff94e | 2014-02-11 12:22:51 -0800 | [diff] [blame] | 5380 | sc = zalloc(sizeof *sc); |
| 5381 | if (sc == NULL) { |
| 5382 | wl_client_post_no_memory(client); |
Kristian Høgsberg | dd62aba | 2014-02-12 09:56:19 -0800 | [diff] [blame] | 5383 | return NULL; |
Kristian Høgsberg | 2bff94e | 2014-02-11 12:22:51 -0800 | [diff] [blame] | 5384 | } |
Kristian Høgsberg | dd62aba | 2014-02-12 09:56:19 -0800 | [diff] [blame] | 5385 | |
| 5386 | sc->resource = wl_resource_create(client, interface, 1, id); |
Kristian Høgsberg | 2bff94e | 2014-02-11 12:22:51 -0800 | [diff] [blame] | 5387 | if (sc->resource == NULL) { |
| 5388 | free(sc); |
| 5389 | wl_client_post_no_memory(client); |
Kristian Høgsberg | dd62aba | 2014-02-12 09:56:19 -0800 | [diff] [blame] | 5390 | return NULL; |
Kristian Høgsberg | 2bff94e | 2014-02-11 12:22:51 -0800 | [diff] [blame] | 5391 | } |
| 5392 | |
| 5393 | sc->client = client; |
| 5394 | sc->shell = shell; |
| 5395 | sc->destroy_listener.notify = handle_shell_client_destroy; |
| 5396 | wl_client_add_destroy_listener(client, &sc->destroy_listener); |
| 5397 | |
Kristian Høgsberg | dd62aba | 2014-02-12 09:56:19 -0800 | [diff] [blame] | 5398 | return sc; |
| 5399 | } |
| 5400 | |
| 5401 | static void |
| 5402 | bind_shell(struct wl_client *client, void *data, uint32_t version, uint32_t id) |
| 5403 | { |
| 5404 | struct desktop_shell *shell = data; |
| 5405 | struct shell_client *sc; |
| 5406 | |
| 5407 | sc = shell_client_create(client, shell, &wl_shell_interface, id); |
| 5408 | if (sc) |
| 5409 | wl_resource_set_implementation(sc->resource, |
| 5410 | &shell_implementation, |
Jason Ekstrand | 9e9512f | 2014-04-16 21:12:10 -0500 | [diff] [blame] | 5411 | sc, NULL); |
Kristian Høgsberg | dd62aba | 2014-02-12 09:56:19 -0800 | [diff] [blame] | 5412 | } |
| 5413 | |
| 5414 | static void |
| 5415 | bind_xdg_shell(struct wl_client *client, void *data, uint32_t version, uint32_t id) |
| 5416 | { |
| 5417 | struct desktop_shell *shell = data; |
| 5418 | struct shell_client *sc; |
| 5419 | |
| 5420 | sc = shell_client_create(client, shell, &xdg_shell_interface, id); |
| 5421 | if (sc) |
| 5422 | wl_resource_set_dispatcher(sc->resource, |
| 5423 | xdg_shell_unversioned_dispatch, |
| 5424 | NULL, sc, NULL); |
Rafael Antognolli | e2a3455 | 2013-12-03 15:35:45 -0200 | [diff] [blame] | 5425 | } |
| 5426 | |
| 5427 | static void |
Pekka Paalanen | 9ef3e01 | 2011-11-15 13:34:48 +0200 | [diff] [blame] | 5428 | unbind_desktop_shell(struct wl_resource *resource) |
| 5429 | { |
Jason Ekstrand | 651f00e | 2013-06-14 10:07:54 -0500 | [diff] [blame] | 5430 | struct desktop_shell *shell = wl_resource_get_user_data(resource); |
Kristian Høgsberg | 1ec0c31 | 2011-11-15 16:39:55 -0500 | [diff] [blame] | 5431 | |
| 5432 | if (shell->locked) |
| 5433 | resume_desktop(shell); |
| 5434 | |
Pekka Paalanen | 9ef3e01 | 2011-11-15 13:34:48 +0200 | [diff] [blame] | 5435 | shell->child.desktop_shell = NULL; |
| 5436 | shell->prepare_event_sent = false; |
Pekka Paalanen | 9ef3e01 | 2011-11-15 13:34:48 +0200 | [diff] [blame] | 5437 | } |
| 5438 | |
| 5439 | static void |
Kristian Høgsberg | 7584062 | 2011-09-06 13:48:16 -0400 | [diff] [blame] | 5440 | bind_desktop_shell(struct wl_client *client, |
| 5441 | void *data, uint32_t version, uint32_t id) |
| 5442 | { |
Tiago Vignatti | be14326 | 2012-04-16 17:31:41 +0300 | [diff] [blame] | 5443 | struct desktop_shell *shell = data; |
Pekka Paalanen | bbe6052 | 2011-11-03 14:11:33 +0200 | [diff] [blame] | 5444 | struct wl_resource *resource; |
Kristian Høgsberg | 7584062 | 2011-09-06 13:48:16 -0400 | [diff] [blame] | 5445 | |
Jason Ekstrand | a85118c | 2013-06-27 20:17:02 -0500 | [diff] [blame] | 5446 | resource = wl_resource_create(client, &desktop_shell_interface, |
Jonny Lamb | 765760d | 2014-08-20 15:53:19 +0200 | [diff] [blame] | 5447 | MIN(version, 3), id); |
Pekka Paalanen | bbe6052 | 2011-11-03 14:11:33 +0200 | [diff] [blame] | 5448 | |
Pekka Paalanen | 9ef3e01 | 2011-11-15 13:34:48 +0200 | [diff] [blame] | 5449 | if (client == shell->child.client) { |
Jason Ekstrand | a85118c | 2013-06-27 20:17:02 -0500 | [diff] [blame] | 5450 | wl_resource_set_implementation(resource, |
| 5451 | &desktop_shell_implementation, |
| 5452 | shell, unbind_desktop_shell); |
Pekka Paalanen | 9ef3e01 | 2011-11-15 13:34:48 +0200 | [diff] [blame] | 5453 | shell->child.desktop_shell = resource; |
Pekka Paalanen | 79346ab | 2013-05-22 18:03:09 +0300 | [diff] [blame] | 5454 | |
| 5455 | if (version < 2) |
| 5456 | shell_fade_startup(shell); |
| 5457 | |
Pekka Paalanen | bbe6052 | 2011-11-03 14:11:33 +0200 | [diff] [blame] | 5458 | return; |
Pekka Paalanen | 9ef3e01 | 2011-11-15 13:34:48 +0200 | [diff] [blame] | 5459 | } |
Pekka Paalanen | bbe6052 | 2011-11-03 14:11:33 +0200 | [diff] [blame] | 5460 | |
| 5461 | wl_resource_post_error(resource, WL_DISPLAY_ERROR_INVALID_OBJECT, |
| 5462 | "permission to bind desktop_shell denied"); |
Kristian Høgsberg | 7584062 | 2011-09-06 13:48:16 -0400 | [diff] [blame] | 5463 | } |
| 5464 | |
Pekka Paalanen | 6e16811 | 2011-11-24 11:34:05 +0200 | [diff] [blame] | 5465 | static void |
Jason Ekstrand | 918f2dd | 2013-12-02 21:01:53 -0600 | [diff] [blame] | 5466 | 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] | 5467 | { |
Giulio Camuffo | 7fe01b1 | 2013-03-28 18:02:42 +0100 | [diff] [blame] | 5468 | struct desktop_shell *shell = surface->configure_private; |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 5469 | struct weston_view *view; |
Giulio Camuffo | 412e6a5 | 2014-07-09 22:12:56 +0300 | [diff] [blame] | 5470 | struct weston_layer_entry *prev; |
Kristian Høgsberg | 1a73a63 | 2012-06-26 22:15:53 -0400 | [diff] [blame] | 5471 | |
Jason Ekstrand | 918f2dd | 2013-12-02 21:01:53 -0600 | [diff] [blame] | 5472 | if (surface->width == 0) |
Giulio Camuffo | 184df50 | 2013-02-21 11:29:21 +0100 | [diff] [blame] | 5473 | return; |
| 5474 | |
Pekka Paalanen | 3a1d07d | 2012-12-20 14:02:13 +0200 | [diff] [blame] | 5475 | /* XXX: starting weston-screensaver beforehand does not work */ |
Kristian Høgsberg | 1a73a63 | 2012-06-26 22:15:53 -0400 | [diff] [blame] | 5476 | if (!shell->locked) |
| 5477 | return; |
| 5478 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 5479 | view = container_of(surface->views.next, struct weston_view, surface_link); |
| 5480 | center_on_output(view, surface->output); |
Kristian Høgsberg | 1a73a63 | 2012-06-26 22:15:53 -0400 | [diff] [blame] | 5481 | |
Giulio Camuffo | 412e6a5 | 2014-07-09 22:12:56 +0300 | [diff] [blame] | 5482 | if (wl_list_empty(&view->layer_link.link)) { |
| 5483 | prev = container_of(shell->lock_layer.view_list.link.prev, |
| 5484 | struct weston_layer_entry, link); |
| 5485 | weston_layer_entry_insert(prev, &view->layer_link); |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 5486 | weston_view_update_transform(view); |
Ander Conselvan de Oliveira | 859e885 | 2013-02-21 18:35:21 +0200 | [diff] [blame] | 5487 | wl_event_source_timer_update(shell->screensaver.timer, |
| 5488 | shell->screensaver.duration); |
Ander Conselvan de Oliveira | 19d10ef | 2013-02-21 18:35:20 +0200 | [diff] [blame] | 5489 | shell_fade(shell, FADE_IN); |
Kristian Høgsberg | 1a73a63 | 2012-06-26 22:15:53 -0400 | [diff] [blame] | 5490 | } |
| 5491 | } |
| 5492 | |
| 5493 | static void |
Pekka Paalanen | 6e16811 | 2011-11-24 11:34:05 +0200 | [diff] [blame] | 5494 | screensaver_set_surface(struct wl_client *client, |
| 5495 | struct wl_resource *resource, |
Kristian Høgsberg | 1a73a63 | 2012-06-26 22:15:53 -0400 | [diff] [blame] | 5496 | struct wl_resource *surface_resource, |
Pekka Paalanen | 6e16811 | 2011-11-24 11:34:05 +0200 | [diff] [blame] | 5497 | struct wl_resource *output_resource) |
| 5498 | { |
Jason Ekstrand | 651f00e | 2013-06-14 10:07:54 -0500 | [diff] [blame] | 5499 | struct desktop_shell *shell = wl_resource_get_user_data(resource); |
Jason Ekstrand | 0f2ef7e | 2013-06-14 10:07:53 -0500 | [diff] [blame] | 5500 | struct weston_surface *surface = |
| 5501 | wl_resource_get_user_data(surface_resource); |
Jason Ekstrand | a0d2dde | 2013-06-14 10:08:01 -0500 | [diff] [blame] | 5502 | struct weston_output *output = wl_resource_get_user_data(output_resource); |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 5503 | struct weston_view *view, *next; |
| 5504 | |
| 5505 | /* Make sure we only have one view */ |
| 5506 | wl_list_for_each_safe(view, next, &surface->views, surface_link) |
| 5507 | weston_view_destroy(view); |
| 5508 | weston_view_create(surface); |
Pekka Paalanen | 6e16811 | 2011-11-24 11:34:05 +0200 | [diff] [blame] | 5509 | |
Kristian Høgsberg | 1a73a63 | 2012-06-26 22:15:53 -0400 | [diff] [blame] | 5510 | surface->configure = screensaver_configure; |
Giulio Camuffo | 7fe01b1 | 2013-03-28 18:02:42 +0100 | [diff] [blame] | 5511 | surface->configure_private = shell; |
Pekka Paalanen | 77346a6 | 2011-11-30 16:26:35 +0200 | [diff] [blame] | 5512 | surface->output = output; |
Pekka Paalanen | 6e16811 | 2011-11-24 11:34:05 +0200 | [diff] [blame] | 5513 | } |
| 5514 | |
| 5515 | static const struct screensaver_interface screensaver_implementation = { |
| 5516 | screensaver_set_surface |
| 5517 | }; |
| 5518 | |
| 5519 | static void |
| 5520 | unbind_screensaver(struct wl_resource *resource) |
| 5521 | { |
Jason Ekstrand | 651f00e | 2013-06-14 10:07:54 -0500 | [diff] [blame] | 5522 | struct desktop_shell *shell = wl_resource_get_user_data(resource); |
Pekka Paalanen | 6e16811 | 2011-11-24 11:34:05 +0200 | [diff] [blame] | 5523 | |
Pekka Paalanen | 77346a6 | 2011-11-30 16:26:35 +0200 | [diff] [blame] | 5524 | shell->screensaver.binding = NULL; |
Pekka Paalanen | 6e16811 | 2011-11-24 11:34:05 +0200 | [diff] [blame] | 5525 | } |
| 5526 | |
| 5527 | static void |
| 5528 | bind_screensaver(struct wl_client *client, |
| 5529 | void *data, uint32_t version, uint32_t id) |
| 5530 | { |
Tiago Vignatti | be14326 | 2012-04-16 17:31:41 +0300 | [diff] [blame] | 5531 | struct desktop_shell *shell = data; |
Pekka Paalanen | 6e16811 | 2011-11-24 11:34:05 +0200 | [diff] [blame] | 5532 | struct wl_resource *resource; |
| 5533 | |
Jason Ekstrand | a85118c | 2013-06-27 20:17:02 -0500 | [diff] [blame] | 5534 | resource = wl_resource_create(client, &screensaver_interface, 1, id); |
Pekka Paalanen | 6e16811 | 2011-11-24 11:34:05 +0200 | [diff] [blame] | 5535 | |
Pekka Paalanen | 77346a6 | 2011-11-30 16:26:35 +0200 | [diff] [blame] | 5536 | if (shell->screensaver.binding == NULL) { |
Jason Ekstrand | a85118c | 2013-06-27 20:17:02 -0500 | [diff] [blame] | 5537 | wl_resource_set_implementation(resource, |
| 5538 | &screensaver_implementation, |
| 5539 | shell, unbind_screensaver); |
Pekka Paalanen | 77346a6 | 2011-11-30 16:26:35 +0200 | [diff] [blame] | 5540 | shell->screensaver.binding = resource; |
Pekka Paalanen | 6e16811 | 2011-11-24 11:34:05 +0200 | [diff] [blame] | 5541 | return; |
| 5542 | } |
| 5543 | |
| 5544 | wl_resource_post_error(resource, WL_DISPLAY_ERROR_INVALID_OBJECT, |
| 5545 | "interface object already bound"); |
Pekka Paalanen | 6e16811 | 2011-11-24 11:34:05 +0200 | [diff] [blame] | 5546 | } |
| 5547 | |
Kristian Høgsberg | 0704539 | 2012-02-19 18:52:44 -0500 | [diff] [blame] | 5548 | struct switcher { |
Tiago Vignatti | be14326 | 2012-04-16 17:31:41 +0300 | [diff] [blame] | 5549 | struct desktop_shell *shell; |
Kristian Høgsberg | 0704539 | 2012-02-19 18:52:44 -0500 | [diff] [blame] | 5550 | struct weston_surface *current; |
| 5551 | struct wl_listener listener; |
Kristian Høgsberg | 29139d4 | 2013-04-18 15:25:39 -0400 | [diff] [blame] | 5552 | struct weston_keyboard_grab grab; |
Manuel Bachmann | c1ae2e8 | 2014-02-26 15:53:11 +0100 | [diff] [blame] | 5553 | struct wl_array minimized_array; |
Kristian Høgsberg | 0704539 | 2012-02-19 18:52:44 -0500 | [diff] [blame] | 5554 | }; |
| 5555 | |
| 5556 | static void |
| 5557 | switcher_next(struct switcher *switcher) |
| 5558 | { |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 5559 | struct weston_view *view; |
Kristian Høgsberg | 0704539 | 2012-02-19 18:52:44 -0500 | [diff] [blame] | 5560 | struct weston_surface *first = NULL, *prev = NULL, *next = NULL; |
Kristian Høgsberg | 32e5686 | 2012-04-02 22:18:58 -0400 | [diff] [blame] | 5561 | struct shell_surface *shsurf; |
Kristian Høgsberg | b0d8e77 | 2012-06-18 16:34:58 -0400 | [diff] [blame] | 5562 | struct workspace *ws = get_current_workspace(switcher->shell); |
Kristian Høgsberg | 0704539 | 2012-02-19 18:52:44 -0500 | [diff] [blame] | 5563 | |
Manuel Bachmann | c1ae2e8 | 2014-02-26 15:53:11 +0100 | [diff] [blame] | 5564 | /* temporary re-display minimized surfaces */ |
| 5565 | struct weston_view *tmp; |
| 5566 | struct weston_view **minimized; |
Giulio Camuffo | 412e6a5 | 2014-07-09 22:12:56 +0300 | [diff] [blame] | 5567 | wl_list_for_each_safe(view, tmp, &switcher->shell->minimized_layer.view_list.link, layer_link.link) { |
| 5568 | weston_layer_entry_remove(&view->layer_link); |
| 5569 | weston_layer_entry_insert(&ws->layer.view_list, &view->layer_link); |
Manuel Bachmann | c1ae2e8 | 2014-02-26 15:53:11 +0100 | [diff] [blame] | 5570 | minimized = wl_array_add(&switcher->minimized_array, sizeof *minimized); |
| 5571 | *minimized = view; |
| 5572 | } |
| 5573 | |
Giulio Camuffo | 412e6a5 | 2014-07-09 22:12:56 +0300 | [diff] [blame] | 5574 | 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] | 5575 | shsurf = get_shell_surface(view->surface); |
Rafael Antognolli | 5031cbe | 2013-12-05 19:01:21 -0200 | [diff] [blame] | 5576 | if (shsurf && |
| 5577 | shsurf->type == SHELL_SURFACE_TOPLEVEL && |
| 5578 | shsurf->parent == NULL) { |
Kristian Høgsberg | 0704539 | 2012-02-19 18:52:44 -0500 | [diff] [blame] | 5579 | if (first == NULL) |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 5580 | first = view->surface; |
Kristian Høgsberg | 0704539 | 2012-02-19 18:52:44 -0500 | [diff] [blame] | 5581 | if (prev == switcher->current) |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 5582 | next = view->surface; |
| 5583 | prev = view->surface; |
| 5584 | view->alpha = 0.25; |
| 5585 | weston_view_geometry_dirty(view); |
| 5586 | weston_surface_damage(view->surface); |
Kristian Høgsberg | 0704539 | 2012-02-19 18:52:44 -0500 | [diff] [blame] | 5587 | } |
Alex Wu | 1659daa | 2012-04-01 20:13:09 +0800 | [diff] [blame] | 5588 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 5589 | if (is_black_surface(view->surface, NULL)) { |
| 5590 | view->alpha = 0.25; |
| 5591 | weston_view_geometry_dirty(view); |
| 5592 | weston_surface_damage(view->surface); |
Alex Wu | 1659daa | 2012-04-01 20:13:09 +0800 | [diff] [blame] | 5593 | } |
Kristian Høgsberg | 0704539 | 2012-02-19 18:52:44 -0500 | [diff] [blame] | 5594 | } |
| 5595 | |
| 5596 | if (next == NULL) |
| 5597 | next = first; |
| 5598 | |
Alex Wu | 07b2606 | 2012-03-12 16:06:01 +0800 | [diff] [blame] | 5599 | if (next == NULL) |
| 5600 | return; |
| 5601 | |
Kristian Høgsberg | 0704539 | 2012-02-19 18:52:44 -0500 | [diff] [blame] | 5602 | wl_list_remove(&switcher->listener.link); |
Jason Ekstrand | 26ed73c | 2013-06-06 22:34:41 -0500 | [diff] [blame] | 5603 | wl_signal_add(&next->destroy_signal, &switcher->listener); |
Kristian Høgsberg | 0704539 | 2012-02-19 18:52:44 -0500 | [diff] [blame] | 5604 | |
| 5605 | switcher->current = next; |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 5606 | wl_list_for_each(view, &next->views, surface_link) |
| 5607 | view->alpha = 1.0; |
Alex Wu | 1659daa | 2012-04-01 20:13:09 +0800 | [diff] [blame] | 5608 | |
Kristian Høgsberg | 32e5686 | 2012-04-02 22:18:58 -0400 | [diff] [blame] | 5609 | shsurf = get_shell_surface(switcher->current); |
Rafael Antognolli | 03b1659 | 2013-12-03 15:35:42 -0200 | [diff] [blame] | 5610 | if (shsurf && shsurf->state.fullscreen) |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 5611 | shsurf->fullscreen.black_view->alpha = 1.0; |
Kristian Høgsberg | 0704539 | 2012-02-19 18:52:44 -0500 | [diff] [blame] | 5612 | } |
| 5613 | |
| 5614 | static void |
Kristian Høgsberg | 27e3052 | 2012-04-11 23:18:23 -0400 | [diff] [blame] | 5615 | switcher_handle_surface_destroy(struct wl_listener *listener, void *data) |
Kristian Høgsberg | 0704539 | 2012-02-19 18:52:44 -0500 | [diff] [blame] | 5616 | { |
| 5617 | struct switcher *switcher = |
| 5618 | container_of(listener, struct switcher, listener); |
| 5619 | |
| 5620 | switcher_next(switcher); |
| 5621 | } |
| 5622 | |
| 5623 | static void |
Daniel Stone | 351eb61 | 2012-05-31 15:27:47 -0400 | [diff] [blame] | 5624 | switcher_destroy(struct switcher *switcher) |
Kristian Høgsberg | 0704539 | 2012-02-19 18:52:44 -0500 | [diff] [blame] | 5625 | { |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 5626 | struct weston_view *view; |
Kristian Høgsberg | 29139d4 | 2013-04-18 15:25:39 -0400 | [diff] [blame] | 5627 | struct weston_keyboard *keyboard = switcher->grab.keyboard; |
Kristian Høgsberg | b0d8e77 | 2012-06-18 16:34:58 -0400 | [diff] [blame] | 5628 | struct workspace *ws = get_current_workspace(switcher->shell); |
Kristian Høgsberg | 0704539 | 2012-02-19 18:52:44 -0500 | [diff] [blame] | 5629 | |
Giulio Camuffo | 412e6a5 | 2014-07-09 22:12:56 +0300 | [diff] [blame] | 5630 | 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] | 5631 | if (is_focus_view(view)) |
| 5632 | continue; |
| 5633 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 5634 | view->alpha = 1.0; |
| 5635 | weston_surface_damage(view->surface); |
Kristian Høgsberg | 0704539 | 2012-02-19 18:52:44 -0500 | [diff] [blame] | 5636 | } |
| 5637 | |
Alex Wu | 07b2606 | 2012-03-12 16:06:01 +0800 | [diff] [blame] | 5638 | if (switcher->current) |
Daniel Stone | 37816df | 2012-05-16 18:45:18 +0100 | [diff] [blame] | 5639 | activate(switcher->shell, switcher->current, |
Emilio Pozuelo Monfort | 9e7c759 | 2014-01-30 14:01:10 +0100 | [diff] [blame] | 5640 | (struct weston_seat *) keyboard->seat, true); |
Kristian Høgsberg | 0704539 | 2012-02-19 18:52:44 -0500 | [diff] [blame] | 5641 | wl_list_remove(&switcher->listener.link); |
Kristian Høgsberg | 29139d4 | 2013-04-18 15:25:39 -0400 | [diff] [blame] | 5642 | weston_keyboard_end_grab(keyboard); |
| 5643 | if (keyboard->input_method_resource) |
| 5644 | keyboard->grab = &keyboard->input_method_grab; |
Manuel Bachmann | c1ae2e8 | 2014-02-26 15:53:11 +0100 | [diff] [blame] | 5645 | |
| 5646 | /* re-hide surfaces that were temporary shown during the switch */ |
| 5647 | struct weston_view **minimized; |
| 5648 | wl_array_for_each(minimized, &switcher->minimized_array) { |
| 5649 | /* with the exception of the current selected */ |
| 5650 | if ((*minimized)->surface != switcher->current) { |
Giulio Camuffo | 412e6a5 | 2014-07-09 22:12:56 +0300 | [diff] [blame] | 5651 | weston_layer_entry_remove(&(*minimized)->layer_link); |
| 5652 | 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] | 5653 | weston_view_damage_below(*minimized); |
| 5654 | } |
| 5655 | } |
| 5656 | wl_array_release(&switcher->minimized_array); |
| 5657 | |
Kristian Høgsberg | 0704539 | 2012-02-19 18:52:44 -0500 | [diff] [blame] | 5658 | free(switcher); |
| 5659 | } |
| 5660 | |
| 5661 | static void |
Kristian Høgsberg | 29139d4 | 2013-04-18 15:25:39 -0400 | [diff] [blame] | 5662 | switcher_key(struct weston_keyboard_grab *grab, |
Daniel Stone | c9785ea | 2012-05-30 16:31:52 +0100 | [diff] [blame] | 5663 | uint32_t time, uint32_t key, uint32_t state_w) |
Kristian Høgsberg | 0704539 | 2012-02-19 18:52:44 -0500 | [diff] [blame] | 5664 | { |
| 5665 | struct switcher *switcher = container_of(grab, struct switcher, grab); |
Daniel Stone | c9785ea | 2012-05-30 16:31:52 +0100 | [diff] [blame] | 5666 | enum wl_keyboard_key_state state = state_w; |
Daniel Stone | 351eb61 | 2012-05-31 15:27:47 -0400 | [diff] [blame] | 5667 | |
Daniel Stone | c9785ea | 2012-05-30 16:31:52 +0100 | [diff] [blame] | 5668 | if (key == KEY_TAB && state == WL_KEYBOARD_KEY_STATE_PRESSED) |
Daniel Stone | 351eb61 | 2012-05-31 15:27:47 -0400 | [diff] [blame] | 5669 | switcher_next(switcher); |
| 5670 | } |
| 5671 | |
| 5672 | static void |
Kristian Høgsberg | 29139d4 | 2013-04-18 15:25:39 -0400 | [diff] [blame] | 5673 | switcher_modifier(struct weston_keyboard_grab *grab, uint32_t serial, |
Daniel Stone | 351eb61 | 2012-05-31 15:27:47 -0400 | [diff] [blame] | 5674 | uint32_t mods_depressed, uint32_t mods_latched, |
| 5675 | uint32_t mods_locked, uint32_t group) |
| 5676 | { |
| 5677 | struct switcher *switcher = container_of(grab, struct switcher, grab); |
Daniel Stone | 37816df | 2012-05-16 18:45:18 +0100 | [diff] [blame] | 5678 | struct weston_seat *seat = (struct weston_seat *) grab->keyboard->seat; |
Kristian Høgsberg | 0704539 | 2012-02-19 18:52:44 -0500 | [diff] [blame] | 5679 | |
Daniel Stone | 351eb61 | 2012-05-31 15:27:47 -0400 | [diff] [blame] | 5680 | if ((seat->modifier_state & switcher->shell->binding_modifier) == 0) |
| 5681 | switcher_destroy(switcher); |
Kristian Høgsberg | b71302e | 2012-05-10 12:28:35 -0400 | [diff] [blame] | 5682 | } |
Kristian Høgsberg | 0704539 | 2012-02-19 18:52:44 -0500 | [diff] [blame] | 5683 | |
Jonas Ådahl | 1ea343e | 2013-10-25 23:18:05 +0200 | [diff] [blame] | 5684 | static void |
| 5685 | switcher_cancel(struct weston_keyboard_grab *grab) |
| 5686 | { |
| 5687 | struct switcher *switcher = container_of(grab, struct switcher, grab); |
| 5688 | |
| 5689 | switcher_destroy(switcher); |
| 5690 | } |
| 5691 | |
Kristian Høgsberg | 29139d4 | 2013-04-18 15:25:39 -0400 | [diff] [blame] | 5692 | static const struct weston_keyboard_grab_interface switcher_grab = { |
Daniel Stone | 351eb61 | 2012-05-31 15:27:47 -0400 | [diff] [blame] | 5693 | switcher_key, |
| 5694 | switcher_modifier, |
Jonas Ådahl | 1ea343e | 2013-10-25 23:18:05 +0200 | [diff] [blame] | 5695 | switcher_cancel, |
Kristian Høgsberg | 0704539 | 2012-02-19 18:52:44 -0500 | [diff] [blame] | 5696 | }; |
| 5697 | |
| 5698 | static void |
Kristian Høgsberg | e314875 | 2013-05-06 23:19:49 -0400 | [diff] [blame] | 5699 | switcher_binding(struct weston_seat *seat, uint32_t time, uint32_t key, |
Daniel Stone | 325fc2d | 2012-05-30 16:31:58 +0100 | [diff] [blame] | 5700 | void *data) |
Kristian Høgsberg | 0704539 | 2012-02-19 18:52:44 -0500 | [diff] [blame] | 5701 | { |
Tiago Vignatti | be14326 | 2012-04-16 17:31:41 +0300 | [diff] [blame] | 5702 | struct desktop_shell *shell = data; |
Kristian Høgsberg | 0704539 | 2012-02-19 18:52:44 -0500 | [diff] [blame] | 5703 | struct switcher *switcher; |
| 5704 | |
| 5705 | switcher = malloc(sizeof *switcher); |
Kristian Høgsberg | 02e79dc | 2012-04-12 09:55:26 -0400 | [diff] [blame] | 5706 | switcher->shell = shell; |
Kristian Høgsberg | 0704539 | 2012-02-19 18:52:44 -0500 | [diff] [blame] | 5707 | switcher->current = NULL; |
Kristian Høgsberg | 27e3052 | 2012-04-11 23:18:23 -0400 | [diff] [blame] | 5708 | switcher->listener.notify = switcher_handle_surface_destroy; |
Kristian Høgsberg | 0704539 | 2012-02-19 18:52:44 -0500 | [diff] [blame] | 5709 | wl_list_init(&switcher->listener.link); |
Manuel Bachmann | c1ae2e8 | 2014-02-26 15:53:11 +0100 | [diff] [blame] | 5710 | wl_array_init(&switcher->minimized_array); |
Kristian Høgsberg | 0704539 | 2012-02-19 18:52:44 -0500 | [diff] [blame] | 5711 | |
Alexander Larsson | f82b6ca | 2013-05-28 16:23:39 +0200 | [diff] [blame] | 5712 | restore_all_output_modes(shell->compositor); |
Kristian Høgsberg | b0d8e77 | 2012-06-18 16:34:58 -0400 | [diff] [blame] | 5713 | lower_fullscreen_layer(switcher->shell); |
Kristian Høgsberg | 0704539 | 2012-02-19 18:52:44 -0500 | [diff] [blame] | 5714 | switcher->grab.interface = &switcher_grab; |
Kristian Høgsberg | 29139d4 | 2013-04-18 15:25:39 -0400 | [diff] [blame] | 5715 | weston_keyboard_start_grab(seat->keyboard, &switcher->grab); |
| 5716 | weston_keyboard_set_focus(seat->keyboard, NULL); |
Kristian Høgsberg | 0704539 | 2012-02-19 18:52:44 -0500 | [diff] [blame] | 5717 | switcher_next(switcher); |
| 5718 | } |
| 5719 | |
Pekka Paalanen | 3c64723 | 2011-12-22 13:43:43 +0200 | [diff] [blame] | 5720 | static void |
Kristian Høgsberg | e314875 | 2013-05-06 23:19:49 -0400 | [diff] [blame] | 5721 | backlight_binding(struct weston_seat *seat, uint32_t time, uint32_t key, |
Daniel Stone | 325fc2d | 2012-05-30 16:31:58 +0100 | [diff] [blame] | 5722 | void *data) |
Tiago Vignatti | 8e53c7f | 2012-02-29 19:53:50 +0200 | [diff] [blame] | 5723 | { |
| 5724 | struct weston_compositor *compositor = data; |
| 5725 | struct weston_output *output; |
Tiago Vignatti | 5ab91ad | 2012-03-12 19:40:09 -0300 | [diff] [blame] | 5726 | long backlight_new = 0; |
Tiago Vignatti | 8e53c7f | 2012-02-29 19:53:50 +0200 | [diff] [blame] | 5727 | |
| 5728 | /* TODO: we're limiting to simple use cases, where we assume just |
| 5729 | * control on the primary display. We'd have to extend later if we |
| 5730 | * ever get support for setting backlights on random desktop LCD |
| 5731 | * panels though */ |
| 5732 | output = get_default_output(compositor); |
| 5733 | if (!output) |
| 5734 | return; |
| 5735 | |
| 5736 | if (!output->set_backlight) |
| 5737 | return; |
| 5738 | |
Tiago Vignatti | 5ab91ad | 2012-03-12 19:40:09 -0300 | [diff] [blame] | 5739 | if (key == KEY_F9 || key == KEY_BRIGHTNESSDOWN) |
| 5740 | backlight_new = output->backlight_current - 25; |
| 5741 | else if (key == KEY_F10 || key == KEY_BRIGHTNESSUP) |
| 5742 | backlight_new = output->backlight_current + 25; |
Tiago Vignatti | 8e53c7f | 2012-02-29 19:53:50 +0200 | [diff] [blame] | 5743 | |
Tiago Vignatti | 5ab91ad | 2012-03-12 19:40:09 -0300 | [diff] [blame] | 5744 | if (backlight_new < 5) |
| 5745 | backlight_new = 5; |
| 5746 | if (backlight_new > 255) |
| 5747 | backlight_new = 255; |
| 5748 | |
| 5749 | output->backlight_current = backlight_new; |
Tiago Vignatti | 8e53c7f | 2012-02-29 19:53:50 +0200 | [diff] [blame] | 5750 | output->set_backlight(output, output->backlight_current); |
| 5751 | } |
| 5752 | |
Ander Conselvan de Oliveira | c509d2b | 2012-11-08 17:20:45 +0200 | [diff] [blame] | 5753 | struct debug_binding_grab { |
Kristian Høgsberg | 29139d4 | 2013-04-18 15:25:39 -0400 | [diff] [blame] | 5754 | struct weston_keyboard_grab grab; |
Ander Conselvan de Oliveira | c509d2b | 2012-11-08 17:20:45 +0200 | [diff] [blame] | 5755 | struct weston_seat *seat; |
| 5756 | uint32_t key[2]; |
| 5757 | int key_released[2]; |
| 5758 | }; |
| 5759 | |
| 5760 | static void |
Kristian Høgsberg | 29139d4 | 2013-04-18 15:25:39 -0400 | [diff] [blame] | 5761 | 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] | 5762 | uint32_t key, uint32_t state) |
| 5763 | { |
| 5764 | struct debug_binding_grab *db = (struct debug_binding_grab *) grab; |
Rob Bradford | 880ebc7 | 2013-07-22 17:31:38 +0100 | [diff] [blame] | 5765 | struct weston_compositor *ec = db->seat->compositor; |
| 5766 | struct wl_display *display = ec->wl_display; |
Ander Conselvan de Oliveira | c509d2b | 2012-11-08 17:20:45 +0200 | [diff] [blame] | 5767 | struct wl_resource *resource; |
Ander Conselvan de Oliveira | c509d2b | 2012-11-08 17:20:45 +0200 | [diff] [blame] | 5768 | uint32_t serial; |
| 5769 | int send = 0, terminate = 0; |
| 5770 | int check_binding = 1; |
| 5771 | int i; |
Neil Roberts | 96d790e | 2013-09-19 17:32:00 +0100 | [diff] [blame] | 5772 | struct wl_list *resource_list; |
Ander Conselvan de Oliveira | c509d2b | 2012-11-08 17:20:45 +0200 | [diff] [blame] | 5773 | |
| 5774 | if (state == WL_KEYBOARD_KEY_STATE_RELEASED) { |
| 5775 | /* Do not run bindings on key releases */ |
| 5776 | check_binding = 0; |
| 5777 | |
| 5778 | for (i = 0; i < 2; i++) |
| 5779 | if (key == db->key[i]) |
| 5780 | db->key_released[i] = 1; |
| 5781 | |
| 5782 | if (db->key_released[0] && db->key_released[1]) { |
| 5783 | /* All key releases been swalled so end the grab */ |
| 5784 | terminate = 1; |
| 5785 | } else if (key != db->key[0] && key != db->key[1]) { |
| 5786 | /* Should not swallow release of other keys */ |
| 5787 | send = 1; |
| 5788 | } |
| 5789 | } else if (key == db->key[0] && !db->key_released[0]) { |
| 5790 | /* Do not check bindings for the first press of the binding |
| 5791 | * key. This allows it to be used as a debug shortcut. |
| 5792 | * We still need to swallow this event. */ |
| 5793 | check_binding = 0; |
| 5794 | } else if (db->key[1]) { |
| 5795 | /* If we already ran a binding don't process another one since |
| 5796 | * we can't keep track of all the binding keys that were |
| 5797 | * pressed in order to swallow the release events. */ |
| 5798 | send = 1; |
| 5799 | check_binding = 0; |
| 5800 | } |
| 5801 | |
| 5802 | if (check_binding) { |
Ander Conselvan de Oliveira | c509d2b | 2012-11-08 17:20:45 +0200 | [diff] [blame] | 5803 | if (weston_compositor_run_debug_binding(ec, db->seat, time, |
| 5804 | key, state)) { |
| 5805 | /* We ran a binding so swallow the press and keep the |
| 5806 | * grab to swallow the released too. */ |
| 5807 | send = 0; |
| 5808 | terminate = 0; |
| 5809 | db->key[1] = key; |
| 5810 | } else { |
| 5811 | /* Terminate the grab since the key pressed is not a |
| 5812 | * debug binding key. */ |
| 5813 | send = 1; |
| 5814 | terminate = 1; |
| 5815 | } |
| 5816 | } |
| 5817 | |
| 5818 | if (send) { |
Neil Roberts | 96d790e | 2013-09-19 17:32:00 +0100 | [diff] [blame] | 5819 | serial = wl_display_next_serial(display); |
| 5820 | resource_list = &grab->keyboard->focus_resource_list; |
| 5821 | wl_resource_for_each(resource, resource_list) { |
Ander Conselvan de Oliveira | c509d2b | 2012-11-08 17:20:45 +0200 | [diff] [blame] | 5822 | wl_keyboard_send_key(resource, serial, time, key, state); |
| 5823 | } |
| 5824 | } |
| 5825 | |
| 5826 | if (terminate) { |
Kristian Høgsberg | 29139d4 | 2013-04-18 15:25:39 -0400 | [diff] [blame] | 5827 | weston_keyboard_end_grab(grab->keyboard); |
| 5828 | if (grab->keyboard->input_method_resource) |
| 5829 | grab->keyboard->grab = &grab->keyboard->input_method_grab; |
Ander Conselvan de Oliveira | c509d2b | 2012-11-08 17:20:45 +0200 | [diff] [blame] | 5830 | free(db); |
| 5831 | } |
| 5832 | } |
| 5833 | |
| 5834 | static void |
Kristian Høgsberg | 29139d4 | 2013-04-18 15:25:39 -0400 | [diff] [blame] | 5835 | 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] | 5836 | uint32_t mods_depressed, uint32_t mods_latched, |
| 5837 | uint32_t mods_locked, uint32_t group) |
| 5838 | { |
| 5839 | struct wl_resource *resource; |
Neil Roberts | 96d790e | 2013-09-19 17:32:00 +0100 | [diff] [blame] | 5840 | struct wl_list *resource_list; |
Ander Conselvan de Oliveira | c509d2b | 2012-11-08 17:20:45 +0200 | [diff] [blame] | 5841 | |
Neil Roberts | 96d790e | 2013-09-19 17:32:00 +0100 | [diff] [blame] | 5842 | resource_list = &grab->keyboard->focus_resource_list; |
Ander Conselvan de Oliveira | c509d2b | 2012-11-08 17:20:45 +0200 | [diff] [blame] | 5843 | |
Neil Roberts | 96d790e | 2013-09-19 17:32:00 +0100 | [diff] [blame] | 5844 | wl_resource_for_each(resource, resource_list) { |
| 5845 | wl_keyboard_send_modifiers(resource, serial, mods_depressed, |
| 5846 | mods_latched, mods_locked, group); |
| 5847 | } |
Ander Conselvan de Oliveira | c509d2b | 2012-11-08 17:20:45 +0200 | [diff] [blame] | 5848 | } |
| 5849 | |
Jonas Ådahl | 1ea343e | 2013-10-25 23:18:05 +0200 | [diff] [blame] | 5850 | static void |
| 5851 | debug_binding_cancel(struct weston_keyboard_grab *grab) |
| 5852 | { |
| 5853 | struct debug_binding_grab *db = (struct debug_binding_grab *) grab; |
| 5854 | |
| 5855 | weston_keyboard_end_grab(grab->keyboard); |
| 5856 | free(db); |
| 5857 | } |
| 5858 | |
Kristian Høgsberg | 29139d4 | 2013-04-18 15:25:39 -0400 | [diff] [blame] | 5859 | struct weston_keyboard_grab_interface debug_binding_keyboard_grab = { |
Ander Conselvan de Oliveira | c509d2b | 2012-11-08 17:20:45 +0200 | [diff] [blame] | 5860 | debug_binding_key, |
Jonas Ådahl | 1ea343e | 2013-10-25 23:18:05 +0200 | [diff] [blame] | 5861 | debug_binding_modifiers, |
| 5862 | debug_binding_cancel, |
Ander Conselvan de Oliveira | c509d2b | 2012-11-08 17:20:45 +0200 | [diff] [blame] | 5863 | }; |
| 5864 | |
| 5865 | static void |
Kristian Høgsberg | e314875 | 2013-05-06 23:19:49 -0400 | [diff] [blame] | 5866 | 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] | 5867 | { |
| 5868 | struct debug_binding_grab *grab; |
| 5869 | |
| 5870 | grab = calloc(1, sizeof *grab); |
| 5871 | if (!grab) |
| 5872 | return; |
| 5873 | |
| 5874 | grab->seat = (struct weston_seat *) seat; |
| 5875 | grab->key[0] = key; |
| 5876 | grab->grab.interface = &debug_binding_keyboard_grab; |
Kristian Høgsberg | 29139d4 | 2013-04-18 15:25:39 -0400 | [diff] [blame] | 5877 | weston_keyboard_start_grab(seat->keyboard, &grab->grab); |
Ander Conselvan de Oliveira | c509d2b | 2012-11-08 17:20:45 +0200 | [diff] [blame] | 5878 | } |
| 5879 | |
Kristian Høgsberg | b41c081 | 2012-03-04 14:53:40 -0500 | [diff] [blame] | 5880 | static void |
Kristian Høgsberg | e314875 | 2013-05-06 23:19:49 -0400 | [diff] [blame] | 5881 | 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] | 5882 | void *data) |
Kristian Høgsberg | 92a57db | 2012-05-26 13:41:06 -0400 | [diff] [blame] | 5883 | { |
Kristian Høgsberg | fe7aa90 | 2013-05-08 09:54:37 -0400 | [diff] [blame] | 5884 | struct weston_surface *focus_surface; |
Kristian Høgsberg | 92a57db | 2012-05-26 13:41:06 -0400 | [diff] [blame] | 5885 | struct wl_client *client; |
Tiago Vignatti | 1d01b01 | 2012-09-27 17:48:36 +0300 | [diff] [blame] | 5886 | struct desktop_shell *shell = data; |
| 5887 | struct weston_compositor *compositor = shell->compositor; |
Kristian Høgsberg | 92a57db | 2012-05-26 13:41:06 -0400 | [diff] [blame] | 5888 | pid_t pid; |
Kristian Høgsberg | 92a57db | 2012-05-26 13:41:06 -0400 | [diff] [blame] | 5889 | |
Philipp Brüschweiler | 6cef009 | 2012-08-13 21:27:27 +0200 | [diff] [blame] | 5890 | focus_surface = seat->keyboard->focus; |
| 5891 | if (!focus_surface) |
| 5892 | return; |
| 5893 | |
Tiago Vignatti | 1d01b01 | 2012-09-27 17:48:36 +0300 | [diff] [blame] | 5894 | wl_signal_emit(&compositor->kill_signal, focus_surface); |
| 5895 | |
Jason Ekstrand | 26ed73c | 2013-06-06 22:34:41 -0500 | [diff] [blame] | 5896 | client = wl_resource_get_client(focus_surface->resource); |
Tiago Vignatti | 920f197 | 2012-09-27 17:48:35 +0300 | [diff] [blame] | 5897 | wl_client_get_credentials(client, &pid, NULL, NULL); |
| 5898 | |
| 5899 | /* Skip clients that we launched ourselves (the credentials of |
| 5900 | * the socketpair is ours) */ |
| 5901 | if (pid == getpid()) |
| 5902 | return; |
Kristian Høgsberg | 92a57db | 2012-05-26 13:41:06 -0400 | [diff] [blame] | 5903 | |
Daniel Stone | 325fc2d | 2012-05-30 16:31:58 +0100 | [diff] [blame] | 5904 | kill(pid, SIGKILL); |
Kristian Høgsberg | 92a57db | 2012-05-26 13:41:06 -0400 | [diff] [blame] | 5905 | } |
| 5906 | |
| 5907 | static void |
Kristian Høgsberg | e314875 | 2013-05-06 23:19:49 -0400 | [diff] [blame] | 5908 | workspace_up_binding(struct weston_seat *seat, uint32_t time, |
Jonas Ådahl | e3cddce | 2012-06-13 00:01:22 +0200 | [diff] [blame] | 5909 | uint32_t key, void *data) |
| 5910 | { |
| 5911 | struct desktop_shell *shell = data; |
| 5912 | unsigned int new_index = shell->workspaces.current; |
| 5913 | |
Kristian Høgsberg | ce345b0 | 2012-06-25 21:35:29 -0400 | [diff] [blame] | 5914 | if (shell->locked) |
Kristian Høgsberg | 4476aaf | 2012-06-25 14:03:13 -0400 | [diff] [blame] | 5915 | return; |
Jonas Ådahl | e3cddce | 2012-06-13 00:01:22 +0200 | [diff] [blame] | 5916 | if (new_index != 0) |
| 5917 | new_index--; |
| 5918 | |
| 5919 | change_workspace(shell, new_index); |
| 5920 | } |
| 5921 | |
| 5922 | static void |
Kristian Høgsberg | e314875 | 2013-05-06 23:19:49 -0400 | [diff] [blame] | 5923 | workspace_down_binding(struct weston_seat *seat, uint32_t time, |
Jonas Ådahl | e3cddce | 2012-06-13 00:01:22 +0200 | [diff] [blame] | 5924 | uint32_t key, void *data) |
| 5925 | { |
| 5926 | struct desktop_shell *shell = data; |
| 5927 | unsigned int new_index = shell->workspaces.current; |
| 5928 | |
Kristian Høgsberg | ce345b0 | 2012-06-25 21:35:29 -0400 | [diff] [blame] | 5929 | if (shell->locked) |
Kristian Høgsberg | 4476aaf | 2012-06-25 14:03:13 -0400 | [diff] [blame] | 5930 | return; |
Jonas Ådahl | e3cddce | 2012-06-13 00:01:22 +0200 | [diff] [blame] | 5931 | if (new_index < shell->workspaces.num - 1) |
| 5932 | new_index++; |
| 5933 | |
| 5934 | change_workspace(shell, new_index); |
| 5935 | } |
| 5936 | |
| 5937 | static void |
Kristian Høgsberg | e314875 | 2013-05-06 23:19:49 -0400 | [diff] [blame] | 5938 | workspace_f_binding(struct weston_seat *seat, uint32_t time, |
Jonas Ådahl | e3cddce | 2012-06-13 00:01:22 +0200 | [diff] [blame] | 5939 | uint32_t key, void *data) |
| 5940 | { |
| 5941 | struct desktop_shell *shell = data; |
| 5942 | unsigned int new_index; |
| 5943 | |
Kristian Høgsberg | ce345b0 | 2012-06-25 21:35:29 -0400 | [diff] [blame] | 5944 | if (shell->locked) |
Kristian Høgsberg | 4476aaf | 2012-06-25 14:03:13 -0400 | [diff] [blame] | 5945 | return; |
Jonas Ådahl | e3cddce | 2012-06-13 00:01:22 +0200 | [diff] [blame] | 5946 | new_index = key - KEY_F1; |
| 5947 | if (new_index >= shell->workspaces.num) |
| 5948 | new_index = shell->workspaces.num - 1; |
| 5949 | |
| 5950 | change_workspace(shell, new_index); |
| 5951 | } |
| 5952 | |
Jonas Ådahl | 8de6a1d | 2012-08-29 22:13:00 +0200 | [diff] [blame] | 5953 | static void |
Kristian Høgsberg | e314875 | 2013-05-06 23:19:49 -0400 | [diff] [blame] | 5954 | workspace_move_surface_up_binding(struct weston_seat *seat, uint32_t time, |
Jonas Ådahl | 8de6a1d | 2012-08-29 22:13:00 +0200 | [diff] [blame] | 5955 | uint32_t key, void *data) |
| 5956 | { |
| 5957 | struct desktop_shell *shell = data; |
| 5958 | unsigned int new_index = shell->workspaces.current; |
| 5959 | |
| 5960 | if (shell->locked) |
| 5961 | return; |
| 5962 | |
| 5963 | if (new_index != 0) |
| 5964 | new_index--; |
| 5965 | |
| 5966 | take_surface_to_workspace_by_seat(shell, seat, new_index); |
| 5967 | } |
| 5968 | |
| 5969 | static void |
Kristian Høgsberg | e314875 | 2013-05-06 23:19:49 -0400 | [diff] [blame] | 5970 | workspace_move_surface_down_binding(struct weston_seat *seat, uint32_t time, |
Jonas Ådahl | 8de6a1d | 2012-08-29 22:13:00 +0200 | [diff] [blame] | 5971 | uint32_t key, void *data) |
| 5972 | { |
| 5973 | struct desktop_shell *shell = data; |
| 5974 | unsigned int new_index = shell->workspaces.current; |
| 5975 | |
| 5976 | if (shell->locked) |
| 5977 | return; |
| 5978 | |
| 5979 | if (new_index < shell->workspaces.num - 1) |
| 5980 | new_index++; |
| 5981 | |
| 5982 | take_surface_to_workspace_by_seat(shell, seat, new_index); |
| 5983 | } |
Jonas Ådahl | e3cddce | 2012-06-13 00:01:22 +0200 | [diff] [blame] | 5984 | |
| 5985 | static void |
Ander Conselvan de Oliveira | c94d622 | 2014-01-29 18:47:54 +0200 | [diff] [blame] | 5986 | shell_reposition_view_on_output_destroy(struct weston_view *view) |
| 5987 | { |
| 5988 | struct weston_output *output, *first_output; |
| 5989 | struct weston_compositor *ec = view->surface->compositor; |
| 5990 | struct shell_surface *shsurf; |
| 5991 | float x, y; |
| 5992 | int visible; |
| 5993 | |
| 5994 | x = view->geometry.x; |
| 5995 | y = view->geometry.y; |
| 5996 | |
| 5997 | /* At this point the destroyed output is not in the list anymore. |
| 5998 | * If the view is still visible somewhere, we leave where it is, |
| 5999 | * otherwise, move it to the first output. */ |
| 6000 | visible = 0; |
| 6001 | wl_list_for_each(output, &ec->output_list, link) { |
| 6002 | if (pixman_region32_contains_point(&output->region, |
| 6003 | x, y, NULL)) { |
| 6004 | visible = 1; |
| 6005 | break; |
| 6006 | } |
| 6007 | } |
| 6008 | |
| 6009 | if (!visible) { |
| 6010 | first_output = container_of(ec->output_list.next, |
| 6011 | struct weston_output, link); |
| 6012 | |
| 6013 | x = first_output->x + first_output->width / 4; |
| 6014 | y = first_output->y + first_output->height / 4; |
Xiong Zhang | 62899f5 | 2014-03-07 16:27:19 +0800 | [diff] [blame] | 6015 | |
| 6016 | weston_view_set_position(view, x, y); |
| 6017 | } else { |
| 6018 | weston_view_geometry_dirty(view); |
Ander Conselvan de Oliveira | c94d622 | 2014-01-29 18:47:54 +0200 | [diff] [blame] | 6019 | } |
| 6020 | |
Ander Conselvan de Oliveira | c94d622 | 2014-01-29 18:47:54 +0200 | [diff] [blame] | 6021 | |
| 6022 | shsurf = get_shell_surface(view->surface); |
| 6023 | |
| 6024 | if (shsurf) { |
| 6025 | shsurf->saved_position_valid = false; |
| 6026 | shsurf->next_state.maximized = false; |
| 6027 | shsurf->next_state.fullscreen = false; |
| 6028 | shsurf->state_changed = true; |
| 6029 | } |
| 6030 | } |
| 6031 | |
Ander Conselvan de Oliveira | 304996d | 2014-04-11 13:57:15 +0300 | [diff] [blame] | 6032 | void |
| 6033 | shell_for_each_layer(struct desktop_shell *shell, |
| 6034 | shell_for_each_layer_func_t func, void *data) |
Ander Conselvan de Oliveira | c94d622 | 2014-01-29 18:47:54 +0200 | [diff] [blame] | 6035 | { |
Ander Conselvan de Oliveira | 304996d | 2014-04-11 13:57:15 +0300 | [diff] [blame] | 6036 | struct workspace **ws; |
| 6037 | |
| 6038 | func(shell, &shell->fullscreen_layer, data); |
| 6039 | func(shell, &shell->panel_layer, data); |
| 6040 | func(shell, &shell->background_layer, data); |
| 6041 | func(shell, &shell->lock_layer, data); |
| 6042 | func(shell, &shell->input_panel_layer, data); |
| 6043 | |
| 6044 | wl_array_for_each(ws, &shell->workspaces.array) |
| 6045 | func(shell, &(*ws)->layer, data); |
| 6046 | } |
| 6047 | |
| 6048 | static void |
| 6049 | shell_output_destroy_move_layer(struct desktop_shell *shell, |
| 6050 | struct weston_layer *layer, |
| 6051 | void *data) |
| 6052 | { |
| 6053 | struct weston_output *output = data; |
Ander Conselvan de Oliveira | c94d622 | 2014-01-29 18:47:54 +0200 | [diff] [blame] | 6054 | struct weston_view *view; |
| 6055 | |
Giulio Camuffo | 412e6a5 | 2014-07-09 22:12:56 +0300 | [diff] [blame] | 6056 | 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] | 6057 | if (view->output != output) |
| 6058 | continue; |
Ander Conselvan de Oliveira | c94d622 | 2014-01-29 18:47:54 +0200 | [diff] [blame] | 6059 | |
Ander Conselvan de Oliveira | 304996d | 2014-04-11 13:57:15 +0300 | [diff] [blame] | 6060 | shell_reposition_view_on_output_destroy(view); |
Ander Conselvan de Oliveira | c94d622 | 2014-01-29 18:47:54 +0200 | [diff] [blame] | 6061 | } |
| 6062 | } |
| 6063 | |
| 6064 | static void |
Xiong Zhang | 6b48142 | 2013-10-23 13:58:32 +0800 | [diff] [blame] | 6065 | handle_output_destroy(struct wl_listener *listener, void *data) |
| 6066 | { |
| 6067 | struct shell_output *output_listener = |
| 6068 | container_of(listener, struct shell_output, destroy_listener); |
Ander Conselvan de Oliveira | 304996d | 2014-04-11 13:57:15 +0300 | [diff] [blame] | 6069 | struct weston_output *output = output_listener->output; |
| 6070 | struct desktop_shell *shell = output_listener->shell; |
Xiong Zhang | 6b48142 | 2013-10-23 13:58:32 +0800 | [diff] [blame] | 6071 | |
Ander Conselvan de Oliveira | 304996d | 2014-04-11 13:57:15 +0300 | [diff] [blame] | 6072 | 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] | 6073 | |
Xiong Zhang | 6b48142 | 2013-10-23 13:58:32 +0800 | [diff] [blame] | 6074 | wl_list_remove(&output_listener->destroy_listener.link); |
| 6075 | wl_list_remove(&output_listener->link); |
| 6076 | free(output_listener); |
| 6077 | } |
| 6078 | |
| 6079 | static void |
| 6080 | create_shell_output(struct desktop_shell *shell, |
| 6081 | struct weston_output *output) |
| 6082 | { |
| 6083 | struct shell_output *shell_output; |
| 6084 | |
| 6085 | shell_output = zalloc(sizeof *shell_output); |
| 6086 | if (shell_output == NULL) |
| 6087 | return; |
| 6088 | |
| 6089 | shell_output->output = output; |
| 6090 | shell_output->shell = shell; |
| 6091 | shell_output->destroy_listener.notify = handle_output_destroy; |
| 6092 | wl_signal_add(&output->destroy_signal, |
| 6093 | &shell_output->destroy_listener); |
Kristian Høgsberg | a3a0e18 | 2013-10-23 23:36:04 -0700 | [diff] [blame] | 6094 | wl_list_insert(shell->output_list.prev, &shell_output->link); |
Xiong Zhang | 6b48142 | 2013-10-23 13:58:32 +0800 | [diff] [blame] | 6095 | } |
| 6096 | |
| 6097 | static void |
| 6098 | handle_output_create(struct wl_listener *listener, void *data) |
| 6099 | { |
| 6100 | struct desktop_shell *shell = |
| 6101 | container_of(listener, struct desktop_shell, output_create_listener); |
| 6102 | struct weston_output *output = (struct weston_output *)data; |
| 6103 | |
| 6104 | create_shell_output(shell, output); |
| 6105 | } |
| 6106 | |
| 6107 | static void |
Ander Conselvan de Oliveira | 304996d | 2014-04-11 13:57:15 +0300 | [diff] [blame] | 6108 | handle_output_move_layer(struct desktop_shell *shell, |
| 6109 | struct weston_layer *layer, void *data) |
Ander Conselvan de Oliveira | a8a9baf | 2014-01-29 18:47:52 +0200 | [diff] [blame] | 6110 | { |
Ander Conselvan de Oliveira | 304996d | 2014-04-11 13:57:15 +0300 | [diff] [blame] | 6111 | struct weston_output *output = data; |
Ander Conselvan de Oliveira | a8a9baf | 2014-01-29 18:47:52 +0200 | [diff] [blame] | 6112 | struct weston_view *view; |
| 6113 | float x, y; |
| 6114 | |
Giulio Camuffo | 412e6a5 | 2014-07-09 22:12:56 +0300 | [diff] [blame] | 6115 | 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] | 6116 | if (view->output != output) |
| 6117 | continue; |
| 6118 | |
| 6119 | x = view->geometry.x + output->move_x; |
| 6120 | y = view->geometry.y + output->move_y; |
| 6121 | weston_view_set_position(view, x, y); |
| 6122 | } |
| 6123 | } |
| 6124 | |
| 6125 | static void |
| 6126 | handle_output_move(struct wl_listener *listener, void *data) |
| 6127 | { |
| 6128 | struct desktop_shell *shell; |
| 6129 | |
Ander Conselvan de Oliveira | a8a9baf | 2014-01-29 18:47:52 +0200 | [diff] [blame] | 6130 | shell = container_of(listener, struct desktop_shell, |
| 6131 | output_move_listener); |
Ander Conselvan de Oliveira | a8a9baf | 2014-01-29 18:47:52 +0200 | [diff] [blame] | 6132 | |
Ander Conselvan de Oliveira | 304996d | 2014-04-11 13:57:15 +0300 | [diff] [blame] | 6133 | shell_for_each_layer(shell, handle_output_move_layer, data); |
Ander Conselvan de Oliveira | a8a9baf | 2014-01-29 18:47:52 +0200 | [diff] [blame] | 6134 | } |
| 6135 | |
| 6136 | static void |
Xiong Zhang | 6b48142 | 2013-10-23 13:58:32 +0800 | [diff] [blame] | 6137 | setup_output_destroy_handler(struct weston_compositor *ec, |
| 6138 | struct desktop_shell *shell) |
| 6139 | { |
| 6140 | struct weston_output *output; |
| 6141 | |
| 6142 | wl_list_init(&shell->output_list); |
| 6143 | wl_list_for_each(output, &ec->output_list, link) |
| 6144 | create_shell_output(shell, output); |
| 6145 | |
| 6146 | shell->output_create_listener.notify = handle_output_create; |
| 6147 | wl_signal_add(&ec->output_created_signal, |
| 6148 | &shell->output_create_listener); |
Ander Conselvan de Oliveira | a8a9baf | 2014-01-29 18:47:52 +0200 | [diff] [blame] | 6149 | |
| 6150 | shell->output_move_listener.notify = handle_output_move; |
| 6151 | wl_signal_add(&ec->output_moved_signal, &shell->output_move_listener); |
Xiong Zhang | 6b48142 | 2013-10-23 13:58:32 +0800 | [diff] [blame] | 6152 | } |
| 6153 | |
| 6154 | static void |
Kristian Høgsberg | 02e79dc | 2012-04-12 09:55:26 -0400 | [diff] [blame] | 6155 | shell_destroy(struct wl_listener *listener, void *data) |
Pekka Paalanen | 3c64723 | 2011-12-22 13:43:43 +0200 | [diff] [blame] | 6156 | { |
Tiago Vignatti | be14326 | 2012-04-16 17:31:41 +0300 | [diff] [blame] | 6157 | struct desktop_shell *shell = |
| 6158 | container_of(listener, struct desktop_shell, destroy_listener); |
Jonas Ådahl | e3cddce | 2012-06-13 00:01:22 +0200 | [diff] [blame] | 6159 | struct workspace **ws; |
Xiong Zhang | 6b48142 | 2013-10-23 13:58:32 +0800 | [diff] [blame] | 6160 | struct shell_output *shell_output, *tmp; |
Pekka Paalanen | 3c64723 | 2011-12-22 13:43:43 +0200 | [diff] [blame] | 6161 | |
Kristian Høgsberg | 17bccae | 2014-01-16 16:46:28 -0800 | [diff] [blame] | 6162 | /* Force state to unlocked so we don't try to fade */ |
| 6163 | shell->locked = false; |
Pekka Paalanen | 9cf5cc8 | 2012-01-02 16:00:24 +0200 | [diff] [blame] | 6164 | if (shell->child.client) |
| 6165 | wl_client_destroy(shell->child.client); |
| 6166 | |
Ander Conselvan de Oliveira | a457563 | 2013-02-21 18:35:23 +0200 | [diff] [blame] | 6167 | wl_list_remove(&shell->idle_listener.link); |
| 6168 | wl_list_remove(&shell->wake_listener.link); |
Kristian Høgsberg | 677a5f5 | 2013-12-04 11:00:19 -0800 | [diff] [blame] | 6169 | |
| 6170 | input_panel_destroy(shell); |
Kristian Høgsberg | 88c1607 | 2012-05-16 08:04:19 -0400 | [diff] [blame] | 6171 | |
Xiong Zhang | 6b48142 | 2013-10-23 13:58:32 +0800 | [diff] [blame] | 6172 | wl_list_for_each_safe(shell_output, tmp, &shell->output_list, link) { |
| 6173 | wl_list_remove(&shell_output->destroy_listener.link); |
| 6174 | wl_list_remove(&shell_output->link); |
| 6175 | free(shell_output); |
| 6176 | } |
| 6177 | |
| 6178 | wl_list_remove(&shell->output_create_listener.link); |
Kristian Høgsberg | 6d50b0f | 2014-04-30 20:46:25 -0700 | [diff] [blame] | 6179 | wl_list_remove(&shell->output_move_listener.link); |
Xiong Zhang | 6b48142 | 2013-10-23 13:58:32 +0800 | [diff] [blame] | 6180 | |
Jonas Ådahl | e3cddce | 2012-06-13 00:01:22 +0200 | [diff] [blame] | 6181 | wl_array_for_each(ws, &shell->workspaces.array) |
| 6182 | workspace_destroy(*ws); |
| 6183 | wl_array_release(&shell->workspaces.array); |
| 6184 | |
Pekka Paalanen | 3c64723 | 2011-12-22 13:43:43 +0200 | [diff] [blame] | 6185 | free(shell->screensaver.path); |
Emilio Pozuelo Monfort | 46ce798 | 2013-11-20 13:22:29 +0100 | [diff] [blame] | 6186 | free(shell->client); |
Pekka Paalanen | 3c64723 | 2011-12-22 13:43:43 +0200 | [diff] [blame] | 6187 | free(shell); |
| 6188 | } |
| 6189 | |
Tiago Vignatti | 0b52d48 | 2012-04-20 18:54:25 +0300 | [diff] [blame] | 6190 | static void |
| 6191 | shell_add_bindings(struct weston_compositor *ec, struct desktop_shell *shell) |
| 6192 | { |
| 6193 | uint32_t mod; |
Jonas Ådahl | e3cddce | 2012-06-13 00:01:22 +0200 | [diff] [blame] | 6194 | int i, num_workspace_bindings; |
Tiago Vignatti | 0b52d48 | 2012-04-20 18:54:25 +0300 | [diff] [blame] | 6195 | |
| 6196 | /* fixed bindings */ |
Daniel Stone | 325fc2d | 2012-05-30 16:31:58 +0100 | [diff] [blame] | 6197 | weston_compositor_add_key_binding(ec, KEY_BACKSPACE, |
| 6198 | MODIFIER_CTRL | MODIFIER_ALT, |
| 6199 | terminate_binding, ec); |
| 6200 | weston_compositor_add_button_binding(ec, BTN_LEFT, 0, |
| 6201 | click_to_activate_binding, |
| 6202 | shell); |
Kristian Høgsberg | f0ce581 | 2014-04-07 11:52:17 -0700 | [diff] [blame] | 6203 | weston_compositor_add_button_binding(ec, BTN_RIGHT, 0, |
| 6204 | click_to_activate_binding, |
| 6205 | shell); |
Neil Roberts | a28c693 | 2013-10-03 16:43:04 +0100 | [diff] [blame] | 6206 | weston_compositor_add_touch_binding(ec, 0, |
| 6207 | touch_to_activate_binding, |
| 6208 | shell); |
Daniel Stone | 325fc2d | 2012-05-30 16:31:58 +0100 | [diff] [blame] | 6209 | weston_compositor_add_axis_binding(ec, WL_POINTER_AXIS_VERTICAL_SCROLL, |
| 6210 | MODIFIER_SUPER | MODIFIER_ALT, |
| 6211 | surface_opacity_binding, NULL); |
| 6212 | weston_compositor_add_axis_binding(ec, WL_POINTER_AXIS_VERTICAL_SCROLL, |
| 6213 | MODIFIER_SUPER, zoom_axis_binding, |
| 6214 | NULL); |
Tiago Vignatti | 0b52d48 | 2012-04-20 18:54:25 +0300 | [diff] [blame] | 6215 | |
| 6216 | /* configurable bindings */ |
| 6217 | mod = shell->binding_modifier; |
Daniel Stone | 325fc2d | 2012-05-30 16:31:58 +0100 | [diff] [blame] | 6218 | weston_compositor_add_key_binding(ec, KEY_PAGEUP, mod, |
| 6219 | zoom_key_binding, NULL); |
| 6220 | weston_compositor_add_key_binding(ec, KEY_PAGEDOWN, mod, |
| 6221 | zoom_key_binding, NULL); |
Kristian Høgsberg | 211b517 | 2014-01-11 13:10:21 -0800 | [diff] [blame] | 6222 | weston_compositor_add_key_binding(ec, KEY_M, mod | MODIFIER_SHIFT, |
| 6223 | maximize_binding, NULL); |
| 6224 | weston_compositor_add_key_binding(ec, KEY_F, mod | MODIFIER_SHIFT, |
| 6225 | fullscreen_binding, NULL); |
Daniel Stone | 325fc2d | 2012-05-30 16:31:58 +0100 | [diff] [blame] | 6226 | weston_compositor_add_button_binding(ec, BTN_LEFT, mod, move_binding, |
| 6227 | shell); |
Neil Roberts | aba0f25 | 2013-10-03 16:43:05 +0100 | [diff] [blame] | 6228 | weston_compositor_add_touch_binding(ec, mod, touch_move_binding, shell); |
Daniel Stone | 325fc2d | 2012-05-30 16:31:58 +0100 | [diff] [blame] | 6229 | weston_compositor_add_button_binding(ec, BTN_MIDDLE, mod, |
| 6230 | resize_binding, shell); |
Kristian Høgsberg | 0837fa9 | 2014-01-20 10:35:26 -0800 | [diff] [blame] | 6231 | weston_compositor_add_button_binding(ec, BTN_LEFT, |
| 6232 | mod | MODIFIER_SHIFT, |
| 6233 | resize_binding, shell); |
Pekka Paalanen | 7bb6510 | 2013-05-22 18:03:04 +0300 | [diff] [blame] | 6234 | |
| 6235 | if (ec->capabilities & WESTON_CAP_ROTATION_ANY) |
| 6236 | weston_compositor_add_button_binding(ec, BTN_RIGHT, mod, |
| 6237 | rotate_binding, NULL); |
| 6238 | |
Daniel Stone | 325fc2d | 2012-05-30 16:31:58 +0100 | [diff] [blame] | 6239 | weston_compositor_add_key_binding(ec, KEY_TAB, mod, switcher_binding, |
| 6240 | shell); |
| 6241 | weston_compositor_add_key_binding(ec, KEY_F9, mod, backlight_binding, |
| 6242 | ec); |
| 6243 | weston_compositor_add_key_binding(ec, KEY_BRIGHTNESSDOWN, 0, |
| 6244 | backlight_binding, ec); |
| 6245 | weston_compositor_add_key_binding(ec, KEY_F10, mod, backlight_binding, |
| 6246 | ec); |
| 6247 | weston_compositor_add_key_binding(ec, KEY_BRIGHTNESSUP, 0, |
| 6248 | backlight_binding, ec); |
Daniel Stone | 325fc2d | 2012-05-30 16:31:58 +0100 | [diff] [blame] | 6249 | weston_compositor_add_key_binding(ec, KEY_K, mod, |
| 6250 | force_kill_binding, shell); |
Jonas Ådahl | e3cddce | 2012-06-13 00:01:22 +0200 | [diff] [blame] | 6251 | weston_compositor_add_key_binding(ec, KEY_UP, mod, |
| 6252 | workspace_up_binding, shell); |
| 6253 | weston_compositor_add_key_binding(ec, KEY_DOWN, mod, |
| 6254 | workspace_down_binding, shell); |
Jonas Ådahl | 8de6a1d | 2012-08-29 22:13:00 +0200 | [diff] [blame] | 6255 | weston_compositor_add_key_binding(ec, KEY_UP, mod | MODIFIER_SHIFT, |
| 6256 | workspace_move_surface_up_binding, |
| 6257 | shell); |
| 6258 | weston_compositor_add_key_binding(ec, KEY_DOWN, mod | MODIFIER_SHIFT, |
| 6259 | workspace_move_surface_down_binding, |
| 6260 | shell); |
Jonas Ådahl | e3cddce | 2012-06-13 00:01:22 +0200 | [diff] [blame] | 6261 | |
Kristian Høgsberg | d56ab4e | 2014-01-16 16:51:52 -0800 | [diff] [blame] | 6262 | if (shell->exposay_modifier) |
| 6263 | weston_compositor_add_modifier_binding(ec, shell->exposay_modifier, |
| 6264 | exposay_binding, shell); |
Daniel Stone | df8133b | 2013-11-19 11:37:14 +0100 | [diff] [blame] | 6265 | |
Jonas Ådahl | e3cddce | 2012-06-13 00:01:22 +0200 | [diff] [blame] | 6266 | /* Add bindings for mod+F[1-6] for workspace 1 to 6. */ |
| 6267 | if (shell->workspaces.num > 1) { |
| 6268 | num_workspace_bindings = shell->workspaces.num; |
| 6269 | if (num_workspace_bindings > 6) |
| 6270 | num_workspace_bindings = 6; |
| 6271 | for (i = 0; i < num_workspace_bindings; i++) |
| 6272 | weston_compositor_add_key_binding(ec, KEY_F1 + i, mod, |
| 6273 | workspace_f_binding, |
| 6274 | shell); |
| 6275 | } |
Ander Conselvan de Oliveira | c509d2b | 2012-11-08 17:20:45 +0200 | [diff] [blame] | 6276 | |
| 6277 | /* Debug bindings */ |
| 6278 | weston_compositor_add_key_binding(ec, KEY_SPACE, mod | MODIFIER_SHIFT, |
| 6279 | debug_binding, shell); |
Tiago Vignatti | 0b52d48 | 2012-04-20 18:54:25 +0300 | [diff] [blame] | 6280 | } |
| 6281 | |
Jason Ekstrand | 024177c | 2014-04-21 19:42:58 -0500 | [diff] [blame] | 6282 | static void |
| 6283 | handle_seat_created(struct wl_listener *listener, void *data) |
| 6284 | { |
| 6285 | struct weston_seat *seat = data; |
| 6286 | |
| 6287 | create_shell_seat(seat); |
| 6288 | } |
| 6289 | |
Kristian Høgsberg | 1c56218 | 2011-05-02 22:09:20 -0400 | [diff] [blame] | 6290 | WL_EXPORT int |
Kristian Høgsberg | cb4685b | 2013-02-20 15:37:49 -0500 | [diff] [blame] | 6291 | module_init(struct weston_compositor *ec, |
Ossama Othman | a50e6e4 | 2013-05-14 09:48:26 -0700 | [diff] [blame] | 6292 | int *argc, char *argv[]) |
Kristian Høgsberg | 4cca349 | 2011-01-18 07:53:49 -0500 | [diff] [blame] | 6293 | { |
Kristian Høgsberg | f4d2f23 | 2012-08-10 10:05:39 -0400 | [diff] [blame] | 6294 | struct weston_seat *seat; |
Tiago Vignatti | be14326 | 2012-04-16 17:31:41 +0300 | [diff] [blame] | 6295 | struct desktop_shell *shell; |
Jonas Ådahl | e3cddce | 2012-06-13 00:01:22 +0200 | [diff] [blame] | 6296 | struct workspace **pws; |
| 6297 | unsigned int i; |
Tiago Vignatti | b7dbbd6 | 2012-09-25 17:57:01 +0300 | [diff] [blame] | 6298 | struct wl_event_loop *loop; |
Kristian Høgsberg | 02ec0a5 | 2011-04-23 13:04:11 -0400 | [diff] [blame] | 6299 | |
Peter Hutterer | f3d6227 | 2013-08-08 11:57:05 +1000 | [diff] [blame] | 6300 | shell = zalloc(sizeof *shell); |
Kristian Høgsberg | 02ec0a5 | 2011-04-23 13:04:11 -0400 | [diff] [blame] | 6301 | if (shell == NULL) |
| 6302 | return -1; |
| 6303 | |
Kristian Høgsberg | 7584062 | 2011-09-06 13:48:16 -0400 | [diff] [blame] | 6304 | shell->compositor = ec; |
Kristian Høgsberg | 02e79dc | 2012-04-12 09:55:26 -0400 | [diff] [blame] | 6305 | |
| 6306 | shell->destroy_listener.notify = shell_destroy; |
| 6307 | wl_signal_add(&ec->destroy_signal, &shell->destroy_listener); |
Ander Conselvan de Oliveira | a457563 | 2013-02-21 18:35:23 +0200 | [diff] [blame] | 6308 | shell->idle_listener.notify = idle_handler; |
| 6309 | wl_signal_add(&ec->idle_signal, &shell->idle_listener); |
| 6310 | shell->wake_listener.notify = wake_handler; |
| 6311 | wl_signal_add(&ec->wake_signal, &shell->wake_listener); |
Kristian Høgsberg | 677a5f5 | 2013-12-04 11:00:19 -0800 | [diff] [blame] | 6312 | |
Kristian Høgsberg | 82a1d11 | 2012-07-19 14:02:00 -0400 | [diff] [blame] | 6313 | ec->shell_interface.shell = shell; |
Tiago Vignatti | bc052c9 | 2012-04-19 16:18:18 +0300 | [diff] [blame] | 6314 | ec->shell_interface.create_shell_surface = create_shell_surface; |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 6315 | ec->shell_interface.get_primary_view = get_primary_view; |
Tiago Vignatti | bc052c9 | 2012-04-19 16:18:18 +0300 | [diff] [blame] | 6316 | ec->shell_interface.set_toplevel = set_toplevel; |
Tiago Vignatti | 491bac1 | 2012-05-18 16:37:43 -0400 | [diff] [blame] | 6317 | ec->shell_interface.set_transient = set_transient; |
Kristian Høgsberg | 4779241 | 2014-05-04 13:47:06 -0700 | [diff] [blame] | 6318 | ec->shell_interface.set_fullscreen = shell_interface_set_fullscreen; |
Tiago Vignatti | fb2adba | 2013-06-12 15:43:21 -0300 | [diff] [blame] | 6319 | ec->shell_interface.set_xwayland = set_xwayland; |
Kristian Høgsberg | ae356ae | 2014-04-29 16:03:54 -0700 | [diff] [blame] | 6320 | ec->shell_interface.move = shell_interface_move; |
Kristian Høgsberg | c1693f2 | 2012-05-22 16:56:23 -0400 | [diff] [blame] | 6321 | ec->shell_interface.resize = surface_resize; |
Giulio Camuffo | 62942ad | 2013-09-11 18:20:47 +0200 | [diff] [blame] | 6322 | ec->shell_interface.set_title = set_title; |
Jasper St. Pierre | ccf48fb | 2014-05-02 10:21:38 -0400 | [diff] [blame] | 6323 | ec->shell_interface.set_window_geometry = set_window_geometry; |
Kristian Høgsberg | 4cca349 | 2011-01-18 07:53:49 -0500 | [diff] [blame] | 6324 | |
Kristian Høgsberg | 3be2ce9 | 2012-02-29 12:42:35 -0500 | [diff] [blame] | 6325 | weston_layer_init(&shell->fullscreen_layer, &ec->cursor_layer.link); |
| 6326 | weston_layer_init(&shell->panel_layer, &shell->fullscreen_layer.link); |
Jonas Ådahl | e3cddce | 2012-06-13 00:01:22 +0200 | [diff] [blame] | 6327 | weston_layer_init(&shell->background_layer, &shell->panel_layer.link); |
| 6328 | weston_layer_init(&shell->lock_layer, NULL); |
Philipp Brüschweiler | 711fda8 | 2012-08-09 18:50:43 +0200 | [diff] [blame] | 6329 | weston_layer_init(&shell->input_panel_layer, NULL); |
Jonas Ådahl | e3cddce | 2012-06-13 00:01:22 +0200 | [diff] [blame] | 6330 | |
| 6331 | wl_array_init(&shell->workspaces.array); |
Jonas Ådahl | e9d2250 | 2012-08-29 22:13:01 +0200 | [diff] [blame] | 6332 | wl_list_init(&shell->workspaces.client_list); |
Kristian Høgsberg | 3be2ce9 | 2012-02-29 12:42:35 -0500 | [diff] [blame] | 6333 | |
Kristian Høgsberg | 677a5f5 | 2013-12-04 11:00:19 -0800 | [diff] [blame] | 6334 | if (input_panel_setup(shell) < 0) |
| 6335 | return -1; |
| 6336 | |
Kristian Høgsberg | 14e438c | 2013-05-26 21:48:14 -0400 | [diff] [blame] | 6337 | shell_configuration(shell); |
Pekka Paalanen | e955f1e | 2011-12-07 11:49:52 +0200 | [diff] [blame] | 6338 | |
Daniel Stone | df8133b | 2013-11-19 11:37:14 +0100 | [diff] [blame] | 6339 | shell->exposay.state_cur = EXPOSAY_LAYOUT_INACTIVE; |
| 6340 | shell->exposay.state_target = EXPOSAY_TARGET_CANCEL; |
| 6341 | |
Jonas Ådahl | e3cddce | 2012-06-13 00:01:22 +0200 | [diff] [blame] | 6342 | for (i = 0; i < shell->workspaces.num; i++) { |
| 6343 | pws = wl_array_add(&shell->workspaces.array, sizeof *pws); |
| 6344 | if (pws == NULL) |
| 6345 | return -1; |
| 6346 | |
| 6347 | *pws = workspace_create(); |
| 6348 | if (*pws == NULL) |
| 6349 | return -1; |
| 6350 | } |
| 6351 | activate_workspace(shell, 0); |
| 6352 | |
Manuel Bachmann | 50c87db | 2014-02-26 15:52:13 +0100 | [diff] [blame] | 6353 | weston_layer_init(&shell->minimized_layer, NULL); |
| 6354 | |
Jonas Ådahl | 8de6a1d | 2012-08-29 22:13:00 +0200 | [diff] [blame] | 6355 | wl_list_init(&shell->workspaces.anim_sticky_list); |
Jonas Ådahl | 62fcd04 | 2012-06-13 00:01:23 +0200 | [diff] [blame] | 6356 | wl_list_init(&shell->workspaces.animation.link); |
| 6357 | shell->workspaces.animation.frame = animate_workspace_change_frame; |
| 6358 | |
Kristian Høgsberg | 919cddb | 2013-07-08 19:03:57 -0400 | [diff] [blame] | 6359 | if (wl_global_create(ec->wl_display, &wl_shell_interface, 1, |
Kristian Høgsberg | 97d44aa | 2011-08-26 17:21:20 -0400 | [diff] [blame] | 6360 | shell, bind_shell) == NULL) |
Kristian Høgsberg | 4cca349 | 2011-01-18 07:53:49 -0500 | [diff] [blame] | 6361 | return -1; |
| 6362 | |
Rafael Antognolli | e2a3455 | 2013-12-03 15:35:45 -0200 | [diff] [blame] | 6363 | if (wl_global_create(ec->wl_display, &xdg_shell_interface, 1, |
| 6364 | shell, bind_xdg_shell) == NULL) |
| 6365 | return -1; |
| 6366 | |
Kristian Høgsberg | 919cddb | 2013-07-08 19:03:57 -0400 | [diff] [blame] | 6367 | if (wl_global_create(ec->wl_display, |
Jonny Lamb | 765760d | 2014-08-20 15:53:19 +0200 | [diff] [blame] | 6368 | &desktop_shell_interface, 3, |
Kristian Høgsberg | 919cddb | 2013-07-08 19:03:57 -0400 | [diff] [blame] | 6369 | shell, bind_desktop_shell) == NULL) |
Kristian Høgsberg | 7584062 | 2011-09-06 13:48:16 -0400 | [diff] [blame] | 6370 | return -1; |
| 6371 | |
Kristian Høgsberg | 919cddb | 2013-07-08 19:03:57 -0400 | [diff] [blame] | 6372 | if (wl_global_create(ec->wl_display, &screensaver_interface, 1, |
| 6373 | shell, bind_screensaver) == NULL) |
Pekka Paalanen | 6e16811 | 2011-11-24 11:34:05 +0200 | [diff] [blame] | 6374 | return -1; |
| 6375 | |
Kristian Høgsberg | 919cddb | 2013-07-08 19:03:57 -0400 | [diff] [blame] | 6376 | if (wl_global_create(ec->wl_display, &workspace_manager_interface, 1, |
| 6377 | shell, bind_workspace_manager) == NULL) |
Jonas Ådahl | e9d2250 | 2012-08-29 22:13:01 +0200 | [diff] [blame] | 6378 | return -1; |
| 6379 | |
Kristian Høgsberg | f03a616 | 2012-01-17 11:07:42 -0500 | [diff] [blame] | 6380 | shell->child.deathstamp = weston_compositor_get_time(); |
Tiago Vignatti | b7dbbd6 | 2012-09-25 17:57:01 +0300 | [diff] [blame] | 6381 | |
Jonny Lamb | 765760d | 2014-08-20 15:53:19 +0200 | [diff] [blame] | 6382 | shell->panel_position = DESKTOP_SHELL_PANEL_POSITION_TOP; |
| 6383 | |
Xiong Zhang | 6b48142 | 2013-10-23 13:58:32 +0800 | [diff] [blame] | 6384 | setup_output_destroy_handler(ec, shell); |
| 6385 | |
Tiago Vignatti | b7dbbd6 | 2012-09-25 17:57:01 +0300 | [diff] [blame] | 6386 | loop = wl_display_get_event_loop(ec->wl_display); |
| 6387 | wl_event_loop_add_idle(loop, launch_desktop_shell_process, shell); |
Pekka Paalanen | 6cd281a | 2011-11-03 14:11:32 +0200 | [diff] [blame] | 6388 | |
Ander Conselvan de Oliveira | 859e885 | 2013-02-21 18:35:21 +0200 | [diff] [blame] | 6389 | shell->screensaver.timer = |
| 6390 | wl_event_loop_add_timer(loop, screensaver_timeout, shell); |
| 6391 | |
Jason Ekstrand | 024177c | 2014-04-21 19:42:58 -0500 | [diff] [blame] | 6392 | wl_list_for_each(seat, &ec->seat_list, link) |
| 6393 | handle_seat_created(NULL, seat); |
| 6394 | shell->seat_create_listener.notify = handle_seat_created; |
| 6395 | wl_signal_add(&ec->seat_created_signal, &shell->seat_create_listener); |
Kristian Høgsberg | d56bd90 | 2012-06-05 09:58:51 -0400 | [diff] [blame] | 6396 | |
Giulio Camuffo | c6ab3d5 | 2013-12-11 23:45:12 +0100 | [diff] [blame] | 6397 | screenshooter_create(ec); |
| 6398 | |
Tiago Vignatti | 0b52d48 | 2012-04-20 18:54:25 +0300 | [diff] [blame] | 6399 | shell_add_bindings(ec, shell); |
Kristian Høgsberg | 0793756 | 2011-04-12 17:25:42 -0400 | [diff] [blame] | 6400 | |
Pekka Paalanen | 79346ab | 2013-05-22 18:03:09 +0300 | [diff] [blame] | 6401 | shell_fade_init(shell); |
Ander Conselvan de Oliveira | 19d10ef | 2013-02-21 18:35:20 +0200 | [diff] [blame] | 6402 | |
Kristian Høgsberg | 4cca349 | 2011-01-18 07:53:49 -0500 | [diff] [blame] | 6403 | return 0; |
| 6404 | } |