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" |
Jonas Ådahl | 6d6fb61 | 2015-11-17 16:00:33 +0800 | [diff] [blame] | 39 | #include "weston-desktop-shell-server-protocol.h" |
Jon Cruz | 4678bab | 2015-06-15 15:37:07 -0700 | [diff] [blame] | 40 | #include "shared/config-parser.h" |
Jon Cruz | d618f68 | 2015-06-15 15:37:09 -0700 | [diff] [blame] | 41 | #include "shared/helpers.h" |
Jonas Ådahl | 2a22933 | 2015-11-17 16:00:32 +0800 | [diff] [blame] | 42 | #include "xdg-shell-unstable-v5-server-protocol.h" |
Kristian Høgsberg | 4cca349 | 2011-01-18 07:53:49 -0500 | [diff] [blame] | 43 | |
Jonas Ådahl | e3cddce | 2012-06-13 00:01:22 +0200 | [diff] [blame] | 44 | #define DEFAULT_NUM_WORKSPACES 1 |
Jonas Ådahl | 62fcd04 | 2012-06-13 00:01:23 +0200 | [diff] [blame] | 45 | #define DEFAULT_WORKSPACE_CHANGE_ANIMATION_LENGTH 200 |
Jonas Ådahl | e3cddce | 2012-06-13 00:01:22 +0200 | [diff] [blame] | 46 | |
Giulio Camuffo | 1aaf3e4 | 2013-12-09 22:47:58 +0100 | [diff] [blame] | 47 | #ifndef static_assert |
| 48 | #define static_assert(cond, msg) |
| 49 | #endif |
| 50 | |
Jonas Ådahl | 0476974 | 2012-06-13 00:01:24 +0200 | [diff] [blame] | 51 | struct focus_state { |
| 52 | struct weston_seat *seat; |
Kristian Høgsberg | 2f5faff | 2012-07-31 16:36:34 -0400 | [diff] [blame] | 53 | struct workspace *ws; |
Jonas Ådahl | 0476974 | 2012-06-13 00:01:24 +0200 | [diff] [blame] | 54 | struct weston_surface *keyboard_focus; |
| 55 | struct wl_list link; |
| 56 | struct wl_listener seat_destroy_listener; |
| 57 | struct wl_listener surface_destroy_listener; |
| 58 | }; |
| 59 | |
Kristian Høgsberg | d2abb83 | 2011-11-23 10:52:40 -0500 | [diff] [blame] | 60 | enum shell_surface_type { |
Pekka Paalanen | 9826223 | 2011-12-01 10:42:22 +0200 | [diff] [blame] | 61 | SHELL_SURFACE_NONE, |
Kristian Høgsberg | d2abb83 | 2011-11-23 10:52:40 -0500 | [diff] [blame] | 62 | SHELL_SURFACE_TOPLEVEL, |
Tiago Vignatti | fb2adba | 2013-06-12 15:43:21 -0300 | [diff] [blame] | 63 | SHELL_SURFACE_POPUP, |
| 64 | SHELL_SURFACE_XWAYLAND |
Pekka Paalanen | 57da4a8 | 2011-11-23 16:42:16 +0200 | [diff] [blame] | 65 | }; |
| 66 | |
Jason Ekstrand | 9e9512f | 2014-04-16 21:12:10 -0500 | [diff] [blame] | 67 | struct shell_client; |
| 68 | |
Philip Withnall | 648a4dd | 2013-11-25 18:01:44 +0000 | [diff] [blame] | 69 | /* |
| 70 | * Surface stacking and ordering. |
| 71 | * |
| 72 | * This is handled using several linked lists of surfaces, organised into |
| 73 | * ‘layers’. The layers are ordered, and each of the surfaces in one layer are |
| 74 | * above all of the surfaces in the layer below. The set of layers is static and |
| 75 | * in the following order (top-most first): |
| 76 | * • Lock layer (only ever displayed on its own) |
| 77 | * • Cursor layer |
Manuel Bachmann | 805d2f5 | 2014-03-05 12:21:34 +0100 | [diff] [blame] | 78 | * • Input panel layer |
Philip Withnall | 648a4dd | 2013-11-25 18:01:44 +0000 | [diff] [blame] | 79 | * • Fullscreen layer |
| 80 | * • Panel layer |
Philip Withnall | 648a4dd | 2013-11-25 18:01:44 +0000 | [diff] [blame] | 81 | * • Workspace layers |
| 82 | * • Background layer |
| 83 | * |
| 84 | * The list of layers may be manipulated to remove whole layers of surfaces from |
| 85 | * display. For example, when locking the screen, all layers except the lock |
| 86 | * layer are removed. |
| 87 | * |
| 88 | * A surface’s layer is modified on configuring the surface, in |
| 89 | * set_surface_type() (which is only called when the surface’s type change is |
| 90 | * _committed_). If a surface’s type changes (e.g. when making a window |
| 91 | * fullscreen) its layer changes too. |
| 92 | * |
| 93 | * In order to allow popup and transient surfaces to be correctly stacked above |
| 94 | * their parent surfaces, each surface tracks both its parent surface, and a |
| 95 | * linked list of its children. When a surface’s layer is updated, so are the |
| 96 | * layers of its children. Note that child surfaces are *not* the same as |
| 97 | * subsurfaces — child/parent surfaces are purely for maintaining stacking |
| 98 | * order. |
| 99 | * |
| 100 | * The children_link list of siblings of a surface (i.e. those surfaces which |
| 101 | * have the same parent) only contains weston_surfaces which have a |
| 102 | * shell_surface. Stacking is not implemented for non-shell_surface |
| 103 | * weston_surfaces. This means that the following implication does *not* hold: |
| 104 | * (shsurf->parent != NULL) ⇒ !wl_list_is_empty(shsurf->children_link) |
| 105 | */ |
| 106 | |
Pekka Paalanen | 56cdea9 | 2011-11-23 16:14:12 +0200 | [diff] [blame] | 107 | struct shell_surface { |
Jason Ekstrand | 651f00e | 2013-06-14 10:07:54 -0500 | [diff] [blame] | 108 | struct wl_resource *resource; |
| 109 | struct wl_signal destroy_signal; |
Jason Ekstrand | 9e9512f | 2014-04-16 21:12:10 -0500 | [diff] [blame] | 110 | struct shell_client *owner; |
Jonas Ådahl | 49d77d2 | 2015-03-18 16:20:51 +0800 | [diff] [blame] | 111 | struct wl_resource *owner_resource; |
Pekka Paalanen | 9d1613e | 2011-11-25 12:09:16 +0200 | [diff] [blame] | 112 | |
Kristian Høgsberg | 8334bc1 | 2012-01-03 10:29:47 -0500 | [diff] [blame] | 113 | struct weston_surface *surface; |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 114 | struct weston_view *view; |
Jason Ekstrand | 918f2dd | 2013-12-02 21:01:53 -0600 | [diff] [blame] | 115 | int32_t last_width, last_height; |
Pekka Paalanen | 9d1613e | 2011-11-25 12:09:16 +0200 | [diff] [blame] | 116 | struct wl_listener surface_destroy_listener; |
Kristian Høgsberg | 160fe75 | 2014-03-11 10:19:10 -0700 | [diff] [blame] | 117 | struct wl_listener resource_destroy_listener; |
| 118 | |
Kristian Høgsberg | 8150b19 | 2012-06-27 10:22:58 -0400 | [diff] [blame] | 119 | struct weston_surface *parent; |
Philip Withnall | 648a4dd | 2013-11-25 18:01:44 +0000 | [diff] [blame] | 120 | struct wl_list children_list; /* child surfaces of this one */ |
| 121 | struct wl_list children_link; /* sibling surfaces of this one */ |
Tiago Vignatti | be14326 | 2012-04-16 17:31:41 +0300 | [diff] [blame] | 122 | struct desktop_shell *shell; |
Pekka Paalanen | 57da4a8 | 2011-11-23 16:42:16 +0200 | [diff] [blame] | 123 | |
Kristian Høgsberg | c8f8dd8 | 2013-12-05 23:20:33 -0800 | [diff] [blame] | 124 | enum shell_surface_type type; |
Kristian Høgsberg | e7afd91 | 2012-05-02 09:47:44 -0400 | [diff] [blame] | 125 | char *title, *class; |
Kristian Høgsberg | d2abb83 | 2011-11-23 10:52:40 -0500 | [diff] [blame] | 126 | int32_t saved_x, saved_y; |
Rafael Antognolli | 3c4e3f7 | 2013-12-03 15:35:46 -0200 | [diff] [blame] | 127 | int32_t saved_width, saved_height; |
Alex Wu | 4539b08 | 2012-03-01 12:57:46 +0800 | [diff] [blame] | 128 | bool saved_position_valid; |
Rafael Antognolli | 3c4e3f7 | 2013-12-03 15:35:46 -0200 | [diff] [blame] | 129 | bool saved_size_valid; |
Alex Wu | 7bcb8bd | 2012-04-27 09:07:24 +0800 | [diff] [blame] | 130 | bool saved_rotation_valid; |
Kristian Høgsberg | c85f1d4 | 2013-10-24 16:52:00 -0700 | [diff] [blame] | 131 | int unresponsive, grabbed; |
Kristian Høgsberg | 44cd196 | 2014-02-05 21:36:04 -0800 | [diff] [blame] | 132 | uint32_t resize_edges; |
Benjamin Franzke | d0f79ab | 2011-11-22 12:43:52 +0100 | [diff] [blame] | 133 | |
Kristian Høgsberg | b3cca0a | 2012-01-04 22:19:14 -0500 | [diff] [blame] | 134 | struct { |
Pekka Paalanen | 460099f | 2012-01-20 16:48:25 +0200 | [diff] [blame] | 135 | struct weston_transform transform; |
Kristian Høgsberg | 765e27b | 2012-01-27 13:36:13 -0500 | [diff] [blame] | 136 | struct weston_matrix rotation; |
Pekka Paalanen | 460099f | 2012-01-20 16:48:25 +0200 | [diff] [blame] | 137 | } rotation; |
| 138 | |
| 139 | struct { |
Giulio Camuffo | 5085a75 | 2013-03-25 21:42:45 +0100 | [diff] [blame] | 140 | struct wl_list grab_link; |
Kristian Høgsberg | b3cca0a | 2012-01-04 22:19:14 -0500 | [diff] [blame] | 141 | int32_t x, y; |
Giulio Camuffo | 5085a75 | 2013-03-25 21:42:45 +0100 | [diff] [blame] | 142 | struct shell_seat *shseat; |
Kristian Høgsberg | 3730f36 | 2012-04-13 12:40:07 -0400 | [diff] [blame] | 143 | uint32_t serial; |
Kristian Høgsberg | b3cca0a | 2012-01-04 22:19:14 -0500 | [diff] [blame] | 144 | } popup; |
| 145 | |
Alex Wu | 4539b08 | 2012-03-01 12:57:46 +0800 | [diff] [blame] | 146 | struct { |
Tiago Vignatti | 52e598c | 2012-05-07 15:23:08 +0300 | [diff] [blame] | 147 | int32_t x, y; |
Tiago Vignatti | 491bac1 | 2012-05-18 16:37:43 -0400 | [diff] [blame] | 148 | uint32_t flags; |
Tiago Vignatti | 52e598c | 2012-05-07 15:23:08 +0300 | [diff] [blame] | 149 | } transient; |
| 150 | |
| 151 | struct { |
Alex Wu | 4539b08 | 2012-03-01 12:57:46 +0800 | [diff] [blame] | 152 | enum wl_shell_surface_fullscreen_method type; |
| 153 | struct weston_transform transform; /* matrix from x, y */ |
| 154 | uint32_t framerate; |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 155 | struct weston_view *black_view; |
Alex Wu | 4539b08 | 2012-03-01 12:57:46 +0800 | [diff] [blame] | 156 | } fullscreen; |
| 157 | |
Jonas Ådahl | 62fcd04 | 2012-06-13 00:01:23 +0200 | [diff] [blame] | 158 | struct weston_transform workspace_transform; |
| 159 | |
Kristian Høgsberg | 1cbf326 | 2012-02-17 23:49:07 -0500 | [diff] [blame] | 160 | struct weston_output *fullscreen_output; |
Kristian Høgsberg | 8334bc1 | 2012-01-03 10:29:47 -0500 | [diff] [blame] | 161 | struct weston_output *output; |
Benjamin Franzke | d0f79ab | 2011-11-22 12:43:52 +0100 | [diff] [blame] | 162 | struct wl_list link; |
Kristian Høgsberg | a61ca06 | 2012-05-22 16:05:52 -0400 | [diff] [blame] | 163 | |
| 164 | const struct weston_shell_client *client; |
Rafael Antognolli | 03b1659 | 2013-12-03 15:35:42 -0200 | [diff] [blame] | 165 | |
Jasper St. Pierre | 6458ec3 | 2014-04-11 16:00:31 -0700 | [diff] [blame] | 166 | struct surface_state { |
Rafael Antognolli | 03b1659 | 2013-12-03 15:35:42 -0200 | [diff] [blame] | 167 | bool maximized; |
| 168 | bool fullscreen; |
Rafael Antognolli | ed207b4 | 2013-12-03 15:35:43 -0200 | [diff] [blame] | 169 | bool relative; |
Emilio Pozuelo Monfort | 9e7c759 | 2014-01-30 14:01:10 +0100 | [diff] [blame] | 170 | bool lowered; |
Jasper St. Pierre | 8c6aa45 | 2014-02-08 18:29:49 -0500 | [diff] [blame] | 171 | } state, next_state, requested_state; /* surface states */ |
Rafael Antognolli | 03b1659 | 2013-12-03 15:35:42 -0200 | [diff] [blame] | 172 | bool state_changed; |
Jasper St. Pierre | 8c6aa45 | 2014-02-08 18:29:49 -0500 | [diff] [blame] | 173 | bool state_requested; |
Jasper St. Pierre | faf27a9 | 2013-12-09 17:36:28 -0500 | [diff] [blame] | 174 | |
Kristian Høgsberg | ae356ae | 2014-04-29 16:03:54 -0700 | [diff] [blame] | 175 | struct { |
Jasper St. Pierre | ccf48fb | 2014-05-02 10:21:38 -0400 | [diff] [blame] | 176 | int32_t x, y, width, height; |
| 177 | } geometry, next_geometry; |
| 178 | bool has_set_geometry, has_next_geometry; |
Kristian Høgsberg | ae356ae | 2014-04-29 16:03:54 -0700 | [diff] [blame] | 179 | |
Jasper St. Pierre | faf27a9 | 2013-12-09 17:36:28 -0500 | [diff] [blame] | 180 | int focus_count; |
Derek Foreman | 039e9be | 2015-04-14 17:09:06 -0500 | [diff] [blame] | 181 | |
| 182 | bool destroying; |
Pekka Paalanen | 56cdea9 | 2011-11-23 16:14:12 +0200 | [diff] [blame] | 183 | }; |
| 184 | |
Ander Conselvan de Oliveira | fe0444a | 2012-04-04 17:48:05 +0300 | [diff] [blame] | 185 | struct shell_grab { |
Kristian Høgsberg | 02bbabb | 2013-05-06 22:15:05 -0400 | [diff] [blame] | 186 | struct weston_pointer_grab grab; |
Ander Conselvan de Oliveira | fe0444a | 2012-04-04 17:48:05 +0300 | [diff] [blame] | 187 | struct shell_surface *shsurf; |
| 188 | struct wl_listener shsurf_destroy_listener; |
| 189 | }; |
| 190 | |
Rusty Lynch | 1084da5 | 2013-08-15 09:10:08 -0700 | [diff] [blame] | 191 | struct shell_touch_grab { |
| 192 | struct weston_touch_grab grab; |
| 193 | struct shell_surface *shsurf; |
| 194 | struct wl_listener shsurf_destroy_listener; |
| 195 | struct weston_touch *touch; |
| 196 | }; |
| 197 | |
Ander Conselvan de Oliveira | fe0444a | 2012-04-04 17:48:05 +0300 | [diff] [blame] | 198 | struct weston_move_grab { |
| 199 | struct shell_grab base; |
Daniel Stone | 103db7f | 2012-05-08 17:17:55 +0100 | [diff] [blame] | 200 | wl_fixed_t dx, dy; |
Derek Foreman | cf7d95a | 2015-06-03 15:53:22 -0500 | [diff] [blame] | 201 | bool client_initiated; |
Kristian Høgsberg | 4cca349 | 2011-01-18 07:53:49 -0500 | [diff] [blame] | 202 | }; |
| 203 | |
Rusty Lynch | 1084da5 | 2013-08-15 09:10:08 -0700 | [diff] [blame] | 204 | struct weston_touch_move_grab { |
| 205 | struct shell_touch_grab base; |
Kristian Høgsberg | 8e80a31 | 2014-01-17 15:18:10 -0800 | [diff] [blame] | 206 | int active; |
Rusty Lynch | 1084da5 | 2013-08-15 09:10:08 -0700 | [diff] [blame] | 207 | wl_fixed_t dx, dy; |
| 208 | }; |
| 209 | |
Pekka Paalanen | 460099f | 2012-01-20 16:48:25 +0200 | [diff] [blame] | 210 | struct rotate_grab { |
Ander Conselvan de Oliveira | fe0444a | 2012-04-04 17:48:05 +0300 | [diff] [blame] | 211 | struct shell_grab base; |
Kristian Høgsberg | 765e27b | 2012-01-27 13:36:13 -0500 | [diff] [blame] | 212 | struct weston_matrix rotation; |
Pekka Paalanen | 460099f | 2012-01-20 16:48:25 +0200 | [diff] [blame] | 213 | struct { |
John Kåre Alsaker | 490d02a | 2012-09-30 02:57:21 +0200 | [diff] [blame] | 214 | float x; |
| 215 | float y; |
Pekka Paalanen | 460099f | 2012-01-20 16:48:25 +0200 | [diff] [blame] | 216 | } center; |
| 217 | }; |
| 218 | |
Giulio Camuffo | 5085a75 | 2013-03-25 21:42:45 +0100 | [diff] [blame] | 219 | struct shell_seat { |
| 220 | struct weston_seat *seat; |
| 221 | struct wl_listener seat_destroy_listener; |
Jasper St. Pierre | faf27a9 | 2013-12-09 17:36:28 -0500 | [diff] [blame] | 222 | struct weston_surface *focused_surface; |
Giulio Camuffo | 5085a75 | 2013-03-25 21:42:45 +0100 | [diff] [blame] | 223 | |
Jason Ekstrand | 024177c | 2014-04-21 19:42:58 -0500 | [diff] [blame] | 224 | struct wl_listener caps_changed_listener; |
| 225 | struct wl_listener pointer_focus_listener; |
| 226 | struct wl_listener keyboard_focus_listener; |
| 227 | |
Giulio Camuffo | 5085a75 | 2013-03-25 21:42:45 +0100 | [diff] [blame] | 228 | struct { |
Kristian Høgsberg | 02bbabb | 2013-05-06 22:15:05 -0400 | [diff] [blame] | 229 | struct weston_pointer_grab grab; |
Jonny Lamb | 76cf1fe | 2014-08-20 11:27:10 +0200 | [diff] [blame] | 230 | struct weston_touch_grab touch_grab; |
Giulio Camuffo | 5085a75 | 2013-03-25 21:42:45 +0100 | [diff] [blame] | 231 | struct wl_list surfaces_list; |
| 232 | struct wl_client *client; |
| 233 | int32_t initial_up; |
Jonny Lamb | 76cf1fe | 2014-08-20 11:27:10 +0200 | [diff] [blame] | 234 | enum { POINTER, TOUCH } type; |
Giulio Camuffo | 5085a75 | 2013-03-25 21:42:45 +0100 | [diff] [blame] | 235 | } popup_grab; |
| 236 | }; |
| 237 | |
Kristian Høgsberg | 2bff94e | 2014-02-11 12:22:51 -0800 | [diff] [blame] | 238 | struct shell_client { |
| 239 | struct wl_resource *resource; |
| 240 | struct wl_client *client; |
| 241 | struct desktop_shell *shell; |
| 242 | struct wl_listener destroy_listener; |
| 243 | struct wl_event_source *ping_timer; |
| 244 | uint32_t ping_serial; |
| 245 | int unresponsive; |
Jonas Ådahl | 49d77d2 | 2015-03-18 16:20:51 +0800 | [diff] [blame] | 246 | struct wl_list surface_list; |
Kristian Høgsberg | 2bff94e | 2014-02-11 12:22:51 -0800 | [diff] [blame] | 247 | }; |
| 248 | |
Alex Wu | bd3354b | 2012-04-17 17:20:49 +0800 | [diff] [blame] | 249 | static struct desktop_shell * |
| 250 | shell_surface_get_shell(struct shell_surface *shsurf); |
| 251 | |
Kristian Høgsberg | 0c36903 | 2013-02-14 21:31:44 -0500 | [diff] [blame] | 252 | static void |
Derek Foreman | 74de469 | 2015-07-15 13:00:39 -0500 | [diff] [blame] | 253 | surface_rotate(struct shell_surface *surface, struct weston_pointer *pointer); |
Kristian Høgsberg | 0c36903 | 2013-02-14 21:31:44 -0500 | [diff] [blame] | 254 | |
Pekka Paalanen | 79346ab | 2013-05-22 18:03:09 +0300 | [diff] [blame] | 255 | static void |
| 256 | shell_fade_startup(struct desktop_shell *shell); |
| 257 | |
Philip Withnall | becb77e | 2013-11-25 18:01:30 +0000 | [diff] [blame] | 258 | static struct shell_seat * |
| 259 | get_shell_seat(struct weston_seat *seat); |
| 260 | |
Jonny Lamb | d73c694 | 2014-08-20 15:53:20 +0200 | [diff] [blame] | 261 | static void |
| 262 | get_output_panel_size(struct desktop_shell *shell, |
| 263 | struct weston_output *output, |
| 264 | int *width, int *height); |
Kristian Høgsberg | ae356ae | 2014-04-29 16:03:54 -0700 | [diff] [blame] | 265 | |
Philip Withnall | 648a4dd | 2013-11-25 18:01:44 +0000 | [diff] [blame] | 266 | static void |
| 267 | shell_surface_update_child_surface_layers(struct shell_surface *shsurf); |
| 268 | |
Alex Wu | bd3354b | 2012-04-17 17:20:49 +0800 | [diff] [blame] | 269 | static bool |
Rafael Antognolli | e2a3455 | 2013-12-03 15:35:45 -0200 | [diff] [blame] | 270 | shell_surface_is_wl_shell_surface(struct shell_surface *shsurf); |
| 271 | |
| 272 | static bool |
| 273 | shell_surface_is_xdg_surface(struct shell_surface *shsurf); |
| 274 | |
| 275 | static bool |
| 276 | shell_surface_is_xdg_popup(struct shell_surface *shsurf); |
| 277 | |
| 278 | static void |
| 279 | shell_surface_set_parent(struct shell_surface *shsurf, |
| 280 | struct weston_surface *parent); |
| 281 | |
Pekka Paalanen | 8274d90 | 2014-08-06 19:36:51 +0300 | [diff] [blame] | 282 | static int |
| 283 | shell_surface_get_label(struct weston_surface *surface, char *buf, size_t len) |
| 284 | { |
| 285 | struct shell_surface *shsurf; |
| 286 | const char *typestr[] = { |
| 287 | [SHELL_SURFACE_NONE] = "unidentified", |
| 288 | [SHELL_SURFACE_TOPLEVEL] = "top-level", |
| 289 | [SHELL_SURFACE_POPUP] = "popup", |
| 290 | [SHELL_SURFACE_XWAYLAND] = "Xwayland", |
| 291 | }; |
| 292 | const char *t, *c; |
| 293 | |
| 294 | shsurf = get_shell_surface(surface); |
| 295 | if (!shsurf) |
| 296 | return snprintf(buf, len, "unidentified window"); |
| 297 | |
| 298 | t = shsurf->title; |
| 299 | c = shsurf->class; |
| 300 | |
| 301 | return snprintf(buf, len, "%s window%s%s%s%s%s", |
| 302 | typestr[shsurf->type], |
| 303 | t ? " '" : "", t ?: "", t ? "'" : "", |
| 304 | c ? " of " : "", c ?: ""); |
| 305 | } |
| 306 | |
Rafael Antognolli | e2a3455 | 2013-12-03 15:35:45 -0200 | [diff] [blame] | 307 | static bool |
Alex Wu | bd3354b | 2012-04-17 17:20:49 +0800 | [diff] [blame] | 308 | shell_surface_is_top_fullscreen(struct shell_surface *shsurf) |
| 309 | { |
| 310 | struct desktop_shell *shell; |
Mario Kleiner | 9f4d655 | 2015-06-21 21:25:08 +0200 | [diff] [blame] | 311 | struct weston_view *view; |
| 312 | struct shell_surface *top_fs_shsurf = NULL; |
Alex Wu | bd3354b | 2012-04-17 17:20:49 +0800 | [diff] [blame] | 313 | |
| 314 | shell = shell_surface_get_shell(shsurf); |
Quentin Glidic | c0d79ce | 2013-01-29 14:16:13 +0100 | [diff] [blame] | 315 | |
Giulio Camuffo | 412e6a5 | 2014-07-09 22:12:56 +0300 | [diff] [blame] | 316 | if (wl_list_empty(&shell->fullscreen_layer.view_list.link)) |
Alex Wu | bd3354b | 2012-04-17 17:20:49 +0800 | [diff] [blame] | 317 | return false; |
| 318 | |
Mario Kleiner | 9f4d655 | 2015-06-21 21:25:08 +0200 | [diff] [blame] | 319 | /* Find topmost shsurf on the same fullscreen output on which shsurf |
| 320 | * is displaying. We don't care about other outputs. |
| 321 | */ |
| 322 | wl_list_for_each(view, &shell->fullscreen_layer.view_list.link, |
| 323 | layer_link.link) { |
| 324 | struct shell_surface *cand_shsurf = get_shell_surface(view->surface); |
| 325 | |
| 326 | if (cand_shsurf && |
| 327 | (cand_shsurf->fullscreen_output == shsurf->fullscreen_output)) { |
| 328 | top_fs_shsurf = cand_shsurf; |
| 329 | break; |
| 330 | } |
| 331 | } |
| 332 | |
| 333 | return (shsurf == top_fs_shsurf); |
Alex Wu | bd3354b | 2012-04-17 17:20:49 +0800 | [diff] [blame] | 334 | } |
| 335 | |
Kristian Høgsberg | 6af8eb9 | 2012-01-25 16:57:11 -0500 | [diff] [blame] | 336 | static void |
Kristian Høgsberg | 27e3052 | 2012-04-11 23:18:23 -0400 | [diff] [blame] | 337 | destroy_shell_grab_shsurf(struct wl_listener *listener, void *data) |
Ander Conselvan de Oliveira | fe0444a | 2012-04-04 17:48:05 +0300 | [diff] [blame] | 338 | { |
| 339 | struct shell_grab *grab; |
| 340 | |
| 341 | grab = container_of(listener, struct shell_grab, |
| 342 | shsurf_destroy_listener); |
| 343 | |
| 344 | grab->shsurf = NULL; |
| 345 | } |
| 346 | |
Kristian Høgsberg | 1ef2313 | 2013-12-04 00:20:01 -0800 | [diff] [blame] | 347 | struct weston_view * |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 348 | get_default_view(struct weston_surface *surface) |
| 349 | { |
| 350 | struct shell_surface *shsurf; |
| 351 | struct weston_view *view; |
| 352 | |
| 353 | if (!surface || wl_list_empty(&surface->views)) |
| 354 | return NULL; |
| 355 | |
| 356 | shsurf = get_shell_surface(surface); |
| 357 | if (shsurf) |
| 358 | return shsurf->view; |
| 359 | |
| 360 | wl_list_for_each(view, &surface->views, surface_link) |
| 361 | if (weston_view_is_mapped(view)) |
| 362 | return view; |
| 363 | |
| 364 | return container_of(surface->views.next, struct weston_view, surface_link); |
| 365 | } |
| 366 | |
Ander Conselvan de Oliveira | fe0444a | 2012-04-04 17:48:05 +0300 | [diff] [blame] | 367 | static void |
Kristian Høgsberg | 02bbabb | 2013-05-06 22:15:05 -0400 | [diff] [blame] | 368 | popup_grab_end(struct weston_pointer *pointer); |
Jonny Lamb | 76cf1fe | 2014-08-20 11:27:10 +0200 | [diff] [blame] | 369 | static void |
| 370 | touch_popup_grab_end(struct weston_touch *touch); |
Kristian Høgsberg | 57e0907 | 2012-10-30 14:07:27 -0400 | [diff] [blame] | 371 | |
| 372 | static void |
Ander Conselvan de Oliveira | b9d2a0f | 2012-06-28 18:08:05 +0300 | [diff] [blame] | 373 | shell_grab_start(struct shell_grab *grab, |
Kristian Høgsberg | 02bbabb | 2013-05-06 22:15:05 -0400 | [diff] [blame] | 374 | const struct weston_pointer_grab_interface *interface, |
Ander Conselvan de Oliveira | b9d2a0f | 2012-06-28 18:08:05 +0300 | [diff] [blame] | 375 | struct shell_surface *shsurf, |
Kristian Høgsberg | 02bbabb | 2013-05-06 22:15:05 -0400 | [diff] [blame] | 376 | struct weston_pointer *pointer, |
Jonas Ådahl | 6d6fb61 | 2015-11-17 16:00:33 +0800 | [diff] [blame] | 377 | enum weston_desktop_shell_cursor cursor) |
Ander Conselvan de Oliveira | fe0444a | 2012-04-04 17:48:05 +0300 | [diff] [blame] | 378 | { |
Ander Conselvan de Oliveira | b9d2a0f | 2012-06-28 18:08:05 +0300 | [diff] [blame] | 379 | struct desktop_shell *shell = shsurf->shell; |
Derek Foreman | 1281a36 | 2015-07-31 16:55:32 -0500 | [diff] [blame] | 380 | struct weston_touch *touch = weston_seat_get_touch(pointer->seat); |
Ander Conselvan de Oliveira | b9d2a0f | 2012-06-28 18:08:05 +0300 | [diff] [blame] | 381 | |
Kristian Høgsberg | 57e0907 | 2012-10-30 14:07:27 -0400 | [diff] [blame] | 382 | popup_grab_end(pointer); |
Derek Foreman | 1281a36 | 2015-07-31 16:55:32 -0500 | [diff] [blame] | 383 | if (touch) |
| 384 | touch_popup_grab_end(touch); |
Kristian Høgsberg | 57e0907 | 2012-10-30 14:07:27 -0400 | [diff] [blame] | 385 | |
Ander Conselvan de Oliveira | fe0444a | 2012-04-04 17:48:05 +0300 | [diff] [blame] | 386 | grab->grab.interface = interface; |
| 387 | grab->shsurf = shsurf; |
Kristian Høgsberg | 27e3052 | 2012-04-11 23:18:23 -0400 | [diff] [blame] | 388 | grab->shsurf_destroy_listener.notify = destroy_shell_grab_shsurf; |
Jason Ekstrand | 651f00e | 2013-06-14 10:07:54 -0500 | [diff] [blame] | 389 | wl_signal_add(&shsurf->destroy_signal, |
Kristian Høgsberg | 27e3052 | 2012-04-11 23:18:23 -0400 | [diff] [blame] | 390 | &grab->shsurf_destroy_listener); |
Ander Conselvan de Oliveira | fe0444a | 2012-04-04 17:48:05 +0300 | [diff] [blame] | 391 | |
Kristian Høgsberg | c85f1d4 | 2013-10-24 16:52:00 -0700 | [diff] [blame] | 392 | shsurf->grabbed = 1; |
Kristian Høgsberg | 02bbabb | 2013-05-06 22:15:05 -0400 | [diff] [blame] | 393 | weston_pointer_start_grab(pointer, &grab->grab); |
Kristian Høgsberg | c9974a0 | 2013-07-03 19:24:57 -0400 | [diff] [blame] | 394 | if (shell->child.desktop_shell) { |
Jonas Ådahl | 6d6fb61 | 2015-11-17 16:00:33 +0800 | [diff] [blame] | 395 | weston_desktop_shell_send_grab_cursor(shell->child.desktop_shell, |
Kristian Høgsberg | c9974a0 | 2013-07-03 19:24:57 -0400 | [diff] [blame] | 396 | cursor); |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 397 | weston_pointer_set_focus(pointer, |
| 398 | get_default_view(shell->grab_surface), |
Kristian Høgsberg | c9974a0 | 2013-07-03 19:24:57 -0400 | [diff] [blame] | 399 | wl_fixed_from_int(0), |
| 400 | wl_fixed_from_int(0)); |
| 401 | } |
Ander Conselvan de Oliveira | fe0444a | 2012-04-04 17:48:05 +0300 | [diff] [blame] | 402 | } |
| 403 | |
Jonny Lamb | d73c694 | 2014-08-20 15:53:20 +0200 | [diff] [blame] | 404 | static void |
| 405 | get_output_panel_size(struct desktop_shell *shell, |
| 406 | struct weston_output *output, |
| 407 | int *width, |
| 408 | int *height) |
Jasper St. Pierre | 6458ec3 | 2014-04-11 16:00:31 -0700 | [diff] [blame] | 409 | { |
| 410 | struct weston_view *view; |
Jonny Lamb | d73c694 | 2014-08-20 15:53:20 +0200 | [diff] [blame] | 411 | |
| 412 | *width = 0; |
| 413 | *height = 0; |
Jasper St. Pierre | 6458ec3 | 2014-04-11 16:00:31 -0700 | [diff] [blame] | 414 | |
| 415 | if (!output) |
Jonny Lamb | d73c694 | 2014-08-20 15:53:20 +0200 | [diff] [blame] | 416 | return; |
Jasper St. Pierre | 6458ec3 | 2014-04-11 16:00:31 -0700 | [diff] [blame] | 417 | |
Giulio Camuffo | 412e6a5 | 2014-07-09 22:12:56 +0300 | [diff] [blame] | 418 | wl_list_for_each(view, &shell->panel_layer.view_list.link, layer_link.link) { |
Jonny Lamb | d73c694 | 2014-08-20 15:53:20 +0200 | [diff] [blame] | 419 | float x, y; |
| 420 | |
| 421 | if (view->surface->output != output) |
| 422 | continue; |
| 423 | |
| 424 | switch (shell->panel_position) { |
Jonas Ådahl | 6d6fb61 | 2015-11-17 16:00:33 +0800 | [diff] [blame] | 425 | case WESTON_DESKTOP_SHELL_PANEL_POSITION_TOP: |
| 426 | case WESTON_DESKTOP_SHELL_PANEL_POSITION_BOTTOM: |
Jonny Lamb | d73c694 | 2014-08-20 15:53:20 +0200 | [diff] [blame] | 427 | weston_view_to_global_float(view, |
| 428 | view->surface->width, 0, |
| 429 | &x, &y); |
| 430 | |
Derek Foreman | 612341f | 2015-04-15 12:23:55 -0500 | [diff] [blame] | 431 | *width = (int)x - output->x; |
| 432 | *height = view->surface->height + (int) y - output->y; |
Jonny Lamb | d73c694 | 2014-08-20 15:53:20 +0200 | [diff] [blame] | 433 | return; |
| 434 | |
Jonas Ådahl | 6d6fb61 | 2015-11-17 16:00:33 +0800 | [diff] [blame] | 435 | case WESTON_DESKTOP_SHELL_PANEL_POSITION_LEFT: |
| 436 | case WESTON_DESKTOP_SHELL_PANEL_POSITION_RIGHT: |
Jonny Lamb | d73c694 | 2014-08-20 15:53:20 +0200 | [diff] [blame] | 437 | weston_view_to_global_float(view, |
| 438 | 0, view->surface->height, |
| 439 | &x, &y); |
| 440 | |
Derek Foreman | 612341f | 2015-04-15 12:23:55 -0500 | [diff] [blame] | 441 | *width = view->surface->width + (int)x - output->x; |
| 442 | *height = (int)y - output->y; |
Jonny Lamb | d73c694 | 2014-08-20 15:53:20 +0200 | [diff] [blame] | 443 | return; |
| 444 | |
| 445 | default: |
| 446 | /* we've already set width and height to |
| 447 | * fallback values. */ |
Jasper St. Pierre | 6458ec3 | 2014-04-11 16:00:31 -0700 | [diff] [blame] | 448 | break; |
| 449 | } |
| 450 | } |
| 451 | |
Jonny Lamb | d73c694 | 2014-08-20 15:53:20 +0200 | [diff] [blame] | 452 | /* the correct view wasn't found */ |
| 453 | } |
| 454 | |
| 455 | static void |
| 456 | get_output_work_area(struct desktop_shell *shell, |
| 457 | struct weston_output *output, |
| 458 | pixman_rectangle32_t *area) |
| 459 | { |
| 460 | int32_t panel_width = 0, panel_height = 0; |
| 461 | |
Derek Foreman | f814c5d | 2015-04-15 12:23:54 -0500 | [diff] [blame] | 462 | area->x = output->x; |
| 463 | area->y = output->y; |
Jonny Lamb | d73c694 | 2014-08-20 15:53:20 +0200 | [diff] [blame] | 464 | |
| 465 | get_output_panel_size(shell, output, &panel_width, &panel_height); |
Jonny Lamb | d73c694 | 2014-08-20 15:53:20 +0200 | [diff] [blame] | 466 | switch (shell->panel_position) { |
Jonas Ådahl | 6d6fb61 | 2015-11-17 16:00:33 +0800 | [diff] [blame] | 467 | case WESTON_DESKTOP_SHELL_PANEL_POSITION_TOP: |
Jonny Lamb | d73c694 | 2014-08-20 15:53:20 +0200 | [diff] [blame] | 468 | default: |
Derek Foreman | f814c5d | 2015-04-15 12:23:54 -0500 | [diff] [blame] | 469 | area->y += panel_height; |
Jonas Ådahl | 6d6fb61 | 2015-11-17 16:00:33 +0800 | [diff] [blame] | 470 | case WESTON_DESKTOP_SHELL_PANEL_POSITION_BOTTOM: |
Jonny Lamb | d73c694 | 2014-08-20 15:53:20 +0200 | [diff] [blame] | 471 | area->width = output->width; |
| 472 | area->height = output->height - panel_height; |
| 473 | break; |
Jonas Ådahl | 6d6fb61 | 2015-11-17 16:00:33 +0800 | [diff] [blame] | 474 | case WESTON_DESKTOP_SHELL_PANEL_POSITION_LEFT: |
Derek Foreman | f814c5d | 2015-04-15 12:23:54 -0500 | [diff] [blame] | 475 | area->x += panel_width; |
Jonas Ådahl | 6d6fb61 | 2015-11-17 16:00:33 +0800 | [diff] [blame] | 476 | case WESTON_DESKTOP_SHELL_PANEL_POSITION_RIGHT: |
Jonny Lamb | d73c694 | 2014-08-20 15:53:20 +0200 | [diff] [blame] | 477 | area->width = output->width - panel_width; |
| 478 | area->height = output->height; |
| 479 | break; |
| 480 | } |
Jasper St. Pierre | 6458ec3 | 2014-04-11 16:00:31 -0700 | [diff] [blame] | 481 | } |
| 482 | |
Derek Foreman | 45a7c27 | 2015-09-11 14:27:40 -0500 | [diff] [blame] | 483 | static struct shell_surface * |
| 484 | find_toplevel_surface(struct shell_surface *in_surface) |
| 485 | { |
| 486 | struct shell_surface *surface = in_surface; |
| 487 | |
Ben Hummon | 445e44c | 2015-10-06 11:48:14 -0500 | [diff] [blame] | 488 | while (surface) { |
| 489 | if (surface->type == SHELL_SURFACE_TOPLEVEL) |
| 490 | return surface; |
Derek Foreman | 45a7c27 | 2015-09-11 14:27:40 -0500 | [diff] [blame] | 491 | surface = get_shell_surface(surface->parent); |
Ben Hummon | 445e44c | 2015-10-06 11:48:14 -0500 | [diff] [blame] | 492 | } |
Derek Foreman | 45a7c27 | 2015-09-11 14:27:40 -0500 | [diff] [blame] | 493 | |
| 494 | /* If no top level surface was found, just use whatever surface was |
| 495 | originally provided. */ |
Ben Hummon | 445e44c | 2015-10-06 11:48:14 -0500 | [diff] [blame] | 496 | return in_surface; |
Derek Foreman | 45a7c27 | 2015-09-11 14:27:40 -0500 | [diff] [blame] | 497 | } |
| 498 | |
Jasper St. Pierre | 6458ec3 | 2014-04-11 16:00:31 -0700 | [diff] [blame] | 499 | static void |
| 500 | send_configure_for_surface(struct shell_surface *shsurf) |
| 501 | { |
| 502 | int32_t width, height; |
| 503 | struct surface_state *state; |
| 504 | |
| 505 | if (shsurf->state_requested) |
| 506 | state = &shsurf->requested_state; |
| 507 | else if (shsurf->state_changed) |
| 508 | state = &shsurf->next_state; |
| 509 | else |
| 510 | state = &shsurf->state; |
| 511 | |
| 512 | if (state->fullscreen) { |
| 513 | width = shsurf->output->width; |
| 514 | height = shsurf->output->height; |
| 515 | } else if (state->maximized) { |
| 516 | struct desktop_shell *shell; |
Jonny Lamb | d73c694 | 2014-08-20 15:53:20 +0200 | [diff] [blame] | 517 | pixman_rectangle32_t area; |
Jasper St. Pierre | 6458ec3 | 2014-04-11 16:00:31 -0700 | [diff] [blame] | 518 | |
| 519 | shell = shell_surface_get_shell(shsurf); |
Jonny Lamb | d73c694 | 2014-08-20 15:53:20 +0200 | [diff] [blame] | 520 | get_output_work_area(shell, shsurf->output, &area); |
Jasper St. Pierre | 6458ec3 | 2014-04-11 16:00:31 -0700 | [diff] [blame] | 521 | |
Jonny Lamb | d73c694 | 2014-08-20 15:53:20 +0200 | [diff] [blame] | 522 | width = area.width; |
| 523 | height = area.height; |
Ryo Munakata | 79954ec | 2015-05-02 21:44:04 +0900 | [diff] [blame] | 524 | } else if (shsurf->resize_edges) { |
| 525 | width = shsurf->geometry.width; |
| 526 | height = shsurf->geometry.height; |
Jasper St. Pierre | 6458ec3 | 2014-04-11 16:00:31 -0700 | [diff] [blame] | 527 | } else { |
| 528 | width = 0; |
| 529 | height = 0; |
| 530 | } |
| 531 | |
| 532 | shsurf->client->send_configure(shsurf->surface, width, height); |
| 533 | } |
| 534 | |
Ander Conselvan de Oliveira | fe0444a | 2012-04-04 17:48:05 +0300 | [diff] [blame] | 535 | static void |
Jasper St. Pierre | 5befdda | 2014-05-06 08:50:47 -0400 | [diff] [blame] | 536 | shell_surface_state_changed(struct shell_surface *shsurf) |
| 537 | { |
Jasper St. Pierre | 6458ec3 | 2014-04-11 16:00:31 -0700 | [diff] [blame] | 538 | if (shell_surface_is_xdg_surface(shsurf)) |
| 539 | send_configure_for_surface(shsurf); |
Jasper St. Pierre | 5befdda | 2014-05-06 08:50:47 -0400 | [diff] [blame] | 540 | } |
| 541 | |
| 542 | static void |
Ander Conselvan de Oliveira | b9d2a0f | 2012-06-28 18:08:05 +0300 | [diff] [blame] | 543 | shell_grab_end(struct shell_grab *grab) |
Ander Conselvan de Oliveira | fe0444a | 2012-04-04 17:48:05 +0300 | [diff] [blame] | 544 | { |
Kristian Høgsberg | c85f1d4 | 2013-10-24 16:52:00 -0700 | [diff] [blame] | 545 | if (grab->shsurf) { |
Kristian Høgsberg | 47b5dca | 2012-06-07 18:08:04 -0400 | [diff] [blame] | 546 | wl_list_remove(&grab->shsurf_destroy_listener.link); |
Kristian Høgsberg | c85f1d4 | 2013-10-24 16:52:00 -0700 | [diff] [blame] | 547 | grab->shsurf->grabbed = 0; |
Jasper St. Pierre | 5befdda | 2014-05-06 08:50:47 -0400 | [diff] [blame] | 548 | |
| 549 | if (grab->shsurf->resize_edges) { |
| 550 | grab->shsurf->resize_edges = 0; |
| 551 | shell_surface_state_changed(grab->shsurf); |
| 552 | } |
Kristian Høgsberg | c85f1d4 | 2013-10-24 16:52:00 -0700 | [diff] [blame] | 553 | } |
Ander Conselvan de Oliveira | b9d2a0f | 2012-06-28 18:08:05 +0300 | [diff] [blame] | 554 | |
Kristian Høgsberg | 9e5d7d1 | 2013-07-22 16:31:53 -0700 | [diff] [blame] | 555 | weston_pointer_end_grab(grab->grab.pointer); |
Ander Conselvan de Oliveira | fe0444a | 2012-04-04 17:48:05 +0300 | [diff] [blame] | 556 | } |
| 557 | |
| 558 | static void |
Rusty Lynch | 1084da5 | 2013-08-15 09:10:08 -0700 | [diff] [blame] | 559 | shell_touch_grab_start(struct shell_touch_grab *grab, |
| 560 | const struct weston_touch_grab_interface *interface, |
| 561 | struct shell_surface *shsurf, |
| 562 | struct weston_touch *touch) |
| 563 | { |
| 564 | struct desktop_shell *shell = shsurf->shell; |
Derek Foreman | 1281a36 | 2015-07-31 16:55:32 -0500 | [diff] [blame] | 565 | struct weston_pointer *pointer = weston_seat_get_pointer(touch->seat); |
U. Artie Eoff | cf5737a | 2014-01-17 10:08:25 -0800 | [diff] [blame] | 566 | |
Jonny Lamb | 76cf1fe | 2014-08-20 11:27:10 +0200 | [diff] [blame] | 567 | touch_popup_grab_end(touch); |
Derek Foreman | 1281a36 | 2015-07-31 16:55:32 -0500 | [diff] [blame] | 568 | if (pointer) |
| 569 | popup_grab_end(pointer); |
Kristian Høgsberg | 74071e0 | 2014-04-29 15:01:16 -0700 | [diff] [blame] | 570 | |
Rusty Lynch | 1084da5 | 2013-08-15 09:10:08 -0700 | [diff] [blame] | 571 | grab->grab.interface = interface; |
| 572 | grab->shsurf = shsurf; |
| 573 | grab->shsurf_destroy_listener.notify = destroy_shell_grab_shsurf; |
| 574 | wl_signal_add(&shsurf->destroy_signal, |
| 575 | &grab->shsurf_destroy_listener); |
| 576 | |
| 577 | grab->touch = touch; |
Kristian Høgsberg | c85f1d4 | 2013-10-24 16:52:00 -0700 | [diff] [blame] | 578 | shsurf->grabbed = 1; |
Rusty Lynch | 1084da5 | 2013-08-15 09:10:08 -0700 | [diff] [blame] | 579 | |
| 580 | weston_touch_start_grab(touch, &grab->grab); |
| 581 | if (shell->child.desktop_shell) |
Derek Foreman | 4c93c08 | 2015-04-30 16:45:41 -0500 | [diff] [blame] | 582 | weston_touch_set_focus(touch, |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 583 | get_default_view(shell->grab_surface)); |
Rusty Lynch | 1084da5 | 2013-08-15 09:10:08 -0700 | [diff] [blame] | 584 | } |
| 585 | |
| 586 | static void |
| 587 | shell_touch_grab_end(struct shell_touch_grab *grab) |
| 588 | { |
Kristian Høgsberg | c85f1d4 | 2013-10-24 16:52:00 -0700 | [diff] [blame] | 589 | if (grab->shsurf) { |
Rusty Lynch | 1084da5 | 2013-08-15 09:10:08 -0700 | [diff] [blame] | 590 | wl_list_remove(&grab->shsurf_destroy_listener.link); |
Kristian Høgsberg | c85f1d4 | 2013-10-24 16:52:00 -0700 | [diff] [blame] | 591 | grab->shsurf->grabbed = 0; |
| 592 | } |
Rusty Lynch | 1084da5 | 2013-08-15 09:10:08 -0700 | [diff] [blame] | 593 | |
| 594 | weston_touch_end_grab(grab->touch); |
| 595 | } |
| 596 | |
| 597 | static void |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 598 | center_on_output(struct weston_view *view, |
Alex Wu | 4539b08 | 2012-03-01 12:57:46 +0800 | [diff] [blame] | 599 | struct weston_output *output); |
| 600 | |
Daniel Stone | 496ca17 | 2012-05-30 16:31:42 +0100 | [diff] [blame] | 601 | static enum weston_keyboard_modifier |
Tiago Vignatti | 0b52d48 | 2012-04-20 18:54:25 +0300 | [diff] [blame] | 602 | get_modifier(char *modifier) |
| 603 | { |
| 604 | if (!modifier) |
| 605 | return MODIFIER_SUPER; |
| 606 | |
| 607 | if (!strcmp("ctrl", modifier)) |
| 608 | return MODIFIER_CTRL; |
| 609 | else if (!strcmp("alt", modifier)) |
| 610 | return MODIFIER_ALT; |
| 611 | else if (!strcmp("super", modifier)) |
| 612 | return MODIFIER_SUPER; |
Bob Ham | 553d124 | 2016-01-12 10:21:49 +0000 | [diff] [blame^] | 613 | else if (!strcmp("none", modifier)) |
| 614 | return 0; |
Tiago Vignatti | 0b52d48 | 2012-04-20 18:54:25 +0300 | [diff] [blame] | 615 | else |
| 616 | return MODIFIER_SUPER; |
| 617 | } |
| 618 | |
Juan Zhao | e10d279 | 2012-04-25 19:09:52 +0800 | [diff] [blame] | 619 | static enum animation_type |
| 620 | get_animation_type(char *animation) |
| 621 | { |
U. Artie Eoff | b571910 | 2014-01-15 14:26:31 -0800 | [diff] [blame] | 622 | if (!animation) |
| 623 | return ANIMATION_NONE; |
| 624 | |
Juan Zhao | e10d279 | 2012-04-25 19:09:52 +0800 | [diff] [blame] | 625 | if (!strcmp("zoom", animation)) |
| 626 | return ANIMATION_ZOOM; |
| 627 | else if (!strcmp("fade", animation)) |
| 628 | return ANIMATION_FADE; |
Louis-Francis Ratté-Boulianne | b482dbd | 2013-11-19 11:37:11 +0100 | [diff] [blame] | 629 | else if (!strcmp("dim-layer", animation)) |
| 630 | return ANIMATION_DIM_LAYER; |
Juan Zhao | e10d279 | 2012-04-25 19:09:52 +0800 | [diff] [blame] | 631 | else |
| 632 | return ANIMATION_NONE; |
| 633 | } |
| 634 | |
Alex Wu | 4539b08 | 2012-03-01 12:57:46 +0800 | [diff] [blame] | 635 | static void |
Kristian Høgsberg | 14e438c | 2013-05-26 21:48:14 -0400 | [diff] [blame] | 636 | shell_configuration(struct desktop_shell *shell) |
Pekka Paalanen | e955f1e | 2011-12-07 11:49:52 +0200 | [diff] [blame] | 637 | { |
Kristian Høgsberg | 673a889 | 2013-05-23 21:40:56 -0400 | [diff] [blame] | 638 | struct weston_config_section *section; |
Derek Foreman | c721043 | 2014-08-21 11:32:38 -0500 | [diff] [blame] | 639 | char *s, *client; |
Pekka Paalanen | 974c094 | 2014-09-05 14:45:09 +0300 | [diff] [blame] | 640 | int ret; |
Bob Ham | 744e653 | 2016-01-12 10:21:48 +0000 | [diff] [blame] | 641 | int allow_zap; |
Pekka Paalanen | e955f1e | 2011-12-07 11:49:52 +0200 | [diff] [blame] | 642 | |
Kristian Høgsberg | 673a889 | 2013-05-23 21:40:56 -0400 | [diff] [blame] | 643 | section = weston_config_get_section(shell->compositor->config, |
Kristian Høgsberg | 673a889 | 2013-05-23 21:40:56 -0400 | [diff] [blame] | 644 | "shell", NULL, NULL); |
Pekka Paalanen | 974c094 | 2014-09-05 14:45:09 +0300 | [diff] [blame] | 645 | ret = asprintf(&client, "%s/%s", weston_config_get_libexec_dir(), |
| 646 | WESTON_SHELL_CLIENT); |
| 647 | if (ret < 0) |
| 648 | client = NULL; |
Kristian Høgsberg | 673a889 | 2013-05-23 21:40:56 -0400 | [diff] [blame] | 649 | weston_config_section_get_string(section, |
Derek Foreman | c721043 | 2014-08-21 11:32:38 -0500 | [diff] [blame] | 650 | "client", &s, client); |
| 651 | free(client); |
Emilio Pozuelo Monfort | 46ce798 | 2013-11-20 13:22:29 +0100 | [diff] [blame] | 652 | shell->client = s; |
Bob Ham | 744e653 | 2016-01-12 10:21:48 +0000 | [diff] [blame] | 653 | |
| 654 | weston_config_section_get_bool(section, |
| 655 | "allow-zap", &allow_zap, true); |
| 656 | shell->allow_zap = allow_zap; |
| 657 | |
Emilio Pozuelo Monfort | 46ce798 | 2013-11-20 13:22:29 +0100 | [diff] [blame] | 658 | weston_config_section_get_string(section, |
Kristian Høgsberg | 673a889 | 2013-05-23 21:40:56 -0400 | [diff] [blame] | 659 | "binding-modifier", &s, "super"); |
| 660 | shell->binding_modifier = get_modifier(s); |
Quentin Glidic | 8418c29 | 2013-06-18 09:11:03 +0200 | [diff] [blame] | 661 | free(s); |
Kristian Høgsberg | d56ab4e | 2014-01-16 16:51:52 -0800 | [diff] [blame] | 662 | |
| 663 | weston_config_section_get_string(section, |
| 664 | "exposay-modifier", &s, "none"); |
Bob Ham | 553d124 | 2016-01-12 10:21:49 +0000 | [diff] [blame^] | 665 | shell->exposay_modifier = get_modifier(s); |
Kristian Høgsberg | d56ab4e | 2014-01-16 16:51:52 -0800 | [diff] [blame] | 666 | free(s); |
| 667 | |
Kristian Høgsberg | 673a889 | 2013-05-23 21:40:56 -0400 | [diff] [blame] | 668 | weston_config_section_get_string(section, "animation", &s, "none"); |
| 669 | shell->win_animation_type = get_animation_type(s); |
Quentin Glidic | 8418c29 | 2013-06-18 09:11:03 +0200 | [diff] [blame] | 670 | free(s); |
Jonny Lamb | f322f8e | 2014-08-12 15:13:30 +0200 | [diff] [blame] | 671 | weston_config_section_get_string(section, "close-animation", &s, "fade"); |
| 672 | shell->win_close_animation_type = get_animation_type(s); |
| 673 | free(s); |
Kristian Høgsberg | 724c8d9 | 2013-10-16 11:38:24 -0700 | [diff] [blame] | 674 | weston_config_section_get_string(section, |
| 675 | "startup-animation", &s, "fade"); |
| 676 | shell->startup_animation_type = get_animation_type(s); |
| 677 | free(s); |
Kristian Høgsberg | 912e0a1 | 2013-10-30 08:59:55 -0700 | [diff] [blame] | 678 | if (shell->startup_animation_type == ANIMATION_ZOOM) |
| 679 | shell->startup_animation_type = ANIMATION_NONE; |
Louis-Francis Ratté-Boulianne | b482dbd | 2013-11-19 11:37:11 +0100 | [diff] [blame] | 680 | weston_config_section_get_string(section, "focus-animation", &s, "none"); |
| 681 | shell->focus_animation_type = get_animation_type(s); |
| 682 | free(s); |
Kristian Høgsberg | 673a889 | 2013-05-23 21:40:56 -0400 | [diff] [blame] | 683 | weston_config_section_get_uint(section, "num-workspaces", |
| 684 | &shell->workspaces.num, |
| 685 | DEFAULT_NUM_WORKSPACES); |
Jonas Ådahl | e3cddce | 2012-06-13 00:01:22 +0200 | [diff] [blame] | 686 | } |
| 687 | |
Kristian Høgsberg | 1ef2313 | 2013-12-04 00:20:01 -0800 | [diff] [blame] | 688 | struct weston_output * |
Louis-Francis Ratté-Boulianne | b482dbd | 2013-11-19 11:37:11 +0100 | [diff] [blame] | 689 | get_default_output(struct weston_compositor *compositor) |
| 690 | { |
| 691 | return container_of(compositor->output_list.next, |
| 692 | struct weston_output, link); |
| 693 | } |
| 694 | |
Pekka Paalanen | 8274d90 | 2014-08-06 19:36:51 +0300 | [diff] [blame] | 695 | static int |
| 696 | focus_surface_get_label(struct weston_surface *surface, char *buf, size_t len) |
| 697 | { |
| 698 | return snprintf(buf, len, "focus highlight effect for output %s", |
| 699 | surface->output->name); |
| 700 | } |
Louis-Francis Ratté-Boulianne | b482dbd | 2013-11-19 11:37:11 +0100 | [diff] [blame] | 701 | |
| 702 | /* no-op func for checking focus surface */ |
| 703 | static void |
Jason Ekstrand | 918f2dd | 2013-12-02 21:01:53 -0600 | [diff] [blame] | 704 | 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] | 705 | { |
| 706 | } |
| 707 | |
| 708 | static struct focus_surface * |
| 709 | get_focus_surface(struct weston_surface *surface) |
| 710 | { |
| 711 | if (surface->configure == focus_surface_configure) |
| 712 | return surface->configure_private; |
| 713 | else |
| 714 | return NULL; |
| 715 | } |
| 716 | |
| 717 | static bool |
| 718 | is_focus_surface (struct weston_surface *es) |
| 719 | { |
| 720 | return (es->configure == focus_surface_configure); |
| 721 | } |
| 722 | |
| 723 | static bool |
| 724 | is_focus_view (struct weston_view *view) |
| 725 | { |
| 726 | return is_focus_surface (view->surface); |
| 727 | } |
| 728 | |
| 729 | static struct focus_surface * |
| 730 | create_focus_surface(struct weston_compositor *ec, |
| 731 | struct weston_output *output) |
| 732 | { |
| 733 | struct focus_surface *fsurf = NULL; |
| 734 | struct weston_surface *surface = NULL; |
| 735 | |
| 736 | fsurf = malloc(sizeof *fsurf); |
| 737 | if (!fsurf) |
| 738 | return NULL; |
| 739 | |
| 740 | fsurf->surface = weston_surface_create(ec); |
| 741 | surface = fsurf->surface; |
| 742 | if (surface == NULL) { |
| 743 | free(fsurf); |
| 744 | return NULL; |
| 745 | } |
| 746 | |
| 747 | surface->configure = focus_surface_configure; |
| 748 | surface->output = output; |
| 749 | surface->configure_private = fsurf; |
Pekka Paalanen | 8274d90 | 2014-08-06 19:36:51 +0300 | [diff] [blame] | 750 | weston_surface_set_label_func(surface, focus_surface_get_label); |
Louis-Francis Ratté-Boulianne | b482dbd | 2013-11-19 11:37:11 +0100 | [diff] [blame] | 751 | |
U. Artie Eoff | 0b23b2b | 2014-01-15 14:45:59 -0800 | [diff] [blame] | 752 | fsurf->view = weston_view_create(surface); |
| 753 | if (fsurf->view == NULL) { |
| 754 | weston_surface_destroy(surface); |
| 755 | free(fsurf); |
| 756 | return NULL; |
| 757 | } |
Emilio Pozuelo Monfort | da64426 | 2013-11-19 11:37:19 +0100 | [diff] [blame] | 758 | fsurf->view->output = output; |
Louis-Francis Ratté-Boulianne | b482dbd | 2013-11-19 11:37:11 +0100 | [diff] [blame] | 759 | |
Jason Ekstrand | 5c11a33 | 2013-12-04 20:32:03 -0600 | [diff] [blame] | 760 | weston_surface_set_size(surface, output->width, output->height); |
Jason Ekstrand | 918f2dd | 2013-12-02 21:01:53 -0600 | [diff] [blame] | 761 | weston_view_set_position(fsurf->view, output->x, output->y); |
Louis-Francis Ratté-Boulianne | b482dbd | 2013-11-19 11:37:11 +0100 | [diff] [blame] | 762 | weston_surface_set_color(surface, 0.0, 0.0, 0.0, 1.0); |
| 763 | pixman_region32_fini(&surface->opaque); |
| 764 | pixman_region32_init_rect(&surface->opaque, output->x, output->y, |
| 765 | output->width, output->height); |
| 766 | pixman_region32_fini(&surface->input); |
| 767 | pixman_region32_init(&surface->input); |
| 768 | |
| 769 | wl_list_init(&fsurf->workspace_transform.link); |
| 770 | |
| 771 | return fsurf; |
| 772 | } |
| 773 | |
| 774 | static void |
| 775 | focus_surface_destroy(struct focus_surface *fsurf) |
| 776 | { |
| 777 | weston_surface_destroy(fsurf->surface); |
| 778 | free(fsurf); |
| 779 | } |
| 780 | |
| 781 | static void |
| 782 | focus_animation_done(struct weston_view_animation *animation, void *data) |
| 783 | { |
| 784 | struct workspace *ws = data; |
| 785 | |
| 786 | ws->focus_animation = NULL; |
| 787 | } |
| 788 | |
Jonas Ådahl | e3cddce | 2012-06-13 00:01:22 +0200 | [diff] [blame] | 789 | static void |
Jonas Ådahl | 0476974 | 2012-06-13 00:01:24 +0200 | [diff] [blame] | 790 | focus_state_destroy(struct focus_state *state) |
| 791 | { |
| 792 | wl_list_remove(&state->seat_destroy_listener.link); |
| 793 | wl_list_remove(&state->surface_destroy_listener.link); |
| 794 | free(state); |
| 795 | } |
| 796 | |
| 797 | static void |
| 798 | focus_state_seat_destroy(struct wl_listener *listener, void *data) |
| 799 | { |
| 800 | struct focus_state *state = container_of(listener, |
| 801 | struct focus_state, |
| 802 | seat_destroy_listener); |
| 803 | |
| 804 | wl_list_remove(&state->link); |
| 805 | focus_state_destroy(state); |
| 806 | } |
| 807 | |
| 808 | static void |
| 809 | focus_state_surface_destroy(struct wl_listener *listener, void *data) |
| 810 | { |
| 811 | struct focus_state *state = container_of(listener, |
| 812 | struct focus_state, |
Kristian Høgsberg | b8e0d0f | 2012-07-31 10:30:26 -0400 | [diff] [blame] | 813 | surface_destroy_listener); |
Kristian Høgsberg | e377822 | 2012-07-31 17:29:30 -0400 | [diff] [blame] | 814 | struct desktop_shell *shell; |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 815 | struct weston_surface *main_surface, *next; |
| 816 | struct weston_view *view; |
Jonas Ådahl | 0476974 | 2012-06-13 00:01:24 +0200 | [diff] [blame] | 817 | |
Pekka Paalanen | 01388e2 | 2013-04-25 13:57:44 +0300 | [diff] [blame] | 818 | main_surface = weston_surface_get_main_surface(state->keyboard_focus); |
| 819 | |
Kristian Høgsberg | e377822 | 2012-07-31 17:29:30 -0400 | [diff] [blame] | 820 | next = NULL; |
Giulio Camuffo | 412e6a5 | 2014-07-09 22:12:56 +0300 | [diff] [blame] | 821 | wl_list_for_each(view, |
| 822 | &state->ws->layer.view_list.link, layer_link.link) { |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 823 | if (view->surface == main_surface) |
Kristian Høgsberg | e377822 | 2012-07-31 17:29:30 -0400 | [diff] [blame] | 824 | continue; |
Louis-Francis Ratté-Boulianne | b482dbd | 2013-11-19 11:37:11 +0100 | [diff] [blame] | 825 | if (is_focus_view(view)) |
| 826 | continue; |
Kristian Høgsberg | e377822 | 2012-07-31 17:29:30 -0400 | [diff] [blame] | 827 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 828 | next = view->surface; |
Kristian Høgsberg | e377822 | 2012-07-31 17:29:30 -0400 | [diff] [blame] | 829 | break; |
| 830 | } |
| 831 | |
Pekka Paalanen | 01388e2 | 2013-04-25 13:57:44 +0300 | [diff] [blame] | 832 | /* if the focus was a sub-surface, activate its main surface */ |
| 833 | if (main_surface != state->keyboard_focus) |
| 834 | next = main_surface; |
| 835 | |
Louis-Francis Ratté-Boulianne | b482dbd | 2013-11-19 11:37:11 +0100 | [diff] [blame] | 836 | shell = state->seat->compositor->shell_interface.shell; |
Kristian Høgsberg | e377822 | 2012-07-31 17:29:30 -0400 | [diff] [blame] | 837 | if (next) { |
Louis-Francis Ratté-Boulianne | b482dbd | 2013-11-19 11:37:11 +0100 | [diff] [blame] | 838 | state->keyboard_focus = NULL; |
Emilio Pozuelo Monfort | 9e7c759 | 2014-01-30 14:01:10 +0100 | [diff] [blame] | 839 | activate(shell, next, state->seat, true); |
Kristian Høgsberg | e377822 | 2012-07-31 17:29:30 -0400 | [diff] [blame] | 840 | } else { |
Louis-Francis Ratté-Boulianne | b482dbd | 2013-11-19 11:37:11 +0100 | [diff] [blame] | 841 | if (shell->focus_animation_type == ANIMATION_DIM_LAYER) { |
| 842 | if (state->ws->focus_animation) |
| 843 | weston_view_animation_destroy(state->ws->focus_animation); |
| 844 | |
| 845 | state->ws->focus_animation = weston_fade_run( |
| 846 | state->ws->fsurf_front->view, |
| 847 | state->ws->fsurf_front->view->alpha, 0.0, 300, |
| 848 | focus_animation_done, state->ws); |
| 849 | } |
| 850 | |
Kristian Høgsberg | e377822 | 2012-07-31 17:29:30 -0400 | [diff] [blame] | 851 | wl_list_remove(&state->link); |
| 852 | focus_state_destroy(state); |
| 853 | } |
Jonas Ådahl | 0476974 | 2012-06-13 00:01:24 +0200 | [diff] [blame] | 854 | } |
| 855 | |
| 856 | static struct focus_state * |
Kristian Høgsberg | 2f5faff | 2012-07-31 16:36:34 -0400 | [diff] [blame] | 857 | focus_state_create(struct weston_seat *seat, struct workspace *ws) |
Jonas Ådahl | 0476974 | 2012-06-13 00:01:24 +0200 | [diff] [blame] | 858 | { |
Jonas Ådahl | 0476974 | 2012-06-13 00:01:24 +0200 | [diff] [blame] | 859 | struct focus_state *state; |
Jonas Ådahl | 0476974 | 2012-06-13 00:01:24 +0200 | [diff] [blame] | 860 | |
| 861 | state = malloc(sizeof *state); |
| 862 | if (state == NULL) |
| 863 | return NULL; |
| 864 | |
Louis-Francis Ratté-Boulianne | b482dbd | 2013-11-19 11:37:11 +0100 | [diff] [blame] | 865 | state->keyboard_focus = NULL; |
Kristian Høgsberg | 2f5faff | 2012-07-31 16:36:34 -0400 | [diff] [blame] | 866 | state->ws = ws; |
Jonas Ådahl | 0476974 | 2012-06-13 00:01:24 +0200 | [diff] [blame] | 867 | state->seat = seat; |
Kristian Høgsberg | 2f5faff | 2012-07-31 16:36:34 -0400 | [diff] [blame] | 868 | wl_list_insert(&ws->focus_list, &state->link); |
Jonas Ådahl | 0476974 | 2012-06-13 00:01:24 +0200 | [diff] [blame] | 869 | |
| 870 | state->seat_destroy_listener.notify = focus_state_seat_destroy; |
| 871 | state->surface_destroy_listener.notify = focus_state_surface_destroy; |
Kristian Høgsberg | 4912454 | 2013-05-06 22:27:40 -0400 | [diff] [blame] | 872 | wl_signal_add(&seat->destroy_signal, |
Jonas Ådahl | 0476974 | 2012-06-13 00:01:24 +0200 | [diff] [blame] | 873 | &state->seat_destroy_listener); |
Kristian Høgsberg | 2f5faff | 2012-07-31 16:36:34 -0400 | [diff] [blame] | 874 | wl_list_init(&state->surface_destroy_listener.link); |
Jonas Ådahl | 0476974 | 2012-06-13 00:01:24 +0200 | [diff] [blame] | 875 | |
| 876 | return state; |
| 877 | } |
| 878 | |
Jonas Ådahl | 8538b22 | 2012-08-29 22:13:03 +0200 | [diff] [blame] | 879 | static struct focus_state * |
| 880 | ensure_focus_state(struct desktop_shell *shell, struct weston_seat *seat) |
| 881 | { |
| 882 | struct workspace *ws = get_current_workspace(shell); |
| 883 | struct focus_state *state; |
| 884 | |
| 885 | wl_list_for_each(state, &ws->focus_list, link) |
| 886 | if (state->seat == seat) |
| 887 | break; |
| 888 | |
| 889 | if (&state->link == &ws->focus_list) |
| 890 | state = focus_state_create(seat, ws); |
| 891 | |
| 892 | return state; |
| 893 | } |
| 894 | |
Jonas Ådahl | 0476974 | 2012-06-13 00:01:24 +0200 | [diff] [blame] | 895 | static void |
Kristian Høgsberg | d500bf1 | 2014-01-22 12:25:20 -0800 | [diff] [blame] | 896 | focus_state_set_focus(struct focus_state *state, |
| 897 | struct weston_surface *surface) |
| 898 | { |
| 899 | if (state->keyboard_focus) { |
| 900 | wl_list_remove(&state->surface_destroy_listener.link); |
| 901 | wl_list_init(&state->surface_destroy_listener.link); |
| 902 | } |
| 903 | |
| 904 | state->keyboard_focus = surface; |
| 905 | if (surface) |
| 906 | wl_signal_add(&surface->destroy_signal, |
| 907 | &state->surface_destroy_listener); |
| 908 | } |
| 909 | |
| 910 | static void |
Kristian Høgsberg | 2f5faff | 2012-07-31 16:36:34 -0400 | [diff] [blame] | 911 | restore_focus_state(struct desktop_shell *shell, struct workspace *ws) |
Jonas Ådahl | 0476974 | 2012-06-13 00:01:24 +0200 | [diff] [blame] | 912 | { |
| 913 | struct focus_state *state, *next; |
Kristian Høgsberg | fe7aa90 | 2013-05-08 09:54:37 -0400 | [diff] [blame] | 914 | struct weston_surface *surface; |
Neil Roberts | 4237f50 | 2014-04-09 16:33:31 +0100 | [diff] [blame] | 915 | struct wl_list pending_seat_list; |
| 916 | struct weston_seat *seat, *next_seat; |
| 917 | |
| 918 | /* Temporarily steal the list of seats so that we can keep |
| 919 | * track of the seats we've already processed */ |
| 920 | wl_list_init(&pending_seat_list); |
| 921 | wl_list_insert_list(&pending_seat_list, &shell->compositor->seat_list); |
| 922 | wl_list_init(&shell->compositor->seat_list); |
Jonas Ådahl | 0476974 | 2012-06-13 00:01:24 +0200 | [diff] [blame] | 923 | |
| 924 | wl_list_for_each_safe(state, next, &ws->focus_list, link) { |
Derek Foreman | 1281a36 | 2015-07-31 16:55:32 -0500 | [diff] [blame] | 925 | struct weston_keyboard *keyboard = |
| 926 | weston_seat_get_keyboard(state->seat); |
| 927 | |
Neil Roberts | 4237f50 | 2014-04-09 16:33:31 +0100 | [diff] [blame] | 928 | wl_list_remove(&state->seat->link); |
| 929 | wl_list_insert(&shell->compositor->seat_list, |
| 930 | &state->seat->link); |
| 931 | |
Derek Foreman | 1281a36 | 2015-07-31 16:55:32 -0500 | [diff] [blame] | 932 | if (!keyboard) |
Kristian Høgsberg | e61d2f4 | 2014-01-17 12:18:53 -0800 | [diff] [blame] | 933 | continue; |
| 934 | |
Kristian Høgsberg | fe7aa90 | 2013-05-08 09:54:37 -0400 | [diff] [blame] | 935 | surface = state->keyboard_focus; |
Jonas Ådahl | 5689944 | 2012-08-29 22:12:59 +0200 | [diff] [blame] | 936 | |
Derek Foreman | 1281a36 | 2015-07-31 16:55:32 -0500 | [diff] [blame] | 937 | weston_keyboard_set_focus(keyboard, surface); |
Jonas Ådahl | 0476974 | 2012-06-13 00:01:24 +0200 | [diff] [blame] | 938 | } |
Neil Roberts | 4237f50 | 2014-04-09 16:33:31 +0100 | [diff] [blame] | 939 | |
| 940 | /* For any remaining seats that we don't have a focus state |
| 941 | * for we'll reset the keyboard focus to NULL */ |
| 942 | wl_list_for_each_safe(seat, next_seat, &pending_seat_list, link) { |
Derek Foreman | 1281a36 | 2015-07-31 16:55:32 -0500 | [diff] [blame] | 943 | struct weston_keyboard *keyboard = |
| 944 | weston_seat_get_keyboard(seat); |
| 945 | |
Neil Roberts | 4237f50 | 2014-04-09 16:33:31 +0100 | [diff] [blame] | 946 | wl_list_insert(&shell->compositor->seat_list, &seat->link); |
| 947 | |
Derek Foreman | 1281a36 | 2015-07-31 16:55:32 -0500 | [diff] [blame] | 948 | if (!keyboard) |
Neil Roberts | 4237f50 | 2014-04-09 16:33:31 +0100 | [diff] [blame] | 949 | continue; |
| 950 | |
Derek Foreman | 1281a36 | 2015-07-31 16:55:32 -0500 | [diff] [blame] | 951 | weston_keyboard_set_focus(keyboard, NULL); |
Neil Roberts | 4237f50 | 2014-04-09 16:33:31 +0100 | [diff] [blame] | 952 | } |
Jonas Ådahl | 0476974 | 2012-06-13 00:01:24 +0200 | [diff] [blame] | 953 | } |
| 954 | |
| 955 | static void |
Jonas Ådahl | 8de6a1d | 2012-08-29 22:13:00 +0200 | [diff] [blame] | 956 | replace_focus_state(struct desktop_shell *shell, struct workspace *ws, |
| 957 | struct weston_seat *seat) |
| 958 | { |
Derek Foreman | 1281a36 | 2015-07-31 16:55:32 -0500 | [diff] [blame] | 959 | struct weston_keyboard *keyboard = weston_seat_get_keyboard(seat); |
Jonas Ådahl | 8de6a1d | 2012-08-29 22:13:00 +0200 | [diff] [blame] | 960 | struct focus_state *state; |
Jonas Ådahl | 8de6a1d | 2012-08-29 22:13:00 +0200 | [diff] [blame] | 961 | |
| 962 | wl_list_for_each(state, &ws->focus_list, link) { |
| 963 | if (state->seat == seat) { |
Derek Foreman | 1281a36 | 2015-07-31 16:55:32 -0500 | [diff] [blame] | 964 | focus_state_set_focus(state, keyboard->focus); |
Jonas Ådahl | 8de6a1d | 2012-08-29 22:13:00 +0200 | [diff] [blame] | 965 | return; |
| 966 | } |
| 967 | } |
| 968 | } |
| 969 | |
| 970 | static void |
| 971 | drop_focus_state(struct desktop_shell *shell, struct workspace *ws, |
| 972 | struct weston_surface *surface) |
| 973 | { |
| 974 | struct focus_state *state; |
| 975 | |
| 976 | wl_list_for_each(state, &ws->focus_list, link) |
| 977 | if (state->keyboard_focus == surface) |
Kristian Høgsberg | d500bf1 | 2014-01-22 12:25:20 -0800 | [diff] [blame] | 978 | focus_state_set_focus(state, NULL); |
Jonas Ådahl | 8de6a1d | 2012-08-29 22:13:00 +0200 | [diff] [blame] | 979 | } |
| 980 | |
| 981 | static void |
Louis-Francis Ratté-Boulianne | b482dbd | 2013-11-19 11:37:11 +0100 | [diff] [blame] | 982 | animate_focus_change(struct desktop_shell *shell, struct workspace *ws, |
| 983 | struct weston_view *from, struct weston_view *to) |
| 984 | { |
| 985 | struct weston_output *output; |
| 986 | bool focus_surface_created = false; |
| 987 | |
| 988 | /* FIXME: Only support dim animation using two layers */ |
| 989 | if (from == to || shell->focus_animation_type != ANIMATION_DIM_LAYER) |
| 990 | return; |
| 991 | |
| 992 | output = get_default_output(shell->compositor); |
| 993 | if (ws->fsurf_front == NULL && (from || to)) { |
| 994 | ws->fsurf_front = create_focus_surface(shell->compositor, output); |
U. Artie Eoff | 0b23b2b | 2014-01-15 14:45:59 -0800 | [diff] [blame] | 995 | if (ws->fsurf_front == NULL) |
| 996 | return; |
Louis-Francis Ratté-Boulianne | b482dbd | 2013-11-19 11:37:11 +0100 | [diff] [blame] | 997 | ws->fsurf_front->view->alpha = 0.0; |
U. Artie Eoff | 0b23b2b | 2014-01-15 14:45:59 -0800 | [diff] [blame] | 998 | |
| 999 | ws->fsurf_back = create_focus_surface(shell->compositor, output); |
| 1000 | if (ws->fsurf_back == NULL) { |
| 1001 | focus_surface_destroy(ws->fsurf_front); |
| 1002 | return; |
| 1003 | } |
Louis-Francis Ratté-Boulianne | b482dbd | 2013-11-19 11:37:11 +0100 | [diff] [blame] | 1004 | ws->fsurf_back->view->alpha = 0.0; |
U. Artie Eoff | 0b23b2b | 2014-01-15 14:45:59 -0800 | [diff] [blame] | 1005 | |
Louis-Francis Ratté-Boulianne | b482dbd | 2013-11-19 11:37:11 +0100 | [diff] [blame] | 1006 | focus_surface_created = true; |
| 1007 | } else { |
Giulio Camuffo | 412e6a5 | 2014-07-09 22:12:56 +0300 | [diff] [blame] | 1008 | weston_layer_entry_remove(&ws->fsurf_front->view->layer_link); |
| 1009 | weston_layer_entry_remove(&ws->fsurf_back->view->layer_link); |
Louis-Francis Ratté-Boulianne | b482dbd | 2013-11-19 11:37:11 +0100 | [diff] [blame] | 1010 | } |
| 1011 | |
| 1012 | if (ws->focus_animation) { |
| 1013 | weston_view_animation_destroy(ws->focus_animation); |
| 1014 | ws->focus_animation = NULL; |
| 1015 | } |
| 1016 | |
| 1017 | if (to) |
Giulio Camuffo | 412e6a5 | 2014-07-09 22:12:56 +0300 | [diff] [blame] | 1018 | weston_layer_entry_insert(&to->layer_link, |
| 1019 | &ws->fsurf_front->view->layer_link); |
Louis-Francis Ratté-Boulianne | b482dbd | 2013-11-19 11:37:11 +0100 | [diff] [blame] | 1020 | else if (from) |
Giulio Camuffo | 412e6a5 | 2014-07-09 22:12:56 +0300 | [diff] [blame] | 1021 | weston_layer_entry_insert(&ws->layer.view_list, |
| 1022 | &ws->fsurf_front->view->layer_link); |
Louis-Francis Ratté-Boulianne | b482dbd | 2013-11-19 11:37:11 +0100 | [diff] [blame] | 1023 | |
| 1024 | if (focus_surface_created) { |
| 1025 | ws->focus_animation = weston_fade_run( |
| 1026 | ws->fsurf_front->view, |
Jonny Lamb | 7e7d485 | 2014-05-22 22:41:34 +0200 | [diff] [blame] | 1027 | ws->fsurf_front->view->alpha, 0.4, 300, |
Louis-Francis Ratté-Boulianne | b482dbd | 2013-11-19 11:37:11 +0100 | [diff] [blame] | 1028 | focus_animation_done, ws); |
| 1029 | } else if (from) { |
Giulio Camuffo | 412e6a5 | 2014-07-09 22:12:56 +0300 | [diff] [blame] | 1030 | weston_layer_entry_insert(&from->layer_link, |
| 1031 | &ws->fsurf_back->view->layer_link); |
Louis-Francis Ratté-Boulianne | b482dbd | 2013-11-19 11:37:11 +0100 | [diff] [blame] | 1032 | ws->focus_animation = weston_stable_fade_run( |
| 1033 | ws->fsurf_front->view, 0.0, |
Jonny Lamb | 7e7d485 | 2014-05-22 22:41:34 +0200 | [diff] [blame] | 1034 | ws->fsurf_back->view, 0.4, |
Louis-Francis Ratté-Boulianne | b482dbd | 2013-11-19 11:37:11 +0100 | [diff] [blame] | 1035 | focus_animation_done, ws); |
| 1036 | } else if (to) { |
Giulio Camuffo | 412e6a5 | 2014-07-09 22:12:56 +0300 | [diff] [blame] | 1037 | weston_layer_entry_insert(&ws->layer.view_list, |
| 1038 | &ws->fsurf_back->view->layer_link); |
Louis-Francis Ratté-Boulianne | b482dbd | 2013-11-19 11:37:11 +0100 | [diff] [blame] | 1039 | ws->focus_animation = weston_stable_fade_run( |
| 1040 | ws->fsurf_front->view, 0.0, |
Jonny Lamb | 7e7d485 | 2014-05-22 22:41:34 +0200 | [diff] [blame] | 1041 | ws->fsurf_back->view, 0.4, |
Louis-Francis Ratté-Boulianne | b482dbd | 2013-11-19 11:37:11 +0100 | [diff] [blame] | 1042 | focus_animation_done, ws); |
| 1043 | } |
| 1044 | } |
| 1045 | |
| 1046 | static void |
Jonas Ådahl | e3cddce | 2012-06-13 00:01:22 +0200 | [diff] [blame] | 1047 | workspace_destroy(struct workspace *ws) |
| 1048 | { |
Jonas Ådahl | 0476974 | 2012-06-13 00:01:24 +0200 | [diff] [blame] | 1049 | struct focus_state *state, *next; |
| 1050 | |
| 1051 | wl_list_for_each_safe(state, next, &ws->focus_list, link) |
| 1052 | focus_state_destroy(state); |
| 1053 | |
Louis-Francis Ratté-Boulianne | b482dbd | 2013-11-19 11:37:11 +0100 | [diff] [blame] | 1054 | if (ws->fsurf_front) |
| 1055 | focus_surface_destroy(ws->fsurf_front); |
| 1056 | if (ws->fsurf_back) |
| 1057 | focus_surface_destroy(ws->fsurf_back); |
| 1058 | |
Jonas Ådahl | e3cddce | 2012-06-13 00:01:22 +0200 | [diff] [blame] | 1059 | free(ws); |
| 1060 | } |
| 1061 | |
Jonas Ådahl | 0476974 | 2012-06-13 00:01:24 +0200 | [diff] [blame] | 1062 | static void |
| 1063 | seat_destroyed(struct wl_listener *listener, void *data) |
| 1064 | { |
| 1065 | struct weston_seat *seat = data; |
| 1066 | struct focus_state *state, *next; |
| 1067 | struct workspace *ws = container_of(listener, |
| 1068 | struct workspace, |
| 1069 | seat_destroyed_listener); |
| 1070 | |
| 1071 | wl_list_for_each_safe(state, next, &ws->focus_list, link) |
| 1072 | if (state->seat == seat) |
| 1073 | wl_list_remove(&state->link); |
| 1074 | } |
| 1075 | |
Jonas Ådahl | e3cddce | 2012-06-13 00:01:22 +0200 | [diff] [blame] | 1076 | static struct workspace * |
| 1077 | workspace_create(void) |
| 1078 | { |
| 1079 | struct workspace *ws = malloc(sizeof *ws); |
| 1080 | if (ws == NULL) |
| 1081 | return NULL; |
| 1082 | |
| 1083 | weston_layer_init(&ws->layer, NULL); |
| 1084 | |
Jonas Ådahl | 0476974 | 2012-06-13 00:01:24 +0200 | [diff] [blame] | 1085 | wl_list_init(&ws->focus_list); |
| 1086 | wl_list_init(&ws->seat_destroyed_listener.link); |
| 1087 | ws->seat_destroyed_listener.notify = seat_destroyed; |
Louis-Francis Ratté-Boulianne | b482dbd | 2013-11-19 11:37:11 +0100 | [diff] [blame] | 1088 | ws->fsurf_front = NULL; |
| 1089 | ws->fsurf_back = NULL; |
| 1090 | ws->focus_animation = NULL; |
Jonas Ådahl | 0476974 | 2012-06-13 00:01:24 +0200 | [diff] [blame] | 1091 | |
Jonas Ådahl | e3cddce | 2012-06-13 00:01:22 +0200 | [diff] [blame] | 1092 | return ws; |
| 1093 | } |
| 1094 | |
Jonas Ådahl | 62fcd04 | 2012-06-13 00:01:23 +0200 | [diff] [blame] | 1095 | static int |
| 1096 | workspace_is_empty(struct workspace *ws) |
| 1097 | { |
Giulio Camuffo | 412e6a5 | 2014-07-09 22:12:56 +0300 | [diff] [blame] | 1098 | return wl_list_empty(&ws->layer.view_list.link); |
Jonas Ådahl | 62fcd04 | 2012-06-13 00:01:23 +0200 | [diff] [blame] | 1099 | } |
| 1100 | |
Jonas Ådahl | e3cddce | 2012-06-13 00:01:22 +0200 | [diff] [blame] | 1101 | static struct workspace * |
| 1102 | get_workspace(struct desktop_shell *shell, unsigned int index) |
| 1103 | { |
| 1104 | struct workspace **pws = shell->workspaces.array.data; |
Philipp Brüschweiler | 067abf6 | 2012-09-01 16:03:05 +0200 | [diff] [blame] | 1105 | assert(index < shell->workspaces.num); |
Jonas Ådahl | e3cddce | 2012-06-13 00:01:22 +0200 | [diff] [blame] | 1106 | pws += index; |
| 1107 | return *pws; |
| 1108 | } |
| 1109 | |
Kristian Høgsberg | 1ef2313 | 2013-12-04 00:20:01 -0800 | [diff] [blame] | 1110 | struct workspace * |
Jonas Ådahl | e3cddce | 2012-06-13 00:01:22 +0200 | [diff] [blame] | 1111 | get_current_workspace(struct desktop_shell *shell) |
| 1112 | { |
| 1113 | return get_workspace(shell, shell->workspaces.current); |
| 1114 | } |
| 1115 | |
| 1116 | static void |
| 1117 | activate_workspace(struct desktop_shell *shell, unsigned int index) |
| 1118 | { |
| 1119 | struct workspace *ws; |
| 1120 | |
| 1121 | ws = get_workspace(shell, index); |
| 1122 | wl_list_insert(&shell->panel_layer.link, &ws->layer.link); |
| 1123 | |
| 1124 | shell->workspaces.current = index; |
| 1125 | } |
| 1126 | |
Jonas Ådahl | 62fcd04 | 2012-06-13 00:01:23 +0200 | [diff] [blame] | 1127 | static unsigned int |
| 1128 | get_output_height(struct weston_output *output) |
| 1129 | { |
| 1130 | return abs(output->region.extents.y1 - output->region.extents.y2); |
| 1131 | } |
| 1132 | |
| 1133 | static void |
Louis-Francis Ratté-Boulianne | b482dbd | 2013-11-19 11:37:11 +0100 | [diff] [blame] | 1134 | view_translate(struct workspace *ws, struct weston_view *view, double d) |
Jonas Ådahl | 62fcd04 | 2012-06-13 00:01:23 +0200 | [diff] [blame] | 1135 | { |
Jonas Ådahl | 62fcd04 | 2012-06-13 00:01:23 +0200 | [diff] [blame] | 1136 | struct weston_transform *transform; |
| 1137 | |
Louis-Francis Ratté-Boulianne | b482dbd | 2013-11-19 11:37:11 +0100 | [diff] [blame] | 1138 | if (is_focus_view(view)) { |
| 1139 | struct focus_surface *fsurf = get_focus_surface(view->surface); |
| 1140 | transform = &fsurf->workspace_transform; |
| 1141 | } else { |
| 1142 | struct shell_surface *shsurf = get_shell_surface(view->surface); |
| 1143 | transform = &shsurf->workspace_transform; |
| 1144 | } |
| 1145 | |
Jonas Ådahl | 62fcd04 | 2012-06-13 00:01:23 +0200 | [diff] [blame] | 1146 | if (wl_list_empty(&transform->link)) |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 1147 | wl_list_insert(view->geometry.transformation_list.prev, |
Louis-Francis Ratté-Boulianne | b482dbd | 2013-11-19 11:37:11 +0100 | [diff] [blame] | 1148 | &transform->link); |
Jonas Ådahl | 62fcd04 | 2012-06-13 00:01:23 +0200 | [diff] [blame] | 1149 | |
Louis-Francis Ratté-Boulianne | b482dbd | 2013-11-19 11:37:11 +0100 | [diff] [blame] | 1150 | weston_matrix_init(&transform->matrix); |
| 1151 | weston_matrix_translate(&transform->matrix, |
Jonas Ådahl | 62fcd04 | 2012-06-13 00:01:23 +0200 | [diff] [blame] | 1152 | 0.0, d, 0.0); |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 1153 | weston_view_geometry_dirty(view); |
Jonas Ådahl | 62fcd04 | 2012-06-13 00:01:23 +0200 | [diff] [blame] | 1154 | } |
| 1155 | |
| 1156 | static void |
| 1157 | workspace_translate_out(struct workspace *ws, double fraction) |
| 1158 | { |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 1159 | struct weston_view *view; |
Jonas Ådahl | 62fcd04 | 2012-06-13 00:01:23 +0200 | [diff] [blame] | 1160 | unsigned int height; |
| 1161 | double d; |
| 1162 | |
Giulio Camuffo | 412e6a5 | 2014-07-09 22:12:56 +0300 | [diff] [blame] | 1163 | 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] | 1164 | height = get_output_height(view->surface->output); |
Jonas Ådahl | 62fcd04 | 2012-06-13 00:01:23 +0200 | [diff] [blame] | 1165 | d = height * fraction; |
| 1166 | |
Louis-Francis Ratté-Boulianne | b482dbd | 2013-11-19 11:37:11 +0100 | [diff] [blame] | 1167 | view_translate(ws, view, d); |
Jonas Ådahl | 62fcd04 | 2012-06-13 00:01:23 +0200 | [diff] [blame] | 1168 | } |
| 1169 | } |
| 1170 | |
| 1171 | static void |
| 1172 | workspace_translate_in(struct workspace *ws, double fraction) |
| 1173 | { |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 1174 | struct weston_view *view; |
Jonas Ådahl | 62fcd04 | 2012-06-13 00:01:23 +0200 | [diff] [blame] | 1175 | unsigned int height; |
| 1176 | double d; |
| 1177 | |
Giulio Camuffo | 412e6a5 | 2014-07-09 22:12:56 +0300 | [diff] [blame] | 1178 | 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] | 1179 | height = get_output_height(view->surface->output); |
Jonas Ådahl | 62fcd04 | 2012-06-13 00:01:23 +0200 | [diff] [blame] | 1180 | |
| 1181 | if (fraction > 0) |
| 1182 | d = -(height - height * fraction); |
| 1183 | else |
| 1184 | d = height + height * fraction; |
| 1185 | |
Louis-Francis Ratté-Boulianne | b482dbd | 2013-11-19 11:37:11 +0100 | [diff] [blame] | 1186 | view_translate(ws, view, d); |
Jonas Ådahl | 62fcd04 | 2012-06-13 00:01:23 +0200 | [diff] [blame] | 1187 | } |
| 1188 | } |
| 1189 | |
| 1190 | static void |
Jonas Ådahl | 62fcd04 | 2012-06-13 00:01:23 +0200 | [diff] [blame] | 1191 | reverse_workspace_change_animation(struct desktop_shell *shell, |
| 1192 | unsigned int index, |
| 1193 | struct workspace *from, |
| 1194 | struct workspace *to) |
| 1195 | { |
| 1196 | shell->workspaces.current = index; |
| 1197 | |
| 1198 | shell->workspaces.anim_to = to; |
| 1199 | shell->workspaces.anim_from = from; |
| 1200 | shell->workspaces.anim_dir = -1 * shell->workspaces.anim_dir; |
| 1201 | shell->workspaces.anim_timestamp = 0; |
| 1202 | |
Scott Moreau | 4272e63 | 2012-08-13 09:58:41 -0600 | [diff] [blame] | 1203 | weston_compositor_schedule_repaint(shell->compositor); |
Jonas Ådahl | 62fcd04 | 2012-06-13 00:01:23 +0200 | [diff] [blame] | 1204 | } |
| 1205 | |
| 1206 | static void |
| 1207 | workspace_deactivate_transforms(struct workspace *ws) |
| 1208 | { |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 1209 | struct weston_view *view; |
Louis-Francis Ratté-Boulianne | b482dbd | 2013-11-19 11:37:11 +0100 | [diff] [blame] | 1210 | struct weston_transform *transform; |
Jonas Ådahl | 62fcd04 | 2012-06-13 00:01:23 +0200 | [diff] [blame] | 1211 | |
Giulio Camuffo | 412e6a5 | 2014-07-09 22:12:56 +0300 | [diff] [blame] | 1212 | 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] | 1213 | if (is_focus_view(view)) { |
| 1214 | struct focus_surface *fsurf = get_focus_surface(view->surface); |
| 1215 | transform = &fsurf->workspace_transform; |
| 1216 | } else { |
| 1217 | struct shell_surface *shsurf = get_shell_surface(view->surface); |
| 1218 | transform = &shsurf->workspace_transform; |
| 1219 | } |
| 1220 | |
| 1221 | if (!wl_list_empty(&transform->link)) { |
| 1222 | wl_list_remove(&transform->link); |
| 1223 | wl_list_init(&transform->link); |
Jonas Ådahl | 8de6a1d | 2012-08-29 22:13:00 +0200 | [diff] [blame] | 1224 | } |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 1225 | weston_view_geometry_dirty(view); |
Jonas Ådahl | 62fcd04 | 2012-06-13 00:01:23 +0200 | [diff] [blame] | 1226 | } |
| 1227 | } |
| 1228 | |
| 1229 | static void |
| 1230 | finish_workspace_change_animation(struct desktop_shell *shell, |
| 1231 | struct workspace *from, |
| 1232 | struct workspace *to) |
| 1233 | { |
Ander Conselvan de Oliveira | 9c6217e | 2014-05-07 11:57:26 +0300 | [diff] [blame] | 1234 | struct weston_view *view; |
| 1235 | |
Scott Moreau | 4272e63 | 2012-08-13 09:58:41 -0600 | [diff] [blame] | 1236 | weston_compositor_schedule_repaint(shell->compositor); |
Jonas Ådahl | 62fcd04 | 2012-06-13 00:01:23 +0200 | [diff] [blame] | 1237 | |
Ander Conselvan de Oliveira | 9c6217e | 2014-05-07 11:57:26 +0300 | [diff] [blame] | 1238 | /* Views that extend past the bottom of the output are still |
| 1239 | * visible after the workspace animation ends but before its layer |
| 1240 | * is hidden. In that case, we need to damage below those views so |
| 1241 | * that the screen is properly repainted. */ |
Giulio Camuffo | 412e6a5 | 2014-07-09 22:12:56 +0300 | [diff] [blame] | 1242 | 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] | 1243 | weston_view_damage_below(view); |
| 1244 | |
Jonas Ådahl | 62fcd04 | 2012-06-13 00:01:23 +0200 | [diff] [blame] | 1245 | wl_list_remove(&shell->workspaces.animation.link); |
| 1246 | workspace_deactivate_transforms(from); |
| 1247 | workspace_deactivate_transforms(to); |
| 1248 | shell->workspaces.anim_to = NULL; |
| 1249 | |
| 1250 | wl_list_remove(&shell->workspaces.anim_from->layer.link); |
| 1251 | } |
| 1252 | |
| 1253 | static void |
| 1254 | animate_workspace_change_frame(struct weston_animation *animation, |
| 1255 | struct weston_output *output, uint32_t msecs) |
| 1256 | { |
| 1257 | struct desktop_shell *shell = |
| 1258 | container_of(animation, struct desktop_shell, |
| 1259 | workspaces.animation); |
| 1260 | struct workspace *from = shell->workspaces.anim_from; |
| 1261 | struct workspace *to = shell->workspaces.anim_to; |
| 1262 | uint32_t t; |
| 1263 | double x, y; |
| 1264 | |
| 1265 | if (workspace_is_empty(from) && workspace_is_empty(to)) { |
| 1266 | finish_workspace_change_animation(shell, from, to); |
| 1267 | return; |
| 1268 | } |
| 1269 | |
| 1270 | if (shell->workspaces.anim_timestamp == 0) { |
| 1271 | if (shell->workspaces.anim_current == 0.0) |
| 1272 | shell->workspaces.anim_timestamp = msecs; |
| 1273 | else |
| 1274 | shell->workspaces.anim_timestamp = |
| 1275 | msecs - |
| 1276 | /* Invers of movement function 'y' below. */ |
| 1277 | (asin(1.0 - shell->workspaces.anim_current) * |
| 1278 | DEFAULT_WORKSPACE_CHANGE_ANIMATION_LENGTH * |
| 1279 | M_2_PI); |
| 1280 | } |
| 1281 | |
| 1282 | t = msecs - shell->workspaces.anim_timestamp; |
| 1283 | |
| 1284 | /* |
| 1285 | * x = [0, π/2] |
| 1286 | * y(x) = sin(x) |
| 1287 | */ |
| 1288 | x = t * (1.0/DEFAULT_WORKSPACE_CHANGE_ANIMATION_LENGTH) * M_PI_2; |
| 1289 | y = sin(x); |
| 1290 | |
| 1291 | if (t < DEFAULT_WORKSPACE_CHANGE_ANIMATION_LENGTH) { |
Scott Moreau | 4272e63 | 2012-08-13 09:58:41 -0600 | [diff] [blame] | 1292 | weston_compositor_schedule_repaint(shell->compositor); |
Jonas Ådahl | 62fcd04 | 2012-06-13 00:01:23 +0200 | [diff] [blame] | 1293 | |
| 1294 | workspace_translate_out(from, shell->workspaces.anim_dir * y); |
| 1295 | workspace_translate_in(to, shell->workspaces.anim_dir * y); |
| 1296 | shell->workspaces.anim_current = y; |
| 1297 | |
Scott Moreau | 4272e63 | 2012-08-13 09:58:41 -0600 | [diff] [blame] | 1298 | weston_compositor_schedule_repaint(shell->compositor); |
Jonas Ådahl | 62fcd04 | 2012-06-13 00:01:23 +0200 | [diff] [blame] | 1299 | } |
Jonas Ådahl | 0476974 | 2012-06-13 00:01:24 +0200 | [diff] [blame] | 1300 | else |
Jonas Ådahl | 62fcd04 | 2012-06-13 00:01:23 +0200 | [diff] [blame] | 1301 | finish_workspace_change_animation(shell, from, to); |
Jonas Ådahl | 62fcd04 | 2012-06-13 00:01:23 +0200 | [diff] [blame] | 1302 | } |
| 1303 | |
| 1304 | static void |
| 1305 | animate_workspace_change(struct desktop_shell *shell, |
| 1306 | unsigned int index, |
| 1307 | struct workspace *from, |
| 1308 | struct workspace *to) |
| 1309 | { |
| 1310 | struct weston_output *output; |
| 1311 | |
| 1312 | int dir; |
| 1313 | |
| 1314 | if (index > shell->workspaces.current) |
| 1315 | dir = -1; |
| 1316 | else |
| 1317 | dir = 1; |
| 1318 | |
| 1319 | shell->workspaces.current = index; |
| 1320 | |
| 1321 | shell->workspaces.anim_dir = dir; |
| 1322 | shell->workspaces.anim_from = from; |
| 1323 | shell->workspaces.anim_to = to; |
| 1324 | shell->workspaces.anim_current = 0.0; |
| 1325 | shell->workspaces.anim_timestamp = 0; |
| 1326 | |
| 1327 | output = container_of(shell->compositor->output_list.next, |
| 1328 | struct weston_output, link); |
| 1329 | wl_list_insert(&output->animation_list, |
| 1330 | &shell->workspaces.animation.link); |
| 1331 | |
Jonas Ådahl | 8de6a1d | 2012-08-29 22:13:00 +0200 | [diff] [blame] | 1332 | wl_list_insert(from->layer.link.prev, &to->layer.link); |
Jonas Ådahl | 62fcd04 | 2012-06-13 00:01:23 +0200 | [diff] [blame] | 1333 | |
| 1334 | workspace_translate_in(to, 0); |
| 1335 | |
Kristian Høgsberg | 2f5faff | 2012-07-31 16:36:34 -0400 | [diff] [blame] | 1336 | restore_focus_state(shell, to); |
Jonas Ådahl | 0476974 | 2012-06-13 00:01:24 +0200 | [diff] [blame] | 1337 | |
Scott Moreau | 4272e63 | 2012-08-13 09:58:41 -0600 | [diff] [blame] | 1338 | weston_compositor_schedule_repaint(shell->compositor); |
Jonas Ådahl | 62fcd04 | 2012-06-13 00:01:23 +0200 | [diff] [blame] | 1339 | } |
| 1340 | |
Jonas Ådahl | e3cddce | 2012-06-13 00:01:22 +0200 | [diff] [blame] | 1341 | static void |
Jonas Ådahl | 8de6a1d | 2012-08-29 22:13:00 +0200 | [diff] [blame] | 1342 | update_workspace(struct desktop_shell *shell, unsigned int index, |
| 1343 | struct workspace *from, struct workspace *to) |
| 1344 | { |
| 1345 | shell->workspaces.current = index; |
| 1346 | wl_list_insert(&from->layer.link, &to->layer.link); |
| 1347 | wl_list_remove(&from->layer.link); |
| 1348 | } |
| 1349 | |
| 1350 | static void |
Jonas Ådahl | e3cddce | 2012-06-13 00:01:22 +0200 | [diff] [blame] | 1351 | change_workspace(struct desktop_shell *shell, unsigned int index) |
| 1352 | { |
| 1353 | struct workspace *from; |
| 1354 | struct workspace *to; |
Louis-Francis Ratté-Boulianne | b482dbd | 2013-11-19 11:37:11 +0100 | [diff] [blame] | 1355 | struct focus_state *state; |
Jonas Ådahl | e3cddce | 2012-06-13 00:01:22 +0200 | [diff] [blame] | 1356 | |
| 1357 | if (index == shell->workspaces.current) |
| 1358 | return; |
| 1359 | |
| 1360 | /* Don't change workspace when there is any fullscreen surfaces. */ |
Giulio Camuffo | 412e6a5 | 2014-07-09 22:12:56 +0300 | [diff] [blame] | 1361 | if (!wl_list_empty(&shell->fullscreen_layer.view_list.link)) |
Jonas Ådahl | e3cddce | 2012-06-13 00:01:22 +0200 | [diff] [blame] | 1362 | return; |
| 1363 | |
Jonas Ådahl | e3cddce | 2012-06-13 00:01:22 +0200 | [diff] [blame] | 1364 | from = get_current_workspace(shell); |
| 1365 | to = get_workspace(shell, index); |
| 1366 | |
Jonas Ådahl | 62fcd04 | 2012-06-13 00:01:23 +0200 | [diff] [blame] | 1367 | if (shell->workspaces.anim_from == to && |
| 1368 | shell->workspaces.anim_to == from) { |
Jonas Ådahl | 8de6a1d | 2012-08-29 22:13:00 +0200 | [diff] [blame] | 1369 | restore_focus_state(shell, to); |
Jonas Ådahl | 62fcd04 | 2012-06-13 00:01:23 +0200 | [diff] [blame] | 1370 | reverse_workspace_change_animation(shell, index, from, to); |
| 1371 | return; |
| 1372 | } |
Jonas Ådahl | e3cddce | 2012-06-13 00:01:22 +0200 | [diff] [blame] | 1373 | |
Jonas Ådahl | 62fcd04 | 2012-06-13 00:01:23 +0200 | [diff] [blame] | 1374 | if (shell->workspaces.anim_to != NULL) |
| 1375 | finish_workspace_change_animation(shell, |
| 1376 | shell->workspaces.anim_from, |
| 1377 | shell->workspaces.anim_to); |
| 1378 | |
Jonas Ådahl | 8de6a1d | 2012-08-29 22:13:00 +0200 | [diff] [blame] | 1379 | restore_focus_state(shell, to); |
Jonas Ådahl | 0476974 | 2012-06-13 00:01:24 +0200 | [diff] [blame] | 1380 | |
Louis-Francis Ratté-Boulianne | b482dbd | 2013-11-19 11:37:11 +0100 | [diff] [blame] | 1381 | if (shell->focus_animation_type != ANIMATION_NONE) { |
| 1382 | wl_list_for_each(state, &from->focus_list, link) |
| 1383 | if (state->keyboard_focus) |
| 1384 | animate_focus_change(shell, from, |
| 1385 | get_default_view(state->keyboard_focus), NULL); |
| 1386 | |
| 1387 | wl_list_for_each(state, &to->focus_list, link) |
| 1388 | if (state->keyboard_focus) |
| 1389 | animate_focus_change(shell, to, |
| 1390 | NULL, get_default_view(state->keyboard_focus)); |
| 1391 | } |
| 1392 | |
Jonas Ådahl | 8de6a1d | 2012-08-29 22:13:00 +0200 | [diff] [blame] | 1393 | if (workspace_is_empty(to) && workspace_is_empty(from)) |
| 1394 | update_workspace(shell, index, from, to); |
Jonas Ådahl | 62fcd04 | 2012-06-13 00:01:23 +0200 | [diff] [blame] | 1395 | else |
| 1396 | animate_workspace_change(shell, index, from, to); |
Pekka Paalanen | e955f1e | 2011-12-07 11:49:52 +0200 | [diff] [blame] | 1397 | } |
| 1398 | |
Jonas Ådahl | 8de6a1d | 2012-08-29 22:13:00 +0200 | [diff] [blame] | 1399 | static bool |
| 1400 | workspace_has_only(struct workspace *ws, struct weston_surface *surface) |
| 1401 | { |
Giulio Camuffo | 412e6a5 | 2014-07-09 22:12:56 +0300 | [diff] [blame] | 1402 | struct wl_list *list = &ws->layer.view_list.link; |
Jonas Ådahl | 8de6a1d | 2012-08-29 22:13:00 +0200 | [diff] [blame] | 1403 | struct wl_list *e; |
| 1404 | |
| 1405 | if (wl_list_empty(list)) |
| 1406 | return false; |
| 1407 | |
| 1408 | e = list->next; |
| 1409 | |
| 1410 | if (e->next != list) |
| 1411 | return false; |
| 1412 | |
Giulio Camuffo | 412e6a5 | 2014-07-09 22:12:56 +0300 | [diff] [blame] | 1413 | return container_of(e, struct weston_view, layer_link.link)->surface == surface; |
Jonas Ådahl | 8de6a1d | 2012-08-29 22:13:00 +0200 | [diff] [blame] | 1414 | } |
| 1415 | |
| 1416 | static void |
Jonas Ådahl | 22faea1 | 2014-10-15 22:02:06 +0200 | [diff] [blame] | 1417 | surface_keyboard_focus_lost(struct weston_surface *surface) |
| 1418 | { |
| 1419 | struct weston_compositor *compositor = surface->compositor; |
| 1420 | struct weston_seat *seat; |
| 1421 | struct weston_surface *focus; |
| 1422 | |
| 1423 | wl_list_for_each(seat, &compositor->seat_list, link) { |
| 1424 | struct weston_keyboard *keyboard = |
| 1425 | weston_seat_get_keyboard(seat); |
| 1426 | |
| 1427 | if (!keyboard) |
| 1428 | continue; |
| 1429 | |
| 1430 | focus = weston_surface_get_main_surface(keyboard->focus); |
| 1431 | if (focus == surface) |
| 1432 | weston_keyboard_set_focus(keyboard, NULL); |
| 1433 | } |
| 1434 | } |
| 1435 | |
| 1436 | static void |
Jonas Ådahl | 8de6a1d | 2012-08-29 22:13:00 +0200 | [diff] [blame] | 1437 | take_surface_to_workspace_by_seat(struct desktop_shell *shell, |
Kristian Høgsberg | e314875 | 2013-05-06 23:19:49 -0400 | [diff] [blame] | 1438 | struct weston_seat *seat, |
Jonas Ådahl | 8de6a1d | 2012-08-29 22:13:00 +0200 | [diff] [blame] | 1439 | unsigned int index) |
| 1440 | { |
Derek Foreman | 1281a36 | 2015-07-31 16:55:32 -0500 | [diff] [blame] | 1441 | struct weston_keyboard *keyboard = weston_seat_get_keyboard(seat); |
Pekka Paalanen | 01388e2 | 2013-04-25 13:57:44 +0300 | [diff] [blame] | 1442 | struct weston_surface *surface; |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 1443 | struct weston_view *view; |
Jonas Ådahl | 8de6a1d | 2012-08-29 22:13:00 +0200 | [diff] [blame] | 1444 | struct shell_surface *shsurf; |
| 1445 | struct workspace *from; |
| 1446 | struct workspace *to; |
Jonas Ådahl | 8538b22 | 2012-08-29 22:13:03 +0200 | [diff] [blame] | 1447 | struct focus_state *state; |
Jonas Ådahl | 8de6a1d | 2012-08-29 22:13:00 +0200 | [diff] [blame] | 1448 | |
Derek Foreman | 1281a36 | 2015-07-31 16:55:32 -0500 | [diff] [blame] | 1449 | surface = weston_surface_get_main_surface(keyboard->focus); |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 1450 | view = get_default_view(surface); |
| 1451 | if (view == NULL || |
Louis-Francis Ratté-Boulianne | b482dbd | 2013-11-19 11:37:11 +0100 | [diff] [blame] | 1452 | index == shell->workspaces.current || |
| 1453 | is_focus_view(view)) |
Jonas Ådahl | 8de6a1d | 2012-08-29 22:13:00 +0200 | [diff] [blame] | 1454 | return; |
| 1455 | |
| 1456 | from = get_current_workspace(shell); |
| 1457 | to = get_workspace(shell, index); |
| 1458 | |
Giulio Camuffo | 412e6a5 | 2014-07-09 22:12:56 +0300 | [diff] [blame] | 1459 | weston_layer_entry_remove(&view->layer_link); |
| 1460 | weston_layer_entry_insert(&to->layer.view_list, &view->layer_link); |
Jonas Ådahl | 8de6a1d | 2012-08-29 22:13:00 +0200 | [diff] [blame] | 1461 | |
Philip Withnall | 659163d | 2013-11-25 18:01:36 +0000 | [diff] [blame] | 1462 | shsurf = get_shell_surface(surface); |
Philip Withnall | 648a4dd | 2013-11-25 18:01:44 +0000 | [diff] [blame] | 1463 | if (shsurf != NULL) |
| 1464 | shell_surface_update_child_surface_layers(shsurf); |
Philip Withnall | 659163d | 2013-11-25 18:01:36 +0000 | [diff] [blame] | 1465 | |
Jonas Ådahl | e9d2250 | 2012-08-29 22:13:01 +0200 | [diff] [blame] | 1466 | replace_focus_state(shell, to, seat); |
Jonas Ådahl | 8de6a1d | 2012-08-29 22:13:00 +0200 | [diff] [blame] | 1467 | drop_focus_state(shell, from, surface); |
| 1468 | |
| 1469 | if (shell->workspaces.anim_from == to && |
| 1470 | shell->workspaces.anim_to == from) { |
Jonas Ådahl | e9d2250 | 2012-08-29 22:13:01 +0200 | [diff] [blame] | 1471 | wl_list_remove(&to->layer.link); |
| 1472 | wl_list_insert(from->layer.link.prev, &to->layer.link); |
| 1473 | |
Jonas Ådahl | 8de6a1d | 2012-08-29 22:13:00 +0200 | [diff] [blame] | 1474 | reverse_workspace_change_animation(shell, index, from, to); |
Jonas Ådahl | e9d2250 | 2012-08-29 22:13:01 +0200 | [diff] [blame] | 1475 | |
Jonas Ådahl | 8de6a1d | 2012-08-29 22:13:00 +0200 | [diff] [blame] | 1476 | return; |
| 1477 | } |
| 1478 | |
| 1479 | if (shell->workspaces.anim_to != NULL) |
| 1480 | finish_workspace_change_animation(shell, |
| 1481 | shell->workspaces.anim_from, |
| 1482 | shell->workspaces.anim_to); |
| 1483 | |
| 1484 | if (workspace_is_empty(from) && |
| 1485 | workspace_has_only(to, surface)) |
| 1486 | update_workspace(shell, index, from, to); |
| 1487 | else { |
Philip Withnall | 2c3849b | 2013-11-25 18:01:45 +0000 | [diff] [blame] | 1488 | if (shsurf != NULL && |
| 1489 | wl_list_empty(&shsurf->workspace_transform.link)) |
Jonas Ådahl | 8de6a1d | 2012-08-29 22:13:00 +0200 | [diff] [blame] | 1490 | wl_list_insert(&shell->workspaces.anim_sticky_list, |
| 1491 | &shsurf->workspace_transform.link); |
| 1492 | |
| 1493 | animate_workspace_change(shell, index, from, to); |
| 1494 | } |
Jonas Ådahl | e9d2250 | 2012-08-29 22:13:01 +0200 | [diff] [blame] | 1495 | |
Jonas Ådahl | 8538b22 | 2012-08-29 22:13:03 +0200 | [diff] [blame] | 1496 | state = ensure_focus_state(shell, seat); |
| 1497 | if (state != NULL) |
Kristian Høgsberg | d500bf1 | 2014-01-22 12:25:20 -0800 | [diff] [blame] | 1498 | focus_state_set_focus(state, surface); |
Jonas Ådahl | e9d2250 | 2012-08-29 22:13:01 +0200 | [diff] [blame] | 1499 | } |
| 1500 | |
| 1501 | static void |
Rusty Lynch | 1084da5 | 2013-08-15 09:10:08 -0700 | [diff] [blame] | 1502 | touch_move_grab_down(struct weston_touch_grab *grab, uint32_t time, |
Giulio Camuffo | 61ed7b6 | 2015-07-08 11:55:28 +0300 | [diff] [blame] | 1503 | int touch_id, wl_fixed_t x, wl_fixed_t y) |
Rusty Lynch | 1084da5 | 2013-08-15 09:10:08 -0700 | [diff] [blame] | 1504 | { |
| 1505 | } |
| 1506 | |
| 1507 | static void |
| 1508 | touch_move_grab_up(struct weston_touch_grab *grab, uint32_t time, int touch_id) |
| 1509 | { |
Jonas Ådahl | 1c6e63e | 2013-10-25 23:18:04 +0200 | [diff] [blame] | 1510 | struct weston_touch_move_grab *move = |
| 1511 | (struct weston_touch_move_grab *) container_of( |
| 1512 | grab, struct shell_touch_grab, grab); |
Neil Roberts | e14aa4f | 2013-10-03 16:43:07 +0100 | [diff] [blame] | 1513 | |
Kristian Høgsberg | 8e80a31 | 2014-01-17 15:18:10 -0800 | [diff] [blame] | 1514 | if (touch_id == 0) |
| 1515 | move->active = 0; |
| 1516 | |
Jonas Ådahl | 9484b69 | 2013-12-02 22:05:03 +0100 | [diff] [blame] | 1517 | if (grab->touch->num_tp == 0) { |
Jonas Ådahl | 1c6e63e | 2013-10-25 23:18:04 +0200 | [diff] [blame] | 1518 | shell_touch_grab_end(&move->base); |
| 1519 | free(move); |
| 1520 | } |
Rusty Lynch | 1084da5 | 2013-08-15 09:10:08 -0700 | [diff] [blame] | 1521 | } |
| 1522 | |
| 1523 | static void |
| 1524 | touch_move_grab_motion(struct weston_touch_grab *grab, uint32_t time, |
Giulio Camuffo | 61ed7b6 | 2015-07-08 11:55:28 +0300 | [diff] [blame] | 1525 | int touch_id, wl_fixed_t x, wl_fixed_t y) |
Rusty Lynch | 1084da5 | 2013-08-15 09:10:08 -0700 | [diff] [blame] | 1526 | { |
| 1527 | struct weston_touch_move_grab *move = (struct weston_touch_move_grab *) grab; |
| 1528 | struct shell_surface *shsurf = move->base.shsurf; |
| 1529 | struct weston_surface *es; |
| 1530 | int dx = wl_fixed_to_int(grab->touch->grab_x + move->dx); |
| 1531 | int dy = wl_fixed_to_int(grab->touch->grab_y + move->dy); |
| 1532 | |
Kristian Høgsberg | 8e80a31 | 2014-01-17 15:18:10 -0800 | [diff] [blame] | 1533 | if (!shsurf || !move->active) |
Rusty Lynch | 1084da5 | 2013-08-15 09:10:08 -0700 | [diff] [blame] | 1534 | return; |
| 1535 | |
| 1536 | es = shsurf->surface; |
| 1537 | |
Jason Ekstrand | 918f2dd | 2013-12-02 21:01:53 -0600 | [diff] [blame] | 1538 | weston_view_set_position(shsurf->view, dx, dy); |
Rusty Lynch | 1084da5 | 2013-08-15 09:10:08 -0700 | [diff] [blame] | 1539 | |
| 1540 | weston_compositor_schedule_repaint(es->compositor); |
| 1541 | } |
| 1542 | |
Jonas Ådahl | 1ea343e | 2013-10-25 23:18:05 +0200 | [diff] [blame] | 1543 | static void |
Jonas Ådahl | 1679f23 | 2014-04-12 09:39:51 +0200 | [diff] [blame] | 1544 | touch_move_grab_frame(struct weston_touch_grab *grab) |
| 1545 | { |
| 1546 | } |
| 1547 | |
| 1548 | static void |
Jonas Ådahl | 1ea343e | 2013-10-25 23:18:05 +0200 | [diff] [blame] | 1549 | touch_move_grab_cancel(struct weston_touch_grab *grab) |
| 1550 | { |
| 1551 | struct weston_touch_move_grab *move = |
| 1552 | (struct weston_touch_move_grab *) container_of( |
| 1553 | grab, struct shell_touch_grab, grab); |
| 1554 | |
| 1555 | shell_touch_grab_end(&move->base); |
| 1556 | free(move); |
| 1557 | } |
| 1558 | |
Rusty Lynch | 1084da5 | 2013-08-15 09:10:08 -0700 | [diff] [blame] | 1559 | static const struct weston_touch_grab_interface touch_move_grab_interface = { |
| 1560 | touch_move_grab_down, |
| 1561 | touch_move_grab_up, |
| 1562 | touch_move_grab_motion, |
Jonas Ådahl | 1679f23 | 2014-04-12 09:39:51 +0200 | [diff] [blame] | 1563 | touch_move_grab_frame, |
Jonas Ådahl | 1ea343e | 2013-10-25 23:18:05 +0200 | [diff] [blame] | 1564 | touch_move_grab_cancel, |
Rusty Lynch | 1084da5 | 2013-08-15 09:10:08 -0700 | [diff] [blame] | 1565 | }; |
| 1566 | |
| 1567 | static int |
Derek Foreman | b7674ae | 2015-07-15 13:00:37 -0500 | [diff] [blame] | 1568 | surface_touch_move(struct shell_surface *shsurf, struct weston_touch *touch) |
Rusty Lynch | 1084da5 | 2013-08-15 09:10:08 -0700 | [diff] [blame] | 1569 | { |
| 1570 | struct weston_touch_move_grab *move; |
| 1571 | |
| 1572 | if (!shsurf) |
| 1573 | return -1; |
| 1574 | |
Ander Conselvan de Oliveira | 6d43f04 | 2014-05-07 14:22:23 +0300 | [diff] [blame] | 1575 | if (shsurf->state.fullscreen || shsurf->state.maximized) |
Rusty Lynch | 1084da5 | 2013-08-15 09:10:08 -0700 | [diff] [blame] | 1576 | return 0; |
| 1577 | |
| 1578 | move = malloc(sizeof *move); |
| 1579 | if (!move) |
| 1580 | return -1; |
| 1581 | |
Kristian Høgsberg | 8e80a31 | 2014-01-17 15:18:10 -0800 | [diff] [blame] | 1582 | move->active = 1; |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 1583 | move->dx = wl_fixed_from_double(shsurf->view->geometry.x) - |
Derek Foreman | b7674ae | 2015-07-15 13:00:37 -0500 | [diff] [blame] | 1584 | touch->grab_x; |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 1585 | move->dy = wl_fixed_from_double(shsurf->view->geometry.y) - |
Derek Foreman | b7674ae | 2015-07-15 13:00:37 -0500 | [diff] [blame] | 1586 | touch->grab_y; |
Rusty Lynch | 1084da5 | 2013-08-15 09:10:08 -0700 | [diff] [blame] | 1587 | |
| 1588 | shell_touch_grab_start(&move->base, &touch_move_grab_interface, shsurf, |
Derek Foreman | b7674ae | 2015-07-15 13:00:37 -0500 | [diff] [blame] | 1589 | touch); |
Rusty Lynch | 1084da5 | 2013-08-15 09:10:08 -0700 | [diff] [blame] | 1590 | |
| 1591 | return 0; |
| 1592 | } |
| 1593 | |
| 1594 | static void |
Kristian Høgsberg | 6848c25 | 2013-05-08 22:02:59 -0400 | [diff] [blame] | 1595 | noop_grab_focus(struct weston_pointer_grab *grab) |
Kristian Høgsberg | 9ddb826 | 2012-01-04 21:30:29 -0500 | [diff] [blame] | 1596 | { |
Kristian Høgsberg | 9ddb826 | 2012-01-04 21:30:29 -0500 | [diff] [blame] | 1597 | } |
| 1598 | |
| 1599 | static void |
Jonas Ådahl | 0336ca0 | 2014-10-04 16:28:29 +0200 | [diff] [blame] | 1600 | noop_grab_axis(struct weston_pointer_grab *grab, |
| 1601 | uint32_t time, uint32_t axis, wl_fixed_t value) |
| 1602 | { |
| 1603 | } |
| 1604 | |
| 1605 | static void |
Kristian Høgsberg | ae356ae | 2014-04-29 16:03:54 -0700 | [diff] [blame] | 1606 | constrain_position(struct weston_move_grab *move, int *cx, int *cy) |
| 1607 | { |
| 1608 | struct shell_surface *shsurf = move->base.shsurf; |
| 1609 | struct weston_pointer *pointer = move->base.grab.pointer; |
Derek Foreman | 6feb0f9 | 2015-04-15 12:23:56 -0500 | [diff] [blame] | 1610 | int x, y, bottom; |
Kristian Høgsberg | ae356ae | 2014-04-29 16:03:54 -0700 | [diff] [blame] | 1611 | const int safety = 50; |
Derek Foreman | 6feb0f9 | 2015-04-15 12:23:56 -0500 | [diff] [blame] | 1612 | pixman_rectangle32_t area; |
Kristian Høgsberg | ae356ae | 2014-04-29 16:03:54 -0700 | [diff] [blame] | 1613 | |
| 1614 | x = wl_fixed_to_int(pointer->x + move->dx); |
| 1615 | y = wl_fixed_to_int(pointer->y + move->dy); |
| 1616 | |
Jonas Ådahl | 6d6fb61 | 2015-11-17 16:00:33 +0800 | [diff] [blame] | 1617 | if (shsurf->shell->panel_position == |
| 1618 | WESTON_DESKTOP_SHELL_PANEL_POSITION_TOP) { |
Derek Foreman | 6feb0f9 | 2015-04-15 12:23:56 -0500 | [diff] [blame] | 1619 | get_output_work_area(shsurf->shell, |
| 1620 | shsurf->surface->output, |
| 1621 | &area); |
Kristian Høgsberg | ae356ae | 2014-04-29 16:03:54 -0700 | [diff] [blame] | 1622 | |
Derek Foreman | 6feb0f9 | 2015-04-15 12:23:56 -0500 | [diff] [blame] | 1623 | bottom = y + shsurf->geometry.height + shsurf->geometry.y; |
| 1624 | if (bottom - safety < area.y) |
| 1625 | y = area.y + safety - shsurf->geometry.height |
| 1626 | - shsurf->geometry.y; |
Jonny Lamb | d73c694 | 2014-08-20 15:53:20 +0200 | [diff] [blame] | 1627 | |
| 1628 | if (move->client_initiated && |
Derek Foreman | 6feb0f9 | 2015-04-15 12:23:56 -0500 | [diff] [blame] | 1629 | y + shsurf->geometry.y < area.y) |
| 1630 | y = area.y - shsurf->geometry.y; |
| 1631 | |
Jonny Lamb | d73c694 | 2014-08-20 15:53:20 +0200 | [diff] [blame] | 1632 | } |
Kristian Høgsberg | ae356ae | 2014-04-29 16:03:54 -0700 | [diff] [blame] | 1633 | |
| 1634 | *cx = x; |
| 1635 | *cy = y; |
| 1636 | } |
| 1637 | |
| 1638 | static void |
Giulio Camuffo | 1959ab8 | 2013-11-14 23:42:52 +0100 | [diff] [blame] | 1639 | move_grab_motion(struct weston_pointer_grab *grab, uint32_t time, |
Jonas Ådahl | d251010 | 2014-10-05 21:39:14 +0200 | [diff] [blame] | 1640 | struct weston_pointer_motion_event *event) |
Kristian Høgsberg | 4cca349 | 2011-01-18 07:53:49 -0500 | [diff] [blame] | 1641 | { |
Kristian Høgsberg | 8334bc1 | 2012-01-03 10:29:47 -0500 | [diff] [blame] | 1642 | struct weston_move_grab *move = (struct weston_move_grab *) grab; |
Kristian Høgsberg | 02bbabb | 2013-05-06 22:15:05 -0400 | [diff] [blame] | 1643 | struct weston_pointer *pointer = grab->pointer; |
Ander Conselvan de Oliveira | fe0444a | 2012-04-04 17:48:05 +0300 | [diff] [blame] | 1644 | struct shell_surface *shsurf = move->base.shsurf; |
Kristian Høgsberg | ae356ae | 2014-04-29 16:03:54 -0700 | [diff] [blame] | 1645 | int cx, cy; |
Giulio Camuffo | 1959ab8 | 2013-11-14 23:42:52 +0100 | [diff] [blame] | 1646 | |
Jonas Ådahl | d251010 | 2014-10-05 21:39:14 +0200 | [diff] [blame] | 1647 | weston_pointer_move(pointer, event); |
Ander Conselvan de Oliveira | fe0444a | 2012-04-04 17:48:05 +0300 | [diff] [blame] | 1648 | if (!shsurf) |
| 1649 | return; |
| 1650 | |
Kristian Høgsberg | ae356ae | 2014-04-29 16:03:54 -0700 | [diff] [blame] | 1651 | constrain_position(move, &cx, &cy); |
| 1652 | |
| 1653 | weston_view_set_position(shsurf->view, cx, cy); |
Kristian Høgsberg | 4cca349 | 2011-01-18 07:53:49 -0500 | [diff] [blame] | 1654 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 1655 | weston_compositor_schedule_repaint(shsurf->surface->compositor); |
Kristian Høgsberg | 4cca349 | 2011-01-18 07:53:49 -0500 | [diff] [blame] | 1656 | } |
| 1657 | |
| 1658 | static void |
Kristian Høgsberg | 02bbabb | 2013-05-06 22:15:05 -0400 | [diff] [blame] | 1659 | move_grab_button(struct weston_pointer_grab *grab, |
Daniel Stone | 4dbadb1 | 2012-05-30 16:31:51 +0100 | [diff] [blame] | 1660 | uint32_t time, uint32_t button, uint32_t state_w) |
Kristian Høgsberg | 4cca349 | 2011-01-18 07:53:49 -0500 | [diff] [blame] | 1661 | { |
Ander Conselvan de Oliveira | fe0444a | 2012-04-04 17:48:05 +0300 | [diff] [blame] | 1662 | struct shell_grab *shell_grab = container_of(grab, struct shell_grab, |
| 1663 | grab); |
Kristian Høgsberg | 02bbabb | 2013-05-06 22:15:05 -0400 | [diff] [blame] | 1664 | struct weston_pointer *pointer = grab->pointer; |
Daniel Stone | 4dbadb1 | 2012-05-30 16:31:51 +0100 | [diff] [blame] | 1665 | enum wl_pointer_button_state state = state_w; |
Kristian Høgsberg | 4cca349 | 2011-01-18 07:53:49 -0500 | [diff] [blame] | 1666 | |
Daniel Stone | 4dbadb1 | 2012-05-30 16:31:51 +0100 | [diff] [blame] | 1667 | if (pointer->button_count == 0 && |
| 1668 | state == WL_POINTER_BUTTON_STATE_RELEASED) { |
Ander Conselvan de Oliveira | b9d2a0f | 2012-06-28 18:08:05 +0300 | [diff] [blame] | 1669 | shell_grab_end(shell_grab); |
Kristian Høgsberg | 9ddb826 | 2012-01-04 21:30:29 -0500 | [diff] [blame] | 1670 | free(grab); |
| 1671 | } |
Kristian Høgsberg | 4cca349 | 2011-01-18 07:53:49 -0500 | [diff] [blame] | 1672 | } |
| 1673 | |
Jonas Ådahl | 1ea343e | 2013-10-25 23:18:05 +0200 | [diff] [blame] | 1674 | static void |
| 1675 | move_grab_cancel(struct weston_pointer_grab *grab) |
| 1676 | { |
| 1677 | struct shell_grab *shell_grab = |
| 1678 | container_of(grab, struct shell_grab, grab); |
| 1679 | |
| 1680 | shell_grab_end(shell_grab); |
| 1681 | free(grab); |
| 1682 | } |
| 1683 | |
Kristian Høgsberg | 02bbabb | 2013-05-06 22:15:05 -0400 | [diff] [blame] | 1684 | static const struct weston_pointer_grab_interface move_grab_interface = { |
Kristian Høgsberg | 9ddb826 | 2012-01-04 21:30:29 -0500 | [diff] [blame] | 1685 | noop_grab_focus, |
Kristian Høgsberg | 4cca349 | 2011-01-18 07:53:49 -0500 | [diff] [blame] | 1686 | move_grab_motion, |
| 1687 | move_grab_button, |
Jonas Ådahl | 0336ca0 | 2014-10-04 16:28:29 +0200 | [diff] [blame] | 1688 | noop_grab_axis, |
Jonas Ådahl | 1ea343e | 2013-10-25 23:18:05 +0200 | [diff] [blame] | 1689 | move_grab_cancel, |
Kristian Høgsberg | 4cca349 | 2011-01-18 07:53:49 -0500 | [diff] [blame] | 1690 | }; |
| 1691 | |
Kristian Høgsberg | 9e31bff | 2012-08-01 00:08:07 -0400 | [diff] [blame] | 1692 | static int |
Derek Foreman | 794fa0e | 2015-07-15 13:00:38 -0500 | [diff] [blame] | 1693 | surface_move(struct shell_surface *shsurf, struct weston_pointer *pointer, |
Derek Foreman | cf7d95a | 2015-06-03 15:53:22 -0500 | [diff] [blame] | 1694 | bool client_initiated) |
Kristian Høgsberg | 9e31bff | 2012-08-01 00:08:07 -0400 | [diff] [blame] | 1695 | { |
| 1696 | struct weston_move_grab *move; |
| 1697 | |
| 1698 | if (!shsurf) |
| 1699 | return -1; |
| 1700 | |
Derek Foreman | 45a7c27 | 2015-09-11 14:27:40 -0500 | [diff] [blame] | 1701 | shsurf = find_toplevel_surface(shsurf); |
| 1702 | |
Kristian Høgsberg | a4b620e | 2014-04-30 16:05:49 -0700 | [diff] [blame] | 1703 | if (shsurf->grabbed || |
| 1704 | shsurf->state.fullscreen || shsurf->state.maximized) |
Kristian Høgsberg | 9e31bff | 2012-08-01 00:08:07 -0400 | [diff] [blame] | 1705 | return 0; |
| 1706 | |
| 1707 | move = malloc(sizeof *move); |
| 1708 | if (!move) |
| 1709 | return -1; |
| 1710 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 1711 | move->dx = wl_fixed_from_double(shsurf->view->geometry.x) - |
Derek Foreman | 794fa0e | 2015-07-15 13:00:38 -0500 | [diff] [blame] | 1712 | pointer->grab_x; |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 1713 | move->dy = wl_fixed_from_double(shsurf->view->geometry.y) - |
Derek Foreman | 794fa0e | 2015-07-15 13:00:38 -0500 | [diff] [blame] | 1714 | pointer->grab_y; |
Kristian Høgsberg | ae356ae | 2014-04-29 16:03:54 -0700 | [diff] [blame] | 1715 | move->client_initiated = client_initiated; |
Kristian Høgsberg | 9e31bff | 2012-08-01 00:08:07 -0400 | [diff] [blame] | 1716 | |
| 1717 | shell_grab_start(&move->base, &move_grab_interface, shsurf, |
Jonas Ådahl | 6d6fb61 | 2015-11-17 16:00:33 +0800 | [diff] [blame] | 1718 | pointer, WESTON_DESKTOP_SHELL_CURSOR_MOVE); |
Kristian Høgsberg | 9e31bff | 2012-08-01 00:08:07 -0400 | [diff] [blame] | 1719 | |
| 1720 | return 0; |
| 1721 | } |
| 1722 | |
| 1723 | static void |
Rafael Antognolli | e2a3455 | 2013-12-03 15:35:45 -0200 | [diff] [blame] | 1724 | common_surface_move(struct wl_resource *resource, |
| 1725 | struct wl_resource *seat_resource, uint32_t serial) |
Kristian Høgsberg | 9e31bff | 2012-08-01 00:08:07 -0400 | [diff] [blame] | 1726 | { |
Jason Ekstrand | 44a3863 | 2013-06-14 10:08:00 -0500 | [diff] [blame] | 1727 | struct weston_seat *seat = wl_resource_get_user_data(seat_resource); |
Derek Foreman | 1281a36 | 2015-07-31 16:55:32 -0500 | [diff] [blame] | 1728 | struct weston_pointer *pointer = weston_seat_get_pointer(seat); |
| 1729 | struct weston_touch *touch = weston_seat_get_touch(seat); |
Jason Ekstrand | 651f00e | 2013-06-14 10:07:54 -0500 | [diff] [blame] | 1730 | struct shell_surface *shsurf = wl_resource_get_user_data(resource); |
Giulio Camuffo | 61da3fc | 2013-04-25 13:57:45 +0300 | [diff] [blame] | 1731 | struct weston_surface *surface; |
Kristian Høgsberg | 9e31bff | 2012-08-01 00:08:07 -0400 | [diff] [blame] | 1732 | |
Derek Foreman | 1281a36 | 2015-07-31 16:55:32 -0500 | [diff] [blame] | 1733 | if (pointer && |
| 1734 | pointer->focus && |
| 1735 | pointer->button_count > 0 && |
| 1736 | pointer->grab_serial == serial) { |
| 1737 | surface = weston_surface_get_main_surface(pointer->focus->surface); |
U. Artie Eoff | cf5737a | 2014-01-17 10:08:25 -0800 | [diff] [blame] | 1738 | if ((surface == shsurf->surface) && |
Derek Foreman | 1281a36 | 2015-07-31 16:55:32 -0500 | [diff] [blame] | 1739 | (surface_move(shsurf, pointer, true) < 0)) |
Rusty Lynch | 1084da5 | 2013-08-15 09:10:08 -0700 | [diff] [blame] | 1740 | wl_resource_post_no_memory(resource); |
Derek Foreman | 1281a36 | 2015-07-31 16:55:32 -0500 | [diff] [blame] | 1741 | } else if (touch && |
| 1742 | touch->focus && |
| 1743 | touch->grab_serial == serial) { |
| 1744 | surface = weston_surface_get_main_surface(touch->focus->surface); |
U. Artie Eoff | cf5737a | 2014-01-17 10:08:25 -0800 | [diff] [blame] | 1745 | if ((surface == shsurf->surface) && |
Derek Foreman | 1281a36 | 2015-07-31 16:55:32 -0500 | [diff] [blame] | 1746 | (surface_touch_move(shsurf, touch) < 0)) |
Rusty Lynch | 1084da5 | 2013-08-15 09:10:08 -0700 | [diff] [blame] | 1747 | wl_resource_post_no_memory(resource); |
| 1748 | } |
Kristian Høgsberg | 9e31bff | 2012-08-01 00:08:07 -0400 | [diff] [blame] | 1749 | } |
| 1750 | |
Rafael Antognolli | e2a3455 | 2013-12-03 15:35:45 -0200 | [diff] [blame] | 1751 | static void |
| 1752 | shell_surface_move(struct wl_client *client, struct wl_resource *resource, |
| 1753 | struct wl_resource *seat_resource, uint32_t serial) |
| 1754 | { |
| 1755 | common_surface_move(resource, seat_resource, serial); |
| 1756 | } |
| 1757 | |
Kristian Høgsberg | 9e31bff | 2012-08-01 00:08:07 -0400 | [diff] [blame] | 1758 | struct weston_resize_grab { |
| 1759 | struct shell_grab base; |
| 1760 | uint32_t edges; |
| 1761 | int32_t width, height; |
| 1762 | }; |
| 1763 | |
| 1764 | static void |
Giulio Camuffo | 1959ab8 | 2013-11-14 23:42:52 +0100 | [diff] [blame] | 1765 | resize_grab_motion(struct weston_pointer_grab *grab, uint32_t time, |
Jonas Ådahl | d251010 | 2014-10-05 21:39:14 +0200 | [diff] [blame] | 1766 | struct weston_pointer_motion_event *event) |
Kristian Høgsberg | 9e31bff | 2012-08-01 00:08:07 -0400 | [diff] [blame] | 1767 | { |
| 1768 | struct weston_resize_grab *resize = (struct weston_resize_grab *) grab; |
Kristian Høgsberg | 02bbabb | 2013-05-06 22:15:05 -0400 | [diff] [blame] | 1769 | struct weston_pointer *pointer = grab->pointer; |
Kristian Høgsberg | 9e31bff | 2012-08-01 00:08:07 -0400 | [diff] [blame] | 1770 | struct shell_surface *shsurf = resize->base.shsurf; |
| 1771 | int32_t width, height; |
| 1772 | wl_fixed_t from_x, from_y; |
| 1773 | wl_fixed_t to_x, to_y; |
| 1774 | |
Jonas Ådahl | d251010 | 2014-10-05 21:39:14 +0200 | [diff] [blame] | 1775 | weston_pointer_move(pointer, event); |
Giulio Camuffo | 1959ab8 | 2013-11-14 23:42:52 +0100 | [diff] [blame] | 1776 | |
Kristian Høgsberg | e0b9d5b | 2014-04-30 13:45:49 -0700 | [diff] [blame] | 1777 | if (!shsurf) |
Kristian Høgsberg | 9e31bff | 2012-08-01 00:08:07 -0400 | [diff] [blame] | 1778 | return; |
| 1779 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 1780 | weston_view_from_global_fixed(shsurf->view, |
| 1781 | pointer->grab_x, pointer->grab_y, |
| 1782 | &from_x, &from_y); |
| 1783 | weston_view_from_global_fixed(shsurf->view, |
| 1784 | pointer->x, pointer->y, &to_x, &to_y); |
Kristian Høgsberg | 9e31bff | 2012-08-01 00:08:07 -0400 | [diff] [blame] | 1785 | |
| 1786 | width = resize->width; |
| 1787 | if (resize->edges & WL_SHELL_SURFACE_RESIZE_LEFT) { |
| 1788 | width += wl_fixed_to_int(from_x - to_x); |
| 1789 | } else if (resize->edges & WL_SHELL_SURFACE_RESIZE_RIGHT) { |
| 1790 | width += wl_fixed_to_int(to_x - from_x); |
| 1791 | } |
| 1792 | |
| 1793 | height = resize->height; |
| 1794 | if (resize->edges & WL_SHELL_SURFACE_RESIZE_TOP) { |
| 1795 | height += wl_fixed_to_int(from_y - to_y); |
| 1796 | } else if (resize->edges & WL_SHELL_SURFACE_RESIZE_BOTTOM) { |
| 1797 | height += wl_fixed_to_int(to_y - from_y); |
| 1798 | } |
| 1799 | |
Derek Foreman | 70ac0ed | 2015-03-18 11:16:33 -0500 | [diff] [blame] | 1800 | if (width < 1) |
| 1801 | width = 1; |
| 1802 | if (height < 1) |
| 1803 | height = 1; |
Jasper St. Pierre | ac985be | 2014-04-28 11:19:28 -0400 | [diff] [blame] | 1804 | shsurf->client->send_configure(shsurf->surface, width, height); |
Kristian Høgsberg | 9e31bff | 2012-08-01 00:08:07 -0400 | [diff] [blame] | 1805 | } |
| 1806 | |
| 1807 | static void |
Jasper St. Pierre | ac985be | 2014-04-28 11:19:28 -0400 | [diff] [blame] | 1808 | 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] | 1809 | { |
| 1810 | struct shell_surface *shsurf = get_shell_surface(surface); |
| 1811 | |
U. Artie Eoff | cf5737a | 2014-01-17 10:08:25 -0800 | [diff] [blame] | 1812 | assert(shsurf); |
| 1813 | |
Kristian Høgsberg | e0b9d5b | 2014-04-30 13:45:49 -0700 | [diff] [blame] | 1814 | if (shsurf->resource) |
| 1815 | wl_shell_surface_send_configure(shsurf->resource, |
Jasper St. Pierre | ac985be | 2014-04-28 11:19:28 -0400 | [diff] [blame] | 1816 | shsurf->resize_edges, |
| 1817 | width, height); |
Kristian Høgsberg | 9e31bff | 2012-08-01 00:08:07 -0400 | [diff] [blame] | 1818 | } |
| 1819 | |
| 1820 | static const struct weston_shell_client shell_client = { |
Giulio Camuffo | f05d18f | 2015-12-11 20:57:05 +0200 | [diff] [blame] | 1821 | send_configure, |
| 1822 | NULL |
Kristian Høgsberg | 9e31bff | 2012-08-01 00:08:07 -0400 | [diff] [blame] | 1823 | }; |
| 1824 | |
| 1825 | static void |
Kristian Høgsberg | 02bbabb | 2013-05-06 22:15:05 -0400 | [diff] [blame] | 1826 | resize_grab_button(struct weston_pointer_grab *grab, |
Kristian Høgsberg | 9e31bff | 2012-08-01 00:08:07 -0400 | [diff] [blame] | 1827 | uint32_t time, uint32_t button, uint32_t state_w) |
| 1828 | { |
| 1829 | struct weston_resize_grab *resize = (struct weston_resize_grab *) grab; |
Kristian Høgsberg | 02bbabb | 2013-05-06 22:15:05 -0400 | [diff] [blame] | 1830 | struct weston_pointer *pointer = grab->pointer; |
Kristian Høgsberg | 9e31bff | 2012-08-01 00:08:07 -0400 | [diff] [blame] | 1831 | enum wl_pointer_button_state state = state_w; |
| 1832 | |
| 1833 | if (pointer->button_count == 0 && |
| 1834 | state == WL_POINTER_BUTTON_STATE_RELEASED) { |
| 1835 | shell_grab_end(&resize->base); |
| 1836 | free(grab); |
| 1837 | } |
| 1838 | } |
| 1839 | |
Jonas Ådahl | 1ea343e | 2013-10-25 23:18:05 +0200 | [diff] [blame] | 1840 | static void |
| 1841 | resize_grab_cancel(struct weston_pointer_grab *grab) |
| 1842 | { |
| 1843 | struct weston_resize_grab *resize = (struct weston_resize_grab *) grab; |
| 1844 | |
| 1845 | shell_grab_end(&resize->base); |
| 1846 | free(grab); |
| 1847 | } |
| 1848 | |
Kristian Høgsberg | 02bbabb | 2013-05-06 22:15:05 -0400 | [diff] [blame] | 1849 | static const struct weston_pointer_grab_interface resize_grab_interface = { |
Kristian Høgsberg | 9e31bff | 2012-08-01 00:08:07 -0400 | [diff] [blame] | 1850 | noop_grab_focus, |
| 1851 | resize_grab_motion, |
| 1852 | resize_grab_button, |
Jonas Ådahl | 0336ca0 | 2014-10-04 16:28:29 +0200 | [diff] [blame] | 1853 | noop_grab_axis, |
Jonas Ådahl | 1ea343e | 2013-10-25 23:18:05 +0200 | [diff] [blame] | 1854 | resize_grab_cancel, |
Kristian Høgsberg | 9e31bff | 2012-08-01 00:08:07 -0400 | [diff] [blame] | 1855 | }; |
| 1856 | |
Giulio Camuffo | b836664 | 2013-04-25 13:57:46 +0300 | [diff] [blame] | 1857 | /* |
| 1858 | * Returns the bounding box of a surface and all its sub-surfaces, |
| 1859 | * in the surface coordinates system. */ |
| 1860 | static void |
| 1861 | surface_subsurfaces_boundingbox(struct weston_surface *surface, int32_t *x, |
| 1862 | int32_t *y, int32_t *w, int32_t *h) { |
| 1863 | pixman_region32_t region; |
| 1864 | pixman_box32_t *box; |
| 1865 | struct weston_subsurface *subsurface; |
| 1866 | |
| 1867 | pixman_region32_init_rect(®ion, 0, 0, |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 1868 | surface->width, |
| 1869 | surface->height); |
Giulio Camuffo | b836664 | 2013-04-25 13:57:46 +0300 | [diff] [blame] | 1870 | |
| 1871 | wl_list_for_each(subsurface, &surface->subsurface_list, parent_link) { |
| 1872 | pixman_region32_union_rect(®ion, ®ion, |
| 1873 | subsurface->position.x, |
| 1874 | subsurface->position.y, |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 1875 | subsurface->surface->width, |
| 1876 | subsurface->surface->height); |
Giulio Camuffo | b836664 | 2013-04-25 13:57:46 +0300 | [diff] [blame] | 1877 | } |
| 1878 | |
| 1879 | box = pixman_region32_extents(®ion); |
| 1880 | if (x) |
| 1881 | *x = box->x1; |
| 1882 | if (y) |
| 1883 | *y = box->y1; |
| 1884 | if (w) |
| 1885 | *w = box->x2 - box->x1; |
| 1886 | if (h) |
| 1887 | *h = box->y2 - box->y1; |
| 1888 | |
| 1889 | pixman_region32_fini(®ion); |
| 1890 | } |
| 1891 | |
Kristian Høgsberg | 9e31bff | 2012-08-01 00:08:07 -0400 | [diff] [blame] | 1892 | static int |
| 1893 | surface_resize(struct shell_surface *shsurf, |
Derek Foreman | 8fbebbd | 2015-07-15 13:00:40 -0500 | [diff] [blame] | 1894 | struct weston_pointer *pointer, uint32_t edges) |
Kristian Høgsberg | 9e31bff | 2012-08-01 00:08:07 -0400 | [diff] [blame] | 1895 | { |
| 1896 | struct weston_resize_grab *resize; |
Ondřej Majerech | ae9c4fc | 2014-08-21 15:47:22 +0200 | [diff] [blame] | 1897 | const unsigned resize_topbottom = |
| 1898 | WL_SHELL_SURFACE_RESIZE_TOP | WL_SHELL_SURFACE_RESIZE_BOTTOM; |
| 1899 | const unsigned resize_leftright = |
| 1900 | WL_SHELL_SURFACE_RESIZE_LEFT | WL_SHELL_SURFACE_RESIZE_RIGHT; |
| 1901 | const unsigned resize_any = resize_topbottom | resize_leftright; |
Kristian Høgsberg | 9e31bff | 2012-08-01 00:08:07 -0400 | [diff] [blame] | 1902 | |
Kristian Høgsberg | a4b620e | 2014-04-30 16:05:49 -0700 | [diff] [blame] | 1903 | if (shsurf->grabbed || |
| 1904 | shsurf->state.fullscreen || shsurf->state.maximized) |
Kristian Høgsberg | 9e31bff | 2012-08-01 00:08:07 -0400 | [diff] [blame] | 1905 | return 0; |
| 1906 | |
Ondřej Majerech | ae9c4fc | 2014-08-21 15:47:22 +0200 | [diff] [blame] | 1907 | /* Check for invalid edge combinations. */ |
| 1908 | if (edges == WL_SHELL_SURFACE_RESIZE_NONE || edges > resize_any || |
| 1909 | (edges & resize_topbottom) == resize_topbottom || |
| 1910 | (edges & resize_leftright) == resize_leftright) |
Kristian Høgsberg | 9e31bff | 2012-08-01 00:08:07 -0400 | [diff] [blame] | 1911 | return 0; |
| 1912 | |
| 1913 | resize = malloc(sizeof *resize); |
| 1914 | if (!resize) |
| 1915 | return -1; |
| 1916 | |
| 1917 | resize->edges = edges; |
Kristian Høgsberg | 9e31bff | 2012-08-01 00:08:07 -0400 | [diff] [blame] | 1918 | |
Jasper St. Pierre | ccf48fb | 2014-05-02 10:21:38 -0400 | [diff] [blame] | 1919 | resize->width = shsurf->geometry.width; |
| 1920 | resize->height = shsurf->geometry.height; |
Jasper St. Pierre | bd65e50 | 2014-07-14 16:28:48 -0400 | [diff] [blame] | 1921 | |
Kristian Høgsberg | 44cd196 | 2014-02-05 21:36:04 -0800 | [diff] [blame] | 1922 | shsurf->resize_edges = edges; |
Jasper St. Pierre | 5befdda | 2014-05-06 08:50:47 -0400 | [diff] [blame] | 1923 | shell_surface_state_changed(shsurf); |
Kristian Høgsberg | 9e31bff | 2012-08-01 00:08:07 -0400 | [diff] [blame] | 1924 | shell_grab_start(&resize->base, &resize_grab_interface, shsurf, |
Derek Foreman | 8fbebbd | 2015-07-15 13:00:40 -0500 | [diff] [blame] | 1925 | pointer, edges); |
Kristian Høgsberg | 9e31bff | 2012-08-01 00:08:07 -0400 | [diff] [blame] | 1926 | |
| 1927 | return 0; |
| 1928 | } |
| 1929 | |
| 1930 | static void |
Rafael Antognolli | e2a3455 | 2013-12-03 15:35:45 -0200 | [diff] [blame] | 1931 | common_surface_resize(struct wl_resource *resource, |
| 1932 | struct wl_resource *seat_resource, uint32_t serial, |
| 1933 | uint32_t edges) |
Kristian Høgsberg | 9e31bff | 2012-08-01 00:08:07 -0400 | [diff] [blame] | 1934 | { |
Jason Ekstrand | 44a3863 | 2013-06-14 10:08:00 -0500 | [diff] [blame] | 1935 | struct weston_seat *seat = wl_resource_get_user_data(seat_resource); |
Derek Foreman | 1281a36 | 2015-07-31 16:55:32 -0500 | [diff] [blame] | 1936 | struct weston_pointer *pointer = weston_seat_get_pointer(seat); |
Jason Ekstrand | 651f00e | 2013-06-14 10:07:54 -0500 | [diff] [blame] | 1937 | struct shell_surface *shsurf = wl_resource_get_user_data(resource); |
Giulio Camuffo | 61da3fc | 2013-04-25 13:57:45 +0300 | [diff] [blame] | 1938 | struct weston_surface *surface; |
Kristian Høgsberg | 9e31bff | 2012-08-01 00:08:07 -0400 | [diff] [blame] | 1939 | |
Derek Foreman | 1281a36 | 2015-07-31 16:55:32 -0500 | [diff] [blame] | 1940 | if (!pointer || |
| 1941 | pointer->button_count == 0 || |
| 1942 | pointer->grab_serial != serial || |
| 1943 | pointer->focus == NULL) |
Kristian Høgsberg | 70f2901 | 2014-01-09 15:43:17 -0800 | [diff] [blame] | 1944 | return; |
| 1945 | |
Derek Foreman | 1281a36 | 2015-07-31 16:55:32 -0500 | [diff] [blame] | 1946 | surface = weston_surface_get_main_surface(pointer->focus->surface); |
Kristian Høgsberg | 70f2901 | 2014-01-09 15:43:17 -0800 | [diff] [blame] | 1947 | if (surface != shsurf->surface) |
Kristian Høgsberg | 9e31bff | 2012-08-01 00:08:07 -0400 | [diff] [blame] | 1948 | return; |
| 1949 | |
Derek Foreman | 1281a36 | 2015-07-31 16:55:32 -0500 | [diff] [blame] | 1950 | if (surface_resize(shsurf, pointer, edges) < 0) |
Kristian Høgsberg | 9e31bff | 2012-08-01 00:08:07 -0400 | [diff] [blame] | 1951 | wl_resource_post_no_memory(resource); |
| 1952 | } |
| 1953 | |
Scott Moreau | c3e54eb | 2012-04-17 19:06:20 -0600 | [diff] [blame] | 1954 | static void |
Rafael Antognolli | e2a3455 | 2013-12-03 15:35:45 -0200 | [diff] [blame] | 1955 | shell_surface_resize(struct wl_client *client, struct wl_resource *resource, |
| 1956 | struct wl_resource *seat_resource, uint32_t serial, |
| 1957 | uint32_t edges) |
| 1958 | { |
| 1959 | common_surface_resize(resource, seat_resource, serial, edges); |
| 1960 | } |
| 1961 | |
| 1962 | static void |
Kristian Høgsberg | 6848c25 | 2013-05-08 22:02:59 -0400 | [diff] [blame] | 1963 | busy_cursor_grab_focus(struct weston_pointer_grab *base) |
Scott Moreau | c3e54eb | 2012-04-17 19:06:20 -0600 | [diff] [blame] | 1964 | { |
Kristian Høgsberg | d56bd90 | 2012-06-05 09:58:51 -0400 | [diff] [blame] | 1965 | struct shell_grab *grab = (struct shell_grab *) base; |
Kristian Høgsberg | 6848c25 | 2013-05-08 22:02:59 -0400 | [diff] [blame] | 1966 | struct weston_pointer *pointer = base->pointer; |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 1967 | struct weston_view *view; |
Kristian Høgsberg | 6848c25 | 2013-05-08 22:02:59 -0400 | [diff] [blame] | 1968 | wl_fixed_t sx, sy; |
| 1969 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 1970 | view = weston_compositor_pick_view(pointer->seat->compositor, |
| 1971 | pointer->x, pointer->y, |
| 1972 | &sx, &sy); |
Scott Moreau | c3e54eb | 2012-04-17 19:06:20 -0600 | [diff] [blame] | 1973 | |
Kristian Høgsberg | 2bff94e | 2014-02-11 12:22:51 -0800 | [diff] [blame] | 1974 | if (!grab->shsurf || grab->shsurf->surface != view->surface) { |
| 1975 | shell_grab_end(grab); |
| 1976 | free(grab); |
| 1977 | } |
Scott Moreau | c3e54eb | 2012-04-17 19:06:20 -0600 | [diff] [blame] | 1978 | } |
| 1979 | |
| 1980 | static void |
Giulio Camuffo | 1959ab8 | 2013-11-14 23:42:52 +0100 | [diff] [blame] | 1981 | busy_cursor_grab_motion(struct weston_pointer_grab *grab, uint32_t time, |
Jonas Ådahl | d251010 | 2014-10-05 21:39:14 +0200 | [diff] [blame] | 1982 | struct weston_pointer_motion_event *event) |
Scott Moreau | c3e54eb | 2012-04-17 19:06:20 -0600 | [diff] [blame] | 1983 | { |
Jonas Ådahl | d251010 | 2014-10-05 21:39:14 +0200 | [diff] [blame] | 1984 | weston_pointer_move(grab->pointer, event); |
Kristian Høgsberg | d56bd90 | 2012-06-05 09:58:51 -0400 | [diff] [blame] | 1985 | } |
Scott Moreau | c3e54eb | 2012-04-17 19:06:20 -0600 | [diff] [blame] | 1986 | |
Kristian Høgsberg | d56bd90 | 2012-06-05 09:58:51 -0400 | [diff] [blame] | 1987 | static void |
Kristian Høgsberg | 02bbabb | 2013-05-06 22:15:05 -0400 | [diff] [blame] | 1988 | busy_cursor_grab_button(struct weston_pointer_grab *base, |
Kristian Høgsberg | d56bd90 | 2012-06-05 09:58:51 -0400 | [diff] [blame] | 1989 | uint32_t time, uint32_t button, uint32_t state) |
| 1990 | { |
Kristian Høgsberg | bbe9839 | 2012-08-01 00:20:21 -0400 | [diff] [blame] | 1991 | struct shell_grab *grab = (struct shell_grab *) base; |
Kristian Høgsberg | e122b7b | 2013-05-08 16:47:00 -0400 | [diff] [blame] | 1992 | struct shell_surface *shsurf = grab->shsurf; |
Derek Foreman | 794fa0e | 2015-07-15 13:00:38 -0500 | [diff] [blame] | 1993 | struct weston_pointer *pointer = grab->grab.pointer; |
| 1994 | struct weston_seat *seat = pointer->seat; |
Kristian Høgsberg | bbe9839 | 2012-08-01 00:20:21 -0400 | [diff] [blame] | 1995 | |
Kristian Høgsberg | bbe9839 | 2012-08-01 00:20:21 -0400 | [diff] [blame] | 1996 | if (shsurf && button == BTN_LEFT && state) { |
Emilio Pozuelo Monfort | 9e7c759 | 2014-01-30 14:01:10 +0100 | [diff] [blame] | 1997 | activate(shsurf->shell, shsurf->surface, seat, true); |
Derek Foreman | 794fa0e | 2015-07-15 13:00:38 -0500 | [diff] [blame] | 1998 | surface_move(shsurf, pointer, false); |
Kristian Høgsberg | 0c36903 | 2013-02-14 21:31:44 -0500 | [diff] [blame] | 1999 | } else if (shsurf && button == BTN_RIGHT && state) { |
Emilio Pozuelo Monfort | 9e7c759 | 2014-01-30 14:01:10 +0100 | [diff] [blame] | 2000 | activate(shsurf->shell, shsurf->surface, seat, true); |
Derek Foreman | 74de469 | 2015-07-15 13:00:39 -0500 | [diff] [blame] | 2001 | surface_rotate(shsurf, pointer); |
Kristian Høgsberg | bbe9839 | 2012-08-01 00:20:21 -0400 | [diff] [blame] | 2002 | } |
Kristian Høgsberg | d56bd90 | 2012-06-05 09:58:51 -0400 | [diff] [blame] | 2003 | } |
| 2004 | |
Jonas Ådahl | 1ea343e | 2013-10-25 23:18:05 +0200 | [diff] [blame] | 2005 | static void |
| 2006 | busy_cursor_grab_cancel(struct weston_pointer_grab *base) |
| 2007 | { |
| 2008 | struct shell_grab *grab = (struct shell_grab *) base; |
| 2009 | |
| 2010 | shell_grab_end(grab); |
| 2011 | free(grab); |
| 2012 | } |
| 2013 | |
Kristian Høgsberg | 02bbabb | 2013-05-06 22:15:05 -0400 | [diff] [blame] | 2014 | static const struct weston_pointer_grab_interface busy_cursor_grab_interface = { |
Kristian Høgsberg | d56bd90 | 2012-06-05 09:58:51 -0400 | [diff] [blame] | 2015 | busy_cursor_grab_focus, |
| 2016 | busy_cursor_grab_motion, |
| 2017 | busy_cursor_grab_button, |
Jonas Ådahl | 0336ca0 | 2014-10-04 16:28:29 +0200 | [diff] [blame] | 2018 | noop_grab_axis, |
Jonas Ådahl | 1ea343e | 2013-10-25 23:18:05 +0200 | [diff] [blame] | 2019 | busy_cursor_grab_cancel, |
Kristian Høgsberg | d56bd90 | 2012-06-05 09:58:51 -0400 | [diff] [blame] | 2020 | }; |
| 2021 | |
| 2022 | static void |
Kristian Høgsberg | 02bbabb | 2013-05-06 22:15:05 -0400 | [diff] [blame] | 2023 | set_busy_cursor(struct shell_surface *shsurf, struct weston_pointer *pointer) |
Kristian Høgsberg | d56bd90 | 2012-06-05 09:58:51 -0400 | [diff] [blame] | 2024 | { |
| 2025 | struct shell_grab *grab; |
Kristian Høgsberg | d56bd90 | 2012-06-05 09:58:51 -0400 | [diff] [blame] | 2026 | |
Kristian Høgsberg | 2bff94e | 2014-02-11 12:22:51 -0800 | [diff] [blame] | 2027 | if (pointer->grab->interface == &busy_cursor_grab_interface) |
| 2028 | return; |
| 2029 | |
Kristian Høgsberg | d56bd90 | 2012-06-05 09:58:51 -0400 | [diff] [blame] | 2030 | grab = malloc(sizeof *grab); |
| 2031 | if (!grab) |
Scott Moreau | c3e54eb | 2012-04-17 19:06:20 -0600 | [diff] [blame] | 2032 | return; |
| 2033 | |
Ander Conselvan de Oliveira | b9d2a0f | 2012-06-28 18:08:05 +0300 | [diff] [blame] | 2034 | shell_grab_start(grab, &busy_cursor_grab_interface, shsurf, pointer, |
Jonas Ådahl | 6d6fb61 | 2015-11-17 16:00:33 +0800 | [diff] [blame] | 2035 | WESTON_DESKTOP_SHELL_CURSOR_BUSY); |
Ander Conselvan de Oliveira | e5a1aee | 2014-04-09 17:39:39 +0300 | [diff] [blame] | 2036 | /* Mark the shsurf as ungrabbed so that button binding is able |
| 2037 | * to move it. */ |
| 2038 | shsurf->grabbed = 0; |
Kristian Høgsberg | d56bd90 | 2012-06-05 09:58:51 -0400 | [diff] [blame] | 2039 | } |
Scott Moreau | c3e54eb | 2012-04-17 19:06:20 -0600 | [diff] [blame] | 2040 | |
Kristian Høgsberg | d56bd90 | 2012-06-05 09:58:51 -0400 | [diff] [blame] | 2041 | static void |
Kristian Høgsberg | 2bff94e | 2014-02-11 12:22:51 -0800 | [diff] [blame] | 2042 | end_busy_cursor(struct weston_compositor *compositor, struct wl_client *client) |
Kristian Høgsberg | d56bd90 | 2012-06-05 09:58:51 -0400 | [diff] [blame] | 2043 | { |
Kristian Høgsberg | 2bff94e | 2014-02-11 12:22:51 -0800 | [diff] [blame] | 2044 | struct shell_grab *grab; |
| 2045 | struct weston_seat *seat; |
Kristian Høgsberg | d56bd90 | 2012-06-05 09:58:51 -0400 | [diff] [blame] | 2046 | |
Kristian Høgsberg | 2bff94e | 2014-02-11 12:22:51 -0800 | [diff] [blame] | 2047 | wl_list_for_each(seat, &compositor->seat_list, link) { |
Derek Foreman | 1281a36 | 2015-07-31 16:55:32 -0500 | [diff] [blame] | 2048 | struct weston_pointer *pointer = weston_seat_get_pointer(seat); |
| 2049 | |
| 2050 | if (!pointer) |
Kristian Høgsberg | 2bff94e | 2014-02-11 12:22:51 -0800 | [diff] [blame] | 2051 | continue; |
| 2052 | |
Derek Foreman | 1281a36 | 2015-07-31 16:55:32 -0500 | [diff] [blame] | 2053 | grab = (struct shell_grab *) pointer->grab; |
Kristian Høgsberg | 2bff94e | 2014-02-11 12:22:51 -0800 | [diff] [blame] | 2054 | if (grab->grab.interface == &busy_cursor_grab_interface && |
Derek Foreman | c0c1497 | 2015-09-11 14:30:39 -0500 | [diff] [blame] | 2055 | grab->shsurf->resource && |
Kristian Høgsberg | 2bff94e | 2014-02-11 12:22:51 -0800 | [diff] [blame] | 2056 | wl_resource_get_client(grab->shsurf->resource) == client) { |
| 2057 | shell_grab_end(grab); |
| 2058 | free(grab); |
| 2059 | } |
Scott Moreau | c3e54eb | 2012-04-17 19:06:20 -0600 | [diff] [blame] | 2060 | } |
Scott Moreau | c3e54eb | 2012-04-17 19:06:20 -0600 | [diff] [blame] | 2061 | } |
| 2062 | |
Scott Moreau | 9521d5e | 2012-04-19 13:06:17 -0600 | [diff] [blame] | 2063 | static void |
Kristian Høgsberg | 2bff94e | 2014-02-11 12:22:51 -0800 | [diff] [blame] | 2064 | handle_shell_client_destroy(struct wl_listener *listener, void *data); |
| 2065 | |
| 2066 | static int |
| 2067 | xdg_ping_timeout_handler(void *data) |
| 2068 | { |
| 2069 | struct shell_client *sc = data; |
| 2070 | struct weston_seat *seat; |
| 2071 | struct shell_surface *shsurf; |
| 2072 | |
| 2073 | /* Client is not responding */ |
| 2074 | sc->unresponsive = 1; |
Kristian Høgsberg | 2bff94e | 2014-02-11 12:22:51 -0800 | [diff] [blame] | 2075 | wl_list_for_each(seat, &sc->shell->compositor->seat_list, link) { |
Derek Foreman | 1281a36 | 2015-07-31 16:55:32 -0500 | [diff] [blame] | 2076 | struct weston_pointer *pointer = weston_seat_get_pointer(seat); |
| 2077 | |
| 2078 | if (!pointer || |
| 2079 | !pointer->focus || |
| 2080 | !pointer->focus->surface->resource) |
Kristian Høgsberg | 2bff94e | 2014-02-11 12:22:51 -0800 | [diff] [blame] | 2081 | continue; |
Michael Vetter | 2a18a52 | 2015-05-15 17:17:47 +0200 | [diff] [blame] | 2082 | |
Derek Foreman | 1281a36 | 2015-07-31 16:55:32 -0500 | [diff] [blame] | 2083 | shsurf = get_shell_surface(pointer->focus->surface); |
Kristian Høgsberg | 2bff94e | 2014-02-11 12:22:51 -0800 | [diff] [blame] | 2084 | if (shsurf && |
| 2085 | wl_resource_get_client(shsurf->resource) == sc->client) |
Derek Foreman | 1281a36 | 2015-07-31 16:55:32 -0500 | [diff] [blame] | 2086 | set_busy_cursor(shsurf, pointer); |
Kristian Høgsberg | 2bff94e | 2014-02-11 12:22:51 -0800 | [diff] [blame] | 2087 | } |
| 2088 | |
| 2089 | return 1; |
| 2090 | } |
| 2091 | |
| 2092 | static void |
| 2093 | handle_xdg_ping(struct shell_surface *shsurf, uint32_t serial) |
| 2094 | { |
| 2095 | struct weston_compositor *compositor = shsurf->shell->compositor; |
Jason Ekstrand | 9e9512f | 2014-04-16 21:12:10 -0500 | [diff] [blame] | 2096 | struct shell_client *sc = shsurf->owner; |
Kristian Høgsberg | 2bff94e | 2014-02-11 12:22:51 -0800 | [diff] [blame] | 2097 | struct wl_event_loop *loop; |
Kristian Høgsberg | dd62aba | 2014-02-12 09:56:19 -0800 | [diff] [blame] | 2098 | static const int ping_timeout = 200; |
Kristian Høgsberg | 2bff94e | 2014-02-11 12:22:51 -0800 | [diff] [blame] | 2099 | |
Kristian Høgsberg | 2bff94e | 2014-02-11 12:22:51 -0800 | [diff] [blame] | 2100 | if (sc->unresponsive) { |
| 2101 | xdg_ping_timeout_handler(sc); |
| 2102 | return; |
| 2103 | } |
| 2104 | |
| 2105 | sc->ping_serial = serial; |
| 2106 | loop = wl_display_get_event_loop(compositor->wl_display); |
| 2107 | if (sc->ping_timer == NULL) |
| 2108 | sc->ping_timer = |
| 2109 | wl_event_loop_add_timer(loop, |
| 2110 | xdg_ping_timeout_handler, sc); |
| 2111 | if (sc->ping_timer == NULL) |
| 2112 | return; |
| 2113 | |
| 2114 | wl_event_source_timer_update(sc->ping_timer, ping_timeout); |
| 2115 | |
Kristian Høgsberg | dd62aba | 2014-02-12 09:56:19 -0800 | [diff] [blame] | 2116 | if (shell_surface_is_xdg_surface(shsurf) || |
| 2117 | shell_surface_is_xdg_popup(shsurf)) |
| 2118 | xdg_shell_send_ping(sc->resource, serial); |
| 2119 | else if (shell_surface_is_wl_shell_surface(shsurf)) |
| 2120 | wl_shell_surface_send_ping(shsurf->resource, serial); |
Kristian Høgsberg | 2bff94e | 2014-02-11 12:22:51 -0800 | [diff] [blame] | 2121 | } |
| 2122 | |
Scott Moreau | ff1db4a | 2012-04-17 19:06:18 -0600 | [diff] [blame] | 2123 | static void |
| 2124 | ping_handler(struct weston_surface *surface, uint32_t serial) |
| 2125 | { |
Kristian Høgsberg | b71302e | 2012-05-10 12:28:35 -0400 | [diff] [blame] | 2126 | struct shell_surface *shsurf = get_shell_surface(surface); |
Scott Moreau | ff1db4a | 2012-04-17 19:06:18 -0600 | [diff] [blame] | 2127 | |
| 2128 | if (!shsurf) |
| 2129 | return; |
Jason Ekstrand | 651f00e | 2013-06-14 10:07:54 -0500 | [diff] [blame] | 2130 | if (!shsurf->resource) |
Kristian Høgsberg | ca535c1 | 2012-04-21 23:20:07 -0400 | [diff] [blame] | 2131 | return; |
Ander Conselvan de Oliveira | eac9a46 | 2012-07-16 14:15:48 +0300 | [diff] [blame] | 2132 | if (shsurf->surface == shsurf->shell->grab_surface) |
| 2133 | return; |
| 2134 | |
Kristian Høgsberg | dd62aba | 2014-02-12 09:56:19 -0800 | [diff] [blame] | 2135 | handle_xdg_ping(shsurf, serial); |
Scott Moreau | ff1db4a | 2012-04-17 19:06:18 -0600 | [diff] [blame] | 2136 | } |
| 2137 | |
| 2138 | static void |
Kristian Høgsberg | d56bd90 | 2012-06-05 09:58:51 -0400 | [diff] [blame] | 2139 | handle_pointer_focus(struct wl_listener *listener, void *data) |
| 2140 | { |
Kristian Høgsberg | 02bbabb | 2013-05-06 22:15:05 -0400 | [diff] [blame] | 2141 | struct weston_pointer *pointer = data; |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 2142 | struct weston_view *view = pointer->focus; |
Kristian Høgsberg | d56bd90 | 2012-06-05 09:58:51 -0400 | [diff] [blame] | 2143 | struct weston_compositor *compositor; |
Kristian Høgsberg | d56bd90 | 2012-06-05 09:58:51 -0400 | [diff] [blame] | 2144 | uint32_t serial; |
| 2145 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 2146 | if (!view) |
Kristian Høgsberg | d56bd90 | 2012-06-05 09:58:51 -0400 | [diff] [blame] | 2147 | return; |
| 2148 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 2149 | compositor = view->surface->compositor; |
Kristian Høgsberg | e11ef64 | 2014-02-11 16:35:22 -0800 | [diff] [blame] | 2150 | serial = wl_display_next_serial(compositor->wl_display); |
| 2151 | ping_handler(view->surface, serial); |
Kristian Høgsberg | d56bd90 | 2012-06-05 09:58:51 -0400 | [diff] [blame] | 2152 | } |
| 2153 | |
| 2154 | static void |
Jasper St. Pierre | faf27a9 | 2013-12-09 17:36:28 -0500 | [diff] [blame] | 2155 | shell_surface_lose_keyboard_focus(struct shell_surface *shsurf) |
| 2156 | { |
| 2157 | if (--shsurf->focus_count == 0) |
Jasper St. Pierre | 973d787 | 2014-05-06 08:44:29 -0400 | [diff] [blame] | 2158 | shell_surface_state_changed(shsurf); |
Jasper St. Pierre | faf27a9 | 2013-12-09 17:36:28 -0500 | [diff] [blame] | 2159 | } |
| 2160 | |
| 2161 | static void |
| 2162 | shell_surface_gain_keyboard_focus(struct shell_surface *shsurf) |
| 2163 | { |
| 2164 | if (shsurf->focus_count++ == 0) |
Jasper St. Pierre | 973d787 | 2014-05-06 08:44:29 -0400 | [diff] [blame] | 2165 | shell_surface_state_changed(shsurf); |
Jasper St. Pierre | faf27a9 | 2013-12-09 17:36:28 -0500 | [diff] [blame] | 2166 | } |
| 2167 | |
| 2168 | static void |
| 2169 | handle_keyboard_focus(struct wl_listener *listener, void *data) |
| 2170 | { |
| 2171 | struct weston_keyboard *keyboard = data; |
| 2172 | struct shell_seat *seat = get_shell_seat(keyboard->seat); |
| 2173 | |
| 2174 | if (seat->focused_surface) { |
| 2175 | struct shell_surface *shsurf = get_shell_surface(seat->focused_surface); |
| 2176 | if (shsurf) |
| 2177 | shell_surface_lose_keyboard_focus(shsurf); |
| 2178 | } |
| 2179 | |
| 2180 | seat->focused_surface = keyboard->focus; |
| 2181 | |
| 2182 | if (seat->focused_surface) { |
| 2183 | struct shell_surface *shsurf = get_shell_surface(seat->focused_surface); |
| 2184 | if (shsurf) |
| 2185 | shell_surface_gain_keyboard_focus(shsurf); |
| 2186 | } |
| 2187 | } |
| 2188 | |
| 2189 | static void |
Kristian Høgsberg | dd62aba | 2014-02-12 09:56:19 -0800 | [diff] [blame] | 2190 | shell_client_pong(struct shell_client *sc, uint32_t serial) |
Rafael Antognolli | e2a3455 | 2013-12-03 15:35:45 -0200 | [diff] [blame] | 2191 | { |
Kristian Høgsberg | dd62aba | 2014-02-12 09:56:19 -0800 | [diff] [blame] | 2192 | if (sc->ping_serial != serial) |
| 2193 | return; |
Rafael Antognolli | e2a3455 | 2013-12-03 15:35:45 -0200 | [diff] [blame] | 2194 | |
Kristian Høgsberg | dd62aba | 2014-02-12 09:56:19 -0800 | [diff] [blame] | 2195 | sc->unresponsive = 0; |
| 2196 | end_busy_cursor(sc->shell->compositor, sc->client); |
Rafael Antognolli | e2a3455 | 2013-12-03 15:35:45 -0200 | [diff] [blame] | 2197 | |
Kristian Høgsberg | dd62aba | 2014-02-12 09:56:19 -0800 | [diff] [blame] | 2198 | if (sc->ping_timer) { |
| 2199 | wl_event_source_remove(sc->ping_timer); |
| 2200 | sc->ping_timer = NULL; |
| 2201 | } |
| 2202 | |
| 2203 | } |
| 2204 | |
| 2205 | static void |
| 2206 | shell_surface_pong(struct wl_client *client, |
| 2207 | struct wl_resource *resource, uint32_t serial) |
| 2208 | { |
Jason Ekstrand | 9e9512f | 2014-04-16 21:12:10 -0500 | [diff] [blame] | 2209 | struct shell_surface *shsurf = wl_resource_get_user_data(resource); |
| 2210 | struct shell_client *sc = shsurf->owner; |
Kristian Høgsberg | dd62aba | 2014-02-12 09:56:19 -0800 | [diff] [blame] | 2211 | |
Kristian Høgsberg | dd62aba | 2014-02-12 09:56:19 -0800 | [diff] [blame] | 2212 | shell_client_pong(sc, serial); |
Rafael Antognolli | e2a3455 | 2013-12-03 15:35:45 -0200 | [diff] [blame] | 2213 | } |
| 2214 | |
| 2215 | static void |
Giulio Camuffo | 62942ad | 2013-09-11 18:20:47 +0200 | [diff] [blame] | 2216 | set_title(struct shell_surface *shsurf, const char *title) |
| 2217 | { |
| 2218 | free(shsurf->title); |
| 2219 | shsurf->title = strdup(title); |
Pekka Paalanen | b502654 | 2014-11-12 15:09:24 +0200 | [diff] [blame] | 2220 | shsurf->surface->timeline.force_refresh = 1; |
| 2221 | } |
| 2222 | |
| 2223 | static void |
Giulio Camuffo | a8e9b41 | 2015-01-27 19:10:37 +0200 | [diff] [blame] | 2224 | set_pid(struct shell_surface *shsurf, pid_t pid) |
| 2225 | { |
| 2226 | /* We have no use for it */ |
| 2227 | } |
| 2228 | |
| 2229 | static void |
Pekka Paalanen | b502654 | 2014-11-12 15:09:24 +0200 | [diff] [blame] | 2230 | set_type(struct shell_surface *shsurf, enum shell_surface_type t) |
| 2231 | { |
| 2232 | shsurf->type = t; |
| 2233 | shsurf->surface->timeline.force_refresh = 1; |
Giulio Camuffo | 62942ad | 2013-09-11 18:20:47 +0200 | [diff] [blame] | 2234 | } |
| 2235 | |
| 2236 | static void |
Jasper St. Pierre | ccf48fb | 2014-05-02 10:21:38 -0400 | [diff] [blame] | 2237 | set_window_geometry(struct shell_surface *shsurf, |
| 2238 | 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] | 2239 | { |
Jasper St. Pierre | ccf48fb | 2014-05-02 10:21:38 -0400 | [diff] [blame] | 2240 | shsurf->next_geometry.x = x; |
| 2241 | shsurf->next_geometry.y = y; |
| 2242 | shsurf->next_geometry.width = width; |
| 2243 | shsurf->next_geometry.height = height; |
| 2244 | shsurf->has_next_geometry = true; |
Kristian Høgsberg | e5c1ae9 | 2014-04-30 16:28:41 -0700 | [diff] [blame] | 2245 | } |
| 2246 | |
| 2247 | static void |
Kristian Høgsberg | e7afd91 | 2012-05-02 09:47:44 -0400 | [diff] [blame] | 2248 | shell_surface_set_title(struct wl_client *client, |
| 2249 | struct wl_resource *resource, const char *title) |
| 2250 | { |
Jason Ekstrand | 651f00e | 2013-06-14 10:07:54 -0500 | [diff] [blame] | 2251 | struct shell_surface *shsurf = wl_resource_get_user_data(resource); |
Kristian Høgsberg | e7afd91 | 2012-05-02 09:47:44 -0400 | [diff] [blame] | 2252 | |
Giulio Camuffo | 62942ad | 2013-09-11 18:20:47 +0200 | [diff] [blame] | 2253 | set_title(shsurf, title); |
Kristian Høgsberg | e7afd91 | 2012-05-02 09:47:44 -0400 | [diff] [blame] | 2254 | } |
| 2255 | |
| 2256 | static void |
| 2257 | shell_surface_set_class(struct wl_client *client, |
| 2258 | struct wl_resource *resource, const char *class) |
| 2259 | { |
Jason Ekstrand | 651f00e | 2013-06-14 10:07:54 -0500 | [diff] [blame] | 2260 | struct shell_surface *shsurf = wl_resource_get_user_data(resource); |
Kristian Høgsberg | e7afd91 | 2012-05-02 09:47:44 -0400 | [diff] [blame] | 2261 | |
| 2262 | free(shsurf->class); |
| 2263 | shsurf->class = strdup(class); |
Pekka Paalanen | b502654 | 2014-11-12 15:09:24 +0200 | [diff] [blame] | 2264 | shsurf->surface->timeline.force_refresh = 1; |
Kristian Høgsberg | e7afd91 | 2012-05-02 09:47:44 -0400 | [diff] [blame] | 2265 | } |
| 2266 | |
Alex Wu | 4539b08 | 2012-03-01 12:57:46 +0800 | [diff] [blame] | 2267 | static void |
Alexander Larsson | f82b6ca | 2013-05-28 16:23:39 +0200 | [diff] [blame] | 2268 | restore_output_mode(struct weston_output *output) |
| 2269 | { |
Derek Foreman | 6ae7bc9 | 2014-11-04 10:47:33 -0600 | [diff] [blame] | 2270 | if (output->original_mode) |
| 2271 | weston_output_mode_switch_to_native(output); |
Alexander Larsson | f82b6ca | 2013-05-28 16:23:39 +0200 | [diff] [blame] | 2272 | } |
| 2273 | |
| 2274 | static void |
| 2275 | restore_all_output_modes(struct weston_compositor *compositor) |
| 2276 | { |
| 2277 | struct weston_output *output; |
| 2278 | |
| 2279 | wl_list_for_each(output, &compositor->output_list, link) |
| 2280 | restore_output_mode(output); |
| 2281 | } |
| 2282 | |
Philip Withnall | 07926d9 | 2013-11-25 18:01:40 +0000 | [diff] [blame] | 2283 | /* The surface will be inserted into the list immediately after the link |
| 2284 | * returned by this function (i.e. will be stacked immediately above the |
| 2285 | * returned link). */ |
Giulio Camuffo | 412e6a5 | 2014-07-09 22:12:56 +0300 | [diff] [blame] | 2286 | static struct weston_layer_entry * |
Philip Withnall | 07926d9 | 2013-11-25 18:01:40 +0000 | [diff] [blame] | 2287 | shell_surface_calculate_layer_link (struct shell_surface *shsurf) |
| 2288 | { |
| 2289 | struct workspace *ws; |
Kristian Høgsberg | ead5242 | 2014-01-01 13:51:52 -0800 | [diff] [blame] | 2290 | struct weston_view *parent; |
Philip Withnall | 07926d9 | 2013-11-25 18:01:40 +0000 | [diff] [blame] | 2291 | |
| 2292 | switch (shsurf->type) { |
Ander Conselvan de Oliveira | ef6a7e4 | 2014-04-30 14:15:14 +0300 | [diff] [blame] | 2293 | case SHELL_SURFACE_XWAYLAND: |
| 2294 | return &shsurf->shell->fullscreen_layer.view_list; |
| 2295 | |
| 2296 | case SHELL_SURFACE_NONE: |
| 2297 | return NULL; |
| 2298 | |
Kristian Høgsberg | ead5242 | 2014-01-01 13:51:52 -0800 | [diff] [blame] | 2299 | case SHELL_SURFACE_POPUP: |
| 2300 | case SHELL_SURFACE_TOPLEVEL: |
Emilio Pozuelo Monfort | 9e7c759 | 2014-01-30 14:01:10 +0100 | [diff] [blame] | 2301 | if (shsurf->state.fullscreen && !shsurf->state.lowered) { |
Rafael Antognolli | 03b1659 | 2013-12-03 15:35:42 -0200 | [diff] [blame] | 2302 | return &shsurf->shell->fullscreen_layer.view_list; |
Rafael Antognolli | ed207b4 | 2013-12-03 15:35:43 -0200 | [diff] [blame] | 2303 | } else if (shsurf->parent) { |
Kristian Høgsberg | d55db69 | 2014-01-01 12:26:14 -0800 | [diff] [blame] | 2304 | /* Move the surface to its parent layer so |
| 2305 | * that surfaces which are transient for |
| 2306 | * fullscreen surfaces don't get hidden by the |
| 2307 | * fullscreen surfaces. */ |
Rafael Antognolli | ed207b4 | 2013-12-03 15:35:43 -0200 | [diff] [blame] | 2308 | |
| 2309 | /* TODO: Handle a parent with multiple views */ |
| 2310 | parent = get_default_view(shsurf->parent); |
| 2311 | if (parent) |
Giulio Camuffo | 412e6a5 | 2014-07-09 22:12:56 +0300 | [diff] [blame] | 2312 | return container_of(parent->layer_link.link.prev, |
| 2313 | struct weston_layer_entry, link); |
Rafael Antognolli | ed207b4 | 2013-12-03 15:35:43 -0200 | [diff] [blame] | 2314 | } |
Philip Withnall | 07926d9 | 2013-11-25 18:01:40 +0000 | [diff] [blame] | 2315 | |
Ander Conselvan de Oliveira | ef6a7e4 | 2014-04-30 14:15:14 +0300 | [diff] [blame] | 2316 | /* Move the surface to a normal workspace layer so that surfaces |
| 2317 | * which were previously fullscreen or transient are no longer |
| 2318 | * rendered on top. */ |
| 2319 | ws = get_current_workspace(shsurf->shell); |
| 2320 | return &ws->layer.view_list; |
Philip Withnall | 07926d9 | 2013-11-25 18:01:40 +0000 | [diff] [blame] | 2321 | } |
| 2322 | |
Ander Conselvan de Oliveira | ef6a7e4 | 2014-04-30 14:15:14 +0300 | [diff] [blame] | 2323 | assert(0 && "Unknown shell surface type"); |
Philip Withnall | 07926d9 | 2013-11-25 18:01:40 +0000 | [diff] [blame] | 2324 | } |
| 2325 | |
Philip Withnall | 648a4dd | 2013-11-25 18:01:44 +0000 | [diff] [blame] | 2326 | static void |
| 2327 | shell_surface_update_child_surface_layers (struct shell_surface *shsurf) |
| 2328 | { |
| 2329 | struct shell_surface *child; |
Giulio Camuffo | 412e6a5 | 2014-07-09 22:12:56 +0300 | [diff] [blame] | 2330 | struct weston_layer_entry *prev; |
Philip Withnall | 648a4dd | 2013-11-25 18:01:44 +0000 | [diff] [blame] | 2331 | |
| 2332 | /* Move the child layers to the same workspace as shsurf. They will be |
| 2333 | * stacked above shsurf. */ |
| 2334 | wl_list_for_each_reverse(child, &shsurf->children_list, children_link) { |
Giulio Camuffo | 412e6a5 | 2014-07-09 22:12:56 +0300 | [diff] [blame] | 2335 | 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] | 2336 | weston_view_damage_below(child->view); |
Philip Withnall | 648a4dd | 2013-11-25 18:01:44 +0000 | [diff] [blame] | 2337 | weston_view_geometry_dirty(child->view); |
Giulio Camuffo | 412e6a5 | 2014-07-09 22:12:56 +0300 | [diff] [blame] | 2338 | prev = container_of(shsurf->view->layer_link.link.prev, |
| 2339 | struct weston_layer_entry, link); |
| 2340 | weston_layer_entry_remove(&child->view->layer_link); |
| 2341 | weston_layer_entry_insert(prev, |
| 2342 | &child->view->layer_link); |
Philip Withnall | 648a4dd | 2013-11-25 18:01:44 +0000 | [diff] [blame] | 2343 | weston_view_geometry_dirty(child->view); |
| 2344 | weston_surface_damage(child->surface); |
| 2345 | |
| 2346 | /* Recurse. We don’t expect this to recurse very far (if |
| 2347 | * at all) because that would imply we have transient |
| 2348 | * (or popup) children of transient surfaces, which |
| 2349 | * would be unusual. */ |
| 2350 | shell_surface_update_child_surface_layers(child); |
| 2351 | } |
| 2352 | } |
| 2353 | } |
| 2354 | |
Philip Withnall | e1d75ae | 2013-11-25 18:01:41 +0000 | [diff] [blame] | 2355 | /* 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] | 2356 | * geometry to ensure the changes are redrawn. |
| 2357 | * |
| 2358 | * If any child surfaces exist and are mapped, ensure they’re in the same layer |
| 2359 | * as this surface. */ |
Philip Withnall | e1d75ae | 2013-11-25 18:01:41 +0000 | [diff] [blame] | 2360 | static void |
| 2361 | shell_surface_update_layer(struct shell_surface *shsurf) |
| 2362 | { |
Giulio Camuffo | 412e6a5 | 2014-07-09 22:12:56 +0300 | [diff] [blame] | 2363 | struct weston_layer_entry *new_layer_link; |
Philip Withnall | e1d75ae | 2013-11-25 18:01:41 +0000 | [diff] [blame] | 2364 | |
| 2365 | new_layer_link = shell_surface_calculate_layer_link(shsurf); |
| 2366 | |
Ander Conselvan de Oliveira | ef6a7e4 | 2014-04-30 14:15:14 +0300 | [diff] [blame] | 2367 | if (new_layer_link == NULL) |
| 2368 | return; |
Philip Withnall | e1d75ae | 2013-11-25 18:01:41 +0000 | [diff] [blame] | 2369 | if (new_layer_link == &shsurf->view->layer_link) |
| 2370 | return; |
| 2371 | |
| 2372 | weston_view_geometry_dirty(shsurf->view); |
Giulio Camuffo | 412e6a5 | 2014-07-09 22:12:56 +0300 | [diff] [blame] | 2373 | weston_layer_entry_remove(&shsurf->view->layer_link); |
| 2374 | weston_layer_entry_insert(new_layer_link, &shsurf->view->layer_link); |
Philip Withnall | e1d75ae | 2013-11-25 18:01:41 +0000 | [diff] [blame] | 2375 | weston_view_geometry_dirty(shsurf->view); |
| 2376 | weston_surface_damage(shsurf->surface); |
Philip Withnall | 648a4dd | 2013-11-25 18:01:44 +0000 | [diff] [blame] | 2377 | |
| 2378 | shell_surface_update_child_surface_layers(shsurf); |
Philip Withnall | e1d75ae | 2013-11-25 18:01:41 +0000 | [diff] [blame] | 2379 | } |
| 2380 | |
Alexander Larsson | f82b6ca | 2013-05-28 16:23:39 +0200 | [diff] [blame] | 2381 | static void |
Philip Withnall | dc4332f | 2013-11-25 18:01:38 +0000 | [diff] [blame] | 2382 | shell_surface_set_parent(struct shell_surface *shsurf, |
| 2383 | struct weston_surface *parent) |
| 2384 | { |
| 2385 | shsurf->parent = parent; |
Philip Withnall | 648a4dd | 2013-11-25 18:01:44 +0000 | [diff] [blame] | 2386 | |
| 2387 | wl_list_remove(&shsurf->children_link); |
| 2388 | wl_list_init(&shsurf->children_link); |
| 2389 | |
| 2390 | /* Insert into the parent surface’s child list. */ |
| 2391 | if (parent != NULL) { |
| 2392 | struct shell_surface *parent_shsurf = get_shell_surface(parent); |
| 2393 | if (parent_shsurf != NULL) |
| 2394 | wl_list_insert(&parent_shsurf->children_list, |
| 2395 | &shsurf->children_link); |
| 2396 | } |
Philip Withnall | dc4332f | 2013-11-25 18:01:38 +0000 | [diff] [blame] | 2397 | } |
| 2398 | |
| 2399 | static void |
Philip Withnall | 352e7ed | 2013-11-25 18:01:35 +0000 | [diff] [blame] | 2400 | shell_surface_set_output(struct shell_surface *shsurf, |
| 2401 | struct weston_output *output) |
| 2402 | { |
| 2403 | struct weston_surface *es = shsurf->surface; |
| 2404 | |
| 2405 | /* get the default output, if the client set it as NULL |
| 2406 | check whether the ouput is available */ |
| 2407 | if (output) |
| 2408 | shsurf->output = output; |
| 2409 | else if (es->output) |
| 2410 | shsurf->output = es->output; |
| 2411 | else |
| 2412 | shsurf->output = get_default_output(es->compositor); |
| 2413 | } |
| 2414 | |
| 2415 | static void |
Rafael Antognolli | 03b1659 | 2013-12-03 15:35:42 -0200 | [diff] [blame] | 2416 | surface_clear_next_states(struct shell_surface *shsurf) |
| 2417 | { |
| 2418 | shsurf->next_state.maximized = false; |
| 2419 | shsurf->next_state.fullscreen = false; |
| 2420 | |
| 2421 | if ((shsurf->next_state.maximized != shsurf->state.maximized) || |
| 2422 | (shsurf->next_state.fullscreen != shsurf->state.fullscreen)) |
| 2423 | shsurf->state_changed = true; |
| 2424 | } |
| 2425 | |
| 2426 | static void |
Philip Withnall | becb77e | 2013-11-25 18:01:30 +0000 | [diff] [blame] | 2427 | set_toplevel(struct shell_surface *shsurf) |
| 2428 | { |
Kristian Høgsberg | 41fbf6f | 2013-12-05 22:31:25 -0800 | [diff] [blame] | 2429 | shell_surface_set_parent(shsurf, NULL); |
| 2430 | surface_clear_next_states(shsurf); |
Pekka Paalanen | b502654 | 2014-11-12 15:09:24 +0200 | [diff] [blame] | 2431 | set_type(shsurf, SHELL_SURFACE_TOPLEVEL); |
Philip Withnall | 648a4dd | 2013-11-25 18:01:44 +0000 | [diff] [blame] | 2432 | |
| 2433 | /* The layer_link is updated in set_surface_type(), |
| 2434 | * called from configure. */ |
Philip Withnall | becb77e | 2013-11-25 18:01:30 +0000 | [diff] [blame] | 2435 | } |
| 2436 | |
| 2437 | static void |
| 2438 | shell_surface_set_toplevel(struct wl_client *client, |
| 2439 | struct wl_resource *resource) |
| 2440 | { |
| 2441 | struct shell_surface *surface = wl_resource_get_user_data(resource); |
| 2442 | |
| 2443 | set_toplevel(surface); |
| 2444 | } |
| 2445 | |
| 2446 | static void |
| 2447 | set_transient(struct shell_surface *shsurf, |
| 2448 | struct weston_surface *parent, int x, int y, uint32_t flags) |
| 2449 | { |
Philip Withnall | dc4332f | 2013-11-25 18:01:38 +0000 | [diff] [blame] | 2450 | assert(parent != NULL); |
| 2451 | |
Kristian Høgsberg | 9f7e331 | 2014-01-02 22:40:37 -0800 | [diff] [blame] | 2452 | shell_surface_set_parent(shsurf, parent); |
| 2453 | |
| 2454 | surface_clear_next_states(shsurf); |
| 2455 | |
Philip Withnall | becb77e | 2013-11-25 18:01:30 +0000 | [diff] [blame] | 2456 | shsurf->transient.x = x; |
| 2457 | shsurf->transient.y = y; |
| 2458 | shsurf->transient.flags = flags; |
Philip Withnall | dc4332f | 2013-11-25 18:01:38 +0000 | [diff] [blame] | 2459 | |
Rafael Antognolli | ed207b4 | 2013-12-03 15:35:43 -0200 | [diff] [blame] | 2460 | shsurf->next_state.relative = true; |
Kristian Høgsberg | a1df7ac | 2013-12-31 15:01:01 -0800 | [diff] [blame] | 2461 | shsurf->state_changed = true; |
Pekka Paalanen | b502654 | 2014-11-12 15:09:24 +0200 | [diff] [blame] | 2462 | set_type(shsurf, SHELL_SURFACE_TOPLEVEL); |
Philip Withnall | 648a4dd | 2013-11-25 18:01:44 +0000 | [diff] [blame] | 2463 | |
| 2464 | /* The layer_link is updated in set_surface_type(), |
| 2465 | * called from configure. */ |
Philip Withnall | becb77e | 2013-11-25 18:01:30 +0000 | [diff] [blame] | 2466 | } |
| 2467 | |
| 2468 | static void |
| 2469 | shell_surface_set_transient(struct wl_client *client, |
| 2470 | struct wl_resource *resource, |
| 2471 | struct wl_resource *parent_resource, |
| 2472 | int x, int y, uint32_t flags) |
| 2473 | { |
| 2474 | struct shell_surface *shsurf = wl_resource_get_user_data(resource); |
| 2475 | struct weston_surface *parent = |
| 2476 | wl_resource_get_user_data(parent_resource); |
| 2477 | |
| 2478 | set_transient(shsurf, parent, x, y, flags); |
| 2479 | } |
| 2480 | |
| 2481 | static void |
| 2482 | set_fullscreen(struct shell_surface *shsurf, |
| 2483 | uint32_t method, |
| 2484 | uint32_t framerate, |
| 2485 | struct weston_output *output) |
| 2486 | { |
Philip Withnall | 352e7ed | 2013-11-25 18:01:35 +0000 | [diff] [blame] | 2487 | shell_surface_set_output(shsurf, output); |
Pekka Paalanen | b502654 | 2014-11-12 15:09:24 +0200 | [diff] [blame] | 2488 | set_type(shsurf, SHELL_SURFACE_TOPLEVEL); |
Philip Withnall | becb77e | 2013-11-25 18:01:30 +0000 | [diff] [blame] | 2489 | |
| 2490 | shsurf->fullscreen_output = shsurf->output; |
| 2491 | shsurf->fullscreen.type = method; |
| 2492 | shsurf->fullscreen.framerate = framerate; |
Philip Withnall | dc4332f | 2013-11-25 18:01:38 +0000 | [diff] [blame] | 2493 | |
Jasper St. Pierre | 6458ec3 | 2014-04-11 16:00:31 -0700 | [diff] [blame] | 2494 | send_configure_for_surface(shsurf); |
Philip Withnall | becb77e | 2013-11-25 18:01:30 +0000 | [diff] [blame] | 2495 | } |
| 2496 | |
| 2497 | static void |
Zhang, Xiong Y | 3123693 | 2013-12-13 22:10:57 +0200 | [diff] [blame] | 2498 | weston_view_set_initial_position(struct weston_view *view, |
| 2499 | struct desktop_shell *shell); |
| 2500 | |
| 2501 | static void |
Philip Withnall | becb77e | 2013-11-25 18:01:30 +0000 | [diff] [blame] | 2502 | unset_fullscreen(struct shell_surface *shsurf) |
Alex Wu | 4539b08 | 2012-03-01 12:57:46 +0800 | [diff] [blame] | 2503 | { |
Philip Withnall | f85fe84 | 2013-11-25 18:01:37 +0000 | [diff] [blame] | 2504 | /* Unset the fullscreen output, driver configuration and transforms. */ |
Alex Wu | bd3354b | 2012-04-17 17:20:49 +0800 | [diff] [blame] | 2505 | if (shsurf->fullscreen.type == WL_SHELL_SURFACE_FULLSCREEN_METHOD_DRIVER && |
| 2506 | shell_surface_is_top_fullscreen(shsurf)) { |
Alexander Larsson | f82b6ca | 2013-05-28 16:23:39 +0200 | [diff] [blame] | 2507 | restore_output_mode(shsurf->fullscreen_output); |
Alex Wu | bd3354b | 2012-04-17 17:20:49 +0800 | [diff] [blame] | 2508 | } |
Philip Withnall | f85fe84 | 2013-11-25 18:01:37 +0000 | [diff] [blame] | 2509 | |
Alex Wu | 4539b08 | 2012-03-01 12:57:46 +0800 | [diff] [blame] | 2510 | shsurf->fullscreen.type = WL_SHELL_SURFACE_FULLSCREEN_METHOD_DEFAULT; |
| 2511 | shsurf->fullscreen.framerate = 0; |
Philip Withnall | f85fe84 | 2013-11-25 18:01:37 +0000 | [diff] [blame] | 2512 | |
Alex Wu | 4539b08 | 2012-03-01 12:57:46 +0800 | [diff] [blame] | 2513 | wl_list_remove(&shsurf->fullscreen.transform.link); |
| 2514 | wl_list_init(&shsurf->fullscreen.transform.link); |
Philip Withnall | f85fe84 | 2013-11-25 18:01:37 +0000 | [diff] [blame] | 2515 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 2516 | if (shsurf->fullscreen.black_view) |
| 2517 | weston_surface_destroy(shsurf->fullscreen.black_view->surface); |
| 2518 | shsurf->fullscreen.black_view = NULL; |
Philip Withnall | f85fe84 | 2013-11-25 18:01:37 +0000 | [diff] [blame] | 2519 | |
Zhang, Xiong Y | 3123693 | 2013-12-13 22:10:57 +0200 | [diff] [blame] | 2520 | if (shsurf->saved_position_valid) |
| 2521 | weston_view_set_position(shsurf->view, |
| 2522 | shsurf->saved_x, shsurf->saved_y); |
| 2523 | else |
| 2524 | weston_view_set_initial_position(shsurf->view, shsurf->shell); |
| 2525 | |
Alex Wu | 7bcb8bd | 2012-04-27 09:07:24 +0800 | [diff] [blame] | 2526 | if (shsurf->saved_rotation_valid) { |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 2527 | wl_list_insert(&shsurf->view->geometry.transformation_list, |
Philip Withnall | becb77e | 2013-11-25 18:01:30 +0000 | [diff] [blame] | 2528 | &shsurf->rotation.transform.link); |
Alex Wu | 7bcb8bd | 2012-04-27 09:07:24 +0800 | [diff] [blame] | 2529 | shsurf->saved_rotation_valid = false; |
| 2530 | } |
Rafal Mielniczuk | 3e3862c | 2012-10-07 20:25:36 +0200 | [diff] [blame] | 2531 | |
Philip Withnall | e1d75ae | 2013-11-25 18:01:41 +0000 | [diff] [blame] | 2532 | /* Layer is updated in set_surface_type(). */ |
Alex Wu | 4539b08 | 2012-03-01 12:57:46 +0800 | [diff] [blame] | 2533 | } |
| 2534 | |
Rafal Mielniczuk | fffdcdd | 2013-03-11 19:26:54 +0100 | [diff] [blame] | 2535 | static void |
Philip Withnall | becb77e | 2013-11-25 18:01:30 +0000 | [diff] [blame] | 2536 | shell_surface_set_fullscreen(struct wl_client *client, |
| 2537 | struct wl_resource *resource, |
| 2538 | uint32_t method, |
| 2539 | uint32_t framerate, |
| 2540 | struct wl_resource *output_resource) |
| 2541 | { |
| 2542 | struct shell_surface *shsurf = wl_resource_get_user_data(resource); |
| 2543 | struct weston_output *output; |
| 2544 | |
| 2545 | if (output_resource) |
| 2546 | output = wl_resource_get_user_data(output_resource); |
| 2547 | else |
| 2548 | output = NULL; |
| 2549 | |
Rafael Antognolli | 4b99a40 | 2013-12-03 15:35:44 -0200 | [diff] [blame] | 2550 | shell_surface_set_parent(shsurf, NULL); |
| 2551 | |
Rafael Antognolli | 03b1659 | 2013-12-03 15:35:42 -0200 | [diff] [blame] | 2552 | surface_clear_next_states(shsurf); |
Jasper St. Pierre | 8c6aa45 | 2014-02-08 18:29:49 -0500 | [diff] [blame] | 2553 | shsurf->next_state.fullscreen = true; |
| 2554 | shsurf->state_changed = true; |
Jasper St. Pierre | 6458ec3 | 2014-04-11 16:00:31 -0700 | [diff] [blame] | 2555 | set_fullscreen(shsurf, method, framerate, output); |
Philip Withnall | becb77e | 2013-11-25 18:01:30 +0000 | [diff] [blame] | 2556 | } |
| 2557 | |
| 2558 | static void |
| 2559 | set_popup(struct shell_surface *shsurf, |
| 2560 | struct weston_surface *parent, |
| 2561 | struct weston_seat *seat, |
| 2562 | uint32_t serial, |
| 2563 | int32_t x, |
| 2564 | int32_t y) |
| 2565 | { |
Philip Withnall | dc4332f | 2013-11-25 18:01:38 +0000 | [diff] [blame] | 2566 | assert(parent != NULL); |
| 2567 | |
Philip Withnall | becb77e | 2013-11-25 18:01:30 +0000 | [diff] [blame] | 2568 | shsurf->popup.shseat = get_shell_seat(seat); |
| 2569 | shsurf->popup.serial = serial; |
| 2570 | shsurf->popup.x = x; |
| 2571 | shsurf->popup.y = y; |
Philip Withnall | dc4332f | 2013-11-25 18:01:38 +0000 | [diff] [blame] | 2572 | |
Pekka Paalanen | b502654 | 2014-11-12 15:09:24 +0200 | [diff] [blame] | 2573 | set_type(shsurf, SHELL_SURFACE_POPUP); |
Philip Withnall | becb77e | 2013-11-25 18:01:30 +0000 | [diff] [blame] | 2574 | } |
| 2575 | |
| 2576 | static void |
| 2577 | shell_surface_set_popup(struct wl_client *client, |
| 2578 | struct wl_resource *resource, |
| 2579 | struct wl_resource *seat_resource, |
| 2580 | uint32_t serial, |
| 2581 | struct wl_resource *parent_resource, |
| 2582 | int32_t x, int32_t y, uint32_t flags) |
| 2583 | { |
| 2584 | struct shell_surface *shsurf = wl_resource_get_user_data(resource); |
Rafael Antognolli | 4b99a40 | 2013-12-03 15:35:44 -0200 | [diff] [blame] | 2585 | struct weston_surface *parent = |
| 2586 | wl_resource_get_user_data(parent_resource); |
| 2587 | |
| 2588 | shell_surface_set_parent(shsurf, parent); |
Philip Withnall | becb77e | 2013-11-25 18:01:30 +0000 | [diff] [blame] | 2589 | |
Rafael Antognolli | 03b1659 | 2013-12-03 15:35:42 -0200 | [diff] [blame] | 2590 | surface_clear_next_states(shsurf); |
Philip Withnall | becb77e | 2013-11-25 18:01:30 +0000 | [diff] [blame] | 2591 | set_popup(shsurf, |
Rafael Antognolli | 4b99a40 | 2013-12-03 15:35:44 -0200 | [diff] [blame] | 2592 | parent, |
Philip Withnall | becb77e | 2013-11-25 18:01:30 +0000 | [diff] [blame] | 2593 | wl_resource_get_user_data(seat_resource), |
| 2594 | serial, x, y); |
| 2595 | } |
| 2596 | |
| 2597 | static void |
Philip Withnall | becb77e | 2013-11-25 18:01:30 +0000 | [diff] [blame] | 2598 | unset_maximized(struct shell_surface *shsurf) |
Rafal Mielniczuk | fffdcdd | 2013-03-11 19:26:54 +0100 | [diff] [blame] | 2599 | { |
Rafal Mielniczuk | fffdcdd | 2013-03-11 19:26:54 +0100 | [diff] [blame] | 2600 | /* undo all maximized things here */ |
| 2601 | shsurf->output = get_default_output(shsurf->surface->compositor); |
Zhang, Xiong Y | 3123693 | 2013-12-13 22:10:57 +0200 | [diff] [blame] | 2602 | |
| 2603 | if (shsurf->saved_position_valid) |
| 2604 | weston_view_set_position(shsurf->view, |
| 2605 | shsurf->saved_x, shsurf->saved_y); |
| 2606 | else |
| 2607 | weston_view_set_initial_position(shsurf->view, shsurf->shell); |
Rafal Mielniczuk | fffdcdd | 2013-03-11 19:26:54 +0100 | [diff] [blame] | 2608 | |
| 2609 | if (shsurf->saved_rotation_valid) { |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 2610 | wl_list_insert(&shsurf->view->geometry.transformation_list, |
| 2611 | &shsurf->rotation.transform.link); |
Rafal Mielniczuk | fffdcdd | 2013-03-11 19:26:54 +0100 | [diff] [blame] | 2612 | shsurf->saved_rotation_valid = false; |
| 2613 | } |
| 2614 | |
Philip Withnall | e1d75ae | 2013-11-25 18:01:41 +0000 | [diff] [blame] | 2615 | /* Layer is updated in set_surface_type(). */ |
Rafal Mielniczuk | fffdcdd | 2013-03-11 19:26:54 +0100 | [diff] [blame] | 2616 | } |
| 2617 | |
Philip Withnall | becb77e | 2013-11-25 18:01:30 +0000 | [diff] [blame] | 2618 | static void |
Manuel Bachmann | dc1c3e4 | 2015-02-16 11:52:13 +0100 | [diff] [blame] | 2619 | set_minimized(struct weston_surface *surface) |
Manuel Bachmann | 50c87db | 2014-02-26 15:52:13 +0100 | [diff] [blame] | 2620 | { |
| 2621 | struct shell_surface *shsurf; |
| 2622 | struct workspace *current_ws; |
Manuel Bachmann | 50c87db | 2014-02-26 15:52:13 +0100 | [diff] [blame] | 2623 | struct weston_view *view; |
| 2624 | |
| 2625 | view = get_default_view(surface); |
| 2626 | if (!view) |
| 2627 | return; |
| 2628 | |
| 2629 | assert(weston_surface_get_main_surface(view->surface) == view->surface); |
| 2630 | |
| 2631 | shsurf = get_shell_surface(surface); |
| 2632 | current_ws = get_current_workspace(shsurf->shell); |
| 2633 | |
Giulio Camuffo | 412e6a5 | 2014-07-09 22:12:56 +0300 | [diff] [blame] | 2634 | weston_layer_entry_remove(&view->layer_link); |
Manuel Bachmann | dc1c3e4 | 2015-02-16 11:52:13 +0100 | [diff] [blame] | 2635 | 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] | 2636 | |
Manuel Bachmann | dc1c3e4 | 2015-02-16 11:52:13 +0100 | [diff] [blame] | 2637 | drop_focus_state(shsurf->shell, current_ws, view->surface); |
Jonas Ådahl | 22faea1 | 2014-10-15 22:02:06 +0200 | [diff] [blame] | 2638 | surface_keyboard_focus_lost(surface); |
Manuel Bachmann | 50c87db | 2014-02-26 15:52:13 +0100 | [diff] [blame] | 2639 | |
| 2640 | shell_surface_update_child_surface_layers(shsurf); |
Manuel Bachmann | 50c87db | 2014-02-26 15:52:13 +0100 | [diff] [blame] | 2641 | weston_view_damage_below(view); |
| 2642 | } |
| 2643 | |
| 2644 | static void |
Philip Withnall | becb77e | 2013-11-25 18:01:30 +0000 | [diff] [blame] | 2645 | shell_surface_set_maximized(struct wl_client *client, |
| 2646 | struct wl_resource *resource, |
| 2647 | struct wl_resource *output_resource) |
| 2648 | { |
| 2649 | struct shell_surface *shsurf = wl_resource_get_user_data(resource); |
| 2650 | struct weston_output *output; |
| 2651 | |
Jasper St. Pierre | 9aa8ce6 | 2014-04-11 16:18:54 -0700 | [diff] [blame] | 2652 | surface_clear_next_states(shsurf); |
| 2653 | shsurf->next_state.maximized = true; |
| 2654 | shsurf->state_changed = true; |
| 2655 | |
Pekka Paalanen | b502654 | 2014-11-12 15:09:24 +0200 | [diff] [blame] | 2656 | set_type(shsurf, SHELL_SURFACE_TOPLEVEL); |
Jasper St. Pierre | 9aa8ce6 | 2014-04-11 16:18:54 -0700 | [diff] [blame] | 2657 | shell_surface_set_parent(shsurf, NULL); |
| 2658 | |
Philip Withnall | becb77e | 2013-11-25 18:01:30 +0000 | [diff] [blame] | 2659 | if (output_resource) |
| 2660 | output = wl_resource_get_user_data(output_resource); |
| 2661 | else |
| 2662 | output = NULL; |
| 2663 | |
Jasper St. Pierre | 9aa8ce6 | 2014-04-11 16:18:54 -0700 | [diff] [blame] | 2664 | shell_surface_set_output(shsurf, output); |
Rafael Antognolli | 4b99a40 | 2013-12-03 15:35:44 -0200 | [diff] [blame] | 2665 | |
Jasper St. Pierre | 9aa8ce6 | 2014-04-11 16:18:54 -0700 | [diff] [blame] | 2666 | send_configure_for_surface(shsurf); |
Philip Withnall | becb77e | 2013-11-25 18:01:30 +0000 | [diff] [blame] | 2667 | } |
| 2668 | |
Philip Withnall | e1d75ae | 2013-11-25 18:01:41 +0000 | [diff] [blame] | 2669 | /* This is only ever called from set_surface_type(), so there’s no need to |
| 2670 | * update layer_links here, since they’ll be updated when we return. */ |
Pekka Paalanen | 9826223 | 2011-12-01 10:42:22 +0200 | [diff] [blame] | 2671 | static int |
Philip Withnall | becb77e | 2013-11-25 18:01:30 +0000 | [diff] [blame] | 2672 | reset_surface_type(struct shell_surface *surface) |
Pekka Paalanen | 9826223 | 2011-12-01 10:42:22 +0200 | [diff] [blame] | 2673 | { |
Rafael Antognolli | 03b1659 | 2013-12-03 15:35:42 -0200 | [diff] [blame] | 2674 | if (surface->state.fullscreen) |
Philip Withnall | becb77e | 2013-11-25 18:01:30 +0000 | [diff] [blame] | 2675 | unset_fullscreen(surface); |
Rafael Antognolli | 03b1659 | 2013-12-03 15:35:42 -0200 | [diff] [blame] | 2676 | if (surface->state.maximized) |
Philip Withnall | becb77e | 2013-11-25 18:01:30 +0000 | [diff] [blame] | 2677 | unset_maximized(surface); |
Pekka Paalanen | 9826223 | 2011-12-01 10:42:22 +0200 | [diff] [blame] | 2678 | |
Pekka Paalanen | 9826223 | 2011-12-01 10:42:22 +0200 | [diff] [blame] | 2679 | return 0; |
| 2680 | } |
| 2681 | |
Kristian Høgsberg | 4cca349 | 2011-01-18 07:53:49 -0500 | [diff] [blame] | 2682 | static void |
Rafael Antognolli | 03b1659 | 2013-12-03 15:35:42 -0200 | [diff] [blame] | 2683 | set_full_output(struct shell_surface *shsurf) |
| 2684 | { |
| 2685 | shsurf->saved_x = shsurf->view->geometry.x; |
| 2686 | shsurf->saved_y = shsurf->view->geometry.y; |
Rafael Antognolli | 3c4e3f7 | 2013-12-03 15:35:46 -0200 | [diff] [blame] | 2687 | shsurf->saved_width = shsurf->surface->width; |
| 2688 | shsurf->saved_height = shsurf->surface->height; |
| 2689 | shsurf->saved_size_valid = true; |
Rafael Antognolli | 03b1659 | 2013-12-03 15:35:42 -0200 | [diff] [blame] | 2690 | shsurf->saved_position_valid = true; |
| 2691 | |
| 2692 | if (!wl_list_empty(&shsurf->rotation.transform.link)) { |
| 2693 | wl_list_remove(&shsurf->rotation.transform.link); |
| 2694 | wl_list_init(&shsurf->rotation.transform.link); |
| 2695 | weston_view_geometry_dirty(shsurf->view); |
| 2696 | shsurf->saved_rotation_valid = true; |
| 2697 | } |
| 2698 | } |
| 2699 | |
| 2700 | static void |
Kristian Høgsberg | 7f366e7 | 2012-04-27 17:20:01 -0400 | [diff] [blame] | 2701 | set_surface_type(struct shell_surface *shsurf) |
| 2702 | { |
Kristian Høgsberg | 8150b19 | 2012-06-27 10:22:58 -0400 | [diff] [blame] | 2703 | struct weston_surface *pes = shsurf->parent; |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 2704 | struct weston_view *pev = get_default_view(pes); |
Kristian Høgsberg | 7f366e7 | 2012-04-27 17:20:01 -0400 | [diff] [blame] | 2705 | |
Philip Withnall | becb77e | 2013-11-25 18:01:30 +0000 | [diff] [blame] | 2706 | reset_surface_type(shsurf); |
Kristian Høgsberg | 7f366e7 | 2012-04-27 17:20:01 -0400 | [diff] [blame] | 2707 | |
Rafael Antognolli | 03b1659 | 2013-12-03 15:35:42 -0200 | [diff] [blame] | 2708 | shsurf->state = shsurf->next_state; |
Rafael Antognolli | 03b1659 | 2013-12-03 15:35:42 -0200 | [diff] [blame] | 2709 | shsurf->state_changed = false; |
Kristian Høgsberg | 7f366e7 | 2012-04-27 17:20:01 -0400 | [diff] [blame] | 2710 | |
| 2711 | switch (shsurf->type) { |
| 2712 | case SHELL_SURFACE_TOPLEVEL: |
Rafael Antognolli | ed207b4 | 2013-12-03 15:35:43 -0200 | [diff] [blame] | 2713 | if (shsurf->state.maximized || shsurf->state.fullscreen) { |
Rafael Antognolli | 03b1659 | 2013-12-03 15:35:42 -0200 | [diff] [blame] | 2714 | set_full_output(shsurf); |
Rafael Antognolli | ed207b4 | 2013-12-03 15:35:43 -0200 | [diff] [blame] | 2715 | } else if (shsurf->state.relative && pev) { |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 2716 | weston_view_set_position(shsurf->view, |
| 2717 | pev->geometry.x + shsurf->transient.x, |
| 2718 | pev->geometry.y + shsurf->transient.y); |
Rafael Antognolli | ed207b4 | 2013-12-03 15:35:43 -0200 | [diff] [blame] | 2719 | } |
Rafael Antognolli | 44a3162 | 2013-12-04 18:37:16 -0200 | [diff] [blame] | 2720 | break; |
Kristian Høgsberg | 7f366e7 | 2012-04-27 17:20:01 -0400 | [diff] [blame] | 2721 | |
Tiago Vignatti | fb2adba | 2013-06-12 15:43:21 -0300 | [diff] [blame] | 2722 | case SHELL_SURFACE_XWAYLAND: |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 2723 | weston_view_set_position(shsurf->view, shsurf->transient.x, |
| 2724 | shsurf->transient.y); |
Tiago Vignatti | fb2adba | 2013-06-12 15:43:21 -0300 | [diff] [blame] | 2725 | break; |
| 2726 | |
Philip Withnall | 0f640e2 | 2013-11-25 18:01:31 +0000 | [diff] [blame] | 2727 | case SHELL_SURFACE_POPUP: |
| 2728 | case SHELL_SURFACE_NONE: |
Kristian Høgsberg | 7f366e7 | 2012-04-27 17:20:01 -0400 | [diff] [blame] | 2729 | default: |
| 2730 | break; |
| 2731 | } |
Philip Withnall | e1d75ae | 2013-11-25 18:01:41 +0000 | [diff] [blame] | 2732 | |
| 2733 | /* Update the surface’s layer. */ |
| 2734 | shell_surface_update_layer(shsurf); |
Kristian Høgsberg | 7f366e7 | 2012-04-27 17:20:01 -0400 | [diff] [blame] | 2735 | } |
| 2736 | |
Tiago Vignatti | be14326 | 2012-04-16 17:31:41 +0300 | [diff] [blame] | 2737 | static struct desktop_shell * |
Juan Zhao | 96879df | 2012-02-07 08:45:41 +0800 | [diff] [blame] | 2738 | shell_surface_get_shell(struct shell_surface *shsurf) |
Pekka Paalanen | af0e34c | 2011-12-02 10:59:17 +0200 | [diff] [blame] | 2739 | { |
Kristian Høgsberg | 02e79dc | 2012-04-12 09:55:26 -0400 | [diff] [blame] | 2740 | return shsurf->shell; |
Juan Zhao | 96879df | 2012-02-07 08:45:41 +0800 | [diff] [blame] | 2741 | } |
| 2742 | |
Pekka Paalanen | 8274d90 | 2014-08-06 19:36:51 +0300 | [diff] [blame] | 2743 | static int |
| 2744 | black_surface_get_label(struct weston_surface *surface, char *buf, size_t len) |
| 2745 | { |
| 2746 | struct weston_surface *fs_surface = surface->configure_private; |
| 2747 | int n; |
| 2748 | int rem; |
| 2749 | int ret; |
| 2750 | |
| 2751 | n = snprintf(buf, len, "black background surface for "); |
| 2752 | if (n < 0) |
| 2753 | return n; |
| 2754 | |
| 2755 | rem = (int)len - n; |
| 2756 | if (rem < 0) |
| 2757 | rem = 0; |
| 2758 | |
| 2759 | if (fs_surface->get_label) |
| 2760 | ret = fs_surface->get_label(fs_surface, buf + n, rem); |
| 2761 | else |
| 2762 | ret = snprintf(buf + n, rem, "<unknown>"); |
| 2763 | |
| 2764 | if (ret < 0) |
| 2765 | return n; |
| 2766 | |
| 2767 | return n + ret; |
| 2768 | } |
| 2769 | |
Alex Wu | 2185843 | 2012-04-01 20:13:08 +0800 | [diff] [blame] | 2770 | static void |
Jason Ekstrand | 918f2dd | 2013-12-02 21:01:53 -0600 | [diff] [blame] | 2771 | 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] | 2772 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 2773 | static struct weston_view * |
Alex Wu | 4539b08 | 2012-03-01 12:57:46 +0800 | [diff] [blame] | 2774 | create_black_surface(struct weston_compositor *ec, |
Alex Wu | 2185843 | 2012-04-01 20:13:08 +0800 | [diff] [blame] | 2775 | struct weston_surface *fs_surface, |
John Kåre Alsaker | 490d02a | 2012-09-30 02:57:21 +0200 | [diff] [blame] | 2776 | float x, float y, int w, int h) |
Alex Wu | 4539b08 | 2012-03-01 12:57:46 +0800 | [diff] [blame] | 2777 | { |
| 2778 | struct weston_surface *surface = NULL; |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 2779 | struct weston_view *view; |
Alex Wu | 4539b08 | 2012-03-01 12:57:46 +0800 | [diff] [blame] | 2780 | |
| 2781 | surface = weston_surface_create(ec); |
| 2782 | if (surface == NULL) { |
Martin Minarik | 6d11836 | 2012-06-07 18:01:59 +0200 | [diff] [blame] | 2783 | weston_log("no memory\n"); |
Alex Wu | 4539b08 | 2012-03-01 12:57:46 +0800 | [diff] [blame] | 2784 | return NULL; |
| 2785 | } |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 2786 | view = weston_view_create(surface); |
| 2787 | if (surface == NULL) { |
| 2788 | weston_log("no memory\n"); |
| 2789 | weston_surface_destroy(surface); |
| 2790 | return NULL; |
| 2791 | } |
Alex Wu | 4539b08 | 2012-03-01 12:57:46 +0800 | [diff] [blame] | 2792 | |
Alex Wu | 2185843 | 2012-04-01 20:13:08 +0800 | [diff] [blame] | 2793 | surface->configure = black_surface_configure; |
Giulio Camuffo | 7fe01b1 | 2013-03-28 18:02:42 +0100 | [diff] [blame] | 2794 | surface->configure_private = fs_surface; |
Pekka Paalanen | 8274d90 | 2014-08-06 19:36:51 +0300 | [diff] [blame] | 2795 | weston_surface_set_label_func(surface, black_surface_get_label); |
Alex Wu | 4539b08 | 2012-03-01 12:57:46 +0800 | [diff] [blame] | 2796 | weston_surface_set_color(surface, 0.0, 0.0, 0.0, 1); |
Pekka Paalanen | 71f6f3b | 2012-10-10 12:49:26 +0300 | [diff] [blame] | 2797 | pixman_region32_fini(&surface->opaque); |
Kristian Høgsberg | 61f00f5 | 2012-08-03 16:31:36 -0400 | [diff] [blame] | 2798 | pixman_region32_init_rect(&surface->opaque, 0, 0, w, h); |
Jonas Ådahl | 33619a4 | 2013-01-15 21:25:55 +0100 | [diff] [blame] | 2799 | pixman_region32_fini(&surface->input); |
| 2800 | pixman_region32_init_rect(&surface->input, 0, 0, w, h); |
Jason Ekstrand | 918f2dd | 2013-12-02 21:01:53 -0600 | [diff] [blame] | 2801 | |
Jason Ekstrand | 6228ee2 | 2014-01-01 15:58:57 -0600 | [diff] [blame] | 2802 | weston_surface_set_size(surface, w, h); |
Jason Ekstrand | 918f2dd | 2013-12-02 21:01:53 -0600 | [diff] [blame] | 2803 | weston_view_set_position(view, x, y); |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 2804 | |
| 2805 | return view; |
Alex Wu | 4539b08 | 2012-03-01 12:57:46 +0800 | [diff] [blame] | 2806 | } |
| 2807 | |
Philip Withnall | ed8f1a9 | 2013-11-25 18:01:43 +0000 | [diff] [blame] | 2808 | static void |
| 2809 | shell_ensure_fullscreen_black_view(struct shell_surface *shsurf) |
| 2810 | { |
| 2811 | struct weston_output *output = shsurf->fullscreen_output; |
| 2812 | |
Rafael Antognolli | 03b1659 | 2013-12-03 15:35:42 -0200 | [diff] [blame] | 2813 | assert(shsurf->state.fullscreen); |
Philip Withnall | ed8f1a9 | 2013-11-25 18:01:43 +0000 | [diff] [blame] | 2814 | |
| 2815 | if (!shsurf->fullscreen.black_view) |
| 2816 | shsurf->fullscreen.black_view = |
| 2817 | create_black_surface(shsurf->surface->compositor, |
| 2818 | shsurf->surface, |
| 2819 | output->x, output->y, |
| 2820 | output->width, |
| 2821 | output->height); |
| 2822 | |
| 2823 | weston_view_geometry_dirty(shsurf->fullscreen.black_view); |
Giulio Camuffo | 412e6a5 | 2014-07-09 22:12:56 +0300 | [diff] [blame] | 2824 | weston_layer_entry_remove(&shsurf->fullscreen.black_view->layer_link); |
| 2825 | weston_layer_entry_insert(&shsurf->view->layer_link, |
| 2826 | &shsurf->fullscreen.black_view->layer_link); |
Philip Withnall | ed8f1a9 | 2013-11-25 18:01:43 +0000 | [diff] [blame] | 2827 | weston_view_geometry_dirty(shsurf->fullscreen.black_view); |
| 2828 | weston_surface_damage(shsurf->surface); |
Emilio Pozuelo Monfort | 9e7c759 | 2014-01-30 14:01:10 +0100 | [diff] [blame] | 2829 | |
| 2830 | shsurf->state.lowered = false; |
Philip Withnall | ed8f1a9 | 2013-11-25 18:01:43 +0000 | [diff] [blame] | 2831 | } |
| 2832 | |
Alex Wu | 4539b08 | 2012-03-01 12:57:46 +0800 | [diff] [blame] | 2833 | /* Create black surface and append it to the associated fullscreen surface. |
| 2834 | * Handle size dismatch and positioning according to the method. */ |
| 2835 | static void |
| 2836 | shell_configure_fullscreen(struct shell_surface *shsurf) |
| 2837 | { |
| 2838 | struct weston_output *output = shsurf->fullscreen_output; |
| 2839 | struct weston_surface *surface = shsurf->surface; |
| 2840 | struct weston_matrix *matrix; |
Kristian Høgsberg | 240dfeb | 2012-07-12 12:32:31 -0400 | [diff] [blame] | 2841 | float scale, output_aspect, surface_aspect, x, y; |
Giulio Camuffo | b836664 | 2013-04-25 13:57:46 +0300 | [diff] [blame] | 2842 | int32_t surf_x, surf_y, surf_width, surf_height; |
Alex Wu | 4539b08 | 2012-03-01 12:57:46 +0800 | [diff] [blame] | 2843 | |
Alexander Larsson | f82b6ca | 2013-05-28 16:23:39 +0200 | [diff] [blame] | 2844 | if (shsurf->fullscreen.type != WL_SHELL_SURFACE_FULLSCREEN_METHOD_DRIVER) |
| 2845 | restore_output_mode(output); |
| 2846 | |
Emilio Pozuelo Monfort | 9e7c759 | 2014-01-30 14:01:10 +0100 | [diff] [blame] | 2847 | /* Reverse the effect of lower_fullscreen_layer() */ |
Giulio Camuffo | 412e6a5 | 2014-07-09 22:12:56 +0300 | [diff] [blame] | 2848 | weston_layer_entry_remove(&shsurf->view->layer_link); |
| 2849 | 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] | 2850 | |
Philip Withnall | ed8f1a9 | 2013-11-25 18:01:43 +0000 | [diff] [blame] | 2851 | shell_ensure_fullscreen_black_view(shsurf); |
Alex Wu | 4539b08 | 2012-03-01 12:57:46 +0800 | [diff] [blame] | 2852 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 2853 | surface_subsurfaces_boundingbox(shsurf->surface, &surf_x, &surf_y, |
Giulio Camuffo | b836664 | 2013-04-25 13:57:46 +0300 | [diff] [blame] | 2854 | &surf_width, &surf_height); |
| 2855 | |
Alex Wu | 4539b08 | 2012-03-01 12:57:46 +0800 | [diff] [blame] | 2856 | switch (shsurf->fullscreen.type) { |
| 2857 | case WL_SHELL_SURFACE_FULLSCREEN_METHOD_DEFAULT: |
Pekka Paalanen | de685b8 | 2012-12-04 15:58:12 +0200 | [diff] [blame] | 2858 | if (surface->buffer_ref.buffer) |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 2859 | center_on_output(shsurf->view, shsurf->fullscreen_output); |
Alex Wu | 4539b08 | 2012-03-01 12:57:46 +0800 | [diff] [blame] | 2860 | break; |
| 2861 | case WL_SHELL_SURFACE_FULLSCREEN_METHOD_SCALE: |
Rob Bradford | 9f3dd15 | 2013-02-12 11:53:47 +0000 | [diff] [blame] | 2862 | /* 1:1 mapping between surface and output dimensions */ |
Giulio Camuffo | b836664 | 2013-04-25 13:57:46 +0300 | [diff] [blame] | 2863 | if (output->width == surf_width && |
| 2864 | output->height == surf_height) { |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 2865 | weston_view_set_position(shsurf->view, |
| 2866 | output->x - surf_x, |
| 2867 | output->y - surf_y); |
Rob Bradford | 9f3dd15 | 2013-02-12 11:53:47 +0000 | [diff] [blame] | 2868 | break; |
| 2869 | } |
| 2870 | |
Alex Wu | 4539b08 | 2012-03-01 12:57:46 +0800 | [diff] [blame] | 2871 | matrix = &shsurf->fullscreen.transform.matrix; |
| 2872 | weston_matrix_init(matrix); |
Kristian Høgsberg | 240dfeb | 2012-07-12 12:32:31 -0400 | [diff] [blame] | 2873 | |
Scott Moreau | 1bad5db | 2012-08-18 01:04:05 -0600 | [diff] [blame] | 2874 | output_aspect = (float) output->width / |
| 2875 | (float) output->height; |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 2876 | /* XXX: Use surf_width and surf_height here? */ |
| 2877 | surface_aspect = (float) surface->width / |
| 2878 | (float) surface->height; |
Kristian Høgsberg | 240dfeb | 2012-07-12 12:32:31 -0400 | [diff] [blame] | 2879 | if (output_aspect < surface_aspect) |
Scott Moreau | 1bad5db | 2012-08-18 01:04:05 -0600 | [diff] [blame] | 2880 | scale = (float) output->width / |
Giulio Camuffo | b836664 | 2013-04-25 13:57:46 +0300 | [diff] [blame] | 2881 | (float) surf_width; |
Kristian Høgsberg | 240dfeb | 2012-07-12 12:32:31 -0400 | [diff] [blame] | 2882 | else |
Scott Moreau | 1bad5db | 2012-08-18 01:04:05 -0600 | [diff] [blame] | 2883 | scale = (float) output->height / |
Giulio Camuffo | b836664 | 2013-04-25 13:57:46 +0300 | [diff] [blame] | 2884 | (float) surf_height; |
Kristian Høgsberg | 240dfeb | 2012-07-12 12:32:31 -0400 | [diff] [blame] | 2885 | |
Alex Wu | 4539b08 | 2012-03-01 12:57:46 +0800 | [diff] [blame] | 2886 | weston_matrix_scale(matrix, scale, scale, 1); |
| 2887 | wl_list_remove(&shsurf->fullscreen.transform.link); |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 2888 | wl_list_insert(&shsurf->view->geometry.transformation_list, |
Alex Wu | 4539b08 | 2012-03-01 12:57:46 +0800 | [diff] [blame] | 2889 | &shsurf->fullscreen.transform.link); |
Giulio Camuffo | b836664 | 2013-04-25 13:57:46 +0300 | [diff] [blame] | 2890 | x = output->x + (output->width - surf_width * scale) / 2 - surf_x; |
| 2891 | y = output->y + (output->height - surf_height * scale) / 2 - surf_y; |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 2892 | weston_view_set_position(shsurf->view, x, y); |
Kristian Høgsberg | 240dfeb | 2012-07-12 12:32:31 -0400 | [diff] [blame] | 2893 | |
Alex Wu | 4539b08 | 2012-03-01 12:57:46 +0800 | [diff] [blame] | 2894 | break; |
| 2895 | case WL_SHELL_SURFACE_FULLSCREEN_METHOD_DRIVER: |
Alex Wu | bd3354b | 2012-04-17 17:20:49 +0800 | [diff] [blame] | 2896 | if (shell_surface_is_top_fullscreen(shsurf)) { |
Quentin Glidic | c0d79ce | 2013-01-29 14:16:13 +0100 | [diff] [blame] | 2897 | struct weston_mode mode = {0, |
Pekka Paalanen | 952b6c8 | 2014-03-14 14:38:15 +0200 | [diff] [blame] | 2898 | surf_width * surface->buffer_viewport.buffer.scale, |
| 2899 | surf_height * surface->buffer_viewport.buffer.scale, |
Alex Wu | bd3354b | 2012-04-17 17:20:49 +0800 | [diff] [blame] | 2900 | shsurf->fullscreen.framerate}; |
| 2901 | |
Derek Foreman | 6ae7bc9 | 2014-11-04 10:47:33 -0600 | [diff] [blame] | 2902 | if (weston_output_mode_switch_to_temporary(output, &mode, |
| 2903 | surface->buffer_viewport.buffer.scale) == 0) { |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 2904 | weston_view_set_position(shsurf->view, |
| 2905 | output->x - surf_x, |
| 2906 | output->y - surf_y); |
Jason Ekstrand | 918f2dd | 2013-12-02 21:01:53 -0600 | [diff] [blame] | 2907 | shsurf->fullscreen.black_view->surface->width = output->width; |
| 2908 | shsurf->fullscreen.black_view->surface->height = output->height; |
| 2909 | weston_view_set_position(shsurf->fullscreen.black_view, |
| 2910 | output->x - surf_x, |
| 2911 | output->y - surf_y); |
Alex Wu | bd3354b | 2012-04-17 17:20:49 +0800 | [diff] [blame] | 2912 | break; |
Alexander Larsson | d622ed3 | 2013-05-28 16:23:40 +0200 | [diff] [blame] | 2913 | } else { |
Mario Kleiner | 492c12f | 2015-06-21 21:25:12 +0200 | [diff] [blame] | 2914 | weston_log("shell: Can't switch to temporary mode.\n"); |
Alexander Larsson | f82b6ca | 2013-05-28 16:23:39 +0200 | [diff] [blame] | 2915 | restore_output_mode(output); |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 2916 | center_on_output(shsurf->view, output); |
Alexander Larsson | d622ed3 | 2013-05-28 16:23:40 +0200 | [diff] [blame] | 2917 | } |
Alex Wu | bd3354b | 2012-04-17 17:20:49 +0800 | [diff] [blame] | 2918 | } |
Alex Wu | 4539b08 | 2012-03-01 12:57:46 +0800 | [diff] [blame] | 2919 | break; |
| 2920 | case WL_SHELL_SURFACE_FULLSCREEN_METHOD_FILL: |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 2921 | center_on_output(shsurf->view, output); |
Alex Wu | 4539b08 | 2012-03-01 12:57:46 +0800 | [diff] [blame] | 2922 | break; |
| 2923 | default: |
| 2924 | break; |
| 2925 | } |
| 2926 | } |
| 2927 | |
Alex Wu | 4539b08 | 2012-03-01 12:57:46 +0800 | [diff] [blame] | 2928 | static void |
| 2929 | shell_map_fullscreen(struct shell_surface *shsurf) |
| 2930 | { |
Alex Wu | bd3354b | 2012-04-17 17:20:49 +0800 | [diff] [blame] | 2931 | shell_configure_fullscreen(shsurf); |
Alex Wu | 4539b08 | 2012-03-01 12:57:46 +0800 | [diff] [blame] | 2932 | } |
| 2933 | |
Kristian Høgsberg | 7a5c979 | 2011-06-18 06:12:54 -0400 | [diff] [blame] | 2934 | static void |
Tiago Vignatti | fb2adba | 2013-06-12 15:43:21 -0300 | [diff] [blame] | 2935 | set_xwayland(struct shell_surface *shsurf, int x, int y, uint32_t flags) |
| 2936 | { |
| 2937 | /* XXX: using the same fields for transient type */ |
Rafael Antognolli | 03b1659 | 2013-12-03 15:35:42 -0200 | [diff] [blame] | 2938 | surface_clear_next_states(shsurf); |
Tiago Vignatti | fb2adba | 2013-06-12 15:43:21 -0300 | [diff] [blame] | 2939 | shsurf->transient.x = x; |
| 2940 | shsurf->transient.y = y; |
| 2941 | shsurf->transient.flags = flags; |
Philip Withnall | dc4332f | 2013-11-25 18:01:38 +0000 | [diff] [blame] | 2942 | |
| 2943 | shell_surface_set_parent(shsurf, NULL); |
| 2944 | |
Pekka Paalanen | b502654 | 2014-11-12 15:09:24 +0200 | [diff] [blame] | 2945 | set_type(shsurf, SHELL_SURFACE_XWAYLAND); |
Kristian Høgsberg | 8bc525c | 2014-01-01 22:34:49 -0800 | [diff] [blame] | 2946 | shsurf->state_changed = true; |
Tiago Vignatti | fb2adba | 2013-06-12 15:43:21 -0300 | [diff] [blame] | 2947 | } |
| 2948 | |
Kristian Høgsberg | 4779241 | 2014-05-04 13:47:06 -0700 | [diff] [blame] | 2949 | static void |
| 2950 | shell_interface_set_fullscreen(struct shell_surface *shsurf, |
| 2951 | uint32_t method, |
| 2952 | uint32_t framerate, |
| 2953 | struct weston_output *output) |
| 2954 | { |
| 2955 | surface_clear_next_states(shsurf); |
Kristian Høgsberg | 4779241 | 2014-05-04 13:47:06 -0700 | [diff] [blame] | 2956 | shsurf->next_state.fullscreen = true; |
| 2957 | shsurf->state_changed = true; |
Marek Chalupa | e9fe467 | 2014-10-29 13:44:44 +0100 | [diff] [blame] | 2958 | |
| 2959 | set_fullscreen(shsurf, method, framerate, output); |
Kristian Høgsberg | 4779241 | 2014-05-04 13:47:06 -0700 | [diff] [blame] | 2960 | } |
| 2961 | |
Giulio Camuffo | 6b4b241 | 2015-01-29 19:06:49 +0200 | [diff] [blame] | 2962 | static struct weston_output * |
| 2963 | get_focused_output(struct weston_compositor *compositor) |
| 2964 | { |
| 2965 | struct weston_seat *seat; |
| 2966 | struct weston_output *output = NULL; |
| 2967 | |
| 2968 | wl_list_for_each(seat, &compositor->seat_list, link) { |
Derek Foreman | 1281a36 | 2015-07-31 16:55:32 -0500 | [diff] [blame] | 2969 | struct weston_touch *touch = weston_seat_get_touch(seat); |
| 2970 | struct weston_pointer *pointer = weston_seat_get_pointer(seat); |
| 2971 | struct weston_keyboard *keyboard = |
| 2972 | weston_seat_get_keyboard(seat); |
| 2973 | |
Giulio Camuffo | 6b4b241 | 2015-01-29 19:06:49 +0200 | [diff] [blame] | 2974 | /* Priority has touch focus, then pointer and |
| 2975 | * then keyboard focus. We should probably have |
| 2976 | * three for loops and check frist for touch, |
| 2977 | * then for pointer, etc. but unless somebody has some |
| 2978 | * objections, I think this is sufficient. */ |
Derek Foreman | 1281a36 | 2015-07-31 16:55:32 -0500 | [diff] [blame] | 2979 | if (touch && touch->focus) |
| 2980 | output = touch->focus->output; |
| 2981 | else if (pointer && pointer->focus) |
| 2982 | output = pointer->focus->output; |
| 2983 | else if (keyboard && keyboard->focus) |
| 2984 | output = keyboard->focus->output; |
Giulio Camuffo | 6b4b241 | 2015-01-29 19:06:49 +0200 | [diff] [blame] | 2985 | |
| 2986 | if (output) |
| 2987 | break; |
| 2988 | } |
| 2989 | |
| 2990 | return output; |
| 2991 | } |
| 2992 | |
| 2993 | static void |
| 2994 | shell_interface_set_maximized(struct shell_surface *shsurf) |
| 2995 | { |
| 2996 | struct weston_output *output; |
| 2997 | |
| 2998 | surface_clear_next_states(shsurf); |
| 2999 | shsurf->next_state.maximized = true; |
| 3000 | shsurf->state_changed = true; |
| 3001 | shsurf->type = SHELL_SURFACE_TOPLEVEL; |
| 3002 | |
| 3003 | if (!weston_surface_is_mapped(shsurf->surface)) |
| 3004 | output = get_focused_output(shsurf->surface->compositor); |
| 3005 | else |
| 3006 | output = shsurf->surface->output; |
| 3007 | |
| 3008 | shell_surface_set_output(shsurf, output); |
| 3009 | send_configure_for_surface(shsurf); |
| 3010 | } |
| 3011 | |
Kristian Høgsberg | ae356ae | 2014-04-29 16:03:54 -0700 | [diff] [blame] | 3012 | static int |
Derek Foreman | e4d6c83 | 2015-08-05 14:48:11 -0500 | [diff] [blame] | 3013 | shell_interface_move(struct shell_surface *shsurf, struct weston_pointer *pointer) |
Kristian Høgsberg | ae356ae | 2014-04-29 16:03:54 -0700 | [diff] [blame] | 3014 | { |
Derek Foreman | e4d6c83 | 2015-08-05 14:48:11 -0500 | [diff] [blame] | 3015 | return surface_move(shsurf, pointer, true); |
Kristian Høgsberg | ae356ae | 2014-04-29 16:03:54 -0700 | [diff] [blame] | 3016 | } |
| 3017 | |
Derek Foreman | 8fbebbd | 2015-07-15 13:00:40 -0500 | [diff] [blame] | 3018 | static int |
| 3019 | shell_interface_resize(struct shell_surface *shsurf, |
Derek Foreman | e4d6c83 | 2015-08-05 14:48:11 -0500 | [diff] [blame] | 3020 | struct weston_pointer *pointer, |
Derek Foreman | 8fbebbd | 2015-07-15 13:00:40 -0500 | [diff] [blame] | 3021 | uint32_t edges) |
| 3022 | { |
Derek Foreman | e4d6c83 | 2015-08-05 14:48:11 -0500 | [diff] [blame] | 3023 | return surface_resize(shsurf, pointer, edges); |
Derek Foreman | 8fbebbd | 2015-07-15 13:00:40 -0500 | [diff] [blame] | 3024 | } |
| 3025 | |
Kristian Høgsberg | 02bbabb | 2013-05-06 22:15:05 -0400 | [diff] [blame] | 3026 | static const struct weston_pointer_grab_interface popup_grab_interface; |
Giulio Camuffo | 5085a75 | 2013-03-25 21:42:45 +0100 | [diff] [blame] | 3027 | |
| 3028 | static void |
| 3029 | destroy_shell_seat(struct wl_listener *listener, void *data) |
| 3030 | { |
| 3031 | struct shell_seat *shseat = |
| 3032 | container_of(listener, |
| 3033 | struct shell_seat, seat_destroy_listener); |
Jonas Ådahl | c2b1011 | 2015-02-13 14:01:53 +0800 | [diff] [blame] | 3034 | struct shell_surface *shsurf, *next; |
Giulio Camuffo | 5085a75 | 2013-03-25 21:42:45 +0100 | [diff] [blame] | 3035 | |
| 3036 | if (shseat->popup_grab.grab.interface == &popup_grab_interface) { |
Kristian Høgsberg | 02bbabb | 2013-05-06 22:15:05 -0400 | [diff] [blame] | 3037 | weston_pointer_end_grab(shseat->popup_grab.grab.pointer); |
Giulio Camuffo | 5085a75 | 2013-03-25 21:42:45 +0100 | [diff] [blame] | 3038 | shseat->popup_grab.client = NULL; |
| 3039 | |
Jonas Ådahl | c2b1011 | 2015-02-13 14:01:53 +0800 | [diff] [blame] | 3040 | wl_list_for_each_safe(shsurf, next, |
| 3041 | &shseat->popup_grab.surfaces_list, |
| 3042 | popup.grab_link) { |
Giulio Camuffo | 5085a75 | 2013-03-25 21:42:45 +0100 | [diff] [blame] | 3043 | shsurf->popup.shseat = NULL; |
Jonas Ådahl | c2b1011 | 2015-02-13 14:01:53 +0800 | [diff] [blame] | 3044 | wl_list_init(&shsurf->popup.grab_link); |
Giulio Camuffo | 5085a75 | 2013-03-25 21:42:45 +0100 | [diff] [blame] | 3045 | } |
Giulio Camuffo | 5085a75 | 2013-03-25 21:42:45 +0100 | [diff] [blame] | 3046 | } |
| 3047 | |
| 3048 | wl_list_remove(&shseat->seat_destroy_listener.link); |
| 3049 | free(shseat); |
| 3050 | } |
| 3051 | |
Jason Ekstrand | 024177c | 2014-04-21 19:42:58 -0500 | [diff] [blame] | 3052 | static void |
| 3053 | shell_seat_caps_changed(struct wl_listener *listener, void *data) |
| 3054 | { |
Derek Foreman | 1281a36 | 2015-07-31 16:55:32 -0500 | [diff] [blame] | 3055 | struct weston_keyboard *keyboard; |
| 3056 | struct weston_pointer *pointer; |
Jason Ekstrand | 024177c | 2014-04-21 19:42:58 -0500 | [diff] [blame] | 3057 | struct shell_seat *seat; |
| 3058 | |
| 3059 | seat = container_of(listener, struct shell_seat, caps_changed_listener); |
Derek Foreman | 1281a36 | 2015-07-31 16:55:32 -0500 | [diff] [blame] | 3060 | keyboard = weston_seat_get_keyboard(seat->seat); |
| 3061 | pointer = weston_seat_get_pointer(seat->seat); |
Jason Ekstrand | 024177c | 2014-04-21 19:42:58 -0500 | [diff] [blame] | 3062 | |
Derek Foreman | 1281a36 | 2015-07-31 16:55:32 -0500 | [diff] [blame] | 3063 | if (keyboard && |
Jason Ekstrand | 024177c | 2014-04-21 19:42:58 -0500 | [diff] [blame] | 3064 | wl_list_empty(&seat->keyboard_focus_listener.link)) { |
Derek Foreman | 1281a36 | 2015-07-31 16:55:32 -0500 | [diff] [blame] | 3065 | wl_signal_add(&keyboard->focus_signal, |
Jason Ekstrand | 024177c | 2014-04-21 19:42:58 -0500 | [diff] [blame] | 3066 | &seat->keyboard_focus_listener); |
Derek Foreman | 1281a36 | 2015-07-31 16:55:32 -0500 | [diff] [blame] | 3067 | } else if (!keyboard) { |
Derek Foreman | 60d9731 | 2015-07-15 13:00:45 -0500 | [diff] [blame] | 3068 | wl_list_remove(&seat->keyboard_focus_listener.link); |
Jason Ekstrand | 024177c | 2014-04-21 19:42:58 -0500 | [diff] [blame] | 3069 | wl_list_init(&seat->keyboard_focus_listener.link); |
| 3070 | } |
| 3071 | |
Derek Foreman | 1281a36 | 2015-07-31 16:55:32 -0500 | [diff] [blame] | 3072 | if (pointer && |
Jason Ekstrand | 024177c | 2014-04-21 19:42:58 -0500 | [diff] [blame] | 3073 | wl_list_empty(&seat->pointer_focus_listener.link)) { |
Derek Foreman | 1281a36 | 2015-07-31 16:55:32 -0500 | [diff] [blame] | 3074 | wl_signal_add(&pointer->focus_signal, |
Jason Ekstrand | 024177c | 2014-04-21 19:42:58 -0500 | [diff] [blame] | 3075 | &seat->pointer_focus_listener); |
Derek Foreman | 1281a36 | 2015-07-31 16:55:32 -0500 | [diff] [blame] | 3076 | } else if (!pointer) { |
Derek Foreman | 60d9731 | 2015-07-15 13:00:45 -0500 | [diff] [blame] | 3077 | wl_list_remove(&seat->pointer_focus_listener.link); |
Jason Ekstrand | 024177c | 2014-04-21 19:42:58 -0500 | [diff] [blame] | 3078 | wl_list_init(&seat->pointer_focus_listener.link); |
| 3079 | } |
| 3080 | } |
| 3081 | |
Giulio Camuffo | 5085a75 | 2013-03-25 21:42:45 +0100 | [diff] [blame] | 3082 | static struct shell_seat * |
| 3083 | create_shell_seat(struct weston_seat *seat) |
| 3084 | { |
| 3085 | struct shell_seat *shseat; |
| 3086 | |
| 3087 | shseat = calloc(1, sizeof *shseat); |
| 3088 | if (!shseat) { |
| 3089 | weston_log("no memory to allocate shell seat\n"); |
| 3090 | return NULL; |
| 3091 | } |
| 3092 | |
| 3093 | shseat->seat = seat; |
| 3094 | wl_list_init(&shseat->popup_grab.surfaces_list); |
| 3095 | |
| 3096 | shseat->seat_destroy_listener.notify = destroy_shell_seat; |
| 3097 | wl_signal_add(&seat->destroy_signal, |
| 3098 | &shseat->seat_destroy_listener); |
| 3099 | |
Jason Ekstrand | 024177c | 2014-04-21 19:42:58 -0500 | [diff] [blame] | 3100 | shseat->keyboard_focus_listener.notify = handle_keyboard_focus; |
| 3101 | wl_list_init(&shseat->keyboard_focus_listener.link); |
| 3102 | |
| 3103 | shseat->pointer_focus_listener.notify = handle_pointer_focus; |
| 3104 | wl_list_init(&shseat->pointer_focus_listener.link); |
| 3105 | |
| 3106 | shseat->caps_changed_listener.notify = shell_seat_caps_changed; |
| 3107 | wl_signal_add(&seat->updated_caps_signal, |
| 3108 | &shseat->caps_changed_listener); |
| 3109 | shell_seat_caps_changed(&shseat->caps_changed_listener, NULL); |
| 3110 | |
Giulio Camuffo | 5085a75 | 2013-03-25 21:42:45 +0100 | [diff] [blame] | 3111 | return shseat; |
| 3112 | } |
| 3113 | |
| 3114 | static struct shell_seat * |
| 3115 | get_shell_seat(struct weston_seat *seat) |
| 3116 | { |
| 3117 | struct wl_listener *listener; |
| 3118 | |
| 3119 | listener = wl_signal_get(&seat->destroy_signal, destroy_shell_seat); |
Jason Ekstrand | 024177c | 2014-04-21 19:42:58 -0500 | [diff] [blame] | 3120 | assert(listener != NULL); |
Giulio Camuffo | 5085a75 | 2013-03-25 21:42:45 +0100 | [diff] [blame] | 3121 | |
| 3122 | return container_of(listener, |
| 3123 | struct shell_seat, seat_destroy_listener); |
| 3124 | } |
| 3125 | |
Kristian Høgsberg | b810eb5 | 2013-02-12 20:07:05 -0500 | [diff] [blame] | 3126 | static void |
Kristian Høgsberg | 6848c25 | 2013-05-08 22:02:59 -0400 | [diff] [blame] | 3127 | popup_grab_focus(struct weston_pointer_grab *grab) |
Kristian Høgsberg | b3cca0a | 2012-01-04 22:19:14 -0500 | [diff] [blame] | 3128 | { |
Kristian Høgsberg | 02bbabb | 2013-05-06 22:15:05 -0400 | [diff] [blame] | 3129 | struct weston_pointer *pointer = grab->pointer; |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 3130 | struct weston_view *view; |
Giulio Camuffo | 5085a75 | 2013-03-25 21:42:45 +0100 | [diff] [blame] | 3131 | struct shell_seat *shseat = |
| 3132 | container_of(grab, struct shell_seat, popup_grab.grab); |
| 3133 | struct wl_client *client = shseat->popup_grab.client; |
Kristian Høgsberg | 6848c25 | 2013-05-08 22:02:59 -0400 | [diff] [blame] | 3134 | wl_fixed_t sx, sy; |
| 3135 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 3136 | view = weston_compositor_pick_view(pointer->seat->compositor, |
| 3137 | pointer->x, pointer->y, |
| 3138 | &sx, &sy); |
Kristian Høgsberg | b3cca0a | 2012-01-04 22:19:14 -0500 | [diff] [blame] | 3139 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 3140 | if (view && view->surface->resource && |
| 3141 | wl_resource_get_client(view->surface->resource) == client) { |
| 3142 | weston_pointer_set_focus(pointer, view, sx, sy); |
Kristian Høgsberg | b3cca0a | 2012-01-04 22:19:14 -0500 | [diff] [blame] | 3143 | } else { |
Derek Foreman | f9318d1 | 2015-05-11 15:40:11 -0500 | [diff] [blame] | 3144 | weston_pointer_clear_focus(pointer); |
Kristian Høgsberg | b3cca0a | 2012-01-04 22:19:14 -0500 | [diff] [blame] | 3145 | } |
| 3146 | } |
| 3147 | |
| 3148 | static void |
Giulio Camuffo | 1959ab8 | 2013-11-14 23:42:52 +0100 | [diff] [blame] | 3149 | popup_grab_motion(struct weston_pointer_grab *grab, uint32_t time, |
Jonas Ådahl | d251010 | 2014-10-05 21:39:14 +0200 | [diff] [blame] | 3150 | struct weston_pointer_motion_event *event) |
Kristian Høgsberg | b3cca0a | 2012-01-04 22:19:14 -0500 | [diff] [blame] | 3151 | { |
Kristian Høgsberg | be6403e | 2013-05-08 21:03:21 -0400 | [diff] [blame] | 3152 | struct weston_pointer *pointer = grab->pointer; |
Neil Roberts | 96d790e | 2013-09-19 17:32:00 +0100 | [diff] [blame] | 3153 | struct wl_resource *resource; |
Jonas Ådahl | 2cbf293 | 2015-07-22 12:05:38 +0800 | [diff] [blame] | 3154 | struct wl_list *resource_list; |
Jonas Ådahl | d251010 | 2014-10-05 21:39:14 +0200 | [diff] [blame] | 3155 | wl_fixed_t x, y; |
Kristian Høgsberg | be6403e | 2013-05-08 21:03:21 -0400 | [diff] [blame] | 3156 | wl_fixed_t sx, sy; |
Kristian Høgsberg | b3cca0a | 2012-01-04 22:19:14 -0500 | [diff] [blame] | 3157 | |
Jonas Ådahl | 61917c8 | 2014-08-11 22:44:02 +0200 | [diff] [blame] | 3158 | if (pointer->focus) { |
Jonas Ådahl | d251010 | 2014-10-05 21:39:14 +0200 | [diff] [blame] | 3159 | weston_pointer_motion_to_abs(pointer, event, &x, &y); |
Jonas Ådahl | 61917c8 | 2014-08-11 22:44:02 +0200 | [diff] [blame] | 3160 | weston_view_from_global_fixed(pointer->focus, x, y, |
| 3161 | &pointer->sx, &pointer->sy); |
| 3162 | } |
| 3163 | |
Jonas Ådahl | d251010 | 2014-10-05 21:39:14 +0200 | [diff] [blame] | 3164 | weston_pointer_move(pointer, event); |
Giulio Camuffo | 1959ab8 | 2013-11-14 23:42:52 +0100 | [diff] [blame] | 3165 | |
Jonas Ådahl | 2cbf293 | 2015-07-22 12:05:38 +0800 | [diff] [blame] | 3166 | if (!pointer->focus_client) |
| 3167 | return; |
| 3168 | |
| 3169 | resource_list = &pointer->focus_client->pointer_resources; |
| 3170 | wl_resource_for_each(resource, resource_list) { |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 3171 | weston_view_from_global_fixed(pointer->focus, |
| 3172 | pointer->x, pointer->y, |
| 3173 | &sx, &sy); |
Neil Roberts | 96d790e | 2013-09-19 17:32:00 +0100 | [diff] [blame] | 3174 | wl_pointer_send_motion(resource, time, sx, sy); |
Kristian Høgsberg | be6403e | 2013-05-08 21:03:21 -0400 | [diff] [blame] | 3175 | } |
Kristian Høgsberg | b3cca0a | 2012-01-04 22:19:14 -0500 | [diff] [blame] | 3176 | } |
| 3177 | |
| 3178 | static void |
Kristian Høgsberg | 02bbabb | 2013-05-06 22:15:05 -0400 | [diff] [blame] | 3179 | popup_grab_button(struct weston_pointer_grab *grab, |
Daniel Stone | 4dbadb1 | 2012-05-30 16:31:51 +0100 | [diff] [blame] | 3180 | uint32_t time, uint32_t button, uint32_t state_w) |
Kristian Høgsberg | b3cca0a | 2012-01-04 22:19:14 -0500 | [diff] [blame] | 3181 | { |
| 3182 | struct wl_resource *resource; |
Giulio Camuffo | 5085a75 | 2013-03-25 21:42:45 +0100 | [diff] [blame] | 3183 | struct shell_seat *shseat = |
| 3184 | container_of(grab, struct shell_seat, popup_grab.grab); |
Rob Bradford | 880ebc7 | 2013-07-22 17:31:38 +0100 | [diff] [blame] | 3185 | struct wl_display *display = shseat->seat->compositor->wl_display; |
Daniel Stone | 4dbadb1 | 2012-05-30 16:31:51 +0100 | [diff] [blame] | 3186 | enum wl_pointer_button_state state = state_w; |
Kristian Høgsberg | eae5de7 | 2012-04-11 22:42:15 -0400 | [diff] [blame] | 3187 | uint32_t serial; |
Jonas Ådahl | 2cbf293 | 2015-07-22 12:05:38 +0800 | [diff] [blame] | 3188 | struct wl_list *resource_list = NULL; |
Kristian Høgsberg | b3cca0a | 2012-01-04 22:19:14 -0500 | [diff] [blame] | 3189 | |
Jonas Ådahl | 2cbf293 | 2015-07-22 12:05:38 +0800 | [diff] [blame] | 3190 | if (grab->pointer->focus_client) |
| 3191 | resource_list = &grab->pointer->focus_client->pointer_resources; |
| 3192 | if (resource_list && !wl_list_empty(resource_list)) { |
Kristian Høgsberg | eae5de7 | 2012-04-11 22:42:15 -0400 | [diff] [blame] | 3193 | serial = wl_display_get_serial(display); |
Neil Roberts | 96d790e | 2013-09-19 17:32:00 +0100 | [diff] [blame] | 3194 | wl_resource_for_each(resource, resource_list) { |
| 3195 | wl_pointer_send_button(resource, serial, |
| 3196 | time, button, state); |
| 3197 | } |
Daniel Stone | 4dbadb1 | 2012-05-30 16:31:51 +0100 | [diff] [blame] | 3198 | } else if (state == WL_POINTER_BUTTON_STATE_RELEASED && |
Giulio Camuffo | 5085a75 | 2013-03-25 21:42:45 +0100 | [diff] [blame] | 3199 | (shseat->popup_grab.initial_up || |
Derek Foreman | f7b2f8b | 2015-07-15 13:00:41 -0500 | [diff] [blame] | 3200 | time - grab->pointer->grab_time > 500)) { |
Kristian Høgsberg | 57e0907 | 2012-10-30 14:07:27 -0400 | [diff] [blame] | 3201 | popup_grab_end(grab->pointer); |
Kristian Høgsberg | b3cca0a | 2012-01-04 22:19:14 -0500 | [diff] [blame] | 3202 | } |
| 3203 | |
Daniel Stone | 4dbadb1 | 2012-05-30 16:31:51 +0100 | [diff] [blame] | 3204 | if (state == WL_POINTER_BUTTON_STATE_RELEASED) |
Giulio Camuffo | 5085a75 | 2013-03-25 21:42:45 +0100 | [diff] [blame] | 3205 | shseat->popup_grab.initial_up = 1; |
Kristian Høgsberg | b3cca0a | 2012-01-04 22:19:14 -0500 | [diff] [blame] | 3206 | } |
| 3207 | |
Jonas Ådahl | 1ea343e | 2013-10-25 23:18:05 +0200 | [diff] [blame] | 3208 | static void |
Jonas Ådahl | 0336ca0 | 2014-10-04 16:28:29 +0200 | [diff] [blame] | 3209 | popup_grab_axis(struct weston_pointer_grab *grab, |
| 3210 | uint32_t time, uint32_t axis, wl_fixed_t value) |
| 3211 | { |
Peter Hutterer | 1118952 | 2015-11-16 12:35:57 +1000 | [diff] [blame] | 3212 | weston_pointer_send_axis(grab->pointer, time, axis, value); |
Jonas Ådahl | 0336ca0 | 2014-10-04 16:28:29 +0200 | [diff] [blame] | 3213 | } |
| 3214 | |
| 3215 | static void |
Jonas Ådahl | 1ea343e | 2013-10-25 23:18:05 +0200 | [diff] [blame] | 3216 | popup_grab_cancel(struct weston_pointer_grab *grab) |
| 3217 | { |
| 3218 | popup_grab_end(grab->pointer); |
| 3219 | } |
| 3220 | |
Kristian Høgsberg | 02bbabb | 2013-05-06 22:15:05 -0400 | [diff] [blame] | 3221 | static const struct weston_pointer_grab_interface popup_grab_interface = { |
Kristian Høgsberg | b3cca0a | 2012-01-04 22:19:14 -0500 | [diff] [blame] | 3222 | popup_grab_focus, |
| 3223 | popup_grab_motion, |
| 3224 | popup_grab_button, |
Jonas Ådahl | 0336ca0 | 2014-10-04 16:28:29 +0200 | [diff] [blame] | 3225 | popup_grab_axis, |
Jonas Ådahl | 1ea343e | 2013-10-25 23:18:05 +0200 | [diff] [blame] | 3226 | popup_grab_cancel, |
Kristian Høgsberg | b3cca0a | 2012-01-04 22:19:14 -0500 | [diff] [blame] | 3227 | }; |
| 3228 | |
| 3229 | static void |
Jonny Lamb | 76cf1fe | 2014-08-20 11:27:10 +0200 | [diff] [blame] | 3230 | touch_popup_grab_down(struct weston_touch_grab *grab, uint32_t time, |
Giulio Camuffo | 61ed7b6 | 2015-07-08 11:55:28 +0300 | [diff] [blame] | 3231 | int touch_id, wl_fixed_t x, wl_fixed_t y) |
Jonny Lamb | 76cf1fe | 2014-08-20 11:27:10 +0200 | [diff] [blame] | 3232 | { |
| 3233 | struct wl_resource *resource; |
| 3234 | struct shell_seat *shseat = |
| 3235 | container_of(grab, struct shell_seat, popup_grab.touch_grab); |
| 3236 | struct wl_display *display = shseat->seat->compositor->wl_display; |
| 3237 | uint32_t serial; |
| 3238 | struct wl_list *resource_list; |
Giulio Camuffo | 61ed7b6 | 2015-07-08 11:55:28 +0300 | [diff] [blame] | 3239 | wl_fixed_t sx, sy; |
| 3240 | |
| 3241 | weston_view_from_global_fixed(grab->touch->focus, x, y, &sx, &sy); |
Jonny Lamb | 76cf1fe | 2014-08-20 11:27:10 +0200 | [diff] [blame] | 3242 | |
| 3243 | resource_list = &grab->touch->focus_resource_list; |
| 3244 | if (!wl_list_empty(resource_list)) { |
| 3245 | serial = wl_display_get_serial(display); |
| 3246 | wl_resource_for_each(resource, resource_list) { |
| 3247 | wl_touch_send_down(resource, serial, time, |
| 3248 | grab->touch->focus->surface->resource, |
| 3249 | touch_id, sx, sy); |
| 3250 | } |
| 3251 | } |
| 3252 | } |
| 3253 | |
| 3254 | static void |
| 3255 | touch_popup_grab_up(struct weston_touch_grab *grab, uint32_t time, int touch_id) |
| 3256 | { |
| 3257 | struct wl_resource *resource; |
| 3258 | struct shell_seat *shseat = |
| 3259 | container_of(grab, struct shell_seat, popup_grab.touch_grab); |
| 3260 | struct wl_display *display = shseat->seat->compositor->wl_display; |
| 3261 | uint32_t serial; |
| 3262 | struct wl_list *resource_list; |
| 3263 | |
| 3264 | resource_list = &grab->touch->focus_resource_list; |
| 3265 | if (!wl_list_empty(resource_list)) { |
| 3266 | serial = wl_display_get_serial(display); |
| 3267 | wl_resource_for_each(resource, resource_list) { |
| 3268 | wl_touch_send_up(resource, serial, time, touch_id); |
| 3269 | } |
| 3270 | } |
| 3271 | } |
| 3272 | |
| 3273 | static void |
| 3274 | touch_popup_grab_motion(struct weston_touch_grab *grab, uint32_t time, |
Giulio Camuffo | 61ed7b6 | 2015-07-08 11:55:28 +0300 | [diff] [blame] | 3275 | int touch_id, wl_fixed_t x, wl_fixed_t y) |
Jonny Lamb | 76cf1fe | 2014-08-20 11:27:10 +0200 | [diff] [blame] | 3276 | { |
| 3277 | struct wl_resource *resource; |
| 3278 | struct wl_list *resource_list; |
Giulio Camuffo | 61ed7b6 | 2015-07-08 11:55:28 +0300 | [diff] [blame] | 3279 | wl_fixed_t sx, sy; |
| 3280 | |
| 3281 | weston_view_from_global_fixed(grab->touch->focus, x, y, &sx, &sy); |
Jonny Lamb | 76cf1fe | 2014-08-20 11:27:10 +0200 | [diff] [blame] | 3282 | |
| 3283 | resource_list = &grab->touch->focus_resource_list; |
| 3284 | if (!wl_list_empty(resource_list)) { |
| 3285 | wl_resource_for_each(resource, resource_list) { |
| 3286 | wl_touch_send_motion(resource, time, touch_id, sx, sy); |
| 3287 | } |
| 3288 | } |
| 3289 | } |
| 3290 | |
| 3291 | static void |
| 3292 | touch_popup_grab_frame(struct weston_touch_grab *grab) |
| 3293 | { |
| 3294 | } |
| 3295 | |
| 3296 | static void |
| 3297 | touch_popup_grab_cancel(struct weston_touch_grab *grab) |
| 3298 | { |
| 3299 | touch_popup_grab_end(grab->touch); |
| 3300 | } |
| 3301 | |
| 3302 | static const struct weston_touch_grab_interface touch_popup_grab_interface = { |
| 3303 | touch_popup_grab_down, |
| 3304 | touch_popup_grab_up, |
| 3305 | touch_popup_grab_motion, |
| 3306 | touch_popup_grab_frame, |
| 3307 | touch_popup_grab_cancel, |
| 3308 | }; |
| 3309 | |
| 3310 | static void |
Rafael Antognolli | e2a3455 | 2013-12-03 15:35:45 -0200 | [diff] [blame] | 3311 | shell_surface_send_popup_done(struct shell_surface *shsurf) |
| 3312 | { |
| 3313 | if (shell_surface_is_wl_shell_surface(shsurf)) |
| 3314 | wl_shell_surface_send_popup_done(shsurf->resource); |
| 3315 | else if (shell_surface_is_xdg_popup(shsurf)) |
Jasper St. Pierre | ecf2a0f | 2015-02-13 14:01:56 +0800 | [diff] [blame] | 3316 | xdg_popup_send_popup_done(shsurf->resource); |
Rafael Antognolli | e2a3455 | 2013-12-03 15:35:45 -0200 | [diff] [blame] | 3317 | } |
| 3318 | |
| 3319 | static void |
Kristian Høgsberg | 02bbabb | 2013-05-06 22:15:05 -0400 | [diff] [blame] | 3320 | popup_grab_end(struct weston_pointer *pointer) |
Kristian Høgsberg | 57e0907 | 2012-10-30 14:07:27 -0400 | [diff] [blame] | 3321 | { |
Kristian Høgsberg | 02bbabb | 2013-05-06 22:15:05 -0400 | [diff] [blame] | 3322 | struct weston_pointer_grab *grab = pointer->grab; |
Giulio Camuffo | 5085a75 | 2013-03-25 21:42:45 +0100 | [diff] [blame] | 3323 | struct shell_seat *shseat = |
| 3324 | container_of(grab, struct shell_seat, popup_grab.grab); |
| 3325 | struct shell_surface *shsurf; |
Jonas Ådahl | c2b1011 | 2015-02-13 14:01:53 +0800 | [diff] [blame] | 3326 | struct shell_surface *next; |
Kristian Høgsberg | 57e0907 | 2012-10-30 14:07:27 -0400 | [diff] [blame] | 3327 | |
| 3328 | if (pointer->grab->interface == &popup_grab_interface) { |
Kristian Høgsberg | 02bbabb | 2013-05-06 22:15:05 -0400 | [diff] [blame] | 3329 | weston_pointer_end_grab(grab->pointer); |
Giulio Camuffo | 5085a75 | 2013-03-25 21:42:45 +0100 | [diff] [blame] | 3330 | shseat->popup_grab.client = NULL; |
Philipp Brüschweiler | 63e7be6 | 2013-04-15 21:09:54 +0200 | [diff] [blame] | 3331 | shseat->popup_grab.grab.interface = NULL; |
| 3332 | assert(!wl_list_empty(&shseat->popup_grab.surfaces_list)); |
Giulio Camuffo | 5085a75 | 2013-03-25 21:42:45 +0100 | [diff] [blame] | 3333 | /* Send the popup_done event to all the popups open */ |
Jonas Ådahl | c2b1011 | 2015-02-13 14:01:53 +0800 | [diff] [blame] | 3334 | wl_list_for_each_safe(shsurf, next, |
| 3335 | &shseat->popup_grab.surfaces_list, |
| 3336 | popup.grab_link) { |
Rafael Antognolli | e2a3455 | 2013-12-03 15:35:45 -0200 | [diff] [blame] | 3337 | shell_surface_send_popup_done(shsurf); |
Giulio Camuffo | 5085a75 | 2013-03-25 21:42:45 +0100 | [diff] [blame] | 3338 | shsurf->popup.shseat = NULL; |
Jonas Ådahl | c2b1011 | 2015-02-13 14:01:53 +0800 | [diff] [blame] | 3339 | wl_list_init(&shsurf->popup.grab_link); |
Giulio Camuffo | 5085a75 | 2013-03-25 21:42:45 +0100 | [diff] [blame] | 3340 | } |
Giulio Camuffo | 5085a75 | 2013-03-25 21:42:45 +0100 | [diff] [blame] | 3341 | wl_list_init(&shseat->popup_grab.surfaces_list); |
| 3342 | } |
| 3343 | } |
| 3344 | |
| 3345 | static void |
Jonny Lamb | 76cf1fe | 2014-08-20 11:27:10 +0200 | [diff] [blame] | 3346 | touch_popup_grab_end(struct weston_touch *touch) |
| 3347 | { |
| 3348 | struct weston_touch_grab *grab = touch->grab; |
| 3349 | struct shell_seat *shseat = |
| 3350 | container_of(grab, struct shell_seat, popup_grab.touch_grab); |
| 3351 | struct shell_surface *shsurf; |
Jonas Ådahl | c2b1011 | 2015-02-13 14:01:53 +0800 | [diff] [blame] | 3352 | struct shell_surface *next; |
Jonny Lamb | 76cf1fe | 2014-08-20 11:27:10 +0200 | [diff] [blame] | 3353 | |
| 3354 | if (touch->grab->interface == &touch_popup_grab_interface) { |
| 3355 | weston_touch_end_grab(grab->touch); |
| 3356 | shseat->popup_grab.client = NULL; |
| 3357 | shseat->popup_grab.touch_grab.interface = NULL; |
| 3358 | assert(!wl_list_empty(&shseat->popup_grab.surfaces_list)); |
| 3359 | /* Send the popup_done event to all the popups open */ |
Jonas Ådahl | c2b1011 | 2015-02-13 14:01:53 +0800 | [diff] [blame] | 3360 | wl_list_for_each_safe(shsurf, next, |
| 3361 | &shseat->popup_grab.surfaces_list, |
| 3362 | popup.grab_link) { |
Jonny Lamb | 76cf1fe | 2014-08-20 11:27:10 +0200 | [diff] [blame] | 3363 | shell_surface_send_popup_done(shsurf); |
| 3364 | shsurf->popup.shseat = NULL; |
Jonas Ådahl | c2b1011 | 2015-02-13 14:01:53 +0800 | [diff] [blame] | 3365 | wl_list_init(&shsurf->popup.grab_link); |
Jonny Lamb | 76cf1fe | 2014-08-20 11:27:10 +0200 | [diff] [blame] | 3366 | } |
Jonny Lamb | 76cf1fe | 2014-08-20 11:27:10 +0200 | [diff] [blame] | 3367 | wl_list_init(&shseat->popup_grab.surfaces_list); |
| 3368 | } |
| 3369 | } |
| 3370 | |
Jasper St. Pierre | da6ecd0 | 2015-02-27 18:35:45 +0800 | [diff] [blame] | 3371 | static struct shell_surface * |
| 3372 | get_top_popup(struct shell_seat *shseat) |
| 3373 | { |
| 3374 | struct shell_surface *shsurf; |
| 3375 | |
| 3376 | if (wl_list_empty(&shseat->popup_grab.surfaces_list)) { |
| 3377 | return NULL; |
| 3378 | } else { |
| 3379 | shsurf = container_of(shseat->popup_grab.surfaces_list.next, |
| 3380 | struct shell_surface, |
| 3381 | popup.grab_link); |
| 3382 | return shsurf; |
| 3383 | } |
| 3384 | } |
| 3385 | |
| 3386 | static int |
Jonas Ådahl | 01193ae | 2015-02-13 14:01:54 +0800 | [diff] [blame] | 3387 | add_popup_grab(struct shell_surface *shsurf, |
| 3388 | struct shell_seat *shseat, |
| 3389 | int32_t type) |
Giulio Camuffo | 5085a75 | 2013-03-25 21:42:45 +0100 | [diff] [blame] | 3390 | { |
Kristian Høgsberg | e314875 | 2013-05-06 23:19:49 -0400 | [diff] [blame] | 3391 | struct weston_seat *seat = shseat->seat; |
Jasper St. Pierre | da6ecd0 | 2015-02-27 18:35:45 +0800 | [diff] [blame] | 3392 | struct shell_surface *parent, *top_surface; |
Derek Foreman | 1281a36 | 2015-07-31 16:55:32 -0500 | [diff] [blame] | 3393 | struct weston_pointer *pointer = weston_seat_get_pointer(seat); |
| 3394 | struct weston_touch *touch = weston_seat_get_touch(seat); |
Jasper St. Pierre | da6ecd0 | 2015-02-27 18:35:45 +0800 | [diff] [blame] | 3395 | |
| 3396 | parent = get_shell_surface(shsurf->parent); |
| 3397 | top_surface = get_top_popup(shseat); |
| 3398 | if (shell_surface_is_xdg_popup(shsurf) && |
Dima Ryazanov | 497f25d | 2015-04-08 11:51:57 -0700 | [diff] [blame] | 3399 | (!parent || |
| 3400 | (top_surface == NULL && !shell_surface_is_xdg_surface(parent)) || |
Jasper St. Pierre | da6ecd0 | 2015-02-27 18:35:45 +0800 | [diff] [blame] | 3401 | (top_surface != NULL && parent != top_surface))) { |
Jonas Ådahl | ee45a55 | 2015-03-18 16:37:47 +0800 | [diff] [blame] | 3402 | wl_resource_post_error(shsurf->owner_resource, |
| 3403 | XDG_SHELL_ERROR_NOT_THE_TOPMOST_POPUP, |
Jasper St. Pierre | da6ecd0 | 2015-02-27 18:35:45 +0800 | [diff] [blame] | 3404 | "xdg_popup was not created on the " |
| 3405 | "topmost popup"); |
| 3406 | return -1; |
| 3407 | } |
Giulio Camuffo | 5085a75 | 2013-03-25 21:42:45 +0100 | [diff] [blame] | 3408 | |
| 3409 | if (wl_list_empty(&shseat->popup_grab.surfaces_list)) { |
Jonny Lamb | 76cf1fe | 2014-08-20 11:27:10 +0200 | [diff] [blame] | 3410 | shseat->popup_grab.type = type; |
Jonas Ådahl | 01193ae | 2015-02-13 14:01:54 +0800 | [diff] [blame] | 3411 | shseat->popup_grab.client = |
| 3412 | wl_resource_get_client(shsurf->resource); |
Jonny Lamb | 76cf1fe | 2014-08-20 11:27:10 +0200 | [diff] [blame] | 3413 | |
| 3414 | if (type == POINTER) { |
Jonas Ådahl | 01193ae | 2015-02-13 14:01:54 +0800 | [diff] [blame] | 3415 | shseat->popup_grab.grab.interface = |
| 3416 | &popup_grab_interface; |
| 3417 | |
| 3418 | /* We must make sure here that this popup was opened |
| 3419 | * after a mouse press, and not just by moving around |
| 3420 | * with other popups already open. */ |
Derek Foreman | 1281a36 | 2015-07-31 16:55:32 -0500 | [diff] [blame] | 3421 | if (pointer->button_count > 0) |
Jonny Lamb | 76cf1fe | 2014-08-20 11:27:10 +0200 | [diff] [blame] | 3422 | shseat->popup_grab.initial_up = 0; |
| 3423 | } else if (type == TOUCH) { |
Jonas Ådahl | 01193ae | 2015-02-13 14:01:54 +0800 | [diff] [blame] | 3424 | shseat->popup_grab.touch_grab.interface = |
| 3425 | &touch_popup_grab_interface; |
Jonny Lamb | 76cf1fe | 2014-08-20 11:27:10 +0200 | [diff] [blame] | 3426 | } |
Giulio Camuffo | 5085a75 | 2013-03-25 21:42:45 +0100 | [diff] [blame] | 3427 | |
Jonas Ådahl | 01193ae | 2015-02-13 14:01:54 +0800 | [diff] [blame] | 3428 | wl_list_insert(&shseat->popup_grab.surfaces_list, |
| 3429 | &shsurf->popup.grab_link); |
Jonny Lamb | 76cf1fe | 2014-08-20 11:27:10 +0200 | [diff] [blame] | 3430 | |
Jonas Ådahl | 01193ae | 2015-02-13 14:01:54 +0800 | [diff] [blame] | 3431 | if (type == POINTER) { |
Derek Foreman | 1281a36 | 2015-07-31 16:55:32 -0500 | [diff] [blame] | 3432 | weston_pointer_start_grab(pointer, |
Jonas Ådahl | 01193ae | 2015-02-13 14:01:54 +0800 | [diff] [blame] | 3433 | &shseat->popup_grab.grab); |
| 3434 | } else if (type == TOUCH) { |
Derek Foreman | 1281a36 | 2015-07-31 16:55:32 -0500 | [diff] [blame] | 3435 | weston_touch_start_grab(touch, |
Jonas Ådahl | 01193ae | 2015-02-13 14:01:54 +0800 | [diff] [blame] | 3436 | &shseat->popup_grab.touch_grab); |
| 3437 | } |
Rob Bradford | dfe3105 | 2013-06-26 19:49:11 +0100 | [diff] [blame] | 3438 | } else { |
Jonas Ådahl | 01193ae | 2015-02-13 14:01:54 +0800 | [diff] [blame] | 3439 | wl_list_insert(&shseat->popup_grab.surfaces_list, |
| 3440 | &shsurf->popup.grab_link); |
Giulio Camuffo | 5085a75 | 2013-03-25 21:42:45 +0100 | [diff] [blame] | 3441 | } |
Jasper St. Pierre | da6ecd0 | 2015-02-27 18:35:45 +0800 | [diff] [blame] | 3442 | |
| 3443 | return 0; |
Giulio Camuffo | 5085a75 | 2013-03-25 21:42:45 +0100 | [diff] [blame] | 3444 | } |
| 3445 | |
| 3446 | static void |
| 3447 | remove_popup_grab(struct shell_surface *shsurf) |
| 3448 | { |
| 3449 | struct shell_seat *shseat = shsurf->popup.shseat; |
| 3450 | |
Jasper St. Pierre | da6ecd0 | 2015-02-27 18:35:45 +0800 | [diff] [blame] | 3451 | if (shell_surface_is_xdg_popup(shsurf) && |
| 3452 | get_top_popup(shseat) != shsurf) { |
Jonas Ådahl | ee45a55 | 2015-03-18 16:37:47 +0800 | [diff] [blame] | 3453 | wl_resource_post_error(shsurf->owner_resource, |
| 3454 | XDG_SHELL_ERROR_NOT_THE_TOPMOST_POPUP, |
Jasper St. Pierre | da6ecd0 | 2015-02-27 18:35:45 +0800 | [diff] [blame] | 3455 | "xdg_popup was destroyed while it was " |
| 3456 | "not the topmost popup."); |
| 3457 | return; |
| 3458 | } |
| 3459 | |
Giulio Camuffo | 5085a75 | 2013-03-25 21:42:45 +0100 | [diff] [blame] | 3460 | wl_list_remove(&shsurf->popup.grab_link); |
| 3461 | wl_list_init(&shsurf->popup.grab_link); |
| 3462 | if (wl_list_empty(&shseat->popup_grab.surfaces_list)) { |
Jonny Lamb | 76cf1fe | 2014-08-20 11:27:10 +0200 | [diff] [blame] | 3463 | if (shseat->popup_grab.type == POINTER) { |
| 3464 | weston_pointer_end_grab(shseat->popup_grab.grab.pointer); |
| 3465 | shseat->popup_grab.grab.interface = NULL; |
| 3466 | } else if (shseat->popup_grab.type == TOUCH) { |
| 3467 | weston_touch_end_grab(shseat->popup_grab.touch_grab.touch); |
| 3468 | shseat->popup_grab.touch_grab.interface = NULL; |
| 3469 | } |
Kristian Høgsberg | 57e0907 | 2012-10-30 14:07:27 -0400 | [diff] [blame] | 3470 | } |
| 3471 | } |
| 3472 | |
Jasper St. Pierre | da6ecd0 | 2015-02-27 18:35:45 +0800 | [diff] [blame] | 3473 | static int |
Kristian Høgsberg | 3730f36 | 2012-04-13 12:40:07 -0400 | [diff] [blame] | 3474 | shell_map_popup(struct shell_surface *shsurf) |
Kristian Høgsberg | b3cca0a | 2012-01-04 22:19:14 -0500 | [diff] [blame] | 3475 | { |
Giulio Camuffo | 5085a75 | 2013-03-25 21:42:45 +0100 | [diff] [blame] | 3476 | struct shell_seat *shseat = shsurf->popup.shseat; |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 3477 | struct weston_view *parent_view = get_default_view(shsurf->parent); |
Derek Foreman | 1281a36 | 2015-07-31 16:55:32 -0500 | [diff] [blame] | 3478 | struct weston_pointer *pointer = weston_seat_get_pointer(shseat->seat); |
| 3479 | struct weston_touch *touch = weston_seat_get_touch(shseat->seat); |
Kristian Høgsberg | b3cca0a | 2012-01-04 22:19:14 -0500 | [diff] [blame] | 3480 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 3481 | shsurf->surface->output = parent_view->output; |
| 3482 | shsurf->view->output = parent_view->output; |
Kristian Høgsberg | b3cca0a | 2012-01-04 22:19:14 -0500 | [diff] [blame] | 3483 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 3484 | weston_view_set_transform_parent(shsurf->view, parent_view); |
| 3485 | weston_view_set_position(shsurf->view, shsurf->popup.x, shsurf->popup.y); |
| 3486 | weston_view_update_transform(shsurf->view); |
Kristian Høgsberg | b3cca0a | 2012-01-04 22:19:14 -0500 | [diff] [blame] | 3487 | |
Derek Foreman | 1281a36 | 2015-07-31 16:55:32 -0500 | [diff] [blame] | 3488 | if (pointer && |
| 3489 | pointer->grab_serial == shsurf->popup.serial) { |
Jasper St. Pierre | da6ecd0 | 2015-02-27 18:35:45 +0800 | [diff] [blame] | 3490 | if (add_popup_grab(shsurf, shseat, POINTER) != 0) |
| 3491 | return -1; |
Derek Foreman | 1281a36 | 2015-07-31 16:55:32 -0500 | [diff] [blame] | 3492 | } else if (touch && |
| 3493 | touch->grab_serial == shsurf->popup.serial) { |
Jasper St. Pierre | da6ecd0 | 2015-02-27 18:35:45 +0800 | [diff] [blame] | 3494 | if (add_popup_grab(shsurf, shseat, TOUCH) != 0) |
| 3495 | return -1; |
Kristian Høgsberg | 3730f36 | 2012-04-13 12:40:07 -0400 | [diff] [blame] | 3496 | } else { |
Rafael Antognolli | e2a3455 | 2013-12-03 15:35:45 -0200 | [diff] [blame] | 3497 | shell_surface_send_popup_done(shsurf); |
Giulio Camuffo | 5085a75 | 2013-03-25 21:42:45 +0100 | [diff] [blame] | 3498 | shseat->popup_grab.client = NULL; |
Kristian Høgsberg | 3730f36 | 2012-04-13 12:40:07 -0400 | [diff] [blame] | 3499 | } |
Jasper St. Pierre | da6ecd0 | 2015-02-27 18:35:45 +0800 | [diff] [blame] | 3500 | |
| 3501 | return 0; |
Kristian Høgsberg | b3cca0a | 2012-01-04 22:19:14 -0500 | [diff] [blame] | 3502 | } |
| 3503 | |
Pekka Paalanen | 9d1613e | 2011-11-25 12:09:16 +0200 | [diff] [blame] | 3504 | static const struct wl_shell_surface_interface shell_surface_implementation = { |
Scott Moreau | ff1db4a | 2012-04-17 19:06:18 -0600 | [diff] [blame] | 3505 | shell_surface_pong, |
Pekka Paalanen | 9d1613e | 2011-11-25 12:09:16 +0200 | [diff] [blame] | 3506 | shell_surface_move, |
| 3507 | shell_surface_resize, |
| 3508 | shell_surface_set_toplevel, |
| 3509 | shell_surface_set_transient, |
Kristian Høgsberg | b3cca0a | 2012-01-04 22:19:14 -0500 | [diff] [blame] | 3510 | shell_surface_set_fullscreen, |
Juan Zhao | 96879df | 2012-02-07 08:45:41 +0800 | [diff] [blame] | 3511 | shell_surface_set_popup, |
Kristian Høgsberg | e7afd91 | 2012-05-02 09:47:44 -0400 | [diff] [blame] | 3512 | shell_surface_set_maximized, |
| 3513 | shell_surface_set_title, |
| 3514 | shell_surface_set_class |
Pekka Paalanen | 9d1613e | 2011-11-25 12:09:16 +0200 | [diff] [blame] | 3515 | }; |
| 3516 | |
| 3517 | static void |
Tiago Vignatti | bc052c9 | 2012-04-19 16:18:18 +0300 | [diff] [blame] | 3518 | destroy_shell_surface(struct shell_surface *shsurf) |
Pekka Paalanen | 9d1613e | 2011-11-25 12:09:16 +0200 | [diff] [blame] | 3519 | { |
Kristian Høgsberg | 9046d24 | 2014-01-10 00:25:30 -0800 | [diff] [blame] | 3520 | struct shell_surface *child, *next; |
| 3521 | |
Jason Ekstrand | 651f00e | 2013-06-14 10:07:54 -0500 | [diff] [blame] | 3522 | wl_signal_emit(&shsurf->destroy_signal, shsurf); |
| 3523 | |
Giulio Camuffo | 5085a75 | 2013-03-25 21:42:45 +0100 | [diff] [blame] | 3524 | if (!wl_list_empty(&shsurf->popup.grab_link)) { |
| 3525 | remove_popup_grab(shsurf); |
| 3526 | } |
Kristian Høgsberg | b3cca0a | 2012-01-04 22:19:14 -0500 | [diff] [blame] | 3527 | |
Alex Wu | bd3354b | 2012-04-17 17:20:49 +0800 | [diff] [blame] | 3528 | if (shsurf->fullscreen.type == WL_SHELL_SURFACE_FULLSCREEN_METHOD_DRIVER && |
Alexander Larsson | f82b6ca | 2013-05-28 16:23:39 +0200 | [diff] [blame] | 3529 | shell_surface_is_top_fullscreen(shsurf)) |
| 3530 | restore_output_mode (shsurf->fullscreen_output); |
Pekka Paalanen | 9d1613e | 2011-11-25 12:09:16 +0200 | [diff] [blame] | 3531 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 3532 | if (shsurf->fullscreen.black_view) |
| 3533 | weston_surface_destroy(shsurf->fullscreen.black_view->surface); |
Alex Wu | aa08e2d | 2012-03-05 11:01:40 +0800 | [diff] [blame] | 3534 | |
Alex Wu | bd3354b | 2012-04-17 17:20:49 +0800 | [diff] [blame] | 3535 | /* As destroy_resource() use wl_list_for_each_safe(), |
| 3536 | * we can always remove the listener. |
| 3537 | */ |
| 3538 | wl_list_remove(&shsurf->surface_destroy_listener.link); |
| 3539 | shsurf->surface->configure = NULL; |
Pekka Paalanen | 8274d90 | 2014-08-06 19:36:51 +0300 | [diff] [blame] | 3540 | weston_surface_set_label_func(shsurf->surface, NULL); |
Scott Moreau | 976a050 | 2013-03-07 10:15:17 -0700 | [diff] [blame] | 3541 | free(shsurf->title); |
Alex Wu | bd3354b | 2012-04-17 17:20:49 +0800 | [diff] [blame] | 3542 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 3543 | weston_view_destroy(shsurf->view); |
| 3544 | |
Philip Withnall | 648a4dd | 2013-11-25 18:01:44 +0000 | [diff] [blame] | 3545 | wl_list_remove(&shsurf->children_link); |
Emilio Pozuelo Monfort | adaa20c | 2014-01-28 13:54:16 +0100 | [diff] [blame] | 3546 | wl_list_for_each_safe(child, next, &shsurf->children_list, children_link) |
| 3547 | shell_surface_set_parent(child, NULL); |
Philip Withnall | 648a4dd | 2013-11-25 18:01:44 +0000 | [diff] [blame] | 3548 | |
Pekka Paalanen | 9d1613e | 2011-11-25 12:09:16 +0200 | [diff] [blame] | 3549 | wl_list_remove(&shsurf->link); |
| 3550 | free(shsurf); |
| 3551 | } |
| 3552 | |
| 3553 | static void |
Tiago Vignatti | bc052c9 | 2012-04-19 16:18:18 +0300 | [diff] [blame] | 3554 | shell_destroy_shell_surface(struct wl_resource *resource) |
| 3555 | { |
Jason Ekstrand | 651f00e | 2013-06-14 10:07:54 -0500 | [diff] [blame] | 3556 | struct shell_surface *shsurf = wl_resource_get_user_data(resource); |
Tiago Vignatti | bc052c9 | 2012-04-19 16:18:18 +0300 | [diff] [blame] | 3557 | |
Bryan Cain | a46b946 | 2014-04-04 17:41:24 -0500 | [diff] [blame] | 3558 | if (!wl_list_empty(&shsurf->popup.grab_link)) |
| 3559 | remove_popup_grab(shsurf); |
Jonas Ådahl | 49d77d2 | 2015-03-18 16:20:51 +0800 | [diff] [blame] | 3560 | wl_list_remove(wl_resource_get_link(shsurf->resource)); |
Kristian Høgsberg | 160fe75 | 2014-03-11 10:19:10 -0700 | [diff] [blame] | 3561 | shsurf->resource = NULL; |
Tiago Vignatti | bc052c9 | 2012-04-19 16:18:18 +0300 | [diff] [blame] | 3562 | } |
| 3563 | |
| 3564 | static void |
Kristian Høgsberg | 27e3052 | 2012-04-11 23:18:23 -0400 | [diff] [blame] | 3565 | shell_handle_surface_destroy(struct wl_listener *listener, void *data) |
Pekka Paalanen | 9d1613e | 2011-11-25 12:09:16 +0200 | [diff] [blame] | 3566 | { |
| 3567 | struct shell_surface *shsurf = container_of(listener, |
| 3568 | struct shell_surface, |
| 3569 | surface_destroy_listener); |
| 3570 | |
Jason Ekstrand | 651f00e | 2013-06-14 10:07:54 -0500 | [diff] [blame] | 3571 | if (shsurf->resource) |
| 3572 | wl_resource_destroy(shsurf->resource); |
Ander Conselvan de Oliveira | 15f9a26 | 2014-04-29 17:54:02 +0300 | [diff] [blame] | 3573 | |
| 3574 | destroy_shell_surface(shsurf); |
Pekka Paalanen | 9d1613e | 2011-11-25 12:09:16 +0200 | [diff] [blame] | 3575 | } |
| 3576 | |
Kristian Høgsberg | d813445 | 2012-06-21 12:49:02 -0400 | [diff] [blame] | 3577 | static void |
Derek Foreman | 039e9be | 2015-04-14 17:09:06 -0500 | [diff] [blame] | 3578 | fade_out_done_idle_cb(void *data) |
Kristian Høgsberg | 160fe75 | 2014-03-11 10:19:10 -0700 | [diff] [blame] | 3579 | { |
| 3580 | struct shell_surface *shsurf = data; |
| 3581 | |
| 3582 | weston_surface_destroy(shsurf->surface); |
| 3583 | } |
| 3584 | |
| 3585 | static void |
Derek Foreman | 039e9be | 2015-04-14 17:09:06 -0500 | [diff] [blame] | 3586 | fade_out_done(struct weston_view_animation *animation, void *data) |
| 3587 | { |
| 3588 | struct shell_surface *shsurf = data; |
| 3589 | struct wl_event_loop *loop; |
| 3590 | |
| 3591 | loop = wl_display_get_event_loop( |
| 3592 | shsurf->surface->compositor->wl_display); |
| 3593 | |
| 3594 | if (!shsurf->destroying) { |
| 3595 | wl_event_loop_add_idle(loop, fade_out_done_idle_cb, shsurf); |
| 3596 | shsurf->destroying = true; |
| 3597 | } |
| 3598 | } |
| 3599 | |
| 3600 | static void |
Kristian Høgsberg | 160fe75 | 2014-03-11 10:19:10 -0700 | [diff] [blame] | 3601 | handle_resource_destroy(struct wl_listener *listener, void *data) |
| 3602 | { |
| 3603 | struct shell_surface *shsurf = |
| 3604 | container_of(listener, struct shell_surface, |
| 3605 | resource_destroy_listener); |
| 3606 | |
Ander Conselvan de Oliveira | 15f9a26 | 2014-04-29 17:54:02 +0300 | [diff] [blame] | 3607 | if (!weston_surface_is_mapped(shsurf->surface)) |
| 3608 | return; |
| 3609 | |
Kristian Høgsberg | 160fe75 | 2014-03-11 10:19:10 -0700 | [diff] [blame] | 3610 | shsurf->surface->ref_count++; |
| 3611 | |
| 3612 | pixman_region32_fini(&shsurf->surface->pending.input); |
| 3613 | pixman_region32_init(&shsurf->surface->pending.input); |
| 3614 | pixman_region32_fini(&shsurf->surface->input); |
| 3615 | pixman_region32_init(&shsurf->surface->input); |
Jonny Lamb | f322f8e | 2014-08-12 15:13:30 +0200 | [diff] [blame] | 3616 | if (shsurf->shell->win_close_animation_type == ANIMATION_FADE) { |
| 3617 | weston_fade_run(shsurf->view, 1.0, 0.0, 300.0, |
| 3618 | fade_out_done, shsurf); |
| 3619 | } else { |
| 3620 | weston_surface_destroy(shsurf->surface); |
| 3621 | } |
Kristian Høgsberg | 160fe75 | 2014-03-11 10:19:10 -0700 | [diff] [blame] | 3622 | } |
| 3623 | |
| 3624 | static void |
Jason Ekstrand | 918f2dd | 2013-12-02 21:01:53 -0600 | [diff] [blame] | 3625 | shell_surface_configure(struct weston_surface *, int32_t, int32_t); |
Kristian Høgsberg | d813445 | 2012-06-21 12:49:02 -0400 | [diff] [blame] | 3626 | |
Kristian Høgsberg | 1ef2313 | 2013-12-04 00:20:01 -0800 | [diff] [blame] | 3627 | struct shell_surface * |
Kristian Høgsberg | 8334bc1 | 2012-01-03 10:29:47 -0500 | [diff] [blame] | 3628 | get_shell_surface(struct weston_surface *surface) |
Pekka Paalanen | ec2b32f | 2011-11-28 15:12:34 +0200 | [diff] [blame] | 3629 | { |
Kristian Høgsberg | d813445 | 2012-06-21 12:49:02 -0400 | [diff] [blame] | 3630 | if (surface->configure == shell_surface_configure) |
Giulio Camuffo | 7fe01b1 | 2013-03-28 18:02:42 +0100 | [diff] [blame] | 3631 | return surface->configure_private; |
Kristian Høgsberg | d813445 | 2012-06-21 12:49:02 -0400 | [diff] [blame] | 3632 | else |
| 3633 | return NULL; |
Pekka Paalanen | ec2b32f | 2011-11-28 15:12:34 +0200 | [diff] [blame] | 3634 | } |
| 3635 | |
Rafael Antognolli | e2a3455 | 2013-12-03 15:35:45 -0200 | [diff] [blame] | 3636 | static struct shell_surface * |
Jason Ekstrand | 9e9512f | 2014-04-16 21:12:10 -0500 | [diff] [blame] | 3637 | create_common_surface(struct shell_client *owner, void *shell, |
| 3638 | struct weston_surface *surface, |
Rafael Antognolli | e2a3455 | 2013-12-03 15:35:45 -0200 | [diff] [blame] | 3639 | const struct weston_shell_client *client) |
Pekka Paalanen | 9d1613e | 2011-11-25 12:09:16 +0200 | [diff] [blame] | 3640 | { |
Pekka Paalanen | 9d1613e | 2011-11-25 12:09:16 +0200 | [diff] [blame] | 3641 | struct shell_surface *shsurf; |
| 3642 | |
Pekka Paalanen | 50b6747 | 2014-10-01 15:02:41 +0300 | [diff] [blame] | 3643 | assert(surface->configure == NULL); |
Ander Conselvan de Oliveira | 093bfa3 | 2012-03-27 17:36:41 +0300 | [diff] [blame] | 3644 | |
Pekka Paalanen | 9d1613e | 2011-11-25 12:09:16 +0200 | [diff] [blame] | 3645 | shsurf = calloc(1, sizeof *shsurf); |
| 3646 | if (!shsurf) { |
Martin Minarik | 6d11836 | 2012-06-07 18:01:59 +0200 | [diff] [blame] | 3647 | weston_log("no memory to allocate shell surface\n"); |
Kristian Høgsberg | 45ba869 | 2012-05-21 14:27:33 -0400 | [diff] [blame] | 3648 | return NULL; |
Pekka Paalanen | 9d1613e | 2011-11-25 12:09:16 +0200 | [diff] [blame] | 3649 | } |
| 3650 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 3651 | shsurf->view = weston_view_create(surface); |
| 3652 | if (!shsurf->view) { |
| 3653 | weston_log("no memory to allocate shell surface\n"); |
| 3654 | free(shsurf); |
| 3655 | return NULL; |
| 3656 | } |
| 3657 | |
Ander Conselvan de Oliveira | 093bfa3 | 2012-03-27 17:36:41 +0300 | [diff] [blame] | 3658 | surface->configure = shell_surface_configure; |
Giulio Camuffo | 7fe01b1 | 2013-03-28 18:02:42 +0100 | [diff] [blame] | 3659 | surface->configure_private = shsurf; |
Pekka Paalanen | 8274d90 | 2014-08-06 19:36:51 +0300 | [diff] [blame] | 3660 | weston_surface_set_label_func(surface, shell_surface_get_label); |
Ander Conselvan de Oliveira | 093bfa3 | 2012-03-27 17:36:41 +0300 | [diff] [blame] | 3661 | |
Kristian Høgsberg | 160fe75 | 2014-03-11 10:19:10 -0700 | [diff] [blame] | 3662 | shsurf->resource_destroy_listener.notify = handle_resource_destroy; |
| 3663 | wl_resource_add_destroy_listener(surface->resource, |
| 3664 | &shsurf->resource_destroy_listener); |
Jason Ekstrand | 9e9512f | 2014-04-16 21:12:10 -0500 | [diff] [blame] | 3665 | shsurf->owner = owner; |
Kristian Høgsberg | 160fe75 | 2014-03-11 10:19:10 -0700 | [diff] [blame] | 3666 | |
Tiago Vignatti | bc052c9 | 2012-04-19 16:18:18 +0300 | [diff] [blame] | 3667 | shsurf->shell = (struct desktop_shell *) shell; |
Scott Moreau | ff1db4a | 2012-04-17 19:06:18 -0600 | [diff] [blame] | 3668 | shsurf->unresponsive = 0; |
Alex Wu | 4539b08 | 2012-03-01 12:57:46 +0800 | [diff] [blame] | 3669 | shsurf->saved_position_valid = false; |
Rafael Antognolli | 3c4e3f7 | 2013-12-03 15:35:46 -0200 | [diff] [blame] | 3670 | shsurf->saved_size_valid = false; |
Alex Wu | 7bcb8bd | 2012-04-27 09:07:24 +0800 | [diff] [blame] | 3671 | shsurf->saved_rotation_valid = false; |
Pekka Paalanen | 9d1613e | 2011-11-25 12:09:16 +0200 | [diff] [blame] | 3672 | shsurf->surface = surface; |
Alex Wu | 4539b08 | 2012-03-01 12:57:46 +0800 | [diff] [blame] | 3673 | shsurf->fullscreen.type = WL_SHELL_SURFACE_FULLSCREEN_METHOD_DEFAULT; |
| 3674 | shsurf->fullscreen.framerate = 0; |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 3675 | shsurf->fullscreen.black_view = NULL; |
Alex Wu | 4539b08 | 2012-03-01 12:57:46 +0800 | [diff] [blame] | 3676 | wl_list_init(&shsurf->fullscreen.transform.link); |
| 3677 | |
Jasper St. Pierre | 9aa8ce6 | 2014-04-11 16:18:54 -0700 | [diff] [blame] | 3678 | shsurf->output = get_default_output(shsurf->shell->compositor); |
| 3679 | |
Jason Ekstrand | 651f00e | 2013-06-14 10:07:54 -0500 | [diff] [blame] | 3680 | wl_signal_init(&shsurf->destroy_signal); |
Kristian Høgsberg | 27e3052 | 2012-04-11 23:18:23 -0400 | [diff] [blame] | 3681 | shsurf->surface_destroy_listener.notify = shell_handle_surface_destroy; |
Jason Ekstrand | 26ed73c | 2013-06-06 22:34:41 -0500 | [diff] [blame] | 3682 | wl_signal_add(&surface->destroy_signal, |
Kristian Høgsberg | 27e3052 | 2012-04-11 23:18:23 -0400 | [diff] [blame] | 3683 | &shsurf->surface_destroy_listener); |
Pekka Paalanen | 9d1613e | 2011-11-25 12:09:16 +0200 | [diff] [blame] | 3684 | |
| 3685 | /* init link so its safe to always remove it in destroy_shell_surface */ |
| 3686 | wl_list_init(&shsurf->link); |
Giulio Camuffo | 5085a75 | 2013-03-25 21:42:45 +0100 | [diff] [blame] | 3687 | wl_list_init(&shsurf->popup.grab_link); |
Pekka Paalanen | 9d1613e | 2011-11-25 12:09:16 +0200 | [diff] [blame] | 3688 | |
Pekka Paalanen | 460099f | 2012-01-20 16:48:25 +0200 | [diff] [blame] | 3689 | /* empty when not in use */ |
| 3690 | wl_list_init(&shsurf->rotation.transform.link); |
Kristian Høgsberg | 765e27b | 2012-01-27 13:36:13 -0500 | [diff] [blame] | 3691 | weston_matrix_init(&shsurf->rotation.rotation); |
Pekka Paalanen | 460099f | 2012-01-20 16:48:25 +0200 | [diff] [blame] | 3692 | |
Jonas Ådahl | 62fcd04 | 2012-06-13 00:01:23 +0200 | [diff] [blame] | 3693 | wl_list_init(&shsurf->workspace_transform.link); |
| 3694 | |
Philip Withnall | 648a4dd | 2013-11-25 18:01:44 +0000 | [diff] [blame] | 3695 | wl_list_init(&shsurf->children_link); |
| 3696 | wl_list_init(&shsurf->children_list); |
| 3697 | shsurf->parent = NULL; |
| 3698 | |
Pekka Paalanen | b502654 | 2014-11-12 15:09:24 +0200 | [diff] [blame] | 3699 | set_type(shsurf, SHELL_SURFACE_NONE); |
Pekka Paalanen | 9d1613e | 2011-11-25 12:09:16 +0200 | [diff] [blame] | 3700 | |
Kristian Høgsberg | a61ca06 | 2012-05-22 16:05:52 -0400 | [diff] [blame] | 3701 | shsurf->client = client; |
| 3702 | |
Kristian Høgsberg | 45ba869 | 2012-05-21 14:27:33 -0400 | [diff] [blame] | 3703 | return shsurf; |
Tiago Vignatti | bc052c9 | 2012-04-19 16:18:18 +0300 | [diff] [blame] | 3704 | } |
| 3705 | |
Rafael Antognolli | e2a3455 | 2013-12-03 15:35:45 -0200 | [diff] [blame] | 3706 | static struct shell_surface * |
| 3707 | create_shell_surface(void *shell, struct weston_surface *surface, |
| 3708 | const struct weston_shell_client *client) |
| 3709 | { |
Jason Ekstrand | 9e9512f | 2014-04-16 21:12:10 -0500 | [diff] [blame] | 3710 | return create_common_surface(NULL, shell, surface, client); |
Rafael Antognolli | e2a3455 | 2013-12-03 15:35:45 -0200 | [diff] [blame] | 3711 | } |
| 3712 | |
Tiago Vignatti | bc052c9 | 2012-04-19 16:18:18 +0300 | [diff] [blame] | 3713 | static void |
| 3714 | shell_get_shell_surface(struct wl_client *client, |
| 3715 | struct wl_resource *resource, |
| 3716 | uint32_t id, |
| 3717 | struct wl_resource *surface_resource) |
| 3718 | { |
Jason Ekstrand | 0f2ef7e | 2013-06-14 10:07:53 -0500 | [diff] [blame] | 3719 | struct weston_surface *surface = |
| 3720 | wl_resource_get_user_data(surface_resource); |
Jason Ekstrand | 9e9512f | 2014-04-16 21:12:10 -0500 | [diff] [blame] | 3721 | struct shell_client *sc = wl_resource_get_user_data(resource); |
| 3722 | struct desktop_shell *shell = sc->shell; |
Tiago Vignatti | bc052c9 | 2012-04-19 16:18:18 +0300 | [diff] [blame] | 3723 | struct shell_surface *shsurf; |
| 3724 | |
Pekka Paalanen | 50b6747 | 2014-10-01 15:02:41 +0300 | [diff] [blame] | 3725 | if (weston_surface_set_role(surface, "wl_shell_surface", |
| 3726 | resource, WL_SHELL_ERROR_ROLE) < 0) |
Tiago Vignatti | bc052c9 | 2012-04-19 16:18:18 +0300 | [diff] [blame] | 3727 | return; |
Tiago Vignatti | bc052c9 | 2012-04-19 16:18:18 +0300 | [diff] [blame] | 3728 | |
Jason Ekstrand | 9e9512f | 2014-04-16 21:12:10 -0500 | [diff] [blame] | 3729 | shsurf = create_common_surface(sc, shell, surface, &shell_client); |
Kristian Høgsberg | 9540ea6 | 2012-05-21 14:28:57 -0400 | [diff] [blame] | 3730 | if (!shsurf) { |
Pekka Paalanen | 50b6747 | 2014-10-01 15:02:41 +0300 | [diff] [blame] | 3731 | wl_resource_post_no_memory(surface_resource); |
Kristian Høgsberg | 9540ea6 | 2012-05-21 14:28:57 -0400 | [diff] [blame] | 3732 | return; |
| 3733 | } |
Tiago Vignatti | bc052c9 | 2012-04-19 16:18:18 +0300 | [diff] [blame] | 3734 | |
Jason Ekstrand | a85118c | 2013-06-27 20:17:02 -0500 | [diff] [blame] | 3735 | shsurf->resource = |
| 3736 | wl_resource_create(client, |
| 3737 | &wl_shell_surface_interface, 1, id); |
| 3738 | wl_resource_set_implementation(shsurf->resource, |
| 3739 | &shell_surface_implementation, |
| 3740 | shsurf, shell_destroy_shell_surface); |
Jonas Ådahl | 49d77d2 | 2015-03-18 16:20:51 +0800 | [diff] [blame] | 3741 | wl_list_init(wl_resource_get_link(shsurf->resource)); |
Pekka Paalanen | 9d1613e | 2011-11-25 12:09:16 +0200 | [diff] [blame] | 3742 | } |
| 3743 | |
Rafael Antognolli | e2a3455 | 2013-12-03 15:35:45 -0200 | [diff] [blame] | 3744 | static bool |
| 3745 | shell_surface_is_wl_shell_surface(struct shell_surface *shsurf) |
| 3746 | { |
Kristian Høgsberg | 0b7d995 | 2014-02-03 15:50:38 -0800 | [diff] [blame] | 3747 | /* A shell surface without a resource is created from xwayland |
| 3748 | * and is considered a wl_shell surface for now. */ |
| 3749 | |
| 3750 | return shsurf->resource == NULL || |
| 3751 | wl_resource_instance_of(shsurf->resource, |
| 3752 | &wl_shell_surface_interface, |
| 3753 | &shell_surface_implementation); |
Rafael Antognolli | e2a3455 | 2013-12-03 15:35:45 -0200 | [diff] [blame] | 3754 | } |
| 3755 | |
Pekka Paalanen | 9d1613e | 2011-11-25 12:09:16 +0200 | [diff] [blame] | 3756 | static const struct wl_shell_interface shell_implementation = { |
Pekka Paalanen | 4622967 | 2011-11-29 15:49:31 +0200 | [diff] [blame] | 3757 | shell_get_shell_surface |
Kristian Høgsberg | 4cca349 | 2011-01-18 07:53:49 -0500 | [diff] [blame] | 3758 | }; |
| 3759 | |
Rafael Antognolli | e2a3455 | 2013-12-03 15:35:45 -0200 | [diff] [blame] | 3760 | /**************************** |
| 3761 | * xdg-shell implementation */ |
| 3762 | |
| 3763 | static void |
| 3764 | xdg_surface_destroy(struct wl_client *client, |
| 3765 | struct wl_resource *resource) |
| 3766 | { |
| 3767 | wl_resource_destroy(resource); |
| 3768 | } |
| 3769 | |
| 3770 | static void |
Jasper St. Pierre | c815d62 | 2014-04-10 18:37:54 -0700 | [diff] [blame] | 3771 | xdg_surface_set_parent(struct wl_client *client, |
| 3772 | struct wl_resource *resource, |
| 3773 | struct wl_resource *parent_resource) |
Jasper St. Pierre | 63a9c33 | 2014-02-01 18:35:15 -0500 | [diff] [blame] | 3774 | { |
| 3775 | struct shell_surface *shsurf = wl_resource_get_user_data(resource); |
Jasper St. Pierre | 66bc949 | 2015-02-13 14:01:55 +0800 | [diff] [blame] | 3776 | struct shell_surface *parent; |
Jasper St. Pierre | 63a9c33 | 2014-02-01 18:35:15 -0500 | [diff] [blame] | 3777 | |
Jasper St. Pierre | 66bc949 | 2015-02-13 14:01:55 +0800 | [diff] [blame] | 3778 | if (parent_resource) { |
Jasper St. Pierre | 63a9c33 | 2014-02-01 18:35:15 -0500 | [diff] [blame] | 3779 | parent = wl_resource_get_user_data(parent_resource); |
Jasper St. Pierre | 66bc949 | 2015-02-13 14:01:55 +0800 | [diff] [blame] | 3780 | shell_surface_set_parent(shsurf, parent->surface); |
| 3781 | } else { |
| 3782 | shell_surface_set_parent(shsurf, NULL); |
| 3783 | } |
Jasper St. Pierre | 63a9c33 | 2014-02-01 18:35:15 -0500 | [diff] [blame] | 3784 | } |
| 3785 | |
| 3786 | static void |
Rafael Antognolli | e2a3455 | 2013-12-03 15:35:45 -0200 | [diff] [blame] | 3787 | xdg_surface_set_app_id(struct wl_client *client, |
| 3788 | struct wl_resource *resource, |
| 3789 | const char *app_id) |
| 3790 | { |
| 3791 | struct shell_surface *shsurf = wl_resource_get_user_data(resource); |
| 3792 | |
| 3793 | free(shsurf->class); |
| 3794 | shsurf->class = strdup(app_id); |
Pekka Paalanen | b502654 | 2014-11-12 15:09:24 +0200 | [diff] [blame] | 3795 | shsurf->surface->timeline.force_refresh = 1; |
Rafael Antognolli | e2a3455 | 2013-12-03 15:35:45 -0200 | [diff] [blame] | 3796 | } |
| 3797 | |
| 3798 | static void |
Jasper St. Pierre | 81ff075 | 2014-03-13 11:04:53 -0400 | [diff] [blame] | 3799 | xdg_surface_show_window_menu(struct wl_client *client, |
| 3800 | struct wl_resource *surface_resource, |
| 3801 | struct wl_resource *seat_resource, |
| 3802 | uint32_t serial, |
| 3803 | int32_t x, |
| 3804 | int32_t y) |
| 3805 | { |
| 3806 | /* TODO */ |
| 3807 | } |
| 3808 | |
| 3809 | static void |
Rafael Antognolli | e2a3455 | 2013-12-03 15:35:45 -0200 | [diff] [blame] | 3810 | xdg_surface_set_title(struct wl_client *client, |
| 3811 | struct wl_resource *resource, const char *title) |
| 3812 | { |
| 3813 | struct shell_surface *shsurf = wl_resource_get_user_data(resource); |
| 3814 | |
| 3815 | set_title(shsurf, title); |
| 3816 | } |
| 3817 | |
| 3818 | static void |
| 3819 | xdg_surface_move(struct wl_client *client, struct wl_resource *resource, |
| 3820 | struct wl_resource *seat_resource, uint32_t serial) |
| 3821 | { |
| 3822 | common_surface_move(resource, seat_resource, serial); |
| 3823 | } |
| 3824 | |
| 3825 | static void |
| 3826 | xdg_surface_resize(struct wl_client *client, struct wl_resource *resource, |
| 3827 | struct wl_resource *seat_resource, uint32_t serial, |
| 3828 | uint32_t edges) |
| 3829 | { |
| 3830 | common_surface_resize(resource, seat_resource, serial, edges); |
| 3831 | } |
| 3832 | |
| 3833 | static void |
Jasper St. Pierre | ab2c108 | 2014-04-10 10:41:46 -0700 | [diff] [blame] | 3834 | xdg_surface_ack_configure(struct wl_client *client, |
| 3835 | struct wl_resource *resource, |
| 3836 | uint32_t serial) |
Rafael Antognolli | e2a3455 | 2013-12-03 15:35:45 -0200 | [diff] [blame] | 3837 | { |
| 3838 | struct shell_surface *shsurf = wl_resource_get_user_data(resource); |
| 3839 | |
Jasper St. Pierre | 8c6aa45 | 2014-02-08 18:29:49 -0500 | [diff] [blame] | 3840 | if (shsurf->state_requested) { |
| 3841 | shsurf->next_state = shsurf->requested_state; |
| 3842 | shsurf->state_changed = true; |
| 3843 | shsurf->state_requested = false; |
Rafael Antognolli | 3c4e3f7 | 2013-12-03 15:35:46 -0200 | [diff] [blame] | 3844 | } |
Rafael Antognolli | e2a3455 | 2013-12-03 15:35:45 -0200 | [diff] [blame] | 3845 | } |
| 3846 | |
Manuel Bachmann | 50c87db | 2014-02-26 15:52:13 +0100 | [diff] [blame] | 3847 | static void |
Jasper St. Pierre | ccf48fb | 2014-05-02 10:21:38 -0400 | [diff] [blame] | 3848 | xdg_surface_set_window_geometry(struct wl_client *client, |
| 3849 | struct wl_resource *resource, |
| 3850 | int32_t x, |
| 3851 | int32_t y, |
| 3852 | int32_t width, |
| 3853 | int32_t height) |
| 3854 | { |
| 3855 | struct shell_surface *shsurf = wl_resource_get_user_data(resource); |
| 3856 | |
| 3857 | set_window_geometry(shsurf, x, y, width, height); |
| 3858 | } |
| 3859 | |
| 3860 | static void |
Jasper St. Pierre | ab2c108 | 2014-04-10 10:41:46 -0700 | [diff] [blame] | 3861 | xdg_surface_set_maximized(struct wl_client *client, |
| 3862 | struct wl_resource *resource) |
| 3863 | { |
| 3864 | struct shell_surface *shsurf = wl_resource_get_user_data(resource); |
Marek Chalupa | bfbb64b | 2014-09-08 12:34:20 +0200 | [diff] [blame] | 3865 | struct weston_output *output; |
Jasper St. Pierre | ab2c108 | 2014-04-10 10:41:46 -0700 | [diff] [blame] | 3866 | |
| 3867 | shsurf->state_requested = true; |
| 3868 | shsurf->requested_state.maximized = true; |
Marek Chalupa | bfbb64b | 2014-09-08 12:34:20 +0200 | [diff] [blame] | 3869 | |
| 3870 | if (!weston_surface_is_mapped(shsurf->surface)) |
| 3871 | output = get_focused_output(shsurf->surface->compositor); |
| 3872 | else |
| 3873 | output = shsurf->surface->output; |
| 3874 | |
| 3875 | shell_surface_set_output(shsurf, output); |
Jasper St. Pierre | 9aa8ce6 | 2014-04-11 16:18:54 -0700 | [diff] [blame] | 3876 | send_configure_for_surface(shsurf); |
Jasper St. Pierre | ab2c108 | 2014-04-10 10:41:46 -0700 | [diff] [blame] | 3877 | } |
| 3878 | |
| 3879 | static void |
| 3880 | xdg_surface_unset_maximized(struct wl_client *client, |
| 3881 | struct wl_resource *resource) |
| 3882 | { |
| 3883 | struct shell_surface *shsurf = wl_resource_get_user_data(resource); |
| 3884 | |
| 3885 | shsurf->state_requested = true; |
| 3886 | shsurf->requested_state.maximized = false; |
Jasper St. Pierre | 6458ec3 | 2014-04-11 16:00:31 -0700 | [diff] [blame] | 3887 | send_configure_for_surface(shsurf); |
Jasper St. Pierre | ab2c108 | 2014-04-10 10:41:46 -0700 | [diff] [blame] | 3888 | } |
| 3889 | |
| 3890 | static void |
| 3891 | xdg_surface_set_fullscreen(struct wl_client *client, |
| 3892 | struct wl_resource *resource, |
| 3893 | struct wl_resource *output_resource) |
| 3894 | { |
| 3895 | struct shell_surface *shsurf = wl_resource_get_user_data(resource); |
| 3896 | struct weston_output *output; |
| 3897 | |
| 3898 | shsurf->state_requested = true; |
| 3899 | shsurf->requested_state.fullscreen = true; |
| 3900 | |
| 3901 | if (output_resource) |
| 3902 | output = wl_resource_get_user_data(output_resource); |
| 3903 | else |
| 3904 | output = NULL; |
| 3905 | |
Marek Chalupa | 052917a | 2014-09-02 11:35:12 +0200 | [diff] [blame] | 3906 | /* handle clients launching in fullscreen */ |
| 3907 | if (output == NULL && !weston_surface_is_mapped(shsurf->surface)) { |
| 3908 | /* Set the output to the one that has focus currently. */ |
| 3909 | assert(shsurf->surface); |
| 3910 | output = get_focused_output(shsurf->surface->compositor); |
| 3911 | } |
| 3912 | |
Jasper St. Pierre | 9aa8ce6 | 2014-04-11 16:18:54 -0700 | [diff] [blame] | 3913 | shell_surface_set_output(shsurf, output); |
| 3914 | shsurf->fullscreen_output = shsurf->output; |
Jasper St. Pierre | ab2c108 | 2014-04-10 10:41:46 -0700 | [diff] [blame] | 3915 | |
Jasper St. Pierre | 9aa8ce6 | 2014-04-11 16:18:54 -0700 | [diff] [blame] | 3916 | send_configure_for_surface(shsurf); |
Jasper St. Pierre | ab2c108 | 2014-04-10 10:41:46 -0700 | [diff] [blame] | 3917 | } |
| 3918 | |
| 3919 | static void |
| 3920 | xdg_surface_unset_fullscreen(struct wl_client *client, |
| 3921 | struct wl_resource *resource) |
| 3922 | { |
| 3923 | struct shell_surface *shsurf = wl_resource_get_user_data(resource); |
| 3924 | |
| 3925 | shsurf->state_requested = true; |
| 3926 | shsurf->requested_state.fullscreen = false; |
Jasper St. Pierre | 6458ec3 | 2014-04-11 16:00:31 -0700 | [diff] [blame] | 3927 | send_configure_for_surface(shsurf); |
Jasper St. Pierre | ab2c108 | 2014-04-10 10:41:46 -0700 | [diff] [blame] | 3928 | } |
| 3929 | |
| 3930 | static void |
Manuel Bachmann | 50c87db | 2014-02-26 15:52:13 +0100 | [diff] [blame] | 3931 | xdg_surface_set_minimized(struct wl_client *client, |
| 3932 | struct wl_resource *resource) |
| 3933 | { |
| 3934 | struct shell_surface *shsurf = wl_resource_get_user_data(resource); |
| 3935 | |
| 3936 | if (shsurf->type != SHELL_SURFACE_TOPLEVEL) |
| 3937 | return; |
| 3938 | |
| 3939 | /* apply compositor's own minimization logic (hide) */ |
Manuel Bachmann | dc1c3e4 | 2015-02-16 11:52:13 +0100 | [diff] [blame] | 3940 | set_minimized(shsurf->surface); |
Manuel Bachmann | 50c87db | 2014-02-26 15:52:13 +0100 | [diff] [blame] | 3941 | } |
| 3942 | |
Rafael Antognolli | e2a3455 | 2013-12-03 15:35:45 -0200 | [diff] [blame] | 3943 | static const struct xdg_surface_interface xdg_surface_implementation = { |
| 3944 | xdg_surface_destroy, |
Jasper St. Pierre | c815d62 | 2014-04-10 18:37:54 -0700 | [diff] [blame] | 3945 | xdg_surface_set_parent, |
Rafael Antognolli | e2a3455 | 2013-12-03 15:35:45 -0200 | [diff] [blame] | 3946 | xdg_surface_set_title, |
| 3947 | xdg_surface_set_app_id, |
Jasper St. Pierre | 81ff075 | 2014-03-13 11:04:53 -0400 | [diff] [blame] | 3948 | xdg_surface_show_window_menu, |
Rafael Antognolli | e2a3455 | 2013-12-03 15:35:45 -0200 | [diff] [blame] | 3949 | xdg_surface_move, |
| 3950 | xdg_surface_resize, |
Jasper St. Pierre | ab2c108 | 2014-04-10 10:41:46 -0700 | [diff] [blame] | 3951 | xdg_surface_ack_configure, |
Jasper St. Pierre | ccf48fb | 2014-05-02 10:21:38 -0400 | [diff] [blame] | 3952 | xdg_surface_set_window_geometry, |
Jasper St. Pierre | ab2c108 | 2014-04-10 10:41:46 -0700 | [diff] [blame] | 3953 | xdg_surface_set_maximized, |
| 3954 | xdg_surface_unset_maximized, |
| 3955 | xdg_surface_set_fullscreen, |
| 3956 | xdg_surface_unset_fullscreen, |
| 3957 | xdg_surface_set_minimized, |
Rafael Antognolli | e2a3455 | 2013-12-03 15:35:45 -0200 | [diff] [blame] | 3958 | }; |
| 3959 | |
| 3960 | static void |
| 3961 | xdg_send_configure(struct weston_surface *surface, |
Jasper St. Pierre | ac985be | 2014-04-28 11:19:28 -0400 | [diff] [blame] | 3962 | int32_t width, int32_t height) |
Rafael Antognolli | e2a3455 | 2013-12-03 15:35:45 -0200 | [diff] [blame] | 3963 | { |
| 3964 | struct shell_surface *shsurf = get_shell_surface(surface); |
Jasper St. Pierre | ab2c108 | 2014-04-10 10:41:46 -0700 | [diff] [blame] | 3965 | uint32_t *s; |
| 3966 | struct wl_array states; |
| 3967 | uint32_t serial; |
Rafael Antognolli | e2a3455 | 2013-12-03 15:35:45 -0200 | [diff] [blame] | 3968 | |
U. Artie Eoff | cf5737a | 2014-01-17 10:08:25 -0800 | [diff] [blame] | 3969 | assert(shsurf); |
| 3970 | |
Jasper St. Pierre | ab2c108 | 2014-04-10 10:41:46 -0700 | [diff] [blame] | 3971 | if (!shsurf->resource) |
| 3972 | return; |
| 3973 | |
| 3974 | wl_array_init(&states); |
| 3975 | if (shsurf->requested_state.fullscreen) { |
| 3976 | s = wl_array_add(&states, sizeof *s); |
| 3977 | *s = XDG_SURFACE_STATE_FULLSCREEN; |
| 3978 | } else if (shsurf->requested_state.maximized) { |
| 3979 | s = wl_array_add(&states, sizeof *s); |
| 3980 | *s = XDG_SURFACE_STATE_MAXIMIZED; |
| 3981 | } |
Jasper St. Pierre | 5befdda | 2014-05-06 08:50:47 -0400 | [diff] [blame] | 3982 | if (shsurf->resize_edges != 0) { |
| 3983 | s = wl_array_add(&states, sizeof *s); |
| 3984 | *s = XDG_SURFACE_STATE_RESIZING; |
| 3985 | } |
Jasper St. Pierre | 973d787 | 2014-05-06 08:44:29 -0400 | [diff] [blame] | 3986 | if (shsurf->focus_count > 0) { |
| 3987 | s = wl_array_add(&states, sizeof *s); |
| 3988 | *s = XDG_SURFACE_STATE_ACTIVATED; |
| 3989 | } |
Jasper St. Pierre | ab2c108 | 2014-04-10 10:41:46 -0700 | [diff] [blame] | 3990 | |
| 3991 | serial = wl_display_next_serial(shsurf->surface->compositor->wl_display); |
| 3992 | xdg_surface_send_configure(shsurf->resource, width, height, &states, serial); |
| 3993 | |
| 3994 | wl_array_release(&states); |
Rafael Antognolli | e2a3455 | 2013-12-03 15:35:45 -0200 | [diff] [blame] | 3995 | } |
| 3996 | |
| 3997 | static const struct weston_shell_client xdg_client = { |
Giulio Camuffo | f05d18f | 2015-12-11 20:57:05 +0200 | [diff] [blame] | 3998 | xdg_send_configure, |
| 3999 | NULL |
Rafael Antognolli | e2a3455 | 2013-12-03 15:35:45 -0200 | [diff] [blame] | 4000 | }; |
| 4001 | |
| 4002 | static void |
Jasper St. Pierre | 084aa0b | 2015-02-13 14:02:00 +0800 | [diff] [blame] | 4003 | xdg_shell_destroy(struct wl_client *client, |
| 4004 | struct wl_resource *resource) |
| 4005 | { |
Jonas Ådahl | 49d77d2 | 2015-03-18 16:20:51 +0800 | [diff] [blame] | 4006 | struct shell_client *sc = wl_resource_get_user_data(resource); |
| 4007 | struct wl_resource *shsurf_resource; |
| 4008 | struct shell_surface *shsurf; |
| 4009 | |
| 4010 | wl_resource_for_each(shsurf_resource, &sc->surface_list) { |
| 4011 | shsurf = wl_resource_get_user_data(shsurf_resource); |
| 4012 | if (shsurf->owner_resource == resource) { |
| 4013 | wl_resource_post_error( |
| 4014 | resource, |
| 4015 | XDG_SHELL_ERROR_DEFUNCT_SURFACES, |
| 4016 | "not all child surface objects destroyed"); |
| 4017 | return; |
| 4018 | } |
| 4019 | } |
| 4020 | |
Jasper St. Pierre | 084aa0b | 2015-02-13 14:02:00 +0800 | [diff] [blame] | 4021 | wl_resource_destroy(resource); |
| 4022 | } |
| 4023 | |
| 4024 | static void |
Rafael Antognolli | e2a3455 | 2013-12-03 15:35:45 -0200 | [diff] [blame] | 4025 | xdg_use_unstable_version(struct wl_client *client, |
| 4026 | struct wl_resource *resource, |
| 4027 | int32_t version) |
| 4028 | { |
| 4029 | if (version > 1) { |
| 4030 | wl_resource_post_error(resource, |
| 4031 | 1, |
| 4032 | "xdg-shell:: version not implemented yet."); |
| 4033 | return; |
| 4034 | } |
| 4035 | } |
| 4036 | |
| 4037 | static struct shell_surface * |
Jason Ekstrand | 9e9512f | 2014-04-16 21:12:10 -0500 | [diff] [blame] | 4038 | create_xdg_surface(struct shell_client *owner, void *shell, |
| 4039 | struct weston_surface *surface, |
Rafael Antognolli | e2a3455 | 2013-12-03 15:35:45 -0200 | [diff] [blame] | 4040 | const struct weston_shell_client *client) |
| 4041 | { |
| 4042 | struct shell_surface *shsurf; |
Rafael Antognolli | e2a3455 | 2013-12-03 15:35:45 -0200 | [diff] [blame] | 4043 | |
Jason Ekstrand | 9e9512f | 2014-04-16 21:12:10 -0500 | [diff] [blame] | 4044 | shsurf = create_common_surface(owner, shell, surface, client); |
Pekka Paalanen | e972b27 | 2014-10-01 14:03:56 +0300 | [diff] [blame] | 4045 | if (!shsurf) |
| 4046 | return NULL; |
| 4047 | |
Pekka Paalanen | b502654 | 2014-11-12 15:09:24 +0200 | [diff] [blame] | 4048 | set_type(shsurf, SHELL_SURFACE_TOPLEVEL); |
Rafael Antognolli | e2a3455 | 2013-12-03 15:35:45 -0200 | [diff] [blame] | 4049 | |
| 4050 | return shsurf; |
| 4051 | } |
| 4052 | |
| 4053 | static void |
| 4054 | xdg_get_xdg_surface(struct wl_client *client, |
| 4055 | struct wl_resource *resource, |
| 4056 | uint32_t id, |
| 4057 | struct wl_resource *surface_resource) |
| 4058 | { |
| 4059 | struct weston_surface *surface = |
| 4060 | wl_resource_get_user_data(surface_resource); |
Kristian Høgsberg | 2bff94e | 2014-02-11 12:22:51 -0800 | [diff] [blame] | 4061 | struct shell_client *sc = wl_resource_get_user_data(resource); |
| 4062 | struct desktop_shell *shell = sc->shell; |
Rafael Antognolli | e2a3455 | 2013-12-03 15:35:45 -0200 | [diff] [blame] | 4063 | struct shell_surface *shsurf; |
| 4064 | |
Jonas Ådahl | bf48e21 | 2015-02-06 10:15:28 +0800 | [diff] [blame] | 4065 | shsurf = get_shell_surface(surface); |
| 4066 | if (shsurf && shell_surface_is_xdg_surface(shsurf)) { |
| 4067 | wl_resource_post_error(resource, XDG_SHELL_ERROR_ROLE, |
| 4068 | "This wl_surface is already an " |
| 4069 | "xdg_surface"); |
| 4070 | return; |
| 4071 | } |
| 4072 | |
Pekka Paalanen | 50b6747 | 2014-10-01 15:02:41 +0300 | [diff] [blame] | 4073 | if (weston_surface_set_role(surface, "xdg_surface", |
| 4074 | resource, XDG_SHELL_ERROR_ROLE) < 0) |
Rafael Antognolli | e2a3455 | 2013-12-03 15:35:45 -0200 | [diff] [blame] | 4075 | return; |
Rafael Antognolli | e2a3455 | 2013-12-03 15:35:45 -0200 | [diff] [blame] | 4076 | |
Jason Ekstrand | 9e9512f | 2014-04-16 21:12:10 -0500 | [diff] [blame] | 4077 | shsurf = create_xdg_surface(sc, shell, surface, &xdg_client); |
Rafael Antognolli | e2a3455 | 2013-12-03 15:35:45 -0200 | [diff] [blame] | 4078 | if (!shsurf) { |
Pekka Paalanen | 50b6747 | 2014-10-01 15:02:41 +0300 | [diff] [blame] | 4079 | wl_resource_post_no_memory(surface_resource); |
Rafael Antognolli | e2a3455 | 2013-12-03 15:35:45 -0200 | [diff] [blame] | 4080 | return; |
| 4081 | } |
| 4082 | |
| 4083 | shsurf->resource = |
| 4084 | wl_resource_create(client, |
| 4085 | &xdg_surface_interface, 1, id); |
| 4086 | wl_resource_set_implementation(shsurf->resource, |
| 4087 | &xdg_surface_implementation, |
| 4088 | shsurf, shell_destroy_shell_surface); |
Jonas Ådahl | 49d77d2 | 2015-03-18 16:20:51 +0800 | [diff] [blame] | 4089 | shsurf->owner_resource = resource; |
| 4090 | wl_list_insert(&sc->surface_list, |
| 4091 | wl_resource_get_link(shsurf->resource)); |
Rafael Antognolli | e2a3455 | 2013-12-03 15:35:45 -0200 | [diff] [blame] | 4092 | } |
| 4093 | |
| 4094 | static bool |
| 4095 | shell_surface_is_xdg_surface(struct shell_surface *shsurf) |
| 4096 | { |
Kristian Høgsberg | 0b7d995 | 2014-02-03 15:50:38 -0800 | [diff] [blame] | 4097 | return shsurf->resource && |
| 4098 | wl_resource_instance_of(shsurf->resource, |
| 4099 | &xdg_surface_interface, |
| 4100 | &xdg_surface_implementation); |
Rafael Antognolli | e2a3455 | 2013-12-03 15:35:45 -0200 | [diff] [blame] | 4101 | } |
| 4102 | |
| 4103 | /* xdg-popup implementation */ |
| 4104 | |
| 4105 | static void |
| 4106 | xdg_popup_destroy(struct wl_client *client, |
| 4107 | struct wl_resource *resource) |
| 4108 | { |
| 4109 | wl_resource_destroy(resource); |
| 4110 | } |
| 4111 | |
Rafael Antognolli | e2a3455 | 2013-12-03 15:35:45 -0200 | [diff] [blame] | 4112 | static const struct xdg_popup_interface xdg_popup_implementation = { |
| 4113 | xdg_popup_destroy, |
Rafael Antognolli | e2a3455 | 2013-12-03 15:35:45 -0200 | [diff] [blame] | 4114 | }; |
| 4115 | |
| 4116 | static void |
| 4117 | xdg_popup_send_configure(struct weston_surface *surface, |
Jasper St. Pierre | ac985be | 2014-04-28 11:19:28 -0400 | [diff] [blame] | 4118 | int32_t width, int32_t height) |
Rafael Antognolli | e2a3455 | 2013-12-03 15:35:45 -0200 | [diff] [blame] | 4119 | { |
| 4120 | } |
| 4121 | |
| 4122 | static const struct weston_shell_client xdg_popup_client = { |
Giulio Camuffo | f05d18f | 2015-12-11 20:57:05 +0200 | [diff] [blame] | 4123 | xdg_popup_send_configure, |
| 4124 | NULL |
Rafael Antognolli | e2a3455 | 2013-12-03 15:35:45 -0200 | [diff] [blame] | 4125 | }; |
| 4126 | |
| 4127 | static struct shell_surface * |
Jason Ekstrand | 9e9512f | 2014-04-16 21:12:10 -0500 | [diff] [blame] | 4128 | create_xdg_popup(struct shell_client *owner, void *shell, |
| 4129 | struct weston_surface *surface, |
Rafael Antognolli | e2a3455 | 2013-12-03 15:35:45 -0200 | [diff] [blame] | 4130 | const struct weston_shell_client *client, |
| 4131 | struct weston_surface *parent, |
| 4132 | struct shell_seat *seat, |
| 4133 | uint32_t serial, |
| 4134 | int32_t x, int32_t y) |
| 4135 | { |
Jonas Ådahl | ee45a55 | 2015-03-18 16:37:47 +0800 | [diff] [blame] | 4136 | struct shell_surface *shsurf; |
Jonas Ådahl | 24185e2 | 2015-02-27 18:37:41 +0800 | [diff] [blame] | 4137 | |
Jason Ekstrand | 9e9512f | 2014-04-16 21:12:10 -0500 | [diff] [blame] | 4138 | shsurf = create_common_surface(owner, shell, surface, client); |
Pekka Paalanen | e972b27 | 2014-10-01 14:03:56 +0300 | [diff] [blame] | 4139 | if (!shsurf) |
| 4140 | return NULL; |
| 4141 | |
Pekka Paalanen | b502654 | 2014-11-12 15:09:24 +0200 | [diff] [blame] | 4142 | set_type(shsurf, SHELL_SURFACE_POPUP); |
Rafael Antognolli | e2a3455 | 2013-12-03 15:35:45 -0200 | [diff] [blame] | 4143 | shsurf->popup.shseat = seat; |
| 4144 | shsurf->popup.serial = serial; |
| 4145 | shsurf->popup.x = x; |
| 4146 | shsurf->popup.y = y; |
| 4147 | shell_surface_set_parent(shsurf, parent); |
| 4148 | |
| 4149 | return shsurf; |
| 4150 | } |
| 4151 | |
| 4152 | static void |
| 4153 | xdg_get_xdg_popup(struct wl_client *client, |
| 4154 | struct wl_resource *resource, |
| 4155 | uint32_t id, |
| 4156 | struct wl_resource *surface_resource, |
| 4157 | struct wl_resource *parent_resource, |
| 4158 | struct wl_resource *seat_resource, |
| 4159 | uint32_t serial, |
Jasper St. Pierre | 14f330c | 2015-02-13 14:01:57 +0800 | [diff] [blame] | 4160 | int32_t x, int32_t y) |
Rafael Antognolli | e2a3455 | 2013-12-03 15:35:45 -0200 | [diff] [blame] | 4161 | { |
| 4162 | struct weston_surface *surface = |
| 4163 | wl_resource_get_user_data(surface_resource); |
Kristian Høgsberg | 2bff94e | 2014-02-11 12:22:51 -0800 | [diff] [blame] | 4164 | struct shell_client *sc = wl_resource_get_user_data(resource); |
| 4165 | struct desktop_shell *shell = sc->shell; |
Rafael Antognolli | e2a3455 | 2013-12-03 15:35:45 -0200 | [diff] [blame] | 4166 | struct shell_surface *shsurf; |
Jonas Ådahl | ee45a55 | 2015-03-18 16:37:47 +0800 | [diff] [blame] | 4167 | struct shell_surface *parent_shsurf; |
Rafael Antognolli | e2a3455 | 2013-12-03 15:35:45 -0200 | [diff] [blame] | 4168 | struct weston_surface *parent; |
| 4169 | struct shell_seat *seat; |
| 4170 | |
Jonas Ådahl | bf48e21 | 2015-02-06 10:15:28 +0800 | [diff] [blame] | 4171 | shsurf = get_shell_surface(surface); |
| 4172 | if (shsurf && shell_surface_is_xdg_popup(shsurf)) { |
| 4173 | wl_resource_post_error(resource, XDG_SHELL_ERROR_ROLE, |
| 4174 | "This wl_surface is already an " |
| 4175 | "xdg_popup"); |
| 4176 | return; |
| 4177 | } |
| 4178 | |
Pekka Paalanen | 50b6747 | 2014-10-01 15:02:41 +0300 | [diff] [blame] | 4179 | if (weston_surface_set_role(surface, "xdg_popup", |
| 4180 | resource, XDG_SHELL_ERROR_ROLE) < 0) |
Rafael Antognolli | e2a3455 | 2013-12-03 15:35:45 -0200 | [diff] [blame] | 4181 | return; |
Rafael Antognolli | e2a3455 | 2013-12-03 15:35:45 -0200 | [diff] [blame] | 4182 | |
| 4183 | if (!parent_resource) { |
| 4184 | wl_resource_post_error(surface_resource, |
| 4185 | WL_DISPLAY_ERROR_INVALID_OBJECT, |
| 4186 | "xdg_shell::get_xdg_popup requires a parent shell surface"); |
Jasper St. Pierre | 666bc92 | 2014-08-07 16:43:13 -0400 | [diff] [blame] | 4187 | return; |
Rafael Antognolli | e2a3455 | 2013-12-03 15:35:45 -0200 | [diff] [blame] | 4188 | } |
| 4189 | |
| 4190 | parent = wl_resource_get_user_data(parent_resource); |
Derek Foreman | bdc8c72 | 2015-10-07 11:51:29 -0500 | [diff] [blame] | 4191 | seat = get_shell_seat(wl_resource_get_user_data(seat_resource)); |
Rafael Antognolli | e2a3455 | 2013-12-03 15:35:45 -0200 | [diff] [blame] | 4192 | |
Jonas Ådahl | ee45a55 | 2015-03-18 16:37:47 +0800 | [diff] [blame] | 4193 | /* Verify that we are creating the top most popup when mapping, |
| 4194 | * as it's not until then we know whether it was mapped as most |
| 4195 | * top level or not. */ |
| 4196 | |
| 4197 | parent_shsurf = get_shell_surface(parent); |
Jonas Ådahl | bc5d849 | 2015-10-07 14:44:50 +0800 | [diff] [blame] | 4198 | if (!parent_shsurf || |
| 4199 | (!shell_surface_is_xdg_popup(parent_shsurf) && |
| 4200 | !shell_surface_is_xdg_surface(parent_shsurf))) { |
Jonas Ådahl | ee45a55 | 2015-03-18 16:37:47 +0800 | [diff] [blame] | 4201 | wl_resource_post_error(resource, |
| 4202 | XDG_SHELL_ERROR_INVALID_POPUP_PARENT, |
| 4203 | "xdg_popup parent was invalid"); |
| 4204 | return; |
| 4205 | } |
| 4206 | |
Jason Ekstrand | 9e9512f | 2014-04-16 21:12:10 -0500 | [diff] [blame] | 4207 | shsurf = create_xdg_popup(sc, shell, surface, &xdg_popup_client, |
Rafael Antognolli | e2a3455 | 2013-12-03 15:35:45 -0200 | [diff] [blame] | 4208 | parent, seat, serial, x, y); |
| 4209 | if (!shsurf) { |
Pekka Paalanen | 50b6747 | 2014-10-01 15:02:41 +0300 | [diff] [blame] | 4210 | wl_resource_post_no_memory(surface_resource); |
Rafael Antognolli | e2a3455 | 2013-12-03 15:35:45 -0200 | [diff] [blame] | 4211 | return; |
| 4212 | } |
| 4213 | |
| 4214 | shsurf->resource = |
| 4215 | wl_resource_create(client, |
| 4216 | &xdg_popup_interface, 1, id); |
| 4217 | wl_resource_set_implementation(shsurf->resource, |
| 4218 | &xdg_popup_implementation, |
| 4219 | shsurf, shell_destroy_shell_surface); |
Jonas Ådahl | 49d77d2 | 2015-03-18 16:20:51 +0800 | [diff] [blame] | 4220 | shsurf->owner_resource = resource; |
| 4221 | wl_list_insert(&sc->surface_list, |
| 4222 | wl_resource_get_link(shsurf->resource)); |
Rafael Antognolli | e2a3455 | 2013-12-03 15:35:45 -0200 | [diff] [blame] | 4223 | } |
| 4224 | |
Kristian Høgsberg | 2bff94e | 2014-02-11 12:22:51 -0800 | [diff] [blame] | 4225 | static void |
| 4226 | xdg_pong(struct wl_client *client, |
| 4227 | struct wl_resource *resource, uint32_t serial) |
| 4228 | { |
| 4229 | struct shell_client *sc = wl_resource_get_user_data(resource); |
Kristian Høgsberg | 2bff94e | 2014-02-11 12:22:51 -0800 | [diff] [blame] | 4230 | |
Kristian Høgsberg | dd62aba | 2014-02-12 09:56:19 -0800 | [diff] [blame] | 4231 | shell_client_pong(sc, serial); |
Kristian Høgsberg | 2bff94e | 2014-02-11 12:22:51 -0800 | [diff] [blame] | 4232 | } |
| 4233 | |
Rafael Antognolli | e2a3455 | 2013-12-03 15:35:45 -0200 | [diff] [blame] | 4234 | static bool |
| 4235 | shell_surface_is_xdg_popup(struct shell_surface *shsurf) |
| 4236 | { |
| 4237 | return wl_resource_instance_of(shsurf->resource, |
| 4238 | &xdg_popup_interface, |
| 4239 | &xdg_popup_implementation); |
| 4240 | } |
| 4241 | |
| 4242 | static const struct xdg_shell_interface xdg_implementation = { |
Jasper St. Pierre | 084aa0b | 2015-02-13 14:02:00 +0800 | [diff] [blame] | 4243 | xdg_shell_destroy, |
Rafael Antognolli | e2a3455 | 2013-12-03 15:35:45 -0200 | [diff] [blame] | 4244 | xdg_use_unstable_version, |
| 4245 | xdg_get_xdg_surface, |
Kristian Høgsberg | 2bff94e | 2014-02-11 12:22:51 -0800 | [diff] [blame] | 4246 | xdg_get_xdg_popup, |
| 4247 | xdg_pong |
Rafael Antognolli | e2a3455 | 2013-12-03 15:35:45 -0200 | [diff] [blame] | 4248 | }; |
| 4249 | |
| 4250 | static int |
| 4251 | xdg_shell_unversioned_dispatch(const void *implementation, |
| 4252 | void *_target, uint32_t opcode, |
| 4253 | const struct wl_message *message, |
| 4254 | union wl_argument *args) |
| 4255 | { |
| 4256 | struct wl_resource *resource = _target; |
Kristian Høgsberg | 2bff94e | 2014-02-11 12:22:51 -0800 | [diff] [blame] | 4257 | struct shell_client *sc = wl_resource_get_user_data(resource); |
Rafael Antognolli | e2a3455 | 2013-12-03 15:35:45 -0200 | [diff] [blame] | 4258 | |
Jasper St. Pierre | 084aa0b | 2015-02-13 14:02:00 +0800 | [diff] [blame] | 4259 | if (opcode != 1 /* XDG_SHELL_USE_UNSTABLE_VERSION */) { |
Rafael Antognolli | e2a3455 | 2013-12-03 15:35:45 -0200 | [diff] [blame] | 4260 | wl_resource_post_error(resource, |
| 4261 | WL_DISPLAY_ERROR_INVALID_OBJECT, |
| 4262 | "must call use_unstable_version first"); |
| 4263 | return 0; |
| 4264 | } |
| 4265 | |
Jasper St. Pierre | 5ba1e1d | 2015-02-13 14:02:02 +0800 | [diff] [blame] | 4266 | #define XDG_SERVER_VERSION 5 |
Rafael Antognolli | e2a3455 | 2013-12-03 15:35:45 -0200 | [diff] [blame] | 4267 | |
Kristian Høgsberg | 8d344a0 | 2013-12-08 22:27:11 -0800 | [diff] [blame] | 4268 | static_assert(XDG_SERVER_VERSION == XDG_SHELL_VERSION_CURRENT, |
| 4269 | "shell implementation doesn't match protocol version"); |
| 4270 | |
Rafael Antognolli | e2a3455 | 2013-12-03 15:35:45 -0200 | [diff] [blame] | 4271 | if (args[0].i != XDG_SERVER_VERSION) { |
| 4272 | wl_resource_post_error(resource, |
| 4273 | WL_DISPLAY_ERROR_INVALID_OBJECT, |
| 4274 | "incompatible version, server is %d " |
| 4275 | "client wants %d", |
| 4276 | XDG_SERVER_VERSION, args[0].i); |
| 4277 | return 0; |
| 4278 | } |
| 4279 | |
| 4280 | wl_resource_set_implementation(resource, &xdg_implementation, |
Kristian Høgsberg | 2bff94e | 2014-02-11 12:22:51 -0800 | [diff] [blame] | 4281 | sc, NULL); |
Rafael Antognolli | e2a3455 | 2013-12-03 15:35:45 -0200 | [diff] [blame] | 4282 | |
| 4283 | return 1; |
| 4284 | } |
| 4285 | |
| 4286 | /* end of xdg-shell implementation */ |
| 4287 | /***********************************/ |
| 4288 | |
Kristian Høgsberg | 0793756 | 2011-04-12 17:25:42 -0400 | [diff] [blame] | 4289 | static void |
Ander Conselvan de Oliveira | 859e885 | 2013-02-21 18:35:21 +0200 | [diff] [blame] | 4290 | shell_fade(struct desktop_shell *shell, enum fade_type type); |
| 4291 | |
Pekka Paalanen | 77346a6 | 2011-11-30 16:26:35 +0200 | [diff] [blame] | 4292 | static void |
Jason Ekstrand | 918f2dd | 2013-12-02 21:01:53 -0600 | [diff] [blame] | 4293 | configure_static_view(struct weston_view *ev, struct weston_layer *layer) |
Kristian Høgsberg | 962342c | 2012-06-26 16:29:50 -0400 | [diff] [blame] | 4294 | { |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 4295 | struct weston_view *v, *next; |
Kristian Høgsberg | 962342c | 2012-06-26 16:29:50 -0400 | [diff] [blame] | 4296 | |
Giulio Camuffo | 412e6a5 | 2014-07-09 22:12:56 +0300 | [diff] [blame] | 4297 | 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] | 4298 | if (v->output == ev->output && v != ev) { |
| 4299 | weston_view_unmap(v); |
| 4300 | v->surface->configure = NULL; |
Pekka Paalanen | 8274d90 | 2014-08-06 19:36:51 +0300 | [diff] [blame] | 4301 | weston_surface_set_label_func(v->surface, NULL); |
Kristian Høgsberg | 962342c | 2012-06-26 16:29:50 -0400 | [diff] [blame] | 4302 | } |
| 4303 | } |
| 4304 | |
Jason Ekstrand | 918f2dd | 2013-12-02 21:01:53 -0600 | [diff] [blame] | 4305 | weston_view_set_position(ev, ev->output->x, ev->output->y); |
Kristian Høgsberg | 962342c | 2012-06-26 16:29:50 -0400 | [diff] [blame] | 4306 | |
Giulio Camuffo | 412e6a5 | 2014-07-09 22:12:56 +0300 | [diff] [blame] | 4307 | if (wl_list_empty(&ev->layer_link.link)) { |
| 4308 | weston_layer_entry_insert(&layer->view_list, &ev->layer_link); |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 4309 | weston_compositor_schedule_repaint(ev->surface->compositor); |
Kristian Høgsberg | 962342c | 2012-06-26 16:29:50 -0400 | [diff] [blame] | 4310 | } |
| 4311 | } |
| 4312 | |
Pekka Paalanen | 8274d90 | 2014-08-06 19:36:51 +0300 | [diff] [blame] | 4313 | static int |
| 4314 | background_get_label(struct weston_surface *surface, char *buf, size_t len) |
| 4315 | { |
| 4316 | return snprintf(buf, len, "background for output %s", |
| 4317 | surface->output->name); |
| 4318 | } |
| 4319 | |
Kristian Høgsberg | 962342c | 2012-06-26 16:29:50 -0400 | [diff] [blame] | 4320 | static void |
Jason Ekstrand | 918f2dd | 2013-12-02 21:01:53 -0600 | [diff] [blame] | 4321 | 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] | 4322 | { |
Giulio Camuffo | 7fe01b1 | 2013-03-28 18:02:42 +0100 | [diff] [blame] | 4323 | struct desktop_shell *shell = es->configure_private; |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 4324 | struct weston_view *view; |
Kristian Høgsberg | af7b1ff | 2012-06-26 21:19:23 -0400 | [diff] [blame] | 4325 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 4326 | view = container_of(es->views.next, struct weston_view, surface_link); |
| 4327 | |
Jason Ekstrand | 918f2dd | 2013-12-02 21:01:53 -0600 | [diff] [blame] | 4328 | configure_static_view(view, &shell->background_layer); |
Kristian Høgsberg | af7b1ff | 2012-06-26 21:19:23 -0400 | [diff] [blame] | 4329 | } |
| 4330 | |
| 4331 | static void |
Kristian Høgsberg | 7584062 | 2011-09-06 13:48:16 -0400 | [diff] [blame] | 4332 | desktop_shell_set_background(struct wl_client *client, |
| 4333 | struct wl_resource *resource, |
Benjamin Franzke | d0f79ab | 2011-11-22 12:43:52 +0100 | [diff] [blame] | 4334 | struct wl_resource *output_resource, |
Kristian Høgsberg | 7584062 | 2011-09-06 13:48:16 -0400 | [diff] [blame] | 4335 | struct wl_resource *surface_resource) |
| 4336 | { |
Jason Ekstrand | 651f00e | 2013-06-14 10:07:54 -0500 | [diff] [blame] | 4337 | struct desktop_shell *shell = wl_resource_get_user_data(resource); |
Jason Ekstrand | 0f2ef7e | 2013-06-14 10:07:53 -0500 | [diff] [blame] | 4338 | struct weston_surface *surface = |
| 4339 | wl_resource_get_user_data(surface_resource); |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 4340 | struct weston_view *view, *next; |
Kristian Høgsberg | 7584062 | 2011-09-06 13:48:16 -0400 | [diff] [blame] | 4341 | |
Kristian Høgsberg | 962342c | 2012-06-26 16:29:50 -0400 | [diff] [blame] | 4342 | if (surface->configure) { |
| 4343 | wl_resource_post_error(surface_resource, |
| 4344 | WL_DISPLAY_ERROR_INVALID_OBJECT, |
| 4345 | "surface role already assigned"); |
| 4346 | return; |
| 4347 | } |
Benjamin Franzke | d0f79ab | 2011-11-22 12:43:52 +0100 | [diff] [blame] | 4348 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 4349 | wl_list_for_each_safe(view, next, &surface->views, surface_link) |
| 4350 | weston_view_destroy(view); |
| 4351 | view = weston_view_create(surface); |
| 4352 | |
Kristian Høgsberg | 962342c | 2012-06-26 16:29:50 -0400 | [diff] [blame] | 4353 | surface->configure = background_configure; |
Giulio Camuffo | 7fe01b1 | 2013-03-28 18:02:42 +0100 | [diff] [blame] | 4354 | surface->configure_private = shell; |
Pekka Paalanen | 8274d90 | 2014-08-06 19:36:51 +0300 | [diff] [blame] | 4355 | weston_surface_set_label_func(surface, background_get_label); |
Jason Ekstrand | a0d2dde | 2013-06-14 10:08:01 -0500 | [diff] [blame] | 4356 | surface->output = wl_resource_get_user_data(output_resource); |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 4357 | view->output = surface->output; |
Jonas Ådahl | 6d6fb61 | 2015-11-17 16:00:33 +0800 | [diff] [blame] | 4358 | weston_desktop_shell_send_configure(resource, 0, |
| 4359 | surface_resource, |
| 4360 | surface->output->width, |
| 4361 | surface->output->height); |
Kristian Høgsberg | 7584062 | 2011-09-06 13:48:16 -0400 | [diff] [blame] | 4362 | } |
| 4363 | |
Pekka Paalanen | 8274d90 | 2014-08-06 19:36:51 +0300 | [diff] [blame] | 4364 | static int |
| 4365 | panel_get_label(struct weston_surface *surface, char *buf, size_t len) |
| 4366 | { |
| 4367 | return snprintf(buf, len, "panel for output %s", |
| 4368 | surface->output->name); |
| 4369 | } |
| 4370 | |
Kristian Høgsberg | 7584062 | 2011-09-06 13:48:16 -0400 | [diff] [blame] | 4371 | static void |
Jason Ekstrand | 918f2dd | 2013-12-02 21:01:53 -0600 | [diff] [blame] | 4372 | 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] | 4373 | { |
Giulio Camuffo | 7fe01b1 | 2013-03-28 18:02:42 +0100 | [diff] [blame] | 4374 | struct desktop_shell *shell = es->configure_private; |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 4375 | struct weston_view *view; |
Kristian Høgsberg | af7b1ff | 2012-06-26 21:19:23 -0400 | [diff] [blame] | 4376 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 4377 | view = container_of(es->views.next, struct weston_view, surface_link); |
| 4378 | |
Jason Ekstrand | 918f2dd | 2013-12-02 21:01:53 -0600 | [diff] [blame] | 4379 | configure_static_view(view, &shell->panel_layer); |
Kristian Høgsberg | af7b1ff | 2012-06-26 21:19:23 -0400 | [diff] [blame] | 4380 | } |
| 4381 | |
| 4382 | static void |
Kristian Høgsberg | 7584062 | 2011-09-06 13:48:16 -0400 | [diff] [blame] | 4383 | desktop_shell_set_panel(struct wl_client *client, |
| 4384 | struct wl_resource *resource, |
Benjamin Franzke | d0f79ab | 2011-11-22 12:43:52 +0100 | [diff] [blame] | 4385 | struct wl_resource *output_resource, |
Kristian Høgsberg | 7584062 | 2011-09-06 13:48:16 -0400 | [diff] [blame] | 4386 | struct wl_resource *surface_resource) |
| 4387 | { |
Jason Ekstrand | 651f00e | 2013-06-14 10:07:54 -0500 | [diff] [blame] | 4388 | struct desktop_shell *shell = wl_resource_get_user_data(resource); |
Jason Ekstrand | 0f2ef7e | 2013-06-14 10:07:53 -0500 | [diff] [blame] | 4389 | struct weston_surface *surface = |
| 4390 | wl_resource_get_user_data(surface_resource); |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 4391 | struct weston_view *view, *next; |
Kristian Høgsberg | 7584062 | 2011-09-06 13:48:16 -0400 | [diff] [blame] | 4392 | |
Kristian Høgsberg | af7b1ff | 2012-06-26 21:19:23 -0400 | [diff] [blame] | 4393 | if (surface->configure) { |
| 4394 | wl_resource_post_error(surface_resource, |
| 4395 | WL_DISPLAY_ERROR_INVALID_OBJECT, |
| 4396 | "surface role already assigned"); |
| 4397 | return; |
| 4398 | } |
Benjamin Franzke | d0f79ab | 2011-11-22 12:43:52 +0100 | [diff] [blame] | 4399 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 4400 | wl_list_for_each_safe(view, next, &surface->views, surface_link) |
| 4401 | weston_view_destroy(view); |
| 4402 | view = weston_view_create(surface); |
| 4403 | |
Kristian Høgsberg | af7b1ff | 2012-06-26 21:19:23 -0400 | [diff] [blame] | 4404 | surface->configure = panel_configure; |
Giulio Camuffo | 7fe01b1 | 2013-03-28 18:02:42 +0100 | [diff] [blame] | 4405 | surface->configure_private = shell; |
Pekka Paalanen | 8274d90 | 2014-08-06 19:36:51 +0300 | [diff] [blame] | 4406 | weston_surface_set_label_func(surface, panel_get_label); |
Jason Ekstrand | a0d2dde | 2013-06-14 10:08:01 -0500 | [diff] [blame] | 4407 | surface->output = wl_resource_get_user_data(output_resource); |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 4408 | view->output = surface->output; |
Jonas Ådahl | 6d6fb61 | 2015-11-17 16:00:33 +0800 | [diff] [blame] | 4409 | weston_desktop_shell_send_configure(resource, 0, |
| 4410 | surface_resource, |
| 4411 | surface->output->width, |
| 4412 | surface->output->height); |
Kristian Høgsberg | 7584062 | 2011-09-06 13:48:16 -0400 | [diff] [blame] | 4413 | } |
| 4414 | |
Pekka Paalanen | 8274d90 | 2014-08-06 19:36:51 +0300 | [diff] [blame] | 4415 | static int |
| 4416 | lock_surface_get_label(struct weston_surface *surface, char *buf, size_t len) |
| 4417 | { |
| 4418 | return snprintf(buf, len, "lock window"); |
| 4419 | } |
| 4420 | |
Pekka Paalanen | 9ef3e01 | 2011-11-15 13:34:48 +0200 | [diff] [blame] | 4421 | static void |
Jason Ekstrand | 918f2dd | 2013-12-02 21:01:53 -0600 | [diff] [blame] | 4422 | 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] | 4423 | { |
Giulio Camuffo | 7fe01b1 | 2013-03-28 18:02:42 +0100 | [diff] [blame] | 4424 | struct desktop_shell *shell = surface->configure_private; |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 4425 | struct weston_view *view; |
| 4426 | |
| 4427 | view = container_of(surface->views.next, struct weston_view, surface_link); |
Kristian Høgsberg | 730c94d | 2012-06-26 21:44:35 -0400 | [diff] [blame] | 4428 | |
Jason Ekstrand | 918f2dd | 2013-12-02 21:01:53 -0600 | [diff] [blame] | 4429 | if (surface->width == 0) |
Giulio Camuffo | 184df50 | 2013-02-21 11:29:21 +0100 | [diff] [blame] | 4430 | return; |
| 4431 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 4432 | center_on_output(view, get_default_output(shell->compositor)); |
Kristian Høgsberg | 730c94d | 2012-06-26 21:44:35 -0400 | [diff] [blame] | 4433 | |
| 4434 | if (!weston_surface_is_mapped(surface)) { |
Giulio Camuffo | 412e6a5 | 2014-07-09 22:12:56 +0300 | [diff] [blame] | 4435 | weston_layer_entry_insert(&shell->lock_layer.view_list, |
| 4436 | &view->layer_link); |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 4437 | weston_view_update_transform(view); |
Ander Conselvan de Oliveira | 87524b6 | 2013-02-21 18:35:22 +0200 | [diff] [blame] | 4438 | shell_fade(shell, FADE_IN); |
Kristian Høgsberg | 730c94d | 2012-06-26 21:44:35 -0400 | [diff] [blame] | 4439 | } |
| 4440 | } |
| 4441 | |
| 4442 | static void |
Kristian Høgsberg | 27e3052 | 2012-04-11 23:18:23 -0400 | [diff] [blame] | 4443 | handle_lock_surface_destroy(struct wl_listener *listener, void *data) |
Kristian Høgsberg | 1ec0c31 | 2011-11-15 16:39:55 -0500 | [diff] [blame] | 4444 | { |
Tiago Vignatti | be14326 | 2012-04-16 17:31:41 +0300 | [diff] [blame] | 4445 | struct desktop_shell *shell = |
| 4446 | container_of(listener, struct desktop_shell, lock_surface_listener); |
Kristian Høgsberg | 1ec0c31 | 2011-11-15 16:39:55 -0500 | [diff] [blame] | 4447 | |
Martin Minarik | 6d11836 | 2012-06-07 18:01:59 +0200 | [diff] [blame] | 4448 | weston_log("lock surface gone\n"); |
Kristian Høgsberg | 1ec0c31 | 2011-11-15 16:39:55 -0500 | [diff] [blame] | 4449 | shell->lock_surface = NULL; |
| 4450 | } |
| 4451 | |
| 4452 | static void |
Pekka Paalanen | 9ef3e01 | 2011-11-15 13:34:48 +0200 | [diff] [blame] | 4453 | desktop_shell_set_lock_surface(struct wl_client *client, |
| 4454 | struct wl_resource *resource, |
| 4455 | struct wl_resource *surface_resource) |
| 4456 | { |
Jason Ekstrand | 651f00e | 2013-06-14 10:07:54 -0500 | [diff] [blame] | 4457 | struct desktop_shell *shell = wl_resource_get_user_data(resource); |
Jason Ekstrand | 0f2ef7e | 2013-06-14 10:07:53 -0500 | [diff] [blame] | 4458 | struct weston_surface *surface = |
| 4459 | wl_resource_get_user_data(surface_resource); |
Pekka Paalanen | 9826223 | 2011-12-01 10:42:22 +0200 | [diff] [blame] | 4460 | |
Pekka Paalanen | f0fc70d | 2011-11-15 13:34:54 +0200 | [diff] [blame] | 4461 | shell->prepare_event_sent = false; |
Kristian Høgsberg | af867cc | 2011-11-15 13:34:49 +0200 | [diff] [blame] | 4462 | |
Pekka Paalanen | f0fc70d | 2011-11-15 13:34:54 +0200 | [diff] [blame] | 4463 | if (!shell->locked) |
| 4464 | return; |
| 4465 | |
Pekka Paalanen | 9826223 | 2011-12-01 10:42:22 +0200 | [diff] [blame] | 4466 | shell->lock_surface = surface; |
Pekka Paalanen | f0fc70d | 2011-11-15 13:34:54 +0200 | [diff] [blame] | 4467 | |
Kristian Høgsberg | 27e3052 | 2012-04-11 23:18:23 -0400 | [diff] [blame] | 4468 | shell->lock_surface_listener.notify = handle_lock_surface_destroy; |
Jason Ekstrand | 651f00e | 2013-06-14 10:07:54 -0500 | [diff] [blame] | 4469 | wl_signal_add(&surface->destroy_signal, |
Kristian Høgsberg | 27e3052 | 2012-04-11 23:18:23 -0400 | [diff] [blame] | 4470 | &shell->lock_surface_listener); |
Pekka Paalanen | 57da4a8 | 2011-11-23 16:42:16 +0200 | [diff] [blame] | 4471 | |
Kristian Høgsberg | aa2ee8b | 2013-10-30 15:49:45 -0700 | [diff] [blame] | 4472 | weston_view_create(surface); |
Kristian Høgsberg | 730c94d | 2012-06-26 21:44:35 -0400 | [diff] [blame] | 4473 | surface->configure = lock_surface_configure; |
Giulio Camuffo | 7fe01b1 | 2013-03-28 18:02:42 +0100 | [diff] [blame] | 4474 | surface->configure_private = shell; |
Pekka Paalanen | 8274d90 | 2014-08-06 19:36:51 +0300 | [diff] [blame] | 4475 | weston_surface_set_label_func(surface, lock_surface_get_label); |
Pekka Paalanen | f0fc70d | 2011-11-15 13:34:54 +0200 | [diff] [blame] | 4476 | } |
| 4477 | |
| 4478 | static void |
Tiago Vignatti | be14326 | 2012-04-16 17:31:41 +0300 | [diff] [blame] | 4479 | resume_desktop(struct desktop_shell *shell) |
Pekka Paalanen | f0fc70d | 2011-11-15 13:34:54 +0200 | [diff] [blame] | 4480 | { |
Kristian Høgsberg | 4476aaf | 2012-06-25 14:03:13 -0400 | [diff] [blame] | 4481 | struct workspace *ws = get_current_workspace(shell); |
Pekka Paalanen | 77346a6 | 2011-11-30 16:26:35 +0200 | [diff] [blame] | 4482 | |
Kristian Høgsberg | 3be2ce9 | 2012-02-29 12:42:35 -0500 | [diff] [blame] | 4483 | wl_list_remove(&shell->lock_layer.link); |
Philipp Brüschweiler | 711fda8 | 2012-08-09 18:50:43 +0200 | [diff] [blame] | 4484 | if (shell->showing_input_panels) { |
Manuel Bachmann | 805d2f5 | 2014-03-05 12:21:34 +0100 | [diff] [blame] | 4485 | wl_list_insert(&shell->compositor->cursor_layer.link, |
Philipp Brüschweiler | 711fda8 | 2012-08-09 18:50:43 +0200 | [diff] [blame] | 4486 | &shell->input_panel_layer.link); |
| 4487 | wl_list_insert(&shell->input_panel_layer.link, |
Manuel Bachmann | 805d2f5 | 2014-03-05 12:21:34 +0100 | [diff] [blame] | 4488 | &shell->fullscreen_layer.link); |
Philipp Brüschweiler | 711fda8 | 2012-08-09 18:50:43 +0200 | [diff] [blame] | 4489 | } else { |
Manuel Bachmann | 805d2f5 | 2014-03-05 12:21:34 +0100 | [diff] [blame] | 4490 | wl_list_insert(&shell->compositor->cursor_layer.link, |
| 4491 | &shell->fullscreen_layer.link); |
Philipp Brüschweiler | 711fda8 | 2012-08-09 18:50:43 +0200 | [diff] [blame] | 4492 | } |
Manuel Bachmann | 805d2f5 | 2014-03-05 12:21:34 +0100 | [diff] [blame] | 4493 | wl_list_insert(&shell->fullscreen_layer.link, |
| 4494 | &shell->panel_layer.link); |
| 4495 | wl_list_insert(&shell->panel_layer.link, |
| 4496 | &ws->layer.link), |
Pekka Paalanen | f0fc70d | 2011-11-15 13:34:54 +0200 | [diff] [blame] | 4497 | |
Kristian Høgsberg | 2f5faff | 2012-07-31 16:36:34 -0400 | [diff] [blame] | 4498 | restore_focus_state(shell, get_current_workspace(shell)); |
Jonas Ådahl | 0476974 | 2012-06-13 00:01:24 +0200 | [diff] [blame] | 4499 | |
Pekka Paalanen | f0fc70d | 2011-11-15 13:34:54 +0200 | [diff] [blame] | 4500 | shell->locked = false; |
Ander Conselvan de Oliveira | 87524b6 | 2013-02-21 18:35:22 +0200 | [diff] [blame] | 4501 | shell_fade(shell, FADE_IN); |
Pekka Paalanen | fc6d91a | 2012-02-10 15:33:10 +0200 | [diff] [blame] | 4502 | weston_compositor_damage_all(shell->compositor); |
Pekka Paalanen | 9ef3e01 | 2011-11-15 13:34:48 +0200 | [diff] [blame] | 4503 | } |
| 4504 | |
| 4505 | static void |
| 4506 | desktop_shell_unlock(struct wl_client *client, |
| 4507 | struct wl_resource *resource) |
| 4508 | { |
Jason Ekstrand | 651f00e | 2013-06-14 10:07:54 -0500 | [diff] [blame] | 4509 | struct desktop_shell *shell = wl_resource_get_user_data(resource); |
Pekka Paalanen | 9ef3e01 | 2011-11-15 13:34:48 +0200 | [diff] [blame] | 4510 | |
Pekka Paalanen | 9ef3e01 | 2011-11-15 13:34:48 +0200 | [diff] [blame] | 4511 | shell->prepare_event_sent = false; |
Pekka Paalanen | f0fc70d | 2011-11-15 13:34:54 +0200 | [diff] [blame] | 4512 | |
| 4513 | if (shell->locked) |
| 4514 | resume_desktop(shell); |
Pekka Paalanen | 9ef3e01 | 2011-11-15 13:34:48 +0200 | [diff] [blame] | 4515 | } |
| 4516 | |
Kristian Høgsberg | d56bd90 | 2012-06-05 09:58:51 -0400 | [diff] [blame] | 4517 | static void |
Ander Conselvan de Oliveira | b9d2a0f | 2012-06-28 18:08:05 +0300 | [diff] [blame] | 4518 | desktop_shell_set_grab_surface(struct wl_client *client, |
Kristian Høgsberg | d56bd90 | 2012-06-05 09:58:51 -0400 | [diff] [blame] | 4519 | struct wl_resource *resource, |
| 4520 | struct wl_resource *surface_resource) |
| 4521 | { |
Jason Ekstrand | 651f00e | 2013-06-14 10:07:54 -0500 | [diff] [blame] | 4522 | struct desktop_shell *shell = wl_resource_get_user_data(resource); |
Kristian Høgsberg | d56bd90 | 2012-06-05 09:58:51 -0400 | [diff] [blame] | 4523 | |
Jason Ekstrand | 0f2ef7e | 2013-06-14 10:07:53 -0500 | [diff] [blame] | 4524 | shell->grab_surface = wl_resource_get_user_data(surface_resource); |
Kristian Høgsberg | 48588f8 | 2013-10-24 15:51:35 -0700 | [diff] [blame] | 4525 | weston_view_create(shell->grab_surface); |
Kristian Høgsberg | d56bd90 | 2012-06-05 09:58:51 -0400 | [diff] [blame] | 4526 | } |
| 4527 | |
Pekka Paalanen | 79346ab | 2013-05-22 18:03:09 +0300 | [diff] [blame] | 4528 | static void |
| 4529 | desktop_shell_desktop_ready(struct wl_client *client, |
| 4530 | struct wl_resource *resource) |
| 4531 | { |
Jason Ekstrand | 651f00e | 2013-06-14 10:07:54 -0500 | [diff] [blame] | 4532 | struct desktop_shell *shell = wl_resource_get_user_data(resource); |
Pekka Paalanen | 79346ab | 2013-05-22 18:03:09 +0300 | [diff] [blame] | 4533 | |
| 4534 | shell_fade_startup(shell); |
| 4535 | } |
| 4536 | |
Jonny Lamb | 765760d | 2014-08-20 15:53:19 +0200 | [diff] [blame] | 4537 | static void |
| 4538 | desktop_shell_set_panel_position(struct wl_client *client, |
| 4539 | struct wl_resource *resource, |
| 4540 | uint32_t position) |
| 4541 | { |
| 4542 | struct desktop_shell *shell = wl_resource_get_user_data(resource); |
| 4543 | |
Jonas Ådahl | 6d6fb61 | 2015-11-17 16:00:33 +0800 | [diff] [blame] | 4544 | if (position != WESTON_DESKTOP_SHELL_PANEL_POSITION_TOP && |
| 4545 | position != WESTON_DESKTOP_SHELL_PANEL_POSITION_BOTTOM && |
| 4546 | position != WESTON_DESKTOP_SHELL_PANEL_POSITION_LEFT && |
| 4547 | position != WESTON_DESKTOP_SHELL_PANEL_POSITION_RIGHT) { |
Jonny Lamb | 765760d | 2014-08-20 15:53:19 +0200 | [diff] [blame] | 4548 | wl_resource_post_error(resource, |
Jonas Ådahl | 6d6fb61 | 2015-11-17 16:00:33 +0800 | [diff] [blame] | 4549 | WESTON_DESKTOP_SHELL_ERROR_INVALID_ARGUMENT, |
Jonny Lamb | 765760d | 2014-08-20 15:53:19 +0200 | [diff] [blame] | 4550 | "bad position argument"); |
| 4551 | return; |
| 4552 | } |
| 4553 | |
| 4554 | shell->panel_position = position; |
| 4555 | } |
| 4556 | |
Jonas Ådahl | 6d6fb61 | 2015-11-17 16:00:33 +0800 | [diff] [blame] | 4557 | static const struct weston_desktop_shell_interface desktop_shell_implementation = { |
Kristian Høgsberg | 7584062 | 2011-09-06 13:48:16 -0400 | [diff] [blame] | 4558 | desktop_shell_set_background, |
Pekka Paalanen | 9ef3e01 | 2011-11-15 13:34:48 +0200 | [diff] [blame] | 4559 | desktop_shell_set_panel, |
| 4560 | desktop_shell_set_lock_surface, |
Kristian Høgsberg | d56bd90 | 2012-06-05 09:58:51 -0400 | [diff] [blame] | 4561 | desktop_shell_unlock, |
Pekka Paalanen | 79346ab | 2013-05-22 18:03:09 +0300 | [diff] [blame] | 4562 | desktop_shell_set_grab_surface, |
Jonny Lamb | 765760d | 2014-08-20 15:53:19 +0200 | [diff] [blame] | 4563 | desktop_shell_desktop_ready, |
| 4564 | desktop_shell_set_panel_position |
Kristian Høgsberg | 7584062 | 2011-09-06 13:48:16 -0400 | [diff] [blame] | 4565 | }; |
| 4566 | |
Pekka Paalanen | 92a0dc4 | 2011-11-28 15:34:13 +0200 | [diff] [blame] | 4567 | static enum shell_surface_type |
Kristian Høgsberg | 8334bc1 | 2012-01-03 10:29:47 -0500 | [diff] [blame] | 4568 | get_shell_surface_type(struct weston_surface *surface) |
Pekka Paalanen | 92a0dc4 | 2011-11-28 15:34:13 +0200 | [diff] [blame] | 4569 | { |
| 4570 | struct shell_surface *shsurf; |
| 4571 | |
| 4572 | shsurf = get_shell_surface(surface); |
| 4573 | if (!shsurf) |
Pekka Paalanen | 9826223 | 2011-12-01 10:42:22 +0200 | [diff] [blame] | 4574 | return SHELL_SURFACE_NONE; |
Pekka Paalanen | 92a0dc4 | 2011-11-28 15:34:13 +0200 | [diff] [blame] | 4575 | return shsurf->type; |
| 4576 | } |
| 4577 | |
Kristian Høgsberg | 7584062 | 2011-09-06 13:48:16 -0400 | [diff] [blame] | 4578 | static void |
Derek Foreman | 8ae2db5 | 2015-07-15 13:00:36 -0500 | [diff] [blame] | 4579 | move_binding(struct weston_pointer *pointer, uint32_t time, |
| 4580 | uint32_t button, void *data) |
Kristian Høgsberg | 0793756 | 2011-04-12 17:25:42 -0400 | [diff] [blame] | 4581 | { |
Rafal Mielniczuk | b2917a2 | 2014-01-05 20:04:59 +0100 | [diff] [blame] | 4582 | struct weston_surface *focus; |
Pekka Paalanen | 01388e2 | 2013-04-25 13:57:44 +0300 | [diff] [blame] | 4583 | struct weston_surface *surface; |
Kristian Høgsberg | 938b8fa | 2012-05-18 13:46:27 -0400 | [diff] [blame] | 4584 | struct shell_surface *shsurf; |
Kristian Høgsberg | d2abb83 | 2011-11-23 10:52:40 -0500 | [diff] [blame] | 4585 | |
Derek Foreman | 8ae2db5 | 2015-07-15 13:00:36 -0500 | [diff] [blame] | 4586 | if (pointer->focus == NULL) |
Rafal Mielniczuk | b2917a2 | 2014-01-05 20:04:59 +0100 | [diff] [blame] | 4587 | return; |
| 4588 | |
Derek Foreman | 8ae2db5 | 2015-07-15 13:00:36 -0500 | [diff] [blame] | 4589 | focus = pointer->focus->surface; |
Rafal Mielniczuk | b2917a2 | 2014-01-05 20:04:59 +0100 | [diff] [blame] | 4590 | |
Pekka Paalanen | 01388e2 | 2013-04-25 13:57:44 +0300 | [diff] [blame] | 4591 | surface = weston_surface_get_main_surface(focus); |
Benjamin Franzke | d0f79ab | 2011-11-22 12:43:52 +0100 | [diff] [blame] | 4592 | if (surface == NULL) |
| 4593 | return; |
Kristian Høgsberg | 0793756 | 2011-04-12 17:25:42 -0400 | [diff] [blame] | 4594 | |
Kristian Høgsberg | 938b8fa | 2012-05-18 13:46:27 -0400 | [diff] [blame] | 4595 | shsurf = get_shell_surface(surface); |
Rafael Antognolli | 03b1659 | 2013-12-03 15:35:42 -0200 | [diff] [blame] | 4596 | if (shsurf == NULL || shsurf->state.fullscreen || |
| 4597 | shsurf->state.maximized) |
Kristian Høgsberg | 938b8fa | 2012-05-18 13:46:27 -0400 | [diff] [blame] | 4598 | return; |
| 4599 | |
Derek Foreman | 794fa0e | 2015-07-15 13:00:38 -0500 | [diff] [blame] | 4600 | surface_move(shsurf, pointer, false); |
Kristian Høgsberg | 0793756 | 2011-04-12 17:25:42 -0400 | [diff] [blame] | 4601 | } |
| 4602 | |
| 4603 | static void |
Derek Foreman | 8ae2db5 | 2015-07-15 13:00:36 -0500 | [diff] [blame] | 4604 | maximize_binding(struct weston_keyboard *keyboard, uint32_t time, |
| 4605 | uint32_t button, void *data) |
Rafael Antognolli | ea997ac | 2013-12-03 15:35:48 -0200 | [diff] [blame] | 4606 | { |
Derek Foreman | 8ae2db5 | 2015-07-15 13:00:36 -0500 | [diff] [blame] | 4607 | struct weston_surface *focus = keyboard->focus; |
Rafael Antognolli | ea997ac | 2013-12-03 15:35:48 -0200 | [diff] [blame] | 4608 | struct weston_surface *surface; |
| 4609 | struct shell_surface *shsurf; |
| 4610 | |
| 4611 | surface = weston_surface_get_main_surface(focus); |
| 4612 | if (surface == NULL) |
| 4613 | return; |
| 4614 | |
| 4615 | shsurf = get_shell_surface(surface); |
| 4616 | if (shsurf == NULL) |
| 4617 | return; |
| 4618 | |
| 4619 | if (!shell_surface_is_xdg_surface(shsurf)) |
| 4620 | return; |
| 4621 | |
Jasper St. Pierre | ab2c108 | 2014-04-10 10:41:46 -0700 | [diff] [blame] | 4622 | shsurf->state_requested = true; |
| 4623 | shsurf->requested_state.maximized = !shsurf->state.maximized; |
Jasper St. Pierre | 9aa8ce6 | 2014-04-11 16:18:54 -0700 | [diff] [blame] | 4624 | send_configure_for_surface(shsurf); |
Rafael Antognolli | ea997ac | 2013-12-03 15:35:48 -0200 | [diff] [blame] | 4625 | } |
| 4626 | |
| 4627 | static void |
Derek Foreman | 8ae2db5 | 2015-07-15 13:00:36 -0500 | [diff] [blame] | 4628 | fullscreen_binding(struct weston_keyboard *keyboard, uint32_t time, |
| 4629 | uint32_t button, void *data) |
Rafael Antognolli | ea997ac | 2013-12-03 15:35:48 -0200 | [diff] [blame] | 4630 | { |
Derek Foreman | 8ae2db5 | 2015-07-15 13:00:36 -0500 | [diff] [blame] | 4631 | struct weston_surface *focus = keyboard->focus; |
Rafael Antognolli | ea997ac | 2013-12-03 15:35:48 -0200 | [diff] [blame] | 4632 | struct weston_surface *surface; |
| 4633 | struct shell_surface *shsurf; |
| 4634 | |
| 4635 | surface = weston_surface_get_main_surface(focus); |
| 4636 | if (surface == NULL) |
| 4637 | return; |
| 4638 | |
| 4639 | shsurf = get_shell_surface(surface); |
| 4640 | if (shsurf == NULL) |
| 4641 | return; |
| 4642 | |
| 4643 | if (!shell_surface_is_xdg_surface(shsurf)) |
| 4644 | return; |
| 4645 | |
Jasper St. Pierre | ab2c108 | 2014-04-10 10:41:46 -0700 | [diff] [blame] | 4646 | shsurf->state_requested = true; |
| 4647 | shsurf->requested_state.fullscreen = !shsurf->state.fullscreen; |
Boyan Ding | 32abdbb | 2014-06-26 10:19:32 +0800 | [diff] [blame] | 4648 | shsurf->fullscreen_output = shsurf->output; |
Jasper St. Pierre | 9aa8ce6 | 2014-04-11 16:18:54 -0700 | [diff] [blame] | 4649 | send_configure_for_surface(shsurf); |
Rafael Antognolli | ea997ac | 2013-12-03 15:35:48 -0200 | [diff] [blame] | 4650 | } |
| 4651 | |
| 4652 | static void |
Derek Foreman | 8ae2db5 | 2015-07-15 13:00:36 -0500 | [diff] [blame] | 4653 | touch_move_binding(struct weston_touch *touch, uint32_t time, void *data) |
Neil Roberts | aba0f25 | 2013-10-03 16:43:05 +0100 | [diff] [blame] | 4654 | { |
Derek Foreman | 362656b | 2014-09-04 10:23:05 -0500 | [diff] [blame] | 4655 | struct weston_surface *focus; |
Neil Roberts | aba0f25 | 2013-10-03 16:43:05 +0100 | [diff] [blame] | 4656 | struct weston_surface *surface; |
| 4657 | struct shell_surface *shsurf; |
| 4658 | |
Derek Foreman | 8ae2db5 | 2015-07-15 13:00:36 -0500 | [diff] [blame] | 4659 | if (touch->focus == NULL) |
Derek Foreman | 362656b | 2014-09-04 10:23:05 -0500 | [diff] [blame] | 4660 | return; |
| 4661 | |
Derek Foreman | 8ae2db5 | 2015-07-15 13:00:36 -0500 | [diff] [blame] | 4662 | focus = touch->focus->surface; |
Neil Roberts | aba0f25 | 2013-10-03 16:43:05 +0100 | [diff] [blame] | 4663 | surface = weston_surface_get_main_surface(focus); |
| 4664 | if (surface == NULL) |
| 4665 | return; |
| 4666 | |
| 4667 | shsurf = get_shell_surface(surface); |
Rafael Antognolli | 03b1659 | 2013-12-03 15:35:42 -0200 | [diff] [blame] | 4668 | if (shsurf == NULL || shsurf->state.fullscreen || |
| 4669 | shsurf->state.maximized) |
Neil Roberts | aba0f25 | 2013-10-03 16:43:05 +0100 | [diff] [blame] | 4670 | return; |
| 4671 | |
Derek Foreman | b7674ae | 2015-07-15 13:00:37 -0500 | [diff] [blame] | 4672 | surface_touch_move(shsurf, touch); |
Neil Roberts | aba0f25 | 2013-10-03 16:43:05 +0100 | [diff] [blame] | 4673 | } |
| 4674 | |
| 4675 | static void |
Derek Foreman | 8ae2db5 | 2015-07-15 13:00:36 -0500 | [diff] [blame] | 4676 | resize_binding(struct weston_pointer *pointer, uint32_t time, |
| 4677 | uint32_t button, void *data) |
Kristian Høgsberg | 0793756 | 2011-04-12 17:25:42 -0400 | [diff] [blame] | 4678 | { |
Rafal Mielniczuk | b2917a2 | 2014-01-05 20:04:59 +0100 | [diff] [blame] | 4679 | struct weston_surface *focus; |
Pekka Paalanen | 01388e2 | 2013-04-25 13:57:44 +0300 | [diff] [blame] | 4680 | struct weston_surface *surface; |
Kristian Høgsberg | 0793756 | 2011-04-12 17:25:42 -0400 | [diff] [blame] | 4681 | uint32_t edges = 0; |
| 4682 | int32_t x, y; |
Pekka Paalanen | 9d1613e | 2011-11-25 12:09:16 +0200 | [diff] [blame] | 4683 | struct shell_surface *shsurf; |
Kristian Høgsberg | d2abb83 | 2011-11-23 10:52:40 -0500 | [diff] [blame] | 4684 | |
Derek Foreman | 8ae2db5 | 2015-07-15 13:00:36 -0500 | [diff] [blame] | 4685 | if (pointer->focus == NULL) |
Rafal Mielniczuk | b2917a2 | 2014-01-05 20:04:59 +0100 | [diff] [blame] | 4686 | return; |
| 4687 | |
Derek Foreman | 8ae2db5 | 2015-07-15 13:00:36 -0500 | [diff] [blame] | 4688 | focus = pointer->focus->surface; |
Rafal Mielniczuk | b2917a2 | 2014-01-05 20:04:59 +0100 | [diff] [blame] | 4689 | |
Pekka Paalanen | 01388e2 | 2013-04-25 13:57:44 +0300 | [diff] [blame] | 4690 | surface = weston_surface_get_main_surface(focus); |
Benjamin Franzke | d0f79ab | 2011-11-22 12:43:52 +0100 | [diff] [blame] | 4691 | if (surface == NULL) |
| 4692 | return; |
Pekka Paalanen | 92a0dc4 | 2011-11-28 15:34:13 +0200 | [diff] [blame] | 4693 | |
Pekka Paalanen | 9d1613e | 2011-11-25 12:09:16 +0200 | [diff] [blame] | 4694 | shsurf = get_shell_surface(surface); |
Rafael Antognolli | 03b1659 | 2013-12-03 15:35:42 -0200 | [diff] [blame] | 4695 | if (shsurf == NULL || shsurf->state.fullscreen || |
| 4696 | shsurf->state.maximized) |
Pekka Paalanen | 92a0dc4 | 2011-11-28 15:34:13 +0200 | [diff] [blame] | 4697 | return; |
| 4698 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 4699 | weston_view_from_global(shsurf->view, |
Derek Foreman | 8ae2db5 | 2015-07-15 13:00:36 -0500 | [diff] [blame] | 4700 | wl_fixed_to_int(pointer->grab_x), |
| 4701 | wl_fixed_to_int(pointer->grab_y), |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 4702 | &x, &y); |
Kristian Høgsberg | 0793756 | 2011-04-12 17:25:42 -0400 | [diff] [blame] | 4703 | |
Jason Ekstrand | 918f2dd | 2013-12-02 21:01:53 -0600 | [diff] [blame] | 4704 | if (x < shsurf->surface->width / 3) |
Pekka Paalanen | 9d1613e | 2011-11-25 12:09:16 +0200 | [diff] [blame] | 4705 | edges |= WL_SHELL_SURFACE_RESIZE_LEFT; |
Jason Ekstrand | 918f2dd | 2013-12-02 21:01:53 -0600 | [diff] [blame] | 4706 | else if (x < 2 * shsurf->surface->width / 3) |
Kristian Høgsberg | 0793756 | 2011-04-12 17:25:42 -0400 | [diff] [blame] | 4707 | edges |= 0; |
| 4708 | else |
Pekka Paalanen | 9d1613e | 2011-11-25 12:09:16 +0200 | [diff] [blame] | 4709 | edges |= WL_SHELL_SURFACE_RESIZE_RIGHT; |
Kristian Høgsberg | 0793756 | 2011-04-12 17:25:42 -0400 | [diff] [blame] | 4710 | |
Jason Ekstrand | 918f2dd | 2013-12-02 21:01:53 -0600 | [diff] [blame] | 4711 | if (y < shsurf->surface->height / 3) |
Pekka Paalanen | 9d1613e | 2011-11-25 12:09:16 +0200 | [diff] [blame] | 4712 | edges |= WL_SHELL_SURFACE_RESIZE_TOP; |
Jason Ekstrand | 918f2dd | 2013-12-02 21:01:53 -0600 | [diff] [blame] | 4713 | else if (y < 2 * shsurf->surface->height / 3) |
Kristian Høgsberg | 0793756 | 2011-04-12 17:25:42 -0400 | [diff] [blame] | 4714 | edges |= 0; |
| 4715 | else |
Pekka Paalanen | 9d1613e | 2011-11-25 12:09:16 +0200 | [diff] [blame] | 4716 | edges |= WL_SHELL_SURFACE_RESIZE_BOTTOM; |
Kristian Høgsberg | 0793756 | 2011-04-12 17:25:42 -0400 | [diff] [blame] | 4717 | |
Derek Foreman | 8fbebbd | 2015-07-15 13:00:40 -0500 | [diff] [blame] | 4718 | surface_resize(shsurf, pointer, edges); |
Kristian Høgsberg | 02ec0a5 | 2011-04-23 13:04:11 -0400 | [diff] [blame] | 4719 | } |
| 4720 | |
| 4721 | static void |
Derek Foreman | 8ae2db5 | 2015-07-15 13:00:36 -0500 | [diff] [blame] | 4722 | surface_opacity_binding(struct weston_pointer *pointer, uint32_t time, |
| 4723 | uint32_t axis, wl_fixed_t value, void *data) |
Scott Moreau | a3aa9c9 | 2012-03-22 11:01:03 -0600 | [diff] [blame] | 4724 | { |
Jonas Ådahl | b0b87ba | 2012-09-27 18:40:42 +0200 | [diff] [blame] | 4725 | float step = 0.005; |
Scott Moreau | a3aa9c9 | 2012-03-22 11:01:03 -0600 | [diff] [blame] | 4726 | struct shell_surface *shsurf; |
Derek Foreman | 8ae2db5 | 2015-07-15 13:00:36 -0500 | [diff] [blame] | 4727 | struct weston_surface *focus = pointer->focus->surface; |
Pekka Paalanen | 01388e2 | 2013-04-25 13:57:44 +0300 | [diff] [blame] | 4728 | struct weston_surface *surface; |
Scott Moreau | a3aa9c9 | 2012-03-22 11:01:03 -0600 | [diff] [blame] | 4729 | |
Pekka Paalanen | 01388e2 | 2013-04-25 13:57:44 +0300 | [diff] [blame] | 4730 | /* XXX: broken for windows containing sub-surfaces */ |
| 4731 | surface = weston_surface_get_main_surface(focus); |
Scott Moreau | a3aa9c9 | 2012-03-22 11:01:03 -0600 | [diff] [blame] | 4732 | if (surface == NULL) |
| 4733 | return; |
| 4734 | |
| 4735 | shsurf = get_shell_surface(surface); |
| 4736 | if (!shsurf) |
| 4737 | return; |
| 4738 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 4739 | shsurf->view->alpha -= wl_fixed_to_double(value) * step; |
Scott Moreau | a3aa9c9 | 2012-03-22 11:01:03 -0600 | [diff] [blame] | 4740 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 4741 | if (shsurf->view->alpha > 1.0) |
| 4742 | shsurf->view->alpha = 1.0; |
| 4743 | if (shsurf->view->alpha < step) |
| 4744 | shsurf->view->alpha = step; |
Scott Moreau | a3aa9c9 | 2012-03-22 11:01:03 -0600 | [diff] [blame] | 4745 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 4746 | weston_view_geometry_dirty(shsurf->view); |
Scott Moreau | a3aa9c9 | 2012-03-22 11:01:03 -0600 | [diff] [blame] | 4747 | weston_surface_damage(surface); |
| 4748 | } |
| 4749 | |
| 4750 | static void |
Kristian Høgsberg | e314875 | 2013-05-06 23:19:49 -0400 | [diff] [blame] | 4751 | 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] | 4752 | wl_fixed_t value) |
Scott Moreau | ccbf29d | 2012-02-22 14:21:41 -0700 | [diff] [blame] | 4753 | { |
Derek Foreman | 8aeeac8 | 2015-01-30 13:24:36 -0600 | [diff] [blame] | 4754 | struct weston_compositor *compositor = seat->compositor; |
Derek Foreman | 1281a36 | 2015-07-31 16:55:32 -0500 | [diff] [blame] | 4755 | struct weston_pointer *pointer = weston_seat_get_pointer(seat); |
Scott Moreau | ccbf29d | 2012-02-22 14:21:41 -0700 | [diff] [blame] | 4756 | struct weston_output *output; |
Scott Moreau | e660398 | 2012-06-11 13:07:51 -0600 | [diff] [blame] | 4757 | float increment; |
Scott Moreau | ccbf29d | 2012-02-22 14:21:41 -0700 | [diff] [blame] | 4758 | |
Derek Foreman | 1281a36 | 2015-07-31 16:55:32 -0500 | [diff] [blame] | 4759 | if (!pointer) { |
Derek Foreman | 7ef3bed | 2015-01-06 14:28:13 -0600 | [diff] [blame] | 4760 | weston_log("Zoom hotkey pressed but seat '%s' contains no pointer.\n", seat->seat_name); |
| 4761 | return; |
| 4762 | } |
| 4763 | |
Scott Moreau | ccbf29d | 2012-02-22 14:21:41 -0700 | [diff] [blame] | 4764 | wl_list_for_each(output, &compositor->output_list, link) { |
| 4765 | if (pixman_region32_contains_point(&output->region, |
Derek Foreman | 1281a36 | 2015-07-31 16:55:32 -0500 | [diff] [blame] | 4766 | wl_fixed_to_double(pointer->x), |
| 4767 | wl_fixed_to_double(pointer->y), |
Daniel Stone | 103db7f | 2012-05-08 17:17:55 +0100 | [diff] [blame] | 4768 | NULL)) { |
Daniel Stone | 325fc2d | 2012-05-30 16:31:58 +0100 | [diff] [blame] | 4769 | if (key == KEY_PAGEUP) |
Kristian Høgsberg | 9b68af0 | 2012-05-22 12:55:18 -0400 | [diff] [blame] | 4770 | increment = output->zoom.increment; |
Daniel Stone | 325fc2d | 2012-05-30 16:31:58 +0100 | [diff] [blame] | 4771 | else if (key == KEY_PAGEDOWN) |
Kristian Høgsberg | 9b68af0 | 2012-05-22 12:55:18 -0400 | [diff] [blame] | 4772 | increment = -output->zoom.increment; |
| 4773 | else if (axis == WL_POINTER_AXIS_VERTICAL_SCROLL) |
Jonas Ådahl | b0b87ba | 2012-09-27 18:40:42 +0200 | [diff] [blame] | 4774 | /* For every pixel zoom 20th of a step */ |
Daniel Stone | 0c1e46e | 2012-05-30 16:31:59 +0100 | [diff] [blame] | 4775 | increment = output->zoom.increment * |
Jonas Ådahl | b0b87ba | 2012-09-27 18:40:42 +0200 | [diff] [blame] | 4776 | -wl_fixed_to_double(value) / 20.0; |
Kristian Høgsberg | 9b68af0 | 2012-05-22 12:55:18 -0400 | [diff] [blame] | 4777 | else |
| 4778 | increment = 0; |
| 4779 | |
Kristian Høgsberg | 9b68af0 | 2012-05-22 12:55:18 -0400 | [diff] [blame] | 4780 | output->zoom.level += increment; |
Scott Moreau | c6d7f60 | 2012-02-23 22:28:37 -0700 | [diff] [blame] | 4781 | |
Scott Moreau | e660398 | 2012-06-11 13:07:51 -0600 | [diff] [blame] | 4782 | if (output->zoom.level < 0.0) |
Scott Moreau | 850ca42 | 2012-05-21 15:21:25 -0600 | [diff] [blame] | 4783 | output->zoom.level = 0.0; |
Scott Moreau | e660398 | 2012-06-11 13:07:51 -0600 | [diff] [blame] | 4784 | else if (output->zoom.level > output->zoom.max_level) |
| 4785 | output->zoom.level = output->zoom.max_level; |
Derek Foreman | 25bd8a7 | 2015-07-23 14:55:13 -0500 | [diff] [blame] | 4786 | |
| 4787 | if (!output->zoom.active) { |
| 4788 | if (output->zoom.level <= 0.0) |
| 4789 | continue; |
Derek Foreman | 22276a5 | 2015-07-23 14:55:15 -0500 | [diff] [blame] | 4790 | weston_output_activate_zoom(output, seat); |
Kristian Høgsberg | 79af73e | 2012-08-03 15:45:23 -0400 | [diff] [blame] | 4791 | } |
Scott Moreau | ccbf29d | 2012-02-22 14:21:41 -0700 | [diff] [blame] | 4792 | |
Scott Moreau | e660398 | 2012-06-11 13:07:51 -0600 | [diff] [blame] | 4793 | output->zoom.spring_z.target = output->zoom.level; |
Scott Moreau | ccbf29d | 2012-02-22 14:21:41 -0700 | [diff] [blame] | 4794 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 4795 | weston_output_update_zoom(output); |
Scott Moreau | ccbf29d | 2012-02-22 14:21:41 -0700 | [diff] [blame] | 4796 | } |
| 4797 | } |
| 4798 | } |
| 4799 | |
Scott Moreau | ccbf29d | 2012-02-22 14:21:41 -0700 | [diff] [blame] | 4800 | static void |
Derek Foreman | 8ae2db5 | 2015-07-15 13:00:36 -0500 | [diff] [blame] | 4801 | zoom_axis_binding(struct weston_pointer *pointer, uint32_t time, |
| 4802 | uint32_t axis, wl_fixed_t value, void *data) |
Daniel Stone | 325fc2d | 2012-05-30 16:31:58 +0100 | [diff] [blame] | 4803 | { |
Derek Foreman | 8ae2db5 | 2015-07-15 13:00:36 -0500 | [diff] [blame] | 4804 | do_zoom(pointer->seat, time, 0, axis, value); |
Daniel Stone | 325fc2d | 2012-05-30 16:31:58 +0100 | [diff] [blame] | 4805 | } |
| 4806 | |
| 4807 | static void |
Derek Foreman | 8ae2db5 | 2015-07-15 13:00:36 -0500 | [diff] [blame] | 4808 | zoom_key_binding(struct weston_keyboard *keyboard, uint32_t time, |
| 4809 | uint32_t key, void *data) |
Daniel Stone | 325fc2d | 2012-05-30 16:31:58 +0100 | [diff] [blame] | 4810 | { |
Derek Foreman | 8ae2db5 | 2015-07-15 13:00:36 -0500 | [diff] [blame] | 4811 | do_zoom(keyboard->seat, time, key, 0, 0); |
Daniel Stone | 325fc2d | 2012-05-30 16:31:58 +0100 | [diff] [blame] | 4812 | } |
| 4813 | |
| 4814 | static void |
Derek Foreman | 8ae2db5 | 2015-07-15 13:00:36 -0500 | [diff] [blame] | 4815 | terminate_binding(struct weston_keyboard *keyboard, uint32_t time, |
| 4816 | uint32_t key, void *data) |
Kristian Høgsberg | e1a850e | 2011-12-19 15:18:05 -0500 | [diff] [blame] | 4817 | { |
Kristian Høgsberg | 8334bc1 | 2012-01-03 10:29:47 -0500 | [diff] [blame] | 4818 | struct weston_compositor *compositor = data; |
Kristian Høgsberg | e1a850e | 2011-12-19 15:18:05 -0500 | [diff] [blame] | 4819 | |
Daniel Stone | 325fc2d | 2012-05-30 16:31:58 +0100 | [diff] [blame] | 4820 | wl_display_terminate(compositor->wl_display); |
Kristian Høgsberg | e1a850e | 2011-12-19 15:18:05 -0500 | [diff] [blame] | 4821 | } |
| 4822 | |
Emilio Pozuelo Monfort | 03251b6 | 2013-11-19 11:37:16 +0100 | [diff] [blame] | 4823 | static void |
Giulio Camuffo | 1959ab8 | 2013-11-14 23:42:52 +0100 | [diff] [blame] | 4824 | rotate_grab_motion(struct weston_pointer_grab *grab, uint32_t time, |
Jonas Ådahl | d251010 | 2014-10-05 21:39:14 +0200 | [diff] [blame] | 4825 | struct weston_pointer_motion_event *event) |
Pekka Paalanen | 460099f | 2012-01-20 16:48:25 +0200 | [diff] [blame] | 4826 | { |
| 4827 | struct rotate_grab *rotate = |
Ander Conselvan de Oliveira | fe0444a | 2012-04-04 17:48:05 +0300 | [diff] [blame] | 4828 | container_of(grab, struct rotate_grab, base.grab); |
Kristian Høgsberg | 02bbabb | 2013-05-06 22:15:05 -0400 | [diff] [blame] | 4829 | struct weston_pointer *pointer = grab->pointer; |
Ander Conselvan de Oliveira | fe0444a | 2012-04-04 17:48:05 +0300 | [diff] [blame] | 4830 | struct shell_surface *shsurf = rotate->base.shsurf; |
John Kåre Alsaker | 490d02a | 2012-09-30 02:57:21 +0200 | [diff] [blame] | 4831 | float cx, cy, dx, dy, cposx, cposy, dposx, dposy, r; |
Ander Conselvan de Oliveira | fe0444a | 2012-04-04 17:48:05 +0300 | [diff] [blame] | 4832 | |
Jonas Ådahl | d251010 | 2014-10-05 21:39:14 +0200 | [diff] [blame] | 4833 | weston_pointer_move(pointer, event); |
Giulio Camuffo | 1959ab8 | 2013-11-14 23:42:52 +0100 | [diff] [blame] | 4834 | |
Ander Conselvan de Oliveira | fe0444a | 2012-04-04 17:48:05 +0300 | [diff] [blame] | 4835 | if (!shsurf) |
| 4836 | return; |
| 4837 | |
Jason Ekstrand | 918f2dd | 2013-12-02 21:01:53 -0600 | [diff] [blame] | 4838 | cx = 0.5f * shsurf->surface->width; |
| 4839 | cy = 0.5f * shsurf->surface->height; |
Pekka Paalanen | 460099f | 2012-01-20 16:48:25 +0200 | [diff] [blame] | 4840 | |
Daniel Stone | 37816df | 2012-05-16 18:45:18 +0100 | [diff] [blame] | 4841 | dx = wl_fixed_to_double(pointer->x) - rotate->center.x; |
| 4842 | dy = wl_fixed_to_double(pointer->y) - rotate->center.y; |
Pekka Paalanen | 460099f | 2012-01-20 16:48:25 +0200 | [diff] [blame] | 4843 | r = sqrtf(dx * dx + dy * dy); |
| 4844 | |
Ander Conselvan de Oliveira | fe0444a | 2012-04-04 17:48:05 +0300 | [diff] [blame] | 4845 | wl_list_remove(&shsurf->rotation.transform.link); |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 4846 | weston_view_geometry_dirty(shsurf->view); |
Pekka Paalanen | 460099f | 2012-01-20 16:48:25 +0200 | [diff] [blame] | 4847 | |
| 4848 | if (r > 20.0f) { |
Pekka Paalanen | 460099f | 2012-01-20 16:48:25 +0200 | [diff] [blame] | 4849 | struct weston_matrix *matrix = |
Ander Conselvan de Oliveira | fe0444a | 2012-04-04 17:48:05 +0300 | [diff] [blame] | 4850 | &shsurf->rotation.transform.matrix; |
Pekka Paalanen | 460099f | 2012-01-20 16:48:25 +0200 | [diff] [blame] | 4851 | |
Kristian Høgsberg | 765e27b | 2012-01-27 13:36:13 -0500 | [diff] [blame] | 4852 | weston_matrix_init(&rotate->rotation); |
Vasily Khoruzhick | 1bbf372 | 2013-01-28 22:40:28 +0300 | [diff] [blame] | 4853 | weston_matrix_rotate_xy(&rotate->rotation, dx / r, dy / r); |
Pekka Paalanen | 460099f | 2012-01-20 16:48:25 +0200 | [diff] [blame] | 4854 | |
| 4855 | weston_matrix_init(matrix); |
Pekka Paalanen | 7b3bd3d | 2012-01-30 14:16:34 +0200 | [diff] [blame] | 4856 | weston_matrix_translate(matrix, -cx, -cy, 0.0f); |
Ander Conselvan de Oliveira | fe0444a | 2012-04-04 17:48:05 +0300 | [diff] [blame] | 4857 | weston_matrix_multiply(matrix, &shsurf->rotation.rotation); |
Kristian Høgsberg | 765e27b | 2012-01-27 13:36:13 -0500 | [diff] [blame] | 4858 | weston_matrix_multiply(matrix, &rotate->rotation); |
Pekka Paalanen | 7b3bd3d | 2012-01-30 14:16:34 +0200 | [diff] [blame] | 4859 | weston_matrix_translate(matrix, cx, cy, 0.0f); |
Pekka Paalanen | 460099f | 2012-01-20 16:48:25 +0200 | [diff] [blame] | 4860 | |
Pekka Paalanen | bc0b7e7 | 2012-01-24 09:53:37 +0200 | [diff] [blame] | 4861 | wl_list_insert( |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 4862 | &shsurf->view->geometry.transformation_list, |
Ander Conselvan de Oliveira | fe0444a | 2012-04-04 17:48:05 +0300 | [diff] [blame] | 4863 | &shsurf->rotation.transform.link); |
Pekka Paalanen | 460099f | 2012-01-20 16:48:25 +0200 | [diff] [blame] | 4864 | } else { |
Ander Conselvan de Oliveira | fe0444a | 2012-04-04 17:48:05 +0300 | [diff] [blame] | 4865 | wl_list_init(&shsurf->rotation.transform.link); |
| 4866 | weston_matrix_init(&shsurf->rotation.rotation); |
Kristian Høgsberg | 765e27b | 2012-01-27 13:36:13 -0500 | [diff] [blame] | 4867 | weston_matrix_init(&rotate->rotation); |
Pekka Paalanen | 460099f | 2012-01-20 16:48:25 +0200 | [diff] [blame] | 4868 | } |
Pekka Paalanen | b45ac5e | 2012-02-09 15:58:44 +0200 | [diff] [blame] | 4869 | |
Rafal Mielniczuk | 2d7ab82 | 2012-03-22 22:22:04 +0100 | [diff] [blame] | 4870 | /* We need to adjust the position of the surface |
| 4871 | * in case it was resized in a rotated state before */ |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 4872 | cposx = shsurf->view->geometry.x + cx; |
| 4873 | cposy = shsurf->view->geometry.y + cy; |
Rafal Mielniczuk | 2d7ab82 | 2012-03-22 22:22:04 +0100 | [diff] [blame] | 4874 | dposx = rotate->center.x - cposx; |
| 4875 | dposy = rotate->center.y - cposy; |
| 4876 | if (dposx != 0.0f || dposy != 0.0f) { |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 4877 | weston_view_set_position(shsurf->view, |
| 4878 | shsurf->view->geometry.x + dposx, |
| 4879 | shsurf->view->geometry.y + dposy); |
Rafal Mielniczuk | 2d7ab82 | 2012-03-22 22:22:04 +0100 | [diff] [blame] | 4880 | } |
| 4881 | |
Derek Foreman | 4b1a0a1 | 2014-09-10 15:37:33 -0500 | [diff] [blame] | 4882 | /* Repaint implies weston_view_update_transform(), which |
Pekka Paalanen | b45ac5e | 2012-02-09 15:58:44 +0200 | [diff] [blame] | 4883 | * lazily applies the damage due to rotation update. |
| 4884 | */ |
Ander Conselvan de Oliveira | fe0444a | 2012-04-04 17:48:05 +0300 | [diff] [blame] | 4885 | weston_compositor_schedule_repaint(shsurf->surface->compositor); |
Pekka Paalanen | 460099f | 2012-01-20 16:48:25 +0200 | [diff] [blame] | 4886 | } |
| 4887 | |
| 4888 | static void |
Kristian Høgsberg | 02bbabb | 2013-05-06 22:15:05 -0400 | [diff] [blame] | 4889 | rotate_grab_button(struct weston_pointer_grab *grab, |
| 4890 | uint32_t time, uint32_t button, uint32_t state_w) |
Pekka Paalanen | 460099f | 2012-01-20 16:48:25 +0200 | [diff] [blame] | 4891 | { |
| 4892 | struct rotate_grab *rotate = |
Ander Conselvan de Oliveira | fe0444a | 2012-04-04 17:48:05 +0300 | [diff] [blame] | 4893 | container_of(grab, struct rotate_grab, base.grab); |
Kristian Høgsberg | 02bbabb | 2013-05-06 22:15:05 -0400 | [diff] [blame] | 4894 | struct weston_pointer *pointer = grab->pointer; |
Ander Conselvan de Oliveira | fe0444a | 2012-04-04 17:48:05 +0300 | [diff] [blame] | 4895 | struct shell_surface *shsurf = rotate->base.shsurf; |
Daniel Stone | 4dbadb1 | 2012-05-30 16:31:51 +0100 | [diff] [blame] | 4896 | enum wl_pointer_button_state state = state_w; |
Pekka Paalanen | 460099f | 2012-01-20 16:48:25 +0200 | [diff] [blame] | 4897 | |
Daniel Stone | 4dbadb1 | 2012-05-30 16:31:51 +0100 | [diff] [blame] | 4898 | if (pointer->button_count == 0 && |
| 4899 | state == WL_POINTER_BUTTON_STATE_RELEASED) { |
Ander Conselvan de Oliveira | fe0444a | 2012-04-04 17:48:05 +0300 | [diff] [blame] | 4900 | if (shsurf) |
| 4901 | weston_matrix_multiply(&shsurf->rotation.rotation, |
| 4902 | &rotate->rotation); |
Ander Conselvan de Oliveira | b9d2a0f | 2012-06-28 18:08:05 +0300 | [diff] [blame] | 4903 | shell_grab_end(&rotate->base); |
Pekka Paalanen | 460099f | 2012-01-20 16:48:25 +0200 | [diff] [blame] | 4904 | free(rotate); |
| 4905 | } |
| 4906 | } |
| 4907 | |
Jonas Ådahl | 1ea343e | 2013-10-25 23:18:05 +0200 | [diff] [blame] | 4908 | static void |
| 4909 | rotate_grab_cancel(struct weston_pointer_grab *grab) |
| 4910 | { |
| 4911 | struct rotate_grab *rotate = |
| 4912 | container_of(grab, struct rotate_grab, base.grab); |
| 4913 | |
| 4914 | shell_grab_end(&rotate->base); |
| 4915 | free(rotate); |
| 4916 | } |
| 4917 | |
Kristian Høgsberg | 02bbabb | 2013-05-06 22:15:05 -0400 | [diff] [blame] | 4918 | static const struct weston_pointer_grab_interface rotate_grab_interface = { |
Pekka Paalanen | 460099f | 2012-01-20 16:48:25 +0200 | [diff] [blame] | 4919 | noop_grab_focus, |
| 4920 | rotate_grab_motion, |
| 4921 | rotate_grab_button, |
Jonas Ådahl | 0336ca0 | 2014-10-04 16:28:29 +0200 | [diff] [blame] | 4922 | noop_grab_axis, |
Jonas Ådahl | 1ea343e | 2013-10-25 23:18:05 +0200 | [diff] [blame] | 4923 | rotate_grab_cancel, |
Pekka Paalanen | 460099f | 2012-01-20 16:48:25 +0200 | [diff] [blame] | 4924 | }; |
| 4925 | |
| 4926 | static void |
Derek Foreman | 74de469 | 2015-07-15 13:00:39 -0500 | [diff] [blame] | 4927 | surface_rotate(struct shell_surface *surface, struct weston_pointer *pointer) |
Pekka Paalanen | 460099f | 2012-01-20 16:48:25 +0200 | [diff] [blame] | 4928 | { |
Pekka Paalanen | 460099f | 2012-01-20 16:48:25 +0200 | [diff] [blame] | 4929 | struct rotate_grab *rotate; |
John Kåre Alsaker | 490d02a | 2012-09-30 02:57:21 +0200 | [diff] [blame] | 4930 | float dx, dy; |
| 4931 | float r; |
Pekka Paalanen | 460099f | 2012-01-20 16:48:25 +0200 | [diff] [blame] | 4932 | |
Derek Foreman | 45a7c27 | 2015-09-11 14:27:40 -0500 | [diff] [blame] | 4933 | surface = find_toplevel_surface(surface); |
| 4934 | |
Pekka Paalanen | 460099f | 2012-01-20 16:48:25 +0200 | [diff] [blame] | 4935 | rotate = malloc(sizeof *rotate); |
| 4936 | if (!rotate) |
| 4937 | return; |
| 4938 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 4939 | weston_view_to_global_float(surface->view, |
Jason Ekstrand | 918f2dd | 2013-12-02 21:01:53 -0600 | [diff] [blame] | 4940 | surface->surface->width * 0.5f, |
| 4941 | surface->surface->height * 0.5f, |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 4942 | &rotate->center.x, &rotate->center.y); |
Pekka Paalanen | 460099f | 2012-01-20 16:48:25 +0200 | [diff] [blame] | 4943 | |
Derek Foreman | 74de469 | 2015-07-15 13:00:39 -0500 | [diff] [blame] | 4944 | dx = wl_fixed_to_double(pointer->x) - rotate->center.x; |
| 4945 | dy = wl_fixed_to_double(pointer->y) - rotate->center.y; |
Kristian Høgsberg | 765e27b | 2012-01-27 13:36:13 -0500 | [diff] [blame] | 4946 | r = sqrtf(dx * dx + dy * dy); |
| 4947 | if (r > 20.0f) { |
| 4948 | struct weston_matrix inverse; |
| 4949 | |
| 4950 | weston_matrix_init(&inverse); |
Vasily Khoruzhick | 1bbf372 | 2013-01-28 22:40:28 +0300 | [diff] [blame] | 4951 | weston_matrix_rotate_xy(&inverse, dx / r, -dy / r); |
Kristian Høgsberg | 765e27b | 2012-01-27 13:36:13 -0500 | [diff] [blame] | 4952 | weston_matrix_multiply(&surface->rotation.rotation, &inverse); |
Rafal Mielniczuk | 2d7ab82 | 2012-03-22 22:22:04 +0100 | [diff] [blame] | 4953 | |
| 4954 | weston_matrix_init(&rotate->rotation); |
Vasily Khoruzhick | 1bbf372 | 2013-01-28 22:40:28 +0300 | [diff] [blame] | 4955 | weston_matrix_rotate_xy(&rotate->rotation, dx / r, dy / r); |
Kristian Høgsberg | 765e27b | 2012-01-27 13:36:13 -0500 | [diff] [blame] | 4956 | } else { |
| 4957 | weston_matrix_init(&surface->rotation.rotation); |
| 4958 | weston_matrix_init(&rotate->rotation); |
| 4959 | } |
| 4960 | |
Ander Conselvan de Oliveira | b9d2a0f | 2012-06-28 18:08:05 +0300 | [diff] [blame] | 4961 | shell_grab_start(&rotate->base, &rotate_grab_interface, surface, |
Jonas Ådahl | 6d6fb61 | 2015-11-17 16:00:33 +0800 | [diff] [blame] | 4962 | pointer, WESTON_DESKTOP_SHELL_CURSOR_ARROW); |
Pekka Paalanen | 460099f | 2012-01-20 16:48:25 +0200 | [diff] [blame] | 4963 | } |
| 4964 | |
| 4965 | static void |
Derek Foreman | 8ae2db5 | 2015-07-15 13:00:36 -0500 | [diff] [blame] | 4966 | 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] | 4967 | void *data) |
| 4968 | { |
Rafal Mielniczuk | b2917a2 | 2014-01-05 20:04:59 +0100 | [diff] [blame] | 4969 | struct weston_surface *focus; |
Pekka Paalanen | 01388e2 | 2013-04-25 13:57:44 +0300 | [diff] [blame] | 4970 | struct weston_surface *base_surface; |
Kristian Høgsberg | 0c36903 | 2013-02-14 21:31:44 -0500 | [diff] [blame] | 4971 | struct shell_surface *surface; |
| 4972 | |
Derek Foreman | 8ae2db5 | 2015-07-15 13:00:36 -0500 | [diff] [blame] | 4973 | if (pointer->focus == NULL) |
Rafal Mielniczuk | b2917a2 | 2014-01-05 20:04:59 +0100 | [diff] [blame] | 4974 | return; |
| 4975 | |
Derek Foreman | 8ae2db5 | 2015-07-15 13:00:36 -0500 | [diff] [blame] | 4976 | focus = pointer->focus->surface; |
Rafal Mielniczuk | b2917a2 | 2014-01-05 20:04:59 +0100 | [diff] [blame] | 4977 | |
Pekka Paalanen | 01388e2 | 2013-04-25 13:57:44 +0300 | [diff] [blame] | 4978 | base_surface = weston_surface_get_main_surface(focus); |
Kristian Høgsberg | 0c36903 | 2013-02-14 21:31:44 -0500 | [diff] [blame] | 4979 | if (base_surface == NULL) |
| 4980 | return; |
| 4981 | |
| 4982 | surface = get_shell_surface(base_surface); |
Rafael Antognolli | 03b1659 | 2013-12-03 15:35:42 -0200 | [diff] [blame] | 4983 | if (surface == NULL || surface->state.fullscreen || |
| 4984 | surface->state.maximized) |
Kristian Høgsberg | 0c36903 | 2013-02-14 21:31:44 -0500 | [diff] [blame] | 4985 | return; |
| 4986 | |
Derek Foreman | 74de469 | 2015-07-15 13:00:39 -0500 | [diff] [blame] | 4987 | surface_rotate(surface, pointer); |
Kristian Høgsberg | 0c36903 | 2013-02-14 21:31:44 -0500 | [diff] [blame] | 4988 | } |
| 4989 | |
Emilio Pozuelo Monfort | 9e7c759 | 2014-01-30 14:01:10 +0100 | [diff] [blame] | 4990 | /* Move all fullscreen layers down to the current workspace and hide their |
| 4991 | * black views. The surfaces' state is set to both fullscreen and lowered, |
| 4992 | * and this is reversed when such a surface is re-configured, see |
| 4993 | * shell_configure_fullscreen() and shell_ensure_fullscreen_black_view(). |
| 4994 | * |
Mario Kleiner | 9f4d655 | 2015-06-21 21:25:08 +0200 | [diff] [blame] | 4995 | * lowering_output = NULL - Lower on all outputs, else only lower on the |
| 4996 | * specified output. |
| 4997 | * |
Emilio Pozuelo Monfort | 9e7c759 | 2014-01-30 14:01:10 +0100 | [diff] [blame] | 4998 | * This should be used when implementing shell-wide overlays, such as |
Philip Withnall | 83ffd9d | 2013-11-25 18:01:42 +0000 | [diff] [blame] | 4999 | * the alt-tab switcher, which need to de-promote fullscreen layers. */ |
Kristian Høgsberg | 1ef2313 | 2013-12-04 00:20:01 -0800 | [diff] [blame] | 5000 | void |
Mario Kleiner | 9f4d655 | 2015-06-21 21:25:08 +0200 | [diff] [blame] | 5001 | lower_fullscreen_layer(struct desktop_shell *shell, |
| 5002 | struct weston_output *lowering_output) |
Kristian Høgsberg | b0d8e77 | 2012-06-18 16:34:58 -0400 | [diff] [blame] | 5003 | { |
| 5004 | struct workspace *ws; |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 5005 | struct weston_view *view, *prev; |
Kristian Høgsberg | b0d8e77 | 2012-06-18 16:34:58 -0400 | [diff] [blame] | 5006 | |
| 5007 | ws = get_current_workspace(shell); |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 5008 | wl_list_for_each_reverse_safe(view, prev, |
Giulio Camuffo | 412e6a5 | 2014-07-09 22:12:56 +0300 | [diff] [blame] | 5009 | &shell->fullscreen_layer.view_list.link, |
| 5010 | layer_link.link) { |
Emilio Pozuelo Monfort | 9e7c759 | 2014-01-30 14:01:10 +0100 | [diff] [blame] | 5011 | struct shell_surface *shsurf = get_shell_surface(view->surface); |
| 5012 | |
| 5013 | if (!shsurf) |
| 5014 | continue; |
| 5015 | |
Mario Kleiner | 9f4d655 | 2015-06-21 21:25:08 +0200 | [diff] [blame] | 5016 | /* Only lower surfaces which have lowering_output as their fullscreen |
| 5017 | * output, unless a NULL output asks for lowering on all outputs. |
| 5018 | */ |
| 5019 | if (lowering_output && (shsurf->fullscreen_output != lowering_output)) |
| 5020 | continue; |
| 5021 | |
Emilio Pozuelo Monfort | 9e7c759 | 2014-01-30 14:01:10 +0100 | [diff] [blame] | 5022 | /* We can have a non-fullscreen popup for a fullscreen surface |
| 5023 | * in the fullscreen layer. */ |
| 5024 | if (shsurf->state.fullscreen) { |
| 5025 | /* Hide the black view */ |
Giulio Camuffo | 412e6a5 | 2014-07-09 22:12:56 +0300 | [diff] [blame] | 5026 | weston_layer_entry_remove(&shsurf->fullscreen.black_view->layer_link); |
| 5027 | wl_list_init(&shsurf->fullscreen.black_view->layer_link.link); |
Kristian Høgsberg | c991513 | 2014-05-09 16:24:07 -0700 | [diff] [blame] | 5028 | weston_view_damage_below(shsurf->fullscreen.black_view); |
| 5029 | |
Emilio Pozuelo Monfort | 9e7c759 | 2014-01-30 14:01:10 +0100 | [diff] [blame] | 5030 | } |
| 5031 | |
| 5032 | /* Lower the view to the workspace layer */ |
Giulio Camuffo | 412e6a5 | 2014-07-09 22:12:56 +0300 | [diff] [blame] | 5033 | weston_layer_entry_remove(&view->layer_link); |
| 5034 | weston_layer_entry_insert(&ws->layer.view_list, &view->layer_link); |
Philip Withnall | 83ffd9d | 2013-11-25 18:01:42 +0000 | [diff] [blame] | 5035 | weston_view_damage_below(view); |
| 5036 | weston_surface_damage(view->surface); |
Emilio Pozuelo Monfort | 9e7c759 | 2014-01-30 14:01:10 +0100 | [diff] [blame] | 5037 | |
| 5038 | shsurf->state.lowered = true; |
Philip Withnall | 83ffd9d | 2013-11-25 18:01:42 +0000 | [diff] [blame] | 5039 | } |
Kristian Høgsberg | b0d8e77 | 2012-06-18 16:34:58 -0400 | [diff] [blame] | 5040 | } |
| 5041 | |
Kristian Høgsberg | 1ef2313 | 2013-12-04 00:20:01 -0800 | [diff] [blame] | 5042 | void |
Tiago Vignatti | be14326 | 2012-04-16 17:31:41 +0300 | [diff] [blame] | 5043 | activate(struct desktop_shell *shell, struct weston_surface *es, |
Emilio Pozuelo Monfort | 9e7c759 | 2014-01-30 14:01:10 +0100 | [diff] [blame] | 5044 | struct weston_seat *seat, bool configure) |
Kristian Høgsberg | 7584062 | 2011-09-06 13:48:16 -0400 | [diff] [blame] | 5045 | { |
Pekka Paalanen | 01388e2 | 2013-04-25 13:57:44 +0300 | [diff] [blame] | 5046 | struct weston_surface *main_surface; |
Kristian Høgsberg | 2f5faff | 2012-07-31 16:36:34 -0400 | [diff] [blame] | 5047 | struct focus_state *state; |
Jonas Ådahl | 8538b22 | 2012-08-29 22:13:03 +0200 | [diff] [blame] | 5048 | struct workspace *ws; |
Louis-Francis Ratté-Boulianne | b482dbd | 2013-11-19 11:37:11 +0100 | [diff] [blame] | 5049 | struct weston_surface *old_es; |
Rafael Antognolli | 03b1659 | 2013-12-03 15:35:42 -0200 | [diff] [blame] | 5050 | struct shell_surface *shsurf; |
Kristian Høgsberg | 7584062 | 2011-09-06 13:48:16 -0400 | [diff] [blame] | 5051 | |
Pekka Paalanen | 01388e2 | 2013-04-25 13:57:44 +0300 | [diff] [blame] | 5052 | main_surface = weston_surface_get_main_surface(es); |
Mario Kleiner | 9f4d655 | 2015-06-21 21:25:08 +0200 | [diff] [blame] | 5053 | shsurf = get_shell_surface(main_surface); |
| 5054 | assert(shsurf); |
| 5055 | |
| 5056 | /* Only demote fullscreen surfaces on the output of activated shsurf. |
| 5057 | * Leave fullscreen surfaces on unrelated outputs alone. */ |
| 5058 | lower_fullscreen_layer(shell, shsurf->output); |
Pekka Paalanen | 01388e2 | 2013-04-25 13:57:44 +0300 | [diff] [blame] | 5059 | |
Daniel Stone | 37816df | 2012-05-16 18:45:18 +0100 | [diff] [blame] | 5060 | weston_surface_activate(es, seat); |
Kristian Høgsberg | 7584062 | 2011-09-06 13:48:16 -0400 | [diff] [blame] | 5061 | |
Jonas Ådahl | 8538b22 | 2012-08-29 22:13:03 +0200 | [diff] [blame] | 5062 | state = ensure_focus_state(shell, seat); |
| 5063 | if (state == NULL) |
| 5064 | return; |
Kristian Høgsberg | 2f5faff | 2012-07-31 16:36:34 -0400 | [diff] [blame] | 5065 | |
Louis-Francis Ratté-Boulianne | b482dbd | 2013-11-19 11:37:11 +0100 | [diff] [blame] | 5066 | old_es = state->keyboard_focus; |
Kristian Høgsberg | d500bf1 | 2014-01-22 12:25:20 -0800 | [diff] [blame] | 5067 | focus_state_set_focus(state, es); |
Kristian Høgsberg | 2f5faff | 2012-07-31 16:36:34 -0400 | [diff] [blame] | 5068 | |
Emilio Pozuelo Monfort | 9e7c759 | 2014-01-30 14:01:10 +0100 | [diff] [blame] | 5069 | if (shsurf->state.fullscreen && configure) |
Rafael Antognolli | 03b1659 | 2013-12-03 15:35:42 -0200 | [diff] [blame] | 5070 | shell_configure_fullscreen(shsurf); |
| 5071 | else |
Mario Kleiner | 492c12f | 2015-06-21 21:25:12 +0200 | [diff] [blame] | 5072 | restore_output_mode(shsurf->output); |
Louis-Francis Ratté-Boulianne | b482dbd | 2013-11-19 11:37:11 +0100 | [diff] [blame] | 5073 | |
Emilio Pozuelo Monfort | 7908bff | 2014-01-30 13:49:39 +0100 | [diff] [blame] | 5074 | /* Update the surface’s layer. This brings it to the top of the stacking |
| 5075 | * order as appropriate. */ |
| 5076 | shell_surface_update_layer(shsurf); |
| 5077 | |
Philip Withnall | 83ffd9d | 2013-11-25 18:01:42 +0000 | [diff] [blame] | 5078 | if (shell->focus_animation_type != ANIMATION_NONE) { |
| 5079 | ws = get_current_workspace(shell); |
Louis-Francis Ratté-Boulianne | b482dbd | 2013-11-19 11:37:11 +0100 | [diff] [blame] | 5080 | 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] | 5081 | } |
Kristian Høgsberg | 7584062 | 2011-09-06 13:48:16 -0400 | [diff] [blame] | 5082 | } |
| 5083 | |
Alex Wu | 2185843 | 2012-04-01 20:13:08 +0800 | [diff] [blame] | 5084 | /* no-op func for checking black surface */ |
| 5085 | static void |
Jason Ekstrand | 918f2dd | 2013-12-02 21:01:53 -0600 | [diff] [blame] | 5086 | 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] | 5087 | { |
| 5088 | } |
| 5089 | |
Quentin Glidic | c0d79ce | 2013-01-29 14:16:13 +0100 | [diff] [blame] | 5090 | static bool |
Alex Wu | 2185843 | 2012-04-01 20:13:08 +0800 | [diff] [blame] | 5091 | is_black_surface (struct weston_surface *es, struct weston_surface **fs_surface) |
| 5092 | { |
| 5093 | if (es->configure == black_surface_configure) { |
| 5094 | if (fs_surface) |
Giulio Camuffo | 7fe01b1 | 2013-03-28 18:02:42 +0100 | [diff] [blame] | 5095 | *fs_surface = (struct weston_surface *)es->configure_private; |
Alex Wu | 2185843 | 2012-04-01 20:13:08 +0800 | [diff] [blame] | 5096 | return true; |
| 5097 | } |
| 5098 | return false; |
| 5099 | } |
| 5100 | |
Kristian Høgsberg | 7584062 | 2011-09-06 13:48:16 -0400 | [diff] [blame] | 5101 | static void |
Neil Roberts | a28c693 | 2013-10-03 16:43:04 +0100 | [diff] [blame] | 5102 | activate_binding(struct weston_seat *seat, |
| 5103 | struct desktop_shell *shell, |
Jonas Ådahl | cd0f1ac | 2015-06-26 12:37:56 +0800 | [diff] [blame] | 5104 | struct weston_view *focus_view) |
Kristian Høgsberg | e1a850e | 2011-12-19 15:18:05 -0500 | [diff] [blame] | 5105 | { |
Jonas Ådahl | cd0f1ac | 2015-06-26 12:37:56 +0800 | [diff] [blame] | 5106 | struct weston_surface *focus; |
Pekka Paalanen | 01388e2 | 2013-04-25 13:57:44 +0300 | [diff] [blame] | 5107 | struct weston_surface *main_surface; |
Kristian Høgsberg | e1a850e | 2011-12-19 15:18:05 -0500 | [diff] [blame] | 5108 | |
Jonas Ådahl | cd0f1ac | 2015-06-26 12:37:56 +0800 | [diff] [blame] | 5109 | focus = focus_view->surface; |
Alex Wu | 9c35e6b | 2012-03-05 14:13:13 +0800 | [diff] [blame] | 5110 | |
Pekka Paalanen | 01388e2 | 2013-04-25 13:57:44 +0300 | [diff] [blame] | 5111 | if (is_black_surface(focus, &main_surface)) |
| 5112 | focus = main_surface; |
Alex Wu | 4539b08 | 2012-03-01 12:57:46 +0800 | [diff] [blame] | 5113 | |
Pekka Paalanen | 01388e2 | 2013-04-25 13:57:44 +0300 | [diff] [blame] | 5114 | main_surface = weston_surface_get_main_surface(focus); |
| 5115 | if (get_shell_surface_type(main_surface) == SHELL_SURFACE_NONE) |
Kristian Høgsberg | 0636ac3 | 2012-06-27 10:22:15 -0400 | [diff] [blame] | 5116 | return; |
Kristian Høgsberg | 85b2e4b | 2012-06-21 16:49:42 -0400 | [diff] [blame] | 5117 | |
Emilio Pozuelo Monfort | 9e7c759 | 2014-01-30 14:01:10 +0100 | [diff] [blame] | 5118 | activate(shell, focus, seat, true); |
Neil Roberts | a28c693 | 2013-10-03 16:43:04 +0100 | [diff] [blame] | 5119 | } |
| 5120 | |
| 5121 | static void |
Derek Foreman | 8ae2db5 | 2015-07-15 13:00:36 -0500 | [diff] [blame] | 5122 | click_to_activate_binding(struct weston_pointer *pointer, uint32_t time, |
| 5123 | uint32_t button, void *data) |
Neil Roberts | a28c693 | 2013-10-03 16:43:04 +0100 | [diff] [blame] | 5124 | { |
Derek Foreman | 8ae2db5 | 2015-07-15 13:00:36 -0500 | [diff] [blame] | 5125 | if (pointer->grab != &pointer->default_grab) |
Neil Roberts | a28c693 | 2013-10-03 16:43:04 +0100 | [diff] [blame] | 5126 | return; |
Derek Foreman | 8ae2db5 | 2015-07-15 13:00:36 -0500 | [diff] [blame] | 5127 | if (pointer->focus == NULL) |
Kristian Høgsberg | 7c4f6cc | 2014-01-01 16:28:32 -0800 | [diff] [blame] | 5128 | return; |
Neil Roberts | a28c693 | 2013-10-03 16:43:04 +0100 | [diff] [blame] | 5129 | |
Jonas Ådahl | cd0f1ac | 2015-06-26 12:37:56 +0800 | [diff] [blame] | 5130 | activate_binding(pointer->seat, data, pointer->focus); |
Neil Roberts | a28c693 | 2013-10-03 16:43:04 +0100 | [diff] [blame] | 5131 | } |
| 5132 | |
| 5133 | static void |
Derek Foreman | 8ae2db5 | 2015-07-15 13:00:36 -0500 | [diff] [blame] | 5134 | touch_to_activate_binding(struct weston_touch *touch, uint32_t time, |
| 5135 | void *data) |
Neil Roberts | a28c693 | 2013-10-03 16:43:04 +0100 | [diff] [blame] | 5136 | { |
Derek Foreman | 8ae2db5 | 2015-07-15 13:00:36 -0500 | [diff] [blame] | 5137 | if (touch->grab != &touch->default_grab) |
Neil Roberts | a28c693 | 2013-10-03 16:43:04 +0100 | [diff] [blame] | 5138 | return; |
Derek Foreman | 8ae2db5 | 2015-07-15 13:00:36 -0500 | [diff] [blame] | 5139 | if (touch->focus == NULL) |
Kristian Høgsberg | 0ed6750 | 2014-01-02 23:00:11 -0800 | [diff] [blame] | 5140 | return; |
Neil Roberts | a28c693 | 2013-10-03 16:43:04 +0100 | [diff] [blame] | 5141 | |
Jonas Ådahl | cd0f1ac | 2015-06-26 12:37:56 +0800 | [diff] [blame] | 5142 | activate_binding(touch->seat, data, touch->focus); |
Kristian Høgsberg | e1a850e | 2011-12-19 15:18:05 -0500 | [diff] [blame] | 5143 | } |
| 5144 | |
| 5145 | static void |
Neil Roberts | b4a9170 | 2014-04-09 16:33:32 +0100 | [diff] [blame] | 5146 | unfocus_all_seats(struct desktop_shell *shell) |
| 5147 | { |
| 5148 | struct weston_seat *seat, *next; |
| 5149 | |
| 5150 | wl_list_for_each_safe(seat, next, &shell->compositor->seat_list, link) { |
Derek Foreman | 1281a36 | 2015-07-31 16:55:32 -0500 | [diff] [blame] | 5151 | struct weston_keyboard *keyboard = |
| 5152 | weston_seat_get_keyboard(seat); |
| 5153 | |
| 5154 | if (!keyboard) |
Neil Roberts | b4a9170 | 2014-04-09 16:33:32 +0100 | [diff] [blame] | 5155 | continue; |
| 5156 | |
Derek Foreman | 1281a36 | 2015-07-31 16:55:32 -0500 | [diff] [blame] | 5157 | weston_keyboard_set_focus(keyboard, NULL); |
Neil Roberts | b4a9170 | 2014-04-09 16:33:32 +0100 | [diff] [blame] | 5158 | } |
| 5159 | } |
| 5160 | |
| 5161 | static void |
Ander Conselvan de Oliveira | 19d10ef | 2013-02-21 18:35:20 +0200 | [diff] [blame] | 5162 | lock(struct desktop_shell *shell) |
Kristian Høgsberg | 02ec0a5 | 2011-04-23 13:04:11 -0400 | [diff] [blame] | 5163 | { |
Kristian Høgsberg | 4476aaf | 2012-06-25 14:03:13 -0400 | [diff] [blame] | 5164 | struct workspace *ws = get_current_workspace(shell); |
Pekka Paalanen | f0fc70d | 2011-11-15 13:34:54 +0200 | [diff] [blame] | 5165 | |
Tiago Vignatti | 8e53c7f | 2012-02-29 19:53:50 +0200 | [diff] [blame] | 5166 | if (shell->locked) { |
Ander Conselvan de Oliveira | 87524b6 | 2013-02-21 18:35:22 +0200 | [diff] [blame] | 5167 | weston_compositor_sleep(shell->compositor); |
Pekka Paalanen | f0fc70d | 2011-11-15 13:34:54 +0200 | [diff] [blame] | 5168 | return; |
Tiago Vignatti | 8e53c7f | 2012-02-29 19:53:50 +0200 | [diff] [blame] | 5169 | } |
Pekka Paalanen | 9ef3e01 | 2011-11-15 13:34:48 +0200 | [diff] [blame] | 5170 | |
| 5171 | shell->locked = true; |
Pekka Paalanen | f0fc70d | 2011-11-15 13:34:54 +0200 | [diff] [blame] | 5172 | |
Kristian Høgsberg | 3be2ce9 | 2012-02-29 12:42:35 -0500 | [diff] [blame] | 5173 | /* Hide all surfaces by removing the fullscreen, panel and |
| 5174 | * toplevel layers. This way nothing else can show or receive |
| 5175 | * input events while we are locked. */ |
Pekka Paalanen | f0fc70d | 2011-11-15 13:34:54 +0200 | [diff] [blame] | 5176 | |
Kristian Høgsberg | 3be2ce9 | 2012-02-29 12:42:35 -0500 | [diff] [blame] | 5177 | wl_list_remove(&shell->panel_layer.link); |
Kristian Høgsberg | 3be2ce9 | 2012-02-29 12:42:35 -0500 | [diff] [blame] | 5178 | wl_list_remove(&shell->fullscreen_layer.link); |
Philipp Brüschweiler | 711fda8 | 2012-08-09 18:50:43 +0200 | [diff] [blame] | 5179 | if (shell->showing_input_panels) |
| 5180 | wl_list_remove(&shell->input_panel_layer.link); |
Kristian Høgsberg | 4476aaf | 2012-06-25 14:03:13 -0400 | [diff] [blame] | 5181 | wl_list_remove(&ws->layer.link); |
Kristian Høgsberg | 3be2ce9 | 2012-02-29 12:42:35 -0500 | [diff] [blame] | 5182 | wl_list_insert(&shell->compositor->cursor_layer.link, |
| 5183 | &shell->lock_layer.link); |
Pekka Paalanen | f0fc70d | 2011-11-15 13:34:54 +0200 | [diff] [blame] | 5184 | |
Derek Foreman | 004b4a1 | 2015-07-20 16:28:13 -0500 | [diff] [blame] | 5185 | weston_compositor_sleep(shell->compositor); |
| 5186 | |
Neil Roberts | b4a9170 | 2014-04-09 16:33:32 +0100 | [diff] [blame] | 5187 | /* Remove the keyboard focus on all seats. This will be |
| 5188 | * restored to the workspace's saved state via |
| 5189 | * restore_focus_state when the compositor is unlocked */ |
| 5190 | unfocus_all_seats(shell); |
| 5191 | |
Pekka Paalanen | f0fc70d | 2011-11-15 13:34:54 +0200 | [diff] [blame] | 5192 | /* TODO: disable bindings that should not work while locked. */ |
| 5193 | |
| 5194 | /* All this must be undone in resume_desktop(). */ |
Pekka Paalanen | 9ef3e01 | 2011-11-15 13:34:48 +0200 | [diff] [blame] | 5195 | } |
| 5196 | |
| 5197 | static void |
Ander Conselvan de Oliveira | 19d10ef | 2013-02-21 18:35:20 +0200 | [diff] [blame] | 5198 | unlock(struct desktop_shell *shell) |
Pekka Paalanen | 9ef3e01 | 2011-11-15 13:34:48 +0200 | [diff] [blame] | 5199 | { |
Jonas Ådahl | 6d6fb61 | 2015-11-17 16:00:33 +0800 | [diff] [blame] | 5200 | struct wl_resource *shell_resource; |
| 5201 | |
Pekka Paalanen | d81c216 | 2011-11-16 13:47:34 +0200 | [diff] [blame] | 5202 | if (!shell->locked || shell->lock_surface) { |
Ander Conselvan de Oliveira | 87524b6 | 2013-02-21 18:35:22 +0200 | [diff] [blame] | 5203 | shell_fade(shell, FADE_IN); |
Pekka Paalanen | 9ef3e01 | 2011-11-15 13:34:48 +0200 | [diff] [blame] | 5204 | return; |
| 5205 | } |
| 5206 | |
| 5207 | /* If desktop-shell client has gone away, unlock immediately. */ |
| 5208 | if (!shell->child.desktop_shell) { |
Pekka Paalanen | f0fc70d | 2011-11-15 13:34:54 +0200 | [diff] [blame] | 5209 | resume_desktop(shell); |
Pekka Paalanen | 9ef3e01 | 2011-11-15 13:34:48 +0200 | [diff] [blame] | 5210 | return; |
| 5211 | } |
| 5212 | |
| 5213 | if (shell->prepare_event_sent) |
| 5214 | return; |
| 5215 | |
Jonas Ådahl | 6d6fb61 | 2015-11-17 16:00:33 +0800 | [diff] [blame] | 5216 | shell_resource = shell->child.desktop_shell; |
| 5217 | weston_desktop_shell_send_prepare_lock_surface(shell_resource); |
Pekka Paalanen | 9ef3e01 | 2011-11-15 13:34:48 +0200 | [diff] [blame] | 5218 | shell->prepare_event_sent = true; |
Kristian Høgsberg | 02ec0a5 | 2011-04-23 13:04:11 -0400 | [diff] [blame] | 5219 | } |
| 5220 | |
| 5221 | static void |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 5222 | shell_fade_done(struct weston_view_animation *animation, void *data) |
Ander Conselvan de Oliveira | 19d10ef | 2013-02-21 18:35:20 +0200 | [diff] [blame] | 5223 | { |
| 5224 | struct desktop_shell *shell = data; |
| 5225 | |
| 5226 | shell->fade.animation = NULL; |
| 5227 | |
| 5228 | switch (shell->fade.type) { |
| 5229 | case FADE_IN: |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 5230 | weston_surface_destroy(shell->fade.view->surface); |
| 5231 | shell->fade.view = NULL; |
Ander Conselvan de Oliveira | 19d10ef | 2013-02-21 18:35:20 +0200 | [diff] [blame] | 5232 | break; |
| 5233 | case FADE_OUT: |
Ander Conselvan de Oliveira | 19d10ef | 2013-02-21 18:35:20 +0200 | [diff] [blame] | 5234 | lock(shell); |
| 5235 | break; |
Philip Withnall | 4a86a0a | 2013-11-25 18:01:32 +0000 | [diff] [blame] | 5236 | default: |
| 5237 | break; |
Ander Conselvan de Oliveira | 19d10ef | 2013-02-21 18:35:20 +0200 | [diff] [blame] | 5238 | } |
| 5239 | } |
| 5240 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 5241 | static struct weston_view * |
Pekka Paalanen | 79346ab | 2013-05-22 18:03:09 +0300 | [diff] [blame] | 5242 | shell_fade_create_surface(struct desktop_shell *shell) |
Ander Conselvan de Oliveira | 19d10ef | 2013-02-21 18:35:20 +0200 | [diff] [blame] | 5243 | { |
| 5244 | struct weston_compositor *compositor = shell->compositor; |
| 5245 | struct weston_surface *surface; |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 5246 | struct weston_view *view; |
Pekka Paalanen | 79346ab | 2013-05-22 18:03:09 +0300 | [diff] [blame] | 5247 | |
| 5248 | surface = weston_surface_create(compositor); |
| 5249 | if (!surface) |
| 5250 | return NULL; |
| 5251 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 5252 | view = weston_view_create(surface); |
| 5253 | if (!view) { |
| 5254 | weston_surface_destroy(surface); |
| 5255 | return NULL; |
| 5256 | } |
| 5257 | |
Jason Ekstrand | 5c11a33 | 2013-12-04 20:32:03 -0600 | [diff] [blame] | 5258 | weston_surface_set_size(surface, 8192, 8192); |
Jason Ekstrand | 918f2dd | 2013-12-02 21:01:53 -0600 | [diff] [blame] | 5259 | weston_view_set_position(view, 0, 0); |
Pekka Paalanen | 79346ab | 2013-05-22 18:03:09 +0300 | [diff] [blame] | 5260 | 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] | 5261 | weston_layer_entry_insert(&compositor->fade_layer.view_list, |
| 5262 | &view->layer_link); |
Pekka Paalanen | 79346ab | 2013-05-22 18:03:09 +0300 | [diff] [blame] | 5263 | pixman_region32_init(&surface->input); |
| 5264 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 5265 | return view; |
Pekka Paalanen | 79346ab | 2013-05-22 18:03:09 +0300 | [diff] [blame] | 5266 | } |
| 5267 | |
| 5268 | static void |
| 5269 | shell_fade(struct desktop_shell *shell, enum fade_type type) |
| 5270 | { |
Ander Conselvan de Oliveira | 19d10ef | 2013-02-21 18:35:20 +0200 | [diff] [blame] | 5271 | float tint; |
| 5272 | |
| 5273 | switch (type) { |
| 5274 | case FADE_IN: |
| 5275 | tint = 0.0; |
| 5276 | break; |
| 5277 | case FADE_OUT: |
| 5278 | tint = 1.0; |
| 5279 | break; |
| 5280 | default: |
| 5281 | weston_log("shell: invalid fade type\n"); |
| 5282 | return; |
| 5283 | } |
| 5284 | |
| 5285 | shell->fade.type = type; |
| 5286 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 5287 | if (shell->fade.view == NULL) { |
| 5288 | shell->fade.view = shell_fade_create_surface(shell); |
| 5289 | if (!shell->fade.view) |
Ander Conselvan de Oliveira | 19d10ef | 2013-02-21 18:35:20 +0200 | [diff] [blame] | 5290 | return; |
| 5291 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 5292 | shell->fade.view->alpha = 1.0 - tint; |
| 5293 | weston_view_update_transform(shell->fade.view); |
Ander Conselvan de Oliveira | 19d10ef | 2013-02-21 18:35:20 +0200 | [diff] [blame] | 5294 | } |
| 5295 | |
Kristian Høgsberg | 87d3b61 | 2014-01-19 21:48:10 -0800 | [diff] [blame] | 5296 | if (shell->fade.view->output == NULL) { |
| 5297 | /* If the black view gets a NULL output, we lost the |
| 5298 | * last output and we'll just cancel the fade. This |
| 5299 | * happens when you close the last window under the |
| 5300 | * X11 or Wayland backends. */ |
| 5301 | shell->locked = false; |
| 5302 | weston_surface_destroy(shell->fade.view->surface); |
| 5303 | shell->fade.view = NULL; |
| 5304 | } else if (shell->fade.animation) { |
Kristian Høgsberg | 5281fb1 | 2013-06-17 10:10:28 -0400 | [diff] [blame] | 5305 | weston_fade_update(shell->fade.animation, tint); |
Kristian Høgsberg | 87d3b61 | 2014-01-19 21:48:10 -0800 | [diff] [blame] | 5306 | } else { |
Ander Conselvan de Oliveira | 19d10ef | 2013-02-21 18:35:20 +0200 | [diff] [blame] | 5307 | shell->fade.animation = |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 5308 | weston_fade_run(shell->fade.view, |
Kristian Høgsberg | 5281fb1 | 2013-06-17 10:10:28 -0400 | [diff] [blame] | 5309 | 1.0 - tint, tint, 300.0, |
Ander Conselvan de Oliveira | 19d10ef | 2013-02-21 18:35:20 +0200 | [diff] [blame] | 5310 | shell_fade_done, shell); |
Kristian Høgsberg | 87d3b61 | 2014-01-19 21:48:10 -0800 | [diff] [blame] | 5311 | } |
Ander Conselvan de Oliveira | 19d10ef | 2013-02-21 18:35:20 +0200 | [diff] [blame] | 5312 | } |
| 5313 | |
| 5314 | static void |
Pekka Paalanen | 79346ab | 2013-05-22 18:03:09 +0300 | [diff] [blame] | 5315 | do_shell_fade_startup(void *data) |
| 5316 | { |
| 5317 | struct desktop_shell *shell = data; |
| 5318 | |
Pekka Paalanen | 23ed5f2 | 2015-05-26 11:54:52 +0300 | [diff] [blame] | 5319 | if (shell->startup_animation_type == ANIMATION_FADE) { |
Kristian Høgsberg | 724c8d9 | 2013-10-16 11:38:24 -0700 | [diff] [blame] | 5320 | shell_fade(shell, FADE_IN); |
Pekka Paalanen | 23ed5f2 | 2015-05-26 11:54:52 +0300 | [diff] [blame] | 5321 | } else { |
| 5322 | weston_log("desktop shell: " |
| 5323 | "unexpected fade-in animation type %d\n", |
| 5324 | shell->startup_animation_type); |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 5325 | weston_surface_destroy(shell->fade.view->surface); |
| 5326 | shell->fade.view = NULL; |
Kristian Høgsberg | 724c8d9 | 2013-10-16 11:38:24 -0700 | [diff] [blame] | 5327 | } |
Pekka Paalanen | 79346ab | 2013-05-22 18:03:09 +0300 | [diff] [blame] | 5328 | } |
| 5329 | |
| 5330 | static void |
| 5331 | shell_fade_startup(struct desktop_shell *shell) |
| 5332 | { |
| 5333 | struct wl_event_loop *loop; |
| 5334 | |
| 5335 | if (!shell->fade.startup_timer) |
| 5336 | return; |
| 5337 | |
| 5338 | wl_event_source_remove(shell->fade.startup_timer); |
| 5339 | shell->fade.startup_timer = NULL; |
| 5340 | |
| 5341 | loop = wl_display_get_event_loop(shell->compositor->wl_display); |
| 5342 | wl_event_loop_add_idle(loop, do_shell_fade_startup, shell); |
| 5343 | } |
| 5344 | |
| 5345 | static int |
| 5346 | fade_startup_timeout(void *data) |
| 5347 | { |
| 5348 | struct desktop_shell *shell = data; |
| 5349 | |
| 5350 | shell_fade_startup(shell); |
| 5351 | return 0; |
| 5352 | } |
| 5353 | |
| 5354 | static void |
| 5355 | shell_fade_init(struct desktop_shell *shell) |
| 5356 | { |
| 5357 | /* Make compositor output all black, and wait for the desktop-shell |
| 5358 | * client to signal it is ready, then fade in. The timer triggers a |
| 5359 | * fade-in, in case the desktop-shell client takes too long. |
| 5360 | */ |
| 5361 | |
| 5362 | struct wl_event_loop *loop; |
| 5363 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 5364 | if (shell->fade.view != NULL) { |
Pekka Paalanen | 79346ab | 2013-05-22 18:03:09 +0300 | [diff] [blame] | 5365 | weston_log("%s: warning: fade surface already exists\n", |
| 5366 | __func__); |
| 5367 | return; |
| 5368 | } |
| 5369 | |
Pekka Paalanen | 23ed5f2 | 2015-05-26 11:54:52 +0300 | [diff] [blame] | 5370 | if (shell->startup_animation_type == ANIMATION_NONE) |
| 5371 | return; |
| 5372 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 5373 | shell->fade.view = shell_fade_create_surface(shell); |
| 5374 | if (!shell->fade.view) |
Pekka Paalanen | 79346ab | 2013-05-22 18:03:09 +0300 | [diff] [blame] | 5375 | return; |
| 5376 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 5377 | weston_view_update_transform(shell->fade.view); |
| 5378 | weston_surface_damage(shell->fade.view->surface); |
Pekka Paalanen | 79346ab | 2013-05-22 18:03:09 +0300 | [diff] [blame] | 5379 | |
| 5380 | loop = wl_display_get_event_loop(shell->compositor->wl_display); |
| 5381 | shell->fade.startup_timer = |
| 5382 | wl_event_loop_add_timer(loop, fade_startup_timeout, shell); |
| 5383 | wl_event_source_timer_update(shell->fade.startup_timer, 15000); |
| 5384 | } |
| 5385 | |
| 5386 | static void |
Ander Conselvan de Oliveira | a457563 | 2013-02-21 18:35:23 +0200 | [diff] [blame] | 5387 | idle_handler(struct wl_listener *listener, void *data) |
Ander Conselvan de Oliveira | 19d10ef | 2013-02-21 18:35:20 +0200 | [diff] [blame] | 5388 | { |
| 5389 | struct desktop_shell *shell = |
Ander Conselvan de Oliveira | a457563 | 2013-02-21 18:35:23 +0200 | [diff] [blame] | 5390 | container_of(listener, struct desktop_shell, idle_listener); |
Kristian Høgsberg | 27d5fa8 | 2014-01-17 16:22:50 -0800 | [diff] [blame] | 5391 | struct weston_seat *seat; |
| 5392 | |
Jonny Lamb | 76cf1fe | 2014-08-20 11:27:10 +0200 | [diff] [blame] | 5393 | wl_list_for_each(seat, &shell->compositor->seat_list, link) { |
Derek Foreman | 1281a36 | 2015-07-31 16:55:32 -0500 | [diff] [blame] | 5394 | struct weston_touch *touch = weston_seat_get_touch(seat); |
| 5395 | struct weston_pointer *pointer = weston_seat_get_pointer(seat); |
| 5396 | |
| 5397 | if (pointer) |
| 5398 | popup_grab_end(pointer); |
| 5399 | if (touch) |
| 5400 | touch_popup_grab_end(touch); |
Jonny Lamb | 76cf1fe | 2014-08-20 11:27:10 +0200 | [diff] [blame] | 5401 | } |
Ander Conselvan de Oliveira | 19d10ef | 2013-02-21 18:35:20 +0200 | [diff] [blame] | 5402 | |
| 5403 | shell_fade(shell, FADE_OUT); |
| 5404 | /* lock() is called from shell_fade_done() */ |
| 5405 | } |
| 5406 | |
| 5407 | static void |
Ander Conselvan de Oliveira | a457563 | 2013-02-21 18:35:23 +0200 | [diff] [blame] | 5408 | wake_handler(struct wl_listener *listener, void *data) |
Ander Conselvan de Oliveira | 19d10ef | 2013-02-21 18:35:20 +0200 | [diff] [blame] | 5409 | { |
| 5410 | struct desktop_shell *shell = |
Ander Conselvan de Oliveira | a457563 | 2013-02-21 18:35:23 +0200 | [diff] [blame] | 5411 | container_of(listener, struct desktop_shell, wake_listener); |
Ander Conselvan de Oliveira | 19d10ef | 2013-02-21 18:35:20 +0200 | [diff] [blame] | 5412 | |
Ander Conselvan de Oliveira | 19d10ef | 2013-02-21 18:35:20 +0200 | [diff] [blame] | 5413 | unlock(shell); |
| 5414 | } |
| 5415 | |
| 5416 | static void |
Giulio Camuffo | f05d18f | 2015-12-11 20:57:05 +0200 | [diff] [blame] | 5417 | transform_handler(struct wl_listener *listener, void *data) |
| 5418 | { |
| 5419 | struct weston_surface *surface = data; |
| 5420 | struct shell_surface *shsurf = get_shell_surface(surface); |
| 5421 | struct weston_view *view;; |
| 5422 | int x, y; |
| 5423 | |
| 5424 | if (!shsurf || !shsurf->client->send_position) |
| 5425 | return; |
| 5426 | |
| 5427 | view = shsurf->view; |
| 5428 | if (!view || !weston_view_is_mapped(view)) |
| 5429 | return; |
| 5430 | |
| 5431 | x = view->geometry.x; |
| 5432 | y = view->geometry.y; |
| 5433 | |
| 5434 | shsurf->client->send_position(surface, x, y); |
| 5435 | } |
| 5436 | |
| 5437 | static void |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 5438 | center_on_output(struct weston_view *view, struct weston_output *output) |
Pekka Paalanen | 77346a6 | 2011-11-30 16:26:35 +0200 | [diff] [blame] | 5439 | { |
Giulio Camuffo | b836664 | 2013-04-25 13:57:46 +0300 | [diff] [blame] | 5440 | int32_t surf_x, surf_y, width, height; |
Ander Conselvan de Oliveira | 012b4c7 | 2012-11-27 17:03:42 +0200 | [diff] [blame] | 5441 | float x, y; |
Pekka Paalanen | 77346a6 | 2011-11-30 16:26:35 +0200 | [diff] [blame] | 5442 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 5443 | surface_subsurfaces_boundingbox(view->surface, &surf_x, &surf_y, &width, &height); |
Giulio Camuffo | b836664 | 2013-04-25 13:57:46 +0300 | [diff] [blame] | 5444 | |
| 5445 | x = output->x + (output->width - width) / 2 - surf_x / 2; |
| 5446 | y = output->y + (output->height - height) / 2 - surf_y / 2; |
Ander Conselvan de Oliveira | 012b4c7 | 2012-11-27 17:03:42 +0200 | [diff] [blame] | 5447 | |
Jason Ekstrand | 918f2dd | 2013-12-02 21:01:53 -0600 | [diff] [blame] | 5448 | weston_view_set_position(view, x, y); |
Pekka Paalanen | 77346a6 | 2011-11-30 16:26:35 +0200 | [diff] [blame] | 5449 | } |
| 5450 | |
| 5451 | static void |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 5452 | weston_view_set_initial_position(struct weston_view *view, |
| 5453 | struct desktop_shell *shell) |
Rob Bradford | ac63e5b | 2012-08-13 14:07:52 +0100 | [diff] [blame] | 5454 | { |
| 5455 | struct weston_compositor *compositor = shell->compositor; |
| 5456 | int ix = 0, iy = 0; |
Jonny Lamb | d73c694 | 2014-08-20 15:53:20 +0200 | [diff] [blame] | 5457 | int32_t range_x, range_y; |
Derek Foreman | f814c5d | 2015-04-15 12:23:54 -0500 | [diff] [blame] | 5458 | int32_t x, y; |
Rob Bradford | ac63e5b | 2012-08-13 14:07:52 +0100 | [diff] [blame] | 5459 | struct weston_output *output, *target_output = NULL; |
| 5460 | struct weston_seat *seat; |
Jonny Lamb | d73c694 | 2014-08-20 15:53:20 +0200 | [diff] [blame] | 5461 | pixman_rectangle32_t area; |
Rob Bradford | ac63e5b | 2012-08-13 14:07:52 +0100 | [diff] [blame] | 5462 | |
| 5463 | /* As a heuristic place the new window on the same output as the |
| 5464 | * pointer. Falling back to the output containing 0, 0. |
| 5465 | * |
| 5466 | * TODO: Do something clever for touch too? |
| 5467 | */ |
| 5468 | wl_list_for_each(seat, &compositor->seat_list, link) { |
Derek Foreman | 1281a36 | 2015-07-31 16:55:32 -0500 | [diff] [blame] | 5469 | struct weston_pointer *pointer = weston_seat_get_pointer(seat); |
| 5470 | |
| 5471 | if (pointer) { |
| 5472 | ix = wl_fixed_to_int(pointer->x); |
| 5473 | iy = wl_fixed_to_int(pointer->y); |
Rob Bradford | ac63e5b | 2012-08-13 14:07:52 +0100 | [diff] [blame] | 5474 | break; |
| 5475 | } |
| 5476 | } |
| 5477 | |
| 5478 | wl_list_for_each(output, &compositor->output_list, link) { |
| 5479 | if (pixman_region32_contains_point(&output->region, ix, iy, NULL)) { |
| 5480 | target_output = output; |
| 5481 | break; |
| 5482 | } |
| 5483 | } |
| 5484 | |
| 5485 | if (!target_output) { |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 5486 | weston_view_set_position(view, 10 + random() % 400, |
| 5487 | 10 + random() % 400); |
Rob Bradford | ac63e5b | 2012-08-13 14:07:52 +0100 | [diff] [blame] | 5488 | return; |
| 5489 | } |
| 5490 | |
| 5491 | /* Valid range within output where the surface will still be onscreen. |
| 5492 | * If this is negative it means that the surface is bigger than |
| 5493 | * output. |
| 5494 | */ |
Jonny Lamb | d73c694 | 2014-08-20 15:53:20 +0200 | [diff] [blame] | 5495 | get_output_work_area(shell, target_output, &area); |
| 5496 | |
Derek Foreman | f814c5d | 2015-04-15 12:23:54 -0500 | [diff] [blame] | 5497 | x = area.x; |
| 5498 | y = area.y; |
Jonny Lamb | d73c694 | 2014-08-20 15:53:20 +0200 | [diff] [blame] | 5499 | range_x = area.width - view->surface->width; |
| 5500 | range_y = area.height - view->surface->height; |
Rob Bradford | ac63e5b | 2012-08-13 14:07:52 +0100 | [diff] [blame] | 5501 | |
Rob Bradford | 4cb88c7 | 2012-08-13 15:18:44 +0100 | [diff] [blame] | 5502 | if (range_x > 0) |
Derek Foreman | f814c5d | 2015-04-15 12:23:54 -0500 | [diff] [blame] | 5503 | x += random() % range_x; |
Rob Bradford | 4cb88c7 | 2012-08-13 15:18:44 +0100 | [diff] [blame] | 5504 | |
| 5505 | if (range_y > 0) |
Derek Foreman | f814c5d | 2015-04-15 12:23:54 -0500 | [diff] [blame] | 5506 | y += random() % range_y; |
Rob Bradford | ac63e5b | 2012-08-13 14:07:52 +0100 | [diff] [blame] | 5507 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 5508 | weston_view_set_position(view, x, y); |
Rob Bradford | ac63e5b | 2012-08-13 14:07:52 +0100 | [diff] [blame] | 5509 | } |
| 5510 | |
| 5511 | static void |
Jonny Lamb | d73c694 | 2014-08-20 15:53:20 +0200 | [diff] [blame] | 5512 | set_maximized_position(struct desktop_shell *shell, |
| 5513 | struct shell_surface *shsurf) |
| 5514 | { |
| 5515 | int32_t surf_x, surf_y; |
| 5516 | pixman_rectangle32_t area; |
| 5517 | |
Jonny Lamb | d73c694 | 2014-08-20 15:53:20 +0200 | [diff] [blame] | 5518 | get_output_work_area(shell, shsurf->output, &area); |
Giulio Camuffo | 7a8d67d | 2015-01-09 20:10:45 +0200 | [diff] [blame] | 5519 | if (shsurf->has_set_geometry) { |
| 5520 | surf_x = shsurf->geometry.x; |
| 5521 | surf_y = shsurf->geometry.y; |
| 5522 | } else { |
| 5523 | surface_subsurfaces_boundingbox(shsurf->surface, |
| 5524 | &surf_x, &surf_y, NULL, NULL); |
| 5525 | } |
Jonny Lamb | d73c694 | 2014-08-20 15:53:20 +0200 | [diff] [blame] | 5526 | |
| 5527 | weston_view_set_position(shsurf->view, |
Marek Chalupa | 6ce7899 | 2015-10-09 18:17:07 +0200 | [diff] [blame] | 5528 | area.x - surf_x, |
| 5529 | area.y - surf_y); |
Jonny Lamb | d73c694 | 2014-08-20 15:53:20 +0200 | [diff] [blame] | 5530 | } |
| 5531 | |
| 5532 | static void |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 5533 | map(struct desktop_shell *shell, struct shell_surface *shsurf, |
Jason Ekstrand | 918f2dd | 2013-12-02 21:01:53 -0600 | [diff] [blame] | 5534 | int32_t sx, int32_t sy) |
Kristian Høgsberg | 02ec0a5 | 2011-04-23 13:04:11 -0400 | [diff] [blame] | 5535 | { |
Kristian Høgsberg | 8334bc1 | 2012-01-03 10:29:47 -0500 | [diff] [blame] | 5536 | struct weston_compositor *compositor = shell->compositor; |
Daniel Stone | b210468 | 2012-05-30 16:31:56 +0100 | [diff] [blame] | 5537 | struct weston_seat *seat; |
Pekka Paalanen | 57da4a8 | 2011-11-23 16:42:16 +0200 | [diff] [blame] | 5538 | |
Pekka Paalanen | 77346a6 | 2011-11-30 16:26:35 +0200 | [diff] [blame] | 5539 | /* initial positioning, see also configure() */ |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 5540 | switch (shsurf->type) { |
Rafael Antognolli | ed207b4 | 2013-12-03 15:35:43 -0200 | [diff] [blame] | 5541 | case SHELL_SURFACE_TOPLEVEL: |
Rafael Antognolli | 03b1659 | 2013-12-03 15:35:42 -0200 | [diff] [blame] | 5542 | if (shsurf->state.fullscreen) { |
| 5543 | center_on_output(shsurf->view, shsurf->fullscreen_output); |
| 5544 | shell_map_fullscreen(shsurf); |
| 5545 | } else if (shsurf->state.maximized) { |
Jonny Lamb | d73c694 | 2014-08-20 15:53:20 +0200 | [diff] [blame] | 5546 | set_maximized_position(shell, shsurf); |
Rafael Antognolli | ed207b4 | 2013-12-03 15:35:43 -0200 | [diff] [blame] | 5547 | } else if (!shsurf->state.relative) { |
Rafael Antognolli | 03b1659 | 2013-12-03 15:35:42 -0200 | [diff] [blame] | 5548 | weston_view_set_initial_position(shsurf->view, shell); |
| 5549 | } |
Juan Zhao | 96879df | 2012-02-07 08:45:41 +0800 | [diff] [blame] | 5550 | break; |
Tiago Vignatti | 0f99701 | 2012-02-10 16:17:23 +0200 | [diff] [blame] | 5551 | case SHELL_SURFACE_POPUP: |
Jasper St. Pierre | da6ecd0 | 2015-02-27 18:35:45 +0800 | [diff] [blame] | 5552 | if (shell_map_popup(shsurf) != 0) |
| 5553 | return; |
Rob Bradford | db99938 | 2012-12-06 12:07:48 +0000 | [diff] [blame] | 5554 | break; |
Ander Conselvan de Oliveira | e9e0515 | 2012-02-15 17:02:56 +0200 | [diff] [blame] | 5555 | case SHELL_SURFACE_NONE: |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 5556 | weston_view_set_position(shsurf->view, |
| 5557 | shsurf->view->geometry.x + sx, |
| 5558 | shsurf->view->geometry.y + sy); |
Tiago Vignatti | 0f99701 | 2012-02-10 16:17:23 +0200 | [diff] [blame] | 5559 | break; |
Philip Withnall | 0f640e2 | 2013-11-25 18:01:31 +0000 | [diff] [blame] | 5560 | case SHELL_SURFACE_XWAYLAND: |
Pekka Paalanen | 77346a6 | 2011-11-30 16:26:35 +0200 | [diff] [blame] | 5561 | default: |
| 5562 | ; |
| 5563 | } |
Kristian Høgsberg | 7584062 | 2011-09-06 13:48:16 -0400 | [diff] [blame] | 5564 | |
Philip Withnall | e1d75ae | 2013-11-25 18:01:41 +0000 | [diff] [blame] | 5565 | /* Surface stacking order, see also activate(). */ |
| 5566 | shell_surface_update_layer(shsurf); |
Pekka Paalanen | f0fc70d | 2011-11-15 13:34:54 +0200 | [diff] [blame] | 5567 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 5568 | if (shsurf->type != SHELL_SURFACE_NONE) { |
| 5569 | weston_view_update_transform(shsurf->view); |
Rafael Antognolli | 03b1659 | 2013-12-03 15:35:42 -0200 | [diff] [blame] | 5570 | if (shsurf->state.maximized) { |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 5571 | shsurf->surface->output = shsurf->output; |
| 5572 | shsurf->view->output = shsurf->output; |
| 5573 | } |
Ander Conselvan de Oliveira | de56c31 | 2012-03-05 15:39:23 +0200 | [diff] [blame] | 5574 | } |
Kristian Høgsberg | 2f88a40 | 2011-12-04 15:32:59 -0500 | [diff] [blame] | 5575 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 5576 | switch (shsurf->type) { |
Tiago Vignatti | fb2adba | 2013-06-12 15:43:21 -0300 | [diff] [blame] | 5577 | /* XXX: xwayland's using the same fields for transient type */ |
| 5578 | case SHELL_SURFACE_XWAYLAND: |
Tiago Vignatti | 99aeb1e | 2012-05-23 22:06:26 +0300 | [diff] [blame] | 5579 | if (shsurf->transient.flags == |
| 5580 | WL_SHELL_SURFACE_TRANSIENT_INACTIVE) |
| 5581 | break; |
| 5582 | case SHELL_SURFACE_TOPLEVEL: |
Rafael Antognolli | ed207b4 | 2013-12-03 15:35:43 -0200 | [diff] [blame] | 5583 | if (shsurf->state.relative && |
| 5584 | shsurf->transient.flags == WL_SHELL_SURFACE_TRANSIENT_INACTIVE) |
| 5585 | break; |
Rafael Antognolli | ba5d2d7 | 2013-12-04 17:49:55 -0200 | [diff] [blame] | 5586 | if (shell->locked) |
Rafael Antognolli | ed207b4 | 2013-12-03 15:35:43 -0200 | [diff] [blame] | 5587 | break; |
| 5588 | wl_list_for_each(seat, &compositor->seat_list, link) |
Emilio Pozuelo Monfort | 9e7c759 | 2014-01-30 14:01:10 +0100 | [diff] [blame] | 5589 | activate(shell, shsurf->surface, seat, true); |
Juan Zhao | 7bb92f0 | 2011-12-15 11:31:51 -0500 | [diff] [blame] | 5590 | break; |
Philip Withnall | 0f640e2 | 2013-11-25 18:01:31 +0000 | [diff] [blame] | 5591 | case SHELL_SURFACE_POPUP: |
| 5592 | case SHELL_SURFACE_NONE: |
Juan Zhao | 7bb92f0 | 2011-12-15 11:31:51 -0500 | [diff] [blame] | 5593 | default: |
| 5594 | break; |
| 5595 | } |
| 5596 | |
Rafael Antognolli | 03b1659 | 2013-12-03 15:35:42 -0200 | [diff] [blame] | 5597 | if (shsurf->type == SHELL_SURFACE_TOPLEVEL && |
| 5598 | !shsurf->state.maximized && !shsurf->state.fullscreen) |
Juan Zhao | e10d279 | 2012-04-25 19:09:52 +0800 | [diff] [blame] | 5599 | { |
| 5600 | switch (shell->win_animation_type) { |
| 5601 | case ANIMATION_FADE: |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 5602 | 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] | 5603 | break; |
| 5604 | case ANIMATION_ZOOM: |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 5605 | weston_zoom_run(shsurf->view, 0.5, 1.0, NULL, NULL); |
Juan Zhao | e10d279 | 2012-04-25 19:09:52 +0800 | [diff] [blame] | 5606 | break; |
Philip Withnall | 4a86a0a | 2013-11-25 18:01:32 +0000 | [diff] [blame] | 5607 | case ANIMATION_NONE: |
Juan Zhao | e10d279 | 2012-04-25 19:09:52 +0800 | [diff] [blame] | 5608 | default: |
| 5609 | break; |
| 5610 | } |
| 5611 | } |
Kristian Høgsberg | 32e24cc | 2011-11-09 12:07:35 -0500 | [diff] [blame] | 5612 | } |
| 5613 | |
| 5614 | static void |
Tiago Vignatti | be14326 | 2012-04-16 17:31:41 +0300 | [diff] [blame] | 5615 | configure(struct desktop_shell *shell, struct weston_surface *surface, |
Jason Ekstrand | 918f2dd | 2013-12-02 21:01:53 -0600 | [diff] [blame] | 5616 | float x, float y) |
Kristian Høgsberg | 32e24cc | 2011-11-09 12:07:35 -0500 | [diff] [blame] | 5617 | { |
Pekka Paalanen | 77346a6 | 2011-11-30 16:26:35 +0200 | [diff] [blame] | 5618 | struct shell_surface *shsurf; |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 5619 | struct weston_view *view; |
Kristian Høgsberg | 32e24cc | 2011-11-09 12:07:35 -0500 | [diff] [blame] | 5620 | |
Pekka Paalanen | 77346a6 | 2011-11-30 16:26:35 +0200 | [diff] [blame] | 5621 | shsurf = get_shell_surface(surface); |
Pekka Paalanen | 77346a6 | 2011-11-30 16:26:35 +0200 | [diff] [blame] | 5622 | |
U. Artie Eoff | cf5737a | 2014-01-17 10:08:25 -0800 | [diff] [blame] | 5623 | assert(shsurf); |
| 5624 | |
Rafael Antognolli | 03b1659 | 2013-12-03 15:35:42 -0200 | [diff] [blame] | 5625 | if (shsurf->state.fullscreen) |
Alex Wu | 4539b08 | 2012-03-01 12:57:46 +0800 | [diff] [blame] | 5626 | shell_configure_fullscreen(shsurf); |
Rafael Antognolli | 03b1659 | 2013-12-03 15:35:42 -0200 | [diff] [blame] | 5627 | else if (shsurf->state.maximized) { |
Jonny Lamb | d73c694 | 2014-08-20 15:53:20 +0200 | [diff] [blame] | 5628 | set_maximized_position(shell, shsurf); |
Rafael Antognolli | 03b1659 | 2013-12-03 15:35:42 -0200 | [diff] [blame] | 5629 | } else { |
Jason Ekstrand | 918f2dd | 2013-12-02 21:01:53 -0600 | [diff] [blame] | 5630 | weston_view_set_position(shsurf->view, x, y); |
Kristian Høgsberg | 7a5c979 | 2011-06-18 06:12:54 -0400 | [diff] [blame] | 5631 | } |
Kristian Høgsberg | 32e24cc | 2011-11-09 12:07:35 -0500 | [diff] [blame] | 5632 | |
Alex Wu | 4539b08 | 2012-03-01 12:57:46 +0800 | [diff] [blame] | 5633 | /* XXX: would a fullscreen surface need the same handling? */ |
Kristian Høgsberg | 6a8b553 | 2012-02-16 23:43:59 -0500 | [diff] [blame] | 5634 | if (surface->output) { |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 5635 | wl_list_for_each(view, &surface->views, surface_link) |
| 5636 | weston_view_update_transform(view); |
Pekka Paalanen | 77346a6 | 2011-11-30 16:26:35 +0200 | [diff] [blame] | 5637 | |
Rafael Antognolli | 03b1659 | 2013-12-03 15:35:42 -0200 | [diff] [blame] | 5638 | if (shsurf->state.maximized) |
Juan Zhao | 96879df | 2012-02-07 08:45:41 +0800 | [diff] [blame] | 5639 | surface->output = shsurf->output; |
Pekka Paalanen | 77346a6 | 2011-11-30 16:26:35 +0200 | [diff] [blame] | 5640 | } |
Kristian Høgsberg | 0793756 | 2011-04-12 17:25:42 -0400 | [diff] [blame] | 5641 | } |
| 5642 | |
Ander Conselvan de Oliveira | 093bfa3 | 2012-03-27 17:36:41 +0300 | [diff] [blame] | 5643 | static void |
Jason Ekstrand | 918f2dd | 2013-12-02 21:01:53 -0600 | [diff] [blame] | 5644 | 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] | 5645 | { |
Ander Conselvan de Oliveira | 7fb9f95 | 2012-03-27 17:36:42 +0300 | [diff] [blame] | 5646 | struct shell_surface *shsurf = get_shell_surface(es); |
U. Artie Eoff | cf5737a | 2014-01-17 10:08:25 -0800 | [diff] [blame] | 5647 | struct desktop_shell *shell; |
Tiago Vignatti | 70e5c9c | 2012-05-07 15:23:07 +0300 | [diff] [blame] | 5648 | int type_changed = 0; |
Ander Conselvan de Oliveira | 093bfa3 | 2012-03-27 17:36:41 +0300 | [diff] [blame] | 5649 | |
U. Artie Eoff | cf5737a | 2014-01-17 10:08:25 -0800 | [diff] [blame] | 5650 | assert(shsurf); |
| 5651 | |
| 5652 | shell = shsurf->shell; |
| 5653 | |
Kristian Høgsberg | 8eb0f4f | 2013-06-17 10:33:14 -0400 | [diff] [blame] | 5654 | if (!weston_surface_is_mapped(es) && |
| 5655 | !wl_list_empty(&shsurf->popup.grab_link)) { |
Giulio Camuffo | 5085a75 | 2013-03-25 21:42:45 +0100 | [diff] [blame] | 5656 | remove_popup_grab(shsurf); |
| 5657 | } |
| 5658 | |
Jason Ekstrand | 918f2dd | 2013-12-02 21:01:53 -0600 | [diff] [blame] | 5659 | if (es->width == 0) |
Giulio Camuffo | 184df50 | 2013-02-21 11:29:21 +0100 | [diff] [blame] | 5660 | return; |
| 5661 | |
Jasper St. Pierre | ccf48fb | 2014-05-02 10:21:38 -0400 | [diff] [blame] | 5662 | if (shsurf->has_next_geometry) { |
| 5663 | shsurf->geometry = shsurf->next_geometry; |
| 5664 | shsurf->has_next_geometry = false; |
| 5665 | shsurf->has_set_geometry = true; |
| 5666 | } else if (!shsurf->has_set_geometry) { |
| 5667 | surface_subsurfaces_boundingbox(shsurf->surface, |
| 5668 | &shsurf->geometry.x, |
| 5669 | &shsurf->geometry.y, |
| 5670 | &shsurf->geometry.width, |
| 5671 | &shsurf->geometry.height); |
Jasper St. Pierre | 851799e | 2014-05-02 10:14:07 -0400 | [diff] [blame] | 5672 | } |
| 5673 | |
Kristian Høgsberg | c8f8dd8 | 2013-12-05 23:20:33 -0800 | [diff] [blame] | 5674 | if (shsurf->state_changed) { |
Kristian Høgsberg | 7f366e7 | 2012-04-27 17:20:01 -0400 | [diff] [blame] | 5675 | set_surface_type(shsurf); |
Kristian Høgsberg | f7e23d5 | 2012-04-27 17:51:59 -0400 | [diff] [blame] | 5676 | type_changed = 1; |
| 5677 | } |
Kristian Høgsberg | 7f366e7 | 2012-04-27 17:20:01 -0400 | [diff] [blame] | 5678 | |
Ander Conselvan de Oliveira | 093bfa3 | 2012-03-27 17:36:41 +0300 | [diff] [blame] | 5679 | if (!weston_surface_is_mapped(es)) { |
Jason Ekstrand | 918f2dd | 2013-12-02 21:01:53 -0600 | [diff] [blame] | 5680 | map(shell, shsurf, sx, sy); |
Kristian Høgsberg | f7e23d5 | 2012-04-27 17:51:59 -0400 | [diff] [blame] | 5681 | } else if (type_changed || sx != 0 || sy != 0 || |
Jason Ekstrand | 918f2dd | 2013-12-02 21:01:53 -0600 | [diff] [blame] | 5682 | shsurf->last_width != es->width || |
| 5683 | shsurf->last_height != es->height) { |
John Kåre Alsaker | 490d02a | 2012-09-30 02:57:21 +0200 | [diff] [blame] | 5684 | float from_x, from_y; |
| 5685 | float to_x, to_y; |
Ander Conselvan de Oliveira | 093bfa3 | 2012-03-27 17:36:41 +0300 | [diff] [blame] | 5686 | |
Kristian Høgsberg | 44cd196 | 2014-02-05 21:36:04 -0800 | [diff] [blame] | 5687 | if (shsurf->resize_edges) { |
| 5688 | sx = 0; |
| 5689 | sy = 0; |
| 5690 | } |
| 5691 | |
| 5692 | if (shsurf->resize_edges & WL_SHELL_SURFACE_RESIZE_LEFT) |
| 5693 | sx = shsurf->last_width - es->width; |
| 5694 | if (shsurf->resize_edges & WL_SHELL_SURFACE_RESIZE_TOP) |
| 5695 | sy = shsurf->last_height - es->height; |
| 5696 | |
| 5697 | shsurf->last_width = es->width; |
| 5698 | shsurf->last_height = es->height; |
| 5699 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 5700 | weston_view_to_global_float(shsurf->view, 0, 0, &from_x, &from_y); |
| 5701 | 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] | 5702 | configure(shell, es, |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 5703 | shsurf->view->geometry.x + to_x - from_x, |
Jason Ekstrand | 918f2dd | 2013-12-02 21:01:53 -0600 | [diff] [blame] | 5704 | shsurf->view->geometry.y + to_y - from_y); |
Ander Conselvan de Oliveira | 093bfa3 | 2012-03-27 17:36:41 +0300 | [diff] [blame] | 5705 | } |
| 5706 | } |
| 5707 | |
Pekka Paalanen | 2e62e4a | 2014-08-28 11:41:26 +0300 | [diff] [blame] | 5708 | static bool |
| 5709 | check_desktop_shell_crash_too_early(struct desktop_shell *shell) |
| 5710 | { |
| 5711 | struct timespec now; |
| 5712 | |
| 5713 | if (clock_gettime(CLOCK_MONOTONIC, &now) < 0) |
| 5714 | return false; |
| 5715 | |
| 5716 | /* |
| 5717 | * If the shell helper client dies before the session has been |
| 5718 | * up for roughly 30 seconds, better just make Weston shut down, |
| 5719 | * because the user likely has no way to interact with the desktop |
| 5720 | * anyway. |
| 5721 | */ |
| 5722 | if (now.tv_sec - shell->startup_time.tv_sec < 30) { |
| 5723 | weston_log("Error: %s apparently cannot run at all.\n", |
| 5724 | shell->client); |
| 5725 | weston_log_continue(STAMP_SPACE "Quitting..."); |
| 5726 | wl_display_terminate(shell->compositor->wl_display); |
| 5727 | |
| 5728 | return true; |
| 5729 | } |
| 5730 | |
| 5731 | return false; |
| 5732 | } |
| 5733 | |
Tiago Vignatti | b7dbbd6 | 2012-09-25 17:57:01 +0300 | [diff] [blame] | 5734 | static void launch_desktop_shell_process(void *data); |
Pekka Paalanen | 4d733ee | 2012-01-17 14:36:27 +0200 | [diff] [blame] | 5735 | |
Kristian Høgsberg | 97d44aa | 2011-08-26 17:21:20 -0400 | [diff] [blame] | 5736 | static void |
Pekka Paalanen | 826dc14 | 2014-08-27 12:11:53 +0300 | [diff] [blame] | 5737 | respawn_desktop_shell_process(struct desktop_shell *shell) |
Pekka Paalanen | 6cd281a | 2011-11-03 14:11:32 +0200 | [diff] [blame] | 5738 | { |
Pekka Paalanen | 4d733ee | 2012-01-17 14:36:27 +0200 | [diff] [blame] | 5739 | uint32_t time; |
Pekka Paalanen | 4d733ee | 2012-01-17 14:36:27 +0200 | [diff] [blame] | 5740 | |
| 5741 | /* if desktop-shell dies more than 5 times in 30 seconds, give up */ |
| 5742 | time = weston_compositor_get_time(); |
Kristian Høgsberg | f03a616 | 2012-01-17 11:07:42 -0500 | [diff] [blame] | 5743 | if (time - shell->child.deathstamp > 30000) { |
Pekka Paalanen | 4d733ee | 2012-01-17 14:36:27 +0200 | [diff] [blame] | 5744 | shell->child.deathstamp = time; |
| 5745 | shell->child.deathcount = 0; |
| 5746 | } |
| 5747 | |
| 5748 | shell->child.deathcount++; |
| 5749 | if (shell->child.deathcount > 5) { |
Pekka Paalanen | 826dc14 | 2014-08-27 12:11:53 +0300 | [diff] [blame] | 5750 | weston_log("%s disconnected, giving up.\n", shell->client); |
Pekka Paalanen | 4d733ee | 2012-01-17 14:36:27 +0200 | [diff] [blame] | 5751 | return; |
| 5752 | } |
| 5753 | |
Pekka Paalanen | 826dc14 | 2014-08-27 12:11:53 +0300 | [diff] [blame] | 5754 | weston_log("%s disconnected, respawning...\n", shell->client); |
Pekka Paalanen | 4d733ee | 2012-01-17 14:36:27 +0200 | [diff] [blame] | 5755 | launch_desktop_shell_process(shell); |
Pekka Paalanen | 6cd281a | 2011-11-03 14:11:32 +0200 | [diff] [blame] | 5756 | } |
| 5757 | |
Tiago Vignatti | b7dbbd6 | 2012-09-25 17:57:01 +0300 | [diff] [blame] | 5758 | static void |
Ander Conselvan de Oliveira | 312ea4c | 2013-12-20 21:07:01 +0200 | [diff] [blame] | 5759 | desktop_shell_client_destroy(struct wl_listener *listener, void *data) |
| 5760 | { |
| 5761 | struct desktop_shell *shell; |
| 5762 | |
| 5763 | shell = container_of(listener, struct desktop_shell, |
| 5764 | child.client_destroy_listener); |
| 5765 | |
Pekka Paalanen | 826dc14 | 2014-08-27 12:11:53 +0300 | [diff] [blame] | 5766 | wl_list_remove(&shell->child.client_destroy_listener.link); |
Ander Conselvan de Oliveira | 312ea4c | 2013-12-20 21:07:01 +0200 | [diff] [blame] | 5767 | shell->child.client = NULL; |
Pekka Paalanen | 826dc14 | 2014-08-27 12:11:53 +0300 | [diff] [blame] | 5768 | /* |
| 5769 | * unbind_desktop_shell() will reset shell->child.desktop_shell |
| 5770 | * before the respawned process has a chance to create a new |
| 5771 | * desktop_shell object, because we are being called from the |
| 5772 | * wl_client destructor which destroys all wl_resources before |
| 5773 | * returning. |
| 5774 | */ |
| 5775 | |
Pekka Paalanen | 2e62e4a | 2014-08-28 11:41:26 +0300 | [diff] [blame] | 5776 | if (!check_desktop_shell_crash_too_early(shell)) |
| 5777 | respawn_desktop_shell_process(shell); |
| 5778 | |
Pekka Paalanen | 826dc14 | 2014-08-27 12:11:53 +0300 | [diff] [blame] | 5779 | shell_fade_startup(shell); |
Ander Conselvan de Oliveira | 312ea4c | 2013-12-20 21:07:01 +0200 | [diff] [blame] | 5780 | } |
| 5781 | |
| 5782 | static void |
Tiago Vignatti | b7dbbd6 | 2012-09-25 17:57:01 +0300 | [diff] [blame] | 5783 | launch_desktop_shell_process(void *data) |
Pekka Paalanen | 6cd281a | 2011-11-03 14:11:32 +0200 | [diff] [blame] | 5784 | { |
Tiago Vignatti | b7dbbd6 | 2012-09-25 17:57:01 +0300 | [diff] [blame] | 5785 | struct desktop_shell *shell = data; |
Pekka Paalanen | 6cd281a | 2011-11-03 14:11:32 +0200 | [diff] [blame] | 5786 | |
Pekka Paalanen | 826dc14 | 2014-08-27 12:11:53 +0300 | [diff] [blame] | 5787 | shell->child.client = weston_client_start(shell->compositor, |
| 5788 | shell->client); |
Pekka Paalanen | 409ef0a | 2011-12-02 15:30:21 +0200 | [diff] [blame] | 5789 | |
Arnaud Vrac | 4263119 | 2014-08-25 20:56:46 +0200 | [diff] [blame] | 5790 | if (!shell->child.client) { |
Emilio Pozuelo Monfort | 46ce798 | 2013-11-20 13:22:29 +0100 | [diff] [blame] | 5791 | weston_log("not able to start %s\n", shell->client); |
Arnaud Vrac | 4263119 | 2014-08-25 20:56:46 +0200 | [diff] [blame] | 5792 | return; |
| 5793 | } |
Ander Conselvan de Oliveira | 312ea4c | 2013-12-20 21:07:01 +0200 | [diff] [blame] | 5794 | |
| 5795 | shell->child.client_destroy_listener.notify = |
| 5796 | desktop_shell_client_destroy; |
| 5797 | wl_client_add_destroy_listener(shell->child.client, |
| 5798 | &shell->child.client_destroy_listener); |
Pekka Paalanen | 6cd281a | 2011-11-03 14:11:32 +0200 | [diff] [blame] | 5799 | } |
| 5800 | |
| 5801 | static void |
Kristian Høgsberg | 2bff94e | 2014-02-11 12:22:51 -0800 | [diff] [blame] | 5802 | handle_shell_client_destroy(struct wl_listener *listener, void *data) |
| 5803 | { |
| 5804 | struct shell_client *sc = |
| 5805 | container_of(listener, struct shell_client, destroy_listener); |
| 5806 | |
| 5807 | if (sc->ping_timer) |
| 5808 | wl_event_source_remove(sc->ping_timer); |
Derek Foreman | e42d754 | 2015-05-29 10:46:44 -0500 | [diff] [blame] | 5809 | |
| 5810 | /* Since we're about to free shell_client, we remove it from the |
| 5811 | * head of the surface list so we don't use that freed list node |
| 5812 | * during surface clean up later on. |
| 5813 | */ |
| 5814 | wl_list_remove(&sc->surface_list); |
| 5815 | |
Kristian Høgsberg | 2bff94e | 2014-02-11 12:22:51 -0800 | [diff] [blame] | 5816 | free(sc); |
| 5817 | } |
| 5818 | |
Kristian Høgsberg | dd62aba | 2014-02-12 09:56:19 -0800 | [diff] [blame] | 5819 | static struct shell_client * |
| 5820 | shell_client_create(struct wl_client *client, struct desktop_shell *shell, |
| 5821 | const struct wl_interface *interface, uint32_t id) |
Rafael Antognolli | e2a3455 | 2013-12-03 15:35:45 -0200 | [diff] [blame] | 5822 | { |
Kristian Høgsberg | 2bff94e | 2014-02-11 12:22:51 -0800 | [diff] [blame] | 5823 | struct shell_client *sc; |
Rafael Antognolli | e2a3455 | 2013-12-03 15:35:45 -0200 | [diff] [blame] | 5824 | |
Kristian Høgsberg | 2bff94e | 2014-02-11 12:22:51 -0800 | [diff] [blame] | 5825 | sc = zalloc(sizeof *sc); |
| 5826 | if (sc == NULL) { |
| 5827 | wl_client_post_no_memory(client); |
Kristian Høgsberg | dd62aba | 2014-02-12 09:56:19 -0800 | [diff] [blame] | 5828 | return NULL; |
Kristian Høgsberg | 2bff94e | 2014-02-11 12:22:51 -0800 | [diff] [blame] | 5829 | } |
Kristian Høgsberg | dd62aba | 2014-02-12 09:56:19 -0800 | [diff] [blame] | 5830 | |
| 5831 | sc->resource = wl_resource_create(client, interface, 1, id); |
Kristian Høgsberg | 2bff94e | 2014-02-11 12:22:51 -0800 | [diff] [blame] | 5832 | if (sc->resource == NULL) { |
| 5833 | free(sc); |
| 5834 | wl_client_post_no_memory(client); |
Kristian Høgsberg | dd62aba | 2014-02-12 09:56:19 -0800 | [diff] [blame] | 5835 | return NULL; |
Kristian Høgsberg | 2bff94e | 2014-02-11 12:22:51 -0800 | [diff] [blame] | 5836 | } |
| 5837 | |
| 5838 | sc->client = client; |
| 5839 | sc->shell = shell; |
| 5840 | sc->destroy_listener.notify = handle_shell_client_destroy; |
| 5841 | wl_client_add_destroy_listener(client, &sc->destroy_listener); |
Jonas Ådahl | 49d77d2 | 2015-03-18 16:20:51 +0800 | [diff] [blame] | 5842 | wl_list_init(&sc->surface_list); |
Kristian Høgsberg | 2bff94e | 2014-02-11 12:22:51 -0800 | [diff] [blame] | 5843 | |
Kristian Høgsberg | dd62aba | 2014-02-12 09:56:19 -0800 | [diff] [blame] | 5844 | return sc; |
| 5845 | } |
| 5846 | |
| 5847 | static void |
| 5848 | bind_shell(struct wl_client *client, void *data, uint32_t version, uint32_t id) |
| 5849 | { |
| 5850 | struct desktop_shell *shell = data; |
| 5851 | struct shell_client *sc; |
| 5852 | |
| 5853 | sc = shell_client_create(client, shell, &wl_shell_interface, id); |
| 5854 | if (sc) |
| 5855 | wl_resource_set_implementation(sc->resource, |
| 5856 | &shell_implementation, |
Jason Ekstrand | 9e9512f | 2014-04-16 21:12:10 -0500 | [diff] [blame] | 5857 | sc, NULL); |
Kristian Høgsberg | dd62aba | 2014-02-12 09:56:19 -0800 | [diff] [blame] | 5858 | } |
| 5859 | |
| 5860 | static void |
| 5861 | bind_xdg_shell(struct wl_client *client, void *data, uint32_t version, uint32_t id) |
| 5862 | { |
| 5863 | struct desktop_shell *shell = data; |
| 5864 | struct shell_client *sc; |
| 5865 | |
| 5866 | sc = shell_client_create(client, shell, &xdg_shell_interface, id); |
| 5867 | if (sc) |
| 5868 | wl_resource_set_dispatcher(sc->resource, |
| 5869 | xdg_shell_unversioned_dispatch, |
| 5870 | NULL, sc, NULL); |
Rafael Antognolli | e2a3455 | 2013-12-03 15:35:45 -0200 | [diff] [blame] | 5871 | } |
| 5872 | |
| 5873 | static void |
Pekka Paalanen | 9ef3e01 | 2011-11-15 13:34:48 +0200 | [diff] [blame] | 5874 | unbind_desktop_shell(struct wl_resource *resource) |
| 5875 | { |
Jason Ekstrand | 651f00e | 2013-06-14 10:07:54 -0500 | [diff] [blame] | 5876 | struct desktop_shell *shell = wl_resource_get_user_data(resource); |
Kristian Høgsberg | 1ec0c31 | 2011-11-15 16:39:55 -0500 | [diff] [blame] | 5877 | |
| 5878 | if (shell->locked) |
| 5879 | resume_desktop(shell); |
| 5880 | |
Pekka Paalanen | 9ef3e01 | 2011-11-15 13:34:48 +0200 | [diff] [blame] | 5881 | shell->child.desktop_shell = NULL; |
| 5882 | shell->prepare_event_sent = false; |
Pekka Paalanen | 9ef3e01 | 2011-11-15 13:34:48 +0200 | [diff] [blame] | 5883 | } |
| 5884 | |
| 5885 | static void |
Kristian Høgsberg | 7584062 | 2011-09-06 13:48:16 -0400 | [diff] [blame] | 5886 | bind_desktop_shell(struct wl_client *client, |
| 5887 | void *data, uint32_t version, uint32_t id) |
| 5888 | { |
Tiago Vignatti | be14326 | 2012-04-16 17:31:41 +0300 | [diff] [blame] | 5889 | struct desktop_shell *shell = data; |
Pekka Paalanen | bbe6052 | 2011-11-03 14:11:33 +0200 | [diff] [blame] | 5890 | struct wl_resource *resource; |
Kristian Høgsberg | 7584062 | 2011-09-06 13:48:16 -0400 | [diff] [blame] | 5891 | |
Jonas Ådahl | 6d6fb61 | 2015-11-17 16:00:33 +0800 | [diff] [blame] | 5892 | resource = wl_resource_create(client, &weston_desktop_shell_interface, |
| 5893 | 1, id); |
Pekka Paalanen | bbe6052 | 2011-11-03 14:11:33 +0200 | [diff] [blame] | 5894 | |
Pekka Paalanen | 9ef3e01 | 2011-11-15 13:34:48 +0200 | [diff] [blame] | 5895 | if (client == shell->child.client) { |
Jason Ekstrand | a85118c | 2013-06-27 20:17:02 -0500 | [diff] [blame] | 5896 | wl_resource_set_implementation(resource, |
| 5897 | &desktop_shell_implementation, |
| 5898 | shell, unbind_desktop_shell); |
Pekka Paalanen | 9ef3e01 | 2011-11-15 13:34:48 +0200 | [diff] [blame] | 5899 | shell->child.desktop_shell = resource; |
Pekka Paalanen | bbe6052 | 2011-11-03 14:11:33 +0200 | [diff] [blame] | 5900 | return; |
Pekka Paalanen | 9ef3e01 | 2011-11-15 13:34:48 +0200 | [diff] [blame] | 5901 | } |
Pekka Paalanen | bbe6052 | 2011-11-03 14:11:33 +0200 | [diff] [blame] | 5902 | |
| 5903 | wl_resource_post_error(resource, WL_DISPLAY_ERROR_INVALID_OBJECT, |
| 5904 | "permission to bind desktop_shell denied"); |
Kristian Høgsberg | 7584062 | 2011-09-06 13:48:16 -0400 | [diff] [blame] | 5905 | } |
| 5906 | |
Kristian Høgsberg | 0704539 | 2012-02-19 18:52:44 -0500 | [diff] [blame] | 5907 | struct switcher { |
Tiago Vignatti | be14326 | 2012-04-16 17:31:41 +0300 | [diff] [blame] | 5908 | struct desktop_shell *shell; |
Kristian Høgsberg | 0704539 | 2012-02-19 18:52:44 -0500 | [diff] [blame] | 5909 | struct weston_surface *current; |
| 5910 | struct wl_listener listener; |
Kristian Høgsberg | 29139d4 | 2013-04-18 15:25:39 -0400 | [diff] [blame] | 5911 | struct weston_keyboard_grab grab; |
Manuel Bachmann | c1ae2e8 | 2014-02-26 15:53:11 +0100 | [diff] [blame] | 5912 | struct wl_array minimized_array; |
Kristian Høgsberg | 0704539 | 2012-02-19 18:52:44 -0500 | [diff] [blame] | 5913 | }; |
| 5914 | |
| 5915 | static void |
| 5916 | switcher_next(struct switcher *switcher) |
| 5917 | { |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 5918 | struct weston_view *view; |
Kristian Høgsberg | 0704539 | 2012-02-19 18:52:44 -0500 | [diff] [blame] | 5919 | struct weston_surface *first = NULL, *prev = NULL, *next = NULL; |
Kristian Høgsberg | 32e5686 | 2012-04-02 22:18:58 -0400 | [diff] [blame] | 5920 | struct shell_surface *shsurf; |
Kristian Høgsberg | b0d8e77 | 2012-06-18 16:34:58 -0400 | [diff] [blame] | 5921 | struct workspace *ws = get_current_workspace(switcher->shell); |
Kristian Høgsberg | 0704539 | 2012-02-19 18:52:44 -0500 | [diff] [blame] | 5922 | |
Manuel Bachmann | c1ae2e8 | 2014-02-26 15:53:11 +0100 | [diff] [blame] | 5923 | /* temporary re-display minimized surfaces */ |
| 5924 | struct weston_view *tmp; |
| 5925 | struct weston_view **minimized; |
Giulio Camuffo | 412e6a5 | 2014-07-09 22:12:56 +0300 | [diff] [blame] | 5926 | wl_list_for_each_safe(view, tmp, &switcher->shell->minimized_layer.view_list.link, layer_link.link) { |
| 5927 | weston_layer_entry_remove(&view->layer_link); |
| 5928 | weston_layer_entry_insert(&ws->layer.view_list, &view->layer_link); |
Manuel Bachmann | c1ae2e8 | 2014-02-26 15:53:11 +0100 | [diff] [blame] | 5929 | minimized = wl_array_add(&switcher->minimized_array, sizeof *minimized); |
| 5930 | *minimized = view; |
| 5931 | } |
| 5932 | |
Giulio Camuffo | 412e6a5 | 2014-07-09 22:12:56 +0300 | [diff] [blame] | 5933 | 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] | 5934 | shsurf = get_shell_surface(view->surface); |
Rafael Antognolli | 5031cbe | 2013-12-05 19:01:21 -0200 | [diff] [blame] | 5935 | if (shsurf && |
| 5936 | shsurf->type == SHELL_SURFACE_TOPLEVEL && |
| 5937 | shsurf->parent == NULL) { |
Kristian Høgsberg | 0704539 | 2012-02-19 18:52:44 -0500 | [diff] [blame] | 5938 | if (first == NULL) |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 5939 | first = view->surface; |
Kristian Høgsberg | 0704539 | 2012-02-19 18:52:44 -0500 | [diff] [blame] | 5940 | if (prev == switcher->current) |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 5941 | next = view->surface; |
| 5942 | prev = view->surface; |
| 5943 | view->alpha = 0.25; |
| 5944 | weston_view_geometry_dirty(view); |
| 5945 | weston_surface_damage(view->surface); |
Kristian Høgsberg | 0704539 | 2012-02-19 18:52:44 -0500 | [diff] [blame] | 5946 | } |
Alex Wu | 1659daa | 2012-04-01 20:13:09 +0800 | [diff] [blame] | 5947 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 5948 | if (is_black_surface(view->surface, NULL)) { |
| 5949 | view->alpha = 0.25; |
| 5950 | weston_view_geometry_dirty(view); |
| 5951 | weston_surface_damage(view->surface); |
Alex Wu | 1659daa | 2012-04-01 20:13:09 +0800 | [diff] [blame] | 5952 | } |
Kristian Høgsberg | 0704539 | 2012-02-19 18:52:44 -0500 | [diff] [blame] | 5953 | } |
| 5954 | |
| 5955 | if (next == NULL) |
| 5956 | next = first; |
| 5957 | |
Alex Wu | 07b2606 | 2012-03-12 16:06:01 +0800 | [diff] [blame] | 5958 | if (next == NULL) |
| 5959 | return; |
| 5960 | |
Kristian Høgsberg | 0704539 | 2012-02-19 18:52:44 -0500 | [diff] [blame] | 5961 | wl_list_remove(&switcher->listener.link); |
Jason Ekstrand | 26ed73c | 2013-06-06 22:34:41 -0500 | [diff] [blame] | 5962 | wl_signal_add(&next->destroy_signal, &switcher->listener); |
Kristian Høgsberg | 0704539 | 2012-02-19 18:52:44 -0500 | [diff] [blame] | 5963 | |
| 5964 | switcher->current = next; |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 5965 | wl_list_for_each(view, &next->views, surface_link) |
| 5966 | view->alpha = 1.0; |
Alex Wu | 1659daa | 2012-04-01 20:13:09 +0800 | [diff] [blame] | 5967 | |
Kristian Høgsberg | 32e5686 | 2012-04-02 22:18:58 -0400 | [diff] [blame] | 5968 | shsurf = get_shell_surface(switcher->current); |
Rafael Antognolli | 03b1659 | 2013-12-03 15:35:42 -0200 | [diff] [blame] | 5969 | if (shsurf && shsurf->state.fullscreen) |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 5970 | shsurf->fullscreen.black_view->alpha = 1.0; |
Kristian Høgsberg | 0704539 | 2012-02-19 18:52:44 -0500 | [diff] [blame] | 5971 | } |
| 5972 | |
| 5973 | static void |
Kristian Høgsberg | 27e3052 | 2012-04-11 23:18:23 -0400 | [diff] [blame] | 5974 | switcher_handle_surface_destroy(struct wl_listener *listener, void *data) |
Kristian Høgsberg | 0704539 | 2012-02-19 18:52:44 -0500 | [diff] [blame] | 5975 | { |
| 5976 | struct switcher *switcher = |
| 5977 | container_of(listener, struct switcher, listener); |
| 5978 | |
| 5979 | switcher_next(switcher); |
| 5980 | } |
| 5981 | |
| 5982 | static void |
Daniel Stone | 351eb61 | 2012-05-31 15:27:47 -0400 | [diff] [blame] | 5983 | switcher_destroy(struct switcher *switcher) |
Kristian Høgsberg | 0704539 | 2012-02-19 18:52:44 -0500 | [diff] [blame] | 5984 | { |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 5985 | struct weston_view *view; |
Kristian Høgsberg | 29139d4 | 2013-04-18 15:25:39 -0400 | [diff] [blame] | 5986 | struct weston_keyboard *keyboard = switcher->grab.keyboard; |
Kristian Høgsberg | b0d8e77 | 2012-06-18 16:34:58 -0400 | [diff] [blame] | 5987 | struct workspace *ws = get_current_workspace(switcher->shell); |
Kristian Høgsberg | 0704539 | 2012-02-19 18:52:44 -0500 | [diff] [blame] | 5988 | |
Giulio Camuffo | 412e6a5 | 2014-07-09 22:12:56 +0300 | [diff] [blame] | 5989 | 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] | 5990 | if (is_focus_view(view)) |
| 5991 | continue; |
| 5992 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 5993 | view->alpha = 1.0; |
| 5994 | weston_surface_damage(view->surface); |
Kristian Høgsberg | 0704539 | 2012-02-19 18:52:44 -0500 | [diff] [blame] | 5995 | } |
| 5996 | |
Alex Wu | 07b2606 | 2012-03-12 16:06:01 +0800 | [diff] [blame] | 5997 | if (switcher->current) |
Daniel Stone | 37816df | 2012-05-16 18:45:18 +0100 | [diff] [blame] | 5998 | activate(switcher->shell, switcher->current, |
Derek Foreman | 8aeeac8 | 2015-01-30 13:24:36 -0600 | [diff] [blame] | 5999 | keyboard->seat, true); |
Kristian Høgsberg | 0704539 | 2012-02-19 18:52:44 -0500 | [diff] [blame] | 6000 | wl_list_remove(&switcher->listener.link); |
Kristian Høgsberg | 29139d4 | 2013-04-18 15:25:39 -0400 | [diff] [blame] | 6001 | weston_keyboard_end_grab(keyboard); |
| 6002 | if (keyboard->input_method_resource) |
| 6003 | keyboard->grab = &keyboard->input_method_grab; |
Manuel Bachmann | c1ae2e8 | 2014-02-26 15:53:11 +0100 | [diff] [blame] | 6004 | |
| 6005 | /* re-hide surfaces that were temporary shown during the switch */ |
| 6006 | struct weston_view **minimized; |
| 6007 | wl_array_for_each(minimized, &switcher->minimized_array) { |
| 6008 | /* with the exception of the current selected */ |
| 6009 | if ((*minimized)->surface != switcher->current) { |
Giulio Camuffo | 412e6a5 | 2014-07-09 22:12:56 +0300 | [diff] [blame] | 6010 | weston_layer_entry_remove(&(*minimized)->layer_link); |
| 6011 | 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] | 6012 | weston_view_damage_below(*minimized); |
| 6013 | } |
| 6014 | } |
| 6015 | wl_array_release(&switcher->minimized_array); |
| 6016 | |
Kristian Høgsberg | 0704539 | 2012-02-19 18:52:44 -0500 | [diff] [blame] | 6017 | free(switcher); |
| 6018 | } |
| 6019 | |
| 6020 | static void |
Kristian Høgsberg | 29139d4 | 2013-04-18 15:25:39 -0400 | [diff] [blame] | 6021 | switcher_key(struct weston_keyboard_grab *grab, |
Daniel Stone | c9785ea | 2012-05-30 16:31:52 +0100 | [diff] [blame] | 6022 | uint32_t time, uint32_t key, uint32_t state_w) |
Kristian Høgsberg | 0704539 | 2012-02-19 18:52:44 -0500 | [diff] [blame] | 6023 | { |
| 6024 | struct switcher *switcher = container_of(grab, struct switcher, grab); |
Daniel Stone | c9785ea | 2012-05-30 16:31:52 +0100 | [diff] [blame] | 6025 | enum wl_keyboard_key_state state = state_w; |
Daniel Stone | 351eb61 | 2012-05-31 15:27:47 -0400 | [diff] [blame] | 6026 | |
Daniel Stone | c9785ea | 2012-05-30 16:31:52 +0100 | [diff] [blame] | 6027 | if (key == KEY_TAB && state == WL_KEYBOARD_KEY_STATE_PRESSED) |
Daniel Stone | 351eb61 | 2012-05-31 15:27:47 -0400 | [diff] [blame] | 6028 | switcher_next(switcher); |
| 6029 | } |
| 6030 | |
| 6031 | static void |
Kristian Høgsberg | 29139d4 | 2013-04-18 15:25:39 -0400 | [diff] [blame] | 6032 | switcher_modifier(struct weston_keyboard_grab *grab, uint32_t serial, |
Daniel Stone | 351eb61 | 2012-05-31 15:27:47 -0400 | [diff] [blame] | 6033 | uint32_t mods_depressed, uint32_t mods_latched, |
| 6034 | uint32_t mods_locked, uint32_t group) |
| 6035 | { |
| 6036 | struct switcher *switcher = container_of(grab, struct switcher, grab); |
Derek Foreman | 8aeeac8 | 2015-01-30 13:24:36 -0600 | [diff] [blame] | 6037 | struct weston_seat *seat = grab->keyboard->seat; |
Kristian Høgsberg | 0704539 | 2012-02-19 18:52:44 -0500 | [diff] [blame] | 6038 | |
Daniel Stone | 351eb61 | 2012-05-31 15:27:47 -0400 | [diff] [blame] | 6039 | if ((seat->modifier_state & switcher->shell->binding_modifier) == 0) |
| 6040 | switcher_destroy(switcher); |
Kristian Høgsberg | b71302e | 2012-05-10 12:28:35 -0400 | [diff] [blame] | 6041 | } |
Kristian Høgsberg | 0704539 | 2012-02-19 18:52:44 -0500 | [diff] [blame] | 6042 | |
Jonas Ådahl | 1ea343e | 2013-10-25 23:18:05 +0200 | [diff] [blame] | 6043 | static void |
| 6044 | switcher_cancel(struct weston_keyboard_grab *grab) |
| 6045 | { |
| 6046 | struct switcher *switcher = container_of(grab, struct switcher, grab); |
| 6047 | |
| 6048 | switcher_destroy(switcher); |
| 6049 | } |
| 6050 | |
Kristian Høgsberg | 29139d4 | 2013-04-18 15:25:39 -0400 | [diff] [blame] | 6051 | static const struct weston_keyboard_grab_interface switcher_grab = { |
Daniel Stone | 351eb61 | 2012-05-31 15:27:47 -0400 | [diff] [blame] | 6052 | switcher_key, |
| 6053 | switcher_modifier, |
Jonas Ådahl | 1ea343e | 2013-10-25 23:18:05 +0200 | [diff] [blame] | 6054 | switcher_cancel, |
Kristian Høgsberg | 0704539 | 2012-02-19 18:52:44 -0500 | [diff] [blame] | 6055 | }; |
| 6056 | |
| 6057 | static void |
Derek Foreman | 8ae2db5 | 2015-07-15 13:00:36 -0500 | [diff] [blame] | 6058 | switcher_binding(struct weston_keyboard *keyboard, uint32_t time, |
| 6059 | uint32_t key, void *data) |
Kristian Høgsberg | 0704539 | 2012-02-19 18:52:44 -0500 | [diff] [blame] | 6060 | { |
Tiago Vignatti | be14326 | 2012-04-16 17:31:41 +0300 | [diff] [blame] | 6061 | struct desktop_shell *shell = data; |
Kristian Høgsberg | 0704539 | 2012-02-19 18:52:44 -0500 | [diff] [blame] | 6062 | struct switcher *switcher; |
| 6063 | |
| 6064 | switcher = malloc(sizeof *switcher); |
Kristian Høgsberg | 02e79dc | 2012-04-12 09:55:26 -0400 | [diff] [blame] | 6065 | switcher->shell = shell; |
Kristian Høgsberg | 0704539 | 2012-02-19 18:52:44 -0500 | [diff] [blame] | 6066 | switcher->current = NULL; |
Kristian Høgsberg | 27e3052 | 2012-04-11 23:18:23 -0400 | [diff] [blame] | 6067 | switcher->listener.notify = switcher_handle_surface_destroy; |
Kristian Høgsberg | 0704539 | 2012-02-19 18:52:44 -0500 | [diff] [blame] | 6068 | wl_list_init(&switcher->listener.link); |
Manuel Bachmann | c1ae2e8 | 2014-02-26 15:53:11 +0100 | [diff] [blame] | 6069 | wl_array_init(&switcher->minimized_array); |
Kristian Høgsberg | 0704539 | 2012-02-19 18:52:44 -0500 | [diff] [blame] | 6070 | |
Alexander Larsson | f82b6ca | 2013-05-28 16:23:39 +0200 | [diff] [blame] | 6071 | restore_all_output_modes(shell->compositor); |
Mario Kleiner | 9f4d655 | 2015-06-21 21:25:08 +0200 | [diff] [blame] | 6072 | lower_fullscreen_layer(switcher->shell, NULL); |
Kristian Høgsberg | 0704539 | 2012-02-19 18:52:44 -0500 | [diff] [blame] | 6073 | switcher->grab.interface = &switcher_grab; |
Derek Foreman | 8ae2db5 | 2015-07-15 13:00:36 -0500 | [diff] [blame] | 6074 | weston_keyboard_start_grab(keyboard, &switcher->grab); |
| 6075 | weston_keyboard_set_focus(keyboard, NULL); |
Kristian Høgsberg | 0704539 | 2012-02-19 18:52:44 -0500 | [diff] [blame] | 6076 | switcher_next(switcher); |
| 6077 | } |
| 6078 | |
Pekka Paalanen | 3c64723 | 2011-12-22 13:43:43 +0200 | [diff] [blame] | 6079 | static void |
Derek Foreman | 8ae2db5 | 2015-07-15 13:00:36 -0500 | [diff] [blame] | 6080 | backlight_binding(struct weston_keyboard *keyboard, uint32_t time, |
| 6081 | uint32_t key, void *data) |
Tiago Vignatti | 8e53c7f | 2012-02-29 19:53:50 +0200 | [diff] [blame] | 6082 | { |
| 6083 | struct weston_compositor *compositor = data; |
| 6084 | struct weston_output *output; |
Tiago Vignatti | 5ab91ad | 2012-03-12 19:40:09 -0300 | [diff] [blame] | 6085 | long backlight_new = 0; |
Tiago Vignatti | 8e53c7f | 2012-02-29 19:53:50 +0200 | [diff] [blame] | 6086 | |
| 6087 | /* TODO: we're limiting to simple use cases, where we assume just |
| 6088 | * control on the primary display. We'd have to extend later if we |
| 6089 | * ever get support for setting backlights on random desktop LCD |
| 6090 | * panels though */ |
| 6091 | output = get_default_output(compositor); |
| 6092 | if (!output) |
| 6093 | return; |
| 6094 | |
| 6095 | if (!output->set_backlight) |
| 6096 | return; |
| 6097 | |
Tiago Vignatti | 5ab91ad | 2012-03-12 19:40:09 -0300 | [diff] [blame] | 6098 | if (key == KEY_F9 || key == KEY_BRIGHTNESSDOWN) |
| 6099 | backlight_new = output->backlight_current - 25; |
| 6100 | else if (key == KEY_F10 || key == KEY_BRIGHTNESSUP) |
| 6101 | backlight_new = output->backlight_current + 25; |
Tiago Vignatti | 8e53c7f | 2012-02-29 19:53:50 +0200 | [diff] [blame] | 6102 | |
Tiago Vignatti | 5ab91ad | 2012-03-12 19:40:09 -0300 | [diff] [blame] | 6103 | if (backlight_new < 5) |
| 6104 | backlight_new = 5; |
| 6105 | if (backlight_new > 255) |
| 6106 | backlight_new = 255; |
| 6107 | |
| 6108 | output->backlight_current = backlight_new; |
Tiago Vignatti | 8e53c7f | 2012-02-29 19:53:50 +0200 | [diff] [blame] | 6109 | output->set_backlight(output, output->backlight_current); |
| 6110 | } |
| 6111 | |
Kristian Høgsberg | b41c081 | 2012-03-04 14:53:40 -0500 | [diff] [blame] | 6112 | static void |
Derek Foreman | 8ae2db5 | 2015-07-15 13:00:36 -0500 | [diff] [blame] | 6113 | force_kill_binding(struct weston_keyboard *keyboard, uint32_t time, |
| 6114 | uint32_t key, void *data) |
Kristian Høgsberg | 92a57db | 2012-05-26 13:41:06 -0400 | [diff] [blame] | 6115 | { |
Kristian Høgsberg | fe7aa90 | 2013-05-08 09:54:37 -0400 | [diff] [blame] | 6116 | struct weston_surface *focus_surface; |
Kristian Høgsberg | 92a57db | 2012-05-26 13:41:06 -0400 | [diff] [blame] | 6117 | struct wl_client *client; |
Tiago Vignatti | 1d01b01 | 2012-09-27 17:48:36 +0300 | [diff] [blame] | 6118 | struct desktop_shell *shell = data; |
| 6119 | struct weston_compositor *compositor = shell->compositor; |
Kristian Høgsberg | 92a57db | 2012-05-26 13:41:06 -0400 | [diff] [blame] | 6120 | pid_t pid; |
Kristian Høgsberg | 92a57db | 2012-05-26 13:41:06 -0400 | [diff] [blame] | 6121 | |
Derek Foreman | 8ae2db5 | 2015-07-15 13:00:36 -0500 | [diff] [blame] | 6122 | focus_surface = keyboard->focus; |
Philipp Brüschweiler | 6cef009 | 2012-08-13 21:27:27 +0200 | [diff] [blame] | 6123 | if (!focus_surface) |
| 6124 | return; |
| 6125 | |
Tiago Vignatti | 1d01b01 | 2012-09-27 17:48:36 +0300 | [diff] [blame] | 6126 | wl_signal_emit(&compositor->kill_signal, focus_surface); |
| 6127 | |
Jason Ekstrand | 26ed73c | 2013-06-06 22:34:41 -0500 | [diff] [blame] | 6128 | client = wl_resource_get_client(focus_surface->resource); |
Tiago Vignatti | 920f197 | 2012-09-27 17:48:35 +0300 | [diff] [blame] | 6129 | wl_client_get_credentials(client, &pid, NULL, NULL); |
| 6130 | |
| 6131 | /* Skip clients that we launched ourselves (the credentials of |
| 6132 | * the socketpair is ours) */ |
| 6133 | if (pid == getpid()) |
| 6134 | return; |
Kristian Høgsberg | 92a57db | 2012-05-26 13:41:06 -0400 | [diff] [blame] | 6135 | |
Daniel Stone | 325fc2d | 2012-05-30 16:31:58 +0100 | [diff] [blame] | 6136 | kill(pid, SIGKILL); |
Kristian Høgsberg | 92a57db | 2012-05-26 13:41:06 -0400 | [diff] [blame] | 6137 | } |
| 6138 | |
| 6139 | static void |
Derek Foreman | 8ae2db5 | 2015-07-15 13:00:36 -0500 | [diff] [blame] | 6140 | workspace_up_binding(struct weston_keyboard *keyboard, uint32_t time, |
Jonas Ådahl | e3cddce | 2012-06-13 00:01:22 +0200 | [diff] [blame] | 6141 | uint32_t key, void *data) |
| 6142 | { |
| 6143 | struct desktop_shell *shell = data; |
| 6144 | unsigned int new_index = shell->workspaces.current; |
| 6145 | |
Kristian Høgsberg | ce345b0 | 2012-06-25 21:35:29 -0400 | [diff] [blame] | 6146 | if (shell->locked) |
Kristian Høgsberg | 4476aaf | 2012-06-25 14:03:13 -0400 | [diff] [blame] | 6147 | return; |
Jonas Ådahl | e3cddce | 2012-06-13 00:01:22 +0200 | [diff] [blame] | 6148 | if (new_index != 0) |
| 6149 | new_index--; |
| 6150 | |
| 6151 | change_workspace(shell, new_index); |
| 6152 | } |
| 6153 | |
| 6154 | static void |
Derek Foreman | 8ae2db5 | 2015-07-15 13:00:36 -0500 | [diff] [blame] | 6155 | workspace_down_binding(struct weston_keyboard *keyboard, uint32_t time, |
Jonas Ådahl | e3cddce | 2012-06-13 00:01:22 +0200 | [diff] [blame] | 6156 | uint32_t key, void *data) |
| 6157 | { |
| 6158 | struct desktop_shell *shell = data; |
| 6159 | unsigned int new_index = shell->workspaces.current; |
| 6160 | |
Kristian Høgsberg | ce345b0 | 2012-06-25 21:35:29 -0400 | [diff] [blame] | 6161 | if (shell->locked) |
Kristian Høgsberg | 4476aaf | 2012-06-25 14:03:13 -0400 | [diff] [blame] | 6162 | return; |
Jonas Ådahl | e3cddce | 2012-06-13 00:01:22 +0200 | [diff] [blame] | 6163 | if (new_index < shell->workspaces.num - 1) |
| 6164 | new_index++; |
| 6165 | |
| 6166 | change_workspace(shell, new_index); |
| 6167 | } |
| 6168 | |
| 6169 | static void |
Derek Foreman | 8ae2db5 | 2015-07-15 13:00:36 -0500 | [diff] [blame] | 6170 | workspace_f_binding(struct weston_keyboard *keyboard, uint32_t time, |
Jonas Ådahl | e3cddce | 2012-06-13 00:01:22 +0200 | [diff] [blame] | 6171 | uint32_t key, void *data) |
| 6172 | { |
| 6173 | struct desktop_shell *shell = data; |
| 6174 | unsigned int new_index; |
| 6175 | |
Kristian Høgsberg | ce345b0 | 2012-06-25 21:35:29 -0400 | [diff] [blame] | 6176 | if (shell->locked) |
Kristian Høgsberg | 4476aaf | 2012-06-25 14:03:13 -0400 | [diff] [blame] | 6177 | return; |
Jonas Ådahl | e3cddce | 2012-06-13 00:01:22 +0200 | [diff] [blame] | 6178 | new_index = key - KEY_F1; |
| 6179 | if (new_index >= shell->workspaces.num) |
| 6180 | new_index = shell->workspaces.num - 1; |
| 6181 | |
| 6182 | change_workspace(shell, new_index); |
| 6183 | } |
| 6184 | |
Jonas Ådahl | 8de6a1d | 2012-08-29 22:13:00 +0200 | [diff] [blame] | 6185 | static void |
Derek Foreman | 8ae2db5 | 2015-07-15 13:00:36 -0500 | [diff] [blame] | 6186 | workspace_move_surface_up_binding(struct weston_keyboard *keyboard, |
| 6187 | uint32_t time, uint32_t key, void *data) |
Jonas Ådahl | 8de6a1d | 2012-08-29 22:13:00 +0200 | [diff] [blame] | 6188 | { |
| 6189 | struct desktop_shell *shell = data; |
| 6190 | unsigned int new_index = shell->workspaces.current; |
| 6191 | |
| 6192 | if (shell->locked) |
| 6193 | return; |
| 6194 | |
| 6195 | if (new_index != 0) |
| 6196 | new_index--; |
| 6197 | |
Derek Foreman | 8ae2db5 | 2015-07-15 13:00:36 -0500 | [diff] [blame] | 6198 | take_surface_to_workspace_by_seat(shell, keyboard->seat, new_index); |
Jonas Ådahl | 8de6a1d | 2012-08-29 22:13:00 +0200 | [diff] [blame] | 6199 | } |
| 6200 | |
| 6201 | static void |
Derek Foreman | 8ae2db5 | 2015-07-15 13:00:36 -0500 | [diff] [blame] | 6202 | workspace_move_surface_down_binding(struct weston_keyboard *keyboard, |
| 6203 | uint32_t time, uint32_t key, void *data) |
Jonas Ådahl | 8de6a1d | 2012-08-29 22:13:00 +0200 | [diff] [blame] | 6204 | { |
| 6205 | struct desktop_shell *shell = data; |
| 6206 | unsigned int new_index = shell->workspaces.current; |
| 6207 | |
| 6208 | if (shell->locked) |
| 6209 | return; |
| 6210 | |
| 6211 | if (new_index < shell->workspaces.num - 1) |
| 6212 | new_index++; |
| 6213 | |
Derek Foreman | 8ae2db5 | 2015-07-15 13:00:36 -0500 | [diff] [blame] | 6214 | take_surface_to_workspace_by_seat(shell, keyboard->seat, new_index); |
Jonas Ådahl | 8de6a1d | 2012-08-29 22:13:00 +0200 | [diff] [blame] | 6215 | } |
Jonas Ådahl | e3cddce | 2012-06-13 00:01:22 +0200 | [diff] [blame] | 6216 | |
| 6217 | static void |
Ander Conselvan de Oliveira | c94d622 | 2014-01-29 18:47:54 +0200 | [diff] [blame] | 6218 | shell_reposition_view_on_output_destroy(struct weston_view *view) |
| 6219 | { |
| 6220 | struct weston_output *output, *first_output; |
| 6221 | struct weston_compositor *ec = view->surface->compositor; |
| 6222 | struct shell_surface *shsurf; |
| 6223 | float x, y; |
| 6224 | int visible; |
| 6225 | |
| 6226 | x = view->geometry.x; |
| 6227 | y = view->geometry.y; |
| 6228 | |
| 6229 | /* At this point the destroyed output is not in the list anymore. |
| 6230 | * If the view is still visible somewhere, we leave where it is, |
| 6231 | * otherwise, move it to the first output. */ |
| 6232 | visible = 0; |
| 6233 | wl_list_for_each(output, &ec->output_list, link) { |
| 6234 | if (pixman_region32_contains_point(&output->region, |
| 6235 | x, y, NULL)) { |
| 6236 | visible = 1; |
| 6237 | break; |
| 6238 | } |
| 6239 | } |
| 6240 | |
| 6241 | if (!visible) { |
| 6242 | first_output = container_of(ec->output_list.next, |
| 6243 | struct weston_output, link); |
| 6244 | |
| 6245 | x = first_output->x + first_output->width / 4; |
| 6246 | y = first_output->y + first_output->height / 4; |
Xiong Zhang | 62899f5 | 2014-03-07 16:27:19 +0800 | [diff] [blame] | 6247 | |
| 6248 | weston_view_set_position(view, x, y); |
| 6249 | } else { |
| 6250 | weston_view_geometry_dirty(view); |
Ander Conselvan de Oliveira | c94d622 | 2014-01-29 18:47:54 +0200 | [diff] [blame] | 6251 | } |
| 6252 | |
Ander Conselvan de Oliveira | c94d622 | 2014-01-29 18:47:54 +0200 | [diff] [blame] | 6253 | |
| 6254 | shsurf = get_shell_surface(view->surface); |
| 6255 | |
| 6256 | if (shsurf) { |
| 6257 | shsurf->saved_position_valid = false; |
| 6258 | shsurf->next_state.maximized = false; |
| 6259 | shsurf->next_state.fullscreen = false; |
| 6260 | shsurf->state_changed = true; |
| 6261 | } |
| 6262 | } |
| 6263 | |
Ander Conselvan de Oliveira | 304996d | 2014-04-11 13:57:15 +0300 | [diff] [blame] | 6264 | void |
| 6265 | shell_for_each_layer(struct desktop_shell *shell, |
| 6266 | shell_for_each_layer_func_t func, void *data) |
Ander Conselvan de Oliveira | c94d622 | 2014-01-29 18:47:54 +0200 | [diff] [blame] | 6267 | { |
Ander Conselvan de Oliveira | 304996d | 2014-04-11 13:57:15 +0300 | [diff] [blame] | 6268 | struct workspace **ws; |
| 6269 | |
| 6270 | func(shell, &shell->fullscreen_layer, data); |
| 6271 | func(shell, &shell->panel_layer, data); |
| 6272 | func(shell, &shell->background_layer, data); |
| 6273 | func(shell, &shell->lock_layer, data); |
| 6274 | func(shell, &shell->input_panel_layer, data); |
| 6275 | |
| 6276 | wl_array_for_each(ws, &shell->workspaces.array) |
| 6277 | func(shell, &(*ws)->layer, data); |
| 6278 | } |
| 6279 | |
| 6280 | static void |
| 6281 | shell_output_destroy_move_layer(struct desktop_shell *shell, |
| 6282 | struct weston_layer *layer, |
| 6283 | void *data) |
| 6284 | { |
| 6285 | struct weston_output *output = data; |
Ander Conselvan de Oliveira | c94d622 | 2014-01-29 18:47:54 +0200 | [diff] [blame] | 6286 | struct weston_view *view; |
| 6287 | |
Giulio Camuffo | 412e6a5 | 2014-07-09 22:12:56 +0300 | [diff] [blame] | 6288 | 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] | 6289 | if (view->output != output) |
| 6290 | continue; |
Ander Conselvan de Oliveira | c94d622 | 2014-01-29 18:47:54 +0200 | [diff] [blame] | 6291 | |
Ander Conselvan de Oliveira | 304996d | 2014-04-11 13:57:15 +0300 | [diff] [blame] | 6292 | shell_reposition_view_on_output_destroy(view); |
Ander Conselvan de Oliveira | c94d622 | 2014-01-29 18:47:54 +0200 | [diff] [blame] | 6293 | } |
| 6294 | } |
| 6295 | |
| 6296 | static void |
Xiong Zhang | 6b48142 | 2013-10-23 13:58:32 +0800 | [diff] [blame] | 6297 | handle_output_destroy(struct wl_listener *listener, void *data) |
| 6298 | { |
| 6299 | struct shell_output *output_listener = |
| 6300 | container_of(listener, struct shell_output, destroy_listener); |
Ander Conselvan de Oliveira | 304996d | 2014-04-11 13:57:15 +0300 | [diff] [blame] | 6301 | struct weston_output *output = output_listener->output; |
| 6302 | struct desktop_shell *shell = output_listener->shell; |
Xiong Zhang | 6b48142 | 2013-10-23 13:58:32 +0800 | [diff] [blame] | 6303 | |
Ander Conselvan de Oliveira | 304996d | 2014-04-11 13:57:15 +0300 | [diff] [blame] | 6304 | 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] | 6305 | |
Xiong Zhang | 6b48142 | 2013-10-23 13:58:32 +0800 | [diff] [blame] | 6306 | wl_list_remove(&output_listener->destroy_listener.link); |
| 6307 | wl_list_remove(&output_listener->link); |
| 6308 | free(output_listener); |
| 6309 | } |
| 6310 | |
| 6311 | static void |
| 6312 | create_shell_output(struct desktop_shell *shell, |
| 6313 | struct weston_output *output) |
| 6314 | { |
| 6315 | struct shell_output *shell_output; |
| 6316 | |
| 6317 | shell_output = zalloc(sizeof *shell_output); |
| 6318 | if (shell_output == NULL) |
| 6319 | return; |
| 6320 | |
| 6321 | shell_output->output = output; |
| 6322 | shell_output->shell = shell; |
| 6323 | shell_output->destroy_listener.notify = handle_output_destroy; |
| 6324 | wl_signal_add(&output->destroy_signal, |
| 6325 | &shell_output->destroy_listener); |
Kristian Høgsberg | a3a0e18 | 2013-10-23 23:36:04 -0700 | [diff] [blame] | 6326 | wl_list_insert(shell->output_list.prev, &shell_output->link); |
Xiong Zhang | 6b48142 | 2013-10-23 13:58:32 +0800 | [diff] [blame] | 6327 | } |
| 6328 | |
| 6329 | static void |
| 6330 | handle_output_create(struct wl_listener *listener, void *data) |
| 6331 | { |
| 6332 | struct desktop_shell *shell = |
| 6333 | container_of(listener, struct desktop_shell, output_create_listener); |
| 6334 | struct weston_output *output = (struct weston_output *)data; |
| 6335 | |
| 6336 | create_shell_output(shell, output); |
| 6337 | } |
| 6338 | |
| 6339 | static void |
Ander Conselvan de Oliveira | 304996d | 2014-04-11 13:57:15 +0300 | [diff] [blame] | 6340 | handle_output_move_layer(struct desktop_shell *shell, |
| 6341 | struct weston_layer *layer, void *data) |
Ander Conselvan de Oliveira | a8a9baf | 2014-01-29 18:47:52 +0200 | [diff] [blame] | 6342 | { |
Ander Conselvan de Oliveira | 304996d | 2014-04-11 13:57:15 +0300 | [diff] [blame] | 6343 | struct weston_output *output = data; |
Ander Conselvan de Oliveira | a8a9baf | 2014-01-29 18:47:52 +0200 | [diff] [blame] | 6344 | struct weston_view *view; |
| 6345 | float x, y; |
| 6346 | |
Giulio Camuffo | 412e6a5 | 2014-07-09 22:12:56 +0300 | [diff] [blame] | 6347 | 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] | 6348 | if (view->output != output) |
| 6349 | continue; |
| 6350 | |
| 6351 | x = view->geometry.x + output->move_x; |
| 6352 | y = view->geometry.y + output->move_y; |
| 6353 | weston_view_set_position(view, x, y); |
| 6354 | } |
| 6355 | } |
| 6356 | |
| 6357 | static void |
| 6358 | handle_output_move(struct wl_listener *listener, void *data) |
| 6359 | { |
| 6360 | struct desktop_shell *shell; |
| 6361 | |
Ander Conselvan de Oliveira | a8a9baf | 2014-01-29 18:47:52 +0200 | [diff] [blame] | 6362 | shell = container_of(listener, struct desktop_shell, |
| 6363 | output_move_listener); |
Ander Conselvan de Oliveira | a8a9baf | 2014-01-29 18:47:52 +0200 | [diff] [blame] | 6364 | |
Ander Conselvan de Oliveira | 304996d | 2014-04-11 13:57:15 +0300 | [diff] [blame] | 6365 | shell_for_each_layer(shell, handle_output_move_layer, data); |
Ander Conselvan de Oliveira | a8a9baf | 2014-01-29 18:47:52 +0200 | [diff] [blame] | 6366 | } |
| 6367 | |
| 6368 | static void |
Xiong Zhang | 6b48142 | 2013-10-23 13:58:32 +0800 | [diff] [blame] | 6369 | setup_output_destroy_handler(struct weston_compositor *ec, |
| 6370 | struct desktop_shell *shell) |
| 6371 | { |
| 6372 | struct weston_output *output; |
| 6373 | |
| 6374 | wl_list_init(&shell->output_list); |
| 6375 | wl_list_for_each(output, &ec->output_list, link) |
| 6376 | create_shell_output(shell, output); |
| 6377 | |
| 6378 | shell->output_create_listener.notify = handle_output_create; |
| 6379 | wl_signal_add(&ec->output_created_signal, |
| 6380 | &shell->output_create_listener); |
Ander Conselvan de Oliveira | a8a9baf | 2014-01-29 18:47:52 +0200 | [diff] [blame] | 6381 | |
| 6382 | shell->output_move_listener.notify = handle_output_move; |
| 6383 | wl_signal_add(&ec->output_moved_signal, &shell->output_move_listener); |
Xiong Zhang | 6b48142 | 2013-10-23 13:58:32 +0800 | [diff] [blame] | 6384 | } |
| 6385 | |
| 6386 | static void |
Kristian Høgsberg | 02e79dc | 2012-04-12 09:55:26 -0400 | [diff] [blame] | 6387 | shell_destroy(struct wl_listener *listener, void *data) |
Pekka Paalanen | 3c64723 | 2011-12-22 13:43:43 +0200 | [diff] [blame] | 6388 | { |
Tiago Vignatti | be14326 | 2012-04-16 17:31:41 +0300 | [diff] [blame] | 6389 | struct desktop_shell *shell = |
| 6390 | container_of(listener, struct desktop_shell, destroy_listener); |
Jonas Ådahl | e3cddce | 2012-06-13 00:01:22 +0200 | [diff] [blame] | 6391 | struct workspace **ws; |
Xiong Zhang | 6b48142 | 2013-10-23 13:58:32 +0800 | [diff] [blame] | 6392 | struct shell_output *shell_output, *tmp; |
Pekka Paalanen | 3c64723 | 2011-12-22 13:43:43 +0200 | [diff] [blame] | 6393 | |
Kristian Høgsberg | 17bccae | 2014-01-16 16:46:28 -0800 | [diff] [blame] | 6394 | /* Force state to unlocked so we don't try to fade */ |
| 6395 | shell->locked = false; |
Pekka Paalanen | 826dc14 | 2014-08-27 12:11:53 +0300 | [diff] [blame] | 6396 | |
| 6397 | if (shell->child.client) { |
| 6398 | /* disable respawn */ |
| 6399 | wl_list_remove(&shell->child.client_destroy_listener.link); |
Pekka Paalanen | 9cf5cc8 | 2012-01-02 16:00:24 +0200 | [diff] [blame] | 6400 | wl_client_destroy(shell->child.client); |
Pekka Paalanen | 826dc14 | 2014-08-27 12:11:53 +0300 | [diff] [blame] | 6401 | } |
Pekka Paalanen | 9cf5cc8 | 2012-01-02 16:00:24 +0200 | [diff] [blame] | 6402 | |
Ander Conselvan de Oliveira | a457563 | 2013-02-21 18:35:23 +0200 | [diff] [blame] | 6403 | wl_list_remove(&shell->idle_listener.link); |
| 6404 | wl_list_remove(&shell->wake_listener.link); |
Giulio Camuffo | f05d18f | 2015-12-11 20:57:05 +0200 | [diff] [blame] | 6405 | wl_list_remove(&shell->transform_listener.link); |
Kristian Høgsberg | 677a5f5 | 2013-12-04 11:00:19 -0800 | [diff] [blame] | 6406 | |
Pekka Paalanen | aa9536a | 2015-06-24 16:09:17 +0300 | [diff] [blame] | 6407 | text_backend_destroy(shell->text_backend); |
Kristian Høgsberg | 677a5f5 | 2013-12-04 11:00:19 -0800 | [diff] [blame] | 6408 | input_panel_destroy(shell); |
Kristian Høgsberg | 88c1607 | 2012-05-16 08:04:19 -0400 | [diff] [blame] | 6409 | |
Xiong Zhang | 6b48142 | 2013-10-23 13:58:32 +0800 | [diff] [blame] | 6410 | wl_list_for_each_safe(shell_output, tmp, &shell->output_list, link) { |
| 6411 | wl_list_remove(&shell_output->destroy_listener.link); |
| 6412 | wl_list_remove(&shell_output->link); |
| 6413 | free(shell_output); |
| 6414 | } |
| 6415 | |
| 6416 | wl_list_remove(&shell->output_create_listener.link); |
Kristian Høgsberg | 6d50b0f | 2014-04-30 20:46:25 -0700 | [diff] [blame] | 6417 | wl_list_remove(&shell->output_move_listener.link); |
Xiong Zhang | 6b48142 | 2013-10-23 13:58:32 +0800 | [diff] [blame] | 6418 | |
Jonas Ådahl | e3cddce | 2012-06-13 00:01:22 +0200 | [diff] [blame] | 6419 | wl_array_for_each(ws, &shell->workspaces.array) |
| 6420 | workspace_destroy(*ws); |
| 6421 | wl_array_release(&shell->workspaces.array); |
| 6422 | |
Emilio Pozuelo Monfort | 46ce798 | 2013-11-20 13:22:29 +0100 | [diff] [blame] | 6423 | free(shell->client); |
Pekka Paalanen | 3c64723 | 2011-12-22 13:43:43 +0200 | [diff] [blame] | 6424 | free(shell); |
| 6425 | } |
| 6426 | |
Tiago Vignatti | 0b52d48 | 2012-04-20 18:54:25 +0300 | [diff] [blame] | 6427 | static void |
| 6428 | shell_add_bindings(struct weston_compositor *ec, struct desktop_shell *shell) |
| 6429 | { |
| 6430 | uint32_t mod; |
Jonas Ådahl | e3cddce | 2012-06-13 00:01:22 +0200 | [diff] [blame] | 6431 | int i, num_workspace_bindings; |
Tiago Vignatti | 0b52d48 | 2012-04-20 18:54:25 +0300 | [diff] [blame] | 6432 | |
Bob Ham | 744e653 | 2016-01-12 10:21:48 +0000 | [diff] [blame] | 6433 | if (shell->allow_zap) |
| 6434 | weston_compositor_add_key_binding(ec, KEY_BACKSPACE, |
| 6435 | MODIFIER_CTRL | MODIFIER_ALT, |
| 6436 | terminate_binding, ec); |
| 6437 | |
Tiago Vignatti | 0b52d48 | 2012-04-20 18:54:25 +0300 | [diff] [blame] | 6438 | /* fixed bindings */ |
Daniel Stone | 325fc2d | 2012-05-30 16:31:58 +0100 | [diff] [blame] | 6439 | weston_compositor_add_button_binding(ec, BTN_LEFT, 0, |
| 6440 | click_to_activate_binding, |
| 6441 | shell); |
Kristian Høgsberg | f0ce581 | 2014-04-07 11:52:17 -0700 | [diff] [blame] | 6442 | weston_compositor_add_button_binding(ec, BTN_RIGHT, 0, |
| 6443 | click_to_activate_binding, |
| 6444 | shell); |
Neil Roberts | a28c693 | 2013-10-03 16:43:04 +0100 | [diff] [blame] | 6445 | weston_compositor_add_touch_binding(ec, 0, |
| 6446 | touch_to_activate_binding, |
| 6447 | shell); |
Daniel Stone | 325fc2d | 2012-05-30 16:31:58 +0100 | [diff] [blame] | 6448 | weston_compositor_add_axis_binding(ec, WL_POINTER_AXIS_VERTICAL_SCROLL, |
| 6449 | MODIFIER_SUPER | MODIFIER_ALT, |
| 6450 | surface_opacity_binding, NULL); |
| 6451 | weston_compositor_add_axis_binding(ec, WL_POINTER_AXIS_VERTICAL_SCROLL, |
| 6452 | MODIFIER_SUPER, zoom_axis_binding, |
| 6453 | NULL); |
Bob Ham | 553d124 | 2016-01-12 10:21:49 +0000 | [diff] [blame^] | 6454 | weston_compositor_add_key_binding(ec, KEY_BRIGHTNESSDOWN, 0, |
| 6455 | backlight_binding, ec); |
| 6456 | weston_compositor_add_key_binding(ec, KEY_BRIGHTNESSUP, 0, |
| 6457 | backlight_binding, ec); |
Tiago Vignatti | 0b52d48 | 2012-04-20 18:54:25 +0300 | [diff] [blame] | 6458 | |
| 6459 | /* configurable bindings */ |
Bob Ham | 553d124 | 2016-01-12 10:21:49 +0000 | [diff] [blame^] | 6460 | if (shell->exposay_modifier) |
| 6461 | weston_compositor_add_modifier_binding(ec, shell->exposay_modifier, |
| 6462 | exposay_binding, shell); |
| 6463 | |
Tiago Vignatti | 0b52d48 | 2012-04-20 18:54:25 +0300 | [diff] [blame] | 6464 | mod = shell->binding_modifier; |
Bob Ham | 553d124 | 2016-01-12 10:21:49 +0000 | [diff] [blame^] | 6465 | if (!mod) |
| 6466 | return; |
| 6467 | |
Daniel Stone | 325fc2d | 2012-05-30 16:31:58 +0100 | [diff] [blame] | 6468 | weston_compositor_add_key_binding(ec, KEY_PAGEUP, mod, |
| 6469 | zoom_key_binding, NULL); |
| 6470 | weston_compositor_add_key_binding(ec, KEY_PAGEDOWN, mod, |
| 6471 | zoom_key_binding, NULL); |
Kristian Høgsberg | 211b517 | 2014-01-11 13:10:21 -0800 | [diff] [blame] | 6472 | weston_compositor_add_key_binding(ec, KEY_M, mod | MODIFIER_SHIFT, |
| 6473 | maximize_binding, NULL); |
| 6474 | weston_compositor_add_key_binding(ec, KEY_F, mod | MODIFIER_SHIFT, |
| 6475 | fullscreen_binding, NULL); |
Daniel Stone | 325fc2d | 2012-05-30 16:31:58 +0100 | [diff] [blame] | 6476 | weston_compositor_add_button_binding(ec, BTN_LEFT, mod, move_binding, |
| 6477 | shell); |
Neil Roberts | aba0f25 | 2013-10-03 16:43:05 +0100 | [diff] [blame] | 6478 | weston_compositor_add_touch_binding(ec, mod, touch_move_binding, shell); |
Derek Foreman | 2217f3f | 2015-06-25 16:03:30 -0500 | [diff] [blame] | 6479 | weston_compositor_add_button_binding(ec, BTN_RIGHT, mod, |
Daniel Stone | 325fc2d | 2012-05-30 16:31:58 +0100 | [diff] [blame] | 6480 | resize_binding, shell); |
Kristian Høgsberg | 0837fa9 | 2014-01-20 10:35:26 -0800 | [diff] [blame] | 6481 | weston_compositor_add_button_binding(ec, BTN_LEFT, |
| 6482 | mod | MODIFIER_SHIFT, |
| 6483 | resize_binding, shell); |
Pekka Paalanen | 7bb6510 | 2013-05-22 18:03:04 +0300 | [diff] [blame] | 6484 | |
| 6485 | if (ec->capabilities & WESTON_CAP_ROTATION_ANY) |
Derek Foreman | 2217f3f | 2015-06-25 16:03:30 -0500 | [diff] [blame] | 6486 | weston_compositor_add_button_binding(ec, BTN_MIDDLE, mod, |
Pekka Paalanen | 7bb6510 | 2013-05-22 18:03:04 +0300 | [diff] [blame] | 6487 | rotate_binding, NULL); |
| 6488 | |
Daniel Stone | 325fc2d | 2012-05-30 16:31:58 +0100 | [diff] [blame] | 6489 | weston_compositor_add_key_binding(ec, KEY_TAB, mod, switcher_binding, |
| 6490 | shell); |
| 6491 | weston_compositor_add_key_binding(ec, KEY_F9, mod, backlight_binding, |
| 6492 | ec); |
Daniel Stone | 325fc2d | 2012-05-30 16:31:58 +0100 | [diff] [blame] | 6493 | weston_compositor_add_key_binding(ec, KEY_F10, mod, backlight_binding, |
| 6494 | ec); |
Daniel Stone | 325fc2d | 2012-05-30 16:31:58 +0100 | [diff] [blame] | 6495 | weston_compositor_add_key_binding(ec, KEY_K, mod, |
| 6496 | force_kill_binding, shell); |
Jonas Ådahl | e3cddce | 2012-06-13 00:01:22 +0200 | [diff] [blame] | 6497 | weston_compositor_add_key_binding(ec, KEY_UP, mod, |
| 6498 | workspace_up_binding, shell); |
| 6499 | weston_compositor_add_key_binding(ec, KEY_DOWN, mod, |
| 6500 | workspace_down_binding, shell); |
Jonas Ådahl | 8de6a1d | 2012-08-29 22:13:00 +0200 | [diff] [blame] | 6501 | weston_compositor_add_key_binding(ec, KEY_UP, mod | MODIFIER_SHIFT, |
| 6502 | workspace_move_surface_up_binding, |
| 6503 | shell); |
| 6504 | weston_compositor_add_key_binding(ec, KEY_DOWN, mod | MODIFIER_SHIFT, |
| 6505 | workspace_move_surface_down_binding, |
| 6506 | shell); |
Jonas Ådahl | e3cddce | 2012-06-13 00:01:22 +0200 | [diff] [blame] | 6507 | |
| 6508 | /* Add bindings for mod+F[1-6] for workspace 1 to 6. */ |
| 6509 | if (shell->workspaces.num > 1) { |
| 6510 | num_workspace_bindings = shell->workspaces.num; |
| 6511 | if (num_workspace_bindings > 6) |
| 6512 | num_workspace_bindings = 6; |
| 6513 | for (i = 0; i < num_workspace_bindings; i++) |
| 6514 | weston_compositor_add_key_binding(ec, KEY_F1 + i, mod, |
| 6515 | workspace_f_binding, |
| 6516 | shell); |
| 6517 | } |
Ander Conselvan de Oliveira | c509d2b | 2012-11-08 17:20:45 +0200 | [diff] [blame] | 6518 | |
Pekka Paalanen | 2829f7c | 2015-02-19 17:02:13 +0200 | [diff] [blame] | 6519 | weston_install_debug_key_binding(ec, mod); |
Tiago Vignatti | 0b52d48 | 2012-04-20 18:54:25 +0300 | [diff] [blame] | 6520 | } |
| 6521 | |
Jason Ekstrand | 024177c | 2014-04-21 19:42:58 -0500 | [diff] [blame] | 6522 | static void |
| 6523 | handle_seat_created(struct wl_listener *listener, void *data) |
| 6524 | { |
| 6525 | struct weston_seat *seat = data; |
| 6526 | |
| 6527 | create_shell_seat(seat); |
| 6528 | } |
| 6529 | |
Kristian Høgsberg | 1c56218 | 2011-05-02 22:09:20 -0400 | [diff] [blame] | 6530 | WL_EXPORT int |
Kristian Høgsberg | cb4685b | 2013-02-20 15:37:49 -0500 | [diff] [blame] | 6531 | module_init(struct weston_compositor *ec, |
Ossama Othman | a50e6e4 | 2013-05-14 09:48:26 -0700 | [diff] [blame] | 6532 | int *argc, char *argv[]) |
Kristian Høgsberg | 4cca349 | 2011-01-18 07:53:49 -0500 | [diff] [blame] | 6533 | { |
Kristian Høgsberg | f4d2f23 | 2012-08-10 10:05:39 -0400 | [diff] [blame] | 6534 | struct weston_seat *seat; |
Tiago Vignatti | be14326 | 2012-04-16 17:31:41 +0300 | [diff] [blame] | 6535 | struct desktop_shell *shell; |
Jonas Ådahl | e3cddce | 2012-06-13 00:01:22 +0200 | [diff] [blame] | 6536 | struct workspace **pws; |
| 6537 | unsigned int i; |
Tiago Vignatti | b7dbbd6 | 2012-09-25 17:57:01 +0300 | [diff] [blame] | 6538 | struct wl_event_loop *loop; |
Kristian Høgsberg | 02ec0a5 | 2011-04-23 13:04:11 -0400 | [diff] [blame] | 6539 | |
Peter Hutterer | f3d6227 | 2013-08-08 11:57:05 +1000 | [diff] [blame] | 6540 | shell = zalloc(sizeof *shell); |
Kristian Høgsberg | 02ec0a5 | 2011-04-23 13:04:11 -0400 | [diff] [blame] | 6541 | if (shell == NULL) |
| 6542 | return -1; |
| 6543 | |
Kristian Høgsberg | 7584062 | 2011-09-06 13:48:16 -0400 | [diff] [blame] | 6544 | shell->compositor = ec; |
Kristian Høgsberg | 02e79dc | 2012-04-12 09:55:26 -0400 | [diff] [blame] | 6545 | |
| 6546 | shell->destroy_listener.notify = shell_destroy; |
| 6547 | wl_signal_add(&ec->destroy_signal, &shell->destroy_listener); |
Ander Conselvan de Oliveira | a457563 | 2013-02-21 18:35:23 +0200 | [diff] [blame] | 6548 | shell->idle_listener.notify = idle_handler; |
| 6549 | wl_signal_add(&ec->idle_signal, &shell->idle_listener); |
| 6550 | shell->wake_listener.notify = wake_handler; |
| 6551 | wl_signal_add(&ec->wake_signal, &shell->wake_listener); |
Giulio Camuffo | f05d18f | 2015-12-11 20:57:05 +0200 | [diff] [blame] | 6552 | shell->transform_listener.notify = transform_handler; |
| 6553 | wl_signal_add(&ec->transform_signal, &shell->transform_listener); |
Kristian Høgsberg | 677a5f5 | 2013-12-04 11:00:19 -0800 | [diff] [blame] | 6554 | |
Kristian Høgsberg | 82a1d11 | 2012-07-19 14:02:00 -0400 | [diff] [blame] | 6555 | ec->shell_interface.shell = shell; |
Tiago Vignatti | bc052c9 | 2012-04-19 16:18:18 +0300 | [diff] [blame] | 6556 | ec->shell_interface.create_shell_surface = create_shell_surface; |
| 6557 | ec->shell_interface.set_toplevel = set_toplevel; |
Tiago Vignatti | 491bac1 | 2012-05-18 16:37:43 -0400 | [diff] [blame] | 6558 | ec->shell_interface.set_transient = set_transient; |
Kristian Høgsberg | 4779241 | 2014-05-04 13:47:06 -0700 | [diff] [blame] | 6559 | ec->shell_interface.set_fullscreen = shell_interface_set_fullscreen; |
Tiago Vignatti | fb2adba | 2013-06-12 15:43:21 -0300 | [diff] [blame] | 6560 | ec->shell_interface.set_xwayland = set_xwayland; |
Kristian Høgsberg | ae356ae | 2014-04-29 16:03:54 -0700 | [diff] [blame] | 6561 | ec->shell_interface.move = shell_interface_move; |
Derek Foreman | 8fbebbd | 2015-07-15 13:00:40 -0500 | [diff] [blame] | 6562 | ec->shell_interface.resize = shell_interface_resize; |
Giulio Camuffo | 62942ad | 2013-09-11 18:20:47 +0200 | [diff] [blame] | 6563 | ec->shell_interface.set_title = set_title; |
Jasper St. Pierre | ccf48fb | 2014-05-02 10:21:38 -0400 | [diff] [blame] | 6564 | ec->shell_interface.set_window_geometry = set_window_geometry; |
Giulio Camuffo | 6b4b241 | 2015-01-29 19:06:49 +0200 | [diff] [blame] | 6565 | ec->shell_interface.set_maximized = shell_interface_set_maximized; |
Giulio Camuffo | a8e9b41 | 2015-01-27 19:10:37 +0200 | [diff] [blame] | 6566 | ec->shell_interface.set_pid = set_pid; |
Kristian Høgsberg | 4cca349 | 2011-01-18 07:53:49 -0500 | [diff] [blame] | 6567 | |
Kristian Høgsberg | 3be2ce9 | 2012-02-29 12:42:35 -0500 | [diff] [blame] | 6568 | weston_layer_init(&shell->fullscreen_layer, &ec->cursor_layer.link); |
| 6569 | weston_layer_init(&shell->panel_layer, &shell->fullscreen_layer.link); |
Jonas Ådahl | e3cddce | 2012-06-13 00:01:22 +0200 | [diff] [blame] | 6570 | weston_layer_init(&shell->background_layer, &shell->panel_layer.link); |
| 6571 | weston_layer_init(&shell->lock_layer, NULL); |
Philipp Brüschweiler | 711fda8 | 2012-08-09 18:50:43 +0200 | [diff] [blame] | 6572 | weston_layer_init(&shell->input_panel_layer, NULL); |
Jonas Ådahl | e3cddce | 2012-06-13 00:01:22 +0200 | [diff] [blame] | 6573 | |
| 6574 | wl_array_init(&shell->workspaces.array); |
Jonas Ådahl | e9d2250 | 2012-08-29 22:13:01 +0200 | [diff] [blame] | 6575 | wl_list_init(&shell->workspaces.client_list); |
Kristian Høgsberg | 3be2ce9 | 2012-02-29 12:42:35 -0500 | [diff] [blame] | 6576 | |
Kristian Høgsberg | 677a5f5 | 2013-12-04 11:00:19 -0800 | [diff] [blame] | 6577 | if (input_panel_setup(shell) < 0) |
| 6578 | return -1; |
| 6579 | |
Pekka Paalanen | aa9536a | 2015-06-24 16:09:17 +0300 | [diff] [blame] | 6580 | shell->text_backend = text_backend_init(ec); |
| 6581 | if (!shell->text_backend) |
Murray Calavera | 9a51cd7 | 2015-06-10 21:16:02 +0000 | [diff] [blame] | 6582 | return -1; |
| 6583 | |
Kristian Høgsberg | 14e438c | 2013-05-26 21:48:14 -0400 | [diff] [blame] | 6584 | shell_configuration(shell); |
Pekka Paalanen | e955f1e | 2011-12-07 11:49:52 +0200 | [diff] [blame] | 6585 | |
Daniel Stone | df8133b | 2013-11-19 11:37:14 +0100 | [diff] [blame] | 6586 | shell->exposay.state_cur = EXPOSAY_LAYOUT_INACTIVE; |
| 6587 | shell->exposay.state_target = EXPOSAY_TARGET_CANCEL; |
| 6588 | |
Jonas Ådahl | e3cddce | 2012-06-13 00:01:22 +0200 | [diff] [blame] | 6589 | for (i = 0; i < shell->workspaces.num; i++) { |
| 6590 | pws = wl_array_add(&shell->workspaces.array, sizeof *pws); |
| 6591 | if (pws == NULL) |
| 6592 | return -1; |
| 6593 | |
| 6594 | *pws = workspace_create(); |
| 6595 | if (*pws == NULL) |
| 6596 | return -1; |
| 6597 | } |
| 6598 | activate_workspace(shell, 0); |
| 6599 | |
Manuel Bachmann | 50c87db | 2014-02-26 15:52:13 +0100 | [diff] [blame] | 6600 | weston_layer_init(&shell->minimized_layer, NULL); |
| 6601 | |
Jonas Ådahl | 8de6a1d | 2012-08-29 22:13:00 +0200 | [diff] [blame] | 6602 | wl_list_init(&shell->workspaces.anim_sticky_list); |
Jonas Ådahl | 62fcd04 | 2012-06-13 00:01:23 +0200 | [diff] [blame] | 6603 | wl_list_init(&shell->workspaces.animation.link); |
| 6604 | shell->workspaces.animation.frame = animate_workspace_change_frame; |
| 6605 | |
Kristian Høgsberg | 919cddb | 2013-07-08 19:03:57 -0400 | [diff] [blame] | 6606 | if (wl_global_create(ec->wl_display, &wl_shell_interface, 1, |
Kristian Høgsberg | 97d44aa | 2011-08-26 17:21:20 -0400 | [diff] [blame] | 6607 | shell, bind_shell) == NULL) |
Kristian Høgsberg | 4cca349 | 2011-01-18 07:53:49 -0500 | [diff] [blame] | 6608 | return -1; |
| 6609 | |
Rafael Antognolli | e2a3455 | 2013-12-03 15:35:45 -0200 | [diff] [blame] | 6610 | if (wl_global_create(ec->wl_display, &xdg_shell_interface, 1, |
| 6611 | shell, bind_xdg_shell) == NULL) |
| 6612 | return -1; |
| 6613 | |
Kristian Høgsberg | 919cddb | 2013-07-08 19:03:57 -0400 | [diff] [blame] | 6614 | if (wl_global_create(ec->wl_display, |
Jonas Ådahl | 6d6fb61 | 2015-11-17 16:00:33 +0800 | [diff] [blame] | 6615 | &weston_desktop_shell_interface, 1, |
Kristian Høgsberg | 919cddb | 2013-07-08 19:03:57 -0400 | [diff] [blame] | 6616 | shell, bind_desktop_shell) == NULL) |
Kristian Høgsberg | 7584062 | 2011-09-06 13:48:16 -0400 | [diff] [blame] | 6617 | return -1; |
| 6618 | |
Kristian Høgsberg | f03a616 | 2012-01-17 11:07:42 -0500 | [diff] [blame] | 6619 | shell->child.deathstamp = weston_compositor_get_time(); |
Tiago Vignatti | b7dbbd6 | 2012-09-25 17:57:01 +0300 | [diff] [blame] | 6620 | |
Jonas Ådahl | 6d6fb61 | 2015-11-17 16:00:33 +0800 | [diff] [blame] | 6621 | shell->panel_position = WESTON_DESKTOP_SHELL_PANEL_POSITION_TOP; |
Jonny Lamb | 765760d | 2014-08-20 15:53:19 +0200 | [diff] [blame] | 6622 | |
Xiong Zhang | 6b48142 | 2013-10-23 13:58:32 +0800 | [diff] [blame] | 6623 | setup_output_destroy_handler(ec, shell); |
| 6624 | |
Tiago Vignatti | b7dbbd6 | 2012-09-25 17:57:01 +0300 | [diff] [blame] | 6625 | loop = wl_display_get_event_loop(ec->wl_display); |
| 6626 | wl_event_loop_add_idle(loop, launch_desktop_shell_process, shell); |
Pekka Paalanen | 6cd281a | 2011-11-03 14:11:32 +0200 | [diff] [blame] | 6627 | |
Jason Ekstrand | 024177c | 2014-04-21 19:42:58 -0500 | [diff] [blame] | 6628 | wl_list_for_each(seat, &ec->seat_list, link) |
| 6629 | handle_seat_created(NULL, seat); |
| 6630 | shell->seat_create_listener.notify = handle_seat_created; |
| 6631 | wl_signal_add(&ec->seat_created_signal, &shell->seat_create_listener); |
Kristian Høgsberg | d56bd90 | 2012-06-05 09:58:51 -0400 | [diff] [blame] | 6632 | |
Giulio Camuffo | c6ab3d5 | 2013-12-11 23:45:12 +0100 | [diff] [blame] | 6633 | screenshooter_create(ec); |
| 6634 | |
Tiago Vignatti | 0b52d48 | 2012-04-20 18:54:25 +0300 | [diff] [blame] | 6635 | shell_add_bindings(ec, shell); |
Kristian Høgsberg | 0793756 | 2011-04-12 17:25:42 -0400 | [diff] [blame] | 6636 | |
Pekka Paalanen | 79346ab | 2013-05-22 18:03:09 +0300 | [diff] [blame] | 6637 | shell_fade_init(shell); |
Ander Conselvan de Oliveira | 19d10ef | 2013-02-21 18:35:20 +0200 | [diff] [blame] | 6638 | |
Pekka Paalanen | 2e62e4a | 2014-08-28 11:41:26 +0300 | [diff] [blame] | 6639 | clock_gettime(CLOCK_MONOTONIC, &shell->startup_time); |
| 6640 | |
Kristian Høgsberg | 4cca349 | 2011-01-18 07:53:49 -0500 | [diff] [blame] | 6641 | return 0; |
| 6642 | } |