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" |
Kristian Høgsberg | 7584062 | 2011-09-06 13:48:16 -0400 | [diff] [blame] | 39 | #include "desktop-shell-server-protocol.h" |
Jonas Ådahl | e9d2250 | 2012-08-29 22:13:01 +0200 | [diff] [blame] | 40 | #include "workspaces-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" |
Rafael Antognolli | e2a3455 | 2013-12-03 15:35:45 -0200 | [diff] [blame] | 43 | #include "xdg-shell-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; |
Rafael Antognolli | 3c4e3f7 | 2013-12-03 15:35:46 -0200 | [diff] [blame] | 128 | int32_t saved_width, saved_height; |
Alex Wu | 4539b08 | 2012-03-01 12:57:46 +0800 | [diff] [blame] | 129 | bool saved_position_valid; |
Rafael Antognolli | 3c4e3f7 | 2013-12-03 15:35:46 -0200 | [diff] [blame] | 130 | bool saved_size_valid; |
Alex Wu | 7bcb8bd | 2012-04-27 09:07:24 +0800 | [diff] [blame] | 131 | bool saved_rotation_valid; |
Kristian Høgsberg | c85f1d4 | 2013-10-24 16:52:00 -0700 | [diff] [blame] | 132 | int unresponsive, grabbed; |
Kristian Høgsberg | 44cd196 | 2014-02-05 21:36:04 -0800 | [diff] [blame] | 133 | uint32_t resize_edges; |
Benjamin Franzke | d0f79ab | 2011-11-22 12:43:52 +0100 | [diff] [blame] | 134 | |
Kristian Høgsberg | b3cca0a | 2012-01-04 22:19:14 -0500 | [diff] [blame] | 135 | struct { |
Pekka Paalanen | 460099f | 2012-01-20 16:48:25 +0200 | [diff] [blame] | 136 | struct weston_transform transform; |
Kristian Høgsberg | 765e27b | 2012-01-27 13:36:13 -0500 | [diff] [blame] | 137 | struct weston_matrix rotation; |
Pekka Paalanen | 460099f | 2012-01-20 16:48:25 +0200 | [diff] [blame] | 138 | } rotation; |
| 139 | |
| 140 | struct { |
Giulio Camuffo | 5085a75 | 2013-03-25 21:42:45 +0100 | [diff] [blame] | 141 | struct wl_list grab_link; |
Kristian Høgsberg | b3cca0a | 2012-01-04 22:19:14 -0500 | [diff] [blame] | 142 | int32_t x, y; |
Giulio Camuffo | 5085a75 | 2013-03-25 21:42:45 +0100 | [diff] [blame] | 143 | struct shell_seat *shseat; |
Kristian Høgsberg | 3730f36 | 2012-04-13 12:40:07 -0400 | [diff] [blame] | 144 | uint32_t serial; |
Kristian Høgsberg | b3cca0a | 2012-01-04 22:19:14 -0500 | [diff] [blame] | 145 | } popup; |
| 146 | |
Alex Wu | 4539b08 | 2012-03-01 12:57:46 +0800 | [diff] [blame] | 147 | struct { |
Tiago Vignatti | 52e598c | 2012-05-07 15:23:08 +0300 | [diff] [blame] | 148 | int32_t x, y; |
Tiago Vignatti | 491bac1 | 2012-05-18 16:37:43 -0400 | [diff] [blame] | 149 | uint32_t flags; |
Tiago Vignatti | 52e598c | 2012-05-07 15:23:08 +0300 | [diff] [blame] | 150 | } transient; |
| 151 | |
| 152 | struct { |
Alex Wu | 4539b08 | 2012-03-01 12:57:46 +0800 | [diff] [blame] | 153 | enum wl_shell_surface_fullscreen_method type; |
| 154 | struct weston_transform transform; /* matrix from x, y */ |
| 155 | uint32_t framerate; |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 156 | struct weston_view *black_view; |
Alex Wu | 4539b08 | 2012-03-01 12:57:46 +0800 | [diff] [blame] | 157 | } fullscreen; |
| 158 | |
Jonas Ådahl | 62fcd04 | 2012-06-13 00:01:23 +0200 | [diff] [blame] | 159 | struct weston_transform workspace_transform; |
| 160 | |
Kristian Høgsberg | 1cbf326 | 2012-02-17 23:49:07 -0500 | [diff] [blame] | 161 | struct weston_output *fullscreen_output; |
Kristian Høgsberg | 8334bc1 | 2012-01-03 10:29:47 -0500 | [diff] [blame] | 162 | struct weston_output *output; |
Benjamin Franzke | d0f79ab | 2011-11-22 12:43:52 +0100 | [diff] [blame] | 163 | struct wl_list link; |
Kristian Høgsberg | a61ca06 | 2012-05-22 16:05:52 -0400 | [diff] [blame] | 164 | |
| 165 | const struct weston_shell_client *client; |
Rafael Antognolli | 03b1659 | 2013-12-03 15:35:42 -0200 | [diff] [blame] | 166 | |
Jasper St. Pierre | 6458ec3 | 2014-04-11 16:00:31 -0700 | [diff] [blame] | 167 | struct surface_state { |
Rafael Antognolli | 03b1659 | 2013-12-03 15:35:42 -0200 | [diff] [blame] | 168 | bool maximized; |
| 169 | bool fullscreen; |
Rafael Antognolli | ed207b4 | 2013-12-03 15:35:43 -0200 | [diff] [blame] | 170 | bool relative; |
Emilio Pozuelo Monfort | 9e7c759 | 2014-01-30 14:01:10 +0100 | [diff] [blame] | 171 | bool lowered; |
Jasper St. Pierre | 8c6aa45 | 2014-02-08 18:29:49 -0500 | [diff] [blame] | 172 | } state, next_state, requested_state; /* surface states */ |
Rafael Antognolli | 03b1659 | 2013-12-03 15:35:42 -0200 | [diff] [blame] | 173 | bool state_changed; |
Jasper St. Pierre | 8c6aa45 | 2014-02-08 18:29:49 -0500 | [diff] [blame] | 174 | bool state_requested; |
Jasper St. Pierre | faf27a9 | 2013-12-09 17:36:28 -0500 | [diff] [blame] | 175 | |
Kristian Høgsberg | ae356ae | 2014-04-29 16:03:54 -0700 | [diff] [blame] | 176 | struct { |
Jasper St. Pierre | ccf48fb | 2014-05-02 10:21:38 -0400 | [diff] [blame] | 177 | int32_t x, y, width, height; |
| 178 | } geometry, next_geometry; |
| 179 | bool has_set_geometry, has_next_geometry; |
Kristian Høgsberg | ae356ae | 2014-04-29 16:03:54 -0700 | [diff] [blame] | 180 | |
Jasper St. Pierre | faf27a9 | 2013-12-09 17:36:28 -0500 | [diff] [blame] | 181 | int focus_count; |
Derek Foreman | 039e9be | 2015-04-14 17:09:06 -0500 | [diff] [blame] | 182 | |
| 183 | bool destroying; |
Pekka Paalanen | 56cdea9 | 2011-11-23 16:14:12 +0200 | [diff] [blame] | 184 | }; |
| 185 | |
Ander Conselvan de Oliveira | fe0444a | 2012-04-04 17:48:05 +0300 | [diff] [blame] | 186 | struct shell_grab { |
Kristian Høgsberg | 02bbabb | 2013-05-06 22:15:05 -0400 | [diff] [blame] | 187 | struct weston_pointer_grab grab; |
Ander Conselvan de Oliveira | fe0444a | 2012-04-04 17:48:05 +0300 | [diff] [blame] | 188 | struct shell_surface *shsurf; |
| 189 | struct wl_listener shsurf_destroy_listener; |
| 190 | }; |
| 191 | |
Rusty Lynch | 1084da5 | 2013-08-15 09:10:08 -0700 | [diff] [blame] | 192 | struct shell_touch_grab { |
| 193 | struct weston_touch_grab grab; |
| 194 | struct shell_surface *shsurf; |
| 195 | struct wl_listener shsurf_destroy_listener; |
| 196 | struct weston_touch *touch; |
| 197 | }; |
| 198 | |
Ander Conselvan de Oliveira | fe0444a | 2012-04-04 17:48:05 +0300 | [diff] [blame] | 199 | struct weston_move_grab { |
| 200 | struct shell_grab base; |
Daniel Stone | 103db7f | 2012-05-08 17:17:55 +0100 | [diff] [blame] | 201 | wl_fixed_t dx, dy; |
Derek Foreman | cf7d95a | 2015-06-03 15:53:22 -0500 | [diff] [blame] | 202 | bool client_initiated; |
Kristian Høgsberg | 4cca349 | 2011-01-18 07:53:49 -0500 | [diff] [blame] | 203 | }; |
| 204 | |
Rusty Lynch | 1084da5 | 2013-08-15 09:10:08 -0700 | [diff] [blame] | 205 | struct weston_touch_move_grab { |
| 206 | struct shell_touch_grab base; |
Kristian Høgsberg | 8e80a31 | 2014-01-17 15:18:10 -0800 | [diff] [blame] | 207 | int active; |
Rusty Lynch | 1084da5 | 2013-08-15 09:10:08 -0700 | [diff] [blame] | 208 | wl_fixed_t dx, dy; |
| 209 | }; |
| 210 | |
Pekka Paalanen | 460099f | 2012-01-20 16:48:25 +0200 | [diff] [blame] | 211 | struct rotate_grab { |
Ander Conselvan de Oliveira | fe0444a | 2012-04-04 17:48:05 +0300 | [diff] [blame] | 212 | struct shell_grab base; |
Kristian Høgsberg | 765e27b | 2012-01-27 13:36:13 -0500 | [diff] [blame] | 213 | struct weston_matrix rotation; |
Pekka Paalanen | 460099f | 2012-01-20 16:48:25 +0200 | [diff] [blame] | 214 | struct { |
John Kåre Alsaker | 490d02a | 2012-09-30 02:57:21 +0200 | [diff] [blame] | 215 | float x; |
| 216 | float y; |
Pekka Paalanen | 460099f | 2012-01-20 16:48:25 +0200 | [diff] [blame] | 217 | } center; |
| 218 | }; |
| 219 | |
Giulio Camuffo | 5085a75 | 2013-03-25 21:42:45 +0100 | [diff] [blame] | 220 | struct shell_seat { |
| 221 | struct weston_seat *seat; |
| 222 | struct wl_listener seat_destroy_listener; |
Jasper St. Pierre | faf27a9 | 2013-12-09 17:36:28 -0500 | [diff] [blame] | 223 | struct weston_surface *focused_surface; |
Giulio Camuffo | 5085a75 | 2013-03-25 21:42:45 +0100 | [diff] [blame] | 224 | |
Jason Ekstrand | 024177c | 2014-04-21 19:42:58 -0500 | [diff] [blame] | 225 | struct wl_listener caps_changed_listener; |
| 226 | struct wl_listener pointer_focus_listener; |
| 227 | struct wl_listener keyboard_focus_listener; |
| 228 | |
Giulio Camuffo | 5085a75 | 2013-03-25 21:42:45 +0100 | [diff] [blame] | 229 | struct { |
Kristian Høgsberg | 02bbabb | 2013-05-06 22:15:05 -0400 | [diff] [blame] | 230 | struct weston_pointer_grab grab; |
Jonny Lamb | 76cf1fe | 2014-08-20 11:27:10 +0200 | [diff] [blame] | 231 | struct weston_touch_grab touch_grab; |
Giulio Camuffo | 5085a75 | 2013-03-25 21:42:45 +0100 | [diff] [blame] | 232 | struct wl_list surfaces_list; |
| 233 | struct wl_client *client; |
| 234 | int32_t initial_up; |
Jonny Lamb | 76cf1fe | 2014-08-20 11:27:10 +0200 | [diff] [blame] | 235 | enum { POINTER, TOUCH } type; |
Giulio Camuffo | 5085a75 | 2013-03-25 21:42:45 +0100 | [diff] [blame] | 236 | } popup_grab; |
| 237 | }; |
| 238 | |
Kristian Høgsberg | 2bff94e | 2014-02-11 12:22:51 -0800 | [diff] [blame] | 239 | struct shell_client { |
| 240 | struct wl_resource *resource; |
| 241 | struct wl_client *client; |
| 242 | struct desktop_shell *shell; |
| 243 | struct wl_listener destroy_listener; |
| 244 | struct wl_event_source *ping_timer; |
| 245 | uint32_t ping_serial; |
| 246 | int unresponsive; |
Jonas Ådahl | 49d77d2 | 2015-03-18 16:20:51 +0800 | [diff] [blame] | 247 | struct wl_list surface_list; |
Kristian Høgsberg | 2bff94e | 2014-02-11 12:22:51 -0800 | [diff] [blame] | 248 | }; |
| 249 | |
Alex Wu | bd3354b | 2012-04-17 17:20:49 +0800 | [diff] [blame] | 250 | static struct desktop_shell * |
| 251 | shell_surface_get_shell(struct shell_surface *shsurf); |
| 252 | |
Kristian Høgsberg | 0c36903 | 2013-02-14 21:31:44 -0500 | [diff] [blame] | 253 | static void |
Derek Foreman | 74de469 | 2015-07-15 13:00:39 -0500 | [diff] [blame] | 254 | surface_rotate(struct shell_surface *surface, struct weston_pointer *pointer); |
Kristian Høgsberg | 0c36903 | 2013-02-14 21:31:44 -0500 | [diff] [blame] | 255 | |
Pekka Paalanen | 79346ab | 2013-05-22 18:03:09 +0300 | [diff] [blame] | 256 | static void |
| 257 | shell_fade_startup(struct desktop_shell *shell); |
| 258 | |
Philip Withnall | becb77e | 2013-11-25 18:01:30 +0000 | [diff] [blame] | 259 | static struct shell_seat * |
| 260 | get_shell_seat(struct weston_seat *seat); |
| 261 | |
Jonny Lamb | d73c694 | 2014-08-20 15:53:20 +0200 | [diff] [blame] | 262 | static void |
| 263 | get_output_panel_size(struct desktop_shell *shell, |
| 264 | struct weston_output *output, |
| 265 | int *width, int *height); |
Kristian Høgsberg | ae356ae | 2014-04-29 16:03:54 -0700 | [diff] [blame] | 266 | |
Philip Withnall | 648a4dd | 2013-11-25 18:01:44 +0000 | [diff] [blame] | 267 | static void |
| 268 | shell_surface_update_child_surface_layers(struct shell_surface *shsurf); |
| 269 | |
Alex Wu | bd3354b | 2012-04-17 17:20:49 +0800 | [diff] [blame] | 270 | static bool |
Rafael Antognolli | e2a3455 | 2013-12-03 15:35:45 -0200 | [diff] [blame] | 271 | shell_surface_is_wl_shell_surface(struct shell_surface *shsurf); |
| 272 | |
| 273 | static bool |
| 274 | shell_surface_is_xdg_surface(struct shell_surface *shsurf); |
| 275 | |
| 276 | static bool |
| 277 | shell_surface_is_xdg_popup(struct shell_surface *shsurf); |
| 278 | |
| 279 | static void |
| 280 | shell_surface_set_parent(struct shell_surface *shsurf, |
| 281 | struct weston_surface *parent); |
| 282 | |
Pekka Paalanen | 8274d90 | 2014-08-06 19:36:51 +0300 | [diff] [blame] | 283 | static int |
| 284 | shell_surface_get_label(struct weston_surface *surface, char *buf, size_t len) |
| 285 | { |
| 286 | struct shell_surface *shsurf; |
| 287 | const char *typestr[] = { |
| 288 | [SHELL_SURFACE_NONE] = "unidentified", |
| 289 | [SHELL_SURFACE_TOPLEVEL] = "top-level", |
| 290 | [SHELL_SURFACE_POPUP] = "popup", |
| 291 | [SHELL_SURFACE_XWAYLAND] = "Xwayland", |
| 292 | }; |
| 293 | const char *t, *c; |
| 294 | |
| 295 | shsurf = get_shell_surface(surface); |
| 296 | if (!shsurf) |
| 297 | return snprintf(buf, len, "unidentified window"); |
| 298 | |
| 299 | t = shsurf->title; |
| 300 | c = shsurf->class; |
| 301 | |
| 302 | return snprintf(buf, len, "%s window%s%s%s%s%s", |
| 303 | typestr[shsurf->type], |
| 304 | t ? " '" : "", t ?: "", t ? "'" : "", |
| 305 | c ? " of " : "", c ?: ""); |
| 306 | } |
| 307 | |
Rafael Antognolli | e2a3455 | 2013-12-03 15:35:45 -0200 | [diff] [blame] | 308 | static bool |
Alex Wu | bd3354b | 2012-04-17 17:20:49 +0800 | [diff] [blame] | 309 | shell_surface_is_top_fullscreen(struct shell_surface *shsurf) |
| 310 | { |
| 311 | struct desktop_shell *shell; |
Mario Kleiner | 9f4d655 | 2015-06-21 21:25:08 +0200 | [diff] [blame] | 312 | struct weston_view *view; |
| 313 | struct shell_surface *top_fs_shsurf = NULL; |
Alex Wu | bd3354b | 2012-04-17 17:20:49 +0800 | [diff] [blame] | 314 | |
| 315 | shell = shell_surface_get_shell(shsurf); |
Quentin Glidic | c0d79ce | 2013-01-29 14:16:13 +0100 | [diff] [blame] | 316 | |
Giulio Camuffo | 412e6a5 | 2014-07-09 22:12:56 +0300 | [diff] [blame] | 317 | if (wl_list_empty(&shell->fullscreen_layer.view_list.link)) |
Alex Wu | bd3354b | 2012-04-17 17:20:49 +0800 | [diff] [blame] | 318 | return false; |
| 319 | |
Mario Kleiner | 9f4d655 | 2015-06-21 21:25:08 +0200 | [diff] [blame] | 320 | /* Find topmost shsurf on the same fullscreen output on which shsurf |
| 321 | * is displaying. We don't care about other outputs. |
| 322 | */ |
| 323 | wl_list_for_each(view, &shell->fullscreen_layer.view_list.link, |
| 324 | layer_link.link) { |
| 325 | struct shell_surface *cand_shsurf = get_shell_surface(view->surface); |
| 326 | |
| 327 | if (cand_shsurf && |
| 328 | (cand_shsurf->fullscreen_output == shsurf->fullscreen_output)) { |
| 329 | top_fs_shsurf = cand_shsurf; |
| 330 | break; |
| 331 | } |
| 332 | } |
| 333 | |
| 334 | return (shsurf == top_fs_shsurf); |
Alex Wu | bd3354b | 2012-04-17 17:20:49 +0800 | [diff] [blame] | 335 | } |
| 336 | |
Kristian Høgsberg | 6af8eb9 | 2012-01-25 16:57:11 -0500 | [diff] [blame] | 337 | static void |
Kristian Høgsberg | 27e3052 | 2012-04-11 23:18:23 -0400 | [diff] [blame] | 338 | destroy_shell_grab_shsurf(struct wl_listener *listener, void *data) |
Ander Conselvan de Oliveira | fe0444a | 2012-04-04 17:48:05 +0300 | [diff] [blame] | 339 | { |
| 340 | struct shell_grab *grab; |
| 341 | |
| 342 | grab = container_of(listener, struct shell_grab, |
| 343 | shsurf_destroy_listener); |
| 344 | |
| 345 | grab->shsurf = NULL; |
| 346 | } |
| 347 | |
Kristian Høgsberg | 1ef2313 | 2013-12-04 00:20:01 -0800 | [diff] [blame] | 348 | struct weston_view * |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 349 | get_default_view(struct weston_surface *surface) |
| 350 | { |
| 351 | struct shell_surface *shsurf; |
| 352 | struct weston_view *view; |
| 353 | |
| 354 | if (!surface || wl_list_empty(&surface->views)) |
| 355 | return NULL; |
| 356 | |
| 357 | shsurf = get_shell_surface(surface); |
| 358 | if (shsurf) |
| 359 | return shsurf->view; |
| 360 | |
| 361 | wl_list_for_each(view, &surface->views, surface_link) |
| 362 | if (weston_view_is_mapped(view)) |
| 363 | return view; |
| 364 | |
| 365 | return container_of(surface->views.next, struct weston_view, surface_link); |
| 366 | } |
| 367 | |
Ander Conselvan de Oliveira | fe0444a | 2012-04-04 17:48:05 +0300 | [diff] [blame] | 368 | static void |
Kristian Høgsberg | 02bbabb | 2013-05-06 22:15:05 -0400 | [diff] [blame] | 369 | popup_grab_end(struct weston_pointer *pointer); |
Jonny Lamb | 76cf1fe | 2014-08-20 11:27:10 +0200 | [diff] [blame] | 370 | static void |
| 371 | touch_popup_grab_end(struct weston_touch *touch); |
Kristian Høgsberg | 57e0907 | 2012-10-30 14:07:27 -0400 | [diff] [blame] | 372 | |
| 373 | static void |
Ander Conselvan de Oliveira | b9d2a0f | 2012-06-28 18:08:05 +0300 | [diff] [blame] | 374 | shell_grab_start(struct shell_grab *grab, |
Kristian Høgsberg | 02bbabb | 2013-05-06 22:15:05 -0400 | [diff] [blame] | 375 | const struct weston_pointer_grab_interface *interface, |
Ander Conselvan de Oliveira | b9d2a0f | 2012-06-28 18:08:05 +0300 | [diff] [blame] | 376 | struct shell_surface *shsurf, |
Kristian Høgsberg | 02bbabb | 2013-05-06 22:15:05 -0400 | [diff] [blame] | 377 | struct weston_pointer *pointer, |
Ander Conselvan de Oliveira | b9d2a0f | 2012-06-28 18:08:05 +0300 | [diff] [blame] | 378 | enum desktop_shell_cursor cursor) |
Ander Conselvan de Oliveira | fe0444a | 2012-04-04 17:48:05 +0300 | [diff] [blame] | 379 | { |
Ander Conselvan de Oliveira | b9d2a0f | 2012-06-28 18:08:05 +0300 | [diff] [blame] | 380 | struct desktop_shell *shell = shsurf->shell; |
Derek Foreman | 1281a36 | 2015-07-31 16:55:32 -0500 | [diff] [blame] | 381 | struct weston_touch *touch = weston_seat_get_touch(pointer->seat); |
Ander Conselvan de Oliveira | b9d2a0f | 2012-06-28 18:08:05 +0300 | [diff] [blame] | 382 | |
Kristian Høgsberg | 57e0907 | 2012-10-30 14:07:27 -0400 | [diff] [blame] | 383 | popup_grab_end(pointer); |
Derek Foreman | 1281a36 | 2015-07-31 16:55:32 -0500 | [diff] [blame] | 384 | if (touch) |
| 385 | touch_popup_grab_end(touch); |
Kristian Høgsberg | 57e0907 | 2012-10-30 14:07:27 -0400 | [diff] [blame] | 386 | |
Ander Conselvan de Oliveira | fe0444a | 2012-04-04 17:48:05 +0300 | [diff] [blame] | 387 | grab->grab.interface = interface; |
| 388 | grab->shsurf = shsurf; |
Kristian Høgsberg | 27e3052 | 2012-04-11 23:18:23 -0400 | [diff] [blame] | 389 | grab->shsurf_destroy_listener.notify = destroy_shell_grab_shsurf; |
Jason Ekstrand | 651f00e | 2013-06-14 10:07:54 -0500 | [diff] [blame] | 390 | wl_signal_add(&shsurf->destroy_signal, |
Kristian Høgsberg | 27e3052 | 2012-04-11 23:18:23 -0400 | [diff] [blame] | 391 | &grab->shsurf_destroy_listener); |
Ander Conselvan de Oliveira | fe0444a | 2012-04-04 17:48:05 +0300 | [diff] [blame] | 392 | |
Kristian Høgsberg | c85f1d4 | 2013-10-24 16:52:00 -0700 | [diff] [blame] | 393 | shsurf->grabbed = 1; |
Kristian Høgsberg | 02bbabb | 2013-05-06 22:15:05 -0400 | [diff] [blame] | 394 | weston_pointer_start_grab(pointer, &grab->grab); |
Kristian Høgsberg | c9974a0 | 2013-07-03 19:24:57 -0400 | [diff] [blame] | 395 | if (shell->child.desktop_shell) { |
| 396 | desktop_shell_send_grab_cursor(shell->child.desktop_shell, |
| 397 | cursor); |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 398 | weston_pointer_set_focus(pointer, |
| 399 | get_default_view(shell->grab_surface), |
Kristian Høgsberg | c9974a0 | 2013-07-03 19:24:57 -0400 | [diff] [blame] | 400 | wl_fixed_from_int(0), |
| 401 | wl_fixed_from_int(0)); |
| 402 | } |
Ander Conselvan de Oliveira | fe0444a | 2012-04-04 17:48:05 +0300 | [diff] [blame] | 403 | } |
| 404 | |
Jonny Lamb | d73c694 | 2014-08-20 15:53:20 +0200 | [diff] [blame] | 405 | static void |
| 406 | get_output_panel_size(struct desktop_shell *shell, |
| 407 | struct weston_output *output, |
| 408 | int *width, |
| 409 | int *height) |
Jasper St. Pierre | 6458ec3 | 2014-04-11 16:00:31 -0700 | [diff] [blame] | 410 | { |
| 411 | struct weston_view *view; |
Jonny Lamb | d73c694 | 2014-08-20 15:53:20 +0200 | [diff] [blame] | 412 | |
| 413 | *width = 0; |
| 414 | *height = 0; |
Jasper St. Pierre | 6458ec3 | 2014-04-11 16:00:31 -0700 | [diff] [blame] | 415 | |
| 416 | if (!output) |
Jonny Lamb | d73c694 | 2014-08-20 15:53:20 +0200 | [diff] [blame] | 417 | return; |
Jasper St. Pierre | 6458ec3 | 2014-04-11 16:00:31 -0700 | [diff] [blame] | 418 | |
Giulio Camuffo | 412e6a5 | 2014-07-09 22:12:56 +0300 | [diff] [blame] | 419 | 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] | 420 | float x, y; |
| 421 | |
| 422 | if (view->surface->output != output) |
| 423 | continue; |
| 424 | |
| 425 | switch (shell->panel_position) { |
| 426 | case DESKTOP_SHELL_PANEL_POSITION_TOP: |
| 427 | case DESKTOP_SHELL_PANEL_POSITION_BOTTOM: |
Jonny Lamb | d73c694 | 2014-08-20 15:53:20 +0200 | [diff] [blame] | 428 | weston_view_to_global_float(view, |
| 429 | view->surface->width, 0, |
| 430 | &x, &y); |
| 431 | |
Derek Foreman | 612341f | 2015-04-15 12:23:55 -0500 | [diff] [blame] | 432 | *width = (int)x - output->x; |
| 433 | *height = view->surface->height + (int) y - output->y; |
Jonny Lamb | d73c694 | 2014-08-20 15:53:20 +0200 | [diff] [blame] | 434 | return; |
| 435 | |
| 436 | case DESKTOP_SHELL_PANEL_POSITION_LEFT: |
| 437 | case DESKTOP_SHELL_PANEL_POSITION_RIGHT: |
| 438 | weston_view_to_global_float(view, |
| 439 | 0, view->surface->height, |
| 440 | &x, &y); |
| 441 | |
Derek Foreman | 612341f | 2015-04-15 12:23:55 -0500 | [diff] [blame] | 442 | *width = view->surface->width + (int)x - output->x; |
| 443 | *height = (int)y - output->y; |
Jonny Lamb | d73c694 | 2014-08-20 15:53:20 +0200 | [diff] [blame] | 444 | return; |
| 445 | |
| 446 | default: |
| 447 | /* we've already set width and height to |
| 448 | * fallback values. */ |
Jasper St. Pierre | 6458ec3 | 2014-04-11 16:00:31 -0700 | [diff] [blame] | 449 | break; |
| 450 | } |
| 451 | } |
| 452 | |
Jonny Lamb | d73c694 | 2014-08-20 15:53:20 +0200 | [diff] [blame] | 453 | /* the correct view wasn't found */ |
| 454 | } |
| 455 | |
| 456 | static void |
| 457 | get_output_work_area(struct desktop_shell *shell, |
| 458 | struct weston_output *output, |
| 459 | pixman_rectangle32_t *area) |
| 460 | { |
| 461 | int32_t panel_width = 0, panel_height = 0; |
| 462 | |
Derek Foreman | f814c5d | 2015-04-15 12:23:54 -0500 | [diff] [blame] | 463 | area->x = output->x; |
| 464 | area->y = output->y; |
Jonny Lamb | d73c694 | 2014-08-20 15:53:20 +0200 | [diff] [blame] | 465 | |
| 466 | get_output_panel_size(shell, output, &panel_width, &panel_height); |
Jonny Lamb | d73c694 | 2014-08-20 15:53:20 +0200 | [diff] [blame] | 467 | switch (shell->panel_position) { |
| 468 | case DESKTOP_SHELL_PANEL_POSITION_TOP: |
| 469 | default: |
Derek Foreman | f814c5d | 2015-04-15 12:23:54 -0500 | [diff] [blame] | 470 | area->y += panel_height; |
Jonny Lamb | d73c694 | 2014-08-20 15:53:20 +0200 | [diff] [blame] | 471 | case DESKTOP_SHELL_PANEL_POSITION_BOTTOM: |
| 472 | area->width = output->width; |
| 473 | area->height = output->height - panel_height; |
| 474 | break; |
| 475 | case DESKTOP_SHELL_PANEL_POSITION_LEFT: |
Derek Foreman | f814c5d | 2015-04-15 12:23:54 -0500 | [diff] [blame] | 476 | area->x += panel_width; |
Jonny Lamb | d73c694 | 2014-08-20 15:53:20 +0200 | [diff] [blame] | 477 | case DESKTOP_SHELL_PANEL_POSITION_RIGHT: |
| 478 | area->width = output->width - panel_width; |
| 479 | area->height = output->height; |
| 480 | break; |
| 481 | } |
Jasper St. Pierre | 6458ec3 | 2014-04-11 16:00:31 -0700 | [diff] [blame] | 482 | } |
| 483 | |
Derek Foreman | 45a7c27 | 2015-09-11 14:27:40 -0500 | [diff] [blame] | 484 | static struct shell_surface * |
| 485 | find_toplevel_surface(struct shell_surface *in_surface) |
| 486 | { |
| 487 | struct shell_surface *surface = in_surface; |
| 488 | |
Ben Hummon | 445e44c | 2015-10-06 11:48:14 -0500 | [diff] [blame^] | 489 | while (surface) { |
| 490 | if (surface->type == SHELL_SURFACE_TOPLEVEL) |
| 491 | return surface; |
Derek Foreman | 45a7c27 | 2015-09-11 14:27:40 -0500 | [diff] [blame] | 492 | surface = get_shell_surface(surface->parent); |
Ben Hummon | 445e44c | 2015-10-06 11:48:14 -0500 | [diff] [blame^] | 493 | } |
Derek Foreman | 45a7c27 | 2015-09-11 14:27:40 -0500 | [diff] [blame] | 494 | |
| 495 | /* If no top level surface was found, just use whatever surface was |
| 496 | originally provided. */ |
Ben Hummon | 445e44c | 2015-10-06 11:48:14 -0500 | [diff] [blame^] | 497 | return in_surface; |
Derek Foreman | 45a7c27 | 2015-09-11 14:27:40 -0500 | [diff] [blame] | 498 | } |
| 499 | |
Jasper St. Pierre | 6458ec3 | 2014-04-11 16:00:31 -0700 | [diff] [blame] | 500 | static void |
| 501 | send_configure_for_surface(struct shell_surface *shsurf) |
| 502 | { |
| 503 | int32_t width, height; |
| 504 | struct surface_state *state; |
| 505 | |
| 506 | if (shsurf->state_requested) |
| 507 | state = &shsurf->requested_state; |
| 508 | else if (shsurf->state_changed) |
| 509 | state = &shsurf->next_state; |
| 510 | else |
| 511 | state = &shsurf->state; |
| 512 | |
| 513 | if (state->fullscreen) { |
| 514 | width = shsurf->output->width; |
| 515 | height = shsurf->output->height; |
| 516 | } else if (state->maximized) { |
| 517 | struct desktop_shell *shell; |
Jonny Lamb | d73c694 | 2014-08-20 15:53:20 +0200 | [diff] [blame] | 518 | pixman_rectangle32_t area; |
Jasper St. Pierre | 6458ec3 | 2014-04-11 16:00:31 -0700 | [diff] [blame] | 519 | |
| 520 | shell = shell_surface_get_shell(shsurf); |
Jonny Lamb | d73c694 | 2014-08-20 15:53:20 +0200 | [diff] [blame] | 521 | get_output_work_area(shell, shsurf->output, &area); |
Jasper St. Pierre | 6458ec3 | 2014-04-11 16:00:31 -0700 | [diff] [blame] | 522 | |
Jonny Lamb | d73c694 | 2014-08-20 15:53:20 +0200 | [diff] [blame] | 523 | width = area.width; |
| 524 | height = area.height; |
Ryo Munakata | 79954ec | 2015-05-02 21:44:04 +0900 | [diff] [blame] | 525 | } else if (shsurf->resize_edges) { |
| 526 | width = shsurf->geometry.width; |
| 527 | height = shsurf->geometry.height; |
Jasper St. Pierre | 6458ec3 | 2014-04-11 16:00:31 -0700 | [diff] [blame] | 528 | } else { |
| 529 | width = 0; |
| 530 | height = 0; |
| 531 | } |
| 532 | |
| 533 | shsurf->client->send_configure(shsurf->surface, width, height); |
| 534 | } |
| 535 | |
Ander Conselvan de Oliveira | fe0444a | 2012-04-04 17:48:05 +0300 | [diff] [blame] | 536 | static void |
Jasper St. Pierre | 5befdda | 2014-05-06 08:50:47 -0400 | [diff] [blame] | 537 | shell_surface_state_changed(struct shell_surface *shsurf) |
| 538 | { |
Jasper St. Pierre | 6458ec3 | 2014-04-11 16:00:31 -0700 | [diff] [blame] | 539 | if (shell_surface_is_xdg_surface(shsurf)) |
| 540 | send_configure_for_surface(shsurf); |
Jasper St. Pierre | 5befdda | 2014-05-06 08:50:47 -0400 | [diff] [blame] | 541 | } |
| 542 | |
| 543 | static void |
Ander Conselvan de Oliveira | b9d2a0f | 2012-06-28 18:08:05 +0300 | [diff] [blame] | 544 | shell_grab_end(struct shell_grab *grab) |
Ander Conselvan de Oliveira | fe0444a | 2012-04-04 17:48:05 +0300 | [diff] [blame] | 545 | { |
Kristian Høgsberg | c85f1d4 | 2013-10-24 16:52:00 -0700 | [diff] [blame] | 546 | if (grab->shsurf) { |
Kristian Høgsberg | 47b5dca | 2012-06-07 18:08:04 -0400 | [diff] [blame] | 547 | wl_list_remove(&grab->shsurf_destroy_listener.link); |
Kristian Høgsberg | c85f1d4 | 2013-10-24 16:52:00 -0700 | [diff] [blame] | 548 | grab->shsurf->grabbed = 0; |
Jasper St. Pierre | 5befdda | 2014-05-06 08:50:47 -0400 | [diff] [blame] | 549 | |
| 550 | if (grab->shsurf->resize_edges) { |
| 551 | grab->shsurf->resize_edges = 0; |
| 552 | shell_surface_state_changed(grab->shsurf); |
| 553 | } |
Kristian Høgsberg | c85f1d4 | 2013-10-24 16:52:00 -0700 | [diff] [blame] | 554 | } |
Ander Conselvan de Oliveira | b9d2a0f | 2012-06-28 18:08:05 +0300 | [diff] [blame] | 555 | |
Kristian Høgsberg | 9e5d7d1 | 2013-07-22 16:31:53 -0700 | [diff] [blame] | 556 | weston_pointer_end_grab(grab->grab.pointer); |
Ander Conselvan de Oliveira | fe0444a | 2012-04-04 17:48:05 +0300 | [diff] [blame] | 557 | } |
| 558 | |
| 559 | static void |
Rusty Lynch | 1084da5 | 2013-08-15 09:10:08 -0700 | [diff] [blame] | 560 | shell_touch_grab_start(struct shell_touch_grab *grab, |
| 561 | const struct weston_touch_grab_interface *interface, |
| 562 | struct shell_surface *shsurf, |
| 563 | struct weston_touch *touch) |
| 564 | { |
| 565 | struct desktop_shell *shell = shsurf->shell; |
Derek Foreman | 1281a36 | 2015-07-31 16:55:32 -0500 | [diff] [blame] | 566 | struct weston_pointer *pointer = weston_seat_get_pointer(touch->seat); |
U. Artie Eoff | cf5737a | 2014-01-17 10:08:25 -0800 | [diff] [blame] | 567 | |
Jonny Lamb | 76cf1fe | 2014-08-20 11:27:10 +0200 | [diff] [blame] | 568 | touch_popup_grab_end(touch); |
Derek Foreman | 1281a36 | 2015-07-31 16:55:32 -0500 | [diff] [blame] | 569 | if (pointer) |
| 570 | popup_grab_end(pointer); |
Kristian Høgsberg | 74071e0 | 2014-04-29 15:01:16 -0700 | [diff] [blame] | 571 | |
Rusty Lynch | 1084da5 | 2013-08-15 09:10:08 -0700 | [diff] [blame] | 572 | grab->grab.interface = interface; |
| 573 | grab->shsurf = shsurf; |
| 574 | grab->shsurf_destroy_listener.notify = destroy_shell_grab_shsurf; |
| 575 | wl_signal_add(&shsurf->destroy_signal, |
| 576 | &grab->shsurf_destroy_listener); |
| 577 | |
| 578 | grab->touch = touch; |
Kristian Høgsberg | c85f1d4 | 2013-10-24 16:52:00 -0700 | [diff] [blame] | 579 | shsurf->grabbed = 1; |
Rusty Lynch | 1084da5 | 2013-08-15 09:10:08 -0700 | [diff] [blame] | 580 | |
| 581 | weston_touch_start_grab(touch, &grab->grab); |
| 582 | if (shell->child.desktop_shell) |
Derek Foreman | 4c93c08 | 2015-04-30 16:45:41 -0500 | [diff] [blame] | 583 | weston_touch_set_focus(touch, |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 584 | get_default_view(shell->grab_surface)); |
Rusty Lynch | 1084da5 | 2013-08-15 09:10:08 -0700 | [diff] [blame] | 585 | } |
| 586 | |
| 587 | static void |
| 588 | shell_touch_grab_end(struct shell_touch_grab *grab) |
| 589 | { |
Kristian Høgsberg | c85f1d4 | 2013-10-24 16:52:00 -0700 | [diff] [blame] | 590 | if (grab->shsurf) { |
Rusty Lynch | 1084da5 | 2013-08-15 09:10:08 -0700 | [diff] [blame] | 591 | wl_list_remove(&grab->shsurf_destroy_listener.link); |
Kristian Høgsberg | c85f1d4 | 2013-10-24 16:52:00 -0700 | [diff] [blame] | 592 | grab->shsurf->grabbed = 0; |
| 593 | } |
Rusty Lynch | 1084da5 | 2013-08-15 09:10:08 -0700 | [diff] [blame] | 594 | |
| 595 | weston_touch_end_grab(grab->touch); |
| 596 | } |
| 597 | |
| 598 | static void |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 599 | center_on_output(struct weston_view *view, |
Alex Wu | 4539b08 | 2012-03-01 12:57:46 +0800 | [diff] [blame] | 600 | struct weston_output *output); |
| 601 | |
Daniel Stone | 496ca17 | 2012-05-30 16:31:42 +0100 | [diff] [blame] | 602 | static enum weston_keyboard_modifier |
Tiago Vignatti | 0b52d48 | 2012-04-20 18:54:25 +0300 | [diff] [blame] | 603 | get_modifier(char *modifier) |
| 604 | { |
| 605 | if (!modifier) |
| 606 | return MODIFIER_SUPER; |
| 607 | |
| 608 | if (!strcmp("ctrl", modifier)) |
| 609 | return MODIFIER_CTRL; |
| 610 | else if (!strcmp("alt", modifier)) |
| 611 | return MODIFIER_ALT; |
| 612 | else if (!strcmp("super", modifier)) |
| 613 | return MODIFIER_SUPER; |
| 614 | else |
| 615 | return MODIFIER_SUPER; |
| 616 | } |
| 617 | |
Juan Zhao | e10d279 | 2012-04-25 19:09:52 +0800 | [diff] [blame] | 618 | static enum animation_type |
| 619 | get_animation_type(char *animation) |
| 620 | { |
U. Artie Eoff | b571910 | 2014-01-15 14:26:31 -0800 | [diff] [blame] | 621 | if (!animation) |
| 622 | return ANIMATION_NONE; |
| 623 | |
Juan Zhao | e10d279 | 2012-04-25 19:09:52 +0800 | [diff] [blame] | 624 | if (!strcmp("zoom", animation)) |
| 625 | return ANIMATION_ZOOM; |
| 626 | else if (!strcmp("fade", animation)) |
| 627 | return ANIMATION_FADE; |
Louis-Francis Ratté-Boulianne | b482dbd | 2013-11-19 11:37:11 +0100 | [diff] [blame] | 628 | else if (!strcmp("dim-layer", animation)) |
| 629 | return ANIMATION_DIM_LAYER; |
Juan Zhao | e10d279 | 2012-04-25 19:09:52 +0800 | [diff] [blame] | 630 | else |
| 631 | return ANIMATION_NONE; |
| 632 | } |
| 633 | |
Alex Wu | 4539b08 | 2012-03-01 12:57:46 +0800 | [diff] [blame] | 634 | static void |
Kristian Høgsberg | 14e438c | 2013-05-26 21:48:14 -0400 | [diff] [blame] | 635 | shell_configuration(struct desktop_shell *shell) |
Pekka Paalanen | e955f1e | 2011-12-07 11:49:52 +0200 | [diff] [blame] | 636 | { |
Kristian Høgsberg | 673a889 | 2013-05-23 21:40:56 -0400 | [diff] [blame] | 637 | struct weston_config_section *section; |
Derek Foreman | c721043 | 2014-08-21 11:32:38 -0500 | [diff] [blame] | 638 | char *s, *client; |
Pekka Paalanen | 974c094 | 2014-09-05 14:45:09 +0300 | [diff] [blame] | 639 | int ret; |
Pekka Paalanen | e955f1e | 2011-12-07 11:49:52 +0200 | [diff] [blame] | 640 | |
Kristian Høgsberg | 673a889 | 2013-05-23 21:40:56 -0400 | [diff] [blame] | 641 | section = weston_config_get_section(shell->compositor->config, |
Kristian Høgsberg | 673a889 | 2013-05-23 21:40:56 -0400 | [diff] [blame] | 642 | "shell", NULL, NULL); |
Pekka Paalanen | 974c094 | 2014-09-05 14:45:09 +0300 | [diff] [blame] | 643 | ret = asprintf(&client, "%s/%s", weston_config_get_libexec_dir(), |
| 644 | WESTON_SHELL_CLIENT); |
| 645 | if (ret < 0) |
| 646 | client = NULL; |
Kristian Høgsberg | 673a889 | 2013-05-23 21:40:56 -0400 | [diff] [blame] | 647 | weston_config_section_get_string(section, |
Derek Foreman | c721043 | 2014-08-21 11:32:38 -0500 | [diff] [blame] | 648 | "client", &s, client); |
| 649 | free(client); |
Emilio Pozuelo Monfort | 46ce798 | 2013-11-20 13:22:29 +0100 | [diff] [blame] | 650 | shell->client = s; |
| 651 | weston_config_section_get_string(section, |
Kristian Høgsberg | 673a889 | 2013-05-23 21:40:56 -0400 | [diff] [blame] | 652 | "binding-modifier", &s, "super"); |
| 653 | shell->binding_modifier = get_modifier(s); |
Quentin Glidic | 8418c29 | 2013-06-18 09:11:03 +0200 | [diff] [blame] | 654 | free(s); |
Kristian Høgsberg | d56ab4e | 2014-01-16 16:51:52 -0800 | [diff] [blame] | 655 | |
| 656 | weston_config_section_get_string(section, |
| 657 | "exposay-modifier", &s, "none"); |
| 658 | if (strcmp(s, "none") == 0) |
| 659 | shell->exposay_modifier = 0; |
| 660 | else |
| 661 | shell->exposay_modifier = get_modifier(s); |
| 662 | free(s); |
| 663 | |
Kristian Høgsberg | 673a889 | 2013-05-23 21:40:56 -0400 | [diff] [blame] | 664 | weston_config_section_get_string(section, "animation", &s, "none"); |
| 665 | shell->win_animation_type = get_animation_type(s); |
Quentin Glidic | 8418c29 | 2013-06-18 09:11:03 +0200 | [diff] [blame] | 666 | free(s); |
Jonny Lamb | f322f8e | 2014-08-12 15:13:30 +0200 | [diff] [blame] | 667 | weston_config_section_get_string(section, "close-animation", &s, "fade"); |
| 668 | shell->win_close_animation_type = get_animation_type(s); |
| 669 | free(s); |
Kristian Høgsberg | 724c8d9 | 2013-10-16 11:38:24 -0700 | [diff] [blame] | 670 | weston_config_section_get_string(section, |
| 671 | "startup-animation", &s, "fade"); |
| 672 | shell->startup_animation_type = get_animation_type(s); |
| 673 | free(s); |
Kristian Høgsberg | 912e0a1 | 2013-10-30 08:59:55 -0700 | [diff] [blame] | 674 | if (shell->startup_animation_type == ANIMATION_ZOOM) |
| 675 | shell->startup_animation_type = ANIMATION_NONE; |
Louis-Francis Ratté-Boulianne | b482dbd | 2013-11-19 11:37:11 +0100 | [diff] [blame] | 676 | weston_config_section_get_string(section, "focus-animation", &s, "none"); |
| 677 | shell->focus_animation_type = get_animation_type(s); |
| 678 | free(s); |
Kristian Høgsberg | 673a889 | 2013-05-23 21:40:56 -0400 | [diff] [blame] | 679 | weston_config_section_get_uint(section, "num-workspaces", |
| 680 | &shell->workspaces.num, |
| 681 | DEFAULT_NUM_WORKSPACES); |
Jonas Ådahl | e3cddce | 2012-06-13 00:01:22 +0200 | [diff] [blame] | 682 | } |
| 683 | |
Kristian Høgsberg | 1ef2313 | 2013-12-04 00:20:01 -0800 | [diff] [blame] | 684 | struct weston_output * |
Louis-Francis Ratté-Boulianne | b482dbd | 2013-11-19 11:37:11 +0100 | [diff] [blame] | 685 | get_default_output(struct weston_compositor *compositor) |
| 686 | { |
| 687 | return container_of(compositor->output_list.next, |
| 688 | struct weston_output, link); |
| 689 | } |
| 690 | |
Pekka Paalanen | 8274d90 | 2014-08-06 19:36:51 +0300 | [diff] [blame] | 691 | static int |
| 692 | focus_surface_get_label(struct weston_surface *surface, char *buf, size_t len) |
| 693 | { |
| 694 | return snprintf(buf, len, "focus highlight effect for output %s", |
| 695 | surface->output->name); |
| 696 | } |
Louis-Francis Ratté-Boulianne | b482dbd | 2013-11-19 11:37:11 +0100 | [diff] [blame] | 697 | |
| 698 | /* no-op func for checking focus surface */ |
| 699 | static void |
Jason Ekstrand | 918f2dd | 2013-12-02 21:01:53 -0600 | [diff] [blame] | 700 | 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] | 701 | { |
| 702 | } |
| 703 | |
| 704 | static struct focus_surface * |
| 705 | get_focus_surface(struct weston_surface *surface) |
| 706 | { |
| 707 | if (surface->configure == focus_surface_configure) |
| 708 | return surface->configure_private; |
| 709 | else |
| 710 | return NULL; |
| 711 | } |
| 712 | |
| 713 | static bool |
| 714 | is_focus_surface (struct weston_surface *es) |
| 715 | { |
| 716 | return (es->configure == focus_surface_configure); |
| 717 | } |
| 718 | |
| 719 | static bool |
| 720 | is_focus_view (struct weston_view *view) |
| 721 | { |
| 722 | return is_focus_surface (view->surface); |
| 723 | } |
| 724 | |
| 725 | static struct focus_surface * |
| 726 | create_focus_surface(struct weston_compositor *ec, |
| 727 | struct weston_output *output) |
| 728 | { |
| 729 | struct focus_surface *fsurf = NULL; |
| 730 | struct weston_surface *surface = NULL; |
| 731 | |
| 732 | fsurf = malloc(sizeof *fsurf); |
| 733 | if (!fsurf) |
| 734 | return NULL; |
| 735 | |
| 736 | fsurf->surface = weston_surface_create(ec); |
| 737 | surface = fsurf->surface; |
| 738 | if (surface == NULL) { |
| 739 | free(fsurf); |
| 740 | return NULL; |
| 741 | } |
| 742 | |
| 743 | surface->configure = focus_surface_configure; |
| 744 | surface->output = output; |
| 745 | surface->configure_private = fsurf; |
Pekka Paalanen | 8274d90 | 2014-08-06 19:36:51 +0300 | [diff] [blame] | 746 | weston_surface_set_label_func(surface, focus_surface_get_label); |
Louis-Francis Ratté-Boulianne | b482dbd | 2013-11-19 11:37:11 +0100 | [diff] [blame] | 747 | |
U. Artie Eoff | 0b23b2b | 2014-01-15 14:45:59 -0800 | [diff] [blame] | 748 | fsurf->view = weston_view_create(surface); |
| 749 | if (fsurf->view == NULL) { |
| 750 | weston_surface_destroy(surface); |
| 751 | free(fsurf); |
| 752 | return NULL; |
| 753 | } |
Emilio Pozuelo Monfort | da64426 | 2013-11-19 11:37:19 +0100 | [diff] [blame] | 754 | fsurf->view->output = output; |
Louis-Francis Ratté-Boulianne | b482dbd | 2013-11-19 11:37:11 +0100 | [diff] [blame] | 755 | |
Jason Ekstrand | 5c11a33 | 2013-12-04 20:32:03 -0600 | [diff] [blame] | 756 | weston_surface_set_size(surface, output->width, output->height); |
Jason Ekstrand | 918f2dd | 2013-12-02 21:01:53 -0600 | [diff] [blame] | 757 | weston_view_set_position(fsurf->view, output->x, output->y); |
Louis-Francis Ratté-Boulianne | b482dbd | 2013-11-19 11:37:11 +0100 | [diff] [blame] | 758 | weston_surface_set_color(surface, 0.0, 0.0, 0.0, 1.0); |
| 759 | pixman_region32_fini(&surface->opaque); |
| 760 | pixman_region32_init_rect(&surface->opaque, output->x, output->y, |
| 761 | output->width, output->height); |
| 762 | pixman_region32_fini(&surface->input); |
| 763 | pixman_region32_init(&surface->input); |
| 764 | |
| 765 | wl_list_init(&fsurf->workspace_transform.link); |
| 766 | |
| 767 | return fsurf; |
| 768 | } |
| 769 | |
| 770 | static void |
| 771 | focus_surface_destroy(struct focus_surface *fsurf) |
| 772 | { |
| 773 | weston_surface_destroy(fsurf->surface); |
| 774 | free(fsurf); |
| 775 | } |
| 776 | |
| 777 | static void |
| 778 | focus_animation_done(struct weston_view_animation *animation, void *data) |
| 779 | { |
| 780 | struct workspace *ws = data; |
| 781 | |
| 782 | ws->focus_animation = NULL; |
| 783 | } |
| 784 | |
Jonas Ådahl | e3cddce | 2012-06-13 00:01:22 +0200 | [diff] [blame] | 785 | static void |
Jonas Ådahl | 0476974 | 2012-06-13 00:01:24 +0200 | [diff] [blame] | 786 | focus_state_destroy(struct focus_state *state) |
| 787 | { |
| 788 | wl_list_remove(&state->seat_destroy_listener.link); |
| 789 | wl_list_remove(&state->surface_destroy_listener.link); |
| 790 | free(state); |
| 791 | } |
| 792 | |
| 793 | static void |
| 794 | focus_state_seat_destroy(struct wl_listener *listener, void *data) |
| 795 | { |
| 796 | struct focus_state *state = container_of(listener, |
| 797 | struct focus_state, |
| 798 | seat_destroy_listener); |
| 799 | |
| 800 | wl_list_remove(&state->link); |
| 801 | focus_state_destroy(state); |
| 802 | } |
| 803 | |
| 804 | static void |
| 805 | focus_state_surface_destroy(struct wl_listener *listener, void *data) |
| 806 | { |
| 807 | struct focus_state *state = container_of(listener, |
| 808 | struct focus_state, |
Kristian Høgsberg | b8e0d0f | 2012-07-31 10:30:26 -0400 | [diff] [blame] | 809 | surface_destroy_listener); |
Kristian Høgsberg | e377822 | 2012-07-31 17:29:30 -0400 | [diff] [blame] | 810 | struct desktop_shell *shell; |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 811 | struct weston_surface *main_surface, *next; |
| 812 | struct weston_view *view; |
Jonas Ådahl | 0476974 | 2012-06-13 00:01:24 +0200 | [diff] [blame] | 813 | |
Pekka Paalanen | 01388e2 | 2013-04-25 13:57:44 +0300 | [diff] [blame] | 814 | main_surface = weston_surface_get_main_surface(state->keyboard_focus); |
| 815 | |
Kristian Høgsberg | e377822 | 2012-07-31 17:29:30 -0400 | [diff] [blame] | 816 | next = NULL; |
Giulio Camuffo | 412e6a5 | 2014-07-09 22:12:56 +0300 | [diff] [blame] | 817 | wl_list_for_each(view, |
| 818 | &state->ws->layer.view_list.link, layer_link.link) { |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 819 | if (view->surface == main_surface) |
Kristian Høgsberg | e377822 | 2012-07-31 17:29:30 -0400 | [diff] [blame] | 820 | continue; |
Louis-Francis Ratté-Boulianne | b482dbd | 2013-11-19 11:37:11 +0100 | [diff] [blame] | 821 | if (is_focus_view(view)) |
| 822 | continue; |
Kristian Høgsberg | e377822 | 2012-07-31 17:29:30 -0400 | [diff] [blame] | 823 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 824 | next = view->surface; |
Kristian Høgsberg | e377822 | 2012-07-31 17:29:30 -0400 | [diff] [blame] | 825 | break; |
| 826 | } |
| 827 | |
Pekka Paalanen | 01388e2 | 2013-04-25 13:57:44 +0300 | [diff] [blame] | 828 | /* if the focus was a sub-surface, activate its main surface */ |
| 829 | if (main_surface != state->keyboard_focus) |
| 830 | next = main_surface; |
| 831 | |
Louis-Francis Ratté-Boulianne | b482dbd | 2013-11-19 11:37:11 +0100 | [diff] [blame] | 832 | shell = state->seat->compositor->shell_interface.shell; |
Kristian Høgsberg | e377822 | 2012-07-31 17:29:30 -0400 | [diff] [blame] | 833 | if (next) { |
Louis-Francis Ratté-Boulianne | b482dbd | 2013-11-19 11:37:11 +0100 | [diff] [blame] | 834 | state->keyboard_focus = NULL; |
Emilio Pozuelo Monfort | 9e7c759 | 2014-01-30 14:01:10 +0100 | [diff] [blame] | 835 | activate(shell, next, state->seat, true); |
Kristian Høgsberg | e377822 | 2012-07-31 17:29:30 -0400 | [diff] [blame] | 836 | } else { |
Louis-Francis Ratté-Boulianne | b482dbd | 2013-11-19 11:37:11 +0100 | [diff] [blame] | 837 | if (shell->focus_animation_type == ANIMATION_DIM_LAYER) { |
| 838 | if (state->ws->focus_animation) |
| 839 | weston_view_animation_destroy(state->ws->focus_animation); |
| 840 | |
| 841 | state->ws->focus_animation = weston_fade_run( |
| 842 | state->ws->fsurf_front->view, |
| 843 | state->ws->fsurf_front->view->alpha, 0.0, 300, |
| 844 | focus_animation_done, state->ws); |
| 845 | } |
| 846 | |
Kristian Høgsberg | e377822 | 2012-07-31 17:29:30 -0400 | [diff] [blame] | 847 | wl_list_remove(&state->link); |
| 848 | focus_state_destroy(state); |
| 849 | } |
Jonas Ådahl | 0476974 | 2012-06-13 00:01:24 +0200 | [diff] [blame] | 850 | } |
| 851 | |
| 852 | static struct focus_state * |
Kristian Høgsberg | 2f5faff | 2012-07-31 16:36:34 -0400 | [diff] [blame] | 853 | focus_state_create(struct weston_seat *seat, struct workspace *ws) |
Jonas Ådahl | 0476974 | 2012-06-13 00:01:24 +0200 | [diff] [blame] | 854 | { |
Jonas Ådahl | 0476974 | 2012-06-13 00:01:24 +0200 | [diff] [blame] | 855 | struct focus_state *state; |
Jonas Ådahl | 0476974 | 2012-06-13 00:01:24 +0200 | [diff] [blame] | 856 | |
| 857 | state = malloc(sizeof *state); |
| 858 | if (state == NULL) |
| 859 | return NULL; |
| 860 | |
Louis-Francis Ratté-Boulianne | b482dbd | 2013-11-19 11:37:11 +0100 | [diff] [blame] | 861 | state->keyboard_focus = NULL; |
Kristian Høgsberg | 2f5faff | 2012-07-31 16:36:34 -0400 | [diff] [blame] | 862 | state->ws = ws; |
Jonas Ådahl | 0476974 | 2012-06-13 00:01:24 +0200 | [diff] [blame] | 863 | state->seat = seat; |
Kristian Høgsberg | 2f5faff | 2012-07-31 16:36:34 -0400 | [diff] [blame] | 864 | wl_list_insert(&ws->focus_list, &state->link); |
Jonas Ådahl | 0476974 | 2012-06-13 00:01:24 +0200 | [diff] [blame] | 865 | |
| 866 | state->seat_destroy_listener.notify = focus_state_seat_destroy; |
| 867 | state->surface_destroy_listener.notify = focus_state_surface_destroy; |
Kristian Høgsberg | 4912454 | 2013-05-06 22:27:40 -0400 | [diff] [blame] | 868 | wl_signal_add(&seat->destroy_signal, |
Jonas Ådahl | 0476974 | 2012-06-13 00:01:24 +0200 | [diff] [blame] | 869 | &state->seat_destroy_listener); |
Kristian Høgsberg | 2f5faff | 2012-07-31 16:36:34 -0400 | [diff] [blame] | 870 | wl_list_init(&state->surface_destroy_listener.link); |
Jonas Ådahl | 0476974 | 2012-06-13 00:01:24 +0200 | [diff] [blame] | 871 | |
| 872 | return state; |
| 873 | } |
| 874 | |
Jonas Ådahl | 8538b22 | 2012-08-29 22:13:03 +0200 | [diff] [blame] | 875 | static struct focus_state * |
| 876 | ensure_focus_state(struct desktop_shell *shell, struct weston_seat *seat) |
| 877 | { |
| 878 | struct workspace *ws = get_current_workspace(shell); |
| 879 | struct focus_state *state; |
| 880 | |
| 881 | wl_list_for_each(state, &ws->focus_list, link) |
| 882 | if (state->seat == seat) |
| 883 | break; |
| 884 | |
| 885 | if (&state->link == &ws->focus_list) |
| 886 | state = focus_state_create(seat, ws); |
| 887 | |
| 888 | return state; |
| 889 | } |
| 890 | |
Jonas Ådahl | 0476974 | 2012-06-13 00:01:24 +0200 | [diff] [blame] | 891 | static void |
Kristian Høgsberg | d500bf1 | 2014-01-22 12:25:20 -0800 | [diff] [blame] | 892 | focus_state_set_focus(struct focus_state *state, |
| 893 | struct weston_surface *surface) |
| 894 | { |
| 895 | if (state->keyboard_focus) { |
| 896 | wl_list_remove(&state->surface_destroy_listener.link); |
| 897 | wl_list_init(&state->surface_destroy_listener.link); |
| 898 | } |
| 899 | |
| 900 | state->keyboard_focus = surface; |
| 901 | if (surface) |
| 902 | wl_signal_add(&surface->destroy_signal, |
| 903 | &state->surface_destroy_listener); |
| 904 | } |
| 905 | |
| 906 | static void |
Kristian Høgsberg | 2f5faff | 2012-07-31 16:36:34 -0400 | [diff] [blame] | 907 | restore_focus_state(struct desktop_shell *shell, struct workspace *ws) |
Jonas Ådahl | 0476974 | 2012-06-13 00:01:24 +0200 | [diff] [blame] | 908 | { |
| 909 | struct focus_state *state, *next; |
Kristian Høgsberg | fe7aa90 | 2013-05-08 09:54:37 -0400 | [diff] [blame] | 910 | struct weston_surface *surface; |
Neil Roberts | 4237f50 | 2014-04-09 16:33:31 +0100 | [diff] [blame] | 911 | struct wl_list pending_seat_list; |
| 912 | struct weston_seat *seat, *next_seat; |
| 913 | |
| 914 | /* Temporarily steal the list of seats so that we can keep |
| 915 | * track of the seats we've already processed */ |
| 916 | wl_list_init(&pending_seat_list); |
| 917 | wl_list_insert_list(&pending_seat_list, &shell->compositor->seat_list); |
| 918 | wl_list_init(&shell->compositor->seat_list); |
Jonas Ådahl | 0476974 | 2012-06-13 00:01:24 +0200 | [diff] [blame] | 919 | |
| 920 | wl_list_for_each_safe(state, next, &ws->focus_list, link) { |
Derek Foreman | 1281a36 | 2015-07-31 16:55:32 -0500 | [diff] [blame] | 921 | struct weston_keyboard *keyboard = |
| 922 | weston_seat_get_keyboard(state->seat); |
| 923 | |
Neil Roberts | 4237f50 | 2014-04-09 16:33:31 +0100 | [diff] [blame] | 924 | wl_list_remove(&state->seat->link); |
| 925 | wl_list_insert(&shell->compositor->seat_list, |
| 926 | &state->seat->link); |
| 927 | |
Derek Foreman | 1281a36 | 2015-07-31 16:55:32 -0500 | [diff] [blame] | 928 | if (!keyboard) |
Kristian Høgsberg | e61d2f4 | 2014-01-17 12:18:53 -0800 | [diff] [blame] | 929 | continue; |
| 930 | |
Kristian Høgsberg | fe7aa90 | 2013-05-08 09:54:37 -0400 | [diff] [blame] | 931 | surface = state->keyboard_focus; |
Jonas Ådahl | 5689944 | 2012-08-29 22:12:59 +0200 | [diff] [blame] | 932 | |
Derek Foreman | 1281a36 | 2015-07-31 16:55:32 -0500 | [diff] [blame] | 933 | weston_keyboard_set_focus(keyboard, surface); |
Jonas Ådahl | 0476974 | 2012-06-13 00:01:24 +0200 | [diff] [blame] | 934 | } |
Neil Roberts | 4237f50 | 2014-04-09 16:33:31 +0100 | [diff] [blame] | 935 | |
| 936 | /* For any remaining seats that we don't have a focus state |
| 937 | * for we'll reset the keyboard focus to NULL */ |
| 938 | wl_list_for_each_safe(seat, next_seat, &pending_seat_list, link) { |
Derek Foreman | 1281a36 | 2015-07-31 16:55:32 -0500 | [diff] [blame] | 939 | struct weston_keyboard *keyboard = |
| 940 | weston_seat_get_keyboard(seat); |
| 941 | |
Neil Roberts | 4237f50 | 2014-04-09 16:33:31 +0100 | [diff] [blame] | 942 | wl_list_insert(&shell->compositor->seat_list, &seat->link); |
| 943 | |
Derek Foreman | 1281a36 | 2015-07-31 16:55:32 -0500 | [diff] [blame] | 944 | if (!keyboard) |
Neil Roberts | 4237f50 | 2014-04-09 16:33:31 +0100 | [diff] [blame] | 945 | continue; |
| 946 | |
Derek Foreman | 1281a36 | 2015-07-31 16:55:32 -0500 | [diff] [blame] | 947 | weston_keyboard_set_focus(keyboard, NULL); |
Neil Roberts | 4237f50 | 2014-04-09 16:33:31 +0100 | [diff] [blame] | 948 | } |
Jonas Ådahl | 0476974 | 2012-06-13 00:01:24 +0200 | [diff] [blame] | 949 | } |
| 950 | |
| 951 | static void |
Jonas Ådahl | 8de6a1d | 2012-08-29 22:13:00 +0200 | [diff] [blame] | 952 | replace_focus_state(struct desktop_shell *shell, struct workspace *ws, |
| 953 | struct weston_seat *seat) |
| 954 | { |
Derek Foreman | 1281a36 | 2015-07-31 16:55:32 -0500 | [diff] [blame] | 955 | struct weston_keyboard *keyboard = weston_seat_get_keyboard(seat); |
Jonas Ådahl | 8de6a1d | 2012-08-29 22:13:00 +0200 | [diff] [blame] | 956 | struct focus_state *state; |
Jonas Ådahl | 8de6a1d | 2012-08-29 22:13:00 +0200 | [diff] [blame] | 957 | |
| 958 | wl_list_for_each(state, &ws->focus_list, link) { |
| 959 | if (state->seat == seat) { |
Derek Foreman | 1281a36 | 2015-07-31 16:55:32 -0500 | [diff] [blame] | 960 | focus_state_set_focus(state, keyboard->focus); |
Jonas Ådahl | 8de6a1d | 2012-08-29 22:13:00 +0200 | [diff] [blame] | 961 | return; |
| 962 | } |
| 963 | } |
| 964 | } |
| 965 | |
| 966 | static void |
| 967 | drop_focus_state(struct desktop_shell *shell, struct workspace *ws, |
| 968 | struct weston_surface *surface) |
| 969 | { |
| 970 | struct focus_state *state; |
| 971 | |
| 972 | wl_list_for_each(state, &ws->focus_list, link) |
| 973 | if (state->keyboard_focus == surface) |
Kristian Høgsberg | d500bf1 | 2014-01-22 12:25:20 -0800 | [diff] [blame] | 974 | focus_state_set_focus(state, NULL); |
Jonas Ådahl | 8de6a1d | 2012-08-29 22:13:00 +0200 | [diff] [blame] | 975 | } |
| 976 | |
| 977 | static void |
Louis-Francis Ratté-Boulianne | b482dbd | 2013-11-19 11:37:11 +0100 | [diff] [blame] | 978 | animate_focus_change(struct desktop_shell *shell, struct workspace *ws, |
| 979 | struct weston_view *from, struct weston_view *to) |
| 980 | { |
| 981 | struct weston_output *output; |
| 982 | bool focus_surface_created = false; |
| 983 | |
| 984 | /* FIXME: Only support dim animation using two layers */ |
| 985 | if (from == to || shell->focus_animation_type != ANIMATION_DIM_LAYER) |
| 986 | return; |
| 987 | |
| 988 | output = get_default_output(shell->compositor); |
| 989 | if (ws->fsurf_front == NULL && (from || to)) { |
| 990 | ws->fsurf_front = create_focus_surface(shell->compositor, output); |
U. Artie Eoff | 0b23b2b | 2014-01-15 14:45:59 -0800 | [diff] [blame] | 991 | if (ws->fsurf_front == NULL) |
| 992 | return; |
Louis-Francis Ratté-Boulianne | b482dbd | 2013-11-19 11:37:11 +0100 | [diff] [blame] | 993 | ws->fsurf_front->view->alpha = 0.0; |
U. Artie Eoff | 0b23b2b | 2014-01-15 14:45:59 -0800 | [diff] [blame] | 994 | |
| 995 | ws->fsurf_back = create_focus_surface(shell->compositor, output); |
| 996 | if (ws->fsurf_back == NULL) { |
| 997 | focus_surface_destroy(ws->fsurf_front); |
| 998 | return; |
| 999 | } |
Louis-Francis Ratté-Boulianne | b482dbd | 2013-11-19 11:37:11 +0100 | [diff] [blame] | 1000 | ws->fsurf_back->view->alpha = 0.0; |
U. Artie Eoff | 0b23b2b | 2014-01-15 14:45:59 -0800 | [diff] [blame] | 1001 | |
Louis-Francis Ratté-Boulianne | b482dbd | 2013-11-19 11:37:11 +0100 | [diff] [blame] | 1002 | focus_surface_created = true; |
| 1003 | } else { |
Giulio Camuffo | 412e6a5 | 2014-07-09 22:12:56 +0300 | [diff] [blame] | 1004 | weston_layer_entry_remove(&ws->fsurf_front->view->layer_link); |
| 1005 | weston_layer_entry_remove(&ws->fsurf_back->view->layer_link); |
Louis-Francis Ratté-Boulianne | b482dbd | 2013-11-19 11:37:11 +0100 | [diff] [blame] | 1006 | } |
| 1007 | |
| 1008 | if (ws->focus_animation) { |
| 1009 | weston_view_animation_destroy(ws->focus_animation); |
| 1010 | ws->focus_animation = NULL; |
| 1011 | } |
| 1012 | |
| 1013 | if (to) |
Giulio Camuffo | 412e6a5 | 2014-07-09 22:12:56 +0300 | [diff] [blame] | 1014 | weston_layer_entry_insert(&to->layer_link, |
| 1015 | &ws->fsurf_front->view->layer_link); |
Louis-Francis Ratté-Boulianne | b482dbd | 2013-11-19 11:37:11 +0100 | [diff] [blame] | 1016 | else if (from) |
Giulio Camuffo | 412e6a5 | 2014-07-09 22:12:56 +0300 | [diff] [blame] | 1017 | weston_layer_entry_insert(&ws->layer.view_list, |
| 1018 | &ws->fsurf_front->view->layer_link); |
Louis-Francis Ratté-Boulianne | b482dbd | 2013-11-19 11:37:11 +0100 | [diff] [blame] | 1019 | |
| 1020 | if (focus_surface_created) { |
| 1021 | ws->focus_animation = weston_fade_run( |
| 1022 | ws->fsurf_front->view, |
Jonny Lamb | 7e7d485 | 2014-05-22 22:41:34 +0200 | [diff] [blame] | 1023 | ws->fsurf_front->view->alpha, 0.4, 300, |
Louis-Francis Ratté-Boulianne | b482dbd | 2013-11-19 11:37:11 +0100 | [diff] [blame] | 1024 | focus_animation_done, ws); |
| 1025 | } else if (from) { |
Giulio Camuffo | 412e6a5 | 2014-07-09 22:12:56 +0300 | [diff] [blame] | 1026 | weston_layer_entry_insert(&from->layer_link, |
| 1027 | &ws->fsurf_back->view->layer_link); |
Louis-Francis Ratté-Boulianne | b482dbd | 2013-11-19 11:37:11 +0100 | [diff] [blame] | 1028 | ws->focus_animation = weston_stable_fade_run( |
| 1029 | ws->fsurf_front->view, 0.0, |
Jonny Lamb | 7e7d485 | 2014-05-22 22:41:34 +0200 | [diff] [blame] | 1030 | ws->fsurf_back->view, 0.4, |
Louis-Francis Ratté-Boulianne | b482dbd | 2013-11-19 11:37:11 +0100 | [diff] [blame] | 1031 | focus_animation_done, ws); |
| 1032 | } else if (to) { |
Giulio Camuffo | 412e6a5 | 2014-07-09 22:12:56 +0300 | [diff] [blame] | 1033 | weston_layer_entry_insert(&ws->layer.view_list, |
| 1034 | &ws->fsurf_back->view->layer_link); |
Louis-Francis Ratté-Boulianne | b482dbd | 2013-11-19 11:37:11 +0100 | [diff] [blame] | 1035 | ws->focus_animation = weston_stable_fade_run( |
| 1036 | ws->fsurf_front->view, 0.0, |
Jonny Lamb | 7e7d485 | 2014-05-22 22:41:34 +0200 | [diff] [blame] | 1037 | ws->fsurf_back->view, 0.4, |
Louis-Francis Ratté-Boulianne | b482dbd | 2013-11-19 11:37:11 +0100 | [diff] [blame] | 1038 | focus_animation_done, ws); |
| 1039 | } |
| 1040 | } |
| 1041 | |
| 1042 | static void |
Jonas Ådahl | e3cddce | 2012-06-13 00:01:22 +0200 | [diff] [blame] | 1043 | workspace_destroy(struct workspace *ws) |
| 1044 | { |
Jonas Ådahl | 0476974 | 2012-06-13 00:01:24 +0200 | [diff] [blame] | 1045 | struct focus_state *state, *next; |
| 1046 | |
| 1047 | wl_list_for_each_safe(state, next, &ws->focus_list, link) |
| 1048 | focus_state_destroy(state); |
| 1049 | |
Louis-Francis Ratté-Boulianne | b482dbd | 2013-11-19 11:37:11 +0100 | [diff] [blame] | 1050 | if (ws->fsurf_front) |
| 1051 | focus_surface_destroy(ws->fsurf_front); |
| 1052 | if (ws->fsurf_back) |
| 1053 | focus_surface_destroy(ws->fsurf_back); |
| 1054 | |
Jonas Ådahl | e3cddce | 2012-06-13 00:01:22 +0200 | [diff] [blame] | 1055 | free(ws); |
| 1056 | } |
| 1057 | |
Jonas Ådahl | 0476974 | 2012-06-13 00:01:24 +0200 | [diff] [blame] | 1058 | static void |
| 1059 | seat_destroyed(struct wl_listener *listener, void *data) |
| 1060 | { |
| 1061 | struct weston_seat *seat = data; |
| 1062 | struct focus_state *state, *next; |
| 1063 | struct workspace *ws = container_of(listener, |
| 1064 | struct workspace, |
| 1065 | seat_destroyed_listener); |
| 1066 | |
| 1067 | wl_list_for_each_safe(state, next, &ws->focus_list, link) |
| 1068 | if (state->seat == seat) |
| 1069 | wl_list_remove(&state->link); |
| 1070 | } |
| 1071 | |
Jonas Ådahl | e3cddce | 2012-06-13 00:01:22 +0200 | [diff] [blame] | 1072 | static struct workspace * |
| 1073 | workspace_create(void) |
| 1074 | { |
| 1075 | struct workspace *ws = malloc(sizeof *ws); |
| 1076 | if (ws == NULL) |
| 1077 | return NULL; |
| 1078 | |
| 1079 | weston_layer_init(&ws->layer, NULL); |
| 1080 | |
Jonas Ådahl | 0476974 | 2012-06-13 00:01:24 +0200 | [diff] [blame] | 1081 | wl_list_init(&ws->focus_list); |
| 1082 | wl_list_init(&ws->seat_destroyed_listener.link); |
| 1083 | ws->seat_destroyed_listener.notify = seat_destroyed; |
Louis-Francis Ratté-Boulianne | b482dbd | 2013-11-19 11:37:11 +0100 | [diff] [blame] | 1084 | ws->fsurf_front = NULL; |
| 1085 | ws->fsurf_back = NULL; |
| 1086 | ws->focus_animation = NULL; |
Jonas Ådahl | 0476974 | 2012-06-13 00:01:24 +0200 | [diff] [blame] | 1087 | |
Jonas Ådahl | e3cddce | 2012-06-13 00:01:22 +0200 | [diff] [blame] | 1088 | return ws; |
| 1089 | } |
| 1090 | |
Jonas Ådahl | 62fcd04 | 2012-06-13 00:01:23 +0200 | [diff] [blame] | 1091 | static int |
| 1092 | workspace_is_empty(struct workspace *ws) |
| 1093 | { |
Giulio Camuffo | 412e6a5 | 2014-07-09 22:12:56 +0300 | [diff] [blame] | 1094 | return wl_list_empty(&ws->layer.view_list.link); |
Jonas Ådahl | 62fcd04 | 2012-06-13 00:01:23 +0200 | [diff] [blame] | 1095 | } |
| 1096 | |
Jonas Ådahl | e3cddce | 2012-06-13 00:01:22 +0200 | [diff] [blame] | 1097 | static struct workspace * |
| 1098 | get_workspace(struct desktop_shell *shell, unsigned int index) |
| 1099 | { |
| 1100 | struct workspace **pws = shell->workspaces.array.data; |
Philipp Brüschweiler | 067abf6 | 2012-09-01 16:03:05 +0200 | [diff] [blame] | 1101 | assert(index < shell->workspaces.num); |
Jonas Ådahl | e3cddce | 2012-06-13 00:01:22 +0200 | [diff] [blame] | 1102 | pws += index; |
| 1103 | return *pws; |
| 1104 | } |
| 1105 | |
Kristian Høgsberg | 1ef2313 | 2013-12-04 00:20:01 -0800 | [diff] [blame] | 1106 | struct workspace * |
Jonas Ådahl | e3cddce | 2012-06-13 00:01:22 +0200 | [diff] [blame] | 1107 | get_current_workspace(struct desktop_shell *shell) |
| 1108 | { |
| 1109 | return get_workspace(shell, shell->workspaces.current); |
| 1110 | } |
| 1111 | |
| 1112 | static void |
| 1113 | activate_workspace(struct desktop_shell *shell, unsigned int index) |
| 1114 | { |
| 1115 | struct workspace *ws; |
| 1116 | |
| 1117 | ws = get_workspace(shell, index); |
| 1118 | wl_list_insert(&shell->panel_layer.link, &ws->layer.link); |
| 1119 | |
| 1120 | shell->workspaces.current = index; |
| 1121 | } |
| 1122 | |
Jonas Ådahl | 62fcd04 | 2012-06-13 00:01:23 +0200 | [diff] [blame] | 1123 | static unsigned int |
| 1124 | get_output_height(struct weston_output *output) |
| 1125 | { |
| 1126 | return abs(output->region.extents.y1 - output->region.extents.y2); |
| 1127 | } |
| 1128 | |
| 1129 | static void |
Louis-Francis Ratté-Boulianne | b482dbd | 2013-11-19 11:37:11 +0100 | [diff] [blame] | 1130 | view_translate(struct workspace *ws, struct weston_view *view, double d) |
Jonas Ådahl | 62fcd04 | 2012-06-13 00:01:23 +0200 | [diff] [blame] | 1131 | { |
Jonas Ådahl | 62fcd04 | 2012-06-13 00:01:23 +0200 | [diff] [blame] | 1132 | struct weston_transform *transform; |
| 1133 | |
Louis-Francis Ratté-Boulianne | b482dbd | 2013-11-19 11:37:11 +0100 | [diff] [blame] | 1134 | if (is_focus_view(view)) { |
| 1135 | struct focus_surface *fsurf = get_focus_surface(view->surface); |
| 1136 | transform = &fsurf->workspace_transform; |
| 1137 | } else { |
| 1138 | struct shell_surface *shsurf = get_shell_surface(view->surface); |
| 1139 | transform = &shsurf->workspace_transform; |
| 1140 | } |
| 1141 | |
Jonas Ådahl | 62fcd04 | 2012-06-13 00:01:23 +0200 | [diff] [blame] | 1142 | if (wl_list_empty(&transform->link)) |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 1143 | wl_list_insert(view->geometry.transformation_list.prev, |
Louis-Francis Ratté-Boulianne | b482dbd | 2013-11-19 11:37:11 +0100 | [diff] [blame] | 1144 | &transform->link); |
Jonas Ådahl | 62fcd04 | 2012-06-13 00:01:23 +0200 | [diff] [blame] | 1145 | |
Louis-Francis Ratté-Boulianne | b482dbd | 2013-11-19 11:37:11 +0100 | [diff] [blame] | 1146 | weston_matrix_init(&transform->matrix); |
| 1147 | weston_matrix_translate(&transform->matrix, |
Jonas Ådahl | 62fcd04 | 2012-06-13 00:01:23 +0200 | [diff] [blame] | 1148 | 0.0, d, 0.0); |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 1149 | weston_view_geometry_dirty(view); |
Jonas Ådahl | 62fcd04 | 2012-06-13 00:01:23 +0200 | [diff] [blame] | 1150 | } |
| 1151 | |
| 1152 | static void |
| 1153 | workspace_translate_out(struct workspace *ws, double fraction) |
| 1154 | { |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 1155 | struct weston_view *view; |
Jonas Ådahl | 62fcd04 | 2012-06-13 00:01:23 +0200 | [diff] [blame] | 1156 | unsigned int height; |
| 1157 | double d; |
| 1158 | |
Giulio Camuffo | 412e6a5 | 2014-07-09 22:12:56 +0300 | [diff] [blame] | 1159 | 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] | 1160 | height = get_output_height(view->surface->output); |
Jonas Ådahl | 62fcd04 | 2012-06-13 00:01:23 +0200 | [diff] [blame] | 1161 | d = height * fraction; |
| 1162 | |
Louis-Francis Ratté-Boulianne | b482dbd | 2013-11-19 11:37:11 +0100 | [diff] [blame] | 1163 | view_translate(ws, view, d); |
Jonas Ådahl | 62fcd04 | 2012-06-13 00:01:23 +0200 | [diff] [blame] | 1164 | } |
| 1165 | } |
| 1166 | |
| 1167 | static void |
| 1168 | workspace_translate_in(struct workspace *ws, double fraction) |
| 1169 | { |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 1170 | struct weston_view *view; |
Jonas Ådahl | 62fcd04 | 2012-06-13 00:01:23 +0200 | [diff] [blame] | 1171 | unsigned int height; |
| 1172 | double d; |
| 1173 | |
Giulio Camuffo | 412e6a5 | 2014-07-09 22:12:56 +0300 | [diff] [blame] | 1174 | 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] | 1175 | height = get_output_height(view->surface->output); |
Jonas Ådahl | 62fcd04 | 2012-06-13 00:01:23 +0200 | [diff] [blame] | 1176 | |
| 1177 | if (fraction > 0) |
| 1178 | d = -(height - height * fraction); |
| 1179 | else |
| 1180 | d = height + height * fraction; |
| 1181 | |
Louis-Francis Ratté-Boulianne | b482dbd | 2013-11-19 11:37:11 +0100 | [diff] [blame] | 1182 | view_translate(ws, view, d); |
Jonas Ådahl | 62fcd04 | 2012-06-13 00:01:23 +0200 | [diff] [blame] | 1183 | } |
| 1184 | } |
| 1185 | |
| 1186 | static void |
Jonas Ådahl | e9d2250 | 2012-08-29 22:13:01 +0200 | [diff] [blame] | 1187 | broadcast_current_workspace_state(struct desktop_shell *shell) |
| 1188 | { |
Kristian Høgsberg | 2e3c396 | 2013-09-11 12:00:47 -0700 | [diff] [blame] | 1189 | struct wl_resource *resource; |
Jonas Ådahl | e9d2250 | 2012-08-29 22:13:01 +0200 | [diff] [blame] | 1190 | |
Kristian Høgsberg | 2e3c396 | 2013-09-11 12:00:47 -0700 | [diff] [blame] | 1191 | wl_resource_for_each(resource, &shell->workspaces.client_list) |
| 1192 | workspace_manager_send_state(resource, |
Jonas Ådahl | e9d2250 | 2012-08-29 22:13:01 +0200 | [diff] [blame] | 1193 | shell->workspaces.current, |
| 1194 | shell->workspaces.num); |
| 1195 | } |
| 1196 | |
| 1197 | static void |
Jonas Ådahl | 62fcd04 | 2012-06-13 00:01:23 +0200 | [diff] [blame] | 1198 | reverse_workspace_change_animation(struct desktop_shell *shell, |
| 1199 | unsigned int index, |
| 1200 | struct workspace *from, |
| 1201 | struct workspace *to) |
| 1202 | { |
| 1203 | shell->workspaces.current = index; |
| 1204 | |
| 1205 | shell->workspaces.anim_to = to; |
| 1206 | shell->workspaces.anim_from = from; |
| 1207 | shell->workspaces.anim_dir = -1 * shell->workspaces.anim_dir; |
| 1208 | shell->workspaces.anim_timestamp = 0; |
| 1209 | |
Scott Moreau | 4272e63 | 2012-08-13 09:58:41 -0600 | [diff] [blame] | 1210 | weston_compositor_schedule_repaint(shell->compositor); |
Jonas Ådahl | 62fcd04 | 2012-06-13 00:01:23 +0200 | [diff] [blame] | 1211 | } |
| 1212 | |
| 1213 | static void |
| 1214 | workspace_deactivate_transforms(struct workspace *ws) |
| 1215 | { |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 1216 | struct weston_view *view; |
Louis-Francis Ratté-Boulianne | b482dbd | 2013-11-19 11:37:11 +0100 | [diff] [blame] | 1217 | struct weston_transform *transform; |
Jonas Ådahl | 62fcd04 | 2012-06-13 00:01:23 +0200 | [diff] [blame] | 1218 | |
Giulio Camuffo | 412e6a5 | 2014-07-09 22:12:56 +0300 | [diff] [blame] | 1219 | 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] | 1220 | if (is_focus_view(view)) { |
| 1221 | struct focus_surface *fsurf = get_focus_surface(view->surface); |
| 1222 | transform = &fsurf->workspace_transform; |
| 1223 | } else { |
| 1224 | struct shell_surface *shsurf = get_shell_surface(view->surface); |
| 1225 | transform = &shsurf->workspace_transform; |
| 1226 | } |
| 1227 | |
| 1228 | if (!wl_list_empty(&transform->link)) { |
| 1229 | wl_list_remove(&transform->link); |
| 1230 | wl_list_init(&transform->link); |
Jonas Ådahl | 8de6a1d | 2012-08-29 22:13:00 +0200 | [diff] [blame] | 1231 | } |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 1232 | weston_view_geometry_dirty(view); |
Jonas Ådahl | 62fcd04 | 2012-06-13 00:01:23 +0200 | [diff] [blame] | 1233 | } |
| 1234 | } |
| 1235 | |
| 1236 | static void |
| 1237 | finish_workspace_change_animation(struct desktop_shell *shell, |
| 1238 | struct workspace *from, |
| 1239 | struct workspace *to) |
| 1240 | { |
Ander Conselvan de Oliveira | 9c6217e | 2014-05-07 11:57:26 +0300 | [diff] [blame] | 1241 | struct weston_view *view; |
| 1242 | |
Scott Moreau | 4272e63 | 2012-08-13 09:58:41 -0600 | [diff] [blame] | 1243 | weston_compositor_schedule_repaint(shell->compositor); |
Jonas Ådahl | 62fcd04 | 2012-06-13 00:01:23 +0200 | [diff] [blame] | 1244 | |
Ander Conselvan de Oliveira | 9c6217e | 2014-05-07 11:57:26 +0300 | [diff] [blame] | 1245 | /* Views that extend past the bottom of the output are still |
| 1246 | * visible after the workspace animation ends but before its layer |
| 1247 | * is hidden. In that case, we need to damage below those views so |
| 1248 | * that the screen is properly repainted. */ |
Giulio Camuffo | 412e6a5 | 2014-07-09 22:12:56 +0300 | [diff] [blame] | 1249 | 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] | 1250 | weston_view_damage_below(view); |
| 1251 | |
Jonas Ådahl | 62fcd04 | 2012-06-13 00:01:23 +0200 | [diff] [blame] | 1252 | wl_list_remove(&shell->workspaces.animation.link); |
| 1253 | workspace_deactivate_transforms(from); |
| 1254 | workspace_deactivate_transforms(to); |
| 1255 | shell->workspaces.anim_to = NULL; |
| 1256 | |
| 1257 | wl_list_remove(&shell->workspaces.anim_from->layer.link); |
| 1258 | } |
| 1259 | |
| 1260 | static void |
| 1261 | animate_workspace_change_frame(struct weston_animation *animation, |
| 1262 | struct weston_output *output, uint32_t msecs) |
| 1263 | { |
| 1264 | struct desktop_shell *shell = |
| 1265 | container_of(animation, struct desktop_shell, |
| 1266 | workspaces.animation); |
| 1267 | struct workspace *from = shell->workspaces.anim_from; |
| 1268 | struct workspace *to = shell->workspaces.anim_to; |
| 1269 | uint32_t t; |
| 1270 | double x, y; |
| 1271 | |
| 1272 | if (workspace_is_empty(from) && workspace_is_empty(to)) { |
| 1273 | finish_workspace_change_animation(shell, from, to); |
| 1274 | return; |
| 1275 | } |
| 1276 | |
| 1277 | if (shell->workspaces.anim_timestamp == 0) { |
| 1278 | if (shell->workspaces.anim_current == 0.0) |
| 1279 | shell->workspaces.anim_timestamp = msecs; |
| 1280 | else |
| 1281 | shell->workspaces.anim_timestamp = |
| 1282 | msecs - |
| 1283 | /* Invers of movement function 'y' below. */ |
| 1284 | (asin(1.0 - shell->workspaces.anim_current) * |
| 1285 | DEFAULT_WORKSPACE_CHANGE_ANIMATION_LENGTH * |
| 1286 | M_2_PI); |
| 1287 | } |
| 1288 | |
| 1289 | t = msecs - shell->workspaces.anim_timestamp; |
| 1290 | |
| 1291 | /* |
| 1292 | * x = [0, π/2] |
| 1293 | * y(x) = sin(x) |
| 1294 | */ |
| 1295 | x = t * (1.0/DEFAULT_WORKSPACE_CHANGE_ANIMATION_LENGTH) * M_PI_2; |
| 1296 | y = sin(x); |
| 1297 | |
| 1298 | if (t < DEFAULT_WORKSPACE_CHANGE_ANIMATION_LENGTH) { |
Scott Moreau | 4272e63 | 2012-08-13 09:58:41 -0600 | [diff] [blame] | 1299 | weston_compositor_schedule_repaint(shell->compositor); |
Jonas Ådahl | 62fcd04 | 2012-06-13 00:01:23 +0200 | [diff] [blame] | 1300 | |
| 1301 | workspace_translate_out(from, shell->workspaces.anim_dir * y); |
| 1302 | workspace_translate_in(to, shell->workspaces.anim_dir * y); |
| 1303 | shell->workspaces.anim_current = y; |
| 1304 | |
Scott Moreau | 4272e63 | 2012-08-13 09:58:41 -0600 | [diff] [blame] | 1305 | weston_compositor_schedule_repaint(shell->compositor); |
Jonas Ådahl | 62fcd04 | 2012-06-13 00:01:23 +0200 | [diff] [blame] | 1306 | } |
Jonas Ådahl | 0476974 | 2012-06-13 00:01:24 +0200 | [diff] [blame] | 1307 | else |
Jonas Ådahl | 62fcd04 | 2012-06-13 00:01:23 +0200 | [diff] [blame] | 1308 | finish_workspace_change_animation(shell, from, to); |
Jonas Ådahl | 62fcd04 | 2012-06-13 00:01:23 +0200 | [diff] [blame] | 1309 | } |
| 1310 | |
| 1311 | static void |
| 1312 | animate_workspace_change(struct desktop_shell *shell, |
| 1313 | unsigned int index, |
| 1314 | struct workspace *from, |
| 1315 | struct workspace *to) |
| 1316 | { |
| 1317 | struct weston_output *output; |
| 1318 | |
| 1319 | int dir; |
| 1320 | |
| 1321 | if (index > shell->workspaces.current) |
| 1322 | dir = -1; |
| 1323 | else |
| 1324 | dir = 1; |
| 1325 | |
| 1326 | shell->workspaces.current = index; |
| 1327 | |
| 1328 | shell->workspaces.anim_dir = dir; |
| 1329 | shell->workspaces.anim_from = from; |
| 1330 | shell->workspaces.anim_to = to; |
| 1331 | shell->workspaces.anim_current = 0.0; |
| 1332 | shell->workspaces.anim_timestamp = 0; |
| 1333 | |
| 1334 | output = container_of(shell->compositor->output_list.next, |
| 1335 | struct weston_output, link); |
| 1336 | wl_list_insert(&output->animation_list, |
| 1337 | &shell->workspaces.animation.link); |
| 1338 | |
Jonas Ådahl | 8de6a1d | 2012-08-29 22:13:00 +0200 | [diff] [blame] | 1339 | wl_list_insert(from->layer.link.prev, &to->layer.link); |
Jonas Ådahl | 62fcd04 | 2012-06-13 00:01:23 +0200 | [diff] [blame] | 1340 | |
| 1341 | workspace_translate_in(to, 0); |
| 1342 | |
Kristian Høgsberg | 2f5faff | 2012-07-31 16:36:34 -0400 | [diff] [blame] | 1343 | restore_focus_state(shell, to); |
Jonas Ådahl | 0476974 | 2012-06-13 00:01:24 +0200 | [diff] [blame] | 1344 | |
Scott Moreau | 4272e63 | 2012-08-13 09:58:41 -0600 | [diff] [blame] | 1345 | weston_compositor_schedule_repaint(shell->compositor); |
Jonas Ådahl | 62fcd04 | 2012-06-13 00:01:23 +0200 | [diff] [blame] | 1346 | } |
| 1347 | |
Jonas Ådahl | e3cddce | 2012-06-13 00:01:22 +0200 | [diff] [blame] | 1348 | static void |
Jonas Ådahl | 8de6a1d | 2012-08-29 22:13:00 +0200 | [diff] [blame] | 1349 | update_workspace(struct desktop_shell *shell, unsigned int index, |
| 1350 | struct workspace *from, struct workspace *to) |
| 1351 | { |
| 1352 | shell->workspaces.current = index; |
| 1353 | wl_list_insert(&from->layer.link, &to->layer.link); |
| 1354 | wl_list_remove(&from->layer.link); |
| 1355 | } |
| 1356 | |
| 1357 | static void |
Jonas Ådahl | e3cddce | 2012-06-13 00:01:22 +0200 | [diff] [blame] | 1358 | change_workspace(struct desktop_shell *shell, unsigned int index) |
| 1359 | { |
| 1360 | struct workspace *from; |
| 1361 | struct workspace *to; |
Louis-Francis Ratté-Boulianne | b482dbd | 2013-11-19 11:37:11 +0100 | [diff] [blame] | 1362 | struct focus_state *state; |
Jonas Ådahl | e3cddce | 2012-06-13 00:01:22 +0200 | [diff] [blame] | 1363 | |
| 1364 | if (index == shell->workspaces.current) |
| 1365 | return; |
| 1366 | |
| 1367 | /* Don't change workspace when there is any fullscreen surfaces. */ |
Giulio Camuffo | 412e6a5 | 2014-07-09 22:12:56 +0300 | [diff] [blame] | 1368 | if (!wl_list_empty(&shell->fullscreen_layer.view_list.link)) |
Jonas Ådahl | e3cddce | 2012-06-13 00:01:22 +0200 | [diff] [blame] | 1369 | return; |
| 1370 | |
Jonas Ådahl | e3cddce | 2012-06-13 00:01:22 +0200 | [diff] [blame] | 1371 | from = get_current_workspace(shell); |
| 1372 | to = get_workspace(shell, index); |
| 1373 | |
Jonas Ådahl | 62fcd04 | 2012-06-13 00:01:23 +0200 | [diff] [blame] | 1374 | if (shell->workspaces.anim_from == to && |
| 1375 | shell->workspaces.anim_to == from) { |
Jonas Ådahl | 8de6a1d | 2012-08-29 22:13:00 +0200 | [diff] [blame] | 1376 | restore_focus_state(shell, to); |
Jonas Ådahl | 62fcd04 | 2012-06-13 00:01:23 +0200 | [diff] [blame] | 1377 | reverse_workspace_change_animation(shell, index, from, to); |
Jonas Ådahl | e9d2250 | 2012-08-29 22:13:01 +0200 | [diff] [blame] | 1378 | broadcast_current_workspace_state(shell); |
Jonas Ådahl | 62fcd04 | 2012-06-13 00:01:23 +0200 | [diff] [blame] | 1379 | return; |
| 1380 | } |
Jonas Ådahl | e3cddce | 2012-06-13 00:01:22 +0200 | [diff] [blame] | 1381 | |
Jonas Ådahl | 62fcd04 | 2012-06-13 00:01:23 +0200 | [diff] [blame] | 1382 | if (shell->workspaces.anim_to != NULL) |
| 1383 | finish_workspace_change_animation(shell, |
| 1384 | shell->workspaces.anim_from, |
| 1385 | shell->workspaces.anim_to); |
| 1386 | |
Jonas Ådahl | 8de6a1d | 2012-08-29 22:13:00 +0200 | [diff] [blame] | 1387 | restore_focus_state(shell, to); |
Jonas Ådahl | 0476974 | 2012-06-13 00:01:24 +0200 | [diff] [blame] | 1388 | |
Louis-Francis Ratté-Boulianne | b482dbd | 2013-11-19 11:37:11 +0100 | [diff] [blame] | 1389 | if (shell->focus_animation_type != ANIMATION_NONE) { |
| 1390 | wl_list_for_each(state, &from->focus_list, link) |
| 1391 | if (state->keyboard_focus) |
| 1392 | animate_focus_change(shell, from, |
| 1393 | get_default_view(state->keyboard_focus), NULL); |
| 1394 | |
| 1395 | wl_list_for_each(state, &to->focus_list, link) |
| 1396 | if (state->keyboard_focus) |
| 1397 | animate_focus_change(shell, to, |
| 1398 | NULL, get_default_view(state->keyboard_focus)); |
| 1399 | } |
| 1400 | |
Jonas Ådahl | 8de6a1d | 2012-08-29 22:13:00 +0200 | [diff] [blame] | 1401 | if (workspace_is_empty(to) && workspace_is_empty(from)) |
| 1402 | update_workspace(shell, index, from, to); |
Jonas Ådahl | 62fcd04 | 2012-06-13 00:01:23 +0200 | [diff] [blame] | 1403 | else |
| 1404 | animate_workspace_change(shell, index, from, to); |
Jonas Ådahl | e9d2250 | 2012-08-29 22:13:01 +0200 | [diff] [blame] | 1405 | |
| 1406 | broadcast_current_workspace_state(shell); |
Pekka Paalanen | e955f1e | 2011-12-07 11:49:52 +0200 | [diff] [blame] | 1407 | } |
| 1408 | |
Jonas Ådahl | 8de6a1d | 2012-08-29 22:13:00 +0200 | [diff] [blame] | 1409 | static bool |
| 1410 | workspace_has_only(struct workspace *ws, struct weston_surface *surface) |
| 1411 | { |
Giulio Camuffo | 412e6a5 | 2014-07-09 22:12:56 +0300 | [diff] [blame] | 1412 | struct wl_list *list = &ws->layer.view_list.link; |
Jonas Ådahl | 8de6a1d | 2012-08-29 22:13:00 +0200 | [diff] [blame] | 1413 | struct wl_list *e; |
| 1414 | |
| 1415 | if (wl_list_empty(list)) |
| 1416 | return false; |
| 1417 | |
| 1418 | e = list->next; |
| 1419 | |
| 1420 | if (e->next != list) |
| 1421 | return false; |
| 1422 | |
Giulio Camuffo | 412e6a5 | 2014-07-09 22:12:56 +0300 | [diff] [blame] | 1423 | return container_of(e, struct weston_view, layer_link.link)->surface == surface; |
Jonas Ådahl | 8de6a1d | 2012-08-29 22:13:00 +0200 | [diff] [blame] | 1424 | } |
| 1425 | |
| 1426 | static void |
Philip Withnall | 659163d | 2013-11-25 18:01:36 +0000 | [diff] [blame] | 1427 | move_surface_to_workspace(struct desktop_shell *shell, |
| 1428 | struct shell_surface *shsurf, |
| 1429 | uint32_t workspace) |
Jonas Ådahl | e9d2250 | 2012-08-29 22:13:01 +0200 | [diff] [blame] | 1430 | { |
| 1431 | struct workspace *from; |
| 1432 | struct workspace *to; |
| 1433 | struct weston_seat *seat; |
Pekka Paalanen | 01388e2 | 2013-04-25 13:57:44 +0300 | [diff] [blame] | 1434 | struct weston_surface *focus; |
Philip Withnall | 659163d | 2013-11-25 18:01:36 +0000 | [diff] [blame] | 1435 | struct weston_view *view; |
Jonas Ådahl | e9d2250 | 2012-08-29 22:13:01 +0200 | [diff] [blame] | 1436 | |
| 1437 | if (workspace == shell->workspaces.current) |
| 1438 | return; |
| 1439 | |
Philip Withnall | 659163d | 2013-11-25 18:01:36 +0000 | [diff] [blame] | 1440 | view = get_default_view(shsurf->surface); |
| 1441 | if (!view) |
| 1442 | return; |
| 1443 | |
| 1444 | assert(weston_surface_get_main_surface(view->surface) == view->surface); |
| 1445 | |
Philipp Brüschweiler | 067abf6 | 2012-09-01 16:03:05 +0200 | [diff] [blame] | 1446 | if (workspace >= shell->workspaces.num) |
| 1447 | workspace = shell->workspaces.num - 1; |
| 1448 | |
Jonas Ådahl | e9d2250 | 2012-08-29 22:13:01 +0200 | [diff] [blame] | 1449 | from = get_current_workspace(shell); |
| 1450 | to = get_workspace(shell, workspace); |
| 1451 | |
Giulio Camuffo | 412e6a5 | 2014-07-09 22:12:56 +0300 | [diff] [blame] | 1452 | weston_layer_entry_remove(&view->layer_link); |
| 1453 | weston_layer_entry_insert(&to->layer.view_list, &view->layer_link); |
Jonas Ådahl | e9d2250 | 2012-08-29 22:13:01 +0200 | [diff] [blame] | 1454 | |
Philip Withnall | 648a4dd | 2013-11-25 18:01:44 +0000 | [diff] [blame] | 1455 | shell_surface_update_child_surface_layers(shsurf); |
| 1456 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 1457 | drop_focus_state(shell, from, view->surface); |
Pekka Paalanen | 01388e2 | 2013-04-25 13:57:44 +0300 | [diff] [blame] | 1458 | wl_list_for_each(seat, &shell->compositor->seat_list, link) { |
Derek Foreman | 1281a36 | 2015-07-31 16:55:32 -0500 | [diff] [blame] | 1459 | struct weston_keyboard *keyboard = |
| 1460 | weston_seat_get_keyboard(seat); |
| 1461 | |
| 1462 | if (!keyboard) |
Pekka Paalanen | 01388e2 | 2013-04-25 13:57:44 +0300 | [diff] [blame] | 1463 | continue; |
| 1464 | |
Derek Foreman | 1281a36 | 2015-07-31 16:55:32 -0500 | [diff] [blame] | 1465 | focus = weston_surface_get_main_surface(keyboard->focus); |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 1466 | if (focus == view->surface) |
Derek Foreman | 1281a36 | 2015-07-31 16:55:32 -0500 | [diff] [blame] | 1467 | weston_keyboard_set_focus(keyboard, NULL); |
Pekka Paalanen | 01388e2 | 2013-04-25 13:57:44 +0300 | [diff] [blame] | 1468 | } |
Jonas Ådahl | e9d2250 | 2012-08-29 22:13:01 +0200 | [diff] [blame] | 1469 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 1470 | weston_view_damage_below(view); |
Jonas Ådahl | e9d2250 | 2012-08-29 22:13:01 +0200 | [diff] [blame] | 1471 | } |
| 1472 | |
| 1473 | static void |
Jonas Ådahl | 8de6a1d | 2012-08-29 22:13:00 +0200 | [diff] [blame] | 1474 | take_surface_to_workspace_by_seat(struct desktop_shell *shell, |
Kristian Høgsberg | e314875 | 2013-05-06 23:19:49 -0400 | [diff] [blame] | 1475 | struct weston_seat *seat, |
Jonas Ådahl | 8de6a1d | 2012-08-29 22:13:00 +0200 | [diff] [blame] | 1476 | unsigned int index) |
| 1477 | { |
Derek Foreman | 1281a36 | 2015-07-31 16:55:32 -0500 | [diff] [blame] | 1478 | struct weston_keyboard *keyboard = weston_seat_get_keyboard(seat); |
Pekka Paalanen | 01388e2 | 2013-04-25 13:57:44 +0300 | [diff] [blame] | 1479 | struct weston_surface *surface; |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 1480 | struct weston_view *view; |
Jonas Ådahl | 8de6a1d | 2012-08-29 22:13:00 +0200 | [diff] [blame] | 1481 | struct shell_surface *shsurf; |
| 1482 | struct workspace *from; |
| 1483 | struct workspace *to; |
Jonas Ådahl | 8538b22 | 2012-08-29 22:13:03 +0200 | [diff] [blame] | 1484 | struct focus_state *state; |
Jonas Ådahl | 8de6a1d | 2012-08-29 22:13:00 +0200 | [diff] [blame] | 1485 | |
Derek Foreman | 1281a36 | 2015-07-31 16:55:32 -0500 | [diff] [blame] | 1486 | surface = weston_surface_get_main_surface(keyboard->focus); |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 1487 | view = get_default_view(surface); |
| 1488 | if (view == NULL || |
Louis-Francis Ratté-Boulianne | b482dbd | 2013-11-19 11:37:11 +0100 | [diff] [blame] | 1489 | index == shell->workspaces.current || |
| 1490 | is_focus_view(view)) |
Jonas Ådahl | 8de6a1d | 2012-08-29 22:13:00 +0200 | [diff] [blame] | 1491 | return; |
| 1492 | |
| 1493 | from = get_current_workspace(shell); |
| 1494 | to = get_workspace(shell, index); |
| 1495 | |
Giulio Camuffo | 412e6a5 | 2014-07-09 22:12:56 +0300 | [diff] [blame] | 1496 | weston_layer_entry_remove(&view->layer_link); |
| 1497 | weston_layer_entry_insert(&to->layer.view_list, &view->layer_link); |
Jonas Ådahl | 8de6a1d | 2012-08-29 22:13:00 +0200 | [diff] [blame] | 1498 | |
Philip Withnall | 659163d | 2013-11-25 18:01:36 +0000 | [diff] [blame] | 1499 | shsurf = get_shell_surface(surface); |
Philip Withnall | 648a4dd | 2013-11-25 18:01:44 +0000 | [diff] [blame] | 1500 | if (shsurf != NULL) |
| 1501 | shell_surface_update_child_surface_layers(shsurf); |
Philip Withnall | 659163d | 2013-11-25 18:01:36 +0000 | [diff] [blame] | 1502 | |
Jonas Ådahl | e9d2250 | 2012-08-29 22:13:01 +0200 | [diff] [blame] | 1503 | replace_focus_state(shell, to, seat); |
Jonas Ådahl | 8de6a1d | 2012-08-29 22:13:00 +0200 | [diff] [blame] | 1504 | drop_focus_state(shell, from, surface); |
| 1505 | |
| 1506 | if (shell->workspaces.anim_from == to && |
| 1507 | shell->workspaces.anim_to == from) { |
Jonas Ådahl | e9d2250 | 2012-08-29 22:13:01 +0200 | [diff] [blame] | 1508 | wl_list_remove(&to->layer.link); |
| 1509 | wl_list_insert(from->layer.link.prev, &to->layer.link); |
| 1510 | |
Jonas Ådahl | 8de6a1d | 2012-08-29 22:13:00 +0200 | [diff] [blame] | 1511 | reverse_workspace_change_animation(shell, index, from, to); |
Jonas Ådahl | e9d2250 | 2012-08-29 22:13:01 +0200 | [diff] [blame] | 1512 | broadcast_current_workspace_state(shell); |
| 1513 | |
Jonas Ådahl | 8de6a1d | 2012-08-29 22:13:00 +0200 | [diff] [blame] | 1514 | return; |
| 1515 | } |
| 1516 | |
| 1517 | if (shell->workspaces.anim_to != NULL) |
| 1518 | finish_workspace_change_animation(shell, |
| 1519 | shell->workspaces.anim_from, |
| 1520 | shell->workspaces.anim_to); |
| 1521 | |
| 1522 | if (workspace_is_empty(from) && |
| 1523 | workspace_has_only(to, surface)) |
| 1524 | update_workspace(shell, index, from, to); |
| 1525 | else { |
Philip Withnall | 2c3849b | 2013-11-25 18:01:45 +0000 | [diff] [blame] | 1526 | if (shsurf != NULL && |
| 1527 | wl_list_empty(&shsurf->workspace_transform.link)) |
Jonas Ådahl | 8de6a1d | 2012-08-29 22:13:00 +0200 | [diff] [blame] | 1528 | wl_list_insert(&shell->workspaces.anim_sticky_list, |
| 1529 | &shsurf->workspace_transform.link); |
| 1530 | |
| 1531 | animate_workspace_change(shell, index, from, to); |
| 1532 | } |
Jonas Ådahl | e9d2250 | 2012-08-29 22:13:01 +0200 | [diff] [blame] | 1533 | |
| 1534 | broadcast_current_workspace_state(shell); |
Jonas Ådahl | 8538b22 | 2012-08-29 22:13:03 +0200 | [diff] [blame] | 1535 | |
| 1536 | state = ensure_focus_state(shell, seat); |
| 1537 | if (state != NULL) |
Kristian Høgsberg | d500bf1 | 2014-01-22 12:25:20 -0800 | [diff] [blame] | 1538 | focus_state_set_focus(state, surface); |
Jonas Ådahl | e9d2250 | 2012-08-29 22:13:01 +0200 | [diff] [blame] | 1539 | } |
| 1540 | |
| 1541 | static void |
| 1542 | workspace_manager_move_surface(struct wl_client *client, |
| 1543 | struct wl_resource *resource, |
| 1544 | struct wl_resource *surface_resource, |
| 1545 | uint32_t workspace) |
| 1546 | { |
Jason Ekstrand | 651f00e | 2013-06-14 10:07:54 -0500 | [diff] [blame] | 1547 | struct desktop_shell *shell = wl_resource_get_user_data(resource); |
Jonas Ådahl | e9d2250 | 2012-08-29 22:13:01 +0200 | [diff] [blame] | 1548 | struct weston_surface *surface = |
Jason Ekstrand | 0f2ef7e | 2013-06-14 10:07:53 -0500 | [diff] [blame] | 1549 | wl_resource_get_user_data(surface_resource); |
Pekka Paalanen | 01388e2 | 2013-04-25 13:57:44 +0300 | [diff] [blame] | 1550 | struct weston_surface *main_surface; |
Philip Withnall | 659163d | 2013-11-25 18:01:36 +0000 | [diff] [blame] | 1551 | struct shell_surface *shell_surface; |
Jonas Ådahl | e9d2250 | 2012-08-29 22:13:01 +0200 | [diff] [blame] | 1552 | |
Pekka Paalanen | 01388e2 | 2013-04-25 13:57:44 +0300 | [diff] [blame] | 1553 | main_surface = weston_surface_get_main_surface(surface); |
Philip Withnall | 659163d | 2013-11-25 18:01:36 +0000 | [diff] [blame] | 1554 | shell_surface = get_shell_surface(main_surface); |
| 1555 | if (shell_surface == NULL) |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 1556 | return; |
Philip Withnall | 659163d | 2013-11-25 18:01:36 +0000 | [diff] [blame] | 1557 | |
| 1558 | move_surface_to_workspace(shell, shell_surface, workspace); |
Jonas Ådahl | e9d2250 | 2012-08-29 22:13:01 +0200 | [diff] [blame] | 1559 | } |
| 1560 | |
| 1561 | static const struct workspace_manager_interface workspace_manager_implementation = { |
| 1562 | workspace_manager_move_surface, |
| 1563 | }; |
| 1564 | |
| 1565 | static void |
| 1566 | unbind_resource(struct wl_resource *resource) |
| 1567 | { |
Jason Ekstrand | 651f00e | 2013-06-14 10:07:54 -0500 | [diff] [blame] | 1568 | wl_list_remove(wl_resource_get_link(resource)); |
Jonas Ådahl | e9d2250 | 2012-08-29 22:13:01 +0200 | [diff] [blame] | 1569 | } |
| 1570 | |
| 1571 | static void |
| 1572 | bind_workspace_manager(struct wl_client *client, |
| 1573 | void *data, uint32_t version, uint32_t id) |
| 1574 | { |
| 1575 | struct desktop_shell *shell = data; |
| 1576 | struct wl_resource *resource; |
| 1577 | |
Jason Ekstrand | a85118c | 2013-06-27 20:17:02 -0500 | [diff] [blame] | 1578 | resource = wl_resource_create(client, |
| 1579 | &workspace_manager_interface, 1, id); |
Jonas Ådahl | e9d2250 | 2012-08-29 22:13:01 +0200 | [diff] [blame] | 1580 | |
| 1581 | if (resource == NULL) { |
| 1582 | weston_log("couldn't add workspace manager object"); |
| 1583 | return; |
| 1584 | } |
| 1585 | |
Jason Ekstrand | a85118c | 2013-06-27 20:17:02 -0500 | [diff] [blame] | 1586 | wl_resource_set_implementation(resource, |
| 1587 | &workspace_manager_implementation, |
| 1588 | shell, unbind_resource); |
Jason Ekstrand | 651f00e | 2013-06-14 10:07:54 -0500 | [diff] [blame] | 1589 | wl_list_insert(&shell->workspaces.client_list, |
| 1590 | wl_resource_get_link(resource)); |
Jonas Ådahl | e9d2250 | 2012-08-29 22:13:01 +0200 | [diff] [blame] | 1591 | |
| 1592 | workspace_manager_send_state(resource, |
| 1593 | shell->workspaces.current, |
| 1594 | shell->workspaces.num); |
Jonas Ådahl | 8de6a1d | 2012-08-29 22:13:00 +0200 | [diff] [blame] | 1595 | } |
| 1596 | |
Pekka Paalanen | 56cdea9 | 2011-11-23 16:14:12 +0200 | [diff] [blame] | 1597 | static void |
Rusty Lynch | 1084da5 | 2013-08-15 09:10:08 -0700 | [diff] [blame] | 1598 | touch_move_grab_down(struct weston_touch_grab *grab, uint32_t time, |
Giulio Camuffo | 61ed7b6 | 2015-07-08 11:55:28 +0300 | [diff] [blame] | 1599 | int touch_id, wl_fixed_t x, wl_fixed_t y) |
Rusty Lynch | 1084da5 | 2013-08-15 09:10:08 -0700 | [diff] [blame] | 1600 | { |
| 1601 | } |
| 1602 | |
| 1603 | static void |
| 1604 | touch_move_grab_up(struct weston_touch_grab *grab, uint32_t time, int touch_id) |
| 1605 | { |
Jonas Ådahl | 1c6e63e | 2013-10-25 23:18:04 +0200 | [diff] [blame] | 1606 | struct weston_touch_move_grab *move = |
| 1607 | (struct weston_touch_move_grab *) container_of( |
| 1608 | grab, struct shell_touch_grab, grab); |
Neil Roberts | e14aa4f | 2013-10-03 16:43:07 +0100 | [diff] [blame] | 1609 | |
Kristian Høgsberg | 8e80a31 | 2014-01-17 15:18:10 -0800 | [diff] [blame] | 1610 | if (touch_id == 0) |
| 1611 | move->active = 0; |
| 1612 | |
Jonas Ådahl | 9484b69 | 2013-12-02 22:05:03 +0100 | [diff] [blame] | 1613 | if (grab->touch->num_tp == 0) { |
Jonas Ådahl | 1c6e63e | 2013-10-25 23:18:04 +0200 | [diff] [blame] | 1614 | shell_touch_grab_end(&move->base); |
| 1615 | free(move); |
| 1616 | } |
Rusty Lynch | 1084da5 | 2013-08-15 09:10:08 -0700 | [diff] [blame] | 1617 | } |
| 1618 | |
| 1619 | static void |
| 1620 | touch_move_grab_motion(struct weston_touch_grab *grab, uint32_t time, |
Giulio Camuffo | 61ed7b6 | 2015-07-08 11:55:28 +0300 | [diff] [blame] | 1621 | int touch_id, wl_fixed_t x, wl_fixed_t y) |
Rusty Lynch | 1084da5 | 2013-08-15 09:10:08 -0700 | [diff] [blame] | 1622 | { |
| 1623 | struct weston_touch_move_grab *move = (struct weston_touch_move_grab *) grab; |
| 1624 | struct shell_surface *shsurf = move->base.shsurf; |
| 1625 | struct weston_surface *es; |
| 1626 | int dx = wl_fixed_to_int(grab->touch->grab_x + move->dx); |
| 1627 | int dy = wl_fixed_to_int(grab->touch->grab_y + move->dy); |
| 1628 | |
Kristian Høgsberg | 8e80a31 | 2014-01-17 15:18:10 -0800 | [diff] [blame] | 1629 | if (!shsurf || !move->active) |
Rusty Lynch | 1084da5 | 2013-08-15 09:10:08 -0700 | [diff] [blame] | 1630 | return; |
| 1631 | |
| 1632 | es = shsurf->surface; |
| 1633 | |
Jason Ekstrand | 918f2dd | 2013-12-02 21:01:53 -0600 | [diff] [blame] | 1634 | weston_view_set_position(shsurf->view, dx, dy); |
Rusty Lynch | 1084da5 | 2013-08-15 09:10:08 -0700 | [diff] [blame] | 1635 | |
| 1636 | weston_compositor_schedule_repaint(es->compositor); |
| 1637 | } |
| 1638 | |
Jonas Ådahl | 1ea343e | 2013-10-25 23:18:05 +0200 | [diff] [blame] | 1639 | static void |
Jonas Ådahl | 1679f23 | 2014-04-12 09:39:51 +0200 | [diff] [blame] | 1640 | touch_move_grab_frame(struct weston_touch_grab *grab) |
| 1641 | { |
| 1642 | } |
| 1643 | |
| 1644 | static void |
Jonas Ådahl | 1ea343e | 2013-10-25 23:18:05 +0200 | [diff] [blame] | 1645 | touch_move_grab_cancel(struct weston_touch_grab *grab) |
| 1646 | { |
| 1647 | struct weston_touch_move_grab *move = |
| 1648 | (struct weston_touch_move_grab *) container_of( |
| 1649 | grab, struct shell_touch_grab, grab); |
| 1650 | |
| 1651 | shell_touch_grab_end(&move->base); |
| 1652 | free(move); |
| 1653 | } |
| 1654 | |
Rusty Lynch | 1084da5 | 2013-08-15 09:10:08 -0700 | [diff] [blame] | 1655 | static const struct weston_touch_grab_interface touch_move_grab_interface = { |
| 1656 | touch_move_grab_down, |
| 1657 | touch_move_grab_up, |
| 1658 | touch_move_grab_motion, |
Jonas Ådahl | 1679f23 | 2014-04-12 09:39:51 +0200 | [diff] [blame] | 1659 | touch_move_grab_frame, |
Jonas Ådahl | 1ea343e | 2013-10-25 23:18:05 +0200 | [diff] [blame] | 1660 | touch_move_grab_cancel, |
Rusty Lynch | 1084da5 | 2013-08-15 09:10:08 -0700 | [diff] [blame] | 1661 | }; |
| 1662 | |
| 1663 | static int |
Derek Foreman | b7674ae | 2015-07-15 13:00:37 -0500 | [diff] [blame] | 1664 | surface_touch_move(struct shell_surface *shsurf, struct weston_touch *touch) |
Rusty Lynch | 1084da5 | 2013-08-15 09:10:08 -0700 | [diff] [blame] | 1665 | { |
| 1666 | struct weston_touch_move_grab *move; |
| 1667 | |
| 1668 | if (!shsurf) |
| 1669 | return -1; |
| 1670 | |
Ander Conselvan de Oliveira | 6d43f04 | 2014-05-07 14:22:23 +0300 | [diff] [blame] | 1671 | if (shsurf->state.fullscreen || shsurf->state.maximized) |
Rusty Lynch | 1084da5 | 2013-08-15 09:10:08 -0700 | [diff] [blame] | 1672 | return 0; |
| 1673 | |
| 1674 | move = malloc(sizeof *move); |
| 1675 | if (!move) |
| 1676 | return -1; |
| 1677 | |
Kristian Høgsberg | 8e80a31 | 2014-01-17 15:18:10 -0800 | [diff] [blame] | 1678 | move->active = 1; |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 1679 | move->dx = wl_fixed_from_double(shsurf->view->geometry.x) - |
Derek Foreman | b7674ae | 2015-07-15 13:00:37 -0500 | [diff] [blame] | 1680 | touch->grab_x; |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 1681 | move->dy = wl_fixed_from_double(shsurf->view->geometry.y) - |
Derek Foreman | b7674ae | 2015-07-15 13:00:37 -0500 | [diff] [blame] | 1682 | touch->grab_y; |
Rusty Lynch | 1084da5 | 2013-08-15 09:10:08 -0700 | [diff] [blame] | 1683 | |
| 1684 | shell_touch_grab_start(&move->base, &touch_move_grab_interface, shsurf, |
Derek Foreman | b7674ae | 2015-07-15 13:00:37 -0500 | [diff] [blame] | 1685 | touch); |
Rusty Lynch | 1084da5 | 2013-08-15 09:10:08 -0700 | [diff] [blame] | 1686 | |
| 1687 | return 0; |
| 1688 | } |
| 1689 | |
| 1690 | static void |
Kristian Høgsberg | 6848c25 | 2013-05-08 22:02:59 -0400 | [diff] [blame] | 1691 | noop_grab_focus(struct weston_pointer_grab *grab) |
Kristian Høgsberg | 9ddb826 | 2012-01-04 21:30:29 -0500 | [diff] [blame] | 1692 | { |
Kristian Høgsberg | 9ddb826 | 2012-01-04 21:30:29 -0500 | [diff] [blame] | 1693 | } |
| 1694 | |
| 1695 | static void |
Kristian Høgsberg | ae356ae | 2014-04-29 16:03:54 -0700 | [diff] [blame] | 1696 | constrain_position(struct weston_move_grab *move, int *cx, int *cy) |
| 1697 | { |
| 1698 | struct shell_surface *shsurf = move->base.shsurf; |
| 1699 | struct weston_pointer *pointer = move->base.grab.pointer; |
Derek Foreman | 6feb0f9 | 2015-04-15 12:23:56 -0500 | [diff] [blame] | 1700 | int x, y, bottom; |
Kristian Høgsberg | ae356ae | 2014-04-29 16:03:54 -0700 | [diff] [blame] | 1701 | const int safety = 50; |
Derek Foreman | 6feb0f9 | 2015-04-15 12:23:56 -0500 | [diff] [blame] | 1702 | pixman_rectangle32_t area; |
Kristian Høgsberg | ae356ae | 2014-04-29 16:03:54 -0700 | [diff] [blame] | 1703 | |
| 1704 | x = wl_fixed_to_int(pointer->x + move->dx); |
| 1705 | y = wl_fixed_to_int(pointer->y + move->dy); |
| 1706 | |
Jonny Lamb | d73c694 | 2014-08-20 15:53:20 +0200 | [diff] [blame] | 1707 | if (shsurf->shell->panel_position == DESKTOP_SHELL_PANEL_POSITION_TOP) { |
Derek Foreman | 6feb0f9 | 2015-04-15 12:23:56 -0500 | [diff] [blame] | 1708 | get_output_work_area(shsurf->shell, |
| 1709 | shsurf->surface->output, |
| 1710 | &area); |
Kristian Høgsberg | ae356ae | 2014-04-29 16:03:54 -0700 | [diff] [blame] | 1711 | |
Derek Foreman | 6feb0f9 | 2015-04-15 12:23:56 -0500 | [diff] [blame] | 1712 | bottom = y + shsurf->geometry.height + shsurf->geometry.y; |
| 1713 | if (bottom - safety < area.y) |
| 1714 | y = area.y + safety - shsurf->geometry.height |
| 1715 | - shsurf->geometry.y; |
Jonny Lamb | d73c694 | 2014-08-20 15:53:20 +0200 | [diff] [blame] | 1716 | |
| 1717 | if (move->client_initiated && |
Derek Foreman | 6feb0f9 | 2015-04-15 12:23:56 -0500 | [diff] [blame] | 1718 | y + shsurf->geometry.y < area.y) |
| 1719 | y = area.y - shsurf->geometry.y; |
| 1720 | |
Jonny Lamb | d73c694 | 2014-08-20 15:53:20 +0200 | [diff] [blame] | 1721 | } |
Kristian Høgsberg | ae356ae | 2014-04-29 16:03:54 -0700 | [diff] [blame] | 1722 | |
| 1723 | *cx = x; |
| 1724 | *cy = y; |
| 1725 | } |
| 1726 | |
| 1727 | static void |
Giulio Camuffo | 1959ab8 | 2013-11-14 23:42:52 +0100 | [diff] [blame] | 1728 | move_grab_motion(struct weston_pointer_grab *grab, uint32_t time, |
| 1729 | wl_fixed_t x, wl_fixed_t y) |
Kristian Høgsberg | 4cca349 | 2011-01-18 07:53:49 -0500 | [diff] [blame] | 1730 | { |
Kristian Høgsberg | 8334bc1 | 2012-01-03 10:29:47 -0500 | [diff] [blame] | 1731 | struct weston_move_grab *move = (struct weston_move_grab *) grab; |
Kristian Høgsberg | 02bbabb | 2013-05-06 22:15:05 -0400 | [diff] [blame] | 1732 | struct weston_pointer *pointer = grab->pointer; |
Ander Conselvan de Oliveira | fe0444a | 2012-04-04 17:48:05 +0300 | [diff] [blame] | 1733 | struct shell_surface *shsurf = move->base.shsurf; |
Kristian Høgsberg | ae356ae | 2014-04-29 16:03:54 -0700 | [diff] [blame] | 1734 | int cx, cy; |
Giulio Camuffo | 1959ab8 | 2013-11-14 23:42:52 +0100 | [diff] [blame] | 1735 | |
| 1736 | weston_pointer_move(pointer, x, y); |
Ander Conselvan de Oliveira | fe0444a | 2012-04-04 17:48:05 +0300 | [diff] [blame] | 1737 | if (!shsurf) |
| 1738 | return; |
| 1739 | |
Kristian Høgsberg | ae356ae | 2014-04-29 16:03:54 -0700 | [diff] [blame] | 1740 | constrain_position(move, &cx, &cy); |
| 1741 | |
| 1742 | weston_view_set_position(shsurf->view, cx, cy); |
Kristian Høgsberg | 4cca349 | 2011-01-18 07:53:49 -0500 | [diff] [blame] | 1743 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 1744 | weston_compositor_schedule_repaint(shsurf->surface->compositor); |
Kristian Høgsberg | 4cca349 | 2011-01-18 07:53:49 -0500 | [diff] [blame] | 1745 | } |
| 1746 | |
| 1747 | static void |
Kristian Høgsberg | 02bbabb | 2013-05-06 22:15:05 -0400 | [diff] [blame] | 1748 | move_grab_button(struct weston_pointer_grab *grab, |
Daniel Stone | 4dbadb1 | 2012-05-30 16:31:51 +0100 | [diff] [blame] | 1749 | uint32_t time, uint32_t button, uint32_t state_w) |
Kristian Høgsberg | 4cca349 | 2011-01-18 07:53:49 -0500 | [diff] [blame] | 1750 | { |
Ander Conselvan de Oliveira | fe0444a | 2012-04-04 17:48:05 +0300 | [diff] [blame] | 1751 | struct shell_grab *shell_grab = container_of(grab, struct shell_grab, |
| 1752 | grab); |
Kristian Høgsberg | 02bbabb | 2013-05-06 22:15:05 -0400 | [diff] [blame] | 1753 | struct weston_pointer *pointer = grab->pointer; |
Daniel Stone | 4dbadb1 | 2012-05-30 16:31:51 +0100 | [diff] [blame] | 1754 | enum wl_pointer_button_state state = state_w; |
Kristian Høgsberg | 4cca349 | 2011-01-18 07:53:49 -0500 | [diff] [blame] | 1755 | |
Daniel Stone | 4dbadb1 | 2012-05-30 16:31:51 +0100 | [diff] [blame] | 1756 | if (pointer->button_count == 0 && |
| 1757 | state == WL_POINTER_BUTTON_STATE_RELEASED) { |
Ander Conselvan de Oliveira | b9d2a0f | 2012-06-28 18:08:05 +0300 | [diff] [blame] | 1758 | shell_grab_end(shell_grab); |
Kristian Høgsberg | 9ddb826 | 2012-01-04 21:30:29 -0500 | [diff] [blame] | 1759 | free(grab); |
| 1760 | } |
Kristian Høgsberg | 4cca349 | 2011-01-18 07:53:49 -0500 | [diff] [blame] | 1761 | } |
| 1762 | |
Jonas Ådahl | 1ea343e | 2013-10-25 23:18:05 +0200 | [diff] [blame] | 1763 | static void |
| 1764 | move_grab_cancel(struct weston_pointer_grab *grab) |
| 1765 | { |
| 1766 | struct shell_grab *shell_grab = |
| 1767 | container_of(grab, struct shell_grab, grab); |
| 1768 | |
| 1769 | shell_grab_end(shell_grab); |
| 1770 | free(grab); |
| 1771 | } |
| 1772 | |
Kristian Høgsberg | 02bbabb | 2013-05-06 22:15:05 -0400 | [diff] [blame] | 1773 | static const struct weston_pointer_grab_interface move_grab_interface = { |
Kristian Høgsberg | 9ddb826 | 2012-01-04 21:30:29 -0500 | [diff] [blame] | 1774 | noop_grab_focus, |
Kristian Høgsberg | 4cca349 | 2011-01-18 07:53:49 -0500 | [diff] [blame] | 1775 | move_grab_motion, |
| 1776 | move_grab_button, |
Jonas Ådahl | 1ea343e | 2013-10-25 23:18:05 +0200 | [diff] [blame] | 1777 | move_grab_cancel, |
Kristian Høgsberg | 4cca349 | 2011-01-18 07:53:49 -0500 | [diff] [blame] | 1778 | }; |
| 1779 | |
Kristian Høgsberg | 9e31bff | 2012-08-01 00:08:07 -0400 | [diff] [blame] | 1780 | static int |
Derek Foreman | 794fa0e | 2015-07-15 13:00:38 -0500 | [diff] [blame] | 1781 | surface_move(struct shell_surface *shsurf, struct weston_pointer *pointer, |
Derek Foreman | cf7d95a | 2015-06-03 15:53:22 -0500 | [diff] [blame] | 1782 | bool client_initiated) |
Kristian Høgsberg | 9e31bff | 2012-08-01 00:08:07 -0400 | [diff] [blame] | 1783 | { |
| 1784 | struct weston_move_grab *move; |
| 1785 | |
| 1786 | if (!shsurf) |
| 1787 | return -1; |
| 1788 | |
Derek Foreman | 45a7c27 | 2015-09-11 14:27:40 -0500 | [diff] [blame] | 1789 | shsurf = find_toplevel_surface(shsurf); |
| 1790 | |
Kristian Høgsberg | a4b620e | 2014-04-30 16:05:49 -0700 | [diff] [blame] | 1791 | if (shsurf->grabbed || |
| 1792 | shsurf->state.fullscreen || shsurf->state.maximized) |
Kristian Høgsberg | 9e31bff | 2012-08-01 00:08:07 -0400 | [diff] [blame] | 1793 | return 0; |
| 1794 | |
| 1795 | move = malloc(sizeof *move); |
| 1796 | if (!move) |
| 1797 | return -1; |
| 1798 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 1799 | move->dx = wl_fixed_from_double(shsurf->view->geometry.x) - |
Derek Foreman | 794fa0e | 2015-07-15 13:00:38 -0500 | [diff] [blame] | 1800 | pointer->grab_x; |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 1801 | move->dy = wl_fixed_from_double(shsurf->view->geometry.y) - |
Derek Foreman | 794fa0e | 2015-07-15 13:00:38 -0500 | [diff] [blame] | 1802 | pointer->grab_y; |
Kristian Høgsberg | ae356ae | 2014-04-29 16:03:54 -0700 | [diff] [blame] | 1803 | move->client_initiated = client_initiated; |
Kristian Høgsberg | 9e31bff | 2012-08-01 00:08:07 -0400 | [diff] [blame] | 1804 | |
| 1805 | shell_grab_start(&move->base, &move_grab_interface, shsurf, |
Derek Foreman | 794fa0e | 2015-07-15 13:00:38 -0500 | [diff] [blame] | 1806 | pointer, DESKTOP_SHELL_CURSOR_MOVE); |
Kristian Høgsberg | 9e31bff | 2012-08-01 00:08:07 -0400 | [diff] [blame] | 1807 | |
| 1808 | return 0; |
| 1809 | } |
| 1810 | |
| 1811 | static void |
Rafael Antognolli | e2a3455 | 2013-12-03 15:35:45 -0200 | [diff] [blame] | 1812 | common_surface_move(struct wl_resource *resource, |
| 1813 | struct wl_resource *seat_resource, uint32_t serial) |
Kristian Høgsberg | 9e31bff | 2012-08-01 00:08:07 -0400 | [diff] [blame] | 1814 | { |
Jason Ekstrand | 44a3863 | 2013-06-14 10:08:00 -0500 | [diff] [blame] | 1815 | struct weston_seat *seat = wl_resource_get_user_data(seat_resource); |
Derek Foreman | 1281a36 | 2015-07-31 16:55:32 -0500 | [diff] [blame] | 1816 | struct weston_pointer *pointer = weston_seat_get_pointer(seat); |
| 1817 | struct weston_touch *touch = weston_seat_get_touch(seat); |
Jason Ekstrand | 651f00e | 2013-06-14 10:07:54 -0500 | [diff] [blame] | 1818 | struct shell_surface *shsurf = wl_resource_get_user_data(resource); |
Giulio Camuffo | 61da3fc | 2013-04-25 13:57:45 +0300 | [diff] [blame] | 1819 | struct weston_surface *surface; |
Kristian Høgsberg | 9e31bff | 2012-08-01 00:08:07 -0400 | [diff] [blame] | 1820 | |
Derek Foreman | 1281a36 | 2015-07-31 16:55:32 -0500 | [diff] [blame] | 1821 | if (pointer && |
| 1822 | pointer->focus && |
| 1823 | pointer->button_count > 0 && |
| 1824 | pointer->grab_serial == serial) { |
| 1825 | surface = weston_surface_get_main_surface(pointer->focus->surface); |
U. Artie Eoff | cf5737a | 2014-01-17 10:08:25 -0800 | [diff] [blame] | 1826 | if ((surface == shsurf->surface) && |
Derek Foreman | 1281a36 | 2015-07-31 16:55:32 -0500 | [diff] [blame] | 1827 | (surface_move(shsurf, pointer, true) < 0)) |
Rusty Lynch | 1084da5 | 2013-08-15 09:10:08 -0700 | [diff] [blame] | 1828 | wl_resource_post_no_memory(resource); |
Derek Foreman | 1281a36 | 2015-07-31 16:55:32 -0500 | [diff] [blame] | 1829 | } else if (touch && |
| 1830 | touch->focus && |
| 1831 | touch->grab_serial == serial) { |
| 1832 | surface = weston_surface_get_main_surface(touch->focus->surface); |
U. Artie Eoff | cf5737a | 2014-01-17 10:08:25 -0800 | [diff] [blame] | 1833 | if ((surface == shsurf->surface) && |
Derek Foreman | 1281a36 | 2015-07-31 16:55:32 -0500 | [diff] [blame] | 1834 | (surface_touch_move(shsurf, touch) < 0)) |
Rusty Lynch | 1084da5 | 2013-08-15 09:10:08 -0700 | [diff] [blame] | 1835 | wl_resource_post_no_memory(resource); |
| 1836 | } |
Kristian Høgsberg | 9e31bff | 2012-08-01 00:08:07 -0400 | [diff] [blame] | 1837 | } |
| 1838 | |
Rafael Antognolli | e2a3455 | 2013-12-03 15:35:45 -0200 | [diff] [blame] | 1839 | static void |
| 1840 | shell_surface_move(struct wl_client *client, struct wl_resource *resource, |
| 1841 | struct wl_resource *seat_resource, uint32_t serial) |
| 1842 | { |
| 1843 | common_surface_move(resource, seat_resource, serial); |
| 1844 | } |
| 1845 | |
Kristian Høgsberg | 9e31bff | 2012-08-01 00:08:07 -0400 | [diff] [blame] | 1846 | struct weston_resize_grab { |
| 1847 | struct shell_grab base; |
| 1848 | uint32_t edges; |
| 1849 | int32_t width, height; |
| 1850 | }; |
| 1851 | |
| 1852 | static void |
Giulio Camuffo | 1959ab8 | 2013-11-14 23:42:52 +0100 | [diff] [blame] | 1853 | resize_grab_motion(struct weston_pointer_grab *grab, uint32_t time, |
| 1854 | wl_fixed_t x, wl_fixed_t y) |
Kristian Høgsberg | 9e31bff | 2012-08-01 00:08:07 -0400 | [diff] [blame] | 1855 | { |
| 1856 | struct weston_resize_grab *resize = (struct weston_resize_grab *) grab; |
Kristian Høgsberg | 02bbabb | 2013-05-06 22:15:05 -0400 | [diff] [blame] | 1857 | struct weston_pointer *pointer = grab->pointer; |
Kristian Høgsberg | 9e31bff | 2012-08-01 00:08:07 -0400 | [diff] [blame] | 1858 | struct shell_surface *shsurf = resize->base.shsurf; |
| 1859 | int32_t width, height; |
| 1860 | wl_fixed_t from_x, from_y; |
| 1861 | wl_fixed_t to_x, to_y; |
| 1862 | |
Giulio Camuffo | 1959ab8 | 2013-11-14 23:42:52 +0100 | [diff] [blame] | 1863 | weston_pointer_move(pointer, x, y); |
| 1864 | |
Kristian Høgsberg | e0b9d5b | 2014-04-30 13:45:49 -0700 | [diff] [blame] | 1865 | if (!shsurf) |
Kristian Høgsberg | 9e31bff | 2012-08-01 00:08:07 -0400 | [diff] [blame] | 1866 | return; |
| 1867 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 1868 | weston_view_from_global_fixed(shsurf->view, |
| 1869 | pointer->grab_x, pointer->grab_y, |
| 1870 | &from_x, &from_y); |
| 1871 | weston_view_from_global_fixed(shsurf->view, |
| 1872 | pointer->x, pointer->y, &to_x, &to_y); |
Kristian Høgsberg | 9e31bff | 2012-08-01 00:08:07 -0400 | [diff] [blame] | 1873 | |
| 1874 | width = resize->width; |
| 1875 | if (resize->edges & WL_SHELL_SURFACE_RESIZE_LEFT) { |
| 1876 | width += wl_fixed_to_int(from_x - to_x); |
| 1877 | } else if (resize->edges & WL_SHELL_SURFACE_RESIZE_RIGHT) { |
| 1878 | width += wl_fixed_to_int(to_x - from_x); |
| 1879 | } |
| 1880 | |
| 1881 | height = resize->height; |
| 1882 | if (resize->edges & WL_SHELL_SURFACE_RESIZE_TOP) { |
| 1883 | height += wl_fixed_to_int(from_y - to_y); |
| 1884 | } else if (resize->edges & WL_SHELL_SURFACE_RESIZE_BOTTOM) { |
| 1885 | height += wl_fixed_to_int(to_y - from_y); |
| 1886 | } |
| 1887 | |
Derek Foreman | 70ac0ed | 2015-03-18 11:16:33 -0500 | [diff] [blame] | 1888 | if (width < 1) |
| 1889 | width = 1; |
| 1890 | if (height < 1) |
| 1891 | height = 1; |
Jasper St. Pierre | ac985be | 2014-04-28 11:19:28 -0400 | [diff] [blame] | 1892 | shsurf->client->send_configure(shsurf->surface, width, height); |
Kristian Høgsberg | 9e31bff | 2012-08-01 00:08:07 -0400 | [diff] [blame] | 1893 | } |
| 1894 | |
| 1895 | static void |
Jasper St. Pierre | ac985be | 2014-04-28 11:19:28 -0400 | [diff] [blame] | 1896 | 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] | 1897 | { |
| 1898 | struct shell_surface *shsurf = get_shell_surface(surface); |
| 1899 | |
U. Artie Eoff | cf5737a | 2014-01-17 10:08:25 -0800 | [diff] [blame] | 1900 | assert(shsurf); |
| 1901 | |
Kristian Høgsberg | e0b9d5b | 2014-04-30 13:45:49 -0700 | [diff] [blame] | 1902 | if (shsurf->resource) |
| 1903 | wl_shell_surface_send_configure(shsurf->resource, |
Jasper St. Pierre | ac985be | 2014-04-28 11:19:28 -0400 | [diff] [blame] | 1904 | shsurf->resize_edges, |
| 1905 | width, height); |
Kristian Høgsberg | 9e31bff | 2012-08-01 00:08:07 -0400 | [diff] [blame] | 1906 | } |
| 1907 | |
| 1908 | static const struct weston_shell_client shell_client = { |
| 1909 | send_configure |
| 1910 | }; |
| 1911 | |
| 1912 | static void |
Kristian Høgsberg | 02bbabb | 2013-05-06 22:15:05 -0400 | [diff] [blame] | 1913 | resize_grab_button(struct weston_pointer_grab *grab, |
Kristian Høgsberg | 9e31bff | 2012-08-01 00:08:07 -0400 | [diff] [blame] | 1914 | uint32_t time, uint32_t button, uint32_t state_w) |
| 1915 | { |
| 1916 | struct weston_resize_grab *resize = (struct weston_resize_grab *) grab; |
Kristian Høgsberg | 02bbabb | 2013-05-06 22:15:05 -0400 | [diff] [blame] | 1917 | struct weston_pointer *pointer = grab->pointer; |
Kristian Høgsberg | 9e31bff | 2012-08-01 00:08:07 -0400 | [diff] [blame] | 1918 | enum wl_pointer_button_state state = state_w; |
| 1919 | |
| 1920 | if (pointer->button_count == 0 && |
| 1921 | state == WL_POINTER_BUTTON_STATE_RELEASED) { |
| 1922 | shell_grab_end(&resize->base); |
| 1923 | free(grab); |
| 1924 | } |
| 1925 | } |
| 1926 | |
Jonas Ådahl | 1ea343e | 2013-10-25 23:18:05 +0200 | [diff] [blame] | 1927 | static void |
| 1928 | resize_grab_cancel(struct weston_pointer_grab *grab) |
| 1929 | { |
| 1930 | struct weston_resize_grab *resize = (struct weston_resize_grab *) grab; |
| 1931 | |
| 1932 | shell_grab_end(&resize->base); |
| 1933 | free(grab); |
| 1934 | } |
| 1935 | |
Kristian Høgsberg | 02bbabb | 2013-05-06 22:15:05 -0400 | [diff] [blame] | 1936 | static const struct weston_pointer_grab_interface resize_grab_interface = { |
Kristian Høgsberg | 9e31bff | 2012-08-01 00:08:07 -0400 | [diff] [blame] | 1937 | noop_grab_focus, |
| 1938 | resize_grab_motion, |
| 1939 | resize_grab_button, |
Jonas Ådahl | 1ea343e | 2013-10-25 23:18:05 +0200 | [diff] [blame] | 1940 | resize_grab_cancel, |
Kristian Høgsberg | 9e31bff | 2012-08-01 00:08:07 -0400 | [diff] [blame] | 1941 | }; |
| 1942 | |
Giulio Camuffo | b836664 | 2013-04-25 13:57:46 +0300 | [diff] [blame] | 1943 | /* |
| 1944 | * Returns the bounding box of a surface and all its sub-surfaces, |
| 1945 | * in the surface coordinates system. */ |
| 1946 | static void |
| 1947 | surface_subsurfaces_boundingbox(struct weston_surface *surface, int32_t *x, |
| 1948 | int32_t *y, int32_t *w, int32_t *h) { |
| 1949 | pixman_region32_t region; |
| 1950 | pixman_box32_t *box; |
| 1951 | struct weston_subsurface *subsurface; |
| 1952 | |
| 1953 | pixman_region32_init_rect(®ion, 0, 0, |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 1954 | surface->width, |
| 1955 | surface->height); |
Giulio Camuffo | b836664 | 2013-04-25 13:57:46 +0300 | [diff] [blame] | 1956 | |
| 1957 | wl_list_for_each(subsurface, &surface->subsurface_list, parent_link) { |
| 1958 | pixman_region32_union_rect(®ion, ®ion, |
| 1959 | subsurface->position.x, |
| 1960 | subsurface->position.y, |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 1961 | subsurface->surface->width, |
| 1962 | subsurface->surface->height); |
Giulio Camuffo | b836664 | 2013-04-25 13:57:46 +0300 | [diff] [blame] | 1963 | } |
| 1964 | |
| 1965 | box = pixman_region32_extents(®ion); |
| 1966 | if (x) |
| 1967 | *x = box->x1; |
| 1968 | if (y) |
| 1969 | *y = box->y1; |
| 1970 | if (w) |
| 1971 | *w = box->x2 - box->x1; |
| 1972 | if (h) |
| 1973 | *h = box->y2 - box->y1; |
| 1974 | |
| 1975 | pixman_region32_fini(®ion); |
| 1976 | } |
| 1977 | |
Kristian Høgsberg | 9e31bff | 2012-08-01 00:08:07 -0400 | [diff] [blame] | 1978 | static int |
| 1979 | surface_resize(struct shell_surface *shsurf, |
Derek Foreman | 8fbebbd | 2015-07-15 13:00:40 -0500 | [diff] [blame] | 1980 | struct weston_pointer *pointer, uint32_t edges) |
Kristian Høgsberg | 9e31bff | 2012-08-01 00:08:07 -0400 | [diff] [blame] | 1981 | { |
| 1982 | struct weston_resize_grab *resize; |
Ondřej Majerech | ae9c4fc | 2014-08-21 15:47:22 +0200 | [diff] [blame] | 1983 | const unsigned resize_topbottom = |
| 1984 | WL_SHELL_SURFACE_RESIZE_TOP | WL_SHELL_SURFACE_RESIZE_BOTTOM; |
| 1985 | const unsigned resize_leftright = |
| 1986 | WL_SHELL_SURFACE_RESIZE_LEFT | WL_SHELL_SURFACE_RESIZE_RIGHT; |
| 1987 | const unsigned resize_any = resize_topbottom | resize_leftright; |
Kristian Høgsberg | 9e31bff | 2012-08-01 00:08:07 -0400 | [diff] [blame] | 1988 | |
Kristian Høgsberg | a4b620e | 2014-04-30 16:05:49 -0700 | [diff] [blame] | 1989 | if (shsurf->grabbed || |
| 1990 | shsurf->state.fullscreen || shsurf->state.maximized) |
Kristian Høgsberg | 9e31bff | 2012-08-01 00:08:07 -0400 | [diff] [blame] | 1991 | return 0; |
| 1992 | |
Ondřej Majerech | ae9c4fc | 2014-08-21 15:47:22 +0200 | [diff] [blame] | 1993 | /* Check for invalid edge combinations. */ |
| 1994 | if (edges == WL_SHELL_SURFACE_RESIZE_NONE || edges > resize_any || |
| 1995 | (edges & resize_topbottom) == resize_topbottom || |
| 1996 | (edges & resize_leftright) == resize_leftright) |
Kristian Høgsberg | 9e31bff | 2012-08-01 00:08:07 -0400 | [diff] [blame] | 1997 | return 0; |
| 1998 | |
| 1999 | resize = malloc(sizeof *resize); |
| 2000 | if (!resize) |
| 2001 | return -1; |
| 2002 | |
| 2003 | resize->edges = edges; |
Kristian Høgsberg | 9e31bff | 2012-08-01 00:08:07 -0400 | [diff] [blame] | 2004 | |
Jasper St. Pierre | ccf48fb | 2014-05-02 10:21:38 -0400 | [diff] [blame] | 2005 | resize->width = shsurf->geometry.width; |
| 2006 | resize->height = shsurf->geometry.height; |
Jasper St. Pierre | bd65e50 | 2014-07-14 16:28:48 -0400 | [diff] [blame] | 2007 | |
Kristian Høgsberg | 44cd196 | 2014-02-05 21:36:04 -0800 | [diff] [blame] | 2008 | shsurf->resize_edges = edges; |
Jasper St. Pierre | 5befdda | 2014-05-06 08:50:47 -0400 | [diff] [blame] | 2009 | shell_surface_state_changed(shsurf); |
Kristian Høgsberg | 9e31bff | 2012-08-01 00:08:07 -0400 | [diff] [blame] | 2010 | shell_grab_start(&resize->base, &resize_grab_interface, shsurf, |
Derek Foreman | 8fbebbd | 2015-07-15 13:00:40 -0500 | [diff] [blame] | 2011 | pointer, edges); |
Kristian Høgsberg | 9e31bff | 2012-08-01 00:08:07 -0400 | [diff] [blame] | 2012 | |
| 2013 | return 0; |
| 2014 | } |
| 2015 | |
| 2016 | static void |
Rafael Antognolli | e2a3455 | 2013-12-03 15:35:45 -0200 | [diff] [blame] | 2017 | common_surface_resize(struct wl_resource *resource, |
| 2018 | struct wl_resource *seat_resource, uint32_t serial, |
| 2019 | uint32_t edges) |
Kristian Høgsberg | 9e31bff | 2012-08-01 00:08:07 -0400 | [diff] [blame] | 2020 | { |
Jason Ekstrand | 44a3863 | 2013-06-14 10:08:00 -0500 | [diff] [blame] | 2021 | struct weston_seat *seat = wl_resource_get_user_data(seat_resource); |
Derek Foreman | 1281a36 | 2015-07-31 16:55:32 -0500 | [diff] [blame] | 2022 | struct weston_pointer *pointer = weston_seat_get_pointer(seat); |
Jason Ekstrand | 651f00e | 2013-06-14 10:07:54 -0500 | [diff] [blame] | 2023 | struct shell_surface *shsurf = wl_resource_get_user_data(resource); |
Giulio Camuffo | 61da3fc | 2013-04-25 13:57:45 +0300 | [diff] [blame] | 2024 | struct weston_surface *surface; |
Kristian Høgsberg | 9e31bff | 2012-08-01 00:08:07 -0400 | [diff] [blame] | 2025 | |
Derek Foreman | 1281a36 | 2015-07-31 16:55:32 -0500 | [diff] [blame] | 2026 | if (!pointer || |
| 2027 | pointer->button_count == 0 || |
| 2028 | pointer->grab_serial != serial || |
| 2029 | pointer->focus == NULL) |
Kristian Høgsberg | 70f2901 | 2014-01-09 15:43:17 -0800 | [diff] [blame] | 2030 | return; |
| 2031 | |
Derek Foreman | 1281a36 | 2015-07-31 16:55:32 -0500 | [diff] [blame] | 2032 | surface = weston_surface_get_main_surface(pointer->focus->surface); |
Kristian Høgsberg | 70f2901 | 2014-01-09 15:43:17 -0800 | [diff] [blame] | 2033 | if (surface != shsurf->surface) |
Kristian Høgsberg | 9e31bff | 2012-08-01 00:08:07 -0400 | [diff] [blame] | 2034 | return; |
| 2035 | |
Derek Foreman | 1281a36 | 2015-07-31 16:55:32 -0500 | [diff] [blame] | 2036 | if (surface_resize(shsurf, pointer, edges) < 0) |
Kristian Høgsberg | 9e31bff | 2012-08-01 00:08:07 -0400 | [diff] [blame] | 2037 | wl_resource_post_no_memory(resource); |
| 2038 | } |
| 2039 | |
Scott Moreau | c3e54eb | 2012-04-17 19:06:20 -0600 | [diff] [blame] | 2040 | static void |
Rafael Antognolli | e2a3455 | 2013-12-03 15:35:45 -0200 | [diff] [blame] | 2041 | shell_surface_resize(struct wl_client *client, struct wl_resource *resource, |
| 2042 | struct wl_resource *seat_resource, uint32_t serial, |
| 2043 | uint32_t edges) |
| 2044 | { |
| 2045 | common_surface_resize(resource, seat_resource, serial, edges); |
| 2046 | } |
| 2047 | |
| 2048 | static void |
Kristian Høgsberg | 6848c25 | 2013-05-08 22:02:59 -0400 | [diff] [blame] | 2049 | busy_cursor_grab_focus(struct weston_pointer_grab *base) |
Scott Moreau | c3e54eb | 2012-04-17 19:06:20 -0600 | [diff] [blame] | 2050 | { |
Kristian Høgsberg | d56bd90 | 2012-06-05 09:58:51 -0400 | [diff] [blame] | 2051 | struct shell_grab *grab = (struct shell_grab *) base; |
Kristian Høgsberg | 6848c25 | 2013-05-08 22:02:59 -0400 | [diff] [blame] | 2052 | struct weston_pointer *pointer = base->pointer; |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 2053 | struct weston_view *view; |
Kristian Høgsberg | 6848c25 | 2013-05-08 22:02:59 -0400 | [diff] [blame] | 2054 | wl_fixed_t sx, sy; |
| 2055 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 2056 | view = weston_compositor_pick_view(pointer->seat->compositor, |
| 2057 | pointer->x, pointer->y, |
| 2058 | &sx, &sy); |
Scott Moreau | c3e54eb | 2012-04-17 19:06:20 -0600 | [diff] [blame] | 2059 | |
Kristian Høgsberg | 2bff94e | 2014-02-11 12:22:51 -0800 | [diff] [blame] | 2060 | if (!grab->shsurf || grab->shsurf->surface != view->surface) { |
| 2061 | shell_grab_end(grab); |
| 2062 | free(grab); |
| 2063 | } |
Scott Moreau | c3e54eb | 2012-04-17 19:06:20 -0600 | [diff] [blame] | 2064 | } |
| 2065 | |
| 2066 | static void |
Giulio Camuffo | 1959ab8 | 2013-11-14 23:42:52 +0100 | [diff] [blame] | 2067 | busy_cursor_grab_motion(struct weston_pointer_grab *grab, uint32_t time, |
| 2068 | wl_fixed_t x, wl_fixed_t y) |
Scott Moreau | c3e54eb | 2012-04-17 19:06:20 -0600 | [diff] [blame] | 2069 | { |
Giulio Camuffo | 1959ab8 | 2013-11-14 23:42:52 +0100 | [diff] [blame] | 2070 | weston_pointer_move(grab->pointer, x, y); |
Kristian Høgsberg | d56bd90 | 2012-06-05 09:58:51 -0400 | [diff] [blame] | 2071 | } |
Scott Moreau | c3e54eb | 2012-04-17 19:06:20 -0600 | [diff] [blame] | 2072 | |
Kristian Høgsberg | d56bd90 | 2012-06-05 09:58:51 -0400 | [diff] [blame] | 2073 | static void |
Kristian Høgsberg | 02bbabb | 2013-05-06 22:15:05 -0400 | [diff] [blame] | 2074 | busy_cursor_grab_button(struct weston_pointer_grab *base, |
Kristian Høgsberg | d56bd90 | 2012-06-05 09:58:51 -0400 | [diff] [blame] | 2075 | uint32_t time, uint32_t button, uint32_t state) |
| 2076 | { |
Kristian Høgsberg | bbe9839 | 2012-08-01 00:20:21 -0400 | [diff] [blame] | 2077 | struct shell_grab *grab = (struct shell_grab *) base; |
Kristian Høgsberg | e122b7b | 2013-05-08 16:47:00 -0400 | [diff] [blame] | 2078 | struct shell_surface *shsurf = grab->shsurf; |
Derek Foreman | 794fa0e | 2015-07-15 13:00:38 -0500 | [diff] [blame] | 2079 | struct weston_pointer *pointer = grab->grab.pointer; |
| 2080 | struct weston_seat *seat = pointer->seat; |
Kristian Høgsberg | bbe9839 | 2012-08-01 00:20:21 -0400 | [diff] [blame] | 2081 | |
Kristian Høgsberg | bbe9839 | 2012-08-01 00:20:21 -0400 | [diff] [blame] | 2082 | if (shsurf && button == BTN_LEFT && state) { |
Emilio Pozuelo Monfort | 9e7c759 | 2014-01-30 14:01:10 +0100 | [diff] [blame] | 2083 | activate(shsurf->shell, shsurf->surface, seat, true); |
Derek Foreman | 794fa0e | 2015-07-15 13:00:38 -0500 | [diff] [blame] | 2084 | surface_move(shsurf, pointer, false); |
Kristian Høgsberg | 0c36903 | 2013-02-14 21:31:44 -0500 | [diff] [blame] | 2085 | } else if (shsurf && button == BTN_RIGHT && state) { |
Emilio Pozuelo Monfort | 9e7c759 | 2014-01-30 14:01:10 +0100 | [diff] [blame] | 2086 | activate(shsurf->shell, shsurf->surface, seat, true); |
Derek Foreman | 74de469 | 2015-07-15 13:00:39 -0500 | [diff] [blame] | 2087 | surface_rotate(shsurf, pointer); |
Kristian Høgsberg | bbe9839 | 2012-08-01 00:20:21 -0400 | [diff] [blame] | 2088 | } |
Kristian Høgsberg | d56bd90 | 2012-06-05 09:58:51 -0400 | [diff] [blame] | 2089 | } |
| 2090 | |
Jonas Ådahl | 1ea343e | 2013-10-25 23:18:05 +0200 | [diff] [blame] | 2091 | static void |
| 2092 | busy_cursor_grab_cancel(struct weston_pointer_grab *base) |
| 2093 | { |
| 2094 | struct shell_grab *grab = (struct shell_grab *) base; |
| 2095 | |
| 2096 | shell_grab_end(grab); |
| 2097 | free(grab); |
| 2098 | } |
| 2099 | |
Kristian Høgsberg | 02bbabb | 2013-05-06 22:15:05 -0400 | [diff] [blame] | 2100 | static const struct weston_pointer_grab_interface busy_cursor_grab_interface = { |
Kristian Høgsberg | d56bd90 | 2012-06-05 09:58:51 -0400 | [diff] [blame] | 2101 | busy_cursor_grab_focus, |
| 2102 | busy_cursor_grab_motion, |
| 2103 | busy_cursor_grab_button, |
Jonas Ådahl | 1ea343e | 2013-10-25 23:18:05 +0200 | [diff] [blame] | 2104 | busy_cursor_grab_cancel, |
Kristian Høgsberg | d56bd90 | 2012-06-05 09:58:51 -0400 | [diff] [blame] | 2105 | }; |
| 2106 | |
| 2107 | static void |
Kristian Høgsberg | 02bbabb | 2013-05-06 22:15:05 -0400 | [diff] [blame] | 2108 | set_busy_cursor(struct shell_surface *shsurf, struct weston_pointer *pointer) |
Kristian Høgsberg | d56bd90 | 2012-06-05 09:58:51 -0400 | [diff] [blame] | 2109 | { |
| 2110 | struct shell_grab *grab; |
Kristian Høgsberg | d56bd90 | 2012-06-05 09:58:51 -0400 | [diff] [blame] | 2111 | |
Kristian Høgsberg | 2bff94e | 2014-02-11 12:22:51 -0800 | [diff] [blame] | 2112 | if (pointer->grab->interface == &busy_cursor_grab_interface) |
| 2113 | return; |
| 2114 | |
Kristian Høgsberg | d56bd90 | 2012-06-05 09:58:51 -0400 | [diff] [blame] | 2115 | grab = malloc(sizeof *grab); |
| 2116 | if (!grab) |
Scott Moreau | c3e54eb | 2012-04-17 19:06:20 -0600 | [diff] [blame] | 2117 | return; |
| 2118 | |
Ander Conselvan de Oliveira | b9d2a0f | 2012-06-28 18:08:05 +0300 | [diff] [blame] | 2119 | shell_grab_start(grab, &busy_cursor_grab_interface, shsurf, pointer, |
| 2120 | DESKTOP_SHELL_CURSOR_BUSY); |
Ander Conselvan de Oliveira | e5a1aee | 2014-04-09 17:39:39 +0300 | [diff] [blame] | 2121 | /* Mark the shsurf as ungrabbed so that button binding is able |
| 2122 | * to move it. */ |
| 2123 | shsurf->grabbed = 0; |
Kristian Høgsberg | d56bd90 | 2012-06-05 09:58:51 -0400 | [diff] [blame] | 2124 | } |
Scott Moreau | c3e54eb | 2012-04-17 19:06:20 -0600 | [diff] [blame] | 2125 | |
Kristian Høgsberg | d56bd90 | 2012-06-05 09:58:51 -0400 | [diff] [blame] | 2126 | static void |
Kristian Høgsberg | 2bff94e | 2014-02-11 12:22:51 -0800 | [diff] [blame] | 2127 | end_busy_cursor(struct weston_compositor *compositor, struct wl_client *client) |
Kristian Høgsberg | d56bd90 | 2012-06-05 09:58:51 -0400 | [diff] [blame] | 2128 | { |
Kristian Høgsberg | 2bff94e | 2014-02-11 12:22:51 -0800 | [diff] [blame] | 2129 | struct shell_grab *grab; |
| 2130 | struct weston_seat *seat; |
Kristian Høgsberg | d56bd90 | 2012-06-05 09:58:51 -0400 | [diff] [blame] | 2131 | |
Kristian Høgsberg | 2bff94e | 2014-02-11 12:22:51 -0800 | [diff] [blame] | 2132 | wl_list_for_each(seat, &compositor->seat_list, link) { |
Derek Foreman | 1281a36 | 2015-07-31 16:55:32 -0500 | [diff] [blame] | 2133 | struct weston_pointer *pointer = weston_seat_get_pointer(seat); |
| 2134 | |
| 2135 | if (!pointer) |
Kristian Høgsberg | 2bff94e | 2014-02-11 12:22:51 -0800 | [diff] [blame] | 2136 | continue; |
| 2137 | |
Derek Foreman | 1281a36 | 2015-07-31 16:55:32 -0500 | [diff] [blame] | 2138 | grab = (struct shell_grab *) pointer->grab; |
Kristian Høgsberg | 2bff94e | 2014-02-11 12:22:51 -0800 | [diff] [blame] | 2139 | if (grab->grab.interface == &busy_cursor_grab_interface && |
Derek Foreman | c0c1497 | 2015-09-11 14:30:39 -0500 | [diff] [blame] | 2140 | grab->shsurf->resource && |
Kristian Høgsberg | 2bff94e | 2014-02-11 12:22:51 -0800 | [diff] [blame] | 2141 | wl_resource_get_client(grab->shsurf->resource) == client) { |
| 2142 | shell_grab_end(grab); |
| 2143 | free(grab); |
| 2144 | } |
Scott Moreau | c3e54eb | 2012-04-17 19:06:20 -0600 | [diff] [blame] | 2145 | } |
Scott Moreau | c3e54eb | 2012-04-17 19:06:20 -0600 | [diff] [blame] | 2146 | } |
| 2147 | |
Scott Moreau | 9521d5e | 2012-04-19 13:06:17 -0600 | [diff] [blame] | 2148 | static void |
Kristian Høgsberg | 2bff94e | 2014-02-11 12:22:51 -0800 | [diff] [blame] | 2149 | handle_shell_client_destroy(struct wl_listener *listener, void *data); |
| 2150 | |
| 2151 | static int |
| 2152 | xdg_ping_timeout_handler(void *data) |
| 2153 | { |
| 2154 | struct shell_client *sc = data; |
| 2155 | struct weston_seat *seat; |
| 2156 | struct shell_surface *shsurf; |
| 2157 | |
| 2158 | /* Client is not responding */ |
| 2159 | sc->unresponsive = 1; |
Kristian Høgsberg | 2bff94e | 2014-02-11 12:22:51 -0800 | [diff] [blame] | 2160 | wl_list_for_each(seat, &sc->shell->compositor->seat_list, link) { |
Derek Foreman | 1281a36 | 2015-07-31 16:55:32 -0500 | [diff] [blame] | 2161 | struct weston_pointer *pointer = weston_seat_get_pointer(seat); |
| 2162 | |
| 2163 | if (!pointer || |
| 2164 | !pointer->focus || |
| 2165 | !pointer->focus->surface->resource) |
Kristian Høgsberg | 2bff94e | 2014-02-11 12:22:51 -0800 | [diff] [blame] | 2166 | continue; |
Michael Vetter | 2a18a52 | 2015-05-15 17:17:47 +0200 | [diff] [blame] | 2167 | |
Derek Foreman | 1281a36 | 2015-07-31 16:55:32 -0500 | [diff] [blame] | 2168 | shsurf = get_shell_surface(pointer->focus->surface); |
Kristian Høgsberg | 2bff94e | 2014-02-11 12:22:51 -0800 | [diff] [blame] | 2169 | if (shsurf && |
| 2170 | wl_resource_get_client(shsurf->resource) == sc->client) |
Derek Foreman | 1281a36 | 2015-07-31 16:55:32 -0500 | [diff] [blame] | 2171 | set_busy_cursor(shsurf, pointer); |
Kristian Høgsberg | 2bff94e | 2014-02-11 12:22:51 -0800 | [diff] [blame] | 2172 | } |
| 2173 | |
| 2174 | return 1; |
| 2175 | } |
| 2176 | |
| 2177 | static void |
| 2178 | handle_xdg_ping(struct shell_surface *shsurf, uint32_t serial) |
| 2179 | { |
| 2180 | struct weston_compositor *compositor = shsurf->shell->compositor; |
Jason Ekstrand | 9e9512f | 2014-04-16 21:12:10 -0500 | [diff] [blame] | 2181 | struct shell_client *sc = shsurf->owner; |
Kristian Høgsberg | 2bff94e | 2014-02-11 12:22:51 -0800 | [diff] [blame] | 2182 | struct wl_event_loop *loop; |
Kristian Høgsberg | dd62aba | 2014-02-12 09:56:19 -0800 | [diff] [blame] | 2183 | static const int ping_timeout = 200; |
Kristian Høgsberg | 2bff94e | 2014-02-11 12:22:51 -0800 | [diff] [blame] | 2184 | |
Kristian Høgsberg | 2bff94e | 2014-02-11 12:22:51 -0800 | [diff] [blame] | 2185 | if (sc->unresponsive) { |
| 2186 | xdg_ping_timeout_handler(sc); |
| 2187 | return; |
| 2188 | } |
| 2189 | |
| 2190 | sc->ping_serial = serial; |
| 2191 | loop = wl_display_get_event_loop(compositor->wl_display); |
| 2192 | if (sc->ping_timer == NULL) |
| 2193 | sc->ping_timer = |
| 2194 | wl_event_loop_add_timer(loop, |
| 2195 | xdg_ping_timeout_handler, sc); |
| 2196 | if (sc->ping_timer == NULL) |
| 2197 | return; |
| 2198 | |
| 2199 | wl_event_source_timer_update(sc->ping_timer, ping_timeout); |
| 2200 | |
Kristian Høgsberg | dd62aba | 2014-02-12 09:56:19 -0800 | [diff] [blame] | 2201 | if (shell_surface_is_xdg_surface(shsurf) || |
| 2202 | shell_surface_is_xdg_popup(shsurf)) |
| 2203 | xdg_shell_send_ping(sc->resource, serial); |
| 2204 | else if (shell_surface_is_wl_shell_surface(shsurf)) |
| 2205 | wl_shell_surface_send_ping(shsurf->resource, serial); |
Kristian Høgsberg | 2bff94e | 2014-02-11 12:22:51 -0800 | [diff] [blame] | 2206 | } |
| 2207 | |
Scott Moreau | ff1db4a | 2012-04-17 19:06:18 -0600 | [diff] [blame] | 2208 | static void |
| 2209 | ping_handler(struct weston_surface *surface, uint32_t serial) |
| 2210 | { |
Kristian Høgsberg | b71302e | 2012-05-10 12:28:35 -0400 | [diff] [blame] | 2211 | struct shell_surface *shsurf = get_shell_surface(surface); |
Scott Moreau | ff1db4a | 2012-04-17 19:06:18 -0600 | [diff] [blame] | 2212 | |
| 2213 | if (!shsurf) |
| 2214 | return; |
Jason Ekstrand | 651f00e | 2013-06-14 10:07:54 -0500 | [diff] [blame] | 2215 | if (!shsurf->resource) |
Kristian Høgsberg | ca535c1 | 2012-04-21 23:20:07 -0400 | [diff] [blame] | 2216 | return; |
Ander Conselvan de Oliveira | eac9a46 | 2012-07-16 14:15:48 +0300 | [diff] [blame] | 2217 | if (shsurf->surface == shsurf->shell->grab_surface) |
| 2218 | return; |
| 2219 | |
Kristian Høgsberg | dd62aba | 2014-02-12 09:56:19 -0800 | [diff] [blame] | 2220 | handle_xdg_ping(shsurf, serial); |
Scott Moreau | ff1db4a | 2012-04-17 19:06:18 -0600 | [diff] [blame] | 2221 | } |
| 2222 | |
| 2223 | static void |
Kristian Høgsberg | d56bd90 | 2012-06-05 09:58:51 -0400 | [diff] [blame] | 2224 | handle_pointer_focus(struct wl_listener *listener, void *data) |
| 2225 | { |
Kristian Høgsberg | 02bbabb | 2013-05-06 22:15:05 -0400 | [diff] [blame] | 2226 | struct weston_pointer *pointer = data; |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 2227 | struct weston_view *view = pointer->focus; |
Kristian Høgsberg | d56bd90 | 2012-06-05 09:58:51 -0400 | [diff] [blame] | 2228 | struct weston_compositor *compositor; |
Kristian Høgsberg | d56bd90 | 2012-06-05 09:58:51 -0400 | [diff] [blame] | 2229 | uint32_t serial; |
| 2230 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 2231 | if (!view) |
Kristian Høgsberg | d56bd90 | 2012-06-05 09:58:51 -0400 | [diff] [blame] | 2232 | return; |
| 2233 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 2234 | compositor = view->surface->compositor; |
Kristian Høgsberg | e11ef64 | 2014-02-11 16:35:22 -0800 | [diff] [blame] | 2235 | serial = wl_display_next_serial(compositor->wl_display); |
| 2236 | ping_handler(view->surface, serial); |
Kristian Høgsberg | d56bd90 | 2012-06-05 09:58:51 -0400 | [diff] [blame] | 2237 | } |
| 2238 | |
| 2239 | static void |
Jasper St. Pierre | faf27a9 | 2013-12-09 17:36:28 -0500 | [diff] [blame] | 2240 | shell_surface_lose_keyboard_focus(struct shell_surface *shsurf) |
| 2241 | { |
| 2242 | if (--shsurf->focus_count == 0) |
Jasper St. Pierre | 973d787 | 2014-05-06 08:44:29 -0400 | [diff] [blame] | 2243 | shell_surface_state_changed(shsurf); |
Jasper St. Pierre | faf27a9 | 2013-12-09 17:36:28 -0500 | [diff] [blame] | 2244 | } |
| 2245 | |
| 2246 | static void |
| 2247 | shell_surface_gain_keyboard_focus(struct shell_surface *shsurf) |
| 2248 | { |
| 2249 | if (shsurf->focus_count++ == 0) |
Jasper St. Pierre | 973d787 | 2014-05-06 08:44:29 -0400 | [diff] [blame] | 2250 | shell_surface_state_changed(shsurf); |
Jasper St. Pierre | faf27a9 | 2013-12-09 17:36:28 -0500 | [diff] [blame] | 2251 | } |
| 2252 | |
| 2253 | static void |
| 2254 | handle_keyboard_focus(struct wl_listener *listener, void *data) |
| 2255 | { |
| 2256 | struct weston_keyboard *keyboard = data; |
| 2257 | struct shell_seat *seat = get_shell_seat(keyboard->seat); |
| 2258 | |
| 2259 | if (seat->focused_surface) { |
| 2260 | struct shell_surface *shsurf = get_shell_surface(seat->focused_surface); |
| 2261 | if (shsurf) |
| 2262 | shell_surface_lose_keyboard_focus(shsurf); |
| 2263 | } |
| 2264 | |
| 2265 | seat->focused_surface = keyboard->focus; |
| 2266 | |
| 2267 | if (seat->focused_surface) { |
| 2268 | struct shell_surface *shsurf = get_shell_surface(seat->focused_surface); |
| 2269 | if (shsurf) |
| 2270 | shell_surface_gain_keyboard_focus(shsurf); |
| 2271 | } |
| 2272 | } |
| 2273 | |
| 2274 | static void |
Kristian Høgsberg | dd62aba | 2014-02-12 09:56:19 -0800 | [diff] [blame] | 2275 | shell_client_pong(struct shell_client *sc, uint32_t serial) |
Rafael Antognolli | e2a3455 | 2013-12-03 15:35:45 -0200 | [diff] [blame] | 2276 | { |
Kristian Høgsberg | dd62aba | 2014-02-12 09:56:19 -0800 | [diff] [blame] | 2277 | if (sc->ping_serial != serial) |
| 2278 | return; |
Rafael Antognolli | e2a3455 | 2013-12-03 15:35:45 -0200 | [diff] [blame] | 2279 | |
Kristian Høgsberg | dd62aba | 2014-02-12 09:56:19 -0800 | [diff] [blame] | 2280 | sc->unresponsive = 0; |
| 2281 | end_busy_cursor(sc->shell->compositor, sc->client); |
Rafael Antognolli | e2a3455 | 2013-12-03 15:35:45 -0200 | [diff] [blame] | 2282 | |
Kristian Høgsberg | dd62aba | 2014-02-12 09:56:19 -0800 | [diff] [blame] | 2283 | if (sc->ping_timer) { |
| 2284 | wl_event_source_remove(sc->ping_timer); |
| 2285 | sc->ping_timer = NULL; |
| 2286 | } |
| 2287 | |
| 2288 | } |
| 2289 | |
| 2290 | static void |
| 2291 | shell_surface_pong(struct wl_client *client, |
| 2292 | struct wl_resource *resource, uint32_t serial) |
| 2293 | { |
Jason Ekstrand | 9e9512f | 2014-04-16 21:12:10 -0500 | [diff] [blame] | 2294 | struct shell_surface *shsurf = wl_resource_get_user_data(resource); |
| 2295 | struct shell_client *sc = shsurf->owner; |
Kristian Høgsberg | dd62aba | 2014-02-12 09:56:19 -0800 | [diff] [blame] | 2296 | |
Kristian Høgsberg | dd62aba | 2014-02-12 09:56:19 -0800 | [diff] [blame] | 2297 | shell_client_pong(sc, serial); |
Rafael Antognolli | e2a3455 | 2013-12-03 15:35:45 -0200 | [diff] [blame] | 2298 | } |
| 2299 | |
| 2300 | static void |
Giulio Camuffo | 62942ad | 2013-09-11 18:20:47 +0200 | [diff] [blame] | 2301 | set_title(struct shell_surface *shsurf, const char *title) |
| 2302 | { |
| 2303 | free(shsurf->title); |
| 2304 | shsurf->title = strdup(title); |
Pekka Paalanen | b502654 | 2014-11-12 15:09:24 +0200 | [diff] [blame] | 2305 | shsurf->surface->timeline.force_refresh = 1; |
| 2306 | } |
| 2307 | |
| 2308 | static void |
Giulio Camuffo | a8e9b41 | 2015-01-27 19:10:37 +0200 | [diff] [blame] | 2309 | set_pid(struct shell_surface *shsurf, pid_t pid) |
| 2310 | { |
| 2311 | /* We have no use for it */ |
| 2312 | } |
| 2313 | |
| 2314 | static void |
Pekka Paalanen | b502654 | 2014-11-12 15:09:24 +0200 | [diff] [blame] | 2315 | set_type(struct shell_surface *shsurf, enum shell_surface_type t) |
| 2316 | { |
| 2317 | shsurf->type = t; |
| 2318 | shsurf->surface->timeline.force_refresh = 1; |
Giulio Camuffo | 62942ad | 2013-09-11 18:20:47 +0200 | [diff] [blame] | 2319 | } |
| 2320 | |
| 2321 | static void |
Jasper St. Pierre | ccf48fb | 2014-05-02 10:21:38 -0400 | [diff] [blame] | 2322 | set_window_geometry(struct shell_surface *shsurf, |
| 2323 | 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] | 2324 | { |
Jasper St. Pierre | ccf48fb | 2014-05-02 10:21:38 -0400 | [diff] [blame] | 2325 | shsurf->next_geometry.x = x; |
| 2326 | shsurf->next_geometry.y = y; |
| 2327 | shsurf->next_geometry.width = width; |
| 2328 | shsurf->next_geometry.height = height; |
| 2329 | shsurf->has_next_geometry = true; |
Kristian Høgsberg | e5c1ae9 | 2014-04-30 16:28:41 -0700 | [diff] [blame] | 2330 | } |
| 2331 | |
| 2332 | static void |
Kristian Høgsberg | e7afd91 | 2012-05-02 09:47:44 -0400 | [diff] [blame] | 2333 | shell_surface_set_title(struct wl_client *client, |
| 2334 | struct wl_resource *resource, const char *title) |
| 2335 | { |
Jason Ekstrand | 651f00e | 2013-06-14 10:07:54 -0500 | [diff] [blame] | 2336 | struct shell_surface *shsurf = wl_resource_get_user_data(resource); |
Kristian Høgsberg | e7afd91 | 2012-05-02 09:47:44 -0400 | [diff] [blame] | 2337 | |
Giulio Camuffo | 62942ad | 2013-09-11 18:20:47 +0200 | [diff] [blame] | 2338 | set_title(shsurf, title); |
Kristian Høgsberg | e7afd91 | 2012-05-02 09:47:44 -0400 | [diff] [blame] | 2339 | } |
| 2340 | |
| 2341 | static void |
| 2342 | shell_surface_set_class(struct wl_client *client, |
| 2343 | struct wl_resource *resource, const char *class) |
| 2344 | { |
Jason Ekstrand | 651f00e | 2013-06-14 10:07:54 -0500 | [diff] [blame] | 2345 | struct shell_surface *shsurf = wl_resource_get_user_data(resource); |
Kristian Høgsberg | e7afd91 | 2012-05-02 09:47:44 -0400 | [diff] [blame] | 2346 | |
| 2347 | free(shsurf->class); |
| 2348 | shsurf->class = strdup(class); |
Pekka Paalanen | b502654 | 2014-11-12 15:09:24 +0200 | [diff] [blame] | 2349 | shsurf->surface->timeline.force_refresh = 1; |
Kristian Høgsberg | e7afd91 | 2012-05-02 09:47:44 -0400 | [diff] [blame] | 2350 | } |
| 2351 | |
Alex Wu | 4539b08 | 2012-03-01 12:57:46 +0800 | [diff] [blame] | 2352 | static void |
Alexander Larsson | f82b6ca | 2013-05-28 16:23:39 +0200 | [diff] [blame] | 2353 | restore_output_mode(struct weston_output *output) |
| 2354 | { |
Derek Foreman | 6ae7bc9 | 2014-11-04 10:47:33 -0600 | [diff] [blame] | 2355 | if (output->original_mode) |
| 2356 | weston_output_mode_switch_to_native(output); |
Alexander Larsson | f82b6ca | 2013-05-28 16:23:39 +0200 | [diff] [blame] | 2357 | } |
| 2358 | |
| 2359 | static void |
| 2360 | restore_all_output_modes(struct weston_compositor *compositor) |
| 2361 | { |
| 2362 | struct weston_output *output; |
| 2363 | |
| 2364 | wl_list_for_each(output, &compositor->output_list, link) |
| 2365 | restore_output_mode(output); |
| 2366 | } |
| 2367 | |
Philip Withnall | 07926d9 | 2013-11-25 18:01:40 +0000 | [diff] [blame] | 2368 | /* The surface will be inserted into the list immediately after the link |
| 2369 | * returned by this function (i.e. will be stacked immediately above the |
| 2370 | * returned link). */ |
Giulio Camuffo | 412e6a5 | 2014-07-09 22:12:56 +0300 | [diff] [blame] | 2371 | static struct weston_layer_entry * |
Philip Withnall | 07926d9 | 2013-11-25 18:01:40 +0000 | [diff] [blame] | 2372 | shell_surface_calculate_layer_link (struct shell_surface *shsurf) |
| 2373 | { |
| 2374 | struct workspace *ws; |
Kristian Høgsberg | ead5242 | 2014-01-01 13:51:52 -0800 | [diff] [blame] | 2375 | struct weston_view *parent; |
Philip Withnall | 07926d9 | 2013-11-25 18:01:40 +0000 | [diff] [blame] | 2376 | |
| 2377 | switch (shsurf->type) { |
Ander Conselvan de Oliveira | ef6a7e4 | 2014-04-30 14:15:14 +0300 | [diff] [blame] | 2378 | case SHELL_SURFACE_XWAYLAND: |
| 2379 | return &shsurf->shell->fullscreen_layer.view_list; |
| 2380 | |
| 2381 | case SHELL_SURFACE_NONE: |
| 2382 | return NULL; |
| 2383 | |
Kristian Høgsberg | ead5242 | 2014-01-01 13:51:52 -0800 | [diff] [blame] | 2384 | case SHELL_SURFACE_POPUP: |
| 2385 | case SHELL_SURFACE_TOPLEVEL: |
Emilio Pozuelo Monfort | 9e7c759 | 2014-01-30 14:01:10 +0100 | [diff] [blame] | 2386 | if (shsurf->state.fullscreen && !shsurf->state.lowered) { |
Rafael Antognolli | 03b1659 | 2013-12-03 15:35:42 -0200 | [diff] [blame] | 2387 | return &shsurf->shell->fullscreen_layer.view_list; |
Rafael Antognolli | ed207b4 | 2013-12-03 15:35:43 -0200 | [diff] [blame] | 2388 | } else if (shsurf->parent) { |
Kristian Høgsberg | d55db69 | 2014-01-01 12:26:14 -0800 | [diff] [blame] | 2389 | /* Move the surface to its parent layer so |
| 2390 | * that surfaces which are transient for |
| 2391 | * fullscreen surfaces don't get hidden by the |
| 2392 | * fullscreen surfaces. */ |
Rafael Antognolli | ed207b4 | 2013-12-03 15:35:43 -0200 | [diff] [blame] | 2393 | |
| 2394 | /* TODO: Handle a parent with multiple views */ |
| 2395 | parent = get_default_view(shsurf->parent); |
| 2396 | if (parent) |
Giulio Camuffo | 412e6a5 | 2014-07-09 22:12:56 +0300 | [diff] [blame] | 2397 | return container_of(parent->layer_link.link.prev, |
| 2398 | struct weston_layer_entry, link); |
Rafael Antognolli | ed207b4 | 2013-12-03 15:35:43 -0200 | [diff] [blame] | 2399 | } |
Philip Withnall | 07926d9 | 2013-11-25 18:01:40 +0000 | [diff] [blame] | 2400 | |
Ander Conselvan de Oliveira | ef6a7e4 | 2014-04-30 14:15:14 +0300 | [diff] [blame] | 2401 | /* Move the surface to a normal workspace layer so that surfaces |
| 2402 | * which were previously fullscreen or transient are no longer |
| 2403 | * rendered on top. */ |
| 2404 | ws = get_current_workspace(shsurf->shell); |
| 2405 | return &ws->layer.view_list; |
Philip Withnall | 07926d9 | 2013-11-25 18:01:40 +0000 | [diff] [blame] | 2406 | } |
| 2407 | |
Ander Conselvan de Oliveira | ef6a7e4 | 2014-04-30 14:15:14 +0300 | [diff] [blame] | 2408 | assert(0 && "Unknown shell surface type"); |
Philip Withnall | 07926d9 | 2013-11-25 18:01:40 +0000 | [diff] [blame] | 2409 | } |
| 2410 | |
Philip Withnall | 648a4dd | 2013-11-25 18:01:44 +0000 | [diff] [blame] | 2411 | static void |
| 2412 | shell_surface_update_child_surface_layers (struct shell_surface *shsurf) |
| 2413 | { |
| 2414 | struct shell_surface *child; |
Giulio Camuffo | 412e6a5 | 2014-07-09 22:12:56 +0300 | [diff] [blame] | 2415 | struct weston_layer_entry *prev; |
Philip Withnall | 648a4dd | 2013-11-25 18:01:44 +0000 | [diff] [blame] | 2416 | |
| 2417 | /* Move the child layers to the same workspace as shsurf. They will be |
| 2418 | * stacked above shsurf. */ |
| 2419 | wl_list_for_each_reverse(child, &shsurf->children_list, children_link) { |
Giulio Camuffo | 412e6a5 | 2014-07-09 22:12:56 +0300 | [diff] [blame] | 2420 | 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] | 2421 | weston_view_damage_below(child->view); |
Philip Withnall | 648a4dd | 2013-11-25 18:01:44 +0000 | [diff] [blame] | 2422 | weston_view_geometry_dirty(child->view); |
Giulio Camuffo | 412e6a5 | 2014-07-09 22:12:56 +0300 | [diff] [blame] | 2423 | prev = container_of(shsurf->view->layer_link.link.prev, |
| 2424 | struct weston_layer_entry, link); |
| 2425 | weston_layer_entry_remove(&child->view->layer_link); |
| 2426 | weston_layer_entry_insert(prev, |
| 2427 | &child->view->layer_link); |
Philip Withnall | 648a4dd | 2013-11-25 18:01:44 +0000 | [diff] [blame] | 2428 | weston_view_geometry_dirty(child->view); |
| 2429 | weston_surface_damage(child->surface); |
| 2430 | |
| 2431 | /* Recurse. We don’t expect this to recurse very far (if |
| 2432 | * at all) because that would imply we have transient |
| 2433 | * (or popup) children of transient surfaces, which |
| 2434 | * would be unusual. */ |
| 2435 | shell_surface_update_child_surface_layers(child); |
| 2436 | } |
| 2437 | } |
| 2438 | } |
| 2439 | |
Philip Withnall | e1d75ae | 2013-11-25 18:01:41 +0000 | [diff] [blame] | 2440 | /* 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] | 2441 | * geometry to ensure the changes are redrawn. |
| 2442 | * |
| 2443 | * If any child surfaces exist and are mapped, ensure they’re in the same layer |
| 2444 | * as this surface. */ |
Philip Withnall | e1d75ae | 2013-11-25 18:01:41 +0000 | [diff] [blame] | 2445 | static void |
| 2446 | shell_surface_update_layer(struct shell_surface *shsurf) |
| 2447 | { |
Giulio Camuffo | 412e6a5 | 2014-07-09 22:12:56 +0300 | [diff] [blame] | 2448 | struct weston_layer_entry *new_layer_link; |
Philip Withnall | e1d75ae | 2013-11-25 18:01:41 +0000 | [diff] [blame] | 2449 | |
| 2450 | new_layer_link = shell_surface_calculate_layer_link(shsurf); |
| 2451 | |
Ander Conselvan de Oliveira | ef6a7e4 | 2014-04-30 14:15:14 +0300 | [diff] [blame] | 2452 | if (new_layer_link == NULL) |
| 2453 | return; |
Philip Withnall | e1d75ae | 2013-11-25 18:01:41 +0000 | [diff] [blame] | 2454 | if (new_layer_link == &shsurf->view->layer_link) |
| 2455 | return; |
| 2456 | |
| 2457 | weston_view_geometry_dirty(shsurf->view); |
Giulio Camuffo | 412e6a5 | 2014-07-09 22:12:56 +0300 | [diff] [blame] | 2458 | weston_layer_entry_remove(&shsurf->view->layer_link); |
| 2459 | weston_layer_entry_insert(new_layer_link, &shsurf->view->layer_link); |
Philip Withnall | e1d75ae | 2013-11-25 18:01:41 +0000 | [diff] [blame] | 2460 | weston_view_geometry_dirty(shsurf->view); |
| 2461 | weston_surface_damage(shsurf->surface); |
Philip Withnall | 648a4dd | 2013-11-25 18:01:44 +0000 | [diff] [blame] | 2462 | |
| 2463 | shell_surface_update_child_surface_layers(shsurf); |
Philip Withnall | e1d75ae | 2013-11-25 18:01:41 +0000 | [diff] [blame] | 2464 | } |
| 2465 | |
Alexander Larsson | f82b6ca | 2013-05-28 16:23:39 +0200 | [diff] [blame] | 2466 | static void |
Philip Withnall | dc4332f | 2013-11-25 18:01:38 +0000 | [diff] [blame] | 2467 | shell_surface_set_parent(struct shell_surface *shsurf, |
| 2468 | struct weston_surface *parent) |
| 2469 | { |
| 2470 | shsurf->parent = parent; |
Philip Withnall | 648a4dd | 2013-11-25 18:01:44 +0000 | [diff] [blame] | 2471 | |
| 2472 | wl_list_remove(&shsurf->children_link); |
| 2473 | wl_list_init(&shsurf->children_link); |
| 2474 | |
| 2475 | /* Insert into the parent surface’s child list. */ |
| 2476 | if (parent != NULL) { |
| 2477 | struct shell_surface *parent_shsurf = get_shell_surface(parent); |
| 2478 | if (parent_shsurf != NULL) |
| 2479 | wl_list_insert(&parent_shsurf->children_list, |
| 2480 | &shsurf->children_link); |
| 2481 | } |
Philip Withnall | dc4332f | 2013-11-25 18:01:38 +0000 | [diff] [blame] | 2482 | } |
| 2483 | |
| 2484 | static void |
Philip Withnall | 352e7ed | 2013-11-25 18:01:35 +0000 | [diff] [blame] | 2485 | shell_surface_set_output(struct shell_surface *shsurf, |
| 2486 | struct weston_output *output) |
| 2487 | { |
| 2488 | struct weston_surface *es = shsurf->surface; |
| 2489 | |
| 2490 | /* get the default output, if the client set it as NULL |
| 2491 | check whether the ouput is available */ |
| 2492 | if (output) |
| 2493 | shsurf->output = output; |
| 2494 | else if (es->output) |
| 2495 | shsurf->output = es->output; |
| 2496 | else |
| 2497 | shsurf->output = get_default_output(es->compositor); |
| 2498 | } |
| 2499 | |
| 2500 | static void |
Rafael Antognolli | 03b1659 | 2013-12-03 15:35:42 -0200 | [diff] [blame] | 2501 | surface_clear_next_states(struct shell_surface *shsurf) |
| 2502 | { |
| 2503 | shsurf->next_state.maximized = false; |
| 2504 | shsurf->next_state.fullscreen = false; |
| 2505 | |
| 2506 | if ((shsurf->next_state.maximized != shsurf->state.maximized) || |
| 2507 | (shsurf->next_state.fullscreen != shsurf->state.fullscreen)) |
| 2508 | shsurf->state_changed = true; |
| 2509 | } |
| 2510 | |
| 2511 | static void |
Philip Withnall | becb77e | 2013-11-25 18:01:30 +0000 | [diff] [blame] | 2512 | set_toplevel(struct shell_surface *shsurf) |
| 2513 | { |
Kristian Høgsberg | 41fbf6f | 2013-12-05 22:31:25 -0800 | [diff] [blame] | 2514 | shell_surface_set_parent(shsurf, NULL); |
| 2515 | surface_clear_next_states(shsurf); |
Pekka Paalanen | b502654 | 2014-11-12 15:09:24 +0200 | [diff] [blame] | 2516 | set_type(shsurf, SHELL_SURFACE_TOPLEVEL); |
Philip Withnall | 648a4dd | 2013-11-25 18:01:44 +0000 | [diff] [blame] | 2517 | |
| 2518 | /* The layer_link is updated in set_surface_type(), |
| 2519 | * called from configure. */ |
Philip Withnall | becb77e | 2013-11-25 18:01:30 +0000 | [diff] [blame] | 2520 | } |
| 2521 | |
| 2522 | static void |
| 2523 | shell_surface_set_toplevel(struct wl_client *client, |
| 2524 | struct wl_resource *resource) |
| 2525 | { |
| 2526 | struct shell_surface *surface = wl_resource_get_user_data(resource); |
| 2527 | |
| 2528 | set_toplevel(surface); |
| 2529 | } |
| 2530 | |
| 2531 | static void |
| 2532 | set_transient(struct shell_surface *shsurf, |
| 2533 | struct weston_surface *parent, int x, int y, uint32_t flags) |
| 2534 | { |
Philip Withnall | dc4332f | 2013-11-25 18:01:38 +0000 | [diff] [blame] | 2535 | assert(parent != NULL); |
| 2536 | |
Kristian Høgsberg | 9f7e331 | 2014-01-02 22:40:37 -0800 | [diff] [blame] | 2537 | shell_surface_set_parent(shsurf, parent); |
| 2538 | |
| 2539 | surface_clear_next_states(shsurf); |
| 2540 | |
Philip Withnall | becb77e | 2013-11-25 18:01:30 +0000 | [diff] [blame] | 2541 | shsurf->transient.x = x; |
| 2542 | shsurf->transient.y = y; |
| 2543 | shsurf->transient.flags = flags; |
Philip Withnall | dc4332f | 2013-11-25 18:01:38 +0000 | [diff] [blame] | 2544 | |
Rafael Antognolli | ed207b4 | 2013-12-03 15:35:43 -0200 | [diff] [blame] | 2545 | shsurf->next_state.relative = true; |
Kristian Høgsberg | a1df7ac | 2013-12-31 15:01:01 -0800 | [diff] [blame] | 2546 | shsurf->state_changed = true; |
Pekka Paalanen | b502654 | 2014-11-12 15:09:24 +0200 | [diff] [blame] | 2547 | set_type(shsurf, SHELL_SURFACE_TOPLEVEL); |
Philip Withnall | 648a4dd | 2013-11-25 18:01:44 +0000 | [diff] [blame] | 2548 | |
| 2549 | /* The layer_link is updated in set_surface_type(), |
| 2550 | * called from configure. */ |
Philip Withnall | becb77e | 2013-11-25 18:01:30 +0000 | [diff] [blame] | 2551 | } |
| 2552 | |
| 2553 | static void |
| 2554 | shell_surface_set_transient(struct wl_client *client, |
| 2555 | struct wl_resource *resource, |
| 2556 | struct wl_resource *parent_resource, |
| 2557 | int x, int y, uint32_t flags) |
| 2558 | { |
| 2559 | struct shell_surface *shsurf = wl_resource_get_user_data(resource); |
| 2560 | struct weston_surface *parent = |
| 2561 | wl_resource_get_user_data(parent_resource); |
| 2562 | |
| 2563 | set_transient(shsurf, parent, x, y, flags); |
| 2564 | } |
| 2565 | |
| 2566 | static void |
| 2567 | set_fullscreen(struct shell_surface *shsurf, |
| 2568 | uint32_t method, |
| 2569 | uint32_t framerate, |
| 2570 | struct weston_output *output) |
| 2571 | { |
Philip Withnall | 352e7ed | 2013-11-25 18:01:35 +0000 | [diff] [blame] | 2572 | shell_surface_set_output(shsurf, output); |
Pekka Paalanen | b502654 | 2014-11-12 15:09:24 +0200 | [diff] [blame] | 2573 | set_type(shsurf, SHELL_SURFACE_TOPLEVEL); |
Philip Withnall | becb77e | 2013-11-25 18:01:30 +0000 | [diff] [blame] | 2574 | |
| 2575 | shsurf->fullscreen_output = shsurf->output; |
| 2576 | shsurf->fullscreen.type = method; |
| 2577 | shsurf->fullscreen.framerate = framerate; |
Philip Withnall | dc4332f | 2013-11-25 18:01:38 +0000 | [diff] [blame] | 2578 | |
Jasper St. Pierre | 6458ec3 | 2014-04-11 16:00:31 -0700 | [diff] [blame] | 2579 | send_configure_for_surface(shsurf); |
Philip Withnall | becb77e | 2013-11-25 18:01:30 +0000 | [diff] [blame] | 2580 | } |
| 2581 | |
| 2582 | static void |
Zhang, Xiong Y | 3123693 | 2013-12-13 22:10:57 +0200 | [diff] [blame] | 2583 | weston_view_set_initial_position(struct weston_view *view, |
| 2584 | struct desktop_shell *shell); |
| 2585 | |
| 2586 | static void |
Philip Withnall | becb77e | 2013-11-25 18:01:30 +0000 | [diff] [blame] | 2587 | unset_fullscreen(struct shell_surface *shsurf) |
Alex Wu | 4539b08 | 2012-03-01 12:57:46 +0800 | [diff] [blame] | 2588 | { |
Philip Withnall | f85fe84 | 2013-11-25 18:01:37 +0000 | [diff] [blame] | 2589 | /* Unset the fullscreen output, driver configuration and transforms. */ |
Alex Wu | bd3354b | 2012-04-17 17:20:49 +0800 | [diff] [blame] | 2590 | if (shsurf->fullscreen.type == WL_SHELL_SURFACE_FULLSCREEN_METHOD_DRIVER && |
| 2591 | shell_surface_is_top_fullscreen(shsurf)) { |
Alexander Larsson | f82b6ca | 2013-05-28 16:23:39 +0200 | [diff] [blame] | 2592 | restore_output_mode(shsurf->fullscreen_output); |
Alex Wu | bd3354b | 2012-04-17 17:20:49 +0800 | [diff] [blame] | 2593 | } |
Philip Withnall | f85fe84 | 2013-11-25 18:01:37 +0000 | [diff] [blame] | 2594 | |
Alex Wu | 4539b08 | 2012-03-01 12:57:46 +0800 | [diff] [blame] | 2595 | shsurf->fullscreen.type = WL_SHELL_SURFACE_FULLSCREEN_METHOD_DEFAULT; |
| 2596 | shsurf->fullscreen.framerate = 0; |
Philip Withnall | f85fe84 | 2013-11-25 18:01:37 +0000 | [diff] [blame] | 2597 | |
Alex Wu | 4539b08 | 2012-03-01 12:57:46 +0800 | [diff] [blame] | 2598 | wl_list_remove(&shsurf->fullscreen.transform.link); |
| 2599 | wl_list_init(&shsurf->fullscreen.transform.link); |
Philip Withnall | f85fe84 | 2013-11-25 18:01:37 +0000 | [diff] [blame] | 2600 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 2601 | if (shsurf->fullscreen.black_view) |
| 2602 | weston_surface_destroy(shsurf->fullscreen.black_view->surface); |
| 2603 | shsurf->fullscreen.black_view = NULL; |
Philip Withnall | f85fe84 | 2013-11-25 18:01:37 +0000 | [diff] [blame] | 2604 | |
Zhang, Xiong Y | 3123693 | 2013-12-13 22:10:57 +0200 | [diff] [blame] | 2605 | if (shsurf->saved_position_valid) |
| 2606 | weston_view_set_position(shsurf->view, |
| 2607 | shsurf->saved_x, shsurf->saved_y); |
| 2608 | else |
| 2609 | weston_view_set_initial_position(shsurf->view, shsurf->shell); |
| 2610 | |
Alex Wu | 7bcb8bd | 2012-04-27 09:07:24 +0800 | [diff] [blame] | 2611 | if (shsurf->saved_rotation_valid) { |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 2612 | wl_list_insert(&shsurf->view->geometry.transformation_list, |
Philip Withnall | becb77e | 2013-11-25 18:01:30 +0000 | [diff] [blame] | 2613 | &shsurf->rotation.transform.link); |
Alex Wu | 7bcb8bd | 2012-04-27 09:07:24 +0800 | [diff] [blame] | 2614 | shsurf->saved_rotation_valid = false; |
| 2615 | } |
Rafal Mielniczuk | 3e3862c | 2012-10-07 20:25:36 +0200 | [diff] [blame] | 2616 | |
Philip Withnall | e1d75ae | 2013-11-25 18:01:41 +0000 | [diff] [blame] | 2617 | /* Layer is updated in set_surface_type(). */ |
Alex Wu | 4539b08 | 2012-03-01 12:57:46 +0800 | [diff] [blame] | 2618 | } |
| 2619 | |
Rafal Mielniczuk | fffdcdd | 2013-03-11 19:26:54 +0100 | [diff] [blame] | 2620 | static void |
Philip Withnall | becb77e | 2013-11-25 18:01:30 +0000 | [diff] [blame] | 2621 | shell_surface_set_fullscreen(struct wl_client *client, |
| 2622 | struct wl_resource *resource, |
| 2623 | uint32_t method, |
| 2624 | uint32_t framerate, |
| 2625 | struct wl_resource *output_resource) |
| 2626 | { |
| 2627 | struct shell_surface *shsurf = wl_resource_get_user_data(resource); |
| 2628 | struct weston_output *output; |
| 2629 | |
| 2630 | if (output_resource) |
| 2631 | output = wl_resource_get_user_data(output_resource); |
| 2632 | else |
| 2633 | output = NULL; |
| 2634 | |
Rafael Antognolli | 4b99a40 | 2013-12-03 15:35:44 -0200 | [diff] [blame] | 2635 | shell_surface_set_parent(shsurf, NULL); |
| 2636 | |
Rafael Antognolli | 03b1659 | 2013-12-03 15:35:42 -0200 | [diff] [blame] | 2637 | surface_clear_next_states(shsurf); |
Jasper St. Pierre | 8c6aa45 | 2014-02-08 18:29:49 -0500 | [diff] [blame] | 2638 | shsurf->next_state.fullscreen = true; |
| 2639 | shsurf->state_changed = true; |
Jasper St. Pierre | 6458ec3 | 2014-04-11 16:00:31 -0700 | [diff] [blame] | 2640 | set_fullscreen(shsurf, method, framerate, output); |
Philip Withnall | becb77e | 2013-11-25 18:01:30 +0000 | [diff] [blame] | 2641 | } |
| 2642 | |
| 2643 | static void |
| 2644 | set_popup(struct shell_surface *shsurf, |
| 2645 | struct weston_surface *parent, |
| 2646 | struct weston_seat *seat, |
| 2647 | uint32_t serial, |
| 2648 | int32_t x, |
| 2649 | int32_t y) |
| 2650 | { |
Philip Withnall | dc4332f | 2013-11-25 18:01:38 +0000 | [diff] [blame] | 2651 | assert(parent != NULL); |
| 2652 | |
Philip Withnall | becb77e | 2013-11-25 18:01:30 +0000 | [diff] [blame] | 2653 | shsurf->popup.shseat = get_shell_seat(seat); |
| 2654 | shsurf->popup.serial = serial; |
| 2655 | shsurf->popup.x = x; |
| 2656 | shsurf->popup.y = y; |
Philip Withnall | dc4332f | 2013-11-25 18:01:38 +0000 | [diff] [blame] | 2657 | |
Pekka Paalanen | b502654 | 2014-11-12 15:09:24 +0200 | [diff] [blame] | 2658 | set_type(shsurf, SHELL_SURFACE_POPUP); |
Philip Withnall | becb77e | 2013-11-25 18:01:30 +0000 | [diff] [blame] | 2659 | } |
| 2660 | |
| 2661 | static void |
| 2662 | shell_surface_set_popup(struct wl_client *client, |
| 2663 | struct wl_resource *resource, |
| 2664 | struct wl_resource *seat_resource, |
| 2665 | uint32_t serial, |
| 2666 | struct wl_resource *parent_resource, |
| 2667 | int32_t x, int32_t y, uint32_t flags) |
| 2668 | { |
| 2669 | struct shell_surface *shsurf = wl_resource_get_user_data(resource); |
Rafael Antognolli | 4b99a40 | 2013-12-03 15:35:44 -0200 | [diff] [blame] | 2670 | struct weston_surface *parent = |
| 2671 | wl_resource_get_user_data(parent_resource); |
| 2672 | |
| 2673 | shell_surface_set_parent(shsurf, parent); |
Philip Withnall | becb77e | 2013-11-25 18:01:30 +0000 | [diff] [blame] | 2674 | |
Rafael Antognolli | 03b1659 | 2013-12-03 15:35:42 -0200 | [diff] [blame] | 2675 | surface_clear_next_states(shsurf); |
Philip Withnall | becb77e | 2013-11-25 18:01:30 +0000 | [diff] [blame] | 2676 | set_popup(shsurf, |
Rafael Antognolli | 4b99a40 | 2013-12-03 15:35:44 -0200 | [diff] [blame] | 2677 | parent, |
Philip Withnall | becb77e | 2013-11-25 18:01:30 +0000 | [diff] [blame] | 2678 | wl_resource_get_user_data(seat_resource), |
| 2679 | serial, x, y); |
| 2680 | } |
| 2681 | |
| 2682 | static void |
Philip Withnall | becb77e | 2013-11-25 18:01:30 +0000 | [diff] [blame] | 2683 | unset_maximized(struct shell_surface *shsurf) |
Rafal Mielniczuk | fffdcdd | 2013-03-11 19:26:54 +0100 | [diff] [blame] | 2684 | { |
Rafal Mielniczuk | fffdcdd | 2013-03-11 19:26:54 +0100 | [diff] [blame] | 2685 | /* undo all maximized things here */ |
| 2686 | shsurf->output = get_default_output(shsurf->surface->compositor); |
Zhang, Xiong Y | 3123693 | 2013-12-13 22:10:57 +0200 | [diff] [blame] | 2687 | |
| 2688 | if (shsurf->saved_position_valid) |
| 2689 | weston_view_set_position(shsurf->view, |
| 2690 | shsurf->saved_x, shsurf->saved_y); |
| 2691 | else |
| 2692 | weston_view_set_initial_position(shsurf->view, shsurf->shell); |
Rafal Mielniczuk | fffdcdd | 2013-03-11 19:26:54 +0100 | [diff] [blame] | 2693 | |
| 2694 | if (shsurf->saved_rotation_valid) { |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 2695 | wl_list_insert(&shsurf->view->geometry.transformation_list, |
| 2696 | &shsurf->rotation.transform.link); |
Rafal Mielniczuk | fffdcdd | 2013-03-11 19:26:54 +0100 | [diff] [blame] | 2697 | shsurf->saved_rotation_valid = false; |
| 2698 | } |
| 2699 | |
Philip Withnall | e1d75ae | 2013-11-25 18:01:41 +0000 | [diff] [blame] | 2700 | /* Layer is updated in set_surface_type(). */ |
Rafal Mielniczuk | fffdcdd | 2013-03-11 19:26:54 +0100 | [diff] [blame] | 2701 | } |
| 2702 | |
Philip Withnall | becb77e | 2013-11-25 18:01:30 +0000 | [diff] [blame] | 2703 | static void |
Manuel Bachmann | dc1c3e4 | 2015-02-16 11:52:13 +0100 | [diff] [blame] | 2704 | set_minimized(struct weston_surface *surface) |
Manuel Bachmann | 50c87db | 2014-02-26 15:52:13 +0100 | [diff] [blame] | 2705 | { |
| 2706 | struct shell_surface *shsurf; |
| 2707 | struct workspace *current_ws; |
| 2708 | struct weston_seat *seat; |
| 2709 | struct weston_surface *focus; |
| 2710 | struct weston_view *view; |
| 2711 | |
| 2712 | view = get_default_view(surface); |
| 2713 | if (!view) |
| 2714 | return; |
| 2715 | |
| 2716 | assert(weston_surface_get_main_surface(view->surface) == view->surface); |
| 2717 | |
| 2718 | shsurf = get_shell_surface(surface); |
| 2719 | current_ws = get_current_workspace(shsurf->shell); |
| 2720 | |
Giulio Camuffo | 412e6a5 | 2014-07-09 22:12:56 +0300 | [diff] [blame] | 2721 | weston_layer_entry_remove(&view->layer_link); |
Manuel Bachmann | dc1c3e4 | 2015-02-16 11:52:13 +0100 | [diff] [blame] | 2722 | 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] | 2723 | |
Manuel Bachmann | dc1c3e4 | 2015-02-16 11:52:13 +0100 | [diff] [blame] | 2724 | drop_focus_state(shsurf->shell, current_ws, view->surface); |
| 2725 | wl_list_for_each(seat, &shsurf->shell->compositor->seat_list, link) { |
Derek Foreman | 1281a36 | 2015-07-31 16:55:32 -0500 | [diff] [blame] | 2726 | struct weston_keyboard *keyboard = |
| 2727 | weston_seat_get_keyboard(seat); |
| 2728 | |
| 2729 | if (!keyboard) |
Manuel Bachmann | dc1c3e4 | 2015-02-16 11:52:13 +0100 | [diff] [blame] | 2730 | continue; |
Derek Foreman | 1281a36 | 2015-07-31 16:55:32 -0500 | [diff] [blame] | 2731 | focus = weston_surface_get_main_surface(keyboard->focus); |
Manuel Bachmann | dc1c3e4 | 2015-02-16 11:52:13 +0100 | [diff] [blame] | 2732 | if (focus == view->surface) |
Derek Foreman | 1281a36 | 2015-07-31 16:55:32 -0500 | [diff] [blame] | 2733 | weston_keyboard_set_focus(keyboard, NULL); |
Manuel Bachmann | 50c87db | 2014-02-26 15:52:13 +0100 | [diff] [blame] | 2734 | } |
| 2735 | |
| 2736 | shell_surface_update_child_surface_layers(shsurf); |
Manuel Bachmann | 50c87db | 2014-02-26 15:52:13 +0100 | [diff] [blame] | 2737 | weston_view_damage_below(view); |
| 2738 | } |
| 2739 | |
| 2740 | static void |
Philip Withnall | becb77e | 2013-11-25 18:01:30 +0000 | [diff] [blame] | 2741 | shell_surface_set_maximized(struct wl_client *client, |
| 2742 | struct wl_resource *resource, |
| 2743 | struct wl_resource *output_resource) |
| 2744 | { |
| 2745 | struct shell_surface *shsurf = wl_resource_get_user_data(resource); |
| 2746 | struct weston_output *output; |
| 2747 | |
Jasper St. Pierre | 9aa8ce6 | 2014-04-11 16:18:54 -0700 | [diff] [blame] | 2748 | surface_clear_next_states(shsurf); |
| 2749 | shsurf->next_state.maximized = true; |
| 2750 | shsurf->state_changed = true; |
| 2751 | |
Pekka Paalanen | b502654 | 2014-11-12 15:09:24 +0200 | [diff] [blame] | 2752 | set_type(shsurf, SHELL_SURFACE_TOPLEVEL); |
Jasper St. Pierre | 9aa8ce6 | 2014-04-11 16:18:54 -0700 | [diff] [blame] | 2753 | shell_surface_set_parent(shsurf, NULL); |
| 2754 | |
Philip Withnall | becb77e | 2013-11-25 18:01:30 +0000 | [diff] [blame] | 2755 | if (output_resource) |
| 2756 | output = wl_resource_get_user_data(output_resource); |
| 2757 | else |
| 2758 | output = NULL; |
| 2759 | |
Jasper St. Pierre | 9aa8ce6 | 2014-04-11 16:18:54 -0700 | [diff] [blame] | 2760 | shell_surface_set_output(shsurf, output); |
Rafael Antognolli | 4b99a40 | 2013-12-03 15:35:44 -0200 | [diff] [blame] | 2761 | |
Jasper St. Pierre | 9aa8ce6 | 2014-04-11 16:18:54 -0700 | [diff] [blame] | 2762 | send_configure_for_surface(shsurf); |
Philip Withnall | becb77e | 2013-11-25 18:01:30 +0000 | [diff] [blame] | 2763 | } |
| 2764 | |
Philip Withnall | e1d75ae | 2013-11-25 18:01:41 +0000 | [diff] [blame] | 2765 | /* This is only ever called from set_surface_type(), so there’s no need to |
| 2766 | * update layer_links here, since they’ll be updated when we return. */ |
Pekka Paalanen | 9826223 | 2011-12-01 10:42:22 +0200 | [diff] [blame] | 2767 | static int |
Philip Withnall | becb77e | 2013-11-25 18:01:30 +0000 | [diff] [blame] | 2768 | reset_surface_type(struct shell_surface *surface) |
Pekka Paalanen | 9826223 | 2011-12-01 10:42:22 +0200 | [diff] [blame] | 2769 | { |
Rafael Antognolli | 03b1659 | 2013-12-03 15:35:42 -0200 | [diff] [blame] | 2770 | if (surface->state.fullscreen) |
Philip Withnall | becb77e | 2013-11-25 18:01:30 +0000 | [diff] [blame] | 2771 | unset_fullscreen(surface); |
Rafael Antognolli | 03b1659 | 2013-12-03 15:35:42 -0200 | [diff] [blame] | 2772 | if (surface->state.maximized) |
Philip Withnall | becb77e | 2013-11-25 18:01:30 +0000 | [diff] [blame] | 2773 | unset_maximized(surface); |
Pekka Paalanen | 9826223 | 2011-12-01 10:42:22 +0200 | [diff] [blame] | 2774 | |
Pekka Paalanen | 9826223 | 2011-12-01 10:42:22 +0200 | [diff] [blame] | 2775 | return 0; |
| 2776 | } |
| 2777 | |
Kristian Høgsberg | 4cca349 | 2011-01-18 07:53:49 -0500 | [diff] [blame] | 2778 | static void |
Rafael Antognolli | 03b1659 | 2013-12-03 15:35:42 -0200 | [diff] [blame] | 2779 | set_full_output(struct shell_surface *shsurf) |
| 2780 | { |
| 2781 | shsurf->saved_x = shsurf->view->geometry.x; |
| 2782 | shsurf->saved_y = shsurf->view->geometry.y; |
Rafael Antognolli | 3c4e3f7 | 2013-12-03 15:35:46 -0200 | [diff] [blame] | 2783 | shsurf->saved_width = shsurf->surface->width; |
| 2784 | shsurf->saved_height = shsurf->surface->height; |
| 2785 | shsurf->saved_size_valid = true; |
Rafael Antognolli | 03b1659 | 2013-12-03 15:35:42 -0200 | [diff] [blame] | 2786 | shsurf->saved_position_valid = true; |
| 2787 | |
| 2788 | if (!wl_list_empty(&shsurf->rotation.transform.link)) { |
| 2789 | wl_list_remove(&shsurf->rotation.transform.link); |
| 2790 | wl_list_init(&shsurf->rotation.transform.link); |
| 2791 | weston_view_geometry_dirty(shsurf->view); |
| 2792 | shsurf->saved_rotation_valid = true; |
| 2793 | } |
| 2794 | } |
| 2795 | |
| 2796 | static void |
Kristian Høgsberg | 7f366e7 | 2012-04-27 17:20:01 -0400 | [diff] [blame] | 2797 | set_surface_type(struct shell_surface *shsurf) |
| 2798 | { |
Kristian Høgsberg | 8150b19 | 2012-06-27 10:22:58 -0400 | [diff] [blame] | 2799 | struct weston_surface *pes = shsurf->parent; |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 2800 | struct weston_view *pev = get_default_view(pes); |
Kristian Høgsberg | 7f366e7 | 2012-04-27 17:20:01 -0400 | [diff] [blame] | 2801 | |
Philip Withnall | becb77e | 2013-11-25 18:01:30 +0000 | [diff] [blame] | 2802 | reset_surface_type(shsurf); |
Kristian Høgsberg | 7f366e7 | 2012-04-27 17:20:01 -0400 | [diff] [blame] | 2803 | |
Rafael Antognolli | 03b1659 | 2013-12-03 15:35:42 -0200 | [diff] [blame] | 2804 | shsurf->state = shsurf->next_state; |
Rafael Antognolli | 03b1659 | 2013-12-03 15:35:42 -0200 | [diff] [blame] | 2805 | shsurf->state_changed = false; |
Kristian Høgsberg | 7f366e7 | 2012-04-27 17:20:01 -0400 | [diff] [blame] | 2806 | |
| 2807 | switch (shsurf->type) { |
| 2808 | case SHELL_SURFACE_TOPLEVEL: |
Rafael Antognolli | ed207b4 | 2013-12-03 15:35:43 -0200 | [diff] [blame] | 2809 | if (shsurf->state.maximized || shsurf->state.fullscreen) { |
Rafael Antognolli | 03b1659 | 2013-12-03 15:35:42 -0200 | [diff] [blame] | 2810 | set_full_output(shsurf); |
Rafael Antognolli | ed207b4 | 2013-12-03 15:35:43 -0200 | [diff] [blame] | 2811 | } else if (shsurf->state.relative && pev) { |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 2812 | weston_view_set_position(shsurf->view, |
| 2813 | pev->geometry.x + shsurf->transient.x, |
| 2814 | pev->geometry.y + shsurf->transient.y); |
Rafael Antognolli | ed207b4 | 2013-12-03 15:35:43 -0200 | [diff] [blame] | 2815 | } |
Rafael Antognolli | 44a3162 | 2013-12-04 18:37:16 -0200 | [diff] [blame] | 2816 | break; |
Kristian Høgsberg | 7f366e7 | 2012-04-27 17:20:01 -0400 | [diff] [blame] | 2817 | |
Tiago Vignatti | fb2adba | 2013-06-12 15:43:21 -0300 | [diff] [blame] | 2818 | case SHELL_SURFACE_XWAYLAND: |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 2819 | weston_view_set_position(shsurf->view, shsurf->transient.x, |
| 2820 | shsurf->transient.y); |
Tiago Vignatti | fb2adba | 2013-06-12 15:43:21 -0300 | [diff] [blame] | 2821 | break; |
| 2822 | |
Philip Withnall | 0f640e2 | 2013-11-25 18:01:31 +0000 | [diff] [blame] | 2823 | case SHELL_SURFACE_POPUP: |
| 2824 | case SHELL_SURFACE_NONE: |
Kristian Høgsberg | 7f366e7 | 2012-04-27 17:20:01 -0400 | [diff] [blame] | 2825 | default: |
| 2826 | break; |
| 2827 | } |
Philip Withnall | e1d75ae | 2013-11-25 18:01:41 +0000 | [diff] [blame] | 2828 | |
| 2829 | /* Update the surface’s layer. */ |
| 2830 | shell_surface_update_layer(shsurf); |
Kristian Høgsberg | 7f366e7 | 2012-04-27 17:20:01 -0400 | [diff] [blame] | 2831 | } |
| 2832 | |
Tiago Vignatti | be14326 | 2012-04-16 17:31:41 +0300 | [diff] [blame] | 2833 | static struct desktop_shell * |
Juan Zhao | 96879df | 2012-02-07 08:45:41 +0800 | [diff] [blame] | 2834 | shell_surface_get_shell(struct shell_surface *shsurf) |
Pekka Paalanen | af0e34c | 2011-12-02 10:59:17 +0200 | [diff] [blame] | 2835 | { |
Kristian Høgsberg | 02e79dc | 2012-04-12 09:55:26 -0400 | [diff] [blame] | 2836 | return shsurf->shell; |
Juan Zhao | 96879df | 2012-02-07 08:45:41 +0800 | [diff] [blame] | 2837 | } |
| 2838 | |
Pekka Paalanen | 8274d90 | 2014-08-06 19:36:51 +0300 | [diff] [blame] | 2839 | static int |
| 2840 | black_surface_get_label(struct weston_surface *surface, char *buf, size_t len) |
| 2841 | { |
| 2842 | struct weston_surface *fs_surface = surface->configure_private; |
| 2843 | int n; |
| 2844 | int rem; |
| 2845 | int ret; |
| 2846 | |
| 2847 | n = snprintf(buf, len, "black background surface for "); |
| 2848 | if (n < 0) |
| 2849 | return n; |
| 2850 | |
| 2851 | rem = (int)len - n; |
| 2852 | if (rem < 0) |
| 2853 | rem = 0; |
| 2854 | |
| 2855 | if (fs_surface->get_label) |
| 2856 | ret = fs_surface->get_label(fs_surface, buf + n, rem); |
| 2857 | else |
| 2858 | ret = snprintf(buf + n, rem, "<unknown>"); |
| 2859 | |
| 2860 | if (ret < 0) |
| 2861 | return n; |
| 2862 | |
| 2863 | return n + ret; |
| 2864 | } |
| 2865 | |
Alex Wu | 2185843 | 2012-04-01 20:13:08 +0800 | [diff] [blame] | 2866 | static void |
Jason Ekstrand | 918f2dd | 2013-12-02 21:01:53 -0600 | [diff] [blame] | 2867 | 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] | 2868 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 2869 | static struct weston_view * |
Alex Wu | 4539b08 | 2012-03-01 12:57:46 +0800 | [diff] [blame] | 2870 | create_black_surface(struct weston_compositor *ec, |
Alex Wu | 2185843 | 2012-04-01 20:13:08 +0800 | [diff] [blame] | 2871 | struct weston_surface *fs_surface, |
John Kåre Alsaker | 490d02a | 2012-09-30 02:57:21 +0200 | [diff] [blame] | 2872 | float x, float y, int w, int h) |
Alex Wu | 4539b08 | 2012-03-01 12:57:46 +0800 | [diff] [blame] | 2873 | { |
| 2874 | struct weston_surface *surface = NULL; |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 2875 | struct weston_view *view; |
Alex Wu | 4539b08 | 2012-03-01 12:57:46 +0800 | [diff] [blame] | 2876 | |
| 2877 | surface = weston_surface_create(ec); |
| 2878 | if (surface == NULL) { |
Martin Minarik | 6d11836 | 2012-06-07 18:01:59 +0200 | [diff] [blame] | 2879 | weston_log("no memory\n"); |
Alex Wu | 4539b08 | 2012-03-01 12:57:46 +0800 | [diff] [blame] | 2880 | return NULL; |
| 2881 | } |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 2882 | view = weston_view_create(surface); |
| 2883 | if (surface == NULL) { |
| 2884 | weston_log("no memory\n"); |
| 2885 | weston_surface_destroy(surface); |
| 2886 | return NULL; |
| 2887 | } |
Alex Wu | 4539b08 | 2012-03-01 12:57:46 +0800 | [diff] [blame] | 2888 | |
Alex Wu | 2185843 | 2012-04-01 20:13:08 +0800 | [diff] [blame] | 2889 | surface->configure = black_surface_configure; |
Giulio Camuffo | 7fe01b1 | 2013-03-28 18:02:42 +0100 | [diff] [blame] | 2890 | surface->configure_private = fs_surface; |
Pekka Paalanen | 8274d90 | 2014-08-06 19:36:51 +0300 | [diff] [blame] | 2891 | weston_surface_set_label_func(surface, black_surface_get_label); |
Alex Wu | 4539b08 | 2012-03-01 12:57:46 +0800 | [diff] [blame] | 2892 | weston_surface_set_color(surface, 0.0, 0.0, 0.0, 1); |
Pekka Paalanen | 71f6f3b | 2012-10-10 12:49:26 +0300 | [diff] [blame] | 2893 | pixman_region32_fini(&surface->opaque); |
Kristian Høgsberg | 61f00f5 | 2012-08-03 16:31:36 -0400 | [diff] [blame] | 2894 | pixman_region32_init_rect(&surface->opaque, 0, 0, w, h); |
Jonas Ådahl | 33619a4 | 2013-01-15 21:25:55 +0100 | [diff] [blame] | 2895 | pixman_region32_fini(&surface->input); |
| 2896 | pixman_region32_init_rect(&surface->input, 0, 0, w, h); |
Jason Ekstrand | 918f2dd | 2013-12-02 21:01:53 -0600 | [diff] [blame] | 2897 | |
Jason Ekstrand | 6228ee2 | 2014-01-01 15:58:57 -0600 | [diff] [blame] | 2898 | weston_surface_set_size(surface, w, h); |
Jason Ekstrand | 918f2dd | 2013-12-02 21:01:53 -0600 | [diff] [blame] | 2899 | weston_view_set_position(view, x, y); |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 2900 | |
| 2901 | return view; |
Alex Wu | 4539b08 | 2012-03-01 12:57:46 +0800 | [diff] [blame] | 2902 | } |
| 2903 | |
Philip Withnall | ed8f1a9 | 2013-11-25 18:01:43 +0000 | [diff] [blame] | 2904 | static void |
| 2905 | shell_ensure_fullscreen_black_view(struct shell_surface *shsurf) |
| 2906 | { |
| 2907 | struct weston_output *output = shsurf->fullscreen_output; |
| 2908 | |
Rafael Antognolli | 03b1659 | 2013-12-03 15:35:42 -0200 | [diff] [blame] | 2909 | assert(shsurf->state.fullscreen); |
Philip Withnall | ed8f1a9 | 2013-11-25 18:01:43 +0000 | [diff] [blame] | 2910 | |
| 2911 | if (!shsurf->fullscreen.black_view) |
| 2912 | shsurf->fullscreen.black_view = |
| 2913 | create_black_surface(shsurf->surface->compositor, |
| 2914 | shsurf->surface, |
| 2915 | output->x, output->y, |
| 2916 | output->width, |
| 2917 | output->height); |
| 2918 | |
| 2919 | weston_view_geometry_dirty(shsurf->fullscreen.black_view); |
Giulio Camuffo | 412e6a5 | 2014-07-09 22:12:56 +0300 | [diff] [blame] | 2920 | weston_layer_entry_remove(&shsurf->fullscreen.black_view->layer_link); |
| 2921 | weston_layer_entry_insert(&shsurf->view->layer_link, |
| 2922 | &shsurf->fullscreen.black_view->layer_link); |
Philip Withnall | ed8f1a9 | 2013-11-25 18:01:43 +0000 | [diff] [blame] | 2923 | weston_view_geometry_dirty(shsurf->fullscreen.black_view); |
| 2924 | weston_surface_damage(shsurf->surface); |
Emilio Pozuelo Monfort | 9e7c759 | 2014-01-30 14:01:10 +0100 | [diff] [blame] | 2925 | |
| 2926 | shsurf->state.lowered = false; |
Philip Withnall | ed8f1a9 | 2013-11-25 18:01:43 +0000 | [diff] [blame] | 2927 | } |
| 2928 | |
Alex Wu | 4539b08 | 2012-03-01 12:57:46 +0800 | [diff] [blame] | 2929 | /* Create black surface and append it to the associated fullscreen surface. |
| 2930 | * Handle size dismatch and positioning according to the method. */ |
| 2931 | static void |
| 2932 | shell_configure_fullscreen(struct shell_surface *shsurf) |
| 2933 | { |
| 2934 | struct weston_output *output = shsurf->fullscreen_output; |
| 2935 | struct weston_surface *surface = shsurf->surface; |
| 2936 | struct weston_matrix *matrix; |
Kristian Høgsberg | 240dfeb | 2012-07-12 12:32:31 -0400 | [diff] [blame] | 2937 | float scale, output_aspect, surface_aspect, x, y; |
Giulio Camuffo | b836664 | 2013-04-25 13:57:46 +0300 | [diff] [blame] | 2938 | int32_t surf_x, surf_y, surf_width, surf_height; |
Alex Wu | 4539b08 | 2012-03-01 12:57:46 +0800 | [diff] [blame] | 2939 | |
Alexander Larsson | f82b6ca | 2013-05-28 16:23:39 +0200 | [diff] [blame] | 2940 | if (shsurf->fullscreen.type != WL_SHELL_SURFACE_FULLSCREEN_METHOD_DRIVER) |
| 2941 | restore_output_mode(output); |
| 2942 | |
Emilio Pozuelo Monfort | 9e7c759 | 2014-01-30 14:01:10 +0100 | [diff] [blame] | 2943 | /* Reverse the effect of lower_fullscreen_layer() */ |
Giulio Camuffo | 412e6a5 | 2014-07-09 22:12:56 +0300 | [diff] [blame] | 2944 | weston_layer_entry_remove(&shsurf->view->layer_link); |
| 2945 | 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] | 2946 | |
Philip Withnall | ed8f1a9 | 2013-11-25 18:01:43 +0000 | [diff] [blame] | 2947 | shell_ensure_fullscreen_black_view(shsurf); |
Alex Wu | 4539b08 | 2012-03-01 12:57:46 +0800 | [diff] [blame] | 2948 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 2949 | surface_subsurfaces_boundingbox(shsurf->surface, &surf_x, &surf_y, |
Giulio Camuffo | b836664 | 2013-04-25 13:57:46 +0300 | [diff] [blame] | 2950 | &surf_width, &surf_height); |
| 2951 | |
Alex Wu | 4539b08 | 2012-03-01 12:57:46 +0800 | [diff] [blame] | 2952 | switch (shsurf->fullscreen.type) { |
| 2953 | case WL_SHELL_SURFACE_FULLSCREEN_METHOD_DEFAULT: |
Pekka Paalanen | de685b8 | 2012-12-04 15:58:12 +0200 | [diff] [blame] | 2954 | if (surface->buffer_ref.buffer) |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 2955 | center_on_output(shsurf->view, shsurf->fullscreen_output); |
Alex Wu | 4539b08 | 2012-03-01 12:57:46 +0800 | [diff] [blame] | 2956 | break; |
| 2957 | case WL_SHELL_SURFACE_FULLSCREEN_METHOD_SCALE: |
Rob Bradford | 9f3dd15 | 2013-02-12 11:53:47 +0000 | [diff] [blame] | 2958 | /* 1:1 mapping between surface and output dimensions */ |
Giulio Camuffo | b836664 | 2013-04-25 13:57:46 +0300 | [diff] [blame] | 2959 | if (output->width == surf_width && |
| 2960 | output->height == surf_height) { |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 2961 | weston_view_set_position(shsurf->view, |
| 2962 | output->x - surf_x, |
| 2963 | output->y - surf_y); |
Rob Bradford | 9f3dd15 | 2013-02-12 11:53:47 +0000 | [diff] [blame] | 2964 | break; |
| 2965 | } |
| 2966 | |
Alex Wu | 4539b08 | 2012-03-01 12:57:46 +0800 | [diff] [blame] | 2967 | matrix = &shsurf->fullscreen.transform.matrix; |
| 2968 | weston_matrix_init(matrix); |
Kristian Høgsberg | 240dfeb | 2012-07-12 12:32:31 -0400 | [diff] [blame] | 2969 | |
Scott Moreau | 1bad5db | 2012-08-18 01:04:05 -0600 | [diff] [blame] | 2970 | output_aspect = (float) output->width / |
| 2971 | (float) output->height; |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 2972 | /* XXX: Use surf_width and surf_height here? */ |
| 2973 | surface_aspect = (float) surface->width / |
| 2974 | (float) surface->height; |
Kristian Høgsberg | 240dfeb | 2012-07-12 12:32:31 -0400 | [diff] [blame] | 2975 | if (output_aspect < surface_aspect) |
Scott Moreau | 1bad5db | 2012-08-18 01:04:05 -0600 | [diff] [blame] | 2976 | scale = (float) output->width / |
Giulio Camuffo | b836664 | 2013-04-25 13:57:46 +0300 | [diff] [blame] | 2977 | (float) surf_width; |
Kristian Høgsberg | 240dfeb | 2012-07-12 12:32:31 -0400 | [diff] [blame] | 2978 | else |
Scott Moreau | 1bad5db | 2012-08-18 01:04:05 -0600 | [diff] [blame] | 2979 | scale = (float) output->height / |
Giulio Camuffo | b836664 | 2013-04-25 13:57:46 +0300 | [diff] [blame] | 2980 | (float) surf_height; |
Kristian Høgsberg | 240dfeb | 2012-07-12 12:32:31 -0400 | [diff] [blame] | 2981 | |
Alex Wu | 4539b08 | 2012-03-01 12:57:46 +0800 | [diff] [blame] | 2982 | weston_matrix_scale(matrix, scale, scale, 1); |
| 2983 | wl_list_remove(&shsurf->fullscreen.transform.link); |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 2984 | wl_list_insert(&shsurf->view->geometry.transformation_list, |
Alex Wu | 4539b08 | 2012-03-01 12:57:46 +0800 | [diff] [blame] | 2985 | &shsurf->fullscreen.transform.link); |
Giulio Camuffo | b836664 | 2013-04-25 13:57:46 +0300 | [diff] [blame] | 2986 | x = output->x + (output->width - surf_width * scale) / 2 - surf_x; |
| 2987 | y = output->y + (output->height - surf_height * scale) / 2 - surf_y; |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 2988 | weston_view_set_position(shsurf->view, x, y); |
Kristian Høgsberg | 240dfeb | 2012-07-12 12:32:31 -0400 | [diff] [blame] | 2989 | |
Alex Wu | 4539b08 | 2012-03-01 12:57:46 +0800 | [diff] [blame] | 2990 | break; |
| 2991 | case WL_SHELL_SURFACE_FULLSCREEN_METHOD_DRIVER: |
Alex Wu | bd3354b | 2012-04-17 17:20:49 +0800 | [diff] [blame] | 2992 | if (shell_surface_is_top_fullscreen(shsurf)) { |
Quentin Glidic | c0d79ce | 2013-01-29 14:16:13 +0100 | [diff] [blame] | 2993 | struct weston_mode mode = {0, |
Pekka Paalanen | 952b6c8 | 2014-03-14 14:38:15 +0200 | [diff] [blame] | 2994 | surf_width * surface->buffer_viewport.buffer.scale, |
| 2995 | surf_height * surface->buffer_viewport.buffer.scale, |
Alex Wu | bd3354b | 2012-04-17 17:20:49 +0800 | [diff] [blame] | 2996 | shsurf->fullscreen.framerate}; |
| 2997 | |
Derek Foreman | 6ae7bc9 | 2014-11-04 10:47:33 -0600 | [diff] [blame] | 2998 | if (weston_output_mode_switch_to_temporary(output, &mode, |
| 2999 | surface->buffer_viewport.buffer.scale) == 0) { |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 3000 | weston_view_set_position(shsurf->view, |
| 3001 | output->x - surf_x, |
| 3002 | output->y - surf_y); |
Jason Ekstrand | 918f2dd | 2013-12-02 21:01:53 -0600 | [diff] [blame] | 3003 | shsurf->fullscreen.black_view->surface->width = output->width; |
| 3004 | shsurf->fullscreen.black_view->surface->height = output->height; |
| 3005 | weston_view_set_position(shsurf->fullscreen.black_view, |
| 3006 | output->x - surf_x, |
| 3007 | output->y - surf_y); |
Alex Wu | bd3354b | 2012-04-17 17:20:49 +0800 | [diff] [blame] | 3008 | break; |
Alexander Larsson | d622ed3 | 2013-05-28 16:23:40 +0200 | [diff] [blame] | 3009 | } else { |
Mario Kleiner | 492c12f | 2015-06-21 21:25:12 +0200 | [diff] [blame] | 3010 | weston_log("shell: Can't switch to temporary mode.\n"); |
Alexander Larsson | f82b6ca | 2013-05-28 16:23:39 +0200 | [diff] [blame] | 3011 | restore_output_mode(output); |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 3012 | center_on_output(shsurf->view, output); |
Alexander Larsson | d622ed3 | 2013-05-28 16:23:40 +0200 | [diff] [blame] | 3013 | } |
Alex Wu | bd3354b | 2012-04-17 17:20:49 +0800 | [diff] [blame] | 3014 | } |
Alex Wu | 4539b08 | 2012-03-01 12:57:46 +0800 | [diff] [blame] | 3015 | break; |
| 3016 | case WL_SHELL_SURFACE_FULLSCREEN_METHOD_FILL: |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 3017 | center_on_output(shsurf->view, output); |
Alex Wu | 4539b08 | 2012-03-01 12:57:46 +0800 | [diff] [blame] | 3018 | break; |
| 3019 | default: |
| 3020 | break; |
| 3021 | } |
| 3022 | } |
| 3023 | |
Alex Wu | 4539b08 | 2012-03-01 12:57:46 +0800 | [diff] [blame] | 3024 | static void |
| 3025 | shell_map_fullscreen(struct shell_surface *shsurf) |
| 3026 | { |
Alex Wu | bd3354b | 2012-04-17 17:20:49 +0800 | [diff] [blame] | 3027 | shell_configure_fullscreen(shsurf); |
Alex Wu | 4539b08 | 2012-03-01 12:57:46 +0800 | [diff] [blame] | 3028 | } |
| 3029 | |
Kristian Høgsberg | 7a5c979 | 2011-06-18 06:12:54 -0400 | [diff] [blame] | 3030 | static void |
Tiago Vignatti | fb2adba | 2013-06-12 15:43:21 -0300 | [diff] [blame] | 3031 | set_xwayland(struct shell_surface *shsurf, int x, int y, uint32_t flags) |
| 3032 | { |
| 3033 | /* XXX: using the same fields for transient type */ |
Rafael Antognolli | 03b1659 | 2013-12-03 15:35:42 -0200 | [diff] [blame] | 3034 | surface_clear_next_states(shsurf); |
Tiago Vignatti | fb2adba | 2013-06-12 15:43:21 -0300 | [diff] [blame] | 3035 | shsurf->transient.x = x; |
| 3036 | shsurf->transient.y = y; |
| 3037 | shsurf->transient.flags = flags; |
Philip Withnall | dc4332f | 2013-11-25 18:01:38 +0000 | [diff] [blame] | 3038 | |
| 3039 | shell_surface_set_parent(shsurf, NULL); |
| 3040 | |
Pekka Paalanen | b502654 | 2014-11-12 15:09:24 +0200 | [diff] [blame] | 3041 | set_type(shsurf, SHELL_SURFACE_XWAYLAND); |
Kristian Høgsberg | 8bc525c | 2014-01-01 22:34:49 -0800 | [diff] [blame] | 3042 | shsurf->state_changed = true; |
Tiago Vignatti | fb2adba | 2013-06-12 15:43:21 -0300 | [diff] [blame] | 3043 | } |
| 3044 | |
Kristian Høgsberg | 4779241 | 2014-05-04 13:47:06 -0700 | [diff] [blame] | 3045 | static void |
| 3046 | shell_interface_set_fullscreen(struct shell_surface *shsurf, |
| 3047 | uint32_t method, |
| 3048 | uint32_t framerate, |
| 3049 | struct weston_output *output) |
| 3050 | { |
| 3051 | surface_clear_next_states(shsurf); |
Kristian Høgsberg | 4779241 | 2014-05-04 13:47:06 -0700 | [diff] [blame] | 3052 | shsurf->next_state.fullscreen = true; |
| 3053 | shsurf->state_changed = true; |
Marek Chalupa | e9fe467 | 2014-10-29 13:44:44 +0100 | [diff] [blame] | 3054 | |
| 3055 | set_fullscreen(shsurf, method, framerate, output); |
Kristian Høgsberg | 4779241 | 2014-05-04 13:47:06 -0700 | [diff] [blame] | 3056 | } |
| 3057 | |
Giulio Camuffo | 6b4b241 | 2015-01-29 19:06:49 +0200 | [diff] [blame] | 3058 | static struct weston_output * |
| 3059 | get_focused_output(struct weston_compositor *compositor) |
| 3060 | { |
| 3061 | struct weston_seat *seat; |
| 3062 | struct weston_output *output = NULL; |
| 3063 | |
| 3064 | wl_list_for_each(seat, &compositor->seat_list, link) { |
Derek Foreman | 1281a36 | 2015-07-31 16:55:32 -0500 | [diff] [blame] | 3065 | struct weston_touch *touch = weston_seat_get_touch(seat); |
| 3066 | struct weston_pointer *pointer = weston_seat_get_pointer(seat); |
| 3067 | struct weston_keyboard *keyboard = |
| 3068 | weston_seat_get_keyboard(seat); |
| 3069 | |
Giulio Camuffo | 6b4b241 | 2015-01-29 19:06:49 +0200 | [diff] [blame] | 3070 | /* Priority has touch focus, then pointer and |
| 3071 | * then keyboard focus. We should probably have |
| 3072 | * three for loops and check frist for touch, |
| 3073 | * then for pointer, etc. but unless somebody has some |
| 3074 | * objections, I think this is sufficient. */ |
Derek Foreman | 1281a36 | 2015-07-31 16:55:32 -0500 | [diff] [blame] | 3075 | if (touch && touch->focus) |
| 3076 | output = touch->focus->output; |
| 3077 | else if (pointer && pointer->focus) |
| 3078 | output = pointer->focus->output; |
| 3079 | else if (keyboard && keyboard->focus) |
| 3080 | output = keyboard->focus->output; |
Giulio Camuffo | 6b4b241 | 2015-01-29 19:06:49 +0200 | [diff] [blame] | 3081 | |
| 3082 | if (output) |
| 3083 | break; |
| 3084 | } |
| 3085 | |
| 3086 | return output; |
| 3087 | } |
| 3088 | |
| 3089 | static void |
| 3090 | shell_interface_set_maximized(struct shell_surface *shsurf) |
| 3091 | { |
| 3092 | struct weston_output *output; |
| 3093 | |
| 3094 | surface_clear_next_states(shsurf); |
| 3095 | shsurf->next_state.maximized = true; |
| 3096 | shsurf->state_changed = true; |
| 3097 | shsurf->type = SHELL_SURFACE_TOPLEVEL; |
| 3098 | |
| 3099 | if (!weston_surface_is_mapped(shsurf->surface)) |
| 3100 | output = get_focused_output(shsurf->surface->compositor); |
| 3101 | else |
| 3102 | output = shsurf->surface->output; |
| 3103 | |
| 3104 | shell_surface_set_output(shsurf, output); |
| 3105 | send_configure_for_surface(shsurf); |
| 3106 | } |
| 3107 | |
Kristian Høgsberg | ae356ae | 2014-04-29 16:03:54 -0700 | [diff] [blame] | 3108 | static int |
Derek Foreman | e4d6c83 | 2015-08-05 14:48:11 -0500 | [diff] [blame] | 3109 | shell_interface_move(struct shell_surface *shsurf, struct weston_pointer *pointer) |
Kristian Høgsberg | ae356ae | 2014-04-29 16:03:54 -0700 | [diff] [blame] | 3110 | { |
Derek Foreman | e4d6c83 | 2015-08-05 14:48:11 -0500 | [diff] [blame] | 3111 | return surface_move(shsurf, pointer, true); |
Kristian Høgsberg | ae356ae | 2014-04-29 16:03:54 -0700 | [diff] [blame] | 3112 | } |
| 3113 | |
Derek Foreman | 8fbebbd | 2015-07-15 13:00:40 -0500 | [diff] [blame] | 3114 | static int |
| 3115 | shell_interface_resize(struct shell_surface *shsurf, |
Derek Foreman | e4d6c83 | 2015-08-05 14:48:11 -0500 | [diff] [blame] | 3116 | struct weston_pointer *pointer, |
Derek Foreman | 8fbebbd | 2015-07-15 13:00:40 -0500 | [diff] [blame] | 3117 | uint32_t edges) |
| 3118 | { |
Derek Foreman | e4d6c83 | 2015-08-05 14:48:11 -0500 | [diff] [blame] | 3119 | return surface_resize(shsurf, pointer, edges); |
Derek Foreman | 8fbebbd | 2015-07-15 13:00:40 -0500 | [diff] [blame] | 3120 | } |
| 3121 | |
Kristian Høgsberg | 02bbabb | 2013-05-06 22:15:05 -0400 | [diff] [blame] | 3122 | static const struct weston_pointer_grab_interface popup_grab_interface; |
Giulio Camuffo | 5085a75 | 2013-03-25 21:42:45 +0100 | [diff] [blame] | 3123 | |
| 3124 | static void |
| 3125 | destroy_shell_seat(struct wl_listener *listener, void *data) |
| 3126 | { |
| 3127 | struct shell_seat *shseat = |
| 3128 | container_of(listener, |
| 3129 | struct shell_seat, seat_destroy_listener); |
Jonas Ådahl | c2b1011 | 2015-02-13 14:01:53 +0800 | [diff] [blame] | 3130 | struct shell_surface *shsurf, *next; |
Giulio Camuffo | 5085a75 | 2013-03-25 21:42:45 +0100 | [diff] [blame] | 3131 | |
| 3132 | if (shseat->popup_grab.grab.interface == &popup_grab_interface) { |
Kristian Høgsberg | 02bbabb | 2013-05-06 22:15:05 -0400 | [diff] [blame] | 3133 | weston_pointer_end_grab(shseat->popup_grab.grab.pointer); |
Giulio Camuffo | 5085a75 | 2013-03-25 21:42:45 +0100 | [diff] [blame] | 3134 | shseat->popup_grab.client = NULL; |
| 3135 | |
Jonas Ådahl | c2b1011 | 2015-02-13 14:01:53 +0800 | [diff] [blame] | 3136 | wl_list_for_each_safe(shsurf, next, |
| 3137 | &shseat->popup_grab.surfaces_list, |
| 3138 | popup.grab_link) { |
Giulio Camuffo | 5085a75 | 2013-03-25 21:42:45 +0100 | [diff] [blame] | 3139 | shsurf->popup.shseat = NULL; |
Jonas Ådahl | c2b1011 | 2015-02-13 14:01:53 +0800 | [diff] [blame] | 3140 | wl_list_init(&shsurf->popup.grab_link); |
Giulio Camuffo | 5085a75 | 2013-03-25 21:42:45 +0100 | [diff] [blame] | 3141 | } |
Giulio Camuffo | 5085a75 | 2013-03-25 21:42:45 +0100 | [diff] [blame] | 3142 | } |
| 3143 | |
| 3144 | wl_list_remove(&shseat->seat_destroy_listener.link); |
| 3145 | free(shseat); |
| 3146 | } |
| 3147 | |
Jason Ekstrand | 024177c | 2014-04-21 19:42:58 -0500 | [diff] [blame] | 3148 | static void |
| 3149 | shell_seat_caps_changed(struct wl_listener *listener, void *data) |
| 3150 | { |
Derek Foreman | 1281a36 | 2015-07-31 16:55:32 -0500 | [diff] [blame] | 3151 | struct weston_keyboard *keyboard; |
| 3152 | struct weston_pointer *pointer; |
Jason Ekstrand | 024177c | 2014-04-21 19:42:58 -0500 | [diff] [blame] | 3153 | struct shell_seat *seat; |
| 3154 | |
| 3155 | seat = container_of(listener, struct shell_seat, caps_changed_listener); |
Derek Foreman | 1281a36 | 2015-07-31 16:55:32 -0500 | [diff] [blame] | 3156 | keyboard = weston_seat_get_keyboard(seat->seat); |
| 3157 | pointer = weston_seat_get_pointer(seat->seat); |
Jason Ekstrand | 024177c | 2014-04-21 19:42:58 -0500 | [diff] [blame] | 3158 | |
Derek Foreman | 1281a36 | 2015-07-31 16:55:32 -0500 | [diff] [blame] | 3159 | if (keyboard && |
Jason Ekstrand | 024177c | 2014-04-21 19:42:58 -0500 | [diff] [blame] | 3160 | wl_list_empty(&seat->keyboard_focus_listener.link)) { |
Derek Foreman | 1281a36 | 2015-07-31 16:55:32 -0500 | [diff] [blame] | 3161 | wl_signal_add(&keyboard->focus_signal, |
Jason Ekstrand | 024177c | 2014-04-21 19:42:58 -0500 | [diff] [blame] | 3162 | &seat->keyboard_focus_listener); |
Derek Foreman | 1281a36 | 2015-07-31 16:55:32 -0500 | [diff] [blame] | 3163 | } else if (!keyboard) { |
Derek Foreman | 60d9731 | 2015-07-15 13:00:45 -0500 | [diff] [blame] | 3164 | wl_list_remove(&seat->keyboard_focus_listener.link); |
Jason Ekstrand | 024177c | 2014-04-21 19:42:58 -0500 | [diff] [blame] | 3165 | wl_list_init(&seat->keyboard_focus_listener.link); |
| 3166 | } |
| 3167 | |
Derek Foreman | 1281a36 | 2015-07-31 16:55:32 -0500 | [diff] [blame] | 3168 | if (pointer && |
Jason Ekstrand | 024177c | 2014-04-21 19:42:58 -0500 | [diff] [blame] | 3169 | wl_list_empty(&seat->pointer_focus_listener.link)) { |
Derek Foreman | 1281a36 | 2015-07-31 16:55:32 -0500 | [diff] [blame] | 3170 | wl_signal_add(&pointer->focus_signal, |
Jason Ekstrand | 024177c | 2014-04-21 19:42:58 -0500 | [diff] [blame] | 3171 | &seat->pointer_focus_listener); |
Derek Foreman | 1281a36 | 2015-07-31 16:55:32 -0500 | [diff] [blame] | 3172 | } else if (!pointer) { |
Derek Foreman | 60d9731 | 2015-07-15 13:00:45 -0500 | [diff] [blame] | 3173 | wl_list_remove(&seat->pointer_focus_listener.link); |
Jason Ekstrand | 024177c | 2014-04-21 19:42:58 -0500 | [diff] [blame] | 3174 | wl_list_init(&seat->pointer_focus_listener.link); |
| 3175 | } |
| 3176 | } |
| 3177 | |
Giulio Camuffo | 5085a75 | 2013-03-25 21:42:45 +0100 | [diff] [blame] | 3178 | static struct shell_seat * |
| 3179 | create_shell_seat(struct weston_seat *seat) |
| 3180 | { |
| 3181 | struct shell_seat *shseat; |
| 3182 | |
| 3183 | shseat = calloc(1, sizeof *shseat); |
| 3184 | if (!shseat) { |
| 3185 | weston_log("no memory to allocate shell seat\n"); |
| 3186 | return NULL; |
| 3187 | } |
| 3188 | |
| 3189 | shseat->seat = seat; |
| 3190 | wl_list_init(&shseat->popup_grab.surfaces_list); |
| 3191 | |
| 3192 | shseat->seat_destroy_listener.notify = destroy_shell_seat; |
| 3193 | wl_signal_add(&seat->destroy_signal, |
| 3194 | &shseat->seat_destroy_listener); |
| 3195 | |
Jason Ekstrand | 024177c | 2014-04-21 19:42:58 -0500 | [diff] [blame] | 3196 | shseat->keyboard_focus_listener.notify = handle_keyboard_focus; |
| 3197 | wl_list_init(&shseat->keyboard_focus_listener.link); |
| 3198 | |
| 3199 | shseat->pointer_focus_listener.notify = handle_pointer_focus; |
| 3200 | wl_list_init(&shseat->pointer_focus_listener.link); |
| 3201 | |
| 3202 | shseat->caps_changed_listener.notify = shell_seat_caps_changed; |
| 3203 | wl_signal_add(&seat->updated_caps_signal, |
| 3204 | &shseat->caps_changed_listener); |
| 3205 | shell_seat_caps_changed(&shseat->caps_changed_listener, NULL); |
| 3206 | |
Giulio Camuffo | 5085a75 | 2013-03-25 21:42:45 +0100 | [diff] [blame] | 3207 | return shseat; |
| 3208 | } |
| 3209 | |
| 3210 | static struct shell_seat * |
| 3211 | get_shell_seat(struct weston_seat *seat) |
| 3212 | { |
| 3213 | struct wl_listener *listener; |
| 3214 | |
| 3215 | listener = wl_signal_get(&seat->destroy_signal, destroy_shell_seat); |
Jason Ekstrand | 024177c | 2014-04-21 19:42:58 -0500 | [diff] [blame] | 3216 | assert(listener != NULL); |
Giulio Camuffo | 5085a75 | 2013-03-25 21:42:45 +0100 | [diff] [blame] | 3217 | |
| 3218 | return container_of(listener, |
| 3219 | struct shell_seat, seat_destroy_listener); |
| 3220 | } |
| 3221 | |
Kristian Høgsberg | b810eb5 | 2013-02-12 20:07:05 -0500 | [diff] [blame] | 3222 | static void |
Kristian Høgsberg | 6848c25 | 2013-05-08 22:02:59 -0400 | [diff] [blame] | 3223 | popup_grab_focus(struct weston_pointer_grab *grab) |
Kristian Høgsberg | b3cca0a | 2012-01-04 22:19:14 -0500 | [diff] [blame] | 3224 | { |
Kristian Høgsberg | 02bbabb | 2013-05-06 22:15:05 -0400 | [diff] [blame] | 3225 | struct weston_pointer *pointer = grab->pointer; |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 3226 | struct weston_view *view; |
Giulio Camuffo | 5085a75 | 2013-03-25 21:42:45 +0100 | [diff] [blame] | 3227 | struct shell_seat *shseat = |
| 3228 | container_of(grab, struct shell_seat, popup_grab.grab); |
| 3229 | struct wl_client *client = shseat->popup_grab.client; |
Kristian Høgsberg | 6848c25 | 2013-05-08 22:02:59 -0400 | [diff] [blame] | 3230 | wl_fixed_t sx, sy; |
| 3231 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 3232 | view = weston_compositor_pick_view(pointer->seat->compositor, |
| 3233 | pointer->x, pointer->y, |
| 3234 | &sx, &sy); |
Kristian Høgsberg | b3cca0a | 2012-01-04 22:19:14 -0500 | [diff] [blame] | 3235 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 3236 | if (view && view->surface->resource && |
| 3237 | wl_resource_get_client(view->surface->resource) == client) { |
| 3238 | weston_pointer_set_focus(pointer, view, sx, sy); |
Kristian Høgsberg | b3cca0a | 2012-01-04 22:19:14 -0500 | [diff] [blame] | 3239 | } else { |
Derek Foreman | f9318d1 | 2015-05-11 15:40:11 -0500 | [diff] [blame] | 3240 | weston_pointer_clear_focus(pointer); |
Kristian Høgsberg | b3cca0a | 2012-01-04 22:19:14 -0500 | [diff] [blame] | 3241 | } |
| 3242 | } |
| 3243 | |
| 3244 | static void |
Giulio Camuffo | 1959ab8 | 2013-11-14 23:42:52 +0100 | [diff] [blame] | 3245 | popup_grab_motion(struct weston_pointer_grab *grab, uint32_t time, |
| 3246 | wl_fixed_t x, wl_fixed_t y) |
Kristian Høgsberg | b3cca0a | 2012-01-04 22:19:14 -0500 | [diff] [blame] | 3247 | { |
Kristian Høgsberg | be6403e | 2013-05-08 21:03:21 -0400 | [diff] [blame] | 3248 | struct weston_pointer *pointer = grab->pointer; |
Neil Roberts | 96d790e | 2013-09-19 17:32:00 +0100 | [diff] [blame] | 3249 | struct wl_resource *resource; |
Kristian Høgsberg | be6403e | 2013-05-08 21:03:21 -0400 | [diff] [blame] | 3250 | wl_fixed_t sx, sy; |
Kristian Høgsberg | b3cca0a | 2012-01-04 22:19:14 -0500 | [diff] [blame] | 3251 | |
Jonas Ådahl | 61917c8 | 2014-08-11 22:44:02 +0200 | [diff] [blame] | 3252 | if (pointer->focus) { |
| 3253 | weston_view_from_global_fixed(pointer->focus, x, y, |
| 3254 | &pointer->sx, &pointer->sy); |
| 3255 | } |
| 3256 | |
Giulio Camuffo | 1959ab8 | 2013-11-14 23:42:52 +0100 | [diff] [blame] | 3257 | weston_pointer_move(pointer, x, y); |
| 3258 | |
Neil Roberts | 96d790e | 2013-09-19 17:32:00 +0100 | [diff] [blame] | 3259 | wl_resource_for_each(resource, &pointer->focus_resource_list) { |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 3260 | weston_view_from_global_fixed(pointer->focus, |
| 3261 | pointer->x, pointer->y, |
| 3262 | &sx, &sy); |
Neil Roberts | 96d790e | 2013-09-19 17:32:00 +0100 | [diff] [blame] | 3263 | wl_pointer_send_motion(resource, time, sx, sy); |
Kristian Høgsberg | be6403e | 2013-05-08 21:03:21 -0400 | [diff] [blame] | 3264 | } |
Kristian Høgsberg | b3cca0a | 2012-01-04 22:19:14 -0500 | [diff] [blame] | 3265 | } |
| 3266 | |
| 3267 | static void |
Kristian Høgsberg | 02bbabb | 2013-05-06 22:15:05 -0400 | [diff] [blame] | 3268 | popup_grab_button(struct weston_pointer_grab *grab, |
Daniel Stone | 4dbadb1 | 2012-05-30 16:31:51 +0100 | [diff] [blame] | 3269 | uint32_t time, uint32_t button, uint32_t state_w) |
Kristian Høgsberg | b3cca0a | 2012-01-04 22:19:14 -0500 | [diff] [blame] | 3270 | { |
| 3271 | struct wl_resource *resource; |
Giulio Camuffo | 5085a75 | 2013-03-25 21:42:45 +0100 | [diff] [blame] | 3272 | struct shell_seat *shseat = |
| 3273 | container_of(grab, struct shell_seat, popup_grab.grab); |
Rob Bradford | 880ebc7 | 2013-07-22 17:31:38 +0100 | [diff] [blame] | 3274 | struct wl_display *display = shseat->seat->compositor->wl_display; |
Daniel Stone | 4dbadb1 | 2012-05-30 16:31:51 +0100 | [diff] [blame] | 3275 | enum wl_pointer_button_state state = state_w; |
Kristian Høgsberg | eae5de7 | 2012-04-11 22:42:15 -0400 | [diff] [blame] | 3276 | uint32_t serial; |
Neil Roberts | 96d790e | 2013-09-19 17:32:00 +0100 | [diff] [blame] | 3277 | struct wl_list *resource_list; |
Kristian Høgsberg | b3cca0a | 2012-01-04 22:19:14 -0500 | [diff] [blame] | 3278 | |
Neil Roberts | 96d790e | 2013-09-19 17:32:00 +0100 | [diff] [blame] | 3279 | resource_list = &grab->pointer->focus_resource_list; |
| 3280 | if (!wl_list_empty(resource_list)) { |
Kristian Høgsberg | eae5de7 | 2012-04-11 22:42:15 -0400 | [diff] [blame] | 3281 | serial = wl_display_get_serial(display); |
Neil Roberts | 96d790e | 2013-09-19 17:32:00 +0100 | [diff] [blame] | 3282 | wl_resource_for_each(resource, resource_list) { |
| 3283 | wl_pointer_send_button(resource, serial, |
| 3284 | time, button, state); |
| 3285 | } |
Daniel Stone | 4dbadb1 | 2012-05-30 16:31:51 +0100 | [diff] [blame] | 3286 | } else if (state == WL_POINTER_BUTTON_STATE_RELEASED && |
Giulio Camuffo | 5085a75 | 2013-03-25 21:42:45 +0100 | [diff] [blame] | 3287 | (shseat->popup_grab.initial_up || |
Derek Foreman | f7b2f8b | 2015-07-15 13:00:41 -0500 | [diff] [blame] | 3288 | time - grab->pointer->grab_time > 500)) { |
Kristian Høgsberg | 57e0907 | 2012-10-30 14:07:27 -0400 | [diff] [blame] | 3289 | popup_grab_end(grab->pointer); |
Kristian Høgsberg | b3cca0a | 2012-01-04 22:19:14 -0500 | [diff] [blame] | 3290 | } |
| 3291 | |
Daniel Stone | 4dbadb1 | 2012-05-30 16:31:51 +0100 | [diff] [blame] | 3292 | if (state == WL_POINTER_BUTTON_STATE_RELEASED) |
Giulio Camuffo | 5085a75 | 2013-03-25 21:42:45 +0100 | [diff] [blame] | 3293 | shseat->popup_grab.initial_up = 1; |
Kristian Høgsberg | b3cca0a | 2012-01-04 22:19:14 -0500 | [diff] [blame] | 3294 | } |
| 3295 | |
Jonas Ådahl | 1ea343e | 2013-10-25 23:18:05 +0200 | [diff] [blame] | 3296 | static void |
| 3297 | popup_grab_cancel(struct weston_pointer_grab *grab) |
| 3298 | { |
| 3299 | popup_grab_end(grab->pointer); |
| 3300 | } |
| 3301 | |
Kristian Høgsberg | 02bbabb | 2013-05-06 22:15:05 -0400 | [diff] [blame] | 3302 | static const struct weston_pointer_grab_interface popup_grab_interface = { |
Kristian Høgsberg | b3cca0a | 2012-01-04 22:19:14 -0500 | [diff] [blame] | 3303 | popup_grab_focus, |
| 3304 | popup_grab_motion, |
| 3305 | popup_grab_button, |
Jonas Ådahl | 1ea343e | 2013-10-25 23:18:05 +0200 | [diff] [blame] | 3306 | popup_grab_cancel, |
Kristian Høgsberg | b3cca0a | 2012-01-04 22:19:14 -0500 | [diff] [blame] | 3307 | }; |
| 3308 | |
| 3309 | static void |
Jonny Lamb | 76cf1fe | 2014-08-20 11:27:10 +0200 | [diff] [blame] | 3310 | touch_popup_grab_down(struct weston_touch_grab *grab, uint32_t time, |
Giulio Camuffo | 61ed7b6 | 2015-07-08 11:55:28 +0300 | [diff] [blame] | 3311 | int touch_id, wl_fixed_t x, wl_fixed_t y) |
Jonny Lamb | 76cf1fe | 2014-08-20 11:27:10 +0200 | [diff] [blame] | 3312 | { |
| 3313 | struct wl_resource *resource; |
| 3314 | struct shell_seat *shseat = |
| 3315 | container_of(grab, struct shell_seat, popup_grab.touch_grab); |
| 3316 | struct wl_display *display = shseat->seat->compositor->wl_display; |
| 3317 | uint32_t serial; |
| 3318 | struct wl_list *resource_list; |
Giulio Camuffo | 61ed7b6 | 2015-07-08 11:55:28 +0300 | [diff] [blame] | 3319 | wl_fixed_t sx, sy; |
| 3320 | |
| 3321 | weston_view_from_global_fixed(grab->touch->focus, x, y, &sx, &sy); |
Jonny Lamb | 76cf1fe | 2014-08-20 11:27:10 +0200 | [diff] [blame] | 3322 | |
| 3323 | resource_list = &grab->touch->focus_resource_list; |
| 3324 | if (!wl_list_empty(resource_list)) { |
| 3325 | serial = wl_display_get_serial(display); |
| 3326 | wl_resource_for_each(resource, resource_list) { |
| 3327 | wl_touch_send_down(resource, serial, time, |
| 3328 | grab->touch->focus->surface->resource, |
| 3329 | touch_id, sx, sy); |
| 3330 | } |
| 3331 | } |
| 3332 | } |
| 3333 | |
| 3334 | static void |
| 3335 | touch_popup_grab_up(struct weston_touch_grab *grab, uint32_t time, int touch_id) |
| 3336 | { |
| 3337 | struct wl_resource *resource; |
| 3338 | struct shell_seat *shseat = |
| 3339 | container_of(grab, struct shell_seat, popup_grab.touch_grab); |
| 3340 | struct wl_display *display = shseat->seat->compositor->wl_display; |
| 3341 | uint32_t serial; |
| 3342 | struct wl_list *resource_list; |
| 3343 | |
| 3344 | resource_list = &grab->touch->focus_resource_list; |
| 3345 | if (!wl_list_empty(resource_list)) { |
| 3346 | serial = wl_display_get_serial(display); |
| 3347 | wl_resource_for_each(resource, resource_list) { |
| 3348 | wl_touch_send_up(resource, serial, time, touch_id); |
| 3349 | } |
| 3350 | } |
| 3351 | } |
| 3352 | |
| 3353 | static void |
| 3354 | touch_popup_grab_motion(struct weston_touch_grab *grab, uint32_t time, |
Giulio Camuffo | 61ed7b6 | 2015-07-08 11:55:28 +0300 | [diff] [blame] | 3355 | int touch_id, wl_fixed_t x, wl_fixed_t y) |
Jonny Lamb | 76cf1fe | 2014-08-20 11:27:10 +0200 | [diff] [blame] | 3356 | { |
| 3357 | struct wl_resource *resource; |
| 3358 | struct wl_list *resource_list; |
Giulio Camuffo | 61ed7b6 | 2015-07-08 11:55:28 +0300 | [diff] [blame] | 3359 | wl_fixed_t sx, sy; |
| 3360 | |
| 3361 | weston_view_from_global_fixed(grab->touch->focus, x, y, &sx, &sy); |
Jonny Lamb | 76cf1fe | 2014-08-20 11:27:10 +0200 | [diff] [blame] | 3362 | |
| 3363 | resource_list = &grab->touch->focus_resource_list; |
| 3364 | if (!wl_list_empty(resource_list)) { |
| 3365 | wl_resource_for_each(resource, resource_list) { |
| 3366 | wl_touch_send_motion(resource, time, touch_id, sx, sy); |
| 3367 | } |
| 3368 | } |
| 3369 | } |
| 3370 | |
| 3371 | static void |
| 3372 | touch_popup_grab_frame(struct weston_touch_grab *grab) |
| 3373 | { |
| 3374 | } |
| 3375 | |
| 3376 | static void |
| 3377 | touch_popup_grab_cancel(struct weston_touch_grab *grab) |
| 3378 | { |
| 3379 | touch_popup_grab_end(grab->touch); |
| 3380 | } |
| 3381 | |
| 3382 | static const struct weston_touch_grab_interface touch_popup_grab_interface = { |
| 3383 | touch_popup_grab_down, |
| 3384 | touch_popup_grab_up, |
| 3385 | touch_popup_grab_motion, |
| 3386 | touch_popup_grab_frame, |
| 3387 | touch_popup_grab_cancel, |
| 3388 | }; |
| 3389 | |
| 3390 | static void |
Rafael Antognolli | e2a3455 | 2013-12-03 15:35:45 -0200 | [diff] [blame] | 3391 | shell_surface_send_popup_done(struct shell_surface *shsurf) |
| 3392 | { |
| 3393 | if (shell_surface_is_wl_shell_surface(shsurf)) |
| 3394 | wl_shell_surface_send_popup_done(shsurf->resource); |
| 3395 | else if (shell_surface_is_xdg_popup(shsurf)) |
Jasper St. Pierre | ecf2a0f | 2015-02-13 14:01:56 +0800 | [diff] [blame] | 3396 | xdg_popup_send_popup_done(shsurf->resource); |
Rafael Antognolli | e2a3455 | 2013-12-03 15:35:45 -0200 | [diff] [blame] | 3397 | } |
| 3398 | |
| 3399 | static void |
Kristian Høgsberg | 02bbabb | 2013-05-06 22:15:05 -0400 | [diff] [blame] | 3400 | popup_grab_end(struct weston_pointer *pointer) |
Kristian Høgsberg | 57e0907 | 2012-10-30 14:07:27 -0400 | [diff] [blame] | 3401 | { |
Kristian Høgsberg | 02bbabb | 2013-05-06 22:15:05 -0400 | [diff] [blame] | 3402 | struct weston_pointer_grab *grab = pointer->grab; |
Giulio Camuffo | 5085a75 | 2013-03-25 21:42:45 +0100 | [diff] [blame] | 3403 | struct shell_seat *shseat = |
| 3404 | container_of(grab, struct shell_seat, popup_grab.grab); |
| 3405 | struct shell_surface *shsurf; |
Jonas Ådahl | c2b1011 | 2015-02-13 14:01:53 +0800 | [diff] [blame] | 3406 | struct shell_surface *next; |
Kristian Høgsberg | 57e0907 | 2012-10-30 14:07:27 -0400 | [diff] [blame] | 3407 | |
| 3408 | if (pointer->grab->interface == &popup_grab_interface) { |
Kristian Høgsberg | 02bbabb | 2013-05-06 22:15:05 -0400 | [diff] [blame] | 3409 | weston_pointer_end_grab(grab->pointer); |
Giulio Camuffo | 5085a75 | 2013-03-25 21:42:45 +0100 | [diff] [blame] | 3410 | shseat->popup_grab.client = NULL; |
Philipp Brüschweiler | 63e7be6 | 2013-04-15 21:09:54 +0200 | [diff] [blame] | 3411 | shseat->popup_grab.grab.interface = NULL; |
| 3412 | assert(!wl_list_empty(&shseat->popup_grab.surfaces_list)); |
Giulio Camuffo | 5085a75 | 2013-03-25 21:42:45 +0100 | [diff] [blame] | 3413 | /* Send the popup_done event to all the popups open */ |
Jonas Ådahl | c2b1011 | 2015-02-13 14:01:53 +0800 | [diff] [blame] | 3414 | wl_list_for_each_safe(shsurf, next, |
| 3415 | &shseat->popup_grab.surfaces_list, |
| 3416 | popup.grab_link) { |
Rafael Antognolli | e2a3455 | 2013-12-03 15:35:45 -0200 | [diff] [blame] | 3417 | shell_surface_send_popup_done(shsurf); |
Giulio Camuffo | 5085a75 | 2013-03-25 21:42:45 +0100 | [diff] [blame] | 3418 | shsurf->popup.shseat = NULL; |
Jonas Ådahl | c2b1011 | 2015-02-13 14:01:53 +0800 | [diff] [blame] | 3419 | wl_list_init(&shsurf->popup.grab_link); |
Giulio Camuffo | 5085a75 | 2013-03-25 21:42:45 +0100 | [diff] [blame] | 3420 | } |
Giulio Camuffo | 5085a75 | 2013-03-25 21:42:45 +0100 | [diff] [blame] | 3421 | wl_list_init(&shseat->popup_grab.surfaces_list); |
| 3422 | } |
| 3423 | } |
| 3424 | |
| 3425 | static void |
Jonny Lamb | 76cf1fe | 2014-08-20 11:27:10 +0200 | [diff] [blame] | 3426 | touch_popup_grab_end(struct weston_touch *touch) |
| 3427 | { |
| 3428 | struct weston_touch_grab *grab = touch->grab; |
| 3429 | struct shell_seat *shseat = |
| 3430 | container_of(grab, struct shell_seat, popup_grab.touch_grab); |
| 3431 | struct shell_surface *shsurf; |
Jonas Ådahl | c2b1011 | 2015-02-13 14:01:53 +0800 | [diff] [blame] | 3432 | struct shell_surface *next; |
Jonny Lamb | 76cf1fe | 2014-08-20 11:27:10 +0200 | [diff] [blame] | 3433 | |
| 3434 | if (touch->grab->interface == &touch_popup_grab_interface) { |
| 3435 | weston_touch_end_grab(grab->touch); |
| 3436 | shseat->popup_grab.client = NULL; |
| 3437 | shseat->popup_grab.touch_grab.interface = NULL; |
| 3438 | assert(!wl_list_empty(&shseat->popup_grab.surfaces_list)); |
| 3439 | /* Send the popup_done event to all the popups open */ |
Jonas Ådahl | c2b1011 | 2015-02-13 14:01:53 +0800 | [diff] [blame] | 3440 | wl_list_for_each_safe(shsurf, next, |
| 3441 | &shseat->popup_grab.surfaces_list, |
| 3442 | popup.grab_link) { |
Jonny Lamb | 76cf1fe | 2014-08-20 11:27:10 +0200 | [diff] [blame] | 3443 | shell_surface_send_popup_done(shsurf); |
| 3444 | shsurf->popup.shseat = NULL; |
Jonas Ådahl | c2b1011 | 2015-02-13 14:01:53 +0800 | [diff] [blame] | 3445 | wl_list_init(&shsurf->popup.grab_link); |
Jonny Lamb | 76cf1fe | 2014-08-20 11:27:10 +0200 | [diff] [blame] | 3446 | } |
Jonny Lamb | 76cf1fe | 2014-08-20 11:27:10 +0200 | [diff] [blame] | 3447 | wl_list_init(&shseat->popup_grab.surfaces_list); |
| 3448 | } |
| 3449 | } |
| 3450 | |
Jasper St. Pierre | da6ecd0 | 2015-02-27 18:35:45 +0800 | [diff] [blame] | 3451 | static struct shell_surface * |
| 3452 | get_top_popup(struct shell_seat *shseat) |
| 3453 | { |
| 3454 | struct shell_surface *shsurf; |
| 3455 | |
| 3456 | if (wl_list_empty(&shseat->popup_grab.surfaces_list)) { |
| 3457 | return NULL; |
| 3458 | } else { |
| 3459 | shsurf = container_of(shseat->popup_grab.surfaces_list.next, |
| 3460 | struct shell_surface, |
| 3461 | popup.grab_link); |
| 3462 | return shsurf; |
| 3463 | } |
| 3464 | } |
| 3465 | |
| 3466 | static int |
Jonas Ådahl | 01193ae | 2015-02-13 14:01:54 +0800 | [diff] [blame] | 3467 | add_popup_grab(struct shell_surface *shsurf, |
| 3468 | struct shell_seat *shseat, |
| 3469 | int32_t type) |
Giulio Camuffo | 5085a75 | 2013-03-25 21:42:45 +0100 | [diff] [blame] | 3470 | { |
Kristian Høgsberg | e314875 | 2013-05-06 23:19:49 -0400 | [diff] [blame] | 3471 | struct weston_seat *seat = shseat->seat; |
Jasper St. Pierre | da6ecd0 | 2015-02-27 18:35:45 +0800 | [diff] [blame] | 3472 | struct shell_surface *parent, *top_surface; |
Derek Foreman | 1281a36 | 2015-07-31 16:55:32 -0500 | [diff] [blame] | 3473 | struct weston_pointer *pointer = weston_seat_get_pointer(seat); |
| 3474 | struct weston_touch *touch = weston_seat_get_touch(seat); |
Jasper St. Pierre | da6ecd0 | 2015-02-27 18:35:45 +0800 | [diff] [blame] | 3475 | |
| 3476 | parent = get_shell_surface(shsurf->parent); |
| 3477 | top_surface = get_top_popup(shseat); |
| 3478 | if (shell_surface_is_xdg_popup(shsurf) && |
Dima Ryazanov | 497f25d | 2015-04-08 11:51:57 -0700 | [diff] [blame] | 3479 | (!parent || |
| 3480 | (top_surface == NULL && !shell_surface_is_xdg_surface(parent)) || |
Jasper St. Pierre | da6ecd0 | 2015-02-27 18:35:45 +0800 | [diff] [blame] | 3481 | (top_surface != NULL && parent != top_surface))) { |
Jonas Ådahl | ee45a55 | 2015-03-18 16:37:47 +0800 | [diff] [blame] | 3482 | wl_resource_post_error(shsurf->owner_resource, |
| 3483 | XDG_SHELL_ERROR_NOT_THE_TOPMOST_POPUP, |
Jasper St. Pierre | da6ecd0 | 2015-02-27 18:35:45 +0800 | [diff] [blame] | 3484 | "xdg_popup was not created on the " |
| 3485 | "topmost popup"); |
| 3486 | return -1; |
| 3487 | } |
Giulio Camuffo | 5085a75 | 2013-03-25 21:42:45 +0100 | [diff] [blame] | 3488 | |
| 3489 | if (wl_list_empty(&shseat->popup_grab.surfaces_list)) { |
Jonny Lamb | 76cf1fe | 2014-08-20 11:27:10 +0200 | [diff] [blame] | 3490 | shseat->popup_grab.type = type; |
Jonas Ådahl | 01193ae | 2015-02-13 14:01:54 +0800 | [diff] [blame] | 3491 | shseat->popup_grab.client = |
| 3492 | wl_resource_get_client(shsurf->resource); |
Jonny Lamb | 76cf1fe | 2014-08-20 11:27:10 +0200 | [diff] [blame] | 3493 | |
| 3494 | if (type == POINTER) { |
Jonas Ådahl | 01193ae | 2015-02-13 14:01:54 +0800 | [diff] [blame] | 3495 | shseat->popup_grab.grab.interface = |
| 3496 | &popup_grab_interface; |
| 3497 | |
| 3498 | /* We must make sure here that this popup was opened |
| 3499 | * after a mouse press, and not just by moving around |
| 3500 | * with other popups already open. */ |
Derek Foreman | 1281a36 | 2015-07-31 16:55:32 -0500 | [diff] [blame] | 3501 | if (pointer->button_count > 0) |
Jonny Lamb | 76cf1fe | 2014-08-20 11:27:10 +0200 | [diff] [blame] | 3502 | shseat->popup_grab.initial_up = 0; |
| 3503 | } else if (type == TOUCH) { |
Jonas Ådahl | 01193ae | 2015-02-13 14:01:54 +0800 | [diff] [blame] | 3504 | shseat->popup_grab.touch_grab.interface = |
| 3505 | &touch_popup_grab_interface; |
Jonny Lamb | 76cf1fe | 2014-08-20 11:27:10 +0200 | [diff] [blame] | 3506 | } |
Giulio Camuffo | 5085a75 | 2013-03-25 21:42:45 +0100 | [diff] [blame] | 3507 | |
Jonas Ådahl | 01193ae | 2015-02-13 14:01:54 +0800 | [diff] [blame] | 3508 | wl_list_insert(&shseat->popup_grab.surfaces_list, |
| 3509 | &shsurf->popup.grab_link); |
Jonny Lamb | 76cf1fe | 2014-08-20 11:27:10 +0200 | [diff] [blame] | 3510 | |
Jonas Ådahl | 01193ae | 2015-02-13 14:01:54 +0800 | [diff] [blame] | 3511 | if (type == POINTER) { |
Derek Foreman | 1281a36 | 2015-07-31 16:55:32 -0500 | [diff] [blame] | 3512 | weston_pointer_start_grab(pointer, |
Jonas Ådahl | 01193ae | 2015-02-13 14:01:54 +0800 | [diff] [blame] | 3513 | &shseat->popup_grab.grab); |
| 3514 | } else if (type == TOUCH) { |
Derek Foreman | 1281a36 | 2015-07-31 16:55:32 -0500 | [diff] [blame] | 3515 | weston_touch_start_grab(touch, |
Jonas Ådahl | 01193ae | 2015-02-13 14:01:54 +0800 | [diff] [blame] | 3516 | &shseat->popup_grab.touch_grab); |
| 3517 | } |
Rob Bradford | dfe3105 | 2013-06-26 19:49:11 +0100 | [diff] [blame] | 3518 | } else { |
Jonas Ådahl | 01193ae | 2015-02-13 14:01:54 +0800 | [diff] [blame] | 3519 | wl_list_insert(&shseat->popup_grab.surfaces_list, |
| 3520 | &shsurf->popup.grab_link); |
Giulio Camuffo | 5085a75 | 2013-03-25 21:42:45 +0100 | [diff] [blame] | 3521 | } |
Jasper St. Pierre | da6ecd0 | 2015-02-27 18:35:45 +0800 | [diff] [blame] | 3522 | |
| 3523 | return 0; |
Giulio Camuffo | 5085a75 | 2013-03-25 21:42:45 +0100 | [diff] [blame] | 3524 | } |
| 3525 | |
| 3526 | static void |
| 3527 | remove_popup_grab(struct shell_surface *shsurf) |
| 3528 | { |
| 3529 | struct shell_seat *shseat = shsurf->popup.shseat; |
| 3530 | |
Jasper St. Pierre | da6ecd0 | 2015-02-27 18:35:45 +0800 | [diff] [blame] | 3531 | if (shell_surface_is_xdg_popup(shsurf) && |
| 3532 | get_top_popup(shseat) != shsurf) { |
Jonas Ådahl | ee45a55 | 2015-03-18 16:37:47 +0800 | [diff] [blame] | 3533 | wl_resource_post_error(shsurf->owner_resource, |
| 3534 | XDG_SHELL_ERROR_NOT_THE_TOPMOST_POPUP, |
Jasper St. Pierre | da6ecd0 | 2015-02-27 18:35:45 +0800 | [diff] [blame] | 3535 | "xdg_popup was destroyed while it was " |
| 3536 | "not the topmost popup."); |
| 3537 | return; |
| 3538 | } |
| 3539 | |
Giulio Camuffo | 5085a75 | 2013-03-25 21:42:45 +0100 | [diff] [blame] | 3540 | wl_list_remove(&shsurf->popup.grab_link); |
| 3541 | wl_list_init(&shsurf->popup.grab_link); |
| 3542 | if (wl_list_empty(&shseat->popup_grab.surfaces_list)) { |
Jonny Lamb | 76cf1fe | 2014-08-20 11:27:10 +0200 | [diff] [blame] | 3543 | if (shseat->popup_grab.type == POINTER) { |
| 3544 | weston_pointer_end_grab(shseat->popup_grab.grab.pointer); |
| 3545 | shseat->popup_grab.grab.interface = NULL; |
| 3546 | } else if (shseat->popup_grab.type == TOUCH) { |
| 3547 | weston_touch_end_grab(shseat->popup_grab.touch_grab.touch); |
| 3548 | shseat->popup_grab.touch_grab.interface = NULL; |
| 3549 | } |
Kristian Høgsberg | 57e0907 | 2012-10-30 14:07:27 -0400 | [diff] [blame] | 3550 | } |
| 3551 | } |
| 3552 | |
Jasper St. Pierre | da6ecd0 | 2015-02-27 18:35:45 +0800 | [diff] [blame] | 3553 | static int |
Kristian Høgsberg | 3730f36 | 2012-04-13 12:40:07 -0400 | [diff] [blame] | 3554 | shell_map_popup(struct shell_surface *shsurf) |
Kristian Høgsberg | b3cca0a | 2012-01-04 22:19:14 -0500 | [diff] [blame] | 3555 | { |
Giulio Camuffo | 5085a75 | 2013-03-25 21:42:45 +0100 | [diff] [blame] | 3556 | struct shell_seat *shseat = shsurf->popup.shseat; |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 3557 | struct weston_view *parent_view = get_default_view(shsurf->parent); |
Derek Foreman | 1281a36 | 2015-07-31 16:55:32 -0500 | [diff] [blame] | 3558 | struct weston_pointer *pointer = weston_seat_get_pointer(shseat->seat); |
| 3559 | struct weston_touch *touch = weston_seat_get_touch(shseat->seat); |
Kristian Høgsberg | b3cca0a | 2012-01-04 22:19:14 -0500 | [diff] [blame] | 3560 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 3561 | shsurf->surface->output = parent_view->output; |
| 3562 | shsurf->view->output = parent_view->output; |
Kristian Høgsberg | b3cca0a | 2012-01-04 22:19:14 -0500 | [diff] [blame] | 3563 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 3564 | weston_view_set_transform_parent(shsurf->view, parent_view); |
| 3565 | weston_view_set_position(shsurf->view, shsurf->popup.x, shsurf->popup.y); |
| 3566 | weston_view_update_transform(shsurf->view); |
Kristian Høgsberg | b3cca0a | 2012-01-04 22:19:14 -0500 | [diff] [blame] | 3567 | |
Derek Foreman | 1281a36 | 2015-07-31 16:55:32 -0500 | [diff] [blame] | 3568 | if (pointer && |
| 3569 | pointer->grab_serial == shsurf->popup.serial) { |
Jasper St. Pierre | da6ecd0 | 2015-02-27 18:35:45 +0800 | [diff] [blame] | 3570 | if (add_popup_grab(shsurf, shseat, POINTER) != 0) |
| 3571 | return -1; |
Derek Foreman | 1281a36 | 2015-07-31 16:55:32 -0500 | [diff] [blame] | 3572 | } else if (touch && |
| 3573 | touch->grab_serial == shsurf->popup.serial) { |
Jasper St. Pierre | da6ecd0 | 2015-02-27 18:35:45 +0800 | [diff] [blame] | 3574 | if (add_popup_grab(shsurf, shseat, TOUCH) != 0) |
| 3575 | return -1; |
Kristian Høgsberg | 3730f36 | 2012-04-13 12:40:07 -0400 | [diff] [blame] | 3576 | } else { |
Rafael Antognolli | e2a3455 | 2013-12-03 15:35:45 -0200 | [diff] [blame] | 3577 | shell_surface_send_popup_done(shsurf); |
Giulio Camuffo | 5085a75 | 2013-03-25 21:42:45 +0100 | [diff] [blame] | 3578 | shseat->popup_grab.client = NULL; |
Kristian Høgsberg | 3730f36 | 2012-04-13 12:40:07 -0400 | [diff] [blame] | 3579 | } |
Jasper St. Pierre | da6ecd0 | 2015-02-27 18:35:45 +0800 | [diff] [blame] | 3580 | |
| 3581 | return 0; |
Kristian Høgsberg | b3cca0a | 2012-01-04 22:19:14 -0500 | [diff] [blame] | 3582 | } |
| 3583 | |
Pekka Paalanen | 9d1613e | 2011-11-25 12:09:16 +0200 | [diff] [blame] | 3584 | static const struct wl_shell_surface_interface shell_surface_implementation = { |
Scott Moreau | ff1db4a | 2012-04-17 19:06:18 -0600 | [diff] [blame] | 3585 | shell_surface_pong, |
Pekka Paalanen | 9d1613e | 2011-11-25 12:09:16 +0200 | [diff] [blame] | 3586 | shell_surface_move, |
| 3587 | shell_surface_resize, |
| 3588 | shell_surface_set_toplevel, |
| 3589 | shell_surface_set_transient, |
Kristian Høgsberg | b3cca0a | 2012-01-04 22:19:14 -0500 | [diff] [blame] | 3590 | shell_surface_set_fullscreen, |
Juan Zhao | 96879df | 2012-02-07 08:45:41 +0800 | [diff] [blame] | 3591 | shell_surface_set_popup, |
Kristian Høgsberg | e7afd91 | 2012-05-02 09:47:44 -0400 | [diff] [blame] | 3592 | shell_surface_set_maximized, |
| 3593 | shell_surface_set_title, |
| 3594 | shell_surface_set_class |
Pekka Paalanen | 9d1613e | 2011-11-25 12:09:16 +0200 | [diff] [blame] | 3595 | }; |
| 3596 | |
| 3597 | static void |
Tiago Vignatti | bc052c9 | 2012-04-19 16:18:18 +0300 | [diff] [blame] | 3598 | destroy_shell_surface(struct shell_surface *shsurf) |
Pekka Paalanen | 9d1613e | 2011-11-25 12:09:16 +0200 | [diff] [blame] | 3599 | { |
Kristian Høgsberg | 9046d24 | 2014-01-10 00:25:30 -0800 | [diff] [blame] | 3600 | struct shell_surface *child, *next; |
| 3601 | |
Jason Ekstrand | 651f00e | 2013-06-14 10:07:54 -0500 | [diff] [blame] | 3602 | wl_signal_emit(&shsurf->destroy_signal, shsurf); |
| 3603 | |
Giulio Camuffo | 5085a75 | 2013-03-25 21:42:45 +0100 | [diff] [blame] | 3604 | if (!wl_list_empty(&shsurf->popup.grab_link)) { |
| 3605 | remove_popup_grab(shsurf); |
| 3606 | } |
Kristian Høgsberg | b3cca0a | 2012-01-04 22:19:14 -0500 | [diff] [blame] | 3607 | |
Alex Wu | bd3354b | 2012-04-17 17:20:49 +0800 | [diff] [blame] | 3608 | if (shsurf->fullscreen.type == WL_SHELL_SURFACE_FULLSCREEN_METHOD_DRIVER && |
Alexander Larsson | f82b6ca | 2013-05-28 16:23:39 +0200 | [diff] [blame] | 3609 | shell_surface_is_top_fullscreen(shsurf)) |
| 3610 | restore_output_mode (shsurf->fullscreen_output); |
Pekka Paalanen | 9d1613e | 2011-11-25 12:09:16 +0200 | [diff] [blame] | 3611 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 3612 | if (shsurf->fullscreen.black_view) |
| 3613 | weston_surface_destroy(shsurf->fullscreen.black_view->surface); |
Alex Wu | aa08e2d | 2012-03-05 11:01:40 +0800 | [diff] [blame] | 3614 | |
Alex Wu | bd3354b | 2012-04-17 17:20:49 +0800 | [diff] [blame] | 3615 | /* As destroy_resource() use wl_list_for_each_safe(), |
| 3616 | * we can always remove the listener. |
| 3617 | */ |
| 3618 | wl_list_remove(&shsurf->surface_destroy_listener.link); |
| 3619 | shsurf->surface->configure = NULL; |
Pekka Paalanen | 8274d90 | 2014-08-06 19:36:51 +0300 | [diff] [blame] | 3620 | weston_surface_set_label_func(shsurf->surface, NULL); |
Scott Moreau | 976a050 | 2013-03-07 10:15:17 -0700 | [diff] [blame] | 3621 | free(shsurf->title); |
Alex Wu | bd3354b | 2012-04-17 17:20:49 +0800 | [diff] [blame] | 3622 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 3623 | weston_view_destroy(shsurf->view); |
| 3624 | |
Philip Withnall | 648a4dd | 2013-11-25 18:01:44 +0000 | [diff] [blame] | 3625 | wl_list_remove(&shsurf->children_link); |
Emilio Pozuelo Monfort | adaa20c | 2014-01-28 13:54:16 +0100 | [diff] [blame] | 3626 | wl_list_for_each_safe(child, next, &shsurf->children_list, children_link) |
| 3627 | shell_surface_set_parent(child, NULL); |
Philip Withnall | 648a4dd | 2013-11-25 18:01:44 +0000 | [diff] [blame] | 3628 | |
Pekka Paalanen | 9d1613e | 2011-11-25 12:09:16 +0200 | [diff] [blame] | 3629 | wl_list_remove(&shsurf->link); |
| 3630 | free(shsurf); |
| 3631 | } |
| 3632 | |
| 3633 | static void |
Tiago Vignatti | bc052c9 | 2012-04-19 16:18:18 +0300 | [diff] [blame] | 3634 | shell_destroy_shell_surface(struct wl_resource *resource) |
| 3635 | { |
Jason Ekstrand | 651f00e | 2013-06-14 10:07:54 -0500 | [diff] [blame] | 3636 | struct shell_surface *shsurf = wl_resource_get_user_data(resource); |
Tiago Vignatti | bc052c9 | 2012-04-19 16:18:18 +0300 | [diff] [blame] | 3637 | |
Bryan Cain | a46b946 | 2014-04-04 17:41:24 -0500 | [diff] [blame] | 3638 | if (!wl_list_empty(&shsurf->popup.grab_link)) |
| 3639 | remove_popup_grab(shsurf); |
Jonas Ådahl | 49d77d2 | 2015-03-18 16:20:51 +0800 | [diff] [blame] | 3640 | wl_list_remove(wl_resource_get_link(shsurf->resource)); |
Kristian Høgsberg | 160fe75 | 2014-03-11 10:19:10 -0700 | [diff] [blame] | 3641 | shsurf->resource = NULL; |
Tiago Vignatti | bc052c9 | 2012-04-19 16:18:18 +0300 | [diff] [blame] | 3642 | } |
| 3643 | |
| 3644 | static void |
Kristian Høgsberg | 27e3052 | 2012-04-11 23:18:23 -0400 | [diff] [blame] | 3645 | shell_handle_surface_destroy(struct wl_listener *listener, void *data) |
Pekka Paalanen | 9d1613e | 2011-11-25 12:09:16 +0200 | [diff] [blame] | 3646 | { |
| 3647 | struct shell_surface *shsurf = container_of(listener, |
| 3648 | struct shell_surface, |
| 3649 | surface_destroy_listener); |
| 3650 | |
Jason Ekstrand | 651f00e | 2013-06-14 10:07:54 -0500 | [diff] [blame] | 3651 | if (shsurf->resource) |
| 3652 | wl_resource_destroy(shsurf->resource); |
Ander Conselvan de Oliveira | 15f9a26 | 2014-04-29 17:54:02 +0300 | [diff] [blame] | 3653 | |
| 3654 | destroy_shell_surface(shsurf); |
Pekka Paalanen | 9d1613e | 2011-11-25 12:09:16 +0200 | [diff] [blame] | 3655 | } |
| 3656 | |
Kristian Høgsberg | d813445 | 2012-06-21 12:49:02 -0400 | [diff] [blame] | 3657 | static void |
Derek Foreman | 039e9be | 2015-04-14 17:09:06 -0500 | [diff] [blame] | 3658 | fade_out_done_idle_cb(void *data) |
Kristian Høgsberg | 160fe75 | 2014-03-11 10:19:10 -0700 | [diff] [blame] | 3659 | { |
| 3660 | struct shell_surface *shsurf = data; |
| 3661 | |
| 3662 | weston_surface_destroy(shsurf->surface); |
| 3663 | } |
| 3664 | |
| 3665 | static void |
Derek Foreman | 039e9be | 2015-04-14 17:09:06 -0500 | [diff] [blame] | 3666 | fade_out_done(struct weston_view_animation *animation, void *data) |
| 3667 | { |
| 3668 | struct shell_surface *shsurf = data; |
| 3669 | struct wl_event_loop *loop; |
| 3670 | |
| 3671 | loop = wl_display_get_event_loop( |
| 3672 | shsurf->surface->compositor->wl_display); |
| 3673 | |
| 3674 | if (!shsurf->destroying) { |
| 3675 | wl_event_loop_add_idle(loop, fade_out_done_idle_cb, shsurf); |
| 3676 | shsurf->destroying = true; |
| 3677 | } |
| 3678 | } |
| 3679 | |
| 3680 | static void |
Kristian Høgsberg | 160fe75 | 2014-03-11 10:19:10 -0700 | [diff] [blame] | 3681 | handle_resource_destroy(struct wl_listener *listener, void *data) |
| 3682 | { |
| 3683 | struct shell_surface *shsurf = |
| 3684 | container_of(listener, struct shell_surface, |
| 3685 | resource_destroy_listener); |
| 3686 | |
Ander Conselvan de Oliveira | 15f9a26 | 2014-04-29 17:54:02 +0300 | [diff] [blame] | 3687 | if (!weston_surface_is_mapped(shsurf->surface)) |
| 3688 | return; |
| 3689 | |
Kristian Høgsberg | 160fe75 | 2014-03-11 10:19:10 -0700 | [diff] [blame] | 3690 | shsurf->surface->ref_count++; |
| 3691 | |
| 3692 | pixman_region32_fini(&shsurf->surface->pending.input); |
| 3693 | pixman_region32_init(&shsurf->surface->pending.input); |
| 3694 | pixman_region32_fini(&shsurf->surface->input); |
| 3695 | pixman_region32_init(&shsurf->surface->input); |
Jonny Lamb | f322f8e | 2014-08-12 15:13:30 +0200 | [diff] [blame] | 3696 | if (shsurf->shell->win_close_animation_type == ANIMATION_FADE) { |
| 3697 | weston_fade_run(shsurf->view, 1.0, 0.0, 300.0, |
| 3698 | fade_out_done, shsurf); |
| 3699 | } else { |
| 3700 | weston_surface_destroy(shsurf->surface); |
| 3701 | } |
Kristian Høgsberg | 160fe75 | 2014-03-11 10:19:10 -0700 | [diff] [blame] | 3702 | } |
| 3703 | |
| 3704 | static void |
Jason Ekstrand | 918f2dd | 2013-12-02 21:01:53 -0600 | [diff] [blame] | 3705 | shell_surface_configure(struct weston_surface *, int32_t, int32_t); |
Kristian Høgsberg | d813445 | 2012-06-21 12:49:02 -0400 | [diff] [blame] | 3706 | |
Kristian Høgsberg | 1ef2313 | 2013-12-04 00:20:01 -0800 | [diff] [blame] | 3707 | struct shell_surface * |
Kristian Høgsberg | 8334bc1 | 2012-01-03 10:29:47 -0500 | [diff] [blame] | 3708 | get_shell_surface(struct weston_surface *surface) |
Pekka Paalanen | ec2b32f | 2011-11-28 15:12:34 +0200 | [diff] [blame] | 3709 | { |
Kristian Høgsberg | d813445 | 2012-06-21 12:49:02 -0400 | [diff] [blame] | 3710 | if (surface->configure == shell_surface_configure) |
Giulio Camuffo | 7fe01b1 | 2013-03-28 18:02:42 +0100 | [diff] [blame] | 3711 | return surface->configure_private; |
Kristian Høgsberg | d813445 | 2012-06-21 12:49:02 -0400 | [diff] [blame] | 3712 | else |
| 3713 | return NULL; |
Pekka Paalanen | ec2b32f | 2011-11-28 15:12:34 +0200 | [diff] [blame] | 3714 | } |
| 3715 | |
Rafael Antognolli | e2a3455 | 2013-12-03 15:35:45 -0200 | [diff] [blame] | 3716 | static struct shell_surface * |
Jason Ekstrand | 9e9512f | 2014-04-16 21:12:10 -0500 | [diff] [blame] | 3717 | create_common_surface(struct shell_client *owner, void *shell, |
| 3718 | struct weston_surface *surface, |
Rafael Antognolli | e2a3455 | 2013-12-03 15:35:45 -0200 | [diff] [blame] | 3719 | const struct weston_shell_client *client) |
Pekka Paalanen | 9d1613e | 2011-11-25 12:09:16 +0200 | [diff] [blame] | 3720 | { |
Pekka Paalanen | 9d1613e | 2011-11-25 12:09:16 +0200 | [diff] [blame] | 3721 | struct shell_surface *shsurf; |
| 3722 | |
Pekka Paalanen | 50b6747 | 2014-10-01 15:02:41 +0300 | [diff] [blame] | 3723 | assert(surface->configure == NULL); |
Ander Conselvan de Oliveira | 093bfa3 | 2012-03-27 17:36:41 +0300 | [diff] [blame] | 3724 | |
Pekka Paalanen | 9d1613e | 2011-11-25 12:09:16 +0200 | [diff] [blame] | 3725 | shsurf = calloc(1, sizeof *shsurf); |
| 3726 | if (!shsurf) { |
Martin Minarik | 6d11836 | 2012-06-07 18:01:59 +0200 | [diff] [blame] | 3727 | weston_log("no memory to allocate shell surface\n"); |
Kristian Høgsberg | 45ba869 | 2012-05-21 14:27:33 -0400 | [diff] [blame] | 3728 | return NULL; |
Pekka Paalanen | 9d1613e | 2011-11-25 12:09:16 +0200 | [diff] [blame] | 3729 | } |
| 3730 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 3731 | shsurf->view = weston_view_create(surface); |
| 3732 | if (!shsurf->view) { |
| 3733 | weston_log("no memory to allocate shell surface\n"); |
| 3734 | free(shsurf); |
| 3735 | return NULL; |
| 3736 | } |
| 3737 | |
Ander Conselvan de Oliveira | 093bfa3 | 2012-03-27 17:36:41 +0300 | [diff] [blame] | 3738 | surface->configure = shell_surface_configure; |
Giulio Camuffo | 7fe01b1 | 2013-03-28 18:02:42 +0100 | [diff] [blame] | 3739 | surface->configure_private = shsurf; |
Pekka Paalanen | 8274d90 | 2014-08-06 19:36:51 +0300 | [diff] [blame] | 3740 | weston_surface_set_label_func(surface, shell_surface_get_label); |
Ander Conselvan de Oliveira | 093bfa3 | 2012-03-27 17:36:41 +0300 | [diff] [blame] | 3741 | |
Kristian Høgsberg | 160fe75 | 2014-03-11 10:19:10 -0700 | [diff] [blame] | 3742 | shsurf->resource_destroy_listener.notify = handle_resource_destroy; |
| 3743 | wl_resource_add_destroy_listener(surface->resource, |
| 3744 | &shsurf->resource_destroy_listener); |
Jason Ekstrand | 9e9512f | 2014-04-16 21:12:10 -0500 | [diff] [blame] | 3745 | shsurf->owner = owner; |
Kristian Høgsberg | 160fe75 | 2014-03-11 10:19:10 -0700 | [diff] [blame] | 3746 | |
Tiago Vignatti | bc052c9 | 2012-04-19 16:18:18 +0300 | [diff] [blame] | 3747 | shsurf->shell = (struct desktop_shell *) shell; |
Scott Moreau | ff1db4a | 2012-04-17 19:06:18 -0600 | [diff] [blame] | 3748 | shsurf->unresponsive = 0; |
Alex Wu | 4539b08 | 2012-03-01 12:57:46 +0800 | [diff] [blame] | 3749 | shsurf->saved_position_valid = false; |
Rafael Antognolli | 3c4e3f7 | 2013-12-03 15:35:46 -0200 | [diff] [blame] | 3750 | shsurf->saved_size_valid = false; |
Alex Wu | 7bcb8bd | 2012-04-27 09:07:24 +0800 | [diff] [blame] | 3751 | shsurf->saved_rotation_valid = false; |
Pekka Paalanen | 9d1613e | 2011-11-25 12:09:16 +0200 | [diff] [blame] | 3752 | shsurf->surface = surface; |
Alex Wu | 4539b08 | 2012-03-01 12:57:46 +0800 | [diff] [blame] | 3753 | shsurf->fullscreen.type = WL_SHELL_SURFACE_FULLSCREEN_METHOD_DEFAULT; |
| 3754 | shsurf->fullscreen.framerate = 0; |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 3755 | shsurf->fullscreen.black_view = NULL; |
Alex Wu | 4539b08 | 2012-03-01 12:57:46 +0800 | [diff] [blame] | 3756 | wl_list_init(&shsurf->fullscreen.transform.link); |
| 3757 | |
Jasper St. Pierre | 9aa8ce6 | 2014-04-11 16:18:54 -0700 | [diff] [blame] | 3758 | shsurf->output = get_default_output(shsurf->shell->compositor); |
| 3759 | |
Jason Ekstrand | 651f00e | 2013-06-14 10:07:54 -0500 | [diff] [blame] | 3760 | wl_signal_init(&shsurf->destroy_signal); |
Kristian Høgsberg | 27e3052 | 2012-04-11 23:18:23 -0400 | [diff] [blame] | 3761 | shsurf->surface_destroy_listener.notify = shell_handle_surface_destroy; |
Jason Ekstrand | 26ed73c | 2013-06-06 22:34:41 -0500 | [diff] [blame] | 3762 | wl_signal_add(&surface->destroy_signal, |
Kristian Høgsberg | 27e3052 | 2012-04-11 23:18:23 -0400 | [diff] [blame] | 3763 | &shsurf->surface_destroy_listener); |
Pekka Paalanen | 9d1613e | 2011-11-25 12:09:16 +0200 | [diff] [blame] | 3764 | |
| 3765 | /* init link so its safe to always remove it in destroy_shell_surface */ |
| 3766 | wl_list_init(&shsurf->link); |
Giulio Camuffo | 5085a75 | 2013-03-25 21:42:45 +0100 | [diff] [blame] | 3767 | wl_list_init(&shsurf->popup.grab_link); |
Pekka Paalanen | 9d1613e | 2011-11-25 12:09:16 +0200 | [diff] [blame] | 3768 | |
Pekka Paalanen | 460099f | 2012-01-20 16:48:25 +0200 | [diff] [blame] | 3769 | /* empty when not in use */ |
| 3770 | wl_list_init(&shsurf->rotation.transform.link); |
Kristian Høgsberg | 765e27b | 2012-01-27 13:36:13 -0500 | [diff] [blame] | 3771 | weston_matrix_init(&shsurf->rotation.rotation); |
Pekka Paalanen | 460099f | 2012-01-20 16:48:25 +0200 | [diff] [blame] | 3772 | |
Jonas Ådahl | 62fcd04 | 2012-06-13 00:01:23 +0200 | [diff] [blame] | 3773 | wl_list_init(&shsurf->workspace_transform.link); |
| 3774 | |
Philip Withnall | 648a4dd | 2013-11-25 18:01:44 +0000 | [diff] [blame] | 3775 | wl_list_init(&shsurf->children_link); |
| 3776 | wl_list_init(&shsurf->children_list); |
| 3777 | shsurf->parent = NULL; |
| 3778 | |
Pekka Paalanen | b502654 | 2014-11-12 15:09:24 +0200 | [diff] [blame] | 3779 | set_type(shsurf, SHELL_SURFACE_NONE); |
Pekka Paalanen | 9d1613e | 2011-11-25 12:09:16 +0200 | [diff] [blame] | 3780 | |
Kristian Høgsberg | a61ca06 | 2012-05-22 16:05:52 -0400 | [diff] [blame] | 3781 | shsurf->client = client; |
| 3782 | |
Kristian Høgsberg | 45ba869 | 2012-05-21 14:27:33 -0400 | [diff] [blame] | 3783 | return shsurf; |
Tiago Vignatti | bc052c9 | 2012-04-19 16:18:18 +0300 | [diff] [blame] | 3784 | } |
| 3785 | |
Rafael Antognolli | e2a3455 | 2013-12-03 15:35:45 -0200 | [diff] [blame] | 3786 | static struct shell_surface * |
| 3787 | create_shell_surface(void *shell, struct weston_surface *surface, |
| 3788 | const struct weston_shell_client *client) |
| 3789 | { |
Jason Ekstrand | 9e9512f | 2014-04-16 21:12:10 -0500 | [diff] [blame] | 3790 | return create_common_surface(NULL, shell, surface, client); |
Rafael Antognolli | e2a3455 | 2013-12-03 15:35:45 -0200 | [diff] [blame] | 3791 | } |
| 3792 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 3793 | static struct weston_view * |
| 3794 | get_primary_view(void *shell, struct shell_surface *shsurf) |
| 3795 | { |
| 3796 | return shsurf->view; |
| 3797 | } |
| 3798 | |
Tiago Vignatti | bc052c9 | 2012-04-19 16:18:18 +0300 | [diff] [blame] | 3799 | static void |
| 3800 | shell_get_shell_surface(struct wl_client *client, |
| 3801 | struct wl_resource *resource, |
| 3802 | uint32_t id, |
| 3803 | struct wl_resource *surface_resource) |
| 3804 | { |
Jason Ekstrand | 0f2ef7e | 2013-06-14 10:07:53 -0500 | [diff] [blame] | 3805 | struct weston_surface *surface = |
| 3806 | wl_resource_get_user_data(surface_resource); |
Jason Ekstrand | 9e9512f | 2014-04-16 21:12:10 -0500 | [diff] [blame] | 3807 | struct shell_client *sc = wl_resource_get_user_data(resource); |
| 3808 | struct desktop_shell *shell = sc->shell; |
Tiago Vignatti | bc052c9 | 2012-04-19 16:18:18 +0300 | [diff] [blame] | 3809 | struct shell_surface *shsurf; |
| 3810 | |
Pekka Paalanen | 50b6747 | 2014-10-01 15:02:41 +0300 | [diff] [blame] | 3811 | if (weston_surface_set_role(surface, "wl_shell_surface", |
| 3812 | resource, WL_SHELL_ERROR_ROLE) < 0) |
Tiago Vignatti | bc052c9 | 2012-04-19 16:18:18 +0300 | [diff] [blame] | 3813 | return; |
Tiago Vignatti | bc052c9 | 2012-04-19 16:18:18 +0300 | [diff] [blame] | 3814 | |
Jason Ekstrand | 9e9512f | 2014-04-16 21:12:10 -0500 | [diff] [blame] | 3815 | shsurf = create_common_surface(sc, shell, surface, &shell_client); |
Kristian Høgsberg | 9540ea6 | 2012-05-21 14:28:57 -0400 | [diff] [blame] | 3816 | if (!shsurf) { |
Pekka Paalanen | 50b6747 | 2014-10-01 15:02:41 +0300 | [diff] [blame] | 3817 | wl_resource_post_no_memory(surface_resource); |
Kristian Høgsberg | 9540ea6 | 2012-05-21 14:28:57 -0400 | [diff] [blame] | 3818 | return; |
| 3819 | } |
Tiago Vignatti | bc052c9 | 2012-04-19 16:18:18 +0300 | [diff] [blame] | 3820 | |
Jason Ekstrand | a85118c | 2013-06-27 20:17:02 -0500 | [diff] [blame] | 3821 | shsurf->resource = |
| 3822 | wl_resource_create(client, |
| 3823 | &wl_shell_surface_interface, 1, id); |
| 3824 | wl_resource_set_implementation(shsurf->resource, |
| 3825 | &shell_surface_implementation, |
| 3826 | shsurf, shell_destroy_shell_surface); |
Jonas Ådahl | 49d77d2 | 2015-03-18 16:20:51 +0800 | [diff] [blame] | 3827 | wl_list_init(wl_resource_get_link(shsurf->resource)); |
Pekka Paalanen | 9d1613e | 2011-11-25 12:09:16 +0200 | [diff] [blame] | 3828 | } |
| 3829 | |
Rafael Antognolli | e2a3455 | 2013-12-03 15:35:45 -0200 | [diff] [blame] | 3830 | static bool |
| 3831 | shell_surface_is_wl_shell_surface(struct shell_surface *shsurf) |
| 3832 | { |
Kristian Høgsberg | 0b7d995 | 2014-02-03 15:50:38 -0800 | [diff] [blame] | 3833 | /* A shell surface without a resource is created from xwayland |
| 3834 | * and is considered a wl_shell surface for now. */ |
| 3835 | |
| 3836 | return shsurf->resource == NULL || |
| 3837 | wl_resource_instance_of(shsurf->resource, |
| 3838 | &wl_shell_surface_interface, |
| 3839 | &shell_surface_implementation); |
Rafael Antognolli | e2a3455 | 2013-12-03 15:35:45 -0200 | [diff] [blame] | 3840 | } |
| 3841 | |
Pekka Paalanen | 9d1613e | 2011-11-25 12:09:16 +0200 | [diff] [blame] | 3842 | static const struct wl_shell_interface shell_implementation = { |
Pekka Paalanen | 4622967 | 2011-11-29 15:49:31 +0200 | [diff] [blame] | 3843 | shell_get_shell_surface |
Kristian Høgsberg | 4cca349 | 2011-01-18 07:53:49 -0500 | [diff] [blame] | 3844 | }; |
| 3845 | |
Rafael Antognolli | e2a3455 | 2013-12-03 15:35:45 -0200 | [diff] [blame] | 3846 | /**************************** |
| 3847 | * xdg-shell implementation */ |
| 3848 | |
| 3849 | static void |
| 3850 | xdg_surface_destroy(struct wl_client *client, |
| 3851 | struct wl_resource *resource) |
| 3852 | { |
| 3853 | wl_resource_destroy(resource); |
| 3854 | } |
| 3855 | |
| 3856 | static void |
Jasper St. Pierre | c815d62 | 2014-04-10 18:37:54 -0700 | [diff] [blame] | 3857 | xdg_surface_set_parent(struct wl_client *client, |
| 3858 | struct wl_resource *resource, |
| 3859 | struct wl_resource *parent_resource) |
Jasper St. Pierre | 63a9c33 | 2014-02-01 18:35:15 -0500 | [diff] [blame] | 3860 | { |
| 3861 | struct shell_surface *shsurf = wl_resource_get_user_data(resource); |
Jasper St. Pierre | 66bc949 | 2015-02-13 14:01:55 +0800 | [diff] [blame] | 3862 | struct shell_surface *parent; |
Jasper St. Pierre | 63a9c33 | 2014-02-01 18:35:15 -0500 | [diff] [blame] | 3863 | |
Jasper St. Pierre | 66bc949 | 2015-02-13 14:01:55 +0800 | [diff] [blame] | 3864 | if (parent_resource) { |
Jasper St. Pierre | 63a9c33 | 2014-02-01 18:35:15 -0500 | [diff] [blame] | 3865 | parent = wl_resource_get_user_data(parent_resource); |
Jasper St. Pierre | 66bc949 | 2015-02-13 14:01:55 +0800 | [diff] [blame] | 3866 | shell_surface_set_parent(shsurf, parent->surface); |
| 3867 | } else { |
| 3868 | shell_surface_set_parent(shsurf, NULL); |
| 3869 | } |
Jasper St. Pierre | 63a9c33 | 2014-02-01 18:35:15 -0500 | [diff] [blame] | 3870 | } |
| 3871 | |
| 3872 | static void |
Rafael Antognolli | e2a3455 | 2013-12-03 15:35:45 -0200 | [diff] [blame] | 3873 | xdg_surface_set_app_id(struct wl_client *client, |
| 3874 | struct wl_resource *resource, |
| 3875 | const char *app_id) |
| 3876 | { |
| 3877 | struct shell_surface *shsurf = wl_resource_get_user_data(resource); |
| 3878 | |
| 3879 | free(shsurf->class); |
| 3880 | shsurf->class = strdup(app_id); |
Pekka Paalanen | b502654 | 2014-11-12 15:09:24 +0200 | [diff] [blame] | 3881 | shsurf->surface->timeline.force_refresh = 1; |
Rafael Antognolli | e2a3455 | 2013-12-03 15:35:45 -0200 | [diff] [blame] | 3882 | } |
| 3883 | |
| 3884 | static void |
Jasper St. Pierre | 81ff075 | 2014-03-13 11:04:53 -0400 | [diff] [blame] | 3885 | xdg_surface_show_window_menu(struct wl_client *client, |
| 3886 | struct wl_resource *surface_resource, |
| 3887 | struct wl_resource *seat_resource, |
| 3888 | uint32_t serial, |
| 3889 | int32_t x, |
| 3890 | int32_t y) |
| 3891 | { |
| 3892 | /* TODO */ |
| 3893 | } |
| 3894 | |
| 3895 | static void |
Rafael Antognolli | e2a3455 | 2013-12-03 15:35:45 -0200 | [diff] [blame] | 3896 | xdg_surface_set_title(struct wl_client *client, |
| 3897 | struct wl_resource *resource, const char *title) |
| 3898 | { |
| 3899 | struct shell_surface *shsurf = wl_resource_get_user_data(resource); |
| 3900 | |
| 3901 | set_title(shsurf, title); |
| 3902 | } |
| 3903 | |
| 3904 | static void |
| 3905 | xdg_surface_move(struct wl_client *client, struct wl_resource *resource, |
| 3906 | struct wl_resource *seat_resource, uint32_t serial) |
| 3907 | { |
| 3908 | common_surface_move(resource, seat_resource, serial); |
| 3909 | } |
| 3910 | |
| 3911 | static void |
| 3912 | xdg_surface_resize(struct wl_client *client, struct wl_resource *resource, |
| 3913 | struct wl_resource *seat_resource, uint32_t serial, |
| 3914 | uint32_t edges) |
| 3915 | { |
| 3916 | common_surface_resize(resource, seat_resource, serial, edges); |
| 3917 | } |
| 3918 | |
| 3919 | static void |
Jasper St. Pierre | ab2c108 | 2014-04-10 10:41:46 -0700 | [diff] [blame] | 3920 | xdg_surface_ack_configure(struct wl_client *client, |
| 3921 | struct wl_resource *resource, |
| 3922 | uint32_t serial) |
Rafael Antognolli | e2a3455 | 2013-12-03 15:35:45 -0200 | [diff] [blame] | 3923 | { |
| 3924 | struct shell_surface *shsurf = wl_resource_get_user_data(resource); |
| 3925 | |
Jasper St. Pierre | 8c6aa45 | 2014-02-08 18:29:49 -0500 | [diff] [blame] | 3926 | if (shsurf->state_requested) { |
| 3927 | shsurf->next_state = shsurf->requested_state; |
| 3928 | shsurf->state_changed = true; |
| 3929 | shsurf->state_requested = false; |
Rafael Antognolli | 3c4e3f7 | 2013-12-03 15:35:46 -0200 | [diff] [blame] | 3930 | } |
Rafael Antognolli | e2a3455 | 2013-12-03 15:35:45 -0200 | [diff] [blame] | 3931 | } |
| 3932 | |
Manuel Bachmann | 50c87db | 2014-02-26 15:52:13 +0100 | [diff] [blame] | 3933 | static void |
Jasper St. Pierre | ccf48fb | 2014-05-02 10:21:38 -0400 | [diff] [blame] | 3934 | xdg_surface_set_window_geometry(struct wl_client *client, |
| 3935 | struct wl_resource *resource, |
| 3936 | int32_t x, |
| 3937 | int32_t y, |
| 3938 | int32_t width, |
| 3939 | int32_t height) |
| 3940 | { |
| 3941 | struct shell_surface *shsurf = wl_resource_get_user_data(resource); |
| 3942 | |
| 3943 | set_window_geometry(shsurf, x, y, width, height); |
| 3944 | } |
| 3945 | |
| 3946 | static void |
Jasper St. Pierre | ab2c108 | 2014-04-10 10:41:46 -0700 | [diff] [blame] | 3947 | xdg_surface_set_maximized(struct wl_client *client, |
| 3948 | struct wl_resource *resource) |
| 3949 | { |
| 3950 | struct shell_surface *shsurf = wl_resource_get_user_data(resource); |
Marek Chalupa | bfbb64b | 2014-09-08 12:34:20 +0200 | [diff] [blame] | 3951 | struct weston_output *output; |
Jasper St. Pierre | ab2c108 | 2014-04-10 10:41:46 -0700 | [diff] [blame] | 3952 | |
| 3953 | shsurf->state_requested = true; |
| 3954 | shsurf->requested_state.maximized = true; |
Marek Chalupa | bfbb64b | 2014-09-08 12:34:20 +0200 | [diff] [blame] | 3955 | |
| 3956 | if (!weston_surface_is_mapped(shsurf->surface)) |
| 3957 | output = get_focused_output(shsurf->surface->compositor); |
| 3958 | else |
| 3959 | output = shsurf->surface->output; |
| 3960 | |
| 3961 | shell_surface_set_output(shsurf, output); |
Jasper St. Pierre | 9aa8ce6 | 2014-04-11 16:18:54 -0700 | [diff] [blame] | 3962 | send_configure_for_surface(shsurf); |
Jasper St. Pierre | ab2c108 | 2014-04-10 10:41:46 -0700 | [diff] [blame] | 3963 | } |
| 3964 | |
| 3965 | static void |
| 3966 | xdg_surface_unset_maximized(struct wl_client *client, |
| 3967 | struct wl_resource *resource) |
| 3968 | { |
| 3969 | struct shell_surface *shsurf = wl_resource_get_user_data(resource); |
| 3970 | |
| 3971 | shsurf->state_requested = true; |
| 3972 | shsurf->requested_state.maximized = false; |
Jasper St. Pierre | 6458ec3 | 2014-04-11 16:00:31 -0700 | [diff] [blame] | 3973 | send_configure_for_surface(shsurf); |
Jasper St. Pierre | ab2c108 | 2014-04-10 10:41:46 -0700 | [diff] [blame] | 3974 | } |
| 3975 | |
| 3976 | static void |
| 3977 | xdg_surface_set_fullscreen(struct wl_client *client, |
| 3978 | struct wl_resource *resource, |
| 3979 | struct wl_resource *output_resource) |
| 3980 | { |
| 3981 | struct shell_surface *shsurf = wl_resource_get_user_data(resource); |
| 3982 | struct weston_output *output; |
| 3983 | |
| 3984 | shsurf->state_requested = true; |
| 3985 | shsurf->requested_state.fullscreen = true; |
| 3986 | |
| 3987 | if (output_resource) |
| 3988 | output = wl_resource_get_user_data(output_resource); |
| 3989 | else |
| 3990 | output = NULL; |
| 3991 | |
Marek Chalupa | 052917a | 2014-09-02 11:35:12 +0200 | [diff] [blame] | 3992 | /* handle clients launching in fullscreen */ |
| 3993 | if (output == NULL && !weston_surface_is_mapped(shsurf->surface)) { |
| 3994 | /* Set the output to the one that has focus currently. */ |
| 3995 | assert(shsurf->surface); |
| 3996 | output = get_focused_output(shsurf->surface->compositor); |
| 3997 | } |
| 3998 | |
Jasper St. Pierre | 9aa8ce6 | 2014-04-11 16:18:54 -0700 | [diff] [blame] | 3999 | shell_surface_set_output(shsurf, output); |
| 4000 | shsurf->fullscreen_output = shsurf->output; |
Jasper St. Pierre | ab2c108 | 2014-04-10 10:41:46 -0700 | [diff] [blame] | 4001 | |
Jasper St. Pierre | 9aa8ce6 | 2014-04-11 16:18:54 -0700 | [diff] [blame] | 4002 | send_configure_for_surface(shsurf); |
Jasper St. Pierre | ab2c108 | 2014-04-10 10:41:46 -0700 | [diff] [blame] | 4003 | } |
| 4004 | |
| 4005 | static void |
| 4006 | xdg_surface_unset_fullscreen(struct wl_client *client, |
| 4007 | struct wl_resource *resource) |
| 4008 | { |
| 4009 | struct shell_surface *shsurf = wl_resource_get_user_data(resource); |
| 4010 | |
| 4011 | shsurf->state_requested = true; |
| 4012 | shsurf->requested_state.fullscreen = false; |
Jasper St. Pierre | 6458ec3 | 2014-04-11 16:00:31 -0700 | [diff] [blame] | 4013 | send_configure_for_surface(shsurf); |
Jasper St. Pierre | ab2c108 | 2014-04-10 10:41:46 -0700 | [diff] [blame] | 4014 | } |
| 4015 | |
| 4016 | static void |
Manuel Bachmann | 50c87db | 2014-02-26 15:52:13 +0100 | [diff] [blame] | 4017 | xdg_surface_set_minimized(struct wl_client *client, |
| 4018 | struct wl_resource *resource) |
| 4019 | { |
| 4020 | struct shell_surface *shsurf = wl_resource_get_user_data(resource); |
| 4021 | |
| 4022 | if (shsurf->type != SHELL_SURFACE_TOPLEVEL) |
| 4023 | return; |
| 4024 | |
| 4025 | /* apply compositor's own minimization logic (hide) */ |
Manuel Bachmann | dc1c3e4 | 2015-02-16 11:52:13 +0100 | [diff] [blame] | 4026 | set_minimized(shsurf->surface); |
Manuel Bachmann | 50c87db | 2014-02-26 15:52:13 +0100 | [diff] [blame] | 4027 | } |
| 4028 | |
Rafael Antognolli | e2a3455 | 2013-12-03 15:35:45 -0200 | [diff] [blame] | 4029 | static const struct xdg_surface_interface xdg_surface_implementation = { |
| 4030 | xdg_surface_destroy, |
Jasper St. Pierre | c815d62 | 2014-04-10 18:37:54 -0700 | [diff] [blame] | 4031 | xdg_surface_set_parent, |
Rafael Antognolli | e2a3455 | 2013-12-03 15:35:45 -0200 | [diff] [blame] | 4032 | xdg_surface_set_title, |
| 4033 | xdg_surface_set_app_id, |
Jasper St. Pierre | 81ff075 | 2014-03-13 11:04:53 -0400 | [diff] [blame] | 4034 | xdg_surface_show_window_menu, |
Rafael Antognolli | e2a3455 | 2013-12-03 15:35:45 -0200 | [diff] [blame] | 4035 | xdg_surface_move, |
| 4036 | xdg_surface_resize, |
Jasper St. Pierre | ab2c108 | 2014-04-10 10:41:46 -0700 | [diff] [blame] | 4037 | xdg_surface_ack_configure, |
Jasper St. Pierre | ccf48fb | 2014-05-02 10:21:38 -0400 | [diff] [blame] | 4038 | xdg_surface_set_window_geometry, |
Jasper St. Pierre | ab2c108 | 2014-04-10 10:41:46 -0700 | [diff] [blame] | 4039 | xdg_surface_set_maximized, |
| 4040 | xdg_surface_unset_maximized, |
| 4041 | xdg_surface_set_fullscreen, |
| 4042 | xdg_surface_unset_fullscreen, |
| 4043 | xdg_surface_set_minimized, |
Rafael Antognolli | e2a3455 | 2013-12-03 15:35:45 -0200 | [diff] [blame] | 4044 | }; |
| 4045 | |
| 4046 | static void |
| 4047 | xdg_send_configure(struct weston_surface *surface, |
Jasper St. Pierre | ac985be | 2014-04-28 11:19:28 -0400 | [diff] [blame] | 4048 | int32_t width, int32_t height) |
Rafael Antognolli | e2a3455 | 2013-12-03 15:35:45 -0200 | [diff] [blame] | 4049 | { |
| 4050 | struct shell_surface *shsurf = get_shell_surface(surface); |
Jasper St. Pierre | ab2c108 | 2014-04-10 10:41:46 -0700 | [diff] [blame] | 4051 | uint32_t *s; |
| 4052 | struct wl_array states; |
| 4053 | uint32_t serial; |
Rafael Antognolli | e2a3455 | 2013-12-03 15:35:45 -0200 | [diff] [blame] | 4054 | |
U. Artie Eoff | cf5737a | 2014-01-17 10:08:25 -0800 | [diff] [blame] | 4055 | assert(shsurf); |
| 4056 | |
Jasper St. Pierre | ab2c108 | 2014-04-10 10:41:46 -0700 | [diff] [blame] | 4057 | if (!shsurf->resource) |
| 4058 | return; |
| 4059 | |
| 4060 | wl_array_init(&states); |
| 4061 | if (shsurf->requested_state.fullscreen) { |
| 4062 | s = wl_array_add(&states, sizeof *s); |
| 4063 | *s = XDG_SURFACE_STATE_FULLSCREEN; |
| 4064 | } else if (shsurf->requested_state.maximized) { |
| 4065 | s = wl_array_add(&states, sizeof *s); |
| 4066 | *s = XDG_SURFACE_STATE_MAXIMIZED; |
| 4067 | } |
Jasper St. Pierre | 5befdda | 2014-05-06 08:50:47 -0400 | [diff] [blame] | 4068 | if (shsurf->resize_edges != 0) { |
| 4069 | s = wl_array_add(&states, sizeof *s); |
| 4070 | *s = XDG_SURFACE_STATE_RESIZING; |
| 4071 | } |
Jasper St. Pierre | 973d787 | 2014-05-06 08:44:29 -0400 | [diff] [blame] | 4072 | if (shsurf->focus_count > 0) { |
| 4073 | s = wl_array_add(&states, sizeof *s); |
| 4074 | *s = XDG_SURFACE_STATE_ACTIVATED; |
| 4075 | } |
Jasper St. Pierre | ab2c108 | 2014-04-10 10:41:46 -0700 | [diff] [blame] | 4076 | |
| 4077 | serial = wl_display_next_serial(shsurf->surface->compositor->wl_display); |
| 4078 | xdg_surface_send_configure(shsurf->resource, width, height, &states, serial); |
| 4079 | |
| 4080 | wl_array_release(&states); |
Rafael Antognolli | e2a3455 | 2013-12-03 15:35:45 -0200 | [diff] [blame] | 4081 | } |
| 4082 | |
| 4083 | static const struct weston_shell_client xdg_client = { |
| 4084 | xdg_send_configure |
| 4085 | }; |
| 4086 | |
| 4087 | static void |
Jasper St. Pierre | 084aa0b | 2015-02-13 14:02:00 +0800 | [diff] [blame] | 4088 | xdg_shell_destroy(struct wl_client *client, |
| 4089 | struct wl_resource *resource) |
| 4090 | { |
Jonas Ådahl | 49d77d2 | 2015-03-18 16:20:51 +0800 | [diff] [blame] | 4091 | struct shell_client *sc = wl_resource_get_user_data(resource); |
| 4092 | struct wl_resource *shsurf_resource; |
| 4093 | struct shell_surface *shsurf; |
| 4094 | |
| 4095 | wl_resource_for_each(shsurf_resource, &sc->surface_list) { |
| 4096 | shsurf = wl_resource_get_user_data(shsurf_resource); |
| 4097 | if (shsurf->owner_resource == resource) { |
| 4098 | wl_resource_post_error( |
| 4099 | resource, |
| 4100 | XDG_SHELL_ERROR_DEFUNCT_SURFACES, |
| 4101 | "not all child surface objects destroyed"); |
| 4102 | return; |
| 4103 | } |
| 4104 | } |
| 4105 | |
Jasper St. Pierre | 084aa0b | 2015-02-13 14:02:00 +0800 | [diff] [blame] | 4106 | wl_resource_destroy(resource); |
| 4107 | } |
| 4108 | |
| 4109 | static void |
Rafael Antognolli | e2a3455 | 2013-12-03 15:35:45 -0200 | [diff] [blame] | 4110 | xdg_use_unstable_version(struct wl_client *client, |
| 4111 | struct wl_resource *resource, |
| 4112 | int32_t version) |
| 4113 | { |
| 4114 | if (version > 1) { |
| 4115 | wl_resource_post_error(resource, |
| 4116 | 1, |
| 4117 | "xdg-shell:: version not implemented yet."); |
| 4118 | return; |
| 4119 | } |
| 4120 | } |
| 4121 | |
| 4122 | static struct shell_surface * |
Jason Ekstrand | 9e9512f | 2014-04-16 21:12:10 -0500 | [diff] [blame] | 4123 | create_xdg_surface(struct shell_client *owner, void *shell, |
| 4124 | struct weston_surface *surface, |
Rafael Antognolli | e2a3455 | 2013-12-03 15:35:45 -0200 | [diff] [blame] | 4125 | const struct weston_shell_client *client) |
| 4126 | { |
| 4127 | struct shell_surface *shsurf; |
Rafael Antognolli | e2a3455 | 2013-12-03 15:35:45 -0200 | [diff] [blame] | 4128 | |
Jason Ekstrand | 9e9512f | 2014-04-16 21:12:10 -0500 | [diff] [blame] | 4129 | shsurf = create_common_surface(owner, shell, surface, client); |
Pekka Paalanen | e972b27 | 2014-10-01 14:03:56 +0300 | [diff] [blame] | 4130 | if (!shsurf) |
| 4131 | return NULL; |
| 4132 | |
Pekka Paalanen | b502654 | 2014-11-12 15:09:24 +0200 | [diff] [blame] | 4133 | set_type(shsurf, SHELL_SURFACE_TOPLEVEL); |
Rafael Antognolli | e2a3455 | 2013-12-03 15:35:45 -0200 | [diff] [blame] | 4134 | |
| 4135 | return shsurf; |
| 4136 | } |
| 4137 | |
| 4138 | static void |
| 4139 | xdg_get_xdg_surface(struct wl_client *client, |
| 4140 | struct wl_resource *resource, |
| 4141 | uint32_t id, |
| 4142 | struct wl_resource *surface_resource) |
| 4143 | { |
| 4144 | struct weston_surface *surface = |
| 4145 | wl_resource_get_user_data(surface_resource); |
Kristian Høgsberg | 2bff94e | 2014-02-11 12:22:51 -0800 | [diff] [blame] | 4146 | struct shell_client *sc = wl_resource_get_user_data(resource); |
| 4147 | struct desktop_shell *shell = sc->shell; |
Rafael Antognolli | e2a3455 | 2013-12-03 15:35:45 -0200 | [diff] [blame] | 4148 | struct shell_surface *shsurf; |
| 4149 | |
Jonas Ådahl | bf48e21 | 2015-02-06 10:15:28 +0800 | [diff] [blame] | 4150 | shsurf = get_shell_surface(surface); |
| 4151 | if (shsurf && shell_surface_is_xdg_surface(shsurf)) { |
| 4152 | wl_resource_post_error(resource, XDG_SHELL_ERROR_ROLE, |
| 4153 | "This wl_surface is already an " |
| 4154 | "xdg_surface"); |
| 4155 | return; |
| 4156 | } |
| 4157 | |
Pekka Paalanen | 50b6747 | 2014-10-01 15:02:41 +0300 | [diff] [blame] | 4158 | if (weston_surface_set_role(surface, "xdg_surface", |
| 4159 | resource, XDG_SHELL_ERROR_ROLE) < 0) |
Rafael Antognolli | e2a3455 | 2013-12-03 15:35:45 -0200 | [diff] [blame] | 4160 | return; |
Rafael Antognolli | e2a3455 | 2013-12-03 15:35:45 -0200 | [diff] [blame] | 4161 | |
Jason Ekstrand | 9e9512f | 2014-04-16 21:12:10 -0500 | [diff] [blame] | 4162 | shsurf = create_xdg_surface(sc, shell, surface, &xdg_client); |
Rafael Antognolli | e2a3455 | 2013-12-03 15:35:45 -0200 | [diff] [blame] | 4163 | if (!shsurf) { |
Pekka Paalanen | 50b6747 | 2014-10-01 15:02:41 +0300 | [diff] [blame] | 4164 | wl_resource_post_no_memory(surface_resource); |
Rafael Antognolli | e2a3455 | 2013-12-03 15:35:45 -0200 | [diff] [blame] | 4165 | return; |
| 4166 | } |
| 4167 | |
| 4168 | shsurf->resource = |
| 4169 | wl_resource_create(client, |
| 4170 | &xdg_surface_interface, 1, id); |
| 4171 | wl_resource_set_implementation(shsurf->resource, |
| 4172 | &xdg_surface_implementation, |
| 4173 | shsurf, shell_destroy_shell_surface); |
Jonas Ådahl | 49d77d2 | 2015-03-18 16:20:51 +0800 | [diff] [blame] | 4174 | shsurf->owner_resource = resource; |
| 4175 | wl_list_insert(&sc->surface_list, |
| 4176 | wl_resource_get_link(shsurf->resource)); |
Rafael Antognolli | e2a3455 | 2013-12-03 15:35:45 -0200 | [diff] [blame] | 4177 | } |
| 4178 | |
| 4179 | static bool |
| 4180 | shell_surface_is_xdg_surface(struct shell_surface *shsurf) |
| 4181 | { |
Kristian Høgsberg | 0b7d995 | 2014-02-03 15:50:38 -0800 | [diff] [blame] | 4182 | return shsurf->resource && |
| 4183 | wl_resource_instance_of(shsurf->resource, |
| 4184 | &xdg_surface_interface, |
| 4185 | &xdg_surface_implementation); |
Rafael Antognolli | e2a3455 | 2013-12-03 15:35:45 -0200 | [diff] [blame] | 4186 | } |
| 4187 | |
| 4188 | /* xdg-popup implementation */ |
| 4189 | |
| 4190 | static void |
| 4191 | xdg_popup_destroy(struct wl_client *client, |
| 4192 | struct wl_resource *resource) |
| 4193 | { |
| 4194 | wl_resource_destroy(resource); |
| 4195 | } |
| 4196 | |
Rafael Antognolli | e2a3455 | 2013-12-03 15:35:45 -0200 | [diff] [blame] | 4197 | static const struct xdg_popup_interface xdg_popup_implementation = { |
| 4198 | xdg_popup_destroy, |
Rafael Antognolli | e2a3455 | 2013-12-03 15:35:45 -0200 | [diff] [blame] | 4199 | }; |
| 4200 | |
| 4201 | static void |
| 4202 | xdg_popup_send_configure(struct weston_surface *surface, |
Jasper St. Pierre | ac985be | 2014-04-28 11:19:28 -0400 | [diff] [blame] | 4203 | int32_t width, int32_t height) |
Rafael Antognolli | e2a3455 | 2013-12-03 15:35:45 -0200 | [diff] [blame] | 4204 | { |
| 4205 | } |
| 4206 | |
| 4207 | static const struct weston_shell_client xdg_popup_client = { |
| 4208 | xdg_popup_send_configure |
| 4209 | }; |
| 4210 | |
| 4211 | static struct shell_surface * |
Jason Ekstrand | 9e9512f | 2014-04-16 21:12:10 -0500 | [diff] [blame] | 4212 | create_xdg_popup(struct shell_client *owner, void *shell, |
| 4213 | struct weston_surface *surface, |
Rafael Antognolli | e2a3455 | 2013-12-03 15:35:45 -0200 | [diff] [blame] | 4214 | const struct weston_shell_client *client, |
| 4215 | struct weston_surface *parent, |
| 4216 | struct shell_seat *seat, |
| 4217 | uint32_t serial, |
| 4218 | int32_t x, int32_t y) |
| 4219 | { |
Jonas Ådahl | ee45a55 | 2015-03-18 16:37:47 +0800 | [diff] [blame] | 4220 | struct shell_surface *shsurf; |
Jonas Ådahl | 24185e2 | 2015-02-27 18:37:41 +0800 | [diff] [blame] | 4221 | |
Jason Ekstrand | 9e9512f | 2014-04-16 21:12:10 -0500 | [diff] [blame] | 4222 | shsurf = create_common_surface(owner, shell, surface, client); |
Pekka Paalanen | e972b27 | 2014-10-01 14:03:56 +0300 | [diff] [blame] | 4223 | if (!shsurf) |
| 4224 | return NULL; |
| 4225 | |
Pekka Paalanen | b502654 | 2014-11-12 15:09:24 +0200 | [diff] [blame] | 4226 | set_type(shsurf, SHELL_SURFACE_POPUP); |
Rafael Antognolli | e2a3455 | 2013-12-03 15:35:45 -0200 | [diff] [blame] | 4227 | shsurf->popup.shseat = seat; |
| 4228 | shsurf->popup.serial = serial; |
| 4229 | shsurf->popup.x = x; |
| 4230 | shsurf->popup.y = y; |
| 4231 | shell_surface_set_parent(shsurf, parent); |
| 4232 | |
| 4233 | return shsurf; |
| 4234 | } |
| 4235 | |
| 4236 | static void |
| 4237 | xdg_get_xdg_popup(struct wl_client *client, |
| 4238 | struct wl_resource *resource, |
| 4239 | uint32_t id, |
| 4240 | struct wl_resource *surface_resource, |
| 4241 | struct wl_resource *parent_resource, |
| 4242 | struct wl_resource *seat_resource, |
| 4243 | uint32_t serial, |
Jasper St. Pierre | 14f330c | 2015-02-13 14:01:57 +0800 | [diff] [blame] | 4244 | int32_t x, int32_t y) |
Rafael Antognolli | e2a3455 | 2013-12-03 15:35:45 -0200 | [diff] [blame] | 4245 | { |
| 4246 | struct weston_surface *surface = |
| 4247 | wl_resource_get_user_data(surface_resource); |
Kristian Høgsberg | 2bff94e | 2014-02-11 12:22:51 -0800 | [diff] [blame] | 4248 | struct shell_client *sc = wl_resource_get_user_data(resource); |
| 4249 | struct desktop_shell *shell = sc->shell; |
Rafael Antognolli | e2a3455 | 2013-12-03 15:35:45 -0200 | [diff] [blame] | 4250 | struct shell_surface *shsurf; |
Jonas Ådahl | ee45a55 | 2015-03-18 16:37:47 +0800 | [diff] [blame] | 4251 | struct shell_surface *parent_shsurf; |
Rafael Antognolli | e2a3455 | 2013-12-03 15:35:45 -0200 | [diff] [blame] | 4252 | struct weston_surface *parent; |
| 4253 | struct shell_seat *seat; |
| 4254 | |
Jonas Ådahl | bf48e21 | 2015-02-06 10:15:28 +0800 | [diff] [blame] | 4255 | shsurf = get_shell_surface(surface); |
| 4256 | if (shsurf && shell_surface_is_xdg_popup(shsurf)) { |
| 4257 | wl_resource_post_error(resource, XDG_SHELL_ERROR_ROLE, |
| 4258 | "This wl_surface is already an " |
| 4259 | "xdg_popup"); |
| 4260 | return; |
| 4261 | } |
| 4262 | |
Pekka Paalanen | 50b6747 | 2014-10-01 15:02:41 +0300 | [diff] [blame] | 4263 | if (weston_surface_set_role(surface, "xdg_popup", |
| 4264 | resource, XDG_SHELL_ERROR_ROLE) < 0) |
Rafael Antognolli | e2a3455 | 2013-12-03 15:35:45 -0200 | [diff] [blame] | 4265 | return; |
Rafael Antognolli | e2a3455 | 2013-12-03 15:35:45 -0200 | [diff] [blame] | 4266 | |
| 4267 | if (!parent_resource) { |
| 4268 | wl_resource_post_error(surface_resource, |
| 4269 | WL_DISPLAY_ERROR_INVALID_OBJECT, |
| 4270 | "xdg_shell::get_xdg_popup requires a parent shell surface"); |
Jasper St. Pierre | 666bc92 | 2014-08-07 16:43:13 -0400 | [diff] [blame] | 4271 | return; |
Rafael Antognolli | e2a3455 | 2013-12-03 15:35:45 -0200 | [diff] [blame] | 4272 | } |
| 4273 | |
| 4274 | parent = wl_resource_get_user_data(parent_resource); |
| 4275 | seat = get_shell_seat(wl_resource_get_user_data(seat_resource));; |
| 4276 | |
Jonas Ådahl | ee45a55 | 2015-03-18 16:37:47 +0800 | [diff] [blame] | 4277 | /* Verify that we are creating the top most popup when mapping, |
| 4278 | * as it's not until then we know whether it was mapped as most |
| 4279 | * top level or not. */ |
| 4280 | |
| 4281 | parent_shsurf = get_shell_surface(parent); |
| 4282 | if (!shell_surface_is_xdg_popup(parent_shsurf) && |
| 4283 | !shell_surface_is_xdg_surface(parent_shsurf)) { |
| 4284 | wl_resource_post_error(resource, |
| 4285 | XDG_SHELL_ERROR_INVALID_POPUP_PARENT, |
| 4286 | "xdg_popup parent was invalid"); |
| 4287 | return; |
| 4288 | } |
| 4289 | |
Jason Ekstrand | 9e9512f | 2014-04-16 21:12:10 -0500 | [diff] [blame] | 4290 | shsurf = create_xdg_popup(sc, shell, surface, &xdg_popup_client, |
Rafael Antognolli | e2a3455 | 2013-12-03 15:35:45 -0200 | [diff] [blame] | 4291 | parent, seat, serial, x, y); |
| 4292 | if (!shsurf) { |
Pekka Paalanen | 50b6747 | 2014-10-01 15:02:41 +0300 | [diff] [blame] | 4293 | wl_resource_post_no_memory(surface_resource); |
Rafael Antognolli | e2a3455 | 2013-12-03 15:35:45 -0200 | [diff] [blame] | 4294 | return; |
| 4295 | } |
| 4296 | |
| 4297 | shsurf->resource = |
| 4298 | wl_resource_create(client, |
| 4299 | &xdg_popup_interface, 1, id); |
| 4300 | wl_resource_set_implementation(shsurf->resource, |
| 4301 | &xdg_popup_implementation, |
| 4302 | shsurf, shell_destroy_shell_surface); |
Jonas Ådahl | 49d77d2 | 2015-03-18 16:20:51 +0800 | [diff] [blame] | 4303 | shsurf->owner_resource = resource; |
| 4304 | wl_list_insert(&sc->surface_list, |
| 4305 | wl_resource_get_link(shsurf->resource)); |
Rafael Antognolli | e2a3455 | 2013-12-03 15:35:45 -0200 | [diff] [blame] | 4306 | } |
| 4307 | |
Kristian Høgsberg | 2bff94e | 2014-02-11 12:22:51 -0800 | [diff] [blame] | 4308 | static void |
| 4309 | xdg_pong(struct wl_client *client, |
| 4310 | struct wl_resource *resource, uint32_t serial) |
| 4311 | { |
| 4312 | struct shell_client *sc = wl_resource_get_user_data(resource); |
Kristian Høgsberg | 2bff94e | 2014-02-11 12:22:51 -0800 | [diff] [blame] | 4313 | |
Kristian Høgsberg | dd62aba | 2014-02-12 09:56:19 -0800 | [diff] [blame] | 4314 | shell_client_pong(sc, serial); |
Kristian Høgsberg | 2bff94e | 2014-02-11 12:22:51 -0800 | [diff] [blame] | 4315 | } |
| 4316 | |
Rafael Antognolli | e2a3455 | 2013-12-03 15:35:45 -0200 | [diff] [blame] | 4317 | static bool |
| 4318 | shell_surface_is_xdg_popup(struct shell_surface *shsurf) |
| 4319 | { |
| 4320 | return wl_resource_instance_of(shsurf->resource, |
| 4321 | &xdg_popup_interface, |
| 4322 | &xdg_popup_implementation); |
| 4323 | } |
| 4324 | |
| 4325 | static const struct xdg_shell_interface xdg_implementation = { |
Jasper St. Pierre | 084aa0b | 2015-02-13 14:02:00 +0800 | [diff] [blame] | 4326 | xdg_shell_destroy, |
Rafael Antognolli | e2a3455 | 2013-12-03 15:35:45 -0200 | [diff] [blame] | 4327 | xdg_use_unstable_version, |
| 4328 | xdg_get_xdg_surface, |
Kristian Høgsberg | 2bff94e | 2014-02-11 12:22:51 -0800 | [diff] [blame] | 4329 | xdg_get_xdg_popup, |
| 4330 | xdg_pong |
Rafael Antognolli | e2a3455 | 2013-12-03 15:35:45 -0200 | [diff] [blame] | 4331 | }; |
| 4332 | |
| 4333 | static int |
| 4334 | xdg_shell_unversioned_dispatch(const void *implementation, |
| 4335 | void *_target, uint32_t opcode, |
| 4336 | const struct wl_message *message, |
| 4337 | union wl_argument *args) |
| 4338 | { |
| 4339 | struct wl_resource *resource = _target; |
Kristian Høgsberg | 2bff94e | 2014-02-11 12:22:51 -0800 | [diff] [blame] | 4340 | struct shell_client *sc = wl_resource_get_user_data(resource); |
Rafael Antognolli | e2a3455 | 2013-12-03 15:35:45 -0200 | [diff] [blame] | 4341 | |
Jasper St. Pierre | 084aa0b | 2015-02-13 14:02:00 +0800 | [diff] [blame] | 4342 | if (opcode != 1 /* XDG_SHELL_USE_UNSTABLE_VERSION */) { |
Rafael Antognolli | e2a3455 | 2013-12-03 15:35:45 -0200 | [diff] [blame] | 4343 | wl_resource_post_error(resource, |
| 4344 | WL_DISPLAY_ERROR_INVALID_OBJECT, |
| 4345 | "must call use_unstable_version first"); |
| 4346 | return 0; |
| 4347 | } |
| 4348 | |
Jasper St. Pierre | 5ba1e1d | 2015-02-13 14:02:02 +0800 | [diff] [blame] | 4349 | #define XDG_SERVER_VERSION 5 |
Rafael Antognolli | e2a3455 | 2013-12-03 15:35:45 -0200 | [diff] [blame] | 4350 | |
Kristian Høgsberg | 8d344a0 | 2013-12-08 22:27:11 -0800 | [diff] [blame] | 4351 | static_assert(XDG_SERVER_VERSION == XDG_SHELL_VERSION_CURRENT, |
| 4352 | "shell implementation doesn't match protocol version"); |
| 4353 | |
Rafael Antognolli | e2a3455 | 2013-12-03 15:35:45 -0200 | [diff] [blame] | 4354 | if (args[0].i != XDG_SERVER_VERSION) { |
| 4355 | wl_resource_post_error(resource, |
| 4356 | WL_DISPLAY_ERROR_INVALID_OBJECT, |
| 4357 | "incompatible version, server is %d " |
| 4358 | "client wants %d", |
| 4359 | XDG_SERVER_VERSION, args[0].i); |
| 4360 | return 0; |
| 4361 | } |
| 4362 | |
| 4363 | wl_resource_set_implementation(resource, &xdg_implementation, |
Kristian Høgsberg | 2bff94e | 2014-02-11 12:22:51 -0800 | [diff] [blame] | 4364 | sc, NULL); |
Rafael Antognolli | e2a3455 | 2013-12-03 15:35:45 -0200 | [diff] [blame] | 4365 | |
| 4366 | return 1; |
| 4367 | } |
| 4368 | |
| 4369 | /* end of xdg-shell implementation */ |
| 4370 | /***********************************/ |
| 4371 | |
Kristian Høgsberg | 0793756 | 2011-04-12 17:25:42 -0400 | [diff] [blame] | 4372 | static void |
Ander Conselvan de Oliveira | 859e885 | 2013-02-21 18:35:21 +0200 | [diff] [blame] | 4373 | shell_fade(struct desktop_shell *shell, enum fade_type type); |
| 4374 | |
Pekka Paalanen | 77346a6 | 2011-11-30 16:26:35 +0200 | [diff] [blame] | 4375 | static void |
Jason Ekstrand | 918f2dd | 2013-12-02 21:01:53 -0600 | [diff] [blame] | 4376 | configure_static_view(struct weston_view *ev, struct weston_layer *layer) |
Kristian Høgsberg | 962342c | 2012-06-26 16:29:50 -0400 | [diff] [blame] | 4377 | { |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 4378 | struct weston_view *v, *next; |
Kristian Høgsberg | 962342c | 2012-06-26 16:29:50 -0400 | [diff] [blame] | 4379 | |
Giulio Camuffo | 412e6a5 | 2014-07-09 22:12:56 +0300 | [diff] [blame] | 4380 | 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] | 4381 | if (v->output == ev->output && v != ev) { |
| 4382 | weston_view_unmap(v); |
| 4383 | v->surface->configure = NULL; |
Pekka Paalanen | 8274d90 | 2014-08-06 19:36:51 +0300 | [diff] [blame] | 4384 | weston_surface_set_label_func(v->surface, NULL); |
Kristian Høgsberg | 962342c | 2012-06-26 16:29:50 -0400 | [diff] [blame] | 4385 | } |
| 4386 | } |
| 4387 | |
Jason Ekstrand | 918f2dd | 2013-12-02 21:01:53 -0600 | [diff] [blame] | 4388 | weston_view_set_position(ev, ev->output->x, ev->output->y); |
Kristian Høgsberg | 962342c | 2012-06-26 16:29:50 -0400 | [diff] [blame] | 4389 | |
Giulio Camuffo | 412e6a5 | 2014-07-09 22:12:56 +0300 | [diff] [blame] | 4390 | if (wl_list_empty(&ev->layer_link.link)) { |
| 4391 | weston_layer_entry_insert(&layer->view_list, &ev->layer_link); |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 4392 | weston_compositor_schedule_repaint(ev->surface->compositor); |
Kristian Høgsberg | 962342c | 2012-06-26 16:29:50 -0400 | [diff] [blame] | 4393 | } |
| 4394 | } |
| 4395 | |
Pekka Paalanen | 8274d90 | 2014-08-06 19:36:51 +0300 | [diff] [blame] | 4396 | static int |
| 4397 | background_get_label(struct weston_surface *surface, char *buf, size_t len) |
| 4398 | { |
| 4399 | return snprintf(buf, len, "background for output %s", |
| 4400 | surface->output->name); |
| 4401 | } |
| 4402 | |
Kristian Høgsberg | 962342c | 2012-06-26 16:29:50 -0400 | [diff] [blame] | 4403 | static void |
Jason Ekstrand | 918f2dd | 2013-12-02 21:01:53 -0600 | [diff] [blame] | 4404 | 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] | 4405 | { |
Giulio Camuffo | 7fe01b1 | 2013-03-28 18:02:42 +0100 | [diff] [blame] | 4406 | struct desktop_shell *shell = es->configure_private; |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 4407 | struct weston_view *view; |
Kristian Høgsberg | af7b1ff | 2012-06-26 21:19:23 -0400 | [diff] [blame] | 4408 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 4409 | view = container_of(es->views.next, struct weston_view, surface_link); |
| 4410 | |
Jason Ekstrand | 918f2dd | 2013-12-02 21:01:53 -0600 | [diff] [blame] | 4411 | configure_static_view(view, &shell->background_layer); |
Kristian Høgsberg | af7b1ff | 2012-06-26 21:19:23 -0400 | [diff] [blame] | 4412 | } |
| 4413 | |
| 4414 | static void |
Kristian Høgsberg | 7584062 | 2011-09-06 13:48:16 -0400 | [diff] [blame] | 4415 | desktop_shell_set_background(struct wl_client *client, |
| 4416 | struct wl_resource *resource, |
Benjamin Franzke | d0f79ab | 2011-11-22 12:43:52 +0100 | [diff] [blame] | 4417 | struct wl_resource *output_resource, |
Kristian Høgsberg | 7584062 | 2011-09-06 13:48:16 -0400 | [diff] [blame] | 4418 | struct wl_resource *surface_resource) |
| 4419 | { |
Jason Ekstrand | 651f00e | 2013-06-14 10:07:54 -0500 | [diff] [blame] | 4420 | struct desktop_shell *shell = wl_resource_get_user_data(resource); |
Jason Ekstrand | 0f2ef7e | 2013-06-14 10:07:53 -0500 | [diff] [blame] | 4421 | struct weston_surface *surface = |
| 4422 | wl_resource_get_user_data(surface_resource); |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 4423 | struct weston_view *view, *next; |
Kristian Høgsberg | 7584062 | 2011-09-06 13:48:16 -0400 | [diff] [blame] | 4424 | |
Kristian Høgsberg | 962342c | 2012-06-26 16:29:50 -0400 | [diff] [blame] | 4425 | if (surface->configure) { |
| 4426 | wl_resource_post_error(surface_resource, |
| 4427 | WL_DISPLAY_ERROR_INVALID_OBJECT, |
| 4428 | "surface role already assigned"); |
| 4429 | return; |
| 4430 | } |
Benjamin Franzke | d0f79ab | 2011-11-22 12:43:52 +0100 | [diff] [blame] | 4431 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 4432 | wl_list_for_each_safe(view, next, &surface->views, surface_link) |
| 4433 | weston_view_destroy(view); |
| 4434 | view = weston_view_create(surface); |
| 4435 | |
Kristian Høgsberg | 962342c | 2012-06-26 16:29:50 -0400 | [diff] [blame] | 4436 | surface->configure = background_configure; |
Giulio Camuffo | 7fe01b1 | 2013-03-28 18:02:42 +0100 | [diff] [blame] | 4437 | surface->configure_private = shell; |
Pekka Paalanen | 8274d90 | 2014-08-06 19:36:51 +0300 | [diff] [blame] | 4438 | weston_surface_set_label_func(surface, background_get_label); |
Jason Ekstrand | a0d2dde | 2013-06-14 10:08:01 -0500 | [diff] [blame] | 4439 | surface->output = wl_resource_get_user_data(output_resource); |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 4440 | view->output = surface->output; |
Kristian Høgsberg | eae5de7 | 2012-04-11 22:42:15 -0400 | [diff] [blame] | 4441 | desktop_shell_send_configure(resource, 0, |
Kristian Høgsberg | 0b5cd0c | 2012-03-04 21:57:37 -0500 | [diff] [blame] | 4442 | surface_resource, |
Scott Moreau | 1bad5db | 2012-08-18 01:04:05 -0600 | [diff] [blame] | 4443 | surface->output->width, |
| 4444 | surface->output->height); |
Kristian Høgsberg | 7584062 | 2011-09-06 13:48:16 -0400 | [diff] [blame] | 4445 | } |
| 4446 | |
Pekka Paalanen | 8274d90 | 2014-08-06 19:36:51 +0300 | [diff] [blame] | 4447 | static int |
| 4448 | panel_get_label(struct weston_surface *surface, char *buf, size_t len) |
| 4449 | { |
| 4450 | return snprintf(buf, len, "panel for output %s", |
| 4451 | surface->output->name); |
| 4452 | } |
| 4453 | |
Kristian Høgsberg | 7584062 | 2011-09-06 13:48:16 -0400 | [diff] [blame] | 4454 | static void |
Jason Ekstrand | 918f2dd | 2013-12-02 21:01:53 -0600 | [diff] [blame] | 4455 | 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] | 4456 | { |
Giulio Camuffo | 7fe01b1 | 2013-03-28 18:02:42 +0100 | [diff] [blame] | 4457 | struct desktop_shell *shell = es->configure_private; |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 4458 | struct weston_view *view; |
Kristian Høgsberg | af7b1ff | 2012-06-26 21:19:23 -0400 | [diff] [blame] | 4459 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 4460 | view = container_of(es->views.next, struct weston_view, surface_link); |
| 4461 | |
Jason Ekstrand | 918f2dd | 2013-12-02 21:01:53 -0600 | [diff] [blame] | 4462 | configure_static_view(view, &shell->panel_layer); |
Kristian Høgsberg | af7b1ff | 2012-06-26 21:19:23 -0400 | [diff] [blame] | 4463 | } |
| 4464 | |
| 4465 | static void |
Kristian Høgsberg | 7584062 | 2011-09-06 13:48:16 -0400 | [diff] [blame] | 4466 | desktop_shell_set_panel(struct wl_client *client, |
| 4467 | struct wl_resource *resource, |
Benjamin Franzke | d0f79ab | 2011-11-22 12:43:52 +0100 | [diff] [blame] | 4468 | struct wl_resource *output_resource, |
Kristian Høgsberg | 7584062 | 2011-09-06 13:48:16 -0400 | [diff] [blame] | 4469 | struct wl_resource *surface_resource) |
| 4470 | { |
Jason Ekstrand | 651f00e | 2013-06-14 10:07:54 -0500 | [diff] [blame] | 4471 | struct desktop_shell *shell = wl_resource_get_user_data(resource); |
Jason Ekstrand | 0f2ef7e | 2013-06-14 10:07:53 -0500 | [diff] [blame] | 4472 | struct weston_surface *surface = |
| 4473 | wl_resource_get_user_data(surface_resource); |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 4474 | struct weston_view *view, *next; |
Kristian Høgsberg | 7584062 | 2011-09-06 13:48:16 -0400 | [diff] [blame] | 4475 | |
Kristian Høgsberg | af7b1ff | 2012-06-26 21:19:23 -0400 | [diff] [blame] | 4476 | if (surface->configure) { |
| 4477 | wl_resource_post_error(surface_resource, |
| 4478 | WL_DISPLAY_ERROR_INVALID_OBJECT, |
| 4479 | "surface role already assigned"); |
| 4480 | return; |
| 4481 | } |
Benjamin Franzke | d0f79ab | 2011-11-22 12:43:52 +0100 | [diff] [blame] | 4482 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 4483 | wl_list_for_each_safe(view, next, &surface->views, surface_link) |
| 4484 | weston_view_destroy(view); |
| 4485 | view = weston_view_create(surface); |
| 4486 | |
Kristian Høgsberg | af7b1ff | 2012-06-26 21:19:23 -0400 | [diff] [blame] | 4487 | surface->configure = panel_configure; |
Giulio Camuffo | 7fe01b1 | 2013-03-28 18:02:42 +0100 | [diff] [blame] | 4488 | surface->configure_private = shell; |
Pekka Paalanen | 8274d90 | 2014-08-06 19:36:51 +0300 | [diff] [blame] | 4489 | weston_surface_set_label_func(surface, panel_get_label); |
Jason Ekstrand | a0d2dde | 2013-06-14 10:08:01 -0500 | [diff] [blame] | 4490 | surface->output = wl_resource_get_user_data(output_resource); |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 4491 | view->output = surface->output; |
Kristian Høgsberg | eae5de7 | 2012-04-11 22:42:15 -0400 | [diff] [blame] | 4492 | desktop_shell_send_configure(resource, 0, |
Kristian Høgsberg | af7b1ff | 2012-06-26 21:19:23 -0400 | [diff] [blame] | 4493 | surface_resource, |
Scott Moreau | 1bad5db | 2012-08-18 01:04:05 -0600 | [diff] [blame] | 4494 | surface->output->width, |
| 4495 | surface->output->height); |
Kristian Høgsberg | 7584062 | 2011-09-06 13:48:16 -0400 | [diff] [blame] | 4496 | } |
| 4497 | |
Pekka Paalanen | 8274d90 | 2014-08-06 19:36:51 +0300 | [diff] [blame] | 4498 | static int |
| 4499 | lock_surface_get_label(struct weston_surface *surface, char *buf, size_t len) |
| 4500 | { |
| 4501 | return snprintf(buf, len, "lock window"); |
| 4502 | } |
| 4503 | |
Pekka Paalanen | 9ef3e01 | 2011-11-15 13:34:48 +0200 | [diff] [blame] | 4504 | static void |
Jason Ekstrand | 918f2dd | 2013-12-02 21:01:53 -0600 | [diff] [blame] | 4505 | 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] | 4506 | { |
Giulio Camuffo | 7fe01b1 | 2013-03-28 18:02:42 +0100 | [diff] [blame] | 4507 | struct desktop_shell *shell = surface->configure_private; |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 4508 | struct weston_view *view; |
| 4509 | |
| 4510 | view = container_of(surface->views.next, struct weston_view, surface_link); |
Kristian Høgsberg | 730c94d | 2012-06-26 21:44:35 -0400 | [diff] [blame] | 4511 | |
Jason Ekstrand | 918f2dd | 2013-12-02 21:01:53 -0600 | [diff] [blame] | 4512 | if (surface->width == 0) |
Giulio Camuffo | 184df50 | 2013-02-21 11:29:21 +0100 | [diff] [blame] | 4513 | return; |
| 4514 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 4515 | center_on_output(view, get_default_output(shell->compositor)); |
Kristian Høgsberg | 730c94d | 2012-06-26 21:44:35 -0400 | [diff] [blame] | 4516 | |
| 4517 | if (!weston_surface_is_mapped(surface)) { |
Giulio Camuffo | 412e6a5 | 2014-07-09 22:12:56 +0300 | [diff] [blame] | 4518 | weston_layer_entry_insert(&shell->lock_layer.view_list, |
| 4519 | &view->layer_link); |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 4520 | weston_view_update_transform(view); |
Ander Conselvan de Oliveira | 87524b6 | 2013-02-21 18:35:22 +0200 | [diff] [blame] | 4521 | shell_fade(shell, FADE_IN); |
Kristian Høgsberg | 730c94d | 2012-06-26 21:44:35 -0400 | [diff] [blame] | 4522 | } |
| 4523 | } |
| 4524 | |
| 4525 | static void |
Kristian Høgsberg | 27e3052 | 2012-04-11 23:18:23 -0400 | [diff] [blame] | 4526 | handle_lock_surface_destroy(struct wl_listener *listener, void *data) |
Kristian Høgsberg | 1ec0c31 | 2011-11-15 16:39:55 -0500 | [diff] [blame] | 4527 | { |
Tiago Vignatti | be14326 | 2012-04-16 17:31:41 +0300 | [diff] [blame] | 4528 | struct desktop_shell *shell = |
| 4529 | container_of(listener, struct desktop_shell, lock_surface_listener); |
Kristian Høgsberg | 1ec0c31 | 2011-11-15 16:39:55 -0500 | [diff] [blame] | 4530 | |
Martin Minarik | 6d11836 | 2012-06-07 18:01:59 +0200 | [diff] [blame] | 4531 | weston_log("lock surface gone\n"); |
Kristian Høgsberg | 1ec0c31 | 2011-11-15 16:39:55 -0500 | [diff] [blame] | 4532 | shell->lock_surface = NULL; |
| 4533 | } |
| 4534 | |
| 4535 | static void |
Pekka Paalanen | 9ef3e01 | 2011-11-15 13:34:48 +0200 | [diff] [blame] | 4536 | desktop_shell_set_lock_surface(struct wl_client *client, |
| 4537 | struct wl_resource *resource, |
| 4538 | struct wl_resource *surface_resource) |
| 4539 | { |
Jason Ekstrand | 651f00e | 2013-06-14 10:07:54 -0500 | [diff] [blame] | 4540 | struct desktop_shell *shell = wl_resource_get_user_data(resource); |
Jason Ekstrand | 0f2ef7e | 2013-06-14 10:07:53 -0500 | [diff] [blame] | 4541 | struct weston_surface *surface = |
| 4542 | wl_resource_get_user_data(surface_resource); |
Pekka Paalanen | 9826223 | 2011-12-01 10:42:22 +0200 | [diff] [blame] | 4543 | |
Pekka Paalanen | f0fc70d | 2011-11-15 13:34:54 +0200 | [diff] [blame] | 4544 | shell->prepare_event_sent = false; |
Kristian Høgsberg | af867cc | 2011-11-15 13:34:49 +0200 | [diff] [blame] | 4545 | |
Pekka Paalanen | f0fc70d | 2011-11-15 13:34:54 +0200 | [diff] [blame] | 4546 | if (!shell->locked) |
| 4547 | return; |
| 4548 | |
Pekka Paalanen | 9826223 | 2011-12-01 10:42:22 +0200 | [diff] [blame] | 4549 | shell->lock_surface = surface; |
Pekka Paalanen | f0fc70d | 2011-11-15 13:34:54 +0200 | [diff] [blame] | 4550 | |
Kristian Høgsberg | 27e3052 | 2012-04-11 23:18:23 -0400 | [diff] [blame] | 4551 | shell->lock_surface_listener.notify = handle_lock_surface_destroy; |
Jason Ekstrand | 651f00e | 2013-06-14 10:07:54 -0500 | [diff] [blame] | 4552 | wl_signal_add(&surface->destroy_signal, |
Kristian Høgsberg | 27e3052 | 2012-04-11 23:18:23 -0400 | [diff] [blame] | 4553 | &shell->lock_surface_listener); |
Pekka Paalanen | 57da4a8 | 2011-11-23 16:42:16 +0200 | [diff] [blame] | 4554 | |
Kristian Høgsberg | aa2ee8b | 2013-10-30 15:49:45 -0700 | [diff] [blame] | 4555 | weston_view_create(surface); |
Kristian Høgsberg | 730c94d | 2012-06-26 21:44:35 -0400 | [diff] [blame] | 4556 | surface->configure = lock_surface_configure; |
Giulio Camuffo | 7fe01b1 | 2013-03-28 18:02:42 +0100 | [diff] [blame] | 4557 | surface->configure_private = shell; |
Pekka Paalanen | 8274d90 | 2014-08-06 19:36:51 +0300 | [diff] [blame] | 4558 | weston_surface_set_label_func(surface, lock_surface_get_label); |
Pekka Paalanen | f0fc70d | 2011-11-15 13:34:54 +0200 | [diff] [blame] | 4559 | } |
| 4560 | |
| 4561 | static void |
Tiago Vignatti | be14326 | 2012-04-16 17:31:41 +0300 | [diff] [blame] | 4562 | resume_desktop(struct desktop_shell *shell) |
Pekka Paalanen | f0fc70d | 2011-11-15 13:34:54 +0200 | [diff] [blame] | 4563 | { |
Kristian Høgsberg | 4476aaf | 2012-06-25 14:03:13 -0400 | [diff] [blame] | 4564 | struct workspace *ws = get_current_workspace(shell); |
Pekka Paalanen | 77346a6 | 2011-11-30 16:26:35 +0200 | [diff] [blame] | 4565 | |
Kristian Høgsberg | 3be2ce9 | 2012-02-29 12:42:35 -0500 | [diff] [blame] | 4566 | wl_list_remove(&shell->lock_layer.link); |
Philipp Brüschweiler | 711fda8 | 2012-08-09 18:50:43 +0200 | [diff] [blame] | 4567 | if (shell->showing_input_panels) { |
Manuel Bachmann | 805d2f5 | 2014-03-05 12:21:34 +0100 | [diff] [blame] | 4568 | wl_list_insert(&shell->compositor->cursor_layer.link, |
Philipp Brüschweiler | 711fda8 | 2012-08-09 18:50:43 +0200 | [diff] [blame] | 4569 | &shell->input_panel_layer.link); |
| 4570 | wl_list_insert(&shell->input_panel_layer.link, |
Manuel Bachmann | 805d2f5 | 2014-03-05 12:21:34 +0100 | [diff] [blame] | 4571 | &shell->fullscreen_layer.link); |
Philipp Brüschweiler | 711fda8 | 2012-08-09 18:50:43 +0200 | [diff] [blame] | 4572 | } else { |
Manuel Bachmann | 805d2f5 | 2014-03-05 12:21:34 +0100 | [diff] [blame] | 4573 | wl_list_insert(&shell->compositor->cursor_layer.link, |
| 4574 | &shell->fullscreen_layer.link); |
Philipp Brüschweiler | 711fda8 | 2012-08-09 18:50:43 +0200 | [diff] [blame] | 4575 | } |
Manuel Bachmann | 805d2f5 | 2014-03-05 12:21:34 +0100 | [diff] [blame] | 4576 | wl_list_insert(&shell->fullscreen_layer.link, |
| 4577 | &shell->panel_layer.link); |
| 4578 | wl_list_insert(&shell->panel_layer.link, |
| 4579 | &ws->layer.link), |
Pekka Paalanen | f0fc70d | 2011-11-15 13:34:54 +0200 | [diff] [blame] | 4580 | |
Kristian Høgsberg | 2f5faff | 2012-07-31 16:36:34 -0400 | [diff] [blame] | 4581 | restore_focus_state(shell, get_current_workspace(shell)); |
Jonas Ådahl | 0476974 | 2012-06-13 00:01:24 +0200 | [diff] [blame] | 4582 | |
Pekka Paalanen | f0fc70d | 2011-11-15 13:34:54 +0200 | [diff] [blame] | 4583 | shell->locked = false; |
Ander Conselvan de Oliveira | 87524b6 | 2013-02-21 18:35:22 +0200 | [diff] [blame] | 4584 | shell_fade(shell, FADE_IN); |
Pekka Paalanen | fc6d91a | 2012-02-10 15:33:10 +0200 | [diff] [blame] | 4585 | weston_compositor_damage_all(shell->compositor); |
Pekka Paalanen | 9ef3e01 | 2011-11-15 13:34:48 +0200 | [diff] [blame] | 4586 | } |
| 4587 | |
| 4588 | static void |
| 4589 | desktop_shell_unlock(struct wl_client *client, |
| 4590 | struct wl_resource *resource) |
| 4591 | { |
Jason Ekstrand | 651f00e | 2013-06-14 10:07:54 -0500 | [diff] [blame] | 4592 | struct desktop_shell *shell = wl_resource_get_user_data(resource); |
Pekka Paalanen | 9ef3e01 | 2011-11-15 13:34:48 +0200 | [diff] [blame] | 4593 | |
Pekka Paalanen | 9ef3e01 | 2011-11-15 13:34:48 +0200 | [diff] [blame] | 4594 | shell->prepare_event_sent = false; |
Pekka Paalanen | f0fc70d | 2011-11-15 13:34:54 +0200 | [diff] [blame] | 4595 | |
| 4596 | if (shell->locked) |
| 4597 | resume_desktop(shell); |
Pekka Paalanen | 9ef3e01 | 2011-11-15 13:34:48 +0200 | [diff] [blame] | 4598 | } |
| 4599 | |
Kristian Høgsberg | d56bd90 | 2012-06-05 09:58:51 -0400 | [diff] [blame] | 4600 | static void |
Ander Conselvan de Oliveira | b9d2a0f | 2012-06-28 18:08:05 +0300 | [diff] [blame] | 4601 | desktop_shell_set_grab_surface(struct wl_client *client, |
Kristian Høgsberg | d56bd90 | 2012-06-05 09:58:51 -0400 | [diff] [blame] | 4602 | struct wl_resource *resource, |
| 4603 | struct wl_resource *surface_resource) |
| 4604 | { |
Jason Ekstrand | 651f00e | 2013-06-14 10:07:54 -0500 | [diff] [blame] | 4605 | struct desktop_shell *shell = wl_resource_get_user_data(resource); |
Kristian Høgsberg | d56bd90 | 2012-06-05 09:58:51 -0400 | [diff] [blame] | 4606 | |
Jason Ekstrand | 0f2ef7e | 2013-06-14 10:07:53 -0500 | [diff] [blame] | 4607 | shell->grab_surface = wl_resource_get_user_data(surface_resource); |
Kristian Høgsberg | 48588f8 | 2013-10-24 15:51:35 -0700 | [diff] [blame] | 4608 | weston_view_create(shell->grab_surface); |
Kristian Høgsberg | d56bd90 | 2012-06-05 09:58:51 -0400 | [diff] [blame] | 4609 | } |
| 4610 | |
Pekka Paalanen | 79346ab | 2013-05-22 18:03:09 +0300 | [diff] [blame] | 4611 | static void |
| 4612 | desktop_shell_desktop_ready(struct wl_client *client, |
| 4613 | struct wl_resource *resource) |
| 4614 | { |
Jason Ekstrand | 651f00e | 2013-06-14 10:07:54 -0500 | [diff] [blame] | 4615 | struct desktop_shell *shell = wl_resource_get_user_data(resource); |
Pekka Paalanen | 79346ab | 2013-05-22 18:03:09 +0300 | [diff] [blame] | 4616 | |
| 4617 | shell_fade_startup(shell); |
| 4618 | } |
| 4619 | |
Jonny Lamb | 765760d | 2014-08-20 15:53:19 +0200 | [diff] [blame] | 4620 | static void |
| 4621 | desktop_shell_set_panel_position(struct wl_client *client, |
| 4622 | struct wl_resource *resource, |
| 4623 | uint32_t position) |
| 4624 | { |
| 4625 | struct desktop_shell *shell = wl_resource_get_user_data(resource); |
| 4626 | |
| 4627 | if (position != DESKTOP_SHELL_PANEL_POSITION_TOP && |
| 4628 | position != DESKTOP_SHELL_PANEL_POSITION_BOTTOM && |
| 4629 | position != DESKTOP_SHELL_PANEL_POSITION_LEFT && |
| 4630 | position != DESKTOP_SHELL_PANEL_POSITION_RIGHT) { |
| 4631 | wl_resource_post_error(resource, |
| 4632 | DESKTOP_SHELL_ERROR_INVALID_ARGUMENT, |
| 4633 | "bad position argument"); |
| 4634 | return; |
| 4635 | } |
| 4636 | |
| 4637 | shell->panel_position = position; |
| 4638 | } |
| 4639 | |
Kristian Høgsberg | 7584062 | 2011-09-06 13:48:16 -0400 | [diff] [blame] | 4640 | static const struct desktop_shell_interface desktop_shell_implementation = { |
| 4641 | desktop_shell_set_background, |
Pekka Paalanen | 9ef3e01 | 2011-11-15 13:34:48 +0200 | [diff] [blame] | 4642 | desktop_shell_set_panel, |
| 4643 | desktop_shell_set_lock_surface, |
Kristian Høgsberg | d56bd90 | 2012-06-05 09:58:51 -0400 | [diff] [blame] | 4644 | desktop_shell_unlock, |
Pekka Paalanen | 79346ab | 2013-05-22 18:03:09 +0300 | [diff] [blame] | 4645 | desktop_shell_set_grab_surface, |
Jonny Lamb | 765760d | 2014-08-20 15:53:19 +0200 | [diff] [blame] | 4646 | desktop_shell_desktop_ready, |
| 4647 | desktop_shell_set_panel_position |
Kristian Høgsberg | 7584062 | 2011-09-06 13:48:16 -0400 | [diff] [blame] | 4648 | }; |
| 4649 | |
Pekka Paalanen | 92a0dc4 | 2011-11-28 15:34:13 +0200 | [diff] [blame] | 4650 | static enum shell_surface_type |
Kristian Høgsberg | 8334bc1 | 2012-01-03 10:29:47 -0500 | [diff] [blame] | 4651 | get_shell_surface_type(struct weston_surface *surface) |
Pekka Paalanen | 92a0dc4 | 2011-11-28 15:34:13 +0200 | [diff] [blame] | 4652 | { |
| 4653 | struct shell_surface *shsurf; |
| 4654 | |
| 4655 | shsurf = get_shell_surface(surface); |
| 4656 | if (!shsurf) |
Pekka Paalanen | 9826223 | 2011-12-01 10:42:22 +0200 | [diff] [blame] | 4657 | return SHELL_SURFACE_NONE; |
Pekka Paalanen | 92a0dc4 | 2011-11-28 15:34:13 +0200 | [diff] [blame] | 4658 | return shsurf->type; |
| 4659 | } |
| 4660 | |
Kristian Høgsberg | 7584062 | 2011-09-06 13:48:16 -0400 | [diff] [blame] | 4661 | static void |
Derek Foreman | 8ae2db5 | 2015-07-15 13:00:36 -0500 | [diff] [blame] | 4662 | move_binding(struct weston_pointer *pointer, uint32_t time, |
| 4663 | uint32_t button, void *data) |
Kristian Høgsberg | 0793756 | 2011-04-12 17:25:42 -0400 | [diff] [blame] | 4664 | { |
Rafal Mielniczuk | b2917a2 | 2014-01-05 20:04:59 +0100 | [diff] [blame] | 4665 | struct weston_surface *focus; |
Pekka Paalanen | 01388e2 | 2013-04-25 13:57:44 +0300 | [diff] [blame] | 4666 | struct weston_surface *surface; |
Kristian Høgsberg | 938b8fa | 2012-05-18 13:46:27 -0400 | [diff] [blame] | 4667 | struct shell_surface *shsurf; |
Kristian Høgsberg | d2abb83 | 2011-11-23 10:52:40 -0500 | [diff] [blame] | 4668 | |
Derek Foreman | 8ae2db5 | 2015-07-15 13:00:36 -0500 | [diff] [blame] | 4669 | if (pointer->focus == NULL) |
Rafal Mielniczuk | b2917a2 | 2014-01-05 20:04:59 +0100 | [diff] [blame] | 4670 | return; |
| 4671 | |
Derek Foreman | 8ae2db5 | 2015-07-15 13:00:36 -0500 | [diff] [blame] | 4672 | focus = pointer->focus->surface; |
Rafal Mielniczuk | b2917a2 | 2014-01-05 20:04:59 +0100 | [diff] [blame] | 4673 | |
Pekka Paalanen | 01388e2 | 2013-04-25 13:57:44 +0300 | [diff] [blame] | 4674 | surface = weston_surface_get_main_surface(focus); |
Benjamin Franzke | d0f79ab | 2011-11-22 12:43:52 +0100 | [diff] [blame] | 4675 | if (surface == NULL) |
| 4676 | return; |
Kristian Høgsberg | 0793756 | 2011-04-12 17:25:42 -0400 | [diff] [blame] | 4677 | |
Kristian Høgsberg | 938b8fa | 2012-05-18 13:46:27 -0400 | [diff] [blame] | 4678 | shsurf = get_shell_surface(surface); |
Rafael Antognolli | 03b1659 | 2013-12-03 15:35:42 -0200 | [diff] [blame] | 4679 | if (shsurf == NULL || shsurf->state.fullscreen || |
| 4680 | shsurf->state.maximized) |
Kristian Høgsberg | 938b8fa | 2012-05-18 13:46:27 -0400 | [diff] [blame] | 4681 | return; |
| 4682 | |
Derek Foreman | 794fa0e | 2015-07-15 13:00:38 -0500 | [diff] [blame] | 4683 | surface_move(shsurf, pointer, false); |
Kristian Høgsberg | 0793756 | 2011-04-12 17:25:42 -0400 | [diff] [blame] | 4684 | } |
| 4685 | |
| 4686 | static void |
Derek Foreman | 8ae2db5 | 2015-07-15 13:00:36 -0500 | [diff] [blame] | 4687 | maximize_binding(struct weston_keyboard *keyboard, uint32_t time, |
| 4688 | uint32_t button, void *data) |
Rafael Antognolli | ea997ac | 2013-12-03 15:35:48 -0200 | [diff] [blame] | 4689 | { |
Derek Foreman | 8ae2db5 | 2015-07-15 13:00:36 -0500 | [diff] [blame] | 4690 | struct weston_surface *focus = keyboard->focus; |
Rafael Antognolli | ea997ac | 2013-12-03 15:35:48 -0200 | [diff] [blame] | 4691 | struct weston_surface *surface; |
| 4692 | struct shell_surface *shsurf; |
| 4693 | |
| 4694 | surface = weston_surface_get_main_surface(focus); |
| 4695 | if (surface == NULL) |
| 4696 | return; |
| 4697 | |
| 4698 | shsurf = get_shell_surface(surface); |
| 4699 | if (shsurf == NULL) |
| 4700 | return; |
| 4701 | |
| 4702 | if (!shell_surface_is_xdg_surface(shsurf)) |
| 4703 | return; |
| 4704 | |
Jasper St. Pierre | ab2c108 | 2014-04-10 10:41:46 -0700 | [diff] [blame] | 4705 | shsurf->state_requested = true; |
| 4706 | shsurf->requested_state.maximized = !shsurf->state.maximized; |
Jasper St. Pierre | 9aa8ce6 | 2014-04-11 16:18:54 -0700 | [diff] [blame] | 4707 | send_configure_for_surface(shsurf); |
Rafael Antognolli | ea997ac | 2013-12-03 15:35:48 -0200 | [diff] [blame] | 4708 | } |
| 4709 | |
| 4710 | static void |
Derek Foreman | 8ae2db5 | 2015-07-15 13:00:36 -0500 | [diff] [blame] | 4711 | fullscreen_binding(struct weston_keyboard *keyboard, uint32_t time, |
| 4712 | uint32_t button, void *data) |
Rafael Antognolli | ea997ac | 2013-12-03 15:35:48 -0200 | [diff] [blame] | 4713 | { |
Derek Foreman | 8ae2db5 | 2015-07-15 13:00:36 -0500 | [diff] [blame] | 4714 | struct weston_surface *focus = keyboard->focus; |
Rafael Antognolli | ea997ac | 2013-12-03 15:35:48 -0200 | [diff] [blame] | 4715 | struct weston_surface *surface; |
| 4716 | struct shell_surface *shsurf; |
| 4717 | |
| 4718 | surface = weston_surface_get_main_surface(focus); |
| 4719 | if (surface == NULL) |
| 4720 | return; |
| 4721 | |
| 4722 | shsurf = get_shell_surface(surface); |
| 4723 | if (shsurf == NULL) |
| 4724 | return; |
| 4725 | |
| 4726 | if (!shell_surface_is_xdg_surface(shsurf)) |
| 4727 | return; |
| 4728 | |
Jasper St. Pierre | ab2c108 | 2014-04-10 10:41:46 -0700 | [diff] [blame] | 4729 | shsurf->state_requested = true; |
| 4730 | shsurf->requested_state.fullscreen = !shsurf->state.fullscreen; |
Boyan Ding | 32abdbb | 2014-06-26 10:19:32 +0800 | [diff] [blame] | 4731 | shsurf->fullscreen_output = shsurf->output; |
Jasper St. Pierre | 9aa8ce6 | 2014-04-11 16:18:54 -0700 | [diff] [blame] | 4732 | send_configure_for_surface(shsurf); |
Rafael Antognolli | ea997ac | 2013-12-03 15:35:48 -0200 | [diff] [blame] | 4733 | } |
| 4734 | |
| 4735 | static void |
Derek Foreman | 8ae2db5 | 2015-07-15 13:00:36 -0500 | [diff] [blame] | 4736 | touch_move_binding(struct weston_touch *touch, uint32_t time, void *data) |
Neil Roberts | aba0f25 | 2013-10-03 16:43:05 +0100 | [diff] [blame] | 4737 | { |
Derek Foreman | 362656b | 2014-09-04 10:23:05 -0500 | [diff] [blame] | 4738 | struct weston_surface *focus; |
Neil Roberts | aba0f25 | 2013-10-03 16:43:05 +0100 | [diff] [blame] | 4739 | struct weston_surface *surface; |
| 4740 | struct shell_surface *shsurf; |
| 4741 | |
Derek Foreman | 8ae2db5 | 2015-07-15 13:00:36 -0500 | [diff] [blame] | 4742 | if (touch->focus == NULL) |
Derek Foreman | 362656b | 2014-09-04 10:23:05 -0500 | [diff] [blame] | 4743 | return; |
| 4744 | |
Derek Foreman | 8ae2db5 | 2015-07-15 13:00:36 -0500 | [diff] [blame] | 4745 | focus = touch->focus->surface; |
Neil Roberts | aba0f25 | 2013-10-03 16:43:05 +0100 | [diff] [blame] | 4746 | surface = weston_surface_get_main_surface(focus); |
| 4747 | if (surface == NULL) |
| 4748 | return; |
| 4749 | |
| 4750 | shsurf = get_shell_surface(surface); |
Rafael Antognolli | 03b1659 | 2013-12-03 15:35:42 -0200 | [diff] [blame] | 4751 | if (shsurf == NULL || shsurf->state.fullscreen || |
| 4752 | shsurf->state.maximized) |
Neil Roberts | aba0f25 | 2013-10-03 16:43:05 +0100 | [diff] [blame] | 4753 | return; |
| 4754 | |
Derek Foreman | b7674ae | 2015-07-15 13:00:37 -0500 | [diff] [blame] | 4755 | surface_touch_move(shsurf, touch); |
Neil Roberts | aba0f25 | 2013-10-03 16:43:05 +0100 | [diff] [blame] | 4756 | } |
| 4757 | |
| 4758 | static void |
Derek Foreman | 8ae2db5 | 2015-07-15 13:00:36 -0500 | [diff] [blame] | 4759 | resize_binding(struct weston_pointer *pointer, uint32_t time, |
| 4760 | uint32_t button, void *data) |
Kristian Høgsberg | 0793756 | 2011-04-12 17:25:42 -0400 | [diff] [blame] | 4761 | { |
Rafal Mielniczuk | b2917a2 | 2014-01-05 20:04:59 +0100 | [diff] [blame] | 4762 | struct weston_surface *focus; |
Pekka Paalanen | 01388e2 | 2013-04-25 13:57:44 +0300 | [diff] [blame] | 4763 | struct weston_surface *surface; |
Kristian Høgsberg | 0793756 | 2011-04-12 17:25:42 -0400 | [diff] [blame] | 4764 | uint32_t edges = 0; |
| 4765 | int32_t x, y; |
Pekka Paalanen | 9d1613e | 2011-11-25 12:09:16 +0200 | [diff] [blame] | 4766 | struct shell_surface *shsurf; |
Kristian Høgsberg | d2abb83 | 2011-11-23 10:52:40 -0500 | [diff] [blame] | 4767 | |
Derek Foreman | 8ae2db5 | 2015-07-15 13:00:36 -0500 | [diff] [blame] | 4768 | if (pointer->focus == NULL) |
Rafal Mielniczuk | b2917a2 | 2014-01-05 20:04:59 +0100 | [diff] [blame] | 4769 | return; |
| 4770 | |
Derek Foreman | 8ae2db5 | 2015-07-15 13:00:36 -0500 | [diff] [blame] | 4771 | focus = pointer->focus->surface; |
Rafal Mielniczuk | b2917a2 | 2014-01-05 20:04:59 +0100 | [diff] [blame] | 4772 | |
Pekka Paalanen | 01388e2 | 2013-04-25 13:57:44 +0300 | [diff] [blame] | 4773 | surface = weston_surface_get_main_surface(focus); |
Benjamin Franzke | d0f79ab | 2011-11-22 12:43:52 +0100 | [diff] [blame] | 4774 | if (surface == NULL) |
| 4775 | return; |
Pekka Paalanen | 92a0dc4 | 2011-11-28 15:34:13 +0200 | [diff] [blame] | 4776 | |
Pekka Paalanen | 9d1613e | 2011-11-25 12:09:16 +0200 | [diff] [blame] | 4777 | shsurf = get_shell_surface(surface); |
Rafael Antognolli | 03b1659 | 2013-12-03 15:35:42 -0200 | [diff] [blame] | 4778 | if (shsurf == NULL || shsurf->state.fullscreen || |
| 4779 | shsurf->state.maximized) |
Pekka Paalanen | 92a0dc4 | 2011-11-28 15:34:13 +0200 | [diff] [blame] | 4780 | return; |
| 4781 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 4782 | weston_view_from_global(shsurf->view, |
Derek Foreman | 8ae2db5 | 2015-07-15 13:00:36 -0500 | [diff] [blame] | 4783 | wl_fixed_to_int(pointer->grab_x), |
| 4784 | wl_fixed_to_int(pointer->grab_y), |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 4785 | &x, &y); |
Kristian Høgsberg | 0793756 | 2011-04-12 17:25:42 -0400 | [diff] [blame] | 4786 | |
Jason Ekstrand | 918f2dd | 2013-12-02 21:01:53 -0600 | [diff] [blame] | 4787 | if (x < shsurf->surface->width / 3) |
Pekka Paalanen | 9d1613e | 2011-11-25 12:09:16 +0200 | [diff] [blame] | 4788 | edges |= WL_SHELL_SURFACE_RESIZE_LEFT; |
Jason Ekstrand | 918f2dd | 2013-12-02 21:01:53 -0600 | [diff] [blame] | 4789 | else if (x < 2 * shsurf->surface->width / 3) |
Kristian Høgsberg | 0793756 | 2011-04-12 17:25:42 -0400 | [diff] [blame] | 4790 | edges |= 0; |
| 4791 | else |
Pekka Paalanen | 9d1613e | 2011-11-25 12:09:16 +0200 | [diff] [blame] | 4792 | edges |= WL_SHELL_SURFACE_RESIZE_RIGHT; |
Kristian Høgsberg | 0793756 | 2011-04-12 17:25:42 -0400 | [diff] [blame] | 4793 | |
Jason Ekstrand | 918f2dd | 2013-12-02 21:01:53 -0600 | [diff] [blame] | 4794 | if (y < shsurf->surface->height / 3) |
Pekka Paalanen | 9d1613e | 2011-11-25 12:09:16 +0200 | [diff] [blame] | 4795 | edges |= WL_SHELL_SURFACE_RESIZE_TOP; |
Jason Ekstrand | 918f2dd | 2013-12-02 21:01:53 -0600 | [diff] [blame] | 4796 | else if (y < 2 * shsurf->surface->height / 3) |
Kristian Høgsberg | 0793756 | 2011-04-12 17:25:42 -0400 | [diff] [blame] | 4797 | edges |= 0; |
| 4798 | else |
Pekka Paalanen | 9d1613e | 2011-11-25 12:09:16 +0200 | [diff] [blame] | 4799 | edges |= WL_SHELL_SURFACE_RESIZE_BOTTOM; |
Kristian Høgsberg | 0793756 | 2011-04-12 17:25:42 -0400 | [diff] [blame] | 4800 | |
Derek Foreman | 8fbebbd | 2015-07-15 13:00:40 -0500 | [diff] [blame] | 4801 | surface_resize(shsurf, pointer, edges); |
Kristian Høgsberg | 02ec0a5 | 2011-04-23 13:04:11 -0400 | [diff] [blame] | 4802 | } |
| 4803 | |
| 4804 | static void |
Derek Foreman | 8ae2db5 | 2015-07-15 13:00:36 -0500 | [diff] [blame] | 4805 | surface_opacity_binding(struct weston_pointer *pointer, uint32_t time, |
| 4806 | uint32_t axis, wl_fixed_t value, void *data) |
Scott Moreau | a3aa9c9 | 2012-03-22 11:01:03 -0600 | [diff] [blame] | 4807 | { |
Jonas Ådahl | b0b87ba | 2012-09-27 18:40:42 +0200 | [diff] [blame] | 4808 | float step = 0.005; |
Scott Moreau | a3aa9c9 | 2012-03-22 11:01:03 -0600 | [diff] [blame] | 4809 | struct shell_surface *shsurf; |
Derek Foreman | 8ae2db5 | 2015-07-15 13:00:36 -0500 | [diff] [blame] | 4810 | struct weston_surface *focus = pointer->focus->surface; |
Pekka Paalanen | 01388e2 | 2013-04-25 13:57:44 +0300 | [diff] [blame] | 4811 | struct weston_surface *surface; |
Scott Moreau | a3aa9c9 | 2012-03-22 11:01:03 -0600 | [diff] [blame] | 4812 | |
Pekka Paalanen | 01388e2 | 2013-04-25 13:57:44 +0300 | [diff] [blame] | 4813 | /* XXX: broken for windows containing sub-surfaces */ |
| 4814 | surface = weston_surface_get_main_surface(focus); |
Scott Moreau | a3aa9c9 | 2012-03-22 11:01:03 -0600 | [diff] [blame] | 4815 | if (surface == NULL) |
| 4816 | return; |
| 4817 | |
| 4818 | shsurf = get_shell_surface(surface); |
| 4819 | if (!shsurf) |
| 4820 | return; |
| 4821 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 4822 | shsurf->view->alpha -= wl_fixed_to_double(value) * step; |
Scott Moreau | a3aa9c9 | 2012-03-22 11:01:03 -0600 | [diff] [blame] | 4823 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 4824 | if (shsurf->view->alpha > 1.0) |
| 4825 | shsurf->view->alpha = 1.0; |
| 4826 | if (shsurf->view->alpha < step) |
| 4827 | shsurf->view->alpha = step; |
Scott Moreau | a3aa9c9 | 2012-03-22 11:01:03 -0600 | [diff] [blame] | 4828 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 4829 | weston_view_geometry_dirty(shsurf->view); |
Scott Moreau | a3aa9c9 | 2012-03-22 11:01:03 -0600 | [diff] [blame] | 4830 | weston_surface_damage(surface); |
| 4831 | } |
| 4832 | |
| 4833 | static void |
Kristian Høgsberg | e314875 | 2013-05-06 23:19:49 -0400 | [diff] [blame] | 4834 | do_zoom(struct weston_seat *seat, uint32_t time, uint32_t key, uint32_t axis, |
Daniel Stone | 0c1e46e | 2012-05-30 16:31:59 +0100 | [diff] [blame] | 4835 | wl_fixed_t value) |
Scott Moreau | ccbf29d | 2012-02-22 14:21:41 -0700 | [diff] [blame] | 4836 | { |
Derek Foreman | 8aeeac8 | 2015-01-30 13:24:36 -0600 | [diff] [blame] | 4837 | struct weston_compositor *compositor = seat->compositor; |
Derek Foreman | 1281a36 | 2015-07-31 16:55:32 -0500 | [diff] [blame] | 4838 | struct weston_pointer *pointer = weston_seat_get_pointer(seat); |
Scott Moreau | ccbf29d | 2012-02-22 14:21:41 -0700 | [diff] [blame] | 4839 | struct weston_output *output; |
Scott Moreau | e660398 | 2012-06-11 13:07:51 -0600 | [diff] [blame] | 4840 | float increment; |
Scott Moreau | ccbf29d | 2012-02-22 14:21:41 -0700 | [diff] [blame] | 4841 | |
Derek Foreman | 1281a36 | 2015-07-31 16:55:32 -0500 | [diff] [blame] | 4842 | if (!pointer) { |
Derek Foreman | 7ef3bed | 2015-01-06 14:28:13 -0600 | [diff] [blame] | 4843 | weston_log("Zoom hotkey pressed but seat '%s' contains no pointer.\n", seat->seat_name); |
| 4844 | return; |
| 4845 | } |
| 4846 | |
Scott Moreau | ccbf29d | 2012-02-22 14:21:41 -0700 | [diff] [blame] | 4847 | wl_list_for_each(output, &compositor->output_list, link) { |
| 4848 | if (pixman_region32_contains_point(&output->region, |
Derek Foreman | 1281a36 | 2015-07-31 16:55:32 -0500 | [diff] [blame] | 4849 | wl_fixed_to_double(pointer->x), |
| 4850 | wl_fixed_to_double(pointer->y), |
Daniel Stone | 103db7f | 2012-05-08 17:17:55 +0100 | [diff] [blame] | 4851 | NULL)) { |
Daniel Stone | 325fc2d | 2012-05-30 16:31:58 +0100 | [diff] [blame] | 4852 | if (key == KEY_PAGEUP) |
Kristian Høgsberg | 9b68af0 | 2012-05-22 12:55:18 -0400 | [diff] [blame] | 4853 | increment = output->zoom.increment; |
Daniel Stone | 325fc2d | 2012-05-30 16:31:58 +0100 | [diff] [blame] | 4854 | else if (key == KEY_PAGEDOWN) |
Kristian Høgsberg | 9b68af0 | 2012-05-22 12:55:18 -0400 | [diff] [blame] | 4855 | increment = -output->zoom.increment; |
| 4856 | else if (axis == WL_POINTER_AXIS_VERTICAL_SCROLL) |
Jonas Ådahl | b0b87ba | 2012-09-27 18:40:42 +0200 | [diff] [blame] | 4857 | /* For every pixel zoom 20th of a step */ |
Daniel Stone | 0c1e46e | 2012-05-30 16:31:59 +0100 | [diff] [blame] | 4858 | increment = output->zoom.increment * |
Jonas Ådahl | b0b87ba | 2012-09-27 18:40:42 +0200 | [diff] [blame] | 4859 | -wl_fixed_to_double(value) / 20.0; |
Kristian Høgsberg | 9b68af0 | 2012-05-22 12:55:18 -0400 | [diff] [blame] | 4860 | else |
| 4861 | increment = 0; |
| 4862 | |
Kristian Høgsberg | 9b68af0 | 2012-05-22 12:55:18 -0400 | [diff] [blame] | 4863 | output->zoom.level += increment; |
Scott Moreau | c6d7f60 | 2012-02-23 22:28:37 -0700 | [diff] [blame] | 4864 | |
Scott Moreau | e660398 | 2012-06-11 13:07:51 -0600 | [diff] [blame] | 4865 | if (output->zoom.level < 0.0) |
Scott Moreau | 850ca42 | 2012-05-21 15:21:25 -0600 | [diff] [blame] | 4866 | output->zoom.level = 0.0; |
Scott Moreau | e660398 | 2012-06-11 13:07:51 -0600 | [diff] [blame] | 4867 | else if (output->zoom.level > output->zoom.max_level) |
| 4868 | output->zoom.level = output->zoom.max_level; |
Derek Foreman | 25bd8a7 | 2015-07-23 14:55:13 -0500 | [diff] [blame] | 4869 | |
| 4870 | if (!output->zoom.active) { |
| 4871 | if (output->zoom.level <= 0.0) |
| 4872 | continue; |
Derek Foreman | 22276a5 | 2015-07-23 14:55:15 -0500 | [diff] [blame] | 4873 | weston_output_activate_zoom(output, seat); |
Kristian Høgsberg | 79af73e | 2012-08-03 15:45:23 -0400 | [diff] [blame] | 4874 | } |
Scott Moreau | ccbf29d | 2012-02-22 14:21:41 -0700 | [diff] [blame] | 4875 | |
Scott Moreau | e660398 | 2012-06-11 13:07:51 -0600 | [diff] [blame] | 4876 | output->zoom.spring_z.target = output->zoom.level; |
Scott Moreau | ccbf29d | 2012-02-22 14:21:41 -0700 | [diff] [blame] | 4877 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 4878 | weston_output_update_zoom(output); |
Scott Moreau | ccbf29d | 2012-02-22 14:21:41 -0700 | [diff] [blame] | 4879 | } |
| 4880 | } |
| 4881 | } |
| 4882 | |
Scott Moreau | ccbf29d | 2012-02-22 14:21:41 -0700 | [diff] [blame] | 4883 | static void |
Derek Foreman | 8ae2db5 | 2015-07-15 13:00:36 -0500 | [diff] [blame] | 4884 | zoom_axis_binding(struct weston_pointer *pointer, uint32_t time, |
| 4885 | uint32_t axis, wl_fixed_t value, void *data) |
Daniel Stone | 325fc2d | 2012-05-30 16:31:58 +0100 | [diff] [blame] | 4886 | { |
Derek Foreman | 8ae2db5 | 2015-07-15 13:00:36 -0500 | [diff] [blame] | 4887 | do_zoom(pointer->seat, time, 0, axis, value); |
Daniel Stone | 325fc2d | 2012-05-30 16:31:58 +0100 | [diff] [blame] | 4888 | } |
| 4889 | |
| 4890 | static void |
Derek Foreman | 8ae2db5 | 2015-07-15 13:00:36 -0500 | [diff] [blame] | 4891 | zoom_key_binding(struct weston_keyboard *keyboard, uint32_t time, |
| 4892 | uint32_t key, void *data) |
Daniel Stone | 325fc2d | 2012-05-30 16:31:58 +0100 | [diff] [blame] | 4893 | { |
Derek Foreman | 8ae2db5 | 2015-07-15 13:00:36 -0500 | [diff] [blame] | 4894 | do_zoom(keyboard->seat, time, key, 0, 0); |
Daniel Stone | 325fc2d | 2012-05-30 16:31:58 +0100 | [diff] [blame] | 4895 | } |
| 4896 | |
| 4897 | static void |
Derek Foreman | 8ae2db5 | 2015-07-15 13:00:36 -0500 | [diff] [blame] | 4898 | terminate_binding(struct weston_keyboard *keyboard, uint32_t time, |
| 4899 | uint32_t key, void *data) |
Kristian Høgsberg | e1a850e | 2011-12-19 15:18:05 -0500 | [diff] [blame] | 4900 | { |
Kristian Høgsberg | 8334bc1 | 2012-01-03 10:29:47 -0500 | [diff] [blame] | 4901 | struct weston_compositor *compositor = data; |
Kristian Høgsberg | e1a850e | 2011-12-19 15:18:05 -0500 | [diff] [blame] | 4902 | |
Daniel Stone | 325fc2d | 2012-05-30 16:31:58 +0100 | [diff] [blame] | 4903 | wl_display_terminate(compositor->wl_display); |
Kristian Høgsberg | e1a850e | 2011-12-19 15:18:05 -0500 | [diff] [blame] | 4904 | } |
| 4905 | |
Emilio Pozuelo Monfort | 03251b6 | 2013-11-19 11:37:16 +0100 | [diff] [blame] | 4906 | static void |
Giulio Camuffo | 1959ab8 | 2013-11-14 23:42:52 +0100 | [diff] [blame] | 4907 | rotate_grab_motion(struct weston_pointer_grab *grab, uint32_t time, |
| 4908 | wl_fixed_t x, wl_fixed_t y) |
Pekka Paalanen | 460099f | 2012-01-20 16:48:25 +0200 | [diff] [blame] | 4909 | { |
| 4910 | struct rotate_grab *rotate = |
Ander Conselvan de Oliveira | fe0444a | 2012-04-04 17:48:05 +0300 | [diff] [blame] | 4911 | container_of(grab, struct rotate_grab, base.grab); |
Kristian Høgsberg | 02bbabb | 2013-05-06 22:15:05 -0400 | [diff] [blame] | 4912 | struct weston_pointer *pointer = grab->pointer; |
Ander Conselvan de Oliveira | fe0444a | 2012-04-04 17:48:05 +0300 | [diff] [blame] | 4913 | struct shell_surface *shsurf = rotate->base.shsurf; |
John Kåre Alsaker | 490d02a | 2012-09-30 02:57:21 +0200 | [diff] [blame] | 4914 | float cx, cy, dx, dy, cposx, cposy, dposx, dposy, r; |
Ander Conselvan de Oliveira | fe0444a | 2012-04-04 17:48:05 +0300 | [diff] [blame] | 4915 | |
Giulio Camuffo | 1959ab8 | 2013-11-14 23:42:52 +0100 | [diff] [blame] | 4916 | weston_pointer_move(pointer, x, y); |
| 4917 | |
Ander Conselvan de Oliveira | fe0444a | 2012-04-04 17:48:05 +0300 | [diff] [blame] | 4918 | if (!shsurf) |
| 4919 | return; |
| 4920 | |
Jason Ekstrand | 918f2dd | 2013-12-02 21:01:53 -0600 | [diff] [blame] | 4921 | cx = 0.5f * shsurf->surface->width; |
| 4922 | cy = 0.5f * shsurf->surface->height; |
Pekka Paalanen | 460099f | 2012-01-20 16:48:25 +0200 | [diff] [blame] | 4923 | |
Daniel Stone | 37816df | 2012-05-16 18:45:18 +0100 | [diff] [blame] | 4924 | dx = wl_fixed_to_double(pointer->x) - rotate->center.x; |
| 4925 | dy = wl_fixed_to_double(pointer->y) - rotate->center.y; |
Pekka Paalanen | 460099f | 2012-01-20 16:48:25 +0200 | [diff] [blame] | 4926 | r = sqrtf(dx * dx + dy * dy); |
| 4927 | |
Ander Conselvan de Oliveira | fe0444a | 2012-04-04 17:48:05 +0300 | [diff] [blame] | 4928 | wl_list_remove(&shsurf->rotation.transform.link); |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 4929 | weston_view_geometry_dirty(shsurf->view); |
Pekka Paalanen | 460099f | 2012-01-20 16:48:25 +0200 | [diff] [blame] | 4930 | |
| 4931 | if (r > 20.0f) { |
Pekka Paalanen | 460099f | 2012-01-20 16:48:25 +0200 | [diff] [blame] | 4932 | struct weston_matrix *matrix = |
Ander Conselvan de Oliveira | fe0444a | 2012-04-04 17:48:05 +0300 | [diff] [blame] | 4933 | &shsurf->rotation.transform.matrix; |
Pekka Paalanen | 460099f | 2012-01-20 16:48:25 +0200 | [diff] [blame] | 4934 | |
Kristian Høgsberg | 765e27b | 2012-01-27 13:36:13 -0500 | [diff] [blame] | 4935 | weston_matrix_init(&rotate->rotation); |
Vasily Khoruzhick | 1bbf372 | 2013-01-28 22:40:28 +0300 | [diff] [blame] | 4936 | weston_matrix_rotate_xy(&rotate->rotation, dx / r, dy / r); |
Pekka Paalanen | 460099f | 2012-01-20 16:48:25 +0200 | [diff] [blame] | 4937 | |
| 4938 | weston_matrix_init(matrix); |
Pekka Paalanen | 7b3bd3d | 2012-01-30 14:16:34 +0200 | [diff] [blame] | 4939 | weston_matrix_translate(matrix, -cx, -cy, 0.0f); |
Ander Conselvan de Oliveira | fe0444a | 2012-04-04 17:48:05 +0300 | [diff] [blame] | 4940 | weston_matrix_multiply(matrix, &shsurf->rotation.rotation); |
Kristian Høgsberg | 765e27b | 2012-01-27 13:36:13 -0500 | [diff] [blame] | 4941 | weston_matrix_multiply(matrix, &rotate->rotation); |
Pekka Paalanen | 7b3bd3d | 2012-01-30 14:16:34 +0200 | [diff] [blame] | 4942 | weston_matrix_translate(matrix, cx, cy, 0.0f); |
Pekka Paalanen | 460099f | 2012-01-20 16:48:25 +0200 | [diff] [blame] | 4943 | |
Pekka Paalanen | bc0b7e7 | 2012-01-24 09:53:37 +0200 | [diff] [blame] | 4944 | wl_list_insert( |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 4945 | &shsurf->view->geometry.transformation_list, |
Ander Conselvan de Oliveira | fe0444a | 2012-04-04 17:48:05 +0300 | [diff] [blame] | 4946 | &shsurf->rotation.transform.link); |
Pekka Paalanen | 460099f | 2012-01-20 16:48:25 +0200 | [diff] [blame] | 4947 | } else { |
Ander Conselvan de Oliveira | fe0444a | 2012-04-04 17:48:05 +0300 | [diff] [blame] | 4948 | wl_list_init(&shsurf->rotation.transform.link); |
| 4949 | weston_matrix_init(&shsurf->rotation.rotation); |
Kristian Høgsberg | 765e27b | 2012-01-27 13:36:13 -0500 | [diff] [blame] | 4950 | weston_matrix_init(&rotate->rotation); |
Pekka Paalanen | 460099f | 2012-01-20 16:48:25 +0200 | [diff] [blame] | 4951 | } |
Pekka Paalanen | b45ac5e | 2012-02-09 15:58:44 +0200 | [diff] [blame] | 4952 | |
Rafal Mielniczuk | 2d7ab82 | 2012-03-22 22:22:04 +0100 | [diff] [blame] | 4953 | /* We need to adjust the position of the surface |
| 4954 | * in case it was resized in a rotated state before */ |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 4955 | cposx = shsurf->view->geometry.x + cx; |
| 4956 | cposy = shsurf->view->geometry.y + cy; |
Rafal Mielniczuk | 2d7ab82 | 2012-03-22 22:22:04 +0100 | [diff] [blame] | 4957 | dposx = rotate->center.x - cposx; |
| 4958 | dposy = rotate->center.y - cposy; |
| 4959 | if (dposx != 0.0f || dposy != 0.0f) { |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 4960 | weston_view_set_position(shsurf->view, |
| 4961 | shsurf->view->geometry.x + dposx, |
| 4962 | shsurf->view->geometry.y + dposy); |
Rafal Mielniczuk | 2d7ab82 | 2012-03-22 22:22:04 +0100 | [diff] [blame] | 4963 | } |
| 4964 | |
Derek Foreman | 4b1a0a1 | 2014-09-10 15:37:33 -0500 | [diff] [blame] | 4965 | /* Repaint implies weston_view_update_transform(), which |
Pekka Paalanen | b45ac5e | 2012-02-09 15:58:44 +0200 | [diff] [blame] | 4966 | * lazily applies the damage due to rotation update. |
| 4967 | */ |
Ander Conselvan de Oliveira | fe0444a | 2012-04-04 17:48:05 +0300 | [diff] [blame] | 4968 | weston_compositor_schedule_repaint(shsurf->surface->compositor); |
Pekka Paalanen | 460099f | 2012-01-20 16:48:25 +0200 | [diff] [blame] | 4969 | } |
| 4970 | |
| 4971 | static void |
Kristian Høgsberg | 02bbabb | 2013-05-06 22:15:05 -0400 | [diff] [blame] | 4972 | rotate_grab_button(struct weston_pointer_grab *grab, |
| 4973 | uint32_t time, uint32_t button, uint32_t state_w) |
Pekka Paalanen | 460099f | 2012-01-20 16:48:25 +0200 | [diff] [blame] | 4974 | { |
| 4975 | struct rotate_grab *rotate = |
Ander Conselvan de Oliveira | fe0444a | 2012-04-04 17:48:05 +0300 | [diff] [blame] | 4976 | container_of(grab, struct rotate_grab, base.grab); |
Kristian Høgsberg | 02bbabb | 2013-05-06 22:15:05 -0400 | [diff] [blame] | 4977 | struct weston_pointer *pointer = grab->pointer; |
Ander Conselvan de Oliveira | fe0444a | 2012-04-04 17:48:05 +0300 | [diff] [blame] | 4978 | struct shell_surface *shsurf = rotate->base.shsurf; |
Daniel Stone | 4dbadb1 | 2012-05-30 16:31:51 +0100 | [diff] [blame] | 4979 | enum wl_pointer_button_state state = state_w; |
Pekka Paalanen | 460099f | 2012-01-20 16:48:25 +0200 | [diff] [blame] | 4980 | |
Daniel Stone | 4dbadb1 | 2012-05-30 16:31:51 +0100 | [diff] [blame] | 4981 | if (pointer->button_count == 0 && |
| 4982 | state == WL_POINTER_BUTTON_STATE_RELEASED) { |
Ander Conselvan de Oliveira | fe0444a | 2012-04-04 17:48:05 +0300 | [diff] [blame] | 4983 | if (shsurf) |
| 4984 | weston_matrix_multiply(&shsurf->rotation.rotation, |
| 4985 | &rotate->rotation); |
Ander Conselvan de Oliveira | b9d2a0f | 2012-06-28 18:08:05 +0300 | [diff] [blame] | 4986 | shell_grab_end(&rotate->base); |
Pekka Paalanen | 460099f | 2012-01-20 16:48:25 +0200 | [diff] [blame] | 4987 | free(rotate); |
| 4988 | } |
| 4989 | } |
| 4990 | |
Jonas Ådahl | 1ea343e | 2013-10-25 23:18:05 +0200 | [diff] [blame] | 4991 | static void |
| 4992 | rotate_grab_cancel(struct weston_pointer_grab *grab) |
| 4993 | { |
| 4994 | struct rotate_grab *rotate = |
| 4995 | container_of(grab, struct rotate_grab, base.grab); |
| 4996 | |
| 4997 | shell_grab_end(&rotate->base); |
| 4998 | free(rotate); |
| 4999 | } |
| 5000 | |
Kristian Høgsberg | 02bbabb | 2013-05-06 22:15:05 -0400 | [diff] [blame] | 5001 | static const struct weston_pointer_grab_interface rotate_grab_interface = { |
Pekka Paalanen | 460099f | 2012-01-20 16:48:25 +0200 | [diff] [blame] | 5002 | noop_grab_focus, |
| 5003 | rotate_grab_motion, |
| 5004 | rotate_grab_button, |
Jonas Ådahl | 1ea343e | 2013-10-25 23:18:05 +0200 | [diff] [blame] | 5005 | rotate_grab_cancel, |
Pekka Paalanen | 460099f | 2012-01-20 16:48:25 +0200 | [diff] [blame] | 5006 | }; |
| 5007 | |
| 5008 | static void |
Derek Foreman | 74de469 | 2015-07-15 13:00:39 -0500 | [diff] [blame] | 5009 | surface_rotate(struct shell_surface *surface, struct weston_pointer *pointer) |
Pekka Paalanen | 460099f | 2012-01-20 16:48:25 +0200 | [diff] [blame] | 5010 | { |
Pekka Paalanen | 460099f | 2012-01-20 16:48:25 +0200 | [diff] [blame] | 5011 | struct rotate_grab *rotate; |
John Kåre Alsaker | 490d02a | 2012-09-30 02:57:21 +0200 | [diff] [blame] | 5012 | float dx, dy; |
| 5013 | float r; |
Pekka Paalanen | 460099f | 2012-01-20 16:48:25 +0200 | [diff] [blame] | 5014 | |
Derek Foreman | 45a7c27 | 2015-09-11 14:27:40 -0500 | [diff] [blame] | 5015 | surface = find_toplevel_surface(surface); |
| 5016 | |
Pekka Paalanen | 460099f | 2012-01-20 16:48:25 +0200 | [diff] [blame] | 5017 | rotate = malloc(sizeof *rotate); |
| 5018 | if (!rotate) |
| 5019 | return; |
| 5020 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 5021 | weston_view_to_global_float(surface->view, |
Jason Ekstrand | 918f2dd | 2013-12-02 21:01:53 -0600 | [diff] [blame] | 5022 | surface->surface->width * 0.5f, |
| 5023 | surface->surface->height * 0.5f, |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 5024 | &rotate->center.x, &rotate->center.y); |
Pekka Paalanen | 460099f | 2012-01-20 16:48:25 +0200 | [diff] [blame] | 5025 | |
Derek Foreman | 74de469 | 2015-07-15 13:00:39 -0500 | [diff] [blame] | 5026 | dx = wl_fixed_to_double(pointer->x) - rotate->center.x; |
| 5027 | dy = wl_fixed_to_double(pointer->y) - rotate->center.y; |
Kristian Høgsberg | 765e27b | 2012-01-27 13:36:13 -0500 | [diff] [blame] | 5028 | r = sqrtf(dx * dx + dy * dy); |
| 5029 | if (r > 20.0f) { |
| 5030 | struct weston_matrix inverse; |
| 5031 | |
| 5032 | weston_matrix_init(&inverse); |
Vasily Khoruzhick | 1bbf372 | 2013-01-28 22:40:28 +0300 | [diff] [blame] | 5033 | weston_matrix_rotate_xy(&inverse, dx / r, -dy / r); |
Kristian Høgsberg | 765e27b | 2012-01-27 13:36:13 -0500 | [diff] [blame] | 5034 | weston_matrix_multiply(&surface->rotation.rotation, &inverse); |
Rafal Mielniczuk | 2d7ab82 | 2012-03-22 22:22:04 +0100 | [diff] [blame] | 5035 | |
| 5036 | weston_matrix_init(&rotate->rotation); |
Vasily Khoruzhick | 1bbf372 | 2013-01-28 22:40:28 +0300 | [diff] [blame] | 5037 | weston_matrix_rotate_xy(&rotate->rotation, dx / r, dy / r); |
Kristian Høgsberg | 765e27b | 2012-01-27 13:36:13 -0500 | [diff] [blame] | 5038 | } else { |
| 5039 | weston_matrix_init(&surface->rotation.rotation); |
| 5040 | weston_matrix_init(&rotate->rotation); |
| 5041 | } |
| 5042 | |
Ander Conselvan de Oliveira | b9d2a0f | 2012-06-28 18:08:05 +0300 | [diff] [blame] | 5043 | shell_grab_start(&rotate->base, &rotate_grab_interface, surface, |
Derek Foreman | 74de469 | 2015-07-15 13:00:39 -0500 | [diff] [blame] | 5044 | pointer, DESKTOP_SHELL_CURSOR_ARROW); |
Pekka Paalanen | 460099f | 2012-01-20 16:48:25 +0200 | [diff] [blame] | 5045 | } |
| 5046 | |
| 5047 | static void |
Derek Foreman | 8ae2db5 | 2015-07-15 13:00:36 -0500 | [diff] [blame] | 5048 | 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] | 5049 | void *data) |
| 5050 | { |
Rafal Mielniczuk | b2917a2 | 2014-01-05 20:04:59 +0100 | [diff] [blame] | 5051 | struct weston_surface *focus; |
Pekka Paalanen | 01388e2 | 2013-04-25 13:57:44 +0300 | [diff] [blame] | 5052 | struct weston_surface *base_surface; |
Kristian Høgsberg | 0c36903 | 2013-02-14 21:31:44 -0500 | [diff] [blame] | 5053 | struct shell_surface *surface; |
| 5054 | |
Derek Foreman | 8ae2db5 | 2015-07-15 13:00:36 -0500 | [diff] [blame] | 5055 | if (pointer->focus == NULL) |
Rafal Mielniczuk | b2917a2 | 2014-01-05 20:04:59 +0100 | [diff] [blame] | 5056 | return; |
| 5057 | |
Derek Foreman | 8ae2db5 | 2015-07-15 13:00:36 -0500 | [diff] [blame] | 5058 | focus = pointer->focus->surface; |
Rafal Mielniczuk | b2917a2 | 2014-01-05 20:04:59 +0100 | [diff] [blame] | 5059 | |
Pekka Paalanen | 01388e2 | 2013-04-25 13:57:44 +0300 | [diff] [blame] | 5060 | base_surface = weston_surface_get_main_surface(focus); |
Kristian Høgsberg | 0c36903 | 2013-02-14 21:31:44 -0500 | [diff] [blame] | 5061 | if (base_surface == NULL) |
| 5062 | return; |
| 5063 | |
| 5064 | surface = get_shell_surface(base_surface); |
Rafael Antognolli | 03b1659 | 2013-12-03 15:35:42 -0200 | [diff] [blame] | 5065 | if (surface == NULL || surface->state.fullscreen || |
| 5066 | surface->state.maximized) |
Kristian Høgsberg | 0c36903 | 2013-02-14 21:31:44 -0500 | [diff] [blame] | 5067 | return; |
| 5068 | |
Derek Foreman | 74de469 | 2015-07-15 13:00:39 -0500 | [diff] [blame] | 5069 | surface_rotate(surface, pointer); |
Kristian Høgsberg | 0c36903 | 2013-02-14 21:31:44 -0500 | [diff] [blame] | 5070 | } |
| 5071 | |
Emilio Pozuelo Monfort | 9e7c759 | 2014-01-30 14:01:10 +0100 | [diff] [blame] | 5072 | /* Move all fullscreen layers down to the current workspace and hide their |
| 5073 | * black views. The surfaces' state is set to both fullscreen and lowered, |
| 5074 | * and this is reversed when such a surface is re-configured, see |
| 5075 | * shell_configure_fullscreen() and shell_ensure_fullscreen_black_view(). |
| 5076 | * |
Mario Kleiner | 9f4d655 | 2015-06-21 21:25:08 +0200 | [diff] [blame] | 5077 | * lowering_output = NULL - Lower on all outputs, else only lower on the |
| 5078 | * specified output. |
| 5079 | * |
Emilio Pozuelo Monfort | 9e7c759 | 2014-01-30 14:01:10 +0100 | [diff] [blame] | 5080 | * This should be used when implementing shell-wide overlays, such as |
Philip Withnall | 83ffd9d | 2013-11-25 18:01:42 +0000 | [diff] [blame] | 5081 | * the alt-tab switcher, which need to de-promote fullscreen layers. */ |
Kristian Høgsberg | 1ef2313 | 2013-12-04 00:20:01 -0800 | [diff] [blame] | 5082 | void |
Mario Kleiner | 9f4d655 | 2015-06-21 21:25:08 +0200 | [diff] [blame] | 5083 | lower_fullscreen_layer(struct desktop_shell *shell, |
| 5084 | struct weston_output *lowering_output) |
Kristian Høgsberg | b0d8e77 | 2012-06-18 16:34:58 -0400 | [diff] [blame] | 5085 | { |
| 5086 | struct workspace *ws; |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 5087 | struct weston_view *view, *prev; |
Kristian Høgsberg | b0d8e77 | 2012-06-18 16:34:58 -0400 | [diff] [blame] | 5088 | |
| 5089 | ws = get_current_workspace(shell); |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 5090 | wl_list_for_each_reverse_safe(view, prev, |
Giulio Camuffo | 412e6a5 | 2014-07-09 22:12:56 +0300 | [diff] [blame] | 5091 | &shell->fullscreen_layer.view_list.link, |
| 5092 | layer_link.link) { |
Emilio Pozuelo Monfort | 9e7c759 | 2014-01-30 14:01:10 +0100 | [diff] [blame] | 5093 | struct shell_surface *shsurf = get_shell_surface(view->surface); |
| 5094 | |
| 5095 | if (!shsurf) |
| 5096 | continue; |
| 5097 | |
Mario Kleiner | 9f4d655 | 2015-06-21 21:25:08 +0200 | [diff] [blame] | 5098 | /* Only lower surfaces which have lowering_output as their fullscreen |
| 5099 | * output, unless a NULL output asks for lowering on all outputs. |
| 5100 | */ |
| 5101 | if (lowering_output && (shsurf->fullscreen_output != lowering_output)) |
| 5102 | continue; |
| 5103 | |
Emilio Pozuelo Monfort | 9e7c759 | 2014-01-30 14:01:10 +0100 | [diff] [blame] | 5104 | /* We can have a non-fullscreen popup for a fullscreen surface |
| 5105 | * in the fullscreen layer. */ |
| 5106 | if (shsurf->state.fullscreen) { |
| 5107 | /* Hide the black view */ |
Giulio Camuffo | 412e6a5 | 2014-07-09 22:12:56 +0300 | [diff] [blame] | 5108 | weston_layer_entry_remove(&shsurf->fullscreen.black_view->layer_link); |
| 5109 | wl_list_init(&shsurf->fullscreen.black_view->layer_link.link); |
Kristian Høgsberg | c991513 | 2014-05-09 16:24:07 -0700 | [diff] [blame] | 5110 | weston_view_damage_below(shsurf->fullscreen.black_view); |
| 5111 | |
Emilio Pozuelo Monfort | 9e7c759 | 2014-01-30 14:01:10 +0100 | [diff] [blame] | 5112 | } |
| 5113 | |
| 5114 | /* Lower the view to the workspace layer */ |
Giulio Camuffo | 412e6a5 | 2014-07-09 22:12:56 +0300 | [diff] [blame] | 5115 | weston_layer_entry_remove(&view->layer_link); |
| 5116 | weston_layer_entry_insert(&ws->layer.view_list, &view->layer_link); |
Philip Withnall | 83ffd9d | 2013-11-25 18:01:42 +0000 | [diff] [blame] | 5117 | weston_view_damage_below(view); |
| 5118 | weston_surface_damage(view->surface); |
Emilio Pozuelo Monfort | 9e7c759 | 2014-01-30 14:01:10 +0100 | [diff] [blame] | 5119 | |
| 5120 | shsurf->state.lowered = true; |
Philip Withnall | 83ffd9d | 2013-11-25 18:01:42 +0000 | [diff] [blame] | 5121 | } |
Kristian Høgsberg | b0d8e77 | 2012-06-18 16:34:58 -0400 | [diff] [blame] | 5122 | } |
| 5123 | |
Kristian Høgsberg | 1ef2313 | 2013-12-04 00:20:01 -0800 | [diff] [blame] | 5124 | void |
Tiago Vignatti | be14326 | 2012-04-16 17:31:41 +0300 | [diff] [blame] | 5125 | activate(struct desktop_shell *shell, struct weston_surface *es, |
Emilio Pozuelo Monfort | 9e7c759 | 2014-01-30 14:01:10 +0100 | [diff] [blame] | 5126 | struct weston_seat *seat, bool configure) |
Kristian Høgsberg | 7584062 | 2011-09-06 13:48:16 -0400 | [diff] [blame] | 5127 | { |
Pekka Paalanen | 01388e2 | 2013-04-25 13:57:44 +0300 | [diff] [blame] | 5128 | struct weston_surface *main_surface; |
Kristian Høgsberg | 2f5faff | 2012-07-31 16:36:34 -0400 | [diff] [blame] | 5129 | struct focus_state *state; |
Jonas Ådahl | 8538b22 | 2012-08-29 22:13:03 +0200 | [diff] [blame] | 5130 | struct workspace *ws; |
Louis-Francis Ratté-Boulianne | b482dbd | 2013-11-19 11:37:11 +0100 | [diff] [blame] | 5131 | struct weston_surface *old_es; |
Rafael Antognolli | 03b1659 | 2013-12-03 15:35:42 -0200 | [diff] [blame] | 5132 | struct shell_surface *shsurf; |
Kristian Høgsberg | 7584062 | 2011-09-06 13:48:16 -0400 | [diff] [blame] | 5133 | |
Pekka Paalanen | 01388e2 | 2013-04-25 13:57:44 +0300 | [diff] [blame] | 5134 | main_surface = weston_surface_get_main_surface(es); |
Mario Kleiner | 9f4d655 | 2015-06-21 21:25:08 +0200 | [diff] [blame] | 5135 | shsurf = get_shell_surface(main_surface); |
| 5136 | assert(shsurf); |
| 5137 | |
| 5138 | /* Only demote fullscreen surfaces on the output of activated shsurf. |
| 5139 | * Leave fullscreen surfaces on unrelated outputs alone. */ |
| 5140 | lower_fullscreen_layer(shell, shsurf->output); |
Pekka Paalanen | 01388e2 | 2013-04-25 13:57:44 +0300 | [diff] [blame] | 5141 | |
Daniel Stone | 37816df | 2012-05-16 18:45:18 +0100 | [diff] [blame] | 5142 | weston_surface_activate(es, seat); |
Kristian Høgsberg | 7584062 | 2011-09-06 13:48:16 -0400 | [diff] [blame] | 5143 | |
Jonas Ådahl | 8538b22 | 2012-08-29 22:13:03 +0200 | [diff] [blame] | 5144 | state = ensure_focus_state(shell, seat); |
| 5145 | if (state == NULL) |
| 5146 | return; |
Kristian Høgsberg | 2f5faff | 2012-07-31 16:36:34 -0400 | [diff] [blame] | 5147 | |
Louis-Francis Ratté-Boulianne | b482dbd | 2013-11-19 11:37:11 +0100 | [diff] [blame] | 5148 | old_es = state->keyboard_focus; |
Kristian Høgsberg | d500bf1 | 2014-01-22 12:25:20 -0800 | [diff] [blame] | 5149 | focus_state_set_focus(state, es); |
Kristian Høgsberg | 2f5faff | 2012-07-31 16:36:34 -0400 | [diff] [blame] | 5150 | |
Emilio Pozuelo Monfort | 9e7c759 | 2014-01-30 14:01:10 +0100 | [diff] [blame] | 5151 | if (shsurf->state.fullscreen && configure) |
Rafael Antognolli | 03b1659 | 2013-12-03 15:35:42 -0200 | [diff] [blame] | 5152 | shell_configure_fullscreen(shsurf); |
| 5153 | else |
Mario Kleiner | 492c12f | 2015-06-21 21:25:12 +0200 | [diff] [blame] | 5154 | restore_output_mode(shsurf->output); |
Louis-Francis Ratté-Boulianne | b482dbd | 2013-11-19 11:37:11 +0100 | [diff] [blame] | 5155 | |
Emilio Pozuelo Monfort | 7908bff | 2014-01-30 13:49:39 +0100 | [diff] [blame] | 5156 | /* Update the surface’s layer. This brings it to the top of the stacking |
| 5157 | * order as appropriate. */ |
| 5158 | shell_surface_update_layer(shsurf); |
| 5159 | |
Philip Withnall | 83ffd9d | 2013-11-25 18:01:42 +0000 | [diff] [blame] | 5160 | if (shell->focus_animation_type != ANIMATION_NONE) { |
| 5161 | ws = get_current_workspace(shell); |
Louis-Francis Ratté-Boulianne | b482dbd | 2013-11-19 11:37:11 +0100 | [diff] [blame] | 5162 | 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] | 5163 | } |
Kristian Høgsberg | 7584062 | 2011-09-06 13:48:16 -0400 | [diff] [blame] | 5164 | } |
| 5165 | |
Alex Wu | 2185843 | 2012-04-01 20:13:08 +0800 | [diff] [blame] | 5166 | /* no-op func for checking black surface */ |
| 5167 | static void |
Jason Ekstrand | 918f2dd | 2013-12-02 21:01:53 -0600 | [diff] [blame] | 5168 | 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] | 5169 | { |
| 5170 | } |
| 5171 | |
Quentin Glidic | c0d79ce | 2013-01-29 14:16:13 +0100 | [diff] [blame] | 5172 | static bool |
Alex Wu | 2185843 | 2012-04-01 20:13:08 +0800 | [diff] [blame] | 5173 | is_black_surface (struct weston_surface *es, struct weston_surface **fs_surface) |
| 5174 | { |
| 5175 | if (es->configure == black_surface_configure) { |
| 5176 | if (fs_surface) |
Giulio Camuffo | 7fe01b1 | 2013-03-28 18:02:42 +0100 | [diff] [blame] | 5177 | *fs_surface = (struct weston_surface *)es->configure_private; |
Alex Wu | 2185843 | 2012-04-01 20:13:08 +0800 | [diff] [blame] | 5178 | return true; |
| 5179 | } |
| 5180 | return false; |
| 5181 | } |
| 5182 | |
Kristian Høgsberg | 7584062 | 2011-09-06 13:48:16 -0400 | [diff] [blame] | 5183 | static void |
Neil Roberts | a28c693 | 2013-10-03 16:43:04 +0100 | [diff] [blame] | 5184 | activate_binding(struct weston_seat *seat, |
| 5185 | struct desktop_shell *shell, |
| 5186 | struct weston_surface *focus) |
Kristian Høgsberg | e1a850e | 2011-12-19 15:18:05 -0500 | [diff] [blame] | 5187 | { |
Pekka Paalanen | 01388e2 | 2013-04-25 13:57:44 +0300 | [diff] [blame] | 5188 | struct weston_surface *main_surface; |
Kristian Høgsberg | e1a850e | 2011-12-19 15:18:05 -0500 | [diff] [blame] | 5189 | |
Alex Wu | 9c35e6b | 2012-03-05 14:13:13 +0800 | [diff] [blame] | 5190 | if (!focus) |
| 5191 | return; |
| 5192 | |
Pekka Paalanen | 01388e2 | 2013-04-25 13:57:44 +0300 | [diff] [blame] | 5193 | if (is_black_surface(focus, &main_surface)) |
| 5194 | focus = main_surface; |
Alex Wu | 4539b08 | 2012-03-01 12:57:46 +0800 | [diff] [blame] | 5195 | |
Pekka Paalanen | 01388e2 | 2013-04-25 13:57:44 +0300 | [diff] [blame] | 5196 | main_surface = weston_surface_get_main_surface(focus); |
| 5197 | if (get_shell_surface_type(main_surface) == SHELL_SURFACE_NONE) |
Kristian Høgsberg | 0636ac3 | 2012-06-27 10:22:15 -0400 | [diff] [blame] | 5198 | return; |
Kristian Høgsberg | 85b2e4b | 2012-06-21 16:49:42 -0400 | [diff] [blame] | 5199 | |
Emilio Pozuelo Monfort | 9e7c759 | 2014-01-30 14:01:10 +0100 | [diff] [blame] | 5200 | activate(shell, focus, seat, true); |
Neil Roberts | a28c693 | 2013-10-03 16:43:04 +0100 | [diff] [blame] | 5201 | } |
| 5202 | |
| 5203 | static void |
Derek Foreman | 8ae2db5 | 2015-07-15 13:00:36 -0500 | [diff] [blame] | 5204 | click_to_activate_binding(struct weston_pointer *pointer, uint32_t time, |
| 5205 | uint32_t button, void *data) |
Neil Roberts | a28c693 | 2013-10-03 16:43:04 +0100 | [diff] [blame] | 5206 | { |
Derek Foreman | 8ae2db5 | 2015-07-15 13:00:36 -0500 | [diff] [blame] | 5207 | if (pointer->grab != &pointer->default_grab) |
Neil Roberts | a28c693 | 2013-10-03 16:43:04 +0100 | [diff] [blame] | 5208 | return; |
Derek Foreman | 8ae2db5 | 2015-07-15 13:00:36 -0500 | [diff] [blame] | 5209 | if (pointer->focus == NULL) |
Kristian Høgsberg | 7c4f6cc | 2014-01-01 16:28:32 -0800 | [diff] [blame] | 5210 | return; |
Neil Roberts | a28c693 | 2013-10-03 16:43:04 +0100 | [diff] [blame] | 5211 | |
Derek Foreman | 8ae2db5 | 2015-07-15 13:00:36 -0500 | [diff] [blame] | 5212 | activate_binding(pointer->seat, data, pointer->focus->surface); |
Neil Roberts | a28c693 | 2013-10-03 16:43:04 +0100 | [diff] [blame] | 5213 | } |
| 5214 | |
| 5215 | static void |
Derek Foreman | 8ae2db5 | 2015-07-15 13:00:36 -0500 | [diff] [blame] | 5216 | touch_to_activate_binding(struct weston_touch *touch, uint32_t time, |
| 5217 | void *data) |
Neil Roberts | a28c693 | 2013-10-03 16:43:04 +0100 | [diff] [blame] | 5218 | { |
Derek Foreman | 8ae2db5 | 2015-07-15 13:00:36 -0500 | [diff] [blame] | 5219 | if (touch->grab != &touch->default_grab) |
Neil Roberts | a28c693 | 2013-10-03 16:43:04 +0100 | [diff] [blame] | 5220 | return; |
Derek Foreman | 8ae2db5 | 2015-07-15 13:00:36 -0500 | [diff] [blame] | 5221 | if (touch->focus == NULL) |
Kristian Høgsberg | 0ed6750 | 2014-01-02 23:00:11 -0800 | [diff] [blame] | 5222 | return; |
Neil Roberts | a28c693 | 2013-10-03 16:43:04 +0100 | [diff] [blame] | 5223 | |
Derek Foreman | 8ae2db5 | 2015-07-15 13:00:36 -0500 | [diff] [blame] | 5224 | activate_binding(touch->seat, data, touch->focus->surface); |
Kristian Høgsberg | e1a850e | 2011-12-19 15:18:05 -0500 | [diff] [blame] | 5225 | } |
| 5226 | |
| 5227 | static void |
Neil Roberts | b4a9170 | 2014-04-09 16:33:32 +0100 | [diff] [blame] | 5228 | unfocus_all_seats(struct desktop_shell *shell) |
| 5229 | { |
| 5230 | struct weston_seat *seat, *next; |
| 5231 | |
| 5232 | wl_list_for_each_safe(seat, next, &shell->compositor->seat_list, link) { |
Derek Foreman | 1281a36 | 2015-07-31 16:55:32 -0500 | [diff] [blame] | 5233 | struct weston_keyboard *keyboard = |
| 5234 | weston_seat_get_keyboard(seat); |
| 5235 | |
| 5236 | if (!keyboard) |
Neil Roberts | b4a9170 | 2014-04-09 16:33:32 +0100 | [diff] [blame] | 5237 | continue; |
| 5238 | |
Derek Foreman | 1281a36 | 2015-07-31 16:55:32 -0500 | [diff] [blame] | 5239 | weston_keyboard_set_focus(keyboard, NULL); |
Neil Roberts | b4a9170 | 2014-04-09 16:33:32 +0100 | [diff] [blame] | 5240 | } |
| 5241 | } |
| 5242 | |
| 5243 | static void |
Ander Conselvan de Oliveira | 19d10ef | 2013-02-21 18:35:20 +0200 | [diff] [blame] | 5244 | lock(struct desktop_shell *shell) |
Kristian Høgsberg | 02ec0a5 | 2011-04-23 13:04:11 -0400 | [diff] [blame] | 5245 | { |
Kristian Høgsberg | 4476aaf | 2012-06-25 14:03:13 -0400 | [diff] [blame] | 5246 | struct workspace *ws = get_current_workspace(shell); |
Pekka Paalanen | f0fc70d | 2011-11-15 13:34:54 +0200 | [diff] [blame] | 5247 | |
Tiago Vignatti | 8e53c7f | 2012-02-29 19:53:50 +0200 | [diff] [blame] | 5248 | if (shell->locked) { |
Ander Conselvan de Oliveira | 87524b6 | 2013-02-21 18:35:22 +0200 | [diff] [blame] | 5249 | weston_compositor_sleep(shell->compositor); |
Pekka Paalanen | f0fc70d | 2011-11-15 13:34:54 +0200 | [diff] [blame] | 5250 | return; |
Tiago Vignatti | 8e53c7f | 2012-02-29 19:53:50 +0200 | [diff] [blame] | 5251 | } |
Pekka Paalanen | 9ef3e01 | 2011-11-15 13:34:48 +0200 | [diff] [blame] | 5252 | |
| 5253 | shell->locked = true; |
Pekka Paalanen | f0fc70d | 2011-11-15 13:34:54 +0200 | [diff] [blame] | 5254 | |
Kristian Høgsberg | 3be2ce9 | 2012-02-29 12:42:35 -0500 | [diff] [blame] | 5255 | /* Hide all surfaces by removing the fullscreen, panel and |
| 5256 | * toplevel layers. This way nothing else can show or receive |
| 5257 | * input events while we are locked. */ |
Pekka Paalanen | f0fc70d | 2011-11-15 13:34:54 +0200 | [diff] [blame] | 5258 | |
Kristian Høgsberg | 3be2ce9 | 2012-02-29 12:42:35 -0500 | [diff] [blame] | 5259 | wl_list_remove(&shell->panel_layer.link); |
Kristian Høgsberg | 3be2ce9 | 2012-02-29 12:42:35 -0500 | [diff] [blame] | 5260 | wl_list_remove(&shell->fullscreen_layer.link); |
Philipp Brüschweiler | 711fda8 | 2012-08-09 18:50:43 +0200 | [diff] [blame] | 5261 | if (shell->showing_input_panels) |
| 5262 | wl_list_remove(&shell->input_panel_layer.link); |
Kristian Høgsberg | 4476aaf | 2012-06-25 14:03:13 -0400 | [diff] [blame] | 5263 | wl_list_remove(&ws->layer.link); |
Kristian Høgsberg | 3be2ce9 | 2012-02-29 12:42:35 -0500 | [diff] [blame] | 5264 | wl_list_insert(&shell->compositor->cursor_layer.link, |
| 5265 | &shell->lock_layer.link); |
Pekka Paalanen | f0fc70d | 2011-11-15 13:34:54 +0200 | [diff] [blame] | 5266 | |
Derek Foreman | 004b4a1 | 2015-07-20 16:28:13 -0500 | [diff] [blame] | 5267 | weston_compositor_sleep(shell->compositor); |
| 5268 | |
Neil Roberts | b4a9170 | 2014-04-09 16:33:32 +0100 | [diff] [blame] | 5269 | /* Remove the keyboard focus on all seats. This will be |
| 5270 | * restored to the workspace's saved state via |
| 5271 | * restore_focus_state when the compositor is unlocked */ |
| 5272 | unfocus_all_seats(shell); |
| 5273 | |
Pekka Paalanen | f0fc70d | 2011-11-15 13:34:54 +0200 | [diff] [blame] | 5274 | /* TODO: disable bindings that should not work while locked. */ |
| 5275 | |
| 5276 | /* All this must be undone in resume_desktop(). */ |
Pekka Paalanen | 9ef3e01 | 2011-11-15 13:34:48 +0200 | [diff] [blame] | 5277 | } |
| 5278 | |
| 5279 | static void |
Ander Conselvan de Oliveira | 19d10ef | 2013-02-21 18:35:20 +0200 | [diff] [blame] | 5280 | unlock(struct desktop_shell *shell) |
Pekka Paalanen | 9ef3e01 | 2011-11-15 13:34:48 +0200 | [diff] [blame] | 5281 | { |
Pekka Paalanen | d81c216 | 2011-11-16 13:47:34 +0200 | [diff] [blame] | 5282 | if (!shell->locked || shell->lock_surface) { |
Ander Conselvan de Oliveira | 87524b6 | 2013-02-21 18:35:22 +0200 | [diff] [blame] | 5283 | shell_fade(shell, FADE_IN); |
Pekka Paalanen | 9ef3e01 | 2011-11-15 13:34:48 +0200 | [diff] [blame] | 5284 | return; |
| 5285 | } |
| 5286 | |
| 5287 | /* If desktop-shell client has gone away, unlock immediately. */ |
| 5288 | if (!shell->child.desktop_shell) { |
Pekka Paalanen | f0fc70d | 2011-11-15 13:34:54 +0200 | [diff] [blame] | 5289 | resume_desktop(shell); |
Pekka Paalanen | 9ef3e01 | 2011-11-15 13:34:48 +0200 | [diff] [blame] | 5290 | return; |
| 5291 | } |
| 5292 | |
| 5293 | if (shell->prepare_event_sent) |
| 5294 | return; |
| 5295 | |
Kristian Høgsberg | 0b5cd0c | 2012-03-04 21:57:37 -0500 | [diff] [blame] | 5296 | desktop_shell_send_prepare_lock_surface(shell->child.desktop_shell); |
Pekka Paalanen | 9ef3e01 | 2011-11-15 13:34:48 +0200 | [diff] [blame] | 5297 | shell->prepare_event_sent = true; |
Kristian Høgsberg | 02ec0a5 | 2011-04-23 13:04:11 -0400 | [diff] [blame] | 5298 | } |
| 5299 | |
| 5300 | static void |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 5301 | shell_fade_done(struct weston_view_animation *animation, void *data) |
Ander Conselvan de Oliveira | 19d10ef | 2013-02-21 18:35:20 +0200 | [diff] [blame] | 5302 | { |
| 5303 | struct desktop_shell *shell = data; |
| 5304 | |
| 5305 | shell->fade.animation = NULL; |
| 5306 | |
| 5307 | switch (shell->fade.type) { |
| 5308 | case FADE_IN: |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 5309 | weston_surface_destroy(shell->fade.view->surface); |
| 5310 | shell->fade.view = NULL; |
Ander Conselvan de Oliveira | 19d10ef | 2013-02-21 18:35:20 +0200 | [diff] [blame] | 5311 | break; |
| 5312 | case FADE_OUT: |
Ander Conselvan de Oliveira | 19d10ef | 2013-02-21 18:35:20 +0200 | [diff] [blame] | 5313 | lock(shell); |
| 5314 | break; |
Philip Withnall | 4a86a0a | 2013-11-25 18:01:32 +0000 | [diff] [blame] | 5315 | default: |
| 5316 | break; |
Ander Conselvan de Oliveira | 19d10ef | 2013-02-21 18:35:20 +0200 | [diff] [blame] | 5317 | } |
| 5318 | } |
| 5319 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 5320 | static struct weston_view * |
Pekka Paalanen | 79346ab | 2013-05-22 18:03:09 +0300 | [diff] [blame] | 5321 | shell_fade_create_surface(struct desktop_shell *shell) |
Ander Conselvan de Oliveira | 19d10ef | 2013-02-21 18:35:20 +0200 | [diff] [blame] | 5322 | { |
| 5323 | struct weston_compositor *compositor = shell->compositor; |
| 5324 | struct weston_surface *surface; |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 5325 | struct weston_view *view; |
Pekka Paalanen | 79346ab | 2013-05-22 18:03:09 +0300 | [diff] [blame] | 5326 | |
| 5327 | surface = weston_surface_create(compositor); |
| 5328 | if (!surface) |
| 5329 | return NULL; |
| 5330 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 5331 | view = weston_view_create(surface); |
| 5332 | if (!view) { |
| 5333 | weston_surface_destroy(surface); |
| 5334 | return NULL; |
| 5335 | } |
| 5336 | |
Jason Ekstrand | 5c11a33 | 2013-12-04 20:32:03 -0600 | [diff] [blame] | 5337 | weston_surface_set_size(surface, 8192, 8192); |
Jason Ekstrand | 918f2dd | 2013-12-02 21:01:53 -0600 | [diff] [blame] | 5338 | weston_view_set_position(view, 0, 0); |
Pekka Paalanen | 79346ab | 2013-05-22 18:03:09 +0300 | [diff] [blame] | 5339 | 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] | 5340 | weston_layer_entry_insert(&compositor->fade_layer.view_list, |
| 5341 | &view->layer_link); |
Pekka Paalanen | 79346ab | 2013-05-22 18:03:09 +0300 | [diff] [blame] | 5342 | pixman_region32_init(&surface->input); |
| 5343 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 5344 | return view; |
Pekka Paalanen | 79346ab | 2013-05-22 18:03:09 +0300 | [diff] [blame] | 5345 | } |
| 5346 | |
| 5347 | static void |
| 5348 | shell_fade(struct desktop_shell *shell, enum fade_type type) |
| 5349 | { |
Ander Conselvan de Oliveira | 19d10ef | 2013-02-21 18:35:20 +0200 | [diff] [blame] | 5350 | float tint; |
| 5351 | |
| 5352 | switch (type) { |
| 5353 | case FADE_IN: |
| 5354 | tint = 0.0; |
| 5355 | break; |
| 5356 | case FADE_OUT: |
| 5357 | tint = 1.0; |
| 5358 | break; |
| 5359 | default: |
| 5360 | weston_log("shell: invalid fade type\n"); |
| 5361 | return; |
| 5362 | } |
| 5363 | |
| 5364 | shell->fade.type = type; |
| 5365 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 5366 | if (shell->fade.view == NULL) { |
| 5367 | shell->fade.view = shell_fade_create_surface(shell); |
| 5368 | if (!shell->fade.view) |
Ander Conselvan de Oliveira | 19d10ef | 2013-02-21 18:35:20 +0200 | [diff] [blame] | 5369 | return; |
| 5370 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 5371 | shell->fade.view->alpha = 1.0 - tint; |
| 5372 | weston_view_update_transform(shell->fade.view); |
Ander Conselvan de Oliveira | 19d10ef | 2013-02-21 18:35:20 +0200 | [diff] [blame] | 5373 | } |
| 5374 | |
Kristian Høgsberg | 87d3b61 | 2014-01-19 21:48:10 -0800 | [diff] [blame] | 5375 | if (shell->fade.view->output == NULL) { |
| 5376 | /* If the black view gets a NULL output, we lost the |
| 5377 | * last output and we'll just cancel the fade. This |
| 5378 | * happens when you close the last window under the |
| 5379 | * X11 or Wayland backends. */ |
| 5380 | shell->locked = false; |
| 5381 | weston_surface_destroy(shell->fade.view->surface); |
| 5382 | shell->fade.view = NULL; |
| 5383 | } else if (shell->fade.animation) { |
Kristian Høgsberg | 5281fb1 | 2013-06-17 10:10:28 -0400 | [diff] [blame] | 5384 | weston_fade_update(shell->fade.animation, tint); |
Kristian Høgsberg | 87d3b61 | 2014-01-19 21:48:10 -0800 | [diff] [blame] | 5385 | } else { |
Ander Conselvan de Oliveira | 19d10ef | 2013-02-21 18:35:20 +0200 | [diff] [blame] | 5386 | shell->fade.animation = |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 5387 | weston_fade_run(shell->fade.view, |
Kristian Høgsberg | 5281fb1 | 2013-06-17 10:10:28 -0400 | [diff] [blame] | 5388 | 1.0 - tint, tint, 300.0, |
Ander Conselvan de Oliveira | 19d10ef | 2013-02-21 18:35:20 +0200 | [diff] [blame] | 5389 | shell_fade_done, shell); |
Kristian Høgsberg | 87d3b61 | 2014-01-19 21:48:10 -0800 | [diff] [blame] | 5390 | } |
Ander Conselvan de Oliveira | 19d10ef | 2013-02-21 18:35:20 +0200 | [diff] [blame] | 5391 | } |
| 5392 | |
| 5393 | static void |
Pekka Paalanen | 79346ab | 2013-05-22 18:03:09 +0300 | [diff] [blame] | 5394 | do_shell_fade_startup(void *data) |
| 5395 | { |
| 5396 | struct desktop_shell *shell = data; |
| 5397 | |
Pekka Paalanen | 23ed5f2 | 2015-05-26 11:54:52 +0300 | [diff] [blame] | 5398 | if (shell->startup_animation_type == ANIMATION_FADE) { |
Kristian Høgsberg | 724c8d9 | 2013-10-16 11:38:24 -0700 | [diff] [blame] | 5399 | shell_fade(shell, FADE_IN); |
Pekka Paalanen | 23ed5f2 | 2015-05-26 11:54:52 +0300 | [diff] [blame] | 5400 | } else { |
| 5401 | weston_log("desktop shell: " |
| 5402 | "unexpected fade-in animation type %d\n", |
| 5403 | shell->startup_animation_type); |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 5404 | weston_surface_destroy(shell->fade.view->surface); |
| 5405 | shell->fade.view = NULL; |
Kristian Høgsberg | 724c8d9 | 2013-10-16 11:38:24 -0700 | [diff] [blame] | 5406 | } |
Pekka Paalanen | 79346ab | 2013-05-22 18:03:09 +0300 | [diff] [blame] | 5407 | } |
| 5408 | |
| 5409 | static void |
| 5410 | shell_fade_startup(struct desktop_shell *shell) |
| 5411 | { |
| 5412 | struct wl_event_loop *loop; |
| 5413 | |
| 5414 | if (!shell->fade.startup_timer) |
| 5415 | return; |
| 5416 | |
| 5417 | wl_event_source_remove(shell->fade.startup_timer); |
| 5418 | shell->fade.startup_timer = NULL; |
| 5419 | |
| 5420 | loop = wl_display_get_event_loop(shell->compositor->wl_display); |
| 5421 | wl_event_loop_add_idle(loop, do_shell_fade_startup, shell); |
| 5422 | } |
| 5423 | |
| 5424 | static int |
| 5425 | fade_startup_timeout(void *data) |
| 5426 | { |
| 5427 | struct desktop_shell *shell = data; |
| 5428 | |
| 5429 | shell_fade_startup(shell); |
| 5430 | return 0; |
| 5431 | } |
| 5432 | |
| 5433 | static void |
| 5434 | shell_fade_init(struct desktop_shell *shell) |
| 5435 | { |
| 5436 | /* Make compositor output all black, and wait for the desktop-shell |
| 5437 | * client to signal it is ready, then fade in. The timer triggers a |
| 5438 | * fade-in, in case the desktop-shell client takes too long. |
| 5439 | */ |
| 5440 | |
| 5441 | struct wl_event_loop *loop; |
| 5442 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 5443 | if (shell->fade.view != NULL) { |
Pekka Paalanen | 79346ab | 2013-05-22 18:03:09 +0300 | [diff] [blame] | 5444 | weston_log("%s: warning: fade surface already exists\n", |
| 5445 | __func__); |
| 5446 | return; |
| 5447 | } |
| 5448 | |
Pekka Paalanen | 23ed5f2 | 2015-05-26 11:54:52 +0300 | [diff] [blame] | 5449 | if (shell->startup_animation_type == ANIMATION_NONE) |
| 5450 | return; |
| 5451 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 5452 | shell->fade.view = shell_fade_create_surface(shell); |
| 5453 | if (!shell->fade.view) |
Pekka Paalanen | 79346ab | 2013-05-22 18:03:09 +0300 | [diff] [blame] | 5454 | return; |
| 5455 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 5456 | weston_view_update_transform(shell->fade.view); |
| 5457 | weston_surface_damage(shell->fade.view->surface); |
Pekka Paalanen | 79346ab | 2013-05-22 18:03:09 +0300 | [diff] [blame] | 5458 | |
| 5459 | loop = wl_display_get_event_loop(shell->compositor->wl_display); |
| 5460 | shell->fade.startup_timer = |
| 5461 | wl_event_loop_add_timer(loop, fade_startup_timeout, shell); |
| 5462 | wl_event_source_timer_update(shell->fade.startup_timer, 15000); |
| 5463 | } |
| 5464 | |
| 5465 | static void |
Ander Conselvan de Oliveira | a457563 | 2013-02-21 18:35:23 +0200 | [diff] [blame] | 5466 | idle_handler(struct wl_listener *listener, void *data) |
Ander Conselvan de Oliveira | 19d10ef | 2013-02-21 18:35:20 +0200 | [diff] [blame] | 5467 | { |
| 5468 | struct desktop_shell *shell = |
Ander Conselvan de Oliveira | a457563 | 2013-02-21 18:35:23 +0200 | [diff] [blame] | 5469 | container_of(listener, struct desktop_shell, idle_listener); |
Kristian Høgsberg | 27d5fa8 | 2014-01-17 16:22:50 -0800 | [diff] [blame] | 5470 | struct weston_seat *seat; |
| 5471 | |
Jonny Lamb | 76cf1fe | 2014-08-20 11:27:10 +0200 | [diff] [blame] | 5472 | wl_list_for_each(seat, &shell->compositor->seat_list, link) { |
Derek Foreman | 1281a36 | 2015-07-31 16:55:32 -0500 | [diff] [blame] | 5473 | struct weston_touch *touch = weston_seat_get_touch(seat); |
| 5474 | struct weston_pointer *pointer = weston_seat_get_pointer(seat); |
| 5475 | |
| 5476 | if (pointer) |
| 5477 | popup_grab_end(pointer); |
| 5478 | if (touch) |
| 5479 | touch_popup_grab_end(touch); |
Jonny Lamb | 76cf1fe | 2014-08-20 11:27:10 +0200 | [diff] [blame] | 5480 | } |
Ander Conselvan de Oliveira | 19d10ef | 2013-02-21 18:35:20 +0200 | [diff] [blame] | 5481 | |
| 5482 | shell_fade(shell, FADE_OUT); |
| 5483 | /* lock() is called from shell_fade_done() */ |
| 5484 | } |
| 5485 | |
| 5486 | static void |
Ander Conselvan de Oliveira | a457563 | 2013-02-21 18:35:23 +0200 | [diff] [blame] | 5487 | wake_handler(struct wl_listener *listener, void *data) |
Ander Conselvan de Oliveira | 19d10ef | 2013-02-21 18:35:20 +0200 | [diff] [blame] | 5488 | { |
| 5489 | struct desktop_shell *shell = |
Ander Conselvan de Oliveira | a457563 | 2013-02-21 18:35:23 +0200 | [diff] [blame] | 5490 | container_of(listener, struct desktop_shell, wake_listener); |
Ander Conselvan de Oliveira | 19d10ef | 2013-02-21 18:35:20 +0200 | [diff] [blame] | 5491 | |
Ander Conselvan de Oliveira | 19d10ef | 2013-02-21 18:35:20 +0200 | [diff] [blame] | 5492 | unlock(shell); |
| 5493 | } |
| 5494 | |
| 5495 | static void |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 5496 | center_on_output(struct weston_view *view, struct weston_output *output) |
Pekka Paalanen | 77346a6 | 2011-11-30 16:26:35 +0200 | [diff] [blame] | 5497 | { |
Giulio Camuffo | b836664 | 2013-04-25 13:57:46 +0300 | [diff] [blame] | 5498 | int32_t surf_x, surf_y, width, height; |
Ander Conselvan de Oliveira | 012b4c7 | 2012-11-27 17:03:42 +0200 | [diff] [blame] | 5499 | float x, y; |
Pekka Paalanen | 77346a6 | 2011-11-30 16:26:35 +0200 | [diff] [blame] | 5500 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 5501 | surface_subsurfaces_boundingbox(view->surface, &surf_x, &surf_y, &width, &height); |
Giulio Camuffo | b836664 | 2013-04-25 13:57:46 +0300 | [diff] [blame] | 5502 | |
| 5503 | x = output->x + (output->width - width) / 2 - surf_x / 2; |
| 5504 | y = output->y + (output->height - height) / 2 - surf_y / 2; |
Ander Conselvan de Oliveira | 012b4c7 | 2012-11-27 17:03:42 +0200 | [diff] [blame] | 5505 | |
Jason Ekstrand | 918f2dd | 2013-12-02 21:01:53 -0600 | [diff] [blame] | 5506 | weston_view_set_position(view, x, y); |
Pekka Paalanen | 77346a6 | 2011-11-30 16:26:35 +0200 | [diff] [blame] | 5507 | } |
| 5508 | |
| 5509 | static void |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 5510 | weston_view_set_initial_position(struct weston_view *view, |
| 5511 | struct desktop_shell *shell) |
Rob Bradford | ac63e5b | 2012-08-13 14:07:52 +0100 | [diff] [blame] | 5512 | { |
| 5513 | struct weston_compositor *compositor = shell->compositor; |
| 5514 | int ix = 0, iy = 0; |
Jonny Lamb | d73c694 | 2014-08-20 15:53:20 +0200 | [diff] [blame] | 5515 | int32_t range_x, range_y; |
Derek Foreman | f814c5d | 2015-04-15 12:23:54 -0500 | [diff] [blame] | 5516 | int32_t x, y; |
Rob Bradford | ac63e5b | 2012-08-13 14:07:52 +0100 | [diff] [blame] | 5517 | struct weston_output *output, *target_output = NULL; |
| 5518 | struct weston_seat *seat; |
Jonny Lamb | d73c694 | 2014-08-20 15:53:20 +0200 | [diff] [blame] | 5519 | pixman_rectangle32_t area; |
Rob Bradford | ac63e5b | 2012-08-13 14:07:52 +0100 | [diff] [blame] | 5520 | |
| 5521 | /* As a heuristic place the new window on the same output as the |
| 5522 | * pointer. Falling back to the output containing 0, 0. |
| 5523 | * |
| 5524 | * TODO: Do something clever for touch too? |
| 5525 | */ |
| 5526 | wl_list_for_each(seat, &compositor->seat_list, link) { |
Derek Foreman | 1281a36 | 2015-07-31 16:55:32 -0500 | [diff] [blame] | 5527 | struct weston_pointer *pointer = weston_seat_get_pointer(seat); |
| 5528 | |
| 5529 | if (pointer) { |
| 5530 | ix = wl_fixed_to_int(pointer->x); |
| 5531 | iy = wl_fixed_to_int(pointer->y); |
Rob Bradford | ac63e5b | 2012-08-13 14:07:52 +0100 | [diff] [blame] | 5532 | break; |
| 5533 | } |
| 5534 | } |
| 5535 | |
| 5536 | wl_list_for_each(output, &compositor->output_list, link) { |
| 5537 | if (pixman_region32_contains_point(&output->region, ix, iy, NULL)) { |
| 5538 | target_output = output; |
| 5539 | break; |
| 5540 | } |
| 5541 | } |
| 5542 | |
| 5543 | if (!target_output) { |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 5544 | weston_view_set_position(view, 10 + random() % 400, |
| 5545 | 10 + random() % 400); |
Rob Bradford | ac63e5b | 2012-08-13 14:07:52 +0100 | [diff] [blame] | 5546 | return; |
| 5547 | } |
| 5548 | |
| 5549 | /* Valid range within output where the surface will still be onscreen. |
| 5550 | * If this is negative it means that the surface is bigger than |
| 5551 | * output. |
| 5552 | */ |
Jonny Lamb | d73c694 | 2014-08-20 15:53:20 +0200 | [diff] [blame] | 5553 | get_output_work_area(shell, target_output, &area); |
| 5554 | |
Derek Foreman | f814c5d | 2015-04-15 12:23:54 -0500 | [diff] [blame] | 5555 | x = area.x; |
| 5556 | y = area.y; |
Jonny Lamb | d73c694 | 2014-08-20 15:53:20 +0200 | [diff] [blame] | 5557 | range_x = area.width - view->surface->width; |
| 5558 | range_y = area.height - view->surface->height; |
Rob Bradford | ac63e5b | 2012-08-13 14:07:52 +0100 | [diff] [blame] | 5559 | |
Rob Bradford | 4cb88c7 | 2012-08-13 15:18:44 +0100 | [diff] [blame] | 5560 | if (range_x > 0) |
Derek Foreman | f814c5d | 2015-04-15 12:23:54 -0500 | [diff] [blame] | 5561 | x += random() % range_x; |
Rob Bradford | 4cb88c7 | 2012-08-13 15:18:44 +0100 | [diff] [blame] | 5562 | |
| 5563 | if (range_y > 0) |
Derek Foreman | f814c5d | 2015-04-15 12:23:54 -0500 | [diff] [blame] | 5564 | y += random() % range_y; |
Rob Bradford | ac63e5b | 2012-08-13 14:07:52 +0100 | [diff] [blame] | 5565 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 5566 | weston_view_set_position(view, x, y); |
Rob Bradford | ac63e5b | 2012-08-13 14:07:52 +0100 | [diff] [blame] | 5567 | } |
| 5568 | |
| 5569 | static void |
Jonny Lamb | d73c694 | 2014-08-20 15:53:20 +0200 | [diff] [blame] | 5570 | set_maximized_position(struct desktop_shell *shell, |
| 5571 | struct shell_surface *shsurf) |
| 5572 | { |
| 5573 | int32_t surf_x, surf_y; |
| 5574 | pixman_rectangle32_t area; |
Marek Chalupa | 8b771af | 2014-09-01 17:20:33 +0200 | [diff] [blame] | 5575 | pixman_box32_t *e; |
Jonny Lamb | d73c694 | 2014-08-20 15:53:20 +0200 | [diff] [blame] | 5576 | |
Jonny Lamb | d73c694 | 2014-08-20 15:53:20 +0200 | [diff] [blame] | 5577 | get_output_work_area(shell, shsurf->output, &area); |
Giulio Camuffo | 7a8d67d | 2015-01-09 20:10:45 +0200 | [diff] [blame] | 5578 | if (shsurf->has_set_geometry) { |
| 5579 | surf_x = shsurf->geometry.x; |
| 5580 | surf_y = shsurf->geometry.y; |
| 5581 | } else { |
| 5582 | surface_subsurfaces_boundingbox(shsurf->surface, |
| 5583 | &surf_x, &surf_y, NULL, NULL); |
| 5584 | } |
Marek Chalupa | 8b771af | 2014-09-01 17:20:33 +0200 | [diff] [blame] | 5585 | e = pixman_region32_extents(&shsurf->output->region); |
Jonny Lamb | d73c694 | 2014-08-20 15:53:20 +0200 | [diff] [blame] | 5586 | |
| 5587 | weston_view_set_position(shsurf->view, |
Marek Chalupa | 8b771af | 2014-09-01 17:20:33 +0200 | [diff] [blame] | 5588 | e->x1 + area.x - surf_x, |
| 5589 | e->y1 + area.y - surf_y); |
Jonny Lamb | d73c694 | 2014-08-20 15:53:20 +0200 | [diff] [blame] | 5590 | } |
| 5591 | |
| 5592 | static void |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 5593 | map(struct desktop_shell *shell, struct shell_surface *shsurf, |
Jason Ekstrand | 918f2dd | 2013-12-02 21:01:53 -0600 | [diff] [blame] | 5594 | int32_t sx, int32_t sy) |
Kristian Høgsberg | 02ec0a5 | 2011-04-23 13:04:11 -0400 | [diff] [blame] | 5595 | { |
Kristian Høgsberg | 8334bc1 | 2012-01-03 10:29:47 -0500 | [diff] [blame] | 5596 | struct weston_compositor *compositor = shell->compositor; |
Daniel Stone | b210468 | 2012-05-30 16:31:56 +0100 | [diff] [blame] | 5597 | struct weston_seat *seat; |
Pekka Paalanen | 57da4a8 | 2011-11-23 16:42:16 +0200 | [diff] [blame] | 5598 | |
Pekka Paalanen | 77346a6 | 2011-11-30 16:26:35 +0200 | [diff] [blame] | 5599 | /* initial positioning, see also configure() */ |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 5600 | switch (shsurf->type) { |
Rafael Antognolli | ed207b4 | 2013-12-03 15:35:43 -0200 | [diff] [blame] | 5601 | case SHELL_SURFACE_TOPLEVEL: |
Rafael Antognolli | 03b1659 | 2013-12-03 15:35:42 -0200 | [diff] [blame] | 5602 | if (shsurf->state.fullscreen) { |
| 5603 | center_on_output(shsurf->view, shsurf->fullscreen_output); |
| 5604 | shell_map_fullscreen(shsurf); |
| 5605 | } else if (shsurf->state.maximized) { |
Jonny Lamb | d73c694 | 2014-08-20 15:53:20 +0200 | [diff] [blame] | 5606 | set_maximized_position(shell, shsurf); |
Rafael Antognolli | ed207b4 | 2013-12-03 15:35:43 -0200 | [diff] [blame] | 5607 | } else if (!shsurf->state.relative) { |
Rafael Antognolli | 03b1659 | 2013-12-03 15:35:42 -0200 | [diff] [blame] | 5608 | weston_view_set_initial_position(shsurf->view, shell); |
| 5609 | } |
Juan Zhao | 96879df | 2012-02-07 08:45:41 +0800 | [diff] [blame] | 5610 | break; |
Tiago Vignatti | 0f99701 | 2012-02-10 16:17:23 +0200 | [diff] [blame] | 5611 | case SHELL_SURFACE_POPUP: |
Jasper St. Pierre | da6ecd0 | 2015-02-27 18:35:45 +0800 | [diff] [blame] | 5612 | if (shell_map_popup(shsurf) != 0) |
| 5613 | return; |
Rob Bradford | db99938 | 2012-12-06 12:07:48 +0000 | [diff] [blame] | 5614 | break; |
Ander Conselvan de Oliveira | e9e0515 | 2012-02-15 17:02:56 +0200 | [diff] [blame] | 5615 | case SHELL_SURFACE_NONE: |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 5616 | weston_view_set_position(shsurf->view, |
| 5617 | shsurf->view->geometry.x + sx, |
| 5618 | shsurf->view->geometry.y + sy); |
Tiago Vignatti | 0f99701 | 2012-02-10 16:17:23 +0200 | [diff] [blame] | 5619 | break; |
Philip Withnall | 0f640e2 | 2013-11-25 18:01:31 +0000 | [diff] [blame] | 5620 | case SHELL_SURFACE_XWAYLAND: |
Pekka Paalanen | 77346a6 | 2011-11-30 16:26:35 +0200 | [diff] [blame] | 5621 | default: |
| 5622 | ; |
| 5623 | } |
Kristian Høgsberg | 7584062 | 2011-09-06 13:48:16 -0400 | [diff] [blame] | 5624 | |
Philip Withnall | e1d75ae | 2013-11-25 18:01:41 +0000 | [diff] [blame] | 5625 | /* Surface stacking order, see also activate(). */ |
| 5626 | shell_surface_update_layer(shsurf); |
Pekka Paalanen | f0fc70d | 2011-11-15 13:34:54 +0200 | [diff] [blame] | 5627 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 5628 | if (shsurf->type != SHELL_SURFACE_NONE) { |
| 5629 | weston_view_update_transform(shsurf->view); |
Rafael Antognolli | 03b1659 | 2013-12-03 15:35:42 -0200 | [diff] [blame] | 5630 | if (shsurf->state.maximized) { |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 5631 | shsurf->surface->output = shsurf->output; |
| 5632 | shsurf->view->output = shsurf->output; |
| 5633 | } |
Ander Conselvan de Oliveira | de56c31 | 2012-03-05 15:39:23 +0200 | [diff] [blame] | 5634 | } |
Kristian Høgsberg | 2f88a40 | 2011-12-04 15:32:59 -0500 | [diff] [blame] | 5635 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 5636 | switch (shsurf->type) { |
Tiago Vignatti | fb2adba | 2013-06-12 15:43:21 -0300 | [diff] [blame] | 5637 | /* XXX: xwayland's using the same fields for transient type */ |
| 5638 | case SHELL_SURFACE_XWAYLAND: |
Tiago Vignatti | 99aeb1e | 2012-05-23 22:06:26 +0300 | [diff] [blame] | 5639 | if (shsurf->transient.flags == |
| 5640 | WL_SHELL_SURFACE_TRANSIENT_INACTIVE) |
| 5641 | break; |
| 5642 | case SHELL_SURFACE_TOPLEVEL: |
Rafael Antognolli | ed207b4 | 2013-12-03 15:35:43 -0200 | [diff] [blame] | 5643 | if (shsurf->state.relative && |
| 5644 | shsurf->transient.flags == WL_SHELL_SURFACE_TRANSIENT_INACTIVE) |
| 5645 | break; |
Rafael Antognolli | ba5d2d7 | 2013-12-04 17:49:55 -0200 | [diff] [blame] | 5646 | if (shell->locked) |
Rafael Antognolli | ed207b4 | 2013-12-03 15:35:43 -0200 | [diff] [blame] | 5647 | break; |
| 5648 | wl_list_for_each(seat, &compositor->seat_list, link) |
Emilio Pozuelo Monfort | 9e7c759 | 2014-01-30 14:01:10 +0100 | [diff] [blame] | 5649 | activate(shell, shsurf->surface, seat, true); |
Juan Zhao | 7bb92f0 | 2011-12-15 11:31:51 -0500 | [diff] [blame] | 5650 | break; |
Philip Withnall | 0f640e2 | 2013-11-25 18:01:31 +0000 | [diff] [blame] | 5651 | case SHELL_SURFACE_POPUP: |
| 5652 | case SHELL_SURFACE_NONE: |
Juan Zhao | 7bb92f0 | 2011-12-15 11:31:51 -0500 | [diff] [blame] | 5653 | default: |
| 5654 | break; |
| 5655 | } |
| 5656 | |
Rafael Antognolli | 03b1659 | 2013-12-03 15:35:42 -0200 | [diff] [blame] | 5657 | if (shsurf->type == SHELL_SURFACE_TOPLEVEL && |
| 5658 | !shsurf->state.maximized && !shsurf->state.fullscreen) |
Juan Zhao | e10d279 | 2012-04-25 19:09:52 +0800 | [diff] [blame] | 5659 | { |
| 5660 | switch (shell->win_animation_type) { |
| 5661 | case ANIMATION_FADE: |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 5662 | 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] | 5663 | break; |
| 5664 | case ANIMATION_ZOOM: |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 5665 | weston_zoom_run(shsurf->view, 0.5, 1.0, NULL, NULL); |
Juan Zhao | e10d279 | 2012-04-25 19:09:52 +0800 | [diff] [blame] | 5666 | break; |
Philip Withnall | 4a86a0a | 2013-11-25 18:01:32 +0000 | [diff] [blame] | 5667 | case ANIMATION_NONE: |
Juan Zhao | e10d279 | 2012-04-25 19:09:52 +0800 | [diff] [blame] | 5668 | default: |
| 5669 | break; |
| 5670 | } |
| 5671 | } |
Kristian Høgsberg | 32e24cc | 2011-11-09 12:07:35 -0500 | [diff] [blame] | 5672 | } |
| 5673 | |
| 5674 | static void |
Tiago Vignatti | be14326 | 2012-04-16 17:31:41 +0300 | [diff] [blame] | 5675 | configure(struct desktop_shell *shell, struct weston_surface *surface, |
Jason Ekstrand | 918f2dd | 2013-12-02 21:01:53 -0600 | [diff] [blame] | 5676 | float x, float y) |
Kristian Høgsberg | 32e24cc | 2011-11-09 12:07:35 -0500 | [diff] [blame] | 5677 | { |
Pekka Paalanen | 77346a6 | 2011-11-30 16:26:35 +0200 | [diff] [blame] | 5678 | struct shell_surface *shsurf; |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 5679 | struct weston_view *view; |
Kristian Høgsberg | 32e24cc | 2011-11-09 12:07:35 -0500 | [diff] [blame] | 5680 | |
Pekka Paalanen | 77346a6 | 2011-11-30 16:26:35 +0200 | [diff] [blame] | 5681 | shsurf = get_shell_surface(surface); |
Pekka Paalanen | 77346a6 | 2011-11-30 16:26:35 +0200 | [diff] [blame] | 5682 | |
U. Artie Eoff | cf5737a | 2014-01-17 10:08:25 -0800 | [diff] [blame] | 5683 | assert(shsurf); |
| 5684 | |
Rafael Antognolli | 03b1659 | 2013-12-03 15:35:42 -0200 | [diff] [blame] | 5685 | if (shsurf->state.fullscreen) |
Alex Wu | 4539b08 | 2012-03-01 12:57:46 +0800 | [diff] [blame] | 5686 | shell_configure_fullscreen(shsurf); |
Rafael Antognolli | 03b1659 | 2013-12-03 15:35:42 -0200 | [diff] [blame] | 5687 | else if (shsurf->state.maximized) { |
Jonny Lamb | d73c694 | 2014-08-20 15:53:20 +0200 | [diff] [blame] | 5688 | set_maximized_position(shell, shsurf); |
Rafael Antognolli | 03b1659 | 2013-12-03 15:35:42 -0200 | [diff] [blame] | 5689 | } else { |
Jason Ekstrand | 918f2dd | 2013-12-02 21:01:53 -0600 | [diff] [blame] | 5690 | weston_view_set_position(shsurf->view, x, y); |
Kristian Høgsberg | 7a5c979 | 2011-06-18 06:12:54 -0400 | [diff] [blame] | 5691 | } |
Kristian Høgsberg | 32e24cc | 2011-11-09 12:07:35 -0500 | [diff] [blame] | 5692 | |
Alex Wu | 4539b08 | 2012-03-01 12:57:46 +0800 | [diff] [blame] | 5693 | /* XXX: would a fullscreen surface need the same handling? */ |
Kristian Høgsberg | 6a8b553 | 2012-02-16 23:43:59 -0500 | [diff] [blame] | 5694 | if (surface->output) { |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 5695 | wl_list_for_each(view, &surface->views, surface_link) |
| 5696 | weston_view_update_transform(view); |
Pekka Paalanen | 77346a6 | 2011-11-30 16:26:35 +0200 | [diff] [blame] | 5697 | |
Rafael Antognolli | 03b1659 | 2013-12-03 15:35:42 -0200 | [diff] [blame] | 5698 | if (shsurf->state.maximized) |
Juan Zhao | 96879df | 2012-02-07 08:45:41 +0800 | [diff] [blame] | 5699 | surface->output = shsurf->output; |
Pekka Paalanen | 77346a6 | 2011-11-30 16:26:35 +0200 | [diff] [blame] | 5700 | } |
Kristian Høgsberg | 0793756 | 2011-04-12 17:25:42 -0400 | [diff] [blame] | 5701 | } |
| 5702 | |
Ander Conselvan de Oliveira | 093bfa3 | 2012-03-27 17:36:41 +0300 | [diff] [blame] | 5703 | static void |
Jason Ekstrand | 918f2dd | 2013-12-02 21:01:53 -0600 | [diff] [blame] | 5704 | 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] | 5705 | { |
Ander Conselvan de Oliveira | 7fb9f95 | 2012-03-27 17:36:42 +0300 | [diff] [blame] | 5706 | struct shell_surface *shsurf = get_shell_surface(es); |
U. Artie Eoff | cf5737a | 2014-01-17 10:08:25 -0800 | [diff] [blame] | 5707 | struct desktop_shell *shell; |
Tiago Vignatti | 70e5c9c | 2012-05-07 15:23:07 +0300 | [diff] [blame] | 5708 | int type_changed = 0; |
Ander Conselvan de Oliveira | 093bfa3 | 2012-03-27 17:36:41 +0300 | [diff] [blame] | 5709 | |
U. Artie Eoff | cf5737a | 2014-01-17 10:08:25 -0800 | [diff] [blame] | 5710 | assert(shsurf); |
| 5711 | |
| 5712 | shell = shsurf->shell; |
| 5713 | |
Kristian Høgsberg | 8eb0f4f | 2013-06-17 10:33:14 -0400 | [diff] [blame] | 5714 | if (!weston_surface_is_mapped(es) && |
| 5715 | !wl_list_empty(&shsurf->popup.grab_link)) { |
Giulio Camuffo | 5085a75 | 2013-03-25 21:42:45 +0100 | [diff] [blame] | 5716 | remove_popup_grab(shsurf); |
| 5717 | } |
| 5718 | |
Jason Ekstrand | 918f2dd | 2013-12-02 21:01:53 -0600 | [diff] [blame] | 5719 | if (es->width == 0) |
Giulio Camuffo | 184df50 | 2013-02-21 11:29:21 +0100 | [diff] [blame] | 5720 | return; |
| 5721 | |
Jasper St. Pierre | ccf48fb | 2014-05-02 10:21:38 -0400 | [diff] [blame] | 5722 | if (shsurf->has_next_geometry) { |
| 5723 | shsurf->geometry = shsurf->next_geometry; |
| 5724 | shsurf->has_next_geometry = false; |
| 5725 | shsurf->has_set_geometry = true; |
| 5726 | } else if (!shsurf->has_set_geometry) { |
| 5727 | surface_subsurfaces_boundingbox(shsurf->surface, |
| 5728 | &shsurf->geometry.x, |
| 5729 | &shsurf->geometry.y, |
| 5730 | &shsurf->geometry.width, |
| 5731 | &shsurf->geometry.height); |
Jasper St. Pierre | 851799e | 2014-05-02 10:14:07 -0400 | [diff] [blame] | 5732 | } |
| 5733 | |
Kristian Høgsberg | c8f8dd8 | 2013-12-05 23:20:33 -0800 | [diff] [blame] | 5734 | if (shsurf->state_changed) { |
Kristian Høgsberg | 7f366e7 | 2012-04-27 17:20:01 -0400 | [diff] [blame] | 5735 | set_surface_type(shsurf); |
Kristian Høgsberg | f7e23d5 | 2012-04-27 17:51:59 -0400 | [diff] [blame] | 5736 | type_changed = 1; |
| 5737 | } |
Kristian Høgsberg | 7f366e7 | 2012-04-27 17:20:01 -0400 | [diff] [blame] | 5738 | |
Ander Conselvan de Oliveira | 093bfa3 | 2012-03-27 17:36:41 +0300 | [diff] [blame] | 5739 | if (!weston_surface_is_mapped(es)) { |
Jason Ekstrand | 918f2dd | 2013-12-02 21:01:53 -0600 | [diff] [blame] | 5740 | map(shell, shsurf, sx, sy); |
Kristian Høgsberg | f7e23d5 | 2012-04-27 17:51:59 -0400 | [diff] [blame] | 5741 | } else if (type_changed || sx != 0 || sy != 0 || |
Jason Ekstrand | 918f2dd | 2013-12-02 21:01:53 -0600 | [diff] [blame] | 5742 | shsurf->last_width != es->width || |
| 5743 | shsurf->last_height != es->height) { |
John Kåre Alsaker | 490d02a | 2012-09-30 02:57:21 +0200 | [diff] [blame] | 5744 | float from_x, from_y; |
| 5745 | float to_x, to_y; |
Ander Conselvan de Oliveira | 093bfa3 | 2012-03-27 17:36:41 +0300 | [diff] [blame] | 5746 | |
Kristian Høgsberg | 44cd196 | 2014-02-05 21:36:04 -0800 | [diff] [blame] | 5747 | if (shsurf->resize_edges) { |
| 5748 | sx = 0; |
| 5749 | sy = 0; |
| 5750 | } |
| 5751 | |
| 5752 | if (shsurf->resize_edges & WL_SHELL_SURFACE_RESIZE_LEFT) |
| 5753 | sx = shsurf->last_width - es->width; |
| 5754 | if (shsurf->resize_edges & WL_SHELL_SURFACE_RESIZE_TOP) |
| 5755 | sy = shsurf->last_height - es->height; |
| 5756 | |
| 5757 | shsurf->last_width = es->width; |
| 5758 | shsurf->last_height = es->height; |
| 5759 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 5760 | weston_view_to_global_float(shsurf->view, 0, 0, &from_x, &from_y); |
| 5761 | 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] | 5762 | configure(shell, es, |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 5763 | shsurf->view->geometry.x + to_x - from_x, |
Jason Ekstrand | 918f2dd | 2013-12-02 21:01:53 -0600 | [diff] [blame] | 5764 | shsurf->view->geometry.y + to_y - from_y); |
Ander Conselvan de Oliveira | 093bfa3 | 2012-03-27 17:36:41 +0300 | [diff] [blame] | 5765 | } |
| 5766 | } |
| 5767 | |
Pekka Paalanen | 2e62e4a | 2014-08-28 11:41:26 +0300 | [diff] [blame] | 5768 | static bool |
| 5769 | check_desktop_shell_crash_too_early(struct desktop_shell *shell) |
| 5770 | { |
| 5771 | struct timespec now; |
| 5772 | |
| 5773 | if (clock_gettime(CLOCK_MONOTONIC, &now) < 0) |
| 5774 | return false; |
| 5775 | |
| 5776 | /* |
| 5777 | * If the shell helper client dies before the session has been |
| 5778 | * up for roughly 30 seconds, better just make Weston shut down, |
| 5779 | * because the user likely has no way to interact with the desktop |
| 5780 | * anyway. |
| 5781 | */ |
| 5782 | if (now.tv_sec - shell->startup_time.tv_sec < 30) { |
| 5783 | weston_log("Error: %s apparently cannot run at all.\n", |
| 5784 | shell->client); |
| 5785 | weston_log_continue(STAMP_SPACE "Quitting..."); |
| 5786 | wl_display_terminate(shell->compositor->wl_display); |
| 5787 | |
| 5788 | return true; |
| 5789 | } |
| 5790 | |
| 5791 | return false; |
| 5792 | } |
| 5793 | |
Tiago Vignatti | b7dbbd6 | 2012-09-25 17:57:01 +0300 | [diff] [blame] | 5794 | static void launch_desktop_shell_process(void *data); |
Pekka Paalanen | 4d733ee | 2012-01-17 14:36:27 +0200 | [diff] [blame] | 5795 | |
Kristian Høgsberg | 97d44aa | 2011-08-26 17:21:20 -0400 | [diff] [blame] | 5796 | static void |
Pekka Paalanen | 826dc14 | 2014-08-27 12:11:53 +0300 | [diff] [blame] | 5797 | respawn_desktop_shell_process(struct desktop_shell *shell) |
Pekka Paalanen | 6cd281a | 2011-11-03 14:11:32 +0200 | [diff] [blame] | 5798 | { |
Pekka Paalanen | 4d733ee | 2012-01-17 14:36:27 +0200 | [diff] [blame] | 5799 | uint32_t time; |
Pekka Paalanen | 4d733ee | 2012-01-17 14:36:27 +0200 | [diff] [blame] | 5800 | |
| 5801 | /* if desktop-shell dies more than 5 times in 30 seconds, give up */ |
| 5802 | time = weston_compositor_get_time(); |
Kristian Høgsberg | f03a616 | 2012-01-17 11:07:42 -0500 | [diff] [blame] | 5803 | if (time - shell->child.deathstamp > 30000) { |
Pekka Paalanen | 4d733ee | 2012-01-17 14:36:27 +0200 | [diff] [blame] | 5804 | shell->child.deathstamp = time; |
| 5805 | shell->child.deathcount = 0; |
| 5806 | } |
| 5807 | |
| 5808 | shell->child.deathcount++; |
| 5809 | if (shell->child.deathcount > 5) { |
Pekka Paalanen | 826dc14 | 2014-08-27 12:11:53 +0300 | [diff] [blame] | 5810 | weston_log("%s disconnected, giving up.\n", shell->client); |
Pekka Paalanen | 4d733ee | 2012-01-17 14:36:27 +0200 | [diff] [blame] | 5811 | return; |
| 5812 | } |
| 5813 | |
Pekka Paalanen | 826dc14 | 2014-08-27 12:11:53 +0300 | [diff] [blame] | 5814 | weston_log("%s disconnected, respawning...\n", shell->client); |
Pekka Paalanen | 4d733ee | 2012-01-17 14:36:27 +0200 | [diff] [blame] | 5815 | launch_desktop_shell_process(shell); |
Pekka Paalanen | 6cd281a | 2011-11-03 14:11:32 +0200 | [diff] [blame] | 5816 | } |
| 5817 | |
Tiago Vignatti | b7dbbd6 | 2012-09-25 17:57:01 +0300 | [diff] [blame] | 5818 | static void |
Ander Conselvan de Oliveira | 312ea4c | 2013-12-20 21:07:01 +0200 | [diff] [blame] | 5819 | desktop_shell_client_destroy(struct wl_listener *listener, void *data) |
| 5820 | { |
| 5821 | struct desktop_shell *shell; |
| 5822 | |
| 5823 | shell = container_of(listener, struct desktop_shell, |
| 5824 | child.client_destroy_listener); |
| 5825 | |
Pekka Paalanen | 826dc14 | 2014-08-27 12:11:53 +0300 | [diff] [blame] | 5826 | wl_list_remove(&shell->child.client_destroy_listener.link); |
Ander Conselvan de Oliveira | 312ea4c | 2013-12-20 21:07:01 +0200 | [diff] [blame] | 5827 | shell->child.client = NULL; |
Pekka Paalanen | 826dc14 | 2014-08-27 12:11:53 +0300 | [diff] [blame] | 5828 | /* |
| 5829 | * unbind_desktop_shell() will reset shell->child.desktop_shell |
| 5830 | * before the respawned process has a chance to create a new |
| 5831 | * desktop_shell object, because we are being called from the |
| 5832 | * wl_client destructor which destroys all wl_resources before |
| 5833 | * returning. |
| 5834 | */ |
| 5835 | |
Pekka Paalanen | 2e62e4a | 2014-08-28 11:41:26 +0300 | [diff] [blame] | 5836 | if (!check_desktop_shell_crash_too_early(shell)) |
| 5837 | respawn_desktop_shell_process(shell); |
| 5838 | |
Pekka Paalanen | 826dc14 | 2014-08-27 12:11:53 +0300 | [diff] [blame] | 5839 | shell_fade_startup(shell); |
Ander Conselvan de Oliveira | 312ea4c | 2013-12-20 21:07:01 +0200 | [diff] [blame] | 5840 | } |
| 5841 | |
| 5842 | static void |
Tiago Vignatti | b7dbbd6 | 2012-09-25 17:57:01 +0300 | [diff] [blame] | 5843 | launch_desktop_shell_process(void *data) |
Pekka Paalanen | 6cd281a | 2011-11-03 14:11:32 +0200 | [diff] [blame] | 5844 | { |
Tiago Vignatti | b7dbbd6 | 2012-09-25 17:57:01 +0300 | [diff] [blame] | 5845 | struct desktop_shell *shell = data; |
Pekka Paalanen | 6cd281a | 2011-11-03 14:11:32 +0200 | [diff] [blame] | 5846 | |
Pekka Paalanen | 826dc14 | 2014-08-27 12:11:53 +0300 | [diff] [blame] | 5847 | shell->child.client = weston_client_start(shell->compositor, |
| 5848 | shell->client); |
Pekka Paalanen | 409ef0a | 2011-12-02 15:30:21 +0200 | [diff] [blame] | 5849 | |
Arnaud Vrac | 4263119 | 2014-08-25 20:56:46 +0200 | [diff] [blame] | 5850 | if (!shell->child.client) { |
Emilio Pozuelo Monfort | 46ce798 | 2013-11-20 13:22:29 +0100 | [diff] [blame] | 5851 | weston_log("not able to start %s\n", shell->client); |
Arnaud Vrac | 4263119 | 2014-08-25 20:56:46 +0200 | [diff] [blame] | 5852 | return; |
| 5853 | } |
Ander Conselvan de Oliveira | 312ea4c | 2013-12-20 21:07:01 +0200 | [diff] [blame] | 5854 | |
| 5855 | shell->child.client_destroy_listener.notify = |
| 5856 | desktop_shell_client_destroy; |
| 5857 | wl_client_add_destroy_listener(shell->child.client, |
| 5858 | &shell->child.client_destroy_listener); |
Pekka Paalanen | 6cd281a | 2011-11-03 14:11:32 +0200 | [diff] [blame] | 5859 | } |
| 5860 | |
| 5861 | static void |
Kristian Høgsberg | 2bff94e | 2014-02-11 12:22:51 -0800 | [diff] [blame] | 5862 | handle_shell_client_destroy(struct wl_listener *listener, void *data) |
| 5863 | { |
| 5864 | struct shell_client *sc = |
| 5865 | container_of(listener, struct shell_client, destroy_listener); |
| 5866 | |
| 5867 | if (sc->ping_timer) |
| 5868 | wl_event_source_remove(sc->ping_timer); |
Derek Foreman | e42d754 | 2015-05-29 10:46:44 -0500 | [diff] [blame] | 5869 | |
| 5870 | /* Since we're about to free shell_client, we remove it from the |
| 5871 | * head of the surface list so we don't use that freed list node |
| 5872 | * during surface clean up later on. |
| 5873 | */ |
| 5874 | wl_list_remove(&sc->surface_list); |
| 5875 | |
Kristian Høgsberg | 2bff94e | 2014-02-11 12:22:51 -0800 | [diff] [blame] | 5876 | free(sc); |
| 5877 | } |
| 5878 | |
Kristian Høgsberg | dd62aba | 2014-02-12 09:56:19 -0800 | [diff] [blame] | 5879 | static struct shell_client * |
| 5880 | shell_client_create(struct wl_client *client, struct desktop_shell *shell, |
| 5881 | const struct wl_interface *interface, uint32_t id) |
Rafael Antognolli | e2a3455 | 2013-12-03 15:35:45 -0200 | [diff] [blame] | 5882 | { |
Kristian Høgsberg | 2bff94e | 2014-02-11 12:22:51 -0800 | [diff] [blame] | 5883 | struct shell_client *sc; |
Rafael Antognolli | e2a3455 | 2013-12-03 15:35:45 -0200 | [diff] [blame] | 5884 | |
Kristian Høgsberg | 2bff94e | 2014-02-11 12:22:51 -0800 | [diff] [blame] | 5885 | sc = zalloc(sizeof *sc); |
| 5886 | if (sc == NULL) { |
| 5887 | wl_client_post_no_memory(client); |
Kristian Høgsberg | dd62aba | 2014-02-12 09:56:19 -0800 | [diff] [blame] | 5888 | return NULL; |
Kristian Høgsberg | 2bff94e | 2014-02-11 12:22:51 -0800 | [diff] [blame] | 5889 | } |
Kristian Høgsberg | dd62aba | 2014-02-12 09:56:19 -0800 | [diff] [blame] | 5890 | |
| 5891 | sc->resource = wl_resource_create(client, interface, 1, id); |
Kristian Høgsberg | 2bff94e | 2014-02-11 12:22:51 -0800 | [diff] [blame] | 5892 | if (sc->resource == NULL) { |
| 5893 | free(sc); |
| 5894 | wl_client_post_no_memory(client); |
Kristian Høgsberg | dd62aba | 2014-02-12 09:56:19 -0800 | [diff] [blame] | 5895 | return NULL; |
Kristian Høgsberg | 2bff94e | 2014-02-11 12:22:51 -0800 | [diff] [blame] | 5896 | } |
| 5897 | |
| 5898 | sc->client = client; |
| 5899 | sc->shell = shell; |
| 5900 | sc->destroy_listener.notify = handle_shell_client_destroy; |
| 5901 | wl_client_add_destroy_listener(client, &sc->destroy_listener); |
Jonas Ådahl | 49d77d2 | 2015-03-18 16:20:51 +0800 | [diff] [blame] | 5902 | wl_list_init(&sc->surface_list); |
Kristian Høgsberg | 2bff94e | 2014-02-11 12:22:51 -0800 | [diff] [blame] | 5903 | |
Kristian Høgsberg | dd62aba | 2014-02-12 09:56:19 -0800 | [diff] [blame] | 5904 | return sc; |
| 5905 | } |
| 5906 | |
| 5907 | static void |
| 5908 | bind_shell(struct wl_client *client, void *data, uint32_t version, uint32_t id) |
| 5909 | { |
| 5910 | struct desktop_shell *shell = data; |
| 5911 | struct shell_client *sc; |
| 5912 | |
| 5913 | sc = shell_client_create(client, shell, &wl_shell_interface, id); |
| 5914 | if (sc) |
| 5915 | wl_resource_set_implementation(sc->resource, |
| 5916 | &shell_implementation, |
Jason Ekstrand | 9e9512f | 2014-04-16 21:12:10 -0500 | [diff] [blame] | 5917 | sc, NULL); |
Kristian Høgsberg | dd62aba | 2014-02-12 09:56:19 -0800 | [diff] [blame] | 5918 | } |
| 5919 | |
| 5920 | static void |
| 5921 | bind_xdg_shell(struct wl_client *client, void *data, uint32_t version, uint32_t id) |
| 5922 | { |
| 5923 | struct desktop_shell *shell = data; |
| 5924 | struct shell_client *sc; |
| 5925 | |
| 5926 | sc = shell_client_create(client, shell, &xdg_shell_interface, id); |
| 5927 | if (sc) |
| 5928 | wl_resource_set_dispatcher(sc->resource, |
| 5929 | xdg_shell_unversioned_dispatch, |
| 5930 | NULL, sc, NULL); |
Rafael Antognolli | e2a3455 | 2013-12-03 15:35:45 -0200 | [diff] [blame] | 5931 | } |
| 5932 | |
| 5933 | static void |
Pekka Paalanen | 9ef3e01 | 2011-11-15 13:34:48 +0200 | [diff] [blame] | 5934 | unbind_desktop_shell(struct wl_resource *resource) |
| 5935 | { |
Jason Ekstrand | 651f00e | 2013-06-14 10:07:54 -0500 | [diff] [blame] | 5936 | struct desktop_shell *shell = wl_resource_get_user_data(resource); |
Kristian Høgsberg | 1ec0c31 | 2011-11-15 16:39:55 -0500 | [diff] [blame] | 5937 | |
| 5938 | if (shell->locked) |
| 5939 | resume_desktop(shell); |
| 5940 | |
Pekka Paalanen | 9ef3e01 | 2011-11-15 13:34:48 +0200 | [diff] [blame] | 5941 | shell->child.desktop_shell = NULL; |
| 5942 | shell->prepare_event_sent = false; |
Pekka Paalanen | 9ef3e01 | 2011-11-15 13:34:48 +0200 | [diff] [blame] | 5943 | } |
| 5944 | |
| 5945 | static void |
Kristian Høgsberg | 7584062 | 2011-09-06 13:48:16 -0400 | [diff] [blame] | 5946 | bind_desktop_shell(struct wl_client *client, |
| 5947 | void *data, uint32_t version, uint32_t id) |
| 5948 | { |
Tiago Vignatti | be14326 | 2012-04-16 17:31:41 +0300 | [diff] [blame] | 5949 | struct desktop_shell *shell = data; |
Pekka Paalanen | bbe6052 | 2011-11-03 14:11:33 +0200 | [diff] [blame] | 5950 | struct wl_resource *resource; |
Kristian Høgsberg | 7584062 | 2011-09-06 13:48:16 -0400 | [diff] [blame] | 5951 | |
Jason Ekstrand | a85118c | 2013-06-27 20:17:02 -0500 | [diff] [blame] | 5952 | resource = wl_resource_create(client, &desktop_shell_interface, |
Jonny Lamb | 765760d | 2014-08-20 15:53:19 +0200 | [diff] [blame] | 5953 | MIN(version, 3), id); |
Pekka Paalanen | bbe6052 | 2011-11-03 14:11:33 +0200 | [diff] [blame] | 5954 | |
Pekka Paalanen | 9ef3e01 | 2011-11-15 13:34:48 +0200 | [diff] [blame] | 5955 | if (client == shell->child.client) { |
Jason Ekstrand | a85118c | 2013-06-27 20:17:02 -0500 | [diff] [blame] | 5956 | wl_resource_set_implementation(resource, |
| 5957 | &desktop_shell_implementation, |
| 5958 | shell, unbind_desktop_shell); |
Pekka Paalanen | 9ef3e01 | 2011-11-15 13:34:48 +0200 | [diff] [blame] | 5959 | shell->child.desktop_shell = resource; |
Pekka Paalanen | 79346ab | 2013-05-22 18:03:09 +0300 | [diff] [blame] | 5960 | |
| 5961 | if (version < 2) |
| 5962 | shell_fade_startup(shell); |
| 5963 | |
Pekka Paalanen | bbe6052 | 2011-11-03 14:11:33 +0200 | [diff] [blame] | 5964 | return; |
Pekka Paalanen | 9ef3e01 | 2011-11-15 13:34:48 +0200 | [diff] [blame] | 5965 | } |
Pekka Paalanen | bbe6052 | 2011-11-03 14:11:33 +0200 | [diff] [blame] | 5966 | |
| 5967 | wl_resource_post_error(resource, WL_DISPLAY_ERROR_INVALID_OBJECT, |
| 5968 | "permission to bind desktop_shell denied"); |
Kristian Høgsberg | 7584062 | 2011-09-06 13:48:16 -0400 | [diff] [blame] | 5969 | } |
| 5970 | |
Kristian Høgsberg | 0704539 | 2012-02-19 18:52:44 -0500 | [diff] [blame] | 5971 | struct switcher { |
Tiago Vignatti | be14326 | 2012-04-16 17:31:41 +0300 | [diff] [blame] | 5972 | struct desktop_shell *shell; |
Kristian Høgsberg | 0704539 | 2012-02-19 18:52:44 -0500 | [diff] [blame] | 5973 | struct weston_surface *current; |
| 5974 | struct wl_listener listener; |
Kristian Høgsberg | 29139d4 | 2013-04-18 15:25:39 -0400 | [diff] [blame] | 5975 | struct weston_keyboard_grab grab; |
Manuel Bachmann | c1ae2e8 | 2014-02-26 15:53:11 +0100 | [diff] [blame] | 5976 | struct wl_array minimized_array; |
Kristian Høgsberg | 0704539 | 2012-02-19 18:52:44 -0500 | [diff] [blame] | 5977 | }; |
| 5978 | |
| 5979 | static void |
| 5980 | switcher_next(struct switcher *switcher) |
| 5981 | { |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 5982 | struct weston_view *view; |
Kristian Høgsberg | 0704539 | 2012-02-19 18:52:44 -0500 | [diff] [blame] | 5983 | struct weston_surface *first = NULL, *prev = NULL, *next = NULL; |
Kristian Høgsberg | 32e5686 | 2012-04-02 22:18:58 -0400 | [diff] [blame] | 5984 | struct shell_surface *shsurf; |
Kristian Høgsberg | b0d8e77 | 2012-06-18 16:34:58 -0400 | [diff] [blame] | 5985 | struct workspace *ws = get_current_workspace(switcher->shell); |
Kristian Høgsberg | 0704539 | 2012-02-19 18:52:44 -0500 | [diff] [blame] | 5986 | |
Manuel Bachmann | c1ae2e8 | 2014-02-26 15:53:11 +0100 | [diff] [blame] | 5987 | /* temporary re-display minimized surfaces */ |
| 5988 | struct weston_view *tmp; |
| 5989 | struct weston_view **minimized; |
Giulio Camuffo | 412e6a5 | 2014-07-09 22:12:56 +0300 | [diff] [blame] | 5990 | wl_list_for_each_safe(view, tmp, &switcher->shell->minimized_layer.view_list.link, layer_link.link) { |
| 5991 | weston_layer_entry_remove(&view->layer_link); |
| 5992 | weston_layer_entry_insert(&ws->layer.view_list, &view->layer_link); |
Manuel Bachmann | c1ae2e8 | 2014-02-26 15:53:11 +0100 | [diff] [blame] | 5993 | minimized = wl_array_add(&switcher->minimized_array, sizeof *minimized); |
| 5994 | *minimized = view; |
| 5995 | } |
| 5996 | |
Giulio Camuffo | 412e6a5 | 2014-07-09 22:12:56 +0300 | [diff] [blame] | 5997 | 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] | 5998 | shsurf = get_shell_surface(view->surface); |
Rafael Antognolli | 5031cbe | 2013-12-05 19:01:21 -0200 | [diff] [blame] | 5999 | if (shsurf && |
| 6000 | shsurf->type == SHELL_SURFACE_TOPLEVEL && |
| 6001 | shsurf->parent == NULL) { |
Kristian Høgsberg | 0704539 | 2012-02-19 18:52:44 -0500 | [diff] [blame] | 6002 | if (first == NULL) |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 6003 | first = view->surface; |
Kristian Høgsberg | 0704539 | 2012-02-19 18:52:44 -0500 | [diff] [blame] | 6004 | if (prev == switcher->current) |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 6005 | next = view->surface; |
| 6006 | prev = view->surface; |
| 6007 | view->alpha = 0.25; |
| 6008 | weston_view_geometry_dirty(view); |
| 6009 | weston_surface_damage(view->surface); |
Kristian Høgsberg | 0704539 | 2012-02-19 18:52:44 -0500 | [diff] [blame] | 6010 | } |
Alex Wu | 1659daa | 2012-04-01 20:13:09 +0800 | [diff] [blame] | 6011 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 6012 | if (is_black_surface(view->surface, NULL)) { |
| 6013 | view->alpha = 0.25; |
| 6014 | weston_view_geometry_dirty(view); |
| 6015 | weston_surface_damage(view->surface); |
Alex Wu | 1659daa | 2012-04-01 20:13:09 +0800 | [diff] [blame] | 6016 | } |
Kristian Høgsberg | 0704539 | 2012-02-19 18:52:44 -0500 | [diff] [blame] | 6017 | } |
| 6018 | |
| 6019 | if (next == NULL) |
| 6020 | next = first; |
| 6021 | |
Alex Wu | 07b2606 | 2012-03-12 16:06:01 +0800 | [diff] [blame] | 6022 | if (next == NULL) |
| 6023 | return; |
| 6024 | |
Kristian Høgsberg | 0704539 | 2012-02-19 18:52:44 -0500 | [diff] [blame] | 6025 | wl_list_remove(&switcher->listener.link); |
Jason Ekstrand | 26ed73c | 2013-06-06 22:34:41 -0500 | [diff] [blame] | 6026 | wl_signal_add(&next->destroy_signal, &switcher->listener); |
Kristian Høgsberg | 0704539 | 2012-02-19 18:52:44 -0500 | [diff] [blame] | 6027 | |
| 6028 | switcher->current = next; |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 6029 | wl_list_for_each(view, &next->views, surface_link) |
| 6030 | view->alpha = 1.0; |
Alex Wu | 1659daa | 2012-04-01 20:13:09 +0800 | [diff] [blame] | 6031 | |
Kristian Høgsberg | 32e5686 | 2012-04-02 22:18:58 -0400 | [diff] [blame] | 6032 | shsurf = get_shell_surface(switcher->current); |
Rafael Antognolli | 03b1659 | 2013-12-03 15:35:42 -0200 | [diff] [blame] | 6033 | if (shsurf && shsurf->state.fullscreen) |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 6034 | shsurf->fullscreen.black_view->alpha = 1.0; |
Kristian Høgsberg | 0704539 | 2012-02-19 18:52:44 -0500 | [diff] [blame] | 6035 | } |
| 6036 | |
| 6037 | static void |
Kristian Høgsberg | 27e3052 | 2012-04-11 23:18:23 -0400 | [diff] [blame] | 6038 | switcher_handle_surface_destroy(struct wl_listener *listener, void *data) |
Kristian Høgsberg | 0704539 | 2012-02-19 18:52:44 -0500 | [diff] [blame] | 6039 | { |
| 6040 | struct switcher *switcher = |
| 6041 | container_of(listener, struct switcher, listener); |
| 6042 | |
| 6043 | switcher_next(switcher); |
| 6044 | } |
| 6045 | |
| 6046 | static void |
Daniel Stone | 351eb61 | 2012-05-31 15:27:47 -0400 | [diff] [blame] | 6047 | switcher_destroy(struct switcher *switcher) |
Kristian Høgsberg | 0704539 | 2012-02-19 18:52:44 -0500 | [diff] [blame] | 6048 | { |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 6049 | struct weston_view *view; |
Kristian Høgsberg | 29139d4 | 2013-04-18 15:25:39 -0400 | [diff] [blame] | 6050 | struct weston_keyboard *keyboard = switcher->grab.keyboard; |
Kristian Høgsberg | b0d8e77 | 2012-06-18 16:34:58 -0400 | [diff] [blame] | 6051 | struct workspace *ws = get_current_workspace(switcher->shell); |
Kristian Høgsberg | 0704539 | 2012-02-19 18:52:44 -0500 | [diff] [blame] | 6052 | |
Giulio Camuffo | 412e6a5 | 2014-07-09 22:12:56 +0300 | [diff] [blame] | 6053 | 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] | 6054 | if (is_focus_view(view)) |
| 6055 | continue; |
| 6056 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 6057 | view->alpha = 1.0; |
| 6058 | weston_surface_damage(view->surface); |
Kristian Høgsberg | 0704539 | 2012-02-19 18:52:44 -0500 | [diff] [blame] | 6059 | } |
| 6060 | |
Alex Wu | 07b2606 | 2012-03-12 16:06:01 +0800 | [diff] [blame] | 6061 | if (switcher->current) |
Daniel Stone | 37816df | 2012-05-16 18:45:18 +0100 | [diff] [blame] | 6062 | activate(switcher->shell, switcher->current, |
Derek Foreman | 8aeeac8 | 2015-01-30 13:24:36 -0600 | [diff] [blame] | 6063 | keyboard->seat, true); |
Kristian Høgsberg | 0704539 | 2012-02-19 18:52:44 -0500 | [diff] [blame] | 6064 | wl_list_remove(&switcher->listener.link); |
Kristian Høgsberg | 29139d4 | 2013-04-18 15:25:39 -0400 | [diff] [blame] | 6065 | weston_keyboard_end_grab(keyboard); |
| 6066 | if (keyboard->input_method_resource) |
| 6067 | keyboard->grab = &keyboard->input_method_grab; |
Manuel Bachmann | c1ae2e8 | 2014-02-26 15:53:11 +0100 | [diff] [blame] | 6068 | |
| 6069 | /* re-hide surfaces that were temporary shown during the switch */ |
| 6070 | struct weston_view **minimized; |
| 6071 | wl_array_for_each(minimized, &switcher->minimized_array) { |
| 6072 | /* with the exception of the current selected */ |
| 6073 | if ((*minimized)->surface != switcher->current) { |
Giulio Camuffo | 412e6a5 | 2014-07-09 22:12:56 +0300 | [diff] [blame] | 6074 | weston_layer_entry_remove(&(*minimized)->layer_link); |
| 6075 | 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] | 6076 | weston_view_damage_below(*minimized); |
| 6077 | } |
| 6078 | } |
| 6079 | wl_array_release(&switcher->minimized_array); |
| 6080 | |
Kristian Høgsberg | 0704539 | 2012-02-19 18:52:44 -0500 | [diff] [blame] | 6081 | free(switcher); |
| 6082 | } |
| 6083 | |
| 6084 | static void |
Kristian Høgsberg | 29139d4 | 2013-04-18 15:25:39 -0400 | [diff] [blame] | 6085 | switcher_key(struct weston_keyboard_grab *grab, |
Daniel Stone | c9785ea | 2012-05-30 16:31:52 +0100 | [diff] [blame] | 6086 | uint32_t time, uint32_t key, uint32_t state_w) |
Kristian Høgsberg | 0704539 | 2012-02-19 18:52:44 -0500 | [diff] [blame] | 6087 | { |
| 6088 | struct switcher *switcher = container_of(grab, struct switcher, grab); |
Daniel Stone | c9785ea | 2012-05-30 16:31:52 +0100 | [diff] [blame] | 6089 | enum wl_keyboard_key_state state = state_w; |
Daniel Stone | 351eb61 | 2012-05-31 15:27:47 -0400 | [diff] [blame] | 6090 | |
Daniel Stone | c9785ea | 2012-05-30 16:31:52 +0100 | [diff] [blame] | 6091 | if (key == KEY_TAB && state == WL_KEYBOARD_KEY_STATE_PRESSED) |
Daniel Stone | 351eb61 | 2012-05-31 15:27:47 -0400 | [diff] [blame] | 6092 | switcher_next(switcher); |
| 6093 | } |
| 6094 | |
| 6095 | static void |
Kristian Høgsberg | 29139d4 | 2013-04-18 15:25:39 -0400 | [diff] [blame] | 6096 | switcher_modifier(struct weston_keyboard_grab *grab, uint32_t serial, |
Daniel Stone | 351eb61 | 2012-05-31 15:27:47 -0400 | [diff] [blame] | 6097 | uint32_t mods_depressed, uint32_t mods_latched, |
| 6098 | uint32_t mods_locked, uint32_t group) |
| 6099 | { |
| 6100 | struct switcher *switcher = container_of(grab, struct switcher, grab); |
Derek Foreman | 8aeeac8 | 2015-01-30 13:24:36 -0600 | [diff] [blame] | 6101 | struct weston_seat *seat = grab->keyboard->seat; |
Kristian Høgsberg | 0704539 | 2012-02-19 18:52:44 -0500 | [diff] [blame] | 6102 | |
Daniel Stone | 351eb61 | 2012-05-31 15:27:47 -0400 | [diff] [blame] | 6103 | if ((seat->modifier_state & switcher->shell->binding_modifier) == 0) |
| 6104 | switcher_destroy(switcher); |
Kristian Høgsberg | b71302e | 2012-05-10 12:28:35 -0400 | [diff] [blame] | 6105 | } |
Kristian Høgsberg | 0704539 | 2012-02-19 18:52:44 -0500 | [diff] [blame] | 6106 | |
Jonas Ådahl | 1ea343e | 2013-10-25 23:18:05 +0200 | [diff] [blame] | 6107 | static void |
| 6108 | switcher_cancel(struct weston_keyboard_grab *grab) |
| 6109 | { |
| 6110 | struct switcher *switcher = container_of(grab, struct switcher, grab); |
| 6111 | |
| 6112 | switcher_destroy(switcher); |
| 6113 | } |
| 6114 | |
Kristian Høgsberg | 29139d4 | 2013-04-18 15:25:39 -0400 | [diff] [blame] | 6115 | static const struct weston_keyboard_grab_interface switcher_grab = { |
Daniel Stone | 351eb61 | 2012-05-31 15:27:47 -0400 | [diff] [blame] | 6116 | switcher_key, |
| 6117 | switcher_modifier, |
Jonas Ådahl | 1ea343e | 2013-10-25 23:18:05 +0200 | [diff] [blame] | 6118 | switcher_cancel, |
Kristian Høgsberg | 0704539 | 2012-02-19 18:52:44 -0500 | [diff] [blame] | 6119 | }; |
| 6120 | |
| 6121 | static void |
Derek Foreman | 8ae2db5 | 2015-07-15 13:00:36 -0500 | [diff] [blame] | 6122 | switcher_binding(struct weston_keyboard *keyboard, uint32_t time, |
| 6123 | uint32_t key, void *data) |
Kristian Høgsberg | 0704539 | 2012-02-19 18:52:44 -0500 | [diff] [blame] | 6124 | { |
Tiago Vignatti | be14326 | 2012-04-16 17:31:41 +0300 | [diff] [blame] | 6125 | struct desktop_shell *shell = data; |
Kristian Høgsberg | 0704539 | 2012-02-19 18:52:44 -0500 | [diff] [blame] | 6126 | struct switcher *switcher; |
| 6127 | |
| 6128 | switcher = malloc(sizeof *switcher); |
Kristian Høgsberg | 02e79dc | 2012-04-12 09:55:26 -0400 | [diff] [blame] | 6129 | switcher->shell = shell; |
Kristian Høgsberg | 0704539 | 2012-02-19 18:52:44 -0500 | [diff] [blame] | 6130 | switcher->current = NULL; |
Kristian Høgsberg | 27e3052 | 2012-04-11 23:18:23 -0400 | [diff] [blame] | 6131 | switcher->listener.notify = switcher_handle_surface_destroy; |
Kristian Høgsberg | 0704539 | 2012-02-19 18:52:44 -0500 | [diff] [blame] | 6132 | wl_list_init(&switcher->listener.link); |
Manuel Bachmann | c1ae2e8 | 2014-02-26 15:53:11 +0100 | [diff] [blame] | 6133 | wl_array_init(&switcher->minimized_array); |
Kristian Høgsberg | 0704539 | 2012-02-19 18:52:44 -0500 | [diff] [blame] | 6134 | |
Alexander Larsson | f82b6ca | 2013-05-28 16:23:39 +0200 | [diff] [blame] | 6135 | restore_all_output_modes(shell->compositor); |
Mario Kleiner | 9f4d655 | 2015-06-21 21:25:08 +0200 | [diff] [blame] | 6136 | lower_fullscreen_layer(switcher->shell, NULL); |
Kristian Høgsberg | 0704539 | 2012-02-19 18:52:44 -0500 | [diff] [blame] | 6137 | switcher->grab.interface = &switcher_grab; |
Derek Foreman | 8ae2db5 | 2015-07-15 13:00:36 -0500 | [diff] [blame] | 6138 | weston_keyboard_start_grab(keyboard, &switcher->grab); |
| 6139 | weston_keyboard_set_focus(keyboard, NULL); |
Kristian Høgsberg | 0704539 | 2012-02-19 18:52:44 -0500 | [diff] [blame] | 6140 | switcher_next(switcher); |
| 6141 | } |
| 6142 | |
Pekka Paalanen | 3c64723 | 2011-12-22 13:43:43 +0200 | [diff] [blame] | 6143 | static void |
Derek Foreman | 8ae2db5 | 2015-07-15 13:00:36 -0500 | [diff] [blame] | 6144 | backlight_binding(struct weston_keyboard *keyboard, uint32_t time, |
| 6145 | uint32_t key, void *data) |
Tiago Vignatti | 8e53c7f | 2012-02-29 19:53:50 +0200 | [diff] [blame] | 6146 | { |
| 6147 | struct weston_compositor *compositor = data; |
| 6148 | struct weston_output *output; |
Tiago Vignatti | 5ab91ad | 2012-03-12 19:40:09 -0300 | [diff] [blame] | 6149 | long backlight_new = 0; |
Tiago Vignatti | 8e53c7f | 2012-02-29 19:53:50 +0200 | [diff] [blame] | 6150 | |
| 6151 | /* TODO: we're limiting to simple use cases, where we assume just |
| 6152 | * control on the primary display. We'd have to extend later if we |
| 6153 | * ever get support for setting backlights on random desktop LCD |
| 6154 | * panels though */ |
| 6155 | output = get_default_output(compositor); |
| 6156 | if (!output) |
| 6157 | return; |
| 6158 | |
| 6159 | if (!output->set_backlight) |
| 6160 | return; |
| 6161 | |
Tiago Vignatti | 5ab91ad | 2012-03-12 19:40:09 -0300 | [diff] [blame] | 6162 | if (key == KEY_F9 || key == KEY_BRIGHTNESSDOWN) |
| 6163 | backlight_new = output->backlight_current - 25; |
| 6164 | else if (key == KEY_F10 || key == KEY_BRIGHTNESSUP) |
| 6165 | backlight_new = output->backlight_current + 25; |
Tiago Vignatti | 8e53c7f | 2012-02-29 19:53:50 +0200 | [diff] [blame] | 6166 | |
Tiago Vignatti | 5ab91ad | 2012-03-12 19:40:09 -0300 | [diff] [blame] | 6167 | if (backlight_new < 5) |
| 6168 | backlight_new = 5; |
| 6169 | if (backlight_new > 255) |
| 6170 | backlight_new = 255; |
| 6171 | |
| 6172 | output->backlight_current = backlight_new; |
Tiago Vignatti | 8e53c7f | 2012-02-29 19:53:50 +0200 | [diff] [blame] | 6173 | output->set_backlight(output, output->backlight_current); |
| 6174 | } |
| 6175 | |
Kristian Høgsberg | b41c081 | 2012-03-04 14:53:40 -0500 | [diff] [blame] | 6176 | static void |
Derek Foreman | 8ae2db5 | 2015-07-15 13:00:36 -0500 | [diff] [blame] | 6177 | force_kill_binding(struct weston_keyboard *keyboard, uint32_t time, |
| 6178 | uint32_t key, void *data) |
Kristian Høgsberg | 92a57db | 2012-05-26 13:41:06 -0400 | [diff] [blame] | 6179 | { |
Kristian Høgsberg | fe7aa90 | 2013-05-08 09:54:37 -0400 | [diff] [blame] | 6180 | struct weston_surface *focus_surface; |
Kristian Høgsberg | 92a57db | 2012-05-26 13:41:06 -0400 | [diff] [blame] | 6181 | struct wl_client *client; |
Tiago Vignatti | 1d01b01 | 2012-09-27 17:48:36 +0300 | [diff] [blame] | 6182 | struct desktop_shell *shell = data; |
| 6183 | struct weston_compositor *compositor = shell->compositor; |
Kristian Høgsberg | 92a57db | 2012-05-26 13:41:06 -0400 | [diff] [blame] | 6184 | pid_t pid; |
Kristian Høgsberg | 92a57db | 2012-05-26 13:41:06 -0400 | [diff] [blame] | 6185 | |
Derek Foreman | 8ae2db5 | 2015-07-15 13:00:36 -0500 | [diff] [blame] | 6186 | focus_surface = keyboard->focus; |
Philipp Brüschweiler | 6cef009 | 2012-08-13 21:27:27 +0200 | [diff] [blame] | 6187 | if (!focus_surface) |
| 6188 | return; |
| 6189 | |
Tiago Vignatti | 1d01b01 | 2012-09-27 17:48:36 +0300 | [diff] [blame] | 6190 | wl_signal_emit(&compositor->kill_signal, focus_surface); |
| 6191 | |
Jason Ekstrand | 26ed73c | 2013-06-06 22:34:41 -0500 | [diff] [blame] | 6192 | client = wl_resource_get_client(focus_surface->resource); |
Tiago Vignatti | 920f197 | 2012-09-27 17:48:35 +0300 | [diff] [blame] | 6193 | wl_client_get_credentials(client, &pid, NULL, NULL); |
| 6194 | |
| 6195 | /* Skip clients that we launched ourselves (the credentials of |
| 6196 | * the socketpair is ours) */ |
| 6197 | if (pid == getpid()) |
| 6198 | return; |
Kristian Høgsberg | 92a57db | 2012-05-26 13:41:06 -0400 | [diff] [blame] | 6199 | |
Daniel Stone | 325fc2d | 2012-05-30 16:31:58 +0100 | [diff] [blame] | 6200 | kill(pid, SIGKILL); |
Kristian Høgsberg | 92a57db | 2012-05-26 13:41:06 -0400 | [diff] [blame] | 6201 | } |
| 6202 | |
| 6203 | static void |
Derek Foreman | 8ae2db5 | 2015-07-15 13:00:36 -0500 | [diff] [blame] | 6204 | workspace_up_binding(struct weston_keyboard *keyboard, uint32_t time, |
Jonas Ådahl | e3cddce | 2012-06-13 00:01:22 +0200 | [diff] [blame] | 6205 | uint32_t key, void *data) |
| 6206 | { |
| 6207 | struct desktop_shell *shell = data; |
| 6208 | unsigned int new_index = shell->workspaces.current; |
| 6209 | |
Kristian Høgsberg | ce345b0 | 2012-06-25 21:35:29 -0400 | [diff] [blame] | 6210 | if (shell->locked) |
Kristian Høgsberg | 4476aaf | 2012-06-25 14:03:13 -0400 | [diff] [blame] | 6211 | return; |
Jonas Ådahl | e3cddce | 2012-06-13 00:01:22 +0200 | [diff] [blame] | 6212 | if (new_index != 0) |
| 6213 | new_index--; |
| 6214 | |
| 6215 | change_workspace(shell, new_index); |
| 6216 | } |
| 6217 | |
| 6218 | static void |
Derek Foreman | 8ae2db5 | 2015-07-15 13:00:36 -0500 | [diff] [blame] | 6219 | workspace_down_binding(struct weston_keyboard *keyboard, uint32_t time, |
Jonas Ådahl | e3cddce | 2012-06-13 00:01:22 +0200 | [diff] [blame] | 6220 | uint32_t key, void *data) |
| 6221 | { |
| 6222 | struct desktop_shell *shell = data; |
| 6223 | unsigned int new_index = shell->workspaces.current; |
| 6224 | |
Kristian Høgsberg | ce345b0 | 2012-06-25 21:35:29 -0400 | [diff] [blame] | 6225 | if (shell->locked) |
Kristian Høgsberg | 4476aaf | 2012-06-25 14:03:13 -0400 | [diff] [blame] | 6226 | return; |
Jonas Ådahl | e3cddce | 2012-06-13 00:01:22 +0200 | [diff] [blame] | 6227 | if (new_index < shell->workspaces.num - 1) |
| 6228 | new_index++; |
| 6229 | |
| 6230 | change_workspace(shell, new_index); |
| 6231 | } |
| 6232 | |
| 6233 | static void |
Derek Foreman | 8ae2db5 | 2015-07-15 13:00:36 -0500 | [diff] [blame] | 6234 | workspace_f_binding(struct weston_keyboard *keyboard, uint32_t time, |
Jonas Ådahl | e3cddce | 2012-06-13 00:01:22 +0200 | [diff] [blame] | 6235 | uint32_t key, void *data) |
| 6236 | { |
| 6237 | struct desktop_shell *shell = data; |
| 6238 | unsigned int new_index; |
| 6239 | |
Kristian Høgsberg | ce345b0 | 2012-06-25 21:35:29 -0400 | [diff] [blame] | 6240 | if (shell->locked) |
Kristian Høgsberg | 4476aaf | 2012-06-25 14:03:13 -0400 | [diff] [blame] | 6241 | return; |
Jonas Ådahl | e3cddce | 2012-06-13 00:01:22 +0200 | [diff] [blame] | 6242 | new_index = key - KEY_F1; |
| 6243 | if (new_index >= shell->workspaces.num) |
| 6244 | new_index = shell->workspaces.num - 1; |
| 6245 | |
| 6246 | change_workspace(shell, new_index); |
| 6247 | } |
| 6248 | |
Jonas Ådahl | 8de6a1d | 2012-08-29 22:13:00 +0200 | [diff] [blame] | 6249 | static void |
Derek Foreman | 8ae2db5 | 2015-07-15 13:00:36 -0500 | [diff] [blame] | 6250 | workspace_move_surface_up_binding(struct weston_keyboard *keyboard, |
| 6251 | uint32_t time, uint32_t key, void *data) |
Jonas Ådahl | 8de6a1d | 2012-08-29 22:13:00 +0200 | [diff] [blame] | 6252 | { |
| 6253 | struct desktop_shell *shell = data; |
| 6254 | unsigned int new_index = shell->workspaces.current; |
| 6255 | |
| 6256 | if (shell->locked) |
| 6257 | return; |
| 6258 | |
| 6259 | if (new_index != 0) |
| 6260 | new_index--; |
| 6261 | |
Derek Foreman | 8ae2db5 | 2015-07-15 13:00:36 -0500 | [diff] [blame] | 6262 | take_surface_to_workspace_by_seat(shell, keyboard->seat, new_index); |
Jonas Ådahl | 8de6a1d | 2012-08-29 22:13:00 +0200 | [diff] [blame] | 6263 | } |
| 6264 | |
| 6265 | static void |
Derek Foreman | 8ae2db5 | 2015-07-15 13:00:36 -0500 | [diff] [blame] | 6266 | workspace_move_surface_down_binding(struct weston_keyboard *keyboard, |
| 6267 | uint32_t time, uint32_t key, void *data) |
Jonas Ådahl | 8de6a1d | 2012-08-29 22:13:00 +0200 | [diff] [blame] | 6268 | { |
| 6269 | struct desktop_shell *shell = data; |
| 6270 | unsigned int new_index = shell->workspaces.current; |
| 6271 | |
| 6272 | if (shell->locked) |
| 6273 | return; |
| 6274 | |
| 6275 | if (new_index < shell->workspaces.num - 1) |
| 6276 | new_index++; |
| 6277 | |
Derek Foreman | 8ae2db5 | 2015-07-15 13:00:36 -0500 | [diff] [blame] | 6278 | take_surface_to_workspace_by_seat(shell, keyboard->seat, new_index); |
Jonas Ådahl | 8de6a1d | 2012-08-29 22:13:00 +0200 | [diff] [blame] | 6279 | } |
Jonas Ådahl | e3cddce | 2012-06-13 00:01:22 +0200 | [diff] [blame] | 6280 | |
| 6281 | static void |
Ander Conselvan de Oliveira | c94d622 | 2014-01-29 18:47:54 +0200 | [diff] [blame] | 6282 | shell_reposition_view_on_output_destroy(struct weston_view *view) |
| 6283 | { |
| 6284 | struct weston_output *output, *first_output; |
| 6285 | struct weston_compositor *ec = view->surface->compositor; |
| 6286 | struct shell_surface *shsurf; |
| 6287 | float x, y; |
| 6288 | int visible; |
| 6289 | |
| 6290 | x = view->geometry.x; |
| 6291 | y = view->geometry.y; |
| 6292 | |
| 6293 | /* At this point the destroyed output is not in the list anymore. |
| 6294 | * If the view is still visible somewhere, we leave where it is, |
| 6295 | * otherwise, move it to the first output. */ |
| 6296 | visible = 0; |
| 6297 | wl_list_for_each(output, &ec->output_list, link) { |
| 6298 | if (pixman_region32_contains_point(&output->region, |
| 6299 | x, y, NULL)) { |
| 6300 | visible = 1; |
| 6301 | break; |
| 6302 | } |
| 6303 | } |
| 6304 | |
| 6305 | if (!visible) { |
| 6306 | first_output = container_of(ec->output_list.next, |
| 6307 | struct weston_output, link); |
| 6308 | |
| 6309 | x = first_output->x + first_output->width / 4; |
| 6310 | y = first_output->y + first_output->height / 4; |
Xiong Zhang | 62899f5 | 2014-03-07 16:27:19 +0800 | [diff] [blame] | 6311 | |
| 6312 | weston_view_set_position(view, x, y); |
| 6313 | } else { |
| 6314 | weston_view_geometry_dirty(view); |
Ander Conselvan de Oliveira | c94d622 | 2014-01-29 18:47:54 +0200 | [diff] [blame] | 6315 | } |
| 6316 | |
Ander Conselvan de Oliveira | c94d622 | 2014-01-29 18:47:54 +0200 | [diff] [blame] | 6317 | |
| 6318 | shsurf = get_shell_surface(view->surface); |
| 6319 | |
| 6320 | if (shsurf) { |
| 6321 | shsurf->saved_position_valid = false; |
| 6322 | shsurf->next_state.maximized = false; |
| 6323 | shsurf->next_state.fullscreen = false; |
| 6324 | shsurf->state_changed = true; |
| 6325 | } |
| 6326 | } |
| 6327 | |
Ander Conselvan de Oliveira | 304996d | 2014-04-11 13:57:15 +0300 | [diff] [blame] | 6328 | void |
| 6329 | shell_for_each_layer(struct desktop_shell *shell, |
| 6330 | shell_for_each_layer_func_t func, void *data) |
Ander Conselvan de Oliveira | c94d622 | 2014-01-29 18:47:54 +0200 | [diff] [blame] | 6331 | { |
Ander Conselvan de Oliveira | 304996d | 2014-04-11 13:57:15 +0300 | [diff] [blame] | 6332 | struct workspace **ws; |
| 6333 | |
| 6334 | func(shell, &shell->fullscreen_layer, data); |
| 6335 | func(shell, &shell->panel_layer, data); |
| 6336 | func(shell, &shell->background_layer, data); |
| 6337 | func(shell, &shell->lock_layer, data); |
| 6338 | func(shell, &shell->input_panel_layer, data); |
| 6339 | |
| 6340 | wl_array_for_each(ws, &shell->workspaces.array) |
| 6341 | func(shell, &(*ws)->layer, data); |
| 6342 | } |
| 6343 | |
| 6344 | static void |
| 6345 | shell_output_destroy_move_layer(struct desktop_shell *shell, |
| 6346 | struct weston_layer *layer, |
| 6347 | void *data) |
| 6348 | { |
| 6349 | struct weston_output *output = data; |
Ander Conselvan de Oliveira | c94d622 | 2014-01-29 18:47:54 +0200 | [diff] [blame] | 6350 | struct weston_view *view; |
| 6351 | |
Giulio Camuffo | 412e6a5 | 2014-07-09 22:12:56 +0300 | [diff] [blame] | 6352 | 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] | 6353 | if (view->output != output) |
| 6354 | continue; |
Ander Conselvan de Oliveira | c94d622 | 2014-01-29 18:47:54 +0200 | [diff] [blame] | 6355 | |
Ander Conselvan de Oliveira | 304996d | 2014-04-11 13:57:15 +0300 | [diff] [blame] | 6356 | shell_reposition_view_on_output_destroy(view); |
Ander Conselvan de Oliveira | c94d622 | 2014-01-29 18:47:54 +0200 | [diff] [blame] | 6357 | } |
| 6358 | } |
| 6359 | |
| 6360 | static void |
Xiong Zhang | 6b48142 | 2013-10-23 13:58:32 +0800 | [diff] [blame] | 6361 | handle_output_destroy(struct wl_listener *listener, void *data) |
| 6362 | { |
| 6363 | struct shell_output *output_listener = |
| 6364 | container_of(listener, struct shell_output, destroy_listener); |
Ander Conselvan de Oliveira | 304996d | 2014-04-11 13:57:15 +0300 | [diff] [blame] | 6365 | struct weston_output *output = output_listener->output; |
| 6366 | struct desktop_shell *shell = output_listener->shell; |
Xiong Zhang | 6b48142 | 2013-10-23 13:58:32 +0800 | [diff] [blame] | 6367 | |
Ander Conselvan de Oliveira | 304996d | 2014-04-11 13:57:15 +0300 | [diff] [blame] | 6368 | 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] | 6369 | |
Xiong Zhang | 6b48142 | 2013-10-23 13:58:32 +0800 | [diff] [blame] | 6370 | wl_list_remove(&output_listener->destroy_listener.link); |
| 6371 | wl_list_remove(&output_listener->link); |
| 6372 | free(output_listener); |
| 6373 | } |
| 6374 | |
| 6375 | static void |
| 6376 | create_shell_output(struct desktop_shell *shell, |
| 6377 | struct weston_output *output) |
| 6378 | { |
| 6379 | struct shell_output *shell_output; |
| 6380 | |
| 6381 | shell_output = zalloc(sizeof *shell_output); |
| 6382 | if (shell_output == NULL) |
| 6383 | return; |
| 6384 | |
| 6385 | shell_output->output = output; |
| 6386 | shell_output->shell = shell; |
| 6387 | shell_output->destroy_listener.notify = handle_output_destroy; |
| 6388 | wl_signal_add(&output->destroy_signal, |
| 6389 | &shell_output->destroy_listener); |
Kristian Høgsberg | a3a0e18 | 2013-10-23 23:36:04 -0700 | [diff] [blame] | 6390 | wl_list_insert(shell->output_list.prev, &shell_output->link); |
Xiong Zhang | 6b48142 | 2013-10-23 13:58:32 +0800 | [diff] [blame] | 6391 | } |
| 6392 | |
| 6393 | static void |
| 6394 | handle_output_create(struct wl_listener *listener, void *data) |
| 6395 | { |
| 6396 | struct desktop_shell *shell = |
| 6397 | container_of(listener, struct desktop_shell, output_create_listener); |
| 6398 | struct weston_output *output = (struct weston_output *)data; |
| 6399 | |
| 6400 | create_shell_output(shell, output); |
| 6401 | } |
| 6402 | |
| 6403 | static void |
Ander Conselvan de Oliveira | 304996d | 2014-04-11 13:57:15 +0300 | [diff] [blame] | 6404 | handle_output_move_layer(struct desktop_shell *shell, |
| 6405 | struct weston_layer *layer, void *data) |
Ander Conselvan de Oliveira | a8a9baf | 2014-01-29 18:47:52 +0200 | [diff] [blame] | 6406 | { |
Ander Conselvan de Oliveira | 304996d | 2014-04-11 13:57:15 +0300 | [diff] [blame] | 6407 | struct weston_output *output = data; |
Ander Conselvan de Oliveira | a8a9baf | 2014-01-29 18:47:52 +0200 | [diff] [blame] | 6408 | struct weston_view *view; |
| 6409 | float x, y; |
| 6410 | |
Giulio Camuffo | 412e6a5 | 2014-07-09 22:12:56 +0300 | [diff] [blame] | 6411 | 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] | 6412 | if (view->output != output) |
| 6413 | continue; |
| 6414 | |
| 6415 | x = view->geometry.x + output->move_x; |
| 6416 | y = view->geometry.y + output->move_y; |
| 6417 | weston_view_set_position(view, x, y); |
| 6418 | } |
| 6419 | } |
| 6420 | |
| 6421 | static void |
| 6422 | handle_output_move(struct wl_listener *listener, void *data) |
| 6423 | { |
| 6424 | struct desktop_shell *shell; |
| 6425 | |
Ander Conselvan de Oliveira | a8a9baf | 2014-01-29 18:47:52 +0200 | [diff] [blame] | 6426 | shell = container_of(listener, struct desktop_shell, |
| 6427 | output_move_listener); |
Ander Conselvan de Oliveira | a8a9baf | 2014-01-29 18:47:52 +0200 | [diff] [blame] | 6428 | |
Ander Conselvan de Oliveira | 304996d | 2014-04-11 13:57:15 +0300 | [diff] [blame] | 6429 | shell_for_each_layer(shell, handle_output_move_layer, data); |
Ander Conselvan de Oliveira | a8a9baf | 2014-01-29 18:47:52 +0200 | [diff] [blame] | 6430 | } |
| 6431 | |
| 6432 | static void |
Xiong Zhang | 6b48142 | 2013-10-23 13:58:32 +0800 | [diff] [blame] | 6433 | setup_output_destroy_handler(struct weston_compositor *ec, |
| 6434 | struct desktop_shell *shell) |
| 6435 | { |
| 6436 | struct weston_output *output; |
| 6437 | |
| 6438 | wl_list_init(&shell->output_list); |
| 6439 | wl_list_for_each(output, &ec->output_list, link) |
| 6440 | create_shell_output(shell, output); |
| 6441 | |
| 6442 | shell->output_create_listener.notify = handle_output_create; |
| 6443 | wl_signal_add(&ec->output_created_signal, |
| 6444 | &shell->output_create_listener); |
Ander Conselvan de Oliveira | a8a9baf | 2014-01-29 18:47:52 +0200 | [diff] [blame] | 6445 | |
| 6446 | shell->output_move_listener.notify = handle_output_move; |
| 6447 | wl_signal_add(&ec->output_moved_signal, &shell->output_move_listener); |
Xiong Zhang | 6b48142 | 2013-10-23 13:58:32 +0800 | [diff] [blame] | 6448 | } |
| 6449 | |
| 6450 | static void |
Kristian Høgsberg | 02e79dc | 2012-04-12 09:55:26 -0400 | [diff] [blame] | 6451 | shell_destroy(struct wl_listener *listener, void *data) |
Pekka Paalanen | 3c64723 | 2011-12-22 13:43:43 +0200 | [diff] [blame] | 6452 | { |
Tiago Vignatti | be14326 | 2012-04-16 17:31:41 +0300 | [diff] [blame] | 6453 | struct desktop_shell *shell = |
| 6454 | container_of(listener, struct desktop_shell, destroy_listener); |
Jonas Ådahl | e3cddce | 2012-06-13 00:01:22 +0200 | [diff] [blame] | 6455 | struct workspace **ws; |
Xiong Zhang | 6b48142 | 2013-10-23 13:58:32 +0800 | [diff] [blame] | 6456 | struct shell_output *shell_output, *tmp; |
Pekka Paalanen | 3c64723 | 2011-12-22 13:43:43 +0200 | [diff] [blame] | 6457 | |
Kristian Høgsberg | 17bccae | 2014-01-16 16:46:28 -0800 | [diff] [blame] | 6458 | /* Force state to unlocked so we don't try to fade */ |
| 6459 | shell->locked = false; |
Pekka Paalanen | 826dc14 | 2014-08-27 12:11:53 +0300 | [diff] [blame] | 6460 | |
| 6461 | if (shell->child.client) { |
| 6462 | /* disable respawn */ |
| 6463 | wl_list_remove(&shell->child.client_destroy_listener.link); |
Pekka Paalanen | 9cf5cc8 | 2012-01-02 16:00:24 +0200 | [diff] [blame] | 6464 | wl_client_destroy(shell->child.client); |
Pekka Paalanen | 826dc14 | 2014-08-27 12:11:53 +0300 | [diff] [blame] | 6465 | } |
Pekka Paalanen | 9cf5cc8 | 2012-01-02 16:00:24 +0200 | [diff] [blame] | 6466 | |
Ander Conselvan de Oliveira | a457563 | 2013-02-21 18:35:23 +0200 | [diff] [blame] | 6467 | wl_list_remove(&shell->idle_listener.link); |
| 6468 | wl_list_remove(&shell->wake_listener.link); |
Kristian Høgsberg | 677a5f5 | 2013-12-04 11:00:19 -0800 | [diff] [blame] | 6469 | |
Pekka Paalanen | aa9536a | 2015-06-24 16:09:17 +0300 | [diff] [blame] | 6470 | text_backend_destroy(shell->text_backend); |
Kristian Høgsberg | 677a5f5 | 2013-12-04 11:00:19 -0800 | [diff] [blame] | 6471 | input_panel_destroy(shell); |
Kristian Høgsberg | 88c1607 | 2012-05-16 08:04:19 -0400 | [diff] [blame] | 6472 | |
Xiong Zhang | 6b48142 | 2013-10-23 13:58:32 +0800 | [diff] [blame] | 6473 | wl_list_for_each_safe(shell_output, tmp, &shell->output_list, link) { |
| 6474 | wl_list_remove(&shell_output->destroy_listener.link); |
| 6475 | wl_list_remove(&shell_output->link); |
| 6476 | free(shell_output); |
| 6477 | } |
| 6478 | |
| 6479 | wl_list_remove(&shell->output_create_listener.link); |
Kristian Høgsberg | 6d50b0f | 2014-04-30 20:46:25 -0700 | [diff] [blame] | 6480 | wl_list_remove(&shell->output_move_listener.link); |
Xiong Zhang | 6b48142 | 2013-10-23 13:58:32 +0800 | [diff] [blame] | 6481 | |
Jonas Ådahl | e3cddce | 2012-06-13 00:01:22 +0200 | [diff] [blame] | 6482 | wl_array_for_each(ws, &shell->workspaces.array) |
| 6483 | workspace_destroy(*ws); |
| 6484 | wl_array_release(&shell->workspaces.array); |
| 6485 | |
Emilio Pozuelo Monfort | 46ce798 | 2013-11-20 13:22:29 +0100 | [diff] [blame] | 6486 | free(shell->client); |
Pekka Paalanen | 3c64723 | 2011-12-22 13:43:43 +0200 | [diff] [blame] | 6487 | free(shell); |
| 6488 | } |
| 6489 | |
Tiago Vignatti | 0b52d48 | 2012-04-20 18:54:25 +0300 | [diff] [blame] | 6490 | static void |
| 6491 | shell_add_bindings(struct weston_compositor *ec, struct desktop_shell *shell) |
| 6492 | { |
| 6493 | uint32_t mod; |
Jonas Ådahl | e3cddce | 2012-06-13 00:01:22 +0200 | [diff] [blame] | 6494 | int i, num_workspace_bindings; |
Tiago Vignatti | 0b52d48 | 2012-04-20 18:54:25 +0300 | [diff] [blame] | 6495 | |
| 6496 | /* fixed bindings */ |
Daniel Stone | 325fc2d | 2012-05-30 16:31:58 +0100 | [diff] [blame] | 6497 | weston_compositor_add_key_binding(ec, KEY_BACKSPACE, |
| 6498 | MODIFIER_CTRL | MODIFIER_ALT, |
| 6499 | terminate_binding, ec); |
| 6500 | weston_compositor_add_button_binding(ec, BTN_LEFT, 0, |
| 6501 | click_to_activate_binding, |
| 6502 | shell); |
Kristian Høgsberg | f0ce581 | 2014-04-07 11:52:17 -0700 | [diff] [blame] | 6503 | weston_compositor_add_button_binding(ec, BTN_RIGHT, 0, |
| 6504 | click_to_activate_binding, |
| 6505 | shell); |
Neil Roberts | a28c693 | 2013-10-03 16:43:04 +0100 | [diff] [blame] | 6506 | weston_compositor_add_touch_binding(ec, 0, |
| 6507 | touch_to_activate_binding, |
| 6508 | shell); |
Daniel Stone | 325fc2d | 2012-05-30 16:31:58 +0100 | [diff] [blame] | 6509 | weston_compositor_add_axis_binding(ec, WL_POINTER_AXIS_VERTICAL_SCROLL, |
| 6510 | MODIFIER_SUPER | MODIFIER_ALT, |
| 6511 | surface_opacity_binding, NULL); |
| 6512 | weston_compositor_add_axis_binding(ec, WL_POINTER_AXIS_VERTICAL_SCROLL, |
| 6513 | MODIFIER_SUPER, zoom_axis_binding, |
| 6514 | NULL); |
Tiago Vignatti | 0b52d48 | 2012-04-20 18:54:25 +0300 | [diff] [blame] | 6515 | |
| 6516 | /* configurable bindings */ |
| 6517 | mod = shell->binding_modifier; |
Daniel Stone | 325fc2d | 2012-05-30 16:31:58 +0100 | [diff] [blame] | 6518 | weston_compositor_add_key_binding(ec, KEY_PAGEUP, mod, |
| 6519 | zoom_key_binding, NULL); |
| 6520 | weston_compositor_add_key_binding(ec, KEY_PAGEDOWN, mod, |
| 6521 | zoom_key_binding, NULL); |
Kristian Høgsberg | 211b517 | 2014-01-11 13:10:21 -0800 | [diff] [blame] | 6522 | weston_compositor_add_key_binding(ec, KEY_M, mod | MODIFIER_SHIFT, |
| 6523 | maximize_binding, NULL); |
| 6524 | weston_compositor_add_key_binding(ec, KEY_F, mod | MODIFIER_SHIFT, |
| 6525 | fullscreen_binding, NULL); |
Daniel Stone | 325fc2d | 2012-05-30 16:31:58 +0100 | [diff] [blame] | 6526 | weston_compositor_add_button_binding(ec, BTN_LEFT, mod, move_binding, |
| 6527 | shell); |
Neil Roberts | aba0f25 | 2013-10-03 16:43:05 +0100 | [diff] [blame] | 6528 | weston_compositor_add_touch_binding(ec, mod, touch_move_binding, shell); |
Derek Foreman | 2217f3f | 2015-06-25 16:03:30 -0500 | [diff] [blame] | 6529 | weston_compositor_add_button_binding(ec, BTN_RIGHT, mod, |
Daniel Stone | 325fc2d | 2012-05-30 16:31:58 +0100 | [diff] [blame] | 6530 | resize_binding, shell); |
Kristian Høgsberg | 0837fa9 | 2014-01-20 10:35:26 -0800 | [diff] [blame] | 6531 | weston_compositor_add_button_binding(ec, BTN_LEFT, |
| 6532 | mod | MODIFIER_SHIFT, |
| 6533 | resize_binding, shell); |
Pekka Paalanen | 7bb6510 | 2013-05-22 18:03:04 +0300 | [diff] [blame] | 6534 | |
| 6535 | if (ec->capabilities & WESTON_CAP_ROTATION_ANY) |
Derek Foreman | 2217f3f | 2015-06-25 16:03:30 -0500 | [diff] [blame] | 6536 | weston_compositor_add_button_binding(ec, BTN_MIDDLE, mod, |
Pekka Paalanen | 7bb6510 | 2013-05-22 18:03:04 +0300 | [diff] [blame] | 6537 | rotate_binding, NULL); |
| 6538 | |
Daniel Stone | 325fc2d | 2012-05-30 16:31:58 +0100 | [diff] [blame] | 6539 | weston_compositor_add_key_binding(ec, KEY_TAB, mod, switcher_binding, |
| 6540 | shell); |
| 6541 | weston_compositor_add_key_binding(ec, KEY_F9, mod, backlight_binding, |
| 6542 | ec); |
| 6543 | weston_compositor_add_key_binding(ec, KEY_BRIGHTNESSDOWN, 0, |
| 6544 | backlight_binding, ec); |
| 6545 | weston_compositor_add_key_binding(ec, KEY_F10, mod, backlight_binding, |
| 6546 | ec); |
| 6547 | weston_compositor_add_key_binding(ec, KEY_BRIGHTNESSUP, 0, |
| 6548 | backlight_binding, ec); |
Daniel Stone | 325fc2d | 2012-05-30 16:31:58 +0100 | [diff] [blame] | 6549 | weston_compositor_add_key_binding(ec, KEY_K, mod, |
| 6550 | force_kill_binding, shell); |
Jonas Ådahl | e3cddce | 2012-06-13 00:01:22 +0200 | [diff] [blame] | 6551 | weston_compositor_add_key_binding(ec, KEY_UP, mod, |
| 6552 | workspace_up_binding, shell); |
| 6553 | weston_compositor_add_key_binding(ec, KEY_DOWN, mod, |
| 6554 | workspace_down_binding, shell); |
Jonas Ådahl | 8de6a1d | 2012-08-29 22:13:00 +0200 | [diff] [blame] | 6555 | weston_compositor_add_key_binding(ec, KEY_UP, mod | MODIFIER_SHIFT, |
| 6556 | workspace_move_surface_up_binding, |
| 6557 | shell); |
| 6558 | weston_compositor_add_key_binding(ec, KEY_DOWN, mod | MODIFIER_SHIFT, |
| 6559 | workspace_move_surface_down_binding, |
| 6560 | shell); |
Jonas Ådahl | e3cddce | 2012-06-13 00:01:22 +0200 | [diff] [blame] | 6561 | |
Kristian Høgsberg | d56ab4e | 2014-01-16 16:51:52 -0800 | [diff] [blame] | 6562 | if (shell->exposay_modifier) |
| 6563 | weston_compositor_add_modifier_binding(ec, shell->exposay_modifier, |
| 6564 | exposay_binding, shell); |
Daniel Stone | df8133b | 2013-11-19 11:37:14 +0100 | [diff] [blame] | 6565 | |
Jonas Ådahl | e3cddce | 2012-06-13 00:01:22 +0200 | [diff] [blame] | 6566 | /* Add bindings for mod+F[1-6] for workspace 1 to 6. */ |
| 6567 | if (shell->workspaces.num > 1) { |
| 6568 | num_workspace_bindings = shell->workspaces.num; |
| 6569 | if (num_workspace_bindings > 6) |
| 6570 | num_workspace_bindings = 6; |
| 6571 | for (i = 0; i < num_workspace_bindings; i++) |
| 6572 | weston_compositor_add_key_binding(ec, KEY_F1 + i, mod, |
| 6573 | workspace_f_binding, |
| 6574 | shell); |
| 6575 | } |
Ander Conselvan de Oliveira | c509d2b | 2012-11-08 17:20:45 +0200 | [diff] [blame] | 6576 | |
Pekka Paalanen | 2829f7c | 2015-02-19 17:02:13 +0200 | [diff] [blame] | 6577 | weston_install_debug_key_binding(ec, mod); |
Tiago Vignatti | 0b52d48 | 2012-04-20 18:54:25 +0300 | [diff] [blame] | 6578 | } |
| 6579 | |
Jason Ekstrand | 024177c | 2014-04-21 19:42:58 -0500 | [diff] [blame] | 6580 | static void |
| 6581 | handle_seat_created(struct wl_listener *listener, void *data) |
| 6582 | { |
| 6583 | struct weston_seat *seat = data; |
| 6584 | |
| 6585 | create_shell_seat(seat); |
| 6586 | } |
| 6587 | |
Kristian Høgsberg | 1c56218 | 2011-05-02 22:09:20 -0400 | [diff] [blame] | 6588 | WL_EXPORT int |
Kristian Høgsberg | cb4685b | 2013-02-20 15:37:49 -0500 | [diff] [blame] | 6589 | module_init(struct weston_compositor *ec, |
Ossama Othman | a50e6e4 | 2013-05-14 09:48:26 -0700 | [diff] [blame] | 6590 | int *argc, char *argv[]) |
Kristian Høgsberg | 4cca349 | 2011-01-18 07:53:49 -0500 | [diff] [blame] | 6591 | { |
Kristian Høgsberg | f4d2f23 | 2012-08-10 10:05:39 -0400 | [diff] [blame] | 6592 | struct weston_seat *seat; |
Tiago Vignatti | be14326 | 2012-04-16 17:31:41 +0300 | [diff] [blame] | 6593 | struct desktop_shell *shell; |
Jonas Ådahl | e3cddce | 2012-06-13 00:01:22 +0200 | [diff] [blame] | 6594 | struct workspace **pws; |
| 6595 | unsigned int i; |
Tiago Vignatti | b7dbbd6 | 2012-09-25 17:57:01 +0300 | [diff] [blame] | 6596 | struct wl_event_loop *loop; |
Kristian Høgsberg | 02ec0a5 | 2011-04-23 13:04:11 -0400 | [diff] [blame] | 6597 | |
Peter Hutterer | f3d6227 | 2013-08-08 11:57:05 +1000 | [diff] [blame] | 6598 | shell = zalloc(sizeof *shell); |
Kristian Høgsberg | 02ec0a5 | 2011-04-23 13:04:11 -0400 | [diff] [blame] | 6599 | if (shell == NULL) |
| 6600 | return -1; |
| 6601 | |
Kristian Høgsberg | 7584062 | 2011-09-06 13:48:16 -0400 | [diff] [blame] | 6602 | shell->compositor = ec; |
Kristian Høgsberg | 02e79dc | 2012-04-12 09:55:26 -0400 | [diff] [blame] | 6603 | |
| 6604 | shell->destroy_listener.notify = shell_destroy; |
| 6605 | wl_signal_add(&ec->destroy_signal, &shell->destroy_listener); |
Ander Conselvan de Oliveira | a457563 | 2013-02-21 18:35:23 +0200 | [diff] [blame] | 6606 | shell->idle_listener.notify = idle_handler; |
| 6607 | wl_signal_add(&ec->idle_signal, &shell->idle_listener); |
| 6608 | shell->wake_listener.notify = wake_handler; |
| 6609 | wl_signal_add(&ec->wake_signal, &shell->wake_listener); |
Kristian Høgsberg | 677a5f5 | 2013-12-04 11:00:19 -0800 | [diff] [blame] | 6610 | |
Kristian Høgsberg | 82a1d11 | 2012-07-19 14:02:00 -0400 | [diff] [blame] | 6611 | ec->shell_interface.shell = shell; |
Tiago Vignatti | bc052c9 | 2012-04-19 16:18:18 +0300 | [diff] [blame] | 6612 | ec->shell_interface.create_shell_surface = create_shell_surface; |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 6613 | ec->shell_interface.get_primary_view = get_primary_view; |
Tiago Vignatti | bc052c9 | 2012-04-19 16:18:18 +0300 | [diff] [blame] | 6614 | ec->shell_interface.set_toplevel = set_toplevel; |
Tiago Vignatti | 491bac1 | 2012-05-18 16:37:43 -0400 | [diff] [blame] | 6615 | ec->shell_interface.set_transient = set_transient; |
Kristian Høgsberg | 4779241 | 2014-05-04 13:47:06 -0700 | [diff] [blame] | 6616 | ec->shell_interface.set_fullscreen = shell_interface_set_fullscreen; |
Tiago Vignatti | fb2adba | 2013-06-12 15:43:21 -0300 | [diff] [blame] | 6617 | ec->shell_interface.set_xwayland = set_xwayland; |
Kristian Høgsberg | ae356ae | 2014-04-29 16:03:54 -0700 | [diff] [blame] | 6618 | ec->shell_interface.move = shell_interface_move; |
Derek Foreman | 8fbebbd | 2015-07-15 13:00:40 -0500 | [diff] [blame] | 6619 | ec->shell_interface.resize = shell_interface_resize; |
Giulio Camuffo | 62942ad | 2013-09-11 18:20:47 +0200 | [diff] [blame] | 6620 | ec->shell_interface.set_title = set_title; |
Jasper St. Pierre | ccf48fb | 2014-05-02 10:21:38 -0400 | [diff] [blame] | 6621 | ec->shell_interface.set_window_geometry = set_window_geometry; |
Giulio Camuffo | 6b4b241 | 2015-01-29 19:06:49 +0200 | [diff] [blame] | 6622 | ec->shell_interface.set_maximized = shell_interface_set_maximized; |
Giulio Camuffo | a8e9b41 | 2015-01-27 19:10:37 +0200 | [diff] [blame] | 6623 | ec->shell_interface.set_pid = set_pid; |
Kristian Høgsberg | 4cca349 | 2011-01-18 07:53:49 -0500 | [diff] [blame] | 6624 | |
Kristian Høgsberg | 3be2ce9 | 2012-02-29 12:42:35 -0500 | [diff] [blame] | 6625 | weston_layer_init(&shell->fullscreen_layer, &ec->cursor_layer.link); |
| 6626 | weston_layer_init(&shell->panel_layer, &shell->fullscreen_layer.link); |
Jonas Ådahl | e3cddce | 2012-06-13 00:01:22 +0200 | [diff] [blame] | 6627 | weston_layer_init(&shell->background_layer, &shell->panel_layer.link); |
| 6628 | weston_layer_init(&shell->lock_layer, NULL); |
Philipp Brüschweiler | 711fda8 | 2012-08-09 18:50:43 +0200 | [diff] [blame] | 6629 | weston_layer_init(&shell->input_panel_layer, NULL); |
Jonas Ådahl | e3cddce | 2012-06-13 00:01:22 +0200 | [diff] [blame] | 6630 | |
| 6631 | wl_array_init(&shell->workspaces.array); |
Jonas Ådahl | e9d2250 | 2012-08-29 22:13:01 +0200 | [diff] [blame] | 6632 | wl_list_init(&shell->workspaces.client_list); |
Kristian Høgsberg | 3be2ce9 | 2012-02-29 12:42:35 -0500 | [diff] [blame] | 6633 | |
Kristian Høgsberg | 677a5f5 | 2013-12-04 11:00:19 -0800 | [diff] [blame] | 6634 | if (input_panel_setup(shell) < 0) |
| 6635 | return -1; |
| 6636 | |
Pekka Paalanen | aa9536a | 2015-06-24 16:09:17 +0300 | [diff] [blame] | 6637 | shell->text_backend = text_backend_init(ec); |
| 6638 | if (!shell->text_backend) |
Murray Calavera | 9a51cd7 | 2015-06-10 21:16:02 +0000 | [diff] [blame] | 6639 | return -1; |
| 6640 | |
Kristian Høgsberg | 14e438c | 2013-05-26 21:48:14 -0400 | [diff] [blame] | 6641 | shell_configuration(shell); |
Pekka Paalanen | e955f1e | 2011-12-07 11:49:52 +0200 | [diff] [blame] | 6642 | |
Daniel Stone | df8133b | 2013-11-19 11:37:14 +0100 | [diff] [blame] | 6643 | shell->exposay.state_cur = EXPOSAY_LAYOUT_INACTIVE; |
| 6644 | shell->exposay.state_target = EXPOSAY_TARGET_CANCEL; |
| 6645 | |
Jonas Ådahl | e3cddce | 2012-06-13 00:01:22 +0200 | [diff] [blame] | 6646 | for (i = 0; i < shell->workspaces.num; i++) { |
| 6647 | pws = wl_array_add(&shell->workspaces.array, sizeof *pws); |
| 6648 | if (pws == NULL) |
| 6649 | return -1; |
| 6650 | |
| 6651 | *pws = workspace_create(); |
| 6652 | if (*pws == NULL) |
| 6653 | return -1; |
| 6654 | } |
| 6655 | activate_workspace(shell, 0); |
| 6656 | |
Manuel Bachmann | 50c87db | 2014-02-26 15:52:13 +0100 | [diff] [blame] | 6657 | weston_layer_init(&shell->minimized_layer, NULL); |
| 6658 | |
Jonas Ådahl | 8de6a1d | 2012-08-29 22:13:00 +0200 | [diff] [blame] | 6659 | wl_list_init(&shell->workspaces.anim_sticky_list); |
Jonas Ådahl | 62fcd04 | 2012-06-13 00:01:23 +0200 | [diff] [blame] | 6660 | wl_list_init(&shell->workspaces.animation.link); |
| 6661 | shell->workspaces.animation.frame = animate_workspace_change_frame; |
| 6662 | |
Kristian Høgsberg | 919cddb | 2013-07-08 19:03:57 -0400 | [diff] [blame] | 6663 | if (wl_global_create(ec->wl_display, &wl_shell_interface, 1, |
Kristian Høgsberg | 97d44aa | 2011-08-26 17:21:20 -0400 | [diff] [blame] | 6664 | shell, bind_shell) == NULL) |
Kristian Høgsberg | 4cca349 | 2011-01-18 07:53:49 -0500 | [diff] [blame] | 6665 | return -1; |
| 6666 | |
Rafael Antognolli | e2a3455 | 2013-12-03 15:35:45 -0200 | [diff] [blame] | 6667 | if (wl_global_create(ec->wl_display, &xdg_shell_interface, 1, |
| 6668 | shell, bind_xdg_shell) == NULL) |
| 6669 | return -1; |
| 6670 | |
Kristian Høgsberg | 919cddb | 2013-07-08 19:03:57 -0400 | [diff] [blame] | 6671 | if (wl_global_create(ec->wl_display, |
Jonny Lamb | 765760d | 2014-08-20 15:53:19 +0200 | [diff] [blame] | 6672 | &desktop_shell_interface, 3, |
Kristian Høgsberg | 919cddb | 2013-07-08 19:03:57 -0400 | [diff] [blame] | 6673 | shell, bind_desktop_shell) == NULL) |
Kristian Høgsberg | 7584062 | 2011-09-06 13:48:16 -0400 | [diff] [blame] | 6674 | return -1; |
| 6675 | |
Kristian Høgsberg | 919cddb | 2013-07-08 19:03:57 -0400 | [diff] [blame] | 6676 | if (wl_global_create(ec->wl_display, &workspace_manager_interface, 1, |
| 6677 | shell, bind_workspace_manager) == NULL) |
Jonas Ådahl | e9d2250 | 2012-08-29 22:13:01 +0200 | [diff] [blame] | 6678 | return -1; |
| 6679 | |
Kristian Høgsberg | f03a616 | 2012-01-17 11:07:42 -0500 | [diff] [blame] | 6680 | shell->child.deathstamp = weston_compositor_get_time(); |
Tiago Vignatti | b7dbbd6 | 2012-09-25 17:57:01 +0300 | [diff] [blame] | 6681 | |
Jonny Lamb | 765760d | 2014-08-20 15:53:19 +0200 | [diff] [blame] | 6682 | shell->panel_position = DESKTOP_SHELL_PANEL_POSITION_TOP; |
| 6683 | |
Xiong Zhang | 6b48142 | 2013-10-23 13:58:32 +0800 | [diff] [blame] | 6684 | setup_output_destroy_handler(ec, shell); |
| 6685 | |
Tiago Vignatti | b7dbbd6 | 2012-09-25 17:57:01 +0300 | [diff] [blame] | 6686 | loop = wl_display_get_event_loop(ec->wl_display); |
| 6687 | wl_event_loop_add_idle(loop, launch_desktop_shell_process, shell); |
Pekka Paalanen | 6cd281a | 2011-11-03 14:11:32 +0200 | [diff] [blame] | 6688 | |
Jason Ekstrand | 024177c | 2014-04-21 19:42:58 -0500 | [diff] [blame] | 6689 | wl_list_for_each(seat, &ec->seat_list, link) |
| 6690 | handle_seat_created(NULL, seat); |
| 6691 | shell->seat_create_listener.notify = handle_seat_created; |
| 6692 | wl_signal_add(&ec->seat_created_signal, &shell->seat_create_listener); |
Kristian Høgsberg | d56bd90 | 2012-06-05 09:58:51 -0400 | [diff] [blame] | 6693 | |
Giulio Camuffo | c6ab3d5 | 2013-12-11 23:45:12 +0100 | [diff] [blame] | 6694 | screenshooter_create(ec); |
| 6695 | |
Tiago Vignatti | 0b52d48 | 2012-04-20 18:54:25 +0300 | [diff] [blame] | 6696 | shell_add_bindings(ec, shell); |
Kristian Høgsberg | 0793756 | 2011-04-12 17:25:42 -0400 | [diff] [blame] | 6697 | |
Pekka Paalanen | 79346ab | 2013-05-22 18:03:09 +0300 | [diff] [blame] | 6698 | shell_fade_init(shell); |
Ander Conselvan de Oliveira | 19d10ef | 2013-02-21 18:35:20 +0200 | [diff] [blame] | 6699 | |
Pekka Paalanen | 2e62e4a | 2014-08-28 11:41:26 +0300 | [diff] [blame] | 6700 | clock_gettime(CLOCK_MONOTONIC, &shell->startup_time); |
| 6701 | |
Kristian Høgsberg | 4cca349 | 2011-01-18 07:53:49 -0500 | [diff] [blame] | 6702 | return 0; |
| 6703 | } |