Kristian Høgsberg | 4cca349 | 2011-01-18 07:53:49 -0500 | [diff] [blame] | 1 | /* |
Kristian Høgsberg | 0704539 | 2012-02-19 18:52:44 -0500 | [diff] [blame] | 2 | * Copyright © 2010-2012 Intel Corporation |
Pekka Paalanen | d581a8f | 2012-01-27 16:25:16 +0200 | [diff] [blame] | 3 | * Copyright © 2011-2012 Collabora, Ltd. |
Daniel Stone | df8133b | 2013-11-19 11:37:14 +0100 | [diff] [blame] | 4 | * Copyright © 2013 Raspberry Pi Foundation |
Kristian Høgsberg | 4cca349 | 2011-01-18 07:53:49 -0500 | [diff] [blame] | 5 | * |
Bryce Harrington | af637c2 | 2015-06-11 12:55:55 -0700 | [diff] [blame] | 6 | * Permission is hereby granted, free of charge, to any person obtaining a |
| 7 | * copy of this software and associated documentation files (the "Software"), |
| 8 | * to deal in the Software without restriction, including without limitation |
| 9 | * the rights to use, copy, modify, merge, publish, distribute, sublicense, |
| 10 | * and/or sell copies of the Software, and to permit persons to whom the |
| 11 | * Software is furnished to do so, subject to the following conditions: |
Kristian Høgsberg | 4cca349 | 2011-01-18 07:53:49 -0500 | [diff] [blame] | 12 | * |
Bryce Harrington | af637c2 | 2015-06-11 12:55:55 -0700 | [diff] [blame] | 13 | * The above copyright notice and this permission notice (including the next |
| 14 | * paragraph) shall be included in all copies or substantial portions of the |
| 15 | * Software. |
| 16 | * |
| 17 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR |
| 18 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, |
| 19 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL |
| 20 | * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER |
| 21 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING |
| 22 | * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER |
| 23 | * DEALINGS IN THE SOFTWARE. |
Kristian Høgsberg | 4cca349 | 2011-01-18 07:53:49 -0500 | [diff] [blame] | 24 | */ |
| 25 | |
Daniel Stone | c228e23 | 2013-05-22 18:03:19 +0300 | [diff] [blame] | 26 | #include "config.h" |
| 27 | |
Kristian Høgsberg | 4cca349 | 2011-01-18 07:53:49 -0500 | [diff] [blame] | 28 | #include <stdlib.h> |
Kristian Høgsberg | 7584062 | 2011-09-06 13:48:16 -0400 | [diff] [blame] | 29 | #include <stdio.h> |
Kristian Høgsberg | 4cca349 | 2011-01-18 07:53:49 -0500 | [diff] [blame] | 30 | #include <string.h> |
| 31 | #include <unistd.h> |
Kristian Høgsberg | 0793756 | 2011-04-12 17:25:42 -0400 | [diff] [blame] | 32 | #include <linux/input.h> |
Pekka Paalanen | f0fc70d | 2011-11-15 13:34:54 +0200 | [diff] [blame] | 33 | #include <assert.h> |
Pekka Paalanen | 18027e5 | 2011-12-02 16:31:49 +0200 | [diff] [blame] | 34 | #include <signal.h> |
Pekka Paalanen | 460099f | 2012-01-20 16:48:25 +0200 | [diff] [blame] | 35 | #include <math.h> |
Kristian Høgsberg | 92a57db | 2012-05-26 13:41:06 -0400 | [diff] [blame] | 36 | #include <sys/types.h> |
Kristian Høgsberg | 4cca349 | 2011-01-18 07:53:49 -0500 | [diff] [blame] | 37 | |
Kristian Høgsberg | 1ef2313 | 2013-12-04 00:20:01 -0800 | [diff] [blame] | 38 | #include "shell.h" |
Kristian Høgsberg | 7584062 | 2011-09-06 13:48:16 -0400 | [diff] [blame] | 39 | #include "desktop-shell-server-protocol.h" |
Jonas Ådahl | e9d2250 | 2012-08-29 22:13:01 +0200 | [diff] [blame] | 40 | #include "workspaces-server-protocol.h" |
Jon Cruz | 4678bab | 2015-06-15 15:37:07 -0700 | [diff] [blame] | 41 | #include "shared/config-parser.h" |
Jon Cruz | d618f68 | 2015-06-15 15:37:09 -0700 | [diff] [blame] | 42 | #include "shared/helpers.h" |
Rafael Antognolli | e2a3455 | 2013-12-03 15:35:45 -0200 | [diff] [blame] | 43 | #include "xdg-shell-server-protocol.h" |
Kristian Høgsberg | 4cca349 | 2011-01-18 07:53:49 -0500 | [diff] [blame] | 44 | |
Jonas Ådahl | e3cddce | 2012-06-13 00:01:22 +0200 | [diff] [blame] | 45 | #define DEFAULT_NUM_WORKSPACES 1 |
Jonas Ådahl | 62fcd04 | 2012-06-13 00:01:23 +0200 | [diff] [blame] | 46 | #define DEFAULT_WORKSPACE_CHANGE_ANIMATION_LENGTH 200 |
Jonas Ådahl | e3cddce | 2012-06-13 00:01:22 +0200 | [diff] [blame] | 47 | |
Giulio Camuffo | 1aaf3e4 | 2013-12-09 22:47:58 +0100 | [diff] [blame] | 48 | #ifndef static_assert |
| 49 | #define static_assert(cond, msg) |
| 50 | #endif |
| 51 | |
Jonas Ådahl | 0476974 | 2012-06-13 00:01:24 +0200 | [diff] [blame] | 52 | struct focus_state { |
| 53 | struct weston_seat *seat; |
Kristian Høgsberg | 2f5faff | 2012-07-31 16:36:34 -0400 | [diff] [blame] | 54 | struct workspace *ws; |
Jonas Ådahl | 0476974 | 2012-06-13 00:01:24 +0200 | [diff] [blame] | 55 | struct weston_surface *keyboard_focus; |
| 56 | struct wl_list link; |
| 57 | struct wl_listener seat_destroy_listener; |
| 58 | struct wl_listener surface_destroy_listener; |
| 59 | }; |
| 60 | |
Kristian Høgsberg | d2abb83 | 2011-11-23 10:52:40 -0500 | [diff] [blame] | 61 | enum shell_surface_type { |
Pekka Paalanen | 9826223 | 2011-12-01 10:42:22 +0200 | [diff] [blame] | 62 | SHELL_SURFACE_NONE, |
Kristian Høgsberg | d2abb83 | 2011-11-23 10:52:40 -0500 | [diff] [blame] | 63 | SHELL_SURFACE_TOPLEVEL, |
Tiago Vignatti | fb2adba | 2013-06-12 15:43:21 -0300 | [diff] [blame] | 64 | SHELL_SURFACE_POPUP, |
| 65 | SHELL_SURFACE_XWAYLAND |
Pekka Paalanen | 57da4a8 | 2011-11-23 16:42:16 +0200 | [diff] [blame] | 66 | }; |
| 67 | |
Jason Ekstrand | 9e9512f | 2014-04-16 21:12:10 -0500 | [diff] [blame] | 68 | struct shell_client; |
| 69 | |
Philip Withnall | 648a4dd | 2013-11-25 18:01:44 +0000 | [diff] [blame] | 70 | /* |
| 71 | * Surface stacking and ordering. |
| 72 | * |
| 73 | * This is handled using several linked lists of surfaces, organised into |
| 74 | * ‘layers’. The layers are ordered, and each of the surfaces in one layer are |
| 75 | * above all of the surfaces in the layer below. The set of layers is static and |
| 76 | * in the following order (top-most first): |
| 77 | * • Lock layer (only ever displayed on its own) |
| 78 | * • Cursor layer |
Manuel Bachmann | 805d2f5 | 2014-03-05 12:21:34 +0100 | [diff] [blame] | 79 | * • Input panel layer |
Philip Withnall | 648a4dd | 2013-11-25 18:01:44 +0000 | [diff] [blame] | 80 | * • Fullscreen layer |
| 81 | * • Panel layer |
Philip Withnall | 648a4dd | 2013-11-25 18:01:44 +0000 | [diff] [blame] | 82 | * • Workspace layers |
| 83 | * • Background layer |
| 84 | * |
| 85 | * The list of layers may be manipulated to remove whole layers of surfaces from |
| 86 | * display. For example, when locking the screen, all layers except the lock |
| 87 | * layer are removed. |
| 88 | * |
| 89 | * A surface’s layer is modified on configuring the surface, in |
| 90 | * set_surface_type() (which is only called when the surface’s type change is |
| 91 | * _committed_). If a surface’s type changes (e.g. when making a window |
| 92 | * fullscreen) its layer changes too. |
| 93 | * |
| 94 | * In order to allow popup and transient surfaces to be correctly stacked above |
| 95 | * their parent surfaces, each surface tracks both its parent surface, and a |
| 96 | * linked list of its children. When a surface’s layer is updated, so are the |
| 97 | * layers of its children. Note that child surfaces are *not* the same as |
| 98 | * subsurfaces — child/parent surfaces are purely for maintaining stacking |
| 99 | * order. |
| 100 | * |
| 101 | * The children_link list of siblings of a surface (i.e. those surfaces which |
| 102 | * have the same parent) only contains weston_surfaces which have a |
| 103 | * shell_surface. Stacking is not implemented for non-shell_surface |
| 104 | * weston_surfaces. This means that the following implication does *not* hold: |
| 105 | * (shsurf->parent != NULL) ⇒ !wl_list_is_empty(shsurf->children_link) |
| 106 | */ |
| 107 | |
Pekka Paalanen | 56cdea9 | 2011-11-23 16:14:12 +0200 | [diff] [blame] | 108 | struct shell_surface { |
Jason Ekstrand | 651f00e | 2013-06-14 10:07:54 -0500 | [diff] [blame] | 109 | struct wl_resource *resource; |
| 110 | struct wl_signal destroy_signal; |
Jason Ekstrand | 9e9512f | 2014-04-16 21:12:10 -0500 | [diff] [blame] | 111 | struct shell_client *owner; |
Jonas Ådahl | 49d77d2 | 2015-03-18 16:20:51 +0800 | [diff] [blame] | 112 | struct wl_resource *owner_resource; |
Pekka Paalanen | 9d1613e | 2011-11-25 12:09:16 +0200 | [diff] [blame] | 113 | |
Kristian Høgsberg | 8334bc1 | 2012-01-03 10:29:47 -0500 | [diff] [blame] | 114 | struct weston_surface *surface; |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 115 | struct weston_view *view; |
Jason Ekstrand | 918f2dd | 2013-12-02 21:01:53 -0600 | [diff] [blame] | 116 | int32_t last_width, last_height; |
Pekka Paalanen | 9d1613e | 2011-11-25 12:09:16 +0200 | [diff] [blame] | 117 | struct wl_listener surface_destroy_listener; |
Kristian Høgsberg | 160fe75 | 2014-03-11 10:19:10 -0700 | [diff] [blame] | 118 | struct wl_listener resource_destroy_listener; |
| 119 | |
Kristian Høgsberg | 8150b19 | 2012-06-27 10:22:58 -0400 | [diff] [blame] | 120 | struct weston_surface *parent; |
Philip Withnall | 648a4dd | 2013-11-25 18:01:44 +0000 | [diff] [blame] | 121 | struct wl_list children_list; /* child surfaces of this one */ |
| 122 | struct wl_list children_link; /* sibling surfaces of this one */ |
Tiago Vignatti | be14326 | 2012-04-16 17:31:41 +0300 | [diff] [blame] | 123 | struct desktop_shell *shell; |
Pekka Paalanen | 57da4a8 | 2011-11-23 16:42:16 +0200 | [diff] [blame] | 124 | |
Kristian Høgsberg | c8f8dd8 | 2013-12-05 23:20:33 -0800 | [diff] [blame] | 125 | enum shell_surface_type type; |
Kristian Høgsberg | e7afd91 | 2012-05-02 09:47:44 -0400 | [diff] [blame] | 126 | char *title, *class; |
Kristian Høgsberg | d2abb83 | 2011-11-23 10:52:40 -0500 | [diff] [blame] | 127 | int32_t saved_x, saved_y; |
Rafael Antognolli | 3c4e3f7 | 2013-12-03 15:35:46 -0200 | [diff] [blame] | 128 | int32_t saved_width, saved_height; |
Alex Wu | 4539b08 | 2012-03-01 12:57:46 +0800 | [diff] [blame] | 129 | bool saved_position_valid; |
Rafael Antognolli | 3c4e3f7 | 2013-12-03 15:35:46 -0200 | [diff] [blame] | 130 | bool saved_size_valid; |
Alex Wu | 7bcb8bd | 2012-04-27 09:07:24 +0800 | [diff] [blame] | 131 | bool saved_rotation_valid; |
Kristian Høgsberg | c85f1d4 | 2013-10-24 16:52:00 -0700 | [diff] [blame] | 132 | int unresponsive, grabbed; |
Kristian Høgsberg | 44cd196 | 2014-02-05 21:36:04 -0800 | [diff] [blame] | 133 | uint32_t resize_edges; |
Benjamin Franzke | d0f79ab | 2011-11-22 12:43:52 +0100 | [diff] [blame] | 134 | |
Kristian Høgsberg | b3cca0a | 2012-01-04 22:19:14 -0500 | [diff] [blame] | 135 | struct { |
Pekka Paalanen | 460099f | 2012-01-20 16:48:25 +0200 | [diff] [blame] | 136 | struct weston_transform transform; |
Kristian Høgsberg | 765e27b | 2012-01-27 13:36:13 -0500 | [diff] [blame] | 137 | struct weston_matrix rotation; |
Pekka Paalanen | 460099f | 2012-01-20 16:48:25 +0200 | [diff] [blame] | 138 | } rotation; |
| 139 | |
| 140 | struct { |
Giulio Camuffo | 5085a75 | 2013-03-25 21:42:45 +0100 | [diff] [blame] | 141 | struct wl_list grab_link; |
Kristian Høgsberg | b3cca0a | 2012-01-04 22:19:14 -0500 | [diff] [blame] | 142 | int32_t x, y; |
Giulio Camuffo | 5085a75 | 2013-03-25 21:42:45 +0100 | [diff] [blame] | 143 | struct shell_seat *shseat; |
Kristian Høgsberg | 3730f36 | 2012-04-13 12:40:07 -0400 | [diff] [blame] | 144 | uint32_t serial; |
Kristian Høgsberg | b3cca0a | 2012-01-04 22:19:14 -0500 | [diff] [blame] | 145 | } popup; |
| 146 | |
Alex Wu | 4539b08 | 2012-03-01 12:57:46 +0800 | [diff] [blame] | 147 | struct { |
Tiago Vignatti | 52e598c | 2012-05-07 15:23:08 +0300 | [diff] [blame] | 148 | int32_t x, y; |
Tiago Vignatti | 491bac1 | 2012-05-18 16:37:43 -0400 | [diff] [blame] | 149 | uint32_t flags; |
Tiago Vignatti | 52e598c | 2012-05-07 15:23:08 +0300 | [diff] [blame] | 150 | } transient; |
| 151 | |
| 152 | struct { |
Alex Wu | 4539b08 | 2012-03-01 12:57:46 +0800 | [diff] [blame] | 153 | enum wl_shell_surface_fullscreen_method type; |
| 154 | struct weston_transform transform; /* matrix from x, y */ |
| 155 | uint32_t framerate; |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 156 | struct weston_view *black_view; |
Alex Wu | 4539b08 | 2012-03-01 12:57:46 +0800 | [diff] [blame] | 157 | } fullscreen; |
| 158 | |
Jonas Ådahl | 62fcd04 | 2012-06-13 00:01:23 +0200 | [diff] [blame] | 159 | struct weston_transform workspace_transform; |
| 160 | |
Kristian Høgsberg | 1cbf326 | 2012-02-17 23:49:07 -0500 | [diff] [blame] | 161 | struct weston_output *fullscreen_output; |
Kristian Høgsberg | 8334bc1 | 2012-01-03 10:29:47 -0500 | [diff] [blame] | 162 | struct weston_output *output; |
Benjamin Franzke | d0f79ab | 2011-11-22 12:43:52 +0100 | [diff] [blame] | 163 | struct wl_list link; |
Kristian Høgsberg | a61ca06 | 2012-05-22 16:05:52 -0400 | [diff] [blame] | 164 | |
| 165 | const struct weston_shell_client *client; |
Rafael Antognolli | 03b1659 | 2013-12-03 15:35:42 -0200 | [diff] [blame] | 166 | |
Jasper St. Pierre | 6458ec3 | 2014-04-11 16:00:31 -0700 | [diff] [blame] | 167 | struct surface_state { |
Rafael Antognolli | 03b1659 | 2013-12-03 15:35:42 -0200 | [diff] [blame] | 168 | bool maximized; |
| 169 | bool fullscreen; |
Rafael Antognolli | ed207b4 | 2013-12-03 15:35:43 -0200 | [diff] [blame] | 170 | bool relative; |
Emilio Pozuelo Monfort | 9e7c759 | 2014-01-30 14:01:10 +0100 | [diff] [blame] | 171 | bool lowered; |
Jasper St. Pierre | 8c6aa45 | 2014-02-08 18:29:49 -0500 | [diff] [blame] | 172 | } state, next_state, requested_state; /* surface states */ |
Rafael Antognolli | 03b1659 | 2013-12-03 15:35:42 -0200 | [diff] [blame] | 173 | bool state_changed; |
Jasper St. Pierre | 8c6aa45 | 2014-02-08 18:29:49 -0500 | [diff] [blame] | 174 | bool state_requested; |
Jasper St. Pierre | faf27a9 | 2013-12-09 17:36:28 -0500 | [diff] [blame] | 175 | |
Kristian Høgsberg | ae356ae | 2014-04-29 16:03:54 -0700 | [diff] [blame] | 176 | struct { |
Jasper St. Pierre | ccf48fb | 2014-05-02 10:21:38 -0400 | [diff] [blame] | 177 | int32_t x, y, width, height; |
| 178 | } geometry, next_geometry; |
| 179 | bool has_set_geometry, has_next_geometry; |
Kristian Høgsberg | ae356ae | 2014-04-29 16:03:54 -0700 | [diff] [blame] | 180 | |
Jasper St. Pierre | faf27a9 | 2013-12-09 17:36:28 -0500 | [diff] [blame] | 181 | int focus_count; |
Derek Foreman | 039e9be | 2015-04-14 17:09:06 -0500 | [diff] [blame] | 182 | |
| 183 | bool destroying; |
Pekka Paalanen | 56cdea9 | 2011-11-23 16:14:12 +0200 | [diff] [blame] | 184 | }; |
| 185 | |
Ander Conselvan de Oliveira | fe0444a | 2012-04-04 17:48:05 +0300 | [diff] [blame] | 186 | struct shell_grab { |
Kristian Høgsberg | 02bbabb | 2013-05-06 22:15:05 -0400 | [diff] [blame] | 187 | struct weston_pointer_grab grab; |
Ander Conselvan de Oliveira | fe0444a | 2012-04-04 17:48:05 +0300 | [diff] [blame] | 188 | struct shell_surface *shsurf; |
| 189 | struct wl_listener shsurf_destroy_listener; |
| 190 | }; |
| 191 | |
Rusty Lynch | 1084da5 | 2013-08-15 09:10:08 -0700 | [diff] [blame] | 192 | struct shell_touch_grab { |
| 193 | struct weston_touch_grab grab; |
| 194 | struct shell_surface *shsurf; |
| 195 | struct wl_listener shsurf_destroy_listener; |
| 196 | struct weston_touch *touch; |
| 197 | }; |
| 198 | |
Ander Conselvan de Oliveira | fe0444a | 2012-04-04 17:48:05 +0300 | [diff] [blame] | 199 | struct weston_move_grab { |
| 200 | struct shell_grab base; |
Daniel Stone | 103db7f | 2012-05-08 17:17:55 +0100 | [diff] [blame] | 201 | wl_fixed_t dx, dy; |
Derek Foreman | cf7d95a | 2015-06-03 15:53:22 -0500 | [diff] [blame] | 202 | bool client_initiated; |
Kristian Høgsberg | 4cca349 | 2011-01-18 07:53:49 -0500 | [diff] [blame] | 203 | }; |
| 204 | |
Rusty Lynch | 1084da5 | 2013-08-15 09:10:08 -0700 | [diff] [blame] | 205 | struct weston_touch_move_grab { |
| 206 | struct shell_touch_grab base; |
Kristian Høgsberg | 8e80a31 | 2014-01-17 15:18:10 -0800 | [diff] [blame] | 207 | int active; |
Rusty Lynch | 1084da5 | 2013-08-15 09:10:08 -0700 | [diff] [blame] | 208 | wl_fixed_t dx, dy; |
| 209 | }; |
| 210 | |
Pekka Paalanen | 460099f | 2012-01-20 16:48:25 +0200 | [diff] [blame] | 211 | struct rotate_grab { |
Ander Conselvan de Oliveira | fe0444a | 2012-04-04 17:48:05 +0300 | [diff] [blame] | 212 | struct shell_grab base; |
Kristian Høgsberg | 765e27b | 2012-01-27 13:36:13 -0500 | [diff] [blame] | 213 | struct weston_matrix rotation; |
Pekka Paalanen | 460099f | 2012-01-20 16:48:25 +0200 | [diff] [blame] | 214 | struct { |
John Kåre Alsaker | 490d02a | 2012-09-30 02:57:21 +0200 | [diff] [blame] | 215 | float x; |
| 216 | float y; |
Pekka Paalanen | 460099f | 2012-01-20 16:48:25 +0200 | [diff] [blame] | 217 | } center; |
| 218 | }; |
| 219 | |
Giulio Camuffo | 5085a75 | 2013-03-25 21:42:45 +0100 | [diff] [blame] | 220 | struct shell_seat { |
| 221 | struct weston_seat *seat; |
| 222 | struct wl_listener seat_destroy_listener; |
Jasper St. Pierre | faf27a9 | 2013-12-09 17:36:28 -0500 | [diff] [blame] | 223 | struct weston_surface *focused_surface; |
Giulio Camuffo | 5085a75 | 2013-03-25 21:42:45 +0100 | [diff] [blame] | 224 | |
Jason Ekstrand | 024177c | 2014-04-21 19:42:58 -0500 | [diff] [blame] | 225 | struct wl_listener caps_changed_listener; |
| 226 | struct wl_listener pointer_focus_listener; |
| 227 | struct wl_listener keyboard_focus_listener; |
| 228 | |
Giulio Camuffo | 5085a75 | 2013-03-25 21:42:45 +0100 | [diff] [blame] | 229 | struct { |
Kristian Høgsberg | 02bbabb | 2013-05-06 22:15:05 -0400 | [diff] [blame] | 230 | struct weston_pointer_grab grab; |
Jonny Lamb | 76cf1fe | 2014-08-20 11:27:10 +0200 | [diff] [blame] | 231 | struct weston_touch_grab touch_grab; |
Giulio Camuffo | 5085a75 | 2013-03-25 21:42:45 +0100 | [diff] [blame] | 232 | struct wl_list surfaces_list; |
| 233 | struct wl_client *client; |
| 234 | int32_t initial_up; |
Jonny Lamb | 76cf1fe | 2014-08-20 11:27:10 +0200 | [diff] [blame] | 235 | enum { POINTER, TOUCH } type; |
Giulio Camuffo | 5085a75 | 2013-03-25 21:42:45 +0100 | [diff] [blame] | 236 | } popup_grab; |
| 237 | }; |
| 238 | |
Kristian Høgsberg | 2bff94e | 2014-02-11 12:22:51 -0800 | [diff] [blame] | 239 | struct shell_client { |
| 240 | struct wl_resource *resource; |
| 241 | struct wl_client *client; |
| 242 | struct desktop_shell *shell; |
| 243 | struct wl_listener destroy_listener; |
| 244 | struct wl_event_source *ping_timer; |
| 245 | uint32_t ping_serial; |
| 246 | int unresponsive; |
Jonas Ådahl | 49d77d2 | 2015-03-18 16:20:51 +0800 | [diff] [blame] | 247 | struct wl_list surface_list; |
Kristian Høgsberg | 2bff94e | 2014-02-11 12:22:51 -0800 | [diff] [blame] | 248 | }; |
| 249 | |
Alex Wu | bd3354b | 2012-04-17 17:20:49 +0800 | [diff] [blame] | 250 | static struct desktop_shell * |
| 251 | shell_surface_get_shell(struct shell_surface *shsurf); |
| 252 | |
Kristian Høgsberg | 0c36903 | 2013-02-14 21:31:44 -0500 | [diff] [blame] | 253 | static void |
Derek Foreman | 74de469 | 2015-07-15 13:00:39 -0500 | [diff] [blame] | 254 | surface_rotate(struct shell_surface *surface, struct weston_pointer *pointer); |
Kristian Høgsberg | 0c36903 | 2013-02-14 21:31:44 -0500 | [diff] [blame] | 255 | |
Pekka Paalanen | 79346ab | 2013-05-22 18:03:09 +0300 | [diff] [blame] | 256 | static void |
| 257 | shell_fade_startup(struct desktop_shell *shell); |
| 258 | |
Philip Withnall | becb77e | 2013-11-25 18:01:30 +0000 | [diff] [blame] | 259 | static struct shell_seat * |
| 260 | get_shell_seat(struct weston_seat *seat); |
| 261 | |
Jonny Lamb | d73c694 | 2014-08-20 15:53:20 +0200 | [diff] [blame] | 262 | static void |
| 263 | get_output_panel_size(struct desktop_shell *shell, |
| 264 | struct weston_output *output, |
| 265 | int *width, int *height); |
Kristian Høgsberg | ae356ae | 2014-04-29 16:03:54 -0700 | [diff] [blame] | 266 | |
Philip Withnall | 648a4dd | 2013-11-25 18:01:44 +0000 | [diff] [blame] | 267 | static void |
| 268 | shell_surface_update_child_surface_layers(struct shell_surface *shsurf); |
| 269 | |
Alex Wu | bd3354b | 2012-04-17 17:20:49 +0800 | [diff] [blame] | 270 | static bool |
Rafael Antognolli | e2a3455 | 2013-12-03 15:35:45 -0200 | [diff] [blame] | 271 | shell_surface_is_wl_shell_surface(struct shell_surface *shsurf); |
| 272 | |
| 273 | static bool |
| 274 | shell_surface_is_xdg_surface(struct shell_surface *shsurf); |
| 275 | |
| 276 | static bool |
| 277 | shell_surface_is_xdg_popup(struct shell_surface *shsurf); |
| 278 | |
| 279 | static void |
| 280 | shell_surface_set_parent(struct shell_surface *shsurf, |
| 281 | struct weston_surface *parent); |
| 282 | |
Pekka Paalanen | 8274d90 | 2014-08-06 19:36:51 +0300 | [diff] [blame] | 283 | static int |
| 284 | shell_surface_get_label(struct weston_surface *surface, char *buf, size_t len) |
| 285 | { |
| 286 | struct shell_surface *shsurf; |
| 287 | const char *typestr[] = { |
| 288 | [SHELL_SURFACE_NONE] = "unidentified", |
| 289 | [SHELL_SURFACE_TOPLEVEL] = "top-level", |
| 290 | [SHELL_SURFACE_POPUP] = "popup", |
| 291 | [SHELL_SURFACE_XWAYLAND] = "Xwayland", |
| 292 | }; |
| 293 | const char *t, *c; |
| 294 | |
| 295 | shsurf = get_shell_surface(surface); |
| 296 | if (!shsurf) |
| 297 | return snprintf(buf, len, "unidentified window"); |
| 298 | |
| 299 | t = shsurf->title; |
| 300 | c = shsurf->class; |
| 301 | |
| 302 | return snprintf(buf, len, "%s window%s%s%s%s%s", |
| 303 | typestr[shsurf->type], |
| 304 | t ? " '" : "", t ?: "", t ? "'" : "", |
| 305 | c ? " of " : "", c ?: ""); |
| 306 | } |
| 307 | |
Rafael Antognolli | e2a3455 | 2013-12-03 15:35:45 -0200 | [diff] [blame] | 308 | static bool |
Alex Wu | bd3354b | 2012-04-17 17:20:49 +0800 | [diff] [blame] | 309 | shell_surface_is_top_fullscreen(struct shell_surface *shsurf) |
| 310 | { |
| 311 | struct desktop_shell *shell; |
Mario Kleiner | 9f4d655 | 2015-06-21 21:25:08 +0200 | [diff] [blame] | 312 | struct weston_view *view; |
| 313 | struct shell_surface *top_fs_shsurf = NULL; |
Alex Wu | bd3354b | 2012-04-17 17:20:49 +0800 | [diff] [blame] | 314 | |
| 315 | shell = shell_surface_get_shell(shsurf); |
Quentin Glidic | c0d79ce | 2013-01-29 14:16:13 +0100 | [diff] [blame] | 316 | |
Giulio Camuffo | 412e6a5 | 2014-07-09 22:12:56 +0300 | [diff] [blame] | 317 | if (wl_list_empty(&shell->fullscreen_layer.view_list.link)) |
Alex Wu | bd3354b | 2012-04-17 17:20:49 +0800 | [diff] [blame] | 318 | return false; |
| 319 | |
Mario Kleiner | 9f4d655 | 2015-06-21 21:25:08 +0200 | [diff] [blame] | 320 | /* Find topmost shsurf on the same fullscreen output on which shsurf |
| 321 | * is displaying. We don't care about other outputs. |
| 322 | */ |
| 323 | wl_list_for_each(view, &shell->fullscreen_layer.view_list.link, |
| 324 | layer_link.link) { |
| 325 | struct shell_surface *cand_shsurf = get_shell_surface(view->surface); |
| 326 | |
| 327 | if (cand_shsurf && |
| 328 | (cand_shsurf->fullscreen_output == shsurf->fullscreen_output)) { |
| 329 | top_fs_shsurf = cand_shsurf; |
| 330 | break; |
| 331 | } |
| 332 | } |
| 333 | |
| 334 | return (shsurf == top_fs_shsurf); |
Alex Wu | bd3354b | 2012-04-17 17:20:49 +0800 | [diff] [blame] | 335 | } |
| 336 | |
Kristian Høgsberg | 6af8eb9 | 2012-01-25 16:57:11 -0500 | [diff] [blame] | 337 | static void |
Kristian Høgsberg | 27e3052 | 2012-04-11 23:18:23 -0400 | [diff] [blame] | 338 | destroy_shell_grab_shsurf(struct wl_listener *listener, void *data) |
Ander Conselvan de Oliveira | fe0444a | 2012-04-04 17:48:05 +0300 | [diff] [blame] | 339 | { |
| 340 | struct shell_grab *grab; |
| 341 | |
| 342 | grab = container_of(listener, struct shell_grab, |
| 343 | shsurf_destroy_listener); |
| 344 | |
| 345 | grab->shsurf = NULL; |
| 346 | } |
| 347 | |
Kristian Høgsberg | 1ef2313 | 2013-12-04 00:20:01 -0800 | [diff] [blame] | 348 | struct weston_view * |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 349 | get_default_view(struct weston_surface *surface) |
| 350 | { |
| 351 | struct shell_surface *shsurf; |
| 352 | struct weston_view *view; |
| 353 | |
| 354 | if (!surface || wl_list_empty(&surface->views)) |
| 355 | return NULL; |
| 356 | |
| 357 | shsurf = get_shell_surface(surface); |
| 358 | if (shsurf) |
| 359 | return shsurf->view; |
| 360 | |
| 361 | wl_list_for_each(view, &surface->views, surface_link) |
| 362 | if (weston_view_is_mapped(view)) |
| 363 | return view; |
| 364 | |
| 365 | return container_of(surface->views.next, struct weston_view, surface_link); |
| 366 | } |
| 367 | |
Ander Conselvan de Oliveira | fe0444a | 2012-04-04 17:48:05 +0300 | [diff] [blame] | 368 | static void |
Kristian Høgsberg | 02bbabb | 2013-05-06 22:15:05 -0400 | [diff] [blame] | 369 | popup_grab_end(struct weston_pointer *pointer); |
Jonny Lamb | 76cf1fe | 2014-08-20 11:27:10 +0200 | [diff] [blame] | 370 | static void |
| 371 | touch_popup_grab_end(struct weston_touch *touch); |
Kristian Høgsberg | 57e0907 | 2012-10-30 14:07:27 -0400 | [diff] [blame] | 372 | |
| 373 | static void |
Ander Conselvan de Oliveira | b9d2a0f | 2012-06-28 18:08:05 +0300 | [diff] [blame] | 374 | shell_grab_start(struct shell_grab *grab, |
Kristian Høgsberg | 02bbabb | 2013-05-06 22:15:05 -0400 | [diff] [blame] | 375 | const struct weston_pointer_grab_interface *interface, |
Ander Conselvan de Oliveira | b9d2a0f | 2012-06-28 18:08:05 +0300 | [diff] [blame] | 376 | struct shell_surface *shsurf, |
Kristian Høgsberg | 02bbabb | 2013-05-06 22:15:05 -0400 | [diff] [blame] | 377 | struct weston_pointer *pointer, |
Ander Conselvan de Oliveira | b9d2a0f | 2012-06-28 18:08:05 +0300 | [diff] [blame] | 378 | enum desktop_shell_cursor cursor) |
Ander Conselvan de Oliveira | fe0444a | 2012-04-04 17:48:05 +0300 | [diff] [blame] | 379 | { |
Ander Conselvan de Oliveira | b9d2a0f | 2012-06-28 18:08:05 +0300 | [diff] [blame] | 380 | struct desktop_shell *shell = shsurf->shell; |
Derek Foreman | 1281a36 | 2015-07-31 16:55:32 -0500 | [diff] [blame] | 381 | struct weston_touch *touch = weston_seat_get_touch(pointer->seat); |
Ander Conselvan de Oliveira | b9d2a0f | 2012-06-28 18:08:05 +0300 | [diff] [blame] | 382 | |
Kristian Høgsberg | 57e0907 | 2012-10-30 14:07:27 -0400 | [diff] [blame] | 383 | popup_grab_end(pointer); |
Derek Foreman | 1281a36 | 2015-07-31 16:55:32 -0500 | [diff] [blame] | 384 | if (touch) |
| 385 | touch_popup_grab_end(touch); |
Kristian Høgsberg | 57e0907 | 2012-10-30 14:07:27 -0400 | [diff] [blame] | 386 | |
Ander Conselvan de Oliveira | fe0444a | 2012-04-04 17:48:05 +0300 | [diff] [blame] | 387 | grab->grab.interface = interface; |
| 388 | grab->shsurf = shsurf; |
Kristian Høgsberg | 27e3052 | 2012-04-11 23:18:23 -0400 | [diff] [blame] | 389 | grab->shsurf_destroy_listener.notify = destroy_shell_grab_shsurf; |
Jason Ekstrand | 651f00e | 2013-06-14 10:07:54 -0500 | [diff] [blame] | 390 | wl_signal_add(&shsurf->destroy_signal, |
Kristian Høgsberg | 27e3052 | 2012-04-11 23:18:23 -0400 | [diff] [blame] | 391 | &grab->shsurf_destroy_listener); |
Ander Conselvan de Oliveira | fe0444a | 2012-04-04 17:48:05 +0300 | [diff] [blame] | 392 | |
Kristian Høgsberg | c85f1d4 | 2013-10-24 16:52:00 -0700 | [diff] [blame] | 393 | shsurf->grabbed = 1; |
Kristian Høgsberg | 02bbabb | 2013-05-06 22:15:05 -0400 | [diff] [blame] | 394 | weston_pointer_start_grab(pointer, &grab->grab); |
Kristian Høgsberg | c9974a0 | 2013-07-03 19:24:57 -0400 | [diff] [blame] | 395 | if (shell->child.desktop_shell) { |
| 396 | desktop_shell_send_grab_cursor(shell->child.desktop_shell, |
| 397 | cursor); |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 398 | weston_pointer_set_focus(pointer, |
| 399 | get_default_view(shell->grab_surface), |
Kristian Høgsberg | c9974a0 | 2013-07-03 19:24:57 -0400 | [diff] [blame] | 400 | wl_fixed_from_int(0), |
| 401 | wl_fixed_from_int(0)); |
| 402 | } |
Ander Conselvan de Oliveira | fe0444a | 2012-04-04 17:48:05 +0300 | [diff] [blame] | 403 | } |
| 404 | |
Jonny Lamb | d73c694 | 2014-08-20 15:53:20 +0200 | [diff] [blame] | 405 | static void |
| 406 | get_output_panel_size(struct desktop_shell *shell, |
| 407 | struct weston_output *output, |
| 408 | int *width, |
| 409 | int *height) |
Jasper St. Pierre | 6458ec3 | 2014-04-11 16:00:31 -0700 | [diff] [blame] | 410 | { |
| 411 | struct weston_view *view; |
Jonny Lamb | d73c694 | 2014-08-20 15:53:20 +0200 | [diff] [blame] | 412 | |
| 413 | *width = 0; |
| 414 | *height = 0; |
Jasper St. Pierre | 6458ec3 | 2014-04-11 16:00:31 -0700 | [diff] [blame] | 415 | |
| 416 | if (!output) |
Jonny Lamb | d73c694 | 2014-08-20 15:53:20 +0200 | [diff] [blame] | 417 | return; |
Jasper St. Pierre | 6458ec3 | 2014-04-11 16:00:31 -0700 | [diff] [blame] | 418 | |
Giulio Camuffo | 412e6a5 | 2014-07-09 22:12:56 +0300 | [diff] [blame] | 419 | wl_list_for_each(view, &shell->panel_layer.view_list.link, layer_link.link) { |
Jonny Lamb | d73c694 | 2014-08-20 15:53:20 +0200 | [diff] [blame] | 420 | float x, y; |
| 421 | |
| 422 | if (view->surface->output != output) |
| 423 | continue; |
| 424 | |
| 425 | switch (shell->panel_position) { |
| 426 | case DESKTOP_SHELL_PANEL_POSITION_TOP: |
| 427 | case DESKTOP_SHELL_PANEL_POSITION_BOTTOM: |
Jonny Lamb | d73c694 | 2014-08-20 15:53:20 +0200 | [diff] [blame] | 428 | weston_view_to_global_float(view, |
| 429 | view->surface->width, 0, |
| 430 | &x, &y); |
| 431 | |
Derek Foreman | 612341f | 2015-04-15 12:23:55 -0500 | [diff] [blame] | 432 | *width = (int)x - output->x; |
| 433 | *height = view->surface->height + (int) y - output->y; |
Jonny Lamb | d73c694 | 2014-08-20 15:53:20 +0200 | [diff] [blame] | 434 | return; |
| 435 | |
| 436 | case DESKTOP_SHELL_PANEL_POSITION_LEFT: |
| 437 | case DESKTOP_SHELL_PANEL_POSITION_RIGHT: |
| 438 | weston_view_to_global_float(view, |
| 439 | 0, view->surface->height, |
| 440 | &x, &y); |
| 441 | |
Derek Foreman | 612341f | 2015-04-15 12:23:55 -0500 | [diff] [blame] | 442 | *width = view->surface->width + (int)x - output->x; |
| 443 | *height = (int)y - output->y; |
Jonny Lamb | d73c694 | 2014-08-20 15:53:20 +0200 | [diff] [blame] | 444 | return; |
| 445 | |
| 446 | default: |
| 447 | /* we've already set width and height to |
| 448 | * fallback values. */ |
Jasper St. Pierre | 6458ec3 | 2014-04-11 16:00:31 -0700 | [diff] [blame] | 449 | break; |
| 450 | } |
| 451 | } |
| 452 | |
Jonny Lamb | d73c694 | 2014-08-20 15:53:20 +0200 | [diff] [blame] | 453 | /* the correct view wasn't found */ |
| 454 | } |
| 455 | |
| 456 | static void |
| 457 | get_output_work_area(struct desktop_shell *shell, |
| 458 | struct weston_output *output, |
| 459 | pixman_rectangle32_t *area) |
| 460 | { |
| 461 | int32_t panel_width = 0, panel_height = 0; |
| 462 | |
Derek Foreman | f814c5d | 2015-04-15 12:23:54 -0500 | [diff] [blame] | 463 | area->x = output->x; |
| 464 | area->y = output->y; |
Jonny Lamb | d73c694 | 2014-08-20 15:53:20 +0200 | [diff] [blame] | 465 | |
| 466 | get_output_panel_size(shell, output, &panel_width, &panel_height); |
Jonny Lamb | d73c694 | 2014-08-20 15:53:20 +0200 | [diff] [blame] | 467 | switch (shell->panel_position) { |
| 468 | case DESKTOP_SHELL_PANEL_POSITION_TOP: |
| 469 | default: |
Derek Foreman | f814c5d | 2015-04-15 12:23:54 -0500 | [diff] [blame] | 470 | area->y += panel_height; |
Jonny Lamb | d73c694 | 2014-08-20 15:53:20 +0200 | [diff] [blame] | 471 | case DESKTOP_SHELL_PANEL_POSITION_BOTTOM: |
| 472 | area->width = output->width; |
| 473 | area->height = output->height - panel_height; |
| 474 | break; |
| 475 | case DESKTOP_SHELL_PANEL_POSITION_LEFT: |
Derek Foreman | f814c5d | 2015-04-15 12:23:54 -0500 | [diff] [blame] | 476 | area->x += panel_width; |
Jonny Lamb | d73c694 | 2014-08-20 15:53:20 +0200 | [diff] [blame] | 477 | case DESKTOP_SHELL_PANEL_POSITION_RIGHT: |
| 478 | area->width = output->width - panel_width; |
| 479 | area->height = output->height; |
| 480 | break; |
| 481 | } |
Jasper St. Pierre | 6458ec3 | 2014-04-11 16:00:31 -0700 | [diff] [blame] | 482 | } |
| 483 | |
Derek Foreman | 45a7c27 | 2015-09-11 14:27:40 -0500 | [diff] [blame] | 484 | static struct shell_surface * |
| 485 | find_toplevel_surface(struct shell_surface *in_surface) |
| 486 | { |
| 487 | struct shell_surface *surface = in_surface; |
| 488 | |
Ben Hummon | 445e44c | 2015-10-06 11:48:14 -0500 | [diff] [blame] | 489 | while (surface) { |
| 490 | if (surface->type == SHELL_SURFACE_TOPLEVEL) |
| 491 | return surface; |
Derek Foreman | 45a7c27 | 2015-09-11 14:27:40 -0500 | [diff] [blame] | 492 | surface = get_shell_surface(surface->parent); |
Ben Hummon | 445e44c | 2015-10-06 11:48:14 -0500 | [diff] [blame] | 493 | } |
Derek Foreman | 45a7c27 | 2015-09-11 14:27:40 -0500 | [diff] [blame] | 494 | |
| 495 | /* If no top level surface was found, just use whatever surface was |
| 496 | originally provided. */ |
Ben Hummon | 445e44c | 2015-10-06 11:48:14 -0500 | [diff] [blame] | 497 | return in_surface; |
Derek Foreman | 45a7c27 | 2015-09-11 14:27:40 -0500 | [diff] [blame] | 498 | } |
| 499 | |
Jasper St. Pierre | 6458ec3 | 2014-04-11 16:00:31 -0700 | [diff] [blame] | 500 | static void |
| 501 | send_configure_for_surface(struct shell_surface *shsurf) |
| 502 | { |
| 503 | int32_t width, height; |
| 504 | struct surface_state *state; |
| 505 | |
| 506 | if (shsurf->state_requested) |
| 507 | state = &shsurf->requested_state; |
| 508 | else if (shsurf->state_changed) |
| 509 | state = &shsurf->next_state; |
| 510 | else |
| 511 | state = &shsurf->state; |
| 512 | |
| 513 | if (state->fullscreen) { |
| 514 | width = shsurf->output->width; |
| 515 | height = shsurf->output->height; |
| 516 | } else if (state->maximized) { |
| 517 | struct desktop_shell *shell; |
Jonny Lamb | d73c694 | 2014-08-20 15:53:20 +0200 | [diff] [blame] | 518 | pixman_rectangle32_t area; |
Jasper St. Pierre | 6458ec3 | 2014-04-11 16:00:31 -0700 | [diff] [blame] | 519 | |
| 520 | shell = shell_surface_get_shell(shsurf); |
Jonny Lamb | d73c694 | 2014-08-20 15:53:20 +0200 | [diff] [blame] | 521 | get_output_work_area(shell, shsurf->output, &area); |
Jasper St. Pierre | 6458ec3 | 2014-04-11 16:00:31 -0700 | [diff] [blame] | 522 | |
Jonny Lamb | d73c694 | 2014-08-20 15:53:20 +0200 | [diff] [blame] | 523 | width = area.width; |
| 524 | height = area.height; |
Ryo Munakata | 79954ec | 2015-05-02 21:44:04 +0900 | [diff] [blame] | 525 | } else if (shsurf->resize_edges) { |
| 526 | width = shsurf->geometry.width; |
| 527 | height = shsurf->geometry.height; |
Jasper St. Pierre | 6458ec3 | 2014-04-11 16:00:31 -0700 | [diff] [blame] | 528 | } else { |
| 529 | width = 0; |
| 530 | height = 0; |
| 531 | } |
| 532 | |
| 533 | shsurf->client->send_configure(shsurf->surface, width, height); |
| 534 | } |
| 535 | |
Ander Conselvan de Oliveira | fe0444a | 2012-04-04 17:48:05 +0300 | [diff] [blame] | 536 | static void |
Jasper St. Pierre | 5befdda | 2014-05-06 08:50:47 -0400 | [diff] [blame] | 537 | shell_surface_state_changed(struct shell_surface *shsurf) |
| 538 | { |
Jasper St. Pierre | 6458ec3 | 2014-04-11 16:00:31 -0700 | [diff] [blame] | 539 | if (shell_surface_is_xdg_surface(shsurf)) |
| 540 | send_configure_for_surface(shsurf); |
Jasper St. Pierre | 5befdda | 2014-05-06 08:50:47 -0400 | [diff] [blame] | 541 | } |
| 542 | |
| 543 | static void |
Ander Conselvan de Oliveira | b9d2a0f | 2012-06-28 18:08:05 +0300 | [diff] [blame] | 544 | shell_grab_end(struct shell_grab *grab) |
Ander Conselvan de Oliveira | fe0444a | 2012-04-04 17:48:05 +0300 | [diff] [blame] | 545 | { |
Kristian Høgsberg | c85f1d4 | 2013-10-24 16:52:00 -0700 | [diff] [blame] | 546 | if (grab->shsurf) { |
Kristian Høgsberg | 47b5dca | 2012-06-07 18:08:04 -0400 | [diff] [blame] | 547 | wl_list_remove(&grab->shsurf_destroy_listener.link); |
Kristian Høgsberg | c85f1d4 | 2013-10-24 16:52:00 -0700 | [diff] [blame] | 548 | grab->shsurf->grabbed = 0; |
Jasper St. Pierre | 5befdda | 2014-05-06 08:50:47 -0400 | [diff] [blame] | 549 | |
| 550 | if (grab->shsurf->resize_edges) { |
| 551 | grab->shsurf->resize_edges = 0; |
| 552 | shell_surface_state_changed(grab->shsurf); |
| 553 | } |
Kristian Høgsberg | c85f1d4 | 2013-10-24 16:52:00 -0700 | [diff] [blame] | 554 | } |
Ander Conselvan de Oliveira | b9d2a0f | 2012-06-28 18:08:05 +0300 | [diff] [blame] | 555 | |
Kristian Høgsberg | 9e5d7d1 | 2013-07-22 16:31:53 -0700 | [diff] [blame] | 556 | weston_pointer_end_grab(grab->grab.pointer); |
Ander Conselvan de Oliveira | fe0444a | 2012-04-04 17:48:05 +0300 | [diff] [blame] | 557 | } |
| 558 | |
| 559 | static void |
Rusty Lynch | 1084da5 | 2013-08-15 09:10:08 -0700 | [diff] [blame] | 560 | shell_touch_grab_start(struct shell_touch_grab *grab, |
| 561 | const struct weston_touch_grab_interface *interface, |
| 562 | struct shell_surface *shsurf, |
| 563 | struct weston_touch *touch) |
| 564 | { |
| 565 | struct desktop_shell *shell = shsurf->shell; |
Derek Foreman | 1281a36 | 2015-07-31 16:55:32 -0500 | [diff] [blame] | 566 | struct weston_pointer *pointer = weston_seat_get_pointer(touch->seat); |
U. Artie Eoff | cf5737a | 2014-01-17 10:08:25 -0800 | [diff] [blame] | 567 | |
Jonny Lamb | 76cf1fe | 2014-08-20 11:27:10 +0200 | [diff] [blame] | 568 | touch_popup_grab_end(touch); |
Derek Foreman | 1281a36 | 2015-07-31 16:55:32 -0500 | [diff] [blame] | 569 | if (pointer) |
| 570 | popup_grab_end(pointer); |
Kristian Høgsberg | 74071e0 | 2014-04-29 15:01:16 -0700 | [diff] [blame] | 571 | |
Rusty Lynch | 1084da5 | 2013-08-15 09:10:08 -0700 | [diff] [blame] | 572 | grab->grab.interface = interface; |
| 573 | grab->shsurf = shsurf; |
| 574 | grab->shsurf_destroy_listener.notify = destroy_shell_grab_shsurf; |
| 575 | wl_signal_add(&shsurf->destroy_signal, |
| 576 | &grab->shsurf_destroy_listener); |
| 577 | |
| 578 | grab->touch = touch; |
Kristian Høgsberg | c85f1d4 | 2013-10-24 16:52:00 -0700 | [diff] [blame] | 579 | shsurf->grabbed = 1; |
Rusty Lynch | 1084da5 | 2013-08-15 09:10:08 -0700 | [diff] [blame] | 580 | |
| 581 | weston_touch_start_grab(touch, &grab->grab); |
| 582 | if (shell->child.desktop_shell) |
Derek Foreman | 4c93c08 | 2015-04-30 16:45:41 -0500 | [diff] [blame] | 583 | weston_touch_set_focus(touch, |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 584 | get_default_view(shell->grab_surface)); |
Rusty Lynch | 1084da5 | 2013-08-15 09:10:08 -0700 | [diff] [blame] | 585 | } |
| 586 | |
| 587 | static void |
| 588 | shell_touch_grab_end(struct shell_touch_grab *grab) |
| 589 | { |
Kristian Høgsberg | c85f1d4 | 2013-10-24 16:52:00 -0700 | [diff] [blame] | 590 | if (grab->shsurf) { |
Rusty Lynch | 1084da5 | 2013-08-15 09:10:08 -0700 | [diff] [blame] | 591 | wl_list_remove(&grab->shsurf_destroy_listener.link); |
Kristian Høgsberg | c85f1d4 | 2013-10-24 16:52:00 -0700 | [diff] [blame] | 592 | grab->shsurf->grabbed = 0; |
| 593 | } |
Rusty Lynch | 1084da5 | 2013-08-15 09:10:08 -0700 | [diff] [blame] | 594 | |
| 595 | weston_touch_end_grab(grab->touch); |
| 596 | } |
| 597 | |
| 598 | static void |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 599 | center_on_output(struct weston_view *view, |
Alex Wu | 4539b08 | 2012-03-01 12:57:46 +0800 | [diff] [blame] | 600 | struct weston_output *output); |
| 601 | |
Daniel Stone | 496ca17 | 2012-05-30 16:31:42 +0100 | [diff] [blame] | 602 | static enum weston_keyboard_modifier |
Tiago Vignatti | 0b52d48 | 2012-04-20 18:54:25 +0300 | [diff] [blame] | 603 | get_modifier(char *modifier) |
| 604 | { |
| 605 | if (!modifier) |
| 606 | return MODIFIER_SUPER; |
| 607 | |
| 608 | if (!strcmp("ctrl", modifier)) |
| 609 | return MODIFIER_CTRL; |
| 610 | else if (!strcmp("alt", modifier)) |
| 611 | return MODIFIER_ALT; |
| 612 | else if (!strcmp("super", modifier)) |
| 613 | return MODIFIER_SUPER; |
| 614 | else |
| 615 | return MODIFIER_SUPER; |
| 616 | } |
| 617 | |
Juan Zhao | e10d279 | 2012-04-25 19:09:52 +0800 | [diff] [blame] | 618 | static enum animation_type |
| 619 | get_animation_type(char *animation) |
| 620 | { |
U. Artie Eoff | b571910 | 2014-01-15 14:26:31 -0800 | [diff] [blame] | 621 | if (!animation) |
| 622 | return ANIMATION_NONE; |
| 623 | |
Juan Zhao | e10d279 | 2012-04-25 19:09:52 +0800 | [diff] [blame] | 624 | if (!strcmp("zoom", animation)) |
| 625 | return ANIMATION_ZOOM; |
| 626 | else if (!strcmp("fade", animation)) |
| 627 | return ANIMATION_FADE; |
Louis-Francis Ratté-Boulianne | b482dbd | 2013-11-19 11:37:11 +0100 | [diff] [blame] | 628 | else if (!strcmp("dim-layer", animation)) |
| 629 | return ANIMATION_DIM_LAYER; |
Juan Zhao | e10d279 | 2012-04-25 19:09:52 +0800 | [diff] [blame] | 630 | else |
| 631 | return ANIMATION_NONE; |
| 632 | } |
| 633 | |
Alex Wu | 4539b08 | 2012-03-01 12:57:46 +0800 | [diff] [blame] | 634 | static void |
Kristian Høgsberg | 14e438c | 2013-05-26 21:48:14 -0400 | [diff] [blame] | 635 | shell_configuration(struct desktop_shell *shell) |
Pekka Paalanen | e955f1e | 2011-12-07 11:49:52 +0200 | [diff] [blame] | 636 | { |
Kristian Høgsberg | 673a889 | 2013-05-23 21:40:56 -0400 | [diff] [blame] | 637 | struct weston_config_section *section; |
Derek Foreman | c721043 | 2014-08-21 11:32:38 -0500 | [diff] [blame] | 638 | char *s, *client; |
Pekka Paalanen | 974c094 | 2014-09-05 14:45:09 +0300 | [diff] [blame] | 639 | int ret; |
Pekka Paalanen | e955f1e | 2011-12-07 11:49:52 +0200 | [diff] [blame] | 640 | |
Kristian Høgsberg | 673a889 | 2013-05-23 21:40:56 -0400 | [diff] [blame] | 641 | section = weston_config_get_section(shell->compositor->config, |
Kristian Høgsberg | 673a889 | 2013-05-23 21:40:56 -0400 | [diff] [blame] | 642 | "shell", NULL, NULL); |
Pekka Paalanen | 974c094 | 2014-09-05 14:45:09 +0300 | [diff] [blame] | 643 | ret = asprintf(&client, "%s/%s", weston_config_get_libexec_dir(), |
| 644 | WESTON_SHELL_CLIENT); |
| 645 | if (ret < 0) |
| 646 | client = NULL; |
Kristian Høgsberg | 673a889 | 2013-05-23 21:40:56 -0400 | [diff] [blame] | 647 | weston_config_section_get_string(section, |
Derek Foreman | c721043 | 2014-08-21 11:32:38 -0500 | [diff] [blame] | 648 | "client", &s, client); |
| 649 | free(client); |
Emilio Pozuelo Monfort | 46ce798 | 2013-11-20 13:22:29 +0100 | [diff] [blame] | 650 | shell->client = s; |
| 651 | weston_config_section_get_string(section, |
Kristian Høgsberg | 673a889 | 2013-05-23 21:40:56 -0400 | [diff] [blame] | 652 | "binding-modifier", &s, "super"); |
| 653 | shell->binding_modifier = get_modifier(s); |
Quentin Glidic | 8418c29 | 2013-06-18 09:11:03 +0200 | [diff] [blame] | 654 | free(s); |
Kristian Høgsberg | d56ab4e | 2014-01-16 16:51:52 -0800 | [diff] [blame] | 655 | |
| 656 | weston_config_section_get_string(section, |
| 657 | "exposay-modifier", &s, "none"); |
| 658 | if (strcmp(s, "none") == 0) |
| 659 | shell->exposay_modifier = 0; |
| 660 | else |
| 661 | shell->exposay_modifier = get_modifier(s); |
| 662 | free(s); |
| 663 | |
Kristian Høgsberg | 673a889 | 2013-05-23 21:40:56 -0400 | [diff] [blame] | 664 | weston_config_section_get_string(section, "animation", &s, "none"); |
| 665 | shell->win_animation_type = get_animation_type(s); |
Quentin Glidic | 8418c29 | 2013-06-18 09:11:03 +0200 | [diff] [blame] | 666 | free(s); |
Jonny Lamb | f322f8e | 2014-08-12 15:13:30 +0200 | [diff] [blame] | 667 | weston_config_section_get_string(section, "close-animation", &s, "fade"); |
| 668 | shell->win_close_animation_type = get_animation_type(s); |
| 669 | free(s); |
Kristian Høgsberg | 724c8d9 | 2013-10-16 11:38:24 -0700 | [diff] [blame] | 670 | weston_config_section_get_string(section, |
| 671 | "startup-animation", &s, "fade"); |
| 672 | shell->startup_animation_type = get_animation_type(s); |
| 673 | free(s); |
Kristian Høgsberg | 912e0a1 | 2013-10-30 08:59:55 -0700 | [diff] [blame] | 674 | if (shell->startup_animation_type == ANIMATION_ZOOM) |
| 675 | shell->startup_animation_type = ANIMATION_NONE; |
Louis-Francis Ratté-Boulianne | b482dbd | 2013-11-19 11:37:11 +0100 | [diff] [blame] | 676 | weston_config_section_get_string(section, "focus-animation", &s, "none"); |
| 677 | shell->focus_animation_type = get_animation_type(s); |
| 678 | free(s); |
Kristian Høgsberg | 673a889 | 2013-05-23 21:40:56 -0400 | [diff] [blame] | 679 | weston_config_section_get_uint(section, "num-workspaces", |
| 680 | &shell->workspaces.num, |
| 681 | DEFAULT_NUM_WORKSPACES); |
Jonas Ådahl | e3cddce | 2012-06-13 00:01:22 +0200 | [diff] [blame] | 682 | } |
| 683 | |
Kristian Høgsberg | 1ef2313 | 2013-12-04 00:20:01 -0800 | [diff] [blame] | 684 | struct weston_output * |
Louis-Francis Ratté-Boulianne | b482dbd | 2013-11-19 11:37:11 +0100 | [diff] [blame] | 685 | get_default_output(struct weston_compositor *compositor) |
| 686 | { |
| 687 | return container_of(compositor->output_list.next, |
| 688 | struct weston_output, link); |
| 689 | } |
| 690 | |
Pekka Paalanen | 8274d90 | 2014-08-06 19:36:51 +0300 | [diff] [blame] | 691 | static int |
| 692 | focus_surface_get_label(struct weston_surface *surface, char *buf, size_t len) |
| 693 | { |
| 694 | return snprintf(buf, len, "focus highlight effect for output %s", |
| 695 | surface->output->name); |
| 696 | } |
Louis-Francis Ratté-Boulianne | b482dbd | 2013-11-19 11:37:11 +0100 | [diff] [blame] | 697 | |
| 698 | /* no-op func for checking focus surface */ |
| 699 | static void |
Jason Ekstrand | 918f2dd | 2013-12-02 21:01:53 -0600 | [diff] [blame] | 700 | focus_surface_configure(struct weston_surface *es, int32_t sx, int32_t sy) |
Louis-Francis Ratté-Boulianne | b482dbd | 2013-11-19 11:37:11 +0100 | [diff] [blame] | 701 | { |
| 702 | } |
| 703 | |
| 704 | static struct focus_surface * |
| 705 | get_focus_surface(struct weston_surface *surface) |
| 706 | { |
| 707 | if (surface->configure == focus_surface_configure) |
| 708 | return surface->configure_private; |
| 709 | else |
| 710 | return NULL; |
| 711 | } |
| 712 | |
| 713 | static bool |
| 714 | is_focus_surface (struct weston_surface *es) |
| 715 | { |
| 716 | return (es->configure == focus_surface_configure); |
| 717 | } |
| 718 | |
| 719 | static bool |
| 720 | is_focus_view (struct weston_view *view) |
| 721 | { |
| 722 | return is_focus_surface (view->surface); |
| 723 | } |
| 724 | |
| 725 | static struct focus_surface * |
| 726 | create_focus_surface(struct weston_compositor *ec, |
| 727 | struct weston_output *output) |
| 728 | { |
| 729 | struct focus_surface *fsurf = NULL; |
| 730 | struct weston_surface *surface = NULL; |
| 731 | |
| 732 | fsurf = malloc(sizeof *fsurf); |
| 733 | if (!fsurf) |
| 734 | return NULL; |
| 735 | |
| 736 | fsurf->surface = weston_surface_create(ec); |
| 737 | surface = fsurf->surface; |
| 738 | if (surface == NULL) { |
| 739 | free(fsurf); |
| 740 | return NULL; |
| 741 | } |
| 742 | |
| 743 | surface->configure = focus_surface_configure; |
| 744 | surface->output = output; |
| 745 | surface->configure_private = fsurf; |
Pekka Paalanen | 8274d90 | 2014-08-06 19:36:51 +0300 | [diff] [blame] | 746 | weston_surface_set_label_func(surface, focus_surface_get_label); |
Louis-Francis Ratté-Boulianne | b482dbd | 2013-11-19 11:37:11 +0100 | [diff] [blame] | 747 | |
U. Artie Eoff | 0b23b2b | 2014-01-15 14:45:59 -0800 | [diff] [blame] | 748 | fsurf->view = weston_view_create(surface); |
| 749 | if (fsurf->view == NULL) { |
| 750 | weston_surface_destroy(surface); |
| 751 | free(fsurf); |
| 752 | return NULL; |
| 753 | } |
Emilio Pozuelo Monfort | da64426 | 2013-11-19 11:37:19 +0100 | [diff] [blame] | 754 | fsurf->view->output = output; |
Louis-Francis Ratté-Boulianne | b482dbd | 2013-11-19 11:37:11 +0100 | [diff] [blame] | 755 | |
Jason Ekstrand | 5c11a33 | 2013-12-04 20:32:03 -0600 | [diff] [blame] | 756 | weston_surface_set_size(surface, output->width, output->height); |
Jason Ekstrand | 918f2dd | 2013-12-02 21:01:53 -0600 | [diff] [blame] | 757 | weston_view_set_position(fsurf->view, output->x, output->y); |
Louis-Francis Ratté-Boulianne | b482dbd | 2013-11-19 11:37:11 +0100 | [diff] [blame] | 758 | weston_surface_set_color(surface, 0.0, 0.0, 0.0, 1.0); |
| 759 | pixman_region32_fini(&surface->opaque); |
| 760 | pixman_region32_init_rect(&surface->opaque, output->x, output->y, |
| 761 | output->width, output->height); |
| 762 | pixman_region32_fini(&surface->input); |
| 763 | pixman_region32_init(&surface->input); |
| 764 | |
| 765 | wl_list_init(&fsurf->workspace_transform.link); |
| 766 | |
| 767 | return fsurf; |
| 768 | } |
| 769 | |
| 770 | static void |
| 771 | focus_surface_destroy(struct focus_surface *fsurf) |
| 772 | { |
| 773 | weston_surface_destroy(fsurf->surface); |
| 774 | free(fsurf); |
| 775 | } |
| 776 | |
| 777 | static void |
| 778 | focus_animation_done(struct weston_view_animation *animation, void *data) |
| 779 | { |
| 780 | struct workspace *ws = data; |
| 781 | |
| 782 | ws->focus_animation = NULL; |
| 783 | } |
| 784 | |
Jonas Ådahl | e3cddce | 2012-06-13 00:01:22 +0200 | [diff] [blame] | 785 | static void |
Jonas Ådahl | 0476974 | 2012-06-13 00:01:24 +0200 | [diff] [blame] | 786 | focus_state_destroy(struct focus_state *state) |
| 787 | { |
| 788 | wl_list_remove(&state->seat_destroy_listener.link); |
| 789 | wl_list_remove(&state->surface_destroy_listener.link); |
| 790 | free(state); |
| 791 | } |
| 792 | |
| 793 | static void |
| 794 | focus_state_seat_destroy(struct wl_listener *listener, void *data) |
| 795 | { |
| 796 | struct focus_state *state = container_of(listener, |
| 797 | struct focus_state, |
| 798 | seat_destroy_listener); |
| 799 | |
| 800 | wl_list_remove(&state->link); |
| 801 | focus_state_destroy(state); |
| 802 | } |
| 803 | |
| 804 | static void |
| 805 | focus_state_surface_destroy(struct wl_listener *listener, void *data) |
| 806 | { |
| 807 | struct focus_state *state = container_of(listener, |
| 808 | struct focus_state, |
Kristian Høgsberg | b8e0d0f | 2012-07-31 10:30:26 -0400 | [diff] [blame] | 809 | surface_destroy_listener); |
Kristian Høgsberg | e377822 | 2012-07-31 17:29:30 -0400 | [diff] [blame] | 810 | struct desktop_shell *shell; |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 811 | struct weston_surface *main_surface, *next; |
| 812 | struct weston_view *view; |
Jonas Ådahl | 0476974 | 2012-06-13 00:01:24 +0200 | [diff] [blame] | 813 | |
Pekka Paalanen | 01388e2 | 2013-04-25 13:57:44 +0300 | [diff] [blame] | 814 | main_surface = weston_surface_get_main_surface(state->keyboard_focus); |
| 815 | |
Kristian Høgsberg | e377822 | 2012-07-31 17:29:30 -0400 | [diff] [blame] | 816 | next = NULL; |
Giulio Camuffo | 412e6a5 | 2014-07-09 22:12:56 +0300 | [diff] [blame] | 817 | wl_list_for_each(view, |
| 818 | &state->ws->layer.view_list.link, layer_link.link) { |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 819 | if (view->surface == main_surface) |
Kristian Høgsberg | e377822 | 2012-07-31 17:29:30 -0400 | [diff] [blame] | 820 | continue; |
Louis-Francis Ratté-Boulianne | b482dbd | 2013-11-19 11:37:11 +0100 | [diff] [blame] | 821 | if (is_focus_view(view)) |
| 822 | continue; |
Kristian Høgsberg | e377822 | 2012-07-31 17:29:30 -0400 | [diff] [blame] | 823 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 824 | next = view->surface; |
Kristian Høgsberg | e377822 | 2012-07-31 17:29:30 -0400 | [diff] [blame] | 825 | break; |
| 826 | } |
| 827 | |
Pekka Paalanen | 01388e2 | 2013-04-25 13:57:44 +0300 | [diff] [blame] | 828 | /* if the focus was a sub-surface, activate its main surface */ |
| 829 | if (main_surface != state->keyboard_focus) |
| 830 | next = main_surface; |
| 831 | |
Louis-Francis Ratté-Boulianne | b482dbd | 2013-11-19 11:37:11 +0100 | [diff] [blame] | 832 | shell = state->seat->compositor->shell_interface.shell; |
Kristian Høgsberg | e377822 | 2012-07-31 17:29:30 -0400 | [diff] [blame] | 833 | if (next) { |
Louis-Francis Ratté-Boulianne | b482dbd | 2013-11-19 11:37:11 +0100 | [diff] [blame] | 834 | state->keyboard_focus = NULL; |
Emilio Pozuelo Monfort | 9e7c759 | 2014-01-30 14:01:10 +0100 | [diff] [blame] | 835 | activate(shell, next, state->seat, true); |
Kristian Høgsberg | e377822 | 2012-07-31 17:29:30 -0400 | [diff] [blame] | 836 | } else { |
Louis-Francis Ratté-Boulianne | b482dbd | 2013-11-19 11:37:11 +0100 | [diff] [blame] | 837 | if (shell->focus_animation_type == ANIMATION_DIM_LAYER) { |
| 838 | if (state->ws->focus_animation) |
| 839 | weston_view_animation_destroy(state->ws->focus_animation); |
| 840 | |
| 841 | state->ws->focus_animation = weston_fade_run( |
| 842 | state->ws->fsurf_front->view, |
| 843 | state->ws->fsurf_front->view->alpha, 0.0, 300, |
| 844 | focus_animation_done, state->ws); |
| 845 | } |
| 846 | |
Kristian Høgsberg | e377822 | 2012-07-31 17:29:30 -0400 | [diff] [blame] | 847 | wl_list_remove(&state->link); |
| 848 | focus_state_destroy(state); |
| 849 | } |
Jonas Ådahl | 0476974 | 2012-06-13 00:01:24 +0200 | [diff] [blame] | 850 | } |
| 851 | |
| 852 | static struct focus_state * |
Kristian Høgsberg | 2f5faff | 2012-07-31 16:36:34 -0400 | [diff] [blame] | 853 | focus_state_create(struct weston_seat *seat, struct workspace *ws) |
Jonas Ådahl | 0476974 | 2012-06-13 00:01:24 +0200 | [diff] [blame] | 854 | { |
Jonas Ådahl | 0476974 | 2012-06-13 00:01:24 +0200 | [diff] [blame] | 855 | struct focus_state *state; |
Jonas Ådahl | 0476974 | 2012-06-13 00:01:24 +0200 | [diff] [blame] | 856 | |
| 857 | state = malloc(sizeof *state); |
| 858 | if (state == NULL) |
| 859 | return NULL; |
| 860 | |
Louis-Francis Ratté-Boulianne | b482dbd | 2013-11-19 11:37:11 +0100 | [diff] [blame] | 861 | state->keyboard_focus = NULL; |
Kristian Høgsberg | 2f5faff | 2012-07-31 16:36:34 -0400 | [diff] [blame] | 862 | state->ws = ws; |
Jonas Ådahl | 0476974 | 2012-06-13 00:01:24 +0200 | [diff] [blame] | 863 | state->seat = seat; |
Kristian Høgsberg | 2f5faff | 2012-07-31 16:36:34 -0400 | [diff] [blame] | 864 | wl_list_insert(&ws->focus_list, &state->link); |
Jonas Ådahl | 0476974 | 2012-06-13 00:01:24 +0200 | [diff] [blame] | 865 | |
| 866 | state->seat_destroy_listener.notify = focus_state_seat_destroy; |
| 867 | state->surface_destroy_listener.notify = focus_state_surface_destroy; |
Kristian Høgsberg | 4912454 | 2013-05-06 22:27:40 -0400 | [diff] [blame] | 868 | wl_signal_add(&seat->destroy_signal, |
Jonas Ådahl | 0476974 | 2012-06-13 00:01:24 +0200 | [diff] [blame] | 869 | &state->seat_destroy_listener); |
Kristian Høgsberg | 2f5faff | 2012-07-31 16:36:34 -0400 | [diff] [blame] | 870 | wl_list_init(&state->surface_destroy_listener.link); |
Jonas Ådahl | 0476974 | 2012-06-13 00:01:24 +0200 | [diff] [blame] | 871 | |
| 872 | return state; |
| 873 | } |
| 874 | |
Jonas Ådahl | 8538b22 | 2012-08-29 22:13:03 +0200 | [diff] [blame] | 875 | static struct focus_state * |
| 876 | ensure_focus_state(struct desktop_shell *shell, struct weston_seat *seat) |
| 877 | { |
| 878 | struct workspace *ws = get_current_workspace(shell); |
| 879 | struct focus_state *state; |
| 880 | |
| 881 | wl_list_for_each(state, &ws->focus_list, link) |
| 882 | if (state->seat == seat) |
| 883 | break; |
| 884 | |
| 885 | if (&state->link == &ws->focus_list) |
| 886 | state = focus_state_create(seat, ws); |
| 887 | |
| 888 | return state; |
| 889 | } |
| 890 | |
Jonas Ådahl | 0476974 | 2012-06-13 00:01:24 +0200 | [diff] [blame] | 891 | static void |
Kristian Høgsberg | d500bf1 | 2014-01-22 12:25:20 -0800 | [diff] [blame] | 892 | focus_state_set_focus(struct focus_state *state, |
| 893 | struct weston_surface *surface) |
| 894 | { |
| 895 | if (state->keyboard_focus) { |
| 896 | wl_list_remove(&state->surface_destroy_listener.link); |
| 897 | wl_list_init(&state->surface_destroy_listener.link); |
| 898 | } |
| 899 | |
| 900 | state->keyboard_focus = surface; |
| 901 | if (surface) |
| 902 | wl_signal_add(&surface->destroy_signal, |
| 903 | &state->surface_destroy_listener); |
| 904 | } |
| 905 | |
| 906 | static void |
Kristian Høgsberg | 2f5faff | 2012-07-31 16:36:34 -0400 | [diff] [blame] | 907 | restore_focus_state(struct desktop_shell *shell, struct workspace *ws) |
Jonas Ådahl | 0476974 | 2012-06-13 00:01:24 +0200 | [diff] [blame] | 908 | { |
| 909 | struct focus_state *state, *next; |
Kristian Høgsberg | fe7aa90 | 2013-05-08 09:54:37 -0400 | [diff] [blame] | 910 | struct weston_surface *surface; |
Neil Roberts | 4237f50 | 2014-04-09 16:33:31 +0100 | [diff] [blame] | 911 | struct wl_list pending_seat_list; |
| 912 | struct weston_seat *seat, *next_seat; |
| 913 | |
| 914 | /* Temporarily steal the list of seats so that we can keep |
| 915 | * track of the seats we've already processed */ |
| 916 | wl_list_init(&pending_seat_list); |
| 917 | wl_list_insert_list(&pending_seat_list, &shell->compositor->seat_list); |
| 918 | wl_list_init(&shell->compositor->seat_list); |
Jonas Ådahl | 0476974 | 2012-06-13 00:01:24 +0200 | [diff] [blame] | 919 | |
| 920 | wl_list_for_each_safe(state, next, &ws->focus_list, link) { |
Derek Foreman | 1281a36 | 2015-07-31 16:55:32 -0500 | [diff] [blame] | 921 | struct weston_keyboard *keyboard = |
| 922 | weston_seat_get_keyboard(state->seat); |
| 923 | |
Neil Roberts | 4237f50 | 2014-04-09 16:33:31 +0100 | [diff] [blame] | 924 | wl_list_remove(&state->seat->link); |
| 925 | wl_list_insert(&shell->compositor->seat_list, |
| 926 | &state->seat->link); |
| 927 | |
Derek Foreman | 1281a36 | 2015-07-31 16:55:32 -0500 | [diff] [blame] | 928 | if (!keyboard) |
Kristian Høgsberg | e61d2f4 | 2014-01-17 12:18:53 -0800 | [diff] [blame] | 929 | continue; |
| 930 | |
Kristian Høgsberg | fe7aa90 | 2013-05-08 09:54:37 -0400 | [diff] [blame] | 931 | surface = state->keyboard_focus; |
Jonas Ådahl | 5689944 | 2012-08-29 22:12:59 +0200 | [diff] [blame] | 932 | |
Derek Foreman | 1281a36 | 2015-07-31 16:55:32 -0500 | [diff] [blame] | 933 | weston_keyboard_set_focus(keyboard, surface); |
Jonas Ådahl | 0476974 | 2012-06-13 00:01:24 +0200 | [diff] [blame] | 934 | } |
Neil Roberts | 4237f50 | 2014-04-09 16:33:31 +0100 | [diff] [blame] | 935 | |
| 936 | /* For any remaining seats that we don't have a focus state |
| 937 | * for we'll reset the keyboard focus to NULL */ |
| 938 | wl_list_for_each_safe(seat, next_seat, &pending_seat_list, link) { |
Derek Foreman | 1281a36 | 2015-07-31 16:55:32 -0500 | [diff] [blame] | 939 | struct weston_keyboard *keyboard = |
| 940 | weston_seat_get_keyboard(seat); |
| 941 | |
Neil Roberts | 4237f50 | 2014-04-09 16:33:31 +0100 | [diff] [blame] | 942 | wl_list_insert(&shell->compositor->seat_list, &seat->link); |
| 943 | |
Derek Foreman | 1281a36 | 2015-07-31 16:55:32 -0500 | [diff] [blame] | 944 | if (!keyboard) |
Neil Roberts | 4237f50 | 2014-04-09 16:33:31 +0100 | [diff] [blame] | 945 | continue; |
| 946 | |
Derek Foreman | 1281a36 | 2015-07-31 16:55:32 -0500 | [diff] [blame] | 947 | weston_keyboard_set_focus(keyboard, NULL); |
Neil Roberts | 4237f50 | 2014-04-09 16:33:31 +0100 | [diff] [blame] | 948 | } |
Jonas Ådahl | 0476974 | 2012-06-13 00:01:24 +0200 | [diff] [blame] | 949 | } |
| 950 | |
| 951 | static void |
Jonas Ådahl | 8de6a1d | 2012-08-29 22:13:00 +0200 | [diff] [blame] | 952 | replace_focus_state(struct desktop_shell *shell, struct workspace *ws, |
| 953 | struct weston_seat *seat) |
| 954 | { |
Derek Foreman | 1281a36 | 2015-07-31 16:55:32 -0500 | [diff] [blame] | 955 | struct weston_keyboard *keyboard = weston_seat_get_keyboard(seat); |
Jonas Ådahl | 8de6a1d | 2012-08-29 22:13:00 +0200 | [diff] [blame] | 956 | struct focus_state *state; |
Jonas Ådahl | 8de6a1d | 2012-08-29 22:13:00 +0200 | [diff] [blame] | 957 | |
| 958 | wl_list_for_each(state, &ws->focus_list, link) { |
| 959 | if (state->seat == seat) { |
Derek Foreman | 1281a36 | 2015-07-31 16:55:32 -0500 | [diff] [blame] | 960 | focus_state_set_focus(state, keyboard->focus); |
Jonas Ådahl | 8de6a1d | 2012-08-29 22:13:00 +0200 | [diff] [blame] | 961 | return; |
| 962 | } |
| 963 | } |
| 964 | } |
| 965 | |
| 966 | static void |
| 967 | drop_focus_state(struct desktop_shell *shell, struct workspace *ws, |
| 968 | struct weston_surface *surface) |
| 969 | { |
| 970 | struct focus_state *state; |
| 971 | |
| 972 | wl_list_for_each(state, &ws->focus_list, link) |
| 973 | if (state->keyboard_focus == surface) |
Kristian Høgsberg | d500bf1 | 2014-01-22 12:25:20 -0800 | [diff] [blame] | 974 | focus_state_set_focus(state, NULL); |
Jonas Ådahl | 8de6a1d | 2012-08-29 22:13:00 +0200 | [diff] [blame] | 975 | } |
| 976 | |
| 977 | static void |
Louis-Francis Ratté-Boulianne | b482dbd | 2013-11-19 11:37:11 +0100 | [diff] [blame] | 978 | animate_focus_change(struct desktop_shell *shell, struct workspace *ws, |
| 979 | struct weston_view *from, struct weston_view *to) |
| 980 | { |
| 981 | struct weston_output *output; |
| 982 | bool focus_surface_created = false; |
| 983 | |
| 984 | /* FIXME: Only support dim animation using two layers */ |
| 985 | if (from == to || shell->focus_animation_type != ANIMATION_DIM_LAYER) |
| 986 | return; |
| 987 | |
| 988 | output = get_default_output(shell->compositor); |
| 989 | if (ws->fsurf_front == NULL && (from || to)) { |
| 990 | ws->fsurf_front = create_focus_surface(shell->compositor, output); |
U. Artie Eoff | 0b23b2b | 2014-01-15 14:45:59 -0800 | [diff] [blame] | 991 | if (ws->fsurf_front == NULL) |
| 992 | return; |
Louis-Francis Ratté-Boulianne | b482dbd | 2013-11-19 11:37:11 +0100 | [diff] [blame] | 993 | ws->fsurf_front->view->alpha = 0.0; |
U. Artie Eoff | 0b23b2b | 2014-01-15 14:45:59 -0800 | [diff] [blame] | 994 | |
| 995 | ws->fsurf_back = create_focus_surface(shell->compositor, output); |
| 996 | if (ws->fsurf_back == NULL) { |
| 997 | focus_surface_destroy(ws->fsurf_front); |
| 998 | return; |
| 999 | } |
Louis-Francis Ratté-Boulianne | b482dbd | 2013-11-19 11:37:11 +0100 | [diff] [blame] | 1000 | ws->fsurf_back->view->alpha = 0.0; |
U. Artie Eoff | 0b23b2b | 2014-01-15 14:45:59 -0800 | [diff] [blame] | 1001 | |
Louis-Francis Ratté-Boulianne | b482dbd | 2013-11-19 11:37:11 +0100 | [diff] [blame] | 1002 | focus_surface_created = true; |
| 1003 | } else { |
Giulio Camuffo | 412e6a5 | 2014-07-09 22:12:56 +0300 | [diff] [blame] | 1004 | weston_layer_entry_remove(&ws->fsurf_front->view->layer_link); |
| 1005 | weston_layer_entry_remove(&ws->fsurf_back->view->layer_link); |
Louis-Francis Ratté-Boulianne | b482dbd | 2013-11-19 11:37:11 +0100 | [diff] [blame] | 1006 | } |
| 1007 | |
| 1008 | if (ws->focus_animation) { |
| 1009 | weston_view_animation_destroy(ws->focus_animation); |
| 1010 | ws->focus_animation = NULL; |
| 1011 | } |
| 1012 | |
| 1013 | if (to) |
Giulio Camuffo | 412e6a5 | 2014-07-09 22:12:56 +0300 | [diff] [blame] | 1014 | weston_layer_entry_insert(&to->layer_link, |
| 1015 | &ws->fsurf_front->view->layer_link); |
Louis-Francis Ratté-Boulianne | b482dbd | 2013-11-19 11:37:11 +0100 | [diff] [blame] | 1016 | else if (from) |
Giulio Camuffo | 412e6a5 | 2014-07-09 22:12:56 +0300 | [diff] [blame] | 1017 | weston_layer_entry_insert(&ws->layer.view_list, |
| 1018 | &ws->fsurf_front->view->layer_link); |
Louis-Francis Ratté-Boulianne | b482dbd | 2013-11-19 11:37:11 +0100 | [diff] [blame] | 1019 | |
| 1020 | if (focus_surface_created) { |
| 1021 | ws->focus_animation = weston_fade_run( |
| 1022 | ws->fsurf_front->view, |
Jonny Lamb | 7e7d485 | 2014-05-22 22:41:34 +0200 | [diff] [blame] | 1023 | ws->fsurf_front->view->alpha, 0.4, 300, |
Louis-Francis Ratté-Boulianne | b482dbd | 2013-11-19 11:37:11 +0100 | [diff] [blame] | 1024 | focus_animation_done, ws); |
| 1025 | } else if (from) { |
Giulio Camuffo | 412e6a5 | 2014-07-09 22:12:56 +0300 | [diff] [blame] | 1026 | weston_layer_entry_insert(&from->layer_link, |
| 1027 | &ws->fsurf_back->view->layer_link); |
Louis-Francis Ratté-Boulianne | b482dbd | 2013-11-19 11:37:11 +0100 | [diff] [blame] | 1028 | ws->focus_animation = weston_stable_fade_run( |
| 1029 | ws->fsurf_front->view, 0.0, |
Jonny Lamb | 7e7d485 | 2014-05-22 22:41:34 +0200 | [diff] [blame] | 1030 | ws->fsurf_back->view, 0.4, |
Louis-Francis Ratté-Boulianne | b482dbd | 2013-11-19 11:37:11 +0100 | [diff] [blame] | 1031 | focus_animation_done, ws); |
| 1032 | } else if (to) { |
Giulio Camuffo | 412e6a5 | 2014-07-09 22:12:56 +0300 | [diff] [blame] | 1033 | weston_layer_entry_insert(&ws->layer.view_list, |
| 1034 | &ws->fsurf_back->view->layer_link); |
Louis-Francis Ratté-Boulianne | b482dbd | 2013-11-19 11:37:11 +0100 | [diff] [blame] | 1035 | ws->focus_animation = weston_stable_fade_run( |
| 1036 | ws->fsurf_front->view, 0.0, |
Jonny Lamb | 7e7d485 | 2014-05-22 22:41:34 +0200 | [diff] [blame] | 1037 | ws->fsurf_back->view, 0.4, |
Louis-Francis Ratté-Boulianne | b482dbd | 2013-11-19 11:37:11 +0100 | [diff] [blame] | 1038 | focus_animation_done, ws); |
| 1039 | } |
| 1040 | } |
| 1041 | |
| 1042 | static void |
Jonas Ådahl | e3cddce | 2012-06-13 00:01:22 +0200 | [diff] [blame] | 1043 | workspace_destroy(struct workspace *ws) |
| 1044 | { |
Jonas Ådahl | 0476974 | 2012-06-13 00:01:24 +0200 | [diff] [blame] | 1045 | struct focus_state *state, *next; |
| 1046 | |
| 1047 | wl_list_for_each_safe(state, next, &ws->focus_list, link) |
| 1048 | focus_state_destroy(state); |
| 1049 | |
Louis-Francis Ratté-Boulianne | b482dbd | 2013-11-19 11:37:11 +0100 | [diff] [blame] | 1050 | if (ws->fsurf_front) |
| 1051 | focus_surface_destroy(ws->fsurf_front); |
| 1052 | if (ws->fsurf_back) |
| 1053 | focus_surface_destroy(ws->fsurf_back); |
| 1054 | |
Jonas Ådahl | e3cddce | 2012-06-13 00:01:22 +0200 | [diff] [blame] | 1055 | free(ws); |
| 1056 | } |
| 1057 | |
Jonas Ådahl | 0476974 | 2012-06-13 00:01:24 +0200 | [diff] [blame] | 1058 | static void |
| 1059 | seat_destroyed(struct wl_listener *listener, void *data) |
| 1060 | { |
| 1061 | struct weston_seat *seat = data; |
| 1062 | struct focus_state *state, *next; |
| 1063 | struct workspace *ws = container_of(listener, |
| 1064 | struct workspace, |
| 1065 | seat_destroyed_listener); |
| 1066 | |
| 1067 | wl_list_for_each_safe(state, next, &ws->focus_list, link) |
| 1068 | if (state->seat == seat) |
| 1069 | wl_list_remove(&state->link); |
| 1070 | } |
| 1071 | |
Jonas Ådahl | e3cddce | 2012-06-13 00:01:22 +0200 | [diff] [blame] | 1072 | static struct workspace * |
| 1073 | workspace_create(void) |
| 1074 | { |
| 1075 | struct workspace *ws = malloc(sizeof *ws); |
| 1076 | if (ws == NULL) |
| 1077 | return NULL; |
| 1078 | |
| 1079 | weston_layer_init(&ws->layer, NULL); |
| 1080 | |
Jonas Ådahl | 0476974 | 2012-06-13 00:01:24 +0200 | [diff] [blame] | 1081 | wl_list_init(&ws->focus_list); |
| 1082 | wl_list_init(&ws->seat_destroyed_listener.link); |
| 1083 | ws->seat_destroyed_listener.notify = seat_destroyed; |
Louis-Francis Ratté-Boulianne | b482dbd | 2013-11-19 11:37:11 +0100 | [diff] [blame] | 1084 | ws->fsurf_front = NULL; |
| 1085 | ws->fsurf_back = NULL; |
| 1086 | ws->focus_animation = NULL; |
Jonas Ådahl | 0476974 | 2012-06-13 00:01:24 +0200 | [diff] [blame] | 1087 | |
Jonas Ådahl | e3cddce | 2012-06-13 00:01:22 +0200 | [diff] [blame] | 1088 | return ws; |
| 1089 | } |
| 1090 | |
Jonas Ådahl | 62fcd04 | 2012-06-13 00:01:23 +0200 | [diff] [blame] | 1091 | static int |
| 1092 | workspace_is_empty(struct workspace *ws) |
| 1093 | { |
Giulio Camuffo | 412e6a5 | 2014-07-09 22:12:56 +0300 | [diff] [blame] | 1094 | return wl_list_empty(&ws->layer.view_list.link); |
Jonas Ådahl | 62fcd04 | 2012-06-13 00:01:23 +0200 | [diff] [blame] | 1095 | } |
| 1096 | |
Jonas Ådahl | e3cddce | 2012-06-13 00:01:22 +0200 | [diff] [blame] | 1097 | static struct workspace * |
| 1098 | get_workspace(struct desktop_shell *shell, unsigned int index) |
| 1099 | { |
| 1100 | struct workspace **pws = shell->workspaces.array.data; |
Philipp Brüschweiler | 067abf6 | 2012-09-01 16:03:05 +0200 | [diff] [blame] | 1101 | assert(index < shell->workspaces.num); |
Jonas Ådahl | e3cddce | 2012-06-13 00:01:22 +0200 | [diff] [blame] | 1102 | pws += index; |
| 1103 | return *pws; |
| 1104 | } |
| 1105 | |
Kristian Høgsberg | 1ef2313 | 2013-12-04 00:20:01 -0800 | [diff] [blame] | 1106 | struct workspace * |
Jonas Ådahl | e3cddce | 2012-06-13 00:01:22 +0200 | [diff] [blame] | 1107 | get_current_workspace(struct desktop_shell *shell) |
| 1108 | { |
| 1109 | return get_workspace(shell, shell->workspaces.current); |
| 1110 | } |
| 1111 | |
| 1112 | static void |
| 1113 | activate_workspace(struct desktop_shell *shell, unsigned int index) |
| 1114 | { |
| 1115 | struct workspace *ws; |
| 1116 | |
| 1117 | ws = get_workspace(shell, index); |
| 1118 | wl_list_insert(&shell->panel_layer.link, &ws->layer.link); |
| 1119 | |
| 1120 | shell->workspaces.current = index; |
| 1121 | } |
| 1122 | |
Jonas Ådahl | 62fcd04 | 2012-06-13 00:01:23 +0200 | [diff] [blame] | 1123 | static unsigned int |
| 1124 | get_output_height(struct weston_output *output) |
| 1125 | { |
| 1126 | return abs(output->region.extents.y1 - output->region.extents.y2); |
| 1127 | } |
| 1128 | |
| 1129 | static void |
Louis-Francis Ratté-Boulianne | b482dbd | 2013-11-19 11:37:11 +0100 | [diff] [blame] | 1130 | view_translate(struct workspace *ws, struct weston_view *view, double d) |
Jonas Ådahl | 62fcd04 | 2012-06-13 00:01:23 +0200 | [diff] [blame] | 1131 | { |
Jonas Ådahl | 62fcd04 | 2012-06-13 00:01:23 +0200 | [diff] [blame] | 1132 | struct weston_transform *transform; |
| 1133 | |
Louis-Francis Ratté-Boulianne | b482dbd | 2013-11-19 11:37:11 +0100 | [diff] [blame] | 1134 | if (is_focus_view(view)) { |
| 1135 | struct focus_surface *fsurf = get_focus_surface(view->surface); |
| 1136 | transform = &fsurf->workspace_transform; |
| 1137 | } else { |
| 1138 | struct shell_surface *shsurf = get_shell_surface(view->surface); |
| 1139 | transform = &shsurf->workspace_transform; |
| 1140 | } |
| 1141 | |
Jonas Ådahl | 62fcd04 | 2012-06-13 00:01:23 +0200 | [diff] [blame] | 1142 | if (wl_list_empty(&transform->link)) |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 1143 | wl_list_insert(view->geometry.transformation_list.prev, |
Louis-Francis Ratté-Boulianne | b482dbd | 2013-11-19 11:37:11 +0100 | [diff] [blame] | 1144 | &transform->link); |
Jonas Ådahl | 62fcd04 | 2012-06-13 00:01:23 +0200 | [diff] [blame] | 1145 | |
Louis-Francis Ratté-Boulianne | b482dbd | 2013-11-19 11:37:11 +0100 | [diff] [blame] | 1146 | weston_matrix_init(&transform->matrix); |
| 1147 | weston_matrix_translate(&transform->matrix, |
Jonas Ådahl | 62fcd04 | 2012-06-13 00:01:23 +0200 | [diff] [blame] | 1148 | 0.0, d, 0.0); |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 1149 | weston_view_geometry_dirty(view); |
Jonas Ådahl | 62fcd04 | 2012-06-13 00:01:23 +0200 | [diff] [blame] | 1150 | } |
| 1151 | |
| 1152 | static void |
| 1153 | workspace_translate_out(struct workspace *ws, double fraction) |
| 1154 | { |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 1155 | struct weston_view *view; |
Jonas Ådahl | 62fcd04 | 2012-06-13 00:01:23 +0200 | [diff] [blame] | 1156 | unsigned int height; |
| 1157 | double d; |
| 1158 | |
Giulio Camuffo | 412e6a5 | 2014-07-09 22:12:56 +0300 | [diff] [blame] | 1159 | wl_list_for_each(view, &ws->layer.view_list.link, layer_link.link) { |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 1160 | height = get_output_height(view->surface->output); |
Jonas Ådahl | 62fcd04 | 2012-06-13 00:01:23 +0200 | [diff] [blame] | 1161 | d = height * fraction; |
| 1162 | |
Louis-Francis Ratté-Boulianne | b482dbd | 2013-11-19 11:37:11 +0100 | [diff] [blame] | 1163 | view_translate(ws, view, d); |
Jonas Ådahl | 62fcd04 | 2012-06-13 00:01:23 +0200 | [diff] [blame] | 1164 | } |
| 1165 | } |
| 1166 | |
| 1167 | static void |
| 1168 | workspace_translate_in(struct workspace *ws, double fraction) |
| 1169 | { |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 1170 | struct weston_view *view; |
Jonas Ådahl | 62fcd04 | 2012-06-13 00:01:23 +0200 | [diff] [blame] | 1171 | unsigned int height; |
| 1172 | double d; |
| 1173 | |
Giulio Camuffo | 412e6a5 | 2014-07-09 22:12:56 +0300 | [diff] [blame] | 1174 | wl_list_for_each(view, &ws->layer.view_list.link, layer_link.link) { |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 1175 | height = get_output_height(view->surface->output); |
Jonas Ådahl | 62fcd04 | 2012-06-13 00:01:23 +0200 | [diff] [blame] | 1176 | |
| 1177 | if (fraction > 0) |
| 1178 | d = -(height - height * fraction); |
| 1179 | else |
| 1180 | d = height + height * fraction; |
| 1181 | |
Louis-Francis Ratté-Boulianne | b482dbd | 2013-11-19 11:37:11 +0100 | [diff] [blame] | 1182 | view_translate(ws, view, d); |
Jonas Ådahl | 62fcd04 | 2012-06-13 00:01:23 +0200 | [diff] [blame] | 1183 | } |
| 1184 | } |
| 1185 | |
| 1186 | static void |
Jonas Ådahl | e9d2250 | 2012-08-29 22:13:01 +0200 | [diff] [blame] | 1187 | broadcast_current_workspace_state(struct desktop_shell *shell) |
| 1188 | { |
Kristian Høgsberg | 2e3c396 | 2013-09-11 12:00:47 -0700 | [diff] [blame] | 1189 | struct wl_resource *resource; |
Jonas Ådahl | e9d2250 | 2012-08-29 22:13:01 +0200 | [diff] [blame] | 1190 | |
Kristian Høgsberg | 2e3c396 | 2013-09-11 12:00:47 -0700 | [diff] [blame] | 1191 | wl_resource_for_each(resource, &shell->workspaces.client_list) |
| 1192 | workspace_manager_send_state(resource, |
Jonas Ådahl | e9d2250 | 2012-08-29 22:13:01 +0200 | [diff] [blame] | 1193 | shell->workspaces.current, |
| 1194 | shell->workspaces.num); |
| 1195 | } |
| 1196 | |
| 1197 | static void |
Jonas Ådahl | 62fcd04 | 2012-06-13 00:01:23 +0200 | [diff] [blame] | 1198 | reverse_workspace_change_animation(struct desktop_shell *shell, |
| 1199 | unsigned int index, |
| 1200 | struct workspace *from, |
| 1201 | struct workspace *to) |
| 1202 | { |
| 1203 | shell->workspaces.current = index; |
| 1204 | |
| 1205 | shell->workspaces.anim_to = to; |
| 1206 | shell->workspaces.anim_from = from; |
| 1207 | shell->workspaces.anim_dir = -1 * shell->workspaces.anim_dir; |
| 1208 | shell->workspaces.anim_timestamp = 0; |
| 1209 | |
Scott Moreau | 4272e63 | 2012-08-13 09:58:41 -0600 | [diff] [blame] | 1210 | weston_compositor_schedule_repaint(shell->compositor); |
Jonas Ådahl | 62fcd04 | 2012-06-13 00:01:23 +0200 | [diff] [blame] | 1211 | } |
| 1212 | |
| 1213 | static void |
| 1214 | workspace_deactivate_transforms(struct workspace *ws) |
| 1215 | { |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 1216 | struct weston_view *view; |
Louis-Francis Ratté-Boulianne | b482dbd | 2013-11-19 11:37:11 +0100 | [diff] [blame] | 1217 | struct weston_transform *transform; |
Jonas Ådahl | 62fcd04 | 2012-06-13 00:01:23 +0200 | [diff] [blame] | 1218 | |
Giulio Camuffo | 412e6a5 | 2014-07-09 22:12:56 +0300 | [diff] [blame] | 1219 | wl_list_for_each(view, &ws->layer.view_list.link, layer_link.link) { |
Louis-Francis Ratté-Boulianne | b482dbd | 2013-11-19 11:37:11 +0100 | [diff] [blame] | 1220 | if (is_focus_view(view)) { |
| 1221 | struct focus_surface *fsurf = get_focus_surface(view->surface); |
| 1222 | transform = &fsurf->workspace_transform; |
| 1223 | } else { |
| 1224 | struct shell_surface *shsurf = get_shell_surface(view->surface); |
| 1225 | transform = &shsurf->workspace_transform; |
| 1226 | } |
| 1227 | |
| 1228 | if (!wl_list_empty(&transform->link)) { |
| 1229 | wl_list_remove(&transform->link); |
| 1230 | wl_list_init(&transform->link); |
Jonas Ådahl | 8de6a1d | 2012-08-29 22:13:00 +0200 | [diff] [blame] | 1231 | } |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 1232 | weston_view_geometry_dirty(view); |
Jonas Ådahl | 62fcd04 | 2012-06-13 00:01:23 +0200 | [diff] [blame] | 1233 | } |
| 1234 | } |
| 1235 | |
| 1236 | static void |
| 1237 | finish_workspace_change_animation(struct desktop_shell *shell, |
| 1238 | struct workspace *from, |
| 1239 | struct workspace *to) |
| 1240 | { |
Ander Conselvan de Oliveira | 9c6217e | 2014-05-07 11:57:26 +0300 | [diff] [blame] | 1241 | struct weston_view *view; |
| 1242 | |
Scott Moreau | 4272e63 | 2012-08-13 09:58:41 -0600 | [diff] [blame] | 1243 | weston_compositor_schedule_repaint(shell->compositor); |
Jonas Ådahl | 62fcd04 | 2012-06-13 00:01:23 +0200 | [diff] [blame] | 1244 | |
Ander Conselvan de Oliveira | 9c6217e | 2014-05-07 11:57:26 +0300 | [diff] [blame] | 1245 | /* Views that extend past the bottom of the output are still |
| 1246 | * visible after the workspace animation ends but before its layer |
| 1247 | * is hidden. In that case, we need to damage below those views so |
| 1248 | * that the screen is properly repainted. */ |
Giulio Camuffo | 412e6a5 | 2014-07-09 22:12:56 +0300 | [diff] [blame] | 1249 | wl_list_for_each(view, &from->layer.view_list.link, layer_link.link) |
Ander Conselvan de Oliveira | 9c6217e | 2014-05-07 11:57:26 +0300 | [diff] [blame] | 1250 | weston_view_damage_below(view); |
| 1251 | |
Jonas Ådahl | 62fcd04 | 2012-06-13 00:01:23 +0200 | [diff] [blame] | 1252 | wl_list_remove(&shell->workspaces.animation.link); |
| 1253 | workspace_deactivate_transforms(from); |
| 1254 | workspace_deactivate_transforms(to); |
| 1255 | shell->workspaces.anim_to = NULL; |
| 1256 | |
| 1257 | wl_list_remove(&shell->workspaces.anim_from->layer.link); |
| 1258 | } |
| 1259 | |
| 1260 | static void |
| 1261 | animate_workspace_change_frame(struct weston_animation *animation, |
| 1262 | struct weston_output *output, uint32_t msecs) |
| 1263 | { |
| 1264 | struct desktop_shell *shell = |
| 1265 | container_of(animation, struct desktop_shell, |
| 1266 | workspaces.animation); |
| 1267 | struct workspace *from = shell->workspaces.anim_from; |
| 1268 | struct workspace *to = shell->workspaces.anim_to; |
| 1269 | uint32_t t; |
| 1270 | double x, y; |
| 1271 | |
| 1272 | if (workspace_is_empty(from) && workspace_is_empty(to)) { |
| 1273 | finish_workspace_change_animation(shell, from, to); |
| 1274 | return; |
| 1275 | } |
| 1276 | |
| 1277 | if (shell->workspaces.anim_timestamp == 0) { |
| 1278 | if (shell->workspaces.anim_current == 0.0) |
| 1279 | shell->workspaces.anim_timestamp = msecs; |
| 1280 | else |
| 1281 | shell->workspaces.anim_timestamp = |
| 1282 | msecs - |
| 1283 | /* Invers of movement function 'y' below. */ |
| 1284 | (asin(1.0 - shell->workspaces.anim_current) * |
| 1285 | DEFAULT_WORKSPACE_CHANGE_ANIMATION_LENGTH * |
| 1286 | M_2_PI); |
| 1287 | } |
| 1288 | |
| 1289 | t = msecs - shell->workspaces.anim_timestamp; |
| 1290 | |
| 1291 | /* |
| 1292 | * x = [0, π/2] |
| 1293 | * y(x) = sin(x) |
| 1294 | */ |
| 1295 | x = t * (1.0/DEFAULT_WORKSPACE_CHANGE_ANIMATION_LENGTH) * M_PI_2; |
| 1296 | y = sin(x); |
| 1297 | |
| 1298 | if (t < DEFAULT_WORKSPACE_CHANGE_ANIMATION_LENGTH) { |
Scott Moreau | 4272e63 | 2012-08-13 09:58:41 -0600 | [diff] [blame] | 1299 | weston_compositor_schedule_repaint(shell->compositor); |
Jonas Ådahl | 62fcd04 | 2012-06-13 00:01:23 +0200 | [diff] [blame] | 1300 | |
| 1301 | workspace_translate_out(from, shell->workspaces.anim_dir * y); |
| 1302 | workspace_translate_in(to, shell->workspaces.anim_dir * y); |
| 1303 | shell->workspaces.anim_current = y; |
| 1304 | |
Scott Moreau | 4272e63 | 2012-08-13 09:58:41 -0600 | [diff] [blame] | 1305 | weston_compositor_schedule_repaint(shell->compositor); |
Jonas Ådahl | 62fcd04 | 2012-06-13 00:01:23 +0200 | [diff] [blame] | 1306 | } |
Jonas Ådahl | 0476974 | 2012-06-13 00:01:24 +0200 | [diff] [blame] | 1307 | else |
Jonas Ådahl | 62fcd04 | 2012-06-13 00:01:23 +0200 | [diff] [blame] | 1308 | finish_workspace_change_animation(shell, from, to); |
Jonas Ådahl | 62fcd04 | 2012-06-13 00:01:23 +0200 | [diff] [blame] | 1309 | } |
| 1310 | |
| 1311 | static void |
| 1312 | animate_workspace_change(struct desktop_shell *shell, |
| 1313 | unsigned int index, |
| 1314 | struct workspace *from, |
| 1315 | struct workspace *to) |
| 1316 | { |
| 1317 | struct weston_output *output; |
| 1318 | |
| 1319 | int dir; |
| 1320 | |
| 1321 | if (index > shell->workspaces.current) |
| 1322 | dir = -1; |
| 1323 | else |
| 1324 | dir = 1; |
| 1325 | |
| 1326 | shell->workspaces.current = index; |
| 1327 | |
| 1328 | shell->workspaces.anim_dir = dir; |
| 1329 | shell->workspaces.anim_from = from; |
| 1330 | shell->workspaces.anim_to = to; |
| 1331 | shell->workspaces.anim_current = 0.0; |
| 1332 | shell->workspaces.anim_timestamp = 0; |
| 1333 | |
| 1334 | output = container_of(shell->compositor->output_list.next, |
| 1335 | struct weston_output, link); |
| 1336 | wl_list_insert(&output->animation_list, |
| 1337 | &shell->workspaces.animation.link); |
| 1338 | |
Jonas Ådahl | 8de6a1d | 2012-08-29 22:13:00 +0200 | [diff] [blame] | 1339 | wl_list_insert(from->layer.link.prev, &to->layer.link); |
Jonas Ådahl | 62fcd04 | 2012-06-13 00:01:23 +0200 | [diff] [blame] | 1340 | |
| 1341 | workspace_translate_in(to, 0); |
| 1342 | |
Kristian Høgsberg | 2f5faff | 2012-07-31 16:36:34 -0400 | [diff] [blame] | 1343 | restore_focus_state(shell, to); |
Jonas Ådahl | 0476974 | 2012-06-13 00:01:24 +0200 | [diff] [blame] | 1344 | |
Scott Moreau | 4272e63 | 2012-08-13 09:58:41 -0600 | [diff] [blame] | 1345 | weston_compositor_schedule_repaint(shell->compositor); |
Jonas Ådahl | 62fcd04 | 2012-06-13 00:01:23 +0200 | [diff] [blame] | 1346 | } |
| 1347 | |
Jonas Ådahl | e3cddce | 2012-06-13 00:01:22 +0200 | [diff] [blame] | 1348 | static void |
Jonas Ådahl | 8de6a1d | 2012-08-29 22:13:00 +0200 | [diff] [blame] | 1349 | update_workspace(struct desktop_shell *shell, unsigned int index, |
| 1350 | struct workspace *from, struct workspace *to) |
| 1351 | { |
| 1352 | shell->workspaces.current = index; |
| 1353 | wl_list_insert(&from->layer.link, &to->layer.link); |
| 1354 | wl_list_remove(&from->layer.link); |
| 1355 | } |
| 1356 | |
| 1357 | static void |
Jonas Ådahl | e3cddce | 2012-06-13 00:01:22 +0200 | [diff] [blame] | 1358 | change_workspace(struct desktop_shell *shell, unsigned int index) |
| 1359 | { |
| 1360 | struct workspace *from; |
| 1361 | struct workspace *to; |
Louis-Francis Ratté-Boulianne | b482dbd | 2013-11-19 11:37:11 +0100 | [diff] [blame] | 1362 | struct focus_state *state; |
Jonas Ådahl | e3cddce | 2012-06-13 00:01:22 +0200 | [diff] [blame] | 1363 | |
| 1364 | if (index == shell->workspaces.current) |
| 1365 | return; |
| 1366 | |
| 1367 | /* Don't change workspace when there is any fullscreen surfaces. */ |
Giulio Camuffo | 412e6a5 | 2014-07-09 22:12:56 +0300 | [diff] [blame] | 1368 | if (!wl_list_empty(&shell->fullscreen_layer.view_list.link)) |
Jonas Ådahl | e3cddce | 2012-06-13 00:01:22 +0200 | [diff] [blame] | 1369 | return; |
| 1370 | |
Jonas Ådahl | e3cddce | 2012-06-13 00:01:22 +0200 | [diff] [blame] | 1371 | from = get_current_workspace(shell); |
| 1372 | to = get_workspace(shell, index); |
| 1373 | |
Jonas Ådahl | 62fcd04 | 2012-06-13 00:01:23 +0200 | [diff] [blame] | 1374 | if (shell->workspaces.anim_from == to && |
| 1375 | shell->workspaces.anim_to == from) { |
Jonas Ådahl | 8de6a1d | 2012-08-29 22:13:00 +0200 | [diff] [blame] | 1376 | restore_focus_state(shell, to); |
Jonas Ådahl | 62fcd04 | 2012-06-13 00:01:23 +0200 | [diff] [blame] | 1377 | reverse_workspace_change_animation(shell, index, from, to); |
Jonas Ådahl | e9d2250 | 2012-08-29 22:13:01 +0200 | [diff] [blame] | 1378 | broadcast_current_workspace_state(shell); |
Jonas Ådahl | 62fcd04 | 2012-06-13 00:01:23 +0200 | [diff] [blame] | 1379 | return; |
| 1380 | } |
Jonas Ådahl | e3cddce | 2012-06-13 00:01:22 +0200 | [diff] [blame] | 1381 | |
Jonas Ådahl | 62fcd04 | 2012-06-13 00:01:23 +0200 | [diff] [blame] | 1382 | if (shell->workspaces.anim_to != NULL) |
| 1383 | finish_workspace_change_animation(shell, |
| 1384 | shell->workspaces.anim_from, |
| 1385 | shell->workspaces.anim_to); |
| 1386 | |
Jonas Ådahl | 8de6a1d | 2012-08-29 22:13:00 +0200 | [diff] [blame] | 1387 | restore_focus_state(shell, to); |
Jonas Ådahl | 0476974 | 2012-06-13 00:01:24 +0200 | [diff] [blame] | 1388 | |
Louis-Francis Ratté-Boulianne | b482dbd | 2013-11-19 11:37:11 +0100 | [diff] [blame] | 1389 | if (shell->focus_animation_type != ANIMATION_NONE) { |
| 1390 | wl_list_for_each(state, &from->focus_list, link) |
| 1391 | if (state->keyboard_focus) |
| 1392 | animate_focus_change(shell, from, |
| 1393 | get_default_view(state->keyboard_focus), NULL); |
| 1394 | |
| 1395 | wl_list_for_each(state, &to->focus_list, link) |
| 1396 | if (state->keyboard_focus) |
| 1397 | animate_focus_change(shell, to, |
| 1398 | NULL, get_default_view(state->keyboard_focus)); |
| 1399 | } |
| 1400 | |
Jonas Ådahl | 8de6a1d | 2012-08-29 22:13:00 +0200 | [diff] [blame] | 1401 | if (workspace_is_empty(to) && workspace_is_empty(from)) |
| 1402 | update_workspace(shell, index, from, to); |
Jonas Ådahl | 62fcd04 | 2012-06-13 00:01:23 +0200 | [diff] [blame] | 1403 | else |
| 1404 | animate_workspace_change(shell, index, from, to); |
Jonas Ådahl | e9d2250 | 2012-08-29 22:13:01 +0200 | [diff] [blame] | 1405 | |
| 1406 | broadcast_current_workspace_state(shell); |
Pekka Paalanen | e955f1e | 2011-12-07 11:49:52 +0200 | [diff] [blame] | 1407 | } |
| 1408 | |
Jonas Ådahl | 8de6a1d | 2012-08-29 22:13:00 +0200 | [diff] [blame] | 1409 | static bool |
| 1410 | workspace_has_only(struct workspace *ws, struct weston_surface *surface) |
| 1411 | { |
Giulio Camuffo | 412e6a5 | 2014-07-09 22:12:56 +0300 | [diff] [blame] | 1412 | struct wl_list *list = &ws->layer.view_list.link; |
Jonas Ådahl | 8de6a1d | 2012-08-29 22:13:00 +0200 | [diff] [blame] | 1413 | struct wl_list *e; |
| 1414 | |
| 1415 | if (wl_list_empty(list)) |
| 1416 | return false; |
| 1417 | |
| 1418 | e = list->next; |
| 1419 | |
| 1420 | if (e->next != list) |
| 1421 | return false; |
| 1422 | |
Giulio Camuffo | 412e6a5 | 2014-07-09 22:12:56 +0300 | [diff] [blame] | 1423 | return container_of(e, struct weston_view, layer_link.link)->surface == surface; |
Jonas Ådahl | 8de6a1d | 2012-08-29 22:13:00 +0200 | [diff] [blame] | 1424 | } |
| 1425 | |
| 1426 | static void |
Jonas Ådahl | 22faea1 | 2014-10-15 22:02:06 +0200 | [diff] [blame^] | 1427 | surface_keyboard_focus_lost(struct weston_surface *surface) |
| 1428 | { |
| 1429 | struct weston_compositor *compositor = surface->compositor; |
| 1430 | struct weston_seat *seat; |
| 1431 | struct weston_surface *focus; |
| 1432 | |
| 1433 | wl_list_for_each(seat, &compositor->seat_list, link) { |
| 1434 | struct weston_keyboard *keyboard = |
| 1435 | weston_seat_get_keyboard(seat); |
| 1436 | |
| 1437 | if (!keyboard) |
| 1438 | continue; |
| 1439 | |
| 1440 | focus = weston_surface_get_main_surface(keyboard->focus); |
| 1441 | if (focus == surface) |
| 1442 | weston_keyboard_set_focus(keyboard, NULL); |
| 1443 | } |
| 1444 | } |
| 1445 | |
| 1446 | static void |
Philip Withnall | 659163d | 2013-11-25 18:01:36 +0000 | [diff] [blame] | 1447 | move_surface_to_workspace(struct desktop_shell *shell, |
| 1448 | struct shell_surface *shsurf, |
| 1449 | uint32_t workspace) |
Jonas Ådahl | e9d2250 | 2012-08-29 22:13:01 +0200 | [diff] [blame] | 1450 | { |
| 1451 | struct workspace *from; |
| 1452 | struct workspace *to; |
Philip Withnall | 659163d | 2013-11-25 18:01:36 +0000 | [diff] [blame] | 1453 | struct weston_view *view; |
Jonas Ådahl | e9d2250 | 2012-08-29 22:13:01 +0200 | [diff] [blame] | 1454 | |
| 1455 | if (workspace == shell->workspaces.current) |
| 1456 | return; |
| 1457 | |
Philip Withnall | 659163d | 2013-11-25 18:01:36 +0000 | [diff] [blame] | 1458 | view = get_default_view(shsurf->surface); |
| 1459 | if (!view) |
| 1460 | return; |
| 1461 | |
| 1462 | assert(weston_surface_get_main_surface(view->surface) == view->surface); |
| 1463 | |
Philipp Brüschweiler | 067abf6 | 2012-09-01 16:03:05 +0200 | [diff] [blame] | 1464 | if (workspace >= shell->workspaces.num) |
| 1465 | workspace = shell->workspaces.num - 1; |
| 1466 | |
Jonas Ådahl | e9d2250 | 2012-08-29 22:13:01 +0200 | [diff] [blame] | 1467 | from = get_current_workspace(shell); |
| 1468 | to = get_workspace(shell, workspace); |
| 1469 | |
Giulio Camuffo | 412e6a5 | 2014-07-09 22:12:56 +0300 | [diff] [blame] | 1470 | weston_layer_entry_remove(&view->layer_link); |
| 1471 | weston_layer_entry_insert(&to->layer.view_list, &view->layer_link); |
Jonas Ådahl | e9d2250 | 2012-08-29 22:13:01 +0200 | [diff] [blame] | 1472 | |
Philip Withnall | 648a4dd | 2013-11-25 18:01:44 +0000 | [diff] [blame] | 1473 | shell_surface_update_child_surface_layers(shsurf); |
| 1474 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 1475 | drop_focus_state(shell, from, view->surface); |
Jonas Ådahl | 22faea1 | 2014-10-15 22:02:06 +0200 | [diff] [blame^] | 1476 | surface_keyboard_focus_lost(view->surface); |
Jonas Ådahl | e9d2250 | 2012-08-29 22:13:01 +0200 | [diff] [blame] | 1477 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 1478 | weston_view_damage_below(view); |
Jonas Ådahl | e9d2250 | 2012-08-29 22:13:01 +0200 | [diff] [blame] | 1479 | } |
| 1480 | |
| 1481 | static void |
Jonas Ådahl | 8de6a1d | 2012-08-29 22:13:00 +0200 | [diff] [blame] | 1482 | take_surface_to_workspace_by_seat(struct desktop_shell *shell, |
Kristian Høgsberg | e314875 | 2013-05-06 23:19:49 -0400 | [diff] [blame] | 1483 | struct weston_seat *seat, |
Jonas Ådahl | 8de6a1d | 2012-08-29 22:13:00 +0200 | [diff] [blame] | 1484 | unsigned int index) |
| 1485 | { |
Derek Foreman | 1281a36 | 2015-07-31 16:55:32 -0500 | [diff] [blame] | 1486 | struct weston_keyboard *keyboard = weston_seat_get_keyboard(seat); |
Pekka Paalanen | 01388e2 | 2013-04-25 13:57:44 +0300 | [diff] [blame] | 1487 | struct weston_surface *surface; |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 1488 | struct weston_view *view; |
Jonas Ådahl | 8de6a1d | 2012-08-29 22:13:00 +0200 | [diff] [blame] | 1489 | struct shell_surface *shsurf; |
| 1490 | struct workspace *from; |
| 1491 | struct workspace *to; |
Jonas Ådahl | 8538b22 | 2012-08-29 22:13:03 +0200 | [diff] [blame] | 1492 | struct focus_state *state; |
Jonas Ådahl | 8de6a1d | 2012-08-29 22:13:00 +0200 | [diff] [blame] | 1493 | |
Derek Foreman | 1281a36 | 2015-07-31 16:55:32 -0500 | [diff] [blame] | 1494 | surface = weston_surface_get_main_surface(keyboard->focus); |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 1495 | view = get_default_view(surface); |
| 1496 | if (view == NULL || |
Louis-Francis Ratté-Boulianne | b482dbd | 2013-11-19 11:37:11 +0100 | [diff] [blame] | 1497 | index == shell->workspaces.current || |
| 1498 | is_focus_view(view)) |
Jonas Ådahl | 8de6a1d | 2012-08-29 22:13:00 +0200 | [diff] [blame] | 1499 | return; |
| 1500 | |
| 1501 | from = get_current_workspace(shell); |
| 1502 | to = get_workspace(shell, index); |
| 1503 | |
Giulio Camuffo | 412e6a5 | 2014-07-09 22:12:56 +0300 | [diff] [blame] | 1504 | weston_layer_entry_remove(&view->layer_link); |
| 1505 | weston_layer_entry_insert(&to->layer.view_list, &view->layer_link); |
Jonas Ådahl | 8de6a1d | 2012-08-29 22:13:00 +0200 | [diff] [blame] | 1506 | |
Philip Withnall | 659163d | 2013-11-25 18:01:36 +0000 | [diff] [blame] | 1507 | shsurf = get_shell_surface(surface); |
Philip Withnall | 648a4dd | 2013-11-25 18:01:44 +0000 | [diff] [blame] | 1508 | if (shsurf != NULL) |
| 1509 | shell_surface_update_child_surface_layers(shsurf); |
Philip Withnall | 659163d | 2013-11-25 18:01:36 +0000 | [diff] [blame] | 1510 | |
Jonas Ådahl | e9d2250 | 2012-08-29 22:13:01 +0200 | [diff] [blame] | 1511 | replace_focus_state(shell, to, seat); |
Jonas Ådahl | 8de6a1d | 2012-08-29 22:13:00 +0200 | [diff] [blame] | 1512 | drop_focus_state(shell, from, surface); |
| 1513 | |
| 1514 | if (shell->workspaces.anim_from == to && |
| 1515 | shell->workspaces.anim_to == from) { |
Jonas Ådahl | e9d2250 | 2012-08-29 22:13:01 +0200 | [diff] [blame] | 1516 | wl_list_remove(&to->layer.link); |
| 1517 | wl_list_insert(from->layer.link.prev, &to->layer.link); |
| 1518 | |
Jonas Ådahl | 8de6a1d | 2012-08-29 22:13:00 +0200 | [diff] [blame] | 1519 | reverse_workspace_change_animation(shell, index, from, to); |
Jonas Ådahl | e9d2250 | 2012-08-29 22:13:01 +0200 | [diff] [blame] | 1520 | broadcast_current_workspace_state(shell); |
| 1521 | |
Jonas Ådahl | 8de6a1d | 2012-08-29 22:13:00 +0200 | [diff] [blame] | 1522 | return; |
| 1523 | } |
| 1524 | |
| 1525 | if (shell->workspaces.anim_to != NULL) |
| 1526 | finish_workspace_change_animation(shell, |
| 1527 | shell->workspaces.anim_from, |
| 1528 | shell->workspaces.anim_to); |
| 1529 | |
| 1530 | if (workspace_is_empty(from) && |
| 1531 | workspace_has_only(to, surface)) |
| 1532 | update_workspace(shell, index, from, to); |
| 1533 | else { |
Philip Withnall | 2c3849b | 2013-11-25 18:01:45 +0000 | [diff] [blame] | 1534 | if (shsurf != NULL && |
| 1535 | wl_list_empty(&shsurf->workspace_transform.link)) |
Jonas Ådahl | 8de6a1d | 2012-08-29 22:13:00 +0200 | [diff] [blame] | 1536 | wl_list_insert(&shell->workspaces.anim_sticky_list, |
| 1537 | &shsurf->workspace_transform.link); |
| 1538 | |
| 1539 | animate_workspace_change(shell, index, from, to); |
| 1540 | } |
Jonas Ådahl | e9d2250 | 2012-08-29 22:13:01 +0200 | [diff] [blame] | 1541 | |
| 1542 | broadcast_current_workspace_state(shell); |
Jonas Ådahl | 8538b22 | 2012-08-29 22:13:03 +0200 | [diff] [blame] | 1543 | |
| 1544 | state = ensure_focus_state(shell, seat); |
| 1545 | if (state != NULL) |
Kristian Høgsberg | d500bf1 | 2014-01-22 12:25:20 -0800 | [diff] [blame] | 1546 | focus_state_set_focus(state, surface); |
Jonas Ådahl | e9d2250 | 2012-08-29 22:13:01 +0200 | [diff] [blame] | 1547 | } |
| 1548 | |
| 1549 | static void |
| 1550 | workspace_manager_move_surface(struct wl_client *client, |
| 1551 | struct wl_resource *resource, |
| 1552 | struct wl_resource *surface_resource, |
| 1553 | uint32_t workspace) |
| 1554 | { |
Jason Ekstrand | 651f00e | 2013-06-14 10:07:54 -0500 | [diff] [blame] | 1555 | struct desktop_shell *shell = wl_resource_get_user_data(resource); |
Jonas Ådahl | e9d2250 | 2012-08-29 22:13:01 +0200 | [diff] [blame] | 1556 | struct weston_surface *surface = |
Jason Ekstrand | 0f2ef7e | 2013-06-14 10:07:53 -0500 | [diff] [blame] | 1557 | wl_resource_get_user_data(surface_resource); |
Pekka Paalanen | 01388e2 | 2013-04-25 13:57:44 +0300 | [diff] [blame] | 1558 | struct weston_surface *main_surface; |
Philip Withnall | 659163d | 2013-11-25 18:01:36 +0000 | [diff] [blame] | 1559 | struct shell_surface *shell_surface; |
Jonas Ådahl | e9d2250 | 2012-08-29 22:13:01 +0200 | [diff] [blame] | 1560 | |
Pekka Paalanen | 01388e2 | 2013-04-25 13:57:44 +0300 | [diff] [blame] | 1561 | main_surface = weston_surface_get_main_surface(surface); |
Philip Withnall | 659163d | 2013-11-25 18:01:36 +0000 | [diff] [blame] | 1562 | shell_surface = get_shell_surface(main_surface); |
| 1563 | if (shell_surface == NULL) |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 1564 | return; |
Philip Withnall | 659163d | 2013-11-25 18:01:36 +0000 | [diff] [blame] | 1565 | |
| 1566 | move_surface_to_workspace(shell, shell_surface, workspace); |
Jonas Ådahl | e9d2250 | 2012-08-29 22:13:01 +0200 | [diff] [blame] | 1567 | } |
| 1568 | |
| 1569 | static const struct workspace_manager_interface workspace_manager_implementation = { |
| 1570 | workspace_manager_move_surface, |
| 1571 | }; |
| 1572 | |
| 1573 | static void |
| 1574 | unbind_resource(struct wl_resource *resource) |
| 1575 | { |
Jason Ekstrand | 651f00e | 2013-06-14 10:07:54 -0500 | [diff] [blame] | 1576 | wl_list_remove(wl_resource_get_link(resource)); |
Jonas Ådahl | e9d2250 | 2012-08-29 22:13:01 +0200 | [diff] [blame] | 1577 | } |
| 1578 | |
| 1579 | static void |
| 1580 | bind_workspace_manager(struct wl_client *client, |
| 1581 | void *data, uint32_t version, uint32_t id) |
| 1582 | { |
| 1583 | struct desktop_shell *shell = data; |
| 1584 | struct wl_resource *resource; |
| 1585 | |
Jason Ekstrand | a85118c | 2013-06-27 20:17:02 -0500 | [diff] [blame] | 1586 | resource = wl_resource_create(client, |
| 1587 | &workspace_manager_interface, 1, id); |
Jonas Ådahl | e9d2250 | 2012-08-29 22:13:01 +0200 | [diff] [blame] | 1588 | |
| 1589 | if (resource == NULL) { |
| 1590 | weston_log("couldn't add workspace manager object"); |
| 1591 | return; |
| 1592 | } |
| 1593 | |
Jason Ekstrand | a85118c | 2013-06-27 20:17:02 -0500 | [diff] [blame] | 1594 | wl_resource_set_implementation(resource, |
| 1595 | &workspace_manager_implementation, |
| 1596 | shell, unbind_resource); |
Jason Ekstrand | 651f00e | 2013-06-14 10:07:54 -0500 | [diff] [blame] | 1597 | wl_list_insert(&shell->workspaces.client_list, |
| 1598 | wl_resource_get_link(resource)); |
Jonas Ådahl | e9d2250 | 2012-08-29 22:13:01 +0200 | [diff] [blame] | 1599 | |
| 1600 | workspace_manager_send_state(resource, |
| 1601 | shell->workspaces.current, |
| 1602 | shell->workspaces.num); |
Jonas Ådahl | 8de6a1d | 2012-08-29 22:13:00 +0200 | [diff] [blame] | 1603 | } |
| 1604 | |
Pekka Paalanen | 56cdea9 | 2011-11-23 16:14:12 +0200 | [diff] [blame] | 1605 | static void |
Rusty Lynch | 1084da5 | 2013-08-15 09:10:08 -0700 | [diff] [blame] | 1606 | touch_move_grab_down(struct weston_touch_grab *grab, uint32_t time, |
Giulio Camuffo | 61ed7b6 | 2015-07-08 11:55:28 +0300 | [diff] [blame] | 1607 | int touch_id, wl_fixed_t x, wl_fixed_t y) |
Rusty Lynch | 1084da5 | 2013-08-15 09:10:08 -0700 | [diff] [blame] | 1608 | { |
| 1609 | } |
| 1610 | |
| 1611 | static void |
| 1612 | touch_move_grab_up(struct weston_touch_grab *grab, uint32_t time, int touch_id) |
| 1613 | { |
Jonas Ådahl | 1c6e63e | 2013-10-25 23:18:04 +0200 | [diff] [blame] | 1614 | struct weston_touch_move_grab *move = |
| 1615 | (struct weston_touch_move_grab *) container_of( |
| 1616 | grab, struct shell_touch_grab, grab); |
Neil Roberts | e14aa4f | 2013-10-03 16:43:07 +0100 | [diff] [blame] | 1617 | |
Kristian Høgsberg | 8e80a31 | 2014-01-17 15:18:10 -0800 | [diff] [blame] | 1618 | if (touch_id == 0) |
| 1619 | move->active = 0; |
| 1620 | |
Jonas Ådahl | 9484b69 | 2013-12-02 22:05:03 +0100 | [diff] [blame] | 1621 | if (grab->touch->num_tp == 0) { |
Jonas Ådahl | 1c6e63e | 2013-10-25 23:18:04 +0200 | [diff] [blame] | 1622 | shell_touch_grab_end(&move->base); |
| 1623 | free(move); |
| 1624 | } |
Rusty Lynch | 1084da5 | 2013-08-15 09:10:08 -0700 | [diff] [blame] | 1625 | } |
| 1626 | |
| 1627 | static void |
| 1628 | touch_move_grab_motion(struct weston_touch_grab *grab, uint32_t time, |
Giulio Camuffo | 61ed7b6 | 2015-07-08 11:55:28 +0300 | [diff] [blame] | 1629 | int touch_id, wl_fixed_t x, wl_fixed_t y) |
Rusty Lynch | 1084da5 | 2013-08-15 09:10:08 -0700 | [diff] [blame] | 1630 | { |
| 1631 | struct weston_touch_move_grab *move = (struct weston_touch_move_grab *) grab; |
| 1632 | struct shell_surface *shsurf = move->base.shsurf; |
| 1633 | struct weston_surface *es; |
| 1634 | int dx = wl_fixed_to_int(grab->touch->grab_x + move->dx); |
| 1635 | int dy = wl_fixed_to_int(grab->touch->grab_y + move->dy); |
| 1636 | |
Kristian Høgsberg | 8e80a31 | 2014-01-17 15:18:10 -0800 | [diff] [blame] | 1637 | if (!shsurf || !move->active) |
Rusty Lynch | 1084da5 | 2013-08-15 09:10:08 -0700 | [diff] [blame] | 1638 | return; |
| 1639 | |
| 1640 | es = shsurf->surface; |
| 1641 | |
Jason Ekstrand | 918f2dd | 2013-12-02 21:01:53 -0600 | [diff] [blame] | 1642 | weston_view_set_position(shsurf->view, dx, dy); |
Rusty Lynch | 1084da5 | 2013-08-15 09:10:08 -0700 | [diff] [blame] | 1643 | |
| 1644 | weston_compositor_schedule_repaint(es->compositor); |
| 1645 | } |
| 1646 | |
Jonas Ådahl | 1ea343e | 2013-10-25 23:18:05 +0200 | [diff] [blame] | 1647 | static void |
Jonas Ådahl | 1679f23 | 2014-04-12 09:39:51 +0200 | [diff] [blame] | 1648 | touch_move_grab_frame(struct weston_touch_grab *grab) |
| 1649 | { |
| 1650 | } |
| 1651 | |
| 1652 | static void |
Jonas Ådahl | 1ea343e | 2013-10-25 23:18:05 +0200 | [diff] [blame] | 1653 | touch_move_grab_cancel(struct weston_touch_grab *grab) |
| 1654 | { |
| 1655 | struct weston_touch_move_grab *move = |
| 1656 | (struct weston_touch_move_grab *) container_of( |
| 1657 | grab, struct shell_touch_grab, grab); |
| 1658 | |
| 1659 | shell_touch_grab_end(&move->base); |
| 1660 | free(move); |
| 1661 | } |
| 1662 | |
Rusty Lynch | 1084da5 | 2013-08-15 09:10:08 -0700 | [diff] [blame] | 1663 | static const struct weston_touch_grab_interface touch_move_grab_interface = { |
| 1664 | touch_move_grab_down, |
| 1665 | touch_move_grab_up, |
| 1666 | touch_move_grab_motion, |
Jonas Ådahl | 1679f23 | 2014-04-12 09:39:51 +0200 | [diff] [blame] | 1667 | touch_move_grab_frame, |
Jonas Ådahl | 1ea343e | 2013-10-25 23:18:05 +0200 | [diff] [blame] | 1668 | touch_move_grab_cancel, |
Rusty Lynch | 1084da5 | 2013-08-15 09:10:08 -0700 | [diff] [blame] | 1669 | }; |
| 1670 | |
| 1671 | static int |
Derek Foreman | b7674ae | 2015-07-15 13:00:37 -0500 | [diff] [blame] | 1672 | surface_touch_move(struct shell_surface *shsurf, struct weston_touch *touch) |
Rusty Lynch | 1084da5 | 2013-08-15 09:10:08 -0700 | [diff] [blame] | 1673 | { |
| 1674 | struct weston_touch_move_grab *move; |
| 1675 | |
| 1676 | if (!shsurf) |
| 1677 | return -1; |
| 1678 | |
Ander Conselvan de Oliveira | 6d43f04 | 2014-05-07 14:22:23 +0300 | [diff] [blame] | 1679 | if (shsurf->state.fullscreen || shsurf->state.maximized) |
Rusty Lynch | 1084da5 | 2013-08-15 09:10:08 -0700 | [diff] [blame] | 1680 | return 0; |
| 1681 | |
| 1682 | move = malloc(sizeof *move); |
| 1683 | if (!move) |
| 1684 | return -1; |
| 1685 | |
Kristian Høgsberg | 8e80a31 | 2014-01-17 15:18:10 -0800 | [diff] [blame] | 1686 | move->active = 1; |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 1687 | move->dx = wl_fixed_from_double(shsurf->view->geometry.x) - |
Derek Foreman | b7674ae | 2015-07-15 13:00:37 -0500 | [diff] [blame] | 1688 | touch->grab_x; |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 1689 | move->dy = wl_fixed_from_double(shsurf->view->geometry.y) - |
Derek Foreman | b7674ae | 2015-07-15 13:00:37 -0500 | [diff] [blame] | 1690 | touch->grab_y; |
Rusty Lynch | 1084da5 | 2013-08-15 09:10:08 -0700 | [diff] [blame] | 1691 | |
| 1692 | shell_touch_grab_start(&move->base, &touch_move_grab_interface, shsurf, |
Derek Foreman | b7674ae | 2015-07-15 13:00:37 -0500 | [diff] [blame] | 1693 | touch); |
Rusty Lynch | 1084da5 | 2013-08-15 09:10:08 -0700 | [diff] [blame] | 1694 | |
| 1695 | return 0; |
| 1696 | } |
| 1697 | |
| 1698 | static void |
Kristian Høgsberg | 6848c25 | 2013-05-08 22:02:59 -0400 | [diff] [blame] | 1699 | noop_grab_focus(struct weston_pointer_grab *grab) |
Kristian Høgsberg | 9ddb826 | 2012-01-04 21:30:29 -0500 | [diff] [blame] | 1700 | { |
Kristian Høgsberg | 9ddb826 | 2012-01-04 21:30:29 -0500 | [diff] [blame] | 1701 | } |
| 1702 | |
| 1703 | static void |
Kristian Høgsberg | ae356ae | 2014-04-29 16:03:54 -0700 | [diff] [blame] | 1704 | constrain_position(struct weston_move_grab *move, int *cx, int *cy) |
| 1705 | { |
| 1706 | struct shell_surface *shsurf = move->base.shsurf; |
| 1707 | struct weston_pointer *pointer = move->base.grab.pointer; |
Derek Foreman | 6feb0f9 | 2015-04-15 12:23:56 -0500 | [diff] [blame] | 1708 | int x, y, bottom; |
Kristian Høgsberg | ae356ae | 2014-04-29 16:03:54 -0700 | [diff] [blame] | 1709 | const int safety = 50; |
Derek Foreman | 6feb0f9 | 2015-04-15 12:23:56 -0500 | [diff] [blame] | 1710 | pixman_rectangle32_t area; |
Kristian Høgsberg | ae356ae | 2014-04-29 16:03:54 -0700 | [diff] [blame] | 1711 | |
| 1712 | x = wl_fixed_to_int(pointer->x + move->dx); |
| 1713 | y = wl_fixed_to_int(pointer->y + move->dy); |
| 1714 | |
Jonny Lamb | d73c694 | 2014-08-20 15:53:20 +0200 | [diff] [blame] | 1715 | if (shsurf->shell->panel_position == DESKTOP_SHELL_PANEL_POSITION_TOP) { |
Derek Foreman | 6feb0f9 | 2015-04-15 12:23:56 -0500 | [diff] [blame] | 1716 | get_output_work_area(shsurf->shell, |
| 1717 | shsurf->surface->output, |
| 1718 | &area); |
Kristian Høgsberg | ae356ae | 2014-04-29 16:03:54 -0700 | [diff] [blame] | 1719 | |
Derek Foreman | 6feb0f9 | 2015-04-15 12:23:56 -0500 | [diff] [blame] | 1720 | bottom = y + shsurf->geometry.height + shsurf->geometry.y; |
| 1721 | if (bottom - safety < area.y) |
| 1722 | y = area.y + safety - shsurf->geometry.height |
| 1723 | - shsurf->geometry.y; |
Jonny Lamb | d73c694 | 2014-08-20 15:53:20 +0200 | [diff] [blame] | 1724 | |
| 1725 | if (move->client_initiated && |
Derek Foreman | 6feb0f9 | 2015-04-15 12:23:56 -0500 | [diff] [blame] | 1726 | y + shsurf->geometry.y < area.y) |
| 1727 | y = area.y - shsurf->geometry.y; |
| 1728 | |
Jonny Lamb | d73c694 | 2014-08-20 15:53:20 +0200 | [diff] [blame] | 1729 | } |
Kristian Høgsberg | ae356ae | 2014-04-29 16:03:54 -0700 | [diff] [blame] | 1730 | |
| 1731 | *cx = x; |
| 1732 | *cy = y; |
| 1733 | } |
| 1734 | |
| 1735 | static void |
Giulio Camuffo | 1959ab8 | 2013-11-14 23:42:52 +0100 | [diff] [blame] | 1736 | move_grab_motion(struct weston_pointer_grab *grab, uint32_t time, |
| 1737 | wl_fixed_t x, wl_fixed_t y) |
Kristian Høgsberg | 4cca349 | 2011-01-18 07:53:49 -0500 | [diff] [blame] | 1738 | { |
Kristian Høgsberg | 8334bc1 | 2012-01-03 10:29:47 -0500 | [diff] [blame] | 1739 | struct weston_move_grab *move = (struct weston_move_grab *) grab; |
Kristian Høgsberg | 02bbabb | 2013-05-06 22:15:05 -0400 | [diff] [blame] | 1740 | struct weston_pointer *pointer = grab->pointer; |
Ander Conselvan de Oliveira | fe0444a | 2012-04-04 17:48:05 +0300 | [diff] [blame] | 1741 | struct shell_surface *shsurf = move->base.shsurf; |
Kristian Høgsberg | ae356ae | 2014-04-29 16:03:54 -0700 | [diff] [blame] | 1742 | int cx, cy; |
Giulio Camuffo | 1959ab8 | 2013-11-14 23:42:52 +0100 | [diff] [blame] | 1743 | |
| 1744 | weston_pointer_move(pointer, x, y); |
Ander Conselvan de Oliveira | fe0444a | 2012-04-04 17:48:05 +0300 | [diff] [blame] | 1745 | if (!shsurf) |
| 1746 | return; |
| 1747 | |
Kristian Høgsberg | ae356ae | 2014-04-29 16:03:54 -0700 | [diff] [blame] | 1748 | constrain_position(move, &cx, &cy); |
| 1749 | |
| 1750 | weston_view_set_position(shsurf->view, cx, cy); |
Kristian Høgsberg | 4cca349 | 2011-01-18 07:53:49 -0500 | [diff] [blame] | 1751 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 1752 | weston_compositor_schedule_repaint(shsurf->surface->compositor); |
Kristian Høgsberg | 4cca349 | 2011-01-18 07:53:49 -0500 | [diff] [blame] | 1753 | } |
| 1754 | |
| 1755 | static void |
Kristian Høgsberg | 02bbabb | 2013-05-06 22:15:05 -0400 | [diff] [blame] | 1756 | move_grab_button(struct weston_pointer_grab *grab, |
Daniel Stone | 4dbadb1 | 2012-05-30 16:31:51 +0100 | [diff] [blame] | 1757 | uint32_t time, uint32_t button, uint32_t state_w) |
Kristian Høgsberg | 4cca349 | 2011-01-18 07:53:49 -0500 | [diff] [blame] | 1758 | { |
Ander Conselvan de Oliveira | fe0444a | 2012-04-04 17:48:05 +0300 | [diff] [blame] | 1759 | struct shell_grab *shell_grab = container_of(grab, struct shell_grab, |
| 1760 | grab); |
Kristian Høgsberg | 02bbabb | 2013-05-06 22:15:05 -0400 | [diff] [blame] | 1761 | struct weston_pointer *pointer = grab->pointer; |
Daniel Stone | 4dbadb1 | 2012-05-30 16:31:51 +0100 | [diff] [blame] | 1762 | enum wl_pointer_button_state state = state_w; |
Kristian Høgsberg | 4cca349 | 2011-01-18 07:53:49 -0500 | [diff] [blame] | 1763 | |
Daniel Stone | 4dbadb1 | 2012-05-30 16:31:51 +0100 | [diff] [blame] | 1764 | if (pointer->button_count == 0 && |
| 1765 | state == WL_POINTER_BUTTON_STATE_RELEASED) { |
Ander Conselvan de Oliveira | b9d2a0f | 2012-06-28 18:08:05 +0300 | [diff] [blame] | 1766 | shell_grab_end(shell_grab); |
Kristian Høgsberg | 9ddb826 | 2012-01-04 21:30:29 -0500 | [diff] [blame] | 1767 | free(grab); |
| 1768 | } |
Kristian Høgsberg | 4cca349 | 2011-01-18 07:53:49 -0500 | [diff] [blame] | 1769 | } |
| 1770 | |
Jonas Ådahl | 1ea343e | 2013-10-25 23:18:05 +0200 | [diff] [blame] | 1771 | static void |
| 1772 | move_grab_cancel(struct weston_pointer_grab *grab) |
| 1773 | { |
| 1774 | struct shell_grab *shell_grab = |
| 1775 | container_of(grab, struct shell_grab, grab); |
| 1776 | |
| 1777 | shell_grab_end(shell_grab); |
| 1778 | free(grab); |
| 1779 | } |
| 1780 | |
Kristian Høgsberg | 02bbabb | 2013-05-06 22:15:05 -0400 | [diff] [blame] | 1781 | static const struct weston_pointer_grab_interface move_grab_interface = { |
Kristian Høgsberg | 9ddb826 | 2012-01-04 21:30:29 -0500 | [diff] [blame] | 1782 | noop_grab_focus, |
Kristian Høgsberg | 4cca349 | 2011-01-18 07:53:49 -0500 | [diff] [blame] | 1783 | move_grab_motion, |
| 1784 | move_grab_button, |
Jonas Ådahl | 1ea343e | 2013-10-25 23:18:05 +0200 | [diff] [blame] | 1785 | move_grab_cancel, |
Kristian Høgsberg | 4cca349 | 2011-01-18 07:53:49 -0500 | [diff] [blame] | 1786 | }; |
| 1787 | |
Kristian Høgsberg | 9e31bff | 2012-08-01 00:08:07 -0400 | [diff] [blame] | 1788 | static int |
Derek Foreman | 794fa0e | 2015-07-15 13:00:38 -0500 | [diff] [blame] | 1789 | surface_move(struct shell_surface *shsurf, struct weston_pointer *pointer, |
Derek Foreman | cf7d95a | 2015-06-03 15:53:22 -0500 | [diff] [blame] | 1790 | bool client_initiated) |
Kristian Høgsberg | 9e31bff | 2012-08-01 00:08:07 -0400 | [diff] [blame] | 1791 | { |
| 1792 | struct weston_move_grab *move; |
| 1793 | |
| 1794 | if (!shsurf) |
| 1795 | return -1; |
| 1796 | |
Derek Foreman | 45a7c27 | 2015-09-11 14:27:40 -0500 | [diff] [blame] | 1797 | shsurf = find_toplevel_surface(shsurf); |
| 1798 | |
Kristian Høgsberg | a4b620e | 2014-04-30 16:05:49 -0700 | [diff] [blame] | 1799 | if (shsurf->grabbed || |
| 1800 | shsurf->state.fullscreen || shsurf->state.maximized) |
Kristian Høgsberg | 9e31bff | 2012-08-01 00:08:07 -0400 | [diff] [blame] | 1801 | return 0; |
| 1802 | |
| 1803 | move = malloc(sizeof *move); |
| 1804 | if (!move) |
| 1805 | return -1; |
| 1806 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 1807 | move->dx = wl_fixed_from_double(shsurf->view->geometry.x) - |
Derek Foreman | 794fa0e | 2015-07-15 13:00:38 -0500 | [diff] [blame] | 1808 | pointer->grab_x; |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 1809 | move->dy = wl_fixed_from_double(shsurf->view->geometry.y) - |
Derek Foreman | 794fa0e | 2015-07-15 13:00:38 -0500 | [diff] [blame] | 1810 | pointer->grab_y; |
Kristian Høgsberg | ae356ae | 2014-04-29 16:03:54 -0700 | [diff] [blame] | 1811 | move->client_initiated = client_initiated; |
Kristian Høgsberg | 9e31bff | 2012-08-01 00:08:07 -0400 | [diff] [blame] | 1812 | |
| 1813 | shell_grab_start(&move->base, &move_grab_interface, shsurf, |
Derek Foreman | 794fa0e | 2015-07-15 13:00:38 -0500 | [diff] [blame] | 1814 | pointer, DESKTOP_SHELL_CURSOR_MOVE); |
Kristian Høgsberg | 9e31bff | 2012-08-01 00:08:07 -0400 | [diff] [blame] | 1815 | |
| 1816 | return 0; |
| 1817 | } |
| 1818 | |
| 1819 | static void |
Rafael Antognolli | e2a3455 | 2013-12-03 15:35:45 -0200 | [diff] [blame] | 1820 | common_surface_move(struct wl_resource *resource, |
| 1821 | struct wl_resource *seat_resource, uint32_t serial) |
Kristian Høgsberg | 9e31bff | 2012-08-01 00:08:07 -0400 | [diff] [blame] | 1822 | { |
Jason Ekstrand | 44a3863 | 2013-06-14 10:08:00 -0500 | [diff] [blame] | 1823 | struct weston_seat *seat = wl_resource_get_user_data(seat_resource); |
Derek Foreman | 1281a36 | 2015-07-31 16:55:32 -0500 | [diff] [blame] | 1824 | struct weston_pointer *pointer = weston_seat_get_pointer(seat); |
| 1825 | struct weston_touch *touch = weston_seat_get_touch(seat); |
Jason Ekstrand | 651f00e | 2013-06-14 10:07:54 -0500 | [diff] [blame] | 1826 | struct shell_surface *shsurf = wl_resource_get_user_data(resource); |
Giulio Camuffo | 61da3fc | 2013-04-25 13:57:45 +0300 | [diff] [blame] | 1827 | struct weston_surface *surface; |
Kristian Høgsberg | 9e31bff | 2012-08-01 00:08:07 -0400 | [diff] [blame] | 1828 | |
Derek Foreman | 1281a36 | 2015-07-31 16:55:32 -0500 | [diff] [blame] | 1829 | if (pointer && |
| 1830 | pointer->focus && |
| 1831 | pointer->button_count > 0 && |
| 1832 | pointer->grab_serial == serial) { |
| 1833 | surface = weston_surface_get_main_surface(pointer->focus->surface); |
U. Artie Eoff | cf5737a | 2014-01-17 10:08:25 -0800 | [diff] [blame] | 1834 | if ((surface == shsurf->surface) && |
Derek Foreman | 1281a36 | 2015-07-31 16:55:32 -0500 | [diff] [blame] | 1835 | (surface_move(shsurf, pointer, true) < 0)) |
Rusty Lynch | 1084da5 | 2013-08-15 09:10:08 -0700 | [diff] [blame] | 1836 | wl_resource_post_no_memory(resource); |
Derek Foreman | 1281a36 | 2015-07-31 16:55:32 -0500 | [diff] [blame] | 1837 | } else if (touch && |
| 1838 | touch->focus && |
| 1839 | touch->grab_serial == serial) { |
| 1840 | surface = weston_surface_get_main_surface(touch->focus->surface); |
U. Artie Eoff | cf5737a | 2014-01-17 10:08:25 -0800 | [diff] [blame] | 1841 | if ((surface == shsurf->surface) && |
Derek Foreman | 1281a36 | 2015-07-31 16:55:32 -0500 | [diff] [blame] | 1842 | (surface_touch_move(shsurf, touch) < 0)) |
Rusty Lynch | 1084da5 | 2013-08-15 09:10:08 -0700 | [diff] [blame] | 1843 | wl_resource_post_no_memory(resource); |
| 1844 | } |
Kristian Høgsberg | 9e31bff | 2012-08-01 00:08:07 -0400 | [diff] [blame] | 1845 | } |
| 1846 | |
Rafael Antognolli | e2a3455 | 2013-12-03 15:35:45 -0200 | [diff] [blame] | 1847 | static void |
| 1848 | shell_surface_move(struct wl_client *client, struct wl_resource *resource, |
| 1849 | struct wl_resource *seat_resource, uint32_t serial) |
| 1850 | { |
| 1851 | common_surface_move(resource, seat_resource, serial); |
| 1852 | } |
| 1853 | |
Kristian Høgsberg | 9e31bff | 2012-08-01 00:08:07 -0400 | [diff] [blame] | 1854 | struct weston_resize_grab { |
| 1855 | struct shell_grab base; |
| 1856 | uint32_t edges; |
| 1857 | int32_t width, height; |
| 1858 | }; |
| 1859 | |
| 1860 | static void |
Giulio Camuffo | 1959ab8 | 2013-11-14 23:42:52 +0100 | [diff] [blame] | 1861 | resize_grab_motion(struct weston_pointer_grab *grab, uint32_t time, |
| 1862 | wl_fixed_t x, wl_fixed_t y) |
Kristian Høgsberg | 9e31bff | 2012-08-01 00:08:07 -0400 | [diff] [blame] | 1863 | { |
| 1864 | struct weston_resize_grab *resize = (struct weston_resize_grab *) grab; |
Kristian Høgsberg | 02bbabb | 2013-05-06 22:15:05 -0400 | [diff] [blame] | 1865 | struct weston_pointer *pointer = grab->pointer; |
Kristian Høgsberg | 9e31bff | 2012-08-01 00:08:07 -0400 | [diff] [blame] | 1866 | struct shell_surface *shsurf = resize->base.shsurf; |
| 1867 | int32_t width, height; |
| 1868 | wl_fixed_t from_x, from_y; |
| 1869 | wl_fixed_t to_x, to_y; |
| 1870 | |
Giulio Camuffo | 1959ab8 | 2013-11-14 23:42:52 +0100 | [diff] [blame] | 1871 | weston_pointer_move(pointer, x, y); |
| 1872 | |
Kristian Høgsberg | e0b9d5b | 2014-04-30 13:45:49 -0700 | [diff] [blame] | 1873 | if (!shsurf) |
Kristian Høgsberg | 9e31bff | 2012-08-01 00:08:07 -0400 | [diff] [blame] | 1874 | return; |
| 1875 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 1876 | weston_view_from_global_fixed(shsurf->view, |
| 1877 | pointer->grab_x, pointer->grab_y, |
| 1878 | &from_x, &from_y); |
| 1879 | weston_view_from_global_fixed(shsurf->view, |
| 1880 | pointer->x, pointer->y, &to_x, &to_y); |
Kristian Høgsberg | 9e31bff | 2012-08-01 00:08:07 -0400 | [diff] [blame] | 1881 | |
| 1882 | width = resize->width; |
| 1883 | if (resize->edges & WL_SHELL_SURFACE_RESIZE_LEFT) { |
| 1884 | width += wl_fixed_to_int(from_x - to_x); |
| 1885 | } else if (resize->edges & WL_SHELL_SURFACE_RESIZE_RIGHT) { |
| 1886 | width += wl_fixed_to_int(to_x - from_x); |
| 1887 | } |
| 1888 | |
| 1889 | height = resize->height; |
| 1890 | if (resize->edges & WL_SHELL_SURFACE_RESIZE_TOP) { |
| 1891 | height += wl_fixed_to_int(from_y - to_y); |
| 1892 | } else if (resize->edges & WL_SHELL_SURFACE_RESIZE_BOTTOM) { |
| 1893 | height += wl_fixed_to_int(to_y - from_y); |
| 1894 | } |
| 1895 | |
Derek Foreman | 70ac0ed | 2015-03-18 11:16:33 -0500 | [diff] [blame] | 1896 | if (width < 1) |
| 1897 | width = 1; |
| 1898 | if (height < 1) |
| 1899 | height = 1; |
Jasper St. Pierre | ac985be | 2014-04-28 11:19:28 -0400 | [diff] [blame] | 1900 | shsurf->client->send_configure(shsurf->surface, width, height); |
Kristian Høgsberg | 9e31bff | 2012-08-01 00:08:07 -0400 | [diff] [blame] | 1901 | } |
| 1902 | |
| 1903 | static void |
Jasper St. Pierre | ac985be | 2014-04-28 11:19:28 -0400 | [diff] [blame] | 1904 | 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] | 1905 | { |
| 1906 | struct shell_surface *shsurf = get_shell_surface(surface); |
| 1907 | |
U. Artie Eoff | cf5737a | 2014-01-17 10:08:25 -0800 | [diff] [blame] | 1908 | assert(shsurf); |
| 1909 | |
Kristian Høgsberg | e0b9d5b | 2014-04-30 13:45:49 -0700 | [diff] [blame] | 1910 | if (shsurf->resource) |
| 1911 | wl_shell_surface_send_configure(shsurf->resource, |
Jasper St. Pierre | ac985be | 2014-04-28 11:19:28 -0400 | [diff] [blame] | 1912 | shsurf->resize_edges, |
| 1913 | width, height); |
Kristian Høgsberg | 9e31bff | 2012-08-01 00:08:07 -0400 | [diff] [blame] | 1914 | } |
| 1915 | |
| 1916 | static const struct weston_shell_client shell_client = { |
| 1917 | send_configure |
| 1918 | }; |
| 1919 | |
| 1920 | static void |
Kristian Høgsberg | 02bbabb | 2013-05-06 22:15:05 -0400 | [diff] [blame] | 1921 | resize_grab_button(struct weston_pointer_grab *grab, |
Kristian Høgsberg | 9e31bff | 2012-08-01 00:08:07 -0400 | [diff] [blame] | 1922 | uint32_t time, uint32_t button, uint32_t state_w) |
| 1923 | { |
| 1924 | struct weston_resize_grab *resize = (struct weston_resize_grab *) grab; |
Kristian Høgsberg | 02bbabb | 2013-05-06 22:15:05 -0400 | [diff] [blame] | 1925 | struct weston_pointer *pointer = grab->pointer; |
Kristian Høgsberg | 9e31bff | 2012-08-01 00:08:07 -0400 | [diff] [blame] | 1926 | enum wl_pointer_button_state state = state_w; |
| 1927 | |
| 1928 | if (pointer->button_count == 0 && |
| 1929 | state == WL_POINTER_BUTTON_STATE_RELEASED) { |
| 1930 | shell_grab_end(&resize->base); |
| 1931 | free(grab); |
| 1932 | } |
| 1933 | } |
| 1934 | |
Jonas Ådahl | 1ea343e | 2013-10-25 23:18:05 +0200 | [diff] [blame] | 1935 | static void |
| 1936 | resize_grab_cancel(struct weston_pointer_grab *grab) |
| 1937 | { |
| 1938 | struct weston_resize_grab *resize = (struct weston_resize_grab *) grab; |
| 1939 | |
| 1940 | shell_grab_end(&resize->base); |
| 1941 | free(grab); |
| 1942 | } |
| 1943 | |
Kristian Høgsberg | 02bbabb | 2013-05-06 22:15:05 -0400 | [diff] [blame] | 1944 | static const struct weston_pointer_grab_interface resize_grab_interface = { |
Kristian Høgsberg | 9e31bff | 2012-08-01 00:08:07 -0400 | [diff] [blame] | 1945 | noop_grab_focus, |
| 1946 | resize_grab_motion, |
| 1947 | resize_grab_button, |
Jonas Ådahl | 1ea343e | 2013-10-25 23:18:05 +0200 | [diff] [blame] | 1948 | resize_grab_cancel, |
Kristian Høgsberg | 9e31bff | 2012-08-01 00:08:07 -0400 | [diff] [blame] | 1949 | }; |
| 1950 | |
Giulio Camuffo | b836664 | 2013-04-25 13:57:46 +0300 | [diff] [blame] | 1951 | /* |
| 1952 | * Returns the bounding box of a surface and all its sub-surfaces, |
| 1953 | * in the surface coordinates system. */ |
| 1954 | static void |
| 1955 | surface_subsurfaces_boundingbox(struct weston_surface *surface, int32_t *x, |
| 1956 | int32_t *y, int32_t *w, int32_t *h) { |
| 1957 | pixman_region32_t region; |
| 1958 | pixman_box32_t *box; |
| 1959 | struct weston_subsurface *subsurface; |
| 1960 | |
| 1961 | pixman_region32_init_rect(®ion, 0, 0, |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 1962 | surface->width, |
| 1963 | surface->height); |
Giulio Camuffo | b836664 | 2013-04-25 13:57:46 +0300 | [diff] [blame] | 1964 | |
| 1965 | wl_list_for_each(subsurface, &surface->subsurface_list, parent_link) { |
| 1966 | pixman_region32_union_rect(®ion, ®ion, |
| 1967 | subsurface->position.x, |
| 1968 | subsurface->position.y, |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 1969 | subsurface->surface->width, |
| 1970 | subsurface->surface->height); |
Giulio Camuffo | b836664 | 2013-04-25 13:57:46 +0300 | [diff] [blame] | 1971 | } |
| 1972 | |
| 1973 | box = pixman_region32_extents(®ion); |
| 1974 | if (x) |
| 1975 | *x = box->x1; |
| 1976 | if (y) |
| 1977 | *y = box->y1; |
| 1978 | if (w) |
| 1979 | *w = box->x2 - box->x1; |
| 1980 | if (h) |
| 1981 | *h = box->y2 - box->y1; |
| 1982 | |
| 1983 | pixman_region32_fini(®ion); |
| 1984 | } |
| 1985 | |
Kristian Høgsberg | 9e31bff | 2012-08-01 00:08:07 -0400 | [diff] [blame] | 1986 | static int |
| 1987 | surface_resize(struct shell_surface *shsurf, |
Derek Foreman | 8fbebbd | 2015-07-15 13:00:40 -0500 | [diff] [blame] | 1988 | struct weston_pointer *pointer, uint32_t edges) |
Kristian Høgsberg | 9e31bff | 2012-08-01 00:08:07 -0400 | [diff] [blame] | 1989 | { |
| 1990 | struct weston_resize_grab *resize; |
Ondřej Majerech | ae9c4fc | 2014-08-21 15:47:22 +0200 | [diff] [blame] | 1991 | const unsigned resize_topbottom = |
| 1992 | WL_SHELL_SURFACE_RESIZE_TOP | WL_SHELL_SURFACE_RESIZE_BOTTOM; |
| 1993 | const unsigned resize_leftright = |
| 1994 | WL_SHELL_SURFACE_RESIZE_LEFT | WL_SHELL_SURFACE_RESIZE_RIGHT; |
| 1995 | const unsigned resize_any = resize_topbottom | resize_leftright; |
Kristian Høgsberg | 9e31bff | 2012-08-01 00:08:07 -0400 | [diff] [blame] | 1996 | |
Kristian Høgsberg | a4b620e | 2014-04-30 16:05:49 -0700 | [diff] [blame] | 1997 | if (shsurf->grabbed || |
| 1998 | shsurf->state.fullscreen || shsurf->state.maximized) |
Kristian Høgsberg | 9e31bff | 2012-08-01 00:08:07 -0400 | [diff] [blame] | 1999 | return 0; |
| 2000 | |
Ondřej Majerech | ae9c4fc | 2014-08-21 15:47:22 +0200 | [diff] [blame] | 2001 | /* Check for invalid edge combinations. */ |
| 2002 | if (edges == WL_SHELL_SURFACE_RESIZE_NONE || edges > resize_any || |
| 2003 | (edges & resize_topbottom) == resize_topbottom || |
| 2004 | (edges & resize_leftright) == resize_leftright) |
Kristian Høgsberg | 9e31bff | 2012-08-01 00:08:07 -0400 | [diff] [blame] | 2005 | return 0; |
| 2006 | |
| 2007 | resize = malloc(sizeof *resize); |
| 2008 | if (!resize) |
| 2009 | return -1; |
| 2010 | |
| 2011 | resize->edges = edges; |
Kristian Høgsberg | 9e31bff | 2012-08-01 00:08:07 -0400 | [diff] [blame] | 2012 | |
Jasper St. Pierre | ccf48fb | 2014-05-02 10:21:38 -0400 | [diff] [blame] | 2013 | resize->width = shsurf->geometry.width; |
| 2014 | resize->height = shsurf->geometry.height; |
Jasper St. Pierre | bd65e50 | 2014-07-14 16:28:48 -0400 | [diff] [blame] | 2015 | |
Kristian Høgsberg | 44cd196 | 2014-02-05 21:36:04 -0800 | [diff] [blame] | 2016 | shsurf->resize_edges = edges; |
Jasper St. Pierre | 5befdda | 2014-05-06 08:50:47 -0400 | [diff] [blame] | 2017 | shell_surface_state_changed(shsurf); |
Kristian Høgsberg | 9e31bff | 2012-08-01 00:08:07 -0400 | [diff] [blame] | 2018 | shell_grab_start(&resize->base, &resize_grab_interface, shsurf, |
Derek Foreman | 8fbebbd | 2015-07-15 13:00:40 -0500 | [diff] [blame] | 2019 | pointer, edges); |
Kristian Høgsberg | 9e31bff | 2012-08-01 00:08:07 -0400 | [diff] [blame] | 2020 | |
| 2021 | return 0; |
| 2022 | } |
| 2023 | |
| 2024 | static void |
Rafael Antognolli | e2a3455 | 2013-12-03 15:35:45 -0200 | [diff] [blame] | 2025 | common_surface_resize(struct wl_resource *resource, |
| 2026 | struct wl_resource *seat_resource, uint32_t serial, |
| 2027 | uint32_t edges) |
Kristian Høgsberg | 9e31bff | 2012-08-01 00:08:07 -0400 | [diff] [blame] | 2028 | { |
Jason Ekstrand | 44a3863 | 2013-06-14 10:08:00 -0500 | [diff] [blame] | 2029 | struct weston_seat *seat = wl_resource_get_user_data(seat_resource); |
Derek Foreman | 1281a36 | 2015-07-31 16:55:32 -0500 | [diff] [blame] | 2030 | struct weston_pointer *pointer = weston_seat_get_pointer(seat); |
Jason Ekstrand | 651f00e | 2013-06-14 10:07:54 -0500 | [diff] [blame] | 2031 | struct shell_surface *shsurf = wl_resource_get_user_data(resource); |
Giulio Camuffo | 61da3fc | 2013-04-25 13:57:45 +0300 | [diff] [blame] | 2032 | struct weston_surface *surface; |
Kristian Høgsberg | 9e31bff | 2012-08-01 00:08:07 -0400 | [diff] [blame] | 2033 | |
Derek Foreman | 1281a36 | 2015-07-31 16:55:32 -0500 | [diff] [blame] | 2034 | if (!pointer || |
| 2035 | pointer->button_count == 0 || |
| 2036 | pointer->grab_serial != serial || |
| 2037 | pointer->focus == NULL) |
Kristian Høgsberg | 70f2901 | 2014-01-09 15:43:17 -0800 | [diff] [blame] | 2038 | return; |
| 2039 | |
Derek Foreman | 1281a36 | 2015-07-31 16:55:32 -0500 | [diff] [blame] | 2040 | surface = weston_surface_get_main_surface(pointer->focus->surface); |
Kristian Høgsberg | 70f2901 | 2014-01-09 15:43:17 -0800 | [diff] [blame] | 2041 | if (surface != shsurf->surface) |
Kristian Høgsberg | 9e31bff | 2012-08-01 00:08:07 -0400 | [diff] [blame] | 2042 | return; |
| 2043 | |
Derek Foreman | 1281a36 | 2015-07-31 16:55:32 -0500 | [diff] [blame] | 2044 | if (surface_resize(shsurf, pointer, edges) < 0) |
Kristian Høgsberg | 9e31bff | 2012-08-01 00:08:07 -0400 | [diff] [blame] | 2045 | wl_resource_post_no_memory(resource); |
| 2046 | } |
| 2047 | |
Scott Moreau | c3e54eb | 2012-04-17 19:06:20 -0600 | [diff] [blame] | 2048 | static void |
Rafael Antognolli | e2a3455 | 2013-12-03 15:35:45 -0200 | [diff] [blame] | 2049 | shell_surface_resize(struct wl_client *client, struct wl_resource *resource, |
| 2050 | struct wl_resource *seat_resource, uint32_t serial, |
| 2051 | uint32_t edges) |
| 2052 | { |
| 2053 | common_surface_resize(resource, seat_resource, serial, edges); |
| 2054 | } |
| 2055 | |
| 2056 | static void |
Kristian Høgsberg | 6848c25 | 2013-05-08 22:02:59 -0400 | [diff] [blame] | 2057 | busy_cursor_grab_focus(struct weston_pointer_grab *base) |
Scott Moreau | c3e54eb | 2012-04-17 19:06:20 -0600 | [diff] [blame] | 2058 | { |
Kristian Høgsberg | d56bd90 | 2012-06-05 09:58:51 -0400 | [diff] [blame] | 2059 | struct shell_grab *grab = (struct shell_grab *) base; |
Kristian Høgsberg | 6848c25 | 2013-05-08 22:02:59 -0400 | [diff] [blame] | 2060 | struct weston_pointer *pointer = base->pointer; |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 2061 | struct weston_view *view; |
Kristian Høgsberg | 6848c25 | 2013-05-08 22:02:59 -0400 | [diff] [blame] | 2062 | wl_fixed_t sx, sy; |
| 2063 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 2064 | view = weston_compositor_pick_view(pointer->seat->compositor, |
| 2065 | pointer->x, pointer->y, |
| 2066 | &sx, &sy); |
Scott Moreau | c3e54eb | 2012-04-17 19:06:20 -0600 | [diff] [blame] | 2067 | |
Kristian Høgsberg | 2bff94e | 2014-02-11 12:22:51 -0800 | [diff] [blame] | 2068 | if (!grab->shsurf || grab->shsurf->surface != view->surface) { |
| 2069 | shell_grab_end(grab); |
| 2070 | free(grab); |
| 2071 | } |
Scott Moreau | c3e54eb | 2012-04-17 19:06:20 -0600 | [diff] [blame] | 2072 | } |
| 2073 | |
| 2074 | static void |
Giulio Camuffo | 1959ab8 | 2013-11-14 23:42:52 +0100 | [diff] [blame] | 2075 | busy_cursor_grab_motion(struct weston_pointer_grab *grab, uint32_t time, |
| 2076 | wl_fixed_t x, wl_fixed_t y) |
Scott Moreau | c3e54eb | 2012-04-17 19:06:20 -0600 | [diff] [blame] | 2077 | { |
Giulio Camuffo | 1959ab8 | 2013-11-14 23:42:52 +0100 | [diff] [blame] | 2078 | weston_pointer_move(grab->pointer, x, y); |
Kristian Høgsberg | d56bd90 | 2012-06-05 09:58:51 -0400 | [diff] [blame] | 2079 | } |
Scott Moreau | c3e54eb | 2012-04-17 19:06:20 -0600 | [diff] [blame] | 2080 | |
Kristian Høgsberg | d56bd90 | 2012-06-05 09:58:51 -0400 | [diff] [blame] | 2081 | static void |
Kristian Høgsberg | 02bbabb | 2013-05-06 22:15:05 -0400 | [diff] [blame] | 2082 | busy_cursor_grab_button(struct weston_pointer_grab *base, |
Kristian Høgsberg | d56bd90 | 2012-06-05 09:58:51 -0400 | [diff] [blame] | 2083 | uint32_t time, uint32_t button, uint32_t state) |
| 2084 | { |
Kristian Høgsberg | bbe9839 | 2012-08-01 00:20:21 -0400 | [diff] [blame] | 2085 | struct shell_grab *grab = (struct shell_grab *) base; |
Kristian Høgsberg | e122b7b | 2013-05-08 16:47:00 -0400 | [diff] [blame] | 2086 | struct shell_surface *shsurf = grab->shsurf; |
Derek Foreman | 794fa0e | 2015-07-15 13:00:38 -0500 | [diff] [blame] | 2087 | struct weston_pointer *pointer = grab->grab.pointer; |
| 2088 | struct weston_seat *seat = pointer->seat; |
Kristian Høgsberg | bbe9839 | 2012-08-01 00:20:21 -0400 | [diff] [blame] | 2089 | |
Kristian Høgsberg | bbe9839 | 2012-08-01 00:20:21 -0400 | [diff] [blame] | 2090 | if (shsurf && button == BTN_LEFT && state) { |
Emilio Pozuelo Monfort | 9e7c759 | 2014-01-30 14:01:10 +0100 | [diff] [blame] | 2091 | activate(shsurf->shell, shsurf->surface, seat, true); |
Derek Foreman | 794fa0e | 2015-07-15 13:00:38 -0500 | [diff] [blame] | 2092 | surface_move(shsurf, pointer, false); |
Kristian Høgsberg | 0c36903 | 2013-02-14 21:31:44 -0500 | [diff] [blame] | 2093 | } else if (shsurf && button == BTN_RIGHT && state) { |
Emilio Pozuelo Monfort | 9e7c759 | 2014-01-30 14:01:10 +0100 | [diff] [blame] | 2094 | activate(shsurf->shell, shsurf->surface, seat, true); |
Derek Foreman | 74de469 | 2015-07-15 13:00:39 -0500 | [diff] [blame] | 2095 | surface_rotate(shsurf, pointer); |
Kristian Høgsberg | bbe9839 | 2012-08-01 00:20:21 -0400 | [diff] [blame] | 2096 | } |
Kristian Høgsberg | d56bd90 | 2012-06-05 09:58:51 -0400 | [diff] [blame] | 2097 | } |
| 2098 | |
Jonas Ådahl | 1ea343e | 2013-10-25 23:18:05 +0200 | [diff] [blame] | 2099 | static void |
| 2100 | busy_cursor_grab_cancel(struct weston_pointer_grab *base) |
| 2101 | { |
| 2102 | struct shell_grab *grab = (struct shell_grab *) base; |
| 2103 | |
| 2104 | shell_grab_end(grab); |
| 2105 | free(grab); |
| 2106 | } |
| 2107 | |
Kristian Høgsberg | 02bbabb | 2013-05-06 22:15:05 -0400 | [diff] [blame] | 2108 | static const struct weston_pointer_grab_interface busy_cursor_grab_interface = { |
Kristian Høgsberg | d56bd90 | 2012-06-05 09:58:51 -0400 | [diff] [blame] | 2109 | busy_cursor_grab_focus, |
| 2110 | busy_cursor_grab_motion, |
| 2111 | busy_cursor_grab_button, |
Jonas Ådahl | 1ea343e | 2013-10-25 23:18:05 +0200 | [diff] [blame] | 2112 | busy_cursor_grab_cancel, |
Kristian Høgsberg | d56bd90 | 2012-06-05 09:58:51 -0400 | [diff] [blame] | 2113 | }; |
| 2114 | |
| 2115 | static void |
Kristian Høgsberg | 02bbabb | 2013-05-06 22:15:05 -0400 | [diff] [blame] | 2116 | set_busy_cursor(struct shell_surface *shsurf, struct weston_pointer *pointer) |
Kristian Høgsberg | d56bd90 | 2012-06-05 09:58:51 -0400 | [diff] [blame] | 2117 | { |
| 2118 | struct shell_grab *grab; |
Kristian Høgsberg | d56bd90 | 2012-06-05 09:58:51 -0400 | [diff] [blame] | 2119 | |
Kristian Høgsberg | 2bff94e | 2014-02-11 12:22:51 -0800 | [diff] [blame] | 2120 | if (pointer->grab->interface == &busy_cursor_grab_interface) |
| 2121 | return; |
| 2122 | |
Kristian Høgsberg | d56bd90 | 2012-06-05 09:58:51 -0400 | [diff] [blame] | 2123 | grab = malloc(sizeof *grab); |
| 2124 | if (!grab) |
Scott Moreau | c3e54eb | 2012-04-17 19:06:20 -0600 | [diff] [blame] | 2125 | return; |
| 2126 | |
Ander Conselvan de Oliveira | b9d2a0f | 2012-06-28 18:08:05 +0300 | [diff] [blame] | 2127 | shell_grab_start(grab, &busy_cursor_grab_interface, shsurf, pointer, |
| 2128 | DESKTOP_SHELL_CURSOR_BUSY); |
Ander Conselvan de Oliveira | e5a1aee | 2014-04-09 17:39:39 +0300 | [diff] [blame] | 2129 | /* Mark the shsurf as ungrabbed so that button binding is able |
| 2130 | * to move it. */ |
| 2131 | shsurf->grabbed = 0; |
Kristian Høgsberg | d56bd90 | 2012-06-05 09:58:51 -0400 | [diff] [blame] | 2132 | } |
Scott Moreau | c3e54eb | 2012-04-17 19:06:20 -0600 | [diff] [blame] | 2133 | |
Kristian Høgsberg | d56bd90 | 2012-06-05 09:58:51 -0400 | [diff] [blame] | 2134 | static void |
Kristian Høgsberg | 2bff94e | 2014-02-11 12:22:51 -0800 | [diff] [blame] | 2135 | end_busy_cursor(struct weston_compositor *compositor, struct wl_client *client) |
Kristian Høgsberg | d56bd90 | 2012-06-05 09:58:51 -0400 | [diff] [blame] | 2136 | { |
Kristian Høgsberg | 2bff94e | 2014-02-11 12:22:51 -0800 | [diff] [blame] | 2137 | struct shell_grab *grab; |
| 2138 | struct weston_seat *seat; |
Kristian Høgsberg | d56bd90 | 2012-06-05 09:58:51 -0400 | [diff] [blame] | 2139 | |
Kristian Høgsberg | 2bff94e | 2014-02-11 12:22:51 -0800 | [diff] [blame] | 2140 | wl_list_for_each(seat, &compositor->seat_list, link) { |
Derek Foreman | 1281a36 | 2015-07-31 16:55:32 -0500 | [diff] [blame] | 2141 | struct weston_pointer *pointer = weston_seat_get_pointer(seat); |
| 2142 | |
| 2143 | if (!pointer) |
Kristian Høgsberg | 2bff94e | 2014-02-11 12:22:51 -0800 | [diff] [blame] | 2144 | continue; |
| 2145 | |
Derek Foreman | 1281a36 | 2015-07-31 16:55:32 -0500 | [diff] [blame] | 2146 | grab = (struct shell_grab *) pointer->grab; |
Kristian Høgsberg | 2bff94e | 2014-02-11 12:22:51 -0800 | [diff] [blame] | 2147 | if (grab->grab.interface == &busy_cursor_grab_interface && |
Derek Foreman | c0c1497 | 2015-09-11 14:30:39 -0500 | [diff] [blame] | 2148 | grab->shsurf->resource && |
Kristian Høgsberg | 2bff94e | 2014-02-11 12:22:51 -0800 | [diff] [blame] | 2149 | wl_resource_get_client(grab->shsurf->resource) == client) { |
| 2150 | shell_grab_end(grab); |
| 2151 | free(grab); |
| 2152 | } |
Scott Moreau | c3e54eb | 2012-04-17 19:06:20 -0600 | [diff] [blame] | 2153 | } |
Scott Moreau | c3e54eb | 2012-04-17 19:06:20 -0600 | [diff] [blame] | 2154 | } |
| 2155 | |
Scott Moreau | 9521d5e | 2012-04-19 13:06:17 -0600 | [diff] [blame] | 2156 | static void |
Kristian Høgsberg | 2bff94e | 2014-02-11 12:22:51 -0800 | [diff] [blame] | 2157 | handle_shell_client_destroy(struct wl_listener *listener, void *data); |
| 2158 | |
| 2159 | static int |
| 2160 | xdg_ping_timeout_handler(void *data) |
| 2161 | { |
| 2162 | struct shell_client *sc = data; |
| 2163 | struct weston_seat *seat; |
| 2164 | struct shell_surface *shsurf; |
| 2165 | |
| 2166 | /* Client is not responding */ |
| 2167 | sc->unresponsive = 1; |
Kristian Høgsberg | 2bff94e | 2014-02-11 12:22:51 -0800 | [diff] [blame] | 2168 | wl_list_for_each(seat, &sc->shell->compositor->seat_list, link) { |
Derek Foreman | 1281a36 | 2015-07-31 16:55:32 -0500 | [diff] [blame] | 2169 | struct weston_pointer *pointer = weston_seat_get_pointer(seat); |
| 2170 | |
| 2171 | if (!pointer || |
| 2172 | !pointer->focus || |
| 2173 | !pointer->focus->surface->resource) |
Kristian Høgsberg | 2bff94e | 2014-02-11 12:22:51 -0800 | [diff] [blame] | 2174 | continue; |
Michael Vetter | 2a18a52 | 2015-05-15 17:17:47 +0200 | [diff] [blame] | 2175 | |
Derek Foreman | 1281a36 | 2015-07-31 16:55:32 -0500 | [diff] [blame] | 2176 | shsurf = get_shell_surface(pointer->focus->surface); |
Kristian Høgsberg | 2bff94e | 2014-02-11 12:22:51 -0800 | [diff] [blame] | 2177 | if (shsurf && |
| 2178 | wl_resource_get_client(shsurf->resource) == sc->client) |
Derek Foreman | 1281a36 | 2015-07-31 16:55:32 -0500 | [diff] [blame] | 2179 | set_busy_cursor(shsurf, pointer); |
Kristian Høgsberg | 2bff94e | 2014-02-11 12:22:51 -0800 | [diff] [blame] | 2180 | } |
| 2181 | |
| 2182 | return 1; |
| 2183 | } |
| 2184 | |
| 2185 | static void |
| 2186 | handle_xdg_ping(struct shell_surface *shsurf, uint32_t serial) |
| 2187 | { |
| 2188 | struct weston_compositor *compositor = shsurf->shell->compositor; |
Jason Ekstrand | 9e9512f | 2014-04-16 21:12:10 -0500 | [diff] [blame] | 2189 | struct shell_client *sc = shsurf->owner; |
Kristian Høgsberg | 2bff94e | 2014-02-11 12:22:51 -0800 | [diff] [blame] | 2190 | struct wl_event_loop *loop; |
Kristian Høgsberg | dd62aba | 2014-02-12 09:56:19 -0800 | [diff] [blame] | 2191 | static const int ping_timeout = 200; |
Kristian Høgsberg | 2bff94e | 2014-02-11 12:22:51 -0800 | [diff] [blame] | 2192 | |
Kristian Høgsberg | 2bff94e | 2014-02-11 12:22:51 -0800 | [diff] [blame] | 2193 | if (sc->unresponsive) { |
| 2194 | xdg_ping_timeout_handler(sc); |
| 2195 | return; |
| 2196 | } |
| 2197 | |
| 2198 | sc->ping_serial = serial; |
| 2199 | loop = wl_display_get_event_loop(compositor->wl_display); |
| 2200 | if (sc->ping_timer == NULL) |
| 2201 | sc->ping_timer = |
| 2202 | wl_event_loop_add_timer(loop, |
| 2203 | xdg_ping_timeout_handler, sc); |
| 2204 | if (sc->ping_timer == NULL) |
| 2205 | return; |
| 2206 | |
| 2207 | wl_event_source_timer_update(sc->ping_timer, ping_timeout); |
| 2208 | |
Kristian Høgsberg | dd62aba | 2014-02-12 09:56:19 -0800 | [diff] [blame] | 2209 | if (shell_surface_is_xdg_surface(shsurf) || |
| 2210 | shell_surface_is_xdg_popup(shsurf)) |
| 2211 | xdg_shell_send_ping(sc->resource, serial); |
| 2212 | else if (shell_surface_is_wl_shell_surface(shsurf)) |
| 2213 | wl_shell_surface_send_ping(shsurf->resource, serial); |
Kristian Høgsberg | 2bff94e | 2014-02-11 12:22:51 -0800 | [diff] [blame] | 2214 | } |
| 2215 | |
Scott Moreau | ff1db4a | 2012-04-17 19:06:18 -0600 | [diff] [blame] | 2216 | static void |
| 2217 | ping_handler(struct weston_surface *surface, uint32_t serial) |
| 2218 | { |
Kristian Høgsberg | b71302e | 2012-05-10 12:28:35 -0400 | [diff] [blame] | 2219 | struct shell_surface *shsurf = get_shell_surface(surface); |
Scott Moreau | ff1db4a | 2012-04-17 19:06:18 -0600 | [diff] [blame] | 2220 | |
| 2221 | if (!shsurf) |
| 2222 | return; |
Jason Ekstrand | 651f00e | 2013-06-14 10:07:54 -0500 | [diff] [blame] | 2223 | if (!shsurf->resource) |
Kristian Høgsberg | ca535c1 | 2012-04-21 23:20:07 -0400 | [diff] [blame] | 2224 | return; |
Ander Conselvan de Oliveira | eac9a46 | 2012-07-16 14:15:48 +0300 | [diff] [blame] | 2225 | if (shsurf->surface == shsurf->shell->grab_surface) |
| 2226 | return; |
| 2227 | |
Kristian Høgsberg | dd62aba | 2014-02-12 09:56:19 -0800 | [diff] [blame] | 2228 | handle_xdg_ping(shsurf, serial); |
Scott Moreau | ff1db4a | 2012-04-17 19:06:18 -0600 | [diff] [blame] | 2229 | } |
| 2230 | |
| 2231 | static void |
Kristian Høgsberg | d56bd90 | 2012-06-05 09:58:51 -0400 | [diff] [blame] | 2232 | handle_pointer_focus(struct wl_listener *listener, void *data) |
| 2233 | { |
Kristian Høgsberg | 02bbabb | 2013-05-06 22:15:05 -0400 | [diff] [blame] | 2234 | struct weston_pointer *pointer = data; |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 2235 | struct weston_view *view = pointer->focus; |
Kristian Høgsberg | d56bd90 | 2012-06-05 09:58:51 -0400 | [diff] [blame] | 2236 | struct weston_compositor *compositor; |
Kristian Høgsberg | d56bd90 | 2012-06-05 09:58:51 -0400 | [diff] [blame] | 2237 | uint32_t serial; |
| 2238 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 2239 | if (!view) |
Kristian Høgsberg | d56bd90 | 2012-06-05 09:58:51 -0400 | [diff] [blame] | 2240 | return; |
| 2241 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 2242 | compositor = view->surface->compositor; |
Kristian Høgsberg | e11ef64 | 2014-02-11 16:35:22 -0800 | [diff] [blame] | 2243 | serial = wl_display_next_serial(compositor->wl_display); |
| 2244 | ping_handler(view->surface, serial); |
Kristian Høgsberg | d56bd90 | 2012-06-05 09:58:51 -0400 | [diff] [blame] | 2245 | } |
| 2246 | |
| 2247 | static void |
Jasper St. Pierre | faf27a9 | 2013-12-09 17:36:28 -0500 | [diff] [blame] | 2248 | shell_surface_lose_keyboard_focus(struct shell_surface *shsurf) |
| 2249 | { |
| 2250 | if (--shsurf->focus_count == 0) |
Jasper St. Pierre | 973d787 | 2014-05-06 08:44:29 -0400 | [diff] [blame] | 2251 | shell_surface_state_changed(shsurf); |
Jasper St. Pierre | faf27a9 | 2013-12-09 17:36:28 -0500 | [diff] [blame] | 2252 | } |
| 2253 | |
| 2254 | static void |
| 2255 | shell_surface_gain_keyboard_focus(struct shell_surface *shsurf) |
| 2256 | { |
| 2257 | if (shsurf->focus_count++ == 0) |
Jasper St. Pierre | 973d787 | 2014-05-06 08:44:29 -0400 | [diff] [blame] | 2258 | shell_surface_state_changed(shsurf); |
Jasper St. Pierre | faf27a9 | 2013-12-09 17:36:28 -0500 | [diff] [blame] | 2259 | } |
| 2260 | |
| 2261 | static void |
| 2262 | handle_keyboard_focus(struct wl_listener *listener, void *data) |
| 2263 | { |
| 2264 | struct weston_keyboard *keyboard = data; |
| 2265 | struct shell_seat *seat = get_shell_seat(keyboard->seat); |
| 2266 | |
| 2267 | if (seat->focused_surface) { |
| 2268 | struct shell_surface *shsurf = get_shell_surface(seat->focused_surface); |
| 2269 | if (shsurf) |
| 2270 | shell_surface_lose_keyboard_focus(shsurf); |
| 2271 | } |
| 2272 | |
| 2273 | seat->focused_surface = keyboard->focus; |
| 2274 | |
| 2275 | if (seat->focused_surface) { |
| 2276 | struct shell_surface *shsurf = get_shell_surface(seat->focused_surface); |
| 2277 | if (shsurf) |
| 2278 | shell_surface_gain_keyboard_focus(shsurf); |
| 2279 | } |
| 2280 | } |
| 2281 | |
| 2282 | static void |
Kristian Høgsberg | dd62aba | 2014-02-12 09:56:19 -0800 | [diff] [blame] | 2283 | shell_client_pong(struct shell_client *sc, uint32_t serial) |
Rafael Antognolli | e2a3455 | 2013-12-03 15:35:45 -0200 | [diff] [blame] | 2284 | { |
Kristian Høgsberg | dd62aba | 2014-02-12 09:56:19 -0800 | [diff] [blame] | 2285 | if (sc->ping_serial != serial) |
| 2286 | return; |
Rafael Antognolli | e2a3455 | 2013-12-03 15:35:45 -0200 | [diff] [blame] | 2287 | |
Kristian Høgsberg | dd62aba | 2014-02-12 09:56:19 -0800 | [diff] [blame] | 2288 | sc->unresponsive = 0; |
| 2289 | end_busy_cursor(sc->shell->compositor, sc->client); |
Rafael Antognolli | e2a3455 | 2013-12-03 15:35:45 -0200 | [diff] [blame] | 2290 | |
Kristian Høgsberg | dd62aba | 2014-02-12 09:56:19 -0800 | [diff] [blame] | 2291 | if (sc->ping_timer) { |
| 2292 | wl_event_source_remove(sc->ping_timer); |
| 2293 | sc->ping_timer = NULL; |
| 2294 | } |
| 2295 | |
| 2296 | } |
| 2297 | |
| 2298 | static void |
| 2299 | shell_surface_pong(struct wl_client *client, |
| 2300 | struct wl_resource *resource, uint32_t serial) |
| 2301 | { |
Jason Ekstrand | 9e9512f | 2014-04-16 21:12:10 -0500 | [diff] [blame] | 2302 | struct shell_surface *shsurf = wl_resource_get_user_data(resource); |
| 2303 | struct shell_client *sc = shsurf->owner; |
Kristian Høgsberg | dd62aba | 2014-02-12 09:56:19 -0800 | [diff] [blame] | 2304 | |
Kristian Høgsberg | dd62aba | 2014-02-12 09:56:19 -0800 | [diff] [blame] | 2305 | shell_client_pong(sc, serial); |
Rafael Antognolli | e2a3455 | 2013-12-03 15:35:45 -0200 | [diff] [blame] | 2306 | } |
| 2307 | |
| 2308 | static void |
Giulio Camuffo | 62942ad | 2013-09-11 18:20:47 +0200 | [diff] [blame] | 2309 | set_title(struct shell_surface *shsurf, const char *title) |
| 2310 | { |
| 2311 | free(shsurf->title); |
| 2312 | shsurf->title = strdup(title); |
Pekka Paalanen | b502654 | 2014-11-12 15:09:24 +0200 | [diff] [blame] | 2313 | shsurf->surface->timeline.force_refresh = 1; |
| 2314 | } |
| 2315 | |
| 2316 | static void |
Giulio Camuffo | a8e9b41 | 2015-01-27 19:10:37 +0200 | [diff] [blame] | 2317 | set_pid(struct shell_surface *shsurf, pid_t pid) |
| 2318 | { |
| 2319 | /* We have no use for it */ |
| 2320 | } |
| 2321 | |
| 2322 | static void |
Pekka Paalanen | b502654 | 2014-11-12 15:09:24 +0200 | [diff] [blame] | 2323 | set_type(struct shell_surface *shsurf, enum shell_surface_type t) |
| 2324 | { |
| 2325 | shsurf->type = t; |
| 2326 | shsurf->surface->timeline.force_refresh = 1; |
Giulio Camuffo | 62942ad | 2013-09-11 18:20:47 +0200 | [diff] [blame] | 2327 | } |
| 2328 | |
| 2329 | static void |
Jasper St. Pierre | ccf48fb | 2014-05-02 10:21:38 -0400 | [diff] [blame] | 2330 | set_window_geometry(struct shell_surface *shsurf, |
| 2331 | 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] | 2332 | { |
Jasper St. Pierre | ccf48fb | 2014-05-02 10:21:38 -0400 | [diff] [blame] | 2333 | shsurf->next_geometry.x = x; |
| 2334 | shsurf->next_geometry.y = y; |
| 2335 | shsurf->next_geometry.width = width; |
| 2336 | shsurf->next_geometry.height = height; |
| 2337 | shsurf->has_next_geometry = true; |
Kristian Høgsberg | e5c1ae9 | 2014-04-30 16:28:41 -0700 | [diff] [blame] | 2338 | } |
| 2339 | |
| 2340 | static void |
Kristian Høgsberg | e7afd91 | 2012-05-02 09:47:44 -0400 | [diff] [blame] | 2341 | shell_surface_set_title(struct wl_client *client, |
| 2342 | struct wl_resource *resource, const char *title) |
| 2343 | { |
Jason Ekstrand | 651f00e | 2013-06-14 10:07:54 -0500 | [diff] [blame] | 2344 | struct shell_surface *shsurf = wl_resource_get_user_data(resource); |
Kristian Høgsberg | e7afd91 | 2012-05-02 09:47:44 -0400 | [diff] [blame] | 2345 | |
Giulio Camuffo | 62942ad | 2013-09-11 18:20:47 +0200 | [diff] [blame] | 2346 | set_title(shsurf, title); |
Kristian Høgsberg | e7afd91 | 2012-05-02 09:47:44 -0400 | [diff] [blame] | 2347 | } |
| 2348 | |
| 2349 | static void |
| 2350 | shell_surface_set_class(struct wl_client *client, |
| 2351 | struct wl_resource *resource, const char *class) |
| 2352 | { |
Jason Ekstrand | 651f00e | 2013-06-14 10:07:54 -0500 | [diff] [blame] | 2353 | struct shell_surface *shsurf = wl_resource_get_user_data(resource); |
Kristian Høgsberg | e7afd91 | 2012-05-02 09:47:44 -0400 | [diff] [blame] | 2354 | |
| 2355 | free(shsurf->class); |
| 2356 | shsurf->class = strdup(class); |
Pekka Paalanen | b502654 | 2014-11-12 15:09:24 +0200 | [diff] [blame] | 2357 | shsurf->surface->timeline.force_refresh = 1; |
Kristian Høgsberg | e7afd91 | 2012-05-02 09:47:44 -0400 | [diff] [blame] | 2358 | } |
| 2359 | |
Alex Wu | 4539b08 | 2012-03-01 12:57:46 +0800 | [diff] [blame] | 2360 | static void |
Alexander Larsson | f82b6ca | 2013-05-28 16:23:39 +0200 | [diff] [blame] | 2361 | restore_output_mode(struct weston_output *output) |
| 2362 | { |
Derek Foreman | 6ae7bc9 | 2014-11-04 10:47:33 -0600 | [diff] [blame] | 2363 | if (output->original_mode) |
| 2364 | weston_output_mode_switch_to_native(output); |
Alexander Larsson | f82b6ca | 2013-05-28 16:23:39 +0200 | [diff] [blame] | 2365 | } |
| 2366 | |
| 2367 | static void |
| 2368 | restore_all_output_modes(struct weston_compositor *compositor) |
| 2369 | { |
| 2370 | struct weston_output *output; |
| 2371 | |
| 2372 | wl_list_for_each(output, &compositor->output_list, link) |
| 2373 | restore_output_mode(output); |
| 2374 | } |
| 2375 | |
Philip Withnall | 07926d9 | 2013-11-25 18:01:40 +0000 | [diff] [blame] | 2376 | /* The surface will be inserted into the list immediately after the link |
| 2377 | * returned by this function (i.e. will be stacked immediately above the |
| 2378 | * returned link). */ |
Giulio Camuffo | 412e6a5 | 2014-07-09 22:12:56 +0300 | [diff] [blame] | 2379 | static struct weston_layer_entry * |
Philip Withnall | 07926d9 | 2013-11-25 18:01:40 +0000 | [diff] [blame] | 2380 | shell_surface_calculate_layer_link (struct shell_surface *shsurf) |
| 2381 | { |
| 2382 | struct workspace *ws; |
Kristian Høgsberg | ead5242 | 2014-01-01 13:51:52 -0800 | [diff] [blame] | 2383 | struct weston_view *parent; |
Philip Withnall | 07926d9 | 2013-11-25 18:01:40 +0000 | [diff] [blame] | 2384 | |
| 2385 | switch (shsurf->type) { |
Ander Conselvan de Oliveira | ef6a7e4 | 2014-04-30 14:15:14 +0300 | [diff] [blame] | 2386 | case SHELL_SURFACE_XWAYLAND: |
| 2387 | return &shsurf->shell->fullscreen_layer.view_list; |
| 2388 | |
| 2389 | case SHELL_SURFACE_NONE: |
| 2390 | return NULL; |
| 2391 | |
Kristian Høgsberg | ead5242 | 2014-01-01 13:51:52 -0800 | [diff] [blame] | 2392 | case SHELL_SURFACE_POPUP: |
| 2393 | case SHELL_SURFACE_TOPLEVEL: |
Emilio Pozuelo Monfort | 9e7c759 | 2014-01-30 14:01:10 +0100 | [diff] [blame] | 2394 | if (shsurf->state.fullscreen && !shsurf->state.lowered) { |
Rafael Antognolli | 03b1659 | 2013-12-03 15:35:42 -0200 | [diff] [blame] | 2395 | return &shsurf->shell->fullscreen_layer.view_list; |
Rafael Antognolli | ed207b4 | 2013-12-03 15:35:43 -0200 | [diff] [blame] | 2396 | } else if (shsurf->parent) { |
Kristian Høgsberg | d55db69 | 2014-01-01 12:26:14 -0800 | [diff] [blame] | 2397 | /* Move the surface to its parent layer so |
| 2398 | * that surfaces which are transient for |
| 2399 | * fullscreen surfaces don't get hidden by the |
| 2400 | * fullscreen surfaces. */ |
Rafael Antognolli | ed207b4 | 2013-12-03 15:35:43 -0200 | [diff] [blame] | 2401 | |
| 2402 | /* TODO: Handle a parent with multiple views */ |
| 2403 | parent = get_default_view(shsurf->parent); |
| 2404 | if (parent) |
Giulio Camuffo | 412e6a5 | 2014-07-09 22:12:56 +0300 | [diff] [blame] | 2405 | return container_of(parent->layer_link.link.prev, |
| 2406 | struct weston_layer_entry, link); |
Rafael Antognolli | ed207b4 | 2013-12-03 15:35:43 -0200 | [diff] [blame] | 2407 | } |
Philip Withnall | 07926d9 | 2013-11-25 18:01:40 +0000 | [diff] [blame] | 2408 | |
Ander Conselvan de Oliveira | ef6a7e4 | 2014-04-30 14:15:14 +0300 | [diff] [blame] | 2409 | /* Move the surface to a normal workspace layer so that surfaces |
| 2410 | * which were previously fullscreen or transient are no longer |
| 2411 | * rendered on top. */ |
| 2412 | ws = get_current_workspace(shsurf->shell); |
| 2413 | return &ws->layer.view_list; |
Philip Withnall | 07926d9 | 2013-11-25 18:01:40 +0000 | [diff] [blame] | 2414 | } |
| 2415 | |
Ander Conselvan de Oliveira | ef6a7e4 | 2014-04-30 14:15:14 +0300 | [diff] [blame] | 2416 | assert(0 && "Unknown shell surface type"); |
Philip Withnall | 07926d9 | 2013-11-25 18:01:40 +0000 | [diff] [blame] | 2417 | } |
| 2418 | |
Philip Withnall | 648a4dd | 2013-11-25 18:01:44 +0000 | [diff] [blame] | 2419 | static void |
| 2420 | shell_surface_update_child_surface_layers (struct shell_surface *shsurf) |
| 2421 | { |
| 2422 | struct shell_surface *child; |
Giulio Camuffo | 412e6a5 | 2014-07-09 22:12:56 +0300 | [diff] [blame] | 2423 | struct weston_layer_entry *prev; |
Philip Withnall | 648a4dd | 2013-11-25 18:01:44 +0000 | [diff] [blame] | 2424 | |
| 2425 | /* Move the child layers to the same workspace as shsurf. They will be |
| 2426 | * stacked above shsurf. */ |
| 2427 | wl_list_for_each_reverse(child, &shsurf->children_list, children_link) { |
Giulio Camuffo | 412e6a5 | 2014-07-09 22:12:56 +0300 | [diff] [blame] | 2428 | 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] | 2429 | weston_view_damage_below(child->view); |
Philip Withnall | 648a4dd | 2013-11-25 18:01:44 +0000 | [diff] [blame] | 2430 | weston_view_geometry_dirty(child->view); |
Giulio Camuffo | 412e6a5 | 2014-07-09 22:12:56 +0300 | [diff] [blame] | 2431 | prev = container_of(shsurf->view->layer_link.link.prev, |
| 2432 | struct weston_layer_entry, link); |
| 2433 | weston_layer_entry_remove(&child->view->layer_link); |
| 2434 | weston_layer_entry_insert(prev, |
| 2435 | &child->view->layer_link); |
Philip Withnall | 648a4dd | 2013-11-25 18:01:44 +0000 | [diff] [blame] | 2436 | weston_view_geometry_dirty(child->view); |
| 2437 | weston_surface_damage(child->surface); |
| 2438 | |
| 2439 | /* Recurse. We don’t expect this to recurse very far (if |
| 2440 | * at all) because that would imply we have transient |
| 2441 | * (or popup) children of transient surfaces, which |
| 2442 | * would be unusual. */ |
| 2443 | shell_surface_update_child_surface_layers(child); |
| 2444 | } |
| 2445 | } |
| 2446 | } |
| 2447 | |
Philip Withnall | e1d75ae | 2013-11-25 18:01:41 +0000 | [diff] [blame] | 2448 | /* 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] | 2449 | * geometry to ensure the changes are redrawn. |
| 2450 | * |
| 2451 | * If any child surfaces exist and are mapped, ensure they’re in the same layer |
| 2452 | * as this surface. */ |
Philip Withnall | e1d75ae | 2013-11-25 18:01:41 +0000 | [diff] [blame] | 2453 | static void |
| 2454 | shell_surface_update_layer(struct shell_surface *shsurf) |
| 2455 | { |
Giulio Camuffo | 412e6a5 | 2014-07-09 22:12:56 +0300 | [diff] [blame] | 2456 | struct weston_layer_entry *new_layer_link; |
Philip Withnall | e1d75ae | 2013-11-25 18:01:41 +0000 | [diff] [blame] | 2457 | |
| 2458 | new_layer_link = shell_surface_calculate_layer_link(shsurf); |
| 2459 | |
Ander Conselvan de Oliveira | ef6a7e4 | 2014-04-30 14:15:14 +0300 | [diff] [blame] | 2460 | if (new_layer_link == NULL) |
| 2461 | return; |
Philip Withnall | e1d75ae | 2013-11-25 18:01:41 +0000 | [diff] [blame] | 2462 | if (new_layer_link == &shsurf->view->layer_link) |
| 2463 | return; |
| 2464 | |
| 2465 | weston_view_geometry_dirty(shsurf->view); |
Giulio Camuffo | 412e6a5 | 2014-07-09 22:12:56 +0300 | [diff] [blame] | 2466 | weston_layer_entry_remove(&shsurf->view->layer_link); |
| 2467 | weston_layer_entry_insert(new_layer_link, &shsurf->view->layer_link); |
Philip Withnall | e1d75ae | 2013-11-25 18:01:41 +0000 | [diff] [blame] | 2468 | weston_view_geometry_dirty(shsurf->view); |
| 2469 | weston_surface_damage(shsurf->surface); |
Philip Withnall | 648a4dd | 2013-11-25 18:01:44 +0000 | [diff] [blame] | 2470 | |
| 2471 | shell_surface_update_child_surface_layers(shsurf); |
Philip Withnall | e1d75ae | 2013-11-25 18:01:41 +0000 | [diff] [blame] | 2472 | } |
| 2473 | |
Alexander Larsson | f82b6ca | 2013-05-28 16:23:39 +0200 | [diff] [blame] | 2474 | static void |
Philip Withnall | dc4332f | 2013-11-25 18:01:38 +0000 | [diff] [blame] | 2475 | shell_surface_set_parent(struct shell_surface *shsurf, |
| 2476 | struct weston_surface *parent) |
| 2477 | { |
| 2478 | shsurf->parent = parent; |
Philip Withnall | 648a4dd | 2013-11-25 18:01:44 +0000 | [diff] [blame] | 2479 | |
| 2480 | wl_list_remove(&shsurf->children_link); |
| 2481 | wl_list_init(&shsurf->children_link); |
| 2482 | |
| 2483 | /* Insert into the parent surface’s child list. */ |
| 2484 | if (parent != NULL) { |
| 2485 | struct shell_surface *parent_shsurf = get_shell_surface(parent); |
| 2486 | if (parent_shsurf != NULL) |
| 2487 | wl_list_insert(&parent_shsurf->children_list, |
| 2488 | &shsurf->children_link); |
| 2489 | } |
Philip Withnall | dc4332f | 2013-11-25 18:01:38 +0000 | [diff] [blame] | 2490 | } |
| 2491 | |
| 2492 | static void |
Philip Withnall | 352e7ed | 2013-11-25 18:01:35 +0000 | [diff] [blame] | 2493 | shell_surface_set_output(struct shell_surface *shsurf, |
| 2494 | struct weston_output *output) |
| 2495 | { |
| 2496 | struct weston_surface *es = shsurf->surface; |
| 2497 | |
| 2498 | /* get the default output, if the client set it as NULL |
| 2499 | check whether the ouput is available */ |
| 2500 | if (output) |
| 2501 | shsurf->output = output; |
| 2502 | else if (es->output) |
| 2503 | shsurf->output = es->output; |
| 2504 | else |
| 2505 | shsurf->output = get_default_output(es->compositor); |
| 2506 | } |
| 2507 | |
| 2508 | static void |
Rafael Antognolli | 03b1659 | 2013-12-03 15:35:42 -0200 | [diff] [blame] | 2509 | surface_clear_next_states(struct shell_surface *shsurf) |
| 2510 | { |
| 2511 | shsurf->next_state.maximized = false; |
| 2512 | shsurf->next_state.fullscreen = false; |
| 2513 | |
| 2514 | if ((shsurf->next_state.maximized != shsurf->state.maximized) || |
| 2515 | (shsurf->next_state.fullscreen != shsurf->state.fullscreen)) |
| 2516 | shsurf->state_changed = true; |
| 2517 | } |
| 2518 | |
| 2519 | static void |
Philip Withnall | becb77e | 2013-11-25 18:01:30 +0000 | [diff] [blame] | 2520 | set_toplevel(struct shell_surface *shsurf) |
| 2521 | { |
Kristian Høgsberg | 41fbf6f | 2013-12-05 22:31:25 -0800 | [diff] [blame] | 2522 | shell_surface_set_parent(shsurf, NULL); |
| 2523 | surface_clear_next_states(shsurf); |
Pekka Paalanen | b502654 | 2014-11-12 15:09:24 +0200 | [diff] [blame] | 2524 | set_type(shsurf, SHELL_SURFACE_TOPLEVEL); |
Philip Withnall | 648a4dd | 2013-11-25 18:01:44 +0000 | [diff] [blame] | 2525 | |
| 2526 | /* The layer_link is updated in set_surface_type(), |
| 2527 | * called from configure. */ |
Philip Withnall | becb77e | 2013-11-25 18:01:30 +0000 | [diff] [blame] | 2528 | } |
| 2529 | |
| 2530 | static void |
| 2531 | shell_surface_set_toplevel(struct wl_client *client, |
| 2532 | struct wl_resource *resource) |
| 2533 | { |
| 2534 | struct shell_surface *surface = wl_resource_get_user_data(resource); |
| 2535 | |
| 2536 | set_toplevel(surface); |
| 2537 | } |
| 2538 | |
| 2539 | static void |
| 2540 | set_transient(struct shell_surface *shsurf, |
| 2541 | struct weston_surface *parent, int x, int y, uint32_t flags) |
| 2542 | { |
Philip Withnall | dc4332f | 2013-11-25 18:01:38 +0000 | [diff] [blame] | 2543 | assert(parent != NULL); |
| 2544 | |
Kristian Høgsberg | 9f7e331 | 2014-01-02 22:40:37 -0800 | [diff] [blame] | 2545 | shell_surface_set_parent(shsurf, parent); |
| 2546 | |
| 2547 | surface_clear_next_states(shsurf); |
| 2548 | |
Philip Withnall | becb77e | 2013-11-25 18:01:30 +0000 | [diff] [blame] | 2549 | shsurf->transient.x = x; |
| 2550 | shsurf->transient.y = y; |
| 2551 | shsurf->transient.flags = flags; |
Philip Withnall | dc4332f | 2013-11-25 18:01:38 +0000 | [diff] [blame] | 2552 | |
Rafael Antognolli | ed207b4 | 2013-12-03 15:35:43 -0200 | [diff] [blame] | 2553 | shsurf->next_state.relative = true; |
Kristian Høgsberg | a1df7ac | 2013-12-31 15:01:01 -0800 | [diff] [blame] | 2554 | shsurf->state_changed = true; |
Pekka Paalanen | b502654 | 2014-11-12 15:09:24 +0200 | [diff] [blame] | 2555 | set_type(shsurf, SHELL_SURFACE_TOPLEVEL); |
Philip Withnall | 648a4dd | 2013-11-25 18:01:44 +0000 | [diff] [blame] | 2556 | |
| 2557 | /* The layer_link is updated in set_surface_type(), |
| 2558 | * called from configure. */ |
Philip Withnall | becb77e | 2013-11-25 18:01:30 +0000 | [diff] [blame] | 2559 | } |
| 2560 | |
| 2561 | static void |
| 2562 | shell_surface_set_transient(struct wl_client *client, |
| 2563 | struct wl_resource *resource, |
| 2564 | struct wl_resource *parent_resource, |
| 2565 | int x, int y, uint32_t flags) |
| 2566 | { |
| 2567 | struct shell_surface *shsurf = wl_resource_get_user_data(resource); |
| 2568 | struct weston_surface *parent = |
| 2569 | wl_resource_get_user_data(parent_resource); |
| 2570 | |
| 2571 | set_transient(shsurf, parent, x, y, flags); |
| 2572 | } |
| 2573 | |
| 2574 | static void |
| 2575 | set_fullscreen(struct shell_surface *shsurf, |
| 2576 | uint32_t method, |
| 2577 | uint32_t framerate, |
| 2578 | struct weston_output *output) |
| 2579 | { |
Philip Withnall | 352e7ed | 2013-11-25 18:01:35 +0000 | [diff] [blame] | 2580 | shell_surface_set_output(shsurf, output); |
Pekka Paalanen | b502654 | 2014-11-12 15:09:24 +0200 | [diff] [blame] | 2581 | set_type(shsurf, SHELL_SURFACE_TOPLEVEL); |
Philip Withnall | becb77e | 2013-11-25 18:01:30 +0000 | [diff] [blame] | 2582 | |
| 2583 | shsurf->fullscreen_output = shsurf->output; |
| 2584 | shsurf->fullscreen.type = method; |
| 2585 | shsurf->fullscreen.framerate = framerate; |
Philip Withnall | dc4332f | 2013-11-25 18:01:38 +0000 | [diff] [blame] | 2586 | |
Jasper St. Pierre | 6458ec3 | 2014-04-11 16:00:31 -0700 | [diff] [blame] | 2587 | send_configure_for_surface(shsurf); |
Philip Withnall | becb77e | 2013-11-25 18:01:30 +0000 | [diff] [blame] | 2588 | } |
| 2589 | |
| 2590 | static void |
Zhang, Xiong Y | 3123693 | 2013-12-13 22:10:57 +0200 | [diff] [blame] | 2591 | weston_view_set_initial_position(struct weston_view *view, |
| 2592 | struct desktop_shell *shell); |
| 2593 | |
| 2594 | static void |
Philip Withnall | becb77e | 2013-11-25 18:01:30 +0000 | [diff] [blame] | 2595 | unset_fullscreen(struct shell_surface *shsurf) |
Alex Wu | 4539b08 | 2012-03-01 12:57:46 +0800 | [diff] [blame] | 2596 | { |
Philip Withnall | f85fe84 | 2013-11-25 18:01:37 +0000 | [diff] [blame] | 2597 | /* Unset the fullscreen output, driver configuration and transforms. */ |
Alex Wu | bd3354b | 2012-04-17 17:20:49 +0800 | [diff] [blame] | 2598 | if (shsurf->fullscreen.type == WL_SHELL_SURFACE_FULLSCREEN_METHOD_DRIVER && |
| 2599 | shell_surface_is_top_fullscreen(shsurf)) { |
Alexander Larsson | f82b6ca | 2013-05-28 16:23:39 +0200 | [diff] [blame] | 2600 | restore_output_mode(shsurf->fullscreen_output); |
Alex Wu | bd3354b | 2012-04-17 17:20:49 +0800 | [diff] [blame] | 2601 | } |
Philip Withnall | f85fe84 | 2013-11-25 18:01:37 +0000 | [diff] [blame] | 2602 | |
Alex Wu | 4539b08 | 2012-03-01 12:57:46 +0800 | [diff] [blame] | 2603 | shsurf->fullscreen.type = WL_SHELL_SURFACE_FULLSCREEN_METHOD_DEFAULT; |
| 2604 | shsurf->fullscreen.framerate = 0; |
Philip Withnall | f85fe84 | 2013-11-25 18:01:37 +0000 | [diff] [blame] | 2605 | |
Alex Wu | 4539b08 | 2012-03-01 12:57:46 +0800 | [diff] [blame] | 2606 | wl_list_remove(&shsurf->fullscreen.transform.link); |
| 2607 | wl_list_init(&shsurf->fullscreen.transform.link); |
Philip Withnall | f85fe84 | 2013-11-25 18:01:37 +0000 | [diff] [blame] | 2608 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 2609 | if (shsurf->fullscreen.black_view) |
| 2610 | weston_surface_destroy(shsurf->fullscreen.black_view->surface); |
| 2611 | shsurf->fullscreen.black_view = NULL; |
Philip Withnall | f85fe84 | 2013-11-25 18:01:37 +0000 | [diff] [blame] | 2612 | |
Zhang, Xiong Y | 3123693 | 2013-12-13 22:10:57 +0200 | [diff] [blame] | 2613 | if (shsurf->saved_position_valid) |
| 2614 | weston_view_set_position(shsurf->view, |
| 2615 | shsurf->saved_x, shsurf->saved_y); |
| 2616 | else |
| 2617 | weston_view_set_initial_position(shsurf->view, shsurf->shell); |
| 2618 | |
Alex Wu | 7bcb8bd | 2012-04-27 09:07:24 +0800 | [diff] [blame] | 2619 | if (shsurf->saved_rotation_valid) { |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 2620 | wl_list_insert(&shsurf->view->geometry.transformation_list, |
Philip Withnall | becb77e | 2013-11-25 18:01:30 +0000 | [diff] [blame] | 2621 | &shsurf->rotation.transform.link); |
Alex Wu | 7bcb8bd | 2012-04-27 09:07:24 +0800 | [diff] [blame] | 2622 | shsurf->saved_rotation_valid = false; |
| 2623 | } |
Rafal Mielniczuk | 3e3862c | 2012-10-07 20:25:36 +0200 | [diff] [blame] | 2624 | |
Philip Withnall | e1d75ae | 2013-11-25 18:01:41 +0000 | [diff] [blame] | 2625 | /* Layer is updated in set_surface_type(). */ |
Alex Wu | 4539b08 | 2012-03-01 12:57:46 +0800 | [diff] [blame] | 2626 | } |
| 2627 | |
Rafal Mielniczuk | fffdcdd | 2013-03-11 19:26:54 +0100 | [diff] [blame] | 2628 | static void |
Philip Withnall | becb77e | 2013-11-25 18:01:30 +0000 | [diff] [blame] | 2629 | shell_surface_set_fullscreen(struct wl_client *client, |
| 2630 | struct wl_resource *resource, |
| 2631 | uint32_t method, |
| 2632 | uint32_t framerate, |
| 2633 | struct wl_resource *output_resource) |
| 2634 | { |
| 2635 | struct shell_surface *shsurf = wl_resource_get_user_data(resource); |
| 2636 | struct weston_output *output; |
| 2637 | |
| 2638 | if (output_resource) |
| 2639 | output = wl_resource_get_user_data(output_resource); |
| 2640 | else |
| 2641 | output = NULL; |
| 2642 | |
Rafael Antognolli | 4b99a40 | 2013-12-03 15:35:44 -0200 | [diff] [blame] | 2643 | shell_surface_set_parent(shsurf, NULL); |
| 2644 | |
Rafael Antognolli | 03b1659 | 2013-12-03 15:35:42 -0200 | [diff] [blame] | 2645 | surface_clear_next_states(shsurf); |
Jasper St. Pierre | 8c6aa45 | 2014-02-08 18:29:49 -0500 | [diff] [blame] | 2646 | shsurf->next_state.fullscreen = true; |
| 2647 | shsurf->state_changed = true; |
Jasper St. Pierre | 6458ec3 | 2014-04-11 16:00:31 -0700 | [diff] [blame] | 2648 | set_fullscreen(shsurf, method, framerate, output); |
Philip Withnall | becb77e | 2013-11-25 18:01:30 +0000 | [diff] [blame] | 2649 | } |
| 2650 | |
| 2651 | static void |
| 2652 | set_popup(struct shell_surface *shsurf, |
| 2653 | struct weston_surface *parent, |
| 2654 | struct weston_seat *seat, |
| 2655 | uint32_t serial, |
| 2656 | int32_t x, |
| 2657 | int32_t y) |
| 2658 | { |
Philip Withnall | dc4332f | 2013-11-25 18:01:38 +0000 | [diff] [blame] | 2659 | assert(parent != NULL); |
| 2660 | |
Philip Withnall | becb77e | 2013-11-25 18:01:30 +0000 | [diff] [blame] | 2661 | shsurf->popup.shseat = get_shell_seat(seat); |
| 2662 | shsurf->popup.serial = serial; |
| 2663 | shsurf->popup.x = x; |
| 2664 | shsurf->popup.y = y; |
Philip Withnall | dc4332f | 2013-11-25 18:01:38 +0000 | [diff] [blame] | 2665 | |
Pekka Paalanen | b502654 | 2014-11-12 15:09:24 +0200 | [diff] [blame] | 2666 | set_type(shsurf, SHELL_SURFACE_POPUP); |
Philip Withnall | becb77e | 2013-11-25 18:01:30 +0000 | [diff] [blame] | 2667 | } |
| 2668 | |
| 2669 | static void |
| 2670 | shell_surface_set_popup(struct wl_client *client, |
| 2671 | struct wl_resource *resource, |
| 2672 | struct wl_resource *seat_resource, |
| 2673 | uint32_t serial, |
| 2674 | struct wl_resource *parent_resource, |
| 2675 | int32_t x, int32_t y, uint32_t flags) |
| 2676 | { |
| 2677 | struct shell_surface *shsurf = wl_resource_get_user_data(resource); |
Rafael Antognolli | 4b99a40 | 2013-12-03 15:35:44 -0200 | [diff] [blame] | 2678 | struct weston_surface *parent = |
| 2679 | wl_resource_get_user_data(parent_resource); |
| 2680 | |
| 2681 | shell_surface_set_parent(shsurf, parent); |
Philip Withnall | becb77e | 2013-11-25 18:01:30 +0000 | [diff] [blame] | 2682 | |
Rafael Antognolli | 03b1659 | 2013-12-03 15:35:42 -0200 | [diff] [blame] | 2683 | surface_clear_next_states(shsurf); |
Philip Withnall | becb77e | 2013-11-25 18:01:30 +0000 | [diff] [blame] | 2684 | set_popup(shsurf, |
Rafael Antognolli | 4b99a40 | 2013-12-03 15:35:44 -0200 | [diff] [blame] | 2685 | parent, |
Philip Withnall | becb77e | 2013-11-25 18:01:30 +0000 | [diff] [blame] | 2686 | wl_resource_get_user_data(seat_resource), |
| 2687 | serial, x, y); |
| 2688 | } |
| 2689 | |
| 2690 | static void |
Philip Withnall | becb77e | 2013-11-25 18:01:30 +0000 | [diff] [blame] | 2691 | unset_maximized(struct shell_surface *shsurf) |
Rafal Mielniczuk | fffdcdd | 2013-03-11 19:26:54 +0100 | [diff] [blame] | 2692 | { |
Rafal Mielniczuk | fffdcdd | 2013-03-11 19:26:54 +0100 | [diff] [blame] | 2693 | /* undo all maximized things here */ |
| 2694 | shsurf->output = get_default_output(shsurf->surface->compositor); |
Zhang, Xiong Y | 3123693 | 2013-12-13 22:10:57 +0200 | [diff] [blame] | 2695 | |
| 2696 | if (shsurf->saved_position_valid) |
| 2697 | weston_view_set_position(shsurf->view, |
| 2698 | shsurf->saved_x, shsurf->saved_y); |
| 2699 | else |
| 2700 | weston_view_set_initial_position(shsurf->view, shsurf->shell); |
Rafal Mielniczuk | fffdcdd | 2013-03-11 19:26:54 +0100 | [diff] [blame] | 2701 | |
| 2702 | if (shsurf->saved_rotation_valid) { |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 2703 | wl_list_insert(&shsurf->view->geometry.transformation_list, |
| 2704 | &shsurf->rotation.transform.link); |
Rafal Mielniczuk | fffdcdd | 2013-03-11 19:26:54 +0100 | [diff] [blame] | 2705 | shsurf->saved_rotation_valid = false; |
| 2706 | } |
| 2707 | |
Philip Withnall | e1d75ae | 2013-11-25 18:01:41 +0000 | [diff] [blame] | 2708 | /* Layer is updated in set_surface_type(). */ |
Rafal Mielniczuk | fffdcdd | 2013-03-11 19:26:54 +0100 | [diff] [blame] | 2709 | } |
| 2710 | |
Philip Withnall | becb77e | 2013-11-25 18:01:30 +0000 | [diff] [blame] | 2711 | static void |
Manuel Bachmann | dc1c3e4 | 2015-02-16 11:52:13 +0100 | [diff] [blame] | 2712 | set_minimized(struct weston_surface *surface) |
Manuel Bachmann | 50c87db | 2014-02-26 15:52:13 +0100 | [diff] [blame] | 2713 | { |
| 2714 | struct shell_surface *shsurf; |
| 2715 | struct workspace *current_ws; |
Manuel Bachmann | 50c87db | 2014-02-26 15:52:13 +0100 | [diff] [blame] | 2716 | struct weston_view *view; |
| 2717 | |
| 2718 | view = get_default_view(surface); |
| 2719 | if (!view) |
| 2720 | return; |
| 2721 | |
| 2722 | assert(weston_surface_get_main_surface(view->surface) == view->surface); |
| 2723 | |
| 2724 | shsurf = get_shell_surface(surface); |
| 2725 | current_ws = get_current_workspace(shsurf->shell); |
| 2726 | |
Giulio Camuffo | 412e6a5 | 2014-07-09 22:12:56 +0300 | [diff] [blame] | 2727 | weston_layer_entry_remove(&view->layer_link); |
Manuel Bachmann | dc1c3e4 | 2015-02-16 11:52:13 +0100 | [diff] [blame] | 2728 | 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] | 2729 | |
Manuel Bachmann | dc1c3e4 | 2015-02-16 11:52:13 +0100 | [diff] [blame] | 2730 | drop_focus_state(shsurf->shell, current_ws, view->surface); |
Jonas Ådahl | 22faea1 | 2014-10-15 22:02:06 +0200 | [diff] [blame^] | 2731 | surface_keyboard_focus_lost(surface); |
Manuel Bachmann | 50c87db | 2014-02-26 15:52:13 +0100 | [diff] [blame] | 2732 | |
| 2733 | shell_surface_update_child_surface_layers(shsurf); |
Manuel Bachmann | 50c87db | 2014-02-26 15:52:13 +0100 | [diff] [blame] | 2734 | weston_view_damage_below(view); |
| 2735 | } |
| 2736 | |
| 2737 | static void |
Philip Withnall | becb77e | 2013-11-25 18:01:30 +0000 | [diff] [blame] | 2738 | shell_surface_set_maximized(struct wl_client *client, |
| 2739 | struct wl_resource *resource, |
| 2740 | struct wl_resource *output_resource) |
| 2741 | { |
| 2742 | struct shell_surface *shsurf = wl_resource_get_user_data(resource); |
| 2743 | struct weston_output *output; |
| 2744 | |
Jasper St. Pierre | 9aa8ce6 | 2014-04-11 16:18:54 -0700 | [diff] [blame] | 2745 | surface_clear_next_states(shsurf); |
| 2746 | shsurf->next_state.maximized = true; |
| 2747 | shsurf->state_changed = true; |
| 2748 | |
Pekka Paalanen | b502654 | 2014-11-12 15:09:24 +0200 | [diff] [blame] | 2749 | set_type(shsurf, SHELL_SURFACE_TOPLEVEL); |
Jasper St. Pierre | 9aa8ce6 | 2014-04-11 16:18:54 -0700 | [diff] [blame] | 2750 | shell_surface_set_parent(shsurf, NULL); |
| 2751 | |
Philip Withnall | becb77e | 2013-11-25 18:01:30 +0000 | [diff] [blame] | 2752 | if (output_resource) |
| 2753 | output = wl_resource_get_user_data(output_resource); |
| 2754 | else |
| 2755 | output = NULL; |
| 2756 | |
Jasper St. Pierre | 9aa8ce6 | 2014-04-11 16:18:54 -0700 | [diff] [blame] | 2757 | shell_surface_set_output(shsurf, output); |
Rafael Antognolli | 4b99a40 | 2013-12-03 15:35:44 -0200 | [diff] [blame] | 2758 | |
Jasper St. Pierre | 9aa8ce6 | 2014-04-11 16:18:54 -0700 | [diff] [blame] | 2759 | send_configure_for_surface(shsurf); |
Philip Withnall | becb77e | 2013-11-25 18:01:30 +0000 | [diff] [blame] | 2760 | } |
| 2761 | |
Philip Withnall | e1d75ae | 2013-11-25 18:01:41 +0000 | [diff] [blame] | 2762 | /* This is only ever called from set_surface_type(), so there’s no need to |
| 2763 | * update layer_links here, since they’ll be updated when we return. */ |
Pekka Paalanen | 9826223 | 2011-12-01 10:42:22 +0200 | [diff] [blame] | 2764 | static int |
Philip Withnall | becb77e | 2013-11-25 18:01:30 +0000 | [diff] [blame] | 2765 | reset_surface_type(struct shell_surface *surface) |
Pekka Paalanen | 9826223 | 2011-12-01 10:42:22 +0200 | [diff] [blame] | 2766 | { |
Rafael Antognolli | 03b1659 | 2013-12-03 15:35:42 -0200 | [diff] [blame] | 2767 | if (surface->state.fullscreen) |
Philip Withnall | becb77e | 2013-11-25 18:01:30 +0000 | [diff] [blame] | 2768 | unset_fullscreen(surface); |
Rafael Antognolli | 03b1659 | 2013-12-03 15:35:42 -0200 | [diff] [blame] | 2769 | if (surface->state.maximized) |
Philip Withnall | becb77e | 2013-11-25 18:01:30 +0000 | [diff] [blame] | 2770 | unset_maximized(surface); |
Pekka Paalanen | 9826223 | 2011-12-01 10:42:22 +0200 | [diff] [blame] | 2771 | |
Pekka Paalanen | 9826223 | 2011-12-01 10:42:22 +0200 | [diff] [blame] | 2772 | return 0; |
| 2773 | } |
| 2774 | |
Kristian Høgsberg | 4cca349 | 2011-01-18 07:53:49 -0500 | [diff] [blame] | 2775 | static void |
Rafael Antognolli | 03b1659 | 2013-12-03 15:35:42 -0200 | [diff] [blame] | 2776 | set_full_output(struct shell_surface *shsurf) |
| 2777 | { |
| 2778 | shsurf->saved_x = shsurf->view->geometry.x; |
| 2779 | shsurf->saved_y = shsurf->view->geometry.y; |
Rafael Antognolli | 3c4e3f7 | 2013-12-03 15:35:46 -0200 | [diff] [blame] | 2780 | shsurf->saved_width = shsurf->surface->width; |
| 2781 | shsurf->saved_height = shsurf->surface->height; |
| 2782 | shsurf->saved_size_valid = true; |
Rafael Antognolli | 03b1659 | 2013-12-03 15:35:42 -0200 | [diff] [blame] | 2783 | shsurf->saved_position_valid = true; |
| 2784 | |
| 2785 | if (!wl_list_empty(&shsurf->rotation.transform.link)) { |
| 2786 | wl_list_remove(&shsurf->rotation.transform.link); |
| 2787 | wl_list_init(&shsurf->rotation.transform.link); |
| 2788 | weston_view_geometry_dirty(shsurf->view); |
| 2789 | shsurf->saved_rotation_valid = true; |
| 2790 | } |
| 2791 | } |
| 2792 | |
| 2793 | static void |
Kristian Høgsberg | 7f366e7 | 2012-04-27 17:20:01 -0400 | [diff] [blame] | 2794 | set_surface_type(struct shell_surface *shsurf) |
| 2795 | { |
Kristian Høgsberg | 8150b19 | 2012-06-27 10:22:58 -0400 | [diff] [blame] | 2796 | struct weston_surface *pes = shsurf->parent; |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 2797 | struct weston_view *pev = get_default_view(pes); |
Kristian Høgsberg | 7f366e7 | 2012-04-27 17:20:01 -0400 | [diff] [blame] | 2798 | |
Philip Withnall | becb77e | 2013-11-25 18:01:30 +0000 | [diff] [blame] | 2799 | reset_surface_type(shsurf); |
Kristian Høgsberg | 7f366e7 | 2012-04-27 17:20:01 -0400 | [diff] [blame] | 2800 | |
Rafael Antognolli | 03b1659 | 2013-12-03 15:35:42 -0200 | [diff] [blame] | 2801 | shsurf->state = shsurf->next_state; |
Rafael Antognolli | 03b1659 | 2013-12-03 15:35:42 -0200 | [diff] [blame] | 2802 | shsurf->state_changed = false; |
Kristian Høgsberg | 7f366e7 | 2012-04-27 17:20:01 -0400 | [diff] [blame] | 2803 | |
| 2804 | switch (shsurf->type) { |
| 2805 | case SHELL_SURFACE_TOPLEVEL: |
Rafael Antognolli | ed207b4 | 2013-12-03 15:35:43 -0200 | [diff] [blame] | 2806 | if (shsurf->state.maximized || shsurf->state.fullscreen) { |
Rafael Antognolli | 03b1659 | 2013-12-03 15:35:42 -0200 | [diff] [blame] | 2807 | set_full_output(shsurf); |
Rafael Antognolli | ed207b4 | 2013-12-03 15:35:43 -0200 | [diff] [blame] | 2808 | } else if (shsurf->state.relative && pev) { |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 2809 | weston_view_set_position(shsurf->view, |
| 2810 | pev->geometry.x + shsurf->transient.x, |
| 2811 | pev->geometry.y + shsurf->transient.y); |
Rafael Antognolli | ed207b4 | 2013-12-03 15:35:43 -0200 | [diff] [blame] | 2812 | } |
Rafael Antognolli | 44a3162 | 2013-12-04 18:37:16 -0200 | [diff] [blame] | 2813 | break; |
Kristian Høgsberg | 7f366e7 | 2012-04-27 17:20:01 -0400 | [diff] [blame] | 2814 | |
Tiago Vignatti | fb2adba | 2013-06-12 15:43:21 -0300 | [diff] [blame] | 2815 | case SHELL_SURFACE_XWAYLAND: |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 2816 | weston_view_set_position(shsurf->view, shsurf->transient.x, |
| 2817 | shsurf->transient.y); |
Tiago Vignatti | fb2adba | 2013-06-12 15:43:21 -0300 | [diff] [blame] | 2818 | break; |
| 2819 | |
Philip Withnall | 0f640e2 | 2013-11-25 18:01:31 +0000 | [diff] [blame] | 2820 | case SHELL_SURFACE_POPUP: |
| 2821 | case SHELL_SURFACE_NONE: |
Kristian Høgsberg | 7f366e7 | 2012-04-27 17:20:01 -0400 | [diff] [blame] | 2822 | default: |
| 2823 | break; |
| 2824 | } |
Philip Withnall | e1d75ae | 2013-11-25 18:01:41 +0000 | [diff] [blame] | 2825 | |
| 2826 | /* Update the surface’s layer. */ |
| 2827 | shell_surface_update_layer(shsurf); |
Kristian Høgsberg | 7f366e7 | 2012-04-27 17:20:01 -0400 | [diff] [blame] | 2828 | } |
| 2829 | |
Tiago Vignatti | be14326 | 2012-04-16 17:31:41 +0300 | [diff] [blame] | 2830 | static struct desktop_shell * |
Juan Zhao | 96879df | 2012-02-07 08:45:41 +0800 | [diff] [blame] | 2831 | shell_surface_get_shell(struct shell_surface *shsurf) |
Pekka Paalanen | af0e34c | 2011-12-02 10:59:17 +0200 | [diff] [blame] | 2832 | { |
Kristian Høgsberg | 02e79dc | 2012-04-12 09:55:26 -0400 | [diff] [blame] | 2833 | return shsurf->shell; |
Juan Zhao | 96879df | 2012-02-07 08:45:41 +0800 | [diff] [blame] | 2834 | } |
| 2835 | |
Pekka Paalanen | 8274d90 | 2014-08-06 19:36:51 +0300 | [diff] [blame] | 2836 | static int |
| 2837 | black_surface_get_label(struct weston_surface *surface, char *buf, size_t len) |
| 2838 | { |
| 2839 | struct weston_surface *fs_surface = surface->configure_private; |
| 2840 | int n; |
| 2841 | int rem; |
| 2842 | int ret; |
| 2843 | |
| 2844 | n = snprintf(buf, len, "black background surface for "); |
| 2845 | if (n < 0) |
| 2846 | return n; |
| 2847 | |
| 2848 | rem = (int)len - n; |
| 2849 | if (rem < 0) |
| 2850 | rem = 0; |
| 2851 | |
| 2852 | if (fs_surface->get_label) |
| 2853 | ret = fs_surface->get_label(fs_surface, buf + n, rem); |
| 2854 | else |
| 2855 | ret = snprintf(buf + n, rem, "<unknown>"); |
| 2856 | |
| 2857 | if (ret < 0) |
| 2858 | return n; |
| 2859 | |
| 2860 | return n + ret; |
| 2861 | } |
| 2862 | |
Alex Wu | 2185843 | 2012-04-01 20:13:08 +0800 | [diff] [blame] | 2863 | static void |
Jason Ekstrand | 918f2dd | 2013-12-02 21:01:53 -0600 | [diff] [blame] | 2864 | 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] | 2865 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 2866 | static struct weston_view * |
Alex Wu | 4539b08 | 2012-03-01 12:57:46 +0800 | [diff] [blame] | 2867 | create_black_surface(struct weston_compositor *ec, |
Alex Wu | 2185843 | 2012-04-01 20:13:08 +0800 | [diff] [blame] | 2868 | struct weston_surface *fs_surface, |
John Kåre Alsaker | 490d02a | 2012-09-30 02:57:21 +0200 | [diff] [blame] | 2869 | float x, float y, int w, int h) |
Alex Wu | 4539b08 | 2012-03-01 12:57:46 +0800 | [diff] [blame] | 2870 | { |
| 2871 | struct weston_surface *surface = NULL; |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 2872 | struct weston_view *view; |
Alex Wu | 4539b08 | 2012-03-01 12:57:46 +0800 | [diff] [blame] | 2873 | |
| 2874 | surface = weston_surface_create(ec); |
| 2875 | if (surface == NULL) { |
Martin Minarik | 6d11836 | 2012-06-07 18:01:59 +0200 | [diff] [blame] | 2876 | weston_log("no memory\n"); |
Alex Wu | 4539b08 | 2012-03-01 12:57:46 +0800 | [diff] [blame] | 2877 | return NULL; |
| 2878 | } |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 2879 | view = weston_view_create(surface); |
| 2880 | if (surface == NULL) { |
| 2881 | weston_log("no memory\n"); |
| 2882 | weston_surface_destroy(surface); |
| 2883 | return NULL; |
| 2884 | } |
Alex Wu | 4539b08 | 2012-03-01 12:57:46 +0800 | [diff] [blame] | 2885 | |
Alex Wu | 2185843 | 2012-04-01 20:13:08 +0800 | [diff] [blame] | 2886 | surface->configure = black_surface_configure; |
Giulio Camuffo | 7fe01b1 | 2013-03-28 18:02:42 +0100 | [diff] [blame] | 2887 | surface->configure_private = fs_surface; |
Pekka Paalanen | 8274d90 | 2014-08-06 19:36:51 +0300 | [diff] [blame] | 2888 | weston_surface_set_label_func(surface, black_surface_get_label); |
Alex Wu | 4539b08 | 2012-03-01 12:57:46 +0800 | [diff] [blame] | 2889 | weston_surface_set_color(surface, 0.0, 0.0, 0.0, 1); |
Pekka Paalanen | 71f6f3b | 2012-10-10 12:49:26 +0300 | [diff] [blame] | 2890 | pixman_region32_fini(&surface->opaque); |
Kristian Høgsberg | 61f00f5 | 2012-08-03 16:31:36 -0400 | [diff] [blame] | 2891 | pixman_region32_init_rect(&surface->opaque, 0, 0, w, h); |
Jonas Ådahl | 33619a4 | 2013-01-15 21:25:55 +0100 | [diff] [blame] | 2892 | pixman_region32_fini(&surface->input); |
| 2893 | pixman_region32_init_rect(&surface->input, 0, 0, w, h); |
Jason Ekstrand | 918f2dd | 2013-12-02 21:01:53 -0600 | [diff] [blame] | 2894 | |
Jason Ekstrand | 6228ee2 | 2014-01-01 15:58:57 -0600 | [diff] [blame] | 2895 | weston_surface_set_size(surface, w, h); |
Jason Ekstrand | 918f2dd | 2013-12-02 21:01:53 -0600 | [diff] [blame] | 2896 | weston_view_set_position(view, x, y); |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 2897 | |
| 2898 | return view; |
Alex Wu | 4539b08 | 2012-03-01 12:57:46 +0800 | [diff] [blame] | 2899 | } |
| 2900 | |
Philip Withnall | ed8f1a9 | 2013-11-25 18:01:43 +0000 | [diff] [blame] | 2901 | static void |
| 2902 | shell_ensure_fullscreen_black_view(struct shell_surface *shsurf) |
| 2903 | { |
| 2904 | struct weston_output *output = shsurf->fullscreen_output; |
| 2905 | |
Rafael Antognolli | 03b1659 | 2013-12-03 15:35:42 -0200 | [diff] [blame] | 2906 | assert(shsurf->state.fullscreen); |
Philip Withnall | ed8f1a9 | 2013-11-25 18:01:43 +0000 | [diff] [blame] | 2907 | |
| 2908 | if (!shsurf->fullscreen.black_view) |
| 2909 | shsurf->fullscreen.black_view = |
| 2910 | create_black_surface(shsurf->surface->compositor, |
| 2911 | shsurf->surface, |
| 2912 | output->x, output->y, |
| 2913 | output->width, |
| 2914 | output->height); |
| 2915 | |
| 2916 | weston_view_geometry_dirty(shsurf->fullscreen.black_view); |
Giulio Camuffo | 412e6a5 | 2014-07-09 22:12:56 +0300 | [diff] [blame] | 2917 | weston_layer_entry_remove(&shsurf->fullscreen.black_view->layer_link); |
| 2918 | weston_layer_entry_insert(&shsurf->view->layer_link, |
| 2919 | &shsurf->fullscreen.black_view->layer_link); |
Philip Withnall | ed8f1a9 | 2013-11-25 18:01:43 +0000 | [diff] [blame] | 2920 | weston_view_geometry_dirty(shsurf->fullscreen.black_view); |
| 2921 | weston_surface_damage(shsurf->surface); |
Emilio Pozuelo Monfort | 9e7c759 | 2014-01-30 14:01:10 +0100 | [diff] [blame] | 2922 | |
| 2923 | shsurf->state.lowered = false; |
Philip Withnall | ed8f1a9 | 2013-11-25 18:01:43 +0000 | [diff] [blame] | 2924 | } |
| 2925 | |
Alex Wu | 4539b08 | 2012-03-01 12:57:46 +0800 | [diff] [blame] | 2926 | /* Create black surface and append it to the associated fullscreen surface. |
| 2927 | * Handle size dismatch and positioning according to the method. */ |
| 2928 | static void |
| 2929 | shell_configure_fullscreen(struct shell_surface *shsurf) |
| 2930 | { |
| 2931 | struct weston_output *output = shsurf->fullscreen_output; |
| 2932 | struct weston_surface *surface = shsurf->surface; |
| 2933 | struct weston_matrix *matrix; |
Kristian Høgsberg | 240dfeb | 2012-07-12 12:32:31 -0400 | [diff] [blame] | 2934 | float scale, output_aspect, surface_aspect, x, y; |
Giulio Camuffo | b836664 | 2013-04-25 13:57:46 +0300 | [diff] [blame] | 2935 | int32_t surf_x, surf_y, surf_width, surf_height; |
Alex Wu | 4539b08 | 2012-03-01 12:57:46 +0800 | [diff] [blame] | 2936 | |
Alexander Larsson | f82b6ca | 2013-05-28 16:23:39 +0200 | [diff] [blame] | 2937 | if (shsurf->fullscreen.type != WL_SHELL_SURFACE_FULLSCREEN_METHOD_DRIVER) |
| 2938 | restore_output_mode(output); |
| 2939 | |
Emilio Pozuelo Monfort | 9e7c759 | 2014-01-30 14:01:10 +0100 | [diff] [blame] | 2940 | /* Reverse the effect of lower_fullscreen_layer() */ |
Giulio Camuffo | 412e6a5 | 2014-07-09 22:12:56 +0300 | [diff] [blame] | 2941 | weston_layer_entry_remove(&shsurf->view->layer_link); |
| 2942 | 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] | 2943 | |
Philip Withnall | ed8f1a9 | 2013-11-25 18:01:43 +0000 | [diff] [blame] | 2944 | shell_ensure_fullscreen_black_view(shsurf); |
Alex Wu | 4539b08 | 2012-03-01 12:57:46 +0800 | [diff] [blame] | 2945 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 2946 | surface_subsurfaces_boundingbox(shsurf->surface, &surf_x, &surf_y, |
Giulio Camuffo | b836664 | 2013-04-25 13:57:46 +0300 | [diff] [blame] | 2947 | &surf_width, &surf_height); |
| 2948 | |
Alex Wu | 4539b08 | 2012-03-01 12:57:46 +0800 | [diff] [blame] | 2949 | switch (shsurf->fullscreen.type) { |
| 2950 | case WL_SHELL_SURFACE_FULLSCREEN_METHOD_DEFAULT: |
Pekka Paalanen | de685b8 | 2012-12-04 15:58:12 +0200 | [diff] [blame] | 2951 | if (surface->buffer_ref.buffer) |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 2952 | center_on_output(shsurf->view, shsurf->fullscreen_output); |
Alex Wu | 4539b08 | 2012-03-01 12:57:46 +0800 | [diff] [blame] | 2953 | break; |
| 2954 | case WL_SHELL_SURFACE_FULLSCREEN_METHOD_SCALE: |
Rob Bradford | 9f3dd15 | 2013-02-12 11:53:47 +0000 | [diff] [blame] | 2955 | /* 1:1 mapping between surface and output dimensions */ |
Giulio Camuffo | b836664 | 2013-04-25 13:57:46 +0300 | [diff] [blame] | 2956 | if (output->width == surf_width && |
| 2957 | output->height == surf_height) { |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 2958 | weston_view_set_position(shsurf->view, |
| 2959 | output->x - surf_x, |
| 2960 | output->y - surf_y); |
Rob Bradford | 9f3dd15 | 2013-02-12 11:53:47 +0000 | [diff] [blame] | 2961 | break; |
| 2962 | } |
| 2963 | |
Alex Wu | 4539b08 | 2012-03-01 12:57:46 +0800 | [diff] [blame] | 2964 | matrix = &shsurf->fullscreen.transform.matrix; |
| 2965 | weston_matrix_init(matrix); |
Kristian Høgsberg | 240dfeb | 2012-07-12 12:32:31 -0400 | [diff] [blame] | 2966 | |
Scott Moreau | 1bad5db | 2012-08-18 01:04:05 -0600 | [diff] [blame] | 2967 | output_aspect = (float) output->width / |
| 2968 | (float) output->height; |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 2969 | /* XXX: Use surf_width and surf_height here? */ |
| 2970 | surface_aspect = (float) surface->width / |
| 2971 | (float) surface->height; |
Kristian Høgsberg | 240dfeb | 2012-07-12 12:32:31 -0400 | [diff] [blame] | 2972 | if (output_aspect < surface_aspect) |
Scott Moreau | 1bad5db | 2012-08-18 01:04:05 -0600 | [diff] [blame] | 2973 | scale = (float) output->width / |
Giulio Camuffo | b836664 | 2013-04-25 13:57:46 +0300 | [diff] [blame] | 2974 | (float) surf_width; |
Kristian Høgsberg | 240dfeb | 2012-07-12 12:32:31 -0400 | [diff] [blame] | 2975 | else |
Scott Moreau | 1bad5db | 2012-08-18 01:04:05 -0600 | [diff] [blame] | 2976 | scale = (float) output->height / |
Giulio Camuffo | b836664 | 2013-04-25 13:57:46 +0300 | [diff] [blame] | 2977 | (float) surf_height; |
Kristian Høgsberg | 240dfeb | 2012-07-12 12:32:31 -0400 | [diff] [blame] | 2978 | |
Alex Wu | 4539b08 | 2012-03-01 12:57:46 +0800 | [diff] [blame] | 2979 | weston_matrix_scale(matrix, scale, scale, 1); |
| 2980 | wl_list_remove(&shsurf->fullscreen.transform.link); |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 2981 | wl_list_insert(&shsurf->view->geometry.transformation_list, |
Alex Wu | 4539b08 | 2012-03-01 12:57:46 +0800 | [diff] [blame] | 2982 | &shsurf->fullscreen.transform.link); |
Giulio Camuffo | b836664 | 2013-04-25 13:57:46 +0300 | [diff] [blame] | 2983 | x = output->x + (output->width - surf_width * scale) / 2 - surf_x; |
| 2984 | y = output->y + (output->height - surf_height * scale) / 2 - surf_y; |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 2985 | weston_view_set_position(shsurf->view, x, y); |
Kristian Høgsberg | 240dfeb | 2012-07-12 12:32:31 -0400 | [diff] [blame] | 2986 | |
Alex Wu | 4539b08 | 2012-03-01 12:57:46 +0800 | [diff] [blame] | 2987 | break; |
| 2988 | case WL_SHELL_SURFACE_FULLSCREEN_METHOD_DRIVER: |
Alex Wu | bd3354b | 2012-04-17 17:20:49 +0800 | [diff] [blame] | 2989 | if (shell_surface_is_top_fullscreen(shsurf)) { |
Quentin Glidic | c0d79ce | 2013-01-29 14:16:13 +0100 | [diff] [blame] | 2990 | struct weston_mode mode = {0, |
Pekka Paalanen | 952b6c8 | 2014-03-14 14:38:15 +0200 | [diff] [blame] | 2991 | surf_width * surface->buffer_viewport.buffer.scale, |
| 2992 | surf_height * surface->buffer_viewport.buffer.scale, |
Alex Wu | bd3354b | 2012-04-17 17:20:49 +0800 | [diff] [blame] | 2993 | shsurf->fullscreen.framerate}; |
| 2994 | |
Derek Foreman | 6ae7bc9 | 2014-11-04 10:47:33 -0600 | [diff] [blame] | 2995 | if (weston_output_mode_switch_to_temporary(output, &mode, |
| 2996 | surface->buffer_viewport.buffer.scale) == 0) { |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 2997 | weston_view_set_position(shsurf->view, |
| 2998 | output->x - surf_x, |
| 2999 | output->y - surf_y); |
Jason Ekstrand | 918f2dd | 2013-12-02 21:01:53 -0600 | [diff] [blame] | 3000 | shsurf->fullscreen.black_view->surface->width = output->width; |
| 3001 | shsurf->fullscreen.black_view->surface->height = output->height; |
| 3002 | weston_view_set_position(shsurf->fullscreen.black_view, |
| 3003 | output->x - surf_x, |
| 3004 | output->y - surf_y); |
Alex Wu | bd3354b | 2012-04-17 17:20:49 +0800 | [diff] [blame] | 3005 | break; |
Alexander Larsson | d622ed3 | 2013-05-28 16:23:40 +0200 | [diff] [blame] | 3006 | } else { |
Mario Kleiner | 492c12f | 2015-06-21 21:25:12 +0200 | [diff] [blame] | 3007 | weston_log("shell: Can't switch to temporary mode.\n"); |
Alexander Larsson | f82b6ca | 2013-05-28 16:23:39 +0200 | [diff] [blame] | 3008 | restore_output_mode(output); |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 3009 | center_on_output(shsurf->view, output); |
Alexander Larsson | d622ed3 | 2013-05-28 16:23:40 +0200 | [diff] [blame] | 3010 | } |
Alex Wu | bd3354b | 2012-04-17 17:20:49 +0800 | [diff] [blame] | 3011 | } |
Alex Wu | 4539b08 | 2012-03-01 12:57:46 +0800 | [diff] [blame] | 3012 | break; |
| 3013 | case WL_SHELL_SURFACE_FULLSCREEN_METHOD_FILL: |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 3014 | center_on_output(shsurf->view, output); |
Alex Wu | 4539b08 | 2012-03-01 12:57:46 +0800 | [diff] [blame] | 3015 | break; |
| 3016 | default: |
| 3017 | break; |
| 3018 | } |
| 3019 | } |
| 3020 | |
Alex Wu | 4539b08 | 2012-03-01 12:57:46 +0800 | [diff] [blame] | 3021 | static void |
| 3022 | shell_map_fullscreen(struct shell_surface *shsurf) |
| 3023 | { |
Alex Wu | bd3354b | 2012-04-17 17:20:49 +0800 | [diff] [blame] | 3024 | shell_configure_fullscreen(shsurf); |
Alex Wu | 4539b08 | 2012-03-01 12:57:46 +0800 | [diff] [blame] | 3025 | } |
| 3026 | |
Kristian Høgsberg | 7a5c979 | 2011-06-18 06:12:54 -0400 | [diff] [blame] | 3027 | static void |
Tiago Vignatti | fb2adba | 2013-06-12 15:43:21 -0300 | [diff] [blame] | 3028 | set_xwayland(struct shell_surface *shsurf, int x, int y, uint32_t flags) |
| 3029 | { |
| 3030 | /* XXX: using the same fields for transient type */ |
Rafael Antognolli | 03b1659 | 2013-12-03 15:35:42 -0200 | [diff] [blame] | 3031 | surface_clear_next_states(shsurf); |
Tiago Vignatti | fb2adba | 2013-06-12 15:43:21 -0300 | [diff] [blame] | 3032 | shsurf->transient.x = x; |
| 3033 | shsurf->transient.y = y; |
| 3034 | shsurf->transient.flags = flags; |
Philip Withnall | dc4332f | 2013-11-25 18:01:38 +0000 | [diff] [blame] | 3035 | |
| 3036 | shell_surface_set_parent(shsurf, NULL); |
| 3037 | |
Pekka Paalanen | b502654 | 2014-11-12 15:09:24 +0200 | [diff] [blame] | 3038 | set_type(shsurf, SHELL_SURFACE_XWAYLAND); |
Kristian Høgsberg | 8bc525c | 2014-01-01 22:34:49 -0800 | [diff] [blame] | 3039 | shsurf->state_changed = true; |
Tiago Vignatti | fb2adba | 2013-06-12 15:43:21 -0300 | [diff] [blame] | 3040 | } |
| 3041 | |
Kristian Høgsberg | 4779241 | 2014-05-04 13:47:06 -0700 | [diff] [blame] | 3042 | static void |
| 3043 | shell_interface_set_fullscreen(struct shell_surface *shsurf, |
| 3044 | uint32_t method, |
| 3045 | uint32_t framerate, |
| 3046 | struct weston_output *output) |
| 3047 | { |
| 3048 | surface_clear_next_states(shsurf); |
Kristian Høgsberg | 4779241 | 2014-05-04 13:47:06 -0700 | [diff] [blame] | 3049 | shsurf->next_state.fullscreen = true; |
| 3050 | shsurf->state_changed = true; |
Marek Chalupa | e9fe467 | 2014-10-29 13:44:44 +0100 | [diff] [blame] | 3051 | |
| 3052 | set_fullscreen(shsurf, method, framerate, output); |
Kristian Høgsberg | 4779241 | 2014-05-04 13:47:06 -0700 | [diff] [blame] | 3053 | } |
| 3054 | |
Giulio Camuffo | 6b4b241 | 2015-01-29 19:06:49 +0200 | [diff] [blame] | 3055 | static struct weston_output * |
| 3056 | get_focused_output(struct weston_compositor *compositor) |
| 3057 | { |
| 3058 | struct weston_seat *seat; |
| 3059 | struct weston_output *output = NULL; |
| 3060 | |
| 3061 | wl_list_for_each(seat, &compositor->seat_list, link) { |
Derek Foreman | 1281a36 | 2015-07-31 16:55:32 -0500 | [diff] [blame] | 3062 | struct weston_touch *touch = weston_seat_get_touch(seat); |
| 3063 | struct weston_pointer *pointer = weston_seat_get_pointer(seat); |
| 3064 | struct weston_keyboard *keyboard = |
| 3065 | weston_seat_get_keyboard(seat); |
| 3066 | |
Giulio Camuffo | 6b4b241 | 2015-01-29 19:06:49 +0200 | [diff] [blame] | 3067 | /* Priority has touch focus, then pointer and |
| 3068 | * then keyboard focus. We should probably have |
| 3069 | * three for loops and check frist for touch, |
| 3070 | * then for pointer, etc. but unless somebody has some |
| 3071 | * objections, I think this is sufficient. */ |
Derek Foreman | 1281a36 | 2015-07-31 16:55:32 -0500 | [diff] [blame] | 3072 | if (touch && touch->focus) |
| 3073 | output = touch->focus->output; |
| 3074 | else if (pointer && pointer->focus) |
| 3075 | output = pointer->focus->output; |
| 3076 | else if (keyboard && keyboard->focus) |
| 3077 | output = keyboard->focus->output; |
Giulio Camuffo | 6b4b241 | 2015-01-29 19:06:49 +0200 | [diff] [blame] | 3078 | |
| 3079 | if (output) |
| 3080 | break; |
| 3081 | } |
| 3082 | |
| 3083 | return output; |
| 3084 | } |
| 3085 | |
| 3086 | static void |
| 3087 | shell_interface_set_maximized(struct shell_surface *shsurf) |
| 3088 | { |
| 3089 | struct weston_output *output; |
| 3090 | |
| 3091 | surface_clear_next_states(shsurf); |
| 3092 | shsurf->next_state.maximized = true; |
| 3093 | shsurf->state_changed = true; |
| 3094 | shsurf->type = SHELL_SURFACE_TOPLEVEL; |
| 3095 | |
| 3096 | if (!weston_surface_is_mapped(shsurf->surface)) |
| 3097 | output = get_focused_output(shsurf->surface->compositor); |
| 3098 | else |
| 3099 | output = shsurf->surface->output; |
| 3100 | |
| 3101 | shell_surface_set_output(shsurf, output); |
| 3102 | send_configure_for_surface(shsurf); |
| 3103 | } |
| 3104 | |
Kristian Høgsberg | ae356ae | 2014-04-29 16:03:54 -0700 | [diff] [blame] | 3105 | static int |
Derek Foreman | e4d6c83 | 2015-08-05 14:48:11 -0500 | [diff] [blame] | 3106 | shell_interface_move(struct shell_surface *shsurf, struct weston_pointer *pointer) |
Kristian Høgsberg | ae356ae | 2014-04-29 16:03:54 -0700 | [diff] [blame] | 3107 | { |
Derek Foreman | e4d6c83 | 2015-08-05 14:48:11 -0500 | [diff] [blame] | 3108 | return surface_move(shsurf, pointer, true); |
Kristian Høgsberg | ae356ae | 2014-04-29 16:03:54 -0700 | [diff] [blame] | 3109 | } |
| 3110 | |
Derek Foreman | 8fbebbd | 2015-07-15 13:00:40 -0500 | [diff] [blame] | 3111 | static int |
| 3112 | shell_interface_resize(struct shell_surface *shsurf, |
Derek Foreman | e4d6c83 | 2015-08-05 14:48:11 -0500 | [diff] [blame] | 3113 | struct weston_pointer *pointer, |
Derek Foreman | 8fbebbd | 2015-07-15 13:00:40 -0500 | [diff] [blame] | 3114 | uint32_t edges) |
| 3115 | { |
Derek Foreman | e4d6c83 | 2015-08-05 14:48:11 -0500 | [diff] [blame] | 3116 | return surface_resize(shsurf, pointer, edges); |
Derek Foreman | 8fbebbd | 2015-07-15 13:00:40 -0500 | [diff] [blame] | 3117 | } |
| 3118 | |
Kristian Høgsberg | 02bbabb | 2013-05-06 22:15:05 -0400 | [diff] [blame] | 3119 | static const struct weston_pointer_grab_interface popup_grab_interface; |
Giulio Camuffo | 5085a75 | 2013-03-25 21:42:45 +0100 | [diff] [blame] | 3120 | |
| 3121 | static void |
| 3122 | destroy_shell_seat(struct wl_listener *listener, void *data) |
| 3123 | { |
| 3124 | struct shell_seat *shseat = |
| 3125 | container_of(listener, |
| 3126 | struct shell_seat, seat_destroy_listener); |
Jonas Ådahl | c2b1011 | 2015-02-13 14:01:53 +0800 | [diff] [blame] | 3127 | struct shell_surface *shsurf, *next; |
Giulio Camuffo | 5085a75 | 2013-03-25 21:42:45 +0100 | [diff] [blame] | 3128 | |
| 3129 | if (shseat->popup_grab.grab.interface == &popup_grab_interface) { |
Kristian Høgsberg | 02bbabb | 2013-05-06 22:15:05 -0400 | [diff] [blame] | 3130 | weston_pointer_end_grab(shseat->popup_grab.grab.pointer); |
Giulio Camuffo | 5085a75 | 2013-03-25 21:42:45 +0100 | [diff] [blame] | 3131 | shseat->popup_grab.client = NULL; |
| 3132 | |
Jonas Ådahl | c2b1011 | 2015-02-13 14:01:53 +0800 | [diff] [blame] | 3133 | wl_list_for_each_safe(shsurf, next, |
| 3134 | &shseat->popup_grab.surfaces_list, |
| 3135 | popup.grab_link) { |
Giulio Camuffo | 5085a75 | 2013-03-25 21:42:45 +0100 | [diff] [blame] | 3136 | shsurf->popup.shseat = NULL; |
Jonas Ådahl | c2b1011 | 2015-02-13 14:01:53 +0800 | [diff] [blame] | 3137 | wl_list_init(&shsurf->popup.grab_link); |
Giulio Camuffo | 5085a75 | 2013-03-25 21:42:45 +0100 | [diff] [blame] | 3138 | } |
Giulio Camuffo | 5085a75 | 2013-03-25 21:42:45 +0100 | [diff] [blame] | 3139 | } |
| 3140 | |
| 3141 | wl_list_remove(&shseat->seat_destroy_listener.link); |
| 3142 | free(shseat); |
| 3143 | } |
| 3144 | |
Jason Ekstrand | 024177c | 2014-04-21 19:42:58 -0500 | [diff] [blame] | 3145 | static void |
| 3146 | shell_seat_caps_changed(struct wl_listener *listener, void *data) |
| 3147 | { |
Derek Foreman | 1281a36 | 2015-07-31 16:55:32 -0500 | [diff] [blame] | 3148 | struct weston_keyboard *keyboard; |
| 3149 | struct weston_pointer *pointer; |
Jason Ekstrand | 024177c | 2014-04-21 19:42:58 -0500 | [diff] [blame] | 3150 | struct shell_seat *seat; |
| 3151 | |
| 3152 | seat = container_of(listener, struct shell_seat, caps_changed_listener); |
Derek Foreman | 1281a36 | 2015-07-31 16:55:32 -0500 | [diff] [blame] | 3153 | keyboard = weston_seat_get_keyboard(seat->seat); |
| 3154 | pointer = weston_seat_get_pointer(seat->seat); |
Jason Ekstrand | 024177c | 2014-04-21 19:42:58 -0500 | [diff] [blame] | 3155 | |
Derek Foreman | 1281a36 | 2015-07-31 16:55:32 -0500 | [diff] [blame] | 3156 | if (keyboard && |
Jason Ekstrand | 024177c | 2014-04-21 19:42:58 -0500 | [diff] [blame] | 3157 | wl_list_empty(&seat->keyboard_focus_listener.link)) { |
Derek Foreman | 1281a36 | 2015-07-31 16:55:32 -0500 | [diff] [blame] | 3158 | wl_signal_add(&keyboard->focus_signal, |
Jason Ekstrand | 024177c | 2014-04-21 19:42:58 -0500 | [diff] [blame] | 3159 | &seat->keyboard_focus_listener); |
Derek Foreman | 1281a36 | 2015-07-31 16:55:32 -0500 | [diff] [blame] | 3160 | } else if (!keyboard) { |
Derek Foreman | 60d9731 | 2015-07-15 13:00:45 -0500 | [diff] [blame] | 3161 | wl_list_remove(&seat->keyboard_focus_listener.link); |
Jason Ekstrand | 024177c | 2014-04-21 19:42:58 -0500 | [diff] [blame] | 3162 | wl_list_init(&seat->keyboard_focus_listener.link); |
| 3163 | } |
| 3164 | |
Derek Foreman | 1281a36 | 2015-07-31 16:55:32 -0500 | [diff] [blame] | 3165 | if (pointer && |
Jason Ekstrand | 024177c | 2014-04-21 19:42:58 -0500 | [diff] [blame] | 3166 | wl_list_empty(&seat->pointer_focus_listener.link)) { |
Derek Foreman | 1281a36 | 2015-07-31 16:55:32 -0500 | [diff] [blame] | 3167 | wl_signal_add(&pointer->focus_signal, |
Jason Ekstrand | 024177c | 2014-04-21 19:42:58 -0500 | [diff] [blame] | 3168 | &seat->pointer_focus_listener); |
Derek Foreman | 1281a36 | 2015-07-31 16:55:32 -0500 | [diff] [blame] | 3169 | } else if (!pointer) { |
Derek Foreman | 60d9731 | 2015-07-15 13:00:45 -0500 | [diff] [blame] | 3170 | wl_list_remove(&seat->pointer_focus_listener.link); |
Jason Ekstrand | 024177c | 2014-04-21 19:42:58 -0500 | [diff] [blame] | 3171 | wl_list_init(&seat->pointer_focus_listener.link); |
| 3172 | } |
| 3173 | } |
| 3174 | |
Giulio Camuffo | 5085a75 | 2013-03-25 21:42:45 +0100 | [diff] [blame] | 3175 | static struct shell_seat * |
| 3176 | create_shell_seat(struct weston_seat *seat) |
| 3177 | { |
| 3178 | struct shell_seat *shseat; |
| 3179 | |
| 3180 | shseat = calloc(1, sizeof *shseat); |
| 3181 | if (!shseat) { |
| 3182 | weston_log("no memory to allocate shell seat\n"); |
| 3183 | return NULL; |
| 3184 | } |
| 3185 | |
| 3186 | shseat->seat = seat; |
| 3187 | wl_list_init(&shseat->popup_grab.surfaces_list); |
| 3188 | |
| 3189 | shseat->seat_destroy_listener.notify = destroy_shell_seat; |
| 3190 | wl_signal_add(&seat->destroy_signal, |
| 3191 | &shseat->seat_destroy_listener); |
| 3192 | |
Jason Ekstrand | 024177c | 2014-04-21 19:42:58 -0500 | [diff] [blame] | 3193 | shseat->keyboard_focus_listener.notify = handle_keyboard_focus; |
| 3194 | wl_list_init(&shseat->keyboard_focus_listener.link); |
| 3195 | |
| 3196 | shseat->pointer_focus_listener.notify = handle_pointer_focus; |
| 3197 | wl_list_init(&shseat->pointer_focus_listener.link); |
| 3198 | |
| 3199 | shseat->caps_changed_listener.notify = shell_seat_caps_changed; |
| 3200 | wl_signal_add(&seat->updated_caps_signal, |
| 3201 | &shseat->caps_changed_listener); |
| 3202 | shell_seat_caps_changed(&shseat->caps_changed_listener, NULL); |
| 3203 | |
Giulio Camuffo | 5085a75 | 2013-03-25 21:42:45 +0100 | [diff] [blame] | 3204 | return shseat; |
| 3205 | } |
| 3206 | |
| 3207 | static struct shell_seat * |
| 3208 | get_shell_seat(struct weston_seat *seat) |
| 3209 | { |
| 3210 | struct wl_listener *listener; |
| 3211 | |
| 3212 | listener = wl_signal_get(&seat->destroy_signal, destroy_shell_seat); |
Jason Ekstrand | 024177c | 2014-04-21 19:42:58 -0500 | [diff] [blame] | 3213 | assert(listener != NULL); |
Giulio Camuffo | 5085a75 | 2013-03-25 21:42:45 +0100 | [diff] [blame] | 3214 | |
| 3215 | return container_of(listener, |
| 3216 | struct shell_seat, seat_destroy_listener); |
| 3217 | } |
| 3218 | |
Kristian Høgsberg | b810eb5 | 2013-02-12 20:07:05 -0500 | [diff] [blame] | 3219 | static void |
Kristian Høgsberg | 6848c25 | 2013-05-08 22:02:59 -0400 | [diff] [blame] | 3220 | popup_grab_focus(struct weston_pointer_grab *grab) |
Kristian Høgsberg | b3cca0a | 2012-01-04 22:19:14 -0500 | [diff] [blame] | 3221 | { |
Kristian Høgsberg | 02bbabb | 2013-05-06 22:15:05 -0400 | [diff] [blame] | 3222 | struct weston_pointer *pointer = grab->pointer; |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 3223 | struct weston_view *view; |
Giulio Camuffo | 5085a75 | 2013-03-25 21:42:45 +0100 | [diff] [blame] | 3224 | struct shell_seat *shseat = |
| 3225 | container_of(grab, struct shell_seat, popup_grab.grab); |
| 3226 | struct wl_client *client = shseat->popup_grab.client; |
Kristian Høgsberg | 6848c25 | 2013-05-08 22:02:59 -0400 | [diff] [blame] | 3227 | wl_fixed_t sx, sy; |
| 3228 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 3229 | view = weston_compositor_pick_view(pointer->seat->compositor, |
| 3230 | pointer->x, pointer->y, |
| 3231 | &sx, &sy); |
Kristian Høgsberg | b3cca0a | 2012-01-04 22:19:14 -0500 | [diff] [blame] | 3232 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 3233 | if (view && view->surface->resource && |
| 3234 | wl_resource_get_client(view->surface->resource) == client) { |
| 3235 | weston_pointer_set_focus(pointer, view, sx, sy); |
Kristian Høgsberg | b3cca0a | 2012-01-04 22:19:14 -0500 | [diff] [blame] | 3236 | } else { |
Derek Foreman | f9318d1 | 2015-05-11 15:40:11 -0500 | [diff] [blame] | 3237 | weston_pointer_clear_focus(pointer); |
Kristian Høgsberg | b3cca0a | 2012-01-04 22:19:14 -0500 | [diff] [blame] | 3238 | } |
| 3239 | } |
| 3240 | |
| 3241 | static void |
Giulio Camuffo | 1959ab8 | 2013-11-14 23:42:52 +0100 | [diff] [blame] | 3242 | popup_grab_motion(struct weston_pointer_grab *grab, uint32_t time, |
| 3243 | wl_fixed_t x, wl_fixed_t y) |
Kristian Høgsberg | b3cca0a | 2012-01-04 22:19:14 -0500 | [diff] [blame] | 3244 | { |
Kristian Høgsberg | be6403e | 2013-05-08 21:03:21 -0400 | [diff] [blame] | 3245 | struct weston_pointer *pointer = grab->pointer; |
Neil Roberts | 96d790e | 2013-09-19 17:32:00 +0100 | [diff] [blame] | 3246 | struct wl_resource *resource; |
Kristian Høgsberg | be6403e | 2013-05-08 21:03:21 -0400 | [diff] [blame] | 3247 | wl_fixed_t sx, sy; |
Kristian Høgsberg | b3cca0a | 2012-01-04 22:19:14 -0500 | [diff] [blame] | 3248 | |
Jonas Ådahl | 61917c8 | 2014-08-11 22:44:02 +0200 | [diff] [blame] | 3249 | if (pointer->focus) { |
| 3250 | weston_view_from_global_fixed(pointer->focus, x, y, |
| 3251 | &pointer->sx, &pointer->sy); |
| 3252 | } |
| 3253 | |
Giulio Camuffo | 1959ab8 | 2013-11-14 23:42:52 +0100 | [diff] [blame] | 3254 | weston_pointer_move(pointer, x, y); |
| 3255 | |
Neil Roberts | 96d790e | 2013-09-19 17:32:00 +0100 | [diff] [blame] | 3256 | wl_resource_for_each(resource, &pointer->focus_resource_list) { |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 3257 | weston_view_from_global_fixed(pointer->focus, |
| 3258 | pointer->x, pointer->y, |
| 3259 | &sx, &sy); |
Neil Roberts | 96d790e | 2013-09-19 17:32:00 +0100 | [diff] [blame] | 3260 | wl_pointer_send_motion(resource, time, sx, sy); |
Kristian Høgsberg | be6403e | 2013-05-08 21:03:21 -0400 | [diff] [blame] | 3261 | } |
Kristian Høgsberg | b3cca0a | 2012-01-04 22:19:14 -0500 | [diff] [blame] | 3262 | } |
| 3263 | |
| 3264 | static void |
Kristian Høgsberg | 02bbabb | 2013-05-06 22:15:05 -0400 | [diff] [blame] | 3265 | popup_grab_button(struct weston_pointer_grab *grab, |
Daniel Stone | 4dbadb1 | 2012-05-30 16:31:51 +0100 | [diff] [blame] | 3266 | uint32_t time, uint32_t button, uint32_t state_w) |
Kristian Høgsberg | b3cca0a | 2012-01-04 22:19:14 -0500 | [diff] [blame] | 3267 | { |
| 3268 | struct wl_resource *resource; |
Giulio Camuffo | 5085a75 | 2013-03-25 21:42:45 +0100 | [diff] [blame] | 3269 | struct shell_seat *shseat = |
| 3270 | container_of(grab, struct shell_seat, popup_grab.grab); |
Rob Bradford | 880ebc7 | 2013-07-22 17:31:38 +0100 | [diff] [blame] | 3271 | struct wl_display *display = shseat->seat->compositor->wl_display; |
Daniel Stone | 4dbadb1 | 2012-05-30 16:31:51 +0100 | [diff] [blame] | 3272 | enum wl_pointer_button_state state = state_w; |
Kristian Høgsberg | eae5de7 | 2012-04-11 22:42:15 -0400 | [diff] [blame] | 3273 | uint32_t serial; |
Neil Roberts | 96d790e | 2013-09-19 17:32:00 +0100 | [diff] [blame] | 3274 | struct wl_list *resource_list; |
Kristian Høgsberg | b3cca0a | 2012-01-04 22:19:14 -0500 | [diff] [blame] | 3275 | |
Neil Roberts | 96d790e | 2013-09-19 17:32:00 +0100 | [diff] [blame] | 3276 | resource_list = &grab->pointer->focus_resource_list; |
| 3277 | if (!wl_list_empty(resource_list)) { |
Kristian Høgsberg | eae5de7 | 2012-04-11 22:42:15 -0400 | [diff] [blame] | 3278 | serial = wl_display_get_serial(display); |
Neil Roberts | 96d790e | 2013-09-19 17:32:00 +0100 | [diff] [blame] | 3279 | wl_resource_for_each(resource, resource_list) { |
| 3280 | wl_pointer_send_button(resource, serial, |
| 3281 | time, button, state); |
| 3282 | } |
Daniel Stone | 4dbadb1 | 2012-05-30 16:31:51 +0100 | [diff] [blame] | 3283 | } else if (state == WL_POINTER_BUTTON_STATE_RELEASED && |
Giulio Camuffo | 5085a75 | 2013-03-25 21:42:45 +0100 | [diff] [blame] | 3284 | (shseat->popup_grab.initial_up || |
Derek Foreman | f7b2f8b | 2015-07-15 13:00:41 -0500 | [diff] [blame] | 3285 | time - grab->pointer->grab_time > 500)) { |
Kristian Høgsberg | 57e0907 | 2012-10-30 14:07:27 -0400 | [diff] [blame] | 3286 | popup_grab_end(grab->pointer); |
Kristian Høgsberg | b3cca0a | 2012-01-04 22:19:14 -0500 | [diff] [blame] | 3287 | } |
| 3288 | |
Daniel Stone | 4dbadb1 | 2012-05-30 16:31:51 +0100 | [diff] [blame] | 3289 | 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 = 1; |
Kristian Høgsberg | b3cca0a | 2012-01-04 22:19:14 -0500 | [diff] [blame] | 3291 | } |
| 3292 | |
Jonas Ådahl | 1ea343e | 2013-10-25 23:18:05 +0200 | [diff] [blame] | 3293 | static void |
| 3294 | popup_grab_cancel(struct weston_pointer_grab *grab) |
| 3295 | { |
| 3296 | popup_grab_end(grab->pointer); |
| 3297 | } |
| 3298 | |
Kristian Høgsberg | 02bbabb | 2013-05-06 22:15:05 -0400 | [diff] [blame] | 3299 | static const struct weston_pointer_grab_interface popup_grab_interface = { |
Kristian Høgsberg | b3cca0a | 2012-01-04 22:19:14 -0500 | [diff] [blame] | 3300 | popup_grab_focus, |
| 3301 | popup_grab_motion, |
| 3302 | popup_grab_button, |
Jonas Ådahl | 1ea343e | 2013-10-25 23:18:05 +0200 | [diff] [blame] | 3303 | popup_grab_cancel, |
Kristian Høgsberg | b3cca0a | 2012-01-04 22:19:14 -0500 | [diff] [blame] | 3304 | }; |
| 3305 | |
| 3306 | static void |
Jonny Lamb | 76cf1fe | 2014-08-20 11:27:10 +0200 | [diff] [blame] | 3307 | touch_popup_grab_down(struct weston_touch_grab *grab, uint32_t time, |
Giulio Camuffo | 61ed7b6 | 2015-07-08 11:55:28 +0300 | [diff] [blame] | 3308 | int touch_id, wl_fixed_t x, wl_fixed_t y) |
Jonny Lamb | 76cf1fe | 2014-08-20 11:27:10 +0200 | [diff] [blame] | 3309 | { |
| 3310 | struct wl_resource *resource; |
| 3311 | struct shell_seat *shseat = |
| 3312 | container_of(grab, struct shell_seat, popup_grab.touch_grab); |
| 3313 | struct wl_display *display = shseat->seat->compositor->wl_display; |
| 3314 | uint32_t serial; |
| 3315 | struct wl_list *resource_list; |
Giulio Camuffo | 61ed7b6 | 2015-07-08 11:55:28 +0300 | [diff] [blame] | 3316 | wl_fixed_t sx, sy; |
| 3317 | |
| 3318 | weston_view_from_global_fixed(grab->touch->focus, x, y, &sx, &sy); |
Jonny Lamb | 76cf1fe | 2014-08-20 11:27:10 +0200 | [diff] [blame] | 3319 | |
| 3320 | resource_list = &grab->touch->focus_resource_list; |
| 3321 | if (!wl_list_empty(resource_list)) { |
| 3322 | serial = wl_display_get_serial(display); |
| 3323 | wl_resource_for_each(resource, resource_list) { |
| 3324 | wl_touch_send_down(resource, serial, time, |
| 3325 | grab->touch->focus->surface->resource, |
| 3326 | touch_id, sx, sy); |
| 3327 | } |
| 3328 | } |
| 3329 | } |
| 3330 | |
| 3331 | static void |
| 3332 | touch_popup_grab_up(struct weston_touch_grab *grab, uint32_t time, int touch_id) |
| 3333 | { |
| 3334 | struct wl_resource *resource; |
| 3335 | struct shell_seat *shseat = |
| 3336 | container_of(grab, struct shell_seat, popup_grab.touch_grab); |
| 3337 | struct wl_display *display = shseat->seat->compositor->wl_display; |
| 3338 | uint32_t serial; |
| 3339 | struct wl_list *resource_list; |
| 3340 | |
| 3341 | resource_list = &grab->touch->focus_resource_list; |
| 3342 | if (!wl_list_empty(resource_list)) { |
| 3343 | serial = wl_display_get_serial(display); |
| 3344 | wl_resource_for_each(resource, resource_list) { |
| 3345 | wl_touch_send_up(resource, serial, time, touch_id); |
| 3346 | } |
| 3347 | } |
| 3348 | } |
| 3349 | |
| 3350 | static void |
| 3351 | touch_popup_grab_motion(struct weston_touch_grab *grab, uint32_t time, |
Giulio Camuffo | 61ed7b6 | 2015-07-08 11:55:28 +0300 | [diff] [blame] | 3352 | int touch_id, wl_fixed_t x, wl_fixed_t y) |
Jonny Lamb | 76cf1fe | 2014-08-20 11:27:10 +0200 | [diff] [blame] | 3353 | { |
| 3354 | struct wl_resource *resource; |
| 3355 | struct wl_list *resource_list; |
Giulio Camuffo | 61ed7b6 | 2015-07-08 11:55:28 +0300 | [diff] [blame] | 3356 | wl_fixed_t sx, sy; |
| 3357 | |
| 3358 | weston_view_from_global_fixed(grab->touch->focus, x, y, &sx, &sy); |
Jonny Lamb | 76cf1fe | 2014-08-20 11:27:10 +0200 | [diff] [blame] | 3359 | |
| 3360 | resource_list = &grab->touch->focus_resource_list; |
| 3361 | if (!wl_list_empty(resource_list)) { |
| 3362 | wl_resource_for_each(resource, resource_list) { |
| 3363 | wl_touch_send_motion(resource, time, touch_id, sx, sy); |
| 3364 | } |
| 3365 | } |
| 3366 | } |
| 3367 | |
| 3368 | static void |
| 3369 | touch_popup_grab_frame(struct weston_touch_grab *grab) |
| 3370 | { |
| 3371 | } |
| 3372 | |
| 3373 | static void |
| 3374 | touch_popup_grab_cancel(struct weston_touch_grab *grab) |
| 3375 | { |
| 3376 | touch_popup_grab_end(grab->touch); |
| 3377 | } |
| 3378 | |
| 3379 | static const struct weston_touch_grab_interface touch_popup_grab_interface = { |
| 3380 | touch_popup_grab_down, |
| 3381 | touch_popup_grab_up, |
| 3382 | touch_popup_grab_motion, |
| 3383 | touch_popup_grab_frame, |
| 3384 | touch_popup_grab_cancel, |
| 3385 | }; |
| 3386 | |
| 3387 | static void |
Rafael Antognolli | e2a3455 | 2013-12-03 15:35:45 -0200 | [diff] [blame] | 3388 | shell_surface_send_popup_done(struct shell_surface *shsurf) |
| 3389 | { |
| 3390 | if (shell_surface_is_wl_shell_surface(shsurf)) |
| 3391 | wl_shell_surface_send_popup_done(shsurf->resource); |
| 3392 | else if (shell_surface_is_xdg_popup(shsurf)) |
Jasper St. Pierre | ecf2a0f | 2015-02-13 14:01:56 +0800 | [diff] [blame] | 3393 | xdg_popup_send_popup_done(shsurf->resource); |
Rafael Antognolli | e2a3455 | 2013-12-03 15:35:45 -0200 | [diff] [blame] | 3394 | } |
| 3395 | |
| 3396 | static void |
Kristian Høgsberg | 02bbabb | 2013-05-06 22:15:05 -0400 | [diff] [blame] | 3397 | popup_grab_end(struct weston_pointer *pointer) |
Kristian Høgsberg | 57e0907 | 2012-10-30 14:07:27 -0400 | [diff] [blame] | 3398 | { |
Kristian Høgsberg | 02bbabb | 2013-05-06 22:15:05 -0400 | [diff] [blame] | 3399 | struct weston_pointer_grab *grab = pointer->grab; |
Giulio Camuffo | 5085a75 | 2013-03-25 21:42:45 +0100 | [diff] [blame] | 3400 | struct shell_seat *shseat = |
| 3401 | container_of(grab, struct shell_seat, popup_grab.grab); |
| 3402 | struct shell_surface *shsurf; |
Jonas Ådahl | c2b1011 | 2015-02-13 14:01:53 +0800 | [diff] [blame] | 3403 | struct shell_surface *next; |
Kristian Høgsberg | 57e0907 | 2012-10-30 14:07:27 -0400 | [diff] [blame] | 3404 | |
| 3405 | if (pointer->grab->interface == &popup_grab_interface) { |
Kristian Høgsberg | 02bbabb | 2013-05-06 22:15:05 -0400 | [diff] [blame] | 3406 | weston_pointer_end_grab(grab->pointer); |
Giulio Camuffo | 5085a75 | 2013-03-25 21:42:45 +0100 | [diff] [blame] | 3407 | shseat->popup_grab.client = NULL; |
Philipp Brüschweiler | 63e7be6 | 2013-04-15 21:09:54 +0200 | [diff] [blame] | 3408 | shseat->popup_grab.grab.interface = NULL; |
| 3409 | assert(!wl_list_empty(&shseat->popup_grab.surfaces_list)); |
Giulio Camuffo | 5085a75 | 2013-03-25 21:42:45 +0100 | [diff] [blame] | 3410 | /* Send the popup_done event to all the popups open */ |
Jonas Ådahl | c2b1011 | 2015-02-13 14:01:53 +0800 | [diff] [blame] | 3411 | wl_list_for_each_safe(shsurf, next, |
| 3412 | &shseat->popup_grab.surfaces_list, |
| 3413 | popup.grab_link) { |
Rafael Antognolli | e2a3455 | 2013-12-03 15:35:45 -0200 | [diff] [blame] | 3414 | shell_surface_send_popup_done(shsurf); |
Giulio Camuffo | 5085a75 | 2013-03-25 21:42:45 +0100 | [diff] [blame] | 3415 | shsurf->popup.shseat = NULL; |
Jonas Ådahl | c2b1011 | 2015-02-13 14:01:53 +0800 | [diff] [blame] | 3416 | wl_list_init(&shsurf->popup.grab_link); |
Giulio Camuffo | 5085a75 | 2013-03-25 21:42:45 +0100 | [diff] [blame] | 3417 | } |
Giulio Camuffo | 5085a75 | 2013-03-25 21:42:45 +0100 | [diff] [blame] | 3418 | wl_list_init(&shseat->popup_grab.surfaces_list); |
| 3419 | } |
| 3420 | } |
| 3421 | |
| 3422 | static void |
Jonny Lamb | 76cf1fe | 2014-08-20 11:27:10 +0200 | [diff] [blame] | 3423 | touch_popup_grab_end(struct weston_touch *touch) |
| 3424 | { |
| 3425 | struct weston_touch_grab *grab = touch->grab; |
| 3426 | struct shell_seat *shseat = |
| 3427 | container_of(grab, struct shell_seat, popup_grab.touch_grab); |
| 3428 | struct shell_surface *shsurf; |
Jonas Ådahl | c2b1011 | 2015-02-13 14:01:53 +0800 | [diff] [blame] | 3429 | struct shell_surface *next; |
Jonny Lamb | 76cf1fe | 2014-08-20 11:27:10 +0200 | [diff] [blame] | 3430 | |
| 3431 | if (touch->grab->interface == &touch_popup_grab_interface) { |
| 3432 | weston_touch_end_grab(grab->touch); |
| 3433 | shseat->popup_grab.client = NULL; |
| 3434 | shseat->popup_grab.touch_grab.interface = NULL; |
| 3435 | assert(!wl_list_empty(&shseat->popup_grab.surfaces_list)); |
| 3436 | /* Send the popup_done event to all the popups open */ |
Jonas Ådahl | c2b1011 | 2015-02-13 14:01:53 +0800 | [diff] [blame] | 3437 | wl_list_for_each_safe(shsurf, next, |
| 3438 | &shseat->popup_grab.surfaces_list, |
| 3439 | popup.grab_link) { |
Jonny Lamb | 76cf1fe | 2014-08-20 11:27:10 +0200 | [diff] [blame] | 3440 | shell_surface_send_popup_done(shsurf); |
| 3441 | shsurf->popup.shseat = NULL; |
Jonas Ådahl | c2b1011 | 2015-02-13 14:01:53 +0800 | [diff] [blame] | 3442 | wl_list_init(&shsurf->popup.grab_link); |
Jonny Lamb | 76cf1fe | 2014-08-20 11:27:10 +0200 | [diff] [blame] | 3443 | } |
Jonny Lamb | 76cf1fe | 2014-08-20 11:27:10 +0200 | [diff] [blame] | 3444 | wl_list_init(&shseat->popup_grab.surfaces_list); |
| 3445 | } |
| 3446 | } |
| 3447 | |
Jasper St. Pierre | da6ecd0 | 2015-02-27 18:35:45 +0800 | [diff] [blame] | 3448 | static struct shell_surface * |
| 3449 | get_top_popup(struct shell_seat *shseat) |
| 3450 | { |
| 3451 | struct shell_surface *shsurf; |
| 3452 | |
| 3453 | if (wl_list_empty(&shseat->popup_grab.surfaces_list)) { |
| 3454 | return NULL; |
| 3455 | } else { |
| 3456 | shsurf = container_of(shseat->popup_grab.surfaces_list.next, |
| 3457 | struct shell_surface, |
| 3458 | popup.grab_link); |
| 3459 | return shsurf; |
| 3460 | } |
| 3461 | } |
| 3462 | |
| 3463 | static int |
Jonas Ådahl | 01193ae | 2015-02-13 14:01:54 +0800 | [diff] [blame] | 3464 | add_popup_grab(struct shell_surface *shsurf, |
| 3465 | struct shell_seat *shseat, |
| 3466 | int32_t type) |
Giulio Camuffo | 5085a75 | 2013-03-25 21:42:45 +0100 | [diff] [blame] | 3467 | { |
Kristian Høgsberg | e314875 | 2013-05-06 23:19:49 -0400 | [diff] [blame] | 3468 | struct weston_seat *seat = shseat->seat; |
Jasper St. Pierre | da6ecd0 | 2015-02-27 18:35:45 +0800 | [diff] [blame] | 3469 | struct shell_surface *parent, *top_surface; |
Derek Foreman | 1281a36 | 2015-07-31 16:55:32 -0500 | [diff] [blame] | 3470 | struct weston_pointer *pointer = weston_seat_get_pointer(seat); |
| 3471 | struct weston_touch *touch = weston_seat_get_touch(seat); |
Jasper St. Pierre | da6ecd0 | 2015-02-27 18:35:45 +0800 | [diff] [blame] | 3472 | |
| 3473 | parent = get_shell_surface(shsurf->parent); |
| 3474 | top_surface = get_top_popup(shseat); |
| 3475 | if (shell_surface_is_xdg_popup(shsurf) && |
Dima Ryazanov | 497f25d | 2015-04-08 11:51:57 -0700 | [diff] [blame] | 3476 | (!parent || |
| 3477 | (top_surface == NULL && !shell_surface_is_xdg_surface(parent)) || |
Jasper St. Pierre | da6ecd0 | 2015-02-27 18:35:45 +0800 | [diff] [blame] | 3478 | (top_surface != NULL && parent != top_surface))) { |
Jonas Ådahl | ee45a55 | 2015-03-18 16:37:47 +0800 | [diff] [blame] | 3479 | wl_resource_post_error(shsurf->owner_resource, |
| 3480 | XDG_SHELL_ERROR_NOT_THE_TOPMOST_POPUP, |
Jasper St. Pierre | da6ecd0 | 2015-02-27 18:35:45 +0800 | [diff] [blame] | 3481 | "xdg_popup was not created on the " |
| 3482 | "topmost popup"); |
| 3483 | return -1; |
| 3484 | } |
Giulio Camuffo | 5085a75 | 2013-03-25 21:42:45 +0100 | [diff] [blame] | 3485 | |
| 3486 | if (wl_list_empty(&shseat->popup_grab.surfaces_list)) { |
Jonny Lamb | 76cf1fe | 2014-08-20 11:27:10 +0200 | [diff] [blame] | 3487 | shseat->popup_grab.type = type; |
Jonas Ådahl | 01193ae | 2015-02-13 14:01:54 +0800 | [diff] [blame] | 3488 | shseat->popup_grab.client = |
| 3489 | wl_resource_get_client(shsurf->resource); |
Jonny Lamb | 76cf1fe | 2014-08-20 11:27:10 +0200 | [diff] [blame] | 3490 | |
| 3491 | if (type == POINTER) { |
Jonas Ådahl | 01193ae | 2015-02-13 14:01:54 +0800 | [diff] [blame] | 3492 | shseat->popup_grab.grab.interface = |
| 3493 | &popup_grab_interface; |
| 3494 | |
| 3495 | /* We must make sure here that this popup was opened |
| 3496 | * after a mouse press, and not just by moving around |
| 3497 | * with other popups already open. */ |
Derek Foreman | 1281a36 | 2015-07-31 16:55:32 -0500 | [diff] [blame] | 3498 | if (pointer->button_count > 0) |
Jonny Lamb | 76cf1fe | 2014-08-20 11:27:10 +0200 | [diff] [blame] | 3499 | shseat->popup_grab.initial_up = 0; |
| 3500 | } else if (type == TOUCH) { |
Jonas Ådahl | 01193ae | 2015-02-13 14:01:54 +0800 | [diff] [blame] | 3501 | shseat->popup_grab.touch_grab.interface = |
| 3502 | &touch_popup_grab_interface; |
Jonny Lamb | 76cf1fe | 2014-08-20 11:27:10 +0200 | [diff] [blame] | 3503 | } |
Giulio Camuffo | 5085a75 | 2013-03-25 21:42:45 +0100 | [diff] [blame] | 3504 | |
Jonas Ådahl | 01193ae | 2015-02-13 14:01:54 +0800 | [diff] [blame] | 3505 | wl_list_insert(&shseat->popup_grab.surfaces_list, |
| 3506 | &shsurf->popup.grab_link); |
Jonny Lamb | 76cf1fe | 2014-08-20 11:27:10 +0200 | [diff] [blame] | 3507 | |
Jonas Ådahl | 01193ae | 2015-02-13 14:01:54 +0800 | [diff] [blame] | 3508 | if (type == POINTER) { |
Derek Foreman | 1281a36 | 2015-07-31 16:55:32 -0500 | [diff] [blame] | 3509 | weston_pointer_start_grab(pointer, |
Jonas Ådahl | 01193ae | 2015-02-13 14:01:54 +0800 | [diff] [blame] | 3510 | &shseat->popup_grab.grab); |
| 3511 | } else if (type == TOUCH) { |
Derek Foreman | 1281a36 | 2015-07-31 16:55:32 -0500 | [diff] [blame] | 3512 | weston_touch_start_grab(touch, |
Jonas Ådahl | 01193ae | 2015-02-13 14:01:54 +0800 | [diff] [blame] | 3513 | &shseat->popup_grab.touch_grab); |
| 3514 | } |
Rob Bradford | dfe3105 | 2013-06-26 19:49:11 +0100 | [diff] [blame] | 3515 | } else { |
Jonas Ådahl | 01193ae | 2015-02-13 14:01:54 +0800 | [diff] [blame] | 3516 | wl_list_insert(&shseat->popup_grab.surfaces_list, |
| 3517 | &shsurf->popup.grab_link); |
Giulio Camuffo | 5085a75 | 2013-03-25 21:42:45 +0100 | [diff] [blame] | 3518 | } |
Jasper St. Pierre | da6ecd0 | 2015-02-27 18:35:45 +0800 | [diff] [blame] | 3519 | |
| 3520 | return 0; |
Giulio Camuffo | 5085a75 | 2013-03-25 21:42:45 +0100 | [diff] [blame] | 3521 | } |
| 3522 | |
| 3523 | static void |
| 3524 | remove_popup_grab(struct shell_surface *shsurf) |
| 3525 | { |
| 3526 | struct shell_seat *shseat = shsurf->popup.shseat; |
| 3527 | |
Jasper St. Pierre | da6ecd0 | 2015-02-27 18:35:45 +0800 | [diff] [blame] | 3528 | if (shell_surface_is_xdg_popup(shsurf) && |
| 3529 | get_top_popup(shseat) != shsurf) { |
Jonas Ådahl | ee45a55 | 2015-03-18 16:37:47 +0800 | [diff] [blame] | 3530 | wl_resource_post_error(shsurf->owner_resource, |
| 3531 | XDG_SHELL_ERROR_NOT_THE_TOPMOST_POPUP, |
Jasper St. Pierre | da6ecd0 | 2015-02-27 18:35:45 +0800 | [diff] [blame] | 3532 | "xdg_popup was destroyed while it was " |
| 3533 | "not the topmost popup."); |
| 3534 | return; |
| 3535 | } |
| 3536 | |
Giulio Camuffo | 5085a75 | 2013-03-25 21:42:45 +0100 | [diff] [blame] | 3537 | wl_list_remove(&shsurf->popup.grab_link); |
| 3538 | wl_list_init(&shsurf->popup.grab_link); |
| 3539 | if (wl_list_empty(&shseat->popup_grab.surfaces_list)) { |
Jonny Lamb | 76cf1fe | 2014-08-20 11:27:10 +0200 | [diff] [blame] | 3540 | if (shseat->popup_grab.type == POINTER) { |
| 3541 | weston_pointer_end_grab(shseat->popup_grab.grab.pointer); |
| 3542 | shseat->popup_grab.grab.interface = NULL; |
| 3543 | } else if (shseat->popup_grab.type == TOUCH) { |
| 3544 | weston_touch_end_grab(shseat->popup_grab.touch_grab.touch); |
| 3545 | shseat->popup_grab.touch_grab.interface = NULL; |
| 3546 | } |
Kristian Høgsberg | 57e0907 | 2012-10-30 14:07:27 -0400 | [diff] [blame] | 3547 | } |
| 3548 | } |
| 3549 | |
Jasper St. Pierre | da6ecd0 | 2015-02-27 18:35:45 +0800 | [diff] [blame] | 3550 | static int |
Kristian Høgsberg | 3730f36 | 2012-04-13 12:40:07 -0400 | [diff] [blame] | 3551 | shell_map_popup(struct shell_surface *shsurf) |
Kristian Høgsberg | b3cca0a | 2012-01-04 22:19:14 -0500 | [diff] [blame] | 3552 | { |
Giulio Camuffo | 5085a75 | 2013-03-25 21:42:45 +0100 | [diff] [blame] | 3553 | struct shell_seat *shseat = shsurf->popup.shseat; |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 3554 | struct weston_view *parent_view = get_default_view(shsurf->parent); |
Derek Foreman | 1281a36 | 2015-07-31 16:55:32 -0500 | [diff] [blame] | 3555 | struct weston_pointer *pointer = weston_seat_get_pointer(shseat->seat); |
| 3556 | struct weston_touch *touch = weston_seat_get_touch(shseat->seat); |
Kristian Høgsberg | b3cca0a | 2012-01-04 22:19:14 -0500 | [diff] [blame] | 3557 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 3558 | shsurf->surface->output = parent_view->output; |
| 3559 | shsurf->view->output = parent_view->output; |
Kristian Høgsberg | b3cca0a | 2012-01-04 22:19:14 -0500 | [diff] [blame] | 3560 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 3561 | weston_view_set_transform_parent(shsurf->view, parent_view); |
| 3562 | weston_view_set_position(shsurf->view, shsurf->popup.x, shsurf->popup.y); |
| 3563 | weston_view_update_transform(shsurf->view); |
Kristian Høgsberg | b3cca0a | 2012-01-04 22:19:14 -0500 | [diff] [blame] | 3564 | |
Derek Foreman | 1281a36 | 2015-07-31 16:55:32 -0500 | [diff] [blame] | 3565 | if (pointer && |
| 3566 | pointer->grab_serial == shsurf->popup.serial) { |
Jasper St. Pierre | da6ecd0 | 2015-02-27 18:35:45 +0800 | [diff] [blame] | 3567 | if (add_popup_grab(shsurf, shseat, POINTER) != 0) |
| 3568 | return -1; |
Derek Foreman | 1281a36 | 2015-07-31 16:55:32 -0500 | [diff] [blame] | 3569 | } else if (touch && |
| 3570 | touch->grab_serial == shsurf->popup.serial) { |
Jasper St. Pierre | da6ecd0 | 2015-02-27 18:35:45 +0800 | [diff] [blame] | 3571 | if (add_popup_grab(shsurf, shseat, TOUCH) != 0) |
| 3572 | return -1; |
Kristian Høgsberg | 3730f36 | 2012-04-13 12:40:07 -0400 | [diff] [blame] | 3573 | } else { |
Rafael Antognolli | e2a3455 | 2013-12-03 15:35:45 -0200 | [diff] [blame] | 3574 | shell_surface_send_popup_done(shsurf); |
Giulio Camuffo | 5085a75 | 2013-03-25 21:42:45 +0100 | [diff] [blame] | 3575 | shseat->popup_grab.client = NULL; |
Kristian Høgsberg | 3730f36 | 2012-04-13 12:40:07 -0400 | [diff] [blame] | 3576 | } |
Jasper St. Pierre | da6ecd0 | 2015-02-27 18:35:45 +0800 | [diff] [blame] | 3577 | |
| 3578 | return 0; |
Kristian Høgsberg | b3cca0a | 2012-01-04 22:19:14 -0500 | [diff] [blame] | 3579 | } |
| 3580 | |
Pekka Paalanen | 9d1613e | 2011-11-25 12:09:16 +0200 | [diff] [blame] | 3581 | static const struct wl_shell_surface_interface shell_surface_implementation = { |
Scott Moreau | ff1db4a | 2012-04-17 19:06:18 -0600 | [diff] [blame] | 3582 | shell_surface_pong, |
Pekka Paalanen | 9d1613e | 2011-11-25 12:09:16 +0200 | [diff] [blame] | 3583 | shell_surface_move, |
| 3584 | shell_surface_resize, |
| 3585 | shell_surface_set_toplevel, |
| 3586 | shell_surface_set_transient, |
Kristian Høgsberg | b3cca0a | 2012-01-04 22:19:14 -0500 | [diff] [blame] | 3587 | shell_surface_set_fullscreen, |
Juan Zhao | 96879df | 2012-02-07 08:45:41 +0800 | [diff] [blame] | 3588 | shell_surface_set_popup, |
Kristian Høgsberg | e7afd91 | 2012-05-02 09:47:44 -0400 | [diff] [blame] | 3589 | shell_surface_set_maximized, |
| 3590 | shell_surface_set_title, |
| 3591 | shell_surface_set_class |
Pekka Paalanen | 9d1613e | 2011-11-25 12:09:16 +0200 | [diff] [blame] | 3592 | }; |
| 3593 | |
| 3594 | static void |
Tiago Vignatti | bc052c9 | 2012-04-19 16:18:18 +0300 | [diff] [blame] | 3595 | destroy_shell_surface(struct shell_surface *shsurf) |
Pekka Paalanen | 9d1613e | 2011-11-25 12:09:16 +0200 | [diff] [blame] | 3596 | { |
Kristian Høgsberg | 9046d24 | 2014-01-10 00:25:30 -0800 | [diff] [blame] | 3597 | struct shell_surface *child, *next; |
| 3598 | |
Jason Ekstrand | 651f00e | 2013-06-14 10:07:54 -0500 | [diff] [blame] | 3599 | wl_signal_emit(&shsurf->destroy_signal, shsurf); |
| 3600 | |
Giulio Camuffo | 5085a75 | 2013-03-25 21:42:45 +0100 | [diff] [blame] | 3601 | if (!wl_list_empty(&shsurf->popup.grab_link)) { |
| 3602 | remove_popup_grab(shsurf); |
| 3603 | } |
Kristian Høgsberg | b3cca0a | 2012-01-04 22:19:14 -0500 | [diff] [blame] | 3604 | |
Alex Wu | bd3354b | 2012-04-17 17:20:49 +0800 | [diff] [blame] | 3605 | if (shsurf->fullscreen.type == WL_SHELL_SURFACE_FULLSCREEN_METHOD_DRIVER && |
Alexander Larsson | f82b6ca | 2013-05-28 16:23:39 +0200 | [diff] [blame] | 3606 | shell_surface_is_top_fullscreen(shsurf)) |
| 3607 | restore_output_mode (shsurf->fullscreen_output); |
Pekka Paalanen | 9d1613e | 2011-11-25 12:09:16 +0200 | [diff] [blame] | 3608 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 3609 | if (shsurf->fullscreen.black_view) |
| 3610 | weston_surface_destroy(shsurf->fullscreen.black_view->surface); |
Alex Wu | aa08e2d | 2012-03-05 11:01:40 +0800 | [diff] [blame] | 3611 | |
Alex Wu | bd3354b | 2012-04-17 17:20:49 +0800 | [diff] [blame] | 3612 | /* As destroy_resource() use wl_list_for_each_safe(), |
| 3613 | * we can always remove the listener. |
| 3614 | */ |
| 3615 | wl_list_remove(&shsurf->surface_destroy_listener.link); |
| 3616 | shsurf->surface->configure = NULL; |
Pekka Paalanen | 8274d90 | 2014-08-06 19:36:51 +0300 | [diff] [blame] | 3617 | weston_surface_set_label_func(shsurf->surface, NULL); |
Scott Moreau | 976a050 | 2013-03-07 10:15:17 -0700 | [diff] [blame] | 3618 | free(shsurf->title); |
Alex Wu | bd3354b | 2012-04-17 17:20:49 +0800 | [diff] [blame] | 3619 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 3620 | weston_view_destroy(shsurf->view); |
| 3621 | |
Philip Withnall | 648a4dd | 2013-11-25 18:01:44 +0000 | [diff] [blame] | 3622 | wl_list_remove(&shsurf->children_link); |
Emilio Pozuelo Monfort | adaa20c | 2014-01-28 13:54:16 +0100 | [diff] [blame] | 3623 | wl_list_for_each_safe(child, next, &shsurf->children_list, children_link) |
| 3624 | shell_surface_set_parent(child, NULL); |
Philip Withnall | 648a4dd | 2013-11-25 18:01:44 +0000 | [diff] [blame] | 3625 | |
Pekka Paalanen | 9d1613e | 2011-11-25 12:09:16 +0200 | [diff] [blame] | 3626 | wl_list_remove(&shsurf->link); |
| 3627 | free(shsurf); |
| 3628 | } |
| 3629 | |
| 3630 | static void |
Tiago Vignatti | bc052c9 | 2012-04-19 16:18:18 +0300 | [diff] [blame] | 3631 | shell_destroy_shell_surface(struct wl_resource *resource) |
| 3632 | { |
Jason Ekstrand | 651f00e | 2013-06-14 10:07:54 -0500 | [diff] [blame] | 3633 | struct shell_surface *shsurf = wl_resource_get_user_data(resource); |
Tiago Vignatti | bc052c9 | 2012-04-19 16:18:18 +0300 | [diff] [blame] | 3634 | |
Bryan Cain | a46b946 | 2014-04-04 17:41:24 -0500 | [diff] [blame] | 3635 | if (!wl_list_empty(&shsurf->popup.grab_link)) |
| 3636 | remove_popup_grab(shsurf); |
Jonas Ådahl | 49d77d2 | 2015-03-18 16:20:51 +0800 | [diff] [blame] | 3637 | wl_list_remove(wl_resource_get_link(shsurf->resource)); |
Kristian Høgsberg | 160fe75 | 2014-03-11 10:19:10 -0700 | [diff] [blame] | 3638 | shsurf->resource = NULL; |
Tiago Vignatti | bc052c9 | 2012-04-19 16:18:18 +0300 | [diff] [blame] | 3639 | } |
| 3640 | |
| 3641 | static void |
Kristian Høgsberg | 27e3052 | 2012-04-11 23:18:23 -0400 | [diff] [blame] | 3642 | shell_handle_surface_destroy(struct wl_listener *listener, void *data) |
Pekka Paalanen | 9d1613e | 2011-11-25 12:09:16 +0200 | [diff] [blame] | 3643 | { |
| 3644 | struct shell_surface *shsurf = container_of(listener, |
| 3645 | struct shell_surface, |
| 3646 | surface_destroy_listener); |
| 3647 | |
Jason Ekstrand | 651f00e | 2013-06-14 10:07:54 -0500 | [diff] [blame] | 3648 | if (shsurf->resource) |
| 3649 | wl_resource_destroy(shsurf->resource); |
Ander Conselvan de Oliveira | 15f9a26 | 2014-04-29 17:54:02 +0300 | [diff] [blame] | 3650 | |
| 3651 | destroy_shell_surface(shsurf); |
Pekka Paalanen | 9d1613e | 2011-11-25 12:09:16 +0200 | [diff] [blame] | 3652 | } |
| 3653 | |
Kristian Høgsberg | d813445 | 2012-06-21 12:49:02 -0400 | [diff] [blame] | 3654 | static void |
Derek Foreman | 039e9be | 2015-04-14 17:09:06 -0500 | [diff] [blame] | 3655 | fade_out_done_idle_cb(void *data) |
Kristian Høgsberg | 160fe75 | 2014-03-11 10:19:10 -0700 | [diff] [blame] | 3656 | { |
| 3657 | struct shell_surface *shsurf = data; |
| 3658 | |
| 3659 | weston_surface_destroy(shsurf->surface); |
| 3660 | } |
| 3661 | |
| 3662 | static void |
Derek Foreman | 039e9be | 2015-04-14 17:09:06 -0500 | [diff] [blame] | 3663 | fade_out_done(struct weston_view_animation *animation, void *data) |
| 3664 | { |
| 3665 | struct shell_surface *shsurf = data; |
| 3666 | struct wl_event_loop *loop; |
| 3667 | |
| 3668 | loop = wl_display_get_event_loop( |
| 3669 | shsurf->surface->compositor->wl_display); |
| 3670 | |
| 3671 | if (!shsurf->destroying) { |
| 3672 | wl_event_loop_add_idle(loop, fade_out_done_idle_cb, shsurf); |
| 3673 | shsurf->destroying = true; |
| 3674 | } |
| 3675 | } |
| 3676 | |
| 3677 | static void |
Kristian Høgsberg | 160fe75 | 2014-03-11 10:19:10 -0700 | [diff] [blame] | 3678 | handle_resource_destroy(struct wl_listener *listener, void *data) |
| 3679 | { |
| 3680 | struct shell_surface *shsurf = |
| 3681 | container_of(listener, struct shell_surface, |
| 3682 | resource_destroy_listener); |
| 3683 | |
Ander Conselvan de Oliveira | 15f9a26 | 2014-04-29 17:54:02 +0300 | [diff] [blame] | 3684 | if (!weston_surface_is_mapped(shsurf->surface)) |
| 3685 | return; |
| 3686 | |
Kristian Høgsberg | 160fe75 | 2014-03-11 10:19:10 -0700 | [diff] [blame] | 3687 | shsurf->surface->ref_count++; |
| 3688 | |
| 3689 | pixman_region32_fini(&shsurf->surface->pending.input); |
| 3690 | pixman_region32_init(&shsurf->surface->pending.input); |
| 3691 | pixman_region32_fini(&shsurf->surface->input); |
| 3692 | pixman_region32_init(&shsurf->surface->input); |
Jonny Lamb | f322f8e | 2014-08-12 15:13:30 +0200 | [diff] [blame] | 3693 | if (shsurf->shell->win_close_animation_type == ANIMATION_FADE) { |
| 3694 | weston_fade_run(shsurf->view, 1.0, 0.0, 300.0, |
| 3695 | fade_out_done, shsurf); |
| 3696 | } else { |
| 3697 | weston_surface_destroy(shsurf->surface); |
| 3698 | } |
Kristian Høgsberg | 160fe75 | 2014-03-11 10:19:10 -0700 | [diff] [blame] | 3699 | } |
| 3700 | |
| 3701 | static void |
Jason Ekstrand | 918f2dd | 2013-12-02 21:01:53 -0600 | [diff] [blame] | 3702 | shell_surface_configure(struct weston_surface *, int32_t, int32_t); |
Kristian Høgsberg | d813445 | 2012-06-21 12:49:02 -0400 | [diff] [blame] | 3703 | |
Kristian Høgsberg | 1ef2313 | 2013-12-04 00:20:01 -0800 | [diff] [blame] | 3704 | struct shell_surface * |
Kristian Høgsberg | 8334bc1 | 2012-01-03 10:29:47 -0500 | [diff] [blame] | 3705 | get_shell_surface(struct weston_surface *surface) |
Pekka Paalanen | ec2b32f | 2011-11-28 15:12:34 +0200 | [diff] [blame] | 3706 | { |
Kristian Høgsberg | d813445 | 2012-06-21 12:49:02 -0400 | [diff] [blame] | 3707 | if (surface->configure == shell_surface_configure) |
Giulio Camuffo | 7fe01b1 | 2013-03-28 18:02:42 +0100 | [diff] [blame] | 3708 | return surface->configure_private; |
Kristian Høgsberg | d813445 | 2012-06-21 12:49:02 -0400 | [diff] [blame] | 3709 | else |
| 3710 | return NULL; |
Pekka Paalanen | ec2b32f | 2011-11-28 15:12:34 +0200 | [diff] [blame] | 3711 | } |
| 3712 | |
Rafael Antognolli | e2a3455 | 2013-12-03 15:35:45 -0200 | [diff] [blame] | 3713 | static struct shell_surface * |
Jason Ekstrand | 9e9512f | 2014-04-16 21:12:10 -0500 | [diff] [blame] | 3714 | create_common_surface(struct shell_client *owner, void *shell, |
| 3715 | struct weston_surface *surface, |
Rafael Antognolli | e2a3455 | 2013-12-03 15:35:45 -0200 | [diff] [blame] | 3716 | const struct weston_shell_client *client) |
Pekka Paalanen | 9d1613e | 2011-11-25 12:09:16 +0200 | [diff] [blame] | 3717 | { |
Pekka Paalanen | 9d1613e | 2011-11-25 12:09:16 +0200 | [diff] [blame] | 3718 | struct shell_surface *shsurf; |
| 3719 | |
Pekka Paalanen | 50b6747 | 2014-10-01 15:02:41 +0300 | [diff] [blame] | 3720 | assert(surface->configure == NULL); |
Ander Conselvan de Oliveira | 093bfa3 | 2012-03-27 17:36:41 +0300 | [diff] [blame] | 3721 | |
Pekka Paalanen | 9d1613e | 2011-11-25 12:09:16 +0200 | [diff] [blame] | 3722 | shsurf = calloc(1, sizeof *shsurf); |
| 3723 | if (!shsurf) { |
Martin Minarik | 6d11836 | 2012-06-07 18:01:59 +0200 | [diff] [blame] | 3724 | weston_log("no memory to allocate shell surface\n"); |
Kristian Høgsberg | 45ba869 | 2012-05-21 14:27:33 -0400 | [diff] [blame] | 3725 | return NULL; |
Pekka Paalanen | 9d1613e | 2011-11-25 12:09:16 +0200 | [diff] [blame] | 3726 | } |
| 3727 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 3728 | shsurf->view = weston_view_create(surface); |
| 3729 | if (!shsurf->view) { |
| 3730 | weston_log("no memory to allocate shell surface\n"); |
| 3731 | free(shsurf); |
| 3732 | return NULL; |
| 3733 | } |
| 3734 | |
Ander Conselvan de Oliveira | 093bfa3 | 2012-03-27 17:36:41 +0300 | [diff] [blame] | 3735 | surface->configure = shell_surface_configure; |
Giulio Camuffo | 7fe01b1 | 2013-03-28 18:02:42 +0100 | [diff] [blame] | 3736 | surface->configure_private = shsurf; |
Pekka Paalanen | 8274d90 | 2014-08-06 19:36:51 +0300 | [diff] [blame] | 3737 | weston_surface_set_label_func(surface, shell_surface_get_label); |
Ander Conselvan de Oliveira | 093bfa3 | 2012-03-27 17:36:41 +0300 | [diff] [blame] | 3738 | |
Kristian Høgsberg | 160fe75 | 2014-03-11 10:19:10 -0700 | [diff] [blame] | 3739 | shsurf->resource_destroy_listener.notify = handle_resource_destroy; |
| 3740 | wl_resource_add_destroy_listener(surface->resource, |
| 3741 | &shsurf->resource_destroy_listener); |
Jason Ekstrand | 9e9512f | 2014-04-16 21:12:10 -0500 | [diff] [blame] | 3742 | shsurf->owner = owner; |
Kristian Høgsberg | 160fe75 | 2014-03-11 10:19:10 -0700 | [diff] [blame] | 3743 | |
Tiago Vignatti | bc052c9 | 2012-04-19 16:18:18 +0300 | [diff] [blame] | 3744 | shsurf->shell = (struct desktop_shell *) shell; |
Scott Moreau | ff1db4a | 2012-04-17 19:06:18 -0600 | [diff] [blame] | 3745 | shsurf->unresponsive = 0; |
Alex Wu | 4539b08 | 2012-03-01 12:57:46 +0800 | [diff] [blame] | 3746 | shsurf->saved_position_valid = false; |
Rafael Antognolli | 3c4e3f7 | 2013-12-03 15:35:46 -0200 | [diff] [blame] | 3747 | shsurf->saved_size_valid = false; |
Alex Wu | 7bcb8bd | 2012-04-27 09:07:24 +0800 | [diff] [blame] | 3748 | shsurf->saved_rotation_valid = false; |
Pekka Paalanen | 9d1613e | 2011-11-25 12:09:16 +0200 | [diff] [blame] | 3749 | shsurf->surface = surface; |
Alex Wu | 4539b08 | 2012-03-01 12:57:46 +0800 | [diff] [blame] | 3750 | shsurf->fullscreen.type = WL_SHELL_SURFACE_FULLSCREEN_METHOD_DEFAULT; |
| 3751 | shsurf->fullscreen.framerate = 0; |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 3752 | shsurf->fullscreen.black_view = NULL; |
Alex Wu | 4539b08 | 2012-03-01 12:57:46 +0800 | [diff] [blame] | 3753 | wl_list_init(&shsurf->fullscreen.transform.link); |
| 3754 | |
Jasper St. Pierre | 9aa8ce6 | 2014-04-11 16:18:54 -0700 | [diff] [blame] | 3755 | shsurf->output = get_default_output(shsurf->shell->compositor); |
| 3756 | |
Jason Ekstrand | 651f00e | 2013-06-14 10:07:54 -0500 | [diff] [blame] | 3757 | wl_signal_init(&shsurf->destroy_signal); |
Kristian Høgsberg | 27e3052 | 2012-04-11 23:18:23 -0400 | [diff] [blame] | 3758 | shsurf->surface_destroy_listener.notify = shell_handle_surface_destroy; |
Jason Ekstrand | 26ed73c | 2013-06-06 22:34:41 -0500 | [diff] [blame] | 3759 | wl_signal_add(&surface->destroy_signal, |
Kristian Høgsberg | 27e3052 | 2012-04-11 23:18:23 -0400 | [diff] [blame] | 3760 | &shsurf->surface_destroy_listener); |
Pekka Paalanen | 9d1613e | 2011-11-25 12:09:16 +0200 | [diff] [blame] | 3761 | |
| 3762 | /* init link so its safe to always remove it in destroy_shell_surface */ |
| 3763 | wl_list_init(&shsurf->link); |
Giulio Camuffo | 5085a75 | 2013-03-25 21:42:45 +0100 | [diff] [blame] | 3764 | wl_list_init(&shsurf->popup.grab_link); |
Pekka Paalanen | 9d1613e | 2011-11-25 12:09:16 +0200 | [diff] [blame] | 3765 | |
Pekka Paalanen | 460099f | 2012-01-20 16:48:25 +0200 | [diff] [blame] | 3766 | /* empty when not in use */ |
| 3767 | wl_list_init(&shsurf->rotation.transform.link); |
Kristian Høgsberg | 765e27b | 2012-01-27 13:36:13 -0500 | [diff] [blame] | 3768 | weston_matrix_init(&shsurf->rotation.rotation); |
Pekka Paalanen | 460099f | 2012-01-20 16:48:25 +0200 | [diff] [blame] | 3769 | |
Jonas Ådahl | 62fcd04 | 2012-06-13 00:01:23 +0200 | [diff] [blame] | 3770 | wl_list_init(&shsurf->workspace_transform.link); |
| 3771 | |
Philip Withnall | 648a4dd | 2013-11-25 18:01:44 +0000 | [diff] [blame] | 3772 | wl_list_init(&shsurf->children_link); |
| 3773 | wl_list_init(&shsurf->children_list); |
| 3774 | shsurf->parent = NULL; |
| 3775 | |
Pekka Paalanen | b502654 | 2014-11-12 15:09:24 +0200 | [diff] [blame] | 3776 | set_type(shsurf, SHELL_SURFACE_NONE); |
Pekka Paalanen | 9d1613e | 2011-11-25 12:09:16 +0200 | [diff] [blame] | 3777 | |
Kristian Høgsberg | a61ca06 | 2012-05-22 16:05:52 -0400 | [diff] [blame] | 3778 | shsurf->client = client; |
| 3779 | |
Kristian Høgsberg | 45ba869 | 2012-05-21 14:27:33 -0400 | [diff] [blame] | 3780 | return shsurf; |
Tiago Vignatti | bc052c9 | 2012-04-19 16:18:18 +0300 | [diff] [blame] | 3781 | } |
| 3782 | |
Rafael Antognolli | e2a3455 | 2013-12-03 15:35:45 -0200 | [diff] [blame] | 3783 | static struct shell_surface * |
| 3784 | create_shell_surface(void *shell, struct weston_surface *surface, |
| 3785 | const struct weston_shell_client *client) |
| 3786 | { |
Jason Ekstrand | 9e9512f | 2014-04-16 21:12:10 -0500 | [diff] [blame] | 3787 | return create_common_surface(NULL, shell, surface, client); |
Rafael Antognolli | e2a3455 | 2013-12-03 15:35:45 -0200 | [diff] [blame] | 3788 | } |
| 3789 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 3790 | static struct weston_view * |
| 3791 | get_primary_view(void *shell, struct shell_surface *shsurf) |
| 3792 | { |
| 3793 | return shsurf->view; |
| 3794 | } |
| 3795 | |
Tiago Vignatti | bc052c9 | 2012-04-19 16:18:18 +0300 | [diff] [blame] | 3796 | static void |
| 3797 | shell_get_shell_surface(struct wl_client *client, |
| 3798 | struct wl_resource *resource, |
| 3799 | uint32_t id, |
| 3800 | struct wl_resource *surface_resource) |
| 3801 | { |
Jason Ekstrand | 0f2ef7e | 2013-06-14 10:07:53 -0500 | [diff] [blame] | 3802 | struct weston_surface *surface = |
| 3803 | wl_resource_get_user_data(surface_resource); |
Jason Ekstrand | 9e9512f | 2014-04-16 21:12:10 -0500 | [diff] [blame] | 3804 | struct shell_client *sc = wl_resource_get_user_data(resource); |
| 3805 | struct desktop_shell *shell = sc->shell; |
Tiago Vignatti | bc052c9 | 2012-04-19 16:18:18 +0300 | [diff] [blame] | 3806 | struct shell_surface *shsurf; |
| 3807 | |
Pekka Paalanen | 50b6747 | 2014-10-01 15:02:41 +0300 | [diff] [blame] | 3808 | if (weston_surface_set_role(surface, "wl_shell_surface", |
| 3809 | resource, WL_SHELL_ERROR_ROLE) < 0) |
Tiago Vignatti | bc052c9 | 2012-04-19 16:18:18 +0300 | [diff] [blame] | 3810 | return; |
Tiago Vignatti | bc052c9 | 2012-04-19 16:18:18 +0300 | [diff] [blame] | 3811 | |
Jason Ekstrand | 9e9512f | 2014-04-16 21:12:10 -0500 | [diff] [blame] | 3812 | shsurf = create_common_surface(sc, shell, surface, &shell_client); |
Kristian Høgsberg | 9540ea6 | 2012-05-21 14:28:57 -0400 | [diff] [blame] | 3813 | if (!shsurf) { |
Pekka Paalanen | 50b6747 | 2014-10-01 15:02:41 +0300 | [diff] [blame] | 3814 | wl_resource_post_no_memory(surface_resource); |
Kristian Høgsberg | 9540ea6 | 2012-05-21 14:28:57 -0400 | [diff] [blame] | 3815 | return; |
| 3816 | } |
Tiago Vignatti | bc052c9 | 2012-04-19 16:18:18 +0300 | [diff] [blame] | 3817 | |
Jason Ekstrand | a85118c | 2013-06-27 20:17:02 -0500 | [diff] [blame] | 3818 | shsurf->resource = |
| 3819 | wl_resource_create(client, |
| 3820 | &wl_shell_surface_interface, 1, id); |
| 3821 | wl_resource_set_implementation(shsurf->resource, |
| 3822 | &shell_surface_implementation, |
| 3823 | shsurf, shell_destroy_shell_surface); |
Jonas Ådahl | 49d77d2 | 2015-03-18 16:20:51 +0800 | [diff] [blame] | 3824 | wl_list_init(wl_resource_get_link(shsurf->resource)); |
Pekka Paalanen | 9d1613e | 2011-11-25 12:09:16 +0200 | [diff] [blame] | 3825 | } |
| 3826 | |
Rafael Antognolli | e2a3455 | 2013-12-03 15:35:45 -0200 | [diff] [blame] | 3827 | static bool |
| 3828 | shell_surface_is_wl_shell_surface(struct shell_surface *shsurf) |
| 3829 | { |
Kristian Høgsberg | 0b7d995 | 2014-02-03 15:50:38 -0800 | [diff] [blame] | 3830 | /* A shell surface without a resource is created from xwayland |
| 3831 | * and is considered a wl_shell surface for now. */ |
| 3832 | |
| 3833 | return shsurf->resource == NULL || |
| 3834 | wl_resource_instance_of(shsurf->resource, |
| 3835 | &wl_shell_surface_interface, |
| 3836 | &shell_surface_implementation); |
Rafael Antognolli | e2a3455 | 2013-12-03 15:35:45 -0200 | [diff] [blame] | 3837 | } |
| 3838 | |
Pekka Paalanen | 9d1613e | 2011-11-25 12:09:16 +0200 | [diff] [blame] | 3839 | static const struct wl_shell_interface shell_implementation = { |
Pekka Paalanen | 4622967 | 2011-11-29 15:49:31 +0200 | [diff] [blame] | 3840 | shell_get_shell_surface |
Kristian Høgsberg | 4cca349 | 2011-01-18 07:53:49 -0500 | [diff] [blame] | 3841 | }; |
| 3842 | |
Rafael Antognolli | e2a3455 | 2013-12-03 15:35:45 -0200 | [diff] [blame] | 3843 | /**************************** |
| 3844 | * xdg-shell implementation */ |
| 3845 | |
| 3846 | static void |
| 3847 | xdg_surface_destroy(struct wl_client *client, |
| 3848 | struct wl_resource *resource) |
| 3849 | { |
| 3850 | wl_resource_destroy(resource); |
| 3851 | } |
| 3852 | |
| 3853 | static void |
Jasper St. Pierre | c815d62 | 2014-04-10 18:37:54 -0700 | [diff] [blame] | 3854 | xdg_surface_set_parent(struct wl_client *client, |
| 3855 | struct wl_resource *resource, |
| 3856 | struct wl_resource *parent_resource) |
Jasper St. Pierre | 63a9c33 | 2014-02-01 18:35:15 -0500 | [diff] [blame] | 3857 | { |
| 3858 | struct shell_surface *shsurf = wl_resource_get_user_data(resource); |
Jasper St. Pierre | 66bc949 | 2015-02-13 14:01:55 +0800 | [diff] [blame] | 3859 | struct shell_surface *parent; |
Jasper St. Pierre | 63a9c33 | 2014-02-01 18:35:15 -0500 | [diff] [blame] | 3860 | |
Jasper St. Pierre | 66bc949 | 2015-02-13 14:01:55 +0800 | [diff] [blame] | 3861 | if (parent_resource) { |
Jasper St. Pierre | 63a9c33 | 2014-02-01 18:35:15 -0500 | [diff] [blame] | 3862 | parent = wl_resource_get_user_data(parent_resource); |
Jasper St. Pierre | 66bc949 | 2015-02-13 14:01:55 +0800 | [diff] [blame] | 3863 | shell_surface_set_parent(shsurf, parent->surface); |
| 3864 | } else { |
| 3865 | shell_surface_set_parent(shsurf, NULL); |
| 3866 | } |
Jasper St. Pierre | 63a9c33 | 2014-02-01 18:35:15 -0500 | [diff] [blame] | 3867 | } |
| 3868 | |
| 3869 | static void |
Rafael Antognolli | e2a3455 | 2013-12-03 15:35:45 -0200 | [diff] [blame] | 3870 | xdg_surface_set_app_id(struct wl_client *client, |
| 3871 | struct wl_resource *resource, |
| 3872 | const char *app_id) |
| 3873 | { |
| 3874 | struct shell_surface *shsurf = wl_resource_get_user_data(resource); |
| 3875 | |
| 3876 | free(shsurf->class); |
| 3877 | shsurf->class = strdup(app_id); |
Pekka Paalanen | b502654 | 2014-11-12 15:09:24 +0200 | [diff] [blame] | 3878 | shsurf->surface->timeline.force_refresh = 1; |
Rafael Antognolli | e2a3455 | 2013-12-03 15:35:45 -0200 | [diff] [blame] | 3879 | } |
| 3880 | |
| 3881 | static void |
Jasper St. Pierre | 81ff075 | 2014-03-13 11:04:53 -0400 | [diff] [blame] | 3882 | xdg_surface_show_window_menu(struct wl_client *client, |
| 3883 | struct wl_resource *surface_resource, |
| 3884 | struct wl_resource *seat_resource, |
| 3885 | uint32_t serial, |
| 3886 | int32_t x, |
| 3887 | int32_t y) |
| 3888 | { |
| 3889 | /* TODO */ |
| 3890 | } |
| 3891 | |
| 3892 | static void |
Rafael Antognolli | e2a3455 | 2013-12-03 15:35:45 -0200 | [diff] [blame] | 3893 | xdg_surface_set_title(struct wl_client *client, |
| 3894 | struct wl_resource *resource, const char *title) |
| 3895 | { |
| 3896 | struct shell_surface *shsurf = wl_resource_get_user_data(resource); |
| 3897 | |
| 3898 | set_title(shsurf, title); |
| 3899 | } |
| 3900 | |
| 3901 | static void |
| 3902 | xdg_surface_move(struct wl_client *client, struct wl_resource *resource, |
| 3903 | struct wl_resource *seat_resource, uint32_t serial) |
| 3904 | { |
| 3905 | common_surface_move(resource, seat_resource, serial); |
| 3906 | } |
| 3907 | |
| 3908 | static void |
| 3909 | xdg_surface_resize(struct wl_client *client, struct wl_resource *resource, |
| 3910 | struct wl_resource *seat_resource, uint32_t serial, |
| 3911 | uint32_t edges) |
| 3912 | { |
| 3913 | common_surface_resize(resource, seat_resource, serial, edges); |
| 3914 | } |
| 3915 | |
| 3916 | static void |
Jasper St. Pierre | ab2c108 | 2014-04-10 10:41:46 -0700 | [diff] [blame] | 3917 | xdg_surface_ack_configure(struct wl_client *client, |
| 3918 | struct wl_resource *resource, |
| 3919 | uint32_t serial) |
Rafael Antognolli | e2a3455 | 2013-12-03 15:35:45 -0200 | [diff] [blame] | 3920 | { |
| 3921 | struct shell_surface *shsurf = wl_resource_get_user_data(resource); |
| 3922 | |
Jasper St. Pierre | 8c6aa45 | 2014-02-08 18:29:49 -0500 | [diff] [blame] | 3923 | if (shsurf->state_requested) { |
| 3924 | shsurf->next_state = shsurf->requested_state; |
| 3925 | shsurf->state_changed = true; |
| 3926 | shsurf->state_requested = false; |
Rafael Antognolli | 3c4e3f7 | 2013-12-03 15:35:46 -0200 | [diff] [blame] | 3927 | } |
Rafael Antognolli | e2a3455 | 2013-12-03 15:35:45 -0200 | [diff] [blame] | 3928 | } |
| 3929 | |
Manuel Bachmann | 50c87db | 2014-02-26 15:52:13 +0100 | [diff] [blame] | 3930 | static void |
Jasper St. Pierre | ccf48fb | 2014-05-02 10:21:38 -0400 | [diff] [blame] | 3931 | xdg_surface_set_window_geometry(struct wl_client *client, |
| 3932 | struct wl_resource *resource, |
| 3933 | int32_t x, |
| 3934 | int32_t y, |
| 3935 | int32_t width, |
| 3936 | int32_t height) |
| 3937 | { |
| 3938 | struct shell_surface *shsurf = wl_resource_get_user_data(resource); |
| 3939 | |
| 3940 | set_window_geometry(shsurf, x, y, width, height); |
| 3941 | } |
| 3942 | |
| 3943 | static void |
Jasper St. Pierre | ab2c108 | 2014-04-10 10:41:46 -0700 | [diff] [blame] | 3944 | xdg_surface_set_maximized(struct wl_client *client, |
| 3945 | struct wl_resource *resource) |
| 3946 | { |
| 3947 | struct shell_surface *shsurf = wl_resource_get_user_data(resource); |
Marek Chalupa | bfbb64b | 2014-09-08 12:34:20 +0200 | [diff] [blame] | 3948 | struct weston_output *output; |
Jasper St. Pierre | ab2c108 | 2014-04-10 10:41:46 -0700 | [diff] [blame] | 3949 | |
| 3950 | shsurf->state_requested = true; |
| 3951 | shsurf->requested_state.maximized = true; |
Marek Chalupa | bfbb64b | 2014-09-08 12:34:20 +0200 | [diff] [blame] | 3952 | |
| 3953 | if (!weston_surface_is_mapped(shsurf->surface)) |
| 3954 | output = get_focused_output(shsurf->surface->compositor); |
| 3955 | else |
| 3956 | output = shsurf->surface->output; |
| 3957 | |
| 3958 | shell_surface_set_output(shsurf, output); |
Jasper St. Pierre | 9aa8ce6 | 2014-04-11 16:18:54 -0700 | [diff] [blame] | 3959 | send_configure_for_surface(shsurf); |
Jasper St. Pierre | ab2c108 | 2014-04-10 10:41:46 -0700 | [diff] [blame] | 3960 | } |
| 3961 | |
| 3962 | static void |
| 3963 | xdg_surface_unset_maximized(struct wl_client *client, |
| 3964 | struct wl_resource *resource) |
| 3965 | { |
| 3966 | struct shell_surface *shsurf = wl_resource_get_user_data(resource); |
| 3967 | |
| 3968 | shsurf->state_requested = true; |
| 3969 | shsurf->requested_state.maximized = false; |
Jasper St. Pierre | 6458ec3 | 2014-04-11 16:00:31 -0700 | [diff] [blame] | 3970 | send_configure_for_surface(shsurf); |
Jasper St. Pierre | ab2c108 | 2014-04-10 10:41:46 -0700 | [diff] [blame] | 3971 | } |
| 3972 | |
| 3973 | static void |
| 3974 | xdg_surface_set_fullscreen(struct wl_client *client, |
| 3975 | struct wl_resource *resource, |
| 3976 | struct wl_resource *output_resource) |
| 3977 | { |
| 3978 | struct shell_surface *shsurf = wl_resource_get_user_data(resource); |
| 3979 | struct weston_output *output; |
| 3980 | |
| 3981 | shsurf->state_requested = true; |
| 3982 | shsurf->requested_state.fullscreen = true; |
| 3983 | |
| 3984 | if (output_resource) |
| 3985 | output = wl_resource_get_user_data(output_resource); |
| 3986 | else |
| 3987 | output = NULL; |
| 3988 | |
Marek Chalupa | 052917a | 2014-09-02 11:35:12 +0200 | [diff] [blame] | 3989 | /* handle clients launching in fullscreen */ |
| 3990 | if (output == NULL && !weston_surface_is_mapped(shsurf->surface)) { |
| 3991 | /* Set the output to the one that has focus currently. */ |
| 3992 | assert(shsurf->surface); |
| 3993 | output = get_focused_output(shsurf->surface->compositor); |
| 3994 | } |
| 3995 | |
Jasper St. Pierre | 9aa8ce6 | 2014-04-11 16:18:54 -0700 | [diff] [blame] | 3996 | shell_surface_set_output(shsurf, output); |
| 3997 | shsurf->fullscreen_output = shsurf->output; |
Jasper St. Pierre | ab2c108 | 2014-04-10 10:41:46 -0700 | [diff] [blame] | 3998 | |
Jasper St. Pierre | 9aa8ce6 | 2014-04-11 16:18:54 -0700 | [diff] [blame] | 3999 | send_configure_for_surface(shsurf); |
Jasper St. Pierre | ab2c108 | 2014-04-10 10:41:46 -0700 | [diff] [blame] | 4000 | } |
| 4001 | |
| 4002 | static void |
| 4003 | xdg_surface_unset_fullscreen(struct wl_client *client, |
| 4004 | struct wl_resource *resource) |
| 4005 | { |
| 4006 | struct shell_surface *shsurf = wl_resource_get_user_data(resource); |
| 4007 | |
| 4008 | shsurf->state_requested = true; |
| 4009 | shsurf->requested_state.fullscreen = false; |
Jasper St. Pierre | 6458ec3 | 2014-04-11 16:00:31 -0700 | [diff] [blame] | 4010 | send_configure_for_surface(shsurf); |
Jasper St. Pierre | ab2c108 | 2014-04-10 10:41:46 -0700 | [diff] [blame] | 4011 | } |
| 4012 | |
| 4013 | static void |
Manuel Bachmann | 50c87db | 2014-02-26 15:52:13 +0100 | [diff] [blame] | 4014 | xdg_surface_set_minimized(struct wl_client *client, |
| 4015 | struct wl_resource *resource) |
| 4016 | { |
| 4017 | struct shell_surface *shsurf = wl_resource_get_user_data(resource); |
| 4018 | |
| 4019 | if (shsurf->type != SHELL_SURFACE_TOPLEVEL) |
| 4020 | return; |
| 4021 | |
| 4022 | /* apply compositor's own minimization logic (hide) */ |
Manuel Bachmann | dc1c3e4 | 2015-02-16 11:52:13 +0100 | [diff] [blame] | 4023 | set_minimized(shsurf->surface); |
Manuel Bachmann | 50c87db | 2014-02-26 15:52:13 +0100 | [diff] [blame] | 4024 | } |
| 4025 | |
Rafael Antognolli | e2a3455 | 2013-12-03 15:35:45 -0200 | [diff] [blame] | 4026 | static const struct xdg_surface_interface xdg_surface_implementation = { |
| 4027 | xdg_surface_destroy, |
Jasper St. Pierre | c815d62 | 2014-04-10 18:37:54 -0700 | [diff] [blame] | 4028 | xdg_surface_set_parent, |
Rafael Antognolli | e2a3455 | 2013-12-03 15:35:45 -0200 | [diff] [blame] | 4029 | xdg_surface_set_title, |
| 4030 | xdg_surface_set_app_id, |
Jasper St. Pierre | 81ff075 | 2014-03-13 11:04:53 -0400 | [diff] [blame] | 4031 | xdg_surface_show_window_menu, |
Rafael Antognolli | e2a3455 | 2013-12-03 15:35:45 -0200 | [diff] [blame] | 4032 | xdg_surface_move, |
| 4033 | xdg_surface_resize, |
Jasper St. Pierre | ab2c108 | 2014-04-10 10:41:46 -0700 | [diff] [blame] | 4034 | xdg_surface_ack_configure, |
Jasper St. Pierre | ccf48fb | 2014-05-02 10:21:38 -0400 | [diff] [blame] | 4035 | xdg_surface_set_window_geometry, |
Jasper St. Pierre | ab2c108 | 2014-04-10 10:41:46 -0700 | [diff] [blame] | 4036 | xdg_surface_set_maximized, |
| 4037 | xdg_surface_unset_maximized, |
| 4038 | xdg_surface_set_fullscreen, |
| 4039 | xdg_surface_unset_fullscreen, |
| 4040 | xdg_surface_set_minimized, |
Rafael Antognolli | e2a3455 | 2013-12-03 15:35:45 -0200 | [diff] [blame] | 4041 | }; |
| 4042 | |
| 4043 | static void |
| 4044 | xdg_send_configure(struct weston_surface *surface, |
Jasper St. Pierre | ac985be | 2014-04-28 11:19:28 -0400 | [diff] [blame] | 4045 | int32_t width, int32_t height) |
Rafael Antognolli | e2a3455 | 2013-12-03 15:35:45 -0200 | [diff] [blame] | 4046 | { |
| 4047 | struct shell_surface *shsurf = get_shell_surface(surface); |
Jasper St. Pierre | ab2c108 | 2014-04-10 10:41:46 -0700 | [diff] [blame] | 4048 | uint32_t *s; |
| 4049 | struct wl_array states; |
| 4050 | uint32_t serial; |
Rafael Antognolli | e2a3455 | 2013-12-03 15:35:45 -0200 | [diff] [blame] | 4051 | |
U. Artie Eoff | cf5737a | 2014-01-17 10:08:25 -0800 | [diff] [blame] | 4052 | assert(shsurf); |
| 4053 | |
Jasper St. Pierre | ab2c108 | 2014-04-10 10:41:46 -0700 | [diff] [blame] | 4054 | if (!shsurf->resource) |
| 4055 | return; |
| 4056 | |
| 4057 | wl_array_init(&states); |
| 4058 | if (shsurf->requested_state.fullscreen) { |
| 4059 | s = wl_array_add(&states, sizeof *s); |
| 4060 | *s = XDG_SURFACE_STATE_FULLSCREEN; |
| 4061 | } else if (shsurf->requested_state.maximized) { |
| 4062 | s = wl_array_add(&states, sizeof *s); |
| 4063 | *s = XDG_SURFACE_STATE_MAXIMIZED; |
| 4064 | } |
Jasper St. Pierre | 5befdda | 2014-05-06 08:50:47 -0400 | [diff] [blame] | 4065 | if (shsurf->resize_edges != 0) { |
| 4066 | s = wl_array_add(&states, sizeof *s); |
| 4067 | *s = XDG_SURFACE_STATE_RESIZING; |
| 4068 | } |
Jasper St. Pierre | 973d787 | 2014-05-06 08:44:29 -0400 | [diff] [blame] | 4069 | if (shsurf->focus_count > 0) { |
| 4070 | s = wl_array_add(&states, sizeof *s); |
| 4071 | *s = XDG_SURFACE_STATE_ACTIVATED; |
| 4072 | } |
Jasper St. Pierre | ab2c108 | 2014-04-10 10:41:46 -0700 | [diff] [blame] | 4073 | |
| 4074 | serial = wl_display_next_serial(shsurf->surface->compositor->wl_display); |
| 4075 | xdg_surface_send_configure(shsurf->resource, width, height, &states, serial); |
| 4076 | |
| 4077 | wl_array_release(&states); |
Rafael Antognolli | e2a3455 | 2013-12-03 15:35:45 -0200 | [diff] [blame] | 4078 | } |
| 4079 | |
| 4080 | static const struct weston_shell_client xdg_client = { |
| 4081 | xdg_send_configure |
| 4082 | }; |
| 4083 | |
| 4084 | static void |
Jasper St. Pierre | 084aa0b | 2015-02-13 14:02:00 +0800 | [diff] [blame] | 4085 | xdg_shell_destroy(struct wl_client *client, |
| 4086 | struct wl_resource *resource) |
| 4087 | { |
Jonas Ådahl | 49d77d2 | 2015-03-18 16:20:51 +0800 | [diff] [blame] | 4088 | struct shell_client *sc = wl_resource_get_user_data(resource); |
| 4089 | struct wl_resource *shsurf_resource; |
| 4090 | struct shell_surface *shsurf; |
| 4091 | |
| 4092 | wl_resource_for_each(shsurf_resource, &sc->surface_list) { |
| 4093 | shsurf = wl_resource_get_user_data(shsurf_resource); |
| 4094 | if (shsurf->owner_resource == resource) { |
| 4095 | wl_resource_post_error( |
| 4096 | resource, |
| 4097 | XDG_SHELL_ERROR_DEFUNCT_SURFACES, |
| 4098 | "not all child surface objects destroyed"); |
| 4099 | return; |
| 4100 | } |
| 4101 | } |
| 4102 | |
Jasper St. Pierre | 084aa0b | 2015-02-13 14:02:00 +0800 | [diff] [blame] | 4103 | wl_resource_destroy(resource); |
| 4104 | } |
| 4105 | |
| 4106 | static void |
Rafael Antognolli | e2a3455 | 2013-12-03 15:35:45 -0200 | [diff] [blame] | 4107 | xdg_use_unstable_version(struct wl_client *client, |
| 4108 | struct wl_resource *resource, |
| 4109 | int32_t version) |
| 4110 | { |
| 4111 | if (version > 1) { |
| 4112 | wl_resource_post_error(resource, |
| 4113 | 1, |
| 4114 | "xdg-shell:: version not implemented yet."); |
| 4115 | return; |
| 4116 | } |
| 4117 | } |
| 4118 | |
| 4119 | static struct shell_surface * |
Jason Ekstrand | 9e9512f | 2014-04-16 21:12:10 -0500 | [diff] [blame] | 4120 | create_xdg_surface(struct shell_client *owner, void *shell, |
| 4121 | struct weston_surface *surface, |
Rafael Antognolli | e2a3455 | 2013-12-03 15:35:45 -0200 | [diff] [blame] | 4122 | const struct weston_shell_client *client) |
| 4123 | { |
| 4124 | struct shell_surface *shsurf; |
Rafael Antognolli | e2a3455 | 2013-12-03 15:35:45 -0200 | [diff] [blame] | 4125 | |
Jason Ekstrand | 9e9512f | 2014-04-16 21:12:10 -0500 | [diff] [blame] | 4126 | shsurf = create_common_surface(owner, shell, surface, client); |
Pekka Paalanen | e972b27 | 2014-10-01 14:03:56 +0300 | [diff] [blame] | 4127 | if (!shsurf) |
| 4128 | return NULL; |
| 4129 | |
Pekka Paalanen | b502654 | 2014-11-12 15:09:24 +0200 | [diff] [blame] | 4130 | set_type(shsurf, SHELL_SURFACE_TOPLEVEL); |
Rafael Antognolli | e2a3455 | 2013-12-03 15:35:45 -0200 | [diff] [blame] | 4131 | |
| 4132 | return shsurf; |
| 4133 | } |
| 4134 | |
| 4135 | static void |
| 4136 | xdg_get_xdg_surface(struct wl_client *client, |
| 4137 | struct wl_resource *resource, |
| 4138 | uint32_t id, |
| 4139 | struct wl_resource *surface_resource) |
| 4140 | { |
| 4141 | struct weston_surface *surface = |
| 4142 | wl_resource_get_user_data(surface_resource); |
Kristian Høgsberg | 2bff94e | 2014-02-11 12:22:51 -0800 | [diff] [blame] | 4143 | struct shell_client *sc = wl_resource_get_user_data(resource); |
| 4144 | struct desktop_shell *shell = sc->shell; |
Rafael Antognolli | e2a3455 | 2013-12-03 15:35:45 -0200 | [diff] [blame] | 4145 | struct shell_surface *shsurf; |
| 4146 | |
Jonas Ådahl | bf48e21 | 2015-02-06 10:15:28 +0800 | [diff] [blame] | 4147 | shsurf = get_shell_surface(surface); |
| 4148 | if (shsurf && shell_surface_is_xdg_surface(shsurf)) { |
| 4149 | wl_resource_post_error(resource, XDG_SHELL_ERROR_ROLE, |
| 4150 | "This wl_surface is already an " |
| 4151 | "xdg_surface"); |
| 4152 | return; |
| 4153 | } |
| 4154 | |
Pekka Paalanen | 50b6747 | 2014-10-01 15:02:41 +0300 | [diff] [blame] | 4155 | if (weston_surface_set_role(surface, "xdg_surface", |
| 4156 | resource, XDG_SHELL_ERROR_ROLE) < 0) |
Rafael Antognolli | e2a3455 | 2013-12-03 15:35:45 -0200 | [diff] [blame] | 4157 | return; |
Rafael Antognolli | e2a3455 | 2013-12-03 15:35:45 -0200 | [diff] [blame] | 4158 | |
Jason Ekstrand | 9e9512f | 2014-04-16 21:12:10 -0500 | [diff] [blame] | 4159 | shsurf = create_xdg_surface(sc, shell, surface, &xdg_client); |
Rafael Antognolli | e2a3455 | 2013-12-03 15:35:45 -0200 | [diff] [blame] | 4160 | if (!shsurf) { |
Pekka Paalanen | 50b6747 | 2014-10-01 15:02:41 +0300 | [diff] [blame] | 4161 | wl_resource_post_no_memory(surface_resource); |
Rafael Antognolli | e2a3455 | 2013-12-03 15:35:45 -0200 | [diff] [blame] | 4162 | return; |
| 4163 | } |
| 4164 | |
| 4165 | shsurf->resource = |
| 4166 | wl_resource_create(client, |
| 4167 | &xdg_surface_interface, 1, id); |
| 4168 | wl_resource_set_implementation(shsurf->resource, |
| 4169 | &xdg_surface_implementation, |
| 4170 | shsurf, shell_destroy_shell_surface); |
Jonas Ådahl | 49d77d2 | 2015-03-18 16:20:51 +0800 | [diff] [blame] | 4171 | shsurf->owner_resource = resource; |
| 4172 | wl_list_insert(&sc->surface_list, |
| 4173 | wl_resource_get_link(shsurf->resource)); |
Rafael Antognolli | e2a3455 | 2013-12-03 15:35:45 -0200 | [diff] [blame] | 4174 | } |
| 4175 | |
| 4176 | static bool |
| 4177 | shell_surface_is_xdg_surface(struct shell_surface *shsurf) |
| 4178 | { |
Kristian Høgsberg | 0b7d995 | 2014-02-03 15:50:38 -0800 | [diff] [blame] | 4179 | return shsurf->resource && |
| 4180 | wl_resource_instance_of(shsurf->resource, |
| 4181 | &xdg_surface_interface, |
| 4182 | &xdg_surface_implementation); |
Rafael Antognolli | e2a3455 | 2013-12-03 15:35:45 -0200 | [diff] [blame] | 4183 | } |
| 4184 | |
| 4185 | /* xdg-popup implementation */ |
| 4186 | |
| 4187 | static void |
| 4188 | xdg_popup_destroy(struct wl_client *client, |
| 4189 | struct wl_resource *resource) |
| 4190 | { |
| 4191 | wl_resource_destroy(resource); |
| 4192 | } |
| 4193 | |
Rafael Antognolli | e2a3455 | 2013-12-03 15:35:45 -0200 | [diff] [blame] | 4194 | static const struct xdg_popup_interface xdg_popup_implementation = { |
| 4195 | xdg_popup_destroy, |
Rafael Antognolli | e2a3455 | 2013-12-03 15:35:45 -0200 | [diff] [blame] | 4196 | }; |
| 4197 | |
| 4198 | static void |
| 4199 | xdg_popup_send_configure(struct weston_surface *surface, |
Jasper St. Pierre | ac985be | 2014-04-28 11:19:28 -0400 | [diff] [blame] | 4200 | int32_t width, int32_t height) |
Rafael Antognolli | e2a3455 | 2013-12-03 15:35:45 -0200 | [diff] [blame] | 4201 | { |
| 4202 | } |
| 4203 | |
| 4204 | static const struct weston_shell_client xdg_popup_client = { |
| 4205 | xdg_popup_send_configure |
| 4206 | }; |
| 4207 | |
| 4208 | static struct shell_surface * |
Jason Ekstrand | 9e9512f | 2014-04-16 21:12:10 -0500 | [diff] [blame] | 4209 | create_xdg_popup(struct shell_client *owner, void *shell, |
| 4210 | struct weston_surface *surface, |
Rafael Antognolli | e2a3455 | 2013-12-03 15:35:45 -0200 | [diff] [blame] | 4211 | const struct weston_shell_client *client, |
| 4212 | struct weston_surface *parent, |
| 4213 | struct shell_seat *seat, |
| 4214 | uint32_t serial, |
| 4215 | int32_t x, int32_t y) |
| 4216 | { |
Jonas Ådahl | ee45a55 | 2015-03-18 16:37:47 +0800 | [diff] [blame] | 4217 | struct shell_surface *shsurf; |
Jonas Ådahl | 24185e2 | 2015-02-27 18:37:41 +0800 | [diff] [blame] | 4218 | |
Jason Ekstrand | 9e9512f | 2014-04-16 21:12:10 -0500 | [diff] [blame] | 4219 | shsurf = create_common_surface(owner, shell, surface, client); |
Pekka Paalanen | e972b27 | 2014-10-01 14:03:56 +0300 | [diff] [blame] | 4220 | if (!shsurf) |
| 4221 | return NULL; |
| 4222 | |
Pekka Paalanen | b502654 | 2014-11-12 15:09:24 +0200 | [diff] [blame] | 4223 | set_type(shsurf, SHELL_SURFACE_POPUP); |
Rafael Antognolli | e2a3455 | 2013-12-03 15:35:45 -0200 | [diff] [blame] | 4224 | shsurf->popup.shseat = seat; |
| 4225 | shsurf->popup.serial = serial; |
| 4226 | shsurf->popup.x = x; |
| 4227 | shsurf->popup.y = y; |
| 4228 | shell_surface_set_parent(shsurf, parent); |
| 4229 | |
| 4230 | return shsurf; |
| 4231 | } |
| 4232 | |
| 4233 | static void |
| 4234 | xdg_get_xdg_popup(struct wl_client *client, |
| 4235 | struct wl_resource *resource, |
| 4236 | uint32_t id, |
| 4237 | struct wl_resource *surface_resource, |
| 4238 | struct wl_resource *parent_resource, |
| 4239 | struct wl_resource *seat_resource, |
| 4240 | uint32_t serial, |
Jasper St. Pierre | 14f330c | 2015-02-13 14:01:57 +0800 | [diff] [blame] | 4241 | int32_t x, int32_t y) |
Rafael Antognolli | e2a3455 | 2013-12-03 15:35:45 -0200 | [diff] [blame] | 4242 | { |
| 4243 | struct weston_surface *surface = |
| 4244 | wl_resource_get_user_data(surface_resource); |
Kristian Høgsberg | 2bff94e | 2014-02-11 12:22:51 -0800 | [diff] [blame] | 4245 | struct shell_client *sc = wl_resource_get_user_data(resource); |
| 4246 | struct desktop_shell *shell = sc->shell; |
Rafael Antognolli | e2a3455 | 2013-12-03 15:35:45 -0200 | [diff] [blame] | 4247 | struct shell_surface *shsurf; |
Jonas Ådahl | ee45a55 | 2015-03-18 16:37:47 +0800 | [diff] [blame] | 4248 | struct shell_surface *parent_shsurf; |
Rafael Antognolli | e2a3455 | 2013-12-03 15:35:45 -0200 | [diff] [blame] | 4249 | struct weston_surface *parent; |
| 4250 | struct shell_seat *seat; |
| 4251 | |
Jonas Ådahl | bf48e21 | 2015-02-06 10:15:28 +0800 | [diff] [blame] | 4252 | shsurf = get_shell_surface(surface); |
| 4253 | if (shsurf && shell_surface_is_xdg_popup(shsurf)) { |
| 4254 | wl_resource_post_error(resource, XDG_SHELL_ERROR_ROLE, |
| 4255 | "This wl_surface is already an " |
| 4256 | "xdg_popup"); |
| 4257 | return; |
| 4258 | } |
| 4259 | |
Pekka Paalanen | 50b6747 | 2014-10-01 15:02:41 +0300 | [diff] [blame] | 4260 | if (weston_surface_set_role(surface, "xdg_popup", |
| 4261 | resource, XDG_SHELL_ERROR_ROLE) < 0) |
Rafael Antognolli | e2a3455 | 2013-12-03 15:35:45 -0200 | [diff] [blame] | 4262 | return; |
Rafael Antognolli | e2a3455 | 2013-12-03 15:35:45 -0200 | [diff] [blame] | 4263 | |
| 4264 | if (!parent_resource) { |
| 4265 | wl_resource_post_error(surface_resource, |
| 4266 | WL_DISPLAY_ERROR_INVALID_OBJECT, |
| 4267 | "xdg_shell::get_xdg_popup requires a parent shell surface"); |
Jasper St. Pierre | 666bc92 | 2014-08-07 16:43:13 -0400 | [diff] [blame] | 4268 | return; |
Rafael Antognolli | e2a3455 | 2013-12-03 15:35:45 -0200 | [diff] [blame] | 4269 | } |
| 4270 | |
| 4271 | parent = wl_resource_get_user_data(parent_resource); |
Derek Foreman | bdc8c72 | 2015-10-07 11:51:29 -0500 | [diff] [blame] | 4272 | seat = get_shell_seat(wl_resource_get_user_data(seat_resource)); |
Rafael Antognolli | e2a3455 | 2013-12-03 15:35:45 -0200 | [diff] [blame] | 4273 | |
Jonas Ådahl | ee45a55 | 2015-03-18 16:37:47 +0800 | [diff] [blame] | 4274 | /* Verify that we are creating the top most popup when mapping, |
| 4275 | * as it's not until then we know whether it was mapped as most |
| 4276 | * top level or not. */ |
| 4277 | |
| 4278 | parent_shsurf = get_shell_surface(parent); |
Jonas Ådahl | bc5d849 | 2015-10-07 14:44:50 +0800 | [diff] [blame] | 4279 | if (!parent_shsurf || |
| 4280 | (!shell_surface_is_xdg_popup(parent_shsurf) && |
| 4281 | !shell_surface_is_xdg_surface(parent_shsurf))) { |
Jonas Ådahl | ee45a55 | 2015-03-18 16:37:47 +0800 | [diff] [blame] | 4282 | wl_resource_post_error(resource, |
| 4283 | XDG_SHELL_ERROR_INVALID_POPUP_PARENT, |
| 4284 | "xdg_popup parent was invalid"); |
| 4285 | return; |
| 4286 | } |
| 4287 | |
Jason Ekstrand | 9e9512f | 2014-04-16 21:12:10 -0500 | [diff] [blame] | 4288 | shsurf = create_xdg_popup(sc, shell, surface, &xdg_popup_client, |
Rafael Antognolli | e2a3455 | 2013-12-03 15:35:45 -0200 | [diff] [blame] | 4289 | parent, seat, serial, x, y); |
| 4290 | if (!shsurf) { |
Pekka Paalanen | 50b6747 | 2014-10-01 15:02:41 +0300 | [diff] [blame] | 4291 | wl_resource_post_no_memory(surface_resource); |
Rafael Antognolli | e2a3455 | 2013-12-03 15:35:45 -0200 | [diff] [blame] | 4292 | return; |
| 4293 | } |
| 4294 | |
| 4295 | shsurf->resource = |
| 4296 | wl_resource_create(client, |
| 4297 | &xdg_popup_interface, 1, id); |
| 4298 | wl_resource_set_implementation(shsurf->resource, |
| 4299 | &xdg_popup_implementation, |
| 4300 | shsurf, shell_destroy_shell_surface); |
Jonas Ådahl | 49d77d2 | 2015-03-18 16:20:51 +0800 | [diff] [blame] | 4301 | shsurf->owner_resource = resource; |
| 4302 | wl_list_insert(&sc->surface_list, |
| 4303 | wl_resource_get_link(shsurf->resource)); |
Rafael Antognolli | e2a3455 | 2013-12-03 15:35:45 -0200 | [diff] [blame] | 4304 | } |
| 4305 | |
Kristian Høgsberg | 2bff94e | 2014-02-11 12:22:51 -0800 | [diff] [blame] | 4306 | static void |
| 4307 | xdg_pong(struct wl_client *client, |
| 4308 | struct wl_resource *resource, uint32_t serial) |
| 4309 | { |
| 4310 | struct shell_client *sc = wl_resource_get_user_data(resource); |
Kristian Høgsberg | 2bff94e | 2014-02-11 12:22:51 -0800 | [diff] [blame] | 4311 | |
Kristian Høgsberg | dd62aba | 2014-02-12 09:56:19 -0800 | [diff] [blame] | 4312 | shell_client_pong(sc, serial); |
Kristian Høgsberg | 2bff94e | 2014-02-11 12:22:51 -0800 | [diff] [blame] | 4313 | } |
| 4314 | |
Rafael Antognolli | e2a3455 | 2013-12-03 15:35:45 -0200 | [diff] [blame] | 4315 | static bool |
| 4316 | shell_surface_is_xdg_popup(struct shell_surface *shsurf) |
| 4317 | { |
| 4318 | return wl_resource_instance_of(shsurf->resource, |
| 4319 | &xdg_popup_interface, |
| 4320 | &xdg_popup_implementation); |
| 4321 | } |
| 4322 | |
| 4323 | static const struct xdg_shell_interface xdg_implementation = { |
Jasper St. Pierre | 084aa0b | 2015-02-13 14:02:00 +0800 | [diff] [blame] | 4324 | xdg_shell_destroy, |
Rafael Antognolli | e2a3455 | 2013-12-03 15:35:45 -0200 | [diff] [blame] | 4325 | xdg_use_unstable_version, |
| 4326 | xdg_get_xdg_surface, |
Kristian Høgsberg | 2bff94e | 2014-02-11 12:22:51 -0800 | [diff] [blame] | 4327 | xdg_get_xdg_popup, |
| 4328 | xdg_pong |
Rafael Antognolli | e2a3455 | 2013-12-03 15:35:45 -0200 | [diff] [blame] | 4329 | }; |
| 4330 | |
| 4331 | static int |
| 4332 | xdg_shell_unversioned_dispatch(const void *implementation, |
| 4333 | void *_target, uint32_t opcode, |
| 4334 | const struct wl_message *message, |
| 4335 | union wl_argument *args) |
| 4336 | { |
| 4337 | struct wl_resource *resource = _target; |
Kristian Høgsberg | 2bff94e | 2014-02-11 12:22:51 -0800 | [diff] [blame] | 4338 | struct shell_client *sc = wl_resource_get_user_data(resource); |
Rafael Antognolli | e2a3455 | 2013-12-03 15:35:45 -0200 | [diff] [blame] | 4339 | |
Jasper St. Pierre | 084aa0b | 2015-02-13 14:02:00 +0800 | [diff] [blame] | 4340 | if (opcode != 1 /* XDG_SHELL_USE_UNSTABLE_VERSION */) { |
Rafael Antognolli | e2a3455 | 2013-12-03 15:35:45 -0200 | [diff] [blame] | 4341 | wl_resource_post_error(resource, |
| 4342 | WL_DISPLAY_ERROR_INVALID_OBJECT, |
| 4343 | "must call use_unstable_version first"); |
| 4344 | return 0; |
| 4345 | } |
| 4346 | |
Jasper St. Pierre | 5ba1e1d | 2015-02-13 14:02:02 +0800 | [diff] [blame] | 4347 | #define XDG_SERVER_VERSION 5 |
Rafael Antognolli | e2a3455 | 2013-12-03 15:35:45 -0200 | [diff] [blame] | 4348 | |
Kristian Høgsberg | 8d344a0 | 2013-12-08 22:27:11 -0800 | [diff] [blame] | 4349 | static_assert(XDG_SERVER_VERSION == XDG_SHELL_VERSION_CURRENT, |
| 4350 | "shell implementation doesn't match protocol version"); |
| 4351 | |
Rafael Antognolli | e2a3455 | 2013-12-03 15:35:45 -0200 | [diff] [blame] | 4352 | if (args[0].i != XDG_SERVER_VERSION) { |
| 4353 | wl_resource_post_error(resource, |
| 4354 | WL_DISPLAY_ERROR_INVALID_OBJECT, |
| 4355 | "incompatible version, server is %d " |
| 4356 | "client wants %d", |
| 4357 | XDG_SERVER_VERSION, args[0].i); |
| 4358 | return 0; |
| 4359 | } |
| 4360 | |
| 4361 | wl_resource_set_implementation(resource, &xdg_implementation, |
Kristian Høgsberg | 2bff94e | 2014-02-11 12:22:51 -0800 | [diff] [blame] | 4362 | sc, NULL); |
Rafael Antognolli | e2a3455 | 2013-12-03 15:35:45 -0200 | [diff] [blame] | 4363 | |
| 4364 | return 1; |
| 4365 | } |
| 4366 | |
| 4367 | /* end of xdg-shell implementation */ |
| 4368 | /***********************************/ |
| 4369 | |
Kristian Høgsberg | 0793756 | 2011-04-12 17:25:42 -0400 | [diff] [blame] | 4370 | static void |
Ander Conselvan de Oliveira | 859e885 | 2013-02-21 18:35:21 +0200 | [diff] [blame] | 4371 | shell_fade(struct desktop_shell *shell, enum fade_type type); |
| 4372 | |
Pekka Paalanen | 77346a6 | 2011-11-30 16:26:35 +0200 | [diff] [blame] | 4373 | static void |
Jason Ekstrand | 918f2dd | 2013-12-02 21:01:53 -0600 | [diff] [blame] | 4374 | configure_static_view(struct weston_view *ev, struct weston_layer *layer) |
Kristian Høgsberg | 962342c | 2012-06-26 16:29:50 -0400 | [diff] [blame] | 4375 | { |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 4376 | struct weston_view *v, *next; |
Kristian Høgsberg | 962342c | 2012-06-26 16:29:50 -0400 | [diff] [blame] | 4377 | |
Giulio Camuffo | 412e6a5 | 2014-07-09 22:12:56 +0300 | [diff] [blame] | 4378 | 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] | 4379 | if (v->output == ev->output && v != ev) { |
| 4380 | weston_view_unmap(v); |
| 4381 | v->surface->configure = NULL; |
Pekka Paalanen | 8274d90 | 2014-08-06 19:36:51 +0300 | [diff] [blame] | 4382 | weston_surface_set_label_func(v->surface, NULL); |
Kristian Høgsberg | 962342c | 2012-06-26 16:29:50 -0400 | [diff] [blame] | 4383 | } |
| 4384 | } |
| 4385 | |
Jason Ekstrand | 918f2dd | 2013-12-02 21:01:53 -0600 | [diff] [blame] | 4386 | weston_view_set_position(ev, ev->output->x, ev->output->y); |
Kristian Høgsberg | 962342c | 2012-06-26 16:29:50 -0400 | [diff] [blame] | 4387 | |
Giulio Camuffo | 412e6a5 | 2014-07-09 22:12:56 +0300 | [diff] [blame] | 4388 | if (wl_list_empty(&ev->layer_link.link)) { |
| 4389 | weston_layer_entry_insert(&layer->view_list, &ev->layer_link); |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 4390 | weston_compositor_schedule_repaint(ev->surface->compositor); |
Kristian Høgsberg | 962342c | 2012-06-26 16:29:50 -0400 | [diff] [blame] | 4391 | } |
| 4392 | } |
| 4393 | |
Pekka Paalanen | 8274d90 | 2014-08-06 19:36:51 +0300 | [diff] [blame] | 4394 | static int |
| 4395 | background_get_label(struct weston_surface *surface, char *buf, size_t len) |
| 4396 | { |
| 4397 | return snprintf(buf, len, "background for output %s", |
| 4398 | surface->output->name); |
| 4399 | } |
| 4400 | |
Kristian Høgsberg | 962342c | 2012-06-26 16:29:50 -0400 | [diff] [blame] | 4401 | static void |
Jason Ekstrand | 918f2dd | 2013-12-02 21:01:53 -0600 | [diff] [blame] | 4402 | background_configure(struct weston_surface *es, int32_t sx, int32_t sy) |
Kristian Høgsberg | af7b1ff | 2012-06-26 21:19:23 -0400 | [diff] [blame] | 4403 | { |
Giulio Camuffo | 7fe01b1 | 2013-03-28 18:02:42 +0100 | [diff] [blame] | 4404 | struct desktop_shell *shell = es->configure_private; |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 4405 | struct weston_view *view; |
Kristian Høgsberg | af7b1ff | 2012-06-26 21:19:23 -0400 | [diff] [blame] | 4406 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 4407 | view = container_of(es->views.next, struct weston_view, surface_link); |
| 4408 | |
Jason Ekstrand | 918f2dd | 2013-12-02 21:01:53 -0600 | [diff] [blame] | 4409 | configure_static_view(view, &shell->background_layer); |
Kristian Høgsberg | af7b1ff | 2012-06-26 21:19:23 -0400 | [diff] [blame] | 4410 | } |
| 4411 | |
| 4412 | static void |
Kristian Høgsberg | 7584062 | 2011-09-06 13:48:16 -0400 | [diff] [blame] | 4413 | desktop_shell_set_background(struct wl_client *client, |
| 4414 | struct wl_resource *resource, |
Benjamin Franzke | d0f79ab | 2011-11-22 12:43:52 +0100 | [diff] [blame] | 4415 | struct wl_resource *output_resource, |
Kristian Høgsberg | 7584062 | 2011-09-06 13:48:16 -0400 | [diff] [blame] | 4416 | struct wl_resource *surface_resource) |
| 4417 | { |
Jason Ekstrand | 651f00e | 2013-06-14 10:07:54 -0500 | [diff] [blame] | 4418 | struct desktop_shell *shell = wl_resource_get_user_data(resource); |
Jason Ekstrand | 0f2ef7e | 2013-06-14 10:07:53 -0500 | [diff] [blame] | 4419 | struct weston_surface *surface = |
| 4420 | wl_resource_get_user_data(surface_resource); |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 4421 | struct weston_view *view, *next; |
Kristian Høgsberg | 7584062 | 2011-09-06 13:48:16 -0400 | [diff] [blame] | 4422 | |
Kristian Høgsberg | 962342c | 2012-06-26 16:29:50 -0400 | [diff] [blame] | 4423 | if (surface->configure) { |
| 4424 | wl_resource_post_error(surface_resource, |
| 4425 | WL_DISPLAY_ERROR_INVALID_OBJECT, |
| 4426 | "surface role already assigned"); |
| 4427 | return; |
| 4428 | } |
Benjamin Franzke | d0f79ab | 2011-11-22 12:43:52 +0100 | [diff] [blame] | 4429 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 4430 | wl_list_for_each_safe(view, next, &surface->views, surface_link) |
| 4431 | weston_view_destroy(view); |
| 4432 | view = weston_view_create(surface); |
| 4433 | |
Kristian Høgsberg | 962342c | 2012-06-26 16:29:50 -0400 | [diff] [blame] | 4434 | surface->configure = background_configure; |
Giulio Camuffo | 7fe01b1 | 2013-03-28 18:02:42 +0100 | [diff] [blame] | 4435 | surface->configure_private = shell; |
Pekka Paalanen | 8274d90 | 2014-08-06 19:36:51 +0300 | [diff] [blame] | 4436 | weston_surface_set_label_func(surface, background_get_label); |
Jason Ekstrand | a0d2dde | 2013-06-14 10:08:01 -0500 | [diff] [blame] | 4437 | surface->output = wl_resource_get_user_data(output_resource); |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 4438 | view->output = surface->output; |
Kristian Høgsberg | eae5de7 | 2012-04-11 22:42:15 -0400 | [diff] [blame] | 4439 | desktop_shell_send_configure(resource, 0, |
Kristian Høgsberg | 0b5cd0c | 2012-03-04 21:57:37 -0500 | [diff] [blame] | 4440 | surface_resource, |
Scott Moreau | 1bad5db | 2012-08-18 01:04:05 -0600 | [diff] [blame] | 4441 | surface->output->width, |
| 4442 | surface->output->height); |
Kristian Høgsberg | 7584062 | 2011-09-06 13:48:16 -0400 | [diff] [blame] | 4443 | } |
| 4444 | |
Pekka Paalanen | 8274d90 | 2014-08-06 19:36:51 +0300 | [diff] [blame] | 4445 | static int |
| 4446 | panel_get_label(struct weston_surface *surface, char *buf, size_t len) |
| 4447 | { |
| 4448 | return snprintf(buf, len, "panel for output %s", |
| 4449 | surface->output->name); |
| 4450 | } |
| 4451 | |
Kristian Høgsberg | 7584062 | 2011-09-06 13:48:16 -0400 | [diff] [blame] | 4452 | static void |
Jason Ekstrand | 918f2dd | 2013-12-02 21:01:53 -0600 | [diff] [blame] | 4453 | 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] | 4454 | { |
Giulio Camuffo | 7fe01b1 | 2013-03-28 18:02:42 +0100 | [diff] [blame] | 4455 | struct desktop_shell *shell = es->configure_private; |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 4456 | struct weston_view *view; |
Kristian Høgsberg | af7b1ff | 2012-06-26 21:19:23 -0400 | [diff] [blame] | 4457 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 4458 | view = container_of(es->views.next, struct weston_view, surface_link); |
| 4459 | |
Jason Ekstrand | 918f2dd | 2013-12-02 21:01:53 -0600 | [diff] [blame] | 4460 | configure_static_view(view, &shell->panel_layer); |
Kristian Høgsberg | af7b1ff | 2012-06-26 21:19:23 -0400 | [diff] [blame] | 4461 | } |
| 4462 | |
| 4463 | static void |
Kristian Høgsberg | 7584062 | 2011-09-06 13:48:16 -0400 | [diff] [blame] | 4464 | desktop_shell_set_panel(struct wl_client *client, |
| 4465 | struct wl_resource *resource, |
Benjamin Franzke | d0f79ab | 2011-11-22 12:43:52 +0100 | [diff] [blame] | 4466 | struct wl_resource *output_resource, |
Kristian Høgsberg | 7584062 | 2011-09-06 13:48:16 -0400 | [diff] [blame] | 4467 | struct wl_resource *surface_resource) |
| 4468 | { |
Jason Ekstrand | 651f00e | 2013-06-14 10:07:54 -0500 | [diff] [blame] | 4469 | struct desktop_shell *shell = wl_resource_get_user_data(resource); |
Jason Ekstrand | 0f2ef7e | 2013-06-14 10:07:53 -0500 | [diff] [blame] | 4470 | struct weston_surface *surface = |
| 4471 | wl_resource_get_user_data(surface_resource); |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 4472 | struct weston_view *view, *next; |
Kristian Høgsberg | 7584062 | 2011-09-06 13:48:16 -0400 | [diff] [blame] | 4473 | |
Kristian Høgsberg | af7b1ff | 2012-06-26 21:19:23 -0400 | [diff] [blame] | 4474 | if (surface->configure) { |
| 4475 | wl_resource_post_error(surface_resource, |
| 4476 | WL_DISPLAY_ERROR_INVALID_OBJECT, |
| 4477 | "surface role already assigned"); |
| 4478 | return; |
| 4479 | } |
Benjamin Franzke | d0f79ab | 2011-11-22 12:43:52 +0100 | [diff] [blame] | 4480 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 4481 | wl_list_for_each_safe(view, next, &surface->views, surface_link) |
| 4482 | weston_view_destroy(view); |
| 4483 | view = weston_view_create(surface); |
| 4484 | |
Kristian Høgsberg | af7b1ff | 2012-06-26 21:19:23 -0400 | [diff] [blame] | 4485 | surface->configure = panel_configure; |
Giulio Camuffo | 7fe01b1 | 2013-03-28 18:02:42 +0100 | [diff] [blame] | 4486 | surface->configure_private = shell; |
Pekka Paalanen | 8274d90 | 2014-08-06 19:36:51 +0300 | [diff] [blame] | 4487 | weston_surface_set_label_func(surface, panel_get_label); |
Jason Ekstrand | a0d2dde | 2013-06-14 10:08:01 -0500 | [diff] [blame] | 4488 | surface->output = wl_resource_get_user_data(output_resource); |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 4489 | view->output = surface->output; |
Kristian Høgsberg | eae5de7 | 2012-04-11 22:42:15 -0400 | [diff] [blame] | 4490 | desktop_shell_send_configure(resource, 0, |
Kristian Høgsberg | af7b1ff | 2012-06-26 21:19:23 -0400 | [diff] [blame] | 4491 | surface_resource, |
Scott Moreau | 1bad5db | 2012-08-18 01:04:05 -0600 | [diff] [blame] | 4492 | surface->output->width, |
| 4493 | surface->output->height); |
Kristian Høgsberg | 7584062 | 2011-09-06 13:48:16 -0400 | [diff] [blame] | 4494 | } |
| 4495 | |
Pekka Paalanen | 8274d90 | 2014-08-06 19:36:51 +0300 | [diff] [blame] | 4496 | static int |
| 4497 | lock_surface_get_label(struct weston_surface *surface, char *buf, size_t len) |
| 4498 | { |
| 4499 | return snprintf(buf, len, "lock window"); |
| 4500 | } |
| 4501 | |
Pekka Paalanen | 9ef3e01 | 2011-11-15 13:34:48 +0200 | [diff] [blame] | 4502 | static void |
Jason Ekstrand | 918f2dd | 2013-12-02 21:01:53 -0600 | [diff] [blame] | 4503 | 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] | 4504 | { |
Giulio Camuffo | 7fe01b1 | 2013-03-28 18:02:42 +0100 | [diff] [blame] | 4505 | struct desktop_shell *shell = surface->configure_private; |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 4506 | struct weston_view *view; |
| 4507 | |
| 4508 | view = container_of(surface->views.next, struct weston_view, surface_link); |
Kristian Høgsberg | 730c94d | 2012-06-26 21:44:35 -0400 | [diff] [blame] | 4509 | |
Jason Ekstrand | 918f2dd | 2013-12-02 21:01:53 -0600 | [diff] [blame] | 4510 | if (surface->width == 0) |
Giulio Camuffo | 184df50 | 2013-02-21 11:29:21 +0100 | [diff] [blame] | 4511 | return; |
| 4512 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 4513 | center_on_output(view, get_default_output(shell->compositor)); |
Kristian Høgsberg | 730c94d | 2012-06-26 21:44:35 -0400 | [diff] [blame] | 4514 | |
| 4515 | if (!weston_surface_is_mapped(surface)) { |
Giulio Camuffo | 412e6a5 | 2014-07-09 22:12:56 +0300 | [diff] [blame] | 4516 | weston_layer_entry_insert(&shell->lock_layer.view_list, |
| 4517 | &view->layer_link); |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 4518 | weston_view_update_transform(view); |
Ander Conselvan de Oliveira | 87524b6 | 2013-02-21 18:35:22 +0200 | [diff] [blame] | 4519 | shell_fade(shell, FADE_IN); |
Kristian Høgsberg | 730c94d | 2012-06-26 21:44:35 -0400 | [diff] [blame] | 4520 | } |
| 4521 | } |
| 4522 | |
| 4523 | static void |
Kristian Høgsberg | 27e3052 | 2012-04-11 23:18:23 -0400 | [diff] [blame] | 4524 | handle_lock_surface_destroy(struct wl_listener *listener, void *data) |
Kristian Høgsberg | 1ec0c31 | 2011-11-15 16:39:55 -0500 | [diff] [blame] | 4525 | { |
Tiago Vignatti | be14326 | 2012-04-16 17:31:41 +0300 | [diff] [blame] | 4526 | struct desktop_shell *shell = |
| 4527 | container_of(listener, struct desktop_shell, lock_surface_listener); |
Kristian Høgsberg | 1ec0c31 | 2011-11-15 16:39:55 -0500 | [diff] [blame] | 4528 | |
Martin Minarik | 6d11836 | 2012-06-07 18:01:59 +0200 | [diff] [blame] | 4529 | weston_log("lock surface gone\n"); |
Kristian Høgsberg | 1ec0c31 | 2011-11-15 16:39:55 -0500 | [diff] [blame] | 4530 | shell->lock_surface = NULL; |
| 4531 | } |
| 4532 | |
| 4533 | static void |
Pekka Paalanen | 9ef3e01 | 2011-11-15 13:34:48 +0200 | [diff] [blame] | 4534 | desktop_shell_set_lock_surface(struct wl_client *client, |
| 4535 | struct wl_resource *resource, |
| 4536 | struct wl_resource *surface_resource) |
| 4537 | { |
Jason Ekstrand | 651f00e | 2013-06-14 10:07:54 -0500 | [diff] [blame] | 4538 | struct desktop_shell *shell = wl_resource_get_user_data(resource); |
Jason Ekstrand | 0f2ef7e | 2013-06-14 10:07:53 -0500 | [diff] [blame] | 4539 | struct weston_surface *surface = |
| 4540 | wl_resource_get_user_data(surface_resource); |
Pekka Paalanen | 9826223 | 2011-12-01 10:42:22 +0200 | [diff] [blame] | 4541 | |
Pekka Paalanen | f0fc70d | 2011-11-15 13:34:54 +0200 | [diff] [blame] | 4542 | shell->prepare_event_sent = false; |
Kristian Høgsberg | af867cc | 2011-11-15 13:34:49 +0200 | [diff] [blame] | 4543 | |
Pekka Paalanen | f0fc70d | 2011-11-15 13:34:54 +0200 | [diff] [blame] | 4544 | if (!shell->locked) |
| 4545 | return; |
| 4546 | |
Pekka Paalanen | 9826223 | 2011-12-01 10:42:22 +0200 | [diff] [blame] | 4547 | shell->lock_surface = surface; |
Pekka Paalanen | f0fc70d | 2011-11-15 13:34:54 +0200 | [diff] [blame] | 4548 | |
Kristian Høgsberg | 27e3052 | 2012-04-11 23:18:23 -0400 | [diff] [blame] | 4549 | shell->lock_surface_listener.notify = handle_lock_surface_destroy; |
Jason Ekstrand | 651f00e | 2013-06-14 10:07:54 -0500 | [diff] [blame] | 4550 | wl_signal_add(&surface->destroy_signal, |
Kristian Høgsberg | 27e3052 | 2012-04-11 23:18:23 -0400 | [diff] [blame] | 4551 | &shell->lock_surface_listener); |
Pekka Paalanen | 57da4a8 | 2011-11-23 16:42:16 +0200 | [diff] [blame] | 4552 | |
Kristian Høgsberg | aa2ee8b | 2013-10-30 15:49:45 -0700 | [diff] [blame] | 4553 | weston_view_create(surface); |
Kristian Høgsberg | 730c94d | 2012-06-26 21:44:35 -0400 | [diff] [blame] | 4554 | surface->configure = lock_surface_configure; |
Giulio Camuffo | 7fe01b1 | 2013-03-28 18:02:42 +0100 | [diff] [blame] | 4555 | surface->configure_private = shell; |
Pekka Paalanen | 8274d90 | 2014-08-06 19:36:51 +0300 | [diff] [blame] | 4556 | weston_surface_set_label_func(surface, lock_surface_get_label); |
Pekka Paalanen | f0fc70d | 2011-11-15 13:34:54 +0200 | [diff] [blame] | 4557 | } |
| 4558 | |
| 4559 | static void |
Tiago Vignatti | be14326 | 2012-04-16 17:31:41 +0300 | [diff] [blame] | 4560 | resume_desktop(struct desktop_shell *shell) |
Pekka Paalanen | f0fc70d | 2011-11-15 13:34:54 +0200 | [diff] [blame] | 4561 | { |
Kristian Høgsberg | 4476aaf | 2012-06-25 14:03:13 -0400 | [diff] [blame] | 4562 | struct workspace *ws = get_current_workspace(shell); |
Pekka Paalanen | 77346a6 | 2011-11-30 16:26:35 +0200 | [diff] [blame] | 4563 | |
Kristian Høgsberg | 3be2ce9 | 2012-02-29 12:42:35 -0500 | [diff] [blame] | 4564 | wl_list_remove(&shell->lock_layer.link); |
Philipp Brüschweiler | 711fda8 | 2012-08-09 18:50:43 +0200 | [diff] [blame] | 4565 | if (shell->showing_input_panels) { |
Manuel Bachmann | 805d2f5 | 2014-03-05 12:21:34 +0100 | [diff] [blame] | 4566 | wl_list_insert(&shell->compositor->cursor_layer.link, |
Philipp Brüschweiler | 711fda8 | 2012-08-09 18:50:43 +0200 | [diff] [blame] | 4567 | &shell->input_panel_layer.link); |
| 4568 | wl_list_insert(&shell->input_panel_layer.link, |
Manuel Bachmann | 805d2f5 | 2014-03-05 12:21:34 +0100 | [diff] [blame] | 4569 | &shell->fullscreen_layer.link); |
Philipp Brüschweiler | 711fda8 | 2012-08-09 18:50:43 +0200 | [diff] [blame] | 4570 | } else { |
Manuel Bachmann | 805d2f5 | 2014-03-05 12:21:34 +0100 | [diff] [blame] | 4571 | wl_list_insert(&shell->compositor->cursor_layer.link, |
| 4572 | &shell->fullscreen_layer.link); |
Philipp Brüschweiler | 711fda8 | 2012-08-09 18:50:43 +0200 | [diff] [blame] | 4573 | } |
Manuel Bachmann | 805d2f5 | 2014-03-05 12:21:34 +0100 | [diff] [blame] | 4574 | wl_list_insert(&shell->fullscreen_layer.link, |
| 4575 | &shell->panel_layer.link); |
| 4576 | wl_list_insert(&shell->panel_layer.link, |
| 4577 | &ws->layer.link), |
Pekka Paalanen | f0fc70d | 2011-11-15 13:34:54 +0200 | [diff] [blame] | 4578 | |
Kristian Høgsberg | 2f5faff | 2012-07-31 16:36:34 -0400 | [diff] [blame] | 4579 | restore_focus_state(shell, get_current_workspace(shell)); |
Jonas Ådahl | 0476974 | 2012-06-13 00:01:24 +0200 | [diff] [blame] | 4580 | |
Pekka Paalanen | f0fc70d | 2011-11-15 13:34:54 +0200 | [diff] [blame] | 4581 | shell->locked = false; |
Ander Conselvan de Oliveira | 87524b6 | 2013-02-21 18:35:22 +0200 | [diff] [blame] | 4582 | shell_fade(shell, FADE_IN); |
Pekka Paalanen | fc6d91a | 2012-02-10 15:33:10 +0200 | [diff] [blame] | 4583 | weston_compositor_damage_all(shell->compositor); |
Pekka Paalanen | 9ef3e01 | 2011-11-15 13:34:48 +0200 | [diff] [blame] | 4584 | } |
| 4585 | |
| 4586 | static void |
| 4587 | desktop_shell_unlock(struct wl_client *client, |
| 4588 | struct wl_resource *resource) |
| 4589 | { |
Jason Ekstrand | 651f00e | 2013-06-14 10:07:54 -0500 | [diff] [blame] | 4590 | struct desktop_shell *shell = wl_resource_get_user_data(resource); |
Pekka Paalanen | 9ef3e01 | 2011-11-15 13:34:48 +0200 | [diff] [blame] | 4591 | |
Pekka Paalanen | 9ef3e01 | 2011-11-15 13:34:48 +0200 | [diff] [blame] | 4592 | shell->prepare_event_sent = false; |
Pekka Paalanen | f0fc70d | 2011-11-15 13:34:54 +0200 | [diff] [blame] | 4593 | |
| 4594 | if (shell->locked) |
| 4595 | resume_desktop(shell); |
Pekka Paalanen | 9ef3e01 | 2011-11-15 13:34:48 +0200 | [diff] [blame] | 4596 | } |
| 4597 | |
Kristian Høgsberg | d56bd90 | 2012-06-05 09:58:51 -0400 | [diff] [blame] | 4598 | static void |
Ander Conselvan de Oliveira | b9d2a0f | 2012-06-28 18:08:05 +0300 | [diff] [blame] | 4599 | desktop_shell_set_grab_surface(struct wl_client *client, |
Kristian Høgsberg | d56bd90 | 2012-06-05 09:58:51 -0400 | [diff] [blame] | 4600 | struct wl_resource *resource, |
| 4601 | struct wl_resource *surface_resource) |
| 4602 | { |
Jason Ekstrand | 651f00e | 2013-06-14 10:07:54 -0500 | [diff] [blame] | 4603 | struct desktop_shell *shell = wl_resource_get_user_data(resource); |
Kristian Høgsberg | d56bd90 | 2012-06-05 09:58:51 -0400 | [diff] [blame] | 4604 | |
Jason Ekstrand | 0f2ef7e | 2013-06-14 10:07:53 -0500 | [diff] [blame] | 4605 | shell->grab_surface = wl_resource_get_user_data(surface_resource); |
Kristian Høgsberg | 48588f8 | 2013-10-24 15:51:35 -0700 | [diff] [blame] | 4606 | weston_view_create(shell->grab_surface); |
Kristian Høgsberg | d56bd90 | 2012-06-05 09:58:51 -0400 | [diff] [blame] | 4607 | } |
| 4608 | |
Pekka Paalanen | 79346ab | 2013-05-22 18:03:09 +0300 | [diff] [blame] | 4609 | static void |
| 4610 | desktop_shell_desktop_ready(struct wl_client *client, |
| 4611 | struct wl_resource *resource) |
| 4612 | { |
Jason Ekstrand | 651f00e | 2013-06-14 10:07:54 -0500 | [diff] [blame] | 4613 | struct desktop_shell *shell = wl_resource_get_user_data(resource); |
Pekka Paalanen | 79346ab | 2013-05-22 18:03:09 +0300 | [diff] [blame] | 4614 | |
| 4615 | shell_fade_startup(shell); |
| 4616 | } |
| 4617 | |
Jonny Lamb | 765760d | 2014-08-20 15:53:19 +0200 | [diff] [blame] | 4618 | static void |
| 4619 | desktop_shell_set_panel_position(struct wl_client *client, |
| 4620 | struct wl_resource *resource, |
| 4621 | uint32_t position) |
| 4622 | { |
| 4623 | struct desktop_shell *shell = wl_resource_get_user_data(resource); |
| 4624 | |
| 4625 | if (position != DESKTOP_SHELL_PANEL_POSITION_TOP && |
| 4626 | position != DESKTOP_SHELL_PANEL_POSITION_BOTTOM && |
| 4627 | position != DESKTOP_SHELL_PANEL_POSITION_LEFT && |
| 4628 | position != DESKTOP_SHELL_PANEL_POSITION_RIGHT) { |
| 4629 | wl_resource_post_error(resource, |
| 4630 | DESKTOP_SHELL_ERROR_INVALID_ARGUMENT, |
| 4631 | "bad position argument"); |
| 4632 | return; |
| 4633 | } |
| 4634 | |
| 4635 | shell->panel_position = position; |
| 4636 | } |
| 4637 | |
Kristian Høgsberg | 7584062 | 2011-09-06 13:48:16 -0400 | [diff] [blame] | 4638 | static const struct desktop_shell_interface desktop_shell_implementation = { |
| 4639 | desktop_shell_set_background, |
Pekka Paalanen | 9ef3e01 | 2011-11-15 13:34:48 +0200 | [diff] [blame] | 4640 | desktop_shell_set_panel, |
| 4641 | desktop_shell_set_lock_surface, |
Kristian Høgsberg | d56bd90 | 2012-06-05 09:58:51 -0400 | [diff] [blame] | 4642 | desktop_shell_unlock, |
Pekka Paalanen | 79346ab | 2013-05-22 18:03:09 +0300 | [diff] [blame] | 4643 | desktop_shell_set_grab_surface, |
Jonny Lamb | 765760d | 2014-08-20 15:53:19 +0200 | [diff] [blame] | 4644 | desktop_shell_desktop_ready, |
| 4645 | desktop_shell_set_panel_position |
Kristian Høgsberg | 7584062 | 2011-09-06 13:48:16 -0400 | [diff] [blame] | 4646 | }; |
| 4647 | |
Pekka Paalanen | 92a0dc4 | 2011-11-28 15:34:13 +0200 | [diff] [blame] | 4648 | static enum shell_surface_type |
Kristian Høgsberg | 8334bc1 | 2012-01-03 10:29:47 -0500 | [diff] [blame] | 4649 | get_shell_surface_type(struct weston_surface *surface) |
Pekka Paalanen | 92a0dc4 | 2011-11-28 15:34:13 +0200 | [diff] [blame] | 4650 | { |
| 4651 | struct shell_surface *shsurf; |
| 4652 | |
| 4653 | shsurf = get_shell_surface(surface); |
| 4654 | if (!shsurf) |
Pekka Paalanen | 9826223 | 2011-12-01 10:42:22 +0200 | [diff] [blame] | 4655 | return SHELL_SURFACE_NONE; |
Pekka Paalanen | 92a0dc4 | 2011-11-28 15:34:13 +0200 | [diff] [blame] | 4656 | return shsurf->type; |
| 4657 | } |
| 4658 | |
Kristian Høgsberg | 7584062 | 2011-09-06 13:48:16 -0400 | [diff] [blame] | 4659 | static void |
Derek Foreman | 8ae2db5 | 2015-07-15 13:00:36 -0500 | [diff] [blame] | 4660 | move_binding(struct weston_pointer *pointer, uint32_t time, |
| 4661 | uint32_t button, void *data) |
Kristian Høgsberg | 0793756 | 2011-04-12 17:25:42 -0400 | [diff] [blame] | 4662 | { |
Rafal Mielniczuk | b2917a2 | 2014-01-05 20:04:59 +0100 | [diff] [blame] | 4663 | struct weston_surface *focus; |
Pekka Paalanen | 01388e2 | 2013-04-25 13:57:44 +0300 | [diff] [blame] | 4664 | struct weston_surface *surface; |
Kristian Høgsberg | 938b8fa | 2012-05-18 13:46:27 -0400 | [diff] [blame] | 4665 | struct shell_surface *shsurf; |
Kristian Høgsberg | d2abb83 | 2011-11-23 10:52:40 -0500 | [diff] [blame] | 4666 | |
Derek Foreman | 8ae2db5 | 2015-07-15 13:00:36 -0500 | [diff] [blame] | 4667 | if (pointer->focus == NULL) |
Rafal Mielniczuk | b2917a2 | 2014-01-05 20:04:59 +0100 | [diff] [blame] | 4668 | return; |
| 4669 | |
Derek Foreman | 8ae2db5 | 2015-07-15 13:00:36 -0500 | [diff] [blame] | 4670 | focus = pointer->focus->surface; |
Rafal Mielniczuk | b2917a2 | 2014-01-05 20:04:59 +0100 | [diff] [blame] | 4671 | |
Pekka Paalanen | 01388e2 | 2013-04-25 13:57:44 +0300 | [diff] [blame] | 4672 | surface = weston_surface_get_main_surface(focus); |
Benjamin Franzke | d0f79ab | 2011-11-22 12:43:52 +0100 | [diff] [blame] | 4673 | if (surface == NULL) |
| 4674 | return; |
Kristian Høgsberg | 0793756 | 2011-04-12 17:25:42 -0400 | [diff] [blame] | 4675 | |
Kristian Høgsberg | 938b8fa | 2012-05-18 13:46:27 -0400 | [diff] [blame] | 4676 | shsurf = get_shell_surface(surface); |
Rafael Antognolli | 03b1659 | 2013-12-03 15:35:42 -0200 | [diff] [blame] | 4677 | if (shsurf == NULL || shsurf->state.fullscreen || |
| 4678 | shsurf->state.maximized) |
Kristian Høgsberg | 938b8fa | 2012-05-18 13:46:27 -0400 | [diff] [blame] | 4679 | return; |
| 4680 | |
Derek Foreman | 794fa0e | 2015-07-15 13:00:38 -0500 | [diff] [blame] | 4681 | surface_move(shsurf, pointer, false); |
Kristian Høgsberg | 0793756 | 2011-04-12 17:25:42 -0400 | [diff] [blame] | 4682 | } |
| 4683 | |
| 4684 | static void |
Derek Foreman | 8ae2db5 | 2015-07-15 13:00:36 -0500 | [diff] [blame] | 4685 | maximize_binding(struct weston_keyboard *keyboard, uint32_t time, |
| 4686 | uint32_t button, void *data) |
Rafael Antognolli | ea997ac | 2013-12-03 15:35:48 -0200 | [diff] [blame] | 4687 | { |
Derek Foreman | 8ae2db5 | 2015-07-15 13:00:36 -0500 | [diff] [blame] | 4688 | struct weston_surface *focus = keyboard->focus; |
Rafael Antognolli | ea997ac | 2013-12-03 15:35:48 -0200 | [diff] [blame] | 4689 | struct weston_surface *surface; |
| 4690 | struct shell_surface *shsurf; |
| 4691 | |
| 4692 | surface = weston_surface_get_main_surface(focus); |
| 4693 | if (surface == NULL) |
| 4694 | return; |
| 4695 | |
| 4696 | shsurf = get_shell_surface(surface); |
| 4697 | if (shsurf == NULL) |
| 4698 | return; |
| 4699 | |
| 4700 | if (!shell_surface_is_xdg_surface(shsurf)) |
| 4701 | return; |
| 4702 | |
Jasper St. Pierre | ab2c108 | 2014-04-10 10:41:46 -0700 | [diff] [blame] | 4703 | shsurf->state_requested = true; |
| 4704 | shsurf->requested_state.maximized = !shsurf->state.maximized; |
Jasper St. Pierre | 9aa8ce6 | 2014-04-11 16:18:54 -0700 | [diff] [blame] | 4705 | send_configure_for_surface(shsurf); |
Rafael Antognolli | ea997ac | 2013-12-03 15:35:48 -0200 | [diff] [blame] | 4706 | } |
| 4707 | |
| 4708 | static void |
Derek Foreman | 8ae2db5 | 2015-07-15 13:00:36 -0500 | [diff] [blame] | 4709 | fullscreen_binding(struct weston_keyboard *keyboard, uint32_t time, |
| 4710 | uint32_t button, void *data) |
Rafael Antognolli | ea997ac | 2013-12-03 15:35:48 -0200 | [diff] [blame] | 4711 | { |
Derek Foreman | 8ae2db5 | 2015-07-15 13:00:36 -0500 | [diff] [blame] | 4712 | struct weston_surface *focus = keyboard->focus; |
Rafael Antognolli | ea997ac | 2013-12-03 15:35:48 -0200 | [diff] [blame] | 4713 | struct weston_surface *surface; |
| 4714 | struct shell_surface *shsurf; |
| 4715 | |
| 4716 | surface = weston_surface_get_main_surface(focus); |
| 4717 | if (surface == NULL) |
| 4718 | return; |
| 4719 | |
| 4720 | shsurf = get_shell_surface(surface); |
| 4721 | if (shsurf == NULL) |
| 4722 | return; |
| 4723 | |
| 4724 | if (!shell_surface_is_xdg_surface(shsurf)) |
| 4725 | return; |
| 4726 | |
Jasper St. Pierre | ab2c108 | 2014-04-10 10:41:46 -0700 | [diff] [blame] | 4727 | shsurf->state_requested = true; |
| 4728 | shsurf->requested_state.fullscreen = !shsurf->state.fullscreen; |
Boyan Ding | 32abdbb | 2014-06-26 10:19:32 +0800 | [diff] [blame] | 4729 | shsurf->fullscreen_output = shsurf->output; |
Jasper St. Pierre | 9aa8ce6 | 2014-04-11 16:18:54 -0700 | [diff] [blame] | 4730 | send_configure_for_surface(shsurf); |
Rafael Antognolli | ea997ac | 2013-12-03 15:35:48 -0200 | [diff] [blame] | 4731 | } |
| 4732 | |
| 4733 | static void |
Derek Foreman | 8ae2db5 | 2015-07-15 13:00:36 -0500 | [diff] [blame] | 4734 | touch_move_binding(struct weston_touch *touch, uint32_t time, void *data) |
Neil Roberts | aba0f25 | 2013-10-03 16:43:05 +0100 | [diff] [blame] | 4735 | { |
Derek Foreman | 362656b | 2014-09-04 10:23:05 -0500 | [diff] [blame] | 4736 | struct weston_surface *focus; |
Neil Roberts | aba0f25 | 2013-10-03 16:43:05 +0100 | [diff] [blame] | 4737 | struct weston_surface *surface; |
| 4738 | struct shell_surface *shsurf; |
| 4739 | |
Derek Foreman | 8ae2db5 | 2015-07-15 13:00:36 -0500 | [diff] [blame] | 4740 | if (touch->focus == NULL) |
Derek Foreman | 362656b | 2014-09-04 10:23:05 -0500 | [diff] [blame] | 4741 | return; |
| 4742 | |
Derek Foreman | 8ae2db5 | 2015-07-15 13:00:36 -0500 | [diff] [blame] | 4743 | focus = touch->focus->surface; |
Neil Roberts | aba0f25 | 2013-10-03 16:43:05 +0100 | [diff] [blame] | 4744 | surface = weston_surface_get_main_surface(focus); |
| 4745 | if (surface == NULL) |
| 4746 | return; |
| 4747 | |
| 4748 | shsurf = get_shell_surface(surface); |
Rafael Antognolli | 03b1659 | 2013-12-03 15:35:42 -0200 | [diff] [blame] | 4749 | if (shsurf == NULL || shsurf->state.fullscreen || |
| 4750 | shsurf->state.maximized) |
Neil Roberts | aba0f25 | 2013-10-03 16:43:05 +0100 | [diff] [blame] | 4751 | return; |
| 4752 | |
Derek Foreman | b7674ae | 2015-07-15 13:00:37 -0500 | [diff] [blame] | 4753 | surface_touch_move(shsurf, touch); |
Neil Roberts | aba0f25 | 2013-10-03 16:43:05 +0100 | [diff] [blame] | 4754 | } |
| 4755 | |
| 4756 | static void |
Derek Foreman | 8ae2db5 | 2015-07-15 13:00:36 -0500 | [diff] [blame] | 4757 | resize_binding(struct weston_pointer *pointer, uint32_t time, |
| 4758 | uint32_t button, void *data) |
Kristian Høgsberg | 0793756 | 2011-04-12 17:25:42 -0400 | [diff] [blame] | 4759 | { |
Rafal Mielniczuk | b2917a2 | 2014-01-05 20:04:59 +0100 | [diff] [blame] | 4760 | struct weston_surface *focus; |
Pekka Paalanen | 01388e2 | 2013-04-25 13:57:44 +0300 | [diff] [blame] | 4761 | struct weston_surface *surface; |
Kristian Høgsberg | 0793756 | 2011-04-12 17:25:42 -0400 | [diff] [blame] | 4762 | uint32_t edges = 0; |
| 4763 | int32_t x, y; |
Pekka Paalanen | 9d1613e | 2011-11-25 12:09:16 +0200 | [diff] [blame] | 4764 | struct shell_surface *shsurf; |
Kristian Høgsberg | d2abb83 | 2011-11-23 10:52:40 -0500 | [diff] [blame] | 4765 | |
Derek Foreman | 8ae2db5 | 2015-07-15 13:00:36 -0500 | [diff] [blame] | 4766 | if (pointer->focus == NULL) |
Rafal Mielniczuk | b2917a2 | 2014-01-05 20:04:59 +0100 | [diff] [blame] | 4767 | return; |
| 4768 | |
Derek Foreman | 8ae2db5 | 2015-07-15 13:00:36 -0500 | [diff] [blame] | 4769 | focus = pointer->focus->surface; |
Rafal Mielniczuk | b2917a2 | 2014-01-05 20:04:59 +0100 | [diff] [blame] | 4770 | |
Pekka Paalanen | 01388e2 | 2013-04-25 13:57:44 +0300 | [diff] [blame] | 4771 | surface = weston_surface_get_main_surface(focus); |
Benjamin Franzke | d0f79ab | 2011-11-22 12:43:52 +0100 | [diff] [blame] | 4772 | if (surface == NULL) |
| 4773 | return; |
Pekka Paalanen | 92a0dc4 | 2011-11-28 15:34:13 +0200 | [diff] [blame] | 4774 | |
Pekka Paalanen | 9d1613e | 2011-11-25 12:09:16 +0200 | [diff] [blame] | 4775 | shsurf = get_shell_surface(surface); |
Rafael Antognolli | 03b1659 | 2013-12-03 15:35:42 -0200 | [diff] [blame] | 4776 | if (shsurf == NULL || shsurf->state.fullscreen || |
| 4777 | shsurf->state.maximized) |
Pekka Paalanen | 92a0dc4 | 2011-11-28 15:34:13 +0200 | [diff] [blame] | 4778 | return; |
| 4779 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 4780 | weston_view_from_global(shsurf->view, |
Derek Foreman | 8ae2db5 | 2015-07-15 13:00:36 -0500 | [diff] [blame] | 4781 | wl_fixed_to_int(pointer->grab_x), |
| 4782 | wl_fixed_to_int(pointer->grab_y), |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 4783 | &x, &y); |
Kristian Høgsberg | 0793756 | 2011-04-12 17:25:42 -0400 | [diff] [blame] | 4784 | |
Jason Ekstrand | 918f2dd | 2013-12-02 21:01:53 -0600 | [diff] [blame] | 4785 | if (x < shsurf->surface->width / 3) |
Pekka Paalanen | 9d1613e | 2011-11-25 12:09:16 +0200 | [diff] [blame] | 4786 | edges |= WL_SHELL_SURFACE_RESIZE_LEFT; |
Jason Ekstrand | 918f2dd | 2013-12-02 21:01:53 -0600 | [diff] [blame] | 4787 | else if (x < 2 * shsurf->surface->width / 3) |
Kristian Høgsberg | 0793756 | 2011-04-12 17:25:42 -0400 | [diff] [blame] | 4788 | edges |= 0; |
| 4789 | else |
Pekka Paalanen | 9d1613e | 2011-11-25 12:09:16 +0200 | [diff] [blame] | 4790 | edges |= WL_SHELL_SURFACE_RESIZE_RIGHT; |
Kristian Høgsberg | 0793756 | 2011-04-12 17:25:42 -0400 | [diff] [blame] | 4791 | |
Jason Ekstrand | 918f2dd | 2013-12-02 21:01:53 -0600 | [diff] [blame] | 4792 | if (y < shsurf->surface->height / 3) |
Pekka Paalanen | 9d1613e | 2011-11-25 12:09:16 +0200 | [diff] [blame] | 4793 | edges |= WL_SHELL_SURFACE_RESIZE_TOP; |
Jason Ekstrand | 918f2dd | 2013-12-02 21:01:53 -0600 | [diff] [blame] | 4794 | else if (y < 2 * shsurf->surface->height / 3) |
Kristian Høgsberg | 0793756 | 2011-04-12 17:25:42 -0400 | [diff] [blame] | 4795 | edges |= 0; |
| 4796 | else |
Pekka Paalanen | 9d1613e | 2011-11-25 12:09:16 +0200 | [diff] [blame] | 4797 | edges |= WL_SHELL_SURFACE_RESIZE_BOTTOM; |
Kristian Høgsberg | 0793756 | 2011-04-12 17:25:42 -0400 | [diff] [blame] | 4798 | |
Derek Foreman | 8fbebbd | 2015-07-15 13:00:40 -0500 | [diff] [blame] | 4799 | surface_resize(shsurf, pointer, edges); |
Kristian Høgsberg | 02ec0a5 | 2011-04-23 13:04:11 -0400 | [diff] [blame] | 4800 | } |
| 4801 | |
| 4802 | static void |
Derek Foreman | 8ae2db5 | 2015-07-15 13:00:36 -0500 | [diff] [blame] | 4803 | surface_opacity_binding(struct weston_pointer *pointer, uint32_t time, |
| 4804 | uint32_t axis, wl_fixed_t value, void *data) |
Scott Moreau | a3aa9c9 | 2012-03-22 11:01:03 -0600 | [diff] [blame] | 4805 | { |
Jonas Ådahl | b0b87ba | 2012-09-27 18:40:42 +0200 | [diff] [blame] | 4806 | float step = 0.005; |
Scott Moreau | a3aa9c9 | 2012-03-22 11:01:03 -0600 | [diff] [blame] | 4807 | struct shell_surface *shsurf; |
Derek Foreman | 8ae2db5 | 2015-07-15 13:00:36 -0500 | [diff] [blame] | 4808 | struct weston_surface *focus = pointer->focus->surface; |
Pekka Paalanen | 01388e2 | 2013-04-25 13:57:44 +0300 | [diff] [blame] | 4809 | struct weston_surface *surface; |
Scott Moreau | a3aa9c9 | 2012-03-22 11:01:03 -0600 | [diff] [blame] | 4810 | |
Pekka Paalanen | 01388e2 | 2013-04-25 13:57:44 +0300 | [diff] [blame] | 4811 | /* XXX: broken for windows containing sub-surfaces */ |
| 4812 | surface = weston_surface_get_main_surface(focus); |
Scott Moreau | a3aa9c9 | 2012-03-22 11:01:03 -0600 | [diff] [blame] | 4813 | if (surface == NULL) |
| 4814 | return; |
| 4815 | |
| 4816 | shsurf = get_shell_surface(surface); |
| 4817 | if (!shsurf) |
| 4818 | return; |
| 4819 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 4820 | shsurf->view->alpha -= wl_fixed_to_double(value) * step; |
Scott Moreau | a3aa9c9 | 2012-03-22 11:01:03 -0600 | [diff] [blame] | 4821 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 4822 | if (shsurf->view->alpha > 1.0) |
| 4823 | shsurf->view->alpha = 1.0; |
| 4824 | if (shsurf->view->alpha < step) |
| 4825 | shsurf->view->alpha = 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 | weston_view_geometry_dirty(shsurf->view); |
Scott Moreau | a3aa9c9 | 2012-03-22 11:01:03 -0600 | [diff] [blame] | 4828 | weston_surface_damage(surface); |
| 4829 | } |
| 4830 | |
| 4831 | static void |
Kristian Høgsberg | e314875 | 2013-05-06 23:19:49 -0400 | [diff] [blame] | 4832 | 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] | 4833 | wl_fixed_t value) |
Scott Moreau | ccbf29d | 2012-02-22 14:21:41 -0700 | [diff] [blame] | 4834 | { |
Derek Foreman | 8aeeac8 | 2015-01-30 13:24:36 -0600 | [diff] [blame] | 4835 | struct weston_compositor *compositor = seat->compositor; |
Derek Foreman | 1281a36 | 2015-07-31 16:55:32 -0500 | [diff] [blame] | 4836 | struct weston_pointer *pointer = weston_seat_get_pointer(seat); |
Scott Moreau | ccbf29d | 2012-02-22 14:21:41 -0700 | [diff] [blame] | 4837 | struct weston_output *output; |
Scott Moreau | e660398 | 2012-06-11 13:07:51 -0600 | [diff] [blame] | 4838 | float increment; |
Scott Moreau | ccbf29d | 2012-02-22 14:21:41 -0700 | [diff] [blame] | 4839 | |
Derek Foreman | 1281a36 | 2015-07-31 16:55:32 -0500 | [diff] [blame] | 4840 | if (!pointer) { |
Derek Foreman | 7ef3bed | 2015-01-06 14:28:13 -0600 | [diff] [blame] | 4841 | weston_log("Zoom hotkey pressed but seat '%s' contains no pointer.\n", seat->seat_name); |
| 4842 | return; |
| 4843 | } |
| 4844 | |
Scott Moreau | ccbf29d | 2012-02-22 14:21:41 -0700 | [diff] [blame] | 4845 | wl_list_for_each(output, &compositor->output_list, link) { |
| 4846 | if (pixman_region32_contains_point(&output->region, |
Derek Foreman | 1281a36 | 2015-07-31 16:55:32 -0500 | [diff] [blame] | 4847 | wl_fixed_to_double(pointer->x), |
| 4848 | wl_fixed_to_double(pointer->y), |
Daniel Stone | 103db7f | 2012-05-08 17:17:55 +0100 | [diff] [blame] | 4849 | NULL)) { |
Daniel Stone | 325fc2d | 2012-05-30 16:31:58 +0100 | [diff] [blame] | 4850 | if (key == KEY_PAGEUP) |
Kristian Høgsberg | 9b68af0 | 2012-05-22 12:55:18 -0400 | [diff] [blame] | 4851 | increment = output->zoom.increment; |
Daniel Stone | 325fc2d | 2012-05-30 16:31:58 +0100 | [diff] [blame] | 4852 | else if (key == KEY_PAGEDOWN) |
Kristian Høgsberg | 9b68af0 | 2012-05-22 12:55:18 -0400 | [diff] [blame] | 4853 | increment = -output->zoom.increment; |
| 4854 | else if (axis == WL_POINTER_AXIS_VERTICAL_SCROLL) |
Jonas Ådahl | b0b87ba | 2012-09-27 18:40:42 +0200 | [diff] [blame] | 4855 | /* For every pixel zoom 20th of a step */ |
Daniel Stone | 0c1e46e | 2012-05-30 16:31:59 +0100 | [diff] [blame] | 4856 | increment = output->zoom.increment * |
Jonas Ådahl | b0b87ba | 2012-09-27 18:40:42 +0200 | [diff] [blame] | 4857 | -wl_fixed_to_double(value) / 20.0; |
Kristian Høgsberg | 9b68af0 | 2012-05-22 12:55:18 -0400 | [diff] [blame] | 4858 | else |
| 4859 | increment = 0; |
| 4860 | |
Kristian Høgsberg | 9b68af0 | 2012-05-22 12:55:18 -0400 | [diff] [blame] | 4861 | output->zoom.level += increment; |
Scott Moreau | c6d7f60 | 2012-02-23 22:28:37 -0700 | [diff] [blame] | 4862 | |
Scott Moreau | e660398 | 2012-06-11 13:07:51 -0600 | [diff] [blame] | 4863 | if (output->zoom.level < 0.0) |
Scott Moreau | 850ca42 | 2012-05-21 15:21:25 -0600 | [diff] [blame] | 4864 | output->zoom.level = 0.0; |
Scott Moreau | e660398 | 2012-06-11 13:07:51 -0600 | [diff] [blame] | 4865 | else if (output->zoom.level > output->zoom.max_level) |
| 4866 | output->zoom.level = output->zoom.max_level; |
Derek Foreman | 25bd8a7 | 2015-07-23 14:55:13 -0500 | [diff] [blame] | 4867 | |
| 4868 | if (!output->zoom.active) { |
| 4869 | if (output->zoom.level <= 0.0) |
| 4870 | continue; |
Derek Foreman | 22276a5 | 2015-07-23 14:55:15 -0500 | [diff] [blame] | 4871 | weston_output_activate_zoom(output, seat); |
Kristian Høgsberg | 79af73e | 2012-08-03 15:45:23 -0400 | [diff] [blame] | 4872 | } |
Scott Moreau | ccbf29d | 2012-02-22 14:21:41 -0700 | [diff] [blame] | 4873 | |
Scott Moreau | e660398 | 2012-06-11 13:07:51 -0600 | [diff] [blame] | 4874 | output->zoom.spring_z.target = output->zoom.level; |
Scott Moreau | ccbf29d | 2012-02-22 14:21:41 -0700 | [diff] [blame] | 4875 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 4876 | weston_output_update_zoom(output); |
Scott Moreau | ccbf29d | 2012-02-22 14:21:41 -0700 | [diff] [blame] | 4877 | } |
| 4878 | } |
| 4879 | } |
| 4880 | |
Scott Moreau | ccbf29d | 2012-02-22 14:21:41 -0700 | [diff] [blame] | 4881 | static void |
Derek Foreman | 8ae2db5 | 2015-07-15 13:00:36 -0500 | [diff] [blame] | 4882 | zoom_axis_binding(struct weston_pointer *pointer, uint32_t time, |
| 4883 | uint32_t axis, wl_fixed_t value, void *data) |
Daniel Stone | 325fc2d | 2012-05-30 16:31:58 +0100 | [diff] [blame] | 4884 | { |
Derek Foreman | 8ae2db5 | 2015-07-15 13:00:36 -0500 | [diff] [blame] | 4885 | do_zoom(pointer->seat, time, 0, axis, value); |
Daniel Stone | 325fc2d | 2012-05-30 16:31:58 +0100 | [diff] [blame] | 4886 | } |
| 4887 | |
| 4888 | static void |
Derek Foreman | 8ae2db5 | 2015-07-15 13:00:36 -0500 | [diff] [blame] | 4889 | zoom_key_binding(struct weston_keyboard *keyboard, uint32_t time, |
| 4890 | uint32_t key, void *data) |
Daniel Stone | 325fc2d | 2012-05-30 16:31:58 +0100 | [diff] [blame] | 4891 | { |
Derek Foreman | 8ae2db5 | 2015-07-15 13:00:36 -0500 | [diff] [blame] | 4892 | do_zoom(keyboard->seat, time, key, 0, 0); |
Daniel Stone | 325fc2d | 2012-05-30 16:31:58 +0100 | [diff] [blame] | 4893 | } |
| 4894 | |
| 4895 | static void |
Derek Foreman | 8ae2db5 | 2015-07-15 13:00:36 -0500 | [diff] [blame] | 4896 | terminate_binding(struct weston_keyboard *keyboard, uint32_t time, |
| 4897 | uint32_t key, void *data) |
Kristian Høgsberg | e1a850e | 2011-12-19 15:18:05 -0500 | [diff] [blame] | 4898 | { |
Kristian Høgsberg | 8334bc1 | 2012-01-03 10:29:47 -0500 | [diff] [blame] | 4899 | struct weston_compositor *compositor = data; |
Kristian Høgsberg | e1a850e | 2011-12-19 15:18:05 -0500 | [diff] [blame] | 4900 | |
Daniel Stone | 325fc2d | 2012-05-30 16:31:58 +0100 | [diff] [blame] | 4901 | wl_display_terminate(compositor->wl_display); |
Kristian Høgsberg | e1a850e | 2011-12-19 15:18:05 -0500 | [diff] [blame] | 4902 | } |
| 4903 | |
Emilio Pozuelo Monfort | 03251b6 | 2013-11-19 11:37:16 +0100 | [diff] [blame] | 4904 | static void |
Giulio Camuffo | 1959ab8 | 2013-11-14 23:42:52 +0100 | [diff] [blame] | 4905 | rotate_grab_motion(struct weston_pointer_grab *grab, uint32_t time, |
| 4906 | wl_fixed_t x, wl_fixed_t y) |
Pekka Paalanen | 460099f | 2012-01-20 16:48:25 +0200 | [diff] [blame] | 4907 | { |
| 4908 | struct rotate_grab *rotate = |
Ander Conselvan de Oliveira | fe0444a | 2012-04-04 17:48:05 +0300 | [diff] [blame] | 4909 | container_of(grab, struct rotate_grab, base.grab); |
Kristian Høgsberg | 02bbabb | 2013-05-06 22:15:05 -0400 | [diff] [blame] | 4910 | struct weston_pointer *pointer = grab->pointer; |
Ander Conselvan de Oliveira | fe0444a | 2012-04-04 17:48:05 +0300 | [diff] [blame] | 4911 | struct shell_surface *shsurf = rotate->base.shsurf; |
John Kåre Alsaker | 490d02a | 2012-09-30 02:57:21 +0200 | [diff] [blame] | 4912 | float cx, cy, dx, dy, cposx, cposy, dposx, dposy, r; |
Ander Conselvan de Oliveira | fe0444a | 2012-04-04 17:48:05 +0300 | [diff] [blame] | 4913 | |
Giulio Camuffo | 1959ab8 | 2013-11-14 23:42:52 +0100 | [diff] [blame] | 4914 | weston_pointer_move(pointer, x, y); |
| 4915 | |
Ander Conselvan de Oliveira | fe0444a | 2012-04-04 17:48:05 +0300 | [diff] [blame] | 4916 | if (!shsurf) |
| 4917 | return; |
| 4918 | |
Jason Ekstrand | 918f2dd | 2013-12-02 21:01:53 -0600 | [diff] [blame] | 4919 | cx = 0.5f * shsurf->surface->width; |
| 4920 | cy = 0.5f * shsurf->surface->height; |
Pekka Paalanen | 460099f | 2012-01-20 16:48:25 +0200 | [diff] [blame] | 4921 | |
Daniel Stone | 37816df | 2012-05-16 18:45:18 +0100 | [diff] [blame] | 4922 | dx = wl_fixed_to_double(pointer->x) - rotate->center.x; |
| 4923 | dy = wl_fixed_to_double(pointer->y) - rotate->center.y; |
Pekka Paalanen | 460099f | 2012-01-20 16:48:25 +0200 | [diff] [blame] | 4924 | r = sqrtf(dx * dx + dy * dy); |
| 4925 | |
Ander Conselvan de Oliveira | fe0444a | 2012-04-04 17:48:05 +0300 | [diff] [blame] | 4926 | wl_list_remove(&shsurf->rotation.transform.link); |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 4927 | weston_view_geometry_dirty(shsurf->view); |
Pekka Paalanen | 460099f | 2012-01-20 16:48:25 +0200 | [diff] [blame] | 4928 | |
| 4929 | if (r > 20.0f) { |
Pekka Paalanen | 460099f | 2012-01-20 16:48:25 +0200 | [diff] [blame] | 4930 | struct weston_matrix *matrix = |
Ander Conselvan de Oliveira | fe0444a | 2012-04-04 17:48:05 +0300 | [diff] [blame] | 4931 | &shsurf->rotation.transform.matrix; |
Pekka Paalanen | 460099f | 2012-01-20 16:48:25 +0200 | [diff] [blame] | 4932 | |
Kristian Høgsberg | 765e27b | 2012-01-27 13:36:13 -0500 | [diff] [blame] | 4933 | weston_matrix_init(&rotate->rotation); |
Vasily Khoruzhick | 1bbf372 | 2013-01-28 22:40:28 +0300 | [diff] [blame] | 4934 | weston_matrix_rotate_xy(&rotate->rotation, dx / r, dy / r); |
Pekka Paalanen | 460099f | 2012-01-20 16:48:25 +0200 | [diff] [blame] | 4935 | |
| 4936 | weston_matrix_init(matrix); |
Pekka Paalanen | 7b3bd3d | 2012-01-30 14:16:34 +0200 | [diff] [blame] | 4937 | weston_matrix_translate(matrix, -cx, -cy, 0.0f); |
Ander Conselvan de Oliveira | fe0444a | 2012-04-04 17:48:05 +0300 | [diff] [blame] | 4938 | weston_matrix_multiply(matrix, &shsurf->rotation.rotation); |
Kristian Høgsberg | 765e27b | 2012-01-27 13:36:13 -0500 | [diff] [blame] | 4939 | weston_matrix_multiply(matrix, &rotate->rotation); |
Pekka Paalanen | 7b3bd3d | 2012-01-30 14:16:34 +0200 | [diff] [blame] | 4940 | weston_matrix_translate(matrix, cx, cy, 0.0f); |
Pekka Paalanen | 460099f | 2012-01-20 16:48:25 +0200 | [diff] [blame] | 4941 | |
Pekka Paalanen | bc0b7e7 | 2012-01-24 09:53:37 +0200 | [diff] [blame] | 4942 | wl_list_insert( |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 4943 | &shsurf->view->geometry.transformation_list, |
Ander Conselvan de Oliveira | fe0444a | 2012-04-04 17:48:05 +0300 | [diff] [blame] | 4944 | &shsurf->rotation.transform.link); |
Pekka Paalanen | 460099f | 2012-01-20 16:48:25 +0200 | [diff] [blame] | 4945 | } else { |
Ander Conselvan de Oliveira | fe0444a | 2012-04-04 17:48:05 +0300 | [diff] [blame] | 4946 | wl_list_init(&shsurf->rotation.transform.link); |
| 4947 | weston_matrix_init(&shsurf->rotation.rotation); |
Kristian Høgsberg | 765e27b | 2012-01-27 13:36:13 -0500 | [diff] [blame] | 4948 | weston_matrix_init(&rotate->rotation); |
Pekka Paalanen | 460099f | 2012-01-20 16:48:25 +0200 | [diff] [blame] | 4949 | } |
Pekka Paalanen | b45ac5e | 2012-02-09 15:58:44 +0200 | [diff] [blame] | 4950 | |
Rafal Mielniczuk | 2d7ab82 | 2012-03-22 22:22:04 +0100 | [diff] [blame] | 4951 | /* We need to adjust the position of the surface |
| 4952 | * in case it was resized in a rotated state before */ |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 4953 | cposx = shsurf->view->geometry.x + cx; |
| 4954 | cposy = shsurf->view->geometry.y + cy; |
Rafal Mielniczuk | 2d7ab82 | 2012-03-22 22:22:04 +0100 | [diff] [blame] | 4955 | dposx = rotate->center.x - cposx; |
| 4956 | dposy = rotate->center.y - cposy; |
| 4957 | if (dposx != 0.0f || dposy != 0.0f) { |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 4958 | weston_view_set_position(shsurf->view, |
| 4959 | shsurf->view->geometry.x + dposx, |
| 4960 | shsurf->view->geometry.y + dposy); |
Rafal Mielniczuk | 2d7ab82 | 2012-03-22 22:22:04 +0100 | [diff] [blame] | 4961 | } |
| 4962 | |
Derek Foreman | 4b1a0a1 | 2014-09-10 15:37:33 -0500 | [diff] [blame] | 4963 | /* Repaint implies weston_view_update_transform(), which |
Pekka Paalanen | b45ac5e | 2012-02-09 15:58:44 +0200 | [diff] [blame] | 4964 | * lazily applies the damage due to rotation update. |
| 4965 | */ |
Ander Conselvan de Oliveira | fe0444a | 2012-04-04 17:48:05 +0300 | [diff] [blame] | 4966 | weston_compositor_schedule_repaint(shsurf->surface->compositor); |
Pekka Paalanen | 460099f | 2012-01-20 16:48:25 +0200 | [diff] [blame] | 4967 | } |
| 4968 | |
| 4969 | static void |
Kristian Høgsberg | 02bbabb | 2013-05-06 22:15:05 -0400 | [diff] [blame] | 4970 | rotate_grab_button(struct weston_pointer_grab *grab, |
| 4971 | uint32_t time, uint32_t button, uint32_t state_w) |
Pekka Paalanen | 460099f | 2012-01-20 16:48:25 +0200 | [diff] [blame] | 4972 | { |
| 4973 | struct rotate_grab *rotate = |
Ander Conselvan de Oliveira | fe0444a | 2012-04-04 17:48:05 +0300 | [diff] [blame] | 4974 | container_of(grab, struct rotate_grab, base.grab); |
Kristian Høgsberg | 02bbabb | 2013-05-06 22:15:05 -0400 | [diff] [blame] | 4975 | struct weston_pointer *pointer = grab->pointer; |
Ander Conselvan de Oliveira | fe0444a | 2012-04-04 17:48:05 +0300 | [diff] [blame] | 4976 | struct shell_surface *shsurf = rotate->base.shsurf; |
Daniel Stone | 4dbadb1 | 2012-05-30 16:31:51 +0100 | [diff] [blame] | 4977 | enum wl_pointer_button_state state = state_w; |
Pekka Paalanen | 460099f | 2012-01-20 16:48:25 +0200 | [diff] [blame] | 4978 | |
Daniel Stone | 4dbadb1 | 2012-05-30 16:31:51 +0100 | [diff] [blame] | 4979 | if (pointer->button_count == 0 && |
| 4980 | state == WL_POINTER_BUTTON_STATE_RELEASED) { |
Ander Conselvan de Oliveira | fe0444a | 2012-04-04 17:48:05 +0300 | [diff] [blame] | 4981 | if (shsurf) |
| 4982 | weston_matrix_multiply(&shsurf->rotation.rotation, |
| 4983 | &rotate->rotation); |
Ander Conselvan de Oliveira | b9d2a0f | 2012-06-28 18:08:05 +0300 | [diff] [blame] | 4984 | shell_grab_end(&rotate->base); |
Pekka Paalanen | 460099f | 2012-01-20 16:48:25 +0200 | [diff] [blame] | 4985 | free(rotate); |
| 4986 | } |
| 4987 | } |
| 4988 | |
Jonas Ådahl | 1ea343e | 2013-10-25 23:18:05 +0200 | [diff] [blame] | 4989 | static void |
| 4990 | rotate_grab_cancel(struct weston_pointer_grab *grab) |
| 4991 | { |
| 4992 | struct rotate_grab *rotate = |
| 4993 | container_of(grab, struct rotate_grab, base.grab); |
| 4994 | |
| 4995 | shell_grab_end(&rotate->base); |
| 4996 | free(rotate); |
| 4997 | } |
| 4998 | |
Kristian Høgsberg | 02bbabb | 2013-05-06 22:15:05 -0400 | [diff] [blame] | 4999 | static const struct weston_pointer_grab_interface rotate_grab_interface = { |
Pekka Paalanen | 460099f | 2012-01-20 16:48:25 +0200 | [diff] [blame] | 5000 | noop_grab_focus, |
| 5001 | rotate_grab_motion, |
| 5002 | rotate_grab_button, |
Jonas Ådahl | 1ea343e | 2013-10-25 23:18:05 +0200 | [diff] [blame] | 5003 | rotate_grab_cancel, |
Pekka Paalanen | 460099f | 2012-01-20 16:48:25 +0200 | [diff] [blame] | 5004 | }; |
| 5005 | |
| 5006 | static void |
Derek Foreman | 74de469 | 2015-07-15 13:00:39 -0500 | [diff] [blame] | 5007 | surface_rotate(struct shell_surface *surface, struct weston_pointer *pointer) |
Pekka Paalanen | 460099f | 2012-01-20 16:48:25 +0200 | [diff] [blame] | 5008 | { |
Pekka Paalanen | 460099f | 2012-01-20 16:48:25 +0200 | [diff] [blame] | 5009 | struct rotate_grab *rotate; |
John Kåre Alsaker | 490d02a | 2012-09-30 02:57:21 +0200 | [diff] [blame] | 5010 | float dx, dy; |
| 5011 | float r; |
Pekka Paalanen | 460099f | 2012-01-20 16:48:25 +0200 | [diff] [blame] | 5012 | |
Derek Foreman | 45a7c27 | 2015-09-11 14:27:40 -0500 | [diff] [blame] | 5013 | surface = find_toplevel_surface(surface); |
| 5014 | |
Pekka Paalanen | 460099f | 2012-01-20 16:48:25 +0200 | [diff] [blame] | 5015 | rotate = malloc(sizeof *rotate); |
| 5016 | if (!rotate) |
| 5017 | return; |
| 5018 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 5019 | weston_view_to_global_float(surface->view, |
Jason Ekstrand | 918f2dd | 2013-12-02 21:01:53 -0600 | [diff] [blame] | 5020 | surface->surface->width * 0.5f, |
| 5021 | surface->surface->height * 0.5f, |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 5022 | &rotate->center.x, &rotate->center.y); |
Pekka Paalanen | 460099f | 2012-01-20 16:48:25 +0200 | [diff] [blame] | 5023 | |
Derek Foreman | 74de469 | 2015-07-15 13:00:39 -0500 | [diff] [blame] | 5024 | dx = wl_fixed_to_double(pointer->x) - rotate->center.x; |
| 5025 | dy = wl_fixed_to_double(pointer->y) - rotate->center.y; |
Kristian Høgsberg | 765e27b | 2012-01-27 13:36:13 -0500 | [diff] [blame] | 5026 | r = sqrtf(dx * dx + dy * dy); |
| 5027 | if (r > 20.0f) { |
| 5028 | struct weston_matrix inverse; |
| 5029 | |
| 5030 | weston_matrix_init(&inverse); |
Vasily Khoruzhick | 1bbf372 | 2013-01-28 22:40:28 +0300 | [diff] [blame] | 5031 | weston_matrix_rotate_xy(&inverse, dx / r, -dy / r); |
Kristian Høgsberg | 765e27b | 2012-01-27 13:36:13 -0500 | [diff] [blame] | 5032 | weston_matrix_multiply(&surface->rotation.rotation, &inverse); |
Rafal Mielniczuk | 2d7ab82 | 2012-03-22 22:22:04 +0100 | [diff] [blame] | 5033 | |
| 5034 | weston_matrix_init(&rotate->rotation); |
Vasily Khoruzhick | 1bbf372 | 2013-01-28 22:40:28 +0300 | [diff] [blame] | 5035 | weston_matrix_rotate_xy(&rotate->rotation, dx / r, dy / r); |
Kristian Høgsberg | 765e27b | 2012-01-27 13:36:13 -0500 | [diff] [blame] | 5036 | } else { |
| 5037 | weston_matrix_init(&surface->rotation.rotation); |
| 5038 | weston_matrix_init(&rotate->rotation); |
| 5039 | } |
| 5040 | |
Ander Conselvan de Oliveira | b9d2a0f | 2012-06-28 18:08:05 +0300 | [diff] [blame] | 5041 | shell_grab_start(&rotate->base, &rotate_grab_interface, surface, |
Derek Foreman | 74de469 | 2015-07-15 13:00:39 -0500 | [diff] [blame] | 5042 | pointer, DESKTOP_SHELL_CURSOR_ARROW); |
Pekka Paalanen | 460099f | 2012-01-20 16:48:25 +0200 | [diff] [blame] | 5043 | } |
| 5044 | |
| 5045 | static void |
Derek Foreman | 8ae2db5 | 2015-07-15 13:00:36 -0500 | [diff] [blame] | 5046 | 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] | 5047 | void *data) |
| 5048 | { |
Rafal Mielniczuk | b2917a2 | 2014-01-05 20:04:59 +0100 | [diff] [blame] | 5049 | struct weston_surface *focus; |
Pekka Paalanen | 01388e2 | 2013-04-25 13:57:44 +0300 | [diff] [blame] | 5050 | struct weston_surface *base_surface; |
Kristian Høgsberg | 0c36903 | 2013-02-14 21:31:44 -0500 | [diff] [blame] | 5051 | struct shell_surface *surface; |
| 5052 | |
Derek Foreman | 8ae2db5 | 2015-07-15 13:00:36 -0500 | [diff] [blame] | 5053 | if (pointer->focus == NULL) |
Rafal Mielniczuk | b2917a2 | 2014-01-05 20:04:59 +0100 | [diff] [blame] | 5054 | return; |
| 5055 | |
Derek Foreman | 8ae2db5 | 2015-07-15 13:00:36 -0500 | [diff] [blame] | 5056 | focus = pointer->focus->surface; |
Rafal Mielniczuk | b2917a2 | 2014-01-05 20:04:59 +0100 | [diff] [blame] | 5057 | |
Pekka Paalanen | 01388e2 | 2013-04-25 13:57:44 +0300 | [diff] [blame] | 5058 | base_surface = weston_surface_get_main_surface(focus); |
Kristian Høgsberg | 0c36903 | 2013-02-14 21:31:44 -0500 | [diff] [blame] | 5059 | if (base_surface == NULL) |
| 5060 | return; |
| 5061 | |
| 5062 | surface = get_shell_surface(base_surface); |
Rafael Antognolli | 03b1659 | 2013-12-03 15:35:42 -0200 | [diff] [blame] | 5063 | if (surface == NULL || surface->state.fullscreen || |
| 5064 | surface->state.maximized) |
Kristian Høgsberg | 0c36903 | 2013-02-14 21:31:44 -0500 | [diff] [blame] | 5065 | return; |
| 5066 | |
Derek Foreman | 74de469 | 2015-07-15 13:00:39 -0500 | [diff] [blame] | 5067 | surface_rotate(surface, pointer); |
Kristian Høgsberg | 0c36903 | 2013-02-14 21:31:44 -0500 | [diff] [blame] | 5068 | } |
| 5069 | |
Emilio Pozuelo Monfort | 9e7c759 | 2014-01-30 14:01:10 +0100 | [diff] [blame] | 5070 | /* Move all fullscreen layers down to the current workspace and hide their |
| 5071 | * black views. The surfaces' state is set to both fullscreen and lowered, |
| 5072 | * and this is reversed when such a surface is re-configured, see |
| 5073 | * shell_configure_fullscreen() and shell_ensure_fullscreen_black_view(). |
| 5074 | * |
Mario Kleiner | 9f4d655 | 2015-06-21 21:25:08 +0200 | [diff] [blame] | 5075 | * lowering_output = NULL - Lower on all outputs, else only lower on the |
| 5076 | * specified output. |
| 5077 | * |
Emilio Pozuelo Monfort | 9e7c759 | 2014-01-30 14:01:10 +0100 | [diff] [blame] | 5078 | * This should be used when implementing shell-wide overlays, such as |
Philip Withnall | 83ffd9d | 2013-11-25 18:01:42 +0000 | [diff] [blame] | 5079 | * the alt-tab switcher, which need to de-promote fullscreen layers. */ |
Kristian Høgsberg | 1ef2313 | 2013-12-04 00:20:01 -0800 | [diff] [blame] | 5080 | void |
Mario Kleiner | 9f4d655 | 2015-06-21 21:25:08 +0200 | [diff] [blame] | 5081 | lower_fullscreen_layer(struct desktop_shell *shell, |
| 5082 | struct weston_output *lowering_output) |
Kristian Høgsberg | b0d8e77 | 2012-06-18 16:34:58 -0400 | [diff] [blame] | 5083 | { |
| 5084 | struct workspace *ws; |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 5085 | struct weston_view *view, *prev; |
Kristian Høgsberg | b0d8e77 | 2012-06-18 16:34:58 -0400 | [diff] [blame] | 5086 | |
| 5087 | ws = get_current_workspace(shell); |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 5088 | wl_list_for_each_reverse_safe(view, prev, |
Giulio Camuffo | 412e6a5 | 2014-07-09 22:12:56 +0300 | [diff] [blame] | 5089 | &shell->fullscreen_layer.view_list.link, |
| 5090 | layer_link.link) { |
Emilio Pozuelo Monfort | 9e7c759 | 2014-01-30 14:01:10 +0100 | [diff] [blame] | 5091 | struct shell_surface *shsurf = get_shell_surface(view->surface); |
| 5092 | |
| 5093 | if (!shsurf) |
| 5094 | continue; |
| 5095 | |
Mario Kleiner | 9f4d655 | 2015-06-21 21:25:08 +0200 | [diff] [blame] | 5096 | /* Only lower surfaces which have lowering_output as their fullscreen |
| 5097 | * output, unless a NULL output asks for lowering on all outputs. |
| 5098 | */ |
| 5099 | if (lowering_output && (shsurf->fullscreen_output != lowering_output)) |
| 5100 | continue; |
| 5101 | |
Emilio Pozuelo Monfort | 9e7c759 | 2014-01-30 14:01:10 +0100 | [diff] [blame] | 5102 | /* We can have a non-fullscreen popup for a fullscreen surface |
| 5103 | * in the fullscreen layer. */ |
| 5104 | if (shsurf->state.fullscreen) { |
| 5105 | /* Hide the black view */ |
Giulio Camuffo | 412e6a5 | 2014-07-09 22:12:56 +0300 | [diff] [blame] | 5106 | weston_layer_entry_remove(&shsurf->fullscreen.black_view->layer_link); |
| 5107 | wl_list_init(&shsurf->fullscreen.black_view->layer_link.link); |
Kristian Høgsberg | c991513 | 2014-05-09 16:24:07 -0700 | [diff] [blame] | 5108 | weston_view_damage_below(shsurf->fullscreen.black_view); |
| 5109 | |
Emilio Pozuelo Monfort | 9e7c759 | 2014-01-30 14:01:10 +0100 | [diff] [blame] | 5110 | } |
| 5111 | |
| 5112 | /* Lower the view to the workspace layer */ |
Giulio Camuffo | 412e6a5 | 2014-07-09 22:12:56 +0300 | [diff] [blame] | 5113 | weston_layer_entry_remove(&view->layer_link); |
| 5114 | weston_layer_entry_insert(&ws->layer.view_list, &view->layer_link); |
Philip Withnall | 83ffd9d | 2013-11-25 18:01:42 +0000 | [diff] [blame] | 5115 | weston_view_damage_below(view); |
| 5116 | weston_surface_damage(view->surface); |
Emilio Pozuelo Monfort | 9e7c759 | 2014-01-30 14:01:10 +0100 | [diff] [blame] | 5117 | |
| 5118 | shsurf->state.lowered = true; |
Philip Withnall | 83ffd9d | 2013-11-25 18:01:42 +0000 | [diff] [blame] | 5119 | } |
Kristian Høgsberg | b0d8e77 | 2012-06-18 16:34:58 -0400 | [diff] [blame] | 5120 | } |
| 5121 | |
Kristian Høgsberg | 1ef2313 | 2013-12-04 00:20:01 -0800 | [diff] [blame] | 5122 | void |
Tiago Vignatti | be14326 | 2012-04-16 17:31:41 +0300 | [diff] [blame] | 5123 | activate(struct desktop_shell *shell, struct weston_surface *es, |
Emilio Pozuelo Monfort | 9e7c759 | 2014-01-30 14:01:10 +0100 | [diff] [blame] | 5124 | struct weston_seat *seat, bool configure) |
Kristian Høgsberg | 7584062 | 2011-09-06 13:48:16 -0400 | [diff] [blame] | 5125 | { |
Pekka Paalanen | 01388e2 | 2013-04-25 13:57:44 +0300 | [diff] [blame] | 5126 | struct weston_surface *main_surface; |
Kristian Høgsberg | 2f5faff | 2012-07-31 16:36:34 -0400 | [diff] [blame] | 5127 | struct focus_state *state; |
Jonas Ådahl | 8538b22 | 2012-08-29 22:13:03 +0200 | [diff] [blame] | 5128 | struct workspace *ws; |
Louis-Francis Ratté-Boulianne | b482dbd | 2013-11-19 11:37:11 +0100 | [diff] [blame] | 5129 | struct weston_surface *old_es; |
Rafael Antognolli | 03b1659 | 2013-12-03 15:35:42 -0200 | [diff] [blame] | 5130 | struct shell_surface *shsurf; |
Kristian Høgsberg | 7584062 | 2011-09-06 13:48:16 -0400 | [diff] [blame] | 5131 | |
Pekka Paalanen | 01388e2 | 2013-04-25 13:57:44 +0300 | [diff] [blame] | 5132 | main_surface = weston_surface_get_main_surface(es); |
Mario Kleiner | 9f4d655 | 2015-06-21 21:25:08 +0200 | [diff] [blame] | 5133 | shsurf = get_shell_surface(main_surface); |
| 5134 | assert(shsurf); |
| 5135 | |
| 5136 | /* Only demote fullscreen surfaces on the output of activated shsurf. |
| 5137 | * Leave fullscreen surfaces on unrelated outputs alone. */ |
| 5138 | lower_fullscreen_layer(shell, shsurf->output); |
Pekka Paalanen | 01388e2 | 2013-04-25 13:57:44 +0300 | [diff] [blame] | 5139 | |
Daniel Stone | 37816df | 2012-05-16 18:45:18 +0100 | [diff] [blame] | 5140 | weston_surface_activate(es, seat); |
Kristian Høgsberg | 7584062 | 2011-09-06 13:48:16 -0400 | [diff] [blame] | 5141 | |
Jonas Ådahl | 8538b22 | 2012-08-29 22:13:03 +0200 | [diff] [blame] | 5142 | state = ensure_focus_state(shell, seat); |
| 5143 | if (state == NULL) |
| 5144 | return; |
Kristian Høgsberg | 2f5faff | 2012-07-31 16:36:34 -0400 | [diff] [blame] | 5145 | |
Louis-Francis Ratté-Boulianne | b482dbd | 2013-11-19 11:37:11 +0100 | [diff] [blame] | 5146 | old_es = state->keyboard_focus; |
Kristian Høgsberg | d500bf1 | 2014-01-22 12:25:20 -0800 | [diff] [blame] | 5147 | focus_state_set_focus(state, es); |
Kristian Høgsberg | 2f5faff | 2012-07-31 16:36:34 -0400 | [diff] [blame] | 5148 | |
Emilio Pozuelo Monfort | 9e7c759 | 2014-01-30 14:01:10 +0100 | [diff] [blame] | 5149 | if (shsurf->state.fullscreen && configure) |
Rafael Antognolli | 03b1659 | 2013-12-03 15:35:42 -0200 | [diff] [blame] | 5150 | shell_configure_fullscreen(shsurf); |
| 5151 | else |
Mario Kleiner | 492c12f | 2015-06-21 21:25:12 +0200 | [diff] [blame] | 5152 | restore_output_mode(shsurf->output); |
Louis-Francis Ratté-Boulianne | b482dbd | 2013-11-19 11:37:11 +0100 | [diff] [blame] | 5153 | |
Emilio Pozuelo Monfort | 7908bff | 2014-01-30 13:49:39 +0100 | [diff] [blame] | 5154 | /* Update the surface’s layer. This brings it to the top of the stacking |
| 5155 | * order as appropriate. */ |
| 5156 | shell_surface_update_layer(shsurf); |
| 5157 | |
Philip Withnall | 83ffd9d | 2013-11-25 18:01:42 +0000 | [diff] [blame] | 5158 | if (shell->focus_animation_type != ANIMATION_NONE) { |
| 5159 | ws = get_current_workspace(shell); |
Louis-Francis Ratté-Boulianne | b482dbd | 2013-11-19 11:37:11 +0100 | [diff] [blame] | 5160 | 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] | 5161 | } |
Kristian Høgsberg | 7584062 | 2011-09-06 13:48:16 -0400 | [diff] [blame] | 5162 | } |
| 5163 | |
Alex Wu | 2185843 | 2012-04-01 20:13:08 +0800 | [diff] [blame] | 5164 | /* no-op func for checking black surface */ |
| 5165 | static void |
Jason Ekstrand | 918f2dd | 2013-12-02 21:01:53 -0600 | [diff] [blame] | 5166 | 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] | 5167 | { |
| 5168 | } |
| 5169 | |
Quentin Glidic | c0d79ce | 2013-01-29 14:16:13 +0100 | [diff] [blame] | 5170 | static bool |
Alex Wu | 2185843 | 2012-04-01 20:13:08 +0800 | [diff] [blame] | 5171 | is_black_surface (struct weston_surface *es, struct weston_surface **fs_surface) |
| 5172 | { |
| 5173 | if (es->configure == black_surface_configure) { |
| 5174 | if (fs_surface) |
Giulio Camuffo | 7fe01b1 | 2013-03-28 18:02:42 +0100 | [diff] [blame] | 5175 | *fs_surface = (struct weston_surface *)es->configure_private; |
Alex Wu | 2185843 | 2012-04-01 20:13:08 +0800 | [diff] [blame] | 5176 | return true; |
| 5177 | } |
| 5178 | return false; |
| 5179 | } |
| 5180 | |
Kristian Høgsberg | 7584062 | 2011-09-06 13:48:16 -0400 | [diff] [blame] | 5181 | static void |
Neil Roberts | a28c693 | 2013-10-03 16:43:04 +0100 | [diff] [blame] | 5182 | activate_binding(struct weston_seat *seat, |
| 5183 | struct desktop_shell *shell, |
Jonas Ådahl | cd0f1ac | 2015-06-26 12:37:56 +0800 | [diff] [blame] | 5184 | struct weston_view *focus_view) |
Kristian Høgsberg | e1a850e | 2011-12-19 15:18:05 -0500 | [diff] [blame] | 5185 | { |
Jonas Ådahl | cd0f1ac | 2015-06-26 12:37:56 +0800 | [diff] [blame] | 5186 | struct weston_surface *focus; |
Pekka Paalanen | 01388e2 | 2013-04-25 13:57:44 +0300 | [diff] [blame] | 5187 | struct weston_surface *main_surface; |
Kristian Høgsberg | e1a850e | 2011-12-19 15:18:05 -0500 | [diff] [blame] | 5188 | |
Jonas Ådahl | cd0f1ac | 2015-06-26 12:37:56 +0800 | [diff] [blame] | 5189 | focus = focus_view->surface; |
Alex Wu | 9c35e6b | 2012-03-05 14:13:13 +0800 | [diff] [blame] | 5190 | |
Pekka Paalanen | 01388e2 | 2013-04-25 13:57:44 +0300 | [diff] [blame] | 5191 | if (is_black_surface(focus, &main_surface)) |
| 5192 | focus = main_surface; |
Alex Wu | 4539b08 | 2012-03-01 12:57:46 +0800 | [diff] [blame] | 5193 | |
Pekka Paalanen | 01388e2 | 2013-04-25 13:57:44 +0300 | [diff] [blame] | 5194 | main_surface = weston_surface_get_main_surface(focus); |
| 5195 | if (get_shell_surface_type(main_surface) == SHELL_SURFACE_NONE) |
Kristian Høgsberg | 0636ac3 | 2012-06-27 10:22:15 -0400 | [diff] [blame] | 5196 | return; |
Kristian Høgsberg | 85b2e4b | 2012-06-21 16:49:42 -0400 | [diff] [blame] | 5197 | |
Emilio Pozuelo Monfort | 9e7c759 | 2014-01-30 14:01:10 +0100 | [diff] [blame] | 5198 | activate(shell, focus, seat, true); |
Neil Roberts | a28c693 | 2013-10-03 16:43:04 +0100 | [diff] [blame] | 5199 | } |
| 5200 | |
| 5201 | static void |
Derek Foreman | 8ae2db5 | 2015-07-15 13:00:36 -0500 | [diff] [blame] | 5202 | click_to_activate_binding(struct weston_pointer *pointer, uint32_t time, |
| 5203 | uint32_t button, void *data) |
Neil Roberts | a28c693 | 2013-10-03 16:43:04 +0100 | [diff] [blame] | 5204 | { |
Derek Foreman | 8ae2db5 | 2015-07-15 13:00:36 -0500 | [diff] [blame] | 5205 | if (pointer->grab != &pointer->default_grab) |
Neil Roberts | a28c693 | 2013-10-03 16:43:04 +0100 | [diff] [blame] | 5206 | return; |
Derek Foreman | 8ae2db5 | 2015-07-15 13:00:36 -0500 | [diff] [blame] | 5207 | if (pointer->focus == NULL) |
Kristian Høgsberg | 7c4f6cc | 2014-01-01 16:28:32 -0800 | [diff] [blame] | 5208 | return; |
Neil Roberts | a28c693 | 2013-10-03 16:43:04 +0100 | [diff] [blame] | 5209 | |
Jonas Ådahl | cd0f1ac | 2015-06-26 12:37:56 +0800 | [diff] [blame] | 5210 | activate_binding(pointer->seat, data, pointer->focus); |
Neil Roberts | a28c693 | 2013-10-03 16:43:04 +0100 | [diff] [blame] | 5211 | } |
| 5212 | |
| 5213 | static void |
Derek Foreman | 8ae2db5 | 2015-07-15 13:00:36 -0500 | [diff] [blame] | 5214 | touch_to_activate_binding(struct weston_touch *touch, uint32_t time, |
| 5215 | void *data) |
Neil Roberts | a28c693 | 2013-10-03 16:43:04 +0100 | [diff] [blame] | 5216 | { |
Derek Foreman | 8ae2db5 | 2015-07-15 13:00:36 -0500 | [diff] [blame] | 5217 | if (touch->grab != &touch->default_grab) |
Neil Roberts | a28c693 | 2013-10-03 16:43:04 +0100 | [diff] [blame] | 5218 | return; |
Derek Foreman | 8ae2db5 | 2015-07-15 13:00:36 -0500 | [diff] [blame] | 5219 | if (touch->focus == NULL) |
Kristian Høgsberg | 0ed6750 | 2014-01-02 23:00:11 -0800 | [diff] [blame] | 5220 | return; |
Neil Roberts | a28c693 | 2013-10-03 16:43:04 +0100 | [diff] [blame] | 5221 | |
Jonas Ådahl | cd0f1ac | 2015-06-26 12:37:56 +0800 | [diff] [blame] | 5222 | activate_binding(touch->seat, data, touch->focus); |
Kristian Høgsberg | e1a850e | 2011-12-19 15:18:05 -0500 | [diff] [blame] | 5223 | } |
| 5224 | |
| 5225 | static void |
Neil Roberts | b4a9170 | 2014-04-09 16:33:32 +0100 | [diff] [blame] | 5226 | unfocus_all_seats(struct desktop_shell *shell) |
| 5227 | { |
| 5228 | struct weston_seat *seat, *next; |
| 5229 | |
| 5230 | wl_list_for_each_safe(seat, next, &shell->compositor->seat_list, link) { |
Derek Foreman | 1281a36 | 2015-07-31 16:55:32 -0500 | [diff] [blame] | 5231 | struct weston_keyboard *keyboard = |
| 5232 | weston_seat_get_keyboard(seat); |
| 5233 | |
| 5234 | if (!keyboard) |
Neil Roberts | b4a9170 | 2014-04-09 16:33:32 +0100 | [diff] [blame] | 5235 | continue; |
| 5236 | |
Derek Foreman | 1281a36 | 2015-07-31 16:55:32 -0500 | [diff] [blame] | 5237 | weston_keyboard_set_focus(keyboard, NULL); |
Neil Roberts | b4a9170 | 2014-04-09 16:33:32 +0100 | [diff] [blame] | 5238 | } |
| 5239 | } |
| 5240 | |
| 5241 | static void |
Ander Conselvan de Oliveira | 19d10ef | 2013-02-21 18:35:20 +0200 | [diff] [blame] | 5242 | lock(struct desktop_shell *shell) |
Kristian Høgsberg | 02ec0a5 | 2011-04-23 13:04:11 -0400 | [diff] [blame] | 5243 | { |
Kristian Høgsberg | 4476aaf | 2012-06-25 14:03:13 -0400 | [diff] [blame] | 5244 | struct workspace *ws = get_current_workspace(shell); |
Pekka Paalanen | f0fc70d | 2011-11-15 13:34:54 +0200 | [diff] [blame] | 5245 | |
Tiago Vignatti | 8e53c7f | 2012-02-29 19:53:50 +0200 | [diff] [blame] | 5246 | if (shell->locked) { |
Ander Conselvan de Oliveira | 87524b6 | 2013-02-21 18:35:22 +0200 | [diff] [blame] | 5247 | weston_compositor_sleep(shell->compositor); |
Pekka Paalanen | f0fc70d | 2011-11-15 13:34:54 +0200 | [diff] [blame] | 5248 | return; |
Tiago Vignatti | 8e53c7f | 2012-02-29 19:53:50 +0200 | [diff] [blame] | 5249 | } |
Pekka Paalanen | 9ef3e01 | 2011-11-15 13:34:48 +0200 | [diff] [blame] | 5250 | |
| 5251 | shell->locked = true; |
Pekka Paalanen | f0fc70d | 2011-11-15 13:34:54 +0200 | [diff] [blame] | 5252 | |
Kristian Høgsberg | 3be2ce9 | 2012-02-29 12:42:35 -0500 | [diff] [blame] | 5253 | /* Hide all surfaces by removing the fullscreen, panel and |
| 5254 | * toplevel layers. This way nothing else can show or receive |
| 5255 | * input events while we are locked. */ |
Pekka Paalanen | f0fc70d | 2011-11-15 13:34:54 +0200 | [diff] [blame] | 5256 | |
Kristian Høgsberg | 3be2ce9 | 2012-02-29 12:42:35 -0500 | [diff] [blame] | 5257 | wl_list_remove(&shell->panel_layer.link); |
Kristian Høgsberg | 3be2ce9 | 2012-02-29 12:42:35 -0500 | [diff] [blame] | 5258 | wl_list_remove(&shell->fullscreen_layer.link); |
Philipp Brüschweiler | 711fda8 | 2012-08-09 18:50:43 +0200 | [diff] [blame] | 5259 | if (shell->showing_input_panels) |
| 5260 | wl_list_remove(&shell->input_panel_layer.link); |
Kristian Høgsberg | 4476aaf | 2012-06-25 14:03:13 -0400 | [diff] [blame] | 5261 | wl_list_remove(&ws->layer.link); |
Kristian Høgsberg | 3be2ce9 | 2012-02-29 12:42:35 -0500 | [diff] [blame] | 5262 | wl_list_insert(&shell->compositor->cursor_layer.link, |
| 5263 | &shell->lock_layer.link); |
Pekka Paalanen | f0fc70d | 2011-11-15 13:34:54 +0200 | [diff] [blame] | 5264 | |
Derek Foreman | 004b4a1 | 2015-07-20 16:28:13 -0500 | [diff] [blame] | 5265 | weston_compositor_sleep(shell->compositor); |
| 5266 | |
Neil Roberts | b4a9170 | 2014-04-09 16:33:32 +0100 | [diff] [blame] | 5267 | /* Remove the keyboard focus on all seats. This will be |
| 5268 | * restored to the workspace's saved state via |
| 5269 | * restore_focus_state when the compositor is unlocked */ |
| 5270 | unfocus_all_seats(shell); |
| 5271 | |
Pekka Paalanen | f0fc70d | 2011-11-15 13:34:54 +0200 | [diff] [blame] | 5272 | /* TODO: disable bindings that should not work while locked. */ |
| 5273 | |
| 5274 | /* All this must be undone in resume_desktop(). */ |
Pekka Paalanen | 9ef3e01 | 2011-11-15 13:34:48 +0200 | [diff] [blame] | 5275 | } |
| 5276 | |
| 5277 | static void |
Ander Conselvan de Oliveira | 19d10ef | 2013-02-21 18:35:20 +0200 | [diff] [blame] | 5278 | unlock(struct desktop_shell *shell) |
Pekka Paalanen | 9ef3e01 | 2011-11-15 13:34:48 +0200 | [diff] [blame] | 5279 | { |
Pekka Paalanen | d81c216 | 2011-11-16 13:47:34 +0200 | [diff] [blame] | 5280 | if (!shell->locked || shell->lock_surface) { |
Ander Conselvan de Oliveira | 87524b6 | 2013-02-21 18:35:22 +0200 | [diff] [blame] | 5281 | shell_fade(shell, FADE_IN); |
Pekka Paalanen | 9ef3e01 | 2011-11-15 13:34:48 +0200 | [diff] [blame] | 5282 | return; |
| 5283 | } |
| 5284 | |
| 5285 | /* If desktop-shell client has gone away, unlock immediately. */ |
| 5286 | if (!shell->child.desktop_shell) { |
Pekka Paalanen | f0fc70d | 2011-11-15 13:34:54 +0200 | [diff] [blame] | 5287 | resume_desktop(shell); |
Pekka Paalanen | 9ef3e01 | 2011-11-15 13:34:48 +0200 | [diff] [blame] | 5288 | return; |
| 5289 | } |
| 5290 | |
| 5291 | if (shell->prepare_event_sent) |
| 5292 | return; |
| 5293 | |
Kristian Høgsberg | 0b5cd0c | 2012-03-04 21:57:37 -0500 | [diff] [blame] | 5294 | desktop_shell_send_prepare_lock_surface(shell->child.desktop_shell); |
Pekka Paalanen | 9ef3e01 | 2011-11-15 13:34:48 +0200 | [diff] [blame] | 5295 | shell->prepare_event_sent = true; |
Kristian Høgsberg | 02ec0a5 | 2011-04-23 13:04:11 -0400 | [diff] [blame] | 5296 | } |
| 5297 | |
| 5298 | static void |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 5299 | shell_fade_done(struct weston_view_animation *animation, void *data) |
Ander Conselvan de Oliveira | 19d10ef | 2013-02-21 18:35:20 +0200 | [diff] [blame] | 5300 | { |
| 5301 | struct desktop_shell *shell = data; |
| 5302 | |
| 5303 | shell->fade.animation = NULL; |
| 5304 | |
| 5305 | switch (shell->fade.type) { |
| 5306 | case FADE_IN: |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 5307 | weston_surface_destroy(shell->fade.view->surface); |
| 5308 | shell->fade.view = NULL; |
Ander Conselvan de Oliveira | 19d10ef | 2013-02-21 18:35:20 +0200 | [diff] [blame] | 5309 | break; |
| 5310 | case FADE_OUT: |
Ander Conselvan de Oliveira | 19d10ef | 2013-02-21 18:35:20 +0200 | [diff] [blame] | 5311 | lock(shell); |
| 5312 | break; |
Philip Withnall | 4a86a0a | 2013-11-25 18:01:32 +0000 | [diff] [blame] | 5313 | default: |
| 5314 | break; |
Ander Conselvan de Oliveira | 19d10ef | 2013-02-21 18:35:20 +0200 | [diff] [blame] | 5315 | } |
| 5316 | } |
| 5317 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 5318 | static struct weston_view * |
Pekka Paalanen | 79346ab | 2013-05-22 18:03:09 +0300 | [diff] [blame] | 5319 | shell_fade_create_surface(struct desktop_shell *shell) |
Ander Conselvan de Oliveira | 19d10ef | 2013-02-21 18:35:20 +0200 | [diff] [blame] | 5320 | { |
| 5321 | struct weston_compositor *compositor = shell->compositor; |
| 5322 | struct weston_surface *surface; |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 5323 | struct weston_view *view; |
Pekka Paalanen | 79346ab | 2013-05-22 18:03:09 +0300 | [diff] [blame] | 5324 | |
| 5325 | surface = weston_surface_create(compositor); |
| 5326 | if (!surface) |
| 5327 | return NULL; |
| 5328 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 5329 | view = weston_view_create(surface); |
| 5330 | if (!view) { |
| 5331 | weston_surface_destroy(surface); |
| 5332 | return NULL; |
| 5333 | } |
| 5334 | |
Jason Ekstrand | 5c11a33 | 2013-12-04 20:32:03 -0600 | [diff] [blame] | 5335 | weston_surface_set_size(surface, 8192, 8192); |
Jason Ekstrand | 918f2dd | 2013-12-02 21:01:53 -0600 | [diff] [blame] | 5336 | weston_view_set_position(view, 0, 0); |
Pekka Paalanen | 79346ab | 2013-05-22 18:03:09 +0300 | [diff] [blame] | 5337 | 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] | 5338 | weston_layer_entry_insert(&compositor->fade_layer.view_list, |
| 5339 | &view->layer_link); |
Pekka Paalanen | 79346ab | 2013-05-22 18:03:09 +0300 | [diff] [blame] | 5340 | pixman_region32_init(&surface->input); |
| 5341 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 5342 | return view; |
Pekka Paalanen | 79346ab | 2013-05-22 18:03:09 +0300 | [diff] [blame] | 5343 | } |
| 5344 | |
| 5345 | static void |
| 5346 | shell_fade(struct desktop_shell *shell, enum fade_type type) |
| 5347 | { |
Ander Conselvan de Oliveira | 19d10ef | 2013-02-21 18:35:20 +0200 | [diff] [blame] | 5348 | float tint; |
| 5349 | |
| 5350 | switch (type) { |
| 5351 | case FADE_IN: |
| 5352 | tint = 0.0; |
| 5353 | break; |
| 5354 | case FADE_OUT: |
| 5355 | tint = 1.0; |
| 5356 | break; |
| 5357 | default: |
| 5358 | weston_log("shell: invalid fade type\n"); |
| 5359 | return; |
| 5360 | } |
| 5361 | |
| 5362 | shell->fade.type = type; |
| 5363 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 5364 | if (shell->fade.view == NULL) { |
| 5365 | shell->fade.view = shell_fade_create_surface(shell); |
| 5366 | if (!shell->fade.view) |
Ander Conselvan de Oliveira | 19d10ef | 2013-02-21 18:35:20 +0200 | [diff] [blame] | 5367 | return; |
| 5368 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 5369 | shell->fade.view->alpha = 1.0 - tint; |
| 5370 | weston_view_update_transform(shell->fade.view); |
Ander Conselvan de Oliveira | 19d10ef | 2013-02-21 18:35:20 +0200 | [diff] [blame] | 5371 | } |
| 5372 | |
Kristian Høgsberg | 87d3b61 | 2014-01-19 21:48:10 -0800 | [diff] [blame] | 5373 | if (shell->fade.view->output == NULL) { |
| 5374 | /* If the black view gets a NULL output, we lost the |
| 5375 | * last output and we'll just cancel the fade. This |
| 5376 | * happens when you close the last window under the |
| 5377 | * X11 or Wayland backends. */ |
| 5378 | shell->locked = false; |
| 5379 | weston_surface_destroy(shell->fade.view->surface); |
| 5380 | shell->fade.view = NULL; |
| 5381 | } else if (shell->fade.animation) { |
Kristian Høgsberg | 5281fb1 | 2013-06-17 10:10:28 -0400 | [diff] [blame] | 5382 | weston_fade_update(shell->fade.animation, tint); |
Kristian Høgsberg | 87d3b61 | 2014-01-19 21:48:10 -0800 | [diff] [blame] | 5383 | } else { |
Ander Conselvan de Oliveira | 19d10ef | 2013-02-21 18:35:20 +0200 | [diff] [blame] | 5384 | shell->fade.animation = |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 5385 | weston_fade_run(shell->fade.view, |
Kristian Høgsberg | 5281fb1 | 2013-06-17 10:10:28 -0400 | [diff] [blame] | 5386 | 1.0 - tint, tint, 300.0, |
Ander Conselvan de Oliveira | 19d10ef | 2013-02-21 18:35:20 +0200 | [diff] [blame] | 5387 | shell_fade_done, shell); |
Kristian Høgsberg | 87d3b61 | 2014-01-19 21:48:10 -0800 | [diff] [blame] | 5388 | } |
Ander Conselvan de Oliveira | 19d10ef | 2013-02-21 18:35:20 +0200 | [diff] [blame] | 5389 | } |
| 5390 | |
| 5391 | static void |
Pekka Paalanen | 79346ab | 2013-05-22 18:03:09 +0300 | [diff] [blame] | 5392 | do_shell_fade_startup(void *data) |
| 5393 | { |
| 5394 | struct desktop_shell *shell = data; |
| 5395 | |
Pekka Paalanen | 23ed5f2 | 2015-05-26 11:54:52 +0300 | [diff] [blame] | 5396 | if (shell->startup_animation_type == ANIMATION_FADE) { |
Kristian Høgsberg | 724c8d9 | 2013-10-16 11:38:24 -0700 | [diff] [blame] | 5397 | shell_fade(shell, FADE_IN); |
Pekka Paalanen | 23ed5f2 | 2015-05-26 11:54:52 +0300 | [diff] [blame] | 5398 | } else { |
| 5399 | weston_log("desktop shell: " |
| 5400 | "unexpected fade-in animation type %d\n", |
| 5401 | shell->startup_animation_type); |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 5402 | weston_surface_destroy(shell->fade.view->surface); |
| 5403 | shell->fade.view = NULL; |
Kristian Høgsberg | 724c8d9 | 2013-10-16 11:38:24 -0700 | [diff] [blame] | 5404 | } |
Pekka Paalanen | 79346ab | 2013-05-22 18:03:09 +0300 | [diff] [blame] | 5405 | } |
| 5406 | |
| 5407 | static void |
| 5408 | shell_fade_startup(struct desktop_shell *shell) |
| 5409 | { |
| 5410 | struct wl_event_loop *loop; |
| 5411 | |
| 5412 | if (!shell->fade.startup_timer) |
| 5413 | return; |
| 5414 | |
| 5415 | wl_event_source_remove(shell->fade.startup_timer); |
| 5416 | shell->fade.startup_timer = NULL; |
| 5417 | |
| 5418 | loop = wl_display_get_event_loop(shell->compositor->wl_display); |
| 5419 | wl_event_loop_add_idle(loop, do_shell_fade_startup, shell); |
| 5420 | } |
| 5421 | |
| 5422 | static int |
| 5423 | fade_startup_timeout(void *data) |
| 5424 | { |
| 5425 | struct desktop_shell *shell = data; |
| 5426 | |
| 5427 | shell_fade_startup(shell); |
| 5428 | return 0; |
| 5429 | } |
| 5430 | |
| 5431 | static void |
| 5432 | shell_fade_init(struct desktop_shell *shell) |
| 5433 | { |
| 5434 | /* Make compositor output all black, and wait for the desktop-shell |
| 5435 | * client to signal it is ready, then fade in. The timer triggers a |
| 5436 | * fade-in, in case the desktop-shell client takes too long. |
| 5437 | */ |
| 5438 | |
| 5439 | struct wl_event_loop *loop; |
| 5440 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 5441 | if (shell->fade.view != NULL) { |
Pekka Paalanen | 79346ab | 2013-05-22 18:03:09 +0300 | [diff] [blame] | 5442 | weston_log("%s: warning: fade surface already exists\n", |
| 5443 | __func__); |
| 5444 | return; |
| 5445 | } |
| 5446 | |
Pekka Paalanen | 23ed5f2 | 2015-05-26 11:54:52 +0300 | [diff] [blame] | 5447 | if (shell->startup_animation_type == ANIMATION_NONE) |
| 5448 | return; |
| 5449 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 5450 | shell->fade.view = shell_fade_create_surface(shell); |
| 5451 | if (!shell->fade.view) |
Pekka Paalanen | 79346ab | 2013-05-22 18:03:09 +0300 | [diff] [blame] | 5452 | return; |
| 5453 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 5454 | weston_view_update_transform(shell->fade.view); |
| 5455 | weston_surface_damage(shell->fade.view->surface); |
Pekka Paalanen | 79346ab | 2013-05-22 18:03:09 +0300 | [diff] [blame] | 5456 | |
| 5457 | loop = wl_display_get_event_loop(shell->compositor->wl_display); |
| 5458 | shell->fade.startup_timer = |
| 5459 | wl_event_loop_add_timer(loop, fade_startup_timeout, shell); |
| 5460 | wl_event_source_timer_update(shell->fade.startup_timer, 15000); |
| 5461 | } |
| 5462 | |
| 5463 | static void |
Ander Conselvan de Oliveira | a457563 | 2013-02-21 18:35:23 +0200 | [diff] [blame] | 5464 | idle_handler(struct wl_listener *listener, void *data) |
Ander Conselvan de Oliveira | 19d10ef | 2013-02-21 18:35:20 +0200 | [diff] [blame] | 5465 | { |
| 5466 | struct desktop_shell *shell = |
Ander Conselvan de Oliveira | a457563 | 2013-02-21 18:35:23 +0200 | [diff] [blame] | 5467 | container_of(listener, struct desktop_shell, idle_listener); |
Kristian Høgsberg | 27d5fa8 | 2014-01-17 16:22:50 -0800 | [diff] [blame] | 5468 | struct weston_seat *seat; |
| 5469 | |
Jonny Lamb | 76cf1fe | 2014-08-20 11:27:10 +0200 | [diff] [blame] | 5470 | wl_list_for_each(seat, &shell->compositor->seat_list, link) { |
Derek Foreman | 1281a36 | 2015-07-31 16:55:32 -0500 | [diff] [blame] | 5471 | struct weston_touch *touch = weston_seat_get_touch(seat); |
| 5472 | struct weston_pointer *pointer = weston_seat_get_pointer(seat); |
| 5473 | |
| 5474 | if (pointer) |
| 5475 | popup_grab_end(pointer); |
| 5476 | if (touch) |
| 5477 | touch_popup_grab_end(touch); |
Jonny Lamb | 76cf1fe | 2014-08-20 11:27:10 +0200 | [diff] [blame] | 5478 | } |
Ander Conselvan de Oliveira | 19d10ef | 2013-02-21 18:35:20 +0200 | [diff] [blame] | 5479 | |
| 5480 | shell_fade(shell, FADE_OUT); |
| 5481 | /* lock() is called from shell_fade_done() */ |
| 5482 | } |
| 5483 | |
| 5484 | static void |
Ander Conselvan de Oliveira | a457563 | 2013-02-21 18:35:23 +0200 | [diff] [blame] | 5485 | wake_handler(struct wl_listener *listener, void *data) |
Ander Conselvan de Oliveira | 19d10ef | 2013-02-21 18:35:20 +0200 | [diff] [blame] | 5486 | { |
| 5487 | struct desktop_shell *shell = |
Ander Conselvan de Oliveira | a457563 | 2013-02-21 18:35:23 +0200 | [diff] [blame] | 5488 | container_of(listener, struct desktop_shell, wake_listener); |
Ander Conselvan de Oliveira | 19d10ef | 2013-02-21 18:35:20 +0200 | [diff] [blame] | 5489 | |
Ander Conselvan de Oliveira | 19d10ef | 2013-02-21 18:35:20 +0200 | [diff] [blame] | 5490 | unlock(shell); |
| 5491 | } |
| 5492 | |
| 5493 | static void |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 5494 | center_on_output(struct weston_view *view, struct weston_output *output) |
Pekka Paalanen | 77346a6 | 2011-11-30 16:26:35 +0200 | [diff] [blame] | 5495 | { |
Giulio Camuffo | b836664 | 2013-04-25 13:57:46 +0300 | [diff] [blame] | 5496 | int32_t surf_x, surf_y, width, height; |
Ander Conselvan de Oliveira | 012b4c7 | 2012-11-27 17:03:42 +0200 | [diff] [blame] | 5497 | float x, y; |
Pekka Paalanen | 77346a6 | 2011-11-30 16:26:35 +0200 | [diff] [blame] | 5498 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 5499 | surface_subsurfaces_boundingbox(view->surface, &surf_x, &surf_y, &width, &height); |
Giulio Camuffo | b836664 | 2013-04-25 13:57:46 +0300 | [diff] [blame] | 5500 | |
| 5501 | x = output->x + (output->width - width) / 2 - surf_x / 2; |
| 5502 | y = output->y + (output->height - height) / 2 - surf_y / 2; |
Ander Conselvan de Oliveira | 012b4c7 | 2012-11-27 17:03:42 +0200 | [diff] [blame] | 5503 | |
Jason Ekstrand | 918f2dd | 2013-12-02 21:01:53 -0600 | [diff] [blame] | 5504 | weston_view_set_position(view, x, y); |
Pekka Paalanen | 77346a6 | 2011-11-30 16:26:35 +0200 | [diff] [blame] | 5505 | } |
| 5506 | |
| 5507 | static void |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 5508 | weston_view_set_initial_position(struct weston_view *view, |
| 5509 | struct desktop_shell *shell) |
Rob Bradford | ac63e5b | 2012-08-13 14:07:52 +0100 | [diff] [blame] | 5510 | { |
| 5511 | struct weston_compositor *compositor = shell->compositor; |
| 5512 | int ix = 0, iy = 0; |
Jonny Lamb | d73c694 | 2014-08-20 15:53:20 +0200 | [diff] [blame] | 5513 | int32_t range_x, range_y; |
Derek Foreman | f814c5d | 2015-04-15 12:23:54 -0500 | [diff] [blame] | 5514 | int32_t x, y; |
Rob Bradford | ac63e5b | 2012-08-13 14:07:52 +0100 | [diff] [blame] | 5515 | struct weston_output *output, *target_output = NULL; |
| 5516 | struct weston_seat *seat; |
Jonny Lamb | d73c694 | 2014-08-20 15:53:20 +0200 | [diff] [blame] | 5517 | pixman_rectangle32_t area; |
Rob Bradford | ac63e5b | 2012-08-13 14:07:52 +0100 | [diff] [blame] | 5518 | |
| 5519 | /* As a heuristic place the new window on the same output as the |
| 5520 | * pointer. Falling back to the output containing 0, 0. |
| 5521 | * |
| 5522 | * TODO: Do something clever for touch too? |
| 5523 | */ |
| 5524 | wl_list_for_each(seat, &compositor->seat_list, link) { |
Derek Foreman | 1281a36 | 2015-07-31 16:55:32 -0500 | [diff] [blame] | 5525 | struct weston_pointer *pointer = weston_seat_get_pointer(seat); |
| 5526 | |
| 5527 | if (pointer) { |
| 5528 | ix = wl_fixed_to_int(pointer->x); |
| 5529 | iy = wl_fixed_to_int(pointer->y); |
Rob Bradford | ac63e5b | 2012-08-13 14:07:52 +0100 | [diff] [blame] | 5530 | break; |
| 5531 | } |
| 5532 | } |
| 5533 | |
| 5534 | wl_list_for_each(output, &compositor->output_list, link) { |
| 5535 | if (pixman_region32_contains_point(&output->region, ix, iy, NULL)) { |
| 5536 | target_output = output; |
| 5537 | break; |
| 5538 | } |
| 5539 | } |
| 5540 | |
| 5541 | if (!target_output) { |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 5542 | weston_view_set_position(view, 10 + random() % 400, |
| 5543 | 10 + random() % 400); |
Rob Bradford | ac63e5b | 2012-08-13 14:07:52 +0100 | [diff] [blame] | 5544 | return; |
| 5545 | } |
| 5546 | |
| 5547 | /* Valid range within output where the surface will still be onscreen. |
| 5548 | * If this is negative it means that the surface is bigger than |
| 5549 | * output. |
| 5550 | */ |
Jonny Lamb | d73c694 | 2014-08-20 15:53:20 +0200 | [diff] [blame] | 5551 | get_output_work_area(shell, target_output, &area); |
| 5552 | |
Derek Foreman | f814c5d | 2015-04-15 12:23:54 -0500 | [diff] [blame] | 5553 | x = area.x; |
| 5554 | y = area.y; |
Jonny Lamb | d73c694 | 2014-08-20 15:53:20 +0200 | [diff] [blame] | 5555 | range_x = area.width - view->surface->width; |
| 5556 | range_y = area.height - view->surface->height; |
Rob Bradford | ac63e5b | 2012-08-13 14:07:52 +0100 | [diff] [blame] | 5557 | |
Rob Bradford | 4cb88c7 | 2012-08-13 15:18:44 +0100 | [diff] [blame] | 5558 | if (range_x > 0) |
Derek Foreman | f814c5d | 2015-04-15 12:23:54 -0500 | [diff] [blame] | 5559 | x += random() % range_x; |
Rob Bradford | 4cb88c7 | 2012-08-13 15:18:44 +0100 | [diff] [blame] | 5560 | |
| 5561 | if (range_y > 0) |
Derek Foreman | f814c5d | 2015-04-15 12:23:54 -0500 | [diff] [blame] | 5562 | y += random() % range_y; |
Rob Bradford | ac63e5b | 2012-08-13 14:07:52 +0100 | [diff] [blame] | 5563 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 5564 | weston_view_set_position(view, x, y); |
Rob Bradford | ac63e5b | 2012-08-13 14:07:52 +0100 | [diff] [blame] | 5565 | } |
| 5566 | |
| 5567 | static void |
Jonny Lamb | d73c694 | 2014-08-20 15:53:20 +0200 | [diff] [blame] | 5568 | set_maximized_position(struct desktop_shell *shell, |
| 5569 | struct shell_surface *shsurf) |
| 5570 | { |
| 5571 | int32_t surf_x, surf_y; |
| 5572 | pixman_rectangle32_t area; |
| 5573 | |
Jonny Lamb | d73c694 | 2014-08-20 15:53:20 +0200 | [diff] [blame] | 5574 | get_output_work_area(shell, shsurf->output, &area); |
Giulio Camuffo | 7a8d67d | 2015-01-09 20:10:45 +0200 | [diff] [blame] | 5575 | if (shsurf->has_set_geometry) { |
| 5576 | surf_x = shsurf->geometry.x; |
| 5577 | surf_y = shsurf->geometry.y; |
| 5578 | } else { |
| 5579 | surface_subsurfaces_boundingbox(shsurf->surface, |
| 5580 | &surf_x, &surf_y, NULL, NULL); |
| 5581 | } |
Jonny Lamb | d73c694 | 2014-08-20 15:53:20 +0200 | [diff] [blame] | 5582 | |
| 5583 | weston_view_set_position(shsurf->view, |
Marek Chalupa | 6ce7899 | 2015-10-09 18:17:07 +0200 | [diff] [blame] | 5584 | area.x - surf_x, |
| 5585 | area.y - surf_y); |
Jonny Lamb | d73c694 | 2014-08-20 15:53:20 +0200 | [diff] [blame] | 5586 | } |
| 5587 | |
| 5588 | static void |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 5589 | map(struct desktop_shell *shell, struct shell_surface *shsurf, |
Jason Ekstrand | 918f2dd | 2013-12-02 21:01:53 -0600 | [diff] [blame] | 5590 | int32_t sx, int32_t sy) |
Kristian Høgsberg | 02ec0a5 | 2011-04-23 13:04:11 -0400 | [diff] [blame] | 5591 | { |
Kristian Høgsberg | 8334bc1 | 2012-01-03 10:29:47 -0500 | [diff] [blame] | 5592 | struct weston_compositor *compositor = shell->compositor; |
Daniel Stone | b210468 | 2012-05-30 16:31:56 +0100 | [diff] [blame] | 5593 | struct weston_seat *seat; |
Pekka Paalanen | 57da4a8 | 2011-11-23 16:42:16 +0200 | [diff] [blame] | 5594 | |
Pekka Paalanen | 77346a6 | 2011-11-30 16:26:35 +0200 | [diff] [blame] | 5595 | /* initial positioning, see also configure() */ |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 5596 | switch (shsurf->type) { |
Rafael Antognolli | ed207b4 | 2013-12-03 15:35:43 -0200 | [diff] [blame] | 5597 | case SHELL_SURFACE_TOPLEVEL: |
Rafael Antognolli | 03b1659 | 2013-12-03 15:35:42 -0200 | [diff] [blame] | 5598 | if (shsurf->state.fullscreen) { |
| 5599 | center_on_output(shsurf->view, shsurf->fullscreen_output); |
| 5600 | shell_map_fullscreen(shsurf); |
| 5601 | } else if (shsurf->state.maximized) { |
Jonny Lamb | d73c694 | 2014-08-20 15:53:20 +0200 | [diff] [blame] | 5602 | set_maximized_position(shell, shsurf); |
Rafael Antognolli | ed207b4 | 2013-12-03 15:35:43 -0200 | [diff] [blame] | 5603 | } else if (!shsurf->state.relative) { |
Rafael Antognolli | 03b1659 | 2013-12-03 15:35:42 -0200 | [diff] [blame] | 5604 | weston_view_set_initial_position(shsurf->view, shell); |
| 5605 | } |
Juan Zhao | 96879df | 2012-02-07 08:45:41 +0800 | [diff] [blame] | 5606 | break; |
Tiago Vignatti | 0f99701 | 2012-02-10 16:17:23 +0200 | [diff] [blame] | 5607 | case SHELL_SURFACE_POPUP: |
Jasper St. Pierre | da6ecd0 | 2015-02-27 18:35:45 +0800 | [diff] [blame] | 5608 | if (shell_map_popup(shsurf) != 0) |
| 5609 | return; |
Rob Bradford | db99938 | 2012-12-06 12:07:48 +0000 | [diff] [blame] | 5610 | break; |
Ander Conselvan de Oliveira | e9e0515 | 2012-02-15 17:02:56 +0200 | [diff] [blame] | 5611 | case SHELL_SURFACE_NONE: |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 5612 | weston_view_set_position(shsurf->view, |
| 5613 | shsurf->view->geometry.x + sx, |
| 5614 | shsurf->view->geometry.y + sy); |
Tiago Vignatti | 0f99701 | 2012-02-10 16:17:23 +0200 | [diff] [blame] | 5615 | break; |
Philip Withnall | 0f640e2 | 2013-11-25 18:01:31 +0000 | [diff] [blame] | 5616 | case SHELL_SURFACE_XWAYLAND: |
Pekka Paalanen | 77346a6 | 2011-11-30 16:26:35 +0200 | [diff] [blame] | 5617 | default: |
| 5618 | ; |
| 5619 | } |
Kristian Høgsberg | 7584062 | 2011-09-06 13:48:16 -0400 | [diff] [blame] | 5620 | |
Philip Withnall | e1d75ae | 2013-11-25 18:01:41 +0000 | [diff] [blame] | 5621 | /* Surface stacking order, see also activate(). */ |
| 5622 | shell_surface_update_layer(shsurf); |
Pekka Paalanen | f0fc70d | 2011-11-15 13:34:54 +0200 | [diff] [blame] | 5623 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 5624 | if (shsurf->type != SHELL_SURFACE_NONE) { |
| 5625 | weston_view_update_transform(shsurf->view); |
Rafael Antognolli | 03b1659 | 2013-12-03 15:35:42 -0200 | [diff] [blame] | 5626 | if (shsurf->state.maximized) { |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 5627 | shsurf->surface->output = shsurf->output; |
| 5628 | shsurf->view->output = shsurf->output; |
| 5629 | } |
Ander Conselvan de Oliveira | de56c31 | 2012-03-05 15:39:23 +0200 | [diff] [blame] | 5630 | } |
Kristian Høgsberg | 2f88a40 | 2011-12-04 15:32:59 -0500 | [diff] [blame] | 5631 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 5632 | switch (shsurf->type) { |
Tiago Vignatti | fb2adba | 2013-06-12 15:43:21 -0300 | [diff] [blame] | 5633 | /* XXX: xwayland's using the same fields for transient type */ |
| 5634 | case SHELL_SURFACE_XWAYLAND: |
Tiago Vignatti | 99aeb1e | 2012-05-23 22:06:26 +0300 | [diff] [blame] | 5635 | if (shsurf->transient.flags == |
| 5636 | WL_SHELL_SURFACE_TRANSIENT_INACTIVE) |
| 5637 | break; |
| 5638 | case SHELL_SURFACE_TOPLEVEL: |
Rafael Antognolli | ed207b4 | 2013-12-03 15:35:43 -0200 | [diff] [blame] | 5639 | if (shsurf->state.relative && |
| 5640 | shsurf->transient.flags == WL_SHELL_SURFACE_TRANSIENT_INACTIVE) |
| 5641 | break; |
Rafael Antognolli | ba5d2d7 | 2013-12-04 17:49:55 -0200 | [diff] [blame] | 5642 | if (shell->locked) |
Rafael Antognolli | ed207b4 | 2013-12-03 15:35:43 -0200 | [diff] [blame] | 5643 | break; |
| 5644 | wl_list_for_each(seat, &compositor->seat_list, link) |
Emilio Pozuelo Monfort | 9e7c759 | 2014-01-30 14:01:10 +0100 | [diff] [blame] | 5645 | activate(shell, shsurf->surface, seat, true); |
Juan Zhao | 7bb92f0 | 2011-12-15 11:31:51 -0500 | [diff] [blame] | 5646 | break; |
Philip Withnall | 0f640e2 | 2013-11-25 18:01:31 +0000 | [diff] [blame] | 5647 | case SHELL_SURFACE_POPUP: |
| 5648 | case SHELL_SURFACE_NONE: |
Juan Zhao | 7bb92f0 | 2011-12-15 11:31:51 -0500 | [diff] [blame] | 5649 | default: |
| 5650 | break; |
| 5651 | } |
| 5652 | |
Rafael Antognolli | 03b1659 | 2013-12-03 15:35:42 -0200 | [diff] [blame] | 5653 | if (shsurf->type == SHELL_SURFACE_TOPLEVEL && |
| 5654 | !shsurf->state.maximized && !shsurf->state.fullscreen) |
Juan Zhao | e10d279 | 2012-04-25 19:09:52 +0800 | [diff] [blame] | 5655 | { |
| 5656 | switch (shell->win_animation_type) { |
| 5657 | case ANIMATION_FADE: |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 5658 | 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] | 5659 | break; |
| 5660 | case ANIMATION_ZOOM: |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 5661 | weston_zoom_run(shsurf->view, 0.5, 1.0, NULL, NULL); |
Juan Zhao | e10d279 | 2012-04-25 19:09:52 +0800 | [diff] [blame] | 5662 | break; |
Philip Withnall | 4a86a0a | 2013-11-25 18:01:32 +0000 | [diff] [blame] | 5663 | case ANIMATION_NONE: |
Juan Zhao | e10d279 | 2012-04-25 19:09:52 +0800 | [diff] [blame] | 5664 | default: |
| 5665 | break; |
| 5666 | } |
| 5667 | } |
Kristian Høgsberg | 32e24cc | 2011-11-09 12:07:35 -0500 | [diff] [blame] | 5668 | } |
| 5669 | |
| 5670 | static void |
Tiago Vignatti | be14326 | 2012-04-16 17:31:41 +0300 | [diff] [blame] | 5671 | configure(struct desktop_shell *shell, struct weston_surface *surface, |
Jason Ekstrand | 918f2dd | 2013-12-02 21:01:53 -0600 | [diff] [blame] | 5672 | float x, float y) |
Kristian Høgsberg | 32e24cc | 2011-11-09 12:07:35 -0500 | [diff] [blame] | 5673 | { |
Pekka Paalanen | 77346a6 | 2011-11-30 16:26:35 +0200 | [diff] [blame] | 5674 | struct shell_surface *shsurf; |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 5675 | struct weston_view *view; |
Kristian Høgsberg | 32e24cc | 2011-11-09 12:07:35 -0500 | [diff] [blame] | 5676 | |
Pekka Paalanen | 77346a6 | 2011-11-30 16:26:35 +0200 | [diff] [blame] | 5677 | shsurf = get_shell_surface(surface); |
Pekka Paalanen | 77346a6 | 2011-11-30 16:26:35 +0200 | [diff] [blame] | 5678 | |
U. Artie Eoff | cf5737a | 2014-01-17 10:08:25 -0800 | [diff] [blame] | 5679 | assert(shsurf); |
| 5680 | |
Rafael Antognolli | 03b1659 | 2013-12-03 15:35:42 -0200 | [diff] [blame] | 5681 | if (shsurf->state.fullscreen) |
Alex Wu | 4539b08 | 2012-03-01 12:57:46 +0800 | [diff] [blame] | 5682 | shell_configure_fullscreen(shsurf); |
Rafael Antognolli | 03b1659 | 2013-12-03 15:35:42 -0200 | [diff] [blame] | 5683 | else if (shsurf->state.maximized) { |
Jonny Lamb | d73c694 | 2014-08-20 15:53:20 +0200 | [diff] [blame] | 5684 | set_maximized_position(shell, shsurf); |
Rafael Antognolli | 03b1659 | 2013-12-03 15:35:42 -0200 | [diff] [blame] | 5685 | } else { |
Jason Ekstrand | 918f2dd | 2013-12-02 21:01:53 -0600 | [diff] [blame] | 5686 | weston_view_set_position(shsurf->view, x, y); |
Kristian Høgsberg | 7a5c979 | 2011-06-18 06:12:54 -0400 | [diff] [blame] | 5687 | } |
Kristian Høgsberg | 32e24cc | 2011-11-09 12:07:35 -0500 | [diff] [blame] | 5688 | |
Alex Wu | 4539b08 | 2012-03-01 12:57:46 +0800 | [diff] [blame] | 5689 | /* XXX: would a fullscreen surface need the same handling? */ |
Kristian Høgsberg | 6a8b553 | 2012-02-16 23:43:59 -0500 | [diff] [blame] | 5690 | if (surface->output) { |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 5691 | wl_list_for_each(view, &surface->views, surface_link) |
| 5692 | weston_view_update_transform(view); |
Pekka Paalanen | 77346a6 | 2011-11-30 16:26:35 +0200 | [diff] [blame] | 5693 | |
Rafael Antognolli | 03b1659 | 2013-12-03 15:35:42 -0200 | [diff] [blame] | 5694 | if (shsurf->state.maximized) |
Juan Zhao | 96879df | 2012-02-07 08:45:41 +0800 | [diff] [blame] | 5695 | surface->output = shsurf->output; |
Pekka Paalanen | 77346a6 | 2011-11-30 16:26:35 +0200 | [diff] [blame] | 5696 | } |
Kristian Høgsberg | 0793756 | 2011-04-12 17:25:42 -0400 | [diff] [blame] | 5697 | } |
| 5698 | |
Ander Conselvan de Oliveira | 093bfa3 | 2012-03-27 17:36:41 +0300 | [diff] [blame] | 5699 | static void |
Jason Ekstrand | 918f2dd | 2013-12-02 21:01:53 -0600 | [diff] [blame] | 5700 | 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] | 5701 | { |
Ander Conselvan de Oliveira | 7fb9f95 | 2012-03-27 17:36:42 +0300 | [diff] [blame] | 5702 | struct shell_surface *shsurf = get_shell_surface(es); |
U. Artie Eoff | cf5737a | 2014-01-17 10:08:25 -0800 | [diff] [blame] | 5703 | struct desktop_shell *shell; |
Tiago Vignatti | 70e5c9c | 2012-05-07 15:23:07 +0300 | [diff] [blame] | 5704 | int type_changed = 0; |
Ander Conselvan de Oliveira | 093bfa3 | 2012-03-27 17:36:41 +0300 | [diff] [blame] | 5705 | |
U. Artie Eoff | cf5737a | 2014-01-17 10:08:25 -0800 | [diff] [blame] | 5706 | assert(shsurf); |
| 5707 | |
| 5708 | shell = shsurf->shell; |
| 5709 | |
Kristian Høgsberg | 8eb0f4f | 2013-06-17 10:33:14 -0400 | [diff] [blame] | 5710 | if (!weston_surface_is_mapped(es) && |
| 5711 | !wl_list_empty(&shsurf->popup.grab_link)) { |
Giulio Camuffo | 5085a75 | 2013-03-25 21:42:45 +0100 | [diff] [blame] | 5712 | remove_popup_grab(shsurf); |
| 5713 | } |
| 5714 | |
Jason Ekstrand | 918f2dd | 2013-12-02 21:01:53 -0600 | [diff] [blame] | 5715 | if (es->width == 0) |
Giulio Camuffo | 184df50 | 2013-02-21 11:29:21 +0100 | [diff] [blame] | 5716 | return; |
| 5717 | |
Jasper St. Pierre | ccf48fb | 2014-05-02 10:21:38 -0400 | [diff] [blame] | 5718 | if (shsurf->has_next_geometry) { |
| 5719 | shsurf->geometry = shsurf->next_geometry; |
| 5720 | shsurf->has_next_geometry = false; |
| 5721 | shsurf->has_set_geometry = true; |
| 5722 | } else if (!shsurf->has_set_geometry) { |
| 5723 | surface_subsurfaces_boundingbox(shsurf->surface, |
| 5724 | &shsurf->geometry.x, |
| 5725 | &shsurf->geometry.y, |
| 5726 | &shsurf->geometry.width, |
| 5727 | &shsurf->geometry.height); |
Jasper St. Pierre | 851799e | 2014-05-02 10:14:07 -0400 | [diff] [blame] | 5728 | } |
| 5729 | |
Kristian Høgsberg | c8f8dd8 | 2013-12-05 23:20:33 -0800 | [diff] [blame] | 5730 | if (shsurf->state_changed) { |
Kristian Høgsberg | 7f366e7 | 2012-04-27 17:20:01 -0400 | [diff] [blame] | 5731 | set_surface_type(shsurf); |
Kristian Høgsberg | f7e23d5 | 2012-04-27 17:51:59 -0400 | [diff] [blame] | 5732 | type_changed = 1; |
| 5733 | } |
Kristian Høgsberg | 7f366e7 | 2012-04-27 17:20:01 -0400 | [diff] [blame] | 5734 | |
Ander Conselvan de Oliveira | 093bfa3 | 2012-03-27 17:36:41 +0300 | [diff] [blame] | 5735 | if (!weston_surface_is_mapped(es)) { |
Jason Ekstrand | 918f2dd | 2013-12-02 21:01:53 -0600 | [diff] [blame] | 5736 | map(shell, shsurf, sx, sy); |
Kristian Høgsberg | f7e23d5 | 2012-04-27 17:51:59 -0400 | [diff] [blame] | 5737 | } else if (type_changed || sx != 0 || sy != 0 || |
Jason Ekstrand | 918f2dd | 2013-12-02 21:01:53 -0600 | [diff] [blame] | 5738 | shsurf->last_width != es->width || |
| 5739 | shsurf->last_height != es->height) { |
John Kåre Alsaker | 490d02a | 2012-09-30 02:57:21 +0200 | [diff] [blame] | 5740 | float from_x, from_y; |
| 5741 | float to_x, to_y; |
Ander Conselvan de Oliveira | 093bfa3 | 2012-03-27 17:36:41 +0300 | [diff] [blame] | 5742 | |
Kristian Høgsberg | 44cd196 | 2014-02-05 21:36:04 -0800 | [diff] [blame] | 5743 | if (shsurf->resize_edges) { |
| 5744 | sx = 0; |
| 5745 | sy = 0; |
| 5746 | } |
| 5747 | |
| 5748 | if (shsurf->resize_edges & WL_SHELL_SURFACE_RESIZE_LEFT) |
| 5749 | sx = shsurf->last_width - es->width; |
| 5750 | if (shsurf->resize_edges & WL_SHELL_SURFACE_RESIZE_TOP) |
| 5751 | sy = shsurf->last_height - es->height; |
| 5752 | |
| 5753 | shsurf->last_width = es->width; |
| 5754 | shsurf->last_height = es->height; |
| 5755 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 5756 | weston_view_to_global_float(shsurf->view, 0, 0, &from_x, &from_y); |
| 5757 | 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] | 5758 | configure(shell, es, |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 5759 | shsurf->view->geometry.x + to_x - from_x, |
Jason Ekstrand | 918f2dd | 2013-12-02 21:01:53 -0600 | [diff] [blame] | 5760 | shsurf->view->geometry.y + to_y - from_y); |
Ander Conselvan de Oliveira | 093bfa3 | 2012-03-27 17:36:41 +0300 | [diff] [blame] | 5761 | } |
| 5762 | } |
| 5763 | |
Pekka Paalanen | 2e62e4a | 2014-08-28 11:41:26 +0300 | [diff] [blame] | 5764 | static bool |
| 5765 | check_desktop_shell_crash_too_early(struct desktop_shell *shell) |
| 5766 | { |
| 5767 | struct timespec now; |
| 5768 | |
| 5769 | if (clock_gettime(CLOCK_MONOTONIC, &now) < 0) |
| 5770 | return false; |
| 5771 | |
| 5772 | /* |
| 5773 | * If the shell helper client dies before the session has been |
| 5774 | * up for roughly 30 seconds, better just make Weston shut down, |
| 5775 | * because the user likely has no way to interact with the desktop |
| 5776 | * anyway. |
| 5777 | */ |
| 5778 | if (now.tv_sec - shell->startup_time.tv_sec < 30) { |
| 5779 | weston_log("Error: %s apparently cannot run at all.\n", |
| 5780 | shell->client); |
| 5781 | weston_log_continue(STAMP_SPACE "Quitting..."); |
| 5782 | wl_display_terminate(shell->compositor->wl_display); |
| 5783 | |
| 5784 | return true; |
| 5785 | } |
| 5786 | |
| 5787 | return false; |
| 5788 | } |
| 5789 | |
Tiago Vignatti | b7dbbd6 | 2012-09-25 17:57:01 +0300 | [diff] [blame] | 5790 | static void launch_desktop_shell_process(void *data); |
Pekka Paalanen | 4d733ee | 2012-01-17 14:36:27 +0200 | [diff] [blame] | 5791 | |
Kristian Høgsberg | 97d44aa | 2011-08-26 17:21:20 -0400 | [diff] [blame] | 5792 | static void |
Pekka Paalanen | 826dc14 | 2014-08-27 12:11:53 +0300 | [diff] [blame] | 5793 | respawn_desktop_shell_process(struct desktop_shell *shell) |
Pekka Paalanen | 6cd281a | 2011-11-03 14:11:32 +0200 | [diff] [blame] | 5794 | { |
Pekka Paalanen | 4d733ee | 2012-01-17 14:36:27 +0200 | [diff] [blame] | 5795 | uint32_t time; |
Pekka Paalanen | 4d733ee | 2012-01-17 14:36:27 +0200 | [diff] [blame] | 5796 | |
| 5797 | /* if desktop-shell dies more than 5 times in 30 seconds, give up */ |
| 5798 | time = weston_compositor_get_time(); |
Kristian Høgsberg | f03a616 | 2012-01-17 11:07:42 -0500 | [diff] [blame] | 5799 | if (time - shell->child.deathstamp > 30000) { |
Pekka Paalanen | 4d733ee | 2012-01-17 14:36:27 +0200 | [diff] [blame] | 5800 | shell->child.deathstamp = time; |
| 5801 | shell->child.deathcount = 0; |
| 5802 | } |
| 5803 | |
| 5804 | shell->child.deathcount++; |
| 5805 | if (shell->child.deathcount > 5) { |
Pekka Paalanen | 826dc14 | 2014-08-27 12:11:53 +0300 | [diff] [blame] | 5806 | weston_log("%s disconnected, giving up.\n", shell->client); |
Pekka Paalanen | 4d733ee | 2012-01-17 14:36:27 +0200 | [diff] [blame] | 5807 | return; |
| 5808 | } |
| 5809 | |
Pekka Paalanen | 826dc14 | 2014-08-27 12:11:53 +0300 | [diff] [blame] | 5810 | weston_log("%s disconnected, respawning...\n", shell->client); |
Pekka Paalanen | 4d733ee | 2012-01-17 14:36:27 +0200 | [diff] [blame] | 5811 | launch_desktop_shell_process(shell); |
Pekka Paalanen | 6cd281a | 2011-11-03 14:11:32 +0200 | [diff] [blame] | 5812 | } |
| 5813 | |
Tiago Vignatti | b7dbbd6 | 2012-09-25 17:57:01 +0300 | [diff] [blame] | 5814 | static void |
Ander Conselvan de Oliveira | 312ea4c | 2013-12-20 21:07:01 +0200 | [diff] [blame] | 5815 | desktop_shell_client_destroy(struct wl_listener *listener, void *data) |
| 5816 | { |
| 5817 | struct desktop_shell *shell; |
| 5818 | |
| 5819 | shell = container_of(listener, struct desktop_shell, |
| 5820 | child.client_destroy_listener); |
| 5821 | |
Pekka Paalanen | 826dc14 | 2014-08-27 12:11:53 +0300 | [diff] [blame] | 5822 | wl_list_remove(&shell->child.client_destroy_listener.link); |
Ander Conselvan de Oliveira | 312ea4c | 2013-12-20 21:07:01 +0200 | [diff] [blame] | 5823 | shell->child.client = NULL; |
Pekka Paalanen | 826dc14 | 2014-08-27 12:11:53 +0300 | [diff] [blame] | 5824 | /* |
| 5825 | * unbind_desktop_shell() will reset shell->child.desktop_shell |
| 5826 | * before the respawned process has a chance to create a new |
| 5827 | * desktop_shell object, because we are being called from the |
| 5828 | * wl_client destructor which destroys all wl_resources before |
| 5829 | * returning. |
| 5830 | */ |
| 5831 | |
Pekka Paalanen | 2e62e4a | 2014-08-28 11:41:26 +0300 | [diff] [blame] | 5832 | if (!check_desktop_shell_crash_too_early(shell)) |
| 5833 | respawn_desktop_shell_process(shell); |
| 5834 | |
Pekka Paalanen | 826dc14 | 2014-08-27 12:11:53 +0300 | [diff] [blame] | 5835 | shell_fade_startup(shell); |
Ander Conselvan de Oliveira | 312ea4c | 2013-12-20 21:07:01 +0200 | [diff] [blame] | 5836 | } |
| 5837 | |
| 5838 | static void |
Tiago Vignatti | b7dbbd6 | 2012-09-25 17:57:01 +0300 | [diff] [blame] | 5839 | launch_desktop_shell_process(void *data) |
Pekka Paalanen | 6cd281a | 2011-11-03 14:11:32 +0200 | [diff] [blame] | 5840 | { |
Tiago Vignatti | b7dbbd6 | 2012-09-25 17:57:01 +0300 | [diff] [blame] | 5841 | struct desktop_shell *shell = data; |
Pekka Paalanen | 6cd281a | 2011-11-03 14:11:32 +0200 | [diff] [blame] | 5842 | |
Pekka Paalanen | 826dc14 | 2014-08-27 12:11:53 +0300 | [diff] [blame] | 5843 | shell->child.client = weston_client_start(shell->compositor, |
| 5844 | shell->client); |
Pekka Paalanen | 409ef0a | 2011-12-02 15:30:21 +0200 | [diff] [blame] | 5845 | |
Arnaud Vrac | 4263119 | 2014-08-25 20:56:46 +0200 | [diff] [blame] | 5846 | if (!shell->child.client) { |
Emilio Pozuelo Monfort | 46ce798 | 2013-11-20 13:22:29 +0100 | [diff] [blame] | 5847 | weston_log("not able to start %s\n", shell->client); |
Arnaud Vrac | 4263119 | 2014-08-25 20:56:46 +0200 | [diff] [blame] | 5848 | return; |
| 5849 | } |
Ander Conselvan de Oliveira | 312ea4c | 2013-12-20 21:07:01 +0200 | [diff] [blame] | 5850 | |
| 5851 | shell->child.client_destroy_listener.notify = |
| 5852 | desktop_shell_client_destroy; |
| 5853 | wl_client_add_destroy_listener(shell->child.client, |
| 5854 | &shell->child.client_destroy_listener); |
Pekka Paalanen | 6cd281a | 2011-11-03 14:11:32 +0200 | [diff] [blame] | 5855 | } |
| 5856 | |
| 5857 | static void |
Kristian Høgsberg | 2bff94e | 2014-02-11 12:22:51 -0800 | [diff] [blame] | 5858 | handle_shell_client_destroy(struct wl_listener *listener, void *data) |
| 5859 | { |
| 5860 | struct shell_client *sc = |
| 5861 | container_of(listener, struct shell_client, destroy_listener); |
| 5862 | |
| 5863 | if (sc->ping_timer) |
| 5864 | wl_event_source_remove(sc->ping_timer); |
Derek Foreman | e42d754 | 2015-05-29 10:46:44 -0500 | [diff] [blame] | 5865 | |
| 5866 | /* Since we're about to free shell_client, we remove it from the |
| 5867 | * head of the surface list so we don't use that freed list node |
| 5868 | * during surface clean up later on. |
| 5869 | */ |
| 5870 | wl_list_remove(&sc->surface_list); |
| 5871 | |
Kristian Høgsberg | 2bff94e | 2014-02-11 12:22:51 -0800 | [diff] [blame] | 5872 | free(sc); |
| 5873 | } |
| 5874 | |
Kristian Høgsberg | dd62aba | 2014-02-12 09:56:19 -0800 | [diff] [blame] | 5875 | static struct shell_client * |
| 5876 | shell_client_create(struct wl_client *client, struct desktop_shell *shell, |
| 5877 | const struct wl_interface *interface, uint32_t id) |
Rafael Antognolli | e2a3455 | 2013-12-03 15:35:45 -0200 | [diff] [blame] | 5878 | { |
Kristian Høgsberg | 2bff94e | 2014-02-11 12:22:51 -0800 | [diff] [blame] | 5879 | struct shell_client *sc; |
Rafael Antognolli | e2a3455 | 2013-12-03 15:35:45 -0200 | [diff] [blame] | 5880 | |
Kristian Høgsberg | 2bff94e | 2014-02-11 12:22:51 -0800 | [diff] [blame] | 5881 | sc = zalloc(sizeof *sc); |
| 5882 | if (sc == NULL) { |
| 5883 | wl_client_post_no_memory(client); |
Kristian Høgsberg | dd62aba | 2014-02-12 09:56:19 -0800 | [diff] [blame] | 5884 | return NULL; |
Kristian Høgsberg | 2bff94e | 2014-02-11 12:22:51 -0800 | [diff] [blame] | 5885 | } |
Kristian Høgsberg | dd62aba | 2014-02-12 09:56:19 -0800 | [diff] [blame] | 5886 | |
| 5887 | sc->resource = wl_resource_create(client, interface, 1, id); |
Kristian Høgsberg | 2bff94e | 2014-02-11 12:22:51 -0800 | [diff] [blame] | 5888 | if (sc->resource == NULL) { |
| 5889 | free(sc); |
| 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 | } |
| 5893 | |
| 5894 | sc->client = client; |
| 5895 | sc->shell = shell; |
| 5896 | sc->destroy_listener.notify = handle_shell_client_destroy; |
| 5897 | wl_client_add_destroy_listener(client, &sc->destroy_listener); |
Jonas Ådahl | 49d77d2 | 2015-03-18 16:20:51 +0800 | [diff] [blame] | 5898 | wl_list_init(&sc->surface_list); |
Kristian Høgsberg | 2bff94e | 2014-02-11 12:22:51 -0800 | [diff] [blame] | 5899 | |
Kristian Høgsberg | dd62aba | 2014-02-12 09:56:19 -0800 | [diff] [blame] | 5900 | return sc; |
| 5901 | } |
| 5902 | |
| 5903 | static void |
| 5904 | bind_shell(struct wl_client *client, void *data, uint32_t version, uint32_t id) |
| 5905 | { |
| 5906 | struct desktop_shell *shell = data; |
| 5907 | struct shell_client *sc; |
| 5908 | |
| 5909 | sc = shell_client_create(client, shell, &wl_shell_interface, id); |
| 5910 | if (sc) |
| 5911 | wl_resource_set_implementation(sc->resource, |
| 5912 | &shell_implementation, |
Jason Ekstrand | 9e9512f | 2014-04-16 21:12:10 -0500 | [diff] [blame] | 5913 | sc, NULL); |
Kristian Høgsberg | dd62aba | 2014-02-12 09:56:19 -0800 | [diff] [blame] | 5914 | } |
| 5915 | |
| 5916 | static void |
| 5917 | bind_xdg_shell(struct wl_client *client, void *data, uint32_t version, uint32_t id) |
| 5918 | { |
| 5919 | struct desktop_shell *shell = data; |
| 5920 | struct shell_client *sc; |
| 5921 | |
| 5922 | sc = shell_client_create(client, shell, &xdg_shell_interface, id); |
| 5923 | if (sc) |
| 5924 | wl_resource_set_dispatcher(sc->resource, |
| 5925 | xdg_shell_unversioned_dispatch, |
| 5926 | NULL, sc, NULL); |
Rafael Antognolli | e2a3455 | 2013-12-03 15:35:45 -0200 | [diff] [blame] | 5927 | } |
| 5928 | |
| 5929 | static void |
Pekka Paalanen | 9ef3e01 | 2011-11-15 13:34:48 +0200 | [diff] [blame] | 5930 | unbind_desktop_shell(struct wl_resource *resource) |
| 5931 | { |
Jason Ekstrand | 651f00e | 2013-06-14 10:07:54 -0500 | [diff] [blame] | 5932 | struct desktop_shell *shell = wl_resource_get_user_data(resource); |
Kristian Høgsberg | 1ec0c31 | 2011-11-15 16:39:55 -0500 | [diff] [blame] | 5933 | |
| 5934 | if (shell->locked) |
| 5935 | resume_desktop(shell); |
| 5936 | |
Pekka Paalanen | 9ef3e01 | 2011-11-15 13:34:48 +0200 | [diff] [blame] | 5937 | shell->child.desktop_shell = NULL; |
| 5938 | shell->prepare_event_sent = false; |
Pekka Paalanen | 9ef3e01 | 2011-11-15 13:34:48 +0200 | [diff] [blame] | 5939 | } |
| 5940 | |
| 5941 | static void |
Kristian Høgsberg | 7584062 | 2011-09-06 13:48:16 -0400 | [diff] [blame] | 5942 | bind_desktop_shell(struct wl_client *client, |
| 5943 | void *data, uint32_t version, uint32_t id) |
| 5944 | { |
Tiago Vignatti | be14326 | 2012-04-16 17:31:41 +0300 | [diff] [blame] | 5945 | struct desktop_shell *shell = data; |
Pekka Paalanen | bbe6052 | 2011-11-03 14:11:33 +0200 | [diff] [blame] | 5946 | struct wl_resource *resource; |
Kristian Høgsberg | 7584062 | 2011-09-06 13:48:16 -0400 | [diff] [blame] | 5947 | |
Jason Ekstrand | a85118c | 2013-06-27 20:17:02 -0500 | [diff] [blame] | 5948 | resource = wl_resource_create(client, &desktop_shell_interface, |
Jonny Lamb | 765760d | 2014-08-20 15:53:19 +0200 | [diff] [blame] | 5949 | MIN(version, 3), id); |
Pekka Paalanen | bbe6052 | 2011-11-03 14:11:33 +0200 | [diff] [blame] | 5950 | |
Pekka Paalanen | 9ef3e01 | 2011-11-15 13:34:48 +0200 | [diff] [blame] | 5951 | if (client == shell->child.client) { |
Jason Ekstrand | a85118c | 2013-06-27 20:17:02 -0500 | [diff] [blame] | 5952 | wl_resource_set_implementation(resource, |
| 5953 | &desktop_shell_implementation, |
| 5954 | shell, unbind_desktop_shell); |
Pekka Paalanen | 9ef3e01 | 2011-11-15 13:34:48 +0200 | [diff] [blame] | 5955 | shell->child.desktop_shell = resource; |
Pekka Paalanen | 79346ab | 2013-05-22 18:03:09 +0300 | [diff] [blame] | 5956 | |
| 5957 | if (version < 2) |
| 5958 | shell_fade_startup(shell); |
| 5959 | |
Pekka Paalanen | bbe6052 | 2011-11-03 14:11:33 +0200 | [diff] [blame] | 5960 | return; |
Pekka Paalanen | 9ef3e01 | 2011-11-15 13:34:48 +0200 | [diff] [blame] | 5961 | } |
Pekka Paalanen | bbe6052 | 2011-11-03 14:11:33 +0200 | [diff] [blame] | 5962 | |
| 5963 | wl_resource_post_error(resource, WL_DISPLAY_ERROR_INVALID_OBJECT, |
| 5964 | "permission to bind desktop_shell denied"); |
Kristian Høgsberg | 7584062 | 2011-09-06 13:48:16 -0400 | [diff] [blame] | 5965 | } |
| 5966 | |
Kristian Høgsberg | 0704539 | 2012-02-19 18:52:44 -0500 | [diff] [blame] | 5967 | struct switcher { |
Tiago Vignatti | be14326 | 2012-04-16 17:31:41 +0300 | [diff] [blame] | 5968 | struct desktop_shell *shell; |
Kristian Høgsberg | 0704539 | 2012-02-19 18:52:44 -0500 | [diff] [blame] | 5969 | struct weston_surface *current; |
| 5970 | struct wl_listener listener; |
Kristian Høgsberg | 29139d4 | 2013-04-18 15:25:39 -0400 | [diff] [blame] | 5971 | struct weston_keyboard_grab grab; |
Manuel Bachmann | c1ae2e8 | 2014-02-26 15:53:11 +0100 | [diff] [blame] | 5972 | struct wl_array minimized_array; |
Kristian Høgsberg | 0704539 | 2012-02-19 18:52:44 -0500 | [diff] [blame] | 5973 | }; |
| 5974 | |
| 5975 | static void |
| 5976 | switcher_next(struct switcher *switcher) |
| 5977 | { |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 5978 | struct weston_view *view; |
Kristian Høgsberg | 0704539 | 2012-02-19 18:52:44 -0500 | [diff] [blame] | 5979 | struct weston_surface *first = NULL, *prev = NULL, *next = NULL; |
Kristian Høgsberg | 32e5686 | 2012-04-02 22:18:58 -0400 | [diff] [blame] | 5980 | struct shell_surface *shsurf; |
Kristian Høgsberg | b0d8e77 | 2012-06-18 16:34:58 -0400 | [diff] [blame] | 5981 | struct workspace *ws = get_current_workspace(switcher->shell); |
Kristian Høgsberg | 0704539 | 2012-02-19 18:52:44 -0500 | [diff] [blame] | 5982 | |
Manuel Bachmann | c1ae2e8 | 2014-02-26 15:53:11 +0100 | [diff] [blame] | 5983 | /* temporary re-display minimized surfaces */ |
| 5984 | struct weston_view *tmp; |
| 5985 | struct weston_view **minimized; |
Giulio Camuffo | 412e6a5 | 2014-07-09 22:12:56 +0300 | [diff] [blame] | 5986 | wl_list_for_each_safe(view, tmp, &switcher->shell->minimized_layer.view_list.link, layer_link.link) { |
| 5987 | weston_layer_entry_remove(&view->layer_link); |
| 5988 | weston_layer_entry_insert(&ws->layer.view_list, &view->layer_link); |
Manuel Bachmann | c1ae2e8 | 2014-02-26 15:53:11 +0100 | [diff] [blame] | 5989 | minimized = wl_array_add(&switcher->minimized_array, sizeof *minimized); |
| 5990 | *minimized = view; |
| 5991 | } |
| 5992 | |
Giulio Camuffo | 412e6a5 | 2014-07-09 22:12:56 +0300 | [diff] [blame] | 5993 | 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] | 5994 | shsurf = get_shell_surface(view->surface); |
Rafael Antognolli | 5031cbe | 2013-12-05 19:01:21 -0200 | [diff] [blame] | 5995 | if (shsurf && |
| 5996 | shsurf->type == SHELL_SURFACE_TOPLEVEL && |
| 5997 | shsurf->parent == NULL) { |
Kristian Høgsberg | 0704539 | 2012-02-19 18:52:44 -0500 | [diff] [blame] | 5998 | if (first == NULL) |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 5999 | first = view->surface; |
Kristian Høgsberg | 0704539 | 2012-02-19 18:52:44 -0500 | [diff] [blame] | 6000 | if (prev == switcher->current) |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 6001 | next = view->surface; |
| 6002 | prev = view->surface; |
| 6003 | view->alpha = 0.25; |
| 6004 | weston_view_geometry_dirty(view); |
| 6005 | weston_surface_damage(view->surface); |
Kristian Høgsberg | 0704539 | 2012-02-19 18:52:44 -0500 | [diff] [blame] | 6006 | } |
Alex Wu | 1659daa | 2012-04-01 20:13:09 +0800 | [diff] [blame] | 6007 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 6008 | if (is_black_surface(view->surface, NULL)) { |
| 6009 | view->alpha = 0.25; |
| 6010 | weston_view_geometry_dirty(view); |
| 6011 | weston_surface_damage(view->surface); |
Alex Wu | 1659daa | 2012-04-01 20:13:09 +0800 | [diff] [blame] | 6012 | } |
Kristian Høgsberg | 0704539 | 2012-02-19 18:52:44 -0500 | [diff] [blame] | 6013 | } |
| 6014 | |
| 6015 | if (next == NULL) |
| 6016 | next = first; |
| 6017 | |
Alex Wu | 07b2606 | 2012-03-12 16:06:01 +0800 | [diff] [blame] | 6018 | if (next == NULL) |
| 6019 | return; |
| 6020 | |
Kristian Høgsberg | 0704539 | 2012-02-19 18:52:44 -0500 | [diff] [blame] | 6021 | wl_list_remove(&switcher->listener.link); |
Jason Ekstrand | 26ed73c | 2013-06-06 22:34:41 -0500 | [diff] [blame] | 6022 | wl_signal_add(&next->destroy_signal, &switcher->listener); |
Kristian Høgsberg | 0704539 | 2012-02-19 18:52:44 -0500 | [diff] [blame] | 6023 | |
| 6024 | switcher->current = next; |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 6025 | wl_list_for_each(view, &next->views, surface_link) |
| 6026 | view->alpha = 1.0; |
Alex Wu | 1659daa | 2012-04-01 20:13:09 +0800 | [diff] [blame] | 6027 | |
Kristian Høgsberg | 32e5686 | 2012-04-02 22:18:58 -0400 | [diff] [blame] | 6028 | shsurf = get_shell_surface(switcher->current); |
Rafael Antognolli | 03b1659 | 2013-12-03 15:35:42 -0200 | [diff] [blame] | 6029 | if (shsurf && shsurf->state.fullscreen) |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 6030 | shsurf->fullscreen.black_view->alpha = 1.0; |
Kristian Høgsberg | 0704539 | 2012-02-19 18:52:44 -0500 | [diff] [blame] | 6031 | } |
| 6032 | |
| 6033 | static void |
Kristian Høgsberg | 27e3052 | 2012-04-11 23:18:23 -0400 | [diff] [blame] | 6034 | switcher_handle_surface_destroy(struct wl_listener *listener, void *data) |
Kristian Høgsberg | 0704539 | 2012-02-19 18:52:44 -0500 | [diff] [blame] | 6035 | { |
| 6036 | struct switcher *switcher = |
| 6037 | container_of(listener, struct switcher, listener); |
| 6038 | |
| 6039 | switcher_next(switcher); |
| 6040 | } |
| 6041 | |
| 6042 | static void |
Daniel Stone | 351eb61 | 2012-05-31 15:27:47 -0400 | [diff] [blame] | 6043 | switcher_destroy(struct switcher *switcher) |
Kristian Høgsberg | 0704539 | 2012-02-19 18:52:44 -0500 | [diff] [blame] | 6044 | { |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 6045 | struct weston_view *view; |
Kristian Høgsberg | 29139d4 | 2013-04-18 15:25:39 -0400 | [diff] [blame] | 6046 | struct weston_keyboard *keyboard = switcher->grab.keyboard; |
Kristian Høgsberg | b0d8e77 | 2012-06-18 16:34:58 -0400 | [diff] [blame] | 6047 | struct workspace *ws = get_current_workspace(switcher->shell); |
Kristian Høgsberg | 0704539 | 2012-02-19 18:52:44 -0500 | [diff] [blame] | 6048 | |
Giulio Camuffo | 412e6a5 | 2014-07-09 22:12:56 +0300 | [diff] [blame] | 6049 | 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] | 6050 | if (is_focus_view(view)) |
| 6051 | continue; |
| 6052 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 6053 | view->alpha = 1.0; |
| 6054 | weston_surface_damage(view->surface); |
Kristian Høgsberg | 0704539 | 2012-02-19 18:52:44 -0500 | [diff] [blame] | 6055 | } |
| 6056 | |
Alex Wu | 07b2606 | 2012-03-12 16:06:01 +0800 | [diff] [blame] | 6057 | if (switcher->current) |
Daniel Stone | 37816df | 2012-05-16 18:45:18 +0100 | [diff] [blame] | 6058 | activate(switcher->shell, switcher->current, |
Derek Foreman | 8aeeac8 | 2015-01-30 13:24:36 -0600 | [diff] [blame] | 6059 | keyboard->seat, true); |
Kristian Høgsberg | 0704539 | 2012-02-19 18:52:44 -0500 | [diff] [blame] | 6060 | wl_list_remove(&switcher->listener.link); |
Kristian Høgsberg | 29139d4 | 2013-04-18 15:25:39 -0400 | [diff] [blame] | 6061 | weston_keyboard_end_grab(keyboard); |
| 6062 | if (keyboard->input_method_resource) |
| 6063 | keyboard->grab = &keyboard->input_method_grab; |
Manuel Bachmann | c1ae2e8 | 2014-02-26 15:53:11 +0100 | [diff] [blame] | 6064 | |
| 6065 | /* re-hide surfaces that were temporary shown during the switch */ |
| 6066 | struct weston_view **minimized; |
| 6067 | wl_array_for_each(minimized, &switcher->minimized_array) { |
| 6068 | /* with the exception of the current selected */ |
| 6069 | if ((*minimized)->surface != switcher->current) { |
Giulio Camuffo | 412e6a5 | 2014-07-09 22:12:56 +0300 | [diff] [blame] | 6070 | weston_layer_entry_remove(&(*minimized)->layer_link); |
| 6071 | 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] | 6072 | weston_view_damage_below(*minimized); |
| 6073 | } |
| 6074 | } |
| 6075 | wl_array_release(&switcher->minimized_array); |
| 6076 | |
Kristian Høgsberg | 0704539 | 2012-02-19 18:52:44 -0500 | [diff] [blame] | 6077 | free(switcher); |
| 6078 | } |
| 6079 | |
| 6080 | static void |
Kristian Høgsberg | 29139d4 | 2013-04-18 15:25:39 -0400 | [diff] [blame] | 6081 | switcher_key(struct weston_keyboard_grab *grab, |
Daniel Stone | c9785ea | 2012-05-30 16:31:52 +0100 | [diff] [blame] | 6082 | uint32_t time, uint32_t key, uint32_t state_w) |
Kristian Høgsberg | 0704539 | 2012-02-19 18:52:44 -0500 | [diff] [blame] | 6083 | { |
| 6084 | struct switcher *switcher = container_of(grab, struct switcher, grab); |
Daniel Stone | c9785ea | 2012-05-30 16:31:52 +0100 | [diff] [blame] | 6085 | enum wl_keyboard_key_state state = state_w; |
Daniel Stone | 351eb61 | 2012-05-31 15:27:47 -0400 | [diff] [blame] | 6086 | |
Daniel Stone | c9785ea | 2012-05-30 16:31:52 +0100 | [diff] [blame] | 6087 | if (key == KEY_TAB && state == WL_KEYBOARD_KEY_STATE_PRESSED) |
Daniel Stone | 351eb61 | 2012-05-31 15:27:47 -0400 | [diff] [blame] | 6088 | switcher_next(switcher); |
| 6089 | } |
| 6090 | |
| 6091 | static void |
Kristian Høgsberg | 29139d4 | 2013-04-18 15:25:39 -0400 | [diff] [blame] | 6092 | switcher_modifier(struct weston_keyboard_grab *grab, uint32_t serial, |
Daniel Stone | 351eb61 | 2012-05-31 15:27:47 -0400 | [diff] [blame] | 6093 | uint32_t mods_depressed, uint32_t mods_latched, |
| 6094 | uint32_t mods_locked, uint32_t group) |
| 6095 | { |
| 6096 | struct switcher *switcher = container_of(grab, struct switcher, grab); |
Derek Foreman | 8aeeac8 | 2015-01-30 13:24:36 -0600 | [diff] [blame] | 6097 | struct weston_seat *seat = grab->keyboard->seat; |
Kristian Høgsberg | 0704539 | 2012-02-19 18:52:44 -0500 | [diff] [blame] | 6098 | |
Daniel Stone | 351eb61 | 2012-05-31 15:27:47 -0400 | [diff] [blame] | 6099 | if ((seat->modifier_state & switcher->shell->binding_modifier) == 0) |
| 6100 | switcher_destroy(switcher); |
Kristian Høgsberg | b71302e | 2012-05-10 12:28:35 -0400 | [diff] [blame] | 6101 | } |
Kristian Høgsberg | 0704539 | 2012-02-19 18:52:44 -0500 | [diff] [blame] | 6102 | |
Jonas Ådahl | 1ea343e | 2013-10-25 23:18:05 +0200 | [diff] [blame] | 6103 | static void |
| 6104 | switcher_cancel(struct weston_keyboard_grab *grab) |
| 6105 | { |
| 6106 | struct switcher *switcher = container_of(grab, struct switcher, grab); |
| 6107 | |
| 6108 | switcher_destroy(switcher); |
| 6109 | } |
| 6110 | |
Kristian Høgsberg | 29139d4 | 2013-04-18 15:25:39 -0400 | [diff] [blame] | 6111 | static const struct weston_keyboard_grab_interface switcher_grab = { |
Daniel Stone | 351eb61 | 2012-05-31 15:27:47 -0400 | [diff] [blame] | 6112 | switcher_key, |
| 6113 | switcher_modifier, |
Jonas Ådahl | 1ea343e | 2013-10-25 23:18:05 +0200 | [diff] [blame] | 6114 | switcher_cancel, |
Kristian Høgsberg | 0704539 | 2012-02-19 18:52:44 -0500 | [diff] [blame] | 6115 | }; |
| 6116 | |
| 6117 | static void |
Derek Foreman | 8ae2db5 | 2015-07-15 13:00:36 -0500 | [diff] [blame] | 6118 | switcher_binding(struct weston_keyboard *keyboard, uint32_t time, |
| 6119 | uint32_t key, void *data) |
Kristian Høgsberg | 0704539 | 2012-02-19 18:52:44 -0500 | [diff] [blame] | 6120 | { |
Tiago Vignatti | be14326 | 2012-04-16 17:31:41 +0300 | [diff] [blame] | 6121 | struct desktop_shell *shell = data; |
Kristian Høgsberg | 0704539 | 2012-02-19 18:52:44 -0500 | [diff] [blame] | 6122 | struct switcher *switcher; |
| 6123 | |
| 6124 | switcher = malloc(sizeof *switcher); |
Kristian Høgsberg | 02e79dc | 2012-04-12 09:55:26 -0400 | [diff] [blame] | 6125 | switcher->shell = shell; |
Kristian Høgsberg | 0704539 | 2012-02-19 18:52:44 -0500 | [diff] [blame] | 6126 | switcher->current = NULL; |
Kristian Høgsberg | 27e3052 | 2012-04-11 23:18:23 -0400 | [diff] [blame] | 6127 | switcher->listener.notify = switcher_handle_surface_destroy; |
Kristian Høgsberg | 0704539 | 2012-02-19 18:52:44 -0500 | [diff] [blame] | 6128 | wl_list_init(&switcher->listener.link); |
Manuel Bachmann | c1ae2e8 | 2014-02-26 15:53:11 +0100 | [diff] [blame] | 6129 | wl_array_init(&switcher->minimized_array); |
Kristian Høgsberg | 0704539 | 2012-02-19 18:52:44 -0500 | [diff] [blame] | 6130 | |
Alexander Larsson | f82b6ca | 2013-05-28 16:23:39 +0200 | [diff] [blame] | 6131 | restore_all_output_modes(shell->compositor); |
Mario Kleiner | 9f4d655 | 2015-06-21 21:25:08 +0200 | [diff] [blame] | 6132 | lower_fullscreen_layer(switcher->shell, NULL); |
Kristian Høgsberg | 0704539 | 2012-02-19 18:52:44 -0500 | [diff] [blame] | 6133 | switcher->grab.interface = &switcher_grab; |
Derek Foreman | 8ae2db5 | 2015-07-15 13:00:36 -0500 | [diff] [blame] | 6134 | weston_keyboard_start_grab(keyboard, &switcher->grab); |
| 6135 | weston_keyboard_set_focus(keyboard, NULL); |
Kristian Høgsberg | 0704539 | 2012-02-19 18:52:44 -0500 | [diff] [blame] | 6136 | switcher_next(switcher); |
| 6137 | } |
| 6138 | |
Pekka Paalanen | 3c64723 | 2011-12-22 13:43:43 +0200 | [diff] [blame] | 6139 | static void |
Derek Foreman | 8ae2db5 | 2015-07-15 13:00:36 -0500 | [diff] [blame] | 6140 | backlight_binding(struct weston_keyboard *keyboard, uint32_t time, |
| 6141 | uint32_t key, void *data) |
Tiago Vignatti | 8e53c7f | 2012-02-29 19:53:50 +0200 | [diff] [blame] | 6142 | { |
| 6143 | struct weston_compositor *compositor = data; |
| 6144 | struct weston_output *output; |
Tiago Vignatti | 5ab91ad | 2012-03-12 19:40:09 -0300 | [diff] [blame] | 6145 | long backlight_new = 0; |
Tiago Vignatti | 8e53c7f | 2012-02-29 19:53:50 +0200 | [diff] [blame] | 6146 | |
| 6147 | /* TODO: we're limiting to simple use cases, where we assume just |
| 6148 | * control on the primary display. We'd have to extend later if we |
| 6149 | * ever get support for setting backlights on random desktop LCD |
| 6150 | * panels though */ |
| 6151 | output = get_default_output(compositor); |
| 6152 | if (!output) |
| 6153 | return; |
| 6154 | |
| 6155 | if (!output->set_backlight) |
| 6156 | return; |
| 6157 | |
Tiago Vignatti | 5ab91ad | 2012-03-12 19:40:09 -0300 | [diff] [blame] | 6158 | if (key == KEY_F9 || key == KEY_BRIGHTNESSDOWN) |
| 6159 | backlight_new = output->backlight_current - 25; |
| 6160 | else if (key == KEY_F10 || key == KEY_BRIGHTNESSUP) |
| 6161 | backlight_new = output->backlight_current + 25; |
Tiago Vignatti | 8e53c7f | 2012-02-29 19:53:50 +0200 | [diff] [blame] | 6162 | |
Tiago Vignatti | 5ab91ad | 2012-03-12 19:40:09 -0300 | [diff] [blame] | 6163 | if (backlight_new < 5) |
| 6164 | backlight_new = 5; |
| 6165 | if (backlight_new > 255) |
| 6166 | backlight_new = 255; |
| 6167 | |
| 6168 | output->backlight_current = backlight_new; |
Tiago Vignatti | 8e53c7f | 2012-02-29 19:53:50 +0200 | [diff] [blame] | 6169 | output->set_backlight(output, output->backlight_current); |
| 6170 | } |
| 6171 | |
Kristian Høgsberg | b41c081 | 2012-03-04 14:53:40 -0500 | [diff] [blame] | 6172 | static void |
Derek Foreman | 8ae2db5 | 2015-07-15 13:00:36 -0500 | [diff] [blame] | 6173 | force_kill_binding(struct weston_keyboard *keyboard, uint32_t time, |
| 6174 | uint32_t key, void *data) |
Kristian Høgsberg | 92a57db | 2012-05-26 13:41:06 -0400 | [diff] [blame] | 6175 | { |
Kristian Høgsberg | fe7aa90 | 2013-05-08 09:54:37 -0400 | [diff] [blame] | 6176 | struct weston_surface *focus_surface; |
Kristian Høgsberg | 92a57db | 2012-05-26 13:41:06 -0400 | [diff] [blame] | 6177 | struct wl_client *client; |
Tiago Vignatti | 1d01b01 | 2012-09-27 17:48:36 +0300 | [diff] [blame] | 6178 | struct desktop_shell *shell = data; |
| 6179 | struct weston_compositor *compositor = shell->compositor; |
Kristian Høgsberg | 92a57db | 2012-05-26 13:41:06 -0400 | [diff] [blame] | 6180 | pid_t pid; |
Kristian Høgsberg | 92a57db | 2012-05-26 13:41:06 -0400 | [diff] [blame] | 6181 | |
Derek Foreman | 8ae2db5 | 2015-07-15 13:00:36 -0500 | [diff] [blame] | 6182 | focus_surface = keyboard->focus; |
Philipp Brüschweiler | 6cef009 | 2012-08-13 21:27:27 +0200 | [diff] [blame] | 6183 | if (!focus_surface) |
| 6184 | return; |
| 6185 | |
Tiago Vignatti | 1d01b01 | 2012-09-27 17:48:36 +0300 | [diff] [blame] | 6186 | wl_signal_emit(&compositor->kill_signal, focus_surface); |
| 6187 | |
Jason Ekstrand | 26ed73c | 2013-06-06 22:34:41 -0500 | [diff] [blame] | 6188 | client = wl_resource_get_client(focus_surface->resource); |
Tiago Vignatti | 920f197 | 2012-09-27 17:48:35 +0300 | [diff] [blame] | 6189 | wl_client_get_credentials(client, &pid, NULL, NULL); |
| 6190 | |
| 6191 | /* Skip clients that we launched ourselves (the credentials of |
| 6192 | * the socketpair is ours) */ |
| 6193 | if (pid == getpid()) |
| 6194 | return; |
Kristian Høgsberg | 92a57db | 2012-05-26 13:41:06 -0400 | [diff] [blame] | 6195 | |
Daniel Stone | 325fc2d | 2012-05-30 16:31:58 +0100 | [diff] [blame] | 6196 | kill(pid, SIGKILL); |
Kristian Høgsberg | 92a57db | 2012-05-26 13:41:06 -0400 | [diff] [blame] | 6197 | } |
| 6198 | |
| 6199 | static void |
Derek Foreman | 8ae2db5 | 2015-07-15 13:00:36 -0500 | [diff] [blame] | 6200 | workspace_up_binding(struct weston_keyboard *keyboard, uint32_t time, |
Jonas Ådahl | e3cddce | 2012-06-13 00:01:22 +0200 | [diff] [blame] | 6201 | uint32_t key, void *data) |
| 6202 | { |
| 6203 | struct desktop_shell *shell = data; |
| 6204 | unsigned int new_index = shell->workspaces.current; |
| 6205 | |
Kristian Høgsberg | ce345b0 | 2012-06-25 21:35:29 -0400 | [diff] [blame] | 6206 | if (shell->locked) |
Kristian Høgsberg | 4476aaf | 2012-06-25 14:03:13 -0400 | [diff] [blame] | 6207 | return; |
Jonas Ådahl | e3cddce | 2012-06-13 00:01:22 +0200 | [diff] [blame] | 6208 | if (new_index != 0) |
| 6209 | new_index--; |
| 6210 | |
| 6211 | change_workspace(shell, new_index); |
| 6212 | } |
| 6213 | |
| 6214 | static void |
Derek Foreman | 8ae2db5 | 2015-07-15 13:00:36 -0500 | [diff] [blame] | 6215 | workspace_down_binding(struct weston_keyboard *keyboard, uint32_t time, |
Jonas Ådahl | e3cddce | 2012-06-13 00:01:22 +0200 | [diff] [blame] | 6216 | uint32_t key, void *data) |
| 6217 | { |
| 6218 | struct desktop_shell *shell = data; |
| 6219 | unsigned int new_index = shell->workspaces.current; |
| 6220 | |
Kristian Høgsberg | ce345b0 | 2012-06-25 21:35:29 -0400 | [diff] [blame] | 6221 | if (shell->locked) |
Kristian Høgsberg | 4476aaf | 2012-06-25 14:03:13 -0400 | [diff] [blame] | 6222 | return; |
Jonas Ådahl | e3cddce | 2012-06-13 00:01:22 +0200 | [diff] [blame] | 6223 | if (new_index < shell->workspaces.num - 1) |
| 6224 | new_index++; |
| 6225 | |
| 6226 | change_workspace(shell, new_index); |
| 6227 | } |
| 6228 | |
| 6229 | static void |
Derek Foreman | 8ae2db5 | 2015-07-15 13:00:36 -0500 | [diff] [blame] | 6230 | workspace_f_binding(struct weston_keyboard *keyboard, uint32_t time, |
Jonas Ådahl | e3cddce | 2012-06-13 00:01:22 +0200 | [diff] [blame] | 6231 | uint32_t key, void *data) |
| 6232 | { |
| 6233 | struct desktop_shell *shell = data; |
| 6234 | unsigned int new_index; |
| 6235 | |
Kristian Høgsberg | ce345b0 | 2012-06-25 21:35:29 -0400 | [diff] [blame] | 6236 | if (shell->locked) |
Kristian Høgsberg | 4476aaf | 2012-06-25 14:03:13 -0400 | [diff] [blame] | 6237 | return; |
Jonas Ådahl | e3cddce | 2012-06-13 00:01:22 +0200 | [diff] [blame] | 6238 | new_index = key - KEY_F1; |
| 6239 | if (new_index >= shell->workspaces.num) |
| 6240 | new_index = shell->workspaces.num - 1; |
| 6241 | |
| 6242 | change_workspace(shell, new_index); |
| 6243 | } |
| 6244 | |
Jonas Ådahl | 8de6a1d | 2012-08-29 22:13:00 +0200 | [diff] [blame] | 6245 | static void |
Derek Foreman | 8ae2db5 | 2015-07-15 13:00:36 -0500 | [diff] [blame] | 6246 | workspace_move_surface_up_binding(struct weston_keyboard *keyboard, |
| 6247 | uint32_t time, uint32_t key, void *data) |
Jonas Ådahl | 8de6a1d | 2012-08-29 22:13:00 +0200 | [diff] [blame] | 6248 | { |
| 6249 | struct desktop_shell *shell = data; |
| 6250 | unsigned int new_index = shell->workspaces.current; |
| 6251 | |
| 6252 | if (shell->locked) |
| 6253 | return; |
| 6254 | |
| 6255 | if (new_index != 0) |
| 6256 | new_index--; |
| 6257 | |
Derek Foreman | 8ae2db5 | 2015-07-15 13:00:36 -0500 | [diff] [blame] | 6258 | take_surface_to_workspace_by_seat(shell, keyboard->seat, new_index); |
Jonas Ådahl | 8de6a1d | 2012-08-29 22:13:00 +0200 | [diff] [blame] | 6259 | } |
| 6260 | |
| 6261 | static void |
Derek Foreman | 8ae2db5 | 2015-07-15 13:00:36 -0500 | [diff] [blame] | 6262 | workspace_move_surface_down_binding(struct weston_keyboard *keyboard, |
| 6263 | uint32_t time, uint32_t key, void *data) |
Jonas Ådahl | 8de6a1d | 2012-08-29 22:13:00 +0200 | [diff] [blame] | 6264 | { |
| 6265 | struct desktop_shell *shell = data; |
| 6266 | unsigned int new_index = shell->workspaces.current; |
| 6267 | |
| 6268 | if (shell->locked) |
| 6269 | return; |
| 6270 | |
| 6271 | if (new_index < shell->workspaces.num - 1) |
| 6272 | new_index++; |
| 6273 | |
Derek Foreman | 8ae2db5 | 2015-07-15 13:00:36 -0500 | [diff] [blame] | 6274 | take_surface_to_workspace_by_seat(shell, keyboard->seat, new_index); |
Jonas Ådahl | 8de6a1d | 2012-08-29 22:13:00 +0200 | [diff] [blame] | 6275 | } |
Jonas Ådahl | e3cddce | 2012-06-13 00:01:22 +0200 | [diff] [blame] | 6276 | |
| 6277 | static void |
Ander Conselvan de Oliveira | c94d622 | 2014-01-29 18:47:54 +0200 | [diff] [blame] | 6278 | shell_reposition_view_on_output_destroy(struct weston_view *view) |
| 6279 | { |
| 6280 | struct weston_output *output, *first_output; |
| 6281 | struct weston_compositor *ec = view->surface->compositor; |
| 6282 | struct shell_surface *shsurf; |
| 6283 | float x, y; |
| 6284 | int visible; |
| 6285 | |
| 6286 | x = view->geometry.x; |
| 6287 | y = view->geometry.y; |
| 6288 | |
| 6289 | /* At this point the destroyed output is not in the list anymore. |
| 6290 | * If the view is still visible somewhere, we leave where it is, |
| 6291 | * otherwise, move it to the first output. */ |
| 6292 | visible = 0; |
| 6293 | wl_list_for_each(output, &ec->output_list, link) { |
| 6294 | if (pixman_region32_contains_point(&output->region, |
| 6295 | x, y, NULL)) { |
| 6296 | visible = 1; |
| 6297 | break; |
| 6298 | } |
| 6299 | } |
| 6300 | |
| 6301 | if (!visible) { |
| 6302 | first_output = container_of(ec->output_list.next, |
| 6303 | struct weston_output, link); |
| 6304 | |
| 6305 | x = first_output->x + first_output->width / 4; |
| 6306 | y = first_output->y + first_output->height / 4; |
Xiong Zhang | 62899f5 | 2014-03-07 16:27:19 +0800 | [diff] [blame] | 6307 | |
| 6308 | weston_view_set_position(view, x, y); |
| 6309 | } else { |
| 6310 | weston_view_geometry_dirty(view); |
Ander Conselvan de Oliveira | c94d622 | 2014-01-29 18:47:54 +0200 | [diff] [blame] | 6311 | } |
| 6312 | |
Ander Conselvan de Oliveira | c94d622 | 2014-01-29 18:47:54 +0200 | [diff] [blame] | 6313 | |
| 6314 | shsurf = get_shell_surface(view->surface); |
| 6315 | |
| 6316 | if (shsurf) { |
| 6317 | shsurf->saved_position_valid = false; |
| 6318 | shsurf->next_state.maximized = false; |
| 6319 | shsurf->next_state.fullscreen = false; |
| 6320 | shsurf->state_changed = true; |
| 6321 | } |
| 6322 | } |
| 6323 | |
Ander Conselvan de Oliveira | 304996d | 2014-04-11 13:57:15 +0300 | [diff] [blame] | 6324 | void |
| 6325 | shell_for_each_layer(struct desktop_shell *shell, |
| 6326 | shell_for_each_layer_func_t func, void *data) |
Ander Conselvan de Oliveira | c94d622 | 2014-01-29 18:47:54 +0200 | [diff] [blame] | 6327 | { |
Ander Conselvan de Oliveira | 304996d | 2014-04-11 13:57:15 +0300 | [diff] [blame] | 6328 | struct workspace **ws; |
| 6329 | |
| 6330 | func(shell, &shell->fullscreen_layer, data); |
| 6331 | func(shell, &shell->panel_layer, data); |
| 6332 | func(shell, &shell->background_layer, data); |
| 6333 | func(shell, &shell->lock_layer, data); |
| 6334 | func(shell, &shell->input_panel_layer, data); |
| 6335 | |
| 6336 | wl_array_for_each(ws, &shell->workspaces.array) |
| 6337 | func(shell, &(*ws)->layer, data); |
| 6338 | } |
| 6339 | |
| 6340 | static void |
| 6341 | shell_output_destroy_move_layer(struct desktop_shell *shell, |
| 6342 | struct weston_layer *layer, |
| 6343 | void *data) |
| 6344 | { |
| 6345 | struct weston_output *output = data; |
Ander Conselvan de Oliveira | c94d622 | 2014-01-29 18:47:54 +0200 | [diff] [blame] | 6346 | struct weston_view *view; |
| 6347 | |
Giulio Camuffo | 412e6a5 | 2014-07-09 22:12:56 +0300 | [diff] [blame] | 6348 | 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] | 6349 | if (view->output != output) |
| 6350 | continue; |
Ander Conselvan de Oliveira | c94d622 | 2014-01-29 18:47:54 +0200 | [diff] [blame] | 6351 | |
Ander Conselvan de Oliveira | 304996d | 2014-04-11 13:57:15 +0300 | [diff] [blame] | 6352 | shell_reposition_view_on_output_destroy(view); |
Ander Conselvan de Oliveira | c94d622 | 2014-01-29 18:47:54 +0200 | [diff] [blame] | 6353 | } |
| 6354 | } |
| 6355 | |
| 6356 | static void |
Xiong Zhang | 6b48142 | 2013-10-23 13:58:32 +0800 | [diff] [blame] | 6357 | handle_output_destroy(struct wl_listener *listener, void *data) |
| 6358 | { |
| 6359 | struct shell_output *output_listener = |
| 6360 | container_of(listener, struct shell_output, destroy_listener); |
Ander Conselvan de Oliveira | 304996d | 2014-04-11 13:57:15 +0300 | [diff] [blame] | 6361 | struct weston_output *output = output_listener->output; |
| 6362 | struct desktop_shell *shell = output_listener->shell; |
Xiong Zhang | 6b48142 | 2013-10-23 13:58:32 +0800 | [diff] [blame] | 6363 | |
Ander Conselvan de Oliveira | 304996d | 2014-04-11 13:57:15 +0300 | [diff] [blame] | 6364 | 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] | 6365 | |
Xiong Zhang | 6b48142 | 2013-10-23 13:58:32 +0800 | [diff] [blame] | 6366 | wl_list_remove(&output_listener->destroy_listener.link); |
| 6367 | wl_list_remove(&output_listener->link); |
| 6368 | free(output_listener); |
| 6369 | } |
| 6370 | |
| 6371 | static void |
| 6372 | create_shell_output(struct desktop_shell *shell, |
| 6373 | struct weston_output *output) |
| 6374 | { |
| 6375 | struct shell_output *shell_output; |
| 6376 | |
| 6377 | shell_output = zalloc(sizeof *shell_output); |
| 6378 | if (shell_output == NULL) |
| 6379 | return; |
| 6380 | |
| 6381 | shell_output->output = output; |
| 6382 | shell_output->shell = shell; |
| 6383 | shell_output->destroy_listener.notify = handle_output_destroy; |
| 6384 | wl_signal_add(&output->destroy_signal, |
| 6385 | &shell_output->destroy_listener); |
Kristian Høgsberg | a3a0e18 | 2013-10-23 23:36:04 -0700 | [diff] [blame] | 6386 | wl_list_insert(shell->output_list.prev, &shell_output->link); |
Xiong Zhang | 6b48142 | 2013-10-23 13:58:32 +0800 | [diff] [blame] | 6387 | } |
| 6388 | |
| 6389 | static void |
| 6390 | handle_output_create(struct wl_listener *listener, void *data) |
| 6391 | { |
| 6392 | struct desktop_shell *shell = |
| 6393 | container_of(listener, struct desktop_shell, output_create_listener); |
| 6394 | struct weston_output *output = (struct weston_output *)data; |
| 6395 | |
| 6396 | create_shell_output(shell, output); |
| 6397 | } |
| 6398 | |
| 6399 | static void |
Ander Conselvan de Oliveira | 304996d | 2014-04-11 13:57:15 +0300 | [diff] [blame] | 6400 | handle_output_move_layer(struct desktop_shell *shell, |
| 6401 | struct weston_layer *layer, void *data) |
Ander Conselvan de Oliveira | a8a9baf | 2014-01-29 18:47:52 +0200 | [diff] [blame] | 6402 | { |
Ander Conselvan de Oliveira | 304996d | 2014-04-11 13:57:15 +0300 | [diff] [blame] | 6403 | struct weston_output *output = data; |
Ander Conselvan de Oliveira | a8a9baf | 2014-01-29 18:47:52 +0200 | [diff] [blame] | 6404 | struct weston_view *view; |
| 6405 | float x, y; |
| 6406 | |
Giulio Camuffo | 412e6a5 | 2014-07-09 22:12:56 +0300 | [diff] [blame] | 6407 | 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] | 6408 | if (view->output != output) |
| 6409 | continue; |
| 6410 | |
| 6411 | x = view->geometry.x + output->move_x; |
| 6412 | y = view->geometry.y + output->move_y; |
| 6413 | weston_view_set_position(view, x, y); |
| 6414 | } |
| 6415 | } |
| 6416 | |
| 6417 | static void |
| 6418 | handle_output_move(struct wl_listener *listener, void *data) |
| 6419 | { |
| 6420 | struct desktop_shell *shell; |
| 6421 | |
Ander Conselvan de Oliveira | a8a9baf | 2014-01-29 18:47:52 +0200 | [diff] [blame] | 6422 | shell = container_of(listener, struct desktop_shell, |
| 6423 | output_move_listener); |
Ander Conselvan de Oliveira | a8a9baf | 2014-01-29 18:47:52 +0200 | [diff] [blame] | 6424 | |
Ander Conselvan de Oliveira | 304996d | 2014-04-11 13:57:15 +0300 | [diff] [blame] | 6425 | shell_for_each_layer(shell, handle_output_move_layer, data); |
Ander Conselvan de Oliveira | a8a9baf | 2014-01-29 18:47:52 +0200 | [diff] [blame] | 6426 | } |
| 6427 | |
| 6428 | static void |
Xiong Zhang | 6b48142 | 2013-10-23 13:58:32 +0800 | [diff] [blame] | 6429 | setup_output_destroy_handler(struct weston_compositor *ec, |
| 6430 | struct desktop_shell *shell) |
| 6431 | { |
| 6432 | struct weston_output *output; |
| 6433 | |
| 6434 | wl_list_init(&shell->output_list); |
| 6435 | wl_list_for_each(output, &ec->output_list, link) |
| 6436 | create_shell_output(shell, output); |
| 6437 | |
| 6438 | shell->output_create_listener.notify = handle_output_create; |
| 6439 | wl_signal_add(&ec->output_created_signal, |
| 6440 | &shell->output_create_listener); |
Ander Conselvan de Oliveira | a8a9baf | 2014-01-29 18:47:52 +0200 | [diff] [blame] | 6441 | |
| 6442 | shell->output_move_listener.notify = handle_output_move; |
| 6443 | wl_signal_add(&ec->output_moved_signal, &shell->output_move_listener); |
Xiong Zhang | 6b48142 | 2013-10-23 13:58:32 +0800 | [diff] [blame] | 6444 | } |
| 6445 | |
| 6446 | static void |
Kristian Høgsberg | 02e79dc | 2012-04-12 09:55:26 -0400 | [diff] [blame] | 6447 | shell_destroy(struct wl_listener *listener, void *data) |
Pekka Paalanen | 3c64723 | 2011-12-22 13:43:43 +0200 | [diff] [blame] | 6448 | { |
Tiago Vignatti | be14326 | 2012-04-16 17:31:41 +0300 | [diff] [blame] | 6449 | struct desktop_shell *shell = |
| 6450 | container_of(listener, struct desktop_shell, destroy_listener); |
Jonas Ådahl | e3cddce | 2012-06-13 00:01:22 +0200 | [diff] [blame] | 6451 | struct workspace **ws; |
Xiong Zhang | 6b48142 | 2013-10-23 13:58:32 +0800 | [diff] [blame] | 6452 | struct shell_output *shell_output, *tmp; |
Pekka Paalanen | 3c64723 | 2011-12-22 13:43:43 +0200 | [diff] [blame] | 6453 | |
Kristian Høgsberg | 17bccae | 2014-01-16 16:46:28 -0800 | [diff] [blame] | 6454 | /* Force state to unlocked so we don't try to fade */ |
| 6455 | shell->locked = false; |
Pekka Paalanen | 826dc14 | 2014-08-27 12:11:53 +0300 | [diff] [blame] | 6456 | |
| 6457 | if (shell->child.client) { |
| 6458 | /* disable respawn */ |
| 6459 | wl_list_remove(&shell->child.client_destroy_listener.link); |
Pekka Paalanen | 9cf5cc8 | 2012-01-02 16:00:24 +0200 | [diff] [blame] | 6460 | wl_client_destroy(shell->child.client); |
Pekka Paalanen | 826dc14 | 2014-08-27 12:11:53 +0300 | [diff] [blame] | 6461 | } |
Pekka Paalanen | 9cf5cc8 | 2012-01-02 16:00:24 +0200 | [diff] [blame] | 6462 | |
Ander Conselvan de Oliveira | a457563 | 2013-02-21 18:35:23 +0200 | [diff] [blame] | 6463 | wl_list_remove(&shell->idle_listener.link); |
| 6464 | wl_list_remove(&shell->wake_listener.link); |
Kristian Høgsberg | 677a5f5 | 2013-12-04 11:00:19 -0800 | [diff] [blame] | 6465 | |
Pekka Paalanen | aa9536a | 2015-06-24 16:09:17 +0300 | [diff] [blame] | 6466 | text_backend_destroy(shell->text_backend); |
Kristian Høgsberg | 677a5f5 | 2013-12-04 11:00:19 -0800 | [diff] [blame] | 6467 | input_panel_destroy(shell); |
Kristian Høgsberg | 88c1607 | 2012-05-16 08:04:19 -0400 | [diff] [blame] | 6468 | |
Xiong Zhang | 6b48142 | 2013-10-23 13:58:32 +0800 | [diff] [blame] | 6469 | wl_list_for_each_safe(shell_output, tmp, &shell->output_list, link) { |
| 6470 | wl_list_remove(&shell_output->destroy_listener.link); |
| 6471 | wl_list_remove(&shell_output->link); |
| 6472 | free(shell_output); |
| 6473 | } |
| 6474 | |
| 6475 | wl_list_remove(&shell->output_create_listener.link); |
Kristian Høgsberg | 6d50b0f | 2014-04-30 20:46:25 -0700 | [diff] [blame] | 6476 | wl_list_remove(&shell->output_move_listener.link); |
Xiong Zhang | 6b48142 | 2013-10-23 13:58:32 +0800 | [diff] [blame] | 6477 | |
Jonas Ådahl | e3cddce | 2012-06-13 00:01:22 +0200 | [diff] [blame] | 6478 | wl_array_for_each(ws, &shell->workspaces.array) |
| 6479 | workspace_destroy(*ws); |
| 6480 | wl_array_release(&shell->workspaces.array); |
| 6481 | |
Emilio Pozuelo Monfort | 46ce798 | 2013-11-20 13:22:29 +0100 | [diff] [blame] | 6482 | free(shell->client); |
Pekka Paalanen | 3c64723 | 2011-12-22 13:43:43 +0200 | [diff] [blame] | 6483 | free(shell); |
| 6484 | } |
| 6485 | |
Tiago Vignatti | 0b52d48 | 2012-04-20 18:54:25 +0300 | [diff] [blame] | 6486 | static void |
| 6487 | shell_add_bindings(struct weston_compositor *ec, struct desktop_shell *shell) |
| 6488 | { |
| 6489 | uint32_t mod; |
Jonas Ådahl | e3cddce | 2012-06-13 00:01:22 +0200 | [diff] [blame] | 6490 | int i, num_workspace_bindings; |
Tiago Vignatti | 0b52d48 | 2012-04-20 18:54:25 +0300 | [diff] [blame] | 6491 | |
| 6492 | /* fixed bindings */ |
Daniel Stone | 325fc2d | 2012-05-30 16:31:58 +0100 | [diff] [blame] | 6493 | weston_compositor_add_key_binding(ec, KEY_BACKSPACE, |
| 6494 | MODIFIER_CTRL | MODIFIER_ALT, |
| 6495 | terminate_binding, ec); |
| 6496 | weston_compositor_add_button_binding(ec, BTN_LEFT, 0, |
| 6497 | click_to_activate_binding, |
| 6498 | shell); |
Kristian Høgsberg | f0ce581 | 2014-04-07 11:52:17 -0700 | [diff] [blame] | 6499 | weston_compositor_add_button_binding(ec, BTN_RIGHT, 0, |
| 6500 | click_to_activate_binding, |
| 6501 | shell); |
Neil Roberts | a28c693 | 2013-10-03 16:43:04 +0100 | [diff] [blame] | 6502 | weston_compositor_add_touch_binding(ec, 0, |
| 6503 | touch_to_activate_binding, |
| 6504 | shell); |
Daniel Stone | 325fc2d | 2012-05-30 16:31:58 +0100 | [diff] [blame] | 6505 | weston_compositor_add_axis_binding(ec, WL_POINTER_AXIS_VERTICAL_SCROLL, |
| 6506 | MODIFIER_SUPER | MODIFIER_ALT, |
| 6507 | surface_opacity_binding, NULL); |
| 6508 | weston_compositor_add_axis_binding(ec, WL_POINTER_AXIS_VERTICAL_SCROLL, |
| 6509 | MODIFIER_SUPER, zoom_axis_binding, |
| 6510 | NULL); |
Tiago Vignatti | 0b52d48 | 2012-04-20 18:54:25 +0300 | [diff] [blame] | 6511 | |
| 6512 | /* configurable bindings */ |
| 6513 | mod = shell->binding_modifier; |
Daniel Stone | 325fc2d | 2012-05-30 16:31:58 +0100 | [diff] [blame] | 6514 | weston_compositor_add_key_binding(ec, KEY_PAGEUP, mod, |
| 6515 | zoom_key_binding, NULL); |
| 6516 | weston_compositor_add_key_binding(ec, KEY_PAGEDOWN, mod, |
| 6517 | zoom_key_binding, NULL); |
Kristian Høgsberg | 211b517 | 2014-01-11 13:10:21 -0800 | [diff] [blame] | 6518 | weston_compositor_add_key_binding(ec, KEY_M, mod | MODIFIER_SHIFT, |
| 6519 | maximize_binding, NULL); |
| 6520 | weston_compositor_add_key_binding(ec, KEY_F, mod | MODIFIER_SHIFT, |
| 6521 | fullscreen_binding, NULL); |
Daniel Stone | 325fc2d | 2012-05-30 16:31:58 +0100 | [diff] [blame] | 6522 | weston_compositor_add_button_binding(ec, BTN_LEFT, mod, move_binding, |
| 6523 | shell); |
Neil Roberts | aba0f25 | 2013-10-03 16:43:05 +0100 | [diff] [blame] | 6524 | weston_compositor_add_touch_binding(ec, mod, touch_move_binding, shell); |
Derek Foreman | 2217f3f | 2015-06-25 16:03:30 -0500 | [diff] [blame] | 6525 | weston_compositor_add_button_binding(ec, BTN_RIGHT, mod, |
Daniel Stone | 325fc2d | 2012-05-30 16:31:58 +0100 | [diff] [blame] | 6526 | resize_binding, shell); |
Kristian Høgsberg | 0837fa9 | 2014-01-20 10:35:26 -0800 | [diff] [blame] | 6527 | weston_compositor_add_button_binding(ec, BTN_LEFT, |
| 6528 | mod | MODIFIER_SHIFT, |
| 6529 | resize_binding, shell); |
Pekka Paalanen | 7bb6510 | 2013-05-22 18:03:04 +0300 | [diff] [blame] | 6530 | |
| 6531 | if (ec->capabilities & WESTON_CAP_ROTATION_ANY) |
Derek Foreman | 2217f3f | 2015-06-25 16:03:30 -0500 | [diff] [blame] | 6532 | weston_compositor_add_button_binding(ec, BTN_MIDDLE, mod, |
Pekka Paalanen | 7bb6510 | 2013-05-22 18:03:04 +0300 | [diff] [blame] | 6533 | rotate_binding, NULL); |
| 6534 | |
Daniel Stone | 325fc2d | 2012-05-30 16:31:58 +0100 | [diff] [blame] | 6535 | weston_compositor_add_key_binding(ec, KEY_TAB, mod, switcher_binding, |
| 6536 | shell); |
| 6537 | weston_compositor_add_key_binding(ec, KEY_F9, mod, backlight_binding, |
| 6538 | ec); |
| 6539 | weston_compositor_add_key_binding(ec, KEY_BRIGHTNESSDOWN, 0, |
| 6540 | backlight_binding, ec); |
| 6541 | weston_compositor_add_key_binding(ec, KEY_F10, mod, backlight_binding, |
| 6542 | ec); |
| 6543 | weston_compositor_add_key_binding(ec, KEY_BRIGHTNESSUP, 0, |
| 6544 | backlight_binding, ec); |
Daniel Stone | 325fc2d | 2012-05-30 16:31:58 +0100 | [diff] [blame] | 6545 | weston_compositor_add_key_binding(ec, KEY_K, mod, |
| 6546 | force_kill_binding, shell); |
Jonas Ådahl | e3cddce | 2012-06-13 00:01:22 +0200 | [diff] [blame] | 6547 | weston_compositor_add_key_binding(ec, KEY_UP, mod, |
| 6548 | workspace_up_binding, shell); |
| 6549 | weston_compositor_add_key_binding(ec, KEY_DOWN, mod, |
| 6550 | workspace_down_binding, shell); |
Jonas Ådahl | 8de6a1d | 2012-08-29 22:13:00 +0200 | [diff] [blame] | 6551 | weston_compositor_add_key_binding(ec, KEY_UP, mod | MODIFIER_SHIFT, |
| 6552 | workspace_move_surface_up_binding, |
| 6553 | shell); |
| 6554 | weston_compositor_add_key_binding(ec, KEY_DOWN, mod | MODIFIER_SHIFT, |
| 6555 | workspace_move_surface_down_binding, |
| 6556 | shell); |
Jonas Ådahl | e3cddce | 2012-06-13 00:01:22 +0200 | [diff] [blame] | 6557 | |
Kristian Høgsberg | d56ab4e | 2014-01-16 16:51:52 -0800 | [diff] [blame] | 6558 | if (shell->exposay_modifier) |
| 6559 | weston_compositor_add_modifier_binding(ec, shell->exposay_modifier, |
| 6560 | exposay_binding, shell); |
Daniel Stone | df8133b | 2013-11-19 11:37:14 +0100 | [diff] [blame] | 6561 | |
Jonas Ådahl | e3cddce | 2012-06-13 00:01:22 +0200 | [diff] [blame] | 6562 | /* Add bindings for mod+F[1-6] for workspace 1 to 6. */ |
| 6563 | if (shell->workspaces.num > 1) { |
| 6564 | num_workspace_bindings = shell->workspaces.num; |
| 6565 | if (num_workspace_bindings > 6) |
| 6566 | num_workspace_bindings = 6; |
| 6567 | for (i = 0; i < num_workspace_bindings; i++) |
| 6568 | weston_compositor_add_key_binding(ec, KEY_F1 + i, mod, |
| 6569 | workspace_f_binding, |
| 6570 | shell); |
| 6571 | } |
Ander Conselvan de Oliveira | c509d2b | 2012-11-08 17:20:45 +0200 | [diff] [blame] | 6572 | |
Pekka Paalanen | 2829f7c | 2015-02-19 17:02:13 +0200 | [diff] [blame] | 6573 | weston_install_debug_key_binding(ec, mod); |
Tiago Vignatti | 0b52d48 | 2012-04-20 18:54:25 +0300 | [diff] [blame] | 6574 | } |
| 6575 | |
Jason Ekstrand | 024177c | 2014-04-21 19:42:58 -0500 | [diff] [blame] | 6576 | static void |
| 6577 | handle_seat_created(struct wl_listener *listener, void *data) |
| 6578 | { |
| 6579 | struct weston_seat *seat = data; |
| 6580 | |
| 6581 | create_shell_seat(seat); |
| 6582 | } |
| 6583 | |
Kristian Høgsberg | 1c56218 | 2011-05-02 22:09:20 -0400 | [diff] [blame] | 6584 | WL_EXPORT int |
Kristian Høgsberg | cb4685b | 2013-02-20 15:37:49 -0500 | [diff] [blame] | 6585 | module_init(struct weston_compositor *ec, |
Ossama Othman | a50e6e4 | 2013-05-14 09:48:26 -0700 | [diff] [blame] | 6586 | int *argc, char *argv[]) |
Kristian Høgsberg | 4cca349 | 2011-01-18 07:53:49 -0500 | [diff] [blame] | 6587 | { |
Kristian Høgsberg | f4d2f23 | 2012-08-10 10:05:39 -0400 | [diff] [blame] | 6588 | struct weston_seat *seat; |
Tiago Vignatti | be14326 | 2012-04-16 17:31:41 +0300 | [diff] [blame] | 6589 | struct desktop_shell *shell; |
Jonas Ådahl | e3cddce | 2012-06-13 00:01:22 +0200 | [diff] [blame] | 6590 | struct workspace **pws; |
| 6591 | unsigned int i; |
Tiago Vignatti | b7dbbd6 | 2012-09-25 17:57:01 +0300 | [diff] [blame] | 6592 | struct wl_event_loop *loop; |
Kristian Høgsberg | 02ec0a5 | 2011-04-23 13:04:11 -0400 | [diff] [blame] | 6593 | |
Peter Hutterer | f3d6227 | 2013-08-08 11:57:05 +1000 | [diff] [blame] | 6594 | shell = zalloc(sizeof *shell); |
Kristian Høgsberg | 02ec0a5 | 2011-04-23 13:04:11 -0400 | [diff] [blame] | 6595 | if (shell == NULL) |
| 6596 | return -1; |
| 6597 | |
Kristian Høgsberg | 7584062 | 2011-09-06 13:48:16 -0400 | [diff] [blame] | 6598 | shell->compositor = ec; |
Kristian Høgsberg | 02e79dc | 2012-04-12 09:55:26 -0400 | [diff] [blame] | 6599 | |
| 6600 | shell->destroy_listener.notify = shell_destroy; |
| 6601 | wl_signal_add(&ec->destroy_signal, &shell->destroy_listener); |
Ander Conselvan de Oliveira | a457563 | 2013-02-21 18:35:23 +0200 | [diff] [blame] | 6602 | shell->idle_listener.notify = idle_handler; |
| 6603 | wl_signal_add(&ec->idle_signal, &shell->idle_listener); |
| 6604 | shell->wake_listener.notify = wake_handler; |
| 6605 | wl_signal_add(&ec->wake_signal, &shell->wake_listener); |
Kristian Høgsberg | 677a5f5 | 2013-12-04 11:00:19 -0800 | [diff] [blame] | 6606 | |
Kristian Høgsberg | 82a1d11 | 2012-07-19 14:02:00 -0400 | [diff] [blame] | 6607 | ec->shell_interface.shell = shell; |
Tiago Vignatti | bc052c9 | 2012-04-19 16:18:18 +0300 | [diff] [blame] | 6608 | ec->shell_interface.create_shell_surface = create_shell_surface; |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 6609 | ec->shell_interface.get_primary_view = get_primary_view; |
Tiago Vignatti | bc052c9 | 2012-04-19 16:18:18 +0300 | [diff] [blame] | 6610 | ec->shell_interface.set_toplevel = set_toplevel; |
Tiago Vignatti | 491bac1 | 2012-05-18 16:37:43 -0400 | [diff] [blame] | 6611 | ec->shell_interface.set_transient = set_transient; |
Kristian Høgsberg | 4779241 | 2014-05-04 13:47:06 -0700 | [diff] [blame] | 6612 | ec->shell_interface.set_fullscreen = shell_interface_set_fullscreen; |
Tiago Vignatti | fb2adba | 2013-06-12 15:43:21 -0300 | [diff] [blame] | 6613 | ec->shell_interface.set_xwayland = set_xwayland; |
Kristian Høgsberg | ae356ae | 2014-04-29 16:03:54 -0700 | [diff] [blame] | 6614 | ec->shell_interface.move = shell_interface_move; |
Derek Foreman | 8fbebbd | 2015-07-15 13:00:40 -0500 | [diff] [blame] | 6615 | ec->shell_interface.resize = shell_interface_resize; |
Giulio Camuffo | 62942ad | 2013-09-11 18:20:47 +0200 | [diff] [blame] | 6616 | ec->shell_interface.set_title = set_title; |
Jasper St. Pierre | ccf48fb | 2014-05-02 10:21:38 -0400 | [diff] [blame] | 6617 | ec->shell_interface.set_window_geometry = set_window_geometry; |
Giulio Camuffo | 6b4b241 | 2015-01-29 19:06:49 +0200 | [diff] [blame] | 6618 | ec->shell_interface.set_maximized = shell_interface_set_maximized; |
Giulio Camuffo | a8e9b41 | 2015-01-27 19:10:37 +0200 | [diff] [blame] | 6619 | ec->shell_interface.set_pid = set_pid; |
Kristian Høgsberg | 4cca349 | 2011-01-18 07:53:49 -0500 | [diff] [blame] | 6620 | |
Kristian Høgsberg | 3be2ce9 | 2012-02-29 12:42:35 -0500 | [diff] [blame] | 6621 | weston_layer_init(&shell->fullscreen_layer, &ec->cursor_layer.link); |
| 6622 | weston_layer_init(&shell->panel_layer, &shell->fullscreen_layer.link); |
Jonas Ådahl | e3cddce | 2012-06-13 00:01:22 +0200 | [diff] [blame] | 6623 | weston_layer_init(&shell->background_layer, &shell->panel_layer.link); |
| 6624 | weston_layer_init(&shell->lock_layer, NULL); |
Philipp Brüschweiler | 711fda8 | 2012-08-09 18:50:43 +0200 | [diff] [blame] | 6625 | weston_layer_init(&shell->input_panel_layer, NULL); |
Jonas Ådahl | e3cddce | 2012-06-13 00:01:22 +0200 | [diff] [blame] | 6626 | |
| 6627 | wl_array_init(&shell->workspaces.array); |
Jonas Ådahl | e9d2250 | 2012-08-29 22:13:01 +0200 | [diff] [blame] | 6628 | wl_list_init(&shell->workspaces.client_list); |
Kristian Høgsberg | 3be2ce9 | 2012-02-29 12:42:35 -0500 | [diff] [blame] | 6629 | |
Kristian Høgsberg | 677a5f5 | 2013-12-04 11:00:19 -0800 | [diff] [blame] | 6630 | if (input_panel_setup(shell) < 0) |
| 6631 | return -1; |
| 6632 | |
Pekka Paalanen | aa9536a | 2015-06-24 16:09:17 +0300 | [diff] [blame] | 6633 | shell->text_backend = text_backend_init(ec); |
| 6634 | if (!shell->text_backend) |
Murray Calavera | 9a51cd7 | 2015-06-10 21:16:02 +0000 | [diff] [blame] | 6635 | return -1; |
| 6636 | |
Kristian Høgsberg | 14e438c | 2013-05-26 21:48:14 -0400 | [diff] [blame] | 6637 | shell_configuration(shell); |
Pekka Paalanen | e955f1e | 2011-12-07 11:49:52 +0200 | [diff] [blame] | 6638 | |
Daniel Stone | df8133b | 2013-11-19 11:37:14 +0100 | [diff] [blame] | 6639 | shell->exposay.state_cur = EXPOSAY_LAYOUT_INACTIVE; |
| 6640 | shell->exposay.state_target = EXPOSAY_TARGET_CANCEL; |
| 6641 | |
Jonas Ådahl | e3cddce | 2012-06-13 00:01:22 +0200 | [diff] [blame] | 6642 | for (i = 0; i < shell->workspaces.num; i++) { |
| 6643 | pws = wl_array_add(&shell->workspaces.array, sizeof *pws); |
| 6644 | if (pws == NULL) |
| 6645 | return -1; |
| 6646 | |
| 6647 | *pws = workspace_create(); |
| 6648 | if (*pws == NULL) |
| 6649 | return -1; |
| 6650 | } |
| 6651 | activate_workspace(shell, 0); |
| 6652 | |
Manuel Bachmann | 50c87db | 2014-02-26 15:52:13 +0100 | [diff] [blame] | 6653 | weston_layer_init(&shell->minimized_layer, NULL); |
| 6654 | |
Jonas Ådahl | 8de6a1d | 2012-08-29 22:13:00 +0200 | [diff] [blame] | 6655 | wl_list_init(&shell->workspaces.anim_sticky_list); |
Jonas Ådahl | 62fcd04 | 2012-06-13 00:01:23 +0200 | [diff] [blame] | 6656 | wl_list_init(&shell->workspaces.animation.link); |
| 6657 | shell->workspaces.animation.frame = animate_workspace_change_frame; |
| 6658 | |
Kristian Høgsberg | 919cddb | 2013-07-08 19:03:57 -0400 | [diff] [blame] | 6659 | if (wl_global_create(ec->wl_display, &wl_shell_interface, 1, |
Kristian Høgsberg | 97d44aa | 2011-08-26 17:21:20 -0400 | [diff] [blame] | 6660 | shell, bind_shell) == NULL) |
Kristian Høgsberg | 4cca349 | 2011-01-18 07:53:49 -0500 | [diff] [blame] | 6661 | return -1; |
| 6662 | |
Rafael Antognolli | e2a3455 | 2013-12-03 15:35:45 -0200 | [diff] [blame] | 6663 | if (wl_global_create(ec->wl_display, &xdg_shell_interface, 1, |
| 6664 | shell, bind_xdg_shell) == NULL) |
| 6665 | return -1; |
| 6666 | |
Kristian Høgsberg | 919cddb | 2013-07-08 19:03:57 -0400 | [diff] [blame] | 6667 | if (wl_global_create(ec->wl_display, |
Jonny Lamb | 765760d | 2014-08-20 15:53:19 +0200 | [diff] [blame] | 6668 | &desktop_shell_interface, 3, |
Kristian Høgsberg | 919cddb | 2013-07-08 19:03:57 -0400 | [diff] [blame] | 6669 | shell, bind_desktop_shell) == NULL) |
Kristian Høgsberg | 7584062 | 2011-09-06 13:48:16 -0400 | [diff] [blame] | 6670 | return -1; |
| 6671 | |
Kristian Høgsberg | 919cddb | 2013-07-08 19:03:57 -0400 | [diff] [blame] | 6672 | if (wl_global_create(ec->wl_display, &workspace_manager_interface, 1, |
| 6673 | shell, bind_workspace_manager) == NULL) |
Jonas Ådahl | e9d2250 | 2012-08-29 22:13:01 +0200 | [diff] [blame] | 6674 | return -1; |
| 6675 | |
Kristian Høgsberg | f03a616 | 2012-01-17 11:07:42 -0500 | [diff] [blame] | 6676 | shell->child.deathstamp = weston_compositor_get_time(); |
Tiago Vignatti | b7dbbd6 | 2012-09-25 17:57:01 +0300 | [diff] [blame] | 6677 | |
Jonny Lamb | 765760d | 2014-08-20 15:53:19 +0200 | [diff] [blame] | 6678 | shell->panel_position = DESKTOP_SHELL_PANEL_POSITION_TOP; |
| 6679 | |
Xiong Zhang | 6b48142 | 2013-10-23 13:58:32 +0800 | [diff] [blame] | 6680 | setup_output_destroy_handler(ec, shell); |
| 6681 | |
Tiago Vignatti | b7dbbd6 | 2012-09-25 17:57:01 +0300 | [diff] [blame] | 6682 | loop = wl_display_get_event_loop(ec->wl_display); |
| 6683 | wl_event_loop_add_idle(loop, launch_desktop_shell_process, shell); |
Pekka Paalanen | 6cd281a | 2011-11-03 14:11:32 +0200 | [diff] [blame] | 6684 | |
Jason Ekstrand | 024177c | 2014-04-21 19:42:58 -0500 | [diff] [blame] | 6685 | wl_list_for_each(seat, &ec->seat_list, link) |
| 6686 | handle_seat_created(NULL, seat); |
| 6687 | shell->seat_create_listener.notify = handle_seat_created; |
| 6688 | wl_signal_add(&ec->seat_created_signal, &shell->seat_create_listener); |
Kristian Høgsberg | d56bd90 | 2012-06-05 09:58:51 -0400 | [diff] [blame] | 6689 | |
Giulio Camuffo | c6ab3d5 | 2013-12-11 23:45:12 +0100 | [diff] [blame] | 6690 | screenshooter_create(ec); |
| 6691 | |
Tiago Vignatti | 0b52d48 | 2012-04-20 18:54:25 +0300 | [diff] [blame] | 6692 | shell_add_bindings(ec, shell); |
Kristian Høgsberg | 0793756 | 2011-04-12 17:25:42 -0400 | [diff] [blame] | 6693 | |
Pekka Paalanen | 79346ab | 2013-05-22 18:03:09 +0300 | [diff] [blame] | 6694 | shell_fade_init(shell); |
Ander Conselvan de Oliveira | 19d10ef | 2013-02-21 18:35:20 +0200 | [diff] [blame] | 6695 | |
Pekka Paalanen | 2e62e4a | 2014-08-28 11:41:26 +0300 | [diff] [blame] | 6696 | clock_gettime(CLOCK_MONOTONIC, &shell->startup_time); |
| 6697 | |
Kristian Høgsberg | 4cca349 | 2011-01-18 07:53:49 -0500 | [diff] [blame] | 6698 | return 0; |
| 6699 | } |