Kristian Høgsberg | 4cca349 | 2011-01-18 07:53:49 -0500 | [diff] [blame] | 1 | /* |
Kristian Høgsberg | 0704539 | 2012-02-19 18:52:44 -0500 | [diff] [blame] | 2 | * Copyright © 2010-2012 Intel Corporation |
Pekka Paalanen | d581a8f | 2012-01-27 16:25:16 +0200 | [diff] [blame] | 3 | * Copyright © 2011-2012 Collabora, Ltd. |
Daniel Stone | df8133b | 2013-11-19 11:37:14 +0100 | [diff] [blame] | 4 | * Copyright © 2013 Raspberry Pi Foundation |
Kristian Høgsberg | 4cca349 | 2011-01-18 07:53:49 -0500 | [diff] [blame] | 5 | * |
Bryce Harrington | af637c2 | 2015-06-11 12:55:55 -0700 | [diff] [blame] | 6 | * Permission is hereby granted, free of charge, to any person obtaining a |
| 7 | * copy of this software and associated documentation files (the "Software"), |
| 8 | * to deal in the Software without restriction, including without limitation |
| 9 | * the rights to use, copy, modify, merge, publish, distribute, sublicense, |
| 10 | * and/or sell copies of the Software, and to permit persons to whom the |
| 11 | * Software is furnished to do so, subject to the following conditions: |
Kristian Høgsberg | 4cca349 | 2011-01-18 07:53:49 -0500 | [diff] [blame] | 12 | * |
Bryce Harrington | af637c2 | 2015-06-11 12:55:55 -0700 | [diff] [blame] | 13 | * The above copyright notice and this permission notice (including the next |
| 14 | * paragraph) shall be included in all copies or substantial portions of the |
| 15 | * Software. |
| 16 | * |
| 17 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR |
| 18 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, |
| 19 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL |
| 20 | * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER |
| 21 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING |
| 22 | * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER |
| 23 | * DEALINGS IN THE SOFTWARE. |
Kristian Høgsberg | 4cca349 | 2011-01-18 07:53:49 -0500 | [diff] [blame] | 24 | */ |
| 25 | |
Daniel Stone | c228e23 | 2013-05-22 18:03:19 +0300 | [diff] [blame] | 26 | #include "config.h" |
| 27 | |
Kristian Høgsberg | 4cca349 | 2011-01-18 07:53:49 -0500 | [diff] [blame] | 28 | #include <stdlib.h> |
Kristian Høgsberg | 7584062 | 2011-09-06 13:48:16 -0400 | [diff] [blame] | 29 | #include <stdio.h> |
Kristian Høgsberg | 4cca349 | 2011-01-18 07:53:49 -0500 | [diff] [blame] | 30 | #include <string.h> |
| 31 | #include <unistd.h> |
Kristian Høgsberg | 0793756 | 2011-04-12 17:25:42 -0400 | [diff] [blame] | 32 | #include <linux/input.h> |
Pekka Paalanen | f0fc70d | 2011-11-15 13:34:54 +0200 | [diff] [blame] | 33 | #include <assert.h> |
Pekka Paalanen | 18027e5 | 2011-12-02 16:31:49 +0200 | [diff] [blame] | 34 | #include <signal.h> |
Pekka Paalanen | 460099f | 2012-01-20 16:48:25 +0200 | [diff] [blame] | 35 | #include <math.h> |
Kristian Høgsberg | 92a57db | 2012-05-26 13:41:06 -0400 | [diff] [blame] | 36 | #include <sys/types.h> |
Kristian Høgsberg | 4cca349 | 2011-01-18 07:53:49 -0500 | [diff] [blame] | 37 | |
Kristian Høgsberg | 1ef2313 | 2013-12-04 00:20:01 -0800 | [diff] [blame] | 38 | #include "shell.h" |
Kristian Høgsberg | 7584062 | 2011-09-06 13:48:16 -0400 | [diff] [blame] | 39 | #include "desktop-shell-server-protocol.h" |
Jonas Ådahl | e9d2250 | 2012-08-29 22:13:01 +0200 | [diff] [blame] | 40 | #include "workspaces-server-protocol.h" |
Jon Cruz | 4678bab | 2015-06-15 15:37:07 -0700 | [diff] [blame] | 41 | #include "shared/config-parser.h" |
Jon Cruz | d618f68 | 2015-06-15 15:37:09 -0700 | [diff] [blame] | 42 | #include "shared/helpers.h" |
Rafael Antognolli | e2a3455 | 2013-12-03 15:35:45 -0200 | [diff] [blame] | 43 | #include "xdg-shell-server-protocol.h" |
Kristian Høgsberg | 4cca349 | 2011-01-18 07:53:49 -0500 | [diff] [blame] | 44 | |
Jonas Ådahl | e3cddce | 2012-06-13 00:01:22 +0200 | [diff] [blame] | 45 | #define DEFAULT_NUM_WORKSPACES 1 |
Jonas Ådahl | 62fcd04 | 2012-06-13 00:01:23 +0200 | [diff] [blame] | 46 | #define DEFAULT_WORKSPACE_CHANGE_ANIMATION_LENGTH 200 |
Jonas Ådahl | e3cddce | 2012-06-13 00:01:22 +0200 | [diff] [blame] | 47 | |
Giulio Camuffo | 1aaf3e4 | 2013-12-09 22:47:58 +0100 | [diff] [blame] | 48 | #ifndef static_assert |
| 49 | #define static_assert(cond, msg) |
| 50 | #endif |
| 51 | |
Jonas Ådahl | 0476974 | 2012-06-13 00:01:24 +0200 | [diff] [blame] | 52 | struct focus_state { |
| 53 | struct weston_seat *seat; |
Kristian Høgsberg | 2f5faff | 2012-07-31 16:36:34 -0400 | [diff] [blame] | 54 | struct workspace *ws; |
Jonas Ådahl | 0476974 | 2012-06-13 00:01:24 +0200 | [diff] [blame] | 55 | struct weston_surface *keyboard_focus; |
| 56 | struct wl_list link; |
| 57 | struct wl_listener seat_destroy_listener; |
| 58 | struct wl_listener surface_destroy_listener; |
| 59 | }; |
| 60 | |
Kristian Høgsberg | d2abb83 | 2011-11-23 10:52:40 -0500 | [diff] [blame] | 61 | enum shell_surface_type { |
Pekka Paalanen | 9826223 | 2011-12-01 10:42:22 +0200 | [diff] [blame] | 62 | SHELL_SURFACE_NONE, |
Kristian Høgsberg | d2abb83 | 2011-11-23 10:52:40 -0500 | [diff] [blame] | 63 | SHELL_SURFACE_TOPLEVEL, |
Tiago Vignatti | fb2adba | 2013-06-12 15:43:21 -0300 | [diff] [blame] | 64 | SHELL_SURFACE_POPUP, |
| 65 | SHELL_SURFACE_XWAYLAND |
Pekka Paalanen | 57da4a8 | 2011-11-23 16:42:16 +0200 | [diff] [blame] | 66 | }; |
| 67 | |
Jason Ekstrand | 9e9512f | 2014-04-16 21:12:10 -0500 | [diff] [blame] | 68 | struct shell_client; |
| 69 | |
Philip Withnall | 648a4dd | 2013-11-25 18:01:44 +0000 | [diff] [blame] | 70 | /* |
| 71 | * Surface stacking and ordering. |
| 72 | * |
| 73 | * This is handled using several linked lists of surfaces, organised into |
| 74 | * ‘layers’. The layers are ordered, and each of the surfaces in one layer are |
| 75 | * above all of the surfaces in the layer below. The set of layers is static and |
| 76 | * in the following order (top-most first): |
| 77 | * • Lock layer (only ever displayed on its own) |
| 78 | * • Cursor layer |
Manuel Bachmann | 805d2f5 | 2014-03-05 12:21:34 +0100 | [diff] [blame] | 79 | * • Input panel layer |
Philip Withnall | 648a4dd | 2013-11-25 18:01:44 +0000 | [diff] [blame] | 80 | * • Fullscreen layer |
| 81 | * • Panel layer |
Philip Withnall | 648a4dd | 2013-11-25 18:01:44 +0000 | [diff] [blame] | 82 | * • Workspace layers |
| 83 | * • Background layer |
| 84 | * |
| 85 | * The list of layers may be manipulated to remove whole layers of surfaces from |
| 86 | * display. For example, when locking the screen, all layers except the lock |
| 87 | * layer are removed. |
| 88 | * |
| 89 | * A surface’s layer is modified on configuring the surface, in |
| 90 | * set_surface_type() (which is only called when the surface’s type change is |
| 91 | * _committed_). If a surface’s type changes (e.g. when making a window |
| 92 | * fullscreen) its layer changes too. |
| 93 | * |
| 94 | * In order to allow popup and transient surfaces to be correctly stacked above |
| 95 | * their parent surfaces, each surface tracks both its parent surface, and a |
| 96 | * linked list of its children. When a surface’s layer is updated, so are the |
| 97 | * layers of its children. Note that child surfaces are *not* the same as |
| 98 | * subsurfaces — child/parent surfaces are purely for maintaining stacking |
| 99 | * order. |
| 100 | * |
| 101 | * The children_link list of siblings of a surface (i.e. those surfaces which |
| 102 | * have the same parent) only contains weston_surfaces which have a |
| 103 | * shell_surface. Stacking is not implemented for non-shell_surface |
| 104 | * weston_surfaces. This means that the following implication does *not* hold: |
| 105 | * (shsurf->parent != NULL) ⇒ !wl_list_is_empty(shsurf->children_link) |
| 106 | */ |
| 107 | |
Pekka Paalanen | 56cdea9 | 2011-11-23 16:14:12 +0200 | [diff] [blame] | 108 | struct shell_surface { |
Jason Ekstrand | 651f00e | 2013-06-14 10:07:54 -0500 | [diff] [blame] | 109 | struct wl_resource *resource; |
| 110 | struct wl_signal destroy_signal; |
Jason Ekstrand | 9e9512f | 2014-04-16 21:12:10 -0500 | [diff] [blame] | 111 | struct shell_client *owner; |
Jonas Ådahl | 49d77d2 | 2015-03-18 16:20:51 +0800 | [diff] [blame] | 112 | struct wl_resource *owner_resource; |
Pekka Paalanen | 9d1613e | 2011-11-25 12:09:16 +0200 | [diff] [blame] | 113 | |
Kristian Høgsberg | 8334bc1 | 2012-01-03 10:29:47 -0500 | [diff] [blame] | 114 | struct weston_surface *surface; |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 115 | struct weston_view *view; |
Jason Ekstrand | 918f2dd | 2013-12-02 21:01:53 -0600 | [diff] [blame] | 116 | int32_t last_width, last_height; |
Pekka Paalanen | 9d1613e | 2011-11-25 12:09:16 +0200 | [diff] [blame] | 117 | struct wl_listener surface_destroy_listener; |
Kristian Høgsberg | 160fe75 | 2014-03-11 10:19:10 -0700 | [diff] [blame] | 118 | struct wl_listener resource_destroy_listener; |
| 119 | |
Kristian Høgsberg | 8150b19 | 2012-06-27 10:22:58 -0400 | [diff] [blame] | 120 | struct weston_surface *parent; |
Philip Withnall | 648a4dd | 2013-11-25 18:01:44 +0000 | [diff] [blame] | 121 | struct wl_list children_list; /* child surfaces of this one */ |
| 122 | struct wl_list children_link; /* sibling surfaces of this one */ |
Tiago Vignatti | be14326 | 2012-04-16 17:31:41 +0300 | [diff] [blame] | 123 | struct desktop_shell *shell; |
Pekka Paalanen | 57da4a8 | 2011-11-23 16:42:16 +0200 | [diff] [blame] | 124 | |
Kristian Høgsberg | c8f8dd8 | 2013-12-05 23:20:33 -0800 | [diff] [blame] | 125 | enum shell_surface_type type; |
Kristian Høgsberg | e7afd91 | 2012-05-02 09:47:44 -0400 | [diff] [blame] | 126 | char *title, *class; |
Kristian Høgsberg | d2abb83 | 2011-11-23 10:52:40 -0500 | [diff] [blame] | 127 | int32_t saved_x, saved_y; |
Rafael Antognolli | 3c4e3f7 | 2013-12-03 15:35:46 -0200 | [diff] [blame] | 128 | int32_t saved_width, saved_height; |
Alex Wu | 4539b08 | 2012-03-01 12:57:46 +0800 | [diff] [blame] | 129 | bool saved_position_valid; |
Rafael Antognolli | 3c4e3f7 | 2013-12-03 15:35:46 -0200 | [diff] [blame] | 130 | bool saved_size_valid; |
Alex Wu | 7bcb8bd | 2012-04-27 09:07:24 +0800 | [diff] [blame] | 131 | bool saved_rotation_valid; |
Kristian Høgsberg | c85f1d4 | 2013-10-24 16:52:00 -0700 | [diff] [blame] | 132 | int unresponsive, grabbed; |
Kristian Høgsberg | 44cd196 | 2014-02-05 21:36:04 -0800 | [diff] [blame] | 133 | uint32_t resize_edges; |
Benjamin Franzke | d0f79ab | 2011-11-22 12:43:52 +0100 | [diff] [blame] | 134 | |
Kristian Høgsberg | b3cca0a | 2012-01-04 22:19:14 -0500 | [diff] [blame] | 135 | struct { |
Pekka Paalanen | 460099f | 2012-01-20 16:48:25 +0200 | [diff] [blame] | 136 | struct weston_transform transform; |
Kristian Høgsberg | 765e27b | 2012-01-27 13:36:13 -0500 | [diff] [blame] | 137 | struct weston_matrix rotation; |
Pekka Paalanen | 460099f | 2012-01-20 16:48:25 +0200 | [diff] [blame] | 138 | } rotation; |
| 139 | |
| 140 | struct { |
Giulio Camuffo | 5085a75 | 2013-03-25 21:42:45 +0100 | [diff] [blame] | 141 | struct wl_list grab_link; |
Kristian Høgsberg | b3cca0a | 2012-01-04 22:19:14 -0500 | [diff] [blame] | 142 | int32_t x, y; |
Giulio Camuffo | 5085a75 | 2013-03-25 21:42:45 +0100 | [diff] [blame] | 143 | struct shell_seat *shseat; |
Kristian Høgsberg | 3730f36 | 2012-04-13 12:40:07 -0400 | [diff] [blame] | 144 | uint32_t serial; |
Kristian Høgsberg | b3cca0a | 2012-01-04 22:19:14 -0500 | [diff] [blame] | 145 | } popup; |
| 146 | |
Alex Wu | 4539b08 | 2012-03-01 12:57:46 +0800 | [diff] [blame] | 147 | struct { |
Tiago Vignatti | 52e598c | 2012-05-07 15:23:08 +0300 | [diff] [blame] | 148 | int32_t x, y; |
Tiago Vignatti | 491bac1 | 2012-05-18 16:37:43 -0400 | [diff] [blame] | 149 | uint32_t flags; |
Tiago Vignatti | 52e598c | 2012-05-07 15:23:08 +0300 | [diff] [blame] | 150 | } transient; |
| 151 | |
| 152 | struct { |
Alex Wu | 4539b08 | 2012-03-01 12:57:46 +0800 | [diff] [blame] | 153 | enum wl_shell_surface_fullscreen_method type; |
| 154 | struct weston_transform transform; /* matrix from x, y */ |
| 155 | uint32_t framerate; |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 156 | struct weston_view *black_view; |
Alex Wu | 4539b08 | 2012-03-01 12:57:46 +0800 | [diff] [blame] | 157 | } fullscreen; |
| 158 | |
Jonas Ådahl | 62fcd04 | 2012-06-13 00:01:23 +0200 | [diff] [blame] | 159 | struct weston_transform workspace_transform; |
| 160 | |
Kristian Høgsberg | 1cbf326 | 2012-02-17 23:49:07 -0500 | [diff] [blame] | 161 | struct weston_output *fullscreen_output; |
Kristian Høgsberg | 8334bc1 | 2012-01-03 10:29:47 -0500 | [diff] [blame] | 162 | struct weston_output *output; |
Benjamin Franzke | d0f79ab | 2011-11-22 12:43:52 +0100 | [diff] [blame] | 163 | struct wl_list link; |
Kristian Høgsberg | a61ca06 | 2012-05-22 16:05:52 -0400 | [diff] [blame] | 164 | |
| 165 | const struct weston_shell_client *client; |
Rafael Antognolli | 03b1659 | 2013-12-03 15:35:42 -0200 | [diff] [blame] | 166 | |
Jasper St. Pierre | 6458ec3 | 2014-04-11 16:00:31 -0700 | [diff] [blame] | 167 | struct surface_state { |
Rafael Antognolli | 03b1659 | 2013-12-03 15:35:42 -0200 | [diff] [blame] | 168 | bool maximized; |
| 169 | bool fullscreen; |
Rafael Antognolli | ed207b4 | 2013-12-03 15:35:43 -0200 | [diff] [blame] | 170 | bool relative; |
Emilio Pozuelo Monfort | 9e7c759 | 2014-01-30 14:01:10 +0100 | [diff] [blame] | 171 | bool lowered; |
Jasper St. Pierre | 8c6aa45 | 2014-02-08 18:29:49 -0500 | [diff] [blame] | 172 | } state, next_state, requested_state; /* surface states */ |
Rafael Antognolli | 03b1659 | 2013-12-03 15:35:42 -0200 | [diff] [blame] | 173 | bool state_changed; |
Jasper St. Pierre | 8c6aa45 | 2014-02-08 18:29:49 -0500 | [diff] [blame] | 174 | bool state_requested; |
Jasper St. Pierre | faf27a9 | 2013-12-09 17:36:28 -0500 | [diff] [blame] | 175 | |
Kristian Høgsberg | ae356ae | 2014-04-29 16:03:54 -0700 | [diff] [blame] | 176 | struct { |
Jasper St. Pierre | ccf48fb | 2014-05-02 10:21:38 -0400 | [diff] [blame] | 177 | int32_t x, y, width, height; |
| 178 | } geometry, next_geometry; |
| 179 | bool has_set_geometry, has_next_geometry; |
Kristian Høgsberg | ae356ae | 2014-04-29 16:03:54 -0700 | [diff] [blame] | 180 | |
Jasper St. Pierre | faf27a9 | 2013-12-09 17:36:28 -0500 | [diff] [blame] | 181 | int focus_count; |
Derek Foreman | 039e9be | 2015-04-14 17:09:06 -0500 | [diff] [blame] | 182 | |
| 183 | bool destroying; |
Pekka Paalanen | 56cdea9 | 2011-11-23 16:14:12 +0200 | [diff] [blame] | 184 | }; |
| 185 | |
Ander Conselvan de Oliveira | fe0444a | 2012-04-04 17:48:05 +0300 | [diff] [blame] | 186 | struct shell_grab { |
Kristian Høgsberg | 02bbabb | 2013-05-06 22:15:05 -0400 | [diff] [blame] | 187 | struct weston_pointer_grab grab; |
Ander Conselvan de Oliveira | fe0444a | 2012-04-04 17:48:05 +0300 | [diff] [blame] | 188 | struct shell_surface *shsurf; |
| 189 | struct wl_listener shsurf_destroy_listener; |
| 190 | }; |
| 191 | |
Rusty Lynch | 1084da5 | 2013-08-15 09:10:08 -0700 | [diff] [blame] | 192 | struct shell_touch_grab { |
| 193 | struct weston_touch_grab grab; |
| 194 | struct shell_surface *shsurf; |
| 195 | struct wl_listener shsurf_destroy_listener; |
| 196 | struct weston_touch *touch; |
| 197 | }; |
| 198 | |
Ander Conselvan de Oliveira | fe0444a | 2012-04-04 17:48:05 +0300 | [diff] [blame] | 199 | struct weston_move_grab { |
| 200 | struct shell_grab base; |
Daniel Stone | 103db7f | 2012-05-08 17:17:55 +0100 | [diff] [blame] | 201 | wl_fixed_t dx, dy; |
Derek Foreman | cf7d95a | 2015-06-03 15:53:22 -0500 | [diff] [blame] | 202 | bool client_initiated; |
Kristian Høgsberg | 4cca349 | 2011-01-18 07:53:49 -0500 | [diff] [blame] | 203 | }; |
| 204 | |
Rusty Lynch | 1084da5 | 2013-08-15 09:10:08 -0700 | [diff] [blame] | 205 | struct weston_touch_move_grab { |
| 206 | struct shell_touch_grab base; |
Kristian Høgsberg | 8e80a31 | 2014-01-17 15:18:10 -0800 | [diff] [blame] | 207 | int active; |
Rusty Lynch | 1084da5 | 2013-08-15 09:10:08 -0700 | [diff] [blame] | 208 | wl_fixed_t dx, dy; |
| 209 | }; |
| 210 | |
Pekka Paalanen | 460099f | 2012-01-20 16:48:25 +0200 | [diff] [blame] | 211 | struct rotate_grab { |
Ander Conselvan de Oliveira | fe0444a | 2012-04-04 17:48:05 +0300 | [diff] [blame] | 212 | struct shell_grab base; |
Kristian Høgsberg | 765e27b | 2012-01-27 13:36:13 -0500 | [diff] [blame] | 213 | struct weston_matrix rotation; |
Pekka Paalanen | 460099f | 2012-01-20 16:48:25 +0200 | [diff] [blame] | 214 | struct { |
John Kåre Alsaker | 490d02a | 2012-09-30 02:57:21 +0200 | [diff] [blame] | 215 | float x; |
| 216 | float y; |
Pekka Paalanen | 460099f | 2012-01-20 16:48:25 +0200 | [diff] [blame] | 217 | } center; |
| 218 | }; |
| 219 | |
Giulio Camuffo | 5085a75 | 2013-03-25 21:42:45 +0100 | [diff] [blame] | 220 | struct shell_seat { |
| 221 | struct weston_seat *seat; |
| 222 | struct wl_listener seat_destroy_listener; |
Jasper St. Pierre | faf27a9 | 2013-12-09 17:36:28 -0500 | [diff] [blame] | 223 | struct weston_surface *focused_surface; |
Giulio Camuffo | 5085a75 | 2013-03-25 21:42:45 +0100 | [diff] [blame] | 224 | |
Jason Ekstrand | 024177c | 2014-04-21 19:42:58 -0500 | [diff] [blame] | 225 | struct wl_listener caps_changed_listener; |
| 226 | struct wl_listener pointer_focus_listener; |
| 227 | struct wl_listener keyboard_focus_listener; |
| 228 | |
Giulio Camuffo | 5085a75 | 2013-03-25 21:42:45 +0100 | [diff] [blame] | 229 | struct { |
Kristian Høgsberg | 02bbabb | 2013-05-06 22:15:05 -0400 | [diff] [blame] | 230 | struct weston_pointer_grab grab; |
Jonny Lamb | 76cf1fe | 2014-08-20 11:27:10 +0200 | [diff] [blame] | 231 | struct weston_touch_grab touch_grab; |
Giulio Camuffo | 5085a75 | 2013-03-25 21:42:45 +0100 | [diff] [blame] | 232 | struct wl_list surfaces_list; |
| 233 | struct wl_client *client; |
| 234 | int32_t initial_up; |
Jonny Lamb | 76cf1fe | 2014-08-20 11:27:10 +0200 | [diff] [blame] | 235 | enum { POINTER, TOUCH } type; |
Giulio Camuffo | 5085a75 | 2013-03-25 21:42:45 +0100 | [diff] [blame] | 236 | } popup_grab; |
| 237 | }; |
| 238 | |
Kristian Høgsberg | 2bff94e | 2014-02-11 12:22:51 -0800 | [diff] [blame] | 239 | struct shell_client { |
| 240 | struct wl_resource *resource; |
| 241 | struct wl_client *client; |
| 242 | struct desktop_shell *shell; |
| 243 | struct wl_listener destroy_listener; |
| 244 | struct wl_event_source *ping_timer; |
| 245 | uint32_t ping_serial; |
| 246 | int unresponsive; |
Jonas Ådahl | 49d77d2 | 2015-03-18 16:20:51 +0800 | [diff] [blame] | 247 | struct wl_list surface_list; |
Kristian Høgsberg | 2bff94e | 2014-02-11 12:22:51 -0800 | [diff] [blame] | 248 | }; |
| 249 | |
Alex Wu | bd3354b | 2012-04-17 17:20:49 +0800 | [diff] [blame] | 250 | static struct desktop_shell * |
| 251 | shell_surface_get_shell(struct shell_surface *shsurf); |
| 252 | |
Kristian Høgsberg | 0c36903 | 2013-02-14 21:31:44 -0500 | [diff] [blame] | 253 | static void |
Derek Foreman | 74de469 | 2015-07-15 13:00:39 -0500 | [diff] [blame] | 254 | surface_rotate(struct shell_surface *surface, struct weston_pointer *pointer); |
Kristian Høgsberg | 0c36903 | 2013-02-14 21:31:44 -0500 | [diff] [blame] | 255 | |
Pekka Paalanen | 79346ab | 2013-05-22 18:03:09 +0300 | [diff] [blame] | 256 | static void |
| 257 | shell_fade_startup(struct desktop_shell *shell); |
| 258 | |
Philip Withnall | becb77e | 2013-11-25 18:01:30 +0000 | [diff] [blame] | 259 | static struct shell_seat * |
| 260 | get_shell_seat(struct weston_seat *seat); |
| 261 | |
Jonny Lamb | d73c694 | 2014-08-20 15:53:20 +0200 | [diff] [blame] | 262 | static void |
| 263 | get_output_panel_size(struct desktop_shell *shell, |
| 264 | struct weston_output *output, |
| 265 | int *width, int *height); |
Kristian Høgsberg | ae356ae | 2014-04-29 16:03:54 -0700 | [diff] [blame] | 266 | |
Philip Withnall | 648a4dd | 2013-11-25 18:01:44 +0000 | [diff] [blame] | 267 | static void |
| 268 | shell_surface_update_child_surface_layers(struct shell_surface *shsurf); |
| 269 | |
Alex Wu | bd3354b | 2012-04-17 17:20:49 +0800 | [diff] [blame] | 270 | static bool |
Rafael Antognolli | e2a3455 | 2013-12-03 15:35:45 -0200 | [diff] [blame] | 271 | shell_surface_is_wl_shell_surface(struct shell_surface *shsurf); |
| 272 | |
| 273 | static bool |
| 274 | shell_surface_is_xdg_surface(struct shell_surface *shsurf); |
| 275 | |
| 276 | static bool |
| 277 | shell_surface_is_xdg_popup(struct shell_surface *shsurf); |
| 278 | |
| 279 | static void |
| 280 | shell_surface_set_parent(struct shell_surface *shsurf, |
| 281 | struct weston_surface *parent); |
| 282 | |
Pekka Paalanen | 8274d90 | 2014-08-06 19:36:51 +0300 | [diff] [blame] | 283 | static int |
| 284 | shell_surface_get_label(struct weston_surface *surface, char *buf, size_t len) |
| 285 | { |
| 286 | struct shell_surface *shsurf; |
| 287 | const char *typestr[] = { |
| 288 | [SHELL_SURFACE_NONE] = "unidentified", |
| 289 | [SHELL_SURFACE_TOPLEVEL] = "top-level", |
| 290 | [SHELL_SURFACE_POPUP] = "popup", |
| 291 | [SHELL_SURFACE_XWAYLAND] = "Xwayland", |
| 292 | }; |
| 293 | const char *t, *c; |
| 294 | |
| 295 | shsurf = get_shell_surface(surface); |
| 296 | if (!shsurf) |
| 297 | return snprintf(buf, len, "unidentified window"); |
| 298 | |
| 299 | t = shsurf->title; |
| 300 | c = shsurf->class; |
| 301 | |
| 302 | return snprintf(buf, len, "%s window%s%s%s%s%s", |
| 303 | typestr[shsurf->type], |
| 304 | t ? " '" : "", t ?: "", t ? "'" : "", |
| 305 | c ? " of " : "", c ?: ""); |
| 306 | } |
| 307 | |
Rafael Antognolli | e2a3455 | 2013-12-03 15:35:45 -0200 | [diff] [blame] | 308 | static bool |
Alex Wu | bd3354b | 2012-04-17 17:20:49 +0800 | [diff] [blame] | 309 | shell_surface_is_top_fullscreen(struct shell_surface *shsurf) |
| 310 | { |
| 311 | struct desktop_shell *shell; |
Mario Kleiner | 9f4d655 | 2015-06-21 21:25:08 +0200 | [diff] [blame] | 312 | struct weston_view *view; |
| 313 | struct shell_surface *top_fs_shsurf = NULL; |
Alex Wu | bd3354b | 2012-04-17 17:20:49 +0800 | [diff] [blame] | 314 | |
| 315 | shell = shell_surface_get_shell(shsurf); |
Quentin Glidic | c0d79ce | 2013-01-29 14:16:13 +0100 | [diff] [blame] | 316 | |
Giulio Camuffo | 412e6a5 | 2014-07-09 22:12:56 +0300 | [diff] [blame] | 317 | if (wl_list_empty(&shell->fullscreen_layer.view_list.link)) |
Alex Wu | bd3354b | 2012-04-17 17:20:49 +0800 | [diff] [blame] | 318 | return false; |
| 319 | |
Mario Kleiner | 9f4d655 | 2015-06-21 21:25:08 +0200 | [diff] [blame] | 320 | /* Find topmost shsurf on the same fullscreen output on which shsurf |
| 321 | * is displaying. We don't care about other outputs. |
| 322 | */ |
| 323 | wl_list_for_each(view, &shell->fullscreen_layer.view_list.link, |
| 324 | layer_link.link) { |
| 325 | struct shell_surface *cand_shsurf = get_shell_surface(view->surface); |
| 326 | |
| 327 | if (cand_shsurf && |
| 328 | (cand_shsurf->fullscreen_output == shsurf->fullscreen_output)) { |
| 329 | top_fs_shsurf = cand_shsurf; |
| 330 | break; |
| 331 | } |
| 332 | } |
| 333 | |
| 334 | return (shsurf == top_fs_shsurf); |
Alex Wu | bd3354b | 2012-04-17 17:20:49 +0800 | [diff] [blame] | 335 | } |
| 336 | |
Kristian Høgsberg | 6af8eb9 | 2012-01-25 16:57:11 -0500 | [diff] [blame] | 337 | static void |
Kristian Høgsberg | 27e3052 | 2012-04-11 23:18:23 -0400 | [diff] [blame] | 338 | destroy_shell_grab_shsurf(struct wl_listener *listener, void *data) |
Ander Conselvan de Oliveira | fe0444a | 2012-04-04 17:48:05 +0300 | [diff] [blame] | 339 | { |
| 340 | struct shell_grab *grab; |
| 341 | |
| 342 | grab = container_of(listener, struct shell_grab, |
| 343 | shsurf_destroy_listener); |
| 344 | |
| 345 | grab->shsurf = NULL; |
| 346 | } |
| 347 | |
Kristian Høgsberg | 1ef2313 | 2013-12-04 00:20:01 -0800 | [diff] [blame] | 348 | struct weston_view * |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 349 | get_default_view(struct weston_surface *surface) |
| 350 | { |
| 351 | struct shell_surface *shsurf; |
| 352 | struct weston_view *view; |
| 353 | |
| 354 | if (!surface || wl_list_empty(&surface->views)) |
| 355 | return NULL; |
| 356 | |
| 357 | shsurf = get_shell_surface(surface); |
| 358 | if (shsurf) |
| 359 | return shsurf->view; |
| 360 | |
| 361 | wl_list_for_each(view, &surface->views, surface_link) |
| 362 | if (weston_view_is_mapped(view)) |
| 363 | return view; |
| 364 | |
| 365 | return container_of(surface->views.next, struct weston_view, surface_link); |
| 366 | } |
| 367 | |
Ander Conselvan de Oliveira | fe0444a | 2012-04-04 17:48:05 +0300 | [diff] [blame] | 368 | static void |
Kristian Høgsberg | 02bbabb | 2013-05-06 22:15:05 -0400 | [diff] [blame] | 369 | popup_grab_end(struct weston_pointer *pointer); |
Jonny Lamb | 76cf1fe | 2014-08-20 11:27:10 +0200 | [diff] [blame] | 370 | static void |
| 371 | touch_popup_grab_end(struct weston_touch *touch); |
Kristian Høgsberg | 57e0907 | 2012-10-30 14:07:27 -0400 | [diff] [blame] | 372 | |
| 373 | static void |
Ander Conselvan de Oliveira | b9d2a0f | 2012-06-28 18:08:05 +0300 | [diff] [blame] | 374 | shell_grab_start(struct shell_grab *grab, |
Kristian Høgsberg | 02bbabb | 2013-05-06 22:15:05 -0400 | [diff] [blame] | 375 | const struct weston_pointer_grab_interface *interface, |
Ander Conselvan de Oliveira | b9d2a0f | 2012-06-28 18:08:05 +0300 | [diff] [blame] | 376 | struct shell_surface *shsurf, |
Kristian Høgsberg | 02bbabb | 2013-05-06 22:15:05 -0400 | [diff] [blame] | 377 | struct weston_pointer *pointer, |
Ander Conselvan de Oliveira | b9d2a0f | 2012-06-28 18:08:05 +0300 | [diff] [blame] | 378 | enum desktop_shell_cursor cursor) |
Ander Conselvan de Oliveira | fe0444a | 2012-04-04 17:48:05 +0300 | [diff] [blame] | 379 | { |
Ander Conselvan de Oliveira | b9d2a0f | 2012-06-28 18:08:05 +0300 | [diff] [blame] | 380 | struct desktop_shell *shell = shsurf->shell; |
Derek Foreman | 1281a36 | 2015-07-31 16:55:32 -0500 | [diff] [blame] | 381 | struct weston_touch *touch = weston_seat_get_touch(pointer->seat); |
Ander Conselvan de Oliveira | b9d2a0f | 2012-06-28 18:08:05 +0300 | [diff] [blame] | 382 | |
Kristian Høgsberg | 57e0907 | 2012-10-30 14:07:27 -0400 | [diff] [blame] | 383 | popup_grab_end(pointer); |
Derek Foreman | 1281a36 | 2015-07-31 16:55:32 -0500 | [diff] [blame] | 384 | if (touch) |
| 385 | touch_popup_grab_end(touch); |
Kristian Høgsberg | 57e0907 | 2012-10-30 14:07:27 -0400 | [diff] [blame] | 386 | |
Ander Conselvan de Oliveira | fe0444a | 2012-04-04 17:48:05 +0300 | [diff] [blame] | 387 | grab->grab.interface = interface; |
| 388 | grab->shsurf = shsurf; |
Kristian Høgsberg | 27e3052 | 2012-04-11 23:18:23 -0400 | [diff] [blame] | 389 | grab->shsurf_destroy_listener.notify = destroy_shell_grab_shsurf; |
Jason Ekstrand | 651f00e | 2013-06-14 10:07:54 -0500 | [diff] [blame] | 390 | wl_signal_add(&shsurf->destroy_signal, |
Kristian Høgsberg | 27e3052 | 2012-04-11 23:18:23 -0400 | [diff] [blame] | 391 | &grab->shsurf_destroy_listener); |
Ander Conselvan de Oliveira | fe0444a | 2012-04-04 17:48:05 +0300 | [diff] [blame] | 392 | |
Kristian Høgsberg | c85f1d4 | 2013-10-24 16:52:00 -0700 | [diff] [blame] | 393 | shsurf->grabbed = 1; |
Kristian Høgsberg | 02bbabb | 2013-05-06 22:15:05 -0400 | [diff] [blame] | 394 | weston_pointer_start_grab(pointer, &grab->grab); |
Kristian Høgsberg | c9974a0 | 2013-07-03 19:24:57 -0400 | [diff] [blame] | 395 | if (shell->child.desktop_shell) { |
| 396 | desktop_shell_send_grab_cursor(shell->child.desktop_shell, |
| 397 | cursor); |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 398 | weston_pointer_set_focus(pointer, |
| 399 | get_default_view(shell->grab_surface), |
Kristian Høgsberg | c9974a0 | 2013-07-03 19:24:57 -0400 | [diff] [blame] | 400 | wl_fixed_from_int(0), |
| 401 | wl_fixed_from_int(0)); |
| 402 | } |
Ander Conselvan de Oliveira | fe0444a | 2012-04-04 17:48:05 +0300 | [diff] [blame] | 403 | } |
| 404 | |
Jonny Lamb | d73c694 | 2014-08-20 15:53:20 +0200 | [diff] [blame] | 405 | static void |
| 406 | get_output_panel_size(struct desktop_shell *shell, |
| 407 | struct weston_output *output, |
| 408 | int *width, |
| 409 | int *height) |
Jasper St. Pierre | 6458ec3 | 2014-04-11 16:00:31 -0700 | [diff] [blame] | 410 | { |
| 411 | struct weston_view *view; |
Jonny Lamb | d73c694 | 2014-08-20 15:53:20 +0200 | [diff] [blame] | 412 | |
| 413 | *width = 0; |
| 414 | *height = 0; |
Jasper St. Pierre | 6458ec3 | 2014-04-11 16:00:31 -0700 | [diff] [blame] | 415 | |
| 416 | if (!output) |
Jonny Lamb | d73c694 | 2014-08-20 15:53:20 +0200 | [diff] [blame] | 417 | return; |
Jasper St. Pierre | 6458ec3 | 2014-04-11 16:00:31 -0700 | [diff] [blame] | 418 | |
Giulio Camuffo | 412e6a5 | 2014-07-09 22:12:56 +0300 | [diff] [blame] | 419 | wl_list_for_each(view, &shell->panel_layer.view_list.link, layer_link.link) { |
Jonny Lamb | d73c694 | 2014-08-20 15:53:20 +0200 | [diff] [blame] | 420 | float x, y; |
| 421 | |
| 422 | if (view->surface->output != output) |
| 423 | continue; |
| 424 | |
| 425 | switch (shell->panel_position) { |
| 426 | case DESKTOP_SHELL_PANEL_POSITION_TOP: |
| 427 | case DESKTOP_SHELL_PANEL_POSITION_BOTTOM: |
Jonny Lamb | d73c694 | 2014-08-20 15:53:20 +0200 | [diff] [blame] | 428 | weston_view_to_global_float(view, |
| 429 | view->surface->width, 0, |
| 430 | &x, &y); |
| 431 | |
Derek Foreman | 612341f | 2015-04-15 12:23:55 -0500 | [diff] [blame] | 432 | *width = (int)x - output->x; |
| 433 | *height = view->surface->height + (int) y - output->y; |
Jonny Lamb | d73c694 | 2014-08-20 15:53:20 +0200 | [diff] [blame] | 434 | return; |
| 435 | |
| 436 | case DESKTOP_SHELL_PANEL_POSITION_LEFT: |
| 437 | case DESKTOP_SHELL_PANEL_POSITION_RIGHT: |
| 438 | weston_view_to_global_float(view, |
| 439 | 0, view->surface->height, |
| 440 | &x, &y); |
| 441 | |
Derek Foreman | 612341f | 2015-04-15 12:23:55 -0500 | [diff] [blame] | 442 | *width = view->surface->width + (int)x - output->x; |
| 443 | *height = (int)y - output->y; |
Jonny Lamb | d73c694 | 2014-08-20 15:53:20 +0200 | [diff] [blame] | 444 | return; |
| 445 | |
| 446 | default: |
| 447 | /* we've already set width and height to |
| 448 | * fallback values. */ |
Jasper St. Pierre | 6458ec3 | 2014-04-11 16:00:31 -0700 | [diff] [blame] | 449 | break; |
| 450 | } |
| 451 | } |
| 452 | |
Jonny Lamb | d73c694 | 2014-08-20 15:53:20 +0200 | [diff] [blame] | 453 | /* the correct view wasn't found */ |
| 454 | } |
| 455 | |
| 456 | static void |
| 457 | get_output_work_area(struct desktop_shell *shell, |
| 458 | struct weston_output *output, |
| 459 | pixman_rectangle32_t *area) |
| 460 | { |
| 461 | int32_t panel_width = 0, panel_height = 0; |
| 462 | |
Derek Foreman | f814c5d | 2015-04-15 12:23:54 -0500 | [diff] [blame] | 463 | area->x = output->x; |
| 464 | area->y = output->y; |
Jonny Lamb | d73c694 | 2014-08-20 15:53:20 +0200 | [diff] [blame] | 465 | |
| 466 | get_output_panel_size(shell, output, &panel_width, &panel_height); |
Jonny Lamb | d73c694 | 2014-08-20 15:53:20 +0200 | [diff] [blame] | 467 | switch (shell->panel_position) { |
| 468 | case DESKTOP_SHELL_PANEL_POSITION_TOP: |
| 469 | default: |
Derek Foreman | f814c5d | 2015-04-15 12:23:54 -0500 | [diff] [blame] | 470 | area->y += panel_height; |
Jonny Lamb | d73c694 | 2014-08-20 15:53:20 +0200 | [diff] [blame] | 471 | case DESKTOP_SHELL_PANEL_POSITION_BOTTOM: |
| 472 | area->width = output->width; |
| 473 | area->height = output->height - panel_height; |
| 474 | break; |
| 475 | case DESKTOP_SHELL_PANEL_POSITION_LEFT: |
Derek Foreman | f814c5d | 2015-04-15 12:23:54 -0500 | [diff] [blame] | 476 | area->x += panel_width; |
Jonny Lamb | d73c694 | 2014-08-20 15:53:20 +0200 | [diff] [blame] | 477 | case DESKTOP_SHELL_PANEL_POSITION_RIGHT: |
| 478 | area->width = output->width - panel_width; |
| 479 | area->height = output->height; |
| 480 | break; |
| 481 | } |
Jasper St. Pierre | 6458ec3 | 2014-04-11 16:00:31 -0700 | [diff] [blame] | 482 | } |
| 483 | |
Derek Foreman | 45a7c27 | 2015-09-11 14:27:40 -0500 | [diff] [blame] | 484 | static struct shell_surface * |
| 485 | find_toplevel_surface(struct shell_surface *in_surface) |
| 486 | { |
| 487 | struct shell_surface *surface = in_surface; |
| 488 | |
| 489 | if (!surface) |
| 490 | return NULL; |
| 491 | |
| 492 | while (surface->parent) |
| 493 | surface = get_shell_surface(surface->parent); |
| 494 | |
| 495 | /* If no top level surface was found, just use whatever surface was |
| 496 | originally provided. */ |
| 497 | if (!surface || surface->type != SHELL_SURFACE_TOPLEVEL) |
| 498 | surface = in_surface; |
| 499 | |
| 500 | return surface; |
| 501 | } |
| 502 | |
Jasper St. Pierre | 6458ec3 | 2014-04-11 16:00:31 -0700 | [diff] [blame] | 503 | static void |
| 504 | send_configure_for_surface(struct shell_surface *shsurf) |
| 505 | { |
| 506 | int32_t width, height; |
| 507 | struct surface_state *state; |
| 508 | |
| 509 | if (shsurf->state_requested) |
| 510 | state = &shsurf->requested_state; |
| 511 | else if (shsurf->state_changed) |
| 512 | state = &shsurf->next_state; |
| 513 | else |
| 514 | state = &shsurf->state; |
| 515 | |
| 516 | if (state->fullscreen) { |
| 517 | width = shsurf->output->width; |
| 518 | height = shsurf->output->height; |
| 519 | } else if (state->maximized) { |
| 520 | struct desktop_shell *shell; |
Jonny Lamb | d73c694 | 2014-08-20 15:53:20 +0200 | [diff] [blame] | 521 | pixman_rectangle32_t area; |
Jasper St. Pierre | 6458ec3 | 2014-04-11 16:00:31 -0700 | [diff] [blame] | 522 | |
| 523 | shell = shell_surface_get_shell(shsurf); |
Jonny Lamb | d73c694 | 2014-08-20 15:53:20 +0200 | [diff] [blame] | 524 | get_output_work_area(shell, shsurf->output, &area); |
Jasper St. Pierre | 6458ec3 | 2014-04-11 16:00:31 -0700 | [diff] [blame] | 525 | |
Jonny Lamb | d73c694 | 2014-08-20 15:53:20 +0200 | [diff] [blame] | 526 | width = area.width; |
| 527 | height = area.height; |
Ryo Munakata | 79954ec | 2015-05-02 21:44:04 +0900 | [diff] [blame] | 528 | } else if (shsurf->resize_edges) { |
| 529 | width = shsurf->geometry.width; |
| 530 | height = shsurf->geometry.height; |
Jasper St. Pierre | 6458ec3 | 2014-04-11 16:00:31 -0700 | [diff] [blame] | 531 | } else { |
| 532 | width = 0; |
| 533 | height = 0; |
| 534 | } |
| 535 | |
| 536 | shsurf->client->send_configure(shsurf->surface, width, height); |
| 537 | } |
| 538 | |
Ander Conselvan de Oliveira | fe0444a | 2012-04-04 17:48:05 +0300 | [diff] [blame] | 539 | static void |
Jasper St. Pierre | 5befdda | 2014-05-06 08:50:47 -0400 | [diff] [blame] | 540 | shell_surface_state_changed(struct shell_surface *shsurf) |
| 541 | { |
Jasper St. Pierre | 6458ec3 | 2014-04-11 16:00:31 -0700 | [diff] [blame] | 542 | if (shell_surface_is_xdg_surface(shsurf)) |
| 543 | send_configure_for_surface(shsurf); |
Jasper St. Pierre | 5befdda | 2014-05-06 08:50:47 -0400 | [diff] [blame] | 544 | } |
| 545 | |
| 546 | static void |
Ander Conselvan de Oliveira | b9d2a0f | 2012-06-28 18:08:05 +0300 | [diff] [blame] | 547 | shell_grab_end(struct shell_grab *grab) |
Ander Conselvan de Oliveira | fe0444a | 2012-04-04 17:48:05 +0300 | [diff] [blame] | 548 | { |
Kristian Høgsberg | c85f1d4 | 2013-10-24 16:52:00 -0700 | [diff] [blame] | 549 | if (grab->shsurf) { |
Kristian Høgsberg | 47b5dca | 2012-06-07 18:08:04 -0400 | [diff] [blame] | 550 | wl_list_remove(&grab->shsurf_destroy_listener.link); |
Kristian Høgsberg | c85f1d4 | 2013-10-24 16:52:00 -0700 | [diff] [blame] | 551 | grab->shsurf->grabbed = 0; |
Jasper St. Pierre | 5befdda | 2014-05-06 08:50:47 -0400 | [diff] [blame] | 552 | |
| 553 | if (grab->shsurf->resize_edges) { |
| 554 | grab->shsurf->resize_edges = 0; |
| 555 | shell_surface_state_changed(grab->shsurf); |
| 556 | } |
Kristian Høgsberg | c85f1d4 | 2013-10-24 16:52:00 -0700 | [diff] [blame] | 557 | } |
Ander Conselvan de Oliveira | b9d2a0f | 2012-06-28 18:08:05 +0300 | [diff] [blame] | 558 | |
Kristian Høgsberg | 9e5d7d1 | 2013-07-22 16:31:53 -0700 | [diff] [blame] | 559 | weston_pointer_end_grab(grab->grab.pointer); |
Ander Conselvan de Oliveira | fe0444a | 2012-04-04 17:48:05 +0300 | [diff] [blame] | 560 | } |
| 561 | |
| 562 | static void |
Rusty Lynch | 1084da5 | 2013-08-15 09:10:08 -0700 | [diff] [blame] | 563 | shell_touch_grab_start(struct shell_touch_grab *grab, |
| 564 | const struct weston_touch_grab_interface *interface, |
| 565 | struct shell_surface *shsurf, |
| 566 | struct weston_touch *touch) |
| 567 | { |
| 568 | struct desktop_shell *shell = shsurf->shell; |
Derek Foreman | 1281a36 | 2015-07-31 16:55:32 -0500 | [diff] [blame] | 569 | struct weston_pointer *pointer = weston_seat_get_pointer(touch->seat); |
U. Artie Eoff | cf5737a | 2014-01-17 10:08:25 -0800 | [diff] [blame] | 570 | |
Jonny Lamb | 76cf1fe | 2014-08-20 11:27:10 +0200 | [diff] [blame] | 571 | touch_popup_grab_end(touch); |
Derek Foreman | 1281a36 | 2015-07-31 16:55:32 -0500 | [diff] [blame] | 572 | if (pointer) |
| 573 | popup_grab_end(pointer); |
Kristian Høgsberg | 74071e0 | 2014-04-29 15:01:16 -0700 | [diff] [blame] | 574 | |
Rusty Lynch | 1084da5 | 2013-08-15 09:10:08 -0700 | [diff] [blame] | 575 | grab->grab.interface = interface; |
| 576 | grab->shsurf = shsurf; |
| 577 | grab->shsurf_destroy_listener.notify = destroy_shell_grab_shsurf; |
| 578 | wl_signal_add(&shsurf->destroy_signal, |
| 579 | &grab->shsurf_destroy_listener); |
| 580 | |
| 581 | grab->touch = touch; |
Kristian Høgsberg | c85f1d4 | 2013-10-24 16:52:00 -0700 | [diff] [blame] | 582 | shsurf->grabbed = 1; |
Rusty Lynch | 1084da5 | 2013-08-15 09:10:08 -0700 | [diff] [blame] | 583 | |
| 584 | weston_touch_start_grab(touch, &grab->grab); |
| 585 | if (shell->child.desktop_shell) |
Derek Foreman | 4c93c08 | 2015-04-30 16:45:41 -0500 | [diff] [blame] | 586 | weston_touch_set_focus(touch, |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 587 | get_default_view(shell->grab_surface)); |
Rusty Lynch | 1084da5 | 2013-08-15 09:10:08 -0700 | [diff] [blame] | 588 | } |
| 589 | |
| 590 | static void |
| 591 | shell_touch_grab_end(struct shell_touch_grab *grab) |
| 592 | { |
Kristian Høgsberg | c85f1d4 | 2013-10-24 16:52:00 -0700 | [diff] [blame] | 593 | if (grab->shsurf) { |
Rusty Lynch | 1084da5 | 2013-08-15 09:10:08 -0700 | [diff] [blame] | 594 | wl_list_remove(&grab->shsurf_destroy_listener.link); |
Kristian Høgsberg | c85f1d4 | 2013-10-24 16:52:00 -0700 | [diff] [blame] | 595 | grab->shsurf->grabbed = 0; |
| 596 | } |
Rusty Lynch | 1084da5 | 2013-08-15 09:10:08 -0700 | [diff] [blame] | 597 | |
| 598 | weston_touch_end_grab(grab->touch); |
| 599 | } |
| 600 | |
| 601 | static void |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 602 | center_on_output(struct weston_view *view, |
Alex Wu | 4539b08 | 2012-03-01 12:57:46 +0800 | [diff] [blame] | 603 | struct weston_output *output); |
| 604 | |
Daniel Stone | 496ca17 | 2012-05-30 16:31:42 +0100 | [diff] [blame] | 605 | static enum weston_keyboard_modifier |
Tiago Vignatti | 0b52d48 | 2012-04-20 18:54:25 +0300 | [diff] [blame] | 606 | get_modifier(char *modifier) |
| 607 | { |
| 608 | if (!modifier) |
| 609 | return MODIFIER_SUPER; |
| 610 | |
| 611 | if (!strcmp("ctrl", modifier)) |
| 612 | return MODIFIER_CTRL; |
| 613 | else if (!strcmp("alt", modifier)) |
| 614 | return MODIFIER_ALT; |
| 615 | else if (!strcmp("super", modifier)) |
| 616 | return MODIFIER_SUPER; |
| 617 | else |
| 618 | return MODIFIER_SUPER; |
| 619 | } |
| 620 | |
Juan Zhao | e10d279 | 2012-04-25 19:09:52 +0800 | [diff] [blame] | 621 | static enum animation_type |
| 622 | get_animation_type(char *animation) |
| 623 | { |
U. Artie Eoff | b571910 | 2014-01-15 14:26:31 -0800 | [diff] [blame] | 624 | if (!animation) |
| 625 | return ANIMATION_NONE; |
| 626 | |
Juan Zhao | e10d279 | 2012-04-25 19:09:52 +0800 | [diff] [blame] | 627 | if (!strcmp("zoom", animation)) |
| 628 | return ANIMATION_ZOOM; |
| 629 | else if (!strcmp("fade", animation)) |
| 630 | return ANIMATION_FADE; |
Louis-Francis Ratté-Boulianne | b482dbd | 2013-11-19 11:37:11 +0100 | [diff] [blame] | 631 | else if (!strcmp("dim-layer", animation)) |
| 632 | return ANIMATION_DIM_LAYER; |
Juan Zhao | e10d279 | 2012-04-25 19:09:52 +0800 | [diff] [blame] | 633 | else |
| 634 | return ANIMATION_NONE; |
| 635 | } |
| 636 | |
Alex Wu | 4539b08 | 2012-03-01 12:57:46 +0800 | [diff] [blame] | 637 | static void |
Kristian Høgsberg | 14e438c | 2013-05-26 21:48:14 -0400 | [diff] [blame] | 638 | shell_configuration(struct desktop_shell *shell) |
Pekka Paalanen | e955f1e | 2011-12-07 11:49:52 +0200 | [diff] [blame] | 639 | { |
Kristian Høgsberg | 673a889 | 2013-05-23 21:40:56 -0400 | [diff] [blame] | 640 | struct weston_config_section *section; |
Derek Foreman | c721043 | 2014-08-21 11:32:38 -0500 | [diff] [blame] | 641 | char *s, *client; |
Pekka Paalanen | 974c094 | 2014-09-05 14:45:09 +0300 | [diff] [blame] | 642 | int ret; |
Pekka Paalanen | e955f1e | 2011-12-07 11:49:52 +0200 | [diff] [blame] | 643 | |
Kristian Høgsberg | 673a889 | 2013-05-23 21:40:56 -0400 | [diff] [blame] | 644 | section = weston_config_get_section(shell->compositor->config, |
Kristian Høgsberg | 673a889 | 2013-05-23 21:40:56 -0400 | [diff] [blame] | 645 | "shell", NULL, NULL); |
Pekka Paalanen | 974c094 | 2014-09-05 14:45:09 +0300 | [diff] [blame] | 646 | ret = asprintf(&client, "%s/%s", weston_config_get_libexec_dir(), |
| 647 | WESTON_SHELL_CLIENT); |
| 648 | if (ret < 0) |
| 649 | client = NULL; |
Kristian Høgsberg | 673a889 | 2013-05-23 21:40:56 -0400 | [diff] [blame] | 650 | weston_config_section_get_string(section, |
Derek Foreman | c721043 | 2014-08-21 11:32:38 -0500 | [diff] [blame] | 651 | "client", &s, client); |
| 652 | free(client); |
Emilio Pozuelo Monfort | 46ce798 | 2013-11-20 13:22:29 +0100 | [diff] [blame] | 653 | shell->client = s; |
| 654 | weston_config_section_get_string(section, |
Kristian Høgsberg | 673a889 | 2013-05-23 21:40:56 -0400 | [diff] [blame] | 655 | "binding-modifier", &s, "super"); |
| 656 | shell->binding_modifier = get_modifier(s); |
Quentin Glidic | 8418c29 | 2013-06-18 09:11:03 +0200 | [diff] [blame] | 657 | free(s); |
Kristian Høgsberg | d56ab4e | 2014-01-16 16:51:52 -0800 | [diff] [blame] | 658 | |
| 659 | weston_config_section_get_string(section, |
| 660 | "exposay-modifier", &s, "none"); |
| 661 | if (strcmp(s, "none") == 0) |
| 662 | shell->exposay_modifier = 0; |
| 663 | else |
| 664 | shell->exposay_modifier = get_modifier(s); |
| 665 | free(s); |
| 666 | |
Kristian Høgsberg | 673a889 | 2013-05-23 21:40:56 -0400 | [diff] [blame] | 667 | weston_config_section_get_string(section, "animation", &s, "none"); |
| 668 | shell->win_animation_type = get_animation_type(s); |
Quentin Glidic | 8418c29 | 2013-06-18 09:11:03 +0200 | [diff] [blame] | 669 | free(s); |
Jonny Lamb | f322f8e | 2014-08-12 15:13:30 +0200 | [diff] [blame] | 670 | weston_config_section_get_string(section, "close-animation", &s, "fade"); |
| 671 | shell->win_close_animation_type = get_animation_type(s); |
| 672 | free(s); |
Kristian Høgsberg | 724c8d9 | 2013-10-16 11:38:24 -0700 | [diff] [blame] | 673 | weston_config_section_get_string(section, |
| 674 | "startup-animation", &s, "fade"); |
| 675 | shell->startup_animation_type = get_animation_type(s); |
| 676 | free(s); |
Kristian Høgsberg | 912e0a1 | 2013-10-30 08:59:55 -0700 | [diff] [blame] | 677 | if (shell->startup_animation_type == ANIMATION_ZOOM) |
| 678 | shell->startup_animation_type = ANIMATION_NONE; |
Louis-Francis Ratté-Boulianne | b482dbd | 2013-11-19 11:37:11 +0100 | [diff] [blame] | 679 | weston_config_section_get_string(section, "focus-animation", &s, "none"); |
| 680 | shell->focus_animation_type = get_animation_type(s); |
| 681 | free(s); |
Kristian Høgsberg | 673a889 | 2013-05-23 21:40:56 -0400 | [diff] [blame] | 682 | weston_config_section_get_uint(section, "num-workspaces", |
| 683 | &shell->workspaces.num, |
| 684 | DEFAULT_NUM_WORKSPACES); |
Jonas Ådahl | e3cddce | 2012-06-13 00:01:22 +0200 | [diff] [blame] | 685 | } |
| 686 | |
Kristian Høgsberg | 1ef2313 | 2013-12-04 00:20:01 -0800 | [diff] [blame] | 687 | struct weston_output * |
Louis-Francis Ratté-Boulianne | b482dbd | 2013-11-19 11:37:11 +0100 | [diff] [blame] | 688 | get_default_output(struct weston_compositor *compositor) |
| 689 | { |
| 690 | return container_of(compositor->output_list.next, |
| 691 | struct weston_output, link); |
| 692 | } |
| 693 | |
Pekka Paalanen | 8274d90 | 2014-08-06 19:36:51 +0300 | [diff] [blame] | 694 | static int |
| 695 | focus_surface_get_label(struct weston_surface *surface, char *buf, size_t len) |
| 696 | { |
| 697 | return snprintf(buf, len, "focus highlight effect for output %s", |
| 698 | surface->output->name); |
| 699 | } |
Louis-Francis Ratté-Boulianne | b482dbd | 2013-11-19 11:37:11 +0100 | [diff] [blame] | 700 | |
| 701 | /* no-op func for checking focus surface */ |
| 702 | static void |
Jason Ekstrand | 918f2dd | 2013-12-02 21:01:53 -0600 | [diff] [blame] | 703 | 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] | 704 | { |
| 705 | } |
| 706 | |
| 707 | static struct focus_surface * |
| 708 | get_focus_surface(struct weston_surface *surface) |
| 709 | { |
| 710 | if (surface->configure == focus_surface_configure) |
| 711 | return surface->configure_private; |
| 712 | else |
| 713 | return NULL; |
| 714 | } |
| 715 | |
| 716 | static bool |
| 717 | is_focus_surface (struct weston_surface *es) |
| 718 | { |
| 719 | return (es->configure == focus_surface_configure); |
| 720 | } |
| 721 | |
| 722 | static bool |
| 723 | is_focus_view (struct weston_view *view) |
| 724 | { |
| 725 | return is_focus_surface (view->surface); |
| 726 | } |
| 727 | |
| 728 | static struct focus_surface * |
| 729 | create_focus_surface(struct weston_compositor *ec, |
| 730 | struct weston_output *output) |
| 731 | { |
| 732 | struct focus_surface *fsurf = NULL; |
| 733 | struct weston_surface *surface = NULL; |
| 734 | |
| 735 | fsurf = malloc(sizeof *fsurf); |
| 736 | if (!fsurf) |
| 737 | return NULL; |
| 738 | |
| 739 | fsurf->surface = weston_surface_create(ec); |
| 740 | surface = fsurf->surface; |
| 741 | if (surface == NULL) { |
| 742 | free(fsurf); |
| 743 | return NULL; |
| 744 | } |
| 745 | |
| 746 | surface->configure = focus_surface_configure; |
| 747 | surface->output = output; |
| 748 | surface->configure_private = fsurf; |
Pekka Paalanen | 8274d90 | 2014-08-06 19:36:51 +0300 | [diff] [blame] | 749 | weston_surface_set_label_func(surface, focus_surface_get_label); |
Louis-Francis Ratté-Boulianne | b482dbd | 2013-11-19 11:37:11 +0100 | [diff] [blame] | 750 | |
U. Artie Eoff | 0b23b2b | 2014-01-15 14:45:59 -0800 | [diff] [blame] | 751 | fsurf->view = weston_view_create(surface); |
| 752 | if (fsurf->view == NULL) { |
| 753 | weston_surface_destroy(surface); |
| 754 | free(fsurf); |
| 755 | return NULL; |
| 756 | } |
Emilio Pozuelo Monfort | da64426 | 2013-11-19 11:37:19 +0100 | [diff] [blame] | 757 | fsurf->view->output = output; |
Louis-Francis Ratté-Boulianne | b482dbd | 2013-11-19 11:37:11 +0100 | [diff] [blame] | 758 | |
Jason Ekstrand | 5c11a33 | 2013-12-04 20:32:03 -0600 | [diff] [blame] | 759 | weston_surface_set_size(surface, output->width, output->height); |
Jason Ekstrand | 918f2dd | 2013-12-02 21:01:53 -0600 | [diff] [blame] | 760 | weston_view_set_position(fsurf->view, output->x, output->y); |
Louis-Francis Ratté-Boulianne | b482dbd | 2013-11-19 11:37:11 +0100 | [diff] [blame] | 761 | weston_surface_set_color(surface, 0.0, 0.0, 0.0, 1.0); |
| 762 | pixman_region32_fini(&surface->opaque); |
| 763 | pixman_region32_init_rect(&surface->opaque, output->x, output->y, |
| 764 | output->width, output->height); |
| 765 | pixman_region32_fini(&surface->input); |
| 766 | pixman_region32_init(&surface->input); |
| 767 | |
| 768 | wl_list_init(&fsurf->workspace_transform.link); |
| 769 | |
| 770 | return fsurf; |
| 771 | } |
| 772 | |
| 773 | static void |
| 774 | focus_surface_destroy(struct focus_surface *fsurf) |
| 775 | { |
| 776 | weston_surface_destroy(fsurf->surface); |
| 777 | free(fsurf); |
| 778 | } |
| 779 | |
| 780 | static void |
| 781 | focus_animation_done(struct weston_view_animation *animation, void *data) |
| 782 | { |
| 783 | struct workspace *ws = data; |
| 784 | |
| 785 | ws->focus_animation = NULL; |
| 786 | } |
| 787 | |
Jonas Ådahl | e3cddce | 2012-06-13 00:01:22 +0200 | [diff] [blame] | 788 | static void |
Jonas Ådahl | 0476974 | 2012-06-13 00:01:24 +0200 | [diff] [blame] | 789 | focus_state_destroy(struct focus_state *state) |
| 790 | { |
| 791 | wl_list_remove(&state->seat_destroy_listener.link); |
| 792 | wl_list_remove(&state->surface_destroy_listener.link); |
| 793 | free(state); |
| 794 | } |
| 795 | |
| 796 | static void |
| 797 | focus_state_seat_destroy(struct wl_listener *listener, void *data) |
| 798 | { |
| 799 | struct focus_state *state = container_of(listener, |
| 800 | struct focus_state, |
| 801 | seat_destroy_listener); |
| 802 | |
| 803 | wl_list_remove(&state->link); |
| 804 | focus_state_destroy(state); |
| 805 | } |
| 806 | |
| 807 | static void |
| 808 | focus_state_surface_destroy(struct wl_listener *listener, void *data) |
| 809 | { |
| 810 | struct focus_state *state = container_of(listener, |
| 811 | struct focus_state, |
Kristian Høgsberg | b8e0d0f | 2012-07-31 10:30:26 -0400 | [diff] [blame] | 812 | surface_destroy_listener); |
Kristian Høgsberg | e377822 | 2012-07-31 17:29:30 -0400 | [diff] [blame] | 813 | struct desktop_shell *shell; |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 814 | struct weston_surface *main_surface, *next; |
| 815 | struct weston_view *view; |
Jonas Ådahl | 0476974 | 2012-06-13 00:01:24 +0200 | [diff] [blame] | 816 | |
Pekka Paalanen | 01388e2 | 2013-04-25 13:57:44 +0300 | [diff] [blame] | 817 | main_surface = weston_surface_get_main_surface(state->keyboard_focus); |
| 818 | |
Kristian Høgsberg | e377822 | 2012-07-31 17:29:30 -0400 | [diff] [blame] | 819 | next = NULL; |
Giulio Camuffo | 412e6a5 | 2014-07-09 22:12:56 +0300 | [diff] [blame] | 820 | wl_list_for_each(view, |
| 821 | &state->ws->layer.view_list.link, layer_link.link) { |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 822 | if (view->surface == main_surface) |
Kristian Høgsberg | e377822 | 2012-07-31 17:29:30 -0400 | [diff] [blame] | 823 | continue; |
Louis-Francis Ratté-Boulianne | b482dbd | 2013-11-19 11:37:11 +0100 | [diff] [blame] | 824 | if (is_focus_view(view)) |
| 825 | continue; |
Kristian Høgsberg | e377822 | 2012-07-31 17:29:30 -0400 | [diff] [blame] | 826 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 827 | next = view->surface; |
Kristian Høgsberg | e377822 | 2012-07-31 17:29:30 -0400 | [diff] [blame] | 828 | break; |
| 829 | } |
| 830 | |
Pekka Paalanen | 01388e2 | 2013-04-25 13:57:44 +0300 | [diff] [blame] | 831 | /* if the focus was a sub-surface, activate its main surface */ |
| 832 | if (main_surface != state->keyboard_focus) |
| 833 | next = main_surface; |
| 834 | |
Louis-Francis Ratté-Boulianne | b482dbd | 2013-11-19 11:37:11 +0100 | [diff] [blame] | 835 | shell = state->seat->compositor->shell_interface.shell; |
Kristian Høgsberg | e377822 | 2012-07-31 17:29:30 -0400 | [diff] [blame] | 836 | if (next) { |
Louis-Francis Ratté-Boulianne | b482dbd | 2013-11-19 11:37:11 +0100 | [diff] [blame] | 837 | state->keyboard_focus = NULL; |
Emilio Pozuelo Monfort | 9e7c759 | 2014-01-30 14:01:10 +0100 | [diff] [blame] | 838 | activate(shell, next, state->seat, true); |
Kristian Høgsberg | e377822 | 2012-07-31 17:29:30 -0400 | [diff] [blame] | 839 | } else { |
Louis-Francis Ratté-Boulianne | b482dbd | 2013-11-19 11:37:11 +0100 | [diff] [blame] | 840 | if (shell->focus_animation_type == ANIMATION_DIM_LAYER) { |
| 841 | if (state->ws->focus_animation) |
| 842 | weston_view_animation_destroy(state->ws->focus_animation); |
| 843 | |
| 844 | state->ws->focus_animation = weston_fade_run( |
| 845 | state->ws->fsurf_front->view, |
| 846 | state->ws->fsurf_front->view->alpha, 0.0, 300, |
| 847 | focus_animation_done, state->ws); |
| 848 | } |
| 849 | |
Kristian Høgsberg | e377822 | 2012-07-31 17:29:30 -0400 | [diff] [blame] | 850 | wl_list_remove(&state->link); |
| 851 | focus_state_destroy(state); |
| 852 | } |
Jonas Ådahl | 0476974 | 2012-06-13 00:01:24 +0200 | [diff] [blame] | 853 | } |
| 854 | |
| 855 | static struct focus_state * |
Kristian Høgsberg | 2f5faff | 2012-07-31 16:36:34 -0400 | [diff] [blame] | 856 | focus_state_create(struct weston_seat *seat, struct workspace *ws) |
Jonas Ådahl | 0476974 | 2012-06-13 00:01:24 +0200 | [diff] [blame] | 857 | { |
Jonas Ådahl | 0476974 | 2012-06-13 00:01:24 +0200 | [diff] [blame] | 858 | struct focus_state *state; |
Jonas Ådahl | 0476974 | 2012-06-13 00:01:24 +0200 | [diff] [blame] | 859 | |
| 860 | state = malloc(sizeof *state); |
| 861 | if (state == NULL) |
| 862 | return NULL; |
| 863 | |
Louis-Francis Ratté-Boulianne | b482dbd | 2013-11-19 11:37:11 +0100 | [diff] [blame] | 864 | state->keyboard_focus = NULL; |
Kristian Høgsberg | 2f5faff | 2012-07-31 16:36:34 -0400 | [diff] [blame] | 865 | state->ws = ws; |
Jonas Ådahl | 0476974 | 2012-06-13 00:01:24 +0200 | [diff] [blame] | 866 | state->seat = seat; |
Kristian Høgsberg | 2f5faff | 2012-07-31 16:36:34 -0400 | [diff] [blame] | 867 | wl_list_insert(&ws->focus_list, &state->link); |
Jonas Ådahl | 0476974 | 2012-06-13 00:01:24 +0200 | [diff] [blame] | 868 | |
| 869 | state->seat_destroy_listener.notify = focus_state_seat_destroy; |
| 870 | state->surface_destroy_listener.notify = focus_state_surface_destroy; |
Kristian Høgsberg | 4912454 | 2013-05-06 22:27:40 -0400 | [diff] [blame] | 871 | wl_signal_add(&seat->destroy_signal, |
Jonas Ådahl | 0476974 | 2012-06-13 00:01:24 +0200 | [diff] [blame] | 872 | &state->seat_destroy_listener); |
Kristian Høgsberg | 2f5faff | 2012-07-31 16:36:34 -0400 | [diff] [blame] | 873 | wl_list_init(&state->surface_destroy_listener.link); |
Jonas Ådahl | 0476974 | 2012-06-13 00:01:24 +0200 | [diff] [blame] | 874 | |
| 875 | return state; |
| 876 | } |
| 877 | |
Jonas Ådahl | 8538b22 | 2012-08-29 22:13:03 +0200 | [diff] [blame] | 878 | static struct focus_state * |
| 879 | ensure_focus_state(struct desktop_shell *shell, struct weston_seat *seat) |
| 880 | { |
| 881 | struct workspace *ws = get_current_workspace(shell); |
| 882 | struct focus_state *state; |
| 883 | |
| 884 | wl_list_for_each(state, &ws->focus_list, link) |
| 885 | if (state->seat == seat) |
| 886 | break; |
| 887 | |
| 888 | if (&state->link == &ws->focus_list) |
| 889 | state = focus_state_create(seat, ws); |
| 890 | |
| 891 | return state; |
| 892 | } |
| 893 | |
Jonas Ådahl | 0476974 | 2012-06-13 00:01:24 +0200 | [diff] [blame] | 894 | static void |
Kristian Høgsberg | d500bf1 | 2014-01-22 12:25:20 -0800 | [diff] [blame] | 895 | focus_state_set_focus(struct focus_state *state, |
| 896 | struct weston_surface *surface) |
| 897 | { |
| 898 | if (state->keyboard_focus) { |
| 899 | wl_list_remove(&state->surface_destroy_listener.link); |
| 900 | wl_list_init(&state->surface_destroy_listener.link); |
| 901 | } |
| 902 | |
| 903 | state->keyboard_focus = surface; |
| 904 | if (surface) |
| 905 | wl_signal_add(&surface->destroy_signal, |
| 906 | &state->surface_destroy_listener); |
| 907 | } |
| 908 | |
| 909 | static void |
Kristian Høgsberg | 2f5faff | 2012-07-31 16:36:34 -0400 | [diff] [blame] | 910 | restore_focus_state(struct desktop_shell *shell, struct workspace *ws) |
Jonas Ådahl | 0476974 | 2012-06-13 00:01:24 +0200 | [diff] [blame] | 911 | { |
| 912 | struct focus_state *state, *next; |
Kristian Høgsberg | fe7aa90 | 2013-05-08 09:54:37 -0400 | [diff] [blame] | 913 | struct weston_surface *surface; |
Neil Roberts | 4237f50 | 2014-04-09 16:33:31 +0100 | [diff] [blame] | 914 | struct wl_list pending_seat_list; |
| 915 | struct weston_seat *seat, *next_seat; |
| 916 | |
| 917 | /* Temporarily steal the list of seats so that we can keep |
| 918 | * track of the seats we've already processed */ |
| 919 | wl_list_init(&pending_seat_list); |
| 920 | wl_list_insert_list(&pending_seat_list, &shell->compositor->seat_list); |
| 921 | wl_list_init(&shell->compositor->seat_list); |
Jonas Ådahl | 0476974 | 2012-06-13 00:01:24 +0200 | [diff] [blame] | 922 | |
| 923 | wl_list_for_each_safe(state, next, &ws->focus_list, link) { |
Derek Foreman | 1281a36 | 2015-07-31 16:55:32 -0500 | [diff] [blame] | 924 | struct weston_keyboard *keyboard = |
| 925 | weston_seat_get_keyboard(state->seat); |
| 926 | |
Neil Roberts | 4237f50 | 2014-04-09 16:33:31 +0100 | [diff] [blame] | 927 | wl_list_remove(&state->seat->link); |
| 928 | wl_list_insert(&shell->compositor->seat_list, |
| 929 | &state->seat->link); |
| 930 | |
Derek Foreman | 1281a36 | 2015-07-31 16:55:32 -0500 | [diff] [blame] | 931 | if (!keyboard) |
Kristian Høgsberg | e61d2f4 | 2014-01-17 12:18:53 -0800 | [diff] [blame] | 932 | continue; |
| 933 | |
Kristian Høgsberg | fe7aa90 | 2013-05-08 09:54:37 -0400 | [diff] [blame] | 934 | surface = state->keyboard_focus; |
Jonas Ådahl | 5689944 | 2012-08-29 22:12:59 +0200 | [diff] [blame] | 935 | |
Derek Foreman | 1281a36 | 2015-07-31 16:55:32 -0500 | [diff] [blame] | 936 | weston_keyboard_set_focus(keyboard, surface); |
Jonas Ådahl | 0476974 | 2012-06-13 00:01:24 +0200 | [diff] [blame] | 937 | } |
Neil Roberts | 4237f50 | 2014-04-09 16:33:31 +0100 | [diff] [blame] | 938 | |
| 939 | /* For any remaining seats that we don't have a focus state |
| 940 | * for we'll reset the keyboard focus to NULL */ |
| 941 | wl_list_for_each_safe(seat, next_seat, &pending_seat_list, link) { |
Derek Foreman | 1281a36 | 2015-07-31 16:55:32 -0500 | [diff] [blame] | 942 | struct weston_keyboard *keyboard = |
| 943 | weston_seat_get_keyboard(seat); |
| 944 | |
Neil Roberts | 4237f50 | 2014-04-09 16:33:31 +0100 | [diff] [blame] | 945 | wl_list_insert(&shell->compositor->seat_list, &seat->link); |
| 946 | |
Derek Foreman | 1281a36 | 2015-07-31 16:55:32 -0500 | [diff] [blame] | 947 | if (!keyboard) |
Neil Roberts | 4237f50 | 2014-04-09 16:33:31 +0100 | [diff] [blame] | 948 | continue; |
| 949 | |
Derek Foreman | 1281a36 | 2015-07-31 16:55:32 -0500 | [diff] [blame] | 950 | weston_keyboard_set_focus(keyboard, NULL); |
Neil Roberts | 4237f50 | 2014-04-09 16:33:31 +0100 | [diff] [blame] | 951 | } |
Jonas Ådahl | 0476974 | 2012-06-13 00:01:24 +0200 | [diff] [blame] | 952 | } |
| 953 | |
| 954 | static void |
Jonas Ådahl | 8de6a1d | 2012-08-29 22:13:00 +0200 | [diff] [blame] | 955 | replace_focus_state(struct desktop_shell *shell, struct workspace *ws, |
| 956 | struct weston_seat *seat) |
| 957 | { |
Derek Foreman | 1281a36 | 2015-07-31 16:55:32 -0500 | [diff] [blame] | 958 | struct weston_keyboard *keyboard = weston_seat_get_keyboard(seat); |
Jonas Ådahl | 8de6a1d | 2012-08-29 22:13:00 +0200 | [diff] [blame] | 959 | struct focus_state *state; |
Jonas Ådahl | 8de6a1d | 2012-08-29 22:13:00 +0200 | [diff] [blame] | 960 | |
| 961 | wl_list_for_each(state, &ws->focus_list, link) { |
| 962 | if (state->seat == seat) { |
Derek Foreman | 1281a36 | 2015-07-31 16:55:32 -0500 | [diff] [blame] | 963 | focus_state_set_focus(state, keyboard->focus); |
Jonas Ådahl | 8de6a1d | 2012-08-29 22:13:00 +0200 | [diff] [blame] | 964 | return; |
| 965 | } |
| 966 | } |
| 967 | } |
| 968 | |
| 969 | static void |
| 970 | drop_focus_state(struct desktop_shell *shell, struct workspace *ws, |
| 971 | struct weston_surface *surface) |
| 972 | { |
| 973 | struct focus_state *state; |
| 974 | |
| 975 | wl_list_for_each(state, &ws->focus_list, link) |
| 976 | if (state->keyboard_focus == surface) |
Kristian Høgsberg | d500bf1 | 2014-01-22 12:25:20 -0800 | [diff] [blame] | 977 | focus_state_set_focus(state, NULL); |
Jonas Ådahl | 8de6a1d | 2012-08-29 22:13:00 +0200 | [diff] [blame] | 978 | } |
| 979 | |
| 980 | static void |
Louis-Francis Ratté-Boulianne | b482dbd | 2013-11-19 11:37:11 +0100 | [diff] [blame] | 981 | animate_focus_change(struct desktop_shell *shell, struct workspace *ws, |
| 982 | struct weston_view *from, struct weston_view *to) |
| 983 | { |
| 984 | struct weston_output *output; |
| 985 | bool focus_surface_created = false; |
| 986 | |
| 987 | /* FIXME: Only support dim animation using two layers */ |
| 988 | if (from == to || shell->focus_animation_type != ANIMATION_DIM_LAYER) |
| 989 | return; |
| 990 | |
| 991 | output = get_default_output(shell->compositor); |
| 992 | if (ws->fsurf_front == NULL && (from || to)) { |
| 993 | ws->fsurf_front = create_focus_surface(shell->compositor, output); |
U. Artie Eoff | 0b23b2b | 2014-01-15 14:45:59 -0800 | [diff] [blame] | 994 | if (ws->fsurf_front == NULL) |
| 995 | return; |
Louis-Francis Ratté-Boulianne | b482dbd | 2013-11-19 11:37:11 +0100 | [diff] [blame] | 996 | ws->fsurf_front->view->alpha = 0.0; |
U. Artie Eoff | 0b23b2b | 2014-01-15 14:45:59 -0800 | [diff] [blame] | 997 | |
| 998 | ws->fsurf_back = create_focus_surface(shell->compositor, output); |
| 999 | if (ws->fsurf_back == NULL) { |
| 1000 | focus_surface_destroy(ws->fsurf_front); |
| 1001 | return; |
| 1002 | } |
Louis-Francis Ratté-Boulianne | b482dbd | 2013-11-19 11:37:11 +0100 | [diff] [blame] | 1003 | ws->fsurf_back->view->alpha = 0.0; |
U. Artie Eoff | 0b23b2b | 2014-01-15 14:45:59 -0800 | [diff] [blame] | 1004 | |
Louis-Francis Ratté-Boulianne | b482dbd | 2013-11-19 11:37:11 +0100 | [diff] [blame] | 1005 | focus_surface_created = true; |
| 1006 | } else { |
Giulio Camuffo | 412e6a5 | 2014-07-09 22:12:56 +0300 | [diff] [blame] | 1007 | weston_layer_entry_remove(&ws->fsurf_front->view->layer_link); |
| 1008 | weston_layer_entry_remove(&ws->fsurf_back->view->layer_link); |
Louis-Francis Ratté-Boulianne | b482dbd | 2013-11-19 11:37:11 +0100 | [diff] [blame] | 1009 | } |
| 1010 | |
| 1011 | if (ws->focus_animation) { |
| 1012 | weston_view_animation_destroy(ws->focus_animation); |
| 1013 | ws->focus_animation = NULL; |
| 1014 | } |
| 1015 | |
| 1016 | if (to) |
Giulio Camuffo | 412e6a5 | 2014-07-09 22:12:56 +0300 | [diff] [blame] | 1017 | weston_layer_entry_insert(&to->layer_link, |
| 1018 | &ws->fsurf_front->view->layer_link); |
Louis-Francis Ratté-Boulianne | b482dbd | 2013-11-19 11:37:11 +0100 | [diff] [blame] | 1019 | else if (from) |
Giulio Camuffo | 412e6a5 | 2014-07-09 22:12:56 +0300 | [diff] [blame] | 1020 | weston_layer_entry_insert(&ws->layer.view_list, |
| 1021 | &ws->fsurf_front->view->layer_link); |
Louis-Francis Ratté-Boulianne | b482dbd | 2013-11-19 11:37:11 +0100 | [diff] [blame] | 1022 | |
| 1023 | if (focus_surface_created) { |
| 1024 | ws->focus_animation = weston_fade_run( |
| 1025 | ws->fsurf_front->view, |
Jonny Lamb | 7e7d485 | 2014-05-22 22:41:34 +0200 | [diff] [blame] | 1026 | ws->fsurf_front->view->alpha, 0.4, 300, |
Louis-Francis Ratté-Boulianne | b482dbd | 2013-11-19 11:37:11 +0100 | [diff] [blame] | 1027 | focus_animation_done, ws); |
| 1028 | } else if (from) { |
Giulio Camuffo | 412e6a5 | 2014-07-09 22:12:56 +0300 | [diff] [blame] | 1029 | weston_layer_entry_insert(&from->layer_link, |
| 1030 | &ws->fsurf_back->view->layer_link); |
Louis-Francis Ratté-Boulianne | b482dbd | 2013-11-19 11:37:11 +0100 | [diff] [blame] | 1031 | ws->focus_animation = weston_stable_fade_run( |
| 1032 | ws->fsurf_front->view, 0.0, |
Jonny Lamb | 7e7d485 | 2014-05-22 22:41:34 +0200 | [diff] [blame] | 1033 | ws->fsurf_back->view, 0.4, |
Louis-Francis Ratté-Boulianne | b482dbd | 2013-11-19 11:37:11 +0100 | [diff] [blame] | 1034 | focus_animation_done, ws); |
| 1035 | } else if (to) { |
Giulio Camuffo | 412e6a5 | 2014-07-09 22:12:56 +0300 | [diff] [blame] | 1036 | weston_layer_entry_insert(&ws->layer.view_list, |
| 1037 | &ws->fsurf_back->view->layer_link); |
Louis-Francis Ratté-Boulianne | b482dbd | 2013-11-19 11:37:11 +0100 | [diff] [blame] | 1038 | ws->focus_animation = weston_stable_fade_run( |
| 1039 | ws->fsurf_front->view, 0.0, |
Jonny Lamb | 7e7d485 | 2014-05-22 22:41:34 +0200 | [diff] [blame] | 1040 | ws->fsurf_back->view, 0.4, |
Louis-Francis Ratté-Boulianne | b482dbd | 2013-11-19 11:37:11 +0100 | [diff] [blame] | 1041 | focus_animation_done, ws); |
| 1042 | } |
| 1043 | } |
| 1044 | |
| 1045 | static void |
Jonas Ådahl | e3cddce | 2012-06-13 00:01:22 +0200 | [diff] [blame] | 1046 | workspace_destroy(struct workspace *ws) |
| 1047 | { |
Jonas Ådahl | 0476974 | 2012-06-13 00:01:24 +0200 | [diff] [blame] | 1048 | struct focus_state *state, *next; |
| 1049 | |
| 1050 | wl_list_for_each_safe(state, next, &ws->focus_list, link) |
| 1051 | focus_state_destroy(state); |
| 1052 | |
Louis-Francis Ratté-Boulianne | b482dbd | 2013-11-19 11:37:11 +0100 | [diff] [blame] | 1053 | if (ws->fsurf_front) |
| 1054 | focus_surface_destroy(ws->fsurf_front); |
| 1055 | if (ws->fsurf_back) |
| 1056 | focus_surface_destroy(ws->fsurf_back); |
| 1057 | |
Jonas Ådahl | e3cddce | 2012-06-13 00:01:22 +0200 | [diff] [blame] | 1058 | free(ws); |
| 1059 | } |
| 1060 | |
Jonas Ådahl | 0476974 | 2012-06-13 00:01:24 +0200 | [diff] [blame] | 1061 | static void |
| 1062 | seat_destroyed(struct wl_listener *listener, void *data) |
| 1063 | { |
| 1064 | struct weston_seat *seat = data; |
| 1065 | struct focus_state *state, *next; |
| 1066 | struct workspace *ws = container_of(listener, |
| 1067 | struct workspace, |
| 1068 | seat_destroyed_listener); |
| 1069 | |
| 1070 | wl_list_for_each_safe(state, next, &ws->focus_list, link) |
| 1071 | if (state->seat == seat) |
| 1072 | wl_list_remove(&state->link); |
| 1073 | } |
| 1074 | |
Jonas Ådahl | e3cddce | 2012-06-13 00:01:22 +0200 | [diff] [blame] | 1075 | static struct workspace * |
| 1076 | workspace_create(void) |
| 1077 | { |
| 1078 | struct workspace *ws = malloc(sizeof *ws); |
| 1079 | if (ws == NULL) |
| 1080 | return NULL; |
| 1081 | |
| 1082 | weston_layer_init(&ws->layer, NULL); |
| 1083 | |
Jonas Ådahl | 0476974 | 2012-06-13 00:01:24 +0200 | [diff] [blame] | 1084 | wl_list_init(&ws->focus_list); |
| 1085 | wl_list_init(&ws->seat_destroyed_listener.link); |
| 1086 | ws->seat_destroyed_listener.notify = seat_destroyed; |
Louis-Francis Ratté-Boulianne | b482dbd | 2013-11-19 11:37:11 +0100 | [diff] [blame] | 1087 | ws->fsurf_front = NULL; |
| 1088 | ws->fsurf_back = NULL; |
| 1089 | ws->focus_animation = NULL; |
Jonas Ådahl | 0476974 | 2012-06-13 00:01:24 +0200 | [diff] [blame] | 1090 | |
Jonas Ådahl | e3cddce | 2012-06-13 00:01:22 +0200 | [diff] [blame] | 1091 | return ws; |
| 1092 | } |
| 1093 | |
Jonas Ådahl | 62fcd04 | 2012-06-13 00:01:23 +0200 | [diff] [blame] | 1094 | static int |
| 1095 | workspace_is_empty(struct workspace *ws) |
| 1096 | { |
Giulio Camuffo | 412e6a5 | 2014-07-09 22:12:56 +0300 | [diff] [blame] | 1097 | return wl_list_empty(&ws->layer.view_list.link); |
Jonas Ådahl | 62fcd04 | 2012-06-13 00:01:23 +0200 | [diff] [blame] | 1098 | } |
| 1099 | |
Jonas Ådahl | e3cddce | 2012-06-13 00:01:22 +0200 | [diff] [blame] | 1100 | static struct workspace * |
| 1101 | get_workspace(struct desktop_shell *shell, unsigned int index) |
| 1102 | { |
| 1103 | struct workspace **pws = shell->workspaces.array.data; |
Philipp Brüschweiler | 067abf6 | 2012-09-01 16:03:05 +0200 | [diff] [blame] | 1104 | assert(index < shell->workspaces.num); |
Jonas Ådahl | e3cddce | 2012-06-13 00:01:22 +0200 | [diff] [blame] | 1105 | pws += index; |
| 1106 | return *pws; |
| 1107 | } |
| 1108 | |
Kristian Høgsberg | 1ef2313 | 2013-12-04 00:20:01 -0800 | [diff] [blame] | 1109 | struct workspace * |
Jonas Ådahl | e3cddce | 2012-06-13 00:01:22 +0200 | [diff] [blame] | 1110 | get_current_workspace(struct desktop_shell *shell) |
| 1111 | { |
| 1112 | return get_workspace(shell, shell->workspaces.current); |
| 1113 | } |
| 1114 | |
| 1115 | static void |
| 1116 | activate_workspace(struct desktop_shell *shell, unsigned int index) |
| 1117 | { |
| 1118 | struct workspace *ws; |
| 1119 | |
| 1120 | ws = get_workspace(shell, index); |
| 1121 | wl_list_insert(&shell->panel_layer.link, &ws->layer.link); |
| 1122 | |
| 1123 | shell->workspaces.current = index; |
| 1124 | } |
| 1125 | |
Jonas Ådahl | 62fcd04 | 2012-06-13 00:01:23 +0200 | [diff] [blame] | 1126 | static unsigned int |
| 1127 | get_output_height(struct weston_output *output) |
| 1128 | { |
| 1129 | return abs(output->region.extents.y1 - output->region.extents.y2); |
| 1130 | } |
| 1131 | |
| 1132 | static void |
Louis-Francis Ratté-Boulianne | b482dbd | 2013-11-19 11:37:11 +0100 | [diff] [blame] | 1133 | view_translate(struct workspace *ws, struct weston_view *view, double d) |
Jonas Ådahl | 62fcd04 | 2012-06-13 00:01:23 +0200 | [diff] [blame] | 1134 | { |
Jonas Ådahl | 62fcd04 | 2012-06-13 00:01:23 +0200 | [diff] [blame] | 1135 | struct weston_transform *transform; |
| 1136 | |
Louis-Francis Ratté-Boulianne | b482dbd | 2013-11-19 11:37:11 +0100 | [diff] [blame] | 1137 | if (is_focus_view(view)) { |
| 1138 | struct focus_surface *fsurf = get_focus_surface(view->surface); |
| 1139 | transform = &fsurf->workspace_transform; |
| 1140 | } else { |
| 1141 | struct shell_surface *shsurf = get_shell_surface(view->surface); |
| 1142 | transform = &shsurf->workspace_transform; |
| 1143 | } |
| 1144 | |
Jonas Ådahl | 62fcd04 | 2012-06-13 00:01:23 +0200 | [diff] [blame] | 1145 | if (wl_list_empty(&transform->link)) |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 1146 | wl_list_insert(view->geometry.transformation_list.prev, |
Louis-Francis Ratté-Boulianne | b482dbd | 2013-11-19 11:37:11 +0100 | [diff] [blame] | 1147 | &transform->link); |
Jonas Ådahl | 62fcd04 | 2012-06-13 00:01:23 +0200 | [diff] [blame] | 1148 | |
Louis-Francis Ratté-Boulianne | b482dbd | 2013-11-19 11:37:11 +0100 | [diff] [blame] | 1149 | weston_matrix_init(&transform->matrix); |
| 1150 | weston_matrix_translate(&transform->matrix, |
Jonas Ådahl | 62fcd04 | 2012-06-13 00:01:23 +0200 | [diff] [blame] | 1151 | 0.0, d, 0.0); |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 1152 | weston_view_geometry_dirty(view); |
Jonas Ådahl | 62fcd04 | 2012-06-13 00:01:23 +0200 | [diff] [blame] | 1153 | } |
| 1154 | |
| 1155 | static void |
| 1156 | workspace_translate_out(struct workspace *ws, double fraction) |
| 1157 | { |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 1158 | struct weston_view *view; |
Jonas Ådahl | 62fcd04 | 2012-06-13 00:01:23 +0200 | [diff] [blame] | 1159 | unsigned int height; |
| 1160 | double d; |
| 1161 | |
Giulio Camuffo | 412e6a5 | 2014-07-09 22:12:56 +0300 | [diff] [blame] | 1162 | 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] | 1163 | height = get_output_height(view->surface->output); |
Jonas Ådahl | 62fcd04 | 2012-06-13 00:01:23 +0200 | [diff] [blame] | 1164 | d = 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 |
| 1171 | workspace_translate_in(struct workspace *ws, double fraction) |
| 1172 | { |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 1173 | struct weston_view *view; |
Jonas Ådahl | 62fcd04 | 2012-06-13 00:01:23 +0200 | [diff] [blame] | 1174 | unsigned int height; |
| 1175 | double d; |
| 1176 | |
Giulio Camuffo | 412e6a5 | 2014-07-09 22:12:56 +0300 | [diff] [blame] | 1177 | 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] | 1178 | height = get_output_height(view->surface->output); |
Jonas Ådahl | 62fcd04 | 2012-06-13 00:01:23 +0200 | [diff] [blame] | 1179 | |
| 1180 | if (fraction > 0) |
| 1181 | d = -(height - height * fraction); |
| 1182 | else |
| 1183 | d = height + height * fraction; |
| 1184 | |
Louis-Francis Ratté-Boulianne | b482dbd | 2013-11-19 11:37:11 +0100 | [diff] [blame] | 1185 | view_translate(ws, view, d); |
Jonas Ådahl | 62fcd04 | 2012-06-13 00:01:23 +0200 | [diff] [blame] | 1186 | } |
| 1187 | } |
| 1188 | |
| 1189 | static void |
Jonas Ådahl | e9d2250 | 2012-08-29 22:13:01 +0200 | [diff] [blame] | 1190 | broadcast_current_workspace_state(struct desktop_shell *shell) |
| 1191 | { |
Kristian Høgsberg | 2e3c396 | 2013-09-11 12:00:47 -0700 | [diff] [blame] | 1192 | struct wl_resource *resource; |
Jonas Ådahl | e9d2250 | 2012-08-29 22:13:01 +0200 | [diff] [blame] | 1193 | |
Kristian Høgsberg | 2e3c396 | 2013-09-11 12:00:47 -0700 | [diff] [blame] | 1194 | wl_resource_for_each(resource, &shell->workspaces.client_list) |
| 1195 | workspace_manager_send_state(resource, |
Jonas Ådahl | e9d2250 | 2012-08-29 22:13:01 +0200 | [diff] [blame] | 1196 | shell->workspaces.current, |
| 1197 | shell->workspaces.num); |
| 1198 | } |
| 1199 | |
| 1200 | static void |
Jonas Ådahl | 62fcd04 | 2012-06-13 00:01:23 +0200 | [diff] [blame] | 1201 | reverse_workspace_change_animation(struct desktop_shell *shell, |
| 1202 | unsigned int index, |
| 1203 | struct workspace *from, |
| 1204 | struct workspace *to) |
| 1205 | { |
| 1206 | shell->workspaces.current = index; |
| 1207 | |
| 1208 | shell->workspaces.anim_to = to; |
| 1209 | shell->workspaces.anim_from = from; |
| 1210 | shell->workspaces.anim_dir = -1 * shell->workspaces.anim_dir; |
| 1211 | shell->workspaces.anim_timestamp = 0; |
| 1212 | |
Scott Moreau | 4272e63 | 2012-08-13 09:58:41 -0600 | [diff] [blame] | 1213 | weston_compositor_schedule_repaint(shell->compositor); |
Jonas Ådahl | 62fcd04 | 2012-06-13 00:01:23 +0200 | [diff] [blame] | 1214 | } |
| 1215 | |
| 1216 | static void |
| 1217 | workspace_deactivate_transforms(struct workspace *ws) |
| 1218 | { |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 1219 | struct weston_view *view; |
Louis-Francis Ratté-Boulianne | b482dbd | 2013-11-19 11:37:11 +0100 | [diff] [blame] | 1220 | struct weston_transform *transform; |
Jonas Ådahl | 62fcd04 | 2012-06-13 00:01:23 +0200 | [diff] [blame] | 1221 | |
Giulio Camuffo | 412e6a5 | 2014-07-09 22:12:56 +0300 | [diff] [blame] | 1222 | 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] | 1223 | if (is_focus_view(view)) { |
| 1224 | struct focus_surface *fsurf = get_focus_surface(view->surface); |
| 1225 | transform = &fsurf->workspace_transform; |
| 1226 | } else { |
| 1227 | struct shell_surface *shsurf = get_shell_surface(view->surface); |
| 1228 | transform = &shsurf->workspace_transform; |
| 1229 | } |
| 1230 | |
| 1231 | if (!wl_list_empty(&transform->link)) { |
| 1232 | wl_list_remove(&transform->link); |
| 1233 | wl_list_init(&transform->link); |
Jonas Ådahl | 8de6a1d | 2012-08-29 22:13:00 +0200 | [diff] [blame] | 1234 | } |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 1235 | weston_view_geometry_dirty(view); |
Jonas Ådahl | 62fcd04 | 2012-06-13 00:01:23 +0200 | [diff] [blame] | 1236 | } |
| 1237 | } |
| 1238 | |
| 1239 | static void |
| 1240 | finish_workspace_change_animation(struct desktop_shell *shell, |
| 1241 | struct workspace *from, |
| 1242 | struct workspace *to) |
| 1243 | { |
Ander Conselvan de Oliveira | 9c6217e | 2014-05-07 11:57:26 +0300 | [diff] [blame] | 1244 | struct weston_view *view; |
| 1245 | |
Scott Moreau | 4272e63 | 2012-08-13 09:58:41 -0600 | [diff] [blame] | 1246 | weston_compositor_schedule_repaint(shell->compositor); |
Jonas Ådahl | 62fcd04 | 2012-06-13 00:01:23 +0200 | [diff] [blame] | 1247 | |
Ander Conselvan de Oliveira | 9c6217e | 2014-05-07 11:57:26 +0300 | [diff] [blame] | 1248 | /* Views that extend past the bottom of the output are still |
| 1249 | * visible after the workspace animation ends but before its layer |
| 1250 | * is hidden. In that case, we need to damage below those views so |
| 1251 | * that the screen is properly repainted. */ |
Giulio Camuffo | 412e6a5 | 2014-07-09 22:12:56 +0300 | [diff] [blame] | 1252 | 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] | 1253 | weston_view_damage_below(view); |
| 1254 | |
Jonas Ådahl | 62fcd04 | 2012-06-13 00:01:23 +0200 | [diff] [blame] | 1255 | wl_list_remove(&shell->workspaces.animation.link); |
| 1256 | workspace_deactivate_transforms(from); |
| 1257 | workspace_deactivate_transforms(to); |
| 1258 | shell->workspaces.anim_to = NULL; |
| 1259 | |
| 1260 | wl_list_remove(&shell->workspaces.anim_from->layer.link); |
| 1261 | } |
| 1262 | |
| 1263 | static void |
| 1264 | animate_workspace_change_frame(struct weston_animation *animation, |
| 1265 | struct weston_output *output, uint32_t msecs) |
| 1266 | { |
| 1267 | struct desktop_shell *shell = |
| 1268 | container_of(animation, struct desktop_shell, |
| 1269 | workspaces.animation); |
| 1270 | struct workspace *from = shell->workspaces.anim_from; |
| 1271 | struct workspace *to = shell->workspaces.anim_to; |
| 1272 | uint32_t t; |
| 1273 | double x, y; |
| 1274 | |
| 1275 | if (workspace_is_empty(from) && workspace_is_empty(to)) { |
| 1276 | finish_workspace_change_animation(shell, from, to); |
| 1277 | return; |
| 1278 | } |
| 1279 | |
| 1280 | if (shell->workspaces.anim_timestamp == 0) { |
| 1281 | if (shell->workspaces.anim_current == 0.0) |
| 1282 | shell->workspaces.anim_timestamp = msecs; |
| 1283 | else |
| 1284 | shell->workspaces.anim_timestamp = |
| 1285 | msecs - |
| 1286 | /* Invers of movement function 'y' below. */ |
| 1287 | (asin(1.0 - shell->workspaces.anim_current) * |
| 1288 | DEFAULT_WORKSPACE_CHANGE_ANIMATION_LENGTH * |
| 1289 | M_2_PI); |
| 1290 | } |
| 1291 | |
| 1292 | t = msecs - shell->workspaces.anim_timestamp; |
| 1293 | |
| 1294 | /* |
| 1295 | * x = [0, π/2] |
| 1296 | * y(x) = sin(x) |
| 1297 | */ |
| 1298 | x = t * (1.0/DEFAULT_WORKSPACE_CHANGE_ANIMATION_LENGTH) * M_PI_2; |
| 1299 | y = sin(x); |
| 1300 | |
| 1301 | if (t < DEFAULT_WORKSPACE_CHANGE_ANIMATION_LENGTH) { |
Scott Moreau | 4272e63 | 2012-08-13 09:58:41 -0600 | [diff] [blame] | 1302 | weston_compositor_schedule_repaint(shell->compositor); |
Jonas Ådahl | 62fcd04 | 2012-06-13 00:01:23 +0200 | [diff] [blame] | 1303 | |
| 1304 | workspace_translate_out(from, shell->workspaces.anim_dir * y); |
| 1305 | workspace_translate_in(to, shell->workspaces.anim_dir * y); |
| 1306 | shell->workspaces.anim_current = y; |
| 1307 | |
Scott Moreau | 4272e63 | 2012-08-13 09:58:41 -0600 | [diff] [blame] | 1308 | weston_compositor_schedule_repaint(shell->compositor); |
Jonas Ådahl | 62fcd04 | 2012-06-13 00:01:23 +0200 | [diff] [blame] | 1309 | } |
Jonas Ådahl | 0476974 | 2012-06-13 00:01:24 +0200 | [diff] [blame] | 1310 | else |
Jonas Ådahl | 62fcd04 | 2012-06-13 00:01:23 +0200 | [diff] [blame] | 1311 | finish_workspace_change_animation(shell, from, to); |
Jonas Ådahl | 62fcd04 | 2012-06-13 00:01:23 +0200 | [diff] [blame] | 1312 | } |
| 1313 | |
| 1314 | static void |
| 1315 | animate_workspace_change(struct desktop_shell *shell, |
| 1316 | unsigned int index, |
| 1317 | struct workspace *from, |
| 1318 | struct workspace *to) |
| 1319 | { |
| 1320 | struct weston_output *output; |
| 1321 | |
| 1322 | int dir; |
| 1323 | |
| 1324 | if (index > shell->workspaces.current) |
| 1325 | dir = -1; |
| 1326 | else |
| 1327 | dir = 1; |
| 1328 | |
| 1329 | shell->workspaces.current = index; |
| 1330 | |
| 1331 | shell->workspaces.anim_dir = dir; |
| 1332 | shell->workspaces.anim_from = from; |
| 1333 | shell->workspaces.anim_to = to; |
| 1334 | shell->workspaces.anim_current = 0.0; |
| 1335 | shell->workspaces.anim_timestamp = 0; |
| 1336 | |
| 1337 | output = container_of(shell->compositor->output_list.next, |
| 1338 | struct weston_output, link); |
| 1339 | wl_list_insert(&output->animation_list, |
| 1340 | &shell->workspaces.animation.link); |
| 1341 | |
Jonas Ådahl | 8de6a1d | 2012-08-29 22:13:00 +0200 | [diff] [blame] | 1342 | wl_list_insert(from->layer.link.prev, &to->layer.link); |
Jonas Ådahl | 62fcd04 | 2012-06-13 00:01:23 +0200 | [diff] [blame] | 1343 | |
| 1344 | workspace_translate_in(to, 0); |
| 1345 | |
Kristian Høgsberg | 2f5faff | 2012-07-31 16:36:34 -0400 | [diff] [blame] | 1346 | restore_focus_state(shell, to); |
Jonas Ådahl | 0476974 | 2012-06-13 00:01:24 +0200 | [diff] [blame] | 1347 | |
Scott Moreau | 4272e63 | 2012-08-13 09:58:41 -0600 | [diff] [blame] | 1348 | weston_compositor_schedule_repaint(shell->compositor); |
Jonas Ådahl | 62fcd04 | 2012-06-13 00:01:23 +0200 | [diff] [blame] | 1349 | } |
| 1350 | |
Jonas Ådahl | e3cddce | 2012-06-13 00:01:22 +0200 | [diff] [blame] | 1351 | static void |
Jonas Ådahl | 8de6a1d | 2012-08-29 22:13:00 +0200 | [diff] [blame] | 1352 | update_workspace(struct desktop_shell *shell, unsigned int index, |
| 1353 | struct workspace *from, struct workspace *to) |
| 1354 | { |
| 1355 | shell->workspaces.current = index; |
| 1356 | wl_list_insert(&from->layer.link, &to->layer.link); |
| 1357 | wl_list_remove(&from->layer.link); |
| 1358 | } |
| 1359 | |
| 1360 | static void |
Jonas Ådahl | e3cddce | 2012-06-13 00:01:22 +0200 | [diff] [blame] | 1361 | change_workspace(struct desktop_shell *shell, unsigned int index) |
| 1362 | { |
| 1363 | struct workspace *from; |
| 1364 | struct workspace *to; |
Louis-Francis Ratté-Boulianne | b482dbd | 2013-11-19 11:37:11 +0100 | [diff] [blame] | 1365 | struct focus_state *state; |
Jonas Ådahl | e3cddce | 2012-06-13 00:01:22 +0200 | [diff] [blame] | 1366 | |
| 1367 | if (index == shell->workspaces.current) |
| 1368 | return; |
| 1369 | |
| 1370 | /* Don't change workspace when there is any fullscreen surfaces. */ |
Giulio Camuffo | 412e6a5 | 2014-07-09 22:12:56 +0300 | [diff] [blame] | 1371 | if (!wl_list_empty(&shell->fullscreen_layer.view_list.link)) |
Jonas Ådahl | e3cddce | 2012-06-13 00:01:22 +0200 | [diff] [blame] | 1372 | return; |
| 1373 | |
Jonas Ådahl | e3cddce | 2012-06-13 00:01:22 +0200 | [diff] [blame] | 1374 | from = get_current_workspace(shell); |
| 1375 | to = get_workspace(shell, index); |
| 1376 | |
Jonas Ådahl | 62fcd04 | 2012-06-13 00:01:23 +0200 | [diff] [blame] | 1377 | if (shell->workspaces.anim_from == to && |
| 1378 | shell->workspaces.anim_to == from) { |
Jonas Ådahl | 8de6a1d | 2012-08-29 22:13:00 +0200 | [diff] [blame] | 1379 | restore_focus_state(shell, to); |
Jonas Ådahl | 62fcd04 | 2012-06-13 00:01:23 +0200 | [diff] [blame] | 1380 | reverse_workspace_change_animation(shell, index, from, to); |
Jonas Ådahl | e9d2250 | 2012-08-29 22:13:01 +0200 | [diff] [blame] | 1381 | broadcast_current_workspace_state(shell); |
Jonas Ådahl | 62fcd04 | 2012-06-13 00:01:23 +0200 | [diff] [blame] | 1382 | return; |
| 1383 | } |
Jonas Ådahl | e3cddce | 2012-06-13 00:01:22 +0200 | [diff] [blame] | 1384 | |
Jonas Ådahl | 62fcd04 | 2012-06-13 00:01:23 +0200 | [diff] [blame] | 1385 | if (shell->workspaces.anim_to != NULL) |
| 1386 | finish_workspace_change_animation(shell, |
| 1387 | shell->workspaces.anim_from, |
| 1388 | shell->workspaces.anim_to); |
| 1389 | |
Jonas Ådahl | 8de6a1d | 2012-08-29 22:13:00 +0200 | [diff] [blame] | 1390 | restore_focus_state(shell, to); |
Jonas Ådahl | 0476974 | 2012-06-13 00:01:24 +0200 | [diff] [blame] | 1391 | |
Louis-Francis Ratté-Boulianne | b482dbd | 2013-11-19 11:37:11 +0100 | [diff] [blame] | 1392 | if (shell->focus_animation_type != ANIMATION_NONE) { |
| 1393 | wl_list_for_each(state, &from->focus_list, link) |
| 1394 | if (state->keyboard_focus) |
| 1395 | animate_focus_change(shell, from, |
| 1396 | get_default_view(state->keyboard_focus), NULL); |
| 1397 | |
| 1398 | wl_list_for_each(state, &to->focus_list, link) |
| 1399 | if (state->keyboard_focus) |
| 1400 | animate_focus_change(shell, to, |
| 1401 | NULL, get_default_view(state->keyboard_focus)); |
| 1402 | } |
| 1403 | |
Jonas Ådahl | 8de6a1d | 2012-08-29 22:13:00 +0200 | [diff] [blame] | 1404 | if (workspace_is_empty(to) && workspace_is_empty(from)) |
| 1405 | update_workspace(shell, index, from, to); |
Jonas Ådahl | 62fcd04 | 2012-06-13 00:01:23 +0200 | [diff] [blame] | 1406 | else |
| 1407 | animate_workspace_change(shell, index, from, to); |
Jonas Ådahl | e9d2250 | 2012-08-29 22:13:01 +0200 | [diff] [blame] | 1408 | |
| 1409 | broadcast_current_workspace_state(shell); |
Pekka Paalanen | e955f1e | 2011-12-07 11:49:52 +0200 | [diff] [blame] | 1410 | } |
| 1411 | |
Jonas Ådahl | 8de6a1d | 2012-08-29 22:13:00 +0200 | [diff] [blame] | 1412 | static bool |
| 1413 | workspace_has_only(struct workspace *ws, struct weston_surface *surface) |
| 1414 | { |
Giulio Camuffo | 412e6a5 | 2014-07-09 22:12:56 +0300 | [diff] [blame] | 1415 | struct wl_list *list = &ws->layer.view_list.link; |
Jonas Ådahl | 8de6a1d | 2012-08-29 22:13:00 +0200 | [diff] [blame] | 1416 | struct wl_list *e; |
| 1417 | |
| 1418 | if (wl_list_empty(list)) |
| 1419 | return false; |
| 1420 | |
| 1421 | e = list->next; |
| 1422 | |
| 1423 | if (e->next != list) |
| 1424 | return false; |
| 1425 | |
Giulio Camuffo | 412e6a5 | 2014-07-09 22:12:56 +0300 | [diff] [blame] | 1426 | return container_of(e, struct weston_view, layer_link.link)->surface == surface; |
Jonas Ådahl | 8de6a1d | 2012-08-29 22:13:00 +0200 | [diff] [blame] | 1427 | } |
| 1428 | |
| 1429 | static void |
Philip Withnall | 659163d | 2013-11-25 18:01:36 +0000 | [diff] [blame] | 1430 | move_surface_to_workspace(struct desktop_shell *shell, |
| 1431 | struct shell_surface *shsurf, |
| 1432 | uint32_t workspace) |
Jonas Ådahl | e9d2250 | 2012-08-29 22:13:01 +0200 | [diff] [blame] | 1433 | { |
| 1434 | struct workspace *from; |
| 1435 | struct workspace *to; |
| 1436 | struct weston_seat *seat; |
Pekka Paalanen | 01388e2 | 2013-04-25 13:57:44 +0300 | [diff] [blame] | 1437 | struct weston_surface *focus; |
Philip Withnall | 659163d | 2013-11-25 18:01:36 +0000 | [diff] [blame] | 1438 | struct weston_view *view; |
Jonas Ådahl | e9d2250 | 2012-08-29 22:13:01 +0200 | [diff] [blame] | 1439 | |
| 1440 | if (workspace == shell->workspaces.current) |
| 1441 | return; |
| 1442 | |
Philip Withnall | 659163d | 2013-11-25 18:01:36 +0000 | [diff] [blame] | 1443 | view = get_default_view(shsurf->surface); |
| 1444 | if (!view) |
| 1445 | return; |
| 1446 | |
| 1447 | assert(weston_surface_get_main_surface(view->surface) == view->surface); |
| 1448 | |
Philipp Brüschweiler | 067abf6 | 2012-09-01 16:03:05 +0200 | [diff] [blame] | 1449 | if (workspace >= shell->workspaces.num) |
| 1450 | workspace = shell->workspaces.num - 1; |
| 1451 | |
Jonas Ådahl | e9d2250 | 2012-08-29 22:13:01 +0200 | [diff] [blame] | 1452 | from = get_current_workspace(shell); |
| 1453 | to = get_workspace(shell, workspace); |
| 1454 | |
Giulio Camuffo | 412e6a5 | 2014-07-09 22:12:56 +0300 | [diff] [blame] | 1455 | weston_layer_entry_remove(&view->layer_link); |
| 1456 | weston_layer_entry_insert(&to->layer.view_list, &view->layer_link); |
Jonas Ådahl | e9d2250 | 2012-08-29 22:13:01 +0200 | [diff] [blame] | 1457 | |
Philip Withnall | 648a4dd | 2013-11-25 18:01:44 +0000 | [diff] [blame] | 1458 | shell_surface_update_child_surface_layers(shsurf); |
| 1459 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 1460 | drop_focus_state(shell, from, view->surface); |
Pekka Paalanen | 01388e2 | 2013-04-25 13:57:44 +0300 | [diff] [blame] | 1461 | wl_list_for_each(seat, &shell->compositor->seat_list, link) { |
Derek Foreman | 1281a36 | 2015-07-31 16:55:32 -0500 | [diff] [blame] | 1462 | struct weston_keyboard *keyboard = |
| 1463 | weston_seat_get_keyboard(seat); |
| 1464 | |
| 1465 | if (!keyboard) |
Pekka Paalanen | 01388e2 | 2013-04-25 13:57:44 +0300 | [diff] [blame] | 1466 | continue; |
| 1467 | |
Derek Foreman | 1281a36 | 2015-07-31 16:55:32 -0500 | [diff] [blame] | 1468 | focus = weston_surface_get_main_surface(keyboard->focus); |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 1469 | if (focus == view->surface) |
Derek Foreman | 1281a36 | 2015-07-31 16:55:32 -0500 | [diff] [blame] | 1470 | weston_keyboard_set_focus(keyboard, NULL); |
Pekka Paalanen | 01388e2 | 2013-04-25 13:57:44 +0300 | [diff] [blame] | 1471 | } |
Jonas Ådahl | e9d2250 | 2012-08-29 22:13:01 +0200 | [diff] [blame] | 1472 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 1473 | weston_view_damage_below(view); |
Jonas Ådahl | e9d2250 | 2012-08-29 22:13:01 +0200 | [diff] [blame] | 1474 | } |
| 1475 | |
| 1476 | static void |
Jonas Ådahl | 8de6a1d | 2012-08-29 22:13:00 +0200 | [diff] [blame] | 1477 | take_surface_to_workspace_by_seat(struct desktop_shell *shell, |
Kristian Høgsberg | e314875 | 2013-05-06 23:19:49 -0400 | [diff] [blame] | 1478 | struct weston_seat *seat, |
Jonas Ådahl | 8de6a1d | 2012-08-29 22:13:00 +0200 | [diff] [blame] | 1479 | unsigned int index) |
| 1480 | { |
Derek Foreman | 1281a36 | 2015-07-31 16:55:32 -0500 | [diff] [blame] | 1481 | struct weston_keyboard *keyboard = weston_seat_get_keyboard(seat); |
Pekka Paalanen | 01388e2 | 2013-04-25 13:57:44 +0300 | [diff] [blame] | 1482 | struct weston_surface *surface; |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 1483 | struct weston_view *view; |
Jonas Ådahl | 8de6a1d | 2012-08-29 22:13:00 +0200 | [diff] [blame] | 1484 | struct shell_surface *shsurf; |
| 1485 | struct workspace *from; |
| 1486 | struct workspace *to; |
Jonas Ådahl | 8538b22 | 2012-08-29 22:13:03 +0200 | [diff] [blame] | 1487 | struct focus_state *state; |
Jonas Ådahl | 8de6a1d | 2012-08-29 22:13:00 +0200 | [diff] [blame] | 1488 | |
Derek Foreman | 1281a36 | 2015-07-31 16:55:32 -0500 | [diff] [blame] | 1489 | surface = weston_surface_get_main_surface(keyboard->focus); |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 1490 | view = get_default_view(surface); |
| 1491 | if (view == NULL || |
Louis-Francis Ratté-Boulianne | b482dbd | 2013-11-19 11:37:11 +0100 | [diff] [blame] | 1492 | index == shell->workspaces.current || |
| 1493 | is_focus_view(view)) |
Jonas Ådahl | 8de6a1d | 2012-08-29 22:13:00 +0200 | [diff] [blame] | 1494 | return; |
| 1495 | |
| 1496 | from = get_current_workspace(shell); |
| 1497 | to = get_workspace(shell, index); |
| 1498 | |
Giulio Camuffo | 412e6a5 | 2014-07-09 22:12:56 +0300 | [diff] [blame] | 1499 | weston_layer_entry_remove(&view->layer_link); |
| 1500 | weston_layer_entry_insert(&to->layer.view_list, &view->layer_link); |
Jonas Ådahl | 8de6a1d | 2012-08-29 22:13:00 +0200 | [diff] [blame] | 1501 | |
Philip Withnall | 659163d | 2013-11-25 18:01:36 +0000 | [diff] [blame] | 1502 | shsurf = get_shell_surface(surface); |
Philip Withnall | 648a4dd | 2013-11-25 18:01:44 +0000 | [diff] [blame] | 1503 | if (shsurf != NULL) |
| 1504 | shell_surface_update_child_surface_layers(shsurf); |
Philip Withnall | 659163d | 2013-11-25 18:01:36 +0000 | [diff] [blame] | 1505 | |
Jonas Ådahl | e9d2250 | 2012-08-29 22:13:01 +0200 | [diff] [blame] | 1506 | replace_focus_state(shell, to, seat); |
Jonas Ådahl | 8de6a1d | 2012-08-29 22:13:00 +0200 | [diff] [blame] | 1507 | drop_focus_state(shell, from, surface); |
| 1508 | |
| 1509 | if (shell->workspaces.anim_from == to && |
| 1510 | shell->workspaces.anim_to == from) { |
Jonas Ådahl | e9d2250 | 2012-08-29 22:13:01 +0200 | [diff] [blame] | 1511 | wl_list_remove(&to->layer.link); |
| 1512 | wl_list_insert(from->layer.link.prev, &to->layer.link); |
| 1513 | |
Jonas Ådahl | 8de6a1d | 2012-08-29 22:13:00 +0200 | [diff] [blame] | 1514 | reverse_workspace_change_animation(shell, index, from, to); |
Jonas Ådahl | e9d2250 | 2012-08-29 22:13:01 +0200 | [diff] [blame] | 1515 | broadcast_current_workspace_state(shell); |
| 1516 | |
Jonas Ådahl | 8de6a1d | 2012-08-29 22:13:00 +0200 | [diff] [blame] | 1517 | return; |
| 1518 | } |
| 1519 | |
| 1520 | if (shell->workspaces.anim_to != NULL) |
| 1521 | finish_workspace_change_animation(shell, |
| 1522 | shell->workspaces.anim_from, |
| 1523 | shell->workspaces.anim_to); |
| 1524 | |
| 1525 | if (workspace_is_empty(from) && |
| 1526 | workspace_has_only(to, surface)) |
| 1527 | update_workspace(shell, index, from, to); |
| 1528 | else { |
Philip Withnall | 2c3849b | 2013-11-25 18:01:45 +0000 | [diff] [blame] | 1529 | if (shsurf != NULL && |
| 1530 | wl_list_empty(&shsurf->workspace_transform.link)) |
Jonas Ådahl | 8de6a1d | 2012-08-29 22:13:00 +0200 | [diff] [blame] | 1531 | wl_list_insert(&shell->workspaces.anim_sticky_list, |
| 1532 | &shsurf->workspace_transform.link); |
| 1533 | |
| 1534 | animate_workspace_change(shell, index, from, to); |
| 1535 | } |
Jonas Ådahl | e9d2250 | 2012-08-29 22:13:01 +0200 | [diff] [blame] | 1536 | |
| 1537 | broadcast_current_workspace_state(shell); |
Jonas Ådahl | 8538b22 | 2012-08-29 22:13:03 +0200 | [diff] [blame] | 1538 | |
| 1539 | state = ensure_focus_state(shell, seat); |
| 1540 | if (state != NULL) |
Kristian Høgsberg | d500bf1 | 2014-01-22 12:25:20 -0800 | [diff] [blame] | 1541 | focus_state_set_focus(state, surface); |
Jonas Ådahl | e9d2250 | 2012-08-29 22:13:01 +0200 | [diff] [blame] | 1542 | } |
| 1543 | |
| 1544 | static void |
| 1545 | workspace_manager_move_surface(struct wl_client *client, |
| 1546 | struct wl_resource *resource, |
| 1547 | struct wl_resource *surface_resource, |
| 1548 | uint32_t workspace) |
| 1549 | { |
Jason Ekstrand | 651f00e | 2013-06-14 10:07:54 -0500 | [diff] [blame] | 1550 | struct desktop_shell *shell = wl_resource_get_user_data(resource); |
Jonas Ådahl | e9d2250 | 2012-08-29 22:13:01 +0200 | [diff] [blame] | 1551 | struct weston_surface *surface = |
Jason Ekstrand | 0f2ef7e | 2013-06-14 10:07:53 -0500 | [diff] [blame] | 1552 | wl_resource_get_user_data(surface_resource); |
Pekka Paalanen | 01388e2 | 2013-04-25 13:57:44 +0300 | [diff] [blame] | 1553 | struct weston_surface *main_surface; |
Philip Withnall | 659163d | 2013-11-25 18:01:36 +0000 | [diff] [blame] | 1554 | struct shell_surface *shell_surface; |
Jonas Ådahl | e9d2250 | 2012-08-29 22:13:01 +0200 | [diff] [blame] | 1555 | |
Pekka Paalanen | 01388e2 | 2013-04-25 13:57:44 +0300 | [diff] [blame] | 1556 | main_surface = weston_surface_get_main_surface(surface); |
Philip Withnall | 659163d | 2013-11-25 18:01:36 +0000 | [diff] [blame] | 1557 | shell_surface = get_shell_surface(main_surface); |
| 1558 | if (shell_surface == NULL) |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 1559 | return; |
Philip Withnall | 659163d | 2013-11-25 18:01:36 +0000 | [diff] [blame] | 1560 | |
| 1561 | move_surface_to_workspace(shell, shell_surface, workspace); |
Jonas Ådahl | e9d2250 | 2012-08-29 22:13:01 +0200 | [diff] [blame] | 1562 | } |
| 1563 | |
| 1564 | static const struct workspace_manager_interface workspace_manager_implementation = { |
| 1565 | workspace_manager_move_surface, |
| 1566 | }; |
| 1567 | |
| 1568 | static void |
| 1569 | unbind_resource(struct wl_resource *resource) |
| 1570 | { |
Jason Ekstrand | 651f00e | 2013-06-14 10:07:54 -0500 | [diff] [blame] | 1571 | wl_list_remove(wl_resource_get_link(resource)); |
Jonas Ådahl | e9d2250 | 2012-08-29 22:13:01 +0200 | [diff] [blame] | 1572 | } |
| 1573 | |
| 1574 | static void |
| 1575 | bind_workspace_manager(struct wl_client *client, |
| 1576 | void *data, uint32_t version, uint32_t id) |
| 1577 | { |
| 1578 | struct desktop_shell *shell = data; |
| 1579 | struct wl_resource *resource; |
| 1580 | |
Jason Ekstrand | a85118c | 2013-06-27 20:17:02 -0500 | [diff] [blame] | 1581 | resource = wl_resource_create(client, |
| 1582 | &workspace_manager_interface, 1, id); |
Jonas Ådahl | e9d2250 | 2012-08-29 22:13:01 +0200 | [diff] [blame] | 1583 | |
| 1584 | if (resource == NULL) { |
| 1585 | weston_log("couldn't add workspace manager object"); |
| 1586 | return; |
| 1587 | } |
| 1588 | |
Jason Ekstrand | a85118c | 2013-06-27 20:17:02 -0500 | [diff] [blame] | 1589 | wl_resource_set_implementation(resource, |
| 1590 | &workspace_manager_implementation, |
| 1591 | shell, unbind_resource); |
Jason Ekstrand | 651f00e | 2013-06-14 10:07:54 -0500 | [diff] [blame] | 1592 | wl_list_insert(&shell->workspaces.client_list, |
| 1593 | wl_resource_get_link(resource)); |
Jonas Ådahl | e9d2250 | 2012-08-29 22:13:01 +0200 | [diff] [blame] | 1594 | |
| 1595 | workspace_manager_send_state(resource, |
| 1596 | shell->workspaces.current, |
| 1597 | shell->workspaces.num); |
Jonas Ådahl | 8de6a1d | 2012-08-29 22:13:00 +0200 | [diff] [blame] | 1598 | } |
| 1599 | |
Pekka Paalanen | 56cdea9 | 2011-11-23 16:14:12 +0200 | [diff] [blame] | 1600 | static void |
Rusty Lynch | 1084da5 | 2013-08-15 09:10:08 -0700 | [diff] [blame] | 1601 | touch_move_grab_down(struct weston_touch_grab *grab, uint32_t time, |
Giulio Camuffo | 61ed7b6 | 2015-07-08 11:55:28 +0300 | [diff] [blame] | 1602 | int touch_id, wl_fixed_t x, wl_fixed_t y) |
Rusty Lynch | 1084da5 | 2013-08-15 09:10:08 -0700 | [diff] [blame] | 1603 | { |
| 1604 | } |
| 1605 | |
| 1606 | static void |
| 1607 | touch_move_grab_up(struct weston_touch_grab *grab, uint32_t time, int touch_id) |
| 1608 | { |
Jonas Ådahl | 1c6e63e | 2013-10-25 23:18:04 +0200 | [diff] [blame] | 1609 | struct weston_touch_move_grab *move = |
| 1610 | (struct weston_touch_move_grab *) container_of( |
| 1611 | grab, struct shell_touch_grab, grab); |
Neil Roberts | e14aa4f | 2013-10-03 16:43:07 +0100 | [diff] [blame] | 1612 | |
Kristian Høgsberg | 8e80a31 | 2014-01-17 15:18:10 -0800 | [diff] [blame] | 1613 | if (touch_id == 0) |
| 1614 | move->active = 0; |
| 1615 | |
Jonas Ådahl | 9484b69 | 2013-12-02 22:05:03 +0100 | [diff] [blame] | 1616 | if (grab->touch->num_tp == 0) { |
Jonas Ådahl | 1c6e63e | 2013-10-25 23:18:04 +0200 | [diff] [blame] | 1617 | shell_touch_grab_end(&move->base); |
| 1618 | free(move); |
| 1619 | } |
Rusty Lynch | 1084da5 | 2013-08-15 09:10:08 -0700 | [diff] [blame] | 1620 | } |
| 1621 | |
| 1622 | static void |
| 1623 | touch_move_grab_motion(struct weston_touch_grab *grab, uint32_t time, |
Giulio Camuffo | 61ed7b6 | 2015-07-08 11:55:28 +0300 | [diff] [blame] | 1624 | int touch_id, wl_fixed_t x, wl_fixed_t y) |
Rusty Lynch | 1084da5 | 2013-08-15 09:10:08 -0700 | [diff] [blame] | 1625 | { |
| 1626 | struct weston_touch_move_grab *move = (struct weston_touch_move_grab *) grab; |
| 1627 | struct shell_surface *shsurf = move->base.shsurf; |
| 1628 | struct weston_surface *es; |
| 1629 | int dx = wl_fixed_to_int(grab->touch->grab_x + move->dx); |
| 1630 | int dy = wl_fixed_to_int(grab->touch->grab_y + move->dy); |
| 1631 | |
Kristian Høgsberg | 8e80a31 | 2014-01-17 15:18:10 -0800 | [diff] [blame] | 1632 | if (!shsurf || !move->active) |
Rusty Lynch | 1084da5 | 2013-08-15 09:10:08 -0700 | [diff] [blame] | 1633 | return; |
| 1634 | |
| 1635 | es = shsurf->surface; |
| 1636 | |
Jason Ekstrand | 918f2dd | 2013-12-02 21:01:53 -0600 | [diff] [blame] | 1637 | weston_view_set_position(shsurf->view, dx, dy); |
Rusty Lynch | 1084da5 | 2013-08-15 09:10:08 -0700 | [diff] [blame] | 1638 | |
| 1639 | weston_compositor_schedule_repaint(es->compositor); |
| 1640 | } |
| 1641 | |
Jonas Ådahl | 1ea343e | 2013-10-25 23:18:05 +0200 | [diff] [blame] | 1642 | static void |
Jonas Ådahl | 1679f23 | 2014-04-12 09:39:51 +0200 | [diff] [blame] | 1643 | touch_move_grab_frame(struct weston_touch_grab *grab) |
| 1644 | { |
| 1645 | } |
| 1646 | |
| 1647 | static void |
Jonas Ådahl | 1ea343e | 2013-10-25 23:18:05 +0200 | [diff] [blame] | 1648 | touch_move_grab_cancel(struct weston_touch_grab *grab) |
| 1649 | { |
| 1650 | struct weston_touch_move_grab *move = |
| 1651 | (struct weston_touch_move_grab *) container_of( |
| 1652 | grab, struct shell_touch_grab, grab); |
| 1653 | |
| 1654 | shell_touch_grab_end(&move->base); |
| 1655 | free(move); |
| 1656 | } |
| 1657 | |
Rusty Lynch | 1084da5 | 2013-08-15 09:10:08 -0700 | [diff] [blame] | 1658 | static const struct weston_touch_grab_interface touch_move_grab_interface = { |
| 1659 | touch_move_grab_down, |
| 1660 | touch_move_grab_up, |
| 1661 | touch_move_grab_motion, |
Jonas Ådahl | 1679f23 | 2014-04-12 09:39:51 +0200 | [diff] [blame] | 1662 | touch_move_grab_frame, |
Jonas Ådahl | 1ea343e | 2013-10-25 23:18:05 +0200 | [diff] [blame] | 1663 | touch_move_grab_cancel, |
Rusty Lynch | 1084da5 | 2013-08-15 09:10:08 -0700 | [diff] [blame] | 1664 | }; |
| 1665 | |
| 1666 | static int |
Derek Foreman | b7674ae | 2015-07-15 13:00:37 -0500 | [diff] [blame] | 1667 | surface_touch_move(struct shell_surface *shsurf, struct weston_touch *touch) |
Rusty Lynch | 1084da5 | 2013-08-15 09:10:08 -0700 | [diff] [blame] | 1668 | { |
| 1669 | struct weston_touch_move_grab *move; |
| 1670 | |
| 1671 | if (!shsurf) |
| 1672 | return -1; |
| 1673 | |
Ander Conselvan de Oliveira | 6d43f04 | 2014-05-07 14:22:23 +0300 | [diff] [blame] | 1674 | if (shsurf->state.fullscreen || shsurf->state.maximized) |
Rusty Lynch | 1084da5 | 2013-08-15 09:10:08 -0700 | [diff] [blame] | 1675 | return 0; |
| 1676 | |
| 1677 | move = malloc(sizeof *move); |
| 1678 | if (!move) |
| 1679 | return -1; |
| 1680 | |
Kristian Høgsberg | 8e80a31 | 2014-01-17 15:18:10 -0800 | [diff] [blame] | 1681 | move->active = 1; |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 1682 | move->dx = wl_fixed_from_double(shsurf->view->geometry.x) - |
Derek Foreman | b7674ae | 2015-07-15 13:00:37 -0500 | [diff] [blame] | 1683 | touch->grab_x; |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 1684 | move->dy = wl_fixed_from_double(shsurf->view->geometry.y) - |
Derek Foreman | b7674ae | 2015-07-15 13:00:37 -0500 | [diff] [blame] | 1685 | touch->grab_y; |
Rusty Lynch | 1084da5 | 2013-08-15 09:10:08 -0700 | [diff] [blame] | 1686 | |
| 1687 | shell_touch_grab_start(&move->base, &touch_move_grab_interface, shsurf, |
Derek Foreman | b7674ae | 2015-07-15 13:00:37 -0500 | [diff] [blame] | 1688 | touch); |
Rusty Lynch | 1084da5 | 2013-08-15 09:10:08 -0700 | [diff] [blame] | 1689 | |
| 1690 | return 0; |
| 1691 | } |
| 1692 | |
| 1693 | static void |
Kristian Høgsberg | 6848c25 | 2013-05-08 22:02:59 -0400 | [diff] [blame] | 1694 | noop_grab_focus(struct weston_pointer_grab *grab) |
Kristian Høgsberg | 9ddb826 | 2012-01-04 21:30:29 -0500 | [diff] [blame] | 1695 | { |
Kristian Høgsberg | 9ddb826 | 2012-01-04 21:30:29 -0500 | [diff] [blame] | 1696 | } |
| 1697 | |
| 1698 | static void |
Kristian Høgsberg | ae356ae | 2014-04-29 16:03:54 -0700 | [diff] [blame] | 1699 | constrain_position(struct weston_move_grab *move, int *cx, int *cy) |
| 1700 | { |
| 1701 | struct shell_surface *shsurf = move->base.shsurf; |
| 1702 | struct weston_pointer *pointer = move->base.grab.pointer; |
Derek Foreman | 6feb0f9 | 2015-04-15 12:23:56 -0500 | [diff] [blame] | 1703 | int x, y, bottom; |
Kristian Høgsberg | ae356ae | 2014-04-29 16:03:54 -0700 | [diff] [blame] | 1704 | const int safety = 50; |
Derek Foreman | 6feb0f9 | 2015-04-15 12:23:56 -0500 | [diff] [blame] | 1705 | pixman_rectangle32_t area; |
Kristian Høgsberg | ae356ae | 2014-04-29 16:03:54 -0700 | [diff] [blame] | 1706 | |
| 1707 | x = wl_fixed_to_int(pointer->x + move->dx); |
| 1708 | y = wl_fixed_to_int(pointer->y + move->dy); |
| 1709 | |
Jonny Lamb | d73c694 | 2014-08-20 15:53:20 +0200 | [diff] [blame] | 1710 | if (shsurf->shell->panel_position == DESKTOP_SHELL_PANEL_POSITION_TOP) { |
Derek Foreman | 6feb0f9 | 2015-04-15 12:23:56 -0500 | [diff] [blame] | 1711 | get_output_work_area(shsurf->shell, |
| 1712 | shsurf->surface->output, |
| 1713 | &area); |
Kristian Høgsberg | ae356ae | 2014-04-29 16:03:54 -0700 | [diff] [blame] | 1714 | |
Derek Foreman | 6feb0f9 | 2015-04-15 12:23:56 -0500 | [diff] [blame] | 1715 | bottom = y + shsurf->geometry.height + shsurf->geometry.y; |
| 1716 | if (bottom - safety < area.y) |
| 1717 | y = area.y + safety - shsurf->geometry.height |
| 1718 | - shsurf->geometry.y; |
Jonny Lamb | d73c694 | 2014-08-20 15:53:20 +0200 | [diff] [blame] | 1719 | |
| 1720 | if (move->client_initiated && |
Derek Foreman | 6feb0f9 | 2015-04-15 12:23:56 -0500 | [diff] [blame] | 1721 | y + shsurf->geometry.y < area.y) |
| 1722 | y = area.y - shsurf->geometry.y; |
| 1723 | |
Jonny Lamb | d73c694 | 2014-08-20 15:53:20 +0200 | [diff] [blame] | 1724 | } |
Kristian Høgsberg | ae356ae | 2014-04-29 16:03:54 -0700 | [diff] [blame] | 1725 | |
| 1726 | *cx = x; |
| 1727 | *cy = y; |
| 1728 | } |
| 1729 | |
| 1730 | static void |
Giulio Camuffo | 1959ab8 | 2013-11-14 23:42:52 +0100 | [diff] [blame] | 1731 | move_grab_motion(struct weston_pointer_grab *grab, uint32_t time, |
| 1732 | wl_fixed_t x, wl_fixed_t y) |
Kristian Høgsberg | 4cca349 | 2011-01-18 07:53:49 -0500 | [diff] [blame] | 1733 | { |
Kristian Høgsberg | 8334bc1 | 2012-01-03 10:29:47 -0500 | [diff] [blame] | 1734 | struct weston_move_grab *move = (struct weston_move_grab *) grab; |
Kristian Høgsberg | 02bbabb | 2013-05-06 22:15:05 -0400 | [diff] [blame] | 1735 | struct weston_pointer *pointer = grab->pointer; |
Ander Conselvan de Oliveira | fe0444a | 2012-04-04 17:48:05 +0300 | [diff] [blame] | 1736 | struct shell_surface *shsurf = move->base.shsurf; |
Kristian Høgsberg | ae356ae | 2014-04-29 16:03:54 -0700 | [diff] [blame] | 1737 | int cx, cy; |
Giulio Camuffo | 1959ab8 | 2013-11-14 23:42:52 +0100 | [diff] [blame] | 1738 | |
| 1739 | weston_pointer_move(pointer, x, y); |
Ander Conselvan de Oliveira | fe0444a | 2012-04-04 17:48:05 +0300 | [diff] [blame] | 1740 | if (!shsurf) |
| 1741 | return; |
| 1742 | |
Kristian Høgsberg | ae356ae | 2014-04-29 16:03:54 -0700 | [diff] [blame] | 1743 | constrain_position(move, &cx, &cy); |
| 1744 | |
| 1745 | weston_view_set_position(shsurf->view, cx, cy); |
Kristian Høgsberg | 4cca349 | 2011-01-18 07:53:49 -0500 | [diff] [blame] | 1746 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 1747 | weston_compositor_schedule_repaint(shsurf->surface->compositor); |
Kristian Høgsberg | 4cca349 | 2011-01-18 07:53:49 -0500 | [diff] [blame] | 1748 | } |
| 1749 | |
| 1750 | static void |
Kristian Høgsberg | 02bbabb | 2013-05-06 22:15:05 -0400 | [diff] [blame] | 1751 | move_grab_button(struct weston_pointer_grab *grab, |
Daniel Stone | 4dbadb1 | 2012-05-30 16:31:51 +0100 | [diff] [blame] | 1752 | uint32_t time, uint32_t button, uint32_t state_w) |
Kristian Høgsberg | 4cca349 | 2011-01-18 07:53:49 -0500 | [diff] [blame] | 1753 | { |
Ander Conselvan de Oliveira | fe0444a | 2012-04-04 17:48:05 +0300 | [diff] [blame] | 1754 | struct shell_grab *shell_grab = container_of(grab, struct shell_grab, |
| 1755 | grab); |
Kristian Høgsberg | 02bbabb | 2013-05-06 22:15:05 -0400 | [diff] [blame] | 1756 | struct weston_pointer *pointer = grab->pointer; |
Daniel Stone | 4dbadb1 | 2012-05-30 16:31:51 +0100 | [diff] [blame] | 1757 | enum wl_pointer_button_state state = state_w; |
Kristian Høgsberg | 4cca349 | 2011-01-18 07:53:49 -0500 | [diff] [blame] | 1758 | |
Daniel Stone | 4dbadb1 | 2012-05-30 16:31:51 +0100 | [diff] [blame] | 1759 | if (pointer->button_count == 0 && |
| 1760 | state == WL_POINTER_BUTTON_STATE_RELEASED) { |
Ander Conselvan de Oliveira | b9d2a0f | 2012-06-28 18:08:05 +0300 | [diff] [blame] | 1761 | shell_grab_end(shell_grab); |
Kristian Høgsberg | 9ddb826 | 2012-01-04 21:30:29 -0500 | [diff] [blame] | 1762 | free(grab); |
| 1763 | } |
Kristian Høgsberg | 4cca349 | 2011-01-18 07:53:49 -0500 | [diff] [blame] | 1764 | } |
| 1765 | |
Jonas Ådahl | 1ea343e | 2013-10-25 23:18:05 +0200 | [diff] [blame] | 1766 | static void |
| 1767 | move_grab_cancel(struct weston_pointer_grab *grab) |
| 1768 | { |
| 1769 | struct shell_grab *shell_grab = |
| 1770 | container_of(grab, struct shell_grab, grab); |
| 1771 | |
| 1772 | shell_grab_end(shell_grab); |
| 1773 | free(grab); |
| 1774 | } |
| 1775 | |
Kristian Høgsberg | 02bbabb | 2013-05-06 22:15:05 -0400 | [diff] [blame] | 1776 | static const struct weston_pointer_grab_interface move_grab_interface = { |
Kristian Høgsberg | 9ddb826 | 2012-01-04 21:30:29 -0500 | [diff] [blame] | 1777 | noop_grab_focus, |
Kristian Høgsberg | 4cca349 | 2011-01-18 07:53:49 -0500 | [diff] [blame] | 1778 | move_grab_motion, |
| 1779 | move_grab_button, |
Jonas Ådahl | 1ea343e | 2013-10-25 23:18:05 +0200 | [diff] [blame] | 1780 | move_grab_cancel, |
Kristian Høgsberg | 4cca349 | 2011-01-18 07:53:49 -0500 | [diff] [blame] | 1781 | }; |
| 1782 | |
Kristian Høgsberg | 9e31bff | 2012-08-01 00:08:07 -0400 | [diff] [blame] | 1783 | static int |
Derek Foreman | 794fa0e | 2015-07-15 13:00:38 -0500 | [diff] [blame] | 1784 | surface_move(struct shell_surface *shsurf, struct weston_pointer *pointer, |
Derek Foreman | cf7d95a | 2015-06-03 15:53:22 -0500 | [diff] [blame] | 1785 | bool client_initiated) |
Kristian Høgsberg | 9e31bff | 2012-08-01 00:08:07 -0400 | [diff] [blame] | 1786 | { |
| 1787 | struct weston_move_grab *move; |
| 1788 | |
| 1789 | if (!shsurf) |
| 1790 | return -1; |
| 1791 | |
Derek Foreman | 45a7c27 | 2015-09-11 14:27:40 -0500 | [diff] [blame] | 1792 | shsurf = find_toplevel_surface(shsurf); |
| 1793 | |
Kristian Høgsberg | a4b620e | 2014-04-30 16:05:49 -0700 | [diff] [blame] | 1794 | if (shsurf->grabbed || |
| 1795 | shsurf->state.fullscreen || shsurf->state.maximized) |
Kristian Høgsberg | 9e31bff | 2012-08-01 00:08:07 -0400 | [diff] [blame] | 1796 | return 0; |
| 1797 | |
| 1798 | move = malloc(sizeof *move); |
| 1799 | if (!move) |
| 1800 | return -1; |
| 1801 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 1802 | move->dx = wl_fixed_from_double(shsurf->view->geometry.x) - |
Derek Foreman | 794fa0e | 2015-07-15 13:00:38 -0500 | [diff] [blame] | 1803 | pointer->grab_x; |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 1804 | move->dy = wl_fixed_from_double(shsurf->view->geometry.y) - |
Derek Foreman | 794fa0e | 2015-07-15 13:00:38 -0500 | [diff] [blame] | 1805 | pointer->grab_y; |
Kristian Høgsberg | ae356ae | 2014-04-29 16:03:54 -0700 | [diff] [blame] | 1806 | move->client_initiated = client_initiated; |
Kristian Høgsberg | 9e31bff | 2012-08-01 00:08:07 -0400 | [diff] [blame] | 1807 | |
| 1808 | shell_grab_start(&move->base, &move_grab_interface, shsurf, |
Derek Foreman | 794fa0e | 2015-07-15 13:00:38 -0500 | [diff] [blame] | 1809 | pointer, DESKTOP_SHELL_CURSOR_MOVE); |
Kristian Høgsberg | 9e31bff | 2012-08-01 00:08:07 -0400 | [diff] [blame] | 1810 | |
| 1811 | return 0; |
| 1812 | } |
| 1813 | |
| 1814 | static void |
Rafael Antognolli | e2a3455 | 2013-12-03 15:35:45 -0200 | [diff] [blame] | 1815 | common_surface_move(struct wl_resource *resource, |
| 1816 | struct wl_resource *seat_resource, uint32_t serial) |
Kristian Høgsberg | 9e31bff | 2012-08-01 00:08:07 -0400 | [diff] [blame] | 1817 | { |
Jason Ekstrand | 44a3863 | 2013-06-14 10:08:00 -0500 | [diff] [blame] | 1818 | struct weston_seat *seat = wl_resource_get_user_data(seat_resource); |
Derek Foreman | 1281a36 | 2015-07-31 16:55:32 -0500 | [diff] [blame] | 1819 | struct weston_pointer *pointer = weston_seat_get_pointer(seat); |
| 1820 | struct weston_touch *touch = weston_seat_get_touch(seat); |
Jason Ekstrand | 651f00e | 2013-06-14 10:07:54 -0500 | [diff] [blame] | 1821 | struct shell_surface *shsurf = wl_resource_get_user_data(resource); |
Giulio Camuffo | 61da3fc | 2013-04-25 13:57:45 +0300 | [diff] [blame] | 1822 | struct weston_surface *surface; |
Kristian Høgsberg | 9e31bff | 2012-08-01 00:08:07 -0400 | [diff] [blame] | 1823 | |
Derek Foreman | 1281a36 | 2015-07-31 16:55:32 -0500 | [diff] [blame] | 1824 | if (pointer && |
| 1825 | pointer->focus && |
| 1826 | pointer->button_count > 0 && |
| 1827 | pointer->grab_serial == serial) { |
| 1828 | surface = weston_surface_get_main_surface(pointer->focus->surface); |
U. Artie Eoff | cf5737a | 2014-01-17 10:08:25 -0800 | [diff] [blame] | 1829 | if ((surface == shsurf->surface) && |
Derek Foreman | 1281a36 | 2015-07-31 16:55:32 -0500 | [diff] [blame] | 1830 | (surface_move(shsurf, pointer, true) < 0)) |
Rusty Lynch | 1084da5 | 2013-08-15 09:10:08 -0700 | [diff] [blame] | 1831 | wl_resource_post_no_memory(resource); |
Derek Foreman | 1281a36 | 2015-07-31 16:55:32 -0500 | [diff] [blame] | 1832 | } else if (touch && |
| 1833 | touch->focus && |
| 1834 | touch->grab_serial == serial) { |
| 1835 | surface = weston_surface_get_main_surface(touch->focus->surface); |
U. Artie Eoff | cf5737a | 2014-01-17 10:08:25 -0800 | [diff] [blame] | 1836 | if ((surface == shsurf->surface) && |
Derek Foreman | 1281a36 | 2015-07-31 16:55:32 -0500 | [diff] [blame] | 1837 | (surface_touch_move(shsurf, touch) < 0)) |
Rusty Lynch | 1084da5 | 2013-08-15 09:10:08 -0700 | [diff] [blame] | 1838 | wl_resource_post_no_memory(resource); |
| 1839 | } |
Kristian Høgsberg | 9e31bff | 2012-08-01 00:08:07 -0400 | [diff] [blame] | 1840 | } |
| 1841 | |
Rafael Antognolli | e2a3455 | 2013-12-03 15:35:45 -0200 | [diff] [blame] | 1842 | static void |
| 1843 | shell_surface_move(struct wl_client *client, struct wl_resource *resource, |
| 1844 | struct wl_resource *seat_resource, uint32_t serial) |
| 1845 | { |
| 1846 | common_surface_move(resource, seat_resource, serial); |
| 1847 | } |
| 1848 | |
Kristian Høgsberg | 9e31bff | 2012-08-01 00:08:07 -0400 | [diff] [blame] | 1849 | struct weston_resize_grab { |
| 1850 | struct shell_grab base; |
| 1851 | uint32_t edges; |
| 1852 | int32_t width, height; |
| 1853 | }; |
| 1854 | |
| 1855 | static void |
Giulio Camuffo | 1959ab8 | 2013-11-14 23:42:52 +0100 | [diff] [blame] | 1856 | resize_grab_motion(struct weston_pointer_grab *grab, uint32_t time, |
| 1857 | wl_fixed_t x, wl_fixed_t y) |
Kristian Høgsberg | 9e31bff | 2012-08-01 00:08:07 -0400 | [diff] [blame] | 1858 | { |
| 1859 | struct weston_resize_grab *resize = (struct weston_resize_grab *) grab; |
Kristian Høgsberg | 02bbabb | 2013-05-06 22:15:05 -0400 | [diff] [blame] | 1860 | struct weston_pointer *pointer = grab->pointer; |
Kristian Høgsberg | 9e31bff | 2012-08-01 00:08:07 -0400 | [diff] [blame] | 1861 | struct shell_surface *shsurf = resize->base.shsurf; |
| 1862 | int32_t width, height; |
| 1863 | wl_fixed_t from_x, from_y; |
| 1864 | wl_fixed_t to_x, to_y; |
| 1865 | |
Giulio Camuffo | 1959ab8 | 2013-11-14 23:42:52 +0100 | [diff] [blame] | 1866 | weston_pointer_move(pointer, x, y); |
| 1867 | |
Kristian Høgsberg | e0b9d5b | 2014-04-30 13:45:49 -0700 | [diff] [blame] | 1868 | if (!shsurf) |
Kristian Høgsberg | 9e31bff | 2012-08-01 00:08:07 -0400 | [diff] [blame] | 1869 | return; |
| 1870 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 1871 | weston_view_from_global_fixed(shsurf->view, |
| 1872 | pointer->grab_x, pointer->grab_y, |
| 1873 | &from_x, &from_y); |
| 1874 | weston_view_from_global_fixed(shsurf->view, |
| 1875 | pointer->x, pointer->y, &to_x, &to_y); |
Kristian Høgsberg | 9e31bff | 2012-08-01 00:08:07 -0400 | [diff] [blame] | 1876 | |
| 1877 | width = resize->width; |
| 1878 | if (resize->edges & WL_SHELL_SURFACE_RESIZE_LEFT) { |
| 1879 | width += wl_fixed_to_int(from_x - to_x); |
| 1880 | } else if (resize->edges & WL_SHELL_SURFACE_RESIZE_RIGHT) { |
| 1881 | width += wl_fixed_to_int(to_x - from_x); |
| 1882 | } |
| 1883 | |
| 1884 | height = resize->height; |
| 1885 | if (resize->edges & WL_SHELL_SURFACE_RESIZE_TOP) { |
| 1886 | height += wl_fixed_to_int(from_y - to_y); |
| 1887 | } else if (resize->edges & WL_SHELL_SURFACE_RESIZE_BOTTOM) { |
| 1888 | height += wl_fixed_to_int(to_y - from_y); |
| 1889 | } |
| 1890 | |
Derek Foreman | 70ac0ed | 2015-03-18 11:16:33 -0500 | [diff] [blame] | 1891 | if (width < 1) |
| 1892 | width = 1; |
| 1893 | if (height < 1) |
| 1894 | height = 1; |
Jasper St. Pierre | ac985be | 2014-04-28 11:19:28 -0400 | [diff] [blame] | 1895 | shsurf->client->send_configure(shsurf->surface, width, height); |
Kristian Høgsberg | 9e31bff | 2012-08-01 00:08:07 -0400 | [diff] [blame] | 1896 | } |
| 1897 | |
| 1898 | static void |
Jasper St. Pierre | ac985be | 2014-04-28 11:19:28 -0400 | [diff] [blame] | 1899 | 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] | 1900 | { |
| 1901 | struct shell_surface *shsurf = get_shell_surface(surface); |
| 1902 | |
U. Artie Eoff | cf5737a | 2014-01-17 10:08:25 -0800 | [diff] [blame] | 1903 | assert(shsurf); |
| 1904 | |
Kristian Høgsberg | e0b9d5b | 2014-04-30 13:45:49 -0700 | [diff] [blame] | 1905 | if (shsurf->resource) |
| 1906 | wl_shell_surface_send_configure(shsurf->resource, |
Jasper St. Pierre | ac985be | 2014-04-28 11:19:28 -0400 | [diff] [blame] | 1907 | shsurf->resize_edges, |
| 1908 | width, height); |
Kristian Høgsberg | 9e31bff | 2012-08-01 00:08:07 -0400 | [diff] [blame] | 1909 | } |
| 1910 | |
| 1911 | static const struct weston_shell_client shell_client = { |
| 1912 | send_configure |
| 1913 | }; |
| 1914 | |
| 1915 | static void |
Kristian Høgsberg | 02bbabb | 2013-05-06 22:15:05 -0400 | [diff] [blame] | 1916 | resize_grab_button(struct weston_pointer_grab *grab, |
Kristian Høgsberg | 9e31bff | 2012-08-01 00:08:07 -0400 | [diff] [blame] | 1917 | uint32_t time, uint32_t button, uint32_t state_w) |
| 1918 | { |
| 1919 | struct weston_resize_grab *resize = (struct weston_resize_grab *) grab; |
Kristian Høgsberg | 02bbabb | 2013-05-06 22:15:05 -0400 | [diff] [blame] | 1920 | struct weston_pointer *pointer = grab->pointer; |
Kristian Høgsberg | 9e31bff | 2012-08-01 00:08:07 -0400 | [diff] [blame] | 1921 | enum wl_pointer_button_state state = state_w; |
| 1922 | |
| 1923 | if (pointer->button_count == 0 && |
| 1924 | state == WL_POINTER_BUTTON_STATE_RELEASED) { |
| 1925 | shell_grab_end(&resize->base); |
| 1926 | free(grab); |
| 1927 | } |
| 1928 | } |
| 1929 | |
Jonas Ådahl | 1ea343e | 2013-10-25 23:18:05 +0200 | [diff] [blame] | 1930 | static void |
| 1931 | resize_grab_cancel(struct weston_pointer_grab *grab) |
| 1932 | { |
| 1933 | struct weston_resize_grab *resize = (struct weston_resize_grab *) grab; |
| 1934 | |
| 1935 | shell_grab_end(&resize->base); |
| 1936 | free(grab); |
| 1937 | } |
| 1938 | |
Kristian Høgsberg | 02bbabb | 2013-05-06 22:15:05 -0400 | [diff] [blame] | 1939 | static const struct weston_pointer_grab_interface resize_grab_interface = { |
Kristian Høgsberg | 9e31bff | 2012-08-01 00:08:07 -0400 | [diff] [blame] | 1940 | noop_grab_focus, |
| 1941 | resize_grab_motion, |
| 1942 | resize_grab_button, |
Jonas Ådahl | 1ea343e | 2013-10-25 23:18:05 +0200 | [diff] [blame] | 1943 | resize_grab_cancel, |
Kristian Høgsberg | 9e31bff | 2012-08-01 00:08:07 -0400 | [diff] [blame] | 1944 | }; |
| 1945 | |
Giulio Camuffo | b836664 | 2013-04-25 13:57:46 +0300 | [diff] [blame] | 1946 | /* |
| 1947 | * Returns the bounding box of a surface and all its sub-surfaces, |
| 1948 | * in the surface coordinates system. */ |
| 1949 | static void |
| 1950 | surface_subsurfaces_boundingbox(struct weston_surface *surface, int32_t *x, |
| 1951 | int32_t *y, int32_t *w, int32_t *h) { |
| 1952 | pixman_region32_t region; |
| 1953 | pixman_box32_t *box; |
| 1954 | struct weston_subsurface *subsurface; |
| 1955 | |
| 1956 | pixman_region32_init_rect(®ion, 0, 0, |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 1957 | surface->width, |
| 1958 | surface->height); |
Giulio Camuffo | b836664 | 2013-04-25 13:57:46 +0300 | [diff] [blame] | 1959 | |
| 1960 | wl_list_for_each(subsurface, &surface->subsurface_list, parent_link) { |
| 1961 | pixman_region32_union_rect(®ion, ®ion, |
| 1962 | subsurface->position.x, |
| 1963 | subsurface->position.y, |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 1964 | subsurface->surface->width, |
| 1965 | subsurface->surface->height); |
Giulio Camuffo | b836664 | 2013-04-25 13:57:46 +0300 | [diff] [blame] | 1966 | } |
| 1967 | |
| 1968 | box = pixman_region32_extents(®ion); |
| 1969 | if (x) |
| 1970 | *x = box->x1; |
| 1971 | if (y) |
| 1972 | *y = box->y1; |
| 1973 | if (w) |
| 1974 | *w = box->x2 - box->x1; |
| 1975 | if (h) |
| 1976 | *h = box->y2 - box->y1; |
| 1977 | |
| 1978 | pixman_region32_fini(®ion); |
| 1979 | } |
| 1980 | |
Kristian Høgsberg | 9e31bff | 2012-08-01 00:08:07 -0400 | [diff] [blame] | 1981 | static int |
| 1982 | surface_resize(struct shell_surface *shsurf, |
Derek Foreman | 8fbebbd | 2015-07-15 13:00:40 -0500 | [diff] [blame] | 1983 | struct weston_pointer *pointer, uint32_t edges) |
Kristian Høgsberg | 9e31bff | 2012-08-01 00:08:07 -0400 | [diff] [blame] | 1984 | { |
| 1985 | struct weston_resize_grab *resize; |
Ondřej Majerech | ae9c4fc | 2014-08-21 15:47:22 +0200 | [diff] [blame] | 1986 | const unsigned resize_topbottom = |
| 1987 | WL_SHELL_SURFACE_RESIZE_TOP | WL_SHELL_SURFACE_RESIZE_BOTTOM; |
| 1988 | const unsigned resize_leftright = |
| 1989 | WL_SHELL_SURFACE_RESIZE_LEFT | WL_SHELL_SURFACE_RESIZE_RIGHT; |
| 1990 | const unsigned resize_any = resize_topbottom | resize_leftright; |
Kristian Høgsberg | 9e31bff | 2012-08-01 00:08:07 -0400 | [diff] [blame] | 1991 | |
Kristian Høgsberg | a4b620e | 2014-04-30 16:05:49 -0700 | [diff] [blame] | 1992 | if (shsurf->grabbed || |
| 1993 | shsurf->state.fullscreen || shsurf->state.maximized) |
Kristian Høgsberg | 9e31bff | 2012-08-01 00:08:07 -0400 | [diff] [blame] | 1994 | return 0; |
| 1995 | |
Ondřej Majerech | ae9c4fc | 2014-08-21 15:47:22 +0200 | [diff] [blame] | 1996 | /* Check for invalid edge combinations. */ |
| 1997 | if (edges == WL_SHELL_SURFACE_RESIZE_NONE || edges > resize_any || |
| 1998 | (edges & resize_topbottom) == resize_topbottom || |
| 1999 | (edges & resize_leftright) == resize_leftright) |
Kristian Høgsberg | 9e31bff | 2012-08-01 00:08:07 -0400 | [diff] [blame] | 2000 | return 0; |
| 2001 | |
| 2002 | resize = malloc(sizeof *resize); |
| 2003 | if (!resize) |
| 2004 | return -1; |
| 2005 | |
| 2006 | resize->edges = edges; |
Kristian Høgsberg | 9e31bff | 2012-08-01 00:08:07 -0400 | [diff] [blame] | 2007 | |
Jasper St. Pierre | ccf48fb | 2014-05-02 10:21:38 -0400 | [diff] [blame] | 2008 | resize->width = shsurf->geometry.width; |
| 2009 | resize->height = shsurf->geometry.height; |
Jasper St. Pierre | bd65e50 | 2014-07-14 16:28:48 -0400 | [diff] [blame] | 2010 | |
Kristian Høgsberg | 44cd196 | 2014-02-05 21:36:04 -0800 | [diff] [blame] | 2011 | shsurf->resize_edges = edges; |
Jasper St. Pierre | 5befdda | 2014-05-06 08:50:47 -0400 | [diff] [blame] | 2012 | shell_surface_state_changed(shsurf); |
Kristian Høgsberg | 9e31bff | 2012-08-01 00:08:07 -0400 | [diff] [blame] | 2013 | shell_grab_start(&resize->base, &resize_grab_interface, shsurf, |
Derek Foreman | 8fbebbd | 2015-07-15 13:00:40 -0500 | [diff] [blame] | 2014 | pointer, edges); |
Kristian Høgsberg | 9e31bff | 2012-08-01 00:08:07 -0400 | [diff] [blame] | 2015 | |
| 2016 | return 0; |
| 2017 | } |
| 2018 | |
| 2019 | static void |
Rafael Antognolli | e2a3455 | 2013-12-03 15:35:45 -0200 | [diff] [blame] | 2020 | common_surface_resize(struct wl_resource *resource, |
| 2021 | struct wl_resource *seat_resource, uint32_t serial, |
| 2022 | uint32_t edges) |
Kristian Høgsberg | 9e31bff | 2012-08-01 00:08:07 -0400 | [diff] [blame] | 2023 | { |
Jason Ekstrand | 44a3863 | 2013-06-14 10:08:00 -0500 | [diff] [blame] | 2024 | struct weston_seat *seat = wl_resource_get_user_data(seat_resource); |
Derek Foreman | 1281a36 | 2015-07-31 16:55:32 -0500 | [diff] [blame] | 2025 | struct weston_pointer *pointer = weston_seat_get_pointer(seat); |
Jason Ekstrand | 651f00e | 2013-06-14 10:07:54 -0500 | [diff] [blame] | 2026 | struct shell_surface *shsurf = wl_resource_get_user_data(resource); |
Giulio Camuffo | 61da3fc | 2013-04-25 13:57:45 +0300 | [diff] [blame] | 2027 | struct weston_surface *surface; |
Kristian Høgsberg | 9e31bff | 2012-08-01 00:08:07 -0400 | [diff] [blame] | 2028 | |
Derek Foreman | 1281a36 | 2015-07-31 16:55:32 -0500 | [diff] [blame] | 2029 | if (!pointer || |
| 2030 | pointer->button_count == 0 || |
| 2031 | pointer->grab_serial != serial || |
| 2032 | pointer->focus == NULL) |
Kristian Høgsberg | 70f2901 | 2014-01-09 15:43:17 -0800 | [diff] [blame] | 2033 | return; |
| 2034 | |
Derek Foreman | 1281a36 | 2015-07-31 16:55:32 -0500 | [diff] [blame] | 2035 | surface = weston_surface_get_main_surface(pointer->focus->surface); |
Kristian Høgsberg | 70f2901 | 2014-01-09 15:43:17 -0800 | [diff] [blame] | 2036 | if (surface != shsurf->surface) |
Kristian Høgsberg | 9e31bff | 2012-08-01 00:08:07 -0400 | [diff] [blame] | 2037 | return; |
| 2038 | |
Derek Foreman | 1281a36 | 2015-07-31 16:55:32 -0500 | [diff] [blame] | 2039 | if (surface_resize(shsurf, pointer, edges) < 0) |
Kristian Høgsberg | 9e31bff | 2012-08-01 00:08:07 -0400 | [diff] [blame] | 2040 | wl_resource_post_no_memory(resource); |
| 2041 | } |
| 2042 | |
Scott Moreau | c3e54eb | 2012-04-17 19:06:20 -0600 | [diff] [blame] | 2043 | static void |
Rafael Antognolli | e2a3455 | 2013-12-03 15:35:45 -0200 | [diff] [blame] | 2044 | shell_surface_resize(struct wl_client *client, struct wl_resource *resource, |
| 2045 | struct wl_resource *seat_resource, uint32_t serial, |
| 2046 | uint32_t edges) |
| 2047 | { |
| 2048 | common_surface_resize(resource, seat_resource, serial, edges); |
| 2049 | } |
| 2050 | |
| 2051 | static void |
Kristian Høgsberg | 6848c25 | 2013-05-08 22:02:59 -0400 | [diff] [blame] | 2052 | busy_cursor_grab_focus(struct weston_pointer_grab *base) |
Scott Moreau | c3e54eb | 2012-04-17 19:06:20 -0600 | [diff] [blame] | 2053 | { |
Kristian Høgsberg | d56bd90 | 2012-06-05 09:58:51 -0400 | [diff] [blame] | 2054 | struct shell_grab *grab = (struct shell_grab *) base; |
Kristian Høgsberg | 6848c25 | 2013-05-08 22:02:59 -0400 | [diff] [blame] | 2055 | struct weston_pointer *pointer = base->pointer; |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 2056 | struct weston_view *view; |
Kristian Høgsberg | 6848c25 | 2013-05-08 22:02:59 -0400 | [diff] [blame] | 2057 | wl_fixed_t sx, sy; |
| 2058 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 2059 | view = weston_compositor_pick_view(pointer->seat->compositor, |
| 2060 | pointer->x, pointer->y, |
| 2061 | &sx, &sy); |
Scott Moreau | c3e54eb | 2012-04-17 19:06:20 -0600 | [diff] [blame] | 2062 | |
Kristian Høgsberg | 2bff94e | 2014-02-11 12:22:51 -0800 | [diff] [blame] | 2063 | if (!grab->shsurf || grab->shsurf->surface != view->surface) { |
| 2064 | shell_grab_end(grab); |
| 2065 | free(grab); |
| 2066 | } |
Scott Moreau | c3e54eb | 2012-04-17 19:06:20 -0600 | [diff] [blame] | 2067 | } |
| 2068 | |
| 2069 | static void |
Giulio Camuffo | 1959ab8 | 2013-11-14 23:42:52 +0100 | [diff] [blame] | 2070 | busy_cursor_grab_motion(struct weston_pointer_grab *grab, uint32_t time, |
| 2071 | wl_fixed_t x, wl_fixed_t y) |
Scott Moreau | c3e54eb | 2012-04-17 19:06:20 -0600 | [diff] [blame] | 2072 | { |
Giulio Camuffo | 1959ab8 | 2013-11-14 23:42:52 +0100 | [diff] [blame] | 2073 | weston_pointer_move(grab->pointer, x, y); |
Kristian Høgsberg | d56bd90 | 2012-06-05 09:58:51 -0400 | [diff] [blame] | 2074 | } |
Scott Moreau | c3e54eb | 2012-04-17 19:06:20 -0600 | [diff] [blame] | 2075 | |
Kristian Høgsberg | d56bd90 | 2012-06-05 09:58:51 -0400 | [diff] [blame] | 2076 | static void |
Kristian Høgsberg | 02bbabb | 2013-05-06 22:15:05 -0400 | [diff] [blame] | 2077 | busy_cursor_grab_button(struct weston_pointer_grab *base, |
Kristian Høgsberg | d56bd90 | 2012-06-05 09:58:51 -0400 | [diff] [blame] | 2078 | uint32_t time, uint32_t button, uint32_t state) |
| 2079 | { |
Kristian Høgsberg | bbe9839 | 2012-08-01 00:20:21 -0400 | [diff] [blame] | 2080 | struct shell_grab *grab = (struct shell_grab *) base; |
Kristian Høgsberg | e122b7b | 2013-05-08 16:47:00 -0400 | [diff] [blame] | 2081 | struct shell_surface *shsurf = grab->shsurf; |
Derek Foreman | 794fa0e | 2015-07-15 13:00:38 -0500 | [diff] [blame] | 2082 | struct weston_pointer *pointer = grab->grab.pointer; |
| 2083 | struct weston_seat *seat = pointer->seat; |
Kristian Høgsberg | bbe9839 | 2012-08-01 00:20:21 -0400 | [diff] [blame] | 2084 | |
Kristian Høgsberg | bbe9839 | 2012-08-01 00:20:21 -0400 | [diff] [blame] | 2085 | if (shsurf && button == BTN_LEFT && state) { |
Emilio Pozuelo Monfort | 9e7c759 | 2014-01-30 14:01:10 +0100 | [diff] [blame] | 2086 | activate(shsurf->shell, shsurf->surface, seat, true); |
Derek Foreman | 794fa0e | 2015-07-15 13:00:38 -0500 | [diff] [blame] | 2087 | surface_move(shsurf, pointer, false); |
Kristian Høgsberg | 0c36903 | 2013-02-14 21:31:44 -0500 | [diff] [blame] | 2088 | } else if (shsurf && button == BTN_RIGHT && state) { |
Emilio Pozuelo Monfort | 9e7c759 | 2014-01-30 14:01:10 +0100 | [diff] [blame] | 2089 | activate(shsurf->shell, shsurf->surface, seat, true); |
Derek Foreman | 74de469 | 2015-07-15 13:00:39 -0500 | [diff] [blame] | 2090 | surface_rotate(shsurf, pointer); |
Kristian Høgsberg | bbe9839 | 2012-08-01 00:20:21 -0400 | [diff] [blame] | 2091 | } |
Kristian Høgsberg | d56bd90 | 2012-06-05 09:58:51 -0400 | [diff] [blame] | 2092 | } |
| 2093 | |
Jonas Ådahl | 1ea343e | 2013-10-25 23:18:05 +0200 | [diff] [blame] | 2094 | static void |
| 2095 | busy_cursor_grab_cancel(struct weston_pointer_grab *base) |
| 2096 | { |
| 2097 | struct shell_grab *grab = (struct shell_grab *) base; |
| 2098 | |
| 2099 | shell_grab_end(grab); |
| 2100 | free(grab); |
| 2101 | } |
| 2102 | |
Kristian Høgsberg | 02bbabb | 2013-05-06 22:15:05 -0400 | [diff] [blame] | 2103 | static const struct weston_pointer_grab_interface busy_cursor_grab_interface = { |
Kristian Høgsberg | d56bd90 | 2012-06-05 09:58:51 -0400 | [diff] [blame] | 2104 | busy_cursor_grab_focus, |
| 2105 | busy_cursor_grab_motion, |
| 2106 | busy_cursor_grab_button, |
Jonas Ådahl | 1ea343e | 2013-10-25 23:18:05 +0200 | [diff] [blame] | 2107 | busy_cursor_grab_cancel, |
Kristian Høgsberg | d56bd90 | 2012-06-05 09:58:51 -0400 | [diff] [blame] | 2108 | }; |
| 2109 | |
| 2110 | static void |
Kristian Høgsberg | 02bbabb | 2013-05-06 22:15:05 -0400 | [diff] [blame] | 2111 | set_busy_cursor(struct shell_surface *shsurf, struct weston_pointer *pointer) |
Kristian Høgsberg | d56bd90 | 2012-06-05 09:58:51 -0400 | [diff] [blame] | 2112 | { |
| 2113 | struct shell_grab *grab; |
Kristian Høgsberg | d56bd90 | 2012-06-05 09:58:51 -0400 | [diff] [blame] | 2114 | |
Kristian Høgsberg | 2bff94e | 2014-02-11 12:22:51 -0800 | [diff] [blame] | 2115 | if (pointer->grab->interface == &busy_cursor_grab_interface) |
| 2116 | return; |
| 2117 | |
Kristian Høgsberg | d56bd90 | 2012-06-05 09:58:51 -0400 | [diff] [blame] | 2118 | grab = malloc(sizeof *grab); |
| 2119 | if (!grab) |
Scott Moreau | c3e54eb | 2012-04-17 19:06:20 -0600 | [diff] [blame] | 2120 | return; |
| 2121 | |
Ander Conselvan de Oliveira | b9d2a0f | 2012-06-28 18:08:05 +0300 | [diff] [blame] | 2122 | shell_grab_start(grab, &busy_cursor_grab_interface, shsurf, pointer, |
| 2123 | DESKTOP_SHELL_CURSOR_BUSY); |
Ander Conselvan de Oliveira | e5a1aee | 2014-04-09 17:39:39 +0300 | [diff] [blame] | 2124 | /* Mark the shsurf as ungrabbed so that button binding is able |
| 2125 | * to move it. */ |
| 2126 | shsurf->grabbed = 0; |
Kristian Høgsberg | d56bd90 | 2012-06-05 09:58:51 -0400 | [diff] [blame] | 2127 | } |
Scott Moreau | c3e54eb | 2012-04-17 19:06:20 -0600 | [diff] [blame] | 2128 | |
Kristian Høgsberg | d56bd90 | 2012-06-05 09:58:51 -0400 | [diff] [blame] | 2129 | static void |
Kristian Høgsberg | 2bff94e | 2014-02-11 12:22:51 -0800 | [diff] [blame] | 2130 | end_busy_cursor(struct weston_compositor *compositor, struct wl_client *client) |
Kristian Høgsberg | d56bd90 | 2012-06-05 09:58:51 -0400 | [diff] [blame] | 2131 | { |
Kristian Høgsberg | 2bff94e | 2014-02-11 12:22:51 -0800 | [diff] [blame] | 2132 | struct shell_grab *grab; |
| 2133 | struct weston_seat *seat; |
Kristian Høgsberg | d56bd90 | 2012-06-05 09:58:51 -0400 | [diff] [blame] | 2134 | |
Kristian Høgsberg | 2bff94e | 2014-02-11 12:22:51 -0800 | [diff] [blame] | 2135 | wl_list_for_each(seat, &compositor->seat_list, link) { |
Derek Foreman | 1281a36 | 2015-07-31 16:55:32 -0500 | [diff] [blame] | 2136 | struct weston_pointer *pointer = weston_seat_get_pointer(seat); |
| 2137 | |
| 2138 | if (!pointer) |
Kristian Høgsberg | 2bff94e | 2014-02-11 12:22:51 -0800 | [diff] [blame] | 2139 | continue; |
| 2140 | |
Derek Foreman | 1281a36 | 2015-07-31 16:55:32 -0500 | [diff] [blame] | 2141 | grab = (struct shell_grab *) pointer->grab; |
Kristian Høgsberg | 2bff94e | 2014-02-11 12:22:51 -0800 | [diff] [blame] | 2142 | if (grab->grab.interface == &busy_cursor_grab_interface && |
Derek Foreman | c0c1497 | 2015-09-11 14:30:39 -0500 | [diff] [blame] | 2143 | grab->shsurf->resource && |
Kristian Høgsberg | 2bff94e | 2014-02-11 12:22:51 -0800 | [diff] [blame] | 2144 | wl_resource_get_client(grab->shsurf->resource) == client) { |
| 2145 | shell_grab_end(grab); |
| 2146 | free(grab); |
| 2147 | } |
Scott Moreau | c3e54eb | 2012-04-17 19:06:20 -0600 | [diff] [blame] | 2148 | } |
Scott Moreau | c3e54eb | 2012-04-17 19:06:20 -0600 | [diff] [blame] | 2149 | } |
| 2150 | |
Scott Moreau | 9521d5e | 2012-04-19 13:06:17 -0600 | [diff] [blame] | 2151 | static void |
Kristian Høgsberg | 2bff94e | 2014-02-11 12:22:51 -0800 | [diff] [blame] | 2152 | handle_shell_client_destroy(struct wl_listener *listener, void *data); |
| 2153 | |
| 2154 | static int |
| 2155 | xdg_ping_timeout_handler(void *data) |
| 2156 | { |
| 2157 | struct shell_client *sc = data; |
| 2158 | struct weston_seat *seat; |
| 2159 | struct shell_surface *shsurf; |
| 2160 | |
| 2161 | /* Client is not responding */ |
| 2162 | sc->unresponsive = 1; |
Kristian Høgsberg | 2bff94e | 2014-02-11 12:22:51 -0800 | [diff] [blame] | 2163 | wl_list_for_each(seat, &sc->shell->compositor->seat_list, link) { |
Derek Foreman | 1281a36 | 2015-07-31 16:55:32 -0500 | [diff] [blame] | 2164 | struct weston_pointer *pointer = weston_seat_get_pointer(seat); |
| 2165 | |
| 2166 | if (!pointer || |
| 2167 | !pointer->focus || |
| 2168 | !pointer->focus->surface->resource) |
Kristian Høgsberg | 2bff94e | 2014-02-11 12:22:51 -0800 | [diff] [blame] | 2169 | continue; |
Michael Vetter | 2a18a52 | 2015-05-15 17:17:47 +0200 | [diff] [blame] | 2170 | |
Derek Foreman | 1281a36 | 2015-07-31 16:55:32 -0500 | [diff] [blame] | 2171 | shsurf = get_shell_surface(pointer->focus->surface); |
Kristian Høgsberg | 2bff94e | 2014-02-11 12:22:51 -0800 | [diff] [blame] | 2172 | if (shsurf && |
| 2173 | wl_resource_get_client(shsurf->resource) == sc->client) |
Derek Foreman | 1281a36 | 2015-07-31 16:55:32 -0500 | [diff] [blame] | 2174 | set_busy_cursor(shsurf, pointer); |
Kristian Høgsberg | 2bff94e | 2014-02-11 12:22:51 -0800 | [diff] [blame] | 2175 | } |
| 2176 | |
| 2177 | return 1; |
| 2178 | } |
| 2179 | |
| 2180 | static void |
| 2181 | handle_xdg_ping(struct shell_surface *shsurf, uint32_t serial) |
| 2182 | { |
| 2183 | struct weston_compositor *compositor = shsurf->shell->compositor; |
Jason Ekstrand | 9e9512f | 2014-04-16 21:12:10 -0500 | [diff] [blame] | 2184 | struct shell_client *sc = shsurf->owner; |
Kristian Høgsberg | 2bff94e | 2014-02-11 12:22:51 -0800 | [diff] [blame] | 2185 | struct wl_event_loop *loop; |
Kristian Høgsberg | dd62aba | 2014-02-12 09:56:19 -0800 | [diff] [blame] | 2186 | static const int ping_timeout = 200; |
Kristian Høgsberg | 2bff94e | 2014-02-11 12:22:51 -0800 | [diff] [blame] | 2187 | |
Kristian Høgsberg | 2bff94e | 2014-02-11 12:22:51 -0800 | [diff] [blame] | 2188 | if (sc->unresponsive) { |
| 2189 | xdg_ping_timeout_handler(sc); |
| 2190 | return; |
| 2191 | } |
| 2192 | |
| 2193 | sc->ping_serial = serial; |
| 2194 | loop = wl_display_get_event_loop(compositor->wl_display); |
| 2195 | if (sc->ping_timer == NULL) |
| 2196 | sc->ping_timer = |
| 2197 | wl_event_loop_add_timer(loop, |
| 2198 | xdg_ping_timeout_handler, sc); |
| 2199 | if (sc->ping_timer == NULL) |
| 2200 | return; |
| 2201 | |
| 2202 | wl_event_source_timer_update(sc->ping_timer, ping_timeout); |
| 2203 | |
Kristian Høgsberg | dd62aba | 2014-02-12 09:56:19 -0800 | [diff] [blame] | 2204 | if (shell_surface_is_xdg_surface(shsurf) || |
| 2205 | shell_surface_is_xdg_popup(shsurf)) |
| 2206 | xdg_shell_send_ping(sc->resource, serial); |
| 2207 | else if (shell_surface_is_wl_shell_surface(shsurf)) |
| 2208 | wl_shell_surface_send_ping(shsurf->resource, serial); |
Kristian Høgsberg | 2bff94e | 2014-02-11 12:22:51 -0800 | [diff] [blame] | 2209 | } |
| 2210 | |
Scott Moreau | ff1db4a | 2012-04-17 19:06:18 -0600 | [diff] [blame] | 2211 | static void |
| 2212 | ping_handler(struct weston_surface *surface, uint32_t serial) |
| 2213 | { |
Kristian Høgsberg | b71302e | 2012-05-10 12:28:35 -0400 | [diff] [blame] | 2214 | struct shell_surface *shsurf = get_shell_surface(surface); |
Scott Moreau | ff1db4a | 2012-04-17 19:06:18 -0600 | [diff] [blame] | 2215 | |
| 2216 | if (!shsurf) |
| 2217 | return; |
Jason Ekstrand | 651f00e | 2013-06-14 10:07:54 -0500 | [diff] [blame] | 2218 | if (!shsurf->resource) |
Kristian Høgsberg | ca535c1 | 2012-04-21 23:20:07 -0400 | [diff] [blame] | 2219 | return; |
Ander Conselvan de Oliveira | eac9a46 | 2012-07-16 14:15:48 +0300 | [diff] [blame] | 2220 | if (shsurf->surface == shsurf->shell->grab_surface) |
| 2221 | return; |
| 2222 | |
Kristian Høgsberg | dd62aba | 2014-02-12 09:56:19 -0800 | [diff] [blame] | 2223 | handle_xdg_ping(shsurf, serial); |
Scott Moreau | ff1db4a | 2012-04-17 19:06:18 -0600 | [diff] [blame] | 2224 | } |
| 2225 | |
| 2226 | static void |
Kristian Høgsberg | d56bd90 | 2012-06-05 09:58:51 -0400 | [diff] [blame] | 2227 | handle_pointer_focus(struct wl_listener *listener, void *data) |
| 2228 | { |
Kristian Høgsberg | 02bbabb | 2013-05-06 22:15:05 -0400 | [diff] [blame] | 2229 | struct weston_pointer *pointer = data; |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 2230 | struct weston_view *view = pointer->focus; |
Kristian Høgsberg | d56bd90 | 2012-06-05 09:58:51 -0400 | [diff] [blame] | 2231 | struct weston_compositor *compositor; |
Kristian Høgsberg | d56bd90 | 2012-06-05 09:58:51 -0400 | [diff] [blame] | 2232 | uint32_t serial; |
| 2233 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 2234 | if (!view) |
Kristian Høgsberg | d56bd90 | 2012-06-05 09:58:51 -0400 | [diff] [blame] | 2235 | return; |
| 2236 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 2237 | compositor = view->surface->compositor; |
Kristian Høgsberg | e11ef64 | 2014-02-11 16:35:22 -0800 | [diff] [blame] | 2238 | serial = wl_display_next_serial(compositor->wl_display); |
| 2239 | ping_handler(view->surface, serial); |
Kristian Høgsberg | d56bd90 | 2012-06-05 09:58:51 -0400 | [diff] [blame] | 2240 | } |
| 2241 | |
| 2242 | static void |
Jasper St. Pierre | faf27a9 | 2013-12-09 17:36:28 -0500 | [diff] [blame] | 2243 | shell_surface_lose_keyboard_focus(struct shell_surface *shsurf) |
| 2244 | { |
| 2245 | if (--shsurf->focus_count == 0) |
Jasper St. Pierre | 973d787 | 2014-05-06 08:44:29 -0400 | [diff] [blame] | 2246 | shell_surface_state_changed(shsurf); |
Jasper St. Pierre | faf27a9 | 2013-12-09 17:36:28 -0500 | [diff] [blame] | 2247 | } |
| 2248 | |
| 2249 | static void |
| 2250 | shell_surface_gain_keyboard_focus(struct shell_surface *shsurf) |
| 2251 | { |
| 2252 | if (shsurf->focus_count++ == 0) |
Jasper St. Pierre | 973d787 | 2014-05-06 08:44:29 -0400 | [diff] [blame] | 2253 | shell_surface_state_changed(shsurf); |
Jasper St. Pierre | faf27a9 | 2013-12-09 17:36:28 -0500 | [diff] [blame] | 2254 | } |
| 2255 | |
| 2256 | static void |
| 2257 | handle_keyboard_focus(struct wl_listener *listener, void *data) |
| 2258 | { |
| 2259 | struct weston_keyboard *keyboard = data; |
| 2260 | struct shell_seat *seat = get_shell_seat(keyboard->seat); |
| 2261 | |
| 2262 | if (seat->focused_surface) { |
| 2263 | struct shell_surface *shsurf = get_shell_surface(seat->focused_surface); |
| 2264 | if (shsurf) |
| 2265 | shell_surface_lose_keyboard_focus(shsurf); |
| 2266 | } |
| 2267 | |
| 2268 | seat->focused_surface = keyboard->focus; |
| 2269 | |
| 2270 | if (seat->focused_surface) { |
| 2271 | struct shell_surface *shsurf = get_shell_surface(seat->focused_surface); |
| 2272 | if (shsurf) |
| 2273 | shell_surface_gain_keyboard_focus(shsurf); |
| 2274 | } |
| 2275 | } |
| 2276 | |
| 2277 | static void |
Kristian Høgsberg | dd62aba | 2014-02-12 09:56:19 -0800 | [diff] [blame] | 2278 | shell_client_pong(struct shell_client *sc, uint32_t serial) |
Rafael Antognolli | e2a3455 | 2013-12-03 15:35:45 -0200 | [diff] [blame] | 2279 | { |
Kristian Høgsberg | dd62aba | 2014-02-12 09:56:19 -0800 | [diff] [blame] | 2280 | if (sc->ping_serial != serial) |
| 2281 | return; |
Rafael Antognolli | e2a3455 | 2013-12-03 15:35:45 -0200 | [diff] [blame] | 2282 | |
Kristian Høgsberg | dd62aba | 2014-02-12 09:56:19 -0800 | [diff] [blame] | 2283 | sc->unresponsive = 0; |
| 2284 | end_busy_cursor(sc->shell->compositor, sc->client); |
Rafael Antognolli | e2a3455 | 2013-12-03 15:35:45 -0200 | [diff] [blame] | 2285 | |
Kristian Høgsberg | dd62aba | 2014-02-12 09:56:19 -0800 | [diff] [blame] | 2286 | if (sc->ping_timer) { |
| 2287 | wl_event_source_remove(sc->ping_timer); |
| 2288 | sc->ping_timer = NULL; |
| 2289 | } |
| 2290 | |
| 2291 | } |
| 2292 | |
| 2293 | static void |
| 2294 | shell_surface_pong(struct wl_client *client, |
| 2295 | struct wl_resource *resource, uint32_t serial) |
| 2296 | { |
Jason Ekstrand | 9e9512f | 2014-04-16 21:12:10 -0500 | [diff] [blame] | 2297 | struct shell_surface *shsurf = wl_resource_get_user_data(resource); |
| 2298 | struct shell_client *sc = shsurf->owner; |
Kristian Høgsberg | dd62aba | 2014-02-12 09:56:19 -0800 | [diff] [blame] | 2299 | |
Kristian Høgsberg | dd62aba | 2014-02-12 09:56:19 -0800 | [diff] [blame] | 2300 | shell_client_pong(sc, serial); |
Rafael Antognolli | e2a3455 | 2013-12-03 15:35:45 -0200 | [diff] [blame] | 2301 | } |
| 2302 | |
| 2303 | static void |
Giulio Camuffo | 62942ad | 2013-09-11 18:20:47 +0200 | [diff] [blame] | 2304 | set_title(struct shell_surface *shsurf, const char *title) |
| 2305 | { |
| 2306 | free(shsurf->title); |
| 2307 | shsurf->title = strdup(title); |
Pekka Paalanen | b502654 | 2014-11-12 15:09:24 +0200 | [diff] [blame] | 2308 | shsurf->surface->timeline.force_refresh = 1; |
| 2309 | } |
| 2310 | |
| 2311 | static void |
Giulio Camuffo | a8e9b41 | 2015-01-27 19:10:37 +0200 | [diff] [blame] | 2312 | set_pid(struct shell_surface *shsurf, pid_t pid) |
| 2313 | { |
| 2314 | /* We have no use for it */ |
| 2315 | } |
| 2316 | |
| 2317 | static void |
Pekka Paalanen | b502654 | 2014-11-12 15:09:24 +0200 | [diff] [blame] | 2318 | set_type(struct shell_surface *shsurf, enum shell_surface_type t) |
| 2319 | { |
| 2320 | shsurf->type = t; |
| 2321 | shsurf->surface->timeline.force_refresh = 1; |
Giulio Camuffo | 62942ad | 2013-09-11 18:20:47 +0200 | [diff] [blame] | 2322 | } |
| 2323 | |
| 2324 | static void |
Jasper St. Pierre | ccf48fb | 2014-05-02 10:21:38 -0400 | [diff] [blame] | 2325 | set_window_geometry(struct shell_surface *shsurf, |
| 2326 | 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] | 2327 | { |
Jasper St. Pierre | ccf48fb | 2014-05-02 10:21:38 -0400 | [diff] [blame] | 2328 | shsurf->next_geometry.x = x; |
| 2329 | shsurf->next_geometry.y = y; |
| 2330 | shsurf->next_geometry.width = width; |
| 2331 | shsurf->next_geometry.height = height; |
| 2332 | shsurf->has_next_geometry = true; |
Kristian Høgsberg | e5c1ae9 | 2014-04-30 16:28:41 -0700 | [diff] [blame] | 2333 | } |
| 2334 | |
| 2335 | static void |
Kristian Høgsberg | e7afd91 | 2012-05-02 09:47:44 -0400 | [diff] [blame] | 2336 | shell_surface_set_title(struct wl_client *client, |
| 2337 | struct wl_resource *resource, const char *title) |
| 2338 | { |
Jason Ekstrand | 651f00e | 2013-06-14 10:07:54 -0500 | [diff] [blame] | 2339 | struct shell_surface *shsurf = wl_resource_get_user_data(resource); |
Kristian Høgsberg | e7afd91 | 2012-05-02 09:47:44 -0400 | [diff] [blame] | 2340 | |
Giulio Camuffo | 62942ad | 2013-09-11 18:20:47 +0200 | [diff] [blame] | 2341 | set_title(shsurf, title); |
Kristian Høgsberg | e7afd91 | 2012-05-02 09:47:44 -0400 | [diff] [blame] | 2342 | } |
| 2343 | |
| 2344 | static void |
| 2345 | shell_surface_set_class(struct wl_client *client, |
| 2346 | struct wl_resource *resource, const char *class) |
| 2347 | { |
Jason Ekstrand | 651f00e | 2013-06-14 10:07:54 -0500 | [diff] [blame] | 2348 | struct shell_surface *shsurf = wl_resource_get_user_data(resource); |
Kristian Høgsberg | e7afd91 | 2012-05-02 09:47:44 -0400 | [diff] [blame] | 2349 | |
| 2350 | free(shsurf->class); |
| 2351 | shsurf->class = strdup(class); |
Pekka Paalanen | b502654 | 2014-11-12 15:09:24 +0200 | [diff] [blame] | 2352 | shsurf->surface->timeline.force_refresh = 1; |
Kristian Høgsberg | e7afd91 | 2012-05-02 09:47:44 -0400 | [diff] [blame] | 2353 | } |
| 2354 | |
Alex Wu | 4539b08 | 2012-03-01 12:57:46 +0800 | [diff] [blame] | 2355 | static void |
Alexander Larsson | f82b6ca | 2013-05-28 16:23:39 +0200 | [diff] [blame] | 2356 | restore_output_mode(struct weston_output *output) |
| 2357 | { |
Derek Foreman | 6ae7bc9 | 2014-11-04 10:47:33 -0600 | [diff] [blame] | 2358 | if (output->original_mode) |
| 2359 | weston_output_mode_switch_to_native(output); |
Alexander Larsson | f82b6ca | 2013-05-28 16:23:39 +0200 | [diff] [blame] | 2360 | } |
| 2361 | |
| 2362 | static void |
| 2363 | restore_all_output_modes(struct weston_compositor *compositor) |
| 2364 | { |
| 2365 | struct weston_output *output; |
| 2366 | |
| 2367 | wl_list_for_each(output, &compositor->output_list, link) |
| 2368 | restore_output_mode(output); |
| 2369 | } |
| 2370 | |
Philip Withnall | 07926d9 | 2013-11-25 18:01:40 +0000 | [diff] [blame] | 2371 | /* The surface will be inserted into the list immediately after the link |
| 2372 | * returned by this function (i.e. will be stacked immediately above the |
| 2373 | * returned link). */ |
Giulio Camuffo | 412e6a5 | 2014-07-09 22:12:56 +0300 | [diff] [blame] | 2374 | static struct weston_layer_entry * |
Philip Withnall | 07926d9 | 2013-11-25 18:01:40 +0000 | [diff] [blame] | 2375 | shell_surface_calculate_layer_link (struct shell_surface *shsurf) |
| 2376 | { |
| 2377 | struct workspace *ws; |
Kristian Høgsberg | ead5242 | 2014-01-01 13:51:52 -0800 | [diff] [blame] | 2378 | struct weston_view *parent; |
Philip Withnall | 07926d9 | 2013-11-25 18:01:40 +0000 | [diff] [blame] | 2379 | |
| 2380 | switch (shsurf->type) { |
Ander Conselvan de Oliveira | ef6a7e4 | 2014-04-30 14:15:14 +0300 | [diff] [blame] | 2381 | case SHELL_SURFACE_XWAYLAND: |
| 2382 | return &shsurf->shell->fullscreen_layer.view_list; |
| 2383 | |
| 2384 | case SHELL_SURFACE_NONE: |
| 2385 | return NULL; |
| 2386 | |
Kristian Høgsberg | ead5242 | 2014-01-01 13:51:52 -0800 | [diff] [blame] | 2387 | case SHELL_SURFACE_POPUP: |
| 2388 | case SHELL_SURFACE_TOPLEVEL: |
Emilio Pozuelo Monfort | 9e7c759 | 2014-01-30 14:01:10 +0100 | [diff] [blame] | 2389 | if (shsurf->state.fullscreen && !shsurf->state.lowered) { |
Rafael Antognolli | 03b1659 | 2013-12-03 15:35:42 -0200 | [diff] [blame] | 2390 | return &shsurf->shell->fullscreen_layer.view_list; |
Rafael Antognolli | ed207b4 | 2013-12-03 15:35:43 -0200 | [diff] [blame] | 2391 | } else if (shsurf->parent) { |
Kristian Høgsberg | d55db69 | 2014-01-01 12:26:14 -0800 | [diff] [blame] | 2392 | /* Move the surface to its parent layer so |
| 2393 | * that surfaces which are transient for |
| 2394 | * fullscreen surfaces don't get hidden by the |
| 2395 | * fullscreen surfaces. */ |
Rafael Antognolli | ed207b4 | 2013-12-03 15:35:43 -0200 | [diff] [blame] | 2396 | |
| 2397 | /* TODO: Handle a parent with multiple views */ |
| 2398 | parent = get_default_view(shsurf->parent); |
| 2399 | if (parent) |
Giulio Camuffo | 412e6a5 | 2014-07-09 22:12:56 +0300 | [diff] [blame] | 2400 | return container_of(parent->layer_link.link.prev, |
| 2401 | struct weston_layer_entry, link); |
Rafael Antognolli | ed207b4 | 2013-12-03 15:35:43 -0200 | [diff] [blame] | 2402 | } |
Philip Withnall | 07926d9 | 2013-11-25 18:01:40 +0000 | [diff] [blame] | 2403 | |
Ander Conselvan de Oliveira | ef6a7e4 | 2014-04-30 14:15:14 +0300 | [diff] [blame] | 2404 | /* Move the surface to a normal workspace layer so that surfaces |
| 2405 | * which were previously fullscreen or transient are no longer |
| 2406 | * rendered on top. */ |
| 2407 | ws = get_current_workspace(shsurf->shell); |
| 2408 | return &ws->layer.view_list; |
Philip Withnall | 07926d9 | 2013-11-25 18:01:40 +0000 | [diff] [blame] | 2409 | } |
| 2410 | |
Ander Conselvan de Oliveira | ef6a7e4 | 2014-04-30 14:15:14 +0300 | [diff] [blame] | 2411 | assert(0 && "Unknown shell surface type"); |
Philip Withnall | 07926d9 | 2013-11-25 18:01:40 +0000 | [diff] [blame] | 2412 | } |
| 2413 | |
Philip Withnall | 648a4dd | 2013-11-25 18:01:44 +0000 | [diff] [blame] | 2414 | static void |
| 2415 | shell_surface_update_child_surface_layers (struct shell_surface *shsurf) |
| 2416 | { |
| 2417 | struct shell_surface *child; |
Giulio Camuffo | 412e6a5 | 2014-07-09 22:12:56 +0300 | [diff] [blame] | 2418 | struct weston_layer_entry *prev; |
Philip Withnall | 648a4dd | 2013-11-25 18:01:44 +0000 | [diff] [blame] | 2419 | |
| 2420 | /* Move the child layers to the same workspace as shsurf. They will be |
| 2421 | * stacked above shsurf. */ |
| 2422 | wl_list_for_each_reverse(child, &shsurf->children_list, children_link) { |
Giulio Camuffo | 412e6a5 | 2014-07-09 22:12:56 +0300 | [diff] [blame] | 2423 | 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] | 2424 | weston_view_damage_below(child->view); |
Philip Withnall | 648a4dd | 2013-11-25 18:01:44 +0000 | [diff] [blame] | 2425 | weston_view_geometry_dirty(child->view); |
Giulio Camuffo | 412e6a5 | 2014-07-09 22:12:56 +0300 | [diff] [blame] | 2426 | prev = container_of(shsurf->view->layer_link.link.prev, |
| 2427 | struct weston_layer_entry, link); |
| 2428 | weston_layer_entry_remove(&child->view->layer_link); |
| 2429 | weston_layer_entry_insert(prev, |
| 2430 | &child->view->layer_link); |
Philip Withnall | 648a4dd | 2013-11-25 18:01:44 +0000 | [diff] [blame] | 2431 | weston_view_geometry_dirty(child->view); |
| 2432 | weston_surface_damage(child->surface); |
| 2433 | |
| 2434 | /* Recurse. We don’t expect this to recurse very far (if |
| 2435 | * at all) because that would imply we have transient |
| 2436 | * (or popup) children of transient surfaces, which |
| 2437 | * would be unusual. */ |
| 2438 | shell_surface_update_child_surface_layers(child); |
| 2439 | } |
| 2440 | } |
| 2441 | } |
| 2442 | |
Philip Withnall | e1d75ae | 2013-11-25 18:01:41 +0000 | [diff] [blame] | 2443 | /* 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] | 2444 | * geometry to ensure the changes are redrawn. |
| 2445 | * |
| 2446 | * If any child surfaces exist and are mapped, ensure they’re in the same layer |
| 2447 | * as this surface. */ |
Philip Withnall | e1d75ae | 2013-11-25 18:01:41 +0000 | [diff] [blame] | 2448 | static void |
| 2449 | shell_surface_update_layer(struct shell_surface *shsurf) |
| 2450 | { |
Giulio Camuffo | 412e6a5 | 2014-07-09 22:12:56 +0300 | [diff] [blame] | 2451 | struct weston_layer_entry *new_layer_link; |
Philip Withnall | e1d75ae | 2013-11-25 18:01:41 +0000 | [diff] [blame] | 2452 | |
| 2453 | new_layer_link = shell_surface_calculate_layer_link(shsurf); |
| 2454 | |
Ander Conselvan de Oliveira | ef6a7e4 | 2014-04-30 14:15:14 +0300 | [diff] [blame] | 2455 | if (new_layer_link == NULL) |
| 2456 | return; |
Philip Withnall | e1d75ae | 2013-11-25 18:01:41 +0000 | [diff] [blame] | 2457 | if (new_layer_link == &shsurf->view->layer_link) |
| 2458 | return; |
| 2459 | |
| 2460 | weston_view_geometry_dirty(shsurf->view); |
Giulio Camuffo | 412e6a5 | 2014-07-09 22:12:56 +0300 | [diff] [blame] | 2461 | weston_layer_entry_remove(&shsurf->view->layer_link); |
| 2462 | weston_layer_entry_insert(new_layer_link, &shsurf->view->layer_link); |
Philip Withnall | e1d75ae | 2013-11-25 18:01:41 +0000 | [diff] [blame] | 2463 | weston_view_geometry_dirty(shsurf->view); |
| 2464 | weston_surface_damage(shsurf->surface); |
Philip Withnall | 648a4dd | 2013-11-25 18:01:44 +0000 | [diff] [blame] | 2465 | |
| 2466 | shell_surface_update_child_surface_layers(shsurf); |
Philip Withnall | e1d75ae | 2013-11-25 18:01:41 +0000 | [diff] [blame] | 2467 | } |
| 2468 | |
Alexander Larsson | f82b6ca | 2013-05-28 16:23:39 +0200 | [diff] [blame] | 2469 | static void |
Philip Withnall | dc4332f | 2013-11-25 18:01:38 +0000 | [diff] [blame] | 2470 | shell_surface_set_parent(struct shell_surface *shsurf, |
| 2471 | struct weston_surface *parent) |
| 2472 | { |
| 2473 | shsurf->parent = parent; |
Philip Withnall | 648a4dd | 2013-11-25 18:01:44 +0000 | [diff] [blame] | 2474 | |
| 2475 | wl_list_remove(&shsurf->children_link); |
| 2476 | wl_list_init(&shsurf->children_link); |
| 2477 | |
| 2478 | /* Insert into the parent surface’s child list. */ |
| 2479 | if (parent != NULL) { |
| 2480 | struct shell_surface *parent_shsurf = get_shell_surface(parent); |
| 2481 | if (parent_shsurf != NULL) |
| 2482 | wl_list_insert(&parent_shsurf->children_list, |
| 2483 | &shsurf->children_link); |
| 2484 | } |
Philip Withnall | dc4332f | 2013-11-25 18:01:38 +0000 | [diff] [blame] | 2485 | } |
| 2486 | |
| 2487 | static void |
Philip Withnall | 352e7ed | 2013-11-25 18:01:35 +0000 | [diff] [blame] | 2488 | shell_surface_set_output(struct shell_surface *shsurf, |
| 2489 | struct weston_output *output) |
| 2490 | { |
| 2491 | struct weston_surface *es = shsurf->surface; |
| 2492 | |
| 2493 | /* get the default output, if the client set it as NULL |
| 2494 | check whether the ouput is available */ |
| 2495 | if (output) |
| 2496 | shsurf->output = output; |
| 2497 | else if (es->output) |
| 2498 | shsurf->output = es->output; |
| 2499 | else |
| 2500 | shsurf->output = get_default_output(es->compositor); |
| 2501 | } |
| 2502 | |
| 2503 | static void |
Rafael Antognolli | 03b1659 | 2013-12-03 15:35:42 -0200 | [diff] [blame] | 2504 | surface_clear_next_states(struct shell_surface *shsurf) |
| 2505 | { |
| 2506 | shsurf->next_state.maximized = false; |
| 2507 | shsurf->next_state.fullscreen = false; |
| 2508 | |
| 2509 | if ((shsurf->next_state.maximized != shsurf->state.maximized) || |
| 2510 | (shsurf->next_state.fullscreen != shsurf->state.fullscreen)) |
| 2511 | shsurf->state_changed = true; |
| 2512 | } |
| 2513 | |
| 2514 | static void |
Philip Withnall | becb77e | 2013-11-25 18:01:30 +0000 | [diff] [blame] | 2515 | set_toplevel(struct shell_surface *shsurf) |
| 2516 | { |
Kristian Høgsberg | 41fbf6f | 2013-12-05 22:31:25 -0800 | [diff] [blame] | 2517 | shell_surface_set_parent(shsurf, NULL); |
| 2518 | surface_clear_next_states(shsurf); |
Pekka Paalanen | b502654 | 2014-11-12 15:09:24 +0200 | [diff] [blame] | 2519 | set_type(shsurf, SHELL_SURFACE_TOPLEVEL); |
Philip Withnall | 648a4dd | 2013-11-25 18:01:44 +0000 | [diff] [blame] | 2520 | |
| 2521 | /* The layer_link is updated in set_surface_type(), |
| 2522 | * called from configure. */ |
Philip Withnall | becb77e | 2013-11-25 18:01:30 +0000 | [diff] [blame] | 2523 | } |
| 2524 | |
| 2525 | static void |
| 2526 | shell_surface_set_toplevel(struct wl_client *client, |
| 2527 | struct wl_resource *resource) |
| 2528 | { |
| 2529 | struct shell_surface *surface = wl_resource_get_user_data(resource); |
| 2530 | |
| 2531 | set_toplevel(surface); |
| 2532 | } |
| 2533 | |
| 2534 | static void |
| 2535 | set_transient(struct shell_surface *shsurf, |
| 2536 | struct weston_surface *parent, int x, int y, uint32_t flags) |
| 2537 | { |
Philip Withnall | dc4332f | 2013-11-25 18:01:38 +0000 | [diff] [blame] | 2538 | assert(parent != NULL); |
| 2539 | |
Kristian Høgsberg | 9f7e331 | 2014-01-02 22:40:37 -0800 | [diff] [blame] | 2540 | shell_surface_set_parent(shsurf, parent); |
| 2541 | |
| 2542 | surface_clear_next_states(shsurf); |
| 2543 | |
Philip Withnall | becb77e | 2013-11-25 18:01:30 +0000 | [diff] [blame] | 2544 | shsurf->transient.x = x; |
| 2545 | shsurf->transient.y = y; |
| 2546 | shsurf->transient.flags = flags; |
Philip Withnall | dc4332f | 2013-11-25 18:01:38 +0000 | [diff] [blame] | 2547 | |
Rafael Antognolli | ed207b4 | 2013-12-03 15:35:43 -0200 | [diff] [blame] | 2548 | shsurf->next_state.relative = true; |
Kristian Høgsberg | a1df7ac | 2013-12-31 15:01:01 -0800 | [diff] [blame] | 2549 | shsurf->state_changed = true; |
Pekka Paalanen | b502654 | 2014-11-12 15:09:24 +0200 | [diff] [blame] | 2550 | set_type(shsurf, SHELL_SURFACE_TOPLEVEL); |
Philip Withnall | 648a4dd | 2013-11-25 18:01:44 +0000 | [diff] [blame] | 2551 | |
| 2552 | /* The layer_link is updated in set_surface_type(), |
| 2553 | * called from configure. */ |
Philip Withnall | becb77e | 2013-11-25 18:01:30 +0000 | [diff] [blame] | 2554 | } |
| 2555 | |
| 2556 | static void |
| 2557 | shell_surface_set_transient(struct wl_client *client, |
| 2558 | struct wl_resource *resource, |
| 2559 | struct wl_resource *parent_resource, |
| 2560 | int x, int y, uint32_t flags) |
| 2561 | { |
| 2562 | struct shell_surface *shsurf = wl_resource_get_user_data(resource); |
| 2563 | struct weston_surface *parent = |
| 2564 | wl_resource_get_user_data(parent_resource); |
| 2565 | |
| 2566 | set_transient(shsurf, parent, x, y, flags); |
| 2567 | } |
| 2568 | |
| 2569 | static void |
| 2570 | set_fullscreen(struct shell_surface *shsurf, |
| 2571 | uint32_t method, |
| 2572 | uint32_t framerate, |
| 2573 | struct weston_output *output) |
| 2574 | { |
Philip Withnall | 352e7ed | 2013-11-25 18:01:35 +0000 | [diff] [blame] | 2575 | shell_surface_set_output(shsurf, output); |
Pekka Paalanen | b502654 | 2014-11-12 15:09:24 +0200 | [diff] [blame] | 2576 | set_type(shsurf, SHELL_SURFACE_TOPLEVEL); |
Philip Withnall | becb77e | 2013-11-25 18:01:30 +0000 | [diff] [blame] | 2577 | |
| 2578 | shsurf->fullscreen_output = shsurf->output; |
| 2579 | shsurf->fullscreen.type = method; |
| 2580 | shsurf->fullscreen.framerate = framerate; |
Philip Withnall | dc4332f | 2013-11-25 18:01:38 +0000 | [diff] [blame] | 2581 | |
Jasper St. Pierre | 6458ec3 | 2014-04-11 16:00:31 -0700 | [diff] [blame] | 2582 | send_configure_for_surface(shsurf); |
Philip Withnall | becb77e | 2013-11-25 18:01:30 +0000 | [diff] [blame] | 2583 | } |
| 2584 | |
| 2585 | static void |
Zhang, Xiong Y | 3123693 | 2013-12-13 22:10:57 +0200 | [diff] [blame] | 2586 | weston_view_set_initial_position(struct weston_view *view, |
| 2587 | struct desktop_shell *shell); |
| 2588 | |
| 2589 | static void |
Philip Withnall | becb77e | 2013-11-25 18:01:30 +0000 | [diff] [blame] | 2590 | unset_fullscreen(struct shell_surface *shsurf) |
Alex Wu | 4539b08 | 2012-03-01 12:57:46 +0800 | [diff] [blame] | 2591 | { |
Philip Withnall | f85fe84 | 2013-11-25 18:01:37 +0000 | [diff] [blame] | 2592 | /* Unset the fullscreen output, driver configuration and transforms. */ |
Alex Wu | bd3354b | 2012-04-17 17:20:49 +0800 | [diff] [blame] | 2593 | if (shsurf->fullscreen.type == WL_SHELL_SURFACE_FULLSCREEN_METHOD_DRIVER && |
| 2594 | shell_surface_is_top_fullscreen(shsurf)) { |
Alexander Larsson | f82b6ca | 2013-05-28 16:23:39 +0200 | [diff] [blame] | 2595 | restore_output_mode(shsurf->fullscreen_output); |
Alex Wu | bd3354b | 2012-04-17 17:20:49 +0800 | [diff] [blame] | 2596 | } |
Philip Withnall | f85fe84 | 2013-11-25 18:01:37 +0000 | [diff] [blame] | 2597 | |
Alex Wu | 4539b08 | 2012-03-01 12:57:46 +0800 | [diff] [blame] | 2598 | shsurf->fullscreen.type = WL_SHELL_SURFACE_FULLSCREEN_METHOD_DEFAULT; |
| 2599 | shsurf->fullscreen.framerate = 0; |
Philip Withnall | f85fe84 | 2013-11-25 18:01:37 +0000 | [diff] [blame] | 2600 | |
Alex Wu | 4539b08 | 2012-03-01 12:57:46 +0800 | [diff] [blame] | 2601 | wl_list_remove(&shsurf->fullscreen.transform.link); |
| 2602 | wl_list_init(&shsurf->fullscreen.transform.link); |
Philip Withnall | f85fe84 | 2013-11-25 18:01:37 +0000 | [diff] [blame] | 2603 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 2604 | if (shsurf->fullscreen.black_view) |
| 2605 | weston_surface_destroy(shsurf->fullscreen.black_view->surface); |
| 2606 | shsurf->fullscreen.black_view = NULL; |
Philip Withnall | f85fe84 | 2013-11-25 18:01:37 +0000 | [diff] [blame] | 2607 | |
Zhang, Xiong Y | 3123693 | 2013-12-13 22:10:57 +0200 | [diff] [blame] | 2608 | if (shsurf->saved_position_valid) |
| 2609 | weston_view_set_position(shsurf->view, |
| 2610 | shsurf->saved_x, shsurf->saved_y); |
| 2611 | else |
| 2612 | weston_view_set_initial_position(shsurf->view, shsurf->shell); |
| 2613 | |
Alex Wu | 7bcb8bd | 2012-04-27 09:07:24 +0800 | [diff] [blame] | 2614 | if (shsurf->saved_rotation_valid) { |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 2615 | wl_list_insert(&shsurf->view->geometry.transformation_list, |
Philip Withnall | becb77e | 2013-11-25 18:01:30 +0000 | [diff] [blame] | 2616 | &shsurf->rotation.transform.link); |
Alex Wu | 7bcb8bd | 2012-04-27 09:07:24 +0800 | [diff] [blame] | 2617 | shsurf->saved_rotation_valid = false; |
| 2618 | } |
Rafal Mielniczuk | 3e3862c | 2012-10-07 20:25:36 +0200 | [diff] [blame] | 2619 | |
Philip Withnall | e1d75ae | 2013-11-25 18:01:41 +0000 | [diff] [blame] | 2620 | /* Layer is updated in set_surface_type(). */ |
Alex Wu | 4539b08 | 2012-03-01 12:57:46 +0800 | [diff] [blame] | 2621 | } |
| 2622 | |
Rafal Mielniczuk | fffdcdd | 2013-03-11 19:26:54 +0100 | [diff] [blame] | 2623 | static void |
Philip Withnall | becb77e | 2013-11-25 18:01:30 +0000 | [diff] [blame] | 2624 | shell_surface_set_fullscreen(struct wl_client *client, |
| 2625 | struct wl_resource *resource, |
| 2626 | uint32_t method, |
| 2627 | uint32_t framerate, |
| 2628 | struct wl_resource *output_resource) |
| 2629 | { |
| 2630 | struct shell_surface *shsurf = wl_resource_get_user_data(resource); |
| 2631 | struct weston_output *output; |
| 2632 | |
| 2633 | if (output_resource) |
| 2634 | output = wl_resource_get_user_data(output_resource); |
| 2635 | else |
| 2636 | output = NULL; |
| 2637 | |
Rafael Antognolli | 4b99a40 | 2013-12-03 15:35:44 -0200 | [diff] [blame] | 2638 | shell_surface_set_parent(shsurf, NULL); |
| 2639 | |
Rafael Antognolli | 03b1659 | 2013-12-03 15:35:42 -0200 | [diff] [blame] | 2640 | surface_clear_next_states(shsurf); |
Jasper St. Pierre | 8c6aa45 | 2014-02-08 18:29:49 -0500 | [diff] [blame] | 2641 | shsurf->next_state.fullscreen = true; |
| 2642 | shsurf->state_changed = true; |
Jasper St. Pierre | 6458ec3 | 2014-04-11 16:00:31 -0700 | [diff] [blame] | 2643 | set_fullscreen(shsurf, method, framerate, output); |
Philip Withnall | becb77e | 2013-11-25 18:01:30 +0000 | [diff] [blame] | 2644 | } |
| 2645 | |
| 2646 | static void |
| 2647 | set_popup(struct shell_surface *shsurf, |
| 2648 | struct weston_surface *parent, |
| 2649 | struct weston_seat *seat, |
| 2650 | uint32_t serial, |
| 2651 | int32_t x, |
| 2652 | int32_t y) |
| 2653 | { |
Philip Withnall | dc4332f | 2013-11-25 18:01:38 +0000 | [diff] [blame] | 2654 | assert(parent != NULL); |
| 2655 | |
Philip Withnall | becb77e | 2013-11-25 18:01:30 +0000 | [diff] [blame] | 2656 | shsurf->popup.shseat = get_shell_seat(seat); |
| 2657 | shsurf->popup.serial = serial; |
| 2658 | shsurf->popup.x = x; |
| 2659 | shsurf->popup.y = y; |
Philip Withnall | dc4332f | 2013-11-25 18:01:38 +0000 | [diff] [blame] | 2660 | |
Pekka Paalanen | b502654 | 2014-11-12 15:09:24 +0200 | [diff] [blame] | 2661 | set_type(shsurf, SHELL_SURFACE_POPUP); |
Philip Withnall | becb77e | 2013-11-25 18:01:30 +0000 | [diff] [blame] | 2662 | } |
| 2663 | |
| 2664 | static void |
| 2665 | shell_surface_set_popup(struct wl_client *client, |
| 2666 | struct wl_resource *resource, |
| 2667 | struct wl_resource *seat_resource, |
| 2668 | uint32_t serial, |
| 2669 | struct wl_resource *parent_resource, |
| 2670 | int32_t x, int32_t y, uint32_t flags) |
| 2671 | { |
| 2672 | struct shell_surface *shsurf = wl_resource_get_user_data(resource); |
Rafael Antognolli | 4b99a40 | 2013-12-03 15:35:44 -0200 | [diff] [blame] | 2673 | struct weston_surface *parent = |
| 2674 | wl_resource_get_user_data(parent_resource); |
| 2675 | |
| 2676 | shell_surface_set_parent(shsurf, parent); |
Philip Withnall | becb77e | 2013-11-25 18:01:30 +0000 | [diff] [blame] | 2677 | |
Rafael Antognolli | 03b1659 | 2013-12-03 15:35:42 -0200 | [diff] [blame] | 2678 | surface_clear_next_states(shsurf); |
Philip Withnall | becb77e | 2013-11-25 18:01:30 +0000 | [diff] [blame] | 2679 | set_popup(shsurf, |
Rafael Antognolli | 4b99a40 | 2013-12-03 15:35:44 -0200 | [diff] [blame] | 2680 | parent, |
Philip Withnall | becb77e | 2013-11-25 18:01:30 +0000 | [diff] [blame] | 2681 | wl_resource_get_user_data(seat_resource), |
| 2682 | serial, x, y); |
| 2683 | } |
| 2684 | |
| 2685 | static void |
Philip Withnall | becb77e | 2013-11-25 18:01:30 +0000 | [diff] [blame] | 2686 | unset_maximized(struct shell_surface *shsurf) |
Rafal Mielniczuk | fffdcdd | 2013-03-11 19:26:54 +0100 | [diff] [blame] | 2687 | { |
Rafal Mielniczuk | fffdcdd | 2013-03-11 19:26:54 +0100 | [diff] [blame] | 2688 | /* undo all maximized things here */ |
| 2689 | shsurf->output = get_default_output(shsurf->surface->compositor); |
Zhang, Xiong Y | 3123693 | 2013-12-13 22:10:57 +0200 | [diff] [blame] | 2690 | |
| 2691 | if (shsurf->saved_position_valid) |
| 2692 | weston_view_set_position(shsurf->view, |
| 2693 | shsurf->saved_x, shsurf->saved_y); |
| 2694 | else |
| 2695 | weston_view_set_initial_position(shsurf->view, shsurf->shell); |
Rafal Mielniczuk | fffdcdd | 2013-03-11 19:26:54 +0100 | [diff] [blame] | 2696 | |
| 2697 | if (shsurf->saved_rotation_valid) { |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 2698 | wl_list_insert(&shsurf->view->geometry.transformation_list, |
| 2699 | &shsurf->rotation.transform.link); |
Rafal Mielniczuk | fffdcdd | 2013-03-11 19:26:54 +0100 | [diff] [blame] | 2700 | shsurf->saved_rotation_valid = false; |
| 2701 | } |
| 2702 | |
Philip Withnall | e1d75ae | 2013-11-25 18:01:41 +0000 | [diff] [blame] | 2703 | /* Layer is updated in set_surface_type(). */ |
Rafal Mielniczuk | fffdcdd | 2013-03-11 19:26:54 +0100 | [diff] [blame] | 2704 | } |
| 2705 | |
Philip Withnall | becb77e | 2013-11-25 18:01:30 +0000 | [diff] [blame] | 2706 | static void |
Manuel Bachmann | dc1c3e4 | 2015-02-16 11:52:13 +0100 | [diff] [blame] | 2707 | set_minimized(struct weston_surface *surface) |
Manuel Bachmann | 50c87db | 2014-02-26 15:52:13 +0100 | [diff] [blame] | 2708 | { |
| 2709 | struct shell_surface *shsurf; |
| 2710 | struct workspace *current_ws; |
| 2711 | struct weston_seat *seat; |
| 2712 | struct weston_surface *focus; |
| 2713 | struct weston_view *view; |
| 2714 | |
| 2715 | view = get_default_view(surface); |
| 2716 | if (!view) |
| 2717 | return; |
| 2718 | |
| 2719 | assert(weston_surface_get_main_surface(view->surface) == view->surface); |
| 2720 | |
| 2721 | shsurf = get_shell_surface(surface); |
| 2722 | current_ws = get_current_workspace(shsurf->shell); |
| 2723 | |
Giulio Camuffo | 412e6a5 | 2014-07-09 22:12:56 +0300 | [diff] [blame] | 2724 | weston_layer_entry_remove(&view->layer_link); |
Manuel Bachmann | dc1c3e4 | 2015-02-16 11:52:13 +0100 | [diff] [blame] | 2725 | 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] | 2726 | |
Manuel Bachmann | dc1c3e4 | 2015-02-16 11:52:13 +0100 | [diff] [blame] | 2727 | drop_focus_state(shsurf->shell, current_ws, view->surface); |
| 2728 | wl_list_for_each(seat, &shsurf->shell->compositor->seat_list, link) { |
Derek Foreman | 1281a36 | 2015-07-31 16:55:32 -0500 | [diff] [blame] | 2729 | struct weston_keyboard *keyboard = |
| 2730 | weston_seat_get_keyboard(seat); |
| 2731 | |
| 2732 | if (!keyboard) |
Manuel Bachmann | dc1c3e4 | 2015-02-16 11:52:13 +0100 | [diff] [blame] | 2733 | continue; |
Derek Foreman | 1281a36 | 2015-07-31 16:55:32 -0500 | [diff] [blame] | 2734 | focus = weston_surface_get_main_surface(keyboard->focus); |
Manuel Bachmann | dc1c3e4 | 2015-02-16 11:52:13 +0100 | [diff] [blame] | 2735 | if (focus == view->surface) |
Derek Foreman | 1281a36 | 2015-07-31 16:55:32 -0500 | [diff] [blame] | 2736 | weston_keyboard_set_focus(keyboard, NULL); |
Manuel Bachmann | 50c87db | 2014-02-26 15:52:13 +0100 | [diff] [blame] | 2737 | } |
| 2738 | |
| 2739 | shell_surface_update_child_surface_layers(shsurf); |
Manuel Bachmann | 50c87db | 2014-02-26 15:52:13 +0100 | [diff] [blame] | 2740 | weston_view_damage_below(view); |
| 2741 | } |
| 2742 | |
| 2743 | static void |
Philip Withnall | becb77e | 2013-11-25 18:01:30 +0000 | [diff] [blame] | 2744 | shell_surface_set_maximized(struct wl_client *client, |
| 2745 | struct wl_resource *resource, |
| 2746 | struct wl_resource *output_resource) |
| 2747 | { |
| 2748 | struct shell_surface *shsurf = wl_resource_get_user_data(resource); |
| 2749 | struct weston_output *output; |
| 2750 | |
Jasper St. Pierre | 9aa8ce6 | 2014-04-11 16:18:54 -0700 | [diff] [blame] | 2751 | surface_clear_next_states(shsurf); |
| 2752 | shsurf->next_state.maximized = true; |
| 2753 | shsurf->state_changed = true; |
| 2754 | |
Pekka Paalanen | b502654 | 2014-11-12 15:09:24 +0200 | [diff] [blame] | 2755 | set_type(shsurf, SHELL_SURFACE_TOPLEVEL); |
Jasper St. Pierre | 9aa8ce6 | 2014-04-11 16:18:54 -0700 | [diff] [blame] | 2756 | shell_surface_set_parent(shsurf, NULL); |
| 2757 | |
Philip Withnall | becb77e | 2013-11-25 18:01:30 +0000 | [diff] [blame] | 2758 | if (output_resource) |
| 2759 | output = wl_resource_get_user_data(output_resource); |
| 2760 | else |
| 2761 | output = NULL; |
| 2762 | |
Jasper St. Pierre | 9aa8ce6 | 2014-04-11 16:18:54 -0700 | [diff] [blame] | 2763 | shell_surface_set_output(shsurf, output); |
Rafael Antognolli | 4b99a40 | 2013-12-03 15:35:44 -0200 | [diff] [blame] | 2764 | |
Jasper St. Pierre | 9aa8ce6 | 2014-04-11 16:18:54 -0700 | [diff] [blame] | 2765 | send_configure_for_surface(shsurf); |
Philip Withnall | becb77e | 2013-11-25 18:01:30 +0000 | [diff] [blame] | 2766 | } |
| 2767 | |
Philip Withnall | e1d75ae | 2013-11-25 18:01:41 +0000 | [diff] [blame] | 2768 | /* This is only ever called from set_surface_type(), so there’s no need to |
| 2769 | * update layer_links here, since they’ll be updated when we return. */ |
Pekka Paalanen | 9826223 | 2011-12-01 10:42:22 +0200 | [diff] [blame] | 2770 | static int |
Philip Withnall | becb77e | 2013-11-25 18:01:30 +0000 | [diff] [blame] | 2771 | reset_surface_type(struct shell_surface *surface) |
Pekka Paalanen | 9826223 | 2011-12-01 10:42:22 +0200 | [diff] [blame] | 2772 | { |
Rafael Antognolli | 03b1659 | 2013-12-03 15:35:42 -0200 | [diff] [blame] | 2773 | if (surface->state.fullscreen) |
Philip Withnall | becb77e | 2013-11-25 18:01:30 +0000 | [diff] [blame] | 2774 | unset_fullscreen(surface); |
Rafael Antognolli | 03b1659 | 2013-12-03 15:35:42 -0200 | [diff] [blame] | 2775 | if (surface->state.maximized) |
Philip Withnall | becb77e | 2013-11-25 18:01:30 +0000 | [diff] [blame] | 2776 | unset_maximized(surface); |
Pekka Paalanen | 9826223 | 2011-12-01 10:42:22 +0200 | [diff] [blame] | 2777 | |
Pekka Paalanen | 9826223 | 2011-12-01 10:42:22 +0200 | [diff] [blame] | 2778 | return 0; |
| 2779 | } |
| 2780 | |
Kristian Høgsberg | 4cca349 | 2011-01-18 07:53:49 -0500 | [diff] [blame] | 2781 | static void |
Rafael Antognolli | 03b1659 | 2013-12-03 15:35:42 -0200 | [diff] [blame] | 2782 | set_full_output(struct shell_surface *shsurf) |
| 2783 | { |
| 2784 | shsurf->saved_x = shsurf->view->geometry.x; |
| 2785 | shsurf->saved_y = shsurf->view->geometry.y; |
Rafael Antognolli | 3c4e3f7 | 2013-12-03 15:35:46 -0200 | [diff] [blame] | 2786 | shsurf->saved_width = shsurf->surface->width; |
| 2787 | shsurf->saved_height = shsurf->surface->height; |
| 2788 | shsurf->saved_size_valid = true; |
Rafael Antognolli | 03b1659 | 2013-12-03 15:35:42 -0200 | [diff] [blame] | 2789 | shsurf->saved_position_valid = true; |
| 2790 | |
| 2791 | if (!wl_list_empty(&shsurf->rotation.transform.link)) { |
| 2792 | wl_list_remove(&shsurf->rotation.transform.link); |
| 2793 | wl_list_init(&shsurf->rotation.transform.link); |
| 2794 | weston_view_geometry_dirty(shsurf->view); |
| 2795 | shsurf->saved_rotation_valid = true; |
| 2796 | } |
| 2797 | } |
| 2798 | |
| 2799 | static void |
Kristian Høgsberg | 7f366e7 | 2012-04-27 17:20:01 -0400 | [diff] [blame] | 2800 | set_surface_type(struct shell_surface *shsurf) |
| 2801 | { |
Kristian Høgsberg | 8150b19 | 2012-06-27 10:22:58 -0400 | [diff] [blame] | 2802 | struct weston_surface *pes = shsurf->parent; |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 2803 | struct weston_view *pev = get_default_view(pes); |
Kristian Høgsberg | 7f366e7 | 2012-04-27 17:20:01 -0400 | [diff] [blame] | 2804 | |
Philip Withnall | becb77e | 2013-11-25 18:01:30 +0000 | [diff] [blame] | 2805 | reset_surface_type(shsurf); |
Kristian Høgsberg | 7f366e7 | 2012-04-27 17:20:01 -0400 | [diff] [blame] | 2806 | |
Rafael Antognolli | 03b1659 | 2013-12-03 15:35:42 -0200 | [diff] [blame] | 2807 | shsurf->state = shsurf->next_state; |
Rafael Antognolli | 03b1659 | 2013-12-03 15:35:42 -0200 | [diff] [blame] | 2808 | shsurf->state_changed = false; |
Kristian Høgsberg | 7f366e7 | 2012-04-27 17:20:01 -0400 | [diff] [blame] | 2809 | |
| 2810 | switch (shsurf->type) { |
| 2811 | case SHELL_SURFACE_TOPLEVEL: |
Rafael Antognolli | ed207b4 | 2013-12-03 15:35:43 -0200 | [diff] [blame] | 2812 | if (shsurf->state.maximized || shsurf->state.fullscreen) { |
Rafael Antognolli | 03b1659 | 2013-12-03 15:35:42 -0200 | [diff] [blame] | 2813 | set_full_output(shsurf); |
Rafael Antognolli | ed207b4 | 2013-12-03 15:35:43 -0200 | [diff] [blame] | 2814 | } else if (shsurf->state.relative && pev) { |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 2815 | weston_view_set_position(shsurf->view, |
| 2816 | pev->geometry.x + shsurf->transient.x, |
| 2817 | pev->geometry.y + shsurf->transient.y); |
Rafael Antognolli | ed207b4 | 2013-12-03 15:35:43 -0200 | [diff] [blame] | 2818 | } |
Rafael Antognolli | 44a3162 | 2013-12-04 18:37:16 -0200 | [diff] [blame] | 2819 | break; |
Kristian Høgsberg | 7f366e7 | 2012-04-27 17:20:01 -0400 | [diff] [blame] | 2820 | |
Tiago Vignatti | fb2adba | 2013-06-12 15:43:21 -0300 | [diff] [blame] | 2821 | case SHELL_SURFACE_XWAYLAND: |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 2822 | weston_view_set_position(shsurf->view, shsurf->transient.x, |
| 2823 | shsurf->transient.y); |
Tiago Vignatti | fb2adba | 2013-06-12 15:43:21 -0300 | [diff] [blame] | 2824 | break; |
| 2825 | |
Philip Withnall | 0f640e2 | 2013-11-25 18:01:31 +0000 | [diff] [blame] | 2826 | case SHELL_SURFACE_POPUP: |
| 2827 | case SHELL_SURFACE_NONE: |
Kristian Høgsberg | 7f366e7 | 2012-04-27 17:20:01 -0400 | [diff] [blame] | 2828 | default: |
| 2829 | break; |
| 2830 | } |
Philip Withnall | e1d75ae | 2013-11-25 18:01:41 +0000 | [diff] [blame] | 2831 | |
| 2832 | /* Update the surface’s layer. */ |
| 2833 | shell_surface_update_layer(shsurf); |
Kristian Høgsberg | 7f366e7 | 2012-04-27 17:20:01 -0400 | [diff] [blame] | 2834 | } |
| 2835 | |
Tiago Vignatti | be14326 | 2012-04-16 17:31:41 +0300 | [diff] [blame] | 2836 | static struct desktop_shell * |
Juan Zhao | 96879df | 2012-02-07 08:45:41 +0800 | [diff] [blame] | 2837 | shell_surface_get_shell(struct shell_surface *shsurf) |
Pekka Paalanen | af0e34c | 2011-12-02 10:59:17 +0200 | [diff] [blame] | 2838 | { |
Kristian Høgsberg | 02e79dc | 2012-04-12 09:55:26 -0400 | [diff] [blame] | 2839 | return shsurf->shell; |
Juan Zhao | 96879df | 2012-02-07 08:45:41 +0800 | [diff] [blame] | 2840 | } |
| 2841 | |
Pekka Paalanen | 8274d90 | 2014-08-06 19:36:51 +0300 | [diff] [blame] | 2842 | static int |
| 2843 | black_surface_get_label(struct weston_surface *surface, char *buf, size_t len) |
| 2844 | { |
| 2845 | struct weston_surface *fs_surface = surface->configure_private; |
| 2846 | int n; |
| 2847 | int rem; |
| 2848 | int ret; |
| 2849 | |
| 2850 | n = snprintf(buf, len, "black background surface for "); |
| 2851 | if (n < 0) |
| 2852 | return n; |
| 2853 | |
| 2854 | rem = (int)len - n; |
| 2855 | if (rem < 0) |
| 2856 | rem = 0; |
| 2857 | |
| 2858 | if (fs_surface->get_label) |
| 2859 | ret = fs_surface->get_label(fs_surface, buf + n, rem); |
| 2860 | else |
| 2861 | ret = snprintf(buf + n, rem, "<unknown>"); |
| 2862 | |
| 2863 | if (ret < 0) |
| 2864 | return n; |
| 2865 | |
| 2866 | return n + ret; |
| 2867 | } |
| 2868 | |
Alex Wu | 2185843 | 2012-04-01 20:13:08 +0800 | [diff] [blame] | 2869 | static void |
Jason Ekstrand | 918f2dd | 2013-12-02 21:01:53 -0600 | [diff] [blame] | 2870 | 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] | 2871 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 2872 | static struct weston_view * |
Alex Wu | 4539b08 | 2012-03-01 12:57:46 +0800 | [diff] [blame] | 2873 | create_black_surface(struct weston_compositor *ec, |
Alex Wu | 2185843 | 2012-04-01 20:13:08 +0800 | [diff] [blame] | 2874 | struct weston_surface *fs_surface, |
John Kåre Alsaker | 490d02a | 2012-09-30 02:57:21 +0200 | [diff] [blame] | 2875 | float x, float y, int w, int h) |
Alex Wu | 4539b08 | 2012-03-01 12:57:46 +0800 | [diff] [blame] | 2876 | { |
| 2877 | struct weston_surface *surface = NULL; |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 2878 | struct weston_view *view; |
Alex Wu | 4539b08 | 2012-03-01 12:57:46 +0800 | [diff] [blame] | 2879 | |
| 2880 | surface = weston_surface_create(ec); |
| 2881 | if (surface == NULL) { |
Martin Minarik | 6d11836 | 2012-06-07 18:01:59 +0200 | [diff] [blame] | 2882 | weston_log("no memory\n"); |
Alex Wu | 4539b08 | 2012-03-01 12:57:46 +0800 | [diff] [blame] | 2883 | return NULL; |
| 2884 | } |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 2885 | view = weston_view_create(surface); |
| 2886 | if (surface == NULL) { |
| 2887 | weston_log("no memory\n"); |
| 2888 | weston_surface_destroy(surface); |
| 2889 | return NULL; |
| 2890 | } |
Alex Wu | 4539b08 | 2012-03-01 12:57:46 +0800 | [diff] [blame] | 2891 | |
Alex Wu | 2185843 | 2012-04-01 20:13:08 +0800 | [diff] [blame] | 2892 | surface->configure = black_surface_configure; |
Giulio Camuffo | 7fe01b1 | 2013-03-28 18:02:42 +0100 | [diff] [blame] | 2893 | surface->configure_private = fs_surface; |
Pekka Paalanen | 8274d90 | 2014-08-06 19:36:51 +0300 | [diff] [blame] | 2894 | weston_surface_set_label_func(surface, black_surface_get_label); |
Alex Wu | 4539b08 | 2012-03-01 12:57:46 +0800 | [diff] [blame] | 2895 | weston_surface_set_color(surface, 0.0, 0.0, 0.0, 1); |
Pekka Paalanen | 71f6f3b | 2012-10-10 12:49:26 +0300 | [diff] [blame] | 2896 | pixman_region32_fini(&surface->opaque); |
Kristian Høgsberg | 61f00f5 | 2012-08-03 16:31:36 -0400 | [diff] [blame] | 2897 | pixman_region32_init_rect(&surface->opaque, 0, 0, w, h); |
Jonas Ådahl | 33619a4 | 2013-01-15 21:25:55 +0100 | [diff] [blame] | 2898 | pixman_region32_fini(&surface->input); |
| 2899 | pixman_region32_init_rect(&surface->input, 0, 0, w, h); |
Jason Ekstrand | 918f2dd | 2013-12-02 21:01:53 -0600 | [diff] [blame] | 2900 | |
Jason Ekstrand | 6228ee2 | 2014-01-01 15:58:57 -0600 | [diff] [blame] | 2901 | weston_surface_set_size(surface, w, h); |
Jason Ekstrand | 918f2dd | 2013-12-02 21:01:53 -0600 | [diff] [blame] | 2902 | weston_view_set_position(view, x, y); |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 2903 | |
| 2904 | return view; |
Alex Wu | 4539b08 | 2012-03-01 12:57:46 +0800 | [diff] [blame] | 2905 | } |
| 2906 | |
Philip Withnall | ed8f1a9 | 2013-11-25 18:01:43 +0000 | [diff] [blame] | 2907 | static void |
| 2908 | shell_ensure_fullscreen_black_view(struct shell_surface *shsurf) |
| 2909 | { |
| 2910 | struct weston_output *output = shsurf->fullscreen_output; |
| 2911 | |
Rafael Antognolli | 03b1659 | 2013-12-03 15:35:42 -0200 | [diff] [blame] | 2912 | assert(shsurf->state.fullscreen); |
Philip Withnall | ed8f1a9 | 2013-11-25 18:01:43 +0000 | [diff] [blame] | 2913 | |
| 2914 | if (!shsurf->fullscreen.black_view) |
| 2915 | shsurf->fullscreen.black_view = |
| 2916 | create_black_surface(shsurf->surface->compositor, |
| 2917 | shsurf->surface, |
| 2918 | output->x, output->y, |
| 2919 | output->width, |
| 2920 | output->height); |
| 2921 | |
| 2922 | weston_view_geometry_dirty(shsurf->fullscreen.black_view); |
Giulio Camuffo | 412e6a5 | 2014-07-09 22:12:56 +0300 | [diff] [blame] | 2923 | weston_layer_entry_remove(&shsurf->fullscreen.black_view->layer_link); |
| 2924 | weston_layer_entry_insert(&shsurf->view->layer_link, |
| 2925 | &shsurf->fullscreen.black_view->layer_link); |
Philip Withnall | ed8f1a9 | 2013-11-25 18:01:43 +0000 | [diff] [blame] | 2926 | weston_view_geometry_dirty(shsurf->fullscreen.black_view); |
| 2927 | weston_surface_damage(shsurf->surface); |
Emilio Pozuelo Monfort | 9e7c759 | 2014-01-30 14:01:10 +0100 | [diff] [blame] | 2928 | |
| 2929 | shsurf->state.lowered = false; |
Philip Withnall | ed8f1a9 | 2013-11-25 18:01:43 +0000 | [diff] [blame] | 2930 | } |
| 2931 | |
Alex Wu | 4539b08 | 2012-03-01 12:57:46 +0800 | [diff] [blame] | 2932 | /* Create black surface and append it to the associated fullscreen surface. |
| 2933 | * Handle size dismatch and positioning according to the method. */ |
| 2934 | static void |
| 2935 | shell_configure_fullscreen(struct shell_surface *shsurf) |
| 2936 | { |
| 2937 | struct weston_output *output = shsurf->fullscreen_output; |
| 2938 | struct weston_surface *surface = shsurf->surface; |
| 2939 | struct weston_matrix *matrix; |
Kristian Høgsberg | 240dfeb | 2012-07-12 12:32:31 -0400 | [diff] [blame] | 2940 | float scale, output_aspect, surface_aspect, x, y; |
Giulio Camuffo | b836664 | 2013-04-25 13:57:46 +0300 | [diff] [blame] | 2941 | int32_t surf_x, surf_y, surf_width, surf_height; |
Alex Wu | 4539b08 | 2012-03-01 12:57:46 +0800 | [diff] [blame] | 2942 | |
Alexander Larsson | f82b6ca | 2013-05-28 16:23:39 +0200 | [diff] [blame] | 2943 | if (shsurf->fullscreen.type != WL_SHELL_SURFACE_FULLSCREEN_METHOD_DRIVER) |
| 2944 | restore_output_mode(output); |
| 2945 | |
Emilio Pozuelo Monfort | 9e7c759 | 2014-01-30 14:01:10 +0100 | [diff] [blame] | 2946 | /* Reverse the effect of lower_fullscreen_layer() */ |
Giulio Camuffo | 412e6a5 | 2014-07-09 22:12:56 +0300 | [diff] [blame] | 2947 | weston_layer_entry_remove(&shsurf->view->layer_link); |
| 2948 | 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] | 2949 | |
Philip Withnall | ed8f1a9 | 2013-11-25 18:01:43 +0000 | [diff] [blame] | 2950 | shell_ensure_fullscreen_black_view(shsurf); |
Alex Wu | 4539b08 | 2012-03-01 12:57:46 +0800 | [diff] [blame] | 2951 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 2952 | surface_subsurfaces_boundingbox(shsurf->surface, &surf_x, &surf_y, |
Giulio Camuffo | b836664 | 2013-04-25 13:57:46 +0300 | [diff] [blame] | 2953 | &surf_width, &surf_height); |
| 2954 | |
Alex Wu | 4539b08 | 2012-03-01 12:57:46 +0800 | [diff] [blame] | 2955 | switch (shsurf->fullscreen.type) { |
| 2956 | case WL_SHELL_SURFACE_FULLSCREEN_METHOD_DEFAULT: |
Pekka Paalanen | de685b8 | 2012-12-04 15:58:12 +0200 | [diff] [blame] | 2957 | if (surface->buffer_ref.buffer) |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 2958 | center_on_output(shsurf->view, shsurf->fullscreen_output); |
Alex Wu | 4539b08 | 2012-03-01 12:57:46 +0800 | [diff] [blame] | 2959 | break; |
| 2960 | case WL_SHELL_SURFACE_FULLSCREEN_METHOD_SCALE: |
Rob Bradford | 9f3dd15 | 2013-02-12 11:53:47 +0000 | [diff] [blame] | 2961 | /* 1:1 mapping between surface and output dimensions */ |
Giulio Camuffo | b836664 | 2013-04-25 13:57:46 +0300 | [diff] [blame] | 2962 | if (output->width == surf_width && |
| 2963 | output->height == surf_height) { |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 2964 | weston_view_set_position(shsurf->view, |
| 2965 | output->x - surf_x, |
| 2966 | output->y - surf_y); |
Rob Bradford | 9f3dd15 | 2013-02-12 11:53:47 +0000 | [diff] [blame] | 2967 | break; |
| 2968 | } |
| 2969 | |
Alex Wu | 4539b08 | 2012-03-01 12:57:46 +0800 | [diff] [blame] | 2970 | matrix = &shsurf->fullscreen.transform.matrix; |
| 2971 | weston_matrix_init(matrix); |
Kristian Høgsberg | 240dfeb | 2012-07-12 12:32:31 -0400 | [diff] [blame] | 2972 | |
Scott Moreau | 1bad5db | 2012-08-18 01:04:05 -0600 | [diff] [blame] | 2973 | output_aspect = (float) output->width / |
| 2974 | (float) output->height; |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 2975 | /* XXX: Use surf_width and surf_height here? */ |
| 2976 | surface_aspect = (float) surface->width / |
| 2977 | (float) surface->height; |
Kristian Høgsberg | 240dfeb | 2012-07-12 12:32:31 -0400 | [diff] [blame] | 2978 | if (output_aspect < surface_aspect) |
Scott Moreau | 1bad5db | 2012-08-18 01:04:05 -0600 | [diff] [blame] | 2979 | scale = (float) output->width / |
Giulio Camuffo | b836664 | 2013-04-25 13:57:46 +0300 | [diff] [blame] | 2980 | (float) surf_width; |
Kristian Høgsberg | 240dfeb | 2012-07-12 12:32:31 -0400 | [diff] [blame] | 2981 | else |
Scott Moreau | 1bad5db | 2012-08-18 01:04:05 -0600 | [diff] [blame] | 2982 | scale = (float) output->height / |
Giulio Camuffo | b836664 | 2013-04-25 13:57:46 +0300 | [diff] [blame] | 2983 | (float) surf_height; |
Kristian Høgsberg | 240dfeb | 2012-07-12 12:32:31 -0400 | [diff] [blame] | 2984 | |
Alex Wu | 4539b08 | 2012-03-01 12:57:46 +0800 | [diff] [blame] | 2985 | weston_matrix_scale(matrix, scale, scale, 1); |
| 2986 | wl_list_remove(&shsurf->fullscreen.transform.link); |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 2987 | wl_list_insert(&shsurf->view->geometry.transformation_list, |
Alex Wu | 4539b08 | 2012-03-01 12:57:46 +0800 | [diff] [blame] | 2988 | &shsurf->fullscreen.transform.link); |
Giulio Camuffo | b836664 | 2013-04-25 13:57:46 +0300 | [diff] [blame] | 2989 | x = output->x + (output->width - surf_width * scale) / 2 - surf_x; |
| 2990 | y = output->y + (output->height - surf_height * scale) / 2 - surf_y; |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 2991 | weston_view_set_position(shsurf->view, x, y); |
Kristian Høgsberg | 240dfeb | 2012-07-12 12:32:31 -0400 | [diff] [blame] | 2992 | |
Alex Wu | 4539b08 | 2012-03-01 12:57:46 +0800 | [diff] [blame] | 2993 | break; |
| 2994 | case WL_SHELL_SURFACE_FULLSCREEN_METHOD_DRIVER: |
Alex Wu | bd3354b | 2012-04-17 17:20:49 +0800 | [diff] [blame] | 2995 | if (shell_surface_is_top_fullscreen(shsurf)) { |
Quentin Glidic | c0d79ce | 2013-01-29 14:16:13 +0100 | [diff] [blame] | 2996 | struct weston_mode mode = {0, |
Pekka Paalanen | 952b6c8 | 2014-03-14 14:38:15 +0200 | [diff] [blame] | 2997 | surf_width * surface->buffer_viewport.buffer.scale, |
| 2998 | surf_height * surface->buffer_viewport.buffer.scale, |
Alex Wu | bd3354b | 2012-04-17 17:20:49 +0800 | [diff] [blame] | 2999 | shsurf->fullscreen.framerate}; |
| 3000 | |
Derek Foreman | 6ae7bc9 | 2014-11-04 10:47:33 -0600 | [diff] [blame] | 3001 | if (weston_output_mode_switch_to_temporary(output, &mode, |
| 3002 | surface->buffer_viewport.buffer.scale) == 0) { |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 3003 | weston_view_set_position(shsurf->view, |
| 3004 | output->x - surf_x, |
| 3005 | output->y - surf_y); |
Jason Ekstrand | 918f2dd | 2013-12-02 21:01:53 -0600 | [diff] [blame] | 3006 | shsurf->fullscreen.black_view->surface->width = output->width; |
| 3007 | shsurf->fullscreen.black_view->surface->height = output->height; |
| 3008 | weston_view_set_position(shsurf->fullscreen.black_view, |
| 3009 | output->x - surf_x, |
| 3010 | output->y - surf_y); |
Alex Wu | bd3354b | 2012-04-17 17:20:49 +0800 | [diff] [blame] | 3011 | break; |
Alexander Larsson | d622ed3 | 2013-05-28 16:23:40 +0200 | [diff] [blame] | 3012 | } else { |
Mario Kleiner | 492c12f | 2015-06-21 21:25:12 +0200 | [diff] [blame] | 3013 | weston_log("shell: Can't switch to temporary mode.\n"); |
Alexander Larsson | f82b6ca | 2013-05-28 16:23:39 +0200 | [diff] [blame] | 3014 | restore_output_mode(output); |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 3015 | center_on_output(shsurf->view, output); |
Alexander Larsson | d622ed3 | 2013-05-28 16:23:40 +0200 | [diff] [blame] | 3016 | } |
Alex Wu | bd3354b | 2012-04-17 17:20:49 +0800 | [diff] [blame] | 3017 | } |
Alex Wu | 4539b08 | 2012-03-01 12:57:46 +0800 | [diff] [blame] | 3018 | break; |
| 3019 | case WL_SHELL_SURFACE_FULLSCREEN_METHOD_FILL: |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 3020 | center_on_output(shsurf->view, output); |
Alex Wu | 4539b08 | 2012-03-01 12:57:46 +0800 | [diff] [blame] | 3021 | break; |
| 3022 | default: |
| 3023 | break; |
| 3024 | } |
| 3025 | } |
| 3026 | |
Alex Wu | 4539b08 | 2012-03-01 12:57:46 +0800 | [diff] [blame] | 3027 | static void |
| 3028 | shell_map_fullscreen(struct shell_surface *shsurf) |
| 3029 | { |
Alex Wu | bd3354b | 2012-04-17 17:20:49 +0800 | [diff] [blame] | 3030 | shell_configure_fullscreen(shsurf); |
Alex Wu | 4539b08 | 2012-03-01 12:57:46 +0800 | [diff] [blame] | 3031 | } |
| 3032 | |
Kristian Høgsberg | 7a5c979 | 2011-06-18 06:12:54 -0400 | [diff] [blame] | 3033 | static void |
Tiago Vignatti | fb2adba | 2013-06-12 15:43:21 -0300 | [diff] [blame] | 3034 | set_xwayland(struct shell_surface *shsurf, int x, int y, uint32_t flags) |
| 3035 | { |
| 3036 | /* XXX: using the same fields for transient type */ |
Rafael Antognolli | 03b1659 | 2013-12-03 15:35:42 -0200 | [diff] [blame] | 3037 | surface_clear_next_states(shsurf); |
Tiago Vignatti | fb2adba | 2013-06-12 15:43:21 -0300 | [diff] [blame] | 3038 | shsurf->transient.x = x; |
| 3039 | shsurf->transient.y = y; |
| 3040 | shsurf->transient.flags = flags; |
Philip Withnall | dc4332f | 2013-11-25 18:01:38 +0000 | [diff] [blame] | 3041 | |
| 3042 | shell_surface_set_parent(shsurf, NULL); |
| 3043 | |
Pekka Paalanen | b502654 | 2014-11-12 15:09:24 +0200 | [diff] [blame] | 3044 | set_type(shsurf, SHELL_SURFACE_XWAYLAND); |
Kristian Høgsberg | 8bc525c | 2014-01-01 22:34:49 -0800 | [diff] [blame] | 3045 | shsurf->state_changed = true; |
Tiago Vignatti | fb2adba | 2013-06-12 15:43:21 -0300 | [diff] [blame] | 3046 | } |
| 3047 | |
Kristian Høgsberg | 4779241 | 2014-05-04 13:47:06 -0700 | [diff] [blame] | 3048 | static void |
| 3049 | shell_interface_set_fullscreen(struct shell_surface *shsurf, |
| 3050 | uint32_t method, |
| 3051 | uint32_t framerate, |
| 3052 | struct weston_output *output) |
| 3053 | { |
| 3054 | surface_clear_next_states(shsurf); |
Kristian Høgsberg | 4779241 | 2014-05-04 13:47:06 -0700 | [diff] [blame] | 3055 | shsurf->next_state.fullscreen = true; |
| 3056 | shsurf->state_changed = true; |
Marek Chalupa | e9fe467 | 2014-10-29 13:44:44 +0100 | [diff] [blame] | 3057 | |
| 3058 | set_fullscreen(shsurf, method, framerate, output); |
Kristian Høgsberg | 4779241 | 2014-05-04 13:47:06 -0700 | [diff] [blame] | 3059 | } |
| 3060 | |
Giulio Camuffo | 6b4b241 | 2015-01-29 19:06:49 +0200 | [diff] [blame] | 3061 | static struct weston_output * |
| 3062 | get_focused_output(struct weston_compositor *compositor) |
| 3063 | { |
| 3064 | struct weston_seat *seat; |
| 3065 | struct weston_output *output = NULL; |
| 3066 | |
| 3067 | wl_list_for_each(seat, &compositor->seat_list, link) { |
Derek Foreman | 1281a36 | 2015-07-31 16:55:32 -0500 | [diff] [blame] | 3068 | struct weston_touch *touch = weston_seat_get_touch(seat); |
| 3069 | struct weston_pointer *pointer = weston_seat_get_pointer(seat); |
| 3070 | struct weston_keyboard *keyboard = |
| 3071 | weston_seat_get_keyboard(seat); |
| 3072 | |
Giulio Camuffo | 6b4b241 | 2015-01-29 19:06:49 +0200 | [diff] [blame] | 3073 | /* Priority has touch focus, then pointer and |
| 3074 | * then keyboard focus. We should probably have |
| 3075 | * three for loops and check frist for touch, |
| 3076 | * then for pointer, etc. but unless somebody has some |
| 3077 | * objections, I think this is sufficient. */ |
Derek Foreman | 1281a36 | 2015-07-31 16:55:32 -0500 | [diff] [blame] | 3078 | if (touch && touch->focus) |
| 3079 | output = touch->focus->output; |
| 3080 | else if (pointer && pointer->focus) |
| 3081 | output = pointer->focus->output; |
| 3082 | else if (keyboard && keyboard->focus) |
| 3083 | output = keyboard->focus->output; |
Giulio Camuffo | 6b4b241 | 2015-01-29 19:06:49 +0200 | [diff] [blame] | 3084 | |
| 3085 | if (output) |
| 3086 | break; |
| 3087 | } |
| 3088 | |
| 3089 | return output; |
| 3090 | } |
| 3091 | |
| 3092 | static void |
| 3093 | shell_interface_set_maximized(struct shell_surface *shsurf) |
| 3094 | { |
| 3095 | struct weston_output *output; |
| 3096 | |
| 3097 | surface_clear_next_states(shsurf); |
| 3098 | shsurf->next_state.maximized = true; |
| 3099 | shsurf->state_changed = true; |
| 3100 | shsurf->type = SHELL_SURFACE_TOPLEVEL; |
| 3101 | |
| 3102 | if (!weston_surface_is_mapped(shsurf->surface)) |
| 3103 | output = get_focused_output(shsurf->surface->compositor); |
| 3104 | else |
| 3105 | output = shsurf->surface->output; |
| 3106 | |
| 3107 | shell_surface_set_output(shsurf, output); |
| 3108 | send_configure_for_surface(shsurf); |
| 3109 | } |
| 3110 | |
Kristian Høgsberg | ae356ae | 2014-04-29 16:03:54 -0700 | [diff] [blame] | 3111 | static int |
Derek Foreman | e4d6c83 | 2015-08-05 14:48:11 -0500 | [diff] [blame] | 3112 | shell_interface_move(struct shell_surface *shsurf, struct weston_pointer *pointer) |
Kristian Høgsberg | ae356ae | 2014-04-29 16:03:54 -0700 | [diff] [blame] | 3113 | { |
Derek Foreman | e4d6c83 | 2015-08-05 14:48:11 -0500 | [diff] [blame] | 3114 | return surface_move(shsurf, pointer, true); |
Kristian Høgsberg | ae356ae | 2014-04-29 16:03:54 -0700 | [diff] [blame] | 3115 | } |
| 3116 | |
Derek Foreman | 8fbebbd | 2015-07-15 13:00:40 -0500 | [diff] [blame] | 3117 | static int |
| 3118 | shell_interface_resize(struct shell_surface *shsurf, |
Derek Foreman | e4d6c83 | 2015-08-05 14:48:11 -0500 | [diff] [blame] | 3119 | struct weston_pointer *pointer, |
Derek Foreman | 8fbebbd | 2015-07-15 13:00:40 -0500 | [diff] [blame] | 3120 | uint32_t edges) |
| 3121 | { |
Derek Foreman | e4d6c83 | 2015-08-05 14:48:11 -0500 | [diff] [blame] | 3122 | return surface_resize(shsurf, pointer, edges); |
Derek Foreman | 8fbebbd | 2015-07-15 13:00:40 -0500 | [diff] [blame] | 3123 | } |
| 3124 | |
Kristian Høgsberg | 02bbabb | 2013-05-06 22:15:05 -0400 | [diff] [blame] | 3125 | static const struct weston_pointer_grab_interface popup_grab_interface; |
Giulio Camuffo | 5085a75 | 2013-03-25 21:42:45 +0100 | [diff] [blame] | 3126 | |
| 3127 | static void |
| 3128 | destroy_shell_seat(struct wl_listener *listener, void *data) |
| 3129 | { |
| 3130 | struct shell_seat *shseat = |
| 3131 | container_of(listener, |
| 3132 | struct shell_seat, seat_destroy_listener); |
Jonas Ådahl | c2b1011 | 2015-02-13 14:01:53 +0800 | [diff] [blame] | 3133 | struct shell_surface *shsurf, *next; |
Giulio Camuffo | 5085a75 | 2013-03-25 21:42:45 +0100 | [diff] [blame] | 3134 | |
| 3135 | if (shseat->popup_grab.grab.interface == &popup_grab_interface) { |
Kristian Høgsberg | 02bbabb | 2013-05-06 22:15:05 -0400 | [diff] [blame] | 3136 | weston_pointer_end_grab(shseat->popup_grab.grab.pointer); |
Giulio Camuffo | 5085a75 | 2013-03-25 21:42:45 +0100 | [diff] [blame] | 3137 | shseat->popup_grab.client = NULL; |
| 3138 | |
Jonas Ådahl | c2b1011 | 2015-02-13 14:01:53 +0800 | [diff] [blame] | 3139 | wl_list_for_each_safe(shsurf, next, |
| 3140 | &shseat->popup_grab.surfaces_list, |
| 3141 | popup.grab_link) { |
Giulio Camuffo | 5085a75 | 2013-03-25 21:42:45 +0100 | [diff] [blame] | 3142 | shsurf->popup.shseat = NULL; |
Jonas Ådahl | c2b1011 | 2015-02-13 14:01:53 +0800 | [diff] [blame] | 3143 | wl_list_init(&shsurf->popup.grab_link); |
Giulio Camuffo | 5085a75 | 2013-03-25 21:42:45 +0100 | [diff] [blame] | 3144 | } |
Giulio Camuffo | 5085a75 | 2013-03-25 21:42:45 +0100 | [diff] [blame] | 3145 | } |
| 3146 | |
| 3147 | wl_list_remove(&shseat->seat_destroy_listener.link); |
| 3148 | free(shseat); |
| 3149 | } |
| 3150 | |
Jason Ekstrand | 024177c | 2014-04-21 19:42:58 -0500 | [diff] [blame] | 3151 | static void |
| 3152 | shell_seat_caps_changed(struct wl_listener *listener, void *data) |
| 3153 | { |
Derek Foreman | 1281a36 | 2015-07-31 16:55:32 -0500 | [diff] [blame] | 3154 | struct weston_keyboard *keyboard; |
| 3155 | struct weston_pointer *pointer; |
Jason Ekstrand | 024177c | 2014-04-21 19:42:58 -0500 | [diff] [blame] | 3156 | struct shell_seat *seat; |
| 3157 | |
| 3158 | seat = container_of(listener, struct shell_seat, caps_changed_listener); |
Derek Foreman | 1281a36 | 2015-07-31 16:55:32 -0500 | [diff] [blame] | 3159 | keyboard = weston_seat_get_keyboard(seat->seat); |
| 3160 | pointer = weston_seat_get_pointer(seat->seat); |
Jason Ekstrand | 024177c | 2014-04-21 19:42:58 -0500 | [diff] [blame] | 3161 | |
Derek Foreman | 1281a36 | 2015-07-31 16:55:32 -0500 | [diff] [blame] | 3162 | if (keyboard && |
Jason Ekstrand | 024177c | 2014-04-21 19:42:58 -0500 | [diff] [blame] | 3163 | wl_list_empty(&seat->keyboard_focus_listener.link)) { |
Derek Foreman | 1281a36 | 2015-07-31 16:55:32 -0500 | [diff] [blame] | 3164 | wl_signal_add(&keyboard->focus_signal, |
Jason Ekstrand | 024177c | 2014-04-21 19:42:58 -0500 | [diff] [blame] | 3165 | &seat->keyboard_focus_listener); |
Derek Foreman | 1281a36 | 2015-07-31 16:55:32 -0500 | [diff] [blame] | 3166 | } else if (!keyboard) { |
Derek Foreman | 60d9731 | 2015-07-15 13:00:45 -0500 | [diff] [blame] | 3167 | wl_list_remove(&seat->keyboard_focus_listener.link); |
Jason Ekstrand | 024177c | 2014-04-21 19:42:58 -0500 | [diff] [blame] | 3168 | wl_list_init(&seat->keyboard_focus_listener.link); |
| 3169 | } |
| 3170 | |
Derek Foreman | 1281a36 | 2015-07-31 16:55:32 -0500 | [diff] [blame] | 3171 | if (pointer && |
Jason Ekstrand | 024177c | 2014-04-21 19:42:58 -0500 | [diff] [blame] | 3172 | wl_list_empty(&seat->pointer_focus_listener.link)) { |
Derek Foreman | 1281a36 | 2015-07-31 16:55:32 -0500 | [diff] [blame] | 3173 | wl_signal_add(&pointer->focus_signal, |
Jason Ekstrand | 024177c | 2014-04-21 19:42:58 -0500 | [diff] [blame] | 3174 | &seat->pointer_focus_listener); |
Derek Foreman | 1281a36 | 2015-07-31 16:55:32 -0500 | [diff] [blame] | 3175 | } else if (!pointer) { |
Derek Foreman | 60d9731 | 2015-07-15 13:00:45 -0500 | [diff] [blame] | 3176 | wl_list_remove(&seat->pointer_focus_listener.link); |
Jason Ekstrand | 024177c | 2014-04-21 19:42:58 -0500 | [diff] [blame] | 3177 | wl_list_init(&seat->pointer_focus_listener.link); |
| 3178 | } |
| 3179 | } |
| 3180 | |
Giulio Camuffo | 5085a75 | 2013-03-25 21:42:45 +0100 | [diff] [blame] | 3181 | static struct shell_seat * |
| 3182 | create_shell_seat(struct weston_seat *seat) |
| 3183 | { |
| 3184 | struct shell_seat *shseat; |
| 3185 | |
| 3186 | shseat = calloc(1, sizeof *shseat); |
| 3187 | if (!shseat) { |
| 3188 | weston_log("no memory to allocate shell seat\n"); |
| 3189 | return NULL; |
| 3190 | } |
| 3191 | |
| 3192 | shseat->seat = seat; |
| 3193 | wl_list_init(&shseat->popup_grab.surfaces_list); |
| 3194 | |
| 3195 | shseat->seat_destroy_listener.notify = destroy_shell_seat; |
| 3196 | wl_signal_add(&seat->destroy_signal, |
| 3197 | &shseat->seat_destroy_listener); |
| 3198 | |
Jason Ekstrand | 024177c | 2014-04-21 19:42:58 -0500 | [diff] [blame] | 3199 | shseat->keyboard_focus_listener.notify = handle_keyboard_focus; |
| 3200 | wl_list_init(&shseat->keyboard_focus_listener.link); |
| 3201 | |
| 3202 | shseat->pointer_focus_listener.notify = handle_pointer_focus; |
| 3203 | wl_list_init(&shseat->pointer_focus_listener.link); |
| 3204 | |
| 3205 | shseat->caps_changed_listener.notify = shell_seat_caps_changed; |
| 3206 | wl_signal_add(&seat->updated_caps_signal, |
| 3207 | &shseat->caps_changed_listener); |
| 3208 | shell_seat_caps_changed(&shseat->caps_changed_listener, NULL); |
| 3209 | |
Giulio Camuffo | 5085a75 | 2013-03-25 21:42:45 +0100 | [diff] [blame] | 3210 | return shseat; |
| 3211 | } |
| 3212 | |
| 3213 | static struct shell_seat * |
| 3214 | get_shell_seat(struct weston_seat *seat) |
| 3215 | { |
| 3216 | struct wl_listener *listener; |
| 3217 | |
| 3218 | listener = wl_signal_get(&seat->destroy_signal, destroy_shell_seat); |
Jason Ekstrand | 024177c | 2014-04-21 19:42:58 -0500 | [diff] [blame] | 3219 | assert(listener != NULL); |
Giulio Camuffo | 5085a75 | 2013-03-25 21:42:45 +0100 | [diff] [blame] | 3220 | |
| 3221 | return container_of(listener, |
| 3222 | struct shell_seat, seat_destroy_listener); |
| 3223 | } |
| 3224 | |
Kristian Høgsberg | b810eb5 | 2013-02-12 20:07:05 -0500 | [diff] [blame] | 3225 | static void |
Kristian Høgsberg | 6848c25 | 2013-05-08 22:02:59 -0400 | [diff] [blame] | 3226 | popup_grab_focus(struct weston_pointer_grab *grab) |
Kristian Høgsberg | b3cca0a | 2012-01-04 22:19:14 -0500 | [diff] [blame] | 3227 | { |
Kristian Høgsberg | 02bbabb | 2013-05-06 22:15:05 -0400 | [diff] [blame] | 3228 | struct weston_pointer *pointer = grab->pointer; |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 3229 | struct weston_view *view; |
Giulio Camuffo | 5085a75 | 2013-03-25 21:42:45 +0100 | [diff] [blame] | 3230 | struct shell_seat *shseat = |
| 3231 | container_of(grab, struct shell_seat, popup_grab.grab); |
| 3232 | struct wl_client *client = shseat->popup_grab.client; |
Kristian Høgsberg | 6848c25 | 2013-05-08 22:02:59 -0400 | [diff] [blame] | 3233 | wl_fixed_t sx, sy; |
| 3234 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 3235 | view = weston_compositor_pick_view(pointer->seat->compositor, |
| 3236 | pointer->x, pointer->y, |
| 3237 | &sx, &sy); |
Kristian Høgsberg | b3cca0a | 2012-01-04 22:19:14 -0500 | [diff] [blame] | 3238 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 3239 | if (view && view->surface->resource && |
| 3240 | wl_resource_get_client(view->surface->resource) == client) { |
| 3241 | weston_pointer_set_focus(pointer, view, sx, sy); |
Kristian Høgsberg | b3cca0a | 2012-01-04 22:19:14 -0500 | [diff] [blame] | 3242 | } else { |
Derek Foreman | f9318d1 | 2015-05-11 15:40:11 -0500 | [diff] [blame] | 3243 | weston_pointer_clear_focus(pointer); |
Kristian Høgsberg | b3cca0a | 2012-01-04 22:19:14 -0500 | [diff] [blame] | 3244 | } |
| 3245 | } |
| 3246 | |
| 3247 | static void |
Giulio Camuffo | 1959ab8 | 2013-11-14 23:42:52 +0100 | [diff] [blame] | 3248 | popup_grab_motion(struct weston_pointer_grab *grab, uint32_t time, |
| 3249 | wl_fixed_t x, wl_fixed_t y) |
Kristian Høgsberg | b3cca0a | 2012-01-04 22:19:14 -0500 | [diff] [blame] | 3250 | { |
Kristian Høgsberg | be6403e | 2013-05-08 21:03:21 -0400 | [diff] [blame] | 3251 | struct weston_pointer *pointer = grab->pointer; |
Neil Roberts | 96d790e | 2013-09-19 17:32:00 +0100 | [diff] [blame] | 3252 | struct wl_resource *resource; |
Kristian Høgsberg | be6403e | 2013-05-08 21:03:21 -0400 | [diff] [blame] | 3253 | wl_fixed_t sx, sy; |
Kristian Høgsberg | b3cca0a | 2012-01-04 22:19:14 -0500 | [diff] [blame] | 3254 | |
Jonas Ådahl | 61917c8 | 2014-08-11 22:44:02 +0200 | [diff] [blame] | 3255 | if (pointer->focus) { |
| 3256 | weston_view_from_global_fixed(pointer->focus, x, y, |
| 3257 | &pointer->sx, &pointer->sy); |
| 3258 | } |
| 3259 | |
Giulio Camuffo | 1959ab8 | 2013-11-14 23:42:52 +0100 | [diff] [blame] | 3260 | weston_pointer_move(pointer, x, y); |
| 3261 | |
Neil Roberts | 96d790e | 2013-09-19 17:32:00 +0100 | [diff] [blame] | 3262 | wl_resource_for_each(resource, &pointer->focus_resource_list) { |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 3263 | weston_view_from_global_fixed(pointer->focus, |
| 3264 | pointer->x, pointer->y, |
| 3265 | &sx, &sy); |
Neil Roberts | 96d790e | 2013-09-19 17:32:00 +0100 | [diff] [blame] | 3266 | wl_pointer_send_motion(resource, time, sx, sy); |
Kristian Høgsberg | be6403e | 2013-05-08 21:03:21 -0400 | [diff] [blame] | 3267 | } |
Kristian Høgsberg | b3cca0a | 2012-01-04 22:19:14 -0500 | [diff] [blame] | 3268 | } |
| 3269 | |
| 3270 | static void |
Kristian Høgsberg | 02bbabb | 2013-05-06 22:15:05 -0400 | [diff] [blame] | 3271 | popup_grab_button(struct weston_pointer_grab *grab, |
Daniel Stone | 4dbadb1 | 2012-05-30 16:31:51 +0100 | [diff] [blame] | 3272 | uint32_t time, uint32_t button, uint32_t state_w) |
Kristian Høgsberg | b3cca0a | 2012-01-04 22:19:14 -0500 | [diff] [blame] | 3273 | { |
| 3274 | struct wl_resource *resource; |
Giulio Camuffo | 5085a75 | 2013-03-25 21:42:45 +0100 | [diff] [blame] | 3275 | struct shell_seat *shseat = |
| 3276 | container_of(grab, struct shell_seat, popup_grab.grab); |
Rob Bradford | 880ebc7 | 2013-07-22 17:31:38 +0100 | [diff] [blame] | 3277 | struct wl_display *display = shseat->seat->compositor->wl_display; |
Daniel Stone | 4dbadb1 | 2012-05-30 16:31:51 +0100 | [diff] [blame] | 3278 | enum wl_pointer_button_state state = state_w; |
Kristian Høgsberg | eae5de7 | 2012-04-11 22:42:15 -0400 | [diff] [blame] | 3279 | uint32_t serial; |
Neil Roberts | 96d790e | 2013-09-19 17:32:00 +0100 | [diff] [blame] | 3280 | struct wl_list *resource_list; |
Kristian Høgsberg | b3cca0a | 2012-01-04 22:19:14 -0500 | [diff] [blame] | 3281 | |
Neil Roberts | 96d790e | 2013-09-19 17:32:00 +0100 | [diff] [blame] | 3282 | resource_list = &grab->pointer->focus_resource_list; |
| 3283 | if (!wl_list_empty(resource_list)) { |
Kristian Høgsberg | eae5de7 | 2012-04-11 22:42:15 -0400 | [diff] [blame] | 3284 | serial = wl_display_get_serial(display); |
Neil Roberts | 96d790e | 2013-09-19 17:32:00 +0100 | [diff] [blame] | 3285 | wl_resource_for_each(resource, resource_list) { |
| 3286 | wl_pointer_send_button(resource, serial, |
| 3287 | time, button, state); |
| 3288 | } |
Daniel Stone | 4dbadb1 | 2012-05-30 16:31:51 +0100 | [diff] [blame] | 3289 | } else if (state == WL_POINTER_BUTTON_STATE_RELEASED && |
Giulio Camuffo | 5085a75 | 2013-03-25 21:42:45 +0100 | [diff] [blame] | 3290 | (shseat->popup_grab.initial_up || |
Derek Foreman | f7b2f8b | 2015-07-15 13:00:41 -0500 | [diff] [blame] | 3291 | time - grab->pointer->grab_time > 500)) { |
Kristian Høgsberg | 57e0907 | 2012-10-30 14:07:27 -0400 | [diff] [blame] | 3292 | popup_grab_end(grab->pointer); |
Kristian Høgsberg | b3cca0a | 2012-01-04 22:19:14 -0500 | [diff] [blame] | 3293 | } |
| 3294 | |
Daniel Stone | 4dbadb1 | 2012-05-30 16:31:51 +0100 | [diff] [blame] | 3295 | if (state == WL_POINTER_BUTTON_STATE_RELEASED) |
Giulio Camuffo | 5085a75 | 2013-03-25 21:42:45 +0100 | [diff] [blame] | 3296 | shseat->popup_grab.initial_up = 1; |
Kristian Høgsberg | b3cca0a | 2012-01-04 22:19:14 -0500 | [diff] [blame] | 3297 | } |
| 3298 | |
Jonas Ådahl | 1ea343e | 2013-10-25 23:18:05 +0200 | [diff] [blame] | 3299 | static void |
| 3300 | popup_grab_cancel(struct weston_pointer_grab *grab) |
| 3301 | { |
| 3302 | popup_grab_end(grab->pointer); |
| 3303 | } |
| 3304 | |
Kristian Høgsberg | 02bbabb | 2013-05-06 22:15:05 -0400 | [diff] [blame] | 3305 | static const struct weston_pointer_grab_interface popup_grab_interface = { |
Kristian Høgsberg | b3cca0a | 2012-01-04 22:19:14 -0500 | [diff] [blame] | 3306 | popup_grab_focus, |
| 3307 | popup_grab_motion, |
| 3308 | popup_grab_button, |
Jonas Ådahl | 1ea343e | 2013-10-25 23:18:05 +0200 | [diff] [blame] | 3309 | popup_grab_cancel, |
Kristian Høgsberg | b3cca0a | 2012-01-04 22:19:14 -0500 | [diff] [blame] | 3310 | }; |
| 3311 | |
| 3312 | static void |
Jonny Lamb | 76cf1fe | 2014-08-20 11:27:10 +0200 | [diff] [blame] | 3313 | touch_popup_grab_down(struct weston_touch_grab *grab, uint32_t time, |
Giulio Camuffo | 61ed7b6 | 2015-07-08 11:55:28 +0300 | [diff] [blame] | 3314 | int touch_id, wl_fixed_t x, wl_fixed_t y) |
Jonny Lamb | 76cf1fe | 2014-08-20 11:27:10 +0200 | [diff] [blame] | 3315 | { |
| 3316 | struct wl_resource *resource; |
| 3317 | struct shell_seat *shseat = |
| 3318 | container_of(grab, struct shell_seat, popup_grab.touch_grab); |
| 3319 | struct wl_display *display = shseat->seat->compositor->wl_display; |
| 3320 | uint32_t serial; |
| 3321 | struct wl_list *resource_list; |
Giulio Camuffo | 61ed7b6 | 2015-07-08 11:55:28 +0300 | [diff] [blame] | 3322 | wl_fixed_t sx, sy; |
| 3323 | |
| 3324 | weston_view_from_global_fixed(grab->touch->focus, x, y, &sx, &sy); |
Jonny Lamb | 76cf1fe | 2014-08-20 11:27:10 +0200 | [diff] [blame] | 3325 | |
| 3326 | resource_list = &grab->touch->focus_resource_list; |
| 3327 | if (!wl_list_empty(resource_list)) { |
| 3328 | serial = wl_display_get_serial(display); |
| 3329 | wl_resource_for_each(resource, resource_list) { |
| 3330 | wl_touch_send_down(resource, serial, time, |
| 3331 | grab->touch->focus->surface->resource, |
| 3332 | touch_id, sx, sy); |
| 3333 | } |
| 3334 | } |
| 3335 | } |
| 3336 | |
| 3337 | static void |
| 3338 | touch_popup_grab_up(struct weston_touch_grab *grab, uint32_t time, int touch_id) |
| 3339 | { |
| 3340 | struct wl_resource *resource; |
| 3341 | struct shell_seat *shseat = |
| 3342 | container_of(grab, struct shell_seat, popup_grab.touch_grab); |
| 3343 | struct wl_display *display = shseat->seat->compositor->wl_display; |
| 3344 | uint32_t serial; |
| 3345 | struct wl_list *resource_list; |
| 3346 | |
| 3347 | resource_list = &grab->touch->focus_resource_list; |
| 3348 | if (!wl_list_empty(resource_list)) { |
| 3349 | serial = wl_display_get_serial(display); |
| 3350 | wl_resource_for_each(resource, resource_list) { |
| 3351 | wl_touch_send_up(resource, serial, time, touch_id); |
| 3352 | } |
| 3353 | } |
| 3354 | } |
| 3355 | |
| 3356 | static void |
| 3357 | touch_popup_grab_motion(struct weston_touch_grab *grab, uint32_t time, |
Giulio Camuffo | 61ed7b6 | 2015-07-08 11:55:28 +0300 | [diff] [blame] | 3358 | int touch_id, wl_fixed_t x, wl_fixed_t y) |
Jonny Lamb | 76cf1fe | 2014-08-20 11:27:10 +0200 | [diff] [blame] | 3359 | { |
| 3360 | struct wl_resource *resource; |
| 3361 | struct wl_list *resource_list; |
Giulio Camuffo | 61ed7b6 | 2015-07-08 11:55:28 +0300 | [diff] [blame] | 3362 | wl_fixed_t sx, sy; |
| 3363 | |
| 3364 | weston_view_from_global_fixed(grab->touch->focus, x, y, &sx, &sy); |
Jonny Lamb | 76cf1fe | 2014-08-20 11:27:10 +0200 | [diff] [blame] | 3365 | |
| 3366 | resource_list = &grab->touch->focus_resource_list; |
| 3367 | if (!wl_list_empty(resource_list)) { |
| 3368 | wl_resource_for_each(resource, resource_list) { |
| 3369 | wl_touch_send_motion(resource, time, touch_id, sx, sy); |
| 3370 | } |
| 3371 | } |
| 3372 | } |
| 3373 | |
| 3374 | static void |
| 3375 | touch_popup_grab_frame(struct weston_touch_grab *grab) |
| 3376 | { |
| 3377 | } |
| 3378 | |
| 3379 | static void |
| 3380 | touch_popup_grab_cancel(struct weston_touch_grab *grab) |
| 3381 | { |
| 3382 | touch_popup_grab_end(grab->touch); |
| 3383 | } |
| 3384 | |
| 3385 | static const struct weston_touch_grab_interface touch_popup_grab_interface = { |
| 3386 | touch_popup_grab_down, |
| 3387 | touch_popup_grab_up, |
| 3388 | touch_popup_grab_motion, |
| 3389 | touch_popup_grab_frame, |
| 3390 | touch_popup_grab_cancel, |
| 3391 | }; |
| 3392 | |
| 3393 | static void |
Rafael Antognolli | e2a3455 | 2013-12-03 15:35:45 -0200 | [diff] [blame] | 3394 | shell_surface_send_popup_done(struct shell_surface *shsurf) |
| 3395 | { |
| 3396 | if (shell_surface_is_wl_shell_surface(shsurf)) |
| 3397 | wl_shell_surface_send_popup_done(shsurf->resource); |
| 3398 | else if (shell_surface_is_xdg_popup(shsurf)) |
Jasper St. Pierre | ecf2a0f | 2015-02-13 14:01:56 +0800 | [diff] [blame] | 3399 | xdg_popup_send_popup_done(shsurf->resource); |
Rafael Antognolli | e2a3455 | 2013-12-03 15:35:45 -0200 | [diff] [blame] | 3400 | } |
| 3401 | |
| 3402 | static void |
Kristian Høgsberg | 02bbabb | 2013-05-06 22:15:05 -0400 | [diff] [blame] | 3403 | popup_grab_end(struct weston_pointer *pointer) |
Kristian Høgsberg | 57e0907 | 2012-10-30 14:07:27 -0400 | [diff] [blame] | 3404 | { |
Kristian Høgsberg | 02bbabb | 2013-05-06 22:15:05 -0400 | [diff] [blame] | 3405 | struct weston_pointer_grab *grab = pointer->grab; |
Giulio Camuffo | 5085a75 | 2013-03-25 21:42:45 +0100 | [diff] [blame] | 3406 | struct shell_seat *shseat = |
| 3407 | container_of(grab, struct shell_seat, popup_grab.grab); |
| 3408 | struct shell_surface *shsurf; |
Jonas Ådahl | c2b1011 | 2015-02-13 14:01:53 +0800 | [diff] [blame] | 3409 | struct shell_surface *next; |
Kristian Høgsberg | 57e0907 | 2012-10-30 14:07:27 -0400 | [diff] [blame] | 3410 | |
| 3411 | if (pointer->grab->interface == &popup_grab_interface) { |
Kristian Høgsberg | 02bbabb | 2013-05-06 22:15:05 -0400 | [diff] [blame] | 3412 | weston_pointer_end_grab(grab->pointer); |
Giulio Camuffo | 5085a75 | 2013-03-25 21:42:45 +0100 | [diff] [blame] | 3413 | shseat->popup_grab.client = NULL; |
Philipp Brüschweiler | 63e7be6 | 2013-04-15 21:09:54 +0200 | [diff] [blame] | 3414 | shseat->popup_grab.grab.interface = NULL; |
| 3415 | assert(!wl_list_empty(&shseat->popup_grab.surfaces_list)); |
Giulio Camuffo | 5085a75 | 2013-03-25 21:42:45 +0100 | [diff] [blame] | 3416 | /* Send the popup_done event to all the popups open */ |
Jonas Ådahl | c2b1011 | 2015-02-13 14:01:53 +0800 | [diff] [blame] | 3417 | wl_list_for_each_safe(shsurf, next, |
| 3418 | &shseat->popup_grab.surfaces_list, |
| 3419 | popup.grab_link) { |
Rafael Antognolli | e2a3455 | 2013-12-03 15:35:45 -0200 | [diff] [blame] | 3420 | shell_surface_send_popup_done(shsurf); |
Giulio Camuffo | 5085a75 | 2013-03-25 21:42:45 +0100 | [diff] [blame] | 3421 | shsurf->popup.shseat = NULL; |
Jonas Ådahl | c2b1011 | 2015-02-13 14:01:53 +0800 | [diff] [blame] | 3422 | wl_list_init(&shsurf->popup.grab_link); |
Giulio Camuffo | 5085a75 | 2013-03-25 21:42:45 +0100 | [diff] [blame] | 3423 | } |
Giulio Camuffo | 5085a75 | 2013-03-25 21:42:45 +0100 | [diff] [blame] | 3424 | wl_list_init(&shseat->popup_grab.surfaces_list); |
| 3425 | } |
| 3426 | } |
| 3427 | |
| 3428 | static void |
Jonny Lamb | 76cf1fe | 2014-08-20 11:27:10 +0200 | [diff] [blame] | 3429 | touch_popup_grab_end(struct weston_touch *touch) |
| 3430 | { |
| 3431 | struct weston_touch_grab *grab = touch->grab; |
| 3432 | struct shell_seat *shseat = |
| 3433 | container_of(grab, struct shell_seat, popup_grab.touch_grab); |
| 3434 | struct shell_surface *shsurf; |
Jonas Ådahl | c2b1011 | 2015-02-13 14:01:53 +0800 | [diff] [blame] | 3435 | struct shell_surface *next; |
Jonny Lamb | 76cf1fe | 2014-08-20 11:27:10 +0200 | [diff] [blame] | 3436 | |
| 3437 | if (touch->grab->interface == &touch_popup_grab_interface) { |
| 3438 | weston_touch_end_grab(grab->touch); |
| 3439 | shseat->popup_grab.client = NULL; |
| 3440 | shseat->popup_grab.touch_grab.interface = NULL; |
| 3441 | assert(!wl_list_empty(&shseat->popup_grab.surfaces_list)); |
| 3442 | /* Send the popup_done event to all the popups open */ |
Jonas Ådahl | c2b1011 | 2015-02-13 14:01:53 +0800 | [diff] [blame] | 3443 | wl_list_for_each_safe(shsurf, next, |
| 3444 | &shseat->popup_grab.surfaces_list, |
| 3445 | popup.grab_link) { |
Jonny Lamb | 76cf1fe | 2014-08-20 11:27:10 +0200 | [diff] [blame] | 3446 | shell_surface_send_popup_done(shsurf); |
| 3447 | shsurf->popup.shseat = NULL; |
Jonas Ådahl | c2b1011 | 2015-02-13 14:01:53 +0800 | [diff] [blame] | 3448 | wl_list_init(&shsurf->popup.grab_link); |
Jonny Lamb | 76cf1fe | 2014-08-20 11:27:10 +0200 | [diff] [blame] | 3449 | } |
Jonny Lamb | 76cf1fe | 2014-08-20 11:27:10 +0200 | [diff] [blame] | 3450 | wl_list_init(&shseat->popup_grab.surfaces_list); |
| 3451 | } |
| 3452 | } |
| 3453 | |
Jasper St. Pierre | da6ecd0 | 2015-02-27 18:35:45 +0800 | [diff] [blame] | 3454 | static struct shell_surface * |
| 3455 | get_top_popup(struct shell_seat *shseat) |
| 3456 | { |
| 3457 | struct shell_surface *shsurf; |
| 3458 | |
| 3459 | if (wl_list_empty(&shseat->popup_grab.surfaces_list)) { |
| 3460 | return NULL; |
| 3461 | } else { |
| 3462 | shsurf = container_of(shseat->popup_grab.surfaces_list.next, |
| 3463 | struct shell_surface, |
| 3464 | popup.grab_link); |
| 3465 | return shsurf; |
| 3466 | } |
| 3467 | } |
| 3468 | |
| 3469 | static int |
Jonas Ådahl | 01193ae | 2015-02-13 14:01:54 +0800 | [diff] [blame] | 3470 | add_popup_grab(struct shell_surface *shsurf, |
| 3471 | struct shell_seat *shseat, |
| 3472 | int32_t type) |
Giulio Camuffo | 5085a75 | 2013-03-25 21:42:45 +0100 | [diff] [blame] | 3473 | { |
Kristian Høgsberg | e314875 | 2013-05-06 23:19:49 -0400 | [diff] [blame] | 3474 | struct weston_seat *seat = shseat->seat; |
Jasper St. Pierre | da6ecd0 | 2015-02-27 18:35:45 +0800 | [diff] [blame] | 3475 | struct shell_surface *parent, *top_surface; |
Derek Foreman | 1281a36 | 2015-07-31 16:55:32 -0500 | [diff] [blame] | 3476 | struct weston_pointer *pointer = weston_seat_get_pointer(seat); |
| 3477 | struct weston_touch *touch = weston_seat_get_touch(seat); |
Jasper St. Pierre | da6ecd0 | 2015-02-27 18:35:45 +0800 | [diff] [blame] | 3478 | |
| 3479 | parent = get_shell_surface(shsurf->parent); |
| 3480 | top_surface = get_top_popup(shseat); |
| 3481 | if (shell_surface_is_xdg_popup(shsurf) && |
Dima Ryazanov | 497f25d | 2015-04-08 11:51:57 -0700 | [diff] [blame] | 3482 | (!parent || |
| 3483 | (top_surface == NULL && !shell_surface_is_xdg_surface(parent)) || |
Jasper St. Pierre | da6ecd0 | 2015-02-27 18:35:45 +0800 | [diff] [blame] | 3484 | (top_surface != NULL && parent != top_surface))) { |
Jonas Ådahl | ee45a55 | 2015-03-18 16:37:47 +0800 | [diff] [blame] | 3485 | wl_resource_post_error(shsurf->owner_resource, |
| 3486 | XDG_SHELL_ERROR_NOT_THE_TOPMOST_POPUP, |
Jasper St. Pierre | da6ecd0 | 2015-02-27 18:35:45 +0800 | [diff] [blame] | 3487 | "xdg_popup was not created on the " |
| 3488 | "topmost popup"); |
| 3489 | return -1; |
| 3490 | } |
Giulio Camuffo | 5085a75 | 2013-03-25 21:42:45 +0100 | [diff] [blame] | 3491 | |
| 3492 | if (wl_list_empty(&shseat->popup_grab.surfaces_list)) { |
Jonny Lamb | 76cf1fe | 2014-08-20 11:27:10 +0200 | [diff] [blame] | 3493 | shseat->popup_grab.type = type; |
Jonas Ådahl | 01193ae | 2015-02-13 14:01:54 +0800 | [diff] [blame] | 3494 | shseat->popup_grab.client = |
| 3495 | wl_resource_get_client(shsurf->resource); |
Jonny Lamb | 76cf1fe | 2014-08-20 11:27:10 +0200 | [diff] [blame] | 3496 | |
| 3497 | if (type == POINTER) { |
Jonas Ådahl | 01193ae | 2015-02-13 14:01:54 +0800 | [diff] [blame] | 3498 | shseat->popup_grab.grab.interface = |
| 3499 | &popup_grab_interface; |
| 3500 | |
| 3501 | /* We must make sure here that this popup was opened |
| 3502 | * after a mouse press, and not just by moving around |
| 3503 | * with other popups already open. */ |
Derek Foreman | 1281a36 | 2015-07-31 16:55:32 -0500 | [diff] [blame] | 3504 | if (pointer->button_count > 0) |
Jonny Lamb | 76cf1fe | 2014-08-20 11:27:10 +0200 | [diff] [blame] | 3505 | shseat->popup_grab.initial_up = 0; |
| 3506 | } else if (type == TOUCH) { |
Jonas Ådahl | 01193ae | 2015-02-13 14:01:54 +0800 | [diff] [blame] | 3507 | shseat->popup_grab.touch_grab.interface = |
| 3508 | &touch_popup_grab_interface; |
Jonny Lamb | 76cf1fe | 2014-08-20 11:27:10 +0200 | [diff] [blame] | 3509 | } |
Giulio Camuffo | 5085a75 | 2013-03-25 21:42:45 +0100 | [diff] [blame] | 3510 | |
Jonas Ådahl | 01193ae | 2015-02-13 14:01:54 +0800 | [diff] [blame] | 3511 | wl_list_insert(&shseat->popup_grab.surfaces_list, |
| 3512 | &shsurf->popup.grab_link); |
Jonny Lamb | 76cf1fe | 2014-08-20 11:27:10 +0200 | [diff] [blame] | 3513 | |
Jonas Ådahl | 01193ae | 2015-02-13 14:01:54 +0800 | [diff] [blame] | 3514 | if (type == POINTER) { |
Derek Foreman | 1281a36 | 2015-07-31 16:55:32 -0500 | [diff] [blame] | 3515 | weston_pointer_start_grab(pointer, |
Jonas Ådahl | 01193ae | 2015-02-13 14:01:54 +0800 | [diff] [blame] | 3516 | &shseat->popup_grab.grab); |
| 3517 | } else if (type == TOUCH) { |
Derek Foreman | 1281a36 | 2015-07-31 16:55:32 -0500 | [diff] [blame] | 3518 | weston_touch_start_grab(touch, |
Jonas Ådahl | 01193ae | 2015-02-13 14:01:54 +0800 | [diff] [blame] | 3519 | &shseat->popup_grab.touch_grab); |
| 3520 | } |
Rob Bradford | dfe3105 | 2013-06-26 19:49:11 +0100 | [diff] [blame] | 3521 | } else { |
Jonas Ådahl | 01193ae | 2015-02-13 14:01:54 +0800 | [diff] [blame] | 3522 | wl_list_insert(&shseat->popup_grab.surfaces_list, |
| 3523 | &shsurf->popup.grab_link); |
Giulio Camuffo | 5085a75 | 2013-03-25 21:42:45 +0100 | [diff] [blame] | 3524 | } |
Jasper St. Pierre | da6ecd0 | 2015-02-27 18:35:45 +0800 | [diff] [blame] | 3525 | |
| 3526 | return 0; |
Giulio Camuffo | 5085a75 | 2013-03-25 21:42:45 +0100 | [diff] [blame] | 3527 | } |
| 3528 | |
| 3529 | static void |
| 3530 | remove_popup_grab(struct shell_surface *shsurf) |
| 3531 | { |
| 3532 | struct shell_seat *shseat = shsurf->popup.shseat; |
| 3533 | |
Jasper St. Pierre | da6ecd0 | 2015-02-27 18:35:45 +0800 | [diff] [blame] | 3534 | if (shell_surface_is_xdg_popup(shsurf) && |
| 3535 | get_top_popup(shseat) != shsurf) { |
Jonas Ådahl | ee45a55 | 2015-03-18 16:37:47 +0800 | [diff] [blame] | 3536 | wl_resource_post_error(shsurf->owner_resource, |
| 3537 | XDG_SHELL_ERROR_NOT_THE_TOPMOST_POPUP, |
Jasper St. Pierre | da6ecd0 | 2015-02-27 18:35:45 +0800 | [diff] [blame] | 3538 | "xdg_popup was destroyed while it was " |
| 3539 | "not the topmost popup."); |
| 3540 | return; |
| 3541 | } |
| 3542 | |
Giulio Camuffo | 5085a75 | 2013-03-25 21:42:45 +0100 | [diff] [blame] | 3543 | wl_list_remove(&shsurf->popup.grab_link); |
| 3544 | wl_list_init(&shsurf->popup.grab_link); |
| 3545 | if (wl_list_empty(&shseat->popup_grab.surfaces_list)) { |
Jonny Lamb | 76cf1fe | 2014-08-20 11:27:10 +0200 | [diff] [blame] | 3546 | if (shseat->popup_grab.type == POINTER) { |
| 3547 | weston_pointer_end_grab(shseat->popup_grab.grab.pointer); |
| 3548 | shseat->popup_grab.grab.interface = NULL; |
| 3549 | } else if (shseat->popup_grab.type == TOUCH) { |
| 3550 | weston_touch_end_grab(shseat->popup_grab.touch_grab.touch); |
| 3551 | shseat->popup_grab.touch_grab.interface = NULL; |
| 3552 | } |
Kristian Høgsberg | 57e0907 | 2012-10-30 14:07:27 -0400 | [diff] [blame] | 3553 | } |
| 3554 | } |
| 3555 | |
Jasper St. Pierre | da6ecd0 | 2015-02-27 18:35:45 +0800 | [diff] [blame] | 3556 | static int |
Kristian Høgsberg | 3730f36 | 2012-04-13 12:40:07 -0400 | [diff] [blame] | 3557 | shell_map_popup(struct shell_surface *shsurf) |
Kristian Høgsberg | b3cca0a | 2012-01-04 22:19:14 -0500 | [diff] [blame] | 3558 | { |
Giulio Camuffo | 5085a75 | 2013-03-25 21:42:45 +0100 | [diff] [blame] | 3559 | struct shell_seat *shseat = shsurf->popup.shseat; |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 3560 | struct weston_view *parent_view = get_default_view(shsurf->parent); |
Derek Foreman | 1281a36 | 2015-07-31 16:55:32 -0500 | [diff] [blame] | 3561 | struct weston_pointer *pointer = weston_seat_get_pointer(shseat->seat); |
| 3562 | struct weston_touch *touch = weston_seat_get_touch(shseat->seat); |
Kristian Høgsberg | b3cca0a | 2012-01-04 22:19:14 -0500 | [diff] [blame] | 3563 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 3564 | shsurf->surface->output = parent_view->output; |
| 3565 | shsurf->view->output = parent_view->output; |
Kristian Høgsberg | b3cca0a | 2012-01-04 22:19:14 -0500 | [diff] [blame] | 3566 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 3567 | weston_view_set_transform_parent(shsurf->view, parent_view); |
| 3568 | weston_view_set_position(shsurf->view, shsurf->popup.x, shsurf->popup.y); |
| 3569 | weston_view_update_transform(shsurf->view); |
Kristian Høgsberg | b3cca0a | 2012-01-04 22:19:14 -0500 | [diff] [blame] | 3570 | |
Derek Foreman | 1281a36 | 2015-07-31 16:55:32 -0500 | [diff] [blame] | 3571 | if (pointer && |
| 3572 | pointer->grab_serial == shsurf->popup.serial) { |
Jasper St. Pierre | da6ecd0 | 2015-02-27 18:35:45 +0800 | [diff] [blame] | 3573 | if (add_popup_grab(shsurf, shseat, POINTER) != 0) |
| 3574 | return -1; |
Derek Foreman | 1281a36 | 2015-07-31 16:55:32 -0500 | [diff] [blame] | 3575 | } else if (touch && |
| 3576 | touch->grab_serial == shsurf->popup.serial) { |
Jasper St. Pierre | da6ecd0 | 2015-02-27 18:35:45 +0800 | [diff] [blame] | 3577 | if (add_popup_grab(shsurf, shseat, TOUCH) != 0) |
| 3578 | return -1; |
Kristian Høgsberg | 3730f36 | 2012-04-13 12:40:07 -0400 | [diff] [blame] | 3579 | } else { |
Rafael Antognolli | e2a3455 | 2013-12-03 15:35:45 -0200 | [diff] [blame] | 3580 | shell_surface_send_popup_done(shsurf); |
Giulio Camuffo | 5085a75 | 2013-03-25 21:42:45 +0100 | [diff] [blame] | 3581 | shseat->popup_grab.client = NULL; |
Kristian Høgsberg | 3730f36 | 2012-04-13 12:40:07 -0400 | [diff] [blame] | 3582 | } |
Jasper St. Pierre | da6ecd0 | 2015-02-27 18:35:45 +0800 | [diff] [blame] | 3583 | |
| 3584 | return 0; |
Kristian Høgsberg | b3cca0a | 2012-01-04 22:19:14 -0500 | [diff] [blame] | 3585 | } |
| 3586 | |
Pekka Paalanen | 9d1613e | 2011-11-25 12:09:16 +0200 | [diff] [blame] | 3587 | static const struct wl_shell_surface_interface shell_surface_implementation = { |
Scott Moreau | ff1db4a | 2012-04-17 19:06:18 -0600 | [diff] [blame] | 3588 | shell_surface_pong, |
Pekka Paalanen | 9d1613e | 2011-11-25 12:09:16 +0200 | [diff] [blame] | 3589 | shell_surface_move, |
| 3590 | shell_surface_resize, |
| 3591 | shell_surface_set_toplevel, |
| 3592 | shell_surface_set_transient, |
Kristian Høgsberg | b3cca0a | 2012-01-04 22:19:14 -0500 | [diff] [blame] | 3593 | shell_surface_set_fullscreen, |
Juan Zhao | 96879df | 2012-02-07 08:45:41 +0800 | [diff] [blame] | 3594 | shell_surface_set_popup, |
Kristian Høgsberg | e7afd91 | 2012-05-02 09:47:44 -0400 | [diff] [blame] | 3595 | shell_surface_set_maximized, |
| 3596 | shell_surface_set_title, |
| 3597 | shell_surface_set_class |
Pekka Paalanen | 9d1613e | 2011-11-25 12:09:16 +0200 | [diff] [blame] | 3598 | }; |
| 3599 | |
| 3600 | static void |
Tiago Vignatti | bc052c9 | 2012-04-19 16:18:18 +0300 | [diff] [blame] | 3601 | destroy_shell_surface(struct shell_surface *shsurf) |
Pekka Paalanen | 9d1613e | 2011-11-25 12:09:16 +0200 | [diff] [blame] | 3602 | { |
Kristian Høgsberg | 9046d24 | 2014-01-10 00:25:30 -0800 | [diff] [blame] | 3603 | struct shell_surface *child, *next; |
| 3604 | |
Jason Ekstrand | 651f00e | 2013-06-14 10:07:54 -0500 | [diff] [blame] | 3605 | wl_signal_emit(&shsurf->destroy_signal, shsurf); |
| 3606 | |
Giulio Camuffo | 5085a75 | 2013-03-25 21:42:45 +0100 | [diff] [blame] | 3607 | if (!wl_list_empty(&shsurf->popup.grab_link)) { |
| 3608 | remove_popup_grab(shsurf); |
| 3609 | } |
Kristian Høgsberg | b3cca0a | 2012-01-04 22:19:14 -0500 | [diff] [blame] | 3610 | |
Alex Wu | bd3354b | 2012-04-17 17:20:49 +0800 | [diff] [blame] | 3611 | if (shsurf->fullscreen.type == WL_SHELL_SURFACE_FULLSCREEN_METHOD_DRIVER && |
Alexander Larsson | f82b6ca | 2013-05-28 16:23:39 +0200 | [diff] [blame] | 3612 | shell_surface_is_top_fullscreen(shsurf)) |
| 3613 | restore_output_mode (shsurf->fullscreen_output); |
Pekka Paalanen | 9d1613e | 2011-11-25 12:09:16 +0200 | [diff] [blame] | 3614 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 3615 | if (shsurf->fullscreen.black_view) |
| 3616 | weston_surface_destroy(shsurf->fullscreen.black_view->surface); |
Alex Wu | aa08e2d | 2012-03-05 11:01:40 +0800 | [diff] [blame] | 3617 | |
Alex Wu | bd3354b | 2012-04-17 17:20:49 +0800 | [diff] [blame] | 3618 | /* As destroy_resource() use wl_list_for_each_safe(), |
| 3619 | * we can always remove the listener. |
| 3620 | */ |
| 3621 | wl_list_remove(&shsurf->surface_destroy_listener.link); |
| 3622 | shsurf->surface->configure = NULL; |
Pekka Paalanen | 8274d90 | 2014-08-06 19:36:51 +0300 | [diff] [blame] | 3623 | weston_surface_set_label_func(shsurf->surface, NULL); |
Scott Moreau | 976a050 | 2013-03-07 10:15:17 -0700 | [diff] [blame] | 3624 | free(shsurf->title); |
Alex Wu | bd3354b | 2012-04-17 17:20:49 +0800 | [diff] [blame] | 3625 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 3626 | weston_view_destroy(shsurf->view); |
| 3627 | |
Philip Withnall | 648a4dd | 2013-11-25 18:01:44 +0000 | [diff] [blame] | 3628 | wl_list_remove(&shsurf->children_link); |
Emilio Pozuelo Monfort | adaa20c | 2014-01-28 13:54:16 +0100 | [diff] [blame] | 3629 | wl_list_for_each_safe(child, next, &shsurf->children_list, children_link) |
| 3630 | shell_surface_set_parent(child, NULL); |
Philip Withnall | 648a4dd | 2013-11-25 18:01:44 +0000 | [diff] [blame] | 3631 | |
Pekka Paalanen | 9d1613e | 2011-11-25 12:09:16 +0200 | [diff] [blame] | 3632 | wl_list_remove(&shsurf->link); |
| 3633 | free(shsurf); |
| 3634 | } |
| 3635 | |
| 3636 | static void |
Tiago Vignatti | bc052c9 | 2012-04-19 16:18:18 +0300 | [diff] [blame] | 3637 | shell_destroy_shell_surface(struct wl_resource *resource) |
| 3638 | { |
Jason Ekstrand | 651f00e | 2013-06-14 10:07:54 -0500 | [diff] [blame] | 3639 | struct shell_surface *shsurf = wl_resource_get_user_data(resource); |
Tiago Vignatti | bc052c9 | 2012-04-19 16:18:18 +0300 | [diff] [blame] | 3640 | |
Bryan Cain | a46b946 | 2014-04-04 17:41:24 -0500 | [diff] [blame] | 3641 | if (!wl_list_empty(&shsurf->popup.grab_link)) |
| 3642 | remove_popup_grab(shsurf); |
Jonas Ådahl | 49d77d2 | 2015-03-18 16:20:51 +0800 | [diff] [blame] | 3643 | wl_list_remove(wl_resource_get_link(shsurf->resource)); |
Kristian Høgsberg | 160fe75 | 2014-03-11 10:19:10 -0700 | [diff] [blame] | 3644 | shsurf->resource = NULL; |
Tiago Vignatti | bc052c9 | 2012-04-19 16:18:18 +0300 | [diff] [blame] | 3645 | } |
| 3646 | |
| 3647 | static void |
Kristian Høgsberg | 27e3052 | 2012-04-11 23:18:23 -0400 | [diff] [blame] | 3648 | shell_handle_surface_destroy(struct wl_listener *listener, void *data) |
Pekka Paalanen | 9d1613e | 2011-11-25 12:09:16 +0200 | [diff] [blame] | 3649 | { |
| 3650 | struct shell_surface *shsurf = container_of(listener, |
| 3651 | struct shell_surface, |
| 3652 | surface_destroy_listener); |
| 3653 | |
Jason Ekstrand | 651f00e | 2013-06-14 10:07:54 -0500 | [diff] [blame] | 3654 | if (shsurf->resource) |
| 3655 | wl_resource_destroy(shsurf->resource); |
Ander Conselvan de Oliveira | 15f9a26 | 2014-04-29 17:54:02 +0300 | [diff] [blame] | 3656 | |
| 3657 | destroy_shell_surface(shsurf); |
Pekka Paalanen | 9d1613e | 2011-11-25 12:09:16 +0200 | [diff] [blame] | 3658 | } |
| 3659 | |
Kristian Høgsberg | d813445 | 2012-06-21 12:49:02 -0400 | [diff] [blame] | 3660 | static void |
Derek Foreman | 039e9be | 2015-04-14 17:09:06 -0500 | [diff] [blame] | 3661 | fade_out_done_idle_cb(void *data) |
Kristian Høgsberg | 160fe75 | 2014-03-11 10:19:10 -0700 | [diff] [blame] | 3662 | { |
| 3663 | struct shell_surface *shsurf = data; |
| 3664 | |
| 3665 | weston_surface_destroy(shsurf->surface); |
| 3666 | } |
| 3667 | |
| 3668 | static void |
Derek Foreman | 039e9be | 2015-04-14 17:09:06 -0500 | [diff] [blame] | 3669 | fade_out_done(struct weston_view_animation *animation, void *data) |
| 3670 | { |
| 3671 | struct shell_surface *shsurf = data; |
| 3672 | struct wl_event_loop *loop; |
| 3673 | |
| 3674 | loop = wl_display_get_event_loop( |
| 3675 | shsurf->surface->compositor->wl_display); |
| 3676 | |
| 3677 | if (!shsurf->destroying) { |
| 3678 | wl_event_loop_add_idle(loop, fade_out_done_idle_cb, shsurf); |
| 3679 | shsurf->destroying = true; |
| 3680 | } |
| 3681 | } |
| 3682 | |
| 3683 | static void |
Kristian Høgsberg | 160fe75 | 2014-03-11 10:19:10 -0700 | [diff] [blame] | 3684 | handle_resource_destroy(struct wl_listener *listener, void *data) |
| 3685 | { |
| 3686 | struct shell_surface *shsurf = |
| 3687 | container_of(listener, struct shell_surface, |
| 3688 | resource_destroy_listener); |
| 3689 | |
Ander Conselvan de Oliveira | 15f9a26 | 2014-04-29 17:54:02 +0300 | [diff] [blame] | 3690 | if (!weston_surface_is_mapped(shsurf->surface)) |
| 3691 | return; |
| 3692 | |
Kristian Høgsberg | 160fe75 | 2014-03-11 10:19:10 -0700 | [diff] [blame] | 3693 | shsurf->surface->ref_count++; |
| 3694 | |
| 3695 | pixman_region32_fini(&shsurf->surface->pending.input); |
| 3696 | pixman_region32_init(&shsurf->surface->pending.input); |
| 3697 | pixman_region32_fini(&shsurf->surface->input); |
| 3698 | pixman_region32_init(&shsurf->surface->input); |
Jonny Lamb | f322f8e | 2014-08-12 15:13:30 +0200 | [diff] [blame] | 3699 | if (shsurf->shell->win_close_animation_type == ANIMATION_FADE) { |
| 3700 | weston_fade_run(shsurf->view, 1.0, 0.0, 300.0, |
| 3701 | fade_out_done, shsurf); |
| 3702 | } else { |
| 3703 | weston_surface_destroy(shsurf->surface); |
| 3704 | } |
Kristian Høgsberg | 160fe75 | 2014-03-11 10:19:10 -0700 | [diff] [blame] | 3705 | } |
| 3706 | |
| 3707 | static void |
Jason Ekstrand | 918f2dd | 2013-12-02 21:01:53 -0600 | [diff] [blame] | 3708 | shell_surface_configure(struct weston_surface *, int32_t, int32_t); |
Kristian Høgsberg | d813445 | 2012-06-21 12:49:02 -0400 | [diff] [blame] | 3709 | |
Kristian Høgsberg | 1ef2313 | 2013-12-04 00:20:01 -0800 | [diff] [blame] | 3710 | struct shell_surface * |
Kristian Høgsberg | 8334bc1 | 2012-01-03 10:29:47 -0500 | [diff] [blame] | 3711 | get_shell_surface(struct weston_surface *surface) |
Pekka Paalanen | ec2b32f | 2011-11-28 15:12:34 +0200 | [diff] [blame] | 3712 | { |
Kristian Høgsberg | d813445 | 2012-06-21 12:49:02 -0400 | [diff] [blame] | 3713 | if (surface->configure == shell_surface_configure) |
Giulio Camuffo | 7fe01b1 | 2013-03-28 18:02:42 +0100 | [diff] [blame] | 3714 | return surface->configure_private; |
Kristian Høgsberg | d813445 | 2012-06-21 12:49:02 -0400 | [diff] [blame] | 3715 | else |
| 3716 | return NULL; |
Pekka Paalanen | ec2b32f | 2011-11-28 15:12:34 +0200 | [diff] [blame] | 3717 | } |
| 3718 | |
Rafael Antognolli | e2a3455 | 2013-12-03 15:35:45 -0200 | [diff] [blame] | 3719 | static struct shell_surface * |
Jason Ekstrand | 9e9512f | 2014-04-16 21:12:10 -0500 | [diff] [blame] | 3720 | create_common_surface(struct shell_client *owner, void *shell, |
| 3721 | struct weston_surface *surface, |
Rafael Antognolli | e2a3455 | 2013-12-03 15:35:45 -0200 | [diff] [blame] | 3722 | const struct weston_shell_client *client) |
Pekka Paalanen | 9d1613e | 2011-11-25 12:09:16 +0200 | [diff] [blame] | 3723 | { |
Pekka Paalanen | 9d1613e | 2011-11-25 12:09:16 +0200 | [diff] [blame] | 3724 | struct shell_surface *shsurf; |
| 3725 | |
Pekka Paalanen | 50b6747 | 2014-10-01 15:02:41 +0300 | [diff] [blame] | 3726 | assert(surface->configure == NULL); |
Ander Conselvan de Oliveira | 093bfa3 | 2012-03-27 17:36:41 +0300 | [diff] [blame] | 3727 | |
Pekka Paalanen | 9d1613e | 2011-11-25 12:09:16 +0200 | [diff] [blame] | 3728 | shsurf = calloc(1, sizeof *shsurf); |
| 3729 | if (!shsurf) { |
Martin Minarik | 6d11836 | 2012-06-07 18:01:59 +0200 | [diff] [blame] | 3730 | weston_log("no memory to allocate shell surface\n"); |
Kristian Høgsberg | 45ba869 | 2012-05-21 14:27:33 -0400 | [diff] [blame] | 3731 | return NULL; |
Pekka Paalanen | 9d1613e | 2011-11-25 12:09:16 +0200 | [diff] [blame] | 3732 | } |
| 3733 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 3734 | shsurf->view = weston_view_create(surface); |
| 3735 | if (!shsurf->view) { |
| 3736 | weston_log("no memory to allocate shell surface\n"); |
| 3737 | free(shsurf); |
| 3738 | return NULL; |
| 3739 | } |
| 3740 | |
Ander Conselvan de Oliveira | 093bfa3 | 2012-03-27 17:36:41 +0300 | [diff] [blame] | 3741 | surface->configure = shell_surface_configure; |
Giulio Camuffo | 7fe01b1 | 2013-03-28 18:02:42 +0100 | [diff] [blame] | 3742 | surface->configure_private = shsurf; |
Pekka Paalanen | 8274d90 | 2014-08-06 19:36:51 +0300 | [diff] [blame] | 3743 | weston_surface_set_label_func(surface, shell_surface_get_label); |
Ander Conselvan de Oliveira | 093bfa3 | 2012-03-27 17:36:41 +0300 | [diff] [blame] | 3744 | |
Kristian Høgsberg | 160fe75 | 2014-03-11 10:19:10 -0700 | [diff] [blame] | 3745 | shsurf->resource_destroy_listener.notify = handle_resource_destroy; |
| 3746 | wl_resource_add_destroy_listener(surface->resource, |
| 3747 | &shsurf->resource_destroy_listener); |
Jason Ekstrand | 9e9512f | 2014-04-16 21:12:10 -0500 | [diff] [blame] | 3748 | shsurf->owner = owner; |
Kristian Høgsberg | 160fe75 | 2014-03-11 10:19:10 -0700 | [diff] [blame] | 3749 | |
Tiago Vignatti | bc052c9 | 2012-04-19 16:18:18 +0300 | [diff] [blame] | 3750 | shsurf->shell = (struct desktop_shell *) shell; |
Scott Moreau | ff1db4a | 2012-04-17 19:06:18 -0600 | [diff] [blame] | 3751 | shsurf->unresponsive = 0; |
Alex Wu | 4539b08 | 2012-03-01 12:57:46 +0800 | [diff] [blame] | 3752 | shsurf->saved_position_valid = false; |
Rafael Antognolli | 3c4e3f7 | 2013-12-03 15:35:46 -0200 | [diff] [blame] | 3753 | shsurf->saved_size_valid = false; |
Alex Wu | 7bcb8bd | 2012-04-27 09:07:24 +0800 | [diff] [blame] | 3754 | shsurf->saved_rotation_valid = false; |
Pekka Paalanen | 9d1613e | 2011-11-25 12:09:16 +0200 | [diff] [blame] | 3755 | shsurf->surface = surface; |
Alex Wu | 4539b08 | 2012-03-01 12:57:46 +0800 | [diff] [blame] | 3756 | shsurf->fullscreen.type = WL_SHELL_SURFACE_FULLSCREEN_METHOD_DEFAULT; |
| 3757 | shsurf->fullscreen.framerate = 0; |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 3758 | shsurf->fullscreen.black_view = NULL; |
Alex Wu | 4539b08 | 2012-03-01 12:57:46 +0800 | [diff] [blame] | 3759 | wl_list_init(&shsurf->fullscreen.transform.link); |
| 3760 | |
Jasper St. Pierre | 9aa8ce6 | 2014-04-11 16:18:54 -0700 | [diff] [blame] | 3761 | shsurf->output = get_default_output(shsurf->shell->compositor); |
| 3762 | |
Jason Ekstrand | 651f00e | 2013-06-14 10:07:54 -0500 | [diff] [blame] | 3763 | wl_signal_init(&shsurf->destroy_signal); |
Kristian Høgsberg | 27e3052 | 2012-04-11 23:18:23 -0400 | [diff] [blame] | 3764 | shsurf->surface_destroy_listener.notify = shell_handle_surface_destroy; |
Jason Ekstrand | 26ed73c | 2013-06-06 22:34:41 -0500 | [diff] [blame] | 3765 | wl_signal_add(&surface->destroy_signal, |
Kristian Høgsberg | 27e3052 | 2012-04-11 23:18:23 -0400 | [diff] [blame] | 3766 | &shsurf->surface_destroy_listener); |
Pekka Paalanen | 9d1613e | 2011-11-25 12:09:16 +0200 | [diff] [blame] | 3767 | |
| 3768 | /* init link so its safe to always remove it in destroy_shell_surface */ |
| 3769 | wl_list_init(&shsurf->link); |
Giulio Camuffo | 5085a75 | 2013-03-25 21:42:45 +0100 | [diff] [blame] | 3770 | wl_list_init(&shsurf->popup.grab_link); |
Pekka Paalanen | 9d1613e | 2011-11-25 12:09:16 +0200 | [diff] [blame] | 3771 | |
Pekka Paalanen | 460099f | 2012-01-20 16:48:25 +0200 | [diff] [blame] | 3772 | /* empty when not in use */ |
| 3773 | wl_list_init(&shsurf->rotation.transform.link); |
Kristian Høgsberg | 765e27b | 2012-01-27 13:36:13 -0500 | [diff] [blame] | 3774 | weston_matrix_init(&shsurf->rotation.rotation); |
Pekka Paalanen | 460099f | 2012-01-20 16:48:25 +0200 | [diff] [blame] | 3775 | |
Jonas Ådahl | 62fcd04 | 2012-06-13 00:01:23 +0200 | [diff] [blame] | 3776 | wl_list_init(&shsurf->workspace_transform.link); |
| 3777 | |
Philip Withnall | 648a4dd | 2013-11-25 18:01:44 +0000 | [diff] [blame] | 3778 | wl_list_init(&shsurf->children_link); |
| 3779 | wl_list_init(&shsurf->children_list); |
| 3780 | shsurf->parent = NULL; |
| 3781 | |
Pekka Paalanen | b502654 | 2014-11-12 15:09:24 +0200 | [diff] [blame] | 3782 | set_type(shsurf, SHELL_SURFACE_NONE); |
Pekka Paalanen | 9d1613e | 2011-11-25 12:09:16 +0200 | [diff] [blame] | 3783 | |
Kristian Høgsberg | a61ca06 | 2012-05-22 16:05:52 -0400 | [diff] [blame] | 3784 | shsurf->client = client; |
| 3785 | |
Kristian Høgsberg | 45ba869 | 2012-05-21 14:27:33 -0400 | [diff] [blame] | 3786 | return shsurf; |
Tiago Vignatti | bc052c9 | 2012-04-19 16:18:18 +0300 | [diff] [blame] | 3787 | } |
| 3788 | |
Rafael Antognolli | e2a3455 | 2013-12-03 15:35:45 -0200 | [diff] [blame] | 3789 | static struct shell_surface * |
| 3790 | create_shell_surface(void *shell, struct weston_surface *surface, |
| 3791 | const struct weston_shell_client *client) |
| 3792 | { |
Jason Ekstrand | 9e9512f | 2014-04-16 21:12:10 -0500 | [diff] [blame] | 3793 | return create_common_surface(NULL, shell, surface, client); |
Rafael Antognolli | e2a3455 | 2013-12-03 15:35:45 -0200 | [diff] [blame] | 3794 | } |
| 3795 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 3796 | static struct weston_view * |
| 3797 | get_primary_view(void *shell, struct shell_surface *shsurf) |
| 3798 | { |
| 3799 | return shsurf->view; |
| 3800 | } |
| 3801 | |
Tiago Vignatti | bc052c9 | 2012-04-19 16:18:18 +0300 | [diff] [blame] | 3802 | static void |
| 3803 | shell_get_shell_surface(struct wl_client *client, |
| 3804 | struct wl_resource *resource, |
| 3805 | uint32_t id, |
| 3806 | struct wl_resource *surface_resource) |
| 3807 | { |
Jason Ekstrand | 0f2ef7e | 2013-06-14 10:07:53 -0500 | [diff] [blame] | 3808 | struct weston_surface *surface = |
| 3809 | wl_resource_get_user_data(surface_resource); |
Jason Ekstrand | 9e9512f | 2014-04-16 21:12:10 -0500 | [diff] [blame] | 3810 | struct shell_client *sc = wl_resource_get_user_data(resource); |
| 3811 | struct desktop_shell *shell = sc->shell; |
Tiago Vignatti | bc052c9 | 2012-04-19 16:18:18 +0300 | [diff] [blame] | 3812 | struct shell_surface *shsurf; |
| 3813 | |
Pekka Paalanen | 50b6747 | 2014-10-01 15:02:41 +0300 | [diff] [blame] | 3814 | if (weston_surface_set_role(surface, "wl_shell_surface", |
| 3815 | resource, WL_SHELL_ERROR_ROLE) < 0) |
Tiago Vignatti | bc052c9 | 2012-04-19 16:18:18 +0300 | [diff] [blame] | 3816 | return; |
Tiago Vignatti | bc052c9 | 2012-04-19 16:18:18 +0300 | [diff] [blame] | 3817 | |
Jason Ekstrand | 9e9512f | 2014-04-16 21:12:10 -0500 | [diff] [blame] | 3818 | shsurf = create_common_surface(sc, shell, surface, &shell_client); |
Kristian Høgsberg | 9540ea6 | 2012-05-21 14:28:57 -0400 | [diff] [blame] | 3819 | if (!shsurf) { |
Pekka Paalanen | 50b6747 | 2014-10-01 15:02:41 +0300 | [diff] [blame] | 3820 | wl_resource_post_no_memory(surface_resource); |
Kristian Høgsberg | 9540ea6 | 2012-05-21 14:28:57 -0400 | [diff] [blame] | 3821 | return; |
| 3822 | } |
Tiago Vignatti | bc052c9 | 2012-04-19 16:18:18 +0300 | [diff] [blame] | 3823 | |
Jason Ekstrand | a85118c | 2013-06-27 20:17:02 -0500 | [diff] [blame] | 3824 | shsurf->resource = |
| 3825 | wl_resource_create(client, |
| 3826 | &wl_shell_surface_interface, 1, id); |
| 3827 | wl_resource_set_implementation(shsurf->resource, |
| 3828 | &shell_surface_implementation, |
| 3829 | shsurf, shell_destroy_shell_surface); |
Jonas Ådahl | 49d77d2 | 2015-03-18 16:20:51 +0800 | [diff] [blame] | 3830 | wl_list_init(wl_resource_get_link(shsurf->resource)); |
Pekka Paalanen | 9d1613e | 2011-11-25 12:09:16 +0200 | [diff] [blame] | 3831 | } |
| 3832 | |
Rafael Antognolli | e2a3455 | 2013-12-03 15:35:45 -0200 | [diff] [blame] | 3833 | static bool |
| 3834 | shell_surface_is_wl_shell_surface(struct shell_surface *shsurf) |
| 3835 | { |
Kristian Høgsberg | 0b7d995 | 2014-02-03 15:50:38 -0800 | [diff] [blame] | 3836 | /* A shell surface without a resource is created from xwayland |
| 3837 | * and is considered a wl_shell surface for now. */ |
| 3838 | |
| 3839 | return shsurf->resource == NULL || |
| 3840 | wl_resource_instance_of(shsurf->resource, |
| 3841 | &wl_shell_surface_interface, |
| 3842 | &shell_surface_implementation); |
Rafael Antognolli | e2a3455 | 2013-12-03 15:35:45 -0200 | [diff] [blame] | 3843 | } |
| 3844 | |
Pekka Paalanen | 9d1613e | 2011-11-25 12:09:16 +0200 | [diff] [blame] | 3845 | static const struct wl_shell_interface shell_implementation = { |
Pekka Paalanen | 4622967 | 2011-11-29 15:49:31 +0200 | [diff] [blame] | 3846 | shell_get_shell_surface |
Kristian Høgsberg | 4cca349 | 2011-01-18 07:53:49 -0500 | [diff] [blame] | 3847 | }; |
| 3848 | |
Rafael Antognolli | e2a3455 | 2013-12-03 15:35:45 -0200 | [diff] [blame] | 3849 | /**************************** |
| 3850 | * xdg-shell implementation */ |
| 3851 | |
| 3852 | static void |
| 3853 | xdg_surface_destroy(struct wl_client *client, |
| 3854 | struct wl_resource *resource) |
| 3855 | { |
| 3856 | wl_resource_destroy(resource); |
| 3857 | } |
| 3858 | |
| 3859 | static void |
Jasper St. Pierre | c815d62 | 2014-04-10 18:37:54 -0700 | [diff] [blame] | 3860 | xdg_surface_set_parent(struct wl_client *client, |
| 3861 | struct wl_resource *resource, |
| 3862 | struct wl_resource *parent_resource) |
Jasper St. Pierre | 63a9c33 | 2014-02-01 18:35:15 -0500 | [diff] [blame] | 3863 | { |
| 3864 | struct shell_surface *shsurf = wl_resource_get_user_data(resource); |
Jasper St. Pierre | 66bc949 | 2015-02-13 14:01:55 +0800 | [diff] [blame] | 3865 | struct shell_surface *parent; |
Jasper St. Pierre | 63a9c33 | 2014-02-01 18:35:15 -0500 | [diff] [blame] | 3866 | |
Jasper St. Pierre | 66bc949 | 2015-02-13 14:01:55 +0800 | [diff] [blame] | 3867 | if (parent_resource) { |
Jasper St. Pierre | 63a9c33 | 2014-02-01 18:35:15 -0500 | [diff] [blame] | 3868 | parent = wl_resource_get_user_data(parent_resource); |
Jasper St. Pierre | 66bc949 | 2015-02-13 14:01:55 +0800 | [diff] [blame] | 3869 | shell_surface_set_parent(shsurf, parent->surface); |
| 3870 | } else { |
| 3871 | shell_surface_set_parent(shsurf, NULL); |
| 3872 | } |
Jasper St. Pierre | 63a9c33 | 2014-02-01 18:35:15 -0500 | [diff] [blame] | 3873 | } |
| 3874 | |
| 3875 | static void |
Rafael Antognolli | e2a3455 | 2013-12-03 15:35:45 -0200 | [diff] [blame] | 3876 | xdg_surface_set_app_id(struct wl_client *client, |
| 3877 | struct wl_resource *resource, |
| 3878 | const char *app_id) |
| 3879 | { |
| 3880 | struct shell_surface *shsurf = wl_resource_get_user_data(resource); |
| 3881 | |
| 3882 | free(shsurf->class); |
| 3883 | shsurf->class = strdup(app_id); |
Pekka Paalanen | b502654 | 2014-11-12 15:09:24 +0200 | [diff] [blame] | 3884 | shsurf->surface->timeline.force_refresh = 1; |
Rafael Antognolli | e2a3455 | 2013-12-03 15:35:45 -0200 | [diff] [blame] | 3885 | } |
| 3886 | |
| 3887 | static void |
Jasper St. Pierre | 81ff075 | 2014-03-13 11:04:53 -0400 | [diff] [blame] | 3888 | xdg_surface_show_window_menu(struct wl_client *client, |
| 3889 | struct wl_resource *surface_resource, |
| 3890 | struct wl_resource *seat_resource, |
| 3891 | uint32_t serial, |
| 3892 | int32_t x, |
| 3893 | int32_t y) |
| 3894 | { |
| 3895 | /* TODO */ |
| 3896 | } |
| 3897 | |
| 3898 | static void |
Rafael Antognolli | e2a3455 | 2013-12-03 15:35:45 -0200 | [diff] [blame] | 3899 | xdg_surface_set_title(struct wl_client *client, |
| 3900 | struct wl_resource *resource, const char *title) |
| 3901 | { |
| 3902 | struct shell_surface *shsurf = wl_resource_get_user_data(resource); |
| 3903 | |
| 3904 | set_title(shsurf, title); |
| 3905 | } |
| 3906 | |
| 3907 | static void |
| 3908 | xdg_surface_move(struct wl_client *client, struct wl_resource *resource, |
| 3909 | struct wl_resource *seat_resource, uint32_t serial) |
| 3910 | { |
| 3911 | common_surface_move(resource, seat_resource, serial); |
| 3912 | } |
| 3913 | |
| 3914 | static void |
| 3915 | xdg_surface_resize(struct wl_client *client, struct wl_resource *resource, |
| 3916 | struct wl_resource *seat_resource, uint32_t serial, |
| 3917 | uint32_t edges) |
| 3918 | { |
| 3919 | common_surface_resize(resource, seat_resource, serial, edges); |
| 3920 | } |
| 3921 | |
| 3922 | static void |
Jasper St. Pierre | ab2c108 | 2014-04-10 10:41:46 -0700 | [diff] [blame] | 3923 | xdg_surface_ack_configure(struct wl_client *client, |
| 3924 | struct wl_resource *resource, |
| 3925 | uint32_t serial) |
Rafael Antognolli | e2a3455 | 2013-12-03 15:35:45 -0200 | [diff] [blame] | 3926 | { |
| 3927 | struct shell_surface *shsurf = wl_resource_get_user_data(resource); |
| 3928 | |
Jasper St. Pierre | 8c6aa45 | 2014-02-08 18:29:49 -0500 | [diff] [blame] | 3929 | if (shsurf->state_requested) { |
| 3930 | shsurf->next_state = shsurf->requested_state; |
| 3931 | shsurf->state_changed = true; |
| 3932 | shsurf->state_requested = false; |
Rafael Antognolli | 3c4e3f7 | 2013-12-03 15:35:46 -0200 | [diff] [blame] | 3933 | } |
Rafael Antognolli | e2a3455 | 2013-12-03 15:35:45 -0200 | [diff] [blame] | 3934 | } |
| 3935 | |
Manuel Bachmann | 50c87db | 2014-02-26 15:52:13 +0100 | [diff] [blame] | 3936 | static void |
Jasper St. Pierre | ccf48fb | 2014-05-02 10:21:38 -0400 | [diff] [blame] | 3937 | xdg_surface_set_window_geometry(struct wl_client *client, |
| 3938 | struct wl_resource *resource, |
| 3939 | int32_t x, |
| 3940 | int32_t y, |
| 3941 | int32_t width, |
| 3942 | int32_t height) |
| 3943 | { |
| 3944 | struct shell_surface *shsurf = wl_resource_get_user_data(resource); |
| 3945 | |
| 3946 | set_window_geometry(shsurf, x, y, width, height); |
| 3947 | } |
| 3948 | |
| 3949 | static void |
Jasper St. Pierre | ab2c108 | 2014-04-10 10:41:46 -0700 | [diff] [blame] | 3950 | xdg_surface_set_maximized(struct wl_client *client, |
| 3951 | struct wl_resource *resource) |
| 3952 | { |
| 3953 | struct shell_surface *shsurf = wl_resource_get_user_data(resource); |
Marek Chalupa | bfbb64b | 2014-09-08 12:34:20 +0200 | [diff] [blame] | 3954 | struct weston_output *output; |
Jasper St. Pierre | ab2c108 | 2014-04-10 10:41:46 -0700 | [diff] [blame] | 3955 | |
| 3956 | shsurf->state_requested = true; |
| 3957 | shsurf->requested_state.maximized = true; |
Marek Chalupa | bfbb64b | 2014-09-08 12:34:20 +0200 | [diff] [blame] | 3958 | |
| 3959 | if (!weston_surface_is_mapped(shsurf->surface)) |
| 3960 | output = get_focused_output(shsurf->surface->compositor); |
| 3961 | else |
| 3962 | output = shsurf->surface->output; |
| 3963 | |
| 3964 | shell_surface_set_output(shsurf, output); |
Jasper St. Pierre | 9aa8ce6 | 2014-04-11 16:18:54 -0700 | [diff] [blame] | 3965 | send_configure_for_surface(shsurf); |
Jasper St. Pierre | ab2c108 | 2014-04-10 10:41:46 -0700 | [diff] [blame] | 3966 | } |
| 3967 | |
| 3968 | static void |
| 3969 | xdg_surface_unset_maximized(struct wl_client *client, |
| 3970 | struct wl_resource *resource) |
| 3971 | { |
| 3972 | struct shell_surface *shsurf = wl_resource_get_user_data(resource); |
| 3973 | |
| 3974 | shsurf->state_requested = true; |
| 3975 | shsurf->requested_state.maximized = false; |
Jasper St. Pierre | 6458ec3 | 2014-04-11 16:00:31 -0700 | [diff] [blame] | 3976 | send_configure_for_surface(shsurf); |
Jasper St. Pierre | ab2c108 | 2014-04-10 10:41:46 -0700 | [diff] [blame] | 3977 | } |
| 3978 | |
| 3979 | static void |
| 3980 | xdg_surface_set_fullscreen(struct wl_client *client, |
| 3981 | struct wl_resource *resource, |
| 3982 | struct wl_resource *output_resource) |
| 3983 | { |
| 3984 | struct shell_surface *shsurf = wl_resource_get_user_data(resource); |
| 3985 | struct weston_output *output; |
| 3986 | |
| 3987 | shsurf->state_requested = true; |
| 3988 | shsurf->requested_state.fullscreen = true; |
| 3989 | |
| 3990 | if (output_resource) |
| 3991 | output = wl_resource_get_user_data(output_resource); |
| 3992 | else |
| 3993 | output = NULL; |
| 3994 | |
Marek Chalupa | 052917a | 2014-09-02 11:35:12 +0200 | [diff] [blame] | 3995 | /* handle clients launching in fullscreen */ |
| 3996 | if (output == NULL && !weston_surface_is_mapped(shsurf->surface)) { |
| 3997 | /* Set the output to the one that has focus currently. */ |
| 3998 | assert(shsurf->surface); |
| 3999 | output = get_focused_output(shsurf->surface->compositor); |
| 4000 | } |
| 4001 | |
Jasper St. Pierre | 9aa8ce6 | 2014-04-11 16:18:54 -0700 | [diff] [blame] | 4002 | shell_surface_set_output(shsurf, output); |
| 4003 | shsurf->fullscreen_output = shsurf->output; |
Jasper St. Pierre | ab2c108 | 2014-04-10 10:41:46 -0700 | [diff] [blame] | 4004 | |
Jasper St. Pierre | 9aa8ce6 | 2014-04-11 16:18:54 -0700 | [diff] [blame] | 4005 | send_configure_for_surface(shsurf); |
Jasper St. Pierre | ab2c108 | 2014-04-10 10:41:46 -0700 | [diff] [blame] | 4006 | } |
| 4007 | |
| 4008 | static void |
| 4009 | xdg_surface_unset_fullscreen(struct wl_client *client, |
| 4010 | struct wl_resource *resource) |
| 4011 | { |
| 4012 | struct shell_surface *shsurf = wl_resource_get_user_data(resource); |
| 4013 | |
| 4014 | shsurf->state_requested = true; |
| 4015 | shsurf->requested_state.fullscreen = false; |
Jasper St. Pierre | 6458ec3 | 2014-04-11 16:00:31 -0700 | [diff] [blame] | 4016 | send_configure_for_surface(shsurf); |
Jasper St. Pierre | ab2c108 | 2014-04-10 10:41:46 -0700 | [diff] [blame] | 4017 | } |
| 4018 | |
| 4019 | static void |
Manuel Bachmann | 50c87db | 2014-02-26 15:52:13 +0100 | [diff] [blame] | 4020 | xdg_surface_set_minimized(struct wl_client *client, |
| 4021 | struct wl_resource *resource) |
| 4022 | { |
| 4023 | struct shell_surface *shsurf = wl_resource_get_user_data(resource); |
| 4024 | |
| 4025 | if (shsurf->type != SHELL_SURFACE_TOPLEVEL) |
| 4026 | return; |
| 4027 | |
| 4028 | /* apply compositor's own minimization logic (hide) */ |
Manuel Bachmann | dc1c3e4 | 2015-02-16 11:52:13 +0100 | [diff] [blame] | 4029 | set_minimized(shsurf->surface); |
Manuel Bachmann | 50c87db | 2014-02-26 15:52:13 +0100 | [diff] [blame] | 4030 | } |
| 4031 | |
Rafael Antognolli | e2a3455 | 2013-12-03 15:35:45 -0200 | [diff] [blame] | 4032 | static const struct xdg_surface_interface xdg_surface_implementation = { |
| 4033 | xdg_surface_destroy, |
Jasper St. Pierre | c815d62 | 2014-04-10 18:37:54 -0700 | [diff] [blame] | 4034 | xdg_surface_set_parent, |
Rafael Antognolli | e2a3455 | 2013-12-03 15:35:45 -0200 | [diff] [blame] | 4035 | xdg_surface_set_title, |
| 4036 | xdg_surface_set_app_id, |
Jasper St. Pierre | 81ff075 | 2014-03-13 11:04:53 -0400 | [diff] [blame] | 4037 | xdg_surface_show_window_menu, |
Rafael Antognolli | e2a3455 | 2013-12-03 15:35:45 -0200 | [diff] [blame] | 4038 | xdg_surface_move, |
| 4039 | xdg_surface_resize, |
Jasper St. Pierre | ab2c108 | 2014-04-10 10:41:46 -0700 | [diff] [blame] | 4040 | xdg_surface_ack_configure, |
Jasper St. Pierre | ccf48fb | 2014-05-02 10:21:38 -0400 | [diff] [blame] | 4041 | xdg_surface_set_window_geometry, |
Jasper St. Pierre | ab2c108 | 2014-04-10 10:41:46 -0700 | [diff] [blame] | 4042 | xdg_surface_set_maximized, |
| 4043 | xdg_surface_unset_maximized, |
| 4044 | xdg_surface_set_fullscreen, |
| 4045 | xdg_surface_unset_fullscreen, |
| 4046 | xdg_surface_set_minimized, |
Rafael Antognolli | e2a3455 | 2013-12-03 15:35:45 -0200 | [diff] [blame] | 4047 | }; |
| 4048 | |
| 4049 | static void |
| 4050 | xdg_send_configure(struct weston_surface *surface, |
Jasper St. Pierre | ac985be | 2014-04-28 11:19:28 -0400 | [diff] [blame] | 4051 | int32_t width, int32_t height) |
Rafael Antognolli | e2a3455 | 2013-12-03 15:35:45 -0200 | [diff] [blame] | 4052 | { |
| 4053 | struct shell_surface *shsurf = get_shell_surface(surface); |
Jasper St. Pierre | ab2c108 | 2014-04-10 10:41:46 -0700 | [diff] [blame] | 4054 | uint32_t *s; |
| 4055 | struct wl_array states; |
| 4056 | uint32_t serial; |
Rafael Antognolli | e2a3455 | 2013-12-03 15:35:45 -0200 | [diff] [blame] | 4057 | |
U. Artie Eoff | cf5737a | 2014-01-17 10:08:25 -0800 | [diff] [blame] | 4058 | assert(shsurf); |
| 4059 | |
Jasper St. Pierre | ab2c108 | 2014-04-10 10:41:46 -0700 | [diff] [blame] | 4060 | if (!shsurf->resource) |
| 4061 | return; |
| 4062 | |
| 4063 | wl_array_init(&states); |
| 4064 | if (shsurf->requested_state.fullscreen) { |
| 4065 | s = wl_array_add(&states, sizeof *s); |
| 4066 | *s = XDG_SURFACE_STATE_FULLSCREEN; |
| 4067 | } else if (shsurf->requested_state.maximized) { |
| 4068 | s = wl_array_add(&states, sizeof *s); |
| 4069 | *s = XDG_SURFACE_STATE_MAXIMIZED; |
| 4070 | } |
Jasper St. Pierre | 5befdda | 2014-05-06 08:50:47 -0400 | [diff] [blame] | 4071 | if (shsurf->resize_edges != 0) { |
| 4072 | s = wl_array_add(&states, sizeof *s); |
| 4073 | *s = XDG_SURFACE_STATE_RESIZING; |
| 4074 | } |
Jasper St. Pierre | 973d787 | 2014-05-06 08:44:29 -0400 | [diff] [blame] | 4075 | if (shsurf->focus_count > 0) { |
| 4076 | s = wl_array_add(&states, sizeof *s); |
| 4077 | *s = XDG_SURFACE_STATE_ACTIVATED; |
| 4078 | } |
Jasper St. Pierre | ab2c108 | 2014-04-10 10:41:46 -0700 | [diff] [blame] | 4079 | |
| 4080 | serial = wl_display_next_serial(shsurf->surface->compositor->wl_display); |
| 4081 | xdg_surface_send_configure(shsurf->resource, width, height, &states, serial); |
| 4082 | |
| 4083 | wl_array_release(&states); |
Rafael Antognolli | e2a3455 | 2013-12-03 15:35:45 -0200 | [diff] [blame] | 4084 | } |
| 4085 | |
| 4086 | static const struct weston_shell_client xdg_client = { |
| 4087 | xdg_send_configure |
| 4088 | }; |
| 4089 | |
| 4090 | static void |
Jasper St. Pierre | 084aa0b | 2015-02-13 14:02:00 +0800 | [diff] [blame] | 4091 | xdg_shell_destroy(struct wl_client *client, |
| 4092 | struct wl_resource *resource) |
| 4093 | { |
Jonas Ådahl | 49d77d2 | 2015-03-18 16:20:51 +0800 | [diff] [blame] | 4094 | struct shell_client *sc = wl_resource_get_user_data(resource); |
| 4095 | struct wl_resource *shsurf_resource; |
| 4096 | struct shell_surface *shsurf; |
| 4097 | |
| 4098 | wl_resource_for_each(shsurf_resource, &sc->surface_list) { |
| 4099 | shsurf = wl_resource_get_user_data(shsurf_resource); |
| 4100 | if (shsurf->owner_resource == resource) { |
| 4101 | wl_resource_post_error( |
| 4102 | resource, |
| 4103 | XDG_SHELL_ERROR_DEFUNCT_SURFACES, |
| 4104 | "not all child surface objects destroyed"); |
| 4105 | return; |
| 4106 | } |
| 4107 | } |
| 4108 | |
Jasper St. Pierre | 084aa0b | 2015-02-13 14:02:00 +0800 | [diff] [blame] | 4109 | wl_resource_destroy(resource); |
| 4110 | } |
| 4111 | |
| 4112 | static void |
Rafael Antognolli | e2a3455 | 2013-12-03 15:35:45 -0200 | [diff] [blame] | 4113 | xdg_use_unstable_version(struct wl_client *client, |
| 4114 | struct wl_resource *resource, |
| 4115 | int32_t version) |
| 4116 | { |
| 4117 | if (version > 1) { |
| 4118 | wl_resource_post_error(resource, |
| 4119 | 1, |
| 4120 | "xdg-shell:: version not implemented yet."); |
| 4121 | return; |
| 4122 | } |
| 4123 | } |
| 4124 | |
| 4125 | static struct shell_surface * |
Jason Ekstrand | 9e9512f | 2014-04-16 21:12:10 -0500 | [diff] [blame] | 4126 | create_xdg_surface(struct shell_client *owner, void *shell, |
| 4127 | struct weston_surface *surface, |
Rafael Antognolli | e2a3455 | 2013-12-03 15:35:45 -0200 | [diff] [blame] | 4128 | const struct weston_shell_client *client) |
| 4129 | { |
| 4130 | struct shell_surface *shsurf; |
Rafael Antognolli | e2a3455 | 2013-12-03 15:35:45 -0200 | [diff] [blame] | 4131 | |
Jason Ekstrand | 9e9512f | 2014-04-16 21:12:10 -0500 | [diff] [blame] | 4132 | shsurf = create_common_surface(owner, shell, surface, client); |
Pekka Paalanen | e972b27 | 2014-10-01 14:03:56 +0300 | [diff] [blame] | 4133 | if (!shsurf) |
| 4134 | return NULL; |
| 4135 | |
Pekka Paalanen | b502654 | 2014-11-12 15:09:24 +0200 | [diff] [blame] | 4136 | set_type(shsurf, SHELL_SURFACE_TOPLEVEL); |
Rafael Antognolli | e2a3455 | 2013-12-03 15:35:45 -0200 | [diff] [blame] | 4137 | |
| 4138 | return shsurf; |
| 4139 | } |
| 4140 | |
| 4141 | static void |
| 4142 | xdg_get_xdg_surface(struct wl_client *client, |
| 4143 | struct wl_resource *resource, |
| 4144 | uint32_t id, |
| 4145 | struct wl_resource *surface_resource) |
| 4146 | { |
| 4147 | struct weston_surface *surface = |
| 4148 | wl_resource_get_user_data(surface_resource); |
Kristian Høgsberg | 2bff94e | 2014-02-11 12:22:51 -0800 | [diff] [blame] | 4149 | struct shell_client *sc = wl_resource_get_user_data(resource); |
| 4150 | struct desktop_shell *shell = sc->shell; |
Rafael Antognolli | e2a3455 | 2013-12-03 15:35:45 -0200 | [diff] [blame] | 4151 | struct shell_surface *shsurf; |
| 4152 | |
Jonas Ådahl | bf48e21 | 2015-02-06 10:15:28 +0800 | [diff] [blame] | 4153 | shsurf = get_shell_surface(surface); |
| 4154 | if (shsurf && shell_surface_is_xdg_surface(shsurf)) { |
| 4155 | wl_resource_post_error(resource, XDG_SHELL_ERROR_ROLE, |
| 4156 | "This wl_surface is already an " |
| 4157 | "xdg_surface"); |
| 4158 | return; |
| 4159 | } |
| 4160 | |
Pekka Paalanen | 50b6747 | 2014-10-01 15:02:41 +0300 | [diff] [blame] | 4161 | if (weston_surface_set_role(surface, "xdg_surface", |
| 4162 | resource, XDG_SHELL_ERROR_ROLE) < 0) |
Rafael Antognolli | e2a3455 | 2013-12-03 15:35:45 -0200 | [diff] [blame] | 4163 | return; |
Rafael Antognolli | e2a3455 | 2013-12-03 15:35:45 -0200 | [diff] [blame] | 4164 | |
Jason Ekstrand | 9e9512f | 2014-04-16 21:12:10 -0500 | [diff] [blame] | 4165 | shsurf = create_xdg_surface(sc, shell, surface, &xdg_client); |
Rafael Antognolli | e2a3455 | 2013-12-03 15:35:45 -0200 | [diff] [blame] | 4166 | if (!shsurf) { |
Pekka Paalanen | 50b6747 | 2014-10-01 15:02:41 +0300 | [diff] [blame] | 4167 | wl_resource_post_no_memory(surface_resource); |
Rafael Antognolli | e2a3455 | 2013-12-03 15:35:45 -0200 | [diff] [blame] | 4168 | return; |
| 4169 | } |
| 4170 | |
| 4171 | shsurf->resource = |
| 4172 | wl_resource_create(client, |
| 4173 | &xdg_surface_interface, 1, id); |
| 4174 | wl_resource_set_implementation(shsurf->resource, |
| 4175 | &xdg_surface_implementation, |
| 4176 | shsurf, shell_destroy_shell_surface); |
Jonas Ådahl | 49d77d2 | 2015-03-18 16:20:51 +0800 | [diff] [blame] | 4177 | shsurf->owner_resource = resource; |
| 4178 | wl_list_insert(&sc->surface_list, |
| 4179 | wl_resource_get_link(shsurf->resource)); |
Rafael Antognolli | e2a3455 | 2013-12-03 15:35:45 -0200 | [diff] [blame] | 4180 | } |
| 4181 | |
| 4182 | static bool |
| 4183 | shell_surface_is_xdg_surface(struct shell_surface *shsurf) |
| 4184 | { |
Kristian Høgsberg | 0b7d995 | 2014-02-03 15:50:38 -0800 | [diff] [blame] | 4185 | return shsurf->resource && |
| 4186 | wl_resource_instance_of(shsurf->resource, |
| 4187 | &xdg_surface_interface, |
| 4188 | &xdg_surface_implementation); |
Rafael Antognolli | e2a3455 | 2013-12-03 15:35:45 -0200 | [diff] [blame] | 4189 | } |
| 4190 | |
| 4191 | /* xdg-popup implementation */ |
| 4192 | |
| 4193 | static void |
| 4194 | xdg_popup_destroy(struct wl_client *client, |
| 4195 | struct wl_resource *resource) |
| 4196 | { |
| 4197 | wl_resource_destroy(resource); |
| 4198 | } |
| 4199 | |
Rafael Antognolli | e2a3455 | 2013-12-03 15:35:45 -0200 | [diff] [blame] | 4200 | static const struct xdg_popup_interface xdg_popup_implementation = { |
| 4201 | xdg_popup_destroy, |
Rafael Antognolli | e2a3455 | 2013-12-03 15:35:45 -0200 | [diff] [blame] | 4202 | }; |
| 4203 | |
| 4204 | static void |
| 4205 | xdg_popup_send_configure(struct weston_surface *surface, |
Jasper St. Pierre | ac985be | 2014-04-28 11:19:28 -0400 | [diff] [blame] | 4206 | int32_t width, int32_t height) |
Rafael Antognolli | e2a3455 | 2013-12-03 15:35:45 -0200 | [diff] [blame] | 4207 | { |
| 4208 | } |
| 4209 | |
| 4210 | static const struct weston_shell_client xdg_popup_client = { |
| 4211 | xdg_popup_send_configure |
| 4212 | }; |
| 4213 | |
| 4214 | static struct shell_surface * |
Jason Ekstrand | 9e9512f | 2014-04-16 21:12:10 -0500 | [diff] [blame] | 4215 | create_xdg_popup(struct shell_client *owner, void *shell, |
| 4216 | struct weston_surface *surface, |
Rafael Antognolli | e2a3455 | 2013-12-03 15:35:45 -0200 | [diff] [blame] | 4217 | const struct weston_shell_client *client, |
| 4218 | struct weston_surface *parent, |
| 4219 | struct shell_seat *seat, |
| 4220 | uint32_t serial, |
| 4221 | int32_t x, int32_t y) |
| 4222 | { |
Jonas Ådahl | ee45a55 | 2015-03-18 16:37:47 +0800 | [diff] [blame] | 4223 | struct shell_surface *shsurf; |
Jonas Ådahl | 24185e2 | 2015-02-27 18:37:41 +0800 | [diff] [blame] | 4224 | |
Jason Ekstrand | 9e9512f | 2014-04-16 21:12:10 -0500 | [diff] [blame] | 4225 | shsurf = create_common_surface(owner, shell, surface, client); |
Pekka Paalanen | e972b27 | 2014-10-01 14:03:56 +0300 | [diff] [blame] | 4226 | if (!shsurf) |
| 4227 | return NULL; |
| 4228 | |
Pekka Paalanen | b502654 | 2014-11-12 15:09:24 +0200 | [diff] [blame] | 4229 | set_type(shsurf, SHELL_SURFACE_POPUP); |
Rafael Antognolli | e2a3455 | 2013-12-03 15:35:45 -0200 | [diff] [blame] | 4230 | shsurf->popup.shseat = seat; |
| 4231 | shsurf->popup.serial = serial; |
| 4232 | shsurf->popup.x = x; |
| 4233 | shsurf->popup.y = y; |
| 4234 | shell_surface_set_parent(shsurf, parent); |
| 4235 | |
| 4236 | return shsurf; |
| 4237 | } |
| 4238 | |
| 4239 | static void |
| 4240 | xdg_get_xdg_popup(struct wl_client *client, |
| 4241 | struct wl_resource *resource, |
| 4242 | uint32_t id, |
| 4243 | struct wl_resource *surface_resource, |
| 4244 | struct wl_resource *parent_resource, |
| 4245 | struct wl_resource *seat_resource, |
| 4246 | uint32_t serial, |
Jasper St. Pierre | 14f330c | 2015-02-13 14:01:57 +0800 | [diff] [blame] | 4247 | int32_t x, int32_t y) |
Rafael Antognolli | e2a3455 | 2013-12-03 15:35:45 -0200 | [diff] [blame] | 4248 | { |
| 4249 | struct weston_surface *surface = |
| 4250 | wl_resource_get_user_data(surface_resource); |
Kristian Høgsberg | 2bff94e | 2014-02-11 12:22:51 -0800 | [diff] [blame] | 4251 | struct shell_client *sc = wl_resource_get_user_data(resource); |
| 4252 | struct desktop_shell *shell = sc->shell; |
Rafael Antognolli | e2a3455 | 2013-12-03 15:35:45 -0200 | [diff] [blame] | 4253 | struct shell_surface *shsurf; |
Jonas Ådahl | ee45a55 | 2015-03-18 16:37:47 +0800 | [diff] [blame] | 4254 | struct shell_surface *parent_shsurf; |
Rafael Antognolli | e2a3455 | 2013-12-03 15:35:45 -0200 | [diff] [blame] | 4255 | struct weston_surface *parent; |
| 4256 | struct shell_seat *seat; |
| 4257 | |
Jonas Ådahl | bf48e21 | 2015-02-06 10:15:28 +0800 | [diff] [blame] | 4258 | shsurf = get_shell_surface(surface); |
| 4259 | if (shsurf && shell_surface_is_xdg_popup(shsurf)) { |
| 4260 | wl_resource_post_error(resource, XDG_SHELL_ERROR_ROLE, |
| 4261 | "This wl_surface is already an " |
| 4262 | "xdg_popup"); |
| 4263 | return; |
| 4264 | } |
| 4265 | |
Pekka Paalanen | 50b6747 | 2014-10-01 15:02:41 +0300 | [diff] [blame] | 4266 | if (weston_surface_set_role(surface, "xdg_popup", |
| 4267 | resource, XDG_SHELL_ERROR_ROLE) < 0) |
Rafael Antognolli | e2a3455 | 2013-12-03 15:35:45 -0200 | [diff] [blame] | 4268 | return; |
Rafael Antognolli | e2a3455 | 2013-12-03 15:35:45 -0200 | [diff] [blame] | 4269 | |
| 4270 | if (!parent_resource) { |
| 4271 | wl_resource_post_error(surface_resource, |
| 4272 | WL_DISPLAY_ERROR_INVALID_OBJECT, |
| 4273 | "xdg_shell::get_xdg_popup requires a parent shell surface"); |
Jasper St. Pierre | 666bc92 | 2014-08-07 16:43:13 -0400 | [diff] [blame] | 4274 | return; |
Rafael Antognolli | e2a3455 | 2013-12-03 15:35:45 -0200 | [diff] [blame] | 4275 | } |
| 4276 | |
| 4277 | parent = wl_resource_get_user_data(parent_resource); |
| 4278 | seat = get_shell_seat(wl_resource_get_user_data(seat_resource));; |
| 4279 | |
Jonas Ådahl | ee45a55 | 2015-03-18 16:37:47 +0800 | [diff] [blame] | 4280 | /* Verify that we are creating the top most popup when mapping, |
| 4281 | * as it's not until then we know whether it was mapped as most |
| 4282 | * top level or not. */ |
| 4283 | |
| 4284 | parent_shsurf = get_shell_surface(parent); |
| 4285 | if (!shell_surface_is_xdg_popup(parent_shsurf) && |
| 4286 | !shell_surface_is_xdg_surface(parent_shsurf)) { |
| 4287 | wl_resource_post_error(resource, |
| 4288 | XDG_SHELL_ERROR_INVALID_POPUP_PARENT, |
| 4289 | "xdg_popup parent was invalid"); |
| 4290 | return; |
| 4291 | } |
| 4292 | |
Jason Ekstrand | 9e9512f | 2014-04-16 21:12:10 -0500 | [diff] [blame] | 4293 | shsurf = create_xdg_popup(sc, shell, surface, &xdg_popup_client, |
Rafael Antognolli | e2a3455 | 2013-12-03 15:35:45 -0200 | [diff] [blame] | 4294 | parent, seat, serial, x, y); |
| 4295 | if (!shsurf) { |
Pekka Paalanen | 50b6747 | 2014-10-01 15:02:41 +0300 | [diff] [blame] | 4296 | wl_resource_post_no_memory(surface_resource); |
Rafael Antognolli | e2a3455 | 2013-12-03 15:35:45 -0200 | [diff] [blame] | 4297 | return; |
| 4298 | } |
| 4299 | |
| 4300 | shsurf->resource = |
| 4301 | wl_resource_create(client, |
| 4302 | &xdg_popup_interface, 1, id); |
| 4303 | wl_resource_set_implementation(shsurf->resource, |
| 4304 | &xdg_popup_implementation, |
| 4305 | shsurf, shell_destroy_shell_surface); |
Jonas Ådahl | 49d77d2 | 2015-03-18 16:20:51 +0800 | [diff] [blame] | 4306 | shsurf->owner_resource = resource; |
| 4307 | wl_list_insert(&sc->surface_list, |
| 4308 | wl_resource_get_link(shsurf->resource)); |
Rafael Antognolli | e2a3455 | 2013-12-03 15:35:45 -0200 | [diff] [blame] | 4309 | } |
| 4310 | |
Kristian Høgsberg | 2bff94e | 2014-02-11 12:22:51 -0800 | [diff] [blame] | 4311 | static void |
| 4312 | xdg_pong(struct wl_client *client, |
| 4313 | struct wl_resource *resource, uint32_t serial) |
| 4314 | { |
| 4315 | struct shell_client *sc = wl_resource_get_user_data(resource); |
Kristian Høgsberg | 2bff94e | 2014-02-11 12:22:51 -0800 | [diff] [blame] | 4316 | |
Kristian Høgsberg | dd62aba | 2014-02-12 09:56:19 -0800 | [diff] [blame] | 4317 | shell_client_pong(sc, serial); |
Kristian Høgsberg | 2bff94e | 2014-02-11 12:22:51 -0800 | [diff] [blame] | 4318 | } |
| 4319 | |
Rafael Antognolli | e2a3455 | 2013-12-03 15:35:45 -0200 | [diff] [blame] | 4320 | static bool |
| 4321 | shell_surface_is_xdg_popup(struct shell_surface *shsurf) |
| 4322 | { |
| 4323 | return wl_resource_instance_of(shsurf->resource, |
| 4324 | &xdg_popup_interface, |
| 4325 | &xdg_popup_implementation); |
| 4326 | } |
| 4327 | |
| 4328 | static const struct xdg_shell_interface xdg_implementation = { |
Jasper St. Pierre | 084aa0b | 2015-02-13 14:02:00 +0800 | [diff] [blame] | 4329 | xdg_shell_destroy, |
Rafael Antognolli | e2a3455 | 2013-12-03 15:35:45 -0200 | [diff] [blame] | 4330 | xdg_use_unstable_version, |
| 4331 | xdg_get_xdg_surface, |
Kristian Høgsberg | 2bff94e | 2014-02-11 12:22:51 -0800 | [diff] [blame] | 4332 | xdg_get_xdg_popup, |
| 4333 | xdg_pong |
Rafael Antognolli | e2a3455 | 2013-12-03 15:35:45 -0200 | [diff] [blame] | 4334 | }; |
| 4335 | |
| 4336 | static int |
| 4337 | xdg_shell_unversioned_dispatch(const void *implementation, |
| 4338 | void *_target, uint32_t opcode, |
| 4339 | const struct wl_message *message, |
| 4340 | union wl_argument *args) |
| 4341 | { |
| 4342 | struct wl_resource *resource = _target; |
Kristian Høgsberg | 2bff94e | 2014-02-11 12:22:51 -0800 | [diff] [blame] | 4343 | struct shell_client *sc = wl_resource_get_user_data(resource); |
Rafael Antognolli | e2a3455 | 2013-12-03 15:35:45 -0200 | [diff] [blame] | 4344 | |
Jasper St. Pierre | 084aa0b | 2015-02-13 14:02:00 +0800 | [diff] [blame] | 4345 | if (opcode != 1 /* XDG_SHELL_USE_UNSTABLE_VERSION */) { |
Rafael Antognolli | e2a3455 | 2013-12-03 15:35:45 -0200 | [diff] [blame] | 4346 | wl_resource_post_error(resource, |
| 4347 | WL_DISPLAY_ERROR_INVALID_OBJECT, |
| 4348 | "must call use_unstable_version first"); |
| 4349 | return 0; |
| 4350 | } |
| 4351 | |
Jasper St. Pierre | 5ba1e1d | 2015-02-13 14:02:02 +0800 | [diff] [blame] | 4352 | #define XDG_SERVER_VERSION 5 |
Rafael Antognolli | e2a3455 | 2013-12-03 15:35:45 -0200 | [diff] [blame] | 4353 | |
Kristian Høgsberg | 8d344a0 | 2013-12-08 22:27:11 -0800 | [diff] [blame] | 4354 | static_assert(XDG_SERVER_VERSION == XDG_SHELL_VERSION_CURRENT, |
| 4355 | "shell implementation doesn't match protocol version"); |
| 4356 | |
Rafael Antognolli | e2a3455 | 2013-12-03 15:35:45 -0200 | [diff] [blame] | 4357 | if (args[0].i != XDG_SERVER_VERSION) { |
| 4358 | wl_resource_post_error(resource, |
| 4359 | WL_DISPLAY_ERROR_INVALID_OBJECT, |
| 4360 | "incompatible version, server is %d " |
| 4361 | "client wants %d", |
| 4362 | XDG_SERVER_VERSION, args[0].i); |
| 4363 | return 0; |
| 4364 | } |
| 4365 | |
| 4366 | wl_resource_set_implementation(resource, &xdg_implementation, |
Kristian Høgsberg | 2bff94e | 2014-02-11 12:22:51 -0800 | [diff] [blame] | 4367 | sc, NULL); |
Rafael Antognolli | e2a3455 | 2013-12-03 15:35:45 -0200 | [diff] [blame] | 4368 | |
| 4369 | return 1; |
| 4370 | } |
| 4371 | |
| 4372 | /* end of xdg-shell implementation */ |
| 4373 | /***********************************/ |
| 4374 | |
Kristian Høgsberg | 0793756 | 2011-04-12 17:25:42 -0400 | [diff] [blame] | 4375 | static void |
Ander Conselvan de Oliveira | 859e885 | 2013-02-21 18:35:21 +0200 | [diff] [blame] | 4376 | shell_fade(struct desktop_shell *shell, enum fade_type type); |
| 4377 | |
Pekka Paalanen | 77346a6 | 2011-11-30 16:26:35 +0200 | [diff] [blame] | 4378 | static void |
Jason Ekstrand | 918f2dd | 2013-12-02 21:01:53 -0600 | [diff] [blame] | 4379 | configure_static_view(struct weston_view *ev, struct weston_layer *layer) |
Kristian Høgsberg | 962342c | 2012-06-26 16:29:50 -0400 | [diff] [blame] | 4380 | { |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 4381 | struct weston_view *v, *next; |
Kristian Høgsberg | 962342c | 2012-06-26 16:29:50 -0400 | [diff] [blame] | 4382 | |
Giulio Camuffo | 412e6a5 | 2014-07-09 22:12:56 +0300 | [diff] [blame] | 4383 | 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] | 4384 | if (v->output == ev->output && v != ev) { |
| 4385 | weston_view_unmap(v); |
| 4386 | v->surface->configure = NULL; |
Pekka Paalanen | 8274d90 | 2014-08-06 19:36:51 +0300 | [diff] [blame] | 4387 | weston_surface_set_label_func(v->surface, NULL); |
Kristian Høgsberg | 962342c | 2012-06-26 16:29:50 -0400 | [diff] [blame] | 4388 | } |
| 4389 | } |
| 4390 | |
Jason Ekstrand | 918f2dd | 2013-12-02 21:01:53 -0600 | [diff] [blame] | 4391 | weston_view_set_position(ev, ev->output->x, ev->output->y); |
Kristian Høgsberg | 962342c | 2012-06-26 16:29:50 -0400 | [diff] [blame] | 4392 | |
Giulio Camuffo | 412e6a5 | 2014-07-09 22:12:56 +0300 | [diff] [blame] | 4393 | if (wl_list_empty(&ev->layer_link.link)) { |
| 4394 | weston_layer_entry_insert(&layer->view_list, &ev->layer_link); |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 4395 | weston_compositor_schedule_repaint(ev->surface->compositor); |
Kristian Høgsberg | 962342c | 2012-06-26 16:29:50 -0400 | [diff] [blame] | 4396 | } |
| 4397 | } |
| 4398 | |
Pekka Paalanen | 8274d90 | 2014-08-06 19:36:51 +0300 | [diff] [blame] | 4399 | static int |
| 4400 | background_get_label(struct weston_surface *surface, char *buf, size_t len) |
| 4401 | { |
| 4402 | return snprintf(buf, len, "background for output %s", |
| 4403 | surface->output->name); |
| 4404 | } |
| 4405 | |
Kristian Høgsberg | 962342c | 2012-06-26 16:29:50 -0400 | [diff] [blame] | 4406 | static void |
Jason Ekstrand | 918f2dd | 2013-12-02 21:01:53 -0600 | [diff] [blame] | 4407 | 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] | 4408 | { |
Giulio Camuffo | 7fe01b1 | 2013-03-28 18:02:42 +0100 | [diff] [blame] | 4409 | struct desktop_shell *shell = es->configure_private; |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 4410 | struct weston_view *view; |
Kristian Høgsberg | af7b1ff | 2012-06-26 21:19:23 -0400 | [diff] [blame] | 4411 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 4412 | view = container_of(es->views.next, struct weston_view, surface_link); |
| 4413 | |
Jason Ekstrand | 918f2dd | 2013-12-02 21:01:53 -0600 | [diff] [blame] | 4414 | configure_static_view(view, &shell->background_layer); |
Kristian Høgsberg | af7b1ff | 2012-06-26 21:19:23 -0400 | [diff] [blame] | 4415 | } |
| 4416 | |
| 4417 | static void |
Kristian Høgsberg | 7584062 | 2011-09-06 13:48:16 -0400 | [diff] [blame] | 4418 | desktop_shell_set_background(struct wl_client *client, |
| 4419 | struct wl_resource *resource, |
Benjamin Franzke | d0f79ab | 2011-11-22 12:43:52 +0100 | [diff] [blame] | 4420 | struct wl_resource *output_resource, |
Kristian Høgsberg | 7584062 | 2011-09-06 13:48:16 -0400 | [diff] [blame] | 4421 | struct wl_resource *surface_resource) |
| 4422 | { |
Jason Ekstrand | 651f00e | 2013-06-14 10:07:54 -0500 | [diff] [blame] | 4423 | struct desktop_shell *shell = wl_resource_get_user_data(resource); |
Jason Ekstrand | 0f2ef7e | 2013-06-14 10:07:53 -0500 | [diff] [blame] | 4424 | struct weston_surface *surface = |
| 4425 | wl_resource_get_user_data(surface_resource); |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 4426 | struct weston_view *view, *next; |
Kristian Høgsberg | 7584062 | 2011-09-06 13:48:16 -0400 | [diff] [blame] | 4427 | |
Kristian Høgsberg | 962342c | 2012-06-26 16:29:50 -0400 | [diff] [blame] | 4428 | if (surface->configure) { |
| 4429 | wl_resource_post_error(surface_resource, |
| 4430 | WL_DISPLAY_ERROR_INVALID_OBJECT, |
| 4431 | "surface role already assigned"); |
| 4432 | return; |
| 4433 | } |
Benjamin Franzke | d0f79ab | 2011-11-22 12:43:52 +0100 | [diff] [blame] | 4434 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 4435 | wl_list_for_each_safe(view, next, &surface->views, surface_link) |
| 4436 | weston_view_destroy(view); |
| 4437 | view = weston_view_create(surface); |
| 4438 | |
Kristian Høgsberg | 962342c | 2012-06-26 16:29:50 -0400 | [diff] [blame] | 4439 | surface->configure = background_configure; |
Giulio Camuffo | 7fe01b1 | 2013-03-28 18:02:42 +0100 | [diff] [blame] | 4440 | surface->configure_private = shell; |
Pekka Paalanen | 8274d90 | 2014-08-06 19:36:51 +0300 | [diff] [blame] | 4441 | weston_surface_set_label_func(surface, background_get_label); |
Jason Ekstrand | a0d2dde | 2013-06-14 10:08:01 -0500 | [diff] [blame] | 4442 | surface->output = wl_resource_get_user_data(output_resource); |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 4443 | view->output = surface->output; |
Kristian Høgsberg | eae5de7 | 2012-04-11 22:42:15 -0400 | [diff] [blame] | 4444 | desktop_shell_send_configure(resource, 0, |
Kristian Høgsberg | 0b5cd0c | 2012-03-04 21:57:37 -0500 | [diff] [blame] | 4445 | surface_resource, |
Scott Moreau | 1bad5db | 2012-08-18 01:04:05 -0600 | [diff] [blame] | 4446 | surface->output->width, |
| 4447 | surface->output->height); |
Kristian Høgsberg | 7584062 | 2011-09-06 13:48:16 -0400 | [diff] [blame] | 4448 | } |
| 4449 | |
Pekka Paalanen | 8274d90 | 2014-08-06 19:36:51 +0300 | [diff] [blame] | 4450 | static int |
| 4451 | panel_get_label(struct weston_surface *surface, char *buf, size_t len) |
| 4452 | { |
| 4453 | return snprintf(buf, len, "panel for output %s", |
| 4454 | surface->output->name); |
| 4455 | } |
| 4456 | |
Kristian Høgsberg | 7584062 | 2011-09-06 13:48:16 -0400 | [diff] [blame] | 4457 | static void |
Jason Ekstrand | 918f2dd | 2013-12-02 21:01:53 -0600 | [diff] [blame] | 4458 | 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] | 4459 | { |
Giulio Camuffo | 7fe01b1 | 2013-03-28 18:02:42 +0100 | [diff] [blame] | 4460 | struct desktop_shell *shell = es->configure_private; |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 4461 | struct weston_view *view; |
Kristian Høgsberg | af7b1ff | 2012-06-26 21:19:23 -0400 | [diff] [blame] | 4462 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 4463 | view = container_of(es->views.next, struct weston_view, surface_link); |
| 4464 | |
Jason Ekstrand | 918f2dd | 2013-12-02 21:01:53 -0600 | [diff] [blame] | 4465 | configure_static_view(view, &shell->panel_layer); |
Kristian Høgsberg | af7b1ff | 2012-06-26 21:19:23 -0400 | [diff] [blame] | 4466 | } |
| 4467 | |
| 4468 | static void |
Kristian Høgsberg | 7584062 | 2011-09-06 13:48:16 -0400 | [diff] [blame] | 4469 | desktop_shell_set_panel(struct wl_client *client, |
| 4470 | struct wl_resource *resource, |
Benjamin Franzke | d0f79ab | 2011-11-22 12:43:52 +0100 | [diff] [blame] | 4471 | struct wl_resource *output_resource, |
Kristian Høgsberg | 7584062 | 2011-09-06 13:48:16 -0400 | [diff] [blame] | 4472 | struct wl_resource *surface_resource) |
| 4473 | { |
Jason Ekstrand | 651f00e | 2013-06-14 10:07:54 -0500 | [diff] [blame] | 4474 | struct desktop_shell *shell = wl_resource_get_user_data(resource); |
Jason Ekstrand | 0f2ef7e | 2013-06-14 10:07:53 -0500 | [diff] [blame] | 4475 | struct weston_surface *surface = |
| 4476 | wl_resource_get_user_data(surface_resource); |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 4477 | struct weston_view *view, *next; |
Kristian Høgsberg | 7584062 | 2011-09-06 13:48:16 -0400 | [diff] [blame] | 4478 | |
Kristian Høgsberg | af7b1ff | 2012-06-26 21:19:23 -0400 | [diff] [blame] | 4479 | if (surface->configure) { |
| 4480 | wl_resource_post_error(surface_resource, |
| 4481 | WL_DISPLAY_ERROR_INVALID_OBJECT, |
| 4482 | "surface role already assigned"); |
| 4483 | return; |
| 4484 | } |
Benjamin Franzke | d0f79ab | 2011-11-22 12:43:52 +0100 | [diff] [blame] | 4485 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 4486 | wl_list_for_each_safe(view, next, &surface->views, surface_link) |
| 4487 | weston_view_destroy(view); |
| 4488 | view = weston_view_create(surface); |
| 4489 | |
Kristian Høgsberg | af7b1ff | 2012-06-26 21:19:23 -0400 | [diff] [blame] | 4490 | surface->configure = panel_configure; |
Giulio Camuffo | 7fe01b1 | 2013-03-28 18:02:42 +0100 | [diff] [blame] | 4491 | surface->configure_private = shell; |
Pekka Paalanen | 8274d90 | 2014-08-06 19:36:51 +0300 | [diff] [blame] | 4492 | weston_surface_set_label_func(surface, panel_get_label); |
Jason Ekstrand | a0d2dde | 2013-06-14 10:08:01 -0500 | [diff] [blame] | 4493 | surface->output = wl_resource_get_user_data(output_resource); |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 4494 | view->output = surface->output; |
Kristian Høgsberg | eae5de7 | 2012-04-11 22:42:15 -0400 | [diff] [blame] | 4495 | desktop_shell_send_configure(resource, 0, |
Kristian Høgsberg | af7b1ff | 2012-06-26 21:19:23 -0400 | [diff] [blame] | 4496 | surface_resource, |
Scott Moreau | 1bad5db | 2012-08-18 01:04:05 -0600 | [diff] [blame] | 4497 | surface->output->width, |
| 4498 | surface->output->height); |
Kristian Høgsberg | 7584062 | 2011-09-06 13:48:16 -0400 | [diff] [blame] | 4499 | } |
| 4500 | |
Pekka Paalanen | 8274d90 | 2014-08-06 19:36:51 +0300 | [diff] [blame] | 4501 | static int |
| 4502 | lock_surface_get_label(struct weston_surface *surface, char *buf, size_t len) |
| 4503 | { |
| 4504 | return snprintf(buf, len, "lock window"); |
| 4505 | } |
| 4506 | |
Pekka Paalanen | 9ef3e01 | 2011-11-15 13:34:48 +0200 | [diff] [blame] | 4507 | static void |
Jason Ekstrand | 918f2dd | 2013-12-02 21:01:53 -0600 | [diff] [blame] | 4508 | 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] | 4509 | { |
Giulio Camuffo | 7fe01b1 | 2013-03-28 18:02:42 +0100 | [diff] [blame] | 4510 | struct desktop_shell *shell = surface->configure_private; |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 4511 | struct weston_view *view; |
| 4512 | |
| 4513 | view = container_of(surface->views.next, struct weston_view, surface_link); |
Kristian Høgsberg | 730c94d | 2012-06-26 21:44:35 -0400 | [diff] [blame] | 4514 | |
Jason Ekstrand | 918f2dd | 2013-12-02 21:01:53 -0600 | [diff] [blame] | 4515 | if (surface->width == 0) |
Giulio Camuffo | 184df50 | 2013-02-21 11:29:21 +0100 | [diff] [blame] | 4516 | return; |
| 4517 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 4518 | center_on_output(view, get_default_output(shell->compositor)); |
Kristian Høgsberg | 730c94d | 2012-06-26 21:44:35 -0400 | [diff] [blame] | 4519 | |
| 4520 | if (!weston_surface_is_mapped(surface)) { |
Giulio Camuffo | 412e6a5 | 2014-07-09 22:12:56 +0300 | [diff] [blame] | 4521 | weston_layer_entry_insert(&shell->lock_layer.view_list, |
| 4522 | &view->layer_link); |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 4523 | weston_view_update_transform(view); |
Ander Conselvan de Oliveira | 87524b6 | 2013-02-21 18:35:22 +0200 | [diff] [blame] | 4524 | shell_fade(shell, FADE_IN); |
Kristian Høgsberg | 730c94d | 2012-06-26 21:44:35 -0400 | [diff] [blame] | 4525 | } |
| 4526 | } |
| 4527 | |
| 4528 | static void |
Kristian Høgsberg | 27e3052 | 2012-04-11 23:18:23 -0400 | [diff] [blame] | 4529 | handle_lock_surface_destroy(struct wl_listener *listener, void *data) |
Kristian Høgsberg | 1ec0c31 | 2011-11-15 16:39:55 -0500 | [diff] [blame] | 4530 | { |
Tiago Vignatti | be14326 | 2012-04-16 17:31:41 +0300 | [diff] [blame] | 4531 | struct desktop_shell *shell = |
| 4532 | container_of(listener, struct desktop_shell, lock_surface_listener); |
Kristian Høgsberg | 1ec0c31 | 2011-11-15 16:39:55 -0500 | [diff] [blame] | 4533 | |
Martin Minarik | 6d11836 | 2012-06-07 18:01:59 +0200 | [diff] [blame] | 4534 | weston_log("lock surface gone\n"); |
Kristian Høgsberg | 1ec0c31 | 2011-11-15 16:39:55 -0500 | [diff] [blame] | 4535 | shell->lock_surface = NULL; |
| 4536 | } |
| 4537 | |
| 4538 | static void |
Pekka Paalanen | 9ef3e01 | 2011-11-15 13:34:48 +0200 | [diff] [blame] | 4539 | desktop_shell_set_lock_surface(struct wl_client *client, |
| 4540 | struct wl_resource *resource, |
| 4541 | struct wl_resource *surface_resource) |
| 4542 | { |
Jason Ekstrand | 651f00e | 2013-06-14 10:07:54 -0500 | [diff] [blame] | 4543 | struct desktop_shell *shell = wl_resource_get_user_data(resource); |
Jason Ekstrand | 0f2ef7e | 2013-06-14 10:07:53 -0500 | [diff] [blame] | 4544 | struct weston_surface *surface = |
| 4545 | wl_resource_get_user_data(surface_resource); |
Pekka Paalanen | 9826223 | 2011-12-01 10:42:22 +0200 | [diff] [blame] | 4546 | |
Pekka Paalanen | f0fc70d | 2011-11-15 13:34:54 +0200 | [diff] [blame] | 4547 | shell->prepare_event_sent = false; |
Kristian Høgsberg | af867cc | 2011-11-15 13:34:49 +0200 | [diff] [blame] | 4548 | |
Pekka Paalanen | f0fc70d | 2011-11-15 13:34:54 +0200 | [diff] [blame] | 4549 | if (!shell->locked) |
| 4550 | return; |
| 4551 | |
Pekka Paalanen | 9826223 | 2011-12-01 10:42:22 +0200 | [diff] [blame] | 4552 | shell->lock_surface = surface; |
Pekka Paalanen | f0fc70d | 2011-11-15 13:34:54 +0200 | [diff] [blame] | 4553 | |
Kristian Høgsberg | 27e3052 | 2012-04-11 23:18:23 -0400 | [diff] [blame] | 4554 | shell->lock_surface_listener.notify = handle_lock_surface_destroy; |
Jason Ekstrand | 651f00e | 2013-06-14 10:07:54 -0500 | [diff] [blame] | 4555 | wl_signal_add(&surface->destroy_signal, |
Kristian Høgsberg | 27e3052 | 2012-04-11 23:18:23 -0400 | [diff] [blame] | 4556 | &shell->lock_surface_listener); |
Pekka Paalanen | 57da4a8 | 2011-11-23 16:42:16 +0200 | [diff] [blame] | 4557 | |
Kristian Høgsberg | aa2ee8b | 2013-10-30 15:49:45 -0700 | [diff] [blame] | 4558 | weston_view_create(surface); |
Kristian Høgsberg | 730c94d | 2012-06-26 21:44:35 -0400 | [diff] [blame] | 4559 | surface->configure = lock_surface_configure; |
Giulio Camuffo | 7fe01b1 | 2013-03-28 18:02:42 +0100 | [diff] [blame] | 4560 | surface->configure_private = shell; |
Pekka Paalanen | 8274d90 | 2014-08-06 19:36:51 +0300 | [diff] [blame] | 4561 | weston_surface_set_label_func(surface, lock_surface_get_label); |
Pekka Paalanen | f0fc70d | 2011-11-15 13:34:54 +0200 | [diff] [blame] | 4562 | } |
| 4563 | |
| 4564 | static void |
Tiago Vignatti | be14326 | 2012-04-16 17:31:41 +0300 | [diff] [blame] | 4565 | resume_desktop(struct desktop_shell *shell) |
Pekka Paalanen | f0fc70d | 2011-11-15 13:34:54 +0200 | [diff] [blame] | 4566 | { |
Kristian Høgsberg | 4476aaf | 2012-06-25 14:03:13 -0400 | [diff] [blame] | 4567 | struct workspace *ws = get_current_workspace(shell); |
Pekka Paalanen | 77346a6 | 2011-11-30 16:26:35 +0200 | [diff] [blame] | 4568 | |
Kristian Høgsberg | 3be2ce9 | 2012-02-29 12:42:35 -0500 | [diff] [blame] | 4569 | wl_list_remove(&shell->lock_layer.link); |
Philipp Brüschweiler | 711fda8 | 2012-08-09 18:50:43 +0200 | [diff] [blame] | 4570 | if (shell->showing_input_panels) { |
Manuel Bachmann | 805d2f5 | 2014-03-05 12:21:34 +0100 | [diff] [blame] | 4571 | wl_list_insert(&shell->compositor->cursor_layer.link, |
Philipp Brüschweiler | 711fda8 | 2012-08-09 18:50:43 +0200 | [diff] [blame] | 4572 | &shell->input_panel_layer.link); |
| 4573 | wl_list_insert(&shell->input_panel_layer.link, |
Manuel Bachmann | 805d2f5 | 2014-03-05 12:21:34 +0100 | [diff] [blame] | 4574 | &shell->fullscreen_layer.link); |
Philipp Brüschweiler | 711fda8 | 2012-08-09 18:50:43 +0200 | [diff] [blame] | 4575 | } else { |
Manuel Bachmann | 805d2f5 | 2014-03-05 12:21:34 +0100 | [diff] [blame] | 4576 | wl_list_insert(&shell->compositor->cursor_layer.link, |
| 4577 | &shell->fullscreen_layer.link); |
Philipp Brüschweiler | 711fda8 | 2012-08-09 18:50:43 +0200 | [diff] [blame] | 4578 | } |
Manuel Bachmann | 805d2f5 | 2014-03-05 12:21:34 +0100 | [diff] [blame] | 4579 | wl_list_insert(&shell->fullscreen_layer.link, |
| 4580 | &shell->panel_layer.link); |
| 4581 | wl_list_insert(&shell->panel_layer.link, |
| 4582 | &ws->layer.link), |
Pekka Paalanen | f0fc70d | 2011-11-15 13:34:54 +0200 | [diff] [blame] | 4583 | |
Kristian Høgsberg | 2f5faff | 2012-07-31 16:36:34 -0400 | [diff] [blame] | 4584 | restore_focus_state(shell, get_current_workspace(shell)); |
Jonas Ådahl | 0476974 | 2012-06-13 00:01:24 +0200 | [diff] [blame] | 4585 | |
Pekka Paalanen | f0fc70d | 2011-11-15 13:34:54 +0200 | [diff] [blame] | 4586 | shell->locked = false; |
Ander Conselvan de Oliveira | 87524b6 | 2013-02-21 18:35:22 +0200 | [diff] [blame] | 4587 | shell_fade(shell, FADE_IN); |
Pekka Paalanen | fc6d91a | 2012-02-10 15:33:10 +0200 | [diff] [blame] | 4588 | weston_compositor_damage_all(shell->compositor); |
Pekka Paalanen | 9ef3e01 | 2011-11-15 13:34:48 +0200 | [diff] [blame] | 4589 | } |
| 4590 | |
| 4591 | static void |
| 4592 | desktop_shell_unlock(struct wl_client *client, |
| 4593 | struct wl_resource *resource) |
| 4594 | { |
Jason Ekstrand | 651f00e | 2013-06-14 10:07:54 -0500 | [diff] [blame] | 4595 | struct desktop_shell *shell = wl_resource_get_user_data(resource); |
Pekka Paalanen | 9ef3e01 | 2011-11-15 13:34:48 +0200 | [diff] [blame] | 4596 | |
Pekka Paalanen | 9ef3e01 | 2011-11-15 13:34:48 +0200 | [diff] [blame] | 4597 | shell->prepare_event_sent = false; |
Pekka Paalanen | f0fc70d | 2011-11-15 13:34:54 +0200 | [diff] [blame] | 4598 | |
| 4599 | if (shell->locked) |
| 4600 | resume_desktop(shell); |
Pekka Paalanen | 9ef3e01 | 2011-11-15 13:34:48 +0200 | [diff] [blame] | 4601 | } |
| 4602 | |
Kristian Høgsberg | d56bd90 | 2012-06-05 09:58:51 -0400 | [diff] [blame] | 4603 | static void |
Ander Conselvan de Oliveira | b9d2a0f | 2012-06-28 18:08:05 +0300 | [diff] [blame] | 4604 | desktop_shell_set_grab_surface(struct wl_client *client, |
Kristian Høgsberg | d56bd90 | 2012-06-05 09:58:51 -0400 | [diff] [blame] | 4605 | struct wl_resource *resource, |
| 4606 | struct wl_resource *surface_resource) |
| 4607 | { |
Jason Ekstrand | 651f00e | 2013-06-14 10:07:54 -0500 | [diff] [blame] | 4608 | struct desktop_shell *shell = wl_resource_get_user_data(resource); |
Kristian Høgsberg | d56bd90 | 2012-06-05 09:58:51 -0400 | [diff] [blame] | 4609 | |
Jason Ekstrand | 0f2ef7e | 2013-06-14 10:07:53 -0500 | [diff] [blame] | 4610 | shell->grab_surface = wl_resource_get_user_data(surface_resource); |
Kristian Høgsberg | 48588f8 | 2013-10-24 15:51:35 -0700 | [diff] [blame] | 4611 | weston_view_create(shell->grab_surface); |
Kristian Høgsberg | d56bd90 | 2012-06-05 09:58:51 -0400 | [diff] [blame] | 4612 | } |
| 4613 | |
Pekka Paalanen | 79346ab | 2013-05-22 18:03:09 +0300 | [diff] [blame] | 4614 | static void |
| 4615 | desktop_shell_desktop_ready(struct wl_client *client, |
| 4616 | struct wl_resource *resource) |
| 4617 | { |
Jason Ekstrand | 651f00e | 2013-06-14 10:07:54 -0500 | [diff] [blame] | 4618 | struct desktop_shell *shell = wl_resource_get_user_data(resource); |
Pekka Paalanen | 79346ab | 2013-05-22 18:03:09 +0300 | [diff] [blame] | 4619 | |
| 4620 | shell_fade_startup(shell); |
| 4621 | } |
| 4622 | |
Jonny Lamb | 765760d | 2014-08-20 15:53:19 +0200 | [diff] [blame] | 4623 | static void |
| 4624 | desktop_shell_set_panel_position(struct wl_client *client, |
| 4625 | struct wl_resource *resource, |
| 4626 | uint32_t position) |
| 4627 | { |
| 4628 | struct desktop_shell *shell = wl_resource_get_user_data(resource); |
| 4629 | |
| 4630 | if (position != DESKTOP_SHELL_PANEL_POSITION_TOP && |
| 4631 | position != DESKTOP_SHELL_PANEL_POSITION_BOTTOM && |
| 4632 | position != DESKTOP_SHELL_PANEL_POSITION_LEFT && |
| 4633 | position != DESKTOP_SHELL_PANEL_POSITION_RIGHT) { |
| 4634 | wl_resource_post_error(resource, |
| 4635 | DESKTOP_SHELL_ERROR_INVALID_ARGUMENT, |
| 4636 | "bad position argument"); |
| 4637 | return; |
| 4638 | } |
| 4639 | |
| 4640 | shell->panel_position = position; |
| 4641 | } |
| 4642 | |
Kristian Høgsberg | 7584062 | 2011-09-06 13:48:16 -0400 | [diff] [blame] | 4643 | static const struct desktop_shell_interface desktop_shell_implementation = { |
| 4644 | desktop_shell_set_background, |
Pekka Paalanen | 9ef3e01 | 2011-11-15 13:34:48 +0200 | [diff] [blame] | 4645 | desktop_shell_set_panel, |
| 4646 | desktop_shell_set_lock_surface, |
Kristian Høgsberg | d56bd90 | 2012-06-05 09:58:51 -0400 | [diff] [blame] | 4647 | desktop_shell_unlock, |
Pekka Paalanen | 79346ab | 2013-05-22 18:03:09 +0300 | [diff] [blame] | 4648 | desktop_shell_set_grab_surface, |
Jonny Lamb | 765760d | 2014-08-20 15:53:19 +0200 | [diff] [blame] | 4649 | desktop_shell_desktop_ready, |
| 4650 | desktop_shell_set_panel_position |
Kristian Høgsberg | 7584062 | 2011-09-06 13:48:16 -0400 | [diff] [blame] | 4651 | }; |
| 4652 | |
Pekka Paalanen | 92a0dc4 | 2011-11-28 15:34:13 +0200 | [diff] [blame] | 4653 | static enum shell_surface_type |
Kristian Høgsberg | 8334bc1 | 2012-01-03 10:29:47 -0500 | [diff] [blame] | 4654 | get_shell_surface_type(struct weston_surface *surface) |
Pekka Paalanen | 92a0dc4 | 2011-11-28 15:34:13 +0200 | [diff] [blame] | 4655 | { |
| 4656 | struct shell_surface *shsurf; |
| 4657 | |
| 4658 | shsurf = get_shell_surface(surface); |
| 4659 | if (!shsurf) |
Pekka Paalanen | 9826223 | 2011-12-01 10:42:22 +0200 | [diff] [blame] | 4660 | return SHELL_SURFACE_NONE; |
Pekka Paalanen | 92a0dc4 | 2011-11-28 15:34:13 +0200 | [diff] [blame] | 4661 | return shsurf->type; |
| 4662 | } |
| 4663 | |
Kristian Høgsberg | 7584062 | 2011-09-06 13:48:16 -0400 | [diff] [blame] | 4664 | static void |
Derek Foreman | 8ae2db5 | 2015-07-15 13:00:36 -0500 | [diff] [blame] | 4665 | move_binding(struct weston_pointer *pointer, uint32_t time, |
| 4666 | uint32_t button, void *data) |
Kristian Høgsberg | 0793756 | 2011-04-12 17:25:42 -0400 | [diff] [blame] | 4667 | { |
Rafal Mielniczuk | b2917a2 | 2014-01-05 20:04:59 +0100 | [diff] [blame] | 4668 | struct weston_surface *focus; |
Pekka Paalanen | 01388e2 | 2013-04-25 13:57:44 +0300 | [diff] [blame] | 4669 | struct weston_surface *surface; |
Kristian Høgsberg | 938b8fa | 2012-05-18 13:46:27 -0400 | [diff] [blame] | 4670 | struct shell_surface *shsurf; |
Kristian Høgsberg | d2abb83 | 2011-11-23 10:52:40 -0500 | [diff] [blame] | 4671 | |
Derek Foreman | 8ae2db5 | 2015-07-15 13:00:36 -0500 | [diff] [blame] | 4672 | if (pointer->focus == NULL) |
Rafal Mielniczuk | b2917a2 | 2014-01-05 20:04:59 +0100 | [diff] [blame] | 4673 | return; |
| 4674 | |
Derek Foreman | 8ae2db5 | 2015-07-15 13:00:36 -0500 | [diff] [blame] | 4675 | focus = pointer->focus->surface; |
Rafal Mielniczuk | b2917a2 | 2014-01-05 20:04:59 +0100 | [diff] [blame] | 4676 | |
Pekka Paalanen | 01388e2 | 2013-04-25 13:57:44 +0300 | [diff] [blame] | 4677 | surface = weston_surface_get_main_surface(focus); |
Benjamin Franzke | d0f79ab | 2011-11-22 12:43:52 +0100 | [diff] [blame] | 4678 | if (surface == NULL) |
| 4679 | return; |
Kristian Høgsberg | 0793756 | 2011-04-12 17:25:42 -0400 | [diff] [blame] | 4680 | |
Kristian Høgsberg | 938b8fa | 2012-05-18 13:46:27 -0400 | [diff] [blame] | 4681 | shsurf = get_shell_surface(surface); |
Rafael Antognolli | 03b1659 | 2013-12-03 15:35:42 -0200 | [diff] [blame] | 4682 | if (shsurf == NULL || shsurf->state.fullscreen || |
| 4683 | shsurf->state.maximized) |
Kristian Høgsberg | 938b8fa | 2012-05-18 13:46:27 -0400 | [diff] [blame] | 4684 | return; |
| 4685 | |
Derek Foreman | 794fa0e | 2015-07-15 13:00:38 -0500 | [diff] [blame] | 4686 | surface_move(shsurf, pointer, false); |
Kristian Høgsberg | 0793756 | 2011-04-12 17:25:42 -0400 | [diff] [blame] | 4687 | } |
| 4688 | |
| 4689 | static void |
Derek Foreman | 8ae2db5 | 2015-07-15 13:00:36 -0500 | [diff] [blame] | 4690 | maximize_binding(struct weston_keyboard *keyboard, uint32_t time, |
| 4691 | uint32_t button, void *data) |
Rafael Antognolli | ea997ac | 2013-12-03 15:35:48 -0200 | [diff] [blame] | 4692 | { |
Derek Foreman | 8ae2db5 | 2015-07-15 13:00:36 -0500 | [diff] [blame] | 4693 | struct weston_surface *focus = keyboard->focus; |
Rafael Antognolli | ea997ac | 2013-12-03 15:35:48 -0200 | [diff] [blame] | 4694 | struct weston_surface *surface; |
| 4695 | struct shell_surface *shsurf; |
| 4696 | |
| 4697 | surface = weston_surface_get_main_surface(focus); |
| 4698 | if (surface == NULL) |
| 4699 | return; |
| 4700 | |
| 4701 | shsurf = get_shell_surface(surface); |
| 4702 | if (shsurf == NULL) |
| 4703 | return; |
| 4704 | |
| 4705 | if (!shell_surface_is_xdg_surface(shsurf)) |
| 4706 | return; |
| 4707 | |
Jasper St. Pierre | ab2c108 | 2014-04-10 10:41:46 -0700 | [diff] [blame] | 4708 | shsurf->state_requested = true; |
| 4709 | shsurf->requested_state.maximized = !shsurf->state.maximized; |
Jasper St. Pierre | 9aa8ce6 | 2014-04-11 16:18:54 -0700 | [diff] [blame] | 4710 | send_configure_for_surface(shsurf); |
Rafael Antognolli | ea997ac | 2013-12-03 15:35:48 -0200 | [diff] [blame] | 4711 | } |
| 4712 | |
| 4713 | static void |
Derek Foreman | 8ae2db5 | 2015-07-15 13:00:36 -0500 | [diff] [blame] | 4714 | fullscreen_binding(struct weston_keyboard *keyboard, uint32_t time, |
| 4715 | uint32_t button, void *data) |
Rafael Antognolli | ea997ac | 2013-12-03 15:35:48 -0200 | [diff] [blame] | 4716 | { |
Derek Foreman | 8ae2db5 | 2015-07-15 13:00:36 -0500 | [diff] [blame] | 4717 | struct weston_surface *focus = keyboard->focus; |
Rafael Antognolli | ea997ac | 2013-12-03 15:35:48 -0200 | [diff] [blame] | 4718 | struct weston_surface *surface; |
| 4719 | struct shell_surface *shsurf; |
| 4720 | |
| 4721 | surface = weston_surface_get_main_surface(focus); |
| 4722 | if (surface == NULL) |
| 4723 | return; |
| 4724 | |
| 4725 | shsurf = get_shell_surface(surface); |
| 4726 | if (shsurf == NULL) |
| 4727 | return; |
| 4728 | |
| 4729 | if (!shell_surface_is_xdg_surface(shsurf)) |
| 4730 | return; |
| 4731 | |
Jasper St. Pierre | ab2c108 | 2014-04-10 10:41:46 -0700 | [diff] [blame] | 4732 | shsurf->state_requested = true; |
| 4733 | shsurf->requested_state.fullscreen = !shsurf->state.fullscreen; |
Boyan Ding | 32abdbb | 2014-06-26 10:19:32 +0800 | [diff] [blame] | 4734 | shsurf->fullscreen_output = shsurf->output; |
Jasper St. Pierre | 9aa8ce6 | 2014-04-11 16:18:54 -0700 | [diff] [blame] | 4735 | send_configure_for_surface(shsurf); |
Rafael Antognolli | ea997ac | 2013-12-03 15:35:48 -0200 | [diff] [blame] | 4736 | } |
| 4737 | |
| 4738 | static void |
Derek Foreman | 8ae2db5 | 2015-07-15 13:00:36 -0500 | [diff] [blame] | 4739 | touch_move_binding(struct weston_touch *touch, uint32_t time, void *data) |
Neil Roberts | aba0f25 | 2013-10-03 16:43:05 +0100 | [diff] [blame] | 4740 | { |
Derek Foreman | 362656b | 2014-09-04 10:23:05 -0500 | [diff] [blame] | 4741 | struct weston_surface *focus; |
Neil Roberts | aba0f25 | 2013-10-03 16:43:05 +0100 | [diff] [blame] | 4742 | struct weston_surface *surface; |
| 4743 | struct shell_surface *shsurf; |
| 4744 | |
Derek Foreman | 8ae2db5 | 2015-07-15 13:00:36 -0500 | [diff] [blame] | 4745 | if (touch->focus == NULL) |
Derek Foreman | 362656b | 2014-09-04 10:23:05 -0500 | [diff] [blame] | 4746 | return; |
| 4747 | |
Derek Foreman | 8ae2db5 | 2015-07-15 13:00:36 -0500 | [diff] [blame] | 4748 | focus = touch->focus->surface; |
Neil Roberts | aba0f25 | 2013-10-03 16:43:05 +0100 | [diff] [blame] | 4749 | surface = weston_surface_get_main_surface(focus); |
| 4750 | if (surface == NULL) |
| 4751 | return; |
| 4752 | |
| 4753 | shsurf = get_shell_surface(surface); |
Rafael Antognolli | 03b1659 | 2013-12-03 15:35:42 -0200 | [diff] [blame] | 4754 | if (shsurf == NULL || shsurf->state.fullscreen || |
| 4755 | shsurf->state.maximized) |
Neil Roberts | aba0f25 | 2013-10-03 16:43:05 +0100 | [diff] [blame] | 4756 | return; |
| 4757 | |
Derek Foreman | b7674ae | 2015-07-15 13:00:37 -0500 | [diff] [blame] | 4758 | surface_touch_move(shsurf, touch); |
Neil Roberts | aba0f25 | 2013-10-03 16:43:05 +0100 | [diff] [blame] | 4759 | } |
| 4760 | |
| 4761 | static void |
Derek Foreman | 8ae2db5 | 2015-07-15 13:00:36 -0500 | [diff] [blame] | 4762 | resize_binding(struct weston_pointer *pointer, uint32_t time, |
| 4763 | uint32_t button, void *data) |
Kristian Høgsberg | 0793756 | 2011-04-12 17:25:42 -0400 | [diff] [blame] | 4764 | { |
Rafal Mielniczuk | b2917a2 | 2014-01-05 20:04:59 +0100 | [diff] [blame] | 4765 | struct weston_surface *focus; |
Pekka Paalanen | 01388e2 | 2013-04-25 13:57:44 +0300 | [diff] [blame] | 4766 | struct weston_surface *surface; |
Kristian Høgsberg | 0793756 | 2011-04-12 17:25:42 -0400 | [diff] [blame] | 4767 | uint32_t edges = 0; |
| 4768 | int32_t x, y; |
Pekka Paalanen | 9d1613e | 2011-11-25 12:09:16 +0200 | [diff] [blame] | 4769 | struct shell_surface *shsurf; |
Kristian Høgsberg | d2abb83 | 2011-11-23 10:52:40 -0500 | [diff] [blame] | 4770 | |
Derek Foreman | 8ae2db5 | 2015-07-15 13:00:36 -0500 | [diff] [blame] | 4771 | if (pointer->focus == NULL) |
Rafal Mielniczuk | b2917a2 | 2014-01-05 20:04:59 +0100 | [diff] [blame] | 4772 | return; |
| 4773 | |
Derek Foreman | 8ae2db5 | 2015-07-15 13:00:36 -0500 | [diff] [blame] | 4774 | focus = pointer->focus->surface; |
Rafal Mielniczuk | b2917a2 | 2014-01-05 20:04:59 +0100 | [diff] [blame] | 4775 | |
Pekka Paalanen | 01388e2 | 2013-04-25 13:57:44 +0300 | [diff] [blame] | 4776 | surface = weston_surface_get_main_surface(focus); |
Benjamin Franzke | d0f79ab | 2011-11-22 12:43:52 +0100 | [diff] [blame] | 4777 | if (surface == NULL) |
| 4778 | return; |
Pekka Paalanen | 92a0dc4 | 2011-11-28 15:34:13 +0200 | [diff] [blame] | 4779 | |
Pekka Paalanen | 9d1613e | 2011-11-25 12:09:16 +0200 | [diff] [blame] | 4780 | shsurf = get_shell_surface(surface); |
Rafael Antognolli | 03b1659 | 2013-12-03 15:35:42 -0200 | [diff] [blame] | 4781 | if (shsurf == NULL || shsurf->state.fullscreen || |
| 4782 | shsurf->state.maximized) |
Pekka Paalanen | 92a0dc4 | 2011-11-28 15:34:13 +0200 | [diff] [blame] | 4783 | return; |
| 4784 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 4785 | weston_view_from_global(shsurf->view, |
Derek Foreman | 8ae2db5 | 2015-07-15 13:00:36 -0500 | [diff] [blame] | 4786 | wl_fixed_to_int(pointer->grab_x), |
| 4787 | wl_fixed_to_int(pointer->grab_y), |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 4788 | &x, &y); |
Kristian Høgsberg | 0793756 | 2011-04-12 17:25:42 -0400 | [diff] [blame] | 4789 | |
Jason Ekstrand | 918f2dd | 2013-12-02 21:01:53 -0600 | [diff] [blame] | 4790 | if (x < shsurf->surface->width / 3) |
Pekka Paalanen | 9d1613e | 2011-11-25 12:09:16 +0200 | [diff] [blame] | 4791 | edges |= WL_SHELL_SURFACE_RESIZE_LEFT; |
Jason Ekstrand | 918f2dd | 2013-12-02 21:01:53 -0600 | [diff] [blame] | 4792 | else if (x < 2 * shsurf->surface->width / 3) |
Kristian Høgsberg | 0793756 | 2011-04-12 17:25:42 -0400 | [diff] [blame] | 4793 | edges |= 0; |
| 4794 | else |
Pekka Paalanen | 9d1613e | 2011-11-25 12:09:16 +0200 | [diff] [blame] | 4795 | edges |= WL_SHELL_SURFACE_RESIZE_RIGHT; |
Kristian Høgsberg | 0793756 | 2011-04-12 17:25:42 -0400 | [diff] [blame] | 4796 | |
Jason Ekstrand | 918f2dd | 2013-12-02 21:01:53 -0600 | [diff] [blame] | 4797 | if (y < shsurf->surface->height / 3) |
Pekka Paalanen | 9d1613e | 2011-11-25 12:09:16 +0200 | [diff] [blame] | 4798 | edges |= WL_SHELL_SURFACE_RESIZE_TOP; |
Jason Ekstrand | 918f2dd | 2013-12-02 21:01:53 -0600 | [diff] [blame] | 4799 | else if (y < 2 * shsurf->surface->height / 3) |
Kristian Høgsberg | 0793756 | 2011-04-12 17:25:42 -0400 | [diff] [blame] | 4800 | edges |= 0; |
| 4801 | else |
Pekka Paalanen | 9d1613e | 2011-11-25 12:09:16 +0200 | [diff] [blame] | 4802 | edges |= WL_SHELL_SURFACE_RESIZE_BOTTOM; |
Kristian Høgsberg | 0793756 | 2011-04-12 17:25:42 -0400 | [diff] [blame] | 4803 | |
Derek Foreman | 8fbebbd | 2015-07-15 13:00:40 -0500 | [diff] [blame] | 4804 | surface_resize(shsurf, pointer, edges); |
Kristian Høgsberg | 02ec0a5 | 2011-04-23 13:04:11 -0400 | [diff] [blame] | 4805 | } |
| 4806 | |
| 4807 | static void |
Derek Foreman | 8ae2db5 | 2015-07-15 13:00:36 -0500 | [diff] [blame] | 4808 | surface_opacity_binding(struct weston_pointer *pointer, uint32_t time, |
| 4809 | uint32_t axis, wl_fixed_t value, void *data) |
Scott Moreau | a3aa9c9 | 2012-03-22 11:01:03 -0600 | [diff] [blame] | 4810 | { |
Jonas Ådahl | b0b87ba | 2012-09-27 18:40:42 +0200 | [diff] [blame] | 4811 | float step = 0.005; |
Scott Moreau | a3aa9c9 | 2012-03-22 11:01:03 -0600 | [diff] [blame] | 4812 | struct shell_surface *shsurf; |
Derek Foreman | 8ae2db5 | 2015-07-15 13:00:36 -0500 | [diff] [blame] | 4813 | struct weston_surface *focus = pointer->focus->surface; |
Pekka Paalanen | 01388e2 | 2013-04-25 13:57:44 +0300 | [diff] [blame] | 4814 | struct weston_surface *surface; |
Scott Moreau | a3aa9c9 | 2012-03-22 11:01:03 -0600 | [diff] [blame] | 4815 | |
Pekka Paalanen | 01388e2 | 2013-04-25 13:57:44 +0300 | [diff] [blame] | 4816 | /* XXX: broken for windows containing sub-surfaces */ |
| 4817 | surface = weston_surface_get_main_surface(focus); |
Scott Moreau | a3aa9c9 | 2012-03-22 11:01:03 -0600 | [diff] [blame] | 4818 | if (surface == NULL) |
| 4819 | return; |
| 4820 | |
| 4821 | shsurf = get_shell_surface(surface); |
| 4822 | if (!shsurf) |
| 4823 | return; |
| 4824 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 4825 | shsurf->view->alpha -= wl_fixed_to_double(value) * step; |
Scott Moreau | a3aa9c9 | 2012-03-22 11:01:03 -0600 | [diff] [blame] | 4826 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 4827 | if (shsurf->view->alpha > 1.0) |
| 4828 | shsurf->view->alpha = 1.0; |
| 4829 | if (shsurf->view->alpha < step) |
| 4830 | shsurf->view->alpha = step; |
Scott Moreau | a3aa9c9 | 2012-03-22 11:01:03 -0600 | [diff] [blame] | 4831 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 4832 | weston_view_geometry_dirty(shsurf->view); |
Scott Moreau | a3aa9c9 | 2012-03-22 11:01:03 -0600 | [diff] [blame] | 4833 | weston_surface_damage(surface); |
| 4834 | } |
| 4835 | |
| 4836 | static void |
Kristian Høgsberg | e314875 | 2013-05-06 23:19:49 -0400 | [diff] [blame] | 4837 | 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] | 4838 | wl_fixed_t value) |
Scott Moreau | ccbf29d | 2012-02-22 14:21:41 -0700 | [diff] [blame] | 4839 | { |
Derek Foreman | 8aeeac8 | 2015-01-30 13:24:36 -0600 | [diff] [blame] | 4840 | struct weston_compositor *compositor = seat->compositor; |
Derek Foreman | 1281a36 | 2015-07-31 16:55:32 -0500 | [diff] [blame] | 4841 | struct weston_pointer *pointer = weston_seat_get_pointer(seat); |
Scott Moreau | ccbf29d | 2012-02-22 14:21:41 -0700 | [diff] [blame] | 4842 | struct weston_output *output; |
Scott Moreau | e660398 | 2012-06-11 13:07:51 -0600 | [diff] [blame] | 4843 | float increment; |
Scott Moreau | ccbf29d | 2012-02-22 14:21:41 -0700 | [diff] [blame] | 4844 | |
Derek Foreman | 1281a36 | 2015-07-31 16:55:32 -0500 | [diff] [blame] | 4845 | if (!pointer) { |
Derek Foreman | 7ef3bed | 2015-01-06 14:28:13 -0600 | [diff] [blame] | 4846 | weston_log("Zoom hotkey pressed but seat '%s' contains no pointer.\n", seat->seat_name); |
| 4847 | return; |
| 4848 | } |
| 4849 | |
Scott Moreau | ccbf29d | 2012-02-22 14:21:41 -0700 | [diff] [blame] | 4850 | wl_list_for_each(output, &compositor->output_list, link) { |
| 4851 | if (pixman_region32_contains_point(&output->region, |
Derek Foreman | 1281a36 | 2015-07-31 16:55:32 -0500 | [diff] [blame] | 4852 | wl_fixed_to_double(pointer->x), |
| 4853 | wl_fixed_to_double(pointer->y), |
Daniel Stone | 103db7f | 2012-05-08 17:17:55 +0100 | [diff] [blame] | 4854 | NULL)) { |
Daniel Stone | 325fc2d | 2012-05-30 16:31:58 +0100 | [diff] [blame] | 4855 | if (key == KEY_PAGEUP) |
Kristian Høgsberg | 9b68af0 | 2012-05-22 12:55:18 -0400 | [diff] [blame] | 4856 | increment = output->zoom.increment; |
Daniel Stone | 325fc2d | 2012-05-30 16:31:58 +0100 | [diff] [blame] | 4857 | else if (key == KEY_PAGEDOWN) |
Kristian Høgsberg | 9b68af0 | 2012-05-22 12:55:18 -0400 | [diff] [blame] | 4858 | increment = -output->zoom.increment; |
| 4859 | else if (axis == WL_POINTER_AXIS_VERTICAL_SCROLL) |
Jonas Ådahl | b0b87ba | 2012-09-27 18:40:42 +0200 | [diff] [blame] | 4860 | /* For every pixel zoom 20th of a step */ |
Daniel Stone | 0c1e46e | 2012-05-30 16:31:59 +0100 | [diff] [blame] | 4861 | increment = output->zoom.increment * |
Jonas Ådahl | b0b87ba | 2012-09-27 18:40:42 +0200 | [diff] [blame] | 4862 | -wl_fixed_to_double(value) / 20.0; |
Kristian Høgsberg | 9b68af0 | 2012-05-22 12:55:18 -0400 | [diff] [blame] | 4863 | else |
| 4864 | increment = 0; |
| 4865 | |
Kristian Høgsberg | 9b68af0 | 2012-05-22 12:55:18 -0400 | [diff] [blame] | 4866 | output->zoom.level += increment; |
Scott Moreau | c6d7f60 | 2012-02-23 22:28:37 -0700 | [diff] [blame] | 4867 | |
Scott Moreau | e660398 | 2012-06-11 13:07:51 -0600 | [diff] [blame] | 4868 | if (output->zoom.level < 0.0) |
Scott Moreau | 850ca42 | 2012-05-21 15:21:25 -0600 | [diff] [blame] | 4869 | output->zoom.level = 0.0; |
Scott Moreau | e660398 | 2012-06-11 13:07:51 -0600 | [diff] [blame] | 4870 | else if (output->zoom.level > output->zoom.max_level) |
| 4871 | output->zoom.level = output->zoom.max_level; |
Derek Foreman | 25bd8a7 | 2015-07-23 14:55:13 -0500 | [diff] [blame] | 4872 | |
| 4873 | if (!output->zoom.active) { |
| 4874 | if (output->zoom.level <= 0.0) |
| 4875 | continue; |
Derek Foreman | 22276a5 | 2015-07-23 14:55:15 -0500 | [diff] [blame] | 4876 | weston_output_activate_zoom(output, seat); |
Kristian Høgsberg | 79af73e | 2012-08-03 15:45:23 -0400 | [diff] [blame] | 4877 | } |
Scott Moreau | ccbf29d | 2012-02-22 14:21:41 -0700 | [diff] [blame] | 4878 | |
Scott Moreau | e660398 | 2012-06-11 13:07:51 -0600 | [diff] [blame] | 4879 | output->zoom.spring_z.target = output->zoom.level; |
Scott Moreau | ccbf29d | 2012-02-22 14:21:41 -0700 | [diff] [blame] | 4880 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 4881 | weston_output_update_zoom(output); |
Scott Moreau | ccbf29d | 2012-02-22 14:21:41 -0700 | [diff] [blame] | 4882 | } |
| 4883 | } |
| 4884 | } |
| 4885 | |
Scott Moreau | ccbf29d | 2012-02-22 14:21:41 -0700 | [diff] [blame] | 4886 | static void |
Derek Foreman | 8ae2db5 | 2015-07-15 13:00:36 -0500 | [diff] [blame] | 4887 | zoom_axis_binding(struct weston_pointer *pointer, uint32_t time, |
| 4888 | uint32_t axis, wl_fixed_t value, void *data) |
Daniel Stone | 325fc2d | 2012-05-30 16:31:58 +0100 | [diff] [blame] | 4889 | { |
Derek Foreman | 8ae2db5 | 2015-07-15 13:00:36 -0500 | [diff] [blame] | 4890 | do_zoom(pointer->seat, time, 0, axis, value); |
Daniel Stone | 325fc2d | 2012-05-30 16:31:58 +0100 | [diff] [blame] | 4891 | } |
| 4892 | |
| 4893 | static void |
Derek Foreman | 8ae2db5 | 2015-07-15 13:00:36 -0500 | [diff] [blame] | 4894 | zoom_key_binding(struct weston_keyboard *keyboard, uint32_t time, |
| 4895 | uint32_t key, void *data) |
Daniel Stone | 325fc2d | 2012-05-30 16:31:58 +0100 | [diff] [blame] | 4896 | { |
Derek Foreman | 8ae2db5 | 2015-07-15 13:00:36 -0500 | [diff] [blame] | 4897 | do_zoom(keyboard->seat, time, key, 0, 0); |
Daniel Stone | 325fc2d | 2012-05-30 16:31:58 +0100 | [diff] [blame] | 4898 | } |
| 4899 | |
| 4900 | static void |
Derek Foreman | 8ae2db5 | 2015-07-15 13:00:36 -0500 | [diff] [blame] | 4901 | terminate_binding(struct weston_keyboard *keyboard, uint32_t time, |
| 4902 | uint32_t key, void *data) |
Kristian Høgsberg | e1a850e | 2011-12-19 15:18:05 -0500 | [diff] [blame] | 4903 | { |
Kristian Høgsberg | 8334bc1 | 2012-01-03 10:29:47 -0500 | [diff] [blame] | 4904 | struct weston_compositor *compositor = data; |
Kristian Høgsberg | e1a850e | 2011-12-19 15:18:05 -0500 | [diff] [blame] | 4905 | |
Daniel Stone | 325fc2d | 2012-05-30 16:31:58 +0100 | [diff] [blame] | 4906 | wl_display_terminate(compositor->wl_display); |
Kristian Høgsberg | e1a850e | 2011-12-19 15:18:05 -0500 | [diff] [blame] | 4907 | } |
| 4908 | |
Emilio Pozuelo Monfort | 03251b6 | 2013-11-19 11:37:16 +0100 | [diff] [blame] | 4909 | static void |
Giulio Camuffo | 1959ab8 | 2013-11-14 23:42:52 +0100 | [diff] [blame] | 4910 | rotate_grab_motion(struct weston_pointer_grab *grab, uint32_t time, |
| 4911 | wl_fixed_t x, wl_fixed_t y) |
Pekka Paalanen | 460099f | 2012-01-20 16:48:25 +0200 | [diff] [blame] | 4912 | { |
| 4913 | struct rotate_grab *rotate = |
Ander Conselvan de Oliveira | fe0444a | 2012-04-04 17:48:05 +0300 | [diff] [blame] | 4914 | container_of(grab, struct rotate_grab, base.grab); |
Kristian Høgsberg | 02bbabb | 2013-05-06 22:15:05 -0400 | [diff] [blame] | 4915 | struct weston_pointer *pointer = grab->pointer; |
Ander Conselvan de Oliveira | fe0444a | 2012-04-04 17:48:05 +0300 | [diff] [blame] | 4916 | struct shell_surface *shsurf = rotate->base.shsurf; |
John Kåre Alsaker | 490d02a | 2012-09-30 02:57:21 +0200 | [diff] [blame] | 4917 | float cx, cy, dx, dy, cposx, cposy, dposx, dposy, r; |
Ander Conselvan de Oliveira | fe0444a | 2012-04-04 17:48:05 +0300 | [diff] [blame] | 4918 | |
Giulio Camuffo | 1959ab8 | 2013-11-14 23:42:52 +0100 | [diff] [blame] | 4919 | weston_pointer_move(pointer, x, y); |
| 4920 | |
Ander Conselvan de Oliveira | fe0444a | 2012-04-04 17:48:05 +0300 | [diff] [blame] | 4921 | if (!shsurf) |
| 4922 | return; |
| 4923 | |
Jason Ekstrand | 918f2dd | 2013-12-02 21:01:53 -0600 | [diff] [blame] | 4924 | cx = 0.5f * shsurf->surface->width; |
| 4925 | cy = 0.5f * shsurf->surface->height; |
Pekka Paalanen | 460099f | 2012-01-20 16:48:25 +0200 | [diff] [blame] | 4926 | |
Daniel Stone | 37816df | 2012-05-16 18:45:18 +0100 | [diff] [blame] | 4927 | dx = wl_fixed_to_double(pointer->x) - rotate->center.x; |
| 4928 | dy = wl_fixed_to_double(pointer->y) - rotate->center.y; |
Pekka Paalanen | 460099f | 2012-01-20 16:48:25 +0200 | [diff] [blame] | 4929 | r = sqrtf(dx * dx + dy * dy); |
| 4930 | |
Ander Conselvan de Oliveira | fe0444a | 2012-04-04 17:48:05 +0300 | [diff] [blame] | 4931 | wl_list_remove(&shsurf->rotation.transform.link); |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 4932 | weston_view_geometry_dirty(shsurf->view); |
Pekka Paalanen | 460099f | 2012-01-20 16:48:25 +0200 | [diff] [blame] | 4933 | |
| 4934 | if (r > 20.0f) { |
Pekka Paalanen | 460099f | 2012-01-20 16:48:25 +0200 | [diff] [blame] | 4935 | struct weston_matrix *matrix = |
Ander Conselvan de Oliveira | fe0444a | 2012-04-04 17:48:05 +0300 | [diff] [blame] | 4936 | &shsurf->rotation.transform.matrix; |
Pekka Paalanen | 460099f | 2012-01-20 16:48:25 +0200 | [diff] [blame] | 4937 | |
Kristian Høgsberg | 765e27b | 2012-01-27 13:36:13 -0500 | [diff] [blame] | 4938 | weston_matrix_init(&rotate->rotation); |
Vasily Khoruzhick | 1bbf372 | 2013-01-28 22:40:28 +0300 | [diff] [blame] | 4939 | weston_matrix_rotate_xy(&rotate->rotation, dx / r, dy / r); |
Pekka Paalanen | 460099f | 2012-01-20 16:48:25 +0200 | [diff] [blame] | 4940 | |
| 4941 | weston_matrix_init(matrix); |
Pekka Paalanen | 7b3bd3d | 2012-01-30 14:16:34 +0200 | [diff] [blame] | 4942 | weston_matrix_translate(matrix, -cx, -cy, 0.0f); |
Ander Conselvan de Oliveira | fe0444a | 2012-04-04 17:48:05 +0300 | [diff] [blame] | 4943 | weston_matrix_multiply(matrix, &shsurf->rotation.rotation); |
Kristian Høgsberg | 765e27b | 2012-01-27 13:36:13 -0500 | [diff] [blame] | 4944 | weston_matrix_multiply(matrix, &rotate->rotation); |
Pekka Paalanen | 7b3bd3d | 2012-01-30 14:16:34 +0200 | [diff] [blame] | 4945 | weston_matrix_translate(matrix, cx, cy, 0.0f); |
Pekka Paalanen | 460099f | 2012-01-20 16:48:25 +0200 | [diff] [blame] | 4946 | |
Pekka Paalanen | bc0b7e7 | 2012-01-24 09:53:37 +0200 | [diff] [blame] | 4947 | wl_list_insert( |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 4948 | &shsurf->view->geometry.transformation_list, |
Ander Conselvan de Oliveira | fe0444a | 2012-04-04 17:48:05 +0300 | [diff] [blame] | 4949 | &shsurf->rotation.transform.link); |
Pekka Paalanen | 460099f | 2012-01-20 16:48:25 +0200 | [diff] [blame] | 4950 | } else { |
Ander Conselvan de Oliveira | fe0444a | 2012-04-04 17:48:05 +0300 | [diff] [blame] | 4951 | wl_list_init(&shsurf->rotation.transform.link); |
| 4952 | weston_matrix_init(&shsurf->rotation.rotation); |
Kristian Høgsberg | 765e27b | 2012-01-27 13:36:13 -0500 | [diff] [blame] | 4953 | weston_matrix_init(&rotate->rotation); |
Pekka Paalanen | 460099f | 2012-01-20 16:48:25 +0200 | [diff] [blame] | 4954 | } |
Pekka Paalanen | b45ac5e | 2012-02-09 15:58:44 +0200 | [diff] [blame] | 4955 | |
Rafal Mielniczuk | 2d7ab82 | 2012-03-22 22:22:04 +0100 | [diff] [blame] | 4956 | /* We need to adjust the position of the surface |
| 4957 | * in case it was resized in a rotated state before */ |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 4958 | cposx = shsurf->view->geometry.x + cx; |
| 4959 | cposy = shsurf->view->geometry.y + cy; |
Rafal Mielniczuk | 2d7ab82 | 2012-03-22 22:22:04 +0100 | [diff] [blame] | 4960 | dposx = rotate->center.x - cposx; |
| 4961 | dposy = rotate->center.y - cposy; |
| 4962 | if (dposx != 0.0f || dposy != 0.0f) { |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 4963 | weston_view_set_position(shsurf->view, |
| 4964 | shsurf->view->geometry.x + dposx, |
| 4965 | shsurf->view->geometry.y + dposy); |
Rafal Mielniczuk | 2d7ab82 | 2012-03-22 22:22:04 +0100 | [diff] [blame] | 4966 | } |
| 4967 | |
Derek Foreman | 4b1a0a1 | 2014-09-10 15:37:33 -0500 | [diff] [blame] | 4968 | /* Repaint implies weston_view_update_transform(), which |
Pekka Paalanen | b45ac5e | 2012-02-09 15:58:44 +0200 | [diff] [blame] | 4969 | * lazily applies the damage due to rotation update. |
| 4970 | */ |
Ander Conselvan de Oliveira | fe0444a | 2012-04-04 17:48:05 +0300 | [diff] [blame] | 4971 | weston_compositor_schedule_repaint(shsurf->surface->compositor); |
Pekka Paalanen | 460099f | 2012-01-20 16:48:25 +0200 | [diff] [blame] | 4972 | } |
| 4973 | |
| 4974 | static void |
Kristian Høgsberg | 02bbabb | 2013-05-06 22:15:05 -0400 | [diff] [blame] | 4975 | rotate_grab_button(struct weston_pointer_grab *grab, |
| 4976 | uint32_t time, uint32_t button, uint32_t state_w) |
Pekka Paalanen | 460099f | 2012-01-20 16:48:25 +0200 | [diff] [blame] | 4977 | { |
| 4978 | struct rotate_grab *rotate = |
Ander Conselvan de Oliveira | fe0444a | 2012-04-04 17:48:05 +0300 | [diff] [blame] | 4979 | container_of(grab, struct rotate_grab, base.grab); |
Kristian Høgsberg | 02bbabb | 2013-05-06 22:15:05 -0400 | [diff] [blame] | 4980 | struct weston_pointer *pointer = grab->pointer; |
Ander Conselvan de Oliveira | fe0444a | 2012-04-04 17:48:05 +0300 | [diff] [blame] | 4981 | struct shell_surface *shsurf = rotate->base.shsurf; |
Daniel Stone | 4dbadb1 | 2012-05-30 16:31:51 +0100 | [diff] [blame] | 4982 | enum wl_pointer_button_state state = state_w; |
Pekka Paalanen | 460099f | 2012-01-20 16:48:25 +0200 | [diff] [blame] | 4983 | |
Daniel Stone | 4dbadb1 | 2012-05-30 16:31:51 +0100 | [diff] [blame] | 4984 | if (pointer->button_count == 0 && |
| 4985 | state == WL_POINTER_BUTTON_STATE_RELEASED) { |
Ander Conselvan de Oliveira | fe0444a | 2012-04-04 17:48:05 +0300 | [diff] [blame] | 4986 | if (shsurf) |
| 4987 | weston_matrix_multiply(&shsurf->rotation.rotation, |
| 4988 | &rotate->rotation); |
Ander Conselvan de Oliveira | b9d2a0f | 2012-06-28 18:08:05 +0300 | [diff] [blame] | 4989 | shell_grab_end(&rotate->base); |
Pekka Paalanen | 460099f | 2012-01-20 16:48:25 +0200 | [diff] [blame] | 4990 | free(rotate); |
| 4991 | } |
| 4992 | } |
| 4993 | |
Jonas Ådahl | 1ea343e | 2013-10-25 23:18:05 +0200 | [diff] [blame] | 4994 | static void |
| 4995 | rotate_grab_cancel(struct weston_pointer_grab *grab) |
| 4996 | { |
| 4997 | struct rotate_grab *rotate = |
| 4998 | container_of(grab, struct rotate_grab, base.grab); |
| 4999 | |
| 5000 | shell_grab_end(&rotate->base); |
| 5001 | free(rotate); |
| 5002 | } |
| 5003 | |
Kristian Høgsberg | 02bbabb | 2013-05-06 22:15:05 -0400 | [diff] [blame] | 5004 | static const struct weston_pointer_grab_interface rotate_grab_interface = { |
Pekka Paalanen | 460099f | 2012-01-20 16:48:25 +0200 | [diff] [blame] | 5005 | noop_grab_focus, |
| 5006 | rotate_grab_motion, |
| 5007 | rotate_grab_button, |
Jonas Ådahl | 1ea343e | 2013-10-25 23:18:05 +0200 | [diff] [blame] | 5008 | rotate_grab_cancel, |
Pekka Paalanen | 460099f | 2012-01-20 16:48:25 +0200 | [diff] [blame] | 5009 | }; |
| 5010 | |
| 5011 | static void |
Derek Foreman | 74de469 | 2015-07-15 13:00:39 -0500 | [diff] [blame] | 5012 | surface_rotate(struct shell_surface *surface, struct weston_pointer *pointer) |
Pekka Paalanen | 460099f | 2012-01-20 16:48:25 +0200 | [diff] [blame] | 5013 | { |
Pekka Paalanen | 460099f | 2012-01-20 16:48:25 +0200 | [diff] [blame] | 5014 | struct rotate_grab *rotate; |
John Kåre Alsaker | 490d02a | 2012-09-30 02:57:21 +0200 | [diff] [blame] | 5015 | float dx, dy; |
| 5016 | float r; |
Pekka Paalanen | 460099f | 2012-01-20 16:48:25 +0200 | [diff] [blame] | 5017 | |
Derek Foreman | 45a7c27 | 2015-09-11 14:27:40 -0500 | [diff] [blame] | 5018 | surface = find_toplevel_surface(surface); |
| 5019 | |
Pekka Paalanen | 460099f | 2012-01-20 16:48:25 +0200 | [diff] [blame] | 5020 | rotate = malloc(sizeof *rotate); |
| 5021 | if (!rotate) |
| 5022 | return; |
| 5023 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 5024 | weston_view_to_global_float(surface->view, |
Jason Ekstrand | 918f2dd | 2013-12-02 21:01:53 -0600 | [diff] [blame] | 5025 | surface->surface->width * 0.5f, |
| 5026 | surface->surface->height * 0.5f, |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 5027 | &rotate->center.x, &rotate->center.y); |
Pekka Paalanen | 460099f | 2012-01-20 16:48:25 +0200 | [diff] [blame] | 5028 | |
Derek Foreman | 74de469 | 2015-07-15 13:00:39 -0500 | [diff] [blame] | 5029 | dx = wl_fixed_to_double(pointer->x) - rotate->center.x; |
| 5030 | dy = wl_fixed_to_double(pointer->y) - rotate->center.y; |
Kristian Høgsberg | 765e27b | 2012-01-27 13:36:13 -0500 | [diff] [blame] | 5031 | r = sqrtf(dx * dx + dy * dy); |
| 5032 | if (r > 20.0f) { |
| 5033 | struct weston_matrix inverse; |
| 5034 | |
| 5035 | weston_matrix_init(&inverse); |
Vasily Khoruzhick | 1bbf372 | 2013-01-28 22:40:28 +0300 | [diff] [blame] | 5036 | weston_matrix_rotate_xy(&inverse, dx / r, -dy / r); |
Kristian Høgsberg | 765e27b | 2012-01-27 13:36:13 -0500 | [diff] [blame] | 5037 | weston_matrix_multiply(&surface->rotation.rotation, &inverse); |
Rafal Mielniczuk | 2d7ab82 | 2012-03-22 22:22:04 +0100 | [diff] [blame] | 5038 | |
| 5039 | weston_matrix_init(&rotate->rotation); |
Vasily Khoruzhick | 1bbf372 | 2013-01-28 22:40:28 +0300 | [diff] [blame] | 5040 | weston_matrix_rotate_xy(&rotate->rotation, dx / r, dy / r); |
Kristian Høgsberg | 765e27b | 2012-01-27 13:36:13 -0500 | [diff] [blame] | 5041 | } else { |
| 5042 | weston_matrix_init(&surface->rotation.rotation); |
| 5043 | weston_matrix_init(&rotate->rotation); |
| 5044 | } |
| 5045 | |
Ander Conselvan de Oliveira | b9d2a0f | 2012-06-28 18:08:05 +0300 | [diff] [blame] | 5046 | shell_grab_start(&rotate->base, &rotate_grab_interface, surface, |
Derek Foreman | 74de469 | 2015-07-15 13:00:39 -0500 | [diff] [blame] | 5047 | pointer, DESKTOP_SHELL_CURSOR_ARROW); |
Pekka Paalanen | 460099f | 2012-01-20 16:48:25 +0200 | [diff] [blame] | 5048 | } |
| 5049 | |
| 5050 | static void |
Derek Foreman | 8ae2db5 | 2015-07-15 13:00:36 -0500 | [diff] [blame] | 5051 | 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] | 5052 | void *data) |
| 5053 | { |
Rafal Mielniczuk | b2917a2 | 2014-01-05 20:04:59 +0100 | [diff] [blame] | 5054 | struct weston_surface *focus; |
Pekka Paalanen | 01388e2 | 2013-04-25 13:57:44 +0300 | [diff] [blame] | 5055 | struct weston_surface *base_surface; |
Kristian Høgsberg | 0c36903 | 2013-02-14 21:31:44 -0500 | [diff] [blame] | 5056 | struct shell_surface *surface; |
| 5057 | |
Derek Foreman | 8ae2db5 | 2015-07-15 13:00:36 -0500 | [diff] [blame] | 5058 | if (pointer->focus == NULL) |
Rafal Mielniczuk | b2917a2 | 2014-01-05 20:04:59 +0100 | [diff] [blame] | 5059 | return; |
| 5060 | |
Derek Foreman | 8ae2db5 | 2015-07-15 13:00:36 -0500 | [diff] [blame] | 5061 | focus = pointer->focus->surface; |
Rafal Mielniczuk | b2917a2 | 2014-01-05 20:04:59 +0100 | [diff] [blame] | 5062 | |
Pekka Paalanen | 01388e2 | 2013-04-25 13:57:44 +0300 | [diff] [blame] | 5063 | base_surface = weston_surface_get_main_surface(focus); |
Kristian Høgsberg | 0c36903 | 2013-02-14 21:31:44 -0500 | [diff] [blame] | 5064 | if (base_surface == NULL) |
| 5065 | return; |
| 5066 | |
| 5067 | surface = get_shell_surface(base_surface); |
Rafael Antognolli | 03b1659 | 2013-12-03 15:35:42 -0200 | [diff] [blame] | 5068 | if (surface == NULL || surface->state.fullscreen || |
| 5069 | surface->state.maximized) |
Kristian Høgsberg | 0c36903 | 2013-02-14 21:31:44 -0500 | [diff] [blame] | 5070 | return; |
| 5071 | |
Derek Foreman | 74de469 | 2015-07-15 13:00:39 -0500 | [diff] [blame] | 5072 | surface_rotate(surface, pointer); |
Kristian Høgsberg | 0c36903 | 2013-02-14 21:31:44 -0500 | [diff] [blame] | 5073 | } |
| 5074 | |
Emilio Pozuelo Monfort | 9e7c759 | 2014-01-30 14:01:10 +0100 | [diff] [blame] | 5075 | /* Move all fullscreen layers down to the current workspace and hide their |
| 5076 | * black views. The surfaces' state is set to both fullscreen and lowered, |
| 5077 | * and this is reversed when such a surface is re-configured, see |
| 5078 | * shell_configure_fullscreen() and shell_ensure_fullscreen_black_view(). |
| 5079 | * |
Mario Kleiner | 9f4d655 | 2015-06-21 21:25:08 +0200 | [diff] [blame] | 5080 | * lowering_output = NULL - Lower on all outputs, else only lower on the |
| 5081 | * specified output. |
| 5082 | * |
Emilio Pozuelo Monfort | 9e7c759 | 2014-01-30 14:01:10 +0100 | [diff] [blame] | 5083 | * This should be used when implementing shell-wide overlays, such as |
Philip Withnall | 83ffd9d | 2013-11-25 18:01:42 +0000 | [diff] [blame] | 5084 | * the alt-tab switcher, which need to de-promote fullscreen layers. */ |
Kristian Høgsberg | 1ef2313 | 2013-12-04 00:20:01 -0800 | [diff] [blame] | 5085 | void |
Mario Kleiner | 9f4d655 | 2015-06-21 21:25:08 +0200 | [diff] [blame] | 5086 | lower_fullscreen_layer(struct desktop_shell *shell, |
| 5087 | struct weston_output *lowering_output) |
Kristian Høgsberg | b0d8e77 | 2012-06-18 16:34:58 -0400 | [diff] [blame] | 5088 | { |
| 5089 | struct workspace *ws; |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 5090 | struct weston_view *view, *prev; |
Kristian Høgsberg | b0d8e77 | 2012-06-18 16:34:58 -0400 | [diff] [blame] | 5091 | |
| 5092 | ws = get_current_workspace(shell); |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 5093 | wl_list_for_each_reverse_safe(view, prev, |
Giulio Camuffo | 412e6a5 | 2014-07-09 22:12:56 +0300 | [diff] [blame] | 5094 | &shell->fullscreen_layer.view_list.link, |
| 5095 | layer_link.link) { |
Emilio Pozuelo Monfort | 9e7c759 | 2014-01-30 14:01:10 +0100 | [diff] [blame] | 5096 | struct shell_surface *shsurf = get_shell_surface(view->surface); |
| 5097 | |
| 5098 | if (!shsurf) |
| 5099 | continue; |
| 5100 | |
Mario Kleiner | 9f4d655 | 2015-06-21 21:25:08 +0200 | [diff] [blame] | 5101 | /* Only lower surfaces which have lowering_output as their fullscreen |
| 5102 | * output, unless a NULL output asks for lowering on all outputs. |
| 5103 | */ |
| 5104 | if (lowering_output && (shsurf->fullscreen_output != lowering_output)) |
| 5105 | continue; |
| 5106 | |
Emilio Pozuelo Monfort | 9e7c759 | 2014-01-30 14:01:10 +0100 | [diff] [blame] | 5107 | /* We can have a non-fullscreen popup for a fullscreen surface |
| 5108 | * in the fullscreen layer. */ |
| 5109 | if (shsurf->state.fullscreen) { |
| 5110 | /* Hide the black view */ |
Giulio Camuffo | 412e6a5 | 2014-07-09 22:12:56 +0300 | [diff] [blame] | 5111 | weston_layer_entry_remove(&shsurf->fullscreen.black_view->layer_link); |
| 5112 | wl_list_init(&shsurf->fullscreen.black_view->layer_link.link); |
Kristian Høgsberg | c991513 | 2014-05-09 16:24:07 -0700 | [diff] [blame] | 5113 | weston_view_damage_below(shsurf->fullscreen.black_view); |
| 5114 | |
Emilio Pozuelo Monfort | 9e7c759 | 2014-01-30 14:01:10 +0100 | [diff] [blame] | 5115 | } |
| 5116 | |
| 5117 | /* Lower the view to the workspace layer */ |
Giulio Camuffo | 412e6a5 | 2014-07-09 22:12:56 +0300 | [diff] [blame] | 5118 | weston_layer_entry_remove(&view->layer_link); |
| 5119 | weston_layer_entry_insert(&ws->layer.view_list, &view->layer_link); |
Philip Withnall | 83ffd9d | 2013-11-25 18:01:42 +0000 | [diff] [blame] | 5120 | weston_view_damage_below(view); |
| 5121 | weston_surface_damage(view->surface); |
Emilio Pozuelo Monfort | 9e7c759 | 2014-01-30 14:01:10 +0100 | [diff] [blame] | 5122 | |
| 5123 | shsurf->state.lowered = true; |
Philip Withnall | 83ffd9d | 2013-11-25 18:01:42 +0000 | [diff] [blame] | 5124 | } |
Kristian Høgsberg | b0d8e77 | 2012-06-18 16:34:58 -0400 | [diff] [blame] | 5125 | } |
| 5126 | |
Kristian Høgsberg | 1ef2313 | 2013-12-04 00:20:01 -0800 | [diff] [blame] | 5127 | void |
Tiago Vignatti | be14326 | 2012-04-16 17:31:41 +0300 | [diff] [blame] | 5128 | activate(struct desktop_shell *shell, struct weston_surface *es, |
Emilio Pozuelo Monfort | 9e7c759 | 2014-01-30 14:01:10 +0100 | [diff] [blame] | 5129 | struct weston_seat *seat, bool configure) |
Kristian Høgsberg | 7584062 | 2011-09-06 13:48:16 -0400 | [diff] [blame] | 5130 | { |
Pekka Paalanen | 01388e2 | 2013-04-25 13:57:44 +0300 | [diff] [blame] | 5131 | struct weston_surface *main_surface; |
Kristian Høgsberg | 2f5faff | 2012-07-31 16:36:34 -0400 | [diff] [blame] | 5132 | struct focus_state *state; |
Jonas Ådahl | 8538b22 | 2012-08-29 22:13:03 +0200 | [diff] [blame] | 5133 | struct workspace *ws; |
Louis-Francis Ratté-Boulianne | b482dbd | 2013-11-19 11:37:11 +0100 | [diff] [blame] | 5134 | struct weston_surface *old_es; |
Rafael Antognolli | 03b1659 | 2013-12-03 15:35:42 -0200 | [diff] [blame] | 5135 | struct shell_surface *shsurf; |
Kristian Høgsberg | 7584062 | 2011-09-06 13:48:16 -0400 | [diff] [blame] | 5136 | |
Pekka Paalanen | 01388e2 | 2013-04-25 13:57:44 +0300 | [diff] [blame] | 5137 | main_surface = weston_surface_get_main_surface(es); |
Mario Kleiner | 9f4d655 | 2015-06-21 21:25:08 +0200 | [diff] [blame] | 5138 | shsurf = get_shell_surface(main_surface); |
| 5139 | assert(shsurf); |
| 5140 | |
| 5141 | /* Only demote fullscreen surfaces on the output of activated shsurf. |
| 5142 | * Leave fullscreen surfaces on unrelated outputs alone. */ |
| 5143 | lower_fullscreen_layer(shell, shsurf->output); |
Pekka Paalanen | 01388e2 | 2013-04-25 13:57:44 +0300 | [diff] [blame] | 5144 | |
Daniel Stone | 37816df | 2012-05-16 18:45:18 +0100 | [diff] [blame] | 5145 | weston_surface_activate(es, seat); |
Kristian Høgsberg | 7584062 | 2011-09-06 13:48:16 -0400 | [diff] [blame] | 5146 | |
Jonas Ådahl | 8538b22 | 2012-08-29 22:13:03 +0200 | [diff] [blame] | 5147 | state = ensure_focus_state(shell, seat); |
| 5148 | if (state == NULL) |
| 5149 | return; |
Kristian Høgsberg | 2f5faff | 2012-07-31 16:36:34 -0400 | [diff] [blame] | 5150 | |
Louis-Francis Ratté-Boulianne | b482dbd | 2013-11-19 11:37:11 +0100 | [diff] [blame] | 5151 | old_es = state->keyboard_focus; |
Kristian Høgsberg | d500bf1 | 2014-01-22 12:25:20 -0800 | [diff] [blame] | 5152 | focus_state_set_focus(state, es); |
Kristian Høgsberg | 2f5faff | 2012-07-31 16:36:34 -0400 | [diff] [blame] | 5153 | |
Emilio Pozuelo Monfort | 9e7c759 | 2014-01-30 14:01:10 +0100 | [diff] [blame] | 5154 | if (shsurf->state.fullscreen && configure) |
Rafael Antognolli | 03b1659 | 2013-12-03 15:35:42 -0200 | [diff] [blame] | 5155 | shell_configure_fullscreen(shsurf); |
| 5156 | else |
Mario Kleiner | 492c12f | 2015-06-21 21:25:12 +0200 | [diff] [blame] | 5157 | restore_output_mode(shsurf->output); |
Louis-Francis Ratté-Boulianne | b482dbd | 2013-11-19 11:37:11 +0100 | [diff] [blame] | 5158 | |
Emilio Pozuelo Monfort | 7908bff | 2014-01-30 13:49:39 +0100 | [diff] [blame] | 5159 | /* Update the surface’s layer. This brings it to the top of the stacking |
| 5160 | * order as appropriate. */ |
| 5161 | shell_surface_update_layer(shsurf); |
| 5162 | |
Philip Withnall | 83ffd9d | 2013-11-25 18:01:42 +0000 | [diff] [blame] | 5163 | if (shell->focus_animation_type != ANIMATION_NONE) { |
| 5164 | ws = get_current_workspace(shell); |
Louis-Francis Ratté-Boulianne | b482dbd | 2013-11-19 11:37:11 +0100 | [diff] [blame] | 5165 | 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] | 5166 | } |
Kristian Høgsberg | 7584062 | 2011-09-06 13:48:16 -0400 | [diff] [blame] | 5167 | } |
| 5168 | |
Alex Wu | 2185843 | 2012-04-01 20:13:08 +0800 | [diff] [blame] | 5169 | /* no-op func for checking black surface */ |
| 5170 | static void |
Jason Ekstrand | 918f2dd | 2013-12-02 21:01:53 -0600 | [diff] [blame] | 5171 | 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] | 5172 | { |
| 5173 | } |
| 5174 | |
Quentin Glidic | c0d79ce | 2013-01-29 14:16:13 +0100 | [diff] [blame] | 5175 | static bool |
Alex Wu | 2185843 | 2012-04-01 20:13:08 +0800 | [diff] [blame] | 5176 | is_black_surface (struct weston_surface *es, struct weston_surface **fs_surface) |
| 5177 | { |
| 5178 | if (es->configure == black_surface_configure) { |
| 5179 | if (fs_surface) |
Giulio Camuffo | 7fe01b1 | 2013-03-28 18:02:42 +0100 | [diff] [blame] | 5180 | *fs_surface = (struct weston_surface *)es->configure_private; |
Alex Wu | 2185843 | 2012-04-01 20:13:08 +0800 | [diff] [blame] | 5181 | return true; |
| 5182 | } |
| 5183 | return false; |
| 5184 | } |
| 5185 | |
Kristian Høgsberg | 7584062 | 2011-09-06 13:48:16 -0400 | [diff] [blame] | 5186 | static void |
Neil Roberts | a28c693 | 2013-10-03 16:43:04 +0100 | [diff] [blame] | 5187 | activate_binding(struct weston_seat *seat, |
| 5188 | struct desktop_shell *shell, |
| 5189 | struct weston_surface *focus) |
Kristian Høgsberg | e1a850e | 2011-12-19 15:18:05 -0500 | [diff] [blame] | 5190 | { |
Pekka Paalanen | 01388e2 | 2013-04-25 13:57:44 +0300 | [diff] [blame] | 5191 | struct weston_surface *main_surface; |
Kristian Høgsberg | e1a850e | 2011-12-19 15:18:05 -0500 | [diff] [blame] | 5192 | |
Alex Wu | 9c35e6b | 2012-03-05 14:13:13 +0800 | [diff] [blame] | 5193 | if (!focus) |
| 5194 | return; |
| 5195 | |
Pekka Paalanen | 01388e2 | 2013-04-25 13:57:44 +0300 | [diff] [blame] | 5196 | if (is_black_surface(focus, &main_surface)) |
| 5197 | focus = main_surface; |
Alex Wu | 4539b08 | 2012-03-01 12:57:46 +0800 | [diff] [blame] | 5198 | |
Pekka Paalanen | 01388e2 | 2013-04-25 13:57:44 +0300 | [diff] [blame] | 5199 | main_surface = weston_surface_get_main_surface(focus); |
| 5200 | if (get_shell_surface_type(main_surface) == SHELL_SURFACE_NONE) |
Kristian Høgsberg | 0636ac3 | 2012-06-27 10:22:15 -0400 | [diff] [blame] | 5201 | return; |
Kristian Høgsberg | 85b2e4b | 2012-06-21 16:49:42 -0400 | [diff] [blame] | 5202 | |
Emilio Pozuelo Monfort | 9e7c759 | 2014-01-30 14:01:10 +0100 | [diff] [blame] | 5203 | activate(shell, focus, seat, true); |
Neil Roberts | a28c693 | 2013-10-03 16:43:04 +0100 | [diff] [blame] | 5204 | } |
| 5205 | |
| 5206 | static void |
Derek Foreman | 8ae2db5 | 2015-07-15 13:00:36 -0500 | [diff] [blame] | 5207 | click_to_activate_binding(struct weston_pointer *pointer, uint32_t time, |
| 5208 | uint32_t button, void *data) |
Neil Roberts | a28c693 | 2013-10-03 16:43:04 +0100 | [diff] [blame] | 5209 | { |
Derek Foreman | 8ae2db5 | 2015-07-15 13:00:36 -0500 | [diff] [blame] | 5210 | if (pointer->grab != &pointer->default_grab) |
Neil Roberts | a28c693 | 2013-10-03 16:43:04 +0100 | [diff] [blame] | 5211 | return; |
Derek Foreman | 8ae2db5 | 2015-07-15 13:00:36 -0500 | [diff] [blame] | 5212 | if (pointer->focus == NULL) |
Kristian Høgsberg | 7c4f6cc | 2014-01-01 16:28:32 -0800 | [diff] [blame] | 5213 | return; |
Neil Roberts | a28c693 | 2013-10-03 16:43:04 +0100 | [diff] [blame] | 5214 | |
Derek Foreman | 8ae2db5 | 2015-07-15 13:00:36 -0500 | [diff] [blame] | 5215 | activate_binding(pointer->seat, data, pointer->focus->surface); |
Neil Roberts | a28c693 | 2013-10-03 16:43:04 +0100 | [diff] [blame] | 5216 | } |
| 5217 | |
| 5218 | static void |
Derek Foreman | 8ae2db5 | 2015-07-15 13:00:36 -0500 | [diff] [blame] | 5219 | touch_to_activate_binding(struct weston_touch *touch, uint32_t time, |
| 5220 | void *data) |
Neil Roberts | a28c693 | 2013-10-03 16:43:04 +0100 | [diff] [blame] | 5221 | { |
Derek Foreman | 8ae2db5 | 2015-07-15 13:00:36 -0500 | [diff] [blame] | 5222 | if (touch->grab != &touch->default_grab) |
Neil Roberts | a28c693 | 2013-10-03 16:43:04 +0100 | [diff] [blame] | 5223 | return; |
Derek Foreman | 8ae2db5 | 2015-07-15 13:00:36 -0500 | [diff] [blame] | 5224 | if (touch->focus == NULL) |
Kristian Høgsberg | 0ed6750 | 2014-01-02 23:00:11 -0800 | [diff] [blame] | 5225 | return; |
Neil Roberts | a28c693 | 2013-10-03 16:43:04 +0100 | [diff] [blame] | 5226 | |
Derek Foreman | 8ae2db5 | 2015-07-15 13:00:36 -0500 | [diff] [blame] | 5227 | activate_binding(touch->seat, data, touch->focus->surface); |
Kristian Høgsberg | e1a850e | 2011-12-19 15:18:05 -0500 | [diff] [blame] | 5228 | } |
| 5229 | |
| 5230 | static void |
Neil Roberts | b4a9170 | 2014-04-09 16:33:32 +0100 | [diff] [blame] | 5231 | unfocus_all_seats(struct desktop_shell *shell) |
| 5232 | { |
| 5233 | struct weston_seat *seat, *next; |
| 5234 | |
| 5235 | wl_list_for_each_safe(seat, next, &shell->compositor->seat_list, link) { |
Derek Foreman | 1281a36 | 2015-07-31 16:55:32 -0500 | [diff] [blame] | 5236 | struct weston_keyboard *keyboard = |
| 5237 | weston_seat_get_keyboard(seat); |
| 5238 | |
| 5239 | if (!keyboard) |
Neil Roberts | b4a9170 | 2014-04-09 16:33:32 +0100 | [diff] [blame] | 5240 | continue; |
| 5241 | |
Derek Foreman | 1281a36 | 2015-07-31 16:55:32 -0500 | [diff] [blame] | 5242 | weston_keyboard_set_focus(keyboard, NULL); |
Neil Roberts | b4a9170 | 2014-04-09 16:33:32 +0100 | [diff] [blame] | 5243 | } |
| 5244 | } |
| 5245 | |
| 5246 | static void |
Ander Conselvan de Oliveira | 19d10ef | 2013-02-21 18:35:20 +0200 | [diff] [blame] | 5247 | lock(struct desktop_shell *shell) |
Kristian Høgsberg | 02ec0a5 | 2011-04-23 13:04:11 -0400 | [diff] [blame] | 5248 | { |
Kristian Høgsberg | 4476aaf | 2012-06-25 14:03:13 -0400 | [diff] [blame] | 5249 | struct workspace *ws = get_current_workspace(shell); |
Pekka Paalanen | f0fc70d | 2011-11-15 13:34:54 +0200 | [diff] [blame] | 5250 | |
Tiago Vignatti | 8e53c7f | 2012-02-29 19:53:50 +0200 | [diff] [blame] | 5251 | if (shell->locked) { |
Ander Conselvan de Oliveira | 87524b6 | 2013-02-21 18:35:22 +0200 | [diff] [blame] | 5252 | weston_compositor_sleep(shell->compositor); |
Pekka Paalanen | f0fc70d | 2011-11-15 13:34:54 +0200 | [diff] [blame] | 5253 | return; |
Tiago Vignatti | 8e53c7f | 2012-02-29 19:53:50 +0200 | [diff] [blame] | 5254 | } |
Pekka Paalanen | 9ef3e01 | 2011-11-15 13:34:48 +0200 | [diff] [blame] | 5255 | |
| 5256 | shell->locked = true; |
Pekka Paalanen | f0fc70d | 2011-11-15 13:34:54 +0200 | [diff] [blame] | 5257 | |
Kristian Høgsberg | 3be2ce9 | 2012-02-29 12:42:35 -0500 | [diff] [blame] | 5258 | /* Hide all surfaces by removing the fullscreen, panel and |
| 5259 | * toplevel layers. This way nothing else can show or receive |
| 5260 | * input events while we are locked. */ |
Pekka Paalanen | f0fc70d | 2011-11-15 13:34:54 +0200 | [diff] [blame] | 5261 | |
Kristian Høgsberg | 3be2ce9 | 2012-02-29 12:42:35 -0500 | [diff] [blame] | 5262 | wl_list_remove(&shell->panel_layer.link); |
Kristian Høgsberg | 3be2ce9 | 2012-02-29 12:42:35 -0500 | [diff] [blame] | 5263 | wl_list_remove(&shell->fullscreen_layer.link); |
Philipp Brüschweiler | 711fda8 | 2012-08-09 18:50:43 +0200 | [diff] [blame] | 5264 | if (shell->showing_input_panels) |
| 5265 | wl_list_remove(&shell->input_panel_layer.link); |
Kristian Høgsberg | 4476aaf | 2012-06-25 14:03:13 -0400 | [diff] [blame] | 5266 | wl_list_remove(&ws->layer.link); |
Kristian Høgsberg | 3be2ce9 | 2012-02-29 12:42:35 -0500 | [diff] [blame] | 5267 | wl_list_insert(&shell->compositor->cursor_layer.link, |
| 5268 | &shell->lock_layer.link); |
Pekka Paalanen | f0fc70d | 2011-11-15 13:34:54 +0200 | [diff] [blame] | 5269 | |
Derek Foreman | 004b4a1 | 2015-07-20 16:28:13 -0500 | [diff] [blame] | 5270 | weston_compositor_sleep(shell->compositor); |
| 5271 | |
Neil Roberts | b4a9170 | 2014-04-09 16:33:32 +0100 | [diff] [blame] | 5272 | /* Remove the keyboard focus on all seats. This will be |
| 5273 | * restored to the workspace's saved state via |
| 5274 | * restore_focus_state when the compositor is unlocked */ |
| 5275 | unfocus_all_seats(shell); |
| 5276 | |
Pekka Paalanen | f0fc70d | 2011-11-15 13:34:54 +0200 | [diff] [blame] | 5277 | /* TODO: disable bindings that should not work while locked. */ |
| 5278 | |
| 5279 | /* All this must be undone in resume_desktop(). */ |
Pekka Paalanen | 9ef3e01 | 2011-11-15 13:34:48 +0200 | [diff] [blame] | 5280 | } |
| 5281 | |
| 5282 | static void |
Ander Conselvan de Oliveira | 19d10ef | 2013-02-21 18:35:20 +0200 | [diff] [blame] | 5283 | unlock(struct desktop_shell *shell) |
Pekka Paalanen | 9ef3e01 | 2011-11-15 13:34:48 +0200 | [diff] [blame] | 5284 | { |
Pekka Paalanen | d81c216 | 2011-11-16 13:47:34 +0200 | [diff] [blame] | 5285 | if (!shell->locked || shell->lock_surface) { |
Ander Conselvan de Oliveira | 87524b6 | 2013-02-21 18:35:22 +0200 | [diff] [blame] | 5286 | shell_fade(shell, FADE_IN); |
Pekka Paalanen | 9ef3e01 | 2011-11-15 13:34:48 +0200 | [diff] [blame] | 5287 | return; |
| 5288 | } |
| 5289 | |
| 5290 | /* If desktop-shell client has gone away, unlock immediately. */ |
| 5291 | if (!shell->child.desktop_shell) { |
Pekka Paalanen | f0fc70d | 2011-11-15 13:34:54 +0200 | [diff] [blame] | 5292 | resume_desktop(shell); |
Pekka Paalanen | 9ef3e01 | 2011-11-15 13:34:48 +0200 | [diff] [blame] | 5293 | return; |
| 5294 | } |
| 5295 | |
| 5296 | if (shell->prepare_event_sent) |
| 5297 | return; |
| 5298 | |
Kristian Høgsberg | 0b5cd0c | 2012-03-04 21:57:37 -0500 | [diff] [blame] | 5299 | desktop_shell_send_prepare_lock_surface(shell->child.desktop_shell); |
Pekka Paalanen | 9ef3e01 | 2011-11-15 13:34:48 +0200 | [diff] [blame] | 5300 | shell->prepare_event_sent = true; |
Kristian Høgsberg | 02ec0a5 | 2011-04-23 13:04:11 -0400 | [diff] [blame] | 5301 | } |
| 5302 | |
| 5303 | static void |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 5304 | shell_fade_done(struct weston_view_animation *animation, void *data) |
Ander Conselvan de Oliveira | 19d10ef | 2013-02-21 18:35:20 +0200 | [diff] [blame] | 5305 | { |
| 5306 | struct desktop_shell *shell = data; |
| 5307 | |
| 5308 | shell->fade.animation = NULL; |
| 5309 | |
| 5310 | switch (shell->fade.type) { |
| 5311 | case FADE_IN: |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 5312 | weston_surface_destroy(shell->fade.view->surface); |
| 5313 | shell->fade.view = NULL; |
Ander Conselvan de Oliveira | 19d10ef | 2013-02-21 18:35:20 +0200 | [diff] [blame] | 5314 | break; |
| 5315 | case FADE_OUT: |
Ander Conselvan de Oliveira | 19d10ef | 2013-02-21 18:35:20 +0200 | [diff] [blame] | 5316 | lock(shell); |
| 5317 | break; |
Philip Withnall | 4a86a0a | 2013-11-25 18:01:32 +0000 | [diff] [blame] | 5318 | default: |
| 5319 | break; |
Ander Conselvan de Oliveira | 19d10ef | 2013-02-21 18:35:20 +0200 | [diff] [blame] | 5320 | } |
| 5321 | } |
| 5322 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 5323 | static struct weston_view * |
Pekka Paalanen | 79346ab | 2013-05-22 18:03:09 +0300 | [diff] [blame] | 5324 | shell_fade_create_surface(struct desktop_shell *shell) |
Ander Conselvan de Oliveira | 19d10ef | 2013-02-21 18:35:20 +0200 | [diff] [blame] | 5325 | { |
| 5326 | struct weston_compositor *compositor = shell->compositor; |
| 5327 | struct weston_surface *surface; |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 5328 | struct weston_view *view; |
Pekka Paalanen | 79346ab | 2013-05-22 18:03:09 +0300 | [diff] [blame] | 5329 | |
| 5330 | surface = weston_surface_create(compositor); |
| 5331 | if (!surface) |
| 5332 | return NULL; |
| 5333 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 5334 | view = weston_view_create(surface); |
| 5335 | if (!view) { |
| 5336 | weston_surface_destroy(surface); |
| 5337 | return NULL; |
| 5338 | } |
| 5339 | |
Jason Ekstrand | 5c11a33 | 2013-12-04 20:32:03 -0600 | [diff] [blame] | 5340 | weston_surface_set_size(surface, 8192, 8192); |
Jason Ekstrand | 918f2dd | 2013-12-02 21:01:53 -0600 | [diff] [blame] | 5341 | weston_view_set_position(view, 0, 0); |
Pekka Paalanen | 79346ab | 2013-05-22 18:03:09 +0300 | [diff] [blame] | 5342 | 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] | 5343 | weston_layer_entry_insert(&compositor->fade_layer.view_list, |
| 5344 | &view->layer_link); |
Pekka Paalanen | 79346ab | 2013-05-22 18:03:09 +0300 | [diff] [blame] | 5345 | pixman_region32_init(&surface->input); |
| 5346 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 5347 | return view; |
Pekka Paalanen | 79346ab | 2013-05-22 18:03:09 +0300 | [diff] [blame] | 5348 | } |
| 5349 | |
| 5350 | static void |
| 5351 | shell_fade(struct desktop_shell *shell, enum fade_type type) |
| 5352 | { |
Ander Conselvan de Oliveira | 19d10ef | 2013-02-21 18:35:20 +0200 | [diff] [blame] | 5353 | float tint; |
| 5354 | |
| 5355 | switch (type) { |
| 5356 | case FADE_IN: |
| 5357 | tint = 0.0; |
| 5358 | break; |
| 5359 | case FADE_OUT: |
| 5360 | tint = 1.0; |
| 5361 | break; |
| 5362 | default: |
| 5363 | weston_log("shell: invalid fade type\n"); |
| 5364 | return; |
| 5365 | } |
| 5366 | |
| 5367 | shell->fade.type = type; |
| 5368 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 5369 | if (shell->fade.view == NULL) { |
| 5370 | shell->fade.view = shell_fade_create_surface(shell); |
| 5371 | if (!shell->fade.view) |
Ander Conselvan de Oliveira | 19d10ef | 2013-02-21 18:35:20 +0200 | [diff] [blame] | 5372 | return; |
| 5373 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 5374 | shell->fade.view->alpha = 1.0 - tint; |
| 5375 | weston_view_update_transform(shell->fade.view); |
Ander Conselvan de Oliveira | 19d10ef | 2013-02-21 18:35:20 +0200 | [diff] [blame] | 5376 | } |
| 5377 | |
Kristian Høgsberg | 87d3b61 | 2014-01-19 21:48:10 -0800 | [diff] [blame] | 5378 | if (shell->fade.view->output == NULL) { |
| 5379 | /* If the black view gets a NULL output, we lost the |
| 5380 | * last output and we'll just cancel the fade. This |
| 5381 | * happens when you close the last window under the |
| 5382 | * X11 or Wayland backends. */ |
| 5383 | shell->locked = false; |
| 5384 | weston_surface_destroy(shell->fade.view->surface); |
| 5385 | shell->fade.view = NULL; |
| 5386 | } else if (shell->fade.animation) { |
Kristian Høgsberg | 5281fb1 | 2013-06-17 10:10:28 -0400 | [diff] [blame] | 5387 | weston_fade_update(shell->fade.animation, tint); |
Kristian Høgsberg | 87d3b61 | 2014-01-19 21:48:10 -0800 | [diff] [blame] | 5388 | } else { |
Ander Conselvan de Oliveira | 19d10ef | 2013-02-21 18:35:20 +0200 | [diff] [blame] | 5389 | shell->fade.animation = |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 5390 | weston_fade_run(shell->fade.view, |
Kristian Høgsberg | 5281fb1 | 2013-06-17 10:10:28 -0400 | [diff] [blame] | 5391 | 1.0 - tint, tint, 300.0, |
Ander Conselvan de Oliveira | 19d10ef | 2013-02-21 18:35:20 +0200 | [diff] [blame] | 5392 | shell_fade_done, shell); |
Kristian Høgsberg | 87d3b61 | 2014-01-19 21:48:10 -0800 | [diff] [blame] | 5393 | } |
Ander Conselvan de Oliveira | 19d10ef | 2013-02-21 18:35:20 +0200 | [diff] [blame] | 5394 | } |
| 5395 | |
| 5396 | static void |
Pekka Paalanen | 79346ab | 2013-05-22 18:03:09 +0300 | [diff] [blame] | 5397 | do_shell_fade_startup(void *data) |
| 5398 | { |
| 5399 | struct desktop_shell *shell = data; |
| 5400 | |
Pekka Paalanen | 23ed5f2 | 2015-05-26 11:54:52 +0300 | [diff] [blame] | 5401 | if (shell->startup_animation_type == ANIMATION_FADE) { |
Kristian Høgsberg | 724c8d9 | 2013-10-16 11:38:24 -0700 | [diff] [blame] | 5402 | shell_fade(shell, FADE_IN); |
Pekka Paalanen | 23ed5f2 | 2015-05-26 11:54:52 +0300 | [diff] [blame] | 5403 | } else { |
| 5404 | weston_log("desktop shell: " |
| 5405 | "unexpected fade-in animation type %d\n", |
| 5406 | shell->startup_animation_type); |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 5407 | weston_surface_destroy(shell->fade.view->surface); |
| 5408 | shell->fade.view = NULL; |
Kristian Høgsberg | 724c8d9 | 2013-10-16 11:38:24 -0700 | [diff] [blame] | 5409 | } |
Pekka Paalanen | 79346ab | 2013-05-22 18:03:09 +0300 | [diff] [blame] | 5410 | } |
| 5411 | |
| 5412 | static void |
| 5413 | shell_fade_startup(struct desktop_shell *shell) |
| 5414 | { |
| 5415 | struct wl_event_loop *loop; |
| 5416 | |
| 5417 | if (!shell->fade.startup_timer) |
| 5418 | return; |
| 5419 | |
| 5420 | wl_event_source_remove(shell->fade.startup_timer); |
| 5421 | shell->fade.startup_timer = NULL; |
| 5422 | |
| 5423 | loop = wl_display_get_event_loop(shell->compositor->wl_display); |
| 5424 | wl_event_loop_add_idle(loop, do_shell_fade_startup, shell); |
| 5425 | } |
| 5426 | |
| 5427 | static int |
| 5428 | fade_startup_timeout(void *data) |
| 5429 | { |
| 5430 | struct desktop_shell *shell = data; |
| 5431 | |
| 5432 | shell_fade_startup(shell); |
| 5433 | return 0; |
| 5434 | } |
| 5435 | |
| 5436 | static void |
| 5437 | shell_fade_init(struct desktop_shell *shell) |
| 5438 | { |
| 5439 | /* Make compositor output all black, and wait for the desktop-shell |
| 5440 | * client to signal it is ready, then fade in. The timer triggers a |
| 5441 | * fade-in, in case the desktop-shell client takes too long. |
| 5442 | */ |
| 5443 | |
| 5444 | struct wl_event_loop *loop; |
| 5445 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 5446 | if (shell->fade.view != NULL) { |
Pekka Paalanen | 79346ab | 2013-05-22 18:03:09 +0300 | [diff] [blame] | 5447 | weston_log("%s: warning: fade surface already exists\n", |
| 5448 | __func__); |
| 5449 | return; |
| 5450 | } |
| 5451 | |
Pekka Paalanen | 23ed5f2 | 2015-05-26 11:54:52 +0300 | [diff] [blame] | 5452 | if (shell->startup_animation_type == ANIMATION_NONE) |
| 5453 | return; |
| 5454 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 5455 | shell->fade.view = shell_fade_create_surface(shell); |
| 5456 | if (!shell->fade.view) |
Pekka Paalanen | 79346ab | 2013-05-22 18:03:09 +0300 | [diff] [blame] | 5457 | return; |
| 5458 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 5459 | weston_view_update_transform(shell->fade.view); |
| 5460 | weston_surface_damage(shell->fade.view->surface); |
Pekka Paalanen | 79346ab | 2013-05-22 18:03:09 +0300 | [diff] [blame] | 5461 | |
| 5462 | loop = wl_display_get_event_loop(shell->compositor->wl_display); |
| 5463 | shell->fade.startup_timer = |
| 5464 | wl_event_loop_add_timer(loop, fade_startup_timeout, shell); |
| 5465 | wl_event_source_timer_update(shell->fade.startup_timer, 15000); |
| 5466 | } |
| 5467 | |
| 5468 | static void |
Ander Conselvan de Oliveira | a457563 | 2013-02-21 18:35:23 +0200 | [diff] [blame] | 5469 | idle_handler(struct wl_listener *listener, void *data) |
Ander Conselvan de Oliveira | 19d10ef | 2013-02-21 18:35:20 +0200 | [diff] [blame] | 5470 | { |
| 5471 | struct desktop_shell *shell = |
Ander Conselvan de Oliveira | a457563 | 2013-02-21 18:35:23 +0200 | [diff] [blame] | 5472 | container_of(listener, struct desktop_shell, idle_listener); |
Kristian Høgsberg | 27d5fa8 | 2014-01-17 16:22:50 -0800 | [diff] [blame] | 5473 | struct weston_seat *seat; |
| 5474 | |
Jonny Lamb | 76cf1fe | 2014-08-20 11:27:10 +0200 | [diff] [blame] | 5475 | wl_list_for_each(seat, &shell->compositor->seat_list, link) { |
Derek Foreman | 1281a36 | 2015-07-31 16:55:32 -0500 | [diff] [blame] | 5476 | struct weston_touch *touch = weston_seat_get_touch(seat); |
| 5477 | struct weston_pointer *pointer = weston_seat_get_pointer(seat); |
| 5478 | |
| 5479 | if (pointer) |
| 5480 | popup_grab_end(pointer); |
| 5481 | if (touch) |
| 5482 | touch_popup_grab_end(touch); |
Jonny Lamb | 76cf1fe | 2014-08-20 11:27:10 +0200 | [diff] [blame] | 5483 | } |
Ander Conselvan de Oliveira | 19d10ef | 2013-02-21 18:35:20 +0200 | [diff] [blame] | 5484 | |
| 5485 | shell_fade(shell, FADE_OUT); |
| 5486 | /* lock() is called from shell_fade_done() */ |
| 5487 | } |
| 5488 | |
| 5489 | static void |
Ander Conselvan de Oliveira | a457563 | 2013-02-21 18:35:23 +0200 | [diff] [blame] | 5490 | wake_handler(struct wl_listener *listener, void *data) |
Ander Conselvan de Oliveira | 19d10ef | 2013-02-21 18:35:20 +0200 | [diff] [blame] | 5491 | { |
| 5492 | struct desktop_shell *shell = |
Ander Conselvan de Oliveira | a457563 | 2013-02-21 18:35:23 +0200 | [diff] [blame] | 5493 | container_of(listener, struct desktop_shell, wake_listener); |
Ander Conselvan de Oliveira | 19d10ef | 2013-02-21 18:35:20 +0200 | [diff] [blame] | 5494 | |
Ander Conselvan de Oliveira | 19d10ef | 2013-02-21 18:35:20 +0200 | [diff] [blame] | 5495 | unlock(shell); |
| 5496 | } |
| 5497 | |
| 5498 | static void |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 5499 | center_on_output(struct weston_view *view, struct weston_output *output) |
Pekka Paalanen | 77346a6 | 2011-11-30 16:26:35 +0200 | [diff] [blame] | 5500 | { |
Giulio Camuffo | b836664 | 2013-04-25 13:57:46 +0300 | [diff] [blame] | 5501 | int32_t surf_x, surf_y, width, height; |
Ander Conselvan de Oliveira | 012b4c7 | 2012-11-27 17:03:42 +0200 | [diff] [blame] | 5502 | float x, y; |
Pekka Paalanen | 77346a6 | 2011-11-30 16:26:35 +0200 | [diff] [blame] | 5503 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 5504 | surface_subsurfaces_boundingbox(view->surface, &surf_x, &surf_y, &width, &height); |
Giulio Camuffo | b836664 | 2013-04-25 13:57:46 +0300 | [diff] [blame] | 5505 | |
| 5506 | x = output->x + (output->width - width) / 2 - surf_x / 2; |
| 5507 | y = output->y + (output->height - height) / 2 - surf_y / 2; |
Ander Conselvan de Oliveira | 012b4c7 | 2012-11-27 17:03:42 +0200 | [diff] [blame] | 5508 | |
Jason Ekstrand | 918f2dd | 2013-12-02 21:01:53 -0600 | [diff] [blame] | 5509 | weston_view_set_position(view, x, y); |
Pekka Paalanen | 77346a6 | 2011-11-30 16:26:35 +0200 | [diff] [blame] | 5510 | } |
| 5511 | |
| 5512 | static void |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 5513 | weston_view_set_initial_position(struct weston_view *view, |
| 5514 | struct desktop_shell *shell) |
Rob Bradford | ac63e5b | 2012-08-13 14:07:52 +0100 | [diff] [blame] | 5515 | { |
| 5516 | struct weston_compositor *compositor = shell->compositor; |
| 5517 | int ix = 0, iy = 0; |
Jonny Lamb | d73c694 | 2014-08-20 15:53:20 +0200 | [diff] [blame] | 5518 | int32_t range_x, range_y; |
Derek Foreman | f814c5d | 2015-04-15 12:23:54 -0500 | [diff] [blame] | 5519 | int32_t x, y; |
Rob Bradford | ac63e5b | 2012-08-13 14:07:52 +0100 | [diff] [blame] | 5520 | struct weston_output *output, *target_output = NULL; |
| 5521 | struct weston_seat *seat; |
Jonny Lamb | d73c694 | 2014-08-20 15:53:20 +0200 | [diff] [blame] | 5522 | pixman_rectangle32_t area; |
Rob Bradford | ac63e5b | 2012-08-13 14:07:52 +0100 | [diff] [blame] | 5523 | |
| 5524 | /* As a heuristic place the new window on the same output as the |
| 5525 | * pointer. Falling back to the output containing 0, 0. |
| 5526 | * |
| 5527 | * TODO: Do something clever for touch too? |
| 5528 | */ |
| 5529 | wl_list_for_each(seat, &compositor->seat_list, link) { |
Derek Foreman | 1281a36 | 2015-07-31 16:55:32 -0500 | [diff] [blame] | 5530 | struct weston_pointer *pointer = weston_seat_get_pointer(seat); |
| 5531 | |
| 5532 | if (pointer) { |
| 5533 | ix = wl_fixed_to_int(pointer->x); |
| 5534 | iy = wl_fixed_to_int(pointer->y); |
Rob Bradford | ac63e5b | 2012-08-13 14:07:52 +0100 | [diff] [blame] | 5535 | break; |
| 5536 | } |
| 5537 | } |
| 5538 | |
| 5539 | wl_list_for_each(output, &compositor->output_list, link) { |
| 5540 | if (pixman_region32_contains_point(&output->region, ix, iy, NULL)) { |
| 5541 | target_output = output; |
| 5542 | break; |
| 5543 | } |
| 5544 | } |
| 5545 | |
| 5546 | if (!target_output) { |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 5547 | weston_view_set_position(view, 10 + random() % 400, |
| 5548 | 10 + random() % 400); |
Rob Bradford | ac63e5b | 2012-08-13 14:07:52 +0100 | [diff] [blame] | 5549 | return; |
| 5550 | } |
| 5551 | |
| 5552 | /* Valid range within output where the surface will still be onscreen. |
| 5553 | * If this is negative it means that the surface is bigger than |
| 5554 | * output. |
| 5555 | */ |
Jonny Lamb | d73c694 | 2014-08-20 15:53:20 +0200 | [diff] [blame] | 5556 | get_output_work_area(shell, target_output, &area); |
| 5557 | |
Derek Foreman | f814c5d | 2015-04-15 12:23:54 -0500 | [diff] [blame] | 5558 | x = area.x; |
| 5559 | y = area.y; |
Jonny Lamb | d73c694 | 2014-08-20 15:53:20 +0200 | [diff] [blame] | 5560 | range_x = area.width - view->surface->width; |
| 5561 | range_y = area.height - view->surface->height; |
Rob Bradford | ac63e5b | 2012-08-13 14:07:52 +0100 | [diff] [blame] | 5562 | |
Rob Bradford | 4cb88c7 | 2012-08-13 15:18:44 +0100 | [diff] [blame] | 5563 | if (range_x > 0) |
Derek Foreman | f814c5d | 2015-04-15 12:23:54 -0500 | [diff] [blame] | 5564 | x += random() % range_x; |
Rob Bradford | 4cb88c7 | 2012-08-13 15:18:44 +0100 | [diff] [blame] | 5565 | |
| 5566 | if (range_y > 0) |
Derek Foreman | f814c5d | 2015-04-15 12:23:54 -0500 | [diff] [blame] | 5567 | y += random() % range_y; |
Rob Bradford | ac63e5b | 2012-08-13 14:07:52 +0100 | [diff] [blame] | 5568 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 5569 | weston_view_set_position(view, x, y); |
Rob Bradford | ac63e5b | 2012-08-13 14:07:52 +0100 | [diff] [blame] | 5570 | } |
| 5571 | |
| 5572 | static void |
Jonny Lamb | d73c694 | 2014-08-20 15:53:20 +0200 | [diff] [blame] | 5573 | set_maximized_position(struct desktop_shell *shell, |
| 5574 | struct shell_surface *shsurf) |
| 5575 | { |
| 5576 | int32_t surf_x, surf_y; |
| 5577 | pixman_rectangle32_t area; |
Marek Chalupa | 8b771af | 2014-09-01 17:20:33 +0200 | [diff] [blame] | 5578 | pixman_box32_t *e; |
Jonny Lamb | d73c694 | 2014-08-20 15:53:20 +0200 | [diff] [blame] | 5579 | |
Jonny Lamb | d73c694 | 2014-08-20 15:53:20 +0200 | [diff] [blame] | 5580 | get_output_work_area(shell, shsurf->output, &area); |
Giulio Camuffo | 7a8d67d | 2015-01-09 20:10:45 +0200 | [diff] [blame] | 5581 | if (shsurf->has_set_geometry) { |
| 5582 | surf_x = shsurf->geometry.x; |
| 5583 | surf_y = shsurf->geometry.y; |
| 5584 | } else { |
| 5585 | surface_subsurfaces_boundingbox(shsurf->surface, |
| 5586 | &surf_x, &surf_y, NULL, NULL); |
| 5587 | } |
Marek Chalupa | 8b771af | 2014-09-01 17:20:33 +0200 | [diff] [blame] | 5588 | e = pixman_region32_extents(&shsurf->output->region); |
Jonny Lamb | d73c694 | 2014-08-20 15:53:20 +0200 | [diff] [blame] | 5589 | |
| 5590 | weston_view_set_position(shsurf->view, |
Marek Chalupa | 8b771af | 2014-09-01 17:20:33 +0200 | [diff] [blame] | 5591 | e->x1 + area.x - surf_x, |
| 5592 | e->y1 + area.y - surf_y); |
Jonny Lamb | d73c694 | 2014-08-20 15:53:20 +0200 | [diff] [blame] | 5593 | } |
| 5594 | |
| 5595 | static void |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 5596 | map(struct desktop_shell *shell, struct shell_surface *shsurf, |
Jason Ekstrand | 918f2dd | 2013-12-02 21:01:53 -0600 | [diff] [blame] | 5597 | int32_t sx, int32_t sy) |
Kristian Høgsberg | 02ec0a5 | 2011-04-23 13:04:11 -0400 | [diff] [blame] | 5598 | { |
Kristian Høgsberg | 8334bc1 | 2012-01-03 10:29:47 -0500 | [diff] [blame] | 5599 | struct weston_compositor *compositor = shell->compositor; |
Daniel Stone | b210468 | 2012-05-30 16:31:56 +0100 | [diff] [blame] | 5600 | struct weston_seat *seat; |
Pekka Paalanen | 57da4a8 | 2011-11-23 16:42:16 +0200 | [diff] [blame] | 5601 | |
Pekka Paalanen | 77346a6 | 2011-11-30 16:26:35 +0200 | [diff] [blame] | 5602 | /* initial positioning, see also configure() */ |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 5603 | switch (shsurf->type) { |
Rafael Antognolli | ed207b4 | 2013-12-03 15:35:43 -0200 | [diff] [blame] | 5604 | case SHELL_SURFACE_TOPLEVEL: |
Rafael Antognolli | 03b1659 | 2013-12-03 15:35:42 -0200 | [diff] [blame] | 5605 | if (shsurf->state.fullscreen) { |
| 5606 | center_on_output(shsurf->view, shsurf->fullscreen_output); |
| 5607 | shell_map_fullscreen(shsurf); |
| 5608 | } else if (shsurf->state.maximized) { |
Jonny Lamb | d73c694 | 2014-08-20 15:53:20 +0200 | [diff] [blame] | 5609 | set_maximized_position(shell, shsurf); |
Rafael Antognolli | ed207b4 | 2013-12-03 15:35:43 -0200 | [diff] [blame] | 5610 | } else if (!shsurf->state.relative) { |
Rafael Antognolli | 03b1659 | 2013-12-03 15:35:42 -0200 | [diff] [blame] | 5611 | weston_view_set_initial_position(shsurf->view, shell); |
| 5612 | } |
Juan Zhao | 96879df | 2012-02-07 08:45:41 +0800 | [diff] [blame] | 5613 | break; |
Tiago Vignatti | 0f99701 | 2012-02-10 16:17:23 +0200 | [diff] [blame] | 5614 | case SHELL_SURFACE_POPUP: |
Jasper St. Pierre | da6ecd0 | 2015-02-27 18:35:45 +0800 | [diff] [blame] | 5615 | if (shell_map_popup(shsurf) != 0) |
| 5616 | return; |
Rob Bradford | db99938 | 2012-12-06 12:07:48 +0000 | [diff] [blame] | 5617 | break; |
Ander Conselvan de Oliveira | e9e0515 | 2012-02-15 17:02:56 +0200 | [diff] [blame] | 5618 | case SHELL_SURFACE_NONE: |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 5619 | weston_view_set_position(shsurf->view, |
| 5620 | shsurf->view->geometry.x + sx, |
| 5621 | shsurf->view->geometry.y + sy); |
Tiago Vignatti | 0f99701 | 2012-02-10 16:17:23 +0200 | [diff] [blame] | 5622 | break; |
Philip Withnall | 0f640e2 | 2013-11-25 18:01:31 +0000 | [diff] [blame] | 5623 | case SHELL_SURFACE_XWAYLAND: |
Pekka Paalanen | 77346a6 | 2011-11-30 16:26:35 +0200 | [diff] [blame] | 5624 | default: |
| 5625 | ; |
| 5626 | } |
Kristian Høgsberg | 7584062 | 2011-09-06 13:48:16 -0400 | [diff] [blame] | 5627 | |
Philip Withnall | e1d75ae | 2013-11-25 18:01:41 +0000 | [diff] [blame] | 5628 | /* Surface stacking order, see also activate(). */ |
| 5629 | shell_surface_update_layer(shsurf); |
Pekka Paalanen | f0fc70d | 2011-11-15 13:34:54 +0200 | [diff] [blame] | 5630 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 5631 | if (shsurf->type != SHELL_SURFACE_NONE) { |
| 5632 | weston_view_update_transform(shsurf->view); |
Rafael Antognolli | 03b1659 | 2013-12-03 15:35:42 -0200 | [diff] [blame] | 5633 | if (shsurf->state.maximized) { |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 5634 | shsurf->surface->output = shsurf->output; |
| 5635 | shsurf->view->output = shsurf->output; |
| 5636 | } |
Ander Conselvan de Oliveira | de56c31 | 2012-03-05 15:39:23 +0200 | [diff] [blame] | 5637 | } |
Kristian Høgsberg | 2f88a40 | 2011-12-04 15:32:59 -0500 | [diff] [blame] | 5638 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 5639 | switch (shsurf->type) { |
Tiago Vignatti | fb2adba | 2013-06-12 15:43:21 -0300 | [diff] [blame] | 5640 | /* XXX: xwayland's using the same fields for transient type */ |
| 5641 | case SHELL_SURFACE_XWAYLAND: |
Tiago Vignatti | 99aeb1e | 2012-05-23 22:06:26 +0300 | [diff] [blame] | 5642 | if (shsurf->transient.flags == |
| 5643 | WL_SHELL_SURFACE_TRANSIENT_INACTIVE) |
| 5644 | break; |
| 5645 | case SHELL_SURFACE_TOPLEVEL: |
Rafael Antognolli | ed207b4 | 2013-12-03 15:35:43 -0200 | [diff] [blame] | 5646 | if (shsurf->state.relative && |
| 5647 | shsurf->transient.flags == WL_SHELL_SURFACE_TRANSIENT_INACTIVE) |
| 5648 | break; |
Rafael Antognolli | ba5d2d7 | 2013-12-04 17:49:55 -0200 | [diff] [blame] | 5649 | if (shell->locked) |
Rafael Antognolli | ed207b4 | 2013-12-03 15:35:43 -0200 | [diff] [blame] | 5650 | break; |
| 5651 | wl_list_for_each(seat, &compositor->seat_list, link) |
Emilio Pozuelo Monfort | 9e7c759 | 2014-01-30 14:01:10 +0100 | [diff] [blame] | 5652 | activate(shell, shsurf->surface, seat, true); |
Juan Zhao | 7bb92f0 | 2011-12-15 11:31:51 -0500 | [diff] [blame] | 5653 | break; |
Philip Withnall | 0f640e2 | 2013-11-25 18:01:31 +0000 | [diff] [blame] | 5654 | case SHELL_SURFACE_POPUP: |
| 5655 | case SHELL_SURFACE_NONE: |
Juan Zhao | 7bb92f0 | 2011-12-15 11:31:51 -0500 | [diff] [blame] | 5656 | default: |
| 5657 | break; |
| 5658 | } |
| 5659 | |
Rafael Antognolli | 03b1659 | 2013-12-03 15:35:42 -0200 | [diff] [blame] | 5660 | if (shsurf->type == SHELL_SURFACE_TOPLEVEL && |
| 5661 | !shsurf->state.maximized && !shsurf->state.fullscreen) |
Juan Zhao | e10d279 | 2012-04-25 19:09:52 +0800 | [diff] [blame] | 5662 | { |
| 5663 | switch (shell->win_animation_type) { |
| 5664 | case ANIMATION_FADE: |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 5665 | 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] | 5666 | break; |
| 5667 | case ANIMATION_ZOOM: |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 5668 | weston_zoom_run(shsurf->view, 0.5, 1.0, NULL, NULL); |
Juan Zhao | e10d279 | 2012-04-25 19:09:52 +0800 | [diff] [blame] | 5669 | break; |
Philip Withnall | 4a86a0a | 2013-11-25 18:01:32 +0000 | [diff] [blame] | 5670 | case ANIMATION_NONE: |
Juan Zhao | e10d279 | 2012-04-25 19:09:52 +0800 | [diff] [blame] | 5671 | default: |
| 5672 | break; |
| 5673 | } |
| 5674 | } |
Kristian Høgsberg | 32e24cc | 2011-11-09 12:07:35 -0500 | [diff] [blame] | 5675 | } |
| 5676 | |
| 5677 | static void |
Tiago Vignatti | be14326 | 2012-04-16 17:31:41 +0300 | [diff] [blame] | 5678 | configure(struct desktop_shell *shell, struct weston_surface *surface, |
Jason Ekstrand | 918f2dd | 2013-12-02 21:01:53 -0600 | [diff] [blame] | 5679 | float x, float y) |
Kristian Høgsberg | 32e24cc | 2011-11-09 12:07:35 -0500 | [diff] [blame] | 5680 | { |
Pekka Paalanen | 77346a6 | 2011-11-30 16:26:35 +0200 | [diff] [blame] | 5681 | struct shell_surface *shsurf; |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 5682 | struct weston_view *view; |
Kristian Høgsberg | 32e24cc | 2011-11-09 12:07:35 -0500 | [diff] [blame] | 5683 | |
Pekka Paalanen | 77346a6 | 2011-11-30 16:26:35 +0200 | [diff] [blame] | 5684 | shsurf = get_shell_surface(surface); |
Pekka Paalanen | 77346a6 | 2011-11-30 16:26:35 +0200 | [diff] [blame] | 5685 | |
U. Artie Eoff | cf5737a | 2014-01-17 10:08:25 -0800 | [diff] [blame] | 5686 | assert(shsurf); |
| 5687 | |
Rafael Antognolli | 03b1659 | 2013-12-03 15:35:42 -0200 | [diff] [blame] | 5688 | if (shsurf->state.fullscreen) |
Alex Wu | 4539b08 | 2012-03-01 12:57:46 +0800 | [diff] [blame] | 5689 | shell_configure_fullscreen(shsurf); |
Rafael Antognolli | 03b1659 | 2013-12-03 15:35:42 -0200 | [diff] [blame] | 5690 | else if (shsurf->state.maximized) { |
Jonny Lamb | d73c694 | 2014-08-20 15:53:20 +0200 | [diff] [blame] | 5691 | set_maximized_position(shell, shsurf); |
Rafael Antognolli | 03b1659 | 2013-12-03 15:35:42 -0200 | [diff] [blame] | 5692 | } else { |
Jason Ekstrand | 918f2dd | 2013-12-02 21:01:53 -0600 | [diff] [blame] | 5693 | weston_view_set_position(shsurf->view, x, y); |
Kristian Høgsberg | 7a5c979 | 2011-06-18 06:12:54 -0400 | [diff] [blame] | 5694 | } |
Kristian Høgsberg | 32e24cc | 2011-11-09 12:07:35 -0500 | [diff] [blame] | 5695 | |
Alex Wu | 4539b08 | 2012-03-01 12:57:46 +0800 | [diff] [blame] | 5696 | /* XXX: would a fullscreen surface need the same handling? */ |
Kristian Høgsberg | 6a8b553 | 2012-02-16 23:43:59 -0500 | [diff] [blame] | 5697 | if (surface->output) { |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 5698 | wl_list_for_each(view, &surface->views, surface_link) |
| 5699 | weston_view_update_transform(view); |
Pekka Paalanen | 77346a6 | 2011-11-30 16:26:35 +0200 | [diff] [blame] | 5700 | |
Rafael Antognolli | 03b1659 | 2013-12-03 15:35:42 -0200 | [diff] [blame] | 5701 | if (shsurf->state.maximized) |
Juan Zhao | 96879df | 2012-02-07 08:45:41 +0800 | [diff] [blame] | 5702 | surface->output = shsurf->output; |
Pekka Paalanen | 77346a6 | 2011-11-30 16:26:35 +0200 | [diff] [blame] | 5703 | } |
Kristian Høgsberg | 0793756 | 2011-04-12 17:25:42 -0400 | [diff] [blame] | 5704 | } |
| 5705 | |
Ander Conselvan de Oliveira | 093bfa3 | 2012-03-27 17:36:41 +0300 | [diff] [blame] | 5706 | static void |
Jason Ekstrand | 918f2dd | 2013-12-02 21:01:53 -0600 | [diff] [blame] | 5707 | 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] | 5708 | { |
Ander Conselvan de Oliveira | 7fb9f95 | 2012-03-27 17:36:42 +0300 | [diff] [blame] | 5709 | struct shell_surface *shsurf = get_shell_surface(es); |
U. Artie Eoff | cf5737a | 2014-01-17 10:08:25 -0800 | [diff] [blame] | 5710 | struct desktop_shell *shell; |
Tiago Vignatti | 70e5c9c | 2012-05-07 15:23:07 +0300 | [diff] [blame] | 5711 | int type_changed = 0; |
Ander Conselvan de Oliveira | 093bfa3 | 2012-03-27 17:36:41 +0300 | [diff] [blame] | 5712 | |
U. Artie Eoff | cf5737a | 2014-01-17 10:08:25 -0800 | [diff] [blame] | 5713 | assert(shsurf); |
| 5714 | |
| 5715 | shell = shsurf->shell; |
| 5716 | |
Kristian Høgsberg | 8eb0f4f | 2013-06-17 10:33:14 -0400 | [diff] [blame] | 5717 | if (!weston_surface_is_mapped(es) && |
| 5718 | !wl_list_empty(&shsurf->popup.grab_link)) { |
Giulio Camuffo | 5085a75 | 2013-03-25 21:42:45 +0100 | [diff] [blame] | 5719 | remove_popup_grab(shsurf); |
| 5720 | } |
| 5721 | |
Jason Ekstrand | 918f2dd | 2013-12-02 21:01:53 -0600 | [diff] [blame] | 5722 | if (es->width == 0) |
Giulio Camuffo | 184df50 | 2013-02-21 11:29:21 +0100 | [diff] [blame] | 5723 | return; |
| 5724 | |
Jasper St. Pierre | ccf48fb | 2014-05-02 10:21:38 -0400 | [diff] [blame] | 5725 | if (shsurf->has_next_geometry) { |
| 5726 | shsurf->geometry = shsurf->next_geometry; |
| 5727 | shsurf->has_next_geometry = false; |
| 5728 | shsurf->has_set_geometry = true; |
| 5729 | } else if (!shsurf->has_set_geometry) { |
| 5730 | surface_subsurfaces_boundingbox(shsurf->surface, |
| 5731 | &shsurf->geometry.x, |
| 5732 | &shsurf->geometry.y, |
| 5733 | &shsurf->geometry.width, |
| 5734 | &shsurf->geometry.height); |
Jasper St. Pierre | 851799e | 2014-05-02 10:14:07 -0400 | [diff] [blame] | 5735 | } |
| 5736 | |
Kristian Høgsberg | c8f8dd8 | 2013-12-05 23:20:33 -0800 | [diff] [blame] | 5737 | if (shsurf->state_changed) { |
Kristian Høgsberg | 7f366e7 | 2012-04-27 17:20:01 -0400 | [diff] [blame] | 5738 | set_surface_type(shsurf); |
Kristian Høgsberg | f7e23d5 | 2012-04-27 17:51:59 -0400 | [diff] [blame] | 5739 | type_changed = 1; |
| 5740 | } |
Kristian Høgsberg | 7f366e7 | 2012-04-27 17:20:01 -0400 | [diff] [blame] | 5741 | |
Ander Conselvan de Oliveira | 093bfa3 | 2012-03-27 17:36:41 +0300 | [diff] [blame] | 5742 | if (!weston_surface_is_mapped(es)) { |
Jason Ekstrand | 918f2dd | 2013-12-02 21:01:53 -0600 | [diff] [blame] | 5743 | map(shell, shsurf, sx, sy); |
Kristian Høgsberg | f7e23d5 | 2012-04-27 17:51:59 -0400 | [diff] [blame] | 5744 | } else if (type_changed || sx != 0 || sy != 0 || |
Jason Ekstrand | 918f2dd | 2013-12-02 21:01:53 -0600 | [diff] [blame] | 5745 | shsurf->last_width != es->width || |
| 5746 | shsurf->last_height != es->height) { |
John Kåre Alsaker | 490d02a | 2012-09-30 02:57:21 +0200 | [diff] [blame] | 5747 | float from_x, from_y; |
| 5748 | float to_x, to_y; |
Ander Conselvan de Oliveira | 093bfa3 | 2012-03-27 17:36:41 +0300 | [diff] [blame] | 5749 | |
Kristian Høgsberg | 44cd196 | 2014-02-05 21:36:04 -0800 | [diff] [blame] | 5750 | if (shsurf->resize_edges) { |
| 5751 | sx = 0; |
| 5752 | sy = 0; |
| 5753 | } |
| 5754 | |
| 5755 | if (shsurf->resize_edges & WL_SHELL_SURFACE_RESIZE_LEFT) |
| 5756 | sx = shsurf->last_width - es->width; |
| 5757 | if (shsurf->resize_edges & WL_SHELL_SURFACE_RESIZE_TOP) |
| 5758 | sy = shsurf->last_height - es->height; |
| 5759 | |
| 5760 | shsurf->last_width = es->width; |
| 5761 | shsurf->last_height = es->height; |
| 5762 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 5763 | weston_view_to_global_float(shsurf->view, 0, 0, &from_x, &from_y); |
| 5764 | 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] | 5765 | configure(shell, es, |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 5766 | shsurf->view->geometry.x + to_x - from_x, |
Jason Ekstrand | 918f2dd | 2013-12-02 21:01:53 -0600 | [diff] [blame] | 5767 | shsurf->view->geometry.y + to_y - from_y); |
Ander Conselvan de Oliveira | 093bfa3 | 2012-03-27 17:36:41 +0300 | [diff] [blame] | 5768 | } |
| 5769 | } |
| 5770 | |
Pekka Paalanen | 2e62e4a | 2014-08-28 11:41:26 +0300 | [diff] [blame] | 5771 | static bool |
| 5772 | check_desktop_shell_crash_too_early(struct desktop_shell *shell) |
| 5773 | { |
| 5774 | struct timespec now; |
| 5775 | |
| 5776 | if (clock_gettime(CLOCK_MONOTONIC, &now) < 0) |
| 5777 | return false; |
| 5778 | |
| 5779 | /* |
| 5780 | * If the shell helper client dies before the session has been |
| 5781 | * up for roughly 30 seconds, better just make Weston shut down, |
| 5782 | * because the user likely has no way to interact with the desktop |
| 5783 | * anyway. |
| 5784 | */ |
| 5785 | if (now.tv_sec - shell->startup_time.tv_sec < 30) { |
| 5786 | weston_log("Error: %s apparently cannot run at all.\n", |
| 5787 | shell->client); |
| 5788 | weston_log_continue(STAMP_SPACE "Quitting..."); |
| 5789 | wl_display_terminate(shell->compositor->wl_display); |
| 5790 | |
| 5791 | return true; |
| 5792 | } |
| 5793 | |
| 5794 | return false; |
| 5795 | } |
| 5796 | |
Tiago Vignatti | b7dbbd6 | 2012-09-25 17:57:01 +0300 | [diff] [blame] | 5797 | static void launch_desktop_shell_process(void *data); |
Pekka Paalanen | 4d733ee | 2012-01-17 14:36:27 +0200 | [diff] [blame] | 5798 | |
Kristian Høgsberg | 97d44aa | 2011-08-26 17:21:20 -0400 | [diff] [blame] | 5799 | static void |
Pekka Paalanen | 826dc14 | 2014-08-27 12:11:53 +0300 | [diff] [blame] | 5800 | respawn_desktop_shell_process(struct desktop_shell *shell) |
Pekka Paalanen | 6cd281a | 2011-11-03 14:11:32 +0200 | [diff] [blame] | 5801 | { |
Pekka Paalanen | 4d733ee | 2012-01-17 14:36:27 +0200 | [diff] [blame] | 5802 | uint32_t time; |
Pekka Paalanen | 4d733ee | 2012-01-17 14:36:27 +0200 | [diff] [blame] | 5803 | |
| 5804 | /* if desktop-shell dies more than 5 times in 30 seconds, give up */ |
| 5805 | time = weston_compositor_get_time(); |
Kristian Høgsberg | f03a616 | 2012-01-17 11:07:42 -0500 | [diff] [blame] | 5806 | if (time - shell->child.deathstamp > 30000) { |
Pekka Paalanen | 4d733ee | 2012-01-17 14:36:27 +0200 | [diff] [blame] | 5807 | shell->child.deathstamp = time; |
| 5808 | shell->child.deathcount = 0; |
| 5809 | } |
| 5810 | |
| 5811 | shell->child.deathcount++; |
| 5812 | if (shell->child.deathcount > 5) { |
Pekka Paalanen | 826dc14 | 2014-08-27 12:11:53 +0300 | [diff] [blame] | 5813 | weston_log("%s disconnected, giving up.\n", shell->client); |
Pekka Paalanen | 4d733ee | 2012-01-17 14:36:27 +0200 | [diff] [blame] | 5814 | return; |
| 5815 | } |
| 5816 | |
Pekka Paalanen | 826dc14 | 2014-08-27 12:11:53 +0300 | [diff] [blame] | 5817 | weston_log("%s disconnected, respawning...\n", shell->client); |
Pekka Paalanen | 4d733ee | 2012-01-17 14:36:27 +0200 | [diff] [blame] | 5818 | launch_desktop_shell_process(shell); |
Pekka Paalanen | 6cd281a | 2011-11-03 14:11:32 +0200 | [diff] [blame] | 5819 | } |
| 5820 | |
Tiago Vignatti | b7dbbd6 | 2012-09-25 17:57:01 +0300 | [diff] [blame] | 5821 | static void |
Ander Conselvan de Oliveira | 312ea4c | 2013-12-20 21:07:01 +0200 | [diff] [blame] | 5822 | desktop_shell_client_destroy(struct wl_listener *listener, void *data) |
| 5823 | { |
| 5824 | struct desktop_shell *shell; |
| 5825 | |
| 5826 | shell = container_of(listener, struct desktop_shell, |
| 5827 | child.client_destroy_listener); |
| 5828 | |
Pekka Paalanen | 826dc14 | 2014-08-27 12:11:53 +0300 | [diff] [blame] | 5829 | wl_list_remove(&shell->child.client_destroy_listener.link); |
Ander Conselvan de Oliveira | 312ea4c | 2013-12-20 21:07:01 +0200 | [diff] [blame] | 5830 | shell->child.client = NULL; |
Pekka Paalanen | 826dc14 | 2014-08-27 12:11:53 +0300 | [diff] [blame] | 5831 | /* |
| 5832 | * unbind_desktop_shell() will reset shell->child.desktop_shell |
| 5833 | * before the respawned process has a chance to create a new |
| 5834 | * desktop_shell object, because we are being called from the |
| 5835 | * wl_client destructor which destroys all wl_resources before |
| 5836 | * returning. |
| 5837 | */ |
| 5838 | |
Pekka Paalanen | 2e62e4a | 2014-08-28 11:41:26 +0300 | [diff] [blame] | 5839 | if (!check_desktop_shell_crash_too_early(shell)) |
| 5840 | respawn_desktop_shell_process(shell); |
| 5841 | |
Pekka Paalanen | 826dc14 | 2014-08-27 12:11:53 +0300 | [diff] [blame] | 5842 | shell_fade_startup(shell); |
Ander Conselvan de Oliveira | 312ea4c | 2013-12-20 21:07:01 +0200 | [diff] [blame] | 5843 | } |
| 5844 | |
| 5845 | static void |
Tiago Vignatti | b7dbbd6 | 2012-09-25 17:57:01 +0300 | [diff] [blame] | 5846 | launch_desktop_shell_process(void *data) |
Pekka Paalanen | 6cd281a | 2011-11-03 14:11:32 +0200 | [diff] [blame] | 5847 | { |
Tiago Vignatti | b7dbbd6 | 2012-09-25 17:57:01 +0300 | [diff] [blame] | 5848 | struct desktop_shell *shell = data; |
Pekka Paalanen | 6cd281a | 2011-11-03 14:11:32 +0200 | [diff] [blame] | 5849 | |
Pekka Paalanen | 826dc14 | 2014-08-27 12:11:53 +0300 | [diff] [blame] | 5850 | shell->child.client = weston_client_start(shell->compositor, |
| 5851 | shell->client); |
Pekka Paalanen | 409ef0a | 2011-12-02 15:30:21 +0200 | [diff] [blame] | 5852 | |
Arnaud Vrac | 4263119 | 2014-08-25 20:56:46 +0200 | [diff] [blame] | 5853 | if (!shell->child.client) { |
Emilio Pozuelo Monfort | 46ce798 | 2013-11-20 13:22:29 +0100 | [diff] [blame] | 5854 | weston_log("not able to start %s\n", shell->client); |
Arnaud Vrac | 4263119 | 2014-08-25 20:56:46 +0200 | [diff] [blame] | 5855 | return; |
| 5856 | } |
Ander Conselvan de Oliveira | 312ea4c | 2013-12-20 21:07:01 +0200 | [diff] [blame] | 5857 | |
| 5858 | shell->child.client_destroy_listener.notify = |
| 5859 | desktop_shell_client_destroy; |
| 5860 | wl_client_add_destroy_listener(shell->child.client, |
| 5861 | &shell->child.client_destroy_listener); |
Pekka Paalanen | 6cd281a | 2011-11-03 14:11:32 +0200 | [diff] [blame] | 5862 | } |
| 5863 | |
| 5864 | static void |
Kristian Høgsberg | 2bff94e | 2014-02-11 12:22:51 -0800 | [diff] [blame] | 5865 | handle_shell_client_destroy(struct wl_listener *listener, void *data) |
| 5866 | { |
| 5867 | struct shell_client *sc = |
| 5868 | container_of(listener, struct shell_client, destroy_listener); |
| 5869 | |
| 5870 | if (sc->ping_timer) |
| 5871 | wl_event_source_remove(sc->ping_timer); |
Derek Foreman | e42d754 | 2015-05-29 10:46:44 -0500 | [diff] [blame] | 5872 | |
| 5873 | /* Since we're about to free shell_client, we remove it from the |
| 5874 | * head of the surface list so we don't use that freed list node |
| 5875 | * during surface clean up later on. |
| 5876 | */ |
| 5877 | wl_list_remove(&sc->surface_list); |
| 5878 | |
Kristian Høgsberg | 2bff94e | 2014-02-11 12:22:51 -0800 | [diff] [blame] | 5879 | free(sc); |
| 5880 | } |
| 5881 | |
Kristian Høgsberg | dd62aba | 2014-02-12 09:56:19 -0800 | [diff] [blame] | 5882 | static struct shell_client * |
| 5883 | shell_client_create(struct wl_client *client, struct desktop_shell *shell, |
| 5884 | const struct wl_interface *interface, uint32_t id) |
Rafael Antognolli | e2a3455 | 2013-12-03 15:35:45 -0200 | [diff] [blame] | 5885 | { |
Kristian Høgsberg | 2bff94e | 2014-02-11 12:22:51 -0800 | [diff] [blame] | 5886 | struct shell_client *sc; |
Rafael Antognolli | e2a3455 | 2013-12-03 15:35:45 -0200 | [diff] [blame] | 5887 | |
Kristian Høgsberg | 2bff94e | 2014-02-11 12:22:51 -0800 | [diff] [blame] | 5888 | sc = zalloc(sizeof *sc); |
| 5889 | if (sc == NULL) { |
| 5890 | wl_client_post_no_memory(client); |
Kristian Høgsberg | dd62aba | 2014-02-12 09:56:19 -0800 | [diff] [blame] | 5891 | return NULL; |
Kristian Høgsberg | 2bff94e | 2014-02-11 12:22:51 -0800 | [diff] [blame] | 5892 | } |
Kristian Høgsberg | dd62aba | 2014-02-12 09:56:19 -0800 | [diff] [blame] | 5893 | |
| 5894 | sc->resource = wl_resource_create(client, interface, 1, id); |
Kristian Høgsberg | 2bff94e | 2014-02-11 12:22:51 -0800 | [diff] [blame] | 5895 | if (sc->resource == NULL) { |
| 5896 | free(sc); |
| 5897 | wl_client_post_no_memory(client); |
Kristian Høgsberg | dd62aba | 2014-02-12 09:56:19 -0800 | [diff] [blame] | 5898 | return NULL; |
Kristian Høgsberg | 2bff94e | 2014-02-11 12:22:51 -0800 | [diff] [blame] | 5899 | } |
| 5900 | |
| 5901 | sc->client = client; |
| 5902 | sc->shell = shell; |
| 5903 | sc->destroy_listener.notify = handle_shell_client_destroy; |
| 5904 | wl_client_add_destroy_listener(client, &sc->destroy_listener); |
Jonas Ådahl | 49d77d2 | 2015-03-18 16:20:51 +0800 | [diff] [blame] | 5905 | wl_list_init(&sc->surface_list); |
Kristian Høgsberg | 2bff94e | 2014-02-11 12:22:51 -0800 | [diff] [blame] | 5906 | |
Kristian Høgsberg | dd62aba | 2014-02-12 09:56:19 -0800 | [diff] [blame] | 5907 | return sc; |
| 5908 | } |
| 5909 | |
| 5910 | static void |
| 5911 | bind_shell(struct wl_client *client, void *data, uint32_t version, uint32_t id) |
| 5912 | { |
| 5913 | struct desktop_shell *shell = data; |
| 5914 | struct shell_client *sc; |
| 5915 | |
| 5916 | sc = shell_client_create(client, shell, &wl_shell_interface, id); |
| 5917 | if (sc) |
| 5918 | wl_resource_set_implementation(sc->resource, |
| 5919 | &shell_implementation, |
Jason Ekstrand | 9e9512f | 2014-04-16 21:12:10 -0500 | [diff] [blame] | 5920 | sc, NULL); |
Kristian Høgsberg | dd62aba | 2014-02-12 09:56:19 -0800 | [diff] [blame] | 5921 | } |
| 5922 | |
| 5923 | static void |
| 5924 | bind_xdg_shell(struct wl_client *client, void *data, uint32_t version, uint32_t id) |
| 5925 | { |
| 5926 | struct desktop_shell *shell = data; |
| 5927 | struct shell_client *sc; |
| 5928 | |
| 5929 | sc = shell_client_create(client, shell, &xdg_shell_interface, id); |
| 5930 | if (sc) |
| 5931 | wl_resource_set_dispatcher(sc->resource, |
| 5932 | xdg_shell_unversioned_dispatch, |
| 5933 | NULL, sc, NULL); |
Rafael Antognolli | e2a3455 | 2013-12-03 15:35:45 -0200 | [diff] [blame] | 5934 | } |
| 5935 | |
| 5936 | static void |
Pekka Paalanen | 9ef3e01 | 2011-11-15 13:34:48 +0200 | [diff] [blame] | 5937 | unbind_desktop_shell(struct wl_resource *resource) |
| 5938 | { |
Jason Ekstrand | 651f00e | 2013-06-14 10:07:54 -0500 | [diff] [blame] | 5939 | struct desktop_shell *shell = wl_resource_get_user_data(resource); |
Kristian Høgsberg | 1ec0c31 | 2011-11-15 16:39:55 -0500 | [diff] [blame] | 5940 | |
| 5941 | if (shell->locked) |
| 5942 | resume_desktop(shell); |
| 5943 | |
Pekka Paalanen | 9ef3e01 | 2011-11-15 13:34:48 +0200 | [diff] [blame] | 5944 | shell->child.desktop_shell = NULL; |
| 5945 | shell->prepare_event_sent = false; |
Pekka Paalanen | 9ef3e01 | 2011-11-15 13:34:48 +0200 | [diff] [blame] | 5946 | } |
| 5947 | |
| 5948 | static void |
Kristian Høgsberg | 7584062 | 2011-09-06 13:48:16 -0400 | [diff] [blame] | 5949 | bind_desktop_shell(struct wl_client *client, |
| 5950 | void *data, uint32_t version, uint32_t id) |
| 5951 | { |
Tiago Vignatti | be14326 | 2012-04-16 17:31:41 +0300 | [diff] [blame] | 5952 | struct desktop_shell *shell = data; |
Pekka Paalanen | bbe6052 | 2011-11-03 14:11:33 +0200 | [diff] [blame] | 5953 | struct wl_resource *resource; |
Kristian Høgsberg | 7584062 | 2011-09-06 13:48:16 -0400 | [diff] [blame] | 5954 | |
Jason Ekstrand | a85118c | 2013-06-27 20:17:02 -0500 | [diff] [blame] | 5955 | resource = wl_resource_create(client, &desktop_shell_interface, |
Jonny Lamb | 765760d | 2014-08-20 15:53:19 +0200 | [diff] [blame] | 5956 | MIN(version, 3), id); |
Pekka Paalanen | bbe6052 | 2011-11-03 14:11:33 +0200 | [diff] [blame] | 5957 | |
Pekka Paalanen | 9ef3e01 | 2011-11-15 13:34:48 +0200 | [diff] [blame] | 5958 | if (client == shell->child.client) { |
Jason Ekstrand | a85118c | 2013-06-27 20:17:02 -0500 | [diff] [blame] | 5959 | wl_resource_set_implementation(resource, |
| 5960 | &desktop_shell_implementation, |
| 5961 | shell, unbind_desktop_shell); |
Pekka Paalanen | 9ef3e01 | 2011-11-15 13:34:48 +0200 | [diff] [blame] | 5962 | shell->child.desktop_shell = resource; |
Pekka Paalanen | 79346ab | 2013-05-22 18:03:09 +0300 | [diff] [blame] | 5963 | |
| 5964 | if (version < 2) |
| 5965 | shell_fade_startup(shell); |
| 5966 | |
Pekka Paalanen | bbe6052 | 2011-11-03 14:11:33 +0200 | [diff] [blame] | 5967 | return; |
Pekka Paalanen | 9ef3e01 | 2011-11-15 13:34:48 +0200 | [diff] [blame] | 5968 | } |
Pekka Paalanen | bbe6052 | 2011-11-03 14:11:33 +0200 | [diff] [blame] | 5969 | |
| 5970 | wl_resource_post_error(resource, WL_DISPLAY_ERROR_INVALID_OBJECT, |
| 5971 | "permission to bind desktop_shell denied"); |
Kristian Høgsberg | 7584062 | 2011-09-06 13:48:16 -0400 | [diff] [blame] | 5972 | } |
| 5973 | |
Kristian Høgsberg | 0704539 | 2012-02-19 18:52:44 -0500 | [diff] [blame] | 5974 | struct switcher { |
Tiago Vignatti | be14326 | 2012-04-16 17:31:41 +0300 | [diff] [blame] | 5975 | struct desktop_shell *shell; |
Kristian Høgsberg | 0704539 | 2012-02-19 18:52:44 -0500 | [diff] [blame] | 5976 | struct weston_surface *current; |
| 5977 | struct wl_listener listener; |
Kristian Høgsberg | 29139d4 | 2013-04-18 15:25:39 -0400 | [diff] [blame] | 5978 | struct weston_keyboard_grab grab; |
Manuel Bachmann | c1ae2e8 | 2014-02-26 15:53:11 +0100 | [diff] [blame] | 5979 | struct wl_array minimized_array; |
Kristian Høgsberg | 0704539 | 2012-02-19 18:52:44 -0500 | [diff] [blame] | 5980 | }; |
| 5981 | |
| 5982 | static void |
| 5983 | switcher_next(struct switcher *switcher) |
| 5984 | { |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 5985 | struct weston_view *view; |
Kristian Høgsberg | 0704539 | 2012-02-19 18:52:44 -0500 | [diff] [blame] | 5986 | struct weston_surface *first = NULL, *prev = NULL, *next = NULL; |
Kristian Høgsberg | 32e5686 | 2012-04-02 22:18:58 -0400 | [diff] [blame] | 5987 | struct shell_surface *shsurf; |
Kristian Høgsberg | b0d8e77 | 2012-06-18 16:34:58 -0400 | [diff] [blame] | 5988 | struct workspace *ws = get_current_workspace(switcher->shell); |
Kristian Høgsberg | 0704539 | 2012-02-19 18:52:44 -0500 | [diff] [blame] | 5989 | |
Manuel Bachmann | c1ae2e8 | 2014-02-26 15:53:11 +0100 | [diff] [blame] | 5990 | /* temporary re-display minimized surfaces */ |
| 5991 | struct weston_view *tmp; |
| 5992 | struct weston_view **minimized; |
Giulio Camuffo | 412e6a5 | 2014-07-09 22:12:56 +0300 | [diff] [blame] | 5993 | wl_list_for_each_safe(view, tmp, &switcher->shell->minimized_layer.view_list.link, layer_link.link) { |
| 5994 | weston_layer_entry_remove(&view->layer_link); |
| 5995 | weston_layer_entry_insert(&ws->layer.view_list, &view->layer_link); |
Manuel Bachmann | c1ae2e8 | 2014-02-26 15:53:11 +0100 | [diff] [blame] | 5996 | minimized = wl_array_add(&switcher->minimized_array, sizeof *minimized); |
| 5997 | *minimized = view; |
| 5998 | } |
| 5999 | |
Giulio Camuffo | 412e6a5 | 2014-07-09 22:12:56 +0300 | [diff] [blame] | 6000 | 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] | 6001 | shsurf = get_shell_surface(view->surface); |
Rafael Antognolli | 5031cbe | 2013-12-05 19:01:21 -0200 | [diff] [blame] | 6002 | if (shsurf && |
| 6003 | shsurf->type == SHELL_SURFACE_TOPLEVEL && |
| 6004 | shsurf->parent == NULL) { |
Kristian Høgsberg | 0704539 | 2012-02-19 18:52:44 -0500 | [diff] [blame] | 6005 | if (first == NULL) |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 6006 | first = view->surface; |
Kristian Høgsberg | 0704539 | 2012-02-19 18:52:44 -0500 | [diff] [blame] | 6007 | if (prev == switcher->current) |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 6008 | next = view->surface; |
| 6009 | prev = view->surface; |
| 6010 | view->alpha = 0.25; |
| 6011 | weston_view_geometry_dirty(view); |
| 6012 | weston_surface_damage(view->surface); |
Kristian Høgsberg | 0704539 | 2012-02-19 18:52:44 -0500 | [diff] [blame] | 6013 | } |
Alex Wu | 1659daa | 2012-04-01 20:13:09 +0800 | [diff] [blame] | 6014 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 6015 | if (is_black_surface(view->surface, NULL)) { |
| 6016 | view->alpha = 0.25; |
| 6017 | weston_view_geometry_dirty(view); |
| 6018 | weston_surface_damage(view->surface); |
Alex Wu | 1659daa | 2012-04-01 20:13:09 +0800 | [diff] [blame] | 6019 | } |
Kristian Høgsberg | 0704539 | 2012-02-19 18:52:44 -0500 | [diff] [blame] | 6020 | } |
| 6021 | |
| 6022 | if (next == NULL) |
| 6023 | next = first; |
| 6024 | |
Alex Wu | 07b2606 | 2012-03-12 16:06:01 +0800 | [diff] [blame] | 6025 | if (next == NULL) |
| 6026 | return; |
| 6027 | |
Kristian Høgsberg | 0704539 | 2012-02-19 18:52:44 -0500 | [diff] [blame] | 6028 | wl_list_remove(&switcher->listener.link); |
Jason Ekstrand | 26ed73c | 2013-06-06 22:34:41 -0500 | [diff] [blame] | 6029 | wl_signal_add(&next->destroy_signal, &switcher->listener); |
Kristian Høgsberg | 0704539 | 2012-02-19 18:52:44 -0500 | [diff] [blame] | 6030 | |
| 6031 | switcher->current = next; |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 6032 | wl_list_for_each(view, &next->views, surface_link) |
| 6033 | view->alpha = 1.0; |
Alex Wu | 1659daa | 2012-04-01 20:13:09 +0800 | [diff] [blame] | 6034 | |
Kristian Høgsberg | 32e5686 | 2012-04-02 22:18:58 -0400 | [diff] [blame] | 6035 | shsurf = get_shell_surface(switcher->current); |
Rafael Antognolli | 03b1659 | 2013-12-03 15:35:42 -0200 | [diff] [blame] | 6036 | if (shsurf && shsurf->state.fullscreen) |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 6037 | shsurf->fullscreen.black_view->alpha = 1.0; |
Kristian Høgsberg | 0704539 | 2012-02-19 18:52:44 -0500 | [diff] [blame] | 6038 | } |
| 6039 | |
| 6040 | static void |
Kristian Høgsberg | 27e3052 | 2012-04-11 23:18:23 -0400 | [diff] [blame] | 6041 | switcher_handle_surface_destroy(struct wl_listener *listener, void *data) |
Kristian Høgsberg | 0704539 | 2012-02-19 18:52:44 -0500 | [diff] [blame] | 6042 | { |
| 6043 | struct switcher *switcher = |
| 6044 | container_of(listener, struct switcher, listener); |
| 6045 | |
| 6046 | switcher_next(switcher); |
| 6047 | } |
| 6048 | |
| 6049 | static void |
Daniel Stone | 351eb61 | 2012-05-31 15:27:47 -0400 | [diff] [blame] | 6050 | switcher_destroy(struct switcher *switcher) |
Kristian Høgsberg | 0704539 | 2012-02-19 18:52:44 -0500 | [diff] [blame] | 6051 | { |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 6052 | struct weston_view *view; |
Kristian Høgsberg | 29139d4 | 2013-04-18 15:25:39 -0400 | [diff] [blame] | 6053 | struct weston_keyboard *keyboard = switcher->grab.keyboard; |
Kristian Høgsberg | b0d8e77 | 2012-06-18 16:34:58 -0400 | [diff] [blame] | 6054 | struct workspace *ws = get_current_workspace(switcher->shell); |
Kristian Høgsberg | 0704539 | 2012-02-19 18:52:44 -0500 | [diff] [blame] | 6055 | |
Giulio Camuffo | 412e6a5 | 2014-07-09 22:12:56 +0300 | [diff] [blame] | 6056 | 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] | 6057 | if (is_focus_view(view)) |
| 6058 | continue; |
| 6059 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 6060 | view->alpha = 1.0; |
| 6061 | weston_surface_damage(view->surface); |
Kristian Høgsberg | 0704539 | 2012-02-19 18:52:44 -0500 | [diff] [blame] | 6062 | } |
| 6063 | |
Alex Wu | 07b2606 | 2012-03-12 16:06:01 +0800 | [diff] [blame] | 6064 | if (switcher->current) |
Daniel Stone | 37816df | 2012-05-16 18:45:18 +0100 | [diff] [blame] | 6065 | activate(switcher->shell, switcher->current, |
Derek Foreman | 8aeeac8 | 2015-01-30 13:24:36 -0600 | [diff] [blame] | 6066 | keyboard->seat, true); |
Kristian Høgsberg | 0704539 | 2012-02-19 18:52:44 -0500 | [diff] [blame] | 6067 | wl_list_remove(&switcher->listener.link); |
Kristian Høgsberg | 29139d4 | 2013-04-18 15:25:39 -0400 | [diff] [blame] | 6068 | weston_keyboard_end_grab(keyboard); |
| 6069 | if (keyboard->input_method_resource) |
| 6070 | keyboard->grab = &keyboard->input_method_grab; |
Manuel Bachmann | c1ae2e8 | 2014-02-26 15:53:11 +0100 | [diff] [blame] | 6071 | |
| 6072 | /* re-hide surfaces that were temporary shown during the switch */ |
| 6073 | struct weston_view **minimized; |
| 6074 | wl_array_for_each(minimized, &switcher->minimized_array) { |
| 6075 | /* with the exception of the current selected */ |
| 6076 | if ((*minimized)->surface != switcher->current) { |
Giulio Camuffo | 412e6a5 | 2014-07-09 22:12:56 +0300 | [diff] [blame] | 6077 | weston_layer_entry_remove(&(*minimized)->layer_link); |
| 6078 | 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] | 6079 | weston_view_damage_below(*minimized); |
| 6080 | } |
| 6081 | } |
| 6082 | wl_array_release(&switcher->minimized_array); |
| 6083 | |
Kristian Høgsberg | 0704539 | 2012-02-19 18:52:44 -0500 | [diff] [blame] | 6084 | free(switcher); |
| 6085 | } |
| 6086 | |
| 6087 | static void |
Kristian Høgsberg | 29139d4 | 2013-04-18 15:25:39 -0400 | [diff] [blame] | 6088 | switcher_key(struct weston_keyboard_grab *grab, |
Daniel Stone | c9785ea | 2012-05-30 16:31:52 +0100 | [diff] [blame] | 6089 | uint32_t time, uint32_t key, uint32_t state_w) |
Kristian Høgsberg | 0704539 | 2012-02-19 18:52:44 -0500 | [diff] [blame] | 6090 | { |
| 6091 | struct switcher *switcher = container_of(grab, struct switcher, grab); |
Daniel Stone | c9785ea | 2012-05-30 16:31:52 +0100 | [diff] [blame] | 6092 | enum wl_keyboard_key_state state = state_w; |
Daniel Stone | 351eb61 | 2012-05-31 15:27:47 -0400 | [diff] [blame] | 6093 | |
Daniel Stone | c9785ea | 2012-05-30 16:31:52 +0100 | [diff] [blame] | 6094 | if (key == KEY_TAB && state == WL_KEYBOARD_KEY_STATE_PRESSED) |
Daniel Stone | 351eb61 | 2012-05-31 15:27:47 -0400 | [diff] [blame] | 6095 | switcher_next(switcher); |
| 6096 | } |
| 6097 | |
| 6098 | static void |
Kristian Høgsberg | 29139d4 | 2013-04-18 15:25:39 -0400 | [diff] [blame] | 6099 | switcher_modifier(struct weston_keyboard_grab *grab, uint32_t serial, |
Daniel Stone | 351eb61 | 2012-05-31 15:27:47 -0400 | [diff] [blame] | 6100 | uint32_t mods_depressed, uint32_t mods_latched, |
| 6101 | uint32_t mods_locked, uint32_t group) |
| 6102 | { |
| 6103 | struct switcher *switcher = container_of(grab, struct switcher, grab); |
Derek Foreman | 8aeeac8 | 2015-01-30 13:24:36 -0600 | [diff] [blame] | 6104 | struct weston_seat *seat = grab->keyboard->seat; |
Kristian Høgsberg | 0704539 | 2012-02-19 18:52:44 -0500 | [diff] [blame] | 6105 | |
Daniel Stone | 351eb61 | 2012-05-31 15:27:47 -0400 | [diff] [blame] | 6106 | if ((seat->modifier_state & switcher->shell->binding_modifier) == 0) |
| 6107 | switcher_destroy(switcher); |
Kristian Høgsberg | b71302e | 2012-05-10 12:28:35 -0400 | [diff] [blame] | 6108 | } |
Kristian Høgsberg | 0704539 | 2012-02-19 18:52:44 -0500 | [diff] [blame] | 6109 | |
Jonas Ådahl | 1ea343e | 2013-10-25 23:18:05 +0200 | [diff] [blame] | 6110 | static void |
| 6111 | switcher_cancel(struct weston_keyboard_grab *grab) |
| 6112 | { |
| 6113 | struct switcher *switcher = container_of(grab, struct switcher, grab); |
| 6114 | |
| 6115 | switcher_destroy(switcher); |
| 6116 | } |
| 6117 | |
Kristian Høgsberg | 29139d4 | 2013-04-18 15:25:39 -0400 | [diff] [blame] | 6118 | static const struct weston_keyboard_grab_interface switcher_grab = { |
Daniel Stone | 351eb61 | 2012-05-31 15:27:47 -0400 | [diff] [blame] | 6119 | switcher_key, |
| 6120 | switcher_modifier, |
Jonas Ådahl | 1ea343e | 2013-10-25 23:18:05 +0200 | [diff] [blame] | 6121 | switcher_cancel, |
Kristian Høgsberg | 0704539 | 2012-02-19 18:52:44 -0500 | [diff] [blame] | 6122 | }; |
| 6123 | |
| 6124 | static void |
Derek Foreman | 8ae2db5 | 2015-07-15 13:00:36 -0500 | [diff] [blame] | 6125 | switcher_binding(struct weston_keyboard *keyboard, uint32_t time, |
| 6126 | uint32_t key, void *data) |
Kristian Høgsberg | 0704539 | 2012-02-19 18:52:44 -0500 | [diff] [blame] | 6127 | { |
Tiago Vignatti | be14326 | 2012-04-16 17:31:41 +0300 | [diff] [blame] | 6128 | struct desktop_shell *shell = data; |
Kristian Høgsberg | 0704539 | 2012-02-19 18:52:44 -0500 | [diff] [blame] | 6129 | struct switcher *switcher; |
| 6130 | |
| 6131 | switcher = malloc(sizeof *switcher); |
Kristian Høgsberg | 02e79dc | 2012-04-12 09:55:26 -0400 | [diff] [blame] | 6132 | switcher->shell = shell; |
Kristian Høgsberg | 0704539 | 2012-02-19 18:52:44 -0500 | [diff] [blame] | 6133 | switcher->current = NULL; |
Kristian Høgsberg | 27e3052 | 2012-04-11 23:18:23 -0400 | [diff] [blame] | 6134 | switcher->listener.notify = switcher_handle_surface_destroy; |
Kristian Høgsberg | 0704539 | 2012-02-19 18:52:44 -0500 | [diff] [blame] | 6135 | wl_list_init(&switcher->listener.link); |
Manuel Bachmann | c1ae2e8 | 2014-02-26 15:53:11 +0100 | [diff] [blame] | 6136 | wl_array_init(&switcher->minimized_array); |
Kristian Høgsberg | 0704539 | 2012-02-19 18:52:44 -0500 | [diff] [blame] | 6137 | |
Alexander Larsson | f82b6ca | 2013-05-28 16:23:39 +0200 | [diff] [blame] | 6138 | restore_all_output_modes(shell->compositor); |
Mario Kleiner | 9f4d655 | 2015-06-21 21:25:08 +0200 | [diff] [blame] | 6139 | lower_fullscreen_layer(switcher->shell, NULL); |
Kristian Høgsberg | 0704539 | 2012-02-19 18:52:44 -0500 | [diff] [blame] | 6140 | switcher->grab.interface = &switcher_grab; |
Derek Foreman | 8ae2db5 | 2015-07-15 13:00:36 -0500 | [diff] [blame] | 6141 | weston_keyboard_start_grab(keyboard, &switcher->grab); |
| 6142 | weston_keyboard_set_focus(keyboard, NULL); |
Kristian Høgsberg | 0704539 | 2012-02-19 18:52:44 -0500 | [diff] [blame] | 6143 | switcher_next(switcher); |
| 6144 | } |
| 6145 | |
Pekka Paalanen | 3c64723 | 2011-12-22 13:43:43 +0200 | [diff] [blame] | 6146 | static void |
Derek Foreman | 8ae2db5 | 2015-07-15 13:00:36 -0500 | [diff] [blame] | 6147 | backlight_binding(struct weston_keyboard *keyboard, uint32_t time, |
| 6148 | uint32_t key, void *data) |
Tiago Vignatti | 8e53c7f | 2012-02-29 19:53:50 +0200 | [diff] [blame] | 6149 | { |
| 6150 | struct weston_compositor *compositor = data; |
| 6151 | struct weston_output *output; |
Tiago Vignatti | 5ab91ad | 2012-03-12 19:40:09 -0300 | [diff] [blame] | 6152 | long backlight_new = 0; |
Tiago Vignatti | 8e53c7f | 2012-02-29 19:53:50 +0200 | [diff] [blame] | 6153 | |
| 6154 | /* TODO: we're limiting to simple use cases, where we assume just |
| 6155 | * control on the primary display. We'd have to extend later if we |
| 6156 | * ever get support for setting backlights on random desktop LCD |
| 6157 | * panels though */ |
| 6158 | output = get_default_output(compositor); |
| 6159 | if (!output) |
| 6160 | return; |
| 6161 | |
| 6162 | if (!output->set_backlight) |
| 6163 | return; |
| 6164 | |
Tiago Vignatti | 5ab91ad | 2012-03-12 19:40:09 -0300 | [diff] [blame] | 6165 | if (key == KEY_F9 || key == KEY_BRIGHTNESSDOWN) |
| 6166 | backlight_new = output->backlight_current - 25; |
| 6167 | else if (key == KEY_F10 || key == KEY_BRIGHTNESSUP) |
| 6168 | backlight_new = output->backlight_current + 25; |
Tiago Vignatti | 8e53c7f | 2012-02-29 19:53:50 +0200 | [diff] [blame] | 6169 | |
Tiago Vignatti | 5ab91ad | 2012-03-12 19:40:09 -0300 | [diff] [blame] | 6170 | if (backlight_new < 5) |
| 6171 | backlight_new = 5; |
| 6172 | if (backlight_new > 255) |
| 6173 | backlight_new = 255; |
| 6174 | |
| 6175 | output->backlight_current = backlight_new; |
Tiago Vignatti | 8e53c7f | 2012-02-29 19:53:50 +0200 | [diff] [blame] | 6176 | output->set_backlight(output, output->backlight_current); |
| 6177 | } |
| 6178 | |
Kristian Høgsberg | b41c081 | 2012-03-04 14:53:40 -0500 | [diff] [blame] | 6179 | static void |
Derek Foreman | 8ae2db5 | 2015-07-15 13:00:36 -0500 | [diff] [blame] | 6180 | force_kill_binding(struct weston_keyboard *keyboard, uint32_t time, |
| 6181 | uint32_t key, void *data) |
Kristian Høgsberg | 92a57db | 2012-05-26 13:41:06 -0400 | [diff] [blame] | 6182 | { |
Kristian Høgsberg | fe7aa90 | 2013-05-08 09:54:37 -0400 | [diff] [blame] | 6183 | struct weston_surface *focus_surface; |
Kristian Høgsberg | 92a57db | 2012-05-26 13:41:06 -0400 | [diff] [blame] | 6184 | struct wl_client *client; |
Tiago Vignatti | 1d01b01 | 2012-09-27 17:48:36 +0300 | [diff] [blame] | 6185 | struct desktop_shell *shell = data; |
| 6186 | struct weston_compositor *compositor = shell->compositor; |
Kristian Høgsberg | 92a57db | 2012-05-26 13:41:06 -0400 | [diff] [blame] | 6187 | pid_t pid; |
Kristian Høgsberg | 92a57db | 2012-05-26 13:41:06 -0400 | [diff] [blame] | 6188 | |
Derek Foreman | 8ae2db5 | 2015-07-15 13:00:36 -0500 | [diff] [blame] | 6189 | focus_surface = keyboard->focus; |
Philipp Brüschweiler | 6cef009 | 2012-08-13 21:27:27 +0200 | [diff] [blame] | 6190 | if (!focus_surface) |
| 6191 | return; |
| 6192 | |
Tiago Vignatti | 1d01b01 | 2012-09-27 17:48:36 +0300 | [diff] [blame] | 6193 | wl_signal_emit(&compositor->kill_signal, focus_surface); |
| 6194 | |
Jason Ekstrand | 26ed73c | 2013-06-06 22:34:41 -0500 | [diff] [blame] | 6195 | client = wl_resource_get_client(focus_surface->resource); |
Tiago Vignatti | 920f197 | 2012-09-27 17:48:35 +0300 | [diff] [blame] | 6196 | wl_client_get_credentials(client, &pid, NULL, NULL); |
| 6197 | |
| 6198 | /* Skip clients that we launched ourselves (the credentials of |
| 6199 | * the socketpair is ours) */ |
| 6200 | if (pid == getpid()) |
| 6201 | return; |
Kristian Høgsberg | 92a57db | 2012-05-26 13:41:06 -0400 | [diff] [blame] | 6202 | |
Daniel Stone | 325fc2d | 2012-05-30 16:31:58 +0100 | [diff] [blame] | 6203 | kill(pid, SIGKILL); |
Kristian Høgsberg | 92a57db | 2012-05-26 13:41:06 -0400 | [diff] [blame] | 6204 | } |
| 6205 | |
| 6206 | static void |
Derek Foreman | 8ae2db5 | 2015-07-15 13:00:36 -0500 | [diff] [blame] | 6207 | workspace_up_binding(struct weston_keyboard *keyboard, uint32_t time, |
Jonas Ådahl | e3cddce | 2012-06-13 00:01:22 +0200 | [diff] [blame] | 6208 | uint32_t key, void *data) |
| 6209 | { |
| 6210 | struct desktop_shell *shell = data; |
| 6211 | unsigned int new_index = shell->workspaces.current; |
| 6212 | |
Kristian Høgsberg | ce345b0 | 2012-06-25 21:35:29 -0400 | [diff] [blame] | 6213 | if (shell->locked) |
Kristian Høgsberg | 4476aaf | 2012-06-25 14:03:13 -0400 | [diff] [blame] | 6214 | return; |
Jonas Ådahl | e3cddce | 2012-06-13 00:01:22 +0200 | [diff] [blame] | 6215 | if (new_index != 0) |
| 6216 | new_index--; |
| 6217 | |
| 6218 | change_workspace(shell, new_index); |
| 6219 | } |
| 6220 | |
| 6221 | static void |
Derek Foreman | 8ae2db5 | 2015-07-15 13:00:36 -0500 | [diff] [blame] | 6222 | workspace_down_binding(struct weston_keyboard *keyboard, uint32_t time, |
Jonas Ådahl | e3cddce | 2012-06-13 00:01:22 +0200 | [diff] [blame] | 6223 | uint32_t key, void *data) |
| 6224 | { |
| 6225 | struct desktop_shell *shell = data; |
| 6226 | unsigned int new_index = shell->workspaces.current; |
| 6227 | |
Kristian Høgsberg | ce345b0 | 2012-06-25 21:35:29 -0400 | [diff] [blame] | 6228 | if (shell->locked) |
Kristian Høgsberg | 4476aaf | 2012-06-25 14:03:13 -0400 | [diff] [blame] | 6229 | return; |
Jonas Ådahl | e3cddce | 2012-06-13 00:01:22 +0200 | [diff] [blame] | 6230 | if (new_index < shell->workspaces.num - 1) |
| 6231 | new_index++; |
| 6232 | |
| 6233 | change_workspace(shell, new_index); |
| 6234 | } |
| 6235 | |
| 6236 | static void |
Derek Foreman | 8ae2db5 | 2015-07-15 13:00:36 -0500 | [diff] [blame] | 6237 | workspace_f_binding(struct weston_keyboard *keyboard, uint32_t time, |
Jonas Ådahl | e3cddce | 2012-06-13 00:01:22 +0200 | [diff] [blame] | 6238 | uint32_t key, void *data) |
| 6239 | { |
| 6240 | struct desktop_shell *shell = data; |
| 6241 | unsigned int new_index; |
| 6242 | |
Kristian Høgsberg | ce345b0 | 2012-06-25 21:35:29 -0400 | [diff] [blame] | 6243 | if (shell->locked) |
Kristian Høgsberg | 4476aaf | 2012-06-25 14:03:13 -0400 | [diff] [blame] | 6244 | return; |
Jonas Ådahl | e3cddce | 2012-06-13 00:01:22 +0200 | [diff] [blame] | 6245 | new_index = key - KEY_F1; |
| 6246 | if (new_index >= shell->workspaces.num) |
| 6247 | new_index = shell->workspaces.num - 1; |
| 6248 | |
| 6249 | change_workspace(shell, new_index); |
| 6250 | } |
| 6251 | |
Jonas Ådahl | 8de6a1d | 2012-08-29 22:13:00 +0200 | [diff] [blame] | 6252 | static void |
Derek Foreman | 8ae2db5 | 2015-07-15 13:00:36 -0500 | [diff] [blame] | 6253 | workspace_move_surface_up_binding(struct weston_keyboard *keyboard, |
| 6254 | uint32_t time, uint32_t key, void *data) |
Jonas Ådahl | 8de6a1d | 2012-08-29 22:13:00 +0200 | [diff] [blame] | 6255 | { |
| 6256 | struct desktop_shell *shell = data; |
| 6257 | unsigned int new_index = shell->workspaces.current; |
| 6258 | |
| 6259 | if (shell->locked) |
| 6260 | return; |
| 6261 | |
| 6262 | if (new_index != 0) |
| 6263 | new_index--; |
| 6264 | |
Derek Foreman | 8ae2db5 | 2015-07-15 13:00:36 -0500 | [diff] [blame] | 6265 | take_surface_to_workspace_by_seat(shell, keyboard->seat, new_index); |
Jonas Ådahl | 8de6a1d | 2012-08-29 22:13:00 +0200 | [diff] [blame] | 6266 | } |
| 6267 | |
| 6268 | static void |
Derek Foreman | 8ae2db5 | 2015-07-15 13:00:36 -0500 | [diff] [blame] | 6269 | workspace_move_surface_down_binding(struct weston_keyboard *keyboard, |
| 6270 | uint32_t time, uint32_t key, void *data) |
Jonas Ådahl | 8de6a1d | 2012-08-29 22:13:00 +0200 | [diff] [blame] | 6271 | { |
| 6272 | struct desktop_shell *shell = data; |
| 6273 | unsigned int new_index = shell->workspaces.current; |
| 6274 | |
| 6275 | if (shell->locked) |
| 6276 | return; |
| 6277 | |
| 6278 | if (new_index < shell->workspaces.num - 1) |
| 6279 | new_index++; |
| 6280 | |
Derek Foreman | 8ae2db5 | 2015-07-15 13:00:36 -0500 | [diff] [blame] | 6281 | take_surface_to_workspace_by_seat(shell, keyboard->seat, new_index); |
Jonas Ådahl | 8de6a1d | 2012-08-29 22:13:00 +0200 | [diff] [blame] | 6282 | } |
Jonas Ådahl | e3cddce | 2012-06-13 00:01:22 +0200 | [diff] [blame] | 6283 | |
| 6284 | static void |
Ander Conselvan de Oliveira | c94d622 | 2014-01-29 18:47:54 +0200 | [diff] [blame] | 6285 | shell_reposition_view_on_output_destroy(struct weston_view *view) |
| 6286 | { |
| 6287 | struct weston_output *output, *first_output; |
| 6288 | struct weston_compositor *ec = view->surface->compositor; |
| 6289 | struct shell_surface *shsurf; |
| 6290 | float x, y; |
| 6291 | int visible; |
| 6292 | |
| 6293 | x = view->geometry.x; |
| 6294 | y = view->geometry.y; |
| 6295 | |
| 6296 | /* At this point the destroyed output is not in the list anymore. |
| 6297 | * If the view is still visible somewhere, we leave where it is, |
| 6298 | * otherwise, move it to the first output. */ |
| 6299 | visible = 0; |
| 6300 | wl_list_for_each(output, &ec->output_list, link) { |
| 6301 | if (pixman_region32_contains_point(&output->region, |
| 6302 | x, y, NULL)) { |
| 6303 | visible = 1; |
| 6304 | break; |
| 6305 | } |
| 6306 | } |
| 6307 | |
| 6308 | if (!visible) { |
| 6309 | first_output = container_of(ec->output_list.next, |
| 6310 | struct weston_output, link); |
| 6311 | |
| 6312 | x = first_output->x + first_output->width / 4; |
| 6313 | y = first_output->y + first_output->height / 4; |
Xiong Zhang | 62899f5 | 2014-03-07 16:27:19 +0800 | [diff] [blame] | 6314 | |
| 6315 | weston_view_set_position(view, x, y); |
| 6316 | } else { |
| 6317 | weston_view_geometry_dirty(view); |
Ander Conselvan de Oliveira | c94d622 | 2014-01-29 18:47:54 +0200 | [diff] [blame] | 6318 | } |
| 6319 | |
Ander Conselvan de Oliveira | c94d622 | 2014-01-29 18:47:54 +0200 | [diff] [blame] | 6320 | |
| 6321 | shsurf = get_shell_surface(view->surface); |
| 6322 | |
| 6323 | if (shsurf) { |
| 6324 | shsurf->saved_position_valid = false; |
| 6325 | shsurf->next_state.maximized = false; |
| 6326 | shsurf->next_state.fullscreen = false; |
| 6327 | shsurf->state_changed = true; |
| 6328 | } |
| 6329 | } |
| 6330 | |
Ander Conselvan de Oliveira | 304996d | 2014-04-11 13:57:15 +0300 | [diff] [blame] | 6331 | void |
| 6332 | shell_for_each_layer(struct desktop_shell *shell, |
| 6333 | shell_for_each_layer_func_t func, void *data) |
Ander Conselvan de Oliveira | c94d622 | 2014-01-29 18:47:54 +0200 | [diff] [blame] | 6334 | { |
Ander Conselvan de Oliveira | 304996d | 2014-04-11 13:57:15 +0300 | [diff] [blame] | 6335 | struct workspace **ws; |
| 6336 | |
| 6337 | func(shell, &shell->fullscreen_layer, data); |
| 6338 | func(shell, &shell->panel_layer, data); |
| 6339 | func(shell, &shell->background_layer, data); |
| 6340 | func(shell, &shell->lock_layer, data); |
| 6341 | func(shell, &shell->input_panel_layer, data); |
| 6342 | |
| 6343 | wl_array_for_each(ws, &shell->workspaces.array) |
| 6344 | func(shell, &(*ws)->layer, data); |
| 6345 | } |
| 6346 | |
| 6347 | static void |
| 6348 | shell_output_destroy_move_layer(struct desktop_shell *shell, |
| 6349 | struct weston_layer *layer, |
| 6350 | void *data) |
| 6351 | { |
| 6352 | struct weston_output *output = data; |
Ander Conselvan de Oliveira | c94d622 | 2014-01-29 18:47:54 +0200 | [diff] [blame] | 6353 | struct weston_view *view; |
| 6354 | |
Giulio Camuffo | 412e6a5 | 2014-07-09 22:12:56 +0300 | [diff] [blame] | 6355 | 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] | 6356 | if (view->output != output) |
| 6357 | continue; |
Ander Conselvan de Oliveira | c94d622 | 2014-01-29 18:47:54 +0200 | [diff] [blame] | 6358 | |
Ander Conselvan de Oliveira | 304996d | 2014-04-11 13:57:15 +0300 | [diff] [blame] | 6359 | shell_reposition_view_on_output_destroy(view); |
Ander Conselvan de Oliveira | c94d622 | 2014-01-29 18:47:54 +0200 | [diff] [blame] | 6360 | } |
| 6361 | } |
| 6362 | |
| 6363 | static void |
Xiong Zhang | 6b48142 | 2013-10-23 13:58:32 +0800 | [diff] [blame] | 6364 | handle_output_destroy(struct wl_listener *listener, void *data) |
| 6365 | { |
| 6366 | struct shell_output *output_listener = |
| 6367 | container_of(listener, struct shell_output, destroy_listener); |
Ander Conselvan de Oliveira | 304996d | 2014-04-11 13:57:15 +0300 | [diff] [blame] | 6368 | struct weston_output *output = output_listener->output; |
| 6369 | struct desktop_shell *shell = output_listener->shell; |
Xiong Zhang | 6b48142 | 2013-10-23 13:58:32 +0800 | [diff] [blame] | 6370 | |
Ander Conselvan de Oliveira | 304996d | 2014-04-11 13:57:15 +0300 | [diff] [blame] | 6371 | 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] | 6372 | |
Xiong Zhang | 6b48142 | 2013-10-23 13:58:32 +0800 | [diff] [blame] | 6373 | wl_list_remove(&output_listener->destroy_listener.link); |
| 6374 | wl_list_remove(&output_listener->link); |
| 6375 | free(output_listener); |
| 6376 | } |
| 6377 | |
| 6378 | static void |
| 6379 | create_shell_output(struct desktop_shell *shell, |
| 6380 | struct weston_output *output) |
| 6381 | { |
| 6382 | struct shell_output *shell_output; |
| 6383 | |
| 6384 | shell_output = zalloc(sizeof *shell_output); |
| 6385 | if (shell_output == NULL) |
| 6386 | return; |
| 6387 | |
| 6388 | shell_output->output = output; |
| 6389 | shell_output->shell = shell; |
| 6390 | shell_output->destroy_listener.notify = handle_output_destroy; |
| 6391 | wl_signal_add(&output->destroy_signal, |
| 6392 | &shell_output->destroy_listener); |
Kristian Høgsberg | a3a0e18 | 2013-10-23 23:36:04 -0700 | [diff] [blame] | 6393 | wl_list_insert(shell->output_list.prev, &shell_output->link); |
Xiong Zhang | 6b48142 | 2013-10-23 13:58:32 +0800 | [diff] [blame] | 6394 | } |
| 6395 | |
| 6396 | static void |
| 6397 | handle_output_create(struct wl_listener *listener, void *data) |
| 6398 | { |
| 6399 | struct desktop_shell *shell = |
| 6400 | container_of(listener, struct desktop_shell, output_create_listener); |
| 6401 | struct weston_output *output = (struct weston_output *)data; |
| 6402 | |
| 6403 | create_shell_output(shell, output); |
| 6404 | } |
| 6405 | |
| 6406 | static void |
Ander Conselvan de Oliveira | 304996d | 2014-04-11 13:57:15 +0300 | [diff] [blame] | 6407 | handle_output_move_layer(struct desktop_shell *shell, |
| 6408 | struct weston_layer *layer, void *data) |
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 | struct weston_output *output = data; |
Ander Conselvan de Oliveira | a8a9baf | 2014-01-29 18:47:52 +0200 | [diff] [blame] | 6411 | struct weston_view *view; |
| 6412 | float x, y; |
| 6413 | |
Giulio Camuffo | 412e6a5 | 2014-07-09 22:12:56 +0300 | [diff] [blame] | 6414 | 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] | 6415 | if (view->output != output) |
| 6416 | continue; |
| 6417 | |
| 6418 | x = view->geometry.x + output->move_x; |
| 6419 | y = view->geometry.y + output->move_y; |
| 6420 | weston_view_set_position(view, x, y); |
| 6421 | } |
| 6422 | } |
| 6423 | |
| 6424 | static void |
| 6425 | handle_output_move(struct wl_listener *listener, void *data) |
| 6426 | { |
| 6427 | struct desktop_shell *shell; |
| 6428 | |
Ander Conselvan de Oliveira | a8a9baf | 2014-01-29 18:47:52 +0200 | [diff] [blame] | 6429 | shell = container_of(listener, struct desktop_shell, |
| 6430 | output_move_listener); |
Ander Conselvan de Oliveira | a8a9baf | 2014-01-29 18:47:52 +0200 | [diff] [blame] | 6431 | |
Ander Conselvan de Oliveira | 304996d | 2014-04-11 13:57:15 +0300 | [diff] [blame] | 6432 | shell_for_each_layer(shell, handle_output_move_layer, data); |
Ander Conselvan de Oliveira | a8a9baf | 2014-01-29 18:47:52 +0200 | [diff] [blame] | 6433 | } |
| 6434 | |
| 6435 | static void |
Xiong Zhang | 6b48142 | 2013-10-23 13:58:32 +0800 | [diff] [blame] | 6436 | setup_output_destroy_handler(struct weston_compositor *ec, |
| 6437 | struct desktop_shell *shell) |
| 6438 | { |
| 6439 | struct weston_output *output; |
| 6440 | |
| 6441 | wl_list_init(&shell->output_list); |
| 6442 | wl_list_for_each(output, &ec->output_list, link) |
| 6443 | create_shell_output(shell, output); |
| 6444 | |
| 6445 | shell->output_create_listener.notify = handle_output_create; |
| 6446 | wl_signal_add(&ec->output_created_signal, |
| 6447 | &shell->output_create_listener); |
Ander Conselvan de Oliveira | a8a9baf | 2014-01-29 18:47:52 +0200 | [diff] [blame] | 6448 | |
| 6449 | shell->output_move_listener.notify = handle_output_move; |
| 6450 | wl_signal_add(&ec->output_moved_signal, &shell->output_move_listener); |
Xiong Zhang | 6b48142 | 2013-10-23 13:58:32 +0800 | [diff] [blame] | 6451 | } |
| 6452 | |
| 6453 | static void |
Kristian Høgsberg | 02e79dc | 2012-04-12 09:55:26 -0400 | [diff] [blame] | 6454 | shell_destroy(struct wl_listener *listener, void *data) |
Pekka Paalanen | 3c64723 | 2011-12-22 13:43:43 +0200 | [diff] [blame] | 6455 | { |
Tiago Vignatti | be14326 | 2012-04-16 17:31:41 +0300 | [diff] [blame] | 6456 | struct desktop_shell *shell = |
| 6457 | container_of(listener, struct desktop_shell, destroy_listener); |
Jonas Ådahl | e3cddce | 2012-06-13 00:01:22 +0200 | [diff] [blame] | 6458 | struct workspace **ws; |
Xiong Zhang | 6b48142 | 2013-10-23 13:58:32 +0800 | [diff] [blame] | 6459 | struct shell_output *shell_output, *tmp; |
Pekka Paalanen | 3c64723 | 2011-12-22 13:43:43 +0200 | [diff] [blame] | 6460 | |
Kristian Høgsberg | 17bccae | 2014-01-16 16:46:28 -0800 | [diff] [blame] | 6461 | /* Force state to unlocked so we don't try to fade */ |
| 6462 | shell->locked = false; |
Pekka Paalanen | 826dc14 | 2014-08-27 12:11:53 +0300 | [diff] [blame] | 6463 | |
| 6464 | if (shell->child.client) { |
| 6465 | /* disable respawn */ |
| 6466 | wl_list_remove(&shell->child.client_destroy_listener.link); |
Pekka Paalanen | 9cf5cc8 | 2012-01-02 16:00:24 +0200 | [diff] [blame] | 6467 | wl_client_destroy(shell->child.client); |
Pekka Paalanen | 826dc14 | 2014-08-27 12:11:53 +0300 | [diff] [blame] | 6468 | } |
Pekka Paalanen | 9cf5cc8 | 2012-01-02 16:00:24 +0200 | [diff] [blame] | 6469 | |
Ander Conselvan de Oliveira | a457563 | 2013-02-21 18:35:23 +0200 | [diff] [blame] | 6470 | wl_list_remove(&shell->idle_listener.link); |
| 6471 | wl_list_remove(&shell->wake_listener.link); |
Kristian Høgsberg | 677a5f5 | 2013-12-04 11:00:19 -0800 | [diff] [blame] | 6472 | |
Pekka Paalanen | aa9536a | 2015-06-24 16:09:17 +0300 | [diff] [blame] | 6473 | text_backend_destroy(shell->text_backend); |
Kristian Høgsberg | 677a5f5 | 2013-12-04 11:00:19 -0800 | [diff] [blame] | 6474 | input_panel_destroy(shell); |
Kristian Høgsberg | 88c1607 | 2012-05-16 08:04:19 -0400 | [diff] [blame] | 6475 | |
Xiong Zhang | 6b48142 | 2013-10-23 13:58:32 +0800 | [diff] [blame] | 6476 | wl_list_for_each_safe(shell_output, tmp, &shell->output_list, link) { |
| 6477 | wl_list_remove(&shell_output->destroy_listener.link); |
| 6478 | wl_list_remove(&shell_output->link); |
| 6479 | free(shell_output); |
| 6480 | } |
| 6481 | |
| 6482 | wl_list_remove(&shell->output_create_listener.link); |
Kristian Høgsberg | 6d50b0f | 2014-04-30 20:46:25 -0700 | [diff] [blame] | 6483 | wl_list_remove(&shell->output_move_listener.link); |
Xiong Zhang | 6b48142 | 2013-10-23 13:58:32 +0800 | [diff] [blame] | 6484 | |
Jonas Ådahl | e3cddce | 2012-06-13 00:01:22 +0200 | [diff] [blame] | 6485 | wl_array_for_each(ws, &shell->workspaces.array) |
| 6486 | workspace_destroy(*ws); |
| 6487 | wl_array_release(&shell->workspaces.array); |
| 6488 | |
Emilio Pozuelo Monfort | 46ce798 | 2013-11-20 13:22:29 +0100 | [diff] [blame] | 6489 | free(shell->client); |
Pekka Paalanen | 3c64723 | 2011-12-22 13:43:43 +0200 | [diff] [blame] | 6490 | free(shell); |
| 6491 | } |
| 6492 | |
Tiago Vignatti | 0b52d48 | 2012-04-20 18:54:25 +0300 | [diff] [blame] | 6493 | static void |
| 6494 | shell_add_bindings(struct weston_compositor *ec, struct desktop_shell *shell) |
| 6495 | { |
| 6496 | uint32_t mod; |
Jonas Ådahl | e3cddce | 2012-06-13 00:01:22 +0200 | [diff] [blame] | 6497 | int i, num_workspace_bindings; |
Tiago Vignatti | 0b52d48 | 2012-04-20 18:54:25 +0300 | [diff] [blame] | 6498 | |
| 6499 | /* fixed bindings */ |
Daniel Stone | 325fc2d | 2012-05-30 16:31:58 +0100 | [diff] [blame] | 6500 | weston_compositor_add_key_binding(ec, KEY_BACKSPACE, |
| 6501 | MODIFIER_CTRL | MODIFIER_ALT, |
| 6502 | terminate_binding, ec); |
| 6503 | weston_compositor_add_button_binding(ec, BTN_LEFT, 0, |
| 6504 | click_to_activate_binding, |
| 6505 | shell); |
Kristian Høgsberg | f0ce581 | 2014-04-07 11:52:17 -0700 | [diff] [blame] | 6506 | weston_compositor_add_button_binding(ec, BTN_RIGHT, 0, |
| 6507 | click_to_activate_binding, |
| 6508 | shell); |
Neil Roberts | a28c693 | 2013-10-03 16:43:04 +0100 | [diff] [blame] | 6509 | weston_compositor_add_touch_binding(ec, 0, |
| 6510 | touch_to_activate_binding, |
| 6511 | shell); |
Daniel Stone | 325fc2d | 2012-05-30 16:31:58 +0100 | [diff] [blame] | 6512 | weston_compositor_add_axis_binding(ec, WL_POINTER_AXIS_VERTICAL_SCROLL, |
| 6513 | MODIFIER_SUPER | MODIFIER_ALT, |
| 6514 | surface_opacity_binding, NULL); |
| 6515 | weston_compositor_add_axis_binding(ec, WL_POINTER_AXIS_VERTICAL_SCROLL, |
| 6516 | MODIFIER_SUPER, zoom_axis_binding, |
| 6517 | NULL); |
Tiago Vignatti | 0b52d48 | 2012-04-20 18:54:25 +0300 | [diff] [blame] | 6518 | |
| 6519 | /* configurable bindings */ |
| 6520 | mod = shell->binding_modifier; |
Daniel Stone | 325fc2d | 2012-05-30 16:31:58 +0100 | [diff] [blame] | 6521 | weston_compositor_add_key_binding(ec, KEY_PAGEUP, mod, |
| 6522 | zoom_key_binding, NULL); |
| 6523 | weston_compositor_add_key_binding(ec, KEY_PAGEDOWN, mod, |
| 6524 | zoom_key_binding, NULL); |
Kristian Høgsberg | 211b517 | 2014-01-11 13:10:21 -0800 | [diff] [blame] | 6525 | weston_compositor_add_key_binding(ec, KEY_M, mod | MODIFIER_SHIFT, |
| 6526 | maximize_binding, NULL); |
| 6527 | weston_compositor_add_key_binding(ec, KEY_F, mod | MODIFIER_SHIFT, |
| 6528 | fullscreen_binding, NULL); |
Daniel Stone | 325fc2d | 2012-05-30 16:31:58 +0100 | [diff] [blame] | 6529 | weston_compositor_add_button_binding(ec, BTN_LEFT, mod, move_binding, |
| 6530 | shell); |
Neil Roberts | aba0f25 | 2013-10-03 16:43:05 +0100 | [diff] [blame] | 6531 | weston_compositor_add_touch_binding(ec, mod, touch_move_binding, shell); |
Derek Foreman | 2217f3f | 2015-06-25 16:03:30 -0500 | [diff] [blame] | 6532 | weston_compositor_add_button_binding(ec, BTN_RIGHT, mod, |
Daniel Stone | 325fc2d | 2012-05-30 16:31:58 +0100 | [diff] [blame] | 6533 | resize_binding, shell); |
Kristian Høgsberg | 0837fa9 | 2014-01-20 10:35:26 -0800 | [diff] [blame] | 6534 | weston_compositor_add_button_binding(ec, BTN_LEFT, |
| 6535 | mod | MODIFIER_SHIFT, |
| 6536 | resize_binding, shell); |
Pekka Paalanen | 7bb6510 | 2013-05-22 18:03:04 +0300 | [diff] [blame] | 6537 | |
| 6538 | if (ec->capabilities & WESTON_CAP_ROTATION_ANY) |
Derek Foreman | 2217f3f | 2015-06-25 16:03:30 -0500 | [diff] [blame] | 6539 | weston_compositor_add_button_binding(ec, BTN_MIDDLE, mod, |
Pekka Paalanen | 7bb6510 | 2013-05-22 18:03:04 +0300 | [diff] [blame] | 6540 | rotate_binding, NULL); |
| 6541 | |
Daniel Stone | 325fc2d | 2012-05-30 16:31:58 +0100 | [diff] [blame] | 6542 | weston_compositor_add_key_binding(ec, KEY_TAB, mod, switcher_binding, |
| 6543 | shell); |
| 6544 | weston_compositor_add_key_binding(ec, KEY_F9, mod, backlight_binding, |
| 6545 | ec); |
| 6546 | weston_compositor_add_key_binding(ec, KEY_BRIGHTNESSDOWN, 0, |
| 6547 | backlight_binding, ec); |
| 6548 | weston_compositor_add_key_binding(ec, KEY_F10, mod, backlight_binding, |
| 6549 | ec); |
| 6550 | weston_compositor_add_key_binding(ec, KEY_BRIGHTNESSUP, 0, |
| 6551 | backlight_binding, ec); |
Daniel Stone | 325fc2d | 2012-05-30 16:31:58 +0100 | [diff] [blame] | 6552 | weston_compositor_add_key_binding(ec, KEY_K, mod, |
| 6553 | force_kill_binding, shell); |
Jonas Ådahl | e3cddce | 2012-06-13 00:01:22 +0200 | [diff] [blame] | 6554 | weston_compositor_add_key_binding(ec, KEY_UP, mod, |
| 6555 | workspace_up_binding, shell); |
| 6556 | weston_compositor_add_key_binding(ec, KEY_DOWN, mod, |
| 6557 | workspace_down_binding, shell); |
Jonas Ådahl | 8de6a1d | 2012-08-29 22:13:00 +0200 | [diff] [blame] | 6558 | weston_compositor_add_key_binding(ec, KEY_UP, mod | MODIFIER_SHIFT, |
| 6559 | workspace_move_surface_up_binding, |
| 6560 | shell); |
| 6561 | weston_compositor_add_key_binding(ec, KEY_DOWN, mod | MODIFIER_SHIFT, |
| 6562 | workspace_move_surface_down_binding, |
| 6563 | shell); |
Jonas Ådahl | e3cddce | 2012-06-13 00:01:22 +0200 | [diff] [blame] | 6564 | |
Kristian Høgsberg | d56ab4e | 2014-01-16 16:51:52 -0800 | [diff] [blame] | 6565 | if (shell->exposay_modifier) |
| 6566 | weston_compositor_add_modifier_binding(ec, shell->exposay_modifier, |
| 6567 | exposay_binding, shell); |
Daniel Stone | df8133b | 2013-11-19 11:37:14 +0100 | [diff] [blame] | 6568 | |
Jonas Ådahl | e3cddce | 2012-06-13 00:01:22 +0200 | [diff] [blame] | 6569 | /* Add bindings for mod+F[1-6] for workspace 1 to 6. */ |
| 6570 | if (shell->workspaces.num > 1) { |
| 6571 | num_workspace_bindings = shell->workspaces.num; |
| 6572 | if (num_workspace_bindings > 6) |
| 6573 | num_workspace_bindings = 6; |
| 6574 | for (i = 0; i < num_workspace_bindings; i++) |
| 6575 | weston_compositor_add_key_binding(ec, KEY_F1 + i, mod, |
| 6576 | workspace_f_binding, |
| 6577 | shell); |
| 6578 | } |
Ander Conselvan de Oliveira | c509d2b | 2012-11-08 17:20:45 +0200 | [diff] [blame] | 6579 | |
Pekka Paalanen | 2829f7c | 2015-02-19 17:02:13 +0200 | [diff] [blame] | 6580 | weston_install_debug_key_binding(ec, mod); |
Tiago Vignatti | 0b52d48 | 2012-04-20 18:54:25 +0300 | [diff] [blame] | 6581 | } |
| 6582 | |
Jason Ekstrand | 024177c | 2014-04-21 19:42:58 -0500 | [diff] [blame] | 6583 | static void |
| 6584 | handle_seat_created(struct wl_listener *listener, void *data) |
| 6585 | { |
| 6586 | struct weston_seat *seat = data; |
| 6587 | |
| 6588 | create_shell_seat(seat); |
| 6589 | } |
| 6590 | |
Kristian Høgsberg | 1c56218 | 2011-05-02 22:09:20 -0400 | [diff] [blame] | 6591 | WL_EXPORT int |
Kristian Høgsberg | cb4685b | 2013-02-20 15:37:49 -0500 | [diff] [blame] | 6592 | module_init(struct weston_compositor *ec, |
Ossama Othman | a50e6e4 | 2013-05-14 09:48:26 -0700 | [diff] [blame] | 6593 | int *argc, char *argv[]) |
Kristian Høgsberg | 4cca349 | 2011-01-18 07:53:49 -0500 | [diff] [blame] | 6594 | { |
Kristian Høgsberg | f4d2f23 | 2012-08-10 10:05:39 -0400 | [diff] [blame] | 6595 | struct weston_seat *seat; |
Tiago Vignatti | be14326 | 2012-04-16 17:31:41 +0300 | [diff] [blame] | 6596 | struct desktop_shell *shell; |
Jonas Ådahl | e3cddce | 2012-06-13 00:01:22 +0200 | [diff] [blame] | 6597 | struct workspace **pws; |
| 6598 | unsigned int i; |
Tiago Vignatti | b7dbbd6 | 2012-09-25 17:57:01 +0300 | [diff] [blame] | 6599 | struct wl_event_loop *loop; |
Kristian Høgsberg | 02ec0a5 | 2011-04-23 13:04:11 -0400 | [diff] [blame] | 6600 | |
Peter Hutterer | f3d6227 | 2013-08-08 11:57:05 +1000 | [diff] [blame] | 6601 | shell = zalloc(sizeof *shell); |
Kristian Høgsberg | 02ec0a5 | 2011-04-23 13:04:11 -0400 | [diff] [blame] | 6602 | if (shell == NULL) |
| 6603 | return -1; |
| 6604 | |
Kristian Høgsberg | 7584062 | 2011-09-06 13:48:16 -0400 | [diff] [blame] | 6605 | shell->compositor = ec; |
Kristian Høgsberg | 02e79dc | 2012-04-12 09:55:26 -0400 | [diff] [blame] | 6606 | |
| 6607 | shell->destroy_listener.notify = shell_destroy; |
| 6608 | wl_signal_add(&ec->destroy_signal, &shell->destroy_listener); |
Ander Conselvan de Oliveira | a457563 | 2013-02-21 18:35:23 +0200 | [diff] [blame] | 6609 | shell->idle_listener.notify = idle_handler; |
| 6610 | wl_signal_add(&ec->idle_signal, &shell->idle_listener); |
| 6611 | shell->wake_listener.notify = wake_handler; |
| 6612 | wl_signal_add(&ec->wake_signal, &shell->wake_listener); |
Kristian Høgsberg | 677a5f5 | 2013-12-04 11:00:19 -0800 | [diff] [blame] | 6613 | |
Kristian Høgsberg | 82a1d11 | 2012-07-19 14:02:00 -0400 | [diff] [blame] | 6614 | ec->shell_interface.shell = shell; |
Tiago Vignatti | bc052c9 | 2012-04-19 16:18:18 +0300 | [diff] [blame] | 6615 | ec->shell_interface.create_shell_surface = create_shell_surface; |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 6616 | ec->shell_interface.get_primary_view = get_primary_view; |
Tiago Vignatti | bc052c9 | 2012-04-19 16:18:18 +0300 | [diff] [blame] | 6617 | ec->shell_interface.set_toplevel = set_toplevel; |
Tiago Vignatti | 491bac1 | 2012-05-18 16:37:43 -0400 | [diff] [blame] | 6618 | ec->shell_interface.set_transient = set_transient; |
Kristian Høgsberg | 4779241 | 2014-05-04 13:47:06 -0700 | [diff] [blame] | 6619 | ec->shell_interface.set_fullscreen = shell_interface_set_fullscreen; |
Tiago Vignatti | fb2adba | 2013-06-12 15:43:21 -0300 | [diff] [blame] | 6620 | ec->shell_interface.set_xwayland = set_xwayland; |
Kristian Høgsberg | ae356ae | 2014-04-29 16:03:54 -0700 | [diff] [blame] | 6621 | ec->shell_interface.move = shell_interface_move; |
Derek Foreman | 8fbebbd | 2015-07-15 13:00:40 -0500 | [diff] [blame] | 6622 | ec->shell_interface.resize = shell_interface_resize; |
Giulio Camuffo | 62942ad | 2013-09-11 18:20:47 +0200 | [diff] [blame] | 6623 | ec->shell_interface.set_title = set_title; |
Jasper St. Pierre | ccf48fb | 2014-05-02 10:21:38 -0400 | [diff] [blame] | 6624 | ec->shell_interface.set_window_geometry = set_window_geometry; |
Giulio Camuffo | 6b4b241 | 2015-01-29 19:06:49 +0200 | [diff] [blame] | 6625 | ec->shell_interface.set_maximized = shell_interface_set_maximized; |
Giulio Camuffo | a8e9b41 | 2015-01-27 19:10:37 +0200 | [diff] [blame] | 6626 | ec->shell_interface.set_pid = set_pid; |
Kristian Høgsberg | 4cca349 | 2011-01-18 07:53:49 -0500 | [diff] [blame] | 6627 | |
Kristian Høgsberg | 3be2ce9 | 2012-02-29 12:42:35 -0500 | [diff] [blame] | 6628 | weston_layer_init(&shell->fullscreen_layer, &ec->cursor_layer.link); |
| 6629 | weston_layer_init(&shell->panel_layer, &shell->fullscreen_layer.link); |
Jonas Ådahl | e3cddce | 2012-06-13 00:01:22 +0200 | [diff] [blame] | 6630 | weston_layer_init(&shell->background_layer, &shell->panel_layer.link); |
| 6631 | weston_layer_init(&shell->lock_layer, NULL); |
Philipp Brüschweiler | 711fda8 | 2012-08-09 18:50:43 +0200 | [diff] [blame] | 6632 | weston_layer_init(&shell->input_panel_layer, NULL); |
Jonas Ådahl | e3cddce | 2012-06-13 00:01:22 +0200 | [diff] [blame] | 6633 | |
| 6634 | wl_array_init(&shell->workspaces.array); |
Jonas Ådahl | e9d2250 | 2012-08-29 22:13:01 +0200 | [diff] [blame] | 6635 | wl_list_init(&shell->workspaces.client_list); |
Kristian Høgsberg | 3be2ce9 | 2012-02-29 12:42:35 -0500 | [diff] [blame] | 6636 | |
Kristian Høgsberg | 677a5f5 | 2013-12-04 11:00:19 -0800 | [diff] [blame] | 6637 | if (input_panel_setup(shell) < 0) |
| 6638 | return -1; |
| 6639 | |
Pekka Paalanen | aa9536a | 2015-06-24 16:09:17 +0300 | [diff] [blame] | 6640 | shell->text_backend = text_backend_init(ec); |
| 6641 | if (!shell->text_backend) |
Murray Calavera | 9a51cd7 | 2015-06-10 21:16:02 +0000 | [diff] [blame] | 6642 | return -1; |
| 6643 | |
Kristian Høgsberg | 14e438c | 2013-05-26 21:48:14 -0400 | [diff] [blame] | 6644 | shell_configuration(shell); |
Pekka Paalanen | e955f1e | 2011-12-07 11:49:52 +0200 | [diff] [blame] | 6645 | |
Daniel Stone | df8133b | 2013-11-19 11:37:14 +0100 | [diff] [blame] | 6646 | shell->exposay.state_cur = EXPOSAY_LAYOUT_INACTIVE; |
| 6647 | shell->exposay.state_target = EXPOSAY_TARGET_CANCEL; |
| 6648 | |
Jonas Ådahl | e3cddce | 2012-06-13 00:01:22 +0200 | [diff] [blame] | 6649 | for (i = 0; i < shell->workspaces.num; i++) { |
| 6650 | pws = wl_array_add(&shell->workspaces.array, sizeof *pws); |
| 6651 | if (pws == NULL) |
| 6652 | return -1; |
| 6653 | |
| 6654 | *pws = workspace_create(); |
| 6655 | if (*pws == NULL) |
| 6656 | return -1; |
| 6657 | } |
| 6658 | activate_workspace(shell, 0); |
| 6659 | |
Manuel Bachmann | 50c87db | 2014-02-26 15:52:13 +0100 | [diff] [blame] | 6660 | weston_layer_init(&shell->minimized_layer, NULL); |
| 6661 | |
Jonas Ådahl | 8de6a1d | 2012-08-29 22:13:00 +0200 | [diff] [blame] | 6662 | wl_list_init(&shell->workspaces.anim_sticky_list); |
Jonas Ådahl | 62fcd04 | 2012-06-13 00:01:23 +0200 | [diff] [blame] | 6663 | wl_list_init(&shell->workspaces.animation.link); |
| 6664 | shell->workspaces.animation.frame = animate_workspace_change_frame; |
| 6665 | |
Kristian Høgsberg | 919cddb | 2013-07-08 19:03:57 -0400 | [diff] [blame] | 6666 | if (wl_global_create(ec->wl_display, &wl_shell_interface, 1, |
Kristian Høgsberg | 97d44aa | 2011-08-26 17:21:20 -0400 | [diff] [blame] | 6667 | shell, bind_shell) == NULL) |
Kristian Høgsberg | 4cca349 | 2011-01-18 07:53:49 -0500 | [diff] [blame] | 6668 | return -1; |
| 6669 | |
Rafael Antognolli | e2a3455 | 2013-12-03 15:35:45 -0200 | [diff] [blame] | 6670 | if (wl_global_create(ec->wl_display, &xdg_shell_interface, 1, |
| 6671 | shell, bind_xdg_shell) == NULL) |
| 6672 | return -1; |
| 6673 | |
Kristian Høgsberg | 919cddb | 2013-07-08 19:03:57 -0400 | [diff] [blame] | 6674 | if (wl_global_create(ec->wl_display, |
Jonny Lamb | 765760d | 2014-08-20 15:53:19 +0200 | [diff] [blame] | 6675 | &desktop_shell_interface, 3, |
Kristian Høgsberg | 919cddb | 2013-07-08 19:03:57 -0400 | [diff] [blame] | 6676 | shell, bind_desktop_shell) == NULL) |
Kristian Høgsberg | 7584062 | 2011-09-06 13:48:16 -0400 | [diff] [blame] | 6677 | return -1; |
| 6678 | |
Kristian Høgsberg | 919cddb | 2013-07-08 19:03:57 -0400 | [diff] [blame] | 6679 | if (wl_global_create(ec->wl_display, &workspace_manager_interface, 1, |
| 6680 | shell, bind_workspace_manager) == NULL) |
Jonas Ådahl | e9d2250 | 2012-08-29 22:13:01 +0200 | [diff] [blame] | 6681 | return -1; |
| 6682 | |
Kristian Høgsberg | f03a616 | 2012-01-17 11:07:42 -0500 | [diff] [blame] | 6683 | shell->child.deathstamp = weston_compositor_get_time(); |
Tiago Vignatti | b7dbbd6 | 2012-09-25 17:57:01 +0300 | [diff] [blame] | 6684 | |
Jonny Lamb | 765760d | 2014-08-20 15:53:19 +0200 | [diff] [blame] | 6685 | shell->panel_position = DESKTOP_SHELL_PANEL_POSITION_TOP; |
| 6686 | |
Xiong Zhang | 6b48142 | 2013-10-23 13:58:32 +0800 | [diff] [blame] | 6687 | setup_output_destroy_handler(ec, shell); |
| 6688 | |
Tiago Vignatti | b7dbbd6 | 2012-09-25 17:57:01 +0300 | [diff] [blame] | 6689 | loop = wl_display_get_event_loop(ec->wl_display); |
| 6690 | wl_event_loop_add_idle(loop, launch_desktop_shell_process, shell); |
Pekka Paalanen | 6cd281a | 2011-11-03 14:11:32 +0200 | [diff] [blame] | 6691 | |
Jason Ekstrand | 024177c | 2014-04-21 19:42:58 -0500 | [diff] [blame] | 6692 | wl_list_for_each(seat, &ec->seat_list, link) |
| 6693 | handle_seat_created(NULL, seat); |
| 6694 | shell->seat_create_listener.notify = handle_seat_created; |
| 6695 | wl_signal_add(&ec->seat_created_signal, &shell->seat_create_listener); |
Kristian Høgsberg | d56bd90 | 2012-06-05 09:58:51 -0400 | [diff] [blame] | 6696 | |
Giulio Camuffo | c6ab3d5 | 2013-12-11 23:45:12 +0100 | [diff] [blame] | 6697 | screenshooter_create(ec); |
| 6698 | |
Tiago Vignatti | 0b52d48 | 2012-04-20 18:54:25 +0300 | [diff] [blame] | 6699 | shell_add_bindings(ec, shell); |
Kristian Høgsberg | 0793756 | 2011-04-12 17:25:42 -0400 | [diff] [blame] | 6700 | |
Pekka Paalanen | 79346ab | 2013-05-22 18:03:09 +0300 | [diff] [blame] | 6701 | shell_fade_init(shell); |
Ander Conselvan de Oliveira | 19d10ef | 2013-02-21 18:35:20 +0200 | [diff] [blame] | 6702 | |
Pekka Paalanen | 2e62e4a | 2014-08-28 11:41:26 +0300 | [diff] [blame] | 6703 | clock_gettime(CLOCK_MONOTONIC, &shell->startup_time); |
| 6704 | |
Kristian Høgsberg | 4cca349 | 2011-01-18 07:53:49 -0500 | [diff] [blame] | 6705 | return 0; |
| 6706 | } |