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; |
| 613 | else |
| 614 | return MODIFIER_SUPER; |
| 615 | } |
| 616 | |
Juan Zhao | e10d279 | 2012-04-25 19:09:52 +0800 | [diff] [blame] | 617 | static enum animation_type |
| 618 | get_animation_type(char *animation) |
| 619 | { |
U. Artie Eoff | b571910 | 2014-01-15 14:26:31 -0800 | [diff] [blame] | 620 | if (!animation) |
| 621 | return ANIMATION_NONE; |
| 622 | |
Juan Zhao | e10d279 | 2012-04-25 19:09:52 +0800 | [diff] [blame] | 623 | if (!strcmp("zoom", animation)) |
| 624 | return ANIMATION_ZOOM; |
| 625 | else if (!strcmp("fade", animation)) |
| 626 | return ANIMATION_FADE; |
Louis-Francis Ratté-Boulianne | b482dbd | 2013-11-19 11:37:11 +0100 | [diff] [blame] | 627 | else if (!strcmp("dim-layer", animation)) |
| 628 | return ANIMATION_DIM_LAYER; |
Juan Zhao | e10d279 | 2012-04-25 19:09:52 +0800 | [diff] [blame] | 629 | else |
| 630 | return ANIMATION_NONE; |
| 631 | } |
| 632 | |
Alex Wu | 4539b08 | 2012-03-01 12:57:46 +0800 | [diff] [blame] | 633 | static void |
Kristian Høgsberg | 14e438c | 2013-05-26 21:48:14 -0400 | [diff] [blame] | 634 | shell_configuration(struct desktop_shell *shell) |
Pekka Paalanen | e955f1e | 2011-12-07 11:49:52 +0200 | [diff] [blame] | 635 | { |
Kristian Høgsberg | 673a889 | 2013-05-23 21:40:56 -0400 | [diff] [blame] | 636 | struct weston_config_section *section; |
Derek Foreman | c721043 | 2014-08-21 11:32:38 -0500 | [diff] [blame] | 637 | char *s, *client; |
Pekka Paalanen | 974c094 | 2014-09-05 14:45:09 +0300 | [diff] [blame] | 638 | int ret; |
Bob Ham | 744e653 | 2016-01-12 10:21:48 +0000 | [diff] [blame^] | 639 | int allow_zap; |
Pekka Paalanen | e955f1e | 2011-12-07 11:49:52 +0200 | [diff] [blame] | 640 | |
Kristian Høgsberg | 673a889 | 2013-05-23 21:40:56 -0400 | [diff] [blame] | 641 | section = weston_config_get_section(shell->compositor->config, |
Kristian Høgsberg | 673a889 | 2013-05-23 21:40:56 -0400 | [diff] [blame] | 642 | "shell", NULL, NULL); |
Pekka Paalanen | 974c094 | 2014-09-05 14:45:09 +0300 | [diff] [blame] | 643 | ret = asprintf(&client, "%s/%s", weston_config_get_libexec_dir(), |
| 644 | WESTON_SHELL_CLIENT); |
| 645 | if (ret < 0) |
| 646 | client = NULL; |
Kristian Høgsberg | 673a889 | 2013-05-23 21:40:56 -0400 | [diff] [blame] | 647 | weston_config_section_get_string(section, |
Derek Foreman | c721043 | 2014-08-21 11:32:38 -0500 | [diff] [blame] | 648 | "client", &s, client); |
| 649 | free(client); |
Emilio Pozuelo Monfort | 46ce798 | 2013-11-20 13:22:29 +0100 | [diff] [blame] | 650 | shell->client = s; |
Bob Ham | 744e653 | 2016-01-12 10:21:48 +0000 | [diff] [blame^] | 651 | |
| 652 | weston_config_section_get_bool(section, |
| 653 | "allow-zap", &allow_zap, true); |
| 654 | shell->allow_zap = allow_zap; |
| 655 | |
Emilio Pozuelo Monfort | 46ce798 | 2013-11-20 13:22:29 +0100 | [diff] [blame] | 656 | weston_config_section_get_string(section, |
Kristian Høgsberg | 673a889 | 2013-05-23 21:40:56 -0400 | [diff] [blame] | 657 | "binding-modifier", &s, "super"); |
| 658 | shell->binding_modifier = get_modifier(s); |
Quentin Glidic | 8418c29 | 2013-06-18 09:11:03 +0200 | [diff] [blame] | 659 | free(s); |
Kristian Høgsberg | d56ab4e | 2014-01-16 16:51:52 -0800 | [diff] [blame] | 660 | |
| 661 | weston_config_section_get_string(section, |
| 662 | "exposay-modifier", &s, "none"); |
| 663 | if (strcmp(s, "none") == 0) |
| 664 | shell->exposay_modifier = 0; |
| 665 | else |
| 666 | shell->exposay_modifier = get_modifier(s); |
| 667 | free(s); |
| 668 | |
Kristian Høgsberg | 673a889 | 2013-05-23 21:40:56 -0400 | [diff] [blame] | 669 | weston_config_section_get_string(section, "animation", &s, "none"); |
| 670 | shell->win_animation_type = get_animation_type(s); |
Quentin Glidic | 8418c29 | 2013-06-18 09:11:03 +0200 | [diff] [blame] | 671 | free(s); |
Jonny Lamb | f322f8e | 2014-08-12 15:13:30 +0200 | [diff] [blame] | 672 | weston_config_section_get_string(section, "close-animation", &s, "fade"); |
| 673 | shell->win_close_animation_type = get_animation_type(s); |
| 674 | free(s); |
Kristian Høgsberg | 724c8d9 | 2013-10-16 11:38:24 -0700 | [diff] [blame] | 675 | weston_config_section_get_string(section, |
| 676 | "startup-animation", &s, "fade"); |
| 677 | shell->startup_animation_type = get_animation_type(s); |
| 678 | free(s); |
Kristian Høgsberg | 912e0a1 | 2013-10-30 08:59:55 -0700 | [diff] [blame] | 679 | if (shell->startup_animation_type == ANIMATION_ZOOM) |
| 680 | shell->startup_animation_type = ANIMATION_NONE; |
Louis-Francis Ratté-Boulianne | b482dbd | 2013-11-19 11:37:11 +0100 | [diff] [blame] | 681 | weston_config_section_get_string(section, "focus-animation", &s, "none"); |
| 682 | shell->focus_animation_type = get_animation_type(s); |
| 683 | free(s); |
Kristian Høgsberg | 673a889 | 2013-05-23 21:40:56 -0400 | [diff] [blame] | 684 | weston_config_section_get_uint(section, "num-workspaces", |
| 685 | &shell->workspaces.num, |
| 686 | DEFAULT_NUM_WORKSPACES); |
Jonas Ådahl | e3cddce | 2012-06-13 00:01:22 +0200 | [diff] [blame] | 687 | } |
| 688 | |
Kristian Høgsberg | 1ef2313 | 2013-12-04 00:20:01 -0800 | [diff] [blame] | 689 | struct weston_output * |
Louis-Francis Ratté-Boulianne | b482dbd | 2013-11-19 11:37:11 +0100 | [diff] [blame] | 690 | get_default_output(struct weston_compositor *compositor) |
| 691 | { |
| 692 | return container_of(compositor->output_list.next, |
| 693 | struct weston_output, link); |
| 694 | } |
| 695 | |
Pekka Paalanen | 8274d90 | 2014-08-06 19:36:51 +0300 | [diff] [blame] | 696 | static int |
| 697 | focus_surface_get_label(struct weston_surface *surface, char *buf, size_t len) |
| 698 | { |
| 699 | return snprintf(buf, len, "focus highlight effect for output %s", |
| 700 | surface->output->name); |
| 701 | } |
Louis-Francis Ratté-Boulianne | b482dbd | 2013-11-19 11:37:11 +0100 | [diff] [blame] | 702 | |
| 703 | /* no-op func for checking focus surface */ |
| 704 | static void |
Jason Ekstrand | 918f2dd | 2013-12-02 21:01:53 -0600 | [diff] [blame] | 705 | 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] | 706 | { |
| 707 | } |
| 708 | |
| 709 | static struct focus_surface * |
| 710 | get_focus_surface(struct weston_surface *surface) |
| 711 | { |
| 712 | if (surface->configure == focus_surface_configure) |
| 713 | return surface->configure_private; |
| 714 | else |
| 715 | return NULL; |
| 716 | } |
| 717 | |
| 718 | static bool |
| 719 | is_focus_surface (struct weston_surface *es) |
| 720 | { |
| 721 | return (es->configure == focus_surface_configure); |
| 722 | } |
| 723 | |
| 724 | static bool |
| 725 | is_focus_view (struct weston_view *view) |
| 726 | { |
| 727 | return is_focus_surface (view->surface); |
| 728 | } |
| 729 | |
| 730 | static struct focus_surface * |
| 731 | create_focus_surface(struct weston_compositor *ec, |
| 732 | struct weston_output *output) |
| 733 | { |
| 734 | struct focus_surface *fsurf = NULL; |
| 735 | struct weston_surface *surface = NULL; |
| 736 | |
| 737 | fsurf = malloc(sizeof *fsurf); |
| 738 | if (!fsurf) |
| 739 | return NULL; |
| 740 | |
| 741 | fsurf->surface = weston_surface_create(ec); |
| 742 | surface = fsurf->surface; |
| 743 | if (surface == NULL) { |
| 744 | free(fsurf); |
| 745 | return NULL; |
| 746 | } |
| 747 | |
| 748 | surface->configure = focus_surface_configure; |
| 749 | surface->output = output; |
| 750 | surface->configure_private = fsurf; |
Pekka Paalanen | 8274d90 | 2014-08-06 19:36:51 +0300 | [diff] [blame] | 751 | weston_surface_set_label_func(surface, focus_surface_get_label); |
Louis-Francis Ratté-Boulianne | b482dbd | 2013-11-19 11:37:11 +0100 | [diff] [blame] | 752 | |
U. Artie Eoff | 0b23b2b | 2014-01-15 14:45:59 -0800 | [diff] [blame] | 753 | fsurf->view = weston_view_create(surface); |
| 754 | if (fsurf->view == NULL) { |
| 755 | weston_surface_destroy(surface); |
| 756 | free(fsurf); |
| 757 | return NULL; |
| 758 | } |
Emilio Pozuelo Monfort | da64426 | 2013-11-19 11:37:19 +0100 | [diff] [blame] | 759 | fsurf->view->output = output; |
Louis-Francis Ratté-Boulianne | b482dbd | 2013-11-19 11:37:11 +0100 | [diff] [blame] | 760 | |
Jason Ekstrand | 5c11a33 | 2013-12-04 20:32:03 -0600 | [diff] [blame] | 761 | weston_surface_set_size(surface, output->width, output->height); |
Jason Ekstrand | 918f2dd | 2013-12-02 21:01:53 -0600 | [diff] [blame] | 762 | weston_view_set_position(fsurf->view, output->x, output->y); |
Louis-Francis Ratté-Boulianne | b482dbd | 2013-11-19 11:37:11 +0100 | [diff] [blame] | 763 | weston_surface_set_color(surface, 0.0, 0.0, 0.0, 1.0); |
| 764 | pixman_region32_fini(&surface->opaque); |
| 765 | pixman_region32_init_rect(&surface->opaque, output->x, output->y, |
| 766 | output->width, output->height); |
| 767 | pixman_region32_fini(&surface->input); |
| 768 | pixman_region32_init(&surface->input); |
| 769 | |
| 770 | wl_list_init(&fsurf->workspace_transform.link); |
| 771 | |
| 772 | return fsurf; |
| 773 | } |
| 774 | |
| 775 | static void |
| 776 | focus_surface_destroy(struct focus_surface *fsurf) |
| 777 | { |
| 778 | weston_surface_destroy(fsurf->surface); |
| 779 | free(fsurf); |
| 780 | } |
| 781 | |
| 782 | static void |
| 783 | focus_animation_done(struct weston_view_animation *animation, void *data) |
| 784 | { |
| 785 | struct workspace *ws = data; |
| 786 | |
| 787 | ws->focus_animation = NULL; |
| 788 | } |
| 789 | |
Jonas Ådahl | e3cddce | 2012-06-13 00:01:22 +0200 | [diff] [blame] | 790 | static void |
Jonas Ådahl | 0476974 | 2012-06-13 00:01:24 +0200 | [diff] [blame] | 791 | focus_state_destroy(struct focus_state *state) |
| 792 | { |
| 793 | wl_list_remove(&state->seat_destroy_listener.link); |
| 794 | wl_list_remove(&state->surface_destroy_listener.link); |
| 795 | free(state); |
| 796 | } |
| 797 | |
| 798 | static void |
| 799 | focus_state_seat_destroy(struct wl_listener *listener, void *data) |
| 800 | { |
| 801 | struct focus_state *state = container_of(listener, |
| 802 | struct focus_state, |
| 803 | seat_destroy_listener); |
| 804 | |
| 805 | wl_list_remove(&state->link); |
| 806 | focus_state_destroy(state); |
| 807 | } |
| 808 | |
| 809 | static void |
| 810 | focus_state_surface_destroy(struct wl_listener *listener, void *data) |
| 811 | { |
| 812 | struct focus_state *state = container_of(listener, |
| 813 | struct focus_state, |
Kristian Høgsberg | b8e0d0f | 2012-07-31 10:30:26 -0400 | [diff] [blame] | 814 | surface_destroy_listener); |
Kristian Høgsberg | e377822 | 2012-07-31 17:29:30 -0400 | [diff] [blame] | 815 | struct desktop_shell *shell; |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 816 | struct weston_surface *main_surface, *next; |
| 817 | struct weston_view *view; |
Jonas Ådahl | 0476974 | 2012-06-13 00:01:24 +0200 | [diff] [blame] | 818 | |
Pekka Paalanen | 01388e2 | 2013-04-25 13:57:44 +0300 | [diff] [blame] | 819 | main_surface = weston_surface_get_main_surface(state->keyboard_focus); |
| 820 | |
Kristian Høgsberg | e377822 | 2012-07-31 17:29:30 -0400 | [diff] [blame] | 821 | next = NULL; |
Giulio Camuffo | 412e6a5 | 2014-07-09 22:12:56 +0300 | [diff] [blame] | 822 | wl_list_for_each(view, |
| 823 | &state->ws->layer.view_list.link, layer_link.link) { |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 824 | if (view->surface == main_surface) |
Kristian Høgsberg | e377822 | 2012-07-31 17:29:30 -0400 | [diff] [blame] | 825 | continue; |
Louis-Francis Ratté-Boulianne | b482dbd | 2013-11-19 11:37:11 +0100 | [diff] [blame] | 826 | if (is_focus_view(view)) |
| 827 | continue; |
Kristian Høgsberg | e377822 | 2012-07-31 17:29:30 -0400 | [diff] [blame] | 828 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 829 | next = view->surface; |
Kristian Høgsberg | e377822 | 2012-07-31 17:29:30 -0400 | [diff] [blame] | 830 | break; |
| 831 | } |
| 832 | |
Pekka Paalanen | 01388e2 | 2013-04-25 13:57:44 +0300 | [diff] [blame] | 833 | /* if the focus was a sub-surface, activate its main surface */ |
| 834 | if (main_surface != state->keyboard_focus) |
| 835 | next = main_surface; |
| 836 | |
Louis-Francis Ratté-Boulianne | b482dbd | 2013-11-19 11:37:11 +0100 | [diff] [blame] | 837 | shell = state->seat->compositor->shell_interface.shell; |
Kristian Høgsberg | e377822 | 2012-07-31 17:29:30 -0400 | [diff] [blame] | 838 | if (next) { |
Louis-Francis Ratté-Boulianne | b482dbd | 2013-11-19 11:37:11 +0100 | [diff] [blame] | 839 | state->keyboard_focus = NULL; |
Emilio Pozuelo Monfort | 9e7c759 | 2014-01-30 14:01:10 +0100 | [diff] [blame] | 840 | activate(shell, next, state->seat, true); |
Kristian Høgsberg | e377822 | 2012-07-31 17:29:30 -0400 | [diff] [blame] | 841 | } else { |
Louis-Francis Ratté-Boulianne | b482dbd | 2013-11-19 11:37:11 +0100 | [diff] [blame] | 842 | if (shell->focus_animation_type == ANIMATION_DIM_LAYER) { |
| 843 | if (state->ws->focus_animation) |
| 844 | weston_view_animation_destroy(state->ws->focus_animation); |
| 845 | |
| 846 | state->ws->focus_animation = weston_fade_run( |
| 847 | state->ws->fsurf_front->view, |
| 848 | state->ws->fsurf_front->view->alpha, 0.0, 300, |
| 849 | focus_animation_done, state->ws); |
| 850 | } |
| 851 | |
Kristian Høgsberg | e377822 | 2012-07-31 17:29:30 -0400 | [diff] [blame] | 852 | wl_list_remove(&state->link); |
| 853 | focus_state_destroy(state); |
| 854 | } |
Jonas Ådahl | 0476974 | 2012-06-13 00:01:24 +0200 | [diff] [blame] | 855 | } |
| 856 | |
| 857 | static struct focus_state * |
Kristian Høgsberg | 2f5faff | 2012-07-31 16:36:34 -0400 | [diff] [blame] | 858 | focus_state_create(struct weston_seat *seat, struct workspace *ws) |
Jonas Ådahl | 0476974 | 2012-06-13 00:01:24 +0200 | [diff] [blame] | 859 | { |
Jonas Ådahl | 0476974 | 2012-06-13 00:01:24 +0200 | [diff] [blame] | 860 | struct focus_state *state; |
Jonas Ådahl | 0476974 | 2012-06-13 00:01:24 +0200 | [diff] [blame] | 861 | |
| 862 | state = malloc(sizeof *state); |
| 863 | if (state == NULL) |
| 864 | return NULL; |
| 865 | |
Louis-Francis Ratté-Boulianne | b482dbd | 2013-11-19 11:37:11 +0100 | [diff] [blame] | 866 | state->keyboard_focus = NULL; |
Kristian Høgsberg | 2f5faff | 2012-07-31 16:36:34 -0400 | [diff] [blame] | 867 | state->ws = ws; |
Jonas Ådahl | 0476974 | 2012-06-13 00:01:24 +0200 | [diff] [blame] | 868 | state->seat = seat; |
Kristian Høgsberg | 2f5faff | 2012-07-31 16:36:34 -0400 | [diff] [blame] | 869 | wl_list_insert(&ws->focus_list, &state->link); |
Jonas Ådahl | 0476974 | 2012-06-13 00:01:24 +0200 | [diff] [blame] | 870 | |
| 871 | state->seat_destroy_listener.notify = focus_state_seat_destroy; |
| 872 | state->surface_destroy_listener.notify = focus_state_surface_destroy; |
Kristian Høgsberg | 4912454 | 2013-05-06 22:27:40 -0400 | [diff] [blame] | 873 | wl_signal_add(&seat->destroy_signal, |
Jonas Ådahl | 0476974 | 2012-06-13 00:01:24 +0200 | [diff] [blame] | 874 | &state->seat_destroy_listener); |
Kristian Høgsberg | 2f5faff | 2012-07-31 16:36:34 -0400 | [diff] [blame] | 875 | wl_list_init(&state->surface_destroy_listener.link); |
Jonas Ådahl | 0476974 | 2012-06-13 00:01:24 +0200 | [diff] [blame] | 876 | |
| 877 | return state; |
| 878 | } |
| 879 | |
Jonas Ådahl | 8538b22 | 2012-08-29 22:13:03 +0200 | [diff] [blame] | 880 | static struct focus_state * |
| 881 | ensure_focus_state(struct desktop_shell *shell, struct weston_seat *seat) |
| 882 | { |
| 883 | struct workspace *ws = get_current_workspace(shell); |
| 884 | struct focus_state *state; |
| 885 | |
| 886 | wl_list_for_each(state, &ws->focus_list, link) |
| 887 | if (state->seat == seat) |
| 888 | break; |
| 889 | |
| 890 | if (&state->link == &ws->focus_list) |
| 891 | state = focus_state_create(seat, ws); |
| 892 | |
| 893 | return state; |
| 894 | } |
| 895 | |
Jonas Ådahl | 0476974 | 2012-06-13 00:01:24 +0200 | [diff] [blame] | 896 | static void |
Kristian Høgsberg | d500bf1 | 2014-01-22 12:25:20 -0800 | [diff] [blame] | 897 | focus_state_set_focus(struct focus_state *state, |
| 898 | struct weston_surface *surface) |
| 899 | { |
| 900 | if (state->keyboard_focus) { |
| 901 | wl_list_remove(&state->surface_destroy_listener.link); |
| 902 | wl_list_init(&state->surface_destroy_listener.link); |
| 903 | } |
| 904 | |
| 905 | state->keyboard_focus = surface; |
| 906 | if (surface) |
| 907 | wl_signal_add(&surface->destroy_signal, |
| 908 | &state->surface_destroy_listener); |
| 909 | } |
| 910 | |
| 911 | static void |
Kristian Høgsberg | 2f5faff | 2012-07-31 16:36:34 -0400 | [diff] [blame] | 912 | restore_focus_state(struct desktop_shell *shell, struct workspace *ws) |
Jonas Ådahl | 0476974 | 2012-06-13 00:01:24 +0200 | [diff] [blame] | 913 | { |
| 914 | struct focus_state *state, *next; |
Kristian Høgsberg | fe7aa90 | 2013-05-08 09:54:37 -0400 | [diff] [blame] | 915 | struct weston_surface *surface; |
Neil Roberts | 4237f50 | 2014-04-09 16:33:31 +0100 | [diff] [blame] | 916 | struct wl_list pending_seat_list; |
| 917 | struct weston_seat *seat, *next_seat; |
| 918 | |
| 919 | /* Temporarily steal the list of seats so that we can keep |
| 920 | * track of the seats we've already processed */ |
| 921 | wl_list_init(&pending_seat_list); |
| 922 | wl_list_insert_list(&pending_seat_list, &shell->compositor->seat_list); |
| 923 | wl_list_init(&shell->compositor->seat_list); |
Jonas Ådahl | 0476974 | 2012-06-13 00:01:24 +0200 | [diff] [blame] | 924 | |
| 925 | wl_list_for_each_safe(state, next, &ws->focus_list, link) { |
Derek Foreman | 1281a36 | 2015-07-31 16:55:32 -0500 | [diff] [blame] | 926 | struct weston_keyboard *keyboard = |
| 927 | weston_seat_get_keyboard(state->seat); |
| 928 | |
Neil Roberts | 4237f50 | 2014-04-09 16:33:31 +0100 | [diff] [blame] | 929 | wl_list_remove(&state->seat->link); |
| 930 | wl_list_insert(&shell->compositor->seat_list, |
| 931 | &state->seat->link); |
| 932 | |
Derek Foreman | 1281a36 | 2015-07-31 16:55:32 -0500 | [diff] [blame] | 933 | if (!keyboard) |
Kristian Høgsberg | e61d2f4 | 2014-01-17 12:18:53 -0800 | [diff] [blame] | 934 | continue; |
| 935 | |
Kristian Høgsberg | fe7aa90 | 2013-05-08 09:54:37 -0400 | [diff] [blame] | 936 | surface = state->keyboard_focus; |
Jonas Ådahl | 5689944 | 2012-08-29 22:12:59 +0200 | [diff] [blame] | 937 | |
Derek Foreman | 1281a36 | 2015-07-31 16:55:32 -0500 | [diff] [blame] | 938 | weston_keyboard_set_focus(keyboard, surface); |
Jonas Ådahl | 0476974 | 2012-06-13 00:01:24 +0200 | [diff] [blame] | 939 | } |
Neil Roberts | 4237f50 | 2014-04-09 16:33:31 +0100 | [diff] [blame] | 940 | |
| 941 | /* For any remaining seats that we don't have a focus state |
| 942 | * for we'll reset the keyboard focus to NULL */ |
| 943 | wl_list_for_each_safe(seat, next_seat, &pending_seat_list, link) { |
Derek Foreman | 1281a36 | 2015-07-31 16:55:32 -0500 | [diff] [blame] | 944 | struct weston_keyboard *keyboard = |
| 945 | weston_seat_get_keyboard(seat); |
| 946 | |
Neil Roberts | 4237f50 | 2014-04-09 16:33:31 +0100 | [diff] [blame] | 947 | wl_list_insert(&shell->compositor->seat_list, &seat->link); |
| 948 | |
Derek Foreman | 1281a36 | 2015-07-31 16:55:32 -0500 | [diff] [blame] | 949 | if (!keyboard) |
Neil Roberts | 4237f50 | 2014-04-09 16:33:31 +0100 | [diff] [blame] | 950 | continue; |
| 951 | |
Derek Foreman | 1281a36 | 2015-07-31 16:55:32 -0500 | [diff] [blame] | 952 | weston_keyboard_set_focus(keyboard, NULL); |
Neil Roberts | 4237f50 | 2014-04-09 16:33:31 +0100 | [diff] [blame] | 953 | } |
Jonas Ådahl | 0476974 | 2012-06-13 00:01:24 +0200 | [diff] [blame] | 954 | } |
| 955 | |
| 956 | static void |
Jonas Ådahl | 8de6a1d | 2012-08-29 22:13:00 +0200 | [diff] [blame] | 957 | replace_focus_state(struct desktop_shell *shell, struct workspace *ws, |
| 958 | struct weston_seat *seat) |
| 959 | { |
Derek Foreman | 1281a36 | 2015-07-31 16:55:32 -0500 | [diff] [blame] | 960 | struct weston_keyboard *keyboard = weston_seat_get_keyboard(seat); |
Jonas Ådahl | 8de6a1d | 2012-08-29 22:13:00 +0200 | [diff] [blame] | 961 | struct focus_state *state; |
Jonas Ådahl | 8de6a1d | 2012-08-29 22:13:00 +0200 | [diff] [blame] | 962 | |
| 963 | wl_list_for_each(state, &ws->focus_list, link) { |
| 964 | if (state->seat == seat) { |
Derek Foreman | 1281a36 | 2015-07-31 16:55:32 -0500 | [diff] [blame] | 965 | focus_state_set_focus(state, keyboard->focus); |
Jonas Ådahl | 8de6a1d | 2012-08-29 22:13:00 +0200 | [diff] [blame] | 966 | return; |
| 967 | } |
| 968 | } |
| 969 | } |
| 970 | |
| 971 | static void |
| 972 | drop_focus_state(struct desktop_shell *shell, struct workspace *ws, |
| 973 | struct weston_surface *surface) |
| 974 | { |
| 975 | struct focus_state *state; |
| 976 | |
| 977 | wl_list_for_each(state, &ws->focus_list, link) |
| 978 | if (state->keyboard_focus == surface) |
Kristian Høgsberg | d500bf1 | 2014-01-22 12:25:20 -0800 | [diff] [blame] | 979 | focus_state_set_focus(state, NULL); |
Jonas Ådahl | 8de6a1d | 2012-08-29 22:13:00 +0200 | [diff] [blame] | 980 | } |
| 981 | |
| 982 | static void |
Louis-Francis Ratté-Boulianne | b482dbd | 2013-11-19 11:37:11 +0100 | [diff] [blame] | 983 | animate_focus_change(struct desktop_shell *shell, struct workspace *ws, |
| 984 | struct weston_view *from, struct weston_view *to) |
| 985 | { |
| 986 | struct weston_output *output; |
| 987 | bool focus_surface_created = false; |
| 988 | |
| 989 | /* FIXME: Only support dim animation using two layers */ |
| 990 | if (from == to || shell->focus_animation_type != ANIMATION_DIM_LAYER) |
| 991 | return; |
| 992 | |
| 993 | output = get_default_output(shell->compositor); |
| 994 | if (ws->fsurf_front == NULL && (from || to)) { |
| 995 | ws->fsurf_front = create_focus_surface(shell->compositor, output); |
U. Artie Eoff | 0b23b2b | 2014-01-15 14:45:59 -0800 | [diff] [blame] | 996 | if (ws->fsurf_front == NULL) |
| 997 | return; |
Louis-Francis Ratté-Boulianne | b482dbd | 2013-11-19 11:37:11 +0100 | [diff] [blame] | 998 | ws->fsurf_front->view->alpha = 0.0; |
U. Artie Eoff | 0b23b2b | 2014-01-15 14:45:59 -0800 | [diff] [blame] | 999 | |
| 1000 | ws->fsurf_back = create_focus_surface(shell->compositor, output); |
| 1001 | if (ws->fsurf_back == NULL) { |
| 1002 | focus_surface_destroy(ws->fsurf_front); |
| 1003 | return; |
| 1004 | } |
Louis-Francis Ratté-Boulianne | b482dbd | 2013-11-19 11:37:11 +0100 | [diff] [blame] | 1005 | ws->fsurf_back->view->alpha = 0.0; |
U. Artie Eoff | 0b23b2b | 2014-01-15 14:45:59 -0800 | [diff] [blame] | 1006 | |
Louis-Francis Ratté-Boulianne | b482dbd | 2013-11-19 11:37:11 +0100 | [diff] [blame] | 1007 | focus_surface_created = true; |
| 1008 | } else { |
Giulio Camuffo | 412e6a5 | 2014-07-09 22:12:56 +0300 | [diff] [blame] | 1009 | weston_layer_entry_remove(&ws->fsurf_front->view->layer_link); |
| 1010 | weston_layer_entry_remove(&ws->fsurf_back->view->layer_link); |
Louis-Francis Ratté-Boulianne | b482dbd | 2013-11-19 11:37:11 +0100 | [diff] [blame] | 1011 | } |
| 1012 | |
| 1013 | if (ws->focus_animation) { |
| 1014 | weston_view_animation_destroy(ws->focus_animation); |
| 1015 | ws->focus_animation = NULL; |
| 1016 | } |
| 1017 | |
| 1018 | if (to) |
Giulio Camuffo | 412e6a5 | 2014-07-09 22:12:56 +0300 | [diff] [blame] | 1019 | weston_layer_entry_insert(&to->layer_link, |
| 1020 | &ws->fsurf_front->view->layer_link); |
Louis-Francis Ratté-Boulianne | b482dbd | 2013-11-19 11:37:11 +0100 | [diff] [blame] | 1021 | else if (from) |
Giulio Camuffo | 412e6a5 | 2014-07-09 22:12:56 +0300 | [diff] [blame] | 1022 | weston_layer_entry_insert(&ws->layer.view_list, |
| 1023 | &ws->fsurf_front->view->layer_link); |
Louis-Francis Ratté-Boulianne | b482dbd | 2013-11-19 11:37:11 +0100 | [diff] [blame] | 1024 | |
| 1025 | if (focus_surface_created) { |
| 1026 | ws->focus_animation = weston_fade_run( |
| 1027 | ws->fsurf_front->view, |
Jonny Lamb | 7e7d485 | 2014-05-22 22:41:34 +0200 | [diff] [blame] | 1028 | ws->fsurf_front->view->alpha, 0.4, 300, |
Louis-Francis Ratté-Boulianne | b482dbd | 2013-11-19 11:37:11 +0100 | [diff] [blame] | 1029 | focus_animation_done, ws); |
| 1030 | } else if (from) { |
Giulio Camuffo | 412e6a5 | 2014-07-09 22:12:56 +0300 | [diff] [blame] | 1031 | weston_layer_entry_insert(&from->layer_link, |
| 1032 | &ws->fsurf_back->view->layer_link); |
Louis-Francis Ratté-Boulianne | b482dbd | 2013-11-19 11:37:11 +0100 | [diff] [blame] | 1033 | ws->focus_animation = weston_stable_fade_run( |
| 1034 | ws->fsurf_front->view, 0.0, |
Jonny Lamb | 7e7d485 | 2014-05-22 22:41:34 +0200 | [diff] [blame] | 1035 | ws->fsurf_back->view, 0.4, |
Louis-Francis Ratté-Boulianne | b482dbd | 2013-11-19 11:37:11 +0100 | [diff] [blame] | 1036 | focus_animation_done, ws); |
| 1037 | } else if (to) { |
Giulio Camuffo | 412e6a5 | 2014-07-09 22:12:56 +0300 | [diff] [blame] | 1038 | weston_layer_entry_insert(&ws->layer.view_list, |
| 1039 | &ws->fsurf_back->view->layer_link); |
Louis-Francis Ratté-Boulianne | b482dbd | 2013-11-19 11:37:11 +0100 | [diff] [blame] | 1040 | ws->focus_animation = weston_stable_fade_run( |
| 1041 | ws->fsurf_front->view, 0.0, |
Jonny Lamb | 7e7d485 | 2014-05-22 22:41:34 +0200 | [diff] [blame] | 1042 | ws->fsurf_back->view, 0.4, |
Louis-Francis Ratté-Boulianne | b482dbd | 2013-11-19 11:37:11 +0100 | [diff] [blame] | 1043 | focus_animation_done, ws); |
| 1044 | } |
| 1045 | } |
| 1046 | |
| 1047 | static void |
Jonas Ådahl | e3cddce | 2012-06-13 00:01:22 +0200 | [diff] [blame] | 1048 | workspace_destroy(struct workspace *ws) |
| 1049 | { |
Jonas Ådahl | 0476974 | 2012-06-13 00:01:24 +0200 | [diff] [blame] | 1050 | struct focus_state *state, *next; |
| 1051 | |
| 1052 | wl_list_for_each_safe(state, next, &ws->focus_list, link) |
| 1053 | focus_state_destroy(state); |
| 1054 | |
Louis-Francis Ratté-Boulianne | b482dbd | 2013-11-19 11:37:11 +0100 | [diff] [blame] | 1055 | if (ws->fsurf_front) |
| 1056 | focus_surface_destroy(ws->fsurf_front); |
| 1057 | if (ws->fsurf_back) |
| 1058 | focus_surface_destroy(ws->fsurf_back); |
| 1059 | |
Jonas Ådahl | e3cddce | 2012-06-13 00:01:22 +0200 | [diff] [blame] | 1060 | free(ws); |
| 1061 | } |
| 1062 | |
Jonas Ådahl | 0476974 | 2012-06-13 00:01:24 +0200 | [diff] [blame] | 1063 | static void |
| 1064 | seat_destroyed(struct wl_listener *listener, void *data) |
| 1065 | { |
| 1066 | struct weston_seat *seat = data; |
| 1067 | struct focus_state *state, *next; |
| 1068 | struct workspace *ws = container_of(listener, |
| 1069 | struct workspace, |
| 1070 | seat_destroyed_listener); |
| 1071 | |
| 1072 | wl_list_for_each_safe(state, next, &ws->focus_list, link) |
| 1073 | if (state->seat == seat) |
| 1074 | wl_list_remove(&state->link); |
| 1075 | } |
| 1076 | |
Jonas Ådahl | e3cddce | 2012-06-13 00:01:22 +0200 | [diff] [blame] | 1077 | static struct workspace * |
| 1078 | workspace_create(void) |
| 1079 | { |
| 1080 | struct workspace *ws = malloc(sizeof *ws); |
| 1081 | if (ws == NULL) |
| 1082 | return NULL; |
| 1083 | |
| 1084 | weston_layer_init(&ws->layer, NULL); |
| 1085 | |
Jonas Ådahl | 0476974 | 2012-06-13 00:01:24 +0200 | [diff] [blame] | 1086 | wl_list_init(&ws->focus_list); |
| 1087 | wl_list_init(&ws->seat_destroyed_listener.link); |
| 1088 | ws->seat_destroyed_listener.notify = seat_destroyed; |
Louis-Francis Ratté-Boulianne | b482dbd | 2013-11-19 11:37:11 +0100 | [diff] [blame] | 1089 | ws->fsurf_front = NULL; |
| 1090 | ws->fsurf_back = NULL; |
| 1091 | ws->focus_animation = NULL; |
Jonas Ådahl | 0476974 | 2012-06-13 00:01:24 +0200 | [diff] [blame] | 1092 | |
Jonas Ådahl | e3cddce | 2012-06-13 00:01:22 +0200 | [diff] [blame] | 1093 | return ws; |
| 1094 | } |
| 1095 | |
Jonas Ådahl | 62fcd04 | 2012-06-13 00:01:23 +0200 | [diff] [blame] | 1096 | static int |
| 1097 | workspace_is_empty(struct workspace *ws) |
| 1098 | { |
Giulio Camuffo | 412e6a5 | 2014-07-09 22:12:56 +0300 | [diff] [blame] | 1099 | return wl_list_empty(&ws->layer.view_list.link); |
Jonas Ådahl | 62fcd04 | 2012-06-13 00:01:23 +0200 | [diff] [blame] | 1100 | } |
| 1101 | |
Jonas Ådahl | e3cddce | 2012-06-13 00:01:22 +0200 | [diff] [blame] | 1102 | static struct workspace * |
| 1103 | get_workspace(struct desktop_shell *shell, unsigned int index) |
| 1104 | { |
| 1105 | struct workspace **pws = shell->workspaces.array.data; |
Philipp Brüschweiler | 067abf6 | 2012-09-01 16:03:05 +0200 | [diff] [blame] | 1106 | assert(index < shell->workspaces.num); |
Jonas Ådahl | e3cddce | 2012-06-13 00:01:22 +0200 | [diff] [blame] | 1107 | pws += index; |
| 1108 | return *pws; |
| 1109 | } |
| 1110 | |
Kristian Høgsberg | 1ef2313 | 2013-12-04 00:20:01 -0800 | [diff] [blame] | 1111 | struct workspace * |
Jonas Ådahl | e3cddce | 2012-06-13 00:01:22 +0200 | [diff] [blame] | 1112 | get_current_workspace(struct desktop_shell *shell) |
| 1113 | { |
| 1114 | return get_workspace(shell, shell->workspaces.current); |
| 1115 | } |
| 1116 | |
| 1117 | static void |
| 1118 | activate_workspace(struct desktop_shell *shell, unsigned int index) |
| 1119 | { |
| 1120 | struct workspace *ws; |
| 1121 | |
| 1122 | ws = get_workspace(shell, index); |
| 1123 | wl_list_insert(&shell->panel_layer.link, &ws->layer.link); |
| 1124 | |
| 1125 | shell->workspaces.current = index; |
| 1126 | } |
| 1127 | |
Jonas Ådahl | 62fcd04 | 2012-06-13 00:01:23 +0200 | [diff] [blame] | 1128 | static unsigned int |
| 1129 | get_output_height(struct weston_output *output) |
| 1130 | { |
| 1131 | return abs(output->region.extents.y1 - output->region.extents.y2); |
| 1132 | } |
| 1133 | |
| 1134 | static void |
Louis-Francis Ratté-Boulianne | b482dbd | 2013-11-19 11:37:11 +0100 | [diff] [blame] | 1135 | view_translate(struct workspace *ws, struct weston_view *view, double d) |
Jonas Ådahl | 62fcd04 | 2012-06-13 00:01:23 +0200 | [diff] [blame] | 1136 | { |
Jonas Ådahl | 62fcd04 | 2012-06-13 00:01:23 +0200 | [diff] [blame] | 1137 | struct weston_transform *transform; |
| 1138 | |
Louis-Francis Ratté-Boulianne | b482dbd | 2013-11-19 11:37:11 +0100 | [diff] [blame] | 1139 | if (is_focus_view(view)) { |
| 1140 | struct focus_surface *fsurf = get_focus_surface(view->surface); |
| 1141 | transform = &fsurf->workspace_transform; |
| 1142 | } else { |
| 1143 | struct shell_surface *shsurf = get_shell_surface(view->surface); |
| 1144 | transform = &shsurf->workspace_transform; |
| 1145 | } |
| 1146 | |
Jonas Ådahl | 62fcd04 | 2012-06-13 00:01:23 +0200 | [diff] [blame] | 1147 | if (wl_list_empty(&transform->link)) |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 1148 | wl_list_insert(view->geometry.transformation_list.prev, |
Louis-Francis Ratté-Boulianne | b482dbd | 2013-11-19 11:37:11 +0100 | [diff] [blame] | 1149 | &transform->link); |
Jonas Ådahl | 62fcd04 | 2012-06-13 00:01:23 +0200 | [diff] [blame] | 1150 | |
Louis-Francis Ratté-Boulianne | b482dbd | 2013-11-19 11:37:11 +0100 | [diff] [blame] | 1151 | weston_matrix_init(&transform->matrix); |
| 1152 | weston_matrix_translate(&transform->matrix, |
Jonas Ådahl | 62fcd04 | 2012-06-13 00:01:23 +0200 | [diff] [blame] | 1153 | 0.0, d, 0.0); |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 1154 | weston_view_geometry_dirty(view); |
Jonas Ådahl | 62fcd04 | 2012-06-13 00:01:23 +0200 | [diff] [blame] | 1155 | } |
| 1156 | |
| 1157 | static void |
| 1158 | workspace_translate_out(struct workspace *ws, double fraction) |
| 1159 | { |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 1160 | struct weston_view *view; |
Jonas Ådahl | 62fcd04 | 2012-06-13 00:01:23 +0200 | [diff] [blame] | 1161 | unsigned int height; |
| 1162 | double d; |
| 1163 | |
Giulio Camuffo | 412e6a5 | 2014-07-09 22:12:56 +0300 | [diff] [blame] | 1164 | 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] | 1165 | height = get_output_height(view->surface->output); |
Jonas Ådahl | 62fcd04 | 2012-06-13 00:01:23 +0200 | [diff] [blame] | 1166 | d = height * fraction; |
| 1167 | |
Louis-Francis Ratté-Boulianne | b482dbd | 2013-11-19 11:37:11 +0100 | [diff] [blame] | 1168 | view_translate(ws, view, d); |
Jonas Ådahl | 62fcd04 | 2012-06-13 00:01:23 +0200 | [diff] [blame] | 1169 | } |
| 1170 | } |
| 1171 | |
| 1172 | static void |
| 1173 | workspace_translate_in(struct workspace *ws, double fraction) |
| 1174 | { |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 1175 | struct weston_view *view; |
Jonas Ådahl | 62fcd04 | 2012-06-13 00:01:23 +0200 | [diff] [blame] | 1176 | unsigned int height; |
| 1177 | double d; |
| 1178 | |
Giulio Camuffo | 412e6a5 | 2014-07-09 22:12:56 +0300 | [diff] [blame] | 1179 | 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] | 1180 | height = get_output_height(view->surface->output); |
Jonas Ådahl | 62fcd04 | 2012-06-13 00:01:23 +0200 | [diff] [blame] | 1181 | |
| 1182 | if (fraction > 0) |
| 1183 | d = -(height - height * fraction); |
| 1184 | else |
| 1185 | d = height + height * fraction; |
| 1186 | |
Louis-Francis Ratté-Boulianne | b482dbd | 2013-11-19 11:37:11 +0100 | [diff] [blame] | 1187 | view_translate(ws, view, d); |
Jonas Ådahl | 62fcd04 | 2012-06-13 00:01:23 +0200 | [diff] [blame] | 1188 | } |
| 1189 | } |
| 1190 | |
| 1191 | static void |
Jonas Ådahl | 62fcd04 | 2012-06-13 00:01:23 +0200 | [diff] [blame] | 1192 | reverse_workspace_change_animation(struct desktop_shell *shell, |
| 1193 | unsigned int index, |
| 1194 | struct workspace *from, |
| 1195 | struct workspace *to) |
| 1196 | { |
| 1197 | shell->workspaces.current = index; |
| 1198 | |
| 1199 | shell->workspaces.anim_to = to; |
| 1200 | shell->workspaces.anim_from = from; |
| 1201 | shell->workspaces.anim_dir = -1 * shell->workspaces.anim_dir; |
| 1202 | shell->workspaces.anim_timestamp = 0; |
| 1203 | |
Scott Moreau | 4272e63 | 2012-08-13 09:58:41 -0600 | [diff] [blame] | 1204 | weston_compositor_schedule_repaint(shell->compositor); |
Jonas Ådahl | 62fcd04 | 2012-06-13 00:01:23 +0200 | [diff] [blame] | 1205 | } |
| 1206 | |
| 1207 | static void |
| 1208 | workspace_deactivate_transforms(struct workspace *ws) |
| 1209 | { |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 1210 | struct weston_view *view; |
Louis-Francis Ratté-Boulianne | b482dbd | 2013-11-19 11:37:11 +0100 | [diff] [blame] | 1211 | struct weston_transform *transform; |
Jonas Ådahl | 62fcd04 | 2012-06-13 00:01:23 +0200 | [diff] [blame] | 1212 | |
Giulio Camuffo | 412e6a5 | 2014-07-09 22:12:56 +0300 | [diff] [blame] | 1213 | 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] | 1214 | if (is_focus_view(view)) { |
| 1215 | struct focus_surface *fsurf = get_focus_surface(view->surface); |
| 1216 | transform = &fsurf->workspace_transform; |
| 1217 | } else { |
| 1218 | struct shell_surface *shsurf = get_shell_surface(view->surface); |
| 1219 | transform = &shsurf->workspace_transform; |
| 1220 | } |
| 1221 | |
| 1222 | if (!wl_list_empty(&transform->link)) { |
| 1223 | wl_list_remove(&transform->link); |
| 1224 | wl_list_init(&transform->link); |
Jonas Ådahl | 8de6a1d | 2012-08-29 22:13:00 +0200 | [diff] [blame] | 1225 | } |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 1226 | weston_view_geometry_dirty(view); |
Jonas Ådahl | 62fcd04 | 2012-06-13 00:01:23 +0200 | [diff] [blame] | 1227 | } |
| 1228 | } |
| 1229 | |
| 1230 | static void |
| 1231 | finish_workspace_change_animation(struct desktop_shell *shell, |
| 1232 | struct workspace *from, |
| 1233 | struct workspace *to) |
| 1234 | { |
Ander Conselvan de Oliveira | 9c6217e | 2014-05-07 11:57:26 +0300 | [diff] [blame] | 1235 | struct weston_view *view; |
| 1236 | |
Scott Moreau | 4272e63 | 2012-08-13 09:58:41 -0600 | [diff] [blame] | 1237 | weston_compositor_schedule_repaint(shell->compositor); |
Jonas Ådahl | 62fcd04 | 2012-06-13 00:01:23 +0200 | [diff] [blame] | 1238 | |
Ander Conselvan de Oliveira | 9c6217e | 2014-05-07 11:57:26 +0300 | [diff] [blame] | 1239 | /* Views that extend past the bottom of the output are still |
| 1240 | * visible after the workspace animation ends but before its layer |
| 1241 | * is hidden. In that case, we need to damage below those views so |
| 1242 | * that the screen is properly repainted. */ |
Giulio Camuffo | 412e6a5 | 2014-07-09 22:12:56 +0300 | [diff] [blame] | 1243 | 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] | 1244 | weston_view_damage_below(view); |
| 1245 | |
Jonas Ådahl | 62fcd04 | 2012-06-13 00:01:23 +0200 | [diff] [blame] | 1246 | wl_list_remove(&shell->workspaces.animation.link); |
| 1247 | workspace_deactivate_transforms(from); |
| 1248 | workspace_deactivate_transforms(to); |
| 1249 | shell->workspaces.anim_to = NULL; |
| 1250 | |
| 1251 | wl_list_remove(&shell->workspaces.anim_from->layer.link); |
| 1252 | } |
| 1253 | |
| 1254 | static void |
| 1255 | animate_workspace_change_frame(struct weston_animation *animation, |
| 1256 | struct weston_output *output, uint32_t msecs) |
| 1257 | { |
| 1258 | struct desktop_shell *shell = |
| 1259 | container_of(animation, struct desktop_shell, |
| 1260 | workspaces.animation); |
| 1261 | struct workspace *from = shell->workspaces.anim_from; |
| 1262 | struct workspace *to = shell->workspaces.anim_to; |
| 1263 | uint32_t t; |
| 1264 | double x, y; |
| 1265 | |
| 1266 | if (workspace_is_empty(from) && workspace_is_empty(to)) { |
| 1267 | finish_workspace_change_animation(shell, from, to); |
| 1268 | return; |
| 1269 | } |
| 1270 | |
| 1271 | if (shell->workspaces.anim_timestamp == 0) { |
| 1272 | if (shell->workspaces.anim_current == 0.0) |
| 1273 | shell->workspaces.anim_timestamp = msecs; |
| 1274 | else |
| 1275 | shell->workspaces.anim_timestamp = |
| 1276 | msecs - |
| 1277 | /* Invers of movement function 'y' below. */ |
| 1278 | (asin(1.0 - shell->workspaces.anim_current) * |
| 1279 | DEFAULT_WORKSPACE_CHANGE_ANIMATION_LENGTH * |
| 1280 | M_2_PI); |
| 1281 | } |
| 1282 | |
| 1283 | t = msecs - shell->workspaces.anim_timestamp; |
| 1284 | |
| 1285 | /* |
| 1286 | * x = [0, π/2] |
| 1287 | * y(x) = sin(x) |
| 1288 | */ |
| 1289 | x = t * (1.0/DEFAULT_WORKSPACE_CHANGE_ANIMATION_LENGTH) * M_PI_2; |
| 1290 | y = sin(x); |
| 1291 | |
| 1292 | if (t < DEFAULT_WORKSPACE_CHANGE_ANIMATION_LENGTH) { |
Scott Moreau | 4272e63 | 2012-08-13 09:58:41 -0600 | [diff] [blame] | 1293 | weston_compositor_schedule_repaint(shell->compositor); |
Jonas Ådahl | 62fcd04 | 2012-06-13 00:01:23 +0200 | [diff] [blame] | 1294 | |
| 1295 | workspace_translate_out(from, shell->workspaces.anim_dir * y); |
| 1296 | workspace_translate_in(to, shell->workspaces.anim_dir * y); |
| 1297 | shell->workspaces.anim_current = y; |
| 1298 | |
Scott Moreau | 4272e63 | 2012-08-13 09:58:41 -0600 | [diff] [blame] | 1299 | weston_compositor_schedule_repaint(shell->compositor); |
Jonas Ådahl | 62fcd04 | 2012-06-13 00:01:23 +0200 | [diff] [blame] | 1300 | } |
Jonas Ådahl | 0476974 | 2012-06-13 00:01:24 +0200 | [diff] [blame] | 1301 | else |
Jonas Ådahl | 62fcd04 | 2012-06-13 00:01:23 +0200 | [diff] [blame] | 1302 | finish_workspace_change_animation(shell, from, to); |
Jonas Ådahl | 62fcd04 | 2012-06-13 00:01:23 +0200 | [diff] [blame] | 1303 | } |
| 1304 | |
| 1305 | static void |
| 1306 | animate_workspace_change(struct desktop_shell *shell, |
| 1307 | unsigned int index, |
| 1308 | struct workspace *from, |
| 1309 | struct workspace *to) |
| 1310 | { |
| 1311 | struct weston_output *output; |
| 1312 | |
| 1313 | int dir; |
| 1314 | |
| 1315 | if (index > shell->workspaces.current) |
| 1316 | dir = -1; |
| 1317 | else |
| 1318 | dir = 1; |
| 1319 | |
| 1320 | shell->workspaces.current = index; |
| 1321 | |
| 1322 | shell->workspaces.anim_dir = dir; |
| 1323 | shell->workspaces.anim_from = from; |
| 1324 | shell->workspaces.anim_to = to; |
| 1325 | shell->workspaces.anim_current = 0.0; |
| 1326 | shell->workspaces.anim_timestamp = 0; |
| 1327 | |
| 1328 | output = container_of(shell->compositor->output_list.next, |
| 1329 | struct weston_output, link); |
| 1330 | wl_list_insert(&output->animation_list, |
| 1331 | &shell->workspaces.animation.link); |
| 1332 | |
Jonas Ådahl | 8de6a1d | 2012-08-29 22:13:00 +0200 | [diff] [blame] | 1333 | wl_list_insert(from->layer.link.prev, &to->layer.link); |
Jonas Ådahl | 62fcd04 | 2012-06-13 00:01:23 +0200 | [diff] [blame] | 1334 | |
| 1335 | workspace_translate_in(to, 0); |
| 1336 | |
Kristian Høgsberg | 2f5faff | 2012-07-31 16:36:34 -0400 | [diff] [blame] | 1337 | restore_focus_state(shell, to); |
Jonas Ådahl | 0476974 | 2012-06-13 00:01:24 +0200 | [diff] [blame] | 1338 | |
Scott Moreau | 4272e63 | 2012-08-13 09:58:41 -0600 | [diff] [blame] | 1339 | weston_compositor_schedule_repaint(shell->compositor); |
Jonas Ådahl | 62fcd04 | 2012-06-13 00:01:23 +0200 | [diff] [blame] | 1340 | } |
| 1341 | |
Jonas Ådahl | e3cddce | 2012-06-13 00:01:22 +0200 | [diff] [blame] | 1342 | static void |
Jonas Ådahl | 8de6a1d | 2012-08-29 22:13:00 +0200 | [diff] [blame] | 1343 | update_workspace(struct desktop_shell *shell, unsigned int index, |
| 1344 | struct workspace *from, struct workspace *to) |
| 1345 | { |
| 1346 | shell->workspaces.current = index; |
| 1347 | wl_list_insert(&from->layer.link, &to->layer.link); |
| 1348 | wl_list_remove(&from->layer.link); |
| 1349 | } |
| 1350 | |
| 1351 | static void |
Jonas Ådahl | e3cddce | 2012-06-13 00:01:22 +0200 | [diff] [blame] | 1352 | change_workspace(struct desktop_shell *shell, unsigned int index) |
| 1353 | { |
| 1354 | struct workspace *from; |
| 1355 | struct workspace *to; |
Louis-Francis Ratté-Boulianne | b482dbd | 2013-11-19 11:37:11 +0100 | [diff] [blame] | 1356 | struct focus_state *state; |
Jonas Ådahl | e3cddce | 2012-06-13 00:01:22 +0200 | [diff] [blame] | 1357 | |
| 1358 | if (index == shell->workspaces.current) |
| 1359 | return; |
| 1360 | |
| 1361 | /* Don't change workspace when there is any fullscreen surfaces. */ |
Giulio Camuffo | 412e6a5 | 2014-07-09 22:12:56 +0300 | [diff] [blame] | 1362 | if (!wl_list_empty(&shell->fullscreen_layer.view_list.link)) |
Jonas Ådahl | e3cddce | 2012-06-13 00:01:22 +0200 | [diff] [blame] | 1363 | return; |
| 1364 | |
Jonas Ådahl | e3cddce | 2012-06-13 00:01:22 +0200 | [diff] [blame] | 1365 | from = get_current_workspace(shell); |
| 1366 | to = get_workspace(shell, index); |
| 1367 | |
Jonas Ådahl | 62fcd04 | 2012-06-13 00:01:23 +0200 | [diff] [blame] | 1368 | if (shell->workspaces.anim_from == to && |
| 1369 | shell->workspaces.anim_to == from) { |
Jonas Ådahl | 8de6a1d | 2012-08-29 22:13:00 +0200 | [diff] [blame] | 1370 | restore_focus_state(shell, to); |
Jonas Ådahl | 62fcd04 | 2012-06-13 00:01:23 +0200 | [diff] [blame] | 1371 | reverse_workspace_change_animation(shell, index, from, to); |
| 1372 | return; |
| 1373 | } |
Jonas Ådahl | e3cddce | 2012-06-13 00:01:22 +0200 | [diff] [blame] | 1374 | |
Jonas Ådahl | 62fcd04 | 2012-06-13 00:01:23 +0200 | [diff] [blame] | 1375 | if (shell->workspaces.anim_to != NULL) |
| 1376 | finish_workspace_change_animation(shell, |
| 1377 | shell->workspaces.anim_from, |
| 1378 | shell->workspaces.anim_to); |
| 1379 | |
Jonas Ådahl | 8de6a1d | 2012-08-29 22:13:00 +0200 | [diff] [blame] | 1380 | restore_focus_state(shell, to); |
Jonas Ådahl | 0476974 | 2012-06-13 00:01:24 +0200 | [diff] [blame] | 1381 | |
Louis-Francis Ratté-Boulianne | b482dbd | 2013-11-19 11:37:11 +0100 | [diff] [blame] | 1382 | if (shell->focus_animation_type != ANIMATION_NONE) { |
| 1383 | wl_list_for_each(state, &from->focus_list, link) |
| 1384 | if (state->keyboard_focus) |
| 1385 | animate_focus_change(shell, from, |
| 1386 | get_default_view(state->keyboard_focus), NULL); |
| 1387 | |
| 1388 | wl_list_for_each(state, &to->focus_list, link) |
| 1389 | if (state->keyboard_focus) |
| 1390 | animate_focus_change(shell, to, |
| 1391 | NULL, get_default_view(state->keyboard_focus)); |
| 1392 | } |
| 1393 | |
Jonas Ådahl | 8de6a1d | 2012-08-29 22:13:00 +0200 | [diff] [blame] | 1394 | if (workspace_is_empty(to) && workspace_is_empty(from)) |
| 1395 | update_workspace(shell, index, from, to); |
Jonas Ådahl | 62fcd04 | 2012-06-13 00:01:23 +0200 | [diff] [blame] | 1396 | else |
| 1397 | animate_workspace_change(shell, index, from, to); |
Pekka Paalanen | e955f1e | 2011-12-07 11:49:52 +0200 | [diff] [blame] | 1398 | } |
| 1399 | |
Jonas Ådahl | 8de6a1d | 2012-08-29 22:13:00 +0200 | [diff] [blame] | 1400 | static bool |
| 1401 | workspace_has_only(struct workspace *ws, struct weston_surface *surface) |
| 1402 | { |
Giulio Camuffo | 412e6a5 | 2014-07-09 22:12:56 +0300 | [diff] [blame] | 1403 | struct wl_list *list = &ws->layer.view_list.link; |
Jonas Ådahl | 8de6a1d | 2012-08-29 22:13:00 +0200 | [diff] [blame] | 1404 | struct wl_list *e; |
| 1405 | |
| 1406 | if (wl_list_empty(list)) |
| 1407 | return false; |
| 1408 | |
| 1409 | e = list->next; |
| 1410 | |
| 1411 | if (e->next != list) |
| 1412 | return false; |
| 1413 | |
Giulio Camuffo | 412e6a5 | 2014-07-09 22:12:56 +0300 | [diff] [blame] | 1414 | return container_of(e, struct weston_view, layer_link.link)->surface == surface; |
Jonas Ådahl | 8de6a1d | 2012-08-29 22:13:00 +0200 | [diff] [blame] | 1415 | } |
| 1416 | |
| 1417 | static void |
Jonas Ådahl | 22faea1 | 2014-10-15 22:02:06 +0200 | [diff] [blame] | 1418 | surface_keyboard_focus_lost(struct weston_surface *surface) |
| 1419 | { |
| 1420 | struct weston_compositor *compositor = surface->compositor; |
| 1421 | struct weston_seat *seat; |
| 1422 | struct weston_surface *focus; |
| 1423 | |
| 1424 | wl_list_for_each(seat, &compositor->seat_list, link) { |
| 1425 | struct weston_keyboard *keyboard = |
| 1426 | weston_seat_get_keyboard(seat); |
| 1427 | |
| 1428 | if (!keyboard) |
| 1429 | continue; |
| 1430 | |
| 1431 | focus = weston_surface_get_main_surface(keyboard->focus); |
| 1432 | if (focus == surface) |
| 1433 | weston_keyboard_set_focus(keyboard, NULL); |
| 1434 | } |
| 1435 | } |
| 1436 | |
| 1437 | static void |
Jonas Ådahl | 8de6a1d | 2012-08-29 22:13:00 +0200 | [diff] [blame] | 1438 | take_surface_to_workspace_by_seat(struct desktop_shell *shell, |
Kristian Høgsberg | e314875 | 2013-05-06 23:19:49 -0400 | [diff] [blame] | 1439 | struct weston_seat *seat, |
Jonas Ådahl | 8de6a1d | 2012-08-29 22:13:00 +0200 | [diff] [blame] | 1440 | unsigned int index) |
| 1441 | { |
Derek Foreman | 1281a36 | 2015-07-31 16:55:32 -0500 | [diff] [blame] | 1442 | struct weston_keyboard *keyboard = weston_seat_get_keyboard(seat); |
Pekka Paalanen | 01388e2 | 2013-04-25 13:57:44 +0300 | [diff] [blame] | 1443 | struct weston_surface *surface; |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 1444 | struct weston_view *view; |
Jonas Ådahl | 8de6a1d | 2012-08-29 22:13:00 +0200 | [diff] [blame] | 1445 | struct shell_surface *shsurf; |
| 1446 | struct workspace *from; |
| 1447 | struct workspace *to; |
Jonas Ådahl | 8538b22 | 2012-08-29 22:13:03 +0200 | [diff] [blame] | 1448 | struct focus_state *state; |
Jonas Ådahl | 8de6a1d | 2012-08-29 22:13:00 +0200 | [diff] [blame] | 1449 | |
Derek Foreman | 1281a36 | 2015-07-31 16:55:32 -0500 | [diff] [blame] | 1450 | surface = weston_surface_get_main_surface(keyboard->focus); |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 1451 | view = get_default_view(surface); |
| 1452 | if (view == NULL || |
Louis-Francis Ratté-Boulianne | b482dbd | 2013-11-19 11:37:11 +0100 | [diff] [blame] | 1453 | index == shell->workspaces.current || |
| 1454 | is_focus_view(view)) |
Jonas Ådahl | 8de6a1d | 2012-08-29 22:13:00 +0200 | [diff] [blame] | 1455 | return; |
| 1456 | |
| 1457 | from = get_current_workspace(shell); |
| 1458 | to = get_workspace(shell, index); |
| 1459 | |
Giulio Camuffo | 412e6a5 | 2014-07-09 22:12:56 +0300 | [diff] [blame] | 1460 | weston_layer_entry_remove(&view->layer_link); |
| 1461 | weston_layer_entry_insert(&to->layer.view_list, &view->layer_link); |
Jonas Ådahl | 8de6a1d | 2012-08-29 22:13:00 +0200 | [diff] [blame] | 1462 | |
Philip Withnall | 659163d | 2013-11-25 18:01:36 +0000 | [diff] [blame] | 1463 | shsurf = get_shell_surface(surface); |
Philip Withnall | 648a4dd | 2013-11-25 18:01:44 +0000 | [diff] [blame] | 1464 | if (shsurf != NULL) |
| 1465 | shell_surface_update_child_surface_layers(shsurf); |
Philip Withnall | 659163d | 2013-11-25 18:01:36 +0000 | [diff] [blame] | 1466 | |
Jonas Ådahl | e9d2250 | 2012-08-29 22:13:01 +0200 | [diff] [blame] | 1467 | replace_focus_state(shell, to, seat); |
Jonas Ådahl | 8de6a1d | 2012-08-29 22:13:00 +0200 | [diff] [blame] | 1468 | drop_focus_state(shell, from, surface); |
| 1469 | |
| 1470 | if (shell->workspaces.anim_from == to && |
| 1471 | shell->workspaces.anim_to == from) { |
Jonas Ådahl | e9d2250 | 2012-08-29 22:13:01 +0200 | [diff] [blame] | 1472 | wl_list_remove(&to->layer.link); |
| 1473 | wl_list_insert(from->layer.link.prev, &to->layer.link); |
| 1474 | |
Jonas Ådahl | 8de6a1d | 2012-08-29 22:13:00 +0200 | [diff] [blame] | 1475 | reverse_workspace_change_animation(shell, index, from, to); |
Jonas Ådahl | e9d2250 | 2012-08-29 22:13:01 +0200 | [diff] [blame] | 1476 | |
Jonas Ådahl | 8de6a1d | 2012-08-29 22:13:00 +0200 | [diff] [blame] | 1477 | return; |
| 1478 | } |
| 1479 | |
| 1480 | if (shell->workspaces.anim_to != NULL) |
| 1481 | finish_workspace_change_animation(shell, |
| 1482 | shell->workspaces.anim_from, |
| 1483 | shell->workspaces.anim_to); |
| 1484 | |
| 1485 | if (workspace_is_empty(from) && |
| 1486 | workspace_has_only(to, surface)) |
| 1487 | update_workspace(shell, index, from, to); |
| 1488 | else { |
Philip Withnall | 2c3849b | 2013-11-25 18:01:45 +0000 | [diff] [blame] | 1489 | if (shsurf != NULL && |
| 1490 | wl_list_empty(&shsurf->workspace_transform.link)) |
Jonas Ådahl | 8de6a1d | 2012-08-29 22:13:00 +0200 | [diff] [blame] | 1491 | wl_list_insert(&shell->workspaces.anim_sticky_list, |
| 1492 | &shsurf->workspace_transform.link); |
| 1493 | |
| 1494 | animate_workspace_change(shell, index, from, to); |
| 1495 | } |
Jonas Ådahl | e9d2250 | 2012-08-29 22:13:01 +0200 | [diff] [blame] | 1496 | |
Jonas Ådahl | 8538b22 | 2012-08-29 22:13:03 +0200 | [diff] [blame] | 1497 | state = ensure_focus_state(shell, seat); |
| 1498 | if (state != NULL) |
Kristian Høgsberg | d500bf1 | 2014-01-22 12:25:20 -0800 | [diff] [blame] | 1499 | focus_state_set_focus(state, surface); |
Jonas Ådahl | e9d2250 | 2012-08-29 22:13:01 +0200 | [diff] [blame] | 1500 | } |
| 1501 | |
| 1502 | static void |
Rusty Lynch | 1084da5 | 2013-08-15 09:10:08 -0700 | [diff] [blame] | 1503 | touch_move_grab_down(struct weston_touch_grab *grab, uint32_t time, |
Giulio Camuffo | 61ed7b6 | 2015-07-08 11:55:28 +0300 | [diff] [blame] | 1504 | int touch_id, wl_fixed_t x, wl_fixed_t y) |
Rusty Lynch | 1084da5 | 2013-08-15 09:10:08 -0700 | [diff] [blame] | 1505 | { |
| 1506 | } |
| 1507 | |
| 1508 | static void |
| 1509 | touch_move_grab_up(struct weston_touch_grab *grab, uint32_t time, int touch_id) |
| 1510 | { |
Jonas Ådahl | 1c6e63e | 2013-10-25 23:18:04 +0200 | [diff] [blame] | 1511 | struct weston_touch_move_grab *move = |
| 1512 | (struct weston_touch_move_grab *) container_of( |
| 1513 | grab, struct shell_touch_grab, grab); |
Neil Roberts | e14aa4f | 2013-10-03 16:43:07 +0100 | [diff] [blame] | 1514 | |
Kristian Høgsberg | 8e80a31 | 2014-01-17 15:18:10 -0800 | [diff] [blame] | 1515 | if (touch_id == 0) |
| 1516 | move->active = 0; |
| 1517 | |
Jonas Ådahl | 9484b69 | 2013-12-02 22:05:03 +0100 | [diff] [blame] | 1518 | if (grab->touch->num_tp == 0) { |
Jonas Ådahl | 1c6e63e | 2013-10-25 23:18:04 +0200 | [diff] [blame] | 1519 | shell_touch_grab_end(&move->base); |
| 1520 | free(move); |
| 1521 | } |
Rusty Lynch | 1084da5 | 2013-08-15 09:10:08 -0700 | [diff] [blame] | 1522 | } |
| 1523 | |
| 1524 | static void |
| 1525 | touch_move_grab_motion(struct weston_touch_grab *grab, uint32_t time, |
Giulio Camuffo | 61ed7b6 | 2015-07-08 11:55:28 +0300 | [diff] [blame] | 1526 | int touch_id, wl_fixed_t x, wl_fixed_t y) |
Rusty Lynch | 1084da5 | 2013-08-15 09:10:08 -0700 | [diff] [blame] | 1527 | { |
| 1528 | struct weston_touch_move_grab *move = (struct weston_touch_move_grab *) grab; |
| 1529 | struct shell_surface *shsurf = move->base.shsurf; |
| 1530 | struct weston_surface *es; |
| 1531 | int dx = wl_fixed_to_int(grab->touch->grab_x + move->dx); |
| 1532 | int dy = wl_fixed_to_int(grab->touch->grab_y + move->dy); |
| 1533 | |
Kristian Høgsberg | 8e80a31 | 2014-01-17 15:18:10 -0800 | [diff] [blame] | 1534 | if (!shsurf || !move->active) |
Rusty Lynch | 1084da5 | 2013-08-15 09:10:08 -0700 | [diff] [blame] | 1535 | return; |
| 1536 | |
| 1537 | es = shsurf->surface; |
| 1538 | |
Jason Ekstrand | 918f2dd | 2013-12-02 21:01:53 -0600 | [diff] [blame] | 1539 | weston_view_set_position(shsurf->view, dx, dy); |
Rusty Lynch | 1084da5 | 2013-08-15 09:10:08 -0700 | [diff] [blame] | 1540 | |
| 1541 | weston_compositor_schedule_repaint(es->compositor); |
| 1542 | } |
| 1543 | |
Jonas Ådahl | 1ea343e | 2013-10-25 23:18:05 +0200 | [diff] [blame] | 1544 | static void |
Jonas Ådahl | 1679f23 | 2014-04-12 09:39:51 +0200 | [diff] [blame] | 1545 | touch_move_grab_frame(struct weston_touch_grab *grab) |
| 1546 | { |
| 1547 | } |
| 1548 | |
| 1549 | static void |
Jonas Ådahl | 1ea343e | 2013-10-25 23:18:05 +0200 | [diff] [blame] | 1550 | touch_move_grab_cancel(struct weston_touch_grab *grab) |
| 1551 | { |
| 1552 | struct weston_touch_move_grab *move = |
| 1553 | (struct weston_touch_move_grab *) container_of( |
| 1554 | grab, struct shell_touch_grab, grab); |
| 1555 | |
| 1556 | shell_touch_grab_end(&move->base); |
| 1557 | free(move); |
| 1558 | } |
| 1559 | |
Rusty Lynch | 1084da5 | 2013-08-15 09:10:08 -0700 | [diff] [blame] | 1560 | static const struct weston_touch_grab_interface touch_move_grab_interface = { |
| 1561 | touch_move_grab_down, |
| 1562 | touch_move_grab_up, |
| 1563 | touch_move_grab_motion, |
Jonas Ådahl | 1679f23 | 2014-04-12 09:39:51 +0200 | [diff] [blame] | 1564 | touch_move_grab_frame, |
Jonas Ådahl | 1ea343e | 2013-10-25 23:18:05 +0200 | [diff] [blame] | 1565 | touch_move_grab_cancel, |
Rusty Lynch | 1084da5 | 2013-08-15 09:10:08 -0700 | [diff] [blame] | 1566 | }; |
| 1567 | |
| 1568 | static int |
Derek Foreman | b7674ae | 2015-07-15 13:00:37 -0500 | [diff] [blame] | 1569 | surface_touch_move(struct shell_surface *shsurf, struct weston_touch *touch) |
Rusty Lynch | 1084da5 | 2013-08-15 09:10:08 -0700 | [diff] [blame] | 1570 | { |
| 1571 | struct weston_touch_move_grab *move; |
| 1572 | |
| 1573 | if (!shsurf) |
| 1574 | return -1; |
| 1575 | |
Ander Conselvan de Oliveira | 6d43f04 | 2014-05-07 14:22:23 +0300 | [diff] [blame] | 1576 | if (shsurf->state.fullscreen || shsurf->state.maximized) |
Rusty Lynch | 1084da5 | 2013-08-15 09:10:08 -0700 | [diff] [blame] | 1577 | return 0; |
| 1578 | |
| 1579 | move = malloc(sizeof *move); |
| 1580 | if (!move) |
| 1581 | return -1; |
| 1582 | |
Kristian Høgsberg | 8e80a31 | 2014-01-17 15:18:10 -0800 | [diff] [blame] | 1583 | move->active = 1; |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 1584 | move->dx = wl_fixed_from_double(shsurf->view->geometry.x) - |
Derek Foreman | b7674ae | 2015-07-15 13:00:37 -0500 | [diff] [blame] | 1585 | touch->grab_x; |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 1586 | move->dy = wl_fixed_from_double(shsurf->view->geometry.y) - |
Derek Foreman | b7674ae | 2015-07-15 13:00:37 -0500 | [diff] [blame] | 1587 | touch->grab_y; |
Rusty Lynch | 1084da5 | 2013-08-15 09:10:08 -0700 | [diff] [blame] | 1588 | |
| 1589 | shell_touch_grab_start(&move->base, &touch_move_grab_interface, shsurf, |
Derek Foreman | b7674ae | 2015-07-15 13:00:37 -0500 | [diff] [blame] | 1590 | touch); |
Rusty Lynch | 1084da5 | 2013-08-15 09:10:08 -0700 | [diff] [blame] | 1591 | |
| 1592 | return 0; |
| 1593 | } |
| 1594 | |
| 1595 | static void |
Kristian Høgsberg | 6848c25 | 2013-05-08 22:02:59 -0400 | [diff] [blame] | 1596 | noop_grab_focus(struct weston_pointer_grab *grab) |
Kristian Høgsberg | 9ddb826 | 2012-01-04 21:30:29 -0500 | [diff] [blame] | 1597 | { |
Kristian Høgsberg | 9ddb826 | 2012-01-04 21:30:29 -0500 | [diff] [blame] | 1598 | } |
| 1599 | |
| 1600 | static void |
Jonas Ådahl | 0336ca0 | 2014-10-04 16:28:29 +0200 | [diff] [blame] | 1601 | noop_grab_axis(struct weston_pointer_grab *grab, |
| 1602 | uint32_t time, uint32_t axis, wl_fixed_t value) |
| 1603 | { |
| 1604 | } |
| 1605 | |
| 1606 | static void |
Kristian Høgsberg | ae356ae | 2014-04-29 16:03:54 -0700 | [diff] [blame] | 1607 | constrain_position(struct weston_move_grab *move, int *cx, int *cy) |
| 1608 | { |
| 1609 | struct shell_surface *shsurf = move->base.shsurf; |
| 1610 | struct weston_pointer *pointer = move->base.grab.pointer; |
Derek Foreman | 6feb0f9 | 2015-04-15 12:23:56 -0500 | [diff] [blame] | 1611 | int x, y, bottom; |
Kristian Høgsberg | ae356ae | 2014-04-29 16:03:54 -0700 | [diff] [blame] | 1612 | const int safety = 50; |
Derek Foreman | 6feb0f9 | 2015-04-15 12:23:56 -0500 | [diff] [blame] | 1613 | pixman_rectangle32_t area; |
Kristian Høgsberg | ae356ae | 2014-04-29 16:03:54 -0700 | [diff] [blame] | 1614 | |
| 1615 | x = wl_fixed_to_int(pointer->x + move->dx); |
| 1616 | y = wl_fixed_to_int(pointer->y + move->dy); |
| 1617 | |
Jonas Ådahl | 6d6fb61 | 2015-11-17 16:00:33 +0800 | [diff] [blame] | 1618 | if (shsurf->shell->panel_position == |
| 1619 | WESTON_DESKTOP_SHELL_PANEL_POSITION_TOP) { |
Derek Foreman | 6feb0f9 | 2015-04-15 12:23:56 -0500 | [diff] [blame] | 1620 | get_output_work_area(shsurf->shell, |
| 1621 | shsurf->surface->output, |
| 1622 | &area); |
Kristian Høgsberg | ae356ae | 2014-04-29 16:03:54 -0700 | [diff] [blame] | 1623 | |
Derek Foreman | 6feb0f9 | 2015-04-15 12:23:56 -0500 | [diff] [blame] | 1624 | bottom = y + shsurf->geometry.height + shsurf->geometry.y; |
| 1625 | if (bottom - safety < area.y) |
| 1626 | y = area.y + safety - shsurf->geometry.height |
| 1627 | - shsurf->geometry.y; |
Jonny Lamb | d73c694 | 2014-08-20 15:53:20 +0200 | [diff] [blame] | 1628 | |
| 1629 | if (move->client_initiated && |
Derek Foreman | 6feb0f9 | 2015-04-15 12:23:56 -0500 | [diff] [blame] | 1630 | y + shsurf->geometry.y < area.y) |
| 1631 | y = area.y - shsurf->geometry.y; |
| 1632 | |
Jonny Lamb | d73c694 | 2014-08-20 15:53:20 +0200 | [diff] [blame] | 1633 | } |
Kristian Høgsberg | ae356ae | 2014-04-29 16:03:54 -0700 | [diff] [blame] | 1634 | |
| 1635 | *cx = x; |
| 1636 | *cy = y; |
| 1637 | } |
| 1638 | |
| 1639 | static void |
Giulio Camuffo | 1959ab8 | 2013-11-14 23:42:52 +0100 | [diff] [blame] | 1640 | move_grab_motion(struct weston_pointer_grab *grab, uint32_t time, |
Jonas Ådahl | d251010 | 2014-10-05 21:39:14 +0200 | [diff] [blame] | 1641 | struct weston_pointer_motion_event *event) |
Kristian Høgsberg | 4cca349 | 2011-01-18 07:53:49 -0500 | [diff] [blame] | 1642 | { |
Kristian Høgsberg | 8334bc1 | 2012-01-03 10:29:47 -0500 | [diff] [blame] | 1643 | struct weston_move_grab *move = (struct weston_move_grab *) grab; |
Kristian Høgsberg | 02bbabb | 2013-05-06 22:15:05 -0400 | [diff] [blame] | 1644 | struct weston_pointer *pointer = grab->pointer; |
Ander Conselvan de Oliveira | fe0444a | 2012-04-04 17:48:05 +0300 | [diff] [blame] | 1645 | struct shell_surface *shsurf = move->base.shsurf; |
Kristian Høgsberg | ae356ae | 2014-04-29 16:03:54 -0700 | [diff] [blame] | 1646 | int cx, cy; |
Giulio Camuffo | 1959ab8 | 2013-11-14 23:42:52 +0100 | [diff] [blame] | 1647 | |
Jonas Ådahl | d251010 | 2014-10-05 21:39:14 +0200 | [diff] [blame] | 1648 | weston_pointer_move(pointer, event); |
Ander Conselvan de Oliveira | fe0444a | 2012-04-04 17:48:05 +0300 | [diff] [blame] | 1649 | if (!shsurf) |
| 1650 | return; |
| 1651 | |
Kristian Høgsberg | ae356ae | 2014-04-29 16:03:54 -0700 | [diff] [blame] | 1652 | constrain_position(move, &cx, &cy); |
| 1653 | |
| 1654 | weston_view_set_position(shsurf->view, cx, cy); |
Kristian Høgsberg | 4cca349 | 2011-01-18 07:53:49 -0500 | [diff] [blame] | 1655 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 1656 | weston_compositor_schedule_repaint(shsurf->surface->compositor); |
Kristian Høgsberg | 4cca349 | 2011-01-18 07:53:49 -0500 | [diff] [blame] | 1657 | } |
| 1658 | |
| 1659 | static void |
Kristian Høgsberg | 02bbabb | 2013-05-06 22:15:05 -0400 | [diff] [blame] | 1660 | move_grab_button(struct weston_pointer_grab *grab, |
Daniel Stone | 4dbadb1 | 2012-05-30 16:31:51 +0100 | [diff] [blame] | 1661 | uint32_t time, uint32_t button, uint32_t state_w) |
Kristian Høgsberg | 4cca349 | 2011-01-18 07:53:49 -0500 | [diff] [blame] | 1662 | { |
Ander Conselvan de Oliveira | fe0444a | 2012-04-04 17:48:05 +0300 | [diff] [blame] | 1663 | struct shell_grab *shell_grab = container_of(grab, struct shell_grab, |
| 1664 | grab); |
Kristian Høgsberg | 02bbabb | 2013-05-06 22:15:05 -0400 | [diff] [blame] | 1665 | struct weston_pointer *pointer = grab->pointer; |
Daniel Stone | 4dbadb1 | 2012-05-30 16:31:51 +0100 | [diff] [blame] | 1666 | enum wl_pointer_button_state state = state_w; |
Kristian Høgsberg | 4cca349 | 2011-01-18 07:53:49 -0500 | [diff] [blame] | 1667 | |
Daniel Stone | 4dbadb1 | 2012-05-30 16:31:51 +0100 | [diff] [blame] | 1668 | if (pointer->button_count == 0 && |
| 1669 | state == WL_POINTER_BUTTON_STATE_RELEASED) { |
Ander Conselvan de Oliveira | b9d2a0f | 2012-06-28 18:08:05 +0300 | [diff] [blame] | 1670 | shell_grab_end(shell_grab); |
Kristian Høgsberg | 9ddb826 | 2012-01-04 21:30:29 -0500 | [diff] [blame] | 1671 | free(grab); |
| 1672 | } |
Kristian Høgsberg | 4cca349 | 2011-01-18 07:53:49 -0500 | [diff] [blame] | 1673 | } |
| 1674 | |
Jonas Ådahl | 1ea343e | 2013-10-25 23:18:05 +0200 | [diff] [blame] | 1675 | static void |
| 1676 | move_grab_cancel(struct weston_pointer_grab *grab) |
| 1677 | { |
| 1678 | struct shell_grab *shell_grab = |
| 1679 | container_of(grab, struct shell_grab, grab); |
| 1680 | |
| 1681 | shell_grab_end(shell_grab); |
| 1682 | free(grab); |
| 1683 | } |
| 1684 | |
Kristian Høgsberg | 02bbabb | 2013-05-06 22:15:05 -0400 | [diff] [blame] | 1685 | static const struct weston_pointer_grab_interface move_grab_interface = { |
Kristian Høgsberg | 9ddb826 | 2012-01-04 21:30:29 -0500 | [diff] [blame] | 1686 | noop_grab_focus, |
Kristian Høgsberg | 4cca349 | 2011-01-18 07:53:49 -0500 | [diff] [blame] | 1687 | move_grab_motion, |
| 1688 | move_grab_button, |
Jonas Ådahl | 0336ca0 | 2014-10-04 16:28:29 +0200 | [diff] [blame] | 1689 | noop_grab_axis, |
Jonas Ådahl | 1ea343e | 2013-10-25 23:18:05 +0200 | [diff] [blame] | 1690 | move_grab_cancel, |
Kristian Høgsberg | 4cca349 | 2011-01-18 07:53:49 -0500 | [diff] [blame] | 1691 | }; |
| 1692 | |
Kristian Høgsberg | 9e31bff | 2012-08-01 00:08:07 -0400 | [diff] [blame] | 1693 | static int |
Derek Foreman | 794fa0e | 2015-07-15 13:00:38 -0500 | [diff] [blame] | 1694 | surface_move(struct shell_surface *shsurf, struct weston_pointer *pointer, |
Derek Foreman | cf7d95a | 2015-06-03 15:53:22 -0500 | [diff] [blame] | 1695 | bool client_initiated) |
Kristian Høgsberg | 9e31bff | 2012-08-01 00:08:07 -0400 | [diff] [blame] | 1696 | { |
| 1697 | struct weston_move_grab *move; |
| 1698 | |
| 1699 | if (!shsurf) |
| 1700 | return -1; |
| 1701 | |
Derek Foreman | 45a7c27 | 2015-09-11 14:27:40 -0500 | [diff] [blame] | 1702 | shsurf = find_toplevel_surface(shsurf); |
| 1703 | |
Kristian Høgsberg | a4b620e | 2014-04-30 16:05:49 -0700 | [diff] [blame] | 1704 | if (shsurf->grabbed || |
| 1705 | shsurf->state.fullscreen || shsurf->state.maximized) |
Kristian Høgsberg | 9e31bff | 2012-08-01 00:08:07 -0400 | [diff] [blame] | 1706 | return 0; |
| 1707 | |
| 1708 | move = malloc(sizeof *move); |
| 1709 | if (!move) |
| 1710 | return -1; |
| 1711 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 1712 | move->dx = wl_fixed_from_double(shsurf->view->geometry.x) - |
Derek Foreman | 794fa0e | 2015-07-15 13:00:38 -0500 | [diff] [blame] | 1713 | pointer->grab_x; |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 1714 | move->dy = wl_fixed_from_double(shsurf->view->geometry.y) - |
Derek Foreman | 794fa0e | 2015-07-15 13:00:38 -0500 | [diff] [blame] | 1715 | pointer->grab_y; |
Kristian Høgsberg | ae356ae | 2014-04-29 16:03:54 -0700 | [diff] [blame] | 1716 | move->client_initiated = client_initiated; |
Kristian Høgsberg | 9e31bff | 2012-08-01 00:08:07 -0400 | [diff] [blame] | 1717 | |
| 1718 | shell_grab_start(&move->base, &move_grab_interface, shsurf, |
Jonas Ådahl | 6d6fb61 | 2015-11-17 16:00:33 +0800 | [diff] [blame] | 1719 | pointer, WESTON_DESKTOP_SHELL_CURSOR_MOVE); |
Kristian Høgsberg | 9e31bff | 2012-08-01 00:08:07 -0400 | [diff] [blame] | 1720 | |
| 1721 | return 0; |
| 1722 | } |
| 1723 | |
| 1724 | static void |
Rafael Antognolli | e2a3455 | 2013-12-03 15:35:45 -0200 | [diff] [blame] | 1725 | common_surface_move(struct wl_resource *resource, |
| 1726 | struct wl_resource *seat_resource, uint32_t serial) |
Kristian Høgsberg | 9e31bff | 2012-08-01 00:08:07 -0400 | [diff] [blame] | 1727 | { |
Jason Ekstrand | 44a3863 | 2013-06-14 10:08:00 -0500 | [diff] [blame] | 1728 | struct weston_seat *seat = wl_resource_get_user_data(seat_resource); |
Derek Foreman | 1281a36 | 2015-07-31 16:55:32 -0500 | [diff] [blame] | 1729 | struct weston_pointer *pointer = weston_seat_get_pointer(seat); |
| 1730 | struct weston_touch *touch = weston_seat_get_touch(seat); |
Jason Ekstrand | 651f00e | 2013-06-14 10:07:54 -0500 | [diff] [blame] | 1731 | struct shell_surface *shsurf = wl_resource_get_user_data(resource); |
Giulio Camuffo | 61da3fc | 2013-04-25 13:57:45 +0300 | [diff] [blame] | 1732 | struct weston_surface *surface; |
Kristian Høgsberg | 9e31bff | 2012-08-01 00:08:07 -0400 | [diff] [blame] | 1733 | |
Derek Foreman | 1281a36 | 2015-07-31 16:55:32 -0500 | [diff] [blame] | 1734 | if (pointer && |
| 1735 | pointer->focus && |
| 1736 | pointer->button_count > 0 && |
| 1737 | pointer->grab_serial == serial) { |
| 1738 | surface = weston_surface_get_main_surface(pointer->focus->surface); |
U. Artie Eoff | cf5737a | 2014-01-17 10:08:25 -0800 | [diff] [blame] | 1739 | if ((surface == shsurf->surface) && |
Derek Foreman | 1281a36 | 2015-07-31 16:55:32 -0500 | [diff] [blame] | 1740 | (surface_move(shsurf, pointer, true) < 0)) |
Rusty Lynch | 1084da5 | 2013-08-15 09:10:08 -0700 | [diff] [blame] | 1741 | wl_resource_post_no_memory(resource); |
Derek Foreman | 1281a36 | 2015-07-31 16:55:32 -0500 | [diff] [blame] | 1742 | } else if (touch && |
| 1743 | touch->focus && |
| 1744 | touch->grab_serial == serial) { |
| 1745 | surface = weston_surface_get_main_surface(touch->focus->surface); |
U. Artie Eoff | cf5737a | 2014-01-17 10:08:25 -0800 | [diff] [blame] | 1746 | if ((surface == shsurf->surface) && |
Derek Foreman | 1281a36 | 2015-07-31 16:55:32 -0500 | [diff] [blame] | 1747 | (surface_touch_move(shsurf, touch) < 0)) |
Rusty Lynch | 1084da5 | 2013-08-15 09:10:08 -0700 | [diff] [blame] | 1748 | wl_resource_post_no_memory(resource); |
| 1749 | } |
Kristian Høgsberg | 9e31bff | 2012-08-01 00:08:07 -0400 | [diff] [blame] | 1750 | } |
| 1751 | |
Rafael Antognolli | e2a3455 | 2013-12-03 15:35:45 -0200 | [diff] [blame] | 1752 | static void |
| 1753 | shell_surface_move(struct wl_client *client, struct wl_resource *resource, |
| 1754 | struct wl_resource *seat_resource, uint32_t serial) |
| 1755 | { |
| 1756 | common_surface_move(resource, seat_resource, serial); |
| 1757 | } |
| 1758 | |
Kristian Høgsberg | 9e31bff | 2012-08-01 00:08:07 -0400 | [diff] [blame] | 1759 | struct weston_resize_grab { |
| 1760 | struct shell_grab base; |
| 1761 | uint32_t edges; |
| 1762 | int32_t width, height; |
| 1763 | }; |
| 1764 | |
| 1765 | static void |
Giulio Camuffo | 1959ab8 | 2013-11-14 23:42:52 +0100 | [diff] [blame] | 1766 | resize_grab_motion(struct weston_pointer_grab *grab, uint32_t time, |
Jonas Ådahl | d251010 | 2014-10-05 21:39:14 +0200 | [diff] [blame] | 1767 | struct weston_pointer_motion_event *event) |
Kristian Høgsberg | 9e31bff | 2012-08-01 00:08:07 -0400 | [diff] [blame] | 1768 | { |
| 1769 | struct weston_resize_grab *resize = (struct weston_resize_grab *) grab; |
Kristian Høgsberg | 02bbabb | 2013-05-06 22:15:05 -0400 | [diff] [blame] | 1770 | struct weston_pointer *pointer = grab->pointer; |
Kristian Høgsberg | 9e31bff | 2012-08-01 00:08:07 -0400 | [diff] [blame] | 1771 | struct shell_surface *shsurf = resize->base.shsurf; |
| 1772 | int32_t width, height; |
| 1773 | wl_fixed_t from_x, from_y; |
| 1774 | wl_fixed_t to_x, to_y; |
| 1775 | |
Jonas Ådahl | d251010 | 2014-10-05 21:39:14 +0200 | [diff] [blame] | 1776 | weston_pointer_move(pointer, event); |
Giulio Camuffo | 1959ab8 | 2013-11-14 23:42:52 +0100 | [diff] [blame] | 1777 | |
Kristian Høgsberg | e0b9d5b | 2014-04-30 13:45:49 -0700 | [diff] [blame] | 1778 | if (!shsurf) |
Kristian Høgsberg | 9e31bff | 2012-08-01 00:08:07 -0400 | [diff] [blame] | 1779 | return; |
| 1780 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 1781 | weston_view_from_global_fixed(shsurf->view, |
| 1782 | pointer->grab_x, pointer->grab_y, |
| 1783 | &from_x, &from_y); |
| 1784 | weston_view_from_global_fixed(shsurf->view, |
| 1785 | pointer->x, pointer->y, &to_x, &to_y); |
Kristian Høgsberg | 9e31bff | 2012-08-01 00:08:07 -0400 | [diff] [blame] | 1786 | |
| 1787 | width = resize->width; |
| 1788 | if (resize->edges & WL_SHELL_SURFACE_RESIZE_LEFT) { |
| 1789 | width += wl_fixed_to_int(from_x - to_x); |
| 1790 | } else if (resize->edges & WL_SHELL_SURFACE_RESIZE_RIGHT) { |
| 1791 | width += wl_fixed_to_int(to_x - from_x); |
| 1792 | } |
| 1793 | |
| 1794 | height = resize->height; |
| 1795 | if (resize->edges & WL_SHELL_SURFACE_RESIZE_TOP) { |
| 1796 | height += wl_fixed_to_int(from_y - to_y); |
| 1797 | } else if (resize->edges & WL_SHELL_SURFACE_RESIZE_BOTTOM) { |
| 1798 | height += wl_fixed_to_int(to_y - from_y); |
| 1799 | } |
| 1800 | |
Derek Foreman | 70ac0ed | 2015-03-18 11:16:33 -0500 | [diff] [blame] | 1801 | if (width < 1) |
| 1802 | width = 1; |
| 1803 | if (height < 1) |
| 1804 | height = 1; |
Jasper St. Pierre | ac985be | 2014-04-28 11:19:28 -0400 | [diff] [blame] | 1805 | shsurf->client->send_configure(shsurf->surface, width, height); |
Kristian Høgsberg | 9e31bff | 2012-08-01 00:08:07 -0400 | [diff] [blame] | 1806 | } |
| 1807 | |
| 1808 | static void |
Jasper St. Pierre | ac985be | 2014-04-28 11:19:28 -0400 | [diff] [blame] | 1809 | 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] | 1810 | { |
| 1811 | struct shell_surface *shsurf = get_shell_surface(surface); |
| 1812 | |
U. Artie Eoff | cf5737a | 2014-01-17 10:08:25 -0800 | [diff] [blame] | 1813 | assert(shsurf); |
| 1814 | |
Kristian Høgsberg | e0b9d5b | 2014-04-30 13:45:49 -0700 | [diff] [blame] | 1815 | if (shsurf->resource) |
| 1816 | wl_shell_surface_send_configure(shsurf->resource, |
Jasper St. Pierre | ac985be | 2014-04-28 11:19:28 -0400 | [diff] [blame] | 1817 | shsurf->resize_edges, |
| 1818 | width, height); |
Kristian Høgsberg | 9e31bff | 2012-08-01 00:08:07 -0400 | [diff] [blame] | 1819 | } |
| 1820 | |
| 1821 | static const struct weston_shell_client shell_client = { |
Giulio Camuffo | f05d18f | 2015-12-11 20:57:05 +0200 | [diff] [blame] | 1822 | send_configure, |
| 1823 | NULL |
Kristian Høgsberg | 9e31bff | 2012-08-01 00:08:07 -0400 | [diff] [blame] | 1824 | }; |
| 1825 | |
| 1826 | static void |
Kristian Høgsberg | 02bbabb | 2013-05-06 22:15:05 -0400 | [diff] [blame] | 1827 | resize_grab_button(struct weston_pointer_grab *grab, |
Kristian Høgsberg | 9e31bff | 2012-08-01 00:08:07 -0400 | [diff] [blame] | 1828 | uint32_t time, uint32_t button, uint32_t state_w) |
| 1829 | { |
| 1830 | struct weston_resize_grab *resize = (struct weston_resize_grab *) grab; |
Kristian Høgsberg | 02bbabb | 2013-05-06 22:15:05 -0400 | [diff] [blame] | 1831 | struct weston_pointer *pointer = grab->pointer; |
Kristian Høgsberg | 9e31bff | 2012-08-01 00:08:07 -0400 | [diff] [blame] | 1832 | enum wl_pointer_button_state state = state_w; |
| 1833 | |
| 1834 | if (pointer->button_count == 0 && |
| 1835 | state == WL_POINTER_BUTTON_STATE_RELEASED) { |
| 1836 | shell_grab_end(&resize->base); |
| 1837 | free(grab); |
| 1838 | } |
| 1839 | } |
| 1840 | |
Jonas Ådahl | 1ea343e | 2013-10-25 23:18:05 +0200 | [diff] [blame] | 1841 | static void |
| 1842 | resize_grab_cancel(struct weston_pointer_grab *grab) |
| 1843 | { |
| 1844 | struct weston_resize_grab *resize = (struct weston_resize_grab *) grab; |
| 1845 | |
| 1846 | shell_grab_end(&resize->base); |
| 1847 | free(grab); |
| 1848 | } |
| 1849 | |
Kristian Høgsberg | 02bbabb | 2013-05-06 22:15:05 -0400 | [diff] [blame] | 1850 | static const struct weston_pointer_grab_interface resize_grab_interface = { |
Kristian Høgsberg | 9e31bff | 2012-08-01 00:08:07 -0400 | [diff] [blame] | 1851 | noop_grab_focus, |
| 1852 | resize_grab_motion, |
| 1853 | resize_grab_button, |
Jonas Ådahl | 0336ca0 | 2014-10-04 16:28:29 +0200 | [diff] [blame] | 1854 | noop_grab_axis, |
Jonas Ådahl | 1ea343e | 2013-10-25 23:18:05 +0200 | [diff] [blame] | 1855 | resize_grab_cancel, |
Kristian Høgsberg | 9e31bff | 2012-08-01 00:08:07 -0400 | [diff] [blame] | 1856 | }; |
| 1857 | |
Giulio Camuffo | b836664 | 2013-04-25 13:57:46 +0300 | [diff] [blame] | 1858 | /* |
| 1859 | * Returns the bounding box of a surface and all its sub-surfaces, |
| 1860 | * in the surface coordinates system. */ |
| 1861 | static void |
| 1862 | surface_subsurfaces_boundingbox(struct weston_surface *surface, int32_t *x, |
| 1863 | int32_t *y, int32_t *w, int32_t *h) { |
| 1864 | pixman_region32_t region; |
| 1865 | pixman_box32_t *box; |
| 1866 | struct weston_subsurface *subsurface; |
| 1867 | |
| 1868 | pixman_region32_init_rect(®ion, 0, 0, |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 1869 | surface->width, |
| 1870 | surface->height); |
Giulio Camuffo | b836664 | 2013-04-25 13:57:46 +0300 | [diff] [blame] | 1871 | |
| 1872 | wl_list_for_each(subsurface, &surface->subsurface_list, parent_link) { |
| 1873 | pixman_region32_union_rect(®ion, ®ion, |
| 1874 | subsurface->position.x, |
| 1875 | subsurface->position.y, |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 1876 | subsurface->surface->width, |
| 1877 | subsurface->surface->height); |
Giulio Camuffo | b836664 | 2013-04-25 13:57:46 +0300 | [diff] [blame] | 1878 | } |
| 1879 | |
| 1880 | box = pixman_region32_extents(®ion); |
| 1881 | if (x) |
| 1882 | *x = box->x1; |
| 1883 | if (y) |
| 1884 | *y = box->y1; |
| 1885 | if (w) |
| 1886 | *w = box->x2 - box->x1; |
| 1887 | if (h) |
| 1888 | *h = box->y2 - box->y1; |
| 1889 | |
| 1890 | pixman_region32_fini(®ion); |
| 1891 | } |
| 1892 | |
Kristian Høgsberg | 9e31bff | 2012-08-01 00:08:07 -0400 | [diff] [blame] | 1893 | static int |
| 1894 | surface_resize(struct shell_surface *shsurf, |
Derek Foreman | 8fbebbd | 2015-07-15 13:00:40 -0500 | [diff] [blame] | 1895 | struct weston_pointer *pointer, uint32_t edges) |
Kristian Høgsberg | 9e31bff | 2012-08-01 00:08:07 -0400 | [diff] [blame] | 1896 | { |
| 1897 | struct weston_resize_grab *resize; |
Ondřej Majerech | ae9c4fc | 2014-08-21 15:47:22 +0200 | [diff] [blame] | 1898 | const unsigned resize_topbottom = |
| 1899 | WL_SHELL_SURFACE_RESIZE_TOP | WL_SHELL_SURFACE_RESIZE_BOTTOM; |
| 1900 | const unsigned resize_leftright = |
| 1901 | WL_SHELL_SURFACE_RESIZE_LEFT | WL_SHELL_SURFACE_RESIZE_RIGHT; |
| 1902 | const unsigned resize_any = resize_topbottom | resize_leftright; |
Kristian Høgsberg | 9e31bff | 2012-08-01 00:08:07 -0400 | [diff] [blame] | 1903 | |
Kristian Høgsberg | a4b620e | 2014-04-30 16:05:49 -0700 | [diff] [blame] | 1904 | if (shsurf->grabbed || |
| 1905 | shsurf->state.fullscreen || shsurf->state.maximized) |
Kristian Høgsberg | 9e31bff | 2012-08-01 00:08:07 -0400 | [diff] [blame] | 1906 | return 0; |
| 1907 | |
Ondřej Majerech | ae9c4fc | 2014-08-21 15:47:22 +0200 | [diff] [blame] | 1908 | /* Check for invalid edge combinations. */ |
| 1909 | if (edges == WL_SHELL_SURFACE_RESIZE_NONE || edges > resize_any || |
| 1910 | (edges & resize_topbottom) == resize_topbottom || |
| 1911 | (edges & resize_leftright) == resize_leftright) |
Kristian Høgsberg | 9e31bff | 2012-08-01 00:08:07 -0400 | [diff] [blame] | 1912 | return 0; |
| 1913 | |
| 1914 | resize = malloc(sizeof *resize); |
| 1915 | if (!resize) |
| 1916 | return -1; |
| 1917 | |
| 1918 | resize->edges = edges; |
Kristian Høgsberg | 9e31bff | 2012-08-01 00:08:07 -0400 | [diff] [blame] | 1919 | |
Jasper St. Pierre | ccf48fb | 2014-05-02 10:21:38 -0400 | [diff] [blame] | 1920 | resize->width = shsurf->geometry.width; |
| 1921 | resize->height = shsurf->geometry.height; |
Jasper St. Pierre | bd65e50 | 2014-07-14 16:28:48 -0400 | [diff] [blame] | 1922 | |
Kristian Høgsberg | 44cd196 | 2014-02-05 21:36:04 -0800 | [diff] [blame] | 1923 | shsurf->resize_edges = edges; |
Jasper St. Pierre | 5befdda | 2014-05-06 08:50:47 -0400 | [diff] [blame] | 1924 | shell_surface_state_changed(shsurf); |
Kristian Høgsberg | 9e31bff | 2012-08-01 00:08:07 -0400 | [diff] [blame] | 1925 | shell_grab_start(&resize->base, &resize_grab_interface, shsurf, |
Derek Foreman | 8fbebbd | 2015-07-15 13:00:40 -0500 | [diff] [blame] | 1926 | pointer, edges); |
Kristian Høgsberg | 9e31bff | 2012-08-01 00:08:07 -0400 | [diff] [blame] | 1927 | |
| 1928 | return 0; |
| 1929 | } |
| 1930 | |
| 1931 | static void |
Rafael Antognolli | e2a3455 | 2013-12-03 15:35:45 -0200 | [diff] [blame] | 1932 | common_surface_resize(struct wl_resource *resource, |
| 1933 | struct wl_resource *seat_resource, uint32_t serial, |
| 1934 | uint32_t edges) |
Kristian Høgsberg | 9e31bff | 2012-08-01 00:08:07 -0400 | [diff] [blame] | 1935 | { |
Jason Ekstrand | 44a3863 | 2013-06-14 10:08:00 -0500 | [diff] [blame] | 1936 | struct weston_seat *seat = wl_resource_get_user_data(seat_resource); |
Derek Foreman | 1281a36 | 2015-07-31 16:55:32 -0500 | [diff] [blame] | 1937 | struct weston_pointer *pointer = weston_seat_get_pointer(seat); |
Jason Ekstrand | 651f00e | 2013-06-14 10:07:54 -0500 | [diff] [blame] | 1938 | struct shell_surface *shsurf = wl_resource_get_user_data(resource); |
Giulio Camuffo | 61da3fc | 2013-04-25 13:57:45 +0300 | [diff] [blame] | 1939 | struct weston_surface *surface; |
Kristian Høgsberg | 9e31bff | 2012-08-01 00:08:07 -0400 | [diff] [blame] | 1940 | |
Derek Foreman | 1281a36 | 2015-07-31 16:55:32 -0500 | [diff] [blame] | 1941 | if (!pointer || |
| 1942 | pointer->button_count == 0 || |
| 1943 | pointer->grab_serial != serial || |
| 1944 | pointer->focus == NULL) |
Kristian Høgsberg | 70f2901 | 2014-01-09 15:43:17 -0800 | [diff] [blame] | 1945 | return; |
| 1946 | |
Derek Foreman | 1281a36 | 2015-07-31 16:55:32 -0500 | [diff] [blame] | 1947 | surface = weston_surface_get_main_surface(pointer->focus->surface); |
Kristian Høgsberg | 70f2901 | 2014-01-09 15:43:17 -0800 | [diff] [blame] | 1948 | if (surface != shsurf->surface) |
Kristian Høgsberg | 9e31bff | 2012-08-01 00:08:07 -0400 | [diff] [blame] | 1949 | return; |
| 1950 | |
Derek Foreman | 1281a36 | 2015-07-31 16:55:32 -0500 | [diff] [blame] | 1951 | if (surface_resize(shsurf, pointer, edges) < 0) |
Kristian Høgsberg | 9e31bff | 2012-08-01 00:08:07 -0400 | [diff] [blame] | 1952 | wl_resource_post_no_memory(resource); |
| 1953 | } |
| 1954 | |
Scott Moreau | c3e54eb | 2012-04-17 19:06:20 -0600 | [diff] [blame] | 1955 | static void |
Rafael Antognolli | e2a3455 | 2013-12-03 15:35:45 -0200 | [diff] [blame] | 1956 | shell_surface_resize(struct wl_client *client, struct wl_resource *resource, |
| 1957 | struct wl_resource *seat_resource, uint32_t serial, |
| 1958 | uint32_t edges) |
| 1959 | { |
| 1960 | common_surface_resize(resource, seat_resource, serial, edges); |
| 1961 | } |
| 1962 | |
| 1963 | static void |
Kristian Høgsberg | 6848c25 | 2013-05-08 22:02:59 -0400 | [diff] [blame] | 1964 | busy_cursor_grab_focus(struct weston_pointer_grab *base) |
Scott Moreau | c3e54eb | 2012-04-17 19:06:20 -0600 | [diff] [blame] | 1965 | { |
Kristian Høgsberg | d56bd90 | 2012-06-05 09:58:51 -0400 | [diff] [blame] | 1966 | struct shell_grab *grab = (struct shell_grab *) base; |
Kristian Høgsberg | 6848c25 | 2013-05-08 22:02:59 -0400 | [diff] [blame] | 1967 | struct weston_pointer *pointer = base->pointer; |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 1968 | struct weston_view *view; |
Kristian Høgsberg | 6848c25 | 2013-05-08 22:02:59 -0400 | [diff] [blame] | 1969 | wl_fixed_t sx, sy; |
| 1970 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 1971 | view = weston_compositor_pick_view(pointer->seat->compositor, |
| 1972 | pointer->x, pointer->y, |
| 1973 | &sx, &sy); |
Scott Moreau | c3e54eb | 2012-04-17 19:06:20 -0600 | [diff] [blame] | 1974 | |
Kristian Høgsberg | 2bff94e | 2014-02-11 12:22:51 -0800 | [diff] [blame] | 1975 | if (!grab->shsurf || grab->shsurf->surface != view->surface) { |
| 1976 | shell_grab_end(grab); |
| 1977 | free(grab); |
| 1978 | } |
Scott Moreau | c3e54eb | 2012-04-17 19:06:20 -0600 | [diff] [blame] | 1979 | } |
| 1980 | |
| 1981 | static void |
Giulio Camuffo | 1959ab8 | 2013-11-14 23:42:52 +0100 | [diff] [blame] | 1982 | busy_cursor_grab_motion(struct weston_pointer_grab *grab, uint32_t time, |
Jonas Ådahl | d251010 | 2014-10-05 21:39:14 +0200 | [diff] [blame] | 1983 | struct weston_pointer_motion_event *event) |
Scott Moreau | c3e54eb | 2012-04-17 19:06:20 -0600 | [diff] [blame] | 1984 | { |
Jonas Ådahl | d251010 | 2014-10-05 21:39:14 +0200 | [diff] [blame] | 1985 | weston_pointer_move(grab->pointer, event); |
Kristian Høgsberg | d56bd90 | 2012-06-05 09:58:51 -0400 | [diff] [blame] | 1986 | } |
Scott Moreau | c3e54eb | 2012-04-17 19:06:20 -0600 | [diff] [blame] | 1987 | |
Kristian Høgsberg | d56bd90 | 2012-06-05 09:58:51 -0400 | [diff] [blame] | 1988 | static void |
Kristian Høgsberg | 02bbabb | 2013-05-06 22:15:05 -0400 | [diff] [blame] | 1989 | busy_cursor_grab_button(struct weston_pointer_grab *base, |
Kristian Høgsberg | d56bd90 | 2012-06-05 09:58:51 -0400 | [diff] [blame] | 1990 | uint32_t time, uint32_t button, uint32_t state) |
| 1991 | { |
Kristian Høgsberg | bbe9839 | 2012-08-01 00:20:21 -0400 | [diff] [blame] | 1992 | struct shell_grab *grab = (struct shell_grab *) base; |
Kristian Høgsberg | e122b7b | 2013-05-08 16:47:00 -0400 | [diff] [blame] | 1993 | struct shell_surface *shsurf = grab->shsurf; |
Derek Foreman | 794fa0e | 2015-07-15 13:00:38 -0500 | [diff] [blame] | 1994 | struct weston_pointer *pointer = grab->grab.pointer; |
| 1995 | struct weston_seat *seat = pointer->seat; |
Kristian Høgsberg | bbe9839 | 2012-08-01 00:20:21 -0400 | [diff] [blame] | 1996 | |
Kristian Høgsberg | bbe9839 | 2012-08-01 00:20:21 -0400 | [diff] [blame] | 1997 | if (shsurf && button == BTN_LEFT && state) { |
Emilio Pozuelo Monfort | 9e7c759 | 2014-01-30 14:01:10 +0100 | [diff] [blame] | 1998 | activate(shsurf->shell, shsurf->surface, seat, true); |
Derek Foreman | 794fa0e | 2015-07-15 13:00:38 -0500 | [diff] [blame] | 1999 | surface_move(shsurf, pointer, false); |
Kristian Høgsberg | 0c36903 | 2013-02-14 21:31:44 -0500 | [diff] [blame] | 2000 | } else if (shsurf && button == BTN_RIGHT && state) { |
Emilio Pozuelo Monfort | 9e7c759 | 2014-01-30 14:01:10 +0100 | [diff] [blame] | 2001 | activate(shsurf->shell, shsurf->surface, seat, true); |
Derek Foreman | 74de469 | 2015-07-15 13:00:39 -0500 | [diff] [blame] | 2002 | surface_rotate(shsurf, pointer); |
Kristian Høgsberg | bbe9839 | 2012-08-01 00:20:21 -0400 | [diff] [blame] | 2003 | } |
Kristian Høgsberg | d56bd90 | 2012-06-05 09:58:51 -0400 | [diff] [blame] | 2004 | } |
| 2005 | |
Jonas Ådahl | 1ea343e | 2013-10-25 23:18:05 +0200 | [diff] [blame] | 2006 | static void |
| 2007 | busy_cursor_grab_cancel(struct weston_pointer_grab *base) |
| 2008 | { |
| 2009 | struct shell_grab *grab = (struct shell_grab *) base; |
| 2010 | |
| 2011 | shell_grab_end(grab); |
| 2012 | free(grab); |
| 2013 | } |
| 2014 | |
Kristian Høgsberg | 02bbabb | 2013-05-06 22:15:05 -0400 | [diff] [blame] | 2015 | static const struct weston_pointer_grab_interface busy_cursor_grab_interface = { |
Kristian Høgsberg | d56bd90 | 2012-06-05 09:58:51 -0400 | [diff] [blame] | 2016 | busy_cursor_grab_focus, |
| 2017 | busy_cursor_grab_motion, |
| 2018 | busy_cursor_grab_button, |
Jonas Ådahl | 0336ca0 | 2014-10-04 16:28:29 +0200 | [diff] [blame] | 2019 | noop_grab_axis, |
Jonas Ådahl | 1ea343e | 2013-10-25 23:18:05 +0200 | [diff] [blame] | 2020 | busy_cursor_grab_cancel, |
Kristian Høgsberg | d56bd90 | 2012-06-05 09:58:51 -0400 | [diff] [blame] | 2021 | }; |
| 2022 | |
| 2023 | static void |
Kristian Høgsberg | 02bbabb | 2013-05-06 22:15:05 -0400 | [diff] [blame] | 2024 | set_busy_cursor(struct shell_surface *shsurf, struct weston_pointer *pointer) |
Kristian Høgsberg | d56bd90 | 2012-06-05 09:58:51 -0400 | [diff] [blame] | 2025 | { |
| 2026 | struct shell_grab *grab; |
Kristian Høgsberg | d56bd90 | 2012-06-05 09:58:51 -0400 | [diff] [blame] | 2027 | |
Kristian Høgsberg | 2bff94e | 2014-02-11 12:22:51 -0800 | [diff] [blame] | 2028 | if (pointer->grab->interface == &busy_cursor_grab_interface) |
| 2029 | return; |
| 2030 | |
Kristian Høgsberg | d56bd90 | 2012-06-05 09:58:51 -0400 | [diff] [blame] | 2031 | grab = malloc(sizeof *grab); |
| 2032 | if (!grab) |
Scott Moreau | c3e54eb | 2012-04-17 19:06:20 -0600 | [diff] [blame] | 2033 | return; |
| 2034 | |
Ander Conselvan de Oliveira | b9d2a0f | 2012-06-28 18:08:05 +0300 | [diff] [blame] | 2035 | shell_grab_start(grab, &busy_cursor_grab_interface, shsurf, pointer, |
Jonas Ådahl | 6d6fb61 | 2015-11-17 16:00:33 +0800 | [diff] [blame] | 2036 | WESTON_DESKTOP_SHELL_CURSOR_BUSY); |
Ander Conselvan de Oliveira | e5a1aee | 2014-04-09 17:39:39 +0300 | [diff] [blame] | 2037 | /* Mark the shsurf as ungrabbed so that button binding is able |
| 2038 | * to move it. */ |
| 2039 | shsurf->grabbed = 0; |
Kristian Høgsberg | d56bd90 | 2012-06-05 09:58:51 -0400 | [diff] [blame] | 2040 | } |
Scott Moreau | c3e54eb | 2012-04-17 19:06:20 -0600 | [diff] [blame] | 2041 | |
Kristian Høgsberg | d56bd90 | 2012-06-05 09:58:51 -0400 | [diff] [blame] | 2042 | static void |
Kristian Høgsberg | 2bff94e | 2014-02-11 12:22:51 -0800 | [diff] [blame] | 2043 | end_busy_cursor(struct weston_compositor *compositor, struct wl_client *client) |
Kristian Høgsberg | d56bd90 | 2012-06-05 09:58:51 -0400 | [diff] [blame] | 2044 | { |
Kristian Høgsberg | 2bff94e | 2014-02-11 12:22:51 -0800 | [diff] [blame] | 2045 | struct shell_grab *grab; |
| 2046 | struct weston_seat *seat; |
Kristian Høgsberg | d56bd90 | 2012-06-05 09:58:51 -0400 | [diff] [blame] | 2047 | |
Kristian Høgsberg | 2bff94e | 2014-02-11 12:22:51 -0800 | [diff] [blame] | 2048 | wl_list_for_each(seat, &compositor->seat_list, link) { |
Derek Foreman | 1281a36 | 2015-07-31 16:55:32 -0500 | [diff] [blame] | 2049 | struct weston_pointer *pointer = weston_seat_get_pointer(seat); |
| 2050 | |
| 2051 | if (!pointer) |
Kristian Høgsberg | 2bff94e | 2014-02-11 12:22:51 -0800 | [diff] [blame] | 2052 | continue; |
| 2053 | |
Derek Foreman | 1281a36 | 2015-07-31 16:55:32 -0500 | [diff] [blame] | 2054 | grab = (struct shell_grab *) pointer->grab; |
Kristian Høgsberg | 2bff94e | 2014-02-11 12:22:51 -0800 | [diff] [blame] | 2055 | if (grab->grab.interface == &busy_cursor_grab_interface && |
Derek Foreman | c0c1497 | 2015-09-11 14:30:39 -0500 | [diff] [blame] | 2056 | grab->shsurf->resource && |
Kristian Høgsberg | 2bff94e | 2014-02-11 12:22:51 -0800 | [diff] [blame] | 2057 | wl_resource_get_client(grab->shsurf->resource) == client) { |
| 2058 | shell_grab_end(grab); |
| 2059 | free(grab); |
| 2060 | } |
Scott Moreau | c3e54eb | 2012-04-17 19:06:20 -0600 | [diff] [blame] | 2061 | } |
Scott Moreau | c3e54eb | 2012-04-17 19:06:20 -0600 | [diff] [blame] | 2062 | } |
| 2063 | |
Scott Moreau | 9521d5e | 2012-04-19 13:06:17 -0600 | [diff] [blame] | 2064 | static void |
Kristian Høgsberg | 2bff94e | 2014-02-11 12:22:51 -0800 | [diff] [blame] | 2065 | handle_shell_client_destroy(struct wl_listener *listener, void *data); |
| 2066 | |
| 2067 | static int |
| 2068 | xdg_ping_timeout_handler(void *data) |
| 2069 | { |
| 2070 | struct shell_client *sc = data; |
| 2071 | struct weston_seat *seat; |
| 2072 | struct shell_surface *shsurf; |
| 2073 | |
| 2074 | /* Client is not responding */ |
| 2075 | sc->unresponsive = 1; |
Kristian Høgsberg | 2bff94e | 2014-02-11 12:22:51 -0800 | [diff] [blame] | 2076 | wl_list_for_each(seat, &sc->shell->compositor->seat_list, link) { |
Derek Foreman | 1281a36 | 2015-07-31 16:55:32 -0500 | [diff] [blame] | 2077 | struct weston_pointer *pointer = weston_seat_get_pointer(seat); |
| 2078 | |
| 2079 | if (!pointer || |
| 2080 | !pointer->focus || |
| 2081 | !pointer->focus->surface->resource) |
Kristian Høgsberg | 2bff94e | 2014-02-11 12:22:51 -0800 | [diff] [blame] | 2082 | continue; |
Michael Vetter | 2a18a52 | 2015-05-15 17:17:47 +0200 | [diff] [blame] | 2083 | |
Derek Foreman | 1281a36 | 2015-07-31 16:55:32 -0500 | [diff] [blame] | 2084 | shsurf = get_shell_surface(pointer->focus->surface); |
Kristian Høgsberg | 2bff94e | 2014-02-11 12:22:51 -0800 | [diff] [blame] | 2085 | if (shsurf && |
| 2086 | wl_resource_get_client(shsurf->resource) == sc->client) |
Derek Foreman | 1281a36 | 2015-07-31 16:55:32 -0500 | [diff] [blame] | 2087 | set_busy_cursor(shsurf, pointer); |
Kristian Høgsberg | 2bff94e | 2014-02-11 12:22:51 -0800 | [diff] [blame] | 2088 | } |
| 2089 | |
| 2090 | return 1; |
| 2091 | } |
| 2092 | |
| 2093 | static void |
| 2094 | handle_xdg_ping(struct shell_surface *shsurf, uint32_t serial) |
| 2095 | { |
| 2096 | struct weston_compositor *compositor = shsurf->shell->compositor; |
Jason Ekstrand | 9e9512f | 2014-04-16 21:12:10 -0500 | [diff] [blame] | 2097 | struct shell_client *sc = shsurf->owner; |
Kristian Høgsberg | 2bff94e | 2014-02-11 12:22:51 -0800 | [diff] [blame] | 2098 | struct wl_event_loop *loop; |
Kristian Høgsberg | dd62aba | 2014-02-12 09:56:19 -0800 | [diff] [blame] | 2099 | static const int ping_timeout = 200; |
Kristian Høgsberg | 2bff94e | 2014-02-11 12:22:51 -0800 | [diff] [blame] | 2100 | |
Kristian Høgsberg | 2bff94e | 2014-02-11 12:22:51 -0800 | [diff] [blame] | 2101 | if (sc->unresponsive) { |
| 2102 | xdg_ping_timeout_handler(sc); |
| 2103 | return; |
| 2104 | } |
| 2105 | |
| 2106 | sc->ping_serial = serial; |
| 2107 | loop = wl_display_get_event_loop(compositor->wl_display); |
| 2108 | if (sc->ping_timer == NULL) |
| 2109 | sc->ping_timer = |
| 2110 | wl_event_loop_add_timer(loop, |
| 2111 | xdg_ping_timeout_handler, sc); |
| 2112 | if (sc->ping_timer == NULL) |
| 2113 | return; |
| 2114 | |
| 2115 | wl_event_source_timer_update(sc->ping_timer, ping_timeout); |
| 2116 | |
Kristian Høgsberg | dd62aba | 2014-02-12 09:56:19 -0800 | [diff] [blame] | 2117 | if (shell_surface_is_xdg_surface(shsurf) || |
| 2118 | shell_surface_is_xdg_popup(shsurf)) |
| 2119 | xdg_shell_send_ping(sc->resource, serial); |
| 2120 | else if (shell_surface_is_wl_shell_surface(shsurf)) |
| 2121 | wl_shell_surface_send_ping(shsurf->resource, serial); |
Kristian Høgsberg | 2bff94e | 2014-02-11 12:22:51 -0800 | [diff] [blame] | 2122 | } |
| 2123 | |
Scott Moreau | ff1db4a | 2012-04-17 19:06:18 -0600 | [diff] [blame] | 2124 | static void |
| 2125 | ping_handler(struct weston_surface *surface, uint32_t serial) |
| 2126 | { |
Kristian Høgsberg | b71302e | 2012-05-10 12:28:35 -0400 | [diff] [blame] | 2127 | struct shell_surface *shsurf = get_shell_surface(surface); |
Scott Moreau | ff1db4a | 2012-04-17 19:06:18 -0600 | [diff] [blame] | 2128 | |
| 2129 | if (!shsurf) |
| 2130 | return; |
Jason Ekstrand | 651f00e | 2013-06-14 10:07:54 -0500 | [diff] [blame] | 2131 | if (!shsurf->resource) |
Kristian Høgsberg | ca535c1 | 2012-04-21 23:20:07 -0400 | [diff] [blame] | 2132 | return; |
Ander Conselvan de Oliveira | eac9a46 | 2012-07-16 14:15:48 +0300 | [diff] [blame] | 2133 | if (shsurf->surface == shsurf->shell->grab_surface) |
| 2134 | return; |
| 2135 | |
Kristian Høgsberg | dd62aba | 2014-02-12 09:56:19 -0800 | [diff] [blame] | 2136 | handle_xdg_ping(shsurf, serial); |
Scott Moreau | ff1db4a | 2012-04-17 19:06:18 -0600 | [diff] [blame] | 2137 | } |
| 2138 | |
| 2139 | static void |
Kristian Høgsberg | d56bd90 | 2012-06-05 09:58:51 -0400 | [diff] [blame] | 2140 | handle_pointer_focus(struct wl_listener *listener, void *data) |
| 2141 | { |
Kristian Høgsberg | 02bbabb | 2013-05-06 22:15:05 -0400 | [diff] [blame] | 2142 | struct weston_pointer *pointer = data; |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 2143 | struct weston_view *view = pointer->focus; |
Kristian Høgsberg | d56bd90 | 2012-06-05 09:58:51 -0400 | [diff] [blame] | 2144 | struct weston_compositor *compositor; |
Kristian Høgsberg | d56bd90 | 2012-06-05 09:58:51 -0400 | [diff] [blame] | 2145 | uint32_t serial; |
| 2146 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 2147 | if (!view) |
Kristian Høgsberg | d56bd90 | 2012-06-05 09:58:51 -0400 | [diff] [blame] | 2148 | return; |
| 2149 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 2150 | compositor = view->surface->compositor; |
Kristian Høgsberg | e11ef64 | 2014-02-11 16:35:22 -0800 | [diff] [blame] | 2151 | serial = wl_display_next_serial(compositor->wl_display); |
| 2152 | ping_handler(view->surface, serial); |
Kristian Høgsberg | d56bd90 | 2012-06-05 09:58:51 -0400 | [diff] [blame] | 2153 | } |
| 2154 | |
| 2155 | static void |
Jasper St. Pierre | faf27a9 | 2013-12-09 17:36:28 -0500 | [diff] [blame] | 2156 | shell_surface_lose_keyboard_focus(struct shell_surface *shsurf) |
| 2157 | { |
| 2158 | if (--shsurf->focus_count == 0) |
Jasper St. Pierre | 973d787 | 2014-05-06 08:44:29 -0400 | [diff] [blame] | 2159 | shell_surface_state_changed(shsurf); |
Jasper St. Pierre | faf27a9 | 2013-12-09 17:36:28 -0500 | [diff] [blame] | 2160 | } |
| 2161 | |
| 2162 | static void |
| 2163 | shell_surface_gain_keyboard_focus(struct shell_surface *shsurf) |
| 2164 | { |
| 2165 | if (shsurf->focus_count++ == 0) |
Jasper St. Pierre | 973d787 | 2014-05-06 08:44:29 -0400 | [diff] [blame] | 2166 | shell_surface_state_changed(shsurf); |
Jasper St. Pierre | faf27a9 | 2013-12-09 17:36:28 -0500 | [diff] [blame] | 2167 | } |
| 2168 | |
| 2169 | static void |
| 2170 | handle_keyboard_focus(struct wl_listener *listener, void *data) |
| 2171 | { |
| 2172 | struct weston_keyboard *keyboard = data; |
| 2173 | struct shell_seat *seat = get_shell_seat(keyboard->seat); |
| 2174 | |
| 2175 | if (seat->focused_surface) { |
| 2176 | struct shell_surface *shsurf = get_shell_surface(seat->focused_surface); |
| 2177 | if (shsurf) |
| 2178 | shell_surface_lose_keyboard_focus(shsurf); |
| 2179 | } |
| 2180 | |
| 2181 | seat->focused_surface = keyboard->focus; |
| 2182 | |
| 2183 | if (seat->focused_surface) { |
| 2184 | struct shell_surface *shsurf = get_shell_surface(seat->focused_surface); |
| 2185 | if (shsurf) |
| 2186 | shell_surface_gain_keyboard_focus(shsurf); |
| 2187 | } |
| 2188 | } |
| 2189 | |
| 2190 | static void |
Kristian Høgsberg | dd62aba | 2014-02-12 09:56:19 -0800 | [diff] [blame] | 2191 | shell_client_pong(struct shell_client *sc, uint32_t serial) |
Rafael Antognolli | e2a3455 | 2013-12-03 15:35:45 -0200 | [diff] [blame] | 2192 | { |
Kristian Høgsberg | dd62aba | 2014-02-12 09:56:19 -0800 | [diff] [blame] | 2193 | if (sc->ping_serial != serial) |
| 2194 | return; |
Rafael Antognolli | e2a3455 | 2013-12-03 15:35:45 -0200 | [diff] [blame] | 2195 | |
Kristian Høgsberg | dd62aba | 2014-02-12 09:56:19 -0800 | [diff] [blame] | 2196 | sc->unresponsive = 0; |
| 2197 | end_busy_cursor(sc->shell->compositor, sc->client); |
Rafael Antognolli | e2a3455 | 2013-12-03 15:35:45 -0200 | [diff] [blame] | 2198 | |
Kristian Høgsberg | dd62aba | 2014-02-12 09:56:19 -0800 | [diff] [blame] | 2199 | if (sc->ping_timer) { |
| 2200 | wl_event_source_remove(sc->ping_timer); |
| 2201 | sc->ping_timer = NULL; |
| 2202 | } |
| 2203 | |
| 2204 | } |
| 2205 | |
| 2206 | static void |
| 2207 | shell_surface_pong(struct wl_client *client, |
| 2208 | struct wl_resource *resource, uint32_t serial) |
| 2209 | { |
Jason Ekstrand | 9e9512f | 2014-04-16 21:12:10 -0500 | [diff] [blame] | 2210 | struct shell_surface *shsurf = wl_resource_get_user_data(resource); |
| 2211 | struct shell_client *sc = shsurf->owner; |
Kristian Høgsberg | dd62aba | 2014-02-12 09:56:19 -0800 | [diff] [blame] | 2212 | |
Kristian Høgsberg | dd62aba | 2014-02-12 09:56:19 -0800 | [diff] [blame] | 2213 | shell_client_pong(sc, serial); |
Rafael Antognolli | e2a3455 | 2013-12-03 15:35:45 -0200 | [diff] [blame] | 2214 | } |
| 2215 | |
| 2216 | static void |
Giulio Camuffo | 62942ad | 2013-09-11 18:20:47 +0200 | [diff] [blame] | 2217 | set_title(struct shell_surface *shsurf, const char *title) |
| 2218 | { |
| 2219 | free(shsurf->title); |
| 2220 | shsurf->title = strdup(title); |
Pekka Paalanen | b502654 | 2014-11-12 15:09:24 +0200 | [diff] [blame] | 2221 | shsurf->surface->timeline.force_refresh = 1; |
| 2222 | } |
| 2223 | |
| 2224 | static void |
Giulio Camuffo | a8e9b41 | 2015-01-27 19:10:37 +0200 | [diff] [blame] | 2225 | set_pid(struct shell_surface *shsurf, pid_t pid) |
| 2226 | { |
| 2227 | /* We have no use for it */ |
| 2228 | } |
| 2229 | |
| 2230 | static void |
Pekka Paalanen | b502654 | 2014-11-12 15:09:24 +0200 | [diff] [blame] | 2231 | set_type(struct shell_surface *shsurf, enum shell_surface_type t) |
| 2232 | { |
| 2233 | shsurf->type = t; |
| 2234 | shsurf->surface->timeline.force_refresh = 1; |
Giulio Camuffo | 62942ad | 2013-09-11 18:20:47 +0200 | [diff] [blame] | 2235 | } |
| 2236 | |
| 2237 | static void |
Jasper St. Pierre | ccf48fb | 2014-05-02 10:21:38 -0400 | [diff] [blame] | 2238 | set_window_geometry(struct shell_surface *shsurf, |
| 2239 | 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] | 2240 | { |
Jasper St. Pierre | ccf48fb | 2014-05-02 10:21:38 -0400 | [diff] [blame] | 2241 | shsurf->next_geometry.x = x; |
| 2242 | shsurf->next_geometry.y = y; |
| 2243 | shsurf->next_geometry.width = width; |
| 2244 | shsurf->next_geometry.height = height; |
| 2245 | shsurf->has_next_geometry = true; |
Kristian Høgsberg | e5c1ae9 | 2014-04-30 16:28:41 -0700 | [diff] [blame] | 2246 | } |
| 2247 | |
| 2248 | static void |
Kristian Høgsberg | e7afd91 | 2012-05-02 09:47:44 -0400 | [diff] [blame] | 2249 | shell_surface_set_title(struct wl_client *client, |
| 2250 | struct wl_resource *resource, const char *title) |
| 2251 | { |
Jason Ekstrand | 651f00e | 2013-06-14 10:07:54 -0500 | [diff] [blame] | 2252 | struct shell_surface *shsurf = wl_resource_get_user_data(resource); |
Kristian Høgsberg | e7afd91 | 2012-05-02 09:47:44 -0400 | [diff] [blame] | 2253 | |
Giulio Camuffo | 62942ad | 2013-09-11 18:20:47 +0200 | [diff] [blame] | 2254 | set_title(shsurf, title); |
Kristian Høgsberg | e7afd91 | 2012-05-02 09:47:44 -0400 | [diff] [blame] | 2255 | } |
| 2256 | |
| 2257 | static void |
| 2258 | shell_surface_set_class(struct wl_client *client, |
| 2259 | struct wl_resource *resource, const char *class) |
| 2260 | { |
Jason Ekstrand | 651f00e | 2013-06-14 10:07:54 -0500 | [diff] [blame] | 2261 | struct shell_surface *shsurf = wl_resource_get_user_data(resource); |
Kristian Høgsberg | e7afd91 | 2012-05-02 09:47:44 -0400 | [diff] [blame] | 2262 | |
| 2263 | free(shsurf->class); |
| 2264 | shsurf->class = strdup(class); |
Pekka Paalanen | b502654 | 2014-11-12 15:09:24 +0200 | [diff] [blame] | 2265 | shsurf->surface->timeline.force_refresh = 1; |
Kristian Høgsberg | e7afd91 | 2012-05-02 09:47:44 -0400 | [diff] [blame] | 2266 | } |
| 2267 | |
Alex Wu | 4539b08 | 2012-03-01 12:57:46 +0800 | [diff] [blame] | 2268 | static void |
Alexander Larsson | f82b6ca | 2013-05-28 16:23:39 +0200 | [diff] [blame] | 2269 | restore_output_mode(struct weston_output *output) |
| 2270 | { |
Derek Foreman | 6ae7bc9 | 2014-11-04 10:47:33 -0600 | [diff] [blame] | 2271 | if (output->original_mode) |
| 2272 | weston_output_mode_switch_to_native(output); |
Alexander Larsson | f82b6ca | 2013-05-28 16:23:39 +0200 | [diff] [blame] | 2273 | } |
| 2274 | |
| 2275 | static void |
| 2276 | restore_all_output_modes(struct weston_compositor *compositor) |
| 2277 | { |
| 2278 | struct weston_output *output; |
| 2279 | |
| 2280 | wl_list_for_each(output, &compositor->output_list, link) |
| 2281 | restore_output_mode(output); |
| 2282 | } |
| 2283 | |
Philip Withnall | 07926d9 | 2013-11-25 18:01:40 +0000 | [diff] [blame] | 2284 | /* The surface will be inserted into the list immediately after the link |
| 2285 | * returned by this function (i.e. will be stacked immediately above the |
| 2286 | * returned link). */ |
Giulio Camuffo | 412e6a5 | 2014-07-09 22:12:56 +0300 | [diff] [blame] | 2287 | static struct weston_layer_entry * |
Philip Withnall | 07926d9 | 2013-11-25 18:01:40 +0000 | [diff] [blame] | 2288 | shell_surface_calculate_layer_link (struct shell_surface *shsurf) |
| 2289 | { |
| 2290 | struct workspace *ws; |
Kristian Høgsberg | ead5242 | 2014-01-01 13:51:52 -0800 | [diff] [blame] | 2291 | struct weston_view *parent; |
Philip Withnall | 07926d9 | 2013-11-25 18:01:40 +0000 | [diff] [blame] | 2292 | |
| 2293 | switch (shsurf->type) { |
Ander Conselvan de Oliveira | ef6a7e4 | 2014-04-30 14:15:14 +0300 | [diff] [blame] | 2294 | case SHELL_SURFACE_XWAYLAND: |
| 2295 | return &shsurf->shell->fullscreen_layer.view_list; |
| 2296 | |
| 2297 | case SHELL_SURFACE_NONE: |
| 2298 | return NULL; |
| 2299 | |
Kristian Høgsberg | ead5242 | 2014-01-01 13:51:52 -0800 | [diff] [blame] | 2300 | case SHELL_SURFACE_POPUP: |
| 2301 | case SHELL_SURFACE_TOPLEVEL: |
Emilio Pozuelo Monfort | 9e7c759 | 2014-01-30 14:01:10 +0100 | [diff] [blame] | 2302 | if (shsurf->state.fullscreen && !shsurf->state.lowered) { |
Rafael Antognolli | 03b1659 | 2013-12-03 15:35:42 -0200 | [diff] [blame] | 2303 | return &shsurf->shell->fullscreen_layer.view_list; |
Rafael Antognolli | ed207b4 | 2013-12-03 15:35:43 -0200 | [diff] [blame] | 2304 | } else if (shsurf->parent) { |
Kristian Høgsberg | d55db69 | 2014-01-01 12:26:14 -0800 | [diff] [blame] | 2305 | /* Move the surface to its parent layer so |
| 2306 | * that surfaces which are transient for |
| 2307 | * fullscreen surfaces don't get hidden by the |
| 2308 | * fullscreen surfaces. */ |
Rafael Antognolli | ed207b4 | 2013-12-03 15:35:43 -0200 | [diff] [blame] | 2309 | |
| 2310 | /* TODO: Handle a parent with multiple views */ |
| 2311 | parent = get_default_view(shsurf->parent); |
| 2312 | if (parent) |
Giulio Camuffo | 412e6a5 | 2014-07-09 22:12:56 +0300 | [diff] [blame] | 2313 | return container_of(parent->layer_link.link.prev, |
| 2314 | struct weston_layer_entry, link); |
Rafael Antognolli | ed207b4 | 2013-12-03 15:35:43 -0200 | [diff] [blame] | 2315 | } |
Philip Withnall | 07926d9 | 2013-11-25 18:01:40 +0000 | [diff] [blame] | 2316 | |
Ander Conselvan de Oliveira | ef6a7e4 | 2014-04-30 14:15:14 +0300 | [diff] [blame] | 2317 | /* Move the surface to a normal workspace layer so that surfaces |
| 2318 | * which were previously fullscreen or transient are no longer |
| 2319 | * rendered on top. */ |
| 2320 | ws = get_current_workspace(shsurf->shell); |
| 2321 | return &ws->layer.view_list; |
Philip Withnall | 07926d9 | 2013-11-25 18:01:40 +0000 | [diff] [blame] | 2322 | } |
| 2323 | |
Ander Conselvan de Oliveira | ef6a7e4 | 2014-04-30 14:15:14 +0300 | [diff] [blame] | 2324 | assert(0 && "Unknown shell surface type"); |
Philip Withnall | 07926d9 | 2013-11-25 18:01:40 +0000 | [diff] [blame] | 2325 | } |
| 2326 | |
Philip Withnall | 648a4dd | 2013-11-25 18:01:44 +0000 | [diff] [blame] | 2327 | static void |
| 2328 | shell_surface_update_child_surface_layers (struct shell_surface *shsurf) |
| 2329 | { |
| 2330 | struct shell_surface *child; |
Giulio Camuffo | 412e6a5 | 2014-07-09 22:12:56 +0300 | [diff] [blame] | 2331 | struct weston_layer_entry *prev; |
Philip Withnall | 648a4dd | 2013-11-25 18:01:44 +0000 | [diff] [blame] | 2332 | |
| 2333 | /* Move the child layers to the same workspace as shsurf. They will be |
| 2334 | * stacked above shsurf. */ |
| 2335 | wl_list_for_each_reverse(child, &shsurf->children_list, children_link) { |
Giulio Camuffo | 412e6a5 | 2014-07-09 22:12:56 +0300 | [diff] [blame] | 2336 | 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] | 2337 | weston_view_damage_below(child->view); |
Philip Withnall | 648a4dd | 2013-11-25 18:01:44 +0000 | [diff] [blame] | 2338 | weston_view_geometry_dirty(child->view); |
Giulio Camuffo | 412e6a5 | 2014-07-09 22:12:56 +0300 | [diff] [blame] | 2339 | prev = container_of(shsurf->view->layer_link.link.prev, |
| 2340 | struct weston_layer_entry, link); |
| 2341 | weston_layer_entry_remove(&child->view->layer_link); |
| 2342 | weston_layer_entry_insert(prev, |
| 2343 | &child->view->layer_link); |
Philip Withnall | 648a4dd | 2013-11-25 18:01:44 +0000 | [diff] [blame] | 2344 | weston_view_geometry_dirty(child->view); |
| 2345 | weston_surface_damage(child->surface); |
| 2346 | |
| 2347 | /* Recurse. We don’t expect this to recurse very far (if |
| 2348 | * at all) because that would imply we have transient |
| 2349 | * (or popup) children of transient surfaces, which |
| 2350 | * would be unusual. */ |
| 2351 | shell_surface_update_child_surface_layers(child); |
| 2352 | } |
| 2353 | } |
| 2354 | } |
| 2355 | |
Philip Withnall | e1d75ae | 2013-11-25 18:01:41 +0000 | [diff] [blame] | 2356 | /* 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] | 2357 | * geometry to ensure the changes are redrawn. |
| 2358 | * |
| 2359 | * If any child surfaces exist and are mapped, ensure they’re in the same layer |
| 2360 | * as this surface. */ |
Philip Withnall | e1d75ae | 2013-11-25 18:01:41 +0000 | [diff] [blame] | 2361 | static void |
| 2362 | shell_surface_update_layer(struct shell_surface *shsurf) |
| 2363 | { |
Giulio Camuffo | 412e6a5 | 2014-07-09 22:12:56 +0300 | [diff] [blame] | 2364 | struct weston_layer_entry *new_layer_link; |
Philip Withnall | e1d75ae | 2013-11-25 18:01:41 +0000 | [diff] [blame] | 2365 | |
| 2366 | new_layer_link = shell_surface_calculate_layer_link(shsurf); |
| 2367 | |
Ander Conselvan de Oliveira | ef6a7e4 | 2014-04-30 14:15:14 +0300 | [diff] [blame] | 2368 | if (new_layer_link == NULL) |
| 2369 | return; |
Philip Withnall | e1d75ae | 2013-11-25 18:01:41 +0000 | [diff] [blame] | 2370 | if (new_layer_link == &shsurf->view->layer_link) |
| 2371 | return; |
| 2372 | |
| 2373 | weston_view_geometry_dirty(shsurf->view); |
Giulio Camuffo | 412e6a5 | 2014-07-09 22:12:56 +0300 | [diff] [blame] | 2374 | weston_layer_entry_remove(&shsurf->view->layer_link); |
| 2375 | weston_layer_entry_insert(new_layer_link, &shsurf->view->layer_link); |
Philip Withnall | e1d75ae | 2013-11-25 18:01:41 +0000 | [diff] [blame] | 2376 | weston_view_geometry_dirty(shsurf->view); |
| 2377 | weston_surface_damage(shsurf->surface); |
Philip Withnall | 648a4dd | 2013-11-25 18:01:44 +0000 | [diff] [blame] | 2378 | |
| 2379 | shell_surface_update_child_surface_layers(shsurf); |
Philip Withnall | e1d75ae | 2013-11-25 18:01:41 +0000 | [diff] [blame] | 2380 | } |
| 2381 | |
Alexander Larsson | f82b6ca | 2013-05-28 16:23:39 +0200 | [diff] [blame] | 2382 | static void |
Philip Withnall | dc4332f | 2013-11-25 18:01:38 +0000 | [diff] [blame] | 2383 | shell_surface_set_parent(struct shell_surface *shsurf, |
| 2384 | struct weston_surface *parent) |
| 2385 | { |
| 2386 | shsurf->parent = parent; |
Philip Withnall | 648a4dd | 2013-11-25 18:01:44 +0000 | [diff] [blame] | 2387 | |
| 2388 | wl_list_remove(&shsurf->children_link); |
| 2389 | wl_list_init(&shsurf->children_link); |
| 2390 | |
| 2391 | /* Insert into the parent surface’s child list. */ |
| 2392 | if (parent != NULL) { |
| 2393 | struct shell_surface *parent_shsurf = get_shell_surface(parent); |
| 2394 | if (parent_shsurf != NULL) |
| 2395 | wl_list_insert(&parent_shsurf->children_list, |
| 2396 | &shsurf->children_link); |
| 2397 | } |
Philip Withnall | dc4332f | 2013-11-25 18:01:38 +0000 | [diff] [blame] | 2398 | } |
| 2399 | |
| 2400 | static void |
Philip Withnall | 352e7ed | 2013-11-25 18:01:35 +0000 | [diff] [blame] | 2401 | shell_surface_set_output(struct shell_surface *shsurf, |
| 2402 | struct weston_output *output) |
| 2403 | { |
| 2404 | struct weston_surface *es = shsurf->surface; |
| 2405 | |
| 2406 | /* get the default output, if the client set it as NULL |
| 2407 | check whether the ouput is available */ |
| 2408 | if (output) |
| 2409 | shsurf->output = output; |
| 2410 | else if (es->output) |
| 2411 | shsurf->output = es->output; |
| 2412 | else |
| 2413 | shsurf->output = get_default_output(es->compositor); |
| 2414 | } |
| 2415 | |
| 2416 | static void |
Rafael Antognolli | 03b1659 | 2013-12-03 15:35:42 -0200 | [diff] [blame] | 2417 | surface_clear_next_states(struct shell_surface *shsurf) |
| 2418 | { |
| 2419 | shsurf->next_state.maximized = false; |
| 2420 | shsurf->next_state.fullscreen = false; |
| 2421 | |
| 2422 | if ((shsurf->next_state.maximized != shsurf->state.maximized) || |
| 2423 | (shsurf->next_state.fullscreen != shsurf->state.fullscreen)) |
| 2424 | shsurf->state_changed = true; |
| 2425 | } |
| 2426 | |
| 2427 | static void |
Philip Withnall | becb77e | 2013-11-25 18:01:30 +0000 | [diff] [blame] | 2428 | set_toplevel(struct shell_surface *shsurf) |
| 2429 | { |
Kristian Høgsberg | 41fbf6f | 2013-12-05 22:31:25 -0800 | [diff] [blame] | 2430 | shell_surface_set_parent(shsurf, NULL); |
| 2431 | surface_clear_next_states(shsurf); |
Pekka Paalanen | b502654 | 2014-11-12 15:09:24 +0200 | [diff] [blame] | 2432 | set_type(shsurf, SHELL_SURFACE_TOPLEVEL); |
Philip Withnall | 648a4dd | 2013-11-25 18:01:44 +0000 | [diff] [blame] | 2433 | |
| 2434 | /* The layer_link is updated in set_surface_type(), |
| 2435 | * called from configure. */ |
Philip Withnall | becb77e | 2013-11-25 18:01:30 +0000 | [diff] [blame] | 2436 | } |
| 2437 | |
| 2438 | static void |
| 2439 | shell_surface_set_toplevel(struct wl_client *client, |
| 2440 | struct wl_resource *resource) |
| 2441 | { |
| 2442 | struct shell_surface *surface = wl_resource_get_user_data(resource); |
| 2443 | |
| 2444 | set_toplevel(surface); |
| 2445 | } |
| 2446 | |
| 2447 | static void |
| 2448 | set_transient(struct shell_surface *shsurf, |
| 2449 | struct weston_surface *parent, int x, int y, uint32_t flags) |
| 2450 | { |
Philip Withnall | dc4332f | 2013-11-25 18:01:38 +0000 | [diff] [blame] | 2451 | assert(parent != NULL); |
| 2452 | |
Kristian Høgsberg | 9f7e331 | 2014-01-02 22:40:37 -0800 | [diff] [blame] | 2453 | shell_surface_set_parent(shsurf, parent); |
| 2454 | |
| 2455 | surface_clear_next_states(shsurf); |
| 2456 | |
Philip Withnall | becb77e | 2013-11-25 18:01:30 +0000 | [diff] [blame] | 2457 | shsurf->transient.x = x; |
| 2458 | shsurf->transient.y = y; |
| 2459 | shsurf->transient.flags = flags; |
Philip Withnall | dc4332f | 2013-11-25 18:01:38 +0000 | [diff] [blame] | 2460 | |
Rafael Antognolli | ed207b4 | 2013-12-03 15:35:43 -0200 | [diff] [blame] | 2461 | shsurf->next_state.relative = true; |
Kristian Høgsberg | a1df7ac | 2013-12-31 15:01:01 -0800 | [diff] [blame] | 2462 | shsurf->state_changed = true; |
Pekka Paalanen | b502654 | 2014-11-12 15:09:24 +0200 | [diff] [blame] | 2463 | set_type(shsurf, SHELL_SURFACE_TOPLEVEL); |
Philip Withnall | 648a4dd | 2013-11-25 18:01:44 +0000 | [diff] [blame] | 2464 | |
| 2465 | /* The layer_link is updated in set_surface_type(), |
| 2466 | * called from configure. */ |
Philip Withnall | becb77e | 2013-11-25 18:01:30 +0000 | [diff] [blame] | 2467 | } |
| 2468 | |
| 2469 | static void |
| 2470 | shell_surface_set_transient(struct wl_client *client, |
| 2471 | struct wl_resource *resource, |
| 2472 | struct wl_resource *parent_resource, |
| 2473 | int x, int y, uint32_t flags) |
| 2474 | { |
| 2475 | struct shell_surface *shsurf = wl_resource_get_user_data(resource); |
| 2476 | struct weston_surface *parent = |
| 2477 | wl_resource_get_user_data(parent_resource); |
| 2478 | |
| 2479 | set_transient(shsurf, parent, x, y, flags); |
| 2480 | } |
| 2481 | |
| 2482 | static void |
| 2483 | set_fullscreen(struct shell_surface *shsurf, |
| 2484 | uint32_t method, |
| 2485 | uint32_t framerate, |
| 2486 | struct weston_output *output) |
| 2487 | { |
Philip Withnall | 352e7ed | 2013-11-25 18:01:35 +0000 | [diff] [blame] | 2488 | shell_surface_set_output(shsurf, output); |
Pekka Paalanen | b502654 | 2014-11-12 15:09:24 +0200 | [diff] [blame] | 2489 | set_type(shsurf, SHELL_SURFACE_TOPLEVEL); |
Philip Withnall | becb77e | 2013-11-25 18:01:30 +0000 | [diff] [blame] | 2490 | |
| 2491 | shsurf->fullscreen_output = shsurf->output; |
| 2492 | shsurf->fullscreen.type = method; |
| 2493 | shsurf->fullscreen.framerate = framerate; |
Philip Withnall | dc4332f | 2013-11-25 18:01:38 +0000 | [diff] [blame] | 2494 | |
Jasper St. Pierre | 6458ec3 | 2014-04-11 16:00:31 -0700 | [diff] [blame] | 2495 | send_configure_for_surface(shsurf); |
Philip Withnall | becb77e | 2013-11-25 18:01:30 +0000 | [diff] [blame] | 2496 | } |
| 2497 | |
| 2498 | static void |
Zhang, Xiong Y | 3123693 | 2013-12-13 22:10:57 +0200 | [diff] [blame] | 2499 | weston_view_set_initial_position(struct weston_view *view, |
| 2500 | struct desktop_shell *shell); |
| 2501 | |
| 2502 | static void |
Philip Withnall | becb77e | 2013-11-25 18:01:30 +0000 | [diff] [blame] | 2503 | unset_fullscreen(struct shell_surface *shsurf) |
Alex Wu | 4539b08 | 2012-03-01 12:57:46 +0800 | [diff] [blame] | 2504 | { |
Philip Withnall | f85fe84 | 2013-11-25 18:01:37 +0000 | [diff] [blame] | 2505 | /* Unset the fullscreen output, driver configuration and transforms. */ |
Alex Wu | bd3354b | 2012-04-17 17:20:49 +0800 | [diff] [blame] | 2506 | if (shsurf->fullscreen.type == WL_SHELL_SURFACE_FULLSCREEN_METHOD_DRIVER && |
| 2507 | shell_surface_is_top_fullscreen(shsurf)) { |
Alexander Larsson | f82b6ca | 2013-05-28 16:23:39 +0200 | [diff] [blame] | 2508 | restore_output_mode(shsurf->fullscreen_output); |
Alex Wu | bd3354b | 2012-04-17 17:20:49 +0800 | [diff] [blame] | 2509 | } |
Philip Withnall | f85fe84 | 2013-11-25 18:01:37 +0000 | [diff] [blame] | 2510 | |
Alex Wu | 4539b08 | 2012-03-01 12:57:46 +0800 | [diff] [blame] | 2511 | shsurf->fullscreen.type = WL_SHELL_SURFACE_FULLSCREEN_METHOD_DEFAULT; |
| 2512 | shsurf->fullscreen.framerate = 0; |
Philip Withnall | f85fe84 | 2013-11-25 18:01:37 +0000 | [diff] [blame] | 2513 | |
Alex Wu | 4539b08 | 2012-03-01 12:57:46 +0800 | [diff] [blame] | 2514 | wl_list_remove(&shsurf->fullscreen.transform.link); |
| 2515 | wl_list_init(&shsurf->fullscreen.transform.link); |
Philip Withnall | f85fe84 | 2013-11-25 18:01:37 +0000 | [diff] [blame] | 2516 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 2517 | if (shsurf->fullscreen.black_view) |
| 2518 | weston_surface_destroy(shsurf->fullscreen.black_view->surface); |
| 2519 | shsurf->fullscreen.black_view = NULL; |
Philip Withnall | f85fe84 | 2013-11-25 18:01:37 +0000 | [diff] [blame] | 2520 | |
Zhang, Xiong Y | 3123693 | 2013-12-13 22:10:57 +0200 | [diff] [blame] | 2521 | if (shsurf->saved_position_valid) |
| 2522 | weston_view_set_position(shsurf->view, |
| 2523 | shsurf->saved_x, shsurf->saved_y); |
| 2524 | else |
| 2525 | weston_view_set_initial_position(shsurf->view, shsurf->shell); |
| 2526 | |
Alex Wu | 7bcb8bd | 2012-04-27 09:07:24 +0800 | [diff] [blame] | 2527 | if (shsurf->saved_rotation_valid) { |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 2528 | wl_list_insert(&shsurf->view->geometry.transformation_list, |
Philip Withnall | becb77e | 2013-11-25 18:01:30 +0000 | [diff] [blame] | 2529 | &shsurf->rotation.transform.link); |
Alex Wu | 7bcb8bd | 2012-04-27 09:07:24 +0800 | [diff] [blame] | 2530 | shsurf->saved_rotation_valid = false; |
| 2531 | } |
Rafal Mielniczuk | 3e3862c | 2012-10-07 20:25:36 +0200 | [diff] [blame] | 2532 | |
Philip Withnall | e1d75ae | 2013-11-25 18:01:41 +0000 | [diff] [blame] | 2533 | /* Layer is updated in set_surface_type(). */ |
Alex Wu | 4539b08 | 2012-03-01 12:57:46 +0800 | [diff] [blame] | 2534 | } |
| 2535 | |
Rafal Mielniczuk | fffdcdd | 2013-03-11 19:26:54 +0100 | [diff] [blame] | 2536 | static void |
Philip Withnall | becb77e | 2013-11-25 18:01:30 +0000 | [diff] [blame] | 2537 | shell_surface_set_fullscreen(struct wl_client *client, |
| 2538 | struct wl_resource *resource, |
| 2539 | uint32_t method, |
| 2540 | uint32_t framerate, |
| 2541 | struct wl_resource *output_resource) |
| 2542 | { |
| 2543 | struct shell_surface *shsurf = wl_resource_get_user_data(resource); |
| 2544 | struct weston_output *output; |
| 2545 | |
| 2546 | if (output_resource) |
| 2547 | output = wl_resource_get_user_data(output_resource); |
| 2548 | else |
| 2549 | output = NULL; |
| 2550 | |
Rafael Antognolli | 4b99a40 | 2013-12-03 15:35:44 -0200 | [diff] [blame] | 2551 | shell_surface_set_parent(shsurf, NULL); |
| 2552 | |
Rafael Antognolli | 03b1659 | 2013-12-03 15:35:42 -0200 | [diff] [blame] | 2553 | surface_clear_next_states(shsurf); |
Jasper St. Pierre | 8c6aa45 | 2014-02-08 18:29:49 -0500 | [diff] [blame] | 2554 | shsurf->next_state.fullscreen = true; |
| 2555 | shsurf->state_changed = true; |
Jasper St. Pierre | 6458ec3 | 2014-04-11 16:00:31 -0700 | [diff] [blame] | 2556 | set_fullscreen(shsurf, method, framerate, output); |
Philip Withnall | becb77e | 2013-11-25 18:01:30 +0000 | [diff] [blame] | 2557 | } |
| 2558 | |
| 2559 | static void |
| 2560 | set_popup(struct shell_surface *shsurf, |
| 2561 | struct weston_surface *parent, |
| 2562 | struct weston_seat *seat, |
| 2563 | uint32_t serial, |
| 2564 | int32_t x, |
| 2565 | int32_t y) |
| 2566 | { |
Philip Withnall | dc4332f | 2013-11-25 18:01:38 +0000 | [diff] [blame] | 2567 | assert(parent != NULL); |
| 2568 | |
Philip Withnall | becb77e | 2013-11-25 18:01:30 +0000 | [diff] [blame] | 2569 | shsurf->popup.shseat = get_shell_seat(seat); |
| 2570 | shsurf->popup.serial = serial; |
| 2571 | shsurf->popup.x = x; |
| 2572 | shsurf->popup.y = y; |
Philip Withnall | dc4332f | 2013-11-25 18:01:38 +0000 | [diff] [blame] | 2573 | |
Pekka Paalanen | b502654 | 2014-11-12 15:09:24 +0200 | [diff] [blame] | 2574 | set_type(shsurf, SHELL_SURFACE_POPUP); |
Philip Withnall | becb77e | 2013-11-25 18:01:30 +0000 | [diff] [blame] | 2575 | } |
| 2576 | |
| 2577 | static void |
| 2578 | shell_surface_set_popup(struct wl_client *client, |
| 2579 | struct wl_resource *resource, |
| 2580 | struct wl_resource *seat_resource, |
| 2581 | uint32_t serial, |
| 2582 | struct wl_resource *parent_resource, |
| 2583 | int32_t x, int32_t y, uint32_t flags) |
| 2584 | { |
| 2585 | struct shell_surface *shsurf = wl_resource_get_user_data(resource); |
Rafael Antognolli | 4b99a40 | 2013-12-03 15:35:44 -0200 | [diff] [blame] | 2586 | struct weston_surface *parent = |
| 2587 | wl_resource_get_user_data(parent_resource); |
| 2588 | |
| 2589 | shell_surface_set_parent(shsurf, parent); |
Philip Withnall | becb77e | 2013-11-25 18:01:30 +0000 | [diff] [blame] | 2590 | |
Rafael Antognolli | 03b1659 | 2013-12-03 15:35:42 -0200 | [diff] [blame] | 2591 | surface_clear_next_states(shsurf); |
Philip Withnall | becb77e | 2013-11-25 18:01:30 +0000 | [diff] [blame] | 2592 | set_popup(shsurf, |
Rafael Antognolli | 4b99a40 | 2013-12-03 15:35:44 -0200 | [diff] [blame] | 2593 | parent, |
Philip Withnall | becb77e | 2013-11-25 18:01:30 +0000 | [diff] [blame] | 2594 | wl_resource_get_user_data(seat_resource), |
| 2595 | serial, x, y); |
| 2596 | } |
| 2597 | |
| 2598 | static void |
Philip Withnall | becb77e | 2013-11-25 18:01:30 +0000 | [diff] [blame] | 2599 | unset_maximized(struct shell_surface *shsurf) |
Rafal Mielniczuk | fffdcdd | 2013-03-11 19:26:54 +0100 | [diff] [blame] | 2600 | { |
Rafal Mielniczuk | fffdcdd | 2013-03-11 19:26:54 +0100 | [diff] [blame] | 2601 | /* undo all maximized things here */ |
| 2602 | shsurf->output = get_default_output(shsurf->surface->compositor); |
Zhang, Xiong Y | 3123693 | 2013-12-13 22:10:57 +0200 | [diff] [blame] | 2603 | |
| 2604 | if (shsurf->saved_position_valid) |
| 2605 | weston_view_set_position(shsurf->view, |
| 2606 | shsurf->saved_x, shsurf->saved_y); |
| 2607 | else |
| 2608 | weston_view_set_initial_position(shsurf->view, shsurf->shell); |
Rafal Mielniczuk | fffdcdd | 2013-03-11 19:26:54 +0100 | [diff] [blame] | 2609 | |
| 2610 | if (shsurf->saved_rotation_valid) { |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 2611 | wl_list_insert(&shsurf->view->geometry.transformation_list, |
| 2612 | &shsurf->rotation.transform.link); |
Rafal Mielniczuk | fffdcdd | 2013-03-11 19:26:54 +0100 | [diff] [blame] | 2613 | shsurf->saved_rotation_valid = false; |
| 2614 | } |
| 2615 | |
Philip Withnall | e1d75ae | 2013-11-25 18:01:41 +0000 | [diff] [blame] | 2616 | /* Layer is updated in set_surface_type(). */ |
Rafal Mielniczuk | fffdcdd | 2013-03-11 19:26:54 +0100 | [diff] [blame] | 2617 | } |
| 2618 | |
Philip Withnall | becb77e | 2013-11-25 18:01:30 +0000 | [diff] [blame] | 2619 | static void |
Manuel Bachmann | dc1c3e4 | 2015-02-16 11:52:13 +0100 | [diff] [blame] | 2620 | set_minimized(struct weston_surface *surface) |
Manuel Bachmann | 50c87db | 2014-02-26 15:52:13 +0100 | [diff] [blame] | 2621 | { |
| 2622 | struct shell_surface *shsurf; |
| 2623 | struct workspace *current_ws; |
Manuel Bachmann | 50c87db | 2014-02-26 15:52:13 +0100 | [diff] [blame] | 2624 | struct weston_view *view; |
| 2625 | |
| 2626 | view = get_default_view(surface); |
| 2627 | if (!view) |
| 2628 | return; |
| 2629 | |
| 2630 | assert(weston_surface_get_main_surface(view->surface) == view->surface); |
| 2631 | |
| 2632 | shsurf = get_shell_surface(surface); |
| 2633 | current_ws = get_current_workspace(shsurf->shell); |
| 2634 | |
Giulio Camuffo | 412e6a5 | 2014-07-09 22:12:56 +0300 | [diff] [blame] | 2635 | weston_layer_entry_remove(&view->layer_link); |
Manuel Bachmann | dc1c3e4 | 2015-02-16 11:52:13 +0100 | [diff] [blame] | 2636 | 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] | 2637 | |
Manuel Bachmann | dc1c3e4 | 2015-02-16 11:52:13 +0100 | [diff] [blame] | 2638 | drop_focus_state(shsurf->shell, current_ws, view->surface); |
Jonas Ådahl | 22faea1 | 2014-10-15 22:02:06 +0200 | [diff] [blame] | 2639 | surface_keyboard_focus_lost(surface); |
Manuel Bachmann | 50c87db | 2014-02-26 15:52:13 +0100 | [diff] [blame] | 2640 | |
| 2641 | shell_surface_update_child_surface_layers(shsurf); |
Manuel Bachmann | 50c87db | 2014-02-26 15:52:13 +0100 | [diff] [blame] | 2642 | weston_view_damage_below(view); |
| 2643 | } |
| 2644 | |
| 2645 | static void |
Philip Withnall | becb77e | 2013-11-25 18:01:30 +0000 | [diff] [blame] | 2646 | shell_surface_set_maximized(struct wl_client *client, |
| 2647 | struct wl_resource *resource, |
| 2648 | struct wl_resource *output_resource) |
| 2649 | { |
| 2650 | struct shell_surface *shsurf = wl_resource_get_user_data(resource); |
| 2651 | struct weston_output *output; |
| 2652 | |
Jasper St. Pierre | 9aa8ce6 | 2014-04-11 16:18:54 -0700 | [diff] [blame] | 2653 | surface_clear_next_states(shsurf); |
| 2654 | shsurf->next_state.maximized = true; |
| 2655 | shsurf->state_changed = true; |
| 2656 | |
Pekka Paalanen | b502654 | 2014-11-12 15:09:24 +0200 | [diff] [blame] | 2657 | set_type(shsurf, SHELL_SURFACE_TOPLEVEL); |
Jasper St. Pierre | 9aa8ce6 | 2014-04-11 16:18:54 -0700 | [diff] [blame] | 2658 | shell_surface_set_parent(shsurf, NULL); |
| 2659 | |
Philip Withnall | becb77e | 2013-11-25 18:01:30 +0000 | [diff] [blame] | 2660 | if (output_resource) |
| 2661 | output = wl_resource_get_user_data(output_resource); |
| 2662 | else |
| 2663 | output = NULL; |
| 2664 | |
Jasper St. Pierre | 9aa8ce6 | 2014-04-11 16:18:54 -0700 | [diff] [blame] | 2665 | shell_surface_set_output(shsurf, output); |
Rafael Antognolli | 4b99a40 | 2013-12-03 15:35:44 -0200 | [diff] [blame] | 2666 | |
Jasper St. Pierre | 9aa8ce6 | 2014-04-11 16:18:54 -0700 | [diff] [blame] | 2667 | send_configure_for_surface(shsurf); |
Philip Withnall | becb77e | 2013-11-25 18:01:30 +0000 | [diff] [blame] | 2668 | } |
| 2669 | |
Philip Withnall | e1d75ae | 2013-11-25 18:01:41 +0000 | [diff] [blame] | 2670 | /* This is only ever called from set_surface_type(), so there’s no need to |
| 2671 | * update layer_links here, since they’ll be updated when we return. */ |
Pekka Paalanen | 9826223 | 2011-12-01 10:42:22 +0200 | [diff] [blame] | 2672 | static int |
Philip Withnall | becb77e | 2013-11-25 18:01:30 +0000 | [diff] [blame] | 2673 | reset_surface_type(struct shell_surface *surface) |
Pekka Paalanen | 9826223 | 2011-12-01 10:42:22 +0200 | [diff] [blame] | 2674 | { |
Rafael Antognolli | 03b1659 | 2013-12-03 15:35:42 -0200 | [diff] [blame] | 2675 | if (surface->state.fullscreen) |
Philip Withnall | becb77e | 2013-11-25 18:01:30 +0000 | [diff] [blame] | 2676 | unset_fullscreen(surface); |
Rafael Antognolli | 03b1659 | 2013-12-03 15:35:42 -0200 | [diff] [blame] | 2677 | if (surface->state.maximized) |
Philip Withnall | becb77e | 2013-11-25 18:01:30 +0000 | [diff] [blame] | 2678 | unset_maximized(surface); |
Pekka Paalanen | 9826223 | 2011-12-01 10:42:22 +0200 | [diff] [blame] | 2679 | |
Pekka Paalanen | 9826223 | 2011-12-01 10:42:22 +0200 | [diff] [blame] | 2680 | return 0; |
| 2681 | } |
| 2682 | |
Kristian Høgsberg | 4cca349 | 2011-01-18 07:53:49 -0500 | [diff] [blame] | 2683 | static void |
Rafael Antognolli | 03b1659 | 2013-12-03 15:35:42 -0200 | [diff] [blame] | 2684 | set_full_output(struct shell_surface *shsurf) |
| 2685 | { |
| 2686 | shsurf->saved_x = shsurf->view->geometry.x; |
| 2687 | shsurf->saved_y = shsurf->view->geometry.y; |
Rafael Antognolli | 3c4e3f7 | 2013-12-03 15:35:46 -0200 | [diff] [blame] | 2688 | shsurf->saved_width = shsurf->surface->width; |
| 2689 | shsurf->saved_height = shsurf->surface->height; |
| 2690 | shsurf->saved_size_valid = true; |
Rafael Antognolli | 03b1659 | 2013-12-03 15:35:42 -0200 | [diff] [blame] | 2691 | shsurf->saved_position_valid = true; |
| 2692 | |
| 2693 | if (!wl_list_empty(&shsurf->rotation.transform.link)) { |
| 2694 | wl_list_remove(&shsurf->rotation.transform.link); |
| 2695 | wl_list_init(&shsurf->rotation.transform.link); |
| 2696 | weston_view_geometry_dirty(shsurf->view); |
| 2697 | shsurf->saved_rotation_valid = true; |
| 2698 | } |
| 2699 | } |
| 2700 | |
| 2701 | static void |
Kristian Høgsberg | 7f366e7 | 2012-04-27 17:20:01 -0400 | [diff] [blame] | 2702 | set_surface_type(struct shell_surface *shsurf) |
| 2703 | { |
Kristian Høgsberg | 8150b19 | 2012-06-27 10:22:58 -0400 | [diff] [blame] | 2704 | struct weston_surface *pes = shsurf->parent; |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 2705 | struct weston_view *pev = get_default_view(pes); |
Kristian Høgsberg | 7f366e7 | 2012-04-27 17:20:01 -0400 | [diff] [blame] | 2706 | |
Philip Withnall | becb77e | 2013-11-25 18:01:30 +0000 | [diff] [blame] | 2707 | reset_surface_type(shsurf); |
Kristian Høgsberg | 7f366e7 | 2012-04-27 17:20:01 -0400 | [diff] [blame] | 2708 | |
Rafael Antognolli | 03b1659 | 2013-12-03 15:35:42 -0200 | [diff] [blame] | 2709 | shsurf->state = shsurf->next_state; |
Rafael Antognolli | 03b1659 | 2013-12-03 15:35:42 -0200 | [diff] [blame] | 2710 | shsurf->state_changed = false; |
Kristian Høgsberg | 7f366e7 | 2012-04-27 17:20:01 -0400 | [diff] [blame] | 2711 | |
| 2712 | switch (shsurf->type) { |
| 2713 | case SHELL_SURFACE_TOPLEVEL: |
Rafael Antognolli | ed207b4 | 2013-12-03 15:35:43 -0200 | [diff] [blame] | 2714 | if (shsurf->state.maximized || shsurf->state.fullscreen) { |
Rafael Antognolli | 03b1659 | 2013-12-03 15:35:42 -0200 | [diff] [blame] | 2715 | set_full_output(shsurf); |
Rafael Antognolli | ed207b4 | 2013-12-03 15:35:43 -0200 | [diff] [blame] | 2716 | } else if (shsurf->state.relative && pev) { |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 2717 | weston_view_set_position(shsurf->view, |
| 2718 | pev->geometry.x + shsurf->transient.x, |
| 2719 | pev->geometry.y + shsurf->transient.y); |
Rafael Antognolli | ed207b4 | 2013-12-03 15:35:43 -0200 | [diff] [blame] | 2720 | } |
Rafael Antognolli | 44a3162 | 2013-12-04 18:37:16 -0200 | [diff] [blame] | 2721 | break; |
Kristian Høgsberg | 7f366e7 | 2012-04-27 17:20:01 -0400 | [diff] [blame] | 2722 | |
Tiago Vignatti | fb2adba | 2013-06-12 15:43:21 -0300 | [diff] [blame] | 2723 | case SHELL_SURFACE_XWAYLAND: |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 2724 | weston_view_set_position(shsurf->view, shsurf->transient.x, |
| 2725 | shsurf->transient.y); |
Tiago Vignatti | fb2adba | 2013-06-12 15:43:21 -0300 | [diff] [blame] | 2726 | break; |
| 2727 | |
Philip Withnall | 0f640e2 | 2013-11-25 18:01:31 +0000 | [diff] [blame] | 2728 | case SHELL_SURFACE_POPUP: |
| 2729 | case SHELL_SURFACE_NONE: |
Kristian Høgsberg | 7f366e7 | 2012-04-27 17:20:01 -0400 | [diff] [blame] | 2730 | default: |
| 2731 | break; |
| 2732 | } |
Philip Withnall | e1d75ae | 2013-11-25 18:01:41 +0000 | [diff] [blame] | 2733 | |
| 2734 | /* Update the surface’s layer. */ |
| 2735 | shell_surface_update_layer(shsurf); |
Kristian Høgsberg | 7f366e7 | 2012-04-27 17:20:01 -0400 | [diff] [blame] | 2736 | } |
| 2737 | |
Tiago Vignatti | be14326 | 2012-04-16 17:31:41 +0300 | [diff] [blame] | 2738 | static struct desktop_shell * |
Juan Zhao | 96879df | 2012-02-07 08:45:41 +0800 | [diff] [blame] | 2739 | shell_surface_get_shell(struct shell_surface *shsurf) |
Pekka Paalanen | af0e34c | 2011-12-02 10:59:17 +0200 | [diff] [blame] | 2740 | { |
Kristian Høgsberg | 02e79dc | 2012-04-12 09:55:26 -0400 | [diff] [blame] | 2741 | return shsurf->shell; |
Juan Zhao | 96879df | 2012-02-07 08:45:41 +0800 | [diff] [blame] | 2742 | } |
| 2743 | |
Pekka Paalanen | 8274d90 | 2014-08-06 19:36:51 +0300 | [diff] [blame] | 2744 | static int |
| 2745 | black_surface_get_label(struct weston_surface *surface, char *buf, size_t len) |
| 2746 | { |
| 2747 | struct weston_surface *fs_surface = surface->configure_private; |
| 2748 | int n; |
| 2749 | int rem; |
| 2750 | int ret; |
| 2751 | |
| 2752 | n = snprintf(buf, len, "black background surface for "); |
| 2753 | if (n < 0) |
| 2754 | return n; |
| 2755 | |
| 2756 | rem = (int)len - n; |
| 2757 | if (rem < 0) |
| 2758 | rem = 0; |
| 2759 | |
| 2760 | if (fs_surface->get_label) |
| 2761 | ret = fs_surface->get_label(fs_surface, buf + n, rem); |
| 2762 | else |
| 2763 | ret = snprintf(buf + n, rem, "<unknown>"); |
| 2764 | |
| 2765 | if (ret < 0) |
| 2766 | return n; |
| 2767 | |
| 2768 | return n + ret; |
| 2769 | } |
| 2770 | |
Alex Wu | 2185843 | 2012-04-01 20:13:08 +0800 | [diff] [blame] | 2771 | static void |
Jason Ekstrand | 918f2dd | 2013-12-02 21:01:53 -0600 | [diff] [blame] | 2772 | 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] | 2773 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 2774 | static struct weston_view * |
Alex Wu | 4539b08 | 2012-03-01 12:57:46 +0800 | [diff] [blame] | 2775 | create_black_surface(struct weston_compositor *ec, |
Alex Wu | 2185843 | 2012-04-01 20:13:08 +0800 | [diff] [blame] | 2776 | struct weston_surface *fs_surface, |
John Kåre Alsaker | 490d02a | 2012-09-30 02:57:21 +0200 | [diff] [blame] | 2777 | float x, float y, int w, int h) |
Alex Wu | 4539b08 | 2012-03-01 12:57:46 +0800 | [diff] [blame] | 2778 | { |
| 2779 | struct weston_surface *surface = NULL; |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 2780 | struct weston_view *view; |
Alex Wu | 4539b08 | 2012-03-01 12:57:46 +0800 | [diff] [blame] | 2781 | |
| 2782 | surface = weston_surface_create(ec); |
| 2783 | if (surface == NULL) { |
Martin Minarik | 6d11836 | 2012-06-07 18:01:59 +0200 | [diff] [blame] | 2784 | weston_log("no memory\n"); |
Alex Wu | 4539b08 | 2012-03-01 12:57:46 +0800 | [diff] [blame] | 2785 | return NULL; |
| 2786 | } |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 2787 | view = weston_view_create(surface); |
| 2788 | if (surface == NULL) { |
| 2789 | weston_log("no memory\n"); |
| 2790 | weston_surface_destroy(surface); |
| 2791 | return NULL; |
| 2792 | } |
Alex Wu | 4539b08 | 2012-03-01 12:57:46 +0800 | [diff] [blame] | 2793 | |
Alex Wu | 2185843 | 2012-04-01 20:13:08 +0800 | [diff] [blame] | 2794 | surface->configure = black_surface_configure; |
Giulio Camuffo | 7fe01b1 | 2013-03-28 18:02:42 +0100 | [diff] [blame] | 2795 | surface->configure_private = fs_surface; |
Pekka Paalanen | 8274d90 | 2014-08-06 19:36:51 +0300 | [diff] [blame] | 2796 | weston_surface_set_label_func(surface, black_surface_get_label); |
Alex Wu | 4539b08 | 2012-03-01 12:57:46 +0800 | [diff] [blame] | 2797 | weston_surface_set_color(surface, 0.0, 0.0, 0.0, 1); |
Pekka Paalanen | 71f6f3b | 2012-10-10 12:49:26 +0300 | [diff] [blame] | 2798 | pixman_region32_fini(&surface->opaque); |
Kristian Høgsberg | 61f00f5 | 2012-08-03 16:31:36 -0400 | [diff] [blame] | 2799 | pixman_region32_init_rect(&surface->opaque, 0, 0, w, h); |
Jonas Ådahl | 33619a4 | 2013-01-15 21:25:55 +0100 | [diff] [blame] | 2800 | pixman_region32_fini(&surface->input); |
| 2801 | pixman_region32_init_rect(&surface->input, 0, 0, w, h); |
Jason Ekstrand | 918f2dd | 2013-12-02 21:01:53 -0600 | [diff] [blame] | 2802 | |
Jason Ekstrand | 6228ee2 | 2014-01-01 15:58:57 -0600 | [diff] [blame] | 2803 | weston_surface_set_size(surface, w, h); |
Jason Ekstrand | 918f2dd | 2013-12-02 21:01:53 -0600 | [diff] [blame] | 2804 | weston_view_set_position(view, x, y); |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 2805 | |
| 2806 | return view; |
Alex Wu | 4539b08 | 2012-03-01 12:57:46 +0800 | [diff] [blame] | 2807 | } |
| 2808 | |
Philip Withnall | ed8f1a9 | 2013-11-25 18:01:43 +0000 | [diff] [blame] | 2809 | static void |
| 2810 | shell_ensure_fullscreen_black_view(struct shell_surface *shsurf) |
| 2811 | { |
| 2812 | struct weston_output *output = shsurf->fullscreen_output; |
| 2813 | |
Rafael Antognolli | 03b1659 | 2013-12-03 15:35:42 -0200 | [diff] [blame] | 2814 | assert(shsurf->state.fullscreen); |
Philip Withnall | ed8f1a9 | 2013-11-25 18:01:43 +0000 | [diff] [blame] | 2815 | |
| 2816 | if (!shsurf->fullscreen.black_view) |
| 2817 | shsurf->fullscreen.black_view = |
| 2818 | create_black_surface(shsurf->surface->compositor, |
| 2819 | shsurf->surface, |
| 2820 | output->x, output->y, |
| 2821 | output->width, |
| 2822 | output->height); |
| 2823 | |
| 2824 | weston_view_geometry_dirty(shsurf->fullscreen.black_view); |
Giulio Camuffo | 412e6a5 | 2014-07-09 22:12:56 +0300 | [diff] [blame] | 2825 | weston_layer_entry_remove(&shsurf->fullscreen.black_view->layer_link); |
| 2826 | weston_layer_entry_insert(&shsurf->view->layer_link, |
| 2827 | &shsurf->fullscreen.black_view->layer_link); |
Philip Withnall | ed8f1a9 | 2013-11-25 18:01:43 +0000 | [diff] [blame] | 2828 | weston_view_geometry_dirty(shsurf->fullscreen.black_view); |
| 2829 | weston_surface_damage(shsurf->surface); |
Emilio Pozuelo Monfort | 9e7c759 | 2014-01-30 14:01:10 +0100 | [diff] [blame] | 2830 | |
| 2831 | shsurf->state.lowered = false; |
Philip Withnall | ed8f1a9 | 2013-11-25 18:01:43 +0000 | [diff] [blame] | 2832 | } |
| 2833 | |
Alex Wu | 4539b08 | 2012-03-01 12:57:46 +0800 | [diff] [blame] | 2834 | /* Create black surface and append it to the associated fullscreen surface. |
| 2835 | * Handle size dismatch and positioning according to the method. */ |
| 2836 | static void |
| 2837 | shell_configure_fullscreen(struct shell_surface *shsurf) |
| 2838 | { |
| 2839 | struct weston_output *output = shsurf->fullscreen_output; |
| 2840 | struct weston_surface *surface = shsurf->surface; |
| 2841 | struct weston_matrix *matrix; |
Kristian Høgsberg | 240dfeb | 2012-07-12 12:32:31 -0400 | [diff] [blame] | 2842 | float scale, output_aspect, surface_aspect, x, y; |
Giulio Camuffo | b836664 | 2013-04-25 13:57:46 +0300 | [diff] [blame] | 2843 | int32_t surf_x, surf_y, surf_width, surf_height; |
Alex Wu | 4539b08 | 2012-03-01 12:57:46 +0800 | [diff] [blame] | 2844 | |
Alexander Larsson | f82b6ca | 2013-05-28 16:23:39 +0200 | [diff] [blame] | 2845 | if (shsurf->fullscreen.type != WL_SHELL_SURFACE_FULLSCREEN_METHOD_DRIVER) |
| 2846 | restore_output_mode(output); |
| 2847 | |
Emilio Pozuelo Monfort | 9e7c759 | 2014-01-30 14:01:10 +0100 | [diff] [blame] | 2848 | /* Reverse the effect of lower_fullscreen_layer() */ |
Giulio Camuffo | 412e6a5 | 2014-07-09 22:12:56 +0300 | [diff] [blame] | 2849 | weston_layer_entry_remove(&shsurf->view->layer_link); |
| 2850 | 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] | 2851 | |
Philip Withnall | ed8f1a9 | 2013-11-25 18:01:43 +0000 | [diff] [blame] | 2852 | shell_ensure_fullscreen_black_view(shsurf); |
Alex Wu | 4539b08 | 2012-03-01 12:57:46 +0800 | [diff] [blame] | 2853 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 2854 | surface_subsurfaces_boundingbox(shsurf->surface, &surf_x, &surf_y, |
Giulio Camuffo | b836664 | 2013-04-25 13:57:46 +0300 | [diff] [blame] | 2855 | &surf_width, &surf_height); |
| 2856 | |
Alex Wu | 4539b08 | 2012-03-01 12:57:46 +0800 | [diff] [blame] | 2857 | switch (shsurf->fullscreen.type) { |
| 2858 | case WL_SHELL_SURFACE_FULLSCREEN_METHOD_DEFAULT: |
Pekka Paalanen | de685b8 | 2012-12-04 15:58:12 +0200 | [diff] [blame] | 2859 | if (surface->buffer_ref.buffer) |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 2860 | center_on_output(shsurf->view, shsurf->fullscreen_output); |
Alex Wu | 4539b08 | 2012-03-01 12:57:46 +0800 | [diff] [blame] | 2861 | break; |
| 2862 | case WL_SHELL_SURFACE_FULLSCREEN_METHOD_SCALE: |
Rob Bradford | 9f3dd15 | 2013-02-12 11:53:47 +0000 | [diff] [blame] | 2863 | /* 1:1 mapping between surface and output dimensions */ |
Giulio Camuffo | b836664 | 2013-04-25 13:57:46 +0300 | [diff] [blame] | 2864 | if (output->width == surf_width && |
| 2865 | output->height == surf_height) { |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 2866 | weston_view_set_position(shsurf->view, |
| 2867 | output->x - surf_x, |
| 2868 | output->y - surf_y); |
Rob Bradford | 9f3dd15 | 2013-02-12 11:53:47 +0000 | [diff] [blame] | 2869 | break; |
| 2870 | } |
| 2871 | |
Alex Wu | 4539b08 | 2012-03-01 12:57:46 +0800 | [diff] [blame] | 2872 | matrix = &shsurf->fullscreen.transform.matrix; |
| 2873 | weston_matrix_init(matrix); |
Kristian Høgsberg | 240dfeb | 2012-07-12 12:32:31 -0400 | [diff] [blame] | 2874 | |
Scott Moreau | 1bad5db | 2012-08-18 01:04:05 -0600 | [diff] [blame] | 2875 | output_aspect = (float) output->width / |
| 2876 | (float) output->height; |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 2877 | /* XXX: Use surf_width and surf_height here? */ |
| 2878 | surface_aspect = (float) surface->width / |
| 2879 | (float) surface->height; |
Kristian Høgsberg | 240dfeb | 2012-07-12 12:32:31 -0400 | [diff] [blame] | 2880 | if (output_aspect < surface_aspect) |
Scott Moreau | 1bad5db | 2012-08-18 01:04:05 -0600 | [diff] [blame] | 2881 | scale = (float) output->width / |
Giulio Camuffo | b836664 | 2013-04-25 13:57:46 +0300 | [diff] [blame] | 2882 | (float) surf_width; |
Kristian Høgsberg | 240dfeb | 2012-07-12 12:32:31 -0400 | [diff] [blame] | 2883 | else |
Scott Moreau | 1bad5db | 2012-08-18 01:04:05 -0600 | [diff] [blame] | 2884 | scale = (float) output->height / |
Giulio Camuffo | b836664 | 2013-04-25 13:57:46 +0300 | [diff] [blame] | 2885 | (float) surf_height; |
Kristian Høgsberg | 240dfeb | 2012-07-12 12:32:31 -0400 | [diff] [blame] | 2886 | |
Alex Wu | 4539b08 | 2012-03-01 12:57:46 +0800 | [diff] [blame] | 2887 | weston_matrix_scale(matrix, scale, scale, 1); |
| 2888 | wl_list_remove(&shsurf->fullscreen.transform.link); |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 2889 | wl_list_insert(&shsurf->view->geometry.transformation_list, |
Alex Wu | 4539b08 | 2012-03-01 12:57:46 +0800 | [diff] [blame] | 2890 | &shsurf->fullscreen.transform.link); |
Giulio Camuffo | b836664 | 2013-04-25 13:57:46 +0300 | [diff] [blame] | 2891 | x = output->x + (output->width - surf_width * scale) / 2 - surf_x; |
| 2892 | y = output->y + (output->height - surf_height * scale) / 2 - surf_y; |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 2893 | weston_view_set_position(shsurf->view, x, y); |
Kristian Høgsberg | 240dfeb | 2012-07-12 12:32:31 -0400 | [diff] [blame] | 2894 | |
Alex Wu | 4539b08 | 2012-03-01 12:57:46 +0800 | [diff] [blame] | 2895 | break; |
| 2896 | case WL_SHELL_SURFACE_FULLSCREEN_METHOD_DRIVER: |
Alex Wu | bd3354b | 2012-04-17 17:20:49 +0800 | [diff] [blame] | 2897 | if (shell_surface_is_top_fullscreen(shsurf)) { |
Quentin Glidic | c0d79ce | 2013-01-29 14:16:13 +0100 | [diff] [blame] | 2898 | struct weston_mode mode = {0, |
Pekka Paalanen | 952b6c8 | 2014-03-14 14:38:15 +0200 | [diff] [blame] | 2899 | surf_width * surface->buffer_viewport.buffer.scale, |
| 2900 | surf_height * surface->buffer_viewport.buffer.scale, |
Alex Wu | bd3354b | 2012-04-17 17:20:49 +0800 | [diff] [blame] | 2901 | shsurf->fullscreen.framerate}; |
| 2902 | |
Derek Foreman | 6ae7bc9 | 2014-11-04 10:47:33 -0600 | [diff] [blame] | 2903 | if (weston_output_mode_switch_to_temporary(output, &mode, |
| 2904 | surface->buffer_viewport.buffer.scale) == 0) { |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 2905 | weston_view_set_position(shsurf->view, |
| 2906 | output->x - surf_x, |
| 2907 | output->y - surf_y); |
Jason Ekstrand | 918f2dd | 2013-12-02 21:01:53 -0600 | [diff] [blame] | 2908 | shsurf->fullscreen.black_view->surface->width = output->width; |
| 2909 | shsurf->fullscreen.black_view->surface->height = output->height; |
| 2910 | weston_view_set_position(shsurf->fullscreen.black_view, |
| 2911 | output->x - surf_x, |
| 2912 | output->y - surf_y); |
Alex Wu | bd3354b | 2012-04-17 17:20:49 +0800 | [diff] [blame] | 2913 | break; |
Alexander Larsson | d622ed3 | 2013-05-28 16:23:40 +0200 | [diff] [blame] | 2914 | } else { |
Mario Kleiner | 492c12f | 2015-06-21 21:25:12 +0200 | [diff] [blame] | 2915 | weston_log("shell: Can't switch to temporary mode.\n"); |
Alexander Larsson | f82b6ca | 2013-05-28 16:23:39 +0200 | [diff] [blame] | 2916 | restore_output_mode(output); |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 2917 | center_on_output(shsurf->view, output); |
Alexander Larsson | d622ed3 | 2013-05-28 16:23:40 +0200 | [diff] [blame] | 2918 | } |
Alex Wu | bd3354b | 2012-04-17 17:20:49 +0800 | [diff] [blame] | 2919 | } |
Alex Wu | 4539b08 | 2012-03-01 12:57:46 +0800 | [diff] [blame] | 2920 | break; |
| 2921 | case WL_SHELL_SURFACE_FULLSCREEN_METHOD_FILL: |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 2922 | center_on_output(shsurf->view, output); |
Alex Wu | 4539b08 | 2012-03-01 12:57:46 +0800 | [diff] [blame] | 2923 | break; |
| 2924 | default: |
| 2925 | break; |
| 2926 | } |
| 2927 | } |
| 2928 | |
Alex Wu | 4539b08 | 2012-03-01 12:57:46 +0800 | [diff] [blame] | 2929 | static void |
| 2930 | shell_map_fullscreen(struct shell_surface *shsurf) |
| 2931 | { |
Alex Wu | bd3354b | 2012-04-17 17:20:49 +0800 | [diff] [blame] | 2932 | shell_configure_fullscreen(shsurf); |
Alex Wu | 4539b08 | 2012-03-01 12:57:46 +0800 | [diff] [blame] | 2933 | } |
| 2934 | |
Kristian Høgsberg | 7a5c979 | 2011-06-18 06:12:54 -0400 | [diff] [blame] | 2935 | static void |
Tiago Vignatti | fb2adba | 2013-06-12 15:43:21 -0300 | [diff] [blame] | 2936 | set_xwayland(struct shell_surface *shsurf, int x, int y, uint32_t flags) |
| 2937 | { |
| 2938 | /* XXX: using the same fields for transient type */ |
Rafael Antognolli | 03b1659 | 2013-12-03 15:35:42 -0200 | [diff] [blame] | 2939 | surface_clear_next_states(shsurf); |
Tiago Vignatti | fb2adba | 2013-06-12 15:43:21 -0300 | [diff] [blame] | 2940 | shsurf->transient.x = x; |
| 2941 | shsurf->transient.y = y; |
| 2942 | shsurf->transient.flags = flags; |
Philip Withnall | dc4332f | 2013-11-25 18:01:38 +0000 | [diff] [blame] | 2943 | |
| 2944 | shell_surface_set_parent(shsurf, NULL); |
| 2945 | |
Pekka Paalanen | b502654 | 2014-11-12 15:09:24 +0200 | [diff] [blame] | 2946 | set_type(shsurf, SHELL_SURFACE_XWAYLAND); |
Kristian Høgsberg | 8bc525c | 2014-01-01 22:34:49 -0800 | [diff] [blame] | 2947 | shsurf->state_changed = true; |
Tiago Vignatti | fb2adba | 2013-06-12 15:43:21 -0300 | [diff] [blame] | 2948 | } |
| 2949 | |
Kristian Høgsberg | 4779241 | 2014-05-04 13:47:06 -0700 | [diff] [blame] | 2950 | static void |
| 2951 | shell_interface_set_fullscreen(struct shell_surface *shsurf, |
| 2952 | uint32_t method, |
| 2953 | uint32_t framerate, |
| 2954 | struct weston_output *output) |
| 2955 | { |
| 2956 | surface_clear_next_states(shsurf); |
Kristian Høgsberg | 4779241 | 2014-05-04 13:47:06 -0700 | [diff] [blame] | 2957 | shsurf->next_state.fullscreen = true; |
| 2958 | shsurf->state_changed = true; |
Marek Chalupa | e9fe467 | 2014-10-29 13:44:44 +0100 | [diff] [blame] | 2959 | |
| 2960 | set_fullscreen(shsurf, method, framerate, output); |
Kristian Høgsberg | 4779241 | 2014-05-04 13:47:06 -0700 | [diff] [blame] | 2961 | } |
| 2962 | |
Giulio Camuffo | 6b4b241 | 2015-01-29 19:06:49 +0200 | [diff] [blame] | 2963 | static struct weston_output * |
| 2964 | get_focused_output(struct weston_compositor *compositor) |
| 2965 | { |
| 2966 | struct weston_seat *seat; |
| 2967 | struct weston_output *output = NULL; |
| 2968 | |
| 2969 | wl_list_for_each(seat, &compositor->seat_list, link) { |
Derek Foreman | 1281a36 | 2015-07-31 16:55:32 -0500 | [diff] [blame] | 2970 | struct weston_touch *touch = weston_seat_get_touch(seat); |
| 2971 | struct weston_pointer *pointer = weston_seat_get_pointer(seat); |
| 2972 | struct weston_keyboard *keyboard = |
| 2973 | weston_seat_get_keyboard(seat); |
| 2974 | |
Giulio Camuffo | 6b4b241 | 2015-01-29 19:06:49 +0200 | [diff] [blame] | 2975 | /* Priority has touch focus, then pointer and |
| 2976 | * then keyboard focus. We should probably have |
| 2977 | * three for loops and check frist for touch, |
| 2978 | * then for pointer, etc. but unless somebody has some |
| 2979 | * objections, I think this is sufficient. */ |
Derek Foreman | 1281a36 | 2015-07-31 16:55:32 -0500 | [diff] [blame] | 2980 | if (touch && touch->focus) |
| 2981 | output = touch->focus->output; |
| 2982 | else if (pointer && pointer->focus) |
| 2983 | output = pointer->focus->output; |
| 2984 | else if (keyboard && keyboard->focus) |
| 2985 | output = keyboard->focus->output; |
Giulio Camuffo | 6b4b241 | 2015-01-29 19:06:49 +0200 | [diff] [blame] | 2986 | |
| 2987 | if (output) |
| 2988 | break; |
| 2989 | } |
| 2990 | |
| 2991 | return output; |
| 2992 | } |
| 2993 | |
| 2994 | static void |
| 2995 | shell_interface_set_maximized(struct shell_surface *shsurf) |
| 2996 | { |
| 2997 | struct weston_output *output; |
| 2998 | |
| 2999 | surface_clear_next_states(shsurf); |
| 3000 | shsurf->next_state.maximized = true; |
| 3001 | shsurf->state_changed = true; |
| 3002 | shsurf->type = SHELL_SURFACE_TOPLEVEL; |
| 3003 | |
| 3004 | if (!weston_surface_is_mapped(shsurf->surface)) |
| 3005 | output = get_focused_output(shsurf->surface->compositor); |
| 3006 | else |
| 3007 | output = shsurf->surface->output; |
| 3008 | |
| 3009 | shell_surface_set_output(shsurf, output); |
| 3010 | send_configure_for_surface(shsurf); |
| 3011 | } |
| 3012 | |
Kristian Høgsberg | ae356ae | 2014-04-29 16:03:54 -0700 | [diff] [blame] | 3013 | static int |
Derek Foreman | e4d6c83 | 2015-08-05 14:48:11 -0500 | [diff] [blame] | 3014 | shell_interface_move(struct shell_surface *shsurf, struct weston_pointer *pointer) |
Kristian Høgsberg | ae356ae | 2014-04-29 16:03:54 -0700 | [diff] [blame] | 3015 | { |
Derek Foreman | e4d6c83 | 2015-08-05 14:48:11 -0500 | [diff] [blame] | 3016 | return surface_move(shsurf, pointer, true); |
Kristian Høgsberg | ae356ae | 2014-04-29 16:03:54 -0700 | [diff] [blame] | 3017 | } |
| 3018 | |
Derek Foreman | 8fbebbd | 2015-07-15 13:00:40 -0500 | [diff] [blame] | 3019 | static int |
| 3020 | shell_interface_resize(struct shell_surface *shsurf, |
Derek Foreman | e4d6c83 | 2015-08-05 14:48:11 -0500 | [diff] [blame] | 3021 | struct weston_pointer *pointer, |
Derek Foreman | 8fbebbd | 2015-07-15 13:00:40 -0500 | [diff] [blame] | 3022 | uint32_t edges) |
| 3023 | { |
Derek Foreman | e4d6c83 | 2015-08-05 14:48:11 -0500 | [diff] [blame] | 3024 | return surface_resize(shsurf, pointer, edges); |
Derek Foreman | 8fbebbd | 2015-07-15 13:00:40 -0500 | [diff] [blame] | 3025 | } |
| 3026 | |
Kristian Høgsberg | 02bbabb | 2013-05-06 22:15:05 -0400 | [diff] [blame] | 3027 | static const struct weston_pointer_grab_interface popup_grab_interface; |
Giulio Camuffo | 5085a75 | 2013-03-25 21:42:45 +0100 | [diff] [blame] | 3028 | |
| 3029 | static void |
| 3030 | destroy_shell_seat(struct wl_listener *listener, void *data) |
| 3031 | { |
| 3032 | struct shell_seat *shseat = |
| 3033 | container_of(listener, |
| 3034 | struct shell_seat, seat_destroy_listener); |
Jonas Ådahl | c2b1011 | 2015-02-13 14:01:53 +0800 | [diff] [blame] | 3035 | struct shell_surface *shsurf, *next; |
Giulio Camuffo | 5085a75 | 2013-03-25 21:42:45 +0100 | [diff] [blame] | 3036 | |
| 3037 | if (shseat->popup_grab.grab.interface == &popup_grab_interface) { |
Kristian Høgsberg | 02bbabb | 2013-05-06 22:15:05 -0400 | [diff] [blame] | 3038 | weston_pointer_end_grab(shseat->popup_grab.grab.pointer); |
Giulio Camuffo | 5085a75 | 2013-03-25 21:42:45 +0100 | [diff] [blame] | 3039 | shseat->popup_grab.client = NULL; |
| 3040 | |
Jonas Ådahl | c2b1011 | 2015-02-13 14:01:53 +0800 | [diff] [blame] | 3041 | wl_list_for_each_safe(shsurf, next, |
| 3042 | &shseat->popup_grab.surfaces_list, |
| 3043 | popup.grab_link) { |
Giulio Camuffo | 5085a75 | 2013-03-25 21:42:45 +0100 | [diff] [blame] | 3044 | shsurf->popup.shseat = NULL; |
Jonas Ådahl | c2b1011 | 2015-02-13 14:01:53 +0800 | [diff] [blame] | 3045 | wl_list_init(&shsurf->popup.grab_link); |
Giulio Camuffo | 5085a75 | 2013-03-25 21:42:45 +0100 | [diff] [blame] | 3046 | } |
Giulio Camuffo | 5085a75 | 2013-03-25 21:42:45 +0100 | [diff] [blame] | 3047 | } |
| 3048 | |
| 3049 | wl_list_remove(&shseat->seat_destroy_listener.link); |
| 3050 | free(shseat); |
| 3051 | } |
| 3052 | |
Jason Ekstrand | 024177c | 2014-04-21 19:42:58 -0500 | [diff] [blame] | 3053 | static void |
| 3054 | shell_seat_caps_changed(struct wl_listener *listener, void *data) |
| 3055 | { |
Derek Foreman | 1281a36 | 2015-07-31 16:55:32 -0500 | [diff] [blame] | 3056 | struct weston_keyboard *keyboard; |
| 3057 | struct weston_pointer *pointer; |
Jason Ekstrand | 024177c | 2014-04-21 19:42:58 -0500 | [diff] [blame] | 3058 | struct shell_seat *seat; |
| 3059 | |
| 3060 | seat = container_of(listener, struct shell_seat, caps_changed_listener); |
Derek Foreman | 1281a36 | 2015-07-31 16:55:32 -0500 | [diff] [blame] | 3061 | keyboard = weston_seat_get_keyboard(seat->seat); |
| 3062 | pointer = weston_seat_get_pointer(seat->seat); |
Jason Ekstrand | 024177c | 2014-04-21 19:42:58 -0500 | [diff] [blame] | 3063 | |
Derek Foreman | 1281a36 | 2015-07-31 16:55:32 -0500 | [diff] [blame] | 3064 | if (keyboard && |
Jason Ekstrand | 024177c | 2014-04-21 19:42:58 -0500 | [diff] [blame] | 3065 | wl_list_empty(&seat->keyboard_focus_listener.link)) { |
Derek Foreman | 1281a36 | 2015-07-31 16:55:32 -0500 | [diff] [blame] | 3066 | wl_signal_add(&keyboard->focus_signal, |
Jason Ekstrand | 024177c | 2014-04-21 19:42:58 -0500 | [diff] [blame] | 3067 | &seat->keyboard_focus_listener); |
Derek Foreman | 1281a36 | 2015-07-31 16:55:32 -0500 | [diff] [blame] | 3068 | } else if (!keyboard) { |
Derek Foreman | 60d9731 | 2015-07-15 13:00:45 -0500 | [diff] [blame] | 3069 | wl_list_remove(&seat->keyboard_focus_listener.link); |
Jason Ekstrand | 024177c | 2014-04-21 19:42:58 -0500 | [diff] [blame] | 3070 | wl_list_init(&seat->keyboard_focus_listener.link); |
| 3071 | } |
| 3072 | |
Derek Foreman | 1281a36 | 2015-07-31 16:55:32 -0500 | [diff] [blame] | 3073 | if (pointer && |
Jason Ekstrand | 024177c | 2014-04-21 19:42:58 -0500 | [diff] [blame] | 3074 | wl_list_empty(&seat->pointer_focus_listener.link)) { |
Derek Foreman | 1281a36 | 2015-07-31 16:55:32 -0500 | [diff] [blame] | 3075 | wl_signal_add(&pointer->focus_signal, |
Jason Ekstrand | 024177c | 2014-04-21 19:42:58 -0500 | [diff] [blame] | 3076 | &seat->pointer_focus_listener); |
Derek Foreman | 1281a36 | 2015-07-31 16:55:32 -0500 | [diff] [blame] | 3077 | } else if (!pointer) { |
Derek Foreman | 60d9731 | 2015-07-15 13:00:45 -0500 | [diff] [blame] | 3078 | wl_list_remove(&seat->pointer_focus_listener.link); |
Jason Ekstrand | 024177c | 2014-04-21 19:42:58 -0500 | [diff] [blame] | 3079 | wl_list_init(&seat->pointer_focus_listener.link); |
| 3080 | } |
| 3081 | } |
| 3082 | |
Giulio Camuffo | 5085a75 | 2013-03-25 21:42:45 +0100 | [diff] [blame] | 3083 | static struct shell_seat * |
| 3084 | create_shell_seat(struct weston_seat *seat) |
| 3085 | { |
| 3086 | struct shell_seat *shseat; |
| 3087 | |
| 3088 | shseat = calloc(1, sizeof *shseat); |
| 3089 | if (!shseat) { |
| 3090 | weston_log("no memory to allocate shell seat\n"); |
| 3091 | return NULL; |
| 3092 | } |
| 3093 | |
| 3094 | shseat->seat = seat; |
| 3095 | wl_list_init(&shseat->popup_grab.surfaces_list); |
| 3096 | |
| 3097 | shseat->seat_destroy_listener.notify = destroy_shell_seat; |
| 3098 | wl_signal_add(&seat->destroy_signal, |
| 3099 | &shseat->seat_destroy_listener); |
| 3100 | |
Jason Ekstrand | 024177c | 2014-04-21 19:42:58 -0500 | [diff] [blame] | 3101 | shseat->keyboard_focus_listener.notify = handle_keyboard_focus; |
| 3102 | wl_list_init(&shseat->keyboard_focus_listener.link); |
| 3103 | |
| 3104 | shseat->pointer_focus_listener.notify = handle_pointer_focus; |
| 3105 | wl_list_init(&shseat->pointer_focus_listener.link); |
| 3106 | |
| 3107 | shseat->caps_changed_listener.notify = shell_seat_caps_changed; |
| 3108 | wl_signal_add(&seat->updated_caps_signal, |
| 3109 | &shseat->caps_changed_listener); |
| 3110 | shell_seat_caps_changed(&shseat->caps_changed_listener, NULL); |
| 3111 | |
Giulio Camuffo | 5085a75 | 2013-03-25 21:42:45 +0100 | [diff] [blame] | 3112 | return shseat; |
| 3113 | } |
| 3114 | |
| 3115 | static struct shell_seat * |
| 3116 | get_shell_seat(struct weston_seat *seat) |
| 3117 | { |
| 3118 | struct wl_listener *listener; |
| 3119 | |
| 3120 | listener = wl_signal_get(&seat->destroy_signal, destroy_shell_seat); |
Jason Ekstrand | 024177c | 2014-04-21 19:42:58 -0500 | [diff] [blame] | 3121 | assert(listener != NULL); |
Giulio Camuffo | 5085a75 | 2013-03-25 21:42:45 +0100 | [diff] [blame] | 3122 | |
| 3123 | return container_of(listener, |
| 3124 | struct shell_seat, seat_destroy_listener); |
| 3125 | } |
| 3126 | |
Kristian Høgsberg | b810eb5 | 2013-02-12 20:07:05 -0500 | [diff] [blame] | 3127 | static void |
Kristian Høgsberg | 6848c25 | 2013-05-08 22:02:59 -0400 | [diff] [blame] | 3128 | popup_grab_focus(struct weston_pointer_grab *grab) |
Kristian Høgsberg | b3cca0a | 2012-01-04 22:19:14 -0500 | [diff] [blame] | 3129 | { |
Kristian Høgsberg | 02bbabb | 2013-05-06 22:15:05 -0400 | [diff] [blame] | 3130 | struct weston_pointer *pointer = grab->pointer; |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 3131 | struct weston_view *view; |
Giulio Camuffo | 5085a75 | 2013-03-25 21:42:45 +0100 | [diff] [blame] | 3132 | struct shell_seat *shseat = |
| 3133 | container_of(grab, struct shell_seat, popup_grab.grab); |
| 3134 | struct wl_client *client = shseat->popup_grab.client; |
Kristian Høgsberg | 6848c25 | 2013-05-08 22:02:59 -0400 | [diff] [blame] | 3135 | wl_fixed_t sx, sy; |
| 3136 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 3137 | view = weston_compositor_pick_view(pointer->seat->compositor, |
| 3138 | pointer->x, pointer->y, |
| 3139 | &sx, &sy); |
Kristian Høgsberg | b3cca0a | 2012-01-04 22:19:14 -0500 | [diff] [blame] | 3140 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 3141 | if (view && view->surface->resource && |
| 3142 | wl_resource_get_client(view->surface->resource) == client) { |
| 3143 | weston_pointer_set_focus(pointer, view, sx, sy); |
Kristian Høgsberg | b3cca0a | 2012-01-04 22:19:14 -0500 | [diff] [blame] | 3144 | } else { |
Derek Foreman | f9318d1 | 2015-05-11 15:40:11 -0500 | [diff] [blame] | 3145 | weston_pointer_clear_focus(pointer); |
Kristian Høgsberg | b3cca0a | 2012-01-04 22:19:14 -0500 | [diff] [blame] | 3146 | } |
| 3147 | } |
| 3148 | |
| 3149 | static void |
Giulio Camuffo | 1959ab8 | 2013-11-14 23:42:52 +0100 | [diff] [blame] | 3150 | popup_grab_motion(struct weston_pointer_grab *grab, uint32_t time, |
Jonas Ådahl | d251010 | 2014-10-05 21:39:14 +0200 | [diff] [blame] | 3151 | struct weston_pointer_motion_event *event) |
Kristian Høgsberg | b3cca0a | 2012-01-04 22:19:14 -0500 | [diff] [blame] | 3152 | { |
Kristian Høgsberg | be6403e | 2013-05-08 21:03:21 -0400 | [diff] [blame] | 3153 | struct weston_pointer *pointer = grab->pointer; |
Neil Roberts | 96d790e | 2013-09-19 17:32:00 +0100 | [diff] [blame] | 3154 | struct wl_resource *resource; |
Jonas Ådahl | 2cbf293 | 2015-07-22 12:05:38 +0800 | [diff] [blame] | 3155 | struct wl_list *resource_list; |
Jonas Ådahl | d251010 | 2014-10-05 21:39:14 +0200 | [diff] [blame] | 3156 | wl_fixed_t x, y; |
Kristian Høgsberg | be6403e | 2013-05-08 21:03:21 -0400 | [diff] [blame] | 3157 | wl_fixed_t sx, sy; |
Kristian Høgsberg | b3cca0a | 2012-01-04 22:19:14 -0500 | [diff] [blame] | 3158 | |
Jonas Ådahl | 61917c8 | 2014-08-11 22:44:02 +0200 | [diff] [blame] | 3159 | if (pointer->focus) { |
Jonas Ådahl | d251010 | 2014-10-05 21:39:14 +0200 | [diff] [blame] | 3160 | weston_pointer_motion_to_abs(pointer, event, &x, &y); |
Jonas Ådahl | 61917c8 | 2014-08-11 22:44:02 +0200 | [diff] [blame] | 3161 | weston_view_from_global_fixed(pointer->focus, x, y, |
| 3162 | &pointer->sx, &pointer->sy); |
| 3163 | } |
| 3164 | |
Jonas Ådahl | d251010 | 2014-10-05 21:39:14 +0200 | [diff] [blame] | 3165 | weston_pointer_move(pointer, event); |
Giulio Camuffo | 1959ab8 | 2013-11-14 23:42:52 +0100 | [diff] [blame] | 3166 | |
Jonas Ådahl | 2cbf293 | 2015-07-22 12:05:38 +0800 | [diff] [blame] | 3167 | if (!pointer->focus_client) |
| 3168 | return; |
| 3169 | |
| 3170 | resource_list = &pointer->focus_client->pointer_resources; |
| 3171 | wl_resource_for_each(resource, resource_list) { |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 3172 | weston_view_from_global_fixed(pointer->focus, |
| 3173 | pointer->x, pointer->y, |
| 3174 | &sx, &sy); |
Neil Roberts | 96d790e | 2013-09-19 17:32:00 +0100 | [diff] [blame] | 3175 | wl_pointer_send_motion(resource, time, sx, sy); |
Kristian Høgsberg | be6403e | 2013-05-08 21:03:21 -0400 | [diff] [blame] | 3176 | } |
Kristian Høgsberg | b3cca0a | 2012-01-04 22:19:14 -0500 | [diff] [blame] | 3177 | } |
| 3178 | |
| 3179 | static void |
Kristian Høgsberg | 02bbabb | 2013-05-06 22:15:05 -0400 | [diff] [blame] | 3180 | popup_grab_button(struct weston_pointer_grab *grab, |
Daniel Stone | 4dbadb1 | 2012-05-30 16:31:51 +0100 | [diff] [blame] | 3181 | uint32_t time, uint32_t button, uint32_t state_w) |
Kristian Høgsberg | b3cca0a | 2012-01-04 22:19:14 -0500 | [diff] [blame] | 3182 | { |
| 3183 | struct wl_resource *resource; |
Giulio Camuffo | 5085a75 | 2013-03-25 21:42:45 +0100 | [diff] [blame] | 3184 | struct shell_seat *shseat = |
| 3185 | container_of(grab, struct shell_seat, popup_grab.grab); |
Rob Bradford | 880ebc7 | 2013-07-22 17:31:38 +0100 | [diff] [blame] | 3186 | struct wl_display *display = shseat->seat->compositor->wl_display; |
Daniel Stone | 4dbadb1 | 2012-05-30 16:31:51 +0100 | [diff] [blame] | 3187 | enum wl_pointer_button_state state = state_w; |
Kristian Høgsberg | eae5de7 | 2012-04-11 22:42:15 -0400 | [diff] [blame] | 3188 | uint32_t serial; |
Jonas Ådahl | 2cbf293 | 2015-07-22 12:05:38 +0800 | [diff] [blame] | 3189 | struct wl_list *resource_list = NULL; |
Kristian Høgsberg | b3cca0a | 2012-01-04 22:19:14 -0500 | [diff] [blame] | 3190 | |
Jonas Ådahl | 2cbf293 | 2015-07-22 12:05:38 +0800 | [diff] [blame] | 3191 | if (grab->pointer->focus_client) |
| 3192 | resource_list = &grab->pointer->focus_client->pointer_resources; |
| 3193 | if (resource_list && !wl_list_empty(resource_list)) { |
Kristian Høgsberg | eae5de7 | 2012-04-11 22:42:15 -0400 | [diff] [blame] | 3194 | serial = wl_display_get_serial(display); |
Neil Roberts | 96d790e | 2013-09-19 17:32:00 +0100 | [diff] [blame] | 3195 | wl_resource_for_each(resource, resource_list) { |
| 3196 | wl_pointer_send_button(resource, serial, |
| 3197 | time, button, state); |
| 3198 | } |
Daniel Stone | 4dbadb1 | 2012-05-30 16:31:51 +0100 | [diff] [blame] | 3199 | } else if (state == WL_POINTER_BUTTON_STATE_RELEASED && |
Giulio Camuffo | 5085a75 | 2013-03-25 21:42:45 +0100 | [diff] [blame] | 3200 | (shseat->popup_grab.initial_up || |
Derek Foreman | f7b2f8b | 2015-07-15 13:00:41 -0500 | [diff] [blame] | 3201 | time - grab->pointer->grab_time > 500)) { |
Kristian Høgsberg | 57e0907 | 2012-10-30 14:07:27 -0400 | [diff] [blame] | 3202 | popup_grab_end(grab->pointer); |
Kristian Høgsberg | b3cca0a | 2012-01-04 22:19:14 -0500 | [diff] [blame] | 3203 | } |
| 3204 | |
Daniel Stone | 4dbadb1 | 2012-05-30 16:31:51 +0100 | [diff] [blame] | 3205 | if (state == WL_POINTER_BUTTON_STATE_RELEASED) |
Giulio Camuffo | 5085a75 | 2013-03-25 21:42:45 +0100 | [diff] [blame] | 3206 | shseat->popup_grab.initial_up = 1; |
Kristian Høgsberg | b3cca0a | 2012-01-04 22:19:14 -0500 | [diff] [blame] | 3207 | } |
| 3208 | |
Jonas Ådahl | 1ea343e | 2013-10-25 23:18:05 +0200 | [diff] [blame] | 3209 | static void |
Jonas Ådahl | 0336ca0 | 2014-10-04 16:28:29 +0200 | [diff] [blame] | 3210 | popup_grab_axis(struct weston_pointer_grab *grab, |
| 3211 | uint32_t time, uint32_t axis, wl_fixed_t value) |
| 3212 | { |
Peter Hutterer | 1118952 | 2015-11-16 12:35:57 +1000 | [diff] [blame] | 3213 | weston_pointer_send_axis(grab->pointer, time, axis, value); |
Jonas Ådahl | 0336ca0 | 2014-10-04 16:28:29 +0200 | [diff] [blame] | 3214 | } |
| 3215 | |
| 3216 | static void |
Jonas Ådahl | 1ea343e | 2013-10-25 23:18:05 +0200 | [diff] [blame] | 3217 | popup_grab_cancel(struct weston_pointer_grab *grab) |
| 3218 | { |
| 3219 | popup_grab_end(grab->pointer); |
| 3220 | } |
| 3221 | |
Kristian Høgsberg | 02bbabb | 2013-05-06 22:15:05 -0400 | [diff] [blame] | 3222 | static const struct weston_pointer_grab_interface popup_grab_interface = { |
Kristian Høgsberg | b3cca0a | 2012-01-04 22:19:14 -0500 | [diff] [blame] | 3223 | popup_grab_focus, |
| 3224 | popup_grab_motion, |
| 3225 | popup_grab_button, |
Jonas Ådahl | 0336ca0 | 2014-10-04 16:28:29 +0200 | [diff] [blame] | 3226 | popup_grab_axis, |
Jonas Ådahl | 1ea343e | 2013-10-25 23:18:05 +0200 | [diff] [blame] | 3227 | popup_grab_cancel, |
Kristian Høgsberg | b3cca0a | 2012-01-04 22:19:14 -0500 | [diff] [blame] | 3228 | }; |
| 3229 | |
| 3230 | static void |
Jonny Lamb | 76cf1fe | 2014-08-20 11:27:10 +0200 | [diff] [blame] | 3231 | touch_popup_grab_down(struct weston_touch_grab *grab, uint32_t time, |
Giulio Camuffo | 61ed7b6 | 2015-07-08 11:55:28 +0300 | [diff] [blame] | 3232 | int touch_id, wl_fixed_t x, wl_fixed_t y) |
Jonny Lamb | 76cf1fe | 2014-08-20 11:27:10 +0200 | [diff] [blame] | 3233 | { |
| 3234 | struct wl_resource *resource; |
| 3235 | struct shell_seat *shseat = |
| 3236 | container_of(grab, struct shell_seat, popup_grab.touch_grab); |
| 3237 | struct wl_display *display = shseat->seat->compositor->wl_display; |
| 3238 | uint32_t serial; |
| 3239 | struct wl_list *resource_list; |
Giulio Camuffo | 61ed7b6 | 2015-07-08 11:55:28 +0300 | [diff] [blame] | 3240 | wl_fixed_t sx, sy; |
| 3241 | |
| 3242 | weston_view_from_global_fixed(grab->touch->focus, x, y, &sx, &sy); |
Jonny Lamb | 76cf1fe | 2014-08-20 11:27:10 +0200 | [diff] [blame] | 3243 | |
| 3244 | resource_list = &grab->touch->focus_resource_list; |
| 3245 | if (!wl_list_empty(resource_list)) { |
| 3246 | serial = wl_display_get_serial(display); |
| 3247 | wl_resource_for_each(resource, resource_list) { |
| 3248 | wl_touch_send_down(resource, serial, time, |
| 3249 | grab->touch->focus->surface->resource, |
| 3250 | touch_id, sx, sy); |
| 3251 | } |
| 3252 | } |
| 3253 | } |
| 3254 | |
| 3255 | static void |
| 3256 | touch_popup_grab_up(struct weston_touch_grab *grab, uint32_t time, int touch_id) |
| 3257 | { |
| 3258 | struct wl_resource *resource; |
| 3259 | struct shell_seat *shseat = |
| 3260 | container_of(grab, struct shell_seat, popup_grab.touch_grab); |
| 3261 | struct wl_display *display = shseat->seat->compositor->wl_display; |
| 3262 | uint32_t serial; |
| 3263 | struct wl_list *resource_list; |
| 3264 | |
| 3265 | resource_list = &grab->touch->focus_resource_list; |
| 3266 | if (!wl_list_empty(resource_list)) { |
| 3267 | serial = wl_display_get_serial(display); |
| 3268 | wl_resource_for_each(resource, resource_list) { |
| 3269 | wl_touch_send_up(resource, serial, time, touch_id); |
| 3270 | } |
| 3271 | } |
| 3272 | } |
| 3273 | |
| 3274 | static void |
| 3275 | touch_popup_grab_motion(struct weston_touch_grab *grab, uint32_t time, |
Giulio Camuffo | 61ed7b6 | 2015-07-08 11:55:28 +0300 | [diff] [blame] | 3276 | int touch_id, wl_fixed_t x, wl_fixed_t y) |
Jonny Lamb | 76cf1fe | 2014-08-20 11:27:10 +0200 | [diff] [blame] | 3277 | { |
| 3278 | struct wl_resource *resource; |
| 3279 | struct wl_list *resource_list; |
Giulio Camuffo | 61ed7b6 | 2015-07-08 11:55:28 +0300 | [diff] [blame] | 3280 | wl_fixed_t sx, sy; |
| 3281 | |
| 3282 | weston_view_from_global_fixed(grab->touch->focus, x, y, &sx, &sy); |
Jonny Lamb | 76cf1fe | 2014-08-20 11:27:10 +0200 | [diff] [blame] | 3283 | |
| 3284 | resource_list = &grab->touch->focus_resource_list; |
| 3285 | if (!wl_list_empty(resource_list)) { |
| 3286 | wl_resource_for_each(resource, resource_list) { |
| 3287 | wl_touch_send_motion(resource, time, touch_id, sx, sy); |
| 3288 | } |
| 3289 | } |
| 3290 | } |
| 3291 | |
| 3292 | static void |
| 3293 | touch_popup_grab_frame(struct weston_touch_grab *grab) |
| 3294 | { |
| 3295 | } |
| 3296 | |
| 3297 | static void |
| 3298 | touch_popup_grab_cancel(struct weston_touch_grab *grab) |
| 3299 | { |
| 3300 | touch_popup_grab_end(grab->touch); |
| 3301 | } |
| 3302 | |
| 3303 | static const struct weston_touch_grab_interface touch_popup_grab_interface = { |
| 3304 | touch_popup_grab_down, |
| 3305 | touch_popup_grab_up, |
| 3306 | touch_popup_grab_motion, |
| 3307 | touch_popup_grab_frame, |
| 3308 | touch_popup_grab_cancel, |
| 3309 | }; |
| 3310 | |
| 3311 | static void |
Rafael Antognolli | e2a3455 | 2013-12-03 15:35:45 -0200 | [diff] [blame] | 3312 | shell_surface_send_popup_done(struct shell_surface *shsurf) |
| 3313 | { |
| 3314 | if (shell_surface_is_wl_shell_surface(shsurf)) |
| 3315 | wl_shell_surface_send_popup_done(shsurf->resource); |
| 3316 | else if (shell_surface_is_xdg_popup(shsurf)) |
Jasper St. Pierre | ecf2a0f | 2015-02-13 14:01:56 +0800 | [diff] [blame] | 3317 | xdg_popup_send_popup_done(shsurf->resource); |
Rafael Antognolli | e2a3455 | 2013-12-03 15:35:45 -0200 | [diff] [blame] | 3318 | } |
| 3319 | |
| 3320 | static void |
Kristian Høgsberg | 02bbabb | 2013-05-06 22:15:05 -0400 | [diff] [blame] | 3321 | popup_grab_end(struct weston_pointer *pointer) |
Kristian Høgsberg | 57e0907 | 2012-10-30 14:07:27 -0400 | [diff] [blame] | 3322 | { |
Kristian Høgsberg | 02bbabb | 2013-05-06 22:15:05 -0400 | [diff] [blame] | 3323 | struct weston_pointer_grab *grab = pointer->grab; |
Giulio Camuffo | 5085a75 | 2013-03-25 21:42:45 +0100 | [diff] [blame] | 3324 | struct shell_seat *shseat = |
| 3325 | container_of(grab, struct shell_seat, popup_grab.grab); |
| 3326 | struct shell_surface *shsurf; |
Jonas Ådahl | c2b1011 | 2015-02-13 14:01:53 +0800 | [diff] [blame] | 3327 | struct shell_surface *next; |
Kristian Høgsberg | 57e0907 | 2012-10-30 14:07:27 -0400 | [diff] [blame] | 3328 | |
| 3329 | if (pointer->grab->interface == &popup_grab_interface) { |
Kristian Høgsberg | 02bbabb | 2013-05-06 22:15:05 -0400 | [diff] [blame] | 3330 | weston_pointer_end_grab(grab->pointer); |
Giulio Camuffo | 5085a75 | 2013-03-25 21:42:45 +0100 | [diff] [blame] | 3331 | shseat->popup_grab.client = NULL; |
Philipp Brüschweiler | 63e7be6 | 2013-04-15 21:09:54 +0200 | [diff] [blame] | 3332 | shseat->popup_grab.grab.interface = NULL; |
| 3333 | assert(!wl_list_empty(&shseat->popup_grab.surfaces_list)); |
Giulio Camuffo | 5085a75 | 2013-03-25 21:42:45 +0100 | [diff] [blame] | 3334 | /* Send the popup_done event to all the popups open */ |
Jonas Ådahl | c2b1011 | 2015-02-13 14:01:53 +0800 | [diff] [blame] | 3335 | wl_list_for_each_safe(shsurf, next, |
| 3336 | &shseat->popup_grab.surfaces_list, |
| 3337 | popup.grab_link) { |
Rafael Antognolli | e2a3455 | 2013-12-03 15:35:45 -0200 | [diff] [blame] | 3338 | shell_surface_send_popup_done(shsurf); |
Giulio Camuffo | 5085a75 | 2013-03-25 21:42:45 +0100 | [diff] [blame] | 3339 | shsurf->popup.shseat = NULL; |
Jonas Ådahl | c2b1011 | 2015-02-13 14:01:53 +0800 | [diff] [blame] | 3340 | wl_list_init(&shsurf->popup.grab_link); |
Giulio Camuffo | 5085a75 | 2013-03-25 21:42:45 +0100 | [diff] [blame] | 3341 | } |
Giulio Camuffo | 5085a75 | 2013-03-25 21:42:45 +0100 | [diff] [blame] | 3342 | wl_list_init(&shseat->popup_grab.surfaces_list); |
| 3343 | } |
| 3344 | } |
| 3345 | |
| 3346 | static void |
Jonny Lamb | 76cf1fe | 2014-08-20 11:27:10 +0200 | [diff] [blame] | 3347 | touch_popup_grab_end(struct weston_touch *touch) |
| 3348 | { |
| 3349 | struct weston_touch_grab *grab = touch->grab; |
| 3350 | struct shell_seat *shseat = |
| 3351 | container_of(grab, struct shell_seat, popup_grab.touch_grab); |
| 3352 | struct shell_surface *shsurf; |
Jonas Ådahl | c2b1011 | 2015-02-13 14:01:53 +0800 | [diff] [blame] | 3353 | struct shell_surface *next; |
Jonny Lamb | 76cf1fe | 2014-08-20 11:27:10 +0200 | [diff] [blame] | 3354 | |
| 3355 | if (touch->grab->interface == &touch_popup_grab_interface) { |
| 3356 | weston_touch_end_grab(grab->touch); |
| 3357 | shseat->popup_grab.client = NULL; |
| 3358 | shseat->popup_grab.touch_grab.interface = NULL; |
| 3359 | assert(!wl_list_empty(&shseat->popup_grab.surfaces_list)); |
| 3360 | /* Send the popup_done event to all the popups open */ |
Jonas Ådahl | c2b1011 | 2015-02-13 14:01:53 +0800 | [diff] [blame] | 3361 | wl_list_for_each_safe(shsurf, next, |
| 3362 | &shseat->popup_grab.surfaces_list, |
| 3363 | popup.grab_link) { |
Jonny Lamb | 76cf1fe | 2014-08-20 11:27:10 +0200 | [diff] [blame] | 3364 | shell_surface_send_popup_done(shsurf); |
| 3365 | shsurf->popup.shseat = NULL; |
Jonas Ådahl | c2b1011 | 2015-02-13 14:01:53 +0800 | [diff] [blame] | 3366 | wl_list_init(&shsurf->popup.grab_link); |
Jonny Lamb | 76cf1fe | 2014-08-20 11:27:10 +0200 | [diff] [blame] | 3367 | } |
Jonny Lamb | 76cf1fe | 2014-08-20 11:27:10 +0200 | [diff] [blame] | 3368 | wl_list_init(&shseat->popup_grab.surfaces_list); |
| 3369 | } |
| 3370 | } |
| 3371 | |
Jasper St. Pierre | da6ecd0 | 2015-02-27 18:35:45 +0800 | [diff] [blame] | 3372 | static struct shell_surface * |
| 3373 | get_top_popup(struct shell_seat *shseat) |
| 3374 | { |
| 3375 | struct shell_surface *shsurf; |
| 3376 | |
| 3377 | if (wl_list_empty(&shseat->popup_grab.surfaces_list)) { |
| 3378 | return NULL; |
| 3379 | } else { |
| 3380 | shsurf = container_of(shseat->popup_grab.surfaces_list.next, |
| 3381 | struct shell_surface, |
| 3382 | popup.grab_link); |
| 3383 | return shsurf; |
| 3384 | } |
| 3385 | } |
| 3386 | |
| 3387 | static int |
Jonas Ådahl | 01193ae | 2015-02-13 14:01:54 +0800 | [diff] [blame] | 3388 | add_popup_grab(struct shell_surface *shsurf, |
| 3389 | struct shell_seat *shseat, |
| 3390 | int32_t type) |
Giulio Camuffo | 5085a75 | 2013-03-25 21:42:45 +0100 | [diff] [blame] | 3391 | { |
Kristian Høgsberg | e314875 | 2013-05-06 23:19:49 -0400 | [diff] [blame] | 3392 | struct weston_seat *seat = shseat->seat; |
Jasper St. Pierre | da6ecd0 | 2015-02-27 18:35:45 +0800 | [diff] [blame] | 3393 | struct shell_surface *parent, *top_surface; |
Derek Foreman | 1281a36 | 2015-07-31 16:55:32 -0500 | [diff] [blame] | 3394 | struct weston_pointer *pointer = weston_seat_get_pointer(seat); |
| 3395 | struct weston_touch *touch = weston_seat_get_touch(seat); |
Jasper St. Pierre | da6ecd0 | 2015-02-27 18:35:45 +0800 | [diff] [blame] | 3396 | |
| 3397 | parent = get_shell_surface(shsurf->parent); |
| 3398 | top_surface = get_top_popup(shseat); |
| 3399 | if (shell_surface_is_xdg_popup(shsurf) && |
Dima Ryazanov | 497f25d | 2015-04-08 11:51:57 -0700 | [diff] [blame] | 3400 | (!parent || |
| 3401 | (top_surface == NULL && !shell_surface_is_xdg_surface(parent)) || |
Jasper St. Pierre | da6ecd0 | 2015-02-27 18:35:45 +0800 | [diff] [blame] | 3402 | (top_surface != NULL && parent != top_surface))) { |
Jonas Ådahl | ee45a55 | 2015-03-18 16:37:47 +0800 | [diff] [blame] | 3403 | wl_resource_post_error(shsurf->owner_resource, |
| 3404 | XDG_SHELL_ERROR_NOT_THE_TOPMOST_POPUP, |
Jasper St. Pierre | da6ecd0 | 2015-02-27 18:35:45 +0800 | [diff] [blame] | 3405 | "xdg_popup was not created on the " |
| 3406 | "topmost popup"); |
| 3407 | return -1; |
| 3408 | } |
Giulio Camuffo | 5085a75 | 2013-03-25 21:42:45 +0100 | [diff] [blame] | 3409 | |
| 3410 | if (wl_list_empty(&shseat->popup_grab.surfaces_list)) { |
Jonny Lamb | 76cf1fe | 2014-08-20 11:27:10 +0200 | [diff] [blame] | 3411 | shseat->popup_grab.type = type; |
Jonas Ådahl | 01193ae | 2015-02-13 14:01:54 +0800 | [diff] [blame] | 3412 | shseat->popup_grab.client = |
| 3413 | wl_resource_get_client(shsurf->resource); |
Jonny Lamb | 76cf1fe | 2014-08-20 11:27:10 +0200 | [diff] [blame] | 3414 | |
| 3415 | if (type == POINTER) { |
Jonas Ådahl | 01193ae | 2015-02-13 14:01:54 +0800 | [diff] [blame] | 3416 | shseat->popup_grab.grab.interface = |
| 3417 | &popup_grab_interface; |
| 3418 | |
| 3419 | /* We must make sure here that this popup was opened |
| 3420 | * after a mouse press, and not just by moving around |
| 3421 | * with other popups already open. */ |
Derek Foreman | 1281a36 | 2015-07-31 16:55:32 -0500 | [diff] [blame] | 3422 | if (pointer->button_count > 0) |
Jonny Lamb | 76cf1fe | 2014-08-20 11:27:10 +0200 | [diff] [blame] | 3423 | shseat->popup_grab.initial_up = 0; |
| 3424 | } else if (type == TOUCH) { |
Jonas Ådahl | 01193ae | 2015-02-13 14:01:54 +0800 | [diff] [blame] | 3425 | shseat->popup_grab.touch_grab.interface = |
| 3426 | &touch_popup_grab_interface; |
Jonny Lamb | 76cf1fe | 2014-08-20 11:27:10 +0200 | [diff] [blame] | 3427 | } |
Giulio Camuffo | 5085a75 | 2013-03-25 21:42:45 +0100 | [diff] [blame] | 3428 | |
Jonas Ådahl | 01193ae | 2015-02-13 14:01:54 +0800 | [diff] [blame] | 3429 | wl_list_insert(&shseat->popup_grab.surfaces_list, |
| 3430 | &shsurf->popup.grab_link); |
Jonny Lamb | 76cf1fe | 2014-08-20 11:27:10 +0200 | [diff] [blame] | 3431 | |
Jonas Ådahl | 01193ae | 2015-02-13 14:01:54 +0800 | [diff] [blame] | 3432 | if (type == POINTER) { |
Derek Foreman | 1281a36 | 2015-07-31 16:55:32 -0500 | [diff] [blame] | 3433 | weston_pointer_start_grab(pointer, |
Jonas Ådahl | 01193ae | 2015-02-13 14:01:54 +0800 | [diff] [blame] | 3434 | &shseat->popup_grab.grab); |
| 3435 | } else if (type == TOUCH) { |
Derek Foreman | 1281a36 | 2015-07-31 16:55:32 -0500 | [diff] [blame] | 3436 | weston_touch_start_grab(touch, |
Jonas Ådahl | 01193ae | 2015-02-13 14:01:54 +0800 | [diff] [blame] | 3437 | &shseat->popup_grab.touch_grab); |
| 3438 | } |
Rob Bradford | dfe3105 | 2013-06-26 19:49:11 +0100 | [diff] [blame] | 3439 | } else { |
Jonas Ådahl | 01193ae | 2015-02-13 14:01:54 +0800 | [diff] [blame] | 3440 | wl_list_insert(&shseat->popup_grab.surfaces_list, |
| 3441 | &shsurf->popup.grab_link); |
Giulio Camuffo | 5085a75 | 2013-03-25 21:42:45 +0100 | [diff] [blame] | 3442 | } |
Jasper St. Pierre | da6ecd0 | 2015-02-27 18:35:45 +0800 | [diff] [blame] | 3443 | |
| 3444 | return 0; |
Giulio Camuffo | 5085a75 | 2013-03-25 21:42:45 +0100 | [diff] [blame] | 3445 | } |
| 3446 | |
| 3447 | static void |
| 3448 | remove_popup_grab(struct shell_surface *shsurf) |
| 3449 | { |
| 3450 | struct shell_seat *shseat = shsurf->popup.shseat; |
| 3451 | |
Jasper St. Pierre | da6ecd0 | 2015-02-27 18:35:45 +0800 | [diff] [blame] | 3452 | if (shell_surface_is_xdg_popup(shsurf) && |
| 3453 | get_top_popup(shseat) != shsurf) { |
Jonas Ådahl | ee45a55 | 2015-03-18 16:37:47 +0800 | [diff] [blame] | 3454 | wl_resource_post_error(shsurf->owner_resource, |
| 3455 | XDG_SHELL_ERROR_NOT_THE_TOPMOST_POPUP, |
Jasper St. Pierre | da6ecd0 | 2015-02-27 18:35:45 +0800 | [diff] [blame] | 3456 | "xdg_popup was destroyed while it was " |
| 3457 | "not the topmost popup."); |
| 3458 | return; |
| 3459 | } |
| 3460 | |
Giulio Camuffo | 5085a75 | 2013-03-25 21:42:45 +0100 | [diff] [blame] | 3461 | wl_list_remove(&shsurf->popup.grab_link); |
| 3462 | wl_list_init(&shsurf->popup.grab_link); |
| 3463 | if (wl_list_empty(&shseat->popup_grab.surfaces_list)) { |
Jonny Lamb | 76cf1fe | 2014-08-20 11:27:10 +0200 | [diff] [blame] | 3464 | if (shseat->popup_grab.type == POINTER) { |
| 3465 | weston_pointer_end_grab(shseat->popup_grab.grab.pointer); |
| 3466 | shseat->popup_grab.grab.interface = NULL; |
| 3467 | } else if (shseat->popup_grab.type == TOUCH) { |
| 3468 | weston_touch_end_grab(shseat->popup_grab.touch_grab.touch); |
| 3469 | shseat->popup_grab.touch_grab.interface = NULL; |
| 3470 | } |
Kristian Høgsberg | 57e0907 | 2012-10-30 14:07:27 -0400 | [diff] [blame] | 3471 | } |
| 3472 | } |
| 3473 | |
Jasper St. Pierre | da6ecd0 | 2015-02-27 18:35:45 +0800 | [diff] [blame] | 3474 | static int |
Kristian Høgsberg | 3730f36 | 2012-04-13 12:40:07 -0400 | [diff] [blame] | 3475 | shell_map_popup(struct shell_surface *shsurf) |
Kristian Høgsberg | b3cca0a | 2012-01-04 22:19:14 -0500 | [diff] [blame] | 3476 | { |
Giulio Camuffo | 5085a75 | 2013-03-25 21:42:45 +0100 | [diff] [blame] | 3477 | struct shell_seat *shseat = shsurf->popup.shseat; |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 3478 | struct weston_view *parent_view = get_default_view(shsurf->parent); |
Derek Foreman | 1281a36 | 2015-07-31 16:55:32 -0500 | [diff] [blame] | 3479 | struct weston_pointer *pointer = weston_seat_get_pointer(shseat->seat); |
| 3480 | struct weston_touch *touch = weston_seat_get_touch(shseat->seat); |
Kristian Høgsberg | b3cca0a | 2012-01-04 22:19:14 -0500 | [diff] [blame] | 3481 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 3482 | shsurf->surface->output = parent_view->output; |
| 3483 | shsurf->view->output = parent_view->output; |
Kristian Høgsberg | b3cca0a | 2012-01-04 22:19:14 -0500 | [diff] [blame] | 3484 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 3485 | weston_view_set_transform_parent(shsurf->view, parent_view); |
| 3486 | weston_view_set_position(shsurf->view, shsurf->popup.x, shsurf->popup.y); |
| 3487 | weston_view_update_transform(shsurf->view); |
Kristian Høgsberg | b3cca0a | 2012-01-04 22:19:14 -0500 | [diff] [blame] | 3488 | |
Derek Foreman | 1281a36 | 2015-07-31 16:55:32 -0500 | [diff] [blame] | 3489 | if (pointer && |
| 3490 | pointer->grab_serial == shsurf->popup.serial) { |
Jasper St. Pierre | da6ecd0 | 2015-02-27 18:35:45 +0800 | [diff] [blame] | 3491 | if (add_popup_grab(shsurf, shseat, POINTER) != 0) |
| 3492 | return -1; |
Derek Foreman | 1281a36 | 2015-07-31 16:55:32 -0500 | [diff] [blame] | 3493 | } else if (touch && |
| 3494 | touch->grab_serial == shsurf->popup.serial) { |
Jasper St. Pierre | da6ecd0 | 2015-02-27 18:35:45 +0800 | [diff] [blame] | 3495 | if (add_popup_grab(shsurf, shseat, TOUCH) != 0) |
| 3496 | return -1; |
Kristian Høgsberg | 3730f36 | 2012-04-13 12:40:07 -0400 | [diff] [blame] | 3497 | } else { |
Rafael Antognolli | e2a3455 | 2013-12-03 15:35:45 -0200 | [diff] [blame] | 3498 | shell_surface_send_popup_done(shsurf); |
Giulio Camuffo | 5085a75 | 2013-03-25 21:42:45 +0100 | [diff] [blame] | 3499 | shseat->popup_grab.client = NULL; |
Kristian Høgsberg | 3730f36 | 2012-04-13 12:40:07 -0400 | [diff] [blame] | 3500 | } |
Jasper St. Pierre | da6ecd0 | 2015-02-27 18:35:45 +0800 | [diff] [blame] | 3501 | |
| 3502 | return 0; |
Kristian Høgsberg | b3cca0a | 2012-01-04 22:19:14 -0500 | [diff] [blame] | 3503 | } |
| 3504 | |
Pekka Paalanen | 9d1613e | 2011-11-25 12:09:16 +0200 | [diff] [blame] | 3505 | static const struct wl_shell_surface_interface shell_surface_implementation = { |
Scott Moreau | ff1db4a | 2012-04-17 19:06:18 -0600 | [diff] [blame] | 3506 | shell_surface_pong, |
Pekka Paalanen | 9d1613e | 2011-11-25 12:09:16 +0200 | [diff] [blame] | 3507 | shell_surface_move, |
| 3508 | shell_surface_resize, |
| 3509 | shell_surface_set_toplevel, |
| 3510 | shell_surface_set_transient, |
Kristian Høgsberg | b3cca0a | 2012-01-04 22:19:14 -0500 | [diff] [blame] | 3511 | shell_surface_set_fullscreen, |
Juan Zhao | 96879df | 2012-02-07 08:45:41 +0800 | [diff] [blame] | 3512 | shell_surface_set_popup, |
Kristian Høgsberg | e7afd91 | 2012-05-02 09:47:44 -0400 | [diff] [blame] | 3513 | shell_surface_set_maximized, |
| 3514 | shell_surface_set_title, |
| 3515 | shell_surface_set_class |
Pekka Paalanen | 9d1613e | 2011-11-25 12:09:16 +0200 | [diff] [blame] | 3516 | }; |
| 3517 | |
| 3518 | static void |
Tiago Vignatti | bc052c9 | 2012-04-19 16:18:18 +0300 | [diff] [blame] | 3519 | destroy_shell_surface(struct shell_surface *shsurf) |
Pekka Paalanen | 9d1613e | 2011-11-25 12:09:16 +0200 | [diff] [blame] | 3520 | { |
Kristian Høgsberg | 9046d24 | 2014-01-10 00:25:30 -0800 | [diff] [blame] | 3521 | struct shell_surface *child, *next; |
| 3522 | |
Jason Ekstrand | 651f00e | 2013-06-14 10:07:54 -0500 | [diff] [blame] | 3523 | wl_signal_emit(&shsurf->destroy_signal, shsurf); |
| 3524 | |
Giulio Camuffo | 5085a75 | 2013-03-25 21:42:45 +0100 | [diff] [blame] | 3525 | if (!wl_list_empty(&shsurf->popup.grab_link)) { |
| 3526 | remove_popup_grab(shsurf); |
| 3527 | } |
Kristian Høgsberg | b3cca0a | 2012-01-04 22:19:14 -0500 | [diff] [blame] | 3528 | |
Alex Wu | bd3354b | 2012-04-17 17:20:49 +0800 | [diff] [blame] | 3529 | if (shsurf->fullscreen.type == WL_SHELL_SURFACE_FULLSCREEN_METHOD_DRIVER && |
Alexander Larsson | f82b6ca | 2013-05-28 16:23:39 +0200 | [diff] [blame] | 3530 | shell_surface_is_top_fullscreen(shsurf)) |
| 3531 | restore_output_mode (shsurf->fullscreen_output); |
Pekka Paalanen | 9d1613e | 2011-11-25 12:09:16 +0200 | [diff] [blame] | 3532 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 3533 | if (shsurf->fullscreen.black_view) |
| 3534 | weston_surface_destroy(shsurf->fullscreen.black_view->surface); |
Alex Wu | aa08e2d | 2012-03-05 11:01:40 +0800 | [diff] [blame] | 3535 | |
Alex Wu | bd3354b | 2012-04-17 17:20:49 +0800 | [diff] [blame] | 3536 | /* As destroy_resource() use wl_list_for_each_safe(), |
| 3537 | * we can always remove the listener. |
| 3538 | */ |
| 3539 | wl_list_remove(&shsurf->surface_destroy_listener.link); |
| 3540 | shsurf->surface->configure = NULL; |
Pekka Paalanen | 8274d90 | 2014-08-06 19:36:51 +0300 | [diff] [blame] | 3541 | weston_surface_set_label_func(shsurf->surface, NULL); |
Scott Moreau | 976a050 | 2013-03-07 10:15:17 -0700 | [diff] [blame] | 3542 | free(shsurf->title); |
Alex Wu | bd3354b | 2012-04-17 17:20:49 +0800 | [diff] [blame] | 3543 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 3544 | weston_view_destroy(shsurf->view); |
| 3545 | |
Philip Withnall | 648a4dd | 2013-11-25 18:01:44 +0000 | [diff] [blame] | 3546 | wl_list_remove(&shsurf->children_link); |
Emilio Pozuelo Monfort | adaa20c | 2014-01-28 13:54:16 +0100 | [diff] [blame] | 3547 | wl_list_for_each_safe(child, next, &shsurf->children_list, children_link) |
| 3548 | shell_surface_set_parent(child, NULL); |
Philip Withnall | 648a4dd | 2013-11-25 18:01:44 +0000 | [diff] [blame] | 3549 | |
Pekka Paalanen | 9d1613e | 2011-11-25 12:09:16 +0200 | [diff] [blame] | 3550 | wl_list_remove(&shsurf->link); |
| 3551 | free(shsurf); |
| 3552 | } |
| 3553 | |
| 3554 | static void |
Tiago Vignatti | bc052c9 | 2012-04-19 16:18:18 +0300 | [diff] [blame] | 3555 | shell_destroy_shell_surface(struct wl_resource *resource) |
| 3556 | { |
Jason Ekstrand | 651f00e | 2013-06-14 10:07:54 -0500 | [diff] [blame] | 3557 | struct shell_surface *shsurf = wl_resource_get_user_data(resource); |
Tiago Vignatti | bc052c9 | 2012-04-19 16:18:18 +0300 | [diff] [blame] | 3558 | |
Bryan Cain | a46b946 | 2014-04-04 17:41:24 -0500 | [diff] [blame] | 3559 | if (!wl_list_empty(&shsurf->popup.grab_link)) |
| 3560 | remove_popup_grab(shsurf); |
Jonas Ådahl | 49d77d2 | 2015-03-18 16:20:51 +0800 | [diff] [blame] | 3561 | wl_list_remove(wl_resource_get_link(shsurf->resource)); |
Kristian Høgsberg | 160fe75 | 2014-03-11 10:19:10 -0700 | [diff] [blame] | 3562 | shsurf->resource = NULL; |
Tiago Vignatti | bc052c9 | 2012-04-19 16:18:18 +0300 | [diff] [blame] | 3563 | } |
| 3564 | |
| 3565 | static void |
Kristian Høgsberg | 27e3052 | 2012-04-11 23:18:23 -0400 | [diff] [blame] | 3566 | shell_handle_surface_destroy(struct wl_listener *listener, void *data) |
Pekka Paalanen | 9d1613e | 2011-11-25 12:09:16 +0200 | [diff] [blame] | 3567 | { |
| 3568 | struct shell_surface *shsurf = container_of(listener, |
| 3569 | struct shell_surface, |
| 3570 | surface_destroy_listener); |
| 3571 | |
Jason Ekstrand | 651f00e | 2013-06-14 10:07:54 -0500 | [diff] [blame] | 3572 | if (shsurf->resource) |
| 3573 | wl_resource_destroy(shsurf->resource); |
Ander Conselvan de Oliveira | 15f9a26 | 2014-04-29 17:54:02 +0300 | [diff] [blame] | 3574 | |
| 3575 | destroy_shell_surface(shsurf); |
Pekka Paalanen | 9d1613e | 2011-11-25 12:09:16 +0200 | [diff] [blame] | 3576 | } |
| 3577 | |
Kristian Høgsberg | d813445 | 2012-06-21 12:49:02 -0400 | [diff] [blame] | 3578 | static void |
Derek Foreman | 039e9be | 2015-04-14 17:09:06 -0500 | [diff] [blame] | 3579 | fade_out_done_idle_cb(void *data) |
Kristian Høgsberg | 160fe75 | 2014-03-11 10:19:10 -0700 | [diff] [blame] | 3580 | { |
| 3581 | struct shell_surface *shsurf = data; |
| 3582 | |
| 3583 | weston_surface_destroy(shsurf->surface); |
| 3584 | } |
| 3585 | |
| 3586 | static void |
Derek Foreman | 039e9be | 2015-04-14 17:09:06 -0500 | [diff] [blame] | 3587 | fade_out_done(struct weston_view_animation *animation, void *data) |
| 3588 | { |
| 3589 | struct shell_surface *shsurf = data; |
| 3590 | struct wl_event_loop *loop; |
| 3591 | |
| 3592 | loop = wl_display_get_event_loop( |
| 3593 | shsurf->surface->compositor->wl_display); |
| 3594 | |
| 3595 | if (!shsurf->destroying) { |
| 3596 | wl_event_loop_add_idle(loop, fade_out_done_idle_cb, shsurf); |
| 3597 | shsurf->destroying = true; |
| 3598 | } |
| 3599 | } |
| 3600 | |
| 3601 | static void |
Kristian Høgsberg | 160fe75 | 2014-03-11 10:19:10 -0700 | [diff] [blame] | 3602 | handle_resource_destroy(struct wl_listener *listener, void *data) |
| 3603 | { |
| 3604 | struct shell_surface *shsurf = |
| 3605 | container_of(listener, struct shell_surface, |
| 3606 | resource_destroy_listener); |
| 3607 | |
Ander Conselvan de Oliveira | 15f9a26 | 2014-04-29 17:54:02 +0300 | [diff] [blame] | 3608 | if (!weston_surface_is_mapped(shsurf->surface)) |
| 3609 | return; |
| 3610 | |
Kristian Høgsberg | 160fe75 | 2014-03-11 10:19:10 -0700 | [diff] [blame] | 3611 | shsurf->surface->ref_count++; |
| 3612 | |
| 3613 | pixman_region32_fini(&shsurf->surface->pending.input); |
| 3614 | pixman_region32_init(&shsurf->surface->pending.input); |
| 3615 | pixman_region32_fini(&shsurf->surface->input); |
| 3616 | pixman_region32_init(&shsurf->surface->input); |
Jonny Lamb | f322f8e | 2014-08-12 15:13:30 +0200 | [diff] [blame] | 3617 | if (shsurf->shell->win_close_animation_type == ANIMATION_FADE) { |
| 3618 | weston_fade_run(shsurf->view, 1.0, 0.0, 300.0, |
| 3619 | fade_out_done, shsurf); |
| 3620 | } else { |
| 3621 | weston_surface_destroy(shsurf->surface); |
| 3622 | } |
Kristian Høgsberg | 160fe75 | 2014-03-11 10:19:10 -0700 | [diff] [blame] | 3623 | } |
| 3624 | |
| 3625 | static void |
Jason Ekstrand | 918f2dd | 2013-12-02 21:01:53 -0600 | [diff] [blame] | 3626 | shell_surface_configure(struct weston_surface *, int32_t, int32_t); |
Kristian Høgsberg | d813445 | 2012-06-21 12:49:02 -0400 | [diff] [blame] | 3627 | |
Kristian Høgsberg | 1ef2313 | 2013-12-04 00:20:01 -0800 | [diff] [blame] | 3628 | struct shell_surface * |
Kristian Høgsberg | 8334bc1 | 2012-01-03 10:29:47 -0500 | [diff] [blame] | 3629 | get_shell_surface(struct weston_surface *surface) |
Pekka Paalanen | ec2b32f | 2011-11-28 15:12:34 +0200 | [diff] [blame] | 3630 | { |
Kristian Høgsberg | d813445 | 2012-06-21 12:49:02 -0400 | [diff] [blame] | 3631 | if (surface->configure == shell_surface_configure) |
Giulio Camuffo | 7fe01b1 | 2013-03-28 18:02:42 +0100 | [diff] [blame] | 3632 | return surface->configure_private; |
Kristian Høgsberg | d813445 | 2012-06-21 12:49:02 -0400 | [diff] [blame] | 3633 | else |
| 3634 | return NULL; |
Pekka Paalanen | ec2b32f | 2011-11-28 15:12:34 +0200 | [diff] [blame] | 3635 | } |
| 3636 | |
Rafael Antognolli | e2a3455 | 2013-12-03 15:35:45 -0200 | [diff] [blame] | 3637 | static struct shell_surface * |
Jason Ekstrand | 9e9512f | 2014-04-16 21:12:10 -0500 | [diff] [blame] | 3638 | create_common_surface(struct shell_client *owner, void *shell, |
| 3639 | struct weston_surface *surface, |
Rafael Antognolli | e2a3455 | 2013-12-03 15:35:45 -0200 | [diff] [blame] | 3640 | const struct weston_shell_client *client) |
Pekka Paalanen | 9d1613e | 2011-11-25 12:09:16 +0200 | [diff] [blame] | 3641 | { |
Pekka Paalanen | 9d1613e | 2011-11-25 12:09:16 +0200 | [diff] [blame] | 3642 | struct shell_surface *shsurf; |
| 3643 | |
Pekka Paalanen | 50b6747 | 2014-10-01 15:02:41 +0300 | [diff] [blame] | 3644 | assert(surface->configure == NULL); |
Ander Conselvan de Oliveira | 093bfa3 | 2012-03-27 17:36:41 +0300 | [diff] [blame] | 3645 | |
Pekka Paalanen | 9d1613e | 2011-11-25 12:09:16 +0200 | [diff] [blame] | 3646 | shsurf = calloc(1, sizeof *shsurf); |
| 3647 | if (!shsurf) { |
Martin Minarik | 6d11836 | 2012-06-07 18:01:59 +0200 | [diff] [blame] | 3648 | weston_log("no memory to allocate shell surface\n"); |
Kristian Høgsberg | 45ba869 | 2012-05-21 14:27:33 -0400 | [diff] [blame] | 3649 | return NULL; |
Pekka Paalanen | 9d1613e | 2011-11-25 12:09:16 +0200 | [diff] [blame] | 3650 | } |
| 3651 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 3652 | shsurf->view = weston_view_create(surface); |
| 3653 | if (!shsurf->view) { |
| 3654 | weston_log("no memory to allocate shell surface\n"); |
| 3655 | free(shsurf); |
| 3656 | return NULL; |
| 3657 | } |
| 3658 | |
Ander Conselvan de Oliveira | 093bfa3 | 2012-03-27 17:36:41 +0300 | [diff] [blame] | 3659 | surface->configure = shell_surface_configure; |
Giulio Camuffo | 7fe01b1 | 2013-03-28 18:02:42 +0100 | [diff] [blame] | 3660 | surface->configure_private = shsurf; |
Pekka Paalanen | 8274d90 | 2014-08-06 19:36:51 +0300 | [diff] [blame] | 3661 | weston_surface_set_label_func(surface, shell_surface_get_label); |
Ander Conselvan de Oliveira | 093bfa3 | 2012-03-27 17:36:41 +0300 | [diff] [blame] | 3662 | |
Kristian Høgsberg | 160fe75 | 2014-03-11 10:19:10 -0700 | [diff] [blame] | 3663 | shsurf->resource_destroy_listener.notify = handle_resource_destroy; |
| 3664 | wl_resource_add_destroy_listener(surface->resource, |
| 3665 | &shsurf->resource_destroy_listener); |
Jason Ekstrand | 9e9512f | 2014-04-16 21:12:10 -0500 | [diff] [blame] | 3666 | shsurf->owner = owner; |
Kristian Høgsberg | 160fe75 | 2014-03-11 10:19:10 -0700 | [diff] [blame] | 3667 | |
Tiago Vignatti | bc052c9 | 2012-04-19 16:18:18 +0300 | [diff] [blame] | 3668 | shsurf->shell = (struct desktop_shell *) shell; |
Scott Moreau | ff1db4a | 2012-04-17 19:06:18 -0600 | [diff] [blame] | 3669 | shsurf->unresponsive = 0; |
Alex Wu | 4539b08 | 2012-03-01 12:57:46 +0800 | [diff] [blame] | 3670 | shsurf->saved_position_valid = false; |
Rafael Antognolli | 3c4e3f7 | 2013-12-03 15:35:46 -0200 | [diff] [blame] | 3671 | shsurf->saved_size_valid = false; |
Alex Wu | 7bcb8bd | 2012-04-27 09:07:24 +0800 | [diff] [blame] | 3672 | shsurf->saved_rotation_valid = false; |
Pekka Paalanen | 9d1613e | 2011-11-25 12:09:16 +0200 | [diff] [blame] | 3673 | shsurf->surface = surface; |
Alex Wu | 4539b08 | 2012-03-01 12:57:46 +0800 | [diff] [blame] | 3674 | shsurf->fullscreen.type = WL_SHELL_SURFACE_FULLSCREEN_METHOD_DEFAULT; |
| 3675 | shsurf->fullscreen.framerate = 0; |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 3676 | shsurf->fullscreen.black_view = NULL; |
Alex Wu | 4539b08 | 2012-03-01 12:57:46 +0800 | [diff] [blame] | 3677 | wl_list_init(&shsurf->fullscreen.transform.link); |
| 3678 | |
Jasper St. Pierre | 9aa8ce6 | 2014-04-11 16:18:54 -0700 | [diff] [blame] | 3679 | shsurf->output = get_default_output(shsurf->shell->compositor); |
| 3680 | |
Jason Ekstrand | 651f00e | 2013-06-14 10:07:54 -0500 | [diff] [blame] | 3681 | wl_signal_init(&shsurf->destroy_signal); |
Kristian Høgsberg | 27e3052 | 2012-04-11 23:18:23 -0400 | [diff] [blame] | 3682 | shsurf->surface_destroy_listener.notify = shell_handle_surface_destroy; |
Jason Ekstrand | 26ed73c | 2013-06-06 22:34:41 -0500 | [diff] [blame] | 3683 | wl_signal_add(&surface->destroy_signal, |
Kristian Høgsberg | 27e3052 | 2012-04-11 23:18:23 -0400 | [diff] [blame] | 3684 | &shsurf->surface_destroy_listener); |
Pekka Paalanen | 9d1613e | 2011-11-25 12:09:16 +0200 | [diff] [blame] | 3685 | |
| 3686 | /* init link so its safe to always remove it in destroy_shell_surface */ |
| 3687 | wl_list_init(&shsurf->link); |
Giulio Camuffo | 5085a75 | 2013-03-25 21:42:45 +0100 | [diff] [blame] | 3688 | wl_list_init(&shsurf->popup.grab_link); |
Pekka Paalanen | 9d1613e | 2011-11-25 12:09:16 +0200 | [diff] [blame] | 3689 | |
Pekka Paalanen | 460099f | 2012-01-20 16:48:25 +0200 | [diff] [blame] | 3690 | /* empty when not in use */ |
| 3691 | wl_list_init(&shsurf->rotation.transform.link); |
Kristian Høgsberg | 765e27b | 2012-01-27 13:36:13 -0500 | [diff] [blame] | 3692 | weston_matrix_init(&shsurf->rotation.rotation); |
Pekka Paalanen | 460099f | 2012-01-20 16:48:25 +0200 | [diff] [blame] | 3693 | |
Jonas Ådahl | 62fcd04 | 2012-06-13 00:01:23 +0200 | [diff] [blame] | 3694 | wl_list_init(&shsurf->workspace_transform.link); |
| 3695 | |
Philip Withnall | 648a4dd | 2013-11-25 18:01:44 +0000 | [diff] [blame] | 3696 | wl_list_init(&shsurf->children_link); |
| 3697 | wl_list_init(&shsurf->children_list); |
| 3698 | shsurf->parent = NULL; |
| 3699 | |
Pekka Paalanen | b502654 | 2014-11-12 15:09:24 +0200 | [diff] [blame] | 3700 | set_type(shsurf, SHELL_SURFACE_NONE); |
Pekka Paalanen | 9d1613e | 2011-11-25 12:09:16 +0200 | [diff] [blame] | 3701 | |
Kristian Høgsberg | a61ca06 | 2012-05-22 16:05:52 -0400 | [diff] [blame] | 3702 | shsurf->client = client; |
| 3703 | |
Kristian Høgsberg | 45ba869 | 2012-05-21 14:27:33 -0400 | [diff] [blame] | 3704 | return shsurf; |
Tiago Vignatti | bc052c9 | 2012-04-19 16:18:18 +0300 | [diff] [blame] | 3705 | } |
| 3706 | |
Rafael Antognolli | e2a3455 | 2013-12-03 15:35:45 -0200 | [diff] [blame] | 3707 | static struct shell_surface * |
| 3708 | create_shell_surface(void *shell, struct weston_surface *surface, |
| 3709 | const struct weston_shell_client *client) |
| 3710 | { |
Jason Ekstrand | 9e9512f | 2014-04-16 21:12:10 -0500 | [diff] [blame] | 3711 | return create_common_surface(NULL, shell, surface, client); |
Rafael Antognolli | e2a3455 | 2013-12-03 15:35:45 -0200 | [diff] [blame] | 3712 | } |
| 3713 | |
Tiago Vignatti | bc052c9 | 2012-04-19 16:18:18 +0300 | [diff] [blame] | 3714 | static void |
| 3715 | shell_get_shell_surface(struct wl_client *client, |
| 3716 | struct wl_resource *resource, |
| 3717 | uint32_t id, |
| 3718 | struct wl_resource *surface_resource) |
| 3719 | { |
Jason Ekstrand | 0f2ef7e | 2013-06-14 10:07:53 -0500 | [diff] [blame] | 3720 | struct weston_surface *surface = |
| 3721 | wl_resource_get_user_data(surface_resource); |
Jason Ekstrand | 9e9512f | 2014-04-16 21:12:10 -0500 | [diff] [blame] | 3722 | struct shell_client *sc = wl_resource_get_user_data(resource); |
| 3723 | struct desktop_shell *shell = sc->shell; |
Tiago Vignatti | bc052c9 | 2012-04-19 16:18:18 +0300 | [diff] [blame] | 3724 | struct shell_surface *shsurf; |
| 3725 | |
Pekka Paalanen | 50b6747 | 2014-10-01 15:02:41 +0300 | [diff] [blame] | 3726 | if (weston_surface_set_role(surface, "wl_shell_surface", |
| 3727 | resource, WL_SHELL_ERROR_ROLE) < 0) |
Tiago Vignatti | bc052c9 | 2012-04-19 16:18:18 +0300 | [diff] [blame] | 3728 | return; |
Tiago Vignatti | bc052c9 | 2012-04-19 16:18:18 +0300 | [diff] [blame] | 3729 | |
Jason Ekstrand | 9e9512f | 2014-04-16 21:12:10 -0500 | [diff] [blame] | 3730 | shsurf = create_common_surface(sc, shell, surface, &shell_client); |
Kristian Høgsberg | 9540ea6 | 2012-05-21 14:28:57 -0400 | [diff] [blame] | 3731 | if (!shsurf) { |
Pekka Paalanen | 50b6747 | 2014-10-01 15:02:41 +0300 | [diff] [blame] | 3732 | wl_resource_post_no_memory(surface_resource); |
Kristian Høgsberg | 9540ea6 | 2012-05-21 14:28:57 -0400 | [diff] [blame] | 3733 | return; |
| 3734 | } |
Tiago Vignatti | bc052c9 | 2012-04-19 16:18:18 +0300 | [diff] [blame] | 3735 | |
Jason Ekstrand | a85118c | 2013-06-27 20:17:02 -0500 | [diff] [blame] | 3736 | shsurf->resource = |
| 3737 | wl_resource_create(client, |
| 3738 | &wl_shell_surface_interface, 1, id); |
| 3739 | wl_resource_set_implementation(shsurf->resource, |
| 3740 | &shell_surface_implementation, |
| 3741 | shsurf, shell_destroy_shell_surface); |
Jonas Ådahl | 49d77d2 | 2015-03-18 16:20:51 +0800 | [diff] [blame] | 3742 | wl_list_init(wl_resource_get_link(shsurf->resource)); |
Pekka Paalanen | 9d1613e | 2011-11-25 12:09:16 +0200 | [diff] [blame] | 3743 | } |
| 3744 | |
Rafael Antognolli | e2a3455 | 2013-12-03 15:35:45 -0200 | [diff] [blame] | 3745 | static bool |
| 3746 | shell_surface_is_wl_shell_surface(struct shell_surface *shsurf) |
| 3747 | { |
Kristian Høgsberg | 0b7d995 | 2014-02-03 15:50:38 -0800 | [diff] [blame] | 3748 | /* A shell surface without a resource is created from xwayland |
| 3749 | * and is considered a wl_shell surface for now. */ |
| 3750 | |
| 3751 | return shsurf->resource == NULL || |
| 3752 | wl_resource_instance_of(shsurf->resource, |
| 3753 | &wl_shell_surface_interface, |
| 3754 | &shell_surface_implementation); |
Rafael Antognolli | e2a3455 | 2013-12-03 15:35:45 -0200 | [diff] [blame] | 3755 | } |
| 3756 | |
Pekka Paalanen | 9d1613e | 2011-11-25 12:09:16 +0200 | [diff] [blame] | 3757 | static const struct wl_shell_interface shell_implementation = { |
Pekka Paalanen | 4622967 | 2011-11-29 15:49:31 +0200 | [diff] [blame] | 3758 | shell_get_shell_surface |
Kristian Høgsberg | 4cca349 | 2011-01-18 07:53:49 -0500 | [diff] [blame] | 3759 | }; |
| 3760 | |
Rafael Antognolli | e2a3455 | 2013-12-03 15:35:45 -0200 | [diff] [blame] | 3761 | /**************************** |
| 3762 | * xdg-shell implementation */ |
| 3763 | |
| 3764 | static void |
| 3765 | xdg_surface_destroy(struct wl_client *client, |
| 3766 | struct wl_resource *resource) |
| 3767 | { |
| 3768 | wl_resource_destroy(resource); |
| 3769 | } |
| 3770 | |
| 3771 | static void |
Jasper St. Pierre | c815d62 | 2014-04-10 18:37:54 -0700 | [diff] [blame] | 3772 | xdg_surface_set_parent(struct wl_client *client, |
| 3773 | struct wl_resource *resource, |
| 3774 | struct wl_resource *parent_resource) |
Jasper St. Pierre | 63a9c33 | 2014-02-01 18:35:15 -0500 | [diff] [blame] | 3775 | { |
| 3776 | struct shell_surface *shsurf = wl_resource_get_user_data(resource); |
Jasper St. Pierre | 66bc949 | 2015-02-13 14:01:55 +0800 | [diff] [blame] | 3777 | struct shell_surface *parent; |
Jasper St. Pierre | 63a9c33 | 2014-02-01 18:35:15 -0500 | [diff] [blame] | 3778 | |
Jasper St. Pierre | 66bc949 | 2015-02-13 14:01:55 +0800 | [diff] [blame] | 3779 | if (parent_resource) { |
Jasper St. Pierre | 63a9c33 | 2014-02-01 18:35:15 -0500 | [diff] [blame] | 3780 | parent = wl_resource_get_user_data(parent_resource); |
Jasper St. Pierre | 66bc949 | 2015-02-13 14:01:55 +0800 | [diff] [blame] | 3781 | shell_surface_set_parent(shsurf, parent->surface); |
| 3782 | } else { |
| 3783 | shell_surface_set_parent(shsurf, NULL); |
| 3784 | } |
Jasper St. Pierre | 63a9c33 | 2014-02-01 18:35:15 -0500 | [diff] [blame] | 3785 | } |
| 3786 | |
| 3787 | static void |
Rafael Antognolli | e2a3455 | 2013-12-03 15:35:45 -0200 | [diff] [blame] | 3788 | xdg_surface_set_app_id(struct wl_client *client, |
| 3789 | struct wl_resource *resource, |
| 3790 | const char *app_id) |
| 3791 | { |
| 3792 | struct shell_surface *shsurf = wl_resource_get_user_data(resource); |
| 3793 | |
| 3794 | free(shsurf->class); |
| 3795 | shsurf->class = strdup(app_id); |
Pekka Paalanen | b502654 | 2014-11-12 15:09:24 +0200 | [diff] [blame] | 3796 | shsurf->surface->timeline.force_refresh = 1; |
Rafael Antognolli | e2a3455 | 2013-12-03 15:35:45 -0200 | [diff] [blame] | 3797 | } |
| 3798 | |
| 3799 | static void |
Jasper St. Pierre | 81ff075 | 2014-03-13 11:04:53 -0400 | [diff] [blame] | 3800 | xdg_surface_show_window_menu(struct wl_client *client, |
| 3801 | struct wl_resource *surface_resource, |
| 3802 | struct wl_resource *seat_resource, |
| 3803 | uint32_t serial, |
| 3804 | int32_t x, |
| 3805 | int32_t y) |
| 3806 | { |
| 3807 | /* TODO */ |
| 3808 | } |
| 3809 | |
| 3810 | static void |
Rafael Antognolli | e2a3455 | 2013-12-03 15:35:45 -0200 | [diff] [blame] | 3811 | xdg_surface_set_title(struct wl_client *client, |
| 3812 | struct wl_resource *resource, const char *title) |
| 3813 | { |
| 3814 | struct shell_surface *shsurf = wl_resource_get_user_data(resource); |
| 3815 | |
| 3816 | set_title(shsurf, title); |
| 3817 | } |
| 3818 | |
| 3819 | static void |
| 3820 | xdg_surface_move(struct wl_client *client, struct wl_resource *resource, |
| 3821 | struct wl_resource *seat_resource, uint32_t serial) |
| 3822 | { |
| 3823 | common_surface_move(resource, seat_resource, serial); |
| 3824 | } |
| 3825 | |
| 3826 | static void |
| 3827 | xdg_surface_resize(struct wl_client *client, struct wl_resource *resource, |
| 3828 | struct wl_resource *seat_resource, uint32_t serial, |
| 3829 | uint32_t edges) |
| 3830 | { |
| 3831 | common_surface_resize(resource, seat_resource, serial, edges); |
| 3832 | } |
| 3833 | |
| 3834 | static void |
Jasper St. Pierre | ab2c108 | 2014-04-10 10:41:46 -0700 | [diff] [blame] | 3835 | xdg_surface_ack_configure(struct wl_client *client, |
| 3836 | struct wl_resource *resource, |
| 3837 | uint32_t serial) |
Rafael Antognolli | e2a3455 | 2013-12-03 15:35:45 -0200 | [diff] [blame] | 3838 | { |
| 3839 | struct shell_surface *shsurf = wl_resource_get_user_data(resource); |
| 3840 | |
Jasper St. Pierre | 8c6aa45 | 2014-02-08 18:29:49 -0500 | [diff] [blame] | 3841 | if (shsurf->state_requested) { |
| 3842 | shsurf->next_state = shsurf->requested_state; |
| 3843 | shsurf->state_changed = true; |
| 3844 | shsurf->state_requested = false; |
Rafael Antognolli | 3c4e3f7 | 2013-12-03 15:35:46 -0200 | [diff] [blame] | 3845 | } |
Rafael Antognolli | e2a3455 | 2013-12-03 15:35:45 -0200 | [diff] [blame] | 3846 | } |
| 3847 | |
Manuel Bachmann | 50c87db | 2014-02-26 15:52:13 +0100 | [diff] [blame] | 3848 | static void |
Jasper St. Pierre | ccf48fb | 2014-05-02 10:21:38 -0400 | [diff] [blame] | 3849 | xdg_surface_set_window_geometry(struct wl_client *client, |
| 3850 | struct wl_resource *resource, |
| 3851 | int32_t x, |
| 3852 | int32_t y, |
| 3853 | int32_t width, |
| 3854 | int32_t height) |
| 3855 | { |
| 3856 | struct shell_surface *shsurf = wl_resource_get_user_data(resource); |
| 3857 | |
| 3858 | set_window_geometry(shsurf, x, y, width, height); |
| 3859 | } |
| 3860 | |
| 3861 | static void |
Jasper St. Pierre | ab2c108 | 2014-04-10 10:41:46 -0700 | [diff] [blame] | 3862 | xdg_surface_set_maximized(struct wl_client *client, |
| 3863 | struct wl_resource *resource) |
| 3864 | { |
| 3865 | struct shell_surface *shsurf = wl_resource_get_user_data(resource); |
Marek Chalupa | bfbb64b | 2014-09-08 12:34:20 +0200 | [diff] [blame] | 3866 | struct weston_output *output; |
Jasper St. Pierre | ab2c108 | 2014-04-10 10:41:46 -0700 | [diff] [blame] | 3867 | |
| 3868 | shsurf->state_requested = true; |
| 3869 | shsurf->requested_state.maximized = true; |
Marek Chalupa | bfbb64b | 2014-09-08 12:34:20 +0200 | [diff] [blame] | 3870 | |
| 3871 | if (!weston_surface_is_mapped(shsurf->surface)) |
| 3872 | output = get_focused_output(shsurf->surface->compositor); |
| 3873 | else |
| 3874 | output = shsurf->surface->output; |
| 3875 | |
| 3876 | shell_surface_set_output(shsurf, output); |
Jasper St. Pierre | 9aa8ce6 | 2014-04-11 16:18:54 -0700 | [diff] [blame] | 3877 | send_configure_for_surface(shsurf); |
Jasper St. Pierre | ab2c108 | 2014-04-10 10:41:46 -0700 | [diff] [blame] | 3878 | } |
| 3879 | |
| 3880 | static void |
| 3881 | xdg_surface_unset_maximized(struct wl_client *client, |
| 3882 | struct wl_resource *resource) |
| 3883 | { |
| 3884 | struct shell_surface *shsurf = wl_resource_get_user_data(resource); |
| 3885 | |
| 3886 | shsurf->state_requested = true; |
| 3887 | shsurf->requested_state.maximized = false; |
Jasper St. Pierre | 6458ec3 | 2014-04-11 16:00:31 -0700 | [diff] [blame] | 3888 | send_configure_for_surface(shsurf); |
Jasper St. Pierre | ab2c108 | 2014-04-10 10:41:46 -0700 | [diff] [blame] | 3889 | } |
| 3890 | |
| 3891 | static void |
| 3892 | xdg_surface_set_fullscreen(struct wl_client *client, |
| 3893 | struct wl_resource *resource, |
| 3894 | struct wl_resource *output_resource) |
| 3895 | { |
| 3896 | struct shell_surface *shsurf = wl_resource_get_user_data(resource); |
| 3897 | struct weston_output *output; |
| 3898 | |
| 3899 | shsurf->state_requested = true; |
| 3900 | shsurf->requested_state.fullscreen = true; |
| 3901 | |
| 3902 | if (output_resource) |
| 3903 | output = wl_resource_get_user_data(output_resource); |
| 3904 | else |
| 3905 | output = NULL; |
| 3906 | |
Marek Chalupa | 052917a | 2014-09-02 11:35:12 +0200 | [diff] [blame] | 3907 | /* handle clients launching in fullscreen */ |
| 3908 | if (output == NULL && !weston_surface_is_mapped(shsurf->surface)) { |
| 3909 | /* Set the output to the one that has focus currently. */ |
| 3910 | assert(shsurf->surface); |
| 3911 | output = get_focused_output(shsurf->surface->compositor); |
| 3912 | } |
| 3913 | |
Jasper St. Pierre | 9aa8ce6 | 2014-04-11 16:18:54 -0700 | [diff] [blame] | 3914 | shell_surface_set_output(shsurf, output); |
| 3915 | shsurf->fullscreen_output = shsurf->output; |
Jasper St. Pierre | ab2c108 | 2014-04-10 10:41:46 -0700 | [diff] [blame] | 3916 | |
Jasper St. Pierre | 9aa8ce6 | 2014-04-11 16:18:54 -0700 | [diff] [blame] | 3917 | send_configure_for_surface(shsurf); |
Jasper St. Pierre | ab2c108 | 2014-04-10 10:41:46 -0700 | [diff] [blame] | 3918 | } |
| 3919 | |
| 3920 | static void |
| 3921 | xdg_surface_unset_fullscreen(struct wl_client *client, |
| 3922 | struct wl_resource *resource) |
| 3923 | { |
| 3924 | struct shell_surface *shsurf = wl_resource_get_user_data(resource); |
| 3925 | |
| 3926 | shsurf->state_requested = true; |
| 3927 | shsurf->requested_state.fullscreen = false; |
Jasper St. Pierre | 6458ec3 | 2014-04-11 16:00:31 -0700 | [diff] [blame] | 3928 | send_configure_for_surface(shsurf); |
Jasper St. Pierre | ab2c108 | 2014-04-10 10:41:46 -0700 | [diff] [blame] | 3929 | } |
| 3930 | |
| 3931 | static void |
Manuel Bachmann | 50c87db | 2014-02-26 15:52:13 +0100 | [diff] [blame] | 3932 | xdg_surface_set_minimized(struct wl_client *client, |
| 3933 | struct wl_resource *resource) |
| 3934 | { |
| 3935 | struct shell_surface *shsurf = wl_resource_get_user_data(resource); |
| 3936 | |
| 3937 | if (shsurf->type != SHELL_SURFACE_TOPLEVEL) |
| 3938 | return; |
| 3939 | |
| 3940 | /* apply compositor's own minimization logic (hide) */ |
Manuel Bachmann | dc1c3e4 | 2015-02-16 11:52:13 +0100 | [diff] [blame] | 3941 | set_minimized(shsurf->surface); |
Manuel Bachmann | 50c87db | 2014-02-26 15:52:13 +0100 | [diff] [blame] | 3942 | } |
| 3943 | |
Rafael Antognolli | e2a3455 | 2013-12-03 15:35:45 -0200 | [diff] [blame] | 3944 | static const struct xdg_surface_interface xdg_surface_implementation = { |
| 3945 | xdg_surface_destroy, |
Jasper St. Pierre | c815d62 | 2014-04-10 18:37:54 -0700 | [diff] [blame] | 3946 | xdg_surface_set_parent, |
Rafael Antognolli | e2a3455 | 2013-12-03 15:35:45 -0200 | [diff] [blame] | 3947 | xdg_surface_set_title, |
| 3948 | xdg_surface_set_app_id, |
Jasper St. Pierre | 81ff075 | 2014-03-13 11:04:53 -0400 | [diff] [blame] | 3949 | xdg_surface_show_window_menu, |
Rafael Antognolli | e2a3455 | 2013-12-03 15:35:45 -0200 | [diff] [blame] | 3950 | xdg_surface_move, |
| 3951 | xdg_surface_resize, |
Jasper St. Pierre | ab2c108 | 2014-04-10 10:41:46 -0700 | [diff] [blame] | 3952 | xdg_surface_ack_configure, |
Jasper St. Pierre | ccf48fb | 2014-05-02 10:21:38 -0400 | [diff] [blame] | 3953 | xdg_surface_set_window_geometry, |
Jasper St. Pierre | ab2c108 | 2014-04-10 10:41:46 -0700 | [diff] [blame] | 3954 | xdg_surface_set_maximized, |
| 3955 | xdg_surface_unset_maximized, |
| 3956 | xdg_surface_set_fullscreen, |
| 3957 | xdg_surface_unset_fullscreen, |
| 3958 | xdg_surface_set_minimized, |
Rafael Antognolli | e2a3455 | 2013-12-03 15:35:45 -0200 | [diff] [blame] | 3959 | }; |
| 3960 | |
| 3961 | static void |
| 3962 | xdg_send_configure(struct weston_surface *surface, |
Jasper St. Pierre | ac985be | 2014-04-28 11:19:28 -0400 | [diff] [blame] | 3963 | int32_t width, int32_t height) |
Rafael Antognolli | e2a3455 | 2013-12-03 15:35:45 -0200 | [diff] [blame] | 3964 | { |
| 3965 | struct shell_surface *shsurf = get_shell_surface(surface); |
Jasper St. Pierre | ab2c108 | 2014-04-10 10:41:46 -0700 | [diff] [blame] | 3966 | uint32_t *s; |
| 3967 | struct wl_array states; |
| 3968 | uint32_t serial; |
Rafael Antognolli | e2a3455 | 2013-12-03 15:35:45 -0200 | [diff] [blame] | 3969 | |
U. Artie Eoff | cf5737a | 2014-01-17 10:08:25 -0800 | [diff] [blame] | 3970 | assert(shsurf); |
| 3971 | |
Jasper St. Pierre | ab2c108 | 2014-04-10 10:41:46 -0700 | [diff] [blame] | 3972 | if (!shsurf->resource) |
| 3973 | return; |
| 3974 | |
| 3975 | wl_array_init(&states); |
| 3976 | if (shsurf->requested_state.fullscreen) { |
| 3977 | s = wl_array_add(&states, sizeof *s); |
| 3978 | *s = XDG_SURFACE_STATE_FULLSCREEN; |
| 3979 | } else if (shsurf->requested_state.maximized) { |
| 3980 | s = wl_array_add(&states, sizeof *s); |
| 3981 | *s = XDG_SURFACE_STATE_MAXIMIZED; |
| 3982 | } |
Jasper St. Pierre | 5befdda | 2014-05-06 08:50:47 -0400 | [diff] [blame] | 3983 | if (shsurf->resize_edges != 0) { |
| 3984 | s = wl_array_add(&states, sizeof *s); |
| 3985 | *s = XDG_SURFACE_STATE_RESIZING; |
| 3986 | } |
Jasper St. Pierre | 973d787 | 2014-05-06 08:44:29 -0400 | [diff] [blame] | 3987 | if (shsurf->focus_count > 0) { |
| 3988 | s = wl_array_add(&states, sizeof *s); |
| 3989 | *s = XDG_SURFACE_STATE_ACTIVATED; |
| 3990 | } |
Jasper St. Pierre | ab2c108 | 2014-04-10 10:41:46 -0700 | [diff] [blame] | 3991 | |
| 3992 | serial = wl_display_next_serial(shsurf->surface->compositor->wl_display); |
| 3993 | xdg_surface_send_configure(shsurf->resource, width, height, &states, serial); |
| 3994 | |
| 3995 | wl_array_release(&states); |
Rafael Antognolli | e2a3455 | 2013-12-03 15:35:45 -0200 | [diff] [blame] | 3996 | } |
| 3997 | |
| 3998 | static const struct weston_shell_client xdg_client = { |
Giulio Camuffo | f05d18f | 2015-12-11 20:57:05 +0200 | [diff] [blame] | 3999 | xdg_send_configure, |
| 4000 | NULL |
Rafael Antognolli | e2a3455 | 2013-12-03 15:35:45 -0200 | [diff] [blame] | 4001 | }; |
| 4002 | |
| 4003 | static void |
Jasper St. Pierre | 084aa0b | 2015-02-13 14:02:00 +0800 | [diff] [blame] | 4004 | xdg_shell_destroy(struct wl_client *client, |
| 4005 | struct wl_resource *resource) |
| 4006 | { |
Jonas Ådahl | 49d77d2 | 2015-03-18 16:20:51 +0800 | [diff] [blame] | 4007 | struct shell_client *sc = wl_resource_get_user_data(resource); |
| 4008 | struct wl_resource *shsurf_resource; |
| 4009 | struct shell_surface *shsurf; |
| 4010 | |
| 4011 | wl_resource_for_each(shsurf_resource, &sc->surface_list) { |
| 4012 | shsurf = wl_resource_get_user_data(shsurf_resource); |
| 4013 | if (shsurf->owner_resource == resource) { |
| 4014 | wl_resource_post_error( |
| 4015 | resource, |
| 4016 | XDG_SHELL_ERROR_DEFUNCT_SURFACES, |
| 4017 | "not all child surface objects destroyed"); |
| 4018 | return; |
| 4019 | } |
| 4020 | } |
| 4021 | |
Jasper St. Pierre | 084aa0b | 2015-02-13 14:02:00 +0800 | [diff] [blame] | 4022 | wl_resource_destroy(resource); |
| 4023 | } |
| 4024 | |
| 4025 | static void |
Rafael Antognolli | e2a3455 | 2013-12-03 15:35:45 -0200 | [diff] [blame] | 4026 | xdg_use_unstable_version(struct wl_client *client, |
| 4027 | struct wl_resource *resource, |
| 4028 | int32_t version) |
| 4029 | { |
| 4030 | if (version > 1) { |
| 4031 | wl_resource_post_error(resource, |
| 4032 | 1, |
| 4033 | "xdg-shell:: version not implemented yet."); |
| 4034 | return; |
| 4035 | } |
| 4036 | } |
| 4037 | |
| 4038 | static struct shell_surface * |
Jason Ekstrand | 9e9512f | 2014-04-16 21:12:10 -0500 | [diff] [blame] | 4039 | create_xdg_surface(struct shell_client *owner, void *shell, |
| 4040 | struct weston_surface *surface, |
Rafael Antognolli | e2a3455 | 2013-12-03 15:35:45 -0200 | [diff] [blame] | 4041 | const struct weston_shell_client *client) |
| 4042 | { |
| 4043 | struct shell_surface *shsurf; |
Rafael Antognolli | e2a3455 | 2013-12-03 15:35:45 -0200 | [diff] [blame] | 4044 | |
Jason Ekstrand | 9e9512f | 2014-04-16 21:12:10 -0500 | [diff] [blame] | 4045 | shsurf = create_common_surface(owner, shell, surface, client); |
Pekka Paalanen | e972b27 | 2014-10-01 14:03:56 +0300 | [diff] [blame] | 4046 | if (!shsurf) |
| 4047 | return NULL; |
| 4048 | |
Pekka Paalanen | b502654 | 2014-11-12 15:09:24 +0200 | [diff] [blame] | 4049 | set_type(shsurf, SHELL_SURFACE_TOPLEVEL); |
Rafael Antognolli | e2a3455 | 2013-12-03 15:35:45 -0200 | [diff] [blame] | 4050 | |
| 4051 | return shsurf; |
| 4052 | } |
| 4053 | |
| 4054 | static void |
| 4055 | xdg_get_xdg_surface(struct wl_client *client, |
| 4056 | struct wl_resource *resource, |
| 4057 | uint32_t id, |
| 4058 | struct wl_resource *surface_resource) |
| 4059 | { |
| 4060 | struct weston_surface *surface = |
| 4061 | wl_resource_get_user_data(surface_resource); |
Kristian Høgsberg | 2bff94e | 2014-02-11 12:22:51 -0800 | [diff] [blame] | 4062 | struct shell_client *sc = wl_resource_get_user_data(resource); |
| 4063 | struct desktop_shell *shell = sc->shell; |
Rafael Antognolli | e2a3455 | 2013-12-03 15:35:45 -0200 | [diff] [blame] | 4064 | struct shell_surface *shsurf; |
| 4065 | |
Jonas Ådahl | bf48e21 | 2015-02-06 10:15:28 +0800 | [diff] [blame] | 4066 | shsurf = get_shell_surface(surface); |
| 4067 | if (shsurf && shell_surface_is_xdg_surface(shsurf)) { |
| 4068 | wl_resource_post_error(resource, XDG_SHELL_ERROR_ROLE, |
| 4069 | "This wl_surface is already an " |
| 4070 | "xdg_surface"); |
| 4071 | return; |
| 4072 | } |
| 4073 | |
Pekka Paalanen | 50b6747 | 2014-10-01 15:02:41 +0300 | [diff] [blame] | 4074 | if (weston_surface_set_role(surface, "xdg_surface", |
| 4075 | resource, XDG_SHELL_ERROR_ROLE) < 0) |
Rafael Antognolli | e2a3455 | 2013-12-03 15:35:45 -0200 | [diff] [blame] | 4076 | return; |
Rafael Antognolli | e2a3455 | 2013-12-03 15:35:45 -0200 | [diff] [blame] | 4077 | |
Jason Ekstrand | 9e9512f | 2014-04-16 21:12:10 -0500 | [diff] [blame] | 4078 | shsurf = create_xdg_surface(sc, shell, surface, &xdg_client); |
Rafael Antognolli | e2a3455 | 2013-12-03 15:35:45 -0200 | [diff] [blame] | 4079 | if (!shsurf) { |
Pekka Paalanen | 50b6747 | 2014-10-01 15:02:41 +0300 | [diff] [blame] | 4080 | wl_resource_post_no_memory(surface_resource); |
Rafael Antognolli | e2a3455 | 2013-12-03 15:35:45 -0200 | [diff] [blame] | 4081 | return; |
| 4082 | } |
| 4083 | |
| 4084 | shsurf->resource = |
| 4085 | wl_resource_create(client, |
| 4086 | &xdg_surface_interface, 1, id); |
| 4087 | wl_resource_set_implementation(shsurf->resource, |
| 4088 | &xdg_surface_implementation, |
| 4089 | shsurf, shell_destroy_shell_surface); |
Jonas Ådahl | 49d77d2 | 2015-03-18 16:20:51 +0800 | [diff] [blame] | 4090 | shsurf->owner_resource = resource; |
| 4091 | wl_list_insert(&sc->surface_list, |
| 4092 | wl_resource_get_link(shsurf->resource)); |
Rafael Antognolli | e2a3455 | 2013-12-03 15:35:45 -0200 | [diff] [blame] | 4093 | } |
| 4094 | |
| 4095 | static bool |
| 4096 | shell_surface_is_xdg_surface(struct shell_surface *shsurf) |
| 4097 | { |
Kristian Høgsberg | 0b7d995 | 2014-02-03 15:50:38 -0800 | [diff] [blame] | 4098 | return shsurf->resource && |
| 4099 | wl_resource_instance_of(shsurf->resource, |
| 4100 | &xdg_surface_interface, |
| 4101 | &xdg_surface_implementation); |
Rafael Antognolli | e2a3455 | 2013-12-03 15:35:45 -0200 | [diff] [blame] | 4102 | } |
| 4103 | |
| 4104 | /* xdg-popup implementation */ |
| 4105 | |
| 4106 | static void |
| 4107 | xdg_popup_destroy(struct wl_client *client, |
| 4108 | struct wl_resource *resource) |
| 4109 | { |
| 4110 | wl_resource_destroy(resource); |
| 4111 | } |
| 4112 | |
Rafael Antognolli | e2a3455 | 2013-12-03 15:35:45 -0200 | [diff] [blame] | 4113 | static const struct xdg_popup_interface xdg_popup_implementation = { |
| 4114 | xdg_popup_destroy, |
Rafael Antognolli | e2a3455 | 2013-12-03 15:35:45 -0200 | [diff] [blame] | 4115 | }; |
| 4116 | |
| 4117 | static void |
| 4118 | xdg_popup_send_configure(struct weston_surface *surface, |
Jasper St. Pierre | ac985be | 2014-04-28 11:19:28 -0400 | [diff] [blame] | 4119 | int32_t width, int32_t height) |
Rafael Antognolli | e2a3455 | 2013-12-03 15:35:45 -0200 | [diff] [blame] | 4120 | { |
| 4121 | } |
| 4122 | |
| 4123 | static const struct weston_shell_client xdg_popup_client = { |
Giulio Camuffo | f05d18f | 2015-12-11 20:57:05 +0200 | [diff] [blame] | 4124 | xdg_popup_send_configure, |
| 4125 | NULL |
Rafael Antognolli | e2a3455 | 2013-12-03 15:35:45 -0200 | [diff] [blame] | 4126 | }; |
| 4127 | |
| 4128 | static struct shell_surface * |
Jason Ekstrand | 9e9512f | 2014-04-16 21:12:10 -0500 | [diff] [blame] | 4129 | create_xdg_popup(struct shell_client *owner, void *shell, |
| 4130 | struct weston_surface *surface, |
Rafael Antognolli | e2a3455 | 2013-12-03 15:35:45 -0200 | [diff] [blame] | 4131 | const struct weston_shell_client *client, |
| 4132 | struct weston_surface *parent, |
| 4133 | struct shell_seat *seat, |
| 4134 | uint32_t serial, |
| 4135 | int32_t x, int32_t y) |
| 4136 | { |
Jonas Ådahl | ee45a55 | 2015-03-18 16:37:47 +0800 | [diff] [blame] | 4137 | struct shell_surface *shsurf; |
Jonas Ådahl | 24185e2 | 2015-02-27 18:37:41 +0800 | [diff] [blame] | 4138 | |
Jason Ekstrand | 9e9512f | 2014-04-16 21:12:10 -0500 | [diff] [blame] | 4139 | shsurf = create_common_surface(owner, shell, surface, client); |
Pekka Paalanen | e972b27 | 2014-10-01 14:03:56 +0300 | [diff] [blame] | 4140 | if (!shsurf) |
| 4141 | return NULL; |
| 4142 | |
Pekka Paalanen | b502654 | 2014-11-12 15:09:24 +0200 | [diff] [blame] | 4143 | set_type(shsurf, SHELL_SURFACE_POPUP); |
Rafael Antognolli | e2a3455 | 2013-12-03 15:35:45 -0200 | [diff] [blame] | 4144 | shsurf->popup.shseat = seat; |
| 4145 | shsurf->popup.serial = serial; |
| 4146 | shsurf->popup.x = x; |
| 4147 | shsurf->popup.y = y; |
| 4148 | shell_surface_set_parent(shsurf, parent); |
| 4149 | |
| 4150 | return shsurf; |
| 4151 | } |
| 4152 | |
| 4153 | static void |
| 4154 | xdg_get_xdg_popup(struct wl_client *client, |
| 4155 | struct wl_resource *resource, |
| 4156 | uint32_t id, |
| 4157 | struct wl_resource *surface_resource, |
| 4158 | struct wl_resource *parent_resource, |
| 4159 | struct wl_resource *seat_resource, |
| 4160 | uint32_t serial, |
Jasper St. Pierre | 14f330c | 2015-02-13 14:01:57 +0800 | [diff] [blame] | 4161 | int32_t x, int32_t y) |
Rafael Antognolli | e2a3455 | 2013-12-03 15:35:45 -0200 | [diff] [blame] | 4162 | { |
| 4163 | struct weston_surface *surface = |
| 4164 | wl_resource_get_user_data(surface_resource); |
Kristian Høgsberg | 2bff94e | 2014-02-11 12:22:51 -0800 | [diff] [blame] | 4165 | struct shell_client *sc = wl_resource_get_user_data(resource); |
| 4166 | struct desktop_shell *shell = sc->shell; |
Rafael Antognolli | e2a3455 | 2013-12-03 15:35:45 -0200 | [diff] [blame] | 4167 | struct shell_surface *shsurf; |
Jonas Ådahl | ee45a55 | 2015-03-18 16:37:47 +0800 | [diff] [blame] | 4168 | struct shell_surface *parent_shsurf; |
Rafael Antognolli | e2a3455 | 2013-12-03 15:35:45 -0200 | [diff] [blame] | 4169 | struct weston_surface *parent; |
| 4170 | struct shell_seat *seat; |
| 4171 | |
Jonas Ådahl | bf48e21 | 2015-02-06 10:15:28 +0800 | [diff] [blame] | 4172 | shsurf = get_shell_surface(surface); |
| 4173 | if (shsurf && shell_surface_is_xdg_popup(shsurf)) { |
| 4174 | wl_resource_post_error(resource, XDG_SHELL_ERROR_ROLE, |
| 4175 | "This wl_surface is already an " |
| 4176 | "xdg_popup"); |
| 4177 | return; |
| 4178 | } |
| 4179 | |
Pekka Paalanen | 50b6747 | 2014-10-01 15:02:41 +0300 | [diff] [blame] | 4180 | if (weston_surface_set_role(surface, "xdg_popup", |
| 4181 | resource, XDG_SHELL_ERROR_ROLE) < 0) |
Rafael Antognolli | e2a3455 | 2013-12-03 15:35:45 -0200 | [diff] [blame] | 4182 | return; |
Rafael Antognolli | e2a3455 | 2013-12-03 15:35:45 -0200 | [diff] [blame] | 4183 | |
| 4184 | if (!parent_resource) { |
| 4185 | wl_resource_post_error(surface_resource, |
| 4186 | WL_DISPLAY_ERROR_INVALID_OBJECT, |
| 4187 | "xdg_shell::get_xdg_popup requires a parent shell surface"); |
Jasper St. Pierre | 666bc92 | 2014-08-07 16:43:13 -0400 | [diff] [blame] | 4188 | return; |
Rafael Antognolli | e2a3455 | 2013-12-03 15:35:45 -0200 | [diff] [blame] | 4189 | } |
| 4190 | |
| 4191 | parent = wl_resource_get_user_data(parent_resource); |
Derek Foreman | bdc8c72 | 2015-10-07 11:51:29 -0500 | [diff] [blame] | 4192 | seat = get_shell_seat(wl_resource_get_user_data(seat_resource)); |
Rafael Antognolli | e2a3455 | 2013-12-03 15:35:45 -0200 | [diff] [blame] | 4193 | |
Jonas Ådahl | ee45a55 | 2015-03-18 16:37:47 +0800 | [diff] [blame] | 4194 | /* Verify that we are creating the top most popup when mapping, |
| 4195 | * as it's not until then we know whether it was mapped as most |
| 4196 | * top level or not. */ |
| 4197 | |
| 4198 | parent_shsurf = get_shell_surface(parent); |
Jonas Ådahl | bc5d849 | 2015-10-07 14:44:50 +0800 | [diff] [blame] | 4199 | if (!parent_shsurf || |
| 4200 | (!shell_surface_is_xdg_popup(parent_shsurf) && |
| 4201 | !shell_surface_is_xdg_surface(parent_shsurf))) { |
Jonas Ådahl | ee45a55 | 2015-03-18 16:37:47 +0800 | [diff] [blame] | 4202 | wl_resource_post_error(resource, |
| 4203 | XDG_SHELL_ERROR_INVALID_POPUP_PARENT, |
| 4204 | "xdg_popup parent was invalid"); |
| 4205 | return; |
| 4206 | } |
| 4207 | |
Jason Ekstrand | 9e9512f | 2014-04-16 21:12:10 -0500 | [diff] [blame] | 4208 | shsurf = create_xdg_popup(sc, shell, surface, &xdg_popup_client, |
Rafael Antognolli | e2a3455 | 2013-12-03 15:35:45 -0200 | [diff] [blame] | 4209 | parent, seat, serial, x, y); |
| 4210 | if (!shsurf) { |
Pekka Paalanen | 50b6747 | 2014-10-01 15:02:41 +0300 | [diff] [blame] | 4211 | wl_resource_post_no_memory(surface_resource); |
Rafael Antognolli | e2a3455 | 2013-12-03 15:35:45 -0200 | [diff] [blame] | 4212 | return; |
| 4213 | } |
| 4214 | |
| 4215 | shsurf->resource = |
| 4216 | wl_resource_create(client, |
| 4217 | &xdg_popup_interface, 1, id); |
| 4218 | wl_resource_set_implementation(shsurf->resource, |
| 4219 | &xdg_popup_implementation, |
| 4220 | shsurf, shell_destroy_shell_surface); |
Jonas Ådahl | 49d77d2 | 2015-03-18 16:20:51 +0800 | [diff] [blame] | 4221 | shsurf->owner_resource = resource; |
| 4222 | wl_list_insert(&sc->surface_list, |
| 4223 | wl_resource_get_link(shsurf->resource)); |
Rafael Antognolli | e2a3455 | 2013-12-03 15:35:45 -0200 | [diff] [blame] | 4224 | } |
| 4225 | |
Kristian Høgsberg | 2bff94e | 2014-02-11 12:22:51 -0800 | [diff] [blame] | 4226 | static void |
| 4227 | xdg_pong(struct wl_client *client, |
| 4228 | struct wl_resource *resource, uint32_t serial) |
| 4229 | { |
| 4230 | struct shell_client *sc = wl_resource_get_user_data(resource); |
Kristian Høgsberg | 2bff94e | 2014-02-11 12:22:51 -0800 | [diff] [blame] | 4231 | |
Kristian Høgsberg | dd62aba | 2014-02-12 09:56:19 -0800 | [diff] [blame] | 4232 | shell_client_pong(sc, serial); |
Kristian Høgsberg | 2bff94e | 2014-02-11 12:22:51 -0800 | [diff] [blame] | 4233 | } |
| 4234 | |
Rafael Antognolli | e2a3455 | 2013-12-03 15:35:45 -0200 | [diff] [blame] | 4235 | static bool |
| 4236 | shell_surface_is_xdg_popup(struct shell_surface *shsurf) |
| 4237 | { |
| 4238 | return wl_resource_instance_of(shsurf->resource, |
| 4239 | &xdg_popup_interface, |
| 4240 | &xdg_popup_implementation); |
| 4241 | } |
| 4242 | |
| 4243 | static const struct xdg_shell_interface xdg_implementation = { |
Jasper St. Pierre | 084aa0b | 2015-02-13 14:02:00 +0800 | [diff] [blame] | 4244 | xdg_shell_destroy, |
Rafael Antognolli | e2a3455 | 2013-12-03 15:35:45 -0200 | [diff] [blame] | 4245 | xdg_use_unstable_version, |
| 4246 | xdg_get_xdg_surface, |
Kristian Høgsberg | 2bff94e | 2014-02-11 12:22:51 -0800 | [diff] [blame] | 4247 | xdg_get_xdg_popup, |
| 4248 | xdg_pong |
Rafael Antognolli | e2a3455 | 2013-12-03 15:35:45 -0200 | [diff] [blame] | 4249 | }; |
| 4250 | |
| 4251 | static int |
| 4252 | xdg_shell_unversioned_dispatch(const void *implementation, |
| 4253 | void *_target, uint32_t opcode, |
| 4254 | const struct wl_message *message, |
| 4255 | union wl_argument *args) |
| 4256 | { |
| 4257 | struct wl_resource *resource = _target; |
Kristian Høgsberg | 2bff94e | 2014-02-11 12:22:51 -0800 | [diff] [blame] | 4258 | struct shell_client *sc = wl_resource_get_user_data(resource); |
Rafael Antognolli | e2a3455 | 2013-12-03 15:35:45 -0200 | [diff] [blame] | 4259 | |
Jasper St. Pierre | 084aa0b | 2015-02-13 14:02:00 +0800 | [diff] [blame] | 4260 | if (opcode != 1 /* XDG_SHELL_USE_UNSTABLE_VERSION */) { |
Rafael Antognolli | e2a3455 | 2013-12-03 15:35:45 -0200 | [diff] [blame] | 4261 | wl_resource_post_error(resource, |
| 4262 | WL_DISPLAY_ERROR_INVALID_OBJECT, |
| 4263 | "must call use_unstable_version first"); |
| 4264 | return 0; |
| 4265 | } |
| 4266 | |
Jasper St. Pierre | 5ba1e1d | 2015-02-13 14:02:02 +0800 | [diff] [blame] | 4267 | #define XDG_SERVER_VERSION 5 |
Rafael Antognolli | e2a3455 | 2013-12-03 15:35:45 -0200 | [diff] [blame] | 4268 | |
Kristian Høgsberg | 8d344a0 | 2013-12-08 22:27:11 -0800 | [diff] [blame] | 4269 | static_assert(XDG_SERVER_VERSION == XDG_SHELL_VERSION_CURRENT, |
| 4270 | "shell implementation doesn't match protocol version"); |
| 4271 | |
Rafael Antognolli | e2a3455 | 2013-12-03 15:35:45 -0200 | [diff] [blame] | 4272 | if (args[0].i != XDG_SERVER_VERSION) { |
| 4273 | wl_resource_post_error(resource, |
| 4274 | WL_DISPLAY_ERROR_INVALID_OBJECT, |
| 4275 | "incompatible version, server is %d " |
| 4276 | "client wants %d", |
| 4277 | XDG_SERVER_VERSION, args[0].i); |
| 4278 | return 0; |
| 4279 | } |
| 4280 | |
| 4281 | wl_resource_set_implementation(resource, &xdg_implementation, |
Kristian Høgsberg | 2bff94e | 2014-02-11 12:22:51 -0800 | [diff] [blame] | 4282 | sc, NULL); |
Rafael Antognolli | e2a3455 | 2013-12-03 15:35:45 -0200 | [diff] [blame] | 4283 | |
| 4284 | return 1; |
| 4285 | } |
| 4286 | |
| 4287 | /* end of xdg-shell implementation */ |
| 4288 | /***********************************/ |
| 4289 | |
Kristian Høgsberg | 0793756 | 2011-04-12 17:25:42 -0400 | [diff] [blame] | 4290 | static void |
Ander Conselvan de Oliveira | 859e885 | 2013-02-21 18:35:21 +0200 | [diff] [blame] | 4291 | shell_fade(struct desktop_shell *shell, enum fade_type type); |
| 4292 | |
Pekka Paalanen | 77346a6 | 2011-11-30 16:26:35 +0200 | [diff] [blame] | 4293 | static void |
Jason Ekstrand | 918f2dd | 2013-12-02 21:01:53 -0600 | [diff] [blame] | 4294 | configure_static_view(struct weston_view *ev, struct weston_layer *layer) |
Kristian Høgsberg | 962342c | 2012-06-26 16:29:50 -0400 | [diff] [blame] | 4295 | { |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 4296 | struct weston_view *v, *next; |
Kristian Høgsberg | 962342c | 2012-06-26 16:29:50 -0400 | [diff] [blame] | 4297 | |
Giulio Camuffo | 412e6a5 | 2014-07-09 22:12:56 +0300 | [diff] [blame] | 4298 | 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] | 4299 | if (v->output == ev->output && v != ev) { |
| 4300 | weston_view_unmap(v); |
| 4301 | v->surface->configure = NULL; |
Pekka Paalanen | 8274d90 | 2014-08-06 19:36:51 +0300 | [diff] [blame] | 4302 | weston_surface_set_label_func(v->surface, NULL); |
Kristian Høgsberg | 962342c | 2012-06-26 16:29:50 -0400 | [diff] [blame] | 4303 | } |
| 4304 | } |
| 4305 | |
Jason Ekstrand | 918f2dd | 2013-12-02 21:01:53 -0600 | [diff] [blame] | 4306 | weston_view_set_position(ev, ev->output->x, ev->output->y); |
Kristian Høgsberg | 962342c | 2012-06-26 16:29:50 -0400 | [diff] [blame] | 4307 | |
Giulio Camuffo | 412e6a5 | 2014-07-09 22:12:56 +0300 | [diff] [blame] | 4308 | if (wl_list_empty(&ev->layer_link.link)) { |
| 4309 | weston_layer_entry_insert(&layer->view_list, &ev->layer_link); |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 4310 | weston_compositor_schedule_repaint(ev->surface->compositor); |
Kristian Høgsberg | 962342c | 2012-06-26 16:29:50 -0400 | [diff] [blame] | 4311 | } |
| 4312 | } |
| 4313 | |
Pekka Paalanen | 8274d90 | 2014-08-06 19:36:51 +0300 | [diff] [blame] | 4314 | static int |
| 4315 | background_get_label(struct weston_surface *surface, char *buf, size_t len) |
| 4316 | { |
| 4317 | return snprintf(buf, len, "background for output %s", |
| 4318 | surface->output->name); |
| 4319 | } |
| 4320 | |
Kristian Høgsberg | 962342c | 2012-06-26 16:29:50 -0400 | [diff] [blame] | 4321 | static void |
Jason Ekstrand | 918f2dd | 2013-12-02 21:01:53 -0600 | [diff] [blame] | 4322 | 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] | 4323 | { |
Giulio Camuffo | 7fe01b1 | 2013-03-28 18:02:42 +0100 | [diff] [blame] | 4324 | struct desktop_shell *shell = es->configure_private; |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 4325 | struct weston_view *view; |
Kristian Høgsberg | af7b1ff | 2012-06-26 21:19:23 -0400 | [diff] [blame] | 4326 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 4327 | view = container_of(es->views.next, struct weston_view, surface_link); |
| 4328 | |
Jason Ekstrand | 918f2dd | 2013-12-02 21:01:53 -0600 | [diff] [blame] | 4329 | configure_static_view(view, &shell->background_layer); |
Kristian Høgsberg | af7b1ff | 2012-06-26 21:19:23 -0400 | [diff] [blame] | 4330 | } |
| 4331 | |
| 4332 | static void |
Kristian Høgsberg | 7584062 | 2011-09-06 13:48:16 -0400 | [diff] [blame] | 4333 | desktop_shell_set_background(struct wl_client *client, |
| 4334 | struct wl_resource *resource, |
Benjamin Franzke | d0f79ab | 2011-11-22 12:43:52 +0100 | [diff] [blame] | 4335 | struct wl_resource *output_resource, |
Kristian Høgsberg | 7584062 | 2011-09-06 13:48:16 -0400 | [diff] [blame] | 4336 | struct wl_resource *surface_resource) |
| 4337 | { |
Jason Ekstrand | 651f00e | 2013-06-14 10:07:54 -0500 | [diff] [blame] | 4338 | struct desktop_shell *shell = wl_resource_get_user_data(resource); |
Jason Ekstrand | 0f2ef7e | 2013-06-14 10:07:53 -0500 | [diff] [blame] | 4339 | struct weston_surface *surface = |
| 4340 | wl_resource_get_user_data(surface_resource); |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 4341 | struct weston_view *view, *next; |
Kristian Høgsberg | 7584062 | 2011-09-06 13:48:16 -0400 | [diff] [blame] | 4342 | |
Kristian Høgsberg | 962342c | 2012-06-26 16:29:50 -0400 | [diff] [blame] | 4343 | if (surface->configure) { |
| 4344 | wl_resource_post_error(surface_resource, |
| 4345 | WL_DISPLAY_ERROR_INVALID_OBJECT, |
| 4346 | "surface role already assigned"); |
| 4347 | return; |
| 4348 | } |
Benjamin Franzke | d0f79ab | 2011-11-22 12:43:52 +0100 | [diff] [blame] | 4349 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 4350 | wl_list_for_each_safe(view, next, &surface->views, surface_link) |
| 4351 | weston_view_destroy(view); |
| 4352 | view = weston_view_create(surface); |
| 4353 | |
Kristian Høgsberg | 962342c | 2012-06-26 16:29:50 -0400 | [diff] [blame] | 4354 | surface->configure = background_configure; |
Giulio Camuffo | 7fe01b1 | 2013-03-28 18:02:42 +0100 | [diff] [blame] | 4355 | surface->configure_private = shell; |
Pekka Paalanen | 8274d90 | 2014-08-06 19:36:51 +0300 | [diff] [blame] | 4356 | weston_surface_set_label_func(surface, background_get_label); |
Jason Ekstrand | a0d2dde | 2013-06-14 10:08:01 -0500 | [diff] [blame] | 4357 | surface->output = wl_resource_get_user_data(output_resource); |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 4358 | view->output = surface->output; |
Jonas Ådahl | 6d6fb61 | 2015-11-17 16:00:33 +0800 | [diff] [blame] | 4359 | weston_desktop_shell_send_configure(resource, 0, |
| 4360 | surface_resource, |
| 4361 | surface->output->width, |
| 4362 | surface->output->height); |
Kristian Høgsberg | 7584062 | 2011-09-06 13:48:16 -0400 | [diff] [blame] | 4363 | } |
| 4364 | |
Pekka Paalanen | 8274d90 | 2014-08-06 19:36:51 +0300 | [diff] [blame] | 4365 | static int |
| 4366 | panel_get_label(struct weston_surface *surface, char *buf, size_t len) |
| 4367 | { |
| 4368 | return snprintf(buf, len, "panel for output %s", |
| 4369 | surface->output->name); |
| 4370 | } |
| 4371 | |
Kristian Høgsberg | 7584062 | 2011-09-06 13:48:16 -0400 | [diff] [blame] | 4372 | static void |
Jason Ekstrand | 918f2dd | 2013-12-02 21:01:53 -0600 | [diff] [blame] | 4373 | 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] | 4374 | { |
Giulio Camuffo | 7fe01b1 | 2013-03-28 18:02:42 +0100 | [diff] [blame] | 4375 | struct desktop_shell *shell = es->configure_private; |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 4376 | struct weston_view *view; |
Kristian Høgsberg | af7b1ff | 2012-06-26 21:19:23 -0400 | [diff] [blame] | 4377 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 4378 | view = container_of(es->views.next, struct weston_view, surface_link); |
| 4379 | |
Jason Ekstrand | 918f2dd | 2013-12-02 21:01:53 -0600 | [diff] [blame] | 4380 | configure_static_view(view, &shell->panel_layer); |
Kristian Høgsberg | af7b1ff | 2012-06-26 21:19:23 -0400 | [diff] [blame] | 4381 | } |
| 4382 | |
| 4383 | static void |
Kristian Høgsberg | 7584062 | 2011-09-06 13:48:16 -0400 | [diff] [blame] | 4384 | desktop_shell_set_panel(struct wl_client *client, |
| 4385 | struct wl_resource *resource, |
Benjamin Franzke | d0f79ab | 2011-11-22 12:43:52 +0100 | [diff] [blame] | 4386 | struct wl_resource *output_resource, |
Kristian Høgsberg | 7584062 | 2011-09-06 13:48:16 -0400 | [diff] [blame] | 4387 | struct wl_resource *surface_resource) |
| 4388 | { |
Jason Ekstrand | 651f00e | 2013-06-14 10:07:54 -0500 | [diff] [blame] | 4389 | struct desktop_shell *shell = wl_resource_get_user_data(resource); |
Jason Ekstrand | 0f2ef7e | 2013-06-14 10:07:53 -0500 | [diff] [blame] | 4390 | struct weston_surface *surface = |
| 4391 | wl_resource_get_user_data(surface_resource); |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 4392 | struct weston_view *view, *next; |
Kristian Høgsberg | 7584062 | 2011-09-06 13:48:16 -0400 | [diff] [blame] | 4393 | |
Kristian Høgsberg | af7b1ff | 2012-06-26 21:19:23 -0400 | [diff] [blame] | 4394 | if (surface->configure) { |
| 4395 | wl_resource_post_error(surface_resource, |
| 4396 | WL_DISPLAY_ERROR_INVALID_OBJECT, |
| 4397 | "surface role already assigned"); |
| 4398 | return; |
| 4399 | } |
Benjamin Franzke | d0f79ab | 2011-11-22 12:43:52 +0100 | [diff] [blame] | 4400 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 4401 | wl_list_for_each_safe(view, next, &surface->views, surface_link) |
| 4402 | weston_view_destroy(view); |
| 4403 | view = weston_view_create(surface); |
| 4404 | |
Kristian Høgsberg | af7b1ff | 2012-06-26 21:19:23 -0400 | [diff] [blame] | 4405 | surface->configure = panel_configure; |
Giulio Camuffo | 7fe01b1 | 2013-03-28 18:02:42 +0100 | [diff] [blame] | 4406 | surface->configure_private = shell; |
Pekka Paalanen | 8274d90 | 2014-08-06 19:36:51 +0300 | [diff] [blame] | 4407 | weston_surface_set_label_func(surface, panel_get_label); |
Jason Ekstrand | a0d2dde | 2013-06-14 10:08:01 -0500 | [diff] [blame] | 4408 | surface->output = wl_resource_get_user_data(output_resource); |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 4409 | view->output = surface->output; |
Jonas Ådahl | 6d6fb61 | 2015-11-17 16:00:33 +0800 | [diff] [blame] | 4410 | weston_desktop_shell_send_configure(resource, 0, |
| 4411 | surface_resource, |
| 4412 | surface->output->width, |
| 4413 | surface->output->height); |
Kristian Høgsberg | 7584062 | 2011-09-06 13:48:16 -0400 | [diff] [blame] | 4414 | } |
| 4415 | |
Pekka Paalanen | 8274d90 | 2014-08-06 19:36:51 +0300 | [diff] [blame] | 4416 | static int |
| 4417 | lock_surface_get_label(struct weston_surface *surface, char *buf, size_t len) |
| 4418 | { |
| 4419 | return snprintf(buf, len, "lock window"); |
| 4420 | } |
| 4421 | |
Pekka Paalanen | 9ef3e01 | 2011-11-15 13:34:48 +0200 | [diff] [blame] | 4422 | static void |
Jason Ekstrand | 918f2dd | 2013-12-02 21:01:53 -0600 | [diff] [blame] | 4423 | 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] | 4424 | { |
Giulio Camuffo | 7fe01b1 | 2013-03-28 18:02:42 +0100 | [diff] [blame] | 4425 | struct desktop_shell *shell = surface->configure_private; |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 4426 | struct weston_view *view; |
| 4427 | |
| 4428 | view = container_of(surface->views.next, struct weston_view, surface_link); |
Kristian Høgsberg | 730c94d | 2012-06-26 21:44:35 -0400 | [diff] [blame] | 4429 | |
Jason Ekstrand | 918f2dd | 2013-12-02 21:01:53 -0600 | [diff] [blame] | 4430 | if (surface->width == 0) |
Giulio Camuffo | 184df50 | 2013-02-21 11:29:21 +0100 | [diff] [blame] | 4431 | return; |
| 4432 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 4433 | center_on_output(view, get_default_output(shell->compositor)); |
Kristian Høgsberg | 730c94d | 2012-06-26 21:44:35 -0400 | [diff] [blame] | 4434 | |
| 4435 | if (!weston_surface_is_mapped(surface)) { |
Giulio Camuffo | 412e6a5 | 2014-07-09 22:12:56 +0300 | [diff] [blame] | 4436 | weston_layer_entry_insert(&shell->lock_layer.view_list, |
| 4437 | &view->layer_link); |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 4438 | weston_view_update_transform(view); |
Ander Conselvan de Oliveira | 87524b6 | 2013-02-21 18:35:22 +0200 | [diff] [blame] | 4439 | shell_fade(shell, FADE_IN); |
Kristian Høgsberg | 730c94d | 2012-06-26 21:44:35 -0400 | [diff] [blame] | 4440 | } |
| 4441 | } |
| 4442 | |
| 4443 | static void |
Kristian Høgsberg | 27e3052 | 2012-04-11 23:18:23 -0400 | [diff] [blame] | 4444 | handle_lock_surface_destroy(struct wl_listener *listener, void *data) |
Kristian Høgsberg | 1ec0c31 | 2011-11-15 16:39:55 -0500 | [diff] [blame] | 4445 | { |
Tiago Vignatti | be14326 | 2012-04-16 17:31:41 +0300 | [diff] [blame] | 4446 | struct desktop_shell *shell = |
| 4447 | container_of(listener, struct desktop_shell, lock_surface_listener); |
Kristian Høgsberg | 1ec0c31 | 2011-11-15 16:39:55 -0500 | [diff] [blame] | 4448 | |
Martin Minarik | 6d11836 | 2012-06-07 18:01:59 +0200 | [diff] [blame] | 4449 | weston_log("lock surface gone\n"); |
Kristian Høgsberg | 1ec0c31 | 2011-11-15 16:39:55 -0500 | [diff] [blame] | 4450 | shell->lock_surface = NULL; |
| 4451 | } |
| 4452 | |
| 4453 | static void |
Pekka Paalanen | 9ef3e01 | 2011-11-15 13:34:48 +0200 | [diff] [blame] | 4454 | desktop_shell_set_lock_surface(struct wl_client *client, |
| 4455 | struct wl_resource *resource, |
| 4456 | struct wl_resource *surface_resource) |
| 4457 | { |
Jason Ekstrand | 651f00e | 2013-06-14 10:07:54 -0500 | [diff] [blame] | 4458 | struct desktop_shell *shell = wl_resource_get_user_data(resource); |
Jason Ekstrand | 0f2ef7e | 2013-06-14 10:07:53 -0500 | [diff] [blame] | 4459 | struct weston_surface *surface = |
| 4460 | wl_resource_get_user_data(surface_resource); |
Pekka Paalanen | 9826223 | 2011-12-01 10:42:22 +0200 | [diff] [blame] | 4461 | |
Pekka Paalanen | f0fc70d | 2011-11-15 13:34:54 +0200 | [diff] [blame] | 4462 | shell->prepare_event_sent = false; |
Kristian Høgsberg | af867cc | 2011-11-15 13:34:49 +0200 | [diff] [blame] | 4463 | |
Pekka Paalanen | f0fc70d | 2011-11-15 13:34:54 +0200 | [diff] [blame] | 4464 | if (!shell->locked) |
| 4465 | return; |
| 4466 | |
Pekka Paalanen | 9826223 | 2011-12-01 10:42:22 +0200 | [diff] [blame] | 4467 | shell->lock_surface = surface; |
Pekka Paalanen | f0fc70d | 2011-11-15 13:34:54 +0200 | [diff] [blame] | 4468 | |
Kristian Høgsberg | 27e3052 | 2012-04-11 23:18:23 -0400 | [diff] [blame] | 4469 | shell->lock_surface_listener.notify = handle_lock_surface_destroy; |
Jason Ekstrand | 651f00e | 2013-06-14 10:07:54 -0500 | [diff] [blame] | 4470 | wl_signal_add(&surface->destroy_signal, |
Kristian Høgsberg | 27e3052 | 2012-04-11 23:18:23 -0400 | [diff] [blame] | 4471 | &shell->lock_surface_listener); |
Pekka Paalanen | 57da4a8 | 2011-11-23 16:42:16 +0200 | [diff] [blame] | 4472 | |
Kristian Høgsberg | aa2ee8b | 2013-10-30 15:49:45 -0700 | [diff] [blame] | 4473 | weston_view_create(surface); |
Kristian Høgsberg | 730c94d | 2012-06-26 21:44:35 -0400 | [diff] [blame] | 4474 | surface->configure = lock_surface_configure; |
Giulio Camuffo | 7fe01b1 | 2013-03-28 18:02:42 +0100 | [diff] [blame] | 4475 | surface->configure_private = shell; |
Pekka Paalanen | 8274d90 | 2014-08-06 19:36:51 +0300 | [diff] [blame] | 4476 | weston_surface_set_label_func(surface, lock_surface_get_label); |
Pekka Paalanen | f0fc70d | 2011-11-15 13:34:54 +0200 | [diff] [blame] | 4477 | } |
| 4478 | |
| 4479 | static void |
Tiago Vignatti | be14326 | 2012-04-16 17:31:41 +0300 | [diff] [blame] | 4480 | resume_desktop(struct desktop_shell *shell) |
Pekka Paalanen | f0fc70d | 2011-11-15 13:34:54 +0200 | [diff] [blame] | 4481 | { |
Kristian Høgsberg | 4476aaf | 2012-06-25 14:03:13 -0400 | [diff] [blame] | 4482 | struct workspace *ws = get_current_workspace(shell); |
Pekka Paalanen | 77346a6 | 2011-11-30 16:26:35 +0200 | [diff] [blame] | 4483 | |
Kristian Høgsberg | 3be2ce9 | 2012-02-29 12:42:35 -0500 | [diff] [blame] | 4484 | wl_list_remove(&shell->lock_layer.link); |
Philipp Brüschweiler | 711fda8 | 2012-08-09 18:50:43 +0200 | [diff] [blame] | 4485 | if (shell->showing_input_panels) { |
Manuel Bachmann | 805d2f5 | 2014-03-05 12:21:34 +0100 | [diff] [blame] | 4486 | wl_list_insert(&shell->compositor->cursor_layer.link, |
Philipp Brüschweiler | 711fda8 | 2012-08-09 18:50:43 +0200 | [diff] [blame] | 4487 | &shell->input_panel_layer.link); |
| 4488 | wl_list_insert(&shell->input_panel_layer.link, |
Manuel Bachmann | 805d2f5 | 2014-03-05 12:21:34 +0100 | [diff] [blame] | 4489 | &shell->fullscreen_layer.link); |
Philipp Brüschweiler | 711fda8 | 2012-08-09 18:50:43 +0200 | [diff] [blame] | 4490 | } else { |
Manuel Bachmann | 805d2f5 | 2014-03-05 12:21:34 +0100 | [diff] [blame] | 4491 | wl_list_insert(&shell->compositor->cursor_layer.link, |
| 4492 | &shell->fullscreen_layer.link); |
Philipp Brüschweiler | 711fda8 | 2012-08-09 18:50:43 +0200 | [diff] [blame] | 4493 | } |
Manuel Bachmann | 805d2f5 | 2014-03-05 12:21:34 +0100 | [diff] [blame] | 4494 | wl_list_insert(&shell->fullscreen_layer.link, |
| 4495 | &shell->panel_layer.link); |
| 4496 | wl_list_insert(&shell->panel_layer.link, |
| 4497 | &ws->layer.link), |
Pekka Paalanen | f0fc70d | 2011-11-15 13:34:54 +0200 | [diff] [blame] | 4498 | |
Kristian Høgsberg | 2f5faff | 2012-07-31 16:36:34 -0400 | [diff] [blame] | 4499 | restore_focus_state(shell, get_current_workspace(shell)); |
Jonas Ådahl | 0476974 | 2012-06-13 00:01:24 +0200 | [diff] [blame] | 4500 | |
Pekka Paalanen | f0fc70d | 2011-11-15 13:34:54 +0200 | [diff] [blame] | 4501 | shell->locked = false; |
Ander Conselvan de Oliveira | 87524b6 | 2013-02-21 18:35:22 +0200 | [diff] [blame] | 4502 | shell_fade(shell, FADE_IN); |
Pekka Paalanen | fc6d91a | 2012-02-10 15:33:10 +0200 | [diff] [blame] | 4503 | weston_compositor_damage_all(shell->compositor); |
Pekka Paalanen | 9ef3e01 | 2011-11-15 13:34:48 +0200 | [diff] [blame] | 4504 | } |
| 4505 | |
| 4506 | static void |
| 4507 | desktop_shell_unlock(struct wl_client *client, |
| 4508 | struct wl_resource *resource) |
| 4509 | { |
Jason Ekstrand | 651f00e | 2013-06-14 10:07:54 -0500 | [diff] [blame] | 4510 | struct desktop_shell *shell = wl_resource_get_user_data(resource); |
Pekka Paalanen | 9ef3e01 | 2011-11-15 13:34:48 +0200 | [diff] [blame] | 4511 | |
Pekka Paalanen | 9ef3e01 | 2011-11-15 13:34:48 +0200 | [diff] [blame] | 4512 | shell->prepare_event_sent = false; |
Pekka Paalanen | f0fc70d | 2011-11-15 13:34:54 +0200 | [diff] [blame] | 4513 | |
| 4514 | if (shell->locked) |
| 4515 | resume_desktop(shell); |
Pekka Paalanen | 9ef3e01 | 2011-11-15 13:34:48 +0200 | [diff] [blame] | 4516 | } |
| 4517 | |
Kristian Høgsberg | d56bd90 | 2012-06-05 09:58:51 -0400 | [diff] [blame] | 4518 | static void |
Ander Conselvan de Oliveira | b9d2a0f | 2012-06-28 18:08:05 +0300 | [diff] [blame] | 4519 | desktop_shell_set_grab_surface(struct wl_client *client, |
Kristian Høgsberg | d56bd90 | 2012-06-05 09:58:51 -0400 | [diff] [blame] | 4520 | struct wl_resource *resource, |
| 4521 | struct wl_resource *surface_resource) |
| 4522 | { |
Jason Ekstrand | 651f00e | 2013-06-14 10:07:54 -0500 | [diff] [blame] | 4523 | struct desktop_shell *shell = wl_resource_get_user_data(resource); |
Kristian Høgsberg | d56bd90 | 2012-06-05 09:58:51 -0400 | [diff] [blame] | 4524 | |
Jason Ekstrand | 0f2ef7e | 2013-06-14 10:07:53 -0500 | [diff] [blame] | 4525 | shell->grab_surface = wl_resource_get_user_data(surface_resource); |
Kristian Høgsberg | 48588f8 | 2013-10-24 15:51:35 -0700 | [diff] [blame] | 4526 | weston_view_create(shell->grab_surface); |
Kristian Høgsberg | d56bd90 | 2012-06-05 09:58:51 -0400 | [diff] [blame] | 4527 | } |
| 4528 | |
Pekka Paalanen | 79346ab | 2013-05-22 18:03:09 +0300 | [diff] [blame] | 4529 | static void |
| 4530 | desktop_shell_desktop_ready(struct wl_client *client, |
| 4531 | struct wl_resource *resource) |
| 4532 | { |
Jason Ekstrand | 651f00e | 2013-06-14 10:07:54 -0500 | [diff] [blame] | 4533 | struct desktop_shell *shell = wl_resource_get_user_data(resource); |
Pekka Paalanen | 79346ab | 2013-05-22 18:03:09 +0300 | [diff] [blame] | 4534 | |
| 4535 | shell_fade_startup(shell); |
| 4536 | } |
| 4537 | |
Jonny Lamb | 765760d | 2014-08-20 15:53:19 +0200 | [diff] [blame] | 4538 | static void |
| 4539 | desktop_shell_set_panel_position(struct wl_client *client, |
| 4540 | struct wl_resource *resource, |
| 4541 | uint32_t position) |
| 4542 | { |
| 4543 | struct desktop_shell *shell = wl_resource_get_user_data(resource); |
| 4544 | |
Jonas Ådahl | 6d6fb61 | 2015-11-17 16:00:33 +0800 | [diff] [blame] | 4545 | if (position != WESTON_DESKTOP_SHELL_PANEL_POSITION_TOP && |
| 4546 | position != WESTON_DESKTOP_SHELL_PANEL_POSITION_BOTTOM && |
| 4547 | position != WESTON_DESKTOP_SHELL_PANEL_POSITION_LEFT && |
| 4548 | position != WESTON_DESKTOP_SHELL_PANEL_POSITION_RIGHT) { |
Jonny Lamb | 765760d | 2014-08-20 15:53:19 +0200 | [diff] [blame] | 4549 | wl_resource_post_error(resource, |
Jonas Ådahl | 6d6fb61 | 2015-11-17 16:00:33 +0800 | [diff] [blame] | 4550 | WESTON_DESKTOP_SHELL_ERROR_INVALID_ARGUMENT, |
Jonny Lamb | 765760d | 2014-08-20 15:53:19 +0200 | [diff] [blame] | 4551 | "bad position argument"); |
| 4552 | return; |
| 4553 | } |
| 4554 | |
| 4555 | shell->panel_position = position; |
| 4556 | } |
| 4557 | |
Jonas Ådahl | 6d6fb61 | 2015-11-17 16:00:33 +0800 | [diff] [blame] | 4558 | static const struct weston_desktop_shell_interface desktop_shell_implementation = { |
Kristian Høgsberg | 7584062 | 2011-09-06 13:48:16 -0400 | [diff] [blame] | 4559 | desktop_shell_set_background, |
Pekka Paalanen | 9ef3e01 | 2011-11-15 13:34:48 +0200 | [diff] [blame] | 4560 | desktop_shell_set_panel, |
| 4561 | desktop_shell_set_lock_surface, |
Kristian Høgsberg | d56bd90 | 2012-06-05 09:58:51 -0400 | [diff] [blame] | 4562 | desktop_shell_unlock, |
Pekka Paalanen | 79346ab | 2013-05-22 18:03:09 +0300 | [diff] [blame] | 4563 | desktop_shell_set_grab_surface, |
Jonny Lamb | 765760d | 2014-08-20 15:53:19 +0200 | [diff] [blame] | 4564 | desktop_shell_desktop_ready, |
| 4565 | desktop_shell_set_panel_position |
Kristian Høgsberg | 7584062 | 2011-09-06 13:48:16 -0400 | [diff] [blame] | 4566 | }; |
| 4567 | |
Pekka Paalanen | 92a0dc4 | 2011-11-28 15:34:13 +0200 | [diff] [blame] | 4568 | static enum shell_surface_type |
Kristian Høgsberg | 8334bc1 | 2012-01-03 10:29:47 -0500 | [diff] [blame] | 4569 | get_shell_surface_type(struct weston_surface *surface) |
Pekka Paalanen | 92a0dc4 | 2011-11-28 15:34:13 +0200 | [diff] [blame] | 4570 | { |
| 4571 | struct shell_surface *shsurf; |
| 4572 | |
| 4573 | shsurf = get_shell_surface(surface); |
| 4574 | if (!shsurf) |
Pekka Paalanen | 9826223 | 2011-12-01 10:42:22 +0200 | [diff] [blame] | 4575 | return SHELL_SURFACE_NONE; |
Pekka Paalanen | 92a0dc4 | 2011-11-28 15:34:13 +0200 | [diff] [blame] | 4576 | return shsurf->type; |
| 4577 | } |
| 4578 | |
Kristian Høgsberg | 7584062 | 2011-09-06 13:48:16 -0400 | [diff] [blame] | 4579 | static void |
Derek Foreman | 8ae2db5 | 2015-07-15 13:00:36 -0500 | [diff] [blame] | 4580 | move_binding(struct weston_pointer *pointer, uint32_t time, |
| 4581 | uint32_t button, void *data) |
Kristian Høgsberg | 0793756 | 2011-04-12 17:25:42 -0400 | [diff] [blame] | 4582 | { |
Rafal Mielniczuk | b2917a2 | 2014-01-05 20:04:59 +0100 | [diff] [blame] | 4583 | struct weston_surface *focus; |
Pekka Paalanen | 01388e2 | 2013-04-25 13:57:44 +0300 | [diff] [blame] | 4584 | struct weston_surface *surface; |
Kristian Høgsberg | 938b8fa | 2012-05-18 13:46:27 -0400 | [diff] [blame] | 4585 | struct shell_surface *shsurf; |
Kristian Høgsberg | d2abb83 | 2011-11-23 10:52:40 -0500 | [diff] [blame] | 4586 | |
Derek Foreman | 8ae2db5 | 2015-07-15 13:00:36 -0500 | [diff] [blame] | 4587 | if (pointer->focus == NULL) |
Rafal Mielniczuk | b2917a2 | 2014-01-05 20:04:59 +0100 | [diff] [blame] | 4588 | return; |
| 4589 | |
Derek Foreman | 8ae2db5 | 2015-07-15 13:00:36 -0500 | [diff] [blame] | 4590 | focus = pointer->focus->surface; |
Rafal Mielniczuk | b2917a2 | 2014-01-05 20:04:59 +0100 | [diff] [blame] | 4591 | |
Pekka Paalanen | 01388e2 | 2013-04-25 13:57:44 +0300 | [diff] [blame] | 4592 | surface = weston_surface_get_main_surface(focus); |
Benjamin Franzke | d0f79ab | 2011-11-22 12:43:52 +0100 | [diff] [blame] | 4593 | if (surface == NULL) |
| 4594 | return; |
Kristian Høgsberg | 0793756 | 2011-04-12 17:25:42 -0400 | [diff] [blame] | 4595 | |
Kristian Høgsberg | 938b8fa | 2012-05-18 13:46:27 -0400 | [diff] [blame] | 4596 | shsurf = get_shell_surface(surface); |
Rafael Antognolli | 03b1659 | 2013-12-03 15:35:42 -0200 | [diff] [blame] | 4597 | if (shsurf == NULL || shsurf->state.fullscreen || |
| 4598 | shsurf->state.maximized) |
Kristian Høgsberg | 938b8fa | 2012-05-18 13:46:27 -0400 | [diff] [blame] | 4599 | return; |
| 4600 | |
Derek Foreman | 794fa0e | 2015-07-15 13:00:38 -0500 | [diff] [blame] | 4601 | surface_move(shsurf, pointer, false); |
Kristian Høgsberg | 0793756 | 2011-04-12 17:25:42 -0400 | [diff] [blame] | 4602 | } |
| 4603 | |
| 4604 | static void |
Derek Foreman | 8ae2db5 | 2015-07-15 13:00:36 -0500 | [diff] [blame] | 4605 | maximize_binding(struct weston_keyboard *keyboard, uint32_t time, |
| 4606 | uint32_t button, void *data) |
Rafael Antognolli | ea997ac | 2013-12-03 15:35:48 -0200 | [diff] [blame] | 4607 | { |
Derek Foreman | 8ae2db5 | 2015-07-15 13:00:36 -0500 | [diff] [blame] | 4608 | struct weston_surface *focus = keyboard->focus; |
Rafael Antognolli | ea997ac | 2013-12-03 15:35:48 -0200 | [diff] [blame] | 4609 | struct weston_surface *surface; |
| 4610 | struct shell_surface *shsurf; |
| 4611 | |
| 4612 | surface = weston_surface_get_main_surface(focus); |
| 4613 | if (surface == NULL) |
| 4614 | return; |
| 4615 | |
| 4616 | shsurf = get_shell_surface(surface); |
| 4617 | if (shsurf == NULL) |
| 4618 | return; |
| 4619 | |
| 4620 | if (!shell_surface_is_xdg_surface(shsurf)) |
| 4621 | return; |
| 4622 | |
Jasper St. Pierre | ab2c108 | 2014-04-10 10:41:46 -0700 | [diff] [blame] | 4623 | shsurf->state_requested = true; |
| 4624 | shsurf->requested_state.maximized = !shsurf->state.maximized; |
Jasper St. Pierre | 9aa8ce6 | 2014-04-11 16:18:54 -0700 | [diff] [blame] | 4625 | send_configure_for_surface(shsurf); |
Rafael Antognolli | ea997ac | 2013-12-03 15:35:48 -0200 | [diff] [blame] | 4626 | } |
| 4627 | |
| 4628 | static void |
Derek Foreman | 8ae2db5 | 2015-07-15 13:00:36 -0500 | [diff] [blame] | 4629 | fullscreen_binding(struct weston_keyboard *keyboard, uint32_t time, |
| 4630 | uint32_t button, void *data) |
Rafael Antognolli | ea997ac | 2013-12-03 15:35:48 -0200 | [diff] [blame] | 4631 | { |
Derek Foreman | 8ae2db5 | 2015-07-15 13:00:36 -0500 | [diff] [blame] | 4632 | struct weston_surface *focus = keyboard->focus; |
Rafael Antognolli | ea997ac | 2013-12-03 15:35:48 -0200 | [diff] [blame] | 4633 | struct weston_surface *surface; |
| 4634 | struct shell_surface *shsurf; |
| 4635 | |
| 4636 | surface = weston_surface_get_main_surface(focus); |
| 4637 | if (surface == NULL) |
| 4638 | return; |
| 4639 | |
| 4640 | shsurf = get_shell_surface(surface); |
| 4641 | if (shsurf == NULL) |
| 4642 | return; |
| 4643 | |
| 4644 | if (!shell_surface_is_xdg_surface(shsurf)) |
| 4645 | return; |
| 4646 | |
Jasper St. Pierre | ab2c108 | 2014-04-10 10:41:46 -0700 | [diff] [blame] | 4647 | shsurf->state_requested = true; |
| 4648 | shsurf->requested_state.fullscreen = !shsurf->state.fullscreen; |
Boyan Ding | 32abdbb | 2014-06-26 10:19:32 +0800 | [diff] [blame] | 4649 | shsurf->fullscreen_output = shsurf->output; |
Jasper St. Pierre | 9aa8ce6 | 2014-04-11 16:18:54 -0700 | [diff] [blame] | 4650 | send_configure_for_surface(shsurf); |
Rafael Antognolli | ea997ac | 2013-12-03 15:35:48 -0200 | [diff] [blame] | 4651 | } |
| 4652 | |
| 4653 | static void |
Derek Foreman | 8ae2db5 | 2015-07-15 13:00:36 -0500 | [diff] [blame] | 4654 | touch_move_binding(struct weston_touch *touch, uint32_t time, void *data) |
Neil Roberts | aba0f25 | 2013-10-03 16:43:05 +0100 | [diff] [blame] | 4655 | { |
Derek Foreman | 362656b | 2014-09-04 10:23:05 -0500 | [diff] [blame] | 4656 | struct weston_surface *focus; |
Neil Roberts | aba0f25 | 2013-10-03 16:43:05 +0100 | [diff] [blame] | 4657 | struct weston_surface *surface; |
| 4658 | struct shell_surface *shsurf; |
| 4659 | |
Derek Foreman | 8ae2db5 | 2015-07-15 13:00:36 -0500 | [diff] [blame] | 4660 | if (touch->focus == NULL) |
Derek Foreman | 362656b | 2014-09-04 10:23:05 -0500 | [diff] [blame] | 4661 | return; |
| 4662 | |
Derek Foreman | 8ae2db5 | 2015-07-15 13:00:36 -0500 | [diff] [blame] | 4663 | focus = touch->focus->surface; |
Neil Roberts | aba0f25 | 2013-10-03 16:43:05 +0100 | [diff] [blame] | 4664 | surface = weston_surface_get_main_surface(focus); |
| 4665 | if (surface == NULL) |
| 4666 | return; |
| 4667 | |
| 4668 | shsurf = get_shell_surface(surface); |
Rafael Antognolli | 03b1659 | 2013-12-03 15:35:42 -0200 | [diff] [blame] | 4669 | if (shsurf == NULL || shsurf->state.fullscreen || |
| 4670 | shsurf->state.maximized) |
Neil Roberts | aba0f25 | 2013-10-03 16:43:05 +0100 | [diff] [blame] | 4671 | return; |
| 4672 | |
Derek Foreman | b7674ae | 2015-07-15 13:00:37 -0500 | [diff] [blame] | 4673 | surface_touch_move(shsurf, touch); |
Neil Roberts | aba0f25 | 2013-10-03 16:43:05 +0100 | [diff] [blame] | 4674 | } |
| 4675 | |
| 4676 | static void |
Derek Foreman | 8ae2db5 | 2015-07-15 13:00:36 -0500 | [diff] [blame] | 4677 | resize_binding(struct weston_pointer *pointer, uint32_t time, |
| 4678 | uint32_t button, void *data) |
Kristian Høgsberg | 0793756 | 2011-04-12 17:25:42 -0400 | [diff] [blame] | 4679 | { |
Rafal Mielniczuk | b2917a2 | 2014-01-05 20:04:59 +0100 | [diff] [blame] | 4680 | struct weston_surface *focus; |
Pekka Paalanen | 01388e2 | 2013-04-25 13:57:44 +0300 | [diff] [blame] | 4681 | struct weston_surface *surface; |
Kristian Høgsberg | 0793756 | 2011-04-12 17:25:42 -0400 | [diff] [blame] | 4682 | uint32_t edges = 0; |
| 4683 | int32_t x, y; |
Pekka Paalanen | 9d1613e | 2011-11-25 12:09:16 +0200 | [diff] [blame] | 4684 | struct shell_surface *shsurf; |
Kristian Høgsberg | d2abb83 | 2011-11-23 10:52:40 -0500 | [diff] [blame] | 4685 | |
Derek Foreman | 8ae2db5 | 2015-07-15 13:00:36 -0500 | [diff] [blame] | 4686 | if (pointer->focus == NULL) |
Rafal Mielniczuk | b2917a2 | 2014-01-05 20:04:59 +0100 | [diff] [blame] | 4687 | return; |
| 4688 | |
Derek Foreman | 8ae2db5 | 2015-07-15 13:00:36 -0500 | [diff] [blame] | 4689 | focus = pointer->focus->surface; |
Rafal Mielniczuk | b2917a2 | 2014-01-05 20:04:59 +0100 | [diff] [blame] | 4690 | |
Pekka Paalanen | 01388e2 | 2013-04-25 13:57:44 +0300 | [diff] [blame] | 4691 | surface = weston_surface_get_main_surface(focus); |
Benjamin Franzke | d0f79ab | 2011-11-22 12:43:52 +0100 | [diff] [blame] | 4692 | if (surface == NULL) |
| 4693 | return; |
Pekka Paalanen | 92a0dc4 | 2011-11-28 15:34:13 +0200 | [diff] [blame] | 4694 | |
Pekka Paalanen | 9d1613e | 2011-11-25 12:09:16 +0200 | [diff] [blame] | 4695 | shsurf = get_shell_surface(surface); |
Rafael Antognolli | 03b1659 | 2013-12-03 15:35:42 -0200 | [diff] [blame] | 4696 | if (shsurf == NULL || shsurf->state.fullscreen || |
| 4697 | shsurf->state.maximized) |
Pekka Paalanen | 92a0dc4 | 2011-11-28 15:34:13 +0200 | [diff] [blame] | 4698 | return; |
| 4699 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 4700 | weston_view_from_global(shsurf->view, |
Derek Foreman | 8ae2db5 | 2015-07-15 13:00:36 -0500 | [diff] [blame] | 4701 | wl_fixed_to_int(pointer->grab_x), |
| 4702 | wl_fixed_to_int(pointer->grab_y), |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 4703 | &x, &y); |
Kristian Høgsberg | 0793756 | 2011-04-12 17:25:42 -0400 | [diff] [blame] | 4704 | |
Jason Ekstrand | 918f2dd | 2013-12-02 21:01:53 -0600 | [diff] [blame] | 4705 | if (x < shsurf->surface->width / 3) |
Pekka Paalanen | 9d1613e | 2011-11-25 12:09:16 +0200 | [diff] [blame] | 4706 | edges |= WL_SHELL_SURFACE_RESIZE_LEFT; |
Jason Ekstrand | 918f2dd | 2013-12-02 21:01:53 -0600 | [diff] [blame] | 4707 | else if (x < 2 * shsurf->surface->width / 3) |
Kristian Høgsberg | 0793756 | 2011-04-12 17:25:42 -0400 | [diff] [blame] | 4708 | edges |= 0; |
| 4709 | else |
Pekka Paalanen | 9d1613e | 2011-11-25 12:09:16 +0200 | [diff] [blame] | 4710 | edges |= WL_SHELL_SURFACE_RESIZE_RIGHT; |
Kristian Høgsberg | 0793756 | 2011-04-12 17:25:42 -0400 | [diff] [blame] | 4711 | |
Jason Ekstrand | 918f2dd | 2013-12-02 21:01:53 -0600 | [diff] [blame] | 4712 | if (y < shsurf->surface->height / 3) |
Pekka Paalanen | 9d1613e | 2011-11-25 12:09:16 +0200 | [diff] [blame] | 4713 | edges |= WL_SHELL_SURFACE_RESIZE_TOP; |
Jason Ekstrand | 918f2dd | 2013-12-02 21:01:53 -0600 | [diff] [blame] | 4714 | else if (y < 2 * shsurf->surface->height / 3) |
Kristian Høgsberg | 0793756 | 2011-04-12 17:25:42 -0400 | [diff] [blame] | 4715 | edges |= 0; |
| 4716 | else |
Pekka Paalanen | 9d1613e | 2011-11-25 12:09:16 +0200 | [diff] [blame] | 4717 | edges |= WL_SHELL_SURFACE_RESIZE_BOTTOM; |
Kristian Høgsberg | 0793756 | 2011-04-12 17:25:42 -0400 | [diff] [blame] | 4718 | |
Derek Foreman | 8fbebbd | 2015-07-15 13:00:40 -0500 | [diff] [blame] | 4719 | surface_resize(shsurf, pointer, edges); |
Kristian Høgsberg | 02ec0a5 | 2011-04-23 13:04:11 -0400 | [diff] [blame] | 4720 | } |
| 4721 | |
| 4722 | static void |
Derek Foreman | 8ae2db5 | 2015-07-15 13:00:36 -0500 | [diff] [blame] | 4723 | surface_opacity_binding(struct weston_pointer *pointer, uint32_t time, |
| 4724 | uint32_t axis, wl_fixed_t value, void *data) |
Scott Moreau | a3aa9c9 | 2012-03-22 11:01:03 -0600 | [diff] [blame] | 4725 | { |
Jonas Ådahl | b0b87ba | 2012-09-27 18:40:42 +0200 | [diff] [blame] | 4726 | float step = 0.005; |
Scott Moreau | a3aa9c9 | 2012-03-22 11:01:03 -0600 | [diff] [blame] | 4727 | struct shell_surface *shsurf; |
Derek Foreman | 8ae2db5 | 2015-07-15 13:00:36 -0500 | [diff] [blame] | 4728 | struct weston_surface *focus = pointer->focus->surface; |
Pekka Paalanen | 01388e2 | 2013-04-25 13:57:44 +0300 | [diff] [blame] | 4729 | struct weston_surface *surface; |
Scott Moreau | a3aa9c9 | 2012-03-22 11:01:03 -0600 | [diff] [blame] | 4730 | |
Pekka Paalanen | 01388e2 | 2013-04-25 13:57:44 +0300 | [diff] [blame] | 4731 | /* XXX: broken for windows containing sub-surfaces */ |
| 4732 | surface = weston_surface_get_main_surface(focus); |
Scott Moreau | a3aa9c9 | 2012-03-22 11:01:03 -0600 | [diff] [blame] | 4733 | if (surface == NULL) |
| 4734 | return; |
| 4735 | |
| 4736 | shsurf = get_shell_surface(surface); |
| 4737 | if (!shsurf) |
| 4738 | return; |
| 4739 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 4740 | shsurf->view->alpha -= wl_fixed_to_double(value) * step; |
Scott Moreau | a3aa9c9 | 2012-03-22 11:01:03 -0600 | [diff] [blame] | 4741 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 4742 | if (shsurf->view->alpha > 1.0) |
| 4743 | shsurf->view->alpha = 1.0; |
| 4744 | if (shsurf->view->alpha < step) |
| 4745 | shsurf->view->alpha = step; |
Scott Moreau | a3aa9c9 | 2012-03-22 11:01:03 -0600 | [diff] [blame] | 4746 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 4747 | weston_view_geometry_dirty(shsurf->view); |
Scott Moreau | a3aa9c9 | 2012-03-22 11:01:03 -0600 | [diff] [blame] | 4748 | weston_surface_damage(surface); |
| 4749 | } |
| 4750 | |
| 4751 | static void |
Kristian Høgsberg | e314875 | 2013-05-06 23:19:49 -0400 | [diff] [blame] | 4752 | 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] | 4753 | wl_fixed_t value) |
Scott Moreau | ccbf29d | 2012-02-22 14:21:41 -0700 | [diff] [blame] | 4754 | { |
Derek Foreman | 8aeeac8 | 2015-01-30 13:24:36 -0600 | [diff] [blame] | 4755 | struct weston_compositor *compositor = seat->compositor; |
Derek Foreman | 1281a36 | 2015-07-31 16:55:32 -0500 | [diff] [blame] | 4756 | struct weston_pointer *pointer = weston_seat_get_pointer(seat); |
Scott Moreau | ccbf29d | 2012-02-22 14:21:41 -0700 | [diff] [blame] | 4757 | struct weston_output *output; |
Scott Moreau | e660398 | 2012-06-11 13:07:51 -0600 | [diff] [blame] | 4758 | float increment; |
Scott Moreau | ccbf29d | 2012-02-22 14:21:41 -0700 | [diff] [blame] | 4759 | |
Derek Foreman | 1281a36 | 2015-07-31 16:55:32 -0500 | [diff] [blame] | 4760 | if (!pointer) { |
Derek Foreman | 7ef3bed | 2015-01-06 14:28:13 -0600 | [diff] [blame] | 4761 | weston_log("Zoom hotkey pressed but seat '%s' contains no pointer.\n", seat->seat_name); |
| 4762 | return; |
| 4763 | } |
| 4764 | |
Scott Moreau | ccbf29d | 2012-02-22 14:21:41 -0700 | [diff] [blame] | 4765 | wl_list_for_each(output, &compositor->output_list, link) { |
| 4766 | if (pixman_region32_contains_point(&output->region, |
Derek Foreman | 1281a36 | 2015-07-31 16:55:32 -0500 | [diff] [blame] | 4767 | wl_fixed_to_double(pointer->x), |
| 4768 | wl_fixed_to_double(pointer->y), |
Daniel Stone | 103db7f | 2012-05-08 17:17:55 +0100 | [diff] [blame] | 4769 | NULL)) { |
Daniel Stone | 325fc2d | 2012-05-30 16:31:58 +0100 | [diff] [blame] | 4770 | if (key == KEY_PAGEUP) |
Kristian Høgsberg | 9b68af0 | 2012-05-22 12:55:18 -0400 | [diff] [blame] | 4771 | increment = output->zoom.increment; |
Daniel Stone | 325fc2d | 2012-05-30 16:31:58 +0100 | [diff] [blame] | 4772 | else if (key == KEY_PAGEDOWN) |
Kristian Høgsberg | 9b68af0 | 2012-05-22 12:55:18 -0400 | [diff] [blame] | 4773 | increment = -output->zoom.increment; |
| 4774 | else if (axis == WL_POINTER_AXIS_VERTICAL_SCROLL) |
Jonas Ådahl | b0b87ba | 2012-09-27 18:40:42 +0200 | [diff] [blame] | 4775 | /* For every pixel zoom 20th of a step */ |
Daniel Stone | 0c1e46e | 2012-05-30 16:31:59 +0100 | [diff] [blame] | 4776 | increment = output->zoom.increment * |
Jonas Ådahl | b0b87ba | 2012-09-27 18:40:42 +0200 | [diff] [blame] | 4777 | -wl_fixed_to_double(value) / 20.0; |
Kristian Høgsberg | 9b68af0 | 2012-05-22 12:55:18 -0400 | [diff] [blame] | 4778 | else |
| 4779 | increment = 0; |
| 4780 | |
Kristian Høgsberg | 9b68af0 | 2012-05-22 12:55:18 -0400 | [diff] [blame] | 4781 | output->zoom.level += increment; |
Scott Moreau | c6d7f60 | 2012-02-23 22:28:37 -0700 | [diff] [blame] | 4782 | |
Scott Moreau | e660398 | 2012-06-11 13:07:51 -0600 | [diff] [blame] | 4783 | if (output->zoom.level < 0.0) |
Scott Moreau | 850ca42 | 2012-05-21 15:21:25 -0600 | [diff] [blame] | 4784 | output->zoom.level = 0.0; |
Scott Moreau | e660398 | 2012-06-11 13:07:51 -0600 | [diff] [blame] | 4785 | else if (output->zoom.level > output->zoom.max_level) |
| 4786 | output->zoom.level = output->zoom.max_level; |
Derek Foreman | 25bd8a7 | 2015-07-23 14:55:13 -0500 | [diff] [blame] | 4787 | |
| 4788 | if (!output->zoom.active) { |
| 4789 | if (output->zoom.level <= 0.0) |
| 4790 | continue; |
Derek Foreman | 22276a5 | 2015-07-23 14:55:15 -0500 | [diff] [blame] | 4791 | weston_output_activate_zoom(output, seat); |
Kristian Høgsberg | 79af73e | 2012-08-03 15:45:23 -0400 | [diff] [blame] | 4792 | } |
Scott Moreau | ccbf29d | 2012-02-22 14:21:41 -0700 | [diff] [blame] | 4793 | |
Scott Moreau | e660398 | 2012-06-11 13:07:51 -0600 | [diff] [blame] | 4794 | output->zoom.spring_z.target = output->zoom.level; |
Scott Moreau | ccbf29d | 2012-02-22 14:21:41 -0700 | [diff] [blame] | 4795 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 4796 | weston_output_update_zoom(output); |
Scott Moreau | ccbf29d | 2012-02-22 14:21:41 -0700 | [diff] [blame] | 4797 | } |
| 4798 | } |
| 4799 | } |
| 4800 | |
Scott Moreau | ccbf29d | 2012-02-22 14:21:41 -0700 | [diff] [blame] | 4801 | static void |
Derek Foreman | 8ae2db5 | 2015-07-15 13:00:36 -0500 | [diff] [blame] | 4802 | zoom_axis_binding(struct weston_pointer *pointer, uint32_t time, |
| 4803 | uint32_t axis, wl_fixed_t value, void *data) |
Daniel Stone | 325fc2d | 2012-05-30 16:31:58 +0100 | [diff] [blame] | 4804 | { |
Derek Foreman | 8ae2db5 | 2015-07-15 13:00:36 -0500 | [diff] [blame] | 4805 | do_zoom(pointer->seat, time, 0, axis, value); |
Daniel Stone | 325fc2d | 2012-05-30 16:31:58 +0100 | [diff] [blame] | 4806 | } |
| 4807 | |
| 4808 | static void |
Derek Foreman | 8ae2db5 | 2015-07-15 13:00:36 -0500 | [diff] [blame] | 4809 | zoom_key_binding(struct weston_keyboard *keyboard, uint32_t time, |
| 4810 | uint32_t key, void *data) |
Daniel Stone | 325fc2d | 2012-05-30 16:31:58 +0100 | [diff] [blame] | 4811 | { |
Derek Foreman | 8ae2db5 | 2015-07-15 13:00:36 -0500 | [diff] [blame] | 4812 | do_zoom(keyboard->seat, time, key, 0, 0); |
Daniel Stone | 325fc2d | 2012-05-30 16:31:58 +0100 | [diff] [blame] | 4813 | } |
| 4814 | |
| 4815 | static void |
Derek Foreman | 8ae2db5 | 2015-07-15 13:00:36 -0500 | [diff] [blame] | 4816 | terminate_binding(struct weston_keyboard *keyboard, uint32_t time, |
| 4817 | uint32_t key, void *data) |
Kristian Høgsberg | e1a850e | 2011-12-19 15:18:05 -0500 | [diff] [blame] | 4818 | { |
Kristian Høgsberg | 8334bc1 | 2012-01-03 10:29:47 -0500 | [diff] [blame] | 4819 | struct weston_compositor *compositor = data; |
Kristian Høgsberg | e1a850e | 2011-12-19 15:18:05 -0500 | [diff] [blame] | 4820 | |
Daniel Stone | 325fc2d | 2012-05-30 16:31:58 +0100 | [diff] [blame] | 4821 | wl_display_terminate(compositor->wl_display); |
Kristian Høgsberg | e1a850e | 2011-12-19 15:18:05 -0500 | [diff] [blame] | 4822 | } |
| 4823 | |
Emilio Pozuelo Monfort | 03251b6 | 2013-11-19 11:37:16 +0100 | [diff] [blame] | 4824 | static void |
Giulio Camuffo | 1959ab8 | 2013-11-14 23:42:52 +0100 | [diff] [blame] | 4825 | rotate_grab_motion(struct weston_pointer_grab *grab, uint32_t time, |
Jonas Ådahl | d251010 | 2014-10-05 21:39:14 +0200 | [diff] [blame] | 4826 | struct weston_pointer_motion_event *event) |
Pekka Paalanen | 460099f | 2012-01-20 16:48:25 +0200 | [diff] [blame] | 4827 | { |
| 4828 | struct rotate_grab *rotate = |
Ander Conselvan de Oliveira | fe0444a | 2012-04-04 17:48:05 +0300 | [diff] [blame] | 4829 | container_of(grab, struct rotate_grab, base.grab); |
Kristian Høgsberg | 02bbabb | 2013-05-06 22:15:05 -0400 | [diff] [blame] | 4830 | struct weston_pointer *pointer = grab->pointer; |
Ander Conselvan de Oliveira | fe0444a | 2012-04-04 17:48:05 +0300 | [diff] [blame] | 4831 | struct shell_surface *shsurf = rotate->base.shsurf; |
John Kåre Alsaker | 490d02a | 2012-09-30 02:57:21 +0200 | [diff] [blame] | 4832 | float cx, cy, dx, dy, cposx, cposy, dposx, dposy, r; |
Ander Conselvan de Oliveira | fe0444a | 2012-04-04 17:48:05 +0300 | [diff] [blame] | 4833 | |
Jonas Ådahl | d251010 | 2014-10-05 21:39:14 +0200 | [diff] [blame] | 4834 | weston_pointer_move(pointer, event); |
Giulio Camuffo | 1959ab8 | 2013-11-14 23:42:52 +0100 | [diff] [blame] | 4835 | |
Ander Conselvan de Oliveira | fe0444a | 2012-04-04 17:48:05 +0300 | [diff] [blame] | 4836 | if (!shsurf) |
| 4837 | return; |
| 4838 | |
Jason Ekstrand | 918f2dd | 2013-12-02 21:01:53 -0600 | [diff] [blame] | 4839 | cx = 0.5f * shsurf->surface->width; |
| 4840 | cy = 0.5f * shsurf->surface->height; |
Pekka Paalanen | 460099f | 2012-01-20 16:48:25 +0200 | [diff] [blame] | 4841 | |
Daniel Stone | 37816df | 2012-05-16 18:45:18 +0100 | [diff] [blame] | 4842 | dx = wl_fixed_to_double(pointer->x) - rotate->center.x; |
| 4843 | dy = wl_fixed_to_double(pointer->y) - rotate->center.y; |
Pekka Paalanen | 460099f | 2012-01-20 16:48:25 +0200 | [diff] [blame] | 4844 | r = sqrtf(dx * dx + dy * dy); |
| 4845 | |
Ander Conselvan de Oliveira | fe0444a | 2012-04-04 17:48:05 +0300 | [diff] [blame] | 4846 | wl_list_remove(&shsurf->rotation.transform.link); |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 4847 | weston_view_geometry_dirty(shsurf->view); |
Pekka Paalanen | 460099f | 2012-01-20 16:48:25 +0200 | [diff] [blame] | 4848 | |
| 4849 | if (r > 20.0f) { |
Pekka Paalanen | 460099f | 2012-01-20 16:48:25 +0200 | [diff] [blame] | 4850 | struct weston_matrix *matrix = |
Ander Conselvan de Oliveira | fe0444a | 2012-04-04 17:48:05 +0300 | [diff] [blame] | 4851 | &shsurf->rotation.transform.matrix; |
Pekka Paalanen | 460099f | 2012-01-20 16:48:25 +0200 | [diff] [blame] | 4852 | |
Kristian Høgsberg | 765e27b | 2012-01-27 13:36:13 -0500 | [diff] [blame] | 4853 | weston_matrix_init(&rotate->rotation); |
Vasily Khoruzhick | 1bbf372 | 2013-01-28 22:40:28 +0300 | [diff] [blame] | 4854 | weston_matrix_rotate_xy(&rotate->rotation, dx / r, dy / r); |
Pekka Paalanen | 460099f | 2012-01-20 16:48:25 +0200 | [diff] [blame] | 4855 | |
| 4856 | weston_matrix_init(matrix); |
Pekka Paalanen | 7b3bd3d | 2012-01-30 14:16:34 +0200 | [diff] [blame] | 4857 | weston_matrix_translate(matrix, -cx, -cy, 0.0f); |
Ander Conselvan de Oliveira | fe0444a | 2012-04-04 17:48:05 +0300 | [diff] [blame] | 4858 | weston_matrix_multiply(matrix, &shsurf->rotation.rotation); |
Kristian Høgsberg | 765e27b | 2012-01-27 13:36:13 -0500 | [diff] [blame] | 4859 | weston_matrix_multiply(matrix, &rotate->rotation); |
Pekka Paalanen | 7b3bd3d | 2012-01-30 14:16:34 +0200 | [diff] [blame] | 4860 | weston_matrix_translate(matrix, cx, cy, 0.0f); |
Pekka Paalanen | 460099f | 2012-01-20 16:48:25 +0200 | [diff] [blame] | 4861 | |
Pekka Paalanen | bc0b7e7 | 2012-01-24 09:53:37 +0200 | [diff] [blame] | 4862 | wl_list_insert( |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 4863 | &shsurf->view->geometry.transformation_list, |
Ander Conselvan de Oliveira | fe0444a | 2012-04-04 17:48:05 +0300 | [diff] [blame] | 4864 | &shsurf->rotation.transform.link); |
Pekka Paalanen | 460099f | 2012-01-20 16:48:25 +0200 | [diff] [blame] | 4865 | } else { |
Ander Conselvan de Oliveira | fe0444a | 2012-04-04 17:48:05 +0300 | [diff] [blame] | 4866 | wl_list_init(&shsurf->rotation.transform.link); |
| 4867 | weston_matrix_init(&shsurf->rotation.rotation); |
Kristian Høgsberg | 765e27b | 2012-01-27 13:36:13 -0500 | [diff] [blame] | 4868 | weston_matrix_init(&rotate->rotation); |
Pekka Paalanen | 460099f | 2012-01-20 16:48:25 +0200 | [diff] [blame] | 4869 | } |
Pekka Paalanen | b45ac5e | 2012-02-09 15:58:44 +0200 | [diff] [blame] | 4870 | |
Rafal Mielniczuk | 2d7ab82 | 2012-03-22 22:22:04 +0100 | [diff] [blame] | 4871 | /* We need to adjust the position of the surface |
| 4872 | * in case it was resized in a rotated state before */ |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 4873 | cposx = shsurf->view->geometry.x + cx; |
| 4874 | cposy = shsurf->view->geometry.y + cy; |
Rafal Mielniczuk | 2d7ab82 | 2012-03-22 22:22:04 +0100 | [diff] [blame] | 4875 | dposx = rotate->center.x - cposx; |
| 4876 | dposy = rotate->center.y - cposy; |
| 4877 | if (dposx != 0.0f || dposy != 0.0f) { |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 4878 | weston_view_set_position(shsurf->view, |
| 4879 | shsurf->view->geometry.x + dposx, |
| 4880 | shsurf->view->geometry.y + dposy); |
Rafal Mielniczuk | 2d7ab82 | 2012-03-22 22:22:04 +0100 | [diff] [blame] | 4881 | } |
| 4882 | |
Derek Foreman | 4b1a0a1 | 2014-09-10 15:37:33 -0500 | [diff] [blame] | 4883 | /* Repaint implies weston_view_update_transform(), which |
Pekka Paalanen | b45ac5e | 2012-02-09 15:58:44 +0200 | [diff] [blame] | 4884 | * lazily applies the damage due to rotation update. |
| 4885 | */ |
Ander Conselvan de Oliveira | fe0444a | 2012-04-04 17:48:05 +0300 | [diff] [blame] | 4886 | weston_compositor_schedule_repaint(shsurf->surface->compositor); |
Pekka Paalanen | 460099f | 2012-01-20 16:48:25 +0200 | [diff] [blame] | 4887 | } |
| 4888 | |
| 4889 | static void |
Kristian Høgsberg | 02bbabb | 2013-05-06 22:15:05 -0400 | [diff] [blame] | 4890 | rotate_grab_button(struct weston_pointer_grab *grab, |
| 4891 | uint32_t time, uint32_t button, uint32_t state_w) |
Pekka Paalanen | 460099f | 2012-01-20 16:48:25 +0200 | [diff] [blame] | 4892 | { |
| 4893 | struct rotate_grab *rotate = |
Ander Conselvan de Oliveira | fe0444a | 2012-04-04 17:48:05 +0300 | [diff] [blame] | 4894 | container_of(grab, struct rotate_grab, base.grab); |
Kristian Høgsberg | 02bbabb | 2013-05-06 22:15:05 -0400 | [diff] [blame] | 4895 | struct weston_pointer *pointer = grab->pointer; |
Ander Conselvan de Oliveira | fe0444a | 2012-04-04 17:48:05 +0300 | [diff] [blame] | 4896 | struct shell_surface *shsurf = rotate->base.shsurf; |
Daniel Stone | 4dbadb1 | 2012-05-30 16:31:51 +0100 | [diff] [blame] | 4897 | enum wl_pointer_button_state state = state_w; |
Pekka Paalanen | 460099f | 2012-01-20 16:48:25 +0200 | [diff] [blame] | 4898 | |
Daniel Stone | 4dbadb1 | 2012-05-30 16:31:51 +0100 | [diff] [blame] | 4899 | if (pointer->button_count == 0 && |
| 4900 | state == WL_POINTER_BUTTON_STATE_RELEASED) { |
Ander Conselvan de Oliveira | fe0444a | 2012-04-04 17:48:05 +0300 | [diff] [blame] | 4901 | if (shsurf) |
| 4902 | weston_matrix_multiply(&shsurf->rotation.rotation, |
| 4903 | &rotate->rotation); |
Ander Conselvan de Oliveira | b9d2a0f | 2012-06-28 18:08:05 +0300 | [diff] [blame] | 4904 | shell_grab_end(&rotate->base); |
Pekka Paalanen | 460099f | 2012-01-20 16:48:25 +0200 | [diff] [blame] | 4905 | free(rotate); |
| 4906 | } |
| 4907 | } |
| 4908 | |
Jonas Ådahl | 1ea343e | 2013-10-25 23:18:05 +0200 | [diff] [blame] | 4909 | static void |
| 4910 | rotate_grab_cancel(struct weston_pointer_grab *grab) |
| 4911 | { |
| 4912 | struct rotate_grab *rotate = |
| 4913 | container_of(grab, struct rotate_grab, base.grab); |
| 4914 | |
| 4915 | shell_grab_end(&rotate->base); |
| 4916 | free(rotate); |
| 4917 | } |
| 4918 | |
Kristian Høgsberg | 02bbabb | 2013-05-06 22:15:05 -0400 | [diff] [blame] | 4919 | static const struct weston_pointer_grab_interface rotate_grab_interface = { |
Pekka Paalanen | 460099f | 2012-01-20 16:48:25 +0200 | [diff] [blame] | 4920 | noop_grab_focus, |
| 4921 | rotate_grab_motion, |
| 4922 | rotate_grab_button, |
Jonas Ådahl | 0336ca0 | 2014-10-04 16:28:29 +0200 | [diff] [blame] | 4923 | noop_grab_axis, |
Jonas Ådahl | 1ea343e | 2013-10-25 23:18:05 +0200 | [diff] [blame] | 4924 | rotate_grab_cancel, |
Pekka Paalanen | 460099f | 2012-01-20 16:48:25 +0200 | [diff] [blame] | 4925 | }; |
| 4926 | |
| 4927 | static void |
Derek Foreman | 74de469 | 2015-07-15 13:00:39 -0500 | [diff] [blame] | 4928 | surface_rotate(struct shell_surface *surface, struct weston_pointer *pointer) |
Pekka Paalanen | 460099f | 2012-01-20 16:48:25 +0200 | [diff] [blame] | 4929 | { |
Pekka Paalanen | 460099f | 2012-01-20 16:48:25 +0200 | [diff] [blame] | 4930 | struct rotate_grab *rotate; |
John Kåre Alsaker | 490d02a | 2012-09-30 02:57:21 +0200 | [diff] [blame] | 4931 | float dx, dy; |
| 4932 | float r; |
Pekka Paalanen | 460099f | 2012-01-20 16:48:25 +0200 | [diff] [blame] | 4933 | |
Derek Foreman | 45a7c27 | 2015-09-11 14:27:40 -0500 | [diff] [blame] | 4934 | surface = find_toplevel_surface(surface); |
| 4935 | |
Pekka Paalanen | 460099f | 2012-01-20 16:48:25 +0200 | [diff] [blame] | 4936 | rotate = malloc(sizeof *rotate); |
| 4937 | if (!rotate) |
| 4938 | return; |
| 4939 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 4940 | weston_view_to_global_float(surface->view, |
Jason Ekstrand | 918f2dd | 2013-12-02 21:01:53 -0600 | [diff] [blame] | 4941 | surface->surface->width * 0.5f, |
| 4942 | surface->surface->height * 0.5f, |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 4943 | &rotate->center.x, &rotate->center.y); |
Pekka Paalanen | 460099f | 2012-01-20 16:48:25 +0200 | [diff] [blame] | 4944 | |
Derek Foreman | 74de469 | 2015-07-15 13:00:39 -0500 | [diff] [blame] | 4945 | dx = wl_fixed_to_double(pointer->x) - rotate->center.x; |
| 4946 | dy = wl_fixed_to_double(pointer->y) - rotate->center.y; |
Kristian Høgsberg | 765e27b | 2012-01-27 13:36:13 -0500 | [diff] [blame] | 4947 | r = sqrtf(dx * dx + dy * dy); |
| 4948 | if (r > 20.0f) { |
| 4949 | struct weston_matrix inverse; |
| 4950 | |
| 4951 | weston_matrix_init(&inverse); |
Vasily Khoruzhick | 1bbf372 | 2013-01-28 22:40:28 +0300 | [diff] [blame] | 4952 | weston_matrix_rotate_xy(&inverse, dx / r, -dy / r); |
Kristian Høgsberg | 765e27b | 2012-01-27 13:36:13 -0500 | [diff] [blame] | 4953 | weston_matrix_multiply(&surface->rotation.rotation, &inverse); |
Rafal Mielniczuk | 2d7ab82 | 2012-03-22 22:22:04 +0100 | [diff] [blame] | 4954 | |
| 4955 | weston_matrix_init(&rotate->rotation); |
Vasily Khoruzhick | 1bbf372 | 2013-01-28 22:40:28 +0300 | [diff] [blame] | 4956 | weston_matrix_rotate_xy(&rotate->rotation, dx / r, dy / r); |
Kristian Høgsberg | 765e27b | 2012-01-27 13:36:13 -0500 | [diff] [blame] | 4957 | } else { |
| 4958 | weston_matrix_init(&surface->rotation.rotation); |
| 4959 | weston_matrix_init(&rotate->rotation); |
| 4960 | } |
| 4961 | |
Ander Conselvan de Oliveira | b9d2a0f | 2012-06-28 18:08:05 +0300 | [diff] [blame] | 4962 | shell_grab_start(&rotate->base, &rotate_grab_interface, surface, |
Jonas Ådahl | 6d6fb61 | 2015-11-17 16:00:33 +0800 | [diff] [blame] | 4963 | pointer, WESTON_DESKTOP_SHELL_CURSOR_ARROW); |
Pekka Paalanen | 460099f | 2012-01-20 16:48:25 +0200 | [diff] [blame] | 4964 | } |
| 4965 | |
| 4966 | static void |
Derek Foreman | 8ae2db5 | 2015-07-15 13:00:36 -0500 | [diff] [blame] | 4967 | 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] | 4968 | void *data) |
| 4969 | { |
Rafal Mielniczuk | b2917a2 | 2014-01-05 20:04:59 +0100 | [diff] [blame] | 4970 | struct weston_surface *focus; |
Pekka Paalanen | 01388e2 | 2013-04-25 13:57:44 +0300 | [diff] [blame] | 4971 | struct weston_surface *base_surface; |
Kristian Høgsberg | 0c36903 | 2013-02-14 21:31:44 -0500 | [diff] [blame] | 4972 | struct shell_surface *surface; |
| 4973 | |
Derek Foreman | 8ae2db5 | 2015-07-15 13:00:36 -0500 | [diff] [blame] | 4974 | if (pointer->focus == NULL) |
Rafal Mielniczuk | b2917a2 | 2014-01-05 20:04:59 +0100 | [diff] [blame] | 4975 | return; |
| 4976 | |
Derek Foreman | 8ae2db5 | 2015-07-15 13:00:36 -0500 | [diff] [blame] | 4977 | focus = pointer->focus->surface; |
Rafal Mielniczuk | b2917a2 | 2014-01-05 20:04:59 +0100 | [diff] [blame] | 4978 | |
Pekka Paalanen | 01388e2 | 2013-04-25 13:57:44 +0300 | [diff] [blame] | 4979 | base_surface = weston_surface_get_main_surface(focus); |
Kristian Høgsberg | 0c36903 | 2013-02-14 21:31:44 -0500 | [diff] [blame] | 4980 | if (base_surface == NULL) |
| 4981 | return; |
| 4982 | |
| 4983 | surface = get_shell_surface(base_surface); |
Rafael Antognolli | 03b1659 | 2013-12-03 15:35:42 -0200 | [diff] [blame] | 4984 | if (surface == NULL || surface->state.fullscreen || |
| 4985 | surface->state.maximized) |
Kristian Høgsberg | 0c36903 | 2013-02-14 21:31:44 -0500 | [diff] [blame] | 4986 | return; |
| 4987 | |
Derek Foreman | 74de469 | 2015-07-15 13:00:39 -0500 | [diff] [blame] | 4988 | surface_rotate(surface, pointer); |
Kristian Høgsberg | 0c36903 | 2013-02-14 21:31:44 -0500 | [diff] [blame] | 4989 | } |
| 4990 | |
Emilio Pozuelo Monfort | 9e7c759 | 2014-01-30 14:01:10 +0100 | [diff] [blame] | 4991 | /* Move all fullscreen layers down to the current workspace and hide their |
| 4992 | * black views. The surfaces' state is set to both fullscreen and lowered, |
| 4993 | * and this is reversed when such a surface is re-configured, see |
| 4994 | * shell_configure_fullscreen() and shell_ensure_fullscreen_black_view(). |
| 4995 | * |
Mario Kleiner | 9f4d655 | 2015-06-21 21:25:08 +0200 | [diff] [blame] | 4996 | * lowering_output = NULL - Lower on all outputs, else only lower on the |
| 4997 | * specified output. |
| 4998 | * |
Emilio Pozuelo Monfort | 9e7c759 | 2014-01-30 14:01:10 +0100 | [diff] [blame] | 4999 | * This should be used when implementing shell-wide overlays, such as |
Philip Withnall | 83ffd9d | 2013-11-25 18:01:42 +0000 | [diff] [blame] | 5000 | * the alt-tab switcher, which need to de-promote fullscreen layers. */ |
Kristian Høgsberg | 1ef2313 | 2013-12-04 00:20:01 -0800 | [diff] [blame] | 5001 | void |
Mario Kleiner | 9f4d655 | 2015-06-21 21:25:08 +0200 | [diff] [blame] | 5002 | lower_fullscreen_layer(struct desktop_shell *shell, |
| 5003 | struct weston_output *lowering_output) |
Kristian Høgsberg | b0d8e77 | 2012-06-18 16:34:58 -0400 | [diff] [blame] | 5004 | { |
| 5005 | struct workspace *ws; |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 5006 | struct weston_view *view, *prev; |
Kristian Høgsberg | b0d8e77 | 2012-06-18 16:34:58 -0400 | [diff] [blame] | 5007 | |
| 5008 | ws = get_current_workspace(shell); |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 5009 | wl_list_for_each_reverse_safe(view, prev, |
Giulio Camuffo | 412e6a5 | 2014-07-09 22:12:56 +0300 | [diff] [blame] | 5010 | &shell->fullscreen_layer.view_list.link, |
| 5011 | layer_link.link) { |
Emilio Pozuelo Monfort | 9e7c759 | 2014-01-30 14:01:10 +0100 | [diff] [blame] | 5012 | struct shell_surface *shsurf = get_shell_surface(view->surface); |
| 5013 | |
| 5014 | if (!shsurf) |
| 5015 | continue; |
| 5016 | |
Mario Kleiner | 9f4d655 | 2015-06-21 21:25:08 +0200 | [diff] [blame] | 5017 | /* Only lower surfaces which have lowering_output as their fullscreen |
| 5018 | * output, unless a NULL output asks for lowering on all outputs. |
| 5019 | */ |
| 5020 | if (lowering_output && (shsurf->fullscreen_output != lowering_output)) |
| 5021 | continue; |
| 5022 | |
Emilio Pozuelo Monfort | 9e7c759 | 2014-01-30 14:01:10 +0100 | [diff] [blame] | 5023 | /* We can have a non-fullscreen popup for a fullscreen surface |
| 5024 | * in the fullscreen layer. */ |
| 5025 | if (shsurf->state.fullscreen) { |
| 5026 | /* Hide the black view */ |
Giulio Camuffo | 412e6a5 | 2014-07-09 22:12:56 +0300 | [diff] [blame] | 5027 | weston_layer_entry_remove(&shsurf->fullscreen.black_view->layer_link); |
| 5028 | wl_list_init(&shsurf->fullscreen.black_view->layer_link.link); |
Kristian Høgsberg | c991513 | 2014-05-09 16:24:07 -0700 | [diff] [blame] | 5029 | weston_view_damage_below(shsurf->fullscreen.black_view); |
| 5030 | |
Emilio Pozuelo Monfort | 9e7c759 | 2014-01-30 14:01:10 +0100 | [diff] [blame] | 5031 | } |
| 5032 | |
| 5033 | /* Lower the view to the workspace layer */ |
Giulio Camuffo | 412e6a5 | 2014-07-09 22:12:56 +0300 | [diff] [blame] | 5034 | weston_layer_entry_remove(&view->layer_link); |
| 5035 | weston_layer_entry_insert(&ws->layer.view_list, &view->layer_link); |
Philip Withnall | 83ffd9d | 2013-11-25 18:01:42 +0000 | [diff] [blame] | 5036 | weston_view_damage_below(view); |
| 5037 | weston_surface_damage(view->surface); |
Emilio Pozuelo Monfort | 9e7c759 | 2014-01-30 14:01:10 +0100 | [diff] [blame] | 5038 | |
| 5039 | shsurf->state.lowered = true; |
Philip Withnall | 83ffd9d | 2013-11-25 18:01:42 +0000 | [diff] [blame] | 5040 | } |
Kristian Høgsberg | b0d8e77 | 2012-06-18 16:34:58 -0400 | [diff] [blame] | 5041 | } |
| 5042 | |
Kristian Høgsberg | 1ef2313 | 2013-12-04 00:20:01 -0800 | [diff] [blame] | 5043 | void |
Tiago Vignatti | be14326 | 2012-04-16 17:31:41 +0300 | [diff] [blame] | 5044 | activate(struct desktop_shell *shell, struct weston_surface *es, |
Emilio Pozuelo Monfort | 9e7c759 | 2014-01-30 14:01:10 +0100 | [diff] [blame] | 5045 | struct weston_seat *seat, bool configure) |
Kristian Høgsberg | 7584062 | 2011-09-06 13:48:16 -0400 | [diff] [blame] | 5046 | { |
Pekka Paalanen | 01388e2 | 2013-04-25 13:57:44 +0300 | [diff] [blame] | 5047 | struct weston_surface *main_surface; |
Kristian Høgsberg | 2f5faff | 2012-07-31 16:36:34 -0400 | [diff] [blame] | 5048 | struct focus_state *state; |
Jonas Ådahl | 8538b22 | 2012-08-29 22:13:03 +0200 | [diff] [blame] | 5049 | struct workspace *ws; |
Louis-Francis Ratté-Boulianne | b482dbd | 2013-11-19 11:37:11 +0100 | [diff] [blame] | 5050 | struct weston_surface *old_es; |
Rafael Antognolli | 03b1659 | 2013-12-03 15:35:42 -0200 | [diff] [blame] | 5051 | struct shell_surface *shsurf; |
Kristian Høgsberg | 7584062 | 2011-09-06 13:48:16 -0400 | [diff] [blame] | 5052 | |
Pekka Paalanen | 01388e2 | 2013-04-25 13:57:44 +0300 | [diff] [blame] | 5053 | main_surface = weston_surface_get_main_surface(es); |
Mario Kleiner | 9f4d655 | 2015-06-21 21:25:08 +0200 | [diff] [blame] | 5054 | shsurf = get_shell_surface(main_surface); |
| 5055 | assert(shsurf); |
| 5056 | |
| 5057 | /* Only demote fullscreen surfaces on the output of activated shsurf. |
| 5058 | * Leave fullscreen surfaces on unrelated outputs alone. */ |
| 5059 | lower_fullscreen_layer(shell, shsurf->output); |
Pekka Paalanen | 01388e2 | 2013-04-25 13:57:44 +0300 | [diff] [blame] | 5060 | |
Daniel Stone | 37816df | 2012-05-16 18:45:18 +0100 | [diff] [blame] | 5061 | weston_surface_activate(es, seat); |
Kristian Høgsberg | 7584062 | 2011-09-06 13:48:16 -0400 | [diff] [blame] | 5062 | |
Jonas Ådahl | 8538b22 | 2012-08-29 22:13:03 +0200 | [diff] [blame] | 5063 | state = ensure_focus_state(shell, seat); |
| 5064 | if (state == NULL) |
| 5065 | return; |
Kristian Høgsberg | 2f5faff | 2012-07-31 16:36:34 -0400 | [diff] [blame] | 5066 | |
Louis-Francis Ratté-Boulianne | b482dbd | 2013-11-19 11:37:11 +0100 | [diff] [blame] | 5067 | old_es = state->keyboard_focus; |
Kristian Høgsberg | d500bf1 | 2014-01-22 12:25:20 -0800 | [diff] [blame] | 5068 | focus_state_set_focus(state, es); |
Kristian Høgsberg | 2f5faff | 2012-07-31 16:36:34 -0400 | [diff] [blame] | 5069 | |
Emilio Pozuelo Monfort | 9e7c759 | 2014-01-30 14:01:10 +0100 | [diff] [blame] | 5070 | if (shsurf->state.fullscreen && configure) |
Rafael Antognolli | 03b1659 | 2013-12-03 15:35:42 -0200 | [diff] [blame] | 5071 | shell_configure_fullscreen(shsurf); |
| 5072 | else |
Mario Kleiner | 492c12f | 2015-06-21 21:25:12 +0200 | [diff] [blame] | 5073 | restore_output_mode(shsurf->output); |
Louis-Francis Ratté-Boulianne | b482dbd | 2013-11-19 11:37:11 +0100 | [diff] [blame] | 5074 | |
Emilio Pozuelo Monfort | 7908bff | 2014-01-30 13:49:39 +0100 | [diff] [blame] | 5075 | /* Update the surface’s layer. This brings it to the top of the stacking |
| 5076 | * order as appropriate. */ |
| 5077 | shell_surface_update_layer(shsurf); |
| 5078 | |
Philip Withnall | 83ffd9d | 2013-11-25 18:01:42 +0000 | [diff] [blame] | 5079 | if (shell->focus_animation_type != ANIMATION_NONE) { |
| 5080 | ws = get_current_workspace(shell); |
Louis-Francis Ratté-Boulianne | b482dbd | 2013-11-19 11:37:11 +0100 | [diff] [blame] | 5081 | 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] | 5082 | } |
Kristian Høgsberg | 7584062 | 2011-09-06 13:48:16 -0400 | [diff] [blame] | 5083 | } |
| 5084 | |
Alex Wu | 2185843 | 2012-04-01 20:13:08 +0800 | [diff] [blame] | 5085 | /* no-op func for checking black surface */ |
| 5086 | static void |
Jason Ekstrand | 918f2dd | 2013-12-02 21:01:53 -0600 | [diff] [blame] | 5087 | 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] | 5088 | { |
| 5089 | } |
| 5090 | |
Quentin Glidic | c0d79ce | 2013-01-29 14:16:13 +0100 | [diff] [blame] | 5091 | static bool |
Alex Wu | 2185843 | 2012-04-01 20:13:08 +0800 | [diff] [blame] | 5092 | is_black_surface (struct weston_surface *es, struct weston_surface **fs_surface) |
| 5093 | { |
| 5094 | if (es->configure == black_surface_configure) { |
| 5095 | if (fs_surface) |
Giulio Camuffo | 7fe01b1 | 2013-03-28 18:02:42 +0100 | [diff] [blame] | 5096 | *fs_surface = (struct weston_surface *)es->configure_private; |
Alex Wu | 2185843 | 2012-04-01 20:13:08 +0800 | [diff] [blame] | 5097 | return true; |
| 5098 | } |
| 5099 | return false; |
| 5100 | } |
| 5101 | |
Kristian Høgsberg | 7584062 | 2011-09-06 13:48:16 -0400 | [diff] [blame] | 5102 | static void |
Neil Roberts | a28c693 | 2013-10-03 16:43:04 +0100 | [diff] [blame] | 5103 | activate_binding(struct weston_seat *seat, |
| 5104 | struct desktop_shell *shell, |
Jonas Ådahl | cd0f1ac | 2015-06-26 12:37:56 +0800 | [diff] [blame] | 5105 | struct weston_view *focus_view) |
Kristian Høgsberg | e1a850e | 2011-12-19 15:18:05 -0500 | [diff] [blame] | 5106 | { |
Jonas Ådahl | cd0f1ac | 2015-06-26 12:37:56 +0800 | [diff] [blame] | 5107 | struct weston_surface *focus; |
Pekka Paalanen | 01388e2 | 2013-04-25 13:57:44 +0300 | [diff] [blame] | 5108 | struct weston_surface *main_surface; |
Kristian Høgsberg | e1a850e | 2011-12-19 15:18:05 -0500 | [diff] [blame] | 5109 | |
Jonas Ådahl | cd0f1ac | 2015-06-26 12:37:56 +0800 | [diff] [blame] | 5110 | focus = focus_view->surface; |
Alex Wu | 9c35e6b | 2012-03-05 14:13:13 +0800 | [diff] [blame] | 5111 | |
Pekka Paalanen | 01388e2 | 2013-04-25 13:57:44 +0300 | [diff] [blame] | 5112 | if (is_black_surface(focus, &main_surface)) |
| 5113 | focus = main_surface; |
Alex Wu | 4539b08 | 2012-03-01 12:57:46 +0800 | [diff] [blame] | 5114 | |
Pekka Paalanen | 01388e2 | 2013-04-25 13:57:44 +0300 | [diff] [blame] | 5115 | main_surface = weston_surface_get_main_surface(focus); |
| 5116 | if (get_shell_surface_type(main_surface) == SHELL_SURFACE_NONE) |
Kristian Høgsberg | 0636ac3 | 2012-06-27 10:22:15 -0400 | [diff] [blame] | 5117 | return; |
Kristian Høgsberg | 85b2e4b | 2012-06-21 16:49:42 -0400 | [diff] [blame] | 5118 | |
Emilio Pozuelo Monfort | 9e7c759 | 2014-01-30 14:01:10 +0100 | [diff] [blame] | 5119 | activate(shell, focus, seat, true); |
Neil Roberts | a28c693 | 2013-10-03 16:43:04 +0100 | [diff] [blame] | 5120 | } |
| 5121 | |
| 5122 | static void |
Derek Foreman | 8ae2db5 | 2015-07-15 13:00:36 -0500 | [diff] [blame] | 5123 | click_to_activate_binding(struct weston_pointer *pointer, uint32_t time, |
| 5124 | uint32_t button, void *data) |
Neil Roberts | a28c693 | 2013-10-03 16:43:04 +0100 | [diff] [blame] | 5125 | { |
Derek Foreman | 8ae2db5 | 2015-07-15 13:00:36 -0500 | [diff] [blame] | 5126 | if (pointer->grab != &pointer->default_grab) |
Neil Roberts | a28c693 | 2013-10-03 16:43:04 +0100 | [diff] [blame] | 5127 | return; |
Derek Foreman | 8ae2db5 | 2015-07-15 13:00:36 -0500 | [diff] [blame] | 5128 | if (pointer->focus == NULL) |
Kristian Høgsberg | 7c4f6cc | 2014-01-01 16:28:32 -0800 | [diff] [blame] | 5129 | return; |
Neil Roberts | a28c693 | 2013-10-03 16:43:04 +0100 | [diff] [blame] | 5130 | |
Jonas Ådahl | cd0f1ac | 2015-06-26 12:37:56 +0800 | [diff] [blame] | 5131 | activate_binding(pointer->seat, data, pointer->focus); |
Neil Roberts | a28c693 | 2013-10-03 16:43:04 +0100 | [diff] [blame] | 5132 | } |
| 5133 | |
| 5134 | static void |
Derek Foreman | 8ae2db5 | 2015-07-15 13:00:36 -0500 | [diff] [blame] | 5135 | touch_to_activate_binding(struct weston_touch *touch, uint32_t time, |
| 5136 | void *data) |
Neil Roberts | a28c693 | 2013-10-03 16:43:04 +0100 | [diff] [blame] | 5137 | { |
Derek Foreman | 8ae2db5 | 2015-07-15 13:00:36 -0500 | [diff] [blame] | 5138 | if (touch->grab != &touch->default_grab) |
Neil Roberts | a28c693 | 2013-10-03 16:43:04 +0100 | [diff] [blame] | 5139 | return; |
Derek Foreman | 8ae2db5 | 2015-07-15 13:00:36 -0500 | [diff] [blame] | 5140 | if (touch->focus == NULL) |
Kristian Høgsberg | 0ed6750 | 2014-01-02 23:00:11 -0800 | [diff] [blame] | 5141 | return; |
Neil Roberts | a28c693 | 2013-10-03 16:43:04 +0100 | [diff] [blame] | 5142 | |
Jonas Ådahl | cd0f1ac | 2015-06-26 12:37:56 +0800 | [diff] [blame] | 5143 | activate_binding(touch->seat, data, touch->focus); |
Kristian Høgsberg | e1a850e | 2011-12-19 15:18:05 -0500 | [diff] [blame] | 5144 | } |
| 5145 | |
| 5146 | static void |
Neil Roberts | b4a9170 | 2014-04-09 16:33:32 +0100 | [diff] [blame] | 5147 | unfocus_all_seats(struct desktop_shell *shell) |
| 5148 | { |
| 5149 | struct weston_seat *seat, *next; |
| 5150 | |
| 5151 | wl_list_for_each_safe(seat, next, &shell->compositor->seat_list, link) { |
Derek Foreman | 1281a36 | 2015-07-31 16:55:32 -0500 | [diff] [blame] | 5152 | struct weston_keyboard *keyboard = |
| 5153 | weston_seat_get_keyboard(seat); |
| 5154 | |
| 5155 | if (!keyboard) |
Neil Roberts | b4a9170 | 2014-04-09 16:33:32 +0100 | [diff] [blame] | 5156 | continue; |
| 5157 | |
Derek Foreman | 1281a36 | 2015-07-31 16:55:32 -0500 | [diff] [blame] | 5158 | weston_keyboard_set_focus(keyboard, NULL); |
Neil Roberts | b4a9170 | 2014-04-09 16:33:32 +0100 | [diff] [blame] | 5159 | } |
| 5160 | } |
| 5161 | |
| 5162 | static void |
Ander Conselvan de Oliveira | 19d10ef | 2013-02-21 18:35:20 +0200 | [diff] [blame] | 5163 | lock(struct desktop_shell *shell) |
Kristian Høgsberg | 02ec0a5 | 2011-04-23 13:04:11 -0400 | [diff] [blame] | 5164 | { |
Kristian Høgsberg | 4476aaf | 2012-06-25 14:03:13 -0400 | [diff] [blame] | 5165 | struct workspace *ws = get_current_workspace(shell); |
Pekka Paalanen | f0fc70d | 2011-11-15 13:34:54 +0200 | [diff] [blame] | 5166 | |
Tiago Vignatti | 8e53c7f | 2012-02-29 19:53:50 +0200 | [diff] [blame] | 5167 | if (shell->locked) { |
Ander Conselvan de Oliveira | 87524b6 | 2013-02-21 18:35:22 +0200 | [diff] [blame] | 5168 | weston_compositor_sleep(shell->compositor); |
Pekka Paalanen | f0fc70d | 2011-11-15 13:34:54 +0200 | [diff] [blame] | 5169 | return; |
Tiago Vignatti | 8e53c7f | 2012-02-29 19:53:50 +0200 | [diff] [blame] | 5170 | } |
Pekka Paalanen | 9ef3e01 | 2011-11-15 13:34:48 +0200 | [diff] [blame] | 5171 | |
| 5172 | shell->locked = true; |
Pekka Paalanen | f0fc70d | 2011-11-15 13:34:54 +0200 | [diff] [blame] | 5173 | |
Kristian Høgsberg | 3be2ce9 | 2012-02-29 12:42:35 -0500 | [diff] [blame] | 5174 | /* Hide all surfaces by removing the fullscreen, panel and |
| 5175 | * toplevel layers. This way nothing else can show or receive |
| 5176 | * input events while we are locked. */ |
Pekka Paalanen | f0fc70d | 2011-11-15 13:34:54 +0200 | [diff] [blame] | 5177 | |
Kristian Høgsberg | 3be2ce9 | 2012-02-29 12:42:35 -0500 | [diff] [blame] | 5178 | wl_list_remove(&shell->panel_layer.link); |
Kristian Høgsberg | 3be2ce9 | 2012-02-29 12:42:35 -0500 | [diff] [blame] | 5179 | wl_list_remove(&shell->fullscreen_layer.link); |
Philipp Brüschweiler | 711fda8 | 2012-08-09 18:50:43 +0200 | [diff] [blame] | 5180 | if (shell->showing_input_panels) |
| 5181 | wl_list_remove(&shell->input_panel_layer.link); |
Kristian Høgsberg | 4476aaf | 2012-06-25 14:03:13 -0400 | [diff] [blame] | 5182 | wl_list_remove(&ws->layer.link); |
Kristian Høgsberg | 3be2ce9 | 2012-02-29 12:42:35 -0500 | [diff] [blame] | 5183 | wl_list_insert(&shell->compositor->cursor_layer.link, |
| 5184 | &shell->lock_layer.link); |
Pekka Paalanen | f0fc70d | 2011-11-15 13:34:54 +0200 | [diff] [blame] | 5185 | |
Derek Foreman | 004b4a1 | 2015-07-20 16:28:13 -0500 | [diff] [blame] | 5186 | weston_compositor_sleep(shell->compositor); |
| 5187 | |
Neil Roberts | b4a9170 | 2014-04-09 16:33:32 +0100 | [diff] [blame] | 5188 | /* Remove the keyboard focus on all seats. This will be |
| 5189 | * restored to the workspace's saved state via |
| 5190 | * restore_focus_state when the compositor is unlocked */ |
| 5191 | unfocus_all_seats(shell); |
| 5192 | |
Pekka Paalanen | f0fc70d | 2011-11-15 13:34:54 +0200 | [diff] [blame] | 5193 | /* TODO: disable bindings that should not work while locked. */ |
| 5194 | |
| 5195 | /* All this must be undone in resume_desktop(). */ |
Pekka Paalanen | 9ef3e01 | 2011-11-15 13:34:48 +0200 | [diff] [blame] | 5196 | } |
| 5197 | |
| 5198 | static void |
Ander Conselvan de Oliveira | 19d10ef | 2013-02-21 18:35:20 +0200 | [diff] [blame] | 5199 | unlock(struct desktop_shell *shell) |
Pekka Paalanen | 9ef3e01 | 2011-11-15 13:34:48 +0200 | [diff] [blame] | 5200 | { |
Jonas Ådahl | 6d6fb61 | 2015-11-17 16:00:33 +0800 | [diff] [blame] | 5201 | struct wl_resource *shell_resource; |
| 5202 | |
Pekka Paalanen | d81c216 | 2011-11-16 13:47:34 +0200 | [diff] [blame] | 5203 | if (!shell->locked || shell->lock_surface) { |
Ander Conselvan de Oliveira | 87524b6 | 2013-02-21 18:35:22 +0200 | [diff] [blame] | 5204 | shell_fade(shell, FADE_IN); |
Pekka Paalanen | 9ef3e01 | 2011-11-15 13:34:48 +0200 | [diff] [blame] | 5205 | return; |
| 5206 | } |
| 5207 | |
| 5208 | /* If desktop-shell client has gone away, unlock immediately. */ |
| 5209 | if (!shell->child.desktop_shell) { |
Pekka Paalanen | f0fc70d | 2011-11-15 13:34:54 +0200 | [diff] [blame] | 5210 | resume_desktop(shell); |
Pekka Paalanen | 9ef3e01 | 2011-11-15 13:34:48 +0200 | [diff] [blame] | 5211 | return; |
| 5212 | } |
| 5213 | |
| 5214 | if (shell->prepare_event_sent) |
| 5215 | return; |
| 5216 | |
Jonas Ådahl | 6d6fb61 | 2015-11-17 16:00:33 +0800 | [diff] [blame] | 5217 | shell_resource = shell->child.desktop_shell; |
| 5218 | weston_desktop_shell_send_prepare_lock_surface(shell_resource); |
Pekka Paalanen | 9ef3e01 | 2011-11-15 13:34:48 +0200 | [diff] [blame] | 5219 | shell->prepare_event_sent = true; |
Kristian Høgsberg | 02ec0a5 | 2011-04-23 13:04:11 -0400 | [diff] [blame] | 5220 | } |
| 5221 | |
| 5222 | static void |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 5223 | shell_fade_done(struct weston_view_animation *animation, void *data) |
Ander Conselvan de Oliveira | 19d10ef | 2013-02-21 18:35:20 +0200 | [diff] [blame] | 5224 | { |
| 5225 | struct desktop_shell *shell = data; |
| 5226 | |
| 5227 | shell->fade.animation = NULL; |
| 5228 | |
| 5229 | switch (shell->fade.type) { |
| 5230 | case FADE_IN: |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 5231 | weston_surface_destroy(shell->fade.view->surface); |
| 5232 | shell->fade.view = NULL; |
Ander Conselvan de Oliveira | 19d10ef | 2013-02-21 18:35:20 +0200 | [diff] [blame] | 5233 | break; |
| 5234 | case FADE_OUT: |
Ander Conselvan de Oliveira | 19d10ef | 2013-02-21 18:35:20 +0200 | [diff] [blame] | 5235 | lock(shell); |
| 5236 | break; |
Philip Withnall | 4a86a0a | 2013-11-25 18:01:32 +0000 | [diff] [blame] | 5237 | default: |
| 5238 | break; |
Ander Conselvan de Oliveira | 19d10ef | 2013-02-21 18:35:20 +0200 | [diff] [blame] | 5239 | } |
| 5240 | } |
| 5241 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 5242 | static struct weston_view * |
Pekka Paalanen | 79346ab | 2013-05-22 18:03:09 +0300 | [diff] [blame] | 5243 | shell_fade_create_surface(struct desktop_shell *shell) |
Ander Conselvan de Oliveira | 19d10ef | 2013-02-21 18:35:20 +0200 | [diff] [blame] | 5244 | { |
| 5245 | struct weston_compositor *compositor = shell->compositor; |
| 5246 | struct weston_surface *surface; |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 5247 | struct weston_view *view; |
Pekka Paalanen | 79346ab | 2013-05-22 18:03:09 +0300 | [diff] [blame] | 5248 | |
| 5249 | surface = weston_surface_create(compositor); |
| 5250 | if (!surface) |
| 5251 | return NULL; |
| 5252 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 5253 | view = weston_view_create(surface); |
| 5254 | if (!view) { |
| 5255 | weston_surface_destroy(surface); |
| 5256 | return NULL; |
| 5257 | } |
| 5258 | |
Jason Ekstrand | 5c11a33 | 2013-12-04 20:32:03 -0600 | [diff] [blame] | 5259 | weston_surface_set_size(surface, 8192, 8192); |
Jason Ekstrand | 918f2dd | 2013-12-02 21:01:53 -0600 | [diff] [blame] | 5260 | weston_view_set_position(view, 0, 0); |
Pekka Paalanen | 79346ab | 2013-05-22 18:03:09 +0300 | [diff] [blame] | 5261 | 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] | 5262 | weston_layer_entry_insert(&compositor->fade_layer.view_list, |
| 5263 | &view->layer_link); |
Pekka Paalanen | 79346ab | 2013-05-22 18:03:09 +0300 | [diff] [blame] | 5264 | pixman_region32_init(&surface->input); |
| 5265 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 5266 | return view; |
Pekka Paalanen | 79346ab | 2013-05-22 18:03:09 +0300 | [diff] [blame] | 5267 | } |
| 5268 | |
| 5269 | static void |
| 5270 | shell_fade(struct desktop_shell *shell, enum fade_type type) |
| 5271 | { |
Ander Conselvan de Oliveira | 19d10ef | 2013-02-21 18:35:20 +0200 | [diff] [blame] | 5272 | float tint; |
| 5273 | |
| 5274 | switch (type) { |
| 5275 | case FADE_IN: |
| 5276 | tint = 0.0; |
| 5277 | break; |
| 5278 | case FADE_OUT: |
| 5279 | tint = 1.0; |
| 5280 | break; |
| 5281 | default: |
| 5282 | weston_log("shell: invalid fade type\n"); |
| 5283 | return; |
| 5284 | } |
| 5285 | |
| 5286 | shell->fade.type = type; |
| 5287 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 5288 | if (shell->fade.view == NULL) { |
| 5289 | shell->fade.view = shell_fade_create_surface(shell); |
| 5290 | if (!shell->fade.view) |
Ander Conselvan de Oliveira | 19d10ef | 2013-02-21 18:35:20 +0200 | [diff] [blame] | 5291 | return; |
| 5292 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 5293 | shell->fade.view->alpha = 1.0 - tint; |
| 5294 | weston_view_update_transform(shell->fade.view); |
Ander Conselvan de Oliveira | 19d10ef | 2013-02-21 18:35:20 +0200 | [diff] [blame] | 5295 | } |
| 5296 | |
Kristian Høgsberg | 87d3b61 | 2014-01-19 21:48:10 -0800 | [diff] [blame] | 5297 | if (shell->fade.view->output == NULL) { |
| 5298 | /* If the black view gets a NULL output, we lost the |
| 5299 | * last output and we'll just cancel the fade. This |
| 5300 | * happens when you close the last window under the |
| 5301 | * X11 or Wayland backends. */ |
| 5302 | shell->locked = false; |
| 5303 | weston_surface_destroy(shell->fade.view->surface); |
| 5304 | shell->fade.view = NULL; |
| 5305 | } else if (shell->fade.animation) { |
Kristian Høgsberg | 5281fb1 | 2013-06-17 10:10:28 -0400 | [diff] [blame] | 5306 | weston_fade_update(shell->fade.animation, tint); |
Kristian Høgsberg | 87d3b61 | 2014-01-19 21:48:10 -0800 | [diff] [blame] | 5307 | } else { |
Ander Conselvan de Oliveira | 19d10ef | 2013-02-21 18:35:20 +0200 | [diff] [blame] | 5308 | shell->fade.animation = |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 5309 | weston_fade_run(shell->fade.view, |
Kristian Høgsberg | 5281fb1 | 2013-06-17 10:10:28 -0400 | [diff] [blame] | 5310 | 1.0 - tint, tint, 300.0, |
Ander Conselvan de Oliveira | 19d10ef | 2013-02-21 18:35:20 +0200 | [diff] [blame] | 5311 | shell_fade_done, shell); |
Kristian Høgsberg | 87d3b61 | 2014-01-19 21:48:10 -0800 | [diff] [blame] | 5312 | } |
Ander Conselvan de Oliveira | 19d10ef | 2013-02-21 18:35:20 +0200 | [diff] [blame] | 5313 | } |
| 5314 | |
| 5315 | static void |
Pekka Paalanen | 79346ab | 2013-05-22 18:03:09 +0300 | [diff] [blame] | 5316 | do_shell_fade_startup(void *data) |
| 5317 | { |
| 5318 | struct desktop_shell *shell = data; |
| 5319 | |
Pekka Paalanen | 23ed5f2 | 2015-05-26 11:54:52 +0300 | [diff] [blame] | 5320 | if (shell->startup_animation_type == ANIMATION_FADE) { |
Kristian Høgsberg | 724c8d9 | 2013-10-16 11:38:24 -0700 | [diff] [blame] | 5321 | shell_fade(shell, FADE_IN); |
Pekka Paalanen | 23ed5f2 | 2015-05-26 11:54:52 +0300 | [diff] [blame] | 5322 | } else { |
| 5323 | weston_log("desktop shell: " |
| 5324 | "unexpected fade-in animation type %d\n", |
| 5325 | shell->startup_animation_type); |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 5326 | weston_surface_destroy(shell->fade.view->surface); |
| 5327 | shell->fade.view = NULL; |
Kristian Høgsberg | 724c8d9 | 2013-10-16 11:38:24 -0700 | [diff] [blame] | 5328 | } |
Pekka Paalanen | 79346ab | 2013-05-22 18:03:09 +0300 | [diff] [blame] | 5329 | } |
| 5330 | |
| 5331 | static void |
| 5332 | shell_fade_startup(struct desktop_shell *shell) |
| 5333 | { |
| 5334 | struct wl_event_loop *loop; |
| 5335 | |
| 5336 | if (!shell->fade.startup_timer) |
| 5337 | return; |
| 5338 | |
| 5339 | wl_event_source_remove(shell->fade.startup_timer); |
| 5340 | shell->fade.startup_timer = NULL; |
| 5341 | |
| 5342 | loop = wl_display_get_event_loop(shell->compositor->wl_display); |
| 5343 | wl_event_loop_add_idle(loop, do_shell_fade_startup, shell); |
| 5344 | } |
| 5345 | |
| 5346 | static int |
| 5347 | fade_startup_timeout(void *data) |
| 5348 | { |
| 5349 | struct desktop_shell *shell = data; |
| 5350 | |
| 5351 | shell_fade_startup(shell); |
| 5352 | return 0; |
| 5353 | } |
| 5354 | |
| 5355 | static void |
| 5356 | shell_fade_init(struct desktop_shell *shell) |
| 5357 | { |
| 5358 | /* Make compositor output all black, and wait for the desktop-shell |
| 5359 | * client to signal it is ready, then fade in. The timer triggers a |
| 5360 | * fade-in, in case the desktop-shell client takes too long. |
| 5361 | */ |
| 5362 | |
| 5363 | struct wl_event_loop *loop; |
| 5364 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 5365 | if (shell->fade.view != NULL) { |
Pekka Paalanen | 79346ab | 2013-05-22 18:03:09 +0300 | [diff] [blame] | 5366 | weston_log("%s: warning: fade surface already exists\n", |
| 5367 | __func__); |
| 5368 | return; |
| 5369 | } |
| 5370 | |
Pekka Paalanen | 23ed5f2 | 2015-05-26 11:54:52 +0300 | [diff] [blame] | 5371 | if (shell->startup_animation_type == ANIMATION_NONE) |
| 5372 | return; |
| 5373 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 5374 | shell->fade.view = shell_fade_create_surface(shell); |
| 5375 | if (!shell->fade.view) |
Pekka Paalanen | 79346ab | 2013-05-22 18:03:09 +0300 | [diff] [blame] | 5376 | return; |
| 5377 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 5378 | weston_view_update_transform(shell->fade.view); |
| 5379 | weston_surface_damage(shell->fade.view->surface); |
Pekka Paalanen | 79346ab | 2013-05-22 18:03:09 +0300 | [diff] [blame] | 5380 | |
| 5381 | loop = wl_display_get_event_loop(shell->compositor->wl_display); |
| 5382 | shell->fade.startup_timer = |
| 5383 | wl_event_loop_add_timer(loop, fade_startup_timeout, shell); |
| 5384 | wl_event_source_timer_update(shell->fade.startup_timer, 15000); |
| 5385 | } |
| 5386 | |
| 5387 | static void |
Ander Conselvan de Oliveira | a457563 | 2013-02-21 18:35:23 +0200 | [diff] [blame] | 5388 | idle_handler(struct wl_listener *listener, void *data) |
Ander Conselvan de Oliveira | 19d10ef | 2013-02-21 18:35:20 +0200 | [diff] [blame] | 5389 | { |
| 5390 | struct desktop_shell *shell = |
Ander Conselvan de Oliveira | a457563 | 2013-02-21 18:35:23 +0200 | [diff] [blame] | 5391 | container_of(listener, struct desktop_shell, idle_listener); |
Kristian Høgsberg | 27d5fa8 | 2014-01-17 16:22:50 -0800 | [diff] [blame] | 5392 | struct weston_seat *seat; |
| 5393 | |
Jonny Lamb | 76cf1fe | 2014-08-20 11:27:10 +0200 | [diff] [blame] | 5394 | wl_list_for_each(seat, &shell->compositor->seat_list, link) { |
Derek Foreman | 1281a36 | 2015-07-31 16:55:32 -0500 | [diff] [blame] | 5395 | struct weston_touch *touch = weston_seat_get_touch(seat); |
| 5396 | struct weston_pointer *pointer = weston_seat_get_pointer(seat); |
| 5397 | |
| 5398 | if (pointer) |
| 5399 | popup_grab_end(pointer); |
| 5400 | if (touch) |
| 5401 | touch_popup_grab_end(touch); |
Jonny Lamb | 76cf1fe | 2014-08-20 11:27:10 +0200 | [diff] [blame] | 5402 | } |
Ander Conselvan de Oliveira | 19d10ef | 2013-02-21 18:35:20 +0200 | [diff] [blame] | 5403 | |
| 5404 | shell_fade(shell, FADE_OUT); |
| 5405 | /* lock() is called from shell_fade_done() */ |
| 5406 | } |
| 5407 | |
| 5408 | static void |
Ander Conselvan de Oliveira | a457563 | 2013-02-21 18:35:23 +0200 | [diff] [blame] | 5409 | wake_handler(struct wl_listener *listener, void *data) |
Ander Conselvan de Oliveira | 19d10ef | 2013-02-21 18:35:20 +0200 | [diff] [blame] | 5410 | { |
| 5411 | struct desktop_shell *shell = |
Ander Conselvan de Oliveira | a457563 | 2013-02-21 18:35:23 +0200 | [diff] [blame] | 5412 | container_of(listener, struct desktop_shell, wake_listener); |
Ander Conselvan de Oliveira | 19d10ef | 2013-02-21 18:35:20 +0200 | [diff] [blame] | 5413 | |
Ander Conselvan de Oliveira | 19d10ef | 2013-02-21 18:35:20 +0200 | [diff] [blame] | 5414 | unlock(shell); |
| 5415 | } |
| 5416 | |
| 5417 | static void |
Giulio Camuffo | f05d18f | 2015-12-11 20:57:05 +0200 | [diff] [blame] | 5418 | transform_handler(struct wl_listener *listener, void *data) |
| 5419 | { |
| 5420 | struct weston_surface *surface = data; |
| 5421 | struct shell_surface *shsurf = get_shell_surface(surface); |
| 5422 | struct weston_view *view;; |
| 5423 | int x, y; |
| 5424 | |
| 5425 | if (!shsurf || !shsurf->client->send_position) |
| 5426 | return; |
| 5427 | |
| 5428 | view = shsurf->view; |
| 5429 | if (!view || !weston_view_is_mapped(view)) |
| 5430 | return; |
| 5431 | |
| 5432 | x = view->geometry.x; |
| 5433 | y = view->geometry.y; |
| 5434 | |
| 5435 | shsurf->client->send_position(surface, x, y); |
| 5436 | } |
| 5437 | |
| 5438 | static void |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 5439 | center_on_output(struct weston_view *view, struct weston_output *output) |
Pekka Paalanen | 77346a6 | 2011-11-30 16:26:35 +0200 | [diff] [blame] | 5440 | { |
Giulio Camuffo | b836664 | 2013-04-25 13:57:46 +0300 | [diff] [blame] | 5441 | int32_t surf_x, surf_y, width, height; |
Ander Conselvan de Oliveira | 012b4c7 | 2012-11-27 17:03:42 +0200 | [diff] [blame] | 5442 | float x, y; |
Pekka Paalanen | 77346a6 | 2011-11-30 16:26:35 +0200 | [diff] [blame] | 5443 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 5444 | surface_subsurfaces_boundingbox(view->surface, &surf_x, &surf_y, &width, &height); |
Giulio Camuffo | b836664 | 2013-04-25 13:57:46 +0300 | [diff] [blame] | 5445 | |
| 5446 | x = output->x + (output->width - width) / 2 - surf_x / 2; |
| 5447 | y = output->y + (output->height - height) / 2 - surf_y / 2; |
Ander Conselvan de Oliveira | 012b4c7 | 2012-11-27 17:03:42 +0200 | [diff] [blame] | 5448 | |
Jason Ekstrand | 918f2dd | 2013-12-02 21:01:53 -0600 | [diff] [blame] | 5449 | weston_view_set_position(view, x, y); |
Pekka Paalanen | 77346a6 | 2011-11-30 16:26:35 +0200 | [diff] [blame] | 5450 | } |
| 5451 | |
| 5452 | static void |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 5453 | weston_view_set_initial_position(struct weston_view *view, |
| 5454 | struct desktop_shell *shell) |
Rob Bradford | ac63e5b | 2012-08-13 14:07:52 +0100 | [diff] [blame] | 5455 | { |
| 5456 | struct weston_compositor *compositor = shell->compositor; |
| 5457 | int ix = 0, iy = 0; |
Jonny Lamb | d73c694 | 2014-08-20 15:53:20 +0200 | [diff] [blame] | 5458 | int32_t range_x, range_y; |
Derek Foreman | f814c5d | 2015-04-15 12:23:54 -0500 | [diff] [blame] | 5459 | int32_t x, y; |
Rob Bradford | ac63e5b | 2012-08-13 14:07:52 +0100 | [diff] [blame] | 5460 | struct weston_output *output, *target_output = NULL; |
| 5461 | struct weston_seat *seat; |
Jonny Lamb | d73c694 | 2014-08-20 15:53:20 +0200 | [diff] [blame] | 5462 | pixman_rectangle32_t area; |
Rob Bradford | ac63e5b | 2012-08-13 14:07:52 +0100 | [diff] [blame] | 5463 | |
| 5464 | /* As a heuristic place the new window on the same output as the |
| 5465 | * pointer. Falling back to the output containing 0, 0. |
| 5466 | * |
| 5467 | * TODO: Do something clever for touch too? |
| 5468 | */ |
| 5469 | wl_list_for_each(seat, &compositor->seat_list, link) { |
Derek Foreman | 1281a36 | 2015-07-31 16:55:32 -0500 | [diff] [blame] | 5470 | struct weston_pointer *pointer = weston_seat_get_pointer(seat); |
| 5471 | |
| 5472 | if (pointer) { |
| 5473 | ix = wl_fixed_to_int(pointer->x); |
| 5474 | iy = wl_fixed_to_int(pointer->y); |
Rob Bradford | ac63e5b | 2012-08-13 14:07:52 +0100 | [diff] [blame] | 5475 | break; |
| 5476 | } |
| 5477 | } |
| 5478 | |
| 5479 | wl_list_for_each(output, &compositor->output_list, link) { |
| 5480 | if (pixman_region32_contains_point(&output->region, ix, iy, NULL)) { |
| 5481 | target_output = output; |
| 5482 | break; |
| 5483 | } |
| 5484 | } |
| 5485 | |
| 5486 | if (!target_output) { |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 5487 | weston_view_set_position(view, 10 + random() % 400, |
| 5488 | 10 + random() % 400); |
Rob Bradford | ac63e5b | 2012-08-13 14:07:52 +0100 | [diff] [blame] | 5489 | return; |
| 5490 | } |
| 5491 | |
| 5492 | /* Valid range within output where the surface will still be onscreen. |
| 5493 | * If this is negative it means that the surface is bigger than |
| 5494 | * output. |
| 5495 | */ |
Jonny Lamb | d73c694 | 2014-08-20 15:53:20 +0200 | [diff] [blame] | 5496 | get_output_work_area(shell, target_output, &area); |
| 5497 | |
Derek Foreman | f814c5d | 2015-04-15 12:23:54 -0500 | [diff] [blame] | 5498 | x = area.x; |
| 5499 | y = area.y; |
Jonny Lamb | d73c694 | 2014-08-20 15:53:20 +0200 | [diff] [blame] | 5500 | range_x = area.width - view->surface->width; |
| 5501 | range_y = area.height - view->surface->height; |
Rob Bradford | ac63e5b | 2012-08-13 14:07:52 +0100 | [diff] [blame] | 5502 | |
Rob Bradford | 4cb88c7 | 2012-08-13 15:18:44 +0100 | [diff] [blame] | 5503 | if (range_x > 0) |
Derek Foreman | f814c5d | 2015-04-15 12:23:54 -0500 | [diff] [blame] | 5504 | x += random() % range_x; |
Rob Bradford | 4cb88c7 | 2012-08-13 15:18:44 +0100 | [diff] [blame] | 5505 | |
| 5506 | if (range_y > 0) |
Derek Foreman | f814c5d | 2015-04-15 12:23:54 -0500 | [diff] [blame] | 5507 | y += random() % range_y; |
Rob Bradford | ac63e5b | 2012-08-13 14:07:52 +0100 | [diff] [blame] | 5508 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 5509 | weston_view_set_position(view, x, y); |
Rob Bradford | ac63e5b | 2012-08-13 14:07:52 +0100 | [diff] [blame] | 5510 | } |
| 5511 | |
| 5512 | static void |
Jonny Lamb | d73c694 | 2014-08-20 15:53:20 +0200 | [diff] [blame] | 5513 | set_maximized_position(struct desktop_shell *shell, |
| 5514 | struct shell_surface *shsurf) |
| 5515 | { |
| 5516 | int32_t surf_x, surf_y; |
| 5517 | pixman_rectangle32_t area; |
| 5518 | |
Jonny Lamb | d73c694 | 2014-08-20 15:53:20 +0200 | [diff] [blame] | 5519 | get_output_work_area(shell, shsurf->output, &area); |
Giulio Camuffo | 7a8d67d | 2015-01-09 20:10:45 +0200 | [diff] [blame] | 5520 | if (shsurf->has_set_geometry) { |
| 5521 | surf_x = shsurf->geometry.x; |
| 5522 | surf_y = shsurf->geometry.y; |
| 5523 | } else { |
| 5524 | surface_subsurfaces_boundingbox(shsurf->surface, |
| 5525 | &surf_x, &surf_y, NULL, NULL); |
| 5526 | } |
Jonny Lamb | d73c694 | 2014-08-20 15:53:20 +0200 | [diff] [blame] | 5527 | |
| 5528 | weston_view_set_position(shsurf->view, |
Marek Chalupa | 6ce7899 | 2015-10-09 18:17:07 +0200 | [diff] [blame] | 5529 | area.x - surf_x, |
| 5530 | area.y - surf_y); |
Jonny Lamb | d73c694 | 2014-08-20 15:53:20 +0200 | [diff] [blame] | 5531 | } |
| 5532 | |
| 5533 | static void |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 5534 | map(struct desktop_shell *shell, struct shell_surface *shsurf, |
Jason Ekstrand | 918f2dd | 2013-12-02 21:01:53 -0600 | [diff] [blame] | 5535 | int32_t sx, int32_t sy) |
Kristian Høgsberg | 02ec0a5 | 2011-04-23 13:04:11 -0400 | [diff] [blame] | 5536 | { |
Kristian Høgsberg | 8334bc1 | 2012-01-03 10:29:47 -0500 | [diff] [blame] | 5537 | struct weston_compositor *compositor = shell->compositor; |
Daniel Stone | b210468 | 2012-05-30 16:31:56 +0100 | [diff] [blame] | 5538 | struct weston_seat *seat; |
Pekka Paalanen | 57da4a8 | 2011-11-23 16:42:16 +0200 | [diff] [blame] | 5539 | |
Pekka Paalanen | 77346a6 | 2011-11-30 16:26:35 +0200 | [diff] [blame] | 5540 | /* initial positioning, see also configure() */ |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 5541 | switch (shsurf->type) { |
Rafael Antognolli | ed207b4 | 2013-12-03 15:35:43 -0200 | [diff] [blame] | 5542 | case SHELL_SURFACE_TOPLEVEL: |
Rafael Antognolli | 03b1659 | 2013-12-03 15:35:42 -0200 | [diff] [blame] | 5543 | if (shsurf->state.fullscreen) { |
| 5544 | center_on_output(shsurf->view, shsurf->fullscreen_output); |
| 5545 | shell_map_fullscreen(shsurf); |
| 5546 | } else if (shsurf->state.maximized) { |
Jonny Lamb | d73c694 | 2014-08-20 15:53:20 +0200 | [diff] [blame] | 5547 | set_maximized_position(shell, shsurf); |
Rafael Antognolli | ed207b4 | 2013-12-03 15:35:43 -0200 | [diff] [blame] | 5548 | } else if (!shsurf->state.relative) { |
Rafael Antognolli | 03b1659 | 2013-12-03 15:35:42 -0200 | [diff] [blame] | 5549 | weston_view_set_initial_position(shsurf->view, shell); |
| 5550 | } |
Juan Zhao | 96879df | 2012-02-07 08:45:41 +0800 | [diff] [blame] | 5551 | break; |
Tiago Vignatti | 0f99701 | 2012-02-10 16:17:23 +0200 | [diff] [blame] | 5552 | case SHELL_SURFACE_POPUP: |
Jasper St. Pierre | da6ecd0 | 2015-02-27 18:35:45 +0800 | [diff] [blame] | 5553 | if (shell_map_popup(shsurf) != 0) |
| 5554 | return; |
Rob Bradford | db99938 | 2012-12-06 12:07:48 +0000 | [diff] [blame] | 5555 | break; |
Ander Conselvan de Oliveira | e9e0515 | 2012-02-15 17:02:56 +0200 | [diff] [blame] | 5556 | case SHELL_SURFACE_NONE: |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 5557 | weston_view_set_position(shsurf->view, |
| 5558 | shsurf->view->geometry.x + sx, |
| 5559 | shsurf->view->geometry.y + sy); |
Tiago Vignatti | 0f99701 | 2012-02-10 16:17:23 +0200 | [diff] [blame] | 5560 | break; |
Philip Withnall | 0f640e2 | 2013-11-25 18:01:31 +0000 | [diff] [blame] | 5561 | case SHELL_SURFACE_XWAYLAND: |
Pekka Paalanen | 77346a6 | 2011-11-30 16:26:35 +0200 | [diff] [blame] | 5562 | default: |
| 5563 | ; |
| 5564 | } |
Kristian Høgsberg | 7584062 | 2011-09-06 13:48:16 -0400 | [diff] [blame] | 5565 | |
Philip Withnall | e1d75ae | 2013-11-25 18:01:41 +0000 | [diff] [blame] | 5566 | /* Surface stacking order, see also activate(). */ |
| 5567 | shell_surface_update_layer(shsurf); |
Pekka Paalanen | f0fc70d | 2011-11-15 13:34:54 +0200 | [diff] [blame] | 5568 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 5569 | if (shsurf->type != SHELL_SURFACE_NONE) { |
| 5570 | weston_view_update_transform(shsurf->view); |
Rafael Antognolli | 03b1659 | 2013-12-03 15:35:42 -0200 | [diff] [blame] | 5571 | if (shsurf->state.maximized) { |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 5572 | shsurf->surface->output = shsurf->output; |
| 5573 | shsurf->view->output = shsurf->output; |
| 5574 | } |
Ander Conselvan de Oliveira | de56c31 | 2012-03-05 15:39:23 +0200 | [diff] [blame] | 5575 | } |
Kristian Høgsberg | 2f88a40 | 2011-12-04 15:32:59 -0500 | [diff] [blame] | 5576 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 5577 | switch (shsurf->type) { |
Tiago Vignatti | fb2adba | 2013-06-12 15:43:21 -0300 | [diff] [blame] | 5578 | /* XXX: xwayland's using the same fields for transient type */ |
| 5579 | case SHELL_SURFACE_XWAYLAND: |
Tiago Vignatti | 99aeb1e | 2012-05-23 22:06:26 +0300 | [diff] [blame] | 5580 | if (shsurf->transient.flags == |
| 5581 | WL_SHELL_SURFACE_TRANSIENT_INACTIVE) |
| 5582 | break; |
| 5583 | case SHELL_SURFACE_TOPLEVEL: |
Rafael Antognolli | ed207b4 | 2013-12-03 15:35:43 -0200 | [diff] [blame] | 5584 | if (shsurf->state.relative && |
| 5585 | shsurf->transient.flags == WL_SHELL_SURFACE_TRANSIENT_INACTIVE) |
| 5586 | break; |
Rafael Antognolli | ba5d2d7 | 2013-12-04 17:49:55 -0200 | [diff] [blame] | 5587 | if (shell->locked) |
Rafael Antognolli | ed207b4 | 2013-12-03 15:35:43 -0200 | [diff] [blame] | 5588 | break; |
| 5589 | wl_list_for_each(seat, &compositor->seat_list, link) |
Emilio Pozuelo Monfort | 9e7c759 | 2014-01-30 14:01:10 +0100 | [diff] [blame] | 5590 | activate(shell, shsurf->surface, seat, true); |
Juan Zhao | 7bb92f0 | 2011-12-15 11:31:51 -0500 | [diff] [blame] | 5591 | break; |
Philip Withnall | 0f640e2 | 2013-11-25 18:01:31 +0000 | [diff] [blame] | 5592 | case SHELL_SURFACE_POPUP: |
| 5593 | case SHELL_SURFACE_NONE: |
Juan Zhao | 7bb92f0 | 2011-12-15 11:31:51 -0500 | [diff] [blame] | 5594 | default: |
| 5595 | break; |
| 5596 | } |
| 5597 | |
Rafael Antognolli | 03b1659 | 2013-12-03 15:35:42 -0200 | [diff] [blame] | 5598 | if (shsurf->type == SHELL_SURFACE_TOPLEVEL && |
| 5599 | !shsurf->state.maximized && !shsurf->state.fullscreen) |
Juan Zhao | e10d279 | 2012-04-25 19:09:52 +0800 | [diff] [blame] | 5600 | { |
| 5601 | switch (shell->win_animation_type) { |
| 5602 | case ANIMATION_FADE: |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 5603 | 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] | 5604 | break; |
| 5605 | case ANIMATION_ZOOM: |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 5606 | weston_zoom_run(shsurf->view, 0.5, 1.0, NULL, NULL); |
Juan Zhao | e10d279 | 2012-04-25 19:09:52 +0800 | [diff] [blame] | 5607 | break; |
Philip Withnall | 4a86a0a | 2013-11-25 18:01:32 +0000 | [diff] [blame] | 5608 | case ANIMATION_NONE: |
Juan Zhao | e10d279 | 2012-04-25 19:09:52 +0800 | [diff] [blame] | 5609 | default: |
| 5610 | break; |
| 5611 | } |
| 5612 | } |
Kristian Høgsberg | 32e24cc | 2011-11-09 12:07:35 -0500 | [diff] [blame] | 5613 | } |
| 5614 | |
| 5615 | static void |
Tiago Vignatti | be14326 | 2012-04-16 17:31:41 +0300 | [diff] [blame] | 5616 | configure(struct desktop_shell *shell, struct weston_surface *surface, |
Jason Ekstrand | 918f2dd | 2013-12-02 21:01:53 -0600 | [diff] [blame] | 5617 | float x, float y) |
Kristian Høgsberg | 32e24cc | 2011-11-09 12:07:35 -0500 | [diff] [blame] | 5618 | { |
Pekka Paalanen | 77346a6 | 2011-11-30 16:26:35 +0200 | [diff] [blame] | 5619 | struct shell_surface *shsurf; |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 5620 | struct weston_view *view; |
Kristian Høgsberg | 32e24cc | 2011-11-09 12:07:35 -0500 | [diff] [blame] | 5621 | |
Pekka Paalanen | 77346a6 | 2011-11-30 16:26:35 +0200 | [diff] [blame] | 5622 | shsurf = get_shell_surface(surface); |
Pekka Paalanen | 77346a6 | 2011-11-30 16:26:35 +0200 | [diff] [blame] | 5623 | |
U. Artie Eoff | cf5737a | 2014-01-17 10:08:25 -0800 | [diff] [blame] | 5624 | assert(shsurf); |
| 5625 | |
Rafael Antognolli | 03b1659 | 2013-12-03 15:35:42 -0200 | [diff] [blame] | 5626 | if (shsurf->state.fullscreen) |
Alex Wu | 4539b08 | 2012-03-01 12:57:46 +0800 | [diff] [blame] | 5627 | shell_configure_fullscreen(shsurf); |
Rafael Antognolli | 03b1659 | 2013-12-03 15:35:42 -0200 | [diff] [blame] | 5628 | else if (shsurf->state.maximized) { |
Jonny Lamb | d73c694 | 2014-08-20 15:53:20 +0200 | [diff] [blame] | 5629 | set_maximized_position(shell, shsurf); |
Rafael Antognolli | 03b1659 | 2013-12-03 15:35:42 -0200 | [diff] [blame] | 5630 | } else { |
Jason Ekstrand | 918f2dd | 2013-12-02 21:01:53 -0600 | [diff] [blame] | 5631 | weston_view_set_position(shsurf->view, x, y); |
Kristian Høgsberg | 7a5c979 | 2011-06-18 06:12:54 -0400 | [diff] [blame] | 5632 | } |
Kristian Høgsberg | 32e24cc | 2011-11-09 12:07:35 -0500 | [diff] [blame] | 5633 | |
Alex Wu | 4539b08 | 2012-03-01 12:57:46 +0800 | [diff] [blame] | 5634 | /* XXX: would a fullscreen surface need the same handling? */ |
Kristian Høgsberg | 6a8b553 | 2012-02-16 23:43:59 -0500 | [diff] [blame] | 5635 | if (surface->output) { |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 5636 | wl_list_for_each(view, &surface->views, surface_link) |
| 5637 | weston_view_update_transform(view); |
Pekka Paalanen | 77346a6 | 2011-11-30 16:26:35 +0200 | [diff] [blame] | 5638 | |
Rafael Antognolli | 03b1659 | 2013-12-03 15:35:42 -0200 | [diff] [blame] | 5639 | if (shsurf->state.maximized) |
Juan Zhao | 96879df | 2012-02-07 08:45:41 +0800 | [diff] [blame] | 5640 | surface->output = shsurf->output; |
Pekka Paalanen | 77346a6 | 2011-11-30 16:26:35 +0200 | [diff] [blame] | 5641 | } |
Kristian Høgsberg | 0793756 | 2011-04-12 17:25:42 -0400 | [diff] [blame] | 5642 | } |
| 5643 | |
Ander Conselvan de Oliveira | 093bfa3 | 2012-03-27 17:36:41 +0300 | [diff] [blame] | 5644 | static void |
Jason Ekstrand | 918f2dd | 2013-12-02 21:01:53 -0600 | [diff] [blame] | 5645 | 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] | 5646 | { |
Ander Conselvan de Oliveira | 7fb9f95 | 2012-03-27 17:36:42 +0300 | [diff] [blame] | 5647 | struct shell_surface *shsurf = get_shell_surface(es); |
U. Artie Eoff | cf5737a | 2014-01-17 10:08:25 -0800 | [diff] [blame] | 5648 | struct desktop_shell *shell; |
Tiago Vignatti | 70e5c9c | 2012-05-07 15:23:07 +0300 | [diff] [blame] | 5649 | int type_changed = 0; |
Ander Conselvan de Oliveira | 093bfa3 | 2012-03-27 17:36:41 +0300 | [diff] [blame] | 5650 | |
U. Artie Eoff | cf5737a | 2014-01-17 10:08:25 -0800 | [diff] [blame] | 5651 | assert(shsurf); |
| 5652 | |
| 5653 | shell = shsurf->shell; |
| 5654 | |
Kristian Høgsberg | 8eb0f4f | 2013-06-17 10:33:14 -0400 | [diff] [blame] | 5655 | if (!weston_surface_is_mapped(es) && |
| 5656 | !wl_list_empty(&shsurf->popup.grab_link)) { |
Giulio Camuffo | 5085a75 | 2013-03-25 21:42:45 +0100 | [diff] [blame] | 5657 | remove_popup_grab(shsurf); |
| 5658 | } |
| 5659 | |
Jason Ekstrand | 918f2dd | 2013-12-02 21:01:53 -0600 | [diff] [blame] | 5660 | if (es->width == 0) |
Giulio Camuffo | 184df50 | 2013-02-21 11:29:21 +0100 | [diff] [blame] | 5661 | return; |
| 5662 | |
Jasper St. Pierre | ccf48fb | 2014-05-02 10:21:38 -0400 | [diff] [blame] | 5663 | if (shsurf->has_next_geometry) { |
| 5664 | shsurf->geometry = shsurf->next_geometry; |
| 5665 | shsurf->has_next_geometry = false; |
| 5666 | shsurf->has_set_geometry = true; |
| 5667 | } else if (!shsurf->has_set_geometry) { |
| 5668 | surface_subsurfaces_boundingbox(shsurf->surface, |
| 5669 | &shsurf->geometry.x, |
| 5670 | &shsurf->geometry.y, |
| 5671 | &shsurf->geometry.width, |
| 5672 | &shsurf->geometry.height); |
Jasper St. Pierre | 851799e | 2014-05-02 10:14:07 -0400 | [diff] [blame] | 5673 | } |
| 5674 | |
Kristian Høgsberg | c8f8dd8 | 2013-12-05 23:20:33 -0800 | [diff] [blame] | 5675 | if (shsurf->state_changed) { |
Kristian Høgsberg | 7f366e7 | 2012-04-27 17:20:01 -0400 | [diff] [blame] | 5676 | set_surface_type(shsurf); |
Kristian Høgsberg | f7e23d5 | 2012-04-27 17:51:59 -0400 | [diff] [blame] | 5677 | type_changed = 1; |
| 5678 | } |
Kristian Høgsberg | 7f366e7 | 2012-04-27 17:20:01 -0400 | [diff] [blame] | 5679 | |
Ander Conselvan de Oliveira | 093bfa3 | 2012-03-27 17:36:41 +0300 | [diff] [blame] | 5680 | if (!weston_surface_is_mapped(es)) { |
Jason Ekstrand | 918f2dd | 2013-12-02 21:01:53 -0600 | [diff] [blame] | 5681 | map(shell, shsurf, sx, sy); |
Kristian Høgsberg | f7e23d5 | 2012-04-27 17:51:59 -0400 | [diff] [blame] | 5682 | } else if (type_changed || sx != 0 || sy != 0 || |
Jason Ekstrand | 918f2dd | 2013-12-02 21:01:53 -0600 | [diff] [blame] | 5683 | shsurf->last_width != es->width || |
| 5684 | shsurf->last_height != es->height) { |
John Kåre Alsaker | 490d02a | 2012-09-30 02:57:21 +0200 | [diff] [blame] | 5685 | float from_x, from_y; |
| 5686 | float to_x, to_y; |
Ander Conselvan de Oliveira | 093bfa3 | 2012-03-27 17:36:41 +0300 | [diff] [blame] | 5687 | |
Kristian Høgsberg | 44cd196 | 2014-02-05 21:36:04 -0800 | [diff] [blame] | 5688 | if (shsurf->resize_edges) { |
| 5689 | sx = 0; |
| 5690 | sy = 0; |
| 5691 | } |
| 5692 | |
| 5693 | if (shsurf->resize_edges & WL_SHELL_SURFACE_RESIZE_LEFT) |
| 5694 | sx = shsurf->last_width - es->width; |
| 5695 | if (shsurf->resize_edges & WL_SHELL_SURFACE_RESIZE_TOP) |
| 5696 | sy = shsurf->last_height - es->height; |
| 5697 | |
| 5698 | shsurf->last_width = es->width; |
| 5699 | shsurf->last_height = es->height; |
| 5700 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 5701 | weston_view_to_global_float(shsurf->view, 0, 0, &from_x, &from_y); |
| 5702 | 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] | 5703 | configure(shell, es, |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 5704 | shsurf->view->geometry.x + to_x - from_x, |
Jason Ekstrand | 918f2dd | 2013-12-02 21:01:53 -0600 | [diff] [blame] | 5705 | shsurf->view->geometry.y + to_y - from_y); |
Ander Conselvan de Oliveira | 093bfa3 | 2012-03-27 17:36:41 +0300 | [diff] [blame] | 5706 | } |
| 5707 | } |
| 5708 | |
Pekka Paalanen | 2e62e4a | 2014-08-28 11:41:26 +0300 | [diff] [blame] | 5709 | static bool |
| 5710 | check_desktop_shell_crash_too_early(struct desktop_shell *shell) |
| 5711 | { |
| 5712 | struct timespec now; |
| 5713 | |
| 5714 | if (clock_gettime(CLOCK_MONOTONIC, &now) < 0) |
| 5715 | return false; |
| 5716 | |
| 5717 | /* |
| 5718 | * If the shell helper client dies before the session has been |
| 5719 | * up for roughly 30 seconds, better just make Weston shut down, |
| 5720 | * because the user likely has no way to interact with the desktop |
| 5721 | * anyway. |
| 5722 | */ |
| 5723 | if (now.tv_sec - shell->startup_time.tv_sec < 30) { |
| 5724 | weston_log("Error: %s apparently cannot run at all.\n", |
| 5725 | shell->client); |
| 5726 | weston_log_continue(STAMP_SPACE "Quitting..."); |
| 5727 | wl_display_terminate(shell->compositor->wl_display); |
| 5728 | |
| 5729 | return true; |
| 5730 | } |
| 5731 | |
| 5732 | return false; |
| 5733 | } |
| 5734 | |
Tiago Vignatti | b7dbbd6 | 2012-09-25 17:57:01 +0300 | [diff] [blame] | 5735 | static void launch_desktop_shell_process(void *data); |
Pekka Paalanen | 4d733ee | 2012-01-17 14:36:27 +0200 | [diff] [blame] | 5736 | |
Kristian Høgsberg | 97d44aa | 2011-08-26 17:21:20 -0400 | [diff] [blame] | 5737 | static void |
Pekka Paalanen | 826dc14 | 2014-08-27 12:11:53 +0300 | [diff] [blame] | 5738 | respawn_desktop_shell_process(struct desktop_shell *shell) |
Pekka Paalanen | 6cd281a | 2011-11-03 14:11:32 +0200 | [diff] [blame] | 5739 | { |
Pekka Paalanen | 4d733ee | 2012-01-17 14:36:27 +0200 | [diff] [blame] | 5740 | uint32_t time; |
Pekka Paalanen | 4d733ee | 2012-01-17 14:36:27 +0200 | [diff] [blame] | 5741 | |
| 5742 | /* if desktop-shell dies more than 5 times in 30 seconds, give up */ |
| 5743 | time = weston_compositor_get_time(); |
Kristian Høgsberg | f03a616 | 2012-01-17 11:07:42 -0500 | [diff] [blame] | 5744 | if (time - shell->child.deathstamp > 30000) { |
Pekka Paalanen | 4d733ee | 2012-01-17 14:36:27 +0200 | [diff] [blame] | 5745 | shell->child.deathstamp = time; |
| 5746 | shell->child.deathcount = 0; |
| 5747 | } |
| 5748 | |
| 5749 | shell->child.deathcount++; |
| 5750 | if (shell->child.deathcount > 5) { |
Pekka Paalanen | 826dc14 | 2014-08-27 12:11:53 +0300 | [diff] [blame] | 5751 | weston_log("%s disconnected, giving up.\n", shell->client); |
Pekka Paalanen | 4d733ee | 2012-01-17 14:36:27 +0200 | [diff] [blame] | 5752 | return; |
| 5753 | } |
| 5754 | |
Pekka Paalanen | 826dc14 | 2014-08-27 12:11:53 +0300 | [diff] [blame] | 5755 | weston_log("%s disconnected, respawning...\n", shell->client); |
Pekka Paalanen | 4d733ee | 2012-01-17 14:36:27 +0200 | [diff] [blame] | 5756 | launch_desktop_shell_process(shell); |
Pekka Paalanen | 6cd281a | 2011-11-03 14:11:32 +0200 | [diff] [blame] | 5757 | } |
| 5758 | |
Tiago Vignatti | b7dbbd6 | 2012-09-25 17:57:01 +0300 | [diff] [blame] | 5759 | static void |
Ander Conselvan de Oliveira | 312ea4c | 2013-12-20 21:07:01 +0200 | [diff] [blame] | 5760 | desktop_shell_client_destroy(struct wl_listener *listener, void *data) |
| 5761 | { |
| 5762 | struct desktop_shell *shell; |
| 5763 | |
| 5764 | shell = container_of(listener, struct desktop_shell, |
| 5765 | child.client_destroy_listener); |
| 5766 | |
Pekka Paalanen | 826dc14 | 2014-08-27 12:11:53 +0300 | [diff] [blame] | 5767 | wl_list_remove(&shell->child.client_destroy_listener.link); |
Ander Conselvan de Oliveira | 312ea4c | 2013-12-20 21:07:01 +0200 | [diff] [blame] | 5768 | shell->child.client = NULL; |
Pekka Paalanen | 826dc14 | 2014-08-27 12:11:53 +0300 | [diff] [blame] | 5769 | /* |
| 5770 | * unbind_desktop_shell() will reset shell->child.desktop_shell |
| 5771 | * before the respawned process has a chance to create a new |
| 5772 | * desktop_shell object, because we are being called from the |
| 5773 | * wl_client destructor which destroys all wl_resources before |
| 5774 | * returning. |
| 5775 | */ |
| 5776 | |
Pekka Paalanen | 2e62e4a | 2014-08-28 11:41:26 +0300 | [diff] [blame] | 5777 | if (!check_desktop_shell_crash_too_early(shell)) |
| 5778 | respawn_desktop_shell_process(shell); |
| 5779 | |
Pekka Paalanen | 826dc14 | 2014-08-27 12:11:53 +0300 | [diff] [blame] | 5780 | shell_fade_startup(shell); |
Ander Conselvan de Oliveira | 312ea4c | 2013-12-20 21:07:01 +0200 | [diff] [blame] | 5781 | } |
| 5782 | |
| 5783 | static void |
Tiago Vignatti | b7dbbd6 | 2012-09-25 17:57:01 +0300 | [diff] [blame] | 5784 | launch_desktop_shell_process(void *data) |
Pekka Paalanen | 6cd281a | 2011-11-03 14:11:32 +0200 | [diff] [blame] | 5785 | { |
Tiago Vignatti | b7dbbd6 | 2012-09-25 17:57:01 +0300 | [diff] [blame] | 5786 | struct desktop_shell *shell = data; |
Pekka Paalanen | 6cd281a | 2011-11-03 14:11:32 +0200 | [diff] [blame] | 5787 | |
Pekka Paalanen | 826dc14 | 2014-08-27 12:11:53 +0300 | [diff] [blame] | 5788 | shell->child.client = weston_client_start(shell->compositor, |
| 5789 | shell->client); |
Pekka Paalanen | 409ef0a | 2011-12-02 15:30:21 +0200 | [diff] [blame] | 5790 | |
Arnaud Vrac | 4263119 | 2014-08-25 20:56:46 +0200 | [diff] [blame] | 5791 | if (!shell->child.client) { |
Emilio Pozuelo Monfort | 46ce798 | 2013-11-20 13:22:29 +0100 | [diff] [blame] | 5792 | weston_log("not able to start %s\n", shell->client); |
Arnaud Vrac | 4263119 | 2014-08-25 20:56:46 +0200 | [diff] [blame] | 5793 | return; |
| 5794 | } |
Ander Conselvan de Oliveira | 312ea4c | 2013-12-20 21:07:01 +0200 | [diff] [blame] | 5795 | |
| 5796 | shell->child.client_destroy_listener.notify = |
| 5797 | desktop_shell_client_destroy; |
| 5798 | wl_client_add_destroy_listener(shell->child.client, |
| 5799 | &shell->child.client_destroy_listener); |
Pekka Paalanen | 6cd281a | 2011-11-03 14:11:32 +0200 | [diff] [blame] | 5800 | } |
| 5801 | |
| 5802 | static void |
Kristian Høgsberg | 2bff94e | 2014-02-11 12:22:51 -0800 | [diff] [blame] | 5803 | handle_shell_client_destroy(struct wl_listener *listener, void *data) |
| 5804 | { |
| 5805 | struct shell_client *sc = |
| 5806 | container_of(listener, struct shell_client, destroy_listener); |
| 5807 | |
| 5808 | if (sc->ping_timer) |
| 5809 | wl_event_source_remove(sc->ping_timer); |
Derek Foreman | e42d754 | 2015-05-29 10:46:44 -0500 | [diff] [blame] | 5810 | |
| 5811 | /* Since we're about to free shell_client, we remove it from the |
| 5812 | * head of the surface list so we don't use that freed list node |
| 5813 | * during surface clean up later on. |
| 5814 | */ |
| 5815 | wl_list_remove(&sc->surface_list); |
| 5816 | |
Kristian Høgsberg | 2bff94e | 2014-02-11 12:22:51 -0800 | [diff] [blame] | 5817 | free(sc); |
| 5818 | } |
| 5819 | |
Kristian Høgsberg | dd62aba | 2014-02-12 09:56:19 -0800 | [diff] [blame] | 5820 | static struct shell_client * |
| 5821 | shell_client_create(struct wl_client *client, struct desktop_shell *shell, |
| 5822 | const struct wl_interface *interface, uint32_t id) |
Rafael Antognolli | e2a3455 | 2013-12-03 15:35:45 -0200 | [diff] [blame] | 5823 | { |
Kristian Høgsberg | 2bff94e | 2014-02-11 12:22:51 -0800 | [diff] [blame] | 5824 | struct shell_client *sc; |
Rafael Antognolli | e2a3455 | 2013-12-03 15:35:45 -0200 | [diff] [blame] | 5825 | |
Kristian Høgsberg | 2bff94e | 2014-02-11 12:22:51 -0800 | [diff] [blame] | 5826 | sc = zalloc(sizeof *sc); |
| 5827 | if (sc == NULL) { |
| 5828 | wl_client_post_no_memory(client); |
Kristian Høgsberg | dd62aba | 2014-02-12 09:56:19 -0800 | [diff] [blame] | 5829 | return NULL; |
Kristian Høgsberg | 2bff94e | 2014-02-11 12:22:51 -0800 | [diff] [blame] | 5830 | } |
Kristian Høgsberg | dd62aba | 2014-02-12 09:56:19 -0800 | [diff] [blame] | 5831 | |
| 5832 | sc->resource = wl_resource_create(client, interface, 1, id); |
Kristian Høgsberg | 2bff94e | 2014-02-11 12:22:51 -0800 | [diff] [blame] | 5833 | if (sc->resource == NULL) { |
| 5834 | free(sc); |
| 5835 | wl_client_post_no_memory(client); |
Kristian Høgsberg | dd62aba | 2014-02-12 09:56:19 -0800 | [diff] [blame] | 5836 | return NULL; |
Kristian Høgsberg | 2bff94e | 2014-02-11 12:22:51 -0800 | [diff] [blame] | 5837 | } |
| 5838 | |
| 5839 | sc->client = client; |
| 5840 | sc->shell = shell; |
| 5841 | sc->destroy_listener.notify = handle_shell_client_destroy; |
| 5842 | wl_client_add_destroy_listener(client, &sc->destroy_listener); |
Jonas Ådahl | 49d77d2 | 2015-03-18 16:20:51 +0800 | [diff] [blame] | 5843 | wl_list_init(&sc->surface_list); |
Kristian Høgsberg | 2bff94e | 2014-02-11 12:22:51 -0800 | [diff] [blame] | 5844 | |
Kristian Høgsberg | dd62aba | 2014-02-12 09:56:19 -0800 | [diff] [blame] | 5845 | return sc; |
| 5846 | } |
| 5847 | |
| 5848 | static void |
| 5849 | bind_shell(struct wl_client *client, void *data, uint32_t version, uint32_t id) |
| 5850 | { |
| 5851 | struct desktop_shell *shell = data; |
| 5852 | struct shell_client *sc; |
| 5853 | |
| 5854 | sc = shell_client_create(client, shell, &wl_shell_interface, id); |
| 5855 | if (sc) |
| 5856 | wl_resource_set_implementation(sc->resource, |
| 5857 | &shell_implementation, |
Jason Ekstrand | 9e9512f | 2014-04-16 21:12:10 -0500 | [diff] [blame] | 5858 | sc, NULL); |
Kristian Høgsberg | dd62aba | 2014-02-12 09:56:19 -0800 | [diff] [blame] | 5859 | } |
| 5860 | |
| 5861 | static void |
| 5862 | bind_xdg_shell(struct wl_client *client, void *data, uint32_t version, uint32_t id) |
| 5863 | { |
| 5864 | struct desktop_shell *shell = data; |
| 5865 | struct shell_client *sc; |
| 5866 | |
| 5867 | sc = shell_client_create(client, shell, &xdg_shell_interface, id); |
| 5868 | if (sc) |
| 5869 | wl_resource_set_dispatcher(sc->resource, |
| 5870 | xdg_shell_unversioned_dispatch, |
| 5871 | NULL, sc, NULL); |
Rafael Antognolli | e2a3455 | 2013-12-03 15:35:45 -0200 | [diff] [blame] | 5872 | } |
| 5873 | |
| 5874 | static void |
Pekka Paalanen | 9ef3e01 | 2011-11-15 13:34:48 +0200 | [diff] [blame] | 5875 | unbind_desktop_shell(struct wl_resource *resource) |
| 5876 | { |
Jason Ekstrand | 651f00e | 2013-06-14 10:07:54 -0500 | [diff] [blame] | 5877 | struct desktop_shell *shell = wl_resource_get_user_data(resource); |
Kristian Høgsberg | 1ec0c31 | 2011-11-15 16:39:55 -0500 | [diff] [blame] | 5878 | |
| 5879 | if (shell->locked) |
| 5880 | resume_desktop(shell); |
| 5881 | |
Pekka Paalanen | 9ef3e01 | 2011-11-15 13:34:48 +0200 | [diff] [blame] | 5882 | shell->child.desktop_shell = NULL; |
| 5883 | shell->prepare_event_sent = false; |
Pekka Paalanen | 9ef3e01 | 2011-11-15 13:34:48 +0200 | [diff] [blame] | 5884 | } |
| 5885 | |
| 5886 | static void |
Kristian Høgsberg | 7584062 | 2011-09-06 13:48:16 -0400 | [diff] [blame] | 5887 | bind_desktop_shell(struct wl_client *client, |
| 5888 | void *data, uint32_t version, uint32_t id) |
| 5889 | { |
Tiago Vignatti | be14326 | 2012-04-16 17:31:41 +0300 | [diff] [blame] | 5890 | struct desktop_shell *shell = data; |
Pekka Paalanen | bbe6052 | 2011-11-03 14:11:33 +0200 | [diff] [blame] | 5891 | struct wl_resource *resource; |
Kristian Høgsberg | 7584062 | 2011-09-06 13:48:16 -0400 | [diff] [blame] | 5892 | |
Jonas Ådahl | 6d6fb61 | 2015-11-17 16:00:33 +0800 | [diff] [blame] | 5893 | resource = wl_resource_create(client, &weston_desktop_shell_interface, |
| 5894 | 1, id); |
Pekka Paalanen | bbe6052 | 2011-11-03 14:11:33 +0200 | [diff] [blame] | 5895 | |
Pekka Paalanen | 9ef3e01 | 2011-11-15 13:34:48 +0200 | [diff] [blame] | 5896 | if (client == shell->child.client) { |
Jason Ekstrand | a85118c | 2013-06-27 20:17:02 -0500 | [diff] [blame] | 5897 | wl_resource_set_implementation(resource, |
| 5898 | &desktop_shell_implementation, |
| 5899 | shell, unbind_desktop_shell); |
Pekka Paalanen | 9ef3e01 | 2011-11-15 13:34:48 +0200 | [diff] [blame] | 5900 | shell->child.desktop_shell = resource; |
Pekka Paalanen | bbe6052 | 2011-11-03 14:11:33 +0200 | [diff] [blame] | 5901 | return; |
Pekka Paalanen | 9ef3e01 | 2011-11-15 13:34:48 +0200 | [diff] [blame] | 5902 | } |
Pekka Paalanen | bbe6052 | 2011-11-03 14:11:33 +0200 | [diff] [blame] | 5903 | |
| 5904 | wl_resource_post_error(resource, WL_DISPLAY_ERROR_INVALID_OBJECT, |
| 5905 | "permission to bind desktop_shell denied"); |
Kristian Høgsberg | 7584062 | 2011-09-06 13:48:16 -0400 | [diff] [blame] | 5906 | } |
| 5907 | |
Kristian Høgsberg | 0704539 | 2012-02-19 18:52:44 -0500 | [diff] [blame] | 5908 | struct switcher { |
Tiago Vignatti | be14326 | 2012-04-16 17:31:41 +0300 | [diff] [blame] | 5909 | struct desktop_shell *shell; |
Kristian Høgsberg | 0704539 | 2012-02-19 18:52:44 -0500 | [diff] [blame] | 5910 | struct weston_surface *current; |
| 5911 | struct wl_listener listener; |
Kristian Høgsberg | 29139d4 | 2013-04-18 15:25:39 -0400 | [diff] [blame] | 5912 | struct weston_keyboard_grab grab; |
Manuel Bachmann | c1ae2e8 | 2014-02-26 15:53:11 +0100 | [diff] [blame] | 5913 | struct wl_array minimized_array; |
Kristian Høgsberg | 0704539 | 2012-02-19 18:52:44 -0500 | [diff] [blame] | 5914 | }; |
| 5915 | |
| 5916 | static void |
| 5917 | switcher_next(struct switcher *switcher) |
| 5918 | { |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 5919 | struct weston_view *view; |
Kristian Høgsberg | 0704539 | 2012-02-19 18:52:44 -0500 | [diff] [blame] | 5920 | struct weston_surface *first = NULL, *prev = NULL, *next = NULL; |
Kristian Høgsberg | 32e5686 | 2012-04-02 22:18:58 -0400 | [diff] [blame] | 5921 | struct shell_surface *shsurf; |
Kristian Høgsberg | b0d8e77 | 2012-06-18 16:34:58 -0400 | [diff] [blame] | 5922 | struct workspace *ws = get_current_workspace(switcher->shell); |
Kristian Høgsberg | 0704539 | 2012-02-19 18:52:44 -0500 | [diff] [blame] | 5923 | |
Manuel Bachmann | c1ae2e8 | 2014-02-26 15:53:11 +0100 | [diff] [blame] | 5924 | /* temporary re-display minimized surfaces */ |
| 5925 | struct weston_view *tmp; |
| 5926 | struct weston_view **minimized; |
Giulio Camuffo | 412e6a5 | 2014-07-09 22:12:56 +0300 | [diff] [blame] | 5927 | wl_list_for_each_safe(view, tmp, &switcher->shell->minimized_layer.view_list.link, layer_link.link) { |
| 5928 | weston_layer_entry_remove(&view->layer_link); |
| 5929 | weston_layer_entry_insert(&ws->layer.view_list, &view->layer_link); |
Manuel Bachmann | c1ae2e8 | 2014-02-26 15:53:11 +0100 | [diff] [blame] | 5930 | minimized = wl_array_add(&switcher->minimized_array, sizeof *minimized); |
| 5931 | *minimized = view; |
| 5932 | } |
| 5933 | |
Giulio Camuffo | 412e6a5 | 2014-07-09 22:12:56 +0300 | [diff] [blame] | 5934 | 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] | 5935 | shsurf = get_shell_surface(view->surface); |
Rafael Antognolli | 5031cbe | 2013-12-05 19:01:21 -0200 | [diff] [blame] | 5936 | if (shsurf && |
| 5937 | shsurf->type == SHELL_SURFACE_TOPLEVEL && |
| 5938 | shsurf->parent == NULL) { |
Kristian Høgsberg | 0704539 | 2012-02-19 18:52:44 -0500 | [diff] [blame] | 5939 | if (first == NULL) |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 5940 | first = view->surface; |
Kristian Høgsberg | 0704539 | 2012-02-19 18:52:44 -0500 | [diff] [blame] | 5941 | if (prev == switcher->current) |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 5942 | next = view->surface; |
| 5943 | prev = view->surface; |
| 5944 | view->alpha = 0.25; |
| 5945 | weston_view_geometry_dirty(view); |
| 5946 | weston_surface_damage(view->surface); |
Kristian Høgsberg | 0704539 | 2012-02-19 18:52:44 -0500 | [diff] [blame] | 5947 | } |
Alex Wu | 1659daa | 2012-04-01 20:13:09 +0800 | [diff] [blame] | 5948 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 5949 | if (is_black_surface(view->surface, NULL)) { |
| 5950 | view->alpha = 0.25; |
| 5951 | weston_view_geometry_dirty(view); |
| 5952 | weston_surface_damage(view->surface); |
Alex Wu | 1659daa | 2012-04-01 20:13:09 +0800 | [diff] [blame] | 5953 | } |
Kristian Høgsberg | 0704539 | 2012-02-19 18:52:44 -0500 | [diff] [blame] | 5954 | } |
| 5955 | |
| 5956 | if (next == NULL) |
| 5957 | next = first; |
| 5958 | |
Alex Wu | 07b2606 | 2012-03-12 16:06:01 +0800 | [diff] [blame] | 5959 | if (next == NULL) |
| 5960 | return; |
| 5961 | |
Kristian Høgsberg | 0704539 | 2012-02-19 18:52:44 -0500 | [diff] [blame] | 5962 | wl_list_remove(&switcher->listener.link); |
Jason Ekstrand | 26ed73c | 2013-06-06 22:34:41 -0500 | [diff] [blame] | 5963 | wl_signal_add(&next->destroy_signal, &switcher->listener); |
Kristian Høgsberg | 0704539 | 2012-02-19 18:52:44 -0500 | [diff] [blame] | 5964 | |
| 5965 | switcher->current = next; |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 5966 | wl_list_for_each(view, &next->views, surface_link) |
| 5967 | view->alpha = 1.0; |
Alex Wu | 1659daa | 2012-04-01 20:13:09 +0800 | [diff] [blame] | 5968 | |
Kristian Høgsberg | 32e5686 | 2012-04-02 22:18:58 -0400 | [diff] [blame] | 5969 | shsurf = get_shell_surface(switcher->current); |
Rafael Antognolli | 03b1659 | 2013-12-03 15:35:42 -0200 | [diff] [blame] | 5970 | if (shsurf && shsurf->state.fullscreen) |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 5971 | shsurf->fullscreen.black_view->alpha = 1.0; |
Kristian Høgsberg | 0704539 | 2012-02-19 18:52:44 -0500 | [diff] [blame] | 5972 | } |
| 5973 | |
| 5974 | static void |
Kristian Høgsberg | 27e3052 | 2012-04-11 23:18:23 -0400 | [diff] [blame] | 5975 | switcher_handle_surface_destroy(struct wl_listener *listener, void *data) |
Kristian Høgsberg | 0704539 | 2012-02-19 18:52:44 -0500 | [diff] [blame] | 5976 | { |
| 5977 | struct switcher *switcher = |
| 5978 | container_of(listener, struct switcher, listener); |
| 5979 | |
| 5980 | switcher_next(switcher); |
| 5981 | } |
| 5982 | |
| 5983 | static void |
Daniel Stone | 351eb61 | 2012-05-31 15:27:47 -0400 | [diff] [blame] | 5984 | switcher_destroy(struct switcher *switcher) |
Kristian Høgsberg | 0704539 | 2012-02-19 18:52:44 -0500 | [diff] [blame] | 5985 | { |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 5986 | struct weston_view *view; |
Kristian Høgsberg | 29139d4 | 2013-04-18 15:25:39 -0400 | [diff] [blame] | 5987 | struct weston_keyboard *keyboard = switcher->grab.keyboard; |
Kristian Høgsberg | b0d8e77 | 2012-06-18 16:34:58 -0400 | [diff] [blame] | 5988 | struct workspace *ws = get_current_workspace(switcher->shell); |
Kristian Høgsberg | 0704539 | 2012-02-19 18:52:44 -0500 | [diff] [blame] | 5989 | |
Giulio Camuffo | 412e6a5 | 2014-07-09 22:12:56 +0300 | [diff] [blame] | 5990 | 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] | 5991 | if (is_focus_view(view)) |
| 5992 | continue; |
| 5993 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 5994 | view->alpha = 1.0; |
| 5995 | weston_surface_damage(view->surface); |
Kristian Høgsberg | 0704539 | 2012-02-19 18:52:44 -0500 | [diff] [blame] | 5996 | } |
| 5997 | |
Alex Wu | 07b2606 | 2012-03-12 16:06:01 +0800 | [diff] [blame] | 5998 | if (switcher->current) |
Daniel Stone | 37816df | 2012-05-16 18:45:18 +0100 | [diff] [blame] | 5999 | activate(switcher->shell, switcher->current, |
Derek Foreman | 8aeeac8 | 2015-01-30 13:24:36 -0600 | [diff] [blame] | 6000 | keyboard->seat, true); |
Kristian Høgsberg | 0704539 | 2012-02-19 18:52:44 -0500 | [diff] [blame] | 6001 | wl_list_remove(&switcher->listener.link); |
Kristian Høgsberg | 29139d4 | 2013-04-18 15:25:39 -0400 | [diff] [blame] | 6002 | weston_keyboard_end_grab(keyboard); |
| 6003 | if (keyboard->input_method_resource) |
| 6004 | keyboard->grab = &keyboard->input_method_grab; |
Manuel Bachmann | c1ae2e8 | 2014-02-26 15:53:11 +0100 | [diff] [blame] | 6005 | |
| 6006 | /* re-hide surfaces that were temporary shown during the switch */ |
| 6007 | struct weston_view **minimized; |
| 6008 | wl_array_for_each(minimized, &switcher->minimized_array) { |
| 6009 | /* with the exception of the current selected */ |
| 6010 | if ((*minimized)->surface != switcher->current) { |
Giulio Camuffo | 412e6a5 | 2014-07-09 22:12:56 +0300 | [diff] [blame] | 6011 | weston_layer_entry_remove(&(*minimized)->layer_link); |
| 6012 | 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] | 6013 | weston_view_damage_below(*minimized); |
| 6014 | } |
| 6015 | } |
| 6016 | wl_array_release(&switcher->minimized_array); |
| 6017 | |
Kristian Høgsberg | 0704539 | 2012-02-19 18:52:44 -0500 | [diff] [blame] | 6018 | free(switcher); |
| 6019 | } |
| 6020 | |
| 6021 | static void |
Kristian Høgsberg | 29139d4 | 2013-04-18 15:25:39 -0400 | [diff] [blame] | 6022 | switcher_key(struct weston_keyboard_grab *grab, |
Daniel Stone | c9785ea | 2012-05-30 16:31:52 +0100 | [diff] [blame] | 6023 | uint32_t time, uint32_t key, uint32_t state_w) |
Kristian Høgsberg | 0704539 | 2012-02-19 18:52:44 -0500 | [diff] [blame] | 6024 | { |
| 6025 | struct switcher *switcher = container_of(grab, struct switcher, grab); |
Daniel Stone | c9785ea | 2012-05-30 16:31:52 +0100 | [diff] [blame] | 6026 | enum wl_keyboard_key_state state = state_w; |
Daniel Stone | 351eb61 | 2012-05-31 15:27:47 -0400 | [diff] [blame] | 6027 | |
Daniel Stone | c9785ea | 2012-05-30 16:31:52 +0100 | [diff] [blame] | 6028 | if (key == KEY_TAB && state == WL_KEYBOARD_KEY_STATE_PRESSED) |
Daniel Stone | 351eb61 | 2012-05-31 15:27:47 -0400 | [diff] [blame] | 6029 | switcher_next(switcher); |
| 6030 | } |
| 6031 | |
| 6032 | static void |
Kristian Høgsberg | 29139d4 | 2013-04-18 15:25:39 -0400 | [diff] [blame] | 6033 | switcher_modifier(struct weston_keyboard_grab *grab, uint32_t serial, |
Daniel Stone | 351eb61 | 2012-05-31 15:27:47 -0400 | [diff] [blame] | 6034 | uint32_t mods_depressed, uint32_t mods_latched, |
| 6035 | uint32_t mods_locked, uint32_t group) |
| 6036 | { |
| 6037 | struct switcher *switcher = container_of(grab, struct switcher, grab); |
Derek Foreman | 8aeeac8 | 2015-01-30 13:24:36 -0600 | [diff] [blame] | 6038 | struct weston_seat *seat = grab->keyboard->seat; |
Kristian Høgsberg | 0704539 | 2012-02-19 18:52:44 -0500 | [diff] [blame] | 6039 | |
Daniel Stone | 351eb61 | 2012-05-31 15:27:47 -0400 | [diff] [blame] | 6040 | if ((seat->modifier_state & switcher->shell->binding_modifier) == 0) |
| 6041 | switcher_destroy(switcher); |
Kristian Høgsberg | b71302e | 2012-05-10 12:28:35 -0400 | [diff] [blame] | 6042 | } |
Kristian Høgsberg | 0704539 | 2012-02-19 18:52:44 -0500 | [diff] [blame] | 6043 | |
Jonas Ådahl | 1ea343e | 2013-10-25 23:18:05 +0200 | [diff] [blame] | 6044 | static void |
| 6045 | switcher_cancel(struct weston_keyboard_grab *grab) |
| 6046 | { |
| 6047 | struct switcher *switcher = container_of(grab, struct switcher, grab); |
| 6048 | |
| 6049 | switcher_destroy(switcher); |
| 6050 | } |
| 6051 | |
Kristian Høgsberg | 29139d4 | 2013-04-18 15:25:39 -0400 | [diff] [blame] | 6052 | static const struct weston_keyboard_grab_interface switcher_grab = { |
Daniel Stone | 351eb61 | 2012-05-31 15:27:47 -0400 | [diff] [blame] | 6053 | switcher_key, |
| 6054 | switcher_modifier, |
Jonas Ådahl | 1ea343e | 2013-10-25 23:18:05 +0200 | [diff] [blame] | 6055 | switcher_cancel, |
Kristian Høgsberg | 0704539 | 2012-02-19 18:52:44 -0500 | [diff] [blame] | 6056 | }; |
| 6057 | |
| 6058 | static void |
Derek Foreman | 8ae2db5 | 2015-07-15 13:00:36 -0500 | [diff] [blame] | 6059 | switcher_binding(struct weston_keyboard *keyboard, uint32_t time, |
| 6060 | uint32_t key, void *data) |
Kristian Høgsberg | 0704539 | 2012-02-19 18:52:44 -0500 | [diff] [blame] | 6061 | { |
Tiago Vignatti | be14326 | 2012-04-16 17:31:41 +0300 | [diff] [blame] | 6062 | struct desktop_shell *shell = data; |
Kristian Høgsberg | 0704539 | 2012-02-19 18:52:44 -0500 | [diff] [blame] | 6063 | struct switcher *switcher; |
| 6064 | |
| 6065 | switcher = malloc(sizeof *switcher); |
Kristian Høgsberg | 02e79dc | 2012-04-12 09:55:26 -0400 | [diff] [blame] | 6066 | switcher->shell = shell; |
Kristian Høgsberg | 0704539 | 2012-02-19 18:52:44 -0500 | [diff] [blame] | 6067 | switcher->current = NULL; |
Kristian Høgsberg | 27e3052 | 2012-04-11 23:18:23 -0400 | [diff] [blame] | 6068 | switcher->listener.notify = switcher_handle_surface_destroy; |
Kristian Høgsberg | 0704539 | 2012-02-19 18:52:44 -0500 | [diff] [blame] | 6069 | wl_list_init(&switcher->listener.link); |
Manuel Bachmann | c1ae2e8 | 2014-02-26 15:53:11 +0100 | [diff] [blame] | 6070 | wl_array_init(&switcher->minimized_array); |
Kristian Høgsberg | 0704539 | 2012-02-19 18:52:44 -0500 | [diff] [blame] | 6071 | |
Alexander Larsson | f82b6ca | 2013-05-28 16:23:39 +0200 | [diff] [blame] | 6072 | restore_all_output_modes(shell->compositor); |
Mario Kleiner | 9f4d655 | 2015-06-21 21:25:08 +0200 | [diff] [blame] | 6073 | lower_fullscreen_layer(switcher->shell, NULL); |
Kristian Høgsberg | 0704539 | 2012-02-19 18:52:44 -0500 | [diff] [blame] | 6074 | switcher->grab.interface = &switcher_grab; |
Derek Foreman | 8ae2db5 | 2015-07-15 13:00:36 -0500 | [diff] [blame] | 6075 | weston_keyboard_start_grab(keyboard, &switcher->grab); |
| 6076 | weston_keyboard_set_focus(keyboard, NULL); |
Kristian Høgsberg | 0704539 | 2012-02-19 18:52:44 -0500 | [diff] [blame] | 6077 | switcher_next(switcher); |
| 6078 | } |
| 6079 | |
Pekka Paalanen | 3c64723 | 2011-12-22 13:43:43 +0200 | [diff] [blame] | 6080 | static void |
Derek Foreman | 8ae2db5 | 2015-07-15 13:00:36 -0500 | [diff] [blame] | 6081 | backlight_binding(struct weston_keyboard *keyboard, uint32_t time, |
| 6082 | uint32_t key, void *data) |
Tiago Vignatti | 8e53c7f | 2012-02-29 19:53:50 +0200 | [diff] [blame] | 6083 | { |
| 6084 | struct weston_compositor *compositor = data; |
| 6085 | struct weston_output *output; |
Tiago Vignatti | 5ab91ad | 2012-03-12 19:40:09 -0300 | [diff] [blame] | 6086 | long backlight_new = 0; |
Tiago Vignatti | 8e53c7f | 2012-02-29 19:53:50 +0200 | [diff] [blame] | 6087 | |
| 6088 | /* TODO: we're limiting to simple use cases, where we assume just |
| 6089 | * control on the primary display. We'd have to extend later if we |
| 6090 | * ever get support for setting backlights on random desktop LCD |
| 6091 | * panels though */ |
| 6092 | output = get_default_output(compositor); |
| 6093 | if (!output) |
| 6094 | return; |
| 6095 | |
| 6096 | if (!output->set_backlight) |
| 6097 | return; |
| 6098 | |
Tiago Vignatti | 5ab91ad | 2012-03-12 19:40:09 -0300 | [diff] [blame] | 6099 | if (key == KEY_F9 || key == KEY_BRIGHTNESSDOWN) |
| 6100 | backlight_new = output->backlight_current - 25; |
| 6101 | else if (key == KEY_F10 || key == KEY_BRIGHTNESSUP) |
| 6102 | backlight_new = output->backlight_current + 25; |
Tiago Vignatti | 8e53c7f | 2012-02-29 19:53:50 +0200 | [diff] [blame] | 6103 | |
Tiago Vignatti | 5ab91ad | 2012-03-12 19:40:09 -0300 | [diff] [blame] | 6104 | if (backlight_new < 5) |
| 6105 | backlight_new = 5; |
| 6106 | if (backlight_new > 255) |
| 6107 | backlight_new = 255; |
| 6108 | |
| 6109 | output->backlight_current = backlight_new; |
Tiago Vignatti | 8e53c7f | 2012-02-29 19:53:50 +0200 | [diff] [blame] | 6110 | output->set_backlight(output, output->backlight_current); |
| 6111 | } |
| 6112 | |
Kristian Høgsberg | b41c081 | 2012-03-04 14:53:40 -0500 | [diff] [blame] | 6113 | static void |
Derek Foreman | 8ae2db5 | 2015-07-15 13:00:36 -0500 | [diff] [blame] | 6114 | force_kill_binding(struct weston_keyboard *keyboard, uint32_t time, |
| 6115 | uint32_t key, void *data) |
Kristian Høgsberg | 92a57db | 2012-05-26 13:41:06 -0400 | [diff] [blame] | 6116 | { |
Kristian Høgsberg | fe7aa90 | 2013-05-08 09:54:37 -0400 | [diff] [blame] | 6117 | struct weston_surface *focus_surface; |
Kristian Høgsberg | 92a57db | 2012-05-26 13:41:06 -0400 | [diff] [blame] | 6118 | struct wl_client *client; |
Tiago Vignatti | 1d01b01 | 2012-09-27 17:48:36 +0300 | [diff] [blame] | 6119 | struct desktop_shell *shell = data; |
| 6120 | struct weston_compositor *compositor = shell->compositor; |
Kristian Høgsberg | 92a57db | 2012-05-26 13:41:06 -0400 | [diff] [blame] | 6121 | pid_t pid; |
Kristian Høgsberg | 92a57db | 2012-05-26 13:41:06 -0400 | [diff] [blame] | 6122 | |
Derek Foreman | 8ae2db5 | 2015-07-15 13:00:36 -0500 | [diff] [blame] | 6123 | focus_surface = keyboard->focus; |
Philipp Brüschweiler | 6cef009 | 2012-08-13 21:27:27 +0200 | [diff] [blame] | 6124 | if (!focus_surface) |
| 6125 | return; |
| 6126 | |
Tiago Vignatti | 1d01b01 | 2012-09-27 17:48:36 +0300 | [diff] [blame] | 6127 | wl_signal_emit(&compositor->kill_signal, focus_surface); |
| 6128 | |
Jason Ekstrand | 26ed73c | 2013-06-06 22:34:41 -0500 | [diff] [blame] | 6129 | client = wl_resource_get_client(focus_surface->resource); |
Tiago Vignatti | 920f197 | 2012-09-27 17:48:35 +0300 | [diff] [blame] | 6130 | wl_client_get_credentials(client, &pid, NULL, NULL); |
| 6131 | |
| 6132 | /* Skip clients that we launched ourselves (the credentials of |
| 6133 | * the socketpair is ours) */ |
| 6134 | if (pid == getpid()) |
| 6135 | return; |
Kristian Høgsberg | 92a57db | 2012-05-26 13:41:06 -0400 | [diff] [blame] | 6136 | |
Daniel Stone | 325fc2d | 2012-05-30 16:31:58 +0100 | [diff] [blame] | 6137 | kill(pid, SIGKILL); |
Kristian Høgsberg | 92a57db | 2012-05-26 13:41:06 -0400 | [diff] [blame] | 6138 | } |
| 6139 | |
| 6140 | static void |
Derek Foreman | 8ae2db5 | 2015-07-15 13:00:36 -0500 | [diff] [blame] | 6141 | workspace_up_binding(struct weston_keyboard *keyboard, uint32_t time, |
Jonas Ådahl | e3cddce | 2012-06-13 00:01:22 +0200 | [diff] [blame] | 6142 | uint32_t key, void *data) |
| 6143 | { |
| 6144 | struct desktop_shell *shell = data; |
| 6145 | unsigned int new_index = shell->workspaces.current; |
| 6146 | |
Kristian Høgsberg | ce345b0 | 2012-06-25 21:35:29 -0400 | [diff] [blame] | 6147 | if (shell->locked) |
Kristian Høgsberg | 4476aaf | 2012-06-25 14:03:13 -0400 | [diff] [blame] | 6148 | return; |
Jonas Ådahl | e3cddce | 2012-06-13 00:01:22 +0200 | [diff] [blame] | 6149 | if (new_index != 0) |
| 6150 | new_index--; |
| 6151 | |
| 6152 | change_workspace(shell, new_index); |
| 6153 | } |
| 6154 | |
| 6155 | static void |
Derek Foreman | 8ae2db5 | 2015-07-15 13:00:36 -0500 | [diff] [blame] | 6156 | workspace_down_binding(struct weston_keyboard *keyboard, uint32_t time, |
Jonas Ådahl | e3cddce | 2012-06-13 00:01:22 +0200 | [diff] [blame] | 6157 | uint32_t key, void *data) |
| 6158 | { |
| 6159 | struct desktop_shell *shell = data; |
| 6160 | unsigned int new_index = shell->workspaces.current; |
| 6161 | |
Kristian Høgsberg | ce345b0 | 2012-06-25 21:35:29 -0400 | [diff] [blame] | 6162 | if (shell->locked) |
Kristian Høgsberg | 4476aaf | 2012-06-25 14:03:13 -0400 | [diff] [blame] | 6163 | return; |
Jonas Ådahl | e3cddce | 2012-06-13 00:01:22 +0200 | [diff] [blame] | 6164 | if (new_index < shell->workspaces.num - 1) |
| 6165 | new_index++; |
| 6166 | |
| 6167 | change_workspace(shell, new_index); |
| 6168 | } |
| 6169 | |
| 6170 | static void |
Derek Foreman | 8ae2db5 | 2015-07-15 13:00:36 -0500 | [diff] [blame] | 6171 | workspace_f_binding(struct weston_keyboard *keyboard, uint32_t time, |
Jonas Ådahl | e3cddce | 2012-06-13 00:01:22 +0200 | [diff] [blame] | 6172 | uint32_t key, void *data) |
| 6173 | { |
| 6174 | struct desktop_shell *shell = data; |
| 6175 | unsigned int new_index; |
| 6176 | |
Kristian Høgsberg | ce345b0 | 2012-06-25 21:35:29 -0400 | [diff] [blame] | 6177 | if (shell->locked) |
Kristian Høgsberg | 4476aaf | 2012-06-25 14:03:13 -0400 | [diff] [blame] | 6178 | return; |
Jonas Ådahl | e3cddce | 2012-06-13 00:01:22 +0200 | [diff] [blame] | 6179 | new_index = key - KEY_F1; |
| 6180 | if (new_index >= shell->workspaces.num) |
| 6181 | new_index = shell->workspaces.num - 1; |
| 6182 | |
| 6183 | change_workspace(shell, new_index); |
| 6184 | } |
| 6185 | |
Jonas Ådahl | 8de6a1d | 2012-08-29 22:13:00 +0200 | [diff] [blame] | 6186 | static void |
Derek Foreman | 8ae2db5 | 2015-07-15 13:00:36 -0500 | [diff] [blame] | 6187 | workspace_move_surface_up_binding(struct weston_keyboard *keyboard, |
| 6188 | uint32_t time, uint32_t key, void *data) |
Jonas Ådahl | 8de6a1d | 2012-08-29 22:13:00 +0200 | [diff] [blame] | 6189 | { |
| 6190 | struct desktop_shell *shell = data; |
| 6191 | unsigned int new_index = shell->workspaces.current; |
| 6192 | |
| 6193 | if (shell->locked) |
| 6194 | return; |
| 6195 | |
| 6196 | if (new_index != 0) |
| 6197 | new_index--; |
| 6198 | |
Derek Foreman | 8ae2db5 | 2015-07-15 13:00:36 -0500 | [diff] [blame] | 6199 | take_surface_to_workspace_by_seat(shell, keyboard->seat, new_index); |
Jonas Ådahl | 8de6a1d | 2012-08-29 22:13:00 +0200 | [diff] [blame] | 6200 | } |
| 6201 | |
| 6202 | static void |
Derek Foreman | 8ae2db5 | 2015-07-15 13:00:36 -0500 | [diff] [blame] | 6203 | workspace_move_surface_down_binding(struct weston_keyboard *keyboard, |
| 6204 | uint32_t time, uint32_t key, void *data) |
Jonas Ådahl | 8de6a1d | 2012-08-29 22:13:00 +0200 | [diff] [blame] | 6205 | { |
| 6206 | struct desktop_shell *shell = data; |
| 6207 | unsigned int new_index = shell->workspaces.current; |
| 6208 | |
| 6209 | if (shell->locked) |
| 6210 | return; |
| 6211 | |
| 6212 | if (new_index < shell->workspaces.num - 1) |
| 6213 | new_index++; |
| 6214 | |
Derek Foreman | 8ae2db5 | 2015-07-15 13:00:36 -0500 | [diff] [blame] | 6215 | take_surface_to_workspace_by_seat(shell, keyboard->seat, new_index); |
Jonas Ådahl | 8de6a1d | 2012-08-29 22:13:00 +0200 | [diff] [blame] | 6216 | } |
Jonas Ådahl | e3cddce | 2012-06-13 00:01:22 +0200 | [diff] [blame] | 6217 | |
| 6218 | static void |
Ander Conselvan de Oliveira | c94d622 | 2014-01-29 18:47:54 +0200 | [diff] [blame] | 6219 | shell_reposition_view_on_output_destroy(struct weston_view *view) |
| 6220 | { |
| 6221 | struct weston_output *output, *first_output; |
| 6222 | struct weston_compositor *ec = view->surface->compositor; |
| 6223 | struct shell_surface *shsurf; |
| 6224 | float x, y; |
| 6225 | int visible; |
| 6226 | |
| 6227 | x = view->geometry.x; |
| 6228 | y = view->geometry.y; |
| 6229 | |
| 6230 | /* At this point the destroyed output is not in the list anymore. |
| 6231 | * If the view is still visible somewhere, we leave where it is, |
| 6232 | * otherwise, move it to the first output. */ |
| 6233 | visible = 0; |
| 6234 | wl_list_for_each(output, &ec->output_list, link) { |
| 6235 | if (pixman_region32_contains_point(&output->region, |
| 6236 | x, y, NULL)) { |
| 6237 | visible = 1; |
| 6238 | break; |
| 6239 | } |
| 6240 | } |
| 6241 | |
| 6242 | if (!visible) { |
| 6243 | first_output = container_of(ec->output_list.next, |
| 6244 | struct weston_output, link); |
| 6245 | |
| 6246 | x = first_output->x + first_output->width / 4; |
| 6247 | y = first_output->y + first_output->height / 4; |
Xiong Zhang | 62899f5 | 2014-03-07 16:27:19 +0800 | [diff] [blame] | 6248 | |
| 6249 | weston_view_set_position(view, x, y); |
| 6250 | } else { |
| 6251 | weston_view_geometry_dirty(view); |
Ander Conselvan de Oliveira | c94d622 | 2014-01-29 18:47:54 +0200 | [diff] [blame] | 6252 | } |
| 6253 | |
Ander Conselvan de Oliveira | c94d622 | 2014-01-29 18:47:54 +0200 | [diff] [blame] | 6254 | |
| 6255 | shsurf = get_shell_surface(view->surface); |
| 6256 | |
| 6257 | if (shsurf) { |
| 6258 | shsurf->saved_position_valid = false; |
| 6259 | shsurf->next_state.maximized = false; |
| 6260 | shsurf->next_state.fullscreen = false; |
| 6261 | shsurf->state_changed = true; |
| 6262 | } |
| 6263 | } |
| 6264 | |
Ander Conselvan de Oliveira | 304996d | 2014-04-11 13:57:15 +0300 | [diff] [blame] | 6265 | void |
| 6266 | shell_for_each_layer(struct desktop_shell *shell, |
| 6267 | shell_for_each_layer_func_t func, void *data) |
Ander Conselvan de Oliveira | c94d622 | 2014-01-29 18:47:54 +0200 | [diff] [blame] | 6268 | { |
Ander Conselvan de Oliveira | 304996d | 2014-04-11 13:57:15 +0300 | [diff] [blame] | 6269 | struct workspace **ws; |
| 6270 | |
| 6271 | func(shell, &shell->fullscreen_layer, data); |
| 6272 | func(shell, &shell->panel_layer, data); |
| 6273 | func(shell, &shell->background_layer, data); |
| 6274 | func(shell, &shell->lock_layer, data); |
| 6275 | func(shell, &shell->input_panel_layer, data); |
| 6276 | |
| 6277 | wl_array_for_each(ws, &shell->workspaces.array) |
| 6278 | func(shell, &(*ws)->layer, data); |
| 6279 | } |
| 6280 | |
| 6281 | static void |
| 6282 | shell_output_destroy_move_layer(struct desktop_shell *shell, |
| 6283 | struct weston_layer *layer, |
| 6284 | void *data) |
| 6285 | { |
| 6286 | struct weston_output *output = data; |
Ander Conselvan de Oliveira | c94d622 | 2014-01-29 18:47:54 +0200 | [diff] [blame] | 6287 | struct weston_view *view; |
| 6288 | |
Giulio Camuffo | 412e6a5 | 2014-07-09 22:12:56 +0300 | [diff] [blame] | 6289 | 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] | 6290 | if (view->output != output) |
| 6291 | continue; |
Ander Conselvan de Oliveira | c94d622 | 2014-01-29 18:47:54 +0200 | [diff] [blame] | 6292 | |
Ander Conselvan de Oliveira | 304996d | 2014-04-11 13:57:15 +0300 | [diff] [blame] | 6293 | shell_reposition_view_on_output_destroy(view); |
Ander Conselvan de Oliveira | c94d622 | 2014-01-29 18:47:54 +0200 | [diff] [blame] | 6294 | } |
| 6295 | } |
| 6296 | |
| 6297 | static void |
Xiong Zhang | 6b48142 | 2013-10-23 13:58:32 +0800 | [diff] [blame] | 6298 | handle_output_destroy(struct wl_listener *listener, void *data) |
| 6299 | { |
| 6300 | struct shell_output *output_listener = |
| 6301 | container_of(listener, struct shell_output, destroy_listener); |
Ander Conselvan de Oliveira | 304996d | 2014-04-11 13:57:15 +0300 | [diff] [blame] | 6302 | struct weston_output *output = output_listener->output; |
| 6303 | struct desktop_shell *shell = output_listener->shell; |
Xiong Zhang | 6b48142 | 2013-10-23 13:58:32 +0800 | [diff] [blame] | 6304 | |
Ander Conselvan de Oliveira | 304996d | 2014-04-11 13:57:15 +0300 | [diff] [blame] | 6305 | 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] | 6306 | |
Xiong Zhang | 6b48142 | 2013-10-23 13:58:32 +0800 | [diff] [blame] | 6307 | wl_list_remove(&output_listener->destroy_listener.link); |
| 6308 | wl_list_remove(&output_listener->link); |
| 6309 | free(output_listener); |
| 6310 | } |
| 6311 | |
| 6312 | static void |
| 6313 | create_shell_output(struct desktop_shell *shell, |
| 6314 | struct weston_output *output) |
| 6315 | { |
| 6316 | struct shell_output *shell_output; |
| 6317 | |
| 6318 | shell_output = zalloc(sizeof *shell_output); |
| 6319 | if (shell_output == NULL) |
| 6320 | return; |
| 6321 | |
| 6322 | shell_output->output = output; |
| 6323 | shell_output->shell = shell; |
| 6324 | shell_output->destroy_listener.notify = handle_output_destroy; |
| 6325 | wl_signal_add(&output->destroy_signal, |
| 6326 | &shell_output->destroy_listener); |
Kristian Høgsberg | a3a0e18 | 2013-10-23 23:36:04 -0700 | [diff] [blame] | 6327 | wl_list_insert(shell->output_list.prev, &shell_output->link); |
Xiong Zhang | 6b48142 | 2013-10-23 13:58:32 +0800 | [diff] [blame] | 6328 | } |
| 6329 | |
| 6330 | static void |
| 6331 | handle_output_create(struct wl_listener *listener, void *data) |
| 6332 | { |
| 6333 | struct desktop_shell *shell = |
| 6334 | container_of(listener, struct desktop_shell, output_create_listener); |
| 6335 | struct weston_output *output = (struct weston_output *)data; |
| 6336 | |
| 6337 | create_shell_output(shell, output); |
| 6338 | } |
| 6339 | |
| 6340 | static void |
Ander Conselvan de Oliveira | 304996d | 2014-04-11 13:57:15 +0300 | [diff] [blame] | 6341 | handle_output_move_layer(struct desktop_shell *shell, |
| 6342 | struct weston_layer *layer, void *data) |
Ander Conselvan de Oliveira | a8a9baf | 2014-01-29 18:47:52 +0200 | [diff] [blame] | 6343 | { |
Ander Conselvan de Oliveira | 304996d | 2014-04-11 13:57:15 +0300 | [diff] [blame] | 6344 | struct weston_output *output = data; |
Ander Conselvan de Oliveira | a8a9baf | 2014-01-29 18:47:52 +0200 | [diff] [blame] | 6345 | struct weston_view *view; |
| 6346 | float x, y; |
| 6347 | |
Giulio Camuffo | 412e6a5 | 2014-07-09 22:12:56 +0300 | [diff] [blame] | 6348 | wl_list_for_each(view, &layer->view_list.link, layer_link.link) { |
Ander Conselvan de Oliveira | 304996d | 2014-04-11 13:57:15 +0300 | [diff] [blame] | 6349 | if (view->output != output) |
| 6350 | continue; |
| 6351 | |
| 6352 | x = view->geometry.x + output->move_x; |
| 6353 | y = view->geometry.y + output->move_y; |
| 6354 | weston_view_set_position(view, x, y); |
| 6355 | } |
| 6356 | } |
| 6357 | |
| 6358 | static void |
| 6359 | handle_output_move(struct wl_listener *listener, void *data) |
| 6360 | { |
| 6361 | struct desktop_shell *shell; |
| 6362 | |
Ander Conselvan de Oliveira | a8a9baf | 2014-01-29 18:47:52 +0200 | [diff] [blame] | 6363 | shell = container_of(listener, struct desktop_shell, |
| 6364 | output_move_listener); |
Ander Conselvan de Oliveira | a8a9baf | 2014-01-29 18:47:52 +0200 | [diff] [blame] | 6365 | |
Ander Conselvan de Oliveira | 304996d | 2014-04-11 13:57:15 +0300 | [diff] [blame] | 6366 | shell_for_each_layer(shell, handle_output_move_layer, data); |
Ander Conselvan de Oliveira | a8a9baf | 2014-01-29 18:47:52 +0200 | [diff] [blame] | 6367 | } |
| 6368 | |
| 6369 | static void |
Xiong Zhang | 6b48142 | 2013-10-23 13:58:32 +0800 | [diff] [blame] | 6370 | setup_output_destroy_handler(struct weston_compositor *ec, |
| 6371 | struct desktop_shell *shell) |
| 6372 | { |
| 6373 | struct weston_output *output; |
| 6374 | |
| 6375 | wl_list_init(&shell->output_list); |
| 6376 | wl_list_for_each(output, &ec->output_list, link) |
| 6377 | create_shell_output(shell, output); |
| 6378 | |
| 6379 | shell->output_create_listener.notify = handle_output_create; |
| 6380 | wl_signal_add(&ec->output_created_signal, |
| 6381 | &shell->output_create_listener); |
Ander Conselvan de Oliveira | a8a9baf | 2014-01-29 18:47:52 +0200 | [diff] [blame] | 6382 | |
| 6383 | shell->output_move_listener.notify = handle_output_move; |
| 6384 | wl_signal_add(&ec->output_moved_signal, &shell->output_move_listener); |
Xiong Zhang | 6b48142 | 2013-10-23 13:58:32 +0800 | [diff] [blame] | 6385 | } |
| 6386 | |
| 6387 | static void |
Kristian Høgsberg | 02e79dc | 2012-04-12 09:55:26 -0400 | [diff] [blame] | 6388 | shell_destroy(struct wl_listener *listener, void *data) |
Pekka Paalanen | 3c64723 | 2011-12-22 13:43:43 +0200 | [diff] [blame] | 6389 | { |
Tiago Vignatti | be14326 | 2012-04-16 17:31:41 +0300 | [diff] [blame] | 6390 | struct desktop_shell *shell = |
| 6391 | container_of(listener, struct desktop_shell, destroy_listener); |
Jonas Ådahl | e3cddce | 2012-06-13 00:01:22 +0200 | [diff] [blame] | 6392 | struct workspace **ws; |
Xiong Zhang | 6b48142 | 2013-10-23 13:58:32 +0800 | [diff] [blame] | 6393 | struct shell_output *shell_output, *tmp; |
Pekka Paalanen | 3c64723 | 2011-12-22 13:43:43 +0200 | [diff] [blame] | 6394 | |
Kristian Høgsberg | 17bccae | 2014-01-16 16:46:28 -0800 | [diff] [blame] | 6395 | /* Force state to unlocked so we don't try to fade */ |
| 6396 | shell->locked = false; |
Pekka Paalanen | 826dc14 | 2014-08-27 12:11:53 +0300 | [diff] [blame] | 6397 | |
| 6398 | if (shell->child.client) { |
| 6399 | /* disable respawn */ |
| 6400 | wl_list_remove(&shell->child.client_destroy_listener.link); |
Pekka Paalanen | 9cf5cc8 | 2012-01-02 16:00:24 +0200 | [diff] [blame] | 6401 | wl_client_destroy(shell->child.client); |
Pekka Paalanen | 826dc14 | 2014-08-27 12:11:53 +0300 | [diff] [blame] | 6402 | } |
Pekka Paalanen | 9cf5cc8 | 2012-01-02 16:00:24 +0200 | [diff] [blame] | 6403 | |
Ander Conselvan de Oliveira | a457563 | 2013-02-21 18:35:23 +0200 | [diff] [blame] | 6404 | wl_list_remove(&shell->idle_listener.link); |
| 6405 | wl_list_remove(&shell->wake_listener.link); |
Giulio Camuffo | f05d18f | 2015-12-11 20:57:05 +0200 | [diff] [blame] | 6406 | wl_list_remove(&shell->transform_listener.link); |
Kristian Høgsberg | 677a5f5 | 2013-12-04 11:00:19 -0800 | [diff] [blame] | 6407 | |
Pekka Paalanen | aa9536a | 2015-06-24 16:09:17 +0300 | [diff] [blame] | 6408 | text_backend_destroy(shell->text_backend); |
Kristian Høgsberg | 677a5f5 | 2013-12-04 11:00:19 -0800 | [diff] [blame] | 6409 | input_panel_destroy(shell); |
Kristian Høgsberg | 88c1607 | 2012-05-16 08:04:19 -0400 | [diff] [blame] | 6410 | |
Xiong Zhang | 6b48142 | 2013-10-23 13:58:32 +0800 | [diff] [blame] | 6411 | wl_list_for_each_safe(shell_output, tmp, &shell->output_list, link) { |
| 6412 | wl_list_remove(&shell_output->destroy_listener.link); |
| 6413 | wl_list_remove(&shell_output->link); |
| 6414 | free(shell_output); |
| 6415 | } |
| 6416 | |
| 6417 | wl_list_remove(&shell->output_create_listener.link); |
Kristian Høgsberg | 6d50b0f | 2014-04-30 20:46:25 -0700 | [diff] [blame] | 6418 | wl_list_remove(&shell->output_move_listener.link); |
Xiong Zhang | 6b48142 | 2013-10-23 13:58:32 +0800 | [diff] [blame] | 6419 | |
Jonas Ådahl | e3cddce | 2012-06-13 00:01:22 +0200 | [diff] [blame] | 6420 | wl_array_for_each(ws, &shell->workspaces.array) |
| 6421 | workspace_destroy(*ws); |
| 6422 | wl_array_release(&shell->workspaces.array); |
| 6423 | |
Emilio Pozuelo Monfort | 46ce798 | 2013-11-20 13:22:29 +0100 | [diff] [blame] | 6424 | free(shell->client); |
Pekka Paalanen | 3c64723 | 2011-12-22 13:43:43 +0200 | [diff] [blame] | 6425 | free(shell); |
| 6426 | } |
| 6427 | |
Tiago Vignatti | 0b52d48 | 2012-04-20 18:54:25 +0300 | [diff] [blame] | 6428 | static void |
| 6429 | shell_add_bindings(struct weston_compositor *ec, struct desktop_shell *shell) |
| 6430 | { |
| 6431 | uint32_t mod; |
Jonas Ådahl | e3cddce | 2012-06-13 00:01:22 +0200 | [diff] [blame] | 6432 | int i, num_workspace_bindings; |
Tiago Vignatti | 0b52d48 | 2012-04-20 18:54:25 +0300 | [diff] [blame] | 6433 | |
Bob Ham | 744e653 | 2016-01-12 10:21:48 +0000 | [diff] [blame^] | 6434 | if (shell->allow_zap) |
| 6435 | weston_compositor_add_key_binding(ec, KEY_BACKSPACE, |
| 6436 | MODIFIER_CTRL | MODIFIER_ALT, |
| 6437 | terminate_binding, ec); |
| 6438 | |
Tiago Vignatti | 0b52d48 | 2012-04-20 18:54:25 +0300 | [diff] [blame] | 6439 | /* fixed bindings */ |
Daniel Stone | 325fc2d | 2012-05-30 16:31:58 +0100 | [diff] [blame] | 6440 | weston_compositor_add_button_binding(ec, BTN_LEFT, 0, |
| 6441 | click_to_activate_binding, |
| 6442 | shell); |
Kristian Høgsberg | f0ce581 | 2014-04-07 11:52:17 -0700 | [diff] [blame] | 6443 | weston_compositor_add_button_binding(ec, BTN_RIGHT, 0, |
| 6444 | click_to_activate_binding, |
| 6445 | shell); |
Neil Roberts | a28c693 | 2013-10-03 16:43:04 +0100 | [diff] [blame] | 6446 | weston_compositor_add_touch_binding(ec, 0, |
| 6447 | touch_to_activate_binding, |
| 6448 | shell); |
Daniel Stone | 325fc2d | 2012-05-30 16:31:58 +0100 | [diff] [blame] | 6449 | weston_compositor_add_axis_binding(ec, WL_POINTER_AXIS_VERTICAL_SCROLL, |
| 6450 | MODIFIER_SUPER | MODIFIER_ALT, |
| 6451 | surface_opacity_binding, NULL); |
| 6452 | weston_compositor_add_axis_binding(ec, WL_POINTER_AXIS_VERTICAL_SCROLL, |
| 6453 | MODIFIER_SUPER, zoom_axis_binding, |
| 6454 | NULL); |
Tiago Vignatti | 0b52d48 | 2012-04-20 18:54:25 +0300 | [diff] [blame] | 6455 | |
| 6456 | /* configurable bindings */ |
| 6457 | mod = shell->binding_modifier; |
Daniel Stone | 325fc2d | 2012-05-30 16:31:58 +0100 | [diff] [blame] | 6458 | weston_compositor_add_key_binding(ec, KEY_PAGEUP, mod, |
| 6459 | zoom_key_binding, NULL); |
| 6460 | weston_compositor_add_key_binding(ec, KEY_PAGEDOWN, mod, |
| 6461 | zoom_key_binding, NULL); |
Kristian Høgsberg | 211b517 | 2014-01-11 13:10:21 -0800 | [diff] [blame] | 6462 | weston_compositor_add_key_binding(ec, KEY_M, mod | MODIFIER_SHIFT, |
| 6463 | maximize_binding, NULL); |
| 6464 | weston_compositor_add_key_binding(ec, KEY_F, mod | MODIFIER_SHIFT, |
| 6465 | fullscreen_binding, NULL); |
Daniel Stone | 325fc2d | 2012-05-30 16:31:58 +0100 | [diff] [blame] | 6466 | weston_compositor_add_button_binding(ec, BTN_LEFT, mod, move_binding, |
| 6467 | shell); |
Neil Roberts | aba0f25 | 2013-10-03 16:43:05 +0100 | [diff] [blame] | 6468 | weston_compositor_add_touch_binding(ec, mod, touch_move_binding, shell); |
Derek Foreman | 2217f3f | 2015-06-25 16:03:30 -0500 | [diff] [blame] | 6469 | weston_compositor_add_button_binding(ec, BTN_RIGHT, mod, |
Daniel Stone | 325fc2d | 2012-05-30 16:31:58 +0100 | [diff] [blame] | 6470 | resize_binding, shell); |
Kristian Høgsberg | 0837fa9 | 2014-01-20 10:35:26 -0800 | [diff] [blame] | 6471 | weston_compositor_add_button_binding(ec, BTN_LEFT, |
| 6472 | mod | MODIFIER_SHIFT, |
| 6473 | resize_binding, shell); |
Pekka Paalanen | 7bb6510 | 2013-05-22 18:03:04 +0300 | [diff] [blame] | 6474 | |
| 6475 | if (ec->capabilities & WESTON_CAP_ROTATION_ANY) |
Derek Foreman | 2217f3f | 2015-06-25 16:03:30 -0500 | [diff] [blame] | 6476 | weston_compositor_add_button_binding(ec, BTN_MIDDLE, mod, |
Pekka Paalanen | 7bb6510 | 2013-05-22 18:03:04 +0300 | [diff] [blame] | 6477 | rotate_binding, NULL); |
| 6478 | |
Daniel Stone | 325fc2d | 2012-05-30 16:31:58 +0100 | [diff] [blame] | 6479 | weston_compositor_add_key_binding(ec, KEY_TAB, mod, switcher_binding, |
| 6480 | shell); |
| 6481 | weston_compositor_add_key_binding(ec, KEY_F9, mod, backlight_binding, |
| 6482 | ec); |
| 6483 | weston_compositor_add_key_binding(ec, KEY_BRIGHTNESSDOWN, 0, |
| 6484 | backlight_binding, ec); |
| 6485 | weston_compositor_add_key_binding(ec, KEY_F10, mod, backlight_binding, |
| 6486 | ec); |
| 6487 | weston_compositor_add_key_binding(ec, KEY_BRIGHTNESSUP, 0, |
| 6488 | backlight_binding, ec); |
Daniel Stone | 325fc2d | 2012-05-30 16:31:58 +0100 | [diff] [blame] | 6489 | weston_compositor_add_key_binding(ec, KEY_K, mod, |
| 6490 | force_kill_binding, shell); |
Jonas Ådahl | e3cddce | 2012-06-13 00:01:22 +0200 | [diff] [blame] | 6491 | weston_compositor_add_key_binding(ec, KEY_UP, mod, |
| 6492 | workspace_up_binding, shell); |
| 6493 | weston_compositor_add_key_binding(ec, KEY_DOWN, mod, |
| 6494 | workspace_down_binding, shell); |
Jonas Ådahl | 8de6a1d | 2012-08-29 22:13:00 +0200 | [diff] [blame] | 6495 | weston_compositor_add_key_binding(ec, KEY_UP, mod | MODIFIER_SHIFT, |
| 6496 | workspace_move_surface_up_binding, |
| 6497 | shell); |
| 6498 | weston_compositor_add_key_binding(ec, KEY_DOWN, mod | MODIFIER_SHIFT, |
| 6499 | workspace_move_surface_down_binding, |
| 6500 | shell); |
Jonas Ådahl | e3cddce | 2012-06-13 00:01:22 +0200 | [diff] [blame] | 6501 | |
Kristian Høgsberg | d56ab4e | 2014-01-16 16:51:52 -0800 | [diff] [blame] | 6502 | if (shell->exposay_modifier) |
| 6503 | weston_compositor_add_modifier_binding(ec, shell->exposay_modifier, |
| 6504 | exposay_binding, shell); |
Daniel Stone | df8133b | 2013-11-19 11:37:14 +0100 | [diff] [blame] | 6505 | |
Jonas Ådahl | e3cddce | 2012-06-13 00:01:22 +0200 | [diff] [blame] | 6506 | /* Add bindings for mod+F[1-6] for workspace 1 to 6. */ |
| 6507 | if (shell->workspaces.num > 1) { |
| 6508 | num_workspace_bindings = shell->workspaces.num; |
| 6509 | if (num_workspace_bindings > 6) |
| 6510 | num_workspace_bindings = 6; |
| 6511 | for (i = 0; i < num_workspace_bindings; i++) |
| 6512 | weston_compositor_add_key_binding(ec, KEY_F1 + i, mod, |
| 6513 | workspace_f_binding, |
| 6514 | shell); |
| 6515 | } |
Ander Conselvan de Oliveira | c509d2b | 2012-11-08 17:20:45 +0200 | [diff] [blame] | 6516 | |
Pekka Paalanen | 2829f7c | 2015-02-19 17:02:13 +0200 | [diff] [blame] | 6517 | weston_install_debug_key_binding(ec, mod); |
Tiago Vignatti | 0b52d48 | 2012-04-20 18:54:25 +0300 | [diff] [blame] | 6518 | } |
| 6519 | |
Jason Ekstrand | 024177c | 2014-04-21 19:42:58 -0500 | [diff] [blame] | 6520 | static void |
| 6521 | handle_seat_created(struct wl_listener *listener, void *data) |
| 6522 | { |
| 6523 | struct weston_seat *seat = data; |
| 6524 | |
| 6525 | create_shell_seat(seat); |
| 6526 | } |
| 6527 | |
Kristian Høgsberg | 1c56218 | 2011-05-02 22:09:20 -0400 | [diff] [blame] | 6528 | WL_EXPORT int |
Kristian Høgsberg | cb4685b | 2013-02-20 15:37:49 -0500 | [diff] [blame] | 6529 | module_init(struct weston_compositor *ec, |
Ossama Othman | a50e6e4 | 2013-05-14 09:48:26 -0700 | [diff] [blame] | 6530 | int *argc, char *argv[]) |
Kristian Høgsberg | 4cca349 | 2011-01-18 07:53:49 -0500 | [diff] [blame] | 6531 | { |
Kristian Høgsberg | f4d2f23 | 2012-08-10 10:05:39 -0400 | [diff] [blame] | 6532 | struct weston_seat *seat; |
Tiago Vignatti | be14326 | 2012-04-16 17:31:41 +0300 | [diff] [blame] | 6533 | struct desktop_shell *shell; |
Jonas Ådahl | e3cddce | 2012-06-13 00:01:22 +0200 | [diff] [blame] | 6534 | struct workspace **pws; |
| 6535 | unsigned int i; |
Tiago Vignatti | b7dbbd6 | 2012-09-25 17:57:01 +0300 | [diff] [blame] | 6536 | struct wl_event_loop *loop; |
Kristian Høgsberg | 02ec0a5 | 2011-04-23 13:04:11 -0400 | [diff] [blame] | 6537 | |
Peter Hutterer | f3d6227 | 2013-08-08 11:57:05 +1000 | [diff] [blame] | 6538 | shell = zalloc(sizeof *shell); |
Kristian Høgsberg | 02ec0a5 | 2011-04-23 13:04:11 -0400 | [diff] [blame] | 6539 | if (shell == NULL) |
| 6540 | return -1; |
| 6541 | |
Kristian Høgsberg | 7584062 | 2011-09-06 13:48:16 -0400 | [diff] [blame] | 6542 | shell->compositor = ec; |
Kristian Høgsberg | 02e79dc | 2012-04-12 09:55:26 -0400 | [diff] [blame] | 6543 | |
| 6544 | shell->destroy_listener.notify = shell_destroy; |
| 6545 | wl_signal_add(&ec->destroy_signal, &shell->destroy_listener); |
Ander Conselvan de Oliveira | a457563 | 2013-02-21 18:35:23 +0200 | [diff] [blame] | 6546 | shell->idle_listener.notify = idle_handler; |
| 6547 | wl_signal_add(&ec->idle_signal, &shell->idle_listener); |
| 6548 | shell->wake_listener.notify = wake_handler; |
| 6549 | wl_signal_add(&ec->wake_signal, &shell->wake_listener); |
Giulio Camuffo | f05d18f | 2015-12-11 20:57:05 +0200 | [diff] [blame] | 6550 | shell->transform_listener.notify = transform_handler; |
| 6551 | wl_signal_add(&ec->transform_signal, &shell->transform_listener); |
Kristian Høgsberg | 677a5f5 | 2013-12-04 11:00:19 -0800 | [diff] [blame] | 6552 | |
Kristian Høgsberg | 82a1d11 | 2012-07-19 14:02:00 -0400 | [diff] [blame] | 6553 | ec->shell_interface.shell = shell; |
Tiago Vignatti | bc052c9 | 2012-04-19 16:18:18 +0300 | [diff] [blame] | 6554 | ec->shell_interface.create_shell_surface = create_shell_surface; |
| 6555 | ec->shell_interface.set_toplevel = set_toplevel; |
Tiago Vignatti | 491bac1 | 2012-05-18 16:37:43 -0400 | [diff] [blame] | 6556 | ec->shell_interface.set_transient = set_transient; |
Kristian Høgsberg | 4779241 | 2014-05-04 13:47:06 -0700 | [diff] [blame] | 6557 | ec->shell_interface.set_fullscreen = shell_interface_set_fullscreen; |
Tiago Vignatti | fb2adba | 2013-06-12 15:43:21 -0300 | [diff] [blame] | 6558 | ec->shell_interface.set_xwayland = set_xwayland; |
Kristian Høgsberg | ae356ae | 2014-04-29 16:03:54 -0700 | [diff] [blame] | 6559 | ec->shell_interface.move = shell_interface_move; |
Derek Foreman | 8fbebbd | 2015-07-15 13:00:40 -0500 | [diff] [blame] | 6560 | ec->shell_interface.resize = shell_interface_resize; |
Giulio Camuffo | 62942ad | 2013-09-11 18:20:47 +0200 | [diff] [blame] | 6561 | ec->shell_interface.set_title = set_title; |
Jasper St. Pierre | ccf48fb | 2014-05-02 10:21:38 -0400 | [diff] [blame] | 6562 | ec->shell_interface.set_window_geometry = set_window_geometry; |
Giulio Camuffo | 6b4b241 | 2015-01-29 19:06:49 +0200 | [diff] [blame] | 6563 | ec->shell_interface.set_maximized = shell_interface_set_maximized; |
Giulio Camuffo | a8e9b41 | 2015-01-27 19:10:37 +0200 | [diff] [blame] | 6564 | ec->shell_interface.set_pid = set_pid; |
Kristian Høgsberg | 4cca349 | 2011-01-18 07:53:49 -0500 | [diff] [blame] | 6565 | |
Kristian Høgsberg | 3be2ce9 | 2012-02-29 12:42:35 -0500 | [diff] [blame] | 6566 | weston_layer_init(&shell->fullscreen_layer, &ec->cursor_layer.link); |
| 6567 | weston_layer_init(&shell->panel_layer, &shell->fullscreen_layer.link); |
Jonas Ådahl | e3cddce | 2012-06-13 00:01:22 +0200 | [diff] [blame] | 6568 | weston_layer_init(&shell->background_layer, &shell->panel_layer.link); |
| 6569 | weston_layer_init(&shell->lock_layer, NULL); |
Philipp Brüschweiler | 711fda8 | 2012-08-09 18:50:43 +0200 | [diff] [blame] | 6570 | weston_layer_init(&shell->input_panel_layer, NULL); |
Jonas Ådahl | e3cddce | 2012-06-13 00:01:22 +0200 | [diff] [blame] | 6571 | |
| 6572 | wl_array_init(&shell->workspaces.array); |
Jonas Ådahl | e9d2250 | 2012-08-29 22:13:01 +0200 | [diff] [blame] | 6573 | wl_list_init(&shell->workspaces.client_list); |
Kristian Høgsberg | 3be2ce9 | 2012-02-29 12:42:35 -0500 | [diff] [blame] | 6574 | |
Kristian Høgsberg | 677a5f5 | 2013-12-04 11:00:19 -0800 | [diff] [blame] | 6575 | if (input_panel_setup(shell) < 0) |
| 6576 | return -1; |
| 6577 | |
Pekka Paalanen | aa9536a | 2015-06-24 16:09:17 +0300 | [diff] [blame] | 6578 | shell->text_backend = text_backend_init(ec); |
| 6579 | if (!shell->text_backend) |
Murray Calavera | 9a51cd7 | 2015-06-10 21:16:02 +0000 | [diff] [blame] | 6580 | return -1; |
| 6581 | |
Kristian Høgsberg | 14e438c | 2013-05-26 21:48:14 -0400 | [diff] [blame] | 6582 | shell_configuration(shell); |
Pekka Paalanen | e955f1e | 2011-12-07 11:49:52 +0200 | [diff] [blame] | 6583 | |
Daniel Stone | df8133b | 2013-11-19 11:37:14 +0100 | [diff] [blame] | 6584 | shell->exposay.state_cur = EXPOSAY_LAYOUT_INACTIVE; |
| 6585 | shell->exposay.state_target = EXPOSAY_TARGET_CANCEL; |
| 6586 | |
Jonas Ådahl | e3cddce | 2012-06-13 00:01:22 +0200 | [diff] [blame] | 6587 | for (i = 0; i < shell->workspaces.num; i++) { |
| 6588 | pws = wl_array_add(&shell->workspaces.array, sizeof *pws); |
| 6589 | if (pws == NULL) |
| 6590 | return -1; |
| 6591 | |
| 6592 | *pws = workspace_create(); |
| 6593 | if (*pws == NULL) |
| 6594 | return -1; |
| 6595 | } |
| 6596 | activate_workspace(shell, 0); |
| 6597 | |
Manuel Bachmann | 50c87db | 2014-02-26 15:52:13 +0100 | [diff] [blame] | 6598 | weston_layer_init(&shell->minimized_layer, NULL); |
| 6599 | |
Jonas Ådahl | 8de6a1d | 2012-08-29 22:13:00 +0200 | [diff] [blame] | 6600 | wl_list_init(&shell->workspaces.anim_sticky_list); |
Jonas Ådahl | 62fcd04 | 2012-06-13 00:01:23 +0200 | [diff] [blame] | 6601 | wl_list_init(&shell->workspaces.animation.link); |
| 6602 | shell->workspaces.animation.frame = animate_workspace_change_frame; |
| 6603 | |
Kristian Høgsberg | 919cddb | 2013-07-08 19:03:57 -0400 | [diff] [blame] | 6604 | if (wl_global_create(ec->wl_display, &wl_shell_interface, 1, |
Kristian Høgsberg | 97d44aa | 2011-08-26 17:21:20 -0400 | [diff] [blame] | 6605 | shell, bind_shell) == NULL) |
Kristian Høgsberg | 4cca349 | 2011-01-18 07:53:49 -0500 | [diff] [blame] | 6606 | return -1; |
| 6607 | |
Rafael Antognolli | e2a3455 | 2013-12-03 15:35:45 -0200 | [diff] [blame] | 6608 | if (wl_global_create(ec->wl_display, &xdg_shell_interface, 1, |
| 6609 | shell, bind_xdg_shell) == NULL) |
| 6610 | return -1; |
| 6611 | |
Kristian Høgsberg | 919cddb | 2013-07-08 19:03:57 -0400 | [diff] [blame] | 6612 | if (wl_global_create(ec->wl_display, |
Jonas Ådahl | 6d6fb61 | 2015-11-17 16:00:33 +0800 | [diff] [blame] | 6613 | &weston_desktop_shell_interface, 1, |
Kristian Høgsberg | 919cddb | 2013-07-08 19:03:57 -0400 | [diff] [blame] | 6614 | shell, bind_desktop_shell) == NULL) |
Kristian Høgsberg | 7584062 | 2011-09-06 13:48:16 -0400 | [diff] [blame] | 6615 | return -1; |
| 6616 | |
Kristian Høgsberg | f03a616 | 2012-01-17 11:07:42 -0500 | [diff] [blame] | 6617 | shell->child.deathstamp = weston_compositor_get_time(); |
Tiago Vignatti | b7dbbd6 | 2012-09-25 17:57:01 +0300 | [diff] [blame] | 6618 | |
Jonas Ådahl | 6d6fb61 | 2015-11-17 16:00:33 +0800 | [diff] [blame] | 6619 | shell->panel_position = WESTON_DESKTOP_SHELL_PANEL_POSITION_TOP; |
Jonny Lamb | 765760d | 2014-08-20 15:53:19 +0200 | [diff] [blame] | 6620 | |
Xiong Zhang | 6b48142 | 2013-10-23 13:58:32 +0800 | [diff] [blame] | 6621 | setup_output_destroy_handler(ec, shell); |
| 6622 | |
Tiago Vignatti | b7dbbd6 | 2012-09-25 17:57:01 +0300 | [diff] [blame] | 6623 | loop = wl_display_get_event_loop(ec->wl_display); |
| 6624 | wl_event_loop_add_idle(loop, launch_desktop_shell_process, shell); |
Pekka Paalanen | 6cd281a | 2011-11-03 14:11:32 +0200 | [diff] [blame] | 6625 | |
Jason Ekstrand | 024177c | 2014-04-21 19:42:58 -0500 | [diff] [blame] | 6626 | wl_list_for_each(seat, &ec->seat_list, link) |
| 6627 | handle_seat_created(NULL, seat); |
| 6628 | shell->seat_create_listener.notify = handle_seat_created; |
| 6629 | wl_signal_add(&ec->seat_created_signal, &shell->seat_create_listener); |
Kristian Høgsberg | d56bd90 | 2012-06-05 09:58:51 -0400 | [diff] [blame] | 6630 | |
Giulio Camuffo | c6ab3d5 | 2013-12-11 23:45:12 +0100 | [diff] [blame] | 6631 | screenshooter_create(ec); |
| 6632 | |
Tiago Vignatti | 0b52d48 | 2012-04-20 18:54:25 +0300 | [diff] [blame] | 6633 | shell_add_bindings(ec, shell); |
Kristian Høgsberg | 0793756 | 2011-04-12 17:25:42 -0400 | [diff] [blame] | 6634 | |
Pekka Paalanen | 79346ab | 2013-05-22 18:03:09 +0300 | [diff] [blame] | 6635 | shell_fade_init(shell); |
Ander Conselvan de Oliveira | 19d10ef | 2013-02-21 18:35:20 +0200 | [diff] [blame] | 6636 | |
Pekka Paalanen | 2e62e4a | 2014-08-28 11:41:26 +0300 | [diff] [blame] | 6637 | clock_gettime(CLOCK_MONOTONIC, &shell->startup_time); |
| 6638 | |
Kristian Høgsberg | 4cca349 | 2011-01-18 07:53:49 -0500 | [diff] [blame] | 6639 | return 0; |
| 6640 | } |