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; |
| 381 | |
Kristian Høgsberg | 57e0907 | 2012-10-30 14:07:27 -0400 | [diff] [blame] | 382 | popup_grab_end(pointer); |
Jonny Lamb | 76cf1fe | 2014-08-20 11:27:10 +0200 | [diff] [blame] | 383 | if (pointer->seat->touch) |
| 384 | touch_popup_grab_end(pointer->seat->touch); |
Kristian Høgsberg | 57e0907 | 2012-10-30 14:07:27 -0400 | [diff] [blame] | 385 | |
Ander Conselvan de Oliveira | fe0444a | 2012-04-04 17:48:05 +0300 | [diff] [blame] | 386 | grab->grab.interface = interface; |
| 387 | grab->shsurf = shsurf; |
Kristian Høgsberg | 27e3052 | 2012-04-11 23:18:23 -0400 | [diff] [blame] | 388 | grab->shsurf_destroy_listener.notify = destroy_shell_grab_shsurf; |
Jason Ekstrand | 651f00e | 2013-06-14 10:07:54 -0500 | [diff] [blame] | 389 | wl_signal_add(&shsurf->destroy_signal, |
Kristian Høgsberg | 27e3052 | 2012-04-11 23:18:23 -0400 | [diff] [blame] | 390 | &grab->shsurf_destroy_listener); |
Ander Conselvan de Oliveira | fe0444a | 2012-04-04 17:48:05 +0300 | [diff] [blame] | 391 | |
Kristian Høgsberg | c85f1d4 | 2013-10-24 16:52:00 -0700 | [diff] [blame] | 392 | shsurf->grabbed = 1; |
Kristian Høgsberg | 02bbabb | 2013-05-06 22:15:05 -0400 | [diff] [blame] | 393 | weston_pointer_start_grab(pointer, &grab->grab); |
Kristian Høgsberg | c9974a0 | 2013-07-03 19:24:57 -0400 | [diff] [blame] | 394 | if (shell->child.desktop_shell) { |
| 395 | desktop_shell_send_grab_cursor(shell->child.desktop_shell, |
| 396 | cursor); |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 397 | weston_pointer_set_focus(pointer, |
| 398 | get_default_view(shell->grab_surface), |
Kristian Høgsberg | c9974a0 | 2013-07-03 19:24:57 -0400 | [diff] [blame] | 399 | wl_fixed_from_int(0), |
| 400 | wl_fixed_from_int(0)); |
| 401 | } |
Ander Conselvan de Oliveira | fe0444a | 2012-04-04 17:48:05 +0300 | [diff] [blame] | 402 | } |
| 403 | |
Jonny Lamb | d73c694 | 2014-08-20 15:53:20 +0200 | [diff] [blame] | 404 | static void |
| 405 | get_output_panel_size(struct desktop_shell *shell, |
| 406 | struct weston_output *output, |
| 407 | int *width, |
| 408 | int *height) |
Jasper St. Pierre | 6458ec3 | 2014-04-11 16:00:31 -0700 | [diff] [blame] | 409 | { |
| 410 | struct weston_view *view; |
Jonny Lamb | d73c694 | 2014-08-20 15:53:20 +0200 | [diff] [blame] | 411 | |
| 412 | *width = 0; |
| 413 | *height = 0; |
Jasper St. Pierre | 6458ec3 | 2014-04-11 16:00:31 -0700 | [diff] [blame] | 414 | |
| 415 | if (!output) |
Jonny Lamb | d73c694 | 2014-08-20 15:53:20 +0200 | [diff] [blame] | 416 | return; |
Jasper St. Pierre | 6458ec3 | 2014-04-11 16:00:31 -0700 | [diff] [blame] | 417 | |
Giulio Camuffo | 412e6a5 | 2014-07-09 22:12:56 +0300 | [diff] [blame] | 418 | 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] | 419 | float x, y; |
| 420 | |
| 421 | if (view->surface->output != output) |
| 422 | continue; |
| 423 | |
| 424 | switch (shell->panel_position) { |
| 425 | case DESKTOP_SHELL_PANEL_POSITION_TOP: |
| 426 | case DESKTOP_SHELL_PANEL_POSITION_BOTTOM: |
Jonny Lamb | d73c694 | 2014-08-20 15:53:20 +0200 | [diff] [blame] | 427 | weston_view_to_global_float(view, |
| 428 | view->surface->width, 0, |
| 429 | &x, &y); |
| 430 | |
Derek Foreman | 612341f | 2015-04-15 12:23:55 -0500 | [diff] [blame] | 431 | *width = (int)x - output->x; |
| 432 | *height = view->surface->height + (int) y - output->y; |
Jonny Lamb | d73c694 | 2014-08-20 15:53:20 +0200 | [diff] [blame] | 433 | return; |
| 434 | |
| 435 | case DESKTOP_SHELL_PANEL_POSITION_LEFT: |
| 436 | case DESKTOP_SHELL_PANEL_POSITION_RIGHT: |
| 437 | weston_view_to_global_float(view, |
| 438 | 0, view->surface->height, |
| 439 | &x, &y); |
| 440 | |
Derek Foreman | 612341f | 2015-04-15 12:23:55 -0500 | [diff] [blame] | 441 | *width = view->surface->width + (int)x - output->x; |
| 442 | *height = (int)y - output->y; |
Jonny Lamb | d73c694 | 2014-08-20 15:53:20 +0200 | [diff] [blame] | 443 | return; |
| 444 | |
| 445 | default: |
| 446 | /* we've already set width and height to |
| 447 | * fallback values. */ |
Jasper St. Pierre | 6458ec3 | 2014-04-11 16:00:31 -0700 | [diff] [blame] | 448 | break; |
| 449 | } |
| 450 | } |
| 451 | |
Jonny Lamb | d73c694 | 2014-08-20 15:53:20 +0200 | [diff] [blame] | 452 | /* the correct view wasn't found */ |
| 453 | } |
| 454 | |
| 455 | static void |
| 456 | get_output_work_area(struct desktop_shell *shell, |
| 457 | struct weston_output *output, |
| 458 | pixman_rectangle32_t *area) |
| 459 | { |
| 460 | int32_t panel_width = 0, panel_height = 0; |
| 461 | |
Derek Foreman | f814c5d | 2015-04-15 12:23:54 -0500 | [diff] [blame] | 462 | area->x = output->x; |
| 463 | area->y = output->y; |
Jonny Lamb | d73c694 | 2014-08-20 15:53:20 +0200 | [diff] [blame] | 464 | |
| 465 | get_output_panel_size(shell, output, &panel_width, &panel_height); |
Jonny Lamb | d73c694 | 2014-08-20 15:53:20 +0200 | [diff] [blame] | 466 | switch (shell->panel_position) { |
| 467 | case DESKTOP_SHELL_PANEL_POSITION_TOP: |
| 468 | default: |
Derek Foreman | f814c5d | 2015-04-15 12:23:54 -0500 | [diff] [blame] | 469 | area->y += panel_height; |
Jonny Lamb | d73c694 | 2014-08-20 15:53:20 +0200 | [diff] [blame] | 470 | case DESKTOP_SHELL_PANEL_POSITION_BOTTOM: |
| 471 | area->width = output->width; |
| 472 | area->height = output->height - panel_height; |
| 473 | break; |
| 474 | case DESKTOP_SHELL_PANEL_POSITION_LEFT: |
Derek Foreman | f814c5d | 2015-04-15 12:23:54 -0500 | [diff] [blame] | 475 | area->x += panel_width; |
Jonny Lamb | d73c694 | 2014-08-20 15:53:20 +0200 | [diff] [blame] | 476 | case DESKTOP_SHELL_PANEL_POSITION_RIGHT: |
| 477 | area->width = output->width - panel_width; |
| 478 | area->height = output->height; |
| 479 | break; |
| 480 | } |
Jasper St. Pierre | 6458ec3 | 2014-04-11 16:00:31 -0700 | [diff] [blame] | 481 | } |
| 482 | |
| 483 | static void |
| 484 | send_configure_for_surface(struct shell_surface *shsurf) |
| 485 | { |
| 486 | int32_t width, height; |
| 487 | struct surface_state *state; |
| 488 | |
| 489 | if (shsurf->state_requested) |
| 490 | state = &shsurf->requested_state; |
| 491 | else if (shsurf->state_changed) |
| 492 | state = &shsurf->next_state; |
| 493 | else |
| 494 | state = &shsurf->state; |
| 495 | |
| 496 | if (state->fullscreen) { |
| 497 | width = shsurf->output->width; |
| 498 | height = shsurf->output->height; |
| 499 | } else if (state->maximized) { |
| 500 | struct desktop_shell *shell; |
Jonny Lamb | d73c694 | 2014-08-20 15:53:20 +0200 | [diff] [blame] | 501 | pixman_rectangle32_t area; |
Jasper St. Pierre | 6458ec3 | 2014-04-11 16:00:31 -0700 | [diff] [blame] | 502 | |
| 503 | shell = shell_surface_get_shell(shsurf); |
Jonny Lamb | d73c694 | 2014-08-20 15:53:20 +0200 | [diff] [blame] | 504 | get_output_work_area(shell, shsurf->output, &area); |
Jasper St. Pierre | 6458ec3 | 2014-04-11 16:00:31 -0700 | [diff] [blame] | 505 | |
Jonny Lamb | d73c694 | 2014-08-20 15:53:20 +0200 | [diff] [blame] | 506 | width = area.width; |
| 507 | height = area.height; |
Ryo Munakata | 79954ec | 2015-05-02 21:44:04 +0900 | [diff] [blame] | 508 | } else if (shsurf->resize_edges) { |
| 509 | width = shsurf->geometry.width; |
| 510 | height = shsurf->geometry.height; |
Jasper St. Pierre | 6458ec3 | 2014-04-11 16:00:31 -0700 | [diff] [blame] | 511 | } else { |
| 512 | width = 0; |
| 513 | height = 0; |
| 514 | } |
| 515 | |
| 516 | shsurf->client->send_configure(shsurf->surface, width, height); |
| 517 | } |
| 518 | |
Ander Conselvan de Oliveira | fe0444a | 2012-04-04 17:48:05 +0300 | [diff] [blame] | 519 | static void |
Jasper St. Pierre | 5befdda | 2014-05-06 08:50:47 -0400 | [diff] [blame] | 520 | shell_surface_state_changed(struct shell_surface *shsurf) |
| 521 | { |
Jasper St. Pierre | 6458ec3 | 2014-04-11 16:00:31 -0700 | [diff] [blame] | 522 | if (shell_surface_is_xdg_surface(shsurf)) |
| 523 | send_configure_for_surface(shsurf); |
Jasper St. Pierre | 5befdda | 2014-05-06 08:50:47 -0400 | [diff] [blame] | 524 | } |
| 525 | |
| 526 | static void |
Ander Conselvan de Oliveira | b9d2a0f | 2012-06-28 18:08:05 +0300 | [diff] [blame] | 527 | shell_grab_end(struct shell_grab *grab) |
Ander Conselvan de Oliveira | fe0444a | 2012-04-04 17:48:05 +0300 | [diff] [blame] | 528 | { |
Kristian Høgsberg | c85f1d4 | 2013-10-24 16:52:00 -0700 | [diff] [blame] | 529 | if (grab->shsurf) { |
Kristian Høgsberg | 47b5dca | 2012-06-07 18:08:04 -0400 | [diff] [blame] | 530 | wl_list_remove(&grab->shsurf_destroy_listener.link); |
Kristian Høgsberg | c85f1d4 | 2013-10-24 16:52:00 -0700 | [diff] [blame] | 531 | grab->shsurf->grabbed = 0; |
Jasper St. Pierre | 5befdda | 2014-05-06 08:50:47 -0400 | [diff] [blame] | 532 | |
| 533 | if (grab->shsurf->resize_edges) { |
| 534 | grab->shsurf->resize_edges = 0; |
| 535 | shell_surface_state_changed(grab->shsurf); |
| 536 | } |
Kristian Høgsberg | c85f1d4 | 2013-10-24 16:52:00 -0700 | [diff] [blame] | 537 | } |
Ander Conselvan de Oliveira | b9d2a0f | 2012-06-28 18:08:05 +0300 | [diff] [blame] | 538 | |
Kristian Høgsberg | 9e5d7d1 | 2013-07-22 16:31:53 -0700 | [diff] [blame] | 539 | weston_pointer_end_grab(grab->grab.pointer); |
Ander Conselvan de Oliveira | fe0444a | 2012-04-04 17:48:05 +0300 | [diff] [blame] | 540 | } |
| 541 | |
| 542 | static void |
Rusty Lynch | 1084da5 | 2013-08-15 09:10:08 -0700 | [diff] [blame] | 543 | shell_touch_grab_start(struct shell_touch_grab *grab, |
| 544 | const struct weston_touch_grab_interface *interface, |
| 545 | struct shell_surface *shsurf, |
| 546 | struct weston_touch *touch) |
| 547 | { |
| 548 | struct desktop_shell *shell = shsurf->shell; |
U. Artie Eoff | cf5737a | 2014-01-17 10:08:25 -0800 | [diff] [blame] | 549 | |
Jonny Lamb | 76cf1fe | 2014-08-20 11:27:10 +0200 | [diff] [blame] | 550 | touch_popup_grab_end(touch); |
Kristian Høgsberg | 74071e0 | 2014-04-29 15:01:16 -0700 | [diff] [blame] | 551 | if (touch->seat->pointer) |
| 552 | popup_grab_end(touch->seat->pointer); |
| 553 | |
Rusty Lynch | 1084da5 | 2013-08-15 09:10:08 -0700 | [diff] [blame] | 554 | grab->grab.interface = interface; |
| 555 | grab->shsurf = shsurf; |
| 556 | grab->shsurf_destroy_listener.notify = destroy_shell_grab_shsurf; |
| 557 | wl_signal_add(&shsurf->destroy_signal, |
| 558 | &grab->shsurf_destroy_listener); |
| 559 | |
| 560 | grab->touch = touch; |
Kristian Høgsberg | c85f1d4 | 2013-10-24 16:52:00 -0700 | [diff] [blame] | 561 | shsurf->grabbed = 1; |
Rusty Lynch | 1084da5 | 2013-08-15 09:10:08 -0700 | [diff] [blame] | 562 | |
| 563 | weston_touch_start_grab(touch, &grab->grab); |
| 564 | if (shell->child.desktop_shell) |
Derek Foreman | 4c93c08 | 2015-04-30 16:45:41 -0500 | [diff] [blame] | 565 | weston_touch_set_focus(touch, |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 566 | get_default_view(shell->grab_surface)); |
Rusty Lynch | 1084da5 | 2013-08-15 09:10:08 -0700 | [diff] [blame] | 567 | } |
| 568 | |
| 569 | static void |
| 570 | shell_touch_grab_end(struct shell_touch_grab *grab) |
| 571 | { |
Kristian Høgsberg | c85f1d4 | 2013-10-24 16:52:00 -0700 | [diff] [blame] | 572 | if (grab->shsurf) { |
Rusty Lynch | 1084da5 | 2013-08-15 09:10:08 -0700 | [diff] [blame] | 573 | wl_list_remove(&grab->shsurf_destroy_listener.link); |
Kristian Høgsberg | c85f1d4 | 2013-10-24 16:52:00 -0700 | [diff] [blame] | 574 | grab->shsurf->grabbed = 0; |
| 575 | } |
Rusty Lynch | 1084da5 | 2013-08-15 09:10:08 -0700 | [diff] [blame] | 576 | |
| 577 | weston_touch_end_grab(grab->touch); |
| 578 | } |
| 579 | |
| 580 | static void |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 581 | center_on_output(struct weston_view *view, |
Alex Wu | 4539b08 | 2012-03-01 12:57:46 +0800 | [diff] [blame] | 582 | struct weston_output *output); |
| 583 | |
Daniel Stone | 496ca17 | 2012-05-30 16:31:42 +0100 | [diff] [blame] | 584 | static enum weston_keyboard_modifier |
Tiago Vignatti | 0b52d48 | 2012-04-20 18:54:25 +0300 | [diff] [blame] | 585 | get_modifier(char *modifier) |
| 586 | { |
| 587 | if (!modifier) |
| 588 | return MODIFIER_SUPER; |
| 589 | |
| 590 | if (!strcmp("ctrl", modifier)) |
| 591 | return MODIFIER_CTRL; |
| 592 | else if (!strcmp("alt", modifier)) |
| 593 | return MODIFIER_ALT; |
| 594 | else if (!strcmp("super", modifier)) |
| 595 | return MODIFIER_SUPER; |
| 596 | else |
| 597 | return MODIFIER_SUPER; |
| 598 | } |
| 599 | |
Juan Zhao | e10d279 | 2012-04-25 19:09:52 +0800 | [diff] [blame] | 600 | static enum animation_type |
| 601 | get_animation_type(char *animation) |
| 602 | { |
U. Artie Eoff | b571910 | 2014-01-15 14:26:31 -0800 | [diff] [blame] | 603 | if (!animation) |
| 604 | return ANIMATION_NONE; |
| 605 | |
Juan Zhao | e10d279 | 2012-04-25 19:09:52 +0800 | [diff] [blame] | 606 | if (!strcmp("zoom", animation)) |
| 607 | return ANIMATION_ZOOM; |
| 608 | else if (!strcmp("fade", animation)) |
| 609 | return ANIMATION_FADE; |
Louis-Francis Ratté-Boulianne | b482dbd | 2013-11-19 11:37:11 +0100 | [diff] [blame] | 610 | else if (!strcmp("dim-layer", animation)) |
| 611 | return ANIMATION_DIM_LAYER; |
Juan Zhao | e10d279 | 2012-04-25 19:09:52 +0800 | [diff] [blame] | 612 | else |
| 613 | return ANIMATION_NONE; |
| 614 | } |
| 615 | |
Alex Wu | 4539b08 | 2012-03-01 12:57:46 +0800 | [diff] [blame] | 616 | static void |
Kristian Høgsberg | 14e438c | 2013-05-26 21:48:14 -0400 | [diff] [blame] | 617 | shell_configuration(struct desktop_shell *shell) |
Pekka Paalanen | e955f1e | 2011-12-07 11:49:52 +0200 | [diff] [blame] | 618 | { |
Kristian Høgsberg | 673a889 | 2013-05-23 21:40:56 -0400 | [diff] [blame] | 619 | struct weston_config_section *section; |
Derek Foreman | c721043 | 2014-08-21 11:32:38 -0500 | [diff] [blame] | 620 | char *s, *client; |
Pekka Paalanen | 974c094 | 2014-09-05 14:45:09 +0300 | [diff] [blame] | 621 | int ret; |
Pekka Paalanen | e955f1e | 2011-12-07 11:49:52 +0200 | [diff] [blame] | 622 | |
Kristian Høgsberg | 673a889 | 2013-05-23 21:40:56 -0400 | [diff] [blame] | 623 | section = weston_config_get_section(shell->compositor->config, |
Kristian Høgsberg | 673a889 | 2013-05-23 21:40:56 -0400 | [diff] [blame] | 624 | "shell", NULL, NULL); |
Pekka Paalanen | 974c094 | 2014-09-05 14:45:09 +0300 | [diff] [blame] | 625 | ret = asprintf(&client, "%s/%s", weston_config_get_libexec_dir(), |
| 626 | WESTON_SHELL_CLIENT); |
| 627 | if (ret < 0) |
| 628 | client = NULL; |
Kristian Høgsberg | 673a889 | 2013-05-23 21:40:56 -0400 | [diff] [blame] | 629 | weston_config_section_get_string(section, |
Derek Foreman | c721043 | 2014-08-21 11:32:38 -0500 | [diff] [blame] | 630 | "client", &s, client); |
| 631 | free(client); |
Emilio Pozuelo Monfort | 46ce798 | 2013-11-20 13:22:29 +0100 | [diff] [blame] | 632 | shell->client = s; |
| 633 | weston_config_section_get_string(section, |
Kristian Høgsberg | 673a889 | 2013-05-23 21:40:56 -0400 | [diff] [blame] | 634 | "binding-modifier", &s, "super"); |
| 635 | shell->binding_modifier = get_modifier(s); |
Quentin Glidic | 8418c29 | 2013-06-18 09:11:03 +0200 | [diff] [blame] | 636 | free(s); |
Kristian Høgsberg | d56ab4e | 2014-01-16 16:51:52 -0800 | [diff] [blame] | 637 | |
| 638 | weston_config_section_get_string(section, |
| 639 | "exposay-modifier", &s, "none"); |
| 640 | if (strcmp(s, "none") == 0) |
| 641 | shell->exposay_modifier = 0; |
| 642 | else |
| 643 | shell->exposay_modifier = get_modifier(s); |
| 644 | free(s); |
| 645 | |
Kristian Høgsberg | 673a889 | 2013-05-23 21:40:56 -0400 | [diff] [blame] | 646 | weston_config_section_get_string(section, "animation", &s, "none"); |
| 647 | shell->win_animation_type = get_animation_type(s); |
Quentin Glidic | 8418c29 | 2013-06-18 09:11:03 +0200 | [diff] [blame] | 648 | free(s); |
Jonny Lamb | f322f8e | 2014-08-12 15:13:30 +0200 | [diff] [blame] | 649 | weston_config_section_get_string(section, "close-animation", &s, "fade"); |
| 650 | shell->win_close_animation_type = get_animation_type(s); |
| 651 | free(s); |
Kristian Høgsberg | 724c8d9 | 2013-10-16 11:38:24 -0700 | [diff] [blame] | 652 | weston_config_section_get_string(section, |
| 653 | "startup-animation", &s, "fade"); |
| 654 | shell->startup_animation_type = get_animation_type(s); |
| 655 | free(s); |
Kristian Høgsberg | 912e0a1 | 2013-10-30 08:59:55 -0700 | [diff] [blame] | 656 | if (shell->startup_animation_type == ANIMATION_ZOOM) |
| 657 | shell->startup_animation_type = ANIMATION_NONE; |
Louis-Francis Ratté-Boulianne | b482dbd | 2013-11-19 11:37:11 +0100 | [diff] [blame] | 658 | weston_config_section_get_string(section, "focus-animation", &s, "none"); |
| 659 | shell->focus_animation_type = get_animation_type(s); |
| 660 | free(s); |
Kristian Høgsberg | 673a889 | 2013-05-23 21:40:56 -0400 | [diff] [blame] | 661 | weston_config_section_get_uint(section, "num-workspaces", |
| 662 | &shell->workspaces.num, |
| 663 | DEFAULT_NUM_WORKSPACES); |
Jonas Ådahl | e3cddce | 2012-06-13 00:01:22 +0200 | [diff] [blame] | 664 | } |
| 665 | |
Kristian Høgsberg | 1ef2313 | 2013-12-04 00:20:01 -0800 | [diff] [blame] | 666 | struct weston_output * |
Louis-Francis Ratté-Boulianne | b482dbd | 2013-11-19 11:37:11 +0100 | [diff] [blame] | 667 | get_default_output(struct weston_compositor *compositor) |
| 668 | { |
| 669 | return container_of(compositor->output_list.next, |
| 670 | struct weston_output, link); |
| 671 | } |
| 672 | |
Pekka Paalanen | 8274d90 | 2014-08-06 19:36:51 +0300 | [diff] [blame] | 673 | static int |
| 674 | focus_surface_get_label(struct weston_surface *surface, char *buf, size_t len) |
| 675 | { |
| 676 | return snprintf(buf, len, "focus highlight effect for output %s", |
| 677 | surface->output->name); |
| 678 | } |
Louis-Francis Ratté-Boulianne | b482dbd | 2013-11-19 11:37:11 +0100 | [diff] [blame] | 679 | |
| 680 | /* no-op func for checking focus surface */ |
| 681 | static void |
Jason Ekstrand | 918f2dd | 2013-12-02 21:01:53 -0600 | [diff] [blame] | 682 | 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] | 683 | { |
| 684 | } |
| 685 | |
| 686 | static struct focus_surface * |
| 687 | get_focus_surface(struct weston_surface *surface) |
| 688 | { |
| 689 | if (surface->configure == focus_surface_configure) |
| 690 | return surface->configure_private; |
| 691 | else |
| 692 | return NULL; |
| 693 | } |
| 694 | |
| 695 | static bool |
| 696 | is_focus_surface (struct weston_surface *es) |
| 697 | { |
| 698 | return (es->configure == focus_surface_configure); |
| 699 | } |
| 700 | |
| 701 | static bool |
| 702 | is_focus_view (struct weston_view *view) |
| 703 | { |
| 704 | return is_focus_surface (view->surface); |
| 705 | } |
| 706 | |
| 707 | static struct focus_surface * |
| 708 | create_focus_surface(struct weston_compositor *ec, |
| 709 | struct weston_output *output) |
| 710 | { |
| 711 | struct focus_surface *fsurf = NULL; |
| 712 | struct weston_surface *surface = NULL; |
| 713 | |
| 714 | fsurf = malloc(sizeof *fsurf); |
| 715 | if (!fsurf) |
| 716 | return NULL; |
| 717 | |
| 718 | fsurf->surface = weston_surface_create(ec); |
| 719 | surface = fsurf->surface; |
| 720 | if (surface == NULL) { |
| 721 | free(fsurf); |
| 722 | return NULL; |
| 723 | } |
| 724 | |
| 725 | surface->configure = focus_surface_configure; |
| 726 | surface->output = output; |
| 727 | surface->configure_private = fsurf; |
Pekka Paalanen | 8274d90 | 2014-08-06 19:36:51 +0300 | [diff] [blame] | 728 | weston_surface_set_label_func(surface, focus_surface_get_label); |
Louis-Francis Ratté-Boulianne | b482dbd | 2013-11-19 11:37:11 +0100 | [diff] [blame] | 729 | |
U. Artie Eoff | 0b23b2b | 2014-01-15 14:45:59 -0800 | [diff] [blame] | 730 | fsurf->view = weston_view_create(surface); |
| 731 | if (fsurf->view == NULL) { |
| 732 | weston_surface_destroy(surface); |
| 733 | free(fsurf); |
| 734 | return NULL; |
| 735 | } |
Emilio Pozuelo Monfort | da64426 | 2013-11-19 11:37:19 +0100 | [diff] [blame] | 736 | fsurf->view->output = output; |
Louis-Francis Ratté-Boulianne | b482dbd | 2013-11-19 11:37:11 +0100 | [diff] [blame] | 737 | |
Jason Ekstrand | 5c11a33 | 2013-12-04 20:32:03 -0600 | [diff] [blame] | 738 | weston_surface_set_size(surface, output->width, output->height); |
Jason Ekstrand | 918f2dd | 2013-12-02 21:01:53 -0600 | [diff] [blame] | 739 | weston_view_set_position(fsurf->view, output->x, output->y); |
Louis-Francis Ratté-Boulianne | b482dbd | 2013-11-19 11:37:11 +0100 | [diff] [blame] | 740 | weston_surface_set_color(surface, 0.0, 0.0, 0.0, 1.0); |
| 741 | pixman_region32_fini(&surface->opaque); |
| 742 | pixman_region32_init_rect(&surface->opaque, output->x, output->y, |
| 743 | output->width, output->height); |
| 744 | pixman_region32_fini(&surface->input); |
| 745 | pixman_region32_init(&surface->input); |
| 746 | |
| 747 | wl_list_init(&fsurf->workspace_transform.link); |
| 748 | |
| 749 | return fsurf; |
| 750 | } |
| 751 | |
| 752 | static void |
| 753 | focus_surface_destroy(struct focus_surface *fsurf) |
| 754 | { |
| 755 | weston_surface_destroy(fsurf->surface); |
| 756 | free(fsurf); |
| 757 | } |
| 758 | |
| 759 | static void |
| 760 | focus_animation_done(struct weston_view_animation *animation, void *data) |
| 761 | { |
| 762 | struct workspace *ws = data; |
| 763 | |
| 764 | ws->focus_animation = NULL; |
| 765 | } |
| 766 | |
Jonas Ådahl | e3cddce | 2012-06-13 00:01:22 +0200 | [diff] [blame] | 767 | static void |
Jonas Ådahl | 0476974 | 2012-06-13 00:01:24 +0200 | [diff] [blame] | 768 | focus_state_destroy(struct focus_state *state) |
| 769 | { |
| 770 | wl_list_remove(&state->seat_destroy_listener.link); |
| 771 | wl_list_remove(&state->surface_destroy_listener.link); |
| 772 | free(state); |
| 773 | } |
| 774 | |
| 775 | static void |
| 776 | focus_state_seat_destroy(struct wl_listener *listener, void *data) |
| 777 | { |
| 778 | struct focus_state *state = container_of(listener, |
| 779 | struct focus_state, |
| 780 | seat_destroy_listener); |
| 781 | |
| 782 | wl_list_remove(&state->link); |
| 783 | focus_state_destroy(state); |
| 784 | } |
| 785 | |
| 786 | static void |
| 787 | focus_state_surface_destroy(struct wl_listener *listener, void *data) |
| 788 | { |
| 789 | struct focus_state *state = container_of(listener, |
| 790 | struct focus_state, |
Kristian Høgsberg | b8e0d0f | 2012-07-31 10:30:26 -0400 | [diff] [blame] | 791 | surface_destroy_listener); |
Kristian Høgsberg | e377822 | 2012-07-31 17:29:30 -0400 | [diff] [blame] | 792 | struct desktop_shell *shell; |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 793 | struct weston_surface *main_surface, *next; |
| 794 | struct weston_view *view; |
Jonas Ådahl | 0476974 | 2012-06-13 00:01:24 +0200 | [diff] [blame] | 795 | |
Pekka Paalanen | 01388e2 | 2013-04-25 13:57:44 +0300 | [diff] [blame] | 796 | main_surface = weston_surface_get_main_surface(state->keyboard_focus); |
| 797 | |
Kristian Høgsberg | e377822 | 2012-07-31 17:29:30 -0400 | [diff] [blame] | 798 | next = NULL; |
Giulio Camuffo | 412e6a5 | 2014-07-09 22:12:56 +0300 | [diff] [blame] | 799 | wl_list_for_each(view, |
| 800 | &state->ws->layer.view_list.link, layer_link.link) { |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 801 | if (view->surface == main_surface) |
Kristian Høgsberg | e377822 | 2012-07-31 17:29:30 -0400 | [diff] [blame] | 802 | continue; |
Louis-Francis Ratté-Boulianne | b482dbd | 2013-11-19 11:37:11 +0100 | [diff] [blame] | 803 | if (is_focus_view(view)) |
| 804 | continue; |
Kristian Høgsberg | e377822 | 2012-07-31 17:29:30 -0400 | [diff] [blame] | 805 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 806 | next = view->surface; |
Kristian Høgsberg | e377822 | 2012-07-31 17:29:30 -0400 | [diff] [blame] | 807 | break; |
| 808 | } |
| 809 | |
Pekka Paalanen | 01388e2 | 2013-04-25 13:57:44 +0300 | [diff] [blame] | 810 | /* if the focus was a sub-surface, activate its main surface */ |
| 811 | if (main_surface != state->keyboard_focus) |
| 812 | next = main_surface; |
| 813 | |
Louis-Francis Ratté-Boulianne | b482dbd | 2013-11-19 11:37:11 +0100 | [diff] [blame] | 814 | shell = state->seat->compositor->shell_interface.shell; |
Kristian Høgsberg | e377822 | 2012-07-31 17:29:30 -0400 | [diff] [blame] | 815 | if (next) { |
Louis-Francis Ratté-Boulianne | b482dbd | 2013-11-19 11:37:11 +0100 | [diff] [blame] | 816 | state->keyboard_focus = NULL; |
Emilio Pozuelo Monfort | 9e7c759 | 2014-01-30 14:01:10 +0100 | [diff] [blame] | 817 | activate(shell, next, state->seat, true); |
Kristian Høgsberg | e377822 | 2012-07-31 17:29:30 -0400 | [diff] [blame] | 818 | } else { |
Louis-Francis Ratté-Boulianne | b482dbd | 2013-11-19 11:37:11 +0100 | [diff] [blame] | 819 | if (shell->focus_animation_type == ANIMATION_DIM_LAYER) { |
| 820 | if (state->ws->focus_animation) |
| 821 | weston_view_animation_destroy(state->ws->focus_animation); |
| 822 | |
| 823 | state->ws->focus_animation = weston_fade_run( |
| 824 | state->ws->fsurf_front->view, |
| 825 | state->ws->fsurf_front->view->alpha, 0.0, 300, |
| 826 | focus_animation_done, state->ws); |
| 827 | } |
| 828 | |
Kristian Høgsberg | e377822 | 2012-07-31 17:29:30 -0400 | [diff] [blame] | 829 | wl_list_remove(&state->link); |
| 830 | focus_state_destroy(state); |
| 831 | } |
Jonas Ådahl | 0476974 | 2012-06-13 00:01:24 +0200 | [diff] [blame] | 832 | } |
| 833 | |
| 834 | static struct focus_state * |
Kristian Høgsberg | 2f5faff | 2012-07-31 16:36:34 -0400 | [diff] [blame] | 835 | focus_state_create(struct weston_seat *seat, struct workspace *ws) |
Jonas Ådahl | 0476974 | 2012-06-13 00:01:24 +0200 | [diff] [blame] | 836 | { |
Jonas Ådahl | 0476974 | 2012-06-13 00:01:24 +0200 | [diff] [blame] | 837 | struct focus_state *state; |
Jonas Ådahl | 0476974 | 2012-06-13 00:01:24 +0200 | [diff] [blame] | 838 | |
| 839 | state = malloc(sizeof *state); |
| 840 | if (state == NULL) |
| 841 | return NULL; |
| 842 | |
Louis-Francis Ratté-Boulianne | b482dbd | 2013-11-19 11:37:11 +0100 | [diff] [blame] | 843 | state->keyboard_focus = NULL; |
Kristian Høgsberg | 2f5faff | 2012-07-31 16:36:34 -0400 | [diff] [blame] | 844 | state->ws = ws; |
Jonas Ådahl | 0476974 | 2012-06-13 00:01:24 +0200 | [diff] [blame] | 845 | state->seat = seat; |
Kristian Høgsberg | 2f5faff | 2012-07-31 16:36:34 -0400 | [diff] [blame] | 846 | wl_list_insert(&ws->focus_list, &state->link); |
Jonas Ådahl | 0476974 | 2012-06-13 00:01:24 +0200 | [diff] [blame] | 847 | |
| 848 | state->seat_destroy_listener.notify = focus_state_seat_destroy; |
| 849 | state->surface_destroy_listener.notify = focus_state_surface_destroy; |
Kristian Høgsberg | 4912454 | 2013-05-06 22:27:40 -0400 | [diff] [blame] | 850 | wl_signal_add(&seat->destroy_signal, |
Jonas Ådahl | 0476974 | 2012-06-13 00:01:24 +0200 | [diff] [blame] | 851 | &state->seat_destroy_listener); |
Kristian Høgsberg | 2f5faff | 2012-07-31 16:36:34 -0400 | [diff] [blame] | 852 | wl_list_init(&state->surface_destroy_listener.link); |
Jonas Ådahl | 0476974 | 2012-06-13 00:01:24 +0200 | [diff] [blame] | 853 | |
| 854 | return state; |
| 855 | } |
| 856 | |
Jonas Ådahl | 8538b22 | 2012-08-29 22:13:03 +0200 | [diff] [blame] | 857 | static struct focus_state * |
| 858 | ensure_focus_state(struct desktop_shell *shell, struct weston_seat *seat) |
| 859 | { |
| 860 | struct workspace *ws = get_current_workspace(shell); |
| 861 | struct focus_state *state; |
| 862 | |
| 863 | wl_list_for_each(state, &ws->focus_list, link) |
| 864 | if (state->seat == seat) |
| 865 | break; |
| 866 | |
| 867 | if (&state->link == &ws->focus_list) |
| 868 | state = focus_state_create(seat, ws); |
| 869 | |
| 870 | return state; |
| 871 | } |
| 872 | |
Jonas Ådahl | 0476974 | 2012-06-13 00:01:24 +0200 | [diff] [blame] | 873 | static void |
Kristian Høgsberg | d500bf1 | 2014-01-22 12:25:20 -0800 | [diff] [blame] | 874 | focus_state_set_focus(struct focus_state *state, |
| 875 | struct weston_surface *surface) |
| 876 | { |
| 877 | if (state->keyboard_focus) { |
| 878 | wl_list_remove(&state->surface_destroy_listener.link); |
| 879 | wl_list_init(&state->surface_destroy_listener.link); |
| 880 | } |
| 881 | |
| 882 | state->keyboard_focus = surface; |
| 883 | if (surface) |
| 884 | wl_signal_add(&surface->destroy_signal, |
| 885 | &state->surface_destroy_listener); |
| 886 | } |
| 887 | |
| 888 | static void |
Kristian Høgsberg | 2f5faff | 2012-07-31 16:36:34 -0400 | [diff] [blame] | 889 | restore_focus_state(struct desktop_shell *shell, struct workspace *ws) |
Jonas Ådahl | 0476974 | 2012-06-13 00:01:24 +0200 | [diff] [blame] | 890 | { |
| 891 | struct focus_state *state, *next; |
Kristian Høgsberg | fe7aa90 | 2013-05-08 09:54:37 -0400 | [diff] [blame] | 892 | struct weston_surface *surface; |
Neil Roberts | 4237f50 | 2014-04-09 16:33:31 +0100 | [diff] [blame] | 893 | struct wl_list pending_seat_list; |
| 894 | struct weston_seat *seat, *next_seat; |
| 895 | |
| 896 | /* Temporarily steal the list of seats so that we can keep |
| 897 | * track of the seats we've already processed */ |
| 898 | wl_list_init(&pending_seat_list); |
| 899 | wl_list_insert_list(&pending_seat_list, &shell->compositor->seat_list); |
| 900 | wl_list_init(&shell->compositor->seat_list); |
Jonas Ådahl | 0476974 | 2012-06-13 00:01:24 +0200 | [diff] [blame] | 901 | |
| 902 | wl_list_for_each_safe(state, next, &ws->focus_list, link) { |
Neil Roberts | 4237f50 | 2014-04-09 16:33:31 +0100 | [diff] [blame] | 903 | wl_list_remove(&state->seat->link); |
| 904 | wl_list_insert(&shell->compositor->seat_list, |
| 905 | &state->seat->link); |
| 906 | |
Kristian Høgsberg | e61d2f4 | 2014-01-17 12:18:53 -0800 | [diff] [blame] | 907 | if (state->seat->keyboard == NULL) |
| 908 | continue; |
| 909 | |
Kristian Høgsberg | fe7aa90 | 2013-05-08 09:54:37 -0400 | [diff] [blame] | 910 | surface = state->keyboard_focus; |
Jonas Ådahl | 5689944 | 2012-08-29 22:12:59 +0200 | [diff] [blame] | 911 | |
Kristian Høgsberg | e314875 | 2013-05-06 23:19:49 -0400 | [diff] [blame] | 912 | weston_keyboard_set_focus(state->seat->keyboard, surface); |
Jonas Ådahl | 0476974 | 2012-06-13 00:01:24 +0200 | [diff] [blame] | 913 | } |
Neil Roberts | 4237f50 | 2014-04-09 16:33:31 +0100 | [diff] [blame] | 914 | |
| 915 | /* For any remaining seats that we don't have a focus state |
| 916 | * for we'll reset the keyboard focus to NULL */ |
| 917 | wl_list_for_each_safe(seat, next_seat, &pending_seat_list, link) { |
| 918 | wl_list_insert(&shell->compositor->seat_list, &seat->link); |
| 919 | |
Ander Conselvan de Oliveira | 6e56ab4 | 2014-05-07 11:57:28 +0300 | [diff] [blame] | 920 | if (seat->keyboard == NULL) |
Neil Roberts | 4237f50 | 2014-04-09 16:33:31 +0100 | [diff] [blame] | 921 | continue; |
| 922 | |
| 923 | weston_keyboard_set_focus(seat->keyboard, NULL); |
| 924 | } |
Jonas Ådahl | 0476974 | 2012-06-13 00:01:24 +0200 | [diff] [blame] | 925 | } |
| 926 | |
| 927 | static void |
Jonas Ådahl | 8de6a1d | 2012-08-29 22:13:00 +0200 | [diff] [blame] | 928 | replace_focus_state(struct desktop_shell *shell, struct workspace *ws, |
| 929 | struct weston_seat *seat) |
| 930 | { |
| 931 | struct focus_state *state; |
Jonas Ådahl | 8de6a1d | 2012-08-29 22:13:00 +0200 | [diff] [blame] | 932 | |
| 933 | wl_list_for_each(state, &ws->focus_list, link) { |
| 934 | if (state->seat == seat) { |
Kristian Høgsberg | d500bf1 | 2014-01-22 12:25:20 -0800 | [diff] [blame] | 935 | focus_state_set_focus(state, seat->keyboard->focus); |
Jonas Ådahl | 8de6a1d | 2012-08-29 22:13:00 +0200 | [diff] [blame] | 936 | return; |
| 937 | } |
| 938 | } |
| 939 | } |
| 940 | |
| 941 | static void |
| 942 | drop_focus_state(struct desktop_shell *shell, struct workspace *ws, |
| 943 | struct weston_surface *surface) |
| 944 | { |
| 945 | struct focus_state *state; |
| 946 | |
| 947 | wl_list_for_each(state, &ws->focus_list, link) |
| 948 | if (state->keyboard_focus == surface) |
Kristian Høgsberg | d500bf1 | 2014-01-22 12:25:20 -0800 | [diff] [blame] | 949 | focus_state_set_focus(state, NULL); |
Jonas Ådahl | 8de6a1d | 2012-08-29 22:13:00 +0200 | [diff] [blame] | 950 | } |
| 951 | |
| 952 | static void |
Louis-Francis Ratté-Boulianne | b482dbd | 2013-11-19 11:37:11 +0100 | [diff] [blame] | 953 | animate_focus_change(struct desktop_shell *shell, struct workspace *ws, |
| 954 | struct weston_view *from, struct weston_view *to) |
| 955 | { |
| 956 | struct weston_output *output; |
| 957 | bool focus_surface_created = false; |
| 958 | |
| 959 | /* FIXME: Only support dim animation using two layers */ |
| 960 | if (from == to || shell->focus_animation_type != ANIMATION_DIM_LAYER) |
| 961 | return; |
| 962 | |
| 963 | output = get_default_output(shell->compositor); |
| 964 | if (ws->fsurf_front == NULL && (from || to)) { |
| 965 | ws->fsurf_front = create_focus_surface(shell->compositor, output); |
U. Artie Eoff | 0b23b2b | 2014-01-15 14:45:59 -0800 | [diff] [blame] | 966 | if (ws->fsurf_front == NULL) |
| 967 | return; |
Louis-Francis Ratté-Boulianne | b482dbd | 2013-11-19 11:37:11 +0100 | [diff] [blame] | 968 | ws->fsurf_front->view->alpha = 0.0; |
U. Artie Eoff | 0b23b2b | 2014-01-15 14:45:59 -0800 | [diff] [blame] | 969 | |
| 970 | ws->fsurf_back = create_focus_surface(shell->compositor, output); |
| 971 | if (ws->fsurf_back == NULL) { |
| 972 | focus_surface_destroy(ws->fsurf_front); |
| 973 | return; |
| 974 | } |
Louis-Francis Ratté-Boulianne | b482dbd | 2013-11-19 11:37:11 +0100 | [diff] [blame] | 975 | ws->fsurf_back->view->alpha = 0.0; |
U. Artie Eoff | 0b23b2b | 2014-01-15 14:45:59 -0800 | [diff] [blame] | 976 | |
Louis-Francis Ratté-Boulianne | b482dbd | 2013-11-19 11:37:11 +0100 | [diff] [blame] | 977 | focus_surface_created = true; |
| 978 | } else { |
Giulio Camuffo | 412e6a5 | 2014-07-09 22:12:56 +0300 | [diff] [blame] | 979 | weston_layer_entry_remove(&ws->fsurf_front->view->layer_link); |
| 980 | weston_layer_entry_remove(&ws->fsurf_back->view->layer_link); |
Louis-Francis Ratté-Boulianne | b482dbd | 2013-11-19 11:37:11 +0100 | [diff] [blame] | 981 | } |
| 982 | |
| 983 | if (ws->focus_animation) { |
| 984 | weston_view_animation_destroy(ws->focus_animation); |
| 985 | ws->focus_animation = NULL; |
| 986 | } |
| 987 | |
| 988 | if (to) |
Giulio Camuffo | 412e6a5 | 2014-07-09 22:12:56 +0300 | [diff] [blame] | 989 | weston_layer_entry_insert(&to->layer_link, |
| 990 | &ws->fsurf_front->view->layer_link); |
Louis-Francis Ratté-Boulianne | b482dbd | 2013-11-19 11:37:11 +0100 | [diff] [blame] | 991 | else if (from) |
Giulio Camuffo | 412e6a5 | 2014-07-09 22:12:56 +0300 | [diff] [blame] | 992 | weston_layer_entry_insert(&ws->layer.view_list, |
| 993 | &ws->fsurf_front->view->layer_link); |
Louis-Francis Ratté-Boulianne | b482dbd | 2013-11-19 11:37:11 +0100 | [diff] [blame] | 994 | |
| 995 | if (focus_surface_created) { |
| 996 | ws->focus_animation = weston_fade_run( |
| 997 | ws->fsurf_front->view, |
Jonny Lamb | 7e7d485 | 2014-05-22 22:41:34 +0200 | [diff] [blame] | 998 | ws->fsurf_front->view->alpha, 0.4, 300, |
Louis-Francis Ratté-Boulianne | b482dbd | 2013-11-19 11:37:11 +0100 | [diff] [blame] | 999 | focus_animation_done, ws); |
| 1000 | } else if (from) { |
Giulio Camuffo | 412e6a5 | 2014-07-09 22:12:56 +0300 | [diff] [blame] | 1001 | weston_layer_entry_insert(&from->layer_link, |
| 1002 | &ws->fsurf_back->view->layer_link); |
Louis-Francis Ratté-Boulianne | b482dbd | 2013-11-19 11:37:11 +0100 | [diff] [blame] | 1003 | ws->focus_animation = weston_stable_fade_run( |
| 1004 | ws->fsurf_front->view, 0.0, |
Jonny Lamb | 7e7d485 | 2014-05-22 22:41:34 +0200 | [diff] [blame] | 1005 | ws->fsurf_back->view, 0.4, |
Louis-Francis Ratté-Boulianne | b482dbd | 2013-11-19 11:37:11 +0100 | [diff] [blame] | 1006 | focus_animation_done, ws); |
| 1007 | } else if (to) { |
Giulio Camuffo | 412e6a5 | 2014-07-09 22:12:56 +0300 | [diff] [blame] | 1008 | weston_layer_entry_insert(&ws->layer.view_list, |
| 1009 | &ws->fsurf_back->view->layer_link); |
Louis-Francis Ratté-Boulianne | b482dbd | 2013-11-19 11:37:11 +0100 | [diff] [blame] | 1010 | ws->focus_animation = weston_stable_fade_run( |
| 1011 | ws->fsurf_front->view, 0.0, |
Jonny Lamb | 7e7d485 | 2014-05-22 22:41:34 +0200 | [diff] [blame] | 1012 | ws->fsurf_back->view, 0.4, |
Louis-Francis Ratté-Boulianne | b482dbd | 2013-11-19 11:37:11 +0100 | [diff] [blame] | 1013 | focus_animation_done, ws); |
| 1014 | } |
| 1015 | } |
| 1016 | |
| 1017 | static void |
Jonas Ådahl | e3cddce | 2012-06-13 00:01:22 +0200 | [diff] [blame] | 1018 | workspace_destroy(struct workspace *ws) |
| 1019 | { |
Jonas Ådahl | 0476974 | 2012-06-13 00:01:24 +0200 | [diff] [blame] | 1020 | struct focus_state *state, *next; |
| 1021 | |
| 1022 | wl_list_for_each_safe(state, next, &ws->focus_list, link) |
| 1023 | focus_state_destroy(state); |
| 1024 | |
Louis-Francis Ratté-Boulianne | b482dbd | 2013-11-19 11:37:11 +0100 | [diff] [blame] | 1025 | if (ws->fsurf_front) |
| 1026 | focus_surface_destroy(ws->fsurf_front); |
| 1027 | if (ws->fsurf_back) |
| 1028 | focus_surface_destroy(ws->fsurf_back); |
| 1029 | |
Jonas Ådahl | e3cddce | 2012-06-13 00:01:22 +0200 | [diff] [blame] | 1030 | free(ws); |
| 1031 | } |
| 1032 | |
Jonas Ådahl | 0476974 | 2012-06-13 00:01:24 +0200 | [diff] [blame] | 1033 | static void |
| 1034 | seat_destroyed(struct wl_listener *listener, void *data) |
| 1035 | { |
| 1036 | struct weston_seat *seat = data; |
| 1037 | struct focus_state *state, *next; |
| 1038 | struct workspace *ws = container_of(listener, |
| 1039 | struct workspace, |
| 1040 | seat_destroyed_listener); |
| 1041 | |
| 1042 | wl_list_for_each_safe(state, next, &ws->focus_list, link) |
| 1043 | if (state->seat == seat) |
| 1044 | wl_list_remove(&state->link); |
| 1045 | } |
| 1046 | |
Jonas Ådahl | e3cddce | 2012-06-13 00:01:22 +0200 | [diff] [blame] | 1047 | static struct workspace * |
| 1048 | workspace_create(void) |
| 1049 | { |
| 1050 | struct workspace *ws = malloc(sizeof *ws); |
| 1051 | if (ws == NULL) |
| 1052 | return NULL; |
| 1053 | |
| 1054 | weston_layer_init(&ws->layer, NULL); |
| 1055 | |
Jonas Ådahl | 0476974 | 2012-06-13 00:01:24 +0200 | [diff] [blame] | 1056 | wl_list_init(&ws->focus_list); |
| 1057 | wl_list_init(&ws->seat_destroyed_listener.link); |
| 1058 | ws->seat_destroyed_listener.notify = seat_destroyed; |
Louis-Francis Ratté-Boulianne | b482dbd | 2013-11-19 11:37:11 +0100 | [diff] [blame] | 1059 | ws->fsurf_front = NULL; |
| 1060 | ws->fsurf_back = NULL; |
| 1061 | ws->focus_animation = NULL; |
Jonas Ådahl | 0476974 | 2012-06-13 00:01:24 +0200 | [diff] [blame] | 1062 | |
Jonas Ådahl | e3cddce | 2012-06-13 00:01:22 +0200 | [diff] [blame] | 1063 | return ws; |
| 1064 | } |
| 1065 | |
Jonas Ådahl | 62fcd04 | 2012-06-13 00:01:23 +0200 | [diff] [blame] | 1066 | static int |
| 1067 | workspace_is_empty(struct workspace *ws) |
| 1068 | { |
Giulio Camuffo | 412e6a5 | 2014-07-09 22:12:56 +0300 | [diff] [blame] | 1069 | return wl_list_empty(&ws->layer.view_list.link); |
Jonas Ådahl | 62fcd04 | 2012-06-13 00:01:23 +0200 | [diff] [blame] | 1070 | } |
| 1071 | |
Jonas Ådahl | e3cddce | 2012-06-13 00:01:22 +0200 | [diff] [blame] | 1072 | static struct workspace * |
| 1073 | get_workspace(struct desktop_shell *shell, unsigned int index) |
| 1074 | { |
| 1075 | struct workspace **pws = shell->workspaces.array.data; |
Philipp Brüschweiler | 067abf6 | 2012-09-01 16:03:05 +0200 | [diff] [blame] | 1076 | assert(index < shell->workspaces.num); |
Jonas Ådahl | e3cddce | 2012-06-13 00:01:22 +0200 | [diff] [blame] | 1077 | pws += index; |
| 1078 | return *pws; |
| 1079 | } |
| 1080 | |
Kristian Høgsberg | 1ef2313 | 2013-12-04 00:20:01 -0800 | [diff] [blame] | 1081 | struct workspace * |
Jonas Ådahl | e3cddce | 2012-06-13 00:01:22 +0200 | [diff] [blame] | 1082 | get_current_workspace(struct desktop_shell *shell) |
| 1083 | { |
| 1084 | return get_workspace(shell, shell->workspaces.current); |
| 1085 | } |
| 1086 | |
| 1087 | static void |
| 1088 | activate_workspace(struct desktop_shell *shell, unsigned int index) |
| 1089 | { |
| 1090 | struct workspace *ws; |
| 1091 | |
| 1092 | ws = get_workspace(shell, index); |
| 1093 | wl_list_insert(&shell->panel_layer.link, &ws->layer.link); |
| 1094 | |
| 1095 | shell->workspaces.current = index; |
| 1096 | } |
| 1097 | |
Jonas Ådahl | 62fcd04 | 2012-06-13 00:01:23 +0200 | [diff] [blame] | 1098 | static unsigned int |
| 1099 | get_output_height(struct weston_output *output) |
| 1100 | { |
| 1101 | return abs(output->region.extents.y1 - output->region.extents.y2); |
| 1102 | } |
| 1103 | |
| 1104 | static void |
Louis-Francis Ratté-Boulianne | b482dbd | 2013-11-19 11:37:11 +0100 | [diff] [blame] | 1105 | view_translate(struct workspace *ws, struct weston_view *view, double d) |
Jonas Ådahl | 62fcd04 | 2012-06-13 00:01:23 +0200 | [diff] [blame] | 1106 | { |
Jonas Ådahl | 62fcd04 | 2012-06-13 00:01:23 +0200 | [diff] [blame] | 1107 | struct weston_transform *transform; |
| 1108 | |
Louis-Francis Ratté-Boulianne | b482dbd | 2013-11-19 11:37:11 +0100 | [diff] [blame] | 1109 | if (is_focus_view(view)) { |
| 1110 | struct focus_surface *fsurf = get_focus_surface(view->surface); |
| 1111 | transform = &fsurf->workspace_transform; |
| 1112 | } else { |
| 1113 | struct shell_surface *shsurf = get_shell_surface(view->surface); |
| 1114 | transform = &shsurf->workspace_transform; |
| 1115 | } |
| 1116 | |
Jonas Ådahl | 62fcd04 | 2012-06-13 00:01:23 +0200 | [diff] [blame] | 1117 | if (wl_list_empty(&transform->link)) |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 1118 | wl_list_insert(view->geometry.transformation_list.prev, |
Louis-Francis Ratté-Boulianne | b482dbd | 2013-11-19 11:37:11 +0100 | [diff] [blame] | 1119 | &transform->link); |
Jonas Ådahl | 62fcd04 | 2012-06-13 00:01:23 +0200 | [diff] [blame] | 1120 | |
Louis-Francis Ratté-Boulianne | b482dbd | 2013-11-19 11:37:11 +0100 | [diff] [blame] | 1121 | weston_matrix_init(&transform->matrix); |
| 1122 | weston_matrix_translate(&transform->matrix, |
Jonas Ådahl | 62fcd04 | 2012-06-13 00:01:23 +0200 | [diff] [blame] | 1123 | 0.0, d, 0.0); |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 1124 | weston_view_geometry_dirty(view); |
Jonas Ådahl | 62fcd04 | 2012-06-13 00:01:23 +0200 | [diff] [blame] | 1125 | } |
| 1126 | |
| 1127 | static void |
| 1128 | workspace_translate_out(struct workspace *ws, double fraction) |
| 1129 | { |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 1130 | struct weston_view *view; |
Jonas Ådahl | 62fcd04 | 2012-06-13 00:01:23 +0200 | [diff] [blame] | 1131 | unsigned int height; |
| 1132 | double d; |
| 1133 | |
Giulio Camuffo | 412e6a5 | 2014-07-09 22:12:56 +0300 | [diff] [blame] | 1134 | 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] | 1135 | height = get_output_height(view->surface->output); |
Jonas Ådahl | 62fcd04 | 2012-06-13 00:01:23 +0200 | [diff] [blame] | 1136 | d = height * fraction; |
| 1137 | |
Louis-Francis Ratté-Boulianne | b482dbd | 2013-11-19 11:37:11 +0100 | [diff] [blame] | 1138 | view_translate(ws, view, d); |
Jonas Ådahl | 62fcd04 | 2012-06-13 00:01:23 +0200 | [diff] [blame] | 1139 | } |
| 1140 | } |
| 1141 | |
| 1142 | static void |
| 1143 | workspace_translate_in(struct workspace *ws, double fraction) |
| 1144 | { |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 1145 | struct weston_view *view; |
Jonas Ådahl | 62fcd04 | 2012-06-13 00:01:23 +0200 | [diff] [blame] | 1146 | unsigned int height; |
| 1147 | double d; |
| 1148 | |
Giulio Camuffo | 412e6a5 | 2014-07-09 22:12:56 +0300 | [diff] [blame] | 1149 | 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] | 1150 | height = get_output_height(view->surface->output); |
Jonas Ådahl | 62fcd04 | 2012-06-13 00:01:23 +0200 | [diff] [blame] | 1151 | |
| 1152 | if (fraction > 0) |
| 1153 | d = -(height - height * fraction); |
| 1154 | else |
| 1155 | d = height + height * fraction; |
| 1156 | |
Louis-Francis Ratté-Boulianne | b482dbd | 2013-11-19 11:37:11 +0100 | [diff] [blame] | 1157 | view_translate(ws, view, d); |
Jonas Ådahl | 62fcd04 | 2012-06-13 00:01:23 +0200 | [diff] [blame] | 1158 | } |
| 1159 | } |
| 1160 | |
| 1161 | static void |
Jonas Ådahl | e9d2250 | 2012-08-29 22:13:01 +0200 | [diff] [blame] | 1162 | broadcast_current_workspace_state(struct desktop_shell *shell) |
| 1163 | { |
Kristian Høgsberg | 2e3c396 | 2013-09-11 12:00:47 -0700 | [diff] [blame] | 1164 | struct wl_resource *resource; |
Jonas Ådahl | e9d2250 | 2012-08-29 22:13:01 +0200 | [diff] [blame] | 1165 | |
Kristian Høgsberg | 2e3c396 | 2013-09-11 12:00:47 -0700 | [diff] [blame] | 1166 | wl_resource_for_each(resource, &shell->workspaces.client_list) |
| 1167 | workspace_manager_send_state(resource, |
Jonas Ådahl | e9d2250 | 2012-08-29 22:13:01 +0200 | [diff] [blame] | 1168 | shell->workspaces.current, |
| 1169 | shell->workspaces.num); |
| 1170 | } |
| 1171 | |
| 1172 | static void |
Jonas Ådahl | 62fcd04 | 2012-06-13 00:01:23 +0200 | [diff] [blame] | 1173 | reverse_workspace_change_animation(struct desktop_shell *shell, |
| 1174 | unsigned int index, |
| 1175 | struct workspace *from, |
| 1176 | struct workspace *to) |
| 1177 | { |
| 1178 | shell->workspaces.current = index; |
| 1179 | |
| 1180 | shell->workspaces.anim_to = to; |
| 1181 | shell->workspaces.anim_from = from; |
| 1182 | shell->workspaces.anim_dir = -1 * shell->workspaces.anim_dir; |
| 1183 | shell->workspaces.anim_timestamp = 0; |
| 1184 | |
Scott Moreau | 4272e63 | 2012-08-13 09:58:41 -0600 | [diff] [blame] | 1185 | weston_compositor_schedule_repaint(shell->compositor); |
Jonas Ådahl | 62fcd04 | 2012-06-13 00:01:23 +0200 | [diff] [blame] | 1186 | } |
| 1187 | |
| 1188 | static void |
| 1189 | workspace_deactivate_transforms(struct workspace *ws) |
| 1190 | { |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 1191 | struct weston_view *view; |
Louis-Francis Ratté-Boulianne | b482dbd | 2013-11-19 11:37:11 +0100 | [diff] [blame] | 1192 | struct weston_transform *transform; |
Jonas Ådahl | 62fcd04 | 2012-06-13 00:01:23 +0200 | [diff] [blame] | 1193 | |
Giulio Camuffo | 412e6a5 | 2014-07-09 22:12:56 +0300 | [diff] [blame] | 1194 | 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] | 1195 | if (is_focus_view(view)) { |
| 1196 | struct focus_surface *fsurf = get_focus_surface(view->surface); |
| 1197 | transform = &fsurf->workspace_transform; |
| 1198 | } else { |
| 1199 | struct shell_surface *shsurf = get_shell_surface(view->surface); |
| 1200 | transform = &shsurf->workspace_transform; |
| 1201 | } |
| 1202 | |
| 1203 | if (!wl_list_empty(&transform->link)) { |
| 1204 | wl_list_remove(&transform->link); |
| 1205 | wl_list_init(&transform->link); |
Jonas Ådahl | 8de6a1d | 2012-08-29 22:13:00 +0200 | [diff] [blame] | 1206 | } |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 1207 | weston_view_geometry_dirty(view); |
Jonas Ådahl | 62fcd04 | 2012-06-13 00:01:23 +0200 | [diff] [blame] | 1208 | } |
| 1209 | } |
| 1210 | |
| 1211 | static void |
| 1212 | finish_workspace_change_animation(struct desktop_shell *shell, |
| 1213 | struct workspace *from, |
| 1214 | struct workspace *to) |
| 1215 | { |
Ander Conselvan de Oliveira | 9c6217e | 2014-05-07 11:57:26 +0300 | [diff] [blame] | 1216 | struct weston_view *view; |
| 1217 | |
Scott Moreau | 4272e63 | 2012-08-13 09:58:41 -0600 | [diff] [blame] | 1218 | weston_compositor_schedule_repaint(shell->compositor); |
Jonas Ådahl | 62fcd04 | 2012-06-13 00:01:23 +0200 | [diff] [blame] | 1219 | |
Ander Conselvan de Oliveira | 9c6217e | 2014-05-07 11:57:26 +0300 | [diff] [blame] | 1220 | /* Views that extend past the bottom of the output are still |
| 1221 | * visible after the workspace animation ends but before its layer |
| 1222 | * is hidden. In that case, we need to damage below those views so |
| 1223 | * that the screen is properly repainted. */ |
Giulio Camuffo | 412e6a5 | 2014-07-09 22:12:56 +0300 | [diff] [blame] | 1224 | 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] | 1225 | weston_view_damage_below(view); |
| 1226 | |
Jonas Ådahl | 62fcd04 | 2012-06-13 00:01:23 +0200 | [diff] [blame] | 1227 | wl_list_remove(&shell->workspaces.animation.link); |
| 1228 | workspace_deactivate_transforms(from); |
| 1229 | workspace_deactivate_transforms(to); |
| 1230 | shell->workspaces.anim_to = NULL; |
| 1231 | |
| 1232 | wl_list_remove(&shell->workspaces.anim_from->layer.link); |
| 1233 | } |
| 1234 | |
| 1235 | static void |
| 1236 | animate_workspace_change_frame(struct weston_animation *animation, |
| 1237 | struct weston_output *output, uint32_t msecs) |
| 1238 | { |
| 1239 | struct desktop_shell *shell = |
| 1240 | container_of(animation, struct desktop_shell, |
| 1241 | workspaces.animation); |
| 1242 | struct workspace *from = shell->workspaces.anim_from; |
| 1243 | struct workspace *to = shell->workspaces.anim_to; |
| 1244 | uint32_t t; |
| 1245 | double x, y; |
| 1246 | |
| 1247 | if (workspace_is_empty(from) && workspace_is_empty(to)) { |
| 1248 | finish_workspace_change_animation(shell, from, to); |
| 1249 | return; |
| 1250 | } |
| 1251 | |
| 1252 | if (shell->workspaces.anim_timestamp == 0) { |
| 1253 | if (shell->workspaces.anim_current == 0.0) |
| 1254 | shell->workspaces.anim_timestamp = msecs; |
| 1255 | else |
| 1256 | shell->workspaces.anim_timestamp = |
| 1257 | msecs - |
| 1258 | /* Invers of movement function 'y' below. */ |
| 1259 | (asin(1.0 - shell->workspaces.anim_current) * |
| 1260 | DEFAULT_WORKSPACE_CHANGE_ANIMATION_LENGTH * |
| 1261 | M_2_PI); |
| 1262 | } |
| 1263 | |
| 1264 | t = msecs - shell->workspaces.anim_timestamp; |
| 1265 | |
| 1266 | /* |
| 1267 | * x = [0, π/2] |
| 1268 | * y(x) = sin(x) |
| 1269 | */ |
| 1270 | x = t * (1.0/DEFAULT_WORKSPACE_CHANGE_ANIMATION_LENGTH) * M_PI_2; |
| 1271 | y = sin(x); |
| 1272 | |
| 1273 | if (t < DEFAULT_WORKSPACE_CHANGE_ANIMATION_LENGTH) { |
Scott Moreau | 4272e63 | 2012-08-13 09:58:41 -0600 | [diff] [blame] | 1274 | weston_compositor_schedule_repaint(shell->compositor); |
Jonas Ådahl | 62fcd04 | 2012-06-13 00:01:23 +0200 | [diff] [blame] | 1275 | |
| 1276 | workspace_translate_out(from, shell->workspaces.anim_dir * y); |
| 1277 | workspace_translate_in(to, shell->workspaces.anim_dir * y); |
| 1278 | shell->workspaces.anim_current = y; |
| 1279 | |
Scott Moreau | 4272e63 | 2012-08-13 09:58:41 -0600 | [diff] [blame] | 1280 | weston_compositor_schedule_repaint(shell->compositor); |
Jonas Ådahl | 62fcd04 | 2012-06-13 00:01:23 +0200 | [diff] [blame] | 1281 | } |
Jonas Ådahl | 0476974 | 2012-06-13 00:01:24 +0200 | [diff] [blame] | 1282 | else |
Jonas Ådahl | 62fcd04 | 2012-06-13 00:01:23 +0200 | [diff] [blame] | 1283 | finish_workspace_change_animation(shell, from, to); |
Jonas Ådahl | 62fcd04 | 2012-06-13 00:01:23 +0200 | [diff] [blame] | 1284 | } |
| 1285 | |
| 1286 | static void |
| 1287 | animate_workspace_change(struct desktop_shell *shell, |
| 1288 | unsigned int index, |
| 1289 | struct workspace *from, |
| 1290 | struct workspace *to) |
| 1291 | { |
| 1292 | struct weston_output *output; |
| 1293 | |
| 1294 | int dir; |
| 1295 | |
| 1296 | if (index > shell->workspaces.current) |
| 1297 | dir = -1; |
| 1298 | else |
| 1299 | dir = 1; |
| 1300 | |
| 1301 | shell->workspaces.current = index; |
| 1302 | |
| 1303 | shell->workspaces.anim_dir = dir; |
| 1304 | shell->workspaces.anim_from = from; |
| 1305 | shell->workspaces.anim_to = to; |
| 1306 | shell->workspaces.anim_current = 0.0; |
| 1307 | shell->workspaces.anim_timestamp = 0; |
| 1308 | |
| 1309 | output = container_of(shell->compositor->output_list.next, |
| 1310 | struct weston_output, link); |
| 1311 | wl_list_insert(&output->animation_list, |
| 1312 | &shell->workspaces.animation.link); |
| 1313 | |
Jonas Ådahl | 8de6a1d | 2012-08-29 22:13:00 +0200 | [diff] [blame] | 1314 | wl_list_insert(from->layer.link.prev, &to->layer.link); |
Jonas Ådahl | 62fcd04 | 2012-06-13 00:01:23 +0200 | [diff] [blame] | 1315 | |
| 1316 | workspace_translate_in(to, 0); |
| 1317 | |
Kristian Høgsberg | 2f5faff | 2012-07-31 16:36:34 -0400 | [diff] [blame] | 1318 | restore_focus_state(shell, to); |
Jonas Ådahl | 0476974 | 2012-06-13 00:01:24 +0200 | [diff] [blame] | 1319 | |
Scott Moreau | 4272e63 | 2012-08-13 09:58:41 -0600 | [diff] [blame] | 1320 | weston_compositor_schedule_repaint(shell->compositor); |
Jonas Ådahl | 62fcd04 | 2012-06-13 00:01:23 +0200 | [diff] [blame] | 1321 | } |
| 1322 | |
Jonas Ådahl | e3cddce | 2012-06-13 00:01:22 +0200 | [diff] [blame] | 1323 | static void |
Jonas Ådahl | 8de6a1d | 2012-08-29 22:13:00 +0200 | [diff] [blame] | 1324 | update_workspace(struct desktop_shell *shell, unsigned int index, |
| 1325 | struct workspace *from, struct workspace *to) |
| 1326 | { |
| 1327 | shell->workspaces.current = index; |
| 1328 | wl_list_insert(&from->layer.link, &to->layer.link); |
| 1329 | wl_list_remove(&from->layer.link); |
| 1330 | } |
| 1331 | |
| 1332 | static void |
Jonas Ådahl | e3cddce | 2012-06-13 00:01:22 +0200 | [diff] [blame] | 1333 | change_workspace(struct desktop_shell *shell, unsigned int index) |
| 1334 | { |
| 1335 | struct workspace *from; |
| 1336 | struct workspace *to; |
Louis-Francis Ratté-Boulianne | b482dbd | 2013-11-19 11:37:11 +0100 | [diff] [blame] | 1337 | struct focus_state *state; |
Jonas Ådahl | e3cddce | 2012-06-13 00:01:22 +0200 | [diff] [blame] | 1338 | |
| 1339 | if (index == shell->workspaces.current) |
| 1340 | return; |
| 1341 | |
| 1342 | /* Don't change workspace when there is any fullscreen surfaces. */ |
Giulio Camuffo | 412e6a5 | 2014-07-09 22:12:56 +0300 | [diff] [blame] | 1343 | if (!wl_list_empty(&shell->fullscreen_layer.view_list.link)) |
Jonas Ådahl | e3cddce | 2012-06-13 00:01:22 +0200 | [diff] [blame] | 1344 | return; |
| 1345 | |
Jonas Ådahl | e3cddce | 2012-06-13 00:01:22 +0200 | [diff] [blame] | 1346 | from = get_current_workspace(shell); |
| 1347 | to = get_workspace(shell, index); |
| 1348 | |
Jonas Ådahl | 62fcd04 | 2012-06-13 00:01:23 +0200 | [diff] [blame] | 1349 | if (shell->workspaces.anim_from == to && |
| 1350 | shell->workspaces.anim_to == from) { |
Jonas Ådahl | 8de6a1d | 2012-08-29 22:13:00 +0200 | [diff] [blame] | 1351 | restore_focus_state(shell, to); |
Jonas Ådahl | 62fcd04 | 2012-06-13 00:01:23 +0200 | [diff] [blame] | 1352 | reverse_workspace_change_animation(shell, index, from, to); |
Jonas Ådahl | e9d2250 | 2012-08-29 22:13:01 +0200 | [diff] [blame] | 1353 | broadcast_current_workspace_state(shell); |
Jonas Ådahl | 62fcd04 | 2012-06-13 00:01:23 +0200 | [diff] [blame] | 1354 | return; |
| 1355 | } |
Jonas Ådahl | e3cddce | 2012-06-13 00:01:22 +0200 | [diff] [blame] | 1356 | |
Jonas Ådahl | 62fcd04 | 2012-06-13 00:01:23 +0200 | [diff] [blame] | 1357 | if (shell->workspaces.anim_to != NULL) |
| 1358 | finish_workspace_change_animation(shell, |
| 1359 | shell->workspaces.anim_from, |
| 1360 | shell->workspaces.anim_to); |
| 1361 | |
Jonas Ådahl | 8de6a1d | 2012-08-29 22:13:00 +0200 | [diff] [blame] | 1362 | restore_focus_state(shell, to); |
Jonas Ådahl | 0476974 | 2012-06-13 00:01:24 +0200 | [diff] [blame] | 1363 | |
Louis-Francis Ratté-Boulianne | b482dbd | 2013-11-19 11:37:11 +0100 | [diff] [blame] | 1364 | if (shell->focus_animation_type != ANIMATION_NONE) { |
| 1365 | wl_list_for_each(state, &from->focus_list, link) |
| 1366 | if (state->keyboard_focus) |
| 1367 | animate_focus_change(shell, from, |
| 1368 | get_default_view(state->keyboard_focus), NULL); |
| 1369 | |
| 1370 | wl_list_for_each(state, &to->focus_list, link) |
| 1371 | if (state->keyboard_focus) |
| 1372 | animate_focus_change(shell, to, |
| 1373 | NULL, get_default_view(state->keyboard_focus)); |
| 1374 | } |
| 1375 | |
Jonas Ådahl | 8de6a1d | 2012-08-29 22:13:00 +0200 | [diff] [blame] | 1376 | if (workspace_is_empty(to) && workspace_is_empty(from)) |
| 1377 | update_workspace(shell, index, from, to); |
Jonas Ådahl | 62fcd04 | 2012-06-13 00:01:23 +0200 | [diff] [blame] | 1378 | else |
| 1379 | animate_workspace_change(shell, index, from, to); |
Jonas Ådahl | e9d2250 | 2012-08-29 22:13:01 +0200 | [diff] [blame] | 1380 | |
| 1381 | broadcast_current_workspace_state(shell); |
Pekka Paalanen | e955f1e | 2011-12-07 11:49:52 +0200 | [diff] [blame] | 1382 | } |
| 1383 | |
Jonas Ådahl | 8de6a1d | 2012-08-29 22:13:00 +0200 | [diff] [blame] | 1384 | static bool |
| 1385 | workspace_has_only(struct workspace *ws, struct weston_surface *surface) |
| 1386 | { |
Giulio Camuffo | 412e6a5 | 2014-07-09 22:12:56 +0300 | [diff] [blame] | 1387 | struct wl_list *list = &ws->layer.view_list.link; |
Jonas Ådahl | 8de6a1d | 2012-08-29 22:13:00 +0200 | [diff] [blame] | 1388 | struct wl_list *e; |
| 1389 | |
| 1390 | if (wl_list_empty(list)) |
| 1391 | return false; |
| 1392 | |
| 1393 | e = list->next; |
| 1394 | |
| 1395 | if (e->next != list) |
| 1396 | return false; |
| 1397 | |
Giulio Camuffo | 412e6a5 | 2014-07-09 22:12:56 +0300 | [diff] [blame] | 1398 | return container_of(e, struct weston_view, layer_link.link)->surface == surface; |
Jonas Ådahl | 8de6a1d | 2012-08-29 22:13:00 +0200 | [diff] [blame] | 1399 | } |
| 1400 | |
| 1401 | static void |
Philip Withnall | 659163d | 2013-11-25 18:01:36 +0000 | [diff] [blame] | 1402 | move_surface_to_workspace(struct desktop_shell *shell, |
| 1403 | struct shell_surface *shsurf, |
| 1404 | uint32_t workspace) |
Jonas Ådahl | e9d2250 | 2012-08-29 22:13:01 +0200 | [diff] [blame] | 1405 | { |
| 1406 | struct workspace *from; |
| 1407 | struct workspace *to; |
| 1408 | struct weston_seat *seat; |
Pekka Paalanen | 01388e2 | 2013-04-25 13:57:44 +0300 | [diff] [blame] | 1409 | struct weston_surface *focus; |
Philip Withnall | 659163d | 2013-11-25 18:01:36 +0000 | [diff] [blame] | 1410 | struct weston_view *view; |
Jonas Ådahl | e9d2250 | 2012-08-29 22:13:01 +0200 | [diff] [blame] | 1411 | |
| 1412 | if (workspace == shell->workspaces.current) |
| 1413 | return; |
| 1414 | |
Philip Withnall | 659163d | 2013-11-25 18:01:36 +0000 | [diff] [blame] | 1415 | view = get_default_view(shsurf->surface); |
| 1416 | if (!view) |
| 1417 | return; |
| 1418 | |
| 1419 | assert(weston_surface_get_main_surface(view->surface) == view->surface); |
| 1420 | |
Philipp Brüschweiler | 067abf6 | 2012-09-01 16:03:05 +0200 | [diff] [blame] | 1421 | if (workspace >= shell->workspaces.num) |
| 1422 | workspace = shell->workspaces.num - 1; |
| 1423 | |
Jonas Ådahl | e9d2250 | 2012-08-29 22:13:01 +0200 | [diff] [blame] | 1424 | from = get_current_workspace(shell); |
| 1425 | to = get_workspace(shell, workspace); |
| 1426 | |
Giulio Camuffo | 412e6a5 | 2014-07-09 22:12:56 +0300 | [diff] [blame] | 1427 | weston_layer_entry_remove(&view->layer_link); |
| 1428 | weston_layer_entry_insert(&to->layer.view_list, &view->layer_link); |
Jonas Ådahl | e9d2250 | 2012-08-29 22:13:01 +0200 | [diff] [blame] | 1429 | |
Philip Withnall | 648a4dd | 2013-11-25 18:01:44 +0000 | [diff] [blame] | 1430 | shell_surface_update_child_surface_layers(shsurf); |
| 1431 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 1432 | drop_focus_state(shell, from, view->surface); |
Pekka Paalanen | 01388e2 | 2013-04-25 13:57:44 +0300 | [diff] [blame] | 1433 | wl_list_for_each(seat, &shell->compositor->seat_list, link) { |
| 1434 | if (!seat->keyboard) |
| 1435 | continue; |
| 1436 | |
| 1437 | focus = weston_surface_get_main_surface(seat->keyboard->focus); |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 1438 | if (focus == view->surface) |
Kristian Høgsberg | e314875 | 2013-05-06 23:19:49 -0400 | [diff] [blame] | 1439 | weston_keyboard_set_focus(seat->keyboard, NULL); |
Pekka Paalanen | 01388e2 | 2013-04-25 13:57:44 +0300 | [diff] [blame] | 1440 | } |
Jonas Ådahl | e9d2250 | 2012-08-29 22:13:01 +0200 | [diff] [blame] | 1441 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 1442 | weston_view_damage_below(view); |
Jonas Ådahl | e9d2250 | 2012-08-29 22:13:01 +0200 | [diff] [blame] | 1443 | } |
| 1444 | |
| 1445 | static void |
Jonas Ådahl | 8de6a1d | 2012-08-29 22:13:00 +0200 | [diff] [blame] | 1446 | take_surface_to_workspace_by_seat(struct desktop_shell *shell, |
Kristian Høgsberg | e314875 | 2013-05-06 23:19:49 -0400 | [diff] [blame] | 1447 | struct weston_seat *seat, |
Jonas Ådahl | 8de6a1d | 2012-08-29 22:13:00 +0200 | [diff] [blame] | 1448 | unsigned int index) |
| 1449 | { |
Pekka Paalanen | 01388e2 | 2013-04-25 13:57:44 +0300 | [diff] [blame] | 1450 | struct weston_surface *surface; |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 1451 | struct weston_view *view; |
Jonas Ådahl | 8de6a1d | 2012-08-29 22:13:00 +0200 | [diff] [blame] | 1452 | struct shell_surface *shsurf; |
| 1453 | struct workspace *from; |
| 1454 | struct workspace *to; |
Jonas Ådahl | 8538b22 | 2012-08-29 22:13:03 +0200 | [diff] [blame] | 1455 | struct focus_state *state; |
Jonas Ådahl | 8de6a1d | 2012-08-29 22:13:00 +0200 | [diff] [blame] | 1456 | |
Pekka Paalanen | 01388e2 | 2013-04-25 13:57:44 +0300 | [diff] [blame] | 1457 | surface = weston_surface_get_main_surface(seat->keyboard->focus); |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 1458 | view = get_default_view(surface); |
| 1459 | if (view == NULL || |
Louis-Francis Ratté-Boulianne | b482dbd | 2013-11-19 11:37:11 +0100 | [diff] [blame] | 1460 | index == shell->workspaces.current || |
| 1461 | is_focus_view(view)) |
Jonas Ådahl | 8de6a1d | 2012-08-29 22:13:00 +0200 | [diff] [blame] | 1462 | return; |
| 1463 | |
| 1464 | from = get_current_workspace(shell); |
| 1465 | to = get_workspace(shell, index); |
| 1466 | |
Giulio Camuffo | 412e6a5 | 2014-07-09 22:12:56 +0300 | [diff] [blame] | 1467 | weston_layer_entry_remove(&view->layer_link); |
| 1468 | weston_layer_entry_insert(&to->layer.view_list, &view->layer_link); |
Jonas Ådahl | 8de6a1d | 2012-08-29 22:13:00 +0200 | [diff] [blame] | 1469 | |
Philip Withnall | 659163d | 2013-11-25 18:01:36 +0000 | [diff] [blame] | 1470 | shsurf = get_shell_surface(surface); |
Philip Withnall | 648a4dd | 2013-11-25 18:01:44 +0000 | [diff] [blame] | 1471 | if (shsurf != NULL) |
| 1472 | shell_surface_update_child_surface_layers(shsurf); |
Philip Withnall | 659163d | 2013-11-25 18:01:36 +0000 | [diff] [blame] | 1473 | |
Jonas Ådahl | e9d2250 | 2012-08-29 22:13:01 +0200 | [diff] [blame] | 1474 | replace_focus_state(shell, to, seat); |
Jonas Ådahl | 8de6a1d | 2012-08-29 22:13:00 +0200 | [diff] [blame] | 1475 | drop_focus_state(shell, from, surface); |
| 1476 | |
| 1477 | if (shell->workspaces.anim_from == to && |
| 1478 | shell->workspaces.anim_to == from) { |
Jonas Ådahl | e9d2250 | 2012-08-29 22:13:01 +0200 | [diff] [blame] | 1479 | wl_list_remove(&to->layer.link); |
| 1480 | wl_list_insert(from->layer.link.prev, &to->layer.link); |
| 1481 | |
Jonas Ådahl | 8de6a1d | 2012-08-29 22:13:00 +0200 | [diff] [blame] | 1482 | reverse_workspace_change_animation(shell, index, from, to); |
Jonas Ådahl | e9d2250 | 2012-08-29 22:13:01 +0200 | [diff] [blame] | 1483 | broadcast_current_workspace_state(shell); |
| 1484 | |
Jonas Ådahl | 8de6a1d | 2012-08-29 22:13:00 +0200 | [diff] [blame] | 1485 | return; |
| 1486 | } |
| 1487 | |
| 1488 | if (shell->workspaces.anim_to != NULL) |
| 1489 | finish_workspace_change_animation(shell, |
| 1490 | shell->workspaces.anim_from, |
| 1491 | shell->workspaces.anim_to); |
| 1492 | |
| 1493 | if (workspace_is_empty(from) && |
| 1494 | workspace_has_only(to, surface)) |
| 1495 | update_workspace(shell, index, from, to); |
| 1496 | else { |
Philip Withnall | 2c3849b | 2013-11-25 18:01:45 +0000 | [diff] [blame] | 1497 | if (shsurf != NULL && |
| 1498 | wl_list_empty(&shsurf->workspace_transform.link)) |
Jonas Ådahl | 8de6a1d | 2012-08-29 22:13:00 +0200 | [diff] [blame] | 1499 | wl_list_insert(&shell->workspaces.anim_sticky_list, |
| 1500 | &shsurf->workspace_transform.link); |
| 1501 | |
| 1502 | animate_workspace_change(shell, index, from, to); |
| 1503 | } |
Jonas Ådahl | e9d2250 | 2012-08-29 22:13:01 +0200 | [diff] [blame] | 1504 | |
| 1505 | broadcast_current_workspace_state(shell); |
Jonas Ådahl | 8538b22 | 2012-08-29 22:13:03 +0200 | [diff] [blame] | 1506 | |
| 1507 | state = ensure_focus_state(shell, seat); |
| 1508 | if (state != NULL) |
Kristian Høgsberg | d500bf1 | 2014-01-22 12:25:20 -0800 | [diff] [blame] | 1509 | focus_state_set_focus(state, surface); |
Jonas Ådahl | e9d2250 | 2012-08-29 22:13:01 +0200 | [diff] [blame] | 1510 | } |
| 1511 | |
| 1512 | static void |
| 1513 | workspace_manager_move_surface(struct wl_client *client, |
| 1514 | struct wl_resource *resource, |
| 1515 | struct wl_resource *surface_resource, |
| 1516 | uint32_t workspace) |
| 1517 | { |
Jason Ekstrand | 651f00e | 2013-06-14 10:07:54 -0500 | [diff] [blame] | 1518 | struct desktop_shell *shell = wl_resource_get_user_data(resource); |
Jonas Ådahl | e9d2250 | 2012-08-29 22:13:01 +0200 | [diff] [blame] | 1519 | struct weston_surface *surface = |
Jason Ekstrand | 0f2ef7e | 2013-06-14 10:07:53 -0500 | [diff] [blame] | 1520 | wl_resource_get_user_data(surface_resource); |
Pekka Paalanen | 01388e2 | 2013-04-25 13:57:44 +0300 | [diff] [blame] | 1521 | struct weston_surface *main_surface; |
Philip Withnall | 659163d | 2013-11-25 18:01:36 +0000 | [diff] [blame] | 1522 | struct shell_surface *shell_surface; |
Jonas Ådahl | e9d2250 | 2012-08-29 22:13:01 +0200 | [diff] [blame] | 1523 | |
Pekka Paalanen | 01388e2 | 2013-04-25 13:57:44 +0300 | [diff] [blame] | 1524 | main_surface = weston_surface_get_main_surface(surface); |
Philip Withnall | 659163d | 2013-11-25 18:01:36 +0000 | [diff] [blame] | 1525 | shell_surface = get_shell_surface(main_surface); |
| 1526 | if (shell_surface == NULL) |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 1527 | return; |
Philip Withnall | 659163d | 2013-11-25 18:01:36 +0000 | [diff] [blame] | 1528 | |
| 1529 | move_surface_to_workspace(shell, shell_surface, workspace); |
Jonas Ådahl | e9d2250 | 2012-08-29 22:13:01 +0200 | [diff] [blame] | 1530 | } |
| 1531 | |
| 1532 | static const struct workspace_manager_interface workspace_manager_implementation = { |
| 1533 | workspace_manager_move_surface, |
| 1534 | }; |
| 1535 | |
| 1536 | static void |
| 1537 | unbind_resource(struct wl_resource *resource) |
| 1538 | { |
Jason Ekstrand | 651f00e | 2013-06-14 10:07:54 -0500 | [diff] [blame] | 1539 | wl_list_remove(wl_resource_get_link(resource)); |
Jonas Ådahl | e9d2250 | 2012-08-29 22:13:01 +0200 | [diff] [blame] | 1540 | } |
| 1541 | |
| 1542 | static void |
| 1543 | bind_workspace_manager(struct wl_client *client, |
| 1544 | void *data, uint32_t version, uint32_t id) |
| 1545 | { |
| 1546 | struct desktop_shell *shell = data; |
| 1547 | struct wl_resource *resource; |
| 1548 | |
Jason Ekstrand | a85118c | 2013-06-27 20:17:02 -0500 | [diff] [blame] | 1549 | resource = wl_resource_create(client, |
| 1550 | &workspace_manager_interface, 1, id); |
Jonas Ådahl | e9d2250 | 2012-08-29 22:13:01 +0200 | [diff] [blame] | 1551 | |
| 1552 | if (resource == NULL) { |
| 1553 | weston_log("couldn't add workspace manager object"); |
| 1554 | return; |
| 1555 | } |
| 1556 | |
Jason Ekstrand | a85118c | 2013-06-27 20:17:02 -0500 | [diff] [blame] | 1557 | wl_resource_set_implementation(resource, |
| 1558 | &workspace_manager_implementation, |
| 1559 | shell, unbind_resource); |
Jason Ekstrand | 651f00e | 2013-06-14 10:07:54 -0500 | [diff] [blame] | 1560 | wl_list_insert(&shell->workspaces.client_list, |
| 1561 | wl_resource_get_link(resource)); |
Jonas Ådahl | e9d2250 | 2012-08-29 22:13:01 +0200 | [diff] [blame] | 1562 | |
| 1563 | workspace_manager_send_state(resource, |
| 1564 | shell->workspaces.current, |
| 1565 | shell->workspaces.num); |
Jonas Ådahl | 8de6a1d | 2012-08-29 22:13:00 +0200 | [diff] [blame] | 1566 | } |
| 1567 | |
Pekka Paalanen | 56cdea9 | 2011-11-23 16:14:12 +0200 | [diff] [blame] | 1568 | static void |
Rusty Lynch | 1084da5 | 2013-08-15 09:10:08 -0700 | [diff] [blame] | 1569 | touch_move_grab_down(struct weston_touch_grab *grab, uint32_t time, |
| 1570 | int touch_id, wl_fixed_t sx, wl_fixed_t sy) |
| 1571 | { |
| 1572 | } |
| 1573 | |
| 1574 | static void |
| 1575 | touch_move_grab_up(struct weston_touch_grab *grab, uint32_t time, int touch_id) |
| 1576 | { |
Jonas Ådahl | 1c6e63e | 2013-10-25 23:18:04 +0200 | [diff] [blame] | 1577 | struct weston_touch_move_grab *move = |
| 1578 | (struct weston_touch_move_grab *) container_of( |
| 1579 | grab, struct shell_touch_grab, grab); |
Neil Roberts | e14aa4f | 2013-10-03 16:43:07 +0100 | [diff] [blame] | 1580 | |
Kristian Høgsberg | 8e80a31 | 2014-01-17 15:18:10 -0800 | [diff] [blame] | 1581 | if (touch_id == 0) |
| 1582 | move->active = 0; |
| 1583 | |
Jonas Ådahl | 9484b69 | 2013-12-02 22:05:03 +0100 | [diff] [blame] | 1584 | if (grab->touch->num_tp == 0) { |
Jonas Ådahl | 1c6e63e | 2013-10-25 23:18:04 +0200 | [diff] [blame] | 1585 | shell_touch_grab_end(&move->base); |
| 1586 | free(move); |
| 1587 | } |
Rusty Lynch | 1084da5 | 2013-08-15 09:10:08 -0700 | [diff] [blame] | 1588 | } |
| 1589 | |
| 1590 | static void |
| 1591 | touch_move_grab_motion(struct weston_touch_grab *grab, uint32_t time, |
| 1592 | int touch_id, wl_fixed_t sx, wl_fixed_t sy) |
| 1593 | { |
| 1594 | struct weston_touch_move_grab *move = (struct weston_touch_move_grab *) grab; |
| 1595 | struct shell_surface *shsurf = move->base.shsurf; |
| 1596 | struct weston_surface *es; |
| 1597 | int dx = wl_fixed_to_int(grab->touch->grab_x + move->dx); |
| 1598 | int dy = wl_fixed_to_int(grab->touch->grab_y + move->dy); |
| 1599 | |
Kristian Høgsberg | 8e80a31 | 2014-01-17 15:18:10 -0800 | [diff] [blame] | 1600 | if (!shsurf || !move->active) |
Rusty Lynch | 1084da5 | 2013-08-15 09:10:08 -0700 | [diff] [blame] | 1601 | return; |
| 1602 | |
| 1603 | es = shsurf->surface; |
| 1604 | |
Jason Ekstrand | 918f2dd | 2013-12-02 21:01:53 -0600 | [diff] [blame] | 1605 | weston_view_set_position(shsurf->view, dx, dy); |
Rusty Lynch | 1084da5 | 2013-08-15 09:10:08 -0700 | [diff] [blame] | 1606 | |
| 1607 | weston_compositor_schedule_repaint(es->compositor); |
| 1608 | } |
| 1609 | |
Jonas Ådahl | 1ea343e | 2013-10-25 23:18:05 +0200 | [diff] [blame] | 1610 | static void |
Jonas Ådahl | 1679f23 | 2014-04-12 09:39:51 +0200 | [diff] [blame] | 1611 | touch_move_grab_frame(struct weston_touch_grab *grab) |
| 1612 | { |
| 1613 | } |
| 1614 | |
| 1615 | static void |
Jonas Ådahl | 1ea343e | 2013-10-25 23:18:05 +0200 | [diff] [blame] | 1616 | touch_move_grab_cancel(struct weston_touch_grab *grab) |
| 1617 | { |
| 1618 | struct weston_touch_move_grab *move = |
| 1619 | (struct weston_touch_move_grab *) container_of( |
| 1620 | grab, struct shell_touch_grab, grab); |
| 1621 | |
| 1622 | shell_touch_grab_end(&move->base); |
| 1623 | free(move); |
| 1624 | } |
| 1625 | |
Rusty Lynch | 1084da5 | 2013-08-15 09:10:08 -0700 | [diff] [blame] | 1626 | static const struct weston_touch_grab_interface touch_move_grab_interface = { |
| 1627 | touch_move_grab_down, |
| 1628 | touch_move_grab_up, |
| 1629 | touch_move_grab_motion, |
Jonas Ådahl | 1679f23 | 2014-04-12 09:39:51 +0200 | [diff] [blame] | 1630 | touch_move_grab_frame, |
Jonas Ådahl | 1ea343e | 2013-10-25 23:18:05 +0200 | [diff] [blame] | 1631 | touch_move_grab_cancel, |
Rusty Lynch | 1084da5 | 2013-08-15 09:10:08 -0700 | [diff] [blame] | 1632 | }; |
| 1633 | |
| 1634 | static int |
Derek Foreman | b7674ae | 2015-07-15 13:00:37 -0500 | [diff] [blame] | 1635 | surface_touch_move(struct shell_surface *shsurf, struct weston_touch *touch) |
Rusty Lynch | 1084da5 | 2013-08-15 09:10:08 -0700 | [diff] [blame] | 1636 | { |
| 1637 | struct weston_touch_move_grab *move; |
| 1638 | |
| 1639 | if (!shsurf) |
| 1640 | return -1; |
| 1641 | |
Ander Conselvan de Oliveira | 6d43f04 | 2014-05-07 14:22:23 +0300 | [diff] [blame] | 1642 | if (shsurf->state.fullscreen || shsurf->state.maximized) |
Rusty Lynch | 1084da5 | 2013-08-15 09:10:08 -0700 | [diff] [blame] | 1643 | return 0; |
| 1644 | |
| 1645 | move = malloc(sizeof *move); |
| 1646 | if (!move) |
| 1647 | return -1; |
| 1648 | |
Kristian Høgsberg | 8e80a31 | 2014-01-17 15:18:10 -0800 | [diff] [blame] | 1649 | move->active = 1; |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 1650 | move->dx = wl_fixed_from_double(shsurf->view->geometry.x) - |
Derek Foreman | b7674ae | 2015-07-15 13:00:37 -0500 | [diff] [blame] | 1651 | touch->grab_x; |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 1652 | move->dy = wl_fixed_from_double(shsurf->view->geometry.y) - |
Derek Foreman | b7674ae | 2015-07-15 13:00:37 -0500 | [diff] [blame] | 1653 | touch->grab_y; |
Rusty Lynch | 1084da5 | 2013-08-15 09:10:08 -0700 | [diff] [blame] | 1654 | |
| 1655 | shell_touch_grab_start(&move->base, &touch_move_grab_interface, shsurf, |
Derek Foreman | b7674ae | 2015-07-15 13:00:37 -0500 | [diff] [blame] | 1656 | touch); |
Rusty Lynch | 1084da5 | 2013-08-15 09:10:08 -0700 | [diff] [blame] | 1657 | |
| 1658 | return 0; |
| 1659 | } |
| 1660 | |
| 1661 | static void |
Kristian Høgsberg | 6848c25 | 2013-05-08 22:02:59 -0400 | [diff] [blame] | 1662 | noop_grab_focus(struct weston_pointer_grab *grab) |
Kristian Høgsberg | 9ddb826 | 2012-01-04 21:30:29 -0500 | [diff] [blame] | 1663 | { |
Kristian Høgsberg | 9ddb826 | 2012-01-04 21:30:29 -0500 | [diff] [blame] | 1664 | } |
| 1665 | |
| 1666 | static void |
Kristian Høgsberg | ae356ae | 2014-04-29 16:03:54 -0700 | [diff] [blame] | 1667 | constrain_position(struct weston_move_grab *move, int *cx, int *cy) |
| 1668 | { |
| 1669 | struct shell_surface *shsurf = move->base.shsurf; |
| 1670 | struct weston_pointer *pointer = move->base.grab.pointer; |
Derek Foreman | 6feb0f9 | 2015-04-15 12:23:56 -0500 | [diff] [blame^] | 1671 | int x, y, bottom; |
Kristian Høgsberg | ae356ae | 2014-04-29 16:03:54 -0700 | [diff] [blame] | 1672 | const int safety = 50; |
Derek Foreman | 6feb0f9 | 2015-04-15 12:23:56 -0500 | [diff] [blame^] | 1673 | pixman_rectangle32_t area; |
Kristian Høgsberg | ae356ae | 2014-04-29 16:03:54 -0700 | [diff] [blame] | 1674 | |
| 1675 | x = wl_fixed_to_int(pointer->x + move->dx); |
| 1676 | y = wl_fixed_to_int(pointer->y + move->dy); |
| 1677 | |
Jonny Lamb | d73c694 | 2014-08-20 15:53:20 +0200 | [diff] [blame] | 1678 | if (shsurf->shell->panel_position == DESKTOP_SHELL_PANEL_POSITION_TOP) { |
Derek Foreman | 6feb0f9 | 2015-04-15 12:23:56 -0500 | [diff] [blame^] | 1679 | get_output_work_area(shsurf->shell, |
| 1680 | shsurf->surface->output, |
| 1681 | &area); |
Kristian Høgsberg | ae356ae | 2014-04-29 16:03:54 -0700 | [diff] [blame] | 1682 | |
Derek Foreman | 6feb0f9 | 2015-04-15 12:23:56 -0500 | [diff] [blame^] | 1683 | bottom = y + shsurf->geometry.height + shsurf->geometry.y; |
| 1684 | if (bottom - safety < area.y) |
| 1685 | y = area.y + safety - shsurf->geometry.height |
| 1686 | - shsurf->geometry.y; |
Jonny Lamb | d73c694 | 2014-08-20 15:53:20 +0200 | [diff] [blame] | 1687 | |
| 1688 | if (move->client_initiated && |
Derek Foreman | 6feb0f9 | 2015-04-15 12:23:56 -0500 | [diff] [blame^] | 1689 | y + shsurf->geometry.y < area.y) |
| 1690 | y = area.y - shsurf->geometry.y; |
| 1691 | |
Jonny Lamb | d73c694 | 2014-08-20 15:53:20 +0200 | [diff] [blame] | 1692 | } |
Kristian Høgsberg | ae356ae | 2014-04-29 16:03:54 -0700 | [diff] [blame] | 1693 | |
| 1694 | *cx = x; |
| 1695 | *cy = y; |
| 1696 | } |
| 1697 | |
| 1698 | static void |
Giulio Camuffo | 1959ab8 | 2013-11-14 23:42:52 +0100 | [diff] [blame] | 1699 | move_grab_motion(struct weston_pointer_grab *grab, uint32_t time, |
| 1700 | wl_fixed_t x, wl_fixed_t y) |
Kristian Høgsberg | 4cca349 | 2011-01-18 07:53:49 -0500 | [diff] [blame] | 1701 | { |
Kristian Høgsberg | 8334bc1 | 2012-01-03 10:29:47 -0500 | [diff] [blame] | 1702 | struct weston_move_grab *move = (struct weston_move_grab *) grab; |
Kristian Høgsberg | 02bbabb | 2013-05-06 22:15:05 -0400 | [diff] [blame] | 1703 | struct weston_pointer *pointer = grab->pointer; |
Ander Conselvan de Oliveira | fe0444a | 2012-04-04 17:48:05 +0300 | [diff] [blame] | 1704 | struct shell_surface *shsurf = move->base.shsurf; |
Kristian Høgsberg | ae356ae | 2014-04-29 16:03:54 -0700 | [diff] [blame] | 1705 | int cx, cy; |
Giulio Camuffo | 1959ab8 | 2013-11-14 23:42:52 +0100 | [diff] [blame] | 1706 | |
| 1707 | weston_pointer_move(pointer, x, y); |
Ander Conselvan de Oliveira | fe0444a | 2012-04-04 17:48:05 +0300 | [diff] [blame] | 1708 | if (!shsurf) |
| 1709 | return; |
| 1710 | |
Kristian Høgsberg | ae356ae | 2014-04-29 16:03:54 -0700 | [diff] [blame] | 1711 | constrain_position(move, &cx, &cy); |
| 1712 | |
| 1713 | weston_view_set_position(shsurf->view, cx, cy); |
Kristian Høgsberg | 4cca349 | 2011-01-18 07:53:49 -0500 | [diff] [blame] | 1714 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 1715 | weston_compositor_schedule_repaint(shsurf->surface->compositor); |
Kristian Høgsberg | 4cca349 | 2011-01-18 07:53:49 -0500 | [diff] [blame] | 1716 | } |
| 1717 | |
| 1718 | static void |
Kristian Høgsberg | 02bbabb | 2013-05-06 22:15:05 -0400 | [diff] [blame] | 1719 | move_grab_button(struct weston_pointer_grab *grab, |
Daniel Stone | 4dbadb1 | 2012-05-30 16:31:51 +0100 | [diff] [blame] | 1720 | uint32_t time, uint32_t button, uint32_t state_w) |
Kristian Høgsberg | 4cca349 | 2011-01-18 07:53:49 -0500 | [diff] [blame] | 1721 | { |
Ander Conselvan de Oliveira | fe0444a | 2012-04-04 17:48:05 +0300 | [diff] [blame] | 1722 | struct shell_grab *shell_grab = container_of(grab, struct shell_grab, |
| 1723 | grab); |
Kristian Høgsberg | 02bbabb | 2013-05-06 22:15:05 -0400 | [diff] [blame] | 1724 | struct weston_pointer *pointer = grab->pointer; |
Daniel Stone | 4dbadb1 | 2012-05-30 16:31:51 +0100 | [diff] [blame] | 1725 | enum wl_pointer_button_state state = state_w; |
Kristian Høgsberg | 4cca349 | 2011-01-18 07:53:49 -0500 | [diff] [blame] | 1726 | |
Daniel Stone | 4dbadb1 | 2012-05-30 16:31:51 +0100 | [diff] [blame] | 1727 | if (pointer->button_count == 0 && |
| 1728 | state == WL_POINTER_BUTTON_STATE_RELEASED) { |
Ander Conselvan de Oliveira | b9d2a0f | 2012-06-28 18:08:05 +0300 | [diff] [blame] | 1729 | shell_grab_end(shell_grab); |
Kristian Høgsberg | 9ddb826 | 2012-01-04 21:30:29 -0500 | [diff] [blame] | 1730 | free(grab); |
| 1731 | } |
Kristian Høgsberg | 4cca349 | 2011-01-18 07:53:49 -0500 | [diff] [blame] | 1732 | } |
| 1733 | |
Jonas Ådahl | 1ea343e | 2013-10-25 23:18:05 +0200 | [diff] [blame] | 1734 | static void |
| 1735 | move_grab_cancel(struct weston_pointer_grab *grab) |
| 1736 | { |
| 1737 | struct shell_grab *shell_grab = |
| 1738 | container_of(grab, struct shell_grab, grab); |
| 1739 | |
| 1740 | shell_grab_end(shell_grab); |
| 1741 | free(grab); |
| 1742 | } |
| 1743 | |
Kristian Høgsberg | 02bbabb | 2013-05-06 22:15:05 -0400 | [diff] [blame] | 1744 | static const struct weston_pointer_grab_interface move_grab_interface = { |
Kristian Høgsberg | 9ddb826 | 2012-01-04 21:30:29 -0500 | [diff] [blame] | 1745 | noop_grab_focus, |
Kristian Høgsberg | 4cca349 | 2011-01-18 07:53:49 -0500 | [diff] [blame] | 1746 | move_grab_motion, |
| 1747 | move_grab_button, |
Jonas Ådahl | 1ea343e | 2013-10-25 23:18:05 +0200 | [diff] [blame] | 1748 | move_grab_cancel, |
Kristian Høgsberg | 4cca349 | 2011-01-18 07:53:49 -0500 | [diff] [blame] | 1749 | }; |
| 1750 | |
Kristian Høgsberg | 9e31bff | 2012-08-01 00:08:07 -0400 | [diff] [blame] | 1751 | static int |
Derek Foreman | 794fa0e | 2015-07-15 13:00:38 -0500 | [diff] [blame] | 1752 | surface_move(struct shell_surface *shsurf, struct weston_pointer *pointer, |
Derek Foreman | cf7d95a | 2015-06-03 15:53:22 -0500 | [diff] [blame] | 1753 | bool client_initiated) |
Kristian Høgsberg | 9e31bff | 2012-08-01 00:08:07 -0400 | [diff] [blame] | 1754 | { |
| 1755 | struct weston_move_grab *move; |
| 1756 | |
| 1757 | if (!shsurf) |
| 1758 | return -1; |
| 1759 | |
Kristian Høgsberg | a4b620e | 2014-04-30 16:05:49 -0700 | [diff] [blame] | 1760 | if (shsurf->grabbed || |
| 1761 | shsurf->state.fullscreen || shsurf->state.maximized) |
Kristian Høgsberg | 9e31bff | 2012-08-01 00:08:07 -0400 | [diff] [blame] | 1762 | return 0; |
| 1763 | |
| 1764 | move = malloc(sizeof *move); |
| 1765 | if (!move) |
| 1766 | return -1; |
| 1767 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 1768 | move->dx = wl_fixed_from_double(shsurf->view->geometry.x) - |
Derek Foreman | 794fa0e | 2015-07-15 13:00:38 -0500 | [diff] [blame] | 1769 | pointer->grab_x; |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 1770 | move->dy = wl_fixed_from_double(shsurf->view->geometry.y) - |
Derek Foreman | 794fa0e | 2015-07-15 13:00:38 -0500 | [diff] [blame] | 1771 | pointer->grab_y; |
Kristian Høgsberg | ae356ae | 2014-04-29 16:03:54 -0700 | [diff] [blame] | 1772 | move->client_initiated = client_initiated; |
Kristian Høgsberg | 9e31bff | 2012-08-01 00:08:07 -0400 | [diff] [blame] | 1773 | |
| 1774 | shell_grab_start(&move->base, &move_grab_interface, shsurf, |
Derek Foreman | 794fa0e | 2015-07-15 13:00:38 -0500 | [diff] [blame] | 1775 | pointer, DESKTOP_SHELL_CURSOR_MOVE); |
Kristian Høgsberg | 9e31bff | 2012-08-01 00:08:07 -0400 | [diff] [blame] | 1776 | |
| 1777 | return 0; |
| 1778 | } |
| 1779 | |
| 1780 | static void |
Rafael Antognolli | e2a3455 | 2013-12-03 15:35:45 -0200 | [diff] [blame] | 1781 | common_surface_move(struct wl_resource *resource, |
| 1782 | struct wl_resource *seat_resource, uint32_t serial) |
Kristian Høgsberg | 9e31bff | 2012-08-01 00:08:07 -0400 | [diff] [blame] | 1783 | { |
Jason Ekstrand | 44a3863 | 2013-06-14 10:08:00 -0500 | [diff] [blame] | 1784 | struct weston_seat *seat = wl_resource_get_user_data(seat_resource); |
Jason Ekstrand | 651f00e | 2013-06-14 10:07:54 -0500 | [diff] [blame] | 1785 | struct shell_surface *shsurf = wl_resource_get_user_data(resource); |
Giulio Camuffo | 61da3fc | 2013-04-25 13:57:45 +0300 | [diff] [blame] | 1786 | struct weston_surface *surface; |
Kristian Høgsberg | 9e31bff | 2012-08-01 00:08:07 -0400 | [diff] [blame] | 1787 | |
Kristian Høgsberg | e1b655d | 2013-08-28 23:16:20 -0700 | [diff] [blame] | 1788 | if (seat->pointer && |
Kristian Høgsberg | 70f2901 | 2014-01-09 15:43:17 -0800 | [diff] [blame] | 1789 | seat->pointer->focus && |
Kristian Høgsberg | e1b655d | 2013-08-28 23:16:20 -0700 | [diff] [blame] | 1790 | seat->pointer->button_count > 0 && |
| 1791 | seat->pointer->grab_serial == serial) { |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 1792 | surface = weston_surface_get_main_surface(seat->pointer->focus->surface); |
U. Artie Eoff | cf5737a | 2014-01-17 10:08:25 -0800 | [diff] [blame] | 1793 | if ((surface == shsurf->surface) && |
Derek Foreman | 794fa0e | 2015-07-15 13:00:38 -0500 | [diff] [blame] | 1794 | (surface_move(shsurf, seat->pointer, true) < 0)) |
Rusty Lynch | 1084da5 | 2013-08-15 09:10:08 -0700 | [diff] [blame] | 1795 | wl_resource_post_no_memory(resource); |
Kristian Høgsberg | e1b655d | 2013-08-28 23:16:20 -0700 | [diff] [blame] | 1796 | } else if (seat->touch && |
Kristian Høgsberg | 70f2901 | 2014-01-09 15:43:17 -0800 | [diff] [blame] | 1797 | seat->touch->focus && |
Kristian Høgsberg | e1b655d | 2013-08-28 23:16:20 -0700 | [diff] [blame] | 1798 | seat->touch->grab_serial == serial) { |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 1799 | surface = weston_surface_get_main_surface(seat->touch->focus->surface); |
U. Artie Eoff | cf5737a | 2014-01-17 10:08:25 -0800 | [diff] [blame] | 1800 | if ((surface == shsurf->surface) && |
Derek Foreman | b7674ae | 2015-07-15 13:00:37 -0500 | [diff] [blame] | 1801 | (surface_touch_move(shsurf, seat->touch) < 0)) |
Rusty Lynch | 1084da5 | 2013-08-15 09:10:08 -0700 | [diff] [blame] | 1802 | wl_resource_post_no_memory(resource); |
| 1803 | } |
Kristian Høgsberg | 9e31bff | 2012-08-01 00:08:07 -0400 | [diff] [blame] | 1804 | } |
| 1805 | |
Rafael Antognolli | e2a3455 | 2013-12-03 15:35:45 -0200 | [diff] [blame] | 1806 | static void |
| 1807 | shell_surface_move(struct wl_client *client, struct wl_resource *resource, |
| 1808 | struct wl_resource *seat_resource, uint32_t serial) |
| 1809 | { |
| 1810 | common_surface_move(resource, seat_resource, serial); |
| 1811 | } |
| 1812 | |
Kristian Høgsberg | 9e31bff | 2012-08-01 00:08:07 -0400 | [diff] [blame] | 1813 | struct weston_resize_grab { |
| 1814 | struct shell_grab base; |
| 1815 | uint32_t edges; |
| 1816 | int32_t width, height; |
| 1817 | }; |
| 1818 | |
| 1819 | static void |
Giulio Camuffo | 1959ab8 | 2013-11-14 23:42:52 +0100 | [diff] [blame] | 1820 | resize_grab_motion(struct weston_pointer_grab *grab, uint32_t time, |
| 1821 | wl_fixed_t x, wl_fixed_t y) |
Kristian Høgsberg | 9e31bff | 2012-08-01 00:08:07 -0400 | [diff] [blame] | 1822 | { |
| 1823 | struct weston_resize_grab *resize = (struct weston_resize_grab *) grab; |
Kristian Høgsberg | 02bbabb | 2013-05-06 22:15:05 -0400 | [diff] [blame] | 1824 | struct weston_pointer *pointer = grab->pointer; |
Kristian Høgsberg | 9e31bff | 2012-08-01 00:08:07 -0400 | [diff] [blame] | 1825 | struct shell_surface *shsurf = resize->base.shsurf; |
| 1826 | int32_t width, height; |
| 1827 | wl_fixed_t from_x, from_y; |
| 1828 | wl_fixed_t to_x, to_y; |
| 1829 | |
Giulio Camuffo | 1959ab8 | 2013-11-14 23:42:52 +0100 | [diff] [blame] | 1830 | weston_pointer_move(pointer, x, y); |
| 1831 | |
Kristian Høgsberg | e0b9d5b | 2014-04-30 13:45:49 -0700 | [diff] [blame] | 1832 | if (!shsurf) |
Kristian Høgsberg | 9e31bff | 2012-08-01 00:08:07 -0400 | [diff] [blame] | 1833 | return; |
| 1834 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 1835 | weston_view_from_global_fixed(shsurf->view, |
| 1836 | pointer->grab_x, pointer->grab_y, |
| 1837 | &from_x, &from_y); |
| 1838 | weston_view_from_global_fixed(shsurf->view, |
| 1839 | pointer->x, pointer->y, &to_x, &to_y); |
Kristian Høgsberg | 9e31bff | 2012-08-01 00:08:07 -0400 | [diff] [blame] | 1840 | |
| 1841 | width = resize->width; |
| 1842 | if (resize->edges & WL_SHELL_SURFACE_RESIZE_LEFT) { |
| 1843 | width += wl_fixed_to_int(from_x - to_x); |
| 1844 | } else if (resize->edges & WL_SHELL_SURFACE_RESIZE_RIGHT) { |
| 1845 | width += wl_fixed_to_int(to_x - from_x); |
| 1846 | } |
| 1847 | |
| 1848 | height = resize->height; |
| 1849 | if (resize->edges & WL_SHELL_SURFACE_RESIZE_TOP) { |
| 1850 | height += wl_fixed_to_int(from_y - to_y); |
| 1851 | } else if (resize->edges & WL_SHELL_SURFACE_RESIZE_BOTTOM) { |
| 1852 | height += wl_fixed_to_int(to_y - from_y); |
| 1853 | } |
| 1854 | |
Derek Foreman | 70ac0ed | 2015-03-18 11:16:33 -0500 | [diff] [blame] | 1855 | if (width < 1) |
| 1856 | width = 1; |
| 1857 | if (height < 1) |
| 1858 | height = 1; |
Jasper St. Pierre | ac985be | 2014-04-28 11:19:28 -0400 | [diff] [blame] | 1859 | shsurf->client->send_configure(shsurf->surface, width, height); |
Kristian Høgsberg | 9e31bff | 2012-08-01 00:08:07 -0400 | [diff] [blame] | 1860 | } |
| 1861 | |
| 1862 | static void |
Jasper St. Pierre | ac985be | 2014-04-28 11:19:28 -0400 | [diff] [blame] | 1863 | 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] | 1864 | { |
| 1865 | struct shell_surface *shsurf = get_shell_surface(surface); |
| 1866 | |
U. Artie Eoff | cf5737a | 2014-01-17 10:08:25 -0800 | [diff] [blame] | 1867 | assert(shsurf); |
| 1868 | |
Kristian Høgsberg | e0b9d5b | 2014-04-30 13:45:49 -0700 | [diff] [blame] | 1869 | if (shsurf->resource) |
| 1870 | wl_shell_surface_send_configure(shsurf->resource, |
Jasper St. Pierre | ac985be | 2014-04-28 11:19:28 -0400 | [diff] [blame] | 1871 | shsurf->resize_edges, |
| 1872 | width, height); |
Kristian Høgsberg | 9e31bff | 2012-08-01 00:08:07 -0400 | [diff] [blame] | 1873 | } |
| 1874 | |
| 1875 | static const struct weston_shell_client shell_client = { |
| 1876 | send_configure |
| 1877 | }; |
| 1878 | |
| 1879 | static void |
Kristian Høgsberg | 02bbabb | 2013-05-06 22:15:05 -0400 | [diff] [blame] | 1880 | resize_grab_button(struct weston_pointer_grab *grab, |
Kristian Høgsberg | 9e31bff | 2012-08-01 00:08:07 -0400 | [diff] [blame] | 1881 | uint32_t time, uint32_t button, uint32_t state_w) |
| 1882 | { |
| 1883 | struct weston_resize_grab *resize = (struct weston_resize_grab *) grab; |
Kristian Høgsberg | 02bbabb | 2013-05-06 22:15:05 -0400 | [diff] [blame] | 1884 | struct weston_pointer *pointer = grab->pointer; |
Kristian Høgsberg | 9e31bff | 2012-08-01 00:08:07 -0400 | [diff] [blame] | 1885 | enum wl_pointer_button_state state = state_w; |
| 1886 | |
| 1887 | if (pointer->button_count == 0 && |
| 1888 | state == WL_POINTER_BUTTON_STATE_RELEASED) { |
| 1889 | shell_grab_end(&resize->base); |
| 1890 | free(grab); |
| 1891 | } |
| 1892 | } |
| 1893 | |
Jonas Ådahl | 1ea343e | 2013-10-25 23:18:05 +0200 | [diff] [blame] | 1894 | static void |
| 1895 | resize_grab_cancel(struct weston_pointer_grab *grab) |
| 1896 | { |
| 1897 | struct weston_resize_grab *resize = (struct weston_resize_grab *) grab; |
| 1898 | |
| 1899 | shell_grab_end(&resize->base); |
| 1900 | free(grab); |
| 1901 | } |
| 1902 | |
Kristian Høgsberg | 02bbabb | 2013-05-06 22:15:05 -0400 | [diff] [blame] | 1903 | static const struct weston_pointer_grab_interface resize_grab_interface = { |
Kristian Høgsberg | 9e31bff | 2012-08-01 00:08:07 -0400 | [diff] [blame] | 1904 | noop_grab_focus, |
| 1905 | resize_grab_motion, |
| 1906 | resize_grab_button, |
Jonas Ådahl | 1ea343e | 2013-10-25 23:18:05 +0200 | [diff] [blame] | 1907 | resize_grab_cancel, |
Kristian Høgsberg | 9e31bff | 2012-08-01 00:08:07 -0400 | [diff] [blame] | 1908 | }; |
| 1909 | |
Giulio Camuffo | b836664 | 2013-04-25 13:57:46 +0300 | [diff] [blame] | 1910 | /* |
| 1911 | * Returns the bounding box of a surface and all its sub-surfaces, |
| 1912 | * in the surface coordinates system. */ |
| 1913 | static void |
| 1914 | surface_subsurfaces_boundingbox(struct weston_surface *surface, int32_t *x, |
| 1915 | int32_t *y, int32_t *w, int32_t *h) { |
| 1916 | pixman_region32_t region; |
| 1917 | pixman_box32_t *box; |
| 1918 | struct weston_subsurface *subsurface; |
| 1919 | |
| 1920 | pixman_region32_init_rect(®ion, 0, 0, |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 1921 | surface->width, |
| 1922 | surface->height); |
Giulio Camuffo | b836664 | 2013-04-25 13:57:46 +0300 | [diff] [blame] | 1923 | |
| 1924 | wl_list_for_each(subsurface, &surface->subsurface_list, parent_link) { |
| 1925 | pixman_region32_union_rect(®ion, ®ion, |
| 1926 | subsurface->position.x, |
| 1927 | subsurface->position.y, |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 1928 | subsurface->surface->width, |
| 1929 | subsurface->surface->height); |
Giulio Camuffo | b836664 | 2013-04-25 13:57:46 +0300 | [diff] [blame] | 1930 | } |
| 1931 | |
| 1932 | box = pixman_region32_extents(®ion); |
| 1933 | if (x) |
| 1934 | *x = box->x1; |
| 1935 | if (y) |
| 1936 | *y = box->y1; |
| 1937 | if (w) |
| 1938 | *w = box->x2 - box->x1; |
| 1939 | if (h) |
| 1940 | *h = box->y2 - box->y1; |
| 1941 | |
| 1942 | pixman_region32_fini(®ion); |
| 1943 | } |
| 1944 | |
Kristian Høgsberg | 9e31bff | 2012-08-01 00:08:07 -0400 | [diff] [blame] | 1945 | static int |
| 1946 | surface_resize(struct shell_surface *shsurf, |
Derek Foreman | 8fbebbd | 2015-07-15 13:00:40 -0500 | [diff] [blame] | 1947 | struct weston_pointer *pointer, uint32_t edges) |
Kristian Høgsberg | 9e31bff | 2012-08-01 00:08:07 -0400 | [diff] [blame] | 1948 | { |
| 1949 | struct weston_resize_grab *resize; |
Ondřej Majerech | ae9c4fc | 2014-08-21 15:47:22 +0200 | [diff] [blame] | 1950 | const unsigned resize_topbottom = |
| 1951 | WL_SHELL_SURFACE_RESIZE_TOP | WL_SHELL_SURFACE_RESIZE_BOTTOM; |
| 1952 | const unsigned resize_leftright = |
| 1953 | WL_SHELL_SURFACE_RESIZE_LEFT | WL_SHELL_SURFACE_RESIZE_RIGHT; |
| 1954 | const unsigned resize_any = resize_topbottom | resize_leftright; |
Kristian Høgsberg | 9e31bff | 2012-08-01 00:08:07 -0400 | [diff] [blame] | 1955 | |
Kristian Høgsberg | a4b620e | 2014-04-30 16:05:49 -0700 | [diff] [blame] | 1956 | if (shsurf->grabbed || |
| 1957 | shsurf->state.fullscreen || shsurf->state.maximized) |
Kristian Høgsberg | 9e31bff | 2012-08-01 00:08:07 -0400 | [diff] [blame] | 1958 | return 0; |
| 1959 | |
Ondřej Majerech | ae9c4fc | 2014-08-21 15:47:22 +0200 | [diff] [blame] | 1960 | /* Check for invalid edge combinations. */ |
| 1961 | if (edges == WL_SHELL_SURFACE_RESIZE_NONE || edges > resize_any || |
| 1962 | (edges & resize_topbottom) == resize_topbottom || |
| 1963 | (edges & resize_leftright) == resize_leftright) |
Kristian Høgsberg | 9e31bff | 2012-08-01 00:08:07 -0400 | [diff] [blame] | 1964 | return 0; |
| 1965 | |
| 1966 | resize = malloc(sizeof *resize); |
| 1967 | if (!resize) |
| 1968 | return -1; |
| 1969 | |
| 1970 | resize->edges = edges; |
Kristian Høgsberg | 9e31bff | 2012-08-01 00:08:07 -0400 | [diff] [blame] | 1971 | |
Jasper St. Pierre | ccf48fb | 2014-05-02 10:21:38 -0400 | [diff] [blame] | 1972 | resize->width = shsurf->geometry.width; |
| 1973 | resize->height = shsurf->geometry.height; |
Jasper St. Pierre | bd65e50 | 2014-07-14 16:28:48 -0400 | [diff] [blame] | 1974 | |
Kristian Høgsberg | 44cd196 | 2014-02-05 21:36:04 -0800 | [diff] [blame] | 1975 | shsurf->resize_edges = edges; |
Jasper St. Pierre | 5befdda | 2014-05-06 08:50:47 -0400 | [diff] [blame] | 1976 | shell_surface_state_changed(shsurf); |
Kristian Høgsberg | 9e31bff | 2012-08-01 00:08:07 -0400 | [diff] [blame] | 1977 | shell_grab_start(&resize->base, &resize_grab_interface, shsurf, |
Derek Foreman | 8fbebbd | 2015-07-15 13:00:40 -0500 | [diff] [blame] | 1978 | pointer, edges); |
Kristian Høgsberg | 9e31bff | 2012-08-01 00:08:07 -0400 | [diff] [blame] | 1979 | |
| 1980 | return 0; |
| 1981 | } |
| 1982 | |
| 1983 | static void |
Rafael Antognolli | e2a3455 | 2013-12-03 15:35:45 -0200 | [diff] [blame] | 1984 | common_surface_resize(struct wl_resource *resource, |
| 1985 | struct wl_resource *seat_resource, uint32_t serial, |
| 1986 | uint32_t edges) |
Kristian Høgsberg | 9e31bff | 2012-08-01 00:08:07 -0400 | [diff] [blame] | 1987 | { |
Jason Ekstrand | 44a3863 | 2013-06-14 10:08:00 -0500 | [diff] [blame] | 1988 | struct weston_seat *seat = wl_resource_get_user_data(seat_resource); |
Jason Ekstrand | 651f00e | 2013-06-14 10:07:54 -0500 | [diff] [blame] | 1989 | struct shell_surface *shsurf = wl_resource_get_user_data(resource); |
Giulio Camuffo | 61da3fc | 2013-04-25 13:57:45 +0300 | [diff] [blame] | 1990 | struct weston_surface *surface; |
Kristian Høgsberg | 9e31bff | 2012-08-01 00:08:07 -0400 | [diff] [blame] | 1991 | |
Emilio Pozuelo Monfort | 5872b68 | 2014-06-18 17:48:58 +0200 | [diff] [blame] | 1992 | if (seat->pointer == NULL || |
| 1993 | seat->pointer->button_count == 0 || |
Kristian Høgsberg | e314875 | 2013-05-06 23:19:49 -0400 | [diff] [blame] | 1994 | seat->pointer->grab_serial != serial || |
Kristian Høgsberg | 70f2901 | 2014-01-09 15:43:17 -0800 | [diff] [blame] | 1995 | seat->pointer->focus == NULL) |
| 1996 | return; |
| 1997 | |
| 1998 | surface = weston_surface_get_main_surface(seat->pointer->focus->surface); |
| 1999 | if (surface != shsurf->surface) |
Kristian Høgsberg | 9e31bff | 2012-08-01 00:08:07 -0400 | [diff] [blame] | 2000 | return; |
| 2001 | |
Derek Foreman | 8fbebbd | 2015-07-15 13:00:40 -0500 | [diff] [blame] | 2002 | if (surface_resize(shsurf, seat->pointer, edges) < 0) |
Kristian Høgsberg | 9e31bff | 2012-08-01 00:08:07 -0400 | [diff] [blame] | 2003 | wl_resource_post_no_memory(resource); |
| 2004 | } |
| 2005 | |
Scott Moreau | c3e54eb | 2012-04-17 19:06:20 -0600 | [diff] [blame] | 2006 | static void |
Rafael Antognolli | e2a3455 | 2013-12-03 15:35:45 -0200 | [diff] [blame] | 2007 | shell_surface_resize(struct wl_client *client, struct wl_resource *resource, |
| 2008 | struct wl_resource *seat_resource, uint32_t serial, |
| 2009 | uint32_t edges) |
| 2010 | { |
| 2011 | common_surface_resize(resource, seat_resource, serial, edges); |
| 2012 | } |
| 2013 | |
| 2014 | static void |
Kristian Høgsberg | 6848c25 | 2013-05-08 22:02:59 -0400 | [diff] [blame] | 2015 | busy_cursor_grab_focus(struct weston_pointer_grab *base) |
Scott Moreau | c3e54eb | 2012-04-17 19:06:20 -0600 | [diff] [blame] | 2016 | { |
Kristian Høgsberg | d56bd90 | 2012-06-05 09:58:51 -0400 | [diff] [blame] | 2017 | struct shell_grab *grab = (struct shell_grab *) base; |
Kristian Høgsberg | 6848c25 | 2013-05-08 22:02:59 -0400 | [diff] [blame] | 2018 | struct weston_pointer *pointer = base->pointer; |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 2019 | struct weston_view *view; |
Kristian Høgsberg | 6848c25 | 2013-05-08 22:02:59 -0400 | [diff] [blame] | 2020 | wl_fixed_t sx, sy; |
| 2021 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 2022 | view = weston_compositor_pick_view(pointer->seat->compositor, |
| 2023 | pointer->x, pointer->y, |
| 2024 | &sx, &sy); |
Scott Moreau | c3e54eb | 2012-04-17 19:06:20 -0600 | [diff] [blame] | 2025 | |
Kristian Høgsberg | 2bff94e | 2014-02-11 12:22:51 -0800 | [diff] [blame] | 2026 | if (!grab->shsurf || grab->shsurf->surface != view->surface) { |
| 2027 | shell_grab_end(grab); |
| 2028 | free(grab); |
| 2029 | } |
Scott Moreau | c3e54eb | 2012-04-17 19:06:20 -0600 | [diff] [blame] | 2030 | } |
| 2031 | |
| 2032 | static void |
Giulio Camuffo | 1959ab8 | 2013-11-14 23:42:52 +0100 | [diff] [blame] | 2033 | busy_cursor_grab_motion(struct weston_pointer_grab *grab, uint32_t time, |
| 2034 | wl_fixed_t x, wl_fixed_t y) |
Scott Moreau | c3e54eb | 2012-04-17 19:06:20 -0600 | [diff] [blame] | 2035 | { |
Giulio Camuffo | 1959ab8 | 2013-11-14 23:42:52 +0100 | [diff] [blame] | 2036 | weston_pointer_move(grab->pointer, x, y); |
Kristian Høgsberg | d56bd90 | 2012-06-05 09:58:51 -0400 | [diff] [blame] | 2037 | } |
Scott Moreau | c3e54eb | 2012-04-17 19:06:20 -0600 | [diff] [blame] | 2038 | |
Kristian Høgsberg | d56bd90 | 2012-06-05 09:58:51 -0400 | [diff] [blame] | 2039 | static void |
Kristian Høgsberg | 02bbabb | 2013-05-06 22:15:05 -0400 | [diff] [blame] | 2040 | busy_cursor_grab_button(struct weston_pointer_grab *base, |
Kristian Høgsberg | d56bd90 | 2012-06-05 09:58:51 -0400 | [diff] [blame] | 2041 | uint32_t time, uint32_t button, uint32_t state) |
| 2042 | { |
Kristian Høgsberg | bbe9839 | 2012-08-01 00:20:21 -0400 | [diff] [blame] | 2043 | struct shell_grab *grab = (struct shell_grab *) base; |
Kristian Høgsberg | e122b7b | 2013-05-08 16:47:00 -0400 | [diff] [blame] | 2044 | struct shell_surface *shsurf = grab->shsurf; |
Derek Foreman | 794fa0e | 2015-07-15 13:00:38 -0500 | [diff] [blame] | 2045 | struct weston_pointer *pointer = grab->grab.pointer; |
| 2046 | struct weston_seat *seat = pointer->seat; |
Kristian Høgsberg | bbe9839 | 2012-08-01 00:20:21 -0400 | [diff] [blame] | 2047 | |
Kristian Høgsberg | bbe9839 | 2012-08-01 00:20:21 -0400 | [diff] [blame] | 2048 | if (shsurf && button == BTN_LEFT && state) { |
Emilio Pozuelo Monfort | 9e7c759 | 2014-01-30 14:01:10 +0100 | [diff] [blame] | 2049 | activate(shsurf->shell, shsurf->surface, seat, true); |
Derek Foreman | 794fa0e | 2015-07-15 13:00:38 -0500 | [diff] [blame] | 2050 | surface_move(shsurf, pointer, false); |
Kristian Høgsberg | 0c36903 | 2013-02-14 21:31:44 -0500 | [diff] [blame] | 2051 | } else if (shsurf && button == BTN_RIGHT && state) { |
Emilio Pozuelo Monfort | 9e7c759 | 2014-01-30 14:01:10 +0100 | [diff] [blame] | 2052 | activate(shsurf->shell, shsurf->surface, seat, true); |
Derek Foreman | 74de469 | 2015-07-15 13:00:39 -0500 | [diff] [blame] | 2053 | surface_rotate(shsurf, pointer); |
Kristian Høgsberg | bbe9839 | 2012-08-01 00:20:21 -0400 | [diff] [blame] | 2054 | } |
Kristian Høgsberg | d56bd90 | 2012-06-05 09:58:51 -0400 | [diff] [blame] | 2055 | } |
| 2056 | |
Jonas Ådahl | 1ea343e | 2013-10-25 23:18:05 +0200 | [diff] [blame] | 2057 | static void |
| 2058 | busy_cursor_grab_cancel(struct weston_pointer_grab *base) |
| 2059 | { |
| 2060 | struct shell_grab *grab = (struct shell_grab *) base; |
| 2061 | |
| 2062 | shell_grab_end(grab); |
| 2063 | free(grab); |
| 2064 | } |
| 2065 | |
Kristian Høgsberg | 02bbabb | 2013-05-06 22:15:05 -0400 | [diff] [blame] | 2066 | static const struct weston_pointer_grab_interface busy_cursor_grab_interface = { |
Kristian Høgsberg | d56bd90 | 2012-06-05 09:58:51 -0400 | [diff] [blame] | 2067 | busy_cursor_grab_focus, |
| 2068 | busy_cursor_grab_motion, |
| 2069 | busy_cursor_grab_button, |
Jonas Ådahl | 1ea343e | 2013-10-25 23:18:05 +0200 | [diff] [blame] | 2070 | busy_cursor_grab_cancel, |
Kristian Høgsberg | d56bd90 | 2012-06-05 09:58:51 -0400 | [diff] [blame] | 2071 | }; |
| 2072 | |
| 2073 | static void |
Kristian Høgsberg | 02bbabb | 2013-05-06 22:15:05 -0400 | [diff] [blame] | 2074 | set_busy_cursor(struct shell_surface *shsurf, struct weston_pointer *pointer) |
Kristian Høgsberg | d56bd90 | 2012-06-05 09:58:51 -0400 | [diff] [blame] | 2075 | { |
| 2076 | struct shell_grab *grab; |
Kristian Høgsberg | d56bd90 | 2012-06-05 09:58:51 -0400 | [diff] [blame] | 2077 | |
Kristian Høgsberg | 2bff94e | 2014-02-11 12:22:51 -0800 | [diff] [blame] | 2078 | if (pointer->grab->interface == &busy_cursor_grab_interface) |
| 2079 | return; |
| 2080 | |
Kristian Høgsberg | d56bd90 | 2012-06-05 09:58:51 -0400 | [diff] [blame] | 2081 | grab = malloc(sizeof *grab); |
| 2082 | if (!grab) |
Scott Moreau | c3e54eb | 2012-04-17 19:06:20 -0600 | [diff] [blame] | 2083 | return; |
| 2084 | |
Ander Conselvan de Oliveira | b9d2a0f | 2012-06-28 18:08:05 +0300 | [diff] [blame] | 2085 | shell_grab_start(grab, &busy_cursor_grab_interface, shsurf, pointer, |
| 2086 | DESKTOP_SHELL_CURSOR_BUSY); |
Ander Conselvan de Oliveira | e5a1aee | 2014-04-09 17:39:39 +0300 | [diff] [blame] | 2087 | /* Mark the shsurf as ungrabbed so that button binding is able |
| 2088 | * to move it. */ |
| 2089 | shsurf->grabbed = 0; |
Kristian Høgsberg | d56bd90 | 2012-06-05 09:58:51 -0400 | [diff] [blame] | 2090 | } |
Scott Moreau | c3e54eb | 2012-04-17 19:06:20 -0600 | [diff] [blame] | 2091 | |
Kristian Høgsberg | d56bd90 | 2012-06-05 09:58:51 -0400 | [diff] [blame] | 2092 | static void |
Kristian Høgsberg | 2bff94e | 2014-02-11 12:22:51 -0800 | [diff] [blame] | 2093 | end_busy_cursor(struct weston_compositor *compositor, struct wl_client *client) |
Kristian Høgsberg | d56bd90 | 2012-06-05 09:58:51 -0400 | [diff] [blame] | 2094 | { |
Kristian Høgsberg | 2bff94e | 2014-02-11 12:22:51 -0800 | [diff] [blame] | 2095 | struct shell_grab *grab; |
| 2096 | struct weston_seat *seat; |
Kristian Høgsberg | d56bd90 | 2012-06-05 09:58:51 -0400 | [diff] [blame] | 2097 | |
Kristian Høgsberg | 2bff94e | 2014-02-11 12:22:51 -0800 | [diff] [blame] | 2098 | wl_list_for_each(seat, &compositor->seat_list, link) { |
| 2099 | if (seat->pointer == NULL) |
| 2100 | continue; |
| 2101 | |
| 2102 | grab = (struct shell_grab *) seat->pointer->grab; |
| 2103 | if (grab->grab.interface == &busy_cursor_grab_interface && |
| 2104 | wl_resource_get_client(grab->shsurf->resource) == client) { |
| 2105 | shell_grab_end(grab); |
| 2106 | free(grab); |
| 2107 | } |
Scott Moreau | c3e54eb | 2012-04-17 19:06:20 -0600 | [diff] [blame] | 2108 | } |
Scott Moreau | c3e54eb | 2012-04-17 19:06:20 -0600 | [diff] [blame] | 2109 | } |
| 2110 | |
Scott Moreau | 9521d5e | 2012-04-19 13:06:17 -0600 | [diff] [blame] | 2111 | static void |
Kristian Høgsberg | 2bff94e | 2014-02-11 12:22:51 -0800 | [diff] [blame] | 2112 | handle_shell_client_destroy(struct wl_listener *listener, void *data); |
| 2113 | |
| 2114 | static int |
| 2115 | xdg_ping_timeout_handler(void *data) |
| 2116 | { |
| 2117 | struct shell_client *sc = data; |
| 2118 | struct weston_seat *seat; |
| 2119 | struct shell_surface *shsurf; |
| 2120 | |
| 2121 | /* Client is not responding */ |
| 2122 | sc->unresponsive = 1; |
Kristian Høgsberg | 2bff94e | 2014-02-11 12:22:51 -0800 | [diff] [blame] | 2123 | wl_list_for_each(seat, &sc->shell->compositor->seat_list, link) { |
| 2124 | if (seat->pointer == NULL || seat->pointer->focus == NULL) |
| 2125 | continue; |
| 2126 | if (seat->pointer->focus->surface->resource == NULL) |
| 2127 | continue; |
Michael Vetter | 2a18a52 | 2015-05-15 17:17:47 +0200 | [diff] [blame] | 2128 | |
Kristian Høgsberg | 2bff94e | 2014-02-11 12:22:51 -0800 | [diff] [blame] | 2129 | shsurf = get_shell_surface(seat->pointer->focus->surface); |
| 2130 | if (shsurf && |
| 2131 | wl_resource_get_client(shsurf->resource) == sc->client) |
| 2132 | set_busy_cursor(shsurf, seat->pointer); |
| 2133 | } |
| 2134 | |
| 2135 | return 1; |
| 2136 | } |
| 2137 | |
| 2138 | static void |
| 2139 | handle_xdg_ping(struct shell_surface *shsurf, uint32_t serial) |
| 2140 | { |
| 2141 | struct weston_compositor *compositor = shsurf->shell->compositor; |
Jason Ekstrand | 9e9512f | 2014-04-16 21:12:10 -0500 | [diff] [blame] | 2142 | struct shell_client *sc = shsurf->owner; |
Kristian Høgsberg | 2bff94e | 2014-02-11 12:22:51 -0800 | [diff] [blame] | 2143 | struct wl_event_loop *loop; |
Kristian Høgsberg | dd62aba | 2014-02-12 09:56:19 -0800 | [diff] [blame] | 2144 | static const int ping_timeout = 200; |
Kristian Høgsberg | 2bff94e | 2014-02-11 12:22:51 -0800 | [diff] [blame] | 2145 | |
Kristian Høgsberg | 2bff94e | 2014-02-11 12:22:51 -0800 | [diff] [blame] | 2146 | if (sc->unresponsive) { |
| 2147 | xdg_ping_timeout_handler(sc); |
| 2148 | return; |
| 2149 | } |
| 2150 | |
| 2151 | sc->ping_serial = serial; |
| 2152 | loop = wl_display_get_event_loop(compositor->wl_display); |
| 2153 | if (sc->ping_timer == NULL) |
| 2154 | sc->ping_timer = |
| 2155 | wl_event_loop_add_timer(loop, |
| 2156 | xdg_ping_timeout_handler, sc); |
| 2157 | if (sc->ping_timer == NULL) |
| 2158 | return; |
| 2159 | |
| 2160 | wl_event_source_timer_update(sc->ping_timer, ping_timeout); |
| 2161 | |
Kristian Høgsberg | dd62aba | 2014-02-12 09:56:19 -0800 | [diff] [blame] | 2162 | if (shell_surface_is_xdg_surface(shsurf) || |
| 2163 | shell_surface_is_xdg_popup(shsurf)) |
| 2164 | xdg_shell_send_ping(sc->resource, serial); |
| 2165 | else if (shell_surface_is_wl_shell_surface(shsurf)) |
| 2166 | wl_shell_surface_send_ping(shsurf->resource, serial); |
Kristian Høgsberg | 2bff94e | 2014-02-11 12:22:51 -0800 | [diff] [blame] | 2167 | } |
| 2168 | |
Scott Moreau | ff1db4a | 2012-04-17 19:06:18 -0600 | [diff] [blame] | 2169 | static void |
| 2170 | ping_handler(struct weston_surface *surface, uint32_t serial) |
| 2171 | { |
Kristian Høgsberg | b71302e | 2012-05-10 12:28:35 -0400 | [diff] [blame] | 2172 | struct shell_surface *shsurf = get_shell_surface(surface); |
Scott Moreau | ff1db4a | 2012-04-17 19:06:18 -0600 | [diff] [blame] | 2173 | |
| 2174 | if (!shsurf) |
| 2175 | return; |
Jason Ekstrand | 651f00e | 2013-06-14 10:07:54 -0500 | [diff] [blame] | 2176 | if (!shsurf->resource) |
Kristian Høgsberg | ca535c1 | 2012-04-21 23:20:07 -0400 | [diff] [blame] | 2177 | return; |
Ander Conselvan de Oliveira | eac9a46 | 2012-07-16 14:15:48 +0300 | [diff] [blame] | 2178 | if (shsurf->surface == shsurf->shell->grab_surface) |
| 2179 | return; |
| 2180 | |
Kristian Høgsberg | dd62aba | 2014-02-12 09:56:19 -0800 | [diff] [blame] | 2181 | handle_xdg_ping(shsurf, serial); |
Scott Moreau | ff1db4a | 2012-04-17 19:06:18 -0600 | [diff] [blame] | 2182 | } |
| 2183 | |
| 2184 | static void |
Kristian Høgsberg | d56bd90 | 2012-06-05 09:58:51 -0400 | [diff] [blame] | 2185 | handle_pointer_focus(struct wl_listener *listener, void *data) |
| 2186 | { |
Kristian Høgsberg | 02bbabb | 2013-05-06 22:15:05 -0400 | [diff] [blame] | 2187 | struct weston_pointer *pointer = data; |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 2188 | struct weston_view *view = pointer->focus; |
Kristian Høgsberg | d56bd90 | 2012-06-05 09:58:51 -0400 | [diff] [blame] | 2189 | struct weston_compositor *compositor; |
Kristian Høgsberg | d56bd90 | 2012-06-05 09:58:51 -0400 | [diff] [blame] | 2190 | uint32_t serial; |
| 2191 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 2192 | if (!view) |
Kristian Høgsberg | d56bd90 | 2012-06-05 09:58:51 -0400 | [diff] [blame] | 2193 | return; |
| 2194 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 2195 | compositor = view->surface->compositor; |
Kristian Høgsberg | e11ef64 | 2014-02-11 16:35:22 -0800 | [diff] [blame] | 2196 | serial = wl_display_next_serial(compositor->wl_display); |
| 2197 | ping_handler(view->surface, serial); |
Kristian Høgsberg | d56bd90 | 2012-06-05 09:58:51 -0400 | [diff] [blame] | 2198 | } |
| 2199 | |
| 2200 | static void |
Jasper St. Pierre | faf27a9 | 2013-12-09 17:36:28 -0500 | [diff] [blame] | 2201 | shell_surface_lose_keyboard_focus(struct shell_surface *shsurf) |
| 2202 | { |
| 2203 | if (--shsurf->focus_count == 0) |
Jasper St. Pierre | 973d787 | 2014-05-06 08:44:29 -0400 | [diff] [blame] | 2204 | shell_surface_state_changed(shsurf); |
Jasper St. Pierre | faf27a9 | 2013-12-09 17:36:28 -0500 | [diff] [blame] | 2205 | } |
| 2206 | |
| 2207 | static void |
| 2208 | shell_surface_gain_keyboard_focus(struct shell_surface *shsurf) |
| 2209 | { |
| 2210 | if (shsurf->focus_count++ == 0) |
Jasper St. Pierre | 973d787 | 2014-05-06 08:44:29 -0400 | [diff] [blame] | 2211 | shell_surface_state_changed(shsurf); |
Jasper St. Pierre | faf27a9 | 2013-12-09 17:36:28 -0500 | [diff] [blame] | 2212 | } |
| 2213 | |
| 2214 | static void |
| 2215 | handle_keyboard_focus(struct wl_listener *listener, void *data) |
| 2216 | { |
| 2217 | struct weston_keyboard *keyboard = data; |
| 2218 | struct shell_seat *seat = get_shell_seat(keyboard->seat); |
| 2219 | |
| 2220 | if (seat->focused_surface) { |
| 2221 | struct shell_surface *shsurf = get_shell_surface(seat->focused_surface); |
| 2222 | if (shsurf) |
| 2223 | shell_surface_lose_keyboard_focus(shsurf); |
| 2224 | } |
| 2225 | |
| 2226 | seat->focused_surface = keyboard->focus; |
| 2227 | |
| 2228 | if (seat->focused_surface) { |
| 2229 | struct shell_surface *shsurf = get_shell_surface(seat->focused_surface); |
| 2230 | if (shsurf) |
| 2231 | shell_surface_gain_keyboard_focus(shsurf); |
| 2232 | } |
| 2233 | } |
| 2234 | |
| 2235 | static void |
Kristian Høgsberg | dd62aba | 2014-02-12 09:56:19 -0800 | [diff] [blame] | 2236 | shell_client_pong(struct shell_client *sc, uint32_t serial) |
Rafael Antognolli | e2a3455 | 2013-12-03 15:35:45 -0200 | [diff] [blame] | 2237 | { |
Kristian Høgsberg | dd62aba | 2014-02-12 09:56:19 -0800 | [diff] [blame] | 2238 | if (sc->ping_serial != serial) |
| 2239 | return; |
Rafael Antognolli | e2a3455 | 2013-12-03 15:35:45 -0200 | [diff] [blame] | 2240 | |
Kristian Høgsberg | dd62aba | 2014-02-12 09:56:19 -0800 | [diff] [blame] | 2241 | sc->unresponsive = 0; |
| 2242 | end_busy_cursor(sc->shell->compositor, sc->client); |
Rafael Antognolli | e2a3455 | 2013-12-03 15:35:45 -0200 | [diff] [blame] | 2243 | |
Kristian Høgsberg | dd62aba | 2014-02-12 09:56:19 -0800 | [diff] [blame] | 2244 | if (sc->ping_timer) { |
| 2245 | wl_event_source_remove(sc->ping_timer); |
| 2246 | sc->ping_timer = NULL; |
| 2247 | } |
| 2248 | |
| 2249 | } |
| 2250 | |
| 2251 | static void |
| 2252 | shell_surface_pong(struct wl_client *client, |
| 2253 | struct wl_resource *resource, uint32_t serial) |
| 2254 | { |
Jason Ekstrand | 9e9512f | 2014-04-16 21:12:10 -0500 | [diff] [blame] | 2255 | struct shell_surface *shsurf = wl_resource_get_user_data(resource); |
| 2256 | struct shell_client *sc = shsurf->owner; |
Kristian Høgsberg | dd62aba | 2014-02-12 09:56:19 -0800 | [diff] [blame] | 2257 | |
Kristian Høgsberg | dd62aba | 2014-02-12 09:56:19 -0800 | [diff] [blame] | 2258 | shell_client_pong(sc, serial); |
Rafael Antognolli | e2a3455 | 2013-12-03 15:35:45 -0200 | [diff] [blame] | 2259 | } |
| 2260 | |
| 2261 | static void |
Giulio Camuffo | 62942ad | 2013-09-11 18:20:47 +0200 | [diff] [blame] | 2262 | set_title(struct shell_surface *shsurf, const char *title) |
| 2263 | { |
| 2264 | free(shsurf->title); |
| 2265 | shsurf->title = strdup(title); |
Pekka Paalanen | b502654 | 2014-11-12 15:09:24 +0200 | [diff] [blame] | 2266 | shsurf->surface->timeline.force_refresh = 1; |
| 2267 | } |
| 2268 | |
| 2269 | static void |
Giulio Camuffo | a8e9b41 | 2015-01-27 19:10:37 +0200 | [diff] [blame] | 2270 | set_pid(struct shell_surface *shsurf, pid_t pid) |
| 2271 | { |
| 2272 | /* We have no use for it */ |
| 2273 | } |
| 2274 | |
| 2275 | static void |
Pekka Paalanen | b502654 | 2014-11-12 15:09:24 +0200 | [diff] [blame] | 2276 | set_type(struct shell_surface *shsurf, enum shell_surface_type t) |
| 2277 | { |
| 2278 | shsurf->type = t; |
| 2279 | shsurf->surface->timeline.force_refresh = 1; |
Giulio Camuffo | 62942ad | 2013-09-11 18:20:47 +0200 | [diff] [blame] | 2280 | } |
| 2281 | |
| 2282 | static void |
Jasper St. Pierre | ccf48fb | 2014-05-02 10:21:38 -0400 | [diff] [blame] | 2283 | set_window_geometry(struct shell_surface *shsurf, |
| 2284 | 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] | 2285 | { |
Jasper St. Pierre | ccf48fb | 2014-05-02 10:21:38 -0400 | [diff] [blame] | 2286 | shsurf->next_geometry.x = x; |
| 2287 | shsurf->next_geometry.y = y; |
| 2288 | shsurf->next_geometry.width = width; |
| 2289 | shsurf->next_geometry.height = height; |
| 2290 | shsurf->has_next_geometry = true; |
Kristian Høgsberg | e5c1ae9 | 2014-04-30 16:28:41 -0700 | [diff] [blame] | 2291 | } |
| 2292 | |
| 2293 | static void |
Kristian Høgsberg | e7afd91 | 2012-05-02 09:47:44 -0400 | [diff] [blame] | 2294 | shell_surface_set_title(struct wl_client *client, |
| 2295 | struct wl_resource *resource, const char *title) |
| 2296 | { |
Jason Ekstrand | 651f00e | 2013-06-14 10:07:54 -0500 | [diff] [blame] | 2297 | struct shell_surface *shsurf = wl_resource_get_user_data(resource); |
Kristian Høgsberg | e7afd91 | 2012-05-02 09:47:44 -0400 | [diff] [blame] | 2298 | |
Giulio Camuffo | 62942ad | 2013-09-11 18:20:47 +0200 | [diff] [blame] | 2299 | set_title(shsurf, title); |
Kristian Høgsberg | e7afd91 | 2012-05-02 09:47:44 -0400 | [diff] [blame] | 2300 | } |
| 2301 | |
| 2302 | static void |
| 2303 | shell_surface_set_class(struct wl_client *client, |
| 2304 | struct wl_resource *resource, const char *class) |
| 2305 | { |
Jason Ekstrand | 651f00e | 2013-06-14 10:07:54 -0500 | [diff] [blame] | 2306 | struct shell_surface *shsurf = wl_resource_get_user_data(resource); |
Kristian Høgsberg | e7afd91 | 2012-05-02 09:47:44 -0400 | [diff] [blame] | 2307 | |
| 2308 | free(shsurf->class); |
| 2309 | shsurf->class = strdup(class); |
Pekka Paalanen | b502654 | 2014-11-12 15:09:24 +0200 | [diff] [blame] | 2310 | shsurf->surface->timeline.force_refresh = 1; |
Kristian Høgsberg | e7afd91 | 2012-05-02 09:47:44 -0400 | [diff] [blame] | 2311 | } |
| 2312 | |
Alex Wu | 4539b08 | 2012-03-01 12:57:46 +0800 | [diff] [blame] | 2313 | static void |
Alexander Larsson | f82b6ca | 2013-05-28 16:23:39 +0200 | [diff] [blame] | 2314 | restore_output_mode(struct weston_output *output) |
| 2315 | { |
Derek Foreman | 6ae7bc9 | 2014-11-04 10:47:33 -0600 | [diff] [blame] | 2316 | if (output->original_mode) |
| 2317 | weston_output_mode_switch_to_native(output); |
Alexander Larsson | f82b6ca | 2013-05-28 16:23:39 +0200 | [diff] [blame] | 2318 | } |
| 2319 | |
| 2320 | static void |
| 2321 | restore_all_output_modes(struct weston_compositor *compositor) |
| 2322 | { |
| 2323 | struct weston_output *output; |
| 2324 | |
| 2325 | wl_list_for_each(output, &compositor->output_list, link) |
| 2326 | restore_output_mode(output); |
| 2327 | } |
| 2328 | |
Philip Withnall | 07926d9 | 2013-11-25 18:01:40 +0000 | [diff] [blame] | 2329 | /* The surface will be inserted into the list immediately after the link |
| 2330 | * returned by this function (i.e. will be stacked immediately above the |
| 2331 | * returned link). */ |
Giulio Camuffo | 412e6a5 | 2014-07-09 22:12:56 +0300 | [diff] [blame] | 2332 | static struct weston_layer_entry * |
Philip Withnall | 07926d9 | 2013-11-25 18:01:40 +0000 | [diff] [blame] | 2333 | shell_surface_calculate_layer_link (struct shell_surface *shsurf) |
| 2334 | { |
| 2335 | struct workspace *ws; |
Kristian Høgsberg | ead5242 | 2014-01-01 13:51:52 -0800 | [diff] [blame] | 2336 | struct weston_view *parent; |
Philip Withnall | 07926d9 | 2013-11-25 18:01:40 +0000 | [diff] [blame] | 2337 | |
| 2338 | switch (shsurf->type) { |
Ander Conselvan de Oliveira | ef6a7e4 | 2014-04-30 14:15:14 +0300 | [diff] [blame] | 2339 | case SHELL_SURFACE_XWAYLAND: |
| 2340 | return &shsurf->shell->fullscreen_layer.view_list; |
| 2341 | |
| 2342 | case SHELL_SURFACE_NONE: |
| 2343 | return NULL; |
| 2344 | |
Kristian Høgsberg | ead5242 | 2014-01-01 13:51:52 -0800 | [diff] [blame] | 2345 | case SHELL_SURFACE_POPUP: |
| 2346 | case SHELL_SURFACE_TOPLEVEL: |
Emilio Pozuelo Monfort | 9e7c759 | 2014-01-30 14:01:10 +0100 | [diff] [blame] | 2347 | if (shsurf->state.fullscreen && !shsurf->state.lowered) { |
Rafael Antognolli | 03b1659 | 2013-12-03 15:35:42 -0200 | [diff] [blame] | 2348 | return &shsurf->shell->fullscreen_layer.view_list; |
Rafael Antognolli | ed207b4 | 2013-12-03 15:35:43 -0200 | [diff] [blame] | 2349 | } else if (shsurf->parent) { |
Kristian Høgsberg | d55db69 | 2014-01-01 12:26:14 -0800 | [diff] [blame] | 2350 | /* Move the surface to its parent layer so |
| 2351 | * that surfaces which are transient for |
| 2352 | * fullscreen surfaces don't get hidden by the |
| 2353 | * fullscreen surfaces. */ |
Rafael Antognolli | ed207b4 | 2013-12-03 15:35:43 -0200 | [diff] [blame] | 2354 | |
| 2355 | /* TODO: Handle a parent with multiple views */ |
| 2356 | parent = get_default_view(shsurf->parent); |
| 2357 | if (parent) |
Giulio Camuffo | 412e6a5 | 2014-07-09 22:12:56 +0300 | [diff] [blame] | 2358 | return container_of(parent->layer_link.link.prev, |
| 2359 | struct weston_layer_entry, link); |
Rafael Antognolli | ed207b4 | 2013-12-03 15:35:43 -0200 | [diff] [blame] | 2360 | } |
Philip Withnall | 07926d9 | 2013-11-25 18:01:40 +0000 | [diff] [blame] | 2361 | |
Ander Conselvan de Oliveira | ef6a7e4 | 2014-04-30 14:15:14 +0300 | [diff] [blame] | 2362 | /* Move the surface to a normal workspace layer so that surfaces |
| 2363 | * which were previously fullscreen or transient are no longer |
| 2364 | * rendered on top. */ |
| 2365 | ws = get_current_workspace(shsurf->shell); |
| 2366 | return &ws->layer.view_list; |
Philip Withnall | 07926d9 | 2013-11-25 18:01:40 +0000 | [diff] [blame] | 2367 | } |
| 2368 | |
Ander Conselvan de Oliveira | ef6a7e4 | 2014-04-30 14:15:14 +0300 | [diff] [blame] | 2369 | assert(0 && "Unknown shell surface type"); |
Philip Withnall | 07926d9 | 2013-11-25 18:01:40 +0000 | [diff] [blame] | 2370 | } |
| 2371 | |
Philip Withnall | 648a4dd | 2013-11-25 18:01:44 +0000 | [diff] [blame] | 2372 | static void |
| 2373 | shell_surface_update_child_surface_layers (struct shell_surface *shsurf) |
| 2374 | { |
| 2375 | struct shell_surface *child; |
Giulio Camuffo | 412e6a5 | 2014-07-09 22:12:56 +0300 | [diff] [blame] | 2376 | struct weston_layer_entry *prev; |
Philip Withnall | 648a4dd | 2013-11-25 18:01:44 +0000 | [diff] [blame] | 2377 | |
| 2378 | /* Move the child layers to the same workspace as shsurf. They will be |
| 2379 | * stacked above shsurf. */ |
| 2380 | wl_list_for_each_reverse(child, &shsurf->children_list, children_link) { |
Giulio Camuffo | 412e6a5 | 2014-07-09 22:12:56 +0300 | [diff] [blame] | 2381 | 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] | 2382 | weston_view_damage_below(child->view); |
Philip Withnall | 648a4dd | 2013-11-25 18:01:44 +0000 | [diff] [blame] | 2383 | weston_view_geometry_dirty(child->view); |
Giulio Camuffo | 412e6a5 | 2014-07-09 22:12:56 +0300 | [diff] [blame] | 2384 | prev = container_of(shsurf->view->layer_link.link.prev, |
| 2385 | struct weston_layer_entry, link); |
| 2386 | weston_layer_entry_remove(&child->view->layer_link); |
| 2387 | weston_layer_entry_insert(prev, |
| 2388 | &child->view->layer_link); |
Philip Withnall | 648a4dd | 2013-11-25 18:01:44 +0000 | [diff] [blame] | 2389 | weston_view_geometry_dirty(child->view); |
| 2390 | weston_surface_damage(child->surface); |
| 2391 | |
| 2392 | /* Recurse. We don’t expect this to recurse very far (if |
| 2393 | * at all) because that would imply we have transient |
| 2394 | * (or popup) children of transient surfaces, which |
| 2395 | * would be unusual. */ |
| 2396 | shell_surface_update_child_surface_layers(child); |
| 2397 | } |
| 2398 | } |
| 2399 | } |
| 2400 | |
Philip Withnall | e1d75ae | 2013-11-25 18:01:41 +0000 | [diff] [blame] | 2401 | /* 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] | 2402 | * geometry to ensure the changes are redrawn. |
| 2403 | * |
| 2404 | * If any child surfaces exist and are mapped, ensure they’re in the same layer |
| 2405 | * as this surface. */ |
Philip Withnall | e1d75ae | 2013-11-25 18:01:41 +0000 | [diff] [blame] | 2406 | static void |
| 2407 | shell_surface_update_layer(struct shell_surface *shsurf) |
| 2408 | { |
Giulio Camuffo | 412e6a5 | 2014-07-09 22:12:56 +0300 | [diff] [blame] | 2409 | struct weston_layer_entry *new_layer_link; |
Philip Withnall | e1d75ae | 2013-11-25 18:01:41 +0000 | [diff] [blame] | 2410 | |
| 2411 | new_layer_link = shell_surface_calculate_layer_link(shsurf); |
| 2412 | |
Ander Conselvan de Oliveira | ef6a7e4 | 2014-04-30 14:15:14 +0300 | [diff] [blame] | 2413 | if (new_layer_link == NULL) |
| 2414 | return; |
Philip Withnall | e1d75ae | 2013-11-25 18:01:41 +0000 | [diff] [blame] | 2415 | if (new_layer_link == &shsurf->view->layer_link) |
| 2416 | return; |
| 2417 | |
| 2418 | weston_view_geometry_dirty(shsurf->view); |
Giulio Camuffo | 412e6a5 | 2014-07-09 22:12:56 +0300 | [diff] [blame] | 2419 | weston_layer_entry_remove(&shsurf->view->layer_link); |
| 2420 | weston_layer_entry_insert(new_layer_link, &shsurf->view->layer_link); |
Philip Withnall | e1d75ae | 2013-11-25 18:01:41 +0000 | [diff] [blame] | 2421 | weston_view_geometry_dirty(shsurf->view); |
| 2422 | weston_surface_damage(shsurf->surface); |
Philip Withnall | 648a4dd | 2013-11-25 18:01:44 +0000 | [diff] [blame] | 2423 | |
| 2424 | shell_surface_update_child_surface_layers(shsurf); |
Philip Withnall | e1d75ae | 2013-11-25 18:01:41 +0000 | [diff] [blame] | 2425 | } |
| 2426 | |
Alexander Larsson | f82b6ca | 2013-05-28 16:23:39 +0200 | [diff] [blame] | 2427 | static void |
Philip Withnall | dc4332f | 2013-11-25 18:01:38 +0000 | [diff] [blame] | 2428 | shell_surface_set_parent(struct shell_surface *shsurf, |
| 2429 | struct weston_surface *parent) |
| 2430 | { |
| 2431 | shsurf->parent = parent; |
Philip Withnall | 648a4dd | 2013-11-25 18:01:44 +0000 | [diff] [blame] | 2432 | |
| 2433 | wl_list_remove(&shsurf->children_link); |
| 2434 | wl_list_init(&shsurf->children_link); |
| 2435 | |
| 2436 | /* Insert into the parent surface’s child list. */ |
| 2437 | if (parent != NULL) { |
| 2438 | struct shell_surface *parent_shsurf = get_shell_surface(parent); |
| 2439 | if (parent_shsurf != NULL) |
| 2440 | wl_list_insert(&parent_shsurf->children_list, |
| 2441 | &shsurf->children_link); |
| 2442 | } |
Philip Withnall | dc4332f | 2013-11-25 18:01:38 +0000 | [diff] [blame] | 2443 | } |
| 2444 | |
| 2445 | static void |
Philip Withnall | 352e7ed | 2013-11-25 18:01:35 +0000 | [diff] [blame] | 2446 | shell_surface_set_output(struct shell_surface *shsurf, |
| 2447 | struct weston_output *output) |
| 2448 | { |
| 2449 | struct weston_surface *es = shsurf->surface; |
| 2450 | |
| 2451 | /* get the default output, if the client set it as NULL |
| 2452 | check whether the ouput is available */ |
| 2453 | if (output) |
| 2454 | shsurf->output = output; |
| 2455 | else if (es->output) |
| 2456 | shsurf->output = es->output; |
| 2457 | else |
| 2458 | shsurf->output = get_default_output(es->compositor); |
| 2459 | } |
| 2460 | |
| 2461 | static void |
Rafael Antognolli | 03b1659 | 2013-12-03 15:35:42 -0200 | [diff] [blame] | 2462 | surface_clear_next_states(struct shell_surface *shsurf) |
| 2463 | { |
| 2464 | shsurf->next_state.maximized = false; |
| 2465 | shsurf->next_state.fullscreen = false; |
| 2466 | |
| 2467 | if ((shsurf->next_state.maximized != shsurf->state.maximized) || |
| 2468 | (shsurf->next_state.fullscreen != shsurf->state.fullscreen)) |
| 2469 | shsurf->state_changed = true; |
| 2470 | } |
| 2471 | |
| 2472 | static void |
Philip Withnall | becb77e | 2013-11-25 18:01:30 +0000 | [diff] [blame] | 2473 | set_toplevel(struct shell_surface *shsurf) |
| 2474 | { |
Kristian Høgsberg | 41fbf6f | 2013-12-05 22:31:25 -0800 | [diff] [blame] | 2475 | shell_surface_set_parent(shsurf, NULL); |
| 2476 | surface_clear_next_states(shsurf); |
Pekka Paalanen | b502654 | 2014-11-12 15:09:24 +0200 | [diff] [blame] | 2477 | set_type(shsurf, SHELL_SURFACE_TOPLEVEL); |
Philip Withnall | 648a4dd | 2013-11-25 18:01:44 +0000 | [diff] [blame] | 2478 | |
| 2479 | /* The layer_link is updated in set_surface_type(), |
| 2480 | * called from configure. */ |
Philip Withnall | becb77e | 2013-11-25 18:01:30 +0000 | [diff] [blame] | 2481 | } |
| 2482 | |
| 2483 | static void |
| 2484 | shell_surface_set_toplevel(struct wl_client *client, |
| 2485 | struct wl_resource *resource) |
| 2486 | { |
| 2487 | struct shell_surface *surface = wl_resource_get_user_data(resource); |
| 2488 | |
| 2489 | set_toplevel(surface); |
| 2490 | } |
| 2491 | |
| 2492 | static void |
| 2493 | set_transient(struct shell_surface *shsurf, |
| 2494 | struct weston_surface *parent, int x, int y, uint32_t flags) |
| 2495 | { |
Philip Withnall | dc4332f | 2013-11-25 18:01:38 +0000 | [diff] [blame] | 2496 | assert(parent != NULL); |
| 2497 | |
Kristian Høgsberg | 9f7e331 | 2014-01-02 22:40:37 -0800 | [diff] [blame] | 2498 | shell_surface_set_parent(shsurf, parent); |
| 2499 | |
| 2500 | surface_clear_next_states(shsurf); |
| 2501 | |
Philip Withnall | becb77e | 2013-11-25 18:01:30 +0000 | [diff] [blame] | 2502 | shsurf->transient.x = x; |
| 2503 | shsurf->transient.y = y; |
| 2504 | shsurf->transient.flags = flags; |
Philip Withnall | dc4332f | 2013-11-25 18:01:38 +0000 | [diff] [blame] | 2505 | |
Rafael Antognolli | ed207b4 | 2013-12-03 15:35:43 -0200 | [diff] [blame] | 2506 | shsurf->next_state.relative = true; |
Kristian Høgsberg | a1df7ac | 2013-12-31 15:01:01 -0800 | [diff] [blame] | 2507 | shsurf->state_changed = true; |
Pekka Paalanen | b502654 | 2014-11-12 15:09:24 +0200 | [diff] [blame] | 2508 | set_type(shsurf, SHELL_SURFACE_TOPLEVEL); |
Philip Withnall | 648a4dd | 2013-11-25 18:01:44 +0000 | [diff] [blame] | 2509 | |
| 2510 | /* The layer_link is updated in set_surface_type(), |
| 2511 | * called from configure. */ |
Philip Withnall | becb77e | 2013-11-25 18:01:30 +0000 | [diff] [blame] | 2512 | } |
| 2513 | |
| 2514 | static void |
| 2515 | shell_surface_set_transient(struct wl_client *client, |
| 2516 | struct wl_resource *resource, |
| 2517 | struct wl_resource *parent_resource, |
| 2518 | int x, int y, uint32_t flags) |
| 2519 | { |
| 2520 | struct shell_surface *shsurf = wl_resource_get_user_data(resource); |
| 2521 | struct weston_surface *parent = |
| 2522 | wl_resource_get_user_data(parent_resource); |
| 2523 | |
| 2524 | set_transient(shsurf, parent, x, y, flags); |
| 2525 | } |
| 2526 | |
| 2527 | static void |
| 2528 | set_fullscreen(struct shell_surface *shsurf, |
| 2529 | uint32_t method, |
| 2530 | uint32_t framerate, |
| 2531 | struct weston_output *output) |
| 2532 | { |
Philip Withnall | 352e7ed | 2013-11-25 18:01:35 +0000 | [diff] [blame] | 2533 | shell_surface_set_output(shsurf, output); |
Pekka Paalanen | b502654 | 2014-11-12 15:09:24 +0200 | [diff] [blame] | 2534 | set_type(shsurf, SHELL_SURFACE_TOPLEVEL); |
Philip Withnall | becb77e | 2013-11-25 18:01:30 +0000 | [diff] [blame] | 2535 | |
| 2536 | shsurf->fullscreen_output = shsurf->output; |
| 2537 | shsurf->fullscreen.type = method; |
| 2538 | shsurf->fullscreen.framerate = framerate; |
Philip Withnall | dc4332f | 2013-11-25 18:01:38 +0000 | [diff] [blame] | 2539 | |
Jasper St. Pierre | 6458ec3 | 2014-04-11 16:00:31 -0700 | [diff] [blame] | 2540 | send_configure_for_surface(shsurf); |
Philip Withnall | becb77e | 2013-11-25 18:01:30 +0000 | [diff] [blame] | 2541 | } |
| 2542 | |
| 2543 | static void |
Zhang, Xiong Y | 3123693 | 2013-12-13 22:10:57 +0200 | [diff] [blame] | 2544 | weston_view_set_initial_position(struct weston_view *view, |
| 2545 | struct desktop_shell *shell); |
| 2546 | |
| 2547 | static void |
Philip Withnall | becb77e | 2013-11-25 18:01:30 +0000 | [diff] [blame] | 2548 | unset_fullscreen(struct shell_surface *shsurf) |
Alex Wu | 4539b08 | 2012-03-01 12:57:46 +0800 | [diff] [blame] | 2549 | { |
Philip Withnall | f85fe84 | 2013-11-25 18:01:37 +0000 | [diff] [blame] | 2550 | /* Unset the fullscreen output, driver configuration and transforms. */ |
Alex Wu | bd3354b | 2012-04-17 17:20:49 +0800 | [diff] [blame] | 2551 | if (shsurf->fullscreen.type == WL_SHELL_SURFACE_FULLSCREEN_METHOD_DRIVER && |
| 2552 | shell_surface_is_top_fullscreen(shsurf)) { |
Alexander Larsson | f82b6ca | 2013-05-28 16:23:39 +0200 | [diff] [blame] | 2553 | restore_output_mode(shsurf->fullscreen_output); |
Alex Wu | bd3354b | 2012-04-17 17:20:49 +0800 | [diff] [blame] | 2554 | } |
Philip Withnall | f85fe84 | 2013-11-25 18:01:37 +0000 | [diff] [blame] | 2555 | |
Alex Wu | 4539b08 | 2012-03-01 12:57:46 +0800 | [diff] [blame] | 2556 | shsurf->fullscreen.type = WL_SHELL_SURFACE_FULLSCREEN_METHOD_DEFAULT; |
| 2557 | shsurf->fullscreen.framerate = 0; |
Philip Withnall | f85fe84 | 2013-11-25 18:01:37 +0000 | [diff] [blame] | 2558 | |
Alex Wu | 4539b08 | 2012-03-01 12:57:46 +0800 | [diff] [blame] | 2559 | wl_list_remove(&shsurf->fullscreen.transform.link); |
| 2560 | wl_list_init(&shsurf->fullscreen.transform.link); |
Philip Withnall | f85fe84 | 2013-11-25 18:01:37 +0000 | [diff] [blame] | 2561 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 2562 | if (shsurf->fullscreen.black_view) |
| 2563 | weston_surface_destroy(shsurf->fullscreen.black_view->surface); |
| 2564 | shsurf->fullscreen.black_view = NULL; |
Philip Withnall | f85fe84 | 2013-11-25 18:01:37 +0000 | [diff] [blame] | 2565 | |
Zhang, Xiong Y | 3123693 | 2013-12-13 22:10:57 +0200 | [diff] [blame] | 2566 | if (shsurf->saved_position_valid) |
| 2567 | weston_view_set_position(shsurf->view, |
| 2568 | shsurf->saved_x, shsurf->saved_y); |
| 2569 | else |
| 2570 | weston_view_set_initial_position(shsurf->view, shsurf->shell); |
| 2571 | |
Alex Wu | 7bcb8bd | 2012-04-27 09:07:24 +0800 | [diff] [blame] | 2572 | if (shsurf->saved_rotation_valid) { |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 2573 | wl_list_insert(&shsurf->view->geometry.transformation_list, |
Philip Withnall | becb77e | 2013-11-25 18:01:30 +0000 | [diff] [blame] | 2574 | &shsurf->rotation.transform.link); |
Alex Wu | 7bcb8bd | 2012-04-27 09:07:24 +0800 | [diff] [blame] | 2575 | shsurf->saved_rotation_valid = false; |
| 2576 | } |
Rafal Mielniczuk | 3e3862c | 2012-10-07 20:25:36 +0200 | [diff] [blame] | 2577 | |
Philip Withnall | e1d75ae | 2013-11-25 18:01:41 +0000 | [diff] [blame] | 2578 | /* Layer is updated in set_surface_type(). */ |
Alex Wu | 4539b08 | 2012-03-01 12:57:46 +0800 | [diff] [blame] | 2579 | } |
| 2580 | |
Rafal Mielniczuk | fffdcdd | 2013-03-11 19:26:54 +0100 | [diff] [blame] | 2581 | static void |
Philip Withnall | becb77e | 2013-11-25 18:01:30 +0000 | [diff] [blame] | 2582 | shell_surface_set_fullscreen(struct wl_client *client, |
| 2583 | struct wl_resource *resource, |
| 2584 | uint32_t method, |
| 2585 | uint32_t framerate, |
| 2586 | struct wl_resource *output_resource) |
| 2587 | { |
| 2588 | struct shell_surface *shsurf = wl_resource_get_user_data(resource); |
| 2589 | struct weston_output *output; |
| 2590 | |
| 2591 | if (output_resource) |
| 2592 | output = wl_resource_get_user_data(output_resource); |
| 2593 | else |
| 2594 | output = NULL; |
| 2595 | |
Rafael Antognolli | 4b99a40 | 2013-12-03 15:35:44 -0200 | [diff] [blame] | 2596 | shell_surface_set_parent(shsurf, NULL); |
| 2597 | |
Rafael Antognolli | 03b1659 | 2013-12-03 15:35:42 -0200 | [diff] [blame] | 2598 | surface_clear_next_states(shsurf); |
Jasper St. Pierre | 8c6aa45 | 2014-02-08 18:29:49 -0500 | [diff] [blame] | 2599 | shsurf->next_state.fullscreen = true; |
| 2600 | shsurf->state_changed = true; |
Jasper St. Pierre | 6458ec3 | 2014-04-11 16:00:31 -0700 | [diff] [blame] | 2601 | set_fullscreen(shsurf, method, framerate, output); |
Philip Withnall | becb77e | 2013-11-25 18:01:30 +0000 | [diff] [blame] | 2602 | } |
| 2603 | |
| 2604 | static void |
| 2605 | set_popup(struct shell_surface *shsurf, |
| 2606 | struct weston_surface *parent, |
| 2607 | struct weston_seat *seat, |
| 2608 | uint32_t serial, |
| 2609 | int32_t x, |
| 2610 | int32_t y) |
| 2611 | { |
Philip Withnall | dc4332f | 2013-11-25 18:01:38 +0000 | [diff] [blame] | 2612 | assert(parent != NULL); |
| 2613 | |
Philip Withnall | becb77e | 2013-11-25 18:01:30 +0000 | [diff] [blame] | 2614 | shsurf->popup.shseat = get_shell_seat(seat); |
| 2615 | shsurf->popup.serial = serial; |
| 2616 | shsurf->popup.x = x; |
| 2617 | shsurf->popup.y = y; |
Philip Withnall | dc4332f | 2013-11-25 18:01:38 +0000 | [diff] [blame] | 2618 | |
Pekka Paalanen | b502654 | 2014-11-12 15:09:24 +0200 | [diff] [blame] | 2619 | set_type(shsurf, SHELL_SURFACE_POPUP); |
Philip Withnall | becb77e | 2013-11-25 18:01:30 +0000 | [diff] [blame] | 2620 | } |
| 2621 | |
| 2622 | static void |
| 2623 | shell_surface_set_popup(struct wl_client *client, |
| 2624 | struct wl_resource *resource, |
| 2625 | struct wl_resource *seat_resource, |
| 2626 | uint32_t serial, |
| 2627 | struct wl_resource *parent_resource, |
| 2628 | int32_t x, int32_t y, uint32_t flags) |
| 2629 | { |
| 2630 | struct shell_surface *shsurf = wl_resource_get_user_data(resource); |
Rafael Antognolli | 4b99a40 | 2013-12-03 15:35:44 -0200 | [diff] [blame] | 2631 | struct weston_surface *parent = |
| 2632 | wl_resource_get_user_data(parent_resource); |
| 2633 | |
| 2634 | shell_surface_set_parent(shsurf, parent); |
Philip Withnall | becb77e | 2013-11-25 18:01:30 +0000 | [diff] [blame] | 2635 | |
Rafael Antognolli | 03b1659 | 2013-12-03 15:35:42 -0200 | [diff] [blame] | 2636 | surface_clear_next_states(shsurf); |
Philip Withnall | becb77e | 2013-11-25 18:01:30 +0000 | [diff] [blame] | 2637 | set_popup(shsurf, |
Rafael Antognolli | 4b99a40 | 2013-12-03 15:35:44 -0200 | [diff] [blame] | 2638 | parent, |
Philip Withnall | becb77e | 2013-11-25 18:01:30 +0000 | [diff] [blame] | 2639 | wl_resource_get_user_data(seat_resource), |
| 2640 | serial, x, y); |
| 2641 | } |
| 2642 | |
| 2643 | static void |
Philip Withnall | becb77e | 2013-11-25 18:01:30 +0000 | [diff] [blame] | 2644 | unset_maximized(struct shell_surface *shsurf) |
Rafal Mielniczuk | fffdcdd | 2013-03-11 19:26:54 +0100 | [diff] [blame] | 2645 | { |
Rafal Mielniczuk | fffdcdd | 2013-03-11 19:26:54 +0100 | [diff] [blame] | 2646 | /* undo all maximized things here */ |
| 2647 | shsurf->output = get_default_output(shsurf->surface->compositor); |
Zhang, Xiong Y | 3123693 | 2013-12-13 22:10:57 +0200 | [diff] [blame] | 2648 | |
| 2649 | if (shsurf->saved_position_valid) |
| 2650 | weston_view_set_position(shsurf->view, |
| 2651 | shsurf->saved_x, shsurf->saved_y); |
| 2652 | else |
| 2653 | weston_view_set_initial_position(shsurf->view, shsurf->shell); |
Rafal Mielniczuk | fffdcdd | 2013-03-11 19:26:54 +0100 | [diff] [blame] | 2654 | |
| 2655 | if (shsurf->saved_rotation_valid) { |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 2656 | wl_list_insert(&shsurf->view->geometry.transformation_list, |
| 2657 | &shsurf->rotation.transform.link); |
Rafal Mielniczuk | fffdcdd | 2013-03-11 19:26:54 +0100 | [diff] [blame] | 2658 | shsurf->saved_rotation_valid = false; |
| 2659 | } |
| 2660 | |
Philip Withnall | e1d75ae | 2013-11-25 18:01:41 +0000 | [diff] [blame] | 2661 | /* Layer is updated in set_surface_type(). */ |
Rafal Mielniczuk | fffdcdd | 2013-03-11 19:26:54 +0100 | [diff] [blame] | 2662 | } |
| 2663 | |
Philip Withnall | becb77e | 2013-11-25 18:01:30 +0000 | [diff] [blame] | 2664 | static void |
Manuel Bachmann | dc1c3e4 | 2015-02-16 11:52:13 +0100 | [diff] [blame] | 2665 | set_minimized(struct weston_surface *surface) |
Manuel Bachmann | 50c87db | 2014-02-26 15:52:13 +0100 | [diff] [blame] | 2666 | { |
| 2667 | struct shell_surface *shsurf; |
| 2668 | struct workspace *current_ws; |
| 2669 | struct weston_seat *seat; |
| 2670 | struct weston_surface *focus; |
| 2671 | struct weston_view *view; |
| 2672 | |
| 2673 | view = get_default_view(surface); |
| 2674 | if (!view) |
| 2675 | return; |
| 2676 | |
| 2677 | assert(weston_surface_get_main_surface(view->surface) == view->surface); |
| 2678 | |
| 2679 | shsurf = get_shell_surface(surface); |
| 2680 | current_ws = get_current_workspace(shsurf->shell); |
| 2681 | |
Giulio Camuffo | 412e6a5 | 2014-07-09 22:12:56 +0300 | [diff] [blame] | 2682 | weston_layer_entry_remove(&view->layer_link); |
Manuel Bachmann | dc1c3e4 | 2015-02-16 11:52:13 +0100 | [diff] [blame] | 2683 | 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] | 2684 | |
Manuel Bachmann | dc1c3e4 | 2015-02-16 11:52:13 +0100 | [diff] [blame] | 2685 | drop_focus_state(shsurf->shell, current_ws, view->surface); |
| 2686 | wl_list_for_each(seat, &shsurf->shell->compositor->seat_list, link) { |
| 2687 | if (!seat->keyboard) |
| 2688 | continue; |
| 2689 | focus = weston_surface_get_main_surface(seat->keyboard->focus); |
| 2690 | if (focus == view->surface) |
| 2691 | weston_keyboard_set_focus(seat->keyboard, NULL); |
Manuel Bachmann | 50c87db | 2014-02-26 15:52:13 +0100 | [diff] [blame] | 2692 | } |
| 2693 | |
| 2694 | shell_surface_update_child_surface_layers(shsurf); |
Manuel Bachmann | 50c87db | 2014-02-26 15:52:13 +0100 | [diff] [blame] | 2695 | weston_view_damage_below(view); |
| 2696 | } |
| 2697 | |
| 2698 | static void |
Philip Withnall | becb77e | 2013-11-25 18:01:30 +0000 | [diff] [blame] | 2699 | shell_surface_set_maximized(struct wl_client *client, |
| 2700 | struct wl_resource *resource, |
| 2701 | struct wl_resource *output_resource) |
| 2702 | { |
| 2703 | struct shell_surface *shsurf = wl_resource_get_user_data(resource); |
| 2704 | struct weston_output *output; |
| 2705 | |
Jasper St. Pierre | 9aa8ce6 | 2014-04-11 16:18:54 -0700 | [diff] [blame] | 2706 | surface_clear_next_states(shsurf); |
| 2707 | shsurf->next_state.maximized = true; |
| 2708 | shsurf->state_changed = true; |
| 2709 | |
Pekka Paalanen | b502654 | 2014-11-12 15:09:24 +0200 | [diff] [blame] | 2710 | set_type(shsurf, SHELL_SURFACE_TOPLEVEL); |
Jasper St. Pierre | 9aa8ce6 | 2014-04-11 16:18:54 -0700 | [diff] [blame] | 2711 | shell_surface_set_parent(shsurf, NULL); |
| 2712 | |
Philip Withnall | becb77e | 2013-11-25 18:01:30 +0000 | [diff] [blame] | 2713 | if (output_resource) |
| 2714 | output = wl_resource_get_user_data(output_resource); |
| 2715 | else |
| 2716 | output = NULL; |
| 2717 | |
Jasper St. Pierre | 9aa8ce6 | 2014-04-11 16:18:54 -0700 | [diff] [blame] | 2718 | shell_surface_set_output(shsurf, output); |
Rafael Antognolli | 4b99a40 | 2013-12-03 15:35:44 -0200 | [diff] [blame] | 2719 | |
Jasper St. Pierre | 9aa8ce6 | 2014-04-11 16:18:54 -0700 | [diff] [blame] | 2720 | send_configure_for_surface(shsurf); |
Philip Withnall | becb77e | 2013-11-25 18:01:30 +0000 | [diff] [blame] | 2721 | } |
| 2722 | |
Philip Withnall | e1d75ae | 2013-11-25 18:01:41 +0000 | [diff] [blame] | 2723 | /* This is only ever called from set_surface_type(), so there’s no need to |
| 2724 | * update layer_links here, since they’ll be updated when we return. */ |
Pekka Paalanen | 9826223 | 2011-12-01 10:42:22 +0200 | [diff] [blame] | 2725 | static int |
Philip Withnall | becb77e | 2013-11-25 18:01:30 +0000 | [diff] [blame] | 2726 | reset_surface_type(struct shell_surface *surface) |
Pekka Paalanen | 9826223 | 2011-12-01 10:42:22 +0200 | [diff] [blame] | 2727 | { |
Rafael Antognolli | 03b1659 | 2013-12-03 15:35:42 -0200 | [diff] [blame] | 2728 | if (surface->state.fullscreen) |
Philip Withnall | becb77e | 2013-11-25 18:01:30 +0000 | [diff] [blame] | 2729 | unset_fullscreen(surface); |
Rafael Antognolli | 03b1659 | 2013-12-03 15:35:42 -0200 | [diff] [blame] | 2730 | if (surface->state.maximized) |
Philip Withnall | becb77e | 2013-11-25 18:01:30 +0000 | [diff] [blame] | 2731 | unset_maximized(surface); |
Pekka Paalanen | 9826223 | 2011-12-01 10:42:22 +0200 | [diff] [blame] | 2732 | |
Pekka Paalanen | 9826223 | 2011-12-01 10:42:22 +0200 | [diff] [blame] | 2733 | return 0; |
| 2734 | } |
| 2735 | |
Kristian Høgsberg | 4cca349 | 2011-01-18 07:53:49 -0500 | [diff] [blame] | 2736 | static void |
Rafael Antognolli | 03b1659 | 2013-12-03 15:35:42 -0200 | [diff] [blame] | 2737 | set_full_output(struct shell_surface *shsurf) |
| 2738 | { |
| 2739 | shsurf->saved_x = shsurf->view->geometry.x; |
| 2740 | shsurf->saved_y = shsurf->view->geometry.y; |
Rafael Antognolli | 3c4e3f7 | 2013-12-03 15:35:46 -0200 | [diff] [blame] | 2741 | shsurf->saved_width = shsurf->surface->width; |
| 2742 | shsurf->saved_height = shsurf->surface->height; |
| 2743 | shsurf->saved_size_valid = true; |
Rafael Antognolli | 03b1659 | 2013-12-03 15:35:42 -0200 | [diff] [blame] | 2744 | shsurf->saved_position_valid = true; |
| 2745 | |
| 2746 | if (!wl_list_empty(&shsurf->rotation.transform.link)) { |
| 2747 | wl_list_remove(&shsurf->rotation.transform.link); |
| 2748 | wl_list_init(&shsurf->rotation.transform.link); |
| 2749 | weston_view_geometry_dirty(shsurf->view); |
| 2750 | shsurf->saved_rotation_valid = true; |
| 2751 | } |
| 2752 | } |
| 2753 | |
| 2754 | static void |
Kristian Høgsberg | 7f366e7 | 2012-04-27 17:20:01 -0400 | [diff] [blame] | 2755 | set_surface_type(struct shell_surface *shsurf) |
| 2756 | { |
Kristian Høgsberg | 8150b19 | 2012-06-27 10:22:58 -0400 | [diff] [blame] | 2757 | struct weston_surface *pes = shsurf->parent; |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 2758 | struct weston_view *pev = get_default_view(pes); |
Kristian Høgsberg | 7f366e7 | 2012-04-27 17:20:01 -0400 | [diff] [blame] | 2759 | |
Philip Withnall | becb77e | 2013-11-25 18:01:30 +0000 | [diff] [blame] | 2760 | reset_surface_type(shsurf); |
Kristian Høgsberg | 7f366e7 | 2012-04-27 17:20:01 -0400 | [diff] [blame] | 2761 | |
Rafael Antognolli | 03b1659 | 2013-12-03 15:35:42 -0200 | [diff] [blame] | 2762 | shsurf->state = shsurf->next_state; |
Rafael Antognolli | 03b1659 | 2013-12-03 15:35:42 -0200 | [diff] [blame] | 2763 | shsurf->state_changed = false; |
Kristian Høgsberg | 7f366e7 | 2012-04-27 17:20:01 -0400 | [diff] [blame] | 2764 | |
| 2765 | switch (shsurf->type) { |
| 2766 | case SHELL_SURFACE_TOPLEVEL: |
Rafael Antognolli | ed207b4 | 2013-12-03 15:35:43 -0200 | [diff] [blame] | 2767 | if (shsurf->state.maximized || shsurf->state.fullscreen) { |
Rafael Antognolli | 03b1659 | 2013-12-03 15:35:42 -0200 | [diff] [blame] | 2768 | set_full_output(shsurf); |
Rafael Antognolli | ed207b4 | 2013-12-03 15:35:43 -0200 | [diff] [blame] | 2769 | } else if (shsurf->state.relative && pev) { |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 2770 | weston_view_set_position(shsurf->view, |
| 2771 | pev->geometry.x + shsurf->transient.x, |
| 2772 | pev->geometry.y + shsurf->transient.y); |
Rafael Antognolli | ed207b4 | 2013-12-03 15:35:43 -0200 | [diff] [blame] | 2773 | } |
Rafael Antognolli | 44a3162 | 2013-12-04 18:37:16 -0200 | [diff] [blame] | 2774 | break; |
Kristian Høgsberg | 7f366e7 | 2012-04-27 17:20:01 -0400 | [diff] [blame] | 2775 | |
Tiago Vignatti | fb2adba | 2013-06-12 15:43:21 -0300 | [diff] [blame] | 2776 | case SHELL_SURFACE_XWAYLAND: |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 2777 | weston_view_set_position(shsurf->view, shsurf->transient.x, |
| 2778 | shsurf->transient.y); |
Tiago Vignatti | fb2adba | 2013-06-12 15:43:21 -0300 | [diff] [blame] | 2779 | break; |
| 2780 | |
Philip Withnall | 0f640e2 | 2013-11-25 18:01:31 +0000 | [diff] [blame] | 2781 | case SHELL_SURFACE_POPUP: |
| 2782 | case SHELL_SURFACE_NONE: |
Kristian Høgsberg | 7f366e7 | 2012-04-27 17:20:01 -0400 | [diff] [blame] | 2783 | default: |
| 2784 | break; |
| 2785 | } |
Philip Withnall | e1d75ae | 2013-11-25 18:01:41 +0000 | [diff] [blame] | 2786 | |
| 2787 | /* Update the surface’s layer. */ |
| 2788 | shell_surface_update_layer(shsurf); |
Kristian Høgsberg | 7f366e7 | 2012-04-27 17:20:01 -0400 | [diff] [blame] | 2789 | } |
| 2790 | |
Tiago Vignatti | be14326 | 2012-04-16 17:31:41 +0300 | [diff] [blame] | 2791 | static struct desktop_shell * |
Juan Zhao | 96879df | 2012-02-07 08:45:41 +0800 | [diff] [blame] | 2792 | shell_surface_get_shell(struct shell_surface *shsurf) |
Pekka Paalanen | af0e34c | 2011-12-02 10:59:17 +0200 | [diff] [blame] | 2793 | { |
Kristian Høgsberg | 02e79dc | 2012-04-12 09:55:26 -0400 | [diff] [blame] | 2794 | return shsurf->shell; |
Juan Zhao | 96879df | 2012-02-07 08:45:41 +0800 | [diff] [blame] | 2795 | } |
| 2796 | |
Pekka Paalanen | 8274d90 | 2014-08-06 19:36:51 +0300 | [diff] [blame] | 2797 | static int |
| 2798 | black_surface_get_label(struct weston_surface *surface, char *buf, size_t len) |
| 2799 | { |
| 2800 | struct weston_surface *fs_surface = surface->configure_private; |
| 2801 | int n; |
| 2802 | int rem; |
| 2803 | int ret; |
| 2804 | |
| 2805 | n = snprintf(buf, len, "black background surface for "); |
| 2806 | if (n < 0) |
| 2807 | return n; |
| 2808 | |
| 2809 | rem = (int)len - n; |
| 2810 | if (rem < 0) |
| 2811 | rem = 0; |
| 2812 | |
| 2813 | if (fs_surface->get_label) |
| 2814 | ret = fs_surface->get_label(fs_surface, buf + n, rem); |
| 2815 | else |
| 2816 | ret = snprintf(buf + n, rem, "<unknown>"); |
| 2817 | |
| 2818 | if (ret < 0) |
| 2819 | return n; |
| 2820 | |
| 2821 | return n + ret; |
| 2822 | } |
| 2823 | |
Alex Wu | 2185843 | 2012-04-01 20:13:08 +0800 | [diff] [blame] | 2824 | static void |
Jason Ekstrand | 918f2dd | 2013-12-02 21:01:53 -0600 | [diff] [blame] | 2825 | 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] | 2826 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 2827 | static struct weston_view * |
Alex Wu | 4539b08 | 2012-03-01 12:57:46 +0800 | [diff] [blame] | 2828 | create_black_surface(struct weston_compositor *ec, |
Alex Wu | 2185843 | 2012-04-01 20:13:08 +0800 | [diff] [blame] | 2829 | struct weston_surface *fs_surface, |
John Kåre Alsaker | 490d02a | 2012-09-30 02:57:21 +0200 | [diff] [blame] | 2830 | float x, float y, int w, int h) |
Alex Wu | 4539b08 | 2012-03-01 12:57:46 +0800 | [diff] [blame] | 2831 | { |
| 2832 | struct weston_surface *surface = NULL; |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 2833 | struct weston_view *view; |
Alex Wu | 4539b08 | 2012-03-01 12:57:46 +0800 | [diff] [blame] | 2834 | |
| 2835 | surface = weston_surface_create(ec); |
| 2836 | if (surface == NULL) { |
Martin Minarik | 6d11836 | 2012-06-07 18:01:59 +0200 | [diff] [blame] | 2837 | weston_log("no memory\n"); |
Alex Wu | 4539b08 | 2012-03-01 12:57:46 +0800 | [diff] [blame] | 2838 | return NULL; |
| 2839 | } |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 2840 | view = weston_view_create(surface); |
| 2841 | if (surface == NULL) { |
| 2842 | weston_log("no memory\n"); |
| 2843 | weston_surface_destroy(surface); |
| 2844 | return NULL; |
| 2845 | } |
Alex Wu | 4539b08 | 2012-03-01 12:57:46 +0800 | [diff] [blame] | 2846 | |
Alex Wu | 2185843 | 2012-04-01 20:13:08 +0800 | [diff] [blame] | 2847 | surface->configure = black_surface_configure; |
Giulio Camuffo | 7fe01b1 | 2013-03-28 18:02:42 +0100 | [diff] [blame] | 2848 | surface->configure_private = fs_surface; |
Pekka Paalanen | 8274d90 | 2014-08-06 19:36:51 +0300 | [diff] [blame] | 2849 | weston_surface_set_label_func(surface, black_surface_get_label); |
Alex Wu | 4539b08 | 2012-03-01 12:57:46 +0800 | [diff] [blame] | 2850 | weston_surface_set_color(surface, 0.0, 0.0, 0.0, 1); |
Pekka Paalanen | 71f6f3b | 2012-10-10 12:49:26 +0300 | [diff] [blame] | 2851 | pixman_region32_fini(&surface->opaque); |
Kristian Høgsberg | 61f00f5 | 2012-08-03 16:31:36 -0400 | [diff] [blame] | 2852 | pixman_region32_init_rect(&surface->opaque, 0, 0, w, h); |
Jonas Ådahl | 33619a4 | 2013-01-15 21:25:55 +0100 | [diff] [blame] | 2853 | pixman_region32_fini(&surface->input); |
| 2854 | pixman_region32_init_rect(&surface->input, 0, 0, w, h); |
Jason Ekstrand | 918f2dd | 2013-12-02 21:01:53 -0600 | [diff] [blame] | 2855 | |
Jason Ekstrand | 6228ee2 | 2014-01-01 15:58:57 -0600 | [diff] [blame] | 2856 | weston_surface_set_size(surface, w, h); |
Jason Ekstrand | 918f2dd | 2013-12-02 21:01:53 -0600 | [diff] [blame] | 2857 | weston_view_set_position(view, x, y); |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 2858 | |
| 2859 | return view; |
Alex Wu | 4539b08 | 2012-03-01 12:57:46 +0800 | [diff] [blame] | 2860 | } |
| 2861 | |
Philip Withnall | ed8f1a9 | 2013-11-25 18:01:43 +0000 | [diff] [blame] | 2862 | static void |
| 2863 | shell_ensure_fullscreen_black_view(struct shell_surface *shsurf) |
| 2864 | { |
| 2865 | struct weston_output *output = shsurf->fullscreen_output; |
| 2866 | |
Rafael Antognolli | 03b1659 | 2013-12-03 15:35:42 -0200 | [diff] [blame] | 2867 | assert(shsurf->state.fullscreen); |
Philip Withnall | ed8f1a9 | 2013-11-25 18:01:43 +0000 | [diff] [blame] | 2868 | |
| 2869 | if (!shsurf->fullscreen.black_view) |
| 2870 | shsurf->fullscreen.black_view = |
| 2871 | create_black_surface(shsurf->surface->compositor, |
| 2872 | shsurf->surface, |
| 2873 | output->x, output->y, |
| 2874 | output->width, |
| 2875 | output->height); |
| 2876 | |
| 2877 | weston_view_geometry_dirty(shsurf->fullscreen.black_view); |
Giulio Camuffo | 412e6a5 | 2014-07-09 22:12:56 +0300 | [diff] [blame] | 2878 | weston_layer_entry_remove(&shsurf->fullscreen.black_view->layer_link); |
| 2879 | weston_layer_entry_insert(&shsurf->view->layer_link, |
| 2880 | &shsurf->fullscreen.black_view->layer_link); |
Philip Withnall | ed8f1a9 | 2013-11-25 18:01:43 +0000 | [diff] [blame] | 2881 | weston_view_geometry_dirty(shsurf->fullscreen.black_view); |
| 2882 | weston_surface_damage(shsurf->surface); |
Emilio Pozuelo Monfort | 9e7c759 | 2014-01-30 14:01:10 +0100 | [diff] [blame] | 2883 | |
| 2884 | shsurf->state.lowered = false; |
Philip Withnall | ed8f1a9 | 2013-11-25 18:01:43 +0000 | [diff] [blame] | 2885 | } |
| 2886 | |
Alex Wu | 4539b08 | 2012-03-01 12:57:46 +0800 | [diff] [blame] | 2887 | /* Create black surface and append it to the associated fullscreen surface. |
| 2888 | * Handle size dismatch and positioning according to the method. */ |
| 2889 | static void |
| 2890 | shell_configure_fullscreen(struct shell_surface *shsurf) |
| 2891 | { |
| 2892 | struct weston_output *output = shsurf->fullscreen_output; |
| 2893 | struct weston_surface *surface = shsurf->surface; |
| 2894 | struct weston_matrix *matrix; |
Kristian Høgsberg | 240dfeb | 2012-07-12 12:32:31 -0400 | [diff] [blame] | 2895 | float scale, output_aspect, surface_aspect, x, y; |
Giulio Camuffo | b836664 | 2013-04-25 13:57:46 +0300 | [diff] [blame] | 2896 | int32_t surf_x, surf_y, surf_width, surf_height; |
Alex Wu | 4539b08 | 2012-03-01 12:57:46 +0800 | [diff] [blame] | 2897 | |
Alexander Larsson | f82b6ca | 2013-05-28 16:23:39 +0200 | [diff] [blame] | 2898 | if (shsurf->fullscreen.type != WL_SHELL_SURFACE_FULLSCREEN_METHOD_DRIVER) |
| 2899 | restore_output_mode(output); |
| 2900 | |
Emilio Pozuelo Monfort | 9e7c759 | 2014-01-30 14:01:10 +0100 | [diff] [blame] | 2901 | /* Reverse the effect of lower_fullscreen_layer() */ |
Giulio Camuffo | 412e6a5 | 2014-07-09 22:12:56 +0300 | [diff] [blame] | 2902 | weston_layer_entry_remove(&shsurf->view->layer_link); |
| 2903 | 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] | 2904 | |
Philip Withnall | ed8f1a9 | 2013-11-25 18:01:43 +0000 | [diff] [blame] | 2905 | shell_ensure_fullscreen_black_view(shsurf); |
Alex Wu | 4539b08 | 2012-03-01 12:57:46 +0800 | [diff] [blame] | 2906 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 2907 | surface_subsurfaces_boundingbox(shsurf->surface, &surf_x, &surf_y, |
Giulio Camuffo | b836664 | 2013-04-25 13:57:46 +0300 | [diff] [blame] | 2908 | &surf_width, &surf_height); |
| 2909 | |
Alex Wu | 4539b08 | 2012-03-01 12:57:46 +0800 | [diff] [blame] | 2910 | switch (shsurf->fullscreen.type) { |
| 2911 | case WL_SHELL_SURFACE_FULLSCREEN_METHOD_DEFAULT: |
Pekka Paalanen | de685b8 | 2012-12-04 15:58:12 +0200 | [diff] [blame] | 2912 | if (surface->buffer_ref.buffer) |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 2913 | center_on_output(shsurf->view, shsurf->fullscreen_output); |
Alex Wu | 4539b08 | 2012-03-01 12:57:46 +0800 | [diff] [blame] | 2914 | break; |
| 2915 | case WL_SHELL_SURFACE_FULLSCREEN_METHOD_SCALE: |
Rob Bradford | 9f3dd15 | 2013-02-12 11:53:47 +0000 | [diff] [blame] | 2916 | /* 1:1 mapping between surface and output dimensions */ |
Giulio Camuffo | b836664 | 2013-04-25 13:57:46 +0300 | [diff] [blame] | 2917 | if (output->width == surf_width && |
| 2918 | output->height == surf_height) { |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 2919 | weston_view_set_position(shsurf->view, |
| 2920 | output->x - surf_x, |
| 2921 | output->y - surf_y); |
Rob Bradford | 9f3dd15 | 2013-02-12 11:53:47 +0000 | [diff] [blame] | 2922 | break; |
| 2923 | } |
| 2924 | |
Alex Wu | 4539b08 | 2012-03-01 12:57:46 +0800 | [diff] [blame] | 2925 | matrix = &shsurf->fullscreen.transform.matrix; |
| 2926 | weston_matrix_init(matrix); |
Kristian Høgsberg | 240dfeb | 2012-07-12 12:32:31 -0400 | [diff] [blame] | 2927 | |
Scott Moreau | 1bad5db | 2012-08-18 01:04:05 -0600 | [diff] [blame] | 2928 | output_aspect = (float) output->width / |
| 2929 | (float) output->height; |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 2930 | /* XXX: Use surf_width and surf_height here? */ |
| 2931 | surface_aspect = (float) surface->width / |
| 2932 | (float) surface->height; |
Kristian Høgsberg | 240dfeb | 2012-07-12 12:32:31 -0400 | [diff] [blame] | 2933 | if (output_aspect < surface_aspect) |
Scott Moreau | 1bad5db | 2012-08-18 01:04:05 -0600 | [diff] [blame] | 2934 | scale = (float) output->width / |
Giulio Camuffo | b836664 | 2013-04-25 13:57:46 +0300 | [diff] [blame] | 2935 | (float) surf_width; |
Kristian Høgsberg | 240dfeb | 2012-07-12 12:32:31 -0400 | [diff] [blame] | 2936 | else |
Scott Moreau | 1bad5db | 2012-08-18 01:04:05 -0600 | [diff] [blame] | 2937 | scale = (float) output->height / |
Giulio Camuffo | b836664 | 2013-04-25 13:57:46 +0300 | [diff] [blame] | 2938 | (float) surf_height; |
Kristian Høgsberg | 240dfeb | 2012-07-12 12:32:31 -0400 | [diff] [blame] | 2939 | |
Alex Wu | 4539b08 | 2012-03-01 12:57:46 +0800 | [diff] [blame] | 2940 | weston_matrix_scale(matrix, scale, scale, 1); |
| 2941 | wl_list_remove(&shsurf->fullscreen.transform.link); |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 2942 | wl_list_insert(&shsurf->view->geometry.transformation_list, |
Alex Wu | 4539b08 | 2012-03-01 12:57:46 +0800 | [diff] [blame] | 2943 | &shsurf->fullscreen.transform.link); |
Giulio Camuffo | b836664 | 2013-04-25 13:57:46 +0300 | [diff] [blame] | 2944 | x = output->x + (output->width - surf_width * scale) / 2 - surf_x; |
| 2945 | y = output->y + (output->height - surf_height * scale) / 2 - surf_y; |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 2946 | weston_view_set_position(shsurf->view, x, y); |
Kristian Høgsberg | 240dfeb | 2012-07-12 12:32:31 -0400 | [diff] [blame] | 2947 | |
Alex Wu | 4539b08 | 2012-03-01 12:57:46 +0800 | [diff] [blame] | 2948 | break; |
| 2949 | case WL_SHELL_SURFACE_FULLSCREEN_METHOD_DRIVER: |
Alex Wu | bd3354b | 2012-04-17 17:20:49 +0800 | [diff] [blame] | 2950 | if (shell_surface_is_top_fullscreen(shsurf)) { |
Quentin Glidic | c0d79ce | 2013-01-29 14:16:13 +0100 | [diff] [blame] | 2951 | struct weston_mode mode = {0, |
Pekka Paalanen | 952b6c8 | 2014-03-14 14:38:15 +0200 | [diff] [blame] | 2952 | surf_width * surface->buffer_viewport.buffer.scale, |
| 2953 | surf_height * surface->buffer_viewport.buffer.scale, |
Alex Wu | bd3354b | 2012-04-17 17:20:49 +0800 | [diff] [blame] | 2954 | shsurf->fullscreen.framerate}; |
| 2955 | |
Derek Foreman | 6ae7bc9 | 2014-11-04 10:47:33 -0600 | [diff] [blame] | 2956 | if (weston_output_mode_switch_to_temporary(output, &mode, |
| 2957 | surface->buffer_viewport.buffer.scale) == 0) { |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 2958 | weston_view_set_position(shsurf->view, |
| 2959 | output->x - surf_x, |
| 2960 | output->y - surf_y); |
Jason Ekstrand | 918f2dd | 2013-12-02 21:01:53 -0600 | [diff] [blame] | 2961 | shsurf->fullscreen.black_view->surface->width = output->width; |
| 2962 | shsurf->fullscreen.black_view->surface->height = output->height; |
| 2963 | weston_view_set_position(shsurf->fullscreen.black_view, |
| 2964 | output->x - surf_x, |
| 2965 | output->y - surf_y); |
Alex Wu | bd3354b | 2012-04-17 17:20:49 +0800 | [diff] [blame] | 2966 | break; |
Alexander Larsson | d622ed3 | 2013-05-28 16:23:40 +0200 | [diff] [blame] | 2967 | } else { |
Mario Kleiner | 492c12f | 2015-06-21 21:25:12 +0200 | [diff] [blame] | 2968 | weston_log("shell: Can't switch to temporary mode.\n"); |
Alexander Larsson | f82b6ca | 2013-05-28 16:23:39 +0200 | [diff] [blame] | 2969 | restore_output_mode(output); |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 2970 | center_on_output(shsurf->view, output); |
Alexander Larsson | d622ed3 | 2013-05-28 16:23:40 +0200 | [diff] [blame] | 2971 | } |
Alex Wu | bd3354b | 2012-04-17 17:20:49 +0800 | [diff] [blame] | 2972 | } |
Alex Wu | 4539b08 | 2012-03-01 12:57:46 +0800 | [diff] [blame] | 2973 | break; |
| 2974 | case WL_SHELL_SURFACE_FULLSCREEN_METHOD_FILL: |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 2975 | center_on_output(shsurf->view, output); |
Alex Wu | 4539b08 | 2012-03-01 12:57:46 +0800 | [diff] [blame] | 2976 | break; |
| 2977 | default: |
| 2978 | break; |
| 2979 | } |
| 2980 | } |
| 2981 | |
Alex Wu | 4539b08 | 2012-03-01 12:57:46 +0800 | [diff] [blame] | 2982 | static void |
| 2983 | shell_map_fullscreen(struct shell_surface *shsurf) |
| 2984 | { |
Alex Wu | bd3354b | 2012-04-17 17:20:49 +0800 | [diff] [blame] | 2985 | shell_configure_fullscreen(shsurf); |
Alex Wu | 4539b08 | 2012-03-01 12:57:46 +0800 | [diff] [blame] | 2986 | } |
| 2987 | |
Kristian Høgsberg | 7a5c979 | 2011-06-18 06:12:54 -0400 | [diff] [blame] | 2988 | static void |
Tiago Vignatti | fb2adba | 2013-06-12 15:43:21 -0300 | [diff] [blame] | 2989 | set_xwayland(struct shell_surface *shsurf, int x, int y, uint32_t flags) |
| 2990 | { |
| 2991 | /* XXX: using the same fields for transient type */ |
Rafael Antognolli | 03b1659 | 2013-12-03 15:35:42 -0200 | [diff] [blame] | 2992 | surface_clear_next_states(shsurf); |
Tiago Vignatti | fb2adba | 2013-06-12 15:43:21 -0300 | [diff] [blame] | 2993 | shsurf->transient.x = x; |
| 2994 | shsurf->transient.y = y; |
| 2995 | shsurf->transient.flags = flags; |
Philip Withnall | dc4332f | 2013-11-25 18:01:38 +0000 | [diff] [blame] | 2996 | |
| 2997 | shell_surface_set_parent(shsurf, NULL); |
| 2998 | |
Pekka Paalanen | b502654 | 2014-11-12 15:09:24 +0200 | [diff] [blame] | 2999 | set_type(shsurf, SHELL_SURFACE_XWAYLAND); |
Kristian Høgsberg | 8bc525c | 2014-01-01 22:34:49 -0800 | [diff] [blame] | 3000 | shsurf->state_changed = true; |
Tiago Vignatti | fb2adba | 2013-06-12 15:43:21 -0300 | [diff] [blame] | 3001 | } |
| 3002 | |
Kristian Høgsberg | 4779241 | 2014-05-04 13:47:06 -0700 | [diff] [blame] | 3003 | static void |
| 3004 | shell_interface_set_fullscreen(struct shell_surface *shsurf, |
| 3005 | uint32_t method, |
| 3006 | uint32_t framerate, |
| 3007 | struct weston_output *output) |
| 3008 | { |
| 3009 | surface_clear_next_states(shsurf); |
Kristian Høgsberg | 4779241 | 2014-05-04 13:47:06 -0700 | [diff] [blame] | 3010 | shsurf->next_state.fullscreen = true; |
| 3011 | shsurf->state_changed = true; |
Marek Chalupa | e9fe467 | 2014-10-29 13:44:44 +0100 | [diff] [blame] | 3012 | |
| 3013 | set_fullscreen(shsurf, method, framerate, output); |
Kristian Høgsberg | 4779241 | 2014-05-04 13:47:06 -0700 | [diff] [blame] | 3014 | } |
| 3015 | |
Giulio Camuffo | 6b4b241 | 2015-01-29 19:06:49 +0200 | [diff] [blame] | 3016 | static struct weston_output * |
| 3017 | get_focused_output(struct weston_compositor *compositor) |
| 3018 | { |
| 3019 | struct weston_seat *seat; |
| 3020 | struct weston_output *output = NULL; |
| 3021 | |
| 3022 | wl_list_for_each(seat, &compositor->seat_list, link) { |
| 3023 | /* Priority has touch focus, then pointer and |
| 3024 | * then keyboard focus. We should probably have |
| 3025 | * three for loops and check frist for touch, |
| 3026 | * then for pointer, etc. but unless somebody has some |
| 3027 | * objections, I think this is sufficient. */ |
| 3028 | if (seat->touch && seat->touch->focus) |
| 3029 | output = seat->touch->focus->output; |
| 3030 | else if (seat->pointer && seat->pointer->focus) |
| 3031 | output = seat->pointer->focus->output; |
| 3032 | else if (seat->keyboard && seat->keyboard->focus) |
| 3033 | output = seat->keyboard->focus->output; |
| 3034 | |
| 3035 | if (output) |
| 3036 | break; |
| 3037 | } |
| 3038 | |
| 3039 | return output; |
| 3040 | } |
| 3041 | |
| 3042 | static void |
| 3043 | shell_interface_set_maximized(struct shell_surface *shsurf) |
| 3044 | { |
| 3045 | struct weston_output *output; |
| 3046 | |
| 3047 | surface_clear_next_states(shsurf); |
| 3048 | shsurf->next_state.maximized = true; |
| 3049 | shsurf->state_changed = true; |
| 3050 | shsurf->type = SHELL_SURFACE_TOPLEVEL; |
| 3051 | |
| 3052 | if (!weston_surface_is_mapped(shsurf->surface)) |
| 3053 | output = get_focused_output(shsurf->surface->compositor); |
| 3054 | else |
| 3055 | output = shsurf->surface->output; |
| 3056 | |
| 3057 | shell_surface_set_output(shsurf, output); |
| 3058 | send_configure_for_surface(shsurf); |
| 3059 | } |
| 3060 | |
Kristian Høgsberg | ae356ae | 2014-04-29 16:03:54 -0700 | [diff] [blame] | 3061 | static int |
| 3062 | shell_interface_move(struct shell_surface *shsurf, struct weston_seat *ws) |
| 3063 | { |
Derek Foreman | 794fa0e | 2015-07-15 13:00:38 -0500 | [diff] [blame] | 3064 | return surface_move(shsurf, ws->pointer, true); |
Kristian Høgsberg | ae356ae | 2014-04-29 16:03:54 -0700 | [diff] [blame] | 3065 | } |
| 3066 | |
Derek Foreman | 8fbebbd | 2015-07-15 13:00:40 -0500 | [diff] [blame] | 3067 | static int |
| 3068 | shell_interface_resize(struct shell_surface *shsurf, |
| 3069 | struct weston_seat *ws, |
| 3070 | uint32_t edges) |
| 3071 | { |
| 3072 | return surface_resize(shsurf, ws->pointer, edges); |
| 3073 | } |
| 3074 | |
Kristian Høgsberg | 02bbabb | 2013-05-06 22:15:05 -0400 | [diff] [blame] | 3075 | static const struct weston_pointer_grab_interface popup_grab_interface; |
Giulio Camuffo | 5085a75 | 2013-03-25 21:42:45 +0100 | [diff] [blame] | 3076 | |
| 3077 | static void |
| 3078 | destroy_shell_seat(struct wl_listener *listener, void *data) |
| 3079 | { |
| 3080 | struct shell_seat *shseat = |
| 3081 | container_of(listener, |
| 3082 | struct shell_seat, seat_destroy_listener); |
Jonas Ådahl | c2b1011 | 2015-02-13 14:01:53 +0800 | [diff] [blame] | 3083 | struct shell_surface *shsurf, *next; |
Giulio Camuffo | 5085a75 | 2013-03-25 21:42:45 +0100 | [diff] [blame] | 3084 | |
| 3085 | if (shseat->popup_grab.grab.interface == &popup_grab_interface) { |
Kristian Høgsberg | 02bbabb | 2013-05-06 22:15:05 -0400 | [diff] [blame] | 3086 | weston_pointer_end_grab(shseat->popup_grab.grab.pointer); |
Giulio Camuffo | 5085a75 | 2013-03-25 21:42:45 +0100 | [diff] [blame] | 3087 | shseat->popup_grab.client = NULL; |
| 3088 | |
Jonas Ådahl | c2b1011 | 2015-02-13 14:01:53 +0800 | [diff] [blame] | 3089 | wl_list_for_each_safe(shsurf, next, |
| 3090 | &shseat->popup_grab.surfaces_list, |
| 3091 | popup.grab_link) { |
Giulio Camuffo | 5085a75 | 2013-03-25 21:42:45 +0100 | [diff] [blame] | 3092 | shsurf->popup.shseat = NULL; |
Jonas Ådahl | c2b1011 | 2015-02-13 14:01:53 +0800 | [diff] [blame] | 3093 | wl_list_init(&shsurf->popup.grab_link); |
Giulio Camuffo | 5085a75 | 2013-03-25 21:42:45 +0100 | [diff] [blame] | 3094 | } |
Giulio Camuffo | 5085a75 | 2013-03-25 21:42:45 +0100 | [diff] [blame] | 3095 | } |
| 3096 | |
| 3097 | wl_list_remove(&shseat->seat_destroy_listener.link); |
| 3098 | free(shseat); |
| 3099 | } |
| 3100 | |
Jason Ekstrand | 024177c | 2014-04-21 19:42:58 -0500 | [diff] [blame] | 3101 | static void |
| 3102 | shell_seat_caps_changed(struct wl_listener *listener, void *data) |
| 3103 | { |
| 3104 | struct shell_seat *seat; |
| 3105 | |
| 3106 | seat = container_of(listener, struct shell_seat, caps_changed_listener); |
| 3107 | |
| 3108 | if (seat->seat->keyboard && |
| 3109 | wl_list_empty(&seat->keyboard_focus_listener.link)) { |
| 3110 | wl_signal_add(&seat->seat->keyboard->focus_signal, |
| 3111 | &seat->keyboard_focus_listener); |
| 3112 | } else if (!seat->seat->keyboard) { |
| 3113 | wl_list_init(&seat->keyboard_focus_listener.link); |
| 3114 | } |
| 3115 | |
| 3116 | if (seat->seat->pointer && |
| 3117 | wl_list_empty(&seat->pointer_focus_listener.link)) { |
| 3118 | wl_signal_add(&seat->seat->pointer->focus_signal, |
| 3119 | &seat->pointer_focus_listener); |
| 3120 | } else if (!seat->seat->pointer) { |
| 3121 | wl_list_init(&seat->pointer_focus_listener.link); |
| 3122 | } |
| 3123 | } |
| 3124 | |
Giulio Camuffo | 5085a75 | 2013-03-25 21:42:45 +0100 | [diff] [blame] | 3125 | static struct shell_seat * |
| 3126 | create_shell_seat(struct weston_seat *seat) |
| 3127 | { |
| 3128 | struct shell_seat *shseat; |
| 3129 | |
| 3130 | shseat = calloc(1, sizeof *shseat); |
| 3131 | if (!shseat) { |
| 3132 | weston_log("no memory to allocate shell seat\n"); |
| 3133 | return NULL; |
| 3134 | } |
| 3135 | |
| 3136 | shseat->seat = seat; |
| 3137 | wl_list_init(&shseat->popup_grab.surfaces_list); |
| 3138 | |
| 3139 | shseat->seat_destroy_listener.notify = destroy_shell_seat; |
| 3140 | wl_signal_add(&seat->destroy_signal, |
| 3141 | &shseat->seat_destroy_listener); |
| 3142 | |
Jason Ekstrand | 024177c | 2014-04-21 19:42:58 -0500 | [diff] [blame] | 3143 | shseat->keyboard_focus_listener.notify = handle_keyboard_focus; |
| 3144 | wl_list_init(&shseat->keyboard_focus_listener.link); |
| 3145 | |
| 3146 | shseat->pointer_focus_listener.notify = handle_pointer_focus; |
| 3147 | wl_list_init(&shseat->pointer_focus_listener.link); |
| 3148 | |
| 3149 | shseat->caps_changed_listener.notify = shell_seat_caps_changed; |
| 3150 | wl_signal_add(&seat->updated_caps_signal, |
| 3151 | &shseat->caps_changed_listener); |
| 3152 | shell_seat_caps_changed(&shseat->caps_changed_listener, NULL); |
| 3153 | |
Giulio Camuffo | 5085a75 | 2013-03-25 21:42:45 +0100 | [diff] [blame] | 3154 | return shseat; |
| 3155 | } |
| 3156 | |
| 3157 | static struct shell_seat * |
| 3158 | get_shell_seat(struct weston_seat *seat) |
| 3159 | { |
| 3160 | struct wl_listener *listener; |
| 3161 | |
| 3162 | listener = wl_signal_get(&seat->destroy_signal, destroy_shell_seat); |
Jason Ekstrand | 024177c | 2014-04-21 19:42:58 -0500 | [diff] [blame] | 3163 | assert(listener != NULL); |
Giulio Camuffo | 5085a75 | 2013-03-25 21:42:45 +0100 | [diff] [blame] | 3164 | |
| 3165 | return container_of(listener, |
| 3166 | struct shell_seat, seat_destroy_listener); |
| 3167 | } |
| 3168 | |
Kristian Høgsberg | b810eb5 | 2013-02-12 20:07:05 -0500 | [diff] [blame] | 3169 | static void |
Kristian Høgsberg | 6848c25 | 2013-05-08 22:02:59 -0400 | [diff] [blame] | 3170 | popup_grab_focus(struct weston_pointer_grab *grab) |
Kristian Høgsberg | b3cca0a | 2012-01-04 22:19:14 -0500 | [diff] [blame] | 3171 | { |
Kristian Høgsberg | 02bbabb | 2013-05-06 22:15:05 -0400 | [diff] [blame] | 3172 | struct weston_pointer *pointer = grab->pointer; |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 3173 | struct weston_view *view; |
Giulio Camuffo | 5085a75 | 2013-03-25 21:42:45 +0100 | [diff] [blame] | 3174 | struct shell_seat *shseat = |
| 3175 | container_of(grab, struct shell_seat, popup_grab.grab); |
| 3176 | struct wl_client *client = shseat->popup_grab.client; |
Kristian Høgsberg | 6848c25 | 2013-05-08 22:02:59 -0400 | [diff] [blame] | 3177 | wl_fixed_t sx, sy; |
| 3178 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 3179 | view = weston_compositor_pick_view(pointer->seat->compositor, |
| 3180 | pointer->x, pointer->y, |
| 3181 | &sx, &sy); |
Kristian Høgsberg | b3cca0a | 2012-01-04 22:19:14 -0500 | [diff] [blame] | 3182 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 3183 | if (view && view->surface->resource && |
| 3184 | wl_resource_get_client(view->surface->resource) == client) { |
| 3185 | weston_pointer_set_focus(pointer, view, sx, sy); |
Kristian Høgsberg | b3cca0a | 2012-01-04 22:19:14 -0500 | [diff] [blame] | 3186 | } else { |
Kristian Høgsberg | 02bbabb | 2013-05-06 22:15:05 -0400 | [diff] [blame] | 3187 | weston_pointer_set_focus(pointer, NULL, |
| 3188 | wl_fixed_from_int(0), |
| 3189 | wl_fixed_from_int(0)); |
Kristian Høgsberg | b3cca0a | 2012-01-04 22:19:14 -0500 | [diff] [blame] | 3190 | } |
| 3191 | } |
| 3192 | |
| 3193 | static void |
Giulio Camuffo | 1959ab8 | 2013-11-14 23:42:52 +0100 | [diff] [blame] | 3194 | popup_grab_motion(struct weston_pointer_grab *grab, uint32_t time, |
| 3195 | wl_fixed_t x, wl_fixed_t y) |
Kristian Høgsberg | b3cca0a | 2012-01-04 22:19:14 -0500 | [diff] [blame] | 3196 | { |
Kristian Høgsberg | be6403e | 2013-05-08 21:03:21 -0400 | [diff] [blame] | 3197 | struct weston_pointer *pointer = grab->pointer; |
Neil Roberts | 96d790e | 2013-09-19 17:32:00 +0100 | [diff] [blame] | 3198 | struct wl_resource *resource; |
Kristian Høgsberg | be6403e | 2013-05-08 21:03:21 -0400 | [diff] [blame] | 3199 | wl_fixed_t sx, sy; |
Kristian Høgsberg | b3cca0a | 2012-01-04 22:19:14 -0500 | [diff] [blame] | 3200 | |
Jonas Ådahl | 61917c8 | 2014-08-11 22:44:02 +0200 | [diff] [blame] | 3201 | if (pointer->focus) { |
| 3202 | weston_view_from_global_fixed(pointer->focus, x, y, |
| 3203 | &pointer->sx, &pointer->sy); |
| 3204 | } |
| 3205 | |
Giulio Camuffo | 1959ab8 | 2013-11-14 23:42:52 +0100 | [diff] [blame] | 3206 | weston_pointer_move(pointer, x, y); |
| 3207 | |
Neil Roberts | 96d790e | 2013-09-19 17:32:00 +0100 | [diff] [blame] | 3208 | wl_resource_for_each(resource, &pointer->focus_resource_list) { |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 3209 | weston_view_from_global_fixed(pointer->focus, |
| 3210 | pointer->x, pointer->y, |
| 3211 | &sx, &sy); |
Neil Roberts | 96d790e | 2013-09-19 17:32:00 +0100 | [diff] [blame] | 3212 | wl_pointer_send_motion(resource, time, sx, sy); |
Kristian Høgsberg | be6403e | 2013-05-08 21:03:21 -0400 | [diff] [blame] | 3213 | } |
Kristian Høgsberg | b3cca0a | 2012-01-04 22:19:14 -0500 | [diff] [blame] | 3214 | } |
| 3215 | |
| 3216 | static void |
Kristian Høgsberg | 02bbabb | 2013-05-06 22:15:05 -0400 | [diff] [blame] | 3217 | popup_grab_button(struct weston_pointer_grab *grab, |
Daniel Stone | 4dbadb1 | 2012-05-30 16:31:51 +0100 | [diff] [blame] | 3218 | uint32_t time, uint32_t button, uint32_t state_w) |
Kristian Høgsberg | b3cca0a | 2012-01-04 22:19:14 -0500 | [diff] [blame] | 3219 | { |
| 3220 | struct wl_resource *resource; |
Giulio Camuffo | 5085a75 | 2013-03-25 21:42:45 +0100 | [diff] [blame] | 3221 | struct shell_seat *shseat = |
| 3222 | container_of(grab, struct shell_seat, popup_grab.grab); |
Rob Bradford | 880ebc7 | 2013-07-22 17:31:38 +0100 | [diff] [blame] | 3223 | struct wl_display *display = shseat->seat->compositor->wl_display; |
Daniel Stone | 4dbadb1 | 2012-05-30 16:31:51 +0100 | [diff] [blame] | 3224 | enum wl_pointer_button_state state = state_w; |
Kristian Høgsberg | eae5de7 | 2012-04-11 22:42:15 -0400 | [diff] [blame] | 3225 | uint32_t serial; |
Neil Roberts | 96d790e | 2013-09-19 17:32:00 +0100 | [diff] [blame] | 3226 | struct wl_list *resource_list; |
Kristian Høgsberg | b3cca0a | 2012-01-04 22:19:14 -0500 | [diff] [blame] | 3227 | |
Neil Roberts | 96d790e | 2013-09-19 17:32:00 +0100 | [diff] [blame] | 3228 | resource_list = &grab->pointer->focus_resource_list; |
| 3229 | if (!wl_list_empty(resource_list)) { |
Kristian Høgsberg | eae5de7 | 2012-04-11 22:42:15 -0400 | [diff] [blame] | 3230 | serial = wl_display_get_serial(display); |
Neil Roberts | 96d790e | 2013-09-19 17:32:00 +0100 | [diff] [blame] | 3231 | wl_resource_for_each(resource, resource_list) { |
| 3232 | wl_pointer_send_button(resource, serial, |
| 3233 | time, button, state); |
| 3234 | } |
Daniel Stone | 4dbadb1 | 2012-05-30 16:31:51 +0100 | [diff] [blame] | 3235 | } else if (state == WL_POINTER_BUTTON_STATE_RELEASED && |
Giulio Camuffo | 5085a75 | 2013-03-25 21:42:45 +0100 | [diff] [blame] | 3236 | (shseat->popup_grab.initial_up || |
Derek Foreman | f7b2f8b | 2015-07-15 13:00:41 -0500 | [diff] [blame] | 3237 | time - grab->pointer->grab_time > 500)) { |
Kristian Høgsberg | 57e0907 | 2012-10-30 14:07:27 -0400 | [diff] [blame] | 3238 | popup_grab_end(grab->pointer); |
Kristian Høgsberg | b3cca0a | 2012-01-04 22:19:14 -0500 | [diff] [blame] | 3239 | } |
| 3240 | |
Daniel Stone | 4dbadb1 | 2012-05-30 16:31:51 +0100 | [diff] [blame] | 3241 | if (state == WL_POINTER_BUTTON_STATE_RELEASED) |
Giulio Camuffo | 5085a75 | 2013-03-25 21:42:45 +0100 | [diff] [blame] | 3242 | shseat->popup_grab.initial_up = 1; |
Kristian Høgsberg | b3cca0a | 2012-01-04 22:19:14 -0500 | [diff] [blame] | 3243 | } |
| 3244 | |
Jonas Ådahl | 1ea343e | 2013-10-25 23:18:05 +0200 | [diff] [blame] | 3245 | static void |
| 3246 | popup_grab_cancel(struct weston_pointer_grab *grab) |
| 3247 | { |
| 3248 | popup_grab_end(grab->pointer); |
| 3249 | } |
| 3250 | |
Kristian Høgsberg | 02bbabb | 2013-05-06 22:15:05 -0400 | [diff] [blame] | 3251 | static const struct weston_pointer_grab_interface popup_grab_interface = { |
Kristian Høgsberg | b3cca0a | 2012-01-04 22:19:14 -0500 | [diff] [blame] | 3252 | popup_grab_focus, |
| 3253 | popup_grab_motion, |
| 3254 | popup_grab_button, |
Jonas Ådahl | 1ea343e | 2013-10-25 23:18:05 +0200 | [diff] [blame] | 3255 | popup_grab_cancel, |
Kristian Høgsberg | b3cca0a | 2012-01-04 22:19:14 -0500 | [diff] [blame] | 3256 | }; |
| 3257 | |
| 3258 | static void |
Jonny Lamb | 76cf1fe | 2014-08-20 11:27:10 +0200 | [diff] [blame] | 3259 | touch_popup_grab_down(struct weston_touch_grab *grab, uint32_t time, |
| 3260 | int touch_id, wl_fixed_t sx, wl_fixed_t sy) |
| 3261 | { |
| 3262 | struct wl_resource *resource; |
| 3263 | struct shell_seat *shseat = |
| 3264 | container_of(grab, struct shell_seat, popup_grab.touch_grab); |
| 3265 | struct wl_display *display = shseat->seat->compositor->wl_display; |
| 3266 | uint32_t serial; |
| 3267 | struct wl_list *resource_list; |
| 3268 | |
| 3269 | resource_list = &grab->touch->focus_resource_list; |
| 3270 | if (!wl_list_empty(resource_list)) { |
| 3271 | serial = wl_display_get_serial(display); |
| 3272 | wl_resource_for_each(resource, resource_list) { |
| 3273 | wl_touch_send_down(resource, serial, time, |
| 3274 | grab->touch->focus->surface->resource, |
| 3275 | touch_id, sx, sy); |
| 3276 | } |
| 3277 | } |
| 3278 | } |
| 3279 | |
| 3280 | static void |
| 3281 | touch_popup_grab_up(struct weston_touch_grab *grab, uint32_t time, int touch_id) |
| 3282 | { |
| 3283 | struct wl_resource *resource; |
| 3284 | struct shell_seat *shseat = |
| 3285 | container_of(grab, struct shell_seat, popup_grab.touch_grab); |
| 3286 | struct wl_display *display = shseat->seat->compositor->wl_display; |
| 3287 | uint32_t serial; |
| 3288 | struct wl_list *resource_list; |
| 3289 | |
| 3290 | resource_list = &grab->touch->focus_resource_list; |
| 3291 | if (!wl_list_empty(resource_list)) { |
| 3292 | serial = wl_display_get_serial(display); |
| 3293 | wl_resource_for_each(resource, resource_list) { |
| 3294 | wl_touch_send_up(resource, serial, time, touch_id); |
| 3295 | } |
| 3296 | } |
| 3297 | } |
| 3298 | |
| 3299 | static void |
| 3300 | touch_popup_grab_motion(struct weston_touch_grab *grab, uint32_t time, |
| 3301 | int touch_id, wl_fixed_t sx, wl_fixed_t sy) |
| 3302 | { |
| 3303 | struct wl_resource *resource; |
| 3304 | struct wl_list *resource_list; |
| 3305 | |
| 3306 | resource_list = &grab->touch->focus_resource_list; |
| 3307 | if (!wl_list_empty(resource_list)) { |
| 3308 | wl_resource_for_each(resource, resource_list) { |
| 3309 | wl_touch_send_motion(resource, time, touch_id, sx, sy); |
| 3310 | } |
| 3311 | } |
| 3312 | } |
| 3313 | |
| 3314 | static void |
| 3315 | touch_popup_grab_frame(struct weston_touch_grab *grab) |
| 3316 | { |
| 3317 | } |
| 3318 | |
| 3319 | static void |
| 3320 | touch_popup_grab_cancel(struct weston_touch_grab *grab) |
| 3321 | { |
| 3322 | touch_popup_grab_end(grab->touch); |
| 3323 | } |
| 3324 | |
| 3325 | static const struct weston_touch_grab_interface touch_popup_grab_interface = { |
| 3326 | touch_popup_grab_down, |
| 3327 | touch_popup_grab_up, |
| 3328 | touch_popup_grab_motion, |
| 3329 | touch_popup_grab_frame, |
| 3330 | touch_popup_grab_cancel, |
| 3331 | }; |
| 3332 | |
| 3333 | static void |
Rafael Antognolli | e2a3455 | 2013-12-03 15:35:45 -0200 | [diff] [blame] | 3334 | shell_surface_send_popup_done(struct shell_surface *shsurf) |
| 3335 | { |
| 3336 | if (shell_surface_is_wl_shell_surface(shsurf)) |
| 3337 | wl_shell_surface_send_popup_done(shsurf->resource); |
| 3338 | else if (shell_surface_is_xdg_popup(shsurf)) |
Jasper St. Pierre | ecf2a0f | 2015-02-13 14:01:56 +0800 | [diff] [blame] | 3339 | xdg_popup_send_popup_done(shsurf->resource); |
Rafael Antognolli | e2a3455 | 2013-12-03 15:35:45 -0200 | [diff] [blame] | 3340 | } |
| 3341 | |
| 3342 | static void |
Kristian Høgsberg | 02bbabb | 2013-05-06 22:15:05 -0400 | [diff] [blame] | 3343 | popup_grab_end(struct weston_pointer *pointer) |
Kristian Høgsberg | 57e0907 | 2012-10-30 14:07:27 -0400 | [diff] [blame] | 3344 | { |
Kristian Høgsberg | 02bbabb | 2013-05-06 22:15:05 -0400 | [diff] [blame] | 3345 | struct weston_pointer_grab *grab = pointer->grab; |
Giulio Camuffo | 5085a75 | 2013-03-25 21:42:45 +0100 | [diff] [blame] | 3346 | struct shell_seat *shseat = |
| 3347 | container_of(grab, struct shell_seat, popup_grab.grab); |
| 3348 | struct shell_surface *shsurf; |
Jonas Ådahl | c2b1011 | 2015-02-13 14:01:53 +0800 | [diff] [blame] | 3349 | struct shell_surface *next; |
Kristian Høgsberg | 57e0907 | 2012-10-30 14:07:27 -0400 | [diff] [blame] | 3350 | |
| 3351 | if (pointer->grab->interface == &popup_grab_interface) { |
Kristian Høgsberg | 02bbabb | 2013-05-06 22:15:05 -0400 | [diff] [blame] | 3352 | weston_pointer_end_grab(grab->pointer); |
Giulio Camuffo | 5085a75 | 2013-03-25 21:42:45 +0100 | [diff] [blame] | 3353 | shseat->popup_grab.client = NULL; |
Philipp Brüschweiler | 63e7be6 | 2013-04-15 21:09:54 +0200 | [diff] [blame] | 3354 | shseat->popup_grab.grab.interface = NULL; |
| 3355 | assert(!wl_list_empty(&shseat->popup_grab.surfaces_list)); |
Giulio Camuffo | 5085a75 | 2013-03-25 21:42:45 +0100 | [diff] [blame] | 3356 | /* Send the popup_done event to all the popups open */ |
Jonas Ådahl | c2b1011 | 2015-02-13 14:01:53 +0800 | [diff] [blame] | 3357 | wl_list_for_each_safe(shsurf, next, |
| 3358 | &shseat->popup_grab.surfaces_list, |
| 3359 | popup.grab_link) { |
Rafael Antognolli | e2a3455 | 2013-12-03 15:35:45 -0200 | [diff] [blame] | 3360 | shell_surface_send_popup_done(shsurf); |
Giulio Camuffo | 5085a75 | 2013-03-25 21:42:45 +0100 | [diff] [blame] | 3361 | shsurf->popup.shseat = NULL; |
Jonas Ådahl | c2b1011 | 2015-02-13 14:01:53 +0800 | [diff] [blame] | 3362 | wl_list_init(&shsurf->popup.grab_link); |
Giulio Camuffo | 5085a75 | 2013-03-25 21:42:45 +0100 | [diff] [blame] | 3363 | } |
Giulio Camuffo | 5085a75 | 2013-03-25 21:42:45 +0100 | [diff] [blame] | 3364 | wl_list_init(&shseat->popup_grab.surfaces_list); |
| 3365 | } |
| 3366 | } |
| 3367 | |
| 3368 | static void |
Jonny Lamb | 76cf1fe | 2014-08-20 11:27:10 +0200 | [diff] [blame] | 3369 | touch_popup_grab_end(struct weston_touch *touch) |
| 3370 | { |
| 3371 | struct weston_touch_grab *grab = touch->grab; |
| 3372 | struct shell_seat *shseat = |
| 3373 | container_of(grab, struct shell_seat, popup_grab.touch_grab); |
| 3374 | struct shell_surface *shsurf; |
Jonas Ådahl | c2b1011 | 2015-02-13 14:01:53 +0800 | [diff] [blame] | 3375 | struct shell_surface *next; |
Jonny Lamb | 76cf1fe | 2014-08-20 11:27:10 +0200 | [diff] [blame] | 3376 | |
| 3377 | if (touch->grab->interface == &touch_popup_grab_interface) { |
| 3378 | weston_touch_end_grab(grab->touch); |
| 3379 | shseat->popup_grab.client = NULL; |
| 3380 | shseat->popup_grab.touch_grab.interface = NULL; |
| 3381 | assert(!wl_list_empty(&shseat->popup_grab.surfaces_list)); |
| 3382 | /* Send the popup_done event to all the popups open */ |
Jonas Ådahl | c2b1011 | 2015-02-13 14:01:53 +0800 | [diff] [blame] | 3383 | wl_list_for_each_safe(shsurf, next, |
| 3384 | &shseat->popup_grab.surfaces_list, |
| 3385 | popup.grab_link) { |
Jonny Lamb | 76cf1fe | 2014-08-20 11:27:10 +0200 | [diff] [blame] | 3386 | shell_surface_send_popup_done(shsurf); |
| 3387 | shsurf->popup.shseat = NULL; |
Jonas Ådahl | c2b1011 | 2015-02-13 14:01:53 +0800 | [diff] [blame] | 3388 | wl_list_init(&shsurf->popup.grab_link); |
Jonny Lamb | 76cf1fe | 2014-08-20 11:27:10 +0200 | [diff] [blame] | 3389 | } |
Jonny Lamb | 76cf1fe | 2014-08-20 11:27:10 +0200 | [diff] [blame] | 3390 | wl_list_init(&shseat->popup_grab.surfaces_list); |
| 3391 | } |
| 3392 | } |
| 3393 | |
Jasper St. Pierre | da6ecd0 | 2015-02-27 18:35:45 +0800 | [diff] [blame] | 3394 | static struct shell_surface * |
| 3395 | get_top_popup(struct shell_seat *shseat) |
| 3396 | { |
| 3397 | struct shell_surface *shsurf; |
| 3398 | |
| 3399 | if (wl_list_empty(&shseat->popup_grab.surfaces_list)) { |
| 3400 | return NULL; |
| 3401 | } else { |
| 3402 | shsurf = container_of(shseat->popup_grab.surfaces_list.next, |
| 3403 | struct shell_surface, |
| 3404 | popup.grab_link); |
| 3405 | return shsurf; |
| 3406 | } |
| 3407 | } |
| 3408 | |
| 3409 | static int |
Jonas Ådahl | 01193ae | 2015-02-13 14:01:54 +0800 | [diff] [blame] | 3410 | add_popup_grab(struct shell_surface *shsurf, |
| 3411 | struct shell_seat *shseat, |
| 3412 | int32_t type) |
Giulio Camuffo | 5085a75 | 2013-03-25 21:42:45 +0100 | [diff] [blame] | 3413 | { |
Kristian Høgsberg | e314875 | 2013-05-06 23:19:49 -0400 | [diff] [blame] | 3414 | struct weston_seat *seat = shseat->seat; |
Jasper St. Pierre | da6ecd0 | 2015-02-27 18:35:45 +0800 | [diff] [blame] | 3415 | struct shell_surface *parent, *top_surface; |
| 3416 | |
| 3417 | parent = get_shell_surface(shsurf->parent); |
| 3418 | top_surface = get_top_popup(shseat); |
| 3419 | if (shell_surface_is_xdg_popup(shsurf) && |
Dima Ryazanov | 497f25d | 2015-04-08 11:51:57 -0700 | [diff] [blame] | 3420 | (!parent || |
| 3421 | (top_surface == NULL && !shell_surface_is_xdg_surface(parent)) || |
Jasper St. Pierre | da6ecd0 | 2015-02-27 18:35:45 +0800 | [diff] [blame] | 3422 | (top_surface != NULL && parent != top_surface))) { |
Jonas Ådahl | ee45a55 | 2015-03-18 16:37:47 +0800 | [diff] [blame] | 3423 | wl_resource_post_error(shsurf->owner_resource, |
| 3424 | XDG_SHELL_ERROR_NOT_THE_TOPMOST_POPUP, |
Jasper St. Pierre | da6ecd0 | 2015-02-27 18:35:45 +0800 | [diff] [blame] | 3425 | "xdg_popup was not created on the " |
| 3426 | "topmost popup"); |
| 3427 | return -1; |
| 3428 | } |
Giulio Camuffo | 5085a75 | 2013-03-25 21:42:45 +0100 | [diff] [blame] | 3429 | |
| 3430 | if (wl_list_empty(&shseat->popup_grab.surfaces_list)) { |
Jonny Lamb | 76cf1fe | 2014-08-20 11:27:10 +0200 | [diff] [blame] | 3431 | shseat->popup_grab.type = type; |
Jonas Ådahl | 01193ae | 2015-02-13 14:01:54 +0800 | [diff] [blame] | 3432 | shseat->popup_grab.client = |
| 3433 | wl_resource_get_client(shsurf->resource); |
Jonny Lamb | 76cf1fe | 2014-08-20 11:27:10 +0200 | [diff] [blame] | 3434 | |
| 3435 | if (type == POINTER) { |
Jonas Ådahl | 01193ae | 2015-02-13 14:01:54 +0800 | [diff] [blame] | 3436 | shseat->popup_grab.grab.interface = |
| 3437 | &popup_grab_interface; |
| 3438 | |
| 3439 | /* We must make sure here that this popup was opened |
| 3440 | * after a mouse press, and not just by moving around |
| 3441 | * with other popups already open. */ |
Jonny Lamb | 76cf1fe | 2014-08-20 11:27:10 +0200 | [diff] [blame] | 3442 | if (shseat->seat->pointer->button_count > 0) |
| 3443 | shseat->popup_grab.initial_up = 0; |
| 3444 | } else if (type == TOUCH) { |
Jonas Ådahl | 01193ae | 2015-02-13 14:01:54 +0800 | [diff] [blame] | 3445 | shseat->popup_grab.touch_grab.interface = |
| 3446 | &touch_popup_grab_interface; |
Jonny Lamb | 76cf1fe | 2014-08-20 11:27:10 +0200 | [diff] [blame] | 3447 | } |
Giulio Camuffo | 5085a75 | 2013-03-25 21:42:45 +0100 | [diff] [blame] | 3448 | |
Jonas Ådahl | 01193ae | 2015-02-13 14:01:54 +0800 | [diff] [blame] | 3449 | wl_list_insert(&shseat->popup_grab.surfaces_list, |
| 3450 | &shsurf->popup.grab_link); |
Jonny Lamb | 76cf1fe | 2014-08-20 11:27:10 +0200 | [diff] [blame] | 3451 | |
Jonas Ådahl | 01193ae | 2015-02-13 14:01:54 +0800 | [diff] [blame] | 3452 | if (type == POINTER) { |
| 3453 | weston_pointer_start_grab(seat->pointer, |
| 3454 | &shseat->popup_grab.grab); |
| 3455 | } else if (type == TOUCH) { |
| 3456 | weston_touch_start_grab(seat->touch, |
| 3457 | &shseat->popup_grab.touch_grab); |
| 3458 | } |
Rob Bradford | dfe3105 | 2013-06-26 19:49:11 +0100 | [diff] [blame] | 3459 | } else { |
Jonas Ådahl | 01193ae | 2015-02-13 14:01:54 +0800 | [diff] [blame] | 3460 | wl_list_insert(&shseat->popup_grab.surfaces_list, |
| 3461 | &shsurf->popup.grab_link); |
Giulio Camuffo | 5085a75 | 2013-03-25 21:42:45 +0100 | [diff] [blame] | 3462 | } |
Jasper St. Pierre | da6ecd0 | 2015-02-27 18:35:45 +0800 | [diff] [blame] | 3463 | |
| 3464 | return 0; |
Giulio Camuffo | 5085a75 | 2013-03-25 21:42:45 +0100 | [diff] [blame] | 3465 | } |
| 3466 | |
| 3467 | static void |
| 3468 | remove_popup_grab(struct shell_surface *shsurf) |
| 3469 | { |
| 3470 | struct shell_seat *shseat = shsurf->popup.shseat; |
| 3471 | |
Jasper St. Pierre | da6ecd0 | 2015-02-27 18:35:45 +0800 | [diff] [blame] | 3472 | if (shell_surface_is_xdg_popup(shsurf) && |
| 3473 | get_top_popup(shseat) != shsurf) { |
Jonas Ådahl | ee45a55 | 2015-03-18 16:37:47 +0800 | [diff] [blame] | 3474 | wl_resource_post_error(shsurf->owner_resource, |
| 3475 | XDG_SHELL_ERROR_NOT_THE_TOPMOST_POPUP, |
Jasper St. Pierre | da6ecd0 | 2015-02-27 18:35:45 +0800 | [diff] [blame] | 3476 | "xdg_popup was destroyed while it was " |
| 3477 | "not the topmost popup."); |
| 3478 | return; |
| 3479 | } |
| 3480 | |
Giulio Camuffo | 5085a75 | 2013-03-25 21:42:45 +0100 | [diff] [blame] | 3481 | wl_list_remove(&shsurf->popup.grab_link); |
| 3482 | wl_list_init(&shsurf->popup.grab_link); |
| 3483 | if (wl_list_empty(&shseat->popup_grab.surfaces_list)) { |
Jonny Lamb | 76cf1fe | 2014-08-20 11:27:10 +0200 | [diff] [blame] | 3484 | if (shseat->popup_grab.type == POINTER) { |
| 3485 | weston_pointer_end_grab(shseat->popup_grab.grab.pointer); |
| 3486 | shseat->popup_grab.grab.interface = NULL; |
| 3487 | } else if (shseat->popup_grab.type == TOUCH) { |
| 3488 | weston_touch_end_grab(shseat->popup_grab.touch_grab.touch); |
| 3489 | shseat->popup_grab.touch_grab.interface = NULL; |
| 3490 | } |
Kristian Høgsberg | 57e0907 | 2012-10-30 14:07:27 -0400 | [diff] [blame] | 3491 | } |
| 3492 | } |
| 3493 | |
Jasper St. Pierre | da6ecd0 | 2015-02-27 18:35:45 +0800 | [diff] [blame] | 3494 | static int |
Kristian Høgsberg | 3730f36 | 2012-04-13 12:40:07 -0400 | [diff] [blame] | 3495 | shell_map_popup(struct shell_surface *shsurf) |
Kristian Høgsberg | b3cca0a | 2012-01-04 22:19:14 -0500 | [diff] [blame] | 3496 | { |
Giulio Camuffo | 5085a75 | 2013-03-25 21:42:45 +0100 | [diff] [blame] | 3497 | struct shell_seat *shseat = shsurf->popup.shseat; |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 3498 | struct weston_view *parent_view = get_default_view(shsurf->parent); |
Kristian Høgsberg | b3cca0a | 2012-01-04 22:19:14 -0500 | [diff] [blame] | 3499 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 3500 | shsurf->surface->output = parent_view->output; |
| 3501 | shsurf->view->output = parent_view->output; |
Kristian Høgsberg | b3cca0a | 2012-01-04 22:19:14 -0500 | [diff] [blame] | 3502 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 3503 | weston_view_set_transform_parent(shsurf->view, parent_view); |
| 3504 | weston_view_set_position(shsurf->view, shsurf->popup.x, shsurf->popup.y); |
| 3505 | weston_view_update_transform(shsurf->view); |
Kristian Høgsberg | b3cca0a | 2012-01-04 22:19:14 -0500 | [diff] [blame] | 3506 | |
Jonny Lamb | e84ab4e | 2014-08-06 11:50:12 +0200 | [diff] [blame] | 3507 | if (shseat->seat->pointer && |
| 3508 | shseat->seat->pointer->grab_serial == shsurf->popup.serial) { |
Jasper St. Pierre | da6ecd0 | 2015-02-27 18:35:45 +0800 | [diff] [blame] | 3509 | if (add_popup_grab(shsurf, shseat, POINTER) != 0) |
| 3510 | return -1; |
Jonny Lamb | 76cf1fe | 2014-08-20 11:27:10 +0200 | [diff] [blame] | 3511 | } else if (shseat->seat->touch && |
| 3512 | shseat->seat->touch->grab_serial == shsurf->popup.serial) { |
Jasper St. Pierre | da6ecd0 | 2015-02-27 18:35:45 +0800 | [diff] [blame] | 3513 | if (add_popup_grab(shsurf, shseat, TOUCH) != 0) |
| 3514 | return -1; |
Kristian Høgsberg | 3730f36 | 2012-04-13 12:40:07 -0400 | [diff] [blame] | 3515 | } else { |
Rafael Antognolli | e2a3455 | 2013-12-03 15:35:45 -0200 | [diff] [blame] | 3516 | shell_surface_send_popup_done(shsurf); |
Giulio Camuffo | 5085a75 | 2013-03-25 21:42:45 +0100 | [diff] [blame] | 3517 | shseat->popup_grab.client = NULL; |
Kristian Høgsberg | 3730f36 | 2012-04-13 12:40:07 -0400 | [diff] [blame] | 3518 | } |
Jasper St. Pierre | da6ecd0 | 2015-02-27 18:35:45 +0800 | [diff] [blame] | 3519 | |
| 3520 | return 0; |
Kristian Høgsberg | b3cca0a | 2012-01-04 22:19:14 -0500 | [diff] [blame] | 3521 | } |
| 3522 | |
Pekka Paalanen | 9d1613e | 2011-11-25 12:09:16 +0200 | [diff] [blame] | 3523 | static const struct wl_shell_surface_interface shell_surface_implementation = { |
Scott Moreau | ff1db4a | 2012-04-17 19:06:18 -0600 | [diff] [blame] | 3524 | shell_surface_pong, |
Pekka Paalanen | 9d1613e | 2011-11-25 12:09:16 +0200 | [diff] [blame] | 3525 | shell_surface_move, |
| 3526 | shell_surface_resize, |
| 3527 | shell_surface_set_toplevel, |
| 3528 | shell_surface_set_transient, |
Kristian Høgsberg | b3cca0a | 2012-01-04 22:19:14 -0500 | [diff] [blame] | 3529 | shell_surface_set_fullscreen, |
Juan Zhao | 96879df | 2012-02-07 08:45:41 +0800 | [diff] [blame] | 3530 | shell_surface_set_popup, |
Kristian Høgsberg | e7afd91 | 2012-05-02 09:47:44 -0400 | [diff] [blame] | 3531 | shell_surface_set_maximized, |
| 3532 | shell_surface_set_title, |
| 3533 | shell_surface_set_class |
Pekka Paalanen | 9d1613e | 2011-11-25 12:09:16 +0200 | [diff] [blame] | 3534 | }; |
| 3535 | |
| 3536 | static void |
Tiago Vignatti | bc052c9 | 2012-04-19 16:18:18 +0300 | [diff] [blame] | 3537 | destroy_shell_surface(struct shell_surface *shsurf) |
Pekka Paalanen | 9d1613e | 2011-11-25 12:09:16 +0200 | [diff] [blame] | 3538 | { |
Kristian Høgsberg | 9046d24 | 2014-01-10 00:25:30 -0800 | [diff] [blame] | 3539 | struct shell_surface *child, *next; |
| 3540 | |
Jason Ekstrand | 651f00e | 2013-06-14 10:07:54 -0500 | [diff] [blame] | 3541 | wl_signal_emit(&shsurf->destroy_signal, shsurf); |
| 3542 | |
Giulio Camuffo | 5085a75 | 2013-03-25 21:42:45 +0100 | [diff] [blame] | 3543 | if (!wl_list_empty(&shsurf->popup.grab_link)) { |
| 3544 | remove_popup_grab(shsurf); |
| 3545 | } |
Kristian Høgsberg | b3cca0a | 2012-01-04 22:19:14 -0500 | [diff] [blame] | 3546 | |
Alex Wu | bd3354b | 2012-04-17 17:20:49 +0800 | [diff] [blame] | 3547 | if (shsurf->fullscreen.type == WL_SHELL_SURFACE_FULLSCREEN_METHOD_DRIVER && |
Alexander Larsson | f82b6ca | 2013-05-28 16:23:39 +0200 | [diff] [blame] | 3548 | shell_surface_is_top_fullscreen(shsurf)) |
| 3549 | restore_output_mode (shsurf->fullscreen_output); |
Pekka Paalanen | 9d1613e | 2011-11-25 12:09:16 +0200 | [diff] [blame] | 3550 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 3551 | if (shsurf->fullscreen.black_view) |
| 3552 | weston_surface_destroy(shsurf->fullscreen.black_view->surface); |
Alex Wu | aa08e2d | 2012-03-05 11:01:40 +0800 | [diff] [blame] | 3553 | |
Alex Wu | bd3354b | 2012-04-17 17:20:49 +0800 | [diff] [blame] | 3554 | /* As destroy_resource() use wl_list_for_each_safe(), |
| 3555 | * we can always remove the listener. |
| 3556 | */ |
| 3557 | wl_list_remove(&shsurf->surface_destroy_listener.link); |
| 3558 | shsurf->surface->configure = NULL; |
Pekka Paalanen | 8274d90 | 2014-08-06 19:36:51 +0300 | [diff] [blame] | 3559 | weston_surface_set_label_func(shsurf->surface, NULL); |
Scott Moreau | 976a050 | 2013-03-07 10:15:17 -0700 | [diff] [blame] | 3560 | free(shsurf->title); |
Alex Wu | bd3354b | 2012-04-17 17:20:49 +0800 | [diff] [blame] | 3561 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 3562 | weston_view_destroy(shsurf->view); |
| 3563 | |
Philip Withnall | 648a4dd | 2013-11-25 18:01:44 +0000 | [diff] [blame] | 3564 | wl_list_remove(&shsurf->children_link); |
Emilio Pozuelo Monfort | adaa20c | 2014-01-28 13:54:16 +0100 | [diff] [blame] | 3565 | wl_list_for_each_safe(child, next, &shsurf->children_list, children_link) |
| 3566 | shell_surface_set_parent(child, NULL); |
Philip Withnall | 648a4dd | 2013-11-25 18:01:44 +0000 | [diff] [blame] | 3567 | |
Pekka Paalanen | 9d1613e | 2011-11-25 12:09:16 +0200 | [diff] [blame] | 3568 | wl_list_remove(&shsurf->link); |
| 3569 | free(shsurf); |
| 3570 | } |
| 3571 | |
| 3572 | static void |
Tiago Vignatti | bc052c9 | 2012-04-19 16:18:18 +0300 | [diff] [blame] | 3573 | shell_destroy_shell_surface(struct wl_resource *resource) |
| 3574 | { |
Jason Ekstrand | 651f00e | 2013-06-14 10:07:54 -0500 | [diff] [blame] | 3575 | struct shell_surface *shsurf = wl_resource_get_user_data(resource); |
Tiago Vignatti | bc052c9 | 2012-04-19 16:18:18 +0300 | [diff] [blame] | 3576 | |
Bryan Cain | a46b946 | 2014-04-04 17:41:24 -0500 | [diff] [blame] | 3577 | if (!wl_list_empty(&shsurf->popup.grab_link)) |
| 3578 | remove_popup_grab(shsurf); |
Jonas Ådahl | 49d77d2 | 2015-03-18 16:20:51 +0800 | [diff] [blame] | 3579 | wl_list_remove(wl_resource_get_link(shsurf->resource)); |
Kristian Høgsberg | 160fe75 | 2014-03-11 10:19:10 -0700 | [diff] [blame] | 3580 | shsurf->resource = NULL; |
Tiago Vignatti | bc052c9 | 2012-04-19 16:18:18 +0300 | [diff] [blame] | 3581 | } |
| 3582 | |
| 3583 | static void |
Kristian Høgsberg | 27e3052 | 2012-04-11 23:18:23 -0400 | [diff] [blame] | 3584 | shell_handle_surface_destroy(struct wl_listener *listener, void *data) |
Pekka Paalanen | 9d1613e | 2011-11-25 12:09:16 +0200 | [diff] [blame] | 3585 | { |
| 3586 | struct shell_surface *shsurf = container_of(listener, |
| 3587 | struct shell_surface, |
| 3588 | surface_destroy_listener); |
| 3589 | |
Jason Ekstrand | 651f00e | 2013-06-14 10:07:54 -0500 | [diff] [blame] | 3590 | if (shsurf->resource) |
| 3591 | wl_resource_destroy(shsurf->resource); |
Ander Conselvan de Oliveira | 15f9a26 | 2014-04-29 17:54:02 +0300 | [diff] [blame] | 3592 | |
| 3593 | destroy_shell_surface(shsurf); |
Pekka Paalanen | 9d1613e | 2011-11-25 12:09:16 +0200 | [diff] [blame] | 3594 | } |
| 3595 | |
Kristian Høgsberg | d813445 | 2012-06-21 12:49:02 -0400 | [diff] [blame] | 3596 | static void |
Derek Foreman | 039e9be | 2015-04-14 17:09:06 -0500 | [diff] [blame] | 3597 | fade_out_done_idle_cb(void *data) |
Kristian Høgsberg | 160fe75 | 2014-03-11 10:19:10 -0700 | [diff] [blame] | 3598 | { |
| 3599 | struct shell_surface *shsurf = data; |
| 3600 | |
| 3601 | weston_surface_destroy(shsurf->surface); |
| 3602 | } |
| 3603 | |
| 3604 | static void |
Derek Foreman | 039e9be | 2015-04-14 17:09:06 -0500 | [diff] [blame] | 3605 | fade_out_done(struct weston_view_animation *animation, void *data) |
| 3606 | { |
| 3607 | struct shell_surface *shsurf = data; |
| 3608 | struct wl_event_loop *loop; |
| 3609 | |
| 3610 | loop = wl_display_get_event_loop( |
| 3611 | shsurf->surface->compositor->wl_display); |
| 3612 | |
| 3613 | if (!shsurf->destroying) { |
| 3614 | wl_event_loop_add_idle(loop, fade_out_done_idle_cb, shsurf); |
| 3615 | shsurf->destroying = true; |
| 3616 | } |
| 3617 | } |
| 3618 | |
| 3619 | static void |
Kristian Høgsberg | 160fe75 | 2014-03-11 10:19:10 -0700 | [diff] [blame] | 3620 | handle_resource_destroy(struct wl_listener *listener, void *data) |
| 3621 | { |
| 3622 | struct shell_surface *shsurf = |
| 3623 | container_of(listener, struct shell_surface, |
| 3624 | resource_destroy_listener); |
| 3625 | |
Ander Conselvan de Oliveira | 15f9a26 | 2014-04-29 17:54:02 +0300 | [diff] [blame] | 3626 | if (!weston_surface_is_mapped(shsurf->surface)) |
| 3627 | return; |
| 3628 | |
Kristian Høgsberg | 160fe75 | 2014-03-11 10:19:10 -0700 | [diff] [blame] | 3629 | shsurf->surface->ref_count++; |
| 3630 | |
| 3631 | pixman_region32_fini(&shsurf->surface->pending.input); |
| 3632 | pixman_region32_init(&shsurf->surface->pending.input); |
| 3633 | pixman_region32_fini(&shsurf->surface->input); |
| 3634 | pixman_region32_init(&shsurf->surface->input); |
Jonny Lamb | f322f8e | 2014-08-12 15:13:30 +0200 | [diff] [blame] | 3635 | if (shsurf->shell->win_close_animation_type == ANIMATION_FADE) { |
| 3636 | weston_fade_run(shsurf->view, 1.0, 0.0, 300.0, |
| 3637 | fade_out_done, shsurf); |
| 3638 | } else { |
| 3639 | weston_surface_destroy(shsurf->surface); |
| 3640 | } |
Kristian Høgsberg | 160fe75 | 2014-03-11 10:19:10 -0700 | [diff] [blame] | 3641 | } |
| 3642 | |
| 3643 | static void |
Jason Ekstrand | 918f2dd | 2013-12-02 21:01:53 -0600 | [diff] [blame] | 3644 | shell_surface_configure(struct weston_surface *, int32_t, int32_t); |
Kristian Høgsberg | d813445 | 2012-06-21 12:49:02 -0400 | [diff] [blame] | 3645 | |
Kristian Høgsberg | 1ef2313 | 2013-12-04 00:20:01 -0800 | [diff] [blame] | 3646 | struct shell_surface * |
Kristian Høgsberg | 8334bc1 | 2012-01-03 10:29:47 -0500 | [diff] [blame] | 3647 | get_shell_surface(struct weston_surface *surface) |
Pekka Paalanen | ec2b32f | 2011-11-28 15:12:34 +0200 | [diff] [blame] | 3648 | { |
Kristian Høgsberg | d813445 | 2012-06-21 12:49:02 -0400 | [diff] [blame] | 3649 | if (surface->configure == shell_surface_configure) |
Giulio Camuffo | 7fe01b1 | 2013-03-28 18:02:42 +0100 | [diff] [blame] | 3650 | return surface->configure_private; |
Kristian Høgsberg | d813445 | 2012-06-21 12:49:02 -0400 | [diff] [blame] | 3651 | else |
| 3652 | return NULL; |
Pekka Paalanen | ec2b32f | 2011-11-28 15:12:34 +0200 | [diff] [blame] | 3653 | } |
| 3654 | |
Rafael Antognolli | e2a3455 | 2013-12-03 15:35:45 -0200 | [diff] [blame] | 3655 | static struct shell_surface * |
Jason Ekstrand | 9e9512f | 2014-04-16 21:12:10 -0500 | [diff] [blame] | 3656 | create_common_surface(struct shell_client *owner, void *shell, |
| 3657 | struct weston_surface *surface, |
Rafael Antognolli | e2a3455 | 2013-12-03 15:35:45 -0200 | [diff] [blame] | 3658 | const struct weston_shell_client *client) |
Pekka Paalanen | 9d1613e | 2011-11-25 12:09:16 +0200 | [diff] [blame] | 3659 | { |
Pekka Paalanen | 9d1613e | 2011-11-25 12:09:16 +0200 | [diff] [blame] | 3660 | struct shell_surface *shsurf; |
| 3661 | |
Pekka Paalanen | 50b6747 | 2014-10-01 15:02:41 +0300 | [diff] [blame] | 3662 | assert(surface->configure == NULL); |
Ander Conselvan de Oliveira | 093bfa3 | 2012-03-27 17:36:41 +0300 | [diff] [blame] | 3663 | |
Pekka Paalanen | 9d1613e | 2011-11-25 12:09:16 +0200 | [diff] [blame] | 3664 | shsurf = calloc(1, sizeof *shsurf); |
| 3665 | if (!shsurf) { |
Martin Minarik | 6d11836 | 2012-06-07 18:01:59 +0200 | [diff] [blame] | 3666 | weston_log("no memory to allocate shell surface\n"); |
Kristian Høgsberg | 45ba869 | 2012-05-21 14:27:33 -0400 | [diff] [blame] | 3667 | return NULL; |
Pekka Paalanen | 9d1613e | 2011-11-25 12:09:16 +0200 | [diff] [blame] | 3668 | } |
| 3669 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 3670 | shsurf->view = weston_view_create(surface); |
| 3671 | if (!shsurf->view) { |
| 3672 | weston_log("no memory to allocate shell surface\n"); |
| 3673 | free(shsurf); |
| 3674 | return NULL; |
| 3675 | } |
| 3676 | |
Ander Conselvan de Oliveira | 093bfa3 | 2012-03-27 17:36:41 +0300 | [diff] [blame] | 3677 | surface->configure = shell_surface_configure; |
Giulio Camuffo | 7fe01b1 | 2013-03-28 18:02:42 +0100 | [diff] [blame] | 3678 | surface->configure_private = shsurf; |
Pekka Paalanen | 8274d90 | 2014-08-06 19:36:51 +0300 | [diff] [blame] | 3679 | weston_surface_set_label_func(surface, shell_surface_get_label); |
Ander Conselvan de Oliveira | 093bfa3 | 2012-03-27 17:36:41 +0300 | [diff] [blame] | 3680 | |
Kristian Høgsberg | 160fe75 | 2014-03-11 10:19:10 -0700 | [diff] [blame] | 3681 | shsurf->resource_destroy_listener.notify = handle_resource_destroy; |
| 3682 | wl_resource_add_destroy_listener(surface->resource, |
| 3683 | &shsurf->resource_destroy_listener); |
Jason Ekstrand | 9e9512f | 2014-04-16 21:12:10 -0500 | [diff] [blame] | 3684 | shsurf->owner = owner; |
Kristian Høgsberg | 160fe75 | 2014-03-11 10:19:10 -0700 | [diff] [blame] | 3685 | |
Tiago Vignatti | bc052c9 | 2012-04-19 16:18:18 +0300 | [diff] [blame] | 3686 | shsurf->shell = (struct desktop_shell *) shell; |
Scott Moreau | ff1db4a | 2012-04-17 19:06:18 -0600 | [diff] [blame] | 3687 | shsurf->unresponsive = 0; |
Alex Wu | 4539b08 | 2012-03-01 12:57:46 +0800 | [diff] [blame] | 3688 | shsurf->saved_position_valid = false; |
Rafael Antognolli | 3c4e3f7 | 2013-12-03 15:35:46 -0200 | [diff] [blame] | 3689 | shsurf->saved_size_valid = false; |
Alex Wu | 7bcb8bd | 2012-04-27 09:07:24 +0800 | [diff] [blame] | 3690 | shsurf->saved_rotation_valid = false; |
Pekka Paalanen | 9d1613e | 2011-11-25 12:09:16 +0200 | [diff] [blame] | 3691 | shsurf->surface = surface; |
Alex Wu | 4539b08 | 2012-03-01 12:57:46 +0800 | [diff] [blame] | 3692 | shsurf->fullscreen.type = WL_SHELL_SURFACE_FULLSCREEN_METHOD_DEFAULT; |
| 3693 | shsurf->fullscreen.framerate = 0; |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 3694 | shsurf->fullscreen.black_view = NULL; |
Alex Wu | 4539b08 | 2012-03-01 12:57:46 +0800 | [diff] [blame] | 3695 | wl_list_init(&shsurf->fullscreen.transform.link); |
| 3696 | |
Jasper St. Pierre | 9aa8ce6 | 2014-04-11 16:18:54 -0700 | [diff] [blame] | 3697 | shsurf->output = get_default_output(shsurf->shell->compositor); |
| 3698 | |
Jason Ekstrand | 651f00e | 2013-06-14 10:07:54 -0500 | [diff] [blame] | 3699 | wl_signal_init(&shsurf->destroy_signal); |
Kristian Høgsberg | 27e3052 | 2012-04-11 23:18:23 -0400 | [diff] [blame] | 3700 | shsurf->surface_destroy_listener.notify = shell_handle_surface_destroy; |
Jason Ekstrand | 26ed73c | 2013-06-06 22:34:41 -0500 | [diff] [blame] | 3701 | wl_signal_add(&surface->destroy_signal, |
Kristian Høgsberg | 27e3052 | 2012-04-11 23:18:23 -0400 | [diff] [blame] | 3702 | &shsurf->surface_destroy_listener); |
Pekka Paalanen | 9d1613e | 2011-11-25 12:09:16 +0200 | [diff] [blame] | 3703 | |
| 3704 | /* init link so its safe to always remove it in destroy_shell_surface */ |
| 3705 | wl_list_init(&shsurf->link); |
Giulio Camuffo | 5085a75 | 2013-03-25 21:42:45 +0100 | [diff] [blame] | 3706 | wl_list_init(&shsurf->popup.grab_link); |
Pekka Paalanen | 9d1613e | 2011-11-25 12:09:16 +0200 | [diff] [blame] | 3707 | |
Pekka Paalanen | 460099f | 2012-01-20 16:48:25 +0200 | [diff] [blame] | 3708 | /* empty when not in use */ |
| 3709 | wl_list_init(&shsurf->rotation.transform.link); |
Kristian Høgsberg | 765e27b | 2012-01-27 13:36:13 -0500 | [diff] [blame] | 3710 | weston_matrix_init(&shsurf->rotation.rotation); |
Pekka Paalanen | 460099f | 2012-01-20 16:48:25 +0200 | [diff] [blame] | 3711 | |
Jonas Ådahl | 62fcd04 | 2012-06-13 00:01:23 +0200 | [diff] [blame] | 3712 | wl_list_init(&shsurf->workspace_transform.link); |
| 3713 | |
Philip Withnall | 648a4dd | 2013-11-25 18:01:44 +0000 | [diff] [blame] | 3714 | wl_list_init(&shsurf->children_link); |
| 3715 | wl_list_init(&shsurf->children_list); |
| 3716 | shsurf->parent = NULL; |
| 3717 | |
Pekka Paalanen | b502654 | 2014-11-12 15:09:24 +0200 | [diff] [blame] | 3718 | set_type(shsurf, SHELL_SURFACE_NONE); |
Pekka Paalanen | 9d1613e | 2011-11-25 12:09:16 +0200 | [diff] [blame] | 3719 | |
Kristian Høgsberg | a61ca06 | 2012-05-22 16:05:52 -0400 | [diff] [blame] | 3720 | shsurf->client = client; |
| 3721 | |
Kristian Høgsberg | 45ba869 | 2012-05-21 14:27:33 -0400 | [diff] [blame] | 3722 | return shsurf; |
Tiago Vignatti | bc052c9 | 2012-04-19 16:18:18 +0300 | [diff] [blame] | 3723 | } |
| 3724 | |
Rafael Antognolli | e2a3455 | 2013-12-03 15:35:45 -0200 | [diff] [blame] | 3725 | static struct shell_surface * |
| 3726 | create_shell_surface(void *shell, struct weston_surface *surface, |
| 3727 | const struct weston_shell_client *client) |
| 3728 | { |
Jason Ekstrand | 9e9512f | 2014-04-16 21:12:10 -0500 | [diff] [blame] | 3729 | return create_common_surface(NULL, shell, surface, client); |
Rafael Antognolli | e2a3455 | 2013-12-03 15:35:45 -0200 | [diff] [blame] | 3730 | } |
| 3731 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 3732 | static struct weston_view * |
| 3733 | get_primary_view(void *shell, struct shell_surface *shsurf) |
| 3734 | { |
| 3735 | return shsurf->view; |
| 3736 | } |
| 3737 | |
Tiago Vignatti | bc052c9 | 2012-04-19 16:18:18 +0300 | [diff] [blame] | 3738 | static void |
| 3739 | shell_get_shell_surface(struct wl_client *client, |
| 3740 | struct wl_resource *resource, |
| 3741 | uint32_t id, |
| 3742 | struct wl_resource *surface_resource) |
| 3743 | { |
Jason Ekstrand | 0f2ef7e | 2013-06-14 10:07:53 -0500 | [diff] [blame] | 3744 | struct weston_surface *surface = |
| 3745 | wl_resource_get_user_data(surface_resource); |
Jason Ekstrand | 9e9512f | 2014-04-16 21:12:10 -0500 | [diff] [blame] | 3746 | struct shell_client *sc = wl_resource_get_user_data(resource); |
| 3747 | struct desktop_shell *shell = sc->shell; |
Tiago Vignatti | bc052c9 | 2012-04-19 16:18:18 +0300 | [diff] [blame] | 3748 | struct shell_surface *shsurf; |
| 3749 | |
Pekka Paalanen | 50b6747 | 2014-10-01 15:02:41 +0300 | [diff] [blame] | 3750 | if (weston_surface_set_role(surface, "wl_shell_surface", |
| 3751 | resource, WL_SHELL_ERROR_ROLE) < 0) |
Tiago Vignatti | bc052c9 | 2012-04-19 16:18:18 +0300 | [diff] [blame] | 3752 | return; |
Tiago Vignatti | bc052c9 | 2012-04-19 16:18:18 +0300 | [diff] [blame] | 3753 | |
Jason Ekstrand | 9e9512f | 2014-04-16 21:12:10 -0500 | [diff] [blame] | 3754 | shsurf = create_common_surface(sc, shell, surface, &shell_client); |
Kristian Høgsberg | 9540ea6 | 2012-05-21 14:28:57 -0400 | [diff] [blame] | 3755 | if (!shsurf) { |
Pekka Paalanen | 50b6747 | 2014-10-01 15:02:41 +0300 | [diff] [blame] | 3756 | wl_resource_post_no_memory(surface_resource); |
Kristian Høgsberg | 9540ea6 | 2012-05-21 14:28:57 -0400 | [diff] [blame] | 3757 | return; |
| 3758 | } |
Tiago Vignatti | bc052c9 | 2012-04-19 16:18:18 +0300 | [diff] [blame] | 3759 | |
Jason Ekstrand | a85118c | 2013-06-27 20:17:02 -0500 | [diff] [blame] | 3760 | shsurf->resource = |
| 3761 | wl_resource_create(client, |
| 3762 | &wl_shell_surface_interface, 1, id); |
| 3763 | wl_resource_set_implementation(shsurf->resource, |
| 3764 | &shell_surface_implementation, |
| 3765 | shsurf, shell_destroy_shell_surface); |
Jonas Ådahl | 49d77d2 | 2015-03-18 16:20:51 +0800 | [diff] [blame] | 3766 | wl_list_init(wl_resource_get_link(shsurf->resource)); |
Pekka Paalanen | 9d1613e | 2011-11-25 12:09:16 +0200 | [diff] [blame] | 3767 | } |
| 3768 | |
Rafael Antognolli | e2a3455 | 2013-12-03 15:35:45 -0200 | [diff] [blame] | 3769 | static bool |
| 3770 | shell_surface_is_wl_shell_surface(struct shell_surface *shsurf) |
| 3771 | { |
Kristian Høgsberg | 0b7d995 | 2014-02-03 15:50:38 -0800 | [diff] [blame] | 3772 | /* A shell surface without a resource is created from xwayland |
| 3773 | * and is considered a wl_shell surface for now. */ |
| 3774 | |
| 3775 | return shsurf->resource == NULL || |
| 3776 | wl_resource_instance_of(shsurf->resource, |
| 3777 | &wl_shell_surface_interface, |
| 3778 | &shell_surface_implementation); |
Rafael Antognolli | e2a3455 | 2013-12-03 15:35:45 -0200 | [diff] [blame] | 3779 | } |
| 3780 | |
Pekka Paalanen | 9d1613e | 2011-11-25 12:09:16 +0200 | [diff] [blame] | 3781 | static const struct wl_shell_interface shell_implementation = { |
Pekka Paalanen | 4622967 | 2011-11-29 15:49:31 +0200 | [diff] [blame] | 3782 | shell_get_shell_surface |
Kristian Høgsberg | 4cca349 | 2011-01-18 07:53:49 -0500 | [diff] [blame] | 3783 | }; |
| 3784 | |
Rafael Antognolli | e2a3455 | 2013-12-03 15:35:45 -0200 | [diff] [blame] | 3785 | /**************************** |
| 3786 | * xdg-shell implementation */ |
| 3787 | |
| 3788 | static void |
| 3789 | xdg_surface_destroy(struct wl_client *client, |
| 3790 | struct wl_resource *resource) |
| 3791 | { |
| 3792 | wl_resource_destroy(resource); |
| 3793 | } |
| 3794 | |
| 3795 | static void |
Jasper St. Pierre | c815d62 | 2014-04-10 18:37:54 -0700 | [diff] [blame] | 3796 | xdg_surface_set_parent(struct wl_client *client, |
| 3797 | struct wl_resource *resource, |
| 3798 | struct wl_resource *parent_resource) |
Jasper St. Pierre | 63a9c33 | 2014-02-01 18:35:15 -0500 | [diff] [blame] | 3799 | { |
| 3800 | struct shell_surface *shsurf = wl_resource_get_user_data(resource); |
Jasper St. Pierre | 66bc949 | 2015-02-13 14:01:55 +0800 | [diff] [blame] | 3801 | struct shell_surface *parent; |
Jasper St. Pierre | 63a9c33 | 2014-02-01 18:35:15 -0500 | [diff] [blame] | 3802 | |
Jasper St. Pierre | 66bc949 | 2015-02-13 14:01:55 +0800 | [diff] [blame] | 3803 | if (parent_resource) { |
Jasper St. Pierre | 63a9c33 | 2014-02-01 18:35:15 -0500 | [diff] [blame] | 3804 | parent = wl_resource_get_user_data(parent_resource); |
Jasper St. Pierre | 66bc949 | 2015-02-13 14:01:55 +0800 | [diff] [blame] | 3805 | shell_surface_set_parent(shsurf, parent->surface); |
| 3806 | } else { |
| 3807 | shell_surface_set_parent(shsurf, NULL); |
| 3808 | } |
Jasper St. Pierre | 63a9c33 | 2014-02-01 18:35:15 -0500 | [diff] [blame] | 3809 | } |
| 3810 | |
| 3811 | static void |
Rafael Antognolli | e2a3455 | 2013-12-03 15:35:45 -0200 | [diff] [blame] | 3812 | xdg_surface_set_app_id(struct wl_client *client, |
| 3813 | struct wl_resource *resource, |
| 3814 | const char *app_id) |
| 3815 | { |
| 3816 | struct shell_surface *shsurf = wl_resource_get_user_data(resource); |
| 3817 | |
| 3818 | free(shsurf->class); |
| 3819 | shsurf->class = strdup(app_id); |
Pekka Paalanen | b502654 | 2014-11-12 15:09:24 +0200 | [diff] [blame] | 3820 | shsurf->surface->timeline.force_refresh = 1; |
Rafael Antognolli | e2a3455 | 2013-12-03 15:35:45 -0200 | [diff] [blame] | 3821 | } |
| 3822 | |
| 3823 | static void |
Jasper St. Pierre | 81ff075 | 2014-03-13 11:04:53 -0400 | [diff] [blame] | 3824 | xdg_surface_show_window_menu(struct wl_client *client, |
| 3825 | struct wl_resource *surface_resource, |
| 3826 | struct wl_resource *seat_resource, |
| 3827 | uint32_t serial, |
| 3828 | int32_t x, |
| 3829 | int32_t y) |
| 3830 | { |
| 3831 | /* TODO */ |
| 3832 | } |
| 3833 | |
| 3834 | static void |
Rafael Antognolli | e2a3455 | 2013-12-03 15:35:45 -0200 | [diff] [blame] | 3835 | xdg_surface_set_title(struct wl_client *client, |
| 3836 | struct wl_resource *resource, const char *title) |
| 3837 | { |
| 3838 | struct shell_surface *shsurf = wl_resource_get_user_data(resource); |
| 3839 | |
| 3840 | set_title(shsurf, title); |
| 3841 | } |
| 3842 | |
| 3843 | static void |
| 3844 | xdg_surface_move(struct wl_client *client, struct wl_resource *resource, |
| 3845 | struct wl_resource *seat_resource, uint32_t serial) |
| 3846 | { |
| 3847 | common_surface_move(resource, seat_resource, serial); |
| 3848 | } |
| 3849 | |
| 3850 | static void |
| 3851 | xdg_surface_resize(struct wl_client *client, struct wl_resource *resource, |
| 3852 | struct wl_resource *seat_resource, uint32_t serial, |
| 3853 | uint32_t edges) |
| 3854 | { |
| 3855 | common_surface_resize(resource, seat_resource, serial, edges); |
| 3856 | } |
| 3857 | |
| 3858 | static void |
Jasper St. Pierre | ab2c108 | 2014-04-10 10:41:46 -0700 | [diff] [blame] | 3859 | xdg_surface_ack_configure(struct wl_client *client, |
| 3860 | struct wl_resource *resource, |
| 3861 | uint32_t serial) |
Rafael Antognolli | e2a3455 | 2013-12-03 15:35:45 -0200 | [diff] [blame] | 3862 | { |
| 3863 | struct shell_surface *shsurf = wl_resource_get_user_data(resource); |
| 3864 | |
Jasper St. Pierre | 8c6aa45 | 2014-02-08 18:29:49 -0500 | [diff] [blame] | 3865 | if (shsurf->state_requested) { |
| 3866 | shsurf->next_state = shsurf->requested_state; |
| 3867 | shsurf->state_changed = true; |
| 3868 | shsurf->state_requested = false; |
Rafael Antognolli | 3c4e3f7 | 2013-12-03 15:35:46 -0200 | [diff] [blame] | 3869 | } |
Rafael Antognolli | e2a3455 | 2013-12-03 15:35:45 -0200 | [diff] [blame] | 3870 | } |
| 3871 | |
Manuel Bachmann | 50c87db | 2014-02-26 15:52:13 +0100 | [diff] [blame] | 3872 | static void |
Jasper St. Pierre | ccf48fb | 2014-05-02 10:21:38 -0400 | [diff] [blame] | 3873 | xdg_surface_set_window_geometry(struct wl_client *client, |
| 3874 | struct wl_resource *resource, |
| 3875 | int32_t x, |
| 3876 | int32_t y, |
| 3877 | int32_t width, |
| 3878 | int32_t height) |
| 3879 | { |
| 3880 | struct shell_surface *shsurf = wl_resource_get_user_data(resource); |
| 3881 | |
| 3882 | set_window_geometry(shsurf, x, y, width, height); |
| 3883 | } |
| 3884 | |
| 3885 | static void |
Jasper St. Pierre | ab2c108 | 2014-04-10 10:41:46 -0700 | [diff] [blame] | 3886 | xdg_surface_set_maximized(struct wl_client *client, |
| 3887 | struct wl_resource *resource) |
| 3888 | { |
| 3889 | struct shell_surface *shsurf = wl_resource_get_user_data(resource); |
Marek Chalupa | bfbb64b | 2014-09-08 12:34:20 +0200 | [diff] [blame] | 3890 | struct weston_output *output; |
Jasper St. Pierre | ab2c108 | 2014-04-10 10:41:46 -0700 | [diff] [blame] | 3891 | |
| 3892 | shsurf->state_requested = true; |
| 3893 | shsurf->requested_state.maximized = true; |
Marek Chalupa | bfbb64b | 2014-09-08 12:34:20 +0200 | [diff] [blame] | 3894 | |
| 3895 | if (!weston_surface_is_mapped(shsurf->surface)) |
| 3896 | output = get_focused_output(shsurf->surface->compositor); |
| 3897 | else |
| 3898 | output = shsurf->surface->output; |
| 3899 | |
| 3900 | shell_surface_set_output(shsurf, output); |
Jasper St. Pierre | 9aa8ce6 | 2014-04-11 16:18:54 -0700 | [diff] [blame] | 3901 | send_configure_for_surface(shsurf); |
Jasper St. Pierre | ab2c108 | 2014-04-10 10:41:46 -0700 | [diff] [blame] | 3902 | } |
| 3903 | |
| 3904 | static void |
| 3905 | xdg_surface_unset_maximized(struct wl_client *client, |
| 3906 | struct wl_resource *resource) |
| 3907 | { |
| 3908 | struct shell_surface *shsurf = wl_resource_get_user_data(resource); |
| 3909 | |
| 3910 | shsurf->state_requested = true; |
| 3911 | shsurf->requested_state.maximized = false; |
Jasper St. Pierre | 6458ec3 | 2014-04-11 16:00:31 -0700 | [diff] [blame] | 3912 | send_configure_for_surface(shsurf); |
Jasper St. Pierre | ab2c108 | 2014-04-10 10:41:46 -0700 | [diff] [blame] | 3913 | } |
| 3914 | |
| 3915 | static void |
| 3916 | xdg_surface_set_fullscreen(struct wl_client *client, |
| 3917 | struct wl_resource *resource, |
| 3918 | struct wl_resource *output_resource) |
| 3919 | { |
| 3920 | struct shell_surface *shsurf = wl_resource_get_user_data(resource); |
| 3921 | struct weston_output *output; |
| 3922 | |
| 3923 | shsurf->state_requested = true; |
| 3924 | shsurf->requested_state.fullscreen = true; |
| 3925 | |
| 3926 | if (output_resource) |
| 3927 | output = wl_resource_get_user_data(output_resource); |
| 3928 | else |
| 3929 | output = NULL; |
| 3930 | |
Marek Chalupa | 052917a | 2014-09-02 11:35:12 +0200 | [diff] [blame] | 3931 | /* handle clients launching in fullscreen */ |
| 3932 | if (output == NULL && !weston_surface_is_mapped(shsurf->surface)) { |
| 3933 | /* Set the output to the one that has focus currently. */ |
| 3934 | assert(shsurf->surface); |
| 3935 | output = get_focused_output(shsurf->surface->compositor); |
| 3936 | } |
| 3937 | |
Jasper St. Pierre | 9aa8ce6 | 2014-04-11 16:18:54 -0700 | [diff] [blame] | 3938 | shell_surface_set_output(shsurf, output); |
| 3939 | shsurf->fullscreen_output = shsurf->output; |
Jasper St. Pierre | ab2c108 | 2014-04-10 10:41:46 -0700 | [diff] [blame] | 3940 | |
Jasper St. Pierre | 9aa8ce6 | 2014-04-11 16:18:54 -0700 | [diff] [blame] | 3941 | send_configure_for_surface(shsurf); |
Jasper St. Pierre | ab2c108 | 2014-04-10 10:41:46 -0700 | [diff] [blame] | 3942 | } |
| 3943 | |
| 3944 | static void |
| 3945 | xdg_surface_unset_fullscreen(struct wl_client *client, |
| 3946 | struct wl_resource *resource) |
| 3947 | { |
| 3948 | struct shell_surface *shsurf = wl_resource_get_user_data(resource); |
| 3949 | |
| 3950 | shsurf->state_requested = true; |
| 3951 | shsurf->requested_state.fullscreen = false; |
Jasper St. Pierre | 6458ec3 | 2014-04-11 16:00:31 -0700 | [diff] [blame] | 3952 | send_configure_for_surface(shsurf); |
Jasper St. Pierre | ab2c108 | 2014-04-10 10:41:46 -0700 | [diff] [blame] | 3953 | } |
| 3954 | |
| 3955 | static void |
Manuel Bachmann | 50c87db | 2014-02-26 15:52:13 +0100 | [diff] [blame] | 3956 | xdg_surface_set_minimized(struct wl_client *client, |
| 3957 | struct wl_resource *resource) |
| 3958 | { |
| 3959 | struct shell_surface *shsurf = wl_resource_get_user_data(resource); |
| 3960 | |
| 3961 | if (shsurf->type != SHELL_SURFACE_TOPLEVEL) |
| 3962 | return; |
| 3963 | |
| 3964 | /* apply compositor's own minimization logic (hide) */ |
Manuel Bachmann | dc1c3e4 | 2015-02-16 11:52:13 +0100 | [diff] [blame] | 3965 | set_minimized(shsurf->surface); |
Manuel Bachmann | 50c87db | 2014-02-26 15:52:13 +0100 | [diff] [blame] | 3966 | } |
| 3967 | |
Rafael Antognolli | e2a3455 | 2013-12-03 15:35:45 -0200 | [diff] [blame] | 3968 | static const struct xdg_surface_interface xdg_surface_implementation = { |
| 3969 | xdg_surface_destroy, |
Jasper St. Pierre | c815d62 | 2014-04-10 18:37:54 -0700 | [diff] [blame] | 3970 | xdg_surface_set_parent, |
Rafael Antognolli | e2a3455 | 2013-12-03 15:35:45 -0200 | [diff] [blame] | 3971 | xdg_surface_set_title, |
| 3972 | xdg_surface_set_app_id, |
Jasper St. Pierre | 81ff075 | 2014-03-13 11:04:53 -0400 | [diff] [blame] | 3973 | xdg_surface_show_window_menu, |
Rafael Antognolli | e2a3455 | 2013-12-03 15:35:45 -0200 | [diff] [blame] | 3974 | xdg_surface_move, |
| 3975 | xdg_surface_resize, |
Jasper St. Pierre | ab2c108 | 2014-04-10 10:41:46 -0700 | [diff] [blame] | 3976 | xdg_surface_ack_configure, |
Jasper St. Pierre | ccf48fb | 2014-05-02 10:21:38 -0400 | [diff] [blame] | 3977 | xdg_surface_set_window_geometry, |
Jasper St. Pierre | ab2c108 | 2014-04-10 10:41:46 -0700 | [diff] [blame] | 3978 | xdg_surface_set_maximized, |
| 3979 | xdg_surface_unset_maximized, |
| 3980 | xdg_surface_set_fullscreen, |
| 3981 | xdg_surface_unset_fullscreen, |
| 3982 | xdg_surface_set_minimized, |
Rafael Antognolli | e2a3455 | 2013-12-03 15:35:45 -0200 | [diff] [blame] | 3983 | }; |
| 3984 | |
| 3985 | static void |
| 3986 | xdg_send_configure(struct weston_surface *surface, |
Jasper St. Pierre | ac985be | 2014-04-28 11:19:28 -0400 | [diff] [blame] | 3987 | int32_t width, int32_t height) |
Rafael Antognolli | e2a3455 | 2013-12-03 15:35:45 -0200 | [diff] [blame] | 3988 | { |
| 3989 | struct shell_surface *shsurf = get_shell_surface(surface); |
Jasper St. Pierre | ab2c108 | 2014-04-10 10:41:46 -0700 | [diff] [blame] | 3990 | uint32_t *s; |
| 3991 | struct wl_array states; |
| 3992 | uint32_t serial; |
Rafael Antognolli | e2a3455 | 2013-12-03 15:35:45 -0200 | [diff] [blame] | 3993 | |
U. Artie Eoff | cf5737a | 2014-01-17 10:08:25 -0800 | [diff] [blame] | 3994 | assert(shsurf); |
| 3995 | |
Jasper St. Pierre | ab2c108 | 2014-04-10 10:41:46 -0700 | [diff] [blame] | 3996 | if (!shsurf->resource) |
| 3997 | return; |
| 3998 | |
| 3999 | wl_array_init(&states); |
| 4000 | if (shsurf->requested_state.fullscreen) { |
| 4001 | s = wl_array_add(&states, sizeof *s); |
| 4002 | *s = XDG_SURFACE_STATE_FULLSCREEN; |
| 4003 | } else if (shsurf->requested_state.maximized) { |
| 4004 | s = wl_array_add(&states, sizeof *s); |
| 4005 | *s = XDG_SURFACE_STATE_MAXIMIZED; |
| 4006 | } |
Jasper St. Pierre | 5befdda | 2014-05-06 08:50:47 -0400 | [diff] [blame] | 4007 | if (shsurf->resize_edges != 0) { |
| 4008 | s = wl_array_add(&states, sizeof *s); |
| 4009 | *s = XDG_SURFACE_STATE_RESIZING; |
| 4010 | } |
Jasper St. Pierre | 973d787 | 2014-05-06 08:44:29 -0400 | [diff] [blame] | 4011 | if (shsurf->focus_count > 0) { |
| 4012 | s = wl_array_add(&states, sizeof *s); |
| 4013 | *s = XDG_SURFACE_STATE_ACTIVATED; |
| 4014 | } |
Jasper St. Pierre | ab2c108 | 2014-04-10 10:41:46 -0700 | [diff] [blame] | 4015 | |
| 4016 | serial = wl_display_next_serial(shsurf->surface->compositor->wl_display); |
| 4017 | xdg_surface_send_configure(shsurf->resource, width, height, &states, serial); |
| 4018 | |
| 4019 | wl_array_release(&states); |
Rafael Antognolli | e2a3455 | 2013-12-03 15:35:45 -0200 | [diff] [blame] | 4020 | } |
| 4021 | |
| 4022 | static const struct weston_shell_client xdg_client = { |
| 4023 | xdg_send_configure |
| 4024 | }; |
| 4025 | |
| 4026 | static void |
Jasper St. Pierre | 084aa0b | 2015-02-13 14:02:00 +0800 | [diff] [blame] | 4027 | xdg_shell_destroy(struct wl_client *client, |
| 4028 | struct wl_resource *resource) |
| 4029 | { |
Jonas Ådahl | 49d77d2 | 2015-03-18 16:20:51 +0800 | [diff] [blame] | 4030 | struct shell_client *sc = wl_resource_get_user_data(resource); |
| 4031 | struct wl_resource *shsurf_resource; |
| 4032 | struct shell_surface *shsurf; |
| 4033 | |
| 4034 | wl_resource_for_each(shsurf_resource, &sc->surface_list) { |
| 4035 | shsurf = wl_resource_get_user_data(shsurf_resource); |
| 4036 | if (shsurf->owner_resource == resource) { |
| 4037 | wl_resource_post_error( |
| 4038 | resource, |
| 4039 | XDG_SHELL_ERROR_DEFUNCT_SURFACES, |
| 4040 | "not all child surface objects destroyed"); |
| 4041 | return; |
| 4042 | } |
| 4043 | } |
| 4044 | |
Jasper St. Pierre | 084aa0b | 2015-02-13 14:02:00 +0800 | [diff] [blame] | 4045 | wl_resource_destroy(resource); |
| 4046 | } |
| 4047 | |
| 4048 | static void |
Rafael Antognolli | e2a3455 | 2013-12-03 15:35:45 -0200 | [diff] [blame] | 4049 | xdg_use_unstable_version(struct wl_client *client, |
| 4050 | struct wl_resource *resource, |
| 4051 | int32_t version) |
| 4052 | { |
| 4053 | if (version > 1) { |
| 4054 | wl_resource_post_error(resource, |
| 4055 | 1, |
| 4056 | "xdg-shell:: version not implemented yet."); |
| 4057 | return; |
| 4058 | } |
| 4059 | } |
| 4060 | |
| 4061 | static struct shell_surface * |
Jason Ekstrand | 9e9512f | 2014-04-16 21:12:10 -0500 | [diff] [blame] | 4062 | create_xdg_surface(struct shell_client *owner, void *shell, |
| 4063 | struct weston_surface *surface, |
Rafael Antognolli | e2a3455 | 2013-12-03 15:35:45 -0200 | [diff] [blame] | 4064 | const struct weston_shell_client *client) |
| 4065 | { |
| 4066 | struct shell_surface *shsurf; |
Rafael Antognolli | e2a3455 | 2013-12-03 15:35:45 -0200 | [diff] [blame] | 4067 | |
Jason Ekstrand | 9e9512f | 2014-04-16 21:12:10 -0500 | [diff] [blame] | 4068 | shsurf = create_common_surface(owner, shell, surface, client); |
Pekka Paalanen | e972b27 | 2014-10-01 14:03:56 +0300 | [diff] [blame] | 4069 | if (!shsurf) |
| 4070 | return NULL; |
| 4071 | |
Pekka Paalanen | b502654 | 2014-11-12 15:09:24 +0200 | [diff] [blame] | 4072 | set_type(shsurf, SHELL_SURFACE_TOPLEVEL); |
Rafael Antognolli | e2a3455 | 2013-12-03 15:35:45 -0200 | [diff] [blame] | 4073 | |
| 4074 | return shsurf; |
| 4075 | } |
| 4076 | |
| 4077 | static void |
| 4078 | xdg_get_xdg_surface(struct wl_client *client, |
| 4079 | struct wl_resource *resource, |
| 4080 | uint32_t id, |
| 4081 | struct wl_resource *surface_resource) |
| 4082 | { |
| 4083 | struct weston_surface *surface = |
| 4084 | wl_resource_get_user_data(surface_resource); |
Kristian Høgsberg | 2bff94e | 2014-02-11 12:22:51 -0800 | [diff] [blame] | 4085 | struct shell_client *sc = wl_resource_get_user_data(resource); |
| 4086 | struct desktop_shell *shell = sc->shell; |
Rafael Antognolli | e2a3455 | 2013-12-03 15:35:45 -0200 | [diff] [blame] | 4087 | struct shell_surface *shsurf; |
| 4088 | |
Jonas Ådahl | bf48e21 | 2015-02-06 10:15:28 +0800 | [diff] [blame] | 4089 | shsurf = get_shell_surface(surface); |
| 4090 | if (shsurf && shell_surface_is_xdg_surface(shsurf)) { |
| 4091 | wl_resource_post_error(resource, XDG_SHELL_ERROR_ROLE, |
| 4092 | "This wl_surface is already an " |
| 4093 | "xdg_surface"); |
| 4094 | return; |
| 4095 | } |
| 4096 | |
Pekka Paalanen | 50b6747 | 2014-10-01 15:02:41 +0300 | [diff] [blame] | 4097 | if (weston_surface_set_role(surface, "xdg_surface", |
| 4098 | resource, XDG_SHELL_ERROR_ROLE) < 0) |
Rafael Antognolli | e2a3455 | 2013-12-03 15:35:45 -0200 | [diff] [blame] | 4099 | return; |
Rafael Antognolli | e2a3455 | 2013-12-03 15:35:45 -0200 | [diff] [blame] | 4100 | |
Jason Ekstrand | 9e9512f | 2014-04-16 21:12:10 -0500 | [diff] [blame] | 4101 | shsurf = create_xdg_surface(sc, shell, surface, &xdg_client); |
Rafael Antognolli | e2a3455 | 2013-12-03 15:35:45 -0200 | [diff] [blame] | 4102 | if (!shsurf) { |
Pekka Paalanen | 50b6747 | 2014-10-01 15:02:41 +0300 | [diff] [blame] | 4103 | wl_resource_post_no_memory(surface_resource); |
Rafael Antognolli | e2a3455 | 2013-12-03 15:35:45 -0200 | [diff] [blame] | 4104 | return; |
| 4105 | } |
| 4106 | |
| 4107 | shsurf->resource = |
| 4108 | wl_resource_create(client, |
| 4109 | &xdg_surface_interface, 1, id); |
| 4110 | wl_resource_set_implementation(shsurf->resource, |
| 4111 | &xdg_surface_implementation, |
| 4112 | shsurf, shell_destroy_shell_surface); |
Jonas Ådahl | 49d77d2 | 2015-03-18 16:20:51 +0800 | [diff] [blame] | 4113 | shsurf->owner_resource = resource; |
| 4114 | wl_list_insert(&sc->surface_list, |
| 4115 | wl_resource_get_link(shsurf->resource)); |
Rafael Antognolli | e2a3455 | 2013-12-03 15:35:45 -0200 | [diff] [blame] | 4116 | } |
| 4117 | |
| 4118 | static bool |
| 4119 | shell_surface_is_xdg_surface(struct shell_surface *shsurf) |
| 4120 | { |
Kristian Høgsberg | 0b7d995 | 2014-02-03 15:50:38 -0800 | [diff] [blame] | 4121 | return shsurf->resource && |
| 4122 | wl_resource_instance_of(shsurf->resource, |
| 4123 | &xdg_surface_interface, |
| 4124 | &xdg_surface_implementation); |
Rafael Antognolli | e2a3455 | 2013-12-03 15:35:45 -0200 | [diff] [blame] | 4125 | } |
| 4126 | |
| 4127 | /* xdg-popup implementation */ |
| 4128 | |
| 4129 | static void |
| 4130 | xdg_popup_destroy(struct wl_client *client, |
| 4131 | struct wl_resource *resource) |
| 4132 | { |
| 4133 | wl_resource_destroy(resource); |
| 4134 | } |
| 4135 | |
Rafael Antognolli | e2a3455 | 2013-12-03 15:35:45 -0200 | [diff] [blame] | 4136 | static const struct xdg_popup_interface xdg_popup_implementation = { |
| 4137 | xdg_popup_destroy, |
Rafael Antognolli | e2a3455 | 2013-12-03 15:35:45 -0200 | [diff] [blame] | 4138 | }; |
| 4139 | |
| 4140 | static void |
| 4141 | xdg_popup_send_configure(struct weston_surface *surface, |
Jasper St. Pierre | ac985be | 2014-04-28 11:19:28 -0400 | [diff] [blame] | 4142 | int32_t width, int32_t height) |
Rafael Antognolli | e2a3455 | 2013-12-03 15:35:45 -0200 | [diff] [blame] | 4143 | { |
| 4144 | } |
| 4145 | |
| 4146 | static const struct weston_shell_client xdg_popup_client = { |
| 4147 | xdg_popup_send_configure |
| 4148 | }; |
| 4149 | |
| 4150 | static struct shell_surface * |
Jason Ekstrand | 9e9512f | 2014-04-16 21:12:10 -0500 | [diff] [blame] | 4151 | create_xdg_popup(struct shell_client *owner, void *shell, |
| 4152 | struct weston_surface *surface, |
Rafael Antognolli | e2a3455 | 2013-12-03 15:35:45 -0200 | [diff] [blame] | 4153 | const struct weston_shell_client *client, |
| 4154 | struct weston_surface *parent, |
| 4155 | struct shell_seat *seat, |
| 4156 | uint32_t serial, |
| 4157 | int32_t x, int32_t y) |
| 4158 | { |
Jonas Ådahl | ee45a55 | 2015-03-18 16:37:47 +0800 | [diff] [blame] | 4159 | struct shell_surface *shsurf; |
Jonas Ådahl | 24185e2 | 2015-02-27 18:37:41 +0800 | [diff] [blame] | 4160 | |
Jason Ekstrand | 9e9512f | 2014-04-16 21:12:10 -0500 | [diff] [blame] | 4161 | shsurf = create_common_surface(owner, shell, surface, client); |
Pekka Paalanen | e972b27 | 2014-10-01 14:03:56 +0300 | [diff] [blame] | 4162 | if (!shsurf) |
| 4163 | return NULL; |
| 4164 | |
Pekka Paalanen | b502654 | 2014-11-12 15:09:24 +0200 | [diff] [blame] | 4165 | set_type(shsurf, SHELL_SURFACE_POPUP); |
Rafael Antognolli | e2a3455 | 2013-12-03 15:35:45 -0200 | [diff] [blame] | 4166 | shsurf->popup.shseat = seat; |
| 4167 | shsurf->popup.serial = serial; |
| 4168 | shsurf->popup.x = x; |
| 4169 | shsurf->popup.y = y; |
| 4170 | shell_surface_set_parent(shsurf, parent); |
| 4171 | |
| 4172 | return shsurf; |
| 4173 | } |
| 4174 | |
| 4175 | static void |
| 4176 | xdg_get_xdg_popup(struct wl_client *client, |
| 4177 | struct wl_resource *resource, |
| 4178 | uint32_t id, |
| 4179 | struct wl_resource *surface_resource, |
| 4180 | struct wl_resource *parent_resource, |
| 4181 | struct wl_resource *seat_resource, |
| 4182 | uint32_t serial, |
Jasper St. Pierre | 14f330c | 2015-02-13 14:01:57 +0800 | [diff] [blame] | 4183 | int32_t x, int32_t y) |
Rafael Antognolli | e2a3455 | 2013-12-03 15:35:45 -0200 | [diff] [blame] | 4184 | { |
| 4185 | struct weston_surface *surface = |
| 4186 | wl_resource_get_user_data(surface_resource); |
Kristian Høgsberg | 2bff94e | 2014-02-11 12:22:51 -0800 | [diff] [blame] | 4187 | struct shell_client *sc = wl_resource_get_user_data(resource); |
| 4188 | struct desktop_shell *shell = sc->shell; |
Rafael Antognolli | e2a3455 | 2013-12-03 15:35:45 -0200 | [diff] [blame] | 4189 | struct shell_surface *shsurf; |
Jonas Ådahl | ee45a55 | 2015-03-18 16:37:47 +0800 | [diff] [blame] | 4190 | struct shell_surface *parent_shsurf; |
Rafael Antognolli | e2a3455 | 2013-12-03 15:35:45 -0200 | [diff] [blame] | 4191 | struct weston_surface *parent; |
| 4192 | struct shell_seat *seat; |
| 4193 | |
Jonas Ådahl | bf48e21 | 2015-02-06 10:15:28 +0800 | [diff] [blame] | 4194 | shsurf = get_shell_surface(surface); |
| 4195 | if (shsurf && shell_surface_is_xdg_popup(shsurf)) { |
| 4196 | wl_resource_post_error(resource, XDG_SHELL_ERROR_ROLE, |
| 4197 | "This wl_surface is already an " |
| 4198 | "xdg_popup"); |
| 4199 | return; |
| 4200 | } |
| 4201 | |
Pekka Paalanen | 50b6747 | 2014-10-01 15:02:41 +0300 | [diff] [blame] | 4202 | if (weston_surface_set_role(surface, "xdg_popup", |
| 4203 | resource, XDG_SHELL_ERROR_ROLE) < 0) |
Rafael Antognolli | e2a3455 | 2013-12-03 15:35:45 -0200 | [diff] [blame] | 4204 | return; |
Rafael Antognolli | e2a3455 | 2013-12-03 15:35:45 -0200 | [diff] [blame] | 4205 | |
| 4206 | if (!parent_resource) { |
| 4207 | wl_resource_post_error(surface_resource, |
| 4208 | WL_DISPLAY_ERROR_INVALID_OBJECT, |
| 4209 | "xdg_shell::get_xdg_popup requires a parent shell surface"); |
Jasper St. Pierre | 666bc92 | 2014-08-07 16:43:13 -0400 | [diff] [blame] | 4210 | return; |
Rafael Antognolli | e2a3455 | 2013-12-03 15:35:45 -0200 | [diff] [blame] | 4211 | } |
| 4212 | |
| 4213 | parent = wl_resource_get_user_data(parent_resource); |
| 4214 | seat = get_shell_seat(wl_resource_get_user_data(seat_resource));; |
| 4215 | |
Jonas Ådahl | ee45a55 | 2015-03-18 16:37:47 +0800 | [diff] [blame] | 4216 | /* Verify that we are creating the top most popup when mapping, |
| 4217 | * as it's not until then we know whether it was mapped as most |
| 4218 | * top level or not. */ |
| 4219 | |
| 4220 | parent_shsurf = get_shell_surface(parent); |
| 4221 | if (!shell_surface_is_xdg_popup(parent_shsurf) && |
| 4222 | !shell_surface_is_xdg_surface(parent_shsurf)) { |
| 4223 | wl_resource_post_error(resource, |
| 4224 | XDG_SHELL_ERROR_INVALID_POPUP_PARENT, |
| 4225 | "xdg_popup parent was invalid"); |
| 4226 | return; |
| 4227 | } |
| 4228 | |
Jason Ekstrand | 9e9512f | 2014-04-16 21:12:10 -0500 | [diff] [blame] | 4229 | shsurf = create_xdg_popup(sc, shell, surface, &xdg_popup_client, |
Rafael Antognolli | e2a3455 | 2013-12-03 15:35:45 -0200 | [diff] [blame] | 4230 | parent, seat, serial, x, y); |
| 4231 | if (!shsurf) { |
Pekka Paalanen | 50b6747 | 2014-10-01 15:02:41 +0300 | [diff] [blame] | 4232 | wl_resource_post_no_memory(surface_resource); |
Rafael Antognolli | e2a3455 | 2013-12-03 15:35:45 -0200 | [diff] [blame] | 4233 | return; |
| 4234 | } |
| 4235 | |
| 4236 | shsurf->resource = |
| 4237 | wl_resource_create(client, |
| 4238 | &xdg_popup_interface, 1, id); |
| 4239 | wl_resource_set_implementation(shsurf->resource, |
| 4240 | &xdg_popup_implementation, |
| 4241 | shsurf, shell_destroy_shell_surface); |
Jonas Ådahl | 49d77d2 | 2015-03-18 16:20:51 +0800 | [diff] [blame] | 4242 | shsurf->owner_resource = resource; |
| 4243 | wl_list_insert(&sc->surface_list, |
| 4244 | wl_resource_get_link(shsurf->resource)); |
Rafael Antognolli | e2a3455 | 2013-12-03 15:35:45 -0200 | [diff] [blame] | 4245 | } |
| 4246 | |
Kristian Høgsberg | 2bff94e | 2014-02-11 12:22:51 -0800 | [diff] [blame] | 4247 | static void |
| 4248 | xdg_pong(struct wl_client *client, |
| 4249 | struct wl_resource *resource, uint32_t serial) |
| 4250 | { |
| 4251 | struct shell_client *sc = wl_resource_get_user_data(resource); |
Kristian Høgsberg | 2bff94e | 2014-02-11 12:22:51 -0800 | [diff] [blame] | 4252 | |
Kristian Høgsberg | dd62aba | 2014-02-12 09:56:19 -0800 | [diff] [blame] | 4253 | shell_client_pong(sc, serial); |
Kristian Høgsberg | 2bff94e | 2014-02-11 12:22:51 -0800 | [diff] [blame] | 4254 | } |
| 4255 | |
Rafael Antognolli | e2a3455 | 2013-12-03 15:35:45 -0200 | [diff] [blame] | 4256 | static bool |
| 4257 | shell_surface_is_xdg_popup(struct shell_surface *shsurf) |
| 4258 | { |
| 4259 | return wl_resource_instance_of(shsurf->resource, |
| 4260 | &xdg_popup_interface, |
| 4261 | &xdg_popup_implementation); |
| 4262 | } |
| 4263 | |
| 4264 | static const struct xdg_shell_interface xdg_implementation = { |
Jasper St. Pierre | 084aa0b | 2015-02-13 14:02:00 +0800 | [diff] [blame] | 4265 | xdg_shell_destroy, |
Rafael Antognolli | e2a3455 | 2013-12-03 15:35:45 -0200 | [diff] [blame] | 4266 | xdg_use_unstable_version, |
| 4267 | xdg_get_xdg_surface, |
Kristian Høgsberg | 2bff94e | 2014-02-11 12:22:51 -0800 | [diff] [blame] | 4268 | xdg_get_xdg_popup, |
| 4269 | xdg_pong |
Rafael Antognolli | e2a3455 | 2013-12-03 15:35:45 -0200 | [diff] [blame] | 4270 | }; |
| 4271 | |
| 4272 | static int |
| 4273 | xdg_shell_unversioned_dispatch(const void *implementation, |
| 4274 | void *_target, uint32_t opcode, |
| 4275 | const struct wl_message *message, |
| 4276 | union wl_argument *args) |
| 4277 | { |
| 4278 | struct wl_resource *resource = _target; |
Kristian Høgsberg | 2bff94e | 2014-02-11 12:22:51 -0800 | [diff] [blame] | 4279 | struct shell_client *sc = wl_resource_get_user_data(resource); |
Rafael Antognolli | e2a3455 | 2013-12-03 15:35:45 -0200 | [diff] [blame] | 4280 | |
Jasper St. Pierre | 084aa0b | 2015-02-13 14:02:00 +0800 | [diff] [blame] | 4281 | if (opcode != 1 /* XDG_SHELL_USE_UNSTABLE_VERSION */) { |
Rafael Antognolli | e2a3455 | 2013-12-03 15:35:45 -0200 | [diff] [blame] | 4282 | wl_resource_post_error(resource, |
| 4283 | WL_DISPLAY_ERROR_INVALID_OBJECT, |
| 4284 | "must call use_unstable_version first"); |
| 4285 | return 0; |
| 4286 | } |
| 4287 | |
Jasper St. Pierre | 5ba1e1d | 2015-02-13 14:02:02 +0800 | [diff] [blame] | 4288 | #define XDG_SERVER_VERSION 5 |
Rafael Antognolli | e2a3455 | 2013-12-03 15:35:45 -0200 | [diff] [blame] | 4289 | |
Kristian Høgsberg | 8d344a0 | 2013-12-08 22:27:11 -0800 | [diff] [blame] | 4290 | static_assert(XDG_SERVER_VERSION == XDG_SHELL_VERSION_CURRENT, |
| 4291 | "shell implementation doesn't match protocol version"); |
| 4292 | |
Rafael Antognolli | e2a3455 | 2013-12-03 15:35:45 -0200 | [diff] [blame] | 4293 | if (args[0].i != XDG_SERVER_VERSION) { |
| 4294 | wl_resource_post_error(resource, |
| 4295 | WL_DISPLAY_ERROR_INVALID_OBJECT, |
| 4296 | "incompatible version, server is %d " |
| 4297 | "client wants %d", |
| 4298 | XDG_SERVER_VERSION, args[0].i); |
| 4299 | return 0; |
| 4300 | } |
| 4301 | |
| 4302 | wl_resource_set_implementation(resource, &xdg_implementation, |
Kristian Høgsberg | 2bff94e | 2014-02-11 12:22:51 -0800 | [diff] [blame] | 4303 | sc, NULL); |
Rafael Antognolli | e2a3455 | 2013-12-03 15:35:45 -0200 | [diff] [blame] | 4304 | |
| 4305 | return 1; |
| 4306 | } |
| 4307 | |
| 4308 | /* end of xdg-shell implementation */ |
| 4309 | /***********************************/ |
| 4310 | |
Kristian Høgsberg | 0793756 | 2011-04-12 17:25:42 -0400 | [diff] [blame] | 4311 | static void |
Ander Conselvan de Oliveira | 859e885 | 2013-02-21 18:35:21 +0200 | [diff] [blame] | 4312 | shell_fade(struct desktop_shell *shell, enum fade_type type); |
| 4313 | |
Pekka Paalanen | 77346a6 | 2011-11-30 16:26:35 +0200 | [diff] [blame] | 4314 | static void |
Jason Ekstrand | 918f2dd | 2013-12-02 21:01:53 -0600 | [diff] [blame] | 4315 | configure_static_view(struct weston_view *ev, struct weston_layer *layer) |
Kristian Høgsberg | 962342c | 2012-06-26 16:29:50 -0400 | [diff] [blame] | 4316 | { |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 4317 | struct weston_view *v, *next; |
Kristian Høgsberg | 962342c | 2012-06-26 16:29:50 -0400 | [diff] [blame] | 4318 | |
Giulio Camuffo | 412e6a5 | 2014-07-09 22:12:56 +0300 | [diff] [blame] | 4319 | 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] | 4320 | if (v->output == ev->output && v != ev) { |
| 4321 | weston_view_unmap(v); |
| 4322 | v->surface->configure = NULL; |
Pekka Paalanen | 8274d90 | 2014-08-06 19:36:51 +0300 | [diff] [blame] | 4323 | weston_surface_set_label_func(v->surface, NULL); |
Kristian Høgsberg | 962342c | 2012-06-26 16:29:50 -0400 | [diff] [blame] | 4324 | } |
| 4325 | } |
| 4326 | |
Jason Ekstrand | 918f2dd | 2013-12-02 21:01:53 -0600 | [diff] [blame] | 4327 | weston_view_set_position(ev, ev->output->x, ev->output->y); |
Kristian Høgsberg | 962342c | 2012-06-26 16:29:50 -0400 | [diff] [blame] | 4328 | |
Giulio Camuffo | 412e6a5 | 2014-07-09 22:12:56 +0300 | [diff] [blame] | 4329 | if (wl_list_empty(&ev->layer_link.link)) { |
| 4330 | weston_layer_entry_insert(&layer->view_list, &ev->layer_link); |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 4331 | weston_compositor_schedule_repaint(ev->surface->compositor); |
Kristian Høgsberg | 962342c | 2012-06-26 16:29:50 -0400 | [diff] [blame] | 4332 | } |
| 4333 | } |
| 4334 | |
Pekka Paalanen | 8274d90 | 2014-08-06 19:36:51 +0300 | [diff] [blame] | 4335 | static int |
| 4336 | background_get_label(struct weston_surface *surface, char *buf, size_t len) |
| 4337 | { |
| 4338 | return snprintf(buf, len, "background for output %s", |
| 4339 | surface->output->name); |
| 4340 | } |
| 4341 | |
Kristian Høgsberg | 962342c | 2012-06-26 16:29:50 -0400 | [diff] [blame] | 4342 | static void |
Jason Ekstrand | 918f2dd | 2013-12-02 21:01:53 -0600 | [diff] [blame] | 4343 | 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] | 4344 | { |
Giulio Camuffo | 7fe01b1 | 2013-03-28 18:02:42 +0100 | [diff] [blame] | 4345 | struct desktop_shell *shell = es->configure_private; |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 4346 | struct weston_view *view; |
Kristian Høgsberg | af7b1ff | 2012-06-26 21:19:23 -0400 | [diff] [blame] | 4347 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 4348 | view = container_of(es->views.next, struct weston_view, surface_link); |
| 4349 | |
Jason Ekstrand | 918f2dd | 2013-12-02 21:01:53 -0600 | [diff] [blame] | 4350 | configure_static_view(view, &shell->background_layer); |
Kristian Høgsberg | af7b1ff | 2012-06-26 21:19:23 -0400 | [diff] [blame] | 4351 | } |
| 4352 | |
| 4353 | static void |
Kristian Høgsberg | 7584062 | 2011-09-06 13:48:16 -0400 | [diff] [blame] | 4354 | desktop_shell_set_background(struct wl_client *client, |
| 4355 | struct wl_resource *resource, |
Benjamin Franzke | d0f79ab | 2011-11-22 12:43:52 +0100 | [diff] [blame] | 4356 | struct wl_resource *output_resource, |
Kristian Høgsberg | 7584062 | 2011-09-06 13:48:16 -0400 | [diff] [blame] | 4357 | struct wl_resource *surface_resource) |
| 4358 | { |
Jason Ekstrand | 651f00e | 2013-06-14 10:07:54 -0500 | [diff] [blame] | 4359 | struct desktop_shell *shell = wl_resource_get_user_data(resource); |
Jason Ekstrand | 0f2ef7e | 2013-06-14 10:07:53 -0500 | [diff] [blame] | 4360 | struct weston_surface *surface = |
| 4361 | wl_resource_get_user_data(surface_resource); |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 4362 | struct weston_view *view, *next; |
Kristian Høgsberg | 7584062 | 2011-09-06 13:48:16 -0400 | [diff] [blame] | 4363 | |
Kristian Høgsberg | 962342c | 2012-06-26 16:29:50 -0400 | [diff] [blame] | 4364 | if (surface->configure) { |
| 4365 | wl_resource_post_error(surface_resource, |
| 4366 | WL_DISPLAY_ERROR_INVALID_OBJECT, |
| 4367 | "surface role already assigned"); |
| 4368 | return; |
| 4369 | } |
Benjamin Franzke | d0f79ab | 2011-11-22 12:43:52 +0100 | [diff] [blame] | 4370 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 4371 | wl_list_for_each_safe(view, next, &surface->views, surface_link) |
| 4372 | weston_view_destroy(view); |
| 4373 | view = weston_view_create(surface); |
| 4374 | |
Kristian Høgsberg | 962342c | 2012-06-26 16:29:50 -0400 | [diff] [blame] | 4375 | surface->configure = background_configure; |
Giulio Camuffo | 7fe01b1 | 2013-03-28 18:02:42 +0100 | [diff] [blame] | 4376 | surface->configure_private = shell; |
Pekka Paalanen | 8274d90 | 2014-08-06 19:36:51 +0300 | [diff] [blame] | 4377 | weston_surface_set_label_func(surface, background_get_label); |
Jason Ekstrand | a0d2dde | 2013-06-14 10:08:01 -0500 | [diff] [blame] | 4378 | surface->output = wl_resource_get_user_data(output_resource); |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 4379 | view->output = surface->output; |
Kristian Høgsberg | eae5de7 | 2012-04-11 22:42:15 -0400 | [diff] [blame] | 4380 | desktop_shell_send_configure(resource, 0, |
Kristian Høgsberg | 0b5cd0c | 2012-03-04 21:57:37 -0500 | [diff] [blame] | 4381 | surface_resource, |
Scott Moreau | 1bad5db | 2012-08-18 01:04:05 -0600 | [diff] [blame] | 4382 | surface->output->width, |
| 4383 | surface->output->height); |
Kristian Høgsberg | 7584062 | 2011-09-06 13:48:16 -0400 | [diff] [blame] | 4384 | } |
| 4385 | |
Pekka Paalanen | 8274d90 | 2014-08-06 19:36:51 +0300 | [diff] [blame] | 4386 | static int |
| 4387 | panel_get_label(struct weston_surface *surface, char *buf, size_t len) |
| 4388 | { |
| 4389 | return snprintf(buf, len, "panel for output %s", |
| 4390 | surface->output->name); |
| 4391 | } |
| 4392 | |
Kristian Høgsberg | 7584062 | 2011-09-06 13:48:16 -0400 | [diff] [blame] | 4393 | static void |
Jason Ekstrand | 918f2dd | 2013-12-02 21:01:53 -0600 | [diff] [blame] | 4394 | 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] | 4395 | { |
Giulio Camuffo | 7fe01b1 | 2013-03-28 18:02:42 +0100 | [diff] [blame] | 4396 | struct desktop_shell *shell = es->configure_private; |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 4397 | struct weston_view *view; |
Kristian Høgsberg | af7b1ff | 2012-06-26 21:19:23 -0400 | [diff] [blame] | 4398 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 4399 | view = container_of(es->views.next, struct weston_view, surface_link); |
| 4400 | |
Jason Ekstrand | 918f2dd | 2013-12-02 21:01:53 -0600 | [diff] [blame] | 4401 | configure_static_view(view, &shell->panel_layer); |
Kristian Høgsberg | af7b1ff | 2012-06-26 21:19:23 -0400 | [diff] [blame] | 4402 | } |
| 4403 | |
| 4404 | static void |
Kristian Høgsberg | 7584062 | 2011-09-06 13:48:16 -0400 | [diff] [blame] | 4405 | desktop_shell_set_panel(struct wl_client *client, |
| 4406 | struct wl_resource *resource, |
Benjamin Franzke | d0f79ab | 2011-11-22 12:43:52 +0100 | [diff] [blame] | 4407 | struct wl_resource *output_resource, |
Kristian Høgsberg | 7584062 | 2011-09-06 13:48:16 -0400 | [diff] [blame] | 4408 | struct wl_resource *surface_resource) |
| 4409 | { |
Jason Ekstrand | 651f00e | 2013-06-14 10:07:54 -0500 | [diff] [blame] | 4410 | struct desktop_shell *shell = wl_resource_get_user_data(resource); |
Jason Ekstrand | 0f2ef7e | 2013-06-14 10:07:53 -0500 | [diff] [blame] | 4411 | struct weston_surface *surface = |
| 4412 | wl_resource_get_user_data(surface_resource); |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 4413 | struct weston_view *view, *next; |
Kristian Høgsberg | 7584062 | 2011-09-06 13:48:16 -0400 | [diff] [blame] | 4414 | |
Kristian Høgsberg | af7b1ff | 2012-06-26 21:19:23 -0400 | [diff] [blame] | 4415 | if (surface->configure) { |
| 4416 | wl_resource_post_error(surface_resource, |
| 4417 | WL_DISPLAY_ERROR_INVALID_OBJECT, |
| 4418 | "surface role already assigned"); |
| 4419 | return; |
| 4420 | } |
Benjamin Franzke | d0f79ab | 2011-11-22 12:43:52 +0100 | [diff] [blame] | 4421 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 4422 | wl_list_for_each_safe(view, next, &surface->views, surface_link) |
| 4423 | weston_view_destroy(view); |
| 4424 | view = weston_view_create(surface); |
| 4425 | |
Kristian Høgsberg | af7b1ff | 2012-06-26 21:19:23 -0400 | [diff] [blame] | 4426 | surface->configure = panel_configure; |
Giulio Camuffo | 7fe01b1 | 2013-03-28 18:02:42 +0100 | [diff] [blame] | 4427 | surface->configure_private = shell; |
Pekka Paalanen | 8274d90 | 2014-08-06 19:36:51 +0300 | [diff] [blame] | 4428 | weston_surface_set_label_func(surface, panel_get_label); |
Jason Ekstrand | a0d2dde | 2013-06-14 10:08:01 -0500 | [diff] [blame] | 4429 | surface->output = wl_resource_get_user_data(output_resource); |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 4430 | view->output = surface->output; |
Kristian Høgsberg | eae5de7 | 2012-04-11 22:42:15 -0400 | [diff] [blame] | 4431 | desktop_shell_send_configure(resource, 0, |
Kristian Høgsberg | af7b1ff | 2012-06-26 21:19:23 -0400 | [diff] [blame] | 4432 | surface_resource, |
Scott Moreau | 1bad5db | 2012-08-18 01:04:05 -0600 | [diff] [blame] | 4433 | surface->output->width, |
| 4434 | surface->output->height); |
Kristian Høgsberg | 7584062 | 2011-09-06 13:48:16 -0400 | [diff] [blame] | 4435 | } |
| 4436 | |
Pekka Paalanen | 8274d90 | 2014-08-06 19:36:51 +0300 | [diff] [blame] | 4437 | static int |
| 4438 | lock_surface_get_label(struct weston_surface *surface, char *buf, size_t len) |
| 4439 | { |
| 4440 | return snprintf(buf, len, "lock window"); |
| 4441 | } |
| 4442 | |
Pekka Paalanen | 9ef3e01 | 2011-11-15 13:34:48 +0200 | [diff] [blame] | 4443 | static void |
Jason Ekstrand | 918f2dd | 2013-12-02 21:01:53 -0600 | [diff] [blame] | 4444 | 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] | 4445 | { |
Giulio Camuffo | 7fe01b1 | 2013-03-28 18:02:42 +0100 | [diff] [blame] | 4446 | struct desktop_shell *shell = surface->configure_private; |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 4447 | struct weston_view *view; |
| 4448 | |
| 4449 | view = container_of(surface->views.next, struct weston_view, surface_link); |
Kristian Høgsberg | 730c94d | 2012-06-26 21:44:35 -0400 | [diff] [blame] | 4450 | |
Jason Ekstrand | 918f2dd | 2013-12-02 21:01:53 -0600 | [diff] [blame] | 4451 | if (surface->width == 0) |
Giulio Camuffo | 184df50 | 2013-02-21 11:29:21 +0100 | [diff] [blame] | 4452 | return; |
| 4453 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 4454 | center_on_output(view, get_default_output(shell->compositor)); |
Kristian Høgsberg | 730c94d | 2012-06-26 21:44:35 -0400 | [diff] [blame] | 4455 | |
| 4456 | if (!weston_surface_is_mapped(surface)) { |
Giulio Camuffo | 412e6a5 | 2014-07-09 22:12:56 +0300 | [diff] [blame] | 4457 | weston_layer_entry_insert(&shell->lock_layer.view_list, |
| 4458 | &view->layer_link); |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 4459 | weston_view_update_transform(view); |
Ander Conselvan de Oliveira | 87524b6 | 2013-02-21 18:35:22 +0200 | [diff] [blame] | 4460 | shell_fade(shell, FADE_IN); |
Kristian Høgsberg | 730c94d | 2012-06-26 21:44:35 -0400 | [diff] [blame] | 4461 | } |
| 4462 | } |
| 4463 | |
| 4464 | static void |
Kristian Høgsberg | 27e3052 | 2012-04-11 23:18:23 -0400 | [diff] [blame] | 4465 | handle_lock_surface_destroy(struct wl_listener *listener, void *data) |
Kristian Høgsberg | 1ec0c31 | 2011-11-15 16:39:55 -0500 | [diff] [blame] | 4466 | { |
Tiago Vignatti | be14326 | 2012-04-16 17:31:41 +0300 | [diff] [blame] | 4467 | struct desktop_shell *shell = |
| 4468 | container_of(listener, struct desktop_shell, lock_surface_listener); |
Kristian Høgsberg | 1ec0c31 | 2011-11-15 16:39:55 -0500 | [diff] [blame] | 4469 | |
Martin Minarik | 6d11836 | 2012-06-07 18:01:59 +0200 | [diff] [blame] | 4470 | weston_log("lock surface gone\n"); |
Kristian Høgsberg | 1ec0c31 | 2011-11-15 16:39:55 -0500 | [diff] [blame] | 4471 | shell->lock_surface = NULL; |
| 4472 | } |
| 4473 | |
| 4474 | static void |
Pekka Paalanen | 9ef3e01 | 2011-11-15 13:34:48 +0200 | [diff] [blame] | 4475 | desktop_shell_set_lock_surface(struct wl_client *client, |
| 4476 | struct wl_resource *resource, |
| 4477 | struct wl_resource *surface_resource) |
| 4478 | { |
Jason Ekstrand | 651f00e | 2013-06-14 10:07:54 -0500 | [diff] [blame] | 4479 | struct desktop_shell *shell = wl_resource_get_user_data(resource); |
Jason Ekstrand | 0f2ef7e | 2013-06-14 10:07:53 -0500 | [diff] [blame] | 4480 | struct weston_surface *surface = |
| 4481 | wl_resource_get_user_data(surface_resource); |
Pekka Paalanen | 9826223 | 2011-12-01 10:42:22 +0200 | [diff] [blame] | 4482 | |
Pekka Paalanen | f0fc70d | 2011-11-15 13:34:54 +0200 | [diff] [blame] | 4483 | shell->prepare_event_sent = false; |
Kristian Høgsberg | af867cc | 2011-11-15 13:34:49 +0200 | [diff] [blame] | 4484 | |
Pekka Paalanen | f0fc70d | 2011-11-15 13:34:54 +0200 | [diff] [blame] | 4485 | if (!shell->locked) |
| 4486 | return; |
| 4487 | |
Pekka Paalanen | 9826223 | 2011-12-01 10:42:22 +0200 | [diff] [blame] | 4488 | shell->lock_surface = surface; |
Pekka Paalanen | f0fc70d | 2011-11-15 13:34:54 +0200 | [diff] [blame] | 4489 | |
Kristian Høgsberg | 27e3052 | 2012-04-11 23:18:23 -0400 | [diff] [blame] | 4490 | shell->lock_surface_listener.notify = handle_lock_surface_destroy; |
Jason Ekstrand | 651f00e | 2013-06-14 10:07:54 -0500 | [diff] [blame] | 4491 | wl_signal_add(&surface->destroy_signal, |
Kristian Høgsberg | 27e3052 | 2012-04-11 23:18:23 -0400 | [diff] [blame] | 4492 | &shell->lock_surface_listener); |
Pekka Paalanen | 57da4a8 | 2011-11-23 16:42:16 +0200 | [diff] [blame] | 4493 | |
Kristian Høgsberg | aa2ee8b | 2013-10-30 15:49:45 -0700 | [diff] [blame] | 4494 | weston_view_create(surface); |
Kristian Høgsberg | 730c94d | 2012-06-26 21:44:35 -0400 | [diff] [blame] | 4495 | surface->configure = lock_surface_configure; |
Giulio Camuffo | 7fe01b1 | 2013-03-28 18:02:42 +0100 | [diff] [blame] | 4496 | surface->configure_private = shell; |
Pekka Paalanen | 8274d90 | 2014-08-06 19:36:51 +0300 | [diff] [blame] | 4497 | weston_surface_set_label_func(surface, lock_surface_get_label); |
Pekka Paalanen | f0fc70d | 2011-11-15 13:34:54 +0200 | [diff] [blame] | 4498 | } |
| 4499 | |
| 4500 | static void |
Tiago Vignatti | be14326 | 2012-04-16 17:31:41 +0300 | [diff] [blame] | 4501 | resume_desktop(struct desktop_shell *shell) |
Pekka Paalanen | f0fc70d | 2011-11-15 13:34:54 +0200 | [diff] [blame] | 4502 | { |
Kristian Høgsberg | 4476aaf | 2012-06-25 14:03:13 -0400 | [diff] [blame] | 4503 | struct workspace *ws = get_current_workspace(shell); |
Pekka Paalanen | 77346a6 | 2011-11-30 16:26:35 +0200 | [diff] [blame] | 4504 | |
Kristian Høgsberg | 3be2ce9 | 2012-02-29 12:42:35 -0500 | [diff] [blame] | 4505 | wl_list_remove(&shell->lock_layer.link); |
Philipp Brüschweiler | 711fda8 | 2012-08-09 18:50:43 +0200 | [diff] [blame] | 4506 | if (shell->showing_input_panels) { |
Manuel Bachmann | 805d2f5 | 2014-03-05 12:21:34 +0100 | [diff] [blame] | 4507 | wl_list_insert(&shell->compositor->cursor_layer.link, |
Philipp Brüschweiler | 711fda8 | 2012-08-09 18:50:43 +0200 | [diff] [blame] | 4508 | &shell->input_panel_layer.link); |
| 4509 | wl_list_insert(&shell->input_panel_layer.link, |
Manuel Bachmann | 805d2f5 | 2014-03-05 12:21:34 +0100 | [diff] [blame] | 4510 | &shell->fullscreen_layer.link); |
Philipp Brüschweiler | 711fda8 | 2012-08-09 18:50:43 +0200 | [diff] [blame] | 4511 | } else { |
Manuel Bachmann | 805d2f5 | 2014-03-05 12:21:34 +0100 | [diff] [blame] | 4512 | wl_list_insert(&shell->compositor->cursor_layer.link, |
| 4513 | &shell->fullscreen_layer.link); |
Philipp Brüschweiler | 711fda8 | 2012-08-09 18:50:43 +0200 | [diff] [blame] | 4514 | } |
Manuel Bachmann | 805d2f5 | 2014-03-05 12:21:34 +0100 | [diff] [blame] | 4515 | wl_list_insert(&shell->fullscreen_layer.link, |
| 4516 | &shell->panel_layer.link); |
| 4517 | wl_list_insert(&shell->panel_layer.link, |
| 4518 | &ws->layer.link), |
Pekka Paalanen | f0fc70d | 2011-11-15 13:34:54 +0200 | [diff] [blame] | 4519 | |
Kristian Høgsberg | 2f5faff | 2012-07-31 16:36:34 -0400 | [diff] [blame] | 4520 | restore_focus_state(shell, get_current_workspace(shell)); |
Jonas Ådahl | 0476974 | 2012-06-13 00:01:24 +0200 | [diff] [blame] | 4521 | |
Pekka Paalanen | f0fc70d | 2011-11-15 13:34:54 +0200 | [diff] [blame] | 4522 | shell->locked = false; |
Ander Conselvan de Oliveira | 87524b6 | 2013-02-21 18:35:22 +0200 | [diff] [blame] | 4523 | shell_fade(shell, FADE_IN); |
Pekka Paalanen | fc6d91a | 2012-02-10 15:33:10 +0200 | [diff] [blame] | 4524 | weston_compositor_damage_all(shell->compositor); |
Pekka Paalanen | 9ef3e01 | 2011-11-15 13:34:48 +0200 | [diff] [blame] | 4525 | } |
| 4526 | |
| 4527 | static void |
| 4528 | desktop_shell_unlock(struct wl_client *client, |
| 4529 | struct wl_resource *resource) |
| 4530 | { |
Jason Ekstrand | 651f00e | 2013-06-14 10:07:54 -0500 | [diff] [blame] | 4531 | struct desktop_shell *shell = wl_resource_get_user_data(resource); |
Pekka Paalanen | 9ef3e01 | 2011-11-15 13:34:48 +0200 | [diff] [blame] | 4532 | |
Pekka Paalanen | 9ef3e01 | 2011-11-15 13:34:48 +0200 | [diff] [blame] | 4533 | shell->prepare_event_sent = false; |
Pekka Paalanen | f0fc70d | 2011-11-15 13:34:54 +0200 | [diff] [blame] | 4534 | |
| 4535 | if (shell->locked) |
| 4536 | resume_desktop(shell); |
Pekka Paalanen | 9ef3e01 | 2011-11-15 13:34:48 +0200 | [diff] [blame] | 4537 | } |
| 4538 | |
Kristian Høgsberg | d56bd90 | 2012-06-05 09:58:51 -0400 | [diff] [blame] | 4539 | static void |
Ander Conselvan de Oliveira | b9d2a0f | 2012-06-28 18:08:05 +0300 | [diff] [blame] | 4540 | desktop_shell_set_grab_surface(struct wl_client *client, |
Kristian Høgsberg | d56bd90 | 2012-06-05 09:58:51 -0400 | [diff] [blame] | 4541 | struct wl_resource *resource, |
| 4542 | struct wl_resource *surface_resource) |
| 4543 | { |
Jason Ekstrand | 651f00e | 2013-06-14 10:07:54 -0500 | [diff] [blame] | 4544 | struct desktop_shell *shell = wl_resource_get_user_data(resource); |
Kristian Høgsberg | d56bd90 | 2012-06-05 09:58:51 -0400 | [diff] [blame] | 4545 | |
Jason Ekstrand | 0f2ef7e | 2013-06-14 10:07:53 -0500 | [diff] [blame] | 4546 | shell->grab_surface = wl_resource_get_user_data(surface_resource); |
Kristian Høgsberg | 48588f8 | 2013-10-24 15:51:35 -0700 | [diff] [blame] | 4547 | weston_view_create(shell->grab_surface); |
Kristian Høgsberg | d56bd90 | 2012-06-05 09:58:51 -0400 | [diff] [blame] | 4548 | } |
| 4549 | |
Pekka Paalanen | 79346ab | 2013-05-22 18:03:09 +0300 | [diff] [blame] | 4550 | static void |
| 4551 | desktop_shell_desktop_ready(struct wl_client *client, |
| 4552 | struct wl_resource *resource) |
| 4553 | { |
Jason Ekstrand | 651f00e | 2013-06-14 10:07:54 -0500 | [diff] [blame] | 4554 | struct desktop_shell *shell = wl_resource_get_user_data(resource); |
Pekka Paalanen | 79346ab | 2013-05-22 18:03:09 +0300 | [diff] [blame] | 4555 | |
| 4556 | shell_fade_startup(shell); |
| 4557 | } |
| 4558 | |
Jonny Lamb | 765760d | 2014-08-20 15:53:19 +0200 | [diff] [blame] | 4559 | static void |
| 4560 | desktop_shell_set_panel_position(struct wl_client *client, |
| 4561 | struct wl_resource *resource, |
| 4562 | uint32_t position) |
| 4563 | { |
| 4564 | struct desktop_shell *shell = wl_resource_get_user_data(resource); |
| 4565 | |
| 4566 | if (position != DESKTOP_SHELL_PANEL_POSITION_TOP && |
| 4567 | position != DESKTOP_SHELL_PANEL_POSITION_BOTTOM && |
| 4568 | position != DESKTOP_SHELL_PANEL_POSITION_LEFT && |
| 4569 | position != DESKTOP_SHELL_PANEL_POSITION_RIGHT) { |
| 4570 | wl_resource_post_error(resource, |
| 4571 | DESKTOP_SHELL_ERROR_INVALID_ARGUMENT, |
| 4572 | "bad position argument"); |
| 4573 | return; |
| 4574 | } |
| 4575 | |
| 4576 | shell->panel_position = position; |
| 4577 | } |
| 4578 | |
Kristian Høgsberg | 7584062 | 2011-09-06 13:48:16 -0400 | [diff] [blame] | 4579 | static const struct desktop_shell_interface desktop_shell_implementation = { |
| 4580 | desktop_shell_set_background, |
Pekka Paalanen | 9ef3e01 | 2011-11-15 13:34:48 +0200 | [diff] [blame] | 4581 | desktop_shell_set_panel, |
| 4582 | desktop_shell_set_lock_surface, |
Kristian Høgsberg | d56bd90 | 2012-06-05 09:58:51 -0400 | [diff] [blame] | 4583 | desktop_shell_unlock, |
Pekka Paalanen | 79346ab | 2013-05-22 18:03:09 +0300 | [diff] [blame] | 4584 | desktop_shell_set_grab_surface, |
Jonny Lamb | 765760d | 2014-08-20 15:53:19 +0200 | [diff] [blame] | 4585 | desktop_shell_desktop_ready, |
| 4586 | desktop_shell_set_panel_position |
Kristian Høgsberg | 7584062 | 2011-09-06 13:48:16 -0400 | [diff] [blame] | 4587 | }; |
| 4588 | |
Pekka Paalanen | 92a0dc4 | 2011-11-28 15:34:13 +0200 | [diff] [blame] | 4589 | static enum shell_surface_type |
Kristian Høgsberg | 8334bc1 | 2012-01-03 10:29:47 -0500 | [diff] [blame] | 4590 | get_shell_surface_type(struct weston_surface *surface) |
Pekka Paalanen | 92a0dc4 | 2011-11-28 15:34:13 +0200 | [diff] [blame] | 4591 | { |
| 4592 | struct shell_surface *shsurf; |
| 4593 | |
| 4594 | shsurf = get_shell_surface(surface); |
| 4595 | if (!shsurf) |
Pekka Paalanen | 9826223 | 2011-12-01 10:42:22 +0200 | [diff] [blame] | 4596 | return SHELL_SURFACE_NONE; |
Pekka Paalanen | 92a0dc4 | 2011-11-28 15:34:13 +0200 | [diff] [blame] | 4597 | return shsurf->type; |
| 4598 | } |
| 4599 | |
Kristian Høgsberg | 7584062 | 2011-09-06 13:48:16 -0400 | [diff] [blame] | 4600 | static void |
Derek Foreman | 8ae2db5 | 2015-07-15 13:00:36 -0500 | [diff] [blame] | 4601 | move_binding(struct weston_pointer *pointer, uint32_t time, |
| 4602 | uint32_t button, void *data) |
Kristian Høgsberg | 0793756 | 2011-04-12 17:25:42 -0400 | [diff] [blame] | 4603 | { |
Rafal Mielniczuk | b2917a2 | 2014-01-05 20:04:59 +0100 | [diff] [blame] | 4604 | struct weston_surface *focus; |
Pekka Paalanen | 01388e2 | 2013-04-25 13:57:44 +0300 | [diff] [blame] | 4605 | struct weston_surface *surface; |
Kristian Høgsberg | 938b8fa | 2012-05-18 13:46:27 -0400 | [diff] [blame] | 4606 | struct shell_surface *shsurf; |
Kristian Høgsberg | d2abb83 | 2011-11-23 10:52:40 -0500 | [diff] [blame] | 4607 | |
Derek Foreman | 8ae2db5 | 2015-07-15 13:00:36 -0500 | [diff] [blame] | 4608 | if (pointer->focus == NULL) |
Rafal Mielniczuk | b2917a2 | 2014-01-05 20:04:59 +0100 | [diff] [blame] | 4609 | return; |
| 4610 | |
Derek Foreman | 8ae2db5 | 2015-07-15 13:00:36 -0500 | [diff] [blame] | 4611 | focus = pointer->focus->surface; |
Rafal Mielniczuk | b2917a2 | 2014-01-05 20:04:59 +0100 | [diff] [blame] | 4612 | |
Pekka Paalanen | 01388e2 | 2013-04-25 13:57:44 +0300 | [diff] [blame] | 4613 | surface = weston_surface_get_main_surface(focus); |
Benjamin Franzke | d0f79ab | 2011-11-22 12:43:52 +0100 | [diff] [blame] | 4614 | if (surface == NULL) |
| 4615 | return; |
Kristian Høgsberg | 0793756 | 2011-04-12 17:25:42 -0400 | [diff] [blame] | 4616 | |
Kristian Høgsberg | 938b8fa | 2012-05-18 13:46:27 -0400 | [diff] [blame] | 4617 | shsurf = get_shell_surface(surface); |
Rafael Antognolli | 03b1659 | 2013-12-03 15:35:42 -0200 | [diff] [blame] | 4618 | if (shsurf == NULL || shsurf->state.fullscreen || |
| 4619 | shsurf->state.maximized) |
Kristian Høgsberg | 938b8fa | 2012-05-18 13:46:27 -0400 | [diff] [blame] | 4620 | return; |
| 4621 | |
Derek Foreman | 794fa0e | 2015-07-15 13:00:38 -0500 | [diff] [blame] | 4622 | surface_move(shsurf, pointer, false); |
Kristian Høgsberg | 0793756 | 2011-04-12 17:25:42 -0400 | [diff] [blame] | 4623 | } |
| 4624 | |
| 4625 | static void |
Derek Foreman | 8ae2db5 | 2015-07-15 13:00:36 -0500 | [diff] [blame] | 4626 | maximize_binding(struct weston_keyboard *keyboard, uint32_t time, |
| 4627 | uint32_t button, void *data) |
Rafael Antognolli | ea997ac | 2013-12-03 15:35:48 -0200 | [diff] [blame] | 4628 | { |
Derek Foreman | 8ae2db5 | 2015-07-15 13:00:36 -0500 | [diff] [blame] | 4629 | struct weston_surface *focus = keyboard->focus; |
Rafael Antognolli | ea997ac | 2013-12-03 15:35:48 -0200 | [diff] [blame] | 4630 | struct weston_surface *surface; |
| 4631 | struct shell_surface *shsurf; |
| 4632 | |
| 4633 | surface = weston_surface_get_main_surface(focus); |
| 4634 | if (surface == NULL) |
| 4635 | return; |
| 4636 | |
| 4637 | shsurf = get_shell_surface(surface); |
| 4638 | if (shsurf == NULL) |
| 4639 | return; |
| 4640 | |
| 4641 | if (!shell_surface_is_xdg_surface(shsurf)) |
| 4642 | return; |
| 4643 | |
Jasper St. Pierre | ab2c108 | 2014-04-10 10:41:46 -0700 | [diff] [blame] | 4644 | shsurf->state_requested = true; |
| 4645 | shsurf->requested_state.maximized = !shsurf->state.maximized; |
Jasper St. Pierre | 9aa8ce6 | 2014-04-11 16:18:54 -0700 | [diff] [blame] | 4646 | send_configure_for_surface(shsurf); |
Rafael Antognolli | ea997ac | 2013-12-03 15:35:48 -0200 | [diff] [blame] | 4647 | } |
| 4648 | |
| 4649 | static void |
Derek Foreman | 8ae2db5 | 2015-07-15 13:00:36 -0500 | [diff] [blame] | 4650 | fullscreen_binding(struct weston_keyboard *keyboard, uint32_t time, |
| 4651 | uint32_t button, void *data) |
Rafael Antognolli | ea997ac | 2013-12-03 15:35:48 -0200 | [diff] [blame] | 4652 | { |
Derek Foreman | 8ae2db5 | 2015-07-15 13:00:36 -0500 | [diff] [blame] | 4653 | struct weston_surface *focus = keyboard->focus; |
Rafael Antognolli | ea997ac | 2013-12-03 15:35:48 -0200 | [diff] [blame] | 4654 | struct weston_surface *surface; |
| 4655 | struct shell_surface *shsurf; |
| 4656 | |
| 4657 | surface = weston_surface_get_main_surface(focus); |
| 4658 | if (surface == NULL) |
| 4659 | return; |
| 4660 | |
| 4661 | shsurf = get_shell_surface(surface); |
| 4662 | if (shsurf == NULL) |
| 4663 | return; |
| 4664 | |
| 4665 | if (!shell_surface_is_xdg_surface(shsurf)) |
| 4666 | return; |
| 4667 | |
Jasper St. Pierre | ab2c108 | 2014-04-10 10:41:46 -0700 | [diff] [blame] | 4668 | shsurf->state_requested = true; |
| 4669 | shsurf->requested_state.fullscreen = !shsurf->state.fullscreen; |
Boyan Ding | 32abdbb | 2014-06-26 10:19:32 +0800 | [diff] [blame] | 4670 | shsurf->fullscreen_output = shsurf->output; |
Jasper St. Pierre | 9aa8ce6 | 2014-04-11 16:18:54 -0700 | [diff] [blame] | 4671 | send_configure_for_surface(shsurf); |
Rafael Antognolli | ea997ac | 2013-12-03 15:35:48 -0200 | [diff] [blame] | 4672 | } |
| 4673 | |
| 4674 | static void |
Derek Foreman | 8ae2db5 | 2015-07-15 13:00:36 -0500 | [diff] [blame] | 4675 | touch_move_binding(struct weston_touch *touch, uint32_t time, void *data) |
Neil Roberts | aba0f25 | 2013-10-03 16:43:05 +0100 | [diff] [blame] | 4676 | { |
Derek Foreman | 362656b | 2014-09-04 10:23:05 -0500 | [diff] [blame] | 4677 | struct weston_surface *focus; |
Neil Roberts | aba0f25 | 2013-10-03 16:43:05 +0100 | [diff] [blame] | 4678 | struct weston_surface *surface; |
| 4679 | struct shell_surface *shsurf; |
| 4680 | |
Derek Foreman | 8ae2db5 | 2015-07-15 13:00:36 -0500 | [diff] [blame] | 4681 | if (touch->focus == NULL) |
Derek Foreman | 362656b | 2014-09-04 10:23:05 -0500 | [diff] [blame] | 4682 | return; |
| 4683 | |
Derek Foreman | 8ae2db5 | 2015-07-15 13:00:36 -0500 | [diff] [blame] | 4684 | focus = touch->focus->surface; |
Neil Roberts | aba0f25 | 2013-10-03 16:43:05 +0100 | [diff] [blame] | 4685 | surface = weston_surface_get_main_surface(focus); |
| 4686 | if (surface == NULL) |
| 4687 | return; |
| 4688 | |
| 4689 | shsurf = get_shell_surface(surface); |
Rafael Antognolli | 03b1659 | 2013-12-03 15:35:42 -0200 | [diff] [blame] | 4690 | if (shsurf == NULL || shsurf->state.fullscreen || |
| 4691 | shsurf->state.maximized) |
Neil Roberts | aba0f25 | 2013-10-03 16:43:05 +0100 | [diff] [blame] | 4692 | return; |
| 4693 | |
Derek Foreman | b7674ae | 2015-07-15 13:00:37 -0500 | [diff] [blame] | 4694 | surface_touch_move(shsurf, touch); |
Neil Roberts | aba0f25 | 2013-10-03 16:43:05 +0100 | [diff] [blame] | 4695 | } |
| 4696 | |
| 4697 | static void |
Derek Foreman | 8ae2db5 | 2015-07-15 13:00:36 -0500 | [diff] [blame] | 4698 | resize_binding(struct weston_pointer *pointer, uint32_t time, |
| 4699 | uint32_t button, void *data) |
Kristian Høgsberg | 0793756 | 2011-04-12 17:25:42 -0400 | [diff] [blame] | 4700 | { |
Rafal Mielniczuk | b2917a2 | 2014-01-05 20:04:59 +0100 | [diff] [blame] | 4701 | struct weston_surface *focus; |
Pekka Paalanen | 01388e2 | 2013-04-25 13:57:44 +0300 | [diff] [blame] | 4702 | struct weston_surface *surface; |
Kristian Høgsberg | 0793756 | 2011-04-12 17:25:42 -0400 | [diff] [blame] | 4703 | uint32_t edges = 0; |
| 4704 | int32_t x, y; |
Pekka Paalanen | 9d1613e | 2011-11-25 12:09:16 +0200 | [diff] [blame] | 4705 | struct shell_surface *shsurf; |
Kristian Høgsberg | d2abb83 | 2011-11-23 10:52:40 -0500 | [diff] [blame] | 4706 | |
Derek Foreman | 8ae2db5 | 2015-07-15 13:00:36 -0500 | [diff] [blame] | 4707 | if (pointer->focus == NULL) |
Rafal Mielniczuk | b2917a2 | 2014-01-05 20:04:59 +0100 | [diff] [blame] | 4708 | return; |
| 4709 | |
Derek Foreman | 8ae2db5 | 2015-07-15 13:00:36 -0500 | [diff] [blame] | 4710 | focus = pointer->focus->surface; |
Rafal Mielniczuk | b2917a2 | 2014-01-05 20:04:59 +0100 | [diff] [blame] | 4711 | |
Pekka Paalanen | 01388e2 | 2013-04-25 13:57:44 +0300 | [diff] [blame] | 4712 | surface = weston_surface_get_main_surface(focus); |
Benjamin Franzke | d0f79ab | 2011-11-22 12:43:52 +0100 | [diff] [blame] | 4713 | if (surface == NULL) |
| 4714 | return; |
Pekka Paalanen | 92a0dc4 | 2011-11-28 15:34:13 +0200 | [diff] [blame] | 4715 | |
Pekka Paalanen | 9d1613e | 2011-11-25 12:09:16 +0200 | [diff] [blame] | 4716 | shsurf = get_shell_surface(surface); |
Rafael Antognolli | 03b1659 | 2013-12-03 15:35:42 -0200 | [diff] [blame] | 4717 | if (shsurf == NULL || shsurf->state.fullscreen || |
| 4718 | shsurf->state.maximized) |
Pekka Paalanen | 92a0dc4 | 2011-11-28 15:34:13 +0200 | [diff] [blame] | 4719 | return; |
| 4720 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 4721 | weston_view_from_global(shsurf->view, |
Derek Foreman | 8ae2db5 | 2015-07-15 13:00:36 -0500 | [diff] [blame] | 4722 | wl_fixed_to_int(pointer->grab_x), |
| 4723 | wl_fixed_to_int(pointer->grab_y), |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 4724 | &x, &y); |
Kristian Høgsberg | 0793756 | 2011-04-12 17:25:42 -0400 | [diff] [blame] | 4725 | |
Jason Ekstrand | 918f2dd | 2013-12-02 21:01:53 -0600 | [diff] [blame] | 4726 | if (x < shsurf->surface->width / 3) |
Pekka Paalanen | 9d1613e | 2011-11-25 12:09:16 +0200 | [diff] [blame] | 4727 | edges |= WL_SHELL_SURFACE_RESIZE_LEFT; |
Jason Ekstrand | 918f2dd | 2013-12-02 21:01:53 -0600 | [diff] [blame] | 4728 | else if (x < 2 * shsurf->surface->width / 3) |
Kristian Høgsberg | 0793756 | 2011-04-12 17:25:42 -0400 | [diff] [blame] | 4729 | edges |= 0; |
| 4730 | else |
Pekka Paalanen | 9d1613e | 2011-11-25 12:09:16 +0200 | [diff] [blame] | 4731 | edges |= WL_SHELL_SURFACE_RESIZE_RIGHT; |
Kristian Høgsberg | 0793756 | 2011-04-12 17:25:42 -0400 | [diff] [blame] | 4732 | |
Jason Ekstrand | 918f2dd | 2013-12-02 21:01:53 -0600 | [diff] [blame] | 4733 | if (y < shsurf->surface->height / 3) |
Pekka Paalanen | 9d1613e | 2011-11-25 12:09:16 +0200 | [diff] [blame] | 4734 | edges |= WL_SHELL_SURFACE_RESIZE_TOP; |
Jason Ekstrand | 918f2dd | 2013-12-02 21:01:53 -0600 | [diff] [blame] | 4735 | else if (y < 2 * shsurf->surface->height / 3) |
Kristian Høgsberg | 0793756 | 2011-04-12 17:25:42 -0400 | [diff] [blame] | 4736 | edges |= 0; |
| 4737 | else |
Pekka Paalanen | 9d1613e | 2011-11-25 12:09:16 +0200 | [diff] [blame] | 4738 | edges |= WL_SHELL_SURFACE_RESIZE_BOTTOM; |
Kristian Høgsberg | 0793756 | 2011-04-12 17:25:42 -0400 | [diff] [blame] | 4739 | |
Derek Foreman | 8fbebbd | 2015-07-15 13:00:40 -0500 | [diff] [blame] | 4740 | surface_resize(shsurf, pointer, edges); |
Kristian Høgsberg | 02ec0a5 | 2011-04-23 13:04:11 -0400 | [diff] [blame] | 4741 | } |
| 4742 | |
| 4743 | static void |
Derek Foreman | 8ae2db5 | 2015-07-15 13:00:36 -0500 | [diff] [blame] | 4744 | surface_opacity_binding(struct weston_pointer *pointer, uint32_t time, |
| 4745 | uint32_t axis, wl_fixed_t value, void *data) |
Scott Moreau | a3aa9c9 | 2012-03-22 11:01:03 -0600 | [diff] [blame] | 4746 | { |
Jonas Ådahl | b0b87ba | 2012-09-27 18:40:42 +0200 | [diff] [blame] | 4747 | float step = 0.005; |
Scott Moreau | a3aa9c9 | 2012-03-22 11:01:03 -0600 | [diff] [blame] | 4748 | struct shell_surface *shsurf; |
Derek Foreman | 8ae2db5 | 2015-07-15 13:00:36 -0500 | [diff] [blame] | 4749 | struct weston_surface *focus = pointer->focus->surface; |
Pekka Paalanen | 01388e2 | 2013-04-25 13:57:44 +0300 | [diff] [blame] | 4750 | struct weston_surface *surface; |
Scott Moreau | a3aa9c9 | 2012-03-22 11:01:03 -0600 | [diff] [blame] | 4751 | |
Pekka Paalanen | 01388e2 | 2013-04-25 13:57:44 +0300 | [diff] [blame] | 4752 | /* XXX: broken for windows containing sub-surfaces */ |
| 4753 | surface = weston_surface_get_main_surface(focus); |
Scott Moreau | a3aa9c9 | 2012-03-22 11:01:03 -0600 | [diff] [blame] | 4754 | if (surface == NULL) |
| 4755 | return; |
| 4756 | |
| 4757 | shsurf = get_shell_surface(surface); |
| 4758 | if (!shsurf) |
| 4759 | return; |
| 4760 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 4761 | shsurf->view->alpha -= wl_fixed_to_double(value) * step; |
Scott Moreau | a3aa9c9 | 2012-03-22 11:01:03 -0600 | [diff] [blame] | 4762 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 4763 | if (shsurf->view->alpha > 1.0) |
| 4764 | shsurf->view->alpha = 1.0; |
| 4765 | if (shsurf->view->alpha < step) |
| 4766 | shsurf->view->alpha = step; |
Scott Moreau | a3aa9c9 | 2012-03-22 11:01:03 -0600 | [diff] [blame] | 4767 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 4768 | weston_view_geometry_dirty(shsurf->view); |
Scott Moreau | a3aa9c9 | 2012-03-22 11:01:03 -0600 | [diff] [blame] | 4769 | weston_surface_damage(surface); |
| 4770 | } |
| 4771 | |
| 4772 | static void |
Kristian Høgsberg | e314875 | 2013-05-06 23:19:49 -0400 | [diff] [blame] | 4773 | 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] | 4774 | wl_fixed_t value) |
Scott Moreau | ccbf29d | 2012-02-22 14:21:41 -0700 | [diff] [blame] | 4775 | { |
Derek Foreman | 8aeeac8 | 2015-01-30 13:24:36 -0600 | [diff] [blame] | 4776 | struct weston_compositor *compositor = seat->compositor; |
Scott Moreau | ccbf29d | 2012-02-22 14:21:41 -0700 | [diff] [blame] | 4777 | struct weston_output *output; |
Scott Moreau | e660398 | 2012-06-11 13:07:51 -0600 | [diff] [blame] | 4778 | float increment; |
Scott Moreau | ccbf29d | 2012-02-22 14:21:41 -0700 | [diff] [blame] | 4779 | |
Derek Foreman | 7ef3bed | 2015-01-06 14:28:13 -0600 | [diff] [blame] | 4780 | if (!seat->pointer) { |
| 4781 | weston_log("Zoom hotkey pressed but seat '%s' contains no pointer.\n", seat->seat_name); |
| 4782 | return; |
| 4783 | } |
| 4784 | |
Scott Moreau | ccbf29d | 2012-02-22 14:21:41 -0700 | [diff] [blame] | 4785 | wl_list_for_each(output, &compositor->output_list, link) { |
| 4786 | if (pixman_region32_contains_point(&output->region, |
Daniel Stone | 37816df | 2012-05-16 18:45:18 +0100 | [diff] [blame] | 4787 | wl_fixed_to_double(seat->pointer->x), |
| 4788 | wl_fixed_to_double(seat->pointer->y), |
Daniel Stone | 103db7f | 2012-05-08 17:17:55 +0100 | [diff] [blame] | 4789 | NULL)) { |
Daniel Stone | 325fc2d | 2012-05-30 16:31:58 +0100 | [diff] [blame] | 4790 | if (key == KEY_PAGEUP) |
Kristian Høgsberg | 9b68af0 | 2012-05-22 12:55:18 -0400 | [diff] [blame] | 4791 | increment = output->zoom.increment; |
Daniel Stone | 325fc2d | 2012-05-30 16:31:58 +0100 | [diff] [blame] | 4792 | else if (key == KEY_PAGEDOWN) |
Kristian Høgsberg | 9b68af0 | 2012-05-22 12:55:18 -0400 | [diff] [blame] | 4793 | increment = -output->zoom.increment; |
| 4794 | else if (axis == WL_POINTER_AXIS_VERTICAL_SCROLL) |
Jonas Ådahl | b0b87ba | 2012-09-27 18:40:42 +0200 | [diff] [blame] | 4795 | /* For every pixel zoom 20th of a step */ |
Daniel Stone | 0c1e46e | 2012-05-30 16:31:59 +0100 | [diff] [blame] | 4796 | increment = output->zoom.increment * |
Jonas Ådahl | b0b87ba | 2012-09-27 18:40:42 +0200 | [diff] [blame] | 4797 | -wl_fixed_to_double(value) / 20.0; |
Kristian Høgsberg | 9b68af0 | 2012-05-22 12:55:18 -0400 | [diff] [blame] | 4798 | else |
| 4799 | increment = 0; |
| 4800 | |
Kristian Høgsberg | 9b68af0 | 2012-05-22 12:55:18 -0400 | [diff] [blame] | 4801 | output->zoom.level += increment; |
Scott Moreau | c6d7f60 | 2012-02-23 22:28:37 -0700 | [diff] [blame] | 4802 | |
Scott Moreau | e660398 | 2012-06-11 13:07:51 -0600 | [diff] [blame] | 4803 | if (output->zoom.level < 0.0) |
Scott Moreau | 850ca42 | 2012-05-21 15:21:25 -0600 | [diff] [blame] | 4804 | output->zoom.level = 0.0; |
Scott Moreau | e660398 | 2012-06-11 13:07:51 -0600 | [diff] [blame] | 4805 | else if (output->zoom.level > output->zoom.max_level) |
| 4806 | output->zoom.level = output->zoom.max_level; |
Ville Syrjälä | aa628d0 | 2012-11-16 11:48:47 +0200 | [diff] [blame] | 4807 | else if (!output->zoom.active) { |
Giulio Camuffo | 412b024 | 2013-11-14 23:42:51 +0100 | [diff] [blame] | 4808 | weston_output_activate_zoom(output); |
Kristian Høgsberg | 79af73e | 2012-08-03 15:45:23 -0400 | [diff] [blame] | 4809 | } |
Scott Moreau | ccbf29d | 2012-02-22 14:21:41 -0700 | [diff] [blame] | 4810 | |
Scott Moreau | e660398 | 2012-06-11 13:07:51 -0600 | [diff] [blame] | 4811 | output->zoom.spring_z.target = output->zoom.level; |
Scott Moreau | ccbf29d | 2012-02-22 14:21:41 -0700 | [diff] [blame] | 4812 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 4813 | weston_output_update_zoom(output); |
Scott Moreau | ccbf29d | 2012-02-22 14:21:41 -0700 | [diff] [blame] | 4814 | } |
| 4815 | } |
| 4816 | } |
| 4817 | |
Scott Moreau | ccbf29d | 2012-02-22 14:21:41 -0700 | [diff] [blame] | 4818 | static void |
Derek Foreman | 8ae2db5 | 2015-07-15 13:00:36 -0500 | [diff] [blame] | 4819 | zoom_axis_binding(struct weston_pointer *pointer, uint32_t time, |
| 4820 | uint32_t axis, wl_fixed_t value, void *data) |
Daniel Stone | 325fc2d | 2012-05-30 16:31:58 +0100 | [diff] [blame] | 4821 | { |
Derek Foreman | 8ae2db5 | 2015-07-15 13:00:36 -0500 | [diff] [blame] | 4822 | do_zoom(pointer->seat, time, 0, axis, value); |
Daniel Stone | 325fc2d | 2012-05-30 16:31:58 +0100 | [diff] [blame] | 4823 | } |
| 4824 | |
| 4825 | static void |
Derek Foreman | 8ae2db5 | 2015-07-15 13:00:36 -0500 | [diff] [blame] | 4826 | zoom_key_binding(struct weston_keyboard *keyboard, uint32_t time, |
| 4827 | uint32_t key, void *data) |
Daniel Stone | 325fc2d | 2012-05-30 16:31:58 +0100 | [diff] [blame] | 4828 | { |
Derek Foreman | 8ae2db5 | 2015-07-15 13:00:36 -0500 | [diff] [blame] | 4829 | do_zoom(keyboard->seat, time, key, 0, 0); |
Daniel Stone | 325fc2d | 2012-05-30 16:31:58 +0100 | [diff] [blame] | 4830 | } |
| 4831 | |
| 4832 | static void |
Derek Foreman | 8ae2db5 | 2015-07-15 13:00:36 -0500 | [diff] [blame] | 4833 | terminate_binding(struct weston_keyboard *keyboard, uint32_t time, |
| 4834 | uint32_t key, void *data) |
Kristian Høgsberg | e1a850e | 2011-12-19 15:18:05 -0500 | [diff] [blame] | 4835 | { |
Kristian Høgsberg | 8334bc1 | 2012-01-03 10:29:47 -0500 | [diff] [blame] | 4836 | struct weston_compositor *compositor = data; |
Kristian Høgsberg | e1a850e | 2011-12-19 15:18:05 -0500 | [diff] [blame] | 4837 | |
Daniel Stone | 325fc2d | 2012-05-30 16:31:58 +0100 | [diff] [blame] | 4838 | wl_display_terminate(compositor->wl_display); |
Kristian Høgsberg | e1a850e | 2011-12-19 15:18:05 -0500 | [diff] [blame] | 4839 | } |
| 4840 | |
Emilio Pozuelo Monfort | 03251b6 | 2013-11-19 11:37:16 +0100 | [diff] [blame] | 4841 | static void |
Giulio Camuffo | 1959ab8 | 2013-11-14 23:42:52 +0100 | [diff] [blame] | 4842 | rotate_grab_motion(struct weston_pointer_grab *grab, uint32_t time, |
| 4843 | wl_fixed_t x, wl_fixed_t y) |
Pekka Paalanen | 460099f | 2012-01-20 16:48:25 +0200 | [diff] [blame] | 4844 | { |
| 4845 | struct rotate_grab *rotate = |
Ander Conselvan de Oliveira | fe0444a | 2012-04-04 17:48:05 +0300 | [diff] [blame] | 4846 | container_of(grab, struct rotate_grab, base.grab); |
Kristian Høgsberg | 02bbabb | 2013-05-06 22:15:05 -0400 | [diff] [blame] | 4847 | struct weston_pointer *pointer = grab->pointer; |
Ander Conselvan de Oliveira | fe0444a | 2012-04-04 17:48:05 +0300 | [diff] [blame] | 4848 | struct shell_surface *shsurf = rotate->base.shsurf; |
John Kåre Alsaker | 490d02a | 2012-09-30 02:57:21 +0200 | [diff] [blame] | 4849 | float cx, cy, dx, dy, cposx, cposy, dposx, dposy, r; |
Ander Conselvan de Oliveira | fe0444a | 2012-04-04 17:48:05 +0300 | [diff] [blame] | 4850 | |
Giulio Camuffo | 1959ab8 | 2013-11-14 23:42:52 +0100 | [diff] [blame] | 4851 | weston_pointer_move(pointer, x, y); |
| 4852 | |
Ander Conselvan de Oliveira | fe0444a | 2012-04-04 17:48:05 +0300 | [diff] [blame] | 4853 | if (!shsurf) |
| 4854 | return; |
| 4855 | |
Jason Ekstrand | 918f2dd | 2013-12-02 21:01:53 -0600 | [diff] [blame] | 4856 | cx = 0.5f * shsurf->surface->width; |
| 4857 | cy = 0.5f * shsurf->surface->height; |
Pekka Paalanen | 460099f | 2012-01-20 16:48:25 +0200 | [diff] [blame] | 4858 | |
Daniel Stone | 37816df | 2012-05-16 18:45:18 +0100 | [diff] [blame] | 4859 | dx = wl_fixed_to_double(pointer->x) - rotate->center.x; |
| 4860 | dy = wl_fixed_to_double(pointer->y) - rotate->center.y; |
Pekka Paalanen | 460099f | 2012-01-20 16:48:25 +0200 | [diff] [blame] | 4861 | r = sqrtf(dx * dx + dy * dy); |
| 4862 | |
Ander Conselvan de Oliveira | fe0444a | 2012-04-04 17:48:05 +0300 | [diff] [blame] | 4863 | wl_list_remove(&shsurf->rotation.transform.link); |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 4864 | weston_view_geometry_dirty(shsurf->view); |
Pekka Paalanen | 460099f | 2012-01-20 16:48:25 +0200 | [diff] [blame] | 4865 | |
| 4866 | if (r > 20.0f) { |
Pekka Paalanen | 460099f | 2012-01-20 16:48:25 +0200 | [diff] [blame] | 4867 | struct weston_matrix *matrix = |
Ander Conselvan de Oliveira | fe0444a | 2012-04-04 17:48:05 +0300 | [diff] [blame] | 4868 | &shsurf->rotation.transform.matrix; |
Pekka Paalanen | 460099f | 2012-01-20 16:48:25 +0200 | [diff] [blame] | 4869 | |
Kristian Høgsberg | 765e27b | 2012-01-27 13:36:13 -0500 | [diff] [blame] | 4870 | weston_matrix_init(&rotate->rotation); |
Vasily Khoruzhick | 1bbf372 | 2013-01-28 22:40:28 +0300 | [diff] [blame] | 4871 | weston_matrix_rotate_xy(&rotate->rotation, dx / r, dy / r); |
Pekka Paalanen | 460099f | 2012-01-20 16:48:25 +0200 | [diff] [blame] | 4872 | |
| 4873 | weston_matrix_init(matrix); |
Pekka Paalanen | 7b3bd3d | 2012-01-30 14:16:34 +0200 | [diff] [blame] | 4874 | weston_matrix_translate(matrix, -cx, -cy, 0.0f); |
Ander Conselvan de Oliveira | fe0444a | 2012-04-04 17:48:05 +0300 | [diff] [blame] | 4875 | weston_matrix_multiply(matrix, &shsurf->rotation.rotation); |
Kristian Høgsberg | 765e27b | 2012-01-27 13:36:13 -0500 | [diff] [blame] | 4876 | weston_matrix_multiply(matrix, &rotate->rotation); |
Pekka Paalanen | 7b3bd3d | 2012-01-30 14:16:34 +0200 | [diff] [blame] | 4877 | weston_matrix_translate(matrix, cx, cy, 0.0f); |
Pekka Paalanen | 460099f | 2012-01-20 16:48:25 +0200 | [diff] [blame] | 4878 | |
Pekka Paalanen | bc0b7e7 | 2012-01-24 09:53:37 +0200 | [diff] [blame] | 4879 | wl_list_insert( |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 4880 | &shsurf->view->geometry.transformation_list, |
Ander Conselvan de Oliveira | fe0444a | 2012-04-04 17:48:05 +0300 | [diff] [blame] | 4881 | &shsurf->rotation.transform.link); |
Pekka Paalanen | 460099f | 2012-01-20 16:48:25 +0200 | [diff] [blame] | 4882 | } else { |
Ander Conselvan de Oliveira | fe0444a | 2012-04-04 17:48:05 +0300 | [diff] [blame] | 4883 | wl_list_init(&shsurf->rotation.transform.link); |
| 4884 | weston_matrix_init(&shsurf->rotation.rotation); |
Kristian Høgsberg | 765e27b | 2012-01-27 13:36:13 -0500 | [diff] [blame] | 4885 | weston_matrix_init(&rotate->rotation); |
Pekka Paalanen | 460099f | 2012-01-20 16:48:25 +0200 | [diff] [blame] | 4886 | } |
Pekka Paalanen | b45ac5e | 2012-02-09 15:58:44 +0200 | [diff] [blame] | 4887 | |
Rafal Mielniczuk | 2d7ab82 | 2012-03-22 22:22:04 +0100 | [diff] [blame] | 4888 | /* We need to adjust the position of the surface |
| 4889 | * in case it was resized in a rotated state before */ |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 4890 | cposx = shsurf->view->geometry.x + cx; |
| 4891 | cposy = shsurf->view->geometry.y + cy; |
Rafal Mielniczuk | 2d7ab82 | 2012-03-22 22:22:04 +0100 | [diff] [blame] | 4892 | dposx = rotate->center.x - cposx; |
| 4893 | dposy = rotate->center.y - cposy; |
| 4894 | if (dposx != 0.0f || dposy != 0.0f) { |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 4895 | weston_view_set_position(shsurf->view, |
| 4896 | shsurf->view->geometry.x + dposx, |
| 4897 | shsurf->view->geometry.y + dposy); |
Rafal Mielniczuk | 2d7ab82 | 2012-03-22 22:22:04 +0100 | [diff] [blame] | 4898 | } |
| 4899 | |
Derek Foreman | 4b1a0a1 | 2014-09-10 15:37:33 -0500 | [diff] [blame] | 4900 | /* Repaint implies weston_view_update_transform(), which |
Pekka Paalanen | b45ac5e | 2012-02-09 15:58:44 +0200 | [diff] [blame] | 4901 | * lazily applies the damage due to rotation update. |
| 4902 | */ |
Ander Conselvan de Oliveira | fe0444a | 2012-04-04 17:48:05 +0300 | [diff] [blame] | 4903 | weston_compositor_schedule_repaint(shsurf->surface->compositor); |
Pekka Paalanen | 460099f | 2012-01-20 16:48:25 +0200 | [diff] [blame] | 4904 | } |
| 4905 | |
| 4906 | static void |
Kristian Høgsberg | 02bbabb | 2013-05-06 22:15:05 -0400 | [diff] [blame] | 4907 | rotate_grab_button(struct weston_pointer_grab *grab, |
| 4908 | uint32_t time, uint32_t button, uint32_t state_w) |
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; |
Daniel Stone | 4dbadb1 | 2012-05-30 16:31:51 +0100 | [diff] [blame] | 4914 | enum wl_pointer_button_state state = state_w; |
Pekka Paalanen | 460099f | 2012-01-20 16:48:25 +0200 | [diff] [blame] | 4915 | |
Daniel Stone | 4dbadb1 | 2012-05-30 16:31:51 +0100 | [diff] [blame] | 4916 | if (pointer->button_count == 0 && |
| 4917 | state == WL_POINTER_BUTTON_STATE_RELEASED) { |
Ander Conselvan de Oliveira | fe0444a | 2012-04-04 17:48:05 +0300 | [diff] [blame] | 4918 | if (shsurf) |
| 4919 | weston_matrix_multiply(&shsurf->rotation.rotation, |
| 4920 | &rotate->rotation); |
Ander Conselvan de Oliveira | b9d2a0f | 2012-06-28 18:08:05 +0300 | [diff] [blame] | 4921 | shell_grab_end(&rotate->base); |
Pekka Paalanen | 460099f | 2012-01-20 16:48:25 +0200 | [diff] [blame] | 4922 | free(rotate); |
| 4923 | } |
| 4924 | } |
| 4925 | |
Jonas Ådahl | 1ea343e | 2013-10-25 23:18:05 +0200 | [diff] [blame] | 4926 | static void |
| 4927 | rotate_grab_cancel(struct weston_pointer_grab *grab) |
| 4928 | { |
| 4929 | struct rotate_grab *rotate = |
| 4930 | container_of(grab, struct rotate_grab, base.grab); |
| 4931 | |
| 4932 | shell_grab_end(&rotate->base); |
| 4933 | free(rotate); |
| 4934 | } |
| 4935 | |
Kristian Høgsberg | 02bbabb | 2013-05-06 22:15:05 -0400 | [diff] [blame] | 4936 | static const struct weston_pointer_grab_interface rotate_grab_interface = { |
Pekka Paalanen | 460099f | 2012-01-20 16:48:25 +0200 | [diff] [blame] | 4937 | noop_grab_focus, |
| 4938 | rotate_grab_motion, |
| 4939 | rotate_grab_button, |
Jonas Ådahl | 1ea343e | 2013-10-25 23:18:05 +0200 | [diff] [blame] | 4940 | rotate_grab_cancel, |
Pekka Paalanen | 460099f | 2012-01-20 16:48:25 +0200 | [diff] [blame] | 4941 | }; |
| 4942 | |
| 4943 | static void |
Derek Foreman | 74de469 | 2015-07-15 13:00:39 -0500 | [diff] [blame] | 4944 | surface_rotate(struct shell_surface *surface, struct weston_pointer *pointer) |
Pekka Paalanen | 460099f | 2012-01-20 16:48:25 +0200 | [diff] [blame] | 4945 | { |
Pekka Paalanen | 460099f | 2012-01-20 16:48:25 +0200 | [diff] [blame] | 4946 | struct rotate_grab *rotate; |
John Kåre Alsaker | 490d02a | 2012-09-30 02:57:21 +0200 | [diff] [blame] | 4947 | float dx, dy; |
| 4948 | float r; |
Pekka Paalanen | 460099f | 2012-01-20 16:48:25 +0200 | [diff] [blame] | 4949 | |
Pekka Paalanen | 460099f | 2012-01-20 16:48:25 +0200 | [diff] [blame] | 4950 | rotate = malloc(sizeof *rotate); |
| 4951 | if (!rotate) |
| 4952 | return; |
| 4953 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 4954 | weston_view_to_global_float(surface->view, |
Jason Ekstrand | 918f2dd | 2013-12-02 21:01:53 -0600 | [diff] [blame] | 4955 | surface->surface->width * 0.5f, |
| 4956 | surface->surface->height * 0.5f, |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 4957 | &rotate->center.x, &rotate->center.y); |
Pekka Paalanen | 460099f | 2012-01-20 16:48:25 +0200 | [diff] [blame] | 4958 | |
Derek Foreman | 74de469 | 2015-07-15 13:00:39 -0500 | [diff] [blame] | 4959 | dx = wl_fixed_to_double(pointer->x) - rotate->center.x; |
| 4960 | dy = wl_fixed_to_double(pointer->y) - rotate->center.y; |
Kristian Høgsberg | 765e27b | 2012-01-27 13:36:13 -0500 | [diff] [blame] | 4961 | r = sqrtf(dx * dx + dy * dy); |
| 4962 | if (r > 20.0f) { |
| 4963 | struct weston_matrix inverse; |
| 4964 | |
| 4965 | weston_matrix_init(&inverse); |
Vasily Khoruzhick | 1bbf372 | 2013-01-28 22:40:28 +0300 | [diff] [blame] | 4966 | weston_matrix_rotate_xy(&inverse, dx / r, -dy / r); |
Kristian Høgsberg | 765e27b | 2012-01-27 13:36:13 -0500 | [diff] [blame] | 4967 | weston_matrix_multiply(&surface->rotation.rotation, &inverse); |
Rafal Mielniczuk | 2d7ab82 | 2012-03-22 22:22:04 +0100 | [diff] [blame] | 4968 | |
| 4969 | weston_matrix_init(&rotate->rotation); |
Vasily Khoruzhick | 1bbf372 | 2013-01-28 22:40:28 +0300 | [diff] [blame] | 4970 | weston_matrix_rotate_xy(&rotate->rotation, dx / r, dy / r); |
Kristian Høgsberg | 765e27b | 2012-01-27 13:36:13 -0500 | [diff] [blame] | 4971 | } else { |
| 4972 | weston_matrix_init(&surface->rotation.rotation); |
| 4973 | weston_matrix_init(&rotate->rotation); |
| 4974 | } |
| 4975 | |
Ander Conselvan de Oliveira | b9d2a0f | 2012-06-28 18:08:05 +0300 | [diff] [blame] | 4976 | shell_grab_start(&rotate->base, &rotate_grab_interface, surface, |
Derek Foreman | 74de469 | 2015-07-15 13:00:39 -0500 | [diff] [blame] | 4977 | pointer, DESKTOP_SHELL_CURSOR_ARROW); |
Pekka Paalanen | 460099f | 2012-01-20 16:48:25 +0200 | [diff] [blame] | 4978 | } |
| 4979 | |
| 4980 | static void |
Derek Foreman | 8ae2db5 | 2015-07-15 13:00:36 -0500 | [diff] [blame] | 4981 | 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] | 4982 | void *data) |
| 4983 | { |
Rafal Mielniczuk | b2917a2 | 2014-01-05 20:04:59 +0100 | [diff] [blame] | 4984 | struct weston_surface *focus; |
Pekka Paalanen | 01388e2 | 2013-04-25 13:57:44 +0300 | [diff] [blame] | 4985 | struct weston_surface *base_surface; |
Kristian Høgsberg | 0c36903 | 2013-02-14 21:31:44 -0500 | [diff] [blame] | 4986 | struct shell_surface *surface; |
| 4987 | |
Derek Foreman | 8ae2db5 | 2015-07-15 13:00:36 -0500 | [diff] [blame] | 4988 | if (pointer->focus == NULL) |
Rafal Mielniczuk | b2917a2 | 2014-01-05 20:04:59 +0100 | [diff] [blame] | 4989 | return; |
| 4990 | |
Derek Foreman | 8ae2db5 | 2015-07-15 13:00:36 -0500 | [diff] [blame] | 4991 | focus = pointer->focus->surface; |
Rafal Mielniczuk | b2917a2 | 2014-01-05 20:04:59 +0100 | [diff] [blame] | 4992 | |
Pekka Paalanen | 01388e2 | 2013-04-25 13:57:44 +0300 | [diff] [blame] | 4993 | base_surface = weston_surface_get_main_surface(focus); |
Kristian Høgsberg | 0c36903 | 2013-02-14 21:31:44 -0500 | [diff] [blame] | 4994 | if (base_surface == NULL) |
| 4995 | return; |
| 4996 | |
| 4997 | surface = get_shell_surface(base_surface); |
Rafael Antognolli | 03b1659 | 2013-12-03 15:35:42 -0200 | [diff] [blame] | 4998 | if (surface == NULL || surface->state.fullscreen || |
| 4999 | surface->state.maximized) |
Kristian Høgsberg | 0c36903 | 2013-02-14 21:31:44 -0500 | [diff] [blame] | 5000 | return; |
| 5001 | |
Derek Foreman | 74de469 | 2015-07-15 13:00:39 -0500 | [diff] [blame] | 5002 | surface_rotate(surface, pointer); |
Kristian Høgsberg | 0c36903 | 2013-02-14 21:31:44 -0500 | [diff] [blame] | 5003 | } |
| 5004 | |
Emilio Pozuelo Monfort | 9e7c759 | 2014-01-30 14:01:10 +0100 | [diff] [blame] | 5005 | /* Move all fullscreen layers down to the current workspace and hide their |
| 5006 | * black views. The surfaces' state is set to both fullscreen and lowered, |
| 5007 | * and this is reversed when such a surface is re-configured, see |
| 5008 | * shell_configure_fullscreen() and shell_ensure_fullscreen_black_view(). |
| 5009 | * |
Mario Kleiner | 9f4d655 | 2015-06-21 21:25:08 +0200 | [diff] [blame] | 5010 | * lowering_output = NULL - Lower on all outputs, else only lower on the |
| 5011 | * specified output. |
| 5012 | * |
Emilio Pozuelo Monfort | 9e7c759 | 2014-01-30 14:01:10 +0100 | [diff] [blame] | 5013 | * This should be used when implementing shell-wide overlays, such as |
Philip Withnall | 83ffd9d | 2013-11-25 18:01:42 +0000 | [diff] [blame] | 5014 | * the alt-tab switcher, which need to de-promote fullscreen layers. */ |
Kristian Høgsberg | 1ef2313 | 2013-12-04 00:20:01 -0800 | [diff] [blame] | 5015 | void |
Mario Kleiner | 9f4d655 | 2015-06-21 21:25:08 +0200 | [diff] [blame] | 5016 | lower_fullscreen_layer(struct desktop_shell *shell, |
| 5017 | struct weston_output *lowering_output) |
Kristian Høgsberg | b0d8e77 | 2012-06-18 16:34:58 -0400 | [diff] [blame] | 5018 | { |
| 5019 | struct workspace *ws; |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 5020 | struct weston_view *view, *prev; |
Kristian Høgsberg | b0d8e77 | 2012-06-18 16:34:58 -0400 | [diff] [blame] | 5021 | |
| 5022 | ws = get_current_workspace(shell); |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 5023 | wl_list_for_each_reverse_safe(view, prev, |
Giulio Camuffo | 412e6a5 | 2014-07-09 22:12:56 +0300 | [diff] [blame] | 5024 | &shell->fullscreen_layer.view_list.link, |
| 5025 | layer_link.link) { |
Emilio Pozuelo Monfort | 9e7c759 | 2014-01-30 14:01:10 +0100 | [diff] [blame] | 5026 | struct shell_surface *shsurf = get_shell_surface(view->surface); |
| 5027 | |
| 5028 | if (!shsurf) |
| 5029 | continue; |
| 5030 | |
Mario Kleiner | 9f4d655 | 2015-06-21 21:25:08 +0200 | [diff] [blame] | 5031 | /* Only lower surfaces which have lowering_output as their fullscreen |
| 5032 | * output, unless a NULL output asks for lowering on all outputs. |
| 5033 | */ |
| 5034 | if (lowering_output && (shsurf->fullscreen_output != lowering_output)) |
| 5035 | continue; |
| 5036 | |
Emilio Pozuelo Monfort | 9e7c759 | 2014-01-30 14:01:10 +0100 | [diff] [blame] | 5037 | /* We can have a non-fullscreen popup for a fullscreen surface |
| 5038 | * in the fullscreen layer. */ |
| 5039 | if (shsurf->state.fullscreen) { |
| 5040 | /* Hide the black view */ |
Giulio Camuffo | 412e6a5 | 2014-07-09 22:12:56 +0300 | [diff] [blame] | 5041 | weston_layer_entry_remove(&shsurf->fullscreen.black_view->layer_link); |
| 5042 | wl_list_init(&shsurf->fullscreen.black_view->layer_link.link); |
Kristian Høgsberg | c991513 | 2014-05-09 16:24:07 -0700 | [diff] [blame] | 5043 | weston_view_damage_below(shsurf->fullscreen.black_view); |
| 5044 | |
Emilio Pozuelo Monfort | 9e7c759 | 2014-01-30 14:01:10 +0100 | [diff] [blame] | 5045 | } |
| 5046 | |
| 5047 | /* Lower the view to the workspace layer */ |
Giulio Camuffo | 412e6a5 | 2014-07-09 22:12:56 +0300 | [diff] [blame] | 5048 | weston_layer_entry_remove(&view->layer_link); |
| 5049 | weston_layer_entry_insert(&ws->layer.view_list, &view->layer_link); |
Philip Withnall | 83ffd9d | 2013-11-25 18:01:42 +0000 | [diff] [blame] | 5050 | weston_view_damage_below(view); |
| 5051 | weston_surface_damage(view->surface); |
Emilio Pozuelo Monfort | 9e7c759 | 2014-01-30 14:01:10 +0100 | [diff] [blame] | 5052 | |
| 5053 | shsurf->state.lowered = true; |
Philip Withnall | 83ffd9d | 2013-11-25 18:01:42 +0000 | [diff] [blame] | 5054 | } |
Kristian Høgsberg | b0d8e77 | 2012-06-18 16:34:58 -0400 | [diff] [blame] | 5055 | } |
| 5056 | |
Kristian Høgsberg | 1ef2313 | 2013-12-04 00:20:01 -0800 | [diff] [blame] | 5057 | void |
Tiago Vignatti | be14326 | 2012-04-16 17:31:41 +0300 | [diff] [blame] | 5058 | activate(struct desktop_shell *shell, struct weston_surface *es, |
Emilio Pozuelo Monfort | 9e7c759 | 2014-01-30 14:01:10 +0100 | [diff] [blame] | 5059 | struct weston_seat *seat, bool configure) |
Kristian Høgsberg | 7584062 | 2011-09-06 13:48:16 -0400 | [diff] [blame] | 5060 | { |
Pekka Paalanen | 01388e2 | 2013-04-25 13:57:44 +0300 | [diff] [blame] | 5061 | struct weston_surface *main_surface; |
Kristian Høgsberg | 2f5faff | 2012-07-31 16:36:34 -0400 | [diff] [blame] | 5062 | struct focus_state *state; |
Jonas Ådahl | 8538b22 | 2012-08-29 22:13:03 +0200 | [diff] [blame] | 5063 | struct workspace *ws; |
Louis-Francis Ratté-Boulianne | b482dbd | 2013-11-19 11:37:11 +0100 | [diff] [blame] | 5064 | struct weston_surface *old_es; |
Rafael Antognolli | 03b1659 | 2013-12-03 15:35:42 -0200 | [diff] [blame] | 5065 | struct shell_surface *shsurf; |
Kristian Høgsberg | 7584062 | 2011-09-06 13:48:16 -0400 | [diff] [blame] | 5066 | |
Pekka Paalanen | 01388e2 | 2013-04-25 13:57:44 +0300 | [diff] [blame] | 5067 | main_surface = weston_surface_get_main_surface(es); |
Mario Kleiner | 9f4d655 | 2015-06-21 21:25:08 +0200 | [diff] [blame] | 5068 | shsurf = get_shell_surface(main_surface); |
| 5069 | assert(shsurf); |
| 5070 | |
| 5071 | /* Only demote fullscreen surfaces on the output of activated shsurf. |
| 5072 | * Leave fullscreen surfaces on unrelated outputs alone. */ |
| 5073 | lower_fullscreen_layer(shell, shsurf->output); |
Pekka Paalanen | 01388e2 | 2013-04-25 13:57:44 +0300 | [diff] [blame] | 5074 | |
Daniel Stone | 37816df | 2012-05-16 18:45:18 +0100 | [diff] [blame] | 5075 | weston_surface_activate(es, seat); |
Kristian Høgsberg | 7584062 | 2011-09-06 13:48:16 -0400 | [diff] [blame] | 5076 | |
Jonas Ådahl | 8538b22 | 2012-08-29 22:13:03 +0200 | [diff] [blame] | 5077 | state = ensure_focus_state(shell, seat); |
| 5078 | if (state == NULL) |
| 5079 | return; |
Kristian Høgsberg | 2f5faff | 2012-07-31 16:36:34 -0400 | [diff] [blame] | 5080 | |
Louis-Francis Ratté-Boulianne | b482dbd | 2013-11-19 11:37:11 +0100 | [diff] [blame] | 5081 | old_es = state->keyboard_focus; |
Kristian Høgsberg | d500bf1 | 2014-01-22 12:25:20 -0800 | [diff] [blame] | 5082 | focus_state_set_focus(state, es); |
Kristian Høgsberg | 2f5faff | 2012-07-31 16:36:34 -0400 | [diff] [blame] | 5083 | |
Emilio Pozuelo Monfort | 9e7c759 | 2014-01-30 14:01:10 +0100 | [diff] [blame] | 5084 | if (shsurf->state.fullscreen && configure) |
Rafael Antognolli | 03b1659 | 2013-12-03 15:35:42 -0200 | [diff] [blame] | 5085 | shell_configure_fullscreen(shsurf); |
| 5086 | else |
Mario Kleiner | 492c12f | 2015-06-21 21:25:12 +0200 | [diff] [blame] | 5087 | restore_output_mode(shsurf->output); |
Louis-Francis Ratté-Boulianne | b482dbd | 2013-11-19 11:37:11 +0100 | [diff] [blame] | 5088 | |
Emilio Pozuelo Monfort | 7908bff | 2014-01-30 13:49:39 +0100 | [diff] [blame] | 5089 | /* Update the surface’s layer. This brings it to the top of the stacking |
| 5090 | * order as appropriate. */ |
| 5091 | shell_surface_update_layer(shsurf); |
| 5092 | |
Philip Withnall | 83ffd9d | 2013-11-25 18:01:42 +0000 | [diff] [blame] | 5093 | if (shell->focus_animation_type != ANIMATION_NONE) { |
| 5094 | ws = get_current_workspace(shell); |
Louis-Francis Ratté-Boulianne | b482dbd | 2013-11-19 11:37:11 +0100 | [diff] [blame] | 5095 | 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] | 5096 | } |
Kristian Høgsberg | 7584062 | 2011-09-06 13:48:16 -0400 | [diff] [blame] | 5097 | } |
| 5098 | |
Alex Wu | 2185843 | 2012-04-01 20:13:08 +0800 | [diff] [blame] | 5099 | /* no-op func for checking black surface */ |
| 5100 | static void |
Jason Ekstrand | 918f2dd | 2013-12-02 21:01:53 -0600 | [diff] [blame] | 5101 | 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] | 5102 | { |
| 5103 | } |
| 5104 | |
Quentin Glidic | c0d79ce | 2013-01-29 14:16:13 +0100 | [diff] [blame] | 5105 | static bool |
Alex Wu | 2185843 | 2012-04-01 20:13:08 +0800 | [diff] [blame] | 5106 | is_black_surface (struct weston_surface *es, struct weston_surface **fs_surface) |
| 5107 | { |
| 5108 | if (es->configure == black_surface_configure) { |
| 5109 | if (fs_surface) |
Giulio Camuffo | 7fe01b1 | 2013-03-28 18:02:42 +0100 | [diff] [blame] | 5110 | *fs_surface = (struct weston_surface *)es->configure_private; |
Alex Wu | 2185843 | 2012-04-01 20:13:08 +0800 | [diff] [blame] | 5111 | return true; |
| 5112 | } |
| 5113 | return false; |
| 5114 | } |
| 5115 | |
Kristian Høgsberg | 7584062 | 2011-09-06 13:48:16 -0400 | [diff] [blame] | 5116 | static void |
Neil Roberts | a28c693 | 2013-10-03 16:43:04 +0100 | [diff] [blame] | 5117 | activate_binding(struct weston_seat *seat, |
| 5118 | struct desktop_shell *shell, |
| 5119 | struct weston_surface *focus) |
Kristian Høgsberg | e1a850e | 2011-12-19 15:18:05 -0500 | [diff] [blame] | 5120 | { |
Pekka Paalanen | 01388e2 | 2013-04-25 13:57:44 +0300 | [diff] [blame] | 5121 | struct weston_surface *main_surface; |
Kristian Høgsberg | e1a850e | 2011-12-19 15:18:05 -0500 | [diff] [blame] | 5122 | |
Alex Wu | 9c35e6b | 2012-03-05 14:13:13 +0800 | [diff] [blame] | 5123 | if (!focus) |
| 5124 | return; |
| 5125 | |
Pekka Paalanen | 01388e2 | 2013-04-25 13:57:44 +0300 | [diff] [blame] | 5126 | if (is_black_surface(focus, &main_surface)) |
| 5127 | focus = main_surface; |
Alex Wu | 4539b08 | 2012-03-01 12:57:46 +0800 | [diff] [blame] | 5128 | |
Pekka Paalanen | 01388e2 | 2013-04-25 13:57:44 +0300 | [diff] [blame] | 5129 | main_surface = weston_surface_get_main_surface(focus); |
| 5130 | if (get_shell_surface_type(main_surface) == SHELL_SURFACE_NONE) |
Kristian Høgsberg | 0636ac3 | 2012-06-27 10:22:15 -0400 | [diff] [blame] | 5131 | return; |
Kristian Høgsberg | 85b2e4b | 2012-06-21 16:49:42 -0400 | [diff] [blame] | 5132 | |
Emilio Pozuelo Monfort | 9e7c759 | 2014-01-30 14:01:10 +0100 | [diff] [blame] | 5133 | activate(shell, focus, seat, true); |
Neil Roberts | a28c693 | 2013-10-03 16:43:04 +0100 | [diff] [blame] | 5134 | } |
| 5135 | |
| 5136 | static void |
Derek Foreman | 8ae2db5 | 2015-07-15 13:00:36 -0500 | [diff] [blame] | 5137 | click_to_activate_binding(struct weston_pointer *pointer, uint32_t time, |
| 5138 | uint32_t button, void *data) |
Neil Roberts | a28c693 | 2013-10-03 16:43:04 +0100 | [diff] [blame] | 5139 | { |
Derek Foreman | 8ae2db5 | 2015-07-15 13:00:36 -0500 | [diff] [blame] | 5140 | if (pointer->grab != &pointer->default_grab) |
Neil Roberts | a28c693 | 2013-10-03 16:43:04 +0100 | [diff] [blame] | 5141 | return; |
Derek Foreman | 8ae2db5 | 2015-07-15 13:00:36 -0500 | [diff] [blame] | 5142 | if (pointer->focus == NULL) |
Kristian Høgsberg | 7c4f6cc | 2014-01-01 16:28:32 -0800 | [diff] [blame] | 5143 | return; |
Neil Roberts | a28c693 | 2013-10-03 16:43:04 +0100 | [diff] [blame] | 5144 | |
Derek Foreman | 8ae2db5 | 2015-07-15 13:00:36 -0500 | [diff] [blame] | 5145 | activate_binding(pointer->seat, data, pointer->focus->surface); |
Neil Roberts | a28c693 | 2013-10-03 16:43:04 +0100 | [diff] [blame] | 5146 | } |
| 5147 | |
| 5148 | static void |
Derek Foreman | 8ae2db5 | 2015-07-15 13:00:36 -0500 | [diff] [blame] | 5149 | touch_to_activate_binding(struct weston_touch *touch, uint32_t time, |
| 5150 | void *data) |
Neil Roberts | a28c693 | 2013-10-03 16:43:04 +0100 | [diff] [blame] | 5151 | { |
Derek Foreman | 8ae2db5 | 2015-07-15 13:00:36 -0500 | [diff] [blame] | 5152 | if (touch->grab != &touch->default_grab) |
Neil Roberts | a28c693 | 2013-10-03 16:43:04 +0100 | [diff] [blame] | 5153 | return; |
Derek Foreman | 8ae2db5 | 2015-07-15 13:00:36 -0500 | [diff] [blame] | 5154 | if (touch->focus == NULL) |
Kristian Høgsberg | 0ed6750 | 2014-01-02 23:00:11 -0800 | [diff] [blame] | 5155 | return; |
Neil Roberts | a28c693 | 2013-10-03 16:43:04 +0100 | [diff] [blame] | 5156 | |
Derek Foreman | 8ae2db5 | 2015-07-15 13:00:36 -0500 | [diff] [blame] | 5157 | activate_binding(touch->seat, data, touch->focus->surface); |
Kristian Høgsberg | e1a850e | 2011-12-19 15:18:05 -0500 | [diff] [blame] | 5158 | } |
| 5159 | |
| 5160 | static void |
Neil Roberts | b4a9170 | 2014-04-09 16:33:32 +0100 | [diff] [blame] | 5161 | unfocus_all_seats(struct desktop_shell *shell) |
| 5162 | { |
| 5163 | struct weston_seat *seat, *next; |
| 5164 | |
| 5165 | wl_list_for_each_safe(seat, next, &shell->compositor->seat_list, link) { |
| 5166 | if (seat->keyboard == NULL) |
| 5167 | continue; |
| 5168 | |
| 5169 | weston_keyboard_set_focus(seat->keyboard, NULL); |
| 5170 | } |
| 5171 | } |
| 5172 | |
| 5173 | static void |
Ander Conselvan de Oliveira | 19d10ef | 2013-02-21 18:35:20 +0200 | [diff] [blame] | 5174 | lock(struct desktop_shell *shell) |
Kristian Høgsberg | 02ec0a5 | 2011-04-23 13:04:11 -0400 | [diff] [blame] | 5175 | { |
Kristian Høgsberg | 4476aaf | 2012-06-25 14:03:13 -0400 | [diff] [blame] | 5176 | struct workspace *ws = get_current_workspace(shell); |
Pekka Paalanen | f0fc70d | 2011-11-15 13:34:54 +0200 | [diff] [blame] | 5177 | |
Tiago Vignatti | 8e53c7f | 2012-02-29 19:53:50 +0200 | [diff] [blame] | 5178 | if (shell->locked) { |
Ander Conselvan de Oliveira | 87524b6 | 2013-02-21 18:35:22 +0200 | [diff] [blame] | 5179 | weston_compositor_sleep(shell->compositor); |
Pekka Paalanen | f0fc70d | 2011-11-15 13:34:54 +0200 | [diff] [blame] | 5180 | return; |
Tiago Vignatti | 8e53c7f | 2012-02-29 19:53:50 +0200 | [diff] [blame] | 5181 | } |
Pekka Paalanen | 9ef3e01 | 2011-11-15 13:34:48 +0200 | [diff] [blame] | 5182 | |
| 5183 | shell->locked = true; |
Pekka Paalanen | f0fc70d | 2011-11-15 13:34:54 +0200 | [diff] [blame] | 5184 | |
Kristian Høgsberg | 3be2ce9 | 2012-02-29 12:42:35 -0500 | [diff] [blame] | 5185 | /* Hide all surfaces by removing the fullscreen, panel and |
| 5186 | * toplevel layers. This way nothing else can show or receive |
| 5187 | * input events while we are locked. */ |
Pekka Paalanen | f0fc70d | 2011-11-15 13:34:54 +0200 | [diff] [blame] | 5188 | |
Kristian Høgsberg | 3be2ce9 | 2012-02-29 12:42:35 -0500 | [diff] [blame] | 5189 | wl_list_remove(&shell->panel_layer.link); |
Kristian Høgsberg | 3be2ce9 | 2012-02-29 12:42:35 -0500 | [diff] [blame] | 5190 | wl_list_remove(&shell->fullscreen_layer.link); |
Philipp Brüschweiler | 711fda8 | 2012-08-09 18:50:43 +0200 | [diff] [blame] | 5191 | if (shell->showing_input_panels) |
| 5192 | wl_list_remove(&shell->input_panel_layer.link); |
Kristian Høgsberg | 4476aaf | 2012-06-25 14:03:13 -0400 | [diff] [blame] | 5193 | wl_list_remove(&ws->layer.link); |
Kristian Høgsberg | 3be2ce9 | 2012-02-29 12:42:35 -0500 | [diff] [blame] | 5194 | wl_list_insert(&shell->compositor->cursor_layer.link, |
| 5195 | &shell->lock_layer.link); |
Pekka Paalanen | f0fc70d | 2011-11-15 13:34:54 +0200 | [diff] [blame] | 5196 | |
Neil Roberts | b4a9170 | 2014-04-09 16:33:32 +0100 | [diff] [blame] | 5197 | /* Remove the keyboard focus on all seats. This will be |
| 5198 | * restored to the workspace's saved state via |
| 5199 | * restore_focus_state when the compositor is unlocked */ |
| 5200 | unfocus_all_seats(shell); |
| 5201 | |
Pekka Paalanen | f0fc70d | 2011-11-15 13:34:54 +0200 | [diff] [blame] | 5202 | /* TODO: disable bindings that should not work while locked. */ |
| 5203 | |
| 5204 | /* All this must be undone in resume_desktop(). */ |
Pekka Paalanen | 9ef3e01 | 2011-11-15 13:34:48 +0200 | [diff] [blame] | 5205 | } |
| 5206 | |
| 5207 | static void |
Ander Conselvan de Oliveira | 19d10ef | 2013-02-21 18:35:20 +0200 | [diff] [blame] | 5208 | unlock(struct desktop_shell *shell) |
Pekka Paalanen | 9ef3e01 | 2011-11-15 13:34:48 +0200 | [diff] [blame] | 5209 | { |
Pekka Paalanen | d81c216 | 2011-11-16 13:47:34 +0200 | [diff] [blame] | 5210 | if (!shell->locked || shell->lock_surface) { |
Ander Conselvan de Oliveira | 87524b6 | 2013-02-21 18:35:22 +0200 | [diff] [blame] | 5211 | shell_fade(shell, FADE_IN); |
Pekka Paalanen | 9ef3e01 | 2011-11-15 13:34:48 +0200 | [diff] [blame] | 5212 | return; |
| 5213 | } |
| 5214 | |
| 5215 | /* If desktop-shell client has gone away, unlock immediately. */ |
| 5216 | if (!shell->child.desktop_shell) { |
Pekka Paalanen | f0fc70d | 2011-11-15 13:34:54 +0200 | [diff] [blame] | 5217 | resume_desktop(shell); |
Pekka Paalanen | 9ef3e01 | 2011-11-15 13:34:48 +0200 | [diff] [blame] | 5218 | return; |
| 5219 | } |
| 5220 | |
| 5221 | if (shell->prepare_event_sent) |
| 5222 | return; |
| 5223 | |
Kristian Høgsberg | 0b5cd0c | 2012-03-04 21:57:37 -0500 | [diff] [blame] | 5224 | desktop_shell_send_prepare_lock_surface(shell->child.desktop_shell); |
Pekka Paalanen | 9ef3e01 | 2011-11-15 13:34:48 +0200 | [diff] [blame] | 5225 | shell->prepare_event_sent = true; |
Kristian Høgsberg | 02ec0a5 | 2011-04-23 13:04:11 -0400 | [diff] [blame] | 5226 | } |
| 5227 | |
| 5228 | static void |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 5229 | shell_fade_done(struct weston_view_animation *animation, void *data) |
Ander Conselvan de Oliveira | 19d10ef | 2013-02-21 18:35:20 +0200 | [diff] [blame] | 5230 | { |
| 5231 | struct desktop_shell *shell = data; |
| 5232 | |
| 5233 | shell->fade.animation = NULL; |
| 5234 | |
| 5235 | switch (shell->fade.type) { |
| 5236 | case FADE_IN: |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 5237 | weston_surface_destroy(shell->fade.view->surface); |
| 5238 | shell->fade.view = NULL; |
Ander Conselvan de Oliveira | 19d10ef | 2013-02-21 18:35:20 +0200 | [diff] [blame] | 5239 | break; |
| 5240 | case FADE_OUT: |
Ander Conselvan de Oliveira | 19d10ef | 2013-02-21 18:35:20 +0200 | [diff] [blame] | 5241 | lock(shell); |
| 5242 | break; |
Philip Withnall | 4a86a0a | 2013-11-25 18:01:32 +0000 | [diff] [blame] | 5243 | default: |
| 5244 | break; |
Ander Conselvan de Oliveira | 19d10ef | 2013-02-21 18:35:20 +0200 | [diff] [blame] | 5245 | } |
| 5246 | } |
| 5247 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 5248 | static struct weston_view * |
Pekka Paalanen | 79346ab | 2013-05-22 18:03:09 +0300 | [diff] [blame] | 5249 | shell_fade_create_surface(struct desktop_shell *shell) |
Ander Conselvan de Oliveira | 19d10ef | 2013-02-21 18:35:20 +0200 | [diff] [blame] | 5250 | { |
| 5251 | struct weston_compositor *compositor = shell->compositor; |
| 5252 | struct weston_surface *surface; |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 5253 | struct weston_view *view; |
Pekka Paalanen | 79346ab | 2013-05-22 18:03:09 +0300 | [diff] [blame] | 5254 | |
| 5255 | surface = weston_surface_create(compositor); |
| 5256 | if (!surface) |
| 5257 | return NULL; |
| 5258 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 5259 | view = weston_view_create(surface); |
| 5260 | if (!view) { |
| 5261 | weston_surface_destroy(surface); |
| 5262 | return NULL; |
| 5263 | } |
| 5264 | |
Jason Ekstrand | 5c11a33 | 2013-12-04 20:32:03 -0600 | [diff] [blame] | 5265 | weston_surface_set_size(surface, 8192, 8192); |
Jason Ekstrand | 918f2dd | 2013-12-02 21:01:53 -0600 | [diff] [blame] | 5266 | weston_view_set_position(view, 0, 0); |
Pekka Paalanen | 79346ab | 2013-05-22 18:03:09 +0300 | [diff] [blame] | 5267 | 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] | 5268 | weston_layer_entry_insert(&compositor->fade_layer.view_list, |
| 5269 | &view->layer_link); |
Pekka Paalanen | 79346ab | 2013-05-22 18:03:09 +0300 | [diff] [blame] | 5270 | pixman_region32_init(&surface->input); |
| 5271 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 5272 | return view; |
Pekka Paalanen | 79346ab | 2013-05-22 18:03:09 +0300 | [diff] [blame] | 5273 | } |
| 5274 | |
| 5275 | static void |
| 5276 | shell_fade(struct desktop_shell *shell, enum fade_type type) |
| 5277 | { |
Ander Conselvan de Oliveira | 19d10ef | 2013-02-21 18:35:20 +0200 | [diff] [blame] | 5278 | float tint; |
| 5279 | |
| 5280 | switch (type) { |
| 5281 | case FADE_IN: |
| 5282 | tint = 0.0; |
| 5283 | break; |
| 5284 | case FADE_OUT: |
| 5285 | tint = 1.0; |
| 5286 | break; |
| 5287 | default: |
| 5288 | weston_log("shell: invalid fade type\n"); |
| 5289 | return; |
| 5290 | } |
| 5291 | |
| 5292 | shell->fade.type = type; |
| 5293 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 5294 | if (shell->fade.view == NULL) { |
| 5295 | shell->fade.view = shell_fade_create_surface(shell); |
| 5296 | if (!shell->fade.view) |
Ander Conselvan de Oliveira | 19d10ef | 2013-02-21 18:35:20 +0200 | [diff] [blame] | 5297 | return; |
| 5298 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 5299 | shell->fade.view->alpha = 1.0 - tint; |
| 5300 | weston_view_update_transform(shell->fade.view); |
Ander Conselvan de Oliveira | 19d10ef | 2013-02-21 18:35:20 +0200 | [diff] [blame] | 5301 | } |
| 5302 | |
Kristian Høgsberg | 87d3b61 | 2014-01-19 21:48:10 -0800 | [diff] [blame] | 5303 | if (shell->fade.view->output == NULL) { |
| 5304 | /* If the black view gets a NULL output, we lost the |
| 5305 | * last output and we'll just cancel the fade. This |
| 5306 | * happens when you close the last window under the |
| 5307 | * X11 or Wayland backends. */ |
| 5308 | shell->locked = false; |
| 5309 | weston_surface_destroy(shell->fade.view->surface); |
| 5310 | shell->fade.view = NULL; |
| 5311 | } else if (shell->fade.animation) { |
Kristian Høgsberg | 5281fb1 | 2013-06-17 10:10:28 -0400 | [diff] [blame] | 5312 | weston_fade_update(shell->fade.animation, tint); |
Kristian Høgsberg | 87d3b61 | 2014-01-19 21:48:10 -0800 | [diff] [blame] | 5313 | } else { |
Ander Conselvan de Oliveira | 19d10ef | 2013-02-21 18:35:20 +0200 | [diff] [blame] | 5314 | shell->fade.animation = |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 5315 | weston_fade_run(shell->fade.view, |
Kristian Høgsberg | 5281fb1 | 2013-06-17 10:10:28 -0400 | [diff] [blame] | 5316 | 1.0 - tint, tint, 300.0, |
Ander Conselvan de Oliveira | 19d10ef | 2013-02-21 18:35:20 +0200 | [diff] [blame] | 5317 | shell_fade_done, shell); |
Kristian Høgsberg | 87d3b61 | 2014-01-19 21:48:10 -0800 | [diff] [blame] | 5318 | } |
Ander Conselvan de Oliveira | 19d10ef | 2013-02-21 18:35:20 +0200 | [diff] [blame] | 5319 | } |
| 5320 | |
| 5321 | static void |
Pekka Paalanen | 79346ab | 2013-05-22 18:03:09 +0300 | [diff] [blame] | 5322 | do_shell_fade_startup(void *data) |
| 5323 | { |
| 5324 | struct desktop_shell *shell = data; |
| 5325 | |
Pekka Paalanen | 23ed5f2 | 2015-05-26 11:54:52 +0300 | [diff] [blame] | 5326 | if (shell->startup_animation_type == ANIMATION_FADE) { |
Kristian Høgsberg | 724c8d9 | 2013-10-16 11:38:24 -0700 | [diff] [blame] | 5327 | shell_fade(shell, FADE_IN); |
Pekka Paalanen | 23ed5f2 | 2015-05-26 11:54:52 +0300 | [diff] [blame] | 5328 | } else { |
| 5329 | weston_log("desktop shell: " |
| 5330 | "unexpected fade-in animation type %d\n", |
| 5331 | shell->startup_animation_type); |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 5332 | weston_surface_destroy(shell->fade.view->surface); |
| 5333 | shell->fade.view = NULL; |
Kristian Høgsberg | 724c8d9 | 2013-10-16 11:38:24 -0700 | [diff] [blame] | 5334 | } |
Pekka Paalanen | 79346ab | 2013-05-22 18:03:09 +0300 | [diff] [blame] | 5335 | } |
| 5336 | |
| 5337 | static void |
| 5338 | shell_fade_startup(struct desktop_shell *shell) |
| 5339 | { |
| 5340 | struct wl_event_loop *loop; |
| 5341 | |
| 5342 | if (!shell->fade.startup_timer) |
| 5343 | return; |
| 5344 | |
| 5345 | wl_event_source_remove(shell->fade.startup_timer); |
| 5346 | shell->fade.startup_timer = NULL; |
| 5347 | |
| 5348 | loop = wl_display_get_event_loop(shell->compositor->wl_display); |
| 5349 | wl_event_loop_add_idle(loop, do_shell_fade_startup, shell); |
| 5350 | } |
| 5351 | |
| 5352 | static int |
| 5353 | fade_startup_timeout(void *data) |
| 5354 | { |
| 5355 | struct desktop_shell *shell = data; |
| 5356 | |
| 5357 | shell_fade_startup(shell); |
| 5358 | return 0; |
| 5359 | } |
| 5360 | |
| 5361 | static void |
| 5362 | shell_fade_init(struct desktop_shell *shell) |
| 5363 | { |
| 5364 | /* Make compositor output all black, and wait for the desktop-shell |
| 5365 | * client to signal it is ready, then fade in. The timer triggers a |
| 5366 | * fade-in, in case the desktop-shell client takes too long. |
| 5367 | */ |
| 5368 | |
| 5369 | struct wl_event_loop *loop; |
| 5370 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 5371 | if (shell->fade.view != NULL) { |
Pekka Paalanen | 79346ab | 2013-05-22 18:03:09 +0300 | [diff] [blame] | 5372 | weston_log("%s: warning: fade surface already exists\n", |
| 5373 | __func__); |
| 5374 | return; |
| 5375 | } |
| 5376 | |
Pekka Paalanen | 23ed5f2 | 2015-05-26 11:54:52 +0300 | [diff] [blame] | 5377 | if (shell->startup_animation_type == ANIMATION_NONE) |
| 5378 | return; |
| 5379 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 5380 | shell->fade.view = shell_fade_create_surface(shell); |
| 5381 | if (!shell->fade.view) |
Pekka Paalanen | 79346ab | 2013-05-22 18:03:09 +0300 | [diff] [blame] | 5382 | return; |
| 5383 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 5384 | weston_view_update_transform(shell->fade.view); |
| 5385 | weston_surface_damage(shell->fade.view->surface); |
Pekka Paalanen | 79346ab | 2013-05-22 18:03:09 +0300 | [diff] [blame] | 5386 | |
| 5387 | loop = wl_display_get_event_loop(shell->compositor->wl_display); |
| 5388 | shell->fade.startup_timer = |
| 5389 | wl_event_loop_add_timer(loop, fade_startup_timeout, shell); |
| 5390 | wl_event_source_timer_update(shell->fade.startup_timer, 15000); |
| 5391 | } |
| 5392 | |
| 5393 | static void |
Ander Conselvan de Oliveira | a457563 | 2013-02-21 18:35:23 +0200 | [diff] [blame] | 5394 | idle_handler(struct wl_listener *listener, void *data) |
Ander Conselvan de Oliveira | 19d10ef | 2013-02-21 18:35:20 +0200 | [diff] [blame] | 5395 | { |
| 5396 | struct desktop_shell *shell = |
Ander Conselvan de Oliveira | a457563 | 2013-02-21 18:35:23 +0200 | [diff] [blame] | 5397 | container_of(listener, struct desktop_shell, idle_listener); |
Kristian Høgsberg | 27d5fa8 | 2014-01-17 16:22:50 -0800 | [diff] [blame] | 5398 | struct weston_seat *seat; |
| 5399 | |
Jonny Lamb | 76cf1fe | 2014-08-20 11:27:10 +0200 | [diff] [blame] | 5400 | wl_list_for_each(seat, &shell->compositor->seat_list, link) { |
Kristian Høgsberg | 27d5fa8 | 2014-01-17 16:22:50 -0800 | [diff] [blame] | 5401 | if (seat->pointer) |
| 5402 | popup_grab_end(seat->pointer); |
Jonny Lamb | 76cf1fe | 2014-08-20 11:27:10 +0200 | [diff] [blame] | 5403 | if (seat->touch) |
| 5404 | touch_popup_grab_end(seat->touch); |
| 5405 | } |
Ander Conselvan de Oliveira | 19d10ef | 2013-02-21 18:35:20 +0200 | [diff] [blame] | 5406 | |
| 5407 | shell_fade(shell, FADE_OUT); |
| 5408 | /* lock() is called from shell_fade_done() */ |
| 5409 | } |
| 5410 | |
| 5411 | static void |
Ander Conselvan de Oliveira | a457563 | 2013-02-21 18:35:23 +0200 | [diff] [blame] | 5412 | wake_handler(struct wl_listener *listener, void *data) |
Ander Conselvan de Oliveira | 19d10ef | 2013-02-21 18:35:20 +0200 | [diff] [blame] | 5413 | { |
| 5414 | struct desktop_shell *shell = |
Ander Conselvan de Oliveira | a457563 | 2013-02-21 18:35:23 +0200 | [diff] [blame] | 5415 | container_of(listener, struct desktop_shell, wake_listener); |
Ander Conselvan de Oliveira | 19d10ef | 2013-02-21 18:35:20 +0200 | [diff] [blame] | 5416 | |
Ander Conselvan de Oliveira | 19d10ef | 2013-02-21 18:35:20 +0200 | [diff] [blame] | 5417 | unlock(shell); |
| 5418 | } |
| 5419 | |
| 5420 | static void |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 5421 | center_on_output(struct weston_view *view, struct weston_output *output) |
Pekka Paalanen | 77346a6 | 2011-11-30 16:26:35 +0200 | [diff] [blame] | 5422 | { |
Giulio Camuffo | b836664 | 2013-04-25 13:57:46 +0300 | [diff] [blame] | 5423 | int32_t surf_x, surf_y, width, height; |
Ander Conselvan de Oliveira | 012b4c7 | 2012-11-27 17:03:42 +0200 | [diff] [blame] | 5424 | float x, y; |
Pekka Paalanen | 77346a6 | 2011-11-30 16:26:35 +0200 | [diff] [blame] | 5425 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 5426 | surface_subsurfaces_boundingbox(view->surface, &surf_x, &surf_y, &width, &height); |
Giulio Camuffo | b836664 | 2013-04-25 13:57:46 +0300 | [diff] [blame] | 5427 | |
| 5428 | x = output->x + (output->width - width) / 2 - surf_x / 2; |
| 5429 | y = output->y + (output->height - height) / 2 - surf_y / 2; |
Ander Conselvan de Oliveira | 012b4c7 | 2012-11-27 17:03:42 +0200 | [diff] [blame] | 5430 | |
Jason Ekstrand | 918f2dd | 2013-12-02 21:01:53 -0600 | [diff] [blame] | 5431 | weston_view_set_position(view, x, y); |
Pekka Paalanen | 77346a6 | 2011-11-30 16:26:35 +0200 | [diff] [blame] | 5432 | } |
| 5433 | |
| 5434 | static void |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 5435 | weston_view_set_initial_position(struct weston_view *view, |
| 5436 | struct desktop_shell *shell) |
Rob Bradford | ac63e5b | 2012-08-13 14:07:52 +0100 | [diff] [blame] | 5437 | { |
| 5438 | struct weston_compositor *compositor = shell->compositor; |
| 5439 | int ix = 0, iy = 0; |
Jonny Lamb | d73c694 | 2014-08-20 15:53:20 +0200 | [diff] [blame] | 5440 | int32_t range_x, range_y; |
Derek Foreman | f814c5d | 2015-04-15 12:23:54 -0500 | [diff] [blame] | 5441 | int32_t x, y; |
Rob Bradford | ac63e5b | 2012-08-13 14:07:52 +0100 | [diff] [blame] | 5442 | struct weston_output *output, *target_output = NULL; |
| 5443 | struct weston_seat *seat; |
Jonny Lamb | d73c694 | 2014-08-20 15:53:20 +0200 | [diff] [blame] | 5444 | pixman_rectangle32_t area; |
Rob Bradford | ac63e5b | 2012-08-13 14:07:52 +0100 | [diff] [blame] | 5445 | |
| 5446 | /* As a heuristic place the new window on the same output as the |
| 5447 | * pointer. Falling back to the output containing 0, 0. |
| 5448 | * |
| 5449 | * TODO: Do something clever for touch too? |
| 5450 | */ |
| 5451 | wl_list_for_each(seat, &compositor->seat_list, link) { |
Kristian Høgsberg | 2bf8762 | 2013-05-07 23:17:41 -0400 | [diff] [blame] | 5452 | if (seat->pointer) { |
Kristian Høgsberg | e314875 | 2013-05-06 23:19:49 -0400 | [diff] [blame] | 5453 | ix = wl_fixed_to_int(seat->pointer->x); |
| 5454 | iy = wl_fixed_to_int(seat->pointer->y); |
Rob Bradford | ac63e5b | 2012-08-13 14:07:52 +0100 | [diff] [blame] | 5455 | break; |
| 5456 | } |
| 5457 | } |
| 5458 | |
| 5459 | wl_list_for_each(output, &compositor->output_list, link) { |
| 5460 | if (pixman_region32_contains_point(&output->region, ix, iy, NULL)) { |
| 5461 | target_output = output; |
| 5462 | break; |
| 5463 | } |
| 5464 | } |
| 5465 | |
| 5466 | if (!target_output) { |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 5467 | weston_view_set_position(view, 10 + random() % 400, |
| 5468 | 10 + random() % 400); |
Rob Bradford | ac63e5b | 2012-08-13 14:07:52 +0100 | [diff] [blame] | 5469 | return; |
| 5470 | } |
| 5471 | |
| 5472 | /* Valid range within output where the surface will still be onscreen. |
| 5473 | * If this is negative it means that the surface is bigger than |
| 5474 | * output. |
| 5475 | */ |
Jonny Lamb | d73c694 | 2014-08-20 15:53:20 +0200 | [diff] [blame] | 5476 | get_output_work_area(shell, target_output, &area); |
| 5477 | |
Derek Foreman | f814c5d | 2015-04-15 12:23:54 -0500 | [diff] [blame] | 5478 | x = area.x; |
| 5479 | y = area.y; |
Jonny Lamb | d73c694 | 2014-08-20 15:53:20 +0200 | [diff] [blame] | 5480 | range_x = area.width - view->surface->width; |
| 5481 | range_y = area.height - view->surface->height; |
Rob Bradford | ac63e5b | 2012-08-13 14:07:52 +0100 | [diff] [blame] | 5482 | |
Rob Bradford | 4cb88c7 | 2012-08-13 15:18:44 +0100 | [diff] [blame] | 5483 | if (range_x > 0) |
Derek Foreman | f814c5d | 2015-04-15 12:23:54 -0500 | [diff] [blame] | 5484 | x += random() % range_x; |
Rob Bradford | 4cb88c7 | 2012-08-13 15:18:44 +0100 | [diff] [blame] | 5485 | |
| 5486 | if (range_y > 0) |
Derek Foreman | f814c5d | 2015-04-15 12:23:54 -0500 | [diff] [blame] | 5487 | y += random() % range_y; |
Rob Bradford | ac63e5b | 2012-08-13 14:07:52 +0100 | [diff] [blame] | 5488 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 5489 | weston_view_set_position(view, x, y); |
Rob Bradford | ac63e5b | 2012-08-13 14:07:52 +0100 | [diff] [blame] | 5490 | } |
| 5491 | |
| 5492 | static void |
Jonny Lamb | d73c694 | 2014-08-20 15:53:20 +0200 | [diff] [blame] | 5493 | set_maximized_position(struct desktop_shell *shell, |
| 5494 | struct shell_surface *shsurf) |
| 5495 | { |
| 5496 | int32_t surf_x, surf_y; |
| 5497 | pixman_rectangle32_t area; |
Marek Chalupa | 8b771af | 2014-09-01 17:20:33 +0200 | [diff] [blame] | 5498 | pixman_box32_t *e; |
Jonny Lamb | d73c694 | 2014-08-20 15:53:20 +0200 | [diff] [blame] | 5499 | |
Jonny Lamb | d73c694 | 2014-08-20 15:53:20 +0200 | [diff] [blame] | 5500 | get_output_work_area(shell, shsurf->output, &area); |
Giulio Camuffo | 7a8d67d | 2015-01-09 20:10:45 +0200 | [diff] [blame] | 5501 | if (shsurf->has_set_geometry) { |
| 5502 | surf_x = shsurf->geometry.x; |
| 5503 | surf_y = shsurf->geometry.y; |
| 5504 | } else { |
| 5505 | surface_subsurfaces_boundingbox(shsurf->surface, |
| 5506 | &surf_x, &surf_y, NULL, NULL); |
| 5507 | } |
Marek Chalupa | 8b771af | 2014-09-01 17:20:33 +0200 | [diff] [blame] | 5508 | e = pixman_region32_extents(&shsurf->output->region); |
Jonny Lamb | d73c694 | 2014-08-20 15:53:20 +0200 | [diff] [blame] | 5509 | |
| 5510 | weston_view_set_position(shsurf->view, |
Marek Chalupa | 8b771af | 2014-09-01 17:20:33 +0200 | [diff] [blame] | 5511 | e->x1 + area.x - surf_x, |
| 5512 | e->y1 + area.y - surf_y); |
Jonny Lamb | d73c694 | 2014-08-20 15:53:20 +0200 | [diff] [blame] | 5513 | } |
| 5514 | |
| 5515 | static void |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 5516 | map(struct desktop_shell *shell, struct shell_surface *shsurf, |
Jason Ekstrand | 918f2dd | 2013-12-02 21:01:53 -0600 | [diff] [blame] | 5517 | int32_t sx, int32_t sy) |
Kristian Høgsberg | 02ec0a5 | 2011-04-23 13:04:11 -0400 | [diff] [blame] | 5518 | { |
Kristian Høgsberg | 8334bc1 | 2012-01-03 10:29:47 -0500 | [diff] [blame] | 5519 | struct weston_compositor *compositor = shell->compositor; |
Daniel Stone | b210468 | 2012-05-30 16:31:56 +0100 | [diff] [blame] | 5520 | struct weston_seat *seat; |
Pekka Paalanen | 57da4a8 | 2011-11-23 16:42:16 +0200 | [diff] [blame] | 5521 | |
Pekka Paalanen | 77346a6 | 2011-11-30 16:26:35 +0200 | [diff] [blame] | 5522 | /* initial positioning, see also configure() */ |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 5523 | switch (shsurf->type) { |
Rafael Antognolli | ed207b4 | 2013-12-03 15:35:43 -0200 | [diff] [blame] | 5524 | case SHELL_SURFACE_TOPLEVEL: |
Rafael Antognolli | 03b1659 | 2013-12-03 15:35:42 -0200 | [diff] [blame] | 5525 | if (shsurf->state.fullscreen) { |
| 5526 | center_on_output(shsurf->view, shsurf->fullscreen_output); |
| 5527 | shell_map_fullscreen(shsurf); |
| 5528 | } else if (shsurf->state.maximized) { |
Jonny Lamb | d73c694 | 2014-08-20 15:53:20 +0200 | [diff] [blame] | 5529 | set_maximized_position(shell, shsurf); |
Rafael Antognolli | ed207b4 | 2013-12-03 15:35:43 -0200 | [diff] [blame] | 5530 | } else if (!shsurf->state.relative) { |
Rafael Antognolli | 03b1659 | 2013-12-03 15:35:42 -0200 | [diff] [blame] | 5531 | weston_view_set_initial_position(shsurf->view, shell); |
| 5532 | } |
Juan Zhao | 96879df | 2012-02-07 08:45:41 +0800 | [diff] [blame] | 5533 | break; |
Tiago Vignatti | 0f99701 | 2012-02-10 16:17:23 +0200 | [diff] [blame] | 5534 | case SHELL_SURFACE_POPUP: |
Jasper St. Pierre | da6ecd0 | 2015-02-27 18:35:45 +0800 | [diff] [blame] | 5535 | if (shell_map_popup(shsurf) != 0) |
| 5536 | return; |
Rob Bradford | db99938 | 2012-12-06 12:07:48 +0000 | [diff] [blame] | 5537 | break; |
Ander Conselvan de Oliveira | e9e0515 | 2012-02-15 17:02:56 +0200 | [diff] [blame] | 5538 | case SHELL_SURFACE_NONE: |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 5539 | weston_view_set_position(shsurf->view, |
| 5540 | shsurf->view->geometry.x + sx, |
| 5541 | shsurf->view->geometry.y + sy); |
Tiago Vignatti | 0f99701 | 2012-02-10 16:17:23 +0200 | [diff] [blame] | 5542 | break; |
Philip Withnall | 0f640e2 | 2013-11-25 18:01:31 +0000 | [diff] [blame] | 5543 | case SHELL_SURFACE_XWAYLAND: |
Pekka Paalanen | 77346a6 | 2011-11-30 16:26:35 +0200 | [diff] [blame] | 5544 | default: |
| 5545 | ; |
| 5546 | } |
Kristian Høgsberg | 7584062 | 2011-09-06 13:48:16 -0400 | [diff] [blame] | 5547 | |
Philip Withnall | e1d75ae | 2013-11-25 18:01:41 +0000 | [diff] [blame] | 5548 | /* Surface stacking order, see also activate(). */ |
| 5549 | shell_surface_update_layer(shsurf); |
Pekka Paalanen | f0fc70d | 2011-11-15 13:34:54 +0200 | [diff] [blame] | 5550 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 5551 | if (shsurf->type != SHELL_SURFACE_NONE) { |
| 5552 | weston_view_update_transform(shsurf->view); |
Rafael Antognolli | 03b1659 | 2013-12-03 15:35:42 -0200 | [diff] [blame] | 5553 | if (shsurf->state.maximized) { |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 5554 | shsurf->surface->output = shsurf->output; |
| 5555 | shsurf->view->output = shsurf->output; |
| 5556 | } |
Ander Conselvan de Oliveira | de56c31 | 2012-03-05 15:39:23 +0200 | [diff] [blame] | 5557 | } |
Kristian Høgsberg | 2f88a40 | 2011-12-04 15:32:59 -0500 | [diff] [blame] | 5558 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 5559 | switch (shsurf->type) { |
Tiago Vignatti | fb2adba | 2013-06-12 15:43:21 -0300 | [diff] [blame] | 5560 | /* XXX: xwayland's using the same fields for transient type */ |
| 5561 | case SHELL_SURFACE_XWAYLAND: |
Tiago Vignatti | 99aeb1e | 2012-05-23 22:06:26 +0300 | [diff] [blame] | 5562 | if (shsurf->transient.flags == |
| 5563 | WL_SHELL_SURFACE_TRANSIENT_INACTIVE) |
| 5564 | break; |
| 5565 | case SHELL_SURFACE_TOPLEVEL: |
Rafael Antognolli | ed207b4 | 2013-12-03 15:35:43 -0200 | [diff] [blame] | 5566 | if (shsurf->state.relative && |
| 5567 | shsurf->transient.flags == WL_SHELL_SURFACE_TRANSIENT_INACTIVE) |
| 5568 | break; |
Rafael Antognolli | ba5d2d7 | 2013-12-04 17:49:55 -0200 | [diff] [blame] | 5569 | if (shell->locked) |
Rafael Antognolli | ed207b4 | 2013-12-03 15:35:43 -0200 | [diff] [blame] | 5570 | break; |
| 5571 | wl_list_for_each(seat, &compositor->seat_list, link) |
Emilio Pozuelo Monfort | 9e7c759 | 2014-01-30 14:01:10 +0100 | [diff] [blame] | 5572 | activate(shell, shsurf->surface, seat, true); |
Juan Zhao | 7bb92f0 | 2011-12-15 11:31:51 -0500 | [diff] [blame] | 5573 | break; |
Philip Withnall | 0f640e2 | 2013-11-25 18:01:31 +0000 | [diff] [blame] | 5574 | case SHELL_SURFACE_POPUP: |
| 5575 | case SHELL_SURFACE_NONE: |
Juan Zhao | 7bb92f0 | 2011-12-15 11:31:51 -0500 | [diff] [blame] | 5576 | default: |
| 5577 | break; |
| 5578 | } |
| 5579 | |
Rafael Antognolli | 03b1659 | 2013-12-03 15:35:42 -0200 | [diff] [blame] | 5580 | if (shsurf->type == SHELL_SURFACE_TOPLEVEL && |
| 5581 | !shsurf->state.maximized && !shsurf->state.fullscreen) |
Juan Zhao | e10d279 | 2012-04-25 19:09:52 +0800 | [diff] [blame] | 5582 | { |
| 5583 | switch (shell->win_animation_type) { |
| 5584 | case ANIMATION_FADE: |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 5585 | 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] | 5586 | break; |
| 5587 | case ANIMATION_ZOOM: |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 5588 | weston_zoom_run(shsurf->view, 0.5, 1.0, NULL, NULL); |
Juan Zhao | e10d279 | 2012-04-25 19:09:52 +0800 | [diff] [blame] | 5589 | break; |
Philip Withnall | 4a86a0a | 2013-11-25 18:01:32 +0000 | [diff] [blame] | 5590 | case ANIMATION_NONE: |
Juan Zhao | e10d279 | 2012-04-25 19:09:52 +0800 | [diff] [blame] | 5591 | default: |
| 5592 | break; |
| 5593 | } |
| 5594 | } |
Kristian Høgsberg | 32e24cc | 2011-11-09 12:07:35 -0500 | [diff] [blame] | 5595 | } |
| 5596 | |
| 5597 | static void |
Tiago Vignatti | be14326 | 2012-04-16 17:31:41 +0300 | [diff] [blame] | 5598 | configure(struct desktop_shell *shell, struct weston_surface *surface, |
Jason Ekstrand | 918f2dd | 2013-12-02 21:01:53 -0600 | [diff] [blame] | 5599 | float x, float y) |
Kristian Høgsberg | 32e24cc | 2011-11-09 12:07:35 -0500 | [diff] [blame] | 5600 | { |
Pekka Paalanen | 77346a6 | 2011-11-30 16:26:35 +0200 | [diff] [blame] | 5601 | struct shell_surface *shsurf; |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 5602 | struct weston_view *view; |
Kristian Høgsberg | 32e24cc | 2011-11-09 12:07:35 -0500 | [diff] [blame] | 5603 | |
Pekka Paalanen | 77346a6 | 2011-11-30 16:26:35 +0200 | [diff] [blame] | 5604 | shsurf = get_shell_surface(surface); |
Pekka Paalanen | 77346a6 | 2011-11-30 16:26:35 +0200 | [diff] [blame] | 5605 | |
U. Artie Eoff | cf5737a | 2014-01-17 10:08:25 -0800 | [diff] [blame] | 5606 | assert(shsurf); |
| 5607 | |
Rafael Antognolli | 03b1659 | 2013-12-03 15:35:42 -0200 | [diff] [blame] | 5608 | if (shsurf->state.fullscreen) |
Alex Wu | 4539b08 | 2012-03-01 12:57:46 +0800 | [diff] [blame] | 5609 | shell_configure_fullscreen(shsurf); |
Rafael Antognolli | 03b1659 | 2013-12-03 15:35:42 -0200 | [diff] [blame] | 5610 | else if (shsurf->state.maximized) { |
Jonny Lamb | d73c694 | 2014-08-20 15:53:20 +0200 | [diff] [blame] | 5611 | set_maximized_position(shell, shsurf); |
Rafael Antognolli | 03b1659 | 2013-12-03 15:35:42 -0200 | [diff] [blame] | 5612 | } else { |
Jason Ekstrand | 918f2dd | 2013-12-02 21:01:53 -0600 | [diff] [blame] | 5613 | weston_view_set_position(shsurf->view, x, y); |
Kristian Høgsberg | 7a5c979 | 2011-06-18 06:12:54 -0400 | [diff] [blame] | 5614 | } |
Kristian Høgsberg | 32e24cc | 2011-11-09 12:07:35 -0500 | [diff] [blame] | 5615 | |
Alex Wu | 4539b08 | 2012-03-01 12:57:46 +0800 | [diff] [blame] | 5616 | /* XXX: would a fullscreen surface need the same handling? */ |
Kristian Høgsberg | 6a8b553 | 2012-02-16 23:43:59 -0500 | [diff] [blame] | 5617 | if (surface->output) { |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 5618 | wl_list_for_each(view, &surface->views, surface_link) |
| 5619 | weston_view_update_transform(view); |
Pekka Paalanen | 77346a6 | 2011-11-30 16:26:35 +0200 | [diff] [blame] | 5620 | |
Rafael Antognolli | 03b1659 | 2013-12-03 15:35:42 -0200 | [diff] [blame] | 5621 | if (shsurf->state.maximized) |
Juan Zhao | 96879df | 2012-02-07 08:45:41 +0800 | [diff] [blame] | 5622 | surface->output = shsurf->output; |
Pekka Paalanen | 77346a6 | 2011-11-30 16:26:35 +0200 | [diff] [blame] | 5623 | } |
Kristian Høgsberg | 0793756 | 2011-04-12 17:25:42 -0400 | [diff] [blame] | 5624 | } |
| 5625 | |
Ander Conselvan de Oliveira | 093bfa3 | 2012-03-27 17:36:41 +0300 | [diff] [blame] | 5626 | static void |
Jason Ekstrand | 918f2dd | 2013-12-02 21:01:53 -0600 | [diff] [blame] | 5627 | 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] | 5628 | { |
Ander Conselvan de Oliveira | 7fb9f95 | 2012-03-27 17:36:42 +0300 | [diff] [blame] | 5629 | struct shell_surface *shsurf = get_shell_surface(es); |
U. Artie Eoff | cf5737a | 2014-01-17 10:08:25 -0800 | [diff] [blame] | 5630 | struct desktop_shell *shell; |
Tiago Vignatti | 70e5c9c | 2012-05-07 15:23:07 +0300 | [diff] [blame] | 5631 | int type_changed = 0; |
Ander Conselvan de Oliveira | 093bfa3 | 2012-03-27 17:36:41 +0300 | [diff] [blame] | 5632 | |
U. Artie Eoff | cf5737a | 2014-01-17 10:08:25 -0800 | [diff] [blame] | 5633 | assert(shsurf); |
| 5634 | |
| 5635 | shell = shsurf->shell; |
| 5636 | |
Kristian Høgsberg | 8eb0f4f | 2013-06-17 10:33:14 -0400 | [diff] [blame] | 5637 | if (!weston_surface_is_mapped(es) && |
| 5638 | !wl_list_empty(&shsurf->popup.grab_link)) { |
Giulio Camuffo | 5085a75 | 2013-03-25 21:42:45 +0100 | [diff] [blame] | 5639 | remove_popup_grab(shsurf); |
| 5640 | } |
| 5641 | |
Jason Ekstrand | 918f2dd | 2013-12-02 21:01:53 -0600 | [diff] [blame] | 5642 | if (es->width == 0) |
Giulio Camuffo | 184df50 | 2013-02-21 11:29:21 +0100 | [diff] [blame] | 5643 | return; |
| 5644 | |
Jasper St. Pierre | ccf48fb | 2014-05-02 10:21:38 -0400 | [diff] [blame] | 5645 | if (shsurf->has_next_geometry) { |
| 5646 | shsurf->geometry = shsurf->next_geometry; |
| 5647 | shsurf->has_next_geometry = false; |
| 5648 | shsurf->has_set_geometry = true; |
| 5649 | } else if (!shsurf->has_set_geometry) { |
| 5650 | surface_subsurfaces_boundingbox(shsurf->surface, |
| 5651 | &shsurf->geometry.x, |
| 5652 | &shsurf->geometry.y, |
| 5653 | &shsurf->geometry.width, |
| 5654 | &shsurf->geometry.height); |
Jasper St. Pierre | 851799e | 2014-05-02 10:14:07 -0400 | [diff] [blame] | 5655 | } |
| 5656 | |
Kristian Høgsberg | c8f8dd8 | 2013-12-05 23:20:33 -0800 | [diff] [blame] | 5657 | if (shsurf->state_changed) { |
Kristian Høgsberg | 7f366e7 | 2012-04-27 17:20:01 -0400 | [diff] [blame] | 5658 | set_surface_type(shsurf); |
Kristian Høgsberg | f7e23d5 | 2012-04-27 17:51:59 -0400 | [diff] [blame] | 5659 | type_changed = 1; |
| 5660 | } |
Kristian Høgsberg | 7f366e7 | 2012-04-27 17:20:01 -0400 | [diff] [blame] | 5661 | |
Ander Conselvan de Oliveira | 093bfa3 | 2012-03-27 17:36:41 +0300 | [diff] [blame] | 5662 | if (!weston_surface_is_mapped(es)) { |
Jason Ekstrand | 918f2dd | 2013-12-02 21:01:53 -0600 | [diff] [blame] | 5663 | map(shell, shsurf, sx, sy); |
Kristian Høgsberg | f7e23d5 | 2012-04-27 17:51:59 -0400 | [diff] [blame] | 5664 | } else if (type_changed || sx != 0 || sy != 0 || |
Jason Ekstrand | 918f2dd | 2013-12-02 21:01:53 -0600 | [diff] [blame] | 5665 | shsurf->last_width != es->width || |
| 5666 | shsurf->last_height != es->height) { |
John Kåre Alsaker | 490d02a | 2012-09-30 02:57:21 +0200 | [diff] [blame] | 5667 | float from_x, from_y; |
| 5668 | float to_x, to_y; |
Ander Conselvan de Oliveira | 093bfa3 | 2012-03-27 17:36:41 +0300 | [diff] [blame] | 5669 | |
Kristian Høgsberg | 44cd196 | 2014-02-05 21:36:04 -0800 | [diff] [blame] | 5670 | if (shsurf->resize_edges) { |
| 5671 | sx = 0; |
| 5672 | sy = 0; |
| 5673 | } |
| 5674 | |
| 5675 | if (shsurf->resize_edges & WL_SHELL_SURFACE_RESIZE_LEFT) |
| 5676 | sx = shsurf->last_width - es->width; |
| 5677 | if (shsurf->resize_edges & WL_SHELL_SURFACE_RESIZE_TOP) |
| 5678 | sy = shsurf->last_height - es->height; |
| 5679 | |
| 5680 | shsurf->last_width = es->width; |
| 5681 | shsurf->last_height = es->height; |
| 5682 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 5683 | weston_view_to_global_float(shsurf->view, 0, 0, &from_x, &from_y); |
| 5684 | 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] | 5685 | configure(shell, es, |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 5686 | shsurf->view->geometry.x + to_x - from_x, |
Jason Ekstrand | 918f2dd | 2013-12-02 21:01:53 -0600 | [diff] [blame] | 5687 | shsurf->view->geometry.y + to_y - from_y); |
Ander Conselvan de Oliveira | 093bfa3 | 2012-03-27 17:36:41 +0300 | [diff] [blame] | 5688 | } |
| 5689 | } |
| 5690 | |
Pekka Paalanen | 2e62e4a | 2014-08-28 11:41:26 +0300 | [diff] [blame] | 5691 | static bool |
| 5692 | check_desktop_shell_crash_too_early(struct desktop_shell *shell) |
| 5693 | { |
| 5694 | struct timespec now; |
| 5695 | |
| 5696 | if (clock_gettime(CLOCK_MONOTONIC, &now) < 0) |
| 5697 | return false; |
| 5698 | |
| 5699 | /* |
| 5700 | * If the shell helper client dies before the session has been |
| 5701 | * up for roughly 30 seconds, better just make Weston shut down, |
| 5702 | * because the user likely has no way to interact with the desktop |
| 5703 | * anyway. |
| 5704 | */ |
| 5705 | if (now.tv_sec - shell->startup_time.tv_sec < 30) { |
| 5706 | weston_log("Error: %s apparently cannot run at all.\n", |
| 5707 | shell->client); |
| 5708 | weston_log_continue(STAMP_SPACE "Quitting..."); |
| 5709 | wl_display_terminate(shell->compositor->wl_display); |
| 5710 | |
| 5711 | return true; |
| 5712 | } |
| 5713 | |
| 5714 | return false; |
| 5715 | } |
| 5716 | |
Tiago Vignatti | b7dbbd6 | 2012-09-25 17:57:01 +0300 | [diff] [blame] | 5717 | static void launch_desktop_shell_process(void *data); |
Pekka Paalanen | 4d733ee | 2012-01-17 14:36:27 +0200 | [diff] [blame] | 5718 | |
Kristian Høgsberg | 97d44aa | 2011-08-26 17:21:20 -0400 | [diff] [blame] | 5719 | static void |
Pekka Paalanen | 826dc14 | 2014-08-27 12:11:53 +0300 | [diff] [blame] | 5720 | respawn_desktop_shell_process(struct desktop_shell *shell) |
Pekka Paalanen | 6cd281a | 2011-11-03 14:11:32 +0200 | [diff] [blame] | 5721 | { |
Pekka Paalanen | 4d733ee | 2012-01-17 14:36:27 +0200 | [diff] [blame] | 5722 | uint32_t time; |
Pekka Paalanen | 4d733ee | 2012-01-17 14:36:27 +0200 | [diff] [blame] | 5723 | |
| 5724 | /* if desktop-shell dies more than 5 times in 30 seconds, give up */ |
| 5725 | time = weston_compositor_get_time(); |
Kristian Høgsberg | f03a616 | 2012-01-17 11:07:42 -0500 | [diff] [blame] | 5726 | if (time - shell->child.deathstamp > 30000) { |
Pekka Paalanen | 4d733ee | 2012-01-17 14:36:27 +0200 | [diff] [blame] | 5727 | shell->child.deathstamp = time; |
| 5728 | shell->child.deathcount = 0; |
| 5729 | } |
| 5730 | |
| 5731 | shell->child.deathcount++; |
| 5732 | if (shell->child.deathcount > 5) { |
Pekka Paalanen | 826dc14 | 2014-08-27 12:11:53 +0300 | [diff] [blame] | 5733 | weston_log("%s disconnected, giving up.\n", shell->client); |
Pekka Paalanen | 4d733ee | 2012-01-17 14:36:27 +0200 | [diff] [blame] | 5734 | return; |
| 5735 | } |
| 5736 | |
Pekka Paalanen | 826dc14 | 2014-08-27 12:11:53 +0300 | [diff] [blame] | 5737 | weston_log("%s disconnected, respawning...\n", shell->client); |
Pekka Paalanen | 4d733ee | 2012-01-17 14:36:27 +0200 | [diff] [blame] | 5738 | launch_desktop_shell_process(shell); |
Pekka Paalanen | 6cd281a | 2011-11-03 14:11:32 +0200 | [diff] [blame] | 5739 | } |
| 5740 | |
Tiago Vignatti | b7dbbd6 | 2012-09-25 17:57:01 +0300 | [diff] [blame] | 5741 | static void |
Ander Conselvan de Oliveira | 312ea4c | 2013-12-20 21:07:01 +0200 | [diff] [blame] | 5742 | desktop_shell_client_destroy(struct wl_listener *listener, void *data) |
| 5743 | { |
| 5744 | struct desktop_shell *shell; |
| 5745 | |
| 5746 | shell = container_of(listener, struct desktop_shell, |
| 5747 | child.client_destroy_listener); |
| 5748 | |
Pekka Paalanen | 826dc14 | 2014-08-27 12:11:53 +0300 | [diff] [blame] | 5749 | wl_list_remove(&shell->child.client_destroy_listener.link); |
Ander Conselvan de Oliveira | 312ea4c | 2013-12-20 21:07:01 +0200 | [diff] [blame] | 5750 | shell->child.client = NULL; |
Pekka Paalanen | 826dc14 | 2014-08-27 12:11:53 +0300 | [diff] [blame] | 5751 | /* |
| 5752 | * unbind_desktop_shell() will reset shell->child.desktop_shell |
| 5753 | * before the respawned process has a chance to create a new |
| 5754 | * desktop_shell object, because we are being called from the |
| 5755 | * wl_client destructor which destroys all wl_resources before |
| 5756 | * returning. |
| 5757 | */ |
| 5758 | |
Pekka Paalanen | 2e62e4a | 2014-08-28 11:41:26 +0300 | [diff] [blame] | 5759 | if (!check_desktop_shell_crash_too_early(shell)) |
| 5760 | respawn_desktop_shell_process(shell); |
| 5761 | |
Pekka Paalanen | 826dc14 | 2014-08-27 12:11:53 +0300 | [diff] [blame] | 5762 | shell_fade_startup(shell); |
Ander Conselvan de Oliveira | 312ea4c | 2013-12-20 21:07:01 +0200 | [diff] [blame] | 5763 | } |
| 5764 | |
| 5765 | static void |
Tiago Vignatti | b7dbbd6 | 2012-09-25 17:57:01 +0300 | [diff] [blame] | 5766 | launch_desktop_shell_process(void *data) |
Pekka Paalanen | 6cd281a | 2011-11-03 14:11:32 +0200 | [diff] [blame] | 5767 | { |
Tiago Vignatti | b7dbbd6 | 2012-09-25 17:57:01 +0300 | [diff] [blame] | 5768 | struct desktop_shell *shell = data; |
Pekka Paalanen | 6cd281a | 2011-11-03 14:11:32 +0200 | [diff] [blame] | 5769 | |
Pekka Paalanen | 826dc14 | 2014-08-27 12:11:53 +0300 | [diff] [blame] | 5770 | shell->child.client = weston_client_start(shell->compositor, |
| 5771 | shell->client); |
Pekka Paalanen | 409ef0a | 2011-12-02 15:30:21 +0200 | [diff] [blame] | 5772 | |
Arnaud Vrac | 4263119 | 2014-08-25 20:56:46 +0200 | [diff] [blame] | 5773 | if (!shell->child.client) { |
Emilio Pozuelo Monfort | 46ce798 | 2013-11-20 13:22:29 +0100 | [diff] [blame] | 5774 | weston_log("not able to start %s\n", shell->client); |
Arnaud Vrac | 4263119 | 2014-08-25 20:56:46 +0200 | [diff] [blame] | 5775 | return; |
| 5776 | } |
Ander Conselvan de Oliveira | 312ea4c | 2013-12-20 21:07:01 +0200 | [diff] [blame] | 5777 | |
| 5778 | shell->child.client_destroy_listener.notify = |
| 5779 | desktop_shell_client_destroy; |
| 5780 | wl_client_add_destroy_listener(shell->child.client, |
| 5781 | &shell->child.client_destroy_listener); |
Pekka Paalanen | 6cd281a | 2011-11-03 14:11:32 +0200 | [diff] [blame] | 5782 | } |
| 5783 | |
| 5784 | static void |
Kristian Høgsberg | 2bff94e | 2014-02-11 12:22:51 -0800 | [diff] [blame] | 5785 | handle_shell_client_destroy(struct wl_listener *listener, void *data) |
| 5786 | { |
| 5787 | struct shell_client *sc = |
| 5788 | container_of(listener, struct shell_client, destroy_listener); |
| 5789 | |
| 5790 | if (sc->ping_timer) |
| 5791 | wl_event_source_remove(sc->ping_timer); |
| 5792 | free(sc); |
| 5793 | } |
| 5794 | |
Kristian Høgsberg | dd62aba | 2014-02-12 09:56:19 -0800 | [diff] [blame] | 5795 | static struct shell_client * |
| 5796 | shell_client_create(struct wl_client *client, struct desktop_shell *shell, |
| 5797 | const struct wl_interface *interface, uint32_t id) |
Rafael Antognolli | e2a3455 | 2013-12-03 15:35:45 -0200 | [diff] [blame] | 5798 | { |
Kristian Høgsberg | 2bff94e | 2014-02-11 12:22:51 -0800 | [diff] [blame] | 5799 | struct shell_client *sc; |
Rafael Antognolli | e2a3455 | 2013-12-03 15:35:45 -0200 | [diff] [blame] | 5800 | |
Kristian Høgsberg | 2bff94e | 2014-02-11 12:22:51 -0800 | [diff] [blame] | 5801 | sc = zalloc(sizeof *sc); |
| 5802 | if (sc == NULL) { |
| 5803 | wl_client_post_no_memory(client); |
Kristian Høgsberg | dd62aba | 2014-02-12 09:56:19 -0800 | [diff] [blame] | 5804 | return NULL; |
Kristian Høgsberg | 2bff94e | 2014-02-11 12:22:51 -0800 | [diff] [blame] | 5805 | } |
Kristian Høgsberg | dd62aba | 2014-02-12 09:56:19 -0800 | [diff] [blame] | 5806 | |
| 5807 | sc->resource = wl_resource_create(client, interface, 1, id); |
Kristian Høgsberg | 2bff94e | 2014-02-11 12:22:51 -0800 | [diff] [blame] | 5808 | if (sc->resource == NULL) { |
| 5809 | free(sc); |
| 5810 | wl_client_post_no_memory(client); |
Kristian Høgsberg | dd62aba | 2014-02-12 09:56:19 -0800 | [diff] [blame] | 5811 | return NULL; |
Kristian Høgsberg | 2bff94e | 2014-02-11 12:22:51 -0800 | [diff] [blame] | 5812 | } |
| 5813 | |
| 5814 | sc->client = client; |
| 5815 | sc->shell = shell; |
| 5816 | sc->destroy_listener.notify = handle_shell_client_destroy; |
| 5817 | wl_client_add_destroy_listener(client, &sc->destroy_listener); |
Jonas Ådahl | 49d77d2 | 2015-03-18 16:20:51 +0800 | [diff] [blame] | 5818 | wl_list_init(&sc->surface_list); |
Kristian Høgsberg | 2bff94e | 2014-02-11 12:22:51 -0800 | [diff] [blame] | 5819 | |
Kristian Høgsberg | dd62aba | 2014-02-12 09:56:19 -0800 | [diff] [blame] | 5820 | return sc; |
| 5821 | } |
| 5822 | |
| 5823 | static void |
| 5824 | bind_shell(struct wl_client *client, void *data, uint32_t version, uint32_t id) |
| 5825 | { |
| 5826 | struct desktop_shell *shell = data; |
| 5827 | struct shell_client *sc; |
| 5828 | |
| 5829 | sc = shell_client_create(client, shell, &wl_shell_interface, id); |
| 5830 | if (sc) |
| 5831 | wl_resource_set_implementation(sc->resource, |
| 5832 | &shell_implementation, |
Jason Ekstrand | 9e9512f | 2014-04-16 21:12:10 -0500 | [diff] [blame] | 5833 | sc, NULL); |
Kristian Høgsberg | dd62aba | 2014-02-12 09:56:19 -0800 | [diff] [blame] | 5834 | } |
| 5835 | |
| 5836 | static void |
| 5837 | bind_xdg_shell(struct wl_client *client, void *data, uint32_t version, uint32_t id) |
| 5838 | { |
| 5839 | struct desktop_shell *shell = data; |
| 5840 | struct shell_client *sc; |
| 5841 | |
| 5842 | sc = shell_client_create(client, shell, &xdg_shell_interface, id); |
| 5843 | if (sc) |
| 5844 | wl_resource_set_dispatcher(sc->resource, |
| 5845 | xdg_shell_unversioned_dispatch, |
| 5846 | NULL, sc, NULL); |
Rafael Antognolli | e2a3455 | 2013-12-03 15:35:45 -0200 | [diff] [blame] | 5847 | } |
| 5848 | |
| 5849 | static void |
Pekka Paalanen | 9ef3e01 | 2011-11-15 13:34:48 +0200 | [diff] [blame] | 5850 | unbind_desktop_shell(struct wl_resource *resource) |
| 5851 | { |
Jason Ekstrand | 651f00e | 2013-06-14 10:07:54 -0500 | [diff] [blame] | 5852 | struct desktop_shell *shell = wl_resource_get_user_data(resource); |
Kristian Høgsberg | 1ec0c31 | 2011-11-15 16:39:55 -0500 | [diff] [blame] | 5853 | |
| 5854 | if (shell->locked) |
| 5855 | resume_desktop(shell); |
| 5856 | |
Pekka Paalanen | 9ef3e01 | 2011-11-15 13:34:48 +0200 | [diff] [blame] | 5857 | shell->child.desktop_shell = NULL; |
| 5858 | shell->prepare_event_sent = false; |
Pekka Paalanen | 9ef3e01 | 2011-11-15 13:34:48 +0200 | [diff] [blame] | 5859 | } |
| 5860 | |
| 5861 | static void |
Kristian Høgsberg | 7584062 | 2011-09-06 13:48:16 -0400 | [diff] [blame] | 5862 | bind_desktop_shell(struct wl_client *client, |
| 5863 | void *data, uint32_t version, uint32_t id) |
| 5864 | { |
Tiago Vignatti | be14326 | 2012-04-16 17:31:41 +0300 | [diff] [blame] | 5865 | struct desktop_shell *shell = data; |
Pekka Paalanen | bbe6052 | 2011-11-03 14:11:33 +0200 | [diff] [blame] | 5866 | struct wl_resource *resource; |
Kristian Høgsberg | 7584062 | 2011-09-06 13:48:16 -0400 | [diff] [blame] | 5867 | |
Jason Ekstrand | a85118c | 2013-06-27 20:17:02 -0500 | [diff] [blame] | 5868 | resource = wl_resource_create(client, &desktop_shell_interface, |
Jonny Lamb | 765760d | 2014-08-20 15:53:19 +0200 | [diff] [blame] | 5869 | MIN(version, 3), id); |
Pekka Paalanen | bbe6052 | 2011-11-03 14:11:33 +0200 | [diff] [blame] | 5870 | |
Pekka Paalanen | 9ef3e01 | 2011-11-15 13:34:48 +0200 | [diff] [blame] | 5871 | if (client == shell->child.client) { |
Jason Ekstrand | a85118c | 2013-06-27 20:17:02 -0500 | [diff] [blame] | 5872 | wl_resource_set_implementation(resource, |
| 5873 | &desktop_shell_implementation, |
| 5874 | shell, unbind_desktop_shell); |
Pekka Paalanen | 9ef3e01 | 2011-11-15 13:34:48 +0200 | [diff] [blame] | 5875 | shell->child.desktop_shell = resource; |
Pekka Paalanen | 79346ab | 2013-05-22 18:03:09 +0300 | [diff] [blame] | 5876 | |
| 5877 | if (version < 2) |
| 5878 | shell_fade_startup(shell); |
| 5879 | |
Pekka Paalanen | bbe6052 | 2011-11-03 14:11:33 +0200 | [diff] [blame] | 5880 | return; |
Pekka Paalanen | 9ef3e01 | 2011-11-15 13:34:48 +0200 | [diff] [blame] | 5881 | } |
Pekka Paalanen | bbe6052 | 2011-11-03 14:11:33 +0200 | [diff] [blame] | 5882 | |
| 5883 | wl_resource_post_error(resource, WL_DISPLAY_ERROR_INVALID_OBJECT, |
| 5884 | "permission to bind desktop_shell denied"); |
Kristian Høgsberg | 7584062 | 2011-09-06 13:48:16 -0400 | [diff] [blame] | 5885 | } |
| 5886 | |
Kristian Høgsberg | 0704539 | 2012-02-19 18:52:44 -0500 | [diff] [blame] | 5887 | struct switcher { |
Tiago Vignatti | be14326 | 2012-04-16 17:31:41 +0300 | [diff] [blame] | 5888 | struct desktop_shell *shell; |
Kristian Høgsberg | 0704539 | 2012-02-19 18:52:44 -0500 | [diff] [blame] | 5889 | struct weston_surface *current; |
| 5890 | struct wl_listener listener; |
Kristian Høgsberg | 29139d4 | 2013-04-18 15:25:39 -0400 | [diff] [blame] | 5891 | struct weston_keyboard_grab grab; |
Manuel Bachmann | c1ae2e8 | 2014-02-26 15:53:11 +0100 | [diff] [blame] | 5892 | struct wl_array minimized_array; |
Kristian Høgsberg | 0704539 | 2012-02-19 18:52:44 -0500 | [diff] [blame] | 5893 | }; |
| 5894 | |
| 5895 | static void |
| 5896 | switcher_next(struct switcher *switcher) |
| 5897 | { |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 5898 | struct weston_view *view; |
Kristian Høgsberg | 0704539 | 2012-02-19 18:52:44 -0500 | [diff] [blame] | 5899 | struct weston_surface *first = NULL, *prev = NULL, *next = NULL; |
Kristian Høgsberg | 32e5686 | 2012-04-02 22:18:58 -0400 | [diff] [blame] | 5900 | struct shell_surface *shsurf; |
Kristian Høgsberg | b0d8e77 | 2012-06-18 16:34:58 -0400 | [diff] [blame] | 5901 | struct workspace *ws = get_current_workspace(switcher->shell); |
Kristian Høgsberg | 0704539 | 2012-02-19 18:52:44 -0500 | [diff] [blame] | 5902 | |
Manuel Bachmann | c1ae2e8 | 2014-02-26 15:53:11 +0100 | [diff] [blame] | 5903 | /* temporary re-display minimized surfaces */ |
| 5904 | struct weston_view *tmp; |
| 5905 | struct weston_view **minimized; |
Giulio Camuffo | 412e6a5 | 2014-07-09 22:12:56 +0300 | [diff] [blame] | 5906 | wl_list_for_each_safe(view, tmp, &switcher->shell->minimized_layer.view_list.link, layer_link.link) { |
| 5907 | weston_layer_entry_remove(&view->layer_link); |
| 5908 | weston_layer_entry_insert(&ws->layer.view_list, &view->layer_link); |
Manuel Bachmann | c1ae2e8 | 2014-02-26 15:53:11 +0100 | [diff] [blame] | 5909 | minimized = wl_array_add(&switcher->minimized_array, sizeof *minimized); |
| 5910 | *minimized = view; |
| 5911 | } |
| 5912 | |
Giulio Camuffo | 412e6a5 | 2014-07-09 22:12:56 +0300 | [diff] [blame] | 5913 | 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] | 5914 | shsurf = get_shell_surface(view->surface); |
Rafael Antognolli | 5031cbe | 2013-12-05 19:01:21 -0200 | [diff] [blame] | 5915 | if (shsurf && |
| 5916 | shsurf->type == SHELL_SURFACE_TOPLEVEL && |
| 5917 | shsurf->parent == NULL) { |
Kristian Høgsberg | 0704539 | 2012-02-19 18:52:44 -0500 | [diff] [blame] | 5918 | if (first == NULL) |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 5919 | first = view->surface; |
Kristian Høgsberg | 0704539 | 2012-02-19 18:52:44 -0500 | [diff] [blame] | 5920 | if (prev == switcher->current) |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 5921 | next = view->surface; |
| 5922 | prev = view->surface; |
| 5923 | view->alpha = 0.25; |
| 5924 | weston_view_geometry_dirty(view); |
| 5925 | weston_surface_damage(view->surface); |
Kristian Høgsberg | 0704539 | 2012-02-19 18:52:44 -0500 | [diff] [blame] | 5926 | } |
Alex Wu | 1659daa | 2012-04-01 20:13:09 +0800 | [diff] [blame] | 5927 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 5928 | if (is_black_surface(view->surface, NULL)) { |
| 5929 | view->alpha = 0.25; |
| 5930 | weston_view_geometry_dirty(view); |
| 5931 | weston_surface_damage(view->surface); |
Alex Wu | 1659daa | 2012-04-01 20:13:09 +0800 | [diff] [blame] | 5932 | } |
Kristian Høgsberg | 0704539 | 2012-02-19 18:52:44 -0500 | [diff] [blame] | 5933 | } |
| 5934 | |
| 5935 | if (next == NULL) |
| 5936 | next = first; |
| 5937 | |
Alex Wu | 07b2606 | 2012-03-12 16:06:01 +0800 | [diff] [blame] | 5938 | if (next == NULL) |
| 5939 | return; |
| 5940 | |
Kristian Høgsberg | 0704539 | 2012-02-19 18:52:44 -0500 | [diff] [blame] | 5941 | wl_list_remove(&switcher->listener.link); |
Jason Ekstrand | 26ed73c | 2013-06-06 22:34:41 -0500 | [diff] [blame] | 5942 | wl_signal_add(&next->destroy_signal, &switcher->listener); |
Kristian Høgsberg | 0704539 | 2012-02-19 18:52:44 -0500 | [diff] [blame] | 5943 | |
| 5944 | switcher->current = next; |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 5945 | wl_list_for_each(view, &next->views, surface_link) |
| 5946 | view->alpha = 1.0; |
Alex Wu | 1659daa | 2012-04-01 20:13:09 +0800 | [diff] [blame] | 5947 | |
Kristian Høgsberg | 32e5686 | 2012-04-02 22:18:58 -0400 | [diff] [blame] | 5948 | shsurf = get_shell_surface(switcher->current); |
Rafael Antognolli | 03b1659 | 2013-12-03 15:35:42 -0200 | [diff] [blame] | 5949 | if (shsurf && shsurf->state.fullscreen) |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 5950 | shsurf->fullscreen.black_view->alpha = 1.0; |
Kristian Høgsberg | 0704539 | 2012-02-19 18:52:44 -0500 | [diff] [blame] | 5951 | } |
| 5952 | |
| 5953 | static void |
Kristian Høgsberg | 27e3052 | 2012-04-11 23:18:23 -0400 | [diff] [blame] | 5954 | switcher_handle_surface_destroy(struct wl_listener *listener, void *data) |
Kristian Høgsberg | 0704539 | 2012-02-19 18:52:44 -0500 | [diff] [blame] | 5955 | { |
| 5956 | struct switcher *switcher = |
| 5957 | container_of(listener, struct switcher, listener); |
| 5958 | |
| 5959 | switcher_next(switcher); |
| 5960 | } |
| 5961 | |
| 5962 | static void |
Daniel Stone | 351eb61 | 2012-05-31 15:27:47 -0400 | [diff] [blame] | 5963 | switcher_destroy(struct switcher *switcher) |
Kristian Høgsberg | 0704539 | 2012-02-19 18:52:44 -0500 | [diff] [blame] | 5964 | { |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 5965 | struct weston_view *view; |
Kristian Høgsberg | 29139d4 | 2013-04-18 15:25:39 -0400 | [diff] [blame] | 5966 | struct weston_keyboard *keyboard = switcher->grab.keyboard; |
Kristian Høgsberg | b0d8e77 | 2012-06-18 16:34:58 -0400 | [diff] [blame] | 5967 | struct workspace *ws = get_current_workspace(switcher->shell); |
Kristian Høgsberg | 0704539 | 2012-02-19 18:52:44 -0500 | [diff] [blame] | 5968 | |
Giulio Camuffo | 412e6a5 | 2014-07-09 22:12:56 +0300 | [diff] [blame] | 5969 | 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] | 5970 | if (is_focus_view(view)) |
| 5971 | continue; |
| 5972 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 5973 | view->alpha = 1.0; |
| 5974 | weston_surface_damage(view->surface); |
Kristian Høgsberg | 0704539 | 2012-02-19 18:52:44 -0500 | [diff] [blame] | 5975 | } |
| 5976 | |
Alex Wu | 07b2606 | 2012-03-12 16:06:01 +0800 | [diff] [blame] | 5977 | if (switcher->current) |
Daniel Stone | 37816df | 2012-05-16 18:45:18 +0100 | [diff] [blame] | 5978 | activate(switcher->shell, switcher->current, |
Derek Foreman | 8aeeac8 | 2015-01-30 13:24:36 -0600 | [diff] [blame] | 5979 | keyboard->seat, true); |
Kristian Høgsberg | 0704539 | 2012-02-19 18:52:44 -0500 | [diff] [blame] | 5980 | wl_list_remove(&switcher->listener.link); |
Kristian Høgsberg | 29139d4 | 2013-04-18 15:25:39 -0400 | [diff] [blame] | 5981 | weston_keyboard_end_grab(keyboard); |
| 5982 | if (keyboard->input_method_resource) |
| 5983 | keyboard->grab = &keyboard->input_method_grab; |
Manuel Bachmann | c1ae2e8 | 2014-02-26 15:53:11 +0100 | [diff] [blame] | 5984 | |
| 5985 | /* re-hide surfaces that were temporary shown during the switch */ |
| 5986 | struct weston_view **minimized; |
| 5987 | wl_array_for_each(minimized, &switcher->minimized_array) { |
| 5988 | /* with the exception of the current selected */ |
| 5989 | if ((*minimized)->surface != switcher->current) { |
Giulio Camuffo | 412e6a5 | 2014-07-09 22:12:56 +0300 | [diff] [blame] | 5990 | weston_layer_entry_remove(&(*minimized)->layer_link); |
| 5991 | 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] | 5992 | weston_view_damage_below(*minimized); |
| 5993 | } |
| 5994 | } |
| 5995 | wl_array_release(&switcher->minimized_array); |
| 5996 | |
Kristian Høgsberg | 0704539 | 2012-02-19 18:52:44 -0500 | [diff] [blame] | 5997 | free(switcher); |
| 5998 | } |
| 5999 | |
| 6000 | static void |
Kristian Høgsberg | 29139d4 | 2013-04-18 15:25:39 -0400 | [diff] [blame] | 6001 | switcher_key(struct weston_keyboard_grab *grab, |
Daniel Stone | c9785ea | 2012-05-30 16:31:52 +0100 | [diff] [blame] | 6002 | uint32_t time, uint32_t key, uint32_t state_w) |
Kristian Høgsberg | 0704539 | 2012-02-19 18:52:44 -0500 | [diff] [blame] | 6003 | { |
| 6004 | struct switcher *switcher = container_of(grab, struct switcher, grab); |
Daniel Stone | c9785ea | 2012-05-30 16:31:52 +0100 | [diff] [blame] | 6005 | enum wl_keyboard_key_state state = state_w; |
Daniel Stone | 351eb61 | 2012-05-31 15:27:47 -0400 | [diff] [blame] | 6006 | |
Daniel Stone | c9785ea | 2012-05-30 16:31:52 +0100 | [diff] [blame] | 6007 | if (key == KEY_TAB && state == WL_KEYBOARD_KEY_STATE_PRESSED) |
Daniel Stone | 351eb61 | 2012-05-31 15:27:47 -0400 | [diff] [blame] | 6008 | switcher_next(switcher); |
| 6009 | } |
| 6010 | |
| 6011 | static void |
Kristian Høgsberg | 29139d4 | 2013-04-18 15:25:39 -0400 | [diff] [blame] | 6012 | switcher_modifier(struct weston_keyboard_grab *grab, uint32_t serial, |
Daniel Stone | 351eb61 | 2012-05-31 15:27:47 -0400 | [diff] [blame] | 6013 | uint32_t mods_depressed, uint32_t mods_latched, |
| 6014 | uint32_t mods_locked, uint32_t group) |
| 6015 | { |
| 6016 | struct switcher *switcher = container_of(grab, struct switcher, grab); |
Derek Foreman | 8aeeac8 | 2015-01-30 13:24:36 -0600 | [diff] [blame] | 6017 | struct weston_seat *seat = grab->keyboard->seat; |
Kristian Høgsberg | 0704539 | 2012-02-19 18:52:44 -0500 | [diff] [blame] | 6018 | |
Daniel Stone | 351eb61 | 2012-05-31 15:27:47 -0400 | [diff] [blame] | 6019 | if ((seat->modifier_state & switcher->shell->binding_modifier) == 0) |
| 6020 | switcher_destroy(switcher); |
Kristian Høgsberg | b71302e | 2012-05-10 12:28:35 -0400 | [diff] [blame] | 6021 | } |
Kristian Høgsberg | 0704539 | 2012-02-19 18:52:44 -0500 | [diff] [blame] | 6022 | |
Jonas Ådahl | 1ea343e | 2013-10-25 23:18:05 +0200 | [diff] [blame] | 6023 | static void |
| 6024 | switcher_cancel(struct weston_keyboard_grab *grab) |
| 6025 | { |
| 6026 | struct switcher *switcher = container_of(grab, struct switcher, grab); |
| 6027 | |
| 6028 | switcher_destroy(switcher); |
| 6029 | } |
| 6030 | |
Kristian Høgsberg | 29139d4 | 2013-04-18 15:25:39 -0400 | [diff] [blame] | 6031 | static const struct weston_keyboard_grab_interface switcher_grab = { |
Daniel Stone | 351eb61 | 2012-05-31 15:27:47 -0400 | [diff] [blame] | 6032 | switcher_key, |
| 6033 | switcher_modifier, |
Jonas Ådahl | 1ea343e | 2013-10-25 23:18:05 +0200 | [diff] [blame] | 6034 | switcher_cancel, |
Kristian Høgsberg | 0704539 | 2012-02-19 18:52:44 -0500 | [diff] [blame] | 6035 | }; |
| 6036 | |
| 6037 | static void |
Derek Foreman | 8ae2db5 | 2015-07-15 13:00:36 -0500 | [diff] [blame] | 6038 | switcher_binding(struct weston_keyboard *keyboard, uint32_t time, |
| 6039 | uint32_t key, void *data) |
Kristian Høgsberg | 0704539 | 2012-02-19 18:52:44 -0500 | [diff] [blame] | 6040 | { |
Tiago Vignatti | be14326 | 2012-04-16 17:31:41 +0300 | [diff] [blame] | 6041 | struct desktop_shell *shell = data; |
Kristian Høgsberg | 0704539 | 2012-02-19 18:52:44 -0500 | [diff] [blame] | 6042 | struct switcher *switcher; |
| 6043 | |
| 6044 | switcher = malloc(sizeof *switcher); |
Kristian Høgsberg | 02e79dc | 2012-04-12 09:55:26 -0400 | [diff] [blame] | 6045 | switcher->shell = shell; |
Kristian Høgsberg | 0704539 | 2012-02-19 18:52:44 -0500 | [diff] [blame] | 6046 | switcher->current = NULL; |
Kristian Høgsberg | 27e3052 | 2012-04-11 23:18:23 -0400 | [diff] [blame] | 6047 | switcher->listener.notify = switcher_handle_surface_destroy; |
Kristian Høgsberg | 0704539 | 2012-02-19 18:52:44 -0500 | [diff] [blame] | 6048 | wl_list_init(&switcher->listener.link); |
Manuel Bachmann | c1ae2e8 | 2014-02-26 15:53:11 +0100 | [diff] [blame] | 6049 | wl_array_init(&switcher->minimized_array); |
Kristian Høgsberg | 0704539 | 2012-02-19 18:52:44 -0500 | [diff] [blame] | 6050 | |
Alexander Larsson | f82b6ca | 2013-05-28 16:23:39 +0200 | [diff] [blame] | 6051 | restore_all_output_modes(shell->compositor); |
Mario Kleiner | 9f4d655 | 2015-06-21 21:25:08 +0200 | [diff] [blame] | 6052 | lower_fullscreen_layer(switcher->shell, NULL); |
Kristian Høgsberg | 0704539 | 2012-02-19 18:52:44 -0500 | [diff] [blame] | 6053 | switcher->grab.interface = &switcher_grab; |
Derek Foreman | 8ae2db5 | 2015-07-15 13:00:36 -0500 | [diff] [blame] | 6054 | weston_keyboard_start_grab(keyboard, &switcher->grab); |
| 6055 | weston_keyboard_set_focus(keyboard, NULL); |
Kristian Høgsberg | 0704539 | 2012-02-19 18:52:44 -0500 | [diff] [blame] | 6056 | switcher_next(switcher); |
| 6057 | } |
| 6058 | |
Pekka Paalanen | 3c64723 | 2011-12-22 13:43:43 +0200 | [diff] [blame] | 6059 | static void |
Derek Foreman | 8ae2db5 | 2015-07-15 13:00:36 -0500 | [diff] [blame] | 6060 | backlight_binding(struct weston_keyboard *keyboard, uint32_t time, |
| 6061 | uint32_t key, void *data) |
Tiago Vignatti | 8e53c7f | 2012-02-29 19:53:50 +0200 | [diff] [blame] | 6062 | { |
| 6063 | struct weston_compositor *compositor = data; |
| 6064 | struct weston_output *output; |
Tiago Vignatti | 5ab91ad | 2012-03-12 19:40:09 -0300 | [diff] [blame] | 6065 | long backlight_new = 0; |
Tiago Vignatti | 8e53c7f | 2012-02-29 19:53:50 +0200 | [diff] [blame] | 6066 | |
| 6067 | /* TODO: we're limiting to simple use cases, where we assume just |
| 6068 | * control on the primary display. We'd have to extend later if we |
| 6069 | * ever get support for setting backlights on random desktop LCD |
| 6070 | * panels though */ |
| 6071 | output = get_default_output(compositor); |
| 6072 | if (!output) |
| 6073 | return; |
| 6074 | |
| 6075 | if (!output->set_backlight) |
| 6076 | return; |
| 6077 | |
Tiago Vignatti | 5ab91ad | 2012-03-12 19:40:09 -0300 | [diff] [blame] | 6078 | if (key == KEY_F9 || key == KEY_BRIGHTNESSDOWN) |
| 6079 | backlight_new = output->backlight_current - 25; |
| 6080 | else if (key == KEY_F10 || key == KEY_BRIGHTNESSUP) |
| 6081 | backlight_new = output->backlight_current + 25; |
Tiago Vignatti | 8e53c7f | 2012-02-29 19:53:50 +0200 | [diff] [blame] | 6082 | |
Tiago Vignatti | 5ab91ad | 2012-03-12 19:40:09 -0300 | [diff] [blame] | 6083 | if (backlight_new < 5) |
| 6084 | backlight_new = 5; |
| 6085 | if (backlight_new > 255) |
| 6086 | backlight_new = 255; |
| 6087 | |
| 6088 | output->backlight_current = backlight_new; |
Tiago Vignatti | 8e53c7f | 2012-02-29 19:53:50 +0200 | [diff] [blame] | 6089 | output->set_backlight(output, output->backlight_current); |
| 6090 | } |
| 6091 | |
Kristian Høgsberg | b41c081 | 2012-03-04 14:53:40 -0500 | [diff] [blame] | 6092 | static void |
Derek Foreman | 8ae2db5 | 2015-07-15 13:00:36 -0500 | [diff] [blame] | 6093 | force_kill_binding(struct weston_keyboard *keyboard, uint32_t time, |
| 6094 | uint32_t key, void *data) |
Kristian Høgsberg | 92a57db | 2012-05-26 13:41:06 -0400 | [diff] [blame] | 6095 | { |
Kristian Høgsberg | fe7aa90 | 2013-05-08 09:54:37 -0400 | [diff] [blame] | 6096 | struct weston_surface *focus_surface; |
Kristian Høgsberg | 92a57db | 2012-05-26 13:41:06 -0400 | [diff] [blame] | 6097 | struct wl_client *client; |
Tiago Vignatti | 1d01b01 | 2012-09-27 17:48:36 +0300 | [diff] [blame] | 6098 | struct desktop_shell *shell = data; |
| 6099 | struct weston_compositor *compositor = shell->compositor; |
Kristian Høgsberg | 92a57db | 2012-05-26 13:41:06 -0400 | [diff] [blame] | 6100 | pid_t pid; |
Kristian Høgsberg | 92a57db | 2012-05-26 13:41:06 -0400 | [diff] [blame] | 6101 | |
Derek Foreman | 8ae2db5 | 2015-07-15 13:00:36 -0500 | [diff] [blame] | 6102 | focus_surface = keyboard->focus; |
Philipp Brüschweiler | 6cef009 | 2012-08-13 21:27:27 +0200 | [diff] [blame] | 6103 | if (!focus_surface) |
| 6104 | return; |
| 6105 | |
Tiago Vignatti | 1d01b01 | 2012-09-27 17:48:36 +0300 | [diff] [blame] | 6106 | wl_signal_emit(&compositor->kill_signal, focus_surface); |
| 6107 | |
Jason Ekstrand | 26ed73c | 2013-06-06 22:34:41 -0500 | [diff] [blame] | 6108 | client = wl_resource_get_client(focus_surface->resource); |
Tiago Vignatti | 920f197 | 2012-09-27 17:48:35 +0300 | [diff] [blame] | 6109 | wl_client_get_credentials(client, &pid, NULL, NULL); |
| 6110 | |
| 6111 | /* Skip clients that we launched ourselves (the credentials of |
| 6112 | * the socketpair is ours) */ |
| 6113 | if (pid == getpid()) |
| 6114 | return; |
Kristian Høgsberg | 92a57db | 2012-05-26 13:41:06 -0400 | [diff] [blame] | 6115 | |
Daniel Stone | 325fc2d | 2012-05-30 16:31:58 +0100 | [diff] [blame] | 6116 | kill(pid, SIGKILL); |
Kristian Høgsberg | 92a57db | 2012-05-26 13:41:06 -0400 | [diff] [blame] | 6117 | } |
| 6118 | |
| 6119 | static void |
Derek Foreman | 8ae2db5 | 2015-07-15 13:00:36 -0500 | [diff] [blame] | 6120 | workspace_up_binding(struct weston_keyboard *keyboard, uint32_t time, |
Jonas Ådahl | e3cddce | 2012-06-13 00:01:22 +0200 | [diff] [blame] | 6121 | uint32_t key, void *data) |
| 6122 | { |
| 6123 | struct desktop_shell *shell = data; |
| 6124 | unsigned int new_index = shell->workspaces.current; |
| 6125 | |
Kristian Høgsberg | ce345b0 | 2012-06-25 21:35:29 -0400 | [diff] [blame] | 6126 | if (shell->locked) |
Kristian Høgsberg | 4476aaf | 2012-06-25 14:03:13 -0400 | [diff] [blame] | 6127 | return; |
Jonas Ådahl | e3cddce | 2012-06-13 00:01:22 +0200 | [diff] [blame] | 6128 | if (new_index != 0) |
| 6129 | new_index--; |
| 6130 | |
| 6131 | change_workspace(shell, new_index); |
| 6132 | } |
| 6133 | |
| 6134 | static void |
Derek Foreman | 8ae2db5 | 2015-07-15 13:00:36 -0500 | [diff] [blame] | 6135 | workspace_down_binding(struct weston_keyboard *keyboard, uint32_t time, |
Jonas Ådahl | e3cddce | 2012-06-13 00:01:22 +0200 | [diff] [blame] | 6136 | uint32_t key, void *data) |
| 6137 | { |
| 6138 | struct desktop_shell *shell = data; |
| 6139 | unsigned int new_index = shell->workspaces.current; |
| 6140 | |
Kristian Høgsberg | ce345b0 | 2012-06-25 21:35:29 -0400 | [diff] [blame] | 6141 | if (shell->locked) |
Kristian Høgsberg | 4476aaf | 2012-06-25 14:03:13 -0400 | [diff] [blame] | 6142 | return; |
Jonas Ådahl | e3cddce | 2012-06-13 00:01:22 +0200 | [diff] [blame] | 6143 | if (new_index < shell->workspaces.num - 1) |
| 6144 | new_index++; |
| 6145 | |
| 6146 | change_workspace(shell, new_index); |
| 6147 | } |
| 6148 | |
| 6149 | static void |
Derek Foreman | 8ae2db5 | 2015-07-15 13:00:36 -0500 | [diff] [blame] | 6150 | workspace_f_binding(struct weston_keyboard *keyboard, uint32_t time, |
Jonas Ådahl | e3cddce | 2012-06-13 00:01:22 +0200 | [diff] [blame] | 6151 | uint32_t key, void *data) |
| 6152 | { |
| 6153 | struct desktop_shell *shell = data; |
| 6154 | unsigned int new_index; |
| 6155 | |
Kristian Høgsberg | ce345b0 | 2012-06-25 21:35:29 -0400 | [diff] [blame] | 6156 | if (shell->locked) |
Kristian Høgsberg | 4476aaf | 2012-06-25 14:03:13 -0400 | [diff] [blame] | 6157 | return; |
Jonas Ådahl | e3cddce | 2012-06-13 00:01:22 +0200 | [diff] [blame] | 6158 | new_index = key - KEY_F1; |
| 6159 | if (new_index >= shell->workspaces.num) |
| 6160 | new_index = shell->workspaces.num - 1; |
| 6161 | |
| 6162 | change_workspace(shell, new_index); |
| 6163 | } |
| 6164 | |
Jonas Ådahl | 8de6a1d | 2012-08-29 22:13:00 +0200 | [diff] [blame] | 6165 | static void |
Derek Foreman | 8ae2db5 | 2015-07-15 13:00:36 -0500 | [diff] [blame] | 6166 | workspace_move_surface_up_binding(struct weston_keyboard *keyboard, |
| 6167 | uint32_t time, uint32_t key, void *data) |
Jonas Ådahl | 8de6a1d | 2012-08-29 22:13:00 +0200 | [diff] [blame] | 6168 | { |
| 6169 | struct desktop_shell *shell = data; |
| 6170 | unsigned int new_index = shell->workspaces.current; |
| 6171 | |
| 6172 | if (shell->locked) |
| 6173 | return; |
| 6174 | |
| 6175 | if (new_index != 0) |
| 6176 | new_index--; |
| 6177 | |
Derek Foreman | 8ae2db5 | 2015-07-15 13:00:36 -0500 | [diff] [blame] | 6178 | take_surface_to_workspace_by_seat(shell, keyboard->seat, new_index); |
Jonas Ådahl | 8de6a1d | 2012-08-29 22:13:00 +0200 | [diff] [blame] | 6179 | } |
| 6180 | |
| 6181 | static void |
Derek Foreman | 8ae2db5 | 2015-07-15 13:00:36 -0500 | [diff] [blame] | 6182 | workspace_move_surface_down_binding(struct weston_keyboard *keyboard, |
| 6183 | uint32_t time, uint32_t key, void *data) |
Jonas Ådahl | 8de6a1d | 2012-08-29 22:13:00 +0200 | [diff] [blame] | 6184 | { |
| 6185 | struct desktop_shell *shell = data; |
| 6186 | unsigned int new_index = shell->workspaces.current; |
| 6187 | |
| 6188 | if (shell->locked) |
| 6189 | return; |
| 6190 | |
| 6191 | if (new_index < shell->workspaces.num - 1) |
| 6192 | new_index++; |
| 6193 | |
Derek Foreman | 8ae2db5 | 2015-07-15 13:00:36 -0500 | [diff] [blame] | 6194 | take_surface_to_workspace_by_seat(shell, keyboard->seat, new_index); |
Jonas Ådahl | 8de6a1d | 2012-08-29 22:13:00 +0200 | [diff] [blame] | 6195 | } |
Jonas Ådahl | e3cddce | 2012-06-13 00:01:22 +0200 | [diff] [blame] | 6196 | |
| 6197 | static void |
Ander Conselvan de Oliveira | c94d622 | 2014-01-29 18:47:54 +0200 | [diff] [blame] | 6198 | shell_reposition_view_on_output_destroy(struct weston_view *view) |
| 6199 | { |
| 6200 | struct weston_output *output, *first_output; |
| 6201 | struct weston_compositor *ec = view->surface->compositor; |
| 6202 | struct shell_surface *shsurf; |
| 6203 | float x, y; |
| 6204 | int visible; |
| 6205 | |
| 6206 | x = view->geometry.x; |
| 6207 | y = view->geometry.y; |
| 6208 | |
| 6209 | /* At this point the destroyed output is not in the list anymore. |
| 6210 | * If the view is still visible somewhere, we leave where it is, |
| 6211 | * otherwise, move it to the first output. */ |
| 6212 | visible = 0; |
| 6213 | wl_list_for_each(output, &ec->output_list, link) { |
| 6214 | if (pixman_region32_contains_point(&output->region, |
| 6215 | x, y, NULL)) { |
| 6216 | visible = 1; |
| 6217 | break; |
| 6218 | } |
| 6219 | } |
| 6220 | |
| 6221 | if (!visible) { |
| 6222 | first_output = container_of(ec->output_list.next, |
| 6223 | struct weston_output, link); |
| 6224 | |
| 6225 | x = first_output->x + first_output->width / 4; |
| 6226 | y = first_output->y + first_output->height / 4; |
Xiong Zhang | 62899f5 | 2014-03-07 16:27:19 +0800 | [diff] [blame] | 6227 | |
| 6228 | weston_view_set_position(view, x, y); |
| 6229 | } else { |
| 6230 | weston_view_geometry_dirty(view); |
Ander Conselvan de Oliveira | c94d622 | 2014-01-29 18:47:54 +0200 | [diff] [blame] | 6231 | } |
| 6232 | |
Ander Conselvan de Oliveira | c94d622 | 2014-01-29 18:47:54 +0200 | [diff] [blame] | 6233 | |
| 6234 | shsurf = get_shell_surface(view->surface); |
| 6235 | |
| 6236 | if (shsurf) { |
| 6237 | shsurf->saved_position_valid = false; |
| 6238 | shsurf->next_state.maximized = false; |
| 6239 | shsurf->next_state.fullscreen = false; |
| 6240 | shsurf->state_changed = true; |
| 6241 | } |
| 6242 | } |
| 6243 | |
Ander Conselvan de Oliveira | 304996d | 2014-04-11 13:57:15 +0300 | [diff] [blame] | 6244 | void |
| 6245 | shell_for_each_layer(struct desktop_shell *shell, |
| 6246 | shell_for_each_layer_func_t func, void *data) |
Ander Conselvan de Oliveira | c94d622 | 2014-01-29 18:47:54 +0200 | [diff] [blame] | 6247 | { |
Ander Conselvan de Oliveira | 304996d | 2014-04-11 13:57:15 +0300 | [diff] [blame] | 6248 | struct workspace **ws; |
| 6249 | |
| 6250 | func(shell, &shell->fullscreen_layer, data); |
| 6251 | func(shell, &shell->panel_layer, data); |
| 6252 | func(shell, &shell->background_layer, data); |
| 6253 | func(shell, &shell->lock_layer, data); |
| 6254 | func(shell, &shell->input_panel_layer, data); |
| 6255 | |
| 6256 | wl_array_for_each(ws, &shell->workspaces.array) |
| 6257 | func(shell, &(*ws)->layer, data); |
| 6258 | } |
| 6259 | |
| 6260 | static void |
| 6261 | shell_output_destroy_move_layer(struct desktop_shell *shell, |
| 6262 | struct weston_layer *layer, |
| 6263 | void *data) |
| 6264 | { |
| 6265 | struct weston_output *output = data; |
Ander Conselvan de Oliveira | c94d622 | 2014-01-29 18:47:54 +0200 | [diff] [blame] | 6266 | struct weston_view *view; |
| 6267 | |
Giulio Camuffo | 412e6a5 | 2014-07-09 22:12:56 +0300 | [diff] [blame] | 6268 | 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] | 6269 | if (view->output != output) |
| 6270 | continue; |
Ander Conselvan de Oliveira | c94d622 | 2014-01-29 18:47:54 +0200 | [diff] [blame] | 6271 | |
Ander Conselvan de Oliveira | 304996d | 2014-04-11 13:57:15 +0300 | [diff] [blame] | 6272 | shell_reposition_view_on_output_destroy(view); |
Ander Conselvan de Oliveira | c94d622 | 2014-01-29 18:47:54 +0200 | [diff] [blame] | 6273 | } |
| 6274 | } |
| 6275 | |
| 6276 | static void |
Xiong Zhang | 6b48142 | 2013-10-23 13:58:32 +0800 | [diff] [blame] | 6277 | handle_output_destroy(struct wl_listener *listener, void *data) |
| 6278 | { |
| 6279 | struct shell_output *output_listener = |
| 6280 | container_of(listener, struct shell_output, destroy_listener); |
Ander Conselvan de Oliveira | 304996d | 2014-04-11 13:57:15 +0300 | [diff] [blame] | 6281 | struct weston_output *output = output_listener->output; |
| 6282 | struct desktop_shell *shell = output_listener->shell; |
Xiong Zhang | 6b48142 | 2013-10-23 13:58:32 +0800 | [diff] [blame] | 6283 | |
Ander Conselvan de Oliveira | 304996d | 2014-04-11 13:57:15 +0300 | [diff] [blame] | 6284 | 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] | 6285 | |
Xiong Zhang | 6b48142 | 2013-10-23 13:58:32 +0800 | [diff] [blame] | 6286 | wl_list_remove(&output_listener->destroy_listener.link); |
| 6287 | wl_list_remove(&output_listener->link); |
| 6288 | free(output_listener); |
| 6289 | } |
| 6290 | |
| 6291 | static void |
| 6292 | create_shell_output(struct desktop_shell *shell, |
| 6293 | struct weston_output *output) |
| 6294 | { |
| 6295 | struct shell_output *shell_output; |
| 6296 | |
| 6297 | shell_output = zalloc(sizeof *shell_output); |
| 6298 | if (shell_output == NULL) |
| 6299 | return; |
| 6300 | |
| 6301 | shell_output->output = output; |
| 6302 | shell_output->shell = shell; |
| 6303 | shell_output->destroy_listener.notify = handle_output_destroy; |
| 6304 | wl_signal_add(&output->destroy_signal, |
| 6305 | &shell_output->destroy_listener); |
Kristian Høgsberg | a3a0e18 | 2013-10-23 23:36:04 -0700 | [diff] [blame] | 6306 | wl_list_insert(shell->output_list.prev, &shell_output->link); |
Xiong Zhang | 6b48142 | 2013-10-23 13:58:32 +0800 | [diff] [blame] | 6307 | } |
| 6308 | |
| 6309 | static void |
| 6310 | handle_output_create(struct wl_listener *listener, void *data) |
| 6311 | { |
| 6312 | struct desktop_shell *shell = |
| 6313 | container_of(listener, struct desktop_shell, output_create_listener); |
| 6314 | struct weston_output *output = (struct weston_output *)data; |
| 6315 | |
| 6316 | create_shell_output(shell, output); |
| 6317 | } |
| 6318 | |
| 6319 | static void |
Ander Conselvan de Oliveira | 304996d | 2014-04-11 13:57:15 +0300 | [diff] [blame] | 6320 | handle_output_move_layer(struct desktop_shell *shell, |
| 6321 | struct weston_layer *layer, void *data) |
Ander Conselvan de Oliveira | a8a9baf | 2014-01-29 18:47:52 +0200 | [diff] [blame] | 6322 | { |
Ander Conselvan de Oliveira | 304996d | 2014-04-11 13:57:15 +0300 | [diff] [blame] | 6323 | struct weston_output *output = data; |
Ander Conselvan de Oliveira | a8a9baf | 2014-01-29 18:47:52 +0200 | [diff] [blame] | 6324 | struct weston_view *view; |
| 6325 | float x, y; |
| 6326 | |
Giulio Camuffo | 412e6a5 | 2014-07-09 22:12:56 +0300 | [diff] [blame] | 6327 | 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] | 6328 | if (view->output != output) |
| 6329 | continue; |
| 6330 | |
| 6331 | x = view->geometry.x + output->move_x; |
| 6332 | y = view->geometry.y + output->move_y; |
| 6333 | weston_view_set_position(view, x, y); |
| 6334 | } |
| 6335 | } |
| 6336 | |
| 6337 | static void |
| 6338 | handle_output_move(struct wl_listener *listener, void *data) |
| 6339 | { |
| 6340 | struct desktop_shell *shell; |
| 6341 | |
Ander Conselvan de Oliveira | a8a9baf | 2014-01-29 18:47:52 +0200 | [diff] [blame] | 6342 | shell = container_of(listener, struct desktop_shell, |
| 6343 | output_move_listener); |
Ander Conselvan de Oliveira | a8a9baf | 2014-01-29 18:47:52 +0200 | [diff] [blame] | 6344 | |
Ander Conselvan de Oliveira | 304996d | 2014-04-11 13:57:15 +0300 | [diff] [blame] | 6345 | shell_for_each_layer(shell, handle_output_move_layer, data); |
Ander Conselvan de Oliveira | a8a9baf | 2014-01-29 18:47:52 +0200 | [diff] [blame] | 6346 | } |
| 6347 | |
| 6348 | static void |
Xiong Zhang | 6b48142 | 2013-10-23 13:58:32 +0800 | [diff] [blame] | 6349 | setup_output_destroy_handler(struct weston_compositor *ec, |
| 6350 | struct desktop_shell *shell) |
| 6351 | { |
| 6352 | struct weston_output *output; |
| 6353 | |
| 6354 | wl_list_init(&shell->output_list); |
| 6355 | wl_list_for_each(output, &ec->output_list, link) |
| 6356 | create_shell_output(shell, output); |
| 6357 | |
| 6358 | shell->output_create_listener.notify = handle_output_create; |
| 6359 | wl_signal_add(&ec->output_created_signal, |
| 6360 | &shell->output_create_listener); |
Ander Conselvan de Oliveira | a8a9baf | 2014-01-29 18:47:52 +0200 | [diff] [blame] | 6361 | |
| 6362 | shell->output_move_listener.notify = handle_output_move; |
| 6363 | wl_signal_add(&ec->output_moved_signal, &shell->output_move_listener); |
Xiong Zhang | 6b48142 | 2013-10-23 13:58:32 +0800 | [diff] [blame] | 6364 | } |
| 6365 | |
| 6366 | static void |
Kristian Høgsberg | 02e79dc | 2012-04-12 09:55:26 -0400 | [diff] [blame] | 6367 | shell_destroy(struct wl_listener *listener, void *data) |
Pekka Paalanen | 3c64723 | 2011-12-22 13:43:43 +0200 | [diff] [blame] | 6368 | { |
Tiago Vignatti | be14326 | 2012-04-16 17:31:41 +0300 | [diff] [blame] | 6369 | struct desktop_shell *shell = |
| 6370 | container_of(listener, struct desktop_shell, destroy_listener); |
Jonas Ådahl | e3cddce | 2012-06-13 00:01:22 +0200 | [diff] [blame] | 6371 | struct workspace **ws; |
Xiong Zhang | 6b48142 | 2013-10-23 13:58:32 +0800 | [diff] [blame] | 6372 | struct shell_output *shell_output, *tmp; |
Pekka Paalanen | 3c64723 | 2011-12-22 13:43:43 +0200 | [diff] [blame] | 6373 | |
Kristian Høgsberg | 17bccae | 2014-01-16 16:46:28 -0800 | [diff] [blame] | 6374 | /* Force state to unlocked so we don't try to fade */ |
| 6375 | shell->locked = false; |
Pekka Paalanen | 826dc14 | 2014-08-27 12:11:53 +0300 | [diff] [blame] | 6376 | |
| 6377 | if (shell->child.client) { |
| 6378 | /* disable respawn */ |
| 6379 | wl_list_remove(&shell->child.client_destroy_listener.link); |
Pekka Paalanen | 9cf5cc8 | 2012-01-02 16:00:24 +0200 | [diff] [blame] | 6380 | wl_client_destroy(shell->child.client); |
Pekka Paalanen | 826dc14 | 2014-08-27 12:11:53 +0300 | [diff] [blame] | 6381 | } |
Pekka Paalanen | 9cf5cc8 | 2012-01-02 16:00:24 +0200 | [diff] [blame] | 6382 | |
Ander Conselvan de Oliveira | a457563 | 2013-02-21 18:35:23 +0200 | [diff] [blame] | 6383 | wl_list_remove(&shell->idle_listener.link); |
| 6384 | wl_list_remove(&shell->wake_listener.link); |
Kristian Høgsberg | 677a5f5 | 2013-12-04 11:00:19 -0800 | [diff] [blame] | 6385 | |
Pekka Paalanen | aa9536a | 2015-06-24 16:09:17 +0300 | [diff] [blame] | 6386 | text_backend_destroy(shell->text_backend); |
Kristian Høgsberg | 677a5f5 | 2013-12-04 11:00:19 -0800 | [diff] [blame] | 6387 | input_panel_destroy(shell); |
Kristian Høgsberg | 88c1607 | 2012-05-16 08:04:19 -0400 | [diff] [blame] | 6388 | |
Xiong Zhang | 6b48142 | 2013-10-23 13:58:32 +0800 | [diff] [blame] | 6389 | wl_list_for_each_safe(shell_output, tmp, &shell->output_list, link) { |
| 6390 | wl_list_remove(&shell_output->destroy_listener.link); |
| 6391 | wl_list_remove(&shell_output->link); |
| 6392 | free(shell_output); |
| 6393 | } |
| 6394 | |
| 6395 | wl_list_remove(&shell->output_create_listener.link); |
Kristian Høgsberg | 6d50b0f | 2014-04-30 20:46:25 -0700 | [diff] [blame] | 6396 | wl_list_remove(&shell->output_move_listener.link); |
Xiong Zhang | 6b48142 | 2013-10-23 13:58:32 +0800 | [diff] [blame] | 6397 | |
Jonas Ådahl | e3cddce | 2012-06-13 00:01:22 +0200 | [diff] [blame] | 6398 | wl_array_for_each(ws, &shell->workspaces.array) |
| 6399 | workspace_destroy(*ws); |
| 6400 | wl_array_release(&shell->workspaces.array); |
| 6401 | |
Emilio Pozuelo Monfort | 46ce798 | 2013-11-20 13:22:29 +0100 | [diff] [blame] | 6402 | free(shell->client); |
Pekka Paalanen | 3c64723 | 2011-12-22 13:43:43 +0200 | [diff] [blame] | 6403 | free(shell); |
| 6404 | } |
| 6405 | |
Tiago Vignatti | 0b52d48 | 2012-04-20 18:54:25 +0300 | [diff] [blame] | 6406 | static void |
| 6407 | shell_add_bindings(struct weston_compositor *ec, struct desktop_shell *shell) |
| 6408 | { |
| 6409 | uint32_t mod; |
Jonas Ådahl | e3cddce | 2012-06-13 00:01:22 +0200 | [diff] [blame] | 6410 | int i, num_workspace_bindings; |
Tiago Vignatti | 0b52d48 | 2012-04-20 18:54:25 +0300 | [diff] [blame] | 6411 | |
| 6412 | /* fixed bindings */ |
Daniel Stone | 325fc2d | 2012-05-30 16:31:58 +0100 | [diff] [blame] | 6413 | weston_compositor_add_key_binding(ec, KEY_BACKSPACE, |
| 6414 | MODIFIER_CTRL | MODIFIER_ALT, |
| 6415 | terminate_binding, ec); |
| 6416 | weston_compositor_add_button_binding(ec, BTN_LEFT, 0, |
| 6417 | click_to_activate_binding, |
| 6418 | shell); |
Kristian Høgsberg | f0ce581 | 2014-04-07 11:52:17 -0700 | [diff] [blame] | 6419 | weston_compositor_add_button_binding(ec, BTN_RIGHT, 0, |
| 6420 | click_to_activate_binding, |
| 6421 | shell); |
Neil Roberts | a28c693 | 2013-10-03 16:43:04 +0100 | [diff] [blame] | 6422 | weston_compositor_add_touch_binding(ec, 0, |
| 6423 | touch_to_activate_binding, |
| 6424 | shell); |
Daniel Stone | 325fc2d | 2012-05-30 16:31:58 +0100 | [diff] [blame] | 6425 | weston_compositor_add_axis_binding(ec, WL_POINTER_AXIS_VERTICAL_SCROLL, |
| 6426 | MODIFIER_SUPER | MODIFIER_ALT, |
| 6427 | surface_opacity_binding, NULL); |
| 6428 | weston_compositor_add_axis_binding(ec, WL_POINTER_AXIS_VERTICAL_SCROLL, |
| 6429 | MODIFIER_SUPER, zoom_axis_binding, |
| 6430 | NULL); |
Tiago Vignatti | 0b52d48 | 2012-04-20 18:54:25 +0300 | [diff] [blame] | 6431 | |
| 6432 | /* configurable bindings */ |
| 6433 | mod = shell->binding_modifier; |
Daniel Stone | 325fc2d | 2012-05-30 16:31:58 +0100 | [diff] [blame] | 6434 | weston_compositor_add_key_binding(ec, KEY_PAGEUP, mod, |
| 6435 | zoom_key_binding, NULL); |
| 6436 | weston_compositor_add_key_binding(ec, KEY_PAGEDOWN, mod, |
| 6437 | zoom_key_binding, NULL); |
Kristian Høgsberg | 211b517 | 2014-01-11 13:10:21 -0800 | [diff] [blame] | 6438 | weston_compositor_add_key_binding(ec, KEY_M, mod | MODIFIER_SHIFT, |
| 6439 | maximize_binding, NULL); |
| 6440 | weston_compositor_add_key_binding(ec, KEY_F, mod | MODIFIER_SHIFT, |
| 6441 | fullscreen_binding, NULL); |
Daniel Stone | 325fc2d | 2012-05-30 16:31:58 +0100 | [diff] [blame] | 6442 | weston_compositor_add_button_binding(ec, BTN_LEFT, mod, move_binding, |
| 6443 | shell); |
Neil Roberts | aba0f25 | 2013-10-03 16:43:05 +0100 | [diff] [blame] | 6444 | weston_compositor_add_touch_binding(ec, mod, touch_move_binding, shell); |
Derek Foreman | 2217f3f | 2015-06-25 16:03:30 -0500 | [diff] [blame] | 6445 | weston_compositor_add_button_binding(ec, BTN_RIGHT, mod, |
Daniel Stone | 325fc2d | 2012-05-30 16:31:58 +0100 | [diff] [blame] | 6446 | resize_binding, shell); |
Kristian Høgsberg | 0837fa9 | 2014-01-20 10:35:26 -0800 | [diff] [blame] | 6447 | weston_compositor_add_button_binding(ec, BTN_LEFT, |
| 6448 | mod | MODIFIER_SHIFT, |
| 6449 | resize_binding, shell); |
Pekka Paalanen | 7bb6510 | 2013-05-22 18:03:04 +0300 | [diff] [blame] | 6450 | |
| 6451 | if (ec->capabilities & WESTON_CAP_ROTATION_ANY) |
Derek Foreman | 2217f3f | 2015-06-25 16:03:30 -0500 | [diff] [blame] | 6452 | weston_compositor_add_button_binding(ec, BTN_MIDDLE, mod, |
Pekka Paalanen | 7bb6510 | 2013-05-22 18:03:04 +0300 | [diff] [blame] | 6453 | rotate_binding, NULL); |
| 6454 | |
Daniel Stone | 325fc2d | 2012-05-30 16:31:58 +0100 | [diff] [blame] | 6455 | weston_compositor_add_key_binding(ec, KEY_TAB, mod, switcher_binding, |
| 6456 | shell); |
| 6457 | weston_compositor_add_key_binding(ec, KEY_F9, mod, backlight_binding, |
| 6458 | ec); |
| 6459 | weston_compositor_add_key_binding(ec, KEY_BRIGHTNESSDOWN, 0, |
| 6460 | backlight_binding, ec); |
| 6461 | weston_compositor_add_key_binding(ec, KEY_F10, mod, backlight_binding, |
| 6462 | ec); |
| 6463 | weston_compositor_add_key_binding(ec, KEY_BRIGHTNESSUP, 0, |
| 6464 | backlight_binding, ec); |
Daniel Stone | 325fc2d | 2012-05-30 16:31:58 +0100 | [diff] [blame] | 6465 | weston_compositor_add_key_binding(ec, KEY_K, mod, |
| 6466 | force_kill_binding, shell); |
Jonas Ådahl | e3cddce | 2012-06-13 00:01:22 +0200 | [diff] [blame] | 6467 | weston_compositor_add_key_binding(ec, KEY_UP, mod, |
| 6468 | workspace_up_binding, shell); |
| 6469 | weston_compositor_add_key_binding(ec, KEY_DOWN, mod, |
| 6470 | workspace_down_binding, shell); |
Jonas Ådahl | 8de6a1d | 2012-08-29 22:13:00 +0200 | [diff] [blame] | 6471 | weston_compositor_add_key_binding(ec, KEY_UP, mod | MODIFIER_SHIFT, |
| 6472 | workspace_move_surface_up_binding, |
| 6473 | shell); |
| 6474 | weston_compositor_add_key_binding(ec, KEY_DOWN, mod | MODIFIER_SHIFT, |
| 6475 | workspace_move_surface_down_binding, |
| 6476 | shell); |
Jonas Ådahl | e3cddce | 2012-06-13 00:01:22 +0200 | [diff] [blame] | 6477 | |
Kristian Høgsberg | d56ab4e | 2014-01-16 16:51:52 -0800 | [diff] [blame] | 6478 | if (shell->exposay_modifier) |
| 6479 | weston_compositor_add_modifier_binding(ec, shell->exposay_modifier, |
| 6480 | exposay_binding, shell); |
Daniel Stone | df8133b | 2013-11-19 11:37:14 +0100 | [diff] [blame] | 6481 | |
Jonas Ådahl | e3cddce | 2012-06-13 00:01:22 +0200 | [diff] [blame] | 6482 | /* Add bindings for mod+F[1-6] for workspace 1 to 6. */ |
| 6483 | if (shell->workspaces.num > 1) { |
| 6484 | num_workspace_bindings = shell->workspaces.num; |
| 6485 | if (num_workspace_bindings > 6) |
| 6486 | num_workspace_bindings = 6; |
| 6487 | for (i = 0; i < num_workspace_bindings; i++) |
| 6488 | weston_compositor_add_key_binding(ec, KEY_F1 + i, mod, |
| 6489 | workspace_f_binding, |
| 6490 | shell); |
| 6491 | } |
Ander Conselvan de Oliveira | c509d2b | 2012-11-08 17:20:45 +0200 | [diff] [blame] | 6492 | |
Pekka Paalanen | 2829f7c | 2015-02-19 17:02:13 +0200 | [diff] [blame] | 6493 | weston_install_debug_key_binding(ec, mod); |
Tiago Vignatti | 0b52d48 | 2012-04-20 18:54:25 +0300 | [diff] [blame] | 6494 | } |
| 6495 | |
Jason Ekstrand | 024177c | 2014-04-21 19:42:58 -0500 | [diff] [blame] | 6496 | static void |
| 6497 | handle_seat_created(struct wl_listener *listener, void *data) |
| 6498 | { |
| 6499 | struct weston_seat *seat = data; |
| 6500 | |
| 6501 | create_shell_seat(seat); |
| 6502 | } |
| 6503 | |
Kristian Høgsberg | 1c56218 | 2011-05-02 22:09:20 -0400 | [diff] [blame] | 6504 | WL_EXPORT int |
Kristian Høgsberg | cb4685b | 2013-02-20 15:37:49 -0500 | [diff] [blame] | 6505 | module_init(struct weston_compositor *ec, |
Ossama Othman | a50e6e4 | 2013-05-14 09:48:26 -0700 | [diff] [blame] | 6506 | int *argc, char *argv[]) |
Kristian Høgsberg | 4cca349 | 2011-01-18 07:53:49 -0500 | [diff] [blame] | 6507 | { |
Kristian Høgsberg | f4d2f23 | 2012-08-10 10:05:39 -0400 | [diff] [blame] | 6508 | struct weston_seat *seat; |
Tiago Vignatti | be14326 | 2012-04-16 17:31:41 +0300 | [diff] [blame] | 6509 | struct desktop_shell *shell; |
Jonas Ådahl | e3cddce | 2012-06-13 00:01:22 +0200 | [diff] [blame] | 6510 | struct workspace **pws; |
| 6511 | unsigned int i; |
Tiago Vignatti | b7dbbd6 | 2012-09-25 17:57:01 +0300 | [diff] [blame] | 6512 | struct wl_event_loop *loop; |
Kristian Høgsberg | 02ec0a5 | 2011-04-23 13:04:11 -0400 | [diff] [blame] | 6513 | |
Peter Hutterer | f3d6227 | 2013-08-08 11:57:05 +1000 | [diff] [blame] | 6514 | shell = zalloc(sizeof *shell); |
Kristian Høgsberg | 02ec0a5 | 2011-04-23 13:04:11 -0400 | [diff] [blame] | 6515 | if (shell == NULL) |
| 6516 | return -1; |
| 6517 | |
Kristian Høgsberg | 7584062 | 2011-09-06 13:48:16 -0400 | [diff] [blame] | 6518 | shell->compositor = ec; |
Kristian Høgsberg | 02e79dc | 2012-04-12 09:55:26 -0400 | [diff] [blame] | 6519 | |
| 6520 | shell->destroy_listener.notify = shell_destroy; |
| 6521 | wl_signal_add(&ec->destroy_signal, &shell->destroy_listener); |
Ander Conselvan de Oliveira | a457563 | 2013-02-21 18:35:23 +0200 | [diff] [blame] | 6522 | shell->idle_listener.notify = idle_handler; |
| 6523 | wl_signal_add(&ec->idle_signal, &shell->idle_listener); |
| 6524 | shell->wake_listener.notify = wake_handler; |
| 6525 | wl_signal_add(&ec->wake_signal, &shell->wake_listener); |
Kristian Høgsberg | 677a5f5 | 2013-12-04 11:00:19 -0800 | [diff] [blame] | 6526 | |
Kristian Høgsberg | 82a1d11 | 2012-07-19 14:02:00 -0400 | [diff] [blame] | 6527 | ec->shell_interface.shell = shell; |
Tiago Vignatti | bc052c9 | 2012-04-19 16:18:18 +0300 | [diff] [blame] | 6528 | ec->shell_interface.create_shell_surface = create_shell_surface; |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 6529 | ec->shell_interface.get_primary_view = get_primary_view; |
Tiago Vignatti | bc052c9 | 2012-04-19 16:18:18 +0300 | [diff] [blame] | 6530 | ec->shell_interface.set_toplevel = set_toplevel; |
Tiago Vignatti | 491bac1 | 2012-05-18 16:37:43 -0400 | [diff] [blame] | 6531 | ec->shell_interface.set_transient = set_transient; |
Kristian Høgsberg | 4779241 | 2014-05-04 13:47:06 -0700 | [diff] [blame] | 6532 | ec->shell_interface.set_fullscreen = shell_interface_set_fullscreen; |
Tiago Vignatti | fb2adba | 2013-06-12 15:43:21 -0300 | [diff] [blame] | 6533 | ec->shell_interface.set_xwayland = set_xwayland; |
Kristian Høgsberg | ae356ae | 2014-04-29 16:03:54 -0700 | [diff] [blame] | 6534 | ec->shell_interface.move = shell_interface_move; |
Derek Foreman | 8fbebbd | 2015-07-15 13:00:40 -0500 | [diff] [blame] | 6535 | ec->shell_interface.resize = shell_interface_resize; |
Giulio Camuffo | 62942ad | 2013-09-11 18:20:47 +0200 | [diff] [blame] | 6536 | ec->shell_interface.set_title = set_title; |
Jasper St. Pierre | ccf48fb | 2014-05-02 10:21:38 -0400 | [diff] [blame] | 6537 | ec->shell_interface.set_window_geometry = set_window_geometry; |
Giulio Camuffo | 6b4b241 | 2015-01-29 19:06:49 +0200 | [diff] [blame] | 6538 | ec->shell_interface.set_maximized = shell_interface_set_maximized; |
Giulio Camuffo | a8e9b41 | 2015-01-27 19:10:37 +0200 | [diff] [blame] | 6539 | ec->shell_interface.set_pid = set_pid; |
Kristian Høgsberg | 4cca349 | 2011-01-18 07:53:49 -0500 | [diff] [blame] | 6540 | |
Kristian Høgsberg | 3be2ce9 | 2012-02-29 12:42:35 -0500 | [diff] [blame] | 6541 | weston_layer_init(&shell->fullscreen_layer, &ec->cursor_layer.link); |
| 6542 | weston_layer_init(&shell->panel_layer, &shell->fullscreen_layer.link); |
Jonas Ådahl | e3cddce | 2012-06-13 00:01:22 +0200 | [diff] [blame] | 6543 | weston_layer_init(&shell->background_layer, &shell->panel_layer.link); |
| 6544 | weston_layer_init(&shell->lock_layer, NULL); |
Philipp Brüschweiler | 711fda8 | 2012-08-09 18:50:43 +0200 | [diff] [blame] | 6545 | weston_layer_init(&shell->input_panel_layer, NULL); |
Jonas Ådahl | e3cddce | 2012-06-13 00:01:22 +0200 | [diff] [blame] | 6546 | |
| 6547 | wl_array_init(&shell->workspaces.array); |
Jonas Ådahl | e9d2250 | 2012-08-29 22:13:01 +0200 | [diff] [blame] | 6548 | wl_list_init(&shell->workspaces.client_list); |
Kristian Høgsberg | 3be2ce9 | 2012-02-29 12:42:35 -0500 | [diff] [blame] | 6549 | |
Kristian Høgsberg | 677a5f5 | 2013-12-04 11:00:19 -0800 | [diff] [blame] | 6550 | if (input_panel_setup(shell) < 0) |
| 6551 | return -1; |
| 6552 | |
Pekka Paalanen | aa9536a | 2015-06-24 16:09:17 +0300 | [diff] [blame] | 6553 | shell->text_backend = text_backend_init(ec); |
| 6554 | if (!shell->text_backend) |
Murray Calavera | 9a51cd7 | 2015-06-10 21:16:02 +0000 | [diff] [blame] | 6555 | return -1; |
| 6556 | |
Kristian Høgsberg | 14e438c | 2013-05-26 21:48:14 -0400 | [diff] [blame] | 6557 | shell_configuration(shell); |
Pekka Paalanen | e955f1e | 2011-12-07 11:49:52 +0200 | [diff] [blame] | 6558 | |
Daniel Stone | df8133b | 2013-11-19 11:37:14 +0100 | [diff] [blame] | 6559 | shell->exposay.state_cur = EXPOSAY_LAYOUT_INACTIVE; |
| 6560 | shell->exposay.state_target = EXPOSAY_TARGET_CANCEL; |
| 6561 | |
Jonas Ådahl | e3cddce | 2012-06-13 00:01:22 +0200 | [diff] [blame] | 6562 | for (i = 0; i < shell->workspaces.num; i++) { |
| 6563 | pws = wl_array_add(&shell->workspaces.array, sizeof *pws); |
| 6564 | if (pws == NULL) |
| 6565 | return -1; |
| 6566 | |
| 6567 | *pws = workspace_create(); |
| 6568 | if (*pws == NULL) |
| 6569 | return -1; |
| 6570 | } |
| 6571 | activate_workspace(shell, 0); |
| 6572 | |
Manuel Bachmann | 50c87db | 2014-02-26 15:52:13 +0100 | [diff] [blame] | 6573 | weston_layer_init(&shell->minimized_layer, NULL); |
| 6574 | |
Jonas Ådahl | 8de6a1d | 2012-08-29 22:13:00 +0200 | [diff] [blame] | 6575 | wl_list_init(&shell->workspaces.anim_sticky_list); |
Jonas Ådahl | 62fcd04 | 2012-06-13 00:01:23 +0200 | [diff] [blame] | 6576 | wl_list_init(&shell->workspaces.animation.link); |
| 6577 | shell->workspaces.animation.frame = animate_workspace_change_frame; |
| 6578 | |
Kristian Høgsberg | 919cddb | 2013-07-08 19:03:57 -0400 | [diff] [blame] | 6579 | if (wl_global_create(ec->wl_display, &wl_shell_interface, 1, |
Kristian Høgsberg | 97d44aa | 2011-08-26 17:21:20 -0400 | [diff] [blame] | 6580 | shell, bind_shell) == NULL) |
Kristian Høgsberg | 4cca349 | 2011-01-18 07:53:49 -0500 | [diff] [blame] | 6581 | return -1; |
| 6582 | |
Rafael Antognolli | e2a3455 | 2013-12-03 15:35:45 -0200 | [diff] [blame] | 6583 | if (wl_global_create(ec->wl_display, &xdg_shell_interface, 1, |
| 6584 | shell, bind_xdg_shell) == NULL) |
| 6585 | return -1; |
| 6586 | |
Kristian Høgsberg | 919cddb | 2013-07-08 19:03:57 -0400 | [diff] [blame] | 6587 | if (wl_global_create(ec->wl_display, |
Jonny Lamb | 765760d | 2014-08-20 15:53:19 +0200 | [diff] [blame] | 6588 | &desktop_shell_interface, 3, |
Kristian Høgsberg | 919cddb | 2013-07-08 19:03:57 -0400 | [diff] [blame] | 6589 | shell, bind_desktop_shell) == NULL) |
Kristian Høgsberg | 7584062 | 2011-09-06 13:48:16 -0400 | [diff] [blame] | 6590 | return -1; |
| 6591 | |
Kristian Høgsberg | 919cddb | 2013-07-08 19:03:57 -0400 | [diff] [blame] | 6592 | if (wl_global_create(ec->wl_display, &workspace_manager_interface, 1, |
| 6593 | shell, bind_workspace_manager) == NULL) |
Jonas Ådahl | e9d2250 | 2012-08-29 22:13:01 +0200 | [diff] [blame] | 6594 | return -1; |
| 6595 | |
Kristian Høgsberg | f03a616 | 2012-01-17 11:07:42 -0500 | [diff] [blame] | 6596 | shell->child.deathstamp = weston_compositor_get_time(); |
Tiago Vignatti | b7dbbd6 | 2012-09-25 17:57:01 +0300 | [diff] [blame] | 6597 | |
Jonny Lamb | 765760d | 2014-08-20 15:53:19 +0200 | [diff] [blame] | 6598 | shell->panel_position = DESKTOP_SHELL_PANEL_POSITION_TOP; |
| 6599 | |
Xiong Zhang | 6b48142 | 2013-10-23 13:58:32 +0800 | [diff] [blame] | 6600 | setup_output_destroy_handler(ec, shell); |
| 6601 | |
Tiago Vignatti | b7dbbd6 | 2012-09-25 17:57:01 +0300 | [diff] [blame] | 6602 | loop = wl_display_get_event_loop(ec->wl_display); |
| 6603 | wl_event_loop_add_idle(loop, launch_desktop_shell_process, shell); |
Pekka Paalanen | 6cd281a | 2011-11-03 14:11:32 +0200 | [diff] [blame] | 6604 | |
Jason Ekstrand | 024177c | 2014-04-21 19:42:58 -0500 | [diff] [blame] | 6605 | wl_list_for_each(seat, &ec->seat_list, link) |
| 6606 | handle_seat_created(NULL, seat); |
| 6607 | shell->seat_create_listener.notify = handle_seat_created; |
| 6608 | wl_signal_add(&ec->seat_created_signal, &shell->seat_create_listener); |
Kristian Høgsberg | d56bd90 | 2012-06-05 09:58:51 -0400 | [diff] [blame] | 6609 | |
Giulio Camuffo | c6ab3d5 | 2013-12-11 23:45:12 +0100 | [diff] [blame] | 6610 | screenshooter_create(ec); |
| 6611 | |
Tiago Vignatti | 0b52d48 | 2012-04-20 18:54:25 +0300 | [diff] [blame] | 6612 | shell_add_bindings(ec, shell); |
Kristian Høgsberg | 0793756 | 2011-04-12 17:25:42 -0400 | [diff] [blame] | 6613 | |
Pekka Paalanen | 79346ab | 2013-05-22 18:03:09 +0300 | [diff] [blame] | 6614 | shell_fade_init(shell); |
Ander Conselvan de Oliveira | 19d10ef | 2013-02-21 18:35:20 +0200 | [diff] [blame] | 6615 | |
Pekka Paalanen | 2e62e4a | 2014-08-28 11:41:26 +0300 | [diff] [blame] | 6616 | clock_gettime(CLOCK_MONOTONIC, &shell->startup_time); |
| 6617 | |
Kristian Høgsberg | 4cca349 | 2011-01-18 07:53:49 -0500 | [diff] [blame] | 6618 | return 0; |
| 6619 | } |