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 | * |
Bryce Harrington | af637c2 | 2015-06-11 12:55:55 -0700 | [diff] [blame] | 6 | * Permission is hereby granted, free of charge, to any person obtaining a |
| 7 | * copy of this software and associated documentation files (the "Software"), |
| 8 | * to deal in the Software without restriction, including without limitation |
| 9 | * the rights to use, copy, modify, merge, publish, distribute, sublicense, |
| 10 | * and/or sell copies of the Software, and to permit persons to whom the |
| 11 | * Software is furnished to do so, subject to the following conditions: |
Kristian Høgsberg | 4cca349 | 2011-01-18 07:53:49 -0500 | [diff] [blame] | 12 | * |
Bryce Harrington | af637c2 | 2015-06-11 12:55:55 -0700 | [diff] [blame] | 13 | * The above copyright notice and this permission notice (including the next |
| 14 | * paragraph) shall be included in all copies or substantial portions of the |
| 15 | * Software. |
| 16 | * |
| 17 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR |
| 18 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, |
| 19 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL |
| 20 | * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER |
| 21 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING |
| 22 | * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER |
| 23 | * DEALINGS IN THE SOFTWARE. |
Kristian Høgsberg | 4cca349 | 2011-01-18 07:53:49 -0500 | [diff] [blame] | 24 | */ |
| 25 | |
Daniel Stone | c228e23 | 2013-05-22 18:03:19 +0300 | [diff] [blame] | 26 | #include "config.h" |
| 27 | |
Kristian Høgsberg | 4cca349 | 2011-01-18 07:53:49 -0500 | [diff] [blame] | 28 | #include <stdlib.h> |
Kristian Høgsberg | 7584062 | 2011-09-06 13:48:16 -0400 | [diff] [blame] | 29 | #include <stdio.h> |
Kristian Høgsberg | 4cca349 | 2011-01-18 07:53:49 -0500 | [diff] [blame] | 30 | #include <string.h> |
| 31 | #include <unistd.h> |
Kristian Høgsberg | 0793756 | 2011-04-12 17:25:42 -0400 | [diff] [blame] | 32 | #include <linux/input.h> |
Pekka Paalanen | f0fc70d | 2011-11-15 13:34:54 +0200 | [diff] [blame] | 33 | #include <assert.h> |
Pekka Paalanen | 18027e5 | 2011-12-02 16:31:49 +0200 | [diff] [blame] | 34 | #include <signal.h> |
Pekka Paalanen | 460099f | 2012-01-20 16:48:25 +0200 | [diff] [blame] | 35 | #include <math.h> |
Kristian Høgsberg | 92a57db | 2012-05-26 13:41:06 -0400 | [diff] [blame] | 36 | #include <sys/types.h> |
Kristian Høgsberg | 4cca349 | 2011-01-18 07:53:49 -0500 | [diff] [blame] | 37 | |
Kristian Høgsberg | 1ef2313 | 2013-12-04 00:20:01 -0800 | [diff] [blame] | 38 | #include "shell.h" |
Pekka Paalanen | 58f98c9 | 2016-06-03 16:45:21 +0300 | [diff] [blame] | 39 | #include "compositor/weston.h" |
Jonas Ådahl | 6d6fb61 | 2015-11-17 16:00:33 +0800 | [diff] [blame] | 40 | #include "weston-desktop-shell-server-protocol.h" |
Jon Cruz | 4678bab | 2015-06-15 15:37:07 -0700 | [diff] [blame] | 41 | #include "shared/config-parser.h" |
Jon Cruz | d618f68 | 2015-06-15 15:37:09 -0700 | [diff] [blame] | 42 | #include "shared/helpers.h" |
Jonas Ådahl | 2a22933 | 2015-11-17 16:00:32 +0800 | [diff] [blame] | 43 | #include "xdg-shell-unstable-v5-server-protocol.h" |
Kristian Høgsberg | 4cca349 | 2011-01-18 07:53:49 -0500 | [diff] [blame] | 44 | |
Jonas Ådahl | e3cddce | 2012-06-13 00:01:22 +0200 | [diff] [blame] | 45 | #define DEFAULT_NUM_WORKSPACES 1 |
Jonas Ådahl | 62fcd04 | 2012-06-13 00:01:23 +0200 | [diff] [blame] | 46 | #define DEFAULT_WORKSPACE_CHANGE_ANIMATION_LENGTH 200 |
Jonas Ådahl | e3cddce | 2012-06-13 00:01:22 +0200 | [diff] [blame] | 47 | |
Giulio Camuffo | 1aaf3e4 | 2013-12-09 22:47:58 +0100 | [diff] [blame] | 48 | #ifndef static_assert |
| 49 | #define static_assert(cond, msg) |
| 50 | #endif |
| 51 | |
Jonas Ådahl | 0476974 | 2012-06-13 00:01:24 +0200 | [diff] [blame] | 52 | struct focus_state { |
| 53 | struct weston_seat *seat; |
Kristian Høgsberg | 2f5faff | 2012-07-31 16:36:34 -0400 | [diff] [blame] | 54 | struct workspace *ws; |
Jonas Ådahl | 0476974 | 2012-06-13 00:01:24 +0200 | [diff] [blame] | 55 | struct weston_surface *keyboard_focus; |
| 56 | struct wl_list link; |
| 57 | struct wl_listener seat_destroy_listener; |
| 58 | struct wl_listener surface_destroy_listener; |
| 59 | }; |
| 60 | |
Kristian Høgsberg | d2abb83 | 2011-11-23 10:52:40 -0500 | [diff] [blame] | 61 | enum shell_surface_type { |
Pekka Paalanen | 9826223 | 2011-12-01 10:42:22 +0200 | [diff] [blame] | 62 | SHELL_SURFACE_NONE, |
Kristian Høgsberg | d2abb83 | 2011-11-23 10:52:40 -0500 | [diff] [blame] | 63 | SHELL_SURFACE_TOPLEVEL, |
Tiago Vignatti | fb2adba | 2013-06-12 15:43:21 -0300 | [diff] [blame] | 64 | SHELL_SURFACE_POPUP, |
| 65 | SHELL_SURFACE_XWAYLAND |
Pekka Paalanen | 57da4a8 | 2011-11-23 16:42:16 +0200 | [diff] [blame] | 66 | }; |
| 67 | |
Jason Ekstrand | 9e9512f | 2014-04-16 21:12:10 -0500 | [diff] [blame] | 68 | struct shell_client; |
| 69 | |
Philip Withnall | 648a4dd | 2013-11-25 18:01:44 +0000 | [diff] [blame] | 70 | /* |
| 71 | * Surface stacking and ordering. |
| 72 | * |
| 73 | * This is handled using several linked lists of surfaces, organised into |
| 74 | * ‘layers’. The layers are ordered, and each of the surfaces in one layer are |
| 75 | * above all of the surfaces in the layer below. The set of layers is static and |
| 76 | * in the following order (top-most first): |
| 77 | * • Lock layer (only ever displayed on its own) |
| 78 | * • Cursor layer |
Manuel Bachmann | 805d2f5 | 2014-03-05 12:21:34 +0100 | [diff] [blame] | 79 | * • Input panel layer |
Philip Withnall | 648a4dd | 2013-11-25 18:01:44 +0000 | [diff] [blame] | 80 | * • Fullscreen layer |
| 81 | * • Panel layer |
Philip Withnall | 648a4dd | 2013-11-25 18:01:44 +0000 | [diff] [blame] | 82 | * • Workspace layers |
| 83 | * • Background layer |
| 84 | * |
| 85 | * The list of layers may be manipulated to remove whole layers of surfaces from |
| 86 | * display. For example, when locking the screen, all layers except the lock |
| 87 | * layer are removed. |
| 88 | * |
| 89 | * A surface’s layer is modified on configuring the surface, in |
| 90 | * set_surface_type() (which is only called when the surface’s type change is |
| 91 | * _committed_). If a surface’s type changes (e.g. when making a window |
| 92 | * fullscreen) its layer changes too. |
| 93 | * |
| 94 | * In order to allow popup and transient surfaces to be correctly stacked above |
| 95 | * their parent surfaces, each surface tracks both its parent surface, and a |
| 96 | * linked list of its children. When a surface’s layer is updated, so are the |
| 97 | * layers of its children. Note that child surfaces are *not* the same as |
| 98 | * subsurfaces — child/parent surfaces are purely for maintaining stacking |
| 99 | * order. |
| 100 | * |
| 101 | * The children_link list of siblings of a surface (i.e. those surfaces which |
| 102 | * have the same parent) only contains weston_surfaces which have a |
| 103 | * shell_surface. Stacking is not implemented for non-shell_surface |
| 104 | * weston_surfaces. This means that the following implication does *not* hold: |
| 105 | * (shsurf->parent != NULL) ⇒ !wl_list_is_empty(shsurf->children_link) |
| 106 | */ |
| 107 | |
Pekka Paalanen | 56cdea9 | 2011-11-23 16:14:12 +0200 | [diff] [blame] | 108 | struct shell_surface { |
Jason Ekstrand | 651f00e | 2013-06-14 10:07:54 -0500 | [diff] [blame] | 109 | struct wl_resource *resource; |
| 110 | struct wl_signal destroy_signal; |
Jason Ekstrand | 9e9512f | 2014-04-16 21:12:10 -0500 | [diff] [blame] | 111 | struct shell_client *owner; |
Jonas Ådahl | 49d77d2 | 2015-03-18 16:20:51 +0800 | [diff] [blame] | 112 | struct wl_resource *owner_resource; |
Pekka Paalanen | 9d1613e | 2011-11-25 12:09:16 +0200 | [diff] [blame] | 113 | |
Kristian Høgsberg | 8334bc1 | 2012-01-03 10:29:47 -0500 | [diff] [blame] | 114 | struct weston_surface *surface; |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 115 | struct weston_view *view; |
Jason Ekstrand | 918f2dd | 2013-12-02 21:01:53 -0600 | [diff] [blame] | 116 | int32_t last_width, last_height; |
Pekka Paalanen | 9d1613e | 2011-11-25 12:09:16 +0200 | [diff] [blame] | 117 | struct wl_listener surface_destroy_listener; |
Kristian Høgsberg | 160fe75 | 2014-03-11 10:19:10 -0700 | [diff] [blame] | 118 | struct wl_listener resource_destroy_listener; |
| 119 | |
Kristian Høgsberg | 8150b19 | 2012-06-27 10:22:58 -0400 | [diff] [blame] | 120 | struct weston_surface *parent; |
Philip Withnall | 648a4dd | 2013-11-25 18:01:44 +0000 | [diff] [blame] | 121 | struct wl_list children_list; /* child surfaces of this one */ |
| 122 | struct wl_list children_link; /* sibling surfaces of this one */ |
Tiago Vignatti | be14326 | 2012-04-16 17:31:41 +0300 | [diff] [blame] | 123 | struct desktop_shell *shell; |
Pekka Paalanen | 57da4a8 | 2011-11-23 16:42:16 +0200 | [diff] [blame] | 124 | |
Kristian Høgsberg | c8f8dd8 | 2013-12-05 23:20:33 -0800 | [diff] [blame] | 125 | enum shell_surface_type type; |
Kristian Høgsberg | e7afd91 | 2012-05-02 09:47:44 -0400 | [diff] [blame] | 126 | char *title, *class; |
Kristian Høgsberg | d2abb83 | 2011-11-23 10:52:40 -0500 | [diff] [blame] | 127 | int32_t saved_x, saved_y; |
Alex Wu | 4539b08 | 2012-03-01 12:57:46 +0800 | [diff] [blame] | 128 | bool saved_position_valid; |
Alex Wu | 7bcb8bd | 2012-04-27 09:07:24 +0800 | [diff] [blame] | 129 | bool saved_rotation_valid; |
Kristian Høgsberg | c85f1d4 | 2013-10-24 16:52:00 -0700 | [diff] [blame] | 130 | int unresponsive, grabbed; |
Kristian Høgsberg | 44cd196 | 2014-02-05 21:36:04 -0800 | [diff] [blame] | 131 | uint32_t resize_edges; |
Benjamin Franzke | d0f79ab | 2011-11-22 12:43:52 +0100 | [diff] [blame] | 132 | |
Kristian Høgsberg | b3cca0a | 2012-01-04 22:19:14 -0500 | [diff] [blame] | 133 | struct { |
Pekka Paalanen | 460099f | 2012-01-20 16:48:25 +0200 | [diff] [blame] | 134 | struct weston_transform transform; |
Kristian Høgsberg | 765e27b | 2012-01-27 13:36:13 -0500 | [diff] [blame] | 135 | struct weston_matrix rotation; |
Pekka Paalanen | 460099f | 2012-01-20 16:48:25 +0200 | [diff] [blame] | 136 | } rotation; |
| 137 | |
| 138 | struct { |
Giulio Camuffo | 5085a75 | 2013-03-25 21:42:45 +0100 | [diff] [blame] | 139 | struct wl_list grab_link; |
Kristian Høgsberg | b3cca0a | 2012-01-04 22:19:14 -0500 | [diff] [blame] | 140 | int32_t x, y; |
Giulio Camuffo | 5085a75 | 2013-03-25 21:42:45 +0100 | [diff] [blame] | 141 | struct shell_seat *shseat; |
Kristian Høgsberg | 3730f36 | 2012-04-13 12:40:07 -0400 | [diff] [blame] | 142 | uint32_t serial; |
Kristian Høgsberg | b3cca0a | 2012-01-04 22:19:14 -0500 | [diff] [blame] | 143 | } popup; |
| 144 | |
Alex Wu | 4539b08 | 2012-03-01 12:57:46 +0800 | [diff] [blame] | 145 | struct { |
Tiago Vignatti | 52e598c | 2012-05-07 15:23:08 +0300 | [diff] [blame] | 146 | int32_t x, y; |
Tiago Vignatti | 491bac1 | 2012-05-18 16:37:43 -0400 | [diff] [blame] | 147 | uint32_t flags; |
Tiago Vignatti | 52e598c | 2012-05-07 15:23:08 +0300 | [diff] [blame] | 148 | } transient; |
| 149 | |
| 150 | struct { |
Alex Wu | 4539b08 | 2012-03-01 12:57:46 +0800 | [diff] [blame] | 151 | enum wl_shell_surface_fullscreen_method type; |
| 152 | struct weston_transform transform; /* matrix from x, y */ |
| 153 | uint32_t framerate; |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 154 | struct weston_view *black_view; |
Alex Wu | 4539b08 | 2012-03-01 12:57:46 +0800 | [diff] [blame] | 155 | } fullscreen; |
| 156 | |
Jonas Ådahl | 62fcd04 | 2012-06-13 00:01:23 +0200 | [diff] [blame] | 157 | struct weston_transform workspace_transform; |
| 158 | |
Kristian Høgsberg | 1cbf326 | 2012-02-17 23:49:07 -0500 | [diff] [blame] | 159 | struct weston_output *fullscreen_output; |
Kristian Høgsberg | 8334bc1 | 2012-01-03 10:29:47 -0500 | [diff] [blame] | 160 | struct weston_output *output; |
Benjamin Franzke | d0f79ab | 2011-11-22 12:43:52 +0100 | [diff] [blame] | 161 | struct wl_list link; |
Kristian Høgsberg | a61ca06 | 2012-05-22 16:05:52 -0400 | [diff] [blame] | 162 | |
| 163 | const struct weston_shell_client *client; |
Rafael Antognolli | 03b1659 | 2013-12-03 15:35:42 -0200 | [diff] [blame] | 164 | |
Jasper St. Pierre | 6458ec3 | 2014-04-11 16:00:31 -0700 | [diff] [blame] | 165 | struct surface_state { |
Rafael Antognolli | 03b1659 | 2013-12-03 15:35:42 -0200 | [diff] [blame] | 166 | bool maximized; |
| 167 | bool fullscreen; |
Rafael Antognolli | ed207b4 | 2013-12-03 15:35:43 -0200 | [diff] [blame] | 168 | bool relative; |
Emilio Pozuelo Monfort | 9e7c759 | 2014-01-30 14:01:10 +0100 | [diff] [blame] | 169 | bool lowered; |
Jasper St. Pierre | 8c6aa45 | 2014-02-08 18:29:49 -0500 | [diff] [blame] | 170 | } state, next_state, requested_state; /* surface states */ |
Rafael Antognolli | 03b1659 | 2013-12-03 15:35:42 -0200 | [diff] [blame] | 171 | bool state_changed; |
Jasper St. Pierre | 8c6aa45 | 2014-02-08 18:29:49 -0500 | [diff] [blame] | 172 | bool state_requested; |
Jasper St. Pierre | faf27a9 | 2013-12-09 17:36:28 -0500 | [diff] [blame] | 173 | |
Kristian Høgsberg | ae356ae | 2014-04-29 16:03:54 -0700 | [diff] [blame] | 174 | struct { |
Jasper St. Pierre | ccf48fb | 2014-05-02 10:21:38 -0400 | [diff] [blame] | 175 | int32_t x, y, width, height; |
| 176 | } geometry, next_geometry; |
| 177 | bool has_set_geometry, has_next_geometry; |
Kristian Høgsberg | ae356ae | 2014-04-29 16:03:54 -0700 | [diff] [blame] | 178 | |
Jasper St. Pierre | faf27a9 | 2013-12-09 17:36:28 -0500 | [diff] [blame] | 179 | int focus_count; |
Derek Foreman | 039e9be | 2015-04-14 17:09:06 -0500 | [diff] [blame] | 180 | |
| 181 | bool destroying; |
Pekka Paalanen | 56cdea9 | 2011-11-23 16:14:12 +0200 | [diff] [blame] | 182 | }; |
| 183 | |
Ander Conselvan de Oliveira | fe0444a | 2012-04-04 17:48:05 +0300 | [diff] [blame] | 184 | struct shell_grab { |
Kristian Høgsberg | 02bbabb | 2013-05-06 22:15:05 -0400 | [diff] [blame] | 185 | struct weston_pointer_grab grab; |
Ander Conselvan de Oliveira | fe0444a | 2012-04-04 17:48:05 +0300 | [diff] [blame] | 186 | struct shell_surface *shsurf; |
| 187 | struct wl_listener shsurf_destroy_listener; |
| 188 | }; |
| 189 | |
Rusty Lynch | 1084da5 | 2013-08-15 09:10:08 -0700 | [diff] [blame] | 190 | struct shell_touch_grab { |
| 191 | struct weston_touch_grab grab; |
| 192 | struct shell_surface *shsurf; |
| 193 | struct wl_listener shsurf_destroy_listener; |
| 194 | struct weston_touch *touch; |
| 195 | }; |
| 196 | |
Ander Conselvan de Oliveira | fe0444a | 2012-04-04 17:48:05 +0300 | [diff] [blame] | 197 | struct weston_move_grab { |
| 198 | struct shell_grab base; |
Daniel Stone | 103db7f | 2012-05-08 17:17:55 +0100 | [diff] [blame] | 199 | wl_fixed_t dx, dy; |
Derek Foreman | cf7d95a | 2015-06-03 15:53:22 -0500 | [diff] [blame] | 200 | bool client_initiated; |
Kristian Høgsberg | 4cca349 | 2011-01-18 07:53:49 -0500 | [diff] [blame] | 201 | }; |
| 202 | |
Rusty Lynch | 1084da5 | 2013-08-15 09:10:08 -0700 | [diff] [blame] | 203 | struct weston_touch_move_grab { |
| 204 | struct shell_touch_grab base; |
Kristian Høgsberg | 8e80a31 | 2014-01-17 15:18:10 -0800 | [diff] [blame] | 205 | int active; |
Rusty Lynch | 1084da5 | 2013-08-15 09:10:08 -0700 | [diff] [blame] | 206 | wl_fixed_t dx, dy; |
| 207 | }; |
| 208 | |
Pekka Paalanen | 460099f | 2012-01-20 16:48:25 +0200 | [diff] [blame] | 209 | struct rotate_grab { |
Ander Conselvan de Oliveira | fe0444a | 2012-04-04 17:48:05 +0300 | [diff] [blame] | 210 | struct shell_grab base; |
Kristian Høgsberg | 765e27b | 2012-01-27 13:36:13 -0500 | [diff] [blame] | 211 | struct weston_matrix rotation; |
Pekka Paalanen | 460099f | 2012-01-20 16:48:25 +0200 | [diff] [blame] | 212 | struct { |
John Kåre Alsaker | 490d02a | 2012-09-30 02:57:21 +0200 | [diff] [blame] | 213 | float x; |
| 214 | float y; |
Pekka Paalanen | 460099f | 2012-01-20 16:48:25 +0200 | [diff] [blame] | 215 | } center; |
| 216 | }; |
| 217 | |
Giulio Camuffo | 5085a75 | 2013-03-25 21:42:45 +0100 | [diff] [blame] | 218 | struct shell_seat { |
| 219 | struct weston_seat *seat; |
| 220 | struct wl_listener seat_destroy_listener; |
Jasper St. Pierre | faf27a9 | 2013-12-09 17:36:28 -0500 | [diff] [blame] | 221 | struct weston_surface *focused_surface; |
Giulio Camuffo | 5085a75 | 2013-03-25 21:42:45 +0100 | [diff] [blame] | 222 | |
Jason Ekstrand | 024177c | 2014-04-21 19:42:58 -0500 | [diff] [blame] | 223 | struct wl_listener caps_changed_listener; |
| 224 | struct wl_listener pointer_focus_listener; |
| 225 | struct wl_listener keyboard_focus_listener; |
| 226 | |
Giulio Camuffo | 5085a75 | 2013-03-25 21:42:45 +0100 | [diff] [blame] | 227 | struct { |
Kristian Høgsberg | 02bbabb | 2013-05-06 22:15:05 -0400 | [diff] [blame] | 228 | struct weston_pointer_grab grab; |
Jonny Lamb | 76cf1fe | 2014-08-20 11:27:10 +0200 | [diff] [blame] | 229 | struct weston_touch_grab touch_grab; |
Giulio Camuffo | 5085a75 | 2013-03-25 21:42:45 +0100 | [diff] [blame] | 230 | struct wl_list surfaces_list; |
| 231 | struct wl_client *client; |
| 232 | int32_t initial_up; |
Jonny Lamb | 76cf1fe | 2014-08-20 11:27:10 +0200 | [diff] [blame] | 233 | enum { POINTER, TOUCH } type; |
Giulio Camuffo | 5085a75 | 2013-03-25 21:42:45 +0100 | [diff] [blame] | 234 | } popup_grab; |
| 235 | }; |
| 236 | |
Kristian Høgsberg | 2bff94e | 2014-02-11 12:22:51 -0800 | [diff] [blame] | 237 | struct shell_client { |
| 238 | struct wl_resource *resource; |
| 239 | struct wl_client *client; |
| 240 | struct desktop_shell *shell; |
| 241 | struct wl_listener destroy_listener; |
| 242 | struct wl_event_source *ping_timer; |
| 243 | uint32_t ping_serial; |
| 244 | int unresponsive; |
Jonas Ådahl | 49d77d2 | 2015-03-18 16:20:51 +0800 | [diff] [blame] | 245 | struct wl_list surface_list; |
Kristian Høgsberg | 2bff94e | 2014-02-11 12:22:51 -0800 | [diff] [blame] | 246 | }; |
| 247 | |
Alex Wu | bd3354b | 2012-04-17 17:20:49 +0800 | [diff] [blame] | 248 | static struct desktop_shell * |
| 249 | shell_surface_get_shell(struct shell_surface *shsurf); |
| 250 | |
Kristian Høgsberg | 0c36903 | 2013-02-14 21:31:44 -0500 | [diff] [blame] | 251 | static void |
Derek Foreman | 74de469 | 2015-07-15 13:00:39 -0500 | [diff] [blame] | 252 | surface_rotate(struct shell_surface *surface, struct weston_pointer *pointer); |
Kristian Høgsberg | 0c36903 | 2013-02-14 21:31:44 -0500 | [diff] [blame] | 253 | |
Pekka Paalanen | 79346ab | 2013-05-22 18:03:09 +0300 | [diff] [blame] | 254 | static void |
| 255 | shell_fade_startup(struct desktop_shell *shell); |
| 256 | |
Philip Withnall | becb77e | 2013-11-25 18:01:30 +0000 | [diff] [blame] | 257 | static struct shell_seat * |
| 258 | get_shell_seat(struct weston_seat *seat); |
| 259 | |
Jonny Lamb | d73c694 | 2014-08-20 15:53:20 +0200 | [diff] [blame] | 260 | static void |
| 261 | get_output_panel_size(struct desktop_shell *shell, |
| 262 | struct weston_output *output, |
| 263 | int *width, int *height); |
Kristian Høgsberg | ae356ae | 2014-04-29 16:03:54 -0700 | [diff] [blame] | 264 | |
Philip Withnall | 648a4dd | 2013-11-25 18:01:44 +0000 | [diff] [blame] | 265 | static void |
| 266 | shell_surface_update_child_surface_layers(struct shell_surface *shsurf); |
| 267 | |
Alex Wu | bd3354b | 2012-04-17 17:20:49 +0800 | [diff] [blame] | 268 | static bool |
Rafael Antognolli | e2a3455 | 2013-12-03 15:35:45 -0200 | [diff] [blame] | 269 | shell_surface_is_wl_shell_surface(struct shell_surface *shsurf); |
| 270 | |
| 271 | static bool |
| 272 | shell_surface_is_xdg_surface(struct shell_surface *shsurf); |
| 273 | |
| 274 | static bool |
| 275 | shell_surface_is_xdg_popup(struct shell_surface *shsurf); |
| 276 | |
| 277 | static void |
| 278 | shell_surface_set_parent(struct shell_surface *shsurf, |
| 279 | struct weston_surface *parent); |
| 280 | |
Pekka Paalanen | 8274d90 | 2014-08-06 19:36:51 +0300 | [diff] [blame] | 281 | static int |
| 282 | shell_surface_get_label(struct weston_surface *surface, char *buf, size_t len) |
| 283 | { |
| 284 | struct shell_surface *shsurf; |
| 285 | const char *typestr[] = { |
| 286 | [SHELL_SURFACE_NONE] = "unidentified", |
| 287 | [SHELL_SURFACE_TOPLEVEL] = "top-level", |
| 288 | [SHELL_SURFACE_POPUP] = "popup", |
| 289 | [SHELL_SURFACE_XWAYLAND] = "Xwayland", |
| 290 | }; |
| 291 | const char *t, *c; |
| 292 | |
| 293 | shsurf = get_shell_surface(surface); |
| 294 | if (!shsurf) |
| 295 | return snprintf(buf, len, "unidentified window"); |
| 296 | |
| 297 | t = shsurf->title; |
| 298 | c = shsurf->class; |
| 299 | |
| 300 | return snprintf(buf, len, "%s window%s%s%s%s%s", |
| 301 | typestr[shsurf->type], |
| 302 | t ? " '" : "", t ?: "", t ? "'" : "", |
| 303 | c ? " of " : "", c ?: ""); |
| 304 | } |
| 305 | |
Rafael Antognolli | e2a3455 | 2013-12-03 15:35:45 -0200 | [diff] [blame] | 306 | static bool |
Alex Wu | bd3354b | 2012-04-17 17:20:49 +0800 | [diff] [blame] | 307 | shell_surface_is_top_fullscreen(struct shell_surface *shsurf) |
| 308 | { |
| 309 | struct desktop_shell *shell; |
Mario Kleiner | 9f4d655 | 2015-06-21 21:25:08 +0200 | [diff] [blame] | 310 | struct weston_view *view; |
| 311 | struct shell_surface *top_fs_shsurf = NULL; |
Alex Wu | bd3354b | 2012-04-17 17:20:49 +0800 | [diff] [blame] | 312 | |
| 313 | shell = shell_surface_get_shell(shsurf); |
Quentin Glidic | c0d79ce | 2013-01-29 14:16:13 +0100 | [diff] [blame] | 314 | |
Giulio Camuffo | 412e6a5 | 2014-07-09 22:12:56 +0300 | [diff] [blame] | 315 | if (wl_list_empty(&shell->fullscreen_layer.view_list.link)) |
Alex Wu | bd3354b | 2012-04-17 17:20:49 +0800 | [diff] [blame] | 316 | return false; |
| 317 | |
Mario Kleiner | 9f4d655 | 2015-06-21 21:25:08 +0200 | [diff] [blame] | 318 | /* Find topmost shsurf on the same fullscreen output on which shsurf |
| 319 | * is displaying. We don't care about other outputs. |
| 320 | */ |
| 321 | wl_list_for_each(view, &shell->fullscreen_layer.view_list.link, |
| 322 | layer_link.link) { |
| 323 | struct shell_surface *cand_shsurf = get_shell_surface(view->surface); |
| 324 | |
| 325 | if (cand_shsurf && |
| 326 | (cand_shsurf->fullscreen_output == shsurf->fullscreen_output)) { |
| 327 | top_fs_shsurf = cand_shsurf; |
| 328 | break; |
| 329 | } |
| 330 | } |
| 331 | |
| 332 | return (shsurf == top_fs_shsurf); |
Alex Wu | bd3354b | 2012-04-17 17:20:49 +0800 | [diff] [blame] | 333 | } |
| 334 | |
Kristian Høgsberg | 6af8eb9 | 2012-01-25 16:57:11 -0500 | [diff] [blame] | 335 | static void |
Kristian Høgsberg | 27e3052 | 2012-04-11 23:18:23 -0400 | [diff] [blame] | 336 | destroy_shell_grab_shsurf(struct wl_listener *listener, void *data) |
Ander Conselvan de Oliveira | fe0444a | 2012-04-04 17:48:05 +0300 | [diff] [blame] | 337 | { |
| 338 | struct shell_grab *grab; |
| 339 | |
| 340 | grab = container_of(listener, struct shell_grab, |
| 341 | shsurf_destroy_listener); |
| 342 | |
| 343 | grab->shsurf = NULL; |
| 344 | } |
| 345 | |
Kristian Høgsberg | 1ef2313 | 2013-12-04 00:20:01 -0800 | [diff] [blame] | 346 | struct weston_view * |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 347 | get_default_view(struct weston_surface *surface) |
| 348 | { |
| 349 | struct shell_surface *shsurf; |
| 350 | struct weston_view *view; |
| 351 | |
| 352 | if (!surface || wl_list_empty(&surface->views)) |
| 353 | return NULL; |
| 354 | |
| 355 | shsurf = get_shell_surface(surface); |
| 356 | if (shsurf) |
| 357 | return shsurf->view; |
| 358 | |
| 359 | wl_list_for_each(view, &surface->views, surface_link) |
| 360 | if (weston_view_is_mapped(view)) |
| 361 | return view; |
| 362 | |
| 363 | return container_of(surface->views.next, struct weston_view, surface_link); |
| 364 | } |
| 365 | |
Ander Conselvan de Oliveira | fe0444a | 2012-04-04 17:48:05 +0300 | [diff] [blame] | 366 | static void |
Kristian Høgsberg | 02bbabb | 2013-05-06 22:15:05 -0400 | [diff] [blame] | 367 | popup_grab_end(struct weston_pointer *pointer); |
Jonny Lamb | 76cf1fe | 2014-08-20 11:27:10 +0200 | [diff] [blame] | 368 | static void |
| 369 | touch_popup_grab_end(struct weston_touch *touch); |
Kristian Høgsberg | 57e0907 | 2012-10-30 14:07:27 -0400 | [diff] [blame] | 370 | |
| 371 | static void |
Ander Conselvan de Oliveira | b9d2a0f | 2012-06-28 18:08:05 +0300 | [diff] [blame] | 372 | shell_grab_start(struct shell_grab *grab, |
Kristian Høgsberg | 02bbabb | 2013-05-06 22:15:05 -0400 | [diff] [blame] | 373 | const struct weston_pointer_grab_interface *interface, |
Ander Conselvan de Oliveira | b9d2a0f | 2012-06-28 18:08:05 +0300 | [diff] [blame] | 374 | struct shell_surface *shsurf, |
Kristian Høgsberg | 02bbabb | 2013-05-06 22:15:05 -0400 | [diff] [blame] | 375 | struct weston_pointer *pointer, |
Jonas Ådahl | 6d6fb61 | 2015-11-17 16:00:33 +0800 | [diff] [blame] | 376 | enum weston_desktop_shell_cursor cursor) |
Ander Conselvan de Oliveira | fe0444a | 2012-04-04 17:48:05 +0300 | [diff] [blame] | 377 | { |
Ander Conselvan de Oliveira | b9d2a0f | 2012-06-28 18:08:05 +0300 | [diff] [blame] | 378 | struct desktop_shell *shell = shsurf->shell; |
Derek Foreman | 1281a36 | 2015-07-31 16:55:32 -0500 | [diff] [blame] | 379 | struct weston_touch *touch = weston_seat_get_touch(pointer->seat); |
Ander Conselvan de Oliveira | b9d2a0f | 2012-06-28 18:08:05 +0300 | [diff] [blame] | 380 | |
Kristian Høgsberg | 57e0907 | 2012-10-30 14:07:27 -0400 | [diff] [blame] | 381 | popup_grab_end(pointer); |
Derek Foreman | 1281a36 | 2015-07-31 16:55:32 -0500 | [diff] [blame] | 382 | if (touch) |
| 383 | touch_popup_grab_end(touch); |
Kristian Høgsberg | 57e0907 | 2012-10-30 14:07:27 -0400 | [diff] [blame] | 384 | |
Ander Conselvan de Oliveira | fe0444a | 2012-04-04 17:48:05 +0300 | [diff] [blame] | 385 | grab->grab.interface = interface; |
| 386 | grab->shsurf = shsurf; |
Kristian Høgsberg | 27e3052 | 2012-04-11 23:18:23 -0400 | [diff] [blame] | 387 | grab->shsurf_destroy_listener.notify = destroy_shell_grab_shsurf; |
Jason Ekstrand | 651f00e | 2013-06-14 10:07:54 -0500 | [diff] [blame] | 388 | wl_signal_add(&shsurf->destroy_signal, |
Kristian Høgsberg | 27e3052 | 2012-04-11 23:18:23 -0400 | [diff] [blame] | 389 | &grab->shsurf_destroy_listener); |
Ander Conselvan de Oliveira | fe0444a | 2012-04-04 17:48:05 +0300 | [diff] [blame] | 390 | |
Kristian Høgsberg | c85f1d4 | 2013-10-24 16:52:00 -0700 | [diff] [blame] | 391 | shsurf->grabbed = 1; |
Kristian Høgsberg | 02bbabb | 2013-05-06 22:15:05 -0400 | [diff] [blame] | 392 | weston_pointer_start_grab(pointer, &grab->grab); |
Kristian Høgsberg | c9974a0 | 2013-07-03 19:24:57 -0400 | [diff] [blame] | 393 | if (shell->child.desktop_shell) { |
Jonas Ådahl | 6d6fb61 | 2015-11-17 16:00:33 +0800 | [diff] [blame] | 394 | weston_desktop_shell_send_grab_cursor(shell->child.desktop_shell, |
Kristian Høgsberg | c9974a0 | 2013-07-03 19:24:57 -0400 | [diff] [blame] | 395 | cursor); |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 396 | weston_pointer_set_focus(pointer, |
| 397 | get_default_view(shell->grab_surface), |
Kristian Høgsberg | c9974a0 | 2013-07-03 19:24:57 -0400 | [diff] [blame] | 398 | wl_fixed_from_int(0), |
| 399 | wl_fixed_from_int(0)); |
| 400 | } |
Ander Conselvan de Oliveira | fe0444a | 2012-04-04 17:48:05 +0300 | [diff] [blame] | 401 | } |
| 402 | |
Jonny Lamb | d73c694 | 2014-08-20 15:53:20 +0200 | [diff] [blame] | 403 | static void |
| 404 | get_output_panel_size(struct desktop_shell *shell, |
| 405 | struct weston_output *output, |
| 406 | int *width, |
| 407 | int *height) |
Jasper St. Pierre | 6458ec3 | 2014-04-11 16:00:31 -0700 | [diff] [blame] | 408 | { |
| 409 | struct weston_view *view; |
Jonny Lamb | d73c694 | 2014-08-20 15:53:20 +0200 | [diff] [blame] | 410 | |
| 411 | *width = 0; |
| 412 | *height = 0; |
Jasper St. Pierre | 6458ec3 | 2014-04-11 16:00:31 -0700 | [diff] [blame] | 413 | |
| 414 | if (!output) |
Jonny Lamb | d73c694 | 2014-08-20 15:53:20 +0200 | [diff] [blame] | 415 | return; |
Jasper St. Pierre | 6458ec3 | 2014-04-11 16:00:31 -0700 | [diff] [blame] | 416 | |
Giulio Camuffo | 412e6a5 | 2014-07-09 22:12:56 +0300 | [diff] [blame] | 417 | 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] | 418 | float x, y; |
| 419 | |
| 420 | if (view->surface->output != output) |
| 421 | continue; |
| 422 | |
| 423 | switch (shell->panel_position) { |
Jonas Ådahl | 6d6fb61 | 2015-11-17 16:00:33 +0800 | [diff] [blame] | 424 | case WESTON_DESKTOP_SHELL_PANEL_POSITION_TOP: |
| 425 | case WESTON_DESKTOP_SHELL_PANEL_POSITION_BOTTOM: |
Jonny Lamb | d73c694 | 2014-08-20 15:53:20 +0200 | [diff] [blame] | 426 | weston_view_to_global_float(view, |
| 427 | view->surface->width, 0, |
| 428 | &x, &y); |
| 429 | |
Derek Foreman | 612341f | 2015-04-15 12:23:55 -0500 | [diff] [blame] | 430 | *width = (int)x - output->x; |
| 431 | *height = view->surface->height + (int) y - output->y; |
Jonny Lamb | d73c694 | 2014-08-20 15:53:20 +0200 | [diff] [blame] | 432 | return; |
| 433 | |
Jonas Ådahl | 6d6fb61 | 2015-11-17 16:00:33 +0800 | [diff] [blame] | 434 | case WESTON_DESKTOP_SHELL_PANEL_POSITION_LEFT: |
| 435 | case WESTON_DESKTOP_SHELL_PANEL_POSITION_RIGHT: |
Jonny Lamb | d73c694 | 2014-08-20 15:53:20 +0200 | [diff] [blame] | 436 | weston_view_to_global_float(view, |
| 437 | 0, view->surface->height, |
| 438 | &x, &y); |
| 439 | |
Derek Foreman | 612341f | 2015-04-15 12:23:55 -0500 | [diff] [blame] | 440 | *width = view->surface->width + (int)x - output->x; |
| 441 | *height = (int)y - output->y; |
Jonny Lamb | d73c694 | 2014-08-20 15:53:20 +0200 | [diff] [blame] | 442 | return; |
| 443 | |
| 444 | default: |
| 445 | /* we've already set width and height to |
| 446 | * fallback values. */ |
Jasper St. Pierre | 6458ec3 | 2014-04-11 16:00:31 -0700 | [diff] [blame] | 447 | break; |
| 448 | } |
| 449 | } |
| 450 | |
Jonny Lamb | d73c694 | 2014-08-20 15:53:20 +0200 | [diff] [blame] | 451 | /* the correct view wasn't found */ |
| 452 | } |
| 453 | |
| 454 | static void |
Quentin Glidic | 5c20195 | 2016-03-23 13:50:49 +0100 | [diff] [blame] | 455 | get_output_work_area(void *data, |
Jonny Lamb | d73c694 | 2014-08-20 15:53:20 +0200 | [diff] [blame] | 456 | struct weston_output *output, |
| 457 | pixman_rectangle32_t *area) |
| 458 | { |
Quentin Glidic | 5c20195 | 2016-03-23 13:50:49 +0100 | [diff] [blame] | 459 | struct desktop_shell *shell = data; |
Jonny Lamb | d73c694 | 2014-08-20 15:53:20 +0200 | [diff] [blame] | 460 | int32_t panel_width = 0, panel_height = 0; |
| 461 | |
Derek Foreman | f814c5d | 2015-04-15 12:23:54 -0500 | [diff] [blame] | 462 | area->x = output->x; |
| 463 | area->y = output->y; |
Jonny Lamb | d73c694 | 2014-08-20 15:53:20 +0200 | [diff] [blame] | 464 | |
| 465 | get_output_panel_size(shell, output, &panel_width, &panel_height); |
Jonny Lamb | d73c694 | 2014-08-20 15:53:20 +0200 | [diff] [blame] | 466 | switch (shell->panel_position) { |
Jonas Ådahl | 6d6fb61 | 2015-11-17 16:00:33 +0800 | [diff] [blame] | 467 | case WESTON_DESKTOP_SHELL_PANEL_POSITION_TOP: |
Jonny Lamb | d73c694 | 2014-08-20 15:53:20 +0200 | [diff] [blame] | 468 | default: |
Derek Foreman | f814c5d | 2015-04-15 12:23:54 -0500 | [diff] [blame] | 469 | area->y += panel_height; |
Jonas Ådahl | 6d6fb61 | 2015-11-17 16:00:33 +0800 | [diff] [blame] | 470 | case WESTON_DESKTOP_SHELL_PANEL_POSITION_BOTTOM: |
Jonny Lamb | d73c694 | 2014-08-20 15:53:20 +0200 | [diff] [blame] | 471 | area->width = output->width; |
| 472 | area->height = output->height - panel_height; |
| 473 | break; |
Jonas Ådahl | 6d6fb61 | 2015-11-17 16:00:33 +0800 | [diff] [blame] | 474 | case WESTON_DESKTOP_SHELL_PANEL_POSITION_LEFT: |
Derek Foreman | f814c5d | 2015-04-15 12:23:54 -0500 | [diff] [blame] | 475 | area->x += panel_width; |
Jonas Ådahl | 6d6fb61 | 2015-11-17 16:00:33 +0800 | [diff] [blame] | 476 | case WESTON_DESKTOP_SHELL_PANEL_POSITION_RIGHT: |
Jonny Lamb | d73c694 | 2014-08-20 15:53:20 +0200 | [diff] [blame] | 477 | area->width = output->width - panel_width; |
| 478 | area->height = output->height; |
| 479 | break; |
| 480 | } |
Jasper St. Pierre | 6458ec3 | 2014-04-11 16:00:31 -0700 | [diff] [blame] | 481 | } |
| 482 | |
Derek Foreman | 45a7c27 | 2015-09-11 14:27:40 -0500 | [diff] [blame] | 483 | static struct shell_surface * |
| 484 | find_toplevel_surface(struct shell_surface *in_surface) |
| 485 | { |
| 486 | struct shell_surface *surface = in_surface; |
| 487 | |
Ben Hummon | 445e44c | 2015-10-06 11:48:14 -0500 | [diff] [blame] | 488 | while (surface) { |
| 489 | if (surface->type == SHELL_SURFACE_TOPLEVEL) |
| 490 | return surface; |
Derek Foreman | 45a7c27 | 2015-09-11 14:27:40 -0500 | [diff] [blame] | 491 | surface = get_shell_surface(surface->parent); |
Ben Hummon | 445e44c | 2015-10-06 11:48:14 -0500 | [diff] [blame] | 492 | } |
Derek Foreman | 45a7c27 | 2015-09-11 14:27:40 -0500 | [diff] [blame] | 493 | |
| 494 | /* If no top level surface was found, just use whatever surface was |
| 495 | originally provided. */ |
Ben Hummon | 445e44c | 2015-10-06 11:48:14 -0500 | [diff] [blame] | 496 | return in_surface; |
Derek Foreman | 45a7c27 | 2015-09-11 14:27:40 -0500 | [diff] [blame] | 497 | } |
| 498 | |
Jasper St. Pierre | 6458ec3 | 2014-04-11 16:00:31 -0700 | [diff] [blame] | 499 | static void |
| 500 | send_configure_for_surface(struct shell_surface *shsurf) |
| 501 | { |
| 502 | int32_t width, height; |
| 503 | struct surface_state *state; |
| 504 | |
| 505 | if (shsurf->state_requested) |
| 506 | state = &shsurf->requested_state; |
| 507 | else if (shsurf->state_changed) |
| 508 | state = &shsurf->next_state; |
| 509 | else |
| 510 | state = &shsurf->state; |
| 511 | |
| 512 | if (state->fullscreen) { |
| 513 | width = shsurf->output->width; |
| 514 | height = shsurf->output->height; |
| 515 | } else if (state->maximized) { |
| 516 | struct desktop_shell *shell; |
Jonny Lamb | d73c694 | 2014-08-20 15:53:20 +0200 | [diff] [blame] | 517 | pixman_rectangle32_t area; |
Jasper St. Pierre | 6458ec3 | 2014-04-11 16:00:31 -0700 | [diff] [blame] | 518 | |
| 519 | shell = shell_surface_get_shell(shsurf); |
Jonny Lamb | d73c694 | 2014-08-20 15:53:20 +0200 | [diff] [blame] | 520 | get_output_work_area(shell, shsurf->output, &area); |
Jasper St. Pierre | 6458ec3 | 2014-04-11 16:00:31 -0700 | [diff] [blame] | 521 | |
Jonny Lamb | d73c694 | 2014-08-20 15:53:20 +0200 | [diff] [blame] | 522 | width = area.width; |
| 523 | height = area.height; |
Ryo Munakata | 79954ec | 2015-05-02 21:44:04 +0900 | [diff] [blame] | 524 | } else if (shsurf->resize_edges) { |
| 525 | width = shsurf->geometry.width; |
| 526 | height = shsurf->geometry.height; |
Jasper St. Pierre | 6458ec3 | 2014-04-11 16:00:31 -0700 | [diff] [blame] | 527 | } else { |
| 528 | width = 0; |
| 529 | height = 0; |
| 530 | } |
| 531 | |
| 532 | shsurf->client->send_configure(shsurf->surface, width, height); |
| 533 | } |
| 534 | |
Ander Conselvan de Oliveira | fe0444a | 2012-04-04 17:48:05 +0300 | [diff] [blame] | 535 | static void |
Jasper St. Pierre | 5befdda | 2014-05-06 08:50:47 -0400 | [diff] [blame] | 536 | shell_surface_state_changed(struct shell_surface *shsurf) |
| 537 | { |
Jasper St. Pierre | 6458ec3 | 2014-04-11 16:00:31 -0700 | [diff] [blame] | 538 | if (shell_surface_is_xdg_surface(shsurf)) |
| 539 | send_configure_for_surface(shsurf); |
Jasper St. Pierre | 5befdda | 2014-05-06 08:50:47 -0400 | [diff] [blame] | 540 | } |
| 541 | |
| 542 | static void |
Ander Conselvan de Oliveira | b9d2a0f | 2012-06-28 18:08:05 +0300 | [diff] [blame] | 543 | shell_grab_end(struct shell_grab *grab) |
Ander Conselvan de Oliveira | fe0444a | 2012-04-04 17:48:05 +0300 | [diff] [blame] | 544 | { |
Kristian Høgsberg | c85f1d4 | 2013-10-24 16:52:00 -0700 | [diff] [blame] | 545 | if (grab->shsurf) { |
Kristian Høgsberg | 47b5dca | 2012-06-07 18:08:04 -0400 | [diff] [blame] | 546 | wl_list_remove(&grab->shsurf_destroy_listener.link); |
Kristian Høgsberg | c85f1d4 | 2013-10-24 16:52:00 -0700 | [diff] [blame] | 547 | grab->shsurf->grabbed = 0; |
Jasper St. Pierre | 5befdda | 2014-05-06 08:50:47 -0400 | [diff] [blame] | 548 | |
| 549 | if (grab->shsurf->resize_edges) { |
| 550 | grab->shsurf->resize_edges = 0; |
| 551 | shell_surface_state_changed(grab->shsurf); |
| 552 | } |
Kristian Høgsberg | c85f1d4 | 2013-10-24 16:52:00 -0700 | [diff] [blame] | 553 | } |
Ander Conselvan de Oliveira | b9d2a0f | 2012-06-28 18:08:05 +0300 | [diff] [blame] | 554 | |
Kristian Høgsberg | 9e5d7d1 | 2013-07-22 16:31:53 -0700 | [diff] [blame] | 555 | weston_pointer_end_grab(grab->grab.pointer); |
Ander Conselvan de Oliveira | fe0444a | 2012-04-04 17:48:05 +0300 | [diff] [blame] | 556 | } |
| 557 | |
| 558 | static void |
Rusty Lynch | 1084da5 | 2013-08-15 09:10:08 -0700 | [diff] [blame] | 559 | shell_touch_grab_start(struct shell_touch_grab *grab, |
| 560 | const struct weston_touch_grab_interface *interface, |
| 561 | struct shell_surface *shsurf, |
| 562 | struct weston_touch *touch) |
| 563 | { |
| 564 | struct desktop_shell *shell = shsurf->shell; |
Derek Foreman | 1281a36 | 2015-07-31 16:55:32 -0500 | [diff] [blame] | 565 | struct weston_pointer *pointer = weston_seat_get_pointer(touch->seat); |
U. Artie Eoff | cf5737a | 2014-01-17 10:08:25 -0800 | [diff] [blame] | 566 | |
Jonny Lamb | 76cf1fe | 2014-08-20 11:27:10 +0200 | [diff] [blame] | 567 | touch_popup_grab_end(touch); |
Derek Foreman | 1281a36 | 2015-07-31 16:55:32 -0500 | [diff] [blame] | 568 | if (pointer) |
| 569 | popup_grab_end(pointer); |
Kristian Høgsberg | 74071e0 | 2014-04-29 15:01:16 -0700 | [diff] [blame] | 570 | |
Rusty Lynch | 1084da5 | 2013-08-15 09:10:08 -0700 | [diff] [blame] | 571 | grab->grab.interface = interface; |
| 572 | grab->shsurf = shsurf; |
| 573 | grab->shsurf_destroy_listener.notify = destroy_shell_grab_shsurf; |
| 574 | wl_signal_add(&shsurf->destroy_signal, |
| 575 | &grab->shsurf_destroy_listener); |
| 576 | |
| 577 | grab->touch = touch; |
Kristian Høgsberg | c85f1d4 | 2013-10-24 16:52:00 -0700 | [diff] [blame] | 578 | shsurf->grabbed = 1; |
Rusty Lynch | 1084da5 | 2013-08-15 09:10:08 -0700 | [diff] [blame] | 579 | |
| 580 | weston_touch_start_grab(touch, &grab->grab); |
| 581 | if (shell->child.desktop_shell) |
Derek Foreman | 4c93c08 | 2015-04-30 16:45:41 -0500 | [diff] [blame] | 582 | weston_touch_set_focus(touch, |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 583 | get_default_view(shell->grab_surface)); |
Rusty Lynch | 1084da5 | 2013-08-15 09:10:08 -0700 | [diff] [blame] | 584 | } |
| 585 | |
| 586 | static void |
| 587 | shell_touch_grab_end(struct shell_touch_grab *grab) |
| 588 | { |
Kristian Høgsberg | c85f1d4 | 2013-10-24 16:52:00 -0700 | [diff] [blame] | 589 | if (grab->shsurf) { |
Rusty Lynch | 1084da5 | 2013-08-15 09:10:08 -0700 | [diff] [blame] | 590 | wl_list_remove(&grab->shsurf_destroy_listener.link); |
Kristian Høgsberg | c85f1d4 | 2013-10-24 16:52:00 -0700 | [diff] [blame] | 591 | grab->shsurf->grabbed = 0; |
| 592 | } |
Rusty Lynch | 1084da5 | 2013-08-15 09:10:08 -0700 | [diff] [blame] | 593 | |
| 594 | weston_touch_end_grab(grab->touch); |
| 595 | } |
| 596 | |
| 597 | static void |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 598 | center_on_output(struct weston_view *view, |
Alex Wu | 4539b08 | 2012-03-01 12:57:46 +0800 | [diff] [blame] | 599 | struct weston_output *output); |
| 600 | |
Daniel Stone | 496ca17 | 2012-05-30 16:31:42 +0100 | [diff] [blame] | 601 | static enum weston_keyboard_modifier |
Tiago Vignatti | 0b52d48 | 2012-04-20 18:54:25 +0300 | [diff] [blame] | 602 | get_modifier(char *modifier) |
| 603 | { |
| 604 | if (!modifier) |
| 605 | return MODIFIER_SUPER; |
| 606 | |
| 607 | if (!strcmp("ctrl", modifier)) |
| 608 | return MODIFIER_CTRL; |
| 609 | else if (!strcmp("alt", modifier)) |
| 610 | return MODIFIER_ALT; |
| 611 | else if (!strcmp("super", modifier)) |
| 612 | return MODIFIER_SUPER; |
Bob Ham | 553d124 | 2016-01-12 10:21:49 +0000 | [diff] [blame] | 613 | else if (!strcmp("none", modifier)) |
| 614 | return 0; |
Tiago Vignatti | 0b52d48 | 2012-04-20 18:54:25 +0300 | [diff] [blame] | 615 | else |
| 616 | return MODIFIER_SUPER; |
| 617 | } |
| 618 | |
Juan Zhao | e10d279 | 2012-04-25 19:09:52 +0800 | [diff] [blame] | 619 | static enum animation_type |
| 620 | get_animation_type(char *animation) |
| 621 | { |
U. Artie Eoff | b571910 | 2014-01-15 14:26:31 -0800 | [diff] [blame] | 622 | if (!animation) |
| 623 | return ANIMATION_NONE; |
| 624 | |
Juan Zhao | e10d279 | 2012-04-25 19:09:52 +0800 | [diff] [blame] | 625 | if (!strcmp("zoom", animation)) |
| 626 | return ANIMATION_ZOOM; |
| 627 | else if (!strcmp("fade", animation)) |
| 628 | return ANIMATION_FADE; |
Louis-Francis Ratté-Boulianne | b482dbd | 2013-11-19 11:37:11 +0100 | [diff] [blame] | 629 | else if (!strcmp("dim-layer", animation)) |
| 630 | return ANIMATION_DIM_LAYER; |
Juan Zhao | e10d279 | 2012-04-25 19:09:52 +0800 | [diff] [blame] | 631 | else |
| 632 | return ANIMATION_NONE; |
| 633 | } |
| 634 | |
Alex Wu | 4539b08 | 2012-03-01 12:57:46 +0800 | [diff] [blame] | 635 | static void |
Kristian Høgsberg | 14e438c | 2013-05-26 21:48:14 -0400 | [diff] [blame] | 636 | shell_configuration(struct desktop_shell *shell) |
Pekka Paalanen | e955f1e | 2011-12-07 11:49:52 +0200 | [diff] [blame] | 637 | { |
Kristian Høgsberg | 673a889 | 2013-05-23 21:40:56 -0400 | [diff] [blame] | 638 | struct weston_config_section *section; |
Derek Foreman | c721043 | 2014-08-21 11:32:38 -0500 | [diff] [blame] | 639 | char *s, *client; |
Pekka Paalanen | 974c094 | 2014-09-05 14:45:09 +0300 | [diff] [blame] | 640 | int ret; |
Bob Ham | 744e653 | 2016-01-12 10:21:48 +0000 | [diff] [blame] | 641 | int allow_zap; |
Pekka Paalanen | e955f1e | 2011-12-07 11:49:52 +0200 | [diff] [blame] | 642 | |
Giulio Camuffo | d52f3b7 | 2016-06-02 21:48:11 +0300 | [diff] [blame] | 643 | section = weston_config_get_section(wet_get_config(shell->compositor), |
Kristian Høgsberg | 673a889 | 2013-05-23 21:40:56 -0400 | [diff] [blame] | 644 | "shell", NULL, NULL); |
Pekka Paalanen | 974c094 | 2014-09-05 14:45:09 +0300 | [diff] [blame] | 645 | ret = asprintf(&client, "%s/%s", weston_config_get_libexec_dir(), |
| 646 | WESTON_SHELL_CLIENT); |
| 647 | if (ret < 0) |
| 648 | client = NULL; |
Kristian Høgsberg | 673a889 | 2013-05-23 21:40:56 -0400 | [diff] [blame] | 649 | weston_config_section_get_string(section, |
Derek Foreman | c721043 | 2014-08-21 11:32:38 -0500 | [diff] [blame] | 650 | "client", &s, client); |
| 651 | free(client); |
Emilio Pozuelo Monfort | 46ce798 | 2013-11-20 13:22:29 +0100 | [diff] [blame] | 652 | shell->client = s; |
Bob Ham | 744e653 | 2016-01-12 10:21:48 +0000 | [diff] [blame] | 653 | |
| 654 | weston_config_section_get_bool(section, |
| 655 | "allow-zap", &allow_zap, true); |
| 656 | shell->allow_zap = allow_zap; |
| 657 | |
Emilio Pozuelo Monfort | 46ce798 | 2013-11-20 13:22:29 +0100 | [diff] [blame] | 658 | weston_config_section_get_string(section, |
Kristian Høgsberg | 673a889 | 2013-05-23 21:40:56 -0400 | [diff] [blame] | 659 | "binding-modifier", &s, "super"); |
| 660 | shell->binding_modifier = get_modifier(s); |
Quentin Glidic | 8418c29 | 2013-06-18 09:11:03 +0200 | [diff] [blame] | 661 | free(s); |
Kristian Høgsberg | d56ab4e | 2014-01-16 16:51:52 -0800 | [diff] [blame] | 662 | |
| 663 | weston_config_section_get_string(section, |
| 664 | "exposay-modifier", &s, "none"); |
Bob Ham | 553d124 | 2016-01-12 10:21:49 +0000 | [diff] [blame] | 665 | shell->exposay_modifier = get_modifier(s); |
Kristian Høgsberg | d56ab4e | 2014-01-16 16:51:52 -0800 | [diff] [blame] | 666 | free(s); |
| 667 | |
Kristian Høgsberg | 673a889 | 2013-05-23 21:40:56 -0400 | [diff] [blame] | 668 | weston_config_section_get_string(section, "animation", &s, "none"); |
| 669 | shell->win_animation_type = get_animation_type(s); |
Quentin Glidic | 8418c29 | 2013-06-18 09:11:03 +0200 | [diff] [blame] | 670 | free(s); |
Jonny Lamb | f322f8e | 2014-08-12 15:13:30 +0200 | [diff] [blame] | 671 | weston_config_section_get_string(section, "close-animation", &s, "fade"); |
| 672 | shell->win_close_animation_type = get_animation_type(s); |
| 673 | free(s); |
Kristian Høgsberg | 724c8d9 | 2013-10-16 11:38:24 -0700 | [diff] [blame] | 674 | weston_config_section_get_string(section, |
| 675 | "startup-animation", &s, "fade"); |
| 676 | shell->startup_animation_type = get_animation_type(s); |
| 677 | free(s); |
Kristian Høgsberg | 912e0a1 | 2013-10-30 08:59:55 -0700 | [diff] [blame] | 678 | if (shell->startup_animation_type == ANIMATION_ZOOM) |
| 679 | shell->startup_animation_type = ANIMATION_NONE; |
Louis-Francis Ratté-Boulianne | b482dbd | 2013-11-19 11:37:11 +0100 | [diff] [blame] | 680 | weston_config_section_get_string(section, "focus-animation", &s, "none"); |
| 681 | shell->focus_animation_type = get_animation_type(s); |
| 682 | free(s); |
Kristian Høgsberg | 673a889 | 2013-05-23 21:40:56 -0400 | [diff] [blame] | 683 | weston_config_section_get_uint(section, "num-workspaces", |
| 684 | &shell->workspaces.num, |
| 685 | DEFAULT_NUM_WORKSPACES); |
Jonas Ådahl | e3cddce | 2012-06-13 00:01:22 +0200 | [diff] [blame] | 686 | } |
| 687 | |
Kristian Høgsberg | 1ef2313 | 2013-12-04 00:20:01 -0800 | [diff] [blame] | 688 | struct weston_output * |
Louis-Francis Ratté-Boulianne | b482dbd | 2013-11-19 11:37:11 +0100 | [diff] [blame] | 689 | get_default_output(struct weston_compositor *compositor) |
| 690 | { |
Armin Krezović | 10b0618 | 2016-06-23 11:59:30 +0200 | [diff] [blame] | 691 | if (wl_list_empty(&compositor->output_list)) |
| 692 | return NULL; |
| 693 | |
Louis-Francis Ratté-Boulianne | b482dbd | 2013-11-19 11:37:11 +0100 | [diff] [blame] | 694 | return container_of(compositor->output_list.next, |
| 695 | struct weston_output, link); |
| 696 | } |
| 697 | |
Pekka Paalanen | 8274d90 | 2014-08-06 19:36:51 +0300 | [diff] [blame] | 698 | static int |
| 699 | focus_surface_get_label(struct weston_surface *surface, char *buf, size_t len) |
| 700 | { |
| 701 | return snprintf(buf, len, "focus highlight effect for output %s", |
| 702 | surface->output->name); |
| 703 | } |
Louis-Francis Ratté-Boulianne | b482dbd | 2013-11-19 11:37:11 +0100 | [diff] [blame] | 704 | |
| 705 | /* no-op func for checking focus surface */ |
| 706 | static void |
Jason Ekstrand | 918f2dd | 2013-12-02 21:01:53 -0600 | [diff] [blame] | 707 | 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] | 708 | { |
| 709 | } |
| 710 | |
| 711 | static struct focus_surface * |
| 712 | get_focus_surface(struct weston_surface *surface) |
| 713 | { |
| 714 | if (surface->configure == focus_surface_configure) |
| 715 | return surface->configure_private; |
| 716 | else |
| 717 | return NULL; |
| 718 | } |
| 719 | |
| 720 | static bool |
| 721 | is_focus_surface (struct weston_surface *es) |
| 722 | { |
| 723 | return (es->configure == focus_surface_configure); |
| 724 | } |
| 725 | |
| 726 | static bool |
| 727 | is_focus_view (struct weston_view *view) |
| 728 | { |
| 729 | return is_focus_surface (view->surface); |
| 730 | } |
| 731 | |
| 732 | static struct focus_surface * |
| 733 | create_focus_surface(struct weston_compositor *ec, |
| 734 | struct weston_output *output) |
| 735 | { |
| 736 | struct focus_surface *fsurf = NULL; |
| 737 | struct weston_surface *surface = NULL; |
| 738 | |
| 739 | fsurf = malloc(sizeof *fsurf); |
| 740 | if (!fsurf) |
| 741 | return NULL; |
| 742 | |
| 743 | fsurf->surface = weston_surface_create(ec); |
| 744 | surface = fsurf->surface; |
| 745 | if (surface == NULL) { |
| 746 | free(fsurf); |
| 747 | return NULL; |
| 748 | } |
| 749 | |
| 750 | surface->configure = focus_surface_configure; |
| 751 | surface->output = output; |
Armin Krezović | 4663aca | 2016-06-30 06:04:29 +0200 | [diff] [blame] | 752 | surface->is_mapped = true; |
Louis-Francis Ratté-Boulianne | b482dbd | 2013-11-19 11:37:11 +0100 | [diff] [blame] | 753 | surface->configure_private = fsurf; |
Pekka Paalanen | 8274d90 | 2014-08-06 19:36:51 +0300 | [diff] [blame] | 754 | weston_surface_set_label_func(surface, focus_surface_get_label); |
Louis-Francis Ratté-Boulianne | b482dbd | 2013-11-19 11:37:11 +0100 | [diff] [blame] | 755 | |
U. Artie Eoff | 0b23b2b | 2014-01-15 14:45:59 -0800 | [diff] [blame] | 756 | fsurf->view = weston_view_create(surface); |
| 757 | if (fsurf->view == NULL) { |
| 758 | weston_surface_destroy(surface); |
| 759 | free(fsurf); |
| 760 | return NULL; |
| 761 | } |
Emilio Pozuelo Monfort | da64426 | 2013-11-19 11:37:19 +0100 | [diff] [blame] | 762 | fsurf->view->output = output; |
Armin Krezović | 4663aca | 2016-06-30 06:04:29 +0200 | [diff] [blame] | 763 | fsurf->view->is_mapped = true; |
Louis-Francis Ratté-Boulianne | b482dbd | 2013-11-19 11:37:11 +0100 | [diff] [blame] | 764 | |
Jason Ekstrand | 5c11a33 | 2013-12-04 20:32:03 -0600 | [diff] [blame] | 765 | weston_surface_set_size(surface, output->width, output->height); |
Jason Ekstrand | 918f2dd | 2013-12-02 21:01:53 -0600 | [diff] [blame] | 766 | weston_view_set_position(fsurf->view, output->x, output->y); |
Louis-Francis Ratté-Boulianne | b482dbd | 2013-11-19 11:37:11 +0100 | [diff] [blame] | 767 | weston_surface_set_color(surface, 0.0, 0.0, 0.0, 1.0); |
| 768 | pixman_region32_fini(&surface->opaque); |
| 769 | pixman_region32_init_rect(&surface->opaque, output->x, output->y, |
| 770 | output->width, output->height); |
| 771 | pixman_region32_fini(&surface->input); |
| 772 | pixman_region32_init(&surface->input); |
| 773 | |
| 774 | wl_list_init(&fsurf->workspace_transform.link); |
| 775 | |
| 776 | return fsurf; |
| 777 | } |
| 778 | |
| 779 | static void |
| 780 | focus_surface_destroy(struct focus_surface *fsurf) |
| 781 | { |
| 782 | weston_surface_destroy(fsurf->surface); |
| 783 | free(fsurf); |
| 784 | } |
| 785 | |
| 786 | static void |
| 787 | focus_animation_done(struct weston_view_animation *animation, void *data) |
| 788 | { |
| 789 | struct workspace *ws = data; |
| 790 | |
| 791 | ws->focus_animation = NULL; |
| 792 | } |
| 793 | |
Jonas Ådahl | e3cddce | 2012-06-13 00:01:22 +0200 | [diff] [blame] | 794 | static void |
Jonas Ådahl | 0476974 | 2012-06-13 00:01:24 +0200 | [diff] [blame] | 795 | focus_state_destroy(struct focus_state *state) |
| 796 | { |
| 797 | wl_list_remove(&state->seat_destroy_listener.link); |
| 798 | wl_list_remove(&state->surface_destroy_listener.link); |
| 799 | free(state); |
| 800 | } |
| 801 | |
| 802 | static void |
| 803 | focus_state_seat_destroy(struct wl_listener *listener, void *data) |
| 804 | { |
| 805 | struct focus_state *state = container_of(listener, |
| 806 | struct focus_state, |
| 807 | seat_destroy_listener); |
| 808 | |
| 809 | wl_list_remove(&state->link); |
| 810 | focus_state_destroy(state); |
| 811 | } |
| 812 | |
| 813 | static void |
| 814 | focus_state_surface_destroy(struct wl_listener *listener, void *data) |
| 815 | { |
| 816 | struct focus_state *state = container_of(listener, |
| 817 | struct focus_state, |
Kristian Høgsberg | b8e0d0f | 2012-07-31 10:30:26 -0400 | [diff] [blame] | 818 | surface_destroy_listener); |
Kristian Høgsberg | e377822 | 2012-07-31 17:29:30 -0400 | [diff] [blame] | 819 | struct desktop_shell *shell; |
Jonas Ådahl | 1fa6ded | 2014-10-18 13:24:53 +0200 | [diff] [blame^] | 820 | struct weston_surface *main_surface; |
| 821 | struct weston_view *next; |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 822 | struct weston_view *view; |
Jonas Ådahl | 0476974 | 2012-06-13 00:01:24 +0200 | [diff] [blame] | 823 | |
Pekka Paalanen | 01388e2 | 2013-04-25 13:57:44 +0300 | [diff] [blame] | 824 | main_surface = weston_surface_get_main_surface(state->keyboard_focus); |
| 825 | |
Kristian Høgsberg | e377822 | 2012-07-31 17:29:30 -0400 | [diff] [blame] | 826 | next = NULL; |
Giulio Camuffo | 412e6a5 | 2014-07-09 22:12:56 +0300 | [diff] [blame] | 827 | wl_list_for_each(view, |
| 828 | &state->ws->layer.view_list.link, layer_link.link) { |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 829 | if (view->surface == main_surface) |
Kristian Høgsberg | e377822 | 2012-07-31 17:29:30 -0400 | [diff] [blame] | 830 | continue; |
Louis-Francis Ratté-Boulianne | b482dbd | 2013-11-19 11:37:11 +0100 | [diff] [blame] | 831 | if (is_focus_view(view)) |
| 832 | continue; |
Kristian Høgsberg | e377822 | 2012-07-31 17:29:30 -0400 | [diff] [blame] | 833 | |
Jonas Ådahl | 1fa6ded | 2014-10-18 13:24:53 +0200 | [diff] [blame^] | 834 | next = view; |
Kristian Høgsberg | e377822 | 2012-07-31 17:29:30 -0400 | [diff] [blame] | 835 | break; |
| 836 | } |
| 837 | |
Pekka Paalanen | 01388e2 | 2013-04-25 13:57:44 +0300 | [diff] [blame] | 838 | /* if the focus was a sub-surface, activate its main surface */ |
| 839 | if (main_surface != state->keyboard_focus) |
Jonas Ådahl | 1fa6ded | 2014-10-18 13:24:53 +0200 | [diff] [blame^] | 840 | next = get_default_view(main_surface); |
Pekka Paalanen | 01388e2 | 2013-04-25 13:57:44 +0300 | [diff] [blame] | 841 | |
Louis-Francis Ratté-Boulianne | b482dbd | 2013-11-19 11:37:11 +0100 | [diff] [blame] | 842 | shell = state->seat->compositor->shell_interface.shell; |
Kristian Høgsberg | e377822 | 2012-07-31 17:29:30 -0400 | [diff] [blame] | 843 | if (next) { |
Louis-Francis Ratté-Boulianne | b482dbd | 2013-11-19 11:37:11 +0100 | [diff] [blame] | 844 | state->keyboard_focus = NULL; |
Emilio Pozuelo Monfort | 9e7c759 | 2014-01-30 14:01:10 +0100 | [diff] [blame] | 845 | activate(shell, next, state->seat, true); |
Kristian Høgsberg | e377822 | 2012-07-31 17:29:30 -0400 | [diff] [blame] | 846 | } else { |
Louis-Francis Ratté-Boulianne | b482dbd | 2013-11-19 11:37:11 +0100 | [diff] [blame] | 847 | if (shell->focus_animation_type == ANIMATION_DIM_LAYER) { |
| 848 | if (state->ws->focus_animation) |
| 849 | weston_view_animation_destroy(state->ws->focus_animation); |
| 850 | |
| 851 | state->ws->focus_animation = weston_fade_run( |
| 852 | state->ws->fsurf_front->view, |
| 853 | state->ws->fsurf_front->view->alpha, 0.0, 300, |
| 854 | focus_animation_done, state->ws); |
| 855 | } |
| 856 | |
Kristian Høgsberg | e377822 | 2012-07-31 17:29:30 -0400 | [diff] [blame] | 857 | wl_list_remove(&state->link); |
| 858 | focus_state_destroy(state); |
| 859 | } |
Jonas Ådahl | 0476974 | 2012-06-13 00:01:24 +0200 | [diff] [blame] | 860 | } |
| 861 | |
| 862 | static struct focus_state * |
Kristian Høgsberg | 2f5faff | 2012-07-31 16:36:34 -0400 | [diff] [blame] | 863 | focus_state_create(struct weston_seat *seat, struct workspace *ws) |
Jonas Ådahl | 0476974 | 2012-06-13 00:01:24 +0200 | [diff] [blame] | 864 | { |
Jonas Ådahl | 0476974 | 2012-06-13 00:01:24 +0200 | [diff] [blame] | 865 | struct focus_state *state; |
Jonas Ådahl | 0476974 | 2012-06-13 00:01:24 +0200 | [diff] [blame] | 866 | |
| 867 | state = malloc(sizeof *state); |
| 868 | if (state == NULL) |
| 869 | return NULL; |
| 870 | |
Louis-Francis Ratté-Boulianne | b482dbd | 2013-11-19 11:37:11 +0100 | [diff] [blame] | 871 | state->keyboard_focus = NULL; |
Kristian Høgsberg | 2f5faff | 2012-07-31 16:36:34 -0400 | [diff] [blame] | 872 | state->ws = ws; |
Jonas Ådahl | 0476974 | 2012-06-13 00:01:24 +0200 | [diff] [blame] | 873 | state->seat = seat; |
Kristian Høgsberg | 2f5faff | 2012-07-31 16:36:34 -0400 | [diff] [blame] | 874 | wl_list_insert(&ws->focus_list, &state->link); |
Jonas Ådahl | 0476974 | 2012-06-13 00:01:24 +0200 | [diff] [blame] | 875 | |
| 876 | state->seat_destroy_listener.notify = focus_state_seat_destroy; |
| 877 | state->surface_destroy_listener.notify = focus_state_surface_destroy; |
Kristian Høgsberg | 4912454 | 2013-05-06 22:27:40 -0400 | [diff] [blame] | 878 | wl_signal_add(&seat->destroy_signal, |
Jonas Ådahl | 0476974 | 2012-06-13 00:01:24 +0200 | [diff] [blame] | 879 | &state->seat_destroy_listener); |
Kristian Høgsberg | 2f5faff | 2012-07-31 16:36:34 -0400 | [diff] [blame] | 880 | wl_list_init(&state->surface_destroy_listener.link); |
Jonas Ådahl | 0476974 | 2012-06-13 00:01:24 +0200 | [diff] [blame] | 881 | |
| 882 | return state; |
| 883 | } |
| 884 | |
Jonas Ådahl | 8538b22 | 2012-08-29 22:13:03 +0200 | [diff] [blame] | 885 | static struct focus_state * |
| 886 | ensure_focus_state(struct desktop_shell *shell, struct weston_seat *seat) |
| 887 | { |
| 888 | struct workspace *ws = get_current_workspace(shell); |
| 889 | struct focus_state *state; |
| 890 | |
| 891 | wl_list_for_each(state, &ws->focus_list, link) |
| 892 | if (state->seat == seat) |
| 893 | break; |
| 894 | |
| 895 | if (&state->link == &ws->focus_list) |
| 896 | state = focus_state_create(seat, ws); |
| 897 | |
| 898 | return state; |
| 899 | } |
| 900 | |
Jonas Ådahl | 0476974 | 2012-06-13 00:01:24 +0200 | [diff] [blame] | 901 | static void |
Kristian Høgsberg | d500bf1 | 2014-01-22 12:25:20 -0800 | [diff] [blame] | 902 | focus_state_set_focus(struct focus_state *state, |
| 903 | struct weston_surface *surface) |
| 904 | { |
| 905 | if (state->keyboard_focus) { |
| 906 | wl_list_remove(&state->surface_destroy_listener.link); |
| 907 | wl_list_init(&state->surface_destroy_listener.link); |
| 908 | } |
| 909 | |
| 910 | state->keyboard_focus = surface; |
| 911 | if (surface) |
| 912 | wl_signal_add(&surface->destroy_signal, |
| 913 | &state->surface_destroy_listener); |
| 914 | } |
| 915 | |
| 916 | static void |
Kristian Høgsberg | 2f5faff | 2012-07-31 16:36:34 -0400 | [diff] [blame] | 917 | restore_focus_state(struct desktop_shell *shell, struct workspace *ws) |
Jonas Ådahl | 0476974 | 2012-06-13 00:01:24 +0200 | [diff] [blame] | 918 | { |
| 919 | struct focus_state *state, *next; |
Kristian Høgsberg | fe7aa90 | 2013-05-08 09:54:37 -0400 | [diff] [blame] | 920 | struct weston_surface *surface; |
Neil Roberts | 4237f50 | 2014-04-09 16:33:31 +0100 | [diff] [blame] | 921 | struct wl_list pending_seat_list; |
| 922 | struct weston_seat *seat, *next_seat; |
| 923 | |
| 924 | /* Temporarily steal the list of seats so that we can keep |
| 925 | * track of the seats we've already processed */ |
| 926 | wl_list_init(&pending_seat_list); |
| 927 | wl_list_insert_list(&pending_seat_list, &shell->compositor->seat_list); |
| 928 | wl_list_init(&shell->compositor->seat_list); |
Jonas Ådahl | 0476974 | 2012-06-13 00:01:24 +0200 | [diff] [blame] | 929 | |
| 930 | wl_list_for_each_safe(state, next, &ws->focus_list, link) { |
Derek Foreman | 1281a36 | 2015-07-31 16:55:32 -0500 | [diff] [blame] | 931 | struct weston_keyboard *keyboard = |
| 932 | weston_seat_get_keyboard(state->seat); |
| 933 | |
Neil Roberts | 4237f50 | 2014-04-09 16:33:31 +0100 | [diff] [blame] | 934 | wl_list_remove(&state->seat->link); |
| 935 | wl_list_insert(&shell->compositor->seat_list, |
| 936 | &state->seat->link); |
| 937 | |
Derek Foreman | 1281a36 | 2015-07-31 16:55:32 -0500 | [diff] [blame] | 938 | if (!keyboard) |
Kristian Høgsberg | e61d2f4 | 2014-01-17 12:18:53 -0800 | [diff] [blame] | 939 | continue; |
| 940 | |
Kristian Høgsberg | fe7aa90 | 2013-05-08 09:54:37 -0400 | [diff] [blame] | 941 | surface = state->keyboard_focus; |
Jonas Ådahl | 5689944 | 2012-08-29 22:12:59 +0200 | [diff] [blame] | 942 | |
Derek Foreman | 1281a36 | 2015-07-31 16:55:32 -0500 | [diff] [blame] | 943 | weston_keyboard_set_focus(keyboard, surface); |
Jonas Ådahl | 0476974 | 2012-06-13 00:01:24 +0200 | [diff] [blame] | 944 | } |
Neil Roberts | 4237f50 | 2014-04-09 16:33:31 +0100 | [diff] [blame] | 945 | |
| 946 | /* For any remaining seats that we don't have a focus state |
| 947 | * for we'll reset the keyboard focus to NULL */ |
| 948 | wl_list_for_each_safe(seat, next_seat, &pending_seat_list, link) { |
Derek Foreman | 1281a36 | 2015-07-31 16:55:32 -0500 | [diff] [blame] | 949 | struct weston_keyboard *keyboard = |
| 950 | weston_seat_get_keyboard(seat); |
| 951 | |
Neil Roberts | 4237f50 | 2014-04-09 16:33:31 +0100 | [diff] [blame] | 952 | wl_list_insert(&shell->compositor->seat_list, &seat->link); |
| 953 | |
Derek Foreman | 1281a36 | 2015-07-31 16:55:32 -0500 | [diff] [blame] | 954 | if (!keyboard) |
Neil Roberts | 4237f50 | 2014-04-09 16:33:31 +0100 | [diff] [blame] | 955 | continue; |
| 956 | |
Derek Foreman | 1281a36 | 2015-07-31 16:55:32 -0500 | [diff] [blame] | 957 | weston_keyboard_set_focus(keyboard, NULL); |
Neil Roberts | 4237f50 | 2014-04-09 16:33:31 +0100 | [diff] [blame] | 958 | } |
Jonas Ådahl | 0476974 | 2012-06-13 00:01:24 +0200 | [diff] [blame] | 959 | } |
| 960 | |
| 961 | static void |
Jonas Ådahl | 8de6a1d | 2012-08-29 22:13:00 +0200 | [diff] [blame] | 962 | replace_focus_state(struct desktop_shell *shell, struct workspace *ws, |
| 963 | struct weston_seat *seat) |
| 964 | { |
Derek Foreman | 1281a36 | 2015-07-31 16:55:32 -0500 | [diff] [blame] | 965 | struct weston_keyboard *keyboard = weston_seat_get_keyboard(seat); |
Jonas Ådahl | 8de6a1d | 2012-08-29 22:13:00 +0200 | [diff] [blame] | 966 | struct focus_state *state; |
Jonas Ådahl | 8de6a1d | 2012-08-29 22:13:00 +0200 | [diff] [blame] | 967 | |
| 968 | wl_list_for_each(state, &ws->focus_list, link) { |
| 969 | if (state->seat == seat) { |
Derek Foreman | 1281a36 | 2015-07-31 16:55:32 -0500 | [diff] [blame] | 970 | focus_state_set_focus(state, keyboard->focus); |
Jonas Ådahl | 8de6a1d | 2012-08-29 22:13:00 +0200 | [diff] [blame] | 971 | return; |
| 972 | } |
| 973 | } |
| 974 | } |
| 975 | |
| 976 | static void |
| 977 | drop_focus_state(struct desktop_shell *shell, struct workspace *ws, |
| 978 | struct weston_surface *surface) |
| 979 | { |
| 980 | struct focus_state *state; |
| 981 | |
| 982 | wl_list_for_each(state, &ws->focus_list, link) |
| 983 | if (state->keyboard_focus == surface) |
Kristian Høgsberg | d500bf1 | 2014-01-22 12:25:20 -0800 | [diff] [blame] | 984 | focus_state_set_focus(state, NULL); |
Jonas Ådahl | 8de6a1d | 2012-08-29 22:13:00 +0200 | [diff] [blame] | 985 | } |
| 986 | |
| 987 | static void |
Louis-Francis Ratté-Boulianne | b482dbd | 2013-11-19 11:37:11 +0100 | [diff] [blame] | 988 | animate_focus_change(struct desktop_shell *shell, struct workspace *ws, |
| 989 | struct weston_view *from, struct weston_view *to) |
| 990 | { |
| 991 | struct weston_output *output; |
| 992 | bool focus_surface_created = false; |
| 993 | |
| 994 | /* FIXME: Only support dim animation using two layers */ |
| 995 | if (from == to || shell->focus_animation_type != ANIMATION_DIM_LAYER) |
| 996 | return; |
| 997 | |
| 998 | output = get_default_output(shell->compositor); |
| 999 | if (ws->fsurf_front == NULL && (from || to)) { |
| 1000 | ws->fsurf_front = create_focus_surface(shell->compositor, output); |
U. Artie Eoff | 0b23b2b | 2014-01-15 14:45:59 -0800 | [diff] [blame] | 1001 | if (ws->fsurf_front == NULL) |
| 1002 | return; |
Louis-Francis Ratté-Boulianne | b482dbd | 2013-11-19 11:37:11 +0100 | [diff] [blame] | 1003 | ws->fsurf_front->view->alpha = 0.0; |
U. Artie Eoff | 0b23b2b | 2014-01-15 14:45:59 -0800 | [diff] [blame] | 1004 | |
| 1005 | ws->fsurf_back = create_focus_surface(shell->compositor, output); |
| 1006 | if (ws->fsurf_back == NULL) { |
| 1007 | focus_surface_destroy(ws->fsurf_front); |
| 1008 | return; |
| 1009 | } |
Louis-Francis Ratté-Boulianne | b482dbd | 2013-11-19 11:37:11 +0100 | [diff] [blame] | 1010 | ws->fsurf_back->view->alpha = 0.0; |
U. Artie Eoff | 0b23b2b | 2014-01-15 14:45:59 -0800 | [diff] [blame] | 1011 | |
Louis-Francis Ratté-Boulianne | b482dbd | 2013-11-19 11:37:11 +0100 | [diff] [blame] | 1012 | focus_surface_created = true; |
| 1013 | } else { |
Giulio Camuffo | 412e6a5 | 2014-07-09 22:12:56 +0300 | [diff] [blame] | 1014 | weston_layer_entry_remove(&ws->fsurf_front->view->layer_link); |
| 1015 | weston_layer_entry_remove(&ws->fsurf_back->view->layer_link); |
Louis-Francis Ratté-Boulianne | b482dbd | 2013-11-19 11:37:11 +0100 | [diff] [blame] | 1016 | } |
| 1017 | |
| 1018 | if (ws->focus_animation) { |
| 1019 | weston_view_animation_destroy(ws->focus_animation); |
| 1020 | ws->focus_animation = NULL; |
| 1021 | } |
| 1022 | |
| 1023 | if (to) |
Giulio Camuffo | 412e6a5 | 2014-07-09 22:12:56 +0300 | [diff] [blame] | 1024 | weston_layer_entry_insert(&to->layer_link, |
| 1025 | &ws->fsurf_front->view->layer_link); |
Louis-Francis Ratté-Boulianne | b482dbd | 2013-11-19 11:37:11 +0100 | [diff] [blame] | 1026 | else if (from) |
Giulio Camuffo | 412e6a5 | 2014-07-09 22:12:56 +0300 | [diff] [blame] | 1027 | weston_layer_entry_insert(&ws->layer.view_list, |
| 1028 | &ws->fsurf_front->view->layer_link); |
Louis-Francis Ratté-Boulianne | b482dbd | 2013-11-19 11:37:11 +0100 | [diff] [blame] | 1029 | |
| 1030 | if (focus_surface_created) { |
| 1031 | ws->focus_animation = weston_fade_run( |
| 1032 | ws->fsurf_front->view, |
Jonny Lamb | 7e7d485 | 2014-05-22 22:41:34 +0200 | [diff] [blame] | 1033 | ws->fsurf_front->view->alpha, 0.4, 300, |
Louis-Francis Ratté-Boulianne | b482dbd | 2013-11-19 11:37:11 +0100 | [diff] [blame] | 1034 | focus_animation_done, ws); |
| 1035 | } else if (from) { |
Giulio Camuffo | 412e6a5 | 2014-07-09 22:12:56 +0300 | [diff] [blame] | 1036 | weston_layer_entry_insert(&from->layer_link, |
| 1037 | &ws->fsurf_back->view->layer_link); |
Louis-Francis Ratté-Boulianne | b482dbd | 2013-11-19 11:37:11 +0100 | [diff] [blame] | 1038 | ws->focus_animation = weston_stable_fade_run( |
| 1039 | ws->fsurf_front->view, 0.0, |
Jonny Lamb | 7e7d485 | 2014-05-22 22:41:34 +0200 | [diff] [blame] | 1040 | ws->fsurf_back->view, 0.4, |
Louis-Francis Ratté-Boulianne | b482dbd | 2013-11-19 11:37:11 +0100 | [diff] [blame] | 1041 | focus_animation_done, ws); |
| 1042 | } else if (to) { |
Giulio Camuffo | 412e6a5 | 2014-07-09 22:12:56 +0300 | [diff] [blame] | 1043 | weston_layer_entry_insert(&ws->layer.view_list, |
| 1044 | &ws->fsurf_back->view->layer_link); |
Louis-Francis Ratté-Boulianne | b482dbd | 2013-11-19 11:37:11 +0100 | [diff] [blame] | 1045 | ws->focus_animation = weston_stable_fade_run( |
| 1046 | ws->fsurf_front->view, 0.0, |
Jonny Lamb | 7e7d485 | 2014-05-22 22:41:34 +0200 | [diff] [blame] | 1047 | ws->fsurf_back->view, 0.4, |
Louis-Francis Ratté-Boulianne | b482dbd | 2013-11-19 11:37:11 +0100 | [diff] [blame] | 1048 | focus_animation_done, ws); |
| 1049 | } |
| 1050 | } |
| 1051 | |
| 1052 | static void |
Jonas Ådahl | e3cddce | 2012-06-13 00:01:22 +0200 | [diff] [blame] | 1053 | workspace_destroy(struct workspace *ws) |
| 1054 | { |
Jonas Ådahl | 0476974 | 2012-06-13 00:01:24 +0200 | [diff] [blame] | 1055 | struct focus_state *state, *next; |
| 1056 | |
| 1057 | wl_list_for_each_safe(state, next, &ws->focus_list, link) |
| 1058 | focus_state_destroy(state); |
| 1059 | |
Louis-Francis Ratté-Boulianne | b482dbd | 2013-11-19 11:37:11 +0100 | [diff] [blame] | 1060 | if (ws->fsurf_front) |
| 1061 | focus_surface_destroy(ws->fsurf_front); |
| 1062 | if (ws->fsurf_back) |
| 1063 | focus_surface_destroy(ws->fsurf_back); |
| 1064 | |
Jonas Ådahl | e3cddce | 2012-06-13 00:01:22 +0200 | [diff] [blame] | 1065 | free(ws); |
| 1066 | } |
| 1067 | |
Jonas Ådahl | 0476974 | 2012-06-13 00:01:24 +0200 | [diff] [blame] | 1068 | static void |
| 1069 | seat_destroyed(struct wl_listener *listener, void *data) |
| 1070 | { |
| 1071 | struct weston_seat *seat = data; |
| 1072 | struct focus_state *state, *next; |
| 1073 | struct workspace *ws = container_of(listener, |
| 1074 | struct workspace, |
| 1075 | seat_destroyed_listener); |
| 1076 | |
| 1077 | wl_list_for_each_safe(state, next, &ws->focus_list, link) |
| 1078 | if (state->seat == seat) |
| 1079 | wl_list_remove(&state->link); |
| 1080 | } |
| 1081 | |
Jonas Ådahl | e3cddce | 2012-06-13 00:01:22 +0200 | [diff] [blame] | 1082 | static struct workspace * |
| 1083 | workspace_create(void) |
| 1084 | { |
| 1085 | struct workspace *ws = malloc(sizeof *ws); |
| 1086 | if (ws == NULL) |
| 1087 | return NULL; |
| 1088 | |
| 1089 | weston_layer_init(&ws->layer, NULL); |
| 1090 | |
Jonas Ådahl | 0476974 | 2012-06-13 00:01:24 +0200 | [diff] [blame] | 1091 | wl_list_init(&ws->focus_list); |
| 1092 | wl_list_init(&ws->seat_destroyed_listener.link); |
| 1093 | ws->seat_destroyed_listener.notify = seat_destroyed; |
Louis-Francis Ratté-Boulianne | b482dbd | 2013-11-19 11:37:11 +0100 | [diff] [blame] | 1094 | ws->fsurf_front = NULL; |
| 1095 | ws->fsurf_back = NULL; |
| 1096 | ws->focus_animation = NULL; |
Jonas Ådahl | 0476974 | 2012-06-13 00:01:24 +0200 | [diff] [blame] | 1097 | |
Jonas Ådahl | e3cddce | 2012-06-13 00:01:22 +0200 | [diff] [blame] | 1098 | return ws; |
| 1099 | } |
| 1100 | |
Jonas Ådahl | 62fcd04 | 2012-06-13 00:01:23 +0200 | [diff] [blame] | 1101 | static int |
| 1102 | workspace_is_empty(struct workspace *ws) |
| 1103 | { |
Giulio Camuffo | 412e6a5 | 2014-07-09 22:12:56 +0300 | [diff] [blame] | 1104 | return wl_list_empty(&ws->layer.view_list.link); |
Jonas Ådahl | 62fcd04 | 2012-06-13 00:01:23 +0200 | [diff] [blame] | 1105 | } |
| 1106 | |
Jonas Ådahl | e3cddce | 2012-06-13 00:01:22 +0200 | [diff] [blame] | 1107 | static struct workspace * |
| 1108 | get_workspace(struct desktop_shell *shell, unsigned int index) |
| 1109 | { |
| 1110 | struct workspace **pws = shell->workspaces.array.data; |
Philipp Brüschweiler | 067abf6 | 2012-09-01 16:03:05 +0200 | [diff] [blame] | 1111 | assert(index < shell->workspaces.num); |
Jonas Ådahl | e3cddce | 2012-06-13 00:01:22 +0200 | [diff] [blame] | 1112 | pws += index; |
| 1113 | return *pws; |
| 1114 | } |
| 1115 | |
Kristian Høgsberg | 1ef2313 | 2013-12-04 00:20:01 -0800 | [diff] [blame] | 1116 | struct workspace * |
Jonas Ådahl | e3cddce | 2012-06-13 00:01:22 +0200 | [diff] [blame] | 1117 | get_current_workspace(struct desktop_shell *shell) |
| 1118 | { |
| 1119 | return get_workspace(shell, shell->workspaces.current); |
| 1120 | } |
| 1121 | |
| 1122 | static void |
| 1123 | activate_workspace(struct desktop_shell *shell, unsigned int index) |
| 1124 | { |
| 1125 | struct workspace *ws; |
| 1126 | |
| 1127 | ws = get_workspace(shell, index); |
| 1128 | wl_list_insert(&shell->panel_layer.link, &ws->layer.link); |
| 1129 | |
| 1130 | shell->workspaces.current = index; |
| 1131 | } |
| 1132 | |
Jonas Ådahl | 62fcd04 | 2012-06-13 00:01:23 +0200 | [diff] [blame] | 1133 | static unsigned int |
| 1134 | get_output_height(struct weston_output *output) |
| 1135 | { |
| 1136 | return abs(output->region.extents.y1 - output->region.extents.y2); |
| 1137 | } |
| 1138 | |
| 1139 | static void |
Louis-Francis Ratté-Boulianne | b482dbd | 2013-11-19 11:37:11 +0100 | [diff] [blame] | 1140 | view_translate(struct workspace *ws, struct weston_view *view, double d) |
Jonas Ådahl | 62fcd04 | 2012-06-13 00:01:23 +0200 | [diff] [blame] | 1141 | { |
Jonas Ådahl | 62fcd04 | 2012-06-13 00:01:23 +0200 | [diff] [blame] | 1142 | struct weston_transform *transform; |
| 1143 | |
Louis-Francis Ratté-Boulianne | b482dbd | 2013-11-19 11:37:11 +0100 | [diff] [blame] | 1144 | if (is_focus_view(view)) { |
| 1145 | struct focus_surface *fsurf = get_focus_surface(view->surface); |
| 1146 | transform = &fsurf->workspace_transform; |
| 1147 | } else { |
| 1148 | struct shell_surface *shsurf = get_shell_surface(view->surface); |
| 1149 | transform = &shsurf->workspace_transform; |
| 1150 | } |
| 1151 | |
Jonas Ådahl | 62fcd04 | 2012-06-13 00:01:23 +0200 | [diff] [blame] | 1152 | if (wl_list_empty(&transform->link)) |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 1153 | wl_list_insert(view->geometry.transformation_list.prev, |
Louis-Francis Ratté-Boulianne | b482dbd | 2013-11-19 11:37:11 +0100 | [diff] [blame] | 1154 | &transform->link); |
Jonas Ådahl | 62fcd04 | 2012-06-13 00:01:23 +0200 | [diff] [blame] | 1155 | |
Louis-Francis Ratté-Boulianne | b482dbd | 2013-11-19 11:37:11 +0100 | [diff] [blame] | 1156 | weston_matrix_init(&transform->matrix); |
| 1157 | weston_matrix_translate(&transform->matrix, |
Jonas Ådahl | 62fcd04 | 2012-06-13 00:01:23 +0200 | [diff] [blame] | 1158 | 0.0, d, 0.0); |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 1159 | weston_view_geometry_dirty(view); |
Jonas Ådahl | 62fcd04 | 2012-06-13 00:01:23 +0200 | [diff] [blame] | 1160 | } |
| 1161 | |
| 1162 | static void |
| 1163 | workspace_translate_out(struct workspace *ws, double fraction) |
| 1164 | { |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 1165 | struct weston_view *view; |
Jonas Ådahl | 62fcd04 | 2012-06-13 00:01:23 +0200 | [diff] [blame] | 1166 | unsigned int height; |
| 1167 | double d; |
| 1168 | |
Giulio Camuffo | 412e6a5 | 2014-07-09 22:12:56 +0300 | [diff] [blame] | 1169 | 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] | 1170 | height = get_output_height(view->surface->output); |
Jonas Ådahl | 62fcd04 | 2012-06-13 00:01:23 +0200 | [diff] [blame] | 1171 | d = height * fraction; |
| 1172 | |
Louis-Francis Ratté-Boulianne | b482dbd | 2013-11-19 11:37:11 +0100 | [diff] [blame] | 1173 | view_translate(ws, view, d); |
Jonas Ådahl | 62fcd04 | 2012-06-13 00:01:23 +0200 | [diff] [blame] | 1174 | } |
| 1175 | } |
| 1176 | |
| 1177 | static void |
| 1178 | workspace_translate_in(struct workspace *ws, double fraction) |
| 1179 | { |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 1180 | struct weston_view *view; |
Jonas Ådahl | 62fcd04 | 2012-06-13 00:01:23 +0200 | [diff] [blame] | 1181 | unsigned int height; |
| 1182 | double d; |
| 1183 | |
Giulio Camuffo | 412e6a5 | 2014-07-09 22:12:56 +0300 | [diff] [blame] | 1184 | 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] | 1185 | height = get_output_height(view->surface->output); |
Jonas Ådahl | 62fcd04 | 2012-06-13 00:01:23 +0200 | [diff] [blame] | 1186 | |
| 1187 | if (fraction > 0) |
| 1188 | d = -(height - height * fraction); |
| 1189 | else |
| 1190 | d = height + height * fraction; |
| 1191 | |
Louis-Francis Ratté-Boulianne | b482dbd | 2013-11-19 11:37:11 +0100 | [diff] [blame] | 1192 | view_translate(ws, view, d); |
Jonas Ådahl | 62fcd04 | 2012-06-13 00:01:23 +0200 | [diff] [blame] | 1193 | } |
| 1194 | } |
| 1195 | |
| 1196 | static void |
Jonas Ådahl | 62fcd04 | 2012-06-13 00:01:23 +0200 | [diff] [blame] | 1197 | reverse_workspace_change_animation(struct desktop_shell *shell, |
| 1198 | unsigned int index, |
| 1199 | struct workspace *from, |
| 1200 | struct workspace *to) |
| 1201 | { |
| 1202 | shell->workspaces.current = index; |
| 1203 | |
| 1204 | shell->workspaces.anim_to = to; |
| 1205 | shell->workspaces.anim_from = from; |
| 1206 | shell->workspaces.anim_dir = -1 * shell->workspaces.anim_dir; |
| 1207 | shell->workspaces.anim_timestamp = 0; |
| 1208 | |
Scott Moreau | 4272e63 | 2012-08-13 09:58:41 -0600 | [diff] [blame] | 1209 | weston_compositor_schedule_repaint(shell->compositor); |
Jonas Ådahl | 62fcd04 | 2012-06-13 00:01:23 +0200 | [diff] [blame] | 1210 | } |
| 1211 | |
| 1212 | static void |
| 1213 | workspace_deactivate_transforms(struct workspace *ws) |
| 1214 | { |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 1215 | struct weston_view *view; |
Louis-Francis Ratté-Boulianne | b482dbd | 2013-11-19 11:37:11 +0100 | [diff] [blame] | 1216 | struct weston_transform *transform; |
Jonas Ådahl | 62fcd04 | 2012-06-13 00:01:23 +0200 | [diff] [blame] | 1217 | |
Giulio Camuffo | 412e6a5 | 2014-07-09 22:12:56 +0300 | [diff] [blame] | 1218 | 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] | 1219 | if (is_focus_view(view)) { |
| 1220 | struct focus_surface *fsurf = get_focus_surface(view->surface); |
| 1221 | transform = &fsurf->workspace_transform; |
| 1222 | } else { |
| 1223 | struct shell_surface *shsurf = get_shell_surface(view->surface); |
| 1224 | transform = &shsurf->workspace_transform; |
| 1225 | } |
| 1226 | |
| 1227 | if (!wl_list_empty(&transform->link)) { |
| 1228 | wl_list_remove(&transform->link); |
| 1229 | wl_list_init(&transform->link); |
Jonas Ådahl | 8de6a1d | 2012-08-29 22:13:00 +0200 | [diff] [blame] | 1230 | } |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 1231 | weston_view_geometry_dirty(view); |
Jonas Ådahl | 62fcd04 | 2012-06-13 00:01:23 +0200 | [diff] [blame] | 1232 | } |
| 1233 | } |
| 1234 | |
| 1235 | static void |
| 1236 | finish_workspace_change_animation(struct desktop_shell *shell, |
| 1237 | struct workspace *from, |
| 1238 | struct workspace *to) |
| 1239 | { |
Ander Conselvan de Oliveira | 9c6217e | 2014-05-07 11:57:26 +0300 | [diff] [blame] | 1240 | struct weston_view *view; |
| 1241 | |
Scott Moreau | 4272e63 | 2012-08-13 09:58:41 -0600 | [diff] [blame] | 1242 | weston_compositor_schedule_repaint(shell->compositor); |
Jonas Ådahl | 62fcd04 | 2012-06-13 00:01:23 +0200 | [diff] [blame] | 1243 | |
Ander Conselvan de Oliveira | 9c6217e | 2014-05-07 11:57:26 +0300 | [diff] [blame] | 1244 | /* Views that extend past the bottom of the output are still |
| 1245 | * visible after the workspace animation ends but before its layer |
| 1246 | * is hidden. In that case, we need to damage below those views so |
| 1247 | * that the screen is properly repainted. */ |
Giulio Camuffo | 412e6a5 | 2014-07-09 22:12:56 +0300 | [diff] [blame] | 1248 | 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] | 1249 | weston_view_damage_below(view); |
| 1250 | |
Jonas Ådahl | 62fcd04 | 2012-06-13 00:01:23 +0200 | [diff] [blame] | 1251 | wl_list_remove(&shell->workspaces.animation.link); |
| 1252 | workspace_deactivate_transforms(from); |
| 1253 | workspace_deactivate_transforms(to); |
| 1254 | shell->workspaces.anim_to = NULL; |
| 1255 | |
| 1256 | wl_list_remove(&shell->workspaces.anim_from->layer.link); |
| 1257 | } |
| 1258 | |
| 1259 | static void |
| 1260 | animate_workspace_change_frame(struct weston_animation *animation, |
| 1261 | struct weston_output *output, uint32_t msecs) |
| 1262 | { |
| 1263 | struct desktop_shell *shell = |
| 1264 | container_of(animation, struct desktop_shell, |
| 1265 | workspaces.animation); |
| 1266 | struct workspace *from = shell->workspaces.anim_from; |
| 1267 | struct workspace *to = shell->workspaces.anim_to; |
| 1268 | uint32_t t; |
| 1269 | double x, y; |
| 1270 | |
| 1271 | if (workspace_is_empty(from) && workspace_is_empty(to)) { |
| 1272 | finish_workspace_change_animation(shell, from, to); |
| 1273 | return; |
| 1274 | } |
| 1275 | |
| 1276 | if (shell->workspaces.anim_timestamp == 0) { |
| 1277 | if (shell->workspaces.anim_current == 0.0) |
| 1278 | shell->workspaces.anim_timestamp = msecs; |
| 1279 | else |
| 1280 | shell->workspaces.anim_timestamp = |
| 1281 | msecs - |
| 1282 | /* Invers of movement function 'y' below. */ |
| 1283 | (asin(1.0 - shell->workspaces.anim_current) * |
| 1284 | DEFAULT_WORKSPACE_CHANGE_ANIMATION_LENGTH * |
| 1285 | M_2_PI); |
| 1286 | } |
| 1287 | |
| 1288 | t = msecs - shell->workspaces.anim_timestamp; |
| 1289 | |
| 1290 | /* |
| 1291 | * x = [0, π/2] |
| 1292 | * y(x) = sin(x) |
| 1293 | */ |
| 1294 | x = t * (1.0/DEFAULT_WORKSPACE_CHANGE_ANIMATION_LENGTH) * M_PI_2; |
| 1295 | y = sin(x); |
| 1296 | |
| 1297 | if (t < DEFAULT_WORKSPACE_CHANGE_ANIMATION_LENGTH) { |
Scott Moreau | 4272e63 | 2012-08-13 09:58:41 -0600 | [diff] [blame] | 1298 | weston_compositor_schedule_repaint(shell->compositor); |
Jonas Ådahl | 62fcd04 | 2012-06-13 00:01:23 +0200 | [diff] [blame] | 1299 | |
| 1300 | workspace_translate_out(from, shell->workspaces.anim_dir * y); |
| 1301 | workspace_translate_in(to, shell->workspaces.anim_dir * y); |
| 1302 | shell->workspaces.anim_current = y; |
| 1303 | |
Scott Moreau | 4272e63 | 2012-08-13 09:58:41 -0600 | [diff] [blame] | 1304 | weston_compositor_schedule_repaint(shell->compositor); |
Jonas Ådahl | 62fcd04 | 2012-06-13 00:01:23 +0200 | [diff] [blame] | 1305 | } |
Jonas Ådahl | 0476974 | 2012-06-13 00:01:24 +0200 | [diff] [blame] | 1306 | else |
Jonas Ådahl | 62fcd04 | 2012-06-13 00:01:23 +0200 | [diff] [blame] | 1307 | finish_workspace_change_animation(shell, from, to); |
Jonas Ådahl | 62fcd04 | 2012-06-13 00:01:23 +0200 | [diff] [blame] | 1308 | } |
| 1309 | |
| 1310 | static void |
| 1311 | animate_workspace_change(struct desktop_shell *shell, |
| 1312 | unsigned int index, |
| 1313 | struct workspace *from, |
| 1314 | struct workspace *to) |
| 1315 | { |
| 1316 | struct weston_output *output; |
| 1317 | |
| 1318 | int dir; |
| 1319 | |
| 1320 | if (index > shell->workspaces.current) |
| 1321 | dir = -1; |
| 1322 | else |
| 1323 | dir = 1; |
| 1324 | |
| 1325 | shell->workspaces.current = index; |
| 1326 | |
| 1327 | shell->workspaces.anim_dir = dir; |
| 1328 | shell->workspaces.anim_from = from; |
| 1329 | shell->workspaces.anim_to = to; |
| 1330 | shell->workspaces.anim_current = 0.0; |
| 1331 | shell->workspaces.anim_timestamp = 0; |
| 1332 | |
| 1333 | output = container_of(shell->compositor->output_list.next, |
| 1334 | struct weston_output, link); |
| 1335 | wl_list_insert(&output->animation_list, |
| 1336 | &shell->workspaces.animation.link); |
| 1337 | |
Jonas Ådahl | 8de6a1d | 2012-08-29 22:13:00 +0200 | [diff] [blame] | 1338 | wl_list_insert(from->layer.link.prev, &to->layer.link); |
Jonas Ådahl | 62fcd04 | 2012-06-13 00:01:23 +0200 | [diff] [blame] | 1339 | |
| 1340 | workspace_translate_in(to, 0); |
| 1341 | |
Kristian Høgsberg | 2f5faff | 2012-07-31 16:36:34 -0400 | [diff] [blame] | 1342 | restore_focus_state(shell, to); |
Jonas Ådahl | 0476974 | 2012-06-13 00:01:24 +0200 | [diff] [blame] | 1343 | |
Scott Moreau | 4272e63 | 2012-08-13 09:58:41 -0600 | [diff] [blame] | 1344 | weston_compositor_schedule_repaint(shell->compositor); |
Jonas Ådahl | 62fcd04 | 2012-06-13 00:01:23 +0200 | [diff] [blame] | 1345 | } |
| 1346 | |
Jonas Ådahl | e3cddce | 2012-06-13 00:01:22 +0200 | [diff] [blame] | 1347 | static void |
Jonas Ådahl | 8de6a1d | 2012-08-29 22:13:00 +0200 | [diff] [blame] | 1348 | update_workspace(struct desktop_shell *shell, unsigned int index, |
| 1349 | struct workspace *from, struct workspace *to) |
| 1350 | { |
| 1351 | shell->workspaces.current = index; |
| 1352 | wl_list_insert(&from->layer.link, &to->layer.link); |
| 1353 | wl_list_remove(&from->layer.link); |
| 1354 | } |
| 1355 | |
| 1356 | static void |
Jonas Ådahl | e3cddce | 2012-06-13 00:01:22 +0200 | [diff] [blame] | 1357 | change_workspace(struct desktop_shell *shell, unsigned int index) |
| 1358 | { |
| 1359 | struct workspace *from; |
| 1360 | struct workspace *to; |
Louis-Francis Ratté-Boulianne | b482dbd | 2013-11-19 11:37:11 +0100 | [diff] [blame] | 1361 | struct focus_state *state; |
Jonas Ådahl | e3cddce | 2012-06-13 00:01:22 +0200 | [diff] [blame] | 1362 | |
| 1363 | if (index == shell->workspaces.current) |
| 1364 | return; |
| 1365 | |
| 1366 | /* Don't change workspace when there is any fullscreen surfaces. */ |
Giulio Camuffo | 412e6a5 | 2014-07-09 22:12:56 +0300 | [diff] [blame] | 1367 | if (!wl_list_empty(&shell->fullscreen_layer.view_list.link)) |
Jonas Ådahl | e3cddce | 2012-06-13 00:01:22 +0200 | [diff] [blame] | 1368 | return; |
| 1369 | |
Jonas Ådahl | e3cddce | 2012-06-13 00:01:22 +0200 | [diff] [blame] | 1370 | from = get_current_workspace(shell); |
| 1371 | to = get_workspace(shell, index); |
| 1372 | |
Jonas Ådahl | 62fcd04 | 2012-06-13 00:01:23 +0200 | [diff] [blame] | 1373 | if (shell->workspaces.anim_from == to && |
| 1374 | shell->workspaces.anim_to == from) { |
Jonas Ådahl | 8de6a1d | 2012-08-29 22:13:00 +0200 | [diff] [blame] | 1375 | restore_focus_state(shell, to); |
Jonas Ådahl | 62fcd04 | 2012-06-13 00:01:23 +0200 | [diff] [blame] | 1376 | reverse_workspace_change_animation(shell, index, from, to); |
| 1377 | return; |
| 1378 | } |
Jonas Ådahl | e3cddce | 2012-06-13 00:01:22 +0200 | [diff] [blame] | 1379 | |
Jonas Ådahl | 62fcd04 | 2012-06-13 00:01:23 +0200 | [diff] [blame] | 1380 | if (shell->workspaces.anim_to != NULL) |
| 1381 | finish_workspace_change_animation(shell, |
| 1382 | shell->workspaces.anim_from, |
| 1383 | shell->workspaces.anim_to); |
| 1384 | |
Jonas Ådahl | 8de6a1d | 2012-08-29 22:13:00 +0200 | [diff] [blame] | 1385 | restore_focus_state(shell, to); |
Jonas Ådahl | 0476974 | 2012-06-13 00:01:24 +0200 | [diff] [blame] | 1386 | |
Louis-Francis Ratté-Boulianne | b482dbd | 2013-11-19 11:37:11 +0100 | [diff] [blame] | 1387 | if (shell->focus_animation_type != ANIMATION_NONE) { |
| 1388 | wl_list_for_each(state, &from->focus_list, link) |
| 1389 | if (state->keyboard_focus) |
| 1390 | animate_focus_change(shell, from, |
| 1391 | get_default_view(state->keyboard_focus), NULL); |
| 1392 | |
| 1393 | wl_list_for_each(state, &to->focus_list, link) |
| 1394 | if (state->keyboard_focus) |
| 1395 | animate_focus_change(shell, to, |
| 1396 | NULL, get_default_view(state->keyboard_focus)); |
| 1397 | } |
| 1398 | |
Jonas Ådahl | 8de6a1d | 2012-08-29 22:13:00 +0200 | [diff] [blame] | 1399 | if (workspace_is_empty(to) && workspace_is_empty(from)) |
| 1400 | update_workspace(shell, index, from, to); |
Jonas Ådahl | 62fcd04 | 2012-06-13 00:01:23 +0200 | [diff] [blame] | 1401 | else |
| 1402 | animate_workspace_change(shell, index, from, to); |
Pekka Paalanen | e955f1e | 2011-12-07 11:49:52 +0200 | [diff] [blame] | 1403 | } |
| 1404 | |
Jonas Ådahl | 8de6a1d | 2012-08-29 22:13:00 +0200 | [diff] [blame] | 1405 | static bool |
| 1406 | workspace_has_only(struct workspace *ws, struct weston_surface *surface) |
| 1407 | { |
Giulio Camuffo | 412e6a5 | 2014-07-09 22:12:56 +0300 | [diff] [blame] | 1408 | struct wl_list *list = &ws->layer.view_list.link; |
Jonas Ådahl | 8de6a1d | 2012-08-29 22:13:00 +0200 | [diff] [blame] | 1409 | struct wl_list *e; |
| 1410 | |
| 1411 | if (wl_list_empty(list)) |
| 1412 | return false; |
| 1413 | |
| 1414 | e = list->next; |
| 1415 | |
| 1416 | if (e->next != list) |
| 1417 | return false; |
| 1418 | |
Giulio Camuffo | 412e6a5 | 2014-07-09 22:12:56 +0300 | [diff] [blame] | 1419 | return container_of(e, struct weston_view, layer_link.link)->surface == surface; |
Jonas Ådahl | 8de6a1d | 2012-08-29 22:13:00 +0200 | [diff] [blame] | 1420 | } |
| 1421 | |
| 1422 | static void |
Jonas Ådahl | 22faea1 | 2014-10-15 22:02:06 +0200 | [diff] [blame] | 1423 | surface_keyboard_focus_lost(struct weston_surface *surface) |
| 1424 | { |
| 1425 | struct weston_compositor *compositor = surface->compositor; |
| 1426 | struct weston_seat *seat; |
| 1427 | struct weston_surface *focus; |
| 1428 | |
| 1429 | wl_list_for_each(seat, &compositor->seat_list, link) { |
| 1430 | struct weston_keyboard *keyboard = |
| 1431 | weston_seat_get_keyboard(seat); |
| 1432 | |
| 1433 | if (!keyboard) |
| 1434 | continue; |
| 1435 | |
| 1436 | focus = weston_surface_get_main_surface(keyboard->focus); |
| 1437 | if (focus == surface) |
| 1438 | weston_keyboard_set_focus(keyboard, NULL); |
| 1439 | } |
| 1440 | } |
| 1441 | |
| 1442 | static void |
Jonas Ådahl | 8de6a1d | 2012-08-29 22:13:00 +0200 | [diff] [blame] | 1443 | take_surface_to_workspace_by_seat(struct desktop_shell *shell, |
Kristian Høgsberg | e314875 | 2013-05-06 23:19:49 -0400 | [diff] [blame] | 1444 | struct weston_seat *seat, |
Jonas Ådahl | 8de6a1d | 2012-08-29 22:13:00 +0200 | [diff] [blame] | 1445 | unsigned int index) |
| 1446 | { |
Derek Foreman | 1281a36 | 2015-07-31 16:55:32 -0500 | [diff] [blame] | 1447 | struct weston_keyboard *keyboard = weston_seat_get_keyboard(seat); |
Pekka Paalanen | 01388e2 | 2013-04-25 13:57:44 +0300 | [diff] [blame] | 1448 | struct weston_surface *surface; |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 1449 | struct weston_view *view; |
Jonas Ådahl | 8de6a1d | 2012-08-29 22:13:00 +0200 | [diff] [blame] | 1450 | struct shell_surface *shsurf; |
| 1451 | struct workspace *from; |
| 1452 | struct workspace *to; |
Jonas Ådahl | 8538b22 | 2012-08-29 22:13:03 +0200 | [diff] [blame] | 1453 | struct focus_state *state; |
Jonas Ådahl | 8de6a1d | 2012-08-29 22:13:00 +0200 | [diff] [blame] | 1454 | |
Derek Foreman | 1281a36 | 2015-07-31 16:55:32 -0500 | [diff] [blame] | 1455 | surface = weston_surface_get_main_surface(keyboard->focus); |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 1456 | view = get_default_view(surface); |
| 1457 | if (view == NULL || |
Louis-Francis Ratté-Boulianne | b482dbd | 2013-11-19 11:37:11 +0100 | [diff] [blame] | 1458 | index == shell->workspaces.current || |
| 1459 | is_focus_view(view)) |
Jonas Ådahl | 8de6a1d | 2012-08-29 22:13:00 +0200 | [diff] [blame] | 1460 | return; |
| 1461 | |
| 1462 | from = get_current_workspace(shell); |
| 1463 | to = get_workspace(shell, index); |
| 1464 | |
Giulio Camuffo | 412e6a5 | 2014-07-09 22:12:56 +0300 | [diff] [blame] | 1465 | weston_layer_entry_remove(&view->layer_link); |
| 1466 | weston_layer_entry_insert(&to->layer.view_list, &view->layer_link); |
Jonas Ådahl | 8de6a1d | 2012-08-29 22:13:00 +0200 | [diff] [blame] | 1467 | |
Philip Withnall | 659163d | 2013-11-25 18:01:36 +0000 | [diff] [blame] | 1468 | shsurf = get_shell_surface(surface); |
Philip Withnall | 648a4dd | 2013-11-25 18:01:44 +0000 | [diff] [blame] | 1469 | if (shsurf != NULL) |
| 1470 | shell_surface_update_child_surface_layers(shsurf); |
Philip Withnall | 659163d | 2013-11-25 18:01:36 +0000 | [diff] [blame] | 1471 | |
Jonas Ådahl | e9d2250 | 2012-08-29 22:13:01 +0200 | [diff] [blame] | 1472 | replace_focus_state(shell, to, seat); |
Jonas Ådahl | 8de6a1d | 2012-08-29 22:13:00 +0200 | [diff] [blame] | 1473 | drop_focus_state(shell, from, surface); |
| 1474 | |
| 1475 | if (shell->workspaces.anim_from == to && |
| 1476 | shell->workspaces.anim_to == from) { |
Jonas Ådahl | e9d2250 | 2012-08-29 22:13:01 +0200 | [diff] [blame] | 1477 | wl_list_remove(&to->layer.link); |
| 1478 | wl_list_insert(from->layer.link.prev, &to->layer.link); |
| 1479 | |
Jonas Ådahl | 8de6a1d | 2012-08-29 22:13:00 +0200 | [diff] [blame] | 1480 | reverse_workspace_change_animation(shell, index, from, to); |
Jonas Ådahl | e9d2250 | 2012-08-29 22:13:01 +0200 | [diff] [blame] | 1481 | |
Jonas Ådahl | 8de6a1d | 2012-08-29 22:13:00 +0200 | [diff] [blame] | 1482 | return; |
| 1483 | } |
| 1484 | |
| 1485 | if (shell->workspaces.anim_to != NULL) |
| 1486 | finish_workspace_change_animation(shell, |
| 1487 | shell->workspaces.anim_from, |
| 1488 | shell->workspaces.anim_to); |
| 1489 | |
| 1490 | if (workspace_is_empty(from) && |
| 1491 | workspace_has_only(to, surface)) |
| 1492 | update_workspace(shell, index, from, to); |
| 1493 | else { |
Philip Withnall | 2c3849b | 2013-11-25 18:01:45 +0000 | [diff] [blame] | 1494 | if (shsurf != NULL && |
| 1495 | wl_list_empty(&shsurf->workspace_transform.link)) |
Jonas Ådahl | 8de6a1d | 2012-08-29 22:13:00 +0200 | [diff] [blame] | 1496 | wl_list_insert(&shell->workspaces.anim_sticky_list, |
| 1497 | &shsurf->workspace_transform.link); |
| 1498 | |
| 1499 | animate_workspace_change(shell, index, from, to); |
| 1500 | } |
Jonas Ådahl | e9d2250 | 2012-08-29 22:13:01 +0200 | [diff] [blame] | 1501 | |
Jonas Ådahl | 8538b22 | 2012-08-29 22:13:03 +0200 | [diff] [blame] | 1502 | state = ensure_focus_state(shell, seat); |
| 1503 | if (state != NULL) |
Kristian Høgsberg | d500bf1 | 2014-01-22 12:25:20 -0800 | [diff] [blame] | 1504 | focus_state_set_focus(state, surface); |
Jonas Ådahl | e9d2250 | 2012-08-29 22:13:01 +0200 | [diff] [blame] | 1505 | } |
| 1506 | |
| 1507 | static void |
Rusty Lynch | 1084da5 | 2013-08-15 09:10:08 -0700 | [diff] [blame] | 1508 | touch_move_grab_down(struct weston_touch_grab *grab, uint32_t time, |
Giulio Camuffo | 61ed7b6 | 2015-07-08 11:55:28 +0300 | [diff] [blame] | 1509 | int touch_id, wl_fixed_t x, wl_fixed_t y) |
Rusty Lynch | 1084da5 | 2013-08-15 09:10:08 -0700 | [diff] [blame] | 1510 | { |
| 1511 | } |
| 1512 | |
| 1513 | static void |
| 1514 | touch_move_grab_up(struct weston_touch_grab *grab, uint32_t time, int touch_id) |
| 1515 | { |
Jonas Ådahl | 1c6e63e | 2013-10-25 23:18:04 +0200 | [diff] [blame] | 1516 | struct weston_touch_move_grab *move = |
| 1517 | (struct weston_touch_move_grab *) container_of( |
| 1518 | grab, struct shell_touch_grab, grab); |
Neil Roberts | e14aa4f | 2013-10-03 16:43:07 +0100 | [diff] [blame] | 1519 | |
Kristian Høgsberg | 8e80a31 | 2014-01-17 15:18:10 -0800 | [diff] [blame] | 1520 | if (touch_id == 0) |
| 1521 | move->active = 0; |
| 1522 | |
Jonas Ådahl | 9484b69 | 2013-12-02 22:05:03 +0100 | [diff] [blame] | 1523 | if (grab->touch->num_tp == 0) { |
Jonas Ådahl | 1c6e63e | 2013-10-25 23:18:04 +0200 | [diff] [blame] | 1524 | shell_touch_grab_end(&move->base); |
| 1525 | free(move); |
| 1526 | } |
Rusty Lynch | 1084da5 | 2013-08-15 09:10:08 -0700 | [diff] [blame] | 1527 | } |
| 1528 | |
| 1529 | static void |
| 1530 | touch_move_grab_motion(struct weston_touch_grab *grab, uint32_t time, |
Giulio Camuffo | 61ed7b6 | 2015-07-08 11:55:28 +0300 | [diff] [blame] | 1531 | int touch_id, wl_fixed_t x, wl_fixed_t y) |
Rusty Lynch | 1084da5 | 2013-08-15 09:10:08 -0700 | [diff] [blame] | 1532 | { |
| 1533 | struct weston_touch_move_grab *move = (struct weston_touch_move_grab *) grab; |
| 1534 | struct shell_surface *shsurf = move->base.shsurf; |
| 1535 | struct weston_surface *es; |
| 1536 | int dx = wl_fixed_to_int(grab->touch->grab_x + move->dx); |
| 1537 | int dy = wl_fixed_to_int(grab->touch->grab_y + move->dy); |
| 1538 | |
Kristian Høgsberg | 8e80a31 | 2014-01-17 15:18:10 -0800 | [diff] [blame] | 1539 | if (!shsurf || !move->active) |
Rusty Lynch | 1084da5 | 2013-08-15 09:10:08 -0700 | [diff] [blame] | 1540 | return; |
| 1541 | |
| 1542 | es = shsurf->surface; |
| 1543 | |
Jason Ekstrand | 918f2dd | 2013-12-02 21:01:53 -0600 | [diff] [blame] | 1544 | weston_view_set_position(shsurf->view, dx, dy); |
Rusty Lynch | 1084da5 | 2013-08-15 09:10:08 -0700 | [diff] [blame] | 1545 | |
| 1546 | weston_compositor_schedule_repaint(es->compositor); |
| 1547 | } |
| 1548 | |
Jonas Ådahl | 1ea343e | 2013-10-25 23:18:05 +0200 | [diff] [blame] | 1549 | static void |
Jonas Ådahl | 1679f23 | 2014-04-12 09:39:51 +0200 | [diff] [blame] | 1550 | touch_move_grab_frame(struct weston_touch_grab *grab) |
| 1551 | { |
| 1552 | } |
| 1553 | |
| 1554 | static void |
Jonas Ådahl | 1ea343e | 2013-10-25 23:18:05 +0200 | [diff] [blame] | 1555 | touch_move_grab_cancel(struct weston_touch_grab *grab) |
| 1556 | { |
| 1557 | struct weston_touch_move_grab *move = |
| 1558 | (struct weston_touch_move_grab *) container_of( |
| 1559 | grab, struct shell_touch_grab, grab); |
| 1560 | |
| 1561 | shell_touch_grab_end(&move->base); |
| 1562 | free(move); |
| 1563 | } |
| 1564 | |
Rusty Lynch | 1084da5 | 2013-08-15 09:10:08 -0700 | [diff] [blame] | 1565 | static const struct weston_touch_grab_interface touch_move_grab_interface = { |
| 1566 | touch_move_grab_down, |
| 1567 | touch_move_grab_up, |
| 1568 | touch_move_grab_motion, |
Jonas Ådahl | 1679f23 | 2014-04-12 09:39:51 +0200 | [diff] [blame] | 1569 | touch_move_grab_frame, |
Jonas Ådahl | 1ea343e | 2013-10-25 23:18:05 +0200 | [diff] [blame] | 1570 | touch_move_grab_cancel, |
Rusty Lynch | 1084da5 | 2013-08-15 09:10:08 -0700 | [diff] [blame] | 1571 | }; |
| 1572 | |
| 1573 | static int |
Derek Foreman | b7674ae | 2015-07-15 13:00:37 -0500 | [diff] [blame] | 1574 | surface_touch_move(struct shell_surface *shsurf, struct weston_touch *touch) |
Rusty Lynch | 1084da5 | 2013-08-15 09:10:08 -0700 | [diff] [blame] | 1575 | { |
| 1576 | struct weston_touch_move_grab *move; |
| 1577 | |
| 1578 | if (!shsurf) |
| 1579 | return -1; |
| 1580 | |
Ander Conselvan de Oliveira | 6d43f04 | 2014-05-07 14:22:23 +0300 | [diff] [blame] | 1581 | if (shsurf->state.fullscreen || shsurf->state.maximized) |
Rusty Lynch | 1084da5 | 2013-08-15 09:10:08 -0700 | [diff] [blame] | 1582 | return 0; |
| 1583 | |
| 1584 | move = malloc(sizeof *move); |
| 1585 | if (!move) |
| 1586 | return -1; |
| 1587 | |
Kristian Høgsberg | 8e80a31 | 2014-01-17 15:18:10 -0800 | [diff] [blame] | 1588 | move->active = 1; |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 1589 | move->dx = wl_fixed_from_double(shsurf->view->geometry.x) - |
Derek Foreman | b7674ae | 2015-07-15 13:00:37 -0500 | [diff] [blame] | 1590 | touch->grab_x; |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 1591 | move->dy = wl_fixed_from_double(shsurf->view->geometry.y) - |
Derek Foreman | b7674ae | 2015-07-15 13:00:37 -0500 | [diff] [blame] | 1592 | touch->grab_y; |
Rusty Lynch | 1084da5 | 2013-08-15 09:10:08 -0700 | [diff] [blame] | 1593 | |
| 1594 | shell_touch_grab_start(&move->base, &touch_move_grab_interface, shsurf, |
Derek Foreman | b7674ae | 2015-07-15 13:00:37 -0500 | [diff] [blame] | 1595 | touch); |
Rusty Lynch | 1084da5 | 2013-08-15 09:10:08 -0700 | [diff] [blame] | 1596 | |
| 1597 | return 0; |
| 1598 | } |
| 1599 | |
| 1600 | static void |
Kristian Høgsberg | 6848c25 | 2013-05-08 22:02:59 -0400 | [diff] [blame] | 1601 | noop_grab_focus(struct weston_pointer_grab *grab) |
Kristian Høgsberg | 9ddb826 | 2012-01-04 21:30:29 -0500 | [diff] [blame] | 1602 | { |
Kristian Høgsberg | 9ddb826 | 2012-01-04 21:30:29 -0500 | [diff] [blame] | 1603 | } |
| 1604 | |
| 1605 | static void |
Jonas Ådahl | 0336ca0 | 2014-10-04 16:28:29 +0200 | [diff] [blame] | 1606 | noop_grab_axis(struct weston_pointer_grab *grab, |
Peter Hutterer | 89b6a49 | 2016-01-18 15:58:17 +1000 | [diff] [blame] | 1607 | uint32_t time, struct weston_pointer_axis_event *event) |
Jonas Ådahl | 0336ca0 | 2014-10-04 16:28:29 +0200 | [diff] [blame] | 1608 | { |
| 1609 | } |
| 1610 | |
| 1611 | static void |
Peter Hutterer | 87743e9 | 2016-01-18 16:38:22 +1000 | [diff] [blame] | 1612 | noop_grab_axis_source(struct weston_pointer_grab *grab, |
| 1613 | uint32_t source) |
| 1614 | { |
| 1615 | } |
| 1616 | |
| 1617 | static void |
| 1618 | noop_grab_frame(struct weston_pointer_grab *grab) |
| 1619 | { |
| 1620 | } |
| 1621 | |
| 1622 | static void |
Kristian Høgsberg | ae356ae | 2014-04-29 16:03:54 -0700 | [diff] [blame] | 1623 | constrain_position(struct weston_move_grab *move, int *cx, int *cy) |
| 1624 | { |
| 1625 | struct shell_surface *shsurf = move->base.shsurf; |
| 1626 | struct weston_pointer *pointer = move->base.grab.pointer; |
Derek Foreman | 6feb0f9 | 2015-04-15 12:23:56 -0500 | [diff] [blame] | 1627 | int x, y, bottom; |
Kristian Høgsberg | ae356ae | 2014-04-29 16:03:54 -0700 | [diff] [blame] | 1628 | const int safety = 50; |
Derek Foreman | 6feb0f9 | 2015-04-15 12:23:56 -0500 | [diff] [blame] | 1629 | pixman_rectangle32_t area; |
Kristian Høgsberg | ae356ae | 2014-04-29 16:03:54 -0700 | [diff] [blame] | 1630 | |
| 1631 | x = wl_fixed_to_int(pointer->x + move->dx); |
| 1632 | y = wl_fixed_to_int(pointer->y + move->dy); |
| 1633 | |
Jonas Ådahl | 6d6fb61 | 2015-11-17 16:00:33 +0800 | [diff] [blame] | 1634 | if (shsurf->shell->panel_position == |
| 1635 | WESTON_DESKTOP_SHELL_PANEL_POSITION_TOP) { |
Derek Foreman | 6feb0f9 | 2015-04-15 12:23:56 -0500 | [diff] [blame] | 1636 | get_output_work_area(shsurf->shell, |
| 1637 | shsurf->surface->output, |
| 1638 | &area); |
Kristian Høgsberg | ae356ae | 2014-04-29 16:03:54 -0700 | [diff] [blame] | 1639 | |
Derek Foreman | 6feb0f9 | 2015-04-15 12:23:56 -0500 | [diff] [blame] | 1640 | bottom = y + shsurf->geometry.height + shsurf->geometry.y; |
| 1641 | if (bottom - safety < area.y) |
| 1642 | y = area.y + safety - shsurf->geometry.height |
| 1643 | - shsurf->geometry.y; |
Jonny Lamb | d73c694 | 2014-08-20 15:53:20 +0200 | [diff] [blame] | 1644 | |
| 1645 | if (move->client_initiated && |
Derek Foreman | 6feb0f9 | 2015-04-15 12:23:56 -0500 | [diff] [blame] | 1646 | y + shsurf->geometry.y < area.y) |
| 1647 | y = area.y - shsurf->geometry.y; |
| 1648 | |
Jonny Lamb | d73c694 | 2014-08-20 15:53:20 +0200 | [diff] [blame] | 1649 | } |
Kristian Høgsberg | ae356ae | 2014-04-29 16:03:54 -0700 | [diff] [blame] | 1650 | |
| 1651 | *cx = x; |
| 1652 | *cy = y; |
| 1653 | } |
| 1654 | |
| 1655 | static void |
Giulio Camuffo | 1959ab8 | 2013-11-14 23:42:52 +0100 | [diff] [blame] | 1656 | move_grab_motion(struct weston_pointer_grab *grab, uint32_t time, |
Jonas Ådahl | d251010 | 2014-10-05 21:39:14 +0200 | [diff] [blame] | 1657 | struct weston_pointer_motion_event *event) |
Kristian Høgsberg | 4cca349 | 2011-01-18 07:53:49 -0500 | [diff] [blame] | 1658 | { |
Kristian Høgsberg | 8334bc1 | 2012-01-03 10:29:47 -0500 | [diff] [blame] | 1659 | struct weston_move_grab *move = (struct weston_move_grab *) grab; |
Kristian Høgsberg | 02bbabb | 2013-05-06 22:15:05 -0400 | [diff] [blame] | 1660 | struct weston_pointer *pointer = grab->pointer; |
Ander Conselvan de Oliveira | fe0444a | 2012-04-04 17:48:05 +0300 | [diff] [blame] | 1661 | struct shell_surface *shsurf = move->base.shsurf; |
Kristian Høgsberg | ae356ae | 2014-04-29 16:03:54 -0700 | [diff] [blame] | 1662 | int cx, cy; |
Giulio Camuffo | 1959ab8 | 2013-11-14 23:42:52 +0100 | [diff] [blame] | 1663 | |
Jonas Ådahl | d251010 | 2014-10-05 21:39:14 +0200 | [diff] [blame] | 1664 | weston_pointer_move(pointer, event); |
Ander Conselvan de Oliveira | fe0444a | 2012-04-04 17:48:05 +0300 | [diff] [blame] | 1665 | if (!shsurf) |
| 1666 | return; |
| 1667 | |
Kristian Høgsberg | ae356ae | 2014-04-29 16:03:54 -0700 | [diff] [blame] | 1668 | constrain_position(move, &cx, &cy); |
| 1669 | |
| 1670 | weston_view_set_position(shsurf->view, cx, cy); |
Kristian Høgsberg | 4cca349 | 2011-01-18 07:53:49 -0500 | [diff] [blame] | 1671 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 1672 | weston_compositor_schedule_repaint(shsurf->surface->compositor); |
Kristian Høgsberg | 4cca349 | 2011-01-18 07:53:49 -0500 | [diff] [blame] | 1673 | } |
| 1674 | |
| 1675 | static void |
Kristian Høgsberg | 02bbabb | 2013-05-06 22:15:05 -0400 | [diff] [blame] | 1676 | move_grab_button(struct weston_pointer_grab *grab, |
Daniel Stone | 4dbadb1 | 2012-05-30 16:31:51 +0100 | [diff] [blame] | 1677 | uint32_t time, uint32_t button, uint32_t state_w) |
Kristian Høgsberg | 4cca349 | 2011-01-18 07:53:49 -0500 | [diff] [blame] | 1678 | { |
Ander Conselvan de Oliveira | fe0444a | 2012-04-04 17:48:05 +0300 | [diff] [blame] | 1679 | struct shell_grab *shell_grab = container_of(grab, struct shell_grab, |
| 1680 | grab); |
Kristian Høgsberg | 02bbabb | 2013-05-06 22:15:05 -0400 | [diff] [blame] | 1681 | struct weston_pointer *pointer = grab->pointer; |
Daniel Stone | 4dbadb1 | 2012-05-30 16:31:51 +0100 | [diff] [blame] | 1682 | enum wl_pointer_button_state state = state_w; |
Kristian Høgsberg | 4cca349 | 2011-01-18 07:53:49 -0500 | [diff] [blame] | 1683 | |
Daniel Stone | 4dbadb1 | 2012-05-30 16:31:51 +0100 | [diff] [blame] | 1684 | if (pointer->button_count == 0 && |
| 1685 | state == WL_POINTER_BUTTON_STATE_RELEASED) { |
Ander Conselvan de Oliveira | b9d2a0f | 2012-06-28 18:08:05 +0300 | [diff] [blame] | 1686 | shell_grab_end(shell_grab); |
Kristian Høgsberg | 9ddb826 | 2012-01-04 21:30:29 -0500 | [diff] [blame] | 1687 | free(grab); |
| 1688 | } |
Kristian Høgsberg | 4cca349 | 2011-01-18 07:53:49 -0500 | [diff] [blame] | 1689 | } |
| 1690 | |
Jonas Ådahl | 1ea343e | 2013-10-25 23:18:05 +0200 | [diff] [blame] | 1691 | static void |
| 1692 | move_grab_cancel(struct weston_pointer_grab *grab) |
| 1693 | { |
| 1694 | struct shell_grab *shell_grab = |
| 1695 | container_of(grab, struct shell_grab, grab); |
| 1696 | |
| 1697 | shell_grab_end(shell_grab); |
| 1698 | free(grab); |
| 1699 | } |
| 1700 | |
Kristian Høgsberg | 02bbabb | 2013-05-06 22:15:05 -0400 | [diff] [blame] | 1701 | static const struct weston_pointer_grab_interface move_grab_interface = { |
Kristian Høgsberg | 9ddb826 | 2012-01-04 21:30:29 -0500 | [diff] [blame] | 1702 | noop_grab_focus, |
Kristian Høgsberg | 4cca349 | 2011-01-18 07:53:49 -0500 | [diff] [blame] | 1703 | move_grab_motion, |
| 1704 | move_grab_button, |
Jonas Ådahl | 0336ca0 | 2014-10-04 16:28:29 +0200 | [diff] [blame] | 1705 | noop_grab_axis, |
Peter Hutterer | 87743e9 | 2016-01-18 16:38:22 +1000 | [diff] [blame] | 1706 | noop_grab_axis_source, |
| 1707 | noop_grab_frame, |
Jonas Ådahl | 1ea343e | 2013-10-25 23:18:05 +0200 | [diff] [blame] | 1708 | move_grab_cancel, |
Kristian Høgsberg | 4cca349 | 2011-01-18 07:53:49 -0500 | [diff] [blame] | 1709 | }; |
| 1710 | |
Kristian Høgsberg | 9e31bff | 2012-08-01 00:08:07 -0400 | [diff] [blame] | 1711 | static int |
Derek Foreman | 794fa0e | 2015-07-15 13:00:38 -0500 | [diff] [blame] | 1712 | surface_move(struct shell_surface *shsurf, struct weston_pointer *pointer, |
Derek Foreman | cf7d95a | 2015-06-03 15:53:22 -0500 | [diff] [blame] | 1713 | bool client_initiated) |
Kristian Høgsberg | 9e31bff | 2012-08-01 00:08:07 -0400 | [diff] [blame] | 1714 | { |
| 1715 | struct weston_move_grab *move; |
| 1716 | |
| 1717 | if (!shsurf) |
| 1718 | return -1; |
| 1719 | |
Derek Foreman | 45a7c27 | 2015-09-11 14:27:40 -0500 | [diff] [blame] | 1720 | shsurf = find_toplevel_surface(shsurf); |
| 1721 | |
Kristian Høgsberg | a4b620e | 2014-04-30 16:05:49 -0700 | [diff] [blame] | 1722 | if (shsurf->grabbed || |
| 1723 | shsurf->state.fullscreen || shsurf->state.maximized) |
Kristian Høgsberg | 9e31bff | 2012-08-01 00:08:07 -0400 | [diff] [blame] | 1724 | return 0; |
| 1725 | |
| 1726 | move = malloc(sizeof *move); |
| 1727 | if (!move) |
| 1728 | return -1; |
| 1729 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 1730 | move->dx = wl_fixed_from_double(shsurf->view->geometry.x) - |
Derek Foreman | 794fa0e | 2015-07-15 13:00:38 -0500 | [diff] [blame] | 1731 | pointer->grab_x; |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 1732 | move->dy = wl_fixed_from_double(shsurf->view->geometry.y) - |
Derek Foreman | 794fa0e | 2015-07-15 13:00:38 -0500 | [diff] [blame] | 1733 | pointer->grab_y; |
Kristian Høgsberg | ae356ae | 2014-04-29 16:03:54 -0700 | [diff] [blame] | 1734 | move->client_initiated = client_initiated; |
Kristian Høgsberg | 9e31bff | 2012-08-01 00:08:07 -0400 | [diff] [blame] | 1735 | |
| 1736 | shell_grab_start(&move->base, &move_grab_interface, shsurf, |
Jonas Ådahl | 6d6fb61 | 2015-11-17 16:00:33 +0800 | [diff] [blame] | 1737 | pointer, WESTON_DESKTOP_SHELL_CURSOR_MOVE); |
Kristian Høgsberg | 9e31bff | 2012-08-01 00:08:07 -0400 | [diff] [blame] | 1738 | |
| 1739 | return 0; |
| 1740 | } |
| 1741 | |
| 1742 | static void |
Rafael Antognolli | e2a3455 | 2013-12-03 15:35:45 -0200 | [diff] [blame] | 1743 | common_surface_move(struct wl_resource *resource, |
| 1744 | struct wl_resource *seat_resource, uint32_t serial) |
Kristian Høgsberg | 9e31bff | 2012-08-01 00:08:07 -0400 | [diff] [blame] | 1745 | { |
Jason Ekstrand | 44a3863 | 2013-06-14 10:08:00 -0500 | [diff] [blame] | 1746 | struct weston_seat *seat = wl_resource_get_user_data(seat_resource); |
Derek Foreman | 1281a36 | 2015-07-31 16:55:32 -0500 | [diff] [blame] | 1747 | struct weston_pointer *pointer = weston_seat_get_pointer(seat); |
| 1748 | struct weston_touch *touch = weston_seat_get_touch(seat); |
Jason Ekstrand | 651f00e | 2013-06-14 10:07:54 -0500 | [diff] [blame] | 1749 | struct shell_surface *shsurf = wl_resource_get_user_data(resource); |
Giulio Camuffo | 61da3fc | 2013-04-25 13:57:45 +0300 | [diff] [blame] | 1750 | struct weston_surface *surface; |
Kristian Høgsberg | 9e31bff | 2012-08-01 00:08:07 -0400 | [diff] [blame] | 1751 | |
Derek Foreman | 1281a36 | 2015-07-31 16:55:32 -0500 | [diff] [blame] | 1752 | if (pointer && |
| 1753 | pointer->focus && |
| 1754 | pointer->button_count > 0 && |
| 1755 | pointer->grab_serial == serial) { |
| 1756 | surface = weston_surface_get_main_surface(pointer->focus->surface); |
U. Artie Eoff | cf5737a | 2014-01-17 10:08:25 -0800 | [diff] [blame] | 1757 | if ((surface == shsurf->surface) && |
Derek Foreman | 1281a36 | 2015-07-31 16:55:32 -0500 | [diff] [blame] | 1758 | (surface_move(shsurf, pointer, true) < 0)) |
Rusty Lynch | 1084da5 | 2013-08-15 09:10:08 -0700 | [diff] [blame] | 1759 | wl_resource_post_no_memory(resource); |
Derek Foreman | 1281a36 | 2015-07-31 16:55:32 -0500 | [diff] [blame] | 1760 | } else if (touch && |
| 1761 | touch->focus && |
| 1762 | touch->grab_serial == serial) { |
| 1763 | surface = weston_surface_get_main_surface(touch->focus->surface); |
U. Artie Eoff | cf5737a | 2014-01-17 10:08:25 -0800 | [diff] [blame] | 1764 | if ((surface == shsurf->surface) && |
Derek Foreman | 1281a36 | 2015-07-31 16:55:32 -0500 | [diff] [blame] | 1765 | (surface_touch_move(shsurf, touch) < 0)) |
Rusty Lynch | 1084da5 | 2013-08-15 09:10:08 -0700 | [diff] [blame] | 1766 | wl_resource_post_no_memory(resource); |
| 1767 | } |
Kristian Høgsberg | 9e31bff | 2012-08-01 00:08:07 -0400 | [diff] [blame] | 1768 | } |
| 1769 | |
Rafael Antognolli | e2a3455 | 2013-12-03 15:35:45 -0200 | [diff] [blame] | 1770 | static void |
| 1771 | shell_surface_move(struct wl_client *client, struct wl_resource *resource, |
| 1772 | struct wl_resource *seat_resource, uint32_t serial) |
| 1773 | { |
| 1774 | common_surface_move(resource, seat_resource, serial); |
| 1775 | } |
| 1776 | |
Kristian Høgsberg | 9e31bff | 2012-08-01 00:08:07 -0400 | [diff] [blame] | 1777 | struct weston_resize_grab { |
| 1778 | struct shell_grab base; |
| 1779 | uint32_t edges; |
| 1780 | int32_t width, height; |
| 1781 | }; |
| 1782 | |
| 1783 | static void |
Giulio Camuffo | 1959ab8 | 2013-11-14 23:42:52 +0100 | [diff] [blame] | 1784 | resize_grab_motion(struct weston_pointer_grab *grab, uint32_t time, |
Jonas Ådahl | d251010 | 2014-10-05 21:39:14 +0200 | [diff] [blame] | 1785 | struct weston_pointer_motion_event *event) |
Kristian Høgsberg | 9e31bff | 2012-08-01 00:08:07 -0400 | [diff] [blame] | 1786 | { |
| 1787 | struct weston_resize_grab *resize = (struct weston_resize_grab *) grab; |
Kristian Høgsberg | 02bbabb | 2013-05-06 22:15:05 -0400 | [diff] [blame] | 1788 | struct weston_pointer *pointer = grab->pointer; |
Kristian Høgsberg | 9e31bff | 2012-08-01 00:08:07 -0400 | [diff] [blame] | 1789 | struct shell_surface *shsurf = resize->base.shsurf; |
| 1790 | int32_t width, height; |
| 1791 | wl_fixed_t from_x, from_y; |
| 1792 | wl_fixed_t to_x, to_y; |
| 1793 | |
Jonas Ådahl | d251010 | 2014-10-05 21:39:14 +0200 | [diff] [blame] | 1794 | weston_pointer_move(pointer, event); |
Giulio Camuffo | 1959ab8 | 2013-11-14 23:42:52 +0100 | [diff] [blame] | 1795 | |
Kristian Høgsberg | e0b9d5b | 2014-04-30 13:45:49 -0700 | [diff] [blame] | 1796 | if (!shsurf) |
Kristian Høgsberg | 9e31bff | 2012-08-01 00:08:07 -0400 | [diff] [blame] | 1797 | return; |
| 1798 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 1799 | weston_view_from_global_fixed(shsurf->view, |
| 1800 | pointer->grab_x, pointer->grab_y, |
| 1801 | &from_x, &from_y); |
| 1802 | weston_view_from_global_fixed(shsurf->view, |
| 1803 | pointer->x, pointer->y, &to_x, &to_y); |
Kristian Høgsberg | 9e31bff | 2012-08-01 00:08:07 -0400 | [diff] [blame] | 1804 | |
| 1805 | width = resize->width; |
| 1806 | if (resize->edges & WL_SHELL_SURFACE_RESIZE_LEFT) { |
| 1807 | width += wl_fixed_to_int(from_x - to_x); |
| 1808 | } else if (resize->edges & WL_SHELL_SURFACE_RESIZE_RIGHT) { |
| 1809 | width += wl_fixed_to_int(to_x - from_x); |
| 1810 | } |
| 1811 | |
| 1812 | height = resize->height; |
| 1813 | if (resize->edges & WL_SHELL_SURFACE_RESIZE_TOP) { |
| 1814 | height += wl_fixed_to_int(from_y - to_y); |
| 1815 | } else if (resize->edges & WL_SHELL_SURFACE_RESIZE_BOTTOM) { |
| 1816 | height += wl_fixed_to_int(to_y - from_y); |
| 1817 | } |
| 1818 | |
Derek Foreman | 70ac0ed | 2015-03-18 11:16:33 -0500 | [diff] [blame] | 1819 | if (width < 1) |
| 1820 | width = 1; |
| 1821 | if (height < 1) |
| 1822 | height = 1; |
Jasper St. Pierre | ac985be | 2014-04-28 11:19:28 -0400 | [diff] [blame] | 1823 | shsurf->client->send_configure(shsurf->surface, width, height); |
Kristian Høgsberg | 9e31bff | 2012-08-01 00:08:07 -0400 | [diff] [blame] | 1824 | } |
| 1825 | |
| 1826 | static void |
Jasper St. Pierre | ac985be | 2014-04-28 11:19:28 -0400 | [diff] [blame] | 1827 | 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] | 1828 | { |
| 1829 | struct shell_surface *shsurf = get_shell_surface(surface); |
| 1830 | |
U. Artie Eoff | cf5737a | 2014-01-17 10:08:25 -0800 | [diff] [blame] | 1831 | assert(shsurf); |
| 1832 | |
Kristian Høgsberg | e0b9d5b | 2014-04-30 13:45:49 -0700 | [diff] [blame] | 1833 | if (shsurf->resource) |
| 1834 | wl_shell_surface_send_configure(shsurf->resource, |
Jasper St. Pierre | ac985be | 2014-04-28 11:19:28 -0400 | [diff] [blame] | 1835 | shsurf->resize_edges, |
| 1836 | width, height); |
Kristian Høgsberg | 9e31bff | 2012-08-01 00:08:07 -0400 | [diff] [blame] | 1837 | } |
| 1838 | |
| 1839 | static const struct weston_shell_client shell_client = { |
Giulio Camuffo | f05d18f | 2015-12-11 20:57:05 +0200 | [diff] [blame] | 1840 | send_configure, |
| 1841 | NULL |
Kristian Høgsberg | 9e31bff | 2012-08-01 00:08:07 -0400 | [diff] [blame] | 1842 | }; |
| 1843 | |
| 1844 | static void |
Kristian Høgsberg | 02bbabb | 2013-05-06 22:15:05 -0400 | [diff] [blame] | 1845 | resize_grab_button(struct weston_pointer_grab *grab, |
Kristian Høgsberg | 9e31bff | 2012-08-01 00:08:07 -0400 | [diff] [blame] | 1846 | uint32_t time, uint32_t button, uint32_t state_w) |
| 1847 | { |
| 1848 | struct weston_resize_grab *resize = (struct weston_resize_grab *) grab; |
Kristian Høgsberg | 02bbabb | 2013-05-06 22:15:05 -0400 | [diff] [blame] | 1849 | struct weston_pointer *pointer = grab->pointer; |
Kristian Høgsberg | 9e31bff | 2012-08-01 00:08:07 -0400 | [diff] [blame] | 1850 | enum wl_pointer_button_state state = state_w; |
| 1851 | |
| 1852 | if (pointer->button_count == 0 && |
| 1853 | state == WL_POINTER_BUTTON_STATE_RELEASED) { |
| 1854 | shell_grab_end(&resize->base); |
| 1855 | free(grab); |
| 1856 | } |
| 1857 | } |
| 1858 | |
Jonas Ådahl | 1ea343e | 2013-10-25 23:18:05 +0200 | [diff] [blame] | 1859 | static void |
| 1860 | resize_grab_cancel(struct weston_pointer_grab *grab) |
| 1861 | { |
| 1862 | struct weston_resize_grab *resize = (struct weston_resize_grab *) grab; |
| 1863 | |
| 1864 | shell_grab_end(&resize->base); |
| 1865 | free(grab); |
| 1866 | } |
| 1867 | |
Kristian Høgsberg | 02bbabb | 2013-05-06 22:15:05 -0400 | [diff] [blame] | 1868 | static const struct weston_pointer_grab_interface resize_grab_interface = { |
Kristian Høgsberg | 9e31bff | 2012-08-01 00:08:07 -0400 | [diff] [blame] | 1869 | noop_grab_focus, |
| 1870 | resize_grab_motion, |
| 1871 | resize_grab_button, |
Jonas Ådahl | 0336ca0 | 2014-10-04 16:28:29 +0200 | [diff] [blame] | 1872 | noop_grab_axis, |
Peter Hutterer | 87743e9 | 2016-01-18 16:38:22 +1000 | [diff] [blame] | 1873 | noop_grab_axis_source, |
| 1874 | noop_grab_frame, |
Jonas Ådahl | 1ea343e | 2013-10-25 23:18:05 +0200 | [diff] [blame] | 1875 | resize_grab_cancel, |
Kristian Høgsberg | 9e31bff | 2012-08-01 00:08:07 -0400 | [diff] [blame] | 1876 | }; |
| 1877 | |
Giulio Camuffo | b836664 | 2013-04-25 13:57:46 +0300 | [diff] [blame] | 1878 | /* |
| 1879 | * Returns the bounding box of a surface and all its sub-surfaces, |
Yong Bakos | bbb783a | 2016-04-28 11:59:06 -0500 | [diff] [blame] | 1880 | * in surface-local coordinates. */ |
Giulio Camuffo | b836664 | 2013-04-25 13:57:46 +0300 | [diff] [blame] | 1881 | static void |
| 1882 | surface_subsurfaces_boundingbox(struct weston_surface *surface, int32_t *x, |
| 1883 | int32_t *y, int32_t *w, int32_t *h) { |
| 1884 | pixman_region32_t region; |
| 1885 | pixman_box32_t *box; |
| 1886 | struct weston_subsurface *subsurface; |
| 1887 | |
| 1888 | pixman_region32_init_rect(®ion, 0, 0, |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 1889 | surface->width, |
| 1890 | surface->height); |
Giulio Camuffo | b836664 | 2013-04-25 13:57:46 +0300 | [diff] [blame] | 1891 | |
| 1892 | wl_list_for_each(subsurface, &surface->subsurface_list, parent_link) { |
| 1893 | pixman_region32_union_rect(®ion, ®ion, |
| 1894 | subsurface->position.x, |
| 1895 | subsurface->position.y, |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 1896 | subsurface->surface->width, |
| 1897 | subsurface->surface->height); |
Giulio Camuffo | b836664 | 2013-04-25 13:57:46 +0300 | [diff] [blame] | 1898 | } |
| 1899 | |
| 1900 | box = pixman_region32_extents(®ion); |
| 1901 | if (x) |
| 1902 | *x = box->x1; |
| 1903 | if (y) |
| 1904 | *y = box->y1; |
| 1905 | if (w) |
| 1906 | *w = box->x2 - box->x1; |
| 1907 | if (h) |
| 1908 | *h = box->y2 - box->y1; |
| 1909 | |
| 1910 | pixman_region32_fini(®ion); |
| 1911 | } |
| 1912 | |
Kristian Høgsberg | 9e31bff | 2012-08-01 00:08:07 -0400 | [diff] [blame] | 1913 | static int |
| 1914 | surface_resize(struct shell_surface *shsurf, |
Derek Foreman | 8fbebbd | 2015-07-15 13:00:40 -0500 | [diff] [blame] | 1915 | struct weston_pointer *pointer, uint32_t edges) |
Kristian Høgsberg | 9e31bff | 2012-08-01 00:08:07 -0400 | [diff] [blame] | 1916 | { |
| 1917 | struct weston_resize_grab *resize; |
Ondřej Majerech | ae9c4fc | 2014-08-21 15:47:22 +0200 | [diff] [blame] | 1918 | const unsigned resize_topbottom = |
| 1919 | WL_SHELL_SURFACE_RESIZE_TOP | WL_SHELL_SURFACE_RESIZE_BOTTOM; |
| 1920 | const unsigned resize_leftright = |
| 1921 | WL_SHELL_SURFACE_RESIZE_LEFT | WL_SHELL_SURFACE_RESIZE_RIGHT; |
| 1922 | const unsigned resize_any = resize_topbottom | resize_leftright; |
Kristian Høgsberg | 9e31bff | 2012-08-01 00:08:07 -0400 | [diff] [blame] | 1923 | |
Kristian Høgsberg | a4b620e | 2014-04-30 16:05:49 -0700 | [diff] [blame] | 1924 | if (shsurf->grabbed || |
| 1925 | shsurf->state.fullscreen || shsurf->state.maximized) |
Kristian Høgsberg | 9e31bff | 2012-08-01 00:08:07 -0400 | [diff] [blame] | 1926 | return 0; |
| 1927 | |
Ondřej Majerech | ae9c4fc | 2014-08-21 15:47:22 +0200 | [diff] [blame] | 1928 | /* Check for invalid edge combinations. */ |
| 1929 | if (edges == WL_SHELL_SURFACE_RESIZE_NONE || edges > resize_any || |
| 1930 | (edges & resize_topbottom) == resize_topbottom || |
| 1931 | (edges & resize_leftright) == resize_leftright) |
Kristian Høgsberg | 9e31bff | 2012-08-01 00:08:07 -0400 | [diff] [blame] | 1932 | return 0; |
| 1933 | |
| 1934 | resize = malloc(sizeof *resize); |
| 1935 | if (!resize) |
| 1936 | return -1; |
| 1937 | |
| 1938 | resize->edges = edges; |
Kristian Høgsberg | 9e31bff | 2012-08-01 00:08:07 -0400 | [diff] [blame] | 1939 | |
Jasper St. Pierre | ccf48fb | 2014-05-02 10:21:38 -0400 | [diff] [blame] | 1940 | resize->width = shsurf->geometry.width; |
| 1941 | resize->height = shsurf->geometry.height; |
Jasper St. Pierre | bd65e50 | 2014-07-14 16:28:48 -0400 | [diff] [blame] | 1942 | |
Kristian Høgsberg | 44cd196 | 2014-02-05 21:36:04 -0800 | [diff] [blame] | 1943 | shsurf->resize_edges = edges; |
Jasper St. Pierre | 5befdda | 2014-05-06 08:50:47 -0400 | [diff] [blame] | 1944 | shell_surface_state_changed(shsurf); |
Kristian Høgsberg | 9e31bff | 2012-08-01 00:08:07 -0400 | [diff] [blame] | 1945 | shell_grab_start(&resize->base, &resize_grab_interface, shsurf, |
Derek Foreman | 8fbebbd | 2015-07-15 13:00:40 -0500 | [diff] [blame] | 1946 | pointer, edges); |
Kristian Høgsberg | 9e31bff | 2012-08-01 00:08:07 -0400 | [diff] [blame] | 1947 | |
| 1948 | return 0; |
| 1949 | } |
| 1950 | |
| 1951 | static void |
Rafael Antognolli | e2a3455 | 2013-12-03 15:35:45 -0200 | [diff] [blame] | 1952 | common_surface_resize(struct wl_resource *resource, |
| 1953 | struct wl_resource *seat_resource, uint32_t serial, |
| 1954 | uint32_t edges) |
Kristian Høgsberg | 9e31bff | 2012-08-01 00:08:07 -0400 | [diff] [blame] | 1955 | { |
Jason Ekstrand | 44a3863 | 2013-06-14 10:08:00 -0500 | [diff] [blame] | 1956 | struct weston_seat *seat = wl_resource_get_user_data(seat_resource); |
Derek Foreman | 1281a36 | 2015-07-31 16:55:32 -0500 | [diff] [blame] | 1957 | struct weston_pointer *pointer = weston_seat_get_pointer(seat); |
Jason Ekstrand | 651f00e | 2013-06-14 10:07:54 -0500 | [diff] [blame] | 1958 | struct shell_surface *shsurf = wl_resource_get_user_data(resource); |
Giulio Camuffo | 61da3fc | 2013-04-25 13:57:45 +0300 | [diff] [blame] | 1959 | struct weston_surface *surface; |
Kristian Høgsberg | 9e31bff | 2012-08-01 00:08:07 -0400 | [diff] [blame] | 1960 | |
Derek Foreman | 1281a36 | 2015-07-31 16:55:32 -0500 | [diff] [blame] | 1961 | if (!pointer || |
| 1962 | pointer->button_count == 0 || |
| 1963 | pointer->grab_serial != serial || |
| 1964 | pointer->focus == NULL) |
Kristian Høgsberg | 70f2901 | 2014-01-09 15:43:17 -0800 | [diff] [blame] | 1965 | return; |
| 1966 | |
Derek Foreman | 1281a36 | 2015-07-31 16:55:32 -0500 | [diff] [blame] | 1967 | surface = weston_surface_get_main_surface(pointer->focus->surface); |
Kristian Høgsberg | 70f2901 | 2014-01-09 15:43:17 -0800 | [diff] [blame] | 1968 | if (surface != shsurf->surface) |
Kristian Høgsberg | 9e31bff | 2012-08-01 00:08:07 -0400 | [diff] [blame] | 1969 | return; |
| 1970 | |
Derek Foreman | 1281a36 | 2015-07-31 16:55:32 -0500 | [diff] [blame] | 1971 | if (surface_resize(shsurf, pointer, edges) < 0) |
Kristian Høgsberg | 9e31bff | 2012-08-01 00:08:07 -0400 | [diff] [blame] | 1972 | wl_resource_post_no_memory(resource); |
| 1973 | } |
| 1974 | |
Scott Moreau | c3e54eb | 2012-04-17 19:06:20 -0600 | [diff] [blame] | 1975 | static void |
Rafael Antognolli | e2a3455 | 2013-12-03 15:35:45 -0200 | [diff] [blame] | 1976 | shell_surface_resize(struct wl_client *client, struct wl_resource *resource, |
| 1977 | struct wl_resource *seat_resource, uint32_t serial, |
| 1978 | uint32_t edges) |
| 1979 | { |
| 1980 | common_surface_resize(resource, seat_resource, serial, edges); |
| 1981 | } |
| 1982 | |
| 1983 | static void |
Kristian Høgsberg | 6848c25 | 2013-05-08 22:02:59 -0400 | [diff] [blame] | 1984 | busy_cursor_grab_focus(struct weston_pointer_grab *base) |
Scott Moreau | c3e54eb | 2012-04-17 19:06:20 -0600 | [diff] [blame] | 1985 | { |
Kristian Høgsberg | d56bd90 | 2012-06-05 09:58:51 -0400 | [diff] [blame] | 1986 | struct shell_grab *grab = (struct shell_grab *) base; |
Kristian Høgsberg | 6848c25 | 2013-05-08 22:02:59 -0400 | [diff] [blame] | 1987 | struct weston_pointer *pointer = base->pointer; |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 1988 | struct weston_view *view; |
Kristian Høgsberg | 6848c25 | 2013-05-08 22:02:59 -0400 | [diff] [blame] | 1989 | wl_fixed_t sx, sy; |
| 1990 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 1991 | view = weston_compositor_pick_view(pointer->seat->compositor, |
| 1992 | pointer->x, pointer->y, |
| 1993 | &sx, &sy); |
Scott Moreau | c3e54eb | 2012-04-17 19:06:20 -0600 | [diff] [blame] | 1994 | |
Kristian Høgsberg | 2bff94e | 2014-02-11 12:22:51 -0800 | [diff] [blame] | 1995 | if (!grab->shsurf || grab->shsurf->surface != view->surface) { |
| 1996 | shell_grab_end(grab); |
| 1997 | free(grab); |
| 1998 | } |
Scott Moreau | c3e54eb | 2012-04-17 19:06:20 -0600 | [diff] [blame] | 1999 | } |
| 2000 | |
| 2001 | static void |
Giulio Camuffo | 1959ab8 | 2013-11-14 23:42:52 +0100 | [diff] [blame] | 2002 | busy_cursor_grab_motion(struct weston_pointer_grab *grab, uint32_t time, |
Jonas Ådahl | d251010 | 2014-10-05 21:39:14 +0200 | [diff] [blame] | 2003 | struct weston_pointer_motion_event *event) |
Scott Moreau | c3e54eb | 2012-04-17 19:06:20 -0600 | [diff] [blame] | 2004 | { |
Jonas Ådahl | d251010 | 2014-10-05 21:39:14 +0200 | [diff] [blame] | 2005 | weston_pointer_move(grab->pointer, event); |
Kristian Høgsberg | d56bd90 | 2012-06-05 09:58:51 -0400 | [diff] [blame] | 2006 | } |
Scott Moreau | c3e54eb | 2012-04-17 19:06:20 -0600 | [diff] [blame] | 2007 | |
Kristian Høgsberg | d56bd90 | 2012-06-05 09:58:51 -0400 | [diff] [blame] | 2008 | static void |
Kristian Høgsberg | 02bbabb | 2013-05-06 22:15:05 -0400 | [diff] [blame] | 2009 | busy_cursor_grab_button(struct weston_pointer_grab *base, |
Kristian Høgsberg | d56bd90 | 2012-06-05 09:58:51 -0400 | [diff] [blame] | 2010 | uint32_t time, uint32_t button, uint32_t state) |
| 2011 | { |
Kristian Høgsberg | bbe9839 | 2012-08-01 00:20:21 -0400 | [diff] [blame] | 2012 | struct shell_grab *grab = (struct shell_grab *) base; |
Kristian Høgsberg | e122b7b | 2013-05-08 16:47:00 -0400 | [diff] [blame] | 2013 | struct shell_surface *shsurf = grab->shsurf; |
Derek Foreman | 794fa0e | 2015-07-15 13:00:38 -0500 | [diff] [blame] | 2014 | struct weston_pointer *pointer = grab->grab.pointer; |
| 2015 | struct weston_seat *seat = pointer->seat; |
Kristian Høgsberg | bbe9839 | 2012-08-01 00:20:21 -0400 | [diff] [blame] | 2016 | |
Kristian Høgsberg | bbe9839 | 2012-08-01 00:20:21 -0400 | [diff] [blame] | 2017 | if (shsurf && button == BTN_LEFT && state) { |
Jonas Ådahl | 1fa6ded | 2014-10-18 13:24:53 +0200 | [diff] [blame^] | 2018 | activate(shsurf->shell, shsurf->view, seat, true); |
Derek Foreman | 794fa0e | 2015-07-15 13:00:38 -0500 | [diff] [blame] | 2019 | surface_move(shsurf, pointer, false); |
Kristian Høgsberg | 0c36903 | 2013-02-14 21:31:44 -0500 | [diff] [blame] | 2020 | } else if (shsurf && button == BTN_RIGHT && state) { |
Jonas Ådahl | 1fa6ded | 2014-10-18 13:24:53 +0200 | [diff] [blame^] | 2021 | activate(shsurf->shell, shsurf->view, seat, true); |
Derek Foreman | 74de469 | 2015-07-15 13:00:39 -0500 | [diff] [blame] | 2022 | surface_rotate(shsurf, pointer); |
Kristian Høgsberg | bbe9839 | 2012-08-01 00:20:21 -0400 | [diff] [blame] | 2023 | } |
Kristian Høgsberg | d56bd90 | 2012-06-05 09:58:51 -0400 | [diff] [blame] | 2024 | } |
| 2025 | |
Jonas Ådahl | 1ea343e | 2013-10-25 23:18:05 +0200 | [diff] [blame] | 2026 | static void |
| 2027 | busy_cursor_grab_cancel(struct weston_pointer_grab *base) |
| 2028 | { |
| 2029 | struct shell_grab *grab = (struct shell_grab *) base; |
| 2030 | |
| 2031 | shell_grab_end(grab); |
| 2032 | free(grab); |
| 2033 | } |
| 2034 | |
Kristian Høgsberg | 02bbabb | 2013-05-06 22:15:05 -0400 | [diff] [blame] | 2035 | static const struct weston_pointer_grab_interface busy_cursor_grab_interface = { |
Kristian Høgsberg | d56bd90 | 2012-06-05 09:58:51 -0400 | [diff] [blame] | 2036 | busy_cursor_grab_focus, |
| 2037 | busy_cursor_grab_motion, |
| 2038 | busy_cursor_grab_button, |
Jonas Ådahl | 0336ca0 | 2014-10-04 16:28:29 +0200 | [diff] [blame] | 2039 | noop_grab_axis, |
Peter Hutterer | 87743e9 | 2016-01-18 16:38:22 +1000 | [diff] [blame] | 2040 | noop_grab_axis_source, |
| 2041 | noop_grab_frame, |
Jonas Ådahl | 1ea343e | 2013-10-25 23:18:05 +0200 | [diff] [blame] | 2042 | busy_cursor_grab_cancel, |
Kristian Høgsberg | d56bd90 | 2012-06-05 09:58:51 -0400 | [diff] [blame] | 2043 | }; |
| 2044 | |
| 2045 | static void |
Kristian Høgsberg | 02bbabb | 2013-05-06 22:15:05 -0400 | [diff] [blame] | 2046 | set_busy_cursor(struct shell_surface *shsurf, struct weston_pointer *pointer) |
Kristian Høgsberg | d56bd90 | 2012-06-05 09:58:51 -0400 | [diff] [blame] | 2047 | { |
| 2048 | struct shell_grab *grab; |
Kristian Høgsberg | d56bd90 | 2012-06-05 09:58:51 -0400 | [diff] [blame] | 2049 | |
Kristian Høgsberg | 2bff94e | 2014-02-11 12:22:51 -0800 | [diff] [blame] | 2050 | if (pointer->grab->interface == &busy_cursor_grab_interface) |
| 2051 | return; |
| 2052 | |
Kristian Høgsberg | d56bd90 | 2012-06-05 09:58:51 -0400 | [diff] [blame] | 2053 | grab = malloc(sizeof *grab); |
| 2054 | if (!grab) |
Scott Moreau | c3e54eb | 2012-04-17 19:06:20 -0600 | [diff] [blame] | 2055 | return; |
| 2056 | |
Ander Conselvan de Oliveira | b9d2a0f | 2012-06-28 18:08:05 +0300 | [diff] [blame] | 2057 | shell_grab_start(grab, &busy_cursor_grab_interface, shsurf, pointer, |
Jonas Ådahl | 6d6fb61 | 2015-11-17 16:00:33 +0800 | [diff] [blame] | 2058 | WESTON_DESKTOP_SHELL_CURSOR_BUSY); |
Ander Conselvan de Oliveira | e5a1aee | 2014-04-09 17:39:39 +0300 | [diff] [blame] | 2059 | /* Mark the shsurf as ungrabbed so that button binding is able |
| 2060 | * to move it. */ |
| 2061 | shsurf->grabbed = 0; |
Kristian Høgsberg | d56bd90 | 2012-06-05 09:58:51 -0400 | [diff] [blame] | 2062 | } |
Scott Moreau | c3e54eb | 2012-04-17 19:06:20 -0600 | [diff] [blame] | 2063 | |
Kristian Høgsberg | d56bd90 | 2012-06-05 09:58:51 -0400 | [diff] [blame] | 2064 | static void |
Kristian Høgsberg | 2bff94e | 2014-02-11 12:22:51 -0800 | [diff] [blame] | 2065 | end_busy_cursor(struct weston_compositor *compositor, struct wl_client *client) |
Kristian Høgsberg | d56bd90 | 2012-06-05 09:58:51 -0400 | [diff] [blame] | 2066 | { |
Kristian Høgsberg | 2bff94e | 2014-02-11 12:22:51 -0800 | [diff] [blame] | 2067 | struct shell_grab *grab; |
| 2068 | struct weston_seat *seat; |
Kristian Høgsberg | d56bd90 | 2012-06-05 09:58:51 -0400 | [diff] [blame] | 2069 | |
Kristian Høgsberg | 2bff94e | 2014-02-11 12:22:51 -0800 | [diff] [blame] | 2070 | wl_list_for_each(seat, &compositor->seat_list, link) { |
Derek Foreman | 1281a36 | 2015-07-31 16:55:32 -0500 | [diff] [blame] | 2071 | struct weston_pointer *pointer = weston_seat_get_pointer(seat); |
| 2072 | |
| 2073 | if (!pointer) |
Kristian Høgsberg | 2bff94e | 2014-02-11 12:22:51 -0800 | [diff] [blame] | 2074 | continue; |
| 2075 | |
Derek Foreman | 1281a36 | 2015-07-31 16:55:32 -0500 | [diff] [blame] | 2076 | grab = (struct shell_grab *) pointer->grab; |
Kristian Høgsberg | 2bff94e | 2014-02-11 12:22:51 -0800 | [diff] [blame] | 2077 | if (grab->grab.interface == &busy_cursor_grab_interface && |
Derek Foreman | c0c1497 | 2015-09-11 14:30:39 -0500 | [diff] [blame] | 2078 | grab->shsurf->resource && |
Kristian Høgsberg | 2bff94e | 2014-02-11 12:22:51 -0800 | [diff] [blame] | 2079 | wl_resource_get_client(grab->shsurf->resource) == client) { |
| 2080 | shell_grab_end(grab); |
| 2081 | free(grab); |
| 2082 | } |
Scott Moreau | c3e54eb | 2012-04-17 19:06:20 -0600 | [diff] [blame] | 2083 | } |
Scott Moreau | c3e54eb | 2012-04-17 19:06:20 -0600 | [diff] [blame] | 2084 | } |
| 2085 | |
Scott Moreau | 9521d5e | 2012-04-19 13:06:17 -0600 | [diff] [blame] | 2086 | static void |
Kristian Høgsberg | 2bff94e | 2014-02-11 12:22:51 -0800 | [diff] [blame] | 2087 | handle_shell_client_destroy(struct wl_listener *listener, void *data); |
| 2088 | |
| 2089 | static int |
| 2090 | xdg_ping_timeout_handler(void *data) |
| 2091 | { |
| 2092 | struct shell_client *sc = data; |
| 2093 | struct weston_seat *seat; |
| 2094 | struct shell_surface *shsurf; |
| 2095 | |
| 2096 | /* Client is not responding */ |
| 2097 | sc->unresponsive = 1; |
Kristian Høgsberg | 2bff94e | 2014-02-11 12:22:51 -0800 | [diff] [blame] | 2098 | wl_list_for_each(seat, &sc->shell->compositor->seat_list, link) { |
Derek Foreman | 1281a36 | 2015-07-31 16:55:32 -0500 | [diff] [blame] | 2099 | struct weston_pointer *pointer = weston_seat_get_pointer(seat); |
| 2100 | |
| 2101 | if (!pointer || |
| 2102 | !pointer->focus || |
| 2103 | !pointer->focus->surface->resource) |
Kristian Høgsberg | 2bff94e | 2014-02-11 12:22:51 -0800 | [diff] [blame] | 2104 | continue; |
Michael Vetter | 2a18a52 | 2015-05-15 17:17:47 +0200 | [diff] [blame] | 2105 | |
Derek Foreman | 1281a36 | 2015-07-31 16:55:32 -0500 | [diff] [blame] | 2106 | shsurf = get_shell_surface(pointer->focus->surface); |
Bryce Harrington | 22b1f93 | 2015-09-23 17:30:43 -0700 | [diff] [blame] | 2107 | if (shsurf && shsurf->resource && |
Kristian Høgsberg | 2bff94e | 2014-02-11 12:22:51 -0800 | [diff] [blame] | 2108 | wl_resource_get_client(shsurf->resource) == sc->client) |
Derek Foreman | 1281a36 | 2015-07-31 16:55:32 -0500 | [diff] [blame] | 2109 | set_busy_cursor(shsurf, pointer); |
Kristian Høgsberg | 2bff94e | 2014-02-11 12:22:51 -0800 | [diff] [blame] | 2110 | } |
| 2111 | |
| 2112 | return 1; |
| 2113 | } |
| 2114 | |
| 2115 | static void |
| 2116 | handle_xdg_ping(struct shell_surface *shsurf, uint32_t serial) |
| 2117 | { |
| 2118 | struct weston_compositor *compositor = shsurf->shell->compositor; |
Jason Ekstrand | 9e9512f | 2014-04-16 21:12:10 -0500 | [diff] [blame] | 2119 | struct shell_client *sc = shsurf->owner; |
Kristian Høgsberg | 2bff94e | 2014-02-11 12:22:51 -0800 | [diff] [blame] | 2120 | struct wl_event_loop *loop; |
Kristian Høgsberg | dd62aba | 2014-02-12 09:56:19 -0800 | [diff] [blame] | 2121 | static const int ping_timeout = 200; |
Kristian Høgsberg | 2bff94e | 2014-02-11 12:22:51 -0800 | [diff] [blame] | 2122 | |
Kristian Høgsberg | 2bff94e | 2014-02-11 12:22:51 -0800 | [diff] [blame] | 2123 | if (sc->unresponsive) { |
| 2124 | xdg_ping_timeout_handler(sc); |
| 2125 | return; |
| 2126 | } |
| 2127 | |
| 2128 | sc->ping_serial = serial; |
| 2129 | loop = wl_display_get_event_loop(compositor->wl_display); |
| 2130 | if (sc->ping_timer == NULL) |
| 2131 | sc->ping_timer = |
| 2132 | wl_event_loop_add_timer(loop, |
| 2133 | xdg_ping_timeout_handler, sc); |
| 2134 | if (sc->ping_timer == NULL) |
| 2135 | return; |
| 2136 | |
| 2137 | wl_event_source_timer_update(sc->ping_timer, ping_timeout); |
| 2138 | |
Kristian Høgsberg | dd62aba | 2014-02-12 09:56:19 -0800 | [diff] [blame] | 2139 | if (shell_surface_is_xdg_surface(shsurf) || |
| 2140 | shell_surface_is_xdg_popup(shsurf)) |
| 2141 | xdg_shell_send_ping(sc->resource, serial); |
Bryce Harrington | 22b1f93 | 2015-09-23 17:30:43 -0700 | [diff] [blame] | 2142 | else if (shell_surface_is_wl_shell_surface(shsurf) |
| 2143 | && shsurf->resource) |
Kristian Høgsberg | dd62aba | 2014-02-12 09:56:19 -0800 | [diff] [blame] | 2144 | wl_shell_surface_send_ping(shsurf->resource, serial); |
Kristian Høgsberg | 2bff94e | 2014-02-11 12:22:51 -0800 | [diff] [blame] | 2145 | } |
| 2146 | |
Scott Moreau | ff1db4a | 2012-04-17 19:06:18 -0600 | [diff] [blame] | 2147 | static void |
| 2148 | ping_handler(struct weston_surface *surface, uint32_t serial) |
| 2149 | { |
Kristian Høgsberg | b71302e | 2012-05-10 12:28:35 -0400 | [diff] [blame] | 2150 | struct shell_surface *shsurf = get_shell_surface(surface); |
Scott Moreau | ff1db4a | 2012-04-17 19:06:18 -0600 | [diff] [blame] | 2151 | |
| 2152 | if (!shsurf) |
| 2153 | return; |
Jason Ekstrand | 651f00e | 2013-06-14 10:07:54 -0500 | [diff] [blame] | 2154 | if (!shsurf->resource) |
Kristian Høgsberg | ca535c1 | 2012-04-21 23:20:07 -0400 | [diff] [blame] | 2155 | return; |
Ander Conselvan de Oliveira | eac9a46 | 2012-07-16 14:15:48 +0300 | [diff] [blame] | 2156 | if (shsurf->surface == shsurf->shell->grab_surface) |
| 2157 | return; |
Jonas Ådahl | d3a3ee9 | 2016-02-26 14:02:06 +0800 | [diff] [blame] | 2158 | if (!shsurf->owner) |
| 2159 | return; |
Ander Conselvan de Oliveira | eac9a46 | 2012-07-16 14:15:48 +0300 | [diff] [blame] | 2160 | |
Kristian Høgsberg | dd62aba | 2014-02-12 09:56:19 -0800 | [diff] [blame] | 2161 | handle_xdg_ping(shsurf, serial); |
Scott Moreau | ff1db4a | 2012-04-17 19:06:18 -0600 | [diff] [blame] | 2162 | } |
| 2163 | |
| 2164 | static void |
Kristian Høgsberg | d56bd90 | 2012-06-05 09:58:51 -0400 | [diff] [blame] | 2165 | handle_pointer_focus(struct wl_listener *listener, void *data) |
| 2166 | { |
Kristian Høgsberg | 02bbabb | 2013-05-06 22:15:05 -0400 | [diff] [blame] | 2167 | struct weston_pointer *pointer = data; |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 2168 | struct weston_view *view = pointer->focus; |
Kristian Høgsberg | d56bd90 | 2012-06-05 09:58:51 -0400 | [diff] [blame] | 2169 | struct weston_compositor *compositor; |
Kristian Høgsberg | d56bd90 | 2012-06-05 09:58:51 -0400 | [diff] [blame] | 2170 | uint32_t serial; |
| 2171 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 2172 | if (!view) |
Kristian Høgsberg | d56bd90 | 2012-06-05 09:58:51 -0400 | [diff] [blame] | 2173 | return; |
| 2174 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 2175 | compositor = view->surface->compositor; |
Kristian Høgsberg | e11ef64 | 2014-02-11 16:35:22 -0800 | [diff] [blame] | 2176 | serial = wl_display_next_serial(compositor->wl_display); |
| 2177 | ping_handler(view->surface, serial); |
Kristian Høgsberg | d56bd90 | 2012-06-05 09:58:51 -0400 | [diff] [blame] | 2178 | } |
| 2179 | |
| 2180 | static void |
Jasper St. Pierre | faf27a9 | 2013-12-09 17:36:28 -0500 | [diff] [blame] | 2181 | shell_surface_lose_keyboard_focus(struct shell_surface *shsurf) |
| 2182 | { |
| 2183 | if (--shsurf->focus_count == 0) |
Jasper St. Pierre | 973d787 | 2014-05-06 08:44:29 -0400 | [diff] [blame] | 2184 | shell_surface_state_changed(shsurf); |
Jasper St. Pierre | faf27a9 | 2013-12-09 17:36:28 -0500 | [diff] [blame] | 2185 | } |
| 2186 | |
| 2187 | static void |
| 2188 | shell_surface_gain_keyboard_focus(struct shell_surface *shsurf) |
| 2189 | { |
| 2190 | if (shsurf->focus_count++ == 0) |
Jasper St. Pierre | 973d787 | 2014-05-06 08:44:29 -0400 | [diff] [blame] | 2191 | shell_surface_state_changed(shsurf); |
Jasper St. Pierre | faf27a9 | 2013-12-09 17:36:28 -0500 | [diff] [blame] | 2192 | } |
| 2193 | |
| 2194 | static void |
| 2195 | handle_keyboard_focus(struct wl_listener *listener, void *data) |
| 2196 | { |
| 2197 | struct weston_keyboard *keyboard = data; |
| 2198 | struct shell_seat *seat = get_shell_seat(keyboard->seat); |
| 2199 | |
| 2200 | if (seat->focused_surface) { |
| 2201 | struct shell_surface *shsurf = get_shell_surface(seat->focused_surface); |
| 2202 | if (shsurf) |
| 2203 | shell_surface_lose_keyboard_focus(shsurf); |
| 2204 | } |
| 2205 | |
| 2206 | seat->focused_surface = keyboard->focus; |
| 2207 | |
| 2208 | if (seat->focused_surface) { |
| 2209 | struct shell_surface *shsurf = get_shell_surface(seat->focused_surface); |
| 2210 | if (shsurf) |
| 2211 | shell_surface_gain_keyboard_focus(shsurf); |
| 2212 | } |
| 2213 | } |
| 2214 | |
| 2215 | static void |
Kristian Høgsberg | dd62aba | 2014-02-12 09:56:19 -0800 | [diff] [blame] | 2216 | shell_client_pong(struct shell_client *sc, uint32_t serial) |
Rafael Antognolli | e2a3455 | 2013-12-03 15:35:45 -0200 | [diff] [blame] | 2217 | { |
Kristian Høgsberg | dd62aba | 2014-02-12 09:56:19 -0800 | [diff] [blame] | 2218 | if (sc->ping_serial != serial) |
| 2219 | return; |
Rafael Antognolli | e2a3455 | 2013-12-03 15:35:45 -0200 | [diff] [blame] | 2220 | |
Kristian Høgsberg | dd62aba | 2014-02-12 09:56:19 -0800 | [diff] [blame] | 2221 | sc->unresponsive = 0; |
| 2222 | end_busy_cursor(sc->shell->compositor, sc->client); |
Rafael Antognolli | e2a3455 | 2013-12-03 15:35:45 -0200 | [diff] [blame] | 2223 | |
Kristian Høgsberg | dd62aba | 2014-02-12 09:56:19 -0800 | [diff] [blame] | 2224 | if (sc->ping_timer) { |
| 2225 | wl_event_source_remove(sc->ping_timer); |
| 2226 | sc->ping_timer = NULL; |
| 2227 | } |
| 2228 | |
| 2229 | } |
| 2230 | |
| 2231 | static void |
| 2232 | shell_surface_pong(struct wl_client *client, |
| 2233 | struct wl_resource *resource, uint32_t serial) |
| 2234 | { |
Jason Ekstrand | 9e9512f | 2014-04-16 21:12:10 -0500 | [diff] [blame] | 2235 | struct shell_surface *shsurf = wl_resource_get_user_data(resource); |
| 2236 | struct shell_client *sc = shsurf->owner; |
Kristian Høgsberg | dd62aba | 2014-02-12 09:56:19 -0800 | [diff] [blame] | 2237 | |
Kristian Høgsberg | dd62aba | 2014-02-12 09:56:19 -0800 | [diff] [blame] | 2238 | shell_client_pong(sc, serial); |
Rafael Antognolli | e2a3455 | 2013-12-03 15:35:45 -0200 | [diff] [blame] | 2239 | } |
| 2240 | |
| 2241 | static void |
Giulio Camuffo | 62942ad | 2013-09-11 18:20:47 +0200 | [diff] [blame] | 2242 | set_title(struct shell_surface *shsurf, const char *title) |
| 2243 | { |
| 2244 | free(shsurf->title); |
| 2245 | shsurf->title = strdup(title); |
Pekka Paalanen | b502654 | 2014-11-12 15:09:24 +0200 | [diff] [blame] | 2246 | shsurf->surface->timeline.force_refresh = 1; |
| 2247 | } |
| 2248 | |
| 2249 | static void |
Giulio Camuffo | a8e9b41 | 2015-01-27 19:10:37 +0200 | [diff] [blame] | 2250 | set_pid(struct shell_surface *shsurf, pid_t pid) |
| 2251 | { |
| 2252 | /* We have no use for it */ |
| 2253 | } |
| 2254 | |
| 2255 | static void |
Pekka Paalanen | b502654 | 2014-11-12 15:09:24 +0200 | [diff] [blame] | 2256 | set_type(struct shell_surface *shsurf, enum shell_surface_type t) |
| 2257 | { |
| 2258 | shsurf->type = t; |
| 2259 | shsurf->surface->timeline.force_refresh = 1; |
Giulio Camuffo | 62942ad | 2013-09-11 18:20:47 +0200 | [diff] [blame] | 2260 | } |
| 2261 | |
| 2262 | static void |
Jasper St. Pierre | ccf48fb | 2014-05-02 10:21:38 -0400 | [diff] [blame] | 2263 | set_window_geometry(struct shell_surface *shsurf, |
| 2264 | 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] | 2265 | { |
Jasper St. Pierre | ccf48fb | 2014-05-02 10:21:38 -0400 | [diff] [blame] | 2266 | shsurf->next_geometry.x = x; |
| 2267 | shsurf->next_geometry.y = y; |
| 2268 | shsurf->next_geometry.width = width; |
| 2269 | shsurf->next_geometry.height = height; |
| 2270 | shsurf->has_next_geometry = true; |
Kristian Høgsberg | e5c1ae9 | 2014-04-30 16:28:41 -0700 | [diff] [blame] | 2271 | } |
| 2272 | |
| 2273 | static void |
Kristian Høgsberg | e7afd91 | 2012-05-02 09:47:44 -0400 | [diff] [blame] | 2274 | shell_surface_set_title(struct wl_client *client, |
| 2275 | struct wl_resource *resource, const char *title) |
| 2276 | { |
Jason Ekstrand | 651f00e | 2013-06-14 10:07:54 -0500 | [diff] [blame] | 2277 | struct shell_surface *shsurf = wl_resource_get_user_data(resource); |
Kristian Høgsberg | e7afd91 | 2012-05-02 09:47:44 -0400 | [diff] [blame] | 2278 | |
Giulio Camuffo | 62942ad | 2013-09-11 18:20:47 +0200 | [diff] [blame] | 2279 | set_title(shsurf, title); |
Kristian Høgsberg | e7afd91 | 2012-05-02 09:47:44 -0400 | [diff] [blame] | 2280 | } |
| 2281 | |
| 2282 | static void |
| 2283 | shell_surface_set_class(struct wl_client *client, |
| 2284 | struct wl_resource *resource, const char *class) |
| 2285 | { |
Jason Ekstrand | 651f00e | 2013-06-14 10:07:54 -0500 | [diff] [blame] | 2286 | struct shell_surface *shsurf = wl_resource_get_user_data(resource); |
Kristian Høgsberg | e7afd91 | 2012-05-02 09:47:44 -0400 | [diff] [blame] | 2287 | |
| 2288 | free(shsurf->class); |
| 2289 | shsurf->class = strdup(class); |
Pekka Paalanen | b502654 | 2014-11-12 15:09:24 +0200 | [diff] [blame] | 2290 | shsurf->surface->timeline.force_refresh = 1; |
Kristian Høgsberg | e7afd91 | 2012-05-02 09:47:44 -0400 | [diff] [blame] | 2291 | } |
| 2292 | |
Alex Wu | 4539b08 | 2012-03-01 12:57:46 +0800 | [diff] [blame] | 2293 | static void |
Alexander Larsson | f82b6ca | 2013-05-28 16:23:39 +0200 | [diff] [blame] | 2294 | restore_output_mode(struct weston_output *output) |
| 2295 | { |
Armin Krezović | c77f258 | 2016-06-23 11:59:32 +0200 | [diff] [blame] | 2296 | if (output && output->original_mode) |
Derek Foreman | 6ae7bc9 | 2014-11-04 10:47:33 -0600 | [diff] [blame] | 2297 | weston_output_mode_switch_to_native(output); |
Alexander Larsson | f82b6ca | 2013-05-28 16:23:39 +0200 | [diff] [blame] | 2298 | } |
| 2299 | |
| 2300 | static void |
| 2301 | restore_all_output_modes(struct weston_compositor *compositor) |
| 2302 | { |
| 2303 | struct weston_output *output; |
| 2304 | |
| 2305 | wl_list_for_each(output, &compositor->output_list, link) |
| 2306 | restore_output_mode(output); |
| 2307 | } |
| 2308 | |
Philip Withnall | 07926d9 | 2013-11-25 18:01:40 +0000 | [diff] [blame] | 2309 | /* The surface will be inserted into the list immediately after the link |
| 2310 | * returned by this function (i.e. will be stacked immediately above the |
| 2311 | * returned link). */ |
Giulio Camuffo | 412e6a5 | 2014-07-09 22:12:56 +0300 | [diff] [blame] | 2312 | static struct weston_layer_entry * |
Philip Withnall | 07926d9 | 2013-11-25 18:01:40 +0000 | [diff] [blame] | 2313 | shell_surface_calculate_layer_link (struct shell_surface *shsurf) |
| 2314 | { |
| 2315 | struct workspace *ws; |
Kristian Høgsberg | ead5242 | 2014-01-01 13:51:52 -0800 | [diff] [blame] | 2316 | struct weston_view *parent; |
Philip Withnall | 07926d9 | 2013-11-25 18:01:40 +0000 | [diff] [blame] | 2317 | |
| 2318 | switch (shsurf->type) { |
Ander Conselvan de Oliveira | ef6a7e4 | 2014-04-30 14:15:14 +0300 | [diff] [blame] | 2319 | case SHELL_SURFACE_XWAYLAND: |
| 2320 | return &shsurf->shell->fullscreen_layer.view_list; |
| 2321 | |
| 2322 | case SHELL_SURFACE_NONE: |
| 2323 | return NULL; |
| 2324 | |
Kristian Høgsberg | ead5242 | 2014-01-01 13:51:52 -0800 | [diff] [blame] | 2325 | case SHELL_SURFACE_POPUP: |
| 2326 | case SHELL_SURFACE_TOPLEVEL: |
Emilio Pozuelo Monfort | 9e7c759 | 2014-01-30 14:01:10 +0100 | [diff] [blame] | 2327 | if (shsurf->state.fullscreen && !shsurf->state.lowered) { |
Rafael Antognolli | 03b1659 | 2013-12-03 15:35:42 -0200 | [diff] [blame] | 2328 | return &shsurf->shell->fullscreen_layer.view_list; |
Rafael Antognolli | ed207b4 | 2013-12-03 15:35:43 -0200 | [diff] [blame] | 2329 | } else if (shsurf->parent) { |
Kristian Høgsberg | d55db69 | 2014-01-01 12:26:14 -0800 | [diff] [blame] | 2330 | /* Move the surface to its parent layer so |
| 2331 | * that surfaces which are transient for |
| 2332 | * fullscreen surfaces don't get hidden by the |
| 2333 | * fullscreen surfaces. */ |
Rafael Antognolli | ed207b4 | 2013-12-03 15:35:43 -0200 | [diff] [blame] | 2334 | |
| 2335 | /* TODO: Handle a parent with multiple views */ |
| 2336 | parent = get_default_view(shsurf->parent); |
| 2337 | if (parent) |
Giulio Camuffo | 412e6a5 | 2014-07-09 22:12:56 +0300 | [diff] [blame] | 2338 | return container_of(parent->layer_link.link.prev, |
| 2339 | struct weston_layer_entry, link); |
Rafael Antognolli | ed207b4 | 2013-12-03 15:35:43 -0200 | [diff] [blame] | 2340 | } |
Philip Withnall | 07926d9 | 2013-11-25 18:01:40 +0000 | [diff] [blame] | 2341 | |
Ander Conselvan de Oliveira | ef6a7e4 | 2014-04-30 14:15:14 +0300 | [diff] [blame] | 2342 | /* Move the surface to a normal workspace layer so that surfaces |
| 2343 | * which were previously fullscreen or transient are no longer |
| 2344 | * rendered on top. */ |
| 2345 | ws = get_current_workspace(shsurf->shell); |
| 2346 | return &ws->layer.view_list; |
Philip Withnall | 07926d9 | 2013-11-25 18:01:40 +0000 | [diff] [blame] | 2347 | } |
| 2348 | |
Ander Conselvan de Oliveira | ef6a7e4 | 2014-04-30 14:15:14 +0300 | [diff] [blame] | 2349 | assert(0 && "Unknown shell surface type"); |
Philip Withnall | 07926d9 | 2013-11-25 18:01:40 +0000 | [diff] [blame] | 2350 | } |
| 2351 | |
Philip Withnall | 648a4dd | 2013-11-25 18:01:44 +0000 | [diff] [blame] | 2352 | static void |
| 2353 | shell_surface_update_child_surface_layers (struct shell_surface *shsurf) |
| 2354 | { |
| 2355 | struct shell_surface *child; |
Giulio Camuffo | 412e6a5 | 2014-07-09 22:12:56 +0300 | [diff] [blame] | 2356 | struct weston_layer_entry *prev; |
Philip Withnall | 648a4dd | 2013-11-25 18:01:44 +0000 | [diff] [blame] | 2357 | |
| 2358 | /* Move the child layers to the same workspace as shsurf. They will be |
| 2359 | * stacked above shsurf. */ |
| 2360 | wl_list_for_each_reverse(child, &shsurf->children_list, children_link) { |
Giulio Camuffo | 412e6a5 | 2014-07-09 22:12:56 +0300 | [diff] [blame] | 2361 | 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] | 2362 | weston_view_damage_below(child->view); |
Philip Withnall | 648a4dd | 2013-11-25 18:01:44 +0000 | [diff] [blame] | 2363 | weston_view_geometry_dirty(child->view); |
Giulio Camuffo | 412e6a5 | 2014-07-09 22:12:56 +0300 | [diff] [blame] | 2364 | prev = container_of(shsurf->view->layer_link.link.prev, |
| 2365 | struct weston_layer_entry, link); |
| 2366 | weston_layer_entry_remove(&child->view->layer_link); |
| 2367 | weston_layer_entry_insert(prev, |
| 2368 | &child->view->layer_link); |
Philip Withnall | 648a4dd | 2013-11-25 18:01:44 +0000 | [diff] [blame] | 2369 | weston_view_geometry_dirty(child->view); |
| 2370 | weston_surface_damage(child->surface); |
| 2371 | |
| 2372 | /* Recurse. We don’t expect this to recurse very far (if |
| 2373 | * at all) because that would imply we have transient |
| 2374 | * (or popup) children of transient surfaces, which |
| 2375 | * would be unusual. */ |
| 2376 | shell_surface_update_child_surface_layers(child); |
| 2377 | } |
| 2378 | } |
| 2379 | } |
| 2380 | |
Philip Withnall | e1d75ae | 2013-11-25 18:01:41 +0000 | [diff] [blame] | 2381 | /* 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] | 2382 | * geometry to ensure the changes are redrawn. |
| 2383 | * |
| 2384 | * If any child surfaces exist and are mapped, ensure they’re in the same layer |
| 2385 | * as this surface. */ |
Philip Withnall | e1d75ae | 2013-11-25 18:01:41 +0000 | [diff] [blame] | 2386 | static void |
| 2387 | shell_surface_update_layer(struct shell_surface *shsurf) |
| 2388 | { |
Giulio Camuffo | 412e6a5 | 2014-07-09 22:12:56 +0300 | [diff] [blame] | 2389 | struct weston_layer_entry *new_layer_link; |
Philip Withnall | e1d75ae | 2013-11-25 18:01:41 +0000 | [diff] [blame] | 2390 | |
| 2391 | new_layer_link = shell_surface_calculate_layer_link(shsurf); |
| 2392 | |
Ander Conselvan de Oliveira | ef6a7e4 | 2014-04-30 14:15:14 +0300 | [diff] [blame] | 2393 | if (new_layer_link == NULL) |
| 2394 | return; |
Philip Withnall | e1d75ae | 2013-11-25 18:01:41 +0000 | [diff] [blame] | 2395 | if (new_layer_link == &shsurf->view->layer_link) |
| 2396 | return; |
| 2397 | |
| 2398 | weston_view_geometry_dirty(shsurf->view); |
Giulio Camuffo | 412e6a5 | 2014-07-09 22:12:56 +0300 | [diff] [blame] | 2399 | weston_layer_entry_remove(&shsurf->view->layer_link); |
| 2400 | weston_layer_entry_insert(new_layer_link, &shsurf->view->layer_link); |
Philip Withnall | e1d75ae | 2013-11-25 18:01:41 +0000 | [diff] [blame] | 2401 | weston_view_geometry_dirty(shsurf->view); |
| 2402 | weston_surface_damage(shsurf->surface); |
Philip Withnall | 648a4dd | 2013-11-25 18:01:44 +0000 | [diff] [blame] | 2403 | |
| 2404 | shell_surface_update_child_surface_layers(shsurf); |
Philip Withnall | e1d75ae | 2013-11-25 18:01:41 +0000 | [diff] [blame] | 2405 | } |
| 2406 | |
Alexander Larsson | f82b6ca | 2013-05-28 16:23:39 +0200 | [diff] [blame] | 2407 | static void |
Philip Withnall | dc4332f | 2013-11-25 18:01:38 +0000 | [diff] [blame] | 2408 | shell_surface_set_parent(struct shell_surface *shsurf, |
| 2409 | struct weston_surface *parent) |
| 2410 | { |
| 2411 | shsurf->parent = parent; |
Philip Withnall | 648a4dd | 2013-11-25 18:01:44 +0000 | [diff] [blame] | 2412 | |
| 2413 | wl_list_remove(&shsurf->children_link); |
| 2414 | wl_list_init(&shsurf->children_link); |
| 2415 | |
| 2416 | /* Insert into the parent surface’s child list. */ |
| 2417 | if (parent != NULL) { |
| 2418 | struct shell_surface *parent_shsurf = get_shell_surface(parent); |
| 2419 | if (parent_shsurf != NULL) |
| 2420 | wl_list_insert(&parent_shsurf->children_list, |
| 2421 | &shsurf->children_link); |
| 2422 | } |
Philip Withnall | dc4332f | 2013-11-25 18:01:38 +0000 | [diff] [blame] | 2423 | } |
| 2424 | |
| 2425 | static void |
Philip Withnall | 352e7ed | 2013-11-25 18:01:35 +0000 | [diff] [blame] | 2426 | shell_surface_set_output(struct shell_surface *shsurf, |
| 2427 | struct weston_output *output) |
| 2428 | { |
| 2429 | struct weston_surface *es = shsurf->surface; |
| 2430 | |
| 2431 | /* get the default output, if the client set it as NULL |
| 2432 | check whether the ouput is available */ |
| 2433 | if (output) |
| 2434 | shsurf->output = output; |
| 2435 | else if (es->output) |
| 2436 | shsurf->output = es->output; |
| 2437 | else |
| 2438 | shsurf->output = get_default_output(es->compositor); |
| 2439 | } |
| 2440 | |
| 2441 | static void |
Rafael Antognolli | 03b1659 | 2013-12-03 15:35:42 -0200 | [diff] [blame] | 2442 | surface_clear_next_states(struct shell_surface *shsurf) |
| 2443 | { |
| 2444 | shsurf->next_state.maximized = false; |
| 2445 | shsurf->next_state.fullscreen = false; |
| 2446 | |
| 2447 | if ((shsurf->next_state.maximized != shsurf->state.maximized) || |
| 2448 | (shsurf->next_state.fullscreen != shsurf->state.fullscreen)) |
| 2449 | shsurf->state_changed = true; |
| 2450 | } |
| 2451 | |
| 2452 | static void |
Philip Withnall | becb77e | 2013-11-25 18:01:30 +0000 | [diff] [blame] | 2453 | set_toplevel(struct shell_surface *shsurf) |
| 2454 | { |
Kristian Høgsberg | 41fbf6f | 2013-12-05 22:31:25 -0800 | [diff] [blame] | 2455 | shell_surface_set_parent(shsurf, NULL); |
| 2456 | surface_clear_next_states(shsurf); |
Pekka Paalanen | b502654 | 2014-11-12 15:09:24 +0200 | [diff] [blame] | 2457 | set_type(shsurf, SHELL_SURFACE_TOPLEVEL); |
Philip Withnall | 648a4dd | 2013-11-25 18:01:44 +0000 | [diff] [blame] | 2458 | |
| 2459 | /* The layer_link is updated in set_surface_type(), |
| 2460 | * called from configure. */ |
Philip Withnall | becb77e | 2013-11-25 18:01:30 +0000 | [diff] [blame] | 2461 | } |
| 2462 | |
| 2463 | static void |
| 2464 | shell_surface_set_toplevel(struct wl_client *client, |
| 2465 | struct wl_resource *resource) |
| 2466 | { |
| 2467 | struct shell_surface *surface = wl_resource_get_user_data(resource); |
| 2468 | |
| 2469 | set_toplevel(surface); |
| 2470 | } |
| 2471 | |
| 2472 | static void |
| 2473 | set_transient(struct shell_surface *shsurf, |
| 2474 | struct weston_surface *parent, int x, int y, uint32_t flags) |
| 2475 | { |
Philip Withnall | dc4332f | 2013-11-25 18:01:38 +0000 | [diff] [blame] | 2476 | assert(parent != NULL); |
| 2477 | |
Kristian Høgsberg | 9f7e331 | 2014-01-02 22:40:37 -0800 | [diff] [blame] | 2478 | shell_surface_set_parent(shsurf, parent); |
| 2479 | |
| 2480 | surface_clear_next_states(shsurf); |
| 2481 | |
Philip Withnall | becb77e | 2013-11-25 18:01:30 +0000 | [diff] [blame] | 2482 | shsurf->transient.x = x; |
| 2483 | shsurf->transient.y = y; |
| 2484 | shsurf->transient.flags = flags; |
Philip Withnall | dc4332f | 2013-11-25 18:01:38 +0000 | [diff] [blame] | 2485 | |
Rafael Antognolli | ed207b4 | 2013-12-03 15:35:43 -0200 | [diff] [blame] | 2486 | shsurf->next_state.relative = true; |
Kristian Høgsberg | a1df7ac | 2013-12-31 15:01:01 -0800 | [diff] [blame] | 2487 | shsurf->state_changed = true; |
Pekka Paalanen | b502654 | 2014-11-12 15:09:24 +0200 | [diff] [blame] | 2488 | set_type(shsurf, SHELL_SURFACE_TOPLEVEL); |
Philip Withnall | 648a4dd | 2013-11-25 18:01:44 +0000 | [diff] [blame] | 2489 | |
| 2490 | /* The layer_link is updated in set_surface_type(), |
| 2491 | * called from configure. */ |
Philip Withnall | becb77e | 2013-11-25 18:01:30 +0000 | [diff] [blame] | 2492 | } |
| 2493 | |
| 2494 | static void |
| 2495 | shell_surface_set_transient(struct wl_client *client, |
| 2496 | struct wl_resource *resource, |
| 2497 | struct wl_resource *parent_resource, |
| 2498 | int x, int y, uint32_t flags) |
| 2499 | { |
| 2500 | struct shell_surface *shsurf = wl_resource_get_user_data(resource); |
| 2501 | struct weston_surface *parent = |
| 2502 | wl_resource_get_user_data(parent_resource); |
| 2503 | |
| 2504 | set_transient(shsurf, parent, x, y, flags); |
| 2505 | } |
| 2506 | |
| 2507 | static void |
| 2508 | set_fullscreen(struct shell_surface *shsurf, |
| 2509 | uint32_t method, |
| 2510 | uint32_t framerate, |
| 2511 | struct weston_output *output) |
| 2512 | { |
Philip Withnall | 352e7ed | 2013-11-25 18:01:35 +0000 | [diff] [blame] | 2513 | shell_surface_set_output(shsurf, output); |
Pekka Paalanen | b502654 | 2014-11-12 15:09:24 +0200 | [diff] [blame] | 2514 | set_type(shsurf, SHELL_SURFACE_TOPLEVEL); |
Philip Withnall | becb77e | 2013-11-25 18:01:30 +0000 | [diff] [blame] | 2515 | |
| 2516 | shsurf->fullscreen_output = shsurf->output; |
| 2517 | shsurf->fullscreen.type = method; |
| 2518 | shsurf->fullscreen.framerate = framerate; |
Philip Withnall | dc4332f | 2013-11-25 18:01:38 +0000 | [diff] [blame] | 2519 | |
Jasper St. Pierre | 6458ec3 | 2014-04-11 16:00:31 -0700 | [diff] [blame] | 2520 | send_configure_for_surface(shsurf); |
Philip Withnall | becb77e | 2013-11-25 18:01:30 +0000 | [diff] [blame] | 2521 | } |
| 2522 | |
| 2523 | static void |
Zhang, Xiong Y | 3123693 | 2013-12-13 22:10:57 +0200 | [diff] [blame] | 2524 | weston_view_set_initial_position(struct weston_view *view, |
| 2525 | struct desktop_shell *shell); |
| 2526 | |
| 2527 | static void |
Philip Withnall | becb77e | 2013-11-25 18:01:30 +0000 | [diff] [blame] | 2528 | unset_fullscreen(struct shell_surface *shsurf) |
Alex Wu | 4539b08 | 2012-03-01 12:57:46 +0800 | [diff] [blame] | 2529 | { |
Philip Withnall | f85fe84 | 2013-11-25 18:01:37 +0000 | [diff] [blame] | 2530 | /* Unset the fullscreen output, driver configuration and transforms. */ |
Alex Wu | bd3354b | 2012-04-17 17:20:49 +0800 | [diff] [blame] | 2531 | if (shsurf->fullscreen.type == WL_SHELL_SURFACE_FULLSCREEN_METHOD_DRIVER && |
| 2532 | shell_surface_is_top_fullscreen(shsurf)) { |
Alexander Larsson | f82b6ca | 2013-05-28 16:23:39 +0200 | [diff] [blame] | 2533 | restore_output_mode(shsurf->fullscreen_output); |
Alex Wu | bd3354b | 2012-04-17 17:20:49 +0800 | [diff] [blame] | 2534 | } |
Philip Withnall | f85fe84 | 2013-11-25 18:01:37 +0000 | [diff] [blame] | 2535 | |
Alex Wu | 4539b08 | 2012-03-01 12:57:46 +0800 | [diff] [blame] | 2536 | shsurf->fullscreen.type = WL_SHELL_SURFACE_FULLSCREEN_METHOD_DEFAULT; |
| 2537 | shsurf->fullscreen.framerate = 0; |
Philip Withnall | f85fe84 | 2013-11-25 18:01:37 +0000 | [diff] [blame] | 2538 | |
Alex Wu | 4539b08 | 2012-03-01 12:57:46 +0800 | [diff] [blame] | 2539 | wl_list_remove(&shsurf->fullscreen.transform.link); |
| 2540 | wl_list_init(&shsurf->fullscreen.transform.link); |
Philip Withnall | f85fe84 | 2013-11-25 18:01:37 +0000 | [diff] [blame] | 2541 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 2542 | if (shsurf->fullscreen.black_view) |
| 2543 | weston_surface_destroy(shsurf->fullscreen.black_view->surface); |
| 2544 | shsurf->fullscreen.black_view = NULL; |
Philip Withnall | f85fe84 | 2013-11-25 18:01:37 +0000 | [diff] [blame] | 2545 | |
Zhang, Xiong Y | 3123693 | 2013-12-13 22:10:57 +0200 | [diff] [blame] | 2546 | if (shsurf->saved_position_valid) |
| 2547 | weston_view_set_position(shsurf->view, |
| 2548 | shsurf->saved_x, shsurf->saved_y); |
| 2549 | else |
| 2550 | weston_view_set_initial_position(shsurf->view, shsurf->shell); |
| 2551 | |
Alex Wu | 7bcb8bd | 2012-04-27 09:07:24 +0800 | [diff] [blame] | 2552 | if (shsurf->saved_rotation_valid) { |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 2553 | wl_list_insert(&shsurf->view->geometry.transformation_list, |
Philip Withnall | becb77e | 2013-11-25 18:01:30 +0000 | [diff] [blame] | 2554 | &shsurf->rotation.transform.link); |
Alex Wu | 7bcb8bd | 2012-04-27 09:07:24 +0800 | [diff] [blame] | 2555 | shsurf->saved_rotation_valid = false; |
| 2556 | } |
Rafal Mielniczuk | 3e3862c | 2012-10-07 20:25:36 +0200 | [diff] [blame] | 2557 | |
Philip Withnall | e1d75ae | 2013-11-25 18:01:41 +0000 | [diff] [blame] | 2558 | /* Layer is updated in set_surface_type(). */ |
Alex Wu | 4539b08 | 2012-03-01 12:57:46 +0800 | [diff] [blame] | 2559 | } |
| 2560 | |
Rafal Mielniczuk | fffdcdd | 2013-03-11 19:26:54 +0100 | [diff] [blame] | 2561 | static void |
Philip Withnall | becb77e | 2013-11-25 18:01:30 +0000 | [diff] [blame] | 2562 | shell_surface_set_fullscreen(struct wl_client *client, |
| 2563 | struct wl_resource *resource, |
| 2564 | uint32_t method, |
| 2565 | uint32_t framerate, |
| 2566 | struct wl_resource *output_resource) |
| 2567 | { |
| 2568 | struct shell_surface *shsurf = wl_resource_get_user_data(resource); |
| 2569 | struct weston_output *output; |
| 2570 | |
Emmanuel Gil Peyrot | 28834b6 | 2016-05-10 03:22:43 +0200 | [diff] [blame] | 2571 | if (shsurf->fullscreen_output == shsurf->output && |
| 2572 | shsurf->fullscreen.type == method && |
| 2573 | shsurf->fullscreen.framerate == framerate) { |
| 2574 | send_configure_for_surface(shsurf); |
| 2575 | return; |
| 2576 | } |
| 2577 | |
Philip Withnall | becb77e | 2013-11-25 18:01:30 +0000 | [diff] [blame] | 2578 | if (output_resource) |
| 2579 | output = wl_resource_get_user_data(output_resource); |
| 2580 | else |
| 2581 | output = NULL; |
| 2582 | |
Rafael Antognolli | 4b99a40 | 2013-12-03 15:35:44 -0200 | [diff] [blame] | 2583 | shell_surface_set_parent(shsurf, NULL); |
| 2584 | |
Rafael Antognolli | 03b1659 | 2013-12-03 15:35:42 -0200 | [diff] [blame] | 2585 | surface_clear_next_states(shsurf); |
Jasper St. Pierre | 8c6aa45 | 2014-02-08 18:29:49 -0500 | [diff] [blame] | 2586 | shsurf->next_state.fullscreen = true; |
| 2587 | shsurf->state_changed = true; |
Jasper St. Pierre | 6458ec3 | 2014-04-11 16:00:31 -0700 | [diff] [blame] | 2588 | set_fullscreen(shsurf, method, framerate, output); |
Philip Withnall | becb77e | 2013-11-25 18:01:30 +0000 | [diff] [blame] | 2589 | } |
| 2590 | |
| 2591 | static void |
| 2592 | set_popup(struct shell_surface *shsurf, |
| 2593 | struct weston_surface *parent, |
| 2594 | struct weston_seat *seat, |
| 2595 | uint32_t serial, |
| 2596 | int32_t x, |
| 2597 | int32_t y) |
| 2598 | { |
Philip Withnall | dc4332f | 2013-11-25 18:01:38 +0000 | [diff] [blame] | 2599 | assert(parent != NULL); |
| 2600 | |
Philip Withnall | becb77e | 2013-11-25 18:01:30 +0000 | [diff] [blame] | 2601 | shsurf->popup.shseat = get_shell_seat(seat); |
| 2602 | shsurf->popup.serial = serial; |
| 2603 | shsurf->popup.x = x; |
| 2604 | shsurf->popup.y = y; |
Philip Withnall | dc4332f | 2013-11-25 18:01:38 +0000 | [diff] [blame] | 2605 | |
Pekka Paalanen | b502654 | 2014-11-12 15:09:24 +0200 | [diff] [blame] | 2606 | set_type(shsurf, SHELL_SURFACE_POPUP); |
Philip Withnall | becb77e | 2013-11-25 18:01:30 +0000 | [diff] [blame] | 2607 | } |
| 2608 | |
| 2609 | static void |
| 2610 | shell_surface_set_popup(struct wl_client *client, |
| 2611 | struct wl_resource *resource, |
| 2612 | struct wl_resource *seat_resource, |
| 2613 | uint32_t serial, |
| 2614 | struct wl_resource *parent_resource, |
| 2615 | int32_t x, int32_t y, uint32_t flags) |
| 2616 | { |
| 2617 | struct shell_surface *shsurf = wl_resource_get_user_data(resource); |
Rafael Antognolli | 4b99a40 | 2013-12-03 15:35:44 -0200 | [diff] [blame] | 2618 | struct weston_surface *parent = |
| 2619 | wl_resource_get_user_data(parent_resource); |
| 2620 | |
| 2621 | shell_surface_set_parent(shsurf, parent); |
Philip Withnall | becb77e | 2013-11-25 18:01:30 +0000 | [diff] [blame] | 2622 | |
Rafael Antognolli | 03b1659 | 2013-12-03 15:35:42 -0200 | [diff] [blame] | 2623 | surface_clear_next_states(shsurf); |
Philip Withnall | becb77e | 2013-11-25 18:01:30 +0000 | [diff] [blame] | 2624 | set_popup(shsurf, |
Rafael Antognolli | 4b99a40 | 2013-12-03 15:35:44 -0200 | [diff] [blame] | 2625 | parent, |
Philip Withnall | becb77e | 2013-11-25 18:01:30 +0000 | [diff] [blame] | 2626 | wl_resource_get_user_data(seat_resource), |
| 2627 | serial, x, y); |
| 2628 | } |
| 2629 | |
| 2630 | static void |
Philip Withnall | becb77e | 2013-11-25 18:01:30 +0000 | [diff] [blame] | 2631 | unset_maximized(struct shell_surface *shsurf) |
Rafal Mielniczuk | fffdcdd | 2013-03-11 19:26:54 +0100 | [diff] [blame] | 2632 | { |
Rafal Mielniczuk | fffdcdd | 2013-03-11 19:26:54 +0100 | [diff] [blame] | 2633 | /* undo all maximized things here */ |
| 2634 | shsurf->output = get_default_output(shsurf->surface->compositor); |
Zhang, Xiong Y | 3123693 | 2013-12-13 22:10:57 +0200 | [diff] [blame] | 2635 | |
| 2636 | if (shsurf->saved_position_valid) |
| 2637 | weston_view_set_position(shsurf->view, |
| 2638 | shsurf->saved_x, shsurf->saved_y); |
| 2639 | else |
| 2640 | weston_view_set_initial_position(shsurf->view, shsurf->shell); |
Rafal Mielniczuk | fffdcdd | 2013-03-11 19:26:54 +0100 | [diff] [blame] | 2641 | |
| 2642 | if (shsurf->saved_rotation_valid) { |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 2643 | wl_list_insert(&shsurf->view->geometry.transformation_list, |
| 2644 | &shsurf->rotation.transform.link); |
Rafal Mielniczuk | fffdcdd | 2013-03-11 19:26:54 +0100 | [diff] [blame] | 2645 | shsurf->saved_rotation_valid = false; |
| 2646 | } |
| 2647 | |
Philip Withnall | e1d75ae | 2013-11-25 18:01:41 +0000 | [diff] [blame] | 2648 | /* Layer is updated in set_surface_type(). */ |
Rafal Mielniczuk | fffdcdd | 2013-03-11 19:26:54 +0100 | [diff] [blame] | 2649 | } |
| 2650 | |
Philip Withnall | becb77e | 2013-11-25 18:01:30 +0000 | [diff] [blame] | 2651 | static void |
Manuel Bachmann | dc1c3e4 | 2015-02-16 11:52:13 +0100 | [diff] [blame] | 2652 | set_minimized(struct weston_surface *surface) |
Manuel Bachmann | 50c87db | 2014-02-26 15:52:13 +0100 | [diff] [blame] | 2653 | { |
| 2654 | struct shell_surface *shsurf; |
| 2655 | struct workspace *current_ws; |
Manuel Bachmann | 50c87db | 2014-02-26 15:52:13 +0100 | [diff] [blame] | 2656 | struct weston_view *view; |
| 2657 | |
| 2658 | view = get_default_view(surface); |
| 2659 | if (!view) |
| 2660 | return; |
| 2661 | |
| 2662 | assert(weston_surface_get_main_surface(view->surface) == view->surface); |
| 2663 | |
| 2664 | shsurf = get_shell_surface(surface); |
| 2665 | current_ws = get_current_workspace(shsurf->shell); |
| 2666 | |
Giulio Camuffo | 412e6a5 | 2014-07-09 22:12:56 +0300 | [diff] [blame] | 2667 | weston_layer_entry_remove(&view->layer_link); |
Manuel Bachmann | dc1c3e4 | 2015-02-16 11:52:13 +0100 | [diff] [blame] | 2668 | 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] | 2669 | |
Manuel Bachmann | dc1c3e4 | 2015-02-16 11:52:13 +0100 | [diff] [blame] | 2670 | drop_focus_state(shsurf->shell, current_ws, view->surface); |
Jonas Ådahl | 22faea1 | 2014-10-15 22:02:06 +0200 | [diff] [blame] | 2671 | surface_keyboard_focus_lost(surface); |
Manuel Bachmann | 50c87db | 2014-02-26 15:52:13 +0100 | [diff] [blame] | 2672 | |
| 2673 | shell_surface_update_child_surface_layers(shsurf); |
Manuel Bachmann | 50c87db | 2014-02-26 15:52:13 +0100 | [diff] [blame] | 2674 | weston_view_damage_below(view); |
| 2675 | } |
| 2676 | |
| 2677 | static void |
Philip Withnall | becb77e | 2013-11-25 18:01:30 +0000 | [diff] [blame] | 2678 | shell_surface_set_maximized(struct wl_client *client, |
| 2679 | struct wl_resource *resource, |
| 2680 | struct wl_resource *output_resource) |
| 2681 | { |
| 2682 | struct shell_surface *shsurf = wl_resource_get_user_data(resource); |
| 2683 | struct weston_output *output; |
| 2684 | |
Jasper St. Pierre | 9aa8ce6 | 2014-04-11 16:18:54 -0700 | [diff] [blame] | 2685 | surface_clear_next_states(shsurf); |
| 2686 | shsurf->next_state.maximized = true; |
| 2687 | shsurf->state_changed = true; |
| 2688 | |
Pekka Paalanen | b502654 | 2014-11-12 15:09:24 +0200 | [diff] [blame] | 2689 | set_type(shsurf, SHELL_SURFACE_TOPLEVEL); |
Jasper St. Pierre | 9aa8ce6 | 2014-04-11 16:18:54 -0700 | [diff] [blame] | 2690 | shell_surface_set_parent(shsurf, NULL); |
| 2691 | |
Philip Withnall | becb77e | 2013-11-25 18:01:30 +0000 | [diff] [blame] | 2692 | if (output_resource) |
| 2693 | output = wl_resource_get_user_data(output_resource); |
| 2694 | else |
| 2695 | output = NULL; |
| 2696 | |
Jasper St. Pierre | 9aa8ce6 | 2014-04-11 16:18:54 -0700 | [diff] [blame] | 2697 | shell_surface_set_output(shsurf, output); |
Rafael Antognolli | 4b99a40 | 2013-12-03 15:35:44 -0200 | [diff] [blame] | 2698 | |
Jasper St. Pierre | 9aa8ce6 | 2014-04-11 16:18:54 -0700 | [diff] [blame] | 2699 | send_configure_for_surface(shsurf); |
Philip Withnall | becb77e | 2013-11-25 18:01:30 +0000 | [diff] [blame] | 2700 | } |
| 2701 | |
Philip Withnall | e1d75ae | 2013-11-25 18:01:41 +0000 | [diff] [blame] | 2702 | /* This is only ever called from set_surface_type(), so there’s no need to |
| 2703 | * update layer_links here, since they’ll be updated when we return. */ |
Pekka Paalanen | 9826223 | 2011-12-01 10:42:22 +0200 | [diff] [blame] | 2704 | static int |
Philip Withnall | becb77e | 2013-11-25 18:01:30 +0000 | [diff] [blame] | 2705 | reset_surface_type(struct shell_surface *surface) |
Pekka Paalanen | 9826223 | 2011-12-01 10:42:22 +0200 | [diff] [blame] | 2706 | { |
Rafael Antognolli | 03b1659 | 2013-12-03 15:35:42 -0200 | [diff] [blame] | 2707 | if (surface->state.fullscreen) |
Philip Withnall | becb77e | 2013-11-25 18:01:30 +0000 | [diff] [blame] | 2708 | unset_fullscreen(surface); |
Rafael Antognolli | 03b1659 | 2013-12-03 15:35:42 -0200 | [diff] [blame] | 2709 | if (surface->state.maximized) |
Philip Withnall | becb77e | 2013-11-25 18:01:30 +0000 | [diff] [blame] | 2710 | unset_maximized(surface); |
Pekka Paalanen | 9826223 | 2011-12-01 10:42:22 +0200 | [diff] [blame] | 2711 | |
Pekka Paalanen | 9826223 | 2011-12-01 10:42:22 +0200 | [diff] [blame] | 2712 | return 0; |
| 2713 | } |
| 2714 | |
Kristian Høgsberg | 4cca349 | 2011-01-18 07:53:49 -0500 | [diff] [blame] | 2715 | static void |
Rafael Antognolli | 03b1659 | 2013-12-03 15:35:42 -0200 | [diff] [blame] | 2716 | set_full_output(struct shell_surface *shsurf) |
| 2717 | { |
| 2718 | shsurf->saved_x = shsurf->view->geometry.x; |
| 2719 | shsurf->saved_y = shsurf->view->geometry.y; |
| 2720 | shsurf->saved_position_valid = true; |
| 2721 | |
| 2722 | if (!wl_list_empty(&shsurf->rotation.transform.link)) { |
| 2723 | wl_list_remove(&shsurf->rotation.transform.link); |
| 2724 | wl_list_init(&shsurf->rotation.transform.link); |
| 2725 | weston_view_geometry_dirty(shsurf->view); |
| 2726 | shsurf->saved_rotation_valid = true; |
| 2727 | } |
| 2728 | } |
| 2729 | |
| 2730 | static void |
Kristian Høgsberg | 7f366e7 | 2012-04-27 17:20:01 -0400 | [diff] [blame] | 2731 | set_surface_type(struct shell_surface *shsurf) |
| 2732 | { |
Kristian Høgsberg | 8150b19 | 2012-06-27 10:22:58 -0400 | [diff] [blame] | 2733 | struct weston_surface *pes = shsurf->parent; |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 2734 | struct weston_view *pev = get_default_view(pes); |
Kristian Høgsberg | 7f366e7 | 2012-04-27 17:20:01 -0400 | [diff] [blame] | 2735 | |
Philip Withnall | becb77e | 2013-11-25 18:01:30 +0000 | [diff] [blame] | 2736 | reset_surface_type(shsurf); |
Kristian Høgsberg | 7f366e7 | 2012-04-27 17:20:01 -0400 | [diff] [blame] | 2737 | |
Rafael Antognolli | 03b1659 | 2013-12-03 15:35:42 -0200 | [diff] [blame] | 2738 | shsurf->state = shsurf->next_state; |
Rafael Antognolli | 03b1659 | 2013-12-03 15:35:42 -0200 | [diff] [blame] | 2739 | shsurf->state_changed = false; |
Kristian Høgsberg | 7f366e7 | 2012-04-27 17:20:01 -0400 | [diff] [blame] | 2740 | |
| 2741 | switch (shsurf->type) { |
| 2742 | case SHELL_SURFACE_TOPLEVEL: |
Rafael Antognolli | ed207b4 | 2013-12-03 15:35:43 -0200 | [diff] [blame] | 2743 | if (shsurf->state.maximized || shsurf->state.fullscreen) { |
Rafael Antognolli | 03b1659 | 2013-12-03 15:35:42 -0200 | [diff] [blame] | 2744 | set_full_output(shsurf); |
Rafael Antognolli | ed207b4 | 2013-12-03 15:35:43 -0200 | [diff] [blame] | 2745 | } else if (shsurf->state.relative && pev) { |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 2746 | weston_view_set_position(shsurf->view, |
| 2747 | pev->geometry.x + shsurf->transient.x, |
| 2748 | pev->geometry.y + shsurf->transient.y); |
Rafael Antognolli | ed207b4 | 2013-12-03 15:35:43 -0200 | [diff] [blame] | 2749 | } |
Rafael Antognolli | 44a3162 | 2013-12-04 18:37:16 -0200 | [diff] [blame] | 2750 | break; |
Kristian Høgsberg | 7f366e7 | 2012-04-27 17:20:01 -0400 | [diff] [blame] | 2751 | |
Tiago Vignatti | fb2adba | 2013-06-12 15:43:21 -0300 | [diff] [blame] | 2752 | case SHELL_SURFACE_XWAYLAND: |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 2753 | weston_view_set_position(shsurf->view, shsurf->transient.x, |
| 2754 | shsurf->transient.y); |
Tiago Vignatti | fb2adba | 2013-06-12 15:43:21 -0300 | [diff] [blame] | 2755 | break; |
| 2756 | |
Philip Withnall | 0f640e2 | 2013-11-25 18:01:31 +0000 | [diff] [blame] | 2757 | case SHELL_SURFACE_POPUP: |
| 2758 | case SHELL_SURFACE_NONE: |
Kristian Høgsberg | 7f366e7 | 2012-04-27 17:20:01 -0400 | [diff] [blame] | 2759 | default: |
| 2760 | break; |
| 2761 | } |
Philip Withnall | e1d75ae | 2013-11-25 18:01:41 +0000 | [diff] [blame] | 2762 | |
| 2763 | /* Update the surface’s layer. */ |
| 2764 | shell_surface_update_layer(shsurf); |
Kristian Høgsberg | 7f366e7 | 2012-04-27 17:20:01 -0400 | [diff] [blame] | 2765 | } |
| 2766 | |
Tiago Vignatti | be14326 | 2012-04-16 17:31:41 +0300 | [diff] [blame] | 2767 | static struct desktop_shell * |
Juan Zhao | 96879df | 2012-02-07 08:45:41 +0800 | [diff] [blame] | 2768 | shell_surface_get_shell(struct shell_surface *shsurf) |
Pekka Paalanen | af0e34c | 2011-12-02 10:59:17 +0200 | [diff] [blame] | 2769 | { |
Kristian Høgsberg | 02e79dc | 2012-04-12 09:55:26 -0400 | [diff] [blame] | 2770 | return shsurf->shell; |
Juan Zhao | 96879df | 2012-02-07 08:45:41 +0800 | [diff] [blame] | 2771 | } |
| 2772 | |
Pekka Paalanen | 8274d90 | 2014-08-06 19:36:51 +0300 | [diff] [blame] | 2773 | static int |
| 2774 | black_surface_get_label(struct weston_surface *surface, char *buf, size_t len) |
| 2775 | { |
Jonas Ådahl | 7bfb113 | 2014-10-18 12:23:20 +0200 | [diff] [blame] | 2776 | struct weston_view *fs_view = surface->configure_private; |
| 2777 | struct weston_surface *fs_surface = fs_view->surface; |
Pekka Paalanen | 8274d90 | 2014-08-06 19:36:51 +0300 | [diff] [blame] | 2778 | int n; |
| 2779 | int rem; |
| 2780 | int ret; |
| 2781 | |
| 2782 | n = snprintf(buf, len, "black background surface for "); |
| 2783 | if (n < 0) |
| 2784 | return n; |
| 2785 | |
| 2786 | rem = (int)len - n; |
| 2787 | if (rem < 0) |
| 2788 | rem = 0; |
| 2789 | |
| 2790 | if (fs_surface->get_label) |
| 2791 | ret = fs_surface->get_label(fs_surface, buf + n, rem); |
| 2792 | else |
| 2793 | ret = snprintf(buf + n, rem, "<unknown>"); |
| 2794 | |
| 2795 | if (ret < 0) |
| 2796 | return n; |
| 2797 | |
| 2798 | return n + ret; |
| 2799 | } |
| 2800 | |
Alex Wu | 2185843 | 2012-04-01 20:13:08 +0800 | [diff] [blame] | 2801 | static void |
Jason Ekstrand | 918f2dd | 2013-12-02 21:01:53 -0600 | [diff] [blame] | 2802 | 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] | 2803 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 2804 | static struct weston_view * |
Alex Wu | 4539b08 | 2012-03-01 12:57:46 +0800 | [diff] [blame] | 2805 | create_black_surface(struct weston_compositor *ec, |
Jonas Ådahl | 7bfb113 | 2014-10-18 12:23:20 +0200 | [diff] [blame] | 2806 | struct weston_view *fs_view, |
John Kåre Alsaker | 490d02a | 2012-09-30 02:57:21 +0200 | [diff] [blame] | 2807 | float x, float y, int w, int h) |
Alex Wu | 4539b08 | 2012-03-01 12:57:46 +0800 | [diff] [blame] | 2808 | { |
| 2809 | struct weston_surface *surface = NULL; |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 2810 | struct weston_view *view; |
Alex Wu | 4539b08 | 2012-03-01 12:57:46 +0800 | [diff] [blame] | 2811 | |
| 2812 | surface = weston_surface_create(ec); |
| 2813 | if (surface == NULL) { |
Martin Minarik | 6d11836 | 2012-06-07 18:01:59 +0200 | [diff] [blame] | 2814 | weston_log("no memory\n"); |
Alex Wu | 4539b08 | 2012-03-01 12:57:46 +0800 | [diff] [blame] | 2815 | return NULL; |
| 2816 | } |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 2817 | view = weston_view_create(surface); |
| 2818 | if (surface == NULL) { |
| 2819 | weston_log("no memory\n"); |
| 2820 | weston_surface_destroy(surface); |
| 2821 | return NULL; |
| 2822 | } |
Alex Wu | 4539b08 | 2012-03-01 12:57:46 +0800 | [diff] [blame] | 2823 | |
Alex Wu | 2185843 | 2012-04-01 20:13:08 +0800 | [diff] [blame] | 2824 | surface->configure = black_surface_configure; |
Jonas Ådahl | 7bfb113 | 2014-10-18 12:23:20 +0200 | [diff] [blame] | 2825 | surface->configure_private = fs_view; |
Pekka Paalanen | 8274d90 | 2014-08-06 19:36:51 +0300 | [diff] [blame] | 2826 | weston_surface_set_label_func(surface, black_surface_get_label); |
Alex Wu | 4539b08 | 2012-03-01 12:57:46 +0800 | [diff] [blame] | 2827 | weston_surface_set_color(surface, 0.0, 0.0, 0.0, 1); |
Pekka Paalanen | 71f6f3b | 2012-10-10 12:49:26 +0300 | [diff] [blame] | 2828 | pixman_region32_fini(&surface->opaque); |
Kristian Høgsberg | 61f00f5 | 2012-08-03 16:31:36 -0400 | [diff] [blame] | 2829 | pixman_region32_init_rect(&surface->opaque, 0, 0, w, h); |
Jonas Ådahl | 33619a4 | 2013-01-15 21:25:55 +0100 | [diff] [blame] | 2830 | pixman_region32_fini(&surface->input); |
| 2831 | pixman_region32_init_rect(&surface->input, 0, 0, w, h); |
Jason Ekstrand | 918f2dd | 2013-12-02 21:01:53 -0600 | [diff] [blame] | 2832 | |
Jason Ekstrand | 6228ee2 | 2014-01-01 15:58:57 -0600 | [diff] [blame] | 2833 | weston_surface_set_size(surface, w, h); |
Jason Ekstrand | 918f2dd | 2013-12-02 21:01:53 -0600 | [diff] [blame] | 2834 | weston_view_set_position(view, x, y); |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 2835 | |
| 2836 | return view; |
Alex Wu | 4539b08 | 2012-03-01 12:57:46 +0800 | [diff] [blame] | 2837 | } |
| 2838 | |
Philip Withnall | ed8f1a9 | 2013-11-25 18:01:43 +0000 | [diff] [blame] | 2839 | static void |
| 2840 | shell_ensure_fullscreen_black_view(struct shell_surface *shsurf) |
| 2841 | { |
| 2842 | struct weston_output *output = shsurf->fullscreen_output; |
| 2843 | |
Rafael Antognolli | 03b1659 | 2013-12-03 15:35:42 -0200 | [diff] [blame] | 2844 | assert(shsurf->state.fullscreen); |
Philip Withnall | ed8f1a9 | 2013-11-25 18:01:43 +0000 | [diff] [blame] | 2845 | |
| 2846 | if (!shsurf->fullscreen.black_view) |
| 2847 | shsurf->fullscreen.black_view = |
| 2848 | create_black_surface(shsurf->surface->compositor, |
Jonas Ådahl | 7bfb113 | 2014-10-18 12:23:20 +0200 | [diff] [blame] | 2849 | shsurf->view, |
Philip Withnall | ed8f1a9 | 2013-11-25 18:01:43 +0000 | [diff] [blame] | 2850 | output->x, output->y, |
| 2851 | output->width, |
| 2852 | output->height); |
| 2853 | |
| 2854 | weston_view_geometry_dirty(shsurf->fullscreen.black_view); |
Giulio Camuffo | 412e6a5 | 2014-07-09 22:12:56 +0300 | [diff] [blame] | 2855 | weston_layer_entry_remove(&shsurf->fullscreen.black_view->layer_link); |
| 2856 | weston_layer_entry_insert(&shsurf->view->layer_link, |
| 2857 | &shsurf->fullscreen.black_view->layer_link); |
Philip Withnall | ed8f1a9 | 2013-11-25 18:01:43 +0000 | [diff] [blame] | 2858 | weston_view_geometry_dirty(shsurf->fullscreen.black_view); |
| 2859 | weston_surface_damage(shsurf->surface); |
Emilio Pozuelo Monfort | 9e7c759 | 2014-01-30 14:01:10 +0100 | [diff] [blame] | 2860 | |
Armin Krezović | 4663aca | 2016-06-30 06:04:29 +0200 | [diff] [blame] | 2861 | shsurf->fullscreen.black_view->is_mapped = true; |
Emilio Pozuelo Monfort | 9e7c759 | 2014-01-30 14:01:10 +0100 | [diff] [blame] | 2862 | shsurf->state.lowered = false; |
Philip Withnall | ed8f1a9 | 2013-11-25 18:01:43 +0000 | [diff] [blame] | 2863 | } |
| 2864 | |
Alex Wu | 4539b08 | 2012-03-01 12:57:46 +0800 | [diff] [blame] | 2865 | /* Create black surface and append it to the associated fullscreen surface. |
| 2866 | * Handle size dismatch and positioning according to the method. */ |
| 2867 | static void |
| 2868 | shell_configure_fullscreen(struct shell_surface *shsurf) |
| 2869 | { |
| 2870 | struct weston_output *output = shsurf->fullscreen_output; |
| 2871 | struct weston_surface *surface = shsurf->surface; |
| 2872 | struct weston_matrix *matrix; |
Kristian Høgsberg | 240dfeb | 2012-07-12 12:32:31 -0400 | [diff] [blame] | 2873 | float scale, output_aspect, surface_aspect, x, y; |
Giulio Camuffo | b836664 | 2013-04-25 13:57:46 +0300 | [diff] [blame] | 2874 | int32_t surf_x, surf_y, surf_width, surf_height; |
Alex Wu | 4539b08 | 2012-03-01 12:57:46 +0800 | [diff] [blame] | 2875 | |
Alexander Larsson | f82b6ca | 2013-05-28 16:23:39 +0200 | [diff] [blame] | 2876 | if (shsurf->fullscreen.type != WL_SHELL_SURFACE_FULLSCREEN_METHOD_DRIVER) |
| 2877 | restore_output_mode(output); |
| 2878 | |
Emilio Pozuelo Monfort | 9e7c759 | 2014-01-30 14:01:10 +0100 | [diff] [blame] | 2879 | /* Reverse the effect of lower_fullscreen_layer() */ |
Giulio Camuffo | 412e6a5 | 2014-07-09 22:12:56 +0300 | [diff] [blame] | 2880 | weston_layer_entry_remove(&shsurf->view->layer_link); |
| 2881 | 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] | 2882 | |
Philip Withnall | ed8f1a9 | 2013-11-25 18:01:43 +0000 | [diff] [blame] | 2883 | shell_ensure_fullscreen_black_view(shsurf); |
Alex Wu | 4539b08 | 2012-03-01 12:57:46 +0800 | [diff] [blame] | 2884 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 2885 | surface_subsurfaces_boundingbox(shsurf->surface, &surf_x, &surf_y, |
Giulio Camuffo | b836664 | 2013-04-25 13:57:46 +0300 | [diff] [blame] | 2886 | &surf_width, &surf_height); |
| 2887 | |
Alex Wu | 4539b08 | 2012-03-01 12:57:46 +0800 | [diff] [blame] | 2888 | switch (shsurf->fullscreen.type) { |
| 2889 | case WL_SHELL_SURFACE_FULLSCREEN_METHOD_DEFAULT: |
Pekka Paalanen | de685b8 | 2012-12-04 15:58:12 +0200 | [diff] [blame] | 2890 | if (surface->buffer_ref.buffer) |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 2891 | center_on_output(shsurf->view, shsurf->fullscreen_output); |
Alex Wu | 4539b08 | 2012-03-01 12:57:46 +0800 | [diff] [blame] | 2892 | break; |
| 2893 | case WL_SHELL_SURFACE_FULLSCREEN_METHOD_SCALE: |
Rob Bradford | 9f3dd15 | 2013-02-12 11:53:47 +0000 | [diff] [blame] | 2894 | /* 1:1 mapping between surface and output dimensions */ |
Giulio Camuffo | b836664 | 2013-04-25 13:57:46 +0300 | [diff] [blame] | 2895 | if (output->width == surf_width && |
| 2896 | output->height == surf_height) { |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 2897 | weston_view_set_position(shsurf->view, |
| 2898 | output->x - surf_x, |
| 2899 | output->y - surf_y); |
Rob Bradford | 9f3dd15 | 2013-02-12 11:53:47 +0000 | [diff] [blame] | 2900 | break; |
| 2901 | } |
| 2902 | |
Alex Wu | 4539b08 | 2012-03-01 12:57:46 +0800 | [diff] [blame] | 2903 | matrix = &shsurf->fullscreen.transform.matrix; |
| 2904 | weston_matrix_init(matrix); |
Kristian Høgsberg | 240dfeb | 2012-07-12 12:32:31 -0400 | [diff] [blame] | 2905 | |
Scott Moreau | 1bad5db | 2012-08-18 01:04:05 -0600 | [diff] [blame] | 2906 | output_aspect = (float) output->width / |
| 2907 | (float) output->height; |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 2908 | /* XXX: Use surf_width and surf_height here? */ |
| 2909 | surface_aspect = (float) surface->width / |
| 2910 | (float) surface->height; |
Kristian Høgsberg | 240dfeb | 2012-07-12 12:32:31 -0400 | [diff] [blame] | 2911 | if (output_aspect < surface_aspect) |
Scott Moreau | 1bad5db | 2012-08-18 01:04:05 -0600 | [diff] [blame] | 2912 | scale = (float) output->width / |
Giulio Camuffo | b836664 | 2013-04-25 13:57:46 +0300 | [diff] [blame] | 2913 | (float) surf_width; |
Kristian Høgsberg | 240dfeb | 2012-07-12 12:32:31 -0400 | [diff] [blame] | 2914 | else |
Scott Moreau | 1bad5db | 2012-08-18 01:04:05 -0600 | [diff] [blame] | 2915 | scale = (float) output->height / |
Giulio Camuffo | b836664 | 2013-04-25 13:57:46 +0300 | [diff] [blame] | 2916 | (float) surf_height; |
Kristian Høgsberg | 240dfeb | 2012-07-12 12:32:31 -0400 | [diff] [blame] | 2917 | |
Alex Wu | 4539b08 | 2012-03-01 12:57:46 +0800 | [diff] [blame] | 2918 | weston_matrix_scale(matrix, scale, scale, 1); |
| 2919 | wl_list_remove(&shsurf->fullscreen.transform.link); |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 2920 | wl_list_insert(&shsurf->view->geometry.transformation_list, |
Alex Wu | 4539b08 | 2012-03-01 12:57:46 +0800 | [diff] [blame] | 2921 | &shsurf->fullscreen.transform.link); |
Giulio Camuffo | b836664 | 2013-04-25 13:57:46 +0300 | [diff] [blame] | 2922 | x = output->x + (output->width - surf_width * scale) / 2 - surf_x; |
| 2923 | y = output->y + (output->height - surf_height * scale) / 2 - surf_y; |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 2924 | weston_view_set_position(shsurf->view, x, y); |
Kristian Høgsberg | 240dfeb | 2012-07-12 12:32:31 -0400 | [diff] [blame] | 2925 | |
Alex Wu | 4539b08 | 2012-03-01 12:57:46 +0800 | [diff] [blame] | 2926 | break; |
| 2927 | case WL_SHELL_SURFACE_FULLSCREEN_METHOD_DRIVER: |
Alex Wu | bd3354b | 2012-04-17 17:20:49 +0800 | [diff] [blame] | 2928 | if (shell_surface_is_top_fullscreen(shsurf)) { |
Quentin Glidic | c0d79ce | 2013-01-29 14:16:13 +0100 | [diff] [blame] | 2929 | struct weston_mode mode = {0, |
Pekka Paalanen | 952b6c8 | 2014-03-14 14:38:15 +0200 | [diff] [blame] | 2930 | surf_width * surface->buffer_viewport.buffer.scale, |
| 2931 | surf_height * surface->buffer_viewport.buffer.scale, |
Alex Wu | bd3354b | 2012-04-17 17:20:49 +0800 | [diff] [blame] | 2932 | shsurf->fullscreen.framerate}; |
| 2933 | |
Derek Foreman | 6ae7bc9 | 2014-11-04 10:47:33 -0600 | [diff] [blame] | 2934 | if (weston_output_mode_switch_to_temporary(output, &mode, |
| 2935 | surface->buffer_viewport.buffer.scale) == 0) { |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 2936 | weston_view_set_position(shsurf->view, |
| 2937 | output->x - surf_x, |
| 2938 | output->y - surf_y); |
Jason Ekstrand | 918f2dd | 2013-12-02 21:01:53 -0600 | [diff] [blame] | 2939 | shsurf->fullscreen.black_view->surface->width = output->width; |
| 2940 | shsurf->fullscreen.black_view->surface->height = output->height; |
| 2941 | weston_view_set_position(shsurf->fullscreen.black_view, |
| 2942 | output->x - surf_x, |
| 2943 | output->y - surf_y); |
Alex Wu | bd3354b | 2012-04-17 17:20:49 +0800 | [diff] [blame] | 2944 | break; |
Alexander Larsson | d622ed3 | 2013-05-28 16:23:40 +0200 | [diff] [blame] | 2945 | } else { |
Mario Kleiner | 492c12f | 2015-06-21 21:25:12 +0200 | [diff] [blame] | 2946 | weston_log("shell: Can't switch to temporary mode.\n"); |
Alexander Larsson | f82b6ca | 2013-05-28 16:23:39 +0200 | [diff] [blame] | 2947 | restore_output_mode(output); |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 2948 | center_on_output(shsurf->view, output); |
Alexander Larsson | d622ed3 | 2013-05-28 16:23:40 +0200 | [diff] [blame] | 2949 | } |
Alex Wu | bd3354b | 2012-04-17 17:20:49 +0800 | [diff] [blame] | 2950 | } |
Alex Wu | 4539b08 | 2012-03-01 12:57:46 +0800 | [diff] [blame] | 2951 | break; |
| 2952 | case WL_SHELL_SURFACE_FULLSCREEN_METHOD_FILL: |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 2953 | center_on_output(shsurf->view, output); |
Alex Wu | 4539b08 | 2012-03-01 12:57:46 +0800 | [diff] [blame] | 2954 | break; |
| 2955 | default: |
| 2956 | break; |
| 2957 | } |
| 2958 | } |
| 2959 | |
Alex Wu | 4539b08 | 2012-03-01 12:57:46 +0800 | [diff] [blame] | 2960 | static void |
| 2961 | shell_map_fullscreen(struct shell_surface *shsurf) |
| 2962 | { |
Alex Wu | bd3354b | 2012-04-17 17:20:49 +0800 | [diff] [blame] | 2963 | shell_configure_fullscreen(shsurf); |
Alex Wu | 4539b08 | 2012-03-01 12:57:46 +0800 | [diff] [blame] | 2964 | } |
| 2965 | |
Kristian Høgsberg | 7a5c979 | 2011-06-18 06:12:54 -0400 | [diff] [blame] | 2966 | static void |
Tiago Vignatti | fb2adba | 2013-06-12 15:43:21 -0300 | [diff] [blame] | 2967 | set_xwayland(struct shell_surface *shsurf, int x, int y, uint32_t flags) |
| 2968 | { |
| 2969 | /* XXX: using the same fields for transient type */ |
Rafael Antognolli | 03b1659 | 2013-12-03 15:35:42 -0200 | [diff] [blame] | 2970 | surface_clear_next_states(shsurf); |
Tiago Vignatti | fb2adba | 2013-06-12 15:43:21 -0300 | [diff] [blame] | 2971 | shsurf->transient.x = x; |
| 2972 | shsurf->transient.y = y; |
| 2973 | shsurf->transient.flags = flags; |
Philip Withnall | dc4332f | 2013-11-25 18:01:38 +0000 | [diff] [blame] | 2974 | |
| 2975 | shell_surface_set_parent(shsurf, NULL); |
| 2976 | |
Pekka Paalanen | b502654 | 2014-11-12 15:09:24 +0200 | [diff] [blame] | 2977 | set_type(shsurf, SHELL_SURFACE_XWAYLAND); |
Kristian Høgsberg | 8bc525c | 2014-01-01 22:34:49 -0800 | [diff] [blame] | 2978 | shsurf->state_changed = true; |
Tiago Vignatti | fb2adba | 2013-06-12 15:43:21 -0300 | [diff] [blame] | 2979 | } |
| 2980 | |
Kristian Høgsberg | 4779241 | 2014-05-04 13:47:06 -0700 | [diff] [blame] | 2981 | static void |
| 2982 | shell_interface_set_fullscreen(struct shell_surface *shsurf, |
| 2983 | uint32_t method, |
| 2984 | uint32_t framerate, |
| 2985 | struct weston_output *output) |
| 2986 | { |
| 2987 | surface_clear_next_states(shsurf); |
Kristian Høgsberg | 4779241 | 2014-05-04 13:47:06 -0700 | [diff] [blame] | 2988 | shsurf->next_state.fullscreen = true; |
| 2989 | shsurf->state_changed = true; |
Marek Chalupa | e9fe467 | 2014-10-29 13:44:44 +0100 | [diff] [blame] | 2990 | |
| 2991 | set_fullscreen(shsurf, method, framerate, output); |
Kristian Høgsberg | 4779241 | 2014-05-04 13:47:06 -0700 | [diff] [blame] | 2992 | } |
| 2993 | |
Giulio Camuffo | 6b4b241 | 2015-01-29 19:06:49 +0200 | [diff] [blame] | 2994 | static struct weston_output * |
| 2995 | get_focused_output(struct weston_compositor *compositor) |
| 2996 | { |
| 2997 | struct weston_seat *seat; |
| 2998 | struct weston_output *output = NULL; |
| 2999 | |
| 3000 | wl_list_for_each(seat, &compositor->seat_list, link) { |
Derek Foreman | 1281a36 | 2015-07-31 16:55:32 -0500 | [diff] [blame] | 3001 | struct weston_touch *touch = weston_seat_get_touch(seat); |
| 3002 | struct weston_pointer *pointer = weston_seat_get_pointer(seat); |
| 3003 | struct weston_keyboard *keyboard = |
| 3004 | weston_seat_get_keyboard(seat); |
| 3005 | |
Giulio Camuffo | 6b4b241 | 2015-01-29 19:06:49 +0200 | [diff] [blame] | 3006 | /* Priority has touch focus, then pointer and |
| 3007 | * then keyboard focus. We should probably have |
| 3008 | * three for loops and check frist for touch, |
| 3009 | * then for pointer, etc. but unless somebody has some |
| 3010 | * objections, I think this is sufficient. */ |
Derek Foreman | 1281a36 | 2015-07-31 16:55:32 -0500 | [diff] [blame] | 3011 | if (touch && touch->focus) |
| 3012 | output = touch->focus->output; |
| 3013 | else if (pointer && pointer->focus) |
| 3014 | output = pointer->focus->output; |
| 3015 | else if (keyboard && keyboard->focus) |
| 3016 | output = keyboard->focus->output; |
Giulio Camuffo | 6b4b241 | 2015-01-29 19:06:49 +0200 | [diff] [blame] | 3017 | |
| 3018 | if (output) |
| 3019 | break; |
| 3020 | } |
| 3021 | |
| 3022 | return output; |
| 3023 | } |
| 3024 | |
| 3025 | static void |
| 3026 | shell_interface_set_maximized(struct shell_surface *shsurf) |
| 3027 | { |
| 3028 | struct weston_output *output; |
| 3029 | |
| 3030 | surface_clear_next_states(shsurf); |
| 3031 | shsurf->next_state.maximized = true; |
| 3032 | shsurf->state_changed = true; |
| 3033 | shsurf->type = SHELL_SURFACE_TOPLEVEL; |
| 3034 | |
| 3035 | if (!weston_surface_is_mapped(shsurf->surface)) |
| 3036 | output = get_focused_output(shsurf->surface->compositor); |
| 3037 | else |
| 3038 | output = shsurf->surface->output; |
| 3039 | |
| 3040 | shell_surface_set_output(shsurf, output); |
| 3041 | send_configure_for_surface(shsurf); |
| 3042 | } |
| 3043 | |
Kristian Høgsberg | ae356ae | 2014-04-29 16:03:54 -0700 | [diff] [blame] | 3044 | static int |
Derek Foreman | e4d6c83 | 2015-08-05 14:48:11 -0500 | [diff] [blame] | 3045 | shell_interface_move(struct shell_surface *shsurf, struct weston_pointer *pointer) |
Kristian Høgsberg | ae356ae | 2014-04-29 16:03:54 -0700 | [diff] [blame] | 3046 | { |
Derek Foreman | e4d6c83 | 2015-08-05 14:48:11 -0500 | [diff] [blame] | 3047 | return surface_move(shsurf, pointer, true); |
Kristian Høgsberg | ae356ae | 2014-04-29 16:03:54 -0700 | [diff] [blame] | 3048 | } |
| 3049 | |
Derek Foreman | 8fbebbd | 2015-07-15 13:00:40 -0500 | [diff] [blame] | 3050 | static int |
| 3051 | shell_interface_resize(struct shell_surface *shsurf, |
Derek Foreman | e4d6c83 | 2015-08-05 14:48:11 -0500 | [diff] [blame] | 3052 | struct weston_pointer *pointer, |
Derek Foreman | 8fbebbd | 2015-07-15 13:00:40 -0500 | [diff] [blame] | 3053 | uint32_t edges) |
| 3054 | { |
Derek Foreman | e4d6c83 | 2015-08-05 14:48:11 -0500 | [diff] [blame] | 3055 | return surface_resize(shsurf, pointer, edges); |
Derek Foreman | 8fbebbd | 2015-07-15 13:00:40 -0500 | [diff] [blame] | 3056 | } |
| 3057 | |
Kristian Høgsberg | 02bbabb | 2013-05-06 22:15:05 -0400 | [diff] [blame] | 3058 | static const struct weston_pointer_grab_interface popup_grab_interface; |
Giulio Camuffo | 5085a75 | 2013-03-25 21:42:45 +0100 | [diff] [blame] | 3059 | |
| 3060 | static void |
| 3061 | destroy_shell_seat(struct wl_listener *listener, void *data) |
| 3062 | { |
| 3063 | struct shell_seat *shseat = |
| 3064 | container_of(listener, |
| 3065 | struct shell_seat, seat_destroy_listener); |
Jonas Ådahl | c2b1011 | 2015-02-13 14:01:53 +0800 | [diff] [blame] | 3066 | struct shell_surface *shsurf, *next; |
Giulio Camuffo | 5085a75 | 2013-03-25 21:42:45 +0100 | [diff] [blame] | 3067 | |
| 3068 | if (shseat->popup_grab.grab.interface == &popup_grab_interface) { |
Kristian Høgsberg | 02bbabb | 2013-05-06 22:15:05 -0400 | [diff] [blame] | 3069 | weston_pointer_end_grab(shseat->popup_grab.grab.pointer); |
Giulio Camuffo | 5085a75 | 2013-03-25 21:42:45 +0100 | [diff] [blame] | 3070 | shseat->popup_grab.client = NULL; |
| 3071 | |
Jonas Ådahl | c2b1011 | 2015-02-13 14:01:53 +0800 | [diff] [blame] | 3072 | wl_list_for_each_safe(shsurf, next, |
| 3073 | &shseat->popup_grab.surfaces_list, |
| 3074 | popup.grab_link) { |
Giulio Camuffo | 5085a75 | 2013-03-25 21:42:45 +0100 | [diff] [blame] | 3075 | shsurf->popup.shseat = NULL; |
Jonas Ådahl | c2b1011 | 2015-02-13 14:01:53 +0800 | [diff] [blame] | 3076 | wl_list_init(&shsurf->popup.grab_link); |
Giulio Camuffo | 5085a75 | 2013-03-25 21:42:45 +0100 | [diff] [blame] | 3077 | } |
Giulio Camuffo | 5085a75 | 2013-03-25 21:42:45 +0100 | [diff] [blame] | 3078 | } |
| 3079 | |
| 3080 | wl_list_remove(&shseat->seat_destroy_listener.link); |
| 3081 | free(shseat); |
| 3082 | } |
| 3083 | |
Jason Ekstrand | 024177c | 2014-04-21 19:42:58 -0500 | [diff] [blame] | 3084 | static void |
| 3085 | shell_seat_caps_changed(struct wl_listener *listener, void *data) |
| 3086 | { |
Derek Foreman | 1281a36 | 2015-07-31 16:55:32 -0500 | [diff] [blame] | 3087 | struct weston_keyboard *keyboard; |
| 3088 | struct weston_pointer *pointer; |
Jason Ekstrand | 024177c | 2014-04-21 19:42:58 -0500 | [diff] [blame] | 3089 | struct shell_seat *seat; |
| 3090 | |
| 3091 | seat = container_of(listener, struct shell_seat, caps_changed_listener); |
Derek Foreman | 1281a36 | 2015-07-31 16:55:32 -0500 | [diff] [blame] | 3092 | keyboard = weston_seat_get_keyboard(seat->seat); |
| 3093 | pointer = weston_seat_get_pointer(seat->seat); |
Jason Ekstrand | 024177c | 2014-04-21 19:42:58 -0500 | [diff] [blame] | 3094 | |
Derek Foreman | 1281a36 | 2015-07-31 16:55:32 -0500 | [diff] [blame] | 3095 | if (keyboard && |
Jason Ekstrand | 024177c | 2014-04-21 19:42:58 -0500 | [diff] [blame] | 3096 | wl_list_empty(&seat->keyboard_focus_listener.link)) { |
Derek Foreman | 1281a36 | 2015-07-31 16:55:32 -0500 | [diff] [blame] | 3097 | wl_signal_add(&keyboard->focus_signal, |
Jason Ekstrand | 024177c | 2014-04-21 19:42:58 -0500 | [diff] [blame] | 3098 | &seat->keyboard_focus_listener); |
Derek Foreman | 1281a36 | 2015-07-31 16:55:32 -0500 | [diff] [blame] | 3099 | } else if (!keyboard) { |
Derek Foreman | 60d9731 | 2015-07-15 13:00:45 -0500 | [diff] [blame] | 3100 | wl_list_remove(&seat->keyboard_focus_listener.link); |
Jason Ekstrand | 024177c | 2014-04-21 19:42:58 -0500 | [diff] [blame] | 3101 | wl_list_init(&seat->keyboard_focus_listener.link); |
| 3102 | } |
| 3103 | |
Derek Foreman | 1281a36 | 2015-07-31 16:55:32 -0500 | [diff] [blame] | 3104 | if (pointer && |
Jason Ekstrand | 024177c | 2014-04-21 19:42:58 -0500 | [diff] [blame] | 3105 | wl_list_empty(&seat->pointer_focus_listener.link)) { |
Derek Foreman | 1281a36 | 2015-07-31 16:55:32 -0500 | [diff] [blame] | 3106 | wl_signal_add(&pointer->focus_signal, |
Jason Ekstrand | 024177c | 2014-04-21 19:42:58 -0500 | [diff] [blame] | 3107 | &seat->pointer_focus_listener); |
Derek Foreman | 1281a36 | 2015-07-31 16:55:32 -0500 | [diff] [blame] | 3108 | } else if (!pointer) { |
Derek Foreman | 60d9731 | 2015-07-15 13:00:45 -0500 | [diff] [blame] | 3109 | wl_list_remove(&seat->pointer_focus_listener.link); |
Jason Ekstrand | 024177c | 2014-04-21 19:42:58 -0500 | [diff] [blame] | 3110 | wl_list_init(&seat->pointer_focus_listener.link); |
| 3111 | } |
| 3112 | } |
| 3113 | |
Giulio Camuffo | 5085a75 | 2013-03-25 21:42:45 +0100 | [diff] [blame] | 3114 | static struct shell_seat * |
| 3115 | create_shell_seat(struct weston_seat *seat) |
| 3116 | { |
| 3117 | struct shell_seat *shseat; |
| 3118 | |
| 3119 | shseat = calloc(1, sizeof *shseat); |
| 3120 | if (!shseat) { |
| 3121 | weston_log("no memory to allocate shell seat\n"); |
| 3122 | return NULL; |
| 3123 | } |
| 3124 | |
| 3125 | shseat->seat = seat; |
| 3126 | wl_list_init(&shseat->popup_grab.surfaces_list); |
| 3127 | |
| 3128 | shseat->seat_destroy_listener.notify = destroy_shell_seat; |
| 3129 | wl_signal_add(&seat->destroy_signal, |
| 3130 | &shseat->seat_destroy_listener); |
| 3131 | |
Jason Ekstrand | 024177c | 2014-04-21 19:42:58 -0500 | [diff] [blame] | 3132 | shseat->keyboard_focus_listener.notify = handle_keyboard_focus; |
| 3133 | wl_list_init(&shseat->keyboard_focus_listener.link); |
| 3134 | |
| 3135 | shseat->pointer_focus_listener.notify = handle_pointer_focus; |
| 3136 | wl_list_init(&shseat->pointer_focus_listener.link); |
| 3137 | |
| 3138 | shseat->caps_changed_listener.notify = shell_seat_caps_changed; |
| 3139 | wl_signal_add(&seat->updated_caps_signal, |
| 3140 | &shseat->caps_changed_listener); |
| 3141 | shell_seat_caps_changed(&shseat->caps_changed_listener, NULL); |
| 3142 | |
Giulio Camuffo | 5085a75 | 2013-03-25 21:42:45 +0100 | [diff] [blame] | 3143 | return shseat; |
| 3144 | } |
| 3145 | |
| 3146 | static struct shell_seat * |
| 3147 | get_shell_seat(struct weston_seat *seat) |
| 3148 | { |
| 3149 | struct wl_listener *listener; |
| 3150 | |
| 3151 | listener = wl_signal_get(&seat->destroy_signal, destroy_shell_seat); |
Jason Ekstrand | 024177c | 2014-04-21 19:42:58 -0500 | [diff] [blame] | 3152 | assert(listener != NULL); |
Giulio Camuffo | 5085a75 | 2013-03-25 21:42:45 +0100 | [diff] [blame] | 3153 | |
| 3154 | return container_of(listener, |
| 3155 | struct shell_seat, seat_destroy_listener); |
| 3156 | } |
| 3157 | |
Kristian Høgsberg | b810eb5 | 2013-02-12 20:07:05 -0500 | [diff] [blame] | 3158 | static void |
Kristian Høgsberg | 6848c25 | 2013-05-08 22:02:59 -0400 | [diff] [blame] | 3159 | popup_grab_focus(struct weston_pointer_grab *grab) |
Kristian Høgsberg | b3cca0a | 2012-01-04 22:19:14 -0500 | [diff] [blame] | 3160 | { |
Kristian Høgsberg | 02bbabb | 2013-05-06 22:15:05 -0400 | [diff] [blame] | 3161 | struct weston_pointer *pointer = grab->pointer; |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 3162 | struct weston_view *view; |
Giulio Camuffo | 5085a75 | 2013-03-25 21:42:45 +0100 | [diff] [blame] | 3163 | struct shell_seat *shseat = |
| 3164 | container_of(grab, struct shell_seat, popup_grab.grab); |
| 3165 | struct wl_client *client = shseat->popup_grab.client; |
Kristian Høgsberg | 6848c25 | 2013-05-08 22:02:59 -0400 | [diff] [blame] | 3166 | wl_fixed_t sx, sy; |
| 3167 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 3168 | view = weston_compositor_pick_view(pointer->seat->compositor, |
| 3169 | pointer->x, pointer->y, |
| 3170 | &sx, &sy); |
Kristian Høgsberg | b3cca0a | 2012-01-04 22:19:14 -0500 | [diff] [blame] | 3171 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 3172 | if (view && view->surface->resource && |
| 3173 | wl_resource_get_client(view->surface->resource) == client) { |
| 3174 | weston_pointer_set_focus(pointer, view, sx, sy); |
Kristian Høgsberg | b3cca0a | 2012-01-04 22:19:14 -0500 | [diff] [blame] | 3175 | } else { |
Derek Foreman | f9318d1 | 2015-05-11 15:40:11 -0500 | [diff] [blame] | 3176 | weston_pointer_clear_focus(pointer); |
Kristian Høgsberg | b3cca0a | 2012-01-04 22:19:14 -0500 | [diff] [blame] | 3177 | } |
| 3178 | } |
| 3179 | |
| 3180 | static void |
Giulio Camuffo | 1959ab8 | 2013-11-14 23:42:52 +0100 | [diff] [blame] | 3181 | popup_grab_motion(struct weston_pointer_grab *grab, uint32_t time, |
Jonas Ådahl | d251010 | 2014-10-05 21:39:14 +0200 | [diff] [blame] | 3182 | struct weston_pointer_motion_event *event) |
Kristian Høgsberg | b3cca0a | 2012-01-04 22:19:14 -0500 | [diff] [blame] | 3183 | { |
Kristian Høgsberg | be6403e | 2013-05-08 21:03:21 -0400 | [diff] [blame] | 3184 | struct weston_pointer *pointer = grab->pointer; |
Neil Roberts | 96d790e | 2013-09-19 17:32:00 +0100 | [diff] [blame] | 3185 | struct wl_resource *resource; |
Jonas Ådahl | 2cbf293 | 2015-07-22 12:05:38 +0800 | [diff] [blame] | 3186 | struct wl_list *resource_list; |
Jonas Ådahl | d251010 | 2014-10-05 21:39:14 +0200 | [diff] [blame] | 3187 | wl_fixed_t x, y; |
Kristian Høgsberg | be6403e | 2013-05-08 21:03:21 -0400 | [diff] [blame] | 3188 | wl_fixed_t sx, sy; |
Kristian Høgsberg | b3cca0a | 2012-01-04 22:19:14 -0500 | [diff] [blame] | 3189 | |
Jonas Ådahl | 61917c8 | 2014-08-11 22:44:02 +0200 | [diff] [blame] | 3190 | if (pointer->focus) { |
Jonas Ådahl | d251010 | 2014-10-05 21:39:14 +0200 | [diff] [blame] | 3191 | weston_pointer_motion_to_abs(pointer, event, &x, &y); |
Jonas Ådahl | 61917c8 | 2014-08-11 22:44:02 +0200 | [diff] [blame] | 3192 | weston_view_from_global_fixed(pointer->focus, x, y, |
| 3193 | &pointer->sx, &pointer->sy); |
| 3194 | } |
| 3195 | |
Jonas Ådahl | d251010 | 2014-10-05 21:39:14 +0200 | [diff] [blame] | 3196 | weston_pointer_move(pointer, event); |
Giulio Camuffo | 1959ab8 | 2013-11-14 23:42:52 +0100 | [diff] [blame] | 3197 | |
Jonas Ådahl | 2cbf293 | 2015-07-22 12:05:38 +0800 | [diff] [blame] | 3198 | if (!pointer->focus_client) |
| 3199 | return; |
| 3200 | |
| 3201 | resource_list = &pointer->focus_client->pointer_resources; |
| 3202 | wl_resource_for_each(resource, resource_list) { |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 3203 | weston_view_from_global_fixed(pointer->focus, |
| 3204 | pointer->x, pointer->y, |
| 3205 | &sx, &sy); |
Neil Roberts | 96d790e | 2013-09-19 17:32:00 +0100 | [diff] [blame] | 3206 | wl_pointer_send_motion(resource, time, sx, sy); |
Kristian Høgsberg | be6403e | 2013-05-08 21:03:21 -0400 | [diff] [blame] | 3207 | } |
Kristian Høgsberg | b3cca0a | 2012-01-04 22:19:14 -0500 | [diff] [blame] | 3208 | } |
| 3209 | |
| 3210 | static void |
Kristian Høgsberg | 02bbabb | 2013-05-06 22:15:05 -0400 | [diff] [blame] | 3211 | popup_grab_button(struct weston_pointer_grab *grab, |
Daniel Stone | 4dbadb1 | 2012-05-30 16:31:51 +0100 | [diff] [blame] | 3212 | uint32_t time, uint32_t button, uint32_t state_w) |
Kristian Høgsberg | b3cca0a | 2012-01-04 22:19:14 -0500 | [diff] [blame] | 3213 | { |
| 3214 | struct wl_resource *resource; |
Giulio Camuffo | 5085a75 | 2013-03-25 21:42:45 +0100 | [diff] [blame] | 3215 | struct shell_seat *shseat = |
| 3216 | container_of(grab, struct shell_seat, popup_grab.grab); |
Rob Bradford | 880ebc7 | 2013-07-22 17:31:38 +0100 | [diff] [blame] | 3217 | struct wl_display *display = shseat->seat->compositor->wl_display; |
Daniel Stone | 4dbadb1 | 2012-05-30 16:31:51 +0100 | [diff] [blame] | 3218 | enum wl_pointer_button_state state = state_w; |
Kristian Høgsberg | eae5de7 | 2012-04-11 22:42:15 -0400 | [diff] [blame] | 3219 | uint32_t serial; |
Jonas Ådahl | 2cbf293 | 2015-07-22 12:05:38 +0800 | [diff] [blame] | 3220 | struct wl_list *resource_list = NULL; |
Kristian Høgsberg | b3cca0a | 2012-01-04 22:19:14 -0500 | [diff] [blame] | 3221 | |
Jonas Ådahl | 2cbf293 | 2015-07-22 12:05:38 +0800 | [diff] [blame] | 3222 | if (grab->pointer->focus_client) |
| 3223 | resource_list = &grab->pointer->focus_client->pointer_resources; |
| 3224 | if (resource_list && !wl_list_empty(resource_list)) { |
Kristian Høgsberg | eae5de7 | 2012-04-11 22:42:15 -0400 | [diff] [blame] | 3225 | serial = wl_display_get_serial(display); |
Neil Roberts | 96d790e | 2013-09-19 17:32:00 +0100 | [diff] [blame] | 3226 | wl_resource_for_each(resource, resource_list) { |
| 3227 | wl_pointer_send_button(resource, serial, |
| 3228 | time, button, state); |
| 3229 | } |
Daniel Stone | 4dbadb1 | 2012-05-30 16:31:51 +0100 | [diff] [blame] | 3230 | } else if (state == WL_POINTER_BUTTON_STATE_RELEASED && |
Giulio Camuffo | 5085a75 | 2013-03-25 21:42:45 +0100 | [diff] [blame] | 3231 | (shseat->popup_grab.initial_up || |
Derek Foreman | f7b2f8b | 2015-07-15 13:00:41 -0500 | [diff] [blame] | 3232 | time - grab->pointer->grab_time > 500)) { |
Kristian Høgsberg | 57e0907 | 2012-10-30 14:07:27 -0400 | [diff] [blame] | 3233 | popup_grab_end(grab->pointer); |
Kristian Høgsberg | b3cca0a | 2012-01-04 22:19:14 -0500 | [diff] [blame] | 3234 | } |
| 3235 | |
Daniel Stone | 4dbadb1 | 2012-05-30 16:31:51 +0100 | [diff] [blame] | 3236 | if (state == WL_POINTER_BUTTON_STATE_RELEASED) |
Giulio Camuffo | 5085a75 | 2013-03-25 21:42:45 +0100 | [diff] [blame] | 3237 | shseat->popup_grab.initial_up = 1; |
Kristian Høgsberg | b3cca0a | 2012-01-04 22:19:14 -0500 | [diff] [blame] | 3238 | } |
| 3239 | |
Jonas Ådahl | 1ea343e | 2013-10-25 23:18:05 +0200 | [diff] [blame] | 3240 | static void |
Jonas Ådahl | 0336ca0 | 2014-10-04 16:28:29 +0200 | [diff] [blame] | 3241 | popup_grab_axis(struct weston_pointer_grab *grab, |
Peter Hutterer | 89b6a49 | 2016-01-18 15:58:17 +1000 | [diff] [blame] | 3242 | uint32_t time, |
| 3243 | struct weston_pointer_axis_event *event) |
Jonas Ådahl | 0336ca0 | 2014-10-04 16:28:29 +0200 | [diff] [blame] | 3244 | { |
Peter Hutterer | 89b6a49 | 2016-01-18 15:58:17 +1000 | [diff] [blame] | 3245 | weston_pointer_send_axis(grab->pointer, time, event); |
Jonas Ådahl | 0336ca0 | 2014-10-04 16:28:29 +0200 | [diff] [blame] | 3246 | } |
| 3247 | |
| 3248 | static void |
Peter Hutterer | 87743e9 | 2016-01-18 16:38:22 +1000 | [diff] [blame] | 3249 | popup_grab_axis_source(struct weston_pointer_grab *grab, uint32_t source) |
| 3250 | { |
| 3251 | weston_pointer_send_axis_source(grab->pointer, source); |
| 3252 | } |
| 3253 | |
| 3254 | static void |
| 3255 | popup_grab_frame(struct weston_pointer_grab *grab) |
| 3256 | { |
| 3257 | weston_pointer_send_frame(grab->pointer); |
| 3258 | } |
| 3259 | |
| 3260 | static void |
Jonas Ådahl | 1ea343e | 2013-10-25 23:18:05 +0200 | [diff] [blame] | 3261 | popup_grab_cancel(struct weston_pointer_grab *grab) |
| 3262 | { |
| 3263 | popup_grab_end(grab->pointer); |
| 3264 | } |
| 3265 | |
Kristian Høgsberg | 02bbabb | 2013-05-06 22:15:05 -0400 | [diff] [blame] | 3266 | static const struct weston_pointer_grab_interface popup_grab_interface = { |
Kristian Høgsberg | b3cca0a | 2012-01-04 22:19:14 -0500 | [diff] [blame] | 3267 | popup_grab_focus, |
| 3268 | popup_grab_motion, |
| 3269 | popup_grab_button, |
Jonas Ådahl | 0336ca0 | 2014-10-04 16:28:29 +0200 | [diff] [blame] | 3270 | popup_grab_axis, |
Peter Hutterer | 87743e9 | 2016-01-18 16:38:22 +1000 | [diff] [blame] | 3271 | popup_grab_axis_source, |
| 3272 | popup_grab_frame, |
Jonas Ådahl | 1ea343e | 2013-10-25 23:18:05 +0200 | [diff] [blame] | 3273 | popup_grab_cancel, |
Kristian Høgsberg | b3cca0a | 2012-01-04 22:19:14 -0500 | [diff] [blame] | 3274 | }; |
| 3275 | |
| 3276 | static void |
Jonny Lamb | 76cf1fe | 2014-08-20 11:27:10 +0200 | [diff] [blame] | 3277 | touch_popup_grab_down(struct weston_touch_grab *grab, uint32_t time, |
Giulio Camuffo | 61ed7b6 | 2015-07-08 11:55:28 +0300 | [diff] [blame] | 3278 | int touch_id, wl_fixed_t x, wl_fixed_t y) |
Jonny Lamb | 76cf1fe | 2014-08-20 11:27:10 +0200 | [diff] [blame] | 3279 | { |
| 3280 | struct wl_resource *resource; |
| 3281 | struct shell_seat *shseat = |
| 3282 | container_of(grab, struct shell_seat, popup_grab.touch_grab); |
| 3283 | struct wl_display *display = shseat->seat->compositor->wl_display; |
| 3284 | uint32_t serial; |
| 3285 | struct wl_list *resource_list; |
Giulio Camuffo | 61ed7b6 | 2015-07-08 11:55:28 +0300 | [diff] [blame] | 3286 | wl_fixed_t sx, sy; |
| 3287 | |
| 3288 | weston_view_from_global_fixed(grab->touch->focus, x, y, &sx, &sy); |
Jonny Lamb | 76cf1fe | 2014-08-20 11:27:10 +0200 | [diff] [blame] | 3289 | |
| 3290 | resource_list = &grab->touch->focus_resource_list; |
| 3291 | if (!wl_list_empty(resource_list)) { |
| 3292 | serial = wl_display_get_serial(display); |
| 3293 | wl_resource_for_each(resource, resource_list) { |
| 3294 | wl_touch_send_down(resource, serial, time, |
| 3295 | grab->touch->focus->surface->resource, |
| 3296 | touch_id, sx, sy); |
| 3297 | } |
| 3298 | } |
| 3299 | } |
| 3300 | |
| 3301 | static void |
| 3302 | touch_popup_grab_up(struct weston_touch_grab *grab, uint32_t time, int touch_id) |
| 3303 | { |
| 3304 | struct wl_resource *resource; |
| 3305 | struct shell_seat *shseat = |
| 3306 | container_of(grab, struct shell_seat, popup_grab.touch_grab); |
| 3307 | struct wl_display *display = shseat->seat->compositor->wl_display; |
| 3308 | uint32_t serial; |
| 3309 | struct wl_list *resource_list; |
| 3310 | |
| 3311 | resource_list = &grab->touch->focus_resource_list; |
| 3312 | if (!wl_list_empty(resource_list)) { |
| 3313 | serial = wl_display_get_serial(display); |
| 3314 | wl_resource_for_each(resource, resource_list) { |
| 3315 | wl_touch_send_up(resource, serial, time, touch_id); |
| 3316 | } |
| 3317 | } |
| 3318 | } |
| 3319 | |
| 3320 | static void |
| 3321 | touch_popup_grab_motion(struct weston_touch_grab *grab, uint32_t time, |
Giulio Camuffo | 61ed7b6 | 2015-07-08 11:55:28 +0300 | [diff] [blame] | 3322 | int touch_id, wl_fixed_t x, wl_fixed_t y) |
Jonny Lamb | 76cf1fe | 2014-08-20 11:27:10 +0200 | [diff] [blame] | 3323 | { |
| 3324 | struct wl_resource *resource; |
| 3325 | struct wl_list *resource_list; |
Giulio Camuffo | 61ed7b6 | 2015-07-08 11:55:28 +0300 | [diff] [blame] | 3326 | wl_fixed_t sx, sy; |
| 3327 | |
| 3328 | weston_view_from_global_fixed(grab->touch->focus, x, y, &sx, &sy); |
Jonny Lamb | 76cf1fe | 2014-08-20 11:27:10 +0200 | [diff] [blame] | 3329 | |
| 3330 | resource_list = &grab->touch->focus_resource_list; |
| 3331 | if (!wl_list_empty(resource_list)) { |
| 3332 | wl_resource_for_each(resource, resource_list) { |
| 3333 | wl_touch_send_motion(resource, time, touch_id, sx, sy); |
| 3334 | } |
| 3335 | } |
| 3336 | } |
| 3337 | |
| 3338 | static void |
| 3339 | touch_popup_grab_frame(struct weston_touch_grab *grab) |
| 3340 | { |
| 3341 | } |
| 3342 | |
| 3343 | static void |
| 3344 | touch_popup_grab_cancel(struct weston_touch_grab *grab) |
| 3345 | { |
| 3346 | touch_popup_grab_end(grab->touch); |
| 3347 | } |
| 3348 | |
| 3349 | static const struct weston_touch_grab_interface touch_popup_grab_interface = { |
| 3350 | touch_popup_grab_down, |
| 3351 | touch_popup_grab_up, |
| 3352 | touch_popup_grab_motion, |
| 3353 | touch_popup_grab_frame, |
| 3354 | touch_popup_grab_cancel, |
| 3355 | }; |
| 3356 | |
| 3357 | static void |
Rafael Antognolli | e2a3455 | 2013-12-03 15:35:45 -0200 | [diff] [blame] | 3358 | shell_surface_send_popup_done(struct shell_surface *shsurf) |
| 3359 | { |
Bryce Harrington | 22b1f93 | 2015-09-23 17:30:43 -0700 | [diff] [blame] | 3360 | if (shsurf->resource == NULL) |
| 3361 | return; |
| 3362 | else if (shell_surface_is_wl_shell_surface(shsurf)) |
Rafael Antognolli | e2a3455 | 2013-12-03 15:35:45 -0200 | [diff] [blame] | 3363 | wl_shell_surface_send_popup_done(shsurf->resource); |
| 3364 | else if (shell_surface_is_xdg_popup(shsurf)) |
Jasper St. Pierre | ecf2a0f | 2015-02-13 14:01:56 +0800 | [diff] [blame] | 3365 | xdg_popup_send_popup_done(shsurf->resource); |
Rafael Antognolli | e2a3455 | 2013-12-03 15:35:45 -0200 | [diff] [blame] | 3366 | } |
| 3367 | |
| 3368 | static void |
Kristian Høgsberg | 02bbabb | 2013-05-06 22:15:05 -0400 | [diff] [blame] | 3369 | popup_grab_end(struct weston_pointer *pointer) |
Kristian Høgsberg | 57e0907 | 2012-10-30 14:07:27 -0400 | [diff] [blame] | 3370 | { |
Kristian Høgsberg | 02bbabb | 2013-05-06 22:15:05 -0400 | [diff] [blame] | 3371 | struct weston_pointer_grab *grab = pointer->grab; |
Giulio Camuffo | 5085a75 | 2013-03-25 21:42:45 +0100 | [diff] [blame] | 3372 | struct shell_seat *shseat = |
| 3373 | container_of(grab, struct shell_seat, popup_grab.grab); |
| 3374 | struct shell_surface *shsurf; |
Jonas Ådahl | c2b1011 | 2015-02-13 14:01:53 +0800 | [diff] [blame] | 3375 | struct shell_surface *next; |
Kristian Høgsberg | 57e0907 | 2012-10-30 14:07:27 -0400 | [diff] [blame] | 3376 | |
| 3377 | if (pointer->grab->interface == &popup_grab_interface) { |
Kristian Høgsberg | 02bbabb | 2013-05-06 22:15:05 -0400 | [diff] [blame] | 3378 | weston_pointer_end_grab(grab->pointer); |
Giulio Camuffo | 5085a75 | 2013-03-25 21:42:45 +0100 | [diff] [blame] | 3379 | shseat->popup_grab.client = NULL; |
Philipp Brüschweiler | 63e7be6 | 2013-04-15 21:09:54 +0200 | [diff] [blame] | 3380 | shseat->popup_grab.grab.interface = NULL; |
| 3381 | assert(!wl_list_empty(&shseat->popup_grab.surfaces_list)); |
Giulio Camuffo | 5085a75 | 2013-03-25 21:42:45 +0100 | [diff] [blame] | 3382 | /* Send the popup_done event to all the popups open */ |
Jonas Ådahl | c2b1011 | 2015-02-13 14:01:53 +0800 | [diff] [blame] | 3383 | wl_list_for_each_safe(shsurf, next, |
| 3384 | &shseat->popup_grab.surfaces_list, |
| 3385 | popup.grab_link) { |
Rafael Antognolli | e2a3455 | 2013-12-03 15:35:45 -0200 | [diff] [blame] | 3386 | shell_surface_send_popup_done(shsurf); |
Giulio Camuffo | 5085a75 | 2013-03-25 21:42:45 +0100 | [diff] [blame] | 3387 | shsurf->popup.shseat = NULL; |
Jonas Ådahl | c2b1011 | 2015-02-13 14:01:53 +0800 | [diff] [blame] | 3388 | wl_list_init(&shsurf->popup.grab_link); |
Giulio Camuffo | 5085a75 | 2013-03-25 21:42:45 +0100 | [diff] [blame] | 3389 | } |
Giulio Camuffo | 5085a75 | 2013-03-25 21:42:45 +0100 | [diff] [blame] | 3390 | wl_list_init(&shseat->popup_grab.surfaces_list); |
| 3391 | } |
| 3392 | } |
| 3393 | |
| 3394 | static void |
Jonny Lamb | 76cf1fe | 2014-08-20 11:27:10 +0200 | [diff] [blame] | 3395 | touch_popup_grab_end(struct weston_touch *touch) |
| 3396 | { |
| 3397 | struct weston_touch_grab *grab = touch->grab; |
| 3398 | struct shell_seat *shseat = |
| 3399 | container_of(grab, struct shell_seat, popup_grab.touch_grab); |
| 3400 | struct shell_surface *shsurf; |
Jonas Ådahl | c2b1011 | 2015-02-13 14:01:53 +0800 | [diff] [blame] | 3401 | struct shell_surface *next; |
Jonny Lamb | 76cf1fe | 2014-08-20 11:27:10 +0200 | [diff] [blame] | 3402 | |
| 3403 | if (touch->grab->interface == &touch_popup_grab_interface) { |
| 3404 | weston_touch_end_grab(grab->touch); |
| 3405 | shseat->popup_grab.client = NULL; |
| 3406 | shseat->popup_grab.touch_grab.interface = NULL; |
| 3407 | assert(!wl_list_empty(&shseat->popup_grab.surfaces_list)); |
| 3408 | /* Send the popup_done event to all the popups open */ |
Jonas Ådahl | c2b1011 | 2015-02-13 14:01:53 +0800 | [diff] [blame] | 3409 | wl_list_for_each_safe(shsurf, next, |
| 3410 | &shseat->popup_grab.surfaces_list, |
| 3411 | popup.grab_link) { |
Jonny Lamb | 76cf1fe | 2014-08-20 11:27:10 +0200 | [diff] [blame] | 3412 | shell_surface_send_popup_done(shsurf); |
| 3413 | shsurf->popup.shseat = NULL; |
Jonas Ådahl | c2b1011 | 2015-02-13 14:01:53 +0800 | [diff] [blame] | 3414 | wl_list_init(&shsurf->popup.grab_link); |
Jonny Lamb | 76cf1fe | 2014-08-20 11:27:10 +0200 | [diff] [blame] | 3415 | } |
Jonny Lamb | 76cf1fe | 2014-08-20 11:27:10 +0200 | [diff] [blame] | 3416 | wl_list_init(&shseat->popup_grab.surfaces_list); |
| 3417 | } |
| 3418 | } |
| 3419 | |
Jasper St. Pierre | da6ecd0 | 2015-02-27 18:35:45 +0800 | [diff] [blame] | 3420 | static struct shell_surface * |
| 3421 | get_top_popup(struct shell_seat *shseat) |
| 3422 | { |
| 3423 | struct shell_surface *shsurf; |
| 3424 | |
| 3425 | if (wl_list_empty(&shseat->popup_grab.surfaces_list)) { |
| 3426 | return NULL; |
| 3427 | } else { |
| 3428 | shsurf = container_of(shseat->popup_grab.surfaces_list.next, |
| 3429 | struct shell_surface, |
| 3430 | popup.grab_link); |
| 3431 | return shsurf; |
| 3432 | } |
| 3433 | } |
| 3434 | |
| 3435 | static int |
Jonas Ådahl | 01193ae | 2015-02-13 14:01:54 +0800 | [diff] [blame] | 3436 | add_popup_grab(struct shell_surface *shsurf, |
| 3437 | struct shell_seat *shseat, |
| 3438 | int32_t type) |
Giulio Camuffo | 5085a75 | 2013-03-25 21:42:45 +0100 | [diff] [blame] | 3439 | { |
Kristian Høgsberg | e314875 | 2013-05-06 23:19:49 -0400 | [diff] [blame] | 3440 | struct weston_seat *seat = shseat->seat; |
Jasper St. Pierre | da6ecd0 | 2015-02-27 18:35:45 +0800 | [diff] [blame] | 3441 | struct shell_surface *parent, *top_surface; |
Derek Foreman | 1281a36 | 2015-07-31 16:55:32 -0500 | [diff] [blame] | 3442 | struct weston_pointer *pointer = weston_seat_get_pointer(seat); |
| 3443 | struct weston_touch *touch = weston_seat_get_touch(seat); |
Jasper St. Pierre | da6ecd0 | 2015-02-27 18:35:45 +0800 | [diff] [blame] | 3444 | |
| 3445 | parent = get_shell_surface(shsurf->parent); |
| 3446 | top_surface = get_top_popup(shseat); |
| 3447 | if (shell_surface_is_xdg_popup(shsurf) && |
Dima Ryazanov | 497f25d | 2015-04-08 11:51:57 -0700 | [diff] [blame] | 3448 | (!parent || |
| 3449 | (top_surface == NULL && !shell_surface_is_xdg_surface(parent)) || |
Jasper St. Pierre | da6ecd0 | 2015-02-27 18:35:45 +0800 | [diff] [blame] | 3450 | (top_surface != NULL && parent != top_surface))) { |
Jonas Ådahl | ee45a55 | 2015-03-18 16:37:47 +0800 | [diff] [blame] | 3451 | wl_resource_post_error(shsurf->owner_resource, |
| 3452 | XDG_SHELL_ERROR_NOT_THE_TOPMOST_POPUP, |
Jasper St. Pierre | da6ecd0 | 2015-02-27 18:35:45 +0800 | [diff] [blame] | 3453 | "xdg_popup was not created on the " |
| 3454 | "topmost popup"); |
| 3455 | return -1; |
| 3456 | } |
Giulio Camuffo | 5085a75 | 2013-03-25 21:42:45 +0100 | [diff] [blame] | 3457 | |
| 3458 | if (wl_list_empty(&shseat->popup_grab.surfaces_list)) { |
Jonny Lamb | 76cf1fe | 2014-08-20 11:27:10 +0200 | [diff] [blame] | 3459 | shseat->popup_grab.type = type; |
Jonas Ådahl | 01193ae | 2015-02-13 14:01:54 +0800 | [diff] [blame] | 3460 | shseat->popup_grab.client = |
| 3461 | wl_resource_get_client(shsurf->resource); |
Jonny Lamb | 76cf1fe | 2014-08-20 11:27:10 +0200 | [diff] [blame] | 3462 | |
| 3463 | if (type == POINTER) { |
Jonas Ådahl | 01193ae | 2015-02-13 14:01:54 +0800 | [diff] [blame] | 3464 | shseat->popup_grab.grab.interface = |
| 3465 | &popup_grab_interface; |
| 3466 | |
| 3467 | /* We must make sure here that this popup was opened |
| 3468 | * after a mouse press, and not just by moving around |
| 3469 | * with other popups already open. */ |
Derek Foreman | 1281a36 | 2015-07-31 16:55:32 -0500 | [diff] [blame] | 3470 | if (pointer->button_count > 0) |
Jonny Lamb | 76cf1fe | 2014-08-20 11:27:10 +0200 | [diff] [blame] | 3471 | shseat->popup_grab.initial_up = 0; |
| 3472 | } else if (type == TOUCH) { |
Jonas Ådahl | 01193ae | 2015-02-13 14:01:54 +0800 | [diff] [blame] | 3473 | shseat->popup_grab.touch_grab.interface = |
| 3474 | &touch_popup_grab_interface; |
Jonny Lamb | 76cf1fe | 2014-08-20 11:27:10 +0200 | [diff] [blame] | 3475 | } |
Giulio Camuffo | 5085a75 | 2013-03-25 21:42:45 +0100 | [diff] [blame] | 3476 | |
Jonas Ådahl | 01193ae | 2015-02-13 14:01:54 +0800 | [diff] [blame] | 3477 | wl_list_insert(&shseat->popup_grab.surfaces_list, |
| 3478 | &shsurf->popup.grab_link); |
Jonny Lamb | 76cf1fe | 2014-08-20 11:27:10 +0200 | [diff] [blame] | 3479 | |
Jonas Ådahl | 01193ae | 2015-02-13 14:01:54 +0800 | [diff] [blame] | 3480 | if (type == POINTER) { |
Derek Foreman | 1281a36 | 2015-07-31 16:55:32 -0500 | [diff] [blame] | 3481 | weston_pointer_start_grab(pointer, |
Jonas Ådahl | 01193ae | 2015-02-13 14:01:54 +0800 | [diff] [blame] | 3482 | &shseat->popup_grab.grab); |
| 3483 | } else if (type == TOUCH) { |
Derek Foreman | 1281a36 | 2015-07-31 16:55:32 -0500 | [diff] [blame] | 3484 | weston_touch_start_grab(touch, |
Jonas Ådahl | 01193ae | 2015-02-13 14:01:54 +0800 | [diff] [blame] | 3485 | &shseat->popup_grab.touch_grab); |
| 3486 | } |
Rob Bradford | dfe3105 | 2013-06-26 19:49:11 +0100 | [diff] [blame] | 3487 | } else { |
Jonas Ådahl | 01193ae | 2015-02-13 14:01:54 +0800 | [diff] [blame] | 3488 | wl_list_insert(&shseat->popup_grab.surfaces_list, |
| 3489 | &shsurf->popup.grab_link); |
Giulio Camuffo | 5085a75 | 2013-03-25 21:42:45 +0100 | [diff] [blame] | 3490 | } |
Jasper St. Pierre | da6ecd0 | 2015-02-27 18:35:45 +0800 | [diff] [blame] | 3491 | |
| 3492 | return 0; |
Giulio Camuffo | 5085a75 | 2013-03-25 21:42:45 +0100 | [diff] [blame] | 3493 | } |
| 3494 | |
| 3495 | static void |
| 3496 | remove_popup_grab(struct shell_surface *shsurf) |
| 3497 | { |
| 3498 | struct shell_seat *shseat = shsurf->popup.shseat; |
| 3499 | |
Jasper St. Pierre | da6ecd0 | 2015-02-27 18:35:45 +0800 | [diff] [blame] | 3500 | if (shell_surface_is_xdg_popup(shsurf) && |
| 3501 | get_top_popup(shseat) != shsurf) { |
Jonas Ådahl | ee45a55 | 2015-03-18 16:37:47 +0800 | [diff] [blame] | 3502 | wl_resource_post_error(shsurf->owner_resource, |
| 3503 | XDG_SHELL_ERROR_NOT_THE_TOPMOST_POPUP, |
Jasper St. Pierre | da6ecd0 | 2015-02-27 18:35:45 +0800 | [diff] [blame] | 3504 | "xdg_popup was destroyed while it was " |
| 3505 | "not the topmost popup."); |
| 3506 | return; |
| 3507 | } |
| 3508 | |
Giulio Camuffo | 5085a75 | 2013-03-25 21:42:45 +0100 | [diff] [blame] | 3509 | wl_list_remove(&shsurf->popup.grab_link); |
| 3510 | wl_list_init(&shsurf->popup.grab_link); |
| 3511 | if (wl_list_empty(&shseat->popup_grab.surfaces_list)) { |
Jonny Lamb | 76cf1fe | 2014-08-20 11:27:10 +0200 | [diff] [blame] | 3512 | if (shseat->popup_grab.type == POINTER) { |
| 3513 | weston_pointer_end_grab(shseat->popup_grab.grab.pointer); |
| 3514 | shseat->popup_grab.grab.interface = NULL; |
| 3515 | } else if (shseat->popup_grab.type == TOUCH) { |
| 3516 | weston_touch_end_grab(shseat->popup_grab.touch_grab.touch); |
| 3517 | shseat->popup_grab.touch_grab.interface = NULL; |
| 3518 | } |
Kristian Høgsberg | 57e0907 | 2012-10-30 14:07:27 -0400 | [diff] [blame] | 3519 | } |
| 3520 | } |
| 3521 | |
Jasper St. Pierre | da6ecd0 | 2015-02-27 18:35:45 +0800 | [diff] [blame] | 3522 | static int |
Kristian Høgsberg | 3730f36 | 2012-04-13 12:40:07 -0400 | [diff] [blame] | 3523 | shell_map_popup(struct shell_surface *shsurf) |
Kristian Høgsberg | b3cca0a | 2012-01-04 22:19:14 -0500 | [diff] [blame] | 3524 | { |
Giulio Camuffo | 5085a75 | 2013-03-25 21:42:45 +0100 | [diff] [blame] | 3525 | struct shell_seat *shseat = shsurf->popup.shseat; |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 3526 | struct weston_view *parent_view = get_default_view(shsurf->parent); |
Derek Foreman | 1281a36 | 2015-07-31 16:55:32 -0500 | [diff] [blame] | 3527 | struct weston_pointer *pointer = weston_seat_get_pointer(shseat->seat); |
| 3528 | struct weston_touch *touch = weston_seat_get_touch(shseat->seat); |
Kristian Høgsberg | b3cca0a | 2012-01-04 22:19:14 -0500 | [diff] [blame] | 3529 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 3530 | shsurf->surface->output = parent_view->output; |
Armin Krezović | 4663aca | 2016-06-30 06:04:29 +0200 | [diff] [blame] | 3531 | shsurf->surface->is_mapped = true; |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 3532 | shsurf->view->output = parent_view->output; |
Kristian Høgsberg | b3cca0a | 2012-01-04 22:19:14 -0500 | [diff] [blame] | 3533 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 3534 | weston_view_set_transform_parent(shsurf->view, parent_view); |
| 3535 | weston_view_set_position(shsurf->view, shsurf->popup.x, shsurf->popup.y); |
| 3536 | weston_view_update_transform(shsurf->view); |
Armin Krezović | 4663aca | 2016-06-30 06:04:29 +0200 | [diff] [blame] | 3537 | shsurf->view->is_mapped = true; |
Kristian Høgsberg | b3cca0a | 2012-01-04 22:19:14 -0500 | [diff] [blame] | 3538 | |
Derek Foreman | 1281a36 | 2015-07-31 16:55:32 -0500 | [diff] [blame] | 3539 | if (pointer && |
| 3540 | pointer->grab_serial == shsurf->popup.serial) { |
Jasper St. Pierre | da6ecd0 | 2015-02-27 18:35:45 +0800 | [diff] [blame] | 3541 | if (add_popup_grab(shsurf, shseat, POINTER) != 0) |
| 3542 | return -1; |
Derek Foreman | 1281a36 | 2015-07-31 16:55:32 -0500 | [diff] [blame] | 3543 | } else if (touch && |
| 3544 | touch->grab_serial == shsurf->popup.serial) { |
Jasper St. Pierre | da6ecd0 | 2015-02-27 18:35:45 +0800 | [diff] [blame] | 3545 | if (add_popup_grab(shsurf, shseat, TOUCH) != 0) |
| 3546 | return -1; |
Kristian Høgsberg | 3730f36 | 2012-04-13 12:40:07 -0400 | [diff] [blame] | 3547 | } else { |
Rafael Antognolli | e2a3455 | 2013-12-03 15:35:45 -0200 | [diff] [blame] | 3548 | shell_surface_send_popup_done(shsurf); |
Giulio Camuffo | 5085a75 | 2013-03-25 21:42:45 +0100 | [diff] [blame] | 3549 | shseat->popup_grab.client = NULL; |
Kristian Høgsberg | 3730f36 | 2012-04-13 12:40:07 -0400 | [diff] [blame] | 3550 | } |
Jasper St. Pierre | da6ecd0 | 2015-02-27 18:35:45 +0800 | [diff] [blame] | 3551 | |
| 3552 | return 0; |
Kristian Høgsberg | b3cca0a | 2012-01-04 22:19:14 -0500 | [diff] [blame] | 3553 | } |
| 3554 | |
Pekka Paalanen | 9d1613e | 2011-11-25 12:09:16 +0200 | [diff] [blame] | 3555 | static const struct wl_shell_surface_interface shell_surface_implementation = { |
Scott Moreau | ff1db4a | 2012-04-17 19:06:18 -0600 | [diff] [blame] | 3556 | shell_surface_pong, |
Pekka Paalanen | 9d1613e | 2011-11-25 12:09:16 +0200 | [diff] [blame] | 3557 | shell_surface_move, |
| 3558 | shell_surface_resize, |
| 3559 | shell_surface_set_toplevel, |
| 3560 | shell_surface_set_transient, |
Kristian Høgsberg | b3cca0a | 2012-01-04 22:19:14 -0500 | [diff] [blame] | 3561 | shell_surface_set_fullscreen, |
Juan Zhao | 96879df | 2012-02-07 08:45:41 +0800 | [diff] [blame] | 3562 | shell_surface_set_popup, |
Kristian Høgsberg | e7afd91 | 2012-05-02 09:47:44 -0400 | [diff] [blame] | 3563 | shell_surface_set_maximized, |
| 3564 | shell_surface_set_title, |
| 3565 | shell_surface_set_class |
Pekka Paalanen | 9d1613e | 2011-11-25 12:09:16 +0200 | [diff] [blame] | 3566 | }; |
| 3567 | |
| 3568 | static void |
Tiago Vignatti | bc052c9 | 2012-04-19 16:18:18 +0300 | [diff] [blame] | 3569 | destroy_shell_surface(struct shell_surface *shsurf) |
Pekka Paalanen | 9d1613e | 2011-11-25 12:09:16 +0200 | [diff] [blame] | 3570 | { |
Kristian Høgsberg | 9046d24 | 2014-01-10 00:25:30 -0800 | [diff] [blame] | 3571 | struct shell_surface *child, *next; |
| 3572 | |
Jason Ekstrand | 651f00e | 2013-06-14 10:07:54 -0500 | [diff] [blame] | 3573 | wl_signal_emit(&shsurf->destroy_signal, shsurf); |
| 3574 | |
Giulio Camuffo | 5085a75 | 2013-03-25 21:42:45 +0100 | [diff] [blame] | 3575 | if (!wl_list_empty(&shsurf->popup.grab_link)) { |
| 3576 | remove_popup_grab(shsurf); |
| 3577 | } |
Kristian Høgsberg | b3cca0a | 2012-01-04 22:19:14 -0500 | [diff] [blame] | 3578 | |
Alex Wu | bd3354b | 2012-04-17 17:20:49 +0800 | [diff] [blame] | 3579 | if (shsurf->fullscreen.type == WL_SHELL_SURFACE_FULLSCREEN_METHOD_DRIVER && |
Alexander Larsson | f82b6ca | 2013-05-28 16:23:39 +0200 | [diff] [blame] | 3580 | shell_surface_is_top_fullscreen(shsurf)) |
| 3581 | restore_output_mode (shsurf->fullscreen_output); |
Pekka Paalanen | 9d1613e | 2011-11-25 12:09:16 +0200 | [diff] [blame] | 3582 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 3583 | if (shsurf->fullscreen.black_view) |
| 3584 | weston_surface_destroy(shsurf->fullscreen.black_view->surface); |
Alex Wu | aa08e2d | 2012-03-05 11:01:40 +0800 | [diff] [blame] | 3585 | |
Alex Wu | bd3354b | 2012-04-17 17:20:49 +0800 | [diff] [blame] | 3586 | /* As destroy_resource() use wl_list_for_each_safe(), |
| 3587 | * we can always remove the listener. |
| 3588 | */ |
| 3589 | wl_list_remove(&shsurf->surface_destroy_listener.link); |
| 3590 | shsurf->surface->configure = NULL; |
Pekka Paalanen | 8274d90 | 2014-08-06 19:36:51 +0300 | [diff] [blame] | 3591 | weston_surface_set_label_func(shsurf->surface, NULL); |
Scott Moreau | 976a050 | 2013-03-07 10:15:17 -0700 | [diff] [blame] | 3592 | free(shsurf->title); |
Alex Wu | bd3354b | 2012-04-17 17:20:49 +0800 | [diff] [blame] | 3593 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 3594 | weston_view_destroy(shsurf->view); |
| 3595 | |
Philip Withnall | 648a4dd | 2013-11-25 18:01:44 +0000 | [diff] [blame] | 3596 | wl_list_remove(&shsurf->children_link); |
Emilio Pozuelo Monfort | adaa20c | 2014-01-28 13:54:16 +0100 | [diff] [blame] | 3597 | wl_list_for_each_safe(child, next, &shsurf->children_list, children_link) |
| 3598 | shell_surface_set_parent(child, NULL); |
Philip Withnall | 648a4dd | 2013-11-25 18:01:44 +0000 | [diff] [blame] | 3599 | |
Pekka Paalanen | 9d1613e | 2011-11-25 12:09:16 +0200 | [diff] [blame] | 3600 | wl_list_remove(&shsurf->link); |
| 3601 | free(shsurf); |
| 3602 | } |
| 3603 | |
| 3604 | static void |
Tiago Vignatti | bc052c9 | 2012-04-19 16:18:18 +0300 | [diff] [blame] | 3605 | shell_destroy_shell_surface(struct wl_resource *resource) |
| 3606 | { |
Jason Ekstrand | 651f00e | 2013-06-14 10:07:54 -0500 | [diff] [blame] | 3607 | struct shell_surface *shsurf = wl_resource_get_user_data(resource); |
Tiago Vignatti | bc052c9 | 2012-04-19 16:18:18 +0300 | [diff] [blame] | 3608 | |
Bryan Cain | a46b946 | 2014-04-04 17:41:24 -0500 | [diff] [blame] | 3609 | if (!wl_list_empty(&shsurf->popup.grab_link)) |
| 3610 | remove_popup_grab(shsurf); |
Bryce Harrington | 22b1f93 | 2015-09-23 17:30:43 -0700 | [diff] [blame] | 3611 | if (shsurf->resource) |
| 3612 | wl_list_remove(wl_resource_get_link(shsurf->resource)); |
Kristian Høgsberg | 160fe75 | 2014-03-11 10:19:10 -0700 | [diff] [blame] | 3613 | shsurf->resource = NULL; |
Tiago Vignatti | bc052c9 | 2012-04-19 16:18:18 +0300 | [diff] [blame] | 3614 | } |
| 3615 | |
| 3616 | static void |
Kristian Høgsberg | 27e3052 | 2012-04-11 23:18:23 -0400 | [diff] [blame] | 3617 | shell_handle_surface_destroy(struct wl_listener *listener, void *data) |
Pekka Paalanen | 9d1613e | 2011-11-25 12:09:16 +0200 | [diff] [blame] | 3618 | { |
| 3619 | struct shell_surface *shsurf = container_of(listener, |
| 3620 | struct shell_surface, |
| 3621 | surface_destroy_listener); |
| 3622 | |
Jason Ekstrand | 651f00e | 2013-06-14 10:07:54 -0500 | [diff] [blame] | 3623 | if (shsurf->resource) |
| 3624 | wl_resource_destroy(shsurf->resource); |
Ander Conselvan de Oliveira | 15f9a26 | 2014-04-29 17:54:02 +0300 | [diff] [blame] | 3625 | |
| 3626 | destroy_shell_surface(shsurf); |
Pekka Paalanen | 9d1613e | 2011-11-25 12:09:16 +0200 | [diff] [blame] | 3627 | } |
| 3628 | |
Kristian Høgsberg | d813445 | 2012-06-21 12:49:02 -0400 | [diff] [blame] | 3629 | static void |
Derek Foreman | 039e9be | 2015-04-14 17:09:06 -0500 | [diff] [blame] | 3630 | fade_out_done_idle_cb(void *data) |
Kristian Høgsberg | 160fe75 | 2014-03-11 10:19:10 -0700 | [diff] [blame] | 3631 | { |
| 3632 | struct shell_surface *shsurf = data; |
| 3633 | |
| 3634 | weston_surface_destroy(shsurf->surface); |
| 3635 | } |
| 3636 | |
| 3637 | static void |
Derek Foreman | 039e9be | 2015-04-14 17:09:06 -0500 | [diff] [blame] | 3638 | fade_out_done(struct weston_view_animation *animation, void *data) |
| 3639 | { |
| 3640 | struct shell_surface *shsurf = data; |
| 3641 | struct wl_event_loop *loop; |
| 3642 | |
| 3643 | loop = wl_display_get_event_loop( |
| 3644 | shsurf->surface->compositor->wl_display); |
| 3645 | |
| 3646 | if (!shsurf->destroying) { |
| 3647 | wl_event_loop_add_idle(loop, fade_out_done_idle_cb, shsurf); |
| 3648 | shsurf->destroying = true; |
| 3649 | } |
| 3650 | } |
| 3651 | |
| 3652 | static void |
Kristian Høgsberg | 160fe75 | 2014-03-11 10:19:10 -0700 | [diff] [blame] | 3653 | handle_resource_destroy(struct wl_listener *listener, void *data) |
| 3654 | { |
| 3655 | struct shell_surface *shsurf = |
| 3656 | container_of(listener, struct shell_surface, |
| 3657 | resource_destroy_listener); |
| 3658 | |
Ander Conselvan de Oliveira | 15f9a26 | 2014-04-29 17:54:02 +0300 | [diff] [blame] | 3659 | if (!weston_surface_is_mapped(shsurf->surface)) |
| 3660 | return; |
| 3661 | |
Kristian Høgsberg | 160fe75 | 2014-03-11 10:19:10 -0700 | [diff] [blame] | 3662 | shsurf->surface->ref_count++; |
| 3663 | |
| 3664 | pixman_region32_fini(&shsurf->surface->pending.input); |
| 3665 | pixman_region32_init(&shsurf->surface->pending.input); |
| 3666 | pixman_region32_fini(&shsurf->surface->input); |
| 3667 | pixman_region32_init(&shsurf->surface->input); |
Jonny Lamb | f322f8e | 2014-08-12 15:13:30 +0200 | [diff] [blame] | 3668 | if (shsurf->shell->win_close_animation_type == ANIMATION_FADE) { |
| 3669 | weston_fade_run(shsurf->view, 1.0, 0.0, 300.0, |
| 3670 | fade_out_done, shsurf); |
| 3671 | } else { |
| 3672 | weston_surface_destroy(shsurf->surface); |
| 3673 | } |
Kristian Høgsberg | 160fe75 | 2014-03-11 10:19:10 -0700 | [diff] [blame] | 3674 | } |
| 3675 | |
| 3676 | static void |
Jason Ekstrand | 918f2dd | 2013-12-02 21:01:53 -0600 | [diff] [blame] | 3677 | shell_surface_configure(struct weston_surface *, int32_t, int32_t); |
Kristian Høgsberg | d813445 | 2012-06-21 12:49:02 -0400 | [diff] [blame] | 3678 | |
Kristian Høgsberg | 1ef2313 | 2013-12-04 00:20:01 -0800 | [diff] [blame] | 3679 | struct shell_surface * |
Kristian Høgsberg | 8334bc1 | 2012-01-03 10:29:47 -0500 | [diff] [blame] | 3680 | get_shell_surface(struct weston_surface *surface) |
Pekka Paalanen | ec2b32f | 2011-11-28 15:12:34 +0200 | [diff] [blame] | 3681 | { |
Kristian Høgsberg | d813445 | 2012-06-21 12:49:02 -0400 | [diff] [blame] | 3682 | if (surface->configure == shell_surface_configure) |
Giulio Camuffo | 7fe01b1 | 2013-03-28 18:02:42 +0100 | [diff] [blame] | 3683 | return surface->configure_private; |
Kristian Høgsberg | d813445 | 2012-06-21 12:49:02 -0400 | [diff] [blame] | 3684 | else |
| 3685 | return NULL; |
Pekka Paalanen | ec2b32f | 2011-11-28 15:12:34 +0200 | [diff] [blame] | 3686 | } |
| 3687 | |
Rafael Antognolli | e2a3455 | 2013-12-03 15:35:45 -0200 | [diff] [blame] | 3688 | static struct shell_surface * |
Jason Ekstrand | 9e9512f | 2014-04-16 21:12:10 -0500 | [diff] [blame] | 3689 | create_common_surface(struct shell_client *owner, void *shell, |
| 3690 | struct weston_surface *surface, |
Rafael Antognolli | e2a3455 | 2013-12-03 15:35:45 -0200 | [diff] [blame] | 3691 | const struct weston_shell_client *client) |
Pekka Paalanen | 9d1613e | 2011-11-25 12:09:16 +0200 | [diff] [blame] | 3692 | { |
Pekka Paalanen | 9d1613e | 2011-11-25 12:09:16 +0200 | [diff] [blame] | 3693 | struct shell_surface *shsurf; |
| 3694 | |
Pekka Paalanen | 50b6747 | 2014-10-01 15:02:41 +0300 | [diff] [blame] | 3695 | assert(surface->configure == NULL); |
Ander Conselvan de Oliveira | 093bfa3 | 2012-03-27 17:36:41 +0300 | [diff] [blame] | 3696 | |
Pekka Paalanen | 9d1613e | 2011-11-25 12:09:16 +0200 | [diff] [blame] | 3697 | shsurf = calloc(1, sizeof *shsurf); |
| 3698 | if (!shsurf) { |
Martin Minarik | 6d11836 | 2012-06-07 18:01:59 +0200 | [diff] [blame] | 3699 | weston_log("no memory to allocate shell surface\n"); |
Kristian Høgsberg | 45ba869 | 2012-05-21 14:27:33 -0400 | [diff] [blame] | 3700 | return NULL; |
Pekka Paalanen | 9d1613e | 2011-11-25 12:09:16 +0200 | [diff] [blame] | 3701 | } |
| 3702 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 3703 | shsurf->view = weston_view_create(surface); |
| 3704 | if (!shsurf->view) { |
| 3705 | weston_log("no memory to allocate shell surface\n"); |
| 3706 | free(shsurf); |
| 3707 | return NULL; |
| 3708 | } |
| 3709 | |
Ander Conselvan de Oliveira | 093bfa3 | 2012-03-27 17:36:41 +0300 | [diff] [blame] | 3710 | surface->configure = shell_surface_configure; |
Giulio Camuffo | 7fe01b1 | 2013-03-28 18:02:42 +0100 | [diff] [blame] | 3711 | surface->configure_private = shsurf; |
Pekka Paalanen | 8274d90 | 2014-08-06 19:36:51 +0300 | [diff] [blame] | 3712 | weston_surface_set_label_func(surface, shell_surface_get_label); |
Ander Conselvan de Oliveira | 093bfa3 | 2012-03-27 17:36:41 +0300 | [diff] [blame] | 3713 | |
Kristian Høgsberg | 160fe75 | 2014-03-11 10:19:10 -0700 | [diff] [blame] | 3714 | shsurf->resource_destroy_listener.notify = handle_resource_destroy; |
| 3715 | wl_resource_add_destroy_listener(surface->resource, |
| 3716 | &shsurf->resource_destroy_listener); |
Jason Ekstrand | 9e9512f | 2014-04-16 21:12:10 -0500 | [diff] [blame] | 3717 | shsurf->owner = owner; |
Kristian Høgsberg | 160fe75 | 2014-03-11 10:19:10 -0700 | [diff] [blame] | 3718 | |
Tiago Vignatti | bc052c9 | 2012-04-19 16:18:18 +0300 | [diff] [blame] | 3719 | shsurf->shell = (struct desktop_shell *) shell; |
Scott Moreau | ff1db4a | 2012-04-17 19:06:18 -0600 | [diff] [blame] | 3720 | shsurf->unresponsive = 0; |
Alex Wu | 4539b08 | 2012-03-01 12:57:46 +0800 | [diff] [blame] | 3721 | shsurf->saved_position_valid = false; |
Alex Wu | 7bcb8bd | 2012-04-27 09:07:24 +0800 | [diff] [blame] | 3722 | shsurf->saved_rotation_valid = false; |
Pekka Paalanen | 9d1613e | 2011-11-25 12:09:16 +0200 | [diff] [blame] | 3723 | shsurf->surface = surface; |
Alex Wu | 4539b08 | 2012-03-01 12:57:46 +0800 | [diff] [blame] | 3724 | shsurf->fullscreen.type = WL_SHELL_SURFACE_FULLSCREEN_METHOD_DEFAULT; |
| 3725 | shsurf->fullscreen.framerate = 0; |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 3726 | shsurf->fullscreen.black_view = NULL; |
Alex Wu | 4539b08 | 2012-03-01 12:57:46 +0800 | [diff] [blame] | 3727 | wl_list_init(&shsurf->fullscreen.transform.link); |
| 3728 | |
Jasper St. Pierre | 9aa8ce6 | 2014-04-11 16:18:54 -0700 | [diff] [blame] | 3729 | shsurf->output = get_default_output(shsurf->shell->compositor); |
| 3730 | |
Jason Ekstrand | 651f00e | 2013-06-14 10:07:54 -0500 | [diff] [blame] | 3731 | wl_signal_init(&shsurf->destroy_signal); |
Kristian Høgsberg | 27e3052 | 2012-04-11 23:18:23 -0400 | [diff] [blame] | 3732 | shsurf->surface_destroy_listener.notify = shell_handle_surface_destroy; |
Jason Ekstrand | 26ed73c | 2013-06-06 22:34:41 -0500 | [diff] [blame] | 3733 | wl_signal_add(&surface->destroy_signal, |
Kristian Høgsberg | 27e3052 | 2012-04-11 23:18:23 -0400 | [diff] [blame] | 3734 | &shsurf->surface_destroy_listener); |
Pekka Paalanen | 9d1613e | 2011-11-25 12:09:16 +0200 | [diff] [blame] | 3735 | |
| 3736 | /* init link so its safe to always remove it in destroy_shell_surface */ |
| 3737 | wl_list_init(&shsurf->link); |
Giulio Camuffo | 5085a75 | 2013-03-25 21:42:45 +0100 | [diff] [blame] | 3738 | wl_list_init(&shsurf->popup.grab_link); |
Pekka Paalanen | 9d1613e | 2011-11-25 12:09:16 +0200 | [diff] [blame] | 3739 | |
Pekka Paalanen | 460099f | 2012-01-20 16:48:25 +0200 | [diff] [blame] | 3740 | /* empty when not in use */ |
| 3741 | wl_list_init(&shsurf->rotation.transform.link); |
Kristian Høgsberg | 765e27b | 2012-01-27 13:36:13 -0500 | [diff] [blame] | 3742 | weston_matrix_init(&shsurf->rotation.rotation); |
Pekka Paalanen | 460099f | 2012-01-20 16:48:25 +0200 | [diff] [blame] | 3743 | |
Jonas Ådahl | 62fcd04 | 2012-06-13 00:01:23 +0200 | [diff] [blame] | 3744 | wl_list_init(&shsurf->workspace_transform.link); |
| 3745 | |
Philip Withnall | 648a4dd | 2013-11-25 18:01:44 +0000 | [diff] [blame] | 3746 | wl_list_init(&shsurf->children_link); |
| 3747 | wl_list_init(&shsurf->children_list); |
| 3748 | shsurf->parent = NULL; |
| 3749 | |
Pekka Paalanen | b502654 | 2014-11-12 15:09:24 +0200 | [diff] [blame] | 3750 | set_type(shsurf, SHELL_SURFACE_NONE); |
Pekka Paalanen | 9d1613e | 2011-11-25 12:09:16 +0200 | [diff] [blame] | 3751 | |
Kristian Høgsberg | a61ca06 | 2012-05-22 16:05:52 -0400 | [diff] [blame] | 3752 | shsurf->client = client; |
| 3753 | |
Kristian Høgsberg | 45ba869 | 2012-05-21 14:27:33 -0400 | [diff] [blame] | 3754 | return shsurf; |
Tiago Vignatti | bc052c9 | 2012-04-19 16:18:18 +0300 | [diff] [blame] | 3755 | } |
| 3756 | |
Rafael Antognolli | e2a3455 | 2013-12-03 15:35:45 -0200 | [diff] [blame] | 3757 | static struct shell_surface * |
| 3758 | create_shell_surface(void *shell, struct weston_surface *surface, |
| 3759 | const struct weston_shell_client *client) |
| 3760 | { |
Jason Ekstrand | 9e9512f | 2014-04-16 21:12:10 -0500 | [diff] [blame] | 3761 | return create_common_surface(NULL, shell, surface, client); |
Rafael Antognolli | e2a3455 | 2013-12-03 15:35:45 -0200 | [diff] [blame] | 3762 | } |
| 3763 | |
Tiago Vignatti | bc052c9 | 2012-04-19 16:18:18 +0300 | [diff] [blame] | 3764 | static void |
| 3765 | shell_get_shell_surface(struct wl_client *client, |
| 3766 | struct wl_resource *resource, |
| 3767 | uint32_t id, |
| 3768 | struct wl_resource *surface_resource) |
| 3769 | { |
Jason Ekstrand | 0f2ef7e | 2013-06-14 10:07:53 -0500 | [diff] [blame] | 3770 | struct weston_surface *surface = |
| 3771 | wl_resource_get_user_data(surface_resource); |
Jason Ekstrand | 9e9512f | 2014-04-16 21:12:10 -0500 | [diff] [blame] | 3772 | struct shell_client *sc = wl_resource_get_user_data(resource); |
| 3773 | struct desktop_shell *shell = sc->shell; |
Tiago Vignatti | bc052c9 | 2012-04-19 16:18:18 +0300 | [diff] [blame] | 3774 | struct shell_surface *shsurf; |
| 3775 | |
Pekka Paalanen | 50b6747 | 2014-10-01 15:02:41 +0300 | [diff] [blame] | 3776 | if (weston_surface_set_role(surface, "wl_shell_surface", |
| 3777 | resource, WL_SHELL_ERROR_ROLE) < 0) |
Tiago Vignatti | bc052c9 | 2012-04-19 16:18:18 +0300 | [diff] [blame] | 3778 | return; |
Tiago Vignatti | bc052c9 | 2012-04-19 16:18:18 +0300 | [diff] [blame] | 3779 | |
Jason Ekstrand | 9e9512f | 2014-04-16 21:12:10 -0500 | [diff] [blame] | 3780 | shsurf = create_common_surface(sc, shell, surface, &shell_client); |
Kristian Høgsberg | 9540ea6 | 2012-05-21 14:28:57 -0400 | [diff] [blame] | 3781 | if (!shsurf) { |
Pekka Paalanen | 50b6747 | 2014-10-01 15:02:41 +0300 | [diff] [blame] | 3782 | wl_resource_post_no_memory(surface_resource); |
Kristian Høgsberg | 9540ea6 | 2012-05-21 14:28:57 -0400 | [diff] [blame] | 3783 | return; |
| 3784 | } |
Tiago Vignatti | bc052c9 | 2012-04-19 16:18:18 +0300 | [diff] [blame] | 3785 | |
Jason Ekstrand | a85118c | 2013-06-27 20:17:02 -0500 | [diff] [blame] | 3786 | shsurf->resource = |
| 3787 | wl_resource_create(client, |
| 3788 | &wl_shell_surface_interface, 1, id); |
Bryce Harrington | 22b1f93 | 2015-09-23 17:30:43 -0700 | [diff] [blame] | 3789 | if (!shsurf->resource) { |
| 3790 | wl_resource_post_no_memory(surface_resource); |
| 3791 | return; |
| 3792 | } |
Jason Ekstrand | a85118c | 2013-06-27 20:17:02 -0500 | [diff] [blame] | 3793 | wl_resource_set_implementation(shsurf->resource, |
| 3794 | &shell_surface_implementation, |
| 3795 | shsurf, shell_destroy_shell_surface); |
Jonas Ådahl | d3a3ee9 | 2016-02-26 14:02:06 +0800 | [diff] [blame] | 3796 | wl_list_insert(&sc->surface_list, |
| 3797 | wl_resource_get_link(shsurf->resource)); |
Pekka Paalanen | 9d1613e | 2011-11-25 12:09:16 +0200 | [diff] [blame] | 3798 | } |
| 3799 | |
Rafael Antognolli | e2a3455 | 2013-12-03 15:35:45 -0200 | [diff] [blame] | 3800 | static bool |
| 3801 | shell_surface_is_wl_shell_surface(struct shell_surface *shsurf) |
| 3802 | { |
Kristian Høgsberg | 0b7d995 | 2014-02-03 15:50:38 -0800 | [diff] [blame] | 3803 | /* A shell surface without a resource is created from xwayland |
| 3804 | * and is considered a wl_shell surface for now. */ |
| 3805 | |
| 3806 | return shsurf->resource == NULL || |
| 3807 | wl_resource_instance_of(shsurf->resource, |
| 3808 | &wl_shell_surface_interface, |
| 3809 | &shell_surface_implementation); |
Rafael Antognolli | e2a3455 | 2013-12-03 15:35:45 -0200 | [diff] [blame] | 3810 | } |
| 3811 | |
Pekka Paalanen | 9d1613e | 2011-11-25 12:09:16 +0200 | [diff] [blame] | 3812 | static const struct wl_shell_interface shell_implementation = { |
Pekka Paalanen | 4622967 | 2011-11-29 15:49:31 +0200 | [diff] [blame] | 3813 | shell_get_shell_surface |
Kristian Høgsberg | 4cca349 | 2011-01-18 07:53:49 -0500 | [diff] [blame] | 3814 | }; |
| 3815 | |
Rafael Antognolli | e2a3455 | 2013-12-03 15:35:45 -0200 | [diff] [blame] | 3816 | /**************************** |
| 3817 | * xdg-shell implementation */ |
| 3818 | |
| 3819 | static void |
| 3820 | xdg_surface_destroy(struct wl_client *client, |
| 3821 | struct wl_resource *resource) |
| 3822 | { |
| 3823 | wl_resource_destroy(resource); |
| 3824 | } |
| 3825 | |
| 3826 | static void |
Jasper St. Pierre | c815d62 | 2014-04-10 18:37:54 -0700 | [diff] [blame] | 3827 | xdg_surface_set_parent(struct wl_client *client, |
| 3828 | struct wl_resource *resource, |
| 3829 | struct wl_resource *parent_resource) |
Jasper St. Pierre | 63a9c33 | 2014-02-01 18:35:15 -0500 | [diff] [blame] | 3830 | { |
| 3831 | struct shell_surface *shsurf = wl_resource_get_user_data(resource); |
Jasper St. Pierre | 66bc949 | 2015-02-13 14:01:55 +0800 | [diff] [blame] | 3832 | struct shell_surface *parent; |
Jasper St. Pierre | 63a9c33 | 2014-02-01 18:35:15 -0500 | [diff] [blame] | 3833 | |
Jasper St. Pierre | 66bc949 | 2015-02-13 14:01:55 +0800 | [diff] [blame] | 3834 | if (parent_resource) { |
Jasper St. Pierre | 63a9c33 | 2014-02-01 18:35:15 -0500 | [diff] [blame] | 3835 | parent = wl_resource_get_user_data(parent_resource); |
Jasper St. Pierre | 66bc949 | 2015-02-13 14:01:55 +0800 | [diff] [blame] | 3836 | shell_surface_set_parent(shsurf, parent->surface); |
| 3837 | } else { |
| 3838 | shell_surface_set_parent(shsurf, NULL); |
| 3839 | } |
Jasper St. Pierre | 63a9c33 | 2014-02-01 18:35:15 -0500 | [diff] [blame] | 3840 | } |
| 3841 | |
| 3842 | static void |
Rafael Antognolli | e2a3455 | 2013-12-03 15:35:45 -0200 | [diff] [blame] | 3843 | xdg_surface_set_app_id(struct wl_client *client, |
| 3844 | struct wl_resource *resource, |
| 3845 | const char *app_id) |
| 3846 | { |
| 3847 | struct shell_surface *shsurf = wl_resource_get_user_data(resource); |
| 3848 | |
| 3849 | free(shsurf->class); |
| 3850 | shsurf->class = strdup(app_id); |
Pekka Paalanen | b502654 | 2014-11-12 15:09:24 +0200 | [diff] [blame] | 3851 | shsurf->surface->timeline.force_refresh = 1; |
Rafael Antognolli | e2a3455 | 2013-12-03 15:35:45 -0200 | [diff] [blame] | 3852 | } |
| 3853 | |
| 3854 | static void |
Jasper St. Pierre | 81ff075 | 2014-03-13 11:04:53 -0400 | [diff] [blame] | 3855 | xdg_surface_show_window_menu(struct wl_client *client, |
| 3856 | struct wl_resource *surface_resource, |
| 3857 | struct wl_resource *seat_resource, |
| 3858 | uint32_t serial, |
| 3859 | int32_t x, |
| 3860 | int32_t y) |
| 3861 | { |
| 3862 | /* TODO */ |
| 3863 | } |
| 3864 | |
| 3865 | static void |
Rafael Antognolli | e2a3455 | 2013-12-03 15:35:45 -0200 | [diff] [blame] | 3866 | xdg_surface_set_title(struct wl_client *client, |
| 3867 | struct wl_resource *resource, const char *title) |
| 3868 | { |
| 3869 | struct shell_surface *shsurf = wl_resource_get_user_data(resource); |
| 3870 | |
| 3871 | set_title(shsurf, title); |
| 3872 | } |
| 3873 | |
| 3874 | static void |
| 3875 | xdg_surface_move(struct wl_client *client, struct wl_resource *resource, |
| 3876 | struct wl_resource *seat_resource, uint32_t serial) |
| 3877 | { |
| 3878 | common_surface_move(resource, seat_resource, serial); |
| 3879 | } |
| 3880 | |
| 3881 | static void |
| 3882 | xdg_surface_resize(struct wl_client *client, struct wl_resource *resource, |
| 3883 | struct wl_resource *seat_resource, uint32_t serial, |
| 3884 | uint32_t edges) |
| 3885 | { |
| 3886 | common_surface_resize(resource, seat_resource, serial, edges); |
| 3887 | } |
| 3888 | |
| 3889 | static void |
Jasper St. Pierre | ab2c108 | 2014-04-10 10:41:46 -0700 | [diff] [blame] | 3890 | xdg_surface_ack_configure(struct wl_client *client, |
| 3891 | struct wl_resource *resource, |
| 3892 | uint32_t serial) |
Rafael Antognolli | e2a3455 | 2013-12-03 15:35:45 -0200 | [diff] [blame] | 3893 | { |
| 3894 | struct shell_surface *shsurf = wl_resource_get_user_data(resource); |
| 3895 | |
Jasper St. Pierre | 8c6aa45 | 2014-02-08 18:29:49 -0500 | [diff] [blame] | 3896 | if (shsurf->state_requested) { |
| 3897 | shsurf->next_state = shsurf->requested_state; |
| 3898 | shsurf->state_changed = true; |
| 3899 | shsurf->state_requested = false; |
Rafael Antognolli | 3c4e3f7 | 2013-12-03 15:35:46 -0200 | [diff] [blame] | 3900 | } |
Rafael Antognolli | e2a3455 | 2013-12-03 15:35:45 -0200 | [diff] [blame] | 3901 | } |
| 3902 | |
Manuel Bachmann | 50c87db | 2014-02-26 15:52:13 +0100 | [diff] [blame] | 3903 | static void |
Jasper St. Pierre | ccf48fb | 2014-05-02 10:21:38 -0400 | [diff] [blame] | 3904 | xdg_surface_set_window_geometry(struct wl_client *client, |
| 3905 | struct wl_resource *resource, |
| 3906 | int32_t x, |
| 3907 | int32_t y, |
| 3908 | int32_t width, |
| 3909 | int32_t height) |
| 3910 | { |
| 3911 | struct shell_surface *shsurf = wl_resource_get_user_data(resource); |
| 3912 | |
| 3913 | set_window_geometry(shsurf, x, y, width, height); |
| 3914 | } |
| 3915 | |
| 3916 | static void |
Jasper St. Pierre | ab2c108 | 2014-04-10 10:41:46 -0700 | [diff] [blame] | 3917 | xdg_surface_set_maximized(struct wl_client *client, |
| 3918 | struct wl_resource *resource) |
| 3919 | { |
| 3920 | struct shell_surface *shsurf = wl_resource_get_user_data(resource); |
Marek Chalupa | bfbb64b | 2014-09-08 12:34:20 +0200 | [diff] [blame] | 3921 | struct weston_output *output; |
Jasper St. Pierre | ab2c108 | 2014-04-10 10:41:46 -0700 | [diff] [blame] | 3922 | |
| 3923 | shsurf->state_requested = true; |
| 3924 | shsurf->requested_state.maximized = true; |
Marek Chalupa | bfbb64b | 2014-09-08 12:34:20 +0200 | [diff] [blame] | 3925 | |
| 3926 | if (!weston_surface_is_mapped(shsurf->surface)) |
| 3927 | output = get_focused_output(shsurf->surface->compositor); |
| 3928 | else |
| 3929 | output = shsurf->surface->output; |
| 3930 | |
| 3931 | shell_surface_set_output(shsurf, output); |
Jasper St. Pierre | 9aa8ce6 | 2014-04-11 16:18:54 -0700 | [diff] [blame] | 3932 | send_configure_for_surface(shsurf); |
Jasper St. Pierre | ab2c108 | 2014-04-10 10:41:46 -0700 | [diff] [blame] | 3933 | } |
| 3934 | |
| 3935 | static void |
| 3936 | xdg_surface_unset_maximized(struct wl_client *client, |
| 3937 | struct wl_resource *resource) |
| 3938 | { |
| 3939 | struct shell_surface *shsurf = wl_resource_get_user_data(resource); |
| 3940 | |
| 3941 | shsurf->state_requested = true; |
| 3942 | shsurf->requested_state.maximized = false; |
Jasper St. Pierre | 6458ec3 | 2014-04-11 16:00:31 -0700 | [diff] [blame] | 3943 | send_configure_for_surface(shsurf); |
Jasper St. Pierre | ab2c108 | 2014-04-10 10:41:46 -0700 | [diff] [blame] | 3944 | } |
| 3945 | |
| 3946 | static void |
| 3947 | xdg_surface_set_fullscreen(struct wl_client *client, |
| 3948 | struct wl_resource *resource, |
| 3949 | struct wl_resource *output_resource) |
| 3950 | { |
| 3951 | struct shell_surface *shsurf = wl_resource_get_user_data(resource); |
| 3952 | struct weston_output *output; |
| 3953 | |
| 3954 | shsurf->state_requested = true; |
| 3955 | shsurf->requested_state.fullscreen = true; |
| 3956 | |
| 3957 | if (output_resource) |
| 3958 | output = wl_resource_get_user_data(output_resource); |
| 3959 | else |
| 3960 | output = NULL; |
| 3961 | |
Marek Chalupa | 052917a | 2014-09-02 11:35:12 +0200 | [diff] [blame] | 3962 | /* handle clients launching in fullscreen */ |
| 3963 | if (output == NULL && !weston_surface_is_mapped(shsurf->surface)) { |
| 3964 | /* Set the output to the one that has focus currently. */ |
| 3965 | assert(shsurf->surface); |
| 3966 | output = get_focused_output(shsurf->surface->compositor); |
| 3967 | } |
| 3968 | |
Jasper St. Pierre | 9aa8ce6 | 2014-04-11 16:18:54 -0700 | [diff] [blame] | 3969 | shell_surface_set_output(shsurf, output); |
| 3970 | shsurf->fullscreen_output = shsurf->output; |
Jasper St. Pierre | ab2c108 | 2014-04-10 10:41:46 -0700 | [diff] [blame] | 3971 | |
Jasper St. Pierre | 9aa8ce6 | 2014-04-11 16:18:54 -0700 | [diff] [blame] | 3972 | send_configure_for_surface(shsurf); |
Jasper St. Pierre | ab2c108 | 2014-04-10 10:41:46 -0700 | [diff] [blame] | 3973 | } |
| 3974 | |
| 3975 | static void |
| 3976 | xdg_surface_unset_fullscreen(struct wl_client *client, |
| 3977 | struct wl_resource *resource) |
| 3978 | { |
| 3979 | struct shell_surface *shsurf = wl_resource_get_user_data(resource); |
| 3980 | |
| 3981 | shsurf->state_requested = true; |
| 3982 | shsurf->requested_state.fullscreen = false; |
Jasper St. Pierre | 6458ec3 | 2014-04-11 16:00:31 -0700 | [diff] [blame] | 3983 | send_configure_for_surface(shsurf); |
Jasper St. Pierre | ab2c108 | 2014-04-10 10:41:46 -0700 | [diff] [blame] | 3984 | } |
| 3985 | |
| 3986 | static void |
Manuel Bachmann | 50c87db | 2014-02-26 15:52:13 +0100 | [diff] [blame] | 3987 | xdg_surface_set_minimized(struct wl_client *client, |
| 3988 | struct wl_resource *resource) |
| 3989 | { |
| 3990 | struct shell_surface *shsurf = wl_resource_get_user_data(resource); |
| 3991 | |
| 3992 | if (shsurf->type != SHELL_SURFACE_TOPLEVEL) |
| 3993 | return; |
| 3994 | |
| 3995 | /* apply compositor's own minimization logic (hide) */ |
Manuel Bachmann | dc1c3e4 | 2015-02-16 11:52:13 +0100 | [diff] [blame] | 3996 | set_minimized(shsurf->surface); |
Manuel Bachmann | 50c87db | 2014-02-26 15:52:13 +0100 | [diff] [blame] | 3997 | } |
| 3998 | |
Rafael Antognolli | e2a3455 | 2013-12-03 15:35:45 -0200 | [diff] [blame] | 3999 | static const struct xdg_surface_interface xdg_surface_implementation = { |
| 4000 | xdg_surface_destroy, |
Jasper St. Pierre | c815d62 | 2014-04-10 18:37:54 -0700 | [diff] [blame] | 4001 | xdg_surface_set_parent, |
Rafael Antognolli | e2a3455 | 2013-12-03 15:35:45 -0200 | [diff] [blame] | 4002 | xdg_surface_set_title, |
| 4003 | xdg_surface_set_app_id, |
Jasper St. Pierre | 81ff075 | 2014-03-13 11:04:53 -0400 | [diff] [blame] | 4004 | xdg_surface_show_window_menu, |
Rafael Antognolli | e2a3455 | 2013-12-03 15:35:45 -0200 | [diff] [blame] | 4005 | xdg_surface_move, |
| 4006 | xdg_surface_resize, |
Jasper St. Pierre | ab2c108 | 2014-04-10 10:41:46 -0700 | [diff] [blame] | 4007 | xdg_surface_ack_configure, |
Jasper St. Pierre | ccf48fb | 2014-05-02 10:21:38 -0400 | [diff] [blame] | 4008 | xdg_surface_set_window_geometry, |
Jasper St. Pierre | ab2c108 | 2014-04-10 10:41:46 -0700 | [diff] [blame] | 4009 | xdg_surface_set_maximized, |
| 4010 | xdg_surface_unset_maximized, |
| 4011 | xdg_surface_set_fullscreen, |
| 4012 | xdg_surface_unset_fullscreen, |
| 4013 | xdg_surface_set_minimized, |
Rafael Antognolli | e2a3455 | 2013-12-03 15:35:45 -0200 | [diff] [blame] | 4014 | }; |
| 4015 | |
| 4016 | static void |
| 4017 | xdg_send_configure(struct weston_surface *surface, |
Jasper St. Pierre | ac985be | 2014-04-28 11:19:28 -0400 | [diff] [blame] | 4018 | int32_t width, int32_t height) |
Rafael Antognolli | e2a3455 | 2013-12-03 15:35:45 -0200 | [diff] [blame] | 4019 | { |
| 4020 | struct shell_surface *shsurf = get_shell_surface(surface); |
Jasper St. Pierre | ab2c108 | 2014-04-10 10:41:46 -0700 | [diff] [blame] | 4021 | uint32_t *s; |
| 4022 | struct wl_array states; |
| 4023 | uint32_t serial; |
Rafael Antognolli | e2a3455 | 2013-12-03 15:35:45 -0200 | [diff] [blame] | 4024 | |
U. Artie Eoff | cf5737a | 2014-01-17 10:08:25 -0800 | [diff] [blame] | 4025 | assert(shsurf); |
| 4026 | |
Jasper St. Pierre | ab2c108 | 2014-04-10 10:41:46 -0700 | [diff] [blame] | 4027 | if (!shsurf->resource) |
| 4028 | return; |
| 4029 | |
| 4030 | wl_array_init(&states); |
| 4031 | if (shsurf->requested_state.fullscreen) { |
| 4032 | s = wl_array_add(&states, sizeof *s); |
| 4033 | *s = XDG_SURFACE_STATE_FULLSCREEN; |
| 4034 | } else if (shsurf->requested_state.maximized) { |
| 4035 | s = wl_array_add(&states, sizeof *s); |
| 4036 | *s = XDG_SURFACE_STATE_MAXIMIZED; |
| 4037 | } |
Jasper St. Pierre | 5befdda | 2014-05-06 08:50:47 -0400 | [diff] [blame] | 4038 | if (shsurf->resize_edges != 0) { |
| 4039 | s = wl_array_add(&states, sizeof *s); |
| 4040 | *s = XDG_SURFACE_STATE_RESIZING; |
| 4041 | } |
Jasper St. Pierre | 973d787 | 2014-05-06 08:44:29 -0400 | [diff] [blame] | 4042 | if (shsurf->focus_count > 0) { |
| 4043 | s = wl_array_add(&states, sizeof *s); |
| 4044 | *s = XDG_SURFACE_STATE_ACTIVATED; |
| 4045 | } |
Jasper St. Pierre | ab2c108 | 2014-04-10 10:41:46 -0700 | [diff] [blame] | 4046 | |
| 4047 | serial = wl_display_next_serial(shsurf->surface->compositor->wl_display); |
| 4048 | xdg_surface_send_configure(shsurf->resource, width, height, &states, serial); |
| 4049 | |
| 4050 | wl_array_release(&states); |
Rafael Antognolli | e2a3455 | 2013-12-03 15:35:45 -0200 | [diff] [blame] | 4051 | } |
| 4052 | |
| 4053 | static const struct weston_shell_client xdg_client = { |
Giulio Camuffo | f05d18f | 2015-12-11 20:57:05 +0200 | [diff] [blame] | 4054 | xdg_send_configure, |
| 4055 | NULL |
Rafael Antognolli | e2a3455 | 2013-12-03 15:35:45 -0200 | [diff] [blame] | 4056 | }; |
| 4057 | |
| 4058 | static void |
Jasper St. Pierre | 084aa0b | 2015-02-13 14:02:00 +0800 | [diff] [blame] | 4059 | xdg_shell_destroy(struct wl_client *client, |
| 4060 | struct wl_resource *resource) |
| 4061 | { |
Jonas Ådahl | 49d77d2 | 2015-03-18 16:20:51 +0800 | [diff] [blame] | 4062 | struct shell_client *sc = wl_resource_get_user_data(resource); |
| 4063 | struct wl_resource *shsurf_resource; |
| 4064 | struct shell_surface *shsurf; |
| 4065 | |
| 4066 | wl_resource_for_each(shsurf_resource, &sc->surface_list) { |
| 4067 | shsurf = wl_resource_get_user_data(shsurf_resource); |
| 4068 | if (shsurf->owner_resource == resource) { |
| 4069 | wl_resource_post_error( |
| 4070 | resource, |
| 4071 | XDG_SHELL_ERROR_DEFUNCT_SURFACES, |
| 4072 | "not all child surface objects destroyed"); |
| 4073 | return; |
| 4074 | } |
| 4075 | } |
| 4076 | |
Jasper St. Pierre | 084aa0b | 2015-02-13 14:02:00 +0800 | [diff] [blame] | 4077 | wl_resource_destroy(resource); |
| 4078 | } |
| 4079 | |
| 4080 | static void |
Rafael Antognolli | e2a3455 | 2013-12-03 15:35:45 -0200 | [diff] [blame] | 4081 | xdg_use_unstable_version(struct wl_client *client, |
| 4082 | struct wl_resource *resource, |
| 4083 | int32_t version) |
| 4084 | { |
| 4085 | if (version > 1) { |
| 4086 | wl_resource_post_error(resource, |
| 4087 | 1, |
| 4088 | "xdg-shell:: version not implemented yet."); |
| 4089 | return; |
| 4090 | } |
| 4091 | } |
| 4092 | |
| 4093 | static struct shell_surface * |
Jason Ekstrand | 9e9512f | 2014-04-16 21:12:10 -0500 | [diff] [blame] | 4094 | create_xdg_surface(struct shell_client *owner, void *shell, |
| 4095 | struct weston_surface *surface, |
Rafael Antognolli | e2a3455 | 2013-12-03 15:35:45 -0200 | [diff] [blame] | 4096 | const struct weston_shell_client *client) |
| 4097 | { |
| 4098 | struct shell_surface *shsurf; |
Rafael Antognolli | e2a3455 | 2013-12-03 15:35:45 -0200 | [diff] [blame] | 4099 | |
Jason Ekstrand | 9e9512f | 2014-04-16 21:12:10 -0500 | [diff] [blame] | 4100 | shsurf = create_common_surface(owner, shell, surface, client); |
Pekka Paalanen | e972b27 | 2014-10-01 14:03:56 +0300 | [diff] [blame] | 4101 | if (!shsurf) |
| 4102 | return NULL; |
| 4103 | |
Pekka Paalanen | b502654 | 2014-11-12 15:09:24 +0200 | [diff] [blame] | 4104 | set_type(shsurf, SHELL_SURFACE_TOPLEVEL); |
Rafael Antognolli | e2a3455 | 2013-12-03 15:35:45 -0200 | [diff] [blame] | 4105 | |
| 4106 | return shsurf; |
| 4107 | } |
| 4108 | |
| 4109 | static void |
| 4110 | xdg_get_xdg_surface(struct wl_client *client, |
| 4111 | struct wl_resource *resource, |
| 4112 | uint32_t id, |
| 4113 | struct wl_resource *surface_resource) |
| 4114 | { |
| 4115 | struct weston_surface *surface = |
| 4116 | wl_resource_get_user_data(surface_resource); |
Kristian Høgsberg | 2bff94e | 2014-02-11 12:22:51 -0800 | [diff] [blame] | 4117 | struct shell_client *sc = wl_resource_get_user_data(resource); |
| 4118 | struct desktop_shell *shell = sc->shell; |
Rafael Antognolli | e2a3455 | 2013-12-03 15:35:45 -0200 | [diff] [blame] | 4119 | struct shell_surface *shsurf; |
| 4120 | |
Jonas Ådahl | bf48e21 | 2015-02-06 10:15:28 +0800 | [diff] [blame] | 4121 | shsurf = get_shell_surface(surface); |
| 4122 | if (shsurf && shell_surface_is_xdg_surface(shsurf)) { |
| 4123 | wl_resource_post_error(resource, XDG_SHELL_ERROR_ROLE, |
| 4124 | "This wl_surface is already an " |
| 4125 | "xdg_surface"); |
| 4126 | return; |
| 4127 | } |
| 4128 | |
Pekka Paalanen | 50b6747 | 2014-10-01 15:02:41 +0300 | [diff] [blame] | 4129 | if (weston_surface_set_role(surface, "xdg_surface", |
| 4130 | resource, XDG_SHELL_ERROR_ROLE) < 0) |
Rafael Antognolli | e2a3455 | 2013-12-03 15:35:45 -0200 | [diff] [blame] | 4131 | return; |
Rafael Antognolli | e2a3455 | 2013-12-03 15:35:45 -0200 | [diff] [blame] | 4132 | |
Jason Ekstrand | 9e9512f | 2014-04-16 21:12:10 -0500 | [diff] [blame] | 4133 | shsurf = create_xdg_surface(sc, shell, surface, &xdg_client); |
Rafael Antognolli | e2a3455 | 2013-12-03 15:35:45 -0200 | [diff] [blame] | 4134 | if (!shsurf) { |
Pekka Paalanen | 50b6747 | 2014-10-01 15:02:41 +0300 | [diff] [blame] | 4135 | wl_resource_post_no_memory(surface_resource); |
Rafael Antognolli | e2a3455 | 2013-12-03 15:35:45 -0200 | [diff] [blame] | 4136 | return; |
| 4137 | } |
| 4138 | |
| 4139 | shsurf->resource = |
| 4140 | wl_resource_create(client, |
| 4141 | &xdg_surface_interface, 1, id); |
Bryce Harrington | 22b1f93 | 2015-09-23 17:30:43 -0700 | [diff] [blame] | 4142 | if (!shsurf->resource) { |
| 4143 | wl_resource_post_no_memory(surface_resource); |
| 4144 | return; |
| 4145 | } |
Rafael Antognolli | e2a3455 | 2013-12-03 15:35:45 -0200 | [diff] [blame] | 4146 | wl_resource_set_implementation(shsurf->resource, |
| 4147 | &xdg_surface_implementation, |
| 4148 | shsurf, shell_destroy_shell_surface); |
Jonas Ådahl | 49d77d2 | 2015-03-18 16:20:51 +0800 | [diff] [blame] | 4149 | shsurf->owner_resource = resource; |
| 4150 | wl_list_insert(&sc->surface_list, |
| 4151 | wl_resource_get_link(shsurf->resource)); |
Rafael Antognolli | e2a3455 | 2013-12-03 15:35:45 -0200 | [diff] [blame] | 4152 | } |
| 4153 | |
| 4154 | static bool |
| 4155 | shell_surface_is_xdg_surface(struct shell_surface *shsurf) |
| 4156 | { |
Kristian Høgsberg | 0b7d995 | 2014-02-03 15:50:38 -0800 | [diff] [blame] | 4157 | return shsurf->resource && |
| 4158 | wl_resource_instance_of(shsurf->resource, |
| 4159 | &xdg_surface_interface, |
| 4160 | &xdg_surface_implementation); |
Rafael Antognolli | e2a3455 | 2013-12-03 15:35:45 -0200 | [diff] [blame] | 4161 | } |
| 4162 | |
| 4163 | /* xdg-popup implementation */ |
| 4164 | |
| 4165 | static void |
| 4166 | xdg_popup_destroy(struct wl_client *client, |
| 4167 | struct wl_resource *resource) |
| 4168 | { |
| 4169 | wl_resource_destroy(resource); |
| 4170 | } |
| 4171 | |
Rafael Antognolli | e2a3455 | 2013-12-03 15:35:45 -0200 | [diff] [blame] | 4172 | static const struct xdg_popup_interface xdg_popup_implementation = { |
| 4173 | xdg_popup_destroy, |
Rafael Antognolli | e2a3455 | 2013-12-03 15:35:45 -0200 | [diff] [blame] | 4174 | }; |
| 4175 | |
| 4176 | static void |
| 4177 | xdg_popup_send_configure(struct weston_surface *surface, |
Jasper St. Pierre | ac985be | 2014-04-28 11:19:28 -0400 | [diff] [blame] | 4178 | int32_t width, int32_t height) |
Rafael Antognolli | e2a3455 | 2013-12-03 15:35:45 -0200 | [diff] [blame] | 4179 | { |
| 4180 | } |
| 4181 | |
| 4182 | static const struct weston_shell_client xdg_popup_client = { |
Giulio Camuffo | f05d18f | 2015-12-11 20:57:05 +0200 | [diff] [blame] | 4183 | xdg_popup_send_configure, |
| 4184 | NULL |
Rafael Antognolli | e2a3455 | 2013-12-03 15:35:45 -0200 | [diff] [blame] | 4185 | }; |
| 4186 | |
| 4187 | static struct shell_surface * |
Jason Ekstrand | 9e9512f | 2014-04-16 21:12:10 -0500 | [diff] [blame] | 4188 | create_xdg_popup(struct shell_client *owner, void *shell, |
| 4189 | struct weston_surface *surface, |
Rafael Antognolli | e2a3455 | 2013-12-03 15:35:45 -0200 | [diff] [blame] | 4190 | const struct weston_shell_client *client, |
| 4191 | struct weston_surface *parent, |
| 4192 | struct shell_seat *seat, |
| 4193 | uint32_t serial, |
| 4194 | int32_t x, int32_t y) |
| 4195 | { |
Jonas Ådahl | ee45a55 | 2015-03-18 16:37:47 +0800 | [diff] [blame] | 4196 | struct shell_surface *shsurf; |
Jonas Ådahl | 24185e2 | 2015-02-27 18:37:41 +0800 | [diff] [blame] | 4197 | |
Jason Ekstrand | 9e9512f | 2014-04-16 21:12:10 -0500 | [diff] [blame] | 4198 | shsurf = create_common_surface(owner, shell, surface, client); |
Pekka Paalanen | e972b27 | 2014-10-01 14:03:56 +0300 | [diff] [blame] | 4199 | if (!shsurf) |
| 4200 | return NULL; |
| 4201 | |
Pekka Paalanen | b502654 | 2014-11-12 15:09:24 +0200 | [diff] [blame] | 4202 | set_type(shsurf, SHELL_SURFACE_POPUP); |
Rafael Antognolli | e2a3455 | 2013-12-03 15:35:45 -0200 | [diff] [blame] | 4203 | shsurf->popup.shseat = seat; |
| 4204 | shsurf->popup.serial = serial; |
| 4205 | shsurf->popup.x = x; |
| 4206 | shsurf->popup.y = y; |
| 4207 | shell_surface_set_parent(shsurf, parent); |
| 4208 | |
| 4209 | return shsurf; |
| 4210 | } |
| 4211 | |
| 4212 | static void |
| 4213 | xdg_get_xdg_popup(struct wl_client *client, |
| 4214 | struct wl_resource *resource, |
| 4215 | uint32_t id, |
| 4216 | struct wl_resource *surface_resource, |
| 4217 | struct wl_resource *parent_resource, |
| 4218 | struct wl_resource *seat_resource, |
| 4219 | uint32_t serial, |
Jasper St. Pierre | 14f330c | 2015-02-13 14:01:57 +0800 | [diff] [blame] | 4220 | int32_t x, int32_t y) |
Rafael Antognolli | e2a3455 | 2013-12-03 15:35:45 -0200 | [diff] [blame] | 4221 | { |
| 4222 | struct weston_surface *surface = |
| 4223 | wl_resource_get_user_data(surface_resource); |
Kristian Høgsberg | 2bff94e | 2014-02-11 12:22:51 -0800 | [diff] [blame] | 4224 | struct shell_client *sc = wl_resource_get_user_data(resource); |
| 4225 | struct desktop_shell *shell = sc->shell; |
Rafael Antognolli | e2a3455 | 2013-12-03 15:35:45 -0200 | [diff] [blame] | 4226 | struct shell_surface *shsurf; |
Jonas Ådahl | ee45a55 | 2015-03-18 16:37:47 +0800 | [diff] [blame] | 4227 | struct shell_surface *parent_shsurf; |
Rafael Antognolli | e2a3455 | 2013-12-03 15:35:45 -0200 | [diff] [blame] | 4228 | struct weston_surface *parent; |
| 4229 | struct shell_seat *seat; |
| 4230 | |
Jonas Ådahl | bf48e21 | 2015-02-06 10:15:28 +0800 | [diff] [blame] | 4231 | shsurf = get_shell_surface(surface); |
| 4232 | if (shsurf && shell_surface_is_xdg_popup(shsurf)) { |
| 4233 | wl_resource_post_error(resource, XDG_SHELL_ERROR_ROLE, |
| 4234 | "This wl_surface is already an " |
| 4235 | "xdg_popup"); |
| 4236 | return; |
| 4237 | } |
| 4238 | |
Pekka Paalanen | 50b6747 | 2014-10-01 15:02:41 +0300 | [diff] [blame] | 4239 | if (weston_surface_set_role(surface, "xdg_popup", |
| 4240 | resource, XDG_SHELL_ERROR_ROLE) < 0) |
Rafael Antognolli | e2a3455 | 2013-12-03 15:35:45 -0200 | [diff] [blame] | 4241 | return; |
Rafael Antognolli | e2a3455 | 2013-12-03 15:35:45 -0200 | [diff] [blame] | 4242 | |
| 4243 | if (!parent_resource) { |
| 4244 | wl_resource_post_error(surface_resource, |
| 4245 | WL_DISPLAY_ERROR_INVALID_OBJECT, |
| 4246 | "xdg_shell::get_xdg_popup requires a parent shell surface"); |
Jasper St. Pierre | 666bc92 | 2014-08-07 16:43:13 -0400 | [diff] [blame] | 4247 | return; |
Rafael Antognolli | e2a3455 | 2013-12-03 15:35:45 -0200 | [diff] [blame] | 4248 | } |
| 4249 | |
| 4250 | parent = wl_resource_get_user_data(parent_resource); |
Derek Foreman | bdc8c72 | 2015-10-07 11:51:29 -0500 | [diff] [blame] | 4251 | seat = get_shell_seat(wl_resource_get_user_data(seat_resource)); |
Rafael Antognolli | e2a3455 | 2013-12-03 15:35:45 -0200 | [diff] [blame] | 4252 | |
Jonas Ådahl | ee45a55 | 2015-03-18 16:37:47 +0800 | [diff] [blame] | 4253 | /* Verify that we are creating the top most popup when mapping, |
| 4254 | * as it's not until then we know whether it was mapped as most |
| 4255 | * top level or not. */ |
| 4256 | |
| 4257 | parent_shsurf = get_shell_surface(parent); |
Jonas Ådahl | bc5d849 | 2015-10-07 14:44:50 +0800 | [diff] [blame] | 4258 | if (!parent_shsurf || |
| 4259 | (!shell_surface_is_xdg_popup(parent_shsurf) && |
| 4260 | !shell_surface_is_xdg_surface(parent_shsurf))) { |
Jonas Ådahl | ee45a55 | 2015-03-18 16:37:47 +0800 | [diff] [blame] | 4261 | wl_resource_post_error(resource, |
| 4262 | XDG_SHELL_ERROR_INVALID_POPUP_PARENT, |
| 4263 | "xdg_popup parent was invalid"); |
| 4264 | return; |
| 4265 | } |
| 4266 | |
Jason Ekstrand | 9e9512f | 2014-04-16 21:12:10 -0500 | [diff] [blame] | 4267 | shsurf = create_xdg_popup(sc, shell, surface, &xdg_popup_client, |
Rafael Antognolli | e2a3455 | 2013-12-03 15:35:45 -0200 | [diff] [blame] | 4268 | parent, seat, serial, x, y); |
| 4269 | if (!shsurf) { |
Pekka Paalanen | 50b6747 | 2014-10-01 15:02:41 +0300 | [diff] [blame] | 4270 | wl_resource_post_no_memory(surface_resource); |
Rafael Antognolli | e2a3455 | 2013-12-03 15:35:45 -0200 | [diff] [blame] | 4271 | return; |
| 4272 | } |
| 4273 | |
| 4274 | shsurf->resource = |
| 4275 | wl_resource_create(client, |
| 4276 | &xdg_popup_interface, 1, id); |
Bryce Harrington | 22b1f93 | 2015-09-23 17:30:43 -0700 | [diff] [blame] | 4277 | if (!shsurf->resource) { |
| 4278 | wl_resource_post_no_memory(surface_resource); |
| 4279 | return; |
| 4280 | } |
Rafael Antognolli | e2a3455 | 2013-12-03 15:35:45 -0200 | [diff] [blame] | 4281 | wl_resource_set_implementation(shsurf->resource, |
| 4282 | &xdg_popup_implementation, |
| 4283 | shsurf, shell_destroy_shell_surface); |
Jonas Ådahl | 49d77d2 | 2015-03-18 16:20:51 +0800 | [diff] [blame] | 4284 | shsurf->owner_resource = resource; |
| 4285 | wl_list_insert(&sc->surface_list, |
| 4286 | wl_resource_get_link(shsurf->resource)); |
Rafael Antognolli | e2a3455 | 2013-12-03 15:35:45 -0200 | [diff] [blame] | 4287 | } |
| 4288 | |
Kristian Høgsberg | 2bff94e | 2014-02-11 12:22:51 -0800 | [diff] [blame] | 4289 | static void |
| 4290 | xdg_pong(struct wl_client *client, |
| 4291 | struct wl_resource *resource, uint32_t serial) |
| 4292 | { |
| 4293 | struct shell_client *sc = wl_resource_get_user_data(resource); |
Kristian Høgsberg | 2bff94e | 2014-02-11 12:22:51 -0800 | [diff] [blame] | 4294 | |
Kristian Høgsberg | dd62aba | 2014-02-12 09:56:19 -0800 | [diff] [blame] | 4295 | shell_client_pong(sc, serial); |
Kristian Høgsberg | 2bff94e | 2014-02-11 12:22:51 -0800 | [diff] [blame] | 4296 | } |
| 4297 | |
Rafael Antognolli | e2a3455 | 2013-12-03 15:35:45 -0200 | [diff] [blame] | 4298 | static bool |
| 4299 | shell_surface_is_xdg_popup(struct shell_surface *shsurf) |
| 4300 | { |
Bryce Harrington | 22b1f93 | 2015-09-23 17:30:43 -0700 | [diff] [blame] | 4301 | return (shsurf->resource && |
| 4302 | wl_resource_instance_of(shsurf->resource, |
| 4303 | &xdg_popup_interface, |
| 4304 | &xdg_popup_implementation)); |
Rafael Antognolli | e2a3455 | 2013-12-03 15:35:45 -0200 | [diff] [blame] | 4305 | } |
| 4306 | |
| 4307 | static const struct xdg_shell_interface xdg_implementation = { |
Jasper St. Pierre | 084aa0b | 2015-02-13 14:02:00 +0800 | [diff] [blame] | 4308 | xdg_shell_destroy, |
Rafael Antognolli | e2a3455 | 2013-12-03 15:35:45 -0200 | [diff] [blame] | 4309 | xdg_use_unstable_version, |
| 4310 | xdg_get_xdg_surface, |
Kristian Høgsberg | 2bff94e | 2014-02-11 12:22:51 -0800 | [diff] [blame] | 4311 | xdg_get_xdg_popup, |
| 4312 | xdg_pong |
Rafael Antognolli | e2a3455 | 2013-12-03 15:35:45 -0200 | [diff] [blame] | 4313 | }; |
| 4314 | |
| 4315 | static int |
| 4316 | xdg_shell_unversioned_dispatch(const void *implementation, |
| 4317 | void *_target, uint32_t opcode, |
| 4318 | const struct wl_message *message, |
| 4319 | union wl_argument *args) |
| 4320 | { |
| 4321 | struct wl_resource *resource = _target; |
Kristian Høgsberg | 2bff94e | 2014-02-11 12:22:51 -0800 | [diff] [blame] | 4322 | struct shell_client *sc = wl_resource_get_user_data(resource); |
Rafael Antognolli | e2a3455 | 2013-12-03 15:35:45 -0200 | [diff] [blame] | 4323 | |
Jasper St. Pierre | 084aa0b | 2015-02-13 14:02:00 +0800 | [diff] [blame] | 4324 | if (opcode != 1 /* XDG_SHELL_USE_UNSTABLE_VERSION */) { |
Rafael Antognolli | e2a3455 | 2013-12-03 15:35:45 -0200 | [diff] [blame] | 4325 | wl_resource_post_error(resource, |
| 4326 | WL_DISPLAY_ERROR_INVALID_OBJECT, |
| 4327 | "must call use_unstable_version first"); |
| 4328 | return 0; |
| 4329 | } |
| 4330 | |
Jasper St. Pierre | 5ba1e1d | 2015-02-13 14:02:02 +0800 | [diff] [blame] | 4331 | #define XDG_SERVER_VERSION 5 |
Rafael Antognolli | e2a3455 | 2013-12-03 15:35:45 -0200 | [diff] [blame] | 4332 | |
Kristian Høgsberg | 8d344a0 | 2013-12-08 22:27:11 -0800 | [diff] [blame] | 4333 | static_assert(XDG_SERVER_VERSION == XDG_SHELL_VERSION_CURRENT, |
| 4334 | "shell implementation doesn't match protocol version"); |
| 4335 | |
Rafael Antognolli | e2a3455 | 2013-12-03 15:35:45 -0200 | [diff] [blame] | 4336 | if (args[0].i != XDG_SERVER_VERSION) { |
| 4337 | wl_resource_post_error(resource, |
| 4338 | WL_DISPLAY_ERROR_INVALID_OBJECT, |
| 4339 | "incompatible version, server is %d " |
| 4340 | "client wants %d", |
| 4341 | XDG_SERVER_VERSION, args[0].i); |
| 4342 | return 0; |
| 4343 | } |
| 4344 | |
| 4345 | wl_resource_set_implementation(resource, &xdg_implementation, |
Kristian Høgsberg | 2bff94e | 2014-02-11 12:22:51 -0800 | [diff] [blame] | 4346 | sc, NULL); |
Rafael Antognolli | e2a3455 | 2013-12-03 15:35:45 -0200 | [diff] [blame] | 4347 | |
| 4348 | return 1; |
| 4349 | } |
| 4350 | |
| 4351 | /* end of xdg-shell implementation */ |
| 4352 | /***********************************/ |
| 4353 | |
Kristian Høgsberg | 0793756 | 2011-04-12 17:25:42 -0400 | [diff] [blame] | 4354 | static void |
Ander Conselvan de Oliveira | 859e885 | 2013-02-21 18:35:21 +0200 | [diff] [blame] | 4355 | shell_fade(struct desktop_shell *shell, enum fade_type type); |
| 4356 | |
Pekka Paalanen | 77346a6 | 2011-11-30 16:26:35 +0200 | [diff] [blame] | 4357 | static void |
Jason Ekstrand | 918f2dd | 2013-12-02 21:01:53 -0600 | [diff] [blame] | 4358 | configure_static_view(struct weston_view *ev, struct weston_layer *layer) |
Kristian Høgsberg | 962342c | 2012-06-26 16:29:50 -0400 | [diff] [blame] | 4359 | { |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 4360 | struct weston_view *v, *next; |
Kristian Høgsberg | 962342c | 2012-06-26 16:29:50 -0400 | [diff] [blame] | 4361 | |
Giulio Camuffo | 412e6a5 | 2014-07-09 22:12:56 +0300 | [diff] [blame] | 4362 | 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] | 4363 | if (v->output == ev->output && v != ev) { |
| 4364 | weston_view_unmap(v); |
| 4365 | v->surface->configure = NULL; |
Pekka Paalanen | 8274d90 | 2014-08-06 19:36:51 +0300 | [diff] [blame] | 4366 | weston_surface_set_label_func(v->surface, NULL); |
Kristian Høgsberg | 962342c | 2012-06-26 16:29:50 -0400 | [diff] [blame] | 4367 | } |
| 4368 | } |
| 4369 | |
Jason Ekstrand | 918f2dd | 2013-12-02 21:01:53 -0600 | [diff] [blame] | 4370 | weston_view_set_position(ev, ev->output->x, ev->output->y); |
Armin Krezović | 4663aca | 2016-06-30 06:04:29 +0200 | [diff] [blame] | 4371 | ev->surface->is_mapped = true; |
| 4372 | ev->is_mapped = true; |
Kristian Høgsberg | 962342c | 2012-06-26 16:29:50 -0400 | [diff] [blame] | 4373 | |
Giulio Camuffo | 412e6a5 | 2014-07-09 22:12:56 +0300 | [diff] [blame] | 4374 | if (wl_list_empty(&ev->layer_link.link)) { |
| 4375 | weston_layer_entry_insert(&layer->view_list, &ev->layer_link); |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 4376 | weston_compositor_schedule_repaint(ev->surface->compositor); |
Kristian Høgsberg | 962342c | 2012-06-26 16:29:50 -0400 | [diff] [blame] | 4377 | } |
| 4378 | } |
| 4379 | |
David Fort | 50d962f | 2016-06-09 17:55:52 +0200 | [diff] [blame] | 4380 | |
| 4381 | static struct shell_output * |
| 4382 | find_shell_output_from_weston_output(struct desktop_shell *shell, struct weston_output *output) |
| 4383 | { |
| 4384 | struct shell_output *shell_output; |
| 4385 | |
| 4386 | wl_list_for_each(shell_output, &shell->output_list, link) { |
| 4387 | if (shell_output->output == output) |
| 4388 | return shell_output; |
| 4389 | } |
| 4390 | |
| 4391 | return NULL; |
| 4392 | } |
| 4393 | |
Pekka Paalanen | 8274d90 | 2014-08-06 19:36:51 +0300 | [diff] [blame] | 4394 | static int |
| 4395 | background_get_label(struct weston_surface *surface, char *buf, size_t len) |
| 4396 | { |
| 4397 | return snprintf(buf, len, "background for output %s", |
| 4398 | surface->output->name); |
| 4399 | } |
| 4400 | |
Kristian Høgsberg | 962342c | 2012-06-26 16:29:50 -0400 | [diff] [blame] | 4401 | static void |
Jason Ekstrand | 918f2dd | 2013-12-02 21:01:53 -0600 | [diff] [blame] | 4402 | 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] | 4403 | { |
Giulio Camuffo | 7fe01b1 | 2013-03-28 18:02:42 +0100 | [diff] [blame] | 4404 | struct desktop_shell *shell = es->configure_private; |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 4405 | struct weston_view *view; |
Kristian Høgsberg | af7b1ff | 2012-06-26 21:19:23 -0400 | [diff] [blame] | 4406 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 4407 | view = container_of(es->views.next, struct weston_view, surface_link); |
| 4408 | |
Jason Ekstrand | 918f2dd | 2013-12-02 21:01:53 -0600 | [diff] [blame] | 4409 | configure_static_view(view, &shell->background_layer); |
Kristian Høgsberg | af7b1ff | 2012-06-26 21:19:23 -0400 | [diff] [blame] | 4410 | } |
| 4411 | |
| 4412 | static void |
David Fort | 50d962f | 2016-06-09 17:55:52 +0200 | [diff] [blame] | 4413 | handle_background_surface_destroy(struct wl_listener *listener, void *data) |
| 4414 | { |
| 4415 | struct shell_output *output = |
| 4416 | container_of(listener, struct shell_output, background_surface_listener); |
| 4417 | |
| 4418 | weston_log("background surface gone\n"); |
| 4419 | output->background_surface = NULL; |
| 4420 | } |
| 4421 | |
| 4422 | static void |
Kristian Høgsberg | 7584062 | 2011-09-06 13:48:16 -0400 | [diff] [blame] | 4423 | desktop_shell_set_background(struct wl_client *client, |
| 4424 | struct wl_resource *resource, |
Benjamin Franzke | d0f79ab | 2011-11-22 12:43:52 +0100 | [diff] [blame] | 4425 | struct wl_resource *output_resource, |
Kristian Høgsberg | 7584062 | 2011-09-06 13:48:16 -0400 | [diff] [blame] | 4426 | struct wl_resource *surface_resource) |
| 4427 | { |
Jason Ekstrand | 651f00e | 2013-06-14 10:07:54 -0500 | [diff] [blame] | 4428 | struct desktop_shell *shell = wl_resource_get_user_data(resource); |
Jason Ekstrand | 0f2ef7e | 2013-06-14 10:07:53 -0500 | [diff] [blame] | 4429 | struct weston_surface *surface = |
| 4430 | wl_resource_get_user_data(surface_resource); |
David Fort | 50d962f | 2016-06-09 17:55:52 +0200 | [diff] [blame] | 4431 | struct shell_output *sh_output; |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 4432 | struct weston_view *view, *next; |
Kristian Høgsberg | 7584062 | 2011-09-06 13:48:16 -0400 | [diff] [blame] | 4433 | |
Kristian Høgsberg | 962342c | 2012-06-26 16:29:50 -0400 | [diff] [blame] | 4434 | if (surface->configure) { |
| 4435 | wl_resource_post_error(surface_resource, |
| 4436 | WL_DISPLAY_ERROR_INVALID_OBJECT, |
| 4437 | "surface role already assigned"); |
| 4438 | return; |
| 4439 | } |
Benjamin Franzke | d0f79ab | 2011-11-22 12:43:52 +0100 | [diff] [blame] | 4440 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 4441 | wl_list_for_each_safe(view, next, &surface->views, surface_link) |
| 4442 | weston_view_destroy(view); |
| 4443 | view = weston_view_create(surface); |
| 4444 | |
Kristian Høgsberg | 962342c | 2012-06-26 16:29:50 -0400 | [diff] [blame] | 4445 | surface->configure = background_configure; |
Giulio Camuffo | 7fe01b1 | 2013-03-28 18:02:42 +0100 | [diff] [blame] | 4446 | surface->configure_private = shell; |
Pekka Paalanen | 8274d90 | 2014-08-06 19:36:51 +0300 | [diff] [blame] | 4447 | weston_surface_set_label_func(surface, background_get_label); |
Jason Ekstrand | a0d2dde | 2013-06-14 10:08:01 -0500 | [diff] [blame] | 4448 | surface->output = wl_resource_get_user_data(output_resource); |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 4449 | view->output = surface->output; |
Jonas Ådahl | 6d6fb61 | 2015-11-17 16:00:33 +0800 | [diff] [blame] | 4450 | weston_desktop_shell_send_configure(resource, 0, |
| 4451 | surface_resource, |
| 4452 | surface->output->width, |
| 4453 | surface->output->height); |
David Fort | 50d962f | 2016-06-09 17:55:52 +0200 | [diff] [blame] | 4454 | |
| 4455 | sh_output = find_shell_output_from_weston_output(shell, surface->output); |
| 4456 | sh_output->background_surface = surface; |
| 4457 | |
| 4458 | sh_output->background_surface_listener.notify = handle_background_surface_destroy; |
| 4459 | wl_signal_add(&surface->destroy_signal, &sh_output->background_surface_listener); |
Kristian Høgsberg | 7584062 | 2011-09-06 13:48:16 -0400 | [diff] [blame] | 4460 | } |
| 4461 | |
Pekka Paalanen | 8274d90 | 2014-08-06 19:36:51 +0300 | [diff] [blame] | 4462 | static int |
| 4463 | panel_get_label(struct weston_surface *surface, char *buf, size_t len) |
| 4464 | { |
| 4465 | return snprintf(buf, len, "panel for output %s", |
| 4466 | surface->output->name); |
| 4467 | } |
| 4468 | |
Kristian Høgsberg | 7584062 | 2011-09-06 13:48:16 -0400 | [diff] [blame] | 4469 | static void |
Jason Ekstrand | 918f2dd | 2013-12-02 21:01:53 -0600 | [diff] [blame] | 4470 | 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] | 4471 | { |
Giulio Camuffo | 7fe01b1 | 2013-03-28 18:02:42 +0100 | [diff] [blame] | 4472 | struct desktop_shell *shell = es->configure_private; |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 4473 | struct weston_view *view; |
Kristian Høgsberg | af7b1ff | 2012-06-26 21:19:23 -0400 | [diff] [blame] | 4474 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 4475 | view = container_of(es->views.next, struct weston_view, surface_link); |
| 4476 | |
Jason Ekstrand | 918f2dd | 2013-12-02 21:01:53 -0600 | [diff] [blame] | 4477 | configure_static_view(view, &shell->panel_layer); |
Kristian Høgsberg | af7b1ff | 2012-06-26 21:19:23 -0400 | [diff] [blame] | 4478 | } |
| 4479 | |
| 4480 | static void |
David Fort | 50d962f | 2016-06-09 17:55:52 +0200 | [diff] [blame] | 4481 | handle_panel_surface_destroy(struct wl_listener *listener, void *data) |
| 4482 | { |
| 4483 | struct shell_output *output = |
| 4484 | container_of(listener, struct shell_output, panel_surface_listener); |
| 4485 | |
| 4486 | weston_log("panel surface gone\n"); |
| 4487 | output->panel_surface = NULL; |
| 4488 | } |
| 4489 | |
| 4490 | |
| 4491 | static void |
Kristian Høgsberg | 7584062 | 2011-09-06 13:48:16 -0400 | [diff] [blame] | 4492 | desktop_shell_set_panel(struct wl_client *client, |
| 4493 | struct wl_resource *resource, |
Benjamin Franzke | d0f79ab | 2011-11-22 12:43:52 +0100 | [diff] [blame] | 4494 | struct wl_resource *output_resource, |
Kristian Høgsberg | 7584062 | 2011-09-06 13:48:16 -0400 | [diff] [blame] | 4495 | struct wl_resource *surface_resource) |
| 4496 | { |
Jason Ekstrand | 651f00e | 2013-06-14 10:07:54 -0500 | [diff] [blame] | 4497 | struct desktop_shell *shell = wl_resource_get_user_data(resource); |
Jason Ekstrand | 0f2ef7e | 2013-06-14 10:07:53 -0500 | [diff] [blame] | 4498 | struct weston_surface *surface = |
| 4499 | wl_resource_get_user_data(surface_resource); |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 4500 | struct weston_view *view, *next; |
David Fort | 50d962f | 2016-06-09 17:55:52 +0200 | [diff] [blame] | 4501 | struct shell_output *sh_output; |
Kristian Høgsberg | 7584062 | 2011-09-06 13:48:16 -0400 | [diff] [blame] | 4502 | |
Kristian Høgsberg | af7b1ff | 2012-06-26 21:19:23 -0400 | [diff] [blame] | 4503 | if (surface->configure) { |
| 4504 | wl_resource_post_error(surface_resource, |
| 4505 | WL_DISPLAY_ERROR_INVALID_OBJECT, |
| 4506 | "surface role already assigned"); |
| 4507 | return; |
| 4508 | } |
Benjamin Franzke | d0f79ab | 2011-11-22 12:43:52 +0100 | [diff] [blame] | 4509 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 4510 | wl_list_for_each_safe(view, next, &surface->views, surface_link) |
| 4511 | weston_view_destroy(view); |
| 4512 | view = weston_view_create(surface); |
| 4513 | |
Kristian Høgsberg | af7b1ff | 2012-06-26 21:19:23 -0400 | [diff] [blame] | 4514 | surface->configure = panel_configure; |
Giulio Camuffo | 7fe01b1 | 2013-03-28 18:02:42 +0100 | [diff] [blame] | 4515 | surface->configure_private = shell; |
Pekka Paalanen | 8274d90 | 2014-08-06 19:36:51 +0300 | [diff] [blame] | 4516 | weston_surface_set_label_func(surface, panel_get_label); |
Jason Ekstrand | a0d2dde | 2013-06-14 10:08:01 -0500 | [diff] [blame] | 4517 | surface->output = wl_resource_get_user_data(output_resource); |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 4518 | view->output = surface->output; |
Jonas Ådahl | 6d6fb61 | 2015-11-17 16:00:33 +0800 | [diff] [blame] | 4519 | weston_desktop_shell_send_configure(resource, 0, |
| 4520 | surface_resource, |
| 4521 | surface->output->width, |
| 4522 | surface->output->height); |
David Fort | 50d962f | 2016-06-09 17:55:52 +0200 | [diff] [blame] | 4523 | |
| 4524 | sh_output = find_shell_output_from_weston_output(shell, surface->output); |
| 4525 | sh_output->panel_surface = surface; |
| 4526 | |
| 4527 | sh_output->panel_surface_listener.notify = handle_panel_surface_destroy; |
| 4528 | wl_signal_add(&surface->destroy_signal, &sh_output->panel_surface_listener); |
Kristian Høgsberg | 7584062 | 2011-09-06 13:48:16 -0400 | [diff] [blame] | 4529 | } |
| 4530 | |
Pekka Paalanen | 8274d90 | 2014-08-06 19:36:51 +0300 | [diff] [blame] | 4531 | static int |
| 4532 | lock_surface_get_label(struct weston_surface *surface, char *buf, size_t len) |
| 4533 | { |
| 4534 | return snprintf(buf, len, "lock window"); |
| 4535 | } |
| 4536 | |
Pekka Paalanen | 9ef3e01 | 2011-11-15 13:34:48 +0200 | [diff] [blame] | 4537 | static void |
Jason Ekstrand | 918f2dd | 2013-12-02 21:01:53 -0600 | [diff] [blame] | 4538 | 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] | 4539 | { |
Giulio Camuffo | 7fe01b1 | 2013-03-28 18:02:42 +0100 | [diff] [blame] | 4540 | struct desktop_shell *shell = surface->configure_private; |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 4541 | struct weston_view *view; |
| 4542 | |
| 4543 | view = container_of(surface->views.next, struct weston_view, surface_link); |
Kristian Høgsberg | 730c94d | 2012-06-26 21:44:35 -0400 | [diff] [blame] | 4544 | |
Jason Ekstrand | 918f2dd | 2013-12-02 21:01:53 -0600 | [diff] [blame] | 4545 | if (surface->width == 0) |
Giulio Camuffo | 184df50 | 2013-02-21 11:29:21 +0100 | [diff] [blame] | 4546 | return; |
| 4547 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 4548 | center_on_output(view, get_default_output(shell->compositor)); |
Kristian Høgsberg | 730c94d | 2012-06-26 21:44:35 -0400 | [diff] [blame] | 4549 | |
| 4550 | if (!weston_surface_is_mapped(surface)) { |
Giulio Camuffo | 412e6a5 | 2014-07-09 22:12:56 +0300 | [diff] [blame] | 4551 | weston_layer_entry_insert(&shell->lock_layer.view_list, |
| 4552 | &view->layer_link); |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 4553 | weston_view_update_transform(view); |
Armin Krezović | 4663aca | 2016-06-30 06:04:29 +0200 | [diff] [blame] | 4554 | surface->is_mapped = true; |
| 4555 | view->is_mapped = true; |
Ander Conselvan de Oliveira | 87524b6 | 2013-02-21 18:35:22 +0200 | [diff] [blame] | 4556 | shell_fade(shell, FADE_IN); |
Kristian Høgsberg | 730c94d | 2012-06-26 21:44:35 -0400 | [diff] [blame] | 4557 | } |
| 4558 | } |
| 4559 | |
| 4560 | static void |
Kristian Høgsberg | 27e3052 | 2012-04-11 23:18:23 -0400 | [diff] [blame] | 4561 | handle_lock_surface_destroy(struct wl_listener *listener, void *data) |
Kristian Høgsberg | 1ec0c31 | 2011-11-15 16:39:55 -0500 | [diff] [blame] | 4562 | { |
Tiago Vignatti | be14326 | 2012-04-16 17:31:41 +0300 | [diff] [blame] | 4563 | struct desktop_shell *shell = |
| 4564 | container_of(listener, struct desktop_shell, lock_surface_listener); |
Kristian Høgsberg | 1ec0c31 | 2011-11-15 16:39:55 -0500 | [diff] [blame] | 4565 | |
Martin Minarik | 6d11836 | 2012-06-07 18:01:59 +0200 | [diff] [blame] | 4566 | weston_log("lock surface gone\n"); |
Kristian Høgsberg | 1ec0c31 | 2011-11-15 16:39:55 -0500 | [diff] [blame] | 4567 | shell->lock_surface = NULL; |
| 4568 | } |
| 4569 | |
| 4570 | static void |
Pekka Paalanen | 9ef3e01 | 2011-11-15 13:34:48 +0200 | [diff] [blame] | 4571 | desktop_shell_set_lock_surface(struct wl_client *client, |
| 4572 | struct wl_resource *resource, |
| 4573 | struct wl_resource *surface_resource) |
| 4574 | { |
Jason Ekstrand | 651f00e | 2013-06-14 10:07:54 -0500 | [diff] [blame] | 4575 | struct desktop_shell *shell = wl_resource_get_user_data(resource); |
Jason Ekstrand | 0f2ef7e | 2013-06-14 10:07:53 -0500 | [diff] [blame] | 4576 | struct weston_surface *surface = |
| 4577 | wl_resource_get_user_data(surface_resource); |
Pekka Paalanen | 9826223 | 2011-12-01 10:42:22 +0200 | [diff] [blame] | 4578 | |
Pekka Paalanen | f0fc70d | 2011-11-15 13:34:54 +0200 | [diff] [blame] | 4579 | shell->prepare_event_sent = false; |
Kristian Høgsberg | af867cc | 2011-11-15 13:34:49 +0200 | [diff] [blame] | 4580 | |
Pekka Paalanen | f0fc70d | 2011-11-15 13:34:54 +0200 | [diff] [blame] | 4581 | if (!shell->locked) |
| 4582 | return; |
| 4583 | |
Pekka Paalanen | 9826223 | 2011-12-01 10:42:22 +0200 | [diff] [blame] | 4584 | shell->lock_surface = surface; |
Pekka Paalanen | f0fc70d | 2011-11-15 13:34:54 +0200 | [diff] [blame] | 4585 | |
Kristian Høgsberg | 27e3052 | 2012-04-11 23:18:23 -0400 | [diff] [blame] | 4586 | shell->lock_surface_listener.notify = handle_lock_surface_destroy; |
Jason Ekstrand | 651f00e | 2013-06-14 10:07:54 -0500 | [diff] [blame] | 4587 | wl_signal_add(&surface->destroy_signal, |
Kristian Høgsberg | 27e3052 | 2012-04-11 23:18:23 -0400 | [diff] [blame] | 4588 | &shell->lock_surface_listener); |
Pekka Paalanen | 57da4a8 | 2011-11-23 16:42:16 +0200 | [diff] [blame] | 4589 | |
Kristian Høgsberg | aa2ee8b | 2013-10-30 15:49:45 -0700 | [diff] [blame] | 4590 | weston_view_create(surface); |
Kristian Høgsberg | 730c94d | 2012-06-26 21:44:35 -0400 | [diff] [blame] | 4591 | surface->configure = lock_surface_configure; |
Giulio Camuffo | 7fe01b1 | 2013-03-28 18:02:42 +0100 | [diff] [blame] | 4592 | surface->configure_private = shell; |
Pekka Paalanen | 8274d90 | 2014-08-06 19:36:51 +0300 | [diff] [blame] | 4593 | weston_surface_set_label_func(surface, lock_surface_get_label); |
Pekka Paalanen | f0fc70d | 2011-11-15 13:34:54 +0200 | [diff] [blame] | 4594 | } |
| 4595 | |
| 4596 | static void |
Tiago Vignatti | be14326 | 2012-04-16 17:31:41 +0300 | [diff] [blame] | 4597 | resume_desktop(struct desktop_shell *shell) |
Pekka Paalanen | f0fc70d | 2011-11-15 13:34:54 +0200 | [diff] [blame] | 4598 | { |
Kristian Høgsberg | 4476aaf | 2012-06-25 14:03:13 -0400 | [diff] [blame] | 4599 | struct workspace *ws = get_current_workspace(shell); |
Pekka Paalanen | 77346a6 | 2011-11-30 16:26:35 +0200 | [diff] [blame] | 4600 | |
Kristian Høgsberg | 3be2ce9 | 2012-02-29 12:42:35 -0500 | [diff] [blame] | 4601 | wl_list_remove(&shell->lock_layer.link); |
Philipp Brüschweiler | 711fda8 | 2012-08-09 18:50:43 +0200 | [diff] [blame] | 4602 | if (shell->showing_input_panels) { |
Manuel Bachmann | 805d2f5 | 2014-03-05 12:21:34 +0100 | [diff] [blame] | 4603 | wl_list_insert(&shell->compositor->cursor_layer.link, |
Philipp Brüschweiler | 711fda8 | 2012-08-09 18:50:43 +0200 | [diff] [blame] | 4604 | &shell->input_panel_layer.link); |
| 4605 | wl_list_insert(&shell->input_panel_layer.link, |
Manuel Bachmann | 805d2f5 | 2014-03-05 12:21:34 +0100 | [diff] [blame] | 4606 | &shell->fullscreen_layer.link); |
Philipp Brüschweiler | 711fda8 | 2012-08-09 18:50:43 +0200 | [diff] [blame] | 4607 | } else { |
Manuel Bachmann | 805d2f5 | 2014-03-05 12:21:34 +0100 | [diff] [blame] | 4608 | wl_list_insert(&shell->compositor->cursor_layer.link, |
| 4609 | &shell->fullscreen_layer.link); |
Philipp Brüschweiler | 711fda8 | 2012-08-09 18:50:43 +0200 | [diff] [blame] | 4610 | } |
Manuel Bachmann | 805d2f5 | 2014-03-05 12:21:34 +0100 | [diff] [blame] | 4611 | wl_list_insert(&shell->fullscreen_layer.link, |
| 4612 | &shell->panel_layer.link); |
| 4613 | wl_list_insert(&shell->panel_layer.link, |
| 4614 | &ws->layer.link), |
Pekka Paalanen | f0fc70d | 2011-11-15 13:34:54 +0200 | [diff] [blame] | 4615 | |
Kristian Høgsberg | 2f5faff | 2012-07-31 16:36:34 -0400 | [diff] [blame] | 4616 | restore_focus_state(shell, get_current_workspace(shell)); |
Jonas Ådahl | 0476974 | 2012-06-13 00:01:24 +0200 | [diff] [blame] | 4617 | |
Pekka Paalanen | f0fc70d | 2011-11-15 13:34:54 +0200 | [diff] [blame] | 4618 | shell->locked = false; |
Ander Conselvan de Oliveira | 87524b6 | 2013-02-21 18:35:22 +0200 | [diff] [blame] | 4619 | shell_fade(shell, FADE_IN); |
Pekka Paalanen | fc6d91a | 2012-02-10 15:33:10 +0200 | [diff] [blame] | 4620 | weston_compositor_damage_all(shell->compositor); |
Pekka Paalanen | 9ef3e01 | 2011-11-15 13:34:48 +0200 | [diff] [blame] | 4621 | } |
| 4622 | |
| 4623 | static void |
| 4624 | desktop_shell_unlock(struct wl_client *client, |
| 4625 | struct wl_resource *resource) |
| 4626 | { |
Jason Ekstrand | 651f00e | 2013-06-14 10:07:54 -0500 | [diff] [blame] | 4627 | struct desktop_shell *shell = wl_resource_get_user_data(resource); |
Pekka Paalanen | 9ef3e01 | 2011-11-15 13:34:48 +0200 | [diff] [blame] | 4628 | |
Pekka Paalanen | 9ef3e01 | 2011-11-15 13:34:48 +0200 | [diff] [blame] | 4629 | shell->prepare_event_sent = false; |
Pekka Paalanen | f0fc70d | 2011-11-15 13:34:54 +0200 | [diff] [blame] | 4630 | |
| 4631 | if (shell->locked) |
| 4632 | resume_desktop(shell); |
Pekka Paalanen | 9ef3e01 | 2011-11-15 13:34:48 +0200 | [diff] [blame] | 4633 | } |
| 4634 | |
Kristian Høgsberg | d56bd90 | 2012-06-05 09:58:51 -0400 | [diff] [blame] | 4635 | static void |
Ander Conselvan de Oliveira | b9d2a0f | 2012-06-28 18:08:05 +0300 | [diff] [blame] | 4636 | desktop_shell_set_grab_surface(struct wl_client *client, |
Kristian Høgsberg | d56bd90 | 2012-06-05 09:58:51 -0400 | [diff] [blame] | 4637 | struct wl_resource *resource, |
| 4638 | struct wl_resource *surface_resource) |
| 4639 | { |
Jason Ekstrand | 651f00e | 2013-06-14 10:07:54 -0500 | [diff] [blame] | 4640 | struct desktop_shell *shell = wl_resource_get_user_data(resource); |
Kristian Høgsberg | d56bd90 | 2012-06-05 09:58:51 -0400 | [diff] [blame] | 4641 | |
Jason Ekstrand | 0f2ef7e | 2013-06-14 10:07:53 -0500 | [diff] [blame] | 4642 | shell->grab_surface = wl_resource_get_user_data(surface_resource); |
Kristian Høgsberg | 48588f8 | 2013-10-24 15:51:35 -0700 | [diff] [blame] | 4643 | weston_view_create(shell->grab_surface); |
Kristian Høgsberg | d56bd90 | 2012-06-05 09:58:51 -0400 | [diff] [blame] | 4644 | } |
| 4645 | |
Pekka Paalanen | 79346ab | 2013-05-22 18:03:09 +0300 | [diff] [blame] | 4646 | static void |
| 4647 | desktop_shell_desktop_ready(struct wl_client *client, |
| 4648 | struct wl_resource *resource) |
| 4649 | { |
Jason Ekstrand | 651f00e | 2013-06-14 10:07:54 -0500 | [diff] [blame] | 4650 | struct desktop_shell *shell = wl_resource_get_user_data(resource); |
Pekka Paalanen | 79346ab | 2013-05-22 18:03:09 +0300 | [diff] [blame] | 4651 | |
| 4652 | shell_fade_startup(shell); |
| 4653 | } |
| 4654 | |
Jonny Lamb | 765760d | 2014-08-20 15:53:19 +0200 | [diff] [blame] | 4655 | static void |
| 4656 | desktop_shell_set_panel_position(struct wl_client *client, |
| 4657 | struct wl_resource *resource, |
| 4658 | uint32_t position) |
| 4659 | { |
| 4660 | struct desktop_shell *shell = wl_resource_get_user_data(resource); |
| 4661 | |
Jonas Ådahl | 6d6fb61 | 2015-11-17 16:00:33 +0800 | [diff] [blame] | 4662 | if (position != WESTON_DESKTOP_SHELL_PANEL_POSITION_TOP && |
| 4663 | position != WESTON_DESKTOP_SHELL_PANEL_POSITION_BOTTOM && |
| 4664 | position != WESTON_DESKTOP_SHELL_PANEL_POSITION_LEFT && |
| 4665 | position != WESTON_DESKTOP_SHELL_PANEL_POSITION_RIGHT) { |
Jonny Lamb | 765760d | 2014-08-20 15:53:19 +0200 | [diff] [blame] | 4666 | wl_resource_post_error(resource, |
Jonas Ådahl | 6d6fb61 | 2015-11-17 16:00:33 +0800 | [diff] [blame] | 4667 | WESTON_DESKTOP_SHELL_ERROR_INVALID_ARGUMENT, |
Jonny Lamb | 765760d | 2014-08-20 15:53:19 +0200 | [diff] [blame] | 4668 | "bad position argument"); |
| 4669 | return; |
| 4670 | } |
| 4671 | |
| 4672 | shell->panel_position = position; |
| 4673 | } |
| 4674 | |
Jonas Ådahl | 6d6fb61 | 2015-11-17 16:00:33 +0800 | [diff] [blame] | 4675 | static const struct weston_desktop_shell_interface desktop_shell_implementation = { |
Kristian Høgsberg | 7584062 | 2011-09-06 13:48:16 -0400 | [diff] [blame] | 4676 | desktop_shell_set_background, |
Pekka Paalanen | 9ef3e01 | 2011-11-15 13:34:48 +0200 | [diff] [blame] | 4677 | desktop_shell_set_panel, |
| 4678 | desktop_shell_set_lock_surface, |
Kristian Høgsberg | d56bd90 | 2012-06-05 09:58:51 -0400 | [diff] [blame] | 4679 | desktop_shell_unlock, |
Pekka Paalanen | 79346ab | 2013-05-22 18:03:09 +0300 | [diff] [blame] | 4680 | desktop_shell_set_grab_surface, |
Jonny Lamb | 765760d | 2014-08-20 15:53:19 +0200 | [diff] [blame] | 4681 | desktop_shell_desktop_ready, |
| 4682 | desktop_shell_set_panel_position |
Kristian Høgsberg | 7584062 | 2011-09-06 13:48:16 -0400 | [diff] [blame] | 4683 | }; |
| 4684 | |
Pekka Paalanen | 92a0dc4 | 2011-11-28 15:34:13 +0200 | [diff] [blame] | 4685 | static enum shell_surface_type |
Kristian Høgsberg | 8334bc1 | 2012-01-03 10:29:47 -0500 | [diff] [blame] | 4686 | get_shell_surface_type(struct weston_surface *surface) |
Pekka Paalanen | 92a0dc4 | 2011-11-28 15:34:13 +0200 | [diff] [blame] | 4687 | { |
| 4688 | struct shell_surface *shsurf; |
| 4689 | |
| 4690 | shsurf = get_shell_surface(surface); |
| 4691 | if (!shsurf) |
Pekka Paalanen | 9826223 | 2011-12-01 10:42:22 +0200 | [diff] [blame] | 4692 | return SHELL_SURFACE_NONE; |
Pekka Paalanen | 92a0dc4 | 2011-11-28 15:34:13 +0200 | [diff] [blame] | 4693 | return shsurf->type; |
| 4694 | } |
| 4695 | |
Kristian Høgsberg | 7584062 | 2011-09-06 13:48:16 -0400 | [diff] [blame] | 4696 | static void |
Derek Foreman | 8ae2db5 | 2015-07-15 13:00:36 -0500 | [diff] [blame] | 4697 | move_binding(struct weston_pointer *pointer, uint32_t time, |
| 4698 | uint32_t button, void *data) |
Kristian Høgsberg | 0793756 | 2011-04-12 17:25:42 -0400 | [diff] [blame] | 4699 | { |
Rafal Mielniczuk | b2917a2 | 2014-01-05 20:04:59 +0100 | [diff] [blame] | 4700 | struct weston_surface *focus; |
Pekka Paalanen | 01388e2 | 2013-04-25 13:57:44 +0300 | [diff] [blame] | 4701 | struct weston_surface *surface; |
Kristian Høgsberg | 938b8fa | 2012-05-18 13:46:27 -0400 | [diff] [blame] | 4702 | struct shell_surface *shsurf; |
Kristian Høgsberg | d2abb83 | 2011-11-23 10:52:40 -0500 | [diff] [blame] | 4703 | |
Derek Foreman | 8ae2db5 | 2015-07-15 13:00:36 -0500 | [diff] [blame] | 4704 | if (pointer->focus == NULL) |
Rafal Mielniczuk | b2917a2 | 2014-01-05 20:04:59 +0100 | [diff] [blame] | 4705 | return; |
| 4706 | |
Derek Foreman | 8ae2db5 | 2015-07-15 13:00:36 -0500 | [diff] [blame] | 4707 | focus = pointer->focus->surface; |
Rafal Mielniczuk | b2917a2 | 2014-01-05 20:04:59 +0100 | [diff] [blame] | 4708 | |
Pekka Paalanen | 01388e2 | 2013-04-25 13:57:44 +0300 | [diff] [blame] | 4709 | surface = weston_surface_get_main_surface(focus); |
Benjamin Franzke | d0f79ab | 2011-11-22 12:43:52 +0100 | [diff] [blame] | 4710 | if (surface == NULL) |
| 4711 | return; |
Kristian Høgsberg | 0793756 | 2011-04-12 17:25:42 -0400 | [diff] [blame] | 4712 | |
Kristian Høgsberg | 938b8fa | 2012-05-18 13:46:27 -0400 | [diff] [blame] | 4713 | shsurf = get_shell_surface(surface); |
Rafael Antognolli | 03b1659 | 2013-12-03 15:35:42 -0200 | [diff] [blame] | 4714 | if (shsurf == NULL || shsurf->state.fullscreen || |
| 4715 | shsurf->state.maximized) |
Kristian Høgsberg | 938b8fa | 2012-05-18 13:46:27 -0400 | [diff] [blame] | 4716 | return; |
| 4717 | |
Derek Foreman | 794fa0e | 2015-07-15 13:00:38 -0500 | [diff] [blame] | 4718 | surface_move(shsurf, pointer, false); |
Kristian Høgsberg | 0793756 | 2011-04-12 17:25:42 -0400 | [diff] [blame] | 4719 | } |
| 4720 | |
| 4721 | static void |
Derek Foreman | 8ae2db5 | 2015-07-15 13:00:36 -0500 | [diff] [blame] | 4722 | maximize_binding(struct weston_keyboard *keyboard, uint32_t time, |
| 4723 | uint32_t button, void *data) |
Rafael Antognolli | ea997ac | 2013-12-03 15:35:48 -0200 | [diff] [blame] | 4724 | { |
Derek Foreman | 8ae2db5 | 2015-07-15 13:00:36 -0500 | [diff] [blame] | 4725 | struct weston_surface *focus = keyboard->focus; |
Rafael Antognolli | ea997ac | 2013-12-03 15:35:48 -0200 | [diff] [blame] | 4726 | struct weston_surface *surface; |
| 4727 | struct shell_surface *shsurf; |
| 4728 | |
| 4729 | surface = weston_surface_get_main_surface(focus); |
| 4730 | if (surface == NULL) |
| 4731 | return; |
| 4732 | |
| 4733 | shsurf = get_shell_surface(surface); |
| 4734 | if (shsurf == NULL) |
| 4735 | return; |
| 4736 | |
| 4737 | if (!shell_surface_is_xdg_surface(shsurf)) |
| 4738 | return; |
| 4739 | |
Jasper St. Pierre | ab2c108 | 2014-04-10 10:41:46 -0700 | [diff] [blame] | 4740 | shsurf->state_requested = true; |
| 4741 | shsurf->requested_state.maximized = !shsurf->state.maximized; |
Jasper St. Pierre | 9aa8ce6 | 2014-04-11 16:18:54 -0700 | [diff] [blame] | 4742 | send_configure_for_surface(shsurf); |
Rafael Antognolli | ea997ac | 2013-12-03 15:35:48 -0200 | [diff] [blame] | 4743 | } |
| 4744 | |
| 4745 | static void |
Derek Foreman | 8ae2db5 | 2015-07-15 13:00:36 -0500 | [diff] [blame] | 4746 | fullscreen_binding(struct weston_keyboard *keyboard, uint32_t time, |
| 4747 | uint32_t button, void *data) |
Rafael Antognolli | ea997ac | 2013-12-03 15:35:48 -0200 | [diff] [blame] | 4748 | { |
Derek Foreman | 8ae2db5 | 2015-07-15 13:00:36 -0500 | [diff] [blame] | 4749 | struct weston_surface *focus = keyboard->focus; |
Rafael Antognolli | ea997ac | 2013-12-03 15:35:48 -0200 | [diff] [blame] | 4750 | struct weston_surface *surface; |
| 4751 | struct shell_surface *shsurf; |
| 4752 | |
| 4753 | surface = weston_surface_get_main_surface(focus); |
| 4754 | if (surface == NULL) |
| 4755 | return; |
| 4756 | |
| 4757 | shsurf = get_shell_surface(surface); |
| 4758 | if (shsurf == NULL) |
| 4759 | return; |
| 4760 | |
| 4761 | if (!shell_surface_is_xdg_surface(shsurf)) |
| 4762 | return; |
| 4763 | |
Jasper St. Pierre | ab2c108 | 2014-04-10 10:41:46 -0700 | [diff] [blame] | 4764 | shsurf->state_requested = true; |
| 4765 | shsurf->requested_state.fullscreen = !shsurf->state.fullscreen; |
Boyan Ding | 32abdbb | 2014-06-26 10:19:32 +0800 | [diff] [blame] | 4766 | shsurf->fullscreen_output = shsurf->output; |
Jasper St. Pierre | 9aa8ce6 | 2014-04-11 16:18:54 -0700 | [diff] [blame] | 4767 | send_configure_for_surface(shsurf); |
Rafael Antognolli | ea997ac | 2013-12-03 15:35:48 -0200 | [diff] [blame] | 4768 | } |
| 4769 | |
| 4770 | static void |
Derek Foreman | 8ae2db5 | 2015-07-15 13:00:36 -0500 | [diff] [blame] | 4771 | touch_move_binding(struct weston_touch *touch, uint32_t time, void *data) |
Neil Roberts | aba0f25 | 2013-10-03 16:43:05 +0100 | [diff] [blame] | 4772 | { |
Derek Foreman | 362656b | 2014-09-04 10:23:05 -0500 | [diff] [blame] | 4773 | struct weston_surface *focus; |
Neil Roberts | aba0f25 | 2013-10-03 16:43:05 +0100 | [diff] [blame] | 4774 | struct weston_surface *surface; |
| 4775 | struct shell_surface *shsurf; |
| 4776 | |
Derek Foreman | 8ae2db5 | 2015-07-15 13:00:36 -0500 | [diff] [blame] | 4777 | if (touch->focus == NULL) |
Derek Foreman | 362656b | 2014-09-04 10:23:05 -0500 | [diff] [blame] | 4778 | return; |
| 4779 | |
Derek Foreman | 8ae2db5 | 2015-07-15 13:00:36 -0500 | [diff] [blame] | 4780 | focus = touch->focus->surface; |
Neil Roberts | aba0f25 | 2013-10-03 16:43:05 +0100 | [diff] [blame] | 4781 | surface = weston_surface_get_main_surface(focus); |
| 4782 | if (surface == NULL) |
| 4783 | return; |
| 4784 | |
| 4785 | shsurf = get_shell_surface(surface); |
Rafael Antognolli | 03b1659 | 2013-12-03 15:35:42 -0200 | [diff] [blame] | 4786 | if (shsurf == NULL || shsurf->state.fullscreen || |
| 4787 | shsurf->state.maximized) |
Neil Roberts | aba0f25 | 2013-10-03 16:43:05 +0100 | [diff] [blame] | 4788 | return; |
| 4789 | |
Derek Foreman | b7674ae | 2015-07-15 13:00:37 -0500 | [diff] [blame] | 4790 | surface_touch_move(shsurf, touch); |
Neil Roberts | aba0f25 | 2013-10-03 16:43:05 +0100 | [diff] [blame] | 4791 | } |
| 4792 | |
| 4793 | static void |
Derek Foreman | 8ae2db5 | 2015-07-15 13:00:36 -0500 | [diff] [blame] | 4794 | resize_binding(struct weston_pointer *pointer, uint32_t time, |
| 4795 | uint32_t button, void *data) |
Kristian Høgsberg | 0793756 | 2011-04-12 17:25:42 -0400 | [diff] [blame] | 4796 | { |
Rafal Mielniczuk | b2917a2 | 2014-01-05 20:04:59 +0100 | [diff] [blame] | 4797 | struct weston_surface *focus; |
Pekka Paalanen | 01388e2 | 2013-04-25 13:57:44 +0300 | [diff] [blame] | 4798 | struct weston_surface *surface; |
Kristian Høgsberg | 0793756 | 2011-04-12 17:25:42 -0400 | [diff] [blame] | 4799 | uint32_t edges = 0; |
| 4800 | int32_t x, y; |
Pekka Paalanen | 9d1613e | 2011-11-25 12:09:16 +0200 | [diff] [blame] | 4801 | struct shell_surface *shsurf; |
Kristian Høgsberg | d2abb83 | 2011-11-23 10:52:40 -0500 | [diff] [blame] | 4802 | |
Derek Foreman | 8ae2db5 | 2015-07-15 13:00:36 -0500 | [diff] [blame] | 4803 | if (pointer->focus == NULL) |
Rafal Mielniczuk | b2917a2 | 2014-01-05 20:04:59 +0100 | [diff] [blame] | 4804 | return; |
| 4805 | |
Derek Foreman | 8ae2db5 | 2015-07-15 13:00:36 -0500 | [diff] [blame] | 4806 | focus = pointer->focus->surface; |
Rafal Mielniczuk | b2917a2 | 2014-01-05 20:04:59 +0100 | [diff] [blame] | 4807 | |
Pekka Paalanen | 01388e2 | 2013-04-25 13:57:44 +0300 | [diff] [blame] | 4808 | surface = weston_surface_get_main_surface(focus); |
Benjamin Franzke | d0f79ab | 2011-11-22 12:43:52 +0100 | [diff] [blame] | 4809 | if (surface == NULL) |
| 4810 | return; |
Pekka Paalanen | 92a0dc4 | 2011-11-28 15:34:13 +0200 | [diff] [blame] | 4811 | |
Pekka Paalanen | 9d1613e | 2011-11-25 12:09:16 +0200 | [diff] [blame] | 4812 | shsurf = get_shell_surface(surface); |
Rafael Antognolli | 03b1659 | 2013-12-03 15:35:42 -0200 | [diff] [blame] | 4813 | if (shsurf == NULL || shsurf->state.fullscreen || |
| 4814 | shsurf->state.maximized) |
Pekka Paalanen | 92a0dc4 | 2011-11-28 15:34:13 +0200 | [diff] [blame] | 4815 | return; |
| 4816 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 4817 | weston_view_from_global(shsurf->view, |
Derek Foreman | 8ae2db5 | 2015-07-15 13:00:36 -0500 | [diff] [blame] | 4818 | wl_fixed_to_int(pointer->grab_x), |
| 4819 | wl_fixed_to_int(pointer->grab_y), |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 4820 | &x, &y); |
Kristian Høgsberg | 0793756 | 2011-04-12 17:25:42 -0400 | [diff] [blame] | 4821 | |
Jason Ekstrand | 918f2dd | 2013-12-02 21:01:53 -0600 | [diff] [blame] | 4822 | if (x < shsurf->surface->width / 3) |
Pekka Paalanen | 9d1613e | 2011-11-25 12:09:16 +0200 | [diff] [blame] | 4823 | edges |= WL_SHELL_SURFACE_RESIZE_LEFT; |
Jason Ekstrand | 918f2dd | 2013-12-02 21:01:53 -0600 | [diff] [blame] | 4824 | else if (x < 2 * shsurf->surface->width / 3) |
Kristian Høgsberg | 0793756 | 2011-04-12 17:25:42 -0400 | [diff] [blame] | 4825 | edges |= 0; |
| 4826 | else |
Pekka Paalanen | 9d1613e | 2011-11-25 12:09:16 +0200 | [diff] [blame] | 4827 | edges |= WL_SHELL_SURFACE_RESIZE_RIGHT; |
Kristian Høgsberg | 0793756 | 2011-04-12 17:25:42 -0400 | [diff] [blame] | 4828 | |
Jason Ekstrand | 918f2dd | 2013-12-02 21:01:53 -0600 | [diff] [blame] | 4829 | if (y < shsurf->surface->height / 3) |
Pekka Paalanen | 9d1613e | 2011-11-25 12:09:16 +0200 | [diff] [blame] | 4830 | edges |= WL_SHELL_SURFACE_RESIZE_TOP; |
Jason Ekstrand | 918f2dd | 2013-12-02 21:01:53 -0600 | [diff] [blame] | 4831 | else if (y < 2 * shsurf->surface->height / 3) |
Kristian Høgsberg | 0793756 | 2011-04-12 17:25:42 -0400 | [diff] [blame] | 4832 | edges |= 0; |
| 4833 | else |
Pekka Paalanen | 9d1613e | 2011-11-25 12:09:16 +0200 | [diff] [blame] | 4834 | edges |= WL_SHELL_SURFACE_RESIZE_BOTTOM; |
Kristian Høgsberg | 0793756 | 2011-04-12 17:25:42 -0400 | [diff] [blame] | 4835 | |
Derek Foreman | 8fbebbd | 2015-07-15 13:00:40 -0500 | [diff] [blame] | 4836 | surface_resize(shsurf, pointer, edges); |
Kristian Høgsberg | 02ec0a5 | 2011-04-23 13:04:11 -0400 | [diff] [blame] | 4837 | } |
| 4838 | |
| 4839 | static void |
Derek Foreman | 8ae2db5 | 2015-07-15 13:00:36 -0500 | [diff] [blame] | 4840 | surface_opacity_binding(struct weston_pointer *pointer, uint32_t time, |
Peter Hutterer | 89b6a49 | 2016-01-18 15:58:17 +1000 | [diff] [blame] | 4841 | struct weston_pointer_axis_event *event, |
| 4842 | void *data) |
Scott Moreau | a3aa9c9 | 2012-03-22 11:01:03 -0600 | [diff] [blame] | 4843 | { |
Jonas Ådahl | b0b87ba | 2012-09-27 18:40:42 +0200 | [diff] [blame] | 4844 | float step = 0.005; |
Scott Moreau | a3aa9c9 | 2012-03-22 11:01:03 -0600 | [diff] [blame] | 4845 | struct shell_surface *shsurf; |
Derek Foreman | 8ae2db5 | 2015-07-15 13:00:36 -0500 | [diff] [blame] | 4846 | struct weston_surface *focus = pointer->focus->surface; |
Pekka Paalanen | 01388e2 | 2013-04-25 13:57:44 +0300 | [diff] [blame] | 4847 | struct weston_surface *surface; |
Scott Moreau | a3aa9c9 | 2012-03-22 11:01:03 -0600 | [diff] [blame] | 4848 | |
Pekka Paalanen | 01388e2 | 2013-04-25 13:57:44 +0300 | [diff] [blame] | 4849 | /* XXX: broken for windows containing sub-surfaces */ |
| 4850 | surface = weston_surface_get_main_surface(focus); |
Scott Moreau | a3aa9c9 | 2012-03-22 11:01:03 -0600 | [diff] [blame] | 4851 | if (surface == NULL) |
| 4852 | return; |
| 4853 | |
| 4854 | shsurf = get_shell_surface(surface); |
| 4855 | if (!shsurf) |
| 4856 | return; |
| 4857 | |
Giulio Camuffo | 90a6fc6 | 2016-03-22 17:44:54 +0200 | [diff] [blame] | 4858 | shsurf->view->alpha -= event->value * step; |
Scott Moreau | a3aa9c9 | 2012-03-22 11:01:03 -0600 | [diff] [blame] | 4859 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 4860 | if (shsurf->view->alpha > 1.0) |
| 4861 | shsurf->view->alpha = 1.0; |
| 4862 | if (shsurf->view->alpha < step) |
| 4863 | shsurf->view->alpha = step; |
Scott Moreau | a3aa9c9 | 2012-03-22 11:01:03 -0600 | [diff] [blame] | 4864 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 4865 | weston_view_geometry_dirty(shsurf->view); |
Scott Moreau | a3aa9c9 | 2012-03-22 11:01:03 -0600 | [diff] [blame] | 4866 | weston_surface_damage(surface); |
| 4867 | } |
| 4868 | |
| 4869 | static void |
Kristian Høgsberg | e314875 | 2013-05-06 23:19:49 -0400 | [diff] [blame] | 4870 | do_zoom(struct weston_seat *seat, uint32_t time, uint32_t key, uint32_t axis, |
Giulio Camuffo | 90a6fc6 | 2016-03-22 17:44:54 +0200 | [diff] [blame] | 4871 | double value) |
Scott Moreau | ccbf29d | 2012-02-22 14:21:41 -0700 | [diff] [blame] | 4872 | { |
Derek Foreman | 8aeeac8 | 2015-01-30 13:24:36 -0600 | [diff] [blame] | 4873 | struct weston_compositor *compositor = seat->compositor; |
Derek Foreman | 1281a36 | 2015-07-31 16:55:32 -0500 | [diff] [blame] | 4874 | struct weston_pointer *pointer = weston_seat_get_pointer(seat); |
Scott Moreau | ccbf29d | 2012-02-22 14:21:41 -0700 | [diff] [blame] | 4875 | struct weston_output *output; |
Scott Moreau | e660398 | 2012-06-11 13:07:51 -0600 | [diff] [blame] | 4876 | float increment; |
Scott Moreau | ccbf29d | 2012-02-22 14:21:41 -0700 | [diff] [blame] | 4877 | |
Derek Foreman | 1281a36 | 2015-07-31 16:55:32 -0500 | [diff] [blame] | 4878 | if (!pointer) { |
Derek Foreman | 7ef3bed | 2015-01-06 14:28:13 -0600 | [diff] [blame] | 4879 | weston_log("Zoom hotkey pressed but seat '%s' contains no pointer.\n", seat->seat_name); |
| 4880 | return; |
| 4881 | } |
| 4882 | |
Scott Moreau | ccbf29d | 2012-02-22 14:21:41 -0700 | [diff] [blame] | 4883 | wl_list_for_each(output, &compositor->output_list, link) { |
| 4884 | if (pixman_region32_contains_point(&output->region, |
Derek Foreman | 1281a36 | 2015-07-31 16:55:32 -0500 | [diff] [blame] | 4885 | wl_fixed_to_double(pointer->x), |
| 4886 | wl_fixed_to_double(pointer->y), |
Daniel Stone | 103db7f | 2012-05-08 17:17:55 +0100 | [diff] [blame] | 4887 | NULL)) { |
Daniel Stone | 325fc2d | 2012-05-30 16:31:58 +0100 | [diff] [blame] | 4888 | if (key == KEY_PAGEUP) |
Kristian Høgsberg | 9b68af0 | 2012-05-22 12:55:18 -0400 | [diff] [blame] | 4889 | increment = output->zoom.increment; |
Daniel Stone | 325fc2d | 2012-05-30 16:31:58 +0100 | [diff] [blame] | 4890 | else if (key == KEY_PAGEDOWN) |
Kristian Høgsberg | 9b68af0 | 2012-05-22 12:55:18 -0400 | [diff] [blame] | 4891 | increment = -output->zoom.increment; |
| 4892 | else if (axis == WL_POINTER_AXIS_VERTICAL_SCROLL) |
Jonas Ådahl | b0b87ba | 2012-09-27 18:40:42 +0200 | [diff] [blame] | 4893 | /* For every pixel zoom 20th of a step */ |
Daniel Stone | 0c1e46e | 2012-05-30 16:31:59 +0100 | [diff] [blame] | 4894 | increment = output->zoom.increment * |
Giulio Camuffo | 90a6fc6 | 2016-03-22 17:44:54 +0200 | [diff] [blame] | 4895 | -value / 20.0; |
Kristian Høgsberg | 9b68af0 | 2012-05-22 12:55:18 -0400 | [diff] [blame] | 4896 | else |
| 4897 | increment = 0; |
| 4898 | |
Kristian Høgsberg | 9b68af0 | 2012-05-22 12:55:18 -0400 | [diff] [blame] | 4899 | output->zoom.level += increment; |
Scott Moreau | c6d7f60 | 2012-02-23 22:28:37 -0700 | [diff] [blame] | 4900 | |
Scott Moreau | e660398 | 2012-06-11 13:07:51 -0600 | [diff] [blame] | 4901 | if (output->zoom.level < 0.0) |
Scott Moreau | 850ca42 | 2012-05-21 15:21:25 -0600 | [diff] [blame] | 4902 | output->zoom.level = 0.0; |
Scott Moreau | e660398 | 2012-06-11 13:07:51 -0600 | [diff] [blame] | 4903 | else if (output->zoom.level > output->zoom.max_level) |
| 4904 | output->zoom.level = output->zoom.max_level; |
Derek Foreman | 25bd8a7 | 2015-07-23 14:55:13 -0500 | [diff] [blame] | 4905 | |
| 4906 | if (!output->zoom.active) { |
| 4907 | if (output->zoom.level <= 0.0) |
| 4908 | continue; |
Derek Foreman | 22276a5 | 2015-07-23 14:55:15 -0500 | [diff] [blame] | 4909 | weston_output_activate_zoom(output, seat); |
Kristian Høgsberg | 79af73e | 2012-08-03 15:45:23 -0400 | [diff] [blame] | 4910 | } |
Scott Moreau | ccbf29d | 2012-02-22 14:21:41 -0700 | [diff] [blame] | 4911 | |
Scott Moreau | e660398 | 2012-06-11 13:07:51 -0600 | [diff] [blame] | 4912 | output->zoom.spring_z.target = output->zoom.level; |
Scott Moreau | ccbf29d | 2012-02-22 14:21:41 -0700 | [diff] [blame] | 4913 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 4914 | weston_output_update_zoom(output); |
Scott Moreau | ccbf29d | 2012-02-22 14:21:41 -0700 | [diff] [blame] | 4915 | } |
| 4916 | } |
| 4917 | } |
| 4918 | |
Scott Moreau | ccbf29d | 2012-02-22 14:21:41 -0700 | [diff] [blame] | 4919 | static void |
Derek Foreman | 8ae2db5 | 2015-07-15 13:00:36 -0500 | [diff] [blame] | 4920 | zoom_axis_binding(struct weston_pointer *pointer, uint32_t time, |
Peter Hutterer | 89b6a49 | 2016-01-18 15:58:17 +1000 | [diff] [blame] | 4921 | struct weston_pointer_axis_event *event, |
| 4922 | void *data) |
Daniel Stone | 325fc2d | 2012-05-30 16:31:58 +0100 | [diff] [blame] | 4923 | { |
Peter Hutterer | 89b6a49 | 2016-01-18 15:58:17 +1000 | [diff] [blame] | 4924 | do_zoom(pointer->seat, time, 0, event->axis, event->value); |
Daniel Stone | 325fc2d | 2012-05-30 16:31:58 +0100 | [diff] [blame] | 4925 | } |
| 4926 | |
| 4927 | static void |
Derek Foreman | 8ae2db5 | 2015-07-15 13:00:36 -0500 | [diff] [blame] | 4928 | zoom_key_binding(struct weston_keyboard *keyboard, uint32_t time, |
| 4929 | uint32_t key, void *data) |
Daniel Stone | 325fc2d | 2012-05-30 16:31:58 +0100 | [diff] [blame] | 4930 | { |
Derek Foreman | 8ae2db5 | 2015-07-15 13:00:36 -0500 | [diff] [blame] | 4931 | do_zoom(keyboard->seat, time, key, 0, 0); |
Daniel Stone | 325fc2d | 2012-05-30 16:31:58 +0100 | [diff] [blame] | 4932 | } |
| 4933 | |
| 4934 | static void |
Derek Foreman | 8ae2db5 | 2015-07-15 13:00:36 -0500 | [diff] [blame] | 4935 | terminate_binding(struct weston_keyboard *keyboard, uint32_t time, |
| 4936 | uint32_t key, void *data) |
Kristian Høgsberg | e1a850e | 2011-12-19 15:18:05 -0500 | [diff] [blame] | 4937 | { |
Kristian Høgsberg | 8334bc1 | 2012-01-03 10:29:47 -0500 | [diff] [blame] | 4938 | struct weston_compositor *compositor = data; |
Kristian Høgsberg | e1a850e | 2011-12-19 15:18:05 -0500 | [diff] [blame] | 4939 | |
Daniel Stone | 325fc2d | 2012-05-30 16:31:58 +0100 | [diff] [blame] | 4940 | wl_display_terminate(compositor->wl_display); |
Kristian Høgsberg | e1a850e | 2011-12-19 15:18:05 -0500 | [diff] [blame] | 4941 | } |
| 4942 | |
Emilio Pozuelo Monfort | 03251b6 | 2013-11-19 11:37:16 +0100 | [diff] [blame] | 4943 | static void |
Giulio Camuffo | 1959ab8 | 2013-11-14 23:42:52 +0100 | [diff] [blame] | 4944 | rotate_grab_motion(struct weston_pointer_grab *grab, uint32_t time, |
Jonas Ådahl | d251010 | 2014-10-05 21:39:14 +0200 | [diff] [blame] | 4945 | struct weston_pointer_motion_event *event) |
Pekka Paalanen | 460099f | 2012-01-20 16:48:25 +0200 | [diff] [blame] | 4946 | { |
| 4947 | struct rotate_grab *rotate = |
Ander Conselvan de Oliveira | fe0444a | 2012-04-04 17:48:05 +0300 | [diff] [blame] | 4948 | container_of(grab, struct rotate_grab, base.grab); |
Kristian Høgsberg | 02bbabb | 2013-05-06 22:15:05 -0400 | [diff] [blame] | 4949 | struct weston_pointer *pointer = grab->pointer; |
Ander Conselvan de Oliveira | fe0444a | 2012-04-04 17:48:05 +0300 | [diff] [blame] | 4950 | struct shell_surface *shsurf = rotate->base.shsurf; |
John Kåre Alsaker | 490d02a | 2012-09-30 02:57:21 +0200 | [diff] [blame] | 4951 | float cx, cy, dx, dy, cposx, cposy, dposx, dposy, r; |
Ander Conselvan de Oliveira | fe0444a | 2012-04-04 17:48:05 +0300 | [diff] [blame] | 4952 | |
Jonas Ådahl | d251010 | 2014-10-05 21:39:14 +0200 | [diff] [blame] | 4953 | weston_pointer_move(pointer, event); |
Giulio Camuffo | 1959ab8 | 2013-11-14 23:42:52 +0100 | [diff] [blame] | 4954 | |
Ander Conselvan de Oliveira | fe0444a | 2012-04-04 17:48:05 +0300 | [diff] [blame] | 4955 | if (!shsurf) |
| 4956 | return; |
| 4957 | |
Jason Ekstrand | 918f2dd | 2013-12-02 21:01:53 -0600 | [diff] [blame] | 4958 | cx = 0.5f * shsurf->surface->width; |
| 4959 | cy = 0.5f * shsurf->surface->height; |
Pekka Paalanen | 460099f | 2012-01-20 16:48:25 +0200 | [diff] [blame] | 4960 | |
Daniel Stone | 37816df | 2012-05-16 18:45:18 +0100 | [diff] [blame] | 4961 | dx = wl_fixed_to_double(pointer->x) - rotate->center.x; |
| 4962 | dy = wl_fixed_to_double(pointer->y) - rotate->center.y; |
Pekka Paalanen | 460099f | 2012-01-20 16:48:25 +0200 | [diff] [blame] | 4963 | r = sqrtf(dx * dx + dy * dy); |
| 4964 | |
Ander Conselvan de Oliveira | fe0444a | 2012-04-04 17:48:05 +0300 | [diff] [blame] | 4965 | wl_list_remove(&shsurf->rotation.transform.link); |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 4966 | weston_view_geometry_dirty(shsurf->view); |
Pekka Paalanen | 460099f | 2012-01-20 16:48:25 +0200 | [diff] [blame] | 4967 | |
| 4968 | if (r > 20.0f) { |
Pekka Paalanen | 460099f | 2012-01-20 16:48:25 +0200 | [diff] [blame] | 4969 | struct weston_matrix *matrix = |
Ander Conselvan de Oliveira | fe0444a | 2012-04-04 17:48:05 +0300 | [diff] [blame] | 4970 | &shsurf->rotation.transform.matrix; |
Pekka Paalanen | 460099f | 2012-01-20 16:48:25 +0200 | [diff] [blame] | 4971 | |
Kristian Høgsberg | 765e27b | 2012-01-27 13:36:13 -0500 | [diff] [blame] | 4972 | weston_matrix_init(&rotate->rotation); |
Vasily Khoruzhick | 1bbf372 | 2013-01-28 22:40:28 +0300 | [diff] [blame] | 4973 | weston_matrix_rotate_xy(&rotate->rotation, dx / r, dy / r); |
Pekka Paalanen | 460099f | 2012-01-20 16:48:25 +0200 | [diff] [blame] | 4974 | |
| 4975 | weston_matrix_init(matrix); |
Pekka Paalanen | 7b3bd3d | 2012-01-30 14:16:34 +0200 | [diff] [blame] | 4976 | weston_matrix_translate(matrix, -cx, -cy, 0.0f); |
Ander Conselvan de Oliveira | fe0444a | 2012-04-04 17:48:05 +0300 | [diff] [blame] | 4977 | weston_matrix_multiply(matrix, &shsurf->rotation.rotation); |
Kristian Høgsberg | 765e27b | 2012-01-27 13:36:13 -0500 | [diff] [blame] | 4978 | weston_matrix_multiply(matrix, &rotate->rotation); |
Pekka Paalanen | 7b3bd3d | 2012-01-30 14:16:34 +0200 | [diff] [blame] | 4979 | weston_matrix_translate(matrix, cx, cy, 0.0f); |
Pekka Paalanen | 460099f | 2012-01-20 16:48:25 +0200 | [diff] [blame] | 4980 | |
Pekka Paalanen | bc0b7e7 | 2012-01-24 09:53:37 +0200 | [diff] [blame] | 4981 | wl_list_insert( |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 4982 | &shsurf->view->geometry.transformation_list, |
Ander Conselvan de Oliveira | fe0444a | 2012-04-04 17:48:05 +0300 | [diff] [blame] | 4983 | &shsurf->rotation.transform.link); |
Pekka Paalanen | 460099f | 2012-01-20 16:48:25 +0200 | [diff] [blame] | 4984 | } else { |
Ander Conselvan de Oliveira | fe0444a | 2012-04-04 17:48:05 +0300 | [diff] [blame] | 4985 | wl_list_init(&shsurf->rotation.transform.link); |
| 4986 | weston_matrix_init(&shsurf->rotation.rotation); |
Kristian Høgsberg | 765e27b | 2012-01-27 13:36:13 -0500 | [diff] [blame] | 4987 | weston_matrix_init(&rotate->rotation); |
Pekka Paalanen | 460099f | 2012-01-20 16:48:25 +0200 | [diff] [blame] | 4988 | } |
Pekka Paalanen | b45ac5e | 2012-02-09 15:58:44 +0200 | [diff] [blame] | 4989 | |
Rafal Mielniczuk | 2d7ab82 | 2012-03-22 22:22:04 +0100 | [diff] [blame] | 4990 | /* We need to adjust the position of the surface |
| 4991 | * in case it was resized in a rotated state before */ |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 4992 | cposx = shsurf->view->geometry.x + cx; |
| 4993 | cposy = shsurf->view->geometry.y + cy; |
Rafal Mielniczuk | 2d7ab82 | 2012-03-22 22:22:04 +0100 | [diff] [blame] | 4994 | dposx = rotate->center.x - cposx; |
| 4995 | dposy = rotate->center.y - cposy; |
| 4996 | if (dposx != 0.0f || dposy != 0.0f) { |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 4997 | weston_view_set_position(shsurf->view, |
| 4998 | shsurf->view->geometry.x + dposx, |
| 4999 | shsurf->view->geometry.y + dposy); |
Rafal Mielniczuk | 2d7ab82 | 2012-03-22 22:22:04 +0100 | [diff] [blame] | 5000 | } |
| 5001 | |
Derek Foreman | 4b1a0a1 | 2014-09-10 15:37:33 -0500 | [diff] [blame] | 5002 | /* Repaint implies weston_view_update_transform(), which |
Pekka Paalanen | b45ac5e | 2012-02-09 15:58:44 +0200 | [diff] [blame] | 5003 | * lazily applies the damage due to rotation update. |
| 5004 | */ |
Ander Conselvan de Oliveira | fe0444a | 2012-04-04 17:48:05 +0300 | [diff] [blame] | 5005 | weston_compositor_schedule_repaint(shsurf->surface->compositor); |
Pekka Paalanen | 460099f | 2012-01-20 16:48:25 +0200 | [diff] [blame] | 5006 | } |
| 5007 | |
| 5008 | static void |
Kristian Høgsberg | 02bbabb | 2013-05-06 22:15:05 -0400 | [diff] [blame] | 5009 | rotate_grab_button(struct weston_pointer_grab *grab, |
| 5010 | uint32_t time, uint32_t button, uint32_t state_w) |
Pekka Paalanen | 460099f | 2012-01-20 16:48:25 +0200 | [diff] [blame] | 5011 | { |
| 5012 | struct rotate_grab *rotate = |
Ander Conselvan de Oliveira | fe0444a | 2012-04-04 17:48:05 +0300 | [diff] [blame] | 5013 | container_of(grab, struct rotate_grab, base.grab); |
Kristian Høgsberg | 02bbabb | 2013-05-06 22:15:05 -0400 | [diff] [blame] | 5014 | struct weston_pointer *pointer = grab->pointer; |
Ander Conselvan de Oliveira | fe0444a | 2012-04-04 17:48:05 +0300 | [diff] [blame] | 5015 | struct shell_surface *shsurf = rotate->base.shsurf; |
Daniel Stone | 4dbadb1 | 2012-05-30 16:31:51 +0100 | [diff] [blame] | 5016 | enum wl_pointer_button_state state = state_w; |
Pekka Paalanen | 460099f | 2012-01-20 16:48:25 +0200 | [diff] [blame] | 5017 | |
Daniel Stone | 4dbadb1 | 2012-05-30 16:31:51 +0100 | [diff] [blame] | 5018 | if (pointer->button_count == 0 && |
| 5019 | state == WL_POINTER_BUTTON_STATE_RELEASED) { |
Ander Conselvan de Oliveira | fe0444a | 2012-04-04 17:48:05 +0300 | [diff] [blame] | 5020 | if (shsurf) |
| 5021 | weston_matrix_multiply(&shsurf->rotation.rotation, |
| 5022 | &rotate->rotation); |
Ander Conselvan de Oliveira | b9d2a0f | 2012-06-28 18:08:05 +0300 | [diff] [blame] | 5023 | shell_grab_end(&rotate->base); |
Pekka Paalanen | 460099f | 2012-01-20 16:48:25 +0200 | [diff] [blame] | 5024 | free(rotate); |
| 5025 | } |
| 5026 | } |
| 5027 | |
Jonas Ådahl | 1ea343e | 2013-10-25 23:18:05 +0200 | [diff] [blame] | 5028 | static void |
| 5029 | rotate_grab_cancel(struct weston_pointer_grab *grab) |
| 5030 | { |
| 5031 | struct rotate_grab *rotate = |
| 5032 | container_of(grab, struct rotate_grab, base.grab); |
| 5033 | |
| 5034 | shell_grab_end(&rotate->base); |
| 5035 | free(rotate); |
| 5036 | } |
| 5037 | |
Kristian Høgsberg | 02bbabb | 2013-05-06 22:15:05 -0400 | [diff] [blame] | 5038 | static const struct weston_pointer_grab_interface rotate_grab_interface = { |
Pekka Paalanen | 460099f | 2012-01-20 16:48:25 +0200 | [diff] [blame] | 5039 | noop_grab_focus, |
| 5040 | rotate_grab_motion, |
| 5041 | rotate_grab_button, |
Jonas Ådahl | 0336ca0 | 2014-10-04 16:28:29 +0200 | [diff] [blame] | 5042 | noop_grab_axis, |
Peter Hutterer | 87743e9 | 2016-01-18 16:38:22 +1000 | [diff] [blame] | 5043 | noop_grab_axis_source, |
| 5044 | noop_grab_frame, |
Jonas Ådahl | 1ea343e | 2013-10-25 23:18:05 +0200 | [diff] [blame] | 5045 | rotate_grab_cancel, |
Pekka Paalanen | 460099f | 2012-01-20 16:48:25 +0200 | [diff] [blame] | 5046 | }; |
| 5047 | |
| 5048 | static void |
Derek Foreman | 74de469 | 2015-07-15 13:00:39 -0500 | [diff] [blame] | 5049 | surface_rotate(struct shell_surface *surface, struct weston_pointer *pointer) |
Pekka Paalanen | 460099f | 2012-01-20 16:48:25 +0200 | [diff] [blame] | 5050 | { |
Pekka Paalanen | 460099f | 2012-01-20 16:48:25 +0200 | [diff] [blame] | 5051 | struct rotate_grab *rotate; |
John Kåre Alsaker | 490d02a | 2012-09-30 02:57:21 +0200 | [diff] [blame] | 5052 | float dx, dy; |
| 5053 | float r; |
Pekka Paalanen | 460099f | 2012-01-20 16:48:25 +0200 | [diff] [blame] | 5054 | |
Derek Foreman | 45a7c27 | 2015-09-11 14:27:40 -0500 | [diff] [blame] | 5055 | surface = find_toplevel_surface(surface); |
| 5056 | |
Pekka Paalanen | 460099f | 2012-01-20 16:48:25 +0200 | [diff] [blame] | 5057 | rotate = malloc(sizeof *rotate); |
| 5058 | if (!rotate) |
| 5059 | return; |
| 5060 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 5061 | weston_view_to_global_float(surface->view, |
Jason Ekstrand | 918f2dd | 2013-12-02 21:01:53 -0600 | [diff] [blame] | 5062 | surface->surface->width * 0.5f, |
| 5063 | surface->surface->height * 0.5f, |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 5064 | &rotate->center.x, &rotate->center.y); |
Pekka Paalanen | 460099f | 2012-01-20 16:48:25 +0200 | [diff] [blame] | 5065 | |
Derek Foreman | 74de469 | 2015-07-15 13:00:39 -0500 | [diff] [blame] | 5066 | dx = wl_fixed_to_double(pointer->x) - rotate->center.x; |
| 5067 | dy = wl_fixed_to_double(pointer->y) - rotate->center.y; |
Kristian Høgsberg | 765e27b | 2012-01-27 13:36:13 -0500 | [diff] [blame] | 5068 | r = sqrtf(dx * dx + dy * dy); |
| 5069 | if (r > 20.0f) { |
| 5070 | struct weston_matrix inverse; |
| 5071 | |
| 5072 | weston_matrix_init(&inverse); |
Vasily Khoruzhick | 1bbf372 | 2013-01-28 22:40:28 +0300 | [diff] [blame] | 5073 | weston_matrix_rotate_xy(&inverse, dx / r, -dy / r); |
Kristian Høgsberg | 765e27b | 2012-01-27 13:36:13 -0500 | [diff] [blame] | 5074 | weston_matrix_multiply(&surface->rotation.rotation, &inverse); |
Rafal Mielniczuk | 2d7ab82 | 2012-03-22 22:22:04 +0100 | [diff] [blame] | 5075 | |
| 5076 | weston_matrix_init(&rotate->rotation); |
Vasily Khoruzhick | 1bbf372 | 2013-01-28 22:40:28 +0300 | [diff] [blame] | 5077 | weston_matrix_rotate_xy(&rotate->rotation, dx / r, dy / r); |
Kristian Høgsberg | 765e27b | 2012-01-27 13:36:13 -0500 | [diff] [blame] | 5078 | } else { |
| 5079 | weston_matrix_init(&surface->rotation.rotation); |
| 5080 | weston_matrix_init(&rotate->rotation); |
| 5081 | } |
| 5082 | |
Ander Conselvan de Oliveira | b9d2a0f | 2012-06-28 18:08:05 +0300 | [diff] [blame] | 5083 | shell_grab_start(&rotate->base, &rotate_grab_interface, surface, |
Jonas Ådahl | 6d6fb61 | 2015-11-17 16:00:33 +0800 | [diff] [blame] | 5084 | pointer, WESTON_DESKTOP_SHELL_CURSOR_ARROW); |
Pekka Paalanen | 460099f | 2012-01-20 16:48:25 +0200 | [diff] [blame] | 5085 | } |
| 5086 | |
| 5087 | static void |
Derek Foreman | 8ae2db5 | 2015-07-15 13:00:36 -0500 | [diff] [blame] | 5088 | rotate_binding(struct weston_pointer *pointer, uint32_t time, uint32_t button, |
Kristian Høgsberg | 0c36903 | 2013-02-14 21:31:44 -0500 | [diff] [blame] | 5089 | void *data) |
| 5090 | { |
Rafal Mielniczuk | b2917a2 | 2014-01-05 20:04:59 +0100 | [diff] [blame] | 5091 | struct weston_surface *focus; |
Pekka Paalanen | 01388e2 | 2013-04-25 13:57:44 +0300 | [diff] [blame] | 5092 | struct weston_surface *base_surface; |
Kristian Høgsberg | 0c36903 | 2013-02-14 21:31:44 -0500 | [diff] [blame] | 5093 | struct shell_surface *surface; |
| 5094 | |
Derek Foreman | 8ae2db5 | 2015-07-15 13:00:36 -0500 | [diff] [blame] | 5095 | if (pointer->focus == NULL) |
Rafal Mielniczuk | b2917a2 | 2014-01-05 20:04:59 +0100 | [diff] [blame] | 5096 | return; |
| 5097 | |
Derek Foreman | 8ae2db5 | 2015-07-15 13:00:36 -0500 | [diff] [blame] | 5098 | focus = pointer->focus->surface; |
Rafal Mielniczuk | b2917a2 | 2014-01-05 20:04:59 +0100 | [diff] [blame] | 5099 | |
Pekka Paalanen | 01388e2 | 2013-04-25 13:57:44 +0300 | [diff] [blame] | 5100 | base_surface = weston_surface_get_main_surface(focus); |
Kristian Høgsberg | 0c36903 | 2013-02-14 21:31:44 -0500 | [diff] [blame] | 5101 | if (base_surface == NULL) |
| 5102 | return; |
| 5103 | |
| 5104 | surface = get_shell_surface(base_surface); |
Rafael Antognolli | 03b1659 | 2013-12-03 15:35:42 -0200 | [diff] [blame] | 5105 | if (surface == NULL || surface->state.fullscreen || |
| 5106 | surface->state.maximized) |
Kristian Høgsberg | 0c36903 | 2013-02-14 21:31:44 -0500 | [diff] [blame] | 5107 | return; |
| 5108 | |
Derek Foreman | 74de469 | 2015-07-15 13:00:39 -0500 | [diff] [blame] | 5109 | surface_rotate(surface, pointer); |
Kristian Høgsberg | 0c36903 | 2013-02-14 21:31:44 -0500 | [diff] [blame] | 5110 | } |
| 5111 | |
Emilio Pozuelo Monfort | 9e7c759 | 2014-01-30 14:01:10 +0100 | [diff] [blame] | 5112 | /* Move all fullscreen layers down to the current workspace and hide their |
| 5113 | * black views. The surfaces' state is set to both fullscreen and lowered, |
| 5114 | * and this is reversed when such a surface is re-configured, see |
| 5115 | * shell_configure_fullscreen() and shell_ensure_fullscreen_black_view(). |
| 5116 | * |
Mario Kleiner | 9f4d655 | 2015-06-21 21:25:08 +0200 | [diff] [blame] | 5117 | * lowering_output = NULL - Lower on all outputs, else only lower on the |
| 5118 | * specified output. |
| 5119 | * |
Emilio Pozuelo Monfort | 9e7c759 | 2014-01-30 14:01:10 +0100 | [diff] [blame] | 5120 | * This should be used when implementing shell-wide overlays, such as |
Philip Withnall | 83ffd9d | 2013-11-25 18:01:42 +0000 | [diff] [blame] | 5121 | * the alt-tab switcher, which need to de-promote fullscreen layers. */ |
Kristian Høgsberg | 1ef2313 | 2013-12-04 00:20:01 -0800 | [diff] [blame] | 5122 | void |
Mario Kleiner | 9f4d655 | 2015-06-21 21:25:08 +0200 | [diff] [blame] | 5123 | lower_fullscreen_layer(struct desktop_shell *shell, |
| 5124 | struct weston_output *lowering_output) |
Kristian Høgsberg | b0d8e77 | 2012-06-18 16:34:58 -0400 | [diff] [blame] | 5125 | { |
| 5126 | struct workspace *ws; |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 5127 | struct weston_view *view, *prev; |
Kristian Høgsberg | b0d8e77 | 2012-06-18 16:34:58 -0400 | [diff] [blame] | 5128 | |
| 5129 | ws = get_current_workspace(shell); |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 5130 | wl_list_for_each_reverse_safe(view, prev, |
Giulio Camuffo | 412e6a5 | 2014-07-09 22:12:56 +0300 | [diff] [blame] | 5131 | &shell->fullscreen_layer.view_list.link, |
| 5132 | layer_link.link) { |
Emilio Pozuelo Monfort | 9e7c759 | 2014-01-30 14:01:10 +0100 | [diff] [blame] | 5133 | struct shell_surface *shsurf = get_shell_surface(view->surface); |
| 5134 | |
| 5135 | if (!shsurf) |
| 5136 | continue; |
| 5137 | |
Mario Kleiner | 9f4d655 | 2015-06-21 21:25:08 +0200 | [diff] [blame] | 5138 | /* Only lower surfaces which have lowering_output as their fullscreen |
| 5139 | * output, unless a NULL output asks for lowering on all outputs. |
| 5140 | */ |
| 5141 | if (lowering_output && (shsurf->fullscreen_output != lowering_output)) |
| 5142 | continue; |
| 5143 | |
Emilio Pozuelo Monfort | 9e7c759 | 2014-01-30 14:01:10 +0100 | [diff] [blame] | 5144 | /* We can have a non-fullscreen popup for a fullscreen surface |
| 5145 | * in the fullscreen layer. */ |
| 5146 | if (shsurf->state.fullscreen) { |
| 5147 | /* Hide the black view */ |
Giulio Camuffo | 412e6a5 | 2014-07-09 22:12:56 +0300 | [diff] [blame] | 5148 | weston_layer_entry_remove(&shsurf->fullscreen.black_view->layer_link); |
| 5149 | wl_list_init(&shsurf->fullscreen.black_view->layer_link.link); |
Kristian Høgsberg | c991513 | 2014-05-09 16:24:07 -0700 | [diff] [blame] | 5150 | weston_view_damage_below(shsurf->fullscreen.black_view); |
| 5151 | |
Emilio Pozuelo Monfort | 9e7c759 | 2014-01-30 14:01:10 +0100 | [diff] [blame] | 5152 | } |
| 5153 | |
| 5154 | /* Lower the view to the workspace layer */ |
Giulio Camuffo | 412e6a5 | 2014-07-09 22:12:56 +0300 | [diff] [blame] | 5155 | weston_layer_entry_remove(&view->layer_link); |
| 5156 | weston_layer_entry_insert(&ws->layer.view_list, &view->layer_link); |
Philip Withnall | 83ffd9d | 2013-11-25 18:01:42 +0000 | [diff] [blame] | 5157 | weston_view_damage_below(view); |
| 5158 | weston_surface_damage(view->surface); |
Emilio Pozuelo Monfort | 9e7c759 | 2014-01-30 14:01:10 +0100 | [diff] [blame] | 5159 | |
| 5160 | shsurf->state.lowered = true; |
Philip Withnall | 83ffd9d | 2013-11-25 18:01:42 +0000 | [diff] [blame] | 5161 | } |
Kristian Høgsberg | b0d8e77 | 2012-06-18 16:34:58 -0400 | [diff] [blame] | 5162 | } |
| 5163 | |
Kristian Høgsberg | 1ef2313 | 2013-12-04 00:20:01 -0800 | [diff] [blame] | 5164 | void |
Jonas Ådahl | 1fa6ded | 2014-10-18 13:24:53 +0200 | [diff] [blame^] | 5165 | activate(struct desktop_shell *shell, struct weston_view *view, |
Emilio Pozuelo Monfort | 9e7c759 | 2014-01-30 14:01:10 +0100 | [diff] [blame] | 5166 | struct weston_seat *seat, bool configure) |
Kristian Høgsberg | 7584062 | 2011-09-06 13:48:16 -0400 | [diff] [blame] | 5167 | { |
Jonas Ådahl | 1fa6ded | 2014-10-18 13:24:53 +0200 | [diff] [blame^] | 5168 | struct weston_surface *es = view->surface; |
Pekka Paalanen | 01388e2 | 2013-04-25 13:57:44 +0300 | [diff] [blame] | 5169 | struct weston_surface *main_surface; |
Kristian Høgsberg | 2f5faff | 2012-07-31 16:36:34 -0400 | [diff] [blame] | 5170 | struct focus_state *state; |
Jonas Ådahl | 8538b22 | 2012-08-29 22:13:03 +0200 | [diff] [blame] | 5171 | struct workspace *ws; |
Louis-Francis Ratté-Boulianne | b482dbd | 2013-11-19 11:37:11 +0100 | [diff] [blame] | 5172 | struct weston_surface *old_es; |
Rafael Antognolli | 03b1659 | 2013-12-03 15:35:42 -0200 | [diff] [blame] | 5173 | struct shell_surface *shsurf; |
Kristian Høgsberg | 7584062 | 2011-09-06 13:48:16 -0400 | [diff] [blame] | 5174 | |
Pekka Paalanen | 01388e2 | 2013-04-25 13:57:44 +0300 | [diff] [blame] | 5175 | main_surface = weston_surface_get_main_surface(es); |
Mario Kleiner | 9f4d655 | 2015-06-21 21:25:08 +0200 | [diff] [blame] | 5176 | shsurf = get_shell_surface(main_surface); |
| 5177 | assert(shsurf); |
| 5178 | |
| 5179 | /* Only demote fullscreen surfaces on the output of activated shsurf. |
| 5180 | * Leave fullscreen surfaces on unrelated outputs alone. */ |
| 5181 | lower_fullscreen_layer(shell, shsurf->output); |
Pekka Paalanen | 01388e2 | 2013-04-25 13:57:44 +0300 | [diff] [blame] | 5182 | |
Bryce Harrington | 260c2ff | 2016-06-29 19:04:06 -0700 | [diff] [blame] | 5183 | weston_seat_set_keyboard_focus(seat, es); |
Kristian Høgsberg | 7584062 | 2011-09-06 13:48:16 -0400 | [diff] [blame] | 5184 | |
Jonas Ådahl | 8538b22 | 2012-08-29 22:13:03 +0200 | [diff] [blame] | 5185 | state = ensure_focus_state(shell, seat); |
| 5186 | if (state == NULL) |
| 5187 | return; |
Kristian Høgsberg | 2f5faff | 2012-07-31 16:36:34 -0400 | [diff] [blame] | 5188 | |
Louis-Francis Ratté-Boulianne | b482dbd | 2013-11-19 11:37:11 +0100 | [diff] [blame] | 5189 | old_es = state->keyboard_focus; |
Kristian Høgsberg | d500bf1 | 2014-01-22 12:25:20 -0800 | [diff] [blame] | 5190 | focus_state_set_focus(state, es); |
Kristian Høgsberg | 2f5faff | 2012-07-31 16:36:34 -0400 | [diff] [blame] | 5191 | |
Emilio Pozuelo Monfort | 9e7c759 | 2014-01-30 14:01:10 +0100 | [diff] [blame] | 5192 | if (shsurf->state.fullscreen && configure) |
Rafael Antognolli | 03b1659 | 2013-12-03 15:35:42 -0200 | [diff] [blame] | 5193 | shell_configure_fullscreen(shsurf); |
| 5194 | else |
Mario Kleiner | 492c12f | 2015-06-21 21:25:12 +0200 | [diff] [blame] | 5195 | restore_output_mode(shsurf->output); |
Louis-Francis Ratté-Boulianne | b482dbd | 2013-11-19 11:37:11 +0100 | [diff] [blame] | 5196 | |
Emilio Pozuelo Monfort | 7908bff | 2014-01-30 13:49:39 +0100 | [diff] [blame] | 5197 | /* Update the surface’s layer. This brings it to the top of the stacking |
| 5198 | * order as appropriate. */ |
| 5199 | shell_surface_update_layer(shsurf); |
| 5200 | |
Philip Withnall | 83ffd9d | 2013-11-25 18:01:42 +0000 | [diff] [blame] | 5201 | if (shell->focus_animation_type != ANIMATION_NONE) { |
| 5202 | ws = get_current_workspace(shell); |
Louis-Francis Ratté-Boulianne | b482dbd | 2013-11-19 11:37:11 +0100 | [diff] [blame] | 5203 | 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] | 5204 | } |
Kristian Høgsberg | 7584062 | 2011-09-06 13:48:16 -0400 | [diff] [blame] | 5205 | } |
| 5206 | |
Alex Wu | 2185843 | 2012-04-01 20:13:08 +0800 | [diff] [blame] | 5207 | /* no-op func for checking black surface */ |
| 5208 | static void |
Jason Ekstrand | 918f2dd | 2013-12-02 21:01:53 -0600 | [diff] [blame] | 5209 | 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] | 5210 | { |
| 5211 | } |
| 5212 | |
Quentin Glidic | c0d79ce | 2013-01-29 14:16:13 +0100 | [diff] [blame] | 5213 | static bool |
Jonas Ådahl | 7bfb113 | 2014-10-18 12:23:20 +0200 | [diff] [blame] | 5214 | is_black_surface_view(struct weston_view *view, struct weston_view **fs_view) |
Alex Wu | 2185843 | 2012-04-01 20:13:08 +0800 | [diff] [blame] | 5215 | { |
Jonas Ådahl | 7bfb113 | 2014-10-18 12:23:20 +0200 | [diff] [blame] | 5216 | struct weston_surface *surface = view->surface; |
| 5217 | |
| 5218 | if (surface->configure == black_surface_configure) { |
| 5219 | if (fs_view) |
| 5220 | *fs_view = surface->configure_private; |
Alex Wu | 2185843 | 2012-04-01 20:13:08 +0800 | [diff] [blame] | 5221 | return true; |
| 5222 | } |
| 5223 | return false; |
| 5224 | } |
| 5225 | |
Kristian Høgsberg | 7584062 | 2011-09-06 13:48:16 -0400 | [diff] [blame] | 5226 | static void |
Neil Roberts | a28c693 | 2013-10-03 16:43:04 +0100 | [diff] [blame] | 5227 | activate_binding(struct weston_seat *seat, |
| 5228 | struct desktop_shell *shell, |
Jonas Ådahl | cd0f1ac | 2015-06-26 12:37:56 +0800 | [diff] [blame] | 5229 | struct weston_view *focus_view) |
Kristian Høgsberg | e1a850e | 2011-12-19 15:18:05 -0500 | [diff] [blame] | 5230 | { |
Jonas Ådahl | 7bfb113 | 2014-10-18 12:23:20 +0200 | [diff] [blame] | 5231 | struct weston_view *main_view; |
Pekka Paalanen | 01388e2 | 2013-04-25 13:57:44 +0300 | [diff] [blame] | 5232 | struct weston_surface *main_surface; |
Kristian Høgsberg | e1a850e | 2011-12-19 15:18:05 -0500 | [diff] [blame] | 5233 | |
Jonas Ådahl | 7bfb113 | 2014-10-18 12:23:20 +0200 | [diff] [blame] | 5234 | if (!focus_view) |
| 5235 | return; |
Alex Wu | 9c35e6b | 2012-03-05 14:13:13 +0800 | [diff] [blame] | 5236 | |
Jonas Ådahl | 7bfb113 | 2014-10-18 12:23:20 +0200 | [diff] [blame] | 5237 | if (is_black_surface_view(focus_view, &main_view)) |
| 5238 | focus_view = main_view; |
Alex Wu | 4539b08 | 2012-03-01 12:57:46 +0800 | [diff] [blame] | 5239 | |
Jonas Ådahl | 7bfb113 | 2014-10-18 12:23:20 +0200 | [diff] [blame] | 5240 | main_surface = weston_surface_get_main_surface(focus_view->surface); |
Pekka Paalanen | 01388e2 | 2013-04-25 13:57:44 +0300 | [diff] [blame] | 5241 | if (get_shell_surface_type(main_surface) == SHELL_SURFACE_NONE) |
Kristian Høgsberg | 0636ac3 | 2012-06-27 10:22:15 -0400 | [diff] [blame] | 5242 | return; |
Kristian Høgsberg | 85b2e4b | 2012-06-21 16:49:42 -0400 | [diff] [blame] | 5243 | |
Jonas Ådahl | 1fa6ded | 2014-10-18 13:24:53 +0200 | [diff] [blame^] | 5244 | activate(shell, focus_view, seat, true); |
Neil Roberts | a28c693 | 2013-10-03 16:43:04 +0100 | [diff] [blame] | 5245 | } |
| 5246 | |
| 5247 | static void |
Derek Foreman | 8ae2db5 | 2015-07-15 13:00:36 -0500 | [diff] [blame] | 5248 | click_to_activate_binding(struct weston_pointer *pointer, uint32_t time, |
| 5249 | uint32_t button, void *data) |
Neil Roberts | a28c693 | 2013-10-03 16:43:04 +0100 | [diff] [blame] | 5250 | { |
Derek Foreman | 8ae2db5 | 2015-07-15 13:00:36 -0500 | [diff] [blame] | 5251 | if (pointer->grab != &pointer->default_grab) |
Neil Roberts | a28c693 | 2013-10-03 16:43:04 +0100 | [diff] [blame] | 5252 | return; |
Derek Foreman | 8ae2db5 | 2015-07-15 13:00:36 -0500 | [diff] [blame] | 5253 | if (pointer->focus == NULL) |
Kristian Høgsberg | 7c4f6cc | 2014-01-01 16:28:32 -0800 | [diff] [blame] | 5254 | return; |
Neil Roberts | a28c693 | 2013-10-03 16:43:04 +0100 | [diff] [blame] | 5255 | |
Jonas Ådahl | cd0f1ac | 2015-06-26 12:37:56 +0800 | [diff] [blame] | 5256 | activate_binding(pointer->seat, data, pointer->focus); |
Neil Roberts | a28c693 | 2013-10-03 16:43:04 +0100 | [diff] [blame] | 5257 | } |
| 5258 | |
| 5259 | static void |
Derek Foreman | 8ae2db5 | 2015-07-15 13:00:36 -0500 | [diff] [blame] | 5260 | touch_to_activate_binding(struct weston_touch *touch, uint32_t time, |
| 5261 | void *data) |
Neil Roberts | a28c693 | 2013-10-03 16:43:04 +0100 | [diff] [blame] | 5262 | { |
Derek Foreman | 8ae2db5 | 2015-07-15 13:00:36 -0500 | [diff] [blame] | 5263 | if (touch->grab != &touch->default_grab) |
Neil Roberts | a28c693 | 2013-10-03 16:43:04 +0100 | [diff] [blame] | 5264 | return; |
Derek Foreman | 8ae2db5 | 2015-07-15 13:00:36 -0500 | [diff] [blame] | 5265 | if (touch->focus == NULL) |
Kristian Høgsberg | 0ed6750 | 2014-01-02 23:00:11 -0800 | [diff] [blame] | 5266 | return; |
Neil Roberts | a28c693 | 2013-10-03 16:43:04 +0100 | [diff] [blame] | 5267 | |
Jonas Ådahl | cd0f1ac | 2015-06-26 12:37:56 +0800 | [diff] [blame] | 5268 | activate_binding(touch->seat, data, touch->focus); |
Kristian Høgsberg | e1a850e | 2011-12-19 15:18:05 -0500 | [diff] [blame] | 5269 | } |
| 5270 | |
| 5271 | static void |
Neil Roberts | b4a9170 | 2014-04-09 16:33:32 +0100 | [diff] [blame] | 5272 | unfocus_all_seats(struct desktop_shell *shell) |
| 5273 | { |
| 5274 | struct weston_seat *seat, *next; |
| 5275 | |
| 5276 | wl_list_for_each_safe(seat, next, &shell->compositor->seat_list, link) { |
Derek Foreman | 1281a36 | 2015-07-31 16:55:32 -0500 | [diff] [blame] | 5277 | struct weston_keyboard *keyboard = |
| 5278 | weston_seat_get_keyboard(seat); |
| 5279 | |
| 5280 | if (!keyboard) |
Neil Roberts | b4a9170 | 2014-04-09 16:33:32 +0100 | [diff] [blame] | 5281 | continue; |
| 5282 | |
Derek Foreman | 1281a36 | 2015-07-31 16:55:32 -0500 | [diff] [blame] | 5283 | weston_keyboard_set_focus(keyboard, NULL); |
Neil Roberts | b4a9170 | 2014-04-09 16:33:32 +0100 | [diff] [blame] | 5284 | } |
| 5285 | } |
| 5286 | |
| 5287 | static void |
Ander Conselvan de Oliveira | 19d10ef | 2013-02-21 18:35:20 +0200 | [diff] [blame] | 5288 | lock(struct desktop_shell *shell) |
Kristian Høgsberg | 02ec0a5 | 2011-04-23 13:04:11 -0400 | [diff] [blame] | 5289 | { |
Kristian Høgsberg | 4476aaf | 2012-06-25 14:03:13 -0400 | [diff] [blame] | 5290 | struct workspace *ws = get_current_workspace(shell); |
Pekka Paalanen | f0fc70d | 2011-11-15 13:34:54 +0200 | [diff] [blame] | 5291 | |
Tiago Vignatti | 8e53c7f | 2012-02-29 19:53:50 +0200 | [diff] [blame] | 5292 | if (shell->locked) { |
Ander Conselvan de Oliveira | 87524b6 | 2013-02-21 18:35:22 +0200 | [diff] [blame] | 5293 | weston_compositor_sleep(shell->compositor); |
Pekka Paalanen | f0fc70d | 2011-11-15 13:34:54 +0200 | [diff] [blame] | 5294 | return; |
Tiago Vignatti | 8e53c7f | 2012-02-29 19:53:50 +0200 | [diff] [blame] | 5295 | } |
Pekka Paalanen | 9ef3e01 | 2011-11-15 13:34:48 +0200 | [diff] [blame] | 5296 | |
| 5297 | shell->locked = true; |
Pekka Paalanen | f0fc70d | 2011-11-15 13:34:54 +0200 | [diff] [blame] | 5298 | |
Kristian Høgsberg | 3be2ce9 | 2012-02-29 12:42:35 -0500 | [diff] [blame] | 5299 | /* Hide all surfaces by removing the fullscreen, panel and |
| 5300 | * toplevel layers. This way nothing else can show or receive |
| 5301 | * input events while we are locked. */ |
Pekka Paalanen | f0fc70d | 2011-11-15 13:34:54 +0200 | [diff] [blame] | 5302 | |
Kristian Høgsberg | 3be2ce9 | 2012-02-29 12:42:35 -0500 | [diff] [blame] | 5303 | wl_list_remove(&shell->panel_layer.link); |
Kristian Høgsberg | 3be2ce9 | 2012-02-29 12:42:35 -0500 | [diff] [blame] | 5304 | wl_list_remove(&shell->fullscreen_layer.link); |
Philipp Brüschweiler | 711fda8 | 2012-08-09 18:50:43 +0200 | [diff] [blame] | 5305 | if (shell->showing_input_panels) |
| 5306 | wl_list_remove(&shell->input_panel_layer.link); |
Kristian Høgsberg | 4476aaf | 2012-06-25 14:03:13 -0400 | [diff] [blame] | 5307 | wl_list_remove(&ws->layer.link); |
Kristian Høgsberg | 3be2ce9 | 2012-02-29 12:42:35 -0500 | [diff] [blame] | 5308 | wl_list_insert(&shell->compositor->cursor_layer.link, |
| 5309 | &shell->lock_layer.link); |
Pekka Paalanen | f0fc70d | 2011-11-15 13:34:54 +0200 | [diff] [blame] | 5310 | |
Derek Foreman | 004b4a1 | 2015-07-20 16:28:13 -0500 | [diff] [blame] | 5311 | weston_compositor_sleep(shell->compositor); |
| 5312 | |
Neil Roberts | b4a9170 | 2014-04-09 16:33:32 +0100 | [diff] [blame] | 5313 | /* Remove the keyboard focus on all seats. This will be |
| 5314 | * restored to the workspace's saved state via |
| 5315 | * restore_focus_state when the compositor is unlocked */ |
| 5316 | unfocus_all_seats(shell); |
| 5317 | |
Pekka Paalanen | f0fc70d | 2011-11-15 13:34:54 +0200 | [diff] [blame] | 5318 | /* TODO: disable bindings that should not work while locked. */ |
| 5319 | |
| 5320 | /* All this must be undone in resume_desktop(). */ |
Pekka Paalanen | 9ef3e01 | 2011-11-15 13:34:48 +0200 | [diff] [blame] | 5321 | } |
| 5322 | |
| 5323 | static void |
Ander Conselvan de Oliveira | 19d10ef | 2013-02-21 18:35:20 +0200 | [diff] [blame] | 5324 | unlock(struct desktop_shell *shell) |
Pekka Paalanen | 9ef3e01 | 2011-11-15 13:34:48 +0200 | [diff] [blame] | 5325 | { |
Jonas Ådahl | 6d6fb61 | 2015-11-17 16:00:33 +0800 | [diff] [blame] | 5326 | struct wl_resource *shell_resource; |
| 5327 | |
Pekka Paalanen | d81c216 | 2011-11-16 13:47:34 +0200 | [diff] [blame] | 5328 | if (!shell->locked || shell->lock_surface) { |
Ander Conselvan de Oliveira | 87524b6 | 2013-02-21 18:35:22 +0200 | [diff] [blame] | 5329 | shell_fade(shell, FADE_IN); |
Pekka Paalanen | 9ef3e01 | 2011-11-15 13:34:48 +0200 | [diff] [blame] | 5330 | return; |
| 5331 | } |
| 5332 | |
| 5333 | /* If desktop-shell client has gone away, unlock immediately. */ |
| 5334 | if (!shell->child.desktop_shell) { |
Pekka Paalanen | f0fc70d | 2011-11-15 13:34:54 +0200 | [diff] [blame] | 5335 | resume_desktop(shell); |
Pekka Paalanen | 9ef3e01 | 2011-11-15 13:34:48 +0200 | [diff] [blame] | 5336 | return; |
| 5337 | } |
| 5338 | |
| 5339 | if (shell->prepare_event_sent) |
| 5340 | return; |
| 5341 | |
Jonas Ådahl | 6d6fb61 | 2015-11-17 16:00:33 +0800 | [diff] [blame] | 5342 | shell_resource = shell->child.desktop_shell; |
| 5343 | weston_desktop_shell_send_prepare_lock_surface(shell_resource); |
Pekka Paalanen | 9ef3e01 | 2011-11-15 13:34:48 +0200 | [diff] [blame] | 5344 | shell->prepare_event_sent = true; |
Kristian Høgsberg | 02ec0a5 | 2011-04-23 13:04:11 -0400 | [diff] [blame] | 5345 | } |
| 5346 | |
| 5347 | static void |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 5348 | shell_fade_done(struct weston_view_animation *animation, void *data) |
Ander Conselvan de Oliveira | 19d10ef | 2013-02-21 18:35:20 +0200 | [diff] [blame] | 5349 | { |
| 5350 | struct desktop_shell *shell = data; |
| 5351 | |
| 5352 | shell->fade.animation = NULL; |
| 5353 | |
| 5354 | switch (shell->fade.type) { |
| 5355 | case FADE_IN: |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 5356 | weston_surface_destroy(shell->fade.view->surface); |
| 5357 | shell->fade.view = NULL; |
Ander Conselvan de Oliveira | 19d10ef | 2013-02-21 18:35:20 +0200 | [diff] [blame] | 5358 | break; |
| 5359 | case FADE_OUT: |
Ander Conselvan de Oliveira | 19d10ef | 2013-02-21 18:35:20 +0200 | [diff] [blame] | 5360 | lock(shell); |
| 5361 | break; |
Philip Withnall | 4a86a0a | 2013-11-25 18:01:32 +0000 | [diff] [blame] | 5362 | default: |
| 5363 | break; |
Ander Conselvan de Oliveira | 19d10ef | 2013-02-21 18:35:20 +0200 | [diff] [blame] | 5364 | } |
| 5365 | } |
| 5366 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 5367 | static struct weston_view * |
Pekka Paalanen | 79346ab | 2013-05-22 18:03:09 +0300 | [diff] [blame] | 5368 | shell_fade_create_surface(struct desktop_shell *shell) |
Ander Conselvan de Oliveira | 19d10ef | 2013-02-21 18:35:20 +0200 | [diff] [blame] | 5369 | { |
| 5370 | struct weston_compositor *compositor = shell->compositor; |
| 5371 | struct weston_surface *surface; |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 5372 | struct weston_view *view; |
Pekka Paalanen | 79346ab | 2013-05-22 18:03:09 +0300 | [diff] [blame] | 5373 | |
| 5374 | surface = weston_surface_create(compositor); |
| 5375 | if (!surface) |
| 5376 | return NULL; |
| 5377 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 5378 | view = weston_view_create(surface); |
| 5379 | if (!view) { |
| 5380 | weston_surface_destroy(surface); |
| 5381 | return NULL; |
| 5382 | } |
| 5383 | |
Jason Ekstrand | 5c11a33 | 2013-12-04 20:32:03 -0600 | [diff] [blame] | 5384 | weston_surface_set_size(surface, 8192, 8192); |
Jason Ekstrand | 918f2dd | 2013-12-02 21:01:53 -0600 | [diff] [blame] | 5385 | weston_view_set_position(view, 0, 0); |
Pekka Paalanen | 79346ab | 2013-05-22 18:03:09 +0300 | [diff] [blame] | 5386 | 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] | 5387 | weston_layer_entry_insert(&compositor->fade_layer.view_list, |
| 5388 | &view->layer_link); |
Pekka Paalanen | 79346ab | 2013-05-22 18:03:09 +0300 | [diff] [blame] | 5389 | pixman_region32_init(&surface->input); |
Armin Krezović | 4663aca | 2016-06-30 06:04:29 +0200 | [diff] [blame] | 5390 | surface->is_mapped = true; |
| 5391 | view->is_mapped = true; |
Pekka Paalanen | 79346ab | 2013-05-22 18:03:09 +0300 | [diff] [blame] | 5392 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 5393 | return view; |
Pekka Paalanen | 79346ab | 2013-05-22 18:03:09 +0300 | [diff] [blame] | 5394 | } |
| 5395 | |
| 5396 | static void |
| 5397 | shell_fade(struct desktop_shell *shell, enum fade_type type) |
| 5398 | { |
Ander Conselvan de Oliveira | 19d10ef | 2013-02-21 18:35:20 +0200 | [diff] [blame] | 5399 | float tint; |
| 5400 | |
| 5401 | switch (type) { |
| 5402 | case FADE_IN: |
| 5403 | tint = 0.0; |
| 5404 | break; |
| 5405 | case FADE_OUT: |
| 5406 | tint = 1.0; |
| 5407 | break; |
| 5408 | default: |
| 5409 | weston_log("shell: invalid fade type\n"); |
| 5410 | return; |
| 5411 | } |
| 5412 | |
| 5413 | shell->fade.type = type; |
| 5414 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 5415 | if (shell->fade.view == NULL) { |
| 5416 | shell->fade.view = shell_fade_create_surface(shell); |
| 5417 | if (!shell->fade.view) |
Ander Conselvan de Oliveira | 19d10ef | 2013-02-21 18:35:20 +0200 | [diff] [blame] | 5418 | return; |
| 5419 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 5420 | shell->fade.view->alpha = 1.0 - tint; |
| 5421 | weston_view_update_transform(shell->fade.view); |
Ander Conselvan de Oliveira | 19d10ef | 2013-02-21 18:35:20 +0200 | [diff] [blame] | 5422 | } |
| 5423 | |
Kristian Høgsberg | 87d3b61 | 2014-01-19 21:48:10 -0800 | [diff] [blame] | 5424 | if (shell->fade.view->output == NULL) { |
| 5425 | /* If the black view gets a NULL output, we lost the |
| 5426 | * last output and we'll just cancel the fade. This |
| 5427 | * happens when you close the last window under the |
| 5428 | * X11 or Wayland backends. */ |
| 5429 | shell->locked = false; |
| 5430 | weston_surface_destroy(shell->fade.view->surface); |
| 5431 | shell->fade.view = NULL; |
| 5432 | } else if (shell->fade.animation) { |
Kristian Høgsberg | 5281fb1 | 2013-06-17 10:10:28 -0400 | [diff] [blame] | 5433 | weston_fade_update(shell->fade.animation, tint); |
Kristian Høgsberg | 87d3b61 | 2014-01-19 21:48:10 -0800 | [diff] [blame] | 5434 | } else { |
Ander Conselvan de Oliveira | 19d10ef | 2013-02-21 18:35:20 +0200 | [diff] [blame] | 5435 | shell->fade.animation = |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 5436 | weston_fade_run(shell->fade.view, |
Kristian Høgsberg | 5281fb1 | 2013-06-17 10:10:28 -0400 | [diff] [blame] | 5437 | 1.0 - tint, tint, 300.0, |
Ander Conselvan de Oliveira | 19d10ef | 2013-02-21 18:35:20 +0200 | [diff] [blame] | 5438 | shell_fade_done, shell); |
Kristian Høgsberg | 87d3b61 | 2014-01-19 21:48:10 -0800 | [diff] [blame] | 5439 | } |
Ander Conselvan de Oliveira | 19d10ef | 2013-02-21 18:35:20 +0200 | [diff] [blame] | 5440 | } |
| 5441 | |
| 5442 | static void |
Pekka Paalanen | 79346ab | 2013-05-22 18:03:09 +0300 | [diff] [blame] | 5443 | do_shell_fade_startup(void *data) |
| 5444 | { |
| 5445 | struct desktop_shell *shell = data; |
| 5446 | |
Pekka Paalanen | 23ed5f2 | 2015-05-26 11:54:52 +0300 | [diff] [blame] | 5447 | if (shell->startup_animation_type == ANIMATION_FADE) { |
Kristian Høgsberg | 724c8d9 | 2013-10-16 11:38:24 -0700 | [diff] [blame] | 5448 | shell_fade(shell, FADE_IN); |
Pekka Paalanen | 23ed5f2 | 2015-05-26 11:54:52 +0300 | [diff] [blame] | 5449 | } else { |
| 5450 | weston_log("desktop shell: " |
| 5451 | "unexpected fade-in animation type %d\n", |
| 5452 | shell->startup_animation_type); |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 5453 | weston_surface_destroy(shell->fade.view->surface); |
| 5454 | shell->fade.view = NULL; |
Kristian Høgsberg | 724c8d9 | 2013-10-16 11:38:24 -0700 | [diff] [blame] | 5455 | } |
Pekka Paalanen | 79346ab | 2013-05-22 18:03:09 +0300 | [diff] [blame] | 5456 | } |
| 5457 | |
| 5458 | static void |
| 5459 | shell_fade_startup(struct desktop_shell *shell) |
| 5460 | { |
| 5461 | struct wl_event_loop *loop; |
| 5462 | |
| 5463 | if (!shell->fade.startup_timer) |
| 5464 | return; |
| 5465 | |
| 5466 | wl_event_source_remove(shell->fade.startup_timer); |
| 5467 | shell->fade.startup_timer = NULL; |
| 5468 | |
| 5469 | loop = wl_display_get_event_loop(shell->compositor->wl_display); |
| 5470 | wl_event_loop_add_idle(loop, do_shell_fade_startup, shell); |
| 5471 | } |
| 5472 | |
| 5473 | static int |
| 5474 | fade_startup_timeout(void *data) |
| 5475 | { |
| 5476 | struct desktop_shell *shell = data; |
| 5477 | |
| 5478 | shell_fade_startup(shell); |
| 5479 | return 0; |
| 5480 | } |
| 5481 | |
| 5482 | static void |
| 5483 | shell_fade_init(struct desktop_shell *shell) |
| 5484 | { |
| 5485 | /* Make compositor output all black, and wait for the desktop-shell |
| 5486 | * client to signal it is ready, then fade in. The timer triggers a |
| 5487 | * fade-in, in case the desktop-shell client takes too long. |
| 5488 | */ |
| 5489 | |
| 5490 | struct wl_event_loop *loop; |
| 5491 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 5492 | if (shell->fade.view != NULL) { |
Pekka Paalanen | 79346ab | 2013-05-22 18:03:09 +0300 | [diff] [blame] | 5493 | weston_log("%s: warning: fade surface already exists\n", |
| 5494 | __func__); |
| 5495 | return; |
| 5496 | } |
| 5497 | |
Pekka Paalanen | 23ed5f2 | 2015-05-26 11:54:52 +0300 | [diff] [blame] | 5498 | if (shell->startup_animation_type == ANIMATION_NONE) |
| 5499 | return; |
| 5500 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 5501 | shell->fade.view = shell_fade_create_surface(shell); |
| 5502 | if (!shell->fade.view) |
Pekka Paalanen | 79346ab | 2013-05-22 18:03:09 +0300 | [diff] [blame] | 5503 | return; |
| 5504 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 5505 | weston_view_update_transform(shell->fade.view); |
| 5506 | weston_surface_damage(shell->fade.view->surface); |
Pekka Paalanen | 79346ab | 2013-05-22 18:03:09 +0300 | [diff] [blame] | 5507 | |
| 5508 | loop = wl_display_get_event_loop(shell->compositor->wl_display); |
| 5509 | shell->fade.startup_timer = |
| 5510 | wl_event_loop_add_timer(loop, fade_startup_timeout, shell); |
| 5511 | wl_event_source_timer_update(shell->fade.startup_timer, 15000); |
| 5512 | } |
| 5513 | |
| 5514 | static void |
Ander Conselvan de Oliveira | a457563 | 2013-02-21 18:35:23 +0200 | [diff] [blame] | 5515 | idle_handler(struct wl_listener *listener, void *data) |
Ander Conselvan de Oliveira | 19d10ef | 2013-02-21 18:35:20 +0200 | [diff] [blame] | 5516 | { |
| 5517 | struct desktop_shell *shell = |
Ander Conselvan de Oliveira | a457563 | 2013-02-21 18:35:23 +0200 | [diff] [blame] | 5518 | container_of(listener, struct desktop_shell, idle_listener); |
Kristian Høgsberg | 27d5fa8 | 2014-01-17 16:22:50 -0800 | [diff] [blame] | 5519 | struct weston_seat *seat; |
| 5520 | |
Jonny Lamb | 76cf1fe | 2014-08-20 11:27:10 +0200 | [diff] [blame] | 5521 | wl_list_for_each(seat, &shell->compositor->seat_list, link) { |
Derek Foreman | 1281a36 | 2015-07-31 16:55:32 -0500 | [diff] [blame] | 5522 | struct weston_touch *touch = weston_seat_get_touch(seat); |
| 5523 | struct weston_pointer *pointer = weston_seat_get_pointer(seat); |
| 5524 | |
| 5525 | if (pointer) |
| 5526 | popup_grab_end(pointer); |
| 5527 | if (touch) |
| 5528 | touch_popup_grab_end(touch); |
Jonny Lamb | 76cf1fe | 2014-08-20 11:27:10 +0200 | [diff] [blame] | 5529 | } |
Ander Conselvan de Oliveira | 19d10ef | 2013-02-21 18:35:20 +0200 | [diff] [blame] | 5530 | |
| 5531 | shell_fade(shell, FADE_OUT); |
| 5532 | /* lock() is called from shell_fade_done() */ |
| 5533 | } |
| 5534 | |
| 5535 | static void |
Ander Conselvan de Oliveira | a457563 | 2013-02-21 18:35:23 +0200 | [diff] [blame] | 5536 | wake_handler(struct wl_listener *listener, void *data) |
Ander Conselvan de Oliveira | 19d10ef | 2013-02-21 18:35:20 +0200 | [diff] [blame] | 5537 | { |
| 5538 | struct desktop_shell *shell = |
Ander Conselvan de Oliveira | a457563 | 2013-02-21 18:35:23 +0200 | [diff] [blame] | 5539 | container_of(listener, struct desktop_shell, wake_listener); |
Ander Conselvan de Oliveira | 19d10ef | 2013-02-21 18:35:20 +0200 | [diff] [blame] | 5540 | |
Ander Conselvan de Oliveira | 19d10ef | 2013-02-21 18:35:20 +0200 | [diff] [blame] | 5541 | unlock(shell); |
| 5542 | } |
| 5543 | |
| 5544 | static void |
Giulio Camuffo | f05d18f | 2015-12-11 20:57:05 +0200 | [diff] [blame] | 5545 | transform_handler(struct wl_listener *listener, void *data) |
| 5546 | { |
| 5547 | struct weston_surface *surface = data; |
| 5548 | struct shell_surface *shsurf = get_shell_surface(surface); |
| 5549 | struct weston_view *view;; |
| 5550 | int x, y; |
| 5551 | |
| 5552 | if (!shsurf || !shsurf->client->send_position) |
| 5553 | return; |
| 5554 | |
| 5555 | view = shsurf->view; |
| 5556 | if (!view || !weston_view_is_mapped(view)) |
| 5557 | return; |
| 5558 | |
| 5559 | x = view->geometry.x; |
| 5560 | y = view->geometry.y; |
| 5561 | |
| 5562 | shsurf->client->send_position(surface, x, y); |
| 5563 | } |
| 5564 | |
| 5565 | static void |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 5566 | center_on_output(struct weston_view *view, struct weston_output *output) |
Pekka Paalanen | 77346a6 | 2011-11-30 16:26:35 +0200 | [diff] [blame] | 5567 | { |
Giulio Camuffo | b836664 | 2013-04-25 13:57:46 +0300 | [diff] [blame] | 5568 | int32_t surf_x, surf_y, width, height; |
Ander Conselvan de Oliveira | 012b4c7 | 2012-11-27 17:03:42 +0200 | [diff] [blame] | 5569 | float x, y; |
Pekka Paalanen | 77346a6 | 2011-11-30 16:26:35 +0200 | [diff] [blame] | 5570 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 5571 | surface_subsurfaces_boundingbox(view->surface, &surf_x, &surf_y, &width, &height); |
Giulio Camuffo | b836664 | 2013-04-25 13:57:46 +0300 | [diff] [blame] | 5572 | |
| 5573 | x = output->x + (output->width - width) / 2 - surf_x / 2; |
| 5574 | y = output->y + (output->height - height) / 2 - surf_y / 2; |
Ander Conselvan de Oliveira | 012b4c7 | 2012-11-27 17:03:42 +0200 | [diff] [blame] | 5575 | |
Jason Ekstrand | 918f2dd | 2013-12-02 21:01:53 -0600 | [diff] [blame] | 5576 | weston_view_set_position(view, x, y); |
Pekka Paalanen | 77346a6 | 2011-11-30 16:26:35 +0200 | [diff] [blame] | 5577 | } |
| 5578 | |
| 5579 | static void |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 5580 | weston_view_set_initial_position(struct weston_view *view, |
| 5581 | struct desktop_shell *shell) |
Rob Bradford | ac63e5b | 2012-08-13 14:07:52 +0100 | [diff] [blame] | 5582 | { |
| 5583 | struct weston_compositor *compositor = shell->compositor; |
| 5584 | int ix = 0, iy = 0; |
Jonny Lamb | d73c694 | 2014-08-20 15:53:20 +0200 | [diff] [blame] | 5585 | int32_t range_x, range_y; |
Derek Foreman | f814c5d | 2015-04-15 12:23:54 -0500 | [diff] [blame] | 5586 | int32_t x, y; |
Rob Bradford | ac63e5b | 2012-08-13 14:07:52 +0100 | [diff] [blame] | 5587 | struct weston_output *output, *target_output = NULL; |
| 5588 | struct weston_seat *seat; |
Jonny Lamb | d73c694 | 2014-08-20 15:53:20 +0200 | [diff] [blame] | 5589 | pixman_rectangle32_t area; |
Rob Bradford | ac63e5b | 2012-08-13 14:07:52 +0100 | [diff] [blame] | 5590 | |
| 5591 | /* As a heuristic place the new window on the same output as the |
| 5592 | * pointer. Falling back to the output containing 0, 0. |
| 5593 | * |
| 5594 | * TODO: Do something clever for touch too? |
| 5595 | */ |
| 5596 | wl_list_for_each(seat, &compositor->seat_list, link) { |
Derek Foreman | 1281a36 | 2015-07-31 16:55:32 -0500 | [diff] [blame] | 5597 | struct weston_pointer *pointer = weston_seat_get_pointer(seat); |
| 5598 | |
| 5599 | if (pointer) { |
| 5600 | ix = wl_fixed_to_int(pointer->x); |
| 5601 | iy = wl_fixed_to_int(pointer->y); |
Rob Bradford | ac63e5b | 2012-08-13 14:07:52 +0100 | [diff] [blame] | 5602 | break; |
| 5603 | } |
| 5604 | } |
| 5605 | |
| 5606 | wl_list_for_each(output, &compositor->output_list, link) { |
| 5607 | if (pixman_region32_contains_point(&output->region, ix, iy, NULL)) { |
| 5608 | target_output = output; |
| 5609 | break; |
| 5610 | } |
| 5611 | } |
| 5612 | |
| 5613 | if (!target_output) { |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 5614 | weston_view_set_position(view, 10 + random() % 400, |
| 5615 | 10 + random() % 400); |
Rob Bradford | ac63e5b | 2012-08-13 14:07:52 +0100 | [diff] [blame] | 5616 | return; |
| 5617 | } |
| 5618 | |
| 5619 | /* Valid range within output where the surface will still be onscreen. |
| 5620 | * If this is negative it means that the surface is bigger than |
| 5621 | * output. |
| 5622 | */ |
Jonny Lamb | d73c694 | 2014-08-20 15:53:20 +0200 | [diff] [blame] | 5623 | get_output_work_area(shell, target_output, &area); |
| 5624 | |
Derek Foreman | f814c5d | 2015-04-15 12:23:54 -0500 | [diff] [blame] | 5625 | x = area.x; |
| 5626 | y = area.y; |
Jonny Lamb | d73c694 | 2014-08-20 15:53:20 +0200 | [diff] [blame] | 5627 | range_x = area.width - view->surface->width; |
| 5628 | range_y = area.height - view->surface->height; |
Rob Bradford | ac63e5b | 2012-08-13 14:07:52 +0100 | [diff] [blame] | 5629 | |
Rob Bradford | 4cb88c7 | 2012-08-13 15:18:44 +0100 | [diff] [blame] | 5630 | if (range_x > 0) |
Derek Foreman | f814c5d | 2015-04-15 12:23:54 -0500 | [diff] [blame] | 5631 | x += random() % range_x; |
Rob Bradford | 4cb88c7 | 2012-08-13 15:18:44 +0100 | [diff] [blame] | 5632 | |
| 5633 | if (range_y > 0) |
Derek Foreman | f814c5d | 2015-04-15 12:23:54 -0500 | [diff] [blame] | 5634 | y += random() % range_y; |
Rob Bradford | ac63e5b | 2012-08-13 14:07:52 +0100 | [diff] [blame] | 5635 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 5636 | weston_view_set_position(view, x, y); |
Rob Bradford | ac63e5b | 2012-08-13 14:07:52 +0100 | [diff] [blame] | 5637 | } |
| 5638 | |
| 5639 | static void |
Jonny Lamb | d73c694 | 2014-08-20 15:53:20 +0200 | [diff] [blame] | 5640 | set_maximized_position(struct desktop_shell *shell, |
| 5641 | struct shell_surface *shsurf) |
| 5642 | { |
| 5643 | int32_t surf_x, surf_y; |
| 5644 | pixman_rectangle32_t area; |
| 5645 | |
Jonny Lamb | d73c694 | 2014-08-20 15:53:20 +0200 | [diff] [blame] | 5646 | get_output_work_area(shell, shsurf->output, &area); |
Giulio Camuffo | 7a8d67d | 2015-01-09 20:10:45 +0200 | [diff] [blame] | 5647 | if (shsurf->has_set_geometry) { |
| 5648 | surf_x = shsurf->geometry.x; |
| 5649 | surf_y = shsurf->geometry.y; |
| 5650 | } else { |
| 5651 | surface_subsurfaces_boundingbox(shsurf->surface, |
| 5652 | &surf_x, &surf_y, NULL, NULL); |
| 5653 | } |
Jonny Lamb | d73c694 | 2014-08-20 15:53:20 +0200 | [diff] [blame] | 5654 | |
| 5655 | weston_view_set_position(shsurf->view, |
Marek Chalupa | 6ce7899 | 2015-10-09 18:17:07 +0200 | [diff] [blame] | 5656 | area.x - surf_x, |
| 5657 | area.y - surf_y); |
Jonny Lamb | d73c694 | 2014-08-20 15:53:20 +0200 | [diff] [blame] | 5658 | } |
| 5659 | |
| 5660 | static void |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 5661 | map(struct desktop_shell *shell, struct shell_surface *shsurf, |
Jason Ekstrand | 918f2dd | 2013-12-02 21:01:53 -0600 | [diff] [blame] | 5662 | int32_t sx, int32_t sy) |
Kristian Høgsberg | 02ec0a5 | 2011-04-23 13:04:11 -0400 | [diff] [blame] | 5663 | { |
Kristian Høgsberg | 8334bc1 | 2012-01-03 10:29:47 -0500 | [diff] [blame] | 5664 | struct weston_compositor *compositor = shell->compositor; |
Daniel Stone | b210468 | 2012-05-30 16:31:56 +0100 | [diff] [blame] | 5665 | struct weston_seat *seat; |
Pekka Paalanen | 57da4a8 | 2011-11-23 16:42:16 +0200 | [diff] [blame] | 5666 | |
Pekka Paalanen | 77346a6 | 2011-11-30 16:26:35 +0200 | [diff] [blame] | 5667 | /* initial positioning, see also configure() */ |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 5668 | switch (shsurf->type) { |
Rafael Antognolli | ed207b4 | 2013-12-03 15:35:43 -0200 | [diff] [blame] | 5669 | case SHELL_SURFACE_TOPLEVEL: |
Rafael Antognolli | 03b1659 | 2013-12-03 15:35:42 -0200 | [diff] [blame] | 5670 | if (shsurf->state.fullscreen) { |
| 5671 | center_on_output(shsurf->view, shsurf->fullscreen_output); |
| 5672 | shell_map_fullscreen(shsurf); |
| 5673 | } else if (shsurf->state.maximized) { |
Jonny Lamb | d73c694 | 2014-08-20 15:53:20 +0200 | [diff] [blame] | 5674 | set_maximized_position(shell, shsurf); |
Rafael Antognolli | ed207b4 | 2013-12-03 15:35:43 -0200 | [diff] [blame] | 5675 | } else if (!shsurf->state.relative) { |
Rafael Antognolli | 03b1659 | 2013-12-03 15:35:42 -0200 | [diff] [blame] | 5676 | weston_view_set_initial_position(shsurf->view, shell); |
| 5677 | } |
Juan Zhao | 96879df | 2012-02-07 08:45:41 +0800 | [diff] [blame] | 5678 | break; |
Tiago Vignatti | 0f99701 | 2012-02-10 16:17:23 +0200 | [diff] [blame] | 5679 | case SHELL_SURFACE_POPUP: |
Jasper St. Pierre | da6ecd0 | 2015-02-27 18:35:45 +0800 | [diff] [blame] | 5680 | if (shell_map_popup(shsurf) != 0) |
| 5681 | return; |
Rob Bradford | db99938 | 2012-12-06 12:07:48 +0000 | [diff] [blame] | 5682 | break; |
Ander Conselvan de Oliveira | e9e0515 | 2012-02-15 17:02:56 +0200 | [diff] [blame] | 5683 | case SHELL_SURFACE_NONE: |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 5684 | weston_view_set_position(shsurf->view, |
| 5685 | shsurf->view->geometry.x + sx, |
| 5686 | shsurf->view->geometry.y + sy); |
Tiago Vignatti | 0f99701 | 2012-02-10 16:17:23 +0200 | [diff] [blame] | 5687 | break; |
Philip Withnall | 0f640e2 | 2013-11-25 18:01:31 +0000 | [diff] [blame] | 5688 | case SHELL_SURFACE_XWAYLAND: |
Pekka Paalanen | 77346a6 | 2011-11-30 16:26:35 +0200 | [diff] [blame] | 5689 | default: |
| 5690 | ; |
| 5691 | } |
Kristian Høgsberg | 7584062 | 2011-09-06 13:48:16 -0400 | [diff] [blame] | 5692 | |
Philip Withnall | e1d75ae | 2013-11-25 18:01:41 +0000 | [diff] [blame] | 5693 | /* Surface stacking order, see also activate(). */ |
| 5694 | shell_surface_update_layer(shsurf); |
Pekka Paalanen | f0fc70d | 2011-11-15 13:34:54 +0200 | [diff] [blame] | 5695 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 5696 | if (shsurf->type != SHELL_SURFACE_NONE) { |
| 5697 | weston_view_update_transform(shsurf->view); |
Armin Krezović | 4663aca | 2016-06-30 06:04:29 +0200 | [diff] [blame] | 5698 | shsurf->view->is_mapped = true; |
Rafael Antognolli | 03b1659 | 2013-12-03 15:35:42 -0200 | [diff] [blame] | 5699 | if (shsurf->state.maximized) { |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 5700 | shsurf->surface->output = shsurf->output; |
| 5701 | shsurf->view->output = shsurf->output; |
| 5702 | } |
Ander Conselvan de Oliveira | de56c31 | 2012-03-05 15:39:23 +0200 | [diff] [blame] | 5703 | } |
Kristian Høgsberg | 2f88a40 | 2011-12-04 15:32:59 -0500 | [diff] [blame] | 5704 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 5705 | switch (shsurf->type) { |
Tiago Vignatti | fb2adba | 2013-06-12 15:43:21 -0300 | [diff] [blame] | 5706 | /* XXX: xwayland's using the same fields for transient type */ |
| 5707 | case SHELL_SURFACE_XWAYLAND: |
Tiago Vignatti | 99aeb1e | 2012-05-23 22:06:26 +0300 | [diff] [blame] | 5708 | if (shsurf->transient.flags == |
| 5709 | WL_SHELL_SURFACE_TRANSIENT_INACTIVE) |
| 5710 | break; |
| 5711 | case SHELL_SURFACE_TOPLEVEL: |
Rafael Antognolli | ed207b4 | 2013-12-03 15:35:43 -0200 | [diff] [blame] | 5712 | if (shsurf->state.relative && |
| 5713 | shsurf->transient.flags == WL_SHELL_SURFACE_TRANSIENT_INACTIVE) |
| 5714 | break; |
Rafael Antognolli | ba5d2d7 | 2013-12-04 17:49:55 -0200 | [diff] [blame] | 5715 | if (shell->locked) |
Rafael Antognolli | ed207b4 | 2013-12-03 15:35:43 -0200 | [diff] [blame] | 5716 | break; |
| 5717 | wl_list_for_each(seat, &compositor->seat_list, link) |
Jonas Ådahl | 1fa6ded | 2014-10-18 13:24:53 +0200 | [diff] [blame^] | 5718 | activate(shell, shsurf->view, seat, true); |
Juan Zhao | 7bb92f0 | 2011-12-15 11:31:51 -0500 | [diff] [blame] | 5719 | break; |
Philip Withnall | 0f640e2 | 2013-11-25 18:01:31 +0000 | [diff] [blame] | 5720 | case SHELL_SURFACE_POPUP: |
| 5721 | case SHELL_SURFACE_NONE: |
Juan Zhao | 7bb92f0 | 2011-12-15 11:31:51 -0500 | [diff] [blame] | 5722 | default: |
| 5723 | break; |
| 5724 | } |
| 5725 | |
Rafael Antognolli | 03b1659 | 2013-12-03 15:35:42 -0200 | [diff] [blame] | 5726 | if (shsurf->type == SHELL_SURFACE_TOPLEVEL && |
| 5727 | !shsurf->state.maximized && !shsurf->state.fullscreen) |
Juan Zhao | e10d279 | 2012-04-25 19:09:52 +0800 | [diff] [blame] | 5728 | { |
| 5729 | switch (shell->win_animation_type) { |
| 5730 | case ANIMATION_FADE: |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 5731 | 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] | 5732 | break; |
| 5733 | case ANIMATION_ZOOM: |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 5734 | weston_zoom_run(shsurf->view, 0.5, 1.0, NULL, NULL); |
Juan Zhao | e10d279 | 2012-04-25 19:09:52 +0800 | [diff] [blame] | 5735 | break; |
Philip Withnall | 4a86a0a | 2013-11-25 18:01:32 +0000 | [diff] [blame] | 5736 | case ANIMATION_NONE: |
Juan Zhao | e10d279 | 2012-04-25 19:09:52 +0800 | [diff] [blame] | 5737 | default: |
| 5738 | break; |
| 5739 | } |
| 5740 | } |
Kristian Høgsberg | 32e24cc | 2011-11-09 12:07:35 -0500 | [diff] [blame] | 5741 | } |
| 5742 | |
| 5743 | static void |
Tiago Vignatti | be14326 | 2012-04-16 17:31:41 +0300 | [diff] [blame] | 5744 | configure(struct desktop_shell *shell, struct weston_surface *surface, |
Jason Ekstrand | 918f2dd | 2013-12-02 21:01:53 -0600 | [diff] [blame] | 5745 | float x, float y) |
Kristian Høgsberg | 32e24cc | 2011-11-09 12:07:35 -0500 | [diff] [blame] | 5746 | { |
Pekka Paalanen | 77346a6 | 2011-11-30 16:26:35 +0200 | [diff] [blame] | 5747 | struct shell_surface *shsurf; |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 5748 | struct weston_view *view; |
Kristian Høgsberg | 32e24cc | 2011-11-09 12:07:35 -0500 | [diff] [blame] | 5749 | |
Pekka Paalanen | 77346a6 | 2011-11-30 16:26:35 +0200 | [diff] [blame] | 5750 | shsurf = get_shell_surface(surface); |
Pekka Paalanen | 77346a6 | 2011-11-30 16:26:35 +0200 | [diff] [blame] | 5751 | |
U. Artie Eoff | cf5737a | 2014-01-17 10:08:25 -0800 | [diff] [blame] | 5752 | assert(shsurf); |
| 5753 | |
Rafael Antognolli | 03b1659 | 2013-12-03 15:35:42 -0200 | [diff] [blame] | 5754 | if (shsurf->state.fullscreen) |
Alex Wu | 4539b08 | 2012-03-01 12:57:46 +0800 | [diff] [blame] | 5755 | shell_configure_fullscreen(shsurf); |
Rafael Antognolli | 03b1659 | 2013-12-03 15:35:42 -0200 | [diff] [blame] | 5756 | else if (shsurf->state.maximized) { |
Jonny Lamb | d73c694 | 2014-08-20 15:53:20 +0200 | [diff] [blame] | 5757 | set_maximized_position(shell, shsurf); |
Rafael Antognolli | 03b1659 | 2013-12-03 15:35:42 -0200 | [diff] [blame] | 5758 | } else { |
Jason Ekstrand | 918f2dd | 2013-12-02 21:01:53 -0600 | [diff] [blame] | 5759 | weston_view_set_position(shsurf->view, x, y); |
Kristian Høgsberg | 7a5c979 | 2011-06-18 06:12:54 -0400 | [diff] [blame] | 5760 | } |
Kristian Høgsberg | 32e24cc | 2011-11-09 12:07:35 -0500 | [diff] [blame] | 5761 | |
Alex Wu | 4539b08 | 2012-03-01 12:57:46 +0800 | [diff] [blame] | 5762 | /* XXX: would a fullscreen surface need the same handling? */ |
Kristian Høgsberg | 6a8b553 | 2012-02-16 23:43:59 -0500 | [diff] [blame] | 5763 | if (surface->output) { |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 5764 | wl_list_for_each(view, &surface->views, surface_link) |
| 5765 | weston_view_update_transform(view); |
Pekka Paalanen | 77346a6 | 2011-11-30 16:26:35 +0200 | [diff] [blame] | 5766 | |
Rafael Antognolli | 03b1659 | 2013-12-03 15:35:42 -0200 | [diff] [blame] | 5767 | if (shsurf->state.maximized) |
Juan Zhao | 96879df | 2012-02-07 08:45:41 +0800 | [diff] [blame] | 5768 | surface->output = shsurf->output; |
Pekka Paalanen | 77346a6 | 2011-11-30 16:26:35 +0200 | [diff] [blame] | 5769 | } |
Kristian Høgsberg | 0793756 | 2011-04-12 17:25:42 -0400 | [diff] [blame] | 5770 | } |
| 5771 | |
Ander Conselvan de Oliveira | 093bfa3 | 2012-03-27 17:36:41 +0300 | [diff] [blame] | 5772 | static void |
Jason Ekstrand | 918f2dd | 2013-12-02 21:01:53 -0600 | [diff] [blame] | 5773 | 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] | 5774 | { |
Ander Conselvan de Oliveira | 7fb9f95 | 2012-03-27 17:36:42 +0300 | [diff] [blame] | 5775 | struct shell_surface *shsurf = get_shell_surface(es); |
U. Artie Eoff | cf5737a | 2014-01-17 10:08:25 -0800 | [diff] [blame] | 5776 | struct desktop_shell *shell; |
Tiago Vignatti | 70e5c9c | 2012-05-07 15:23:07 +0300 | [diff] [blame] | 5777 | int type_changed = 0; |
Ander Conselvan de Oliveira | 093bfa3 | 2012-03-27 17:36:41 +0300 | [diff] [blame] | 5778 | |
U. Artie Eoff | cf5737a | 2014-01-17 10:08:25 -0800 | [diff] [blame] | 5779 | assert(shsurf); |
| 5780 | |
| 5781 | shell = shsurf->shell; |
| 5782 | |
Kristian Høgsberg | 8eb0f4f | 2013-06-17 10:33:14 -0400 | [diff] [blame] | 5783 | if (!weston_surface_is_mapped(es) && |
| 5784 | !wl_list_empty(&shsurf->popup.grab_link)) { |
Giulio Camuffo | 5085a75 | 2013-03-25 21:42:45 +0100 | [diff] [blame] | 5785 | remove_popup_grab(shsurf); |
| 5786 | } |
| 5787 | |
Jason Ekstrand | 918f2dd | 2013-12-02 21:01:53 -0600 | [diff] [blame] | 5788 | if (es->width == 0) |
Giulio Camuffo | 184df50 | 2013-02-21 11:29:21 +0100 | [diff] [blame] | 5789 | return; |
| 5790 | |
Jasper St. Pierre | ccf48fb | 2014-05-02 10:21:38 -0400 | [diff] [blame] | 5791 | if (shsurf->has_next_geometry) { |
| 5792 | shsurf->geometry = shsurf->next_geometry; |
| 5793 | shsurf->has_next_geometry = false; |
| 5794 | shsurf->has_set_geometry = true; |
| 5795 | } else if (!shsurf->has_set_geometry) { |
| 5796 | surface_subsurfaces_boundingbox(shsurf->surface, |
| 5797 | &shsurf->geometry.x, |
| 5798 | &shsurf->geometry.y, |
| 5799 | &shsurf->geometry.width, |
| 5800 | &shsurf->geometry.height); |
Jasper St. Pierre | 851799e | 2014-05-02 10:14:07 -0400 | [diff] [blame] | 5801 | } |
| 5802 | |
Kristian Høgsberg | c8f8dd8 | 2013-12-05 23:20:33 -0800 | [diff] [blame] | 5803 | if (shsurf->state_changed) { |
Kristian Høgsberg | 7f366e7 | 2012-04-27 17:20:01 -0400 | [diff] [blame] | 5804 | set_surface_type(shsurf); |
Kristian Høgsberg | f7e23d5 | 2012-04-27 17:51:59 -0400 | [diff] [blame] | 5805 | type_changed = 1; |
| 5806 | } |
Kristian Høgsberg | 7f366e7 | 2012-04-27 17:20:01 -0400 | [diff] [blame] | 5807 | |
Ander Conselvan de Oliveira | 093bfa3 | 2012-03-27 17:36:41 +0300 | [diff] [blame] | 5808 | if (!weston_surface_is_mapped(es)) { |
Jason Ekstrand | 918f2dd | 2013-12-02 21:01:53 -0600 | [diff] [blame] | 5809 | map(shell, shsurf, sx, sy); |
Armin Krezović | 4663aca | 2016-06-30 06:04:29 +0200 | [diff] [blame] | 5810 | es->is_mapped = true; |
Kristian Høgsberg | f7e23d5 | 2012-04-27 17:51:59 -0400 | [diff] [blame] | 5811 | } else if (type_changed || sx != 0 || sy != 0 || |
Jason Ekstrand | 918f2dd | 2013-12-02 21:01:53 -0600 | [diff] [blame] | 5812 | shsurf->last_width != es->width || |
| 5813 | shsurf->last_height != es->height) { |
John Kåre Alsaker | 490d02a | 2012-09-30 02:57:21 +0200 | [diff] [blame] | 5814 | float from_x, from_y; |
| 5815 | float to_x, to_y; |
Ander Conselvan de Oliveira | 093bfa3 | 2012-03-27 17:36:41 +0300 | [diff] [blame] | 5816 | |
Kristian Høgsberg | 44cd196 | 2014-02-05 21:36:04 -0800 | [diff] [blame] | 5817 | if (shsurf->resize_edges) { |
| 5818 | sx = 0; |
| 5819 | sy = 0; |
| 5820 | } |
| 5821 | |
| 5822 | if (shsurf->resize_edges & WL_SHELL_SURFACE_RESIZE_LEFT) |
| 5823 | sx = shsurf->last_width - es->width; |
| 5824 | if (shsurf->resize_edges & WL_SHELL_SURFACE_RESIZE_TOP) |
| 5825 | sy = shsurf->last_height - es->height; |
| 5826 | |
| 5827 | shsurf->last_width = es->width; |
| 5828 | shsurf->last_height = es->height; |
| 5829 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 5830 | weston_view_to_global_float(shsurf->view, 0, 0, &from_x, &from_y); |
| 5831 | 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] | 5832 | configure(shell, es, |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 5833 | shsurf->view->geometry.x + to_x - from_x, |
Jason Ekstrand | 918f2dd | 2013-12-02 21:01:53 -0600 | [diff] [blame] | 5834 | shsurf->view->geometry.y + to_y - from_y); |
Ander Conselvan de Oliveira | 093bfa3 | 2012-03-27 17:36:41 +0300 | [diff] [blame] | 5835 | } |
| 5836 | } |
| 5837 | |
Pekka Paalanen | 2e62e4a | 2014-08-28 11:41:26 +0300 | [diff] [blame] | 5838 | static bool |
| 5839 | check_desktop_shell_crash_too_early(struct desktop_shell *shell) |
| 5840 | { |
| 5841 | struct timespec now; |
| 5842 | |
| 5843 | if (clock_gettime(CLOCK_MONOTONIC, &now) < 0) |
| 5844 | return false; |
| 5845 | |
| 5846 | /* |
| 5847 | * If the shell helper client dies before the session has been |
| 5848 | * up for roughly 30 seconds, better just make Weston shut down, |
| 5849 | * because the user likely has no way to interact with the desktop |
| 5850 | * anyway. |
| 5851 | */ |
| 5852 | if (now.tv_sec - shell->startup_time.tv_sec < 30) { |
| 5853 | weston_log("Error: %s apparently cannot run at all.\n", |
| 5854 | shell->client); |
| 5855 | weston_log_continue(STAMP_SPACE "Quitting..."); |
| 5856 | wl_display_terminate(shell->compositor->wl_display); |
| 5857 | |
| 5858 | return true; |
| 5859 | } |
| 5860 | |
| 5861 | return false; |
| 5862 | } |
| 5863 | |
Tiago Vignatti | b7dbbd6 | 2012-09-25 17:57:01 +0300 | [diff] [blame] | 5864 | static void launch_desktop_shell_process(void *data); |
Pekka Paalanen | 4d733ee | 2012-01-17 14:36:27 +0200 | [diff] [blame] | 5865 | |
Kristian Høgsberg | 97d44aa | 2011-08-26 17:21:20 -0400 | [diff] [blame] | 5866 | static void |
Pekka Paalanen | 826dc14 | 2014-08-27 12:11:53 +0300 | [diff] [blame] | 5867 | respawn_desktop_shell_process(struct desktop_shell *shell) |
Pekka Paalanen | 6cd281a | 2011-11-03 14:11:32 +0200 | [diff] [blame] | 5868 | { |
Pekka Paalanen | 4d733ee | 2012-01-17 14:36:27 +0200 | [diff] [blame] | 5869 | uint32_t time; |
Pekka Paalanen | 4d733ee | 2012-01-17 14:36:27 +0200 | [diff] [blame] | 5870 | |
| 5871 | /* if desktop-shell dies more than 5 times in 30 seconds, give up */ |
| 5872 | time = weston_compositor_get_time(); |
Kristian Høgsberg | f03a616 | 2012-01-17 11:07:42 -0500 | [diff] [blame] | 5873 | if (time - shell->child.deathstamp > 30000) { |
Pekka Paalanen | 4d733ee | 2012-01-17 14:36:27 +0200 | [diff] [blame] | 5874 | shell->child.deathstamp = time; |
| 5875 | shell->child.deathcount = 0; |
| 5876 | } |
| 5877 | |
| 5878 | shell->child.deathcount++; |
| 5879 | if (shell->child.deathcount > 5) { |
Pekka Paalanen | 826dc14 | 2014-08-27 12:11:53 +0300 | [diff] [blame] | 5880 | weston_log("%s disconnected, giving up.\n", shell->client); |
Pekka Paalanen | 4d733ee | 2012-01-17 14:36:27 +0200 | [diff] [blame] | 5881 | return; |
| 5882 | } |
| 5883 | |
Pekka Paalanen | 826dc14 | 2014-08-27 12:11:53 +0300 | [diff] [blame] | 5884 | weston_log("%s disconnected, respawning...\n", shell->client); |
Pekka Paalanen | 4d733ee | 2012-01-17 14:36:27 +0200 | [diff] [blame] | 5885 | launch_desktop_shell_process(shell); |
Pekka Paalanen | 6cd281a | 2011-11-03 14:11:32 +0200 | [diff] [blame] | 5886 | } |
| 5887 | |
Tiago Vignatti | b7dbbd6 | 2012-09-25 17:57:01 +0300 | [diff] [blame] | 5888 | static void |
Ander Conselvan de Oliveira | 312ea4c | 2013-12-20 21:07:01 +0200 | [diff] [blame] | 5889 | desktop_shell_client_destroy(struct wl_listener *listener, void *data) |
| 5890 | { |
| 5891 | struct desktop_shell *shell; |
| 5892 | |
| 5893 | shell = container_of(listener, struct desktop_shell, |
| 5894 | child.client_destroy_listener); |
| 5895 | |
Pekka Paalanen | 826dc14 | 2014-08-27 12:11:53 +0300 | [diff] [blame] | 5896 | wl_list_remove(&shell->child.client_destroy_listener.link); |
Ander Conselvan de Oliveira | 312ea4c | 2013-12-20 21:07:01 +0200 | [diff] [blame] | 5897 | shell->child.client = NULL; |
Pekka Paalanen | 826dc14 | 2014-08-27 12:11:53 +0300 | [diff] [blame] | 5898 | /* |
| 5899 | * unbind_desktop_shell() will reset shell->child.desktop_shell |
| 5900 | * before the respawned process has a chance to create a new |
| 5901 | * desktop_shell object, because we are being called from the |
| 5902 | * wl_client destructor which destroys all wl_resources before |
| 5903 | * returning. |
| 5904 | */ |
| 5905 | |
Pekka Paalanen | 2e62e4a | 2014-08-28 11:41:26 +0300 | [diff] [blame] | 5906 | if (!check_desktop_shell_crash_too_early(shell)) |
| 5907 | respawn_desktop_shell_process(shell); |
| 5908 | |
Pekka Paalanen | 826dc14 | 2014-08-27 12:11:53 +0300 | [diff] [blame] | 5909 | shell_fade_startup(shell); |
Ander Conselvan de Oliveira | 312ea4c | 2013-12-20 21:07:01 +0200 | [diff] [blame] | 5910 | } |
| 5911 | |
| 5912 | static void |
Tiago Vignatti | b7dbbd6 | 2012-09-25 17:57:01 +0300 | [diff] [blame] | 5913 | launch_desktop_shell_process(void *data) |
Pekka Paalanen | 6cd281a | 2011-11-03 14:11:32 +0200 | [diff] [blame] | 5914 | { |
Tiago Vignatti | b7dbbd6 | 2012-09-25 17:57:01 +0300 | [diff] [blame] | 5915 | struct desktop_shell *shell = data; |
Pekka Paalanen | 6cd281a | 2011-11-03 14:11:32 +0200 | [diff] [blame] | 5916 | |
Pekka Paalanen | 826dc14 | 2014-08-27 12:11:53 +0300 | [diff] [blame] | 5917 | shell->child.client = weston_client_start(shell->compositor, |
| 5918 | shell->client); |
Pekka Paalanen | 409ef0a | 2011-12-02 15:30:21 +0200 | [diff] [blame] | 5919 | |
Arnaud Vrac | 4263119 | 2014-08-25 20:56:46 +0200 | [diff] [blame] | 5920 | if (!shell->child.client) { |
Emilio Pozuelo Monfort | 46ce798 | 2013-11-20 13:22:29 +0100 | [diff] [blame] | 5921 | weston_log("not able to start %s\n", shell->client); |
Arnaud Vrac | 4263119 | 2014-08-25 20:56:46 +0200 | [diff] [blame] | 5922 | return; |
| 5923 | } |
Ander Conselvan de Oliveira | 312ea4c | 2013-12-20 21:07:01 +0200 | [diff] [blame] | 5924 | |
| 5925 | shell->child.client_destroy_listener.notify = |
| 5926 | desktop_shell_client_destroy; |
| 5927 | wl_client_add_destroy_listener(shell->child.client, |
| 5928 | &shell->child.client_destroy_listener); |
Pekka Paalanen | 6cd281a | 2011-11-03 14:11:32 +0200 | [diff] [blame] | 5929 | } |
| 5930 | |
| 5931 | static void |
Kristian Høgsberg | 2bff94e | 2014-02-11 12:22:51 -0800 | [diff] [blame] | 5932 | handle_shell_client_destroy(struct wl_listener *listener, void *data) |
| 5933 | { |
| 5934 | struct shell_client *sc = |
| 5935 | container_of(listener, struct shell_client, destroy_listener); |
Jonas Ådahl | d3a3ee9 | 2016-02-26 14:02:06 +0800 | [diff] [blame] | 5936 | struct wl_resource *shsurf_resource; |
| 5937 | struct shell_surface *shsurf; |
Kristian Høgsberg | 2bff94e | 2014-02-11 12:22:51 -0800 | [diff] [blame] | 5938 | |
| 5939 | if (sc->ping_timer) |
| 5940 | wl_event_source_remove(sc->ping_timer); |
Derek Foreman | e42d754 | 2015-05-29 10:46:44 -0500 | [diff] [blame] | 5941 | |
| 5942 | /* Since we're about to free shell_client, we remove it from the |
| 5943 | * head of the surface list so we don't use that freed list node |
| 5944 | * during surface clean up later on. |
| 5945 | */ |
Jonas Ådahl | d3a3ee9 | 2016-02-26 14:02:06 +0800 | [diff] [blame] | 5946 | wl_resource_for_each(shsurf_resource, &sc->surface_list) { |
| 5947 | shsurf = wl_resource_get_user_data(shsurf_resource); |
| 5948 | shsurf->owner = NULL; |
| 5949 | } |
Derek Foreman | e42d754 | 2015-05-29 10:46:44 -0500 | [diff] [blame] | 5950 | wl_list_remove(&sc->surface_list); |
| 5951 | |
Kristian Høgsberg | 2bff94e | 2014-02-11 12:22:51 -0800 | [diff] [blame] | 5952 | free(sc); |
| 5953 | } |
| 5954 | |
Kristian Høgsberg | dd62aba | 2014-02-12 09:56:19 -0800 | [diff] [blame] | 5955 | static struct shell_client * |
| 5956 | shell_client_create(struct wl_client *client, struct desktop_shell *shell, |
| 5957 | const struct wl_interface *interface, uint32_t id) |
Rafael Antognolli | e2a3455 | 2013-12-03 15:35:45 -0200 | [diff] [blame] | 5958 | { |
Kristian Høgsberg | 2bff94e | 2014-02-11 12:22:51 -0800 | [diff] [blame] | 5959 | struct shell_client *sc; |
Rafael Antognolli | e2a3455 | 2013-12-03 15:35:45 -0200 | [diff] [blame] | 5960 | |
Kristian Høgsberg | 2bff94e | 2014-02-11 12:22:51 -0800 | [diff] [blame] | 5961 | sc = zalloc(sizeof *sc); |
| 5962 | if (sc == NULL) { |
| 5963 | wl_client_post_no_memory(client); |
Kristian Høgsberg | dd62aba | 2014-02-12 09:56:19 -0800 | [diff] [blame] | 5964 | return NULL; |
Kristian Høgsberg | 2bff94e | 2014-02-11 12:22:51 -0800 | [diff] [blame] | 5965 | } |
Kristian Høgsberg | dd62aba | 2014-02-12 09:56:19 -0800 | [diff] [blame] | 5966 | |
| 5967 | sc->resource = wl_resource_create(client, interface, 1, id); |
Kristian Høgsberg | 2bff94e | 2014-02-11 12:22:51 -0800 | [diff] [blame] | 5968 | if (sc->resource == NULL) { |
| 5969 | free(sc); |
| 5970 | wl_client_post_no_memory(client); |
Kristian Høgsberg | dd62aba | 2014-02-12 09:56:19 -0800 | [diff] [blame] | 5971 | return NULL; |
Kristian Høgsberg | 2bff94e | 2014-02-11 12:22:51 -0800 | [diff] [blame] | 5972 | } |
| 5973 | |
| 5974 | sc->client = client; |
| 5975 | sc->shell = shell; |
| 5976 | sc->destroy_listener.notify = handle_shell_client_destroy; |
| 5977 | wl_client_add_destroy_listener(client, &sc->destroy_listener); |
Jonas Ådahl | 49d77d2 | 2015-03-18 16:20:51 +0800 | [diff] [blame] | 5978 | wl_list_init(&sc->surface_list); |
Kristian Høgsberg | 2bff94e | 2014-02-11 12:22:51 -0800 | [diff] [blame] | 5979 | |
Kristian Høgsberg | dd62aba | 2014-02-12 09:56:19 -0800 | [diff] [blame] | 5980 | return sc; |
| 5981 | } |
| 5982 | |
| 5983 | static void |
| 5984 | bind_shell(struct wl_client *client, void *data, uint32_t version, uint32_t id) |
| 5985 | { |
| 5986 | struct desktop_shell *shell = data; |
| 5987 | struct shell_client *sc; |
| 5988 | |
| 5989 | sc = shell_client_create(client, shell, &wl_shell_interface, id); |
| 5990 | if (sc) |
| 5991 | wl_resource_set_implementation(sc->resource, |
| 5992 | &shell_implementation, |
Jason Ekstrand | 9e9512f | 2014-04-16 21:12:10 -0500 | [diff] [blame] | 5993 | sc, NULL); |
Kristian Høgsberg | dd62aba | 2014-02-12 09:56:19 -0800 | [diff] [blame] | 5994 | } |
| 5995 | |
| 5996 | static void |
| 5997 | bind_xdg_shell(struct wl_client *client, void *data, uint32_t version, uint32_t id) |
| 5998 | { |
| 5999 | struct desktop_shell *shell = data; |
| 6000 | struct shell_client *sc; |
| 6001 | |
| 6002 | sc = shell_client_create(client, shell, &xdg_shell_interface, id); |
| 6003 | if (sc) |
| 6004 | wl_resource_set_dispatcher(sc->resource, |
| 6005 | xdg_shell_unversioned_dispatch, |
| 6006 | NULL, sc, NULL); |
Rafael Antognolli | e2a3455 | 2013-12-03 15:35:45 -0200 | [diff] [blame] | 6007 | } |
| 6008 | |
| 6009 | static void |
Pekka Paalanen | 9ef3e01 | 2011-11-15 13:34:48 +0200 | [diff] [blame] | 6010 | unbind_desktop_shell(struct wl_resource *resource) |
| 6011 | { |
Jason Ekstrand | 651f00e | 2013-06-14 10:07:54 -0500 | [diff] [blame] | 6012 | struct desktop_shell *shell = wl_resource_get_user_data(resource); |
Kristian Høgsberg | 1ec0c31 | 2011-11-15 16:39:55 -0500 | [diff] [blame] | 6013 | |
| 6014 | if (shell->locked) |
| 6015 | resume_desktop(shell); |
| 6016 | |
Pekka Paalanen | 9ef3e01 | 2011-11-15 13:34:48 +0200 | [diff] [blame] | 6017 | shell->child.desktop_shell = NULL; |
| 6018 | shell->prepare_event_sent = false; |
Pekka Paalanen | 9ef3e01 | 2011-11-15 13:34:48 +0200 | [diff] [blame] | 6019 | } |
| 6020 | |
| 6021 | static void |
Kristian Høgsberg | 7584062 | 2011-09-06 13:48:16 -0400 | [diff] [blame] | 6022 | bind_desktop_shell(struct wl_client *client, |
| 6023 | void *data, uint32_t version, uint32_t id) |
| 6024 | { |
Tiago Vignatti | be14326 | 2012-04-16 17:31:41 +0300 | [diff] [blame] | 6025 | struct desktop_shell *shell = data; |
Pekka Paalanen | bbe6052 | 2011-11-03 14:11:33 +0200 | [diff] [blame] | 6026 | struct wl_resource *resource; |
Kristian Høgsberg | 7584062 | 2011-09-06 13:48:16 -0400 | [diff] [blame] | 6027 | |
Jonas Ådahl | 6d6fb61 | 2015-11-17 16:00:33 +0800 | [diff] [blame] | 6028 | resource = wl_resource_create(client, &weston_desktop_shell_interface, |
| 6029 | 1, id); |
Pekka Paalanen | bbe6052 | 2011-11-03 14:11:33 +0200 | [diff] [blame] | 6030 | |
Pekka Paalanen | 9ef3e01 | 2011-11-15 13:34:48 +0200 | [diff] [blame] | 6031 | if (client == shell->child.client) { |
Jason Ekstrand | a85118c | 2013-06-27 20:17:02 -0500 | [diff] [blame] | 6032 | wl_resource_set_implementation(resource, |
| 6033 | &desktop_shell_implementation, |
| 6034 | shell, unbind_desktop_shell); |
Pekka Paalanen | 9ef3e01 | 2011-11-15 13:34:48 +0200 | [diff] [blame] | 6035 | shell->child.desktop_shell = resource; |
Pekka Paalanen | bbe6052 | 2011-11-03 14:11:33 +0200 | [diff] [blame] | 6036 | return; |
Pekka Paalanen | 9ef3e01 | 2011-11-15 13:34:48 +0200 | [diff] [blame] | 6037 | } |
Pekka Paalanen | bbe6052 | 2011-11-03 14:11:33 +0200 | [diff] [blame] | 6038 | |
| 6039 | wl_resource_post_error(resource, WL_DISPLAY_ERROR_INVALID_OBJECT, |
| 6040 | "permission to bind desktop_shell denied"); |
Kristian Høgsberg | 7584062 | 2011-09-06 13:48:16 -0400 | [diff] [blame] | 6041 | } |
| 6042 | |
Kristian Høgsberg | 0704539 | 2012-02-19 18:52:44 -0500 | [diff] [blame] | 6043 | struct switcher { |
Tiago Vignatti | be14326 | 2012-04-16 17:31:41 +0300 | [diff] [blame] | 6044 | struct desktop_shell *shell; |
Jonas Ådahl | 90c90b2 | 2014-10-18 13:09:56 +0200 | [diff] [blame] | 6045 | struct weston_view *current; |
Kristian Høgsberg | 0704539 | 2012-02-19 18:52:44 -0500 | [diff] [blame] | 6046 | struct wl_listener listener; |
Kristian Høgsberg | 29139d4 | 2013-04-18 15:25:39 -0400 | [diff] [blame] | 6047 | struct weston_keyboard_grab grab; |
Manuel Bachmann | c1ae2e8 | 2014-02-26 15:53:11 +0100 | [diff] [blame] | 6048 | struct wl_array minimized_array; |
Kristian Høgsberg | 0704539 | 2012-02-19 18:52:44 -0500 | [diff] [blame] | 6049 | }; |
| 6050 | |
| 6051 | static void |
| 6052 | switcher_next(struct switcher *switcher) |
| 6053 | { |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 6054 | struct weston_view *view; |
Jonas Ådahl | 90c90b2 | 2014-10-18 13:09:56 +0200 | [diff] [blame] | 6055 | struct weston_view *first = NULL, *prev = NULL, *next = NULL; |
Kristian Høgsberg | 32e5686 | 2012-04-02 22:18:58 -0400 | [diff] [blame] | 6056 | struct shell_surface *shsurf; |
Kristian Høgsberg | b0d8e77 | 2012-06-18 16:34:58 -0400 | [diff] [blame] | 6057 | struct workspace *ws = get_current_workspace(switcher->shell); |
Kristian Høgsberg | 0704539 | 2012-02-19 18:52:44 -0500 | [diff] [blame] | 6058 | |
Manuel Bachmann | c1ae2e8 | 2014-02-26 15:53:11 +0100 | [diff] [blame] | 6059 | /* temporary re-display minimized surfaces */ |
| 6060 | struct weston_view *tmp; |
| 6061 | struct weston_view **minimized; |
Giulio Camuffo | 412e6a5 | 2014-07-09 22:12:56 +0300 | [diff] [blame] | 6062 | wl_list_for_each_safe(view, tmp, &switcher->shell->minimized_layer.view_list.link, layer_link.link) { |
| 6063 | weston_layer_entry_remove(&view->layer_link); |
| 6064 | weston_layer_entry_insert(&ws->layer.view_list, &view->layer_link); |
Manuel Bachmann | c1ae2e8 | 2014-02-26 15:53:11 +0100 | [diff] [blame] | 6065 | minimized = wl_array_add(&switcher->minimized_array, sizeof *minimized); |
| 6066 | *minimized = view; |
| 6067 | } |
| 6068 | |
Giulio Camuffo | 412e6a5 | 2014-07-09 22:12:56 +0300 | [diff] [blame] | 6069 | 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] | 6070 | shsurf = get_shell_surface(view->surface); |
Rafael Antognolli | 5031cbe | 2013-12-05 19:01:21 -0200 | [diff] [blame] | 6071 | if (shsurf && |
| 6072 | shsurf->type == SHELL_SURFACE_TOPLEVEL && |
| 6073 | shsurf->parent == NULL) { |
Kristian Høgsberg | 0704539 | 2012-02-19 18:52:44 -0500 | [diff] [blame] | 6074 | if (first == NULL) |
Jonas Ådahl | 90c90b2 | 2014-10-18 13:09:56 +0200 | [diff] [blame] | 6075 | first = view; |
Kristian Høgsberg | 0704539 | 2012-02-19 18:52:44 -0500 | [diff] [blame] | 6076 | if (prev == switcher->current) |
Jonas Ådahl | 90c90b2 | 2014-10-18 13:09:56 +0200 | [diff] [blame] | 6077 | next = view; |
| 6078 | prev = view; |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 6079 | view->alpha = 0.25; |
| 6080 | weston_view_geometry_dirty(view); |
| 6081 | weston_surface_damage(view->surface); |
Kristian Høgsberg | 0704539 | 2012-02-19 18:52:44 -0500 | [diff] [blame] | 6082 | } |
Alex Wu | 1659daa | 2012-04-01 20:13:09 +0800 | [diff] [blame] | 6083 | |
Jonas Ådahl | 7bfb113 | 2014-10-18 12:23:20 +0200 | [diff] [blame] | 6084 | if (is_black_surface_view(view, NULL)) { |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 6085 | view->alpha = 0.25; |
| 6086 | weston_view_geometry_dirty(view); |
| 6087 | weston_surface_damage(view->surface); |
Alex Wu | 1659daa | 2012-04-01 20:13:09 +0800 | [diff] [blame] | 6088 | } |
Kristian Høgsberg | 0704539 | 2012-02-19 18:52:44 -0500 | [diff] [blame] | 6089 | } |
| 6090 | |
| 6091 | if (next == NULL) |
| 6092 | next = first; |
| 6093 | |
Alex Wu | 07b2606 | 2012-03-12 16:06:01 +0800 | [diff] [blame] | 6094 | if (next == NULL) |
| 6095 | return; |
| 6096 | |
Kristian Høgsberg | 0704539 | 2012-02-19 18:52:44 -0500 | [diff] [blame] | 6097 | wl_list_remove(&switcher->listener.link); |
Jason Ekstrand | 26ed73c | 2013-06-06 22:34:41 -0500 | [diff] [blame] | 6098 | wl_signal_add(&next->destroy_signal, &switcher->listener); |
Kristian Høgsberg | 0704539 | 2012-02-19 18:52:44 -0500 | [diff] [blame] | 6099 | |
| 6100 | switcher->current = next; |
Jonas Ådahl | 90c90b2 | 2014-10-18 13:09:56 +0200 | [diff] [blame] | 6101 | wl_list_for_each(view, &next->surface->views, surface_link) |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 6102 | view->alpha = 1.0; |
Alex Wu | 1659daa | 2012-04-01 20:13:09 +0800 | [diff] [blame] | 6103 | |
Jonas Ådahl | 90c90b2 | 2014-10-18 13:09:56 +0200 | [diff] [blame] | 6104 | shsurf = get_shell_surface(switcher->current->surface); |
Rafael Antognolli | 03b1659 | 2013-12-03 15:35:42 -0200 | [diff] [blame] | 6105 | if (shsurf && shsurf->state.fullscreen) |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 6106 | shsurf->fullscreen.black_view->alpha = 1.0; |
Kristian Høgsberg | 0704539 | 2012-02-19 18:52:44 -0500 | [diff] [blame] | 6107 | } |
| 6108 | |
| 6109 | static void |
Jonas Ådahl | 90c90b2 | 2014-10-18 13:09:56 +0200 | [diff] [blame] | 6110 | switcher_handle_view_destroy(struct wl_listener *listener, void *data) |
Kristian Høgsberg | 0704539 | 2012-02-19 18:52:44 -0500 | [diff] [blame] | 6111 | { |
| 6112 | struct switcher *switcher = |
| 6113 | container_of(listener, struct switcher, listener); |
| 6114 | |
| 6115 | switcher_next(switcher); |
| 6116 | } |
| 6117 | |
| 6118 | static void |
Daniel Stone | 351eb61 | 2012-05-31 15:27:47 -0400 | [diff] [blame] | 6119 | switcher_destroy(struct switcher *switcher) |
Kristian Høgsberg | 0704539 | 2012-02-19 18:52:44 -0500 | [diff] [blame] | 6120 | { |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 6121 | struct weston_view *view; |
Kristian Høgsberg | 29139d4 | 2013-04-18 15:25:39 -0400 | [diff] [blame] | 6122 | struct weston_keyboard *keyboard = switcher->grab.keyboard; |
Kristian Høgsberg | b0d8e77 | 2012-06-18 16:34:58 -0400 | [diff] [blame] | 6123 | struct workspace *ws = get_current_workspace(switcher->shell); |
Kristian Høgsberg | 0704539 | 2012-02-19 18:52:44 -0500 | [diff] [blame] | 6124 | |
Giulio Camuffo | 412e6a5 | 2014-07-09 22:12:56 +0300 | [diff] [blame] | 6125 | 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] | 6126 | if (is_focus_view(view)) |
| 6127 | continue; |
| 6128 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 6129 | view->alpha = 1.0; |
| 6130 | weston_surface_damage(view->surface); |
Kristian Høgsberg | 0704539 | 2012-02-19 18:52:44 -0500 | [diff] [blame] | 6131 | } |
| 6132 | |
Alex Wu | 07b2606 | 2012-03-12 16:06:01 +0800 | [diff] [blame] | 6133 | if (switcher->current) |
Jonas Ådahl | 1fa6ded | 2014-10-18 13:24:53 +0200 | [diff] [blame^] | 6134 | activate(switcher->shell, switcher->current, |
Derek Foreman | 8aeeac8 | 2015-01-30 13:24:36 -0600 | [diff] [blame] | 6135 | keyboard->seat, true); |
Kristian Høgsberg | 0704539 | 2012-02-19 18:52:44 -0500 | [diff] [blame] | 6136 | wl_list_remove(&switcher->listener.link); |
Kristian Høgsberg | 29139d4 | 2013-04-18 15:25:39 -0400 | [diff] [blame] | 6137 | weston_keyboard_end_grab(keyboard); |
| 6138 | if (keyboard->input_method_resource) |
| 6139 | keyboard->grab = &keyboard->input_method_grab; |
Manuel Bachmann | c1ae2e8 | 2014-02-26 15:53:11 +0100 | [diff] [blame] | 6140 | |
| 6141 | /* re-hide surfaces that were temporary shown during the switch */ |
| 6142 | struct weston_view **minimized; |
| 6143 | wl_array_for_each(minimized, &switcher->minimized_array) { |
| 6144 | /* with the exception of the current selected */ |
Jonas Ådahl | 90c90b2 | 2014-10-18 13:09:56 +0200 | [diff] [blame] | 6145 | if ((*minimized)->surface != switcher->current->surface) { |
Giulio Camuffo | 412e6a5 | 2014-07-09 22:12:56 +0300 | [diff] [blame] | 6146 | weston_layer_entry_remove(&(*minimized)->layer_link); |
| 6147 | 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] | 6148 | weston_view_damage_below(*minimized); |
| 6149 | } |
| 6150 | } |
| 6151 | wl_array_release(&switcher->minimized_array); |
| 6152 | |
Kristian Høgsberg | 0704539 | 2012-02-19 18:52:44 -0500 | [diff] [blame] | 6153 | free(switcher); |
| 6154 | } |
| 6155 | |
| 6156 | static void |
Kristian Høgsberg | 29139d4 | 2013-04-18 15:25:39 -0400 | [diff] [blame] | 6157 | switcher_key(struct weston_keyboard_grab *grab, |
Daniel Stone | c9785ea | 2012-05-30 16:31:52 +0100 | [diff] [blame] | 6158 | uint32_t time, uint32_t key, uint32_t state_w) |
Kristian Høgsberg | 0704539 | 2012-02-19 18:52:44 -0500 | [diff] [blame] | 6159 | { |
| 6160 | struct switcher *switcher = container_of(grab, struct switcher, grab); |
Daniel Stone | c9785ea | 2012-05-30 16:31:52 +0100 | [diff] [blame] | 6161 | enum wl_keyboard_key_state state = state_w; |
Daniel Stone | 351eb61 | 2012-05-31 15:27:47 -0400 | [diff] [blame] | 6162 | |
Daniel Stone | c9785ea | 2012-05-30 16:31:52 +0100 | [diff] [blame] | 6163 | if (key == KEY_TAB && state == WL_KEYBOARD_KEY_STATE_PRESSED) |
Daniel Stone | 351eb61 | 2012-05-31 15:27:47 -0400 | [diff] [blame] | 6164 | switcher_next(switcher); |
| 6165 | } |
| 6166 | |
| 6167 | static void |
Kristian Høgsberg | 29139d4 | 2013-04-18 15:25:39 -0400 | [diff] [blame] | 6168 | switcher_modifier(struct weston_keyboard_grab *grab, uint32_t serial, |
Daniel Stone | 351eb61 | 2012-05-31 15:27:47 -0400 | [diff] [blame] | 6169 | uint32_t mods_depressed, uint32_t mods_latched, |
| 6170 | uint32_t mods_locked, uint32_t group) |
| 6171 | { |
| 6172 | struct switcher *switcher = container_of(grab, struct switcher, grab); |
Derek Foreman | 8aeeac8 | 2015-01-30 13:24:36 -0600 | [diff] [blame] | 6173 | struct weston_seat *seat = grab->keyboard->seat; |
Kristian Høgsberg | 0704539 | 2012-02-19 18:52:44 -0500 | [diff] [blame] | 6174 | |
Daniel Stone | 351eb61 | 2012-05-31 15:27:47 -0400 | [diff] [blame] | 6175 | if ((seat->modifier_state & switcher->shell->binding_modifier) == 0) |
| 6176 | switcher_destroy(switcher); |
Kristian Høgsberg | b71302e | 2012-05-10 12:28:35 -0400 | [diff] [blame] | 6177 | } |
Kristian Høgsberg | 0704539 | 2012-02-19 18:52:44 -0500 | [diff] [blame] | 6178 | |
Jonas Ådahl | 1ea343e | 2013-10-25 23:18:05 +0200 | [diff] [blame] | 6179 | static void |
| 6180 | switcher_cancel(struct weston_keyboard_grab *grab) |
| 6181 | { |
| 6182 | struct switcher *switcher = container_of(grab, struct switcher, grab); |
| 6183 | |
| 6184 | switcher_destroy(switcher); |
| 6185 | } |
| 6186 | |
Kristian Høgsberg | 29139d4 | 2013-04-18 15:25:39 -0400 | [diff] [blame] | 6187 | static const struct weston_keyboard_grab_interface switcher_grab = { |
Daniel Stone | 351eb61 | 2012-05-31 15:27:47 -0400 | [diff] [blame] | 6188 | switcher_key, |
| 6189 | switcher_modifier, |
Jonas Ådahl | 1ea343e | 2013-10-25 23:18:05 +0200 | [diff] [blame] | 6190 | switcher_cancel, |
Kristian Høgsberg | 0704539 | 2012-02-19 18:52:44 -0500 | [diff] [blame] | 6191 | }; |
| 6192 | |
| 6193 | static void |
Derek Foreman | 8ae2db5 | 2015-07-15 13:00:36 -0500 | [diff] [blame] | 6194 | switcher_binding(struct weston_keyboard *keyboard, uint32_t time, |
| 6195 | uint32_t key, void *data) |
Kristian Høgsberg | 0704539 | 2012-02-19 18:52:44 -0500 | [diff] [blame] | 6196 | { |
Tiago Vignatti | be14326 | 2012-04-16 17:31:41 +0300 | [diff] [blame] | 6197 | struct desktop_shell *shell = data; |
Kristian Høgsberg | 0704539 | 2012-02-19 18:52:44 -0500 | [diff] [blame] | 6198 | struct switcher *switcher; |
| 6199 | |
| 6200 | switcher = malloc(sizeof *switcher); |
Kristian Høgsberg | 02e79dc | 2012-04-12 09:55:26 -0400 | [diff] [blame] | 6201 | switcher->shell = shell; |
Kristian Høgsberg | 0704539 | 2012-02-19 18:52:44 -0500 | [diff] [blame] | 6202 | switcher->current = NULL; |
Jonas Ådahl | 90c90b2 | 2014-10-18 13:09:56 +0200 | [diff] [blame] | 6203 | switcher->listener.notify = switcher_handle_view_destroy; |
Kristian Høgsberg | 0704539 | 2012-02-19 18:52:44 -0500 | [diff] [blame] | 6204 | wl_list_init(&switcher->listener.link); |
Manuel Bachmann | c1ae2e8 | 2014-02-26 15:53:11 +0100 | [diff] [blame] | 6205 | wl_array_init(&switcher->minimized_array); |
Kristian Høgsberg | 0704539 | 2012-02-19 18:52:44 -0500 | [diff] [blame] | 6206 | |
Alexander Larsson | f82b6ca | 2013-05-28 16:23:39 +0200 | [diff] [blame] | 6207 | restore_all_output_modes(shell->compositor); |
Mario Kleiner | 9f4d655 | 2015-06-21 21:25:08 +0200 | [diff] [blame] | 6208 | lower_fullscreen_layer(switcher->shell, NULL); |
Kristian Høgsberg | 0704539 | 2012-02-19 18:52:44 -0500 | [diff] [blame] | 6209 | switcher->grab.interface = &switcher_grab; |
Derek Foreman | 8ae2db5 | 2015-07-15 13:00:36 -0500 | [diff] [blame] | 6210 | weston_keyboard_start_grab(keyboard, &switcher->grab); |
| 6211 | weston_keyboard_set_focus(keyboard, NULL); |
Kristian Høgsberg | 0704539 | 2012-02-19 18:52:44 -0500 | [diff] [blame] | 6212 | switcher_next(switcher); |
| 6213 | } |
| 6214 | |
Pekka Paalanen | 3c64723 | 2011-12-22 13:43:43 +0200 | [diff] [blame] | 6215 | static void |
Derek Foreman | 8ae2db5 | 2015-07-15 13:00:36 -0500 | [diff] [blame] | 6216 | backlight_binding(struct weston_keyboard *keyboard, uint32_t time, |
| 6217 | uint32_t key, void *data) |
Tiago Vignatti | 8e53c7f | 2012-02-29 19:53:50 +0200 | [diff] [blame] | 6218 | { |
| 6219 | struct weston_compositor *compositor = data; |
| 6220 | struct weston_output *output; |
Tiago Vignatti | 5ab91ad | 2012-03-12 19:40:09 -0300 | [diff] [blame] | 6221 | long backlight_new = 0; |
Tiago Vignatti | 8e53c7f | 2012-02-29 19:53:50 +0200 | [diff] [blame] | 6222 | |
| 6223 | /* TODO: we're limiting to simple use cases, where we assume just |
| 6224 | * control on the primary display. We'd have to extend later if we |
| 6225 | * ever get support for setting backlights on random desktop LCD |
| 6226 | * panels though */ |
| 6227 | output = get_default_output(compositor); |
| 6228 | if (!output) |
| 6229 | return; |
| 6230 | |
| 6231 | if (!output->set_backlight) |
| 6232 | return; |
| 6233 | |
Tiago Vignatti | 5ab91ad | 2012-03-12 19:40:09 -0300 | [diff] [blame] | 6234 | if (key == KEY_F9 || key == KEY_BRIGHTNESSDOWN) |
| 6235 | backlight_new = output->backlight_current - 25; |
| 6236 | else if (key == KEY_F10 || key == KEY_BRIGHTNESSUP) |
| 6237 | backlight_new = output->backlight_current + 25; |
Tiago Vignatti | 8e53c7f | 2012-02-29 19:53:50 +0200 | [diff] [blame] | 6238 | |
Tiago Vignatti | 5ab91ad | 2012-03-12 19:40:09 -0300 | [diff] [blame] | 6239 | if (backlight_new < 5) |
| 6240 | backlight_new = 5; |
| 6241 | if (backlight_new > 255) |
| 6242 | backlight_new = 255; |
| 6243 | |
| 6244 | output->backlight_current = backlight_new; |
Tiago Vignatti | 8e53c7f | 2012-02-29 19:53:50 +0200 | [diff] [blame] | 6245 | output->set_backlight(output, output->backlight_current); |
| 6246 | } |
| 6247 | |
Kristian Høgsberg | b41c081 | 2012-03-04 14:53:40 -0500 | [diff] [blame] | 6248 | static void |
Derek Foreman | 8ae2db5 | 2015-07-15 13:00:36 -0500 | [diff] [blame] | 6249 | force_kill_binding(struct weston_keyboard *keyboard, uint32_t time, |
| 6250 | uint32_t key, void *data) |
Kristian Høgsberg | 92a57db | 2012-05-26 13:41:06 -0400 | [diff] [blame] | 6251 | { |
Kristian Høgsberg | fe7aa90 | 2013-05-08 09:54:37 -0400 | [diff] [blame] | 6252 | struct weston_surface *focus_surface; |
Kristian Høgsberg | 92a57db | 2012-05-26 13:41:06 -0400 | [diff] [blame] | 6253 | struct wl_client *client; |
Tiago Vignatti | 1d01b01 | 2012-09-27 17:48:36 +0300 | [diff] [blame] | 6254 | struct desktop_shell *shell = data; |
| 6255 | struct weston_compositor *compositor = shell->compositor; |
Kristian Høgsberg | 92a57db | 2012-05-26 13:41:06 -0400 | [diff] [blame] | 6256 | pid_t pid; |
Kristian Høgsberg | 92a57db | 2012-05-26 13:41:06 -0400 | [diff] [blame] | 6257 | |
Derek Foreman | 8ae2db5 | 2015-07-15 13:00:36 -0500 | [diff] [blame] | 6258 | focus_surface = keyboard->focus; |
Philipp Brüschweiler | 6cef009 | 2012-08-13 21:27:27 +0200 | [diff] [blame] | 6259 | if (!focus_surface) |
| 6260 | return; |
| 6261 | |
Tiago Vignatti | 1d01b01 | 2012-09-27 17:48:36 +0300 | [diff] [blame] | 6262 | wl_signal_emit(&compositor->kill_signal, focus_surface); |
| 6263 | |
Jason Ekstrand | 26ed73c | 2013-06-06 22:34:41 -0500 | [diff] [blame] | 6264 | client = wl_resource_get_client(focus_surface->resource); |
Tiago Vignatti | 920f197 | 2012-09-27 17:48:35 +0300 | [diff] [blame] | 6265 | wl_client_get_credentials(client, &pid, NULL, NULL); |
| 6266 | |
| 6267 | /* Skip clients that we launched ourselves (the credentials of |
| 6268 | * the socketpair is ours) */ |
| 6269 | if (pid == getpid()) |
| 6270 | return; |
Kristian Høgsberg | 92a57db | 2012-05-26 13:41:06 -0400 | [diff] [blame] | 6271 | |
Daniel Stone | 325fc2d | 2012-05-30 16:31:58 +0100 | [diff] [blame] | 6272 | kill(pid, SIGKILL); |
Kristian Høgsberg | 92a57db | 2012-05-26 13:41:06 -0400 | [diff] [blame] | 6273 | } |
| 6274 | |
| 6275 | static void |
Derek Foreman | 8ae2db5 | 2015-07-15 13:00:36 -0500 | [diff] [blame] | 6276 | workspace_up_binding(struct weston_keyboard *keyboard, uint32_t time, |
Jonas Ådahl | e3cddce | 2012-06-13 00:01:22 +0200 | [diff] [blame] | 6277 | uint32_t key, void *data) |
| 6278 | { |
| 6279 | struct desktop_shell *shell = data; |
| 6280 | unsigned int new_index = shell->workspaces.current; |
| 6281 | |
Kristian Høgsberg | ce345b0 | 2012-06-25 21:35:29 -0400 | [diff] [blame] | 6282 | if (shell->locked) |
Kristian Høgsberg | 4476aaf | 2012-06-25 14:03:13 -0400 | [diff] [blame] | 6283 | return; |
Jonas Ådahl | e3cddce | 2012-06-13 00:01:22 +0200 | [diff] [blame] | 6284 | if (new_index != 0) |
| 6285 | new_index--; |
| 6286 | |
| 6287 | change_workspace(shell, new_index); |
| 6288 | } |
| 6289 | |
| 6290 | static void |
Derek Foreman | 8ae2db5 | 2015-07-15 13:00:36 -0500 | [diff] [blame] | 6291 | workspace_down_binding(struct weston_keyboard *keyboard, uint32_t time, |
Jonas Ådahl | e3cddce | 2012-06-13 00:01:22 +0200 | [diff] [blame] | 6292 | uint32_t key, void *data) |
| 6293 | { |
| 6294 | struct desktop_shell *shell = data; |
| 6295 | unsigned int new_index = shell->workspaces.current; |
| 6296 | |
Kristian Høgsberg | ce345b0 | 2012-06-25 21:35:29 -0400 | [diff] [blame] | 6297 | if (shell->locked) |
Kristian Høgsberg | 4476aaf | 2012-06-25 14:03:13 -0400 | [diff] [blame] | 6298 | return; |
Jonas Ådahl | e3cddce | 2012-06-13 00:01:22 +0200 | [diff] [blame] | 6299 | if (new_index < shell->workspaces.num - 1) |
| 6300 | new_index++; |
| 6301 | |
| 6302 | change_workspace(shell, new_index); |
| 6303 | } |
| 6304 | |
| 6305 | static void |
Derek Foreman | 8ae2db5 | 2015-07-15 13:00:36 -0500 | [diff] [blame] | 6306 | workspace_f_binding(struct weston_keyboard *keyboard, uint32_t time, |
Jonas Ådahl | e3cddce | 2012-06-13 00:01:22 +0200 | [diff] [blame] | 6307 | uint32_t key, void *data) |
| 6308 | { |
| 6309 | struct desktop_shell *shell = data; |
| 6310 | unsigned int new_index; |
| 6311 | |
Kristian Høgsberg | ce345b0 | 2012-06-25 21:35:29 -0400 | [diff] [blame] | 6312 | if (shell->locked) |
Kristian Høgsberg | 4476aaf | 2012-06-25 14:03:13 -0400 | [diff] [blame] | 6313 | return; |
Jonas Ådahl | e3cddce | 2012-06-13 00:01:22 +0200 | [diff] [blame] | 6314 | new_index = key - KEY_F1; |
| 6315 | if (new_index >= shell->workspaces.num) |
| 6316 | new_index = shell->workspaces.num - 1; |
| 6317 | |
| 6318 | change_workspace(shell, new_index); |
| 6319 | } |
| 6320 | |
Jonas Ådahl | 8de6a1d | 2012-08-29 22:13:00 +0200 | [diff] [blame] | 6321 | static void |
Derek Foreman | 8ae2db5 | 2015-07-15 13:00:36 -0500 | [diff] [blame] | 6322 | workspace_move_surface_up_binding(struct weston_keyboard *keyboard, |
| 6323 | uint32_t time, uint32_t key, void *data) |
Jonas Ådahl | 8de6a1d | 2012-08-29 22:13:00 +0200 | [diff] [blame] | 6324 | { |
| 6325 | struct desktop_shell *shell = data; |
| 6326 | unsigned int new_index = shell->workspaces.current; |
| 6327 | |
| 6328 | if (shell->locked) |
| 6329 | return; |
| 6330 | |
| 6331 | if (new_index != 0) |
| 6332 | new_index--; |
| 6333 | |
Derek Foreman | 8ae2db5 | 2015-07-15 13:00:36 -0500 | [diff] [blame] | 6334 | take_surface_to_workspace_by_seat(shell, keyboard->seat, new_index); |
Jonas Ådahl | 8de6a1d | 2012-08-29 22:13:00 +0200 | [diff] [blame] | 6335 | } |
| 6336 | |
| 6337 | static void |
Derek Foreman | 8ae2db5 | 2015-07-15 13:00:36 -0500 | [diff] [blame] | 6338 | workspace_move_surface_down_binding(struct weston_keyboard *keyboard, |
| 6339 | uint32_t time, uint32_t key, void *data) |
Jonas Ådahl | 8de6a1d | 2012-08-29 22:13:00 +0200 | [diff] [blame] | 6340 | { |
| 6341 | struct desktop_shell *shell = data; |
| 6342 | unsigned int new_index = shell->workspaces.current; |
| 6343 | |
| 6344 | if (shell->locked) |
| 6345 | return; |
| 6346 | |
| 6347 | if (new_index < shell->workspaces.num - 1) |
| 6348 | new_index++; |
| 6349 | |
Derek Foreman | 8ae2db5 | 2015-07-15 13:00:36 -0500 | [diff] [blame] | 6350 | take_surface_to_workspace_by_seat(shell, keyboard->seat, new_index); |
Jonas Ådahl | 8de6a1d | 2012-08-29 22:13:00 +0200 | [diff] [blame] | 6351 | } |
Jonas Ådahl | e3cddce | 2012-06-13 00:01:22 +0200 | [diff] [blame] | 6352 | |
| 6353 | static void |
Ander Conselvan de Oliveira | c94d622 | 2014-01-29 18:47:54 +0200 | [diff] [blame] | 6354 | shell_reposition_view_on_output_destroy(struct weston_view *view) |
| 6355 | { |
| 6356 | struct weston_output *output, *first_output; |
| 6357 | struct weston_compositor *ec = view->surface->compositor; |
| 6358 | struct shell_surface *shsurf; |
| 6359 | float x, y; |
| 6360 | int visible; |
| 6361 | |
| 6362 | x = view->geometry.x; |
| 6363 | y = view->geometry.y; |
| 6364 | |
| 6365 | /* At this point the destroyed output is not in the list anymore. |
| 6366 | * If the view is still visible somewhere, we leave where it is, |
| 6367 | * otherwise, move it to the first output. */ |
| 6368 | visible = 0; |
| 6369 | wl_list_for_each(output, &ec->output_list, link) { |
| 6370 | if (pixman_region32_contains_point(&output->region, |
| 6371 | x, y, NULL)) { |
| 6372 | visible = 1; |
| 6373 | break; |
| 6374 | } |
| 6375 | } |
| 6376 | |
| 6377 | if (!visible) { |
| 6378 | first_output = container_of(ec->output_list.next, |
| 6379 | struct weston_output, link); |
| 6380 | |
| 6381 | x = first_output->x + first_output->width / 4; |
| 6382 | y = first_output->y + first_output->height / 4; |
Xiong Zhang | 62899f5 | 2014-03-07 16:27:19 +0800 | [diff] [blame] | 6383 | |
| 6384 | weston_view_set_position(view, x, y); |
| 6385 | } else { |
| 6386 | weston_view_geometry_dirty(view); |
Ander Conselvan de Oliveira | c94d622 | 2014-01-29 18:47:54 +0200 | [diff] [blame] | 6387 | } |
| 6388 | |
Ander Conselvan de Oliveira | c94d622 | 2014-01-29 18:47:54 +0200 | [diff] [blame] | 6389 | |
| 6390 | shsurf = get_shell_surface(view->surface); |
| 6391 | |
| 6392 | if (shsurf) { |
| 6393 | shsurf->saved_position_valid = false; |
| 6394 | shsurf->next_state.maximized = false; |
| 6395 | shsurf->next_state.fullscreen = false; |
| 6396 | shsurf->state_changed = true; |
| 6397 | } |
| 6398 | } |
| 6399 | |
Ander Conselvan de Oliveira | 304996d | 2014-04-11 13:57:15 +0300 | [diff] [blame] | 6400 | void |
| 6401 | shell_for_each_layer(struct desktop_shell *shell, |
| 6402 | shell_for_each_layer_func_t func, void *data) |
Ander Conselvan de Oliveira | c94d622 | 2014-01-29 18:47:54 +0200 | [diff] [blame] | 6403 | { |
Ander Conselvan de Oliveira | 304996d | 2014-04-11 13:57:15 +0300 | [diff] [blame] | 6404 | struct workspace **ws; |
| 6405 | |
| 6406 | func(shell, &shell->fullscreen_layer, data); |
| 6407 | func(shell, &shell->panel_layer, data); |
| 6408 | func(shell, &shell->background_layer, data); |
| 6409 | func(shell, &shell->lock_layer, data); |
| 6410 | func(shell, &shell->input_panel_layer, data); |
| 6411 | |
| 6412 | wl_array_for_each(ws, &shell->workspaces.array) |
| 6413 | func(shell, &(*ws)->layer, data); |
| 6414 | } |
| 6415 | |
| 6416 | static void |
| 6417 | shell_output_destroy_move_layer(struct desktop_shell *shell, |
| 6418 | struct weston_layer *layer, |
| 6419 | void *data) |
| 6420 | { |
| 6421 | struct weston_output *output = data; |
Ander Conselvan de Oliveira | c94d622 | 2014-01-29 18:47:54 +0200 | [diff] [blame] | 6422 | struct weston_view *view; |
| 6423 | |
Giulio Camuffo | 412e6a5 | 2014-07-09 22:12:56 +0300 | [diff] [blame] | 6424 | 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] | 6425 | if (view->output != output) |
| 6426 | continue; |
Ander Conselvan de Oliveira | c94d622 | 2014-01-29 18:47:54 +0200 | [diff] [blame] | 6427 | |
Ander Conselvan de Oliveira | 304996d | 2014-04-11 13:57:15 +0300 | [diff] [blame] | 6428 | shell_reposition_view_on_output_destroy(view); |
Ander Conselvan de Oliveira | c94d622 | 2014-01-29 18:47:54 +0200 | [diff] [blame] | 6429 | } |
| 6430 | } |
| 6431 | |
| 6432 | static void |
Xiong Zhang | 6b48142 | 2013-10-23 13:58:32 +0800 | [diff] [blame] | 6433 | handle_output_destroy(struct wl_listener *listener, void *data) |
| 6434 | { |
| 6435 | struct shell_output *output_listener = |
| 6436 | container_of(listener, struct shell_output, destroy_listener); |
Ander Conselvan de Oliveira | 304996d | 2014-04-11 13:57:15 +0300 | [diff] [blame] | 6437 | struct weston_output *output = output_listener->output; |
| 6438 | struct desktop_shell *shell = output_listener->shell; |
Xiong Zhang | 6b48142 | 2013-10-23 13:58:32 +0800 | [diff] [blame] | 6439 | |
Ander Conselvan de Oliveira | 304996d | 2014-04-11 13:57:15 +0300 | [diff] [blame] | 6440 | 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] | 6441 | |
Xiong Zhang | 6b48142 | 2013-10-23 13:58:32 +0800 | [diff] [blame] | 6442 | wl_list_remove(&output_listener->destroy_listener.link); |
| 6443 | wl_list_remove(&output_listener->link); |
| 6444 | free(output_listener); |
| 6445 | } |
| 6446 | |
| 6447 | static void |
David Fort | 50d962f | 2016-06-09 17:55:52 +0200 | [diff] [blame] | 6448 | shell_resize_surface_to_output(struct desktop_shell *shell, |
| 6449 | struct weston_surface *surface, |
| 6450 | const struct weston_output *output) |
| 6451 | { |
| 6452 | if (!surface) |
| 6453 | return; |
| 6454 | |
| 6455 | weston_desktop_shell_send_configure(shell->child.desktop_shell, 0, |
| 6456 | surface->resource, |
| 6457 | output->width, |
| 6458 | output->height); |
| 6459 | } |
| 6460 | |
| 6461 | |
| 6462 | static void |
| 6463 | handle_output_resized(struct wl_listener *listener, void *data) |
| 6464 | { |
| 6465 | struct desktop_shell *shell = |
| 6466 | container_of(listener, struct desktop_shell, resized_listener); |
| 6467 | struct weston_output *output = (struct weston_output *)data; |
| 6468 | struct shell_output *sh_output = find_shell_output_from_weston_output(shell, output); |
| 6469 | |
| 6470 | shell_resize_surface_to_output(shell, sh_output->background_surface, output); |
| 6471 | shell_resize_surface_to_output(shell, sh_output->panel_surface, output); |
| 6472 | } |
| 6473 | |
| 6474 | static void |
Xiong Zhang | 6b48142 | 2013-10-23 13:58:32 +0800 | [diff] [blame] | 6475 | create_shell_output(struct desktop_shell *shell, |
| 6476 | struct weston_output *output) |
| 6477 | { |
| 6478 | struct shell_output *shell_output; |
| 6479 | |
| 6480 | shell_output = zalloc(sizeof *shell_output); |
| 6481 | if (shell_output == NULL) |
| 6482 | return; |
| 6483 | |
| 6484 | shell_output->output = output; |
| 6485 | shell_output->shell = shell; |
| 6486 | shell_output->destroy_listener.notify = handle_output_destroy; |
| 6487 | wl_signal_add(&output->destroy_signal, |
| 6488 | &shell_output->destroy_listener); |
Kristian Høgsberg | a3a0e18 | 2013-10-23 23:36:04 -0700 | [diff] [blame] | 6489 | wl_list_insert(shell->output_list.prev, &shell_output->link); |
Xiong Zhang | 6b48142 | 2013-10-23 13:58:32 +0800 | [diff] [blame] | 6490 | } |
| 6491 | |
| 6492 | static void |
| 6493 | handle_output_create(struct wl_listener *listener, void *data) |
| 6494 | { |
| 6495 | struct desktop_shell *shell = |
| 6496 | container_of(listener, struct desktop_shell, output_create_listener); |
| 6497 | struct weston_output *output = (struct weston_output *)data; |
| 6498 | |
| 6499 | create_shell_output(shell, output); |
| 6500 | } |
| 6501 | |
| 6502 | static void |
Ander Conselvan de Oliveira | 304996d | 2014-04-11 13:57:15 +0300 | [diff] [blame] | 6503 | handle_output_move_layer(struct desktop_shell *shell, |
| 6504 | struct weston_layer *layer, void *data) |
Ander Conselvan de Oliveira | a8a9baf | 2014-01-29 18:47:52 +0200 | [diff] [blame] | 6505 | { |
Ander Conselvan de Oliveira | 304996d | 2014-04-11 13:57:15 +0300 | [diff] [blame] | 6506 | struct weston_output *output = data; |
Ander Conselvan de Oliveira | a8a9baf | 2014-01-29 18:47:52 +0200 | [diff] [blame] | 6507 | struct weston_view *view; |
| 6508 | float x, y; |
| 6509 | |
Giulio Camuffo | 412e6a5 | 2014-07-09 22:12:56 +0300 | [diff] [blame] | 6510 | 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] | 6511 | if (view->output != output) |
| 6512 | continue; |
| 6513 | |
| 6514 | x = view->geometry.x + output->move_x; |
| 6515 | y = view->geometry.y + output->move_y; |
| 6516 | weston_view_set_position(view, x, y); |
| 6517 | } |
| 6518 | } |
| 6519 | |
| 6520 | static void |
| 6521 | handle_output_move(struct wl_listener *listener, void *data) |
| 6522 | { |
| 6523 | struct desktop_shell *shell; |
| 6524 | |
Ander Conselvan de Oliveira | a8a9baf | 2014-01-29 18:47:52 +0200 | [diff] [blame] | 6525 | shell = container_of(listener, struct desktop_shell, |
| 6526 | output_move_listener); |
Ander Conselvan de Oliveira | a8a9baf | 2014-01-29 18:47:52 +0200 | [diff] [blame] | 6527 | |
Ander Conselvan de Oliveira | 304996d | 2014-04-11 13:57:15 +0300 | [diff] [blame] | 6528 | shell_for_each_layer(shell, handle_output_move_layer, data); |
Ander Conselvan de Oliveira | a8a9baf | 2014-01-29 18:47:52 +0200 | [diff] [blame] | 6529 | } |
| 6530 | |
| 6531 | static void |
Xiong Zhang | 6b48142 | 2013-10-23 13:58:32 +0800 | [diff] [blame] | 6532 | setup_output_destroy_handler(struct weston_compositor *ec, |
| 6533 | struct desktop_shell *shell) |
| 6534 | { |
| 6535 | struct weston_output *output; |
| 6536 | |
| 6537 | wl_list_init(&shell->output_list); |
| 6538 | wl_list_for_each(output, &ec->output_list, link) |
| 6539 | create_shell_output(shell, output); |
| 6540 | |
| 6541 | shell->output_create_listener.notify = handle_output_create; |
| 6542 | wl_signal_add(&ec->output_created_signal, |
| 6543 | &shell->output_create_listener); |
Ander Conselvan de Oliveira | a8a9baf | 2014-01-29 18:47:52 +0200 | [diff] [blame] | 6544 | |
| 6545 | shell->output_move_listener.notify = handle_output_move; |
| 6546 | wl_signal_add(&ec->output_moved_signal, &shell->output_move_listener); |
Xiong Zhang | 6b48142 | 2013-10-23 13:58:32 +0800 | [diff] [blame] | 6547 | } |
| 6548 | |
| 6549 | static void |
Kristian Høgsberg | 02e79dc | 2012-04-12 09:55:26 -0400 | [diff] [blame] | 6550 | shell_destroy(struct wl_listener *listener, void *data) |
Pekka Paalanen | 3c64723 | 2011-12-22 13:43:43 +0200 | [diff] [blame] | 6551 | { |
Tiago Vignatti | be14326 | 2012-04-16 17:31:41 +0300 | [diff] [blame] | 6552 | struct desktop_shell *shell = |
| 6553 | container_of(listener, struct desktop_shell, destroy_listener); |
Jonas Ådahl | e3cddce | 2012-06-13 00:01:22 +0200 | [diff] [blame] | 6554 | struct workspace **ws; |
Xiong Zhang | 6b48142 | 2013-10-23 13:58:32 +0800 | [diff] [blame] | 6555 | struct shell_output *shell_output, *tmp; |
Pekka Paalanen | 3c64723 | 2011-12-22 13:43:43 +0200 | [diff] [blame] | 6556 | |
Kristian Høgsberg | 17bccae | 2014-01-16 16:46:28 -0800 | [diff] [blame] | 6557 | /* Force state to unlocked so we don't try to fade */ |
| 6558 | shell->locked = false; |
Pekka Paalanen | 826dc14 | 2014-08-27 12:11:53 +0300 | [diff] [blame] | 6559 | |
| 6560 | if (shell->child.client) { |
| 6561 | /* disable respawn */ |
| 6562 | wl_list_remove(&shell->child.client_destroy_listener.link); |
Pekka Paalanen | 9cf5cc8 | 2012-01-02 16:00:24 +0200 | [diff] [blame] | 6563 | wl_client_destroy(shell->child.client); |
Pekka Paalanen | 826dc14 | 2014-08-27 12:11:53 +0300 | [diff] [blame] | 6564 | } |
Pekka Paalanen | 9cf5cc8 | 2012-01-02 16:00:24 +0200 | [diff] [blame] | 6565 | |
Ander Conselvan de Oliveira | a457563 | 2013-02-21 18:35:23 +0200 | [diff] [blame] | 6566 | wl_list_remove(&shell->idle_listener.link); |
| 6567 | wl_list_remove(&shell->wake_listener.link); |
Giulio Camuffo | f05d18f | 2015-12-11 20:57:05 +0200 | [diff] [blame] | 6568 | wl_list_remove(&shell->transform_listener.link); |
Kristian Høgsberg | 677a5f5 | 2013-12-04 11:00:19 -0800 | [diff] [blame] | 6569 | |
Pekka Paalanen | aa9536a | 2015-06-24 16:09:17 +0300 | [diff] [blame] | 6570 | text_backend_destroy(shell->text_backend); |
Kristian Høgsberg | 677a5f5 | 2013-12-04 11:00:19 -0800 | [diff] [blame] | 6571 | input_panel_destroy(shell); |
Kristian Høgsberg | 88c1607 | 2012-05-16 08:04:19 -0400 | [diff] [blame] | 6572 | |
Xiong Zhang | 6b48142 | 2013-10-23 13:58:32 +0800 | [diff] [blame] | 6573 | wl_list_for_each_safe(shell_output, tmp, &shell->output_list, link) { |
| 6574 | wl_list_remove(&shell_output->destroy_listener.link); |
| 6575 | wl_list_remove(&shell_output->link); |
| 6576 | free(shell_output); |
| 6577 | } |
| 6578 | |
| 6579 | wl_list_remove(&shell->output_create_listener.link); |
Kristian Høgsberg | 6d50b0f | 2014-04-30 20:46:25 -0700 | [diff] [blame] | 6580 | wl_list_remove(&shell->output_move_listener.link); |
David Fort | 50d962f | 2016-06-09 17:55:52 +0200 | [diff] [blame] | 6581 | wl_list_remove(&shell->resized_listener.link); |
Xiong Zhang | 6b48142 | 2013-10-23 13:58:32 +0800 | [diff] [blame] | 6582 | |
Jonas Ådahl | e3cddce | 2012-06-13 00:01:22 +0200 | [diff] [blame] | 6583 | wl_array_for_each(ws, &shell->workspaces.array) |
| 6584 | workspace_destroy(*ws); |
| 6585 | wl_array_release(&shell->workspaces.array); |
| 6586 | |
Emilio Pozuelo Monfort | 46ce798 | 2013-11-20 13:22:29 +0100 | [diff] [blame] | 6587 | free(shell->client); |
Pekka Paalanen | 3c64723 | 2011-12-22 13:43:43 +0200 | [diff] [blame] | 6588 | free(shell); |
| 6589 | } |
| 6590 | |
Tiago Vignatti | 0b52d48 | 2012-04-20 18:54:25 +0300 | [diff] [blame] | 6591 | static void |
| 6592 | shell_add_bindings(struct weston_compositor *ec, struct desktop_shell *shell) |
| 6593 | { |
| 6594 | uint32_t mod; |
Jonas Ådahl | e3cddce | 2012-06-13 00:01:22 +0200 | [diff] [blame] | 6595 | int i, num_workspace_bindings; |
Tiago Vignatti | 0b52d48 | 2012-04-20 18:54:25 +0300 | [diff] [blame] | 6596 | |
Bob Ham | 744e653 | 2016-01-12 10:21:48 +0000 | [diff] [blame] | 6597 | if (shell->allow_zap) |
| 6598 | weston_compositor_add_key_binding(ec, KEY_BACKSPACE, |
| 6599 | MODIFIER_CTRL | MODIFIER_ALT, |
| 6600 | terminate_binding, ec); |
| 6601 | |
Tiago Vignatti | 0b52d48 | 2012-04-20 18:54:25 +0300 | [diff] [blame] | 6602 | /* fixed bindings */ |
Daniel Stone | 325fc2d | 2012-05-30 16:31:58 +0100 | [diff] [blame] | 6603 | weston_compositor_add_button_binding(ec, BTN_LEFT, 0, |
| 6604 | click_to_activate_binding, |
| 6605 | shell); |
Kristian Høgsberg | f0ce581 | 2014-04-07 11:52:17 -0700 | [diff] [blame] | 6606 | weston_compositor_add_button_binding(ec, BTN_RIGHT, 0, |
| 6607 | click_to_activate_binding, |
| 6608 | shell); |
Neil Roberts | a28c693 | 2013-10-03 16:43:04 +0100 | [diff] [blame] | 6609 | weston_compositor_add_touch_binding(ec, 0, |
| 6610 | touch_to_activate_binding, |
| 6611 | shell); |
Daniel Stone | 325fc2d | 2012-05-30 16:31:58 +0100 | [diff] [blame] | 6612 | weston_compositor_add_axis_binding(ec, WL_POINTER_AXIS_VERTICAL_SCROLL, |
| 6613 | MODIFIER_SUPER | MODIFIER_ALT, |
| 6614 | surface_opacity_binding, NULL); |
| 6615 | weston_compositor_add_axis_binding(ec, WL_POINTER_AXIS_VERTICAL_SCROLL, |
| 6616 | MODIFIER_SUPER, zoom_axis_binding, |
| 6617 | NULL); |
Bob Ham | 553d124 | 2016-01-12 10:21:49 +0000 | [diff] [blame] | 6618 | weston_compositor_add_key_binding(ec, KEY_BRIGHTNESSDOWN, 0, |
| 6619 | backlight_binding, ec); |
| 6620 | weston_compositor_add_key_binding(ec, KEY_BRIGHTNESSUP, 0, |
| 6621 | backlight_binding, ec); |
Tiago Vignatti | 0b52d48 | 2012-04-20 18:54:25 +0300 | [diff] [blame] | 6622 | |
| 6623 | /* configurable bindings */ |
Bob Ham | 553d124 | 2016-01-12 10:21:49 +0000 | [diff] [blame] | 6624 | if (shell->exposay_modifier) |
| 6625 | weston_compositor_add_modifier_binding(ec, shell->exposay_modifier, |
| 6626 | exposay_binding, shell); |
| 6627 | |
Tiago Vignatti | 0b52d48 | 2012-04-20 18:54:25 +0300 | [diff] [blame] | 6628 | mod = shell->binding_modifier; |
Bob Ham | 553d124 | 2016-01-12 10:21:49 +0000 | [diff] [blame] | 6629 | if (!mod) |
| 6630 | return; |
| 6631 | |
Daniel Stone | 325fc2d | 2012-05-30 16:31:58 +0100 | [diff] [blame] | 6632 | weston_compositor_add_key_binding(ec, KEY_PAGEUP, mod, |
| 6633 | zoom_key_binding, NULL); |
| 6634 | weston_compositor_add_key_binding(ec, KEY_PAGEDOWN, mod, |
| 6635 | zoom_key_binding, NULL); |
Kristian Høgsberg | 211b517 | 2014-01-11 13:10:21 -0800 | [diff] [blame] | 6636 | weston_compositor_add_key_binding(ec, KEY_M, mod | MODIFIER_SHIFT, |
| 6637 | maximize_binding, NULL); |
| 6638 | weston_compositor_add_key_binding(ec, KEY_F, mod | MODIFIER_SHIFT, |
| 6639 | fullscreen_binding, NULL); |
Daniel Stone | 325fc2d | 2012-05-30 16:31:58 +0100 | [diff] [blame] | 6640 | weston_compositor_add_button_binding(ec, BTN_LEFT, mod, move_binding, |
| 6641 | shell); |
Neil Roberts | aba0f25 | 2013-10-03 16:43:05 +0100 | [diff] [blame] | 6642 | weston_compositor_add_touch_binding(ec, mod, touch_move_binding, shell); |
Derek Foreman | 2217f3f | 2015-06-25 16:03:30 -0500 | [diff] [blame] | 6643 | weston_compositor_add_button_binding(ec, BTN_RIGHT, mod, |
Daniel Stone | 325fc2d | 2012-05-30 16:31:58 +0100 | [diff] [blame] | 6644 | resize_binding, shell); |
Kristian Høgsberg | 0837fa9 | 2014-01-20 10:35:26 -0800 | [diff] [blame] | 6645 | weston_compositor_add_button_binding(ec, BTN_LEFT, |
| 6646 | mod | MODIFIER_SHIFT, |
| 6647 | resize_binding, shell); |
Pekka Paalanen | 7bb6510 | 2013-05-22 18:03:04 +0300 | [diff] [blame] | 6648 | |
| 6649 | if (ec->capabilities & WESTON_CAP_ROTATION_ANY) |
Derek Foreman | 2217f3f | 2015-06-25 16:03:30 -0500 | [diff] [blame] | 6650 | weston_compositor_add_button_binding(ec, BTN_MIDDLE, mod, |
Pekka Paalanen | 7bb6510 | 2013-05-22 18:03:04 +0300 | [diff] [blame] | 6651 | rotate_binding, NULL); |
| 6652 | |
Daniel Stone | 325fc2d | 2012-05-30 16:31:58 +0100 | [diff] [blame] | 6653 | weston_compositor_add_key_binding(ec, KEY_TAB, mod, switcher_binding, |
| 6654 | shell); |
| 6655 | weston_compositor_add_key_binding(ec, KEY_F9, mod, backlight_binding, |
| 6656 | ec); |
Daniel Stone | 325fc2d | 2012-05-30 16:31:58 +0100 | [diff] [blame] | 6657 | weston_compositor_add_key_binding(ec, KEY_F10, mod, backlight_binding, |
| 6658 | ec); |
Daniel Stone | 325fc2d | 2012-05-30 16:31:58 +0100 | [diff] [blame] | 6659 | weston_compositor_add_key_binding(ec, KEY_K, mod, |
| 6660 | force_kill_binding, shell); |
Jonas Ådahl | e3cddce | 2012-06-13 00:01:22 +0200 | [diff] [blame] | 6661 | weston_compositor_add_key_binding(ec, KEY_UP, mod, |
| 6662 | workspace_up_binding, shell); |
| 6663 | weston_compositor_add_key_binding(ec, KEY_DOWN, mod, |
| 6664 | workspace_down_binding, shell); |
Jonas Ådahl | 8de6a1d | 2012-08-29 22:13:00 +0200 | [diff] [blame] | 6665 | weston_compositor_add_key_binding(ec, KEY_UP, mod | MODIFIER_SHIFT, |
| 6666 | workspace_move_surface_up_binding, |
| 6667 | shell); |
| 6668 | weston_compositor_add_key_binding(ec, KEY_DOWN, mod | MODIFIER_SHIFT, |
| 6669 | workspace_move_surface_down_binding, |
| 6670 | shell); |
Jonas Ådahl | e3cddce | 2012-06-13 00:01:22 +0200 | [diff] [blame] | 6671 | |
| 6672 | /* Add bindings for mod+F[1-6] for workspace 1 to 6. */ |
| 6673 | if (shell->workspaces.num > 1) { |
| 6674 | num_workspace_bindings = shell->workspaces.num; |
| 6675 | if (num_workspace_bindings > 6) |
| 6676 | num_workspace_bindings = 6; |
| 6677 | for (i = 0; i < num_workspace_bindings; i++) |
| 6678 | weston_compositor_add_key_binding(ec, KEY_F1 + i, mod, |
| 6679 | workspace_f_binding, |
| 6680 | shell); |
| 6681 | } |
Ander Conselvan de Oliveira | c509d2b | 2012-11-08 17:20:45 +0200 | [diff] [blame] | 6682 | |
Pekka Paalanen | 2829f7c | 2015-02-19 17:02:13 +0200 | [diff] [blame] | 6683 | weston_install_debug_key_binding(ec, mod); |
Tiago Vignatti | 0b52d48 | 2012-04-20 18:54:25 +0300 | [diff] [blame] | 6684 | } |
| 6685 | |
Jason Ekstrand | 024177c | 2014-04-21 19:42:58 -0500 | [diff] [blame] | 6686 | static void |
| 6687 | handle_seat_created(struct wl_listener *listener, void *data) |
| 6688 | { |
| 6689 | struct weston_seat *seat = data; |
| 6690 | |
| 6691 | create_shell_seat(seat); |
| 6692 | } |
| 6693 | |
Kristian Høgsberg | 1c56218 | 2011-05-02 22:09:20 -0400 | [diff] [blame] | 6694 | WL_EXPORT int |
Kristian Høgsberg | cb4685b | 2013-02-20 15:37:49 -0500 | [diff] [blame] | 6695 | module_init(struct weston_compositor *ec, |
Ossama Othman | a50e6e4 | 2013-05-14 09:48:26 -0700 | [diff] [blame] | 6696 | int *argc, char *argv[]) |
Kristian Høgsberg | 4cca349 | 2011-01-18 07:53:49 -0500 | [diff] [blame] | 6697 | { |
Kristian Høgsberg | f4d2f23 | 2012-08-10 10:05:39 -0400 | [diff] [blame] | 6698 | struct weston_seat *seat; |
Tiago Vignatti | be14326 | 2012-04-16 17:31:41 +0300 | [diff] [blame] | 6699 | struct desktop_shell *shell; |
Jonas Ådahl | e3cddce | 2012-06-13 00:01:22 +0200 | [diff] [blame] | 6700 | struct workspace **pws; |
| 6701 | unsigned int i; |
Tiago Vignatti | b7dbbd6 | 2012-09-25 17:57:01 +0300 | [diff] [blame] | 6702 | struct wl_event_loop *loop; |
Kristian Høgsberg | 02ec0a5 | 2011-04-23 13:04:11 -0400 | [diff] [blame] | 6703 | |
Peter Hutterer | f3d6227 | 2013-08-08 11:57:05 +1000 | [diff] [blame] | 6704 | shell = zalloc(sizeof *shell); |
Kristian Høgsberg | 02ec0a5 | 2011-04-23 13:04:11 -0400 | [diff] [blame] | 6705 | if (shell == NULL) |
| 6706 | return -1; |
| 6707 | |
Kristian Høgsberg | 7584062 | 2011-09-06 13:48:16 -0400 | [diff] [blame] | 6708 | shell->compositor = ec; |
Kristian Høgsberg | 02e79dc | 2012-04-12 09:55:26 -0400 | [diff] [blame] | 6709 | |
| 6710 | shell->destroy_listener.notify = shell_destroy; |
| 6711 | wl_signal_add(&ec->destroy_signal, &shell->destroy_listener); |
Ander Conselvan de Oliveira | a457563 | 2013-02-21 18:35:23 +0200 | [diff] [blame] | 6712 | shell->idle_listener.notify = idle_handler; |
| 6713 | wl_signal_add(&ec->idle_signal, &shell->idle_listener); |
| 6714 | shell->wake_listener.notify = wake_handler; |
| 6715 | wl_signal_add(&ec->wake_signal, &shell->wake_listener); |
Giulio Camuffo | f05d18f | 2015-12-11 20:57:05 +0200 | [diff] [blame] | 6716 | shell->transform_listener.notify = transform_handler; |
| 6717 | wl_signal_add(&ec->transform_signal, &shell->transform_listener); |
Kristian Høgsberg | 677a5f5 | 2013-12-04 11:00:19 -0800 | [diff] [blame] | 6718 | |
Kristian Høgsberg | 82a1d11 | 2012-07-19 14:02:00 -0400 | [diff] [blame] | 6719 | ec->shell_interface.shell = shell; |
Tiago Vignatti | bc052c9 | 2012-04-19 16:18:18 +0300 | [diff] [blame] | 6720 | ec->shell_interface.create_shell_surface = create_shell_surface; |
| 6721 | ec->shell_interface.set_toplevel = set_toplevel; |
Tiago Vignatti | 491bac1 | 2012-05-18 16:37:43 -0400 | [diff] [blame] | 6722 | ec->shell_interface.set_transient = set_transient; |
Kristian Høgsberg | 4779241 | 2014-05-04 13:47:06 -0700 | [diff] [blame] | 6723 | ec->shell_interface.set_fullscreen = shell_interface_set_fullscreen; |
Tiago Vignatti | fb2adba | 2013-06-12 15:43:21 -0300 | [diff] [blame] | 6724 | ec->shell_interface.set_xwayland = set_xwayland; |
Kristian Høgsberg | ae356ae | 2014-04-29 16:03:54 -0700 | [diff] [blame] | 6725 | ec->shell_interface.move = shell_interface_move; |
Derek Foreman | 8fbebbd | 2015-07-15 13:00:40 -0500 | [diff] [blame] | 6726 | ec->shell_interface.resize = shell_interface_resize; |
Giulio Camuffo | 62942ad | 2013-09-11 18:20:47 +0200 | [diff] [blame] | 6727 | ec->shell_interface.set_title = set_title; |
Jasper St. Pierre | ccf48fb | 2014-05-02 10:21:38 -0400 | [diff] [blame] | 6728 | ec->shell_interface.set_window_geometry = set_window_geometry; |
Giulio Camuffo | 6b4b241 | 2015-01-29 19:06:49 +0200 | [diff] [blame] | 6729 | ec->shell_interface.set_maximized = shell_interface_set_maximized; |
Giulio Camuffo | a8e9b41 | 2015-01-27 19:10:37 +0200 | [diff] [blame] | 6730 | ec->shell_interface.set_pid = set_pid; |
Quentin Glidic | 5c20195 | 2016-03-23 13:50:49 +0100 | [diff] [blame] | 6731 | ec->shell_interface.get_output_work_area = get_output_work_area; |
Kristian Høgsberg | 4cca349 | 2011-01-18 07:53:49 -0500 | [diff] [blame] | 6732 | |
Kristian Høgsberg | 3be2ce9 | 2012-02-29 12:42:35 -0500 | [diff] [blame] | 6733 | weston_layer_init(&shell->fullscreen_layer, &ec->cursor_layer.link); |
| 6734 | weston_layer_init(&shell->panel_layer, &shell->fullscreen_layer.link); |
Jonas Ådahl | e3cddce | 2012-06-13 00:01:22 +0200 | [diff] [blame] | 6735 | weston_layer_init(&shell->background_layer, &shell->panel_layer.link); |
| 6736 | weston_layer_init(&shell->lock_layer, NULL); |
Philipp Brüschweiler | 711fda8 | 2012-08-09 18:50:43 +0200 | [diff] [blame] | 6737 | weston_layer_init(&shell->input_panel_layer, NULL); |
Jonas Ådahl | e3cddce | 2012-06-13 00:01:22 +0200 | [diff] [blame] | 6738 | |
| 6739 | wl_array_init(&shell->workspaces.array); |
Jonas Ådahl | e9d2250 | 2012-08-29 22:13:01 +0200 | [diff] [blame] | 6740 | wl_list_init(&shell->workspaces.client_list); |
Kristian Høgsberg | 3be2ce9 | 2012-02-29 12:42:35 -0500 | [diff] [blame] | 6741 | |
Kristian Høgsberg | 677a5f5 | 2013-12-04 11:00:19 -0800 | [diff] [blame] | 6742 | if (input_panel_setup(shell) < 0) |
| 6743 | return -1; |
| 6744 | |
Pekka Paalanen | aa9536a | 2015-06-24 16:09:17 +0300 | [diff] [blame] | 6745 | shell->text_backend = text_backend_init(ec); |
| 6746 | if (!shell->text_backend) |
Murray Calavera | 9a51cd7 | 2015-06-10 21:16:02 +0000 | [diff] [blame] | 6747 | return -1; |
| 6748 | |
Kristian Høgsberg | 14e438c | 2013-05-26 21:48:14 -0400 | [diff] [blame] | 6749 | shell_configuration(shell); |
Pekka Paalanen | e955f1e | 2011-12-07 11:49:52 +0200 | [diff] [blame] | 6750 | |
Daniel Stone | df8133b | 2013-11-19 11:37:14 +0100 | [diff] [blame] | 6751 | shell->exposay.state_cur = EXPOSAY_LAYOUT_INACTIVE; |
| 6752 | shell->exposay.state_target = EXPOSAY_TARGET_CANCEL; |
| 6753 | |
Jonas Ådahl | e3cddce | 2012-06-13 00:01:22 +0200 | [diff] [blame] | 6754 | for (i = 0; i < shell->workspaces.num; i++) { |
| 6755 | pws = wl_array_add(&shell->workspaces.array, sizeof *pws); |
| 6756 | if (pws == NULL) |
| 6757 | return -1; |
| 6758 | |
| 6759 | *pws = workspace_create(); |
| 6760 | if (*pws == NULL) |
| 6761 | return -1; |
| 6762 | } |
| 6763 | activate_workspace(shell, 0); |
| 6764 | |
Manuel Bachmann | 50c87db | 2014-02-26 15:52:13 +0100 | [diff] [blame] | 6765 | weston_layer_init(&shell->minimized_layer, NULL); |
| 6766 | |
Jonas Ådahl | 8de6a1d | 2012-08-29 22:13:00 +0200 | [diff] [blame] | 6767 | wl_list_init(&shell->workspaces.anim_sticky_list); |
Jonas Ådahl | 62fcd04 | 2012-06-13 00:01:23 +0200 | [diff] [blame] | 6768 | wl_list_init(&shell->workspaces.animation.link); |
| 6769 | shell->workspaces.animation.frame = animate_workspace_change_frame; |
| 6770 | |
Kristian Høgsberg | 919cddb | 2013-07-08 19:03:57 -0400 | [diff] [blame] | 6771 | if (wl_global_create(ec->wl_display, &wl_shell_interface, 1, |
Kristian Høgsberg | 97d44aa | 2011-08-26 17:21:20 -0400 | [diff] [blame] | 6772 | shell, bind_shell) == NULL) |
Kristian Høgsberg | 4cca349 | 2011-01-18 07:53:49 -0500 | [diff] [blame] | 6773 | return -1; |
| 6774 | |
Rafael Antognolli | e2a3455 | 2013-12-03 15:35:45 -0200 | [diff] [blame] | 6775 | if (wl_global_create(ec->wl_display, &xdg_shell_interface, 1, |
| 6776 | shell, bind_xdg_shell) == NULL) |
| 6777 | return -1; |
| 6778 | |
Kristian Høgsberg | 919cddb | 2013-07-08 19:03:57 -0400 | [diff] [blame] | 6779 | if (wl_global_create(ec->wl_display, |
Jonas Ådahl | 6d6fb61 | 2015-11-17 16:00:33 +0800 | [diff] [blame] | 6780 | &weston_desktop_shell_interface, 1, |
Kristian Høgsberg | 919cddb | 2013-07-08 19:03:57 -0400 | [diff] [blame] | 6781 | shell, bind_desktop_shell) == NULL) |
Kristian Høgsberg | 7584062 | 2011-09-06 13:48:16 -0400 | [diff] [blame] | 6782 | return -1; |
| 6783 | |
Kristian Høgsberg | f03a616 | 2012-01-17 11:07:42 -0500 | [diff] [blame] | 6784 | shell->child.deathstamp = weston_compositor_get_time(); |
Tiago Vignatti | b7dbbd6 | 2012-09-25 17:57:01 +0300 | [diff] [blame] | 6785 | |
Jonas Ådahl | 6d6fb61 | 2015-11-17 16:00:33 +0800 | [diff] [blame] | 6786 | shell->panel_position = WESTON_DESKTOP_SHELL_PANEL_POSITION_TOP; |
Jonny Lamb | 765760d | 2014-08-20 15:53:19 +0200 | [diff] [blame] | 6787 | |
Xiong Zhang | 6b48142 | 2013-10-23 13:58:32 +0800 | [diff] [blame] | 6788 | setup_output_destroy_handler(ec, shell); |
| 6789 | |
Tiago Vignatti | b7dbbd6 | 2012-09-25 17:57:01 +0300 | [diff] [blame] | 6790 | loop = wl_display_get_event_loop(ec->wl_display); |
| 6791 | wl_event_loop_add_idle(loop, launch_desktop_shell_process, shell); |
Pekka Paalanen | 6cd281a | 2011-11-03 14:11:32 +0200 | [diff] [blame] | 6792 | |
Jason Ekstrand | 024177c | 2014-04-21 19:42:58 -0500 | [diff] [blame] | 6793 | wl_list_for_each(seat, &ec->seat_list, link) |
| 6794 | handle_seat_created(NULL, seat); |
| 6795 | shell->seat_create_listener.notify = handle_seat_created; |
| 6796 | wl_signal_add(&ec->seat_created_signal, &shell->seat_create_listener); |
Kristian Høgsberg | d56bd90 | 2012-06-05 09:58:51 -0400 | [diff] [blame] | 6797 | |
David Fort | 50d962f | 2016-06-09 17:55:52 +0200 | [diff] [blame] | 6798 | shell->resized_listener.notify = handle_output_resized; |
| 6799 | wl_signal_add(&ec->output_resized_signal, &shell->resized_listener); |
| 6800 | |
Giulio Camuffo | c6ab3d5 | 2013-12-11 23:45:12 +0100 | [diff] [blame] | 6801 | screenshooter_create(ec); |
| 6802 | |
Tiago Vignatti | 0b52d48 | 2012-04-20 18:54:25 +0300 | [diff] [blame] | 6803 | shell_add_bindings(ec, shell); |
Kristian Høgsberg | 0793756 | 2011-04-12 17:25:42 -0400 | [diff] [blame] | 6804 | |
Pekka Paalanen | 79346ab | 2013-05-22 18:03:09 +0300 | [diff] [blame] | 6805 | shell_fade_init(shell); |
Ander Conselvan de Oliveira | 19d10ef | 2013-02-21 18:35:20 +0200 | [diff] [blame] | 6806 | |
Pekka Paalanen | 2e62e4a | 2014-08-28 11:41:26 +0300 | [diff] [blame] | 6807 | clock_gettime(CLOCK_MONOTONIC, &shell->startup_time); |
| 6808 | |
Kristian Høgsberg | 4cca349 | 2011-01-18 07:53:49 -0500 | [diff] [blame] | 6809 | return 0; |
| 6810 | } |