Kristian Høgsberg | 4cca349 | 2011-01-18 07:53:49 -0500 | [diff] [blame] | 1 | /* |
Kristian Høgsberg | 0704539 | 2012-02-19 18:52:44 -0500 | [diff] [blame] | 2 | * Copyright © 2010-2012 Intel Corporation |
Pekka Paalanen | d581a8f | 2012-01-27 16:25:16 +0200 | [diff] [blame] | 3 | * Copyright © 2011-2012 Collabora, Ltd. |
Daniel Stone | df8133b | 2013-11-19 11:37:14 +0100 | [diff] [blame] | 4 | * Copyright © 2013 Raspberry Pi Foundation |
Kristian Høgsberg | 4cca349 | 2011-01-18 07:53:49 -0500 | [diff] [blame] | 5 | * |
Bryce Harrington | af637c2 | 2015-06-11 12:55:55 -0700 | [diff] [blame] | 6 | * Permission is hereby granted, free of charge, to any person obtaining a |
| 7 | * copy of this software and associated documentation files (the "Software"), |
| 8 | * to deal in the Software without restriction, including without limitation |
| 9 | * the rights to use, copy, modify, merge, publish, distribute, sublicense, |
| 10 | * and/or sell copies of the Software, and to permit persons to whom the |
| 11 | * Software is furnished to do so, subject to the following conditions: |
Kristian Høgsberg | 4cca349 | 2011-01-18 07:53:49 -0500 | [diff] [blame] | 12 | * |
Bryce Harrington | af637c2 | 2015-06-11 12:55:55 -0700 | [diff] [blame] | 13 | * The above copyright notice and this permission notice (including the next |
| 14 | * paragraph) shall be included in all copies or substantial portions of the |
| 15 | * Software. |
| 16 | * |
| 17 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR |
| 18 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, |
| 19 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL |
| 20 | * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER |
| 21 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING |
| 22 | * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER |
| 23 | * DEALINGS IN THE SOFTWARE. |
Kristian Høgsberg | 4cca349 | 2011-01-18 07:53:49 -0500 | [diff] [blame] | 24 | */ |
| 25 | |
Daniel Stone | c228e23 | 2013-05-22 18:03:19 +0300 | [diff] [blame] | 26 | #include "config.h" |
| 27 | |
Kristian Høgsberg | 4cca349 | 2011-01-18 07:53:49 -0500 | [diff] [blame] | 28 | #include <stdlib.h> |
Kristian Høgsberg | 7584062 | 2011-09-06 13:48:16 -0400 | [diff] [blame] | 29 | #include <stdio.h> |
Kristian Høgsberg | 4cca349 | 2011-01-18 07:53:49 -0500 | [diff] [blame] | 30 | #include <string.h> |
| 31 | #include <unistd.h> |
Kristian Høgsberg | 0793756 | 2011-04-12 17:25:42 -0400 | [diff] [blame] | 32 | #include <linux/input.h> |
Pekka Paalanen | f0fc70d | 2011-11-15 13:34:54 +0200 | [diff] [blame] | 33 | #include <assert.h> |
Pekka Paalanen | 18027e5 | 2011-12-02 16:31:49 +0200 | [diff] [blame] | 34 | #include <signal.h> |
Pekka Paalanen | 460099f | 2012-01-20 16:48:25 +0200 | [diff] [blame] | 35 | #include <math.h> |
Kristian Høgsberg | 92a57db | 2012-05-26 13:41:06 -0400 | [diff] [blame] | 36 | #include <sys/types.h> |
Kristian Høgsberg | 4cca349 | 2011-01-18 07:53:49 -0500 | [diff] [blame] | 37 | |
Kristian Høgsberg | 1ef2313 | 2013-12-04 00:20:01 -0800 | [diff] [blame] | 38 | #include "shell.h" |
Kristian Høgsberg | 7584062 | 2011-09-06 13:48:16 -0400 | [diff] [blame] | 39 | #include "desktop-shell-server-protocol.h" |
Jonas Ådahl | e9d2250 | 2012-08-29 22:13:01 +0200 | [diff] [blame] | 40 | #include "workspaces-server-protocol.h" |
Jon Cruz | 4678bab | 2015-06-15 15:37:07 -0700 | [diff] [blame] | 41 | #include "shared/config-parser.h" |
Jon Cruz | d618f68 | 2015-06-15 15:37:09 -0700 | [diff] [blame] | 42 | #include "shared/helpers.h" |
Rafael Antognolli | e2a3455 | 2013-12-03 15:35:45 -0200 | [diff] [blame] | 43 | #include "xdg-shell-server-protocol.h" |
Kristian Høgsberg | 4cca349 | 2011-01-18 07:53:49 -0500 | [diff] [blame] | 44 | |
Jonas Ådahl | e3cddce | 2012-06-13 00:01:22 +0200 | [diff] [blame] | 45 | #define DEFAULT_NUM_WORKSPACES 1 |
Jonas Ådahl | 62fcd04 | 2012-06-13 00:01:23 +0200 | [diff] [blame] | 46 | #define DEFAULT_WORKSPACE_CHANGE_ANIMATION_LENGTH 200 |
Jonas Ådahl | e3cddce | 2012-06-13 00:01:22 +0200 | [diff] [blame] | 47 | |
Giulio Camuffo | 1aaf3e4 | 2013-12-09 22:47:58 +0100 | [diff] [blame] | 48 | #ifndef static_assert |
| 49 | #define static_assert(cond, msg) |
| 50 | #endif |
| 51 | |
Jonas Ådahl | 0476974 | 2012-06-13 00:01:24 +0200 | [diff] [blame] | 52 | struct focus_state { |
| 53 | struct weston_seat *seat; |
Kristian Høgsberg | 2f5faff | 2012-07-31 16:36:34 -0400 | [diff] [blame] | 54 | struct workspace *ws; |
Jonas Ådahl | 0476974 | 2012-06-13 00:01:24 +0200 | [diff] [blame] | 55 | struct weston_surface *keyboard_focus; |
| 56 | struct wl_list link; |
| 57 | struct wl_listener seat_destroy_listener; |
| 58 | struct wl_listener surface_destroy_listener; |
| 59 | }; |
| 60 | |
Kristian Høgsberg | d2abb83 | 2011-11-23 10:52:40 -0500 | [diff] [blame] | 61 | enum shell_surface_type { |
Pekka Paalanen | 9826223 | 2011-12-01 10:42:22 +0200 | [diff] [blame] | 62 | SHELL_SURFACE_NONE, |
Kristian Høgsberg | d2abb83 | 2011-11-23 10:52:40 -0500 | [diff] [blame] | 63 | SHELL_SURFACE_TOPLEVEL, |
Tiago Vignatti | fb2adba | 2013-06-12 15:43:21 -0300 | [diff] [blame] | 64 | SHELL_SURFACE_POPUP, |
| 65 | SHELL_SURFACE_XWAYLAND |
Pekka Paalanen | 57da4a8 | 2011-11-23 16:42:16 +0200 | [diff] [blame] | 66 | }; |
| 67 | |
Jason Ekstrand | 9e9512f | 2014-04-16 21:12:10 -0500 | [diff] [blame] | 68 | struct shell_client; |
| 69 | |
Philip Withnall | 648a4dd | 2013-11-25 18:01:44 +0000 | [diff] [blame] | 70 | /* |
| 71 | * Surface stacking and ordering. |
| 72 | * |
| 73 | * This is handled using several linked lists of surfaces, organised into |
| 74 | * ‘layers’. The layers are ordered, and each of the surfaces in one layer are |
| 75 | * above all of the surfaces in the layer below. The set of layers is static and |
| 76 | * in the following order (top-most first): |
| 77 | * • Lock layer (only ever displayed on its own) |
| 78 | * • Cursor layer |
Manuel Bachmann | 805d2f5 | 2014-03-05 12:21:34 +0100 | [diff] [blame] | 79 | * • Input panel layer |
Philip Withnall | 648a4dd | 2013-11-25 18:01:44 +0000 | [diff] [blame] | 80 | * • Fullscreen layer |
| 81 | * • Panel layer |
Philip Withnall | 648a4dd | 2013-11-25 18:01:44 +0000 | [diff] [blame] | 82 | * • Workspace layers |
| 83 | * • Background layer |
| 84 | * |
| 85 | * The list of layers may be manipulated to remove whole layers of surfaces from |
| 86 | * display. For example, when locking the screen, all layers except the lock |
| 87 | * layer are removed. |
| 88 | * |
| 89 | * A surface’s layer is modified on configuring the surface, in |
| 90 | * set_surface_type() (which is only called when the surface’s type change is |
| 91 | * _committed_). If a surface’s type changes (e.g. when making a window |
| 92 | * fullscreen) its layer changes too. |
| 93 | * |
| 94 | * In order to allow popup and transient surfaces to be correctly stacked above |
| 95 | * their parent surfaces, each surface tracks both its parent surface, and a |
| 96 | * linked list of its children. When a surface’s layer is updated, so are the |
| 97 | * layers of its children. Note that child surfaces are *not* the same as |
| 98 | * subsurfaces — child/parent surfaces are purely for maintaining stacking |
| 99 | * order. |
| 100 | * |
| 101 | * The children_link list of siblings of a surface (i.e. those surfaces which |
| 102 | * have the same parent) only contains weston_surfaces which have a |
| 103 | * shell_surface. Stacking is not implemented for non-shell_surface |
| 104 | * weston_surfaces. This means that the following implication does *not* hold: |
| 105 | * (shsurf->parent != NULL) ⇒ !wl_list_is_empty(shsurf->children_link) |
| 106 | */ |
| 107 | |
Pekka Paalanen | 56cdea9 | 2011-11-23 16:14:12 +0200 | [diff] [blame] | 108 | struct shell_surface { |
Jason Ekstrand | 651f00e | 2013-06-14 10:07:54 -0500 | [diff] [blame] | 109 | struct wl_resource *resource; |
| 110 | struct wl_signal destroy_signal; |
Jason Ekstrand | 9e9512f | 2014-04-16 21:12:10 -0500 | [diff] [blame] | 111 | struct shell_client *owner; |
Jonas Ådahl | 49d77d2 | 2015-03-18 16:20:51 +0800 | [diff] [blame] | 112 | struct wl_resource *owner_resource; |
Pekka Paalanen | 9d1613e | 2011-11-25 12:09:16 +0200 | [diff] [blame] | 113 | |
Kristian Høgsberg | 8334bc1 | 2012-01-03 10:29:47 -0500 | [diff] [blame] | 114 | struct weston_surface *surface; |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 115 | struct weston_view *view; |
Jason Ekstrand | 918f2dd | 2013-12-02 21:01:53 -0600 | [diff] [blame] | 116 | int32_t last_width, last_height; |
Pekka Paalanen | 9d1613e | 2011-11-25 12:09:16 +0200 | [diff] [blame] | 117 | struct wl_listener surface_destroy_listener; |
Kristian Høgsberg | 160fe75 | 2014-03-11 10:19:10 -0700 | [diff] [blame] | 118 | struct wl_listener resource_destroy_listener; |
| 119 | |
Kristian Høgsberg | 8150b19 | 2012-06-27 10:22:58 -0400 | [diff] [blame] | 120 | struct weston_surface *parent; |
Philip Withnall | 648a4dd | 2013-11-25 18:01:44 +0000 | [diff] [blame] | 121 | struct wl_list children_list; /* child surfaces of this one */ |
| 122 | struct wl_list children_link; /* sibling surfaces of this one */ |
Tiago Vignatti | be14326 | 2012-04-16 17:31:41 +0300 | [diff] [blame] | 123 | struct desktop_shell *shell; |
Pekka Paalanen | 57da4a8 | 2011-11-23 16:42:16 +0200 | [diff] [blame] | 124 | |
Kristian Høgsberg | c8f8dd8 | 2013-12-05 23:20:33 -0800 | [diff] [blame] | 125 | enum shell_surface_type type; |
Kristian Høgsberg | e7afd91 | 2012-05-02 09:47:44 -0400 | [diff] [blame] | 126 | char *title, *class; |
Kristian Høgsberg | d2abb83 | 2011-11-23 10:52:40 -0500 | [diff] [blame] | 127 | int32_t saved_x, saved_y; |
Rafael Antognolli | 3c4e3f7 | 2013-12-03 15:35:46 -0200 | [diff] [blame] | 128 | int32_t saved_width, saved_height; |
Alex Wu | 4539b08 | 2012-03-01 12:57:46 +0800 | [diff] [blame] | 129 | bool saved_position_valid; |
Rafael Antognolli | 3c4e3f7 | 2013-12-03 15:35:46 -0200 | [diff] [blame] | 130 | bool saved_size_valid; |
Alex Wu | 7bcb8bd | 2012-04-27 09:07:24 +0800 | [diff] [blame] | 131 | bool saved_rotation_valid; |
Kristian Høgsberg | c85f1d4 | 2013-10-24 16:52:00 -0700 | [diff] [blame] | 132 | int unresponsive, grabbed; |
Kristian Høgsberg | 44cd196 | 2014-02-05 21:36:04 -0800 | [diff] [blame] | 133 | uint32_t resize_edges; |
Benjamin Franzke | d0f79ab | 2011-11-22 12:43:52 +0100 | [diff] [blame] | 134 | |
Kristian Høgsberg | b3cca0a | 2012-01-04 22:19:14 -0500 | [diff] [blame] | 135 | struct { |
Pekka Paalanen | 460099f | 2012-01-20 16:48:25 +0200 | [diff] [blame] | 136 | struct weston_transform transform; |
Kristian Høgsberg | 765e27b | 2012-01-27 13:36:13 -0500 | [diff] [blame] | 137 | struct weston_matrix rotation; |
Pekka Paalanen | 460099f | 2012-01-20 16:48:25 +0200 | [diff] [blame] | 138 | } rotation; |
| 139 | |
| 140 | struct { |
Giulio Camuffo | 5085a75 | 2013-03-25 21:42:45 +0100 | [diff] [blame] | 141 | struct wl_list grab_link; |
Kristian Høgsberg | b3cca0a | 2012-01-04 22:19:14 -0500 | [diff] [blame] | 142 | int32_t x, y; |
Giulio Camuffo | 5085a75 | 2013-03-25 21:42:45 +0100 | [diff] [blame] | 143 | struct shell_seat *shseat; |
Kristian Høgsberg | 3730f36 | 2012-04-13 12:40:07 -0400 | [diff] [blame] | 144 | uint32_t serial; |
Kristian Høgsberg | b3cca0a | 2012-01-04 22:19:14 -0500 | [diff] [blame] | 145 | } popup; |
| 146 | |
Alex Wu | 4539b08 | 2012-03-01 12:57:46 +0800 | [diff] [blame] | 147 | struct { |
Tiago Vignatti | 52e598c | 2012-05-07 15:23:08 +0300 | [diff] [blame] | 148 | int32_t x, y; |
Tiago Vignatti | 491bac1 | 2012-05-18 16:37:43 -0400 | [diff] [blame] | 149 | uint32_t flags; |
Tiago Vignatti | 52e598c | 2012-05-07 15:23:08 +0300 | [diff] [blame] | 150 | } transient; |
| 151 | |
| 152 | struct { |
Alex Wu | 4539b08 | 2012-03-01 12:57:46 +0800 | [diff] [blame] | 153 | enum wl_shell_surface_fullscreen_method type; |
| 154 | struct weston_transform transform; /* matrix from x, y */ |
| 155 | uint32_t framerate; |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 156 | struct weston_view *black_view; |
Alex Wu | 4539b08 | 2012-03-01 12:57:46 +0800 | [diff] [blame] | 157 | } fullscreen; |
| 158 | |
Jonas Ådahl | 62fcd04 | 2012-06-13 00:01:23 +0200 | [diff] [blame] | 159 | struct weston_transform workspace_transform; |
| 160 | |
Kristian Høgsberg | 1cbf326 | 2012-02-17 23:49:07 -0500 | [diff] [blame] | 161 | struct weston_output *fullscreen_output; |
Kristian Høgsberg | 8334bc1 | 2012-01-03 10:29:47 -0500 | [diff] [blame] | 162 | struct weston_output *output; |
Benjamin Franzke | d0f79ab | 2011-11-22 12:43:52 +0100 | [diff] [blame] | 163 | struct wl_list link; |
Kristian Høgsberg | a61ca06 | 2012-05-22 16:05:52 -0400 | [diff] [blame] | 164 | |
| 165 | const struct weston_shell_client *client; |
Rafael Antognolli | 03b1659 | 2013-12-03 15:35:42 -0200 | [diff] [blame] | 166 | |
Jasper St. Pierre | 6458ec3 | 2014-04-11 16:00:31 -0700 | [diff] [blame] | 167 | struct surface_state { |
Rafael Antognolli | 03b1659 | 2013-12-03 15:35:42 -0200 | [diff] [blame] | 168 | bool maximized; |
| 169 | bool fullscreen; |
Rafael Antognolli | ed207b4 | 2013-12-03 15:35:43 -0200 | [diff] [blame] | 170 | bool relative; |
Emilio Pozuelo Monfort | 9e7c759 | 2014-01-30 14:01:10 +0100 | [diff] [blame] | 171 | bool lowered; |
Jasper St. Pierre | 8c6aa45 | 2014-02-08 18:29:49 -0500 | [diff] [blame] | 172 | } state, next_state, requested_state; /* surface states */ |
Rafael Antognolli | 03b1659 | 2013-12-03 15:35:42 -0200 | [diff] [blame] | 173 | bool state_changed; |
Jasper St. Pierre | 8c6aa45 | 2014-02-08 18:29:49 -0500 | [diff] [blame] | 174 | bool state_requested; |
Jasper St. Pierre | faf27a9 | 2013-12-09 17:36:28 -0500 | [diff] [blame] | 175 | |
Kristian Høgsberg | ae356ae | 2014-04-29 16:03:54 -0700 | [diff] [blame] | 176 | struct { |
Jasper St. Pierre | ccf48fb | 2014-05-02 10:21:38 -0400 | [diff] [blame] | 177 | int32_t x, y, width, height; |
| 178 | } geometry, next_geometry; |
| 179 | bool has_set_geometry, has_next_geometry; |
Kristian Høgsberg | ae356ae | 2014-04-29 16:03:54 -0700 | [diff] [blame] | 180 | |
Jasper St. Pierre | faf27a9 | 2013-12-09 17:36:28 -0500 | [diff] [blame] | 181 | int focus_count; |
Derek Foreman | 039e9be | 2015-04-14 17:09:06 -0500 | [diff] [blame] | 182 | |
| 183 | bool destroying; |
Pekka Paalanen | 56cdea9 | 2011-11-23 16:14:12 +0200 | [diff] [blame] | 184 | }; |
| 185 | |
Ander Conselvan de Oliveira | fe0444a | 2012-04-04 17:48:05 +0300 | [diff] [blame] | 186 | struct shell_grab { |
Kristian Høgsberg | 02bbabb | 2013-05-06 22:15:05 -0400 | [diff] [blame] | 187 | struct weston_pointer_grab grab; |
Ander Conselvan de Oliveira | fe0444a | 2012-04-04 17:48:05 +0300 | [diff] [blame] | 188 | struct shell_surface *shsurf; |
| 189 | struct wl_listener shsurf_destroy_listener; |
| 190 | }; |
| 191 | |
Rusty Lynch | 1084da5 | 2013-08-15 09:10:08 -0700 | [diff] [blame] | 192 | struct shell_touch_grab { |
| 193 | struct weston_touch_grab grab; |
| 194 | struct shell_surface *shsurf; |
| 195 | struct wl_listener shsurf_destroy_listener; |
| 196 | struct weston_touch *touch; |
| 197 | }; |
| 198 | |
Ander Conselvan de Oliveira | fe0444a | 2012-04-04 17:48:05 +0300 | [diff] [blame] | 199 | struct weston_move_grab { |
| 200 | struct shell_grab base; |
Daniel Stone | 103db7f | 2012-05-08 17:17:55 +0100 | [diff] [blame] | 201 | wl_fixed_t dx, dy; |
Derek Foreman | cf7d95a | 2015-06-03 15:53:22 -0500 | [diff] [blame] | 202 | bool client_initiated; |
Kristian Høgsberg | 4cca349 | 2011-01-18 07:53:49 -0500 | [diff] [blame] | 203 | }; |
| 204 | |
Rusty Lynch | 1084da5 | 2013-08-15 09:10:08 -0700 | [diff] [blame] | 205 | struct weston_touch_move_grab { |
| 206 | struct shell_touch_grab base; |
Kristian Høgsberg | 8e80a31 | 2014-01-17 15:18:10 -0800 | [diff] [blame] | 207 | int active; |
Rusty Lynch | 1084da5 | 2013-08-15 09:10:08 -0700 | [diff] [blame] | 208 | wl_fixed_t dx, dy; |
| 209 | }; |
| 210 | |
Pekka Paalanen | 460099f | 2012-01-20 16:48:25 +0200 | [diff] [blame] | 211 | struct rotate_grab { |
Ander Conselvan de Oliveira | fe0444a | 2012-04-04 17:48:05 +0300 | [diff] [blame] | 212 | struct shell_grab base; |
Kristian Høgsberg | 765e27b | 2012-01-27 13:36:13 -0500 | [diff] [blame] | 213 | struct weston_matrix rotation; |
Pekka Paalanen | 460099f | 2012-01-20 16:48:25 +0200 | [diff] [blame] | 214 | struct { |
John Kåre Alsaker | 490d02a | 2012-09-30 02:57:21 +0200 | [diff] [blame] | 215 | float x; |
| 216 | float y; |
Pekka Paalanen | 460099f | 2012-01-20 16:48:25 +0200 | [diff] [blame] | 217 | } center; |
| 218 | }; |
| 219 | |
Giulio Camuffo | 5085a75 | 2013-03-25 21:42:45 +0100 | [diff] [blame] | 220 | struct shell_seat { |
| 221 | struct weston_seat *seat; |
| 222 | struct wl_listener seat_destroy_listener; |
Jasper St. Pierre | faf27a9 | 2013-12-09 17:36:28 -0500 | [diff] [blame] | 223 | struct weston_surface *focused_surface; |
Giulio Camuffo | 5085a75 | 2013-03-25 21:42:45 +0100 | [diff] [blame] | 224 | |
Jason Ekstrand | 024177c | 2014-04-21 19:42:58 -0500 | [diff] [blame] | 225 | struct wl_listener caps_changed_listener; |
| 226 | struct wl_listener pointer_focus_listener; |
| 227 | struct wl_listener keyboard_focus_listener; |
| 228 | |
Giulio Camuffo | 5085a75 | 2013-03-25 21:42:45 +0100 | [diff] [blame] | 229 | struct { |
Kristian Høgsberg | 02bbabb | 2013-05-06 22:15:05 -0400 | [diff] [blame] | 230 | struct weston_pointer_grab grab; |
Jonny Lamb | 76cf1fe | 2014-08-20 11:27:10 +0200 | [diff] [blame] | 231 | struct weston_touch_grab touch_grab; |
Giulio Camuffo | 5085a75 | 2013-03-25 21:42:45 +0100 | [diff] [blame] | 232 | struct wl_list surfaces_list; |
| 233 | struct wl_client *client; |
| 234 | int32_t initial_up; |
Jonny Lamb | 76cf1fe | 2014-08-20 11:27:10 +0200 | [diff] [blame] | 235 | enum { POINTER, TOUCH } type; |
Giulio Camuffo | 5085a75 | 2013-03-25 21:42:45 +0100 | [diff] [blame] | 236 | } popup_grab; |
| 237 | }; |
| 238 | |
Kristian Høgsberg | 2bff94e | 2014-02-11 12:22:51 -0800 | [diff] [blame] | 239 | struct shell_client { |
| 240 | struct wl_resource *resource; |
| 241 | struct wl_client *client; |
| 242 | struct desktop_shell *shell; |
| 243 | struct wl_listener destroy_listener; |
| 244 | struct wl_event_source *ping_timer; |
| 245 | uint32_t ping_serial; |
| 246 | int unresponsive; |
Jonas Ådahl | 49d77d2 | 2015-03-18 16:20:51 +0800 | [diff] [blame] | 247 | struct wl_list surface_list; |
Kristian Høgsberg | 2bff94e | 2014-02-11 12:22:51 -0800 | [diff] [blame] | 248 | }; |
| 249 | |
Alex Wu | bd3354b | 2012-04-17 17:20:49 +0800 | [diff] [blame] | 250 | static struct desktop_shell * |
| 251 | shell_surface_get_shell(struct shell_surface *shsurf); |
| 252 | |
Kristian Høgsberg | 0c36903 | 2013-02-14 21:31:44 -0500 | [diff] [blame] | 253 | static void |
Derek Foreman | 74de469 | 2015-07-15 13:00:39 -0500 | [diff] [blame] | 254 | surface_rotate(struct shell_surface *surface, struct weston_pointer *pointer); |
Kristian Høgsberg | 0c36903 | 2013-02-14 21:31:44 -0500 | [diff] [blame] | 255 | |
Pekka Paalanen | 79346ab | 2013-05-22 18:03:09 +0300 | [diff] [blame] | 256 | static void |
| 257 | shell_fade_startup(struct desktop_shell *shell); |
| 258 | |
Philip Withnall | becb77e | 2013-11-25 18:01:30 +0000 | [diff] [blame] | 259 | static struct shell_seat * |
| 260 | get_shell_seat(struct weston_seat *seat); |
| 261 | |
Jonny Lamb | d73c694 | 2014-08-20 15:53:20 +0200 | [diff] [blame] | 262 | static void |
| 263 | get_output_panel_size(struct desktop_shell *shell, |
| 264 | struct weston_output *output, |
| 265 | int *width, int *height); |
Kristian Høgsberg | ae356ae | 2014-04-29 16:03:54 -0700 | [diff] [blame] | 266 | |
Philip Withnall | 648a4dd | 2013-11-25 18:01:44 +0000 | [diff] [blame] | 267 | static void |
| 268 | shell_surface_update_child_surface_layers(struct shell_surface *shsurf); |
| 269 | |
Alex Wu | bd3354b | 2012-04-17 17:20:49 +0800 | [diff] [blame] | 270 | static bool |
Rafael Antognolli | e2a3455 | 2013-12-03 15:35:45 -0200 | [diff] [blame] | 271 | shell_surface_is_wl_shell_surface(struct shell_surface *shsurf); |
| 272 | |
| 273 | static bool |
| 274 | shell_surface_is_xdg_surface(struct shell_surface *shsurf); |
| 275 | |
| 276 | static bool |
| 277 | shell_surface_is_xdg_popup(struct shell_surface *shsurf); |
| 278 | |
| 279 | static void |
| 280 | shell_surface_set_parent(struct shell_surface *shsurf, |
| 281 | struct weston_surface *parent); |
| 282 | |
Pekka Paalanen | 8274d90 | 2014-08-06 19:36:51 +0300 | [diff] [blame] | 283 | static int |
| 284 | shell_surface_get_label(struct weston_surface *surface, char *buf, size_t len) |
| 285 | { |
| 286 | struct shell_surface *shsurf; |
| 287 | const char *typestr[] = { |
| 288 | [SHELL_SURFACE_NONE] = "unidentified", |
| 289 | [SHELL_SURFACE_TOPLEVEL] = "top-level", |
| 290 | [SHELL_SURFACE_POPUP] = "popup", |
| 291 | [SHELL_SURFACE_XWAYLAND] = "Xwayland", |
| 292 | }; |
| 293 | const char *t, *c; |
| 294 | |
| 295 | shsurf = get_shell_surface(surface); |
| 296 | if (!shsurf) |
| 297 | return snprintf(buf, len, "unidentified window"); |
| 298 | |
| 299 | t = shsurf->title; |
| 300 | c = shsurf->class; |
| 301 | |
| 302 | return snprintf(buf, len, "%s window%s%s%s%s%s", |
| 303 | typestr[shsurf->type], |
| 304 | t ? " '" : "", t ?: "", t ? "'" : "", |
| 305 | c ? " of " : "", c ?: ""); |
| 306 | } |
| 307 | |
Rafael Antognolli | e2a3455 | 2013-12-03 15:35:45 -0200 | [diff] [blame] | 308 | static bool |
Alex Wu | bd3354b | 2012-04-17 17:20:49 +0800 | [diff] [blame] | 309 | shell_surface_is_top_fullscreen(struct shell_surface *shsurf) |
| 310 | { |
| 311 | struct desktop_shell *shell; |
Mario Kleiner | 9f4d655 | 2015-06-21 21:25:08 +0200 | [diff] [blame] | 312 | struct weston_view *view; |
| 313 | struct shell_surface *top_fs_shsurf = NULL; |
Alex Wu | bd3354b | 2012-04-17 17:20:49 +0800 | [diff] [blame] | 314 | |
| 315 | shell = shell_surface_get_shell(shsurf); |
Quentin Glidic | c0d79ce | 2013-01-29 14:16:13 +0100 | [diff] [blame] | 316 | |
Giulio Camuffo | 412e6a5 | 2014-07-09 22:12:56 +0300 | [diff] [blame] | 317 | if (wl_list_empty(&shell->fullscreen_layer.view_list.link)) |
Alex Wu | bd3354b | 2012-04-17 17:20:49 +0800 | [diff] [blame] | 318 | return false; |
| 319 | |
Mario Kleiner | 9f4d655 | 2015-06-21 21:25:08 +0200 | [diff] [blame] | 320 | /* Find topmost shsurf on the same fullscreen output on which shsurf |
| 321 | * is displaying. We don't care about other outputs. |
| 322 | */ |
| 323 | wl_list_for_each(view, &shell->fullscreen_layer.view_list.link, |
| 324 | layer_link.link) { |
| 325 | struct shell_surface *cand_shsurf = get_shell_surface(view->surface); |
| 326 | |
| 327 | if (cand_shsurf && |
| 328 | (cand_shsurf->fullscreen_output == shsurf->fullscreen_output)) { |
| 329 | top_fs_shsurf = cand_shsurf; |
| 330 | break; |
| 331 | } |
| 332 | } |
| 333 | |
| 334 | return (shsurf == top_fs_shsurf); |
Alex Wu | bd3354b | 2012-04-17 17:20:49 +0800 | [diff] [blame] | 335 | } |
| 336 | |
Kristian Høgsberg | 6af8eb9 | 2012-01-25 16:57:11 -0500 | [diff] [blame] | 337 | static void |
Kristian Høgsberg | 27e3052 | 2012-04-11 23:18:23 -0400 | [diff] [blame] | 338 | destroy_shell_grab_shsurf(struct wl_listener *listener, void *data) |
Ander Conselvan de Oliveira | fe0444a | 2012-04-04 17:48:05 +0300 | [diff] [blame] | 339 | { |
| 340 | struct shell_grab *grab; |
| 341 | |
| 342 | grab = container_of(listener, struct shell_grab, |
| 343 | shsurf_destroy_listener); |
| 344 | |
| 345 | grab->shsurf = NULL; |
| 346 | } |
| 347 | |
Kristian Høgsberg | 1ef2313 | 2013-12-04 00:20:01 -0800 | [diff] [blame] | 348 | struct weston_view * |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 349 | get_default_view(struct weston_surface *surface) |
| 350 | { |
| 351 | struct shell_surface *shsurf; |
| 352 | struct weston_view *view; |
| 353 | |
| 354 | if (!surface || wl_list_empty(&surface->views)) |
| 355 | return NULL; |
| 356 | |
| 357 | shsurf = get_shell_surface(surface); |
| 358 | if (shsurf) |
| 359 | return shsurf->view; |
| 360 | |
| 361 | wl_list_for_each(view, &surface->views, surface_link) |
| 362 | if (weston_view_is_mapped(view)) |
| 363 | return view; |
| 364 | |
| 365 | return container_of(surface->views.next, struct weston_view, surface_link); |
| 366 | } |
| 367 | |
Ander Conselvan de Oliveira | fe0444a | 2012-04-04 17:48:05 +0300 | [diff] [blame] | 368 | static void |
Kristian Høgsberg | 02bbabb | 2013-05-06 22:15:05 -0400 | [diff] [blame] | 369 | popup_grab_end(struct weston_pointer *pointer); |
Jonny Lamb | 76cf1fe | 2014-08-20 11:27:10 +0200 | [diff] [blame] | 370 | static void |
| 371 | touch_popup_grab_end(struct weston_touch *touch); |
Kristian Høgsberg | 57e0907 | 2012-10-30 14:07:27 -0400 | [diff] [blame] | 372 | |
| 373 | static void |
Ander Conselvan de Oliveira | b9d2a0f | 2012-06-28 18:08:05 +0300 | [diff] [blame] | 374 | shell_grab_start(struct shell_grab *grab, |
Kristian Høgsberg | 02bbabb | 2013-05-06 22:15:05 -0400 | [diff] [blame] | 375 | const struct weston_pointer_grab_interface *interface, |
Ander Conselvan de Oliveira | b9d2a0f | 2012-06-28 18:08:05 +0300 | [diff] [blame] | 376 | struct shell_surface *shsurf, |
Kristian Høgsberg | 02bbabb | 2013-05-06 22:15:05 -0400 | [diff] [blame] | 377 | struct weston_pointer *pointer, |
Ander Conselvan de Oliveira | b9d2a0f | 2012-06-28 18:08:05 +0300 | [diff] [blame] | 378 | enum desktop_shell_cursor cursor) |
Ander Conselvan de Oliveira | fe0444a | 2012-04-04 17:48:05 +0300 | [diff] [blame] | 379 | { |
Ander Conselvan de Oliveira | b9d2a0f | 2012-06-28 18:08:05 +0300 | [diff] [blame] | 380 | struct desktop_shell *shell = shsurf->shell; |
Derek Foreman | 1281a36 | 2015-07-31 16:55:32 -0500 | [diff] [blame] | 381 | struct weston_touch *touch = weston_seat_get_touch(pointer->seat); |
Ander Conselvan de Oliveira | b9d2a0f | 2012-06-28 18:08:05 +0300 | [diff] [blame] | 382 | |
Kristian Høgsberg | 57e0907 | 2012-10-30 14:07:27 -0400 | [diff] [blame] | 383 | popup_grab_end(pointer); |
Derek Foreman | 1281a36 | 2015-07-31 16:55:32 -0500 | [diff] [blame] | 384 | if (touch) |
| 385 | touch_popup_grab_end(touch); |
Kristian Høgsberg | 57e0907 | 2012-10-30 14:07:27 -0400 | [diff] [blame] | 386 | |
Ander Conselvan de Oliveira | fe0444a | 2012-04-04 17:48:05 +0300 | [diff] [blame] | 387 | grab->grab.interface = interface; |
| 388 | grab->shsurf = shsurf; |
Kristian Høgsberg | 27e3052 | 2012-04-11 23:18:23 -0400 | [diff] [blame] | 389 | grab->shsurf_destroy_listener.notify = destroy_shell_grab_shsurf; |
Jason Ekstrand | 651f00e | 2013-06-14 10:07:54 -0500 | [diff] [blame] | 390 | wl_signal_add(&shsurf->destroy_signal, |
Kristian Høgsberg | 27e3052 | 2012-04-11 23:18:23 -0400 | [diff] [blame] | 391 | &grab->shsurf_destroy_listener); |
Ander Conselvan de Oliveira | fe0444a | 2012-04-04 17:48:05 +0300 | [diff] [blame] | 392 | |
Kristian Høgsberg | c85f1d4 | 2013-10-24 16:52:00 -0700 | [diff] [blame] | 393 | shsurf->grabbed = 1; |
Kristian Høgsberg | 02bbabb | 2013-05-06 22:15:05 -0400 | [diff] [blame] | 394 | weston_pointer_start_grab(pointer, &grab->grab); |
Kristian Høgsberg | c9974a0 | 2013-07-03 19:24:57 -0400 | [diff] [blame] | 395 | if (shell->child.desktop_shell) { |
| 396 | desktop_shell_send_grab_cursor(shell->child.desktop_shell, |
| 397 | cursor); |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 398 | weston_pointer_set_focus(pointer, |
| 399 | get_default_view(shell->grab_surface), |
Kristian Høgsberg | c9974a0 | 2013-07-03 19:24:57 -0400 | [diff] [blame] | 400 | wl_fixed_from_int(0), |
| 401 | wl_fixed_from_int(0)); |
| 402 | } |
Ander Conselvan de Oliveira | fe0444a | 2012-04-04 17:48:05 +0300 | [diff] [blame] | 403 | } |
| 404 | |
Jonny Lamb | d73c694 | 2014-08-20 15:53:20 +0200 | [diff] [blame] | 405 | static void |
| 406 | get_output_panel_size(struct desktop_shell *shell, |
| 407 | struct weston_output *output, |
| 408 | int *width, |
| 409 | int *height) |
Jasper St. Pierre | 6458ec3 | 2014-04-11 16:00:31 -0700 | [diff] [blame] | 410 | { |
| 411 | struct weston_view *view; |
Jonny Lamb | d73c694 | 2014-08-20 15:53:20 +0200 | [diff] [blame] | 412 | |
| 413 | *width = 0; |
| 414 | *height = 0; |
Jasper St. Pierre | 6458ec3 | 2014-04-11 16:00:31 -0700 | [diff] [blame] | 415 | |
| 416 | if (!output) |
Jonny Lamb | d73c694 | 2014-08-20 15:53:20 +0200 | [diff] [blame] | 417 | return; |
Jasper St. Pierre | 6458ec3 | 2014-04-11 16:00:31 -0700 | [diff] [blame] | 418 | |
Giulio Camuffo | 412e6a5 | 2014-07-09 22:12:56 +0300 | [diff] [blame] | 419 | wl_list_for_each(view, &shell->panel_layer.view_list.link, layer_link.link) { |
Jonny Lamb | d73c694 | 2014-08-20 15:53:20 +0200 | [diff] [blame] | 420 | float x, y; |
| 421 | |
| 422 | if (view->surface->output != output) |
| 423 | continue; |
| 424 | |
| 425 | switch (shell->panel_position) { |
| 426 | case DESKTOP_SHELL_PANEL_POSITION_TOP: |
| 427 | case DESKTOP_SHELL_PANEL_POSITION_BOTTOM: |
Jonny Lamb | d73c694 | 2014-08-20 15:53:20 +0200 | [diff] [blame] | 428 | weston_view_to_global_float(view, |
| 429 | view->surface->width, 0, |
| 430 | &x, &y); |
| 431 | |
Derek Foreman | 612341f | 2015-04-15 12:23:55 -0500 | [diff] [blame] | 432 | *width = (int)x - output->x; |
| 433 | *height = view->surface->height + (int) y - output->y; |
Jonny Lamb | d73c694 | 2014-08-20 15:53:20 +0200 | [diff] [blame] | 434 | return; |
| 435 | |
| 436 | case DESKTOP_SHELL_PANEL_POSITION_LEFT: |
| 437 | case DESKTOP_SHELL_PANEL_POSITION_RIGHT: |
| 438 | weston_view_to_global_float(view, |
| 439 | 0, view->surface->height, |
| 440 | &x, &y); |
| 441 | |
Derek Foreman | 612341f | 2015-04-15 12:23:55 -0500 | [diff] [blame] | 442 | *width = view->surface->width + (int)x - output->x; |
| 443 | *height = (int)y - output->y; |
Jonny Lamb | d73c694 | 2014-08-20 15:53:20 +0200 | [diff] [blame] | 444 | return; |
| 445 | |
| 446 | default: |
| 447 | /* we've already set width and height to |
| 448 | * fallback values. */ |
Jasper St. Pierre | 6458ec3 | 2014-04-11 16:00:31 -0700 | [diff] [blame] | 449 | break; |
| 450 | } |
| 451 | } |
| 452 | |
Jonny Lamb | d73c694 | 2014-08-20 15:53:20 +0200 | [diff] [blame] | 453 | /* the correct view wasn't found */ |
| 454 | } |
| 455 | |
| 456 | static void |
| 457 | get_output_work_area(struct desktop_shell *shell, |
| 458 | struct weston_output *output, |
| 459 | pixman_rectangle32_t *area) |
| 460 | { |
| 461 | int32_t panel_width = 0, panel_height = 0; |
| 462 | |
Derek Foreman | f814c5d | 2015-04-15 12:23:54 -0500 | [diff] [blame] | 463 | area->x = output->x; |
| 464 | area->y = output->y; |
Jonny Lamb | d73c694 | 2014-08-20 15:53:20 +0200 | [diff] [blame] | 465 | |
| 466 | get_output_panel_size(shell, output, &panel_width, &panel_height); |
Jonny Lamb | d73c694 | 2014-08-20 15:53:20 +0200 | [diff] [blame] | 467 | switch (shell->panel_position) { |
| 468 | case DESKTOP_SHELL_PANEL_POSITION_TOP: |
| 469 | default: |
Derek Foreman | f814c5d | 2015-04-15 12:23:54 -0500 | [diff] [blame] | 470 | area->y += panel_height; |
Jonny Lamb | d73c694 | 2014-08-20 15:53:20 +0200 | [diff] [blame] | 471 | case DESKTOP_SHELL_PANEL_POSITION_BOTTOM: |
| 472 | area->width = output->width; |
| 473 | area->height = output->height - panel_height; |
| 474 | break; |
| 475 | case DESKTOP_SHELL_PANEL_POSITION_LEFT: |
Derek Foreman | f814c5d | 2015-04-15 12:23:54 -0500 | [diff] [blame] | 476 | area->x += panel_width; |
Jonny Lamb | d73c694 | 2014-08-20 15:53:20 +0200 | [diff] [blame] | 477 | case DESKTOP_SHELL_PANEL_POSITION_RIGHT: |
| 478 | area->width = output->width - panel_width; |
| 479 | area->height = output->height; |
| 480 | break; |
| 481 | } |
Jasper St. Pierre | 6458ec3 | 2014-04-11 16:00:31 -0700 | [diff] [blame] | 482 | } |
| 483 | |
| 484 | static void |
| 485 | send_configure_for_surface(struct shell_surface *shsurf) |
| 486 | { |
| 487 | int32_t width, height; |
| 488 | struct surface_state *state; |
| 489 | |
| 490 | if (shsurf->state_requested) |
| 491 | state = &shsurf->requested_state; |
| 492 | else if (shsurf->state_changed) |
| 493 | state = &shsurf->next_state; |
| 494 | else |
| 495 | state = &shsurf->state; |
| 496 | |
| 497 | if (state->fullscreen) { |
| 498 | width = shsurf->output->width; |
| 499 | height = shsurf->output->height; |
| 500 | } else if (state->maximized) { |
| 501 | struct desktop_shell *shell; |
Jonny Lamb | d73c694 | 2014-08-20 15:53:20 +0200 | [diff] [blame] | 502 | pixman_rectangle32_t area; |
Jasper St. Pierre | 6458ec3 | 2014-04-11 16:00:31 -0700 | [diff] [blame] | 503 | |
| 504 | shell = shell_surface_get_shell(shsurf); |
Jonny Lamb | d73c694 | 2014-08-20 15:53:20 +0200 | [diff] [blame] | 505 | get_output_work_area(shell, shsurf->output, &area); |
Jasper St. Pierre | 6458ec3 | 2014-04-11 16:00:31 -0700 | [diff] [blame] | 506 | |
Jonny Lamb | d73c694 | 2014-08-20 15:53:20 +0200 | [diff] [blame] | 507 | width = area.width; |
| 508 | height = area.height; |
Ryo Munakata | 79954ec | 2015-05-02 21:44:04 +0900 | [diff] [blame] | 509 | } else if (shsurf->resize_edges) { |
| 510 | width = shsurf->geometry.width; |
| 511 | height = shsurf->geometry.height; |
Jasper St. Pierre | 6458ec3 | 2014-04-11 16:00:31 -0700 | [diff] [blame] | 512 | } else { |
| 513 | width = 0; |
| 514 | height = 0; |
| 515 | } |
| 516 | |
| 517 | shsurf->client->send_configure(shsurf->surface, width, height); |
| 518 | } |
| 519 | |
Ander Conselvan de Oliveira | fe0444a | 2012-04-04 17:48:05 +0300 | [diff] [blame] | 520 | static void |
Jasper St. Pierre | 5befdda | 2014-05-06 08:50:47 -0400 | [diff] [blame] | 521 | shell_surface_state_changed(struct shell_surface *shsurf) |
| 522 | { |
Jasper St. Pierre | 6458ec3 | 2014-04-11 16:00:31 -0700 | [diff] [blame] | 523 | if (shell_surface_is_xdg_surface(shsurf)) |
| 524 | send_configure_for_surface(shsurf); |
Jasper St. Pierre | 5befdda | 2014-05-06 08:50:47 -0400 | [diff] [blame] | 525 | } |
| 526 | |
| 527 | static void |
Ander Conselvan de Oliveira | b9d2a0f | 2012-06-28 18:08:05 +0300 | [diff] [blame] | 528 | shell_grab_end(struct shell_grab *grab) |
Ander Conselvan de Oliveira | fe0444a | 2012-04-04 17:48:05 +0300 | [diff] [blame] | 529 | { |
Kristian Høgsberg | c85f1d4 | 2013-10-24 16:52:00 -0700 | [diff] [blame] | 530 | if (grab->shsurf) { |
Kristian Høgsberg | 47b5dca | 2012-06-07 18:08:04 -0400 | [diff] [blame] | 531 | wl_list_remove(&grab->shsurf_destroy_listener.link); |
Kristian Høgsberg | c85f1d4 | 2013-10-24 16:52:00 -0700 | [diff] [blame] | 532 | grab->shsurf->grabbed = 0; |
Jasper St. Pierre | 5befdda | 2014-05-06 08:50:47 -0400 | [diff] [blame] | 533 | |
| 534 | if (grab->shsurf->resize_edges) { |
| 535 | grab->shsurf->resize_edges = 0; |
| 536 | shell_surface_state_changed(grab->shsurf); |
| 537 | } |
Kristian Høgsberg | c85f1d4 | 2013-10-24 16:52:00 -0700 | [diff] [blame] | 538 | } |
Ander Conselvan de Oliveira | b9d2a0f | 2012-06-28 18:08:05 +0300 | [diff] [blame] | 539 | |
Kristian Høgsberg | 9e5d7d1 | 2013-07-22 16:31:53 -0700 | [diff] [blame] | 540 | weston_pointer_end_grab(grab->grab.pointer); |
Ander Conselvan de Oliveira | fe0444a | 2012-04-04 17:48:05 +0300 | [diff] [blame] | 541 | } |
| 542 | |
| 543 | static void |
Rusty Lynch | 1084da5 | 2013-08-15 09:10:08 -0700 | [diff] [blame] | 544 | shell_touch_grab_start(struct shell_touch_grab *grab, |
| 545 | const struct weston_touch_grab_interface *interface, |
| 546 | struct shell_surface *shsurf, |
| 547 | struct weston_touch *touch) |
| 548 | { |
| 549 | struct desktop_shell *shell = shsurf->shell; |
Derek Foreman | 1281a36 | 2015-07-31 16:55:32 -0500 | [diff] [blame] | 550 | struct weston_pointer *pointer = weston_seat_get_pointer(touch->seat); |
U. Artie Eoff | cf5737a | 2014-01-17 10:08:25 -0800 | [diff] [blame] | 551 | |
Jonny Lamb | 76cf1fe | 2014-08-20 11:27:10 +0200 | [diff] [blame] | 552 | touch_popup_grab_end(touch); |
Derek Foreman | 1281a36 | 2015-07-31 16:55:32 -0500 | [diff] [blame] | 553 | if (pointer) |
| 554 | popup_grab_end(pointer); |
Kristian Høgsberg | 74071e0 | 2014-04-29 15:01:16 -0700 | [diff] [blame] | 555 | |
Rusty Lynch | 1084da5 | 2013-08-15 09:10:08 -0700 | [diff] [blame] | 556 | grab->grab.interface = interface; |
| 557 | grab->shsurf = shsurf; |
| 558 | grab->shsurf_destroy_listener.notify = destroy_shell_grab_shsurf; |
| 559 | wl_signal_add(&shsurf->destroy_signal, |
| 560 | &grab->shsurf_destroy_listener); |
| 561 | |
| 562 | grab->touch = touch; |
Kristian Høgsberg | c85f1d4 | 2013-10-24 16:52:00 -0700 | [diff] [blame] | 563 | shsurf->grabbed = 1; |
Rusty Lynch | 1084da5 | 2013-08-15 09:10:08 -0700 | [diff] [blame] | 564 | |
| 565 | weston_touch_start_grab(touch, &grab->grab); |
| 566 | if (shell->child.desktop_shell) |
Derek Foreman | 4c93c08 | 2015-04-30 16:45:41 -0500 | [diff] [blame] | 567 | weston_touch_set_focus(touch, |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 568 | get_default_view(shell->grab_surface)); |
Rusty Lynch | 1084da5 | 2013-08-15 09:10:08 -0700 | [diff] [blame] | 569 | } |
| 570 | |
| 571 | static void |
| 572 | shell_touch_grab_end(struct shell_touch_grab *grab) |
| 573 | { |
Kristian Høgsberg | c85f1d4 | 2013-10-24 16:52:00 -0700 | [diff] [blame] | 574 | if (grab->shsurf) { |
Rusty Lynch | 1084da5 | 2013-08-15 09:10:08 -0700 | [diff] [blame] | 575 | wl_list_remove(&grab->shsurf_destroy_listener.link); |
Kristian Høgsberg | c85f1d4 | 2013-10-24 16:52:00 -0700 | [diff] [blame] | 576 | grab->shsurf->grabbed = 0; |
| 577 | } |
Rusty Lynch | 1084da5 | 2013-08-15 09:10:08 -0700 | [diff] [blame] | 578 | |
| 579 | weston_touch_end_grab(grab->touch); |
| 580 | } |
| 581 | |
| 582 | static void |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 583 | center_on_output(struct weston_view *view, |
Alex Wu | 4539b08 | 2012-03-01 12:57:46 +0800 | [diff] [blame] | 584 | struct weston_output *output); |
| 585 | |
Daniel Stone | 496ca17 | 2012-05-30 16:31:42 +0100 | [diff] [blame] | 586 | static enum weston_keyboard_modifier |
Tiago Vignatti | 0b52d48 | 2012-04-20 18:54:25 +0300 | [diff] [blame] | 587 | get_modifier(char *modifier) |
| 588 | { |
| 589 | if (!modifier) |
| 590 | return MODIFIER_SUPER; |
| 591 | |
| 592 | if (!strcmp("ctrl", modifier)) |
| 593 | return MODIFIER_CTRL; |
| 594 | else if (!strcmp("alt", modifier)) |
| 595 | return MODIFIER_ALT; |
| 596 | else if (!strcmp("super", modifier)) |
| 597 | return MODIFIER_SUPER; |
| 598 | else |
| 599 | return MODIFIER_SUPER; |
| 600 | } |
| 601 | |
Juan Zhao | e10d279 | 2012-04-25 19:09:52 +0800 | [diff] [blame] | 602 | static enum animation_type |
| 603 | get_animation_type(char *animation) |
| 604 | { |
U. Artie Eoff | b571910 | 2014-01-15 14:26:31 -0800 | [diff] [blame] | 605 | if (!animation) |
| 606 | return ANIMATION_NONE; |
| 607 | |
Juan Zhao | e10d279 | 2012-04-25 19:09:52 +0800 | [diff] [blame] | 608 | if (!strcmp("zoom", animation)) |
| 609 | return ANIMATION_ZOOM; |
| 610 | else if (!strcmp("fade", animation)) |
| 611 | return ANIMATION_FADE; |
Louis-Francis Ratté-Boulianne | b482dbd | 2013-11-19 11:37:11 +0100 | [diff] [blame] | 612 | else if (!strcmp("dim-layer", animation)) |
| 613 | return ANIMATION_DIM_LAYER; |
Juan Zhao | e10d279 | 2012-04-25 19:09:52 +0800 | [diff] [blame] | 614 | else |
| 615 | return ANIMATION_NONE; |
| 616 | } |
| 617 | |
Alex Wu | 4539b08 | 2012-03-01 12:57:46 +0800 | [diff] [blame] | 618 | static void |
Kristian Høgsberg | 14e438c | 2013-05-26 21:48:14 -0400 | [diff] [blame] | 619 | shell_configuration(struct desktop_shell *shell) |
Pekka Paalanen | e955f1e | 2011-12-07 11:49:52 +0200 | [diff] [blame] | 620 | { |
Kristian Høgsberg | 673a889 | 2013-05-23 21:40:56 -0400 | [diff] [blame] | 621 | struct weston_config_section *section; |
Derek Foreman | c721043 | 2014-08-21 11:32:38 -0500 | [diff] [blame] | 622 | char *s, *client; |
Pekka Paalanen | 974c094 | 2014-09-05 14:45:09 +0300 | [diff] [blame] | 623 | int ret; |
Pekka Paalanen | e955f1e | 2011-12-07 11:49:52 +0200 | [diff] [blame] | 624 | |
Kristian Høgsberg | 673a889 | 2013-05-23 21:40:56 -0400 | [diff] [blame] | 625 | section = weston_config_get_section(shell->compositor->config, |
Kristian Høgsberg | 673a889 | 2013-05-23 21:40:56 -0400 | [diff] [blame] | 626 | "shell", NULL, NULL); |
Pekka Paalanen | 974c094 | 2014-09-05 14:45:09 +0300 | [diff] [blame] | 627 | ret = asprintf(&client, "%s/%s", weston_config_get_libexec_dir(), |
| 628 | WESTON_SHELL_CLIENT); |
| 629 | if (ret < 0) |
| 630 | client = NULL; |
Kristian Høgsberg | 673a889 | 2013-05-23 21:40:56 -0400 | [diff] [blame] | 631 | weston_config_section_get_string(section, |
Derek Foreman | c721043 | 2014-08-21 11:32:38 -0500 | [diff] [blame] | 632 | "client", &s, client); |
| 633 | free(client); |
Emilio Pozuelo Monfort | 46ce798 | 2013-11-20 13:22:29 +0100 | [diff] [blame] | 634 | shell->client = s; |
| 635 | weston_config_section_get_string(section, |
Kristian Høgsberg | 673a889 | 2013-05-23 21:40:56 -0400 | [diff] [blame] | 636 | "binding-modifier", &s, "super"); |
| 637 | shell->binding_modifier = get_modifier(s); |
Quentin Glidic | 8418c29 | 2013-06-18 09:11:03 +0200 | [diff] [blame] | 638 | free(s); |
Kristian Høgsberg | d56ab4e | 2014-01-16 16:51:52 -0800 | [diff] [blame] | 639 | |
| 640 | weston_config_section_get_string(section, |
| 641 | "exposay-modifier", &s, "none"); |
| 642 | if (strcmp(s, "none") == 0) |
| 643 | shell->exposay_modifier = 0; |
| 644 | else |
| 645 | shell->exposay_modifier = get_modifier(s); |
| 646 | free(s); |
| 647 | |
Kristian Høgsberg | 673a889 | 2013-05-23 21:40:56 -0400 | [diff] [blame] | 648 | weston_config_section_get_string(section, "animation", &s, "none"); |
| 649 | shell->win_animation_type = get_animation_type(s); |
Quentin Glidic | 8418c29 | 2013-06-18 09:11:03 +0200 | [diff] [blame] | 650 | free(s); |
Jonny Lamb | f322f8e | 2014-08-12 15:13:30 +0200 | [diff] [blame] | 651 | weston_config_section_get_string(section, "close-animation", &s, "fade"); |
| 652 | shell->win_close_animation_type = get_animation_type(s); |
| 653 | free(s); |
Kristian Høgsberg | 724c8d9 | 2013-10-16 11:38:24 -0700 | [diff] [blame] | 654 | weston_config_section_get_string(section, |
| 655 | "startup-animation", &s, "fade"); |
| 656 | shell->startup_animation_type = get_animation_type(s); |
| 657 | free(s); |
Kristian Høgsberg | 912e0a1 | 2013-10-30 08:59:55 -0700 | [diff] [blame] | 658 | if (shell->startup_animation_type == ANIMATION_ZOOM) |
| 659 | shell->startup_animation_type = ANIMATION_NONE; |
Louis-Francis Ratté-Boulianne | b482dbd | 2013-11-19 11:37:11 +0100 | [diff] [blame] | 660 | weston_config_section_get_string(section, "focus-animation", &s, "none"); |
| 661 | shell->focus_animation_type = get_animation_type(s); |
| 662 | free(s); |
Kristian Høgsberg | 673a889 | 2013-05-23 21:40:56 -0400 | [diff] [blame] | 663 | weston_config_section_get_uint(section, "num-workspaces", |
| 664 | &shell->workspaces.num, |
| 665 | DEFAULT_NUM_WORKSPACES); |
Jonas Ådahl | e3cddce | 2012-06-13 00:01:22 +0200 | [diff] [blame] | 666 | } |
| 667 | |
Kristian Høgsberg | 1ef2313 | 2013-12-04 00:20:01 -0800 | [diff] [blame] | 668 | struct weston_output * |
Louis-Francis Ratté-Boulianne | b482dbd | 2013-11-19 11:37:11 +0100 | [diff] [blame] | 669 | get_default_output(struct weston_compositor *compositor) |
| 670 | { |
| 671 | return container_of(compositor->output_list.next, |
| 672 | struct weston_output, link); |
| 673 | } |
| 674 | |
Pekka Paalanen | 8274d90 | 2014-08-06 19:36:51 +0300 | [diff] [blame] | 675 | static int |
| 676 | focus_surface_get_label(struct weston_surface *surface, char *buf, size_t len) |
| 677 | { |
| 678 | return snprintf(buf, len, "focus highlight effect for output %s", |
| 679 | surface->output->name); |
| 680 | } |
Louis-Francis Ratté-Boulianne | b482dbd | 2013-11-19 11:37:11 +0100 | [diff] [blame] | 681 | |
| 682 | /* no-op func for checking focus surface */ |
| 683 | static void |
Jason Ekstrand | 918f2dd | 2013-12-02 21:01:53 -0600 | [diff] [blame] | 684 | 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] | 685 | { |
| 686 | } |
| 687 | |
| 688 | static struct focus_surface * |
| 689 | get_focus_surface(struct weston_surface *surface) |
| 690 | { |
| 691 | if (surface->configure == focus_surface_configure) |
| 692 | return surface->configure_private; |
| 693 | else |
| 694 | return NULL; |
| 695 | } |
| 696 | |
| 697 | static bool |
| 698 | is_focus_surface (struct weston_surface *es) |
| 699 | { |
| 700 | return (es->configure == focus_surface_configure); |
| 701 | } |
| 702 | |
| 703 | static bool |
| 704 | is_focus_view (struct weston_view *view) |
| 705 | { |
| 706 | return is_focus_surface (view->surface); |
| 707 | } |
| 708 | |
| 709 | static struct focus_surface * |
| 710 | create_focus_surface(struct weston_compositor *ec, |
| 711 | struct weston_output *output) |
| 712 | { |
| 713 | struct focus_surface *fsurf = NULL; |
| 714 | struct weston_surface *surface = NULL; |
| 715 | |
| 716 | fsurf = malloc(sizeof *fsurf); |
| 717 | if (!fsurf) |
| 718 | return NULL; |
| 719 | |
| 720 | fsurf->surface = weston_surface_create(ec); |
| 721 | surface = fsurf->surface; |
| 722 | if (surface == NULL) { |
| 723 | free(fsurf); |
| 724 | return NULL; |
| 725 | } |
| 726 | |
| 727 | surface->configure = focus_surface_configure; |
| 728 | surface->output = output; |
| 729 | surface->configure_private = fsurf; |
Pekka Paalanen | 8274d90 | 2014-08-06 19:36:51 +0300 | [diff] [blame] | 730 | weston_surface_set_label_func(surface, focus_surface_get_label); |
Louis-Francis Ratté-Boulianne | b482dbd | 2013-11-19 11:37:11 +0100 | [diff] [blame] | 731 | |
U. Artie Eoff | 0b23b2b | 2014-01-15 14:45:59 -0800 | [diff] [blame] | 732 | fsurf->view = weston_view_create(surface); |
| 733 | if (fsurf->view == NULL) { |
| 734 | weston_surface_destroy(surface); |
| 735 | free(fsurf); |
| 736 | return NULL; |
| 737 | } |
Emilio Pozuelo Monfort | da64426 | 2013-11-19 11:37:19 +0100 | [diff] [blame] | 738 | fsurf->view->output = output; |
Louis-Francis Ratté-Boulianne | b482dbd | 2013-11-19 11:37:11 +0100 | [diff] [blame] | 739 | |
Jason Ekstrand | 5c11a33 | 2013-12-04 20:32:03 -0600 | [diff] [blame] | 740 | weston_surface_set_size(surface, output->width, output->height); |
Jason Ekstrand | 918f2dd | 2013-12-02 21:01:53 -0600 | [diff] [blame] | 741 | weston_view_set_position(fsurf->view, output->x, output->y); |
Louis-Francis Ratté-Boulianne | b482dbd | 2013-11-19 11:37:11 +0100 | [diff] [blame] | 742 | weston_surface_set_color(surface, 0.0, 0.0, 0.0, 1.0); |
| 743 | pixman_region32_fini(&surface->opaque); |
| 744 | pixman_region32_init_rect(&surface->opaque, output->x, output->y, |
| 745 | output->width, output->height); |
| 746 | pixman_region32_fini(&surface->input); |
| 747 | pixman_region32_init(&surface->input); |
| 748 | |
| 749 | wl_list_init(&fsurf->workspace_transform.link); |
| 750 | |
| 751 | return fsurf; |
| 752 | } |
| 753 | |
| 754 | static void |
| 755 | focus_surface_destroy(struct focus_surface *fsurf) |
| 756 | { |
| 757 | weston_surface_destroy(fsurf->surface); |
| 758 | free(fsurf); |
| 759 | } |
| 760 | |
| 761 | static void |
| 762 | focus_animation_done(struct weston_view_animation *animation, void *data) |
| 763 | { |
| 764 | struct workspace *ws = data; |
| 765 | |
| 766 | ws->focus_animation = NULL; |
| 767 | } |
| 768 | |
Jonas Ådahl | e3cddce | 2012-06-13 00:01:22 +0200 | [diff] [blame] | 769 | static void |
Jonas Ådahl | 0476974 | 2012-06-13 00:01:24 +0200 | [diff] [blame] | 770 | focus_state_destroy(struct focus_state *state) |
| 771 | { |
| 772 | wl_list_remove(&state->seat_destroy_listener.link); |
| 773 | wl_list_remove(&state->surface_destroy_listener.link); |
| 774 | free(state); |
| 775 | } |
| 776 | |
| 777 | static void |
| 778 | focus_state_seat_destroy(struct wl_listener *listener, void *data) |
| 779 | { |
| 780 | struct focus_state *state = container_of(listener, |
| 781 | struct focus_state, |
| 782 | seat_destroy_listener); |
| 783 | |
| 784 | wl_list_remove(&state->link); |
| 785 | focus_state_destroy(state); |
| 786 | } |
| 787 | |
| 788 | static void |
| 789 | focus_state_surface_destroy(struct wl_listener *listener, void *data) |
| 790 | { |
| 791 | struct focus_state *state = container_of(listener, |
| 792 | struct focus_state, |
Kristian Høgsberg | b8e0d0f | 2012-07-31 10:30:26 -0400 | [diff] [blame] | 793 | surface_destroy_listener); |
Kristian Høgsberg | e377822 | 2012-07-31 17:29:30 -0400 | [diff] [blame] | 794 | struct desktop_shell *shell; |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 795 | struct weston_surface *main_surface, *next; |
| 796 | struct weston_view *view; |
Jonas Ådahl | 0476974 | 2012-06-13 00:01:24 +0200 | [diff] [blame] | 797 | |
Pekka Paalanen | 01388e2 | 2013-04-25 13:57:44 +0300 | [diff] [blame] | 798 | main_surface = weston_surface_get_main_surface(state->keyboard_focus); |
| 799 | |
Kristian Høgsberg | e377822 | 2012-07-31 17:29:30 -0400 | [diff] [blame] | 800 | next = NULL; |
Giulio Camuffo | 412e6a5 | 2014-07-09 22:12:56 +0300 | [diff] [blame] | 801 | wl_list_for_each(view, |
| 802 | &state->ws->layer.view_list.link, layer_link.link) { |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 803 | if (view->surface == main_surface) |
Kristian Høgsberg | e377822 | 2012-07-31 17:29:30 -0400 | [diff] [blame] | 804 | continue; |
Louis-Francis Ratté-Boulianne | b482dbd | 2013-11-19 11:37:11 +0100 | [diff] [blame] | 805 | if (is_focus_view(view)) |
| 806 | continue; |
Kristian Høgsberg | e377822 | 2012-07-31 17:29:30 -0400 | [diff] [blame] | 807 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 808 | next = view->surface; |
Kristian Høgsberg | e377822 | 2012-07-31 17:29:30 -0400 | [diff] [blame] | 809 | break; |
| 810 | } |
| 811 | |
Pekka Paalanen | 01388e2 | 2013-04-25 13:57:44 +0300 | [diff] [blame] | 812 | /* if the focus was a sub-surface, activate its main surface */ |
| 813 | if (main_surface != state->keyboard_focus) |
| 814 | next = main_surface; |
| 815 | |
Louis-Francis Ratté-Boulianne | b482dbd | 2013-11-19 11:37:11 +0100 | [diff] [blame] | 816 | shell = state->seat->compositor->shell_interface.shell; |
Kristian Høgsberg | e377822 | 2012-07-31 17:29:30 -0400 | [diff] [blame] | 817 | if (next) { |
Louis-Francis Ratté-Boulianne | b482dbd | 2013-11-19 11:37:11 +0100 | [diff] [blame] | 818 | state->keyboard_focus = NULL; |
Emilio Pozuelo Monfort | 9e7c759 | 2014-01-30 14:01:10 +0100 | [diff] [blame] | 819 | activate(shell, next, state->seat, true); |
Kristian Høgsberg | e377822 | 2012-07-31 17:29:30 -0400 | [diff] [blame] | 820 | } else { |
Louis-Francis Ratté-Boulianne | b482dbd | 2013-11-19 11:37:11 +0100 | [diff] [blame] | 821 | if (shell->focus_animation_type == ANIMATION_DIM_LAYER) { |
| 822 | if (state->ws->focus_animation) |
| 823 | weston_view_animation_destroy(state->ws->focus_animation); |
| 824 | |
| 825 | state->ws->focus_animation = weston_fade_run( |
| 826 | state->ws->fsurf_front->view, |
| 827 | state->ws->fsurf_front->view->alpha, 0.0, 300, |
| 828 | focus_animation_done, state->ws); |
| 829 | } |
| 830 | |
Kristian Høgsberg | e377822 | 2012-07-31 17:29:30 -0400 | [diff] [blame] | 831 | wl_list_remove(&state->link); |
| 832 | focus_state_destroy(state); |
| 833 | } |
Jonas Ådahl | 0476974 | 2012-06-13 00:01:24 +0200 | [diff] [blame] | 834 | } |
| 835 | |
| 836 | static struct focus_state * |
Kristian Høgsberg | 2f5faff | 2012-07-31 16:36:34 -0400 | [diff] [blame] | 837 | focus_state_create(struct weston_seat *seat, struct workspace *ws) |
Jonas Ådahl | 0476974 | 2012-06-13 00:01:24 +0200 | [diff] [blame] | 838 | { |
Jonas Ådahl | 0476974 | 2012-06-13 00:01:24 +0200 | [diff] [blame] | 839 | struct focus_state *state; |
Jonas Ådahl | 0476974 | 2012-06-13 00:01:24 +0200 | [diff] [blame] | 840 | |
| 841 | state = malloc(sizeof *state); |
| 842 | if (state == NULL) |
| 843 | return NULL; |
| 844 | |
Louis-Francis Ratté-Boulianne | b482dbd | 2013-11-19 11:37:11 +0100 | [diff] [blame] | 845 | state->keyboard_focus = NULL; |
Kristian Høgsberg | 2f5faff | 2012-07-31 16:36:34 -0400 | [diff] [blame] | 846 | state->ws = ws; |
Jonas Ådahl | 0476974 | 2012-06-13 00:01:24 +0200 | [diff] [blame] | 847 | state->seat = seat; |
Kristian Høgsberg | 2f5faff | 2012-07-31 16:36:34 -0400 | [diff] [blame] | 848 | wl_list_insert(&ws->focus_list, &state->link); |
Jonas Ådahl | 0476974 | 2012-06-13 00:01:24 +0200 | [diff] [blame] | 849 | |
| 850 | state->seat_destroy_listener.notify = focus_state_seat_destroy; |
| 851 | state->surface_destroy_listener.notify = focus_state_surface_destroy; |
Kristian Høgsberg | 4912454 | 2013-05-06 22:27:40 -0400 | [diff] [blame] | 852 | wl_signal_add(&seat->destroy_signal, |
Jonas Ådahl | 0476974 | 2012-06-13 00:01:24 +0200 | [diff] [blame] | 853 | &state->seat_destroy_listener); |
Kristian Høgsberg | 2f5faff | 2012-07-31 16:36:34 -0400 | [diff] [blame] | 854 | wl_list_init(&state->surface_destroy_listener.link); |
Jonas Ådahl | 0476974 | 2012-06-13 00:01:24 +0200 | [diff] [blame] | 855 | |
| 856 | return state; |
| 857 | } |
| 858 | |
Jonas Ådahl | 8538b22 | 2012-08-29 22:13:03 +0200 | [diff] [blame] | 859 | static struct focus_state * |
| 860 | ensure_focus_state(struct desktop_shell *shell, struct weston_seat *seat) |
| 861 | { |
| 862 | struct workspace *ws = get_current_workspace(shell); |
| 863 | struct focus_state *state; |
| 864 | |
| 865 | wl_list_for_each(state, &ws->focus_list, link) |
| 866 | if (state->seat == seat) |
| 867 | break; |
| 868 | |
| 869 | if (&state->link == &ws->focus_list) |
| 870 | state = focus_state_create(seat, ws); |
| 871 | |
| 872 | return state; |
| 873 | } |
| 874 | |
Jonas Ådahl | 0476974 | 2012-06-13 00:01:24 +0200 | [diff] [blame] | 875 | static void |
Kristian Høgsberg | d500bf1 | 2014-01-22 12:25:20 -0800 | [diff] [blame] | 876 | focus_state_set_focus(struct focus_state *state, |
| 877 | struct weston_surface *surface) |
| 878 | { |
| 879 | if (state->keyboard_focus) { |
| 880 | wl_list_remove(&state->surface_destroy_listener.link); |
| 881 | wl_list_init(&state->surface_destroy_listener.link); |
| 882 | } |
| 883 | |
| 884 | state->keyboard_focus = surface; |
| 885 | if (surface) |
| 886 | wl_signal_add(&surface->destroy_signal, |
| 887 | &state->surface_destroy_listener); |
| 888 | } |
| 889 | |
| 890 | static void |
Kristian Høgsberg | 2f5faff | 2012-07-31 16:36:34 -0400 | [diff] [blame] | 891 | restore_focus_state(struct desktop_shell *shell, struct workspace *ws) |
Jonas Ådahl | 0476974 | 2012-06-13 00:01:24 +0200 | [diff] [blame] | 892 | { |
| 893 | struct focus_state *state, *next; |
Kristian Høgsberg | fe7aa90 | 2013-05-08 09:54:37 -0400 | [diff] [blame] | 894 | struct weston_surface *surface; |
Neil Roberts | 4237f50 | 2014-04-09 16:33:31 +0100 | [diff] [blame] | 895 | struct wl_list pending_seat_list; |
| 896 | struct weston_seat *seat, *next_seat; |
| 897 | |
| 898 | /* Temporarily steal the list of seats so that we can keep |
| 899 | * track of the seats we've already processed */ |
| 900 | wl_list_init(&pending_seat_list); |
| 901 | wl_list_insert_list(&pending_seat_list, &shell->compositor->seat_list); |
| 902 | wl_list_init(&shell->compositor->seat_list); |
Jonas Ådahl | 0476974 | 2012-06-13 00:01:24 +0200 | [diff] [blame] | 903 | |
| 904 | wl_list_for_each_safe(state, next, &ws->focus_list, link) { |
Derek Foreman | 1281a36 | 2015-07-31 16:55:32 -0500 | [diff] [blame] | 905 | struct weston_keyboard *keyboard = |
| 906 | weston_seat_get_keyboard(state->seat); |
| 907 | |
Neil Roberts | 4237f50 | 2014-04-09 16:33:31 +0100 | [diff] [blame] | 908 | wl_list_remove(&state->seat->link); |
| 909 | wl_list_insert(&shell->compositor->seat_list, |
| 910 | &state->seat->link); |
| 911 | |
Derek Foreman | 1281a36 | 2015-07-31 16:55:32 -0500 | [diff] [blame] | 912 | if (!keyboard) |
Kristian Høgsberg | e61d2f4 | 2014-01-17 12:18:53 -0800 | [diff] [blame] | 913 | continue; |
| 914 | |
Kristian Høgsberg | fe7aa90 | 2013-05-08 09:54:37 -0400 | [diff] [blame] | 915 | surface = state->keyboard_focus; |
Jonas Ådahl | 5689944 | 2012-08-29 22:12:59 +0200 | [diff] [blame] | 916 | |
Derek Foreman | 1281a36 | 2015-07-31 16:55:32 -0500 | [diff] [blame] | 917 | weston_keyboard_set_focus(keyboard, surface); |
Jonas Ådahl | 0476974 | 2012-06-13 00:01:24 +0200 | [diff] [blame] | 918 | } |
Neil Roberts | 4237f50 | 2014-04-09 16:33:31 +0100 | [diff] [blame] | 919 | |
| 920 | /* For any remaining seats that we don't have a focus state |
| 921 | * for we'll reset the keyboard focus to NULL */ |
| 922 | wl_list_for_each_safe(seat, next_seat, &pending_seat_list, link) { |
Derek Foreman | 1281a36 | 2015-07-31 16:55:32 -0500 | [diff] [blame] | 923 | struct weston_keyboard *keyboard = |
| 924 | weston_seat_get_keyboard(seat); |
| 925 | |
Neil Roberts | 4237f50 | 2014-04-09 16:33:31 +0100 | [diff] [blame] | 926 | wl_list_insert(&shell->compositor->seat_list, &seat->link); |
| 927 | |
Derek Foreman | 1281a36 | 2015-07-31 16:55:32 -0500 | [diff] [blame] | 928 | if (!keyboard) |
Neil Roberts | 4237f50 | 2014-04-09 16:33:31 +0100 | [diff] [blame] | 929 | continue; |
| 930 | |
Derek Foreman | 1281a36 | 2015-07-31 16:55:32 -0500 | [diff] [blame] | 931 | weston_keyboard_set_focus(keyboard, NULL); |
Neil Roberts | 4237f50 | 2014-04-09 16:33:31 +0100 | [diff] [blame] | 932 | } |
Jonas Ådahl | 0476974 | 2012-06-13 00:01:24 +0200 | [diff] [blame] | 933 | } |
| 934 | |
| 935 | static void |
Jonas Ådahl | 8de6a1d | 2012-08-29 22:13:00 +0200 | [diff] [blame] | 936 | replace_focus_state(struct desktop_shell *shell, struct workspace *ws, |
| 937 | struct weston_seat *seat) |
| 938 | { |
Derek Foreman | 1281a36 | 2015-07-31 16:55:32 -0500 | [diff] [blame] | 939 | struct weston_keyboard *keyboard = weston_seat_get_keyboard(seat); |
Jonas Ådahl | 8de6a1d | 2012-08-29 22:13:00 +0200 | [diff] [blame] | 940 | struct focus_state *state; |
Jonas Ådahl | 8de6a1d | 2012-08-29 22:13:00 +0200 | [diff] [blame] | 941 | |
| 942 | wl_list_for_each(state, &ws->focus_list, link) { |
| 943 | if (state->seat == seat) { |
Derek Foreman | 1281a36 | 2015-07-31 16:55:32 -0500 | [diff] [blame] | 944 | focus_state_set_focus(state, keyboard->focus); |
Jonas Ådahl | 8de6a1d | 2012-08-29 22:13:00 +0200 | [diff] [blame] | 945 | return; |
| 946 | } |
| 947 | } |
| 948 | } |
| 949 | |
| 950 | static void |
| 951 | drop_focus_state(struct desktop_shell *shell, struct workspace *ws, |
| 952 | struct weston_surface *surface) |
| 953 | { |
| 954 | struct focus_state *state; |
| 955 | |
| 956 | wl_list_for_each(state, &ws->focus_list, link) |
| 957 | if (state->keyboard_focus == surface) |
Kristian Høgsberg | d500bf1 | 2014-01-22 12:25:20 -0800 | [diff] [blame] | 958 | focus_state_set_focus(state, NULL); |
Jonas Ådahl | 8de6a1d | 2012-08-29 22:13:00 +0200 | [diff] [blame] | 959 | } |
| 960 | |
| 961 | static void |
Louis-Francis Ratté-Boulianne | b482dbd | 2013-11-19 11:37:11 +0100 | [diff] [blame] | 962 | animate_focus_change(struct desktop_shell *shell, struct workspace *ws, |
| 963 | struct weston_view *from, struct weston_view *to) |
| 964 | { |
| 965 | struct weston_output *output; |
| 966 | bool focus_surface_created = false; |
| 967 | |
| 968 | /* FIXME: Only support dim animation using two layers */ |
| 969 | if (from == to || shell->focus_animation_type != ANIMATION_DIM_LAYER) |
| 970 | return; |
| 971 | |
| 972 | output = get_default_output(shell->compositor); |
| 973 | if (ws->fsurf_front == NULL && (from || to)) { |
| 974 | ws->fsurf_front = create_focus_surface(shell->compositor, output); |
U. Artie Eoff | 0b23b2b | 2014-01-15 14:45:59 -0800 | [diff] [blame] | 975 | if (ws->fsurf_front == NULL) |
| 976 | return; |
Louis-Francis Ratté-Boulianne | b482dbd | 2013-11-19 11:37:11 +0100 | [diff] [blame] | 977 | ws->fsurf_front->view->alpha = 0.0; |
U. Artie Eoff | 0b23b2b | 2014-01-15 14:45:59 -0800 | [diff] [blame] | 978 | |
| 979 | ws->fsurf_back = create_focus_surface(shell->compositor, output); |
| 980 | if (ws->fsurf_back == NULL) { |
| 981 | focus_surface_destroy(ws->fsurf_front); |
| 982 | return; |
| 983 | } |
Louis-Francis Ratté-Boulianne | b482dbd | 2013-11-19 11:37:11 +0100 | [diff] [blame] | 984 | ws->fsurf_back->view->alpha = 0.0; |
U. Artie Eoff | 0b23b2b | 2014-01-15 14:45:59 -0800 | [diff] [blame] | 985 | |
Louis-Francis Ratté-Boulianne | b482dbd | 2013-11-19 11:37:11 +0100 | [diff] [blame] | 986 | focus_surface_created = true; |
| 987 | } else { |
Giulio Camuffo | 412e6a5 | 2014-07-09 22:12:56 +0300 | [diff] [blame] | 988 | weston_layer_entry_remove(&ws->fsurf_front->view->layer_link); |
| 989 | weston_layer_entry_remove(&ws->fsurf_back->view->layer_link); |
Louis-Francis Ratté-Boulianne | b482dbd | 2013-11-19 11:37:11 +0100 | [diff] [blame] | 990 | } |
| 991 | |
| 992 | if (ws->focus_animation) { |
| 993 | weston_view_animation_destroy(ws->focus_animation); |
| 994 | ws->focus_animation = NULL; |
| 995 | } |
| 996 | |
| 997 | if (to) |
Giulio Camuffo | 412e6a5 | 2014-07-09 22:12:56 +0300 | [diff] [blame] | 998 | weston_layer_entry_insert(&to->layer_link, |
| 999 | &ws->fsurf_front->view->layer_link); |
Louis-Francis Ratté-Boulianne | b482dbd | 2013-11-19 11:37:11 +0100 | [diff] [blame] | 1000 | else if (from) |
Giulio Camuffo | 412e6a5 | 2014-07-09 22:12:56 +0300 | [diff] [blame] | 1001 | weston_layer_entry_insert(&ws->layer.view_list, |
| 1002 | &ws->fsurf_front->view->layer_link); |
Louis-Francis Ratté-Boulianne | b482dbd | 2013-11-19 11:37:11 +0100 | [diff] [blame] | 1003 | |
| 1004 | if (focus_surface_created) { |
| 1005 | ws->focus_animation = weston_fade_run( |
| 1006 | ws->fsurf_front->view, |
Jonny Lamb | 7e7d485 | 2014-05-22 22:41:34 +0200 | [diff] [blame] | 1007 | ws->fsurf_front->view->alpha, 0.4, 300, |
Louis-Francis Ratté-Boulianne | b482dbd | 2013-11-19 11:37:11 +0100 | [diff] [blame] | 1008 | focus_animation_done, ws); |
| 1009 | } else if (from) { |
Giulio Camuffo | 412e6a5 | 2014-07-09 22:12:56 +0300 | [diff] [blame] | 1010 | weston_layer_entry_insert(&from->layer_link, |
| 1011 | &ws->fsurf_back->view->layer_link); |
Louis-Francis Ratté-Boulianne | b482dbd | 2013-11-19 11:37:11 +0100 | [diff] [blame] | 1012 | ws->focus_animation = weston_stable_fade_run( |
| 1013 | ws->fsurf_front->view, 0.0, |
Jonny Lamb | 7e7d485 | 2014-05-22 22:41:34 +0200 | [diff] [blame] | 1014 | ws->fsurf_back->view, 0.4, |
Louis-Francis Ratté-Boulianne | b482dbd | 2013-11-19 11:37:11 +0100 | [diff] [blame] | 1015 | focus_animation_done, ws); |
| 1016 | } else if (to) { |
Giulio Camuffo | 412e6a5 | 2014-07-09 22:12:56 +0300 | [diff] [blame] | 1017 | weston_layer_entry_insert(&ws->layer.view_list, |
| 1018 | &ws->fsurf_back->view->layer_link); |
Louis-Francis Ratté-Boulianne | b482dbd | 2013-11-19 11:37:11 +0100 | [diff] [blame] | 1019 | ws->focus_animation = weston_stable_fade_run( |
| 1020 | ws->fsurf_front->view, 0.0, |
Jonny Lamb | 7e7d485 | 2014-05-22 22:41:34 +0200 | [diff] [blame] | 1021 | ws->fsurf_back->view, 0.4, |
Louis-Francis Ratté-Boulianne | b482dbd | 2013-11-19 11:37:11 +0100 | [diff] [blame] | 1022 | focus_animation_done, ws); |
| 1023 | } |
| 1024 | } |
| 1025 | |
| 1026 | static void |
Jonas Ådahl | e3cddce | 2012-06-13 00:01:22 +0200 | [diff] [blame] | 1027 | workspace_destroy(struct workspace *ws) |
| 1028 | { |
Jonas Ådahl | 0476974 | 2012-06-13 00:01:24 +0200 | [diff] [blame] | 1029 | struct focus_state *state, *next; |
| 1030 | |
| 1031 | wl_list_for_each_safe(state, next, &ws->focus_list, link) |
| 1032 | focus_state_destroy(state); |
| 1033 | |
Louis-Francis Ratté-Boulianne | b482dbd | 2013-11-19 11:37:11 +0100 | [diff] [blame] | 1034 | if (ws->fsurf_front) |
| 1035 | focus_surface_destroy(ws->fsurf_front); |
| 1036 | if (ws->fsurf_back) |
| 1037 | focus_surface_destroy(ws->fsurf_back); |
| 1038 | |
Jonas Ådahl | e3cddce | 2012-06-13 00:01:22 +0200 | [diff] [blame] | 1039 | free(ws); |
| 1040 | } |
| 1041 | |
Jonas Ådahl | 0476974 | 2012-06-13 00:01:24 +0200 | [diff] [blame] | 1042 | static void |
| 1043 | seat_destroyed(struct wl_listener *listener, void *data) |
| 1044 | { |
| 1045 | struct weston_seat *seat = data; |
| 1046 | struct focus_state *state, *next; |
| 1047 | struct workspace *ws = container_of(listener, |
| 1048 | struct workspace, |
| 1049 | seat_destroyed_listener); |
| 1050 | |
| 1051 | wl_list_for_each_safe(state, next, &ws->focus_list, link) |
| 1052 | if (state->seat == seat) |
| 1053 | wl_list_remove(&state->link); |
| 1054 | } |
| 1055 | |
Jonas Ådahl | e3cddce | 2012-06-13 00:01:22 +0200 | [diff] [blame] | 1056 | static struct workspace * |
| 1057 | workspace_create(void) |
| 1058 | { |
| 1059 | struct workspace *ws = malloc(sizeof *ws); |
| 1060 | if (ws == NULL) |
| 1061 | return NULL; |
| 1062 | |
| 1063 | weston_layer_init(&ws->layer, NULL); |
| 1064 | |
Jonas Ådahl | 0476974 | 2012-06-13 00:01:24 +0200 | [diff] [blame] | 1065 | wl_list_init(&ws->focus_list); |
| 1066 | wl_list_init(&ws->seat_destroyed_listener.link); |
| 1067 | ws->seat_destroyed_listener.notify = seat_destroyed; |
Louis-Francis Ratté-Boulianne | b482dbd | 2013-11-19 11:37:11 +0100 | [diff] [blame] | 1068 | ws->fsurf_front = NULL; |
| 1069 | ws->fsurf_back = NULL; |
| 1070 | ws->focus_animation = NULL; |
Jonas Ådahl | 0476974 | 2012-06-13 00:01:24 +0200 | [diff] [blame] | 1071 | |
Jonas Ådahl | e3cddce | 2012-06-13 00:01:22 +0200 | [diff] [blame] | 1072 | return ws; |
| 1073 | } |
| 1074 | |
Jonas Ådahl | 62fcd04 | 2012-06-13 00:01:23 +0200 | [diff] [blame] | 1075 | static int |
| 1076 | workspace_is_empty(struct workspace *ws) |
| 1077 | { |
Giulio Camuffo | 412e6a5 | 2014-07-09 22:12:56 +0300 | [diff] [blame] | 1078 | return wl_list_empty(&ws->layer.view_list.link); |
Jonas Ådahl | 62fcd04 | 2012-06-13 00:01:23 +0200 | [diff] [blame] | 1079 | } |
| 1080 | |
Jonas Ådahl | e3cddce | 2012-06-13 00:01:22 +0200 | [diff] [blame] | 1081 | static struct workspace * |
| 1082 | get_workspace(struct desktop_shell *shell, unsigned int index) |
| 1083 | { |
| 1084 | struct workspace **pws = shell->workspaces.array.data; |
Philipp Brüschweiler | 067abf6 | 2012-09-01 16:03:05 +0200 | [diff] [blame] | 1085 | assert(index < shell->workspaces.num); |
Jonas Ådahl | e3cddce | 2012-06-13 00:01:22 +0200 | [diff] [blame] | 1086 | pws += index; |
| 1087 | return *pws; |
| 1088 | } |
| 1089 | |
Kristian Høgsberg | 1ef2313 | 2013-12-04 00:20:01 -0800 | [diff] [blame] | 1090 | struct workspace * |
Jonas Ådahl | e3cddce | 2012-06-13 00:01:22 +0200 | [diff] [blame] | 1091 | get_current_workspace(struct desktop_shell *shell) |
| 1092 | { |
| 1093 | return get_workspace(shell, shell->workspaces.current); |
| 1094 | } |
| 1095 | |
| 1096 | static void |
| 1097 | activate_workspace(struct desktop_shell *shell, unsigned int index) |
| 1098 | { |
| 1099 | struct workspace *ws; |
| 1100 | |
| 1101 | ws = get_workspace(shell, index); |
| 1102 | wl_list_insert(&shell->panel_layer.link, &ws->layer.link); |
| 1103 | |
| 1104 | shell->workspaces.current = index; |
| 1105 | } |
| 1106 | |
Jonas Ådahl | 62fcd04 | 2012-06-13 00:01:23 +0200 | [diff] [blame] | 1107 | static unsigned int |
| 1108 | get_output_height(struct weston_output *output) |
| 1109 | { |
| 1110 | return abs(output->region.extents.y1 - output->region.extents.y2); |
| 1111 | } |
| 1112 | |
| 1113 | static void |
Louis-Francis Ratté-Boulianne | b482dbd | 2013-11-19 11:37:11 +0100 | [diff] [blame] | 1114 | view_translate(struct workspace *ws, struct weston_view *view, double d) |
Jonas Ådahl | 62fcd04 | 2012-06-13 00:01:23 +0200 | [diff] [blame] | 1115 | { |
Jonas Ådahl | 62fcd04 | 2012-06-13 00:01:23 +0200 | [diff] [blame] | 1116 | struct weston_transform *transform; |
| 1117 | |
Louis-Francis Ratté-Boulianne | b482dbd | 2013-11-19 11:37:11 +0100 | [diff] [blame] | 1118 | if (is_focus_view(view)) { |
| 1119 | struct focus_surface *fsurf = get_focus_surface(view->surface); |
| 1120 | transform = &fsurf->workspace_transform; |
| 1121 | } else { |
| 1122 | struct shell_surface *shsurf = get_shell_surface(view->surface); |
| 1123 | transform = &shsurf->workspace_transform; |
| 1124 | } |
| 1125 | |
Jonas Ådahl | 62fcd04 | 2012-06-13 00:01:23 +0200 | [diff] [blame] | 1126 | if (wl_list_empty(&transform->link)) |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 1127 | wl_list_insert(view->geometry.transformation_list.prev, |
Louis-Francis Ratté-Boulianne | b482dbd | 2013-11-19 11:37:11 +0100 | [diff] [blame] | 1128 | &transform->link); |
Jonas Ådahl | 62fcd04 | 2012-06-13 00:01:23 +0200 | [diff] [blame] | 1129 | |
Louis-Francis Ratté-Boulianne | b482dbd | 2013-11-19 11:37:11 +0100 | [diff] [blame] | 1130 | weston_matrix_init(&transform->matrix); |
| 1131 | weston_matrix_translate(&transform->matrix, |
Jonas Ådahl | 62fcd04 | 2012-06-13 00:01:23 +0200 | [diff] [blame] | 1132 | 0.0, d, 0.0); |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 1133 | weston_view_geometry_dirty(view); |
Jonas Ådahl | 62fcd04 | 2012-06-13 00:01:23 +0200 | [diff] [blame] | 1134 | } |
| 1135 | |
| 1136 | static void |
| 1137 | workspace_translate_out(struct workspace *ws, double fraction) |
| 1138 | { |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 1139 | struct weston_view *view; |
Jonas Ådahl | 62fcd04 | 2012-06-13 00:01:23 +0200 | [diff] [blame] | 1140 | unsigned int height; |
| 1141 | double d; |
| 1142 | |
Giulio Camuffo | 412e6a5 | 2014-07-09 22:12:56 +0300 | [diff] [blame] | 1143 | 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] | 1144 | height = get_output_height(view->surface->output); |
Jonas Ådahl | 62fcd04 | 2012-06-13 00:01:23 +0200 | [diff] [blame] | 1145 | d = height * fraction; |
| 1146 | |
Louis-Francis Ratté-Boulianne | b482dbd | 2013-11-19 11:37:11 +0100 | [diff] [blame] | 1147 | view_translate(ws, view, d); |
Jonas Ådahl | 62fcd04 | 2012-06-13 00:01:23 +0200 | [diff] [blame] | 1148 | } |
| 1149 | } |
| 1150 | |
| 1151 | static void |
| 1152 | workspace_translate_in(struct workspace *ws, double fraction) |
| 1153 | { |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 1154 | struct weston_view *view; |
Jonas Ådahl | 62fcd04 | 2012-06-13 00:01:23 +0200 | [diff] [blame] | 1155 | unsigned int height; |
| 1156 | double d; |
| 1157 | |
Giulio Camuffo | 412e6a5 | 2014-07-09 22:12:56 +0300 | [diff] [blame] | 1158 | 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] | 1159 | height = get_output_height(view->surface->output); |
Jonas Ådahl | 62fcd04 | 2012-06-13 00:01:23 +0200 | [diff] [blame] | 1160 | |
| 1161 | if (fraction > 0) |
| 1162 | d = -(height - height * fraction); |
| 1163 | else |
| 1164 | d = height + height * fraction; |
| 1165 | |
Louis-Francis Ratté-Boulianne | b482dbd | 2013-11-19 11:37:11 +0100 | [diff] [blame] | 1166 | view_translate(ws, view, d); |
Jonas Ådahl | 62fcd04 | 2012-06-13 00:01:23 +0200 | [diff] [blame] | 1167 | } |
| 1168 | } |
| 1169 | |
| 1170 | static void |
Jonas Ådahl | e9d2250 | 2012-08-29 22:13:01 +0200 | [diff] [blame] | 1171 | broadcast_current_workspace_state(struct desktop_shell *shell) |
| 1172 | { |
Kristian Høgsberg | 2e3c396 | 2013-09-11 12:00:47 -0700 | [diff] [blame] | 1173 | struct wl_resource *resource; |
Jonas Ådahl | e9d2250 | 2012-08-29 22:13:01 +0200 | [diff] [blame] | 1174 | |
Kristian Høgsberg | 2e3c396 | 2013-09-11 12:00:47 -0700 | [diff] [blame] | 1175 | wl_resource_for_each(resource, &shell->workspaces.client_list) |
| 1176 | workspace_manager_send_state(resource, |
Jonas Ådahl | e9d2250 | 2012-08-29 22:13:01 +0200 | [diff] [blame] | 1177 | shell->workspaces.current, |
| 1178 | shell->workspaces.num); |
| 1179 | } |
| 1180 | |
| 1181 | static void |
Jonas Ådahl | 62fcd04 | 2012-06-13 00:01:23 +0200 | [diff] [blame] | 1182 | reverse_workspace_change_animation(struct desktop_shell *shell, |
| 1183 | unsigned int index, |
| 1184 | struct workspace *from, |
| 1185 | struct workspace *to) |
| 1186 | { |
| 1187 | shell->workspaces.current = index; |
| 1188 | |
| 1189 | shell->workspaces.anim_to = to; |
| 1190 | shell->workspaces.anim_from = from; |
| 1191 | shell->workspaces.anim_dir = -1 * shell->workspaces.anim_dir; |
| 1192 | shell->workspaces.anim_timestamp = 0; |
| 1193 | |
Scott Moreau | 4272e63 | 2012-08-13 09:58:41 -0600 | [diff] [blame] | 1194 | weston_compositor_schedule_repaint(shell->compositor); |
Jonas Ådahl | 62fcd04 | 2012-06-13 00:01:23 +0200 | [diff] [blame] | 1195 | } |
| 1196 | |
| 1197 | static void |
| 1198 | workspace_deactivate_transforms(struct workspace *ws) |
| 1199 | { |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 1200 | struct weston_view *view; |
Louis-Francis Ratté-Boulianne | b482dbd | 2013-11-19 11:37:11 +0100 | [diff] [blame] | 1201 | struct weston_transform *transform; |
Jonas Ådahl | 62fcd04 | 2012-06-13 00:01:23 +0200 | [diff] [blame] | 1202 | |
Giulio Camuffo | 412e6a5 | 2014-07-09 22:12:56 +0300 | [diff] [blame] | 1203 | 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] | 1204 | if (is_focus_view(view)) { |
| 1205 | struct focus_surface *fsurf = get_focus_surface(view->surface); |
| 1206 | transform = &fsurf->workspace_transform; |
| 1207 | } else { |
| 1208 | struct shell_surface *shsurf = get_shell_surface(view->surface); |
| 1209 | transform = &shsurf->workspace_transform; |
| 1210 | } |
| 1211 | |
| 1212 | if (!wl_list_empty(&transform->link)) { |
| 1213 | wl_list_remove(&transform->link); |
| 1214 | wl_list_init(&transform->link); |
Jonas Ådahl | 8de6a1d | 2012-08-29 22:13:00 +0200 | [diff] [blame] | 1215 | } |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 1216 | weston_view_geometry_dirty(view); |
Jonas Ådahl | 62fcd04 | 2012-06-13 00:01:23 +0200 | [diff] [blame] | 1217 | } |
| 1218 | } |
| 1219 | |
| 1220 | static void |
| 1221 | finish_workspace_change_animation(struct desktop_shell *shell, |
| 1222 | struct workspace *from, |
| 1223 | struct workspace *to) |
| 1224 | { |
Ander Conselvan de Oliveira | 9c6217e | 2014-05-07 11:57:26 +0300 | [diff] [blame] | 1225 | struct weston_view *view; |
| 1226 | |
Scott Moreau | 4272e63 | 2012-08-13 09:58:41 -0600 | [diff] [blame] | 1227 | weston_compositor_schedule_repaint(shell->compositor); |
Jonas Ådahl | 62fcd04 | 2012-06-13 00:01:23 +0200 | [diff] [blame] | 1228 | |
Ander Conselvan de Oliveira | 9c6217e | 2014-05-07 11:57:26 +0300 | [diff] [blame] | 1229 | /* Views that extend past the bottom of the output are still |
| 1230 | * visible after the workspace animation ends but before its layer |
| 1231 | * is hidden. In that case, we need to damage below those views so |
| 1232 | * that the screen is properly repainted. */ |
Giulio Camuffo | 412e6a5 | 2014-07-09 22:12:56 +0300 | [diff] [blame] | 1233 | 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] | 1234 | weston_view_damage_below(view); |
| 1235 | |
Jonas Ådahl | 62fcd04 | 2012-06-13 00:01:23 +0200 | [diff] [blame] | 1236 | wl_list_remove(&shell->workspaces.animation.link); |
| 1237 | workspace_deactivate_transforms(from); |
| 1238 | workspace_deactivate_transforms(to); |
| 1239 | shell->workspaces.anim_to = NULL; |
| 1240 | |
| 1241 | wl_list_remove(&shell->workspaces.anim_from->layer.link); |
| 1242 | } |
| 1243 | |
| 1244 | static void |
| 1245 | animate_workspace_change_frame(struct weston_animation *animation, |
| 1246 | struct weston_output *output, uint32_t msecs) |
| 1247 | { |
| 1248 | struct desktop_shell *shell = |
| 1249 | container_of(animation, struct desktop_shell, |
| 1250 | workspaces.animation); |
| 1251 | struct workspace *from = shell->workspaces.anim_from; |
| 1252 | struct workspace *to = shell->workspaces.anim_to; |
| 1253 | uint32_t t; |
| 1254 | double x, y; |
| 1255 | |
| 1256 | if (workspace_is_empty(from) && workspace_is_empty(to)) { |
| 1257 | finish_workspace_change_animation(shell, from, to); |
| 1258 | return; |
| 1259 | } |
| 1260 | |
| 1261 | if (shell->workspaces.anim_timestamp == 0) { |
| 1262 | if (shell->workspaces.anim_current == 0.0) |
| 1263 | shell->workspaces.anim_timestamp = msecs; |
| 1264 | else |
| 1265 | shell->workspaces.anim_timestamp = |
| 1266 | msecs - |
| 1267 | /* Invers of movement function 'y' below. */ |
| 1268 | (asin(1.0 - shell->workspaces.anim_current) * |
| 1269 | DEFAULT_WORKSPACE_CHANGE_ANIMATION_LENGTH * |
| 1270 | M_2_PI); |
| 1271 | } |
| 1272 | |
| 1273 | t = msecs - shell->workspaces.anim_timestamp; |
| 1274 | |
| 1275 | /* |
| 1276 | * x = [0, π/2] |
| 1277 | * y(x) = sin(x) |
| 1278 | */ |
| 1279 | x = t * (1.0/DEFAULT_WORKSPACE_CHANGE_ANIMATION_LENGTH) * M_PI_2; |
| 1280 | y = sin(x); |
| 1281 | |
| 1282 | if (t < DEFAULT_WORKSPACE_CHANGE_ANIMATION_LENGTH) { |
Scott Moreau | 4272e63 | 2012-08-13 09:58:41 -0600 | [diff] [blame] | 1283 | weston_compositor_schedule_repaint(shell->compositor); |
Jonas Ådahl | 62fcd04 | 2012-06-13 00:01:23 +0200 | [diff] [blame] | 1284 | |
| 1285 | workspace_translate_out(from, shell->workspaces.anim_dir * y); |
| 1286 | workspace_translate_in(to, shell->workspaces.anim_dir * y); |
| 1287 | shell->workspaces.anim_current = y; |
| 1288 | |
Scott Moreau | 4272e63 | 2012-08-13 09:58:41 -0600 | [diff] [blame] | 1289 | weston_compositor_schedule_repaint(shell->compositor); |
Jonas Ådahl | 62fcd04 | 2012-06-13 00:01:23 +0200 | [diff] [blame] | 1290 | } |
Jonas Ådahl | 0476974 | 2012-06-13 00:01:24 +0200 | [diff] [blame] | 1291 | else |
Jonas Ådahl | 62fcd04 | 2012-06-13 00:01:23 +0200 | [diff] [blame] | 1292 | finish_workspace_change_animation(shell, from, to); |
Jonas Ådahl | 62fcd04 | 2012-06-13 00:01:23 +0200 | [diff] [blame] | 1293 | } |
| 1294 | |
| 1295 | static void |
| 1296 | animate_workspace_change(struct desktop_shell *shell, |
| 1297 | unsigned int index, |
| 1298 | struct workspace *from, |
| 1299 | struct workspace *to) |
| 1300 | { |
| 1301 | struct weston_output *output; |
| 1302 | |
| 1303 | int dir; |
| 1304 | |
| 1305 | if (index > shell->workspaces.current) |
| 1306 | dir = -1; |
| 1307 | else |
| 1308 | dir = 1; |
| 1309 | |
| 1310 | shell->workspaces.current = index; |
| 1311 | |
| 1312 | shell->workspaces.anim_dir = dir; |
| 1313 | shell->workspaces.anim_from = from; |
| 1314 | shell->workspaces.anim_to = to; |
| 1315 | shell->workspaces.anim_current = 0.0; |
| 1316 | shell->workspaces.anim_timestamp = 0; |
| 1317 | |
| 1318 | output = container_of(shell->compositor->output_list.next, |
| 1319 | struct weston_output, link); |
| 1320 | wl_list_insert(&output->animation_list, |
| 1321 | &shell->workspaces.animation.link); |
| 1322 | |
Jonas Ådahl | 8de6a1d | 2012-08-29 22:13:00 +0200 | [diff] [blame] | 1323 | wl_list_insert(from->layer.link.prev, &to->layer.link); |
Jonas Ådahl | 62fcd04 | 2012-06-13 00:01:23 +0200 | [diff] [blame] | 1324 | |
| 1325 | workspace_translate_in(to, 0); |
| 1326 | |
Kristian Høgsberg | 2f5faff | 2012-07-31 16:36:34 -0400 | [diff] [blame] | 1327 | restore_focus_state(shell, to); |
Jonas Ådahl | 0476974 | 2012-06-13 00:01:24 +0200 | [diff] [blame] | 1328 | |
Scott Moreau | 4272e63 | 2012-08-13 09:58:41 -0600 | [diff] [blame] | 1329 | weston_compositor_schedule_repaint(shell->compositor); |
Jonas Ådahl | 62fcd04 | 2012-06-13 00:01:23 +0200 | [diff] [blame] | 1330 | } |
| 1331 | |
Jonas Ådahl | e3cddce | 2012-06-13 00:01:22 +0200 | [diff] [blame] | 1332 | static void |
Jonas Ådahl | 8de6a1d | 2012-08-29 22:13:00 +0200 | [diff] [blame] | 1333 | update_workspace(struct desktop_shell *shell, unsigned int index, |
| 1334 | struct workspace *from, struct workspace *to) |
| 1335 | { |
| 1336 | shell->workspaces.current = index; |
| 1337 | wl_list_insert(&from->layer.link, &to->layer.link); |
| 1338 | wl_list_remove(&from->layer.link); |
| 1339 | } |
| 1340 | |
| 1341 | static void |
Jonas Ådahl | e3cddce | 2012-06-13 00:01:22 +0200 | [diff] [blame] | 1342 | change_workspace(struct desktop_shell *shell, unsigned int index) |
| 1343 | { |
| 1344 | struct workspace *from; |
| 1345 | struct workspace *to; |
Louis-Francis Ratté-Boulianne | b482dbd | 2013-11-19 11:37:11 +0100 | [diff] [blame] | 1346 | struct focus_state *state; |
Jonas Ådahl | e3cddce | 2012-06-13 00:01:22 +0200 | [diff] [blame] | 1347 | |
| 1348 | if (index == shell->workspaces.current) |
| 1349 | return; |
| 1350 | |
| 1351 | /* Don't change workspace when there is any fullscreen surfaces. */ |
Giulio Camuffo | 412e6a5 | 2014-07-09 22:12:56 +0300 | [diff] [blame] | 1352 | if (!wl_list_empty(&shell->fullscreen_layer.view_list.link)) |
Jonas Ådahl | e3cddce | 2012-06-13 00:01:22 +0200 | [diff] [blame] | 1353 | return; |
| 1354 | |
Jonas Ådahl | e3cddce | 2012-06-13 00:01:22 +0200 | [diff] [blame] | 1355 | from = get_current_workspace(shell); |
| 1356 | to = get_workspace(shell, index); |
| 1357 | |
Jonas Ådahl | 62fcd04 | 2012-06-13 00:01:23 +0200 | [diff] [blame] | 1358 | if (shell->workspaces.anim_from == to && |
| 1359 | shell->workspaces.anim_to == from) { |
Jonas Ådahl | 8de6a1d | 2012-08-29 22:13:00 +0200 | [diff] [blame] | 1360 | restore_focus_state(shell, to); |
Jonas Ådahl | 62fcd04 | 2012-06-13 00:01:23 +0200 | [diff] [blame] | 1361 | reverse_workspace_change_animation(shell, index, from, to); |
Jonas Ådahl | e9d2250 | 2012-08-29 22:13:01 +0200 | [diff] [blame] | 1362 | broadcast_current_workspace_state(shell); |
Jonas Ådahl | 62fcd04 | 2012-06-13 00:01:23 +0200 | [diff] [blame] | 1363 | return; |
| 1364 | } |
Jonas Ådahl | e3cddce | 2012-06-13 00:01:22 +0200 | [diff] [blame] | 1365 | |
Jonas Ådahl | 62fcd04 | 2012-06-13 00:01:23 +0200 | [diff] [blame] | 1366 | if (shell->workspaces.anim_to != NULL) |
| 1367 | finish_workspace_change_animation(shell, |
| 1368 | shell->workspaces.anim_from, |
| 1369 | shell->workspaces.anim_to); |
| 1370 | |
Jonas Ådahl | 8de6a1d | 2012-08-29 22:13:00 +0200 | [diff] [blame] | 1371 | restore_focus_state(shell, to); |
Jonas Ådahl | 0476974 | 2012-06-13 00:01:24 +0200 | [diff] [blame] | 1372 | |
Louis-Francis Ratté-Boulianne | b482dbd | 2013-11-19 11:37:11 +0100 | [diff] [blame] | 1373 | if (shell->focus_animation_type != ANIMATION_NONE) { |
| 1374 | wl_list_for_each(state, &from->focus_list, link) |
| 1375 | if (state->keyboard_focus) |
| 1376 | animate_focus_change(shell, from, |
| 1377 | get_default_view(state->keyboard_focus), NULL); |
| 1378 | |
| 1379 | wl_list_for_each(state, &to->focus_list, link) |
| 1380 | if (state->keyboard_focus) |
| 1381 | animate_focus_change(shell, to, |
| 1382 | NULL, get_default_view(state->keyboard_focus)); |
| 1383 | } |
| 1384 | |
Jonas Ådahl | 8de6a1d | 2012-08-29 22:13:00 +0200 | [diff] [blame] | 1385 | if (workspace_is_empty(to) && workspace_is_empty(from)) |
| 1386 | update_workspace(shell, index, from, to); |
Jonas Ådahl | 62fcd04 | 2012-06-13 00:01:23 +0200 | [diff] [blame] | 1387 | else |
| 1388 | animate_workspace_change(shell, index, from, to); |
Jonas Ådahl | e9d2250 | 2012-08-29 22:13:01 +0200 | [diff] [blame] | 1389 | |
| 1390 | broadcast_current_workspace_state(shell); |
Pekka Paalanen | e955f1e | 2011-12-07 11:49:52 +0200 | [diff] [blame] | 1391 | } |
| 1392 | |
Jonas Ådahl | 8de6a1d | 2012-08-29 22:13:00 +0200 | [diff] [blame] | 1393 | static bool |
| 1394 | workspace_has_only(struct workspace *ws, struct weston_surface *surface) |
| 1395 | { |
Giulio Camuffo | 412e6a5 | 2014-07-09 22:12:56 +0300 | [diff] [blame] | 1396 | struct wl_list *list = &ws->layer.view_list.link; |
Jonas Ådahl | 8de6a1d | 2012-08-29 22:13:00 +0200 | [diff] [blame] | 1397 | struct wl_list *e; |
| 1398 | |
| 1399 | if (wl_list_empty(list)) |
| 1400 | return false; |
| 1401 | |
| 1402 | e = list->next; |
| 1403 | |
| 1404 | if (e->next != list) |
| 1405 | return false; |
| 1406 | |
Giulio Camuffo | 412e6a5 | 2014-07-09 22:12:56 +0300 | [diff] [blame] | 1407 | return container_of(e, struct weston_view, layer_link.link)->surface == surface; |
Jonas Ådahl | 8de6a1d | 2012-08-29 22:13:00 +0200 | [diff] [blame] | 1408 | } |
| 1409 | |
| 1410 | static void |
Philip Withnall | 659163d | 2013-11-25 18:01:36 +0000 | [diff] [blame] | 1411 | move_surface_to_workspace(struct desktop_shell *shell, |
| 1412 | struct shell_surface *shsurf, |
| 1413 | uint32_t workspace) |
Jonas Ådahl | e9d2250 | 2012-08-29 22:13:01 +0200 | [diff] [blame] | 1414 | { |
| 1415 | struct workspace *from; |
| 1416 | struct workspace *to; |
| 1417 | struct weston_seat *seat; |
Pekka Paalanen | 01388e2 | 2013-04-25 13:57:44 +0300 | [diff] [blame] | 1418 | struct weston_surface *focus; |
Philip Withnall | 659163d | 2013-11-25 18:01:36 +0000 | [diff] [blame] | 1419 | struct weston_view *view; |
Jonas Ådahl | e9d2250 | 2012-08-29 22:13:01 +0200 | [diff] [blame] | 1420 | |
| 1421 | if (workspace == shell->workspaces.current) |
| 1422 | return; |
| 1423 | |
Philip Withnall | 659163d | 2013-11-25 18:01:36 +0000 | [diff] [blame] | 1424 | view = get_default_view(shsurf->surface); |
| 1425 | if (!view) |
| 1426 | return; |
| 1427 | |
| 1428 | assert(weston_surface_get_main_surface(view->surface) == view->surface); |
| 1429 | |
Philipp Brüschweiler | 067abf6 | 2012-09-01 16:03:05 +0200 | [diff] [blame] | 1430 | if (workspace >= shell->workspaces.num) |
| 1431 | workspace = shell->workspaces.num - 1; |
| 1432 | |
Jonas Ådahl | e9d2250 | 2012-08-29 22:13:01 +0200 | [diff] [blame] | 1433 | from = get_current_workspace(shell); |
| 1434 | to = get_workspace(shell, workspace); |
| 1435 | |
Giulio Camuffo | 412e6a5 | 2014-07-09 22:12:56 +0300 | [diff] [blame] | 1436 | weston_layer_entry_remove(&view->layer_link); |
| 1437 | weston_layer_entry_insert(&to->layer.view_list, &view->layer_link); |
Jonas Ådahl | e9d2250 | 2012-08-29 22:13:01 +0200 | [diff] [blame] | 1438 | |
Philip Withnall | 648a4dd | 2013-11-25 18:01:44 +0000 | [diff] [blame] | 1439 | shell_surface_update_child_surface_layers(shsurf); |
| 1440 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 1441 | drop_focus_state(shell, from, view->surface); |
Pekka Paalanen | 01388e2 | 2013-04-25 13:57:44 +0300 | [diff] [blame] | 1442 | wl_list_for_each(seat, &shell->compositor->seat_list, link) { |
Derek Foreman | 1281a36 | 2015-07-31 16:55:32 -0500 | [diff] [blame] | 1443 | struct weston_keyboard *keyboard = |
| 1444 | weston_seat_get_keyboard(seat); |
| 1445 | |
| 1446 | if (!keyboard) |
Pekka Paalanen | 01388e2 | 2013-04-25 13:57:44 +0300 | [diff] [blame] | 1447 | continue; |
| 1448 | |
Derek Foreman | 1281a36 | 2015-07-31 16:55:32 -0500 | [diff] [blame] | 1449 | focus = weston_surface_get_main_surface(keyboard->focus); |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 1450 | if (focus == view->surface) |
Derek Foreman | 1281a36 | 2015-07-31 16:55:32 -0500 | [diff] [blame] | 1451 | weston_keyboard_set_focus(keyboard, NULL); |
Pekka Paalanen | 01388e2 | 2013-04-25 13:57:44 +0300 | [diff] [blame] | 1452 | } |
Jonas Ådahl | e9d2250 | 2012-08-29 22:13:01 +0200 | [diff] [blame] | 1453 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 1454 | weston_view_damage_below(view); |
Jonas Ådahl | e9d2250 | 2012-08-29 22:13:01 +0200 | [diff] [blame] | 1455 | } |
| 1456 | |
| 1457 | static void |
Jonas Ådahl | 8de6a1d | 2012-08-29 22:13:00 +0200 | [diff] [blame] | 1458 | take_surface_to_workspace_by_seat(struct desktop_shell *shell, |
Kristian Høgsberg | e314875 | 2013-05-06 23:19:49 -0400 | [diff] [blame] | 1459 | struct weston_seat *seat, |
Jonas Ådahl | 8de6a1d | 2012-08-29 22:13:00 +0200 | [diff] [blame] | 1460 | unsigned int index) |
| 1461 | { |
Derek Foreman | 1281a36 | 2015-07-31 16:55:32 -0500 | [diff] [blame] | 1462 | struct weston_keyboard *keyboard = weston_seat_get_keyboard(seat); |
Pekka Paalanen | 01388e2 | 2013-04-25 13:57:44 +0300 | [diff] [blame] | 1463 | struct weston_surface *surface; |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 1464 | struct weston_view *view; |
Jonas Ådahl | 8de6a1d | 2012-08-29 22:13:00 +0200 | [diff] [blame] | 1465 | struct shell_surface *shsurf; |
| 1466 | struct workspace *from; |
| 1467 | struct workspace *to; |
Jonas Ådahl | 8538b22 | 2012-08-29 22:13:03 +0200 | [diff] [blame] | 1468 | struct focus_state *state; |
Jonas Ådahl | 8de6a1d | 2012-08-29 22:13:00 +0200 | [diff] [blame] | 1469 | |
Derek Foreman | 1281a36 | 2015-07-31 16:55:32 -0500 | [diff] [blame] | 1470 | surface = weston_surface_get_main_surface(keyboard->focus); |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 1471 | view = get_default_view(surface); |
| 1472 | if (view == NULL || |
Louis-Francis Ratté-Boulianne | b482dbd | 2013-11-19 11:37:11 +0100 | [diff] [blame] | 1473 | index == shell->workspaces.current || |
| 1474 | is_focus_view(view)) |
Jonas Ådahl | 8de6a1d | 2012-08-29 22:13:00 +0200 | [diff] [blame] | 1475 | return; |
| 1476 | |
| 1477 | from = get_current_workspace(shell); |
| 1478 | to = get_workspace(shell, index); |
| 1479 | |
Giulio Camuffo | 412e6a5 | 2014-07-09 22:12:56 +0300 | [diff] [blame] | 1480 | weston_layer_entry_remove(&view->layer_link); |
| 1481 | weston_layer_entry_insert(&to->layer.view_list, &view->layer_link); |
Jonas Ådahl | 8de6a1d | 2012-08-29 22:13:00 +0200 | [diff] [blame] | 1482 | |
Philip Withnall | 659163d | 2013-11-25 18:01:36 +0000 | [diff] [blame] | 1483 | shsurf = get_shell_surface(surface); |
Philip Withnall | 648a4dd | 2013-11-25 18:01:44 +0000 | [diff] [blame] | 1484 | if (shsurf != NULL) |
| 1485 | shell_surface_update_child_surface_layers(shsurf); |
Philip Withnall | 659163d | 2013-11-25 18:01:36 +0000 | [diff] [blame] | 1486 | |
Jonas Ådahl | e9d2250 | 2012-08-29 22:13:01 +0200 | [diff] [blame] | 1487 | replace_focus_state(shell, to, seat); |
Jonas Ådahl | 8de6a1d | 2012-08-29 22:13:00 +0200 | [diff] [blame] | 1488 | drop_focus_state(shell, from, surface); |
| 1489 | |
| 1490 | if (shell->workspaces.anim_from == to && |
| 1491 | shell->workspaces.anim_to == from) { |
Jonas Ådahl | e9d2250 | 2012-08-29 22:13:01 +0200 | [diff] [blame] | 1492 | wl_list_remove(&to->layer.link); |
| 1493 | wl_list_insert(from->layer.link.prev, &to->layer.link); |
| 1494 | |
Jonas Ådahl | 8de6a1d | 2012-08-29 22:13:00 +0200 | [diff] [blame] | 1495 | reverse_workspace_change_animation(shell, index, from, to); |
Jonas Ådahl | e9d2250 | 2012-08-29 22:13:01 +0200 | [diff] [blame] | 1496 | broadcast_current_workspace_state(shell); |
| 1497 | |
Jonas Ådahl | 8de6a1d | 2012-08-29 22:13:00 +0200 | [diff] [blame] | 1498 | return; |
| 1499 | } |
| 1500 | |
| 1501 | if (shell->workspaces.anim_to != NULL) |
| 1502 | finish_workspace_change_animation(shell, |
| 1503 | shell->workspaces.anim_from, |
| 1504 | shell->workspaces.anim_to); |
| 1505 | |
| 1506 | if (workspace_is_empty(from) && |
| 1507 | workspace_has_only(to, surface)) |
| 1508 | update_workspace(shell, index, from, to); |
| 1509 | else { |
Philip Withnall | 2c3849b | 2013-11-25 18:01:45 +0000 | [diff] [blame] | 1510 | if (shsurf != NULL && |
| 1511 | wl_list_empty(&shsurf->workspace_transform.link)) |
Jonas Ådahl | 8de6a1d | 2012-08-29 22:13:00 +0200 | [diff] [blame] | 1512 | wl_list_insert(&shell->workspaces.anim_sticky_list, |
| 1513 | &shsurf->workspace_transform.link); |
| 1514 | |
| 1515 | animate_workspace_change(shell, index, from, to); |
| 1516 | } |
Jonas Ådahl | e9d2250 | 2012-08-29 22:13:01 +0200 | [diff] [blame] | 1517 | |
| 1518 | broadcast_current_workspace_state(shell); |
Jonas Ådahl | 8538b22 | 2012-08-29 22:13:03 +0200 | [diff] [blame] | 1519 | |
| 1520 | state = ensure_focus_state(shell, seat); |
| 1521 | if (state != NULL) |
Kristian Høgsberg | d500bf1 | 2014-01-22 12:25:20 -0800 | [diff] [blame] | 1522 | focus_state_set_focus(state, surface); |
Jonas Ådahl | e9d2250 | 2012-08-29 22:13:01 +0200 | [diff] [blame] | 1523 | } |
| 1524 | |
| 1525 | static void |
| 1526 | workspace_manager_move_surface(struct wl_client *client, |
| 1527 | struct wl_resource *resource, |
| 1528 | struct wl_resource *surface_resource, |
| 1529 | uint32_t workspace) |
| 1530 | { |
Jason Ekstrand | 651f00e | 2013-06-14 10:07:54 -0500 | [diff] [blame] | 1531 | struct desktop_shell *shell = wl_resource_get_user_data(resource); |
Jonas Ådahl | e9d2250 | 2012-08-29 22:13:01 +0200 | [diff] [blame] | 1532 | struct weston_surface *surface = |
Jason Ekstrand | 0f2ef7e | 2013-06-14 10:07:53 -0500 | [diff] [blame] | 1533 | wl_resource_get_user_data(surface_resource); |
Pekka Paalanen | 01388e2 | 2013-04-25 13:57:44 +0300 | [diff] [blame] | 1534 | struct weston_surface *main_surface; |
Philip Withnall | 659163d | 2013-11-25 18:01:36 +0000 | [diff] [blame] | 1535 | struct shell_surface *shell_surface; |
Jonas Ådahl | e9d2250 | 2012-08-29 22:13:01 +0200 | [diff] [blame] | 1536 | |
Pekka Paalanen | 01388e2 | 2013-04-25 13:57:44 +0300 | [diff] [blame] | 1537 | main_surface = weston_surface_get_main_surface(surface); |
Philip Withnall | 659163d | 2013-11-25 18:01:36 +0000 | [diff] [blame] | 1538 | shell_surface = get_shell_surface(main_surface); |
| 1539 | if (shell_surface == NULL) |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 1540 | return; |
Philip Withnall | 659163d | 2013-11-25 18:01:36 +0000 | [diff] [blame] | 1541 | |
| 1542 | move_surface_to_workspace(shell, shell_surface, workspace); |
Jonas Ådahl | e9d2250 | 2012-08-29 22:13:01 +0200 | [diff] [blame] | 1543 | } |
| 1544 | |
| 1545 | static const struct workspace_manager_interface workspace_manager_implementation = { |
| 1546 | workspace_manager_move_surface, |
| 1547 | }; |
| 1548 | |
| 1549 | static void |
| 1550 | unbind_resource(struct wl_resource *resource) |
| 1551 | { |
Jason Ekstrand | 651f00e | 2013-06-14 10:07:54 -0500 | [diff] [blame] | 1552 | wl_list_remove(wl_resource_get_link(resource)); |
Jonas Ådahl | e9d2250 | 2012-08-29 22:13:01 +0200 | [diff] [blame] | 1553 | } |
| 1554 | |
| 1555 | static void |
| 1556 | bind_workspace_manager(struct wl_client *client, |
| 1557 | void *data, uint32_t version, uint32_t id) |
| 1558 | { |
| 1559 | struct desktop_shell *shell = data; |
| 1560 | struct wl_resource *resource; |
| 1561 | |
Jason Ekstrand | a85118c | 2013-06-27 20:17:02 -0500 | [diff] [blame] | 1562 | resource = wl_resource_create(client, |
| 1563 | &workspace_manager_interface, 1, id); |
Jonas Ådahl | e9d2250 | 2012-08-29 22:13:01 +0200 | [diff] [blame] | 1564 | |
| 1565 | if (resource == NULL) { |
| 1566 | weston_log("couldn't add workspace manager object"); |
| 1567 | return; |
| 1568 | } |
| 1569 | |
Jason Ekstrand | a85118c | 2013-06-27 20:17:02 -0500 | [diff] [blame] | 1570 | wl_resource_set_implementation(resource, |
| 1571 | &workspace_manager_implementation, |
| 1572 | shell, unbind_resource); |
Jason Ekstrand | 651f00e | 2013-06-14 10:07:54 -0500 | [diff] [blame] | 1573 | wl_list_insert(&shell->workspaces.client_list, |
| 1574 | wl_resource_get_link(resource)); |
Jonas Ådahl | e9d2250 | 2012-08-29 22:13:01 +0200 | [diff] [blame] | 1575 | |
| 1576 | workspace_manager_send_state(resource, |
| 1577 | shell->workspaces.current, |
| 1578 | shell->workspaces.num); |
Jonas Ådahl | 8de6a1d | 2012-08-29 22:13:00 +0200 | [diff] [blame] | 1579 | } |
| 1580 | |
Pekka Paalanen | 56cdea9 | 2011-11-23 16:14:12 +0200 | [diff] [blame] | 1581 | static void |
Rusty Lynch | 1084da5 | 2013-08-15 09:10:08 -0700 | [diff] [blame] | 1582 | touch_move_grab_down(struct weston_touch_grab *grab, uint32_t time, |
Giulio Camuffo | 61ed7b6 | 2015-07-08 11:55:28 +0300 | [diff] [blame^] | 1583 | int touch_id, wl_fixed_t x, wl_fixed_t y) |
Rusty Lynch | 1084da5 | 2013-08-15 09:10:08 -0700 | [diff] [blame] | 1584 | { |
| 1585 | } |
| 1586 | |
| 1587 | static void |
| 1588 | touch_move_grab_up(struct weston_touch_grab *grab, uint32_t time, int touch_id) |
| 1589 | { |
Jonas Ådahl | 1c6e63e | 2013-10-25 23:18:04 +0200 | [diff] [blame] | 1590 | struct weston_touch_move_grab *move = |
| 1591 | (struct weston_touch_move_grab *) container_of( |
| 1592 | grab, struct shell_touch_grab, grab); |
Neil Roberts | e14aa4f | 2013-10-03 16:43:07 +0100 | [diff] [blame] | 1593 | |
Kristian Høgsberg | 8e80a31 | 2014-01-17 15:18:10 -0800 | [diff] [blame] | 1594 | if (touch_id == 0) |
| 1595 | move->active = 0; |
| 1596 | |
Jonas Ådahl | 9484b69 | 2013-12-02 22:05:03 +0100 | [diff] [blame] | 1597 | if (grab->touch->num_tp == 0) { |
Jonas Ådahl | 1c6e63e | 2013-10-25 23:18:04 +0200 | [diff] [blame] | 1598 | shell_touch_grab_end(&move->base); |
| 1599 | free(move); |
| 1600 | } |
Rusty Lynch | 1084da5 | 2013-08-15 09:10:08 -0700 | [diff] [blame] | 1601 | } |
| 1602 | |
| 1603 | static void |
| 1604 | touch_move_grab_motion(struct weston_touch_grab *grab, uint32_t time, |
Giulio Camuffo | 61ed7b6 | 2015-07-08 11:55:28 +0300 | [diff] [blame^] | 1605 | int touch_id, wl_fixed_t x, wl_fixed_t y) |
Rusty Lynch | 1084da5 | 2013-08-15 09:10:08 -0700 | [diff] [blame] | 1606 | { |
| 1607 | struct weston_touch_move_grab *move = (struct weston_touch_move_grab *) grab; |
| 1608 | struct shell_surface *shsurf = move->base.shsurf; |
| 1609 | struct weston_surface *es; |
| 1610 | int dx = wl_fixed_to_int(grab->touch->grab_x + move->dx); |
| 1611 | int dy = wl_fixed_to_int(grab->touch->grab_y + move->dy); |
| 1612 | |
Kristian Høgsberg | 8e80a31 | 2014-01-17 15:18:10 -0800 | [diff] [blame] | 1613 | if (!shsurf || !move->active) |
Rusty Lynch | 1084da5 | 2013-08-15 09:10:08 -0700 | [diff] [blame] | 1614 | return; |
| 1615 | |
| 1616 | es = shsurf->surface; |
| 1617 | |
Jason Ekstrand | 918f2dd | 2013-12-02 21:01:53 -0600 | [diff] [blame] | 1618 | weston_view_set_position(shsurf->view, dx, dy); |
Rusty Lynch | 1084da5 | 2013-08-15 09:10:08 -0700 | [diff] [blame] | 1619 | |
| 1620 | weston_compositor_schedule_repaint(es->compositor); |
| 1621 | } |
| 1622 | |
Jonas Ådahl | 1ea343e | 2013-10-25 23:18:05 +0200 | [diff] [blame] | 1623 | static void |
Jonas Ådahl | 1679f23 | 2014-04-12 09:39:51 +0200 | [diff] [blame] | 1624 | touch_move_grab_frame(struct weston_touch_grab *grab) |
| 1625 | { |
| 1626 | } |
| 1627 | |
| 1628 | static void |
Jonas Ådahl | 1ea343e | 2013-10-25 23:18:05 +0200 | [diff] [blame] | 1629 | touch_move_grab_cancel(struct weston_touch_grab *grab) |
| 1630 | { |
| 1631 | struct weston_touch_move_grab *move = |
| 1632 | (struct weston_touch_move_grab *) container_of( |
| 1633 | grab, struct shell_touch_grab, grab); |
| 1634 | |
| 1635 | shell_touch_grab_end(&move->base); |
| 1636 | free(move); |
| 1637 | } |
| 1638 | |
Rusty Lynch | 1084da5 | 2013-08-15 09:10:08 -0700 | [diff] [blame] | 1639 | static const struct weston_touch_grab_interface touch_move_grab_interface = { |
| 1640 | touch_move_grab_down, |
| 1641 | touch_move_grab_up, |
| 1642 | touch_move_grab_motion, |
Jonas Ådahl | 1679f23 | 2014-04-12 09:39:51 +0200 | [diff] [blame] | 1643 | touch_move_grab_frame, |
Jonas Ådahl | 1ea343e | 2013-10-25 23:18:05 +0200 | [diff] [blame] | 1644 | touch_move_grab_cancel, |
Rusty Lynch | 1084da5 | 2013-08-15 09:10:08 -0700 | [diff] [blame] | 1645 | }; |
| 1646 | |
| 1647 | static int |
Derek Foreman | b7674ae | 2015-07-15 13:00:37 -0500 | [diff] [blame] | 1648 | surface_touch_move(struct shell_surface *shsurf, struct weston_touch *touch) |
Rusty Lynch | 1084da5 | 2013-08-15 09:10:08 -0700 | [diff] [blame] | 1649 | { |
| 1650 | struct weston_touch_move_grab *move; |
| 1651 | |
| 1652 | if (!shsurf) |
| 1653 | return -1; |
| 1654 | |
Ander Conselvan de Oliveira | 6d43f04 | 2014-05-07 14:22:23 +0300 | [diff] [blame] | 1655 | if (shsurf->state.fullscreen || shsurf->state.maximized) |
Rusty Lynch | 1084da5 | 2013-08-15 09:10:08 -0700 | [diff] [blame] | 1656 | return 0; |
| 1657 | |
| 1658 | move = malloc(sizeof *move); |
| 1659 | if (!move) |
| 1660 | return -1; |
| 1661 | |
Kristian Høgsberg | 8e80a31 | 2014-01-17 15:18:10 -0800 | [diff] [blame] | 1662 | move->active = 1; |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 1663 | move->dx = wl_fixed_from_double(shsurf->view->geometry.x) - |
Derek Foreman | b7674ae | 2015-07-15 13:00:37 -0500 | [diff] [blame] | 1664 | touch->grab_x; |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 1665 | move->dy = wl_fixed_from_double(shsurf->view->geometry.y) - |
Derek Foreman | b7674ae | 2015-07-15 13:00:37 -0500 | [diff] [blame] | 1666 | touch->grab_y; |
Rusty Lynch | 1084da5 | 2013-08-15 09:10:08 -0700 | [diff] [blame] | 1667 | |
| 1668 | shell_touch_grab_start(&move->base, &touch_move_grab_interface, shsurf, |
Derek Foreman | b7674ae | 2015-07-15 13:00:37 -0500 | [diff] [blame] | 1669 | touch); |
Rusty Lynch | 1084da5 | 2013-08-15 09:10:08 -0700 | [diff] [blame] | 1670 | |
| 1671 | return 0; |
| 1672 | } |
| 1673 | |
| 1674 | static void |
Kristian Høgsberg | 6848c25 | 2013-05-08 22:02:59 -0400 | [diff] [blame] | 1675 | noop_grab_focus(struct weston_pointer_grab *grab) |
Kristian Høgsberg | 9ddb826 | 2012-01-04 21:30:29 -0500 | [diff] [blame] | 1676 | { |
Kristian Høgsberg | 9ddb826 | 2012-01-04 21:30:29 -0500 | [diff] [blame] | 1677 | } |
| 1678 | |
| 1679 | static void |
Kristian Høgsberg | ae356ae | 2014-04-29 16:03:54 -0700 | [diff] [blame] | 1680 | constrain_position(struct weston_move_grab *move, int *cx, int *cy) |
| 1681 | { |
| 1682 | struct shell_surface *shsurf = move->base.shsurf; |
| 1683 | struct weston_pointer *pointer = move->base.grab.pointer; |
Derek Foreman | 6feb0f9 | 2015-04-15 12:23:56 -0500 | [diff] [blame] | 1684 | int x, y, bottom; |
Kristian Høgsberg | ae356ae | 2014-04-29 16:03:54 -0700 | [diff] [blame] | 1685 | const int safety = 50; |
Derek Foreman | 6feb0f9 | 2015-04-15 12:23:56 -0500 | [diff] [blame] | 1686 | pixman_rectangle32_t area; |
Kristian Høgsberg | ae356ae | 2014-04-29 16:03:54 -0700 | [diff] [blame] | 1687 | |
| 1688 | x = wl_fixed_to_int(pointer->x + move->dx); |
| 1689 | y = wl_fixed_to_int(pointer->y + move->dy); |
| 1690 | |
Jonny Lamb | d73c694 | 2014-08-20 15:53:20 +0200 | [diff] [blame] | 1691 | if (shsurf->shell->panel_position == DESKTOP_SHELL_PANEL_POSITION_TOP) { |
Derek Foreman | 6feb0f9 | 2015-04-15 12:23:56 -0500 | [diff] [blame] | 1692 | get_output_work_area(shsurf->shell, |
| 1693 | shsurf->surface->output, |
| 1694 | &area); |
Kristian Høgsberg | ae356ae | 2014-04-29 16:03:54 -0700 | [diff] [blame] | 1695 | |
Derek Foreman | 6feb0f9 | 2015-04-15 12:23:56 -0500 | [diff] [blame] | 1696 | bottom = y + shsurf->geometry.height + shsurf->geometry.y; |
| 1697 | if (bottom - safety < area.y) |
| 1698 | y = area.y + safety - shsurf->geometry.height |
| 1699 | - shsurf->geometry.y; |
Jonny Lamb | d73c694 | 2014-08-20 15:53:20 +0200 | [diff] [blame] | 1700 | |
| 1701 | if (move->client_initiated && |
Derek Foreman | 6feb0f9 | 2015-04-15 12:23:56 -0500 | [diff] [blame] | 1702 | y + shsurf->geometry.y < area.y) |
| 1703 | y = area.y - shsurf->geometry.y; |
| 1704 | |
Jonny Lamb | d73c694 | 2014-08-20 15:53:20 +0200 | [diff] [blame] | 1705 | } |
Kristian Høgsberg | ae356ae | 2014-04-29 16:03:54 -0700 | [diff] [blame] | 1706 | |
| 1707 | *cx = x; |
| 1708 | *cy = y; |
| 1709 | } |
| 1710 | |
| 1711 | static void |
Giulio Camuffo | 1959ab8 | 2013-11-14 23:42:52 +0100 | [diff] [blame] | 1712 | move_grab_motion(struct weston_pointer_grab *grab, uint32_t time, |
| 1713 | wl_fixed_t x, wl_fixed_t y) |
Kristian Høgsberg | 4cca349 | 2011-01-18 07:53:49 -0500 | [diff] [blame] | 1714 | { |
Kristian Høgsberg | 8334bc1 | 2012-01-03 10:29:47 -0500 | [diff] [blame] | 1715 | struct weston_move_grab *move = (struct weston_move_grab *) grab; |
Kristian Høgsberg | 02bbabb | 2013-05-06 22:15:05 -0400 | [diff] [blame] | 1716 | struct weston_pointer *pointer = grab->pointer; |
Ander Conselvan de Oliveira | fe0444a | 2012-04-04 17:48:05 +0300 | [diff] [blame] | 1717 | struct shell_surface *shsurf = move->base.shsurf; |
Kristian Høgsberg | ae356ae | 2014-04-29 16:03:54 -0700 | [diff] [blame] | 1718 | int cx, cy; |
Giulio Camuffo | 1959ab8 | 2013-11-14 23:42:52 +0100 | [diff] [blame] | 1719 | |
| 1720 | weston_pointer_move(pointer, x, y); |
Ander Conselvan de Oliveira | fe0444a | 2012-04-04 17:48:05 +0300 | [diff] [blame] | 1721 | if (!shsurf) |
| 1722 | return; |
| 1723 | |
Kristian Høgsberg | ae356ae | 2014-04-29 16:03:54 -0700 | [diff] [blame] | 1724 | constrain_position(move, &cx, &cy); |
| 1725 | |
| 1726 | weston_view_set_position(shsurf->view, cx, cy); |
Kristian Høgsberg | 4cca349 | 2011-01-18 07:53:49 -0500 | [diff] [blame] | 1727 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 1728 | weston_compositor_schedule_repaint(shsurf->surface->compositor); |
Kristian Høgsberg | 4cca349 | 2011-01-18 07:53:49 -0500 | [diff] [blame] | 1729 | } |
| 1730 | |
| 1731 | static void |
Kristian Høgsberg | 02bbabb | 2013-05-06 22:15:05 -0400 | [diff] [blame] | 1732 | move_grab_button(struct weston_pointer_grab *grab, |
Daniel Stone | 4dbadb1 | 2012-05-30 16:31:51 +0100 | [diff] [blame] | 1733 | uint32_t time, uint32_t button, uint32_t state_w) |
Kristian Høgsberg | 4cca349 | 2011-01-18 07:53:49 -0500 | [diff] [blame] | 1734 | { |
Ander Conselvan de Oliveira | fe0444a | 2012-04-04 17:48:05 +0300 | [diff] [blame] | 1735 | struct shell_grab *shell_grab = container_of(grab, struct shell_grab, |
| 1736 | grab); |
Kristian Høgsberg | 02bbabb | 2013-05-06 22:15:05 -0400 | [diff] [blame] | 1737 | struct weston_pointer *pointer = grab->pointer; |
Daniel Stone | 4dbadb1 | 2012-05-30 16:31:51 +0100 | [diff] [blame] | 1738 | enum wl_pointer_button_state state = state_w; |
Kristian Høgsberg | 4cca349 | 2011-01-18 07:53:49 -0500 | [diff] [blame] | 1739 | |
Daniel Stone | 4dbadb1 | 2012-05-30 16:31:51 +0100 | [diff] [blame] | 1740 | if (pointer->button_count == 0 && |
| 1741 | state == WL_POINTER_BUTTON_STATE_RELEASED) { |
Ander Conselvan de Oliveira | b9d2a0f | 2012-06-28 18:08:05 +0300 | [diff] [blame] | 1742 | shell_grab_end(shell_grab); |
Kristian Høgsberg | 9ddb826 | 2012-01-04 21:30:29 -0500 | [diff] [blame] | 1743 | free(grab); |
| 1744 | } |
Kristian Høgsberg | 4cca349 | 2011-01-18 07:53:49 -0500 | [diff] [blame] | 1745 | } |
| 1746 | |
Jonas Ådahl | 1ea343e | 2013-10-25 23:18:05 +0200 | [diff] [blame] | 1747 | static void |
| 1748 | move_grab_cancel(struct weston_pointer_grab *grab) |
| 1749 | { |
| 1750 | struct shell_grab *shell_grab = |
| 1751 | container_of(grab, struct shell_grab, grab); |
| 1752 | |
| 1753 | shell_grab_end(shell_grab); |
| 1754 | free(grab); |
| 1755 | } |
| 1756 | |
Kristian Høgsberg | 02bbabb | 2013-05-06 22:15:05 -0400 | [diff] [blame] | 1757 | static const struct weston_pointer_grab_interface move_grab_interface = { |
Kristian Høgsberg | 9ddb826 | 2012-01-04 21:30:29 -0500 | [diff] [blame] | 1758 | noop_grab_focus, |
Kristian Høgsberg | 4cca349 | 2011-01-18 07:53:49 -0500 | [diff] [blame] | 1759 | move_grab_motion, |
| 1760 | move_grab_button, |
Jonas Ådahl | 1ea343e | 2013-10-25 23:18:05 +0200 | [diff] [blame] | 1761 | move_grab_cancel, |
Kristian Høgsberg | 4cca349 | 2011-01-18 07:53:49 -0500 | [diff] [blame] | 1762 | }; |
| 1763 | |
Kristian Høgsberg | 9e31bff | 2012-08-01 00:08:07 -0400 | [diff] [blame] | 1764 | static int |
Derek Foreman | 794fa0e | 2015-07-15 13:00:38 -0500 | [diff] [blame] | 1765 | surface_move(struct shell_surface *shsurf, struct weston_pointer *pointer, |
Derek Foreman | cf7d95a | 2015-06-03 15:53:22 -0500 | [diff] [blame] | 1766 | bool client_initiated) |
Kristian Høgsberg | 9e31bff | 2012-08-01 00:08:07 -0400 | [diff] [blame] | 1767 | { |
| 1768 | struct weston_move_grab *move; |
| 1769 | |
| 1770 | if (!shsurf) |
| 1771 | return -1; |
| 1772 | |
Kristian Høgsberg | a4b620e | 2014-04-30 16:05:49 -0700 | [diff] [blame] | 1773 | if (shsurf->grabbed || |
| 1774 | shsurf->state.fullscreen || shsurf->state.maximized) |
Kristian Høgsberg | 9e31bff | 2012-08-01 00:08:07 -0400 | [diff] [blame] | 1775 | return 0; |
| 1776 | |
| 1777 | move = malloc(sizeof *move); |
| 1778 | if (!move) |
| 1779 | return -1; |
| 1780 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 1781 | move->dx = wl_fixed_from_double(shsurf->view->geometry.x) - |
Derek Foreman | 794fa0e | 2015-07-15 13:00:38 -0500 | [diff] [blame] | 1782 | pointer->grab_x; |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 1783 | move->dy = wl_fixed_from_double(shsurf->view->geometry.y) - |
Derek Foreman | 794fa0e | 2015-07-15 13:00:38 -0500 | [diff] [blame] | 1784 | pointer->grab_y; |
Kristian Høgsberg | ae356ae | 2014-04-29 16:03:54 -0700 | [diff] [blame] | 1785 | move->client_initiated = client_initiated; |
Kristian Høgsberg | 9e31bff | 2012-08-01 00:08:07 -0400 | [diff] [blame] | 1786 | |
| 1787 | shell_grab_start(&move->base, &move_grab_interface, shsurf, |
Derek Foreman | 794fa0e | 2015-07-15 13:00:38 -0500 | [diff] [blame] | 1788 | pointer, DESKTOP_SHELL_CURSOR_MOVE); |
Kristian Høgsberg | 9e31bff | 2012-08-01 00:08:07 -0400 | [diff] [blame] | 1789 | |
| 1790 | return 0; |
| 1791 | } |
| 1792 | |
| 1793 | static void |
Rafael Antognolli | e2a3455 | 2013-12-03 15:35:45 -0200 | [diff] [blame] | 1794 | common_surface_move(struct wl_resource *resource, |
| 1795 | struct wl_resource *seat_resource, uint32_t serial) |
Kristian Høgsberg | 9e31bff | 2012-08-01 00:08:07 -0400 | [diff] [blame] | 1796 | { |
Jason Ekstrand | 44a3863 | 2013-06-14 10:08:00 -0500 | [diff] [blame] | 1797 | struct weston_seat *seat = wl_resource_get_user_data(seat_resource); |
Derek Foreman | 1281a36 | 2015-07-31 16:55:32 -0500 | [diff] [blame] | 1798 | struct weston_pointer *pointer = weston_seat_get_pointer(seat); |
| 1799 | struct weston_touch *touch = weston_seat_get_touch(seat); |
Jason Ekstrand | 651f00e | 2013-06-14 10:07:54 -0500 | [diff] [blame] | 1800 | struct shell_surface *shsurf = wl_resource_get_user_data(resource); |
Giulio Camuffo | 61da3fc | 2013-04-25 13:57:45 +0300 | [diff] [blame] | 1801 | struct weston_surface *surface; |
Kristian Høgsberg | 9e31bff | 2012-08-01 00:08:07 -0400 | [diff] [blame] | 1802 | |
Derek Foreman | 1281a36 | 2015-07-31 16:55:32 -0500 | [diff] [blame] | 1803 | if (pointer && |
| 1804 | pointer->focus && |
| 1805 | pointer->button_count > 0 && |
| 1806 | pointer->grab_serial == serial) { |
| 1807 | surface = weston_surface_get_main_surface(pointer->focus->surface); |
U. Artie Eoff | cf5737a | 2014-01-17 10:08:25 -0800 | [diff] [blame] | 1808 | if ((surface == shsurf->surface) && |
Derek Foreman | 1281a36 | 2015-07-31 16:55:32 -0500 | [diff] [blame] | 1809 | (surface_move(shsurf, pointer, true) < 0)) |
Rusty Lynch | 1084da5 | 2013-08-15 09:10:08 -0700 | [diff] [blame] | 1810 | wl_resource_post_no_memory(resource); |
Derek Foreman | 1281a36 | 2015-07-31 16:55:32 -0500 | [diff] [blame] | 1811 | } else if (touch && |
| 1812 | touch->focus && |
| 1813 | touch->grab_serial == serial) { |
| 1814 | surface = weston_surface_get_main_surface(touch->focus->surface); |
U. Artie Eoff | cf5737a | 2014-01-17 10:08:25 -0800 | [diff] [blame] | 1815 | if ((surface == shsurf->surface) && |
Derek Foreman | 1281a36 | 2015-07-31 16:55:32 -0500 | [diff] [blame] | 1816 | (surface_touch_move(shsurf, touch) < 0)) |
Rusty Lynch | 1084da5 | 2013-08-15 09:10:08 -0700 | [diff] [blame] | 1817 | wl_resource_post_no_memory(resource); |
| 1818 | } |
Kristian Høgsberg | 9e31bff | 2012-08-01 00:08:07 -0400 | [diff] [blame] | 1819 | } |
| 1820 | |
Rafael Antognolli | e2a3455 | 2013-12-03 15:35:45 -0200 | [diff] [blame] | 1821 | static void |
| 1822 | shell_surface_move(struct wl_client *client, struct wl_resource *resource, |
| 1823 | struct wl_resource *seat_resource, uint32_t serial) |
| 1824 | { |
| 1825 | common_surface_move(resource, seat_resource, serial); |
| 1826 | } |
| 1827 | |
Kristian Høgsberg | 9e31bff | 2012-08-01 00:08:07 -0400 | [diff] [blame] | 1828 | struct weston_resize_grab { |
| 1829 | struct shell_grab base; |
| 1830 | uint32_t edges; |
| 1831 | int32_t width, height; |
| 1832 | }; |
| 1833 | |
| 1834 | static void |
Giulio Camuffo | 1959ab8 | 2013-11-14 23:42:52 +0100 | [diff] [blame] | 1835 | resize_grab_motion(struct weston_pointer_grab *grab, uint32_t time, |
| 1836 | wl_fixed_t x, wl_fixed_t y) |
Kristian Høgsberg | 9e31bff | 2012-08-01 00:08:07 -0400 | [diff] [blame] | 1837 | { |
| 1838 | struct weston_resize_grab *resize = (struct weston_resize_grab *) grab; |
Kristian Høgsberg | 02bbabb | 2013-05-06 22:15:05 -0400 | [diff] [blame] | 1839 | struct weston_pointer *pointer = grab->pointer; |
Kristian Høgsberg | 9e31bff | 2012-08-01 00:08:07 -0400 | [diff] [blame] | 1840 | struct shell_surface *shsurf = resize->base.shsurf; |
| 1841 | int32_t width, height; |
| 1842 | wl_fixed_t from_x, from_y; |
| 1843 | wl_fixed_t to_x, to_y; |
| 1844 | |
Giulio Camuffo | 1959ab8 | 2013-11-14 23:42:52 +0100 | [diff] [blame] | 1845 | weston_pointer_move(pointer, x, y); |
| 1846 | |
Kristian Høgsberg | e0b9d5b | 2014-04-30 13:45:49 -0700 | [diff] [blame] | 1847 | if (!shsurf) |
Kristian Høgsberg | 9e31bff | 2012-08-01 00:08:07 -0400 | [diff] [blame] | 1848 | return; |
| 1849 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 1850 | weston_view_from_global_fixed(shsurf->view, |
| 1851 | pointer->grab_x, pointer->grab_y, |
| 1852 | &from_x, &from_y); |
| 1853 | weston_view_from_global_fixed(shsurf->view, |
| 1854 | pointer->x, pointer->y, &to_x, &to_y); |
Kristian Høgsberg | 9e31bff | 2012-08-01 00:08:07 -0400 | [diff] [blame] | 1855 | |
| 1856 | width = resize->width; |
| 1857 | if (resize->edges & WL_SHELL_SURFACE_RESIZE_LEFT) { |
| 1858 | width += wl_fixed_to_int(from_x - to_x); |
| 1859 | } else if (resize->edges & WL_SHELL_SURFACE_RESIZE_RIGHT) { |
| 1860 | width += wl_fixed_to_int(to_x - from_x); |
| 1861 | } |
| 1862 | |
| 1863 | height = resize->height; |
| 1864 | if (resize->edges & WL_SHELL_SURFACE_RESIZE_TOP) { |
| 1865 | height += wl_fixed_to_int(from_y - to_y); |
| 1866 | } else if (resize->edges & WL_SHELL_SURFACE_RESIZE_BOTTOM) { |
| 1867 | height += wl_fixed_to_int(to_y - from_y); |
| 1868 | } |
| 1869 | |
Derek Foreman | 70ac0ed | 2015-03-18 11:16:33 -0500 | [diff] [blame] | 1870 | if (width < 1) |
| 1871 | width = 1; |
| 1872 | if (height < 1) |
| 1873 | height = 1; |
Jasper St. Pierre | ac985be | 2014-04-28 11:19:28 -0400 | [diff] [blame] | 1874 | shsurf->client->send_configure(shsurf->surface, width, height); |
Kristian Høgsberg | 9e31bff | 2012-08-01 00:08:07 -0400 | [diff] [blame] | 1875 | } |
| 1876 | |
| 1877 | static void |
Jasper St. Pierre | ac985be | 2014-04-28 11:19:28 -0400 | [diff] [blame] | 1878 | 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] | 1879 | { |
| 1880 | struct shell_surface *shsurf = get_shell_surface(surface); |
| 1881 | |
U. Artie Eoff | cf5737a | 2014-01-17 10:08:25 -0800 | [diff] [blame] | 1882 | assert(shsurf); |
| 1883 | |
Kristian Høgsberg | e0b9d5b | 2014-04-30 13:45:49 -0700 | [diff] [blame] | 1884 | if (shsurf->resource) |
| 1885 | wl_shell_surface_send_configure(shsurf->resource, |
Jasper St. Pierre | ac985be | 2014-04-28 11:19:28 -0400 | [diff] [blame] | 1886 | shsurf->resize_edges, |
| 1887 | width, height); |
Kristian Høgsberg | 9e31bff | 2012-08-01 00:08:07 -0400 | [diff] [blame] | 1888 | } |
| 1889 | |
| 1890 | static const struct weston_shell_client shell_client = { |
| 1891 | send_configure |
| 1892 | }; |
| 1893 | |
| 1894 | static void |
Kristian Høgsberg | 02bbabb | 2013-05-06 22:15:05 -0400 | [diff] [blame] | 1895 | resize_grab_button(struct weston_pointer_grab *grab, |
Kristian Høgsberg | 9e31bff | 2012-08-01 00:08:07 -0400 | [diff] [blame] | 1896 | uint32_t time, uint32_t button, uint32_t state_w) |
| 1897 | { |
| 1898 | struct weston_resize_grab *resize = (struct weston_resize_grab *) grab; |
Kristian Høgsberg | 02bbabb | 2013-05-06 22:15:05 -0400 | [diff] [blame] | 1899 | struct weston_pointer *pointer = grab->pointer; |
Kristian Høgsberg | 9e31bff | 2012-08-01 00:08:07 -0400 | [diff] [blame] | 1900 | enum wl_pointer_button_state state = state_w; |
| 1901 | |
| 1902 | if (pointer->button_count == 0 && |
| 1903 | state == WL_POINTER_BUTTON_STATE_RELEASED) { |
| 1904 | shell_grab_end(&resize->base); |
| 1905 | free(grab); |
| 1906 | } |
| 1907 | } |
| 1908 | |
Jonas Ådahl | 1ea343e | 2013-10-25 23:18:05 +0200 | [diff] [blame] | 1909 | static void |
| 1910 | resize_grab_cancel(struct weston_pointer_grab *grab) |
| 1911 | { |
| 1912 | struct weston_resize_grab *resize = (struct weston_resize_grab *) grab; |
| 1913 | |
| 1914 | shell_grab_end(&resize->base); |
| 1915 | free(grab); |
| 1916 | } |
| 1917 | |
Kristian Høgsberg | 02bbabb | 2013-05-06 22:15:05 -0400 | [diff] [blame] | 1918 | static const struct weston_pointer_grab_interface resize_grab_interface = { |
Kristian Høgsberg | 9e31bff | 2012-08-01 00:08:07 -0400 | [diff] [blame] | 1919 | noop_grab_focus, |
| 1920 | resize_grab_motion, |
| 1921 | resize_grab_button, |
Jonas Ådahl | 1ea343e | 2013-10-25 23:18:05 +0200 | [diff] [blame] | 1922 | resize_grab_cancel, |
Kristian Høgsberg | 9e31bff | 2012-08-01 00:08:07 -0400 | [diff] [blame] | 1923 | }; |
| 1924 | |
Giulio Camuffo | b836664 | 2013-04-25 13:57:46 +0300 | [diff] [blame] | 1925 | /* |
| 1926 | * Returns the bounding box of a surface and all its sub-surfaces, |
| 1927 | * in the surface coordinates system. */ |
| 1928 | static void |
| 1929 | surface_subsurfaces_boundingbox(struct weston_surface *surface, int32_t *x, |
| 1930 | int32_t *y, int32_t *w, int32_t *h) { |
| 1931 | pixman_region32_t region; |
| 1932 | pixman_box32_t *box; |
| 1933 | struct weston_subsurface *subsurface; |
| 1934 | |
| 1935 | pixman_region32_init_rect(®ion, 0, 0, |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 1936 | surface->width, |
| 1937 | surface->height); |
Giulio Camuffo | b836664 | 2013-04-25 13:57:46 +0300 | [diff] [blame] | 1938 | |
| 1939 | wl_list_for_each(subsurface, &surface->subsurface_list, parent_link) { |
| 1940 | pixman_region32_union_rect(®ion, ®ion, |
| 1941 | subsurface->position.x, |
| 1942 | subsurface->position.y, |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 1943 | subsurface->surface->width, |
| 1944 | subsurface->surface->height); |
Giulio Camuffo | b836664 | 2013-04-25 13:57:46 +0300 | [diff] [blame] | 1945 | } |
| 1946 | |
| 1947 | box = pixman_region32_extents(®ion); |
| 1948 | if (x) |
| 1949 | *x = box->x1; |
| 1950 | if (y) |
| 1951 | *y = box->y1; |
| 1952 | if (w) |
| 1953 | *w = box->x2 - box->x1; |
| 1954 | if (h) |
| 1955 | *h = box->y2 - box->y1; |
| 1956 | |
| 1957 | pixman_region32_fini(®ion); |
| 1958 | } |
| 1959 | |
Kristian Høgsberg | 9e31bff | 2012-08-01 00:08:07 -0400 | [diff] [blame] | 1960 | static int |
| 1961 | surface_resize(struct shell_surface *shsurf, |
Derek Foreman | 8fbebbd | 2015-07-15 13:00:40 -0500 | [diff] [blame] | 1962 | struct weston_pointer *pointer, uint32_t edges) |
Kristian Høgsberg | 9e31bff | 2012-08-01 00:08:07 -0400 | [diff] [blame] | 1963 | { |
| 1964 | struct weston_resize_grab *resize; |
Ondřej Majerech | ae9c4fc | 2014-08-21 15:47:22 +0200 | [diff] [blame] | 1965 | const unsigned resize_topbottom = |
| 1966 | WL_SHELL_SURFACE_RESIZE_TOP | WL_SHELL_SURFACE_RESIZE_BOTTOM; |
| 1967 | const unsigned resize_leftright = |
| 1968 | WL_SHELL_SURFACE_RESIZE_LEFT | WL_SHELL_SURFACE_RESIZE_RIGHT; |
| 1969 | const unsigned resize_any = resize_topbottom | resize_leftright; |
Kristian Høgsberg | 9e31bff | 2012-08-01 00:08:07 -0400 | [diff] [blame] | 1970 | |
Kristian Høgsberg | a4b620e | 2014-04-30 16:05:49 -0700 | [diff] [blame] | 1971 | if (shsurf->grabbed || |
| 1972 | shsurf->state.fullscreen || shsurf->state.maximized) |
Kristian Høgsberg | 9e31bff | 2012-08-01 00:08:07 -0400 | [diff] [blame] | 1973 | return 0; |
| 1974 | |
Ondřej Majerech | ae9c4fc | 2014-08-21 15:47:22 +0200 | [diff] [blame] | 1975 | /* Check for invalid edge combinations. */ |
| 1976 | if (edges == WL_SHELL_SURFACE_RESIZE_NONE || edges > resize_any || |
| 1977 | (edges & resize_topbottom) == resize_topbottom || |
| 1978 | (edges & resize_leftright) == resize_leftright) |
Kristian Høgsberg | 9e31bff | 2012-08-01 00:08:07 -0400 | [diff] [blame] | 1979 | return 0; |
| 1980 | |
| 1981 | resize = malloc(sizeof *resize); |
| 1982 | if (!resize) |
| 1983 | return -1; |
| 1984 | |
| 1985 | resize->edges = edges; |
Kristian Høgsberg | 9e31bff | 2012-08-01 00:08:07 -0400 | [diff] [blame] | 1986 | |
Jasper St. Pierre | ccf48fb | 2014-05-02 10:21:38 -0400 | [diff] [blame] | 1987 | resize->width = shsurf->geometry.width; |
| 1988 | resize->height = shsurf->geometry.height; |
Jasper St. Pierre | bd65e50 | 2014-07-14 16:28:48 -0400 | [diff] [blame] | 1989 | |
Kristian Høgsberg | 44cd196 | 2014-02-05 21:36:04 -0800 | [diff] [blame] | 1990 | shsurf->resize_edges = edges; |
Jasper St. Pierre | 5befdda | 2014-05-06 08:50:47 -0400 | [diff] [blame] | 1991 | shell_surface_state_changed(shsurf); |
Kristian Høgsberg | 9e31bff | 2012-08-01 00:08:07 -0400 | [diff] [blame] | 1992 | shell_grab_start(&resize->base, &resize_grab_interface, shsurf, |
Derek Foreman | 8fbebbd | 2015-07-15 13:00:40 -0500 | [diff] [blame] | 1993 | pointer, edges); |
Kristian Høgsberg | 9e31bff | 2012-08-01 00:08:07 -0400 | [diff] [blame] | 1994 | |
| 1995 | return 0; |
| 1996 | } |
| 1997 | |
| 1998 | static void |
Rafael Antognolli | e2a3455 | 2013-12-03 15:35:45 -0200 | [diff] [blame] | 1999 | common_surface_resize(struct wl_resource *resource, |
| 2000 | struct wl_resource *seat_resource, uint32_t serial, |
| 2001 | uint32_t edges) |
Kristian Høgsberg | 9e31bff | 2012-08-01 00:08:07 -0400 | [diff] [blame] | 2002 | { |
Jason Ekstrand | 44a3863 | 2013-06-14 10:08:00 -0500 | [diff] [blame] | 2003 | struct weston_seat *seat = wl_resource_get_user_data(seat_resource); |
Derek Foreman | 1281a36 | 2015-07-31 16:55:32 -0500 | [diff] [blame] | 2004 | struct weston_pointer *pointer = weston_seat_get_pointer(seat); |
Jason Ekstrand | 651f00e | 2013-06-14 10:07:54 -0500 | [diff] [blame] | 2005 | struct shell_surface *shsurf = wl_resource_get_user_data(resource); |
Giulio Camuffo | 61da3fc | 2013-04-25 13:57:45 +0300 | [diff] [blame] | 2006 | struct weston_surface *surface; |
Kristian Høgsberg | 9e31bff | 2012-08-01 00:08:07 -0400 | [diff] [blame] | 2007 | |
Derek Foreman | 1281a36 | 2015-07-31 16:55:32 -0500 | [diff] [blame] | 2008 | if (!pointer || |
| 2009 | pointer->button_count == 0 || |
| 2010 | pointer->grab_serial != serial || |
| 2011 | pointer->focus == NULL) |
Kristian Høgsberg | 70f2901 | 2014-01-09 15:43:17 -0800 | [diff] [blame] | 2012 | return; |
| 2013 | |
Derek Foreman | 1281a36 | 2015-07-31 16:55:32 -0500 | [diff] [blame] | 2014 | surface = weston_surface_get_main_surface(pointer->focus->surface); |
Kristian Høgsberg | 70f2901 | 2014-01-09 15:43:17 -0800 | [diff] [blame] | 2015 | if (surface != shsurf->surface) |
Kristian Høgsberg | 9e31bff | 2012-08-01 00:08:07 -0400 | [diff] [blame] | 2016 | return; |
| 2017 | |
Derek Foreman | 1281a36 | 2015-07-31 16:55:32 -0500 | [diff] [blame] | 2018 | if (surface_resize(shsurf, pointer, edges) < 0) |
Kristian Høgsberg | 9e31bff | 2012-08-01 00:08:07 -0400 | [diff] [blame] | 2019 | wl_resource_post_no_memory(resource); |
| 2020 | } |
| 2021 | |
Scott Moreau | c3e54eb | 2012-04-17 19:06:20 -0600 | [diff] [blame] | 2022 | static void |
Rafael Antognolli | e2a3455 | 2013-12-03 15:35:45 -0200 | [diff] [blame] | 2023 | shell_surface_resize(struct wl_client *client, struct wl_resource *resource, |
| 2024 | struct wl_resource *seat_resource, uint32_t serial, |
| 2025 | uint32_t edges) |
| 2026 | { |
| 2027 | common_surface_resize(resource, seat_resource, serial, edges); |
| 2028 | } |
| 2029 | |
| 2030 | static void |
Kristian Høgsberg | 6848c25 | 2013-05-08 22:02:59 -0400 | [diff] [blame] | 2031 | busy_cursor_grab_focus(struct weston_pointer_grab *base) |
Scott Moreau | c3e54eb | 2012-04-17 19:06:20 -0600 | [diff] [blame] | 2032 | { |
Kristian Høgsberg | d56bd90 | 2012-06-05 09:58:51 -0400 | [diff] [blame] | 2033 | struct shell_grab *grab = (struct shell_grab *) base; |
Kristian Høgsberg | 6848c25 | 2013-05-08 22:02:59 -0400 | [diff] [blame] | 2034 | struct weston_pointer *pointer = base->pointer; |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 2035 | struct weston_view *view; |
Kristian Høgsberg | 6848c25 | 2013-05-08 22:02:59 -0400 | [diff] [blame] | 2036 | wl_fixed_t sx, sy; |
| 2037 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 2038 | view = weston_compositor_pick_view(pointer->seat->compositor, |
| 2039 | pointer->x, pointer->y, |
| 2040 | &sx, &sy); |
Scott Moreau | c3e54eb | 2012-04-17 19:06:20 -0600 | [diff] [blame] | 2041 | |
Kristian Høgsberg | 2bff94e | 2014-02-11 12:22:51 -0800 | [diff] [blame] | 2042 | if (!grab->shsurf || grab->shsurf->surface != view->surface) { |
| 2043 | shell_grab_end(grab); |
| 2044 | free(grab); |
| 2045 | } |
Scott Moreau | c3e54eb | 2012-04-17 19:06:20 -0600 | [diff] [blame] | 2046 | } |
| 2047 | |
| 2048 | static void |
Giulio Camuffo | 1959ab8 | 2013-11-14 23:42:52 +0100 | [diff] [blame] | 2049 | busy_cursor_grab_motion(struct weston_pointer_grab *grab, uint32_t time, |
| 2050 | wl_fixed_t x, wl_fixed_t y) |
Scott Moreau | c3e54eb | 2012-04-17 19:06:20 -0600 | [diff] [blame] | 2051 | { |
Giulio Camuffo | 1959ab8 | 2013-11-14 23:42:52 +0100 | [diff] [blame] | 2052 | weston_pointer_move(grab->pointer, x, y); |
Kristian Høgsberg | d56bd90 | 2012-06-05 09:58:51 -0400 | [diff] [blame] | 2053 | } |
Scott Moreau | c3e54eb | 2012-04-17 19:06:20 -0600 | [diff] [blame] | 2054 | |
Kristian Høgsberg | d56bd90 | 2012-06-05 09:58:51 -0400 | [diff] [blame] | 2055 | static void |
Kristian Høgsberg | 02bbabb | 2013-05-06 22:15:05 -0400 | [diff] [blame] | 2056 | busy_cursor_grab_button(struct weston_pointer_grab *base, |
Kristian Høgsberg | d56bd90 | 2012-06-05 09:58:51 -0400 | [diff] [blame] | 2057 | uint32_t time, uint32_t button, uint32_t state) |
| 2058 | { |
Kristian Høgsberg | bbe9839 | 2012-08-01 00:20:21 -0400 | [diff] [blame] | 2059 | struct shell_grab *grab = (struct shell_grab *) base; |
Kristian Høgsberg | e122b7b | 2013-05-08 16:47:00 -0400 | [diff] [blame] | 2060 | struct shell_surface *shsurf = grab->shsurf; |
Derek Foreman | 794fa0e | 2015-07-15 13:00:38 -0500 | [diff] [blame] | 2061 | struct weston_pointer *pointer = grab->grab.pointer; |
| 2062 | struct weston_seat *seat = pointer->seat; |
Kristian Høgsberg | bbe9839 | 2012-08-01 00:20:21 -0400 | [diff] [blame] | 2063 | |
Kristian Høgsberg | bbe9839 | 2012-08-01 00:20:21 -0400 | [diff] [blame] | 2064 | if (shsurf && button == BTN_LEFT && state) { |
Emilio Pozuelo Monfort | 9e7c759 | 2014-01-30 14:01:10 +0100 | [diff] [blame] | 2065 | activate(shsurf->shell, shsurf->surface, seat, true); |
Derek Foreman | 794fa0e | 2015-07-15 13:00:38 -0500 | [diff] [blame] | 2066 | surface_move(shsurf, pointer, false); |
Kristian Høgsberg | 0c36903 | 2013-02-14 21:31:44 -0500 | [diff] [blame] | 2067 | } else if (shsurf && button == BTN_RIGHT && state) { |
Emilio Pozuelo Monfort | 9e7c759 | 2014-01-30 14:01:10 +0100 | [diff] [blame] | 2068 | activate(shsurf->shell, shsurf->surface, seat, true); |
Derek Foreman | 74de469 | 2015-07-15 13:00:39 -0500 | [diff] [blame] | 2069 | surface_rotate(shsurf, pointer); |
Kristian Høgsberg | bbe9839 | 2012-08-01 00:20:21 -0400 | [diff] [blame] | 2070 | } |
Kristian Høgsberg | d56bd90 | 2012-06-05 09:58:51 -0400 | [diff] [blame] | 2071 | } |
| 2072 | |
Jonas Ådahl | 1ea343e | 2013-10-25 23:18:05 +0200 | [diff] [blame] | 2073 | static void |
| 2074 | busy_cursor_grab_cancel(struct weston_pointer_grab *base) |
| 2075 | { |
| 2076 | struct shell_grab *grab = (struct shell_grab *) base; |
| 2077 | |
| 2078 | shell_grab_end(grab); |
| 2079 | free(grab); |
| 2080 | } |
| 2081 | |
Kristian Høgsberg | 02bbabb | 2013-05-06 22:15:05 -0400 | [diff] [blame] | 2082 | static const struct weston_pointer_grab_interface busy_cursor_grab_interface = { |
Kristian Høgsberg | d56bd90 | 2012-06-05 09:58:51 -0400 | [diff] [blame] | 2083 | busy_cursor_grab_focus, |
| 2084 | busy_cursor_grab_motion, |
| 2085 | busy_cursor_grab_button, |
Jonas Ådahl | 1ea343e | 2013-10-25 23:18:05 +0200 | [diff] [blame] | 2086 | busy_cursor_grab_cancel, |
Kristian Høgsberg | d56bd90 | 2012-06-05 09:58:51 -0400 | [diff] [blame] | 2087 | }; |
| 2088 | |
| 2089 | static void |
Kristian Høgsberg | 02bbabb | 2013-05-06 22:15:05 -0400 | [diff] [blame] | 2090 | set_busy_cursor(struct shell_surface *shsurf, struct weston_pointer *pointer) |
Kristian Høgsberg | d56bd90 | 2012-06-05 09:58:51 -0400 | [diff] [blame] | 2091 | { |
| 2092 | struct shell_grab *grab; |
Kristian Høgsberg | d56bd90 | 2012-06-05 09:58:51 -0400 | [diff] [blame] | 2093 | |
Kristian Høgsberg | 2bff94e | 2014-02-11 12:22:51 -0800 | [diff] [blame] | 2094 | if (pointer->grab->interface == &busy_cursor_grab_interface) |
| 2095 | return; |
| 2096 | |
Kristian Høgsberg | d56bd90 | 2012-06-05 09:58:51 -0400 | [diff] [blame] | 2097 | grab = malloc(sizeof *grab); |
| 2098 | if (!grab) |
Scott Moreau | c3e54eb | 2012-04-17 19:06:20 -0600 | [diff] [blame] | 2099 | return; |
| 2100 | |
Ander Conselvan de Oliveira | b9d2a0f | 2012-06-28 18:08:05 +0300 | [diff] [blame] | 2101 | shell_grab_start(grab, &busy_cursor_grab_interface, shsurf, pointer, |
| 2102 | DESKTOP_SHELL_CURSOR_BUSY); |
Ander Conselvan de Oliveira | e5a1aee | 2014-04-09 17:39:39 +0300 | [diff] [blame] | 2103 | /* Mark the shsurf as ungrabbed so that button binding is able |
| 2104 | * to move it. */ |
| 2105 | shsurf->grabbed = 0; |
Kristian Høgsberg | d56bd90 | 2012-06-05 09:58:51 -0400 | [diff] [blame] | 2106 | } |
Scott Moreau | c3e54eb | 2012-04-17 19:06:20 -0600 | [diff] [blame] | 2107 | |
Kristian Høgsberg | d56bd90 | 2012-06-05 09:58:51 -0400 | [diff] [blame] | 2108 | static void |
Kristian Høgsberg | 2bff94e | 2014-02-11 12:22:51 -0800 | [diff] [blame] | 2109 | end_busy_cursor(struct weston_compositor *compositor, struct wl_client *client) |
Kristian Høgsberg | d56bd90 | 2012-06-05 09:58:51 -0400 | [diff] [blame] | 2110 | { |
Kristian Høgsberg | 2bff94e | 2014-02-11 12:22:51 -0800 | [diff] [blame] | 2111 | struct shell_grab *grab; |
| 2112 | struct weston_seat *seat; |
Kristian Høgsberg | d56bd90 | 2012-06-05 09:58:51 -0400 | [diff] [blame] | 2113 | |
Kristian Høgsberg | 2bff94e | 2014-02-11 12:22:51 -0800 | [diff] [blame] | 2114 | wl_list_for_each(seat, &compositor->seat_list, link) { |
Derek Foreman | 1281a36 | 2015-07-31 16:55:32 -0500 | [diff] [blame] | 2115 | struct weston_pointer *pointer = weston_seat_get_pointer(seat); |
| 2116 | |
| 2117 | if (!pointer) |
Kristian Høgsberg | 2bff94e | 2014-02-11 12:22:51 -0800 | [diff] [blame] | 2118 | continue; |
| 2119 | |
Derek Foreman | 1281a36 | 2015-07-31 16:55:32 -0500 | [diff] [blame] | 2120 | grab = (struct shell_grab *) pointer->grab; |
Kristian Høgsberg | 2bff94e | 2014-02-11 12:22:51 -0800 | [diff] [blame] | 2121 | if (grab->grab.interface == &busy_cursor_grab_interface && |
| 2122 | wl_resource_get_client(grab->shsurf->resource) == client) { |
| 2123 | shell_grab_end(grab); |
| 2124 | free(grab); |
| 2125 | } |
Scott Moreau | c3e54eb | 2012-04-17 19:06:20 -0600 | [diff] [blame] | 2126 | } |
Scott Moreau | c3e54eb | 2012-04-17 19:06:20 -0600 | [diff] [blame] | 2127 | } |
| 2128 | |
Scott Moreau | 9521d5e | 2012-04-19 13:06:17 -0600 | [diff] [blame] | 2129 | static void |
Kristian Høgsberg | 2bff94e | 2014-02-11 12:22:51 -0800 | [diff] [blame] | 2130 | handle_shell_client_destroy(struct wl_listener *listener, void *data); |
| 2131 | |
| 2132 | static int |
| 2133 | xdg_ping_timeout_handler(void *data) |
| 2134 | { |
| 2135 | struct shell_client *sc = data; |
| 2136 | struct weston_seat *seat; |
| 2137 | struct shell_surface *shsurf; |
| 2138 | |
| 2139 | /* Client is not responding */ |
| 2140 | sc->unresponsive = 1; |
Kristian Høgsberg | 2bff94e | 2014-02-11 12:22:51 -0800 | [diff] [blame] | 2141 | wl_list_for_each(seat, &sc->shell->compositor->seat_list, link) { |
Derek Foreman | 1281a36 | 2015-07-31 16:55:32 -0500 | [diff] [blame] | 2142 | struct weston_pointer *pointer = weston_seat_get_pointer(seat); |
| 2143 | |
| 2144 | if (!pointer || |
| 2145 | !pointer->focus || |
| 2146 | !pointer->focus->surface->resource) |
Kristian Høgsberg | 2bff94e | 2014-02-11 12:22:51 -0800 | [diff] [blame] | 2147 | continue; |
Michael Vetter | 2a18a52 | 2015-05-15 17:17:47 +0200 | [diff] [blame] | 2148 | |
Derek Foreman | 1281a36 | 2015-07-31 16:55:32 -0500 | [diff] [blame] | 2149 | shsurf = get_shell_surface(pointer->focus->surface); |
Kristian Høgsberg | 2bff94e | 2014-02-11 12:22:51 -0800 | [diff] [blame] | 2150 | if (shsurf && |
| 2151 | wl_resource_get_client(shsurf->resource) == sc->client) |
Derek Foreman | 1281a36 | 2015-07-31 16:55:32 -0500 | [diff] [blame] | 2152 | set_busy_cursor(shsurf, pointer); |
Kristian Høgsberg | 2bff94e | 2014-02-11 12:22:51 -0800 | [diff] [blame] | 2153 | } |
| 2154 | |
| 2155 | return 1; |
| 2156 | } |
| 2157 | |
| 2158 | static void |
| 2159 | handle_xdg_ping(struct shell_surface *shsurf, uint32_t serial) |
| 2160 | { |
| 2161 | struct weston_compositor *compositor = shsurf->shell->compositor; |
Jason Ekstrand | 9e9512f | 2014-04-16 21:12:10 -0500 | [diff] [blame] | 2162 | struct shell_client *sc = shsurf->owner; |
Kristian Høgsberg | 2bff94e | 2014-02-11 12:22:51 -0800 | [diff] [blame] | 2163 | struct wl_event_loop *loop; |
Kristian Høgsberg | dd62aba | 2014-02-12 09:56:19 -0800 | [diff] [blame] | 2164 | static const int ping_timeout = 200; |
Kristian Høgsberg | 2bff94e | 2014-02-11 12:22:51 -0800 | [diff] [blame] | 2165 | |
Kristian Høgsberg | 2bff94e | 2014-02-11 12:22:51 -0800 | [diff] [blame] | 2166 | if (sc->unresponsive) { |
| 2167 | xdg_ping_timeout_handler(sc); |
| 2168 | return; |
| 2169 | } |
| 2170 | |
| 2171 | sc->ping_serial = serial; |
| 2172 | loop = wl_display_get_event_loop(compositor->wl_display); |
| 2173 | if (sc->ping_timer == NULL) |
| 2174 | sc->ping_timer = |
| 2175 | wl_event_loop_add_timer(loop, |
| 2176 | xdg_ping_timeout_handler, sc); |
| 2177 | if (sc->ping_timer == NULL) |
| 2178 | return; |
| 2179 | |
| 2180 | wl_event_source_timer_update(sc->ping_timer, ping_timeout); |
| 2181 | |
Kristian Høgsberg | dd62aba | 2014-02-12 09:56:19 -0800 | [diff] [blame] | 2182 | if (shell_surface_is_xdg_surface(shsurf) || |
| 2183 | shell_surface_is_xdg_popup(shsurf)) |
| 2184 | xdg_shell_send_ping(sc->resource, serial); |
| 2185 | else if (shell_surface_is_wl_shell_surface(shsurf)) |
| 2186 | wl_shell_surface_send_ping(shsurf->resource, serial); |
Kristian Høgsberg | 2bff94e | 2014-02-11 12:22:51 -0800 | [diff] [blame] | 2187 | } |
| 2188 | |
Scott Moreau | ff1db4a | 2012-04-17 19:06:18 -0600 | [diff] [blame] | 2189 | static void |
| 2190 | ping_handler(struct weston_surface *surface, uint32_t serial) |
| 2191 | { |
Kristian Høgsberg | b71302e | 2012-05-10 12:28:35 -0400 | [diff] [blame] | 2192 | struct shell_surface *shsurf = get_shell_surface(surface); |
Scott Moreau | ff1db4a | 2012-04-17 19:06:18 -0600 | [diff] [blame] | 2193 | |
| 2194 | if (!shsurf) |
| 2195 | return; |
Jason Ekstrand | 651f00e | 2013-06-14 10:07:54 -0500 | [diff] [blame] | 2196 | if (!shsurf->resource) |
Kristian Høgsberg | ca535c1 | 2012-04-21 23:20:07 -0400 | [diff] [blame] | 2197 | return; |
Ander Conselvan de Oliveira | eac9a46 | 2012-07-16 14:15:48 +0300 | [diff] [blame] | 2198 | if (shsurf->surface == shsurf->shell->grab_surface) |
| 2199 | return; |
| 2200 | |
Kristian Høgsberg | dd62aba | 2014-02-12 09:56:19 -0800 | [diff] [blame] | 2201 | handle_xdg_ping(shsurf, serial); |
Scott Moreau | ff1db4a | 2012-04-17 19:06:18 -0600 | [diff] [blame] | 2202 | } |
| 2203 | |
| 2204 | static void |
Kristian Høgsberg | d56bd90 | 2012-06-05 09:58:51 -0400 | [diff] [blame] | 2205 | handle_pointer_focus(struct wl_listener *listener, void *data) |
| 2206 | { |
Kristian Høgsberg | 02bbabb | 2013-05-06 22:15:05 -0400 | [diff] [blame] | 2207 | struct weston_pointer *pointer = data; |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 2208 | struct weston_view *view = pointer->focus; |
Kristian Høgsberg | d56bd90 | 2012-06-05 09:58:51 -0400 | [diff] [blame] | 2209 | struct weston_compositor *compositor; |
Kristian Høgsberg | d56bd90 | 2012-06-05 09:58:51 -0400 | [diff] [blame] | 2210 | uint32_t serial; |
| 2211 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 2212 | if (!view) |
Kristian Høgsberg | d56bd90 | 2012-06-05 09:58:51 -0400 | [diff] [blame] | 2213 | return; |
| 2214 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 2215 | compositor = view->surface->compositor; |
Kristian Høgsberg | e11ef64 | 2014-02-11 16:35:22 -0800 | [diff] [blame] | 2216 | serial = wl_display_next_serial(compositor->wl_display); |
| 2217 | ping_handler(view->surface, serial); |
Kristian Høgsberg | d56bd90 | 2012-06-05 09:58:51 -0400 | [diff] [blame] | 2218 | } |
| 2219 | |
| 2220 | static void |
Jasper St. Pierre | faf27a9 | 2013-12-09 17:36:28 -0500 | [diff] [blame] | 2221 | shell_surface_lose_keyboard_focus(struct shell_surface *shsurf) |
| 2222 | { |
| 2223 | if (--shsurf->focus_count == 0) |
Jasper St. Pierre | 973d787 | 2014-05-06 08:44:29 -0400 | [diff] [blame] | 2224 | shell_surface_state_changed(shsurf); |
Jasper St. Pierre | faf27a9 | 2013-12-09 17:36:28 -0500 | [diff] [blame] | 2225 | } |
| 2226 | |
| 2227 | static void |
| 2228 | shell_surface_gain_keyboard_focus(struct shell_surface *shsurf) |
| 2229 | { |
| 2230 | if (shsurf->focus_count++ == 0) |
Jasper St. Pierre | 973d787 | 2014-05-06 08:44:29 -0400 | [diff] [blame] | 2231 | shell_surface_state_changed(shsurf); |
Jasper St. Pierre | faf27a9 | 2013-12-09 17:36:28 -0500 | [diff] [blame] | 2232 | } |
| 2233 | |
| 2234 | static void |
| 2235 | handle_keyboard_focus(struct wl_listener *listener, void *data) |
| 2236 | { |
| 2237 | struct weston_keyboard *keyboard = data; |
| 2238 | struct shell_seat *seat = get_shell_seat(keyboard->seat); |
| 2239 | |
| 2240 | if (seat->focused_surface) { |
| 2241 | struct shell_surface *shsurf = get_shell_surface(seat->focused_surface); |
| 2242 | if (shsurf) |
| 2243 | shell_surface_lose_keyboard_focus(shsurf); |
| 2244 | } |
| 2245 | |
| 2246 | seat->focused_surface = keyboard->focus; |
| 2247 | |
| 2248 | if (seat->focused_surface) { |
| 2249 | struct shell_surface *shsurf = get_shell_surface(seat->focused_surface); |
| 2250 | if (shsurf) |
| 2251 | shell_surface_gain_keyboard_focus(shsurf); |
| 2252 | } |
| 2253 | } |
| 2254 | |
| 2255 | static void |
Kristian Høgsberg | dd62aba | 2014-02-12 09:56:19 -0800 | [diff] [blame] | 2256 | shell_client_pong(struct shell_client *sc, uint32_t serial) |
Rafael Antognolli | e2a3455 | 2013-12-03 15:35:45 -0200 | [diff] [blame] | 2257 | { |
Kristian Høgsberg | dd62aba | 2014-02-12 09:56:19 -0800 | [diff] [blame] | 2258 | if (sc->ping_serial != serial) |
| 2259 | return; |
Rafael Antognolli | e2a3455 | 2013-12-03 15:35:45 -0200 | [diff] [blame] | 2260 | |
Kristian Høgsberg | dd62aba | 2014-02-12 09:56:19 -0800 | [diff] [blame] | 2261 | sc->unresponsive = 0; |
| 2262 | end_busy_cursor(sc->shell->compositor, sc->client); |
Rafael Antognolli | e2a3455 | 2013-12-03 15:35:45 -0200 | [diff] [blame] | 2263 | |
Kristian Høgsberg | dd62aba | 2014-02-12 09:56:19 -0800 | [diff] [blame] | 2264 | if (sc->ping_timer) { |
| 2265 | wl_event_source_remove(sc->ping_timer); |
| 2266 | sc->ping_timer = NULL; |
| 2267 | } |
| 2268 | |
| 2269 | } |
| 2270 | |
| 2271 | static void |
| 2272 | shell_surface_pong(struct wl_client *client, |
| 2273 | struct wl_resource *resource, uint32_t serial) |
| 2274 | { |
Jason Ekstrand | 9e9512f | 2014-04-16 21:12:10 -0500 | [diff] [blame] | 2275 | struct shell_surface *shsurf = wl_resource_get_user_data(resource); |
| 2276 | struct shell_client *sc = shsurf->owner; |
Kristian Høgsberg | dd62aba | 2014-02-12 09:56:19 -0800 | [diff] [blame] | 2277 | |
Kristian Høgsberg | dd62aba | 2014-02-12 09:56:19 -0800 | [diff] [blame] | 2278 | shell_client_pong(sc, serial); |
Rafael Antognolli | e2a3455 | 2013-12-03 15:35:45 -0200 | [diff] [blame] | 2279 | } |
| 2280 | |
| 2281 | static void |
Giulio Camuffo | 62942ad | 2013-09-11 18:20:47 +0200 | [diff] [blame] | 2282 | set_title(struct shell_surface *shsurf, const char *title) |
| 2283 | { |
| 2284 | free(shsurf->title); |
| 2285 | shsurf->title = strdup(title); |
Pekka Paalanen | b502654 | 2014-11-12 15:09:24 +0200 | [diff] [blame] | 2286 | shsurf->surface->timeline.force_refresh = 1; |
| 2287 | } |
| 2288 | |
| 2289 | static void |
Giulio Camuffo | a8e9b41 | 2015-01-27 19:10:37 +0200 | [diff] [blame] | 2290 | set_pid(struct shell_surface *shsurf, pid_t pid) |
| 2291 | { |
| 2292 | /* We have no use for it */ |
| 2293 | } |
| 2294 | |
| 2295 | static void |
Pekka Paalanen | b502654 | 2014-11-12 15:09:24 +0200 | [diff] [blame] | 2296 | set_type(struct shell_surface *shsurf, enum shell_surface_type t) |
| 2297 | { |
| 2298 | shsurf->type = t; |
| 2299 | shsurf->surface->timeline.force_refresh = 1; |
Giulio Camuffo | 62942ad | 2013-09-11 18:20:47 +0200 | [diff] [blame] | 2300 | } |
| 2301 | |
| 2302 | static void |
Jasper St. Pierre | ccf48fb | 2014-05-02 10:21:38 -0400 | [diff] [blame] | 2303 | set_window_geometry(struct shell_surface *shsurf, |
| 2304 | 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] | 2305 | { |
Jasper St. Pierre | ccf48fb | 2014-05-02 10:21:38 -0400 | [diff] [blame] | 2306 | shsurf->next_geometry.x = x; |
| 2307 | shsurf->next_geometry.y = y; |
| 2308 | shsurf->next_geometry.width = width; |
| 2309 | shsurf->next_geometry.height = height; |
| 2310 | shsurf->has_next_geometry = true; |
Kristian Høgsberg | e5c1ae9 | 2014-04-30 16:28:41 -0700 | [diff] [blame] | 2311 | } |
| 2312 | |
| 2313 | static void |
Kristian Høgsberg | e7afd91 | 2012-05-02 09:47:44 -0400 | [diff] [blame] | 2314 | shell_surface_set_title(struct wl_client *client, |
| 2315 | struct wl_resource *resource, const char *title) |
| 2316 | { |
Jason Ekstrand | 651f00e | 2013-06-14 10:07:54 -0500 | [diff] [blame] | 2317 | struct shell_surface *shsurf = wl_resource_get_user_data(resource); |
Kristian Høgsberg | e7afd91 | 2012-05-02 09:47:44 -0400 | [diff] [blame] | 2318 | |
Giulio Camuffo | 62942ad | 2013-09-11 18:20:47 +0200 | [diff] [blame] | 2319 | set_title(shsurf, title); |
Kristian Høgsberg | e7afd91 | 2012-05-02 09:47:44 -0400 | [diff] [blame] | 2320 | } |
| 2321 | |
| 2322 | static void |
| 2323 | shell_surface_set_class(struct wl_client *client, |
| 2324 | struct wl_resource *resource, const char *class) |
| 2325 | { |
Jason Ekstrand | 651f00e | 2013-06-14 10:07:54 -0500 | [diff] [blame] | 2326 | struct shell_surface *shsurf = wl_resource_get_user_data(resource); |
Kristian Høgsberg | e7afd91 | 2012-05-02 09:47:44 -0400 | [diff] [blame] | 2327 | |
| 2328 | free(shsurf->class); |
| 2329 | shsurf->class = strdup(class); |
Pekka Paalanen | b502654 | 2014-11-12 15:09:24 +0200 | [diff] [blame] | 2330 | shsurf->surface->timeline.force_refresh = 1; |
Kristian Høgsberg | e7afd91 | 2012-05-02 09:47:44 -0400 | [diff] [blame] | 2331 | } |
| 2332 | |
Alex Wu | 4539b08 | 2012-03-01 12:57:46 +0800 | [diff] [blame] | 2333 | static void |
Alexander Larsson | f82b6ca | 2013-05-28 16:23:39 +0200 | [diff] [blame] | 2334 | restore_output_mode(struct weston_output *output) |
| 2335 | { |
Derek Foreman | 6ae7bc9 | 2014-11-04 10:47:33 -0600 | [diff] [blame] | 2336 | if (output->original_mode) |
| 2337 | weston_output_mode_switch_to_native(output); |
Alexander Larsson | f82b6ca | 2013-05-28 16:23:39 +0200 | [diff] [blame] | 2338 | } |
| 2339 | |
| 2340 | static void |
| 2341 | restore_all_output_modes(struct weston_compositor *compositor) |
| 2342 | { |
| 2343 | struct weston_output *output; |
| 2344 | |
| 2345 | wl_list_for_each(output, &compositor->output_list, link) |
| 2346 | restore_output_mode(output); |
| 2347 | } |
| 2348 | |
Philip Withnall | 07926d9 | 2013-11-25 18:01:40 +0000 | [diff] [blame] | 2349 | /* The surface will be inserted into the list immediately after the link |
| 2350 | * returned by this function (i.e. will be stacked immediately above the |
| 2351 | * returned link). */ |
Giulio Camuffo | 412e6a5 | 2014-07-09 22:12:56 +0300 | [diff] [blame] | 2352 | static struct weston_layer_entry * |
Philip Withnall | 07926d9 | 2013-11-25 18:01:40 +0000 | [diff] [blame] | 2353 | shell_surface_calculate_layer_link (struct shell_surface *shsurf) |
| 2354 | { |
| 2355 | struct workspace *ws; |
Kristian Høgsberg | ead5242 | 2014-01-01 13:51:52 -0800 | [diff] [blame] | 2356 | struct weston_view *parent; |
Philip Withnall | 07926d9 | 2013-11-25 18:01:40 +0000 | [diff] [blame] | 2357 | |
| 2358 | switch (shsurf->type) { |
Ander Conselvan de Oliveira | ef6a7e4 | 2014-04-30 14:15:14 +0300 | [diff] [blame] | 2359 | case SHELL_SURFACE_XWAYLAND: |
| 2360 | return &shsurf->shell->fullscreen_layer.view_list; |
| 2361 | |
| 2362 | case SHELL_SURFACE_NONE: |
| 2363 | return NULL; |
| 2364 | |
Kristian Høgsberg | ead5242 | 2014-01-01 13:51:52 -0800 | [diff] [blame] | 2365 | case SHELL_SURFACE_POPUP: |
| 2366 | case SHELL_SURFACE_TOPLEVEL: |
Emilio Pozuelo Monfort | 9e7c759 | 2014-01-30 14:01:10 +0100 | [diff] [blame] | 2367 | if (shsurf->state.fullscreen && !shsurf->state.lowered) { |
Rafael Antognolli | 03b1659 | 2013-12-03 15:35:42 -0200 | [diff] [blame] | 2368 | return &shsurf->shell->fullscreen_layer.view_list; |
Rafael Antognolli | ed207b4 | 2013-12-03 15:35:43 -0200 | [diff] [blame] | 2369 | } else if (shsurf->parent) { |
Kristian Høgsberg | d55db69 | 2014-01-01 12:26:14 -0800 | [diff] [blame] | 2370 | /* Move the surface to its parent layer so |
| 2371 | * that surfaces which are transient for |
| 2372 | * fullscreen surfaces don't get hidden by the |
| 2373 | * fullscreen surfaces. */ |
Rafael Antognolli | ed207b4 | 2013-12-03 15:35:43 -0200 | [diff] [blame] | 2374 | |
| 2375 | /* TODO: Handle a parent with multiple views */ |
| 2376 | parent = get_default_view(shsurf->parent); |
| 2377 | if (parent) |
Giulio Camuffo | 412e6a5 | 2014-07-09 22:12:56 +0300 | [diff] [blame] | 2378 | return container_of(parent->layer_link.link.prev, |
| 2379 | struct weston_layer_entry, link); |
Rafael Antognolli | ed207b4 | 2013-12-03 15:35:43 -0200 | [diff] [blame] | 2380 | } |
Philip Withnall | 07926d9 | 2013-11-25 18:01:40 +0000 | [diff] [blame] | 2381 | |
Ander Conselvan de Oliveira | ef6a7e4 | 2014-04-30 14:15:14 +0300 | [diff] [blame] | 2382 | /* Move the surface to a normal workspace layer so that surfaces |
| 2383 | * which were previously fullscreen or transient are no longer |
| 2384 | * rendered on top. */ |
| 2385 | ws = get_current_workspace(shsurf->shell); |
| 2386 | return &ws->layer.view_list; |
Philip Withnall | 07926d9 | 2013-11-25 18:01:40 +0000 | [diff] [blame] | 2387 | } |
| 2388 | |
Ander Conselvan de Oliveira | ef6a7e4 | 2014-04-30 14:15:14 +0300 | [diff] [blame] | 2389 | assert(0 && "Unknown shell surface type"); |
Philip Withnall | 07926d9 | 2013-11-25 18:01:40 +0000 | [diff] [blame] | 2390 | } |
| 2391 | |
Philip Withnall | 648a4dd | 2013-11-25 18:01:44 +0000 | [diff] [blame] | 2392 | static void |
| 2393 | shell_surface_update_child_surface_layers (struct shell_surface *shsurf) |
| 2394 | { |
| 2395 | struct shell_surface *child; |
Giulio Camuffo | 412e6a5 | 2014-07-09 22:12:56 +0300 | [diff] [blame] | 2396 | struct weston_layer_entry *prev; |
Philip Withnall | 648a4dd | 2013-11-25 18:01:44 +0000 | [diff] [blame] | 2397 | |
| 2398 | /* Move the child layers to the same workspace as shsurf. They will be |
| 2399 | * stacked above shsurf. */ |
| 2400 | wl_list_for_each_reverse(child, &shsurf->children_list, children_link) { |
Giulio Camuffo | 412e6a5 | 2014-07-09 22:12:56 +0300 | [diff] [blame] | 2401 | 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] | 2402 | weston_view_damage_below(child->view); |
Philip Withnall | 648a4dd | 2013-11-25 18:01:44 +0000 | [diff] [blame] | 2403 | weston_view_geometry_dirty(child->view); |
Giulio Camuffo | 412e6a5 | 2014-07-09 22:12:56 +0300 | [diff] [blame] | 2404 | prev = container_of(shsurf->view->layer_link.link.prev, |
| 2405 | struct weston_layer_entry, link); |
| 2406 | weston_layer_entry_remove(&child->view->layer_link); |
| 2407 | weston_layer_entry_insert(prev, |
| 2408 | &child->view->layer_link); |
Philip Withnall | 648a4dd | 2013-11-25 18:01:44 +0000 | [diff] [blame] | 2409 | weston_view_geometry_dirty(child->view); |
| 2410 | weston_surface_damage(child->surface); |
| 2411 | |
| 2412 | /* Recurse. We don’t expect this to recurse very far (if |
| 2413 | * at all) because that would imply we have transient |
| 2414 | * (or popup) children of transient surfaces, which |
| 2415 | * would be unusual. */ |
| 2416 | shell_surface_update_child_surface_layers(child); |
| 2417 | } |
| 2418 | } |
| 2419 | } |
| 2420 | |
Philip Withnall | e1d75ae | 2013-11-25 18:01:41 +0000 | [diff] [blame] | 2421 | /* 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] | 2422 | * geometry to ensure the changes are redrawn. |
| 2423 | * |
| 2424 | * If any child surfaces exist and are mapped, ensure they’re in the same layer |
| 2425 | * as this surface. */ |
Philip Withnall | e1d75ae | 2013-11-25 18:01:41 +0000 | [diff] [blame] | 2426 | static void |
| 2427 | shell_surface_update_layer(struct shell_surface *shsurf) |
| 2428 | { |
Giulio Camuffo | 412e6a5 | 2014-07-09 22:12:56 +0300 | [diff] [blame] | 2429 | struct weston_layer_entry *new_layer_link; |
Philip Withnall | e1d75ae | 2013-11-25 18:01:41 +0000 | [diff] [blame] | 2430 | |
| 2431 | new_layer_link = shell_surface_calculate_layer_link(shsurf); |
| 2432 | |
Ander Conselvan de Oliveira | ef6a7e4 | 2014-04-30 14:15:14 +0300 | [diff] [blame] | 2433 | if (new_layer_link == NULL) |
| 2434 | return; |
Philip Withnall | e1d75ae | 2013-11-25 18:01:41 +0000 | [diff] [blame] | 2435 | if (new_layer_link == &shsurf->view->layer_link) |
| 2436 | return; |
| 2437 | |
| 2438 | weston_view_geometry_dirty(shsurf->view); |
Giulio Camuffo | 412e6a5 | 2014-07-09 22:12:56 +0300 | [diff] [blame] | 2439 | weston_layer_entry_remove(&shsurf->view->layer_link); |
| 2440 | weston_layer_entry_insert(new_layer_link, &shsurf->view->layer_link); |
Philip Withnall | e1d75ae | 2013-11-25 18:01:41 +0000 | [diff] [blame] | 2441 | weston_view_geometry_dirty(shsurf->view); |
| 2442 | weston_surface_damage(shsurf->surface); |
Philip Withnall | 648a4dd | 2013-11-25 18:01:44 +0000 | [diff] [blame] | 2443 | |
| 2444 | shell_surface_update_child_surface_layers(shsurf); |
Philip Withnall | e1d75ae | 2013-11-25 18:01:41 +0000 | [diff] [blame] | 2445 | } |
| 2446 | |
Alexander Larsson | f82b6ca | 2013-05-28 16:23:39 +0200 | [diff] [blame] | 2447 | static void |
Philip Withnall | dc4332f | 2013-11-25 18:01:38 +0000 | [diff] [blame] | 2448 | shell_surface_set_parent(struct shell_surface *shsurf, |
| 2449 | struct weston_surface *parent) |
| 2450 | { |
| 2451 | shsurf->parent = parent; |
Philip Withnall | 648a4dd | 2013-11-25 18:01:44 +0000 | [diff] [blame] | 2452 | |
| 2453 | wl_list_remove(&shsurf->children_link); |
| 2454 | wl_list_init(&shsurf->children_link); |
| 2455 | |
| 2456 | /* Insert into the parent surface’s child list. */ |
| 2457 | if (parent != NULL) { |
| 2458 | struct shell_surface *parent_shsurf = get_shell_surface(parent); |
| 2459 | if (parent_shsurf != NULL) |
| 2460 | wl_list_insert(&parent_shsurf->children_list, |
| 2461 | &shsurf->children_link); |
| 2462 | } |
Philip Withnall | dc4332f | 2013-11-25 18:01:38 +0000 | [diff] [blame] | 2463 | } |
| 2464 | |
| 2465 | static void |
Philip Withnall | 352e7ed | 2013-11-25 18:01:35 +0000 | [diff] [blame] | 2466 | shell_surface_set_output(struct shell_surface *shsurf, |
| 2467 | struct weston_output *output) |
| 2468 | { |
| 2469 | struct weston_surface *es = shsurf->surface; |
| 2470 | |
| 2471 | /* get the default output, if the client set it as NULL |
| 2472 | check whether the ouput is available */ |
| 2473 | if (output) |
| 2474 | shsurf->output = output; |
| 2475 | else if (es->output) |
| 2476 | shsurf->output = es->output; |
| 2477 | else |
| 2478 | shsurf->output = get_default_output(es->compositor); |
| 2479 | } |
| 2480 | |
| 2481 | static void |
Rafael Antognolli | 03b1659 | 2013-12-03 15:35:42 -0200 | [diff] [blame] | 2482 | surface_clear_next_states(struct shell_surface *shsurf) |
| 2483 | { |
| 2484 | shsurf->next_state.maximized = false; |
| 2485 | shsurf->next_state.fullscreen = false; |
| 2486 | |
| 2487 | if ((shsurf->next_state.maximized != shsurf->state.maximized) || |
| 2488 | (shsurf->next_state.fullscreen != shsurf->state.fullscreen)) |
| 2489 | shsurf->state_changed = true; |
| 2490 | } |
| 2491 | |
| 2492 | static void |
Philip Withnall | becb77e | 2013-11-25 18:01:30 +0000 | [diff] [blame] | 2493 | set_toplevel(struct shell_surface *shsurf) |
| 2494 | { |
Kristian Høgsberg | 41fbf6f | 2013-12-05 22:31:25 -0800 | [diff] [blame] | 2495 | shell_surface_set_parent(shsurf, NULL); |
| 2496 | surface_clear_next_states(shsurf); |
Pekka Paalanen | b502654 | 2014-11-12 15:09:24 +0200 | [diff] [blame] | 2497 | set_type(shsurf, SHELL_SURFACE_TOPLEVEL); |
Philip Withnall | 648a4dd | 2013-11-25 18:01:44 +0000 | [diff] [blame] | 2498 | |
| 2499 | /* The layer_link is updated in set_surface_type(), |
| 2500 | * called from configure. */ |
Philip Withnall | becb77e | 2013-11-25 18:01:30 +0000 | [diff] [blame] | 2501 | } |
| 2502 | |
| 2503 | static void |
| 2504 | shell_surface_set_toplevel(struct wl_client *client, |
| 2505 | struct wl_resource *resource) |
| 2506 | { |
| 2507 | struct shell_surface *surface = wl_resource_get_user_data(resource); |
| 2508 | |
| 2509 | set_toplevel(surface); |
| 2510 | } |
| 2511 | |
| 2512 | static void |
| 2513 | set_transient(struct shell_surface *shsurf, |
| 2514 | struct weston_surface *parent, int x, int y, uint32_t flags) |
| 2515 | { |
Philip Withnall | dc4332f | 2013-11-25 18:01:38 +0000 | [diff] [blame] | 2516 | assert(parent != NULL); |
| 2517 | |
Kristian Høgsberg | 9f7e331 | 2014-01-02 22:40:37 -0800 | [diff] [blame] | 2518 | shell_surface_set_parent(shsurf, parent); |
| 2519 | |
| 2520 | surface_clear_next_states(shsurf); |
| 2521 | |
Philip Withnall | becb77e | 2013-11-25 18:01:30 +0000 | [diff] [blame] | 2522 | shsurf->transient.x = x; |
| 2523 | shsurf->transient.y = y; |
| 2524 | shsurf->transient.flags = flags; |
Philip Withnall | dc4332f | 2013-11-25 18:01:38 +0000 | [diff] [blame] | 2525 | |
Rafael Antognolli | ed207b4 | 2013-12-03 15:35:43 -0200 | [diff] [blame] | 2526 | shsurf->next_state.relative = true; |
Kristian Høgsberg | a1df7ac | 2013-12-31 15:01:01 -0800 | [diff] [blame] | 2527 | shsurf->state_changed = true; |
Pekka Paalanen | b502654 | 2014-11-12 15:09:24 +0200 | [diff] [blame] | 2528 | set_type(shsurf, SHELL_SURFACE_TOPLEVEL); |
Philip Withnall | 648a4dd | 2013-11-25 18:01:44 +0000 | [diff] [blame] | 2529 | |
| 2530 | /* The layer_link is updated in set_surface_type(), |
| 2531 | * called from configure. */ |
Philip Withnall | becb77e | 2013-11-25 18:01:30 +0000 | [diff] [blame] | 2532 | } |
| 2533 | |
| 2534 | static void |
| 2535 | shell_surface_set_transient(struct wl_client *client, |
| 2536 | struct wl_resource *resource, |
| 2537 | struct wl_resource *parent_resource, |
| 2538 | int x, int y, uint32_t flags) |
| 2539 | { |
| 2540 | struct shell_surface *shsurf = wl_resource_get_user_data(resource); |
| 2541 | struct weston_surface *parent = |
| 2542 | wl_resource_get_user_data(parent_resource); |
| 2543 | |
| 2544 | set_transient(shsurf, parent, x, y, flags); |
| 2545 | } |
| 2546 | |
| 2547 | static void |
| 2548 | set_fullscreen(struct shell_surface *shsurf, |
| 2549 | uint32_t method, |
| 2550 | uint32_t framerate, |
| 2551 | struct weston_output *output) |
| 2552 | { |
Philip Withnall | 352e7ed | 2013-11-25 18:01:35 +0000 | [diff] [blame] | 2553 | shell_surface_set_output(shsurf, output); |
Pekka Paalanen | b502654 | 2014-11-12 15:09:24 +0200 | [diff] [blame] | 2554 | set_type(shsurf, SHELL_SURFACE_TOPLEVEL); |
Philip Withnall | becb77e | 2013-11-25 18:01:30 +0000 | [diff] [blame] | 2555 | |
| 2556 | shsurf->fullscreen_output = shsurf->output; |
| 2557 | shsurf->fullscreen.type = method; |
| 2558 | shsurf->fullscreen.framerate = framerate; |
Philip Withnall | dc4332f | 2013-11-25 18:01:38 +0000 | [diff] [blame] | 2559 | |
Jasper St. Pierre | 6458ec3 | 2014-04-11 16:00:31 -0700 | [diff] [blame] | 2560 | send_configure_for_surface(shsurf); |
Philip Withnall | becb77e | 2013-11-25 18:01:30 +0000 | [diff] [blame] | 2561 | } |
| 2562 | |
| 2563 | static void |
Zhang, Xiong Y | 3123693 | 2013-12-13 22:10:57 +0200 | [diff] [blame] | 2564 | weston_view_set_initial_position(struct weston_view *view, |
| 2565 | struct desktop_shell *shell); |
| 2566 | |
| 2567 | static void |
Philip Withnall | becb77e | 2013-11-25 18:01:30 +0000 | [diff] [blame] | 2568 | unset_fullscreen(struct shell_surface *shsurf) |
Alex Wu | 4539b08 | 2012-03-01 12:57:46 +0800 | [diff] [blame] | 2569 | { |
Philip Withnall | f85fe84 | 2013-11-25 18:01:37 +0000 | [diff] [blame] | 2570 | /* Unset the fullscreen output, driver configuration and transforms. */ |
Alex Wu | bd3354b | 2012-04-17 17:20:49 +0800 | [diff] [blame] | 2571 | if (shsurf->fullscreen.type == WL_SHELL_SURFACE_FULLSCREEN_METHOD_DRIVER && |
| 2572 | shell_surface_is_top_fullscreen(shsurf)) { |
Alexander Larsson | f82b6ca | 2013-05-28 16:23:39 +0200 | [diff] [blame] | 2573 | restore_output_mode(shsurf->fullscreen_output); |
Alex Wu | bd3354b | 2012-04-17 17:20:49 +0800 | [diff] [blame] | 2574 | } |
Philip Withnall | f85fe84 | 2013-11-25 18:01:37 +0000 | [diff] [blame] | 2575 | |
Alex Wu | 4539b08 | 2012-03-01 12:57:46 +0800 | [diff] [blame] | 2576 | shsurf->fullscreen.type = WL_SHELL_SURFACE_FULLSCREEN_METHOD_DEFAULT; |
| 2577 | shsurf->fullscreen.framerate = 0; |
Philip Withnall | f85fe84 | 2013-11-25 18:01:37 +0000 | [diff] [blame] | 2578 | |
Alex Wu | 4539b08 | 2012-03-01 12:57:46 +0800 | [diff] [blame] | 2579 | wl_list_remove(&shsurf->fullscreen.transform.link); |
| 2580 | wl_list_init(&shsurf->fullscreen.transform.link); |
Philip Withnall | f85fe84 | 2013-11-25 18:01:37 +0000 | [diff] [blame] | 2581 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 2582 | if (shsurf->fullscreen.black_view) |
| 2583 | weston_surface_destroy(shsurf->fullscreen.black_view->surface); |
| 2584 | shsurf->fullscreen.black_view = NULL; |
Philip Withnall | f85fe84 | 2013-11-25 18:01:37 +0000 | [diff] [blame] | 2585 | |
Zhang, Xiong Y | 3123693 | 2013-12-13 22:10:57 +0200 | [diff] [blame] | 2586 | if (shsurf->saved_position_valid) |
| 2587 | weston_view_set_position(shsurf->view, |
| 2588 | shsurf->saved_x, shsurf->saved_y); |
| 2589 | else |
| 2590 | weston_view_set_initial_position(shsurf->view, shsurf->shell); |
| 2591 | |
Alex Wu | 7bcb8bd | 2012-04-27 09:07:24 +0800 | [diff] [blame] | 2592 | if (shsurf->saved_rotation_valid) { |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 2593 | wl_list_insert(&shsurf->view->geometry.transformation_list, |
Philip Withnall | becb77e | 2013-11-25 18:01:30 +0000 | [diff] [blame] | 2594 | &shsurf->rotation.transform.link); |
Alex Wu | 7bcb8bd | 2012-04-27 09:07:24 +0800 | [diff] [blame] | 2595 | shsurf->saved_rotation_valid = false; |
| 2596 | } |
Rafal Mielniczuk | 3e3862c | 2012-10-07 20:25:36 +0200 | [diff] [blame] | 2597 | |
Philip Withnall | e1d75ae | 2013-11-25 18:01:41 +0000 | [diff] [blame] | 2598 | /* Layer is updated in set_surface_type(). */ |
Alex Wu | 4539b08 | 2012-03-01 12:57:46 +0800 | [diff] [blame] | 2599 | } |
| 2600 | |
Rafal Mielniczuk | fffdcdd | 2013-03-11 19:26:54 +0100 | [diff] [blame] | 2601 | static void |
Philip Withnall | becb77e | 2013-11-25 18:01:30 +0000 | [diff] [blame] | 2602 | shell_surface_set_fullscreen(struct wl_client *client, |
| 2603 | struct wl_resource *resource, |
| 2604 | uint32_t method, |
| 2605 | uint32_t framerate, |
| 2606 | struct wl_resource *output_resource) |
| 2607 | { |
| 2608 | struct shell_surface *shsurf = wl_resource_get_user_data(resource); |
| 2609 | struct weston_output *output; |
| 2610 | |
| 2611 | if (output_resource) |
| 2612 | output = wl_resource_get_user_data(output_resource); |
| 2613 | else |
| 2614 | output = NULL; |
| 2615 | |
Rafael Antognolli | 4b99a40 | 2013-12-03 15:35:44 -0200 | [diff] [blame] | 2616 | shell_surface_set_parent(shsurf, NULL); |
| 2617 | |
Rafael Antognolli | 03b1659 | 2013-12-03 15:35:42 -0200 | [diff] [blame] | 2618 | surface_clear_next_states(shsurf); |
Jasper St. Pierre | 8c6aa45 | 2014-02-08 18:29:49 -0500 | [diff] [blame] | 2619 | shsurf->next_state.fullscreen = true; |
| 2620 | shsurf->state_changed = true; |
Jasper St. Pierre | 6458ec3 | 2014-04-11 16:00:31 -0700 | [diff] [blame] | 2621 | set_fullscreen(shsurf, method, framerate, output); |
Philip Withnall | becb77e | 2013-11-25 18:01:30 +0000 | [diff] [blame] | 2622 | } |
| 2623 | |
| 2624 | static void |
| 2625 | set_popup(struct shell_surface *shsurf, |
| 2626 | struct weston_surface *parent, |
| 2627 | struct weston_seat *seat, |
| 2628 | uint32_t serial, |
| 2629 | int32_t x, |
| 2630 | int32_t y) |
| 2631 | { |
Philip Withnall | dc4332f | 2013-11-25 18:01:38 +0000 | [diff] [blame] | 2632 | assert(parent != NULL); |
| 2633 | |
Philip Withnall | becb77e | 2013-11-25 18:01:30 +0000 | [diff] [blame] | 2634 | shsurf->popup.shseat = get_shell_seat(seat); |
| 2635 | shsurf->popup.serial = serial; |
| 2636 | shsurf->popup.x = x; |
| 2637 | shsurf->popup.y = y; |
Philip Withnall | dc4332f | 2013-11-25 18:01:38 +0000 | [diff] [blame] | 2638 | |
Pekka Paalanen | b502654 | 2014-11-12 15:09:24 +0200 | [diff] [blame] | 2639 | set_type(shsurf, SHELL_SURFACE_POPUP); |
Philip Withnall | becb77e | 2013-11-25 18:01:30 +0000 | [diff] [blame] | 2640 | } |
| 2641 | |
| 2642 | static void |
| 2643 | shell_surface_set_popup(struct wl_client *client, |
| 2644 | struct wl_resource *resource, |
| 2645 | struct wl_resource *seat_resource, |
| 2646 | uint32_t serial, |
| 2647 | struct wl_resource *parent_resource, |
| 2648 | int32_t x, int32_t y, uint32_t flags) |
| 2649 | { |
| 2650 | struct shell_surface *shsurf = wl_resource_get_user_data(resource); |
Rafael Antognolli | 4b99a40 | 2013-12-03 15:35:44 -0200 | [diff] [blame] | 2651 | struct weston_surface *parent = |
| 2652 | wl_resource_get_user_data(parent_resource); |
| 2653 | |
| 2654 | shell_surface_set_parent(shsurf, parent); |
Philip Withnall | becb77e | 2013-11-25 18:01:30 +0000 | [diff] [blame] | 2655 | |
Rafael Antognolli | 03b1659 | 2013-12-03 15:35:42 -0200 | [diff] [blame] | 2656 | surface_clear_next_states(shsurf); |
Philip Withnall | becb77e | 2013-11-25 18:01:30 +0000 | [diff] [blame] | 2657 | set_popup(shsurf, |
Rafael Antognolli | 4b99a40 | 2013-12-03 15:35:44 -0200 | [diff] [blame] | 2658 | parent, |
Philip Withnall | becb77e | 2013-11-25 18:01:30 +0000 | [diff] [blame] | 2659 | wl_resource_get_user_data(seat_resource), |
| 2660 | serial, x, y); |
| 2661 | } |
| 2662 | |
| 2663 | static void |
Philip Withnall | becb77e | 2013-11-25 18:01:30 +0000 | [diff] [blame] | 2664 | unset_maximized(struct shell_surface *shsurf) |
Rafal Mielniczuk | fffdcdd | 2013-03-11 19:26:54 +0100 | [diff] [blame] | 2665 | { |
Rafal Mielniczuk | fffdcdd | 2013-03-11 19:26:54 +0100 | [diff] [blame] | 2666 | /* undo all maximized things here */ |
| 2667 | shsurf->output = get_default_output(shsurf->surface->compositor); |
Zhang, Xiong Y | 3123693 | 2013-12-13 22:10:57 +0200 | [diff] [blame] | 2668 | |
| 2669 | if (shsurf->saved_position_valid) |
| 2670 | weston_view_set_position(shsurf->view, |
| 2671 | shsurf->saved_x, shsurf->saved_y); |
| 2672 | else |
| 2673 | weston_view_set_initial_position(shsurf->view, shsurf->shell); |
Rafal Mielniczuk | fffdcdd | 2013-03-11 19:26:54 +0100 | [diff] [blame] | 2674 | |
| 2675 | if (shsurf->saved_rotation_valid) { |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 2676 | wl_list_insert(&shsurf->view->geometry.transformation_list, |
| 2677 | &shsurf->rotation.transform.link); |
Rafal Mielniczuk | fffdcdd | 2013-03-11 19:26:54 +0100 | [diff] [blame] | 2678 | shsurf->saved_rotation_valid = false; |
| 2679 | } |
| 2680 | |
Philip Withnall | e1d75ae | 2013-11-25 18:01:41 +0000 | [diff] [blame] | 2681 | /* Layer is updated in set_surface_type(). */ |
Rafal Mielniczuk | fffdcdd | 2013-03-11 19:26:54 +0100 | [diff] [blame] | 2682 | } |
| 2683 | |
Philip Withnall | becb77e | 2013-11-25 18:01:30 +0000 | [diff] [blame] | 2684 | static void |
Manuel Bachmann | dc1c3e4 | 2015-02-16 11:52:13 +0100 | [diff] [blame] | 2685 | set_minimized(struct weston_surface *surface) |
Manuel Bachmann | 50c87db | 2014-02-26 15:52:13 +0100 | [diff] [blame] | 2686 | { |
| 2687 | struct shell_surface *shsurf; |
| 2688 | struct workspace *current_ws; |
| 2689 | struct weston_seat *seat; |
| 2690 | struct weston_surface *focus; |
| 2691 | struct weston_view *view; |
| 2692 | |
| 2693 | view = get_default_view(surface); |
| 2694 | if (!view) |
| 2695 | return; |
| 2696 | |
| 2697 | assert(weston_surface_get_main_surface(view->surface) == view->surface); |
| 2698 | |
| 2699 | shsurf = get_shell_surface(surface); |
| 2700 | current_ws = get_current_workspace(shsurf->shell); |
| 2701 | |
Giulio Camuffo | 412e6a5 | 2014-07-09 22:12:56 +0300 | [diff] [blame] | 2702 | weston_layer_entry_remove(&view->layer_link); |
Manuel Bachmann | dc1c3e4 | 2015-02-16 11:52:13 +0100 | [diff] [blame] | 2703 | 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] | 2704 | |
Manuel Bachmann | dc1c3e4 | 2015-02-16 11:52:13 +0100 | [diff] [blame] | 2705 | drop_focus_state(shsurf->shell, current_ws, view->surface); |
| 2706 | wl_list_for_each(seat, &shsurf->shell->compositor->seat_list, link) { |
Derek Foreman | 1281a36 | 2015-07-31 16:55:32 -0500 | [diff] [blame] | 2707 | struct weston_keyboard *keyboard = |
| 2708 | weston_seat_get_keyboard(seat); |
| 2709 | |
| 2710 | if (!keyboard) |
Manuel Bachmann | dc1c3e4 | 2015-02-16 11:52:13 +0100 | [diff] [blame] | 2711 | continue; |
Derek Foreman | 1281a36 | 2015-07-31 16:55:32 -0500 | [diff] [blame] | 2712 | focus = weston_surface_get_main_surface(keyboard->focus); |
Manuel Bachmann | dc1c3e4 | 2015-02-16 11:52:13 +0100 | [diff] [blame] | 2713 | if (focus == view->surface) |
Derek Foreman | 1281a36 | 2015-07-31 16:55:32 -0500 | [diff] [blame] | 2714 | weston_keyboard_set_focus(keyboard, NULL); |
Manuel Bachmann | 50c87db | 2014-02-26 15:52:13 +0100 | [diff] [blame] | 2715 | } |
| 2716 | |
| 2717 | shell_surface_update_child_surface_layers(shsurf); |
Manuel Bachmann | 50c87db | 2014-02-26 15:52:13 +0100 | [diff] [blame] | 2718 | weston_view_damage_below(view); |
| 2719 | } |
| 2720 | |
| 2721 | static void |
Philip Withnall | becb77e | 2013-11-25 18:01:30 +0000 | [diff] [blame] | 2722 | shell_surface_set_maximized(struct wl_client *client, |
| 2723 | struct wl_resource *resource, |
| 2724 | struct wl_resource *output_resource) |
| 2725 | { |
| 2726 | struct shell_surface *shsurf = wl_resource_get_user_data(resource); |
| 2727 | struct weston_output *output; |
| 2728 | |
Jasper St. Pierre | 9aa8ce6 | 2014-04-11 16:18:54 -0700 | [diff] [blame] | 2729 | surface_clear_next_states(shsurf); |
| 2730 | shsurf->next_state.maximized = true; |
| 2731 | shsurf->state_changed = true; |
| 2732 | |
Pekka Paalanen | b502654 | 2014-11-12 15:09:24 +0200 | [diff] [blame] | 2733 | set_type(shsurf, SHELL_SURFACE_TOPLEVEL); |
Jasper St. Pierre | 9aa8ce6 | 2014-04-11 16:18:54 -0700 | [diff] [blame] | 2734 | shell_surface_set_parent(shsurf, NULL); |
| 2735 | |
Philip Withnall | becb77e | 2013-11-25 18:01:30 +0000 | [diff] [blame] | 2736 | if (output_resource) |
| 2737 | output = wl_resource_get_user_data(output_resource); |
| 2738 | else |
| 2739 | output = NULL; |
| 2740 | |
Jasper St. Pierre | 9aa8ce6 | 2014-04-11 16:18:54 -0700 | [diff] [blame] | 2741 | shell_surface_set_output(shsurf, output); |
Rafael Antognolli | 4b99a40 | 2013-12-03 15:35:44 -0200 | [diff] [blame] | 2742 | |
Jasper St. Pierre | 9aa8ce6 | 2014-04-11 16:18:54 -0700 | [diff] [blame] | 2743 | send_configure_for_surface(shsurf); |
Philip Withnall | becb77e | 2013-11-25 18:01:30 +0000 | [diff] [blame] | 2744 | } |
| 2745 | |
Philip Withnall | e1d75ae | 2013-11-25 18:01:41 +0000 | [diff] [blame] | 2746 | /* This is only ever called from set_surface_type(), so there’s no need to |
| 2747 | * update layer_links here, since they’ll be updated when we return. */ |
Pekka Paalanen | 9826223 | 2011-12-01 10:42:22 +0200 | [diff] [blame] | 2748 | static int |
Philip Withnall | becb77e | 2013-11-25 18:01:30 +0000 | [diff] [blame] | 2749 | reset_surface_type(struct shell_surface *surface) |
Pekka Paalanen | 9826223 | 2011-12-01 10:42:22 +0200 | [diff] [blame] | 2750 | { |
Rafael Antognolli | 03b1659 | 2013-12-03 15:35:42 -0200 | [diff] [blame] | 2751 | if (surface->state.fullscreen) |
Philip Withnall | becb77e | 2013-11-25 18:01:30 +0000 | [diff] [blame] | 2752 | unset_fullscreen(surface); |
Rafael Antognolli | 03b1659 | 2013-12-03 15:35:42 -0200 | [diff] [blame] | 2753 | if (surface->state.maximized) |
Philip Withnall | becb77e | 2013-11-25 18:01:30 +0000 | [diff] [blame] | 2754 | unset_maximized(surface); |
Pekka Paalanen | 9826223 | 2011-12-01 10:42:22 +0200 | [diff] [blame] | 2755 | |
Pekka Paalanen | 9826223 | 2011-12-01 10:42:22 +0200 | [diff] [blame] | 2756 | return 0; |
| 2757 | } |
| 2758 | |
Kristian Høgsberg | 4cca349 | 2011-01-18 07:53:49 -0500 | [diff] [blame] | 2759 | static void |
Rafael Antognolli | 03b1659 | 2013-12-03 15:35:42 -0200 | [diff] [blame] | 2760 | set_full_output(struct shell_surface *shsurf) |
| 2761 | { |
| 2762 | shsurf->saved_x = shsurf->view->geometry.x; |
| 2763 | shsurf->saved_y = shsurf->view->geometry.y; |
Rafael Antognolli | 3c4e3f7 | 2013-12-03 15:35:46 -0200 | [diff] [blame] | 2764 | shsurf->saved_width = shsurf->surface->width; |
| 2765 | shsurf->saved_height = shsurf->surface->height; |
| 2766 | shsurf->saved_size_valid = true; |
Rafael Antognolli | 03b1659 | 2013-12-03 15:35:42 -0200 | [diff] [blame] | 2767 | shsurf->saved_position_valid = true; |
| 2768 | |
| 2769 | if (!wl_list_empty(&shsurf->rotation.transform.link)) { |
| 2770 | wl_list_remove(&shsurf->rotation.transform.link); |
| 2771 | wl_list_init(&shsurf->rotation.transform.link); |
| 2772 | weston_view_geometry_dirty(shsurf->view); |
| 2773 | shsurf->saved_rotation_valid = true; |
| 2774 | } |
| 2775 | } |
| 2776 | |
| 2777 | static void |
Kristian Høgsberg | 7f366e7 | 2012-04-27 17:20:01 -0400 | [diff] [blame] | 2778 | set_surface_type(struct shell_surface *shsurf) |
| 2779 | { |
Kristian Høgsberg | 8150b19 | 2012-06-27 10:22:58 -0400 | [diff] [blame] | 2780 | struct weston_surface *pes = shsurf->parent; |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 2781 | struct weston_view *pev = get_default_view(pes); |
Kristian Høgsberg | 7f366e7 | 2012-04-27 17:20:01 -0400 | [diff] [blame] | 2782 | |
Philip Withnall | becb77e | 2013-11-25 18:01:30 +0000 | [diff] [blame] | 2783 | reset_surface_type(shsurf); |
Kristian Høgsberg | 7f366e7 | 2012-04-27 17:20:01 -0400 | [diff] [blame] | 2784 | |
Rafael Antognolli | 03b1659 | 2013-12-03 15:35:42 -0200 | [diff] [blame] | 2785 | shsurf->state = shsurf->next_state; |
Rafael Antognolli | 03b1659 | 2013-12-03 15:35:42 -0200 | [diff] [blame] | 2786 | shsurf->state_changed = false; |
Kristian Høgsberg | 7f366e7 | 2012-04-27 17:20:01 -0400 | [diff] [blame] | 2787 | |
| 2788 | switch (shsurf->type) { |
| 2789 | case SHELL_SURFACE_TOPLEVEL: |
Rafael Antognolli | ed207b4 | 2013-12-03 15:35:43 -0200 | [diff] [blame] | 2790 | if (shsurf->state.maximized || shsurf->state.fullscreen) { |
Rafael Antognolli | 03b1659 | 2013-12-03 15:35:42 -0200 | [diff] [blame] | 2791 | set_full_output(shsurf); |
Rafael Antognolli | ed207b4 | 2013-12-03 15:35:43 -0200 | [diff] [blame] | 2792 | } else if (shsurf->state.relative && pev) { |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 2793 | weston_view_set_position(shsurf->view, |
| 2794 | pev->geometry.x + shsurf->transient.x, |
| 2795 | pev->geometry.y + shsurf->transient.y); |
Rafael Antognolli | ed207b4 | 2013-12-03 15:35:43 -0200 | [diff] [blame] | 2796 | } |
Rafael Antognolli | 44a3162 | 2013-12-04 18:37:16 -0200 | [diff] [blame] | 2797 | break; |
Kristian Høgsberg | 7f366e7 | 2012-04-27 17:20:01 -0400 | [diff] [blame] | 2798 | |
Tiago Vignatti | fb2adba | 2013-06-12 15:43:21 -0300 | [diff] [blame] | 2799 | case SHELL_SURFACE_XWAYLAND: |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 2800 | weston_view_set_position(shsurf->view, shsurf->transient.x, |
| 2801 | shsurf->transient.y); |
Tiago Vignatti | fb2adba | 2013-06-12 15:43:21 -0300 | [diff] [blame] | 2802 | break; |
| 2803 | |
Philip Withnall | 0f640e2 | 2013-11-25 18:01:31 +0000 | [diff] [blame] | 2804 | case SHELL_SURFACE_POPUP: |
| 2805 | case SHELL_SURFACE_NONE: |
Kristian Høgsberg | 7f366e7 | 2012-04-27 17:20:01 -0400 | [diff] [blame] | 2806 | default: |
| 2807 | break; |
| 2808 | } |
Philip Withnall | e1d75ae | 2013-11-25 18:01:41 +0000 | [diff] [blame] | 2809 | |
| 2810 | /* Update the surface’s layer. */ |
| 2811 | shell_surface_update_layer(shsurf); |
Kristian Høgsberg | 7f366e7 | 2012-04-27 17:20:01 -0400 | [diff] [blame] | 2812 | } |
| 2813 | |
Tiago Vignatti | be14326 | 2012-04-16 17:31:41 +0300 | [diff] [blame] | 2814 | static struct desktop_shell * |
Juan Zhao | 96879df | 2012-02-07 08:45:41 +0800 | [diff] [blame] | 2815 | shell_surface_get_shell(struct shell_surface *shsurf) |
Pekka Paalanen | af0e34c | 2011-12-02 10:59:17 +0200 | [diff] [blame] | 2816 | { |
Kristian Høgsberg | 02e79dc | 2012-04-12 09:55:26 -0400 | [diff] [blame] | 2817 | return shsurf->shell; |
Juan Zhao | 96879df | 2012-02-07 08:45:41 +0800 | [diff] [blame] | 2818 | } |
| 2819 | |
Pekka Paalanen | 8274d90 | 2014-08-06 19:36:51 +0300 | [diff] [blame] | 2820 | static int |
| 2821 | black_surface_get_label(struct weston_surface *surface, char *buf, size_t len) |
| 2822 | { |
| 2823 | struct weston_surface *fs_surface = surface->configure_private; |
| 2824 | int n; |
| 2825 | int rem; |
| 2826 | int ret; |
| 2827 | |
| 2828 | n = snprintf(buf, len, "black background surface for "); |
| 2829 | if (n < 0) |
| 2830 | return n; |
| 2831 | |
| 2832 | rem = (int)len - n; |
| 2833 | if (rem < 0) |
| 2834 | rem = 0; |
| 2835 | |
| 2836 | if (fs_surface->get_label) |
| 2837 | ret = fs_surface->get_label(fs_surface, buf + n, rem); |
| 2838 | else |
| 2839 | ret = snprintf(buf + n, rem, "<unknown>"); |
| 2840 | |
| 2841 | if (ret < 0) |
| 2842 | return n; |
| 2843 | |
| 2844 | return n + ret; |
| 2845 | } |
| 2846 | |
Alex Wu | 2185843 | 2012-04-01 20:13:08 +0800 | [diff] [blame] | 2847 | static void |
Jason Ekstrand | 918f2dd | 2013-12-02 21:01:53 -0600 | [diff] [blame] | 2848 | 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] | 2849 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 2850 | static struct weston_view * |
Alex Wu | 4539b08 | 2012-03-01 12:57:46 +0800 | [diff] [blame] | 2851 | create_black_surface(struct weston_compositor *ec, |
Alex Wu | 2185843 | 2012-04-01 20:13:08 +0800 | [diff] [blame] | 2852 | struct weston_surface *fs_surface, |
John Kåre Alsaker | 490d02a | 2012-09-30 02:57:21 +0200 | [diff] [blame] | 2853 | float x, float y, int w, int h) |
Alex Wu | 4539b08 | 2012-03-01 12:57:46 +0800 | [diff] [blame] | 2854 | { |
| 2855 | struct weston_surface *surface = NULL; |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 2856 | struct weston_view *view; |
Alex Wu | 4539b08 | 2012-03-01 12:57:46 +0800 | [diff] [blame] | 2857 | |
| 2858 | surface = weston_surface_create(ec); |
| 2859 | if (surface == NULL) { |
Martin Minarik | 6d11836 | 2012-06-07 18:01:59 +0200 | [diff] [blame] | 2860 | weston_log("no memory\n"); |
Alex Wu | 4539b08 | 2012-03-01 12:57:46 +0800 | [diff] [blame] | 2861 | return NULL; |
| 2862 | } |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 2863 | view = weston_view_create(surface); |
| 2864 | if (surface == NULL) { |
| 2865 | weston_log("no memory\n"); |
| 2866 | weston_surface_destroy(surface); |
| 2867 | return NULL; |
| 2868 | } |
Alex Wu | 4539b08 | 2012-03-01 12:57:46 +0800 | [diff] [blame] | 2869 | |
Alex Wu | 2185843 | 2012-04-01 20:13:08 +0800 | [diff] [blame] | 2870 | surface->configure = black_surface_configure; |
Giulio Camuffo | 7fe01b1 | 2013-03-28 18:02:42 +0100 | [diff] [blame] | 2871 | surface->configure_private = fs_surface; |
Pekka Paalanen | 8274d90 | 2014-08-06 19:36:51 +0300 | [diff] [blame] | 2872 | weston_surface_set_label_func(surface, black_surface_get_label); |
Alex Wu | 4539b08 | 2012-03-01 12:57:46 +0800 | [diff] [blame] | 2873 | weston_surface_set_color(surface, 0.0, 0.0, 0.0, 1); |
Pekka Paalanen | 71f6f3b | 2012-10-10 12:49:26 +0300 | [diff] [blame] | 2874 | pixman_region32_fini(&surface->opaque); |
Kristian Høgsberg | 61f00f5 | 2012-08-03 16:31:36 -0400 | [diff] [blame] | 2875 | pixman_region32_init_rect(&surface->opaque, 0, 0, w, h); |
Jonas Ådahl | 33619a4 | 2013-01-15 21:25:55 +0100 | [diff] [blame] | 2876 | pixman_region32_fini(&surface->input); |
| 2877 | pixman_region32_init_rect(&surface->input, 0, 0, w, h); |
Jason Ekstrand | 918f2dd | 2013-12-02 21:01:53 -0600 | [diff] [blame] | 2878 | |
Jason Ekstrand | 6228ee2 | 2014-01-01 15:58:57 -0600 | [diff] [blame] | 2879 | weston_surface_set_size(surface, w, h); |
Jason Ekstrand | 918f2dd | 2013-12-02 21:01:53 -0600 | [diff] [blame] | 2880 | weston_view_set_position(view, x, y); |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 2881 | |
| 2882 | return view; |
Alex Wu | 4539b08 | 2012-03-01 12:57:46 +0800 | [diff] [blame] | 2883 | } |
| 2884 | |
Philip Withnall | ed8f1a9 | 2013-11-25 18:01:43 +0000 | [diff] [blame] | 2885 | static void |
| 2886 | shell_ensure_fullscreen_black_view(struct shell_surface *shsurf) |
| 2887 | { |
| 2888 | struct weston_output *output = shsurf->fullscreen_output; |
| 2889 | |
Rafael Antognolli | 03b1659 | 2013-12-03 15:35:42 -0200 | [diff] [blame] | 2890 | assert(shsurf->state.fullscreen); |
Philip Withnall | ed8f1a9 | 2013-11-25 18:01:43 +0000 | [diff] [blame] | 2891 | |
| 2892 | if (!shsurf->fullscreen.black_view) |
| 2893 | shsurf->fullscreen.black_view = |
| 2894 | create_black_surface(shsurf->surface->compositor, |
| 2895 | shsurf->surface, |
| 2896 | output->x, output->y, |
| 2897 | output->width, |
| 2898 | output->height); |
| 2899 | |
| 2900 | weston_view_geometry_dirty(shsurf->fullscreen.black_view); |
Giulio Camuffo | 412e6a5 | 2014-07-09 22:12:56 +0300 | [diff] [blame] | 2901 | weston_layer_entry_remove(&shsurf->fullscreen.black_view->layer_link); |
| 2902 | weston_layer_entry_insert(&shsurf->view->layer_link, |
| 2903 | &shsurf->fullscreen.black_view->layer_link); |
Philip Withnall | ed8f1a9 | 2013-11-25 18:01:43 +0000 | [diff] [blame] | 2904 | weston_view_geometry_dirty(shsurf->fullscreen.black_view); |
| 2905 | weston_surface_damage(shsurf->surface); |
Emilio Pozuelo Monfort | 9e7c759 | 2014-01-30 14:01:10 +0100 | [diff] [blame] | 2906 | |
| 2907 | shsurf->state.lowered = false; |
Philip Withnall | ed8f1a9 | 2013-11-25 18:01:43 +0000 | [diff] [blame] | 2908 | } |
| 2909 | |
Alex Wu | 4539b08 | 2012-03-01 12:57:46 +0800 | [diff] [blame] | 2910 | /* Create black surface and append it to the associated fullscreen surface. |
| 2911 | * Handle size dismatch and positioning according to the method. */ |
| 2912 | static void |
| 2913 | shell_configure_fullscreen(struct shell_surface *shsurf) |
| 2914 | { |
| 2915 | struct weston_output *output = shsurf->fullscreen_output; |
| 2916 | struct weston_surface *surface = shsurf->surface; |
| 2917 | struct weston_matrix *matrix; |
Kristian Høgsberg | 240dfeb | 2012-07-12 12:32:31 -0400 | [diff] [blame] | 2918 | float scale, output_aspect, surface_aspect, x, y; |
Giulio Camuffo | b836664 | 2013-04-25 13:57:46 +0300 | [diff] [blame] | 2919 | int32_t surf_x, surf_y, surf_width, surf_height; |
Alex Wu | 4539b08 | 2012-03-01 12:57:46 +0800 | [diff] [blame] | 2920 | |
Alexander Larsson | f82b6ca | 2013-05-28 16:23:39 +0200 | [diff] [blame] | 2921 | if (shsurf->fullscreen.type != WL_SHELL_SURFACE_FULLSCREEN_METHOD_DRIVER) |
| 2922 | restore_output_mode(output); |
| 2923 | |
Emilio Pozuelo Monfort | 9e7c759 | 2014-01-30 14:01:10 +0100 | [diff] [blame] | 2924 | /* Reverse the effect of lower_fullscreen_layer() */ |
Giulio Camuffo | 412e6a5 | 2014-07-09 22:12:56 +0300 | [diff] [blame] | 2925 | weston_layer_entry_remove(&shsurf->view->layer_link); |
| 2926 | 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] | 2927 | |
Philip Withnall | ed8f1a9 | 2013-11-25 18:01:43 +0000 | [diff] [blame] | 2928 | shell_ensure_fullscreen_black_view(shsurf); |
Alex Wu | 4539b08 | 2012-03-01 12:57:46 +0800 | [diff] [blame] | 2929 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 2930 | surface_subsurfaces_boundingbox(shsurf->surface, &surf_x, &surf_y, |
Giulio Camuffo | b836664 | 2013-04-25 13:57:46 +0300 | [diff] [blame] | 2931 | &surf_width, &surf_height); |
| 2932 | |
Alex Wu | 4539b08 | 2012-03-01 12:57:46 +0800 | [diff] [blame] | 2933 | switch (shsurf->fullscreen.type) { |
| 2934 | case WL_SHELL_SURFACE_FULLSCREEN_METHOD_DEFAULT: |
Pekka Paalanen | de685b8 | 2012-12-04 15:58:12 +0200 | [diff] [blame] | 2935 | if (surface->buffer_ref.buffer) |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 2936 | center_on_output(shsurf->view, shsurf->fullscreen_output); |
Alex Wu | 4539b08 | 2012-03-01 12:57:46 +0800 | [diff] [blame] | 2937 | break; |
| 2938 | case WL_SHELL_SURFACE_FULLSCREEN_METHOD_SCALE: |
Rob Bradford | 9f3dd15 | 2013-02-12 11:53:47 +0000 | [diff] [blame] | 2939 | /* 1:1 mapping between surface and output dimensions */ |
Giulio Camuffo | b836664 | 2013-04-25 13:57:46 +0300 | [diff] [blame] | 2940 | if (output->width == surf_width && |
| 2941 | output->height == surf_height) { |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 2942 | weston_view_set_position(shsurf->view, |
| 2943 | output->x - surf_x, |
| 2944 | output->y - surf_y); |
Rob Bradford | 9f3dd15 | 2013-02-12 11:53:47 +0000 | [diff] [blame] | 2945 | break; |
| 2946 | } |
| 2947 | |
Alex Wu | 4539b08 | 2012-03-01 12:57:46 +0800 | [diff] [blame] | 2948 | matrix = &shsurf->fullscreen.transform.matrix; |
| 2949 | weston_matrix_init(matrix); |
Kristian Høgsberg | 240dfeb | 2012-07-12 12:32:31 -0400 | [diff] [blame] | 2950 | |
Scott Moreau | 1bad5db | 2012-08-18 01:04:05 -0600 | [diff] [blame] | 2951 | output_aspect = (float) output->width / |
| 2952 | (float) output->height; |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 2953 | /* XXX: Use surf_width and surf_height here? */ |
| 2954 | surface_aspect = (float) surface->width / |
| 2955 | (float) surface->height; |
Kristian Høgsberg | 240dfeb | 2012-07-12 12:32:31 -0400 | [diff] [blame] | 2956 | if (output_aspect < surface_aspect) |
Scott Moreau | 1bad5db | 2012-08-18 01:04:05 -0600 | [diff] [blame] | 2957 | scale = (float) output->width / |
Giulio Camuffo | b836664 | 2013-04-25 13:57:46 +0300 | [diff] [blame] | 2958 | (float) surf_width; |
Kristian Høgsberg | 240dfeb | 2012-07-12 12:32:31 -0400 | [diff] [blame] | 2959 | else |
Scott Moreau | 1bad5db | 2012-08-18 01:04:05 -0600 | [diff] [blame] | 2960 | scale = (float) output->height / |
Giulio Camuffo | b836664 | 2013-04-25 13:57:46 +0300 | [diff] [blame] | 2961 | (float) surf_height; |
Kristian Høgsberg | 240dfeb | 2012-07-12 12:32:31 -0400 | [diff] [blame] | 2962 | |
Alex Wu | 4539b08 | 2012-03-01 12:57:46 +0800 | [diff] [blame] | 2963 | weston_matrix_scale(matrix, scale, scale, 1); |
| 2964 | wl_list_remove(&shsurf->fullscreen.transform.link); |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 2965 | wl_list_insert(&shsurf->view->geometry.transformation_list, |
Alex Wu | 4539b08 | 2012-03-01 12:57:46 +0800 | [diff] [blame] | 2966 | &shsurf->fullscreen.transform.link); |
Giulio Camuffo | b836664 | 2013-04-25 13:57:46 +0300 | [diff] [blame] | 2967 | x = output->x + (output->width - surf_width * scale) / 2 - surf_x; |
| 2968 | y = output->y + (output->height - surf_height * scale) / 2 - surf_y; |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 2969 | weston_view_set_position(shsurf->view, x, y); |
Kristian Høgsberg | 240dfeb | 2012-07-12 12:32:31 -0400 | [diff] [blame] | 2970 | |
Alex Wu | 4539b08 | 2012-03-01 12:57:46 +0800 | [diff] [blame] | 2971 | break; |
| 2972 | case WL_SHELL_SURFACE_FULLSCREEN_METHOD_DRIVER: |
Alex Wu | bd3354b | 2012-04-17 17:20:49 +0800 | [diff] [blame] | 2973 | if (shell_surface_is_top_fullscreen(shsurf)) { |
Quentin Glidic | c0d79ce | 2013-01-29 14:16:13 +0100 | [diff] [blame] | 2974 | struct weston_mode mode = {0, |
Pekka Paalanen | 952b6c8 | 2014-03-14 14:38:15 +0200 | [diff] [blame] | 2975 | surf_width * surface->buffer_viewport.buffer.scale, |
| 2976 | surf_height * surface->buffer_viewport.buffer.scale, |
Alex Wu | bd3354b | 2012-04-17 17:20:49 +0800 | [diff] [blame] | 2977 | shsurf->fullscreen.framerate}; |
| 2978 | |
Derek Foreman | 6ae7bc9 | 2014-11-04 10:47:33 -0600 | [diff] [blame] | 2979 | if (weston_output_mode_switch_to_temporary(output, &mode, |
| 2980 | surface->buffer_viewport.buffer.scale) == 0) { |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 2981 | weston_view_set_position(shsurf->view, |
| 2982 | output->x - surf_x, |
| 2983 | output->y - surf_y); |
Jason Ekstrand | 918f2dd | 2013-12-02 21:01:53 -0600 | [diff] [blame] | 2984 | shsurf->fullscreen.black_view->surface->width = output->width; |
| 2985 | shsurf->fullscreen.black_view->surface->height = output->height; |
| 2986 | weston_view_set_position(shsurf->fullscreen.black_view, |
| 2987 | output->x - surf_x, |
| 2988 | output->y - surf_y); |
Alex Wu | bd3354b | 2012-04-17 17:20:49 +0800 | [diff] [blame] | 2989 | break; |
Alexander Larsson | d622ed3 | 2013-05-28 16:23:40 +0200 | [diff] [blame] | 2990 | } else { |
Mario Kleiner | 492c12f | 2015-06-21 21:25:12 +0200 | [diff] [blame] | 2991 | weston_log("shell: Can't switch to temporary mode.\n"); |
Alexander Larsson | f82b6ca | 2013-05-28 16:23:39 +0200 | [diff] [blame] | 2992 | restore_output_mode(output); |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 2993 | center_on_output(shsurf->view, output); |
Alexander Larsson | d622ed3 | 2013-05-28 16:23:40 +0200 | [diff] [blame] | 2994 | } |
Alex Wu | bd3354b | 2012-04-17 17:20:49 +0800 | [diff] [blame] | 2995 | } |
Alex Wu | 4539b08 | 2012-03-01 12:57:46 +0800 | [diff] [blame] | 2996 | break; |
| 2997 | case WL_SHELL_SURFACE_FULLSCREEN_METHOD_FILL: |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 2998 | center_on_output(shsurf->view, output); |
Alex Wu | 4539b08 | 2012-03-01 12:57:46 +0800 | [diff] [blame] | 2999 | break; |
| 3000 | default: |
| 3001 | break; |
| 3002 | } |
| 3003 | } |
| 3004 | |
Alex Wu | 4539b08 | 2012-03-01 12:57:46 +0800 | [diff] [blame] | 3005 | static void |
| 3006 | shell_map_fullscreen(struct shell_surface *shsurf) |
| 3007 | { |
Alex Wu | bd3354b | 2012-04-17 17:20:49 +0800 | [diff] [blame] | 3008 | shell_configure_fullscreen(shsurf); |
Alex Wu | 4539b08 | 2012-03-01 12:57:46 +0800 | [diff] [blame] | 3009 | } |
| 3010 | |
Kristian Høgsberg | 7a5c979 | 2011-06-18 06:12:54 -0400 | [diff] [blame] | 3011 | static void |
Tiago Vignatti | fb2adba | 2013-06-12 15:43:21 -0300 | [diff] [blame] | 3012 | set_xwayland(struct shell_surface *shsurf, int x, int y, uint32_t flags) |
| 3013 | { |
| 3014 | /* XXX: using the same fields for transient type */ |
Rafael Antognolli | 03b1659 | 2013-12-03 15:35:42 -0200 | [diff] [blame] | 3015 | surface_clear_next_states(shsurf); |
Tiago Vignatti | fb2adba | 2013-06-12 15:43:21 -0300 | [diff] [blame] | 3016 | shsurf->transient.x = x; |
| 3017 | shsurf->transient.y = y; |
| 3018 | shsurf->transient.flags = flags; |
Philip Withnall | dc4332f | 2013-11-25 18:01:38 +0000 | [diff] [blame] | 3019 | |
| 3020 | shell_surface_set_parent(shsurf, NULL); |
| 3021 | |
Pekka Paalanen | b502654 | 2014-11-12 15:09:24 +0200 | [diff] [blame] | 3022 | set_type(shsurf, SHELL_SURFACE_XWAYLAND); |
Kristian Høgsberg | 8bc525c | 2014-01-01 22:34:49 -0800 | [diff] [blame] | 3023 | shsurf->state_changed = true; |
Tiago Vignatti | fb2adba | 2013-06-12 15:43:21 -0300 | [diff] [blame] | 3024 | } |
| 3025 | |
Kristian Høgsberg | 4779241 | 2014-05-04 13:47:06 -0700 | [diff] [blame] | 3026 | static void |
| 3027 | shell_interface_set_fullscreen(struct shell_surface *shsurf, |
| 3028 | uint32_t method, |
| 3029 | uint32_t framerate, |
| 3030 | struct weston_output *output) |
| 3031 | { |
| 3032 | surface_clear_next_states(shsurf); |
Kristian Høgsberg | 4779241 | 2014-05-04 13:47:06 -0700 | [diff] [blame] | 3033 | shsurf->next_state.fullscreen = true; |
| 3034 | shsurf->state_changed = true; |
Marek Chalupa | e9fe467 | 2014-10-29 13:44:44 +0100 | [diff] [blame] | 3035 | |
| 3036 | set_fullscreen(shsurf, method, framerate, output); |
Kristian Høgsberg | 4779241 | 2014-05-04 13:47:06 -0700 | [diff] [blame] | 3037 | } |
| 3038 | |
Giulio Camuffo | 6b4b241 | 2015-01-29 19:06:49 +0200 | [diff] [blame] | 3039 | static struct weston_output * |
| 3040 | get_focused_output(struct weston_compositor *compositor) |
| 3041 | { |
| 3042 | struct weston_seat *seat; |
| 3043 | struct weston_output *output = NULL; |
| 3044 | |
| 3045 | wl_list_for_each(seat, &compositor->seat_list, link) { |
Derek Foreman | 1281a36 | 2015-07-31 16:55:32 -0500 | [diff] [blame] | 3046 | struct weston_touch *touch = weston_seat_get_touch(seat); |
| 3047 | struct weston_pointer *pointer = weston_seat_get_pointer(seat); |
| 3048 | struct weston_keyboard *keyboard = |
| 3049 | weston_seat_get_keyboard(seat); |
| 3050 | |
Giulio Camuffo | 6b4b241 | 2015-01-29 19:06:49 +0200 | [diff] [blame] | 3051 | /* Priority has touch focus, then pointer and |
| 3052 | * then keyboard focus. We should probably have |
| 3053 | * three for loops and check frist for touch, |
| 3054 | * then for pointer, etc. but unless somebody has some |
| 3055 | * objections, I think this is sufficient. */ |
Derek Foreman | 1281a36 | 2015-07-31 16:55:32 -0500 | [diff] [blame] | 3056 | if (touch && touch->focus) |
| 3057 | output = touch->focus->output; |
| 3058 | else if (pointer && pointer->focus) |
| 3059 | output = pointer->focus->output; |
| 3060 | else if (keyboard && keyboard->focus) |
| 3061 | output = keyboard->focus->output; |
Giulio Camuffo | 6b4b241 | 2015-01-29 19:06:49 +0200 | [diff] [blame] | 3062 | |
| 3063 | if (output) |
| 3064 | break; |
| 3065 | } |
| 3066 | |
| 3067 | return output; |
| 3068 | } |
| 3069 | |
| 3070 | static void |
| 3071 | shell_interface_set_maximized(struct shell_surface *shsurf) |
| 3072 | { |
| 3073 | struct weston_output *output; |
| 3074 | |
| 3075 | surface_clear_next_states(shsurf); |
| 3076 | shsurf->next_state.maximized = true; |
| 3077 | shsurf->state_changed = true; |
| 3078 | shsurf->type = SHELL_SURFACE_TOPLEVEL; |
| 3079 | |
| 3080 | if (!weston_surface_is_mapped(shsurf->surface)) |
| 3081 | output = get_focused_output(shsurf->surface->compositor); |
| 3082 | else |
| 3083 | output = shsurf->surface->output; |
| 3084 | |
| 3085 | shell_surface_set_output(shsurf, output); |
| 3086 | send_configure_for_surface(shsurf); |
| 3087 | } |
| 3088 | |
Kristian Høgsberg | ae356ae | 2014-04-29 16:03:54 -0700 | [diff] [blame] | 3089 | static int |
Derek Foreman | e4d6c83 | 2015-08-05 14:48:11 -0500 | [diff] [blame] | 3090 | shell_interface_move(struct shell_surface *shsurf, struct weston_pointer *pointer) |
Kristian Høgsberg | ae356ae | 2014-04-29 16:03:54 -0700 | [diff] [blame] | 3091 | { |
Derek Foreman | e4d6c83 | 2015-08-05 14:48:11 -0500 | [diff] [blame] | 3092 | return surface_move(shsurf, pointer, true); |
Kristian Høgsberg | ae356ae | 2014-04-29 16:03:54 -0700 | [diff] [blame] | 3093 | } |
| 3094 | |
Derek Foreman | 8fbebbd | 2015-07-15 13:00:40 -0500 | [diff] [blame] | 3095 | static int |
| 3096 | shell_interface_resize(struct shell_surface *shsurf, |
Derek Foreman | e4d6c83 | 2015-08-05 14:48:11 -0500 | [diff] [blame] | 3097 | struct weston_pointer *pointer, |
Derek Foreman | 8fbebbd | 2015-07-15 13:00:40 -0500 | [diff] [blame] | 3098 | uint32_t edges) |
| 3099 | { |
Derek Foreman | e4d6c83 | 2015-08-05 14:48:11 -0500 | [diff] [blame] | 3100 | return surface_resize(shsurf, pointer, edges); |
Derek Foreman | 8fbebbd | 2015-07-15 13:00:40 -0500 | [diff] [blame] | 3101 | } |
| 3102 | |
Kristian Høgsberg | 02bbabb | 2013-05-06 22:15:05 -0400 | [diff] [blame] | 3103 | static const struct weston_pointer_grab_interface popup_grab_interface; |
Giulio Camuffo | 5085a75 | 2013-03-25 21:42:45 +0100 | [diff] [blame] | 3104 | |
| 3105 | static void |
| 3106 | destroy_shell_seat(struct wl_listener *listener, void *data) |
| 3107 | { |
| 3108 | struct shell_seat *shseat = |
| 3109 | container_of(listener, |
| 3110 | struct shell_seat, seat_destroy_listener); |
Jonas Ådahl | c2b1011 | 2015-02-13 14:01:53 +0800 | [diff] [blame] | 3111 | struct shell_surface *shsurf, *next; |
Giulio Camuffo | 5085a75 | 2013-03-25 21:42:45 +0100 | [diff] [blame] | 3112 | |
| 3113 | if (shseat->popup_grab.grab.interface == &popup_grab_interface) { |
Kristian Høgsberg | 02bbabb | 2013-05-06 22:15:05 -0400 | [diff] [blame] | 3114 | weston_pointer_end_grab(shseat->popup_grab.grab.pointer); |
Giulio Camuffo | 5085a75 | 2013-03-25 21:42:45 +0100 | [diff] [blame] | 3115 | shseat->popup_grab.client = NULL; |
| 3116 | |
Jonas Ådahl | c2b1011 | 2015-02-13 14:01:53 +0800 | [diff] [blame] | 3117 | wl_list_for_each_safe(shsurf, next, |
| 3118 | &shseat->popup_grab.surfaces_list, |
| 3119 | popup.grab_link) { |
Giulio Camuffo | 5085a75 | 2013-03-25 21:42:45 +0100 | [diff] [blame] | 3120 | shsurf->popup.shseat = NULL; |
Jonas Ådahl | c2b1011 | 2015-02-13 14:01:53 +0800 | [diff] [blame] | 3121 | wl_list_init(&shsurf->popup.grab_link); |
Giulio Camuffo | 5085a75 | 2013-03-25 21:42:45 +0100 | [diff] [blame] | 3122 | } |
Giulio Camuffo | 5085a75 | 2013-03-25 21:42:45 +0100 | [diff] [blame] | 3123 | } |
| 3124 | |
| 3125 | wl_list_remove(&shseat->seat_destroy_listener.link); |
| 3126 | free(shseat); |
| 3127 | } |
| 3128 | |
Jason Ekstrand | 024177c | 2014-04-21 19:42:58 -0500 | [diff] [blame] | 3129 | static void |
| 3130 | shell_seat_caps_changed(struct wl_listener *listener, void *data) |
| 3131 | { |
Derek Foreman | 1281a36 | 2015-07-31 16:55:32 -0500 | [diff] [blame] | 3132 | struct weston_keyboard *keyboard; |
| 3133 | struct weston_pointer *pointer; |
Jason Ekstrand | 024177c | 2014-04-21 19:42:58 -0500 | [diff] [blame] | 3134 | struct shell_seat *seat; |
| 3135 | |
| 3136 | seat = container_of(listener, struct shell_seat, caps_changed_listener); |
Derek Foreman | 1281a36 | 2015-07-31 16:55:32 -0500 | [diff] [blame] | 3137 | keyboard = weston_seat_get_keyboard(seat->seat); |
| 3138 | pointer = weston_seat_get_pointer(seat->seat); |
Jason Ekstrand | 024177c | 2014-04-21 19:42:58 -0500 | [diff] [blame] | 3139 | |
Derek Foreman | 1281a36 | 2015-07-31 16:55:32 -0500 | [diff] [blame] | 3140 | if (keyboard && |
Jason Ekstrand | 024177c | 2014-04-21 19:42:58 -0500 | [diff] [blame] | 3141 | wl_list_empty(&seat->keyboard_focus_listener.link)) { |
Derek Foreman | 1281a36 | 2015-07-31 16:55:32 -0500 | [diff] [blame] | 3142 | wl_signal_add(&keyboard->focus_signal, |
Jason Ekstrand | 024177c | 2014-04-21 19:42:58 -0500 | [diff] [blame] | 3143 | &seat->keyboard_focus_listener); |
Derek Foreman | 1281a36 | 2015-07-31 16:55:32 -0500 | [diff] [blame] | 3144 | } else if (!keyboard) { |
Derek Foreman | 60d9731 | 2015-07-15 13:00:45 -0500 | [diff] [blame] | 3145 | wl_list_remove(&seat->keyboard_focus_listener.link); |
Jason Ekstrand | 024177c | 2014-04-21 19:42:58 -0500 | [diff] [blame] | 3146 | wl_list_init(&seat->keyboard_focus_listener.link); |
| 3147 | } |
| 3148 | |
Derek Foreman | 1281a36 | 2015-07-31 16:55:32 -0500 | [diff] [blame] | 3149 | if (pointer && |
Jason Ekstrand | 024177c | 2014-04-21 19:42:58 -0500 | [diff] [blame] | 3150 | wl_list_empty(&seat->pointer_focus_listener.link)) { |
Derek Foreman | 1281a36 | 2015-07-31 16:55:32 -0500 | [diff] [blame] | 3151 | wl_signal_add(&pointer->focus_signal, |
Jason Ekstrand | 024177c | 2014-04-21 19:42:58 -0500 | [diff] [blame] | 3152 | &seat->pointer_focus_listener); |
Derek Foreman | 1281a36 | 2015-07-31 16:55:32 -0500 | [diff] [blame] | 3153 | } else if (!pointer) { |
Derek Foreman | 60d9731 | 2015-07-15 13:00:45 -0500 | [diff] [blame] | 3154 | wl_list_remove(&seat->pointer_focus_listener.link); |
Jason Ekstrand | 024177c | 2014-04-21 19:42:58 -0500 | [diff] [blame] | 3155 | wl_list_init(&seat->pointer_focus_listener.link); |
| 3156 | } |
| 3157 | } |
| 3158 | |
Giulio Camuffo | 5085a75 | 2013-03-25 21:42:45 +0100 | [diff] [blame] | 3159 | static struct shell_seat * |
| 3160 | create_shell_seat(struct weston_seat *seat) |
| 3161 | { |
| 3162 | struct shell_seat *shseat; |
| 3163 | |
| 3164 | shseat = calloc(1, sizeof *shseat); |
| 3165 | if (!shseat) { |
| 3166 | weston_log("no memory to allocate shell seat\n"); |
| 3167 | return NULL; |
| 3168 | } |
| 3169 | |
| 3170 | shseat->seat = seat; |
| 3171 | wl_list_init(&shseat->popup_grab.surfaces_list); |
| 3172 | |
| 3173 | shseat->seat_destroy_listener.notify = destroy_shell_seat; |
| 3174 | wl_signal_add(&seat->destroy_signal, |
| 3175 | &shseat->seat_destroy_listener); |
| 3176 | |
Jason Ekstrand | 024177c | 2014-04-21 19:42:58 -0500 | [diff] [blame] | 3177 | shseat->keyboard_focus_listener.notify = handle_keyboard_focus; |
| 3178 | wl_list_init(&shseat->keyboard_focus_listener.link); |
| 3179 | |
| 3180 | shseat->pointer_focus_listener.notify = handle_pointer_focus; |
| 3181 | wl_list_init(&shseat->pointer_focus_listener.link); |
| 3182 | |
| 3183 | shseat->caps_changed_listener.notify = shell_seat_caps_changed; |
| 3184 | wl_signal_add(&seat->updated_caps_signal, |
| 3185 | &shseat->caps_changed_listener); |
| 3186 | shell_seat_caps_changed(&shseat->caps_changed_listener, NULL); |
| 3187 | |
Giulio Camuffo | 5085a75 | 2013-03-25 21:42:45 +0100 | [diff] [blame] | 3188 | return shseat; |
| 3189 | } |
| 3190 | |
| 3191 | static struct shell_seat * |
| 3192 | get_shell_seat(struct weston_seat *seat) |
| 3193 | { |
| 3194 | struct wl_listener *listener; |
| 3195 | |
| 3196 | listener = wl_signal_get(&seat->destroy_signal, destroy_shell_seat); |
Jason Ekstrand | 024177c | 2014-04-21 19:42:58 -0500 | [diff] [blame] | 3197 | assert(listener != NULL); |
Giulio Camuffo | 5085a75 | 2013-03-25 21:42:45 +0100 | [diff] [blame] | 3198 | |
| 3199 | return container_of(listener, |
| 3200 | struct shell_seat, seat_destroy_listener); |
| 3201 | } |
| 3202 | |
Kristian Høgsberg | b810eb5 | 2013-02-12 20:07:05 -0500 | [diff] [blame] | 3203 | static void |
Kristian Høgsberg | 6848c25 | 2013-05-08 22:02:59 -0400 | [diff] [blame] | 3204 | popup_grab_focus(struct weston_pointer_grab *grab) |
Kristian Høgsberg | b3cca0a | 2012-01-04 22:19:14 -0500 | [diff] [blame] | 3205 | { |
Kristian Høgsberg | 02bbabb | 2013-05-06 22:15:05 -0400 | [diff] [blame] | 3206 | struct weston_pointer *pointer = grab->pointer; |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 3207 | struct weston_view *view; |
Giulio Camuffo | 5085a75 | 2013-03-25 21:42:45 +0100 | [diff] [blame] | 3208 | struct shell_seat *shseat = |
| 3209 | container_of(grab, struct shell_seat, popup_grab.grab); |
| 3210 | struct wl_client *client = shseat->popup_grab.client; |
Kristian Høgsberg | 6848c25 | 2013-05-08 22:02:59 -0400 | [diff] [blame] | 3211 | wl_fixed_t sx, sy; |
| 3212 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 3213 | view = weston_compositor_pick_view(pointer->seat->compositor, |
| 3214 | pointer->x, pointer->y, |
| 3215 | &sx, &sy); |
Kristian Høgsberg | b3cca0a | 2012-01-04 22:19:14 -0500 | [diff] [blame] | 3216 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 3217 | if (view && view->surface->resource && |
| 3218 | wl_resource_get_client(view->surface->resource) == client) { |
| 3219 | weston_pointer_set_focus(pointer, view, sx, sy); |
Kristian Høgsberg | b3cca0a | 2012-01-04 22:19:14 -0500 | [diff] [blame] | 3220 | } else { |
Kristian Høgsberg | 02bbabb | 2013-05-06 22:15:05 -0400 | [diff] [blame] | 3221 | weston_pointer_set_focus(pointer, NULL, |
| 3222 | wl_fixed_from_int(0), |
| 3223 | wl_fixed_from_int(0)); |
Kristian Høgsberg | b3cca0a | 2012-01-04 22:19:14 -0500 | [diff] [blame] | 3224 | } |
| 3225 | } |
| 3226 | |
| 3227 | static void |
Giulio Camuffo | 1959ab8 | 2013-11-14 23:42:52 +0100 | [diff] [blame] | 3228 | popup_grab_motion(struct weston_pointer_grab *grab, uint32_t time, |
| 3229 | wl_fixed_t x, wl_fixed_t y) |
Kristian Høgsberg | b3cca0a | 2012-01-04 22:19:14 -0500 | [diff] [blame] | 3230 | { |
Kristian Høgsberg | be6403e | 2013-05-08 21:03:21 -0400 | [diff] [blame] | 3231 | struct weston_pointer *pointer = grab->pointer; |
Neil Roberts | 96d790e | 2013-09-19 17:32:00 +0100 | [diff] [blame] | 3232 | struct wl_resource *resource; |
Kristian Høgsberg | be6403e | 2013-05-08 21:03:21 -0400 | [diff] [blame] | 3233 | wl_fixed_t sx, sy; |
Kristian Høgsberg | b3cca0a | 2012-01-04 22:19:14 -0500 | [diff] [blame] | 3234 | |
Jonas Ådahl | 61917c8 | 2014-08-11 22:44:02 +0200 | [diff] [blame] | 3235 | if (pointer->focus) { |
| 3236 | weston_view_from_global_fixed(pointer->focus, x, y, |
| 3237 | &pointer->sx, &pointer->sy); |
| 3238 | } |
| 3239 | |
Giulio Camuffo | 1959ab8 | 2013-11-14 23:42:52 +0100 | [diff] [blame] | 3240 | weston_pointer_move(pointer, x, y); |
| 3241 | |
Neil Roberts | 96d790e | 2013-09-19 17:32:00 +0100 | [diff] [blame] | 3242 | wl_resource_for_each(resource, &pointer->focus_resource_list) { |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 3243 | weston_view_from_global_fixed(pointer->focus, |
| 3244 | pointer->x, pointer->y, |
| 3245 | &sx, &sy); |
Neil Roberts | 96d790e | 2013-09-19 17:32:00 +0100 | [diff] [blame] | 3246 | wl_pointer_send_motion(resource, time, sx, sy); |
Kristian Høgsberg | be6403e | 2013-05-08 21:03:21 -0400 | [diff] [blame] | 3247 | } |
Kristian Høgsberg | b3cca0a | 2012-01-04 22:19:14 -0500 | [diff] [blame] | 3248 | } |
| 3249 | |
| 3250 | static void |
Kristian Høgsberg | 02bbabb | 2013-05-06 22:15:05 -0400 | [diff] [blame] | 3251 | popup_grab_button(struct weston_pointer_grab *grab, |
Daniel Stone | 4dbadb1 | 2012-05-30 16:31:51 +0100 | [diff] [blame] | 3252 | uint32_t time, uint32_t button, uint32_t state_w) |
Kristian Høgsberg | b3cca0a | 2012-01-04 22:19:14 -0500 | [diff] [blame] | 3253 | { |
| 3254 | struct wl_resource *resource; |
Giulio Camuffo | 5085a75 | 2013-03-25 21:42:45 +0100 | [diff] [blame] | 3255 | struct shell_seat *shseat = |
| 3256 | container_of(grab, struct shell_seat, popup_grab.grab); |
Rob Bradford | 880ebc7 | 2013-07-22 17:31:38 +0100 | [diff] [blame] | 3257 | struct wl_display *display = shseat->seat->compositor->wl_display; |
Daniel Stone | 4dbadb1 | 2012-05-30 16:31:51 +0100 | [diff] [blame] | 3258 | enum wl_pointer_button_state state = state_w; |
Kristian Høgsberg | eae5de7 | 2012-04-11 22:42:15 -0400 | [diff] [blame] | 3259 | uint32_t serial; |
Neil Roberts | 96d790e | 2013-09-19 17:32:00 +0100 | [diff] [blame] | 3260 | struct wl_list *resource_list; |
Kristian Høgsberg | b3cca0a | 2012-01-04 22:19:14 -0500 | [diff] [blame] | 3261 | |
Neil Roberts | 96d790e | 2013-09-19 17:32:00 +0100 | [diff] [blame] | 3262 | resource_list = &grab->pointer->focus_resource_list; |
| 3263 | if (!wl_list_empty(resource_list)) { |
Kristian Høgsberg | eae5de7 | 2012-04-11 22:42:15 -0400 | [diff] [blame] | 3264 | serial = wl_display_get_serial(display); |
Neil Roberts | 96d790e | 2013-09-19 17:32:00 +0100 | [diff] [blame] | 3265 | wl_resource_for_each(resource, resource_list) { |
| 3266 | wl_pointer_send_button(resource, serial, |
| 3267 | time, button, state); |
| 3268 | } |
Daniel Stone | 4dbadb1 | 2012-05-30 16:31:51 +0100 | [diff] [blame] | 3269 | } else if (state == WL_POINTER_BUTTON_STATE_RELEASED && |
Giulio Camuffo | 5085a75 | 2013-03-25 21:42:45 +0100 | [diff] [blame] | 3270 | (shseat->popup_grab.initial_up || |
Derek Foreman | f7b2f8b | 2015-07-15 13:00:41 -0500 | [diff] [blame] | 3271 | time - grab->pointer->grab_time > 500)) { |
Kristian Høgsberg | 57e0907 | 2012-10-30 14:07:27 -0400 | [diff] [blame] | 3272 | popup_grab_end(grab->pointer); |
Kristian Høgsberg | b3cca0a | 2012-01-04 22:19:14 -0500 | [diff] [blame] | 3273 | } |
| 3274 | |
Daniel Stone | 4dbadb1 | 2012-05-30 16:31:51 +0100 | [diff] [blame] | 3275 | if (state == WL_POINTER_BUTTON_STATE_RELEASED) |
Giulio Camuffo | 5085a75 | 2013-03-25 21:42:45 +0100 | [diff] [blame] | 3276 | shseat->popup_grab.initial_up = 1; |
Kristian Høgsberg | b3cca0a | 2012-01-04 22:19:14 -0500 | [diff] [blame] | 3277 | } |
| 3278 | |
Jonas Ådahl | 1ea343e | 2013-10-25 23:18:05 +0200 | [diff] [blame] | 3279 | static void |
| 3280 | popup_grab_cancel(struct weston_pointer_grab *grab) |
| 3281 | { |
| 3282 | popup_grab_end(grab->pointer); |
| 3283 | } |
| 3284 | |
Kristian Høgsberg | 02bbabb | 2013-05-06 22:15:05 -0400 | [diff] [blame] | 3285 | static const struct weston_pointer_grab_interface popup_grab_interface = { |
Kristian Høgsberg | b3cca0a | 2012-01-04 22:19:14 -0500 | [diff] [blame] | 3286 | popup_grab_focus, |
| 3287 | popup_grab_motion, |
| 3288 | popup_grab_button, |
Jonas Ådahl | 1ea343e | 2013-10-25 23:18:05 +0200 | [diff] [blame] | 3289 | popup_grab_cancel, |
Kristian Høgsberg | b3cca0a | 2012-01-04 22:19:14 -0500 | [diff] [blame] | 3290 | }; |
| 3291 | |
| 3292 | static void |
Jonny Lamb | 76cf1fe | 2014-08-20 11:27:10 +0200 | [diff] [blame] | 3293 | touch_popup_grab_down(struct weston_touch_grab *grab, uint32_t time, |
Giulio Camuffo | 61ed7b6 | 2015-07-08 11:55:28 +0300 | [diff] [blame^] | 3294 | int touch_id, wl_fixed_t x, wl_fixed_t y) |
Jonny Lamb | 76cf1fe | 2014-08-20 11:27:10 +0200 | [diff] [blame] | 3295 | { |
| 3296 | struct wl_resource *resource; |
| 3297 | struct shell_seat *shseat = |
| 3298 | container_of(grab, struct shell_seat, popup_grab.touch_grab); |
| 3299 | struct wl_display *display = shseat->seat->compositor->wl_display; |
| 3300 | uint32_t serial; |
| 3301 | struct wl_list *resource_list; |
Giulio Camuffo | 61ed7b6 | 2015-07-08 11:55:28 +0300 | [diff] [blame^] | 3302 | wl_fixed_t sx, sy; |
| 3303 | |
| 3304 | weston_view_from_global_fixed(grab->touch->focus, x, y, &sx, &sy); |
Jonny Lamb | 76cf1fe | 2014-08-20 11:27:10 +0200 | [diff] [blame] | 3305 | |
| 3306 | resource_list = &grab->touch->focus_resource_list; |
| 3307 | if (!wl_list_empty(resource_list)) { |
| 3308 | serial = wl_display_get_serial(display); |
| 3309 | wl_resource_for_each(resource, resource_list) { |
| 3310 | wl_touch_send_down(resource, serial, time, |
| 3311 | grab->touch->focus->surface->resource, |
| 3312 | touch_id, sx, sy); |
| 3313 | } |
| 3314 | } |
| 3315 | } |
| 3316 | |
| 3317 | static void |
| 3318 | touch_popup_grab_up(struct weston_touch_grab *grab, uint32_t time, int touch_id) |
| 3319 | { |
| 3320 | struct wl_resource *resource; |
| 3321 | struct shell_seat *shseat = |
| 3322 | container_of(grab, struct shell_seat, popup_grab.touch_grab); |
| 3323 | struct wl_display *display = shseat->seat->compositor->wl_display; |
| 3324 | uint32_t serial; |
| 3325 | struct wl_list *resource_list; |
| 3326 | |
| 3327 | resource_list = &grab->touch->focus_resource_list; |
| 3328 | if (!wl_list_empty(resource_list)) { |
| 3329 | serial = wl_display_get_serial(display); |
| 3330 | wl_resource_for_each(resource, resource_list) { |
| 3331 | wl_touch_send_up(resource, serial, time, touch_id); |
| 3332 | } |
| 3333 | } |
| 3334 | } |
| 3335 | |
| 3336 | static void |
| 3337 | touch_popup_grab_motion(struct weston_touch_grab *grab, uint32_t time, |
Giulio Camuffo | 61ed7b6 | 2015-07-08 11:55:28 +0300 | [diff] [blame^] | 3338 | int touch_id, wl_fixed_t x, wl_fixed_t y) |
Jonny Lamb | 76cf1fe | 2014-08-20 11:27:10 +0200 | [diff] [blame] | 3339 | { |
| 3340 | struct wl_resource *resource; |
| 3341 | struct wl_list *resource_list; |
Giulio Camuffo | 61ed7b6 | 2015-07-08 11:55:28 +0300 | [diff] [blame^] | 3342 | wl_fixed_t sx, sy; |
| 3343 | |
| 3344 | weston_view_from_global_fixed(grab->touch->focus, x, y, &sx, &sy); |
Jonny Lamb | 76cf1fe | 2014-08-20 11:27:10 +0200 | [diff] [blame] | 3345 | |
| 3346 | resource_list = &grab->touch->focus_resource_list; |
| 3347 | if (!wl_list_empty(resource_list)) { |
| 3348 | wl_resource_for_each(resource, resource_list) { |
| 3349 | wl_touch_send_motion(resource, time, touch_id, sx, sy); |
| 3350 | } |
| 3351 | } |
| 3352 | } |
| 3353 | |
| 3354 | static void |
| 3355 | touch_popup_grab_frame(struct weston_touch_grab *grab) |
| 3356 | { |
| 3357 | } |
| 3358 | |
| 3359 | static void |
| 3360 | touch_popup_grab_cancel(struct weston_touch_grab *grab) |
| 3361 | { |
| 3362 | touch_popup_grab_end(grab->touch); |
| 3363 | } |
| 3364 | |
| 3365 | static const struct weston_touch_grab_interface touch_popup_grab_interface = { |
| 3366 | touch_popup_grab_down, |
| 3367 | touch_popup_grab_up, |
| 3368 | touch_popup_grab_motion, |
| 3369 | touch_popup_grab_frame, |
| 3370 | touch_popup_grab_cancel, |
| 3371 | }; |
| 3372 | |
| 3373 | static void |
Rafael Antognolli | e2a3455 | 2013-12-03 15:35:45 -0200 | [diff] [blame] | 3374 | shell_surface_send_popup_done(struct shell_surface *shsurf) |
| 3375 | { |
| 3376 | if (shell_surface_is_wl_shell_surface(shsurf)) |
| 3377 | wl_shell_surface_send_popup_done(shsurf->resource); |
| 3378 | else if (shell_surface_is_xdg_popup(shsurf)) |
Jasper St. Pierre | ecf2a0f | 2015-02-13 14:01:56 +0800 | [diff] [blame] | 3379 | xdg_popup_send_popup_done(shsurf->resource); |
Rafael Antognolli | e2a3455 | 2013-12-03 15:35:45 -0200 | [diff] [blame] | 3380 | } |
| 3381 | |
| 3382 | static void |
Kristian Høgsberg | 02bbabb | 2013-05-06 22:15:05 -0400 | [diff] [blame] | 3383 | popup_grab_end(struct weston_pointer *pointer) |
Kristian Høgsberg | 57e0907 | 2012-10-30 14:07:27 -0400 | [diff] [blame] | 3384 | { |
Kristian Høgsberg | 02bbabb | 2013-05-06 22:15:05 -0400 | [diff] [blame] | 3385 | struct weston_pointer_grab *grab = pointer->grab; |
Giulio Camuffo | 5085a75 | 2013-03-25 21:42:45 +0100 | [diff] [blame] | 3386 | struct shell_seat *shseat = |
| 3387 | container_of(grab, struct shell_seat, popup_grab.grab); |
| 3388 | struct shell_surface *shsurf; |
Jonas Ådahl | c2b1011 | 2015-02-13 14:01:53 +0800 | [diff] [blame] | 3389 | struct shell_surface *next; |
Kristian Høgsberg | 57e0907 | 2012-10-30 14:07:27 -0400 | [diff] [blame] | 3390 | |
| 3391 | if (pointer->grab->interface == &popup_grab_interface) { |
Kristian Høgsberg | 02bbabb | 2013-05-06 22:15:05 -0400 | [diff] [blame] | 3392 | weston_pointer_end_grab(grab->pointer); |
Giulio Camuffo | 5085a75 | 2013-03-25 21:42:45 +0100 | [diff] [blame] | 3393 | shseat->popup_grab.client = NULL; |
Philipp Brüschweiler | 63e7be6 | 2013-04-15 21:09:54 +0200 | [diff] [blame] | 3394 | shseat->popup_grab.grab.interface = NULL; |
| 3395 | assert(!wl_list_empty(&shseat->popup_grab.surfaces_list)); |
Giulio Camuffo | 5085a75 | 2013-03-25 21:42:45 +0100 | [diff] [blame] | 3396 | /* Send the popup_done event to all the popups open */ |
Jonas Ådahl | c2b1011 | 2015-02-13 14:01:53 +0800 | [diff] [blame] | 3397 | wl_list_for_each_safe(shsurf, next, |
| 3398 | &shseat->popup_grab.surfaces_list, |
| 3399 | popup.grab_link) { |
Rafael Antognolli | e2a3455 | 2013-12-03 15:35:45 -0200 | [diff] [blame] | 3400 | shell_surface_send_popup_done(shsurf); |
Giulio Camuffo | 5085a75 | 2013-03-25 21:42:45 +0100 | [diff] [blame] | 3401 | shsurf->popup.shseat = NULL; |
Jonas Ådahl | c2b1011 | 2015-02-13 14:01:53 +0800 | [diff] [blame] | 3402 | wl_list_init(&shsurf->popup.grab_link); |
Giulio Camuffo | 5085a75 | 2013-03-25 21:42:45 +0100 | [diff] [blame] | 3403 | } |
Giulio Camuffo | 5085a75 | 2013-03-25 21:42:45 +0100 | [diff] [blame] | 3404 | wl_list_init(&shseat->popup_grab.surfaces_list); |
| 3405 | } |
| 3406 | } |
| 3407 | |
| 3408 | static void |
Jonny Lamb | 76cf1fe | 2014-08-20 11:27:10 +0200 | [diff] [blame] | 3409 | touch_popup_grab_end(struct weston_touch *touch) |
| 3410 | { |
| 3411 | struct weston_touch_grab *grab = touch->grab; |
| 3412 | struct shell_seat *shseat = |
| 3413 | container_of(grab, struct shell_seat, popup_grab.touch_grab); |
| 3414 | struct shell_surface *shsurf; |
Jonas Ådahl | c2b1011 | 2015-02-13 14:01:53 +0800 | [diff] [blame] | 3415 | struct shell_surface *next; |
Jonny Lamb | 76cf1fe | 2014-08-20 11:27:10 +0200 | [diff] [blame] | 3416 | |
| 3417 | if (touch->grab->interface == &touch_popup_grab_interface) { |
| 3418 | weston_touch_end_grab(grab->touch); |
| 3419 | shseat->popup_grab.client = NULL; |
| 3420 | shseat->popup_grab.touch_grab.interface = NULL; |
| 3421 | assert(!wl_list_empty(&shseat->popup_grab.surfaces_list)); |
| 3422 | /* Send the popup_done event to all the popups open */ |
Jonas Ådahl | c2b1011 | 2015-02-13 14:01:53 +0800 | [diff] [blame] | 3423 | wl_list_for_each_safe(shsurf, next, |
| 3424 | &shseat->popup_grab.surfaces_list, |
| 3425 | popup.grab_link) { |
Jonny Lamb | 76cf1fe | 2014-08-20 11:27:10 +0200 | [diff] [blame] | 3426 | shell_surface_send_popup_done(shsurf); |
| 3427 | shsurf->popup.shseat = NULL; |
Jonas Ådahl | c2b1011 | 2015-02-13 14:01:53 +0800 | [diff] [blame] | 3428 | wl_list_init(&shsurf->popup.grab_link); |
Jonny Lamb | 76cf1fe | 2014-08-20 11:27:10 +0200 | [diff] [blame] | 3429 | } |
Jonny Lamb | 76cf1fe | 2014-08-20 11:27:10 +0200 | [diff] [blame] | 3430 | wl_list_init(&shseat->popup_grab.surfaces_list); |
| 3431 | } |
| 3432 | } |
| 3433 | |
Jasper St. Pierre | da6ecd0 | 2015-02-27 18:35:45 +0800 | [diff] [blame] | 3434 | static struct shell_surface * |
| 3435 | get_top_popup(struct shell_seat *shseat) |
| 3436 | { |
| 3437 | struct shell_surface *shsurf; |
| 3438 | |
| 3439 | if (wl_list_empty(&shseat->popup_grab.surfaces_list)) { |
| 3440 | return NULL; |
| 3441 | } else { |
| 3442 | shsurf = container_of(shseat->popup_grab.surfaces_list.next, |
| 3443 | struct shell_surface, |
| 3444 | popup.grab_link); |
| 3445 | return shsurf; |
| 3446 | } |
| 3447 | } |
| 3448 | |
| 3449 | static int |
Jonas Ådahl | 01193ae | 2015-02-13 14:01:54 +0800 | [diff] [blame] | 3450 | add_popup_grab(struct shell_surface *shsurf, |
| 3451 | struct shell_seat *shseat, |
| 3452 | int32_t type) |
Giulio Camuffo | 5085a75 | 2013-03-25 21:42:45 +0100 | [diff] [blame] | 3453 | { |
Kristian Høgsberg | e314875 | 2013-05-06 23:19:49 -0400 | [diff] [blame] | 3454 | struct weston_seat *seat = shseat->seat; |
Jasper St. Pierre | da6ecd0 | 2015-02-27 18:35:45 +0800 | [diff] [blame] | 3455 | struct shell_surface *parent, *top_surface; |
Derek Foreman | 1281a36 | 2015-07-31 16:55:32 -0500 | [diff] [blame] | 3456 | struct weston_pointer *pointer = weston_seat_get_pointer(seat); |
| 3457 | struct weston_touch *touch = weston_seat_get_touch(seat); |
Jasper St. Pierre | da6ecd0 | 2015-02-27 18:35:45 +0800 | [diff] [blame] | 3458 | |
| 3459 | parent = get_shell_surface(shsurf->parent); |
| 3460 | top_surface = get_top_popup(shseat); |
| 3461 | if (shell_surface_is_xdg_popup(shsurf) && |
Dima Ryazanov | 497f25d | 2015-04-08 11:51:57 -0700 | [diff] [blame] | 3462 | (!parent || |
| 3463 | (top_surface == NULL && !shell_surface_is_xdg_surface(parent)) || |
Jasper St. Pierre | da6ecd0 | 2015-02-27 18:35:45 +0800 | [diff] [blame] | 3464 | (top_surface != NULL && parent != top_surface))) { |
Jonas Ådahl | ee45a55 | 2015-03-18 16:37:47 +0800 | [diff] [blame] | 3465 | wl_resource_post_error(shsurf->owner_resource, |
| 3466 | XDG_SHELL_ERROR_NOT_THE_TOPMOST_POPUP, |
Jasper St. Pierre | da6ecd0 | 2015-02-27 18:35:45 +0800 | [diff] [blame] | 3467 | "xdg_popup was not created on the " |
| 3468 | "topmost popup"); |
| 3469 | return -1; |
| 3470 | } |
Giulio Camuffo | 5085a75 | 2013-03-25 21:42:45 +0100 | [diff] [blame] | 3471 | |
| 3472 | if (wl_list_empty(&shseat->popup_grab.surfaces_list)) { |
Jonny Lamb | 76cf1fe | 2014-08-20 11:27:10 +0200 | [diff] [blame] | 3473 | shseat->popup_grab.type = type; |
Jonas Ådahl | 01193ae | 2015-02-13 14:01:54 +0800 | [diff] [blame] | 3474 | shseat->popup_grab.client = |
| 3475 | wl_resource_get_client(shsurf->resource); |
Jonny Lamb | 76cf1fe | 2014-08-20 11:27:10 +0200 | [diff] [blame] | 3476 | |
| 3477 | if (type == POINTER) { |
Jonas Ådahl | 01193ae | 2015-02-13 14:01:54 +0800 | [diff] [blame] | 3478 | shseat->popup_grab.grab.interface = |
| 3479 | &popup_grab_interface; |
| 3480 | |
| 3481 | /* We must make sure here that this popup was opened |
| 3482 | * after a mouse press, and not just by moving around |
| 3483 | * with other popups already open. */ |
Derek Foreman | 1281a36 | 2015-07-31 16:55:32 -0500 | [diff] [blame] | 3484 | if (pointer->button_count > 0) |
Jonny Lamb | 76cf1fe | 2014-08-20 11:27:10 +0200 | [diff] [blame] | 3485 | shseat->popup_grab.initial_up = 0; |
| 3486 | } else if (type == TOUCH) { |
Jonas Ådahl | 01193ae | 2015-02-13 14:01:54 +0800 | [diff] [blame] | 3487 | shseat->popup_grab.touch_grab.interface = |
| 3488 | &touch_popup_grab_interface; |
Jonny Lamb | 76cf1fe | 2014-08-20 11:27:10 +0200 | [diff] [blame] | 3489 | } |
Giulio Camuffo | 5085a75 | 2013-03-25 21:42:45 +0100 | [diff] [blame] | 3490 | |
Jonas Ådahl | 01193ae | 2015-02-13 14:01:54 +0800 | [diff] [blame] | 3491 | wl_list_insert(&shseat->popup_grab.surfaces_list, |
| 3492 | &shsurf->popup.grab_link); |
Jonny Lamb | 76cf1fe | 2014-08-20 11:27:10 +0200 | [diff] [blame] | 3493 | |
Jonas Ådahl | 01193ae | 2015-02-13 14:01:54 +0800 | [diff] [blame] | 3494 | if (type == POINTER) { |
Derek Foreman | 1281a36 | 2015-07-31 16:55:32 -0500 | [diff] [blame] | 3495 | weston_pointer_start_grab(pointer, |
Jonas Ådahl | 01193ae | 2015-02-13 14:01:54 +0800 | [diff] [blame] | 3496 | &shseat->popup_grab.grab); |
| 3497 | } else if (type == TOUCH) { |
Derek Foreman | 1281a36 | 2015-07-31 16:55:32 -0500 | [diff] [blame] | 3498 | weston_touch_start_grab(touch, |
Jonas Ådahl | 01193ae | 2015-02-13 14:01:54 +0800 | [diff] [blame] | 3499 | &shseat->popup_grab.touch_grab); |
| 3500 | } |
Rob Bradford | dfe3105 | 2013-06-26 19:49:11 +0100 | [diff] [blame] | 3501 | } else { |
Jonas Ådahl | 01193ae | 2015-02-13 14:01:54 +0800 | [diff] [blame] | 3502 | wl_list_insert(&shseat->popup_grab.surfaces_list, |
| 3503 | &shsurf->popup.grab_link); |
Giulio Camuffo | 5085a75 | 2013-03-25 21:42:45 +0100 | [diff] [blame] | 3504 | } |
Jasper St. Pierre | da6ecd0 | 2015-02-27 18:35:45 +0800 | [diff] [blame] | 3505 | |
| 3506 | return 0; |
Giulio Camuffo | 5085a75 | 2013-03-25 21:42:45 +0100 | [diff] [blame] | 3507 | } |
| 3508 | |
| 3509 | static void |
| 3510 | remove_popup_grab(struct shell_surface *shsurf) |
| 3511 | { |
| 3512 | struct shell_seat *shseat = shsurf->popup.shseat; |
| 3513 | |
Jasper St. Pierre | da6ecd0 | 2015-02-27 18:35:45 +0800 | [diff] [blame] | 3514 | if (shell_surface_is_xdg_popup(shsurf) && |
| 3515 | get_top_popup(shseat) != shsurf) { |
Jonas Ådahl | ee45a55 | 2015-03-18 16:37:47 +0800 | [diff] [blame] | 3516 | wl_resource_post_error(shsurf->owner_resource, |
| 3517 | XDG_SHELL_ERROR_NOT_THE_TOPMOST_POPUP, |
Jasper St. Pierre | da6ecd0 | 2015-02-27 18:35:45 +0800 | [diff] [blame] | 3518 | "xdg_popup was destroyed while it was " |
| 3519 | "not the topmost popup."); |
| 3520 | return; |
| 3521 | } |
| 3522 | |
Giulio Camuffo | 5085a75 | 2013-03-25 21:42:45 +0100 | [diff] [blame] | 3523 | wl_list_remove(&shsurf->popup.grab_link); |
| 3524 | wl_list_init(&shsurf->popup.grab_link); |
| 3525 | if (wl_list_empty(&shseat->popup_grab.surfaces_list)) { |
Jonny Lamb | 76cf1fe | 2014-08-20 11:27:10 +0200 | [diff] [blame] | 3526 | if (shseat->popup_grab.type == POINTER) { |
| 3527 | weston_pointer_end_grab(shseat->popup_grab.grab.pointer); |
| 3528 | shseat->popup_grab.grab.interface = NULL; |
| 3529 | } else if (shseat->popup_grab.type == TOUCH) { |
| 3530 | weston_touch_end_grab(shseat->popup_grab.touch_grab.touch); |
| 3531 | shseat->popup_grab.touch_grab.interface = NULL; |
| 3532 | } |
Kristian Høgsberg | 57e0907 | 2012-10-30 14:07:27 -0400 | [diff] [blame] | 3533 | } |
| 3534 | } |
| 3535 | |
Jasper St. Pierre | da6ecd0 | 2015-02-27 18:35:45 +0800 | [diff] [blame] | 3536 | static int |
Kristian Høgsberg | 3730f36 | 2012-04-13 12:40:07 -0400 | [diff] [blame] | 3537 | shell_map_popup(struct shell_surface *shsurf) |
Kristian Høgsberg | b3cca0a | 2012-01-04 22:19:14 -0500 | [diff] [blame] | 3538 | { |
Giulio Camuffo | 5085a75 | 2013-03-25 21:42:45 +0100 | [diff] [blame] | 3539 | struct shell_seat *shseat = shsurf->popup.shseat; |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 3540 | struct weston_view *parent_view = get_default_view(shsurf->parent); |
Derek Foreman | 1281a36 | 2015-07-31 16:55:32 -0500 | [diff] [blame] | 3541 | struct weston_pointer *pointer = weston_seat_get_pointer(shseat->seat); |
| 3542 | struct weston_touch *touch = weston_seat_get_touch(shseat->seat); |
Kristian Høgsberg | b3cca0a | 2012-01-04 22:19:14 -0500 | [diff] [blame] | 3543 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 3544 | shsurf->surface->output = parent_view->output; |
| 3545 | shsurf->view->output = parent_view->output; |
Kristian Høgsberg | b3cca0a | 2012-01-04 22:19:14 -0500 | [diff] [blame] | 3546 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 3547 | weston_view_set_transform_parent(shsurf->view, parent_view); |
| 3548 | weston_view_set_position(shsurf->view, shsurf->popup.x, shsurf->popup.y); |
| 3549 | weston_view_update_transform(shsurf->view); |
Kristian Høgsberg | b3cca0a | 2012-01-04 22:19:14 -0500 | [diff] [blame] | 3550 | |
Derek Foreman | 1281a36 | 2015-07-31 16:55:32 -0500 | [diff] [blame] | 3551 | if (pointer && |
| 3552 | pointer->grab_serial == shsurf->popup.serial) { |
Jasper St. Pierre | da6ecd0 | 2015-02-27 18:35:45 +0800 | [diff] [blame] | 3553 | if (add_popup_grab(shsurf, shseat, POINTER) != 0) |
| 3554 | return -1; |
Derek Foreman | 1281a36 | 2015-07-31 16:55:32 -0500 | [diff] [blame] | 3555 | } else if (touch && |
| 3556 | touch->grab_serial == shsurf->popup.serial) { |
Jasper St. Pierre | da6ecd0 | 2015-02-27 18:35:45 +0800 | [diff] [blame] | 3557 | if (add_popup_grab(shsurf, shseat, TOUCH) != 0) |
| 3558 | return -1; |
Kristian Høgsberg | 3730f36 | 2012-04-13 12:40:07 -0400 | [diff] [blame] | 3559 | } else { |
Rafael Antognolli | e2a3455 | 2013-12-03 15:35:45 -0200 | [diff] [blame] | 3560 | shell_surface_send_popup_done(shsurf); |
Giulio Camuffo | 5085a75 | 2013-03-25 21:42:45 +0100 | [diff] [blame] | 3561 | shseat->popup_grab.client = NULL; |
Kristian Høgsberg | 3730f36 | 2012-04-13 12:40:07 -0400 | [diff] [blame] | 3562 | } |
Jasper St. Pierre | da6ecd0 | 2015-02-27 18:35:45 +0800 | [diff] [blame] | 3563 | |
| 3564 | return 0; |
Kristian Høgsberg | b3cca0a | 2012-01-04 22:19:14 -0500 | [diff] [blame] | 3565 | } |
| 3566 | |
Pekka Paalanen | 9d1613e | 2011-11-25 12:09:16 +0200 | [diff] [blame] | 3567 | static const struct wl_shell_surface_interface shell_surface_implementation = { |
Scott Moreau | ff1db4a | 2012-04-17 19:06:18 -0600 | [diff] [blame] | 3568 | shell_surface_pong, |
Pekka Paalanen | 9d1613e | 2011-11-25 12:09:16 +0200 | [diff] [blame] | 3569 | shell_surface_move, |
| 3570 | shell_surface_resize, |
| 3571 | shell_surface_set_toplevel, |
| 3572 | shell_surface_set_transient, |
Kristian Høgsberg | b3cca0a | 2012-01-04 22:19:14 -0500 | [diff] [blame] | 3573 | shell_surface_set_fullscreen, |
Juan Zhao | 96879df | 2012-02-07 08:45:41 +0800 | [diff] [blame] | 3574 | shell_surface_set_popup, |
Kristian Høgsberg | e7afd91 | 2012-05-02 09:47:44 -0400 | [diff] [blame] | 3575 | shell_surface_set_maximized, |
| 3576 | shell_surface_set_title, |
| 3577 | shell_surface_set_class |
Pekka Paalanen | 9d1613e | 2011-11-25 12:09:16 +0200 | [diff] [blame] | 3578 | }; |
| 3579 | |
| 3580 | static void |
Tiago Vignatti | bc052c9 | 2012-04-19 16:18:18 +0300 | [diff] [blame] | 3581 | destroy_shell_surface(struct shell_surface *shsurf) |
Pekka Paalanen | 9d1613e | 2011-11-25 12:09:16 +0200 | [diff] [blame] | 3582 | { |
Kristian Høgsberg | 9046d24 | 2014-01-10 00:25:30 -0800 | [diff] [blame] | 3583 | struct shell_surface *child, *next; |
| 3584 | |
Jason Ekstrand | 651f00e | 2013-06-14 10:07:54 -0500 | [diff] [blame] | 3585 | wl_signal_emit(&shsurf->destroy_signal, shsurf); |
| 3586 | |
Giulio Camuffo | 5085a75 | 2013-03-25 21:42:45 +0100 | [diff] [blame] | 3587 | if (!wl_list_empty(&shsurf->popup.grab_link)) { |
| 3588 | remove_popup_grab(shsurf); |
| 3589 | } |
Kristian Høgsberg | b3cca0a | 2012-01-04 22:19:14 -0500 | [diff] [blame] | 3590 | |
Alex Wu | bd3354b | 2012-04-17 17:20:49 +0800 | [diff] [blame] | 3591 | if (shsurf->fullscreen.type == WL_SHELL_SURFACE_FULLSCREEN_METHOD_DRIVER && |
Alexander Larsson | f82b6ca | 2013-05-28 16:23:39 +0200 | [diff] [blame] | 3592 | shell_surface_is_top_fullscreen(shsurf)) |
| 3593 | restore_output_mode (shsurf->fullscreen_output); |
Pekka Paalanen | 9d1613e | 2011-11-25 12:09:16 +0200 | [diff] [blame] | 3594 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 3595 | if (shsurf->fullscreen.black_view) |
| 3596 | weston_surface_destroy(shsurf->fullscreen.black_view->surface); |
Alex Wu | aa08e2d | 2012-03-05 11:01:40 +0800 | [diff] [blame] | 3597 | |
Alex Wu | bd3354b | 2012-04-17 17:20:49 +0800 | [diff] [blame] | 3598 | /* As destroy_resource() use wl_list_for_each_safe(), |
| 3599 | * we can always remove the listener. |
| 3600 | */ |
| 3601 | wl_list_remove(&shsurf->surface_destroy_listener.link); |
| 3602 | shsurf->surface->configure = NULL; |
Pekka Paalanen | 8274d90 | 2014-08-06 19:36:51 +0300 | [diff] [blame] | 3603 | weston_surface_set_label_func(shsurf->surface, NULL); |
Scott Moreau | 976a050 | 2013-03-07 10:15:17 -0700 | [diff] [blame] | 3604 | free(shsurf->title); |
Alex Wu | bd3354b | 2012-04-17 17:20:49 +0800 | [diff] [blame] | 3605 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 3606 | weston_view_destroy(shsurf->view); |
| 3607 | |
Philip Withnall | 648a4dd | 2013-11-25 18:01:44 +0000 | [diff] [blame] | 3608 | wl_list_remove(&shsurf->children_link); |
Emilio Pozuelo Monfort | adaa20c | 2014-01-28 13:54:16 +0100 | [diff] [blame] | 3609 | wl_list_for_each_safe(child, next, &shsurf->children_list, children_link) |
| 3610 | shell_surface_set_parent(child, NULL); |
Philip Withnall | 648a4dd | 2013-11-25 18:01:44 +0000 | [diff] [blame] | 3611 | |
Pekka Paalanen | 9d1613e | 2011-11-25 12:09:16 +0200 | [diff] [blame] | 3612 | wl_list_remove(&shsurf->link); |
| 3613 | free(shsurf); |
| 3614 | } |
| 3615 | |
| 3616 | static void |
Tiago Vignatti | bc052c9 | 2012-04-19 16:18:18 +0300 | [diff] [blame] | 3617 | shell_destroy_shell_surface(struct wl_resource *resource) |
| 3618 | { |
Jason Ekstrand | 651f00e | 2013-06-14 10:07:54 -0500 | [diff] [blame] | 3619 | struct shell_surface *shsurf = wl_resource_get_user_data(resource); |
Tiago Vignatti | bc052c9 | 2012-04-19 16:18:18 +0300 | [diff] [blame] | 3620 | |
Bryan Cain | a46b946 | 2014-04-04 17:41:24 -0500 | [diff] [blame] | 3621 | if (!wl_list_empty(&shsurf->popup.grab_link)) |
| 3622 | remove_popup_grab(shsurf); |
Jonas Ådahl | 49d77d2 | 2015-03-18 16:20:51 +0800 | [diff] [blame] | 3623 | wl_list_remove(wl_resource_get_link(shsurf->resource)); |
Kristian Høgsberg | 160fe75 | 2014-03-11 10:19:10 -0700 | [diff] [blame] | 3624 | shsurf->resource = NULL; |
Tiago Vignatti | bc052c9 | 2012-04-19 16:18:18 +0300 | [diff] [blame] | 3625 | } |
| 3626 | |
| 3627 | static void |
Kristian Høgsberg | 27e3052 | 2012-04-11 23:18:23 -0400 | [diff] [blame] | 3628 | shell_handle_surface_destroy(struct wl_listener *listener, void *data) |
Pekka Paalanen | 9d1613e | 2011-11-25 12:09:16 +0200 | [diff] [blame] | 3629 | { |
| 3630 | struct shell_surface *shsurf = container_of(listener, |
| 3631 | struct shell_surface, |
| 3632 | surface_destroy_listener); |
| 3633 | |
Jason Ekstrand | 651f00e | 2013-06-14 10:07:54 -0500 | [diff] [blame] | 3634 | if (shsurf->resource) |
| 3635 | wl_resource_destroy(shsurf->resource); |
Ander Conselvan de Oliveira | 15f9a26 | 2014-04-29 17:54:02 +0300 | [diff] [blame] | 3636 | |
| 3637 | destroy_shell_surface(shsurf); |
Pekka Paalanen | 9d1613e | 2011-11-25 12:09:16 +0200 | [diff] [blame] | 3638 | } |
| 3639 | |
Kristian Høgsberg | d813445 | 2012-06-21 12:49:02 -0400 | [diff] [blame] | 3640 | static void |
Derek Foreman | 039e9be | 2015-04-14 17:09:06 -0500 | [diff] [blame] | 3641 | fade_out_done_idle_cb(void *data) |
Kristian Høgsberg | 160fe75 | 2014-03-11 10:19:10 -0700 | [diff] [blame] | 3642 | { |
| 3643 | struct shell_surface *shsurf = data; |
| 3644 | |
| 3645 | weston_surface_destroy(shsurf->surface); |
| 3646 | } |
| 3647 | |
| 3648 | static void |
Derek Foreman | 039e9be | 2015-04-14 17:09:06 -0500 | [diff] [blame] | 3649 | fade_out_done(struct weston_view_animation *animation, void *data) |
| 3650 | { |
| 3651 | struct shell_surface *shsurf = data; |
| 3652 | struct wl_event_loop *loop; |
| 3653 | |
| 3654 | loop = wl_display_get_event_loop( |
| 3655 | shsurf->surface->compositor->wl_display); |
| 3656 | |
| 3657 | if (!shsurf->destroying) { |
| 3658 | wl_event_loop_add_idle(loop, fade_out_done_idle_cb, shsurf); |
| 3659 | shsurf->destroying = true; |
| 3660 | } |
| 3661 | } |
| 3662 | |
| 3663 | static void |
Kristian Høgsberg | 160fe75 | 2014-03-11 10:19:10 -0700 | [diff] [blame] | 3664 | handle_resource_destroy(struct wl_listener *listener, void *data) |
| 3665 | { |
| 3666 | struct shell_surface *shsurf = |
| 3667 | container_of(listener, struct shell_surface, |
| 3668 | resource_destroy_listener); |
| 3669 | |
Ander Conselvan de Oliveira | 15f9a26 | 2014-04-29 17:54:02 +0300 | [diff] [blame] | 3670 | if (!weston_surface_is_mapped(shsurf->surface)) |
| 3671 | return; |
| 3672 | |
Kristian Høgsberg | 160fe75 | 2014-03-11 10:19:10 -0700 | [diff] [blame] | 3673 | shsurf->surface->ref_count++; |
| 3674 | |
| 3675 | pixman_region32_fini(&shsurf->surface->pending.input); |
| 3676 | pixman_region32_init(&shsurf->surface->pending.input); |
| 3677 | pixman_region32_fini(&shsurf->surface->input); |
| 3678 | pixman_region32_init(&shsurf->surface->input); |
Jonny Lamb | f322f8e | 2014-08-12 15:13:30 +0200 | [diff] [blame] | 3679 | if (shsurf->shell->win_close_animation_type == ANIMATION_FADE) { |
| 3680 | weston_fade_run(shsurf->view, 1.0, 0.0, 300.0, |
| 3681 | fade_out_done, shsurf); |
| 3682 | } else { |
| 3683 | weston_surface_destroy(shsurf->surface); |
| 3684 | } |
Kristian Høgsberg | 160fe75 | 2014-03-11 10:19:10 -0700 | [diff] [blame] | 3685 | } |
| 3686 | |
| 3687 | static void |
Jason Ekstrand | 918f2dd | 2013-12-02 21:01:53 -0600 | [diff] [blame] | 3688 | shell_surface_configure(struct weston_surface *, int32_t, int32_t); |
Kristian Høgsberg | d813445 | 2012-06-21 12:49:02 -0400 | [diff] [blame] | 3689 | |
Kristian Høgsberg | 1ef2313 | 2013-12-04 00:20:01 -0800 | [diff] [blame] | 3690 | struct shell_surface * |
Kristian Høgsberg | 8334bc1 | 2012-01-03 10:29:47 -0500 | [diff] [blame] | 3691 | get_shell_surface(struct weston_surface *surface) |
Pekka Paalanen | ec2b32f | 2011-11-28 15:12:34 +0200 | [diff] [blame] | 3692 | { |
Kristian Høgsberg | d813445 | 2012-06-21 12:49:02 -0400 | [diff] [blame] | 3693 | if (surface->configure == shell_surface_configure) |
Giulio Camuffo | 7fe01b1 | 2013-03-28 18:02:42 +0100 | [diff] [blame] | 3694 | return surface->configure_private; |
Kristian Høgsberg | d813445 | 2012-06-21 12:49:02 -0400 | [diff] [blame] | 3695 | else |
| 3696 | return NULL; |
Pekka Paalanen | ec2b32f | 2011-11-28 15:12:34 +0200 | [diff] [blame] | 3697 | } |
| 3698 | |
Rafael Antognolli | e2a3455 | 2013-12-03 15:35:45 -0200 | [diff] [blame] | 3699 | static struct shell_surface * |
Jason Ekstrand | 9e9512f | 2014-04-16 21:12:10 -0500 | [diff] [blame] | 3700 | create_common_surface(struct shell_client *owner, void *shell, |
| 3701 | struct weston_surface *surface, |
Rafael Antognolli | e2a3455 | 2013-12-03 15:35:45 -0200 | [diff] [blame] | 3702 | const struct weston_shell_client *client) |
Pekka Paalanen | 9d1613e | 2011-11-25 12:09:16 +0200 | [diff] [blame] | 3703 | { |
Pekka Paalanen | 9d1613e | 2011-11-25 12:09:16 +0200 | [diff] [blame] | 3704 | struct shell_surface *shsurf; |
| 3705 | |
Pekka Paalanen | 50b6747 | 2014-10-01 15:02:41 +0300 | [diff] [blame] | 3706 | assert(surface->configure == NULL); |
Ander Conselvan de Oliveira | 093bfa3 | 2012-03-27 17:36:41 +0300 | [diff] [blame] | 3707 | |
Pekka Paalanen | 9d1613e | 2011-11-25 12:09:16 +0200 | [diff] [blame] | 3708 | shsurf = calloc(1, sizeof *shsurf); |
| 3709 | if (!shsurf) { |
Martin Minarik | 6d11836 | 2012-06-07 18:01:59 +0200 | [diff] [blame] | 3710 | weston_log("no memory to allocate shell surface\n"); |
Kristian Høgsberg | 45ba869 | 2012-05-21 14:27:33 -0400 | [diff] [blame] | 3711 | return NULL; |
Pekka Paalanen | 9d1613e | 2011-11-25 12:09:16 +0200 | [diff] [blame] | 3712 | } |
| 3713 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 3714 | shsurf->view = weston_view_create(surface); |
| 3715 | if (!shsurf->view) { |
| 3716 | weston_log("no memory to allocate shell surface\n"); |
| 3717 | free(shsurf); |
| 3718 | return NULL; |
| 3719 | } |
| 3720 | |
Ander Conselvan de Oliveira | 093bfa3 | 2012-03-27 17:36:41 +0300 | [diff] [blame] | 3721 | surface->configure = shell_surface_configure; |
Giulio Camuffo | 7fe01b1 | 2013-03-28 18:02:42 +0100 | [diff] [blame] | 3722 | surface->configure_private = shsurf; |
Pekka Paalanen | 8274d90 | 2014-08-06 19:36:51 +0300 | [diff] [blame] | 3723 | weston_surface_set_label_func(surface, shell_surface_get_label); |
Ander Conselvan de Oliveira | 093bfa3 | 2012-03-27 17:36:41 +0300 | [diff] [blame] | 3724 | |
Kristian Høgsberg | 160fe75 | 2014-03-11 10:19:10 -0700 | [diff] [blame] | 3725 | shsurf->resource_destroy_listener.notify = handle_resource_destroy; |
| 3726 | wl_resource_add_destroy_listener(surface->resource, |
| 3727 | &shsurf->resource_destroy_listener); |
Jason Ekstrand | 9e9512f | 2014-04-16 21:12:10 -0500 | [diff] [blame] | 3728 | shsurf->owner = owner; |
Kristian Høgsberg | 160fe75 | 2014-03-11 10:19:10 -0700 | [diff] [blame] | 3729 | |
Tiago Vignatti | bc052c9 | 2012-04-19 16:18:18 +0300 | [diff] [blame] | 3730 | shsurf->shell = (struct desktop_shell *) shell; |
Scott Moreau | ff1db4a | 2012-04-17 19:06:18 -0600 | [diff] [blame] | 3731 | shsurf->unresponsive = 0; |
Alex Wu | 4539b08 | 2012-03-01 12:57:46 +0800 | [diff] [blame] | 3732 | shsurf->saved_position_valid = false; |
Rafael Antognolli | 3c4e3f7 | 2013-12-03 15:35:46 -0200 | [diff] [blame] | 3733 | shsurf->saved_size_valid = false; |
Alex Wu | 7bcb8bd | 2012-04-27 09:07:24 +0800 | [diff] [blame] | 3734 | shsurf->saved_rotation_valid = false; |
Pekka Paalanen | 9d1613e | 2011-11-25 12:09:16 +0200 | [diff] [blame] | 3735 | shsurf->surface = surface; |
Alex Wu | 4539b08 | 2012-03-01 12:57:46 +0800 | [diff] [blame] | 3736 | shsurf->fullscreen.type = WL_SHELL_SURFACE_FULLSCREEN_METHOD_DEFAULT; |
| 3737 | shsurf->fullscreen.framerate = 0; |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 3738 | shsurf->fullscreen.black_view = NULL; |
Alex Wu | 4539b08 | 2012-03-01 12:57:46 +0800 | [diff] [blame] | 3739 | wl_list_init(&shsurf->fullscreen.transform.link); |
| 3740 | |
Jasper St. Pierre | 9aa8ce6 | 2014-04-11 16:18:54 -0700 | [diff] [blame] | 3741 | shsurf->output = get_default_output(shsurf->shell->compositor); |
| 3742 | |
Jason Ekstrand | 651f00e | 2013-06-14 10:07:54 -0500 | [diff] [blame] | 3743 | wl_signal_init(&shsurf->destroy_signal); |
Kristian Høgsberg | 27e3052 | 2012-04-11 23:18:23 -0400 | [diff] [blame] | 3744 | shsurf->surface_destroy_listener.notify = shell_handle_surface_destroy; |
Jason Ekstrand | 26ed73c | 2013-06-06 22:34:41 -0500 | [diff] [blame] | 3745 | wl_signal_add(&surface->destroy_signal, |
Kristian Høgsberg | 27e3052 | 2012-04-11 23:18:23 -0400 | [diff] [blame] | 3746 | &shsurf->surface_destroy_listener); |
Pekka Paalanen | 9d1613e | 2011-11-25 12:09:16 +0200 | [diff] [blame] | 3747 | |
| 3748 | /* init link so its safe to always remove it in destroy_shell_surface */ |
| 3749 | wl_list_init(&shsurf->link); |
Giulio Camuffo | 5085a75 | 2013-03-25 21:42:45 +0100 | [diff] [blame] | 3750 | wl_list_init(&shsurf->popup.grab_link); |
Pekka Paalanen | 9d1613e | 2011-11-25 12:09:16 +0200 | [diff] [blame] | 3751 | |
Pekka Paalanen | 460099f | 2012-01-20 16:48:25 +0200 | [diff] [blame] | 3752 | /* empty when not in use */ |
| 3753 | wl_list_init(&shsurf->rotation.transform.link); |
Kristian Høgsberg | 765e27b | 2012-01-27 13:36:13 -0500 | [diff] [blame] | 3754 | weston_matrix_init(&shsurf->rotation.rotation); |
Pekka Paalanen | 460099f | 2012-01-20 16:48:25 +0200 | [diff] [blame] | 3755 | |
Jonas Ådahl | 62fcd04 | 2012-06-13 00:01:23 +0200 | [diff] [blame] | 3756 | wl_list_init(&shsurf->workspace_transform.link); |
| 3757 | |
Philip Withnall | 648a4dd | 2013-11-25 18:01:44 +0000 | [diff] [blame] | 3758 | wl_list_init(&shsurf->children_link); |
| 3759 | wl_list_init(&shsurf->children_list); |
| 3760 | shsurf->parent = NULL; |
| 3761 | |
Pekka Paalanen | b502654 | 2014-11-12 15:09:24 +0200 | [diff] [blame] | 3762 | set_type(shsurf, SHELL_SURFACE_NONE); |
Pekka Paalanen | 9d1613e | 2011-11-25 12:09:16 +0200 | [diff] [blame] | 3763 | |
Kristian Høgsberg | a61ca06 | 2012-05-22 16:05:52 -0400 | [diff] [blame] | 3764 | shsurf->client = client; |
| 3765 | |
Kristian Høgsberg | 45ba869 | 2012-05-21 14:27:33 -0400 | [diff] [blame] | 3766 | return shsurf; |
Tiago Vignatti | bc052c9 | 2012-04-19 16:18:18 +0300 | [diff] [blame] | 3767 | } |
| 3768 | |
Rafael Antognolli | e2a3455 | 2013-12-03 15:35:45 -0200 | [diff] [blame] | 3769 | static struct shell_surface * |
| 3770 | create_shell_surface(void *shell, struct weston_surface *surface, |
| 3771 | const struct weston_shell_client *client) |
| 3772 | { |
Jason Ekstrand | 9e9512f | 2014-04-16 21:12:10 -0500 | [diff] [blame] | 3773 | return create_common_surface(NULL, shell, surface, client); |
Rafael Antognolli | e2a3455 | 2013-12-03 15:35:45 -0200 | [diff] [blame] | 3774 | } |
| 3775 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 3776 | static struct weston_view * |
| 3777 | get_primary_view(void *shell, struct shell_surface *shsurf) |
| 3778 | { |
| 3779 | return shsurf->view; |
| 3780 | } |
| 3781 | |
Tiago Vignatti | bc052c9 | 2012-04-19 16:18:18 +0300 | [diff] [blame] | 3782 | static void |
| 3783 | shell_get_shell_surface(struct wl_client *client, |
| 3784 | struct wl_resource *resource, |
| 3785 | uint32_t id, |
| 3786 | struct wl_resource *surface_resource) |
| 3787 | { |
Jason Ekstrand | 0f2ef7e | 2013-06-14 10:07:53 -0500 | [diff] [blame] | 3788 | struct weston_surface *surface = |
| 3789 | wl_resource_get_user_data(surface_resource); |
Jason Ekstrand | 9e9512f | 2014-04-16 21:12:10 -0500 | [diff] [blame] | 3790 | struct shell_client *sc = wl_resource_get_user_data(resource); |
| 3791 | struct desktop_shell *shell = sc->shell; |
Tiago Vignatti | bc052c9 | 2012-04-19 16:18:18 +0300 | [diff] [blame] | 3792 | struct shell_surface *shsurf; |
| 3793 | |
Pekka Paalanen | 50b6747 | 2014-10-01 15:02:41 +0300 | [diff] [blame] | 3794 | if (weston_surface_set_role(surface, "wl_shell_surface", |
| 3795 | resource, WL_SHELL_ERROR_ROLE) < 0) |
Tiago Vignatti | bc052c9 | 2012-04-19 16:18:18 +0300 | [diff] [blame] | 3796 | return; |
Tiago Vignatti | bc052c9 | 2012-04-19 16:18:18 +0300 | [diff] [blame] | 3797 | |
Jason Ekstrand | 9e9512f | 2014-04-16 21:12:10 -0500 | [diff] [blame] | 3798 | shsurf = create_common_surface(sc, shell, surface, &shell_client); |
Kristian Høgsberg | 9540ea6 | 2012-05-21 14:28:57 -0400 | [diff] [blame] | 3799 | if (!shsurf) { |
Pekka Paalanen | 50b6747 | 2014-10-01 15:02:41 +0300 | [diff] [blame] | 3800 | wl_resource_post_no_memory(surface_resource); |
Kristian Høgsberg | 9540ea6 | 2012-05-21 14:28:57 -0400 | [diff] [blame] | 3801 | return; |
| 3802 | } |
Tiago Vignatti | bc052c9 | 2012-04-19 16:18:18 +0300 | [diff] [blame] | 3803 | |
Jason Ekstrand | a85118c | 2013-06-27 20:17:02 -0500 | [diff] [blame] | 3804 | shsurf->resource = |
| 3805 | wl_resource_create(client, |
| 3806 | &wl_shell_surface_interface, 1, id); |
| 3807 | wl_resource_set_implementation(shsurf->resource, |
| 3808 | &shell_surface_implementation, |
| 3809 | shsurf, shell_destroy_shell_surface); |
Jonas Ådahl | 49d77d2 | 2015-03-18 16:20:51 +0800 | [diff] [blame] | 3810 | wl_list_init(wl_resource_get_link(shsurf->resource)); |
Pekka Paalanen | 9d1613e | 2011-11-25 12:09:16 +0200 | [diff] [blame] | 3811 | } |
| 3812 | |
Rafael Antognolli | e2a3455 | 2013-12-03 15:35:45 -0200 | [diff] [blame] | 3813 | static bool |
| 3814 | shell_surface_is_wl_shell_surface(struct shell_surface *shsurf) |
| 3815 | { |
Kristian Høgsberg | 0b7d995 | 2014-02-03 15:50:38 -0800 | [diff] [blame] | 3816 | /* A shell surface without a resource is created from xwayland |
| 3817 | * and is considered a wl_shell surface for now. */ |
| 3818 | |
| 3819 | return shsurf->resource == NULL || |
| 3820 | wl_resource_instance_of(shsurf->resource, |
| 3821 | &wl_shell_surface_interface, |
| 3822 | &shell_surface_implementation); |
Rafael Antognolli | e2a3455 | 2013-12-03 15:35:45 -0200 | [diff] [blame] | 3823 | } |
| 3824 | |
Pekka Paalanen | 9d1613e | 2011-11-25 12:09:16 +0200 | [diff] [blame] | 3825 | static const struct wl_shell_interface shell_implementation = { |
Pekka Paalanen | 4622967 | 2011-11-29 15:49:31 +0200 | [diff] [blame] | 3826 | shell_get_shell_surface |
Kristian Høgsberg | 4cca349 | 2011-01-18 07:53:49 -0500 | [diff] [blame] | 3827 | }; |
| 3828 | |
Rafael Antognolli | e2a3455 | 2013-12-03 15:35:45 -0200 | [diff] [blame] | 3829 | /**************************** |
| 3830 | * xdg-shell implementation */ |
| 3831 | |
| 3832 | static void |
| 3833 | xdg_surface_destroy(struct wl_client *client, |
| 3834 | struct wl_resource *resource) |
| 3835 | { |
| 3836 | wl_resource_destroy(resource); |
| 3837 | } |
| 3838 | |
| 3839 | static void |
Jasper St. Pierre | c815d62 | 2014-04-10 18:37:54 -0700 | [diff] [blame] | 3840 | xdg_surface_set_parent(struct wl_client *client, |
| 3841 | struct wl_resource *resource, |
| 3842 | struct wl_resource *parent_resource) |
Jasper St. Pierre | 63a9c33 | 2014-02-01 18:35:15 -0500 | [diff] [blame] | 3843 | { |
| 3844 | struct shell_surface *shsurf = wl_resource_get_user_data(resource); |
Jasper St. Pierre | 66bc949 | 2015-02-13 14:01:55 +0800 | [diff] [blame] | 3845 | struct shell_surface *parent; |
Jasper St. Pierre | 63a9c33 | 2014-02-01 18:35:15 -0500 | [diff] [blame] | 3846 | |
Jasper St. Pierre | 66bc949 | 2015-02-13 14:01:55 +0800 | [diff] [blame] | 3847 | if (parent_resource) { |
Jasper St. Pierre | 63a9c33 | 2014-02-01 18:35:15 -0500 | [diff] [blame] | 3848 | parent = wl_resource_get_user_data(parent_resource); |
Jasper St. Pierre | 66bc949 | 2015-02-13 14:01:55 +0800 | [diff] [blame] | 3849 | shell_surface_set_parent(shsurf, parent->surface); |
| 3850 | } else { |
| 3851 | shell_surface_set_parent(shsurf, NULL); |
| 3852 | } |
Jasper St. Pierre | 63a9c33 | 2014-02-01 18:35:15 -0500 | [diff] [blame] | 3853 | } |
| 3854 | |
| 3855 | static void |
Rafael Antognolli | e2a3455 | 2013-12-03 15:35:45 -0200 | [diff] [blame] | 3856 | xdg_surface_set_app_id(struct wl_client *client, |
| 3857 | struct wl_resource *resource, |
| 3858 | const char *app_id) |
| 3859 | { |
| 3860 | struct shell_surface *shsurf = wl_resource_get_user_data(resource); |
| 3861 | |
| 3862 | free(shsurf->class); |
| 3863 | shsurf->class = strdup(app_id); |
Pekka Paalanen | b502654 | 2014-11-12 15:09:24 +0200 | [diff] [blame] | 3864 | shsurf->surface->timeline.force_refresh = 1; |
Rafael Antognolli | e2a3455 | 2013-12-03 15:35:45 -0200 | [diff] [blame] | 3865 | } |
| 3866 | |
| 3867 | static void |
Jasper St. Pierre | 81ff075 | 2014-03-13 11:04:53 -0400 | [diff] [blame] | 3868 | xdg_surface_show_window_menu(struct wl_client *client, |
| 3869 | struct wl_resource *surface_resource, |
| 3870 | struct wl_resource *seat_resource, |
| 3871 | uint32_t serial, |
| 3872 | int32_t x, |
| 3873 | int32_t y) |
| 3874 | { |
| 3875 | /* TODO */ |
| 3876 | } |
| 3877 | |
| 3878 | static void |
Rafael Antognolli | e2a3455 | 2013-12-03 15:35:45 -0200 | [diff] [blame] | 3879 | xdg_surface_set_title(struct wl_client *client, |
| 3880 | struct wl_resource *resource, const char *title) |
| 3881 | { |
| 3882 | struct shell_surface *shsurf = wl_resource_get_user_data(resource); |
| 3883 | |
| 3884 | set_title(shsurf, title); |
| 3885 | } |
| 3886 | |
| 3887 | static void |
| 3888 | xdg_surface_move(struct wl_client *client, struct wl_resource *resource, |
| 3889 | struct wl_resource *seat_resource, uint32_t serial) |
| 3890 | { |
| 3891 | common_surface_move(resource, seat_resource, serial); |
| 3892 | } |
| 3893 | |
| 3894 | static void |
| 3895 | xdg_surface_resize(struct wl_client *client, struct wl_resource *resource, |
| 3896 | struct wl_resource *seat_resource, uint32_t serial, |
| 3897 | uint32_t edges) |
| 3898 | { |
| 3899 | common_surface_resize(resource, seat_resource, serial, edges); |
| 3900 | } |
| 3901 | |
| 3902 | static void |
Jasper St. Pierre | ab2c108 | 2014-04-10 10:41:46 -0700 | [diff] [blame] | 3903 | xdg_surface_ack_configure(struct wl_client *client, |
| 3904 | struct wl_resource *resource, |
| 3905 | uint32_t serial) |
Rafael Antognolli | e2a3455 | 2013-12-03 15:35:45 -0200 | [diff] [blame] | 3906 | { |
| 3907 | struct shell_surface *shsurf = wl_resource_get_user_data(resource); |
| 3908 | |
Jasper St. Pierre | 8c6aa45 | 2014-02-08 18:29:49 -0500 | [diff] [blame] | 3909 | if (shsurf->state_requested) { |
| 3910 | shsurf->next_state = shsurf->requested_state; |
| 3911 | shsurf->state_changed = true; |
| 3912 | shsurf->state_requested = false; |
Rafael Antognolli | 3c4e3f7 | 2013-12-03 15:35:46 -0200 | [diff] [blame] | 3913 | } |
Rafael Antognolli | e2a3455 | 2013-12-03 15:35:45 -0200 | [diff] [blame] | 3914 | } |
| 3915 | |
Manuel Bachmann | 50c87db | 2014-02-26 15:52:13 +0100 | [diff] [blame] | 3916 | static void |
Jasper St. Pierre | ccf48fb | 2014-05-02 10:21:38 -0400 | [diff] [blame] | 3917 | xdg_surface_set_window_geometry(struct wl_client *client, |
| 3918 | struct wl_resource *resource, |
| 3919 | int32_t x, |
| 3920 | int32_t y, |
| 3921 | int32_t width, |
| 3922 | int32_t height) |
| 3923 | { |
| 3924 | struct shell_surface *shsurf = wl_resource_get_user_data(resource); |
| 3925 | |
| 3926 | set_window_geometry(shsurf, x, y, width, height); |
| 3927 | } |
| 3928 | |
| 3929 | static void |
Jasper St. Pierre | ab2c108 | 2014-04-10 10:41:46 -0700 | [diff] [blame] | 3930 | xdg_surface_set_maximized(struct wl_client *client, |
| 3931 | struct wl_resource *resource) |
| 3932 | { |
| 3933 | struct shell_surface *shsurf = wl_resource_get_user_data(resource); |
Marek Chalupa | bfbb64b | 2014-09-08 12:34:20 +0200 | [diff] [blame] | 3934 | struct weston_output *output; |
Jasper St. Pierre | ab2c108 | 2014-04-10 10:41:46 -0700 | [diff] [blame] | 3935 | |
| 3936 | shsurf->state_requested = true; |
| 3937 | shsurf->requested_state.maximized = true; |
Marek Chalupa | bfbb64b | 2014-09-08 12:34:20 +0200 | [diff] [blame] | 3938 | |
| 3939 | if (!weston_surface_is_mapped(shsurf->surface)) |
| 3940 | output = get_focused_output(shsurf->surface->compositor); |
| 3941 | else |
| 3942 | output = shsurf->surface->output; |
| 3943 | |
| 3944 | shell_surface_set_output(shsurf, output); |
Jasper St. Pierre | 9aa8ce6 | 2014-04-11 16:18:54 -0700 | [diff] [blame] | 3945 | send_configure_for_surface(shsurf); |
Jasper St. Pierre | ab2c108 | 2014-04-10 10:41:46 -0700 | [diff] [blame] | 3946 | } |
| 3947 | |
| 3948 | static void |
| 3949 | xdg_surface_unset_maximized(struct wl_client *client, |
| 3950 | struct wl_resource *resource) |
| 3951 | { |
| 3952 | struct shell_surface *shsurf = wl_resource_get_user_data(resource); |
| 3953 | |
| 3954 | shsurf->state_requested = true; |
| 3955 | shsurf->requested_state.maximized = false; |
Jasper St. Pierre | 6458ec3 | 2014-04-11 16:00:31 -0700 | [diff] [blame] | 3956 | send_configure_for_surface(shsurf); |
Jasper St. Pierre | ab2c108 | 2014-04-10 10:41:46 -0700 | [diff] [blame] | 3957 | } |
| 3958 | |
| 3959 | static void |
| 3960 | xdg_surface_set_fullscreen(struct wl_client *client, |
| 3961 | struct wl_resource *resource, |
| 3962 | struct wl_resource *output_resource) |
| 3963 | { |
| 3964 | struct shell_surface *shsurf = wl_resource_get_user_data(resource); |
| 3965 | struct weston_output *output; |
| 3966 | |
| 3967 | shsurf->state_requested = true; |
| 3968 | shsurf->requested_state.fullscreen = true; |
| 3969 | |
| 3970 | if (output_resource) |
| 3971 | output = wl_resource_get_user_data(output_resource); |
| 3972 | else |
| 3973 | output = NULL; |
| 3974 | |
Marek Chalupa | 052917a | 2014-09-02 11:35:12 +0200 | [diff] [blame] | 3975 | /* handle clients launching in fullscreen */ |
| 3976 | if (output == NULL && !weston_surface_is_mapped(shsurf->surface)) { |
| 3977 | /* Set the output to the one that has focus currently. */ |
| 3978 | assert(shsurf->surface); |
| 3979 | output = get_focused_output(shsurf->surface->compositor); |
| 3980 | } |
| 3981 | |
Jasper St. Pierre | 9aa8ce6 | 2014-04-11 16:18:54 -0700 | [diff] [blame] | 3982 | shell_surface_set_output(shsurf, output); |
| 3983 | shsurf->fullscreen_output = shsurf->output; |
Jasper St. Pierre | ab2c108 | 2014-04-10 10:41:46 -0700 | [diff] [blame] | 3984 | |
Jasper St. Pierre | 9aa8ce6 | 2014-04-11 16:18:54 -0700 | [diff] [blame] | 3985 | send_configure_for_surface(shsurf); |
Jasper St. Pierre | ab2c108 | 2014-04-10 10:41:46 -0700 | [diff] [blame] | 3986 | } |
| 3987 | |
| 3988 | static void |
| 3989 | xdg_surface_unset_fullscreen(struct wl_client *client, |
| 3990 | struct wl_resource *resource) |
| 3991 | { |
| 3992 | struct shell_surface *shsurf = wl_resource_get_user_data(resource); |
| 3993 | |
| 3994 | shsurf->state_requested = true; |
| 3995 | shsurf->requested_state.fullscreen = false; |
Jasper St. Pierre | 6458ec3 | 2014-04-11 16:00:31 -0700 | [diff] [blame] | 3996 | send_configure_for_surface(shsurf); |
Jasper St. Pierre | ab2c108 | 2014-04-10 10:41:46 -0700 | [diff] [blame] | 3997 | } |
| 3998 | |
| 3999 | static void |
Manuel Bachmann | 50c87db | 2014-02-26 15:52:13 +0100 | [diff] [blame] | 4000 | xdg_surface_set_minimized(struct wl_client *client, |
| 4001 | struct wl_resource *resource) |
| 4002 | { |
| 4003 | struct shell_surface *shsurf = wl_resource_get_user_data(resource); |
| 4004 | |
| 4005 | if (shsurf->type != SHELL_SURFACE_TOPLEVEL) |
| 4006 | return; |
| 4007 | |
| 4008 | /* apply compositor's own minimization logic (hide) */ |
Manuel Bachmann | dc1c3e4 | 2015-02-16 11:52:13 +0100 | [diff] [blame] | 4009 | set_minimized(shsurf->surface); |
Manuel Bachmann | 50c87db | 2014-02-26 15:52:13 +0100 | [diff] [blame] | 4010 | } |
| 4011 | |
Rafael Antognolli | e2a3455 | 2013-12-03 15:35:45 -0200 | [diff] [blame] | 4012 | static const struct xdg_surface_interface xdg_surface_implementation = { |
| 4013 | xdg_surface_destroy, |
Jasper St. Pierre | c815d62 | 2014-04-10 18:37:54 -0700 | [diff] [blame] | 4014 | xdg_surface_set_parent, |
Rafael Antognolli | e2a3455 | 2013-12-03 15:35:45 -0200 | [diff] [blame] | 4015 | xdg_surface_set_title, |
| 4016 | xdg_surface_set_app_id, |
Jasper St. Pierre | 81ff075 | 2014-03-13 11:04:53 -0400 | [diff] [blame] | 4017 | xdg_surface_show_window_menu, |
Rafael Antognolli | e2a3455 | 2013-12-03 15:35:45 -0200 | [diff] [blame] | 4018 | xdg_surface_move, |
| 4019 | xdg_surface_resize, |
Jasper St. Pierre | ab2c108 | 2014-04-10 10:41:46 -0700 | [diff] [blame] | 4020 | xdg_surface_ack_configure, |
Jasper St. Pierre | ccf48fb | 2014-05-02 10:21:38 -0400 | [diff] [blame] | 4021 | xdg_surface_set_window_geometry, |
Jasper St. Pierre | ab2c108 | 2014-04-10 10:41:46 -0700 | [diff] [blame] | 4022 | xdg_surface_set_maximized, |
| 4023 | xdg_surface_unset_maximized, |
| 4024 | xdg_surface_set_fullscreen, |
| 4025 | xdg_surface_unset_fullscreen, |
| 4026 | xdg_surface_set_minimized, |
Rafael Antognolli | e2a3455 | 2013-12-03 15:35:45 -0200 | [diff] [blame] | 4027 | }; |
| 4028 | |
| 4029 | static void |
| 4030 | xdg_send_configure(struct weston_surface *surface, |
Jasper St. Pierre | ac985be | 2014-04-28 11:19:28 -0400 | [diff] [blame] | 4031 | int32_t width, int32_t height) |
Rafael Antognolli | e2a3455 | 2013-12-03 15:35:45 -0200 | [diff] [blame] | 4032 | { |
| 4033 | struct shell_surface *shsurf = get_shell_surface(surface); |
Jasper St. Pierre | ab2c108 | 2014-04-10 10:41:46 -0700 | [diff] [blame] | 4034 | uint32_t *s; |
| 4035 | struct wl_array states; |
| 4036 | uint32_t serial; |
Rafael Antognolli | e2a3455 | 2013-12-03 15:35:45 -0200 | [diff] [blame] | 4037 | |
U. Artie Eoff | cf5737a | 2014-01-17 10:08:25 -0800 | [diff] [blame] | 4038 | assert(shsurf); |
| 4039 | |
Jasper St. Pierre | ab2c108 | 2014-04-10 10:41:46 -0700 | [diff] [blame] | 4040 | if (!shsurf->resource) |
| 4041 | return; |
| 4042 | |
| 4043 | wl_array_init(&states); |
| 4044 | if (shsurf->requested_state.fullscreen) { |
| 4045 | s = wl_array_add(&states, sizeof *s); |
| 4046 | *s = XDG_SURFACE_STATE_FULLSCREEN; |
| 4047 | } else if (shsurf->requested_state.maximized) { |
| 4048 | s = wl_array_add(&states, sizeof *s); |
| 4049 | *s = XDG_SURFACE_STATE_MAXIMIZED; |
| 4050 | } |
Jasper St. Pierre | 5befdda | 2014-05-06 08:50:47 -0400 | [diff] [blame] | 4051 | if (shsurf->resize_edges != 0) { |
| 4052 | s = wl_array_add(&states, sizeof *s); |
| 4053 | *s = XDG_SURFACE_STATE_RESIZING; |
| 4054 | } |
Jasper St. Pierre | 973d787 | 2014-05-06 08:44:29 -0400 | [diff] [blame] | 4055 | if (shsurf->focus_count > 0) { |
| 4056 | s = wl_array_add(&states, sizeof *s); |
| 4057 | *s = XDG_SURFACE_STATE_ACTIVATED; |
| 4058 | } |
Jasper St. Pierre | ab2c108 | 2014-04-10 10:41:46 -0700 | [diff] [blame] | 4059 | |
| 4060 | serial = wl_display_next_serial(shsurf->surface->compositor->wl_display); |
| 4061 | xdg_surface_send_configure(shsurf->resource, width, height, &states, serial); |
| 4062 | |
| 4063 | wl_array_release(&states); |
Rafael Antognolli | e2a3455 | 2013-12-03 15:35:45 -0200 | [diff] [blame] | 4064 | } |
| 4065 | |
| 4066 | static const struct weston_shell_client xdg_client = { |
| 4067 | xdg_send_configure |
| 4068 | }; |
| 4069 | |
| 4070 | static void |
Jasper St. Pierre | 084aa0b | 2015-02-13 14:02:00 +0800 | [diff] [blame] | 4071 | xdg_shell_destroy(struct wl_client *client, |
| 4072 | struct wl_resource *resource) |
| 4073 | { |
Jonas Ådahl | 49d77d2 | 2015-03-18 16:20:51 +0800 | [diff] [blame] | 4074 | struct shell_client *sc = wl_resource_get_user_data(resource); |
| 4075 | struct wl_resource *shsurf_resource; |
| 4076 | struct shell_surface *shsurf; |
| 4077 | |
| 4078 | wl_resource_for_each(shsurf_resource, &sc->surface_list) { |
| 4079 | shsurf = wl_resource_get_user_data(shsurf_resource); |
| 4080 | if (shsurf->owner_resource == resource) { |
| 4081 | wl_resource_post_error( |
| 4082 | resource, |
| 4083 | XDG_SHELL_ERROR_DEFUNCT_SURFACES, |
| 4084 | "not all child surface objects destroyed"); |
| 4085 | return; |
| 4086 | } |
| 4087 | } |
| 4088 | |
Jasper St. Pierre | 084aa0b | 2015-02-13 14:02:00 +0800 | [diff] [blame] | 4089 | wl_resource_destroy(resource); |
| 4090 | } |
| 4091 | |
| 4092 | static void |
Rafael Antognolli | e2a3455 | 2013-12-03 15:35:45 -0200 | [diff] [blame] | 4093 | xdg_use_unstable_version(struct wl_client *client, |
| 4094 | struct wl_resource *resource, |
| 4095 | int32_t version) |
| 4096 | { |
| 4097 | if (version > 1) { |
| 4098 | wl_resource_post_error(resource, |
| 4099 | 1, |
| 4100 | "xdg-shell:: version not implemented yet."); |
| 4101 | return; |
| 4102 | } |
| 4103 | } |
| 4104 | |
| 4105 | static struct shell_surface * |
Jason Ekstrand | 9e9512f | 2014-04-16 21:12:10 -0500 | [diff] [blame] | 4106 | create_xdg_surface(struct shell_client *owner, void *shell, |
| 4107 | struct weston_surface *surface, |
Rafael Antognolli | e2a3455 | 2013-12-03 15:35:45 -0200 | [diff] [blame] | 4108 | const struct weston_shell_client *client) |
| 4109 | { |
| 4110 | struct shell_surface *shsurf; |
Rafael Antognolli | e2a3455 | 2013-12-03 15:35:45 -0200 | [diff] [blame] | 4111 | |
Jason Ekstrand | 9e9512f | 2014-04-16 21:12:10 -0500 | [diff] [blame] | 4112 | shsurf = create_common_surface(owner, shell, surface, client); |
Pekka Paalanen | e972b27 | 2014-10-01 14:03:56 +0300 | [diff] [blame] | 4113 | if (!shsurf) |
| 4114 | return NULL; |
| 4115 | |
Pekka Paalanen | b502654 | 2014-11-12 15:09:24 +0200 | [diff] [blame] | 4116 | set_type(shsurf, SHELL_SURFACE_TOPLEVEL); |
Rafael Antognolli | e2a3455 | 2013-12-03 15:35:45 -0200 | [diff] [blame] | 4117 | |
| 4118 | return shsurf; |
| 4119 | } |
| 4120 | |
| 4121 | static void |
| 4122 | xdg_get_xdg_surface(struct wl_client *client, |
| 4123 | struct wl_resource *resource, |
| 4124 | uint32_t id, |
| 4125 | struct wl_resource *surface_resource) |
| 4126 | { |
| 4127 | struct weston_surface *surface = |
| 4128 | wl_resource_get_user_data(surface_resource); |
Kristian Høgsberg | 2bff94e | 2014-02-11 12:22:51 -0800 | [diff] [blame] | 4129 | struct shell_client *sc = wl_resource_get_user_data(resource); |
| 4130 | struct desktop_shell *shell = sc->shell; |
Rafael Antognolli | e2a3455 | 2013-12-03 15:35:45 -0200 | [diff] [blame] | 4131 | struct shell_surface *shsurf; |
| 4132 | |
Jonas Ådahl | bf48e21 | 2015-02-06 10:15:28 +0800 | [diff] [blame] | 4133 | shsurf = get_shell_surface(surface); |
| 4134 | if (shsurf && shell_surface_is_xdg_surface(shsurf)) { |
| 4135 | wl_resource_post_error(resource, XDG_SHELL_ERROR_ROLE, |
| 4136 | "This wl_surface is already an " |
| 4137 | "xdg_surface"); |
| 4138 | return; |
| 4139 | } |
| 4140 | |
Pekka Paalanen | 50b6747 | 2014-10-01 15:02:41 +0300 | [diff] [blame] | 4141 | if (weston_surface_set_role(surface, "xdg_surface", |
| 4142 | resource, XDG_SHELL_ERROR_ROLE) < 0) |
Rafael Antognolli | e2a3455 | 2013-12-03 15:35:45 -0200 | [diff] [blame] | 4143 | return; |
Rafael Antognolli | e2a3455 | 2013-12-03 15:35:45 -0200 | [diff] [blame] | 4144 | |
Jason Ekstrand | 9e9512f | 2014-04-16 21:12:10 -0500 | [diff] [blame] | 4145 | shsurf = create_xdg_surface(sc, shell, surface, &xdg_client); |
Rafael Antognolli | e2a3455 | 2013-12-03 15:35:45 -0200 | [diff] [blame] | 4146 | if (!shsurf) { |
Pekka Paalanen | 50b6747 | 2014-10-01 15:02:41 +0300 | [diff] [blame] | 4147 | wl_resource_post_no_memory(surface_resource); |
Rafael Antognolli | e2a3455 | 2013-12-03 15:35:45 -0200 | [diff] [blame] | 4148 | return; |
| 4149 | } |
| 4150 | |
| 4151 | shsurf->resource = |
| 4152 | wl_resource_create(client, |
| 4153 | &xdg_surface_interface, 1, id); |
| 4154 | wl_resource_set_implementation(shsurf->resource, |
| 4155 | &xdg_surface_implementation, |
| 4156 | shsurf, shell_destroy_shell_surface); |
Jonas Ådahl | 49d77d2 | 2015-03-18 16:20:51 +0800 | [diff] [blame] | 4157 | shsurf->owner_resource = resource; |
| 4158 | wl_list_insert(&sc->surface_list, |
| 4159 | wl_resource_get_link(shsurf->resource)); |
Rafael Antognolli | e2a3455 | 2013-12-03 15:35:45 -0200 | [diff] [blame] | 4160 | } |
| 4161 | |
| 4162 | static bool |
| 4163 | shell_surface_is_xdg_surface(struct shell_surface *shsurf) |
| 4164 | { |
Kristian Høgsberg | 0b7d995 | 2014-02-03 15:50:38 -0800 | [diff] [blame] | 4165 | return shsurf->resource && |
| 4166 | wl_resource_instance_of(shsurf->resource, |
| 4167 | &xdg_surface_interface, |
| 4168 | &xdg_surface_implementation); |
Rafael Antognolli | e2a3455 | 2013-12-03 15:35:45 -0200 | [diff] [blame] | 4169 | } |
| 4170 | |
| 4171 | /* xdg-popup implementation */ |
| 4172 | |
| 4173 | static void |
| 4174 | xdg_popup_destroy(struct wl_client *client, |
| 4175 | struct wl_resource *resource) |
| 4176 | { |
| 4177 | wl_resource_destroy(resource); |
| 4178 | } |
| 4179 | |
Rafael Antognolli | e2a3455 | 2013-12-03 15:35:45 -0200 | [diff] [blame] | 4180 | static const struct xdg_popup_interface xdg_popup_implementation = { |
| 4181 | xdg_popup_destroy, |
Rafael Antognolli | e2a3455 | 2013-12-03 15:35:45 -0200 | [diff] [blame] | 4182 | }; |
| 4183 | |
| 4184 | static void |
| 4185 | xdg_popup_send_configure(struct weston_surface *surface, |
Jasper St. Pierre | ac985be | 2014-04-28 11:19:28 -0400 | [diff] [blame] | 4186 | int32_t width, int32_t height) |
Rafael Antognolli | e2a3455 | 2013-12-03 15:35:45 -0200 | [diff] [blame] | 4187 | { |
| 4188 | } |
| 4189 | |
| 4190 | static const struct weston_shell_client xdg_popup_client = { |
| 4191 | xdg_popup_send_configure |
| 4192 | }; |
| 4193 | |
| 4194 | static struct shell_surface * |
Jason Ekstrand | 9e9512f | 2014-04-16 21:12:10 -0500 | [diff] [blame] | 4195 | create_xdg_popup(struct shell_client *owner, void *shell, |
| 4196 | struct weston_surface *surface, |
Rafael Antognolli | e2a3455 | 2013-12-03 15:35:45 -0200 | [diff] [blame] | 4197 | const struct weston_shell_client *client, |
| 4198 | struct weston_surface *parent, |
| 4199 | struct shell_seat *seat, |
| 4200 | uint32_t serial, |
| 4201 | int32_t x, int32_t y) |
| 4202 | { |
Jonas Ådahl | ee45a55 | 2015-03-18 16:37:47 +0800 | [diff] [blame] | 4203 | struct shell_surface *shsurf; |
Jonas Ådahl | 24185e2 | 2015-02-27 18:37:41 +0800 | [diff] [blame] | 4204 | |
Jason Ekstrand | 9e9512f | 2014-04-16 21:12:10 -0500 | [diff] [blame] | 4205 | shsurf = create_common_surface(owner, shell, surface, client); |
Pekka Paalanen | e972b27 | 2014-10-01 14:03:56 +0300 | [diff] [blame] | 4206 | if (!shsurf) |
| 4207 | return NULL; |
| 4208 | |
Pekka Paalanen | b502654 | 2014-11-12 15:09:24 +0200 | [diff] [blame] | 4209 | set_type(shsurf, SHELL_SURFACE_POPUP); |
Rafael Antognolli | e2a3455 | 2013-12-03 15:35:45 -0200 | [diff] [blame] | 4210 | shsurf->popup.shseat = seat; |
| 4211 | shsurf->popup.serial = serial; |
| 4212 | shsurf->popup.x = x; |
| 4213 | shsurf->popup.y = y; |
| 4214 | shell_surface_set_parent(shsurf, parent); |
| 4215 | |
| 4216 | return shsurf; |
| 4217 | } |
| 4218 | |
| 4219 | static void |
| 4220 | xdg_get_xdg_popup(struct wl_client *client, |
| 4221 | struct wl_resource *resource, |
| 4222 | uint32_t id, |
| 4223 | struct wl_resource *surface_resource, |
| 4224 | struct wl_resource *parent_resource, |
| 4225 | struct wl_resource *seat_resource, |
| 4226 | uint32_t serial, |
Jasper St. Pierre | 14f330c | 2015-02-13 14:01:57 +0800 | [diff] [blame] | 4227 | int32_t x, int32_t y) |
Rafael Antognolli | e2a3455 | 2013-12-03 15:35:45 -0200 | [diff] [blame] | 4228 | { |
| 4229 | struct weston_surface *surface = |
| 4230 | wl_resource_get_user_data(surface_resource); |
Kristian Høgsberg | 2bff94e | 2014-02-11 12:22:51 -0800 | [diff] [blame] | 4231 | struct shell_client *sc = wl_resource_get_user_data(resource); |
| 4232 | struct desktop_shell *shell = sc->shell; |
Rafael Antognolli | e2a3455 | 2013-12-03 15:35:45 -0200 | [diff] [blame] | 4233 | struct shell_surface *shsurf; |
Jonas Ådahl | ee45a55 | 2015-03-18 16:37:47 +0800 | [diff] [blame] | 4234 | struct shell_surface *parent_shsurf; |
Rafael Antognolli | e2a3455 | 2013-12-03 15:35:45 -0200 | [diff] [blame] | 4235 | struct weston_surface *parent; |
| 4236 | struct shell_seat *seat; |
| 4237 | |
Jonas Ådahl | bf48e21 | 2015-02-06 10:15:28 +0800 | [diff] [blame] | 4238 | shsurf = get_shell_surface(surface); |
| 4239 | if (shsurf && shell_surface_is_xdg_popup(shsurf)) { |
| 4240 | wl_resource_post_error(resource, XDG_SHELL_ERROR_ROLE, |
| 4241 | "This wl_surface is already an " |
| 4242 | "xdg_popup"); |
| 4243 | return; |
| 4244 | } |
| 4245 | |
Pekka Paalanen | 50b6747 | 2014-10-01 15:02:41 +0300 | [diff] [blame] | 4246 | if (weston_surface_set_role(surface, "xdg_popup", |
| 4247 | resource, XDG_SHELL_ERROR_ROLE) < 0) |
Rafael Antognolli | e2a3455 | 2013-12-03 15:35:45 -0200 | [diff] [blame] | 4248 | return; |
Rafael Antognolli | e2a3455 | 2013-12-03 15:35:45 -0200 | [diff] [blame] | 4249 | |
| 4250 | if (!parent_resource) { |
| 4251 | wl_resource_post_error(surface_resource, |
| 4252 | WL_DISPLAY_ERROR_INVALID_OBJECT, |
| 4253 | "xdg_shell::get_xdg_popup requires a parent shell surface"); |
Jasper St. Pierre | 666bc92 | 2014-08-07 16:43:13 -0400 | [diff] [blame] | 4254 | return; |
Rafael Antognolli | e2a3455 | 2013-12-03 15:35:45 -0200 | [diff] [blame] | 4255 | } |
| 4256 | |
| 4257 | parent = wl_resource_get_user_data(parent_resource); |
| 4258 | seat = get_shell_seat(wl_resource_get_user_data(seat_resource));; |
| 4259 | |
Jonas Ådahl | ee45a55 | 2015-03-18 16:37:47 +0800 | [diff] [blame] | 4260 | /* Verify that we are creating the top most popup when mapping, |
| 4261 | * as it's not until then we know whether it was mapped as most |
| 4262 | * top level or not. */ |
| 4263 | |
| 4264 | parent_shsurf = get_shell_surface(parent); |
| 4265 | if (!shell_surface_is_xdg_popup(parent_shsurf) && |
| 4266 | !shell_surface_is_xdg_surface(parent_shsurf)) { |
| 4267 | wl_resource_post_error(resource, |
| 4268 | XDG_SHELL_ERROR_INVALID_POPUP_PARENT, |
| 4269 | "xdg_popup parent was invalid"); |
| 4270 | return; |
| 4271 | } |
| 4272 | |
Jason Ekstrand | 9e9512f | 2014-04-16 21:12:10 -0500 | [diff] [blame] | 4273 | shsurf = create_xdg_popup(sc, shell, surface, &xdg_popup_client, |
Rafael Antognolli | e2a3455 | 2013-12-03 15:35:45 -0200 | [diff] [blame] | 4274 | parent, seat, serial, x, y); |
| 4275 | if (!shsurf) { |
Pekka Paalanen | 50b6747 | 2014-10-01 15:02:41 +0300 | [diff] [blame] | 4276 | wl_resource_post_no_memory(surface_resource); |
Rafael Antognolli | e2a3455 | 2013-12-03 15:35:45 -0200 | [diff] [blame] | 4277 | return; |
| 4278 | } |
| 4279 | |
| 4280 | shsurf->resource = |
| 4281 | wl_resource_create(client, |
| 4282 | &xdg_popup_interface, 1, id); |
| 4283 | wl_resource_set_implementation(shsurf->resource, |
| 4284 | &xdg_popup_implementation, |
| 4285 | shsurf, shell_destroy_shell_surface); |
Jonas Ådahl | 49d77d2 | 2015-03-18 16:20:51 +0800 | [diff] [blame] | 4286 | shsurf->owner_resource = resource; |
| 4287 | wl_list_insert(&sc->surface_list, |
| 4288 | wl_resource_get_link(shsurf->resource)); |
Rafael Antognolli | e2a3455 | 2013-12-03 15:35:45 -0200 | [diff] [blame] | 4289 | } |
| 4290 | |
Kristian Høgsberg | 2bff94e | 2014-02-11 12:22:51 -0800 | [diff] [blame] | 4291 | static void |
| 4292 | xdg_pong(struct wl_client *client, |
| 4293 | struct wl_resource *resource, uint32_t serial) |
| 4294 | { |
| 4295 | struct shell_client *sc = wl_resource_get_user_data(resource); |
Kristian Høgsberg | 2bff94e | 2014-02-11 12:22:51 -0800 | [diff] [blame] | 4296 | |
Kristian Høgsberg | dd62aba | 2014-02-12 09:56:19 -0800 | [diff] [blame] | 4297 | shell_client_pong(sc, serial); |
Kristian Høgsberg | 2bff94e | 2014-02-11 12:22:51 -0800 | [diff] [blame] | 4298 | } |
| 4299 | |
Rafael Antognolli | e2a3455 | 2013-12-03 15:35:45 -0200 | [diff] [blame] | 4300 | static bool |
| 4301 | shell_surface_is_xdg_popup(struct shell_surface *shsurf) |
| 4302 | { |
| 4303 | return wl_resource_instance_of(shsurf->resource, |
| 4304 | &xdg_popup_interface, |
| 4305 | &xdg_popup_implementation); |
| 4306 | } |
| 4307 | |
| 4308 | static const struct xdg_shell_interface xdg_implementation = { |
Jasper St. Pierre | 084aa0b | 2015-02-13 14:02:00 +0800 | [diff] [blame] | 4309 | xdg_shell_destroy, |
Rafael Antognolli | e2a3455 | 2013-12-03 15:35:45 -0200 | [diff] [blame] | 4310 | xdg_use_unstable_version, |
| 4311 | xdg_get_xdg_surface, |
Kristian Høgsberg | 2bff94e | 2014-02-11 12:22:51 -0800 | [diff] [blame] | 4312 | xdg_get_xdg_popup, |
| 4313 | xdg_pong |
Rafael Antognolli | e2a3455 | 2013-12-03 15:35:45 -0200 | [diff] [blame] | 4314 | }; |
| 4315 | |
| 4316 | static int |
| 4317 | xdg_shell_unversioned_dispatch(const void *implementation, |
| 4318 | void *_target, uint32_t opcode, |
| 4319 | const struct wl_message *message, |
| 4320 | union wl_argument *args) |
| 4321 | { |
| 4322 | struct wl_resource *resource = _target; |
Kristian Høgsberg | 2bff94e | 2014-02-11 12:22:51 -0800 | [diff] [blame] | 4323 | struct shell_client *sc = wl_resource_get_user_data(resource); |
Rafael Antognolli | e2a3455 | 2013-12-03 15:35:45 -0200 | [diff] [blame] | 4324 | |
Jasper St. Pierre | 084aa0b | 2015-02-13 14:02:00 +0800 | [diff] [blame] | 4325 | if (opcode != 1 /* XDG_SHELL_USE_UNSTABLE_VERSION */) { |
Rafael Antognolli | e2a3455 | 2013-12-03 15:35:45 -0200 | [diff] [blame] | 4326 | wl_resource_post_error(resource, |
| 4327 | WL_DISPLAY_ERROR_INVALID_OBJECT, |
| 4328 | "must call use_unstable_version first"); |
| 4329 | return 0; |
| 4330 | } |
| 4331 | |
Jasper St. Pierre | 5ba1e1d | 2015-02-13 14:02:02 +0800 | [diff] [blame] | 4332 | #define XDG_SERVER_VERSION 5 |
Rafael Antognolli | e2a3455 | 2013-12-03 15:35:45 -0200 | [diff] [blame] | 4333 | |
Kristian Høgsberg | 8d344a0 | 2013-12-08 22:27:11 -0800 | [diff] [blame] | 4334 | static_assert(XDG_SERVER_VERSION == XDG_SHELL_VERSION_CURRENT, |
| 4335 | "shell implementation doesn't match protocol version"); |
| 4336 | |
Rafael Antognolli | e2a3455 | 2013-12-03 15:35:45 -0200 | [diff] [blame] | 4337 | if (args[0].i != XDG_SERVER_VERSION) { |
| 4338 | wl_resource_post_error(resource, |
| 4339 | WL_DISPLAY_ERROR_INVALID_OBJECT, |
| 4340 | "incompatible version, server is %d " |
| 4341 | "client wants %d", |
| 4342 | XDG_SERVER_VERSION, args[0].i); |
| 4343 | return 0; |
| 4344 | } |
| 4345 | |
| 4346 | wl_resource_set_implementation(resource, &xdg_implementation, |
Kristian Høgsberg | 2bff94e | 2014-02-11 12:22:51 -0800 | [diff] [blame] | 4347 | sc, NULL); |
Rafael Antognolli | e2a3455 | 2013-12-03 15:35:45 -0200 | [diff] [blame] | 4348 | |
| 4349 | return 1; |
| 4350 | } |
| 4351 | |
| 4352 | /* end of xdg-shell implementation */ |
| 4353 | /***********************************/ |
| 4354 | |
Kristian Høgsberg | 0793756 | 2011-04-12 17:25:42 -0400 | [diff] [blame] | 4355 | static void |
Ander Conselvan de Oliveira | 859e885 | 2013-02-21 18:35:21 +0200 | [diff] [blame] | 4356 | shell_fade(struct desktop_shell *shell, enum fade_type type); |
| 4357 | |
Pekka Paalanen | 77346a6 | 2011-11-30 16:26:35 +0200 | [diff] [blame] | 4358 | static void |
Jason Ekstrand | 918f2dd | 2013-12-02 21:01:53 -0600 | [diff] [blame] | 4359 | configure_static_view(struct weston_view *ev, struct weston_layer *layer) |
Kristian Høgsberg | 962342c | 2012-06-26 16:29:50 -0400 | [diff] [blame] | 4360 | { |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 4361 | struct weston_view *v, *next; |
Kristian Høgsberg | 962342c | 2012-06-26 16:29:50 -0400 | [diff] [blame] | 4362 | |
Giulio Camuffo | 412e6a5 | 2014-07-09 22:12:56 +0300 | [diff] [blame] | 4363 | 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] | 4364 | if (v->output == ev->output && v != ev) { |
| 4365 | weston_view_unmap(v); |
| 4366 | v->surface->configure = NULL; |
Pekka Paalanen | 8274d90 | 2014-08-06 19:36:51 +0300 | [diff] [blame] | 4367 | weston_surface_set_label_func(v->surface, NULL); |
Kristian Høgsberg | 962342c | 2012-06-26 16:29:50 -0400 | [diff] [blame] | 4368 | } |
| 4369 | } |
| 4370 | |
Jason Ekstrand | 918f2dd | 2013-12-02 21:01:53 -0600 | [diff] [blame] | 4371 | weston_view_set_position(ev, ev->output->x, ev->output->y); |
Kristian Høgsberg | 962342c | 2012-06-26 16:29:50 -0400 | [diff] [blame] | 4372 | |
Giulio Camuffo | 412e6a5 | 2014-07-09 22:12:56 +0300 | [diff] [blame] | 4373 | if (wl_list_empty(&ev->layer_link.link)) { |
| 4374 | weston_layer_entry_insert(&layer->view_list, &ev->layer_link); |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 4375 | weston_compositor_schedule_repaint(ev->surface->compositor); |
Kristian Høgsberg | 962342c | 2012-06-26 16:29:50 -0400 | [diff] [blame] | 4376 | } |
| 4377 | } |
| 4378 | |
Pekka Paalanen | 8274d90 | 2014-08-06 19:36:51 +0300 | [diff] [blame] | 4379 | static int |
| 4380 | background_get_label(struct weston_surface *surface, char *buf, size_t len) |
| 4381 | { |
| 4382 | return snprintf(buf, len, "background for output %s", |
| 4383 | surface->output->name); |
| 4384 | } |
| 4385 | |
Kristian Høgsberg | 962342c | 2012-06-26 16:29:50 -0400 | [diff] [blame] | 4386 | static void |
Jason Ekstrand | 918f2dd | 2013-12-02 21:01:53 -0600 | [diff] [blame] | 4387 | 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] | 4388 | { |
Giulio Camuffo | 7fe01b1 | 2013-03-28 18:02:42 +0100 | [diff] [blame] | 4389 | struct desktop_shell *shell = es->configure_private; |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 4390 | struct weston_view *view; |
Kristian Høgsberg | af7b1ff | 2012-06-26 21:19:23 -0400 | [diff] [blame] | 4391 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 4392 | view = container_of(es->views.next, struct weston_view, surface_link); |
| 4393 | |
Jason Ekstrand | 918f2dd | 2013-12-02 21:01:53 -0600 | [diff] [blame] | 4394 | configure_static_view(view, &shell->background_layer); |
Kristian Høgsberg | af7b1ff | 2012-06-26 21:19:23 -0400 | [diff] [blame] | 4395 | } |
| 4396 | |
| 4397 | static void |
Kristian Høgsberg | 7584062 | 2011-09-06 13:48:16 -0400 | [diff] [blame] | 4398 | desktop_shell_set_background(struct wl_client *client, |
| 4399 | struct wl_resource *resource, |
Benjamin Franzke | d0f79ab | 2011-11-22 12:43:52 +0100 | [diff] [blame] | 4400 | struct wl_resource *output_resource, |
Kristian Høgsberg | 7584062 | 2011-09-06 13:48:16 -0400 | [diff] [blame] | 4401 | struct wl_resource *surface_resource) |
| 4402 | { |
Jason Ekstrand | 651f00e | 2013-06-14 10:07:54 -0500 | [diff] [blame] | 4403 | struct desktop_shell *shell = wl_resource_get_user_data(resource); |
Jason Ekstrand | 0f2ef7e | 2013-06-14 10:07:53 -0500 | [diff] [blame] | 4404 | struct weston_surface *surface = |
| 4405 | wl_resource_get_user_data(surface_resource); |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 4406 | struct weston_view *view, *next; |
Kristian Høgsberg | 7584062 | 2011-09-06 13:48:16 -0400 | [diff] [blame] | 4407 | |
Kristian Høgsberg | 962342c | 2012-06-26 16:29:50 -0400 | [diff] [blame] | 4408 | if (surface->configure) { |
| 4409 | wl_resource_post_error(surface_resource, |
| 4410 | WL_DISPLAY_ERROR_INVALID_OBJECT, |
| 4411 | "surface role already assigned"); |
| 4412 | return; |
| 4413 | } |
Benjamin Franzke | d0f79ab | 2011-11-22 12:43:52 +0100 | [diff] [blame] | 4414 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 4415 | wl_list_for_each_safe(view, next, &surface->views, surface_link) |
| 4416 | weston_view_destroy(view); |
| 4417 | view = weston_view_create(surface); |
| 4418 | |
Kristian Høgsberg | 962342c | 2012-06-26 16:29:50 -0400 | [diff] [blame] | 4419 | surface->configure = background_configure; |
Giulio Camuffo | 7fe01b1 | 2013-03-28 18:02:42 +0100 | [diff] [blame] | 4420 | surface->configure_private = shell; |
Pekka Paalanen | 8274d90 | 2014-08-06 19:36:51 +0300 | [diff] [blame] | 4421 | weston_surface_set_label_func(surface, background_get_label); |
Jason Ekstrand | a0d2dde | 2013-06-14 10:08:01 -0500 | [diff] [blame] | 4422 | surface->output = wl_resource_get_user_data(output_resource); |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 4423 | view->output = surface->output; |
Kristian Høgsberg | eae5de7 | 2012-04-11 22:42:15 -0400 | [diff] [blame] | 4424 | desktop_shell_send_configure(resource, 0, |
Kristian Høgsberg | 0b5cd0c | 2012-03-04 21:57:37 -0500 | [diff] [blame] | 4425 | surface_resource, |
Scott Moreau | 1bad5db | 2012-08-18 01:04:05 -0600 | [diff] [blame] | 4426 | surface->output->width, |
| 4427 | surface->output->height); |
Kristian Høgsberg | 7584062 | 2011-09-06 13:48:16 -0400 | [diff] [blame] | 4428 | } |
| 4429 | |
Pekka Paalanen | 8274d90 | 2014-08-06 19:36:51 +0300 | [diff] [blame] | 4430 | static int |
| 4431 | panel_get_label(struct weston_surface *surface, char *buf, size_t len) |
| 4432 | { |
| 4433 | return snprintf(buf, len, "panel for output %s", |
| 4434 | surface->output->name); |
| 4435 | } |
| 4436 | |
Kristian Høgsberg | 7584062 | 2011-09-06 13:48:16 -0400 | [diff] [blame] | 4437 | static void |
Jason Ekstrand | 918f2dd | 2013-12-02 21:01:53 -0600 | [diff] [blame] | 4438 | 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] | 4439 | { |
Giulio Camuffo | 7fe01b1 | 2013-03-28 18:02:42 +0100 | [diff] [blame] | 4440 | struct desktop_shell *shell = es->configure_private; |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 4441 | struct weston_view *view; |
Kristian Høgsberg | af7b1ff | 2012-06-26 21:19:23 -0400 | [diff] [blame] | 4442 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 4443 | view = container_of(es->views.next, struct weston_view, surface_link); |
| 4444 | |
Jason Ekstrand | 918f2dd | 2013-12-02 21:01:53 -0600 | [diff] [blame] | 4445 | configure_static_view(view, &shell->panel_layer); |
Kristian Høgsberg | af7b1ff | 2012-06-26 21:19:23 -0400 | [diff] [blame] | 4446 | } |
| 4447 | |
| 4448 | static void |
Kristian Høgsberg | 7584062 | 2011-09-06 13:48:16 -0400 | [diff] [blame] | 4449 | desktop_shell_set_panel(struct wl_client *client, |
| 4450 | struct wl_resource *resource, |
Benjamin Franzke | d0f79ab | 2011-11-22 12:43:52 +0100 | [diff] [blame] | 4451 | struct wl_resource *output_resource, |
Kristian Høgsberg | 7584062 | 2011-09-06 13:48:16 -0400 | [diff] [blame] | 4452 | struct wl_resource *surface_resource) |
| 4453 | { |
Jason Ekstrand | 651f00e | 2013-06-14 10:07:54 -0500 | [diff] [blame] | 4454 | struct desktop_shell *shell = wl_resource_get_user_data(resource); |
Jason Ekstrand | 0f2ef7e | 2013-06-14 10:07:53 -0500 | [diff] [blame] | 4455 | struct weston_surface *surface = |
| 4456 | wl_resource_get_user_data(surface_resource); |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 4457 | struct weston_view *view, *next; |
Kristian Høgsberg | 7584062 | 2011-09-06 13:48:16 -0400 | [diff] [blame] | 4458 | |
Kristian Høgsberg | af7b1ff | 2012-06-26 21:19:23 -0400 | [diff] [blame] | 4459 | if (surface->configure) { |
| 4460 | wl_resource_post_error(surface_resource, |
| 4461 | WL_DISPLAY_ERROR_INVALID_OBJECT, |
| 4462 | "surface role already assigned"); |
| 4463 | return; |
| 4464 | } |
Benjamin Franzke | d0f79ab | 2011-11-22 12:43:52 +0100 | [diff] [blame] | 4465 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 4466 | wl_list_for_each_safe(view, next, &surface->views, surface_link) |
| 4467 | weston_view_destroy(view); |
| 4468 | view = weston_view_create(surface); |
| 4469 | |
Kristian Høgsberg | af7b1ff | 2012-06-26 21:19:23 -0400 | [diff] [blame] | 4470 | surface->configure = panel_configure; |
Giulio Camuffo | 7fe01b1 | 2013-03-28 18:02:42 +0100 | [diff] [blame] | 4471 | surface->configure_private = shell; |
Pekka Paalanen | 8274d90 | 2014-08-06 19:36:51 +0300 | [diff] [blame] | 4472 | weston_surface_set_label_func(surface, panel_get_label); |
Jason Ekstrand | a0d2dde | 2013-06-14 10:08:01 -0500 | [diff] [blame] | 4473 | surface->output = wl_resource_get_user_data(output_resource); |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 4474 | view->output = surface->output; |
Kristian Høgsberg | eae5de7 | 2012-04-11 22:42:15 -0400 | [diff] [blame] | 4475 | desktop_shell_send_configure(resource, 0, |
Kristian Høgsberg | af7b1ff | 2012-06-26 21:19:23 -0400 | [diff] [blame] | 4476 | surface_resource, |
Scott Moreau | 1bad5db | 2012-08-18 01:04:05 -0600 | [diff] [blame] | 4477 | surface->output->width, |
| 4478 | surface->output->height); |
Kristian Høgsberg | 7584062 | 2011-09-06 13:48:16 -0400 | [diff] [blame] | 4479 | } |
| 4480 | |
Pekka Paalanen | 8274d90 | 2014-08-06 19:36:51 +0300 | [diff] [blame] | 4481 | static int |
| 4482 | lock_surface_get_label(struct weston_surface *surface, char *buf, size_t len) |
| 4483 | { |
| 4484 | return snprintf(buf, len, "lock window"); |
| 4485 | } |
| 4486 | |
Pekka Paalanen | 9ef3e01 | 2011-11-15 13:34:48 +0200 | [diff] [blame] | 4487 | static void |
Jason Ekstrand | 918f2dd | 2013-12-02 21:01:53 -0600 | [diff] [blame] | 4488 | 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] | 4489 | { |
Giulio Camuffo | 7fe01b1 | 2013-03-28 18:02:42 +0100 | [diff] [blame] | 4490 | struct desktop_shell *shell = surface->configure_private; |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 4491 | struct weston_view *view; |
| 4492 | |
| 4493 | view = container_of(surface->views.next, struct weston_view, surface_link); |
Kristian Høgsberg | 730c94d | 2012-06-26 21:44:35 -0400 | [diff] [blame] | 4494 | |
Jason Ekstrand | 918f2dd | 2013-12-02 21:01:53 -0600 | [diff] [blame] | 4495 | if (surface->width == 0) |
Giulio Camuffo | 184df50 | 2013-02-21 11:29:21 +0100 | [diff] [blame] | 4496 | return; |
| 4497 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 4498 | center_on_output(view, get_default_output(shell->compositor)); |
Kristian Høgsberg | 730c94d | 2012-06-26 21:44:35 -0400 | [diff] [blame] | 4499 | |
| 4500 | if (!weston_surface_is_mapped(surface)) { |
Giulio Camuffo | 412e6a5 | 2014-07-09 22:12:56 +0300 | [diff] [blame] | 4501 | weston_layer_entry_insert(&shell->lock_layer.view_list, |
| 4502 | &view->layer_link); |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 4503 | weston_view_update_transform(view); |
Ander Conselvan de Oliveira | 87524b6 | 2013-02-21 18:35:22 +0200 | [diff] [blame] | 4504 | shell_fade(shell, FADE_IN); |
Kristian Høgsberg | 730c94d | 2012-06-26 21:44:35 -0400 | [diff] [blame] | 4505 | } |
| 4506 | } |
| 4507 | |
| 4508 | static void |
Kristian Høgsberg | 27e3052 | 2012-04-11 23:18:23 -0400 | [diff] [blame] | 4509 | handle_lock_surface_destroy(struct wl_listener *listener, void *data) |
Kristian Høgsberg | 1ec0c31 | 2011-11-15 16:39:55 -0500 | [diff] [blame] | 4510 | { |
Tiago Vignatti | be14326 | 2012-04-16 17:31:41 +0300 | [diff] [blame] | 4511 | struct desktop_shell *shell = |
| 4512 | container_of(listener, struct desktop_shell, lock_surface_listener); |
Kristian Høgsberg | 1ec0c31 | 2011-11-15 16:39:55 -0500 | [diff] [blame] | 4513 | |
Martin Minarik | 6d11836 | 2012-06-07 18:01:59 +0200 | [diff] [blame] | 4514 | weston_log("lock surface gone\n"); |
Kristian Høgsberg | 1ec0c31 | 2011-11-15 16:39:55 -0500 | [diff] [blame] | 4515 | shell->lock_surface = NULL; |
| 4516 | } |
| 4517 | |
| 4518 | static void |
Pekka Paalanen | 9ef3e01 | 2011-11-15 13:34:48 +0200 | [diff] [blame] | 4519 | desktop_shell_set_lock_surface(struct wl_client *client, |
| 4520 | struct wl_resource *resource, |
| 4521 | struct wl_resource *surface_resource) |
| 4522 | { |
Jason Ekstrand | 651f00e | 2013-06-14 10:07:54 -0500 | [diff] [blame] | 4523 | struct desktop_shell *shell = wl_resource_get_user_data(resource); |
Jason Ekstrand | 0f2ef7e | 2013-06-14 10:07:53 -0500 | [diff] [blame] | 4524 | struct weston_surface *surface = |
| 4525 | wl_resource_get_user_data(surface_resource); |
Pekka Paalanen | 9826223 | 2011-12-01 10:42:22 +0200 | [diff] [blame] | 4526 | |
Pekka Paalanen | f0fc70d | 2011-11-15 13:34:54 +0200 | [diff] [blame] | 4527 | shell->prepare_event_sent = false; |
Kristian Høgsberg | af867cc | 2011-11-15 13:34:49 +0200 | [diff] [blame] | 4528 | |
Pekka Paalanen | f0fc70d | 2011-11-15 13:34:54 +0200 | [diff] [blame] | 4529 | if (!shell->locked) |
| 4530 | return; |
| 4531 | |
Pekka Paalanen | 9826223 | 2011-12-01 10:42:22 +0200 | [diff] [blame] | 4532 | shell->lock_surface = surface; |
Pekka Paalanen | f0fc70d | 2011-11-15 13:34:54 +0200 | [diff] [blame] | 4533 | |
Kristian Høgsberg | 27e3052 | 2012-04-11 23:18:23 -0400 | [diff] [blame] | 4534 | shell->lock_surface_listener.notify = handle_lock_surface_destroy; |
Jason Ekstrand | 651f00e | 2013-06-14 10:07:54 -0500 | [diff] [blame] | 4535 | wl_signal_add(&surface->destroy_signal, |
Kristian Høgsberg | 27e3052 | 2012-04-11 23:18:23 -0400 | [diff] [blame] | 4536 | &shell->lock_surface_listener); |
Pekka Paalanen | 57da4a8 | 2011-11-23 16:42:16 +0200 | [diff] [blame] | 4537 | |
Kristian Høgsberg | aa2ee8b | 2013-10-30 15:49:45 -0700 | [diff] [blame] | 4538 | weston_view_create(surface); |
Kristian Høgsberg | 730c94d | 2012-06-26 21:44:35 -0400 | [diff] [blame] | 4539 | surface->configure = lock_surface_configure; |
Giulio Camuffo | 7fe01b1 | 2013-03-28 18:02:42 +0100 | [diff] [blame] | 4540 | surface->configure_private = shell; |
Pekka Paalanen | 8274d90 | 2014-08-06 19:36:51 +0300 | [diff] [blame] | 4541 | weston_surface_set_label_func(surface, lock_surface_get_label); |
Pekka Paalanen | f0fc70d | 2011-11-15 13:34:54 +0200 | [diff] [blame] | 4542 | } |
| 4543 | |
| 4544 | static void |
Tiago Vignatti | be14326 | 2012-04-16 17:31:41 +0300 | [diff] [blame] | 4545 | resume_desktop(struct desktop_shell *shell) |
Pekka Paalanen | f0fc70d | 2011-11-15 13:34:54 +0200 | [diff] [blame] | 4546 | { |
Kristian Høgsberg | 4476aaf | 2012-06-25 14:03:13 -0400 | [diff] [blame] | 4547 | struct workspace *ws = get_current_workspace(shell); |
Pekka Paalanen | 77346a6 | 2011-11-30 16:26:35 +0200 | [diff] [blame] | 4548 | |
Kristian Høgsberg | 3be2ce9 | 2012-02-29 12:42:35 -0500 | [diff] [blame] | 4549 | wl_list_remove(&shell->lock_layer.link); |
Philipp Brüschweiler | 711fda8 | 2012-08-09 18:50:43 +0200 | [diff] [blame] | 4550 | if (shell->showing_input_panels) { |
Manuel Bachmann | 805d2f5 | 2014-03-05 12:21:34 +0100 | [diff] [blame] | 4551 | wl_list_insert(&shell->compositor->cursor_layer.link, |
Philipp Brüschweiler | 711fda8 | 2012-08-09 18:50:43 +0200 | [diff] [blame] | 4552 | &shell->input_panel_layer.link); |
| 4553 | wl_list_insert(&shell->input_panel_layer.link, |
Manuel Bachmann | 805d2f5 | 2014-03-05 12:21:34 +0100 | [diff] [blame] | 4554 | &shell->fullscreen_layer.link); |
Philipp Brüschweiler | 711fda8 | 2012-08-09 18:50:43 +0200 | [diff] [blame] | 4555 | } else { |
Manuel Bachmann | 805d2f5 | 2014-03-05 12:21:34 +0100 | [diff] [blame] | 4556 | wl_list_insert(&shell->compositor->cursor_layer.link, |
| 4557 | &shell->fullscreen_layer.link); |
Philipp Brüschweiler | 711fda8 | 2012-08-09 18:50:43 +0200 | [diff] [blame] | 4558 | } |
Manuel Bachmann | 805d2f5 | 2014-03-05 12:21:34 +0100 | [diff] [blame] | 4559 | wl_list_insert(&shell->fullscreen_layer.link, |
| 4560 | &shell->panel_layer.link); |
| 4561 | wl_list_insert(&shell->panel_layer.link, |
| 4562 | &ws->layer.link), |
Pekka Paalanen | f0fc70d | 2011-11-15 13:34:54 +0200 | [diff] [blame] | 4563 | |
Kristian Høgsberg | 2f5faff | 2012-07-31 16:36:34 -0400 | [diff] [blame] | 4564 | restore_focus_state(shell, get_current_workspace(shell)); |
Jonas Ådahl | 0476974 | 2012-06-13 00:01:24 +0200 | [diff] [blame] | 4565 | |
Pekka Paalanen | f0fc70d | 2011-11-15 13:34:54 +0200 | [diff] [blame] | 4566 | shell->locked = false; |
Ander Conselvan de Oliveira | 87524b6 | 2013-02-21 18:35:22 +0200 | [diff] [blame] | 4567 | shell_fade(shell, FADE_IN); |
Pekka Paalanen | fc6d91a | 2012-02-10 15:33:10 +0200 | [diff] [blame] | 4568 | weston_compositor_damage_all(shell->compositor); |
Pekka Paalanen | 9ef3e01 | 2011-11-15 13:34:48 +0200 | [diff] [blame] | 4569 | } |
| 4570 | |
| 4571 | static void |
| 4572 | desktop_shell_unlock(struct wl_client *client, |
| 4573 | struct wl_resource *resource) |
| 4574 | { |
Jason Ekstrand | 651f00e | 2013-06-14 10:07:54 -0500 | [diff] [blame] | 4575 | struct desktop_shell *shell = wl_resource_get_user_data(resource); |
Pekka Paalanen | 9ef3e01 | 2011-11-15 13:34:48 +0200 | [diff] [blame] | 4576 | |
Pekka Paalanen | 9ef3e01 | 2011-11-15 13:34:48 +0200 | [diff] [blame] | 4577 | shell->prepare_event_sent = false; |
Pekka Paalanen | f0fc70d | 2011-11-15 13:34:54 +0200 | [diff] [blame] | 4578 | |
| 4579 | if (shell->locked) |
| 4580 | resume_desktop(shell); |
Pekka Paalanen | 9ef3e01 | 2011-11-15 13:34:48 +0200 | [diff] [blame] | 4581 | } |
| 4582 | |
Kristian Høgsberg | d56bd90 | 2012-06-05 09:58:51 -0400 | [diff] [blame] | 4583 | static void |
Ander Conselvan de Oliveira | b9d2a0f | 2012-06-28 18:08:05 +0300 | [diff] [blame] | 4584 | desktop_shell_set_grab_surface(struct wl_client *client, |
Kristian Høgsberg | d56bd90 | 2012-06-05 09:58:51 -0400 | [diff] [blame] | 4585 | struct wl_resource *resource, |
| 4586 | struct wl_resource *surface_resource) |
| 4587 | { |
Jason Ekstrand | 651f00e | 2013-06-14 10:07:54 -0500 | [diff] [blame] | 4588 | struct desktop_shell *shell = wl_resource_get_user_data(resource); |
Kristian Høgsberg | d56bd90 | 2012-06-05 09:58:51 -0400 | [diff] [blame] | 4589 | |
Jason Ekstrand | 0f2ef7e | 2013-06-14 10:07:53 -0500 | [diff] [blame] | 4590 | shell->grab_surface = wl_resource_get_user_data(surface_resource); |
Kristian Høgsberg | 48588f8 | 2013-10-24 15:51:35 -0700 | [diff] [blame] | 4591 | weston_view_create(shell->grab_surface); |
Kristian Høgsberg | d56bd90 | 2012-06-05 09:58:51 -0400 | [diff] [blame] | 4592 | } |
| 4593 | |
Pekka Paalanen | 79346ab | 2013-05-22 18:03:09 +0300 | [diff] [blame] | 4594 | static void |
| 4595 | desktop_shell_desktop_ready(struct wl_client *client, |
| 4596 | struct wl_resource *resource) |
| 4597 | { |
Jason Ekstrand | 651f00e | 2013-06-14 10:07:54 -0500 | [diff] [blame] | 4598 | struct desktop_shell *shell = wl_resource_get_user_data(resource); |
Pekka Paalanen | 79346ab | 2013-05-22 18:03:09 +0300 | [diff] [blame] | 4599 | |
| 4600 | shell_fade_startup(shell); |
| 4601 | } |
| 4602 | |
Jonny Lamb | 765760d | 2014-08-20 15:53:19 +0200 | [diff] [blame] | 4603 | static void |
| 4604 | desktop_shell_set_panel_position(struct wl_client *client, |
| 4605 | struct wl_resource *resource, |
| 4606 | uint32_t position) |
| 4607 | { |
| 4608 | struct desktop_shell *shell = wl_resource_get_user_data(resource); |
| 4609 | |
| 4610 | if (position != DESKTOP_SHELL_PANEL_POSITION_TOP && |
| 4611 | position != DESKTOP_SHELL_PANEL_POSITION_BOTTOM && |
| 4612 | position != DESKTOP_SHELL_PANEL_POSITION_LEFT && |
| 4613 | position != DESKTOP_SHELL_PANEL_POSITION_RIGHT) { |
| 4614 | wl_resource_post_error(resource, |
| 4615 | DESKTOP_SHELL_ERROR_INVALID_ARGUMENT, |
| 4616 | "bad position argument"); |
| 4617 | return; |
| 4618 | } |
| 4619 | |
| 4620 | shell->panel_position = position; |
| 4621 | } |
| 4622 | |
Kristian Høgsberg | 7584062 | 2011-09-06 13:48:16 -0400 | [diff] [blame] | 4623 | static const struct desktop_shell_interface desktop_shell_implementation = { |
| 4624 | desktop_shell_set_background, |
Pekka Paalanen | 9ef3e01 | 2011-11-15 13:34:48 +0200 | [diff] [blame] | 4625 | desktop_shell_set_panel, |
| 4626 | desktop_shell_set_lock_surface, |
Kristian Høgsberg | d56bd90 | 2012-06-05 09:58:51 -0400 | [diff] [blame] | 4627 | desktop_shell_unlock, |
Pekka Paalanen | 79346ab | 2013-05-22 18:03:09 +0300 | [diff] [blame] | 4628 | desktop_shell_set_grab_surface, |
Jonny Lamb | 765760d | 2014-08-20 15:53:19 +0200 | [diff] [blame] | 4629 | desktop_shell_desktop_ready, |
| 4630 | desktop_shell_set_panel_position |
Kristian Høgsberg | 7584062 | 2011-09-06 13:48:16 -0400 | [diff] [blame] | 4631 | }; |
| 4632 | |
Pekka Paalanen | 92a0dc4 | 2011-11-28 15:34:13 +0200 | [diff] [blame] | 4633 | static enum shell_surface_type |
Kristian Høgsberg | 8334bc1 | 2012-01-03 10:29:47 -0500 | [diff] [blame] | 4634 | get_shell_surface_type(struct weston_surface *surface) |
Pekka Paalanen | 92a0dc4 | 2011-11-28 15:34:13 +0200 | [diff] [blame] | 4635 | { |
| 4636 | struct shell_surface *shsurf; |
| 4637 | |
| 4638 | shsurf = get_shell_surface(surface); |
| 4639 | if (!shsurf) |
Pekka Paalanen | 9826223 | 2011-12-01 10:42:22 +0200 | [diff] [blame] | 4640 | return SHELL_SURFACE_NONE; |
Pekka Paalanen | 92a0dc4 | 2011-11-28 15:34:13 +0200 | [diff] [blame] | 4641 | return shsurf->type; |
| 4642 | } |
| 4643 | |
Kristian Høgsberg | 7584062 | 2011-09-06 13:48:16 -0400 | [diff] [blame] | 4644 | static void |
Derek Foreman | 8ae2db5 | 2015-07-15 13:00:36 -0500 | [diff] [blame] | 4645 | move_binding(struct weston_pointer *pointer, uint32_t time, |
| 4646 | uint32_t button, void *data) |
Kristian Høgsberg | 0793756 | 2011-04-12 17:25:42 -0400 | [diff] [blame] | 4647 | { |
Rafal Mielniczuk | b2917a2 | 2014-01-05 20:04:59 +0100 | [diff] [blame] | 4648 | struct weston_surface *focus; |
Pekka Paalanen | 01388e2 | 2013-04-25 13:57:44 +0300 | [diff] [blame] | 4649 | struct weston_surface *surface; |
Kristian Høgsberg | 938b8fa | 2012-05-18 13:46:27 -0400 | [diff] [blame] | 4650 | struct shell_surface *shsurf; |
Kristian Høgsberg | d2abb83 | 2011-11-23 10:52:40 -0500 | [diff] [blame] | 4651 | |
Derek Foreman | 8ae2db5 | 2015-07-15 13:00:36 -0500 | [diff] [blame] | 4652 | if (pointer->focus == NULL) |
Rafal Mielniczuk | b2917a2 | 2014-01-05 20:04:59 +0100 | [diff] [blame] | 4653 | return; |
| 4654 | |
Derek Foreman | 8ae2db5 | 2015-07-15 13:00:36 -0500 | [diff] [blame] | 4655 | focus = pointer->focus->surface; |
Rafal Mielniczuk | b2917a2 | 2014-01-05 20:04:59 +0100 | [diff] [blame] | 4656 | |
Pekka Paalanen | 01388e2 | 2013-04-25 13:57:44 +0300 | [diff] [blame] | 4657 | surface = weston_surface_get_main_surface(focus); |
Benjamin Franzke | d0f79ab | 2011-11-22 12:43:52 +0100 | [diff] [blame] | 4658 | if (surface == NULL) |
| 4659 | return; |
Kristian Høgsberg | 0793756 | 2011-04-12 17:25:42 -0400 | [diff] [blame] | 4660 | |
Kristian Høgsberg | 938b8fa | 2012-05-18 13:46:27 -0400 | [diff] [blame] | 4661 | shsurf = get_shell_surface(surface); |
Rafael Antognolli | 03b1659 | 2013-12-03 15:35:42 -0200 | [diff] [blame] | 4662 | if (shsurf == NULL || shsurf->state.fullscreen || |
| 4663 | shsurf->state.maximized) |
Kristian Høgsberg | 938b8fa | 2012-05-18 13:46:27 -0400 | [diff] [blame] | 4664 | return; |
| 4665 | |
Derek Foreman | 794fa0e | 2015-07-15 13:00:38 -0500 | [diff] [blame] | 4666 | surface_move(shsurf, pointer, false); |
Kristian Høgsberg | 0793756 | 2011-04-12 17:25:42 -0400 | [diff] [blame] | 4667 | } |
| 4668 | |
| 4669 | static void |
Derek Foreman | 8ae2db5 | 2015-07-15 13:00:36 -0500 | [diff] [blame] | 4670 | maximize_binding(struct weston_keyboard *keyboard, uint32_t time, |
| 4671 | uint32_t button, void *data) |
Rafael Antognolli | ea997ac | 2013-12-03 15:35:48 -0200 | [diff] [blame] | 4672 | { |
Derek Foreman | 8ae2db5 | 2015-07-15 13:00:36 -0500 | [diff] [blame] | 4673 | struct weston_surface *focus = keyboard->focus; |
Rafael Antognolli | ea997ac | 2013-12-03 15:35:48 -0200 | [diff] [blame] | 4674 | struct weston_surface *surface; |
| 4675 | struct shell_surface *shsurf; |
| 4676 | |
| 4677 | surface = weston_surface_get_main_surface(focus); |
| 4678 | if (surface == NULL) |
| 4679 | return; |
| 4680 | |
| 4681 | shsurf = get_shell_surface(surface); |
| 4682 | if (shsurf == NULL) |
| 4683 | return; |
| 4684 | |
| 4685 | if (!shell_surface_is_xdg_surface(shsurf)) |
| 4686 | return; |
| 4687 | |
Jasper St. Pierre | ab2c108 | 2014-04-10 10:41:46 -0700 | [diff] [blame] | 4688 | shsurf->state_requested = true; |
| 4689 | shsurf->requested_state.maximized = !shsurf->state.maximized; |
Jasper St. Pierre | 9aa8ce6 | 2014-04-11 16:18:54 -0700 | [diff] [blame] | 4690 | send_configure_for_surface(shsurf); |
Rafael Antognolli | ea997ac | 2013-12-03 15:35:48 -0200 | [diff] [blame] | 4691 | } |
| 4692 | |
| 4693 | static void |
Derek Foreman | 8ae2db5 | 2015-07-15 13:00:36 -0500 | [diff] [blame] | 4694 | fullscreen_binding(struct weston_keyboard *keyboard, uint32_t time, |
| 4695 | uint32_t button, void *data) |
Rafael Antognolli | ea997ac | 2013-12-03 15:35:48 -0200 | [diff] [blame] | 4696 | { |
Derek Foreman | 8ae2db5 | 2015-07-15 13:00:36 -0500 | [diff] [blame] | 4697 | struct weston_surface *focus = keyboard->focus; |
Rafael Antognolli | ea997ac | 2013-12-03 15:35:48 -0200 | [diff] [blame] | 4698 | struct weston_surface *surface; |
| 4699 | struct shell_surface *shsurf; |
| 4700 | |
| 4701 | surface = weston_surface_get_main_surface(focus); |
| 4702 | if (surface == NULL) |
| 4703 | return; |
| 4704 | |
| 4705 | shsurf = get_shell_surface(surface); |
| 4706 | if (shsurf == NULL) |
| 4707 | return; |
| 4708 | |
| 4709 | if (!shell_surface_is_xdg_surface(shsurf)) |
| 4710 | return; |
| 4711 | |
Jasper St. Pierre | ab2c108 | 2014-04-10 10:41:46 -0700 | [diff] [blame] | 4712 | shsurf->state_requested = true; |
| 4713 | shsurf->requested_state.fullscreen = !shsurf->state.fullscreen; |
Boyan Ding | 32abdbb | 2014-06-26 10:19:32 +0800 | [diff] [blame] | 4714 | shsurf->fullscreen_output = shsurf->output; |
Jasper St. Pierre | 9aa8ce6 | 2014-04-11 16:18:54 -0700 | [diff] [blame] | 4715 | send_configure_for_surface(shsurf); |
Rafael Antognolli | ea997ac | 2013-12-03 15:35:48 -0200 | [diff] [blame] | 4716 | } |
| 4717 | |
| 4718 | static void |
Derek Foreman | 8ae2db5 | 2015-07-15 13:00:36 -0500 | [diff] [blame] | 4719 | touch_move_binding(struct weston_touch *touch, uint32_t time, void *data) |
Neil Roberts | aba0f25 | 2013-10-03 16:43:05 +0100 | [diff] [blame] | 4720 | { |
Derek Foreman | 362656b | 2014-09-04 10:23:05 -0500 | [diff] [blame] | 4721 | struct weston_surface *focus; |
Neil Roberts | aba0f25 | 2013-10-03 16:43:05 +0100 | [diff] [blame] | 4722 | struct weston_surface *surface; |
| 4723 | struct shell_surface *shsurf; |
| 4724 | |
Derek Foreman | 8ae2db5 | 2015-07-15 13:00:36 -0500 | [diff] [blame] | 4725 | if (touch->focus == NULL) |
Derek Foreman | 362656b | 2014-09-04 10:23:05 -0500 | [diff] [blame] | 4726 | return; |
| 4727 | |
Derek Foreman | 8ae2db5 | 2015-07-15 13:00:36 -0500 | [diff] [blame] | 4728 | focus = touch->focus->surface; |
Neil Roberts | aba0f25 | 2013-10-03 16:43:05 +0100 | [diff] [blame] | 4729 | surface = weston_surface_get_main_surface(focus); |
| 4730 | if (surface == NULL) |
| 4731 | return; |
| 4732 | |
| 4733 | shsurf = get_shell_surface(surface); |
Rafael Antognolli | 03b1659 | 2013-12-03 15:35:42 -0200 | [diff] [blame] | 4734 | if (shsurf == NULL || shsurf->state.fullscreen || |
| 4735 | shsurf->state.maximized) |
Neil Roberts | aba0f25 | 2013-10-03 16:43:05 +0100 | [diff] [blame] | 4736 | return; |
| 4737 | |
Derek Foreman | b7674ae | 2015-07-15 13:00:37 -0500 | [diff] [blame] | 4738 | surface_touch_move(shsurf, touch); |
Neil Roberts | aba0f25 | 2013-10-03 16:43:05 +0100 | [diff] [blame] | 4739 | } |
| 4740 | |
| 4741 | static void |
Derek Foreman | 8ae2db5 | 2015-07-15 13:00:36 -0500 | [diff] [blame] | 4742 | resize_binding(struct weston_pointer *pointer, uint32_t time, |
| 4743 | uint32_t button, void *data) |
Kristian Høgsberg | 0793756 | 2011-04-12 17:25:42 -0400 | [diff] [blame] | 4744 | { |
Rafal Mielniczuk | b2917a2 | 2014-01-05 20:04:59 +0100 | [diff] [blame] | 4745 | struct weston_surface *focus; |
Pekka Paalanen | 01388e2 | 2013-04-25 13:57:44 +0300 | [diff] [blame] | 4746 | struct weston_surface *surface; |
Kristian Høgsberg | 0793756 | 2011-04-12 17:25:42 -0400 | [diff] [blame] | 4747 | uint32_t edges = 0; |
| 4748 | int32_t x, y; |
Pekka Paalanen | 9d1613e | 2011-11-25 12:09:16 +0200 | [diff] [blame] | 4749 | struct shell_surface *shsurf; |
Kristian Høgsberg | d2abb83 | 2011-11-23 10:52:40 -0500 | [diff] [blame] | 4750 | |
Derek Foreman | 8ae2db5 | 2015-07-15 13:00:36 -0500 | [diff] [blame] | 4751 | if (pointer->focus == NULL) |
Rafal Mielniczuk | b2917a2 | 2014-01-05 20:04:59 +0100 | [diff] [blame] | 4752 | return; |
| 4753 | |
Derek Foreman | 8ae2db5 | 2015-07-15 13:00:36 -0500 | [diff] [blame] | 4754 | focus = pointer->focus->surface; |
Rafal Mielniczuk | b2917a2 | 2014-01-05 20:04:59 +0100 | [diff] [blame] | 4755 | |
Pekka Paalanen | 01388e2 | 2013-04-25 13:57:44 +0300 | [diff] [blame] | 4756 | surface = weston_surface_get_main_surface(focus); |
Benjamin Franzke | d0f79ab | 2011-11-22 12:43:52 +0100 | [diff] [blame] | 4757 | if (surface == NULL) |
| 4758 | return; |
Pekka Paalanen | 92a0dc4 | 2011-11-28 15:34:13 +0200 | [diff] [blame] | 4759 | |
Pekka Paalanen | 9d1613e | 2011-11-25 12:09:16 +0200 | [diff] [blame] | 4760 | shsurf = get_shell_surface(surface); |
Rafael Antognolli | 03b1659 | 2013-12-03 15:35:42 -0200 | [diff] [blame] | 4761 | if (shsurf == NULL || shsurf->state.fullscreen || |
| 4762 | shsurf->state.maximized) |
Pekka Paalanen | 92a0dc4 | 2011-11-28 15:34:13 +0200 | [diff] [blame] | 4763 | return; |
| 4764 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 4765 | weston_view_from_global(shsurf->view, |
Derek Foreman | 8ae2db5 | 2015-07-15 13:00:36 -0500 | [diff] [blame] | 4766 | wl_fixed_to_int(pointer->grab_x), |
| 4767 | wl_fixed_to_int(pointer->grab_y), |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 4768 | &x, &y); |
Kristian Høgsberg | 0793756 | 2011-04-12 17:25:42 -0400 | [diff] [blame] | 4769 | |
Jason Ekstrand | 918f2dd | 2013-12-02 21:01:53 -0600 | [diff] [blame] | 4770 | if (x < shsurf->surface->width / 3) |
Pekka Paalanen | 9d1613e | 2011-11-25 12:09:16 +0200 | [diff] [blame] | 4771 | edges |= WL_SHELL_SURFACE_RESIZE_LEFT; |
Jason Ekstrand | 918f2dd | 2013-12-02 21:01:53 -0600 | [diff] [blame] | 4772 | else if (x < 2 * shsurf->surface->width / 3) |
Kristian Høgsberg | 0793756 | 2011-04-12 17:25:42 -0400 | [diff] [blame] | 4773 | edges |= 0; |
| 4774 | else |
Pekka Paalanen | 9d1613e | 2011-11-25 12:09:16 +0200 | [diff] [blame] | 4775 | edges |= WL_SHELL_SURFACE_RESIZE_RIGHT; |
Kristian Høgsberg | 0793756 | 2011-04-12 17:25:42 -0400 | [diff] [blame] | 4776 | |
Jason Ekstrand | 918f2dd | 2013-12-02 21:01:53 -0600 | [diff] [blame] | 4777 | if (y < shsurf->surface->height / 3) |
Pekka Paalanen | 9d1613e | 2011-11-25 12:09:16 +0200 | [diff] [blame] | 4778 | edges |= WL_SHELL_SURFACE_RESIZE_TOP; |
Jason Ekstrand | 918f2dd | 2013-12-02 21:01:53 -0600 | [diff] [blame] | 4779 | else if (y < 2 * shsurf->surface->height / 3) |
Kristian Høgsberg | 0793756 | 2011-04-12 17:25:42 -0400 | [diff] [blame] | 4780 | edges |= 0; |
| 4781 | else |
Pekka Paalanen | 9d1613e | 2011-11-25 12:09:16 +0200 | [diff] [blame] | 4782 | edges |= WL_SHELL_SURFACE_RESIZE_BOTTOM; |
Kristian Høgsberg | 0793756 | 2011-04-12 17:25:42 -0400 | [diff] [blame] | 4783 | |
Derek Foreman | 8fbebbd | 2015-07-15 13:00:40 -0500 | [diff] [blame] | 4784 | surface_resize(shsurf, pointer, edges); |
Kristian Høgsberg | 02ec0a5 | 2011-04-23 13:04:11 -0400 | [diff] [blame] | 4785 | } |
| 4786 | |
| 4787 | static void |
Derek Foreman | 8ae2db5 | 2015-07-15 13:00:36 -0500 | [diff] [blame] | 4788 | surface_opacity_binding(struct weston_pointer *pointer, uint32_t time, |
| 4789 | uint32_t axis, wl_fixed_t value, void *data) |
Scott Moreau | a3aa9c9 | 2012-03-22 11:01:03 -0600 | [diff] [blame] | 4790 | { |
Jonas Ådahl | b0b87ba | 2012-09-27 18:40:42 +0200 | [diff] [blame] | 4791 | float step = 0.005; |
Scott Moreau | a3aa9c9 | 2012-03-22 11:01:03 -0600 | [diff] [blame] | 4792 | struct shell_surface *shsurf; |
Derek Foreman | 8ae2db5 | 2015-07-15 13:00:36 -0500 | [diff] [blame] | 4793 | struct weston_surface *focus = pointer->focus->surface; |
Pekka Paalanen | 01388e2 | 2013-04-25 13:57:44 +0300 | [diff] [blame] | 4794 | struct weston_surface *surface; |
Scott Moreau | a3aa9c9 | 2012-03-22 11:01:03 -0600 | [diff] [blame] | 4795 | |
Pekka Paalanen | 01388e2 | 2013-04-25 13:57:44 +0300 | [diff] [blame] | 4796 | /* XXX: broken for windows containing sub-surfaces */ |
| 4797 | surface = weston_surface_get_main_surface(focus); |
Scott Moreau | a3aa9c9 | 2012-03-22 11:01:03 -0600 | [diff] [blame] | 4798 | if (surface == NULL) |
| 4799 | return; |
| 4800 | |
| 4801 | shsurf = get_shell_surface(surface); |
| 4802 | if (!shsurf) |
| 4803 | return; |
| 4804 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 4805 | shsurf->view->alpha -= wl_fixed_to_double(value) * step; |
Scott Moreau | a3aa9c9 | 2012-03-22 11:01:03 -0600 | [diff] [blame] | 4806 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 4807 | if (shsurf->view->alpha > 1.0) |
| 4808 | shsurf->view->alpha = 1.0; |
| 4809 | if (shsurf->view->alpha < step) |
| 4810 | shsurf->view->alpha = step; |
Scott Moreau | a3aa9c9 | 2012-03-22 11:01:03 -0600 | [diff] [blame] | 4811 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 4812 | weston_view_geometry_dirty(shsurf->view); |
Scott Moreau | a3aa9c9 | 2012-03-22 11:01:03 -0600 | [diff] [blame] | 4813 | weston_surface_damage(surface); |
| 4814 | } |
| 4815 | |
| 4816 | static void |
Kristian Høgsberg | e314875 | 2013-05-06 23:19:49 -0400 | [diff] [blame] | 4817 | 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] | 4818 | wl_fixed_t value) |
Scott Moreau | ccbf29d | 2012-02-22 14:21:41 -0700 | [diff] [blame] | 4819 | { |
Derek Foreman | 8aeeac8 | 2015-01-30 13:24:36 -0600 | [diff] [blame] | 4820 | struct weston_compositor *compositor = seat->compositor; |
Derek Foreman | 1281a36 | 2015-07-31 16:55:32 -0500 | [diff] [blame] | 4821 | struct weston_pointer *pointer = weston_seat_get_pointer(seat); |
Scott Moreau | ccbf29d | 2012-02-22 14:21:41 -0700 | [diff] [blame] | 4822 | struct weston_output *output; |
Scott Moreau | e660398 | 2012-06-11 13:07:51 -0600 | [diff] [blame] | 4823 | float increment; |
Scott Moreau | ccbf29d | 2012-02-22 14:21:41 -0700 | [diff] [blame] | 4824 | |
Derek Foreman | 1281a36 | 2015-07-31 16:55:32 -0500 | [diff] [blame] | 4825 | if (!pointer) { |
Derek Foreman | 7ef3bed | 2015-01-06 14:28:13 -0600 | [diff] [blame] | 4826 | weston_log("Zoom hotkey pressed but seat '%s' contains no pointer.\n", seat->seat_name); |
| 4827 | return; |
| 4828 | } |
| 4829 | |
Scott Moreau | ccbf29d | 2012-02-22 14:21:41 -0700 | [diff] [blame] | 4830 | wl_list_for_each(output, &compositor->output_list, link) { |
| 4831 | if (pixman_region32_contains_point(&output->region, |
Derek Foreman | 1281a36 | 2015-07-31 16:55:32 -0500 | [diff] [blame] | 4832 | wl_fixed_to_double(pointer->x), |
| 4833 | wl_fixed_to_double(pointer->y), |
Daniel Stone | 103db7f | 2012-05-08 17:17:55 +0100 | [diff] [blame] | 4834 | NULL)) { |
Daniel Stone | 325fc2d | 2012-05-30 16:31:58 +0100 | [diff] [blame] | 4835 | if (key == KEY_PAGEUP) |
Kristian Høgsberg | 9b68af0 | 2012-05-22 12:55:18 -0400 | [diff] [blame] | 4836 | increment = output->zoom.increment; |
Daniel Stone | 325fc2d | 2012-05-30 16:31:58 +0100 | [diff] [blame] | 4837 | else if (key == KEY_PAGEDOWN) |
Kristian Høgsberg | 9b68af0 | 2012-05-22 12:55:18 -0400 | [diff] [blame] | 4838 | increment = -output->zoom.increment; |
| 4839 | else if (axis == WL_POINTER_AXIS_VERTICAL_SCROLL) |
Jonas Ådahl | b0b87ba | 2012-09-27 18:40:42 +0200 | [diff] [blame] | 4840 | /* For every pixel zoom 20th of a step */ |
Daniel Stone | 0c1e46e | 2012-05-30 16:31:59 +0100 | [diff] [blame] | 4841 | increment = output->zoom.increment * |
Jonas Ådahl | b0b87ba | 2012-09-27 18:40:42 +0200 | [diff] [blame] | 4842 | -wl_fixed_to_double(value) / 20.0; |
Kristian Høgsberg | 9b68af0 | 2012-05-22 12:55:18 -0400 | [diff] [blame] | 4843 | else |
| 4844 | increment = 0; |
| 4845 | |
Kristian Høgsberg | 9b68af0 | 2012-05-22 12:55:18 -0400 | [diff] [blame] | 4846 | output->zoom.level += increment; |
Scott Moreau | c6d7f60 | 2012-02-23 22:28:37 -0700 | [diff] [blame] | 4847 | |
Scott Moreau | e660398 | 2012-06-11 13:07:51 -0600 | [diff] [blame] | 4848 | if (output->zoom.level < 0.0) |
Scott Moreau | 850ca42 | 2012-05-21 15:21:25 -0600 | [diff] [blame] | 4849 | output->zoom.level = 0.0; |
Scott Moreau | e660398 | 2012-06-11 13:07:51 -0600 | [diff] [blame] | 4850 | else if (output->zoom.level > output->zoom.max_level) |
| 4851 | output->zoom.level = output->zoom.max_level; |
Derek Foreman | 25bd8a7 | 2015-07-23 14:55:13 -0500 | [diff] [blame] | 4852 | |
| 4853 | if (!output->zoom.active) { |
| 4854 | if (output->zoom.level <= 0.0) |
| 4855 | continue; |
Derek Foreman | 22276a5 | 2015-07-23 14:55:15 -0500 | [diff] [blame] | 4856 | weston_output_activate_zoom(output, seat); |
Kristian Høgsberg | 79af73e | 2012-08-03 15:45:23 -0400 | [diff] [blame] | 4857 | } |
Scott Moreau | ccbf29d | 2012-02-22 14:21:41 -0700 | [diff] [blame] | 4858 | |
Scott Moreau | e660398 | 2012-06-11 13:07:51 -0600 | [diff] [blame] | 4859 | output->zoom.spring_z.target = output->zoom.level; |
Scott Moreau | ccbf29d | 2012-02-22 14:21:41 -0700 | [diff] [blame] | 4860 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 4861 | weston_output_update_zoom(output); |
Scott Moreau | ccbf29d | 2012-02-22 14:21:41 -0700 | [diff] [blame] | 4862 | } |
| 4863 | } |
| 4864 | } |
| 4865 | |
Scott Moreau | ccbf29d | 2012-02-22 14:21:41 -0700 | [diff] [blame] | 4866 | static void |
Derek Foreman | 8ae2db5 | 2015-07-15 13:00:36 -0500 | [diff] [blame] | 4867 | zoom_axis_binding(struct weston_pointer *pointer, uint32_t time, |
| 4868 | uint32_t axis, wl_fixed_t value, void *data) |
Daniel Stone | 325fc2d | 2012-05-30 16:31:58 +0100 | [diff] [blame] | 4869 | { |
Derek Foreman | 8ae2db5 | 2015-07-15 13:00:36 -0500 | [diff] [blame] | 4870 | do_zoom(pointer->seat, time, 0, axis, value); |
Daniel Stone | 325fc2d | 2012-05-30 16:31:58 +0100 | [diff] [blame] | 4871 | } |
| 4872 | |
| 4873 | static void |
Derek Foreman | 8ae2db5 | 2015-07-15 13:00:36 -0500 | [diff] [blame] | 4874 | zoom_key_binding(struct weston_keyboard *keyboard, uint32_t time, |
| 4875 | uint32_t key, void *data) |
Daniel Stone | 325fc2d | 2012-05-30 16:31:58 +0100 | [diff] [blame] | 4876 | { |
Derek Foreman | 8ae2db5 | 2015-07-15 13:00:36 -0500 | [diff] [blame] | 4877 | do_zoom(keyboard->seat, time, key, 0, 0); |
Daniel Stone | 325fc2d | 2012-05-30 16:31:58 +0100 | [diff] [blame] | 4878 | } |
| 4879 | |
| 4880 | static void |
Derek Foreman | 8ae2db5 | 2015-07-15 13:00:36 -0500 | [diff] [blame] | 4881 | terminate_binding(struct weston_keyboard *keyboard, uint32_t time, |
| 4882 | uint32_t key, void *data) |
Kristian Høgsberg | e1a850e | 2011-12-19 15:18:05 -0500 | [diff] [blame] | 4883 | { |
Kristian Høgsberg | 8334bc1 | 2012-01-03 10:29:47 -0500 | [diff] [blame] | 4884 | struct weston_compositor *compositor = data; |
Kristian Høgsberg | e1a850e | 2011-12-19 15:18:05 -0500 | [diff] [blame] | 4885 | |
Daniel Stone | 325fc2d | 2012-05-30 16:31:58 +0100 | [diff] [blame] | 4886 | wl_display_terminate(compositor->wl_display); |
Kristian Høgsberg | e1a850e | 2011-12-19 15:18:05 -0500 | [diff] [blame] | 4887 | } |
| 4888 | |
Emilio Pozuelo Monfort | 03251b6 | 2013-11-19 11:37:16 +0100 | [diff] [blame] | 4889 | static void |
Giulio Camuffo | 1959ab8 | 2013-11-14 23:42:52 +0100 | [diff] [blame] | 4890 | rotate_grab_motion(struct weston_pointer_grab *grab, uint32_t time, |
| 4891 | wl_fixed_t x, wl_fixed_t y) |
Pekka Paalanen | 460099f | 2012-01-20 16:48:25 +0200 | [diff] [blame] | 4892 | { |
| 4893 | struct rotate_grab *rotate = |
Ander Conselvan de Oliveira | fe0444a | 2012-04-04 17:48:05 +0300 | [diff] [blame] | 4894 | container_of(grab, struct rotate_grab, base.grab); |
Kristian Høgsberg | 02bbabb | 2013-05-06 22:15:05 -0400 | [diff] [blame] | 4895 | struct weston_pointer *pointer = grab->pointer; |
Ander Conselvan de Oliveira | fe0444a | 2012-04-04 17:48:05 +0300 | [diff] [blame] | 4896 | struct shell_surface *shsurf = rotate->base.shsurf; |
John Kåre Alsaker | 490d02a | 2012-09-30 02:57:21 +0200 | [diff] [blame] | 4897 | float cx, cy, dx, dy, cposx, cposy, dposx, dposy, r; |
Ander Conselvan de Oliveira | fe0444a | 2012-04-04 17:48:05 +0300 | [diff] [blame] | 4898 | |
Giulio Camuffo | 1959ab8 | 2013-11-14 23:42:52 +0100 | [diff] [blame] | 4899 | weston_pointer_move(pointer, x, y); |
| 4900 | |
Ander Conselvan de Oliveira | fe0444a | 2012-04-04 17:48:05 +0300 | [diff] [blame] | 4901 | if (!shsurf) |
| 4902 | return; |
| 4903 | |
Jason Ekstrand | 918f2dd | 2013-12-02 21:01:53 -0600 | [diff] [blame] | 4904 | cx = 0.5f * shsurf->surface->width; |
| 4905 | cy = 0.5f * shsurf->surface->height; |
Pekka Paalanen | 460099f | 2012-01-20 16:48:25 +0200 | [diff] [blame] | 4906 | |
Daniel Stone | 37816df | 2012-05-16 18:45:18 +0100 | [diff] [blame] | 4907 | dx = wl_fixed_to_double(pointer->x) - rotate->center.x; |
| 4908 | dy = wl_fixed_to_double(pointer->y) - rotate->center.y; |
Pekka Paalanen | 460099f | 2012-01-20 16:48:25 +0200 | [diff] [blame] | 4909 | r = sqrtf(dx * dx + dy * dy); |
| 4910 | |
Ander Conselvan de Oliveira | fe0444a | 2012-04-04 17:48:05 +0300 | [diff] [blame] | 4911 | wl_list_remove(&shsurf->rotation.transform.link); |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 4912 | weston_view_geometry_dirty(shsurf->view); |
Pekka Paalanen | 460099f | 2012-01-20 16:48:25 +0200 | [diff] [blame] | 4913 | |
| 4914 | if (r > 20.0f) { |
Pekka Paalanen | 460099f | 2012-01-20 16:48:25 +0200 | [diff] [blame] | 4915 | struct weston_matrix *matrix = |
Ander Conselvan de Oliveira | fe0444a | 2012-04-04 17:48:05 +0300 | [diff] [blame] | 4916 | &shsurf->rotation.transform.matrix; |
Pekka Paalanen | 460099f | 2012-01-20 16:48:25 +0200 | [diff] [blame] | 4917 | |
Kristian Høgsberg | 765e27b | 2012-01-27 13:36:13 -0500 | [diff] [blame] | 4918 | weston_matrix_init(&rotate->rotation); |
Vasily Khoruzhick | 1bbf372 | 2013-01-28 22:40:28 +0300 | [diff] [blame] | 4919 | weston_matrix_rotate_xy(&rotate->rotation, dx / r, dy / r); |
Pekka Paalanen | 460099f | 2012-01-20 16:48:25 +0200 | [diff] [blame] | 4920 | |
| 4921 | weston_matrix_init(matrix); |
Pekka Paalanen | 7b3bd3d | 2012-01-30 14:16:34 +0200 | [diff] [blame] | 4922 | weston_matrix_translate(matrix, -cx, -cy, 0.0f); |
Ander Conselvan de Oliveira | fe0444a | 2012-04-04 17:48:05 +0300 | [diff] [blame] | 4923 | weston_matrix_multiply(matrix, &shsurf->rotation.rotation); |
Kristian Høgsberg | 765e27b | 2012-01-27 13:36:13 -0500 | [diff] [blame] | 4924 | weston_matrix_multiply(matrix, &rotate->rotation); |
Pekka Paalanen | 7b3bd3d | 2012-01-30 14:16:34 +0200 | [diff] [blame] | 4925 | weston_matrix_translate(matrix, cx, cy, 0.0f); |
Pekka Paalanen | 460099f | 2012-01-20 16:48:25 +0200 | [diff] [blame] | 4926 | |
Pekka Paalanen | bc0b7e7 | 2012-01-24 09:53:37 +0200 | [diff] [blame] | 4927 | wl_list_insert( |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 4928 | &shsurf->view->geometry.transformation_list, |
Ander Conselvan de Oliveira | fe0444a | 2012-04-04 17:48:05 +0300 | [diff] [blame] | 4929 | &shsurf->rotation.transform.link); |
Pekka Paalanen | 460099f | 2012-01-20 16:48:25 +0200 | [diff] [blame] | 4930 | } else { |
Ander Conselvan de Oliveira | fe0444a | 2012-04-04 17:48:05 +0300 | [diff] [blame] | 4931 | wl_list_init(&shsurf->rotation.transform.link); |
| 4932 | weston_matrix_init(&shsurf->rotation.rotation); |
Kristian Høgsberg | 765e27b | 2012-01-27 13:36:13 -0500 | [diff] [blame] | 4933 | weston_matrix_init(&rotate->rotation); |
Pekka Paalanen | 460099f | 2012-01-20 16:48:25 +0200 | [diff] [blame] | 4934 | } |
Pekka Paalanen | b45ac5e | 2012-02-09 15:58:44 +0200 | [diff] [blame] | 4935 | |
Rafal Mielniczuk | 2d7ab82 | 2012-03-22 22:22:04 +0100 | [diff] [blame] | 4936 | /* We need to adjust the position of the surface |
| 4937 | * in case it was resized in a rotated state before */ |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 4938 | cposx = shsurf->view->geometry.x + cx; |
| 4939 | cposy = shsurf->view->geometry.y + cy; |
Rafal Mielniczuk | 2d7ab82 | 2012-03-22 22:22:04 +0100 | [diff] [blame] | 4940 | dposx = rotate->center.x - cposx; |
| 4941 | dposy = rotate->center.y - cposy; |
| 4942 | if (dposx != 0.0f || dposy != 0.0f) { |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 4943 | weston_view_set_position(shsurf->view, |
| 4944 | shsurf->view->geometry.x + dposx, |
| 4945 | shsurf->view->geometry.y + dposy); |
Rafal Mielniczuk | 2d7ab82 | 2012-03-22 22:22:04 +0100 | [diff] [blame] | 4946 | } |
| 4947 | |
Derek Foreman | 4b1a0a1 | 2014-09-10 15:37:33 -0500 | [diff] [blame] | 4948 | /* Repaint implies weston_view_update_transform(), which |
Pekka Paalanen | b45ac5e | 2012-02-09 15:58:44 +0200 | [diff] [blame] | 4949 | * lazily applies the damage due to rotation update. |
| 4950 | */ |
Ander Conselvan de Oliveira | fe0444a | 2012-04-04 17:48:05 +0300 | [diff] [blame] | 4951 | weston_compositor_schedule_repaint(shsurf->surface->compositor); |
Pekka Paalanen | 460099f | 2012-01-20 16:48:25 +0200 | [diff] [blame] | 4952 | } |
| 4953 | |
| 4954 | static void |
Kristian Høgsberg | 02bbabb | 2013-05-06 22:15:05 -0400 | [diff] [blame] | 4955 | rotate_grab_button(struct weston_pointer_grab *grab, |
| 4956 | uint32_t time, uint32_t button, uint32_t state_w) |
Pekka Paalanen | 460099f | 2012-01-20 16:48:25 +0200 | [diff] [blame] | 4957 | { |
| 4958 | struct rotate_grab *rotate = |
Ander Conselvan de Oliveira | fe0444a | 2012-04-04 17:48:05 +0300 | [diff] [blame] | 4959 | container_of(grab, struct rotate_grab, base.grab); |
Kristian Høgsberg | 02bbabb | 2013-05-06 22:15:05 -0400 | [diff] [blame] | 4960 | struct weston_pointer *pointer = grab->pointer; |
Ander Conselvan de Oliveira | fe0444a | 2012-04-04 17:48:05 +0300 | [diff] [blame] | 4961 | struct shell_surface *shsurf = rotate->base.shsurf; |
Daniel Stone | 4dbadb1 | 2012-05-30 16:31:51 +0100 | [diff] [blame] | 4962 | enum wl_pointer_button_state state = state_w; |
Pekka Paalanen | 460099f | 2012-01-20 16:48:25 +0200 | [diff] [blame] | 4963 | |
Daniel Stone | 4dbadb1 | 2012-05-30 16:31:51 +0100 | [diff] [blame] | 4964 | if (pointer->button_count == 0 && |
| 4965 | state == WL_POINTER_BUTTON_STATE_RELEASED) { |
Ander Conselvan de Oliveira | fe0444a | 2012-04-04 17:48:05 +0300 | [diff] [blame] | 4966 | if (shsurf) |
| 4967 | weston_matrix_multiply(&shsurf->rotation.rotation, |
| 4968 | &rotate->rotation); |
Ander Conselvan de Oliveira | b9d2a0f | 2012-06-28 18:08:05 +0300 | [diff] [blame] | 4969 | shell_grab_end(&rotate->base); |
Pekka Paalanen | 460099f | 2012-01-20 16:48:25 +0200 | [diff] [blame] | 4970 | free(rotate); |
| 4971 | } |
| 4972 | } |
| 4973 | |
Jonas Ådahl | 1ea343e | 2013-10-25 23:18:05 +0200 | [diff] [blame] | 4974 | static void |
| 4975 | rotate_grab_cancel(struct weston_pointer_grab *grab) |
| 4976 | { |
| 4977 | struct rotate_grab *rotate = |
| 4978 | container_of(grab, struct rotate_grab, base.grab); |
| 4979 | |
| 4980 | shell_grab_end(&rotate->base); |
| 4981 | free(rotate); |
| 4982 | } |
| 4983 | |
Kristian Høgsberg | 02bbabb | 2013-05-06 22:15:05 -0400 | [diff] [blame] | 4984 | static const struct weston_pointer_grab_interface rotate_grab_interface = { |
Pekka Paalanen | 460099f | 2012-01-20 16:48:25 +0200 | [diff] [blame] | 4985 | noop_grab_focus, |
| 4986 | rotate_grab_motion, |
| 4987 | rotate_grab_button, |
Jonas Ådahl | 1ea343e | 2013-10-25 23:18:05 +0200 | [diff] [blame] | 4988 | rotate_grab_cancel, |
Pekka Paalanen | 460099f | 2012-01-20 16:48:25 +0200 | [diff] [blame] | 4989 | }; |
| 4990 | |
| 4991 | static void |
Derek Foreman | 74de469 | 2015-07-15 13:00:39 -0500 | [diff] [blame] | 4992 | surface_rotate(struct shell_surface *surface, struct weston_pointer *pointer) |
Pekka Paalanen | 460099f | 2012-01-20 16:48:25 +0200 | [diff] [blame] | 4993 | { |
Pekka Paalanen | 460099f | 2012-01-20 16:48:25 +0200 | [diff] [blame] | 4994 | struct rotate_grab *rotate; |
John Kåre Alsaker | 490d02a | 2012-09-30 02:57:21 +0200 | [diff] [blame] | 4995 | float dx, dy; |
| 4996 | float r; |
Pekka Paalanen | 460099f | 2012-01-20 16:48:25 +0200 | [diff] [blame] | 4997 | |
Pekka Paalanen | 460099f | 2012-01-20 16:48:25 +0200 | [diff] [blame] | 4998 | rotate = malloc(sizeof *rotate); |
| 4999 | if (!rotate) |
| 5000 | return; |
| 5001 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 5002 | weston_view_to_global_float(surface->view, |
Jason Ekstrand | 918f2dd | 2013-12-02 21:01:53 -0600 | [diff] [blame] | 5003 | surface->surface->width * 0.5f, |
| 5004 | surface->surface->height * 0.5f, |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 5005 | &rotate->center.x, &rotate->center.y); |
Pekka Paalanen | 460099f | 2012-01-20 16:48:25 +0200 | [diff] [blame] | 5006 | |
Derek Foreman | 74de469 | 2015-07-15 13:00:39 -0500 | [diff] [blame] | 5007 | dx = wl_fixed_to_double(pointer->x) - rotate->center.x; |
| 5008 | dy = wl_fixed_to_double(pointer->y) - rotate->center.y; |
Kristian Høgsberg | 765e27b | 2012-01-27 13:36:13 -0500 | [diff] [blame] | 5009 | r = sqrtf(dx * dx + dy * dy); |
| 5010 | if (r > 20.0f) { |
| 5011 | struct weston_matrix inverse; |
| 5012 | |
| 5013 | weston_matrix_init(&inverse); |
Vasily Khoruzhick | 1bbf372 | 2013-01-28 22:40:28 +0300 | [diff] [blame] | 5014 | weston_matrix_rotate_xy(&inverse, dx / r, -dy / r); |
Kristian Høgsberg | 765e27b | 2012-01-27 13:36:13 -0500 | [diff] [blame] | 5015 | weston_matrix_multiply(&surface->rotation.rotation, &inverse); |
Rafal Mielniczuk | 2d7ab82 | 2012-03-22 22:22:04 +0100 | [diff] [blame] | 5016 | |
| 5017 | weston_matrix_init(&rotate->rotation); |
Vasily Khoruzhick | 1bbf372 | 2013-01-28 22:40:28 +0300 | [diff] [blame] | 5018 | weston_matrix_rotate_xy(&rotate->rotation, dx / r, dy / r); |
Kristian Høgsberg | 765e27b | 2012-01-27 13:36:13 -0500 | [diff] [blame] | 5019 | } else { |
| 5020 | weston_matrix_init(&surface->rotation.rotation); |
| 5021 | weston_matrix_init(&rotate->rotation); |
| 5022 | } |
| 5023 | |
Ander Conselvan de Oliveira | b9d2a0f | 2012-06-28 18:08:05 +0300 | [diff] [blame] | 5024 | shell_grab_start(&rotate->base, &rotate_grab_interface, surface, |
Derek Foreman | 74de469 | 2015-07-15 13:00:39 -0500 | [diff] [blame] | 5025 | pointer, DESKTOP_SHELL_CURSOR_ARROW); |
Pekka Paalanen | 460099f | 2012-01-20 16:48:25 +0200 | [diff] [blame] | 5026 | } |
| 5027 | |
| 5028 | static void |
Derek Foreman | 8ae2db5 | 2015-07-15 13:00:36 -0500 | [diff] [blame] | 5029 | 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] | 5030 | void *data) |
| 5031 | { |
Rafal Mielniczuk | b2917a2 | 2014-01-05 20:04:59 +0100 | [diff] [blame] | 5032 | struct weston_surface *focus; |
Pekka Paalanen | 01388e2 | 2013-04-25 13:57:44 +0300 | [diff] [blame] | 5033 | struct weston_surface *base_surface; |
Kristian Høgsberg | 0c36903 | 2013-02-14 21:31:44 -0500 | [diff] [blame] | 5034 | struct shell_surface *surface; |
| 5035 | |
Derek Foreman | 8ae2db5 | 2015-07-15 13:00:36 -0500 | [diff] [blame] | 5036 | if (pointer->focus == NULL) |
Rafal Mielniczuk | b2917a2 | 2014-01-05 20:04:59 +0100 | [diff] [blame] | 5037 | return; |
| 5038 | |
Derek Foreman | 8ae2db5 | 2015-07-15 13:00:36 -0500 | [diff] [blame] | 5039 | focus = pointer->focus->surface; |
Rafal Mielniczuk | b2917a2 | 2014-01-05 20:04:59 +0100 | [diff] [blame] | 5040 | |
Pekka Paalanen | 01388e2 | 2013-04-25 13:57:44 +0300 | [diff] [blame] | 5041 | base_surface = weston_surface_get_main_surface(focus); |
Kristian Høgsberg | 0c36903 | 2013-02-14 21:31:44 -0500 | [diff] [blame] | 5042 | if (base_surface == NULL) |
| 5043 | return; |
| 5044 | |
| 5045 | surface = get_shell_surface(base_surface); |
Rafael Antognolli | 03b1659 | 2013-12-03 15:35:42 -0200 | [diff] [blame] | 5046 | if (surface == NULL || surface->state.fullscreen || |
| 5047 | surface->state.maximized) |
Kristian Høgsberg | 0c36903 | 2013-02-14 21:31:44 -0500 | [diff] [blame] | 5048 | return; |
| 5049 | |
Derek Foreman | 74de469 | 2015-07-15 13:00:39 -0500 | [diff] [blame] | 5050 | surface_rotate(surface, pointer); |
Kristian Høgsberg | 0c36903 | 2013-02-14 21:31:44 -0500 | [diff] [blame] | 5051 | } |
| 5052 | |
Emilio Pozuelo Monfort | 9e7c759 | 2014-01-30 14:01:10 +0100 | [diff] [blame] | 5053 | /* Move all fullscreen layers down to the current workspace and hide their |
| 5054 | * black views. The surfaces' state is set to both fullscreen and lowered, |
| 5055 | * and this is reversed when such a surface is re-configured, see |
| 5056 | * shell_configure_fullscreen() and shell_ensure_fullscreen_black_view(). |
| 5057 | * |
Mario Kleiner | 9f4d655 | 2015-06-21 21:25:08 +0200 | [diff] [blame] | 5058 | * lowering_output = NULL - Lower on all outputs, else only lower on the |
| 5059 | * specified output. |
| 5060 | * |
Emilio Pozuelo Monfort | 9e7c759 | 2014-01-30 14:01:10 +0100 | [diff] [blame] | 5061 | * This should be used when implementing shell-wide overlays, such as |
Philip Withnall | 83ffd9d | 2013-11-25 18:01:42 +0000 | [diff] [blame] | 5062 | * the alt-tab switcher, which need to de-promote fullscreen layers. */ |
Kristian Høgsberg | 1ef2313 | 2013-12-04 00:20:01 -0800 | [diff] [blame] | 5063 | void |
Mario Kleiner | 9f4d655 | 2015-06-21 21:25:08 +0200 | [diff] [blame] | 5064 | lower_fullscreen_layer(struct desktop_shell *shell, |
| 5065 | struct weston_output *lowering_output) |
Kristian Høgsberg | b0d8e77 | 2012-06-18 16:34:58 -0400 | [diff] [blame] | 5066 | { |
| 5067 | struct workspace *ws; |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 5068 | struct weston_view *view, *prev; |
Kristian Høgsberg | b0d8e77 | 2012-06-18 16:34:58 -0400 | [diff] [blame] | 5069 | |
| 5070 | ws = get_current_workspace(shell); |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 5071 | wl_list_for_each_reverse_safe(view, prev, |
Giulio Camuffo | 412e6a5 | 2014-07-09 22:12:56 +0300 | [diff] [blame] | 5072 | &shell->fullscreen_layer.view_list.link, |
| 5073 | layer_link.link) { |
Emilio Pozuelo Monfort | 9e7c759 | 2014-01-30 14:01:10 +0100 | [diff] [blame] | 5074 | struct shell_surface *shsurf = get_shell_surface(view->surface); |
| 5075 | |
| 5076 | if (!shsurf) |
| 5077 | continue; |
| 5078 | |
Mario Kleiner | 9f4d655 | 2015-06-21 21:25:08 +0200 | [diff] [blame] | 5079 | /* Only lower surfaces which have lowering_output as their fullscreen |
| 5080 | * output, unless a NULL output asks for lowering on all outputs. |
| 5081 | */ |
| 5082 | if (lowering_output && (shsurf->fullscreen_output != lowering_output)) |
| 5083 | continue; |
| 5084 | |
Emilio Pozuelo Monfort | 9e7c759 | 2014-01-30 14:01:10 +0100 | [diff] [blame] | 5085 | /* We can have a non-fullscreen popup for a fullscreen surface |
| 5086 | * in the fullscreen layer. */ |
| 5087 | if (shsurf->state.fullscreen) { |
| 5088 | /* Hide the black view */ |
Giulio Camuffo | 412e6a5 | 2014-07-09 22:12:56 +0300 | [diff] [blame] | 5089 | weston_layer_entry_remove(&shsurf->fullscreen.black_view->layer_link); |
| 5090 | wl_list_init(&shsurf->fullscreen.black_view->layer_link.link); |
Kristian Høgsberg | c991513 | 2014-05-09 16:24:07 -0700 | [diff] [blame] | 5091 | weston_view_damage_below(shsurf->fullscreen.black_view); |
| 5092 | |
Emilio Pozuelo Monfort | 9e7c759 | 2014-01-30 14:01:10 +0100 | [diff] [blame] | 5093 | } |
| 5094 | |
| 5095 | /* Lower the view to the workspace layer */ |
Giulio Camuffo | 412e6a5 | 2014-07-09 22:12:56 +0300 | [diff] [blame] | 5096 | weston_layer_entry_remove(&view->layer_link); |
| 5097 | weston_layer_entry_insert(&ws->layer.view_list, &view->layer_link); |
Philip Withnall | 83ffd9d | 2013-11-25 18:01:42 +0000 | [diff] [blame] | 5098 | weston_view_damage_below(view); |
| 5099 | weston_surface_damage(view->surface); |
Emilio Pozuelo Monfort | 9e7c759 | 2014-01-30 14:01:10 +0100 | [diff] [blame] | 5100 | |
| 5101 | shsurf->state.lowered = true; |
Philip Withnall | 83ffd9d | 2013-11-25 18:01:42 +0000 | [diff] [blame] | 5102 | } |
Kristian Høgsberg | b0d8e77 | 2012-06-18 16:34:58 -0400 | [diff] [blame] | 5103 | } |
| 5104 | |
Kristian Høgsberg | 1ef2313 | 2013-12-04 00:20:01 -0800 | [diff] [blame] | 5105 | void |
Tiago Vignatti | be14326 | 2012-04-16 17:31:41 +0300 | [diff] [blame] | 5106 | activate(struct desktop_shell *shell, struct weston_surface *es, |
Emilio Pozuelo Monfort | 9e7c759 | 2014-01-30 14:01:10 +0100 | [diff] [blame] | 5107 | struct weston_seat *seat, bool configure) |
Kristian Høgsberg | 7584062 | 2011-09-06 13:48:16 -0400 | [diff] [blame] | 5108 | { |
Pekka Paalanen | 01388e2 | 2013-04-25 13:57:44 +0300 | [diff] [blame] | 5109 | struct weston_surface *main_surface; |
Kristian Høgsberg | 2f5faff | 2012-07-31 16:36:34 -0400 | [diff] [blame] | 5110 | struct focus_state *state; |
Jonas Ådahl | 8538b22 | 2012-08-29 22:13:03 +0200 | [diff] [blame] | 5111 | struct workspace *ws; |
Louis-Francis Ratté-Boulianne | b482dbd | 2013-11-19 11:37:11 +0100 | [diff] [blame] | 5112 | struct weston_surface *old_es; |
Rafael Antognolli | 03b1659 | 2013-12-03 15:35:42 -0200 | [diff] [blame] | 5113 | struct shell_surface *shsurf; |
Kristian Høgsberg | 7584062 | 2011-09-06 13:48:16 -0400 | [diff] [blame] | 5114 | |
Pekka Paalanen | 01388e2 | 2013-04-25 13:57:44 +0300 | [diff] [blame] | 5115 | main_surface = weston_surface_get_main_surface(es); |
Mario Kleiner | 9f4d655 | 2015-06-21 21:25:08 +0200 | [diff] [blame] | 5116 | shsurf = get_shell_surface(main_surface); |
| 5117 | assert(shsurf); |
| 5118 | |
| 5119 | /* Only demote fullscreen surfaces on the output of activated shsurf. |
| 5120 | * Leave fullscreen surfaces on unrelated outputs alone. */ |
| 5121 | lower_fullscreen_layer(shell, shsurf->output); |
Pekka Paalanen | 01388e2 | 2013-04-25 13:57:44 +0300 | [diff] [blame] | 5122 | |
Daniel Stone | 37816df | 2012-05-16 18:45:18 +0100 | [diff] [blame] | 5123 | weston_surface_activate(es, seat); |
Kristian Høgsberg | 7584062 | 2011-09-06 13:48:16 -0400 | [diff] [blame] | 5124 | |
Jonas Ådahl | 8538b22 | 2012-08-29 22:13:03 +0200 | [diff] [blame] | 5125 | state = ensure_focus_state(shell, seat); |
| 5126 | if (state == NULL) |
| 5127 | return; |
Kristian Høgsberg | 2f5faff | 2012-07-31 16:36:34 -0400 | [diff] [blame] | 5128 | |
Louis-Francis Ratté-Boulianne | b482dbd | 2013-11-19 11:37:11 +0100 | [diff] [blame] | 5129 | old_es = state->keyboard_focus; |
Kristian Høgsberg | d500bf1 | 2014-01-22 12:25:20 -0800 | [diff] [blame] | 5130 | focus_state_set_focus(state, es); |
Kristian Høgsberg | 2f5faff | 2012-07-31 16:36:34 -0400 | [diff] [blame] | 5131 | |
Emilio Pozuelo Monfort | 9e7c759 | 2014-01-30 14:01:10 +0100 | [diff] [blame] | 5132 | if (shsurf->state.fullscreen && configure) |
Rafael Antognolli | 03b1659 | 2013-12-03 15:35:42 -0200 | [diff] [blame] | 5133 | shell_configure_fullscreen(shsurf); |
| 5134 | else |
Mario Kleiner | 492c12f | 2015-06-21 21:25:12 +0200 | [diff] [blame] | 5135 | restore_output_mode(shsurf->output); |
Louis-Francis Ratté-Boulianne | b482dbd | 2013-11-19 11:37:11 +0100 | [diff] [blame] | 5136 | |
Emilio Pozuelo Monfort | 7908bff | 2014-01-30 13:49:39 +0100 | [diff] [blame] | 5137 | /* Update the surface’s layer. This brings it to the top of the stacking |
| 5138 | * order as appropriate. */ |
| 5139 | shell_surface_update_layer(shsurf); |
| 5140 | |
Philip Withnall | 83ffd9d | 2013-11-25 18:01:42 +0000 | [diff] [blame] | 5141 | if (shell->focus_animation_type != ANIMATION_NONE) { |
| 5142 | ws = get_current_workspace(shell); |
Louis-Francis Ratté-Boulianne | b482dbd | 2013-11-19 11:37:11 +0100 | [diff] [blame] | 5143 | 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] | 5144 | } |
Kristian Høgsberg | 7584062 | 2011-09-06 13:48:16 -0400 | [diff] [blame] | 5145 | } |
| 5146 | |
Alex Wu | 2185843 | 2012-04-01 20:13:08 +0800 | [diff] [blame] | 5147 | /* no-op func for checking black surface */ |
| 5148 | static void |
Jason Ekstrand | 918f2dd | 2013-12-02 21:01:53 -0600 | [diff] [blame] | 5149 | 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] | 5150 | { |
| 5151 | } |
| 5152 | |
Quentin Glidic | c0d79ce | 2013-01-29 14:16:13 +0100 | [diff] [blame] | 5153 | static bool |
Alex Wu | 2185843 | 2012-04-01 20:13:08 +0800 | [diff] [blame] | 5154 | is_black_surface (struct weston_surface *es, struct weston_surface **fs_surface) |
| 5155 | { |
| 5156 | if (es->configure == black_surface_configure) { |
| 5157 | if (fs_surface) |
Giulio Camuffo | 7fe01b1 | 2013-03-28 18:02:42 +0100 | [diff] [blame] | 5158 | *fs_surface = (struct weston_surface *)es->configure_private; |
Alex Wu | 2185843 | 2012-04-01 20:13:08 +0800 | [diff] [blame] | 5159 | return true; |
| 5160 | } |
| 5161 | return false; |
| 5162 | } |
| 5163 | |
Kristian Høgsberg | 7584062 | 2011-09-06 13:48:16 -0400 | [diff] [blame] | 5164 | static void |
Neil Roberts | a28c693 | 2013-10-03 16:43:04 +0100 | [diff] [blame] | 5165 | activate_binding(struct weston_seat *seat, |
| 5166 | struct desktop_shell *shell, |
| 5167 | struct weston_surface *focus) |
Kristian Høgsberg | e1a850e | 2011-12-19 15:18:05 -0500 | [diff] [blame] | 5168 | { |
Pekka Paalanen | 01388e2 | 2013-04-25 13:57:44 +0300 | [diff] [blame] | 5169 | struct weston_surface *main_surface; |
Kristian Høgsberg | e1a850e | 2011-12-19 15:18:05 -0500 | [diff] [blame] | 5170 | |
Alex Wu | 9c35e6b | 2012-03-05 14:13:13 +0800 | [diff] [blame] | 5171 | if (!focus) |
| 5172 | return; |
| 5173 | |
Pekka Paalanen | 01388e2 | 2013-04-25 13:57:44 +0300 | [diff] [blame] | 5174 | if (is_black_surface(focus, &main_surface)) |
| 5175 | focus = main_surface; |
Alex Wu | 4539b08 | 2012-03-01 12:57:46 +0800 | [diff] [blame] | 5176 | |
Pekka Paalanen | 01388e2 | 2013-04-25 13:57:44 +0300 | [diff] [blame] | 5177 | main_surface = weston_surface_get_main_surface(focus); |
| 5178 | if (get_shell_surface_type(main_surface) == SHELL_SURFACE_NONE) |
Kristian Høgsberg | 0636ac3 | 2012-06-27 10:22:15 -0400 | [diff] [blame] | 5179 | return; |
Kristian Høgsberg | 85b2e4b | 2012-06-21 16:49:42 -0400 | [diff] [blame] | 5180 | |
Emilio Pozuelo Monfort | 9e7c759 | 2014-01-30 14:01:10 +0100 | [diff] [blame] | 5181 | activate(shell, focus, seat, true); |
Neil Roberts | a28c693 | 2013-10-03 16:43:04 +0100 | [diff] [blame] | 5182 | } |
| 5183 | |
| 5184 | static void |
Derek Foreman | 8ae2db5 | 2015-07-15 13:00:36 -0500 | [diff] [blame] | 5185 | click_to_activate_binding(struct weston_pointer *pointer, uint32_t time, |
| 5186 | uint32_t button, void *data) |
Neil Roberts | a28c693 | 2013-10-03 16:43:04 +0100 | [diff] [blame] | 5187 | { |
Derek Foreman | 8ae2db5 | 2015-07-15 13:00:36 -0500 | [diff] [blame] | 5188 | if (pointer->grab != &pointer->default_grab) |
Neil Roberts | a28c693 | 2013-10-03 16:43:04 +0100 | [diff] [blame] | 5189 | return; |
Derek Foreman | 8ae2db5 | 2015-07-15 13:00:36 -0500 | [diff] [blame] | 5190 | if (pointer->focus == NULL) |
Kristian Høgsberg | 7c4f6cc | 2014-01-01 16:28:32 -0800 | [diff] [blame] | 5191 | return; |
Neil Roberts | a28c693 | 2013-10-03 16:43:04 +0100 | [diff] [blame] | 5192 | |
Derek Foreman | 8ae2db5 | 2015-07-15 13:00:36 -0500 | [diff] [blame] | 5193 | activate_binding(pointer->seat, data, pointer->focus->surface); |
Neil Roberts | a28c693 | 2013-10-03 16:43:04 +0100 | [diff] [blame] | 5194 | } |
| 5195 | |
| 5196 | static void |
Derek Foreman | 8ae2db5 | 2015-07-15 13:00:36 -0500 | [diff] [blame] | 5197 | touch_to_activate_binding(struct weston_touch *touch, uint32_t time, |
| 5198 | void *data) |
Neil Roberts | a28c693 | 2013-10-03 16:43:04 +0100 | [diff] [blame] | 5199 | { |
Derek Foreman | 8ae2db5 | 2015-07-15 13:00:36 -0500 | [diff] [blame] | 5200 | if (touch->grab != &touch->default_grab) |
Neil Roberts | a28c693 | 2013-10-03 16:43:04 +0100 | [diff] [blame] | 5201 | return; |
Derek Foreman | 8ae2db5 | 2015-07-15 13:00:36 -0500 | [diff] [blame] | 5202 | if (touch->focus == NULL) |
Kristian Høgsberg | 0ed6750 | 2014-01-02 23:00:11 -0800 | [diff] [blame] | 5203 | return; |
Neil Roberts | a28c693 | 2013-10-03 16:43:04 +0100 | [diff] [blame] | 5204 | |
Derek Foreman | 8ae2db5 | 2015-07-15 13:00:36 -0500 | [diff] [blame] | 5205 | activate_binding(touch->seat, data, touch->focus->surface); |
Kristian Høgsberg | e1a850e | 2011-12-19 15:18:05 -0500 | [diff] [blame] | 5206 | } |
| 5207 | |
| 5208 | static void |
Neil Roberts | b4a9170 | 2014-04-09 16:33:32 +0100 | [diff] [blame] | 5209 | unfocus_all_seats(struct desktop_shell *shell) |
| 5210 | { |
| 5211 | struct weston_seat *seat, *next; |
| 5212 | |
| 5213 | wl_list_for_each_safe(seat, next, &shell->compositor->seat_list, link) { |
Derek Foreman | 1281a36 | 2015-07-31 16:55:32 -0500 | [diff] [blame] | 5214 | struct weston_keyboard *keyboard = |
| 5215 | weston_seat_get_keyboard(seat); |
| 5216 | |
| 5217 | if (!keyboard) |
Neil Roberts | b4a9170 | 2014-04-09 16:33:32 +0100 | [diff] [blame] | 5218 | continue; |
| 5219 | |
Derek Foreman | 1281a36 | 2015-07-31 16:55:32 -0500 | [diff] [blame] | 5220 | weston_keyboard_set_focus(keyboard, NULL); |
Neil Roberts | b4a9170 | 2014-04-09 16:33:32 +0100 | [diff] [blame] | 5221 | } |
| 5222 | } |
| 5223 | |
| 5224 | static void |
Ander Conselvan de Oliveira | 19d10ef | 2013-02-21 18:35:20 +0200 | [diff] [blame] | 5225 | lock(struct desktop_shell *shell) |
Kristian Høgsberg | 02ec0a5 | 2011-04-23 13:04:11 -0400 | [diff] [blame] | 5226 | { |
Kristian Høgsberg | 4476aaf | 2012-06-25 14:03:13 -0400 | [diff] [blame] | 5227 | struct workspace *ws = get_current_workspace(shell); |
Pekka Paalanen | f0fc70d | 2011-11-15 13:34:54 +0200 | [diff] [blame] | 5228 | |
Tiago Vignatti | 8e53c7f | 2012-02-29 19:53:50 +0200 | [diff] [blame] | 5229 | if (shell->locked) { |
Ander Conselvan de Oliveira | 87524b6 | 2013-02-21 18:35:22 +0200 | [diff] [blame] | 5230 | weston_compositor_sleep(shell->compositor); |
Pekka Paalanen | f0fc70d | 2011-11-15 13:34:54 +0200 | [diff] [blame] | 5231 | return; |
Tiago Vignatti | 8e53c7f | 2012-02-29 19:53:50 +0200 | [diff] [blame] | 5232 | } |
Pekka Paalanen | 9ef3e01 | 2011-11-15 13:34:48 +0200 | [diff] [blame] | 5233 | |
| 5234 | shell->locked = true; |
Pekka Paalanen | f0fc70d | 2011-11-15 13:34:54 +0200 | [diff] [blame] | 5235 | |
Kristian Høgsberg | 3be2ce9 | 2012-02-29 12:42:35 -0500 | [diff] [blame] | 5236 | /* Hide all surfaces by removing the fullscreen, panel and |
| 5237 | * toplevel layers. This way nothing else can show or receive |
| 5238 | * input events while we are locked. */ |
Pekka Paalanen | f0fc70d | 2011-11-15 13:34:54 +0200 | [diff] [blame] | 5239 | |
Kristian Høgsberg | 3be2ce9 | 2012-02-29 12:42:35 -0500 | [diff] [blame] | 5240 | wl_list_remove(&shell->panel_layer.link); |
Kristian Høgsberg | 3be2ce9 | 2012-02-29 12:42:35 -0500 | [diff] [blame] | 5241 | wl_list_remove(&shell->fullscreen_layer.link); |
Philipp Brüschweiler | 711fda8 | 2012-08-09 18:50:43 +0200 | [diff] [blame] | 5242 | if (shell->showing_input_panels) |
| 5243 | wl_list_remove(&shell->input_panel_layer.link); |
Kristian Høgsberg | 4476aaf | 2012-06-25 14:03:13 -0400 | [diff] [blame] | 5244 | wl_list_remove(&ws->layer.link); |
Kristian Høgsberg | 3be2ce9 | 2012-02-29 12:42:35 -0500 | [diff] [blame] | 5245 | wl_list_insert(&shell->compositor->cursor_layer.link, |
| 5246 | &shell->lock_layer.link); |
Pekka Paalanen | f0fc70d | 2011-11-15 13:34:54 +0200 | [diff] [blame] | 5247 | |
Derek Foreman | 004b4a1 | 2015-07-20 16:28:13 -0500 | [diff] [blame] | 5248 | weston_compositor_sleep(shell->compositor); |
| 5249 | |
Neil Roberts | b4a9170 | 2014-04-09 16:33:32 +0100 | [diff] [blame] | 5250 | /* Remove the keyboard focus on all seats. This will be |
| 5251 | * restored to the workspace's saved state via |
| 5252 | * restore_focus_state when the compositor is unlocked */ |
| 5253 | unfocus_all_seats(shell); |
| 5254 | |
Pekka Paalanen | f0fc70d | 2011-11-15 13:34:54 +0200 | [diff] [blame] | 5255 | /* TODO: disable bindings that should not work while locked. */ |
| 5256 | |
| 5257 | /* All this must be undone in resume_desktop(). */ |
Pekka Paalanen | 9ef3e01 | 2011-11-15 13:34:48 +0200 | [diff] [blame] | 5258 | } |
| 5259 | |
| 5260 | static void |
Ander Conselvan de Oliveira | 19d10ef | 2013-02-21 18:35:20 +0200 | [diff] [blame] | 5261 | unlock(struct desktop_shell *shell) |
Pekka Paalanen | 9ef3e01 | 2011-11-15 13:34:48 +0200 | [diff] [blame] | 5262 | { |
Pekka Paalanen | d81c216 | 2011-11-16 13:47:34 +0200 | [diff] [blame] | 5263 | if (!shell->locked || shell->lock_surface) { |
Ander Conselvan de Oliveira | 87524b6 | 2013-02-21 18:35:22 +0200 | [diff] [blame] | 5264 | shell_fade(shell, FADE_IN); |
Pekka Paalanen | 9ef3e01 | 2011-11-15 13:34:48 +0200 | [diff] [blame] | 5265 | return; |
| 5266 | } |
| 5267 | |
| 5268 | /* If desktop-shell client has gone away, unlock immediately. */ |
| 5269 | if (!shell->child.desktop_shell) { |
Pekka Paalanen | f0fc70d | 2011-11-15 13:34:54 +0200 | [diff] [blame] | 5270 | resume_desktop(shell); |
Pekka Paalanen | 9ef3e01 | 2011-11-15 13:34:48 +0200 | [diff] [blame] | 5271 | return; |
| 5272 | } |
| 5273 | |
| 5274 | if (shell->prepare_event_sent) |
| 5275 | return; |
| 5276 | |
Kristian Høgsberg | 0b5cd0c | 2012-03-04 21:57:37 -0500 | [diff] [blame] | 5277 | desktop_shell_send_prepare_lock_surface(shell->child.desktop_shell); |
Pekka Paalanen | 9ef3e01 | 2011-11-15 13:34:48 +0200 | [diff] [blame] | 5278 | shell->prepare_event_sent = true; |
Kristian Høgsberg | 02ec0a5 | 2011-04-23 13:04:11 -0400 | [diff] [blame] | 5279 | } |
| 5280 | |
| 5281 | static void |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 5282 | shell_fade_done(struct weston_view_animation *animation, void *data) |
Ander Conselvan de Oliveira | 19d10ef | 2013-02-21 18:35:20 +0200 | [diff] [blame] | 5283 | { |
| 5284 | struct desktop_shell *shell = data; |
| 5285 | |
| 5286 | shell->fade.animation = NULL; |
| 5287 | |
| 5288 | switch (shell->fade.type) { |
| 5289 | case FADE_IN: |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 5290 | weston_surface_destroy(shell->fade.view->surface); |
| 5291 | shell->fade.view = NULL; |
Ander Conselvan de Oliveira | 19d10ef | 2013-02-21 18:35:20 +0200 | [diff] [blame] | 5292 | break; |
| 5293 | case FADE_OUT: |
Ander Conselvan de Oliveira | 19d10ef | 2013-02-21 18:35:20 +0200 | [diff] [blame] | 5294 | lock(shell); |
| 5295 | break; |
Philip Withnall | 4a86a0a | 2013-11-25 18:01:32 +0000 | [diff] [blame] | 5296 | default: |
| 5297 | break; |
Ander Conselvan de Oliveira | 19d10ef | 2013-02-21 18:35:20 +0200 | [diff] [blame] | 5298 | } |
| 5299 | } |
| 5300 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 5301 | static struct weston_view * |
Pekka Paalanen | 79346ab | 2013-05-22 18:03:09 +0300 | [diff] [blame] | 5302 | shell_fade_create_surface(struct desktop_shell *shell) |
Ander Conselvan de Oliveira | 19d10ef | 2013-02-21 18:35:20 +0200 | [diff] [blame] | 5303 | { |
| 5304 | struct weston_compositor *compositor = shell->compositor; |
| 5305 | struct weston_surface *surface; |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 5306 | struct weston_view *view; |
Pekka Paalanen | 79346ab | 2013-05-22 18:03:09 +0300 | [diff] [blame] | 5307 | |
| 5308 | surface = weston_surface_create(compositor); |
| 5309 | if (!surface) |
| 5310 | return NULL; |
| 5311 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 5312 | view = weston_view_create(surface); |
| 5313 | if (!view) { |
| 5314 | weston_surface_destroy(surface); |
| 5315 | return NULL; |
| 5316 | } |
| 5317 | |
Jason Ekstrand | 5c11a33 | 2013-12-04 20:32:03 -0600 | [diff] [blame] | 5318 | weston_surface_set_size(surface, 8192, 8192); |
Jason Ekstrand | 918f2dd | 2013-12-02 21:01:53 -0600 | [diff] [blame] | 5319 | weston_view_set_position(view, 0, 0); |
Pekka Paalanen | 79346ab | 2013-05-22 18:03:09 +0300 | [diff] [blame] | 5320 | 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] | 5321 | weston_layer_entry_insert(&compositor->fade_layer.view_list, |
| 5322 | &view->layer_link); |
Pekka Paalanen | 79346ab | 2013-05-22 18:03:09 +0300 | [diff] [blame] | 5323 | pixman_region32_init(&surface->input); |
| 5324 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 5325 | return view; |
Pekka Paalanen | 79346ab | 2013-05-22 18:03:09 +0300 | [diff] [blame] | 5326 | } |
| 5327 | |
| 5328 | static void |
| 5329 | shell_fade(struct desktop_shell *shell, enum fade_type type) |
| 5330 | { |
Ander Conselvan de Oliveira | 19d10ef | 2013-02-21 18:35:20 +0200 | [diff] [blame] | 5331 | float tint; |
| 5332 | |
| 5333 | switch (type) { |
| 5334 | case FADE_IN: |
| 5335 | tint = 0.0; |
| 5336 | break; |
| 5337 | case FADE_OUT: |
| 5338 | tint = 1.0; |
| 5339 | break; |
| 5340 | default: |
| 5341 | weston_log("shell: invalid fade type\n"); |
| 5342 | return; |
| 5343 | } |
| 5344 | |
| 5345 | shell->fade.type = type; |
| 5346 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 5347 | if (shell->fade.view == NULL) { |
| 5348 | shell->fade.view = shell_fade_create_surface(shell); |
| 5349 | if (!shell->fade.view) |
Ander Conselvan de Oliveira | 19d10ef | 2013-02-21 18:35:20 +0200 | [diff] [blame] | 5350 | return; |
| 5351 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 5352 | shell->fade.view->alpha = 1.0 - tint; |
| 5353 | weston_view_update_transform(shell->fade.view); |
Ander Conselvan de Oliveira | 19d10ef | 2013-02-21 18:35:20 +0200 | [diff] [blame] | 5354 | } |
| 5355 | |
Kristian Høgsberg | 87d3b61 | 2014-01-19 21:48:10 -0800 | [diff] [blame] | 5356 | if (shell->fade.view->output == NULL) { |
| 5357 | /* If the black view gets a NULL output, we lost the |
| 5358 | * last output and we'll just cancel the fade. This |
| 5359 | * happens when you close the last window under the |
| 5360 | * X11 or Wayland backends. */ |
| 5361 | shell->locked = false; |
| 5362 | weston_surface_destroy(shell->fade.view->surface); |
| 5363 | shell->fade.view = NULL; |
| 5364 | } else if (shell->fade.animation) { |
Kristian Høgsberg | 5281fb1 | 2013-06-17 10:10:28 -0400 | [diff] [blame] | 5365 | weston_fade_update(shell->fade.animation, tint); |
Kristian Høgsberg | 87d3b61 | 2014-01-19 21:48:10 -0800 | [diff] [blame] | 5366 | } else { |
Ander Conselvan de Oliveira | 19d10ef | 2013-02-21 18:35:20 +0200 | [diff] [blame] | 5367 | shell->fade.animation = |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 5368 | weston_fade_run(shell->fade.view, |
Kristian Høgsberg | 5281fb1 | 2013-06-17 10:10:28 -0400 | [diff] [blame] | 5369 | 1.0 - tint, tint, 300.0, |
Ander Conselvan de Oliveira | 19d10ef | 2013-02-21 18:35:20 +0200 | [diff] [blame] | 5370 | shell_fade_done, shell); |
Kristian Høgsberg | 87d3b61 | 2014-01-19 21:48:10 -0800 | [diff] [blame] | 5371 | } |
Ander Conselvan de Oliveira | 19d10ef | 2013-02-21 18:35:20 +0200 | [diff] [blame] | 5372 | } |
| 5373 | |
| 5374 | static void |
Pekka Paalanen | 79346ab | 2013-05-22 18:03:09 +0300 | [diff] [blame] | 5375 | do_shell_fade_startup(void *data) |
| 5376 | { |
| 5377 | struct desktop_shell *shell = data; |
| 5378 | |
Pekka Paalanen | 23ed5f2 | 2015-05-26 11:54:52 +0300 | [diff] [blame] | 5379 | if (shell->startup_animation_type == ANIMATION_FADE) { |
Kristian Høgsberg | 724c8d9 | 2013-10-16 11:38:24 -0700 | [diff] [blame] | 5380 | shell_fade(shell, FADE_IN); |
Pekka Paalanen | 23ed5f2 | 2015-05-26 11:54:52 +0300 | [diff] [blame] | 5381 | } else { |
| 5382 | weston_log("desktop shell: " |
| 5383 | "unexpected fade-in animation type %d\n", |
| 5384 | shell->startup_animation_type); |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 5385 | weston_surface_destroy(shell->fade.view->surface); |
| 5386 | shell->fade.view = NULL; |
Kristian Høgsberg | 724c8d9 | 2013-10-16 11:38:24 -0700 | [diff] [blame] | 5387 | } |
Pekka Paalanen | 79346ab | 2013-05-22 18:03:09 +0300 | [diff] [blame] | 5388 | } |
| 5389 | |
| 5390 | static void |
| 5391 | shell_fade_startup(struct desktop_shell *shell) |
| 5392 | { |
| 5393 | struct wl_event_loop *loop; |
| 5394 | |
| 5395 | if (!shell->fade.startup_timer) |
| 5396 | return; |
| 5397 | |
| 5398 | wl_event_source_remove(shell->fade.startup_timer); |
| 5399 | shell->fade.startup_timer = NULL; |
| 5400 | |
| 5401 | loop = wl_display_get_event_loop(shell->compositor->wl_display); |
| 5402 | wl_event_loop_add_idle(loop, do_shell_fade_startup, shell); |
| 5403 | } |
| 5404 | |
| 5405 | static int |
| 5406 | fade_startup_timeout(void *data) |
| 5407 | { |
| 5408 | struct desktop_shell *shell = data; |
| 5409 | |
| 5410 | shell_fade_startup(shell); |
| 5411 | return 0; |
| 5412 | } |
| 5413 | |
| 5414 | static void |
| 5415 | shell_fade_init(struct desktop_shell *shell) |
| 5416 | { |
| 5417 | /* Make compositor output all black, and wait for the desktop-shell |
| 5418 | * client to signal it is ready, then fade in. The timer triggers a |
| 5419 | * fade-in, in case the desktop-shell client takes too long. |
| 5420 | */ |
| 5421 | |
| 5422 | struct wl_event_loop *loop; |
| 5423 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 5424 | if (shell->fade.view != NULL) { |
Pekka Paalanen | 79346ab | 2013-05-22 18:03:09 +0300 | [diff] [blame] | 5425 | weston_log("%s: warning: fade surface already exists\n", |
| 5426 | __func__); |
| 5427 | return; |
| 5428 | } |
| 5429 | |
Pekka Paalanen | 23ed5f2 | 2015-05-26 11:54:52 +0300 | [diff] [blame] | 5430 | if (shell->startup_animation_type == ANIMATION_NONE) |
| 5431 | return; |
| 5432 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 5433 | shell->fade.view = shell_fade_create_surface(shell); |
| 5434 | if (!shell->fade.view) |
Pekka Paalanen | 79346ab | 2013-05-22 18:03:09 +0300 | [diff] [blame] | 5435 | return; |
| 5436 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 5437 | weston_view_update_transform(shell->fade.view); |
| 5438 | weston_surface_damage(shell->fade.view->surface); |
Pekka Paalanen | 79346ab | 2013-05-22 18:03:09 +0300 | [diff] [blame] | 5439 | |
| 5440 | loop = wl_display_get_event_loop(shell->compositor->wl_display); |
| 5441 | shell->fade.startup_timer = |
| 5442 | wl_event_loop_add_timer(loop, fade_startup_timeout, shell); |
| 5443 | wl_event_source_timer_update(shell->fade.startup_timer, 15000); |
| 5444 | } |
| 5445 | |
| 5446 | static void |
Ander Conselvan de Oliveira | a457563 | 2013-02-21 18:35:23 +0200 | [diff] [blame] | 5447 | idle_handler(struct wl_listener *listener, void *data) |
Ander Conselvan de Oliveira | 19d10ef | 2013-02-21 18:35:20 +0200 | [diff] [blame] | 5448 | { |
| 5449 | struct desktop_shell *shell = |
Ander Conselvan de Oliveira | a457563 | 2013-02-21 18:35:23 +0200 | [diff] [blame] | 5450 | container_of(listener, struct desktop_shell, idle_listener); |
Kristian Høgsberg | 27d5fa8 | 2014-01-17 16:22:50 -0800 | [diff] [blame] | 5451 | struct weston_seat *seat; |
| 5452 | |
Jonny Lamb | 76cf1fe | 2014-08-20 11:27:10 +0200 | [diff] [blame] | 5453 | wl_list_for_each(seat, &shell->compositor->seat_list, link) { |
Derek Foreman | 1281a36 | 2015-07-31 16:55:32 -0500 | [diff] [blame] | 5454 | struct weston_touch *touch = weston_seat_get_touch(seat); |
| 5455 | struct weston_pointer *pointer = weston_seat_get_pointer(seat); |
| 5456 | |
| 5457 | if (pointer) |
| 5458 | popup_grab_end(pointer); |
| 5459 | if (touch) |
| 5460 | touch_popup_grab_end(touch); |
Jonny Lamb | 76cf1fe | 2014-08-20 11:27:10 +0200 | [diff] [blame] | 5461 | } |
Ander Conselvan de Oliveira | 19d10ef | 2013-02-21 18:35:20 +0200 | [diff] [blame] | 5462 | |
| 5463 | shell_fade(shell, FADE_OUT); |
| 5464 | /* lock() is called from shell_fade_done() */ |
| 5465 | } |
| 5466 | |
| 5467 | static void |
Ander Conselvan de Oliveira | a457563 | 2013-02-21 18:35:23 +0200 | [diff] [blame] | 5468 | wake_handler(struct wl_listener *listener, void *data) |
Ander Conselvan de Oliveira | 19d10ef | 2013-02-21 18:35:20 +0200 | [diff] [blame] | 5469 | { |
| 5470 | struct desktop_shell *shell = |
Ander Conselvan de Oliveira | a457563 | 2013-02-21 18:35:23 +0200 | [diff] [blame] | 5471 | container_of(listener, struct desktop_shell, wake_listener); |
Ander Conselvan de Oliveira | 19d10ef | 2013-02-21 18:35:20 +0200 | [diff] [blame] | 5472 | |
Ander Conselvan de Oliveira | 19d10ef | 2013-02-21 18:35:20 +0200 | [diff] [blame] | 5473 | unlock(shell); |
| 5474 | } |
| 5475 | |
| 5476 | static void |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 5477 | center_on_output(struct weston_view *view, struct weston_output *output) |
Pekka Paalanen | 77346a6 | 2011-11-30 16:26:35 +0200 | [diff] [blame] | 5478 | { |
Giulio Camuffo | b836664 | 2013-04-25 13:57:46 +0300 | [diff] [blame] | 5479 | int32_t surf_x, surf_y, width, height; |
Ander Conselvan de Oliveira | 012b4c7 | 2012-11-27 17:03:42 +0200 | [diff] [blame] | 5480 | float x, y; |
Pekka Paalanen | 77346a6 | 2011-11-30 16:26:35 +0200 | [diff] [blame] | 5481 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 5482 | surface_subsurfaces_boundingbox(view->surface, &surf_x, &surf_y, &width, &height); |
Giulio Camuffo | b836664 | 2013-04-25 13:57:46 +0300 | [diff] [blame] | 5483 | |
| 5484 | x = output->x + (output->width - width) / 2 - surf_x / 2; |
| 5485 | y = output->y + (output->height - height) / 2 - surf_y / 2; |
Ander Conselvan de Oliveira | 012b4c7 | 2012-11-27 17:03:42 +0200 | [diff] [blame] | 5486 | |
Jason Ekstrand | 918f2dd | 2013-12-02 21:01:53 -0600 | [diff] [blame] | 5487 | weston_view_set_position(view, x, y); |
Pekka Paalanen | 77346a6 | 2011-11-30 16:26:35 +0200 | [diff] [blame] | 5488 | } |
| 5489 | |
| 5490 | static void |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 5491 | weston_view_set_initial_position(struct weston_view *view, |
| 5492 | struct desktop_shell *shell) |
Rob Bradford | ac63e5b | 2012-08-13 14:07:52 +0100 | [diff] [blame] | 5493 | { |
| 5494 | struct weston_compositor *compositor = shell->compositor; |
| 5495 | int ix = 0, iy = 0; |
Jonny Lamb | d73c694 | 2014-08-20 15:53:20 +0200 | [diff] [blame] | 5496 | int32_t range_x, range_y; |
Derek Foreman | f814c5d | 2015-04-15 12:23:54 -0500 | [diff] [blame] | 5497 | int32_t x, y; |
Rob Bradford | ac63e5b | 2012-08-13 14:07:52 +0100 | [diff] [blame] | 5498 | struct weston_output *output, *target_output = NULL; |
| 5499 | struct weston_seat *seat; |
Jonny Lamb | d73c694 | 2014-08-20 15:53:20 +0200 | [diff] [blame] | 5500 | pixman_rectangle32_t area; |
Rob Bradford | ac63e5b | 2012-08-13 14:07:52 +0100 | [diff] [blame] | 5501 | |
| 5502 | /* As a heuristic place the new window on the same output as the |
| 5503 | * pointer. Falling back to the output containing 0, 0. |
| 5504 | * |
| 5505 | * TODO: Do something clever for touch too? |
| 5506 | */ |
| 5507 | wl_list_for_each(seat, &compositor->seat_list, link) { |
Derek Foreman | 1281a36 | 2015-07-31 16:55:32 -0500 | [diff] [blame] | 5508 | struct weston_pointer *pointer = weston_seat_get_pointer(seat); |
| 5509 | |
| 5510 | if (pointer) { |
| 5511 | ix = wl_fixed_to_int(pointer->x); |
| 5512 | iy = wl_fixed_to_int(pointer->y); |
Rob Bradford | ac63e5b | 2012-08-13 14:07:52 +0100 | [diff] [blame] | 5513 | break; |
| 5514 | } |
| 5515 | } |
| 5516 | |
| 5517 | wl_list_for_each(output, &compositor->output_list, link) { |
| 5518 | if (pixman_region32_contains_point(&output->region, ix, iy, NULL)) { |
| 5519 | target_output = output; |
| 5520 | break; |
| 5521 | } |
| 5522 | } |
| 5523 | |
| 5524 | if (!target_output) { |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 5525 | weston_view_set_position(view, 10 + random() % 400, |
| 5526 | 10 + random() % 400); |
Rob Bradford | ac63e5b | 2012-08-13 14:07:52 +0100 | [diff] [blame] | 5527 | return; |
| 5528 | } |
| 5529 | |
| 5530 | /* Valid range within output where the surface will still be onscreen. |
| 5531 | * If this is negative it means that the surface is bigger than |
| 5532 | * output. |
| 5533 | */ |
Jonny Lamb | d73c694 | 2014-08-20 15:53:20 +0200 | [diff] [blame] | 5534 | get_output_work_area(shell, target_output, &area); |
| 5535 | |
Derek Foreman | f814c5d | 2015-04-15 12:23:54 -0500 | [diff] [blame] | 5536 | x = area.x; |
| 5537 | y = area.y; |
Jonny Lamb | d73c694 | 2014-08-20 15:53:20 +0200 | [diff] [blame] | 5538 | range_x = area.width - view->surface->width; |
| 5539 | range_y = area.height - view->surface->height; |
Rob Bradford | ac63e5b | 2012-08-13 14:07:52 +0100 | [diff] [blame] | 5540 | |
Rob Bradford | 4cb88c7 | 2012-08-13 15:18:44 +0100 | [diff] [blame] | 5541 | if (range_x > 0) |
Derek Foreman | f814c5d | 2015-04-15 12:23:54 -0500 | [diff] [blame] | 5542 | x += random() % range_x; |
Rob Bradford | 4cb88c7 | 2012-08-13 15:18:44 +0100 | [diff] [blame] | 5543 | |
| 5544 | if (range_y > 0) |
Derek Foreman | f814c5d | 2015-04-15 12:23:54 -0500 | [diff] [blame] | 5545 | y += random() % range_y; |
Rob Bradford | ac63e5b | 2012-08-13 14:07:52 +0100 | [diff] [blame] | 5546 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 5547 | weston_view_set_position(view, x, y); |
Rob Bradford | ac63e5b | 2012-08-13 14:07:52 +0100 | [diff] [blame] | 5548 | } |
| 5549 | |
| 5550 | static void |
Jonny Lamb | d73c694 | 2014-08-20 15:53:20 +0200 | [diff] [blame] | 5551 | set_maximized_position(struct desktop_shell *shell, |
| 5552 | struct shell_surface *shsurf) |
| 5553 | { |
| 5554 | int32_t surf_x, surf_y; |
| 5555 | pixman_rectangle32_t area; |
Marek Chalupa | 8b771af | 2014-09-01 17:20:33 +0200 | [diff] [blame] | 5556 | pixman_box32_t *e; |
Jonny Lamb | d73c694 | 2014-08-20 15:53:20 +0200 | [diff] [blame] | 5557 | |
Jonny Lamb | d73c694 | 2014-08-20 15:53:20 +0200 | [diff] [blame] | 5558 | get_output_work_area(shell, shsurf->output, &area); |
Giulio Camuffo | 7a8d67d | 2015-01-09 20:10:45 +0200 | [diff] [blame] | 5559 | if (shsurf->has_set_geometry) { |
| 5560 | surf_x = shsurf->geometry.x; |
| 5561 | surf_y = shsurf->geometry.y; |
| 5562 | } else { |
| 5563 | surface_subsurfaces_boundingbox(shsurf->surface, |
| 5564 | &surf_x, &surf_y, NULL, NULL); |
| 5565 | } |
Marek Chalupa | 8b771af | 2014-09-01 17:20:33 +0200 | [diff] [blame] | 5566 | e = pixman_region32_extents(&shsurf->output->region); |
Jonny Lamb | d73c694 | 2014-08-20 15:53:20 +0200 | [diff] [blame] | 5567 | |
| 5568 | weston_view_set_position(shsurf->view, |
Marek Chalupa | 8b771af | 2014-09-01 17:20:33 +0200 | [diff] [blame] | 5569 | e->x1 + area.x - surf_x, |
| 5570 | e->y1 + area.y - surf_y); |
Jonny Lamb | d73c694 | 2014-08-20 15:53:20 +0200 | [diff] [blame] | 5571 | } |
| 5572 | |
| 5573 | static void |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 5574 | map(struct desktop_shell *shell, struct shell_surface *shsurf, |
Jason Ekstrand | 918f2dd | 2013-12-02 21:01:53 -0600 | [diff] [blame] | 5575 | int32_t sx, int32_t sy) |
Kristian Høgsberg | 02ec0a5 | 2011-04-23 13:04:11 -0400 | [diff] [blame] | 5576 | { |
Kristian Høgsberg | 8334bc1 | 2012-01-03 10:29:47 -0500 | [diff] [blame] | 5577 | struct weston_compositor *compositor = shell->compositor; |
Daniel Stone | b210468 | 2012-05-30 16:31:56 +0100 | [diff] [blame] | 5578 | struct weston_seat *seat; |
Pekka Paalanen | 57da4a8 | 2011-11-23 16:42:16 +0200 | [diff] [blame] | 5579 | |
Pekka Paalanen | 77346a6 | 2011-11-30 16:26:35 +0200 | [diff] [blame] | 5580 | /* initial positioning, see also configure() */ |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 5581 | switch (shsurf->type) { |
Rafael Antognolli | ed207b4 | 2013-12-03 15:35:43 -0200 | [diff] [blame] | 5582 | case SHELL_SURFACE_TOPLEVEL: |
Rafael Antognolli | 03b1659 | 2013-12-03 15:35:42 -0200 | [diff] [blame] | 5583 | if (shsurf->state.fullscreen) { |
| 5584 | center_on_output(shsurf->view, shsurf->fullscreen_output); |
| 5585 | shell_map_fullscreen(shsurf); |
| 5586 | } else if (shsurf->state.maximized) { |
Jonny Lamb | d73c694 | 2014-08-20 15:53:20 +0200 | [diff] [blame] | 5587 | set_maximized_position(shell, shsurf); |
Rafael Antognolli | ed207b4 | 2013-12-03 15:35:43 -0200 | [diff] [blame] | 5588 | } else if (!shsurf->state.relative) { |
Rafael Antognolli | 03b1659 | 2013-12-03 15:35:42 -0200 | [diff] [blame] | 5589 | weston_view_set_initial_position(shsurf->view, shell); |
| 5590 | } |
Juan Zhao | 96879df | 2012-02-07 08:45:41 +0800 | [diff] [blame] | 5591 | break; |
Tiago Vignatti | 0f99701 | 2012-02-10 16:17:23 +0200 | [diff] [blame] | 5592 | case SHELL_SURFACE_POPUP: |
Jasper St. Pierre | da6ecd0 | 2015-02-27 18:35:45 +0800 | [diff] [blame] | 5593 | if (shell_map_popup(shsurf) != 0) |
| 5594 | return; |
Rob Bradford | db99938 | 2012-12-06 12:07:48 +0000 | [diff] [blame] | 5595 | break; |
Ander Conselvan de Oliveira | e9e0515 | 2012-02-15 17:02:56 +0200 | [diff] [blame] | 5596 | case SHELL_SURFACE_NONE: |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 5597 | weston_view_set_position(shsurf->view, |
| 5598 | shsurf->view->geometry.x + sx, |
| 5599 | shsurf->view->geometry.y + sy); |
Tiago Vignatti | 0f99701 | 2012-02-10 16:17:23 +0200 | [diff] [blame] | 5600 | break; |
Philip Withnall | 0f640e2 | 2013-11-25 18:01:31 +0000 | [diff] [blame] | 5601 | case SHELL_SURFACE_XWAYLAND: |
Pekka Paalanen | 77346a6 | 2011-11-30 16:26:35 +0200 | [diff] [blame] | 5602 | default: |
| 5603 | ; |
| 5604 | } |
Kristian Høgsberg | 7584062 | 2011-09-06 13:48:16 -0400 | [diff] [blame] | 5605 | |
Philip Withnall | e1d75ae | 2013-11-25 18:01:41 +0000 | [diff] [blame] | 5606 | /* Surface stacking order, see also activate(). */ |
| 5607 | shell_surface_update_layer(shsurf); |
Pekka Paalanen | f0fc70d | 2011-11-15 13:34:54 +0200 | [diff] [blame] | 5608 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 5609 | if (shsurf->type != SHELL_SURFACE_NONE) { |
| 5610 | weston_view_update_transform(shsurf->view); |
Rafael Antognolli | 03b1659 | 2013-12-03 15:35:42 -0200 | [diff] [blame] | 5611 | if (shsurf->state.maximized) { |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 5612 | shsurf->surface->output = shsurf->output; |
| 5613 | shsurf->view->output = shsurf->output; |
| 5614 | } |
Ander Conselvan de Oliveira | de56c31 | 2012-03-05 15:39:23 +0200 | [diff] [blame] | 5615 | } |
Kristian Høgsberg | 2f88a40 | 2011-12-04 15:32:59 -0500 | [diff] [blame] | 5616 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 5617 | switch (shsurf->type) { |
Tiago Vignatti | fb2adba | 2013-06-12 15:43:21 -0300 | [diff] [blame] | 5618 | /* XXX: xwayland's using the same fields for transient type */ |
| 5619 | case SHELL_SURFACE_XWAYLAND: |
Tiago Vignatti | 99aeb1e | 2012-05-23 22:06:26 +0300 | [diff] [blame] | 5620 | if (shsurf->transient.flags == |
| 5621 | WL_SHELL_SURFACE_TRANSIENT_INACTIVE) |
| 5622 | break; |
| 5623 | case SHELL_SURFACE_TOPLEVEL: |
Rafael Antognolli | ed207b4 | 2013-12-03 15:35:43 -0200 | [diff] [blame] | 5624 | if (shsurf->state.relative && |
| 5625 | shsurf->transient.flags == WL_SHELL_SURFACE_TRANSIENT_INACTIVE) |
| 5626 | break; |
Rafael Antognolli | ba5d2d7 | 2013-12-04 17:49:55 -0200 | [diff] [blame] | 5627 | if (shell->locked) |
Rafael Antognolli | ed207b4 | 2013-12-03 15:35:43 -0200 | [diff] [blame] | 5628 | break; |
| 5629 | wl_list_for_each(seat, &compositor->seat_list, link) |
Emilio Pozuelo Monfort | 9e7c759 | 2014-01-30 14:01:10 +0100 | [diff] [blame] | 5630 | activate(shell, shsurf->surface, seat, true); |
Juan Zhao | 7bb92f0 | 2011-12-15 11:31:51 -0500 | [diff] [blame] | 5631 | break; |
Philip Withnall | 0f640e2 | 2013-11-25 18:01:31 +0000 | [diff] [blame] | 5632 | case SHELL_SURFACE_POPUP: |
| 5633 | case SHELL_SURFACE_NONE: |
Juan Zhao | 7bb92f0 | 2011-12-15 11:31:51 -0500 | [diff] [blame] | 5634 | default: |
| 5635 | break; |
| 5636 | } |
| 5637 | |
Rafael Antognolli | 03b1659 | 2013-12-03 15:35:42 -0200 | [diff] [blame] | 5638 | if (shsurf->type == SHELL_SURFACE_TOPLEVEL && |
| 5639 | !shsurf->state.maximized && !shsurf->state.fullscreen) |
Juan Zhao | e10d279 | 2012-04-25 19:09:52 +0800 | [diff] [blame] | 5640 | { |
| 5641 | switch (shell->win_animation_type) { |
| 5642 | case ANIMATION_FADE: |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 5643 | 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] | 5644 | break; |
| 5645 | case ANIMATION_ZOOM: |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 5646 | weston_zoom_run(shsurf->view, 0.5, 1.0, NULL, NULL); |
Juan Zhao | e10d279 | 2012-04-25 19:09:52 +0800 | [diff] [blame] | 5647 | break; |
Philip Withnall | 4a86a0a | 2013-11-25 18:01:32 +0000 | [diff] [blame] | 5648 | case ANIMATION_NONE: |
Juan Zhao | e10d279 | 2012-04-25 19:09:52 +0800 | [diff] [blame] | 5649 | default: |
| 5650 | break; |
| 5651 | } |
| 5652 | } |
Kristian Høgsberg | 32e24cc | 2011-11-09 12:07:35 -0500 | [diff] [blame] | 5653 | } |
| 5654 | |
| 5655 | static void |
Tiago Vignatti | be14326 | 2012-04-16 17:31:41 +0300 | [diff] [blame] | 5656 | configure(struct desktop_shell *shell, struct weston_surface *surface, |
Jason Ekstrand | 918f2dd | 2013-12-02 21:01:53 -0600 | [diff] [blame] | 5657 | float x, float y) |
Kristian Høgsberg | 32e24cc | 2011-11-09 12:07:35 -0500 | [diff] [blame] | 5658 | { |
Pekka Paalanen | 77346a6 | 2011-11-30 16:26:35 +0200 | [diff] [blame] | 5659 | struct shell_surface *shsurf; |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 5660 | struct weston_view *view; |
Kristian Høgsberg | 32e24cc | 2011-11-09 12:07:35 -0500 | [diff] [blame] | 5661 | |
Pekka Paalanen | 77346a6 | 2011-11-30 16:26:35 +0200 | [diff] [blame] | 5662 | shsurf = get_shell_surface(surface); |
Pekka Paalanen | 77346a6 | 2011-11-30 16:26:35 +0200 | [diff] [blame] | 5663 | |
U. Artie Eoff | cf5737a | 2014-01-17 10:08:25 -0800 | [diff] [blame] | 5664 | assert(shsurf); |
| 5665 | |
Rafael Antognolli | 03b1659 | 2013-12-03 15:35:42 -0200 | [diff] [blame] | 5666 | if (shsurf->state.fullscreen) |
Alex Wu | 4539b08 | 2012-03-01 12:57:46 +0800 | [diff] [blame] | 5667 | shell_configure_fullscreen(shsurf); |
Rafael Antognolli | 03b1659 | 2013-12-03 15:35:42 -0200 | [diff] [blame] | 5668 | else if (shsurf->state.maximized) { |
Jonny Lamb | d73c694 | 2014-08-20 15:53:20 +0200 | [diff] [blame] | 5669 | set_maximized_position(shell, shsurf); |
Rafael Antognolli | 03b1659 | 2013-12-03 15:35:42 -0200 | [diff] [blame] | 5670 | } else { |
Jason Ekstrand | 918f2dd | 2013-12-02 21:01:53 -0600 | [diff] [blame] | 5671 | weston_view_set_position(shsurf->view, x, y); |
Kristian Høgsberg | 7a5c979 | 2011-06-18 06:12:54 -0400 | [diff] [blame] | 5672 | } |
Kristian Høgsberg | 32e24cc | 2011-11-09 12:07:35 -0500 | [diff] [blame] | 5673 | |
Alex Wu | 4539b08 | 2012-03-01 12:57:46 +0800 | [diff] [blame] | 5674 | /* XXX: would a fullscreen surface need the same handling? */ |
Kristian Høgsberg | 6a8b553 | 2012-02-16 23:43:59 -0500 | [diff] [blame] | 5675 | if (surface->output) { |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 5676 | wl_list_for_each(view, &surface->views, surface_link) |
| 5677 | weston_view_update_transform(view); |
Pekka Paalanen | 77346a6 | 2011-11-30 16:26:35 +0200 | [diff] [blame] | 5678 | |
Rafael Antognolli | 03b1659 | 2013-12-03 15:35:42 -0200 | [diff] [blame] | 5679 | if (shsurf->state.maximized) |
Juan Zhao | 96879df | 2012-02-07 08:45:41 +0800 | [diff] [blame] | 5680 | surface->output = shsurf->output; |
Pekka Paalanen | 77346a6 | 2011-11-30 16:26:35 +0200 | [diff] [blame] | 5681 | } |
Kristian Høgsberg | 0793756 | 2011-04-12 17:25:42 -0400 | [diff] [blame] | 5682 | } |
| 5683 | |
Ander Conselvan de Oliveira | 093bfa3 | 2012-03-27 17:36:41 +0300 | [diff] [blame] | 5684 | static void |
Jason Ekstrand | 918f2dd | 2013-12-02 21:01:53 -0600 | [diff] [blame] | 5685 | 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] | 5686 | { |
Ander Conselvan de Oliveira | 7fb9f95 | 2012-03-27 17:36:42 +0300 | [diff] [blame] | 5687 | struct shell_surface *shsurf = get_shell_surface(es); |
U. Artie Eoff | cf5737a | 2014-01-17 10:08:25 -0800 | [diff] [blame] | 5688 | struct desktop_shell *shell; |
Tiago Vignatti | 70e5c9c | 2012-05-07 15:23:07 +0300 | [diff] [blame] | 5689 | int type_changed = 0; |
Ander Conselvan de Oliveira | 093bfa3 | 2012-03-27 17:36:41 +0300 | [diff] [blame] | 5690 | |
U. Artie Eoff | cf5737a | 2014-01-17 10:08:25 -0800 | [diff] [blame] | 5691 | assert(shsurf); |
| 5692 | |
| 5693 | shell = shsurf->shell; |
| 5694 | |
Kristian Høgsberg | 8eb0f4f | 2013-06-17 10:33:14 -0400 | [diff] [blame] | 5695 | if (!weston_surface_is_mapped(es) && |
| 5696 | !wl_list_empty(&shsurf->popup.grab_link)) { |
Giulio Camuffo | 5085a75 | 2013-03-25 21:42:45 +0100 | [diff] [blame] | 5697 | remove_popup_grab(shsurf); |
| 5698 | } |
| 5699 | |
Jason Ekstrand | 918f2dd | 2013-12-02 21:01:53 -0600 | [diff] [blame] | 5700 | if (es->width == 0) |
Giulio Camuffo | 184df50 | 2013-02-21 11:29:21 +0100 | [diff] [blame] | 5701 | return; |
| 5702 | |
Jasper St. Pierre | ccf48fb | 2014-05-02 10:21:38 -0400 | [diff] [blame] | 5703 | if (shsurf->has_next_geometry) { |
| 5704 | shsurf->geometry = shsurf->next_geometry; |
| 5705 | shsurf->has_next_geometry = false; |
| 5706 | shsurf->has_set_geometry = true; |
| 5707 | } else if (!shsurf->has_set_geometry) { |
| 5708 | surface_subsurfaces_boundingbox(shsurf->surface, |
| 5709 | &shsurf->geometry.x, |
| 5710 | &shsurf->geometry.y, |
| 5711 | &shsurf->geometry.width, |
| 5712 | &shsurf->geometry.height); |
Jasper St. Pierre | 851799e | 2014-05-02 10:14:07 -0400 | [diff] [blame] | 5713 | } |
| 5714 | |
Kristian Høgsberg | c8f8dd8 | 2013-12-05 23:20:33 -0800 | [diff] [blame] | 5715 | if (shsurf->state_changed) { |
Kristian Høgsberg | 7f366e7 | 2012-04-27 17:20:01 -0400 | [diff] [blame] | 5716 | set_surface_type(shsurf); |
Kristian Høgsberg | f7e23d5 | 2012-04-27 17:51:59 -0400 | [diff] [blame] | 5717 | type_changed = 1; |
| 5718 | } |
Kristian Høgsberg | 7f366e7 | 2012-04-27 17:20:01 -0400 | [diff] [blame] | 5719 | |
Ander Conselvan de Oliveira | 093bfa3 | 2012-03-27 17:36:41 +0300 | [diff] [blame] | 5720 | if (!weston_surface_is_mapped(es)) { |
Jason Ekstrand | 918f2dd | 2013-12-02 21:01:53 -0600 | [diff] [blame] | 5721 | map(shell, shsurf, sx, sy); |
Kristian Høgsberg | f7e23d5 | 2012-04-27 17:51:59 -0400 | [diff] [blame] | 5722 | } else if (type_changed || sx != 0 || sy != 0 || |
Jason Ekstrand | 918f2dd | 2013-12-02 21:01:53 -0600 | [diff] [blame] | 5723 | shsurf->last_width != es->width || |
| 5724 | shsurf->last_height != es->height) { |
John Kåre Alsaker | 490d02a | 2012-09-30 02:57:21 +0200 | [diff] [blame] | 5725 | float from_x, from_y; |
| 5726 | float to_x, to_y; |
Ander Conselvan de Oliveira | 093bfa3 | 2012-03-27 17:36:41 +0300 | [diff] [blame] | 5727 | |
Kristian Høgsberg | 44cd196 | 2014-02-05 21:36:04 -0800 | [diff] [blame] | 5728 | if (shsurf->resize_edges) { |
| 5729 | sx = 0; |
| 5730 | sy = 0; |
| 5731 | } |
| 5732 | |
| 5733 | if (shsurf->resize_edges & WL_SHELL_SURFACE_RESIZE_LEFT) |
| 5734 | sx = shsurf->last_width - es->width; |
| 5735 | if (shsurf->resize_edges & WL_SHELL_SURFACE_RESIZE_TOP) |
| 5736 | sy = shsurf->last_height - es->height; |
| 5737 | |
| 5738 | shsurf->last_width = es->width; |
| 5739 | shsurf->last_height = es->height; |
| 5740 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 5741 | weston_view_to_global_float(shsurf->view, 0, 0, &from_x, &from_y); |
| 5742 | 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] | 5743 | configure(shell, es, |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 5744 | shsurf->view->geometry.x + to_x - from_x, |
Jason Ekstrand | 918f2dd | 2013-12-02 21:01:53 -0600 | [diff] [blame] | 5745 | shsurf->view->geometry.y + to_y - from_y); |
Ander Conselvan de Oliveira | 093bfa3 | 2012-03-27 17:36:41 +0300 | [diff] [blame] | 5746 | } |
| 5747 | } |
| 5748 | |
Pekka Paalanen | 2e62e4a | 2014-08-28 11:41:26 +0300 | [diff] [blame] | 5749 | static bool |
| 5750 | check_desktop_shell_crash_too_early(struct desktop_shell *shell) |
| 5751 | { |
| 5752 | struct timespec now; |
| 5753 | |
| 5754 | if (clock_gettime(CLOCK_MONOTONIC, &now) < 0) |
| 5755 | return false; |
| 5756 | |
| 5757 | /* |
| 5758 | * If the shell helper client dies before the session has been |
| 5759 | * up for roughly 30 seconds, better just make Weston shut down, |
| 5760 | * because the user likely has no way to interact with the desktop |
| 5761 | * anyway. |
| 5762 | */ |
| 5763 | if (now.tv_sec - shell->startup_time.tv_sec < 30) { |
| 5764 | weston_log("Error: %s apparently cannot run at all.\n", |
| 5765 | shell->client); |
| 5766 | weston_log_continue(STAMP_SPACE "Quitting..."); |
| 5767 | wl_display_terminate(shell->compositor->wl_display); |
| 5768 | |
| 5769 | return true; |
| 5770 | } |
| 5771 | |
| 5772 | return false; |
| 5773 | } |
| 5774 | |
Tiago Vignatti | b7dbbd6 | 2012-09-25 17:57:01 +0300 | [diff] [blame] | 5775 | static void launch_desktop_shell_process(void *data); |
Pekka Paalanen | 4d733ee | 2012-01-17 14:36:27 +0200 | [diff] [blame] | 5776 | |
Kristian Høgsberg | 97d44aa | 2011-08-26 17:21:20 -0400 | [diff] [blame] | 5777 | static void |
Pekka Paalanen | 826dc14 | 2014-08-27 12:11:53 +0300 | [diff] [blame] | 5778 | respawn_desktop_shell_process(struct desktop_shell *shell) |
Pekka Paalanen | 6cd281a | 2011-11-03 14:11:32 +0200 | [diff] [blame] | 5779 | { |
Pekka Paalanen | 4d733ee | 2012-01-17 14:36:27 +0200 | [diff] [blame] | 5780 | uint32_t time; |
Pekka Paalanen | 4d733ee | 2012-01-17 14:36:27 +0200 | [diff] [blame] | 5781 | |
| 5782 | /* if desktop-shell dies more than 5 times in 30 seconds, give up */ |
| 5783 | time = weston_compositor_get_time(); |
Kristian Høgsberg | f03a616 | 2012-01-17 11:07:42 -0500 | [diff] [blame] | 5784 | if (time - shell->child.deathstamp > 30000) { |
Pekka Paalanen | 4d733ee | 2012-01-17 14:36:27 +0200 | [diff] [blame] | 5785 | shell->child.deathstamp = time; |
| 5786 | shell->child.deathcount = 0; |
| 5787 | } |
| 5788 | |
| 5789 | shell->child.deathcount++; |
| 5790 | if (shell->child.deathcount > 5) { |
Pekka Paalanen | 826dc14 | 2014-08-27 12:11:53 +0300 | [diff] [blame] | 5791 | weston_log("%s disconnected, giving up.\n", shell->client); |
Pekka Paalanen | 4d733ee | 2012-01-17 14:36:27 +0200 | [diff] [blame] | 5792 | return; |
| 5793 | } |
| 5794 | |
Pekka Paalanen | 826dc14 | 2014-08-27 12:11:53 +0300 | [diff] [blame] | 5795 | weston_log("%s disconnected, respawning...\n", shell->client); |
Pekka Paalanen | 4d733ee | 2012-01-17 14:36:27 +0200 | [diff] [blame] | 5796 | launch_desktop_shell_process(shell); |
Pekka Paalanen | 6cd281a | 2011-11-03 14:11:32 +0200 | [diff] [blame] | 5797 | } |
| 5798 | |
Tiago Vignatti | b7dbbd6 | 2012-09-25 17:57:01 +0300 | [diff] [blame] | 5799 | static void |
Ander Conselvan de Oliveira | 312ea4c | 2013-12-20 21:07:01 +0200 | [diff] [blame] | 5800 | desktop_shell_client_destroy(struct wl_listener *listener, void *data) |
| 5801 | { |
| 5802 | struct desktop_shell *shell; |
| 5803 | |
| 5804 | shell = container_of(listener, struct desktop_shell, |
| 5805 | child.client_destroy_listener); |
| 5806 | |
Pekka Paalanen | 826dc14 | 2014-08-27 12:11:53 +0300 | [diff] [blame] | 5807 | wl_list_remove(&shell->child.client_destroy_listener.link); |
Ander Conselvan de Oliveira | 312ea4c | 2013-12-20 21:07:01 +0200 | [diff] [blame] | 5808 | shell->child.client = NULL; |
Pekka Paalanen | 826dc14 | 2014-08-27 12:11:53 +0300 | [diff] [blame] | 5809 | /* |
| 5810 | * unbind_desktop_shell() will reset shell->child.desktop_shell |
| 5811 | * before the respawned process has a chance to create a new |
| 5812 | * desktop_shell object, because we are being called from the |
| 5813 | * wl_client destructor which destroys all wl_resources before |
| 5814 | * returning. |
| 5815 | */ |
| 5816 | |
Pekka Paalanen | 2e62e4a | 2014-08-28 11:41:26 +0300 | [diff] [blame] | 5817 | if (!check_desktop_shell_crash_too_early(shell)) |
| 5818 | respawn_desktop_shell_process(shell); |
| 5819 | |
Pekka Paalanen | 826dc14 | 2014-08-27 12:11:53 +0300 | [diff] [blame] | 5820 | shell_fade_startup(shell); |
Ander Conselvan de Oliveira | 312ea4c | 2013-12-20 21:07:01 +0200 | [diff] [blame] | 5821 | } |
| 5822 | |
| 5823 | static void |
Tiago Vignatti | b7dbbd6 | 2012-09-25 17:57:01 +0300 | [diff] [blame] | 5824 | launch_desktop_shell_process(void *data) |
Pekka Paalanen | 6cd281a | 2011-11-03 14:11:32 +0200 | [diff] [blame] | 5825 | { |
Tiago Vignatti | b7dbbd6 | 2012-09-25 17:57:01 +0300 | [diff] [blame] | 5826 | struct desktop_shell *shell = data; |
Pekka Paalanen | 6cd281a | 2011-11-03 14:11:32 +0200 | [diff] [blame] | 5827 | |
Pekka Paalanen | 826dc14 | 2014-08-27 12:11:53 +0300 | [diff] [blame] | 5828 | shell->child.client = weston_client_start(shell->compositor, |
| 5829 | shell->client); |
Pekka Paalanen | 409ef0a | 2011-12-02 15:30:21 +0200 | [diff] [blame] | 5830 | |
Arnaud Vrac | 4263119 | 2014-08-25 20:56:46 +0200 | [diff] [blame] | 5831 | if (!shell->child.client) { |
Emilio Pozuelo Monfort | 46ce798 | 2013-11-20 13:22:29 +0100 | [diff] [blame] | 5832 | weston_log("not able to start %s\n", shell->client); |
Arnaud Vrac | 4263119 | 2014-08-25 20:56:46 +0200 | [diff] [blame] | 5833 | return; |
| 5834 | } |
Ander Conselvan de Oliveira | 312ea4c | 2013-12-20 21:07:01 +0200 | [diff] [blame] | 5835 | |
| 5836 | shell->child.client_destroy_listener.notify = |
| 5837 | desktop_shell_client_destroy; |
| 5838 | wl_client_add_destroy_listener(shell->child.client, |
| 5839 | &shell->child.client_destroy_listener); |
Pekka Paalanen | 6cd281a | 2011-11-03 14:11:32 +0200 | [diff] [blame] | 5840 | } |
| 5841 | |
| 5842 | static void |
Kristian Høgsberg | 2bff94e | 2014-02-11 12:22:51 -0800 | [diff] [blame] | 5843 | handle_shell_client_destroy(struct wl_listener *listener, void *data) |
| 5844 | { |
| 5845 | struct shell_client *sc = |
| 5846 | container_of(listener, struct shell_client, destroy_listener); |
| 5847 | |
| 5848 | if (sc->ping_timer) |
| 5849 | wl_event_source_remove(sc->ping_timer); |
Derek Foreman | e42d754 | 2015-05-29 10:46:44 -0500 | [diff] [blame] | 5850 | |
| 5851 | /* Since we're about to free shell_client, we remove it from the |
| 5852 | * head of the surface list so we don't use that freed list node |
| 5853 | * during surface clean up later on. |
| 5854 | */ |
| 5855 | wl_list_remove(&sc->surface_list); |
| 5856 | |
Kristian Høgsberg | 2bff94e | 2014-02-11 12:22:51 -0800 | [diff] [blame] | 5857 | free(sc); |
| 5858 | } |
| 5859 | |
Kristian Høgsberg | dd62aba | 2014-02-12 09:56:19 -0800 | [diff] [blame] | 5860 | static struct shell_client * |
| 5861 | shell_client_create(struct wl_client *client, struct desktop_shell *shell, |
| 5862 | const struct wl_interface *interface, uint32_t id) |
Rafael Antognolli | e2a3455 | 2013-12-03 15:35:45 -0200 | [diff] [blame] | 5863 | { |
Kristian Høgsberg | 2bff94e | 2014-02-11 12:22:51 -0800 | [diff] [blame] | 5864 | struct shell_client *sc; |
Rafael Antognolli | e2a3455 | 2013-12-03 15:35:45 -0200 | [diff] [blame] | 5865 | |
Kristian Høgsberg | 2bff94e | 2014-02-11 12:22:51 -0800 | [diff] [blame] | 5866 | sc = zalloc(sizeof *sc); |
| 5867 | if (sc == NULL) { |
| 5868 | wl_client_post_no_memory(client); |
Kristian Høgsberg | dd62aba | 2014-02-12 09:56:19 -0800 | [diff] [blame] | 5869 | return NULL; |
Kristian Høgsberg | 2bff94e | 2014-02-11 12:22:51 -0800 | [diff] [blame] | 5870 | } |
Kristian Høgsberg | dd62aba | 2014-02-12 09:56:19 -0800 | [diff] [blame] | 5871 | |
| 5872 | sc->resource = wl_resource_create(client, interface, 1, id); |
Kristian Høgsberg | 2bff94e | 2014-02-11 12:22:51 -0800 | [diff] [blame] | 5873 | if (sc->resource == NULL) { |
| 5874 | free(sc); |
| 5875 | wl_client_post_no_memory(client); |
Kristian Høgsberg | dd62aba | 2014-02-12 09:56:19 -0800 | [diff] [blame] | 5876 | return NULL; |
Kristian Høgsberg | 2bff94e | 2014-02-11 12:22:51 -0800 | [diff] [blame] | 5877 | } |
| 5878 | |
| 5879 | sc->client = client; |
| 5880 | sc->shell = shell; |
| 5881 | sc->destroy_listener.notify = handle_shell_client_destroy; |
| 5882 | wl_client_add_destroy_listener(client, &sc->destroy_listener); |
Jonas Ådahl | 49d77d2 | 2015-03-18 16:20:51 +0800 | [diff] [blame] | 5883 | wl_list_init(&sc->surface_list); |
Kristian Høgsberg | 2bff94e | 2014-02-11 12:22:51 -0800 | [diff] [blame] | 5884 | |
Kristian Høgsberg | dd62aba | 2014-02-12 09:56:19 -0800 | [diff] [blame] | 5885 | return sc; |
| 5886 | } |
| 5887 | |
| 5888 | static void |
| 5889 | bind_shell(struct wl_client *client, void *data, uint32_t version, uint32_t id) |
| 5890 | { |
| 5891 | struct desktop_shell *shell = data; |
| 5892 | struct shell_client *sc; |
| 5893 | |
| 5894 | sc = shell_client_create(client, shell, &wl_shell_interface, id); |
| 5895 | if (sc) |
| 5896 | wl_resource_set_implementation(sc->resource, |
| 5897 | &shell_implementation, |
Jason Ekstrand | 9e9512f | 2014-04-16 21:12:10 -0500 | [diff] [blame] | 5898 | sc, NULL); |
Kristian Høgsberg | dd62aba | 2014-02-12 09:56:19 -0800 | [diff] [blame] | 5899 | } |
| 5900 | |
| 5901 | static void |
| 5902 | bind_xdg_shell(struct wl_client *client, void *data, uint32_t version, uint32_t id) |
| 5903 | { |
| 5904 | struct desktop_shell *shell = data; |
| 5905 | struct shell_client *sc; |
| 5906 | |
| 5907 | sc = shell_client_create(client, shell, &xdg_shell_interface, id); |
| 5908 | if (sc) |
| 5909 | wl_resource_set_dispatcher(sc->resource, |
| 5910 | xdg_shell_unversioned_dispatch, |
| 5911 | NULL, sc, NULL); |
Rafael Antognolli | e2a3455 | 2013-12-03 15:35:45 -0200 | [diff] [blame] | 5912 | } |
| 5913 | |
| 5914 | static void |
Pekka Paalanen | 9ef3e01 | 2011-11-15 13:34:48 +0200 | [diff] [blame] | 5915 | unbind_desktop_shell(struct wl_resource *resource) |
| 5916 | { |
Jason Ekstrand | 651f00e | 2013-06-14 10:07:54 -0500 | [diff] [blame] | 5917 | struct desktop_shell *shell = wl_resource_get_user_data(resource); |
Kristian Høgsberg | 1ec0c31 | 2011-11-15 16:39:55 -0500 | [diff] [blame] | 5918 | |
| 5919 | if (shell->locked) |
| 5920 | resume_desktop(shell); |
| 5921 | |
Pekka Paalanen | 9ef3e01 | 2011-11-15 13:34:48 +0200 | [diff] [blame] | 5922 | shell->child.desktop_shell = NULL; |
| 5923 | shell->prepare_event_sent = false; |
Pekka Paalanen | 9ef3e01 | 2011-11-15 13:34:48 +0200 | [diff] [blame] | 5924 | } |
| 5925 | |
| 5926 | static void |
Kristian Høgsberg | 7584062 | 2011-09-06 13:48:16 -0400 | [diff] [blame] | 5927 | bind_desktop_shell(struct wl_client *client, |
| 5928 | void *data, uint32_t version, uint32_t id) |
| 5929 | { |
Tiago Vignatti | be14326 | 2012-04-16 17:31:41 +0300 | [diff] [blame] | 5930 | struct desktop_shell *shell = data; |
Pekka Paalanen | bbe6052 | 2011-11-03 14:11:33 +0200 | [diff] [blame] | 5931 | struct wl_resource *resource; |
Kristian Høgsberg | 7584062 | 2011-09-06 13:48:16 -0400 | [diff] [blame] | 5932 | |
Jason Ekstrand | a85118c | 2013-06-27 20:17:02 -0500 | [diff] [blame] | 5933 | resource = wl_resource_create(client, &desktop_shell_interface, |
Jonny Lamb | 765760d | 2014-08-20 15:53:19 +0200 | [diff] [blame] | 5934 | MIN(version, 3), id); |
Pekka Paalanen | bbe6052 | 2011-11-03 14:11:33 +0200 | [diff] [blame] | 5935 | |
Pekka Paalanen | 9ef3e01 | 2011-11-15 13:34:48 +0200 | [diff] [blame] | 5936 | if (client == shell->child.client) { |
Jason Ekstrand | a85118c | 2013-06-27 20:17:02 -0500 | [diff] [blame] | 5937 | wl_resource_set_implementation(resource, |
| 5938 | &desktop_shell_implementation, |
| 5939 | shell, unbind_desktop_shell); |
Pekka Paalanen | 9ef3e01 | 2011-11-15 13:34:48 +0200 | [diff] [blame] | 5940 | shell->child.desktop_shell = resource; |
Pekka Paalanen | 79346ab | 2013-05-22 18:03:09 +0300 | [diff] [blame] | 5941 | |
| 5942 | if (version < 2) |
| 5943 | shell_fade_startup(shell); |
| 5944 | |
Pekka Paalanen | bbe6052 | 2011-11-03 14:11:33 +0200 | [diff] [blame] | 5945 | return; |
Pekka Paalanen | 9ef3e01 | 2011-11-15 13:34:48 +0200 | [diff] [blame] | 5946 | } |
Pekka Paalanen | bbe6052 | 2011-11-03 14:11:33 +0200 | [diff] [blame] | 5947 | |
| 5948 | wl_resource_post_error(resource, WL_DISPLAY_ERROR_INVALID_OBJECT, |
| 5949 | "permission to bind desktop_shell denied"); |
Kristian Høgsberg | 7584062 | 2011-09-06 13:48:16 -0400 | [diff] [blame] | 5950 | } |
| 5951 | |
Kristian Høgsberg | 0704539 | 2012-02-19 18:52:44 -0500 | [diff] [blame] | 5952 | struct switcher { |
Tiago Vignatti | be14326 | 2012-04-16 17:31:41 +0300 | [diff] [blame] | 5953 | struct desktop_shell *shell; |
Kristian Høgsberg | 0704539 | 2012-02-19 18:52:44 -0500 | [diff] [blame] | 5954 | struct weston_surface *current; |
| 5955 | struct wl_listener listener; |
Kristian Høgsberg | 29139d4 | 2013-04-18 15:25:39 -0400 | [diff] [blame] | 5956 | struct weston_keyboard_grab grab; |
Manuel Bachmann | c1ae2e8 | 2014-02-26 15:53:11 +0100 | [diff] [blame] | 5957 | struct wl_array minimized_array; |
Kristian Høgsberg | 0704539 | 2012-02-19 18:52:44 -0500 | [diff] [blame] | 5958 | }; |
| 5959 | |
| 5960 | static void |
| 5961 | switcher_next(struct switcher *switcher) |
| 5962 | { |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 5963 | struct weston_view *view; |
Kristian Høgsberg | 0704539 | 2012-02-19 18:52:44 -0500 | [diff] [blame] | 5964 | struct weston_surface *first = NULL, *prev = NULL, *next = NULL; |
Kristian Høgsberg | 32e5686 | 2012-04-02 22:18:58 -0400 | [diff] [blame] | 5965 | struct shell_surface *shsurf; |
Kristian Høgsberg | b0d8e77 | 2012-06-18 16:34:58 -0400 | [diff] [blame] | 5966 | struct workspace *ws = get_current_workspace(switcher->shell); |
Kristian Høgsberg | 0704539 | 2012-02-19 18:52:44 -0500 | [diff] [blame] | 5967 | |
Manuel Bachmann | c1ae2e8 | 2014-02-26 15:53:11 +0100 | [diff] [blame] | 5968 | /* temporary re-display minimized surfaces */ |
| 5969 | struct weston_view *tmp; |
| 5970 | struct weston_view **minimized; |
Giulio Camuffo | 412e6a5 | 2014-07-09 22:12:56 +0300 | [diff] [blame] | 5971 | wl_list_for_each_safe(view, tmp, &switcher->shell->minimized_layer.view_list.link, layer_link.link) { |
| 5972 | weston_layer_entry_remove(&view->layer_link); |
| 5973 | weston_layer_entry_insert(&ws->layer.view_list, &view->layer_link); |
Manuel Bachmann | c1ae2e8 | 2014-02-26 15:53:11 +0100 | [diff] [blame] | 5974 | minimized = wl_array_add(&switcher->minimized_array, sizeof *minimized); |
| 5975 | *minimized = view; |
| 5976 | } |
| 5977 | |
Giulio Camuffo | 412e6a5 | 2014-07-09 22:12:56 +0300 | [diff] [blame] | 5978 | wl_list_for_each(view, &ws->layer.view_list.link, layer_link.link) { |
Rafael Antognolli | ed207b4 | 2013-12-03 15:35:43 -0200 | [diff] [blame] | 5979 | shsurf = get_shell_surface(view->surface); |
Rafael Antognolli | 5031cbe | 2013-12-05 19:01:21 -0200 | [diff] [blame] | 5980 | if (shsurf && |
| 5981 | shsurf->type == SHELL_SURFACE_TOPLEVEL && |
| 5982 | shsurf->parent == NULL) { |
Kristian Høgsberg | 0704539 | 2012-02-19 18:52:44 -0500 | [diff] [blame] | 5983 | if (first == NULL) |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 5984 | first = view->surface; |
Kristian Høgsberg | 0704539 | 2012-02-19 18:52:44 -0500 | [diff] [blame] | 5985 | if (prev == switcher->current) |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 5986 | next = view->surface; |
| 5987 | prev = view->surface; |
| 5988 | view->alpha = 0.25; |
| 5989 | weston_view_geometry_dirty(view); |
| 5990 | weston_surface_damage(view->surface); |
Kristian Høgsberg | 0704539 | 2012-02-19 18:52:44 -0500 | [diff] [blame] | 5991 | } |
Alex Wu | 1659daa | 2012-04-01 20:13:09 +0800 | [diff] [blame] | 5992 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 5993 | if (is_black_surface(view->surface, NULL)) { |
| 5994 | view->alpha = 0.25; |
| 5995 | weston_view_geometry_dirty(view); |
| 5996 | weston_surface_damage(view->surface); |
Alex Wu | 1659daa | 2012-04-01 20:13:09 +0800 | [diff] [blame] | 5997 | } |
Kristian Høgsberg | 0704539 | 2012-02-19 18:52:44 -0500 | [diff] [blame] | 5998 | } |
| 5999 | |
| 6000 | if (next == NULL) |
| 6001 | next = first; |
| 6002 | |
Alex Wu | 07b2606 | 2012-03-12 16:06:01 +0800 | [diff] [blame] | 6003 | if (next == NULL) |
| 6004 | return; |
| 6005 | |
Kristian Høgsberg | 0704539 | 2012-02-19 18:52:44 -0500 | [diff] [blame] | 6006 | wl_list_remove(&switcher->listener.link); |
Jason Ekstrand | 26ed73c | 2013-06-06 22:34:41 -0500 | [diff] [blame] | 6007 | wl_signal_add(&next->destroy_signal, &switcher->listener); |
Kristian Høgsberg | 0704539 | 2012-02-19 18:52:44 -0500 | [diff] [blame] | 6008 | |
| 6009 | switcher->current = next; |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 6010 | wl_list_for_each(view, &next->views, surface_link) |
| 6011 | view->alpha = 1.0; |
Alex Wu | 1659daa | 2012-04-01 20:13:09 +0800 | [diff] [blame] | 6012 | |
Kristian Høgsberg | 32e5686 | 2012-04-02 22:18:58 -0400 | [diff] [blame] | 6013 | shsurf = get_shell_surface(switcher->current); |
Rafael Antognolli | 03b1659 | 2013-12-03 15:35:42 -0200 | [diff] [blame] | 6014 | if (shsurf && shsurf->state.fullscreen) |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 6015 | shsurf->fullscreen.black_view->alpha = 1.0; |
Kristian Høgsberg | 0704539 | 2012-02-19 18:52:44 -0500 | [diff] [blame] | 6016 | } |
| 6017 | |
| 6018 | static void |
Kristian Høgsberg | 27e3052 | 2012-04-11 23:18:23 -0400 | [diff] [blame] | 6019 | switcher_handle_surface_destroy(struct wl_listener *listener, void *data) |
Kristian Høgsberg | 0704539 | 2012-02-19 18:52:44 -0500 | [diff] [blame] | 6020 | { |
| 6021 | struct switcher *switcher = |
| 6022 | container_of(listener, struct switcher, listener); |
| 6023 | |
| 6024 | switcher_next(switcher); |
| 6025 | } |
| 6026 | |
| 6027 | static void |
Daniel Stone | 351eb61 | 2012-05-31 15:27:47 -0400 | [diff] [blame] | 6028 | switcher_destroy(struct switcher *switcher) |
Kristian Høgsberg | 0704539 | 2012-02-19 18:52:44 -0500 | [diff] [blame] | 6029 | { |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 6030 | struct weston_view *view; |
Kristian Høgsberg | 29139d4 | 2013-04-18 15:25:39 -0400 | [diff] [blame] | 6031 | struct weston_keyboard *keyboard = switcher->grab.keyboard; |
Kristian Høgsberg | b0d8e77 | 2012-06-18 16:34:58 -0400 | [diff] [blame] | 6032 | struct workspace *ws = get_current_workspace(switcher->shell); |
Kristian Høgsberg | 0704539 | 2012-02-19 18:52:44 -0500 | [diff] [blame] | 6033 | |
Giulio Camuffo | 412e6a5 | 2014-07-09 22:12:56 +0300 | [diff] [blame] | 6034 | 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] | 6035 | if (is_focus_view(view)) |
| 6036 | continue; |
| 6037 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 6038 | view->alpha = 1.0; |
| 6039 | weston_surface_damage(view->surface); |
Kristian Høgsberg | 0704539 | 2012-02-19 18:52:44 -0500 | [diff] [blame] | 6040 | } |
| 6041 | |
Alex Wu | 07b2606 | 2012-03-12 16:06:01 +0800 | [diff] [blame] | 6042 | if (switcher->current) |
Daniel Stone | 37816df | 2012-05-16 18:45:18 +0100 | [diff] [blame] | 6043 | activate(switcher->shell, switcher->current, |
Derek Foreman | 8aeeac8 | 2015-01-30 13:24:36 -0600 | [diff] [blame] | 6044 | keyboard->seat, true); |
Kristian Høgsberg | 0704539 | 2012-02-19 18:52:44 -0500 | [diff] [blame] | 6045 | wl_list_remove(&switcher->listener.link); |
Kristian Høgsberg | 29139d4 | 2013-04-18 15:25:39 -0400 | [diff] [blame] | 6046 | weston_keyboard_end_grab(keyboard); |
| 6047 | if (keyboard->input_method_resource) |
| 6048 | keyboard->grab = &keyboard->input_method_grab; |
Manuel Bachmann | c1ae2e8 | 2014-02-26 15:53:11 +0100 | [diff] [blame] | 6049 | |
| 6050 | /* re-hide surfaces that were temporary shown during the switch */ |
| 6051 | struct weston_view **minimized; |
| 6052 | wl_array_for_each(minimized, &switcher->minimized_array) { |
| 6053 | /* with the exception of the current selected */ |
| 6054 | if ((*minimized)->surface != switcher->current) { |
Giulio Camuffo | 412e6a5 | 2014-07-09 22:12:56 +0300 | [diff] [blame] | 6055 | weston_layer_entry_remove(&(*minimized)->layer_link); |
| 6056 | 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] | 6057 | weston_view_damage_below(*minimized); |
| 6058 | } |
| 6059 | } |
| 6060 | wl_array_release(&switcher->minimized_array); |
| 6061 | |
Kristian Høgsberg | 0704539 | 2012-02-19 18:52:44 -0500 | [diff] [blame] | 6062 | free(switcher); |
| 6063 | } |
| 6064 | |
| 6065 | static void |
Kristian Høgsberg | 29139d4 | 2013-04-18 15:25:39 -0400 | [diff] [blame] | 6066 | switcher_key(struct weston_keyboard_grab *grab, |
Daniel Stone | c9785ea | 2012-05-30 16:31:52 +0100 | [diff] [blame] | 6067 | uint32_t time, uint32_t key, uint32_t state_w) |
Kristian Høgsberg | 0704539 | 2012-02-19 18:52:44 -0500 | [diff] [blame] | 6068 | { |
| 6069 | struct switcher *switcher = container_of(grab, struct switcher, grab); |
Daniel Stone | c9785ea | 2012-05-30 16:31:52 +0100 | [diff] [blame] | 6070 | enum wl_keyboard_key_state state = state_w; |
Daniel Stone | 351eb61 | 2012-05-31 15:27:47 -0400 | [diff] [blame] | 6071 | |
Daniel Stone | c9785ea | 2012-05-30 16:31:52 +0100 | [diff] [blame] | 6072 | if (key == KEY_TAB && state == WL_KEYBOARD_KEY_STATE_PRESSED) |
Daniel Stone | 351eb61 | 2012-05-31 15:27:47 -0400 | [diff] [blame] | 6073 | switcher_next(switcher); |
| 6074 | } |
| 6075 | |
| 6076 | static void |
Kristian Høgsberg | 29139d4 | 2013-04-18 15:25:39 -0400 | [diff] [blame] | 6077 | switcher_modifier(struct weston_keyboard_grab *grab, uint32_t serial, |
Daniel Stone | 351eb61 | 2012-05-31 15:27:47 -0400 | [diff] [blame] | 6078 | uint32_t mods_depressed, uint32_t mods_latched, |
| 6079 | uint32_t mods_locked, uint32_t group) |
| 6080 | { |
| 6081 | struct switcher *switcher = container_of(grab, struct switcher, grab); |
Derek Foreman | 8aeeac8 | 2015-01-30 13:24:36 -0600 | [diff] [blame] | 6082 | struct weston_seat *seat = grab->keyboard->seat; |
Kristian Høgsberg | 0704539 | 2012-02-19 18:52:44 -0500 | [diff] [blame] | 6083 | |
Daniel Stone | 351eb61 | 2012-05-31 15:27:47 -0400 | [diff] [blame] | 6084 | if ((seat->modifier_state & switcher->shell->binding_modifier) == 0) |
| 6085 | switcher_destroy(switcher); |
Kristian Høgsberg | b71302e | 2012-05-10 12:28:35 -0400 | [diff] [blame] | 6086 | } |
Kristian Høgsberg | 0704539 | 2012-02-19 18:52:44 -0500 | [diff] [blame] | 6087 | |
Jonas Ådahl | 1ea343e | 2013-10-25 23:18:05 +0200 | [diff] [blame] | 6088 | static void |
| 6089 | switcher_cancel(struct weston_keyboard_grab *grab) |
| 6090 | { |
| 6091 | struct switcher *switcher = container_of(grab, struct switcher, grab); |
| 6092 | |
| 6093 | switcher_destroy(switcher); |
| 6094 | } |
| 6095 | |
Kristian Høgsberg | 29139d4 | 2013-04-18 15:25:39 -0400 | [diff] [blame] | 6096 | static const struct weston_keyboard_grab_interface switcher_grab = { |
Daniel Stone | 351eb61 | 2012-05-31 15:27:47 -0400 | [diff] [blame] | 6097 | switcher_key, |
| 6098 | switcher_modifier, |
Jonas Ådahl | 1ea343e | 2013-10-25 23:18:05 +0200 | [diff] [blame] | 6099 | switcher_cancel, |
Kristian Høgsberg | 0704539 | 2012-02-19 18:52:44 -0500 | [diff] [blame] | 6100 | }; |
| 6101 | |
| 6102 | static void |
Derek Foreman | 8ae2db5 | 2015-07-15 13:00:36 -0500 | [diff] [blame] | 6103 | switcher_binding(struct weston_keyboard *keyboard, uint32_t time, |
| 6104 | uint32_t key, void *data) |
Kristian Høgsberg | 0704539 | 2012-02-19 18:52:44 -0500 | [diff] [blame] | 6105 | { |
Tiago Vignatti | be14326 | 2012-04-16 17:31:41 +0300 | [diff] [blame] | 6106 | struct desktop_shell *shell = data; |
Kristian Høgsberg | 0704539 | 2012-02-19 18:52:44 -0500 | [diff] [blame] | 6107 | struct switcher *switcher; |
| 6108 | |
| 6109 | switcher = malloc(sizeof *switcher); |
Kristian Høgsberg | 02e79dc | 2012-04-12 09:55:26 -0400 | [diff] [blame] | 6110 | switcher->shell = shell; |
Kristian Høgsberg | 0704539 | 2012-02-19 18:52:44 -0500 | [diff] [blame] | 6111 | switcher->current = NULL; |
Kristian Høgsberg | 27e3052 | 2012-04-11 23:18:23 -0400 | [diff] [blame] | 6112 | switcher->listener.notify = switcher_handle_surface_destroy; |
Kristian Høgsberg | 0704539 | 2012-02-19 18:52:44 -0500 | [diff] [blame] | 6113 | wl_list_init(&switcher->listener.link); |
Manuel Bachmann | c1ae2e8 | 2014-02-26 15:53:11 +0100 | [diff] [blame] | 6114 | wl_array_init(&switcher->minimized_array); |
Kristian Høgsberg | 0704539 | 2012-02-19 18:52:44 -0500 | [diff] [blame] | 6115 | |
Alexander Larsson | f82b6ca | 2013-05-28 16:23:39 +0200 | [diff] [blame] | 6116 | restore_all_output_modes(shell->compositor); |
Mario Kleiner | 9f4d655 | 2015-06-21 21:25:08 +0200 | [diff] [blame] | 6117 | lower_fullscreen_layer(switcher->shell, NULL); |
Kristian Høgsberg | 0704539 | 2012-02-19 18:52:44 -0500 | [diff] [blame] | 6118 | switcher->grab.interface = &switcher_grab; |
Derek Foreman | 8ae2db5 | 2015-07-15 13:00:36 -0500 | [diff] [blame] | 6119 | weston_keyboard_start_grab(keyboard, &switcher->grab); |
| 6120 | weston_keyboard_set_focus(keyboard, NULL); |
Kristian Høgsberg | 0704539 | 2012-02-19 18:52:44 -0500 | [diff] [blame] | 6121 | switcher_next(switcher); |
| 6122 | } |
| 6123 | |
Pekka Paalanen | 3c64723 | 2011-12-22 13:43:43 +0200 | [diff] [blame] | 6124 | static void |
Derek Foreman | 8ae2db5 | 2015-07-15 13:00:36 -0500 | [diff] [blame] | 6125 | backlight_binding(struct weston_keyboard *keyboard, uint32_t time, |
| 6126 | uint32_t key, void *data) |
Tiago Vignatti | 8e53c7f | 2012-02-29 19:53:50 +0200 | [diff] [blame] | 6127 | { |
| 6128 | struct weston_compositor *compositor = data; |
| 6129 | struct weston_output *output; |
Tiago Vignatti | 5ab91ad | 2012-03-12 19:40:09 -0300 | [diff] [blame] | 6130 | long backlight_new = 0; |
Tiago Vignatti | 8e53c7f | 2012-02-29 19:53:50 +0200 | [diff] [blame] | 6131 | |
| 6132 | /* TODO: we're limiting to simple use cases, where we assume just |
| 6133 | * control on the primary display. We'd have to extend later if we |
| 6134 | * ever get support for setting backlights on random desktop LCD |
| 6135 | * panels though */ |
| 6136 | output = get_default_output(compositor); |
| 6137 | if (!output) |
| 6138 | return; |
| 6139 | |
| 6140 | if (!output->set_backlight) |
| 6141 | return; |
| 6142 | |
Tiago Vignatti | 5ab91ad | 2012-03-12 19:40:09 -0300 | [diff] [blame] | 6143 | if (key == KEY_F9 || key == KEY_BRIGHTNESSDOWN) |
| 6144 | backlight_new = output->backlight_current - 25; |
| 6145 | else if (key == KEY_F10 || key == KEY_BRIGHTNESSUP) |
| 6146 | backlight_new = output->backlight_current + 25; |
Tiago Vignatti | 8e53c7f | 2012-02-29 19:53:50 +0200 | [diff] [blame] | 6147 | |
Tiago Vignatti | 5ab91ad | 2012-03-12 19:40:09 -0300 | [diff] [blame] | 6148 | if (backlight_new < 5) |
| 6149 | backlight_new = 5; |
| 6150 | if (backlight_new > 255) |
| 6151 | backlight_new = 255; |
| 6152 | |
| 6153 | output->backlight_current = backlight_new; |
Tiago Vignatti | 8e53c7f | 2012-02-29 19:53:50 +0200 | [diff] [blame] | 6154 | output->set_backlight(output, output->backlight_current); |
| 6155 | } |
| 6156 | |
Kristian Høgsberg | b41c081 | 2012-03-04 14:53:40 -0500 | [diff] [blame] | 6157 | static void |
Derek Foreman | 8ae2db5 | 2015-07-15 13:00:36 -0500 | [diff] [blame] | 6158 | force_kill_binding(struct weston_keyboard *keyboard, uint32_t time, |
| 6159 | uint32_t key, void *data) |
Kristian Høgsberg | 92a57db | 2012-05-26 13:41:06 -0400 | [diff] [blame] | 6160 | { |
Kristian Høgsberg | fe7aa90 | 2013-05-08 09:54:37 -0400 | [diff] [blame] | 6161 | struct weston_surface *focus_surface; |
Kristian Høgsberg | 92a57db | 2012-05-26 13:41:06 -0400 | [diff] [blame] | 6162 | struct wl_client *client; |
Tiago Vignatti | 1d01b01 | 2012-09-27 17:48:36 +0300 | [diff] [blame] | 6163 | struct desktop_shell *shell = data; |
| 6164 | struct weston_compositor *compositor = shell->compositor; |
Kristian Høgsberg | 92a57db | 2012-05-26 13:41:06 -0400 | [diff] [blame] | 6165 | pid_t pid; |
Kristian Høgsberg | 92a57db | 2012-05-26 13:41:06 -0400 | [diff] [blame] | 6166 | |
Derek Foreman | 8ae2db5 | 2015-07-15 13:00:36 -0500 | [diff] [blame] | 6167 | focus_surface = keyboard->focus; |
Philipp Brüschweiler | 6cef009 | 2012-08-13 21:27:27 +0200 | [diff] [blame] | 6168 | if (!focus_surface) |
| 6169 | return; |
| 6170 | |
Tiago Vignatti | 1d01b01 | 2012-09-27 17:48:36 +0300 | [diff] [blame] | 6171 | wl_signal_emit(&compositor->kill_signal, focus_surface); |
| 6172 | |
Jason Ekstrand | 26ed73c | 2013-06-06 22:34:41 -0500 | [diff] [blame] | 6173 | client = wl_resource_get_client(focus_surface->resource); |
Tiago Vignatti | 920f197 | 2012-09-27 17:48:35 +0300 | [diff] [blame] | 6174 | wl_client_get_credentials(client, &pid, NULL, NULL); |
| 6175 | |
| 6176 | /* Skip clients that we launched ourselves (the credentials of |
| 6177 | * the socketpair is ours) */ |
| 6178 | if (pid == getpid()) |
| 6179 | return; |
Kristian Høgsberg | 92a57db | 2012-05-26 13:41:06 -0400 | [diff] [blame] | 6180 | |
Daniel Stone | 325fc2d | 2012-05-30 16:31:58 +0100 | [diff] [blame] | 6181 | kill(pid, SIGKILL); |
Kristian Høgsberg | 92a57db | 2012-05-26 13:41:06 -0400 | [diff] [blame] | 6182 | } |
| 6183 | |
| 6184 | static void |
Derek Foreman | 8ae2db5 | 2015-07-15 13:00:36 -0500 | [diff] [blame] | 6185 | workspace_up_binding(struct weston_keyboard *keyboard, uint32_t time, |
Jonas Ådahl | e3cddce | 2012-06-13 00:01:22 +0200 | [diff] [blame] | 6186 | uint32_t key, void *data) |
| 6187 | { |
| 6188 | struct desktop_shell *shell = data; |
| 6189 | unsigned int new_index = shell->workspaces.current; |
| 6190 | |
Kristian Høgsberg | ce345b0 | 2012-06-25 21:35:29 -0400 | [diff] [blame] | 6191 | if (shell->locked) |
Kristian Høgsberg | 4476aaf | 2012-06-25 14:03:13 -0400 | [diff] [blame] | 6192 | return; |
Jonas Ådahl | e3cddce | 2012-06-13 00:01:22 +0200 | [diff] [blame] | 6193 | if (new_index != 0) |
| 6194 | new_index--; |
| 6195 | |
| 6196 | change_workspace(shell, new_index); |
| 6197 | } |
| 6198 | |
| 6199 | static void |
Derek Foreman | 8ae2db5 | 2015-07-15 13:00:36 -0500 | [diff] [blame] | 6200 | workspace_down_binding(struct weston_keyboard *keyboard, uint32_t time, |
Jonas Ådahl | e3cddce | 2012-06-13 00:01:22 +0200 | [diff] [blame] | 6201 | uint32_t key, void *data) |
| 6202 | { |
| 6203 | struct desktop_shell *shell = data; |
| 6204 | unsigned int new_index = shell->workspaces.current; |
| 6205 | |
Kristian Høgsberg | ce345b0 | 2012-06-25 21:35:29 -0400 | [diff] [blame] | 6206 | if (shell->locked) |
Kristian Høgsberg | 4476aaf | 2012-06-25 14:03:13 -0400 | [diff] [blame] | 6207 | return; |
Jonas Ådahl | e3cddce | 2012-06-13 00:01:22 +0200 | [diff] [blame] | 6208 | if (new_index < shell->workspaces.num - 1) |
| 6209 | new_index++; |
| 6210 | |
| 6211 | change_workspace(shell, new_index); |
| 6212 | } |
| 6213 | |
| 6214 | static void |
Derek Foreman | 8ae2db5 | 2015-07-15 13:00:36 -0500 | [diff] [blame] | 6215 | workspace_f_binding(struct weston_keyboard *keyboard, uint32_t time, |
Jonas Ådahl | e3cddce | 2012-06-13 00:01:22 +0200 | [diff] [blame] | 6216 | uint32_t key, void *data) |
| 6217 | { |
| 6218 | struct desktop_shell *shell = data; |
| 6219 | unsigned int new_index; |
| 6220 | |
Kristian Høgsberg | ce345b0 | 2012-06-25 21:35:29 -0400 | [diff] [blame] | 6221 | if (shell->locked) |
Kristian Høgsberg | 4476aaf | 2012-06-25 14:03:13 -0400 | [diff] [blame] | 6222 | return; |
Jonas Ådahl | e3cddce | 2012-06-13 00:01:22 +0200 | [diff] [blame] | 6223 | new_index = key - KEY_F1; |
| 6224 | if (new_index >= shell->workspaces.num) |
| 6225 | new_index = shell->workspaces.num - 1; |
| 6226 | |
| 6227 | change_workspace(shell, new_index); |
| 6228 | } |
| 6229 | |
Jonas Ådahl | 8de6a1d | 2012-08-29 22:13:00 +0200 | [diff] [blame] | 6230 | static void |
Derek Foreman | 8ae2db5 | 2015-07-15 13:00:36 -0500 | [diff] [blame] | 6231 | workspace_move_surface_up_binding(struct weston_keyboard *keyboard, |
| 6232 | uint32_t time, uint32_t key, void *data) |
Jonas Ådahl | 8de6a1d | 2012-08-29 22:13:00 +0200 | [diff] [blame] | 6233 | { |
| 6234 | struct desktop_shell *shell = data; |
| 6235 | unsigned int new_index = shell->workspaces.current; |
| 6236 | |
| 6237 | if (shell->locked) |
| 6238 | return; |
| 6239 | |
| 6240 | if (new_index != 0) |
| 6241 | new_index--; |
| 6242 | |
Derek Foreman | 8ae2db5 | 2015-07-15 13:00:36 -0500 | [diff] [blame] | 6243 | take_surface_to_workspace_by_seat(shell, keyboard->seat, new_index); |
Jonas Ådahl | 8de6a1d | 2012-08-29 22:13:00 +0200 | [diff] [blame] | 6244 | } |
| 6245 | |
| 6246 | static void |
Derek Foreman | 8ae2db5 | 2015-07-15 13:00:36 -0500 | [diff] [blame] | 6247 | workspace_move_surface_down_binding(struct weston_keyboard *keyboard, |
| 6248 | uint32_t time, uint32_t key, void *data) |
Jonas Ådahl | 8de6a1d | 2012-08-29 22:13:00 +0200 | [diff] [blame] | 6249 | { |
| 6250 | struct desktop_shell *shell = data; |
| 6251 | unsigned int new_index = shell->workspaces.current; |
| 6252 | |
| 6253 | if (shell->locked) |
| 6254 | return; |
| 6255 | |
| 6256 | if (new_index < shell->workspaces.num - 1) |
| 6257 | new_index++; |
| 6258 | |
Derek Foreman | 8ae2db5 | 2015-07-15 13:00:36 -0500 | [diff] [blame] | 6259 | take_surface_to_workspace_by_seat(shell, keyboard->seat, new_index); |
Jonas Ådahl | 8de6a1d | 2012-08-29 22:13:00 +0200 | [diff] [blame] | 6260 | } |
Jonas Ådahl | e3cddce | 2012-06-13 00:01:22 +0200 | [diff] [blame] | 6261 | |
| 6262 | static void |
Ander Conselvan de Oliveira | c94d622 | 2014-01-29 18:47:54 +0200 | [diff] [blame] | 6263 | shell_reposition_view_on_output_destroy(struct weston_view *view) |
| 6264 | { |
| 6265 | struct weston_output *output, *first_output; |
| 6266 | struct weston_compositor *ec = view->surface->compositor; |
| 6267 | struct shell_surface *shsurf; |
| 6268 | float x, y; |
| 6269 | int visible; |
| 6270 | |
| 6271 | x = view->geometry.x; |
| 6272 | y = view->geometry.y; |
| 6273 | |
| 6274 | /* At this point the destroyed output is not in the list anymore. |
| 6275 | * If the view is still visible somewhere, we leave where it is, |
| 6276 | * otherwise, move it to the first output. */ |
| 6277 | visible = 0; |
| 6278 | wl_list_for_each(output, &ec->output_list, link) { |
| 6279 | if (pixman_region32_contains_point(&output->region, |
| 6280 | x, y, NULL)) { |
| 6281 | visible = 1; |
| 6282 | break; |
| 6283 | } |
| 6284 | } |
| 6285 | |
| 6286 | if (!visible) { |
| 6287 | first_output = container_of(ec->output_list.next, |
| 6288 | struct weston_output, link); |
| 6289 | |
| 6290 | x = first_output->x + first_output->width / 4; |
| 6291 | y = first_output->y + first_output->height / 4; |
Xiong Zhang | 62899f5 | 2014-03-07 16:27:19 +0800 | [diff] [blame] | 6292 | |
| 6293 | weston_view_set_position(view, x, y); |
| 6294 | } else { |
| 6295 | weston_view_geometry_dirty(view); |
Ander Conselvan de Oliveira | c94d622 | 2014-01-29 18:47:54 +0200 | [diff] [blame] | 6296 | } |
| 6297 | |
Ander Conselvan de Oliveira | c94d622 | 2014-01-29 18:47:54 +0200 | [diff] [blame] | 6298 | |
| 6299 | shsurf = get_shell_surface(view->surface); |
| 6300 | |
| 6301 | if (shsurf) { |
| 6302 | shsurf->saved_position_valid = false; |
| 6303 | shsurf->next_state.maximized = false; |
| 6304 | shsurf->next_state.fullscreen = false; |
| 6305 | shsurf->state_changed = true; |
| 6306 | } |
| 6307 | } |
| 6308 | |
Ander Conselvan de Oliveira | 304996d | 2014-04-11 13:57:15 +0300 | [diff] [blame] | 6309 | void |
| 6310 | shell_for_each_layer(struct desktop_shell *shell, |
| 6311 | shell_for_each_layer_func_t func, void *data) |
Ander Conselvan de Oliveira | c94d622 | 2014-01-29 18:47:54 +0200 | [diff] [blame] | 6312 | { |
Ander Conselvan de Oliveira | 304996d | 2014-04-11 13:57:15 +0300 | [diff] [blame] | 6313 | struct workspace **ws; |
| 6314 | |
| 6315 | func(shell, &shell->fullscreen_layer, data); |
| 6316 | func(shell, &shell->panel_layer, data); |
| 6317 | func(shell, &shell->background_layer, data); |
| 6318 | func(shell, &shell->lock_layer, data); |
| 6319 | func(shell, &shell->input_panel_layer, data); |
| 6320 | |
| 6321 | wl_array_for_each(ws, &shell->workspaces.array) |
| 6322 | func(shell, &(*ws)->layer, data); |
| 6323 | } |
| 6324 | |
| 6325 | static void |
| 6326 | shell_output_destroy_move_layer(struct desktop_shell *shell, |
| 6327 | struct weston_layer *layer, |
| 6328 | void *data) |
| 6329 | { |
| 6330 | struct weston_output *output = data; |
Ander Conselvan de Oliveira | c94d622 | 2014-01-29 18:47:54 +0200 | [diff] [blame] | 6331 | struct weston_view *view; |
| 6332 | |
Giulio Camuffo | 412e6a5 | 2014-07-09 22:12:56 +0300 | [diff] [blame] | 6333 | 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] | 6334 | if (view->output != output) |
| 6335 | continue; |
Ander Conselvan de Oliveira | c94d622 | 2014-01-29 18:47:54 +0200 | [diff] [blame] | 6336 | |
Ander Conselvan de Oliveira | 304996d | 2014-04-11 13:57:15 +0300 | [diff] [blame] | 6337 | shell_reposition_view_on_output_destroy(view); |
Ander Conselvan de Oliveira | c94d622 | 2014-01-29 18:47:54 +0200 | [diff] [blame] | 6338 | } |
| 6339 | } |
| 6340 | |
| 6341 | static void |
Xiong Zhang | 6b48142 | 2013-10-23 13:58:32 +0800 | [diff] [blame] | 6342 | handle_output_destroy(struct wl_listener *listener, void *data) |
| 6343 | { |
| 6344 | struct shell_output *output_listener = |
| 6345 | container_of(listener, struct shell_output, destroy_listener); |
Ander Conselvan de Oliveira | 304996d | 2014-04-11 13:57:15 +0300 | [diff] [blame] | 6346 | struct weston_output *output = output_listener->output; |
| 6347 | struct desktop_shell *shell = output_listener->shell; |
Xiong Zhang | 6b48142 | 2013-10-23 13:58:32 +0800 | [diff] [blame] | 6348 | |
Ander Conselvan de Oliveira | 304996d | 2014-04-11 13:57:15 +0300 | [diff] [blame] | 6349 | 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] | 6350 | |
Xiong Zhang | 6b48142 | 2013-10-23 13:58:32 +0800 | [diff] [blame] | 6351 | wl_list_remove(&output_listener->destroy_listener.link); |
| 6352 | wl_list_remove(&output_listener->link); |
| 6353 | free(output_listener); |
| 6354 | } |
| 6355 | |
| 6356 | static void |
| 6357 | create_shell_output(struct desktop_shell *shell, |
| 6358 | struct weston_output *output) |
| 6359 | { |
| 6360 | struct shell_output *shell_output; |
| 6361 | |
| 6362 | shell_output = zalloc(sizeof *shell_output); |
| 6363 | if (shell_output == NULL) |
| 6364 | return; |
| 6365 | |
| 6366 | shell_output->output = output; |
| 6367 | shell_output->shell = shell; |
| 6368 | shell_output->destroy_listener.notify = handle_output_destroy; |
| 6369 | wl_signal_add(&output->destroy_signal, |
| 6370 | &shell_output->destroy_listener); |
Kristian Høgsberg | a3a0e18 | 2013-10-23 23:36:04 -0700 | [diff] [blame] | 6371 | wl_list_insert(shell->output_list.prev, &shell_output->link); |
Xiong Zhang | 6b48142 | 2013-10-23 13:58:32 +0800 | [diff] [blame] | 6372 | } |
| 6373 | |
| 6374 | static void |
| 6375 | handle_output_create(struct wl_listener *listener, void *data) |
| 6376 | { |
| 6377 | struct desktop_shell *shell = |
| 6378 | container_of(listener, struct desktop_shell, output_create_listener); |
| 6379 | struct weston_output *output = (struct weston_output *)data; |
| 6380 | |
| 6381 | create_shell_output(shell, output); |
| 6382 | } |
| 6383 | |
| 6384 | static void |
Ander Conselvan de Oliveira | 304996d | 2014-04-11 13:57:15 +0300 | [diff] [blame] | 6385 | handle_output_move_layer(struct desktop_shell *shell, |
| 6386 | struct weston_layer *layer, void *data) |
Ander Conselvan de Oliveira | a8a9baf | 2014-01-29 18:47:52 +0200 | [diff] [blame] | 6387 | { |
Ander Conselvan de Oliveira | 304996d | 2014-04-11 13:57:15 +0300 | [diff] [blame] | 6388 | struct weston_output *output = data; |
Ander Conselvan de Oliveira | a8a9baf | 2014-01-29 18:47:52 +0200 | [diff] [blame] | 6389 | struct weston_view *view; |
| 6390 | float x, y; |
| 6391 | |
Giulio Camuffo | 412e6a5 | 2014-07-09 22:12:56 +0300 | [diff] [blame] | 6392 | 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] | 6393 | if (view->output != output) |
| 6394 | continue; |
| 6395 | |
| 6396 | x = view->geometry.x + output->move_x; |
| 6397 | y = view->geometry.y + output->move_y; |
| 6398 | weston_view_set_position(view, x, y); |
| 6399 | } |
| 6400 | } |
| 6401 | |
| 6402 | static void |
| 6403 | handle_output_move(struct wl_listener *listener, void *data) |
| 6404 | { |
| 6405 | struct desktop_shell *shell; |
| 6406 | |
Ander Conselvan de Oliveira | a8a9baf | 2014-01-29 18:47:52 +0200 | [diff] [blame] | 6407 | shell = container_of(listener, struct desktop_shell, |
| 6408 | output_move_listener); |
Ander Conselvan de Oliveira | a8a9baf | 2014-01-29 18:47:52 +0200 | [diff] [blame] | 6409 | |
Ander Conselvan de Oliveira | 304996d | 2014-04-11 13:57:15 +0300 | [diff] [blame] | 6410 | shell_for_each_layer(shell, handle_output_move_layer, data); |
Ander Conselvan de Oliveira | a8a9baf | 2014-01-29 18:47:52 +0200 | [diff] [blame] | 6411 | } |
| 6412 | |
| 6413 | static void |
Xiong Zhang | 6b48142 | 2013-10-23 13:58:32 +0800 | [diff] [blame] | 6414 | setup_output_destroy_handler(struct weston_compositor *ec, |
| 6415 | struct desktop_shell *shell) |
| 6416 | { |
| 6417 | struct weston_output *output; |
| 6418 | |
| 6419 | wl_list_init(&shell->output_list); |
| 6420 | wl_list_for_each(output, &ec->output_list, link) |
| 6421 | create_shell_output(shell, output); |
| 6422 | |
| 6423 | shell->output_create_listener.notify = handle_output_create; |
| 6424 | wl_signal_add(&ec->output_created_signal, |
| 6425 | &shell->output_create_listener); |
Ander Conselvan de Oliveira | a8a9baf | 2014-01-29 18:47:52 +0200 | [diff] [blame] | 6426 | |
| 6427 | shell->output_move_listener.notify = handle_output_move; |
| 6428 | wl_signal_add(&ec->output_moved_signal, &shell->output_move_listener); |
Xiong Zhang | 6b48142 | 2013-10-23 13:58:32 +0800 | [diff] [blame] | 6429 | } |
| 6430 | |
| 6431 | static void |
Kristian Høgsberg | 02e79dc | 2012-04-12 09:55:26 -0400 | [diff] [blame] | 6432 | shell_destroy(struct wl_listener *listener, void *data) |
Pekka Paalanen | 3c64723 | 2011-12-22 13:43:43 +0200 | [diff] [blame] | 6433 | { |
Tiago Vignatti | be14326 | 2012-04-16 17:31:41 +0300 | [diff] [blame] | 6434 | struct desktop_shell *shell = |
| 6435 | container_of(listener, struct desktop_shell, destroy_listener); |
Jonas Ådahl | e3cddce | 2012-06-13 00:01:22 +0200 | [diff] [blame] | 6436 | struct workspace **ws; |
Xiong Zhang | 6b48142 | 2013-10-23 13:58:32 +0800 | [diff] [blame] | 6437 | struct shell_output *shell_output, *tmp; |
Pekka Paalanen | 3c64723 | 2011-12-22 13:43:43 +0200 | [diff] [blame] | 6438 | |
Kristian Høgsberg | 17bccae | 2014-01-16 16:46:28 -0800 | [diff] [blame] | 6439 | /* Force state to unlocked so we don't try to fade */ |
| 6440 | shell->locked = false; |
Pekka Paalanen | 826dc14 | 2014-08-27 12:11:53 +0300 | [diff] [blame] | 6441 | |
| 6442 | if (shell->child.client) { |
| 6443 | /* disable respawn */ |
| 6444 | wl_list_remove(&shell->child.client_destroy_listener.link); |
Pekka Paalanen | 9cf5cc8 | 2012-01-02 16:00:24 +0200 | [diff] [blame] | 6445 | wl_client_destroy(shell->child.client); |
Pekka Paalanen | 826dc14 | 2014-08-27 12:11:53 +0300 | [diff] [blame] | 6446 | } |
Pekka Paalanen | 9cf5cc8 | 2012-01-02 16:00:24 +0200 | [diff] [blame] | 6447 | |
Ander Conselvan de Oliveira | a457563 | 2013-02-21 18:35:23 +0200 | [diff] [blame] | 6448 | wl_list_remove(&shell->idle_listener.link); |
| 6449 | wl_list_remove(&shell->wake_listener.link); |
Kristian Høgsberg | 677a5f5 | 2013-12-04 11:00:19 -0800 | [diff] [blame] | 6450 | |
Pekka Paalanen | aa9536a | 2015-06-24 16:09:17 +0300 | [diff] [blame] | 6451 | text_backend_destroy(shell->text_backend); |
Kristian Høgsberg | 677a5f5 | 2013-12-04 11:00:19 -0800 | [diff] [blame] | 6452 | input_panel_destroy(shell); |
Kristian Høgsberg | 88c1607 | 2012-05-16 08:04:19 -0400 | [diff] [blame] | 6453 | |
Xiong Zhang | 6b48142 | 2013-10-23 13:58:32 +0800 | [diff] [blame] | 6454 | wl_list_for_each_safe(shell_output, tmp, &shell->output_list, link) { |
| 6455 | wl_list_remove(&shell_output->destroy_listener.link); |
| 6456 | wl_list_remove(&shell_output->link); |
| 6457 | free(shell_output); |
| 6458 | } |
| 6459 | |
| 6460 | wl_list_remove(&shell->output_create_listener.link); |
Kristian Høgsberg | 6d50b0f | 2014-04-30 20:46:25 -0700 | [diff] [blame] | 6461 | wl_list_remove(&shell->output_move_listener.link); |
Xiong Zhang | 6b48142 | 2013-10-23 13:58:32 +0800 | [diff] [blame] | 6462 | |
Jonas Ådahl | e3cddce | 2012-06-13 00:01:22 +0200 | [diff] [blame] | 6463 | wl_array_for_each(ws, &shell->workspaces.array) |
| 6464 | workspace_destroy(*ws); |
| 6465 | wl_array_release(&shell->workspaces.array); |
| 6466 | |
Emilio Pozuelo Monfort | 46ce798 | 2013-11-20 13:22:29 +0100 | [diff] [blame] | 6467 | free(shell->client); |
Pekka Paalanen | 3c64723 | 2011-12-22 13:43:43 +0200 | [diff] [blame] | 6468 | free(shell); |
| 6469 | } |
| 6470 | |
Tiago Vignatti | 0b52d48 | 2012-04-20 18:54:25 +0300 | [diff] [blame] | 6471 | static void |
| 6472 | shell_add_bindings(struct weston_compositor *ec, struct desktop_shell *shell) |
| 6473 | { |
| 6474 | uint32_t mod; |
Jonas Ådahl | e3cddce | 2012-06-13 00:01:22 +0200 | [diff] [blame] | 6475 | int i, num_workspace_bindings; |
Tiago Vignatti | 0b52d48 | 2012-04-20 18:54:25 +0300 | [diff] [blame] | 6476 | |
| 6477 | /* fixed bindings */ |
Daniel Stone | 325fc2d | 2012-05-30 16:31:58 +0100 | [diff] [blame] | 6478 | weston_compositor_add_key_binding(ec, KEY_BACKSPACE, |
| 6479 | MODIFIER_CTRL | MODIFIER_ALT, |
| 6480 | terminate_binding, ec); |
| 6481 | weston_compositor_add_button_binding(ec, BTN_LEFT, 0, |
| 6482 | click_to_activate_binding, |
| 6483 | shell); |
Kristian Høgsberg | f0ce581 | 2014-04-07 11:52:17 -0700 | [diff] [blame] | 6484 | weston_compositor_add_button_binding(ec, BTN_RIGHT, 0, |
| 6485 | click_to_activate_binding, |
| 6486 | shell); |
Neil Roberts | a28c693 | 2013-10-03 16:43:04 +0100 | [diff] [blame] | 6487 | weston_compositor_add_touch_binding(ec, 0, |
| 6488 | touch_to_activate_binding, |
| 6489 | shell); |
Daniel Stone | 325fc2d | 2012-05-30 16:31:58 +0100 | [diff] [blame] | 6490 | weston_compositor_add_axis_binding(ec, WL_POINTER_AXIS_VERTICAL_SCROLL, |
| 6491 | MODIFIER_SUPER | MODIFIER_ALT, |
| 6492 | surface_opacity_binding, NULL); |
| 6493 | weston_compositor_add_axis_binding(ec, WL_POINTER_AXIS_VERTICAL_SCROLL, |
| 6494 | MODIFIER_SUPER, zoom_axis_binding, |
| 6495 | NULL); |
Tiago Vignatti | 0b52d48 | 2012-04-20 18:54:25 +0300 | [diff] [blame] | 6496 | |
| 6497 | /* configurable bindings */ |
| 6498 | mod = shell->binding_modifier; |
Daniel Stone | 325fc2d | 2012-05-30 16:31:58 +0100 | [diff] [blame] | 6499 | weston_compositor_add_key_binding(ec, KEY_PAGEUP, mod, |
| 6500 | zoom_key_binding, NULL); |
| 6501 | weston_compositor_add_key_binding(ec, KEY_PAGEDOWN, mod, |
| 6502 | zoom_key_binding, NULL); |
Kristian Høgsberg | 211b517 | 2014-01-11 13:10:21 -0800 | [diff] [blame] | 6503 | weston_compositor_add_key_binding(ec, KEY_M, mod | MODIFIER_SHIFT, |
| 6504 | maximize_binding, NULL); |
| 6505 | weston_compositor_add_key_binding(ec, KEY_F, mod | MODIFIER_SHIFT, |
| 6506 | fullscreen_binding, NULL); |
Daniel Stone | 325fc2d | 2012-05-30 16:31:58 +0100 | [diff] [blame] | 6507 | weston_compositor_add_button_binding(ec, BTN_LEFT, mod, move_binding, |
| 6508 | shell); |
Neil Roberts | aba0f25 | 2013-10-03 16:43:05 +0100 | [diff] [blame] | 6509 | weston_compositor_add_touch_binding(ec, mod, touch_move_binding, shell); |
Derek Foreman | 2217f3f | 2015-06-25 16:03:30 -0500 | [diff] [blame] | 6510 | weston_compositor_add_button_binding(ec, BTN_RIGHT, mod, |
Daniel Stone | 325fc2d | 2012-05-30 16:31:58 +0100 | [diff] [blame] | 6511 | resize_binding, shell); |
Kristian Høgsberg | 0837fa9 | 2014-01-20 10:35:26 -0800 | [diff] [blame] | 6512 | weston_compositor_add_button_binding(ec, BTN_LEFT, |
| 6513 | mod | MODIFIER_SHIFT, |
| 6514 | resize_binding, shell); |
Pekka Paalanen | 7bb6510 | 2013-05-22 18:03:04 +0300 | [diff] [blame] | 6515 | |
| 6516 | if (ec->capabilities & WESTON_CAP_ROTATION_ANY) |
Derek Foreman | 2217f3f | 2015-06-25 16:03:30 -0500 | [diff] [blame] | 6517 | weston_compositor_add_button_binding(ec, BTN_MIDDLE, mod, |
Pekka Paalanen | 7bb6510 | 2013-05-22 18:03:04 +0300 | [diff] [blame] | 6518 | rotate_binding, NULL); |
| 6519 | |
Daniel Stone | 325fc2d | 2012-05-30 16:31:58 +0100 | [diff] [blame] | 6520 | weston_compositor_add_key_binding(ec, KEY_TAB, mod, switcher_binding, |
| 6521 | shell); |
| 6522 | weston_compositor_add_key_binding(ec, KEY_F9, mod, backlight_binding, |
| 6523 | ec); |
| 6524 | weston_compositor_add_key_binding(ec, KEY_BRIGHTNESSDOWN, 0, |
| 6525 | backlight_binding, ec); |
| 6526 | weston_compositor_add_key_binding(ec, KEY_F10, mod, backlight_binding, |
| 6527 | ec); |
| 6528 | weston_compositor_add_key_binding(ec, KEY_BRIGHTNESSUP, 0, |
| 6529 | backlight_binding, ec); |
Daniel Stone | 325fc2d | 2012-05-30 16:31:58 +0100 | [diff] [blame] | 6530 | weston_compositor_add_key_binding(ec, KEY_K, mod, |
| 6531 | force_kill_binding, shell); |
Jonas Ådahl | e3cddce | 2012-06-13 00:01:22 +0200 | [diff] [blame] | 6532 | weston_compositor_add_key_binding(ec, KEY_UP, mod, |
| 6533 | workspace_up_binding, shell); |
| 6534 | weston_compositor_add_key_binding(ec, KEY_DOWN, mod, |
| 6535 | workspace_down_binding, shell); |
Jonas Ådahl | 8de6a1d | 2012-08-29 22:13:00 +0200 | [diff] [blame] | 6536 | weston_compositor_add_key_binding(ec, KEY_UP, mod | MODIFIER_SHIFT, |
| 6537 | workspace_move_surface_up_binding, |
| 6538 | shell); |
| 6539 | weston_compositor_add_key_binding(ec, KEY_DOWN, mod | MODIFIER_SHIFT, |
| 6540 | workspace_move_surface_down_binding, |
| 6541 | shell); |
Jonas Ådahl | e3cddce | 2012-06-13 00:01:22 +0200 | [diff] [blame] | 6542 | |
Kristian Høgsberg | d56ab4e | 2014-01-16 16:51:52 -0800 | [diff] [blame] | 6543 | if (shell->exposay_modifier) |
| 6544 | weston_compositor_add_modifier_binding(ec, shell->exposay_modifier, |
| 6545 | exposay_binding, shell); |
Daniel Stone | df8133b | 2013-11-19 11:37:14 +0100 | [diff] [blame] | 6546 | |
Jonas Ådahl | e3cddce | 2012-06-13 00:01:22 +0200 | [diff] [blame] | 6547 | /* Add bindings for mod+F[1-6] for workspace 1 to 6. */ |
| 6548 | if (shell->workspaces.num > 1) { |
| 6549 | num_workspace_bindings = shell->workspaces.num; |
| 6550 | if (num_workspace_bindings > 6) |
| 6551 | num_workspace_bindings = 6; |
| 6552 | for (i = 0; i < num_workspace_bindings; i++) |
| 6553 | weston_compositor_add_key_binding(ec, KEY_F1 + i, mod, |
| 6554 | workspace_f_binding, |
| 6555 | shell); |
| 6556 | } |
Ander Conselvan de Oliveira | c509d2b | 2012-11-08 17:20:45 +0200 | [diff] [blame] | 6557 | |
Pekka Paalanen | 2829f7c | 2015-02-19 17:02:13 +0200 | [diff] [blame] | 6558 | weston_install_debug_key_binding(ec, mod); |
Tiago Vignatti | 0b52d48 | 2012-04-20 18:54:25 +0300 | [diff] [blame] | 6559 | } |
| 6560 | |
Jason Ekstrand | 024177c | 2014-04-21 19:42:58 -0500 | [diff] [blame] | 6561 | static void |
| 6562 | handle_seat_created(struct wl_listener *listener, void *data) |
| 6563 | { |
| 6564 | struct weston_seat *seat = data; |
| 6565 | |
| 6566 | create_shell_seat(seat); |
| 6567 | } |
| 6568 | |
Kristian Høgsberg | 1c56218 | 2011-05-02 22:09:20 -0400 | [diff] [blame] | 6569 | WL_EXPORT int |
Kristian Høgsberg | cb4685b | 2013-02-20 15:37:49 -0500 | [diff] [blame] | 6570 | module_init(struct weston_compositor *ec, |
Ossama Othman | a50e6e4 | 2013-05-14 09:48:26 -0700 | [diff] [blame] | 6571 | int *argc, char *argv[]) |
Kristian Høgsberg | 4cca349 | 2011-01-18 07:53:49 -0500 | [diff] [blame] | 6572 | { |
Kristian Høgsberg | f4d2f23 | 2012-08-10 10:05:39 -0400 | [diff] [blame] | 6573 | struct weston_seat *seat; |
Tiago Vignatti | be14326 | 2012-04-16 17:31:41 +0300 | [diff] [blame] | 6574 | struct desktop_shell *shell; |
Jonas Ådahl | e3cddce | 2012-06-13 00:01:22 +0200 | [diff] [blame] | 6575 | struct workspace **pws; |
| 6576 | unsigned int i; |
Tiago Vignatti | b7dbbd6 | 2012-09-25 17:57:01 +0300 | [diff] [blame] | 6577 | struct wl_event_loop *loop; |
Kristian Høgsberg | 02ec0a5 | 2011-04-23 13:04:11 -0400 | [diff] [blame] | 6578 | |
Peter Hutterer | f3d6227 | 2013-08-08 11:57:05 +1000 | [diff] [blame] | 6579 | shell = zalloc(sizeof *shell); |
Kristian Høgsberg | 02ec0a5 | 2011-04-23 13:04:11 -0400 | [diff] [blame] | 6580 | if (shell == NULL) |
| 6581 | return -1; |
| 6582 | |
Kristian Høgsberg | 7584062 | 2011-09-06 13:48:16 -0400 | [diff] [blame] | 6583 | shell->compositor = ec; |
Kristian Høgsberg | 02e79dc | 2012-04-12 09:55:26 -0400 | [diff] [blame] | 6584 | |
| 6585 | shell->destroy_listener.notify = shell_destroy; |
| 6586 | wl_signal_add(&ec->destroy_signal, &shell->destroy_listener); |
Ander Conselvan de Oliveira | a457563 | 2013-02-21 18:35:23 +0200 | [diff] [blame] | 6587 | shell->idle_listener.notify = idle_handler; |
| 6588 | wl_signal_add(&ec->idle_signal, &shell->idle_listener); |
| 6589 | shell->wake_listener.notify = wake_handler; |
| 6590 | wl_signal_add(&ec->wake_signal, &shell->wake_listener); |
Kristian Høgsberg | 677a5f5 | 2013-12-04 11:00:19 -0800 | [diff] [blame] | 6591 | |
Kristian Høgsberg | 82a1d11 | 2012-07-19 14:02:00 -0400 | [diff] [blame] | 6592 | ec->shell_interface.shell = shell; |
Tiago Vignatti | bc052c9 | 2012-04-19 16:18:18 +0300 | [diff] [blame] | 6593 | ec->shell_interface.create_shell_surface = create_shell_surface; |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 6594 | ec->shell_interface.get_primary_view = get_primary_view; |
Tiago Vignatti | bc052c9 | 2012-04-19 16:18:18 +0300 | [diff] [blame] | 6595 | ec->shell_interface.set_toplevel = set_toplevel; |
Tiago Vignatti | 491bac1 | 2012-05-18 16:37:43 -0400 | [diff] [blame] | 6596 | ec->shell_interface.set_transient = set_transient; |
Kristian Høgsberg | 4779241 | 2014-05-04 13:47:06 -0700 | [diff] [blame] | 6597 | ec->shell_interface.set_fullscreen = shell_interface_set_fullscreen; |
Tiago Vignatti | fb2adba | 2013-06-12 15:43:21 -0300 | [diff] [blame] | 6598 | ec->shell_interface.set_xwayland = set_xwayland; |
Kristian Høgsberg | ae356ae | 2014-04-29 16:03:54 -0700 | [diff] [blame] | 6599 | ec->shell_interface.move = shell_interface_move; |
Derek Foreman | 8fbebbd | 2015-07-15 13:00:40 -0500 | [diff] [blame] | 6600 | ec->shell_interface.resize = shell_interface_resize; |
Giulio Camuffo | 62942ad | 2013-09-11 18:20:47 +0200 | [diff] [blame] | 6601 | ec->shell_interface.set_title = set_title; |
Jasper St. Pierre | ccf48fb | 2014-05-02 10:21:38 -0400 | [diff] [blame] | 6602 | ec->shell_interface.set_window_geometry = set_window_geometry; |
Giulio Camuffo | 6b4b241 | 2015-01-29 19:06:49 +0200 | [diff] [blame] | 6603 | ec->shell_interface.set_maximized = shell_interface_set_maximized; |
Giulio Camuffo | a8e9b41 | 2015-01-27 19:10:37 +0200 | [diff] [blame] | 6604 | ec->shell_interface.set_pid = set_pid; |
Kristian Høgsberg | 4cca349 | 2011-01-18 07:53:49 -0500 | [diff] [blame] | 6605 | |
Kristian Høgsberg | 3be2ce9 | 2012-02-29 12:42:35 -0500 | [diff] [blame] | 6606 | weston_layer_init(&shell->fullscreen_layer, &ec->cursor_layer.link); |
| 6607 | weston_layer_init(&shell->panel_layer, &shell->fullscreen_layer.link); |
Jonas Ådahl | e3cddce | 2012-06-13 00:01:22 +0200 | [diff] [blame] | 6608 | weston_layer_init(&shell->background_layer, &shell->panel_layer.link); |
| 6609 | weston_layer_init(&shell->lock_layer, NULL); |
Philipp Brüschweiler | 711fda8 | 2012-08-09 18:50:43 +0200 | [diff] [blame] | 6610 | weston_layer_init(&shell->input_panel_layer, NULL); |
Jonas Ådahl | e3cddce | 2012-06-13 00:01:22 +0200 | [diff] [blame] | 6611 | |
| 6612 | wl_array_init(&shell->workspaces.array); |
Jonas Ådahl | e9d2250 | 2012-08-29 22:13:01 +0200 | [diff] [blame] | 6613 | wl_list_init(&shell->workspaces.client_list); |
Kristian Høgsberg | 3be2ce9 | 2012-02-29 12:42:35 -0500 | [diff] [blame] | 6614 | |
Kristian Høgsberg | 677a5f5 | 2013-12-04 11:00:19 -0800 | [diff] [blame] | 6615 | if (input_panel_setup(shell) < 0) |
| 6616 | return -1; |
| 6617 | |
Pekka Paalanen | aa9536a | 2015-06-24 16:09:17 +0300 | [diff] [blame] | 6618 | shell->text_backend = text_backend_init(ec); |
| 6619 | if (!shell->text_backend) |
Murray Calavera | 9a51cd7 | 2015-06-10 21:16:02 +0000 | [diff] [blame] | 6620 | return -1; |
| 6621 | |
Kristian Høgsberg | 14e438c | 2013-05-26 21:48:14 -0400 | [diff] [blame] | 6622 | shell_configuration(shell); |
Pekka Paalanen | e955f1e | 2011-12-07 11:49:52 +0200 | [diff] [blame] | 6623 | |
Daniel Stone | df8133b | 2013-11-19 11:37:14 +0100 | [diff] [blame] | 6624 | shell->exposay.state_cur = EXPOSAY_LAYOUT_INACTIVE; |
| 6625 | shell->exposay.state_target = EXPOSAY_TARGET_CANCEL; |
| 6626 | |
Jonas Ådahl | e3cddce | 2012-06-13 00:01:22 +0200 | [diff] [blame] | 6627 | for (i = 0; i < shell->workspaces.num; i++) { |
| 6628 | pws = wl_array_add(&shell->workspaces.array, sizeof *pws); |
| 6629 | if (pws == NULL) |
| 6630 | return -1; |
| 6631 | |
| 6632 | *pws = workspace_create(); |
| 6633 | if (*pws == NULL) |
| 6634 | return -1; |
| 6635 | } |
| 6636 | activate_workspace(shell, 0); |
| 6637 | |
Manuel Bachmann | 50c87db | 2014-02-26 15:52:13 +0100 | [diff] [blame] | 6638 | weston_layer_init(&shell->minimized_layer, NULL); |
| 6639 | |
Jonas Ådahl | 8de6a1d | 2012-08-29 22:13:00 +0200 | [diff] [blame] | 6640 | wl_list_init(&shell->workspaces.anim_sticky_list); |
Jonas Ådahl | 62fcd04 | 2012-06-13 00:01:23 +0200 | [diff] [blame] | 6641 | wl_list_init(&shell->workspaces.animation.link); |
| 6642 | shell->workspaces.animation.frame = animate_workspace_change_frame; |
| 6643 | |
Kristian Høgsberg | 919cddb | 2013-07-08 19:03:57 -0400 | [diff] [blame] | 6644 | if (wl_global_create(ec->wl_display, &wl_shell_interface, 1, |
Kristian Høgsberg | 97d44aa | 2011-08-26 17:21:20 -0400 | [diff] [blame] | 6645 | shell, bind_shell) == NULL) |
Kristian Høgsberg | 4cca349 | 2011-01-18 07:53:49 -0500 | [diff] [blame] | 6646 | return -1; |
| 6647 | |
Rafael Antognolli | e2a3455 | 2013-12-03 15:35:45 -0200 | [diff] [blame] | 6648 | if (wl_global_create(ec->wl_display, &xdg_shell_interface, 1, |
| 6649 | shell, bind_xdg_shell) == NULL) |
| 6650 | return -1; |
| 6651 | |
Kristian Høgsberg | 919cddb | 2013-07-08 19:03:57 -0400 | [diff] [blame] | 6652 | if (wl_global_create(ec->wl_display, |
Jonny Lamb | 765760d | 2014-08-20 15:53:19 +0200 | [diff] [blame] | 6653 | &desktop_shell_interface, 3, |
Kristian Høgsberg | 919cddb | 2013-07-08 19:03:57 -0400 | [diff] [blame] | 6654 | shell, bind_desktop_shell) == NULL) |
Kristian Høgsberg | 7584062 | 2011-09-06 13:48:16 -0400 | [diff] [blame] | 6655 | return -1; |
| 6656 | |
Kristian Høgsberg | 919cddb | 2013-07-08 19:03:57 -0400 | [diff] [blame] | 6657 | if (wl_global_create(ec->wl_display, &workspace_manager_interface, 1, |
| 6658 | shell, bind_workspace_manager) == NULL) |
Jonas Ådahl | e9d2250 | 2012-08-29 22:13:01 +0200 | [diff] [blame] | 6659 | return -1; |
| 6660 | |
Kristian Høgsberg | f03a616 | 2012-01-17 11:07:42 -0500 | [diff] [blame] | 6661 | shell->child.deathstamp = weston_compositor_get_time(); |
Tiago Vignatti | b7dbbd6 | 2012-09-25 17:57:01 +0300 | [diff] [blame] | 6662 | |
Jonny Lamb | 765760d | 2014-08-20 15:53:19 +0200 | [diff] [blame] | 6663 | shell->panel_position = DESKTOP_SHELL_PANEL_POSITION_TOP; |
| 6664 | |
Xiong Zhang | 6b48142 | 2013-10-23 13:58:32 +0800 | [diff] [blame] | 6665 | setup_output_destroy_handler(ec, shell); |
| 6666 | |
Tiago Vignatti | b7dbbd6 | 2012-09-25 17:57:01 +0300 | [diff] [blame] | 6667 | loop = wl_display_get_event_loop(ec->wl_display); |
| 6668 | wl_event_loop_add_idle(loop, launch_desktop_shell_process, shell); |
Pekka Paalanen | 6cd281a | 2011-11-03 14:11:32 +0200 | [diff] [blame] | 6669 | |
Jason Ekstrand | 024177c | 2014-04-21 19:42:58 -0500 | [diff] [blame] | 6670 | wl_list_for_each(seat, &ec->seat_list, link) |
| 6671 | handle_seat_created(NULL, seat); |
| 6672 | shell->seat_create_listener.notify = handle_seat_created; |
| 6673 | wl_signal_add(&ec->seat_created_signal, &shell->seat_create_listener); |
Kristian Høgsberg | d56bd90 | 2012-06-05 09:58:51 -0400 | [diff] [blame] | 6674 | |
Giulio Camuffo | c6ab3d5 | 2013-12-11 23:45:12 +0100 | [diff] [blame] | 6675 | screenshooter_create(ec); |
| 6676 | |
Tiago Vignatti | 0b52d48 | 2012-04-20 18:54:25 +0300 | [diff] [blame] | 6677 | shell_add_bindings(ec, shell); |
Kristian Høgsberg | 0793756 | 2011-04-12 17:25:42 -0400 | [diff] [blame] | 6678 | |
Pekka Paalanen | 79346ab | 2013-05-22 18:03:09 +0300 | [diff] [blame] | 6679 | shell_fade_init(shell); |
Ander Conselvan de Oliveira | 19d10ef | 2013-02-21 18:35:20 +0200 | [diff] [blame] | 6680 | |
Pekka Paalanen | 2e62e4a | 2014-08-28 11:41:26 +0300 | [diff] [blame] | 6681 | clock_gettime(CLOCK_MONOTONIC, &shell->startup_time); |
| 6682 | |
Kristian Høgsberg | 4cca349 | 2011-01-18 07:53:49 -0500 | [diff] [blame] | 6683 | return 0; |
| 6684 | } |