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; |
Pekka Paalanen | e955f1e | 2011-12-07 11:49:52 +0200 | [diff] [blame] | 639 | |
Kristian Høgsberg | 673a889 | 2013-05-23 21:40:56 -0400 | [diff] [blame] | 640 | section = weston_config_get_section(shell->compositor->config, |
Kristian Høgsberg | 673a889 | 2013-05-23 21:40:56 -0400 | [diff] [blame] | 641 | "shell", NULL, NULL); |
Pekka Paalanen | 974c094 | 2014-09-05 14:45:09 +0300 | [diff] [blame] | 642 | ret = asprintf(&client, "%s/%s", weston_config_get_libexec_dir(), |
| 643 | WESTON_SHELL_CLIENT); |
| 644 | if (ret < 0) |
| 645 | client = NULL; |
Kristian Høgsberg | 673a889 | 2013-05-23 21:40:56 -0400 | [diff] [blame] | 646 | weston_config_section_get_string(section, |
Derek Foreman | c721043 | 2014-08-21 11:32:38 -0500 | [diff] [blame] | 647 | "client", &s, client); |
| 648 | free(client); |
Emilio Pozuelo Monfort | 46ce798 | 2013-11-20 13:22:29 +0100 | [diff] [blame] | 649 | shell->client = s; |
| 650 | weston_config_section_get_string(section, |
Kristian Høgsberg | 673a889 | 2013-05-23 21:40:56 -0400 | [diff] [blame] | 651 | "binding-modifier", &s, "super"); |
| 652 | shell->binding_modifier = get_modifier(s); |
Quentin Glidic | 8418c29 | 2013-06-18 09:11:03 +0200 | [diff] [blame] | 653 | free(s); |
Kristian Høgsberg | d56ab4e | 2014-01-16 16:51:52 -0800 | [diff] [blame] | 654 | |
| 655 | weston_config_section_get_string(section, |
| 656 | "exposay-modifier", &s, "none"); |
| 657 | if (strcmp(s, "none") == 0) |
| 658 | shell->exposay_modifier = 0; |
| 659 | else |
| 660 | shell->exposay_modifier = get_modifier(s); |
| 661 | free(s); |
| 662 | |
Kristian Høgsberg | 673a889 | 2013-05-23 21:40:56 -0400 | [diff] [blame] | 663 | weston_config_section_get_string(section, "animation", &s, "none"); |
| 664 | shell->win_animation_type = get_animation_type(s); |
Quentin Glidic | 8418c29 | 2013-06-18 09:11:03 +0200 | [diff] [blame] | 665 | free(s); |
Jonny Lamb | f322f8e | 2014-08-12 15:13:30 +0200 | [diff] [blame] | 666 | weston_config_section_get_string(section, "close-animation", &s, "fade"); |
| 667 | shell->win_close_animation_type = get_animation_type(s); |
| 668 | free(s); |
Kristian Høgsberg | 724c8d9 | 2013-10-16 11:38:24 -0700 | [diff] [blame] | 669 | weston_config_section_get_string(section, |
| 670 | "startup-animation", &s, "fade"); |
| 671 | shell->startup_animation_type = get_animation_type(s); |
| 672 | free(s); |
Kristian Høgsberg | 912e0a1 | 2013-10-30 08:59:55 -0700 | [diff] [blame] | 673 | if (shell->startup_animation_type == ANIMATION_ZOOM) |
| 674 | shell->startup_animation_type = ANIMATION_NONE; |
Louis-Francis Ratté-Boulianne | b482dbd | 2013-11-19 11:37:11 +0100 | [diff] [blame] | 675 | weston_config_section_get_string(section, "focus-animation", &s, "none"); |
| 676 | shell->focus_animation_type = get_animation_type(s); |
| 677 | free(s); |
Kristian Høgsberg | 673a889 | 2013-05-23 21:40:56 -0400 | [diff] [blame] | 678 | weston_config_section_get_uint(section, "num-workspaces", |
| 679 | &shell->workspaces.num, |
| 680 | DEFAULT_NUM_WORKSPACES); |
Jonas Ådahl | e3cddce | 2012-06-13 00:01:22 +0200 | [diff] [blame] | 681 | } |
| 682 | |
Kristian Høgsberg | 1ef2313 | 2013-12-04 00:20:01 -0800 | [diff] [blame] | 683 | struct weston_output * |
Louis-Francis Ratté-Boulianne | b482dbd | 2013-11-19 11:37:11 +0100 | [diff] [blame] | 684 | get_default_output(struct weston_compositor *compositor) |
| 685 | { |
| 686 | return container_of(compositor->output_list.next, |
| 687 | struct weston_output, link); |
| 688 | } |
| 689 | |
Pekka Paalanen | 8274d90 | 2014-08-06 19:36:51 +0300 | [diff] [blame] | 690 | static int |
| 691 | focus_surface_get_label(struct weston_surface *surface, char *buf, size_t len) |
| 692 | { |
| 693 | return snprintf(buf, len, "focus highlight effect for output %s", |
| 694 | surface->output->name); |
| 695 | } |
Louis-Francis Ratté-Boulianne | b482dbd | 2013-11-19 11:37:11 +0100 | [diff] [blame] | 696 | |
| 697 | /* no-op func for checking focus surface */ |
| 698 | static void |
Jason Ekstrand | 918f2dd | 2013-12-02 21:01:53 -0600 | [diff] [blame] | 699 | 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] | 700 | { |
| 701 | } |
| 702 | |
| 703 | static struct focus_surface * |
| 704 | get_focus_surface(struct weston_surface *surface) |
| 705 | { |
| 706 | if (surface->configure == focus_surface_configure) |
| 707 | return surface->configure_private; |
| 708 | else |
| 709 | return NULL; |
| 710 | } |
| 711 | |
| 712 | static bool |
| 713 | is_focus_surface (struct weston_surface *es) |
| 714 | { |
| 715 | return (es->configure == focus_surface_configure); |
| 716 | } |
| 717 | |
| 718 | static bool |
| 719 | is_focus_view (struct weston_view *view) |
| 720 | { |
| 721 | return is_focus_surface (view->surface); |
| 722 | } |
| 723 | |
| 724 | static struct focus_surface * |
| 725 | create_focus_surface(struct weston_compositor *ec, |
| 726 | struct weston_output *output) |
| 727 | { |
| 728 | struct focus_surface *fsurf = NULL; |
| 729 | struct weston_surface *surface = NULL; |
| 730 | |
| 731 | fsurf = malloc(sizeof *fsurf); |
| 732 | if (!fsurf) |
| 733 | return NULL; |
| 734 | |
| 735 | fsurf->surface = weston_surface_create(ec); |
| 736 | surface = fsurf->surface; |
| 737 | if (surface == NULL) { |
| 738 | free(fsurf); |
| 739 | return NULL; |
| 740 | } |
| 741 | |
| 742 | surface->configure = focus_surface_configure; |
| 743 | surface->output = output; |
| 744 | surface->configure_private = fsurf; |
Pekka Paalanen | 8274d90 | 2014-08-06 19:36:51 +0300 | [diff] [blame] | 745 | weston_surface_set_label_func(surface, focus_surface_get_label); |
Louis-Francis Ratté-Boulianne | b482dbd | 2013-11-19 11:37:11 +0100 | [diff] [blame] | 746 | |
U. Artie Eoff | 0b23b2b | 2014-01-15 14:45:59 -0800 | [diff] [blame] | 747 | fsurf->view = weston_view_create(surface); |
| 748 | if (fsurf->view == NULL) { |
| 749 | weston_surface_destroy(surface); |
| 750 | free(fsurf); |
| 751 | return NULL; |
| 752 | } |
Emilio Pozuelo Monfort | da64426 | 2013-11-19 11:37:19 +0100 | [diff] [blame] | 753 | fsurf->view->output = output; |
Louis-Francis Ratté-Boulianne | b482dbd | 2013-11-19 11:37:11 +0100 | [diff] [blame] | 754 | |
Jason Ekstrand | 5c11a33 | 2013-12-04 20:32:03 -0600 | [diff] [blame] | 755 | weston_surface_set_size(surface, output->width, output->height); |
Jason Ekstrand | 918f2dd | 2013-12-02 21:01:53 -0600 | [diff] [blame] | 756 | weston_view_set_position(fsurf->view, output->x, output->y); |
Louis-Francis Ratté-Boulianne | b482dbd | 2013-11-19 11:37:11 +0100 | [diff] [blame] | 757 | weston_surface_set_color(surface, 0.0, 0.0, 0.0, 1.0); |
| 758 | pixman_region32_fini(&surface->opaque); |
| 759 | pixman_region32_init_rect(&surface->opaque, output->x, output->y, |
| 760 | output->width, output->height); |
| 761 | pixman_region32_fini(&surface->input); |
| 762 | pixman_region32_init(&surface->input); |
| 763 | |
| 764 | wl_list_init(&fsurf->workspace_transform.link); |
| 765 | |
| 766 | return fsurf; |
| 767 | } |
| 768 | |
| 769 | static void |
| 770 | focus_surface_destroy(struct focus_surface *fsurf) |
| 771 | { |
| 772 | weston_surface_destroy(fsurf->surface); |
| 773 | free(fsurf); |
| 774 | } |
| 775 | |
| 776 | static void |
| 777 | focus_animation_done(struct weston_view_animation *animation, void *data) |
| 778 | { |
| 779 | struct workspace *ws = data; |
| 780 | |
| 781 | ws->focus_animation = NULL; |
| 782 | } |
| 783 | |
Jonas Ådahl | e3cddce | 2012-06-13 00:01:22 +0200 | [diff] [blame] | 784 | static void |
Jonas Ådahl | 0476974 | 2012-06-13 00:01:24 +0200 | [diff] [blame] | 785 | focus_state_destroy(struct focus_state *state) |
| 786 | { |
| 787 | wl_list_remove(&state->seat_destroy_listener.link); |
| 788 | wl_list_remove(&state->surface_destroy_listener.link); |
| 789 | free(state); |
| 790 | } |
| 791 | |
| 792 | static void |
| 793 | focus_state_seat_destroy(struct wl_listener *listener, void *data) |
| 794 | { |
| 795 | struct focus_state *state = container_of(listener, |
| 796 | struct focus_state, |
| 797 | seat_destroy_listener); |
| 798 | |
| 799 | wl_list_remove(&state->link); |
| 800 | focus_state_destroy(state); |
| 801 | } |
| 802 | |
| 803 | static void |
| 804 | focus_state_surface_destroy(struct wl_listener *listener, void *data) |
| 805 | { |
| 806 | struct focus_state *state = container_of(listener, |
| 807 | struct focus_state, |
Kristian Høgsberg | b8e0d0f | 2012-07-31 10:30:26 -0400 | [diff] [blame] | 808 | surface_destroy_listener); |
Kristian Høgsberg | e377822 | 2012-07-31 17:29:30 -0400 | [diff] [blame] | 809 | struct desktop_shell *shell; |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 810 | struct weston_surface *main_surface, *next; |
| 811 | struct weston_view *view; |
Jonas Ådahl | 0476974 | 2012-06-13 00:01:24 +0200 | [diff] [blame] | 812 | |
Pekka Paalanen | 01388e2 | 2013-04-25 13:57:44 +0300 | [diff] [blame] | 813 | main_surface = weston_surface_get_main_surface(state->keyboard_focus); |
| 814 | |
Kristian Høgsberg | e377822 | 2012-07-31 17:29:30 -0400 | [diff] [blame] | 815 | next = NULL; |
Giulio Camuffo | 412e6a5 | 2014-07-09 22:12:56 +0300 | [diff] [blame] | 816 | wl_list_for_each(view, |
| 817 | &state->ws->layer.view_list.link, layer_link.link) { |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 818 | if (view->surface == main_surface) |
Kristian Høgsberg | e377822 | 2012-07-31 17:29:30 -0400 | [diff] [blame] | 819 | continue; |
Louis-Francis Ratté-Boulianne | b482dbd | 2013-11-19 11:37:11 +0100 | [diff] [blame] | 820 | if (is_focus_view(view)) |
| 821 | continue; |
Kristian Høgsberg | e377822 | 2012-07-31 17:29:30 -0400 | [diff] [blame] | 822 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 823 | next = view->surface; |
Kristian Høgsberg | e377822 | 2012-07-31 17:29:30 -0400 | [diff] [blame] | 824 | break; |
| 825 | } |
| 826 | |
Pekka Paalanen | 01388e2 | 2013-04-25 13:57:44 +0300 | [diff] [blame] | 827 | /* if the focus was a sub-surface, activate its main surface */ |
| 828 | if (main_surface != state->keyboard_focus) |
| 829 | next = main_surface; |
| 830 | |
Louis-Francis Ratté-Boulianne | b482dbd | 2013-11-19 11:37:11 +0100 | [diff] [blame] | 831 | shell = state->seat->compositor->shell_interface.shell; |
Kristian Høgsberg | e377822 | 2012-07-31 17:29:30 -0400 | [diff] [blame] | 832 | if (next) { |
Louis-Francis Ratté-Boulianne | b482dbd | 2013-11-19 11:37:11 +0100 | [diff] [blame] | 833 | state->keyboard_focus = NULL; |
Emilio Pozuelo Monfort | 9e7c759 | 2014-01-30 14:01:10 +0100 | [diff] [blame] | 834 | activate(shell, next, state->seat, true); |
Kristian Høgsberg | e377822 | 2012-07-31 17:29:30 -0400 | [diff] [blame] | 835 | } else { |
Louis-Francis Ratté-Boulianne | b482dbd | 2013-11-19 11:37:11 +0100 | [diff] [blame] | 836 | if (shell->focus_animation_type == ANIMATION_DIM_LAYER) { |
| 837 | if (state->ws->focus_animation) |
| 838 | weston_view_animation_destroy(state->ws->focus_animation); |
| 839 | |
| 840 | state->ws->focus_animation = weston_fade_run( |
| 841 | state->ws->fsurf_front->view, |
| 842 | state->ws->fsurf_front->view->alpha, 0.0, 300, |
| 843 | focus_animation_done, state->ws); |
| 844 | } |
| 845 | |
Kristian Høgsberg | e377822 | 2012-07-31 17:29:30 -0400 | [diff] [blame] | 846 | wl_list_remove(&state->link); |
| 847 | focus_state_destroy(state); |
| 848 | } |
Jonas Ådahl | 0476974 | 2012-06-13 00:01:24 +0200 | [diff] [blame] | 849 | } |
| 850 | |
| 851 | static struct focus_state * |
Kristian Høgsberg | 2f5faff | 2012-07-31 16:36:34 -0400 | [diff] [blame] | 852 | focus_state_create(struct weston_seat *seat, struct workspace *ws) |
Jonas Ådahl | 0476974 | 2012-06-13 00:01:24 +0200 | [diff] [blame] | 853 | { |
Jonas Ådahl | 0476974 | 2012-06-13 00:01:24 +0200 | [diff] [blame] | 854 | struct focus_state *state; |
Jonas Ådahl | 0476974 | 2012-06-13 00:01:24 +0200 | [diff] [blame] | 855 | |
| 856 | state = malloc(sizeof *state); |
| 857 | if (state == NULL) |
| 858 | return NULL; |
| 859 | |
Louis-Francis Ratté-Boulianne | b482dbd | 2013-11-19 11:37:11 +0100 | [diff] [blame] | 860 | state->keyboard_focus = NULL; |
Kristian Høgsberg | 2f5faff | 2012-07-31 16:36:34 -0400 | [diff] [blame] | 861 | state->ws = ws; |
Jonas Ådahl | 0476974 | 2012-06-13 00:01:24 +0200 | [diff] [blame] | 862 | state->seat = seat; |
Kristian Høgsberg | 2f5faff | 2012-07-31 16:36:34 -0400 | [diff] [blame] | 863 | wl_list_insert(&ws->focus_list, &state->link); |
Jonas Ådahl | 0476974 | 2012-06-13 00:01:24 +0200 | [diff] [blame] | 864 | |
| 865 | state->seat_destroy_listener.notify = focus_state_seat_destroy; |
| 866 | state->surface_destroy_listener.notify = focus_state_surface_destroy; |
Kristian Høgsberg | 4912454 | 2013-05-06 22:27:40 -0400 | [diff] [blame] | 867 | wl_signal_add(&seat->destroy_signal, |
Jonas Ådahl | 0476974 | 2012-06-13 00:01:24 +0200 | [diff] [blame] | 868 | &state->seat_destroy_listener); |
Kristian Høgsberg | 2f5faff | 2012-07-31 16:36:34 -0400 | [diff] [blame] | 869 | wl_list_init(&state->surface_destroy_listener.link); |
Jonas Ådahl | 0476974 | 2012-06-13 00:01:24 +0200 | [diff] [blame] | 870 | |
| 871 | return state; |
| 872 | } |
| 873 | |
Jonas Ådahl | 8538b22 | 2012-08-29 22:13:03 +0200 | [diff] [blame] | 874 | static struct focus_state * |
| 875 | ensure_focus_state(struct desktop_shell *shell, struct weston_seat *seat) |
| 876 | { |
| 877 | struct workspace *ws = get_current_workspace(shell); |
| 878 | struct focus_state *state; |
| 879 | |
| 880 | wl_list_for_each(state, &ws->focus_list, link) |
| 881 | if (state->seat == seat) |
| 882 | break; |
| 883 | |
| 884 | if (&state->link == &ws->focus_list) |
| 885 | state = focus_state_create(seat, ws); |
| 886 | |
| 887 | return state; |
| 888 | } |
| 889 | |
Jonas Ådahl | 0476974 | 2012-06-13 00:01:24 +0200 | [diff] [blame] | 890 | static void |
Kristian Høgsberg | d500bf1 | 2014-01-22 12:25:20 -0800 | [diff] [blame] | 891 | focus_state_set_focus(struct focus_state *state, |
| 892 | struct weston_surface *surface) |
| 893 | { |
| 894 | if (state->keyboard_focus) { |
| 895 | wl_list_remove(&state->surface_destroy_listener.link); |
| 896 | wl_list_init(&state->surface_destroy_listener.link); |
| 897 | } |
| 898 | |
| 899 | state->keyboard_focus = surface; |
| 900 | if (surface) |
| 901 | wl_signal_add(&surface->destroy_signal, |
| 902 | &state->surface_destroy_listener); |
| 903 | } |
| 904 | |
| 905 | static void |
Kristian Høgsberg | 2f5faff | 2012-07-31 16:36:34 -0400 | [diff] [blame] | 906 | restore_focus_state(struct desktop_shell *shell, struct workspace *ws) |
Jonas Ådahl | 0476974 | 2012-06-13 00:01:24 +0200 | [diff] [blame] | 907 | { |
| 908 | struct focus_state *state, *next; |
Kristian Høgsberg | fe7aa90 | 2013-05-08 09:54:37 -0400 | [diff] [blame] | 909 | struct weston_surface *surface; |
Neil Roberts | 4237f50 | 2014-04-09 16:33:31 +0100 | [diff] [blame] | 910 | struct wl_list pending_seat_list; |
| 911 | struct weston_seat *seat, *next_seat; |
| 912 | |
| 913 | /* Temporarily steal the list of seats so that we can keep |
| 914 | * track of the seats we've already processed */ |
| 915 | wl_list_init(&pending_seat_list); |
| 916 | wl_list_insert_list(&pending_seat_list, &shell->compositor->seat_list); |
| 917 | wl_list_init(&shell->compositor->seat_list); |
Jonas Ådahl | 0476974 | 2012-06-13 00:01:24 +0200 | [diff] [blame] | 918 | |
| 919 | wl_list_for_each_safe(state, next, &ws->focus_list, link) { |
Derek Foreman | 1281a36 | 2015-07-31 16:55:32 -0500 | [diff] [blame] | 920 | struct weston_keyboard *keyboard = |
| 921 | weston_seat_get_keyboard(state->seat); |
| 922 | |
Neil Roberts | 4237f50 | 2014-04-09 16:33:31 +0100 | [diff] [blame] | 923 | wl_list_remove(&state->seat->link); |
| 924 | wl_list_insert(&shell->compositor->seat_list, |
| 925 | &state->seat->link); |
| 926 | |
Derek Foreman | 1281a36 | 2015-07-31 16:55:32 -0500 | [diff] [blame] | 927 | if (!keyboard) |
Kristian Høgsberg | e61d2f4 | 2014-01-17 12:18:53 -0800 | [diff] [blame] | 928 | continue; |
| 929 | |
Kristian Høgsberg | fe7aa90 | 2013-05-08 09:54:37 -0400 | [diff] [blame] | 930 | surface = state->keyboard_focus; |
Jonas Ådahl | 5689944 | 2012-08-29 22:12:59 +0200 | [diff] [blame] | 931 | |
Derek Foreman | 1281a36 | 2015-07-31 16:55:32 -0500 | [diff] [blame] | 932 | weston_keyboard_set_focus(keyboard, surface); |
Jonas Ådahl | 0476974 | 2012-06-13 00:01:24 +0200 | [diff] [blame] | 933 | } |
Neil Roberts | 4237f50 | 2014-04-09 16:33:31 +0100 | [diff] [blame] | 934 | |
| 935 | /* For any remaining seats that we don't have a focus state |
| 936 | * for we'll reset the keyboard focus to NULL */ |
| 937 | wl_list_for_each_safe(seat, next_seat, &pending_seat_list, link) { |
Derek Foreman | 1281a36 | 2015-07-31 16:55:32 -0500 | [diff] [blame] | 938 | struct weston_keyboard *keyboard = |
| 939 | weston_seat_get_keyboard(seat); |
| 940 | |
Neil Roberts | 4237f50 | 2014-04-09 16:33:31 +0100 | [diff] [blame] | 941 | wl_list_insert(&shell->compositor->seat_list, &seat->link); |
| 942 | |
Derek Foreman | 1281a36 | 2015-07-31 16:55:32 -0500 | [diff] [blame] | 943 | if (!keyboard) |
Neil Roberts | 4237f50 | 2014-04-09 16:33:31 +0100 | [diff] [blame] | 944 | continue; |
| 945 | |
Derek Foreman | 1281a36 | 2015-07-31 16:55:32 -0500 | [diff] [blame] | 946 | weston_keyboard_set_focus(keyboard, NULL); |
Neil Roberts | 4237f50 | 2014-04-09 16:33:31 +0100 | [diff] [blame] | 947 | } |
Jonas Ådahl | 0476974 | 2012-06-13 00:01:24 +0200 | [diff] [blame] | 948 | } |
| 949 | |
| 950 | static void |
Jonas Ådahl | 8de6a1d | 2012-08-29 22:13:00 +0200 | [diff] [blame] | 951 | replace_focus_state(struct desktop_shell *shell, struct workspace *ws, |
| 952 | struct weston_seat *seat) |
| 953 | { |
Derek Foreman | 1281a36 | 2015-07-31 16:55:32 -0500 | [diff] [blame] | 954 | struct weston_keyboard *keyboard = weston_seat_get_keyboard(seat); |
Jonas Ådahl | 8de6a1d | 2012-08-29 22:13:00 +0200 | [diff] [blame] | 955 | struct focus_state *state; |
Jonas Ådahl | 8de6a1d | 2012-08-29 22:13:00 +0200 | [diff] [blame] | 956 | |
| 957 | wl_list_for_each(state, &ws->focus_list, link) { |
| 958 | if (state->seat == seat) { |
Derek Foreman | 1281a36 | 2015-07-31 16:55:32 -0500 | [diff] [blame] | 959 | focus_state_set_focus(state, keyboard->focus); |
Jonas Ådahl | 8de6a1d | 2012-08-29 22:13:00 +0200 | [diff] [blame] | 960 | return; |
| 961 | } |
| 962 | } |
| 963 | } |
| 964 | |
| 965 | static void |
| 966 | drop_focus_state(struct desktop_shell *shell, struct workspace *ws, |
| 967 | struct weston_surface *surface) |
| 968 | { |
| 969 | struct focus_state *state; |
| 970 | |
| 971 | wl_list_for_each(state, &ws->focus_list, link) |
| 972 | if (state->keyboard_focus == surface) |
Kristian Høgsberg | d500bf1 | 2014-01-22 12:25:20 -0800 | [diff] [blame] | 973 | focus_state_set_focus(state, NULL); |
Jonas Ådahl | 8de6a1d | 2012-08-29 22:13:00 +0200 | [diff] [blame] | 974 | } |
| 975 | |
| 976 | static void |
Louis-Francis Ratté-Boulianne | b482dbd | 2013-11-19 11:37:11 +0100 | [diff] [blame] | 977 | animate_focus_change(struct desktop_shell *shell, struct workspace *ws, |
| 978 | struct weston_view *from, struct weston_view *to) |
| 979 | { |
| 980 | struct weston_output *output; |
| 981 | bool focus_surface_created = false; |
| 982 | |
| 983 | /* FIXME: Only support dim animation using two layers */ |
| 984 | if (from == to || shell->focus_animation_type != ANIMATION_DIM_LAYER) |
| 985 | return; |
| 986 | |
| 987 | output = get_default_output(shell->compositor); |
| 988 | if (ws->fsurf_front == NULL && (from || to)) { |
| 989 | ws->fsurf_front = create_focus_surface(shell->compositor, output); |
U. Artie Eoff | 0b23b2b | 2014-01-15 14:45:59 -0800 | [diff] [blame] | 990 | if (ws->fsurf_front == NULL) |
| 991 | return; |
Louis-Francis Ratté-Boulianne | b482dbd | 2013-11-19 11:37:11 +0100 | [diff] [blame] | 992 | ws->fsurf_front->view->alpha = 0.0; |
U. Artie Eoff | 0b23b2b | 2014-01-15 14:45:59 -0800 | [diff] [blame] | 993 | |
| 994 | ws->fsurf_back = create_focus_surface(shell->compositor, output); |
| 995 | if (ws->fsurf_back == NULL) { |
| 996 | focus_surface_destroy(ws->fsurf_front); |
| 997 | return; |
| 998 | } |
Louis-Francis Ratté-Boulianne | b482dbd | 2013-11-19 11:37:11 +0100 | [diff] [blame] | 999 | ws->fsurf_back->view->alpha = 0.0; |
U. Artie Eoff | 0b23b2b | 2014-01-15 14:45:59 -0800 | [diff] [blame] | 1000 | |
Louis-Francis Ratté-Boulianne | b482dbd | 2013-11-19 11:37:11 +0100 | [diff] [blame] | 1001 | focus_surface_created = true; |
| 1002 | } else { |
Giulio Camuffo | 412e6a5 | 2014-07-09 22:12:56 +0300 | [diff] [blame] | 1003 | weston_layer_entry_remove(&ws->fsurf_front->view->layer_link); |
| 1004 | weston_layer_entry_remove(&ws->fsurf_back->view->layer_link); |
Louis-Francis Ratté-Boulianne | b482dbd | 2013-11-19 11:37:11 +0100 | [diff] [blame] | 1005 | } |
| 1006 | |
| 1007 | if (ws->focus_animation) { |
| 1008 | weston_view_animation_destroy(ws->focus_animation); |
| 1009 | ws->focus_animation = NULL; |
| 1010 | } |
| 1011 | |
| 1012 | if (to) |
Giulio Camuffo | 412e6a5 | 2014-07-09 22:12:56 +0300 | [diff] [blame] | 1013 | weston_layer_entry_insert(&to->layer_link, |
| 1014 | &ws->fsurf_front->view->layer_link); |
Louis-Francis Ratté-Boulianne | b482dbd | 2013-11-19 11:37:11 +0100 | [diff] [blame] | 1015 | else if (from) |
Giulio Camuffo | 412e6a5 | 2014-07-09 22:12:56 +0300 | [diff] [blame] | 1016 | weston_layer_entry_insert(&ws->layer.view_list, |
| 1017 | &ws->fsurf_front->view->layer_link); |
Louis-Francis Ratté-Boulianne | b482dbd | 2013-11-19 11:37:11 +0100 | [diff] [blame] | 1018 | |
| 1019 | if (focus_surface_created) { |
| 1020 | ws->focus_animation = weston_fade_run( |
| 1021 | ws->fsurf_front->view, |
Jonny Lamb | 7e7d485 | 2014-05-22 22:41:34 +0200 | [diff] [blame] | 1022 | ws->fsurf_front->view->alpha, 0.4, 300, |
Louis-Francis Ratté-Boulianne | b482dbd | 2013-11-19 11:37:11 +0100 | [diff] [blame] | 1023 | focus_animation_done, ws); |
| 1024 | } else if (from) { |
Giulio Camuffo | 412e6a5 | 2014-07-09 22:12:56 +0300 | [diff] [blame] | 1025 | weston_layer_entry_insert(&from->layer_link, |
| 1026 | &ws->fsurf_back->view->layer_link); |
Louis-Francis Ratté-Boulianne | b482dbd | 2013-11-19 11:37:11 +0100 | [diff] [blame] | 1027 | ws->focus_animation = weston_stable_fade_run( |
| 1028 | ws->fsurf_front->view, 0.0, |
Jonny Lamb | 7e7d485 | 2014-05-22 22:41:34 +0200 | [diff] [blame] | 1029 | ws->fsurf_back->view, 0.4, |
Louis-Francis Ratté-Boulianne | b482dbd | 2013-11-19 11:37:11 +0100 | [diff] [blame] | 1030 | focus_animation_done, ws); |
| 1031 | } else if (to) { |
Giulio Camuffo | 412e6a5 | 2014-07-09 22:12:56 +0300 | [diff] [blame] | 1032 | weston_layer_entry_insert(&ws->layer.view_list, |
| 1033 | &ws->fsurf_back->view->layer_link); |
Louis-Francis Ratté-Boulianne | b482dbd | 2013-11-19 11:37:11 +0100 | [diff] [blame] | 1034 | ws->focus_animation = weston_stable_fade_run( |
| 1035 | ws->fsurf_front->view, 0.0, |
Jonny Lamb | 7e7d485 | 2014-05-22 22:41:34 +0200 | [diff] [blame] | 1036 | ws->fsurf_back->view, 0.4, |
Louis-Francis Ratté-Boulianne | b482dbd | 2013-11-19 11:37:11 +0100 | [diff] [blame] | 1037 | focus_animation_done, ws); |
| 1038 | } |
| 1039 | } |
| 1040 | |
| 1041 | static void |
Jonas Ådahl | e3cddce | 2012-06-13 00:01:22 +0200 | [diff] [blame] | 1042 | workspace_destroy(struct workspace *ws) |
| 1043 | { |
Jonas Ådahl | 0476974 | 2012-06-13 00:01:24 +0200 | [diff] [blame] | 1044 | struct focus_state *state, *next; |
| 1045 | |
| 1046 | wl_list_for_each_safe(state, next, &ws->focus_list, link) |
| 1047 | focus_state_destroy(state); |
| 1048 | |
Louis-Francis Ratté-Boulianne | b482dbd | 2013-11-19 11:37:11 +0100 | [diff] [blame] | 1049 | if (ws->fsurf_front) |
| 1050 | focus_surface_destroy(ws->fsurf_front); |
| 1051 | if (ws->fsurf_back) |
| 1052 | focus_surface_destroy(ws->fsurf_back); |
| 1053 | |
Jonas Ådahl | e3cddce | 2012-06-13 00:01:22 +0200 | [diff] [blame] | 1054 | free(ws); |
| 1055 | } |
| 1056 | |
Jonas Ådahl | 0476974 | 2012-06-13 00:01:24 +0200 | [diff] [blame] | 1057 | static void |
| 1058 | seat_destroyed(struct wl_listener *listener, void *data) |
| 1059 | { |
| 1060 | struct weston_seat *seat = data; |
| 1061 | struct focus_state *state, *next; |
| 1062 | struct workspace *ws = container_of(listener, |
| 1063 | struct workspace, |
| 1064 | seat_destroyed_listener); |
| 1065 | |
| 1066 | wl_list_for_each_safe(state, next, &ws->focus_list, link) |
| 1067 | if (state->seat == seat) |
| 1068 | wl_list_remove(&state->link); |
| 1069 | } |
| 1070 | |
Jonas Ådahl | e3cddce | 2012-06-13 00:01:22 +0200 | [diff] [blame] | 1071 | static struct workspace * |
| 1072 | workspace_create(void) |
| 1073 | { |
| 1074 | struct workspace *ws = malloc(sizeof *ws); |
| 1075 | if (ws == NULL) |
| 1076 | return NULL; |
| 1077 | |
| 1078 | weston_layer_init(&ws->layer, NULL); |
| 1079 | |
Jonas Ådahl | 0476974 | 2012-06-13 00:01:24 +0200 | [diff] [blame] | 1080 | wl_list_init(&ws->focus_list); |
| 1081 | wl_list_init(&ws->seat_destroyed_listener.link); |
| 1082 | ws->seat_destroyed_listener.notify = seat_destroyed; |
Louis-Francis Ratté-Boulianne | b482dbd | 2013-11-19 11:37:11 +0100 | [diff] [blame] | 1083 | ws->fsurf_front = NULL; |
| 1084 | ws->fsurf_back = NULL; |
| 1085 | ws->focus_animation = NULL; |
Jonas Ådahl | 0476974 | 2012-06-13 00:01:24 +0200 | [diff] [blame] | 1086 | |
Jonas Ådahl | e3cddce | 2012-06-13 00:01:22 +0200 | [diff] [blame] | 1087 | return ws; |
| 1088 | } |
| 1089 | |
Jonas Ådahl | 62fcd04 | 2012-06-13 00:01:23 +0200 | [diff] [blame] | 1090 | static int |
| 1091 | workspace_is_empty(struct workspace *ws) |
| 1092 | { |
Giulio Camuffo | 412e6a5 | 2014-07-09 22:12:56 +0300 | [diff] [blame] | 1093 | return wl_list_empty(&ws->layer.view_list.link); |
Jonas Ådahl | 62fcd04 | 2012-06-13 00:01:23 +0200 | [diff] [blame] | 1094 | } |
| 1095 | |
Jonas Ådahl | e3cddce | 2012-06-13 00:01:22 +0200 | [diff] [blame] | 1096 | static struct workspace * |
| 1097 | get_workspace(struct desktop_shell *shell, unsigned int index) |
| 1098 | { |
| 1099 | struct workspace **pws = shell->workspaces.array.data; |
Philipp Brüschweiler | 067abf6 | 2012-09-01 16:03:05 +0200 | [diff] [blame] | 1100 | assert(index < shell->workspaces.num); |
Jonas Ådahl | e3cddce | 2012-06-13 00:01:22 +0200 | [diff] [blame] | 1101 | pws += index; |
| 1102 | return *pws; |
| 1103 | } |
| 1104 | |
Kristian Høgsberg | 1ef2313 | 2013-12-04 00:20:01 -0800 | [diff] [blame] | 1105 | struct workspace * |
Jonas Ådahl | e3cddce | 2012-06-13 00:01:22 +0200 | [diff] [blame] | 1106 | get_current_workspace(struct desktop_shell *shell) |
| 1107 | { |
| 1108 | return get_workspace(shell, shell->workspaces.current); |
| 1109 | } |
| 1110 | |
| 1111 | static void |
| 1112 | activate_workspace(struct desktop_shell *shell, unsigned int index) |
| 1113 | { |
| 1114 | struct workspace *ws; |
| 1115 | |
| 1116 | ws = get_workspace(shell, index); |
| 1117 | wl_list_insert(&shell->panel_layer.link, &ws->layer.link); |
| 1118 | |
| 1119 | shell->workspaces.current = index; |
| 1120 | } |
| 1121 | |
Jonas Ådahl | 62fcd04 | 2012-06-13 00:01:23 +0200 | [diff] [blame] | 1122 | static unsigned int |
| 1123 | get_output_height(struct weston_output *output) |
| 1124 | { |
| 1125 | return abs(output->region.extents.y1 - output->region.extents.y2); |
| 1126 | } |
| 1127 | |
| 1128 | static void |
Louis-Francis Ratté-Boulianne | b482dbd | 2013-11-19 11:37:11 +0100 | [diff] [blame] | 1129 | view_translate(struct workspace *ws, struct weston_view *view, double d) |
Jonas Ådahl | 62fcd04 | 2012-06-13 00:01:23 +0200 | [diff] [blame] | 1130 | { |
Jonas Ådahl | 62fcd04 | 2012-06-13 00:01:23 +0200 | [diff] [blame] | 1131 | struct weston_transform *transform; |
| 1132 | |
Louis-Francis Ratté-Boulianne | b482dbd | 2013-11-19 11:37:11 +0100 | [diff] [blame] | 1133 | if (is_focus_view(view)) { |
| 1134 | struct focus_surface *fsurf = get_focus_surface(view->surface); |
| 1135 | transform = &fsurf->workspace_transform; |
| 1136 | } else { |
| 1137 | struct shell_surface *shsurf = get_shell_surface(view->surface); |
| 1138 | transform = &shsurf->workspace_transform; |
| 1139 | } |
| 1140 | |
Jonas Ådahl | 62fcd04 | 2012-06-13 00:01:23 +0200 | [diff] [blame] | 1141 | if (wl_list_empty(&transform->link)) |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 1142 | wl_list_insert(view->geometry.transformation_list.prev, |
Louis-Francis Ratté-Boulianne | b482dbd | 2013-11-19 11:37:11 +0100 | [diff] [blame] | 1143 | &transform->link); |
Jonas Ådahl | 62fcd04 | 2012-06-13 00:01:23 +0200 | [diff] [blame] | 1144 | |
Louis-Francis Ratté-Boulianne | b482dbd | 2013-11-19 11:37:11 +0100 | [diff] [blame] | 1145 | weston_matrix_init(&transform->matrix); |
| 1146 | weston_matrix_translate(&transform->matrix, |
Jonas Ådahl | 62fcd04 | 2012-06-13 00:01:23 +0200 | [diff] [blame] | 1147 | 0.0, d, 0.0); |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 1148 | weston_view_geometry_dirty(view); |
Jonas Ådahl | 62fcd04 | 2012-06-13 00:01:23 +0200 | [diff] [blame] | 1149 | } |
| 1150 | |
| 1151 | static void |
| 1152 | workspace_translate_out(struct workspace *ws, double fraction) |
| 1153 | { |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 1154 | struct weston_view *view; |
Jonas Ådahl | 62fcd04 | 2012-06-13 00:01:23 +0200 | [diff] [blame] | 1155 | unsigned int height; |
| 1156 | double d; |
| 1157 | |
Giulio Camuffo | 412e6a5 | 2014-07-09 22:12:56 +0300 | [diff] [blame] | 1158 | wl_list_for_each(view, &ws->layer.view_list.link, layer_link.link) { |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 1159 | height = get_output_height(view->surface->output); |
Jonas Ådahl | 62fcd04 | 2012-06-13 00:01:23 +0200 | [diff] [blame] | 1160 | d = height * fraction; |
| 1161 | |
Louis-Francis Ratté-Boulianne | b482dbd | 2013-11-19 11:37:11 +0100 | [diff] [blame] | 1162 | view_translate(ws, view, d); |
Jonas Ådahl | 62fcd04 | 2012-06-13 00:01:23 +0200 | [diff] [blame] | 1163 | } |
| 1164 | } |
| 1165 | |
| 1166 | static void |
| 1167 | workspace_translate_in(struct workspace *ws, double fraction) |
| 1168 | { |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 1169 | struct weston_view *view; |
Jonas Ådahl | 62fcd04 | 2012-06-13 00:01:23 +0200 | [diff] [blame] | 1170 | unsigned int height; |
| 1171 | double d; |
| 1172 | |
Giulio Camuffo | 412e6a5 | 2014-07-09 22:12:56 +0300 | [diff] [blame] | 1173 | 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] | 1174 | height = get_output_height(view->surface->output); |
Jonas Ådahl | 62fcd04 | 2012-06-13 00:01:23 +0200 | [diff] [blame] | 1175 | |
| 1176 | if (fraction > 0) |
| 1177 | d = -(height - height * fraction); |
| 1178 | else |
| 1179 | d = height + height * fraction; |
| 1180 | |
Louis-Francis Ratté-Boulianne | b482dbd | 2013-11-19 11:37:11 +0100 | [diff] [blame] | 1181 | view_translate(ws, view, d); |
Jonas Ådahl | 62fcd04 | 2012-06-13 00:01:23 +0200 | [diff] [blame] | 1182 | } |
| 1183 | } |
| 1184 | |
| 1185 | static void |
Jonas Ådahl | 62fcd04 | 2012-06-13 00:01:23 +0200 | [diff] [blame] | 1186 | reverse_workspace_change_animation(struct desktop_shell *shell, |
| 1187 | unsigned int index, |
| 1188 | struct workspace *from, |
| 1189 | struct workspace *to) |
| 1190 | { |
| 1191 | shell->workspaces.current = index; |
| 1192 | |
| 1193 | shell->workspaces.anim_to = to; |
| 1194 | shell->workspaces.anim_from = from; |
| 1195 | shell->workspaces.anim_dir = -1 * shell->workspaces.anim_dir; |
| 1196 | shell->workspaces.anim_timestamp = 0; |
| 1197 | |
Scott Moreau | 4272e63 | 2012-08-13 09:58:41 -0600 | [diff] [blame] | 1198 | weston_compositor_schedule_repaint(shell->compositor); |
Jonas Ådahl | 62fcd04 | 2012-06-13 00:01:23 +0200 | [diff] [blame] | 1199 | } |
| 1200 | |
| 1201 | static void |
| 1202 | workspace_deactivate_transforms(struct workspace *ws) |
| 1203 | { |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 1204 | struct weston_view *view; |
Louis-Francis Ratté-Boulianne | b482dbd | 2013-11-19 11:37:11 +0100 | [diff] [blame] | 1205 | struct weston_transform *transform; |
Jonas Ådahl | 62fcd04 | 2012-06-13 00:01:23 +0200 | [diff] [blame] | 1206 | |
Giulio Camuffo | 412e6a5 | 2014-07-09 22:12:56 +0300 | [diff] [blame] | 1207 | 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] | 1208 | if (is_focus_view(view)) { |
| 1209 | struct focus_surface *fsurf = get_focus_surface(view->surface); |
| 1210 | transform = &fsurf->workspace_transform; |
| 1211 | } else { |
| 1212 | struct shell_surface *shsurf = get_shell_surface(view->surface); |
| 1213 | transform = &shsurf->workspace_transform; |
| 1214 | } |
| 1215 | |
| 1216 | if (!wl_list_empty(&transform->link)) { |
| 1217 | wl_list_remove(&transform->link); |
| 1218 | wl_list_init(&transform->link); |
Jonas Ådahl | 8de6a1d | 2012-08-29 22:13:00 +0200 | [diff] [blame] | 1219 | } |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 1220 | weston_view_geometry_dirty(view); |
Jonas Ådahl | 62fcd04 | 2012-06-13 00:01:23 +0200 | [diff] [blame] | 1221 | } |
| 1222 | } |
| 1223 | |
| 1224 | static void |
| 1225 | finish_workspace_change_animation(struct desktop_shell *shell, |
| 1226 | struct workspace *from, |
| 1227 | struct workspace *to) |
| 1228 | { |
Ander Conselvan de Oliveira | 9c6217e | 2014-05-07 11:57:26 +0300 | [diff] [blame] | 1229 | struct weston_view *view; |
| 1230 | |
Scott Moreau | 4272e63 | 2012-08-13 09:58:41 -0600 | [diff] [blame] | 1231 | weston_compositor_schedule_repaint(shell->compositor); |
Jonas Ådahl | 62fcd04 | 2012-06-13 00:01:23 +0200 | [diff] [blame] | 1232 | |
Ander Conselvan de Oliveira | 9c6217e | 2014-05-07 11:57:26 +0300 | [diff] [blame] | 1233 | /* Views that extend past the bottom of the output are still |
| 1234 | * visible after the workspace animation ends but before its layer |
| 1235 | * is hidden. In that case, we need to damage below those views so |
| 1236 | * that the screen is properly repainted. */ |
Giulio Camuffo | 412e6a5 | 2014-07-09 22:12:56 +0300 | [diff] [blame] | 1237 | 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] | 1238 | weston_view_damage_below(view); |
| 1239 | |
Jonas Ådahl | 62fcd04 | 2012-06-13 00:01:23 +0200 | [diff] [blame] | 1240 | wl_list_remove(&shell->workspaces.animation.link); |
| 1241 | workspace_deactivate_transforms(from); |
| 1242 | workspace_deactivate_transforms(to); |
| 1243 | shell->workspaces.anim_to = NULL; |
| 1244 | |
| 1245 | wl_list_remove(&shell->workspaces.anim_from->layer.link); |
| 1246 | } |
| 1247 | |
| 1248 | static void |
| 1249 | animate_workspace_change_frame(struct weston_animation *animation, |
| 1250 | struct weston_output *output, uint32_t msecs) |
| 1251 | { |
| 1252 | struct desktop_shell *shell = |
| 1253 | container_of(animation, struct desktop_shell, |
| 1254 | workspaces.animation); |
| 1255 | struct workspace *from = shell->workspaces.anim_from; |
| 1256 | struct workspace *to = shell->workspaces.anim_to; |
| 1257 | uint32_t t; |
| 1258 | double x, y; |
| 1259 | |
| 1260 | if (workspace_is_empty(from) && workspace_is_empty(to)) { |
| 1261 | finish_workspace_change_animation(shell, from, to); |
| 1262 | return; |
| 1263 | } |
| 1264 | |
| 1265 | if (shell->workspaces.anim_timestamp == 0) { |
| 1266 | if (shell->workspaces.anim_current == 0.0) |
| 1267 | shell->workspaces.anim_timestamp = msecs; |
| 1268 | else |
| 1269 | shell->workspaces.anim_timestamp = |
| 1270 | msecs - |
| 1271 | /* Invers of movement function 'y' below. */ |
| 1272 | (asin(1.0 - shell->workspaces.anim_current) * |
| 1273 | DEFAULT_WORKSPACE_CHANGE_ANIMATION_LENGTH * |
| 1274 | M_2_PI); |
| 1275 | } |
| 1276 | |
| 1277 | t = msecs - shell->workspaces.anim_timestamp; |
| 1278 | |
| 1279 | /* |
| 1280 | * x = [0, π/2] |
| 1281 | * y(x) = sin(x) |
| 1282 | */ |
| 1283 | x = t * (1.0/DEFAULT_WORKSPACE_CHANGE_ANIMATION_LENGTH) * M_PI_2; |
| 1284 | y = sin(x); |
| 1285 | |
| 1286 | if (t < DEFAULT_WORKSPACE_CHANGE_ANIMATION_LENGTH) { |
Scott Moreau | 4272e63 | 2012-08-13 09:58:41 -0600 | [diff] [blame] | 1287 | weston_compositor_schedule_repaint(shell->compositor); |
Jonas Ådahl | 62fcd04 | 2012-06-13 00:01:23 +0200 | [diff] [blame] | 1288 | |
| 1289 | workspace_translate_out(from, shell->workspaces.anim_dir * y); |
| 1290 | workspace_translate_in(to, shell->workspaces.anim_dir * y); |
| 1291 | shell->workspaces.anim_current = y; |
| 1292 | |
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 | } |
Jonas Ådahl | 0476974 | 2012-06-13 00:01:24 +0200 | [diff] [blame] | 1295 | else |
Jonas Ådahl | 62fcd04 | 2012-06-13 00:01:23 +0200 | [diff] [blame] | 1296 | finish_workspace_change_animation(shell, from, to); |
Jonas Ådahl | 62fcd04 | 2012-06-13 00:01:23 +0200 | [diff] [blame] | 1297 | } |
| 1298 | |
| 1299 | static void |
| 1300 | animate_workspace_change(struct desktop_shell *shell, |
| 1301 | unsigned int index, |
| 1302 | struct workspace *from, |
| 1303 | struct workspace *to) |
| 1304 | { |
| 1305 | struct weston_output *output; |
| 1306 | |
| 1307 | int dir; |
| 1308 | |
| 1309 | if (index > shell->workspaces.current) |
| 1310 | dir = -1; |
| 1311 | else |
| 1312 | dir = 1; |
| 1313 | |
| 1314 | shell->workspaces.current = index; |
| 1315 | |
| 1316 | shell->workspaces.anim_dir = dir; |
| 1317 | shell->workspaces.anim_from = from; |
| 1318 | shell->workspaces.anim_to = to; |
| 1319 | shell->workspaces.anim_current = 0.0; |
| 1320 | shell->workspaces.anim_timestamp = 0; |
| 1321 | |
| 1322 | output = container_of(shell->compositor->output_list.next, |
| 1323 | struct weston_output, link); |
| 1324 | wl_list_insert(&output->animation_list, |
| 1325 | &shell->workspaces.animation.link); |
| 1326 | |
Jonas Ådahl | 8de6a1d | 2012-08-29 22:13:00 +0200 | [diff] [blame] | 1327 | wl_list_insert(from->layer.link.prev, &to->layer.link); |
Jonas Ådahl | 62fcd04 | 2012-06-13 00:01:23 +0200 | [diff] [blame] | 1328 | |
| 1329 | workspace_translate_in(to, 0); |
| 1330 | |
Kristian Høgsberg | 2f5faff | 2012-07-31 16:36:34 -0400 | [diff] [blame] | 1331 | restore_focus_state(shell, to); |
Jonas Ådahl | 0476974 | 2012-06-13 00:01:24 +0200 | [diff] [blame] | 1332 | |
Scott Moreau | 4272e63 | 2012-08-13 09:58:41 -0600 | [diff] [blame] | 1333 | weston_compositor_schedule_repaint(shell->compositor); |
Jonas Ådahl | 62fcd04 | 2012-06-13 00:01:23 +0200 | [diff] [blame] | 1334 | } |
| 1335 | |
Jonas Ådahl | e3cddce | 2012-06-13 00:01:22 +0200 | [diff] [blame] | 1336 | static void |
Jonas Ådahl | 8de6a1d | 2012-08-29 22:13:00 +0200 | [diff] [blame] | 1337 | update_workspace(struct desktop_shell *shell, unsigned int index, |
| 1338 | struct workspace *from, struct workspace *to) |
| 1339 | { |
| 1340 | shell->workspaces.current = index; |
| 1341 | wl_list_insert(&from->layer.link, &to->layer.link); |
| 1342 | wl_list_remove(&from->layer.link); |
| 1343 | } |
| 1344 | |
| 1345 | static void |
Jonas Ådahl | e3cddce | 2012-06-13 00:01:22 +0200 | [diff] [blame] | 1346 | change_workspace(struct desktop_shell *shell, unsigned int index) |
| 1347 | { |
| 1348 | struct workspace *from; |
| 1349 | struct workspace *to; |
Louis-Francis Ratté-Boulianne | b482dbd | 2013-11-19 11:37:11 +0100 | [diff] [blame] | 1350 | struct focus_state *state; |
Jonas Ådahl | e3cddce | 2012-06-13 00:01:22 +0200 | [diff] [blame] | 1351 | |
| 1352 | if (index == shell->workspaces.current) |
| 1353 | return; |
| 1354 | |
| 1355 | /* Don't change workspace when there is any fullscreen surfaces. */ |
Giulio Camuffo | 412e6a5 | 2014-07-09 22:12:56 +0300 | [diff] [blame] | 1356 | if (!wl_list_empty(&shell->fullscreen_layer.view_list.link)) |
Jonas Ådahl | e3cddce | 2012-06-13 00:01:22 +0200 | [diff] [blame] | 1357 | return; |
| 1358 | |
Jonas Ådahl | e3cddce | 2012-06-13 00:01:22 +0200 | [diff] [blame] | 1359 | from = get_current_workspace(shell); |
| 1360 | to = get_workspace(shell, index); |
| 1361 | |
Jonas Ådahl | 62fcd04 | 2012-06-13 00:01:23 +0200 | [diff] [blame] | 1362 | if (shell->workspaces.anim_from == to && |
| 1363 | shell->workspaces.anim_to == from) { |
Jonas Ådahl | 8de6a1d | 2012-08-29 22:13:00 +0200 | [diff] [blame] | 1364 | restore_focus_state(shell, to); |
Jonas Ådahl | 62fcd04 | 2012-06-13 00:01:23 +0200 | [diff] [blame] | 1365 | reverse_workspace_change_animation(shell, index, from, to); |
| 1366 | return; |
| 1367 | } |
Jonas Ådahl | e3cddce | 2012-06-13 00:01:22 +0200 | [diff] [blame] | 1368 | |
Jonas Ådahl | 62fcd04 | 2012-06-13 00:01:23 +0200 | [diff] [blame] | 1369 | if (shell->workspaces.anim_to != NULL) |
| 1370 | finish_workspace_change_animation(shell, |
| 1371 | shell->workspaces.anim_from, |
| 1372 | shell->workspaces.anim_to); |
| 1373 | |
Jonas Ådahl | 8de6a1d | 2012-08-29 22:13:00 +0200 | [diff] [blame] | 1374 | restore_focus_state(shell, to); |
Jonas Ådahl | 0476974 | 2012-06-13 00:01:24 +0200 | [diff] [blame] | 1375 | |
Louis-Francis Ratté-Boulianne | b482dbd | 2013-11-19 11:37:11 +0100 | [diff] [blame] | 1376 | if (shell->focus_animation_type != ANIMATION_NONE) { |
| 1377 | wl_list_for_each(state, &from->focus_list, link) |
| 1378 | if (state->keyboard_focus) |
| 1379 | animate_focus_change(shell, from, |
| 1380 | get_default_view(state->keyboard_focus), NULL); |
| 1381 | |
| 1382 | wl_list_for_each(state, &to->focus_list, link) |
| 1383 | if (state->keyboard_focus) |
| 1384 | animate_focus_change(shell, to, |
| 1385 | NULL, get_default_view(state->keyboard_focus)); |
| 1386 | } |
| 1387 | |
Jonas Ådahl | 8de6a1d | 2012-08-29 22:13:00 +0200 | [diff] [blame] | 1388 | if (workspace_is_empty(to) && workspace_is_empty(from)) |
| 1389 | update_workspace(shell, index, from, to); |
Jonas Ådahl | 62fcd04 | 2012-06-13 00:01:23 +0200 | [diff] [blame] | 1390 | else |
| 1391 | animate_workspace_change(shell, index, from, to); |
Pekka Paalanen | e955f1e | 2011-12-07 11:49:52 +0200 | [diff] [blame] | 1392 | } |
| 1393 | |
Jonas Ådahl | 8de6a1d | 2012-08-29 22:13:00 +0200 | [diff] [blame] | 1394 | static bool |
| 1395 | workspace_has_only(struct workspace *ws, struct weston_surface *surface) |
| 1396 | { |
Giulio Camuffo | 412e6a5 | 2014-07-09 22:12:56 +0300 | [diff] [blame] | 1397 | struct wl_list *list = &ws->layer.view_list.link; |
Jonas Ådahl | 8de6a1d | 2012-08-29 22:13:00 +0200 | [diff] [blame] | 1398 | struct wl_list *e; |
| 1399 | |
| 1400 | if (wl_list_empty(list)) |
| 1401 | return false; |
| 1402 | |
| 1403 | e = list->next; |
| 1404 | |
| 1405 | if (e->next != list) |
| 1406 | return false; |
| 1407 | |
Giulio Camuffo | 412e6a5 | 2014-07-09 22:12:56 +0300 | [diff] [blame] | 1408 | return container_of(e, struct weston_view, layer_link.link)->surface == surface; |
Jonas Ådahl | 8de6a1d | 2012-08-29 22:13:00 +0200 | [diff] [blame] | 1409 | } |
| 1410 | |
| 1411 | static void |
Jonas Ådahl | 22faea1 | 2014-10-15 22:02:06 +0200 | [diff] [blame] | 1412 | surface_keyboard_focus_lost(struct weston_surface *surface) |
| 1413 | { |
| 1414 | struct weston_compositor *compositor = surface->compositor; |
| 1415 | struct weston_seat *seat; |
| 1416 | struct weston_surface *focus; |
| 1417 | |
| 1418 | wl_list_for_each(seat, &compositor->seat_list, link) { |
| 1419 | struct weston_keyboard *keyboard = |
| 1420 | weston_seat_get_keyboard(seat); |
| 1421 | |
| 1422 | if (!keyboard) |
| 1423 | continue; |
| 1424 | |
| 1425 | focus = weston_surface_get_main_surface(keyboard->focus); |
| 1426 | if (focus == surface) |
| 1427 | weston_keyboard_set_focus(keyboard, NULL); |
| 1428 | } |
| 1429 | } |
| 1430 | |
| 1431 | static void |
Jonas Ådahl | 8de6a1d | 2012-08-29 22:13:00 +0200 | [diff] [blame] | 1432 | take_surface_to_workspace_by_seat(struct desktop_shell *shell, |
Kristian Høgsberg | e314875 | 2013-05-06 23:19:49 -0400 | [diff] [blame] | 1433 | struct weston_seat *seat, |
Jonas Ådahl | 8de6a1d | 2012-08-29 22:13:00 +0200 | [diff] [blame] | 1434 | unsigned int index) |
| 1435 | { |
Derek Foreman | 1281a36 | 2015-07-31 16:55:32 -0500 | [diff] [blame] | 1436 | struct weston_keyboard *keyboard = weston_seat_get_keyboard(seat); |
Pekka Paalanen | 01388e2 | 2013-04-25 13:57:44 +0300 | [diff] [blame] | 1437 | struct weston_surface *surface; |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 1438 | struct weston_view *view; |
Jonas Ådahl | 8de6a1d | 2012-08-29 22:13:00 +0200 | [diff] [blame] | 1439 | struct shell_surface *shsurf; |
| 1440 | struct workspace *from; |
| 1441 | struct workspace *to; |
Jonas Ådahl | 8538b22 | 2012-08-29 22:13:03 +0200 | [diff] [blame] | 1442 | struct focus_state *state; |
Jonas Ådahl | 8de6a1d | 2012-08-29 22:13:00 +0200 | [diff] [blame] | 1443 | |
Derek Foreman | 1281a36 | 2015-07-31 16:55:32 -0500 | [diff] [blame] | 1444 | surface = weston_surface_get_main_surface(keyboard->focus); |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 1445 | view = get_default_view(surface); |
| 1446 | if (view == NULL || |
Louis-Francis Ratté-Boulianne | b482dbd | 2013-11-19 11:37:11 +0100 | [diff] [blame] | 1447 | index == shell->workspaces.current || |
| 1448 | is_focus_view(view)) |
Jonas Ådahl | 8de6a1d | 2012-08-29 22:13:00 +0200 | [diff] [blame] | 1449 | return; |
| 1450 | |
| 1451 | from = get_current_workspace(shell); |
| 1452 | to = get_workspace(shell, index); |
| 1453 | |
Giulio Camuffo | 412e6a5 | 2014-07-09 22:12:56 +0300 | [diff] [blame] | 1454 | weston_layer_entry_remove(&view->layer_link); |
| 1455 | weston_layer_entry_insert(&to->layer.view_list, &view->layer_link); |
Jonas Ådahl | 8de6a1d | 2012-08-29 22:13:00 +0200 | [diff] [blame] | 1456 | |
Philip Withnall | 659163d | 2013-11-25 18:01:36 +0000 | [diff] [blame] | 1457 | shsurf = get_shell_surface(surface); |
Philip Withnall | 648a4dd | 2013-11-25 18:01:44 +0000 | [diff] [blame] | 1458 | if (shsurf != NULL) |
| 1459 | shell_surface_update_child_surface_layers(shsurf); |
Philip Withnall | 659163d | 2013-11-25 18:01:36 +0000 | [diff] [blame] | 1460 | |
Jonas Ådahl | e9d2250 | 2012-08-29 22:13:01 +0200 | [diff] [blame] | 1461 | replace_focus_state(shell, to, seat); |
Jonas Ådahl | 8de6a1d | 2012-08-29 22:13:00 +0200 | [diff] [blame] | 1462 | drop_focus_state(shell, from, surface); |
| 1463 | |
| 1464 | if (shell->workspaces.anim_from == to && |
| 1465 | shell->workspaces.anim_to == from) { |
Jonas Ådahl | e9d2250 | 2012-08-29 22:13:01 +0200 | [diff] [blame] | 1466 | wl_list_remove(&to->layer.link); |
| 1467 | wl_list_insert(from->layer.link.prev, &to->layer.link); |
| 1468 | |
Jonas Ådahl | 8de6a1d | 2012-08-29 22:13:00 +0200 | [diff] [blame] | 1469 | reverse_workspace_change_animation(shell, index, from, to); |
Jonas Ådahl | e9d2250 | 2012-08-29 22:13:01 +0200 | [diff] [blame] | 1470 | |
Jonas Ådahl | 8de6a1d | 2012-08-29 22:13:00 +0200 | [diff] [blame] | 1471 | return; |
| 1472 | } |
| 1473 | |
| 1474 | if (shell->workspaces.anim_to != NULL) |
| 1475 | finish_workspace_change_animation(shell, |
| 1476 | shell->workspaces.anim_from, |
| 1477 | shell->workspaces.anim_to); |
| 1478 | |
| 1479 | if (workspace_is_empty(from) && |
| 1480 | workspace_has_only(to, surface)) |
| 1481 | update_workspace(shell, index, from, to); |
| 1482 | else { |
Philip Withnall | 2c3849b | 2013-11-25 18:01:45 +0000 | [diff] [blame] | 1483 | if (shsurf != NULL && |
| 1484 | wl_list_empty(&shsurf->workspace_transform.link)) |
Jonas Ådahl | 8de6a1d | 2012-08-29 22:13:00 +0200 | [diff] [blame] | 1485 | wl_list_insert(&shell->workspaces.anim_sticky_list, |
| 1486 | &shsurf->workspace_transform.link); |
| 1487 | |
| 1488 | animate_workspace_change(shell, index, from, to); |
| 1489 | } |
Jonas Ådahl | e9d2250 | 2012-08-29 22:13:01 +0200 | [diff] [blame] | 1490 | |
Jonas Ådahl | 8538b22 | 2012-08-29 22:13:03 +0200 | [diff] [blame] | 1491 | state = ensure_focus_state(shell, seat); |
| 1492 | if (state != NULL) |
Kristian Høgsberg | d500bf1 | 2014-01-22 12:25:20 -0800 | [diff] [blame] | 1493 | focus_state_set_focus(state, surface); |
Jonas Ådahl | e9d2250 | 2012-08-29 22:13:01 +0200 | [diff] [blame] | 1494 | } |
| 1495 | |
| 1496 | static void |
Rusty Lynch | 1084da5 | 2013-08-15 09:10:08 -0700 | [diff] [blame] | 1497 | touch_move_grab_down(struct weston_touch_grab *grab, uint32_t time, |
Giulio Camuffo | 61ed7b6 | 2015-07-08 11:55:28 +0300 | [diff] [blame] | 1498 | int touch_id, wl_fixed_t x, wl_fixed_t y) |
Rusty Lynch | 1084da5 | 2013-08-15 09:10:08 -0700 | [diff] [blame] | 1499 | { |
| 1500 | } |
| 1501 | |
| 1502 | static void |
| 1503 | touch_move_grab_up(struct weston_touch_grab *grab, uint32_t time, int touch_id) |
| 1504 | { |
Jonas Ådahl | 1c6e63e | 2013-10-25 23:18:04 +0200 | [diff] [blame] | 1505 | struct weston_touch_move_grab *move = |
| 1506 | (struct weston_touch_move_grab *) container_of( |
| 1507 | grab, struct shell_touch_grab, grab); |
Neil Roberts | e14aa4f | 2013-10-03 16:43:07 +0100 | [diff] [blame] | 1508 | |
Kristian Høgsberg | 8e80a31 | 2014-01-17 15:18:10 -0800 | [diff] [blame] | 1509 | if (touch_id == 0) |
| 1510 | move->active = 0; |
| 1511 | |
Jonas Ådahl | 9484b69 | 2013-12-02 22:05:03 +0100 | [diff] [blame] | 1512 | if (grab->touch->num_tp == 0) { |
Jonas Ådahl | 1c6e63e | 2013-10-25 23:18:04 +0200 | [diff] [blame] | 1513 | shell_touch_grab_end(&move->base); |
| 1514 | free(move); |
| 1515 | } |
Rusty Lynch | 1084da5 | 2013-08-15 09:10:08 -0700 | [diff] [blame] | 1516 | } |
| 1517 | |
| 1518 | static void |
| 1519 | touch_move_grab_motion(struct weston_touch_grab *grab, uint32_t time, |
Giulio Camuffo | 61ed7b6 | 2015-07-08 11:55:28 +0300 | [diff] [blame] | 1520 | int touch_id, wl_fixed_t x, wl_fixed_t y) |
Rusty Lynch | 1084da5 | 2013-08-15 09:10:08 -0700 | [diff] [blame] | 1521 | { |
| 1522 | struct weston_touch_move_grab *move = (struct weston_touch_move_grab *) grab; |
| 1523 | struct shell_surface *shsurf = move->base.shsurf; |
| 1524 | struct weston_surface *es; |
| 1525 | int dx = wl_fixed_to_int(grab->touch->grab_x + move->dx); |
| 1526 | int dy = wl_fixed_to_int(grab->touch->grab_y + move->dy); |
| 1527 | |
Kristian Høgsberg | 8e80a31 | 2014-01-17 15:18:10 -0800 | [diff] [blame] | 1528 | if (!shsurf || !move->active) |
Rusty Lynch | 1084da5 | 2013-08-15 09:10:08 -0700 | [diff] [blame] | 1529 | return; |
| 1530 | |
| 1531 | es = shsurf->surface; |
| 1532 | |
Jason Ekstrand | 918f2dd | 2013-12-02 21:01:53 -0600 | [diff] [blame] | 1533 | weston_view_set_position(shsurf->view, dx, dy); |
Rusty Lynch | 1084da5 | 2013-08-15 09:10:08 -0700 | [diff] [blame] | 1534 | |
| 1535 | weston_compositor_schedule_repaint(es->compositor); |
| 1536 | } |
| 1537 | |
Jonas Ådahl | 1ea343e | 2013-10-25 23:18:05 +0200 | [diff] [blame] | 1538 | static void |
Jonas Ådahl | 1679f23 | 2014-04-12 09:39:51 +0200 | [diff] [blame] | 1539 | touch_move_grab_frame(struct weston_touch_grab *grab) |
| 1540 | { |
| 1541 | } |
| 1542 | |
| 1543 | static void |
Jonas Ådahl | 1ea343e | 2013-10-25 23:18:05 +0200 | [diff] [blame] | 1544 | touch_move_grab_cancel(struct weston_touch_grab *grab) |
| 1545 | { |
| 1546 | struct weston_touch_move_grab *move = |
| 1547 | (struct weston_touch_move_grab *) container_of( |
| 1548 | grab, struct shell_touch_grab, grab); |
| 1549 | |
| 1550 | shell_touch_grab_end(&move->base); |
| 1551 | free(move); |
| 1552 | } |
| 1553 | |
Rusty Lynch | 1084da5 | 2013-08-15 09:10:08 -0700 | [diff] [blame] | 1554 | static const struct weston_touch_grab_interface touch_move_grab_interface = { |
| 1555 | touch_move_grab_down, |
| 1556 | touch_move_grab_up, |
| 1557 | touch_move_grab_motion, |
Jonas Ådahl | 1679f23 | 2014-04-12 09:39:51 +0200 | [diff] [blame] | 1558 | touch_move_grab_frame, |
Jonas Ådahl | 1ea343e | 2013-10-25 23:18:05 +0200 | [diff] [blame] | 1559 | touch_move_grab_cancel, |
Rusty Lynch | 1084da5 | 2013-08-15 09:10:08 -0700 | [diff] [blame] | 1560 | }; |
| 1561 | |
| 1562 | static int |
Derek Foreman | b7674ae | 2015-07-15 13:00:37 -0500 | [diff] [blame] | 1563 | surface_touch_move(struct shell_surface *shsurf, struct weston_touch *touch) |
Rusty Lynch | 1084da5 | 2013-08-15 09:10:08 -0700 | [diff] [blame] | 1564 | { |
| 1565 | struct weston_touch_move_grab *move; |
| 1566 | |
| 1567 | if (!shsurf) |
| 1568 | return -1; |
| 1569 | |
Ander Conselvan de Oliveira | 6d43f04 | 2014-05-07 14:22:23 +0300 | [diff] [blame] | 1570 | if (shsurf->state.fullscreen || shsurf->state.maximized) |
Rusty Lynch | 1084da5 | 2013-08-15 09:10:08 -0700 | [diff] [blame] | 1571 | return 0; |
| 1572 | |
| 1573 | move = malloc(sizeof *move); |
| 1574 | if (!move) |
| 1575 | return -1; |
| 1576 | |
Kristian Høgsberg | 8e80a31 | 2014-01-17 15:18:10 -0800 | [diff] [blame] | 1577 | move->active = 1; |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 1578 | move->dx = wl_fixed_from_double(shsurf->view->geometry.x) - |
Derek Foreman | b7674ae | 2015-07-15 13:00:37 -0500 | [diff] [blame] | 1579 | touch->grab_x; |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 1580 | move->dy = wl_fixed_from_double(shsurf->view->geometry.y) - |
Derek Foreman | b7674ae | 2015-07-15 13:00:37 -0500 | [diff] [blame] | 1581 | touch->grab_y; |
Rusty Lynch | 1084da5 | 2013-08-15 09:10:08 -0700 | [diff] [blame] | 1582 | |
| 1583 | shell_touch_grab_start(&move->base, &touch_move_grab_interface, shsurf, |
Derek Foreman | b7674ae | 2015-07-15 13:00:37 -0500 | [diff] [blame] | 1584 | touch); |
Rusty Lynch | 1084da5 | 2013-08-15 09:10:08 -0700 | [diff] [blame] | 1585 | |
| 1586 | return 0; |
| 1587 | } |
| 1588 | |
| 1589 | static void |
Kristian Høgsberg | 6848c25 | 2013-05-08 22:02:59 -0400 | [diff] [blame] | 1590 | noop_grab_focus(struct weston_pointer_grab *grab) |
Kristian Høgsberg | 9ddb826 | 2012-01-04 21:30:29 -0500 | [diff] [blame] | 1591 | { |
Kristian Høgsberg | 9ddb826 | 2012-01-04 21:30:29 -0500 | [diff] [blame] | 1592 | } |
| 1593 | |
| 1594 | static void |
Jonas Ådahl | 0336ca0 | 2014-10-04 16:28:29 +0200 | [diff] [blame] | 1595 | noop_grab_axis(struct weston_pointer_grab *grab, |
| 1596 | uint32_t time, uint32_t axis, wl_fixed_t value) |
| 1597 | { |
| 1598 | } |
| 1599 | |
| 1600 | static void |
Kristian Høgsberg | ae356ae | 2014-04-29 16:03:54 -0700 | [diff] [blame] | 1601 | constrain_position(struct weston_move_grab *move, int *cx, int *cy) |
| 1602 | { |
| 1603 | struct shell_surface *shsurf = move->base.shsurf; |
| 1604 | struct weston_pointer *pointer = move->base.grab.pointer; |
Derek Foreman | 6feb0f9 | 2015-04-15 12:23:56 -0500 | [diff] [blame] | 1605 | int x, y, bottom; |
Kristian Høgsberg | ae356ae | 2014-04-29 16:03:54 -0700 | [diff] [blame] | 1606 | const int safety = 50; |
Derek Foreman | 6feb0f9 | 2015-04-15 12:23:56 -0500 | [diff] [blame] | 1607 | pixman_rectangle32_t area; |
Kristian Høgsberg | ae356ae | 2014-04-29 16:03:54 -0700 | [diff] [blame] | 1608 | |
| 1609 | x = wl_fixed_to_int(pointer->x + move->dx); |
| 1610 | y = wl_fixed_to_int(pointer->y + move->dy); |
| 1611 | |
Jonas Ådahl | 6d6fb61 | 2015-11-17 16:00:33 +0800 | [diff] [blame] | 1612 | if (shsurf->shell->panel_position == |
| 1613 | WESTON_DESKTOP_SHELL_PANEL_POSITION_TOP) { |
Derek Foreman | 6feb0f9 | 2015-04-15 12:23:56 -0500 | [diff] [blame] | 1614 | get_output_work_area(shsurf->shell, |
| 1615 | shsurf->surface->output, |
| 1616 | &area); |
Kristian Høgsberg | ae356ae | 2014-04-29 16:03:54 -0700 | [diff] [blame] | 1617 | |
Derek Foreman | 6feb0f9 | 2015-04-15 12:23:56 -0500 | [diff] [blame] | 1618 | bottom = y + shsurf->geometry.height + shsurf->geometry.y; |
| 1619 | if (bottom - safety < area.y) |
| 1620 | y = area.y + safety - shsurf->geometry.height |
| 1621 | - shsurf->geometry.y; |
Jonny Lamb | d73c694 | 2014-08-20 15:53:20 +0200 | [diff] [blame] | 1622 | |
| 1623 | if (move->client_initiated && |
Derek Foreman | 6feb0f9 | 2015-04-15 12:23:56 -0500 | [diff] [blame] | 1624 | y + shsurf->geometry.y < area.y) |
| 1625 | y = area.y - shsurf->geometry.y; |
| 1626 | |
Jonny Lamb | d73c694 | 2014-08-20 15:53:20 +0200 | [diff] [blame] | 1627 | } |
Kristian Høgsberg | ae356ae | 2014-04-29 16:03:54 -0700 | [diff] [blame] | 1628 | |
| 1629 | *cx = x; |
| 1630 | *cy = y; |
| 1631 | } |
| 1632 | |
| 1633 | static void |
Giulio Camuffo | 1959ab8 | 2013-11-14 23:42:52 +0100 | [diff] [blame] | 1634 | move_grab_motion(struct weston_pointer_grab *grab, uint32_t time, |
Jonas Ådahl | d251010 | 2014-10-05 21:39:14 +0200 | [diff] [blame] | 1635 | struct weston_pointer_motion_event *event) |
Kristian Høgsberg | 4cca349 | 2011-01-18 07:53:49 -0500 | [diff] [blame] | 1636 | { |
Kristian Høgsberg | 8334bc1 | 2012-01-03 10:29:47 -0500 | [diff] [blame] | 1637 | struct weston_move_grab *move = (struct weston_move_grab *) grab; |
Kristian Høgsberg | 02bbabb | 2013-05-06 22:15:05 -0400 | [diff] [blame] | 1638 | struct weston_pointer *pointer = grab->pointer; |
Ander Conselvan de Oliveira | fe0444a | 2012-04-04 17:48:05 +0300 | [diff] [blame] | 1639 | struct shell_surface *shsurf = move->base.shsurf; |
Kristian Høgsberg | ae356ae | 2014-04-29 16:03:54 -0700 | [diff] [blame] | 1640 | int cx, cy; |
Giulio Camuffo | 1959ab8 | 2013-11-14 23:42:52 +0100 | [diff] [blame] | 1641 | |
Jonas Ådahl | d251010 | 2014-10-05 21:39:14 +0200 | [diff] [blame] | 1642 | weston_pointer_move(pointer, event); |
Ander Conselvan de Oliveira | fe0444a | 2012-04-04 17:48:05 +0300 | [diff] [blame] | 1643 | if (!shsurf) |
| 1644 | return; |
| 1645 | |
Kristian Høgsberg | ae356ae | 2014-04-29 16:03:54 -0700 | [diff] [blame] | 1646 | constrain_position(move, &cx, &cy); |
| 1647 | |
| 1648 | weston_view_set_position(shsurf->view, cx, cy); |
Kristian Høgsberg | 4cca349 | 2011-01-18 07:53:49 -0500 | [diff] [blame] | 1649 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 1650 | weston_compositor_schedule_repaint(shsurf->surface->compositor); |
Kristian Høgsberg | 4cca349 | 2011-01-18 07:53:49 -0500 | [diff] [blame] | 1651 | } |
| 1652 | |
| 1653 | static void |
Kristian Høgsberg | 02bbabb | 2013-05-06 22:15:05 -0400 | [diff] [blame] | 1654 | move_grab_button(struct weston_pointer_grab *grab, |
Daniel Stone | 4dbadb1 | 2012-05-30 16:31:51 +0100 | [diff] [blame] | 1655 | uint32_t time, uint32_t button, uint32_t state_w) |
Kristian Høgsberg | 4cca349 | 2011-01-18 07:53:49 -0500 | [diff] [blame] | 1656 | { |
Ander Conselvan de Oliveira | fe0444a | 2012-04-04 17:48:05 +0300 | [diff] [blame] | 1657 | struct shell_grab *shell_grab = container_of(grab, struct shell_grab, |
| 1658 | grab); |
Kristian Høgsberg | 02bbabb | 2013-05-06 22:15:05 -0400 | [diff] [blame] | 1659 | struct weston_pointer *pointer = grab->pointer; |
Daniel Stone | 4dbadb1 | 2012-05-30 16:31:51 +0100 | [diff] [blame] | 1660 | enum wl_pointer_button_state state = state_w; |
Kristian Høgsberg | 4cca349 | 2011-01-18 07:53:49 -0500 | [diff] [blame] | 1661 | |
Daniel Stone | 4dbadb1 | 2012-05-30 16:31:51 +0100 | [diff] [blame] | 1662 | if (pointer->button_count == 0 && |
| 1663 | state == WL_POINTER_BUTTON_STATE_RELEASED) { |
Ander Conselvan de Oliveira | b9d2a0f | 2012-06-28 18:08:05 +0300 | [diff] [blame] | 1664 | shell_grab_end(shell_grab); |
Kristian Høgsberg | 9ddb826 | 2012-01-04 21:30:29 -0500 | [diff] [blame] | 1665 | free(grab); |
| 1666 | } |
Kristian Høgsberg | 4cca349 | 2011-01-18 07:53:49 -0500 | [diff] [blame] | 1667 | } |
| 1668 | |
Jonas Ådahl | 1ea343e | 2013-10-25 23:18:05 +0200 | [diff] [blame] | 1669 | static void |
| 1670 | move_grab_cancel(struct weston_pointer_grab *grab) |
| 1671 | { |
| 1672 | struct shell_grab *shell_grab = |
| 1673 | container_of(grab, struct shell_grab, grab); |
| 1674 | |
| 1675 | shell_grab_end(shell_grab); |
| 1676 | free(grab); |
| 1677 | } |
| 1678 | |
Kristian Høgsberg | 02bbabb | 2013-05-06 22:15:05 -0400 | [diff] [blame] | 1679 | static const struct weston_pointer_grab_interface move_grab_interface = { |
Kristian Høgsberg | 9ddb826 | 2012-01-04 21:30:29 -0500 | [diff] [blame] | 1680 | noop_grab_focus, |
Kristian Høgsberg | 4cca349 | 2011-01-18 07:53:49 -0500 | [diff] [blame] | 1681 | move_grab_motion, |
| 1682 | move_grab_button, |
Jonas Ådahl | 0336ca0 | 2014-10-04 16:28:29 +0200 | [diff] [blame] | 1683 | noop_grab_axis, |
Jonas Ådahl | 1ea343e | 2013-10-25 23:18:05 +0200 | [diff] [blame] | 1684 | move_grab_cancel, |
Kristian Høgsberg | 4cca349 | 2011-01-18 07:53:49 -0500 | [diff] [blame] | 1685 | }; |
| 1686 | |
Kristian Høgsberg | 9e31bff | 2012-08-01 00:08:07 -0400 | [diff] [blame] | 1687 | static int |
Derek Foreman | 794fa0e | 2015-07-15 13:00:38 -0500 | [diff] [blame] | 1688 | surface_move(struct shell_surface *shsurf, struct weston_pointer *pointer, |
Derek Foreman | cf7d95a | 2015-06-03 15:53:22 -0500 | [diff] [blame] | 1689 | bool client_initiated) |
Kristian Høgsberg | 9e31bff | 2012-08-01 00:08:07 -0400 | [diff] [blame] | 1690 | { |
| 1691 | struct weston_move_grab *move; |
| 1692 | |
| 1693 | if (!shsurf) |
| 1694 | return -1; |
| 1695 | |
Derek Foreman | 45a7c27 | 2015-09-11 14:27:40 -0500 | [diff] [blame] | 1696 | shsurf = find_toplevel_surface(shsurf); |
| 1697 | |
Kristian Høgsberg | a4b620e | 2014-04-30 16:05:49 -0700 | [diff] [blame] | 1698 | if (shsurf->grabbed || |
| 1699 | shsurf->state.fullscreen || shsurf->state.maximized) |
Kristian Høgsberg | 9e31bff | 2012-08-01 00:08:07 -0400 | [diff] [blame] | 1700 | return 0; |
| 1701 | |
| 1702 | move = malloc(sizeof *move); |
| 1703 | if (!move) |
| 1704 | return -1; |
| 1705 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 1706 | move->dx = wl_fixed_from_double(shsurf->view->geometry.x) - |
Derek Foreman | 794fa0e | 2015-07-15 13:00:38 -0500 | [diff] [blame] | 1707 | pointer->grab_x; |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 1708 | move->dy = wl_fixed_from_double(shsurf->view->geometry.y) - |
Derek Foreman | 794fa0e | 2015-07-15 13:00:38 -0500 | [diff] [blame] | 1709 | pointer->grab_y; |
Kristian Høgsberg | ae356ae | 2014-04-29 16:03:54 -0700 | [diff] [blame] | 1710 | move->client_initiated = client_initiated; |
Kristian Høgsberg | 9e31bff | 2012-08-01 00:08:07 -0400 | [diff] [blame] | 1711 | |
| 1712 | shell_grab_start(&move->base, &move_grab_interface, shsurf, |
Jonas Ådahl | 6d6fb61 | 2015-11-17 16:00:33 +0800 | [diff] [blame] | 1713 | pointer, WESTON_DESKTOP_SHELL_CURSOR_MOVE); |
Kristian Høgsberg | 9e31bff | 2012-08-01 00:08:07 -0400 | [diff] [blame] | 1714 | |
| 1715 | return 0; |
| 1716 | } |
| 1717 | |
| 1718 | static void |
Rafael Antognolli | e2a3455 | 2013-12-03 15:35:45 -0200 | [diff] [blame] | 1719 | common_surface_move(struct wl_resource *resource, |
| 1720 | struct wl_resource *seat_resource, uint32_t serial) |
Kristian Høgsberg | 9e31bff | 2012-08-01 00:08:07 -0400 | [diff] [blame] | 1721 | { |
Jason Ekstrand | 44a3863 | 2013-06-14 10:08:00 -0500 | [diff] [blame] | 1722 | struct weston_seat *seat = wl_resource_get_user_data(seat_resource); |
Derek Foreman | 1281a36 | 2015-07-31 16:55:32 -0500 | [diff] [blame] | 1723 | struct weston_pointer *pointer = weston_seat_get_pointer(seat); |
| 1724 | struct weston_touch *touch = weston_seat_get_touch(seat); |
Jason Ekstrand | 651f00e | 2013-06-14 10:07:54 -0500 | [diff] [blame] | 1725 | struct shell_surface *shsurf = wl_resource_get_user_data(resource); |
Giulio Camuffo | 61da3fc | 2013-04-25 13:57:45 +0300 | [diff] [blame] | 1726 | struct weston_surface *surface; |
Kristian Høgsberg | 9e31bff | 2012-08-01 00:08:07 -0400 | [diff] [blame] | 1727 | |
Derek Foreman | 1281a36 | 2015-07-31 16:55:32 -0500 | [diff] [blame] | 1728 | if (pointer && |
| 1729 | pointer->focus && |
| 1730 | pointer->button_count > 0 && |
| 1731 | pointer->grab_serial == serial) { |
| 1732 | surface = weston_surface_get_main_surface(pointer->focus->surface); |
U. Artie Eoff | cf5737a | 2014-01-17 10:08:25 -0800 | [diff] [blame] | 1733 | if ((surface == shsurf->surface) && |
Derek Foreman | 1281a36 | 2015-07-31 16:55:32 -0500 | [diff] [blame] | 1734 | (surface_move(shsurf, pointer, true) < 0)) |
Rusty Lynch | 1084da5 | 2013-08-15 09:10:08 -0700 | [diff] [blame] | 1735 | wl_resource_post_no_memory(resource); |
Derek Foreman | 1281a36 | 2015-07-31 16:55:32 -0500 | [diff] [blame] | 1736 | } else if (touch && |
| 1737 | touch->focus && |
| 1738 | touch->grab_serial == serial) { |
| 1739 | surface = weston_surface_get_main_surface(touch->focus->surface); |
U. Artie Eoff | cf5737a | 2014-01-17 10:08:25 -0800 | [diff] [blame] | 1740 | if ((surface == shsurf->surface) && |
Derek Foreman | 1281a36 | 2015-07-31 16:55:32 -0500 | [diff] [blame] | 1741 | (surface_touch_move(shsurf, touch) < 0)) |
Rusty Lynch | 1084da5 | 2013-08-15 09:10:08 -0700 | [diff] [blame] | 1742 | wl_resource_post_no_memory(resource); |
| 1743 | } |
Kristian Høgsberg | 9e31bff | 2012-08-01 00:08:07 -0400 | [diff] [blame] | 1744 | } |
| 1745 | |
Rafael Antognolli | e2a3455 | 2013-12-03 15:35:45 -0200 | [diff] [blame] | 1746 | static void |
| 1747 | shell_surface_move(struct wl_client *client, struct wl_resource *resource, |
| 1748 | struct wl_resource *seat_resource, uint32_t serial) |
| 1749 | { |
| 1750 | common_surface_move(resource, seat_resource, serial); |
| 1751 | } |
| 1752 | |
Kristian Høgsberg | 9e31bff | 2012-08-01 00:08:07 -0400 | [diff] [blame] | 1753 | struct weston_resize_grab { |
| 1754 | struct shell_grab base; |
| 1755 | uint32_t edges; |
| 1756 | int32_t width, height; |
| 1757 | }; |
| 1758 | |
| 1759 | static void |
Giulio Camuffo | 1959ab8 | 2013-11-14 23:42:52 +0100 | [diff] [blame] | 1760 | resize_grab_motion(struct weston_pointer_grab *grab, uint32_t time, |
Jonas Ådahl | d251010 | 2014-10-05 21:39:14 +0200 | [diff] [blame] | 1761 | struct weston_pointer_motion_event *event) |
Kristian Høgsberg | 9e31bff | 2012-08-01 00:08:07 -0400 | [diff] [blame] | 1762 | { |
| 1763 | struct weston_resize_grab *resize = (struct weston_resize_grab *) grab; |
Kristian Høgsberg | 02bbabb | 2013-05-06 22:15:05 -0400 | [diff] [blame] | 1764 | struct weston_pointer *pointer = grab->pointer; |
Kristian Høgsberg | 9e31bff | 2012-08-01 00:08:07 -0400 | [diff] [blame] | 1765 | struct shell_surface *shsurf = resize->base.shsurf; |
| 1766 | int32_t width, height; |
| 1767 | wl_fixed_t from_x, from_y; |
| 1768 | wl_fixed_t to_x, to_y; |
| 1769 | |
Jonas Ådahl | d251010 | 2014-10-05 21:39:14 +0200 | [diff] [blame] | 1770 | weston_pointer_move(pointer, event); |
Giulio Camuffo | 1959ab8 | 2013-11-14 23:42:52 +0100 | [diff] [blame] | 1771 | |
Kristian Høgsberg | e0b9d5b | 2014-04-30 13:45:49 -0700 | [diff] [blame] | 1772 | if (!shsurf) |
Kristian Høgsberg | 9e31bff | 2012-08-01 00:08:07 -0400 | [diff] [blame] | 1773 | return; |
| 1774 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 1775 | weston_view_from_global_fixed(shsurf->view, |
| 1776 | pointer->grab_x, pointer->grab_y, |
| 1777 | &from_x, &from_y); |
| 1778 | weston_view_from_global_fixed(shsurf->view, |
| 1779 | pointer->x, pointer->y, &to_x, &to_y); |
Kristian Høgsberg | 9e31bff | 2012-08-01 00:08:07 -0400 | [diff] [blame] | 1780 | |
| 1781 | width = resize->width; |
| 1782 | if (resize->edges & WL_SHELL_SURFACE_RESIZE_LEFT) { |
| 1783 | width += wl_fixed_to_int(from_x - to_x); |
| 1784 | } else if (resize->edges & WL_SHELL_SURFACE_RESIZE_RIGHT) { |
| 1785 | width += wl_fixed_to_int(to_x - from_x); |
| 1786 | } |
| 1787 | |
| 1788 | height = resize->height; |
| 1789 | if (resize->edges & WL_SHELL_SURFACE_RESIZE_TOP) { |
| 1790 | height += wl_fixed_to_int(from_y - to_y); |
| 1791 | } else if (resize->edges & WL_SHELL_SURFACE_RESIZE_BOTTOM) { |
| 1792 | height += wl_fixed_to_int(to_y - from_y); |
| 1793 | } |
| 1794 | |
Derek Foreman | 70ac0ed | 2015-03-18 11:16:33 -0500 | [diff] [blame] | 1795 | if (width < 1) |
| 1796 | width = 1; |
| 1797 | if (height < 1) |
| 1798 | height = 1; |
Jasper St. Pierre | ac985be | 2014-04-28 11:19:28 -0400 | [diff] [blame] | 1799 | shsurf->client->send_configure(shsurf->surface, width, height); |
Kristian Høgsberg | 9e31bff | 2012-08-01 00:08:07 -0400 | [diff] [blame] | 1800 | } |
| 1801 | |
| 1802 | static void |
Jasper St. Pierre | ac985be | 2014-04-28 11:19:28 -0400 | [diff] [blame] | 1803 | 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] | 1804 | { |
| 1805 | struct shell_surface *shsurf = get_shell_surface(surface); |
| 1806 | |
U. Artie Eoff | cf5737a | 2014-01-17 10:08:25 -0800 | [diff] [blame] | 1807 | assert(shsurf); |
| 1808 | |
Kristian Høgsberg | e0b9d5b | 2014-04-30 13:45:49 -0700 | [diff] [blame] | 1809 | if (shsurf->resource) |
| 1810 | wl_shell_surface_send_configure(shsurf->resource, |
Jasper St. Pierre | ac985be | 2014-04-28 11:19:28 -0400 | [diff] [blame] | 1811 | shsurf->resize_edges, |
| 1812 | width, height); |
Kristian Høgsberg | 9e31bff | 2012-08-01 00:08:07 -0400 | [diff] [blame] | 1813 | } |
| 1814 | |
| 1815 | static const struct weston_shell_client shell_client = { |
Giulio Camuffo | f05d18f | 2015-12-11 20:57:05 +0200 | [diff] [blame^] | 1816 | send_configure, |
| 1817 | NULL |
Kristian Høgsberg | 9e31bff | 2012-08-01 00:08:07 -0400 | [diff] [blame] | 1818 | }; |
| 1819 | |
| 1820 | static void |
Kristian Høgsberg | 02bbabb | 2013-05-06 22:15:05 -0400 | [diff] [blame] | 1821 | resize_grab_button(struct weston_pointer_grab *grab, |
Kristian Høgsberg | 9e31bff | 2012-08-01 00:08:07 -0400 | [diff] [blame] | 1822 | uint32_t time, uint32_t button, uint32_t state_w) |
| 1823 | { |
| 1824 | struct weston_resize_grab *resize = (struct weston_resize_grab *) grab; |
Kristian Høgsberg | 02bbabb | 2013-05-06 22:15:05 -0400 | [diff] [blame] | 1825 | struct weston_pointer *pointer = grab->pointer; |
Kristian Høgsberg | 9e31bff | 2012-08-01 00:08:07 -0400 | [diff] [blame] | 1826 | enum wl_pointer_button_state state = state_w; |
| 1827 | |
| 1828 | if (pointer->button_count == 0 && |
| 1829 | state == WL_POINTER_BUTTON_STATE_RELEASED) { |
| 1830 | shell_grab_end(&resize->base); |
| 1831 | free(grab); |
| 1832 | } |
| 1833 | } |
| 1834 | |
Jonas Ådahl | 1ea343e | 2013-10-25 23:18:05 +0200 | [diff] [blame] | 1835 | static void |
| 1836 | resize_grab_cancel(struct weston_pointer_grab *grab) |
| 1837 | { |
| 1838 | struct weston_resize_grab *resize = (struct weston_resize_grab *) grab; |
| 1839 | |
| 1840 | shell_grab_end(&resize->base); |
| 1841 | free(grab); |
| 1842 | } |
| 1843 | |
Kristian Høgsberg | 02bbabb | 2013-05-06 22:15:05 -0400 | [diff] [blame] | 1844 | static const struct weston_pointer_grab_interface resize_grab_interface = { |
Kristian Høgsberg | 9e31bff | 2012-08-01 00:08:07 -0400 | [diff] [blame] | 1845 | noop_grab_focus, |
| 1846 | resize_grab_motion, |
| 1847 | resize_grab_button, |
Jonas Ådahl | 0336ca0 | 2014-10-04 16:28:29 +0200 | [diff] [blame] | 1848 | noop_grab_axis, |
Jonas Ådahl | 1ea343e | 2013-10-25 23:18:05 +0200 | [diff] [blame] | 1849 | resize_grab_cancel, |
Kristian Høgsberg | 9e31bff | 2012-08-01 00:08:07 -0400 | [diff] [blame] | 1850 | }; |
| 1851 | |
Giulio Camuffo | b836664 | 2013-04-25 13:57:46 +0300 | [diff] [blame] | 1852 | /* |
| 1853 | * Returns the bounding box of a surface and all its sub-surfaces, |
| 1854 | * in the surface coordinates system. */ |
| 1855 | static void |
| 1856 | surface_subsurfaces_boundingbox(struct weston_surface *surface, int32_t *x, |
| 1857 | int32_t *y, int32_t *w, int32_t *h) { |
| 1858 | pixman_region32_t region; |
| 1859 | pixman_box32_t *box; |
| 1860 | struct weston_subsurface *subsurface; |
| 1861 | |
| 1862 | pixman_region32_init_rect(®ion, 0, 0, |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 1863 | surface->width, |
| 1864 | surface->height); |
Giulio Camuffo | b836664 | 2013-04-25 13:57:46 +0300 | [diff] [blame] | 1865 | |
| 1866 | wl_list_for_each(subsurface, &surface->subsurface_list, parent_link) { |
| 1867 | pixman_region32_union_rect(®ion, ®ion, |
| 1868 | subsurface->position.x, |
| 1869 | subsurface->position.y, |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 1870 | subsurface->surface->width, |
| 1871 | subsurface->surface->height); |
Giulio Camuffo | b836664 | 2013-04-25 13:57:46 +0300 | [diff] [blame] | 1872 | } |
| 1873 | |
| 1874 | box = pixman_region32_extents(®ion); |
| 1875 | if (x) |
| 1876 | *x = box->x1; |
| 1877 | if (y) |
| 1878 | *y = box->y1; |
| 1879 | if (w) |
| 1880 | *w = box->x2 - box->x1; |
| 1881 | if (h) |
| 1882 | *h = box->y2 - box->y1; |
| 1883 | |
| 1884 | pixman_region32_fini(®ion); |
| 1885 | } |
| 1886 | |
Kristian Høgsberg | 9e31bff | 2012-08-01 00:08:07 -0400 | [diff] [blame] | 1887 | static int |
| 1888 | surface_resize(struct shell_surface *shsurf, |
Derek Foreman | 8fbebbd | 2015-07-15 13:00:40 -0500 | [diff] [blame] | 1889 | struct weston_pointer *pointer, uint32_t edges) |
Kristian Høgsberg | 9e31bff | 2012-08-01 00:08:07 -0400 | [diff] [blame] | 1890 | { |
| 1891 | struct weston_resize_grab *resize; |
Ondřej Majerech | ae9c4fc | 2014-08-21 15:47:22 +0200 | [diff] [blame] | 1892 | const unsigned resize_topbottom = |
| 1893 | WL_SHELL_SURFACE_RESIZE_TOP | WL_SHELL_SURFACE_RESIZE_BOTTOM; |
| 1894 | const unsigned resize_leftright = |
| 1895 | WL_SHELL_SURFACE_RESIZE_LEFT | WL_SHELL_SURFACE_RESIZE_RIGHT; |
| 1896 | const unsigned resize_any = resize_topbottom | resize_leftright; |
Kristian Høgsberg | 9e31bff | 2012-08-01 00:08:07 -0400 | [diff] [blame] | 1897 | |
Kristian Høgsberg | a4b620e | 2014-04-30 16:05:49 -0700 | [diff] [blame] | 1898 | if (shsurf->grabbed || |
| 1899 | shsurf->state.fullscreen || shsurf->state.maximized) |
Kristian Høgsberg | 9e31bff | 2012-08-01 00:08:07 -0400 | [diff] [blame] | 1900 | return 0; |
| 1901 | |
Ondřej Majerech | ae9c4fc | 2014-08-21 15:47:22 +0200 | [diff] [blame] | 1902 | /* Check for invalid edge combinations. */ |
| 1903 | if (edges == WL_SHELL_SURFACE_RESIZE_NONE || edges > resize_any || |
| 1904 | (edges & resize_topbottom) == resize_topbottom || |
| 1905 | (edges & resize_leftright) == resize_leftright) |
Kristian Høgsberg | 9e31bff | 2012-08-01 00:08:07 -0400 | [diff] [blame] | 1906 | return 0; |
| 1907 | |
| 1908 | resize = malloc(sizeof *resize); |
| 1909 | if (!resize) |
| 1910 | return -1; |
| 1911 | |
| 1912 | resize->edges = edges; |
Kristian Høgsberg | 9e31bff | 2012-08-01 00:08:07 -0400 | [diff] [blame] | 1913 | |
Jasper St. Pierre | ccf48fb | 2014-05-02 10:21:38 -0400 | [diff] [blame] | 1914 | resize->width = shsurf->geometry.width; |
| 1915 | resize->height = shsurf->geometry.height; |
Jasper St. Pierre | bd65e50 | 2014-07-14 16:28:48 -0400 | [diff] [blame] | 1916 | |
Kristian Høgsberg | 44cd196 | 2014-02-05 21:36:04 -0800 | [diff] [blame] | 1917 | shsurf->resize_edges = edges; |
Jasper St. Pierre | 5befdda | 2014-05-06 08:50:47 -0400 | [diff] [blame] | 1918 | shell_surface_state_changed(shsurf); |
Kristian Høgsberg | 9e31bff | 2012-08-01 00:08:07 -0400 | [diff] [blame] | 1919 | shell_grab_start(&resize->base, &resize_grab_interface, shsurf, |
Derek Foreman | 8fbebbd | 2015-07-15 13:00:40 -0500 | [diff] [blame] | 1920 | pointer, edges); |
Kristian Høgsberg | 9e31bff | 2012-08-01 00:08:07 -0400 | [diff] [blame] | 1921 | |
| 1922 | return 0; |
| 1923 | } |
| 1924 | |
| 1925 | static void |
Rafael Antognolli | e2a3455 | 2013-12-03 15:35:45 -0200 | [diff] [blame] | 1926 | common_surface_resize(struct wl_resource *resource, |
| 1927 | struct wl_resource *seat_resource, uint32_t serial, |
| 1928 | uint32_t edges) |
Kristian Høgsberg | 9e31bff | 2012-08-01 00:08:07 -0400 | [diff] [blame] | 1929 | { |
Jason Ekstrand | 44a3863 | 2013-06-14 10:08:00 -0500 | [diff] [blame] | 1930 | struct weston_seat *seat = wl_resource_get_user_data(seat_resource); |
Derek Foreman | 1281a36 | 2015-07-31 16:55:32 -0500 | [diff] [blame] | 1931 | struct weston_pointer *pointer = weston_seat_get_pointer(seat); |
Jason Ekstrand | 651f00e | 2013-06-14 10:07:54 -0500 | [diff] [blame] | 1932 | struct shell_surface *shsurf = wl_resource_get_user_data(resource); |
Giulio Camuffo | 61da3fc | 2013-04-25 13:57:45 +0300 | [diff] [blame] | 1933 | struct weston_surface *surface; |
Kristian Høgsberg | 9e31bff | 2012-08-01 00:08:07 -0400 | [diff] [blame] | 1934 | |
Derek Foreman | 1281a36 | 2015-07-31 16:55:32 -0500 | [diff] [blame] | 1935 | if (!pointer || |
| 1936 | pointer->button_count == 0 || |
| 1937 | pointer->grab_serial != serial || |
| 1938 | pointer->focus == NULL) |
Kristian Høgsberg | 70f2901 | 2014-01-09 15:43:17 -0800 | [diff] [blame] | 1939 | return; |
| 1940 | |
Derek Foreman | 1281a36 | 2015-07-31 16:55:32 -0500 | [diff] [blame] | 1941 | surface = weston_surface_get_main_surface(pointer->focus->surface); |
Kristian Høgsberg | 70f2901 | 2014-01-09 15:43:17 -0800 | [diff] [blame] | 1942 | if (surface != shsurf->surface) |
Kristian Høgsberg | 9e31bff | 2012-08-01 00:08:07 -0400 | [diff] [blame] | 1943 | return; |
| 1944 | |
Derek Foreman | 1281a36 | 2015-07-31 16:55:32 -0500 | [diff] [blame] | 1945 | if (surface_resize(shsurf, pointer, edges) < 0) |
Kristian Høgsberg | 9e31bff | 2012-08-01 00:08:07 -0400 | [diff] [blame] | 1946 | wl_resource_post_no_memory(resource); |
| 1947 | } |
| 1948 | |
Scott Moreau | c3e54eb | 2012-04-17 19:06:20 -0600 | [diff] [blame] | 1949 | static void |
Rafael Antognolli | e2a3455 | 2013-12-03 15:35:45 -0200 | [diff] [blame] | 1950 | shell_surface_resize(struct wl_client *client, struct wl_resource *resource, |
| 1951 | struct wl_resource *seat_resource, uint32_t serial, |
| 1952 | uint32_t edges) |
| 1953 | { |
| 1954 | common_surface_resize(resource, seat_resource, serial, edges); |
| 1955 | } |
| 1956 | |
| 1957 | static void |
Kristian Høgsberg | 6848c25 | 2013-05-08 22:02:59 -0400 | [diff] [blame] | 1958 | busy_cursor_grab_focus(struct weston_pointer_grab *base) |
Scott Moreau | c3e54eb | 2012-04-17 19:06:20 -0600 | [diff] [blame] | 1959 | { |
Kristian Høgsberg | d56bd90 | 2012-06-05 09:58:51 -0400 | [diff] [blame] | 1960 | struct shell_grab *grab = (struct shell_grab *) base; |
Kristian Høgsberg | 6848c25 | 2013-05-08 22:02:59 -0400 | [diff] [blame] | 1961 | struct weston_pointer *pointer = base->pointer; |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 1962 | struct weston_view *view; |
Kristian Høgsberg | 6848c25 | 2013-05-08 22:02:59 -0400 | [diff] [blame] | 1963 | wl_fixed_t sx, sy; |
| 1964 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 1965 | view = weston_compositor_pick_view(pointer->seat->compositor, |
| 1966 | pointer->x, pointer->y, |
| 1967 | &sx, &sy); |
Scott Moreau | c3e54eb | 2012-04-17 19:06:20 -0600 | [diff] [blame] | 1968 | |
Kristian Høgsberg | 2bff94e | 2014-02-11 12:22:51 -0800 | [diff] [blame] | 1969 | if (!grab->shsurf || grab->shsurf->surface != view->surface) { |
| 1970 | shell_grab_end(grab); |
| 1971 | free(grab); |
| 1972 | } |
Scott Moreau | c3e54eb | 2012-04-17 19:06:20 -0600 | [diff] [blame] | 1973 | } |
| 1974 | |
| 1975 | static void |
Giulio Camuffo | 1959ab8 | 2013-11-14 23:42:52 +0100 | [diff] [blame] | 1976 | busy_cursor_grab_motion(struct weston_pointer_grab *grab, uint32_t time, |
Jonas Ådahl | d251010 | 2014-10-05 21:39:14 +0200 | [diff] [blame] | 1977 | struct weston_pointer_motion_event *event) |
Scott Moreau | c3e54eb | 2012-04-17 19:06:20 -0600 | [diff] [blame] | 1978 | { |
Jonas Ådahl | d251010 | 2014-10-05 21:39:14 +0200 | [diff] [blame] | 1979 | weston_pointer_move(grab->pointer, event); |
Kristian Høgsberg | d56bd90 | 2012-06-05 09:58:51 -0400 | [diff] [blame] | 1980 | } |
Scott Moreau | c3e54eb | 2012-04-17 19:06:20 -0600 | [diff] [blame] | 1981 | |
Kristian Høgsberg | d56bd90 | 2012-06-05 09:58:51 -0400 | [diff] [blame] | 1982 | static void |
Kristian Høgsberg | 02bbabb | 2013-05-06 22:15:05 -0400 | [diff] [blame] | 1983 | busy_cursor_grab_button(struct weston_pointer_grab *base, |
Kristian Høgsberg | d56bd90 | 2012-06-05 09:58:51 -0400 | [diff] [blame] | 1984 | uint32_t time, uint32_t button, uint32_t state) |
| 1985 | { |
Kristian Høgsberg | bbe9839 | 2012-08-01 00:20:21 -0400 | [diff] [blame] | 1986 | struct shell_grab *grab = (struct shell_grab *) base; |
Kristian Høgsberg | e122b7b | 2013-05-08 16:47:00 -0400 | [diff] [blame] | 1987 | struct shell_surface *shsurf = grab->shsurf; |
Derek Foreman | 794fa0e | 2015-07-15 13:00:38 -0500 | [diff] [blame] | 1988 | struct weston_pointer *pointer = grab->grab.pointer; |
| 1989 | struct weston_seat *seat = pointer->seat; |
Kristian Høgsberg | bbe9839 | 2012-08-01 00:20:21 -0400 | [diff] [blame] | 1990 | |
Kristian Høgsberg | bbe9839 | 2012-08-01 00:20:21 -0400 | [diff] [blame] | 1991 | if (shsurf && button == BTN_LEFT && state) { |
Emilio Pozuelo Monfort | 9e7c759 | 2014-01-30 14:01:10 +0100 | [diff] [blame] | 1992 | activate(shsurf->shell, shsurf->surface, seat, true); |
Derek Foreman | 794fa0e | 2015-07-15 13:00:38 -0500 | [diff] [blame] | 1993 | surface_move(shsurf, pointer, false); |
Kristian Høgsberg | 0c36903 | 2013-02-14 21:31:44 -0500 | [diff] [blame] | 1994 | } else if (shsurf && button == BTN_RIGHT && state) { |
Emilio Pozuelo Monfort | 9e7c759 | 2014-01-30 14:01:10 +0100 | [diff] [blame] | 1995 | activate(shsurf->shell, shsurf->surface, seat, true); |
Derek Foreman | 74de469 | 2015-07-15 13:00:39 -0500 | [diff] [blame] | 1996 | surface_rotate(shsurf, pointer); |
Kristian Høgsberg | bbe9839 | 2012-08-01 00:20:21 -0400 | [diff] [blame] | 1997 | } |
Kristian Høgsberg | d56bd90 | 2012-06-05 09:58:51 -0400 | [diff] [blame] | 1998 | } |
| 1999 | |
Jonas Ådahl | 1ea343e | 2013-10-25 23:18:05 +0200 | [diff] [blame] | 2000 | static void |
| 2001 | busy_cursor_grab_cancel(struct weston_pointer_grab *base) |
| 2002 | { |
| 2003 | struct shell_grab *grab = (struct shell_grab *) base; |
| 2004 | |
| 2005 | shell_grab_end(grab); |
| 2006 | free(grab); |
| 2007 | } |
| 2008 | |
Kristian Høgsberg | 02bbabb | 2013-05-06 22:15:05 -0400 | [diff] [blame] | 2009 | static const struct weston_pointer_grab_interface busy_cursor_grab_interface = { |
Kristian Høgsberg | d56bd90 | 2012-06-05 09:58:51 -0400 | [diff] [blame] | 2010 | busy_cursor_grab_focus, |
| 2011 | busy_cursor_grab_motion, |
| 2012 | busy_cursor_grab_button, |
Jonas Ådahl | 0336ca0 | 2014-10-04 16:28:29 +0200 | [diff] [blame] | 2013 | noop_grab_axis, |
Jonas Ådahl | 1ea343e | 2013-10-25 23:18:05 +0200 | [diff] [blame] | 2014 | busy_cursor_grab_cancel, |
Kristian Høgsberg | d56bd90 | 2012-06-05 09:58:51 -0400 | [diff] [blame] | 2015 | }; |
| 2016 | |
| 2017 | static void |
Kristian Høgsberg | 02bbabb | 2013-05-06 22:15:05 -0400 | [diff] [blame] | 2018 | set_busy_cursor(struct shell_surface *shsurf, struct weston_pointer *pointer) |
Kristian Høgsberg | d56bd90 | 2012-06-05 09:58:51 -0400 | [diff] [blame] | 2019 | { |
| 2020 | struct shell_grab *grab; |
Kristian Høgsberg | d56bd90 | 2012-06-05 09:58:51 -0400 | [diff] [blame] | 2021 | |
Kristian Høgsberg | 2bff94e | 2014-02-11 12:22:51 -0800 | [diff] [blame] | 2022 | if (pointer->grab->interface == &busy_cursor_grab_interface) |
| 2023 | return; |
| 2024 | |
Kristian Høgsberg | d56bd90 | 2012-06-05 09:58:51 -0400 | [diff] [blame] | 2025 | grab = malloc(sizeof *grab); |
| 2026 | if (!grab) |
Scott Moreau | c3e54eb | 2012-04-17 19:06:20 -0600 | [diff] [blame] | 2027 | return; |
| 2028 | |
Ander Conselvan de Oliveira | b9d2a0f | 2012-06-28 18:08:05 +0300 | [diff] [blame] | 2029 | shell_grab_start(grab, &busy_cursor_grab_interface, shsurf, pointer, |
Jonas Ådahl | 6d6fb61 | 2015-11-17 16:00:33 +0800 | [diff] [blame] | 2030 | WESTON_DESKTOP_SHELL_CURSOR_BUSY); |
Ander Conselvan de Oliveira | e5a1aee | 2014-04-09 17:39:39 +0300 | [diff] [blame] | 2031 | /* Mark the shsurf as ungrabbed so that button binding is able |
| 2032 | * to move it. */ |
| 2033 | shsurf->grabbed = 0; |
Kristian Høgsberg | d56bd90 | 2012-06-05 09:58:51 -0400 | [diff] [blame] | 2034 | } |
Scott Moreau | c3e54eb | 2012-04-17 19:06:20 -0600 | [diff] [blame] | 2035 | |
Kristian Høgsberg | d56bd90 | 2012-06-05 09:58:51 -0400 | [diff] [blame] | 2036 | static void |
Kristian Høgsberg | 2bff94e | 2014-02-11 12:22:51 -0800 | [diff] [blame] | 2037 | end_busy_cursor(struct weston_compositor *compositor, struct wl_client *client) |
Kristian Høgsberg | d56bd90 | 2012-06-05 09:58:51 -0400 | [diff] [blame] | 2038 | { |
Kristian Høgsberg | 2bff94e | 2014-02-11 12:22:51 -0800 | [diff] [blame] | 2039 | struct shell_grab *grab; |
| 2040 | struct weston_seat *seat; |
Kristian Høgsberg | d56bd90 | 2012-06-05 09:58:51 -0400 | [diff] [blame] | 2041 | |
Kristian Høgsberg | 2bff94e | 2014-02-11 12:22:51 -0800 | [diff] [blame] | 2042 | wl_list_for_each(seat, &compositor->seat_list, link) { |
Derek Foreman | 1281a36 | 2015-07-31 16:55:32 -0500 | [diff] [blame] | 2043 | struct weston_pointer *pointer = weston_seat_get_pointer(seat); |
| 2044 | |
| 2045 | if (!pointer) |
Kristian Høgsberg | 2bff94e | 2014-02-11 12:22:51 -0800 | [diff] [blame] | 2046 | continue; |
| 2047 | |
Derek Foreman | 1281a36 | 2015-07-31 16:55:32 -0500 | [diff] [blame] | 2048 | grab = (struct shell_grab *) pointer->grab; |
Kristian Høgsberg | 2bff94e | 2014-02-11 12:22:51 -0800 | [diff] [blame] | 2049 | if (grab->grab.interface == &busy_cursor_grab_interface && |
Derek Foreman | c0c1497 | 2015-09-11 14:30:39 -0500 | [diff] [blame] | 2050 | grab->shsurf->resource && |
Kristian Høgsberg | 2bff94e | 2014-02-11 12:22:51 -0800 | [diff] [blame] | 2051 | wl_resource_get_client(grab->shsurf->resource) == client) { |
| 2052 | shell_grab_end(grab); |
| 2053 | free(grab); |
| 2054 | } |
Scott Moreau | c3e54eb | 2012-04-17 19:06:20 -0600 | [diff] [blame] | 2055 | } |
Scott Moreau | c3e54eb | 2012-04-17 19:06:20 -0600 | [diff] [blame] | 2056 | } |
| 2057 | |
Scott Moreau | 9521d5e | 2012-04-19 13:06:17 -0600 | [diff] [blame] | 2058 | static void |
Kristian Høgsberg | 2bff94e | 2014-02-11 12:22:51 -0800 | [diff] [blame] | 2059 | handle_shell_client_destroy(struct wl_listener *listener, void *data); |
| 2060 | |
| 2061 | static int |
| 2062 | xdg_ping_timeout_handler(void *data) |
| 2063 | { |
| 2064 | struct shell_client *sc = data; |
| 2065 | struct weston_seat *seat; |
| 2066 | struct shell_surface *shsurf; |
| 2067 | |
| 2068 | /* Client is not responding */ |
| 2069 | sc->unresponsive = 1; |
Kristian Høgsberg | 2bff94e | 2014-02-11 12:22:51 -0800 | [diff] [blame] | 2070 | wl_list_for_each(seat, &sc->shell->compositor->seat_list, link) { |
Derek Foreman | 1281a36 | 2015-07-31 16:55:32 -0500 | [diff] [blame] | 2071 | struct weston_pointer *pointer = weston_seat_get_pointer(seat); |
| 2072 | |
| 2073 | if (!pointer || |
| 2074 | !pointer->focus || |
| 2075 | !pointer->focus->surface->resource) |
Kristian Høgsberg | 2bff94e | 2014-02-11 12:22:51 -0800 | [diff] [blame] | 2076 | continue; |
Michael Vetter | 2a18a52 | 2015-05-15 17:17:47 +0200 | [diff] [blame] | 2077 | |
Derek Foreman | 1281a36 | 2015-07-31 16:55:32 -0500 | [diff] [blame] | 2078 | shsurf = get_shell_surface(pointer->focus->surface); |
Kristian Høgsberg | 2bff94e | 2014-02-11 12:22:51 -0800 | [diff] [blame] | 2079 | if (shsurf && |
| 2080 | wl_resource_get_client(shsurf->resource) == sc->client) |
Derek Foreman | 1281a36 | 2015-07-31 16:55:32 -0500 | [diff] [blame] | 2081 | set_busy_cursor(shsurf, pointer); |
Kristian Høgsberg | 2bff94e | 2014-02-11 12:22:51 -0800 | [diff] [blame] | 2082 | } |
| 2083 | |
| 2084 | return 1; |
| 2085 | } |
| 2086 | |
| 2087 | static void |
| 2088 | handle_xdg_ping(struct shell_surface *shsurf, uint32_t serial) |
| 2089 | { |
| 2090 | struct weston_compositor *compositor = shsurf->shell->compositor; |
Jason Ekstrand | 9e9512f | 2014-04-16 21:12:10 -0500 | [diff] [blame] | 2091 | struct shell_client *sc = shsurf->owner; |
Kristian Høgsberg | 2bff94e | 2014-02-11 12:22:51 -0800 | [diff] [blame] | 2092 | struct wl_event_loop *loop; |
Kristian Høgsberg | dd62aba | 2014-02-12 09:56:19 -0800 | [diff] [blame] | 2093 | static const int ping_timeout = 200; |
Kristian Høgsberg | 2bff94e | 2014-02-11 12:22:51 -0800 | [diff] [blame] | 2094 | |
Kristian Høgsberg | 2bff94e | 2014-02-11 12:22:51 -0800 | [diff] [blame] | 2095 | if (sc->unresponsive) { |
| 2096 | xdg_ping_timeout_handler(sc); |
| 2097 | return; |
| 2098 | } |
| 2099 | |
| 2100 | sc->ping_serial = serial; |
| 2101 | loop = wl_display_get_event_loop(compositor->wl_display); |
| 2102 | if (sc->ping_timer == NULL) |
| 2103 | sc->ping_timer = |
| 2104 | wl_event_loop_add_timer(loop, |
| 2105 | xdg_ping_timeout_handler, sc); |
| 2106 | if (sc->ping_timer == NULL) |
| 2107 | return; |
| 2108 | |
| 2109 | wl_event_source_timer_update(sc->ping_timer, ping_timeout); |
| 2110 | |
Kristian Høgsberg | dd62aba | 2014-02-12 09:56:19 -0800 | [diff] [blame] | 2111 | if (shell_surface_is_xdg_surface(shsurf) || |
| 2112 | shell_surface_is_xdg_popup(shsurf)) |
| 2113 | xdg_shell_send_ping(sc->resource, serial); |
| 2114 | else if (shell_surface_is_wl_shell_surface(shsurf)) |
| 2115 | wl_shell_surface_send_ping(shsurf->resource, serial); |
Kristian Høgsberg | 2bff94e | 2014-02-11 12:22:51 -0800 | [diff] [blame] | 2116 | } |
| 2117 | |
Scott Moreau | ff1db4a | 2012-04-17 19:06:18 -0600 | [diff] [blame] | 2118 | static void |
| 2119 | ping_handler(struct weston_surface *surface, uint32_t serial) |
| 2120 | { |
Kristian Høgsberg | b71302e | 2012-05-10 12:28:35 -0400 | [diff] [blame] | 2121 | struct shell_surface *shsurf = get_shell_surface(surface); |
Scott Moreau | ff1db4a | 2012-04-17 19:06:18 -0600 | [diff] [blame] | 2122 | |
| 2123 | if (!shsurf) |
| 2124 | return; |
Jason Ekstrand | 651f00e | 2013-06-14 10:07:54 -0500 | [diff] [blame] | 2125 | if (!shsurf->resource) |
Kristian Høgsberg | ca535c1 | 2012-04-21 23:20:07 -0400 | [diff] [blame] | 2126 | return; |
Ander Conselvan de Oliveira | eac9a46 | 2012-07-16 14:15:48 +0300 | [diff] [blame] | 2127 | if (shsurf->surface == shsurf->shell->grab_surface) |
| 2128 | return; |
| 2129 | |
Kristian Høgsberg | dd62aba | 2014-02-12 09:56:19 -0800 | [diff] [blame] | 2130 | handle_xdg_ping(shsurf, serial); |
Scott Moreau | ff1db4a | 2012-04-17 19:06:18 -0600 | [diff] [blame] | 2131 | } |
| 2132 | |
| 2133 | static void |
Kristian Høgsberg | d56bd90 | 2012-06-05 09:58:51 -0400 | [diff] [blame] | 2134 | handle_pointer_focus(struct wl_listener *listener, void *data) |
| 2135 | { |
Kristian Høgsberg | 02bbabb | 2013-05-06 22:15:05 -0400 | [diff] [blame] | 2136 | struct weston_pointer *pointer = data; |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 2137 | struct weston_view *view = pointer->focus; |
Kristian Høgsberg | d56bd90 | 2012-06-05 09:58:51 -0400 | [diff] [blame] | 2138 | struct weston_compositor *compositor; |
Kristian Høgsberg | d56bd90 | 2012-06-05 09:58:51 -0400 | [diff] [blame] | 2139 | uint32_t serial; |
| 2140 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 2141 | if (!view) |
Kristian Høgsberg | d56bd90 | 2012-06-05 09:58:51 -0400 | [diff] [blame] | 2142 | return; |
| 2143 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 2144 | compositor = view->surface->compositor; |
Kristian Høgsberg | e11ef64 | 2014-02-11 16:35:22 -0800 | [diff] [blame] | 2145 | serial = wl_display_next_serial(compositor->wl_display); |
| 2146 | ping_handler(view->surface, serial); |
Kristian Høgsberg | d56bd90 | 2012-06-05 09:58:51 -0400 | [diff] [blame] | 2147 | } |
| 2148 | |
| 2149 | static void |
Jasper St. Pierre | faf27a9 | 2013-12-09 17:36:28 -0500 | [diff] [blame] | 2150 | shell_surface_lose_keyboard_focus(struct shell_surface *shsurf) |
| 2151 | { |
| 2152 | if (--shsurf->focus_count == 0) |
Jasper St. Pierre | 973d787 | 2014-05-06 08:44:29 -0400 | [diff] [blame] | 2153 | shell_surface_state_changed(shsurf); |
Jasper St. Pierre | faf27a9 | 2013-12-09 17:36:28 -0500 | [diff] [blame] | 2154 | } |
| 2155 | |
| 2156 | static void |
| 2157 | shell_surface_gain_keyboard_focus(struct shell_surface *shsurf) |
| 2158 | { |
| 2159 | if (shsurf->focus_count++ == 0) |
Jasper St. Pierre | 973d787 | 2014-05-06 08:44:29 -0400 | [diff] [blame] | 2160 | shell_surface_state_changed(shsurf); |
Jasper St. Pierre | faf27a9 | 2013-12-09 17:36:28 -0500 | [diff] [blame] | 2161 | } |
| 2162 | |
| 2163 | static void |
| 2164 | handle_keyboard_focus(struct wl_listener *listener, void *data) |
| 2165 | { |
| 2166 | struct weston_keyboard *keyboard = data; |
| 2167 | struct shell_seat *seat = get_shell_seat(keyboard->seat); |
| 2168 | |
| 2169 | if (seat->focused_surface) { |
| 2170 | struct shell_surface *shsurf = get_shell_surface(seat->focused_surface); |
| 2171 | if (shsurf) |
| 2172 | shell_surface_lose_keyboard_focus(shsurf); |
| 2173 | } |
| 2174 | |
| 2175 | seat->focused_surface = keyboard->focus; |
| 2176 | |
| 2177 | if (seat->focused_surface) { |
| 2178 | struct shell_surface *shsurf = get_shell_surface(seat->focused_surface); |
| 2179 | if (shsurf) |
| 2180 | shell_surface_gain_keyboard_focus(shsurf); |
| 2181 | } |
| 2182 | } |
| 2183 | |
| 2184 | static void |
Kristian Høgsberg | dd62aba | 2014-02-12 09:56:19 -0800 | [diff] [blame] | 2185 | shell_client_pong(struct shell_client *sc, uint32_t serial) |
Rafael Antognolli | e2a3455 | 2013-12-03 15:35:45 -0200 | [diff] [blame] | 2186 | { |
Kristian Høgsberg | dd62aba | 2014-02-12 09:56:19 -0800 | [diff] [blame] | 2187 | if (sc->ping_serial != serial) |
| 2188 | return; |
Rafael Antognolli | e2a3455 | 2013-12-03 15:35:45 -0200 | [diff] [blame] | 2189 | |
Kristian Høgsberg | dd62aba | 2014-02-12 09:56:19 -0800 | [diff] [blame] | 2190 | sc->unresponsive = 0; |
| 2191 | end_busy_cursor(sc->shell->compositor, sc->client); |
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_timer) { |
| 2194 | wl_event_source_remove(sc->ping_timer); |
| 2195 | sc->ping_timer = NULL; |
| 2196 | } |
| 2197 | |
| 2198 | } |
| 2199 | |
| 2200 | static void |
| 2201 | shell_surface_pong(struct wl_client *client, |
| 2202 | struct wl_resource *resource, uint32_t serial) |
| 2203 | { |
Jason Ekstrand | 9e9512f | 2014-04-16 21:12:10 -0500 | [diff] [blame] | 2204 | struct shell_surface *shsurf = wl_resource_get_user_data(resource); |
| 2205 | struct shell_client *sc = shsurf->owner; |
Kristian Høgsberg | dd62aba | 2014-02-12 09:56:19 -0800 | [diff] [blame] | 2206 | |
Kristian Høgsberg | dd62aba | 2014-02-12 09:56:19 -0800 | [diff] [blame] | 2207 | shell_client_pong(sc, serial); |
Rafael Antognolli | e2a3455 | 2013-12-03 15:35:45 -0200 | [diff] [blame] | 2208 | } |
| 2209 | |
| 2210 | static void |
Giulio Camuffo | 62942ad | 2013-09-11 18:20:47 +0200 | [diff] [blame] | 2211 | set_title(struct shell_surface *shsurf, const char *title) |
| 2212 | { |
| 2213 | free(shsurf->title); |
| 2214 | shsurf->title = strdup(title); |
Pekka Paalanen | b502654 | 2014-11-12 15:09:24 +0200 | [diff] [blame] | 2215 | shsurf->surface->timeline.force_refresh = 1; |
| 2216 | } |
| 2217 | |
| 2218 | static void |
Giulio Camuffo | a8e9b41 | 2015-01-27 19:10:37 +0200 | [diff] [blame] | 2219 | set_pid(struct shell_surface *shsurf, pid_t pid) |
| 2220 | { |
| 2221 | /* We have no use for it */ |
| 2222 | } |
| 2223 | |
| 2224 | static void |
Pekka Paalanen | b502654 | 2014-11-12 15:09:24 +0200 | [diff] [blame] | 2225 | set_type(struct shell_surface *shsurf, enum shell_surface_type t) |
| 2226 | { |
| 2227 | shsurf->type = t; |
| 2228 | shsurf->surface->timeline.force_refresh = 1; |
Giulio Camuffo | 62942ad | 2013-09-11 18:20:47 +0200 | [diff] [blame] | 2229 | } |
| 2230 | |
| 2231 | static void |
Jasper St. Pierre | ccf48fb | 2014-05-02 10:21:38 -0400 | [diff] [blame] | 2232 | set_window_geometry(struct shell_surface *shsurf, |
| 2233 | 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] | 2234 | { |
Jasper St. Pierre | ccf48fb | 2014-05-02 10:21:38 -0400 | [diff] [blame] | 2235 | shsurf->next_geometry.x = x; |
| 2236 | shsurf->next_geometry.y = y; |
| 2237 | shsurf->next_geometry.width = width; |
| 2238 | shsurf->next_geometry.height = height; |
| 2239 | shsurf->has_next_geometry = true; |
Kristian Høgsberg | e5c1ae9 | 2014-04-30 16:28:41 -0700 | [diff] [blame] | 2240 | } |
| 2241 | |
| 2242 | static void |
Kristian Høgsberg | e7afd91 | 2012-05-02 09:47:44 -0400 | [diff] [blame] | 2243 | shell_surface_set_title(struct wl_client *client, |
| 2244 | struct wl_resource *resource, const char *title) |
| 2245 | { |
Jason Ekstrand | 651f00e | 2013-06-14 10:07:54 -0500 | [diff] [blame] | 2246 | struct shell_surface *shsurf = wl_resource_get_user_data(resource); |
Kristian Høgsberg | e7afd91 | 2012-05-02 09:47:44 -0400 | [diff] [blame] | 2247 | |
Giulio Camuffo | 62942ad | 2013-09-11 18:20:47 +0200 | [diff] [blame] | 2248 | set_title(shsurf, title); |
Kristian Høgsberg | e7afd91 | 2012-05-02 09:47:44 -0400 | [diff] [blame] | 2249 | } |
| 2250 | |
| 2251 | static void |
| 2252 | shell_surface_set_class(struct wl_client *client, |
| 2253 | struct wl_resource *resource, const char *class) |
| 2254 | { |
Jason Ekstrand | 651f00e | 2013-06-14 10:07:54 -0500 | [diff] [blame] | 2255 | struct shell_surface *shsurf = wl_resource_get_user_data(resource); |
Kristian Høgsberg | e7afd91 | 2012-05-02 09:47:44 -0400 | [diff] [blame] | 2256 | |
| 2257 | free(shsurf->class); |
| 2258 | shsurf->class = strdup(class); |
Pekka Paalanen | b502654 | 2014-11-12 15:09:24 +0200 | [diff] [blame] | 2259 | shsurf->surface->timeline.force_refresh = 1; |
Kristian Høgsberg | e7afd91 | 2012-05-02 09:47:44 -0400 | [diff] [blame] | 2260 | } |
| 2261 | |
Alex Wu | 4539b08 | 2012-03-01 12:57:46 +0800 | [diff] [blame] | 2262 | static void |
Alexander Larsson | f82b6ca | 2013-05-28 16:23:39 +0200 | [diff] [blame] | 2263 | restore_output_mode(struct weston_output *output) |
| 2264 | { |
Derek Foreman | 6ae7bc9 | 2014-11-04 10:47:33 -0600 | [diff] [blame] | 2265 | if (output->original_mode) |
| 2266 | weston_output_mode_switch_to_native(output); |
Alexander Larsson | f82b6ca | 2013-05-28 16:23:39 +0200 | [diff] [blame] | 2267 | } |
| 2268 | |
| 2269 | static void |
| 2270 | restore_all_output_modes(struct weston_compositor *compositor) |
| 2271 | { |
| 2272 | struct weston_output *output; |
| 2273 | |
| 2274 | wl_list_for_each(output, &compositor->output_list, link) |
| 2275 | restore_output_mode(output); |
| 2276 | } |
| 2277 | |
Philip Withnall | 07926d9 | 2013-11-25 18:01:40 +0000 | [diff] [blame] | 2278 | /* The surface will be inserted into the list immediately after the link |
| 2279 | * returned by this function (i.e. will be stacked immediately above the |
| 2280 | * returned link). */ |
Giulio Camuffo | 412e6a5 | 2014-07-09 22:12:56 +0300 | [diff] [blame] | 2281 | static struct weston_layer_entry * |
Philip Withnall | 07926d9 | 2013-11-25 18:01:40 +0000 | [diff] [blame] | 2282 | shell_surface_calculate_layer_link (struct shell_surface *shsurf) |
| 2283 | { |
| 2284 | struct workspace *ws; |
Kristian Høgsberg | ead5242 | 2014-01-01 13:51:52 -0800 | [diff] [blame] | 2285 | struct weston_view *parent; |
Philip Withnall | 07926d9 | 2013-11-25 18:01:40 +0000 | [diff] [blame] | 2286 | |
| 2287 | switch (shsurf->type) { |
Ander Conselvan de Oliveira | ef6a7e4 | 2014-04-30 14:15:14 +0300 | [diff] [blame] | 2288 | case SHELL_SURFACE_XWAYLAND: |
| 2289 | return &shsurf->shell->fullscreen_layer.view_list; |
| 2290 | |
| 2291 | case SHELL_SURFACE_NONE: |
| 2292 | return NULL; |
| 2293 | |
Kristian Høgsberg | ead5242 | 2014-01-01 13:51:52 -0800 | [diff] [blame] | 2294 | case SHELL_SURFACE_POPUP: |
| 2295 | case SHELL_SURFACE_TOPLEVEL: |
Emilio Pozuelo Monfort | 9e7c759 | 2014-01-30 14:01:10 +0100 | [diff] [blame] | 2296 | if (shsurf->state.fullscreen && !shsurf->state.lowered) { |
Rafael Antognolli | 03b1659 | 2013-12-03 15:35:42 -0200 | [diff] [blame] | 2297 | return &shsurf->shell->fullscreen_layer.view_list; |
Rafael Antognolli | ed207b4 | 2013-12-03 15:35:43 -0200 | [diff] [blame] | 2298 | } else if (shsurf->parent) { |
Kristian Høgsberg | d55db69 | 2014-01-01 12:26:14 -0800 | [diff] [blame] | 2299 | /* Move the surface to its parent layer so |
| 2300 | * that surfaces which are transient for |
| 2301 | * fullscreen surfaces don't get hidden by the |
| 2302 | * fullscreen surfaces. */ |
Rafael Antognolli | ed207b4 | 2013-12-03 15:35:43 -0200 | [diff] [blame] | 2303 | |
| 2304 | /* TODO: Handle a parent with multiple views */ |
| 2305 | parent = get_default_view(shsurf->parent); |
| 2306 | if (parent) |
Giulio Camuffo | 412e6a5 | 2014-07-09 22:12:56 +0300 | [diff] [blame] | 2307 | return container_of(parent->layer_link.link.prev, |
| 2308 | struct weston_layer_entry, link); |
Rafael Antognolli | ed207b4 | 2013-12-03 15:35:43 -0200 | [diff] [blame] | 2309 | } |
Philip Withnall | 07926d9 | 2013-11-25 18:01:40 +0000 | [diff] [blame] | 2310 | |
Ander Conselvan de Oliveira | ef6a7e4 | 2014-04-30 14:15:14 +0300 | [diff] [blame] | 2311 | /* Move the surface to a normal workspace layer so that surfaces |
| 2312 | * which were previously fullscreen or transient are no longer |
| 2313 | * rendered on top. */ |
| 2314 | ws = get_current_workspace(shsurf->shell); |
| 2315 | return &ws->layer.view_list; |
Philip Withnall | 07926d9 | 2013-11-25 18:01:40 +0000 | [diff] [blame] | 2316 | } |
| 2317 | |
Ander Conselvan de Oliveira | ef6a7e4 | 2014-04-30 14:15:14 +0300 | [diff] [blame] | 2318 | assert(0 && "Unknown shell surface type"); |
Philip Withnall | 07926d9 | 2013-11-25 18:01:40 +0000 | [diff] [blame] | 2319 | } |
| 2320 | |
Philip Withnall | 648a4dd | 2013-11-25 18:01:44 +0000 | [diff] [blame] | 2321 | static void |
| 2322 | shell_surface_update_child_surface_layers (struct shell_surface *shsurf) |
| 2323 | { |
| 2324 | struct shell_surface *child; |
Giulio Camuffo | 412e6a5 | 2014-07-09 22:12:56 +0300 | [diff] [blame] | 2325 | struct weston_layer_entry *prev; |
Philip Withnall | 648a4dd | 2013-11-25 18:01:44 +0000 | [diff] [blame] | 2326 | |
| 2327 | /* Move the child layers to the same workspace as shsurf. They will be |
| 2328 | * stacked above shsurf. */ |
| 2329 | wl_list_for_each_reverse(child, &shsurf->children_list, children_link) { |
Giulio Camuffo | 412e6a5 | 2014-07-09 22:12:56 +0300 | [diff] [blame] | 2330 | 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] | 2331 | weston_view_damage_below(child->view); |
Philip Withnall | 648a4dd | 2013-11-25 18:01:44 +0000 | [diff] [blame] | 2332 | weston_view_geometry_dirty(child->view); |
Giulio Camuffo | 412e6a5 | 2014-07-09 22:12:56 +0300 | [diff] [blame] | 2333 | prev = container_of(shsurf->view->layer_link.link.prev, |
| 2334 | struct weston_layer_entry, link); |
| 2335 | weston_layer_entry_remove(&child->view->layer_link); |
| 2336 | weston_layer_entry_insert(prev, |
| 2337 | &child->view->layer_link); |
Philip Withnall | 648a4dd | 2013-11-25 18:01:44 +0000 | [diff] [blame] | 2338 | weston_view_geometry_dirty(child->view); |
| 2339 | weston_surface_damage(child->surface); |
| 2340 | |
| 2341 | /* Recurse. We don’t expect this to recurse very far (if |
| 2342 | * at all) because that would imply we have transient |
| 2343 | * (or popup) children of transient surfaces, which |
| 2344 | * would be unusual. */ |
| 2345 | shell_surface_update_child_surface_layers(child); |
| 2346 | } |
| 2347 | } |
| 2348 | } |
| 2349 | |
Philip Withnall | e1d75ae | 2013-11-25 18:01:41 +0000 | [diff] [blame] | 2350 | /* 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] | 2351 | * geometry to ensure the changes are redrawn. |
| 2352 | * |
| 2353 | * If any child surfaces exist and are mapped, ensure they’re in the same layer |
| 2354 | * as this surface. */ |
Philip Withnall | e1d75ae | 2013-11-25 18:01:41 +0000 | [diff] [blame] | 2355 | static void |
| 2356 | shell_surface_update_layer(struct shell_surface *shsurf) |
| 2357 | { |
Giulio Camuffo | 412e6a5 | 2014-07-09 22:12:56 +0300 | [diff] [blame] | 2358 | struct weston_layer_entry *new_layer_link; |
Philip Withnall | e1d75ae | 2013-11-25 18:01:41 +0000 | [diff] [blame] | 2359 | |
| 2360 | new_layer_link = shell_surface_calculate_layer_link(shsurf); |
| 2361 | |
Ander Conselvan de Oliveira | ef6a7e4 | 2014-04-30 14:15:14 +0300 | [diff] [blame] | 2362 | if (new_layer_link == NULL) |
| 2363 | return; |
Philip Withnall | e1d75ae | 2013-11-25 18:01:41 +0000 | [diff] [blame] | 2364 | if (new_layer_link == &shsurf->view->layer_link) |
| 2365 | return; |
| 2366 | |
| 2367 | weston_view_geometry_dirty(shsurf->view); |
Giulio Camuffo | 412e6a5 | 2014-07-09 22:12:56 +0300 | [diff] [blame] | 2368 | weston_layer_entry_remove(&shsurf->view->layer_link); |
| 2369 | weston_layer_entry_insert(new_layer_link, &shsurf->view->layer_link); |
Philip Withnall | e1d75ae | 2013-11-25 18:01:41 +0000 | [diff] [blame] | 2370 | weston_view_geometry_dirty(shsurf->view); |
| 2371 | weston_surface_damage(shsurf->surface); |
Philip Withnall | 648a4dd | 2013-11-25 18:01:44 +0000 | [diff] [blame] | 2372 | |
| 2373 | shell_surface_update_child_surface_layers(shsurf); |
Philip Withnall | e1d75ae | 2013-11-25 18:01:41 +0000 | [diff] [blame] | 2374 | } |
| 2375 | |
Alexander Larsson | f82b6ca | 2013-05-28 16:23:39 +0200 | [diff] [blame] | 2376 | static void |
Philip Withnall | dc4332f | 2013-11-25 18:01:38 +0000 | [diff] [blame] | 2377 | shell_surface_set_parent(struct shell_surface *shsurf, |
| 2378 | struct weston_surface *parent) |
| 2379 | { |
| 2380 | shsurf->parent = parent; |
Philip Withnall | 648a4dd | 2013-11-25 18:01:44 +0000 | [diff] [blame] | 2381 | |
| 2382 | wl_list_remove(&shsurf->children_link); |
| 2383 | wl_list_init(&shsurf->children_link); |
| 2384 | |
| 2385 | /* Insert into the parent surface’s child list. */ |
| 2386 | if (parent != NULL) { |
| 2387 | struct shell_surface *parent_shsurf = get_shell_surface(parent); |
| 2388 | if (parent_shsurf != NULL) |
| 2389 | wl_list_insert(&parent_shsurf->children_list, |
| 2390 | &shsurf->children_link); |
| 2391 | } |
Philip Withnall | dc4332f | 2013-11-25 18:01:38 +0000 | [diff] [blame] | 2392 | } |
| 2393 | |
| 2394 | static void |
Philip Withnall | 352e7ed | 2013-11-25 18:01:35 +0000 | [diff] [blame] | 2395 | shell_surface_set_output(struct shell_surface *shsurf, |
| 2396 | struct weston_output *output) |
| 2397 | { |
| 2398 | struct weston_surface *es = shsurf->surface; |
| 2399 | |
| 2400 | /* get the default output, if the client set it as NULL |
| 2401 | check whether the ouput is available */ |
| 2402 | if (output) |
| 2403 | shsurf->output = output; |
| 2404 | else if (es->output) |
| 2405 | shsurf->output = es->output; |
| 2406 | else |
| 2407 | shsurf->output = get_default_output(es->compositor); |
| 2408 | } |
| 2409 | |
| 2410 | static void |
Rafael Antognolli | 03b1659 | 2013-12-03 15:35:42 -0200 | [diff] [blame] | 2411 | surface_clear_next_states(struct shell_surface *shsurf) |
| 2412 | { |
| 2413 | shsurf->next_state.maximized = false; |
| 2414 | shsurf->next_state.fullscreen = false; |
| 2415 | |
| 2416 | if ((shsurf->next_state.maximized != shsurf->state.maximized) || |
| 2417 | (shsurf->next_state.fullscreen != shsurf->state.fullscreen)) |
| 2418 | shsurf->state_changed = true; |
| 2419 | } |
| 2420 | |
| 2421 | static void |
Philip Withnall | becb77e | 2013-11-25 18:01:30 +0000 | [diff] [blame] | 2422 | set_toplevel(struct shell_surface *shsurf) |
| 2423 | { |
Kristian Høgsberg | 41fbf6f | 2013-12-05 22:31:25 -0800 | [diff] [blame] | 2424 | shell_surface_set_parent(shsurf, NULL); |
| 2425 | surface_clear_next_states(shsurf); |
Pekka Paalanen | b502654 | 2014-11-12 15:09:24 +0200 | [diff] [blame] | 2426 | set_type(shsurf, SHELL_SURFACE_TOPLEVEL); |
Philip Withnall | 648a4dd | 2013-11-25 18:01:44 +0000 | [diff] [blame] | 2427 | |
| 2428 | /* The layer_link is updated in set_surface_type(), |
| 2429 | * called from configure. */ |
Philip Withnall | becb77e | 2013-11-25 18:01:30 +0000 | [diff] [blame] | 2430 | } |
| 2431 | |
| 2432 | static void |
| 2433 | shell_surface_set_toplevel(struct wl_client *client, |
| 2434 | struct wl_resource *resource) |
| 2435 | { |
| 2436 | struct shell_surface *surface = wl_resource_get_user_data(resource); |
| 2437 | |
| 2438 | set_toplevel(surface); |
| 2439 | } |
| 2440 | |
| 2441 | static void |
| 2442 | set_transient(struct shell_surface *shsurf, |
| 2443 | struct weston_surface *parent, int x, int y, uint32_t flags) |
| 2444 | { |
Philip Withnall | dc4332f | 2013-11-25 18:01:38 +0000 | [diff] [blame] | 2445 | assert(parent != NULL); |
| 2446 | |
Kristian Høgsberg | 9f7e331 | 2014-01-02 22:40:37 -0800 | [diff] [blame] | 2447 | shell_surface_set_parent(shsurf, parent); |
| 2448 | |
| 2449 | surface_clear_next_states(shsurf); |
| 2450 | |
Philip Withnall | becb77e | 2013-11-25 18:01:30 +0000 | [diff] [blame] | 2451 | shsurf->transient.x = x; |
| 2452 | shsurf->transient.y = y; |
| 2453 | shsurf->transient.flags = flags; |
Philip Withnall | dc4332f | 2013-11-25 18:01:38 +0000 | [diff] [blame] | 2454 | |
Rafael Antognolli | ed207b4 | 2013-12-03 15:35:43 -0200 | [diff] [blame] | 2455 | shsurf->next_state.relative = true; |
Kristian Høgsberg | a1df7ac | 2013-12-31 15:01:01 -0800 | [diff] [blame] | 2456 | shsurf->state_changed = true; |
Pekka Paalanen | b502654 | 2014-11-12 15:09:24 +0200 | [diff] [blame] | 2457 | set_type(shsurf, SHELL_SURFACE_TOPLEVEL); |
Philip Withnall | 648a4dd | 2013-11-25 18:01:44 +0000 | [diff] [blame] | 2458 | |
| 2459 | /* The layer_link is updated in set_surface_type(), |
| 2460 | * called from configure. */ |
Philip Withnall | becb77e | 2013-11-25 18:01:30 +0000 | [diff] [blame] | 2461 | } |
| 2462 | |
| 2463 | static void |
| 2464 | shell_surface_set_transient(struct wl_client *client, |
| 2465 | struct wl_resource *resource, |
| 2466 | struct wl_resource *parent_resource, |
| 2467 | int x, int y, uint32_t flags) |
| 2468 | { |
| 2469 | struct shell_surface *shsurf = wl_resource_get_user_data(resource); |
| 2470 | struct weston_surface *parent = |
| 2471 | wl_resource_get_user_data(parent_resource); |
| 2472 | |
| 2473 | set_transient(shsurf, parent, x, y, flags); |
| 2474 | } |
| 2475 | |
| 2476 | static void |
| 2477 | set_fullscreen(struct shell_surface *shsurf, |
| 2478 | uint32_t method, |
| 2479 | uint32_t framerate, |
| 2480 | struct weston_output *output) |
| 2481 | { |
Philip Withnall | 352e7ed | 2013-11-25 18:01:35 +0000 | [diff] [blame] | 2482 | shell_surface_set_output(shsurf, output); |
Pekka Paalanen | b502654 | 2014-11-12 15:09:24 +0200 | [diff] [blame] | 2483 | set_type(shsurf, SHELL_SURFACE_TOPLEVEL); |
Philip Withnall | becb77e | 2013-11-25 18:01:30 +0000 | [diff] [blame] | 2484 | |
| 2485 | shsurf->fullscreen_output = shsurf->output; |
| 2486 | shsurf->fullscreen.type = method; |
| 2487 | shsurf->fullscreen.framerate = framerate; |
Philip Withnall | dc4332f | 2013-11-25 18:01:38 +0000 | [diff] [blame] | 2488 | |
Jasper St. Pierre | 6458ec3 | 2014-04-11 16:00:31 -0700 | [diff] [blame] | 2489 | send_configure_for_surface(shsurf); |
Philip Withnall | becb77e | 2013-11-25 18:01:30 +0000 | [diff] [blame] | 2490 | } |
| 2491 | |
| 2492 | static void |
Zhang, Xiong Y | 3123693 | 2013-12-13 22:10:57 +0200 | [diff] [blame] | 2493 | weston_view_set_initial_position(struct weston_view *view, |
| 2494 | struct desktop_shell *shell); |
| 2495 | |
| 2496 | static void |
Philip Withnall | becb77e | 2013-11-25 18:01:30 +0000 | [diff] [blame] | 2497 | unset_fullscreen(struct shell_surface *shsurf) |
Alex Wu | 4539b08 | 2012-03-01 12:57:46 +0800 | [diff] [blame] | 2498 | { |
Philip Withnall | f85fe84 | 2013-11-25 18:01:37 +0000 | [diff] [blame] | 2499 | /* Unset the fullscreen output, driver configuration and transforms. */ |
Alex Wu | bd3354b | 2012-04-17 17:20:49 +0800 | [diff] [blame] | 2500 | if (shsurf->fullscreen.type == WL_SHELL_SURFACE_FULLSCREEN_METHOD_DRIVER && |
| 2501 | shell_surface_is_top_fullscreen(shsurf)) { |
Alexander Larsson | f82b6ca | 2013-05-28 16:23:39 +0200 | [diff] [blame] | 2502 | restore_output_mode(shsurf->fullscreen_output); |
Alex Wu | bd3354b | 2012-04-17 17:20:49 +0800 | [diff] [blame] | 2503 | } |
Philip Withnall | f85fe84 | 2013-11-25 18:01:37 +0000 | [diff] [blame] | 2504 | |
Alex Wu | 4539b08 | 2012-03-01 12:57:46 +0800 | [diff] [blame] | 2505 | shsurf->fullscreen.type = WL_SHELL_SURFACE_FULLSCREEN_METHOD_DEFAULT; |
| 2506 | shsurf->fullscreen.framerate = 0; |
Philip Withnall | f85fe84 | 2013-11-25 18:01:37 +0000 | [diff] [blame] | 2507 | |
Alex Wu | 4539b08 | 2012-03-01 12:57:46 +0800 | [diff] [blame] | 2508 | wl_list_remove(&shsurf->fullscreen.transform.link); |
| 2509 | wl_list_init(&shsurf->fullscreen.transform.link); |
Philip Withnall | f85fe84 | 2013-11-25 18:01:37 +0000 | [diff] [blame] | 2510 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 2511 | if (shsurf->fullscreen.black_view) |
| 2512 | weston_surface_destroy(shsurf->fullscreen.black_view->surface); |
| 2513 | shsurf->fullscreen.black_view = NULL; |
Philip Withnall | f85fe84 | 2013-11-25 18:01:37 +0000 | [diff] [blame] | 2514 | |
Zhang, Xiong Y | 3123693 | 2013-12-13 22:10:57 +0200 | [diff] [blame] | 2515 | if (shsurf->saved_position_valid) |
| 2516 | weston_view_set_position(shsurf->view, |
| 2517 | shsurf->saved_x, shsurf->saved_y); |
| 2518 | else |
| 2519 | weston_view_set_initial_position(shsurf->view, shsurf->shell); |
| 2520 | |
Alex Wu | 7bcb8bd | 2012-04-27 09:07:24 +0800 | [diff] [blame] | 2521 | if (shsurf->saved_rotation_valid) { |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 2522 | wl_list_insert(&shsurf->view->geometry.transformation_list, |
Philip Withnall | becb77e | 2013-11-25 18:01:30 +0000 | [diff] [blame] | 2523 | &shsurf->rotation.transform.link); |
Alex Wu | 7bcb8bd | 2012-04-27 09:07:24 +0800 | [diff] [blame] | 2524 | shsurf->saved_rotation_valid = false; |
| 2525 | } |
Rafal Mielniczuk | 3e3862c | 2012-10-07 20:25:36 +0200 | [diff] [blame] | 2526 | |
Philip Withnall | e1d75ae | 2013-11-25 18:01:41 +0000 | [diff] [blame] | 2527 | /* Layer is updated in set_surface_type(). */ |
Alex Wu | 4539b08 | 2012-03-01 12:57:46 +0800 | [diff] [blame] | 2528 | } |
| 2529 | |
Rafal Mielniczuk | fffdcdd | 2013-03-11 19:26:54 +0100 | [diff] [blame] | 2530 | static void |
Philip Withnall | becb77e | 2013-11-25 18:01:30 +0000 | [diff] [blame] | 2531 | shell_surface_set_fullscreen(struct wl_client *client, |
| 2532 | struct wl_resource *resource, |
| 2533 | uint32_t method, |
| 2534 | uint32_t framerate, |
| 2535 | struct wl_resource *output_resource) |
| 2536 | { |
| 2537 | struct shell_surface *shsurf = wl_resource_get_user_data(resource); |
| 2538 | struct weston_output *output; |
| 2539 | |
| 2540 | if (output_resource) |
| 2541 | output = wl_resource_get_user_data(output_resource); |
| 2542 | else |
| 2543 | output = NULL; |
| 2544 | |
Rafael Antognolli | 4b99a40 | 2013-12-03 15:35:44 -0200 | [diff] [blame] | 2545 | shell_surface_set_parent(shsurf, NULL); |
| 2546 | |
Rafael Antognolli | 03b1659 | 2013-12-03 15:35:42 -0200 | [diff] [blame] | 2547 | surface_clear_next_states(shsurf); |
Jasper St. Pierre | 8c6aa45 | 2014-02-08 18:29:49 -0500 | [diff] [blame] | 2548 | shsurf->next_state.fullscreen = true; |
| 2549 | shsurf->state_changed = true; |
Jasper St. Pierre | 6458ec3 | 2014-04-11 16:00:31 -0700 | [diff] [blame] | 2550 | set_fullscreen(shsurf, method, framerate, output); |
Philip Withnall | becb77e | 2013-11-25 18:01:30 +0000 | [diff] [blame] | 2551 | } |
| 2552 | |
| 2553 | static void |
| 2554 | set_popup(struct shell_surface *shsurf, |
| 2555 | struct weston_surface *parent, |
| 2556 | struct weston_seat *seat, |
| 2557 | uint32_t serial, |
| 2558 | int32_t x, |
| 2559 | int32_t y) |
| 2560 | { |
Philip Withnall | dc4332f | 2013-11-25 18:01:38 +0000 | [diff] [blame] | 2561 | assert(parent != NULL); |
| 2562 | |
Philip Withnall | becb77e | 2013-11-25 18:01:30 +0000 | [diff] [blame] | 2563 | shsurf->popup.shseat = get_shell_seat(seat); |
| 2564 | shsurf->popup.serial = serial; |
| 2565 | shsurf->popup.x = x; |
| 2566 | shsurf->popup.y = y; |
Philip Withnall | dc4332f | 2013-11-25 18:01:38 +0000 | [diff] [blame] | 2567 | |
Pekka Paalanen | b502654 | 2014-11-12 15:09:24 +0200 | [diff] [blame] | 2568 | set_type(shsurf, SHELL_SURFACE_POPUP); |
Philip Withnall | becb77e | 2013-11-25 18:01:30 +0000 | [diff] [blame] | 2569 | } |
| 2570 | |
| 2571 | static void |
| 2572 | shell_surface_set_popup(struct wl_client *client, |
| 2573 | struct wl_resource *resource, |
| 2574 | struct wl_resource *seat_resource, |
| 2575 | uint32_t serial, |
| 2576 | struct wl_resource *parent_resource, |
| 2577 | int32_t x, int32_t y, uint32_t flags) |
| 2578 | { |
| 2579 | struct shell_surface *shsurf = wl_resource_get_user_data(resource); |
Rafael Antognolli | 4b99a40 | 2013-12-03 15:35:44 -0200 | [diff] [blame] | 2580 | struct weston_surface *parent = |
| 2581 | wl_resource_get_user_data(parent_resource); |
| 2582 | |
| 2583 | shell_surface_set_parent(shsurf, parent); |
Philip Withnall | becb77e | 2013-11-25 18:01:30 +0000 | [diff] [blame] | 2584 | |
Rafael Antognolli | 03b1659 | 2013-12-03 15:35:42 -0200 | [diff] [blame] | 2585 | surface_clear_next_states(shsurf); |
Philip Withnall | becb77e | 2013-11-25 18:01:30 +0000 | [diff] [blame] | 2586 | set_popup(shsurf, |
Rafael Antognolli | 4b99a40 | 2013-12-03 15:35:44 -0200 | [diff] [blame] | 2587 | parent, |
Philip Withnall | becb77e | 2013-11-25 18:01:30 +0000 | [diff] [blame] | 2588 | wl_resource_get_user_data(seat_resource), |
| 2589 | serial, x, y); |
| 2590 | } |
| 2591 | |
| 2592 | static void |
Philip Withnall | becb77e | 2013-11-25 18:01:30 +0000 | [diff] [blame] | 2593 | unset_maximized(struct shell_surface *shsurf) |
Rafal Mielniczuk | fffdcdd | 2013-03-11 19:26:54 +0100 | [diff] [blame] | 2594 | { |
Rafal Mielniczuk | fffdcdd | 2013-03-11 19:26:54 +0100 | [diff] [blame] | 2595 | /* undo all maximized things here */ |
| 2596 | shsurf->output = get_default_output(shsurf->surface->compositor); |
Zhang, Xiong Y | 3123693 | 2013-12-13 22:10:57 +0200 | [diff] [blame] | 2597 | |
| 2598 | if (shsurf->saved_position_valid) |
| 2599 | weston_view_set_position(shsurf->view, |
| 2600 | shsurf->saved_x, shsurf->saved_y); |
| 2601 | else |
| 2602 | weston_view_set_initial_position(shsurf->view, shsurf->shell); |
Rafal Mielniczuk | fffdcdd | 2013-03-11 19:26:54 +0100 | [diff] [blame] | 2603 | |
| 2604 | if (shsurf->saved_rotation_valid) { |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 2605 | wl_list_insert(&shsurf->view->geometry.transformation_list, |
| 2606 | &shsurf->rotation.transform.link); |
Rafal Mielniczuk | fffdcdd | 2013-03-11 19:26:54 +0100 | [diff] [blame] | 2607 | shsurf->saved_rotation_valid = false; |
| 2608 | } |
| 2609 | |
Philip Withnall | e1d75ae | 2013-11-25 18:01:41 +0000 | [diff] [blame] | 2610 | /* Layer is updated in set_surface_type(). */ |
Rafal Mielniczuk | fffdcdd | 2013-03-11 19:26:54 +0100 | [diff] [blame] | 2611 | } |
| 2612 | |
Philip Withnall | becb77e | 2013-11-25 18:01:30 +0000 | [diff] [blame] | 2613 | static void |
Manuel Bachmann | dc1c3e4 | 2015-02-16 11:52:13 +0100 | [diff] [blame] | 2614 | set_minimized(struct weston_surface *surface) |
Manuel Bachmann | 50c87db | 2014-02-26 15:52:13 +0100 | [diff] [blame] | 2615 | { |
| 2616 | struct shell_surface *shsurf; |
| 2617 | struct workspace *current_ws; |
Manuel Bachmann | 50c87db | 2014-02-26 15:52:13 +0100 | [diff] [blame] | 2618 | struct weston_view *view; |
| 2619 | |
| 2620 | view = get_default_view(surface); |
| 2621 | if (!view) |
| 2622 | return; |
| 2623 | |
| 2624 | assert(weston_surface_get_main_surface(view->surface) == view->surface); |
| 2625 | |
| 2626 | shsurf = get_shell_surface(surface); |
| 2627 | current_ws = get_current_workspace(shsurf->shell); |
| 2628 | |
Giulio Camuffo | 412e6a5 | 2014-07-09 22:12:56 +0300 | [diff] [blame] | 2629 | weston_layer_entry_remove(&view->layer_link); |
Manuel Bachmann | dc1c3e4 | 2015-02-16 11:52:13 +0100 | [diff] [blame] | 2630 | 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] | 2631 | |
Manuel Bachmann | dc1c3e4 | 2015-02-16 11:52:13 +0100 | [diff] [blame] | 2632 | drop_focus_state(shsurf->shell, current_ws, view->surface); |
Jonas Ådahl | 22faea1 | 2014-10-15 22:02:06 +0200 | [diff] [blame] | 2633 | surface_keyboard_focus_lost(surface); |
Manuel Bachmann | 50c87db | 2014-02-26 15:52:13 +0100 | [diff] [blame] | 2634 | |
| 2635 | shell_surface_update_child_surface_layers(shsurf); |
Manuel Bachmann | 50c87db | 2014-02-26 15:52:13 +0100 | [diff] [blame] | 2636 | weston_view_damage_below(view); |
| 2637 | } |
| 2638 | |
| 2639 | static void |
Philip Withnall | becb77e | 2013-11-25 18:01:30 +0000 | [diff] [blame] | 2640 | shell_surface_set_maximized(struct wl_client *client, |
| 2641 | struct wl_resource *resource, |
| 2642 | struct wl_resource *output_resource) |
| 2643 | { |
| 2644 | struct shell_surface *shsurf = wl_resource_get_user_data(resource); |
| 2645 | struct weston_output *output; |
| 2646 | |
Jasper St. Pierre | 9aa8ce6 | 2014-04-11 16:18:54 -0700 | [diff] [blame] | 2647 | surface_clear_next_states(shsurf); |
| 2648 | shsurf->next_state.maximized = true; |
| 2649 | shsurf->state_changed = true; |
| 2650 | |
Pekka Paalanen | b502654 | 2014-11-12 15:09:24 +0200 | [diff] [blame] | 2651 | set_type(shsurf, SHELL_SURFACE_TOPLEVEL); |
Jasper St. Pierre | 9aa8ce6 | 2014-04-11 16:18:54 -0700 | [diff] [blame] | 2652 | shell_surface_set_parent(shsurf, NULL); |
| 2653 | |
Philip Withnall | becb77e | 2013-11-25 18:01:30 +0000 | [diff] [blame] | 2654 | if (output_resource) |
| 2655 | output = wl_resource_get_user_data(output_resource); |
| 2656 | else |
| 2657 | output = NULL; |
| 2658 | |
Jasper St. Pierre | 9aa8ce6 | 2014-04-11 16:18:54 -0700 | [diff] [blame] | 2659 | shell_surface_set_output(shsurf, output); |
Rafael Antognolli | 4b99a40 | 2013-12-03 15:35:44 -0200 | [diff] [blame] | 2660 | |
Jasper St. Pierre | 9aa8ce6 | 2014-04-11 16:18:54 -0700 | [diff] [blame] | 2661 | send_configure_for_surface(shsurf); |
Philip Withnall | becb77e | 2013-11-25 18:01:30 +0000 | [diff] [blame] | 2662 | } |
| 2663 | |
Philip Withnall | e1d75ae | 2013-11-25 18:01:41 +0000 | [diff] [blame] | 2664 | /* This is only ever called from set_surface_type(), so there’s no need to |
| 2665 | * update layer_links here, since they’ll be updated when we return. */ |
Pekka Paalanen | 9826223 | 2011-12-01 10:42:22 +0200 | [diff] [blame] | 2666 | static int |
Philip Withnall | becb77e | 2013-11-25 18:01:30 +0000 | [diff] [blame] | 2667 | reset_surface_type(struct shell_surface *surface) |
Pekka Paalanen | 9826223 | 2011-12-01 10:42:22 +0200 | [diff] [blame] | 2668 | { |
Rafael Antognolli | 03b1659 | 2013-12-03 15:35:42 -0200 | [diff] [blame] | 2669 | if (surface->state.fullscreen) |
Philip Withnall | becb77e | 2013-11-25 18:01:30 +0000 | [diff] [blame] | 2670 | unset_fullscreen(surface); |
Rafael Antognolli | 03b1659 | 2013-12-03 15:35:42 -0200 | [diff] [blame] | 2671 | if (surface->state.maximized) |
Philip Withnall | becb77e | 2013-11-25 18:01:30 +0000 | [diff] [blame] | 2672 | unset_maximized(surface); |
Pekka Paalanen | 9826223 | 2011-12-01 10:42:22 +0200 | [diff] [blame] | 2673 | |
Pekka Paalanen | 9826223 | 2011-12-01 10:42:22 +0200 | [diff] [blame] | 2674 | return 0; |
| 2675 | } |
| 2676 | |
Kristian Høgsberg | 4cca349 | 2011-01-18 07:53:49 -0500 | [diff] [blame] | 2677 | static void |
Rafael Antognolli | 03b1659 | 2013-12-03 15:35:42 -0200 | [diff] [blame] | 2678 | set_full_output(struct shell_surface *shsurf) |
| 2679 | { |
| 2680 | shsurf->saved_x = shsurf->view->geometry.x; |
| 2681 | shsurf->saved_y = shsurf->view->geometry.y; |
Rafael Antognolli | 3c4e3f7 | 2013-12-03 15:35:46 -0200 | [diff] [blame] | 2682 | shsurf->saved_width = shsurf->surface->width; |
| 2683 | shsurf->saved_height = shsurf->surface->height; |
| 2684 | shsurf->saved_size_valid = true; |
Rafael Antognolli | 03b1659 | 2013-12-03 15:35:42 -0200 | [diff] [blame] | 2685 | shsurf->saved_position_valid = true; |
| 2686 | |
| 2687 | if (!wl_list_empty(&shsurf->rotation.transform.link)) { |
| 2688 | wl_list_remove(&shsurf->rotation.transform.link); |
| 2689 | wl_list_init(&shsurf->rotation.transform.link); |
| 2690 | weston_view_geometry_dirty(shsurf->view); |
| 2691 | shsurf->saved_rotation_valid = true; |
| 2692 | } |
| 2693 | } |
| 2694 | |
| 2695 | static void |
Kristian Høgsberg | 7f366e7 | 2012-04-27 17:20:01 -0400 | [diff] [blame] | 2696 | set_surface_type(struct shell_surface *shsurf) |
| 2697 | { |
Kristian Høgsberg | 8150b19 | 2012-06-27 10:22:58 -0400 | [diff] [blame] | 2698 | struct weston_surface *pes = shsurf->parent; |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 2699 | struct weston_view *pev = get_default_view(pes); |
Kristian Høgsberg | 7f366e7 | 2012-04-27 17:20:01 -0400 | [diff] [blame] | 2700 | |
Philip Withnall | becb77e | 2013-11-25 18:01:30 +0000 | [diff] [blame] | 2701 | reset_surface_type(shsurf); |
Kristian Høgsberg | 7f366e7 | 2012-04-27 17:20:01 -0400 | [diff] [blame] | 2702 | |
Rafael Antognolli | 03b1659 | 2013-12-03 15:35:42 -0200 | [diff] [blame] | 2703 | shsurf->state = shsurf->next_state; |
Rafael Antognolli | 03b1659 | 2013-12-03 15:35:42 -0200 | [diff] [blame] | 2704 | shsurf->state_changed = false; |
Kristian Høgsberg | 7f366e7 | 2012-04-27 17:20:01 -0400 | [diff] [blame] | 2705 | |
| 2706 | switch (shsurf->type) { |
| 2707 | case SHELL_SURFACE_TOPLEVEL: |
Rafael Antognolli | ed207b4 | 2013-12-03 15:35:43 -0200 | [diff] [blame] | 2708 | if (shsurf->state.maximized || shsurf->state.fullscreen) { |
Rafael Antognolli | 03b1659 | 2013-12-03 15:35:42 -0200 | [diff] [blame] | 2709 | set_full_output(shsurf); |
Rafael Antognolli | ed207b4 | 2013-12-03 15:35:43 -0200 | [diff] [blame] | 2710 | } else if (shsurf->state.relative && pev) { |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 2711 | weston_view_set_position(shsurf->view, |
| 2712 | pev->geometry.x + shsurf->transient.x, |
| 2713 | pev->geometry.y + shsurf->transient.y); |
Rafael Antognolli | ed207b4 | 2013-12-03 15:35:43 -0200 | [diff] [blame] | 2714 | } |
Rafael Antognolli | 44a3162 | 2013-12-04 18:37:16 -0200 | [diff] [blame] | 2715 | break; |
Kristian Høgsberg | 7f366e7 | 2012-04-27 17:20:01 -0400 | [diff] [blame] | 2716 | |
Tiago Vignatti | fb2adba | 2013-06-12 15:43:21 -0300 | [diff] [blame] | 2717 | case SHELL_SURFACE_XWAYLAND: |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 2718 | weston_view_set_position(shsurf->view, shsurf->transient.x, |
| 2719 | shsurf->transient.y); |
Tiago Vignatti | fb2adba | 2013-06-12 15:43:21 -0300 | [diff] [blame] | 2720 | break; |
| 2721 | |
Philip Withnall | 0f640e2 | 2013-11-25 18:01:31 +0000 | [diff] [blame] | 2722 | case SHELL_SURFACE_POPUP: |
| 2723 | case SHELL_SURFACE_NONE: |
Kristian Høgsberg | 7f366e7 | 2012-04-27 17:20:01 -0400 | [diff] [blame] | 2724 | default: |
| 2725 | break; |
| 2726 | } |
Philip Withnall | e1d75ae | 2013-11-25 18:01:41 +0000 | [diff] [blame] | 2727 | |
| 2728 | /* Update the surface’s layer. */ |
| 2729 | shell_surface_update_layer(shsurf); |
Kristian Høgsberg | 7f366e7 | 2012-04-27 17:20:01 -0400 | [diff] [blame] | 2730 | } |
| 2731 | |
Tiago Vignatti | be14326 | 2012-04-16 17:31:41 +0300 | [diff] [blame] | 2732 | static struct desktop_shell * |
Juan Zhao | 96879df | 2012-02-07 08:45:41 +0800 | [diff] [blame] | 2733 | shell_surface_get_shell(struct shell_surface *shsurf) |
Pekka Paalanen | af0e34c | 2011-12-02 10:59:17 +0200 | [diff] [blame] | 2734 | { |
Kristian Høgsberg | 02e79dc | 2012-04-12 09:55:26 -0400 | [diff] [blame] | 2735 | return shsurf->shell; |
Juan Zhao | 96879df | 2012-02-07 08:45:41 +0800 | [diff] [blame] | 2736 | } |
| 2737 | |
Pekka Paalanen | 8274d90 | 2014-08-06 19:36:51 +0300 | [diff] [blame] | 2738 | static int |
| 2739 | black_surface_get_label(struct weston_surface *surface, char *buf, size_t len) |
| 2740 | { |
| 2741 | struct weston_surface *fs_surface = surface->configure_private; |
| 2742 | int n; |
| 2743 | int rem; |
| 2744 | int ret; |
| 2745 | |
| 2746 | n = snprintf(buf, len, "black background surface for "); |
| 2747 | if (n < 0) |
| 2748 | return n; |
| 2749 | |
| 2750 | rem = (int)len - n; |
| 2751 | if (rem < 0) |
| 2752 | rem = 0; |
| 2753 | |
| 2754 | if (fs_surface->get_label) |
| 2755 | ret = fs_surface->get_label(fs_surface, buf + n, rem); |
| 2756 | else |
| 2757 | ret = snprintf(buf + n, rem, "<unknown>"); |
| 2758 | |
| 2759 | if (ret < 0) |
| 2760 | return n; |
| 2761 | |
| 2762 | return n + ret; |
| 2763 | } |
| 2764 | |
Alex Wu | 2185843 | 2012-04-01 20:13:08 +0800 | [diff] [blame] | 2765 | static void |
Jason Ekstrand | 918f2dd | 2013-12-02 21:01:53 -0600 | [diff] [blame] | 2766 | 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] | 2767 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 2768 | static struct weston_view * |
Alex Wu | 4539b08 | 2012-03-01 12:57:46 +0800 | [diff] [blame] | 2769 | create_black_surface(struct weston_compositor *ec, |
Alex Wu | 2185843 | 2012-04-01 20:13:08 +0800 | [diff] [blame] | 2770 | struct weston_surface *fs_surface, |
John Kåre Alsaker | 490d02a | 2012-09-30 02:57:21 +0200 | [diff] [blame] | 2771 | float x, float y, int w, int h) |
Alex Wu | 4539b08 | 2012-03-01 12:57:46 +0800 | [diff] [blame] | 2772 | { |
| 2773 | struct weston_surface *surface = NULL; |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 2774 | struct weston_view *view; |
Alex Wu | 4539b08 | 2012-03-01 12:57:46 +0800 | [diff] [blame] | 2775 | |
| 2776 | surface = weston_surface_create(ec); |
| 2777 | if (surface == NULL) { |
Martin Minarik | 6d11836 | 2012-06-07 18:01:59 +0200 | [diff] [blame] | 2778 | weston_log("no memory\n"); |
Alex Wu | 4539b08 | 2012-03-01 12:57:46 +0800 | [diff] [blame] | 2779 | return NULL; |
| 2780 | } |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 2781 | view = weston_view_create(surface); |
| 2782 | if (surface == NULL) { |
| 2783 | weston_log("no memory\n"); |
| 2784 | weston_surface_destroy(surface); |
| 2785 | return NULL; |
| 2786 | } |
Alex Wu | 4539b08 | 2012-03-01 12:57:46 +0800 | [diff] [blame] | 2787 | |
Alex Wu | 2185843 | 2012-04-01 20:13:08 +0800 | [diff] [blame] | 2788 | surface->configure = black_surface_configure; |
Giulio Camuffo | 7fe01b1 | 2013-03-28 18:02:42 +0100 | [diff] [blame] | 2789 | surface->configure_private = fs_surface; |
Pekka Paalanen | 8274d90 | 2014-08-06 19:36:51 +0300 | [diff] [blame] | 2790 | weston_surface_set_label_func(surface, black_surface_get_label); |
Alex Wu | 4539b08 | 2012-03-01 12:57:46 +0800 | [diff] [blame] | 2791 | weston_surface_set_color(surface, 0.0, 0.0, 0.0, 1); |
Pekka Paalanen | 71f6f3b | 2012-10-10 12:49:26 +0300 | [diff] [blame] | 2792 | pixman_region32_fini(&surface->opaque); |
Kristian Høgsberg | 61f00f5 | 2012-08-03 16:31:36 -0400 | [diff] [blame] | 2793 | pixman_region32_init_rect(&surface->opaque, 0, 0, w, h); |
Jonas Ådahl | 33619a4 | 2013-01-15 21:25:55 +0100 | [diff] [blame] | 2794 | pixman_region32_fini(&surface->input); |
| 2795 | pixman_region32_init_rect(&surface->input, 0, 0, w, h); |
Jason Ekstrand | 918f2dd | 2013-12-02 21:01:53 -0600 | [diff] [blame] | 2796 | |
Jason Ekstrand | 6228ee2 | 2014-01-01 15:58:57 -0600 | [diff] [blame] | 2797 | weston_surface_set_size(surface, w, h); |
Jason Ekstrand | 918f2dd | 2013-12-02 21:01:53 -0600 | [diff] [blame] | 2798 | weston_view_set_position(view, x, y); |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 2799 | |
| 2800 | return view; |
Alex Wu | 4539b08 | 2012-03-01 12:57:46 +0800 | [diff] [blame] | 2801 | } |
| 2802 | |
Philip Withnall | ed8f1a9 | 2013-11-25 18:01:43 +0000 | [diff] [blame] | 2803 | static void |
| 2804 | shell_ensure_fullscreen_black_view(struct shell_surface *shsurf) |
| 2805 | { |
| 2806 | struct weston_output *output = shsurf->fullscreen_output; |
| 2807 | |
Rafael Antognolli | 03b1659 | 2013-12-03 15:35:42 -0200 | [diff] [blame] | 2808 | assert(shsurf->state.fullscreen); |
Philip Withnall | ed8f1a9 | 2013-11-25 18:01:43 +0000 | [diff] [blame] | 2809 | |
| 2810 | if (!shsurf->fullscreen.black_view) |
| 2811 | shsurf->fullscreen.black_view = |
| 2812 | create_black_surface(shsurf->surface->compositor, |
| 2813 | shsurf->surface, |
| 2814 | output->x, output->y, |
| 2815 | output->width, |
| 2816 | output->height); |
| 2817 | |
| 2818 | weston_view_geometry_dirty(shsurf->fullscreen.black_view); |
Giulio Camuffo | 412e6a5 | 2014-07-09 22:12:56 +0300 | [diff] [blame] | 2819 | weston_layer_entry_remove(&shsurf->fullscreen.black_view->layer_link); |
| 2820 | weston_layer_entry_insert(&shsurf->view->layer_link, |
| 2821 | &shsurf->fullscreen.black_view->layer_link); |
Philip Withnall | ed8f1a9 | 2013-11-25 18:01:43 +0000 | [diff] [blame] | 2822 | weston_view_geometry_dirty(shsurf->fullscreen.black_view); |
| 2823 | weston_surface_damage(shsurf->surface); |
Emilio Pozuelo Monfort | 9e7c759 | 2014-01-30 14:01:10 +0100 | [diff] [blame] | 2824 | |
| 2825 | shsurf->state.lowered = false; |
Philip Withnall | ed8f1a9 | 2013-11-25 18:01:43 +0000 | [diff] [blame] | 2826 | } |
| 2827 | |
Alex Wu | 4539b08 | 2012-03-01 12:57:46 +0800 | [diff] [blame] | 2828 | /* Create black surface and append it to the associated fullscreen surface. |
| 2829 | * Handle size dismatch and positioning according to the method. */ |
| 2830 | static void |
| 2831 | shell_configure_fullscreen(struct shell_surface *shsurf) |
| 2832 | { |
| 2833 | struct weston_output *output = shsurf->fullscreen_output; |
| 2834 | struct weston_surface *surface = shsurf->surface; |
| 2835 | struct weston_matrix *matrix; |
Kristian Høgsberg | 240dfeb | 2012-07-12 12:32:31 -0400 | [diff] [blame] | 2836 | float scale, output_aspect, surface_aspect, x, y; |
Giulio Camuffo | b836664 | 2013-04-25 13:57:46 +0300 | [diff] [blame] | 2837 | int32_t surf_x, surf_y, surf_width, surf_height; |
Alex Wu | 4539b08 | 2012-03-01 12:57:46 +0800 | [diff] [blame] | 2838 | |
Alexander Larsson | f82b6ca | 2013-05-28 16:23:39 +0200 | [diff] [blame] | 2839 | if (shsurf->fullscreen.type != WL_SHELL_SURFACE_FULLSCREEN_METHOD_DRIVER) |
| 2840 | restore_output_mode(output); |
| 2841 | |
Emilio Pozuelo Monfort | 9e7c759 | 2014-01-30 14:01:10 +0100 | [diff] [blame] | 2842 | /* Reverse the effect of lower_fullscreen_layer() */ |
Giulio Camuffo | 412e6a5 | 2014-07-09 22:12:56 +0300 | [diff] [blame] | 2843 | weston_layer_entry_remove(&shsurf->view->layer_link); |
| 2844 | 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] | 2845 | |
Philip Withnall | ed8f1a9 | 2013-11-25 18:01:43 +0000 | [diff] [blame] | 2846 | shell_ensure_fullscreen_black_view(shsurf); |
Alex Wu | 4539b08 | 2012-03-01 12:57:46 +0800 | [diff] [blame] | 2847 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 2848 | surface_subsurfaces_boundingbox(shsurf->surface, &surf_x, &surf_y, |
Giulio Camuffo | b836664 | 2013-04-25 13:57:46 +0300 | [diff] [blame] | 2849 | &surf_width, &surf_height); |
| 2850 | |
Alex Wu | 4539b08 | 2012-03-01 12:57:46 +0800 | [diff] [blame] | 2851 | switch (shsurf->fullscreen.type) { |
| 2852 | case WL_SHELL_SURFACE_FULLSCREEN_METHOD_DEFAULT: |
Pekka Paalanen | de685b8 | 2012-12-04 15:58:12 +0200 | [diff] [blame] | 2853 | if (surface->buffer_ref.buffer) |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 2854 | center_on_output(shsurf->view, shsurf->fullscreen_output); |
Alex Wu | 4539b08 | 2012-03-01 12:57:46 +0800 | [diff] [blame] | 2855 | break; |
| 2856 | case WL_SHELL_SURFACE_FULLSCREEN_METHOD_SCALE: |
Rob Bradford | 9f3dd15 | 2013-02-12 11:53:47 +0000 | [diff] [blame] | 2857 | /* 1:1 mapping between surface and output dimensions */ |
Giulio Camuffo | b836664 | 2013-04-25 13:57:46 +0300 | [diff] [blame] | 2858 | if (output->width == surf_width && |
| 2859 | output->height == surf_height) { |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 2860 | weston_view_set_position(shsurf->view, |
| 2861 | output->x - surf_x, |
| 2862 | output->y - surf_y); |
Rob Bradford | 9f3dd15 | 2013-02-12 11:53:47 +0000 | [diff] [blame] | 2863 | break; |
| 2864 | } |
| 2865 | |
Alex Wu | 4539b08 | 2012-03-01 12:57:46 +0800 | [diff] [blame] | 2866 | matrix = &shsurf->fullscreen.transform.matrix; |
| 2867 | weston_matrix_init(matrix); |
Kristian Høgsberg | 240dfeb | 2012-07-12 12:32:31 -0400 | [diff] [blame] | 2868 | |
Scott Moreau | 1bad5db | 2012-08-18 01:04:05 -0600 | [diff] [blame] | 2869 | output_aspect = (float) output->width / |
| 2870 | (float) output->height; |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 2871 | /* XXX: Use surf_width and surf_height here? */ |
| 2872 | surface_aspect = (float) surface->width / |
| 2873 | (float) surface->height; |
Kristian Høgsberg | 240dfeb | 2012-07-12 12:32:31 -0400 | [diff] [blame] | 2874 | if (output_aspect < surface_aspect) |
Scott Moreau | 1bad5db | 2012-08-18 01:04:05 -0600 | [diff] [blame] | 2875 | scale = (float) output->width / |
Giulio Camuffo | b836664 | 2013-04-25 13:57:46 +0300 | [diff] [blame] | 2876 | (float) surf_width; |
Kristian Høgsberg | 240dfeb | 2012-07-12 12:32:31 -0400 | [diff] [blame] | 2877 | else |
Scott Moreau | 1bad5db | 2012-08-18 01:04:05 -0600 | [diff] [blame] | 2878 | scale = (float) output->height / |
Giulio Camuffo | b836664 | 2013-04-25 13:57:46 +0300 | [diff] [blame] | 2879 | (float) surf_height; |
Kristian Høgsberg | 240dfeb | 2012-07-12 12:32:31 -0400 | [diff] [blame] | 2880 | |
Alex Wu | 4539b08 | 2012-03-01 12:57:46 +0800 | [diff] [blame] | 2881 | weston_matrix_scale(matrix, scale, scale, 1); |
| 2882 | wl_list_remove(&shsurf->fullscreen.transform.link); |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 2883 | wl_list_insert(&shsurf->view->geometry.transformation_list, |
Alex Wu | 4539b08 | 2012-03-01 12:57:46 +0800 | [diff] [blame] | 2884 | &shsurf->fullscreen.transform.link); |
Giulio Camuffo | b836664 | 2013-04-25 13:57:46 +0300 | [diff] [blame] | 2885 | x = output->x + (output->width - surf_width * scale) / 2 - surf_x; |
| 2886 | y = output->y + (output->height - surf_height * scale) / 2 - surf_y; |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 2887 | weston_view_set_position(shsurf->view, x, y); |
Kristian Høgsberg | 240dfeb | 2012-07-12 12:32:31 -0400 | [diff] [blame] | 2888 | |
Alex Wu | 4539b08 | 2012-03-01 12:57:46 +0800 | [diff] [blame] | 2889 | break; |
| 2890 | case WL_SHELL_SURFACE_FULLSCREEN_METHOD_DRIVER: |
Alex Wu | bd3354b | 2012-04-17 17:20:49 +0800 | [diff] [blame] | 2891 | if (shell_surface_is_top_fullscreen(shsurf)) { |
Quentin Glidic | c0d79ce | 2013-01-29 14:16:13 +0100 | [diff] [blame] | 2892 | struct weston_mode mode = {0, |
Pekka Paalanen | 952b6c8 | 2014-03-14 14:38:15 +0200 | [diff] [blame] | 2893 | surf_width * surface->buffer_viewport.buffer.scale, |
| 2894 | surf_height * surface->buffer_viewport.buffer.scale, |
Alex Wu | bd3354b | 2012-04-17 17:20:49 +0800 | [diff] [blame] | 2895 | shsurf->fullscreen.framerate}; |
| 2896 | |
Derek Foreman | 6ae7bc9 | 2014-11-04 10:47:33 -0600 | [diff] [blame] | 2897 | if (weston_output_mode_switch_to_temporary(output, &mode, |
| 2898 | surface->buffer_viewport.buffer.scale) == 0) { |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 2899 | weston_view_set_position(shsurf->view, |
| 2900 | output->x - surf_x, |
| 2901 | output->y - surf_y); |
Jason Ekstrand | 918f2dd | 2013-12-02 21:01:53 -0600 | [diff] [blame] | 2902 | shsurf->fullscreen.black_view->surface->width = output->width; |
| 2903 | shsurf->fullscreen.black_view->surface->height = output->height; |
| 2904 | weston_view_set_position(shsurf->fullscreen.black_view, |
| 2905 | output->x - surf_x, |
| 2906 | output->y - surf_y); |
Alex Wu | bd3354b | 2012-04-17 17:20:49 +0800 | [diff] [blame] | 2907 | break; |
Alexander Larsson | d622ed3 | 2013-05-28 16:23:40 +0200 | [diff] [blame] | 2908 | } else { |
Mario Kleiner | 492c12f | 2015-06-21 21:25:12 +0200 | [diff] [blame] | 2909 | weston_log("shell: Can't switch to temporary mode.\n"); |
Alexander Larsson | f82b6ca | 2013-05-28 16:23:39 +0200 | [diff] [blame] | 2910 | restore_output_mode(output); |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 2911 | center_on_output(shsurf->view, output); |
Alexander Larsson | d622ed3 | 2013-05-28 16:23:40 +0200 | [diff] [blame] | 2912 | } |
Alex Wu | bd3354b | 2012-04-17 17:20:49 +0800 | [diff] [blame] | 2913 | } |
Alex Wu | 4539b08 | 2012-03-01 12:57:46 +0800 | [diff] [blame] | 2914 | break; |
| 2915 | case WL_SHELL_SURFACE_FULLSCREEN_METHOD_FILL: |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 2916 | center_on_output(shsurf->view, output); |
Alex Wu | 4539b08 | 2012-03-01 12:57:46 +0800 | [diff] [blame] | 2917 | break; |
| 2918 | default: |
| 2919 | break; |
| 2920 | } |
| 2921 | } |
| 2922 | |
Alex Wu | 4539b08 | 2012-03-01 12:57:46 +0800 | [diff] [blame] | 2923 | static void |
| 2924 | shell_map_fullscreen(struct shell_surface *shsurf) |
| 2925 | { |
Alex Wu | bd3354b | 2012-04-17 17:20:49 +0800 | [diff] [blame] | 2926 | shell_configure_fullscreen(shsurf); |
Alex Wu | 4539b08 | 2012-03-01 12:57:46 +0800 | [diff] [blame] | 2927 | } |
| 2928 | |
Kristian Høgsberg | 7a5c979 | 2011-06-18 06:12:54 -0400 | [diff] [blame] | 2929 | static void |
Tiago Vignatti | fb2adba | 2013-06-12 15:43:21 -0300 | [diff] [blame] | 2930 | set_xwayland(struct shell_surface *shsurf, int x, int y, uint32_t flags) |
| 2931 | { |
| 2932 | /* XXX: using the same fields for transient type */ |
Rafael Antognolli | 03b1659 | 2013-12-03 15:35:42 -0200 | [diff] [blame] | 2933 | surface_clear_next_states(shsurf); |
Tiago Vignatti | fb2adba | 2013-06-12 15:43:21 -0300 | [diff] [blame] | 2934 | shsurf->transient.x = x; |
| 2935 | shsurf->transient.y = y; |
| 2936 | shsurf->transient.flags = flags; |
Philip Withnall | dc4332f | 2013-11-25 18:01:38 +0000 | [diff] [blame] | 2937 | |
| 2938 | shell_surface_set_parent(shsurf, NULL); |
| 2939 | |
Pekka Paalanen | b502654 | 2014-11-12 15:09:24 +0200 | [diff] [blame] | 2940 | set_type(shsurf, SHELL_SURFACE_XWAYLAND); |
Kristian Høgsberg | 8bc525c | 2014-01-01 22:34:49 -0800 | [diff] [blame] | 2941 | shsurf->state_changed = true; |
Tiago Vignatti | fb2adba | 2013-06-12 15:43:21 -0300 | [diff] [blame] | 2942 | } |
| 2943 | |
Kristian Høgsberg | 4779241 | 2014-05-04 13:47:06 -0700 | [diff] [blame] | 2944 | static void |
| 2945 | shell_interface_set_fullscreen(struct shell_surface *shsurf, |
| 2946 | uint32_t method, |
| 2947 | uint32_t framerate, |
| 2948 | struct weston_output *output) |
| 2949 | { |
| 2950 | surface_clear_next_states(shsurf); |
Kristian Høgsberg | 4779241 | 2014-05-04 13:47:06 -0700 | [diff] [blame] | 2951 | shsurf->next_state.fullscreen = true; |
| 2952 | shsurf->state_changed = true; |
Marek Chalupa | e9fe467 | 2014-10-29 13:44:44 +0100 | [diff] [blame] | 2953 | |
| 2954 | set_fullscreen(shsurf, method, framerate, output); |
Kristian Høgsberg | 4779241 | 2014-05-04 13:47:06 -0700 | [diff] [blame] | 2955 | } |
| 2956 | |
Giulio Camuffo | 6b4b241 | 2015-01-29 19:06:49 +0200 | [diff] [blame] | 2957 | static struct weston_output * |
| 2958 | get_focused_output(struct weston_compositor *compositor) |
| 2959 | { |
| 2960 | struct weston_seat *seat; |
| 2961 | struct weston_output *output = NULL; |
| 2962 | |
| 2963 | wl_list_for_each(seat, &compositor->seat_list, link) { |
Derek Foreman | 1281a36 | 2015-07-31 16:55:32 -0500 | [diff] [blame] | 2964 | struct weston_touch *touch = weston_seat_get_touch(seat); |
| 2965 | struct weston_pointer *pointer = weston_seat_get_pointer(seat); |
| 2966 | struct weston_keyboard *keyboard = |
| 2967 | weston_seat_get_keyboard(seat); |
| 2968 | |
Giulio Camuffo | 6b4b241 | 2015-01-29 19:06:49 +0200 | [diff] [blame] | 2969 | /* Priority has touch focus, then pointer and |
| 2970 | * then keyboard focus. We should probably have |
| 2971 | * three for loops and check frist for touch, |
| 2972 | * then for pointer, etc. but unless somebody has some |
| 2973 | * objections, I think this is sufficient. */ |
Derek Foreman | 1281a36 | 2015-07-31 16:55:32 -0500 | [diff] [blame] | 2974 | if (touch && touch->focus) |
| 2975 | output = touch->focus->output; |
| 2976 | else if (pointer && pointer->focus) |
| 2977 | output = pointer->focus->output; |
| 2978 | else if (keyboard && keyboard->focus) |
| 2979 | output = keyboard->focus->output; |
Giulio Camuffo | 6b4b241 | 2015-01-29 19:06:49 +0200 | [diff] [blame] | 2980 | |
| 2981 | if (output) |
| 2982 | break; |
| 2983 | } |
| 2984 | |
| 2985 | return output; |
| 2986 | } |
| 2987 | |
| 2988 | static void |
| 2989 | shell_interface_set_maximized(struct shell_surface *shsurf) |
| 2990 | { |
| 2991 | struct weston_output *output; |
| 2992 | |
| 2993 | surface_clear_next_states(shsurf); |
| 2994 | shsurf->next_state.maximized = true; |
| 2995 | shsurf->state_changed = true; |
| 2996 | shsurf->type = SHELL_SURFACE_TOPLEVEL; |
| 2997 | |
| 2998 | if (!weston_surface_is_mapped(shsurf->surface)) |
| 2999 | output = get_focused_output(shsurf->surface->compositor); |
| 3000 | else |
| 3001 | output = shsurf->surface->output; |
| 3002 | |
| 3003 | shell_surface_set_output(shsurf, output); |
| 3004 | send_configure_for_surface(shsurf); |
| 3005 | } |
| 3006 | |
Kristian Høgsberg | ae356ae | 2014-04-29 16:03:54 -0700 | [diff] [blame] | 3007 | static int |
Derek Foreman | e4d6c83 | 2015-08-05 14:48:11 -0500 | [diff] [blame] | 3008 | shell_interface_move(struct shell_surface *shsurf, struct weston_pointer *pointer) |
Kristian Høgsberg | ae356ae | 2014-04-29 16:03:54 -0700 | [diff] [blame] | 3009 | { |
Derek Foreman | e4d6c83 | 2015-08-05 14:48:11 -0500 | [diff] [blame] | 3010 | return surface_move(shsurf, pointer, true); |
Kristian Høgsberg | ae356ae | 2014-04-29 16:03:54 -0700 | [diff] [blame] | 3011 | } |
| 3012 | |
Derek Foreman | 8fbebbd | 2015-07-15 13:00:40 -0500 | [diff] [blame] | 3013 | static int |
| 3014 | shell_interface_resize(struct shell_surface *shsurf, |
Derek Foreman | e4d6c83 | 2015-08-05 14:48:11 -0500 | [diff] [blame] | 3015 | struct weston_pointer *pointer, |
Derek Foreman | 8fbebbd | 2015-07-15 13:00:40 -0500 | [diff] [blame] | 3016 | uint32_t edges) |
| 3017 | { |
Derek Foreman | e4d6c83 | 2015-08-05 14:48:11 -0500 | [diff] [blame] | 3018 | return surface_resize(shsurf, pointer, edges); |
Derek Foreman | 8fbebbd | 2015-07-15 13:00:40 -0500 | [diff] [blame] | 3019 | } |
| 3020 | |
Kristian Høgsberg | 02bbabb | 2013-05-06 22:15:05 -0400 | [diff] [blame] | 3021 | static const struct weston_pointer_grab_interface popup_grab_interface; |
Giulio Camuffo | 5085a75 | 2013-03-25 21:42:45 +0100 | [diff] [blame] | 3022 | |
| 3023 | static void |
| 3024 | destroy_shell_seat(struct wl_listener *listener, void *data) |
| 3025 | { |
| 3026 | struct shell_seat *shseat = |
| 3027 | container_of(listener, |
| 3028 | struct shell_seat, seat_destroy_listener); |
Jonas Ådahl | c2b1011 | 2015-02-13 14:01:53 +0800 | [diff] [blame] | 3029 | struct shell_surface *shsurf, *next; |
Giulio Camuffo | 5085a75 | 2013-03-25 21:42:45 +0100 | [diff] [blame] | 3030 | |
| 3031 | if (shseat->popup_grab.grab.interface == &popup_grab_interface) { |
Kristian Høgsberg | 02bbabb | 2013-05-06 22:15:05 -0400 | [diff] [blame] | 3032 | weston_pointer_end_grab(shseat->popup_grab.grab.pointer); |
Giulio Camuffo | 5085a75 | 2013-03-25 21:42:45 +0100 | [diff] [blame] | 3033 | shseat->popup_grab.client = NULL; |
| 3034 | |
Jonas Ådahl | c2b1011 | 2015-02-13 14:01:53 +0800 | [diff] [blame] | 3035 | wl_list_for_each_safe(shsurf, next, |
| 3036 | &shseat->popup_grab.surfaces_list, |
| 3037 | popup.grab_link) { |
Giulio Camuffo | 5085a75 | 2013-03-25 21:42:45 +0100 | [diff] [blame] | 3038 | shsurf->popup.shseat = NULL; |
Jonas Ådahl | c2b1011 | 2015-02-13 14:01:53 +0800 | [diff] [blame] | 3039 | wl_list_init(&shsurf->popup.grab_link); |
Giulio Camuffo | 5085a75 | 2013-03-25 21:42:45 +0100 | [diff] [blame] | 3040 | } |
Giulio Camuffo | 5085a75 | 2013-03-25 21:42:45 +0100 | [diff] [blame] | 3041 | } |
| 3042 | |
| 3043 | wl_list_remove(&shseat->seat_destroy_listener.link); |
| 3044 | free(shseat); |
| 3045 | } |
| 3046 | |
Jason Ekstrand | 024177c | 2014-04-21 19:42:58 -0500 | [diff] [blame] | 3047 | static void |
| 3048 | shell_seat_caps_changed(struct wl_listener *listener, void *data) |
| 3049 | { |
Derek Foreman | 1281a36 | 2015-07-31 16:55:32 -0500 | [diff] [blame] | 3050 | struct weston_keyboard *keyboard; |
| 3051 | struct weston_pointer *pointer; |
Jason Ekstrand | 024177c | 2014-04-21 19:42:58 -0500 | [diff] [blame] | 3052 | struct shell_seat *seat; |
| 3053 | |
| 3054 | seat = container_of(listener, struct shell_seat, caps_changed_listener); |
Derek Foreman | 1281a36 | 2015-07-31 16:55:32 -0500 | [diff] [blame] | 3055 | keyboard = weston_seat_get_keyboard(seat->seat); |
| 3056 | pointer = weston_seat_get_pointer(seat->seat); |
Jason Ekstrand | 024177c | 2014-04-21 19:42:58 -0500 | [diff] [blame] | 3057 | |
Derek Foreman | 1281a36 | 2015-07-31 16:55:32 -0500 | [diff] [blame] | 3058 | if (keyboard && |
Jason Ekstrand | 024177c | 2014-04-21 19:42:58 -0500 | [diff] [blame] | 3059 | wl_list_empty(&seat->keyboard_focus_listener.link)) { |
Derek Foreman | 1281a36 | 2015-07-31 16:55:32 -0500 | [diff] [blame] | 3060 | wl_signal_add(&keyboard->focus_signal, |
Jason Ekstrand | 024177c | 2014-04-21 19:42:58 -0500 | [diff] [blame] | 3061 | &seat->keyboard_focus_listener); |
Derek Foreman | 1281a36 | 2015-07-31 16:55:32 -0500 | [diff] [blame] | 3062 | } else if (!keyboard) { |
Derek Foreman | 60d9731 | 2015-07-15 13:00:45 -0500 | [diff] [blame] | 3063 | wl_list_remove(&seat->keyboard_focus_listener.link); |
Jason Ekstrand | 024177c | 2014-04-21 19:42:58 -0500 | [diff] [blame] | 3064 | wl_list_init(&seat->keyboard_focus_listener.link); |
| 3065 | } |
| 3066 | |
Derek Foreman | 1281a36 | 2015-07-31 16:55:32 -0500 | [diff] [blame] | 3067 | if (pointer && |
Jason Ekstrand | 024177c | 2014-04-21 19:42:58 -0500 | [diff] [blame] | 3068 | wl_list_empty(&seat->pointer_focus_listener.link)) { |
Derek Foreman | 1281a36 | 2015-07-31 16:55:32 -0500 | [diff] [blame] | 3069 | wl_signal_add(&pointer->focus_signal, |
Jason Ekstrand | 024177c | 2014-04-21 19:42:58 -0500 | [diff] [blame] | 3070 | &seat->pointer_focus_listener); |
Derek Foreman | 1281a36 | 2015-07-31 16:55:32 -0500 | [diff] [blame] | 3071 | } else if (!pointer) { |
Derek Foreman | 60d9731 | 2015-07-15 13:00:45 -0500 | [diff] [blame] | 3072 | wl_list_remove(&seat->pointer_focus_listener.link); |
Jason Ekstrand | 024177c | 2014-04-21 19:42:58 -0500 | [diff] [blame] | 3073 | wl_list_init(&seat->pointer_focus_listener.link); |
| 3074 | } |
| 3075 | } |
| 3076 | |
Giulio Camuffo | 5085a75 | 2013-03-25 21:42:45 +0100 | [diff] [blame] | 3077 | static struct shell_seat * |
| 3078 | create_shell_seat(struct weston_seat *seat) |
| 3079 | { |
| 3080 | struct shell_seat *shseat; |
| 3081 | |
| 3082 | shseat = calloc(1, sizeof *shseat); |
| 3083 | if (!shseat) { |
| 3084 | weston_log("no memory to allocate shell seat\n"); |
| 3085 | return NULL; |
| 3086 | } |
| 3087 | |
| 3088 | shseat->seat = seat; |
| 3089 | wl_list_init(&shseat->popup_grab.surfaces_list); |
| 3090 | |
| 3091 | shseat->seat_destroy_listener.notify = destroy_shell_seat; |
| 3092 | wl_signal_add(&seat->destroy_signal, |
| 3093 | &shseat->seat_destroy_listener); |
| 3094 | |
Jason Ekstrand | 024177c | 2014-04-21 19:42:58 -0500 | [diff] [blame] | 3095 | shseat->keyboard_focus_listener.notify = handle_keyboard_focus; |
| 3096 | wl_list_init(&shseat->keyboard_focus_listener.link); |
| 3097 | |
| 3098 | shseat->pointer_focus_listener.notify = handle_pointer_focus; |
| 3099 | wl_list_init(&shseat->pointer_focus_listener.link); |
| 3100 | |
| 3101 | shseat->caps_changed_listener.notify = shell_seat_caps_changed; |
| 3102 | wl_signal_add(&seat->updated_caps_signal, |
| 3103 | &shseat->caps_changed_listener); |
| 3104 | shell_seat_caps_changed(&shseat->caps_changed_listener, NULL); |
| 3105 | |
Giulio Camuffo | 5085a75 | 2013-03-25 21:42:45 +0100 | [diff] [blame] | 3106 | return shseat; |
| 3107 | } |
| 3108 | |
| 3109 | static struct shell_seat * |
| 3110 | get_shell_seat(struct weston_seat *seat) |
| 3111 | { |
| 3112 | struct wl_listener *listener; |
| 3113 | |
| 3114 | listener = wl_signal_get(&seat->destroy_signal, destroy_shell_seat); |
Jason Ekstrand | 024177c | 2014-04-21 19:42:58 -0500 | [diff] [blame] | 3115 | assert(listener != NULL); |
Giulio Camuffo | 5085a75 | 2013-03-25 21:42:45 +0100 | [diff] [blame] | 3116 | |
| 3117 | return container_of(listener, |
| 3118 | struct shell_seat, seat_destroy_listener); |
| 3119 | } |
| 3120 | |
Kristian Høgsberg | b810eb5 | 2013-02-12 20:07:05 -0500 | [diff] [blame] | 3121 | static void |
Kristian Høgsberg | 6848c25 | 2013-05-08 22:02:59 -0400 | [diff] [blame] | 3122 | popup_grab_focus(struct weston_pointer_grab *grab) |
Kristian Høgsberg | b3cca0a | 2012-01-04 22:19:14 -0500 | [diff] [blame] | 3123 | { |
Kristian Høgsberg | 02bbabb | 2013-05-06 22:15:05 -0400 | [diff] [blame] | 3124 | struct weston_pointer *pointer = grab->pointer; |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 3125 | struct weston_view *view; |
Giulio Camuffo | 5085a75 | 2013-03-25 21:42:45 +0100 | [diff] [blame] | 3126 | struct shell_seat *shseat = |
| 3127 | container_of(grab, struct shell_seat, popup_grab.grab); |
| 3128 | struct wl_client *client = shseat->popup_grab.client; |
Kristian Høgsberg | 6848c25 | 2013-05-08 22:02:59 -0400 | [diff] [blame] | 3129 | wl_fixed_t sx, sy; |
| 3130 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 3131 | view = weston_compositor_pick_view(pointer->seat->compositor, |
| 3132 | pointer->x, pointer->y, |
| 3133 | &sx, &sy); |
Kristian Høgsberg | b3cca0a | 2012-01-04 22:19:14 -0500 | [diff] [blame] | 3134 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 3135 | if (view && view->surface->resource && |
| 3136 | wl_resource_get_client(view->surface->resource) == client) { |
| 3137 | weston_pointer_set_focus(pointer, view, sx, sy); |
Kristian Høgsberg | b3cca0a | 2012-01-04 22:19:14 -0500 | [diff] [blame] | 3138 | } else { |
Derek Foreman | f9318d1 | 2015-05-11 15:40:11 -0500 | [diff] [blame] | 3139 | weston_pointer_clear_focus(pointer); |
Kristian Høgsberg | b3cca0a | 2012-01-04 22:19:14 -0500 | [diff] [blame] | 3140 | } |
| 3141 | } |
| 3142 | |
| 3143 | static void |
Giulio Camuffo | 1959ab8 | 2013-11-14 23:42:52 +0100 | [diff] [blame] | 3144 | popup_grab_motion(struct weston_pointer_grab *grab, uint32_t time, |
Jonas Ådahl | d251010 | 2014-10-05 21:39:14 +0200 | [diff] [blame] | 3145 | struct weston_pointer_motion_event *event) |
Kristian Høgsberg | b3cca0a | 2012-01-04 22:19:14 -0500 | [diff] [blame] | 3146 | { |
Kristian Høgsberg | be6403e | 2013-05-08 21:03:21 -0400 | [diff] [blame] | 3147 | struct weston_pointer *pointer = grab->pointer; |
Neil Roberts | 96d790e | 2013-09-19 17:32:00 +0100 | [diff] [blame] | 3148 | struct wl_resource *resource; |
Jonas Ådahl | 2cbf293 | 2015-07-22 12:05:38 +0800 | [diff] [blame] | 3149 | struct wl_list *resource_list; |
Jonas Ådahl | d251010 | 2014-10-05 21:39:14 +0200 | [diff] [blame] | 3150 | wl_fixed_t x, y; |
Kristian Høgsberg | be6403e | 2013-05-08 21:03:21 -0400 | [diff] [blame] | 3151 | wl_fixed_t sx, sy; |
Kristian Høgsberg | b3cca0a | 2012-01-04 22:19:14 -0500 | [diff] [blame] | 3152 | |
Jonas Ådahl | 61917c8 | 2014-08-11 22:44:02 +0200 | [diff] [blame] | 3153 | if (pointer->focus) { |
Jonas Ådahl | d251010 | 2014-10-05 21:39:14 +0200 | [diff] [blame] | 3154 | weston_pointer_motion_to_abs(pointer, event, &x, &y); |
Jonas Ådahl | 61917c8 | 2014-08-11 22:44:02 +0200 | [diff] [blame] | 3155 | weston_view_from_global_fixed(pointer->focus, x, y, |
| 3156 | &pointer->sx, &pointer->sy); |
| 3157 | } |
| 3158 | |
Jonas Ådahl | d251010 | 2014-10-05 21:39:14 +0200 | [diff] [blame] | 3159 | weston_pointer_move(pointer, event); |
Giulio Camuffo | 1959ab8 | 2013-11-14 23:42:52 +0100 | [diff] [blame] | 3160 | |
Jonas Ådahl | 2cbf293 | 2015-07-22 12:05:38 +0800 | [diff] [blame] | 3161 | if (!pointer->focus_client) |
| 3162 | return; |
| 3163 | |
| 3164 | resource_list = &pointer->focus_client->pointer_resources; |
| 3165 | wl_resource_for_each(resource, resource_list) { |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 3166 | weston_view_from_global_fixed(pointer->focus, |
| 3167 | pointer->x, pointer->y, |
| 3168 | &sx, &sy); |
Neil Roberts | 96d790e | 2013-09-19 17:32:00 +0100 | [diff] [blame] | 3169 | wl_pointer_send_motion(resource, time, sx, sy); |
Kristian Høgsberg | be6403e | 2013-05-08 21:03:21 -0400 | [diff] [blame] | 3170 | } |
Kristian Høgsberg | b3cca0a | 2012-01-04 22:19:14 -0500 | [diff] [blame] | 3171 | } |
| 3172 | |
| 3173 | static void |
Kristian Høgsberg | 02bbabb | 2013-05-06 22:15:05 -0400 | [diff] [blame] | 3174 | popup_grab_button(struct weston_pointer_grab *grab, |
Daniel Stone | 4dbadb1 | 2012-05-30 16:31:51 +0100 | [diff] [blame] | 3175 | uint32_t time, uint32_t button, uint32_t state_w) |
Kristian Høgsberg | b3cca0a | 2012-01-04 22:19:14 -0500 | [diff] [blame] | 3176 | { |
| 3177 | struct wl_resource *resource; |
Giulio Camuffo | 5085a75 | 2013-03-25 21:42:45 +0100 | [diff] [blame] | 3178 | struct shell_seat *shseat = |
| 3179 | container_of(grab, struct shell_seat, popup_grab.grab); |
Rob Bradford | 880ebc7 | 2013-07-22 17:31:38 +0100 | [diff] [blame] | 3180 | struct wl_display *display = shseat->seat->compositor->wl_display; |
Daniel Stone | 4dbadb1 | 2012-05-30 16:31:51 +0100 | [diff] [blame] | 3181 | enum wl_pointer_button_state state = state_w; |
Kristian Høgsberg | eae5de7 | 2012-04-11 22:42:15 -0400 | [diff] [blame] | 3182 | uint32_t serial; |
Jonas Ådahl | 2cbf293 | 2015-07-22 12:05:38 +0800 | [diff] [blame] | 3183 | struct wl_list *resource_list = NULL; |
Kristian Høgsberg | b3cca0a | 2012-01-04 22:19:14 -0500 | [diff] [blame] | 3184 | |
Jonas Ådahl | 2cbf293 | 2015-07-22 12:05:38 +0800 | [diff] [blame] | 3185 | if (grab->pointer->focus_client) |
| 3186 | resource_list = &grab->pointer->focus_client->pointer_resources; |
| 3187 | if (resource_list && !wl_list_empty(resource_list)) { |
Kristian Høgsberg | eae5de7 | 2012-04-11 22:42:15 -0400 | [diff] [blame] | 3188 | serial = wl_display_get_serial(display); |
Neil Roberts | 96d790e | 2013-09-19 17:32:00 +0100 | [diff] [blame] | 3189 | wl_resource_for_each(resource, resource_list) { |
| 3190 | wl_pointer_send_button(resource, serial, |
| 3191 | time, button, state); |
| 3192 | } |
Daniel Stone | 4dbadb1 | 2012-05-30 16:31:51 +0100 | [diff] [blame] | 3193 | } else if (state == WL_POINTER_BUTTON_STATE_RELEASED && |
Giulio Camuffo | 5085a75 | 2013-03-25 21:42:45 +0100 | [diff] [blame] | 3194 | (shseat->popup_grab.initial_up || |
Derek Foreman | f7b2f8b | 2015-07-15 13:00:41 -0500 | [diff] [blame] | 3195 | time - grab->pointer->grab_time > 500)) { |
Kristian Høgsberg | 57e0907 | 2012-10-30 14:07:27 -0400 | [diff] [blame] | 3196 | popup_grab_end(grab->pointer); |
Kristian Høgsberg | b3cca0a | 2012-01-04 22:19:14 -0500 | [diff] [blame] | 3197 | } |
| 3198 | |
Daniel Stone | 4dbadb1 | 2012-05-30 16:31:51 +0100 | [diff] [blame] | 3199 | 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 = 1; |
Kristian Høgsberg | b3cca0a | 2012-01-04 22:19:14 -0500 | [diff] [blame] | 3201 | } |
| 3202 | |
Jonas Ådahl | 1ea343e | 2013-10-25 23:18:05 +0200 | [diff] [blame] | 3203 | static void |
Jonas Ådahl | 0336ca0 | 2014-10-04 16:28:29 +0200 | [diff] [blame] | 3204 | popup_grab_axis(struct weston_pointer_grab *grab, |
| 3205 | uint32_t time, uint32_t axis, wl_fixed_t value) |
| 3206 | { |
Peter Hutterer | 1118952 | 2015-11-16 12:35:57 +1000 | [diff] [blame] | 3207 | weston_pointer_send_axis(grab->pointer, time, axis, value); |
Jonas Ådahl | 0336ca0 | 2014-10-04 16:28:29 +0200 | [diff] [blame] | 3208 | } |
| 3209 | |
| 3210 | static void |
Jonas Ådahl | 1ea343e | 2013-10-25 23:18:05 +0200 | [diff] [blame] | 3211 | popup_grab_cancel(struct weston_pointer_grab *grab) |
| 3212 | { |
| 3213 | popup_grab_end(grab->pointer); |
| 3214 | } |
| 3215 | |
Kristian Høgsberg | 02bbabb | 2013-05-06 22:15:05 -0400 | [diff] [blame] | 3216 | static const struct weston_pointer_grab_interface popup_grab_interface = { |
Kristian Høgsberg | b3cca0a | 2012-01-04 22:19:14 -0500 | [diff] [blame] | 3217 | popup_grab_focus, |
| 3218 | popup_grab_motion, |
| 3219 | popup_grab_button, |
Jonas Ådahl | 0336ca0 | 2014-10-04 16:28:29 +0200 | [diff] [blame] | 3220 | popup_grab_axis, |
Jonas Ådahl | 1ea343e | 2013-10-25 23:18:05 +0200 | [diff] [blame] | 3221 | popup_grab_cancel, |
Kristian Høgsberg | b3cca0a | 2012-01-04 22:19:14 -0500 | [diff] [blame] | 3222 | }; |
| 3223 | |
| 3224 | static void |
Jonny Lamb | 76cf1fe | 2014-08-20 11:27:10 +0200 | [diff] [blame] | 3225 | touch_popup_grab_down(struct weston_touch_grab *grab, uint32_t time, |
Giulio Camuffo | 61ed7b6 | 2015-07-08 11:55:28 +0300 | [diff] [blame] | 3226 | int touch_id, wl_fixed_t x, wl_fixed_t y) |
Jonny Lamb | 76cf1fe | 2014-08-20 11:27:10 +0200 | [diff] [blame] | 3227 | { |
| 3228 | struct wl_resource *resource; |
| 3229 | struct shell_seat *shseat = |
| 3230 | container_of(grab, struct shell_seat, popup_grab.touch_grab); |
| 3231 | struct wl_display *display = shseat->seat->compositor->wl_display; |
| 3232 | uint32_t serial; |
| 3233 | struct wl_list *resource_list; |
Giulio Camuffo | 61ed7b6 | 2015-07-08 11:55:28 +0300 | [diff] [blame] | 3234 | wl_fixed_t sx, sy; |
| 3235 | |
| 3236 | weston_view_from_global_fixed(grab->touch->focus, x, y, &sx, &sy); |
Jonny Lamb | 76cf1fe | 2014-08-20 11:27:10 +0200 | [diff] [blame] | 3237 | |
| 3238 | resource_list = &grab->touch->focus_resource_list; |
| 3239 | if (!wl_list_empty(resource_list)) { |
| 3240 | serial = wl_display_get_serial(display); |
| 3241 | wl_resource_for_each(resource, resource_list) { |
| 3242 | wl_touch_send_down(resource, serial, time, |
| 3243 | grab->touch->focus->surface->resource, |
| 3244 | touch_id, sx, sy); |
| 3245 | } |
| 3246 | } |
| 3247 | } |
| 3248 | |
| 3249 | static void |
| 3250 | touch_popup_grab_up(struct weston_touch_grab *grab, uint32_t time, int touch_id) |
| 3251 | { |
| 3252 | struct wl_resource *resource; |
| 3253 | struct shell_seat *shseat = |
| 3254 | container_of(grab, struct shell_seat, popup_grab.touch_grab); |
| 3255 | struct wl_display *display = shseat->seat->compositor->wl_display; |
| 3256 | uint32_t serial; |
| 3257 | struct wl_list *resource_list; |
| 3258 | |
| 3259 | resource_list = &grab->touch->focus_resource_list; |
| 3260 | if (!wl_list_empty(resource_list)) { |
| 3261 | serial = wl_display_get_serial(display); |
| 3262 | wl_resource_for_each(resource, resource_list) { |
| 3263 | wl_touch_send_up(resource, serial, time, touch_id); |
| 3264 | } |
| 3265 | } |
| 3266 | } |
| 3267 | |
| 3268 | static void |
| 3269 | touch_popup_grab_motion(struct weston_touch_grab *grab, uint32_t time, |
Giulio Camuffo | 61ed7b6 | 2015-07-08 11:55:28 +0300 | [diff] [blame] | 3270 | int touch_id, wl_fixed_t x, wl_fixed_t y) |
Jonny Lamb | 76cf1fe | 2014-08-20 11:27:10 +0200 | [diff] [blame] | 3271 | { |
| 3272 | struct wl_resource *resource; |
| 3273 | struct wl_list *resource_list; |
Giulio Camuffo | 61ed7b6 | 2015-07-08 11:55:28 +0300 | [diff] [blame] | 3274 | wl_fixed_t sx, sy; |
| 3275 | |
| 3276 | weston_view_from_global_fixed(grab->touch->focus, x, y, &sx, &sy); |
Jonny Lamb | 76cf1fe | 2014-08-20 11:27:10 +0200 | [diff] [blame] | 3277 | |
| 3278 | resource_list = &grab->touch->focus_resource_list; |
| 3279 | if (!wl_list_empty(resource_list)) { |
| 3280 | wl_resource_for_each(resource, resource_list) { |
| 3281 | wl_touch_send_motion(resource, time, touch_id, sx, sy); |
| 3282 | } |
| 3283 | } |
| 3284 | } |
| 3285 | |
| 3286 | static void |
| 3287 | touch_popup_grab_frame(struct weston_touch_grab *grab) |
| 3288 | { |
| 3289 | } |
| 3290 | |
| 3291 | static void |
| 3292 | touch_popup_grab_cancel(struct weston_touch_grab *grab) |
| 3293 | { |
| 3294 | touch_popup_grab_end(grab->touch); |
| 3295 | } |
| 3296 | |
| 3297 | static const struct weston_touch_grab_interface touch_popup_grab_interface = { |
| 3298 | touch_popup_grab_down, |
| 3299 | touch_popup_grab_up, |
| 3300 | touch_popup_grab_motion, |
| 3301 | touch_popup_grab_frame, |
| 3302 | touch_popup_grab_cancel, |
| 3303 | }; |
| 3304 | |
| 3305 | static void |
Rafael Antognolli | e2a3455 | 2013-12-03 15:35:45 -0200 | [diff] [blame] | 3306 | shell_surface_send_popup_done(struct shell_surface *shsurf) |
| 3307 | { |
| 3308 | if (shell_surface_is_wl_shell_surface(shsurf)) |
| 3309 | wl_shell_surface_send_popup_done(shsurf->resource); |
| 3310 | else if (shell_surface_is_xdg_popup(shsurf)) |
Jasper St. Pierre | ecf2a0f | 2015-02-13 14:01:56 +0800 | [diff] [blame] | 3311 | xdg_popup_send_popup_done(shsurf->resource); |
Rafael Antognolli | e2a3455 | 2013-12-03 15:35:45 -0200 | [diff] [blame] | 3312 | } |
| 3313 | |
| 3314 | static void |
Kristian Høgsberg | 02bbabb | 2013-05-06 22:15:05 -0400 | [diff] [blame] | 3315 | popup_grab_end(struct weston_pointer *pointer) |
Kristian Høgsberg | 57e0907 | 2012-10-30 14:07:27 -0400 | [diff] [blame] | 3316 | { |
Kristian Høgsberg | 02bbabb | 2013-05-06 22:15:05 -0400 | [diff] [blame] | 3317 | struct weston_pointer_grab *grab = pointer->grab; |
Giulio Camuffo | 5085a75 | 2013-03-25 21:42:45 +0100 | [diff] [blame] | 3318 | struct shell_seat *shseat = |
| 3319 | container_of(grab, struct shell_seat, popup_grab.grab); |
| 3320 | struct shell_surface *shsurf; |
Jonas Ådahl | c2b1011 | 2015-02-13 14:01:53 +0800 | [diff] [blame] | 3321 | struct shell_surface *next; |
Kristian Høgsberg | 57e0907 | 2012-10-30 14:07:27 -0400 | [diff] [blame] | 3322 | |
| 3323 | if (pointer->grab->interface == &popup_grab_interface) { |
Kristian Høgsberg | 02bbabb | 2013-05-06 22:15:05 -0400 | [diff] [blame] | 3324 | weston_pointer_end_grab(grab->pointer); |
Giulio Camuffo | 5085a75 | 2013-03-25 21:42:45 +0100 | [diff] [blame] | 3325 | shseat->popup_grab.client = NULL; |
Philipp Brüschweiler | 63e7be6 | 2013-04-15 21:09:54 +0200 | [diff] [blame] | 3326 | shseat->popup_grab.grab.interface = NULL; |
| 3327 | assert(!wl_list_empty(&shseat->popup_grab.surfaces_list)); |
Giulio Camuffo | 5085a75 | 2013-03-25 21:42:45 +0100 | [diff] [blame] | 3328 | /* Send the popup_done event to all the popups open */ |
Jonas Ådahl | c2b1011 | 2015-02-13 14:01:53 +0800 | [diff] [blame] | 3329 | wl_list_for_each_safe(shsurf, next, |
| 3330 | &shseat->popup_grab.surfaces_list, |
| 3331 | popup.grab_link) { |
Rafael Antognolli | e2a3455 | 2013-12-03 15:35:45 -0200 | [diff] [blame] | 3332 | shell_surface_send_popup_done(shsurf); |
Giulio Camuffo | 5085a75 | 2013-03-25 21:42:45 +0100 | [diff] [blame] | 3333 | shsurf->popup.shseat = NULL; |
Jonas Ådahl | c2b1011 | 2015-02-13 14:01:53 +0800 | [diff] [blame] | 3334 | wl_list_init(&shsurf->popup.grab_link); |
Giulio Camuffo | 5085a75 | 2013-03-25 21:42:45 +0100 | [diff] [blame] | 3335 | } |
Giulio Camuffo | 5085a75 | 2013-03-25 21:42:45 +0100 | [diff] [blame] | 3336 | wl_list_init(&shseat->popup_grab.surfaces_list); |
| 3337 | } |
| 3338 | } |
| 3339 | |
| 3340 | static void |
Jonny Lamb | 76cf1fe | 2014-08-20 11:27:10 +0200 | [diff] [blame] | 3341 | touch_popup_grab_end(struct weston_touch *touch) |
| 3342 | { |
| 3343 | struct weston_touch_grab *grab = touch->grab; |
| 3344 | struct shell_seat *shseat = |
| 3345 | container_of(grab, struct shell_seat, popup_grab.touch_grab); |
| 3346 | struct shell_surface *shsurf; |
Jonas Ådahl | c2b1011 | 2015-02-13 14:01:53 +0800 | [diff] [blame] | 3347 | struct shell_surface *next; |
Jonny Lamb | 76cf1fe | 2014-08-20 11:27:10 +0200 | [diff] [blame] | 3348 | |
| 3349 | if (touch->grab->interface == &touch_popup_grab_interface) { |
| 3350 | weston_touch_end_grab(grab->touch); |
| 3351 | shseat->popup_grab.client = NULL; |
| 3352 | shseat->popup_grab.touch_grab.interface = NULL; |
| 3353 | assert(!wl_list_empty(&shseat->popup_grab.surfaces_list)); |
| 3354 | /* Send the popup_done event to all the popups open */ |
Jonas Ådahl | c2b1011 | 2015-02-13 14:01:53 +0800 | [diff] [blame] | 3355 | wl_list_for_each_safe(shsurf, next, |
| 3356 | &shseat->popup_grab.surfaces_list, |
| 3357 | popup.grab_link) { |
Jonny Lamb | 76cf1fe | 2014-08-20 11:27:10 +0200 | [diff] [blame] | 3358 | shell_surface_send_popup_done(shsurf); |
| 3359 | shsurf->popup.shseat = NULL; |
Jonas Ådahl | c2b1011 | 2015-02-13 14:01:53 +0800 | [diff] [blame] | 3360 | wl_list_init(&shsurf->popup.grab_link); |
Jonny Lamb | 76cf1fe | 2014-08-20 11:27:10 +0200 | [diff] [blame] | 3361 | } |
Jonny Lamb | 76cf1fe | 2014-08-20 11:27:10 +0200 | [diff] [blame] | 3362 | wl_list_init(&shseat->popup_grab.surfaces_list); |
| 3363 | } |
| 3364 | } |
| 3365 | |
Jasper St. Pierre | da6ecd0 | 2015-02-27 18:35:45 +0800 | [diff] [blame] | 3366 | static struct shell_surface * |
| 3367 | get_top_popup(struct shell_seat *shseat) |
| 3368 | { |
| 3369 | struct shell_surface *shsurf; |
| 3370 | |
| 3371 | if (wl_list_empty(&shseat->popup_grab.surfaces_list)) { |
| 3372 | return NULL; |
| 3373 | } else { |
| 3374 | shsurf = container_of(shseat->popup_grab.surfaces_list.next, |
| 3375 | struct shell_surface, |
| 3376 | popup.grab_link); |
| 3377 | return shsurf; |
| 3378 | } |
| 3379 | } |
| 3380 | |
| 3381 | static int |
Jonas Ådahl | 01193ae | 2015-02-13 14:01:54 +0800 | [diff] [blame] | 3382 | add_popup_grab(struct shell_surface *shsurf, |
| 3383 | struct shell_seat *shseat, |
| 3384 | int32_t type) |
Giulio Camuffo | 5085a75 | 2013-03-25 21:42:45 +0100 | [diff] [blame] | 3385 | { |
Kristian Høgsberg | e314875 | 2013-05-06 23:19:49 -0400 | [diff] [blame] | 3386 | struct weston_seat *seat = shseat->seat; |
Jasper St. Pierre | da6ecd0 | 2015-02-27 18:35:45 +0800 | [diff] [blame] | 3387 | struct shell_surface *parent, *top_surface; |
Derek Foreman | 1281a36 | 2015-07-31 16:55:32 -0500 | [diff] [blame] | 3388 | struct weston_pointer *pointer = weston_seat_get_pointer(seat); |
| 3389 | struct weston_touch *touch = weston_seat_get_touch(seat); |
Jasper St. Pierre | da6ecd0 | 2015-02-27 18:35:45 +0800 | [diff] [blame] | 3390 | |
| 3391 | parent = get_shell_surface(shsurf->parent); |
| 3392 | top_surface = get_top_popup(shseat); |
| 3393 | if (shell_surface_is_xdg_popup(shsurf) && |
Dima Ryazanov | 497f25d | 2015-04-08 11:51:57 -0700 | [diff] [blame] | 3394 | (!parent || |
| 3395 | (top_surface == NULL && !shell_surface_is_xdg_surface(parent)) || |
Jasper St. Pierre | da6ecd0 | 2015-02-27 18:35:45 +0800 | [diff] [blame] | 3396 | (top_surface != NULL && parent != top_surface))) { |
Jonas Ådahl | ee45a55 | 2015-03-18 16:37:47 +0800 | [diff] [blame] | 3397 | wl_resource_post_error(shsurf->owner_resource, |
| 3398 | XDG_SHELL_ERROR_NOT_THE_TOPMOST_POPUP, |
Jasper St. Pierre | da6ecd0 | 2015-02-27 18:35:45 +0800 | [diff] [blame] | 3399 | "xdg_popup was not created on the " |
| 3400 | "topmost popup"); |
| 3401 | return -1; |
| 3402 | } |
Giulio Camuffo | 5085a75 | 2013-03-25 21:42:45 +0100 | [diff] [blame] | 3403 | |
| 3404 | if (wl_list_empty(&shseat->popup_grab.surfaces_list)) { |
Jonny Lamb | 76cf1fe | 2014-08-20 11:27:10 +0200 | [diff] [blame] | 3405 | shseat->popup_grab.type = type; |
Jonas Ådahl | 01193ae | 2015-02-13 14:01:54 +0800 | [diff] [blame] | 3406 | shseat->popup_grab.client = |
| 3407 | wl_resource_get_client(shsurf->resource); |
Jonny Lamb | 76cf1fe | 2014-08-20 11:27:10 +0200 | [diff] [blame] | 3408 | |
| 3409 | if (type == POINTER) { |
Jonas Ådahl | 01193ae | 2015-02-13 14:01:54 +0800 | [diff] [blame] | 3410 | shseat->popup_grab.grab.interface = |
| 3411 | &popup_grab_interface; |
| 3412 | |
| 3413 | /* We must make sure here that this popup was opened |
| 3414 | * after a mouse press, and not just by moving around |
| 3415 | * with other popups already open. */ |
Derek Foreman | 1281a36 | 2015-07-31 16:55:32 -0500 | [diff] [blame] | 3416 | if (pointer->button_count > 0) |
Jonny Lamb | 76cf1fe | 2014-08-20 11:27:10 +0200 | [diff] [blame] | 3417 | shseat->popup_grab.initial_up = 0; |
| 3418 | } else if (type == TOUCH) { |
Jonas Ådahl | 01193ae | 2015-02-13 14:01:54 +0800 | [diff] [blame] | 3419 | shseat->popup_grab.touch_grab.interface = |
| 3420 | &touch_popup_grab_interface; |
Jonny Lamb | 76cf1fe | 2014-08-20 11:27:10 +0200 | [diff] [blame] | 3421 | } |
Giulio Camuffo | 5085a75 | 2013-03-25 21:42:45 +0100 | [diff] [blame] | 3422 | |
Jonas Ådahl | 01193ae | 2015-02-13 14:01:54 +0800 | [diff] [blame] | 3423 | wl_list_insert(&shseat->popup_grab.surfaces_list, |
| 3424 | &shsurf->popup.grab_link); |
Jonny Lamb | 76cf1fe | 2014-08-20 11:27:10 +0200 | [diff] [blame] | 3425 | |
Jonas Ådahl | 01193ae | 2015-02-13 14:01:54 +0800 | [diff] [blame] | 3426 | if (type == POINTER) { |
Derek Foreman | 1281a36 | 2015-07-31 16:55:32 -0500 | [diff] [blame] | 3427 | weston_pointer_start_grab(pointer, |
Jonas Ådahl | 01193ae | 2015-02-13 14:01:54 +0800 | [diff] [blame] | 3428 | &shseat->popup_grab.grab); |
| 3429 | } else if (type == TOUCH) { |
Derek Foreman | 1281a36 | 2015-07-31 16:55:32 -0500 | [diff] [blame] | 3430 | weston_touch_start_grab(touch, |
Jonas Ådahl | 01193ae | 2015-02-13 14:01:54 +0800 | [diff] [blame] | 3431 | &shseat->popup_grab.touch_grab); |
| 3432 | } |
Rob Bradford | dfe3105 | 2013-06-26 19:49:11 +0100 | [diff] [blame] | 3433 | } else { |
Jonas Ådahl | 01193ae | 2015-02-13 14:01:54 +0800 | [diff] [blame] | 3434 | wl_list_insert(&shseat->popup_grab.surfaces_list, |
| 3435 | &shsurf->popup.grab_link); |
Giulio Camuffo | 5085a75 | 2013-03-25 21:42:45 +0100 | [diff] [blame] | 3436 | } |
Jasper St. Pierre | da6ecd0 | 2015-02-27 18:35:45 +0800 | [diff] [blame] | 3437 | |
| 3438 | return 0; |
Giulio Camuffo | 5085a75 | 2013-03-25 21:42:45 +0100 | [diff] [blame] | 3439 | } |
| 3440 | |
| 3441 | static void |
| 3442 | remove_popup_grab(struct shell_surface *shsurf) |
| 3443 | { |
| 3444 | struct shell_seat *shseat = shsurf->popup.shseat; |
| 3445 | |
Jasper St. Pierre | da6ecd0 | 2015-02-27 18:35:45 +0800 | [diff] [blame] | 3446 | if (shell_surface_is_xdg_popup(shsurf) && |
| 3447 | get_top_popup(shseat) != shsurf) { |
Jonas Ådahl | ee45a55 | 2015-03-18 16:37:47 +0800 | [diff] [blame] | 3448 | wl_resource_post_error(shsurf->owner_resource, |
| 3449 | XDG_SHELL_ERROR_NOT_THE_TOPMOST_POPUP, |
Jasper St. Pierre | da6ecd0 | 2015-02-27 18:35:45 +0800 | [diff] [blame] | 3450 | "xdg_popup was destroyed while it was " |
| 3451 | "not the topmost popup."); |
| 3452 | return; |
| 3453 | } |
| 3454 | |
Giulio Camuffo | 5085a75 | 2013-03-25 21:42:45 +0100 | [diff] [blame] | 3455 | wl_list_remove(&shsurf->popup.grab_link); |
| 3456 | wl_list_init(&shsurf->popup.grab_link); |
| 3457 | if (wl_list_empty(&shseat->popup_grab.surfaces_list)) { |
Jonny Lamb | 76cf1fe | 2014-08-20 11:27:10 +0200 | [diff] [blame] | 3458 | if (shseat->popup_grab.type == POINTER) { |
| 3459 | weston_pointer_end_grab(shseat->popup_grab.grab.pointer); |
| 3460 | shseat->popup_grab.grab.interface = NULL; |
| 3461 | } else if (shseat->popup_grab.type == TOUCH) { |
| 3462 | weston_touch_end_grab(shseat->popup_grab.touch_grab.touch); |
| 3463 | shseat->popup_grab.touch_grab.interface = NULL; |
| 3464 | } |
Kristian Høgsberg | 57e0907 | 2012-10-30 14:07:27 -0400 | [diff] [blame] | 3465 | } |
| 3466 | } |
| 3467 | |
Jasper St. Pierre | da6ecd0 | 2015-02-27 18:35:45 +0800 | [diff] [blame] | 3468 | static int |
Kristian Høgsberg | 3730f36 | 2012-04-13 12:40:07 -0400 | [diff] [blame] | 3469 | shell_map_popup(struct shell_surface *shsurf) |
Kristian Høgsberg | b3cca0a | 2012-01-04 22:19:14 -0500 | [diff] [blame] | 3470 | { |
Giulio Camuffo | 5085a75 | 2013-03-25 21:42:45 +0100 | [diff] [blame] | 3471 | struct shell_seat *shseat = shsurf->popup.shseat; |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 3472 | struct weston_view *parent_view = get_default_view(shsurf->parent); |
Derek Foreman | 1281a36 | 2015-07-31 16:55:32 -0500 | [diff] [blame] | 3473 | struct weston_pointer *pointer = weston_seat_get_pointer(shseat->seat); |
| 3474 | struct weston_touch *touch = weston_seat_get_touch(shseat->seat); |
Kristian Høgsberg | b3cca0a | 2012-01-04 22:19:14 -0500 | [diff] [blame] | 3475 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 3476 | shsurf->surface->output = parent_view->output; |
| 3477 | shsurf->view->output = parent_view->output; |
Kristian Høgsberg | b3cca0a | 2012-01-04 22:19:14 -0500 | [diff] [blame] | 3478 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 3479 | weston_view_set_transform_parent(shsurf->view, parent_view); |
| 3480 | weston_view_set_position(shsurf->view, shsurf->popup.x, shsurf->popup.y); |
| 3481 | weston_view_update_transform(shsurf->view); |
Kristian Høgsberg | b3cca0a | 2012-01-04 22:19:14 -0500 | [diff] [blame] | 3482 | |
Derek Foreman | 1281a36 | 2015-07-31 16:55:32 -0500 | [diff] [blame] | 3483 | if (pointer && |
| 3484 | pointer->grab_serial == shsurf->popup.serial) { |
Jasper St. Pierre | da6ecd0 | 2015-02-27 18:35:45 +0800 | [diff] [blame] | 3485 | if (add_popup_grab(shsurf, shseat, POINTER) != 0) |
| 3486 | return -1; |
Derek Foreman | 1281a36 | 2015-07-31 16:55:32 -0500 | [diff] [blame] | 3487 | } else if (touch && |
| 3488 | touch->grab_serial == shsurf->popup.serial) { |
Jasper St. Pierre | da6ecd0 | 2015-02-27 18:35:45 +0800 | [diff] [blame] | 3489 | if (add_popup_grab(shsurf, shseat, TOUCH) != 0) |
| 3490 | return -1; |
Kristian Høgsberg | 3730f36 | 2012-04-13 12:40:07 -0400 | [diff] [blame] | 3491 | } else { |
Rafael Antognolli | e2a3455 | 2013-12-03 15:35:45 -0200 | [diff] [blame] | 3492 | shell_surface_send_popup_done(shsurf); |
Giulio Camuffo | 5085a75 | 2013-03-25 21:42:45 +0100 | [diff] [blame] | 3493 | shseat->popup_grab.client = NULL; |
Kristian Høgsberg | 3730f36 | 2012-04-13 12:40:07 -0400 | [diff] [blame] | 3494 | } |
Jasper St. Pierre | da6ecd0 | 2015-02-27 18:35:45 +0800 | [diff] [blame] | 3495 | |
| 3496 | return 0; |
Kristian Høgsberg | b3cca0a | 2012-01-04 22:19:14 -0500 | [diff] [blame] | 3497 | } |
| 3498 | |
Pekka Paalanen | 9d1613e | 2011-11-25 12:09:16 +0200 | [diff] [blame] | 3499 | static const struct wl_shell_surface_interface shell_surface_implementation = { |
Scott Moreau | ff1db4a | 2012-04-17 19:06:18 -0600 | [diff] [blame] | 3500 | shell_surface_pong, |
Pekka Paalanen | 9d1613e | 2011-11-25 12:09:16 +0200 | [diff] [blame] | 3501 | shell_surface_move, |
| 3502 | shell_surface_resize, |
| 3503 | shell_surface_set_toplevel, |
| 3504 | shell_surface_set_transient, |
Kristian Høgsberg | b3cca0a | 2012-01-04 22:19:14 -0500 | [diff] [blame] | 3505 | shell_surface_set_fullscreen, |
Juan Zhao | 96879df | 2012-02-07 08:45:41 +0800 | [diff] [blame] | 3506 | shell_surface_set_popup, |
Kristian Høgsberg | e7afd91 | 2012-05-02 09:47:44 -0400 | [diff] [blame] | 3507 | shell_surface_set_maximized, |
| 3508 | shell_surface_set_title, |
| 3509 | shell_surface_set_class |
Pekka Paalanen | 9d1613e | 2011-11-25 12:09:16 +0200 | [diff] [blame] | 3510 | }; |
| 3511 | |
| 3512 | static void |
Tiago Vignatti | bc052c9 | 2012-04-19 16:18:18 +0300 | [diff] [blame] | 3513 | destroy_shell_surface(struct shell_surface *shsurf) |
Pekka Paalanen | 9d1613e | 2011-11-25 12:09:16 +0200 | [diff] [blame] | 3514 | { |
Kristian Høgsberg | 9046d24 | 2014-01-10 00:25:30 -0800 | [diff] [blame] | 3515 | struct shell_surface *child, *next; |
| 3516 | |
Jason Ekstrand | 651f00e | 2013-06-14 10:07:54 -0500 | [diff] [blame] | 3517 | wl_signal_emit(&shsurf->destroy_signal, shsurf); |
| 3518 | |
Giulio Camuffo | 5085a75 | 2013-03-25 21:42:45 +0100 | [diff] [blame] | 3519 | if (!wl_list_empty(&shsurf->popup.grab_link)) { |
| 3520 | remove_popup_grab(shsurf); |
| 3521 | } |
Kristian Høgsberg | b3cca0a | 2012-01-04 22:19:14 -0500 | [diff] [blame] | 3522 | |
Alex Wu | bd3354b | 2012-04-17 17:20:49 +0800 | [diff] [blame] | 3523 | if (shsurf->fullscreen.type == WL_SHELL_SURFACE_FULLSCREEN_METHOD_DRIVER && |
Alexander Larsson | f82b6ca | 2013-05-28 16:23:39 +0200 | [diff] [blame] | 3524 | shell_surface_is_top_fullscreen(shsurf)) |
| 3525 | restore_output_mode (shsurf->fullscreen_output); |
Pekka Paalanen | 9d1613e | 2011-11-25 12:09:16 +0200 | [diff] [blame] | 3526 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 3527 | if (shsurf->fullscreen.black_view) |
| 3528 | weston_surface_destroy(shsurf->fullscreen.black_view->surface); |
Alex Wu | aa08e2d | 2012-03-05 11:01:40 +0800 | [diff] [blame] | 3529 | |
Alex Wu | bd3354b | 2012-04-17 17:20:49 +0800 | [diff] [blame] | 3530 | /* As destroy_resource() use wl_list_for_each_safe(), |
| 3531 | * we can always remove the listener. |
| 3532 | */ |
| 3533 | wl_list_remove(&shsurf->surface_destroy_listener.link); |
| 3534 | shsurf->surface->configure = NULL; |
Pekka Paalanen | 8274d90 | 2014-08-06 19:36:51 +0300 | [diff] [blame] | 3535 | weston_surface_set_label_func(shsurf->surface, NULL); |
Scott Moreau | 976a050 | 2013-03-07 10:15:17 -0700 | [diff] [blame] | 3536 | free(shsurf->title); |
Alex Wu | bd3354b | 2012-04-17 17:20:49 +0800 | [diff] [blame] | 3537 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 3538 | weston_view_destroy(shsurf->view); |
| 3539 | |
Philip Withnall | 648a4dd | 2013-11-25 18:01:44 +0000 | [diff] [blame] | 3540 | wl_list_remove(&shsurf->children_link); |
Emilio Pozuelo Monfort | adaa20c | 2014-01-28 13:54:16 +0100 | [diff] [blame] | 3541 | wl_list_for_each_safe(child, next, &shsurf->children_list, children_link) |
| 3542 | shell_surface_set_parent(child, NULL); |
Philip Withnall | 648a4dd | 2013-11-25 18:01:44 +0000 | [diff] [blame] | 3543 | |
Pekka Paalanen | 9d1613e | 2011-11-25 12:09:16 +0200 | [diff] [blame] | 3544 | wl_list_remove(&shsurf->link); |
| 3545 | free(shsurf); |
| 3546 | } |
| 3547 | |
| 3548 | static void |
Tiago Vignatti | bc052c9 | 2012-04-19 16:18:18 +0300 | [diff] [blame] | 3549 | shell_destroy_shell_surface(struct wl_resource *resource) |
| 3550 | { |
Jason Ekstrand | 651f00e | 2013-06-14 10:07:54 -0500 | [diff] [blame] | 3551 | struct shell_surface *shsurf = wl_resource_get_user_data(resource); |
Tiago Vignatti | bc052c9 | 2012-04-19 16:18:18 +0300 | [diff] [blame] | 3552 | |
Bryan Cain | a46b946 | 2014-04-04 17:41:24 -0500 | [diff] [blame] | 3553 | if (!wl_list_empty(&shsurf->popup.grab_link)) |
| 3554 | remove_popup_grab(shsurf); |
Jonas Ådahl | 49d77d2 | 2015-03-18 16:20:51 +0800 | [diff] [blame] | 3555 | wl_list_remove(wl_resource_get_link(shsurf->resource)); |
Kristian Høgsberg | 160fe75 | 2014-03-11 10:19:10 -0700 | [diff] [blame] | 3556 | shsurf->resource = NULL; |
Tiago Vignatti | bc052c9 | 2012-04-19 16:18:18 +0300 | [diff] [blame] | 3557 | } |
| 3558 | |
| 3559 | static void |
Kristian Høgsberg | 27e3052 | 2012-04-11 23:18:23 -0400 | [diff] [blame] | 3560 | shell_handle_surface_destroy(struct wl_listener *listener, void *data) |
Pekka Paalanen | 9d1613e | 2011-11-25 12:09:16 +0200 | [diff] [blame] | 3561 | { |
| 3562 | struct shell_surface *shsurf = container_of(listener, |
| 3563 | struct shell_surface, |
| 3564 | surface_destroy_listener); |
| 3565 | |
Jason Ekstrand | 651f00e | 2013-06-14 10:07:54 -0500 | [diff] [blame] | 3566 | if (shsurf->resource) |
| 3567 | wl_resource_destroy(shsurf->resource); |
Ander Conselvan de Oliveira | 15f9a26 | 2014-04-29 17:54:02 +0300 | [diff] [blame] | 3568 | |
| 3569 | destroy_shell_surface(shsurf); |
Pekka Paalanen | 9d1613e | 2011-11-25 12:09:16 +0200 | [diff] [blame] | 3570 | } |
| 3571 | |
Kristian Høgsberg | d813445 | 2012-06-21 12:49:02 -0400 | [diff] [blame] | 3572 | static void |
Derek Foreman | 039e9be | 2015-04-14 17:09:06 -0500 | [diff] [blame] | 3573 | fade_out_done_idle_cb(void *data) |
Kristian Høgsberg | 160fe75 | 2014-03-11 10:19:10 -0700 | [diff] [blame] | 3574 | { |
| 3575 | struct shell_surface *shsurf = data; |
| 3576 | |
| 3577 | weston_surface_destroy(shsurf->surface); |
| 3578 | } |
| 3579 | |
| 3580 | static void |
Derek Foreman | 039e9be | 2015-04-14 17:09:06 -0500 | [diff] [blame] | 3581 | fade_out_done(struct weston_view_animation *animation, void *data) |
| 3582 | { |
| 3583 | struct shell_surface *shsurf = data; |
| 3584 | struct wl_event_loop *loop; |
| 3585 | |
| 3586 | loop = wl_display_get_event_loop( |
| 3587 | shsurf->surface->compositor->wl_display); |
| 3588 | |
| 3589 | if (!shsurf->destroying) { |
| 3590 | wl_event_loop_add_idle(loop, fade_out_done_idle_cb, shsurf); |
| 3591 | shsurf->destroying = true; |
| 3592 | } |
| 3593 | } |
| 3594 | |
| 3595 | static void |
Kristian Høgsberg | 160fe75 | 2014-03-11 10:19:10 -0700 | [diff] [blame] | 3596 | handle_resource_destroy(struct wl_listener *listener, void *data) |
| 3597 | { |
| 3598 | struct shell_surface *shsurf = |
| 3599 | container_of(listener, struct shell_surface, |
| 3600 | resource_destroy_listener); |
| 3601 | |
Ander Conselvan de Oliveira | 15f9a26 | 2014-04-29 17:54:02 +0300 | [diff] [blame] | 3602 | if (!weston_surface_is_mapped(shsurf->surface)) |
| 3603 | return; |
| 3604 | |
Kristian Høgsberg | 160fe75 | 2014-03-11 10:19:10 -0700 | [diff] [blame] | 3605 | shsurf->surface->ref_count++; |
| 3606 | |
| 3607 | pixman_region32_fini(&shsurf->surface->pending.input); |
| 3608 | pixman_region32_init(&shsurf->surface->pending.input); |
| 3609 | pixman_region32_fini(&shsurf->surface->input); |
| 3610 | pixman_region32_init(&shsurf->surface->input); |
Jonny Lamb | f322f8e | 2014-08-12 15:13:30 +0200 | [diff] [blame] | 3611 | if (shsurf->shell->win_close_animation_type == ANIMATION_FADE) { |
| 3612 | weston_fade_run(shsurf->view, 1.0, 0.0, 300.0, |
| 3613 | fade_out_done, shsurf); |
| 3614 | } else { |
| 3615 | weston_surface_destroy(shsurf->surface); |
| 3616 | } |
Kristian Høgsberg | 160fe75 | 2014-03-11 10:19:10 -0700 | [diff] [blame] | 3617 | } |
| 3618 | |
| 3619 | static void |
Jason Ekstrand | 918f2dd | 2013-12-02 21:01:53 -0600 | [diff] [blame] | 3620 | shell_surface_configure(struct weston_surface *, int32_t, int32_t); |
Kristian Høgsberg | d813445 | 2012-06-21 12:49:02 -0400 | [diff] [blame] | 3621 | |
Kristian Høgsberg | 1ef2313 | 2013-12-04 00:20:01 -0800 | [diff] [blame] | 3622 | struct shell_surface * |
Kristian Høgsberg | 8334bc1 | 2012-01-03 10:29:47 -0500 | [diff] [blame] | 3623 | get_shell_surface(struct weston_surface *surface) |
Pekka Paalanen | ec2b32f | 2011-11-28 15:12:34 +0200 | [diff] [blame] | 3624 | { |
Kristian Høgsberg | d813445 | 2012-06-21 12:49:02 -0400 | [diff] [blame] | 3625 | if (surface->configure == shell_surface_configure) |
Giulio Camuffo | 7fe01b1 | 2013-03-28 18:02:42 +0100 | [diff] [blame] | 3626 | return surface->configure_private; |
Kristian Høgsberg | d813445 | 2012-06-21 12:49:02 -0400 | [diff] [blame] | 3627 | else |
| 3628 | return NULL; |
Pekka Paalanen | ec2b32f | 2011-11-28 15:12:34 +0200 | [diff] [blame] | 3629 | } |
| 3630 | |
Rafael Antognolli | e2a3455 | 2013-12-03 15:35:45 -0200 | [diff] [blame] | 3631 | static struct shell_surface * |
Jason Ekstrand | 9e9512f | 2014-04-16 21:12:10 -0500 | [diff] [blame] | 3632 | create_common_surface(struct shell_client *owner, void *shell, |
| 3633 | struct weston_surface *surface, |
Rafael Antognolli | e2a3455 | 2013-12-03 15:35:45 -0200 | [diff] [blame] | 3634 | const struct weston_shell_client *client) |
Pekka Paalanen | 9d1613e | 2011-11-25 12:09:16 +0200 | [diff] [blame] | 3635 | { |
Pekka Paalanen | 9d1613e | 2011-11-25 12:09:16 +0200 | [diff] [blame] | 3636 | struct shell_surface *shsurf; |
| 3637 | |
Pekka Paalanen | 50b6747 | 2014-10-01 15:02:41 +0300 | [diff] [blame] | 3638 | assert(surface->configure == NULL); |
Ander Conselvan de Oliveira | 093bfa3 | 2012-03-27 17:36:41 +0300 | [diff] [blame] | 3639 | |
Pekka Paalanen | 9d1613e | 2011-11-25 12:09:16 +0200 | [diff] [blame] | 3640 | shsurf = calloc(1, sizeof *shsurf); |
| 3641 | if (!shsurf) { |
Martin Minarik | 6d11836 | 2012-06-07 18:01:59 +0200 | [diff] [blame] | 3642 | weston_log("no memory to allocate shell surface\n"); |
Kristian Høgsberg | 45ba869 | 2012-05-21 14:27:33 -0400 | [diff] [blame] | 3643 | return NULL; |
Pekka Paalanen | 9d1613e | 2011-11-25 12:09:16 +0200 | [diff] [blame] | 3644 | } |
| 3645 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 3646 | shsurf->view = weston_view_create(surface); |
| 3647 | if (!shsurf->view) { |
| 3648 | weston_log("no memory to allocate shell surface\n"); |
| 3649 | free(shsurf); |
| 3650 | return NULL; |
| 3651 | } |
| 3652 | |
Ander Conselvan de Oliveira | 093bfa3 | 2012-03-27 17:36:41 +0300 | [diff] [blame] | 3653 | surface->configure = shell_surface_configure; |
Giulio Camuffo | 7fe01b1 | 2013-03-28 18:02:42 +0100 | [diff] [blame] | 3654 | surface->configure_private = shsurf; |
Pekka Paalanen | 8274d90 | 2014-08-06 19:36:51 +0300 | [diff] [blame] | 3655 | weston_surface_set_label_func(surface, shell_surface_get_label); |
Ander Conselvan de Oliveira | 093bfa3 | 2012-03-27 17:36:41 +0300 | [diff] [blame] | 3656 | |
Kristian Høgsberg | 160fe75 | 2014-03-11 10:19:10 -0700 | [diff] [blame] | 3657 | shsurf->resource_destroy_listener.notify = handle_resource_destroy; |
| 3658 | wl_resource_add_destroy_listener(surface->resource, |
| 3659 | &shsurf->resource_destroy_listener); |
Jason Ekstrand | 9e9512f | 2014-04-16 21:12:10 -0500 | [diff] [blame] | 3660 | shsurf->owner = owner; |
Kristian Høgsberg | 160fe75 | 2014-03-11 10:19:10 -0700 | [diff] [blame] | 3661 | |
Tiago Vignatti | bc052c9 | 2012-04-19 16:18:18 +0300 | [diff] [blame] | 3662 | shsurf->shell = (struct desktop_shell *) shell; |
Scott Moreau | ff1db4a | 2012-04-17 19:06:18 -0600 | [diff] [blame] | 3663 | shsurf->unresponsive = 0; |
Alex Wu | 4539b08 | 2012-03-01 12:57:46 +0800 | [diff] [blame] | 3664 | shsurf->saved_position_valid = false; |
Rafael Antognolli | 3c4e3f7 | 2013-12-03 15:35:46 -0200 | [diff] [blame] | 3665 | shsurf->saved_size_valid = false; |
Alex Wu | 7bcb8bd | 2012-04-27 09:07:24 +0800 | [diff] [blame] | 3666 | shsurf->saved_rotation_valid = false; |
Pekka Paalanen | 9d1613e | 2011-11-25 12:09:16 +0200 | [diff] [blame] | 3667 | shsurf->surface = surface; |
Alex Wu | 4539b08 | 2012-03-01 12:57:46 +0800 | [diff] [blame] | 3668 | shsurf->fullscreen.type = WL_SHELL_SURFACE_FULLSCREEN_METHOD_DEFAULT; |
| 3669 | shsurf->fullscreen.framerate = 0; |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 3670 | shsurf->fullscreen.black_view = NULL; |
Alex Wu | 4539b08 | 2012-03-01 12:57:46 +0800 | [diff] [blame] | 3671 | wl_list_init(&shsurf->fullscreen.transform.link); |
| 3672 | |
Jasper St. Pierre | 9aa8ce6 | 2014-04-11 16:18:54 -0700 | [diff] [blame] | 3673 | shsurf->output = get_default_output(shsurf->shell->compositor); |
| 3674 | |
Jason Ekstrand | 651f00e | 2013-06-14 10:07:54 -0500 | [diff] [blame] | 3675 | wl_signal_init(&shsurf->destroy_signal); |
Kristian Høgsberg | 27e3052 | 2012-04-11 23:18:23 -0400 | [diff] [blame] | 3676 | shsurf->surface_destroy_listener.notify = shell_handle_surface_destroy; |
Jason Ekstrand | 26ed73c | 2013-06-06 22:34:41 -0500 | [diff] [blame] | 3677 | wl_signal_add(&surface->destroy_signal, |
Kristian Høgsberg | 27e3052 | 2012-04-11 23:18:23 -0400 | [diff] [blame] | 3678 | &shsurf->surface_destroy_listener); |
Pekka Paalanen | 9d1613e | 2011-11-25 12:09:16 +0200 | [diff] [blame] | 3679 | |
| 3680 | /* init link so its safe to always remove it in destroy_shell_surface */ |
| 3681 | wl_list_init(&shsurf->link); |
Giulio Camuffo | 5085a75 | 2013-03-25 21:42:45 +0100 | [diff] [blame] | 3682 | wl_list_init(&shsurf->popup.grab_link); |
Pekka Paalanen | 9d1613e | 2011-11-25 12:09:16 +0200 | [diff] [blame] | 3683 | |
Pekka Paalanen | 460099f | 2012-01-20 16:48:25 +0200 | [diff] [blame] | 3684 | /* empty when not in use */ |
| 3685 | wl_list_init(&shsurf->rotation.transform.link); |
Kristian Høgsberg | 765e27b | 2012-01-27 13:36:13 -0500 | [diff] [blame] | 3686 | weston_matrix_init(&shsurf->rotation.rotation); |
Pekka Paalanen | 460099f | 2012-01-20 16:48:25 +0200 | [diff] [blame] | 3687 | |
Jonas Ådahl | 62fcd04 | 2012-06-13 00:01:23 +0200 | [diff] [blame] | 3688 | wl_list_init(&shsurf->workspace_transform.link); |
| 3689 | |
Philip Withnall | 648a4dd | 2013-11-25 18:01:44 +0000 | [diff] [blame] | 3690 | wl_list_init(&shsurf->children_link); |
| 3691 | wl_list_init(&shsurf->children_list); |
| 3692 | shsurf->parent = NULL; |
| 3693 | |
Pekka Paalanen | b502654 | 2014-11-12 15:09:24 +0200 | [diff] [blame] | 3694 | set_type(shsurf, SHELL_SURFACE_NONE); |
Pekka Paalanen | 9d1613e | 2011-11-25 12:09:16 +0200 | [diff] [blame] | 3695 | |
Kristian Høgsberg | a61ca06 | 2012-05-22 16:05:52 -0400 | [diff] [blame] | 3696 | shsurf->client = client; |
| 3697 | |
Kristian Høgsberg | 45ba869 | 2012-05-21 14:27:33 -0400 | [diff] [blame] | 3698 | return shsurf; |
Tiago Vignatti | bc052c9 | 2012-04-19 16:18:18 +0300 | [diff] [blame] | 3699 | } |
| 3700 | |
Rafael Antognolli | e2a3455 | 2013-12-03 15:35:45 -0200 | [diff] [blame] | 3701 | static struct shell_surface * |
| 3702 | create_shell_surface(void *shell, struct weston_surface *surface, |
| 3703 | const struct weston_shell_client *client) |
| 3704 | { |
Jason Ekstrand | 9e9512f | 2014-04-16 21:12:10 -0500 | [diff] [blame] | 3705 | return create_common_surface(NULL, shell, surface, client); |
Rafael Antognolli | e2a3455 | 2013-12-03 15:35:45 -0200 | [diff] [blame] | 3706 | } |
| 3707 | |
Tiago Vignatti | bc052c9 | 2012-04-19 16:18:18 +0300 | [diff] [blame] | 3708 | static void |
| 3709 | shell_get_shell_surface(struct wl_client *client, |
| 3710 | struct wl_resource *resource, |
| 3711 | uint32_t id, |
| 3712 | struct wl_resource *surface_resource) |
| 3713 | { |
Jason Ekstrand | 0f2ef7e | 2013-06-14 10:07:53 -0500 | [diff] [blame] | 3714 | struct weston_surface *surface = |
| 3715 | wl_resource_get_user_data(surface_resource); |
Jason Ekstrand | 9e9512f | 2014-04-16 21:12:10 -0500 | [diff] [blame] | 3716 | struct shell_client *sc = wl_resource_get_user_data(resource); |
| 3717 | struct desktop_shell *shell = sc->shell; |
Tiago Vignatti | bc052c9 | 2012-04-19 16:18:18 +0300 | [diff] [blame] | 3718 | struct shell_surface *shsurf; |
| 3719 | |
Pekka Paalanen | 50b6747 | 2014-10-01 15:02:41 +0300 | [diff] [blame] | 3720 | if (weston_surface_set_role(surface, "wl_shell_surface", |
| 3721 | resource, WL_SHELL_ERROR_ROLE) < 0) |
Tiago Vignatti | bc052c9 | 2012-04-19 16:18:18 +0300 | [diff] [blame] | 3722 | return; |
Tiago Vignatti | bc052c9 | 2012-04-19 16:18:18 +0300 | [diff] [blame] | 3723 | |
Jason Ekstrand | 9e9512f | 2014-04-16 21:12:10 -0500 | [diff] [blame] | 3724 | shsurf = create_common_surface(sc, shell, surface, &shell_client); |
Kristian Høgsberg | 9540ea6 | 2012-05-21 14:28:57 -0400 | [diff] [blame] | 3725 | if (!shsurf) { |
Pekka Paalanen | 50b6747 | 2014-10-01 15:02:41 +0300 | [diff] [blame] | 3726 | wl_resource_post_no_memory(surface_resource); |
Kristian Høgsberg | 9540ea6 | 2012-05-21 14:28:57 -0400 | [diff] [blame] | 3727 | return; |
| 3728 | } |
Tiago Vignatti | bc052c9 | 2012-04-19 16:18:18 +0300 | [diff] [blame] | 3729 | |
Jason Ekstrand | a85118c | 2013-06-27 20:17:02 -0500 | [diff] [blame] | 3730 | shsurf->resource = |
| 3731 | wl_resource_create(client, |
| 3732 | &wl_shell_surface_interface, 1, id); |
| 3733 | wl_resource_set_implementation(shsurf->resource, |
| 3734 | &shell_surface_implementation, |
| 3735 | shsurf, shell_destroy_shell_surface); |
Jonas Ådahl | 49d77d2 | 2015-03-18 16:20:51 +0800 | [diff] [blame] | 3736 | wl_list_init(wl_resource_get_link(shsurf->resource)); |
Pekka Paalanen | 9d1613e | 2011-11-25 12:09:16 +0200 | [diff] [blame] | 3737 | } |
| 3738 | |
Rafael Antognolli | e2a3455 | 2013-12-03 15:35:45 -0200 | [diff] [blame] | 3739 | static bool |
| 3740 | shell_surface_is_wl_shell_surface(struct shell_surface *shsurf) |
| 3741 | { |
Kristian Høgsberg | 0b7d995 | 2014-02-03 15:50:38 -0800 | [diff] [blame] | 3742 | /* A shell surface without a resource is created from xwayland |
| 3743 | * and is considered a wl_shell surface for now. */ |
| 3744 | |
| 3745 | return shsurf->resource == NULL || |
| 3746 | wl_resource_instance_of(shsurf->resource, |
| 3747 | &wl_shell_surface_interface, |
| 3748 | &shell_surface_implementation); |
Rafael Antognolli | e2a3455 | 2013-12-03 15:35:45 -0200 | [diff] [blame] | 3749 | } |
| 3750 | |
Pekka Paalanen | 9d1613e | 2011-11-25 12:09:16 +0200 | [diff] [blame] | 3751 | static const struct wl_shell_interface shell_implementation = { |
Pekka Paalanen | 4622967 | 2011-11-29 15:49:31 +0200 | [diff] [blame] | 3752 | shell_get_shell_surface |
Kristian Høgsberg | 4cca349 | 2011-01-18 07:53:49 -0500 | [diff] [blame] | 3753 | }; |
| 3754 | |
Rafael Antognolli | e2a3455 | 2013-12-03 15:35:45 -0200 | [diff] [blame] | 3755 | /**************************** |
| 3756 | * xdg-shell implementation */ |
| 3757 | |
| 3758 | static void |
| 3759 | xdg_surface_destroy(struct wl_client *client, |
| 3760 | struct wl_resource *resource) |
| 3761 | { |
| 3762 | wl_resource_destroy(resource); |
| 3763 | } |
| 3764 | |
| 3765 | static void |
Jasper St. Pierre | c815d62 | 2014-04-10 18:37:54 -0700 | [diff] [blame] | 3766 | xdg_surface_set_parent(struct wl_client *client, |
| 3767 | struct wl_resource *resource, |
| 3768 | struct wl_resource *parent_resource) |
Jasper St. Pierre | 63a9c33 | 2014-02-01 18:35:15 -0500 | [diff] [blame] | 3769 | { |
| 3770 | struct shell_surface *shsurf = wl_resource_get_user_data(resource); |
Jasper St. Pierre | 66bc949 | 2015-02-13 14:01:55 +0800 | [diff] [blame] | 3771 | struct shell_surface *parent; |
Jasper St. Pierre | 63a9c33 | 2014-02-01 18:35:15 -0500 | [diff] [blame] | 3772 | |
Jasper St. Pierre | 66bc949 | 2015-02-13 14:01:55 +0800 | [diff] [blame] | 3773 | if (parent_resource) { |
Jasper St. Pierre | 63a9c33 | 2014-02-01 18:35:15 -0500 | [diff] [blame] | 3774 | parent = wl_resource_get_user_data(parent_resource); |
Jasper St. Pierre | 66bc949 | 2015-02-13 14:01:55 +0800 | [diff] [blame] | 3775 | shell_surface_set_parent(shsurf, parent->surface); |
| 3776 | } else { |
| 3777 | shell_surface_set_parent(shsurf, NULL); |
| 3778 | } |
Jasper St. Pierre | 63a9c33 | 2014-02-01 18:35:15 -0500 | [diff] [blame] | 3779 | } |
| 3780 | |
| 3781 | static void |
Rafael Antognolli | e2a3455 | 2013-12-03 15:35:45 -0200 | [diff] [blame] | 3782 | xdg_surface_set_app_id(struct wl_client *client, |
| 3783 | struct wl_resource *resource, |
| 3784 | const char *app_id) |
| 3785 | { |
| 3786 | struct shell_surface *shsurf = wl_resource_get_user_data(resource); |
| 3787 | |
| 3788 | free(shsurf->class); |
| 3789 | shsurf->class = strdup(app_id); |
Pekka Paalanen | b502654 | 2014-11-12 15:09:24 +0200 | [diff] [blame] | 3790 | shsurf->surface->timeline.force_refresh = 1; |
Rafael Antognolli | e2a3455 | 2013-12-03 15:35:45 -0200 | [diff] [blame] | 3791 | } |
| 3792 | |
| 3793 | static void |
Jasper St. Pierre | 81ff075 | 2014-03-13 11:04:53 -0400 | [diff] [blame] | 3794 | xdg_surface_show_window_menu(struct wl_client *client, |
| 3795 | struct wl_resource *surface_resource, |
| 3796 | struct wl_resource *seat_resource, |
| 3797 | uint32_t serial, |
| 3798 | int32_t x, |
| 3799 | int32_t y) |
| 3800 | { |
| 3801 | /* TODO */ |
| 3802 | } |
| 3803 | |
| 3804 | static void |
Rafael Antognolli | e2a3455 | 2013-12-03 15:35:45 -0200 | [diff] [blame] | 3805 | xdg_surface_set_title(struct wl_client *client, |
| 3806 | struct wl_resource *resource, const char *title) |
| 3807 | { |
| 3808 | struct shell_surface *shsurf = wl_resource_get_user_data(resource); |
| 3809 | |
| 3810 | set_title(shsurf, title); |
| 3811 | } |
| 3812 | |
| 3813 | static void |
| 3814 | xdg_surface_move(struct wl_client *client, struct wl_resource *resource, |
| 3815 | struct wl_resource *seat_resource, uint32_t serial) |
| 3816 | { |
| 3817 | common_surface_move(resource, seat_resource, serial); |
| 3818 | } |
| 3819 | |
| 3820 | static void |
| 3821 | xdg_surface_resize(struct wl_client *client, struct wl_resource *resource, |
| 3822 | struct wl_resource *seat_resource, uint32_t serial, |
| 3823 | uint32_t edges) |
| 3824 | { |
| 3825 | common_surface_resize(resource, seat_resource, serial, edges); |
| 3826 | } |
| 3827 | |
| 3828 | static void |
Jasper St. Pierre | ab2c108 | 2014-04-10 10:41:46 -0700 | [diff] [blame] | 3829 | xdg_surface_ack_configure(struct wl_client *client, |
| 3830 | struct wl_resource *resource, |
| 3831 | uint32_t serial) |
Rafael Antognolli | e2a3455 | 2013-12-03 15:35:45 -0200 | [diff] [blame] | 3832 | { |
| 3833 | struct shell_surface *shsurf = wl_resource_get_user_data(resource); |
| 3834 | |
Jasper St. Pierre | 8c6aa45 | 2014-02-08 18:29:49 -0500 | [diff] [blame] | 3835 | if (shsurf->state_requested) { |
| 3836 | shsurf->next_state = shsurf->requested_state; |
| 3837 | shsurf->state_changed = true; |
| 3838 | shsurf->state_requested = false; |
Rafael Antognolli | 3c4e3f7 | 2013-12-03 15:35:46 -0200 | [diff] [blame] | 3839 | } |
Rafael Antognolli | e2a3455 | 2013-12-03 15:35:45 -0200 | [diff] [blame] | 3840 | } |
| 3841 | |
Manuel Bachmann | 50c87db | 2014-02-26 15:52:13 +0100 | [diff] [blame] | 3842 | static void |
Jasper St. Pierre | ccf48fb | 2014-05-02 10:21:38 -0400 | [diff] [blame] | 3843 | xdg_surface_set_window_geometry(struct wl_client *client, |
| 3844 | struct wl_resource *resource, |
| 3845 | int32_t x, |
| 3846 | int32_t y, |
| 3847 | int32_t width, |
| 3848 | int32_t height) |
| 3849 | { |
| 3850 | struct shell_surface *shsurf = wl_resource_get_user_data(resource); |
| 3851 | |
| 3852 | set_window_geometry(shsurf, x, y, width, height); |
| 3853 | } |
| 3854 | |
| 3855 | static void |
Jasper St. Pierre | ab2c108 | 2014-04-10 10:41:46 -0700 | [diff] [blame] | 3856 | xdg_surface_set_maximized(struct wl_client *client, |
| 3857 | struct wl_resource *resource) |
| 3858 | { |
| 3859 | struct shell_surface *shsurf = wl_resource_get_user_data(resource); |
Marek Chalupa | bfbb64b | 2014-09-08 12:34:20 +0200 | [diff] [blame] | 3860 | struct weston_output *output; |
Jasper St. Pierre | ab2c108 | 2014-04-10 10:41:46 -0700 | [diff] [blame] | 3861 | |
| 3862 | shsurf->state_requested = true; |
| 3863 | shsurf->requested_state.maximized = true; |
Marek Chalupa | bfbb64b | 2014-09-08 12:34:20 +0200 | [diff] [blame] | 3864 | |
| 3865 | if (!weston_surface_is_mapped(shsurf->surface)) |
| 3866 | output = get_focused_output(shsurf->surface->compositor); |
| 3867 | else |
| 3868 | output = shsurf->surface->output; |
| 3869 | |
| 3870 | shell_surface_set_output(shsurf, output); |
Jasper St. Pierre | 9aa8ce6 | 2014-04-11 16:18:54 -0700 | [diff] [blame] | 3871 | send_configure_for_surface(shsurf); |
Jasper St. Pierre | ab2c108 | 2014-04-10 10:41:46 -0700 | [diff] [blame] | 3872 | } |
| 3873 | |
| 3874 | static void |
| 3875 | xdg_surface_unset_maximized(struct wl_client *client, |
| 3876 | struct wl_resource *resource) |
| 3877 | { |
| 3878 | struct shell_surface *shsurf = wl_resource_get_user_data(resource); |
| 3879 | |
| 3880 | shsurf->state_requested = true; |
| 3881 | shsurf->requested_state.maximized = false; |
Jasper St. Pierre | 6458ec3 | 2014-04-11 16:00:31 -0700 | [diff] [blame] | 3882 | send_configure_for_surface(shsurf); |
Jasper St. Pierre | ab2c108 | 2014-04-10 10:41:46 -0700 | [diff] [blame] | 3883 | } |
| 3884 | |
| 3885 | static void |
| 3886 | xdg_surface_set_fullscreen(struct wl_client *client, |
| 3887 | struct wl_resource *resource, |
| 3888 | struct wl_resource *output_resource) |
| 3889 | { |
| 3890 | struct shell_surface *shsurf = wl_resource_get_user_data(resource); |
| 3891 | struct weston_output *output; |
| 3892 | |
| 3893 | shsurf->state_requested = true; |
| 3894 | shsurf->requested_state.fullscreen = true; |
| 3895 | |
| 3896 | if (output_resource) |
| 3897 | output = wl_resource_get_user_data(output_resource); |
| 3898 | else |
| 3899 | output = NULL; |
| 3900 | |
Marek Chalupa | 052917a | 2014-09-02 11:35:12 +0200 | [diff] [blame] | 3901 | /* handle clients launching in fullscreen */ |
| 3902 | if (output == NULL && !weston_surface_is_mapped(shsurf->surface)) { |
| 3903 | /* Set the output to the one that has focus currently. */ |
| 3904 | assert(shsurf->surface); |
| 3905 | output = get_focused_output(shsurf->surface->compositor); |
| 3906 | } |
| 3907 | |
Jasper St. Pierre | 9aa8ce6 | 2014-04-11 16:18:54 -0700 | [diff] [blame] | 3908 | shell_surface_set_output(shsurf, output); |
| 3909 | shsurf->fullscreen_output = shsurf->output; |
Jasper St. Pierre | ab2c108 | 2014-04-10 10:41:46 -0700 | [diff] [blame] | 3910 | |
Jasper St. Pierre | 9aa8ce6 | 2014-04-11 16:18:54 -0700 | [diff] [blame] | 3911 | send_configure_for_surface(shsurf); |
Jasper St. Pierre | ab2c108 | 2014-04-10 10:41:46 -0700 | [diff] [blame] | 3912 | } |
| 3913 | |
| 3914 | static void |
| 3915 | xdg_surface_unset_fullscreen(struct wl_client *client, |
| 3916 | struct wl_resource *resource) |
| 3917 | { |
| 3918 | struct shell_surface *shsurf = wl_resource_get_user_data(resource); |
| 3919 | |
| 3920 | shsurf->state_requested = true; |
| 3921 | shsurf->requested_state.fullscreen = false; |
Jasper St. Pierre | 6458ec3 | 2014-04-11 16:00:31 -0700 | [diff] [blame] | 3922 | send_configure_for_surface(shsurf); |
Jasper St. Pierre | ab2c108 | 2014-04-10 10:41:46 -0700 | [diff] [blame] | 3923 | } |
| 3924 | |
| 3925 | static void |
Manuel Bachmann | 50c87db | 2014-02-26 15:52:13 +0100 | [diff] [blame] | 3926 | xdg_surface_set_minimized(struct wl_client *client, |
| 3927 | struct wl_resource *resource) |
| 3928 | { |
| 3929 | struct shell_surface *shsurf = wl_resource_get_user_data(resource); |
| 3930 | |
| 3931 | if (shsurf->type != SHELL_SURFACE_TOPLEVEL) |
| 3932 | return; |
| 3933 | |
| 3934 | /* apply compositor's own minimization logic (hide) */ |
Manuel Bachmann | dc1c3e4 | 2015-02-16 11:52:13 +0100 | [diff] [blame] | 3935 | set_minimized(shsurf->surface); |
Manuel Bachmann | 50c87db | 2014-02-26 15:52:13 +0100 | [diff] [blame] | 3936 | } |
| 3937 | |
Rafael Antognolli | e2a3455 | 2013-12-03 15:35:45 -0200 | [diff] [blame] | 3938 | static const struct xdg_surface_interface xdg_surface_implementation = { |
| 3939 | xdg_surface_destroy, |
Jasper St. Pierre | c815d62 | 2014-04-10 18:37:54 -0700 | [diff] [blame] | 3940 | xdg_surface_set_parent, |
Rafael Antognolli | e2a3455 | 2013-12-03 15:35:45 -0200 | [diff] [blame] | 3941 | xdg_surface_set_title, |
| 3942 | xdg_surface_set_app_id, |
Jasper St. Pierre | 81ff075 | 2014-03-13 11:04:53 -0400 | [diff] [blame] | 3943 | xdg_surface_show_window_menu, |
Rafael Antognolli | e2a3455 | 2013-12-03 15:35:45 -0200 | [diff] [blame] | 3944 | xdg_surface_move, |
| 3945 | xdg_surface_resize, |
Jasper St. Pierre | ab2c108 | 2014-04-10 10:41:46 -0700 | [diff] [blame] | 3946 | xdg_surface_ack_configure, |
Jasper St. Pierre | ccf48fb | 2014-05-02 10:21:38 -0400 | [diff] [blame] | 3947 | xdg_surface_set_window_geometry, |
Jasper St. Pierre | ab2c108 | 2014-04-10 10:41:46 -0700 | [diff] [blame] | 3948 | xdg_surface_set_maximized, |
| 3949 | xdg_surface_unset_maximized, |
| 3950 | xdg_surface_set_fullscreen, |
| 3951 | xdg_surface_unset_fullscreen, |
| 3952 | xdg_surface_set_minimized, |
Rafael Antognolli | e2a3455 | 2013-12-03 15:35:45 -0200 | [diff] [blame] | 3953 | }; |
| 3954 | |
| 3955 | static void |
| 3956 | xdg_send_configure(struct weston_surface *surface, |
Jasper St. Pierre | ac985be | 2014-04-28 11:19:28 -0400 | [diff] [blame] | 3957 | int32_t width, int32_t height) |
Rafael Antognolli | e2a3455 | 2013-12-03 15:35:45 -0200 | [diff] [blame] | 3958 | { |
| 3959 | struct shell_surface *shsurf = get_shell_surface(surface); |
Jasper St. Pierre | ab2c108 | 2014-04-10 10:41:46 -0700 | [diff] [blame] | 3960 | uint32_t *s; |
| 3961 | struct wl_array states; |
| 3962 | uint32_t serial; |
Rafael Antognolli | e2a3455 | 2013-12-03 15:35:45 -0200 | [diff] [blame] | 3963 | |
U. Artie Eoff | cf5737a | 2014-01-17 10:08:25 -0800 | [diff] [blame] | 3964 | assert(shsurf); |
| 3965 | |
Jasper St. Pierre | ab2c108 | 2014-04-10 10:41:46 -0700 | [diff] [blame] | 3966 | if (!shsurf->resource) |
| 3967 | return; |
| 3968 | |
| 3969 | wl_array_init(&states); |
| 3970 | if (shsurf->requested_state.fullscreen) { |
| 3971 | s = wl_array_add(&states, sizeof *s); |
| 3972 | *s = XDG_SURFACE_STATE_FULLSCREEN; |
| 3973 | } else if (shsurf->requested_state.maximized) { |
| 3974 | s = wl_array_add(&states, sizeof *s); |
| 3975 | *s = XDG_SURFACE_STATE_MAXIMIZED; |
| 3976 | } |
Jasper St. Pierre | 5befdda | 2014-05-06 08:50:47 -0400 | [diff] [blame] | 3977 | if (shsurf->resize_edges != 0) { |
| 3978 | s = wl_array_add(&states, sizeof *s); |
| 3979 | *s = XDG_SURFACE_STATE_RESIZING; |
| 3980 | } |
Jasper St. Pierre | 973d787 | 2014-05-06 08:44:29 -0400 | [diff] [blame] | 3981 | if (shsurf->focus_count > 0) { |
| 3982 | s = wl_array_add(&states, sizeof *s); |
| 3983 | *s = XDG_SURFACE_STATE_ACTIVATED; |
| 3984 | } |
Jasper St. Pierre | ab2c108 | 2014-04-10 10:41:46 -0700 | [diff] [blame] | 3985 | |
| 3986 | serial = wl_display_next_serial(shsurf->surface->compositor->wl_display); |
| 3987 | xdg_surface_send_configure(shsurf->resource, width, height, &states, serial); |
| 3988 | |
| 3989 | wl_array_release(&states); |
Rafael Antognolli | e2a3455 | 2013-12-03 15:35:45 -0200 | [diff] [blame] | 3990 | } |
| 3991 | |
| 3992 | static const struct weston_shell_client xdg_client = { |
Giulio Camuffo | f05d18f | 2015-12-11 20:57:05 +0200 | [diff] [blame^] | 3993 | xdg_send_configure, |
| 3994 | NULL |
Rafael Antognolli | e2a3455 | 2013-12-03 15:35:45 -0200 | [diff] [blame] | 3995 | }; |
| 3996 | |
| 3997 | static void |
Jasper St. Pierre | 084aa0b | 2015-02-13 14:02:00 +0800 | [diff] [blame] | 3998 | xdg_shell_destroy(struct wl_client *client, |
| 3999 | struct wl_resource *resource) |
| 4000 | { |
Jonas Ådahl | 49d77d2 | 2015-03-18 16:20:51 +0800 | [diff] [blame] | 4001 | struct shell_client *sc = wl_resource_get_user_data(resource); |
| 4002 | struct wl_resource *shsurf_resource; |
| 4003 | struct shell_surface *shsurf; |
| 4004 | |
| 4005 | wl_resource_for_each(shsurf_resource, &sc->surface_list) { |
| 4006 | shsurf = wl_resource_get_user_data(shsurf_resource); |
| 4007 | if (shsurf->owner_resource == resource) { |
| 4008 | wl_resource_post_error( |
| 4009 | resource, |
| 4010 | XDG_SHELL_ERROR_DEFUNCT_SURFACES, |
| 4011 | "not all child surface objects destroyed"); |
| 4012 | return; |
| 4013 | } |
| 4014 | } |
| 4015 | |
Jasper St. Pierre | 084aa0b | 2015-02-13 14:02:00 +0800 | [diff] [blame] | 4016 | wl_resource_destroy(resource); |
| 4017 | } |
| 4018 | |
| 4019 | static void |
Rafael Antognolli | e2a3455 | 2013-12-03 15:35:45 -0200 | [diff] [blame] | 4020 | xdg_use_unstable_version(struct wl_client *client, |
| 4021 | struct wl_resource *resource, |
| 4022 | int32_t version) |
| 4023 | { |
| 4024 | if (version > 1) { |
| 4025 | wl_resource_post_error(resource, |
| 4026 | 1, |
| 4027 | "xdg-shell:: version not implemented yet."); |
| 4028 | return; |
| 4029 | } |
| 4030 | } |
| 4031 | |
| 4032 | static struct shell_surface * |
Jason Ekstrand | 9e9512f | 2014-04-16 21:12:10 -0500 | [diff] [blame] | 4033 | create_xdg_surface(struct shell_client *owner, void *shell, |
| 4034 | struct weston_surface *surface, |
Rafael Antognolli | e2a3455 | 2013-12-03 15:35:45 -0200 | [diff] [blame] | 4035 | const struct weston_shell_client *client) |
| 4036 | { |
| 4037 | struct shell_surface *shsurf; |
Rafael Antognolli | e2a3455 | 2013-12-03 15:35:45 -0200 | [diff] [blame] | 4038 | |
Jason Ekstrand | 9e9512f | 2014-04-16 21:12:10 -0500 | [diff] [blame] | 4039 | shsurf = create_common_surface(owner, shell, surface, client); |
Pekka Paalanen | e972b27 | 2014-10-01 14:03:56 +0300 | [diff] [blame] | 4040 | if (!shsurf) |
| 4041 | return NULL; |
| 4042 | |
Pekka Paalanen | b502654 | 2014-11-12 15:09:24 +0200 | [diff] [blame] | 4043 | set_type(shsurf, SHELL_SURFACE_TOPLEVEL); |
Rafael Antognolli | e2a3455 | 2013-12-03 15:35:45 -0200 | [diff] [blame] | 4044 | |
| 4045 | return shsurf; |
| 4046 | } |
| 4047 | |
| 4048 | static void |
| 4049 | xdg_get_xdg_surface(struct wl_client *client, |
| 4050 | struct wl_resource *resource, |
| 4051 | uint32_t id, |
| 4052 | struct wl_resource *surface_resource) |
| 4053 | { |
| 4054 | struct weston_surface *surface = |
| 4055 | wl_resource_get_user_data(surface_resource); |
Kristian Høgsberg | 2bff94e | 2014-02-11 12:22:51 -0800 | [diff] [blame] | 4056 | struct shell_client *sc = wl_resource_get_user_data(resource); |
| 4057 | struct desktop_shell *shell = sc->shell; |
Rafael Antognolli | e2a3455 | 2013-12-03 15:35:45 -0200 | [diff] [blame] | 4058 | struct shell_surface *shsurf; |
| 4059 | |
Jonas Ådahl | bf48e21 | 2015-02-06 10:15:28 +0800 | [diff] [blame] | 4060 | shsurf = get_shell_surface(surface); |
| 4061 | if (shsurf && shell_surface_is_xdg_surface(shsurf)) { |
| 4062 | wl_resource_post_error(resource, XDG_SHELL_ERROR_ROLE, |
| 4063 | "This wl_surface is already an " |
| 4064 | "xdg_surface"); |
| 4065 | return; |
| 4066 | } |
| 4067 | |
Pekka Paalanen | 50b6747 | 2014-10-01 15:02:41 +0300 | [diff] [blame] | 4068 | if (weston_surface_set_role(surface, "xdg_surface", |
| 4069 | resource, XDG_SHELL_ERROR_ROLE) < 0) |
Rafael Antognolli | e2a3455 | 2013-12-03 15:35:45 -0200 | [diff] [blame] | 4070 | return; |
Rafael Antognolli | e2a3455 | 2013-12-03 15:35:45 -0200 | [diff] [blame] | 4071 | |
Jason Ekstrand | 9e9512f | 2014-04-16 21:12:10 -0500 | [diff] [blame] | 4072 | shsurf = create_xdg_surface(sc, shell, surface, &xdg_client); |
Rafael Antognolli | e2a3455 | 2013-12-03 15:35:45 -0200 | [diff] [blame] | 4073 | if (!shsurf) { |
Pekka Paalanen | 50b6747 | 2014-10-01 15:02:41 +0300 | [diff] [blame] | 4074 | wl_resource_post_no_memory(surface_resource); |
Rafael Antognolli | e2a3455 | 2013-12-03 15:35:45 -0200 | [diff] [blame] | 4075 | return; |
| 4076 | } |
| 4077 | |
| 4078 | shsurf->resource = |
| 4079 | wl_resource_create(client, |
| 4080 | &xdg_surface_interface, 1, id); |
| 4081 | wl_resource_set_implementation(shsurf->resource, |
| 4082 | &xdg_surface_implementation, |
| 4083 | shsurf, shell_destroy_shell_surface); |
Jonas Ådahl | 49d77d2 | 2015-03-18 16:20:51 +0800 | [diff] [blame] | 4084 | shsurf->owner_resource = resource; |
| 4085 | wl_list_insert(&sc->surface_list, |
| 4086 | wl_resource_get_link(shsurf->resource)); |
Rafael Antognolli | e2a3455 | 2013-12-03 15:35:45 -0200 | [diff] [blame] | 4087 | } |
| 4088 | |
| 4089 | static bool |
| 4090 | shell_surface_is_xdg_surface(struct shell_surface *shsurf) |
| 4091 | { |
Kristian Høgsberg | 0b7d995 | 2014-02-03 15:50:38 -0800 | [diff] [blame] | 4092 | return shsurf->resource && |
| 4093 | wl_resource_instance_of(shsurf->resource, |
| 4094 | &xdg_surface_interface, |
| 4095 | &xdg_surface_implementation); |
Rafael Antognolli | e2a3455 | 2013-12-03 15:35:45 -0200 | [diff] [blame] | 4096 | } |
| 4097 | |
| 4098 | /* xdg-popup implementation */ |
| 4099 | |
| 4100 | static void |
| 4101 | xdg_popup_destroy(struct wl_client *client, |
| 4102 | struct wl_resource *resource) |
| 4103 | { |
| 4104 | wl_resource_destroy(resource); |
| 4105 | } |
| 4106 | |
Rafael Antognolli | e2a3455 | 2013-12-03 15:35:45 -0200 | [diff] [blame] | 4107 | static const struct xdg_popup_interface xdg_popup_implementation = { |
| 4108 | xdg_popup_destroy, |
Rafael Antognolli | e2a3455 | 2013-12-03 15:35:45 -0200 | [diff] [blame] | 4109 | }; |
| 4110 | |
| 4111 | static void |
| 4112 | xdg_popup_send_configure(struct weston_surface *surface, |
Jasper St. Pierre | ac985be | 2014-04-28 11:19:28 -0400 | [diff] [blame] | 4113 | int32_t width, int32_t height) |
Rafael Antognolli | e2a3455 | 2013-12-03 15:35:45 -0200 | [diff] [blame] | 4114 | { |
| 4115 | } |
| 4116 | |
| 4117 | static const struct weston_shell_client xdg_popup_client = { |
Giulio Camuffo | f05d18f | 2015-12-11 20:57:05 +0200 | [diff] [blame^] | 4118 | xdg_popup_send_configure, |
| 4119 | NULL |
Rafael Antognolli | e2a3455 | 2013-12-03 15:35:45 -0200 | [diff] [blame] | 4120 | }; |
| 4121 | |
| 4122 | static struct shell_surface * |
Jason Ekstrand | 9e9512f | 2014-04-16 21:12:10 -0500 | [diff] [blame] | 4123 | create_xdg_popup(struct shell_client *owner, void *shell, |
| 4124 | struct weston_surface *surface, |
Rafael Antognolli | e2a3455 | 2013-12-03 15:35:45 -0200 | [diff] [blame] | 4125 | const struct weston_shell_client *client, |
| 4126 | struct weston_surface *parent, |
| 4127 | struct shell_seat *seat, |
| 4128 | uint32_t serial, |
| 4129 | int32_t x, int32_t y) |
| 4130 | { |
Jonas Ådahl | ee45a55 | 2015-03-18 16:37:47 +0800 | [diff] [blame] | 4131 | struct shell_surface *shsurf; |
Jonas Ådahl | 24185e2 | 2015-02-27 18:37:41 +0800 | [diff] [blame] | 4132 | |
Jason Ekstrand | 9e9512f | 2014-04-16 21:12:10 -0500 | [diff] [blame] | 4133 | shsurf = create_common_surface(owner, shell, surface, client); |
Pekka Paalanen | e972b27 | 2014-10-01 14:03:56 +0300 | [diff] [blame] | 4134 | if (!shsurf) |
| 4135 | return NULL; |
| 4136 | |
Pekka Paalanen | b502654 | 2014-11-12 15:09:24 +0200 | [diff] [blame] | 4137 | set_type(shsurf, SHELL_SURFACE_POPUP); |
Rafael Antognolli | e2a3455 | 2013-12-03 15:35:45 -0200 | [diff] [blame] | 4138 | shsurf->popup.shseat = seat; |
| 4139 | shsurf->popup.serial = serial; |
| 4140 | shsurf->popup.x = x; |
| 4141 | shsurf->popup.y = y; |
| 4142 | shell_surface_set_parent(shsurf, parent); |
| 4143 | |
| 4144 | return shsurf; |
| 4145 | } |
| 4146 | |
| 4147 | static void |
| 4148 | xdg_get_xdg_popup(struct wl_client *client, |
| 4149 | struct wl_resource *resource, |
| 4150 | uint32_t id, |
| 4151 | struct wl_resource *surface_resource, |
| 4152 | struct wl_resource *parent_resource, |
| 4153 | struct wl_resource *seat_resource, |
| 4154 | uint32_t serial, |
Jasper St. Pierre | 14f330c | 2015-02-13 14:01:57 +0800 | [diff] [blame] | 4155 | int32_t x, int32_t y) |
Rafael Antognolli | e2a3455 | 2013-12-03 15:35:45 -0200 | [diff] [blame] | 4156 | { |
| 4157 | struct weston_surface *surface = |
| 4158 | wl_resource_get_user_data(surface_resource); |
Kristian Høgsberg | 2bff94e | 2014-02-11 12:22:51 -0800 | [diff] [blame] | 4159 | struct shell_client *sc = wl_resource_get_user_data(resource); |
| 4160 | struct desktop_shell *shell = sc->shell; |
Rafael Antognolli | e2a3455 | 2013-12-03 15:35:45 -0200 | [diff] [blame] | 4161 | struct shell_surface *shsurf; |
Jonas Ådahl | ee45a55 | 2015-03-18 16:37:47 +0800 | [diff] [blame] | 4162 | struct shell_surface *parent_shsurf; |
Rafael Antognolli | e2a3455 | 2013-12-03 15:35:45 -0200 | [diff] [blame] | 4163 | struct weston_surface *parent; |
| 4164 | struct shell_seat *seat; |
| 4165 | |
Jonas Ådahl | bf48e21 | 2015-02-06 10:15:28 +0800 | [diff] [blame] | 4166 | shsurf = get_shell_surface(surface); |
| 4167 | if (shsurf && shell_surface_is_xdg_popup(shsurf)) { |
| 4168 | wl_resource_post_error(resource, XDG_SHELL_ERROR_ROLE, |
| 4169 | "This wl_surface is already an " |
| 4170 | "xdg_popup"); |
| 4171 | return; |
| 4172 | } |
| 4173 | |
Pekka Paalanen | 50b6747 | 2014-10-01 15:02:41 +0300 | [diff] [blame] | 4174 | if (weston_surface_set_role(surface, "xdg_popup", |
| 4175 | resource, XDG_SHELL_ERROR_ROLE) < 0) |
Rafael Antognolli | e2a3455 | 2013-12-03 15:35:45 -0200 | [diff] [blame] | 4176 | return; |
Rafael Antognolli | e2a3455 | 2013-12-03 15:35:45 -0200 | [diff] [blame] | 4177 | |
| 4178 | if (!parent_resource) { |
| 4179 | wl_resource_post_error(surface_resource, |
| 4180 | WL_DISPLAY_ERROR_INVALID_OBJECT, |
| 4181 | "xdg_shell::get_xdg_popup requires a parent shell surface"); |
Jasper St. Pierre | 666bc92 | 2014-08-07 16:43:13 -0400 | [diff] [blame] | 4182 | return; |
Rafael Antognolli | e2a3455 | 2013-12-03 15:35:45 -0200 | [diff] [blame] | 4183 | } |
| 4184 | |
| 4185 | parent = wl_resource_get_user_data(parent_resource); |
Derek Foreman | bdc8c72 | 2015-10-07 11:51:29 -0500 | [diff] [blame] | 4186 | seat = get_shell_seat(wl_resource_get_user_data(seat_resource)); |
Rafael Antognolli | e2a3455 | 2013-12-03 15:35:45 -0200 | [diff] [blame] | 4187 | |
Jonas Ådahl | ee45a55 | 2015-03-18 16:37:47 +0800 | [diff] [blame] | 4188 | /* Verify that we are creating the top most popup when mapping, |
| 4189 | * as it's not until then we know whether it was mapped as most |
| 4190 | * top level or not. */ |
| 4191 | |
| 4192 | parent_shsurf = get_shell_surface(parent); |
Jonas Ådahl | bc5d849 | 2015-10-07 14:44:50 +0800 | [diff] [blame] | 4193 | if (!parent_shsurf || |
| 4194 | (!shell_surface_is_xdg_popup(parent_shsurf) && |
| 4195 | !shell_surface_is_xdg_surface(parent_shsurf))) { |
Jonas Ådahl | ee45a55 | 2015-03-18 16:37:47 +0800 | [diff] [blame] | 4196 | wl_resource_post_error(resource, |
| 4197 | XDG_SHELL_ERROR_INVALID_POPUP_PARENT, |
| 4198 | "xdg_popup parent was invalid"); |
| 4199 | return; |
| 4200 | } |
| 4201 | |
Jason Ekstrand | 9e9512f | 2014-04-16 21:12:10 -0500 | [diff] [blame] | 4202 | shsurf = create_xdg_popup(sc, shell, surface, &xdg_popup_client, |
Rafael Antognolli | e2a3455 | 2013-12-03 15:35:45 -0200 | [diff] [blame] | 4203 | parent, seat, serial, x, y); |
| 4204 | if (!shsurf) { |
Pekka Paalanen | 50b6747 | 2014-10-01 15:02:41 +0300 | [diff] [blame] | 4205 | wl_resource_post_no_memory(surface_resource); |
Rafael Antognolli | e2a3455 | 2013-12-03 15:35:45 -0200 | [diff] [blame] | 4206 | return; |
| 4207 | } |
| 4208 | |
| 4209 | shsurf->resource = |
| 4210 | wl_resource_create(client, |
| 4211 | &xdg_popup_interface, 1, id); |
| 4212 | wl_resource_set_implementation(shsurf->resource, |
| 4213 | &xdg_popup_implementation, |
| 4214 | shsurf, shell_destroy_shell_surface); |
Jonas Ådahl | 49d77d2 | 2015-03-18 16:20:51 +0800 | [diff] [blame] | 4215 | shsurf->owner_resource = resource; |
| 4216 | wl_list_insert(&sc->surface_list, |
| 4217 | wl_resource_get_link(shsurf->resource)); |
Rafael Antognolli | e2a3455 | 2013-12-03 15:35:45 -0200 | [diff] [blame] | 4218 | } |
| 4219 | |
Kristian Høgsberg | 2bff94e | 2014-02-11 12:22:51 -0800 | [diff] [blame] | 4220 | static void |
| 4221 | xdg_pong(struct wl_client *client, |
| 4222 | struct wl_resource *resource, uint32_t serial) |
| 4223 | { |
| 4224 | struct shell_client *sc = wl_resource_get_user_data(resource); |
Kristian Høgsberg | 2bff94e | 2014-02-11 12:22:51 -0800 | [diff] [blame] | 4225 | |
Kristian Høgsberg | dd62aba | 2014-02-12 09:56:19 -0800 | [diff] [blame] | 4226 | shell_client_pong(sc, serial); |
Kristian Høgsberg | 2bff94e | 2014-02-11 12:22:51 -0800 | [diff] [blame] | 4227 | } |
| 4228 | |
Rafael Antognolli | e2a3455 | 2013-12-03 15:35:45 -0200 | [diff] [blame] | 4229 | static bool |
| 4230 | shell_surface_is_xdg_popup(struct shell_surface *shsurf) |
| 4231 | { |
| 4232 | return wl_resource_instance_of(shsurf->resource, |
| 4233 | &xdg_popup_interface, |
| 4234 | &xdg_popup_implementation); |
| 4235 | } |
| 4236 | |
| 4237 | static const struct xdg_shell_interface xdg_implementation = { |
Jasper St. Pierre | 084aa0b | 2015-02-13 14:02:00 +0800 | [diff] [blame] | 4238 | xdg_shell_destroy, |
Rafael Antognolli | e2a3455 | 2013-12-03 15:35:45 -0200 | [diff] [blame] | 4239 | xdg_use_unstable_version, |
| 4240 | xdg_get_xdg_surface, |
Kristian Høgsberg | 2bff94e | 2014-02-11 12:22:51 -0800 | [diff] [blame] | 4241 | xdg_get_xdg_popup, |
| 4242 | xdg_pong |
Rafael Antognolli | e2a3455 | 2013-12-03 15:35:45 -0200 | [diff] [blame] | 4243 | }; |
| 4244 | |
| 4245 | static int |
| 4246 | xdg_shell_unversioned_dispatch(const void *implementation, |
| 4247 | void *_target, uint32_t opcode, |
| 4248 | const struct wl_message *message, |
| 4249 | union wl_argument *args) |
| 4250 | { |
| 4251 | struct wl_resource *resource = _target; |
Kristian Høgsberg | 2bff94e | 2014-02-11 12:22:51 -0800 | [diff] [blame] | 4252 | struct shell_client *sc = wl_resource_get_user_data(resource); |
Rafael Antognolli | e2a3455 | 2013-12-03 15:35:45 -0200 | [diff] [blame] | 4253 | |
Jasper St. Pierre | 084aa0b | 2015-02-13 14:02:00 +0800 | [diff] [blame] | 4254 | if (opcode != 1 /* XDG_SHELL_USE_UNSTABLE_VERSION */) { |
Rafael Antognolli | e2a3455 | 2013-12-03 15:35:45 -0200 | [diff] [blame] | 4255 | wl_resource_post_error(resource, |
| 4256 | WL_DISPLAY_ERROR_INVALID_OBJECT, |
| 4257 | "must call use_unstable_version first"); |
| 4258 | return 0; |
| 4259 | } |
| 4260 | |
Jasper St. Pierre | 5ba1e1d | 2015-02-13 14:02:02 +0800 | [diff] [blame] | 4261 | #define XDG_SERVER_VERSION 5 |
Rafael Antognolli | e2a3455 | 2013-12-03 15:35:45 -0200 | [diff] [blame] | 4262 | |
Kristian Høgsberg | 8d344a0 | 2013-12-08 22:27:11 -0800 | [diff] [blame] | 4263 | static_assert(XDG_SERVER_VERSION == XDG_SHELL_VERSION_CURRENT, |
| 4264 | "shell implementation doesn't match protocol version"); |
| 4265 | |
Rafael Antognolli | e2a3455 | 2013-12-03 15:35:45 -0200 | [diff] [blame] | 4266 | if (args[0].i != XDG_SERVER_VERSION) { |
| 4267 | wl_resource_post_error(resource, |
| 4268 | WL_DISPLAY_ERROR_INVALID_OBJECT, |
| 4269 | "incompatible version, server is %d " |
| 4270 | "client wants %d", |
| 4271 | XDG_SERVER_VERSION, args[0].i); |
| 4272 | return 0; |
| 4273 | } |
| 4274 | |
| 4275 | wl_resource_set_implementation(resource, &xdg_implementation, |
Kristian Høgsberg | 2bff94e | 2014-02-11 12:22:51 -0800 | [diff] [blame] | 4276 | sc, NULL); |
Rafael Antognolli | e2a3455 | 2013-12-03 15:35:45 -0200 | [diff] [blame] | 4277 | |
| 4278 | return 1; |
| 4279 | } |
| 4280 | |
| 4281 | /* end of xdg-shell implementation */ |
| 4282 | /***********************************/ |
| 4283 | |
Kristian Høgsberg | 0793756 | 2011-04-12 17:25:42 -0400 | [diff] [blame] | 4284 | static void |
Ander Conselvan de Oliveira | 859e885 | 2013-02-21 18:35:21 +0200 | [diff] [blame] | 4285 | shell_fade(struct desktop_shell *shell, enum fade_type type); |
| 4286 | |
Pekka Paalanen | 77346a6 | 2011-11-30 16:26:35 +0200 | [diff] [blame] | 4287 | static void |
Jason Ekstrand | 918f2dd | 2013-12-02 21:01:53 -0600 | [diff] [blame] | 4288 | configure_static_view(struct weston_view *ev, struct weston_layer *layer) |
Kristian Høgsberg | 962342c | 2012-06-26 16:29:50 -0400 | [diff] [blame] | 4289 | { |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 4290 | struct weston_view *v, *next; |
Kristian Høgsberg | 962342c | 2012-06-26 16:29:50 -0400 | [diff] [blame] | 4291 | |
Giulio Camuffo | 412e6a5 | 2014-07-09 22:12:56 +0300 | [diff] [blame] | 4292 | 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] | 4293 | if (v->output == ev->output && v != ev) { |
| 4294 | weston_view_unmap(v); |
| 4295 | v->surface->configure = NULL; |
Pekka Paalanen | 8274d90 | 2014-08-06 19:36:51 +0300 | [diff] [blame] | 4296 | weston_surface_set_label_func(v->surface, NULL); |
Kristian Høgsberg | 962342c | 2012-06-26 16:29:50 -0400 | [diff] [blame] | 4297 | } |
| 4298 | } |
| 4299 | |
Jason Ekstrand | 918f2dd | 2013-12-02 21:01:53 -0600 | [diff] [blame] | 4300 | weston_view_set_position(ev, ev->output->x, ev->output->y); |
Kristian Høgsberg | 962342c | 2012-06-26 16:29:50 -0400 | [diff] [blame] | 4301 | |
Giulio Camuffo | 412e6a5 | 2014-07-09 22:12:56 +0300 | [diff] [blame] | 4302 | if (wl_list_empty(&ev->layer_link.link)) { |
| 4303 | weston_layer_entry_insert(&layer->view_list, &ev->layer_link); |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 4304 | weston_compositor_schedule_repaint(ev->surface->compositor); |
Kristian Høgsberg | 962342c | 2012-06-26 16:29:50 -0400 | [diff] [blame] | 4305 | } |
| 4306 | } |
| 4307 | |
Pekka Paalanen | 8274d90 | 2014-08-06 19:36:51 +0300 | [diff] [blame] | 4308 | static int |
| 4309 | background_get_label(struct weston_surface *surface, char *buf, size_t len) |
| 4310 | { |
| 4311 | return snprintf(buf, len, "background for output %s", |
| 4312 | surface->output->name); |
| 4313 | } |
| 4314 | |
Kristian Høgsberg | 962342c | 2012-06-26 16:29:50 -0400 | [diff] [blame] | 4315 | static void |
Jason Ekstrand | 918f2dd | 2013-12-02 21:01:53 -0600 | [diff] [blame] | 4316 | 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] | 4317 | { |
Giulio Camuffo | 7fe01b1 | 2013-03-28 18:02:42 +0100 | [diff] [blame] | 4318 | struct desktop_shell *shell = es->configure_private; |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 4319 | struct weston_view *view; |
Kristian Høgsberg | af7b1ff | 2012-06-26 21:19:23 -0400 | [diff] [blame] | 4320 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 4321 | view = container_of(es->views.next, struct weston_view, surface_link); |
| 4322 | |
Jason Ekstrand | 918f2dd | 2013-12-02 21:01:53 -0600 | [diff] [blame] | 4323 | configure_static_view(view, &shell->background_layer); |
Kristian Høgsberg | af7b1ff | 2012-06-26 21:19:23 -0400 | [diff] [blame] | 4324 | } |
| 4325 | |
| 4326 | static void |
Kristian Høgsberg | 7584062 | 2011-09-06 13:48:16 -0400 | [diff] [blame] | 4327 | desktop_shell_set_background(struct wl_client *client, |
| 4328 | struct wl_resource *resource, |
Benjamin Franzke | d0f79ab | 2011-11-22 12:43:52 +0100 | [diff] [blame] | 4329 | struct wl_resource *output_resource, |
Kristian Høgsberg | 7584062 | 2011-09-06 13:48:16 -0400 | [diff] [blame] | 4330 | struct wl_resource *surface_resource) |
| 4331 | { |
Jason Ekstrand | 651f00e | 2013-06-14 10:07:54 -0500 | [diff] [blame] | 4332 | struct desktop_shell *shell = wl_resource_get_user_data(resource); |
Jason Ekstrand | 0f2ef7e | 2013-06-14 10:07:53 -0500 | [diff] [blame] | 4333 | struct weston_surface *surface = |
| 4334 | wl_resource_get_user_data(surface_resource); |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 4335 | struct weston_view *view, *next; |
Kristian Høgsberg | 7584062 | 2011-09-06 13:48:16 -0400 | [diff] [blame] | 4336 | |
Kristian Høgsberg | 962342c | 2012-06-26 16:29:50 -0400 | [diff] [blame] | 4337 | if (surface->configure) { |
| 4338 | wl_resource_post_error(surface_resource, |
| 4339 | WL_DISPLAY_ERROR_INVALID_OBJECT, |
| 4340 | "surface role already assigned"); |
| 4341 | return; |
| 4342 | } |
Benjamin Franzke | d0f79ab | 2011-11-22 12:43:52 +0100 | [diff] [blame] | 4343 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 4344 | wl_list_for_each_safe(view, next, &surface->views, surface_link) |
| 4345 | weston_view_destroy(view); |
| 4346 | view = weston_view_create(surface); |
| 4347 | |
Kristian Høgsberg | 962342c | 2012-06-26 16:29:50 -0400 | [diff] [blame] | 4348 | surface->configure = background_configure; |
Giulio Camuffo | 7fe01b1 | 2013-03-28 18:02:42 +0100 | [diff] [blame] | 4349 | surface->configure_private = shell; |
Pekka Paalanen | 8274d90 | 2014-08-06 19:36:51 +0300 | [diff] [blame] | 4350 | weston_surface_set_label_func(surface, background_get_label); |
Jason Ekstrand | a0d2dde | 2013-06-14 10:08:01 -0500 | [diff] [blame] | 4351 | surface->output = wl_resource_get_user_data(output_resource); |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 4352 | view->output = surface->output; |
Jonas Ådahl | 6d6fb61 | 2015-11-17 16:00:33 +0800 | [diff] [blame] | 4353 | weston_desktop_shell_send_configure(resource, 0, |
| 4354 | surface_resource, |
| 4355 | surface->output->width, |
| 4356 | surface->output->height); |
Kristian Høgsberg | 7584062 | 2011-09-06 13:48:16 -0400 | [diff] [blame] | 4357 | } |
| 4358 | |
Pekka Paalanen | 8274d90 | 2014-08-06 19:36:51 +0300 | [diff] [blame] | 4359 | static int |
| 4360 | panel_get_label(struct weston_surface *surface, char *buf, size_t len) |
| 4361 | { |
| 4362 | return snprintf(buf, len, "panel for output %s", |
| 4363 | surface->output->name); |
| 4364 | } |
| 4365 | |
Kristian Høgsberg | 7584062 | 2011-09-06 13:48:16 -0400 | [diff] [blame] | 4366 | static void |
Jason Ekstrand | 918f2dd | 2013-12-02 21:01:53 -0600 | [diff] [blame] | 4367 | 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] | 4368 | { |
Giulio Camuffo | 7fe01b1 | 2013-03-28 18:02:42 +0100 | [diff] [blame] | 4369 | struct desktop_shell *shell = es->configure_private; |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 4370 | struct weston_view *view; |
Kristian Høgsberg | af7b1ff | 2012-06-26 21:19:23 -0400 | [diff] [blame] | 4371 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 4372 | view = container_of(es->views.next, struct weston_view, surface_link); |
| 4373 | |
Jason Ekstrand | 918f2dd | 2013-12-02 21:01:53 -0600 | [diff] [blame] | 4374 | configure_static_view(view, &shell->panel_layer); |
Kristian Høgsberg | af7b1ff | 2012-06-26 21:19:23 -0400 | [diff] [blame] | 4375 | } |
| 4376 | |
| 4377 | static void |
Kristian Høgsberg | 7584062 | 2011-09-06 13:48:16 -0400 | [diff] [blame] | 4378 | desktop_shell_set_panel(struct wl_client *client, |
| 4379 | struct wl_resource *resource, |
Benjamin Franzke | d0f79ab | 2011-11-22 12:43:52 +0100 | [diff] [blame] | 4380 | struct wl_resource *output_resource, |
Kristian Høgsberg | 7584062 | 2011-09-06 13:48:16 -0400 | [diff] [blame] | 4381 | struct wl_resource *surface_resource) |
| 4382 | { |
Jason Ekstrand | 651f00e | 2013-06-14 10:07:54 -0500 | [diff] [blame] | 4383 | struct desktop_shell *shell = wl_resource_get_user_data(resource); |
Jason Ekstrand | 0f2ef7e | 2013-06-14 10:07:53 -0500 | [diff] [blame] | 4384 | struct weston_surface *surface = |
| 4385 | wl_resource_get_user_data(surface_resource); |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 4386 | struct weston_view *view, *next; |
Kristian Høgsberg | 7584062 | 2011-09-06 13:48:16 -0400 | [diff] [blame] | 4387 | |
Kristian Høgsberg | af7b1ff | 2012-06-26 21:19:23 -0400 | [diff] [blame] | 4388 | if (surface->configure) { |
| 4389 | wl_resource_post_error(surface_resource, |
| 4390 | WL_DISPLAY_ERROR_INVALID_OBJECT, |
| 4391 | "surface role already assigned"); |
| 4392 | return; |
| 4393 | } |
Benjamin Franzke | d0f79ab | 2011-11-22 12:43:52 +0100 | [diff] [blame] | 4394 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 4395 | wl_list_for_each_safe(view, next, &surface->views, surface_link) |
| 4396 | weston_view_destroy(view); |
| 4397 | view = weston_view_create(surface); |
| 4398 | |
Kristian Høgsberg | af7b1ff | 2012-06-26 21:19:23 -0400 | [diff] [blame] | 4399 | surface->configure = panel_configure; |
Giulio Camuffo | 7fe01b1 | 2013-03-28 18:02:42 +0100 | [diff] [blame] | 4400 | surface->configure_private = shell; |
Pekka Paalanen | 8274d90 | 2014-08-06 19:36:51 +0300 | [diff] [blame] | 4401 | weston_surface_set_label_func(surface, panel_get_label); |
Jason Ekstrand | a0d2dde | 2013-06-14 10:08:01 -0500 | [diff] [blame] | 4402 | surface->output = wl_resource_get_user_data(output_resource); |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 4403 | view->output = surface->output; |
Jonas Ådahl | 6d6fb61 | 2015-11-17 16:00:33 +0800 | [diff] [blame] | 4404 | weston_desktop_shell_send_configure(resource, 0, |
| 4405 | surface_resource, |
| 4406 | surface->output->width, |
| 4407 | surface->output->height); |
Kristian Høgsberg | 7584062 | 2011-09-06 13:48:16 -0400 | [diff] [blame] | 4408 | } |
| 4409 | |
Pekka Paalanen | 8274d90 | 2014-08-06 19:36:51 +0300 | [diff] [blame] | 4410 | static int |
| 4411 | lock_surface_get_label(struct weston_surface *surface, char *buf, size_t len) |
| 4412 | { |
| 4413 | return snprintf(buf, len, "lock window"); |
| 4414 | } |
| 4415 | |
Pekka Paalanen | 9ef3e01 | 2011-11-15 13:34:48 +0200 | [diff] [blame] | 4416 | static void |
Jason Ekstrand | 918f2dd | 2013-12-02 21:01:53 -0600 | [diff] [blame] | 4417 | 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] | 4418 | { |
Giulio Camuffo | 7fe01b1 | 2013-03-28 18:02:42 +0100 | [diff] [blame] | 4419 | struct desktop_shell *shell = surface->configure_private; |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 4420 | struct weston_view *view; |
| 4421 | |
| 4422 | view = container_of(surface->views.next, struct weston_view, surface_link); |
Kristian Høgsberg | 730c94d | 2012-06-26 21:44:35 -0400 | [diff] [blame] | 4423 | |
Jason Ekstrand | 918f2dd | 2013-12-02 21:01:53 -0600 | [diff] [blame] | 4424 | if (surface->width == 0) |
Giulio Camuffo | 184df50 | 2013-02-21 11:29:21 +0100 | [diff] [blame] | 4425 | return; |
| 4426 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 4427 | center_on_output(view, get_default_output(shell->compositor)); |
Kristian Høgsberg | 730c94d | 2012-06-26 21:44:35 -0400 | [diff] [blame] | 4428 | |
| 4429 | if (!weston_surface_is_mapped(surface)) { |
Giulio Camuffo | 412e6a5 | 2014-07-09 22:12:56 +0300 | [diff] [blame] | 4430 | weston_layer_entry_insert(&shell->lock_layer.view_list, |
| 4431 | &view->layer_link); |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 4432 | weston_view_update_transform(view); |
Ander Conselvan de Oliveira | 87524b6 | 2013-02-21 18:35:22 +0200 | [diff] [blame] | 4433 | shell_fade(shell, FADE_IN); |
Kristian Høgsberg | 730c94d | 2012-06-26 21:44:35 -0400 | [diff] [blame] | 4434 | } |
| 4435 | } |
| 4436 | |
| 4437 | static void |
Kristian Høgsberg | 27e3052 | 2012-04-11 23:18:23 -0400 | [diff] [blame] | 4438 | handle_lock_surface_destroy(struct wl_listener *listener, void *data) |
Kristian Høgsberg | 1ec0c31 | 2011-11-15 16:39:55 -0500 | [diff] [blame] | 4439 | { |
Tiago Vignatti | be14326 | 2012-04-16 17:31:41 +0300 | [diff] [blame] | 4440 | struct desktop_shell *shell = |
| 4441 | container_of(listener, struct desktop_shell, lock_surface_listener); |
Kristian Høgsberg | 1ec0c31 | 2011-11-15 16:39:55 -0500 | [diff] [blame] | 4442 | |
Martin Minarik | 6d11836 | 2012-06-07 18:01:59 +0200 | [diff] [blame] | 4443 | weston_log("lock surface gone\n"); |
Kristian Høgsberg | 1ec0c31 | 2011-11-15 16:39:55 -0500 | [diff] [blame] | 4444 | shell->lock_surface = NULL; |
| 4445 | } |
| 4446 | |
| 4447 | static void |
Pekka Paalanen | 9ef3e01 | 2011-11-15 13:34:48 +0200 | [diff] [blame] | 4448 | desktop_shell_set_lock_surface(struct wl_client *client, |
| 4449 | struct wl_resource *resource, |
| 4450 | struct wl_resource *surface_resource) |
| 4451 | { |
Jason Ekstrand | 651f00e | 2013-06-14 10:07:54 -0500 | [diff] [blame] | 4452 | struct desktop_shell *shell = wl_resource_get_user_data(resource); |
Jason Ekstrand | 0f2ef7e | 2013-06-14 10:07:53 -0500 | [diff] [blame] | 4453 | struct weston_surface *surface = |
| 4454 | wl_resource_get_user_data(surface_resource); |
Pekka Paalanen | 9826223 | 2011-12-01 10:42:22 +0200 | [diff] [blame] | 4455 | |
Pekka Paalanen | f0fc70d | 2011-11-15 13:34:54 +0200 | [diff] [blame] | 4456 | shell->prepare_event_sent = false; |
Kristian Høgsberg | af867cc | 2011-11-15 13:34:49 +0200 | [diff] [blame] | 4457 | |
Pekka Paalanen | f0fc70d | 2011-11-15 13:34:54 +0200 | [diff] [blame] | 4458 | if (!shell->locked) |
| 4459 | return; |
| 4460 | |
Pekka Paalanen | 9826223 | 2011-12-01 10:42:22 +0200 | [diff] [blame] | 4461 | shell->lock_surface = surface; |
Pekka Paalanen | f0fc70d | 2011-11-15 13:34:54 +0200 | [diff] [blame] | 4462 | |
Kristian Høgsberg | 27e3052 | 2012-04-11 23:18:23 -0400 | [diff] [blame] | 4463 | shell->lock_surface_listener.notify = handle_lock_surface_destroy; |
Jason Ekstrand | 651f00e | 2013-06-14 10:07:54 -0500 | [diff] [blame] | 4464 | wl_signal_add(&surface->destroy_signal, |
Kristian Høgsberg | 27e3052 | 2012-04-11 23:18:23 -0400 | [diff] [blame] | 4465 | &shell->lock_surface_listener); |
Pekka Paalanen | 57da4a8 | 2011-11-23 16:42:16 +0200 | [diff] [blame] | 4466 | |
Kristian Høgsberg | aa2ee8b | 2013-10-30 15:49:45 -0700 | [diff] [blame] | 4467 | weston_view_create(surface); |
Kristian Høgsberg | 730c94d | 2012-06-26 21:44:35 -0400 | [diff] [blame] | 4468 | surface->configure = lock_surface_configure; |
Giulio Camuffo | 7fe01b1 | 2013-03-28 18:02:42 +0100 | [diff] [blame] | 4469 | surface->configure_private = shell; |
Pekka Paalanen | 8274d90 | 2014-08-06 19:36:51 +0300 | [diff] [blame] | 4470 | weston_surface_set_label_func(surface, lock_surface_get_label); |
Pekka Paalanen | f0fc70d | 2011-11-15 13:34:54 +0200 | [diff] [blame] | 4471 | } |
| 4472 | |
| 4473 | static void |
Tiago Vignatti | be14326 | 2012-04-16 17:31:41 +0300 | [diff] [blame] | 4474 | resume_desktop(struct desktop_shell *shell) |
Pekka Paalanen | f0fc70d | 2011-11-15 13:34:54 +0200 | [diff] [blame] | 4475 | { |
Kristian Høgsberg | 4476aaf | 2012-06-25 14:03:13 -0400 | [diff] [blame] | 4476 | struct workspace *ws = get_current_workspace(shell); |
Pekka Paalanen | 77346a6 | 2011-11-30 16:26:35 +0200 | [diff] [blame] | 4477 | |
Kristian Høgsberg | 3be2ce9 | 2012-02-29 12:42:35 -0500 | [diff] [blame] | 4478 | wl_list_remove(&shell->lock_layer.link); |
Philipp Brüschweiler | 711fda8 | 2012-08-09 18:50:43 +0200 | [diff] [blame] | 4479 | if (shell->showing_input_panels) { |
Manuel Bachmann | 805d2f5 | 2014-03-05 12:21:34 +0100 | [diff] [blame] | 4480 | wl_list_insert(&shell->compositor->cursor_layer.link, |
Philipp Brüschweiler | 711fda8 | 2012-08-09 18:50:43 +0200 | [diff] [blame] | 4481 | &shell->input_panel_layer.link); |
| 4482 | wl_list_insert(&shell->input_panel_layer.link, |
Manuel Bachmann | 805d2f5 | 2014-03-05 12:21:34 +0100 | [diff] [blame] | 4483 | &shell->fullscreen_layer.link); |
Philipp Brüschweiler | 711fda8 | 2012-08-09 18:50:43 +0200 | [diff] [blame] | 4484 | } else { |
Manuel Bachmann | 805d2f5 | 2014-03-05 12:21:34 +0100 | [diff] [blame] | 4485 | wl_list_insert(&shell->compositor->cursor_layer.link, |
| 4486 | &shell->fullscreen_layer.link); |
Philipp Brüschweiler | 711fda8 | 2012-08-09 18:50:43 +0200 | [diff] [blame] | 4487 | } |
Manuel Bachmann | 805d2f5 | 2014-03-05 12:21:34 +0100 | [diff] [blame] | 4488 | wl_list_insert(&shell->fullscreen_layer.link, |
| 4489 | &shell->panel_layer.link); |
| 4490 | wl_list_insert(&shell->panel_layer.link, |
| 4491 | &ws->layer.link), |
Pekka Paalanen | f0fc70d | 2011-11-15 13:34:54 +0200 | [diff] [blame] | 4492 | |
Kristian Høgsberg | 2f5faff | 2012-07-31 16:36:34 -0400 | [diff] [blame] | 4493 | restore_focus_state(shell, get_current_workspace(shell)); |
Jonas Ådahl | 0476974 | 2012-06-13 00:01:24 +0200 | [diff] [blame] | 4494 | |
Pekka Paalanen | f0fc70d | 2011-11-15 13:34:54 +0200 | [diff] [blame] | 4495 | shell->locked = false; |
Ander Conselvan de Oliveira | 87524b6 | 2013-02-21 18:35:22 +0200 | [diff] [blame] | 4496 | shell_fade(shell, FADE_IN); |
Pekka Paalanen | fc6d91a | 2012-02-10 15:33:10 +0200 | [diff] [blame] | 4497 | weston_compositor_damage_all(shell->compositor); |
Pekka Paalanen | 9ef3e01 | 2011-11-15 13:34:48 +0200 | [diff] [blame] | 4498 | } |
| 4499 | |
| 4500 | static void |
| 4501 | desktop_shell_unlock(struct wl_client *client, |
| 4502 | struct wl_resource *resource) |
| 4503 | { |
Jason Ekstrand | 651f00e | 2013-06-14 10:07:54 -0500 | [diff] [blame] | 4504 | struct desktop_shell *shell = wl_resource_get_user_data(resource); |
Pekka Paalanen | 9ef3e01 | 2011-11-15 13:34:48 +0200 | [diff] [blame] | 4505 | |
Pekka Paalanen | 9ef3e01 | 2011-11-15 13:34:48 +0200 | [diff] [blame] | 4506 | shell->prepare_event_sent = false; |
Pekka Paalanen | f0fc70d | 2011-11-15 13:34:54 +0200 | [diff] [blame] | 4507 | |
| 4508 | if (shell->locked) |
| 4509 | resume_desktop(shell); |
Pekka Paalanen | 9ef3e01 | 2011-11-15 13:34:48 +0200 | [diff] [blame] | 4510 | } |
| 4511 | |
Kristian Høgsberg | d56bd90 | 2012-06-05 09:58:51 -0400 | [diff] [blame] | 4512 | static void |
Ander Conselvan de Oliveira | b9d2a0f | 2012-06-28 18:08:05 +0300 | [diff] [blame] | 4513 | desktop_shell_set_grab_surface(struct wl_client *client, |
Kristian Høgsberg | d56bd90 | 2012-06-05 09:58:51 -0400 | [diff] [blame] | 4514 | struct wl_resource *resource, |
| 4515 | struct wl_resource *surface_resource) |
| 4516 | { |
Jason Ekstrand | 651f00e | 2013-06-14 10:07:54 -0500 | [diff] [blame] | 4517 | struct desktop_shell *shell = wl_resource_get_user_data(resource); |
Kristian Høgsberg | d56bd90 | 2012-06-05 09:58:51 -0400 | [diff] [blame] | 4518 | |
Jason Ekstrand | 0f2ef7e | 2013-06-14 10:07:53 -0500 | [diff] [blame] | 4519 | shell->grab_surface = wl_resource_get_user_data(surface_resource); |
Kristian Høgsberg | 48588f8 | 2013-10-24 15:51:35 -0700 | [diff] [blame] | 4520 | weston_view_create(shell->grab_surface); |
Kristian Høgsberg | d56bd90 | 2012-06-05 09:58:51 -0400 | [diff] [blame] | 4521 | } |
| 4522 | |
Pekka Paalanen | 79346ab | 2013-05-22 18:03:09 +0300 | [diff] [blame] | 4523 | static void |
| 4524 | desktop_shell_desktop_ready(struct wl_client *client, |
| 4525 | struct wl_resource *resource) |
| 4526 | { |
Jason Ekstrand | 651f00e | 2013-06-14 10:07:54 -0500 | [diff] [blame] | 4527 | struct desktop_shell *shell = wl_resource_get_user_data(resource); |
Pekka Paalanen | 79346ab | 2013-05-22 18:03:09 +0300 | [diff] [blame] | 4528 | |
| 4529 | shell_fade_startup(shell); |
| 4530 | } |
| 4531 | |
Jonny Lamb | 765760d | 2014-08-20 15:53:19 +0200 | [diff] [blame] | 4532 | static void |
| 4533 | desktop_shell_set_panel_position(struct wl_client *client, |
| 4534 | struct wl_resource *resource, |
| 4535 | uint32_t position) |
| 4536 | { |
| 4537 | struct desktop_shell *shell = wl_resource_get_user_data(resource); |
| 4538 | |
Jonas Ådahl | 6d6fb61 | 2015-11-17 16:00:33 +0800 | [diff] [blame] | 4539 | if (position != WESTON_DESKTOP_SHELL_PANEL_POSITION_TOP && |
| 4540 | position != WESTON_DESKTOP_SHELL_PANEL_POSITION_BOTTOM && |
| 4541 | position != WESTON_DESKTOP_SHELL_PANEL_POSITION_LEFT && |
| 4542 | position != WESTON_DESKTOP_SHELL_PANEL_POSITION_RIGHT) { |
Jonny Lamb | 765760d | 2014-08-20 15:53:19 +0200 | [diff] [blame] | 4543 | wl_resource_post_error(resource, |
Jonas Ådahl | 6d6fb61 | 2015-11-17 16:00:33 +0800 | [diff] [blame] | 4544 | WESTON_DESKTOP_SHELL_ERROR_INVALID_ARGUMENT, |
Jonny Lamb | 765760d | 2014-08-20 15:53:19 +0200 | [diff] [blame] | 4545 | "bad position argument"); |
| 4546 | return; |
| 4547 | } |
| 4548 | |
| 4549 | shell->panel_position = position; |
| 4550 | } |
| 4551 | |
Jonas Ådahl | 6d6fb61 | 2015-11-17 16:00:33 +0800 | [diff] [blame] | 4552 | static const struct weston_desktop_shell_interface desktop_shell_implementation = { |
Kristian Høgsberg | 7584062 | 2011-09-06 13:48:16 -0400 | [diff] [blame] | 4553 | desktop_shell_set_background, |
Pekka Paalanen | 9ef3e01 | 2011-11-15 13:34:48 +0200 | [diff] [blame] | 4554 | desktop_shell_set_panel, |
| 4555 | desktop_shell_set_lock_surface, |
Kristian Høgsberg | d56bd90 | 2012-06-05 09:58:51 -0400 | [diff] [blame] | 4556 | desktop_shell_unlock, |
Pekka Paalanen | 79346ab | 2013-05-22 18:03:09 +0300 | [diff] [blame] | 4557 | desktop_shell_set_grab_surface, |
Jonny Lamb | 765760d | 2014-08-20 15:53:19 +0200 | [diff] [blame] | 4558 | desktop_shell_desktop_ready, |
| 4559 | desktop_shell_set_panel_position |
Kristian Høgsberg | 7584062 | 2011-09-06 13:48:16 -0400 | [diff] [blame] | 4560 | }; |
| 4561 | |
Pekka Paalanen | 92a0dc4 | 2011-11-28 15:34:13 +0200 | [diff] [blame] | 4562 | static enum shell_surface_type |
Kristian Høgsberg | 8334bc1 | 2012-01-03 10:29:47 -0500 | [diff] [blame] | 4563 | get_shell_surface_type(struct weston_surface *surface) |
Pekka Paalanen | 92a0dc4 | 2011-11-28 15:34:13 +0200 | [diff] [blame] | 4564 | { |
| 4565 | struct shell_surface *shsurf; |
| 4566 | |
| 4567 | shsurf = get_shell_surface(surface); |
| 4568 | if (!shsurf) |
Pekka Paalanen | 9826223 | 2011-12-01 10:42:22 +0200 | [diff] [blame] | 4569 | return SHELL_SURFACE_NONE; |
Pekka Paalanen | 92a0dc4 | 2011-11-28 15:34:13 +0200 | [diff] [blame] | 4570 | return shsurf->type; |
| 4571 | } |
| 4572 | |
Kristian Høgsberg | 7584062 | 2011-09-06 13:48:16 -0400 | [diff] [blame] | 4573 | static void |
Derek Foreman | 8ae2db5 | 2015-07-15 13:00:36 -0500 | [diff] [blame] | 4574 | move_binding(struct weston_pointer *pointer, uint32_t time, |
| 4575 | uint32_t button, void *data) |
Kristian Høgsberg | 0793756 | 2011-04-12 17:25:42 -0400 | [diff] [blame] | 4576 | { |
Rafal Mielniczuk | b2917a2 | 2014-01-05 20:04:59 +0100 | [diff] [blame] | 4577 | struct weston_surface *focus; |
Pekka Paalanen | 01388e2 | 2013-04-25 13:57:44 +0300 | [diff] [blame] | 4578 | struct weston_surface *surface; |
Kristian Høgsberg | 938b8fa | 2012-05-18 13:46:27 -0400 | [diff] [blame] | 4579 | struct shell_surface *shsurf; |
Kristian Høgsberg | d2abb83 | 2011-11-23 10:52:40 -0500 | [diff] [blame] | 4580 | |
Derek Foreman | 8ae2db5 | 2015-07-15 13:00:36 -0500 | [diff] [blame] | 4581 | if (pointer->focus == NULL) |
Rafal Mielniczuk | b2917a2 | 2014-01-05 20:04:59 +0100 | [diff] [blame] | 4582 | return; |
| 4583 | |
Derek Foreman | 8ae2db5 | 2015-07-15 13:00:36 -0500 | [diff] [blame] | 4584 | focus = pointer->focus->surface; |
Rafal Mielniczuk | b2917a2 | 2014-01-05 20:04:59 +0100 | [diff] [blame] | 4585 | |
Pekka Paalanen | 01388e2 | 2013-04-25 13:57:44 +0300 | [diff] [blame] | 4586 | surface = weston_surface_get_main_surface(focus); |
Benjamin Franzke | d0f79ab | 2011-11-22 12:43:52 +0100 | [diff] [blame] | 4587 | if (surface == NULL) |
| 4588 | return; |
Kristian Høgsberg | 0793756 | 2011-04-12 17:25:42 -0400 | [diff] [blame] | 4589 | |
Kristian Høgsberg | 938b8fa | 2012-05-18 13:46:27 -0400 | [diff] [blame] | 4590 | shsurf = get_shell_surface(surface); |
Rafael Antognolli | 03b1659 | 2013-12-03 15:35:42 -0200 | [diff] [blame] | 4591 | if (shsurf == NULL || shsurf->state.fullscreen || |
| 4592 | shsurf->state.maximized) |
Kristian Høgsberg | 938b8fa | 2012-05-18 13:46:27 -0400 | [diff] [blame] | 4593 | return; |
| 4594 | |
Derek Foreman | 794fa0e | 2015-07-15 13:00:38 -0500 | [diff] [blame] | 4595 | surface_move(shsurf, pointer, false); |
Kristian Høgsberg | 0793756 | 2011-04-12 17:25:42 -0400 | [diff] [blame] | 4596 | } |
| 4597 | |
| 4598 | static void |
Derek Foreman | 8ae2db5 | 2015-07-15 13:00:36 -0500 | [diff] [blame] | 4599 | maximize_binding(struct weston_keyboard *keyboard, uint32_t time, |
| 4600 | uint32_t button, void *data) |
Rafael Antognolli | ea997ac | 2013-12-03 15:35:48 -0200 | [diff] [blame] | 4601 | { |
Derek Foreman | 8ae2db5 | 2015-07-15 13:00:36 -0500 | [diff] [blame] | 4602 | struct weston_surface *focus = keyboard->focus; |
Rafael Antognolli | ea997ac | 2013-12-03 15:35:48 -0200 | [diff] [blame] | 4603 | struct weston_surface *surface; |
| 4604 | struct shell_surface *shsurf; |
| 4605 | |
| 4606 | surface = weston_surface_get_main_surface(focus); |
| 4607 | if (surface == NULL) |
| 4608 | return; |
| 4609 | |
| 4610 | shsurf = get_shell_surface(surface); |
| 4611 | if (shsurf == NULL) |
| 4612 | return; |
| 4613 | |
| 4614 | if (!shell_surface_is_xdg_surface(shsurf)) |
| 4615 | return; |
| 4616 | |
Jasper St. Pierre | ab2c108 | 2014-04-10 10:41:46 -0700 | [diff] [blame] | 4617 | shsurf->state_requested = true; |
| 4618 | shsurf->requested_state.maximized = !shsurf->state.maximized; |
Jasper St. Pierre | 9aa8ce6 | 2014-04-11 16:18:54 -0700 | [diff] [blame] | 4619 | send_configure_for_surface(shsurf); |
Rafael Antognolli | ea997ac | 2013-12-03 15:35:48 -0200 | [diff] [blame] | 4620 | } |
| 4621 | |
| 4622 | static void |
Derek Foreman | 8ae2db5 | 2015-07-15 13:00:36 -0500 | [diff] [blame] | 4623 | fullscreen_binding(struct weston_keyboard *keyboard, uint32_t time, |
| 4624 | uint32_t button, void *data) |
Rafael Antognolli | ea997ac | 2013-12-03 15:35:48 -0200 | [diff] [blame] | 4625 | { |
Derek Foreman | 8ae2db5 | 2015-07-15 13:00:36 -0500 | [diff] [blame] | 4626 | struct weston_surface *focus = keyboard->focus; |
Rafael Antognolli | ea997ac | 2013-12-03 15:35:48 -0200 | [diff] [blame] | 4627 | struct weston_surface *surface; |
| 4628 | struct shell_surface *shsurf; |
| 4629 | |
| 4630 | surface = weston_surface_get_main_surface(focus); |
| 4631 | if (surface == NULL) |
| 4632 | return; |
| 4633 | |
| 4634 | shsurf = get_shell_surface(surface); |
| 4635 | if (shsurf == NULL) |
| 4636 | return; |
| 4637 | |
| 4638 | if (!shell_surface_is_xdg_surface(shsurf)) |
| 4639 | return; |
| 4640 | |
Jasper St. Pierre | ab2c108 | 2014-04-10 10:41:46 -0700 | [diff] [blame] | 4641 | shsurf->state_requested = true; |
| 4642 | shsurf->requested_state.fullscreen = !shsurf->state.fullscreen; |
Boyan Ding | 32abdbb | 2014-06-26 10:19:32 +0800 | [diff] [blame] | 4643 | shsurf->fullscreen_output = shsurf->output; |
Jasper St. Pierre | 9aa8ce6 | 2014-04-11 16:18:54 -0700 | [diff] [blame] | 4644 | send_configure_for_surface(shsurf); |
Rafael Antognolli | ea997ac | 2013-12-03 15:35:48 -0200 | [diff] [blame] | 4645 | } |
| 4646 | |
| 4647 | static void |
Derek Foreman | 8ae2db5 | 2015-07-15 13:00:36 -0500 | [diff] [blame] | 4648 | touch_move_binding(struct weston_touch *touch, uint32_t time, void *data) |
Neil Roberts | aba0f25 | 2013-10-03 16:43:05 +0100 | [diff] [blame] | 4649 | { |
Derek Foreman | 362656b | 2014-09-04 10:23:05 -0500 | [diff] [blame] | 4650 | struct weston_surface *focus; |
Neil Roberts | aba0f25 | 2013-10-03 16:43:05 +0100 | [diff] [blame] | 4651 | struct weston_surface *surface; |
| 4652 | struct shell_surface *shsurf; |
| 4653 | |
Derek Foreman | 8ae2db5 | 2015-07-15 13:00:36 -0500 | [diff] [blame] | 4654 | if (touch->focus == NULL) |
Derek Foreman | 362656b | 2014-09-04 10:23:05 -0500 | [diff] [blame] | 4655 | return; |
| 4656 | |
Derek Foreman | 8ae2db5 | 2015-07-15 13:00:36 -0500 | [diff] [blame] | 4657 | focus = touch->focus->surface; |
Neil Roberts | aba0f25 | 2013-10-03 16:43:05 +0100 | [diff] [blame] | 4658 | surface = weston_surface_get_main_surface(focus); |
| 4659 | if (surface == NULL) |
| 4660 | return; |
| 4661 | |
| 4662 | shsurf = get_shell_surface(surface); |
Rafael Antognolli | 03b1659 | 2013-12-03 15:35:42 -0200 | [diff] [blame] | 4663 | if (shsurf == NULL || shsurf->state.fullscreen || |
| 4664 | shsurf->state.maximized) |
Neil Roberts | aba0f25 | 2013-10-03 16:43:05 +0100 | [diff] [blame] | 4665 | return; |
| 4666 | |
Derek Foreman | b7674ae | 2015-07-15 13:00:37 -0500 | [diff] [blame] | 4667 | surface_touch_move(shsurf, touch); |
Neil Roberts | aba0f25 | 2013-10-03 16:43:05 +0100 | [diff] [blame] | 4668 | } |
| 4669 | |
| 4670 | static void |
Derek Foreman | 8ae2db5 | 2015-07-15 13:00:36 -0500 | [diff] [blame] | 4671 | resize_binding(struct weston_pointer *pointer, uint32_t time, |
| 4672 | uint32_t button, void *data) |
Kristian Høgsberg | 0793756 | 2011-04-12 17:25:42 -0400 | [diff] [blame] | 4673 | { |
Rafal Mielniczuk | b2917a2 | 2014-01-05 20:04:59 +0100 | [diff] [blame] | 4674 | struct weston_surface *focus; |
Pekka Paalanen | 01388e2 | 2013-04-25 13:57:44 +0300 | [diff] [blame] | 4675 | struct weston_surface *surface; |
Kristian Høgsberg | 0793756 | 2011-04-12 17:25:42 -0400 | [diff] [blame] | 4676 | uint32_t edges = 0; |
| 4677 | int32_t x, y; |
Pekka Paalanen | 9d1613e | 2011-11-25 12:09:16 +0200 | [diff] [blame] | 4678 | struct shell_surface *shsurf; |
Kristian Høgsberg | d2abb83 | 2011-11-23 10:52:40 -0500 | [diff] [blame] | 4679 | |
Derek Foreman | 8ae2db5 | 2015-07-15 13:00:36 -0500 | [diff] [blame] | 4680 | if (pointer->focus == NULL) |
Rafal Mielniczuk | b2917a2 | 2014-01-05 20:04:59 +0100 | [diff] [blame] | 4681 | return; |
| 4682 | |
Derek Foreman | 8ae2db5 | 2015-07-15 13:00:36 -0500 | [diff] [blame] | 4683 | focus = pointer->focus->surface; |
Rafal Mielniczuk | b2917a2 | 2014-01-05 20:04:59 +0100 | [diff] [blame] | 4684 | |
Pekka Paalanen | 01388e2 | 2013-04-25 13:57:44 +0300 | [diff] [blame] | 4685 | surface = weston_surface_get_main_surface(focus); |
Benjamin Franzke | d0f79ab | 2011-11-22 12:43:52 +0100 | [diff] [blame] | 4686 | if (surface == NULL) |
| 4687 | return; |
Pekka Paalanen | 92a0dc4 | 2011-11-28 15:34:13 +0200 | [diff] [blame] | 4688 | |
Pekka Paalanen | 9d1613e | 2011-11-25 12:09:16 +0200 | [diff] [blame] | 4689 | shsurf = get_shell_surface(surface); |
Rafael Antognolli | 03b1659 | 2013-12-03 15:35:42 -0200 | [diff] [blame] | 4690 | if (shsurf == NULL || shsurf->state.fullscreen || |
| 4691 | shsurf->state.maximized) |
Pekka Paalanen | 92a0dc4 | 2011-11-28 15:34:13 +0200 | [diff] [blame] | 4692 | return; |
| 4693 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 4694 | weston_view_from_global(shsurf->view, |
Derek Foreman | 8ae2db5 | 2015-07-15 13:00:36 -0500 | [diff] [blame] | 4695 | wl_fixed_to_int(pointer->grab_x), |
| 4696 | wl_fixed_to_int(pointer->grab_y), |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 4697 | &x, &y); |
Kristian Høgsberg | 0793756 | 2011-04-12 17:25:42 -0400 | [diff] [blame] | 4698 | |
Jason Ekstrand | 918f2dd | 2013-12-02 21:01:53 -0600 | [diff] [blame] | 4699 | if (x < shsurf->surface->width / 3) |
Pekka Paalanen | 9d1613e | 2011-11-25 12:09:16 +0200 | [diff] [blame] | 4700 | edges |= WL_SHELL_SURFACE_RESIZE_LEFT; |
Jason Ekstrand | 918f2dd | 2013-12-02 21:01:53 -0600 | [diff] [blame] | 4701 | else if (x < 2 * shsurf->surface->width / 3) |
Kristian Høgsberg | 0793756 | 2011-04-12 17:25:42 -0400 | [diff] [blame] | 4702 | edges |= 0; |
| 4703 | else |
Pekka Paalanen | 9d1613e | 2011-11-25 12:09:16 +0200 | [diff] [blame] | 4704 | edges |= WL_SHELL_SURFACE_RESIZE_RIGHT; |
Kristian Høgsberg | 0793756 | 2011-04-12 17:25:42 -0400 | [diff] [blame] | 4705 | |
Jason Ekstrand | 918f2dd | 2013-12-02 21:01:53 -0600 | [diff] [blame] | 4706 | if (y < shsurf->surface->height / 3) |
Pekka Paalanen | 9d1613e | 2011-11-25 12:09:16 +0200 | [diff] [blame] | 4707 | edges |= WL_SHELL_SURFACE_RESIZE_TOP; |
Jason Ekstrand | 918f2dd | 2013-12-02 21:01:53 -0600 | [diff] [blame] | 4708 | else if (y < 2 * shsurf->surface->height / 3) |
Kristian Høgsberg | 0793756 | 2011-04-12 17:25:42 -0400 | [diff] [blame] | 4709 | edges |= 0; |
| 4710 | else |
Pekka Paalanen | 9d1613e | 2011-11-25 12:09:16 +0200 | [diff] [blame] | 4711 | edges |= WL_SHELL_SURFACE_RESIZE_BOTTOM; |
Kristian Høgsberg | 0793756 | 2011-04-12 17:25:42 -0400 | [diff] [blame] | 4712 | |
Derek Foreman | 8fbebbd | 2015-07-15 13:00:40 -0500 | [diff] [blame] | 4713 | surface_resize(shsurf, pointer, edges); |
Kristian Høgsberg | 02ec0a5 | 2011-04-23 13:04:11 -0400 | [diff] [blame] | 4714 | } |
| 4715 | |
| 4716 | static void |
Derek Foreman | 8ae2db5 | 2015-07-15 13:00:36 -0500 | [diff] [blame] | 4717 | surface_opacity_binding(struct weston_pointer *pointer, uint32_t time, |
| 4718 | uint32_t axis, wl_fixed_t value, void *data) |
Scott Moreau | a3aa9c9 | 2012-03-22 11:01:03 -0600 | [diff] [blame] | 4719 | { |
Jonas Ådahl | b0b87ba | 2012-09-27 18:40:42 +0200 | [diff] [blame] | 4720 | float step = 0.005; |
Scott Moreau | a3aa9c9 | 2012-03-22 11:01:03 -0600 | [diff] [blame] | 4721 | struct shell_surface *shsurf; |
Derek Foreman | 8ae2db5 | 2015-07-15 13:00:36 -0500 | [diff] [blame] | 4722 | struct weston_surface *focus = pointer->focus->surface; |
Pekka Paalanen | 01388e2 | 2013-04-25 13:57:44 +0300 | [diff] [blame] | 4723 | struct weston_surface *surface; |
Scott Moreau | a3aa9c9 | 2012-03-22 11:01:03 -0600 | [diff] [blame] | 4724 | |
Pekka Paalanen | 01388e2 | 2013-04-25 13:57:44 +0300 | [diff] [blame] | 4725 | /* XXX: broken for windows containing sub-surfaces */ |
| 4726 | surface = weston_surface_get_main_surface(focus); |
Scott Moreau | a3aa9c9 | 2012-03-22 11:01:03 -0600 | [diff] [blame] | 4727 | if (surface == NULL) |
| 4728 | return; |
| 4729 | |
| 4730 | shsurf = get_shell_surface(surface); |
| 4731 | if (!shsurf) |
| 4732 | return; |
| 4733 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 4734 | shsurf->view->alpha -= wl_fixed_to_double(value) * step; |
Scott Moreau | a3aa9c9 | 2012-03-22 11:01:03 -0600 | [diff] [blame] | 4735 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 4736 | if (shsurf->view->alpha > 1.0) |
| 4737 | shsurf->view->alpha = 1.0; |
| 4738 | if (shsurf->view->alpha < step) |
| 4739 | shsurf->view->alpha = step; |
Scott Moreau | a3aa9c9 | 2012-03-22 11:01:03 -0600 | [diff] [blame] | 4740 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 4741 | weston_view_geometry_dirty(shsurf->view); |
Scott Moreau | a3aa9c9 | 2012-03-22 11:01:03 -0600 | [diff] [blame] | 4742 | weston_surface_damage(surface); |
| 4743 | } |
| 4744 | |
| 4745 | static void |
Kristian Høgsberg | e314875 | 2013-05-06 23:19:49 -0400 | [diff] [blame] | 4746 | 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] | 4747 | wl_fixed_t value) |
Scott Moreau | ccbf29d | 2012-02-22 14:21:41 -0700 | [diff] [blame] | 4748 | { |
Derek Foreman | 8aeeac8 | 2015-01-30 13:24:36 -0600 | [diff] [blame] | 4749 | struct weston_compositor *compositor = seat->compositor; |
Derek Foreman | 1281a36 | 2015-07-31 16:55:32 -0500 | [diff] [blame] | 4750 | struct weston_pointer *pointer = weston_seat_get_pointer(seat); |
Scott Moreau | ccbf29d | 2012-02-22 14:21:41 -0700 | [diff] [blame] | 4751 | struct weston_output *output; |
Scott Moreau | e660398 | 2012-06-11 13:07:51 -0600 | [diff] [blame] | 4752 | float increment; |
Scott Moreau | ccbf29d | 2012-02-22 14:21:41 -0700 | [diff] [blame] | 4753 | |
Derek Foreman | 1281a36 | 2015-07-31 16:55:32 -0500 | [diff] [blame] | 4754 | if (!pointer) { |
Derek Foreman | 7ef3bed | 2015-01-06 14:28:13 -0600 | [diff] [blame] | 4755 | weston_log("Zoom hotkey pressed but seat '%s' contains no pointer.\n", seat->seat_name); |
| 4756 | return; |
| 4757 | } |
| 4758 | |
Scott Moreau | ccbf29d | 2012-02-22 14:21:41 -0700 | [diff] [blame] | 4759 | wl_list_for_each(output, &compositor->output_list, link) { |
| 4760 | if (pixman_region32_contains_point(&output->region, |
Derek Foreman | 1281a36 | 2015-07-31 16:55:32 -0500 | [diff] [blame] | 4761 | wl_fixed_to_double(pointer->x), |
| 4762 | wl_fixed_to_double(pointer->y), |
Daniel Stone | 103db7f | 2012-05-08 17:17:55 +0100 | [diff] [blame] | 4763 | NULL)) { |
Daniel Stone | 325fc2d | 2012-05-30 16:31:58 +0100 | [diff] [blame] | 4764 | if (key == KEY_PAGEUP) |
Kristian Høgsberg | 9b68af0 | 2012-05-22 12:55:18 -0400 | [diff] [blame] | 4765 | increment = output->zoom.increment; |
Daniel Stone | 325fc2d | 2012-05-30 16:31:58 +0100 | [diff] [blame] | 4766 | else if (key == KEY_PAGEDOWN) |
Kristian Høgsberg | 9b68af0 | 2012-05-22 12:55:18 -0400 | [diff] [blame] | 4767 | increment = -output->zoom.increment; |
| 4768 | else if (axis == WL_POINTER_AXIS_VERTICAL_SCROLL) |
Jonas Ådahl | b0b87ba | 2012-09-27 18:40:42 +0200 | [diff] [blame] | 4769 | /* For every pixel zoom 20th of a step */ |
Daniel Stone | 0c1e46e | 2012-05-30 16:31:59 +0100 | [diff] [blame] | 4770 | increment = output->zoom.increment * |
Jonas Ådahl | b0b87ba | 2012-09-27 18:40:42 +0200 | [diff] [blame] | 4771 | -wl_fixed_to_double(value) / 20.0; |
Kristian Høgsberg | 9b68af0 | 2012-05-22 12:55:18 -0400 | [diff] [blame] | 4772 | else |
| 4773 | increment = 0; |
| 4774 | |
Kristian Høgsberg | 9b68af0 | 2012-05-22 12:55:18 -0400 | [diff] [blame] | 4775 | output->zoom.level += increment; |
Scott Moreau | c6d7f60 | 2012-02-23 22:28:37 -0700 | [diff] [blame] | 4776 | |
Scott Moreau | e660398 | 2012-06-11 13:07:51 -0600 | [diff] [blame] | 4777 | if (output->zoom.level < 0.0) |
Scott Moreau | 850ca42 | 2012-05-21 15:21:25 -0600 | [diff] [blame] | 4778 | output->zoom.level = 0.0; |
Scott Moreau | e660398 | 2012-06-11 13:07:51 -0600 | [diff] [blame] | 4779 | else if (output->zoom.level > output->zoom.max_level) |
| 4780 | output->zoom.level = output->zoom.max_level; |
Derek Foreman | 25bd8a7 | 2015-07-23 14:55:13 -0500 | [diff] [blame] | 4781 | |
| 4782 | if (!output->zoom.active) { |
| 4783 | if (output->zoom.level <= 0.0) |
| 4784 | continue; |
Derek Foreman | 22276a5 | 2015-07-23 14:55:15 -0500 | [diff] [blame] | 4785 | weston_output_activate_zoom(output, seat); |
Kristian Høgsberg | 79af73e | 2012-08-03 15:45:23 -0400 | [diff] [blame] | 4786 | } |
Scott Moreau | ccbf29d | 2012-02-22 14:21:41 -0700 | [diff] [blame] | 4787 | |
Scott Moreau | e660398 | 2012-06-11 13:07:51 -0600 | [diff] [blame] | 4788 | output->zoom.spring_z.target = output->zoom.level; |
Scott Moreau | ccbf29d | 2012-02-22 14:21:41 -0700 | [diff] [blame] | 4789 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 4790 | weston_output_update_zoom(output); |
Scott Moreau | ccbf29d | 2012-02-22 14:21:41 -0700 | [diff] [blame] | 4791 | } |
| 4792 | } |
| 4793 | } |
| 4794 | |
Scott Moreau | ccbf29d | 2012-02-22 14:21:41 -0700 | [diff] [blame] | 4795 | static void |
Derek Foreman | 8ae2db5 | 2015-07-15 13:00:36 -0500 | [diff] [blame] | 4796 | zoom_axis_binding(struct weston_pointer *pointer, uint32_t time, |
| 4797 | uint32_t axis, wl_fixed_t value, void *data) |
Daniel Stone | 325fc2d | 2012-05-30 16:31:58 +0100 | [diff] [blame] | 4798 | { |
Derek Foreman | 8ae2db5 | 2015-07-15 13:00:36 -0500 | [diff] [blame] | 4799 | do_zoom(pointer->seat, time, 0, axis, value); |
Daniel Stone | 325fc2d | 2012-05-30 16:31:58 +0100 | [diff] [blame] | 4800 | } |
| 4801 | |
| 4802 | static void |
Derek Foreman | 8ae2db5 | 2015-07-15 13:00:36 -0500 | [diff] [blame] | 4803 | zoom_key_binding(struct weston_keyboard *keyboard, uint32_t time, |
| 4804 | uint32_t key, void *data) |
Daniel Stone | 325fc2d | 2012-05-30 16:31:58 +0100 | [diff] [blame] | 4805 | { |
Derek Foreman | 8ae2db5 | 2015-07-15 13:00:36 -0500 | [diff] [blame] | 4806 | do_zoom(keyboard->seat, time, key, 0, 0); |
Daniel Stone | 325fc2d | 2012-05-30 16:31:58 +0100 | [diff] [blame] | 4807 | } |
| 4808 | |
| 4809 | static void |
Derek Foreman | 8ae2db5 | 2015-07-15 13:00:36 -0500 | [diff] [blame] | 4810 | terminate_binding(struct weston_keyboard *keyboard, uint32_t time, |
| 4811 | uint32_t key, void *data) |
Kristian Høgsberg | e1a850e | 2011-12-19 15:18:05 -0500 | [diff] [blame] | 4812 | { |
Kristian Høgsberg | 8334bc1 | 2012-01-03 10:29:47 -0500 | [diff] [blame] | 4813 | struct weston_compositor *compositor = data; |
Kristian Høgsberg | e1a850e | 2011-12-19 15:18:05 -0500 | [diff] [blame] | 4814 | |
Daniel Stone | 325fc2d | 2012-05-30 16:31:58 +0100 | [diff] [blame] | 4815 | wl_display_terminate(compositor->wl_display); |
Kristian Høgsberg | e1a850e | 2011-12-19 15:18:05 -0500 | [diff] [blame] | 4816 | } |
| 4817 | |
Emilio Pozuelo Monfort | 03251b6 | 2013-11-19 11:37:16 +0100 | [diff] [blame] | 4818 | static void |
Giulio Camuffo | 1959ab8 | 2013-11-14 23:42:52 +0100 | [diff] [blame] | 4819 | rotate_grab_motion(struct weston_pointer_grab *grab, uint32_t time, |
Jonas Ådahl | d251010 | 2014-10-05 21:39:14 +0200 | [diff] [blame] | 4820 | struct weston_pointer_motion_event *event) |
Pekka Paalanen | 460099f | 2012-01-20 16:48:25 +0200 | [diff] [blame] | 4821 | { |
| 4822 | struct rotate_grab *rotate = |
Ander Conselvan de Oliveira | fe0444a | 2012-04-04 17:48:05 +0300 | [diff] [blame] | 4823 | container_of(grab, struct rotate_grab, base.grab); |
Kristian Høgsberg | 02bbabb | 2013-05-06 22:15:05 -0400 | [diff] [blame] | 4824 | struct weston_pointer *pointer = grab->pointer; |
Ander Conselvan de Oliveira | fe0444a | 2012-04-04 17:48:05 +0300 | [diff] [blame] | 4825 | struct shell_surface *shsurf = rotate->base.shsurf; |
John Kåre Alsaker | 490d02a | 2012-09-30 02:57:21 +0200 | [diff] [blame] | 4826 | float cx, cy, dx, dy, cposx, cposy, dposx, dposy, r; |
Ander Conselvan de Oliveira | fe0444a | 2012-04-04 17:48:05 +0300 | [diff] [blame] | 4827 | |
Jonas Ådahl | d251010 | 2014-10-05 21:39:14 +0200 | [diff] [blame] | 4828 | weston_pointer_move(pointer, event); |
Giulio Camuffo | 1959ab8 | 2013-11-14 23:42:52 +0100 | [diff] [blame] | 4829 | |
Ander Conselvan de Oliveira | fe0444a | 2012-04-04 17:48:05 +0300 | [diff] [blame] | 4830 | if (!shsurf) |
| 4831 | return; |
| 4832 | |
Jason Ekstrand | 918f2dd | 2013-12-02 21:01:53 -0600 | [diff] [blame] | 4833 | cx = 0.5f * shsurf->surface->width; |
| 4834 | cy = 0.5f * shsurf->surface->height; |
Pekka Paalanen | 460099f | 2012-01-20 16:48:25 +0200 | [diff] [blame] | 4835 | |
Daniel Stone | 37816df | 2012-05-16 18:45:18 +0100 | [diff] [blame] | 4836 | dx = wl_fixed_to_double(pointer->x) - rotate->center.x; |
| 4837 | dy = wl_fixed_to_double(pointer->y) - rotate->center.y; |
Pekka Paalanen | 460099f | 2012-01-20 16:48:25 +0200 | [diff] [blame] | 4838 | r = sqrtf(dx * dx + dy * dy); |
| 4839 | |
Ander Conselvan de Oliveira | fe0444a | 2012-04-04 17:48:05 +0300 | [diff] [blame] | 4840 | wl_list_remove(&shsurf->rotation.transform.link); |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 4841 | weston_view_geometry_dirty(shsurf->view); |
Pekka Paalanen | 460099f | 2012-01-20 16:48:25 +0200 | [diff] [blame] | 4842 | |
| 4843 | if (r > 20.0f) { |
Pekka Paalanen | 460099f | 2012-01-20 16:48:25 +0200 | [diff] [blame] | 4844 | struct weston_matrix *matrix = |
Ander Conselvan de Oliveira | fe0444a | 2012-04-04 17:48:05 +0300 | [diff] [blame] | 4845 | &shsurf->rotation.transform.matrix; |
Pekka Paalanen | 460099f | 2012-01-20 16:48:25 +0200 | [diff] [blame] | 4846 | |
Kristian Høgsberg | 765e27b | 2012-01-27 13:36:13 -0500 | [diff] [blame] | 4847 | weston_matrix_init(&rotate->rotation); |
Vasily Khoruzhick | 1bbf372 | 2013-01-28 22:40:28 +0300 | [diff] [blame] | 4848 | weston_matrix_rotate_xy(&rotate->rotation, dx / r, dy / r); |
Pekka Paalanen | 460099f | 2012-01-20 16:48:25 +0200 | [diff] [blame] | 4849 | |
| 4850 | weston_matrix_init(matrix); |
Pekka Paalanen | 7b3bd3d | 2012-01-30 14:16:34 +0200 | [diff] [blame] | 4851 | weston_matrix_translate(matrix, -cx, -cy, 0.0f); |
Ander Conselvan de Oliveira | fe0444a | 2012-04-04 17:48:05 +0300 | [diff] [blame] | 4852 | weston_matrix_multiply(matrix, &shsurf->rotation.rotation); |
Kristian Høgsberg | 765e27b | 2012-01-27 13:36:13 -0500 | [diff] [blame] | 4853 | weston_matrix_multiply(matrix, &rotate->rotation); |
Pekka Paalanen | 7b3bd3d | 2012-01-30 14:16:34 +0200 | [diff] [blame] | 4854 | weston_matrix_translate(matrix, cx, cy, 0.0f); |
Pekka Paalanen | 460099f | 2012-01-20 16:48:25 +0200 | [diff] [blame] | 4855 | |
Pekka Paalanen | bc0b7e7 | 2012-01-24 09:53:37 +0200 | [diff] [blame] | 4856 | wl_list_insert( |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 4857 | &shsurf->view->geometry.transformation_list, |
Ander Conselvan de Oliveira | fe0444a | 2012-04-04 17:48:05 +0300 | [diff] [blame] | 4858 | &shsurf->rotation.transform.link); |
Pekka Paalanen | 460099f | 2012-01-20 16:48:25 +0200 | [diff] [blame] | 4859 | } else { |
Ander Conselvan de Oliveira | fe0444a | 2012-04-04 17:48:05 +0300 | [diff] [blame] | 4860 | wl_list_init(&shsurf->rotation.transform.link); |
| 4861 | weston_matrix_init(&shsurf->rotation.rotation); |
Kristian Høgsberg | 765e27b | 2012-01-27 13:36:13 -0500 | [diff] [blame] | 4862 | weston_matrix_init(&rotate->rotation); |
Pekka Paalanen | 460099f | 2012-01-20 16:48:25 +0200 | [diff] [blame] | 4863 | } |
Pekka Paalanen | b45ac5e | 2012-02-09 15:58:44 +0200 | [diff] [blame] | 4864 | |
Rafal Mielniczuk | 2d7ab82 | 2012-03-22 22:22:04 +0100 | [diff] [blame] | 4865 | /* We need to adjust the position of the surface |
| 4866 | * in case it was resized in a rotated state before */ |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 4867 | cposx = shsurf->view->geometry.x + cx; |
| 4868 | cposy = shsurf->view->geometry.y + cy; |
Rafal Mielniczuk | 2d7ab82 | 2012-03-22 22:22:04 +0100 | [diff] [blame] | 4869 | dposx = rotate->center.x - cposx; |
| 4870 | dposy = rotate->center.y - cposy; |
| 4871 | if (dposx != 0.0f || dposy != 0.0f) { |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 4872 | weston_view_set_position(shsurf->view, |
| 4873 | shsurf->view->geometry.x + dposx, |
| 4874 | shsurf->view->geometry.y + dposy); |
Rafal Mielniczuk | 2d7ab82 | 2012-03-22 22:22:04 +0100 | [diff] [blame] | 4875 | } |
| 4876 | |
Derek Foreman | 4b1a0a1 | 2014-09-10 15:37:33 -0500 | [diff] [blame] | 4877 | /* Repaint implies weston_view_update_transform(), which |
Pekka Paalanen | b45ac5e | 2012-02-09 15:58:44 +0200 | [diff] [blame] | 4878 | * lazily applies the damage due to rotation update. |
| 4879 | */ |
Ander Conselvan de Oliveira | fe0444a | 2012-04-04 17:48:05 +0300 | [diff] [blame] | 4880 | weston_compositor_schedule_repaint(shsurf->surface->compositor); |
Pekka Paalanen | 460099f | 2012-01-20 16:48:25 +0200 | [diff] [blame] | 4881 | } |
| 4882 | |
| 4883 | static void |
Kristian Høgsberg | 02bbabb | 2013-05-06 22:15:05 -0400 | [diff] [blame] | 4884 | rotate_grab_button(struct weston_pointer_grab *grab, |
| 4885 | uint32_t time, uint32_t button, uint32_t state_w) |
Pekka Paalanen | 460099f | 2012-01-20 16:48:25 +0200 | [diff] [blame] | 4886 | { |
| 4887 | struct rotate_grab *rotate = |
Ander Conselvan de Oliveira | fe0444a | 2012-04-04 17:48:05 +0300 | [diff] [blame] | 4888 | container_of(grab, struct rotate_grab, base.grab); |
Kristian Høgsberg | 02bbabb | 2013-05-06 22:15:05 -0400 | [diff] [blame] | 4889 | struct weston_pointer *pointer = grab->pointer; |
Ander Conselvan de Oliveira | fe0444a | 2012-04-04 17:48:05 +0300 | [diff] [blame] | 4890 | struct shell_surface *shsurf = rotate->base.shsurf; |
Daniel Stone | 4dbadb1 | 2012-05-30 16:31:51 +0100 | [diff] [blame] | 4891 | enum wl_pointer_button_state state = state_w; |
Pekka Paalanen | 460099f | 2012-01-20 16:48:25 +0200 | [diff] [blame] | 4892 | |
Daniel Stone | 4dbadb1 | 2012-05-30 16:31:51 +0100 | [diff] [blame] | 4893 | if (pointer->button_count == 0 && |
| 4894 | state == WL_POINTER_BUTTON_STATE_RELEASED) { |
Ander Conselvan de Oliveira | fe0444a | 2012-04-04 17:48:05 +0300 | [diff] [blame] | 4895 | if (shsurf) |
| 4896 | weston_matrix_multiply(&shsurf->rotation.rotation, |
| 4897 | &rotate->rotation); |
Ander Conselvan de Oliveira | b9d2a0f | 2012-06-28 18:08:05 +0300 | [diff] [blame] | 4898 | shell_grab_end(&rotate->base); |
Pekka Paalanen | 460099f | 2012-01-20 16:48:25 +0200 | [diff] [blame] | 4899 | free(rotate); |
| 4900 | } |
| 4901 | } |
| 4902 | |
Jonas Ådahl | 1ea343e | 2013-10-25 23:18:05 +0200 | [diff] [blame] | 4903 | static void |
| 4904 | rotate_grab_cancel(struct weston_pointer_grab *grab) |
| 4905 | { |
| 4906 | struct rotate_grab *rotate = |
| 4907 | container_of(grab, struct rotate_grab, base.grab); |
| 4908 | |
| 4909 | shell_grab_end(&rotate->base); |
| 4910 | free(rotate); |
| 4911 | } |
| 4912 | |
Kristian Høgsberg | 02bbabb | 2013-05-06 22:15:05 -0400 | [diff] [blame] | 4913 | static const struct weston_pointer_grab_interface rotate_grab_interface = { |
Pekka Paalanen | 460099f | 2012-01-20 16:48:25 +0200 | [diff] [blame] | 4914 | noop_grab_focus, |
| 4915 | rotate_grab_motion, |
| 4916 | rotate_grab_button, |
Jonas Ådahl | 0336ca0 | 2014-10-04 16:28:29 +0200 | [diff] [blame] | 4917 | noop_grab_axis, |
Jonas Ådahl | 1ea343e | 2013-10-25 23:18:05 +0200 | [diff] [blame] | 4918 | rotate_grab_cancel, |
Pekka Paalanen | 460099f | 2012-01-20 16:48:25 +0200 | [diff] [blame] | 4919 | }; |
| 4920 | |
| 4921 | static void |
Derek Foreman | 74de469 | 2015-07-15 13:00:39 -0500 | [diff] [blame] | 4922 | surface_rotate(struct shell_surface *surface, struct weston_pointer *pointer) |
Pekka Paalanen | 460099f | 2012-01-20 16:48:25 +0200 | [diff] [blame] | 4923 | { |
Pekka Paalanen | 460099f | 2012-01-20 16:48:25 +0200 | [diff] [blame] | 4924 | struct rotate_grab *rotate; |
John Kåre Alsaker | 490d02a | 2012-09-30 02:57:21 +0200 | [diff] [blame] | 4925 | float dx, dy; |
| 4926 | float r; |
Pekka Paalanen | 460099f | 2012-01-20 16:48:25 +0200 | [diff] [blame] | 4927 | |
Derek Foreman | 45a7c27 | 2015-09-11 14:27:40 -0500 | [diff] [blame] | 4928 | surface = find_toplevel_surface(surface); |
| 4929 | |
Pekka Paalanen | 460099f | 2012-01-20 16:48:25 +0200 | [diff] [blame] | 4930 | rotate = malloc(sizeof *rotate); |
| 4931 | if (!rotate) |
| 4932 | return; |
| 4933 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 4934 | weston_view_to_global_float(surface->view, |
Jason Ekstrand | 918f2dd | 2013-12-02 21:01:53 -0600 | [diff] [blame] | 4935 | surface->surface->width * 0.5f, |
| 4936 | surface->surface->height * 0.5f, |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 4937 | &rotate->center.x, &rotate->center.y); |
Pekka Paalanen | 460099f | 2012-01-20 16:48:25 +0200 | [diff] [blame] | 4938 | |
Derek Foreman | 74de469 | 2015-07-15 13:00:39 -0500 | [diff] [blame] | 4939 | dx = wl_fixed_to_double(pointer->x) - rotate->center.x; |
| 4940 | dy = wl_fixed_to_double(pointer->y) - rotate->center.y; |
Kristian Høgsberg | 765e27b | 2012-01-27 13:36:13 -0500 | [diff] [blame] | 4941 | r = sqrtf(dx * dx + dy * dy); |
| 4942 | if (r > 20.0f) { |
| 4943 | struct weston_matrix inverse; |
| 4944 | |
| 4945 | weston_matrix_init(&inverse); |
Vasily Khoruzhick | 1bbf372 | 2013-01-28 22:40:28 +0300 | [diff] [blame] | 4946 | weston_matrix_rotate_xy(&inverse, dx / r, -dy / r); |
Kristian Høgsberg | 765e27b | 2012-01-27 13:36:13 -0500 | [diff] [blame] | 4947 | weston_matrix_multiply(&surface->rotation.rotation, &inverse); |
Rafal Mielniczuk | 2d7ab82 | 2012-03-22 22:22:04 +0100 | [diff] [blame] | 4948 | |
| 4949 | weston_matrix_init(&rotate->rotation); |
Vasily Khoruzhick | 1bbf372 | 2013-01-28 22:40:28 +0300 | [diff] [blame] | 4950 | weston_matrix_rotate_xy(&rotate->rotation, dx / r, dy / r); |
Kristian Høgsberg | 765e27b | 2012-01-27 13:36:13 -0500 | [diff] [blame] | 4951 | } else { |
| 4952 | weston_matrix_init(&surface->rotation.rotation); |
| 4953 | weston_matrix_init(&rotate->rotation); |
| 4954 | } |
| 4955 | |
Ander Conselvan de Oliveira | b9d2a0f | 2012-06-28 18:08:05 +0300 | [diff] [blame] | 4956 | shell_grab_start(&rotate->base, &rotate_grab_interface, surface, |
Jonas Ådahl | 6d6fb61 | 2015-11-17 16:00:33 +0800 | [diff] [blame] | 4957 | pointer, WESTON_DESKTOP_SHELL_CURSOR_ARROW); |
Pekka Paalanen | 460099f | 2012-01-20 16:48:25 +0200 | [diff] [blame] | 4958 | } |
| 4959 | |
| 4960 | static void |
Derek Foreman | 8ae2db5 | 2015-07-15 13:00:36 -0500 | [diff] [blame] | 4961 | 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] | 4962 | void *data) |
| 4963 | { |
Rafal Mielniczuk | b2917a2 | 2014-01-05 20:04:59 +0100 | [diff] [blame] | 4964 | struct weston_surface *focus; |
Pekka Paalanen | 01388e2 | 2013-04-25 13:57:44 +0300 | [diff] [blame] | 4965 | struct weston_surface *base_surface; |
Kristian Høgsberg | 0c36903 | 2013-02-14 21:31:44 -0500 | [diff] [blame] | 4966 | struct shell_surface *surface; |
| 4967 | |
Derek Foreman | 8ae2db5 | 2015-07-15 13:00:36 -0500 | [diff] [blame] | 4968 | if (pointer->focus == NULL) |
Rafal Mielniczuk | b2917a2 | 2014-01-05 20:04:59 +0100 | [diff] [blame] | 4969 | return; |
| 4970 | |
Derek Foreman | 8ae2db5 | 2015-07-15 13:00:36 -0500 | [diff] [blame] | 4971 | focus = pointer->focus->surface; |
Rafal Mielniczuk | b2917a2 | 2014-01-05 20:04:59 +0100 | [diff] [blame] | 4972 | |
Pekka Paalanen | 01388e2 | 2013-04-25 13:57:44 +0300 | [diff] [blame] | 4973 | base_surface = weston_surface_get_main_surface(focus); |
Kristian Høgsberg | 0c36903 | 2013-02-14 21:31:44 -0500 | [diff] [blame] | 4974 | if (base_surface == NULL) |
| 4975 | return; |
| 4976 | |
| 4977 | surface = get_shell_surface(base_surface); |
Rafael Antognolli | 03b1659 | 2013-12-03 15:35:42 -0200 | [diff] [blame] | 4978 | if (surface == NULL || surface->state.fullscreen || |
| 4979 | surface->state.maximized) |
Kristian Høgsberg | 0c36903 | 2013-02-14 21:31:44 -0500 | [diff] [blame] | 4980 | return; |
| 4981 | |
Derek Foreman | 74de469 | 2015-07-15 13:00:39 -0500 | [diff] [blame] | 4982 | surface_rotate(surface, pointer); |
Kristian Høgsberg | 0c36903 | 2013-02-14 21:31:44 -0500 | [diff] [blame] | 4983 | } |
| 4984 | |
Emilio Pozuelo Monfort | 9e7c759 | 2014-01-30 14:01:10 +0100 | [diff] [blame] | 4985 | /* Move all fullscreen layers down to the current workspace and hide their |
| 4986 | * black views. The surfaces' state is set to both fullscreen and lowered, |
| 4987 | * and this is reversed when such a surface is re-configured, see |
| 4988 | * shell_configure_fullscreen() and shell_ensure_fullscreen_black_view(). |
| 4989 | * |
Mario Kleiner | 9f4d655 | 2015-06-21 21:25:08 +0200 | [diff] [blame] | 4990 | * lowering_output = NULL - Lower on all outputs, else only lower on the |
| 4991 | * specified output. |
| 4992 | * |
Emilio Pozuelo Monfort | 9e7c759 | 2014-01-30 14:01:10 +0100 | [diff] [blame] | 4993 | * This should be used when implementing shell-wide overlays, such as |
Philip Withnall | 83ffd9d | 2013-11-25 18:01:42 +0000 | [diff] [blame] | 4994 | * the alt-tab switcher, which need to de-promote fullscreen layers. */ |
Kristian Høgsberg | 1ef2313 | 2013-12-04 00:20:01 -0800 | [diff] [blame] | 4995 | void |
Mario Kleiner | 9f4d655 | 2015-06-21 21:25:08 +0200 | [diff] [blame] | 4996 | lower_fullscreen_layer(struct desktop_shell *shell, |
| 4997 | struct weston_output *lowering_output) |
Kristian Høgsberg | b0d8e77 | 2012-06-18 16:34:58 -0400 | [diff] [blame] | 4998 | { |
| 4999 | struct workspace *ws; |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 5000 | struct weston_view *view, *prev; |
Kristian Høgsberg | b0d8e77 | 2012-06-18 16:34:58 -0400 | [diff] [blame] | 5001 | |
| 5002 | ws = get_current_workspace(shell); |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 5003 | wl_list_for_each_reverse_safe(view, prev, |
Giulio Camuffo | 412e6a5 | 2014-07-09 22:12:56 +0300 | [diff] [blame] | 5004 | &shell->fullscreen_layer.view_list.link, |
| 5005 | layer_link.link) { |
Emilio Pozuelo Monfort | 9e7c759 | 2014-01-30 14:01:10 +0100 | [diff] [blame] | 5006 | struct shell_surface *shsurf = get_shell_surface(view->surface); |
| 5007 | |
| 5008 | if (!shsurf) |
| 5009 | continue; |
| 5010 | |
Mario Kleiner | 9f4d655 | 2015-06-21 21:25:08 +0200 | [diff] [blame] | 5011 | /* Only lower surfaces which have lowering_output as their fullscreen |
| 5012 | * output, unless a NULL output asks for lowering on all outputs. |
| 5013 | */ |
| 5014 | if (lowering_output && (shsurf->fullscreen_output != lowering_output)) |
| 5015 | continue; |
| 5016 | |
Emilio Pozuelo Monfort | 9e7c759 | 2014-01-30 14:01:10 +0100 | [diff] [blame] | 5017 | /* We can have a non-fullscreen popup for a fullscreen surface |
| 5018 | * in the fullscreen layer. */ |
| 5019 | if (shsurf->state.fullscreen) { |
| 5020 | /* Hide the black view */ |
Giulio Camuffo | 412e6a5 | 2014-07-09 22:12:56 +0300 | [diff] [blame] | 5021 | weston_layer_entry_remove(&shsurf->fullscreen.black_view->layer_link); |
| 5022 | wl_list_init(&shsurf->fullscreen.black_view->layer_link.link); |
Kristian Høgsberg | c991513 | 2014-05-09 16:24:07 -0700 | [diff] [blame] | 5023 | weston_view_damage_below(shsurf->fullscreen.black_view); |
| 5024 | |
Emilio Pozuelo Monfort | 9e7c759 | 2014-01-30 14:01:10 +0100 | [diff] [blame] | 5025 | } |
| 5026 | |
| 5027 | /* Lower the view to the workspace layer */ |
Giulio Camuffo | 412e6a5 | 2014-07-09 22:12:56 +0300 | [diff] [blame] | 5028 | weston_layer_entry_remove(&view->layer_link); |
| 5029 | weston_layer_entry_insert(&ws->layer.view_list, &view->layer_link); |
Philip Withnall | 83ffd9d | 2013-11-25 18:01:42 +0000 | [diff] [blame] | 5030 | weston_view_damage_below(view); |
| 5031 | weston_surface_damage(view->surface); |
Emilio Pozuelo Monfort | 9e7c759 | 2014-01-30 14:01:10 +0100 | [diff] [blame] | 5032 | |
| 5033 | shsurf->state.lowered = true; |
Philip Withnall | 83ffd9d | 2013-11-25 18:01:42 +0000 | [diff] [blame] | 5034 | } |
Kristian Høgsberg | b0d8e77 | 2012-06-18 16:34:58 -0400 | [diff] [blame] | 5035 | } |
| 5036 | |
Kristian Høgsberg | 1ef2313 | 2013-12-04 00:20:01 -0800 | [diff] [blame] | 5037 | void |
Tiago Vignatti | be14326 | 2012-04-16 17:31:41 +0300 | [diff] [blame] | 5038 | activate(struct desktop_shell *shell, struct weston_surface *es, |
Emilio Pozuelo Monfort | 9e7c759 | 2014-01-30 14:01:10 +0100 | [diff] [blame] | 5039 | struct weston_seat *seat, bool configure) |
Kristian Høgsberg | 7584062 | 2011-09-06 13:48:16 -0400 | [diff] [blame] | 5040 | { |
Pekka Paalanen | 01388e2 | 2013-04-25 13:57:44 +0300 | [diff] [blame] | 5041 | struct weston_surface *main_surface; |
Kristian Høgsberg | 2f5faff | 2012-07-31 16:36:34 -0400 | [diff] [blame] | 5042 | struct focus_state *state; |
Jonas Ådahl | 8538b22 | 2012-08-29 22:13:03 +0200 | [diff] [blame] | 5043 | struct workspace *ws; |
Louis-Francis Ratté-Boulianne | b482dbd | 2013-11-19 11:37:11 +0100 | [diff] [blame] | 5044 | struct weston_surface *old_es; |
Rafael Antognolli | 03b1659 | 2013-12-03 15:35:42 -0200 | [diff] [blame] | 5045 | struct shell_surface *shsurf; |
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 | main_surface = weston_surface_get_main_surface(es); |
Mario Kleiner | 9f4d655 | 2015-06-21 21:25:08 +0200 | [diff] [blame] | 5048 | shsurf = get_shell_surface(main_surface); |
| 5049 | assert(shsurf); |
| 5050 | |
| 5051 | /* Only demote fullscreen surfaces on the output of activated shsurf. |
| 5052 | * Leave fullscreen surfaces on unrelated outputs alone. */ |
| 5053 | lower_fullscreen_layer(shell, shsurf->output); |
Pekka Paalanen | 01388e2 | 2013-04-25 13:57:44 +0300 | [diff] [blame] | 5054 | |
Daniel Stone | 37816df | 2012-05-16 18:45:18 +0100 | [diff] [blame] | 5055 | weston_surface_activate(es, seat); |
Kristian Høgsberg | 7584062 | 2011-09-06 13:48:16 -0400 | [diff] [blame] | 5056 | |
Jonas Ådahl | 8538b22 | 2012-08-29 22:13:03 +0200 | [diff] [blame] | 5057 | state = ensure_focus_state(shell, seat); |
| 5058 | if (state == NULL) |
| 5059 | return; |
Kristian Høgsberg | 2f5faff | 2012-07-31 16:36:34 -0400 | [diff] [blame] | 5060 | |
Louis-Francis Ratté-Boulianne | b482dbd | 2013-11-19 11:37:11 +0100 | [diff] [blame] | 5061 | old_es = state->keyboard_focus; |
Kristian Høgsberg | d500bf1 | 2014-01-22 12:25:20 -0800 | [diff] [blame] | 5062 | focus_state_set_focus(state, es); |
Kristian Høgsberg | 2f5faff | 2012-07-31 16:36:34 -0400 | [diff] [blame] | 5063 | |
Emilio Pozuelo Monfort | 9e7c759 | 2014-01-30 14:01:10 +0100 | [diff] [blame] | 5064 | if (shsurf->state.fullscreen && configure) |
Rafael Antognolli | 03b1659 | 2013-12-03 15:35:42 -0200 | [diff] [blame] | 5065 | shell_configure_fullscreen(shsurf); |
| 5066 | else |
Mario Kleiner | 492c12f | 2015-06-21 21:25:12 +0200 | [diff] [blame] | 5067 | restore_output_mode(shsurf->output); |
Louis-Francis Ratté-Boulianne | b482dbd | 2013-11-19 11:37:11 +0100 | [diff] [blame] | 5068 | |
Emilio Pozuelo Monfort | 7908bff | 2014-01-30 13:49:39 +0100 | [diff] [blame] | 5069 | /* Update the surface’s layer. This brings it to the top of the stacking |
| 5070 | * order as appropriate. */ |
| 5071 | shell_surface_update_layer(shsurf); |
| 5072 | |
Philip Withnall | 83ffd9d | 2013-11-25 18:01:42 +0000 | [diff] [blame] | 5073 | if (shell->focus_animation_type != ANIMATION_NONE) { |
| 5074 | ws = get_current_workspace(shell); |
Louis-Francis Ratté-Boulianne | b482dbd | 2013-11-19 11:37:11 +0100 | [diff] [blame] | 5075 | 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] | 5076 | } |
Kristian Høgsberg | 7584062 | 2011-09-06 13:48:16 -0400 | [diff] [blame] | 5077 | } |
| 5078 | |
Alex Wu | 2185843 | 2012-04-01 20:13:08 +0800 | [diff] [blame] | 5079 | /* no-op func for checking black surface */ |
| 5080 | static void |
Jason Ekstrand | 918f2dd | 2013-12-02 21:01:53 -0600 | [diff] [blame] | 5081 | 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] | 5082 | { |
| 5083 | } |
| 5084 | |
Quentin Glidic | c0d79ce | 2013-01-29 14:16:13 +0100 | [diff] [blame] | 5085 | static bool |
Alex Wu | 2185843 | 2012-04-01 20:13:08 +0800 | [diff] [blame] | 5086 | is_black_surface (struct weston_surface *es, struct weston_surface **fs_surface) |
| 5087 | { |
| 5088 | if (es->configure == black_surface_configure) { |
| 5089 | if (fs_surface) |
Giulio Camuffo | 7fe01b1 | 2013-03-28 18:02:42 +0100 | [diff] [blame] | 5090 | *fs_surface = (struct weston_surface *)es->configure_private; |
Alex Wu | 2185843 | 2012-04-01 20:13:08 +0800 | [diff] [blame] | 5091 | return true; |
| 5092 | } |
| 5093 | return false; |
| 5094 | } |
| 5095 | |
Kristian Høgsberg | 7584062 | 2011-09-06 13:48:16 -0400 | [diff] [blame] | 5096 | static void |
Neil Roberts | a28c693 | 2013-10-03 16:43:04 +0100 | [diff] [blame] | 5097 | activate_binding(struct weston_seat *seat, |
| 5098 | struct desktop_shell *shell, |
Jonas Ådahl | cd0f1ac | 2015-06-26 12:37:56 +0800 | [diff] [blame] | 5099 | struct weston_view *focus_view) |
Kristian Høgsberg | e1a850e | 2011-12-19 15:18:05 -0500 | [diff] [blame] | 5100 | { |
Jonas Ådahl | cd0f1ac | 2015-06-26 12:37:56 +0800 | [diff] [blame] | 5101 | struct weston_surface *focus; |
Pekka Paalanen | 01388e2 | 2013-04-25 13:57:44 +0300 | [diff] [blame] | 5102 | struct weston_surface *main_surface; |
Kristian Høgsberg | e1a850e | 2011-12-19 15:18:05 -0500 | [diff] [blame] | 5103 | |
Jonas Ådahl | cd0f1ac | 2015-06-26 12:37:56 +0800 | [diff] [blame] | 5104 | focus = focus_view->surface; |
Alex Wu | 9c35e6b | 2012-03-05 14:13:13 +0800 | [diff] [blame] | 5105 | |
Pekka Paalanen | 01388e2 | 2013-04-25 13:57:44 +0300 | [diff] [blame] | 5106 | if (is_black_surface(focus, &main_surface)) |
| 5107 | focus = main_surface; |
Alex Wu | 4539b08 | 2012-03-01 12:57:46 +0800 | [diff] [blame] | 5108 | |
Pekka Paalanen | 01388e2 | 2013-04-25 13:57:44 +0300 | [diff] [blame] | 5109 | main_surface = weston_surface_get_main_surface(focus); |
| 5110 | if (get_shell_surface_type(main_surface) == SHELL_SURFACE_NONE) |
Kristian Høgsberg | 0636ac3 | 2012-06-27 10:22:15 -0400 | [diff] [blame] | 5111 | return; |
Kristian Høgsberg | 85b2e4b | 2012-06-21 16:49:42 -0400 | [diff] [blame] | 5112 | |
Emilio Pozuelo Monfort | 9e7c759 | 2014-01-30 14:01:10 +0100 | [diff] [blame] | 5113 | activate(shell, focus, seat, true); |
Neil Roberts | a28c693 | 2013-10-03 16:43:04 +0100 | [diff] [blame] | 5114 | } |
| 5115 | |
| 5116 | static void |
Derek Foreman | 8ae2db5 | 2015-07-15 13:00:36 -0500 | [diff] [blame] | 5117 | click_to_activate_binding(struct weston_pointer *pointer, uint32_t time, |
| 5118 | uint32_t button, void *data) |
Neil Roberts | a28c693 | 2013-10-03 16:43:04 +0100 | [diff] [blame] | 5119 | { |
Derek Foreman | 8ae2db5 | 2015-07-15 13:00:36 -0500 | [diff] [blame] | 5120 | if (pointer->grab != &pointer->default_grab) |
Neil Roberts | a28c693 | 2013-10-03 16:43:04 +0100 | [diff] [blame] | 5121 | return; |
Derek Foreman | 8ae2db5 | 2015-07-15 13:00:36 -0500 | [diff] [blame] | 5122 | if (pointer->focus == NULL) |
Kristian Høgsberg | 7c4f6cc | 2014-01-01 16:28:32 -0800 | [diff] [blame] | 5123 | return; |
Neil Roberts | a28c693 | 2013-10-03 16:43:04 +0100 | [diff] [blame] | 5124 | |
Jonas Ådahl | cd0f1ac | 2015-06-26 12:37:56 +0800 | [diff] [blame] | 5125 | activate_binding(pointer->seat, data, pointer->focus); |
Neil Roberts | a28c693 | 2013-10-03 16:43:04 +0100 | [diff] [blame] | 5126 | } |
| 5127 | |
| 5128 | static void |
Derek Foreman | 8ae2db5 | 2015-07-15 13:00:36 -0500 | [diff] [blame] | 5129 | touch_to_activate_binding(struct weston_touch *touch, uint32_t time, |
| 5130 | void *data) |
Neil Roberts | a28c693 | 2013-10-03 16:43:04 +0100 | [diff] [blame] | 5131 | { |
Derek Foreman | 8ae2db5 | 2015-07-15 13:00:36 -0500 | [diff] [blame] | 5132 | if (touch->grab != &touch->default_grab) |
Neil Roberts | a28c693 | 2013-10-03 16:43:04 +0100 | [diff] [blame] | 5133 | return; |
Derek Foreman | 8ae2db5 | 2015-07-15 13:00:36 -0500 | [diff] [blame] | 5134 | if (touch->focus == NULL) |
Kristian Høgsberg | 0ed6750 | 2014-01-02 23:00:11 -0800 | [diff] [blame] | 5135 | return; |
Neil Roberts | a28c693 | 2013-10-03 16:43:04 +0100 | [diff] [blame] | 5136 | |
Jonas Ådahl | cd0f1ac | 2015-06-26 12:37:56 +0800 | [diff] [blame] | 5137 | activate_binding(touch->seat, data, touch->focus); |
Kristian Høgsberg | e1a850e | 2011-12-19 15:18:05 -0500 | [diff] [blame] | 5138 | } |
| 5139 | |
| 5140 | static void |
Neil Roberts | b4a9170 | 2014-04-09 16:33:32 +0100 | [diff] [blame] | 5141 | unfocus_all_seats(struct desktop_shell *shell) |
| 5142 | { |
| 5143 | struct weston_seat *seat, *next; |
| 5144 | |
| 5145 | wl_list_for_each_safe(seat, next, &shell->compositor->seat_list, link) { |
Derek Foreman | 1281a36 | 2015-07-31 16:55:32 -0500 | [diff] [blame] | 5146 | struct weston_keyboard *keyboard = |
| 5147 | weston_seat_get_keyboard(seat); |
| 5148 | |
| 5149 | if (!keyboard) |
Neil Roberts | b4a9170 | 2014-04-09 16:33:32 +0100 | [diff] [blame] | 5150 | continue; |
| 5151 | |
Derek Foreman | 1281a36 | 2015-07-31 16:55:32 -0500 | [diff] [blame] | 5152 | weston_keyboard_set_focus(keyboard, NULL); |
Neil Roberts | b4a9170 | 2014-04-09 16:33:32 +0100 | [diff] [blame] | 5153 | } |
| 5154 | } |
| 5155 | |
| 5156 | static void |
Ander Conselvan de Oliveira | 19d10ef | 2013-02-21 18:35:20 +0200 | [diff] [blame] | 5157 | lock(struct desktop_shell *shell) |
Kristian Høgsberg | 02ec0a5 | 2011-04-23 13:04:11 -0400 | [diff] [blame] | 5158 | { |
Kristian Høgsberg | 4476aaf | 2012-06-25 14:03:13 -0400 | [diff] [blame] | 5159 | struct workspace *ws = get_current_workspace(shell); |
Pekka Paalanen | f0fc70d | 2011-11-15 13:34:54 +0200 | [diff] [blame] | 5160 | |
Tiago Vignatti | 8e53c7f | 2012-02-29 19:53:50 +0200 | [diff] [blame] | 5161 | if (shell->locked) { |
Ander Conselvan de Oliveira | 87524b6 | 2013-02-21 18:35:22 +0200 | [diff] [blame] | 5162 | weston_compositor_sleep(shell->compositor); |
Pekka Paalanen | f0fc70d | 2011-11-15 13:34:54 +0200 | [diff] [blame] | 5163 | return; |
Tiago Vignatti | 8e53c7f | 2012-02-29 19:53:50 +0200 | [diff] [blame] | 5164 | } |
Pekka Paalanen | 9ef3e01 | 2011-11-15 13:34:48 +0200 | [diff] [blame] | 5165 | |
| 5166 | shell->locked = true; |
Pekka Paalanen | f0fc70d | 2011-11-15 13:34:54 +0200 | [diff] [blame] | 5167 | |
Kristian Høgsberg | 3be2ce9 | 2012-02-29 12:42:35 -0500 | [diff] [blame] | 5168 | /* Hide all surfaces by removing the fullscreen, panel and |
| 5169 | * toplevel layers. This way nothing else can show or receive |
| 5170 | * input events while we are locked. */ |
Pekka Paalanen | f0fc70d | 2011-11-15 13:34:54 +0200 | [diff] [blame] | 5171 | |
Kristian Høgsberg | 3be2ce9 | 2012-02-29 12:42:35 -0500 | [diff] [blame] | 5172 | wl_list_remove(&shell->panel_layer.link); |
Kristian Høgsberg | 3be2ce9 | 2012-02-29 12:42:35 -0500 | [diff] [blame] | 5173 | wl_list_remove(&shell->fullscreen_layer.link); |
Philipp Brüschweiler | 711fda8 | 2012-08-09 18:50:43 +0200 | [diff] [blame] | 5174 | if (shell->showing_input_panels) |
| 5175 | wl_list_remove(&shell->input_panel_layer.link); |
Kristian Høgsberg | 4476aaf | 2012-06-25 14:03:13 -0400 | [diff] [blame] | 5176 | wl_list_remove(&ws->layer.link); |
Kristian Høgsberg | 3be2ce9 | 2012-02-29 12:42:35 -0500 | [diff] [blame] | 5177 | wl_list_insert(&shell->compositor->cursor_layer.link, |
| 5178 | &shell->lock_layer.link); |
Pekka Paalanen | f0fc70d | 2011-11-15 13:34:54 +0200 | [diff] [blame] | 5179 | |
Derek Foreman | 004b4a1 | 2015-07-20 16:28:13 -0500 | [diff] [blame] | 5180 | weston_compositor_sleep(shell->compositor); |
| 5181 | |
Neil Roberts | b4a9170 | 2014-04-09 16:33:32 +0100 | [diff] [blame] | 5182 | /* Remove the keyboard focus on all seats. This will be |
| 5183 | * restored to the workspace's saved state via |
| 5184 | * restore_focus_state when the compositor is unlocked */ |
| 5185 | unfocus_all_seats(shell); |
| 5186 | |
Pekka Paalanen | f0fc70d | 2011-11-15 13:34:54 +0200 | [diff] [blame] | 5187 | /* TODO: disable bindings that should not work while locked. */ |
| 5188 | |
| 5189 | /* All this must be undone in resume_desktop(). */ |
Pekka Paalanen | 9ef3e01 | 2011-11-15 13:34:48 +0200 | [diff] [blame] | 5190 | } |
| 5191 | |
| 5192 | static void |
Ander Conselvan de Oliveira | 19d10ef | 2013-02-21 18:35:20 +0200 | [diff] [blame] | 5193 | unlock(struct desktop_shell *shell) |
Pekka Paalanen | 9ef3e01 | 2011-11-15 13:34:48 +0200 | [diff] [blame] | 5194 | { |
Jonas Ådahl | 6d6fb61 | 2015-11-17 16:00:33 +0800 | [diff] [blame] | 5195 | struct wl_resource *shell_resource; |
| 5196 | |
Pekka Paalanen | d81c216 | 2011-11-16 13:47:34 +0200 | [diff] [blame] | 5197 | if (!shell->locked || shell->lock_surface) { |
Ander Conselvan de Oliveira | 87524b6 | 2013-02-21 18:35:22 +0200 | [diff] [blame] | 5198 | shell_fade(shell, FADE_IN); |
Pekka Paalanen | 9ef3e01 | 2011-11-15 13:34:48 +0200 | [diff] [blame] | 5199 | return; |
| 5200 | } |
| 5201 | |
| 5202 | /* If desktop-shell client has gone away, unlock immediately. */ |
| 5203 | if (!shell->child.desktop_shell) { |
Pekka Paalanen | f0fc70d | 2011-11-15 13:34:54 +0200 | [diff] [blame] | 5204 | resume_desktop(shell); |
Pekka Paalanen | 9ef3e01 | 2011-11-15 13:34:48 +0200 | [diff] [blame] | 5205 | return; |
| 5206 | } |
| 5207 | |
| 5208 | if (shell->prepare_event_sent) |
| 5209 | return; |
| 5210 | |
Jonas Ådahl | 6d6fb61 | 2015-11-17 16:00:33 +0800 | [diff] [blame] | 5211 | shell_resource = shell->child.desktop_shell; |
| 5212 | weston_desktop_shell_send_prepare_lock_surface(shell_resource); |
Pekka Paalanen | 9ef3e01 | 2011-11-15 13:34:48 +0200 | [diff] [blame] | 5213 | shell->prepare_event_sent = true; |
Kristian Høgsberg | 02ec0a5 | 2011-04-23 13:04:11 -0400 | [diff] [blame] | 5214 | } |
| 5215 | |
| 5216 | static void |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 5217 | shell_fade_done(struct weston_view_animation *animation, void *data) |
Ander Conselvan de Oliveira | 19d10ef | 2013-02-21 18:35:20 +0200 | [diff] [blame] | 5218 | { |
| 5219 | struct desktop_shell *shell = data; |
| 5220 | |
| 5221 | shell->fade.animation = NULL; |
| 5222 | |
| 5223 | switch (shell->fade.type) { |
| 5224 | case FADE_IN: |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 5225 | weston_surface_destroy(shell->fade.view->surface); |
| 5226 | shell->fade.view = NULL; |
Ander Conselvan de Oliveira | 19d10ef | 2013-02-21 18:35:20 +0200 | [diff] [blame] | 5227 | break; |
| 5228 | case FADE_OUT: |
Ander Conselvan de Oliveira | 19d10ef | 2013-02-21 18:35:20 +0200 | [diff] [blame] | 5229 | lock(shell); |
| 5230 | break; |
Philip Withnall | 4a86a0a | 2013-11-25 18:01:32 +0000 | [diff] [blame] | 5231 | default: |
| 5232 | break; |
Ander Conselvan de Oliveira | 19d10ef | 2013-02-21 18:35:20 +0200 | [diff] [blame] | 5233 | } |
| 5234 | } |
| 5235 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 5236 | static struct weston_view * |
Pekka Paalanen | 79346ab | 2013-05-22 18:03:09 +0300 | [diff] [blame] | 5237 | shell_fade_create_surface(struct desktop_shell *shell) |
Ander Conselvan de Oliveira | 19d10ef | 2013-02-21 18:35:20 +0200 | [diff] [blame] | 5238 | { |
| 5239 | struct weston_compositor *compositor = shell->compositor; |
| 5240 | struct weston_surface *surface; |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 5241 | struct weston_view *view; |
Pekka Paalanen | 79346ab | 2013-05-22 18:03:09 +0300 | [diff] [blame] | 5242 | |
| 5243 | surface = weston_surface_create(compositor); |
| 5244 | if (!surface) |
| 5245 | return NULL; |
| 5246 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 5247 | view = weston_view_create(surface); |
| 5248 | if (!view) { |
| 5249 | weston_surface_destroy(surface); |
| 5250 | return NULL; |
| 5251 | } |
| 5252 | |
Jason Ekstrand | 5c11a33 | 2013-12-04 20:32:03 -0600 | [diff] [blame] | 5253 | weston_surface_set_size(surface, 8192, 8192); |
Jason Ekstrand | 918f2dd | 2013-12-02 21:01:53 -0600 | [diff] [blame] | 5254 | weston_view_set_position(view, 0, 0); |
Pekka Paalanen | 79346ab | 2013-05-22 18:03:09 +0300 | [diff] [blame] | 5255 | 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] | 5256 | weston_layer_entry_insert(&compositor->fade_layer.view_list, |
| 5257 | &view->layer_link); |
Pekka Paalanen | 79346ab | 2013-05-22 18:03:09 +0300 | [diff] [blame] | 5258 | pixman_region32_init(&surface->input); |
| 5259 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 5260 | return view; |
Pekka Paalanen | 79346ab | 2013-05-22 18:03:09 +0300 | [diff] [blame] | 5261 | } |
| 5262 | |
| 5263 | static void |
| 5264 | shell_fade(struct desktop_shell *shell, enum fade_type type) |
| 5265 | { |
Ander Conselvan de Oliveira | 19d10ef | 2013-02-21 18:35:20 +0200 | [diff] [blame] | 5266 | float tint; |
| 5267 | |
| 5268 | switch (type) { |
| 5269 | case FADE_IN: |
| 5270 | tint = 0.0; |
| 5271 | break; |
| 5272 | case FADE_OUT: |
| 5273 | tint = 1.0; |
| 5274 | break; |
| 5275 | default: |
| 5276 | weston_log("shell: invalid fade type\n"); |
| 5277 | return; |
| 5278 | } |
| 5279 | |
| 5280 | shell->fade.type = type; |
| 5281 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 5282 | if (shell->fade.view == NULL) { |
| 5283 | shell->fade.view = shell_fade_create_surface(shell); |
| 5284 | if (!shell->fade.view) |
Ander Conselvan de Oliveira | 19d10ef | 2013-02-21 18:35:20 +0200 | [diff] [blame] | 5285 | return; |
| 5286 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 5287 | shell->fade.view->alpha = 1.0 - tint; |
| 5288 | weston_view_update_transform(shell->fade.view); |
Ander Conselvan de Oliveira | 19d10ef | 2013-02-21 18:35:20 +0200 | [diff] [blame] | 5289 | } |
| 5290 | |
Kristian Høgsberg | 87d3b61 | 2014-01-19 21:48:10 -0800 | [diff] [blame] | 5291 | if (shell->fade.view->output == NULL) { |
| 5292 | /* If the black view gets a NULL output, we lost the |
| 5293 | * last output and we'll just cancel the fade. This |
| 5294 | * happens when you close the last window under the |
| 5295 | * X11 or Wayland backends. */ |
| 5296 | shell->locked = false; |
| 5297 | weston_surface_destroy(shell->fade.view->surface); |
| 5298 | shell->fade.view = NULL; |
| 5299 | } else if (shell->fade.animation) { |
Kristian Høgsberg | 5281fb1 | 2013-06-17 10:10:28 -0400 | [diff] [blame] | 5300 | weston_fade_update(shell->fade.animation, tint); |
Kristian Høgsberg | 87d3b61 | 2014-01-19 21:48:10 -0800 | [diff] [blame] | 5301 | } else { |
Ander Conselvan de Oliveira | 19d10ef | 2013-02-21 18:35:20 +0200 | [diff] [blame] | 5302 | shell->fade.animation = |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 5303 | weston_fade_run(shell->fade.view, |
Kristian Høgsberg | 5281fb1 | 2013-06-17 10:10:28 -0400 | [diff] [blame] | 5304 | 1.0 - tint, tint, 300.0, |
Ander Conselvan de Oliveira | 19d10ef | 2013-02-21 18:35:20 +0200 | [diff] [blame] | 5305 | shell_fade_done, shell); |
Kristian Høgsberg | 87d3b61 | 2014-01-19 21:48:10 -0800 | [diff] [blame] | 5306 | } |
Ander Conselvan de Oliveira | 19d10ef | 2013-02-21 18:35:20 +0200 | [diff] [blame] | 5307 | } |
| 5308 | |
| 5309 | static void |
Pekka Paalanen | 79346ab | 2013-05-22 18:03:09 +0300 | [diff] [blame] | 5310 | do_shell_fade_startup(void *data) |
| 5311 | { |
| 5312 | struct desktop_shell *shell = data; |
| 5313 | |
Pekka Paalanen | 23ed5f2 | 2015-05-26 11:54:52 +0300 | [diff] [blame] | 5314 | if (shell->startup_animation_type == ANIMATION_FADE) { |
Kristian Høgsberg | 724c8d9 | 2013-10-16 11:38:24 -0700 | [diff] [blame] | 5315 | shell_fade(shell, FADE_IN); |
Pekka Paalanen | 23ed5f2 | 2015-05-26 11:54:52 +0300 | [diff] [blame] | 5316 | } else { |
| 5317 | weston_log("desktop shell: " |
| 5318 | "unexpected fade-in animation type %d\n", |
| 5319 | shell->startup_animation_type); |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 5320 | weston_surface_destroy(shell->fade.view->surface); |
| 5321 | shell->fade.view = NULL; |
Kristian Høgsberg | 724c8d9 | 2013-10-16 11:38:24 -0700 | [diff] [blame] | 5322 | } |
Pekka Paalanen | 79346ab | 2013-05-22 18:03:09 +0300 | [diff] [blame] | 5323 | } |
| 5324 | |
| 5325 | static void |
| 5326 | shell_fade_startup(struct desktop_shell *shell) |
| 5327 | { |
| 5328 | struct wl_event_loop *loop; |
| 5329 | |
| 5330 | if (!shell->fade.startup_timer) |
| 5331 | return; |
| 5332 | |
| 5333 | wl_event_source_remove(shell->fade.startup_timer); |
| 5334 | shell->fade.startup_timer = NULL; |
| 5335 | |
| 5336 | loop = wl_display_get_event_loop(shell->compositor->wl_display); |
| 5337 | wl_event_loop_add_idle(loop, do_shell_fade_startup, shell); |
| 5338 | } |
| 5339 | |
| 5340 | static int |
| 5341 | fade_startup_timeout(void *data) |
| 5342 | { |
| 5343 | struct desktop_shell *shell = data; |
| 5344 | |
| 5345 | shell_fade_startup(shell); |
| 5346 | return 0; |
| 5347 | } |
| 5348 | |
| 5349 | static void |
| 5350 | shell_fade_init(struct desktop_shell *shell) |
| 5351 | { |
| 5352 | /* Make compositor output all black, and wait for the desktop-shell |
| 5353 | * client to signal it is ready, then fade in. The timer triggers a |
| 5354 | * fade-in, in case the desktop-shell client takes too long. |
| 5355 | */ |
| 5356 | |
| 5357 | struct wl_event_loop *loop; |
| 5358 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 5359 | if (shell->fade.view != NULL) { |
Pekka Paalanen | 79346ab | 2013-05-22 18:03:09 +0300 | [diff] [blame] | 5360 | weston_log("%s: warning: fade surface already exists\n", |
| 5361 | __func__); |
| 5362 | return; |
| 5363 | } |
| 5364 | |
Pekka Paalanen | 23ed5f2 | 2015-05-26 11:54:52 +0300 | [diff] [blame] | 5365 | if (shell->startup_animation_type == ANIMATION_NONE) |
| 5366 | return; |
| 5367 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 5368 | shell->fade.view = shell_fade_create_surface(shell); |
| 5369 | if (!shell->fade.view) |
Pekka Paalanen | 79346ab | 2013-05-22 18:03:09 +0300 | [diff] [blame] | 5370 | return; |
| 5371 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 5372 | weston_view_update_transform(shell->fade.view); |
| 5373 | weston_surface_damage(shell->fade.view->surface); |
Pekka Paalanen | 79346ab | 2013-05-22 18:03:09 +0300 | [diff] [blame] | 5374 | |
| 5375 | loop = wl_display_get_event_loop(shell->compositor->wl_display); |
| 5376 | shell->fade.startup_timer = |
| 5377 | wl_event_loop_add_timer(loop, fade_startup_timeout, shell); |
| 5378 | wl_event_source_timer_update(shell->fade.startup_timer, 15000); |
| 5379 | } |
| 5380 | |
| 5381 | static void |
Ander Conselvan de Oliveira | a457563 | 2013-02-21 18:35:23 +0200 | [diff] [blame] | 5382 | idle_handler(struct wl_listener *listener, void *data) |
Ander Conselvan de Oliveira | 19d10ef | 2013-02-21 18:35:20 +0200 | [diff] [blame] | 5383 | { |
| 5384 | struct desktop_shell *shell = |
Ander Conselvan de Oliveira | a457563 | 2013-02-21 18:35:23 +0200 | [diff] [blame] | 5385 | container_of(listener, struct desktop_shell, idle_listener); |
Kristian Høgsberg | 27d5fa8 | 2014-01-17 16:22:50 -0800 | [diff] [blame] | 5386 | struct weston_seat *seat; |
| 5387 | |
Jonny Lamb | 76cf1fe | 2014-08-20 11:27:10 +0200 | [diff] [blame] | 5388 | wl_list_for_each(seat, &shell->compositor->seat_list, link) { |
Derek Foreman | 1281a36 | 2015-07-31 16:55:32 -0500 | [diff] [blame] | 5389 | struct weston_touch *touch = weston_seat_get_touch(seat); |
| 5390 | struct weston_pointer *pointer = weston_seat_get_pointer(seat); |
| 5391 | |
| 5392 | if (pointer) |
| 5393 | popup_grab_end(pointer); |
| 5394 | if (touch) |
| 5395 | touch_popup_grab_end(touch); |
Jonny Lamb | 76cf1fe | 2014-08-20 11:27:10 +0200 | [diff] [blame] | 5396 | } |
Ander Conselvan de Oliveira | 19d10ef | 2013-02-21 18:35:20 +0200 | [diff] [blame] | 5397 | |
| 5398 | shell_fade(shell, FADE_OUT); |
| 5399 | /* lock() is called from shell_fade_done() */ |
| 5400 | } |
| 5401 | |
| 5402 | static void |
Ander Conselvan de Oliveira | a457563 | 2013-02-21 18:35:23 +0200 | [diff] [blame] | 5403 | wake_handler(struct wl_listener *listener, void *data) |
Ander Conselvan de Oliveira | 19d10ef | 2013-02-21 18:35:20 +0200 | [diff] [blame] | 5404 | { |
| 5405 | struct desktop_shell *shell = |
Ander Conselvan de Oliveira | a457563 | 2013-02-21 18:35:23 +0200 | [diff] [blame] | 5406 | container_of(listener, struct desktop_shell, wake_listener); |
Ander Conselvan de Oliveira | 19d10ef | 2013-02-21 18:35:20 +0200 | [diff] [blame] | 5407 | |
Ander Conselvan de Oliveira | 19d10ef | 2013-02-21 18:35:20 +0200 | [diff] [blame] | 5408 | unlock(shell); |
| 5409 | } |
| 5410 | |
| 5411 | static void |
Giulio Camuffo | f05d18f | 2015-12-11 20:57:05 +0200 | [diff] [blame^] | 5412 | transform_handler(struct wl_listener *listener, void *data) |
| 5413 | { |
| 5414 | struct weston_surface *surface = data; |
| 5415 | struct shell_surface *shsurf = get_shell_surface(surface); |
| 5416 | struct weston_view *view;; |
| 5417 | int x, y; |
| 5418 | |
| 5419 | if (!shsurf || !shsurf->client->send_position) |
| 5420 | return; |
| 5421 | |
| 5422 | view = shsurf->view; |
| 5423 | if (!view || !weston_view_is_mapped(view)) |
| 5424 | return; |
| 5425 | |
| 5426 | x = view->geometry.x; |
| 5427 | y = view->geometry.y; |
| 5428 | |
| 5429 | shsurf->client->send_position(surface, x, y); |
| 5430 | } |
| 5431 | |
| 5432 | static void |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 5433 | center_on_output(struct weston_view *view, struct weston_output *output) |
Pekka Paalanen | 77346a6 | 2011-11-30 16:26:35 +0200 | [diff] [blame] | 5434 | { |
Giulio Camuffo | b836664 | 2013-04-25 13:57:46 +0300 | [diff] [blame] | 5435 | int32_t surf_x, surf_y, width, height; |
Ander Conselvan de Oliveira | 012b4c7 | 2012-11-27 17:03:42 +0200 | [diff] [blame] | 5436 | float x, y; |
Pekka Paalanen | 77346a6 | 2011-11-30 16:26:35 +0200 | [diff] [blame] | 5437 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 5438 | surface_subsurfaces_boundingbox(view->surface, &surf_x, &surf_y, &width, &height); |
Giulio Camuffo | b836664 | 2013-04-25 13:57:46 +0300 | [diff] [blame] | 5439 | |
| 5440 | x = output->x + (output->width - width) / 2 - surf_x / 2; |
| 5441 | y = output->y + (output->height - height) / 2 - surf_y / 2; |
Ander Conselvan de Oliveira | 012b4c7 | 2012-11-27 17:03:42 +0200 | [diff] [blame] | 5442 | |
Jason Ekstrand | 918f2dd | 2013-12-02 21:01:53 -0600 | [diff] [blame] | 5443 | weston_view_set_position(view, x, y); |
Pekka Paalanen | 77346a6 | 2011-11-30 16:26:35 +0200 | [diff] [blame] | 5444 | } |
| 5445 | |
| 5446 | static void |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 5447 | weston_view_set_initial_position(struct weston_view *view, |
| 5448 | struct desktop_shell *shell) |
Rob Bradford | ac63e5b | 2012-08-13 14:07:52 +0100 | [diff] [blame] | 5449 | { |
| 5450 | struct weston_compositor *compositor = shell->compositor; |
| 5451 | int ix = 0, iy = 0; |
Jonny Lamb | d73c694 | 2014-08-20 15:53:20 +0200 | [diff] [blame] | 5452 | int32_t range_x, range_y; |
Derek Foreman | f814c5d | 2015-04-15 12:23:54 -0500 | [diff] [blame] | 5453 | int32_t x, y; |
Rob Bradford | ac63e5b | 2012-08-13 14:07:52 +0100 | [diff] [blame] | 5454 | struct weston_output *output, *target_output = NULL; |
| 5455 | struct weston_seat *seat; |
Jonny Lamb | d73c694 | 2014-08-20 15:53:20 +0200 | [diff] [blame] | 5456 | pixman_rectangle32_t area; |
Rob Bradford | ac63e5b | 2012-08-13 14:07:52 +0100 | [diff] [blame] | 5457 | |
| 5458 | /* As a heuristic place the new window on the same output as the |
| 5459 | * pointer. Falling back to the output containing 0, 0. |
| 5460 | * |
| 5461 | * TODO: Do something clever for touch too? |
| 5462 | */ |
| 5463 | wl_list_for_each(seat, &compositor->seat_list, link) { |
Derek Foreman | 1281a36 | 2015-07-31 16:55:32 -0500 | [diff] [blame] | 5464 | struct weston_pointer *pointer = weston_seat_get_pointer(seat); |
| 5465 | |
| 5466 | if (pointer) { |
| 5467 | ix = wl_fixed_to_int(pointer->x); |
| 5468 | iy = wl_fixed_to_int(pointer->y); |
Rob Bradford | ac63e5b | 2012-08-13 14:07:52 +0100 | [diff] [blame] | 5469 | break; |
| 5470 | } |
| 5471 | } |
| 5472 | |
| 5473 | wl_list_for_each(output, &compositor->output_list, link) { |
| 5474 | if (pixman_region32_contains_point(&output->region, ix, iy, NULL)) { |
| 5475 | target_output = output; |
| 5476 | break; |
| 5477 | } |
| 5478 | } |
| 5479 | |
| 5480 | if (!target_output) { |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 5481 | weston_view_set_position(view, 10 + random() % 400, |
| 5482 | 10 + random() % 400); |
Rob Bradford | ac63e5b | 2012-08-13 14:07:52 +0100 | [diff] [blame] | 5483 | return; |
| 5484 | } |
| 5485 | |
| 5486 | /* Valid range within output where the surface will still be onscreen. |
| 5487 | * If this is negative it means that the surface is bigger than |
| 5488 | * output. |
| 5489 | */ |
Jonny Lamb | d73c694 | 2014-08-20 15:53:20 +0200 | [diff] [blame] | 5490 | get_output_work_area(shell, target_output, &area); |
| 5491 | |
Derek Foreman | f814c5d | 2015-04-15 12:23:54 -0500 | [diff] [blame] | 5492 | x = area.x; |
| 5493 | y = area.y; |
Jonny Lamb | d73c694 | 2014-08-20 15:53:20 +0200 | [diff] [blame] | 5494 | range_x = area.width - view->surface->width; |
| 5495 | range_y = area.height - view->surface->height; |
Rob Bradford | ac63e5b | 2012-08-13 14:07:52 +0100 | [diff] [blame] | 5496 | |
Rob Bradford | 4cb88c7 | 2012-08-13 15:18:44 +0100 | [diff] [blame] | 5497 | if (range_x > 0) |
Derek Foreman | f814c5d | 2015-04-15 12:23:54 -0500 | [diff] [blame] | 5498 | x += random() % range_x; |
Rob Bradford | 4cb88c7 | 2012-08-13 15:18:44 +0100 | [diff] [blame] | 5499 | |
| 5500 | if (range_y > 0) |
Derek Foreman | f814c5d | 2015-04-15 12:23:54 -0500 | [diff] [blame] | 5501 | y += random() % range_y; |
Rob Bradford | ac63e5b | 2012-08-13 14:07:52 +0100 | [diff] [blame] | 5502 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 5503 | weston_view_set_position(view, x, y); |
Rob Bradford | ac63e5b | 2012-08-13 14:07:52 +0100 | [diff] [blame] | 5504 | } |
| 5505 | |
| 5506 | static void |
Jonny Lamb | d73c694 | 2014-08-20 15:53:20 +0200 | [diff] [blame] | 5507 | set_maximized_position(struct desktop_shell *shell, |
| 5508 | struct shell_surface *shsurf) |
| 5509 | { |
| 5510 | int32_t surf_x, surf_y; |
| 5511 | pixman_rectangle32_t area; |
| 5512 | |
Jonny Lamb | d73c694 | 2014-08-20 15:53:20 +0200 | [diff] [blame] | 5513 | get_output_work_area(shell, shsurf->output, &area); |
Giulio Camuffo | 7a8d67d | 2015-01-09 20:10:45 +0200 | [diff] [blame] | 5514 | if (shsurf->has_set_geometry) { |
| 5515 | surf_x = shsurf->geometry.x; |
| 5516 | surf_y = shsurf->geometry.y; |
| 5517 | } else { |
| 5518 | surface_subsurfaces_boundingbox(shsurf->surface, |
| 5519 | &surf_x, &surf_y, NULL, NULL); |
| 5520 | } |
Jonny Lamb | d73c694 | 2014-08-20 15:53:20 +0200 | [diff] [blame] | 5521 | |
| 5522 | weston_view_set_position(shsurf->view, |
Marek Chalupa | 6ce7899 | 2015-10-09 18:17:07 +0200 | [diff] [blame] | 5523 | area.x - surf_x, |
| 5524 | area.y - surf_y); |
Jonny Lamb | d73c694 | 2014-08-20 15:53:20 +0200 | [diff] [blame] | 5525 | } |
| 5526 | |
| 5527 | static void |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 5528 | map(struct desktop_shell *shell, struct shell_surface *shsurf, |
Jason Ekstrand | 918f2dd | 2013-12-02 21:01:53 -0600 | [diff] [blame] | 5529 | int32_t sx, int32_t sy) |
Kristian Høgsberg | 02ec0a5 | 2011-04-23 13:04:11 -0400 | [diff] [blame] | 5530 | { |
Kristian Høgsberg | 8334bc1 | 2012-01-03 10:29:47 -0500 | [diff] [blame] | 5531 | struct weston_compositor *compositor = shell->compositor; |
Daniel Stone | b210468 | 2012-05-30 16:31:56 +0100 | [diff] [blame] | 5532 | struct weston_seat *seat; |
Pekka Paalanen | 57da4a8 | 2011-11-23 16:42:16 +0200 | [diff] [blame] | 5533 | |
Pekka Paalanen | 77346a6 | 2011-11-30 16:26:35 +0200 | [diff] [blame] | 5534 | /* initial positioning, see also configure() */ |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 5535 | switch (shsurf->type) { |
Rafael Antognolli | ed207b4 | 2013-12-03 15:35:43 -0200 | [diff] [blame] | 5536 | case SHELL_SURFACE_TOPLEVEL: |
Rafael Antognolli | 03b1659 | 2013-12-03 15:35:42 -0200 | [diff] [blame] | 5537 | if (shsurf->state.fullscreen) { |
| 5538 | center_on_output(shsurf->view, shsurf->fullscreen_output); |
| 5539 | shell_map_fullscreen(shsurf); |
| 5540 | } else if (shsurf->state.maximized) { |
Jonny Lamb | d73c694 | 2014-08-20 15:53:20 +0200 | [diff] [blame] | 5541 | set_maximized_position(shell, shsurf); |
Rafael Antognolli | ed207b4 | 2013-12-03 15:35:43 -0200 | [diff] [blame] | 5542 | } else if (!shsurf->state.relative) { |
Rafael Antognolli | 03b1659 | 2013-12-03 15:35:42 -0200 | [diff] [blame] | 5543 | weston_view_set_initial_position(shsurf->view, shell); |
| 5544 | } |
Juan Zhao | 96879df | 2012-02-07 08:45:41 +0800 | [diff] [blame] | 5545 | break; |
Tiago Vignatti | 0f99701 | 2012-02-10 16:17:23 +0200 | [diff] [blame] | 5546 | case SHELL_SURFACE_POPUP: |
Jasper St. Pierre | da6ecd0 | 2015-02-27 18:35:45 +0800 | [diff] [blame] | 5547 | if (shell_map_popup(shsurf) != 0) |
| 5548 | return; |
Rob Bradford | db99938 | 2012-12-06 12:07:48 +0000 | [diff] [blame] | 5549 | break; |
Ander Conselvan de Oliveira | e9e0515 | 2012-02-15 17:02:56 +0200 | [diff] [blame] | 5550 | case SHELL_SURFACE_NONE: |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 5551 | weston_view_set_position(shsurf->view, |
| 5552 | shsurf->view->geometry.x + sx, |
| 5553 | shsurf->view->geometry.y + sy); |
Tiago Vignatti | 0f99701 | 2012-02-10 16:17:23 +0200 | [diff] [blame] | 5554 | break; |
Philip Withnall | 0f640e2 | 2013-11-25 18:01:31 +0000 | [diff] [blame] | 5555 | case SHELL_SURFACE_XWAYLAND: |
Pekka Paalanen | 77346a6 | 2011-11-30 16:26:35 +0200 | [diff] [blame] | 5556 | default: |
| 5557 | ; |
| 5558 | } |
Kristian Høgsberg | 7584062 | 2011-09-06 13:48:16 -0400 | [diff] [blame] | 5559 | |
Philip Withnall | e1d75ae | 2013-11-25 18:01:41 +0000 | [diff] [blame] | 5560 | /* Surface stacking order, see also activate(). */ |
| 5561 | shell_surface_update_layer(shsurf); |
Pekka Paalanen | f0fc70d | 2011-11-15 13:34:54 +0200 | [diff] [blame] | 5562 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 5563 | if (shsurf->type != SHELL_SURFACE_NONE) { |
| 5564 | weston_view_update_transform(shsurf->view); |
Rafael Antognolli | 03b1659 | 2013-12-03 15:35:42 -0200 | [diff] [blame] | 5565 | if (shsurf->state.maximized) { |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 5566 | shsurf->surface->output = shsurf->output; |
| 5567 | shsurf->view->output = shsurf->output; |
| 5568 | } |
Ander Conselvan de Oliveira | de56c31 | 2012-03-05 15:39:23 +0200 | [diff] [blame] | 5569 | } |
Kristian Høgsberg | 2f88a40 | 2011-12-04 15:32:59 -0500 | [diff] [blame] | 5570 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 5571 | switch (shsurf->type) { |
Tiago Vignatti | fb2adba | 2013-06-12 15:43:21 -0300 | [diff] [blame] | 5572 | /* XXX: xwayland's using the same fields for transient type */ |
| 5573 | case SHELL_SURFACE_XWAYLAND: |
Tiago Vignatti | 99aeb1e | 2012-05-23 22:06:26 +0300 | [diff] [blame] | 5574 | if (shsurf->transient.flags == |
| 5575 | WL_SHELL_SURFACE_TRANSIENT_INACTIVE) |
| 5576 | break; |
| 5577 | case SHELL_SURFACE_TOPLEVEL: |
Rafael Antognolli | ed207b4 | 2013-12-03 15:35:43 -0200 | [diff] [blame] | 5578 | if (shsurf->state.relative && |
| 5579 | shsurf->transient.flags == WL_SHELL_SURFACE_TRANSIENT_INACTIVE) |
| 5580 | break; |
Rafael Antognolli | ba5d2d7 | 2013-12-04 17:49:55 -0200 | [diff] [blame] | 5581 | if (shell->locked) |
Rafael Antognolli | ed207b4 | 2013-12-03 15:35:43 -0200 | [diff] [blame] | 5582 | break; |
| 5583 | wl_list_for_each(seat, &compositor->seat_list, link) |
Emilio Pozuelo Monfort | 9e7c759 | 2014-01-30 14:01:10 +0100 | [diff] [blame] | 5584 | activate(shell, shsurf->surface, seat, true); |
Juan Zhao | 7bb92f0 | 2011-12-15 11:31:51 -0500 | [diff] [blame] | 5585 | break; |
Philip Withnall | 0f640e2 | 2013-11-25 18:01:31 +0000 | [diff] [blame] | 5586 | case SHELL_SURFACE_POPUP: |
| 5587 | case SHELL_SURFACE_NONE: |
Juan Zhao | 7bb92f0 | 2011-12-15 11:31:51 -0500 | [diff] [blame] | 5588 | default: |
| 5589 | break; |
| 5590 | } |
| 5591 | |
Rafael Antognolli | 03b1659 | 2013-12-03 15:35:42 -0200 | [diff] [blame] | 5592 | if (shsurf->type == SHELL_SURFACE_TOPLEVEL && |
| 5593 | !shsurf->state.maximized && !shsurf->state.fullscreen) |
Juan Zhao | e10d279 | 2012-04-25 19:09:52 +0800 | [diff] [blame] | 5594 | { |
| 5595 | switch (shell->win_animation_type) { |
| 5596 | case ANIMATION_FADE: |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 5597 | 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] | 5598 | break; |
| 5599 | case ANIMATION_ZOOM: |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 5600 | weston_zoom_run(shsurf->view, 0.5, 1.0, NULL, NULL); |
Juan Zhao | e10d279 | 2012-04-25 19:09:52 +0800 | [diff] [blame] | 5601 | break; |
Philip Withnall | 4a86a0a | 2013-11-25 18:01:32 +0000 | [diff] [blame] | 5602 | case ANIMATION_NONE: |
Juan Zhao | e10d279 | 2012-04-25 19:09:52 +0800 | [diff] [blame] | 5603 | default: |
| 5604 | break; |
| 5605 | } |
| 5606 | } |
Kristian Høgsberg | 32e24cc | 2011-11-09 12:07:35 -0500 | [diff] [blame] | 5607 | } |
| 5608 | |
| 5609 | static void |
Tiago Vignatti | be14326 | 2012-04-16 17:31:41 +0300 | [diff] [blame] | 5610 | configure(struct desktop_shell *shell, struct weston_surface *surface, |
Jason Ekstrand | 918f2dd | 2013-12-02 21:01:53 -0600 | [diff] [blame] | 5611 | float x, float y) |
Kristian Høgsberg | 32e24cc | 2011-11-09 12:07:35 -0500 | [diff] [blame] | 5612 | { |
Pekka Paalanen | 77346a6 | 2011-11-30 16:26:35 +0200 | [diff] [blame] | 5613 | struct shell_surface *shsurf; |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 5614 | struct weston_view *view; |
Kristian Høgsberg | 32e24cc | 2011-11-09 12:07:35 -0500 | [diff] [blame] | 5615 | |
Pekka Paalanen | 77346a6 | 2011-11-30 16:26:35 +0200 | [diff] [blame] | 5616 | shsurf = get_shell_surface(surface); |
Pekka Paalanen | 77346a6 | 2011-11-30 16:26:35 +0200 | [diff] [blame] | 5617 | |
U. Artie Eoff | cf5737a | 2014-01-17 10:08:25 -0800 | [diff] [blame] | 5618 | assert(shsurf); |
| 5619 | |
Rafael Antognolli | 03b1659 | 2013-12-03 15:35:42 -0200 | [diff] [blame] | 5620 | if (shsurf->state.fullscreen) |
Alex Wu | 4539b08 | 2012-03-01 12:57:46 +0800 | [diff] [blame] | 5621 | shell_configure_fullscreen(shsurf); |
Rafael Antognolli | 03b1659 | 2013-12-03 15:35:42 -0200 | [diff] [blame] | 5622 | else if (shsurf->state.maximized) { |
Jonny Lamb | d73c694 | 2014-08-20 15:53:20 +0200 | [diff] [blame] | 5623 | set_maximized_position(shell, shsurf); |
Rafael Antognolli | 03b1659 | 2013-12-03 15:35:42 -0200 | [diff] [blame] | 5624 | } else { |
Jason Ekstrand | 918f2dd | 2013-12-02 21:01:53 -0600 | [diff] [blame] | 5625 | weston_view_set_position(shsurf->view, x, y); |
Kristian Høgsberg | 7a5c979 | 2011-06-18 06:12:54 -0400 | [diff] [blame] | 5626 | } |
Kristian Høgsberg | 32e24cc | 2011-11-09 12:07:35 -0500 | [diff] [blame] | 5627 | |
Alex Wu | 4539b08 | 2012-03-01 12:57:46 +0800 | [diff] [blame] | 5628 | /* XXX: would a fullscreen surface need the same handling? */ |
Kristian Høgsberg | 6a8b553 | 2012-02-16 23:43:59 -0500 | [diff] [blame] | 5629 | if (surface->output) { |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 5630 | wl_list_for_each(view, &surface->views, surface_link) |
| 5631 | weston_view_update_transform(view); |
Pekka Paalanen | 77346a6 | 2011-11-30 16:26:35 +0200 | [diff] [blame] | 5632 | |
Rafael Antognolli | 03b1659 | 2013-12-03 15:35:42 -0200 | [diff] [blame] | 5633 | if (shsurf->state.maximized) |
Juan Zhao | 96879df | 2012-02-07 08:45:41 +0800 | [diff] [blame] | 5634 | surface->output = shsurf->output; |
Pekka Paalanen | 77346a6 | 2011-11-30 16:26:35 +0200 | [diff] [blame] | 5635 | } |
Kristian Høgsberg | 0793756 | 2011-04-12 17:25:42 -0400 | [diff] [blame] | 5636 | } |
| 5637 | |
Ander Conselvan de Oliveira | 093bfa3 | 2012-03-27 17:36:41 +0300 | [diff] [blame] | 5638 | static void |
Jason Ekstrand | 918f2dd | 2013-12-02 21:01:53 -0600 | [diff] [blame] | 5639 | 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] | 5640 | { |
Ander Conselvan de Oliveira | 7fb9f95 | 2012-03-27 17:36:42 +0300 | [diff] [blame] | 5641 | struct shell_surface *shsurf = get_shell_surface(es); |
U. Artie Eoff | cf5737a | 2014-01-17 10:08:25 -0800 | [diff] [blame] | 5642 | struct desktop_shell *shell; |
Tiago Vignatti | 70e5c9c | 2012-05-07 15:23:07 +0300 | [diff] [blame] | 5643 | int type_changed = 0; |
Ander Conselvan de Oliveira | 093bfa3 | 2012-03-27 17:36:41 +0300 | [diff] [blame] | 5644 | |
U. Artie Eoff | cf5737a | 2014-01-17 10:08:25 -0800 | [diff] [blame] | 5645 | assert(shsurf); |
| 5646 | |
| 5647 | shell = shsurf->shell; |
| 5648 | |
Kristian Høgsberg | 8eb0f4f | 2013-06-17 10:33:14 -0400 | [diff] [blame] | 5649 | if (!weston_surface_is_mapped(es) && |
| 5650 | !wl_list_empty(&shsurf->popup.grab_link)) { |
Giulio Camuffo | 5085a75 | 2013-03-25 21:42:45 +0100 | [diff] [blame] | 5651 | remove_popup_grab(shsurf); |
| 5652 | } |
| 5653 | |
Jason Ekstrand | 918f2dd | 2013-12-02 21:01:53 -0600 | [diff] [blame] | 5654 | if (es->width == 0) |
Giulio Camuffo | 184df50 | 2013-02-21 11:29:21 +0100 | [diff] [blame] | 5655 | return; |
| 5656 | |
Jasper St. Pierre | ccf48fb | 2014-05-02 10:21:38 -0400 | [diff] [blame] | 5657 | if (shsurf->has_next_geometry) { |
| 5658 | shsurf->geometry = shsurf->next_geometry; |
| 5659 | shsurf->has_next_geometry = false; |
| 5660 | shsurf->has_set_geometry = true; |
| 5661 | } else if (!shsurf->has_set_geometry) { |
| 5662 | surface_subsurfaces_boundingbox(shsurf->surface, |
| 5663 | &shsurf->geometry.x, |
| 5664 | &shsurf->geometry.y, |
| 5665 | &shsurf->geometry.width, |
| 5666 | &shsurf->geometry.height); |
Jasper St. Pierre | 851799e | 2014-05-02 10:14:07 -0400 | [diff] [blame] | 5667 | } |
| 5668 | |
Kristian Høgsberg | c8f8dd8 | 2013-12-05 23:20:33 -0800 | [diff] [blame] | 5669 | if (shsurf->state_changed) { |
Kristian Høgsberg | 7f366e7 | 2012-04-27 17:20:01 -0400 | [diff] [blame] | 5670 | set_surface_type(shsurf); |
Kristian Høgsberg | f7e23d5 | 2012-04-27 17:51:59 -0400 | [diff] [blame] | 5671 | type_changed = 1; |
| 5672 | } |
Kristian Høgsberg | 7f366e7 | 2012-04-27 17:20:01 -0400 | [diff] [blame] | 5673 | |
Ander Conselvan de Oliveira | 093bfa3 | 2012-03-27 17:36:41 +0300 | [diff] [blame] | 5674 | if (!weston_surface_is_mapped(es)) { |
Jason Ekstrand | 918f2dd | 2013-12-02 21:01:53 -0600 | [diff] [blame] | 5675 | map(shell, shsurf, sx, sy); |
Kristian Høgsberg | f7e23d5 | 2012-04-27 17:51:59 -0400 | [diff] [blame] | 5676 | } else if (type_changed || sx != 0 || sy != 0 || |
Jason Ekstrand | 918f2dd | 2013-12-02 21:01:53 -0600 | [diff] [blame] | 5677 | shsurf->last_width != es->width || |
| 5678 | shsurf->last_height != es->height) { |
John Kåre Alsaker | 490d02a | 2012-09-30 02:57:21 +0200 | [diff] [blame] | 5679 | float from_x, from_y; |
| 5680 | float to_x, to_y; |
Ander Conselvan de Oliveira | 093bfa3 | 2012-03-27 17:36:41 +0300 | [diff] [blame] | 5681 | |
Kristian Høgsberg | 44cd196 | 2014-02-05 21:36:04 -0800 | [diff] [blame] | 5682 | if (shsurf->resize_edges) { |
| 5683 | sx = 0; |
| 5684 | sy = 0; |
| 5685 | } |
| 5686 | |
| 5687 | if (shsurf->resize_edges & WL_SHELL_SURFACE_RESIZE_LEFT) |
| 5688 | sx = shsurf->last_width - es->width; |
| 5689 | if (shsurf->resize_edges & WL_SHELL_SURFACE_RESIZE_TOP) |
| 5690 | sy = shsurf->last_height - es->height; |
| 5691 | |
| 5692 | shsurf->last_width = es->width; |
| 5693 | shsurf->last_height = es->height; |
| 5694 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 5695 | weston_view_to_global_float(shsurf->view, 0, 0, &from_x, &from_y); |
| 5696 | 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] | 5697 | configure(shell, es, |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 5698 | shsurf->view->geometry.x + to_x - from_x, |
Jason Ekstrand | 918f2dd | 2013-12-02 21:01:53 -0600 | [diff] [blame] | 5699 | shsurf->view->geometry.y + to_y - from_y); |
Ander Conselvan de Oliveira | 093bfa3 | 2012-03-27 17:36:41 +0300 | [diff] [blame] | 5700 | } |
| 5701 | } |
| 5702 | |
Pekka Paalanen | 2e62e4a | 2014-08-28 11:41:26 +0300 | [diff] [blame] | 5703 | static bool |
| 5704 | check_desktop_shell_crash_too_early(struct desktop_shell *shell) |
| 5705 | { |
| 5706 | struct timespec now; |
| 5707 | |
| 5708 | if (clock_gettime(CLOCK_MONOTONIC, &now) < 0) |
| 5709 | return false; |
| 5710 | |
| 5711 | /* |
| 5712 | * If the shell helper client dies before the session has been |
| 5713 | * up for roughly 30 seconds, better just make Weston shut down, |
| 5714 | * because the user likely has no way to interact with the desktop |
| 5715 | * anyway. |
| 5716 | */ |
| 5717 | if (now.tv_sec - shell->startup_time.tv_sec < 30) { |
| 5718 | weston_log("Error: %s apparently cannot run at all.\n", |
| 5719 | shell->client); |
| 5720 | weston_log_continue(STAMP_SPACE "Quitting..."); |
| 5721 | wl_display_terminate(shell->compositor->wl_display); |
| 5722 | |
| 5723 | return true; |
| 5724 | } |
| 5725 | |
| 5726 | return false; |
| 5727 | } |
| 5728 | |
Tiago Vignatti | b7dbbd6 | 2012-09-25 17:57:01 +0300 | [diff] [blame] | 5729 | static void launch_desktop_shell_process(void *data); |
Pekka Paalanen | 4d733ee | 2012-01-17 14:36:27 +0200 | [diff] [blame] | 5730 | |
Kristian Høgsberg | 97d44aa | 2011-08-26 17:21:20 -0400 | [diff] [blame] | 5731 | static void |
Pekka Paalanen | 826dc14 | 2014-08-27 12:11:53 +0300 | [diff] [blame] | 5732 | respawn_desktop_shell_process(struct desktop_shell *shell) |
Pekka Paalanen | 6cd281a | 2011-11-03 14:11:32 +0200 | [diff] [blame] | 5733 | { |
Pekka Paalanen | 4d733ee | 2012-01-17 14:36:27 +0200 | [diff] [blame] | 5734 | uint32_t time; |
Pekka Paalanen | 4d733ee | 2012-01-17 14:36:27 +0200 | [diff] [blame] | 5735 | |
| 5736 | /* if desktop-shell dies more than 5 times in 30 seconds, give up */ |
| 5737 | time = weston_compositor_get_time(); |
Kristian Høgsberg | f03a616 | 2012-01-17 11:07:42 -0500 | [diff] [blame] | 5738 | if (time - shell->child.deathstamp > 30000) { |
Pekka Paalanen | 4d733ee | 2012-01-17 14:36:27 +0200 | [diff] [blame] | 5739 | shell->child.deathstamp = time; |
| 5740 | shell->child.deathcount = 0; |
| 5741 | } |
| 5742 | |
| 5743 | shell->child.deathcount++; |
| 5744 | if (shell->child.deathcount > 5) { |
Pekka Paalanen | 826dc14 | 2014-08-27 12:11:53 +0300 | [diff] [blame] | 5745 | weston_log("%s disconnected, giving up.\n", shell->client); |
Pekka Paalanen | 4d733ee | 2012-01-17 14:36:27 +0200 | [diff] [blame] | 5746 | return; |
| 5747 | } |
| 5748 | |
Pekka Paalanen | 826dc14 | 2014-08-27 12:11:53 +0300 | [diff] [blame] | 5749 | weston_log("%s disconnected, respawning...\n", shell->client); |
Pekka Paalanen | 4d733ee | 2012-01-17 14:36:27 +0200 | [diff] [blame] | 5750 | launch_desktop_shell_process(shell); |
Pekka Paalanen | 6cd281a | 2011-11-03 14:11:32 +0200 | [diff] [blame] | 5751 | } |
| 5752 | |
Tiago Vignatti | b7dbbd6 | 2012-09-25 17:57:01 +0300 | [diff] [blame] | 5753 | static void |
Ander Conselvan de Oliveira | 312ea4c | 2013-12-20 21:07:01 +0200 | [diff] [blame] | 5754 | desktop_shell_client_destroy(struct wl_listener *listener, void *data) |
| 5755 | { |
| 5756 | struct desktop_shell *shell; |
| 5757 | |
| 5758 | shell = container_of(listener, struct desktop_shell, |
| 5759 | child.client_destroy_listener); |
| 5760 | |
Pekka Paalanen | 826dc14 | 2014-08-27 12:11:53 +0300 | [diff] [blame] | 5761 | wl_list_remove(&shell->child.client_destroy_listener.link); |
Ander Conselvan de Oliveira | 312ea4c | 2013-12-20 21:07:01 +0200 | [diff] [blame] | 5762 | shell->child.client = NULL; |
Pekka Paalanen | 826dc14 | 2014-08-27 12:11:53 +0300 | [diff] [blame] | 5763 | /* |
| 5764 | * unbind_desktop_shell() will reset shell->child.desktop_shell |
| 5765 | * before the respawned process has a chance to create a new |
| 5766 | * desktop_shell object, because we are being called from the |
| 5767 | * wl_client destructor which destroys all wl_resources before |
| 5768 | * returning. |
| 5769 | */ |
| 5770 | |
Pekka Paalanen | 2e62e4a | 2014-08-28 11:41:26 +0300 | [diff] [blame] | 5771 | if (!check_desktop_shell_crash_too_early(shell)) |
| 5772 | respawn_desktop_shell_process(shell); |
| 5773 | |
Pekka Paalanen | 826dc14 | 2014-08-27 12:11:53 +0300 | [diff] [blame] | 5774 | shell_fade_startup(shell); |
Ander Conselvan de Oliveira | 312ea4c | 2013-12-20 21:07:01 +0200 | [diff] [blame] | 5775 | } |
| 5776 | |
| 5777 | static void |
Tiago Vignatti | b7dbbd6 | 2012-09-25 17:57:01 +0300 | [diff] [blame] | 5778 | launch_desktop_shell_process(void *data) |
Pekka Paalanen | 6cd281a | 2011-11-03 14:11:32 +0200 | [diff] [blame] | 5779 | { |
Tiago Vignatti | b7dbbd6 | 2012-09-25 17:57:01 +0300 | [diff] [blame] | 5780 | struct desktop_shell *shell = data; |
Pekka Paalanen | 6cd281a | 2011-11-03 14:11:32 +0200 | [diff] [blame] | 5781 | |
Pekka Paalanen | 826dc14 | 2014-08-27 12:11:53 +0300 | [diff] [blame] | 5782 | shell->child.client = weston_client_start(shell->compositor, |
| 5783 | shell->client); |
Pekka Paalanen | 409ef0a | 2011-12-02 15:30:21 +0200 | [diff] [blame] | 5784 | |
Arnaud Vrac | 4263119 | 2014-08-25 20:56:46 +0200 | [diff] [blame] | 5785 | if (!shell->child.client) { |
Emilio Pozuelo Monfort | 46ce798 | 2013-11-20 13:22:29 +0100 | [diff] [blame] | 5786 | weston_log("not able to start %s\n", shell->client); |
Arnaud Vrac | 4263119 | 2014-08-25 20:56:46 +0200 | [diff] [blame] | 5787 | return; |
| 5788 | } |
Ander Conselvan de Oliveira | 312ea4c | 2013-12-20 21:07:01 +0200 | [diff] [blame] | 5789 | |
| 5790 | shell->child.client_destroy_listener.notify = |
| 5791 | desktop_shell_client_destroy; |
| 5792 | wl_client_add_destroy_listener(shell->child.client, |
| 5793 | &shell->child.client_destroy_listener); |
Pekka Paalanen | 6cd281a | 2011-11-03 14:11:32 +0200 | [diff] [blame] | 5794 | } |
| 5795 | |
| 5796 | static void |
Kristian Høgsberg | 2bff94e | 2014-02-11 12:22:51 -0800 | [diff] [blame] | 5797 | handle_shell_client_destroy(struct wl_listener *listener, void *data) |
| 5798 | { |
| 5799 | struct shell_client *sc = |
| 5800 | container_of(listener, struct shell_client, destroy_listener); |
| 5801 | |
| 5802 | if (sc->ping_timer) |
| 5803 | wl_event_source_remove(sc->ping_timer); |
Derek Foreman | e42d754 | 2015-05-29 10:46:44 -0500 | [diff] [blame] | 5804 | |
| 5805 | /* Since we're about to free shell_client, we remove it from the |
| 5806 | * head of the surface list so we don't use that freed list node |
| 5807 | * during surface clean up later on. |
| 5808 | */ |
| 5809 | wl_list_remove(&sc->surface_list); |
| 5810 | |
Kristian Høgsberg | 2bff94e | 2014-02-11 12:22:51 -0800 | [diff] [blame] | 5811 | free(sc); |
| 5812 | } |
| 5813 | |
Kristian Høgsberg | dd62aba | 2014-02-12 09:56:19 -0800 | [diff] [blame] | 5814 | static struct shell_client * |
| 5815 | shell_client_create(struct wl_client *client, struct desktop_shell *shell, |
| 5816 | const struct wl_interface *interface, uint32_t id) |
Rafael Antognolli | e2a3455 | 2013-12-03 15:35:45 -0200 | [diff] [blame] | 5817 | { |
Kristian Høgsberg | 2bff94e | 2014-02-11 12:22:51 -0800 | [diff] [blame] | 5818 | struct shell_client *sc; |
Rafael Antognolli | e2a3455 | 2013-12-03 15:35:45 -0200 | [diff] [blame] | 5819 | |
Kristian Høgsberg | 2bff94e | 2014-02-11 12:22:51 -0800 | [diff] [blame] | 5820 | sc = zalloc(sizeof *sc); |
| 5821 | if (sc == NULL) { |
| 5822 | wl_client_post_no_memory(client); |
Kristian Høgsberg | dd62aba | 2014-02-12 09:56:19 -0800 | [diff] [blame] | 5823 | return NULL; |
Kristian Høgsberg | 2bff94e | 2014-02-11 12:22:51 -0800 | [diff] [blame] | 5824 | } |
Kristian Høgsberg | dd62aba | 2014-02-12 09:56:19 -0800 | [diff] [blame] | 5825 | |
| 5826 | sc->resource = wl_resource_create(client, interface, 1, id); |
Kristian Høgsberg | 2bff94e | 2014-02-11 12:22:51 -0800 | [diff] [blame] | 5827 | if (sc->resource == NULL) { |
| 5828 | free(sc); |
| 5829 | wl_client_post_no_memory(client); |
Kristian Høgsberg | dd62aba | 2014-02-12 09:56:19 -0800 | [diff] [blame] | 5830 | return NULL; |
Kristian Høgsberg | 2bff94e | 2014-02-11 12:22:51 -0800 | [diff] [blame] | 5831 | } |
| 5832 | |
| 5833 | sc->client = client; |
| 5834 | sc->shell = shell; |
| 5835 | sc->destroy_listener.notify = handle_shell_client_destroy; |
| 5836 | wl_client_add_destroy_listener(client, &sc->destroy_listener); |
Jonas Ådahl | 49d77d2 | 2015-03-18 16:20:51 +0800 | [diff] [blame] | 5837 | wl_list_init(&sc->surface_list); |
Kristian Høgsberg | 2bff94e | 2014-02-11 12:22:51 -0800 | [diff] [blame] | 5838 | |
Kristian Høgsberg | dd62aba | 2014-02-12 09:56:19 -0800 | [diff] [blame] | 5839 | return sc; |
| 5840 | } |
| 5841 | |
| 5842 | static void |
| 5843 | bind_shell(struct wl_client *client, void *data, uint32_t version, uint32_t id) |
| 5844 | { |
| 5845 | struct desktop_shell *shell = data; |
| 5846 | struct shell_client *sc; |
| 5847 | |
| 5848 | sc = shell_client_create(client, shell, &wl_shell_interface, id); |
| 5849 | if (sc) |
| 5850 | wl_resource_set_implementation(sc->resource, |
| 5851 | &shell_implementation, |
Jason Ekstrand | 9e9512f | 2014-04-16 21:12:10 -0500 | [diff] [blame] | 5852 | sc, NULL); |
Kristian Høgsberg | dd62aba | 2014-02-12 09:56:19 -0800 | [diff] [blame] | 5853 | } |
| 5854 | |
| 5855 | static void |
| 5856 | bind_xdg_shell(struct wl_client *client, void *data, uint32_t version, uint32_t id) |
| 5857 | { |
| 5858 | struct desktop_shell *shell = data; |
| 5859 | struct shell_client *sc; |
| 5860 | |
| 5861 | sc = shell_client_create(client, shell, &xdg_shell_interface, id); |
| 5862 | if (sc) |
| 5863 | wl_resource_set_dispatcher(sc->resource, |
| 5864 | xdg_shell_unversioned_dispatch, |
| 5865 | NULL, sc, NULL); |
Rafael Antognolli | e2a3455 | 2013-12-03 15:35:45 -0200 | [diff] [blame] | 5866 | } |
| 5867 | |
| 5868 | static void |
Pekka Paalanen | 9ef3e01 | 2011-11-15 13:34:48 +0200 | [diff] [blame] | 5869 | unbind_desktop_shell(struct wl_resource *resource) |
| 5870 | { |
Jason Ekstrand | 651f00e | 2013-06-14 10:07:54 -0500 | [diff] [blame] | 5871 | struct desktop_shell *shell = wl_resource_get_user_data(resource); |
Kristian Høgsberg | 1ec0c31 | 2011-11-15 16:39:55 -0500 | [diff] [blame] | 5872 | |
| 5873 | if (shell->locked) |
| 5874 | resume_desktop(shell); |
| 5875 | |
Pekka Paalanen | 9ef3e01 | 2011-11-15 13:34:48 +0200 | [diff] [blame] | 5876 | shell->child.desktop_shell = NULL; |
| 5877 | shell->prepare_event_sent = false; |
Pekka Paalanen | 9ef3e01 | 2011-11-15 13:34:48 +0200 | [diff] [blame] | 5878 | } |
| 5879 | |
| 5880 | static void |
Kristian Høgsberg | 7584062 | 2011-09-06 13:48:16 -0400 | [diff] [blame] | 5881 | bind_desktop_shell(struct wl_client *client, |
| 5882 | void *data, uint32_t version, uint32_t id) |
| 5883 | { |
Tiago Vignatti | be14326 | 2012-04-16 17:31:41 +0300 | [diff] [blame] | 5884 | struct desktop_shell *shell = data; |
Pekka Paalanen | bbe6052 | 2011-11-03 14:11:33 +0200 | [diff] [blame] | 5885 | struct wl_resource *resource; |
Kristian Høgsberg | 7584062 | 2011-09-06 13:48:16 -0400 | [diff] [blame] | 5886 | |
Jonas Ådahl | 6d6fb61 | 2015-11-17 16:00:33 +0800 | [diff] [blame] | 5887 | resource = wl_resource_create(client, &weston_desktop_shell_interface, |
| 5888 | 1, id); |
Pekka Paalanen | bbe6052 | 2011-11-03 14:11:33 +0200 | [diff] [blame] | 5889 | |
Pekka Paalanen | 9ef3e01 | 2011-11-15 13:34:48 +0200 | [diff] [blame] | 5890 | if (client == shell->child.client) { |
Jason Ekstrand | a85118c | 2013-06-27 20:17:02 -0500 | [diff] [blame] | 5891 | wl_resource_set_implementation(resource, |
| 5892 | &desktop_shell_implementation, |
| 5893 | shell, unbind_desktop_shell); |
Pekka Paalanen | 9ef3e01 | 2011-11-15 13:34:48 +0200 | [diff] [blame] | 5894 | shell->child.desktop_shell = resource; |
Pekka Paalanen | bbe6052 | 2011-11-03 14:11:33 +0200 | [diff] [blame] | 5895 | return; |
Pekka Paalanen | 9ef3e01 | 2011-11-15 13:34:48 +0200 | [diff] [blame] | 5896 | } |
Pekka Paalanen | bbe6052 | 2011-11-03 14:11:33 +0200 | [diff] [blame] | 5897 | |
| 5898 | wl_resource_post_error(resource, WL_DISPLAY_ERROR_INVALID_OBJECT, |
| 5899 | "permission to bind desktop_shell denied"); |
Kristian Høgsberg | 7584062 | 2011-09-06 13:48:16 -0400 | [diff] [blame] | 5900 | } |
| 5901 | |
Kristian Høgsberg | 0704539 | 2012-02-19 18:52:44 -0500 | [diff] [blame] | 5902 | struct switcher { |
Tiago Vignatti | be14326 | 2012-04-16 17:31:41 +0300 | [diff] [blame] | 5903 | struct desktop_shell *shell; |
Kristian Høgsberg | 0704539 | 2012-02-19 18:52:44 -0500 | [diff] [blame] | 5904 | struct weston_surface *current; |
| 5905 | struct wl_listener listener; |
Kristian Høgsberg | 29139d4 | 2013-04-18 15:25:39 -0400 | [diff] [blame] | 5906 | struct weston_keyboard_grab grab; |
Manuel Bachmann | c1ae2e8 | 2014-02-26 15:53:11 +0100 | [diff] [blame] | 5907 | struct wl_array minimized_array; |
Kristian Høgsberg | 0704539 | 2012-02-19 18:52:44 -0500 | [diff] [blame] | 5908 | }; |
| 5909 | |
| 5910 | static void |
| 5911 | switcher_next(struct switcher *switcher) |
| 5912 | { |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 5913 | struct weston_view *view; |
Kristian Høgsberg | 0704539 | 2012-02-19 18:52:44 -0500 | [diff] [blame] | 5914 | struct weston_surface *first = NULL, *prev = NULL, *next = NULL; |
Kristian Høgsberg | 32e5686 | 2012-04-02 22:18:58 -0400 | [diff] [blame] | 5915 | struct shell_surface *shsurf; |
Kristian Høgsberg | b0d8e77 | 2012-06-18 16:34:58 -0400 | [diff] [blame] | 5916 | struct workspace *ws = get_current_workspace(switcher->shell); |
Kristian Høgsberg | 0704539 | 2012-02-19 18:52:44 -0500 | [diff] [blame] | 5917 | |
Manuel Bachmann | c1ae2e8 | 2014-02-26 15:53:11 +0100 | [diff] [blame] | 5918 | /* temporary re-display minimized surfaces */ |
| 5919 | struct weston_view *tmp; |
| 5920 | struct weston_view **minimized; |
Giulio Camuffo | 412e6a5 | 2014-07-09 22:12:56 +0300 | [diff] [blame] | 5921 | wl_list_for_each_safe(view, tmp, &switcher->shell->minimized_layer.view_list.link, layer_link.link) { |
| 5922 | weston_layer_entry_remove(&view->layer_link); |
| 5923 | weston_layer_entry_insert(&ws->layer.view_list, &view->layer_link); |
Manuel Bachmann | c1ae2e8 | 2014-02-26 15:53:11 +0100 | [diff] [blame] | 5924 | minimized = wl_array_add(&switcher->minimized_array, sizeof *minimized); |
| 5925 | *minimized = view; |
| 5926 | } |
| 5927 | |
Giulio Camuffo | 412e6a5 | 2014-07-09 22:12:56 +0300 | [diff] [blame] | 5928 | 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] | 5929 | shsurf = get_shell_surface(view->surface); |
Rafael Antognolli | 5031cbe | 2013-12-05 19:01:21 -0200 | [diff] [blame] | 5930 | if (shsurf && |
| 5931 | shsurf->type == SHELL_SURFACE_TOPLEVEL && |
| 5932 | shsurf->parent == NULL) { |
Kristian Høgsberg | 0704539 | 2012-02-19 18:52:44 -0500 | [diff] [blame] | 5933 | if (first == NULL) |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 5934 | first = view->surface; |
Kristian Høgsberg | 0704539 | 2012-02-19 18:52:44 -0500 | [diff] [blame] | 5935 | if (prev == switcher->current) |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 5936 | next = view->surface; |
| 5937 | prev = view->surface; |
| 5938 | view->alpha = 0.25; |
| 5939 | weston_view_geometry_dirty(view); |
| 5940 | weston_surface_damage(view->surface); |
Kristian Høgsberg | 0704539 | 2012-02-19 18:52:44 -0500 | [diff] [blame] | 5941 | } |
Alex Wu | 1659daa | 2012-04-01 20:13:09 +0800 | [diff] [blame] | 5942 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 5943 | if (is_black_surface(view->surface, NULL)) { |
| 5944 | view->alpha = 0.25; |
| 5945 | weston_view_geometry_dirty(view); |
| 5946 | weston_surface_damage(view->surface); |
Alex Wu | 1659daa | 2012-04-01 20:13:09 +0800 | [diff] [blame] | 5947 | } |
Kristian Høgsberg | 0704539 | 2012-02-19 18:52:44 -0500 | [diff] [blame] | 5948 | } |
| 5949 | |
| 5950 | if (next == NULL) |
| 5951 | next = first; |
| 5952 | |
Alex Wu | 07b2606 | 2012-03-12 16:06:01 +0800 | [diff] [blame] | 5953 | if (next == NULL) |
| 5954 | return; |
| 5955 | |
Kristian Høgsberg | 0704539 | 2012-02-19 18:52:44 -0500 | [diff] [blame] | 5956 | wl_list_remove(&switcher->listener.link); |
Jason Ekstrand | 26ed73c | 2013-06-06 22:34:41 -0500 | [diff] [blame] | 5957 | wl_signal_add(&next->destroy_signal, &switcher->listener); |
Kristian Høgsberg | 0704539 | 2012-02-19 18:52:44 -0500 | [diff] [blame] | 5958 | |
| 5959 | switcher->current = next; |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 5960 | wl_list_for_each(view, &next->views, surface_link) |
| 5961 | view->alpha = 1.0; |
Alex Wu | 1659daa | 2012-04-01 20:13:09 +0800 | [diff] [blame] | 5962 | |
Kristian Høgsberg | 32e5686 | 2012-04-02 22:18:58 -0400 | [diff] [blame] | 5963 | shsurf = get_shell_surface(switcher->current); |
Rafael Antognolli | 03b1659 | 2013-12-03 15:35:42 -0200 | [diff] [blame] | 5964 | if (shsurf && shsurf->state.fullscreen) |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 5965 | shsurf->fullscreen.black_view->alpha = 1.0; |
Kristian Høgsberg | 0704539 | 2012-02-19 18:52:44 -0500 | [diff] [blame] | 5966 | } |
| 5967 | |
| 5968 | static void |
Kristian Høgsberg | 27e3052 | 2012-04-11 23:18:23 -0400 | [diff] [blame] | 5969 | switcher_handle_surface_destroy(struct wl_listener *listener, void *data) |
Kristian Høgsberg | 0704539 | 2012-02-19 18:52:44 -0500 | [diff] [blame] | 5970 | { |
| 5971 | struct switcher *switcher = |
| 5972 | container_of(listener, struct switcher, listener); |
| 5973 | |
| 5974 | switcher_next(switcher); |
| 5975 | } |
| 5976 | |
| 5977 | static void |
Daniel Stone | 351eb61 | 2012-05-31 15:27:47 -0400 | [diff] [blame] | 5978 | switcher_destroy(struct switcher *switcher) |
Kristian Høgsberg | 0704539 | 2012-02-19 18:52:44 -0500 | [diff] [blame] | 5979 | { |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 5980 | struct weston_view *view; |
Kristian Høgsberg | 29139d4 | 2013-04-18 15:25:39 -0400 | [diff] [blame] | 5981 | struct weston_keyboard *keyboard = switcher->grab.keyboard; |
Kristian Høgsberg | b0d8e77 | 2012-06-18 16:34:58 -0400 | [diff] [blame] | 5982 | struct workspace *ws = get_current_workspace(switcher->shell); |
Kristian Høgsberg | 0704539 | 2012-02-19 18:52:44 -0500 | [diff] [blame] | 5983 | |
Giulio Camuffo | 412e6a5 | 2014-07-09 22:12:56 +0300 | [diff] [blame] | 5984 | 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] | 5985 | if (is_focus_view(view)) |
| 5986 | continue; |
| 5987 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 5988 | view->alpha = 1.0; |
| 5989 | weston_surface_damage(view->surface); |
Kristian Høgsberg | 0704539 | 2012-02-19 18:52:44 -0500 | [diff] [blame] | 5990 | } |
| 5991 | |
Alex Wu | 07b2606 | 2012-03-12 16:06:01 +0800 | [diff] [blame] | 5992 | if (switcher->current) |
Daniel Stone | 37816df | 2012-05-16 18:45:18 +0100 | [diff] [blame] | 5993 | activate(switcher->shell, switcher->current, |
Derek Foreman | 8aeeac8 | 2015-01-30 13:24:36 -0600 | [diff] [blame] | 5994 | keyboard->seat, true); |
Kristian Høgsberg | 0704539 | 2012-02-19 18:52:44 -0500 | [diff] [blame] | 5995 | wl_list_remove(&switcher->listener.link); |
Kristian Høgsberg | 29139d4 | 2013-04-18 15:25:39 -0400 | [diff] [blame] | 5996 | weston_keyboard_end_grab(keyboard); |
| 5997 | if (keyboard->input_method_resource) |
| 5998 | keyboard->grab = &keyboard->input_method_grab; |
Manuel Bachmann | c1ae2e8 | 2014-02-26 15:53:11 +0100 | [diff] [blame] | 5999 | |
| 6000 | /* re-hide surfaces that were temporary shown during the switch */ |
| 6001 | struct weston_view **minimized; |
| 6002 | wl_array_for_each(minimized, &switcher->minimized_array) { |
| 6003 | /* with the exception of the current selected */ |
| 6004 | if ((*minimized)->surface != switcher->current) { |
Giulio Camuffo | 412e6a5 | 2014-07-09 22:12:56 +0300 | [diff] [blame] | 6005 | weston_layer_entry_remove(&(*minimized)->layer_link); |
| 6006 | 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] | 6007 | weston_view_damage_below(*minimized); |
| 6008 | } |
| 6009 | } |
| 6010 | wl_array_release(&switcher->minimized_array); |
| 6011 | |
Kristian Høgsberg | 0704539 | 2012-02-19 18:52:44 -0500 | [diff] [blame] | 6012 | free(switcher); |
| 6013 | } |
| 6014 | |
| 6015 | static void |
Kristian Høgsberg | 29139d4 | 2013-04-18 15:25:39 -0400 | [diff] [blame] | 6016 | switcher_key(struct weston_keyboard_grab *grab, |
Daniel Stone | c9785ea | 2012-05-30 16:31:52 +0100 | [diff] [blame] | 6017 | uint32_t time, uint32_t key, uint32_t state_w) |
Kristian Høgsberg | 0704539 | 2012-02-19 18:52:44 -0500 | [diff] [blame] | 6018 | { |
| 6019 | struct switcher *switcher = container_of(grab, struct switcher, grab); |
Daniel Stone | c9785ea | 2012-05-30 16:31:52 +0100 | [diff] [blame] | 6020 | enum wl_keyboard_key_state state = state_w; |
Daniel Stone | 351eb61 | 2012-05-31 15:27:47 -0400 | [diff] [blame] | 6021 | |
Daniel Stone | c9785ea | 2012-05-30 16:31:52 +0100 | [diff] [blame] | 6022 | if (key == KEY_TAB && state == WL_KEYBOARD_KEY_STATE_PRESSED) |
Daniel Stone | 351eb61 | 2012-05-31 15:27:47 -0400 | [diff] [blame] | 6023 | switcher_next(switcher); |
| 6024 | } |
| 6025 | |
| 6026 | static void |
Kristian Høgsberg | 29139d4 | 2013-04-18 15:25:39 -0400 | [diff] [blame] | 6027 | switcher_modifier(struct weston_keyboard_grab *grab, uint32_t serial, |
Daniel Stone | 351eb61 | 2012-05-31 15:27:47 -0400 | [diff] [blame] | 6028 | uint32_t mods_depressed, uint32_t mods_latched, |
| 6029 | uint32_t mods_locked, uint32_t group) |
| 6030 | { |
| 6031 | struct switcher *switcher = container_of(grab, struct switcher, grab); |
Derek Foreman | 8aeeac8 | 2015-01-30 13:24:36 -0600 | [diff] [blame] | 6032 | struct weston_seat *seat = grab->keyboard->seat; |
Kristian Høgsberg | 0704539 | 2012-02-19 18:52:44 -0500 | [diff] [blame] | 6033 | |
Daniel Stone | 351eb61 | 2012-05-31 15:27:47 -0400 | [diff] [blame] | 6034 | if ((seat->modifier_state & switcher->shell->binding_modifier) == 0) |
| 6035 | switcher_destroy(switcher); |
Kristian Høgsberg | b71302e | 2012-05-10 12:28:35 -0400 | [diff] [blame] | 6036 | } |
Kristian Høgsberg | 0704539 | 2012-02-19 18:52:44 -0500 | [diff] [blame] | 6037 | |
Jonas Ådahl | 1ea343e | 2013-10-25 23:18:05 +0200 | [diff] [blame] | 6038 | static void |
| 6039 | switcher_cancel(struct weston_keyboard_grab *grab) |
| 6040 | { |
| 6041 | struct switcher *switcher = container_of(grab, struct switcher, grab); |
| 6042 | |
| 6043 | switcher_destroy(switcher); |
| 6044 | } |
| 6045 | |
Kristian Høgsberg | 29139d4 | 2013-04-18 15:25:39 -0400 | [diff] [blame] | 6046 | static const struct weston_keyboard_grab_interface switcher_grab = { |
Daniel Stone | 351eb61 | 2012-05-31 15:27:47 -0400 | [diff] [blame] | 6047 | switcher_key, |
| 6048 | switcher_modifier, |
Jonas Ådahl | 1ea343e | 2013-10-25 23:18:05 +0200 | [diff] [blame] | 6049 | switcher_cancel, |
Kristian Høgsberg | 0704539 | 2012-02-19 18:52:44 -0500 | [diff] [blame] | 6050 | }; |
| 6051 | |
| 6052 | static void |
Derek Foreman | 8ae2db5 | 2015-07-15 13:00:36 -0500 | [diff] [blame] | 6053 | switcher_binding(struct weston_keyboard *keyboard, uint32_t time, |
| 6054 | uint32_t key, void *data) |
Kristian Høgsberg | 0704539 | 2012-02-19 18:52:44 -0500 | [diff] [blame] | 6055 | { |
Tiago Vignatti | be14326 | 2012-04-16 17:31:41 +0300 | [diff] [blame] | 6056 | struct desktop_shell *shell = data; |
Kristian Høgsberg | 0704539 | 2012-02-19 18:52:44 -0500 | [diff] [blame] | 6057 | struct switcher *switcher; |
| 6058 | |
| 6059 | switcher = malloc(sizeof *switcher); |
Kristian Høgsberg | 02e79dc | 2012-04-12 09:55:26 -0400 | [diff] [blame] | 6060 | switcher->shell = shell; |
Kristian Høgsberg | 0704539 | 2012-02-19 18:52:44 -0500 | [diff] [blame] | 6061 | switcher->current = NULL; |
Kristian Høgsberg | 27e3052 | 2012-04-11 23:18:23 -0400 | [diff] [blame] | 6062 | switcher->listener.notify = switcher_handle_surface_destroy; |
Kristian Høgsberg | 0704539 | 2012-02-19 18:52:44 -0500 | [diff] [blame] | 6063 | wl_list_init(&switcher->listener.link); |
Manuel Bachmann | c1ae2e8 | 2014-02-26 15:53:11 +0100 | [diff] [blame] | 6064 | wl_array_init(&switcher->minimized_array); |
Kristian Høgsberg | 0704539 | 2012-02-19 18:52:44 -0500 | [diff] [blame] | 6065 | |
Alexander Larsson | f82b6ca | 2013-05-28 16:23:39 +0200 | [diff] [blame] | 6066 | restore_all_output_modes(shell->compositor); |
Mario Kleiner | 9f4d655 | 2015-06-21 21:25:08 +0200 | [diff] [blame] | 6067 | lower_fullscreen_layer(switcher->shell, NULL); |
Kristian Høgsberg | 0704539 | 2012-02-19 18:52:44 -0500 | [diff] [blame] | 6068 | switcher->grab.interface = &switcher_grab; |
Derek Foreman | 8ae2db5 | 2015-07-15 13:00:36 -0500 | [diff] [blame] | 6069 | weston_keyboard_start_grab(keyboard, &switcher->grab); |
| 6070 | weston_keyboard_set_focus(keyboard, NULL); |
Kristian Høgsberg | 0704539 | 2012-02-19 18:52:44 -0500 | [diff] [blame] | 6071 | switcher_next(switcher); |
| 6072 | } |
| 6073 | |
Pekka Paalanen | 3c64723 | 2011-12-22 13:43:43 +0200 | [diff] [blame] | 6074 | static void |
Derek Foreman | 8ae2db5 | 2015-07-15 13:00:36 -0500 | [diff] [blame] | 6075 | backlight_binding(struct weston_keyboard *keyboard, uint32_t time, |
| 6076 | uint32_t key, void *data) |
Tiago Vignatti | 8e53c7f | 2012-02-29 19:53:50 +0200 | [diff] [blame] | 6077 | { |
| 6078 | struct weston_compositor *compositor = data; |
| 6079 | struct weston_output *output; |
Tiago Vignatti | 5ab91ad | 2012-03-12 19:40:09 -0300 | [diff] [blame] | 6080 | long backlight_new = 0; |
Tiago Vignatti | 8e53c7f | 2012-02-29 19:53:50 +0200 | [diff] [blame] | 6081 | |
| 6082 | /* TODO: we're limiting to simple use cases, where we assume just |
| 6083 | * control on the primary display. We'd have to extend later if we |
| 6084 | * ever get support for setting backlights on random desktop LCD |
| 6085 | * panels though */ |
| 6086 | output = get_default_output(compositor); |
| 6087 | if (!output) |
| 6088 | return; |
| 6089 | |
| 6090 | if (!output->set_backlight) |
| 6091 | return; |
| 6092 | |
Tiago Vignatti | 5ab91ad | 2012-03-12 19:40:09 -0300 | [diff] [blame] | 6093 | if (key == KEY_F9 || key == KEY_BRIGHTNESSDOWN) |
| 6094 | backlight_new = output->backlight_current - 25; |
| 6095 | else if (key == KEY_F10 || key == KEY_BRIGHTNESSUP) |
| 6096 | backlight_new = output->backlight_current + 25; |
Tiago Vignatti | 8e53c7f | 2012-02-29 19:53:50 +0200 | [diff] [blame] | 6097 | |
Tiago Vignatti | 5ab91ad | 2012-03-12 19:40:09 -0300 | [diff] [blame] | 6098 | if (backlight_new < 5) |
| 6099 | backlight_new = 5; |
| 6100 | if (backlight_new > 255) |
| 6101 | backlight_new = 255; |
| 6102 | |
| 6103 | output->backlight_current = backlight_new; |
Tiago Vignatti | 8e53c7f | 2012-02-29 19:53:50 +0200 | [diff] [blame] | 6104 | output->set_backlight(output, output->backlight_current); |
| 6105 | } |
| 6106 | |
Kristian Høgsberg | b41c081 | 2012-03-04 14:53:40 -0500 | [diff] [blame] | 6107 | static void |
Derek Foreman | 8ae2db5 | 2015-07-15 13:00:36 -0500 | [diff] [blame] | 6108 | force_kill_binding(struct weston_keyboard *keyboard, uint32_t time, |
| 6109 | uint32_t key, void *data) |
Kristian Høgsberg | 92a57db | 2012-05-26 13:41:06 -0400 | [diff] [blame] | 6110 | { |
Kristian Høgsberg | fe7aa90 | 2013-05-08 09:54:37 -0400 | [diff] [blame] | 6111 | struct weston_surface *focus_surface; |
Kristian Høgsberg | 92a57db | 2012-05-26 13:41:06 -0400 | [diff] [blame] | 6112 | struct wl_client *client; |
Tiago Vignatti | 1d01b01 | 2012-09-27 17:48:36 +0300 | [diff] [blame] | 6113 | struct desktop_shell *shell = data; |
| 6114 | struct weston_compositor *compositor = shell->compositor; |
Kristian Høgsberg | 92a57db | 2012-05-26 13:41:06 -0400 | [diff] [blame] | 6115 | pid_t pid; |
Kristian Høgsberg | 92a57db | 2012-05-26 13:41:06 -0400 | [diff] [blame] | 6116 | |
Derek Foreman | 8ae2db5 | 2015-07-15 13:00:36 -0500 | [diff] [blame] | 6117 | focus_surface = keyboard->focus; |
Philipp Brüschweiler | 6cef009 | 2012-08-13 21:27:27 +0200 | [diff] [blame] | 6118 | if (!focus_surface) |
| 6119 | return; |
| 6120 | |
Tiago Vignatti | 1d01b01 | 2012-09-27 17:48:36 +0300 | [diff] [blame] | 6121 | wl_signal_emit(&compositor->kill_signal, focus_surface); |
| 6122 | |
Jason Ekstrand | 26ed73c | 2013-06-06 22:34:41 -0500 | [diff] [blame] | 6123 | client = wl_resource_get_client(focus_surface->resource); |
Tiago Vignatti | 920f197 | 2012-09-27 17:48:35 +0300 | [diff] [blame] | 6124 | wl_client_get_credentials(client, &pid, NULL, NULL); |
| 6125 | |
| 6126 | /* Skip clients that we launched ourselves (the credentials of |
| 6127 | * the socketpair is ours) */ |
| 6128 | if (pid == getpid()) |
| 6129 | return; |
Kristian Høgsberg | 92a57db | 2012-05-26 13:41:06 -0400 | [diff] [blame] | 6130 | |
Daniel Stone | 325fc2d | 2012-05-30 16:31:58 +0100 | [diff] [blame] | 6131 | kill(pid, SIGKILL); |
Kristian Høgsberg | 92a57db | 2012-05-26 13:41:06 -0400 | [diff] [blame] | 6132 | } |
| 6133 | |
| 6134 | static void |
Derek Foreman | 8ae2db5 | 2015-07-15 13:00:36 -0500 | [diff] [blame] | 6135 | workspace_up_binding(struct weston_keyboard *keyboard, uint32_t time, |
Jonas Ådahl | e3cddce | 2012-06-13 00:01:22 +0200 | [diff] [blame] | 6136 | uint32_t key, void *data) |
| 6137 | { |
| 6138 | struct desktop_shell *shell = data; |
| 6139 | unsigned int new_index = shell->workspaces.current; |
| 6140 | |
Kristian Høgsberg | ce345b0 | 2012-06-25 21:35:29 -0400 | [diff] [blame] | 6141 | if (shell->locked) |
Kristian Høgsberg | 4476aaf | 2012-06-25 14:03:13 -0400 | [diff] [blame] | 6142 | return; |
Jonas Ådahl | e3cddce | 2012-06-13 00:01:22 +0200 | [diff] [blame] | 6143 | if (new_index != 0) |
| 6144 | new_index--; |
| 6145 | |
| 6146 | change_workspace(shell, new_index); |
| 6147 | } |
| 6148 | |
| 6149 | static void |
Derek Foreman | 8ae2db5 | 2015-07-15 13:00:36 -0500 | [diff] [blame] | 6150 | workspace_down_binding(struct weston_keyboard *keyboard, uint32_t time, |
Jonas Ådahl | e3cddce | 2012-06-13 00:01:22 +0200 | [diff] [blame] | 6151 | uint32_t key, void *data) |
| 6152 | { |
| 6153 | struct desktop_shell *shell = data; |
| 6154 | unsigned int new_index = shell->workspaces.current; |
| 6155 | |
Kristian Høgsberg | ce345b0 | 2012-06-25 21:35:29 -0400 | [diff] [blame] | 6156 | if (shell->locked) |
Kristian Høgsberg | 4476aaf | 2012-06-25 14:03:13 -0400 | [diff] [blame] | 6157 | return; |
Jonas Ådahl | e3cddce | 2012-06-13 00:01:22 +0200 | [diff] [blame] | 6158 | if (new_index < shell->workspaces.num - 1) |
| 6159 | new_index++; |
| 6160 | |
| 6161 | change_workspace(shell, new_index); |
| 6162 | } |
| 6163 | |
| 6164 | static void |
Derek Foreman | 8ae2db5 | 2015-07-15 13:00:36 -0500 | [diff] [blame] | 6165 | workspace_f_binding(struct weston_keyboard *keyboard, uint32_t time, |
Jonas Ådahl | e3cddce | 2012-06-13 00:01:22 +0200 | [diff] [blame] | 6166 | uint32_t key, void *data) |
| 6167 | { |
| 6168 | struct desktop_shell *shell = data; |
| 6169 | unsigned int new_index; |
| 6170 | |
Kristian Høgsberg | ce345b0 | 2012-06-25 21:35:29 -0400 | [diff] [blame] | 6171 | if (shell->locked) |
Kristian Høgsberg | 4476aaf | 2012-06-25 14:03:13 -0400 | [diff] [blame] | 6172 | return; |
Jonas Ådahl | e3cddce | 2012-06-13 00:01:22 +0200 | [diff] [blame] | 6173 | new_index = key - KEY_F1; |
| 6174 | if (new_index >= shell->workspaces.num) |
| 6175 | new_index = shell->workspaces.num - 1; |
| 6176 | |
| 6177 | change_workspace(shell, new_index); |
| 6178 | } |
| 6179 | |
Jonas Ådahl | 8de6a1d | 2012-08-29 22:13:00 +0200 | [diff] [blame] | 6180 | static void |
Derek Foreman | 8ae2db5 | 2015-07-15 13:00:36 -0500 | [diff] [blame] | 6181 | workspace_move_surface_up_binding(struct weston_keyboard *keyboard, |
| 6182 | uint32_t time, uint32_t key, void *data) |
Jonas Ådahl | 8de6a1d | 2012-08-29 22:13:00 +0200 | [diff] [blame] | 6183 | { |
| 6184 | struct desktop_shell *shell = data; |
| 6185 | unsigned int new_index = shell->workspaces.current; |
| 6186 | |
| 6187 | if (shell->locked) |
| 6188 | return; |
| 6189 | |
| 6190 | if (new_index != 0) |
| 6191 | new_index--; |
| 6192 | |
Derek Foreman | 8ae2db5 | 2015-07-15 13:00:36 -0500 | [diff] [blame] | 6193 | take_surface_to_workspace_by_seat(shell, keyboard->seat, new_index); |
Jonas Ådahl | 8de6a1d | 2012-08-29 22:13:00 +0200 | [diff] [blame] | 6194 | } |
| 6195 | |
| 6196 | static void |
Derek Foreman | 8ae2db5 | 2015-07-15 13:00:36 -0500 | [diff] [blame] | 6197 | workspace_move_surface_down_binding(struct weston_keyboard *keyboard, |
| 6198 | uint32_t time, uint32_t key, void *data) |
Jonas Ådahl | 8de6a1d | 2012-08-29 22:13:00 +0200 | [diff] [blame] | 6199 | { |
| 6200 | struct desktop_shell *shell = data; |
| 6201 | unsigned int new_index = shell->workspaces.current; |
| 6202 | |
| 6203 | if (shell->locked) |
| 6204 | return; |
| 6205 | |
| 6206 | if (new_index < shell->workspaces.num - 1) |
| 6207 | new_index++; |
| 6208 | |
Derek Foreman | 8ae2db5 | 2015-07-15 13:00:36 -0500 | [diff] [blame] | 6209 | take_surface_to_workspace_by_seat(shell, keyboard->seat, new_index); |
Jonas Ådahl | 8de6a1d | 2012-08-29 22:13:00 +0200 | [diff] [blame] | 6210 | } |
Jonas Ådahl | e3cddce | 2012-06-13 00:01:22 +0200 | [diff] [blame] | 6211 | |
| 6212 | static void |
Ander Conselvan de Oliveira | c94d622 | 2014-01-29 18:47:54 +0200 | [diff] [blame] | 6213 | shell_reposition_view_on_output_destroy(struct weston_view *view) |
| 6214 | { |
| 6215 | struct weston_output *output, *first_output; |
| 6216 | struct weston_compositor *ec = view->surface->compositor; |
| 6217 | struct shell_surface *shsurf; |
| 6218 | float x, y; |
| 6219 | int visible; |
| 6220 | |
| 6221 | x = view->geometry.x; |
| 6222 | y = view->geometry.y; |
| 6223 | |
| 6224 | /* At this point the destroyed output is not in the list anymore. |
| 6225 | * If the view is still visible somewhere, we leave where it is, |
| 6226 | * otherwise, move it to the first output. */ |
| 6227 | visible = 0; |
| 6228 | wl_list_for_each(output, &ec->output_list, link) { |
| 6229 | if (pixman_region32_contains_point(&output->region, |
| 6230 | x, y, NULL)) { |
| 6231 | visible = 1; |
| 6232 | break; |
| 6233 | } |
| 6234 | } |
| 6235 | |
| 6236 | if (!visible) { |
| 6237 | first_output = container_of(ec->output_list.next, |
| 6238 | struct weston_output, link); |
| 6239 | |
| 6240 | x = first_output->x + first_output->width / 4; |
| 6241 | y = first_output->y + first_output->height / 4; |
Xiong Zhang | 62899f5 | 2014-03-07 16:27:19 +0800 | [diff] [blame] | 6242 | |
| 6243 | weston_view_set_position(view, x, y); |
| 6244 | } else { |
| 6245 | weston_view_geometry_dirty(view); |
Ander Conselvan de Oliveira | c94d622 | 2014-01-29 18:47:54 +0200 | [diff] [blame] | 6246 | } |
| 6247 | |
Ander Conselvan de Oliveira | c94d622 | 2014-01-29 18:47:54 +0200 | [diff] [blame] | 6248 | |
| 6249 | shsurf = get_shell_surface(view->surface); |
| 6250 | |
| 6251 | if (shsurf) { |
| 6252 | shsurf->saved_position_valid = false; |
| 6253 | shsurf->next_state.maximized = false; |
| 6254 | shsurf->next_state.fullscreen = false; |
| 6255 | shsurf->state_changed = true; |
| 6256 | } |
| 6257 | } |
| 6258 | |
Ander Conselvan de Oliveira | 304996d | 2014-04-11 13:57:15 +0300 | [diff] [blame] | 6259 | void |
| 6260 | shell_for_each_layer(struct desktop_shell *shell, |
| 6261 | shell_for_each_layer_func_t func, void *data) |
Ander Conselvan de Oliveira | c94d622 | 2014-01-29 18:47:54 +0200 | [diff] [blame] | 6262 | { |
Ander Conselvan de Oliveira | 304996d | 2014-04-11 13:57:15 +0300 | [diff] [blame] | 6263 | struct workspace **ws; |
| 6264 | |
| 6265 | func(shell, &shell->fullscreen_layer, data); |
| 6266 | func(shell, &shell->panel_layer, data); |
| 6267 | func(shell, &shell->background_layer, data); |
| 6268 | func(shell, &shell->lock_layer, data); |
| 6269 | func(shell, &shell->input_panel_layer, data); |
| 6270 | |
| 6271 | wl_array_for_each(ws, &shell->workspaces.array) |
| 6272 | func(shell, &(*ws)->layer, data); |
| 6273 | } |
| 6274 | |
| 6275 | static void |
| 6276 | shell_output_destroy_move_layer(struct desktop_shell *shell, |
| 6277 | struct weston_layer *layer, |
| 6278 | void *data) |
| 6279 | { |
| 6280 | struct weston_output *output = data; |
Ander Conselvan de Oliveira | c94d622 | 2014-01-29 18:47:54 +0200 | [diff] [blame] | 6281 | struct weston_view *view; |
| 6282 | |
Giulio Camuffo | 412e6a5 | 2014-07-09 22:12:56 +0300 | [diff] [blame] | 6283 | 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] | 6284 | if (view->output != output) |
| 6285 | continue; |
Ander Conselvan de Oliveira | c94d622 | 2014-01-29 18:47:54 +0200 | [diff] [blame] | 6286 | |
Ander Conselvan de Oliveira | 304996d | 2014-04-11 13:57:15 +0300 | [diff] [blame] | 6287 | shell_reposition_view_on_output_destroy(view); |
Ander Conselvan de Oliveira | c94d622 | 2014-01-29 18:47:54 +0200 | [diff] [blame] | 6288 | } |
| 6289 | } |
| 6290 | |
| 6291 | static void |
Xiong Zhang | 6b48142 | 2013-10-23 13:58:32 +0800 | [diff] [blame] | 6292 | handle_output_destroy(struct wl_listener *listener, void *data) |
| 6293 | { |
| 6294 | struct shell_output *output_listener = |
| 6295 | container_of(listener, struct shell_output, destroy_listener); |
Ander Conselvan de Oliveira | 304996d | 2014-04-11 13:57:15 +0300 | [diff] [blame] | 6296 | struct weston_output *output = output_listener->output; |
| 6297 | struct desktop_shell *shell = output_listener->shell; |
Xiong Zhang | 6b48142 | 2013-10-23 13:58:32 +0800 | [diff] [blame] | 6298 | |
Ander Conselvan de Oliveira | 304996d | 2014-04-11 13:57:15 +0300 | [diff] [blame] | 6299 | 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] | 6300 | |
Xiong Zhang | 6b48142 | 2013-10-23 13:58:32 +0800 | [diff] [blame] | 6301 | wl_list_remove(&output_listener->destroy_listener.link); |
| 6302 | wl_list_remove(&output_listener->link); |
| 6303 | free(output_listener); |
| 6304 | } |
| 6305 | |
| 6306 | static void |
| 6307 | create_shell_output(struct desktop_shell *shell, |
| 6308 | struct weston_output *output) |
| 6309 | { |
| 6310 | struct shell_output *shell_output; |
| 6311 | |
| 6312 | shell_output = zalloc(sizeof *shell_output); |
| 6313 | if (shell_output == NULL) |
| 6314 | return; |
| 6315 | |
| 6316 | shell_output->output = output; |
| 6317 | shell_output->shell = shell; |
| 6318 | shell_output->destroy_listener.notify = handle_output_destroy; |
| 6319 | wl_signal_add(&output->destroy_signal, |
| 6320 | &shell_output->destroy_listener); |
Kristian Høgsberg | a3a0e18 | 2013-10-23 23:36:04 -0700 | [diff] [blame] | 6321 | wl_list_insert(shell->output_list.prev, &shell_output->link); |
Xiong Zhang | 6b48142 | 2013-10-23 13:58:32 +0800 | [diff] [blame] | 6322 | } |
| 6323 | |
| 6324 | static void |
| 6325 | handle_output_create(struct wl_listener *listener, void *data) |
| 6326 | { |
| 6327 | struct desktop_shell *shell = |
| 6328 | container_of(listener, struct desktop_shell, output_create_listener); |
| 6329 | struct weston_output *output = (struct weston_output *)data; |
| 6330 | |
| 6331 | create_shell_output(shell, output); |
| 6332 | } |
| 6333 | |
| 6334 | static void |
Ander Conselvan de Oliveira | 304996d | 2014-04-11 13:57:15 +0300 | [diff] [blame] | 6335 | handle_output_move_layer(struct desktop_shell *shell, |
| 6336 | struct weston_layer *layer, void *data) |
Ander Conselvan de Oliveira | a8a9baf | 2014-01-29 18:47:52 +0200 | [diff] [blame] | 6337 | { |
Ander Conselvan de Oliveira | 304996d | 2014-04-11 13:57:15 +0300 | [diff] [blame] | 6338 | struct weston_output *output = data; |
Ander Conselvan de Oliveira | a8a9baf | 2014-01-29 18:47:52 +0200 | [diff] [blame] | 6339 | struct weston_view *view; |
| 6340 | float x, y; |
| 6341 | |
Giulio Camuffo | 412e6a5 | 2014-07-09 22:12:56 +0300 | [diff] [blame] | 6342 | 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] | 6343 | if (view->output != output) |
| 6344 | continue; |
| 6345 | |
| 6346 | x = view->geometry.x + output->move_x; |
| 6347 | y = view->geometry.y + output->move_y; |
| 6348 | weston_view_set_position(view, x, y); |
| 6349 | } |
| 6350 | } |
| 6351 | |
| 6352 | static void |
| 6353 | handle_output_move(struct wl_listener *listener, void *data) |
| 6354 | { |
| 6355 | struct desktop_shell *shell; |
| 6356 | |
Ander Conselvan de Oliveira | a8a9baf | 2014-01-29 18:47:52 +0200 | [diff] [blame] | 6357 | shell = container_of(listener, struct desktop_shell, |
| 6358 | output_move_listener); |
Ander Conselvan de Oliveira | a8a9baf | 2014-01-29 18:47:52 +0200 | [diff] [blame] | 6359 | |
Ander Conselvan de Oliveira | 304996d | 2014-04-11 13:57:15 +0300 | [diff] [blame] | 6360 | shell_for_each_layer(shell, handle_output_move_layer, data); |
Ander Conselvan de Oliveira | a8a9baf | 2014-01-29 18:47:52 +0200 | [diff] [blame] | 6361 | } |
| 6362 | |
| 6363 | static void |
Xiong Zhang | 6b48142 | 2013-10-23 13:58:32 +0800 | [diff] [blame] | 6364 | setup_output_destroy_handler(struct weston_compositor *ec, |
| 6365 | struct desktop_shell *shell) |
| 6366 | { |
| 6367 | struct weston_output *output; |
| 6368 | |
| 6369 | wl_list_init(&shell->output_list); |
| 6370 | wl_list_for_each(output, &ec->output_list, link) |
| 6371 | create_shell_output(shell, output); |
| 6372 | |
| 6373 | shell->output_create_listener.notify = handle_output_create; |
| 6374 | wl_signal_add(&ec->output_created_signal, |
| 6375 | &shell->output_create_listener); |
Ander Conselvan de Oliveira | a8a9baf | 2014-01-29 18:47:52 +0200 | [diff] [blame] | 6376 | |
| 6377 | shell->output_move_listener.notify = handle_output_move; |
| 6378 | wl_signal_add(&ec->output_moved_signal, &shell->output_move_listener); |
Xiong Zhang | 6b48142 | 2013-10-23 13:58:32 +0800 | [diff] [blame] | 6379 | } |
| 6380 | |
| 6381 | static void |
Kristian Høgsberg | 02e79dc | 2012-04-12 09:55:26 -0400 | [diff] [blame] | 6382 | shell_destroy(struct wl_listener *listener, void *data) |
Pekka Paalanen | 3c64723 | 2011-12-22 13:43:43 +0200 | [diff] [blame] | 6383 | { |
Tiago Vignatti | be14326 | 2012-04-16 17:31:41 +0300 | [diff] [blame] | 6384 | struct desktop_shell *shell = |
| 6385 | container_of(listener, struct desktop_shell, destroy_listener); |
Jonas Ådahl | e3cddce | 2012-06-13 00:01:22 +0200 | [diff] [blame] | 6386 | struct workspace **ws; |
Xiong Zhang | 6b48142 | 2013-10-23 13:58:32 +0800 | [diff] [blame] | 6387 | struct shell_output *shell_output, *tmp; |
Pekka Paalanen | 3c64723 | 2011-12-22 13:43:43 +0200 | [diff] [blame] | 6388 | |
Kristian Høgsberg | 17bccae | 2014-01-16 16:46:28 -0800 | [diff] [blame] | 6389 | /* Force state to unlocked so we don't try to fade */ |
| 6390 | shell->locked = false; |
Pekka Paalanen | 826dc14 | 2014-08-27 12:11:53 +0300 | [diff] [blame] | 6391 | |
| 6392 | if (shell->child.client) { |
| 6393 | /* disable respawn */ |
| 6394 | wl_list_remove(&shell->child.client_destroy_listener.link); |
Pekka Paalanen | 9cf5cc8 | 2012-01-02 16:00:24 +0200 | [diff] [blame] | 6395 | wl_client_destroy(shell->child.client); |
Pekka Paalanen | 826dc14 | 2014-08-27 12:11:53 +0300 | [diff] [blame] | 6396 | } |
Pekka Paalanen | 9cf5cc8 | 2012-01-02 16:00:24 +0200 | [diff] [blame] | 6397 | |
Ander Conselvan de Oliveira | a457563 | 2013-02-21 18:35:23 +0200 | [diff] [blame] | 6398 | wl_list_remove(&shell->idle_listener.link); |
| 6399 | wl_list_remove(&shell->wake_listener.link); |
Giulio Camuffo | f05d18f | 2015-12-11 20:57:05 +0200 | [diff] [blame^] | 6400 | wl_list_remove(&shell->transform_listener.link); |
Kristian Høgsberg | 677a5f5 | 2013-12-04 11:00:19 -0800 | [diff] [blame] | 6401 | |
Pekka Paalanen | aa9536a | 2015-06-24 16:09:17 +0300 | [diff] [blame] | 6402 | text_backend_destroy(shell->text_backend); |
Kristian Høgsberg | 677a5f5 | 2013-12-04 11:00:19 -0800 | [diff] [blame] | 6403 | input_panel_destroy(shell); |
Kristian Høgsberg | 88c1607 | 2012-05-16 08:04:19 -0400 | [diff] [blame] | 6404 | |
Xiong Zhang | 6b48142 | 2013-10-23 13:58:32 +0800 | [diff] [blame] | 6405 | wl_list_for_each_safe(shell_output, tmp, &shell->output_list, link) { |
| 6406 | wl_list_remove(&shell_output->destroy_listener.link); |
| 6407 | wl_list_remove(&shell_output->link); |
| 6408 | free(shell_output); |
| 6409 | } |
| 6410 | |
| 6411 | wl_list_remove(&shell->output_create_listener.link); |
Kristian Høgsberg | 6d50b0f | 2014-04-30 20:46:25 -0700 | [diff] [blame] | 6412 | wl_list_remove(&shell->output_move_listener.link); |
Xiong Zhang | 6b48142 | 2013-10-23 13:58:32 +0800 | [diff] [blame] | 6413 | |
Jonas Ådahl | e3cddce | 2012-06-13 00:01:22 +0200 | [diff] [blame] | 6414 | wl_array_for_each(ws, &shell->workspaces.array) |
| 6415 | workspace_destroy(*ws); |
| 6416 | wl_array_release(&shell->workspaces.array); |
| 6417 | |
Emilio Pozuelo Monfort | 46ce798 | 2013-11-20 13:22:29 +0100 | [diff] [blame] | 6418 | free(shell->client); |
Pekka Paalanen | 3c64723 | 2011-12-22 13:43:43 +0200 | [diff] [blame] | 6419 | free(shell); |
| 6420 | } |
| 6421 | |
Tiago Vignatti | 0b52d48 | 2012-04-20 18:54:25 +0300 | [diff] [blame] | 6422 | static void |
| 6423 | shell_add_bindings(struct weston_compositor *ec, struct desktop_shell *shell) |
| 6424 | { |
| 6425 | uint32_t mod; |
Jonas Ådahl | e3cddce | 2012-06-13 00:01:22 +0200 | [diff] [blame] | 6426 | int i, num_workspace_bindings; |
Tiago Vignatti | 0b52d48 | 2012-04-20 18:54:25 +0300 | [diff] [blame] | 6427 | |
| 6428 | /* fixed bindings */ |
Daniel Stone | 325fc2d | 2012-05-30 16:31:58 +0100 | [diff] [blame] | 6429 | weston_compositor_add_key_binding(ec, KEY_BACKSPACE, |
| 6430 | MODIFIER_CTRL | MODIFIER_ALT, |
| 6431 | terminate_binding, ec); |
| 6432 | weston_compositor_add_button_binding(ec, BTN_LEFT, 0, |
| 6433 | click_to_activate_binding, |
| 6434 | shell); |
Kristian Høgsberg | f0ce581 | 2014-04-07 11:52:17 -0700 | [diff] [blame] | 6435 | weston_compositor_add_button_binding(ec, BTN_RIGHT, 0, |
| 6436 | click_to_activate_binding, |
| 6437 | shell); |
Neil Roberts | a28c693 | 2013-10-03 16:43:04 +0100 | [diff] [blame] | 6438 | weston_compositor_add_touch_binding(ec, 0, |
| 6439 | touch_to_activate_binding, |
| 6440 | shell); |
Daniel Stone | 325fc2d | 2012-05-30 16:31:58 +0100 | [diff] [blame] | 6441 | weston_compositor_add_axis_binding(ec, WL_POINTER_AXIS_VERTICAL_SCROLL, |
| 6442 | MODIFIER_SUPER | MODIFIER_ALT, |
| 6443 | surface_opacity_binding, NULL); |
| 6444 | weston_compositor_add_axis_binding(ec, WL_POINTER_AXIS_VERTICAL_SCROLL, |
| 6445 | MODIFIER_SUPER, zoom_axis_binding, |
| 6446 | NULL); |
Tiago Vignatti | 0b52d48 | 2012-04-20 18:54:25 +0300 | [diff] [blame] | 6447 | |
| 6448 | /* configurable bindings */ |
| 6449 | mod = shell->binding_modifier; |
Daniel Stone | 325fc2d | 2012-05-30 16:31:58 +0100 | [diff] [blame] | 6450 | weston_compositor_add_key_binding(ec, KEY_PAGEUP, mod, |
| 6451 | zoom_key_binding, NULL); |
| 6452 | weston_compositor_add_key_binding(ec, KEY_PAGEDOWN, mod, |
| 6453 | zoom_key_binding, NULL); |
Kristian Høgsberg | 211b517 | 2014-01-11 13:10:21 -0800 | [diff] [blame] | 6454 | weston_compositor_add_key_binding(ec, KEY_M, mod | MODIFIER_SHIFT, |
| 6455 | maximize_binding, NULL); |
| 6456 | weston_compositor_add_key_binding(ec, KEY_F, mod | MODIFIER_SHIFT, |
| 6457 | fullscreen_binding, NULL); |
Daniel Stone | 325fc2d | 2012-05-30 16:31:58 +0100 | [diff] [blame] | 6458 | weston_compositor_add_button_binding(ec, BTN_LEFT, mod, move_binding, |
| 6459 | shell); |
Neil Roberts | aba0f25 | 2013-10-03 16:43:05 +0100 | [diff] [blame] | 6460 | weston_compositor_add_touch_binding(ec, mod, touch_move_binding, shell); |
Derek Foreman | 2217f3f | 2015-06-25 16:03:30 -0500 | [diff] [blame] | 6461 | weston_compositor_add_button_binding(ec, BTN_RIGHT, mod, |
Daniel Stone | 325fc2d | 2012-05-30 16:31:58 +0100 | [diff] [blame] | 6462 | resize_binding, shell); |
Kristian Høgsberg | 0837fa9 | 2014-01-20 10:35:26 -0800 | [diff] [blame] | 6463 | weston_compositor_add_button_binding(ec, BTN_LEFT, |
| 6464 | mod | MODIFIER_SHIFT, |
| 6465 | resize_binding, shell); |
Pekka Paalanen | 7bb6510 | 2013-05-22 18:03:04 +0300 | [diff] [blame] | 6466 | |
| 6467 | if (ec->capabilities & WESTON_CAP_ROTATION_ANY) |
Derek Foreman | 2217f3f | 2015-06-25 16:03:30 -0500 | [diff] [blame] | 6468 | weston_compositor_add_button_binding(ec, BTN_MIDDLE, mod, |
Pekka Paalanen | 7bb6510 | 2013-05-22 18:03:04 +0300 | [diff] [blame] | 6469 | rotate_binding, NULL); |
| 6470 | |
Daniel Stone | 325fc2d | 2012-05-30 16:31:58 +0100 | [diff] [blame] | 6471 | weston_compositor_add_key_binding(ec, KEY_TAB, mod, switcher_binding, |
| 6472 | shell); |
| 6473 | weston_compositor_add_key_binding(ec, KEY_F9, mod, backlight_binding, |
| 6474 | ec); |
| 6475 | weston_compositor_add_key_binding(ec, KEY_BRIGHTNESSDOWN, 0, |
| 6476 | backlight_binding, ec); |
| 6477 | weston_compositor_add_key_binding(ec, KEY_F10, mod, backlight_binding, |
| 6478 | ec); |
| 6479 | weston_compositor_add_key_binding(ec, KEY_BRIGHTNESSUP, 0, |
| 6480 | backlight_binding, ec); |
Daniel Stone | 325fc2d | 2012-05-30 16:31:58 +0100 | [diff] [blame] | 6481 | weston_compositor_add_key_binding(ec, KEY_K, mod, |
| 6482 | force_kill_binding, shell); |
Jonas Ådahl | e3cddce | 2012-06-13 00:01:22 +0200 | [diff] [blame] | 6483 | weston_compositor_add_key_binding(ec, KEY_UP, mod, |
| 6484 | workspace_up_binding, shell); |
| 6485 | weston_compositor_add_key_binding(ec, KEY_DOWN, mod, |
| 6486 | workspace_down_binding, shell); |
Jonas Ådahl | 8de6a1d | 2012-08-29 22:13:00 +0200 | [diff] [blame] | 6487 | weston_compositor_add_key_binding(ec, KEY_UP, mod | MODIFIER_SHIFT, |
| 6488 | workspace_move_surface_up_binding, |
| 6489 | shell); |
| 6490 | weston_compositor_add_key_binding(ec, KEY_DOWN, mod | MODIFIER_SHIFT, |
| 6491 | workspace_move_surface_down_binding, |
| 6492 | shell); |
Jonas Ådahl | e3cddce | 2012-06-13 00:01:22 +0200 | [diff] [blame] | 6493 | |
Kristian Høgsberg | d56ab4e | 2014-01-16 16:51:52 -0800 | [diff] [blame] | 6494 | if (shell->exposay_modifier) |
| 6495 | weston_compositor_add_modifier_binding(ec, shell->exposay_modifier, |
| 6496 | exposay_binding, shell); |
Daniel Stone | df8133b | 2013-11-19 11:37:14 +0100 | [diff] [blame] | 6497 | |
Jonas Ådahl | e3cddce | 2012-06-13 00:01:22 +0200 | [diff] [blame] | 6498 | /* Add bindings for mod+F[1-6] for workspace 1 to 6. */ |
| 6499 | if (shell->workspaces.num > 1) { |
| 6500 | num_workspace_bindings = shell->workspaces.num; |
| 6501 | if (num_workspace_bindings > 6) |
| 6502 | num_workspace_bindings = 6; |
| 6503 | for (i = 0; i < num_workspace_bindings; i++) |
| 6504 | weston_compositor_add_key_binding(ec, KEY_F1 + i, mod, |
| 6505 | workspace_f_binding, |
| 6506 | shell); |
| 6507 | } |
Ander Conselvan de Oliveira | c509d2b | 2012-11-08 17:20:45 +0200 | [diff] [blame] | 6508 | |
Pekka Paalanen | 2829f7c | 2015-02-19 17:02:13 +0200 | [diff] [blame] | 6509 | weston_install_debug_key_binding(ec, mod); |
Tiago Vignatti | 0b52d48 | 2012-04-20 18:54:25 +0300 | [diff] [blame] | 6510 | } |
| 6511 | |
Jason Ekstrand | 024177c | 2014-04-21 19:42:58 -0500 | [diff] [blame] | 6512 | static void |
| 6513 | handle_seat_created(struct wl_listener *listener, void *data) |
| 6514 | { |
| 6515 | struct weston_seat *seat = data; |
| 6516 | |
| 6517 | create_shell_seat(seat); |
| 6518 | } |
| 6519 | |
Kristian Høgsberg | 1c56218 | 2011-05-02 22:09:20 -0400 | [diff] [blame] | 6520 | WL_EXPORT int |
Kristian Høgsberg | cb4685b | 2013-02-20 15:37:49 -0500 | [diff] [blame] | 6521 | module_init(struct weston_compositor *ec, |
Ossama Othman | a50e6e4 | 2013-05-14 09:48:26 -0700 | [diff] [blame] | 6522 | int *argc, char *argv[]) |
Kristian Høgsberg | 4cca349 | 2011-01-18 07:53:49 -0500 | [diff] [blame] | 6523 | { |
Kristian Høgsberg | f4d2f23 | 2012-08-10 10:05:39 -0400 | [diff] [blame] | 6524 | struct weston_seat *seat; |
Tiago Vignatti | be14326 | 2012-04-16 17:31:41 +0300 | [diff] [blame] | 6525 | struct desktop_shell *shell; |
Jonas Ådahl | e3cddce | 2012-06-13 00:01:22 +0200 | [diff] [blame] | 6526 | struct workspace **pws; |
| 6527 | unsigned int i; |
Tiago Vignatti | b7dbbd6 | 2012-09-25 17:57:01 +0300 | [diff] [blame] | 6528 | struct wl_event_loop *loop; |
Kristian Høgsberg | 02ec0a5 | 2011-04-23 13:04:11 -0400 | [diff] [blame] | 6529 | |
Peter Hutterer | f3d6227 | 2013-08-08 11:57:05 +1000 | [diff] [blame] | 6530 | shell = zalloc(sizeof *shell); |
Kristian Høgsberg | 02ec0a5 | 2011-04-23 13:04:11 -0400 | [diff] [blame] | 6531 | if (shell == NULL) |
| 6532 | return -1; |
| 6533 | |
Kristian Høgsberg | 7584062 | 2011-09-06 13:48:16 -0400 | [diff] [blame] | 6534 | shell->compositor = ec; |
Kristian Høgsberg | 02e79dc | 2012-04-12 09:55:26 -0400 | [diff] [blame] | 6535 | |
| 6536 | shell->destroy_listener.notify = shell_destroy; |
| 6537 | wl_signal_add(&ec->destroy_signal, &shell->destroy_listener); |
Ander Conselvan de Oliveira | a457563 | 2013-02-21 18:35:23 +0200 | [diff] [blame] | 6538 | shell->idle_listener.notify = idle_handler; |
| 6539 | wl_signal_add(&ec->idle_signal, &shell->idle_listener); |
| 6540 | shell->wake_listener.notify = wake_handler; |
| 6541 | wl_signal_add(&ec->wake_signal, &shell->wake_listener); |
Giulio Camuffo | f05d18f | 2015-12-11 20:57:05 +0200 | [diff] [blame^] | 6542 | shell->transform_listener.notify = transform_handler; |
| 6543 | wl_signal_add(&ec->transform_signal, &shell->transform_listener); |
Kristian Høgsberg | 677a5f5 | 2013-12-04 11:00:19 -0800 | [diff] [blame] | 6544 | |
Kristian Høgsberg | 82a1d11 | 2012-07-19 14:02:00 -0400 | [diff] [blame] | 6545 | ec->shell_interface.shell = shell; |
Tiago Vignatti | bc052c9 | 2012-04-19 16:18:18 +0300 | [diff] [blame] | 6546 | ec->shell_interface.create_shell_surface = create_shell_surface; |
| 6547 | ec->shell_interface.set_toplevel = set_toplevel; |
Tiago Vignatti | 491bac1 | 2012-05-18 16:37:43 -0400 | [diff] [blame] | 6548 | ec->shell_interface.set_transient = set_transient; |
Kristian Høgsberg | 4779241 | 2014-05-04 13:47:06 -0700 | [diff] [blame] | 6549 | ec->shell_interface.set_fullscreen = shell_interface_set_fullscreen; |
Tiago Vignatti | fb2adba | 2013-06-12 15:43:21 -0300 | [diff] [blame] | 6550 | ec->shell_interface.set_xwayland = set_xwayland; |
Kristian Høgsberg | ae356ae | 2014-04-29 16:03:54 -0700 | [diff] [blame] | 6551 | ec->shell_interface.move = shell_interface_move; |
Derek Foreman | 8fbebbd | 2015-07-15 13:00:40 -0500 | [diff] [blame] | 6552 | ec->shell_interface.resize = shell_interface_resize; |
Giulio Camuffo | 62942ad | 2013-09-11 18:20:47 +0200 | [diff] [blame] | 6553 | ec->shell_interface.set_title = set_title; |
Jasper St. Pierre | ccf48fb | 2014-05-02 10:21:38 -0400 | [diff] [blame] | 6554 | ec->shell_interface.set_window_geometry = set_window_geometry; |
Giulio Camuffo | 6b4b241 | 2015-01-29 19:06:49 +0200 | [diff] [blame] | 6555 | ec->shell_interface.set_maximized = shell_interface_set_maximized; |
Giulio Camuffo | a8e9b41 | 2015-01-27 19:10:37 +0200 | [diff] [blame] | 6556 | ec->shell_interface.set_pid = set_pid; |
Kristian Høgsberg | 4cca349 | 2011-01-18 07:53:49 -0500 | [diff] [blame] | 6557 | |
Kristian Høgsberg | 3be2ce9 | 2012-02-29 12:42:35 -0500 | [diff] [blame] | 6558 | weston_layer_init(&shell->fullscreen_layer, &ec->cursor_layer.link); |
| 6559 | weston_layer_init(&shell->panel_layer, &shell->fullscreen_layer.link); |
Jonas Ådahl | e3cddce | 2012-06-13 00:01:22 +0200 | [diff] [blame] | 6560 | weston_layer_init(&shell->background_layer, &shell->panel_layer.link); |
| 6561 | weston_layer_init(&shell->lock_layer, NULL); |
Philipp Brüschweiler | 711fda8 | 2012-08-09 18:50:43 +0200 | [diff] [blame] | 6562 | weston_layer_init(&shell->input_panel_layer, NULL); |
Jonas Ådahl | e3cddce | 2012-06-13 00:01:22 +0200 | [diff] [blame] | 6563 | |
| 6564 | wl_array_init(&shell->workspaces.array); |
Jonas Ådahl | e9d2250 | 2012-08-29 22:13:01 +0200 | [diff] [blame] | 6565 | wl_list_init(&shell->workspaces.client_list); |
Kristian Høgsberg | 3be2ce9 | 2012-02-29 12:42:35 -0500 | [diff] [blame] | 6566 | |
Kristian Høgsberg | 677a5f5 | 2013-12-04 11:00:19 -0800 | [diff] [blame] | 6567 | if (input_panel_setup(shell) < 0) |
| 6568 | return -1; |
| 6569 | |
Pekka Paalanen | aa9536a | 2015-06-24 16:09:17 +0300 | [diff] [blame] | 6570 | shell->text_backend = text_backend_init(ec); |
| 6571 | if (!shell->text_backend) |
Murray Calavera | 9a51cd7 | 2015-06-10 21:16:02 +0000 | [diff] [blame] | 6572 | return -1; |
| 6573 | |
Kristian Høgsberg | 14e438c | 2013-05-26 21:48:14 -0400 | [diff] [blame] | 6574 | shell_configuration(shell); |
Pekka Paalanen | e955f1e | 2011-12-07 11:49:52 +0200 | [diff] [blame] | 6575 | |
Daniel Stone | df8133b | 2013-11-19 11:37:14 +0100 | [diff] [blame] | 6576 | shell->exposay.state_cur = EXPOSAY_LAYOUT_INACTIVE; |
| 6577 | shell->exposay.state_target = EXPOSAY_TARGET_CANCEL; |
| 6578 | |
Jonas Ådahl | e3cddce | 2012-06-13 00:01:22 +0200 | [diff] [blame] | 6579 | for (i = 0; i < shell->workspaces.num; i++) { |
| 6580 | pws = wl_array_add(&shell->workspaces.array, sizeof *pws); |
| 6581 | if (pws == NULL) |
| 6582 | return -1; |
| 6583 | |
| 6584 | *pws = workspace_create(); |
| 6585 | if (*pws == NULL) |
| 6586 | return -1; |
| 6587 | } |
| 6588 | activate_workspace(shell, 0); |
| 6589 | |
Manuel Bachmann | 50c87db | 2014-02-26 15:52:13 +0100 | [diff] [blame] | 6590 | weston_layer_init(&shell->minimized_layer, NULL); |
| 6591 | |
Jonas Ådahl | 8de6a1d | 2012-08-29 22:13:00 +0200 | [diff] [blame] | 6592 | wl_list_init(&shell->workspaces.anim_sticky_list); |
Jonas Ådahl | 62fcd04 | 2012-06-13 00:01:23 +0200 | [diff] [blame] | 6593 | wl_list_init(&shell->workspaces.animation.link); |
| 6594 | shell->workspaces.animation.frame = animate_workspace_change_frame; |
| 6595 | |
Kristian Høgsberg | 919cddb | 2013-07-08 19:03:57 -0400 | [diff] [blame] | 6596 | if (wl_global_create(ec->wl_display, &wl_shell_interface, 1, |
Kristian Høgsberg | 97d44aa | 2011-08-26 17:21:20 -0400 | [diff] [blame] | 6597 | shell, bind_shell) == NULL) |
Kristian Høgsberg | 4cca349 | 2011-01-18 07:53:49 -0500 | [diff] [blame] | 6598 | return -1; |
| 6599 | |
Rafael Antognolli | e2a3455 | 2013-12-03 15:35:45 -0200 | [diff] [blame] | 6600 | if (wl_global_create(ec->wl_display, &xdg_shell_interface, 1, |
| 6601 | shell, bind_xdg_shell) == NULL) |
| 6602 | return -1; |
| 6603 | |
Kristian Høgsberg | 919cddb | 2013-07-08 19:03:57 -0400 | [diff] [blame] | 6604 | if (wl_global_create(ec->wl_display, |
Jonas Ådahl | 6d6fb61 | 2015-11-17 16:00:33 +0800 | [diff] [blame] | 6605 | &weston_desktop_shell_interface, 1, |
Kristian Høgsberg | 919cddb | 2013-07-08 19:03:57 -0400 | [diff] [blame] | 6606 | shell, bind_desktop_shell) == NULL) |
Kristian Høgsberg | 7584062 | 2011-09-06 13:48:16 -0400 | [diff] [blame] | 6607 | return -1; |
| 6608 | |
Kristian Høgsberg | f03a616 | 2012-01-17 11:07:42 -0500 | [diff] [blame] | 6609 | shell->child.deathstamp = weston_compositor_get_time(); |
Tiago Vignatti | b7dbbd6 | 2012-09-25 17:57:01 +0300 | [diff] [blame] | 6610 | |
Jonas Ådahl | 6d6fb61 | 2015-11-17 16:00:33 +0800 | [diff] [blame] | 6611 | shell->panel_position = WESTON_DESKTOP_SHELL_PANEL_POSITION_TOP; |
Jonny Lamb | 765760d | 2014-08-20 15:53:19 +0200 | [diff] [blame] | 6612 | |
Xiong Zhang | 6b48142 | 2013-10-23 13:58:32 +0800 | [diff] [blame] | 6613 | setup_output_destroy_handler(ec, shell); |
| 6614 | |
Tiago Vignatti | b7dbbd6 | 2012-09-25 17:57:01 +0300 | [diff] [blame] | 6615 | loop = wl_display_get_event_loop(ec->wl_display); |
| 6616 | wl_event_loop_add_idle(loop, launch_desktop_shell_process, shell); |
Pekka Paalanen | 6cd281a | 2011-11-03 14:11:32 +0200 | [diff] [blame] | 6617 | |
Jason Ekstrand | 024177c | 2014-04-21 19:42:58 -0500 | [diff] [blame] | 6618 | wl_list_for_each(seat, &ec->seat_list, link) |
| 6619 | handle_seat_created(NULL, seat); |
| 6620 | shell->seat_create_listener.notify = handle_seat_created; |
| 6621 | wl_signal_add(&ec->seat_created_signal, &shell->seat_create_listener); |
Kristian Høgsberg | d56bd90 | 2012-06-05 09:58:51 -0400 | [diff] [blame] | 6622 | |
Giulio Camuffo | c6ab3d5 | 2013-12-11 23:45:12 +0100 | [diff] [blame] | 6623 | screenshooter_create(ec); |
| 6624 | |
Tiago Vignatti | 0b52d48 | 2012-04-20 18:54:25 +0300 | [diff] [blame] | 6625 | shell_add_bindings(ec, shell); |
Kristian Høgsberg | 0793756 | 2011-04-12 17:25:42 -0400 | [diff] [blame] | 6626 | |
Pekka Paalanen | 79346ab | 2013-05-22 18:03:09 +0300 | [diff] [blame] | 6627 | shell_fade_init(shell); |
Ander Conselvan de Oliveira | 19d10ef | 2013-02-21 18:35:20 +0200 | [diff] [blame] | 6628 | |
Pekka Paalanen | 2e62e4a | 2014-08-28 11:41:26 +0300 | [diff] [blame] | 6629 | clock_gettime(CLOCK_MONOTONIC, &shell->startup_time); |
| 6630 | |
Kristian Høgsberg | 4cca349 | 2011-01-18 07:53:49 -0500 | [diff] [blame] | 6631 | return 0; |
| 6632 | } |