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 | * |
| 6 | * Permission to use, copy, modify, distribute, and sell this software and |
| 7 | * its documentation for any purpose is hereby granted without fee, provided |
| 8 | * that the above copyright notice appear in all copies and that both that |
| 9 | * copyright notice and this permission notice appear in supporting |
| 10 | * documentation, and that the name of the copyright holders not be used in |
| 11 | * advertising or publicity pertaining to distribution of the software |
| 12 | * without specific, written prior permission. The copyright holders make |
| 13 | * no representations about the suitability of this software for any |
| 14 | * purpose. It is provided "as is" without express or implied warranty. |
| 15 | * |
| 16 | * THE COPYRIGHT HOLDERS DISCLAIM ALL WARRANTIES WITH REGARD TO THIS |
| 17 | * SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND |
| 18 | * FITNESS, IN NO EVENT SHALL THE COPYRIGHT HOLDERS BE LIABLE FOR ANY |
| 19 | * SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER |
| 20 | * RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF |
| 21 | * CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN |
| 22 | * CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. |
| 23 | */ |
| 24 | |
Daniel Stone | c228e23 | 2013-05-22 18:03:19 +0300 | [diff] [blame] | 25 | #include "config.h" |
| 26 | |
Kristian Høgsberg | 4cca349 | 2011-01-18 07:53:49 -0500 | [diff] [blame] | 27 | #include <stdlib.h> |
Kristian Høgsberg | 7584062 | 2011-09-06 13:48:16 -0400 | [diff] [blame] | 28 | #include <stdio.h> |
Kristian Høgsberg | 4cca349 | 2011-01-18 07:53:49 -0500 | [diff] [blame] | 29 | #include <string.h> |
| 30 | #include <unistd.h> |
Kristian Høgsberg | 0793756 | 2011-04-12 17:25:42 -0400 | [diff] [blame] | 31 | #include <linux/input.h> |
Pekka Paalanen | f0fc70d | 2011-11-15 13:34:54 +0200 | [diff] [blame] | 32 | #include <assert.h> |
Pekka Paalanen | 18027e5 | 2011-12-02 16:31:49 +0200 | [diff] [blame] | 33 | #include <signal.h> |
Pekka Paalanen | 460099f | 2012-01-20 16:48:25 +0200 | [diff] [blame] | 34 | #include <math.h> |
Kristian Høgsberg | 92a57db | 2012-05-26 13:41:06 -0400 | [diff] [blame] | 35 | #include <sys/types.h> |
Kristian Høgsberg | 4cca349 | 2011-01-18 07:53:49 -0500 | [diff] [blame] | 36 | |
Kristian Høgsberg | 1ef2313 | 2013-12-04 00:20:01 -0800 | [diff] [blame] | 37 | #include "shell.h" |
Kristian Høgsberg | 7584062 | 2011-09-06 13:48:16 -0400 | [diff] [blame] | 38 | #include "desktop-shell-server-protocol.h" |
Jonas Ådahl | e9d2250 | 2012-08-29 22:13:01 +0200 | [diff] [blame] | 39 | #include "workspaces-server-protocol.h" |
Pekka Paalanen | e955f1e | 2011-12-07 11:49:52 +0200 | [diff] [blame] | 40 | #include "../shared/config-parser.h" |
Rafael Antognolli | e2a3455 | 2013-12-03 15:35:45 -0200 | [diff] [blame] | 41 | #include "xdg-shell-server-protocol.h" |
Kristian Høgsberg | 4cca349 | 2011-01-18 07:53:49 -0500 | [diff] [blame] | 42 | |
Jonas Ådahl | e3cddce | 2012-06-13 00:01:22 +0200 | [diff] [blame] | 43 | #define DEFAULT_NUM_WORKSPACES 1 |
Jonas Ådahl | 62fcd04 | 2012-06-13 00:01:23 +0200 | [diff] [blame] | 44 | #define DEFAULT_WORKSPACE_CHANGE_ANIMATION_LENGTH 200 |
Jonas Ådahl | e3cddce | 2012-06-13 00:01:22 +0200 | [diff] [blame] | 45 | |
Giulio Camuffo | 1aaf3e4 | 2013-12-09 22:47:58 +0100 | [diff] [blame] | 46 | #ifndef static_assert |
| 47 | #define static_assert(cond, msg) |
| 48 | #endif |
| 49 | |
Jonas Ådahl | 0476974 | 2012-06-13 00:01:24 +0200 | [diff] [blame] | 50 | struct focus_state { |
| 51 | struct weston_seat *seat; |
Kristian Høgsberg | 2f5faff | 2012-07-31 16:36:34 -0400 | [diff] [blame] | 52 | struct workspace *ws; |
Jonas Ådahl | 0476974 | 2012-06-13 00:01:24 +0200 | [diff] [blame] | 53 | struct weston_surface *keyboard_focus; |
| 54 | struct wl_list link; |
| 55 | struct wl_listener seat_destroy_listener; |
| 56 | struct wl_listener surface_destroy_listener; |
| 57 | }; |
| 58 | |
Kristian Høgsberg | d2abb83 | 2011-11-23 10:52:40 -0500 | [diff] [blame] | 59 | enum shell_surface_type { |
Pekka Paalanen | 9826223 | 2011-12-01 10:42:22 +0200 | [diff] [blame] | 60 | SHELL_SURFACE_NONE, |
Kristian Høgsberg | d2abb83 | 2011-11-23 10:52:40 -0500 | [diff] [blame] | 61 | SHELL_SURFACE_TOPLEVEL, |
Tiago Vignatti | fb2adba | 2013-06-12 15:43:21 -0300 | [diff] [blame] | 62 | SHELL_SURFACE_POPUP, |
| 63 | SHELL_SURFACE_XWAYLAND |
Pekka Paalanen | 57da4a8 | 2011-11-23 16:42:16 +0200 | [diff] [blame] | 64 | }; |
| 65 | |
Jason Ekstrand | 9e9512f | 2014-04-16 21:12:10 -0500 | [diff] [blame] | 66 | struct shell_client; |
| 67 | |
Philip Withnall | 648a4dd | 2013-11-25 18:01:44 +0000 | [diff] [blame] | 68 | /* |
| 69 | * Surface stacking and ordering. |
| 70 | * |
| 71 | * This is handled using several linked lists of surfaces, organised into |
| 72 | * ‘layers’. The layers are ordered, and each of the surfaces in one layer are |
| 73 | * above all of the surfaces in the layer below. The set of layers is static and |
| 74 | * in the following order (top-most first): |
| 75 | * • Lock layer (only ever displayed on its own) |
| 76 | * • Cursor layer |
Manuel Bachmann | 805d2f5 | 2014-03-05 12:21:34 +0100 | [diff] [blame] | 77 | * • Input panel layer |
Philip Withnall | 648a4dd | 2013-11-25 18:01:44 +0000 | [diff] [blame] | 78 | * • Fullscreen layer |
| 79 | * • Panel layer |
Philip Withnall | 648a4dd | 2013-11-25 18:01:44 +0000 | [diff] [blame] | 80 | * • Workspace layers |
| 81 | * • Background layer |
| 82 | * |
| 83 | * The list of layers may be manipulated to remove whole layers of surfaces from |
| 84 | * display. For example, when locking the screen, all layers except the lock |
| 85 | * layer are removed. |
| 86 | * |
| 87 | * A surface’s layer is modified on configuring the surface, in |
| 88 | * set_surface_type() (which is only called when the surface’s type change is |
| 89 | * _committed_). If a surface’s type changes (e.g. when making a window |
| 90 | * fullscreen) its layer changes too. |
| 91 | * |
| 92 | * In order to allow popup and transient surfaces to be correctly stacked above |
| 93 | * their parent surfaces, each surface tracks both its parent surface, and a |
| 94 | * linked list of its children. When a surface’s layer is updated, so are the |
| 95 | * layers of its children. Note that child surfaces are *not* the same as |
| 96 | * subsurfaces — child/parent surfaces are purely for maintaining stacking |
| 97 | * order. |
| 98 | * |
| 99 | * The children_link list of siblings of a surface (i.e. those surfaces which |
| 100 | * have the same parent) only contains weston_surfaces which have a |
| 101 | * shell_surface. Stacking is not implemented for non-shell_surface |
| 102 | * weston_surfaces. This means that the following implication does *not* hold: |
| 103 | * (shsurf->parent != NULL) ⇒ !wl_list_is_empty(shsurf->children_link) |
| 104 | */ |
| 105 | |
Pekka Paalanen | 56cdea9 | 2011-11-23 16:14:12 +0200 | [diff] [blame] | 106 | struct shell_surface { |
Jason Ekstrand | 651f00e | 2013-06-14 10:07:54 -0500 | [diff] [blame] | 107 | struct wl_resource *resource; |
| 108 | struct wl_signal destroy_signal; |
Jason Ekstrand | 9e9512f | 2014-04-16 21:12:10 -0500 | [diff] [blame] | 109 | struct shell_client *owner; |
Pekka Paalanen | 9d1613e | 2011-11-25 12:09:16 +0200 | [diff] [blame] | 110 | |
Kristian Høgsberg | 8334bc1 | 2012-01-03 10:29:47 -0500 | [diff] [blame] | 111 | struct weston_surface *surface; |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 112 | struct weston_view *view; |
Jason Ekstrand | 918f2dd | 2013-12-02 21:01:53 -0600 | [diff] [blame] | 113 | int32_t last_width, last_height; |
Pekka Paalanen | 9d1613e | 2011-11-25 12:09:16 +0200 | [diff] [blame] | 114 | struct wl_listener surface_destroy_listener; |
Kristian Høgsberg | 160fe75 | 2014-03-11 10:19:10 -0700 | [diff] [blame] | 115 | struct wl_listener resource_destroy_listener; |
| 116 | |
Kristian Høgsberg | 8150b19 | 2012-06-27 10:22:58 -0400 | [diff] [blame] | 117 | struct weston_surface *parent; |
Philip Withnall | 648a4dd | 2013-11-25 18:01:44 +0000 | [diff] [blame] | 118 | struct wl_list children_list; /* child surfaces of this one */ |
| 119 | struct wl_list children_link; /* sibling surfaces of this one */ |
Tiago Vignatti | be14326 | 2012-04-16 17:31:41 +0300 | [diff] [blame] | 120 | struct desktop_shell *shell; |
Pekka Paalanen | 57da4a8 | 2011-11-23 16:42:16 +0200 | [diff] [blame] | 121 | |
Kristian Høgsberg | c8f8dd8 | 2013-12-05 23:20:33 -0800 | [diff] [blame] | 122 | enum shell_surface_type type; |
Kristian Høgsberg | e7afd91 | 2012-05-02 09:47:44 -0400 | [diff] [blame] | 123 | char *title, *class; |
Kristian Høgsberg | d2abb83 | 2011-11-23 10:52:40 -0500 | [diff] [blame] | 124 | int32_t saved_x, saved_y; |
Rafael Antognolli | 3c4e3f7 | 2013-12-03 15:35:46 -0200 | [diff] [blame] | 125 | int32_t saved_width, saved_height; |
Alex Wu | 4539b08 | 2012-03-01 12:57:46 +0800 | [diff] [blame] | 126 | bool saved_position_valid; |
Rafael Antognolli | 3c4e3f7 | 2013-12-03 15:35:46 -0200 | [diff] [blame] | 127 | bool saved_size_valid; |
Alex Wu | 7bcb8bd | 2012-04-27 09:07:24 +0800 | [diff] [blame] | 128 | bool saved_rotation_valid; |
Kristian Høgsberg | c85f1d4 | 2013-10-24 16:52:00 -0700 | [diff] [blame] | 129 | int unresponsive, grabbed; |
Kristian Høgsberg | 44cd196 | 2014-02-05 21:36:04 -0800 | [diff] [blame] | 130 | uint32_t resize_edges; |
Benjamin Franzke | d0f79ab | 2011-11-22 12:43:52 +0100 | [diff] [blame] | 131 | |
Kristian Høgsberg | b3cca0a | 2012-01-04 22:19:14 -0500 | [diff] [blame] | 132 | struct { |
Pekka Paalanen | 460099f | 2012-01-20 16:48:25 +0200 | [diff] [blame] | 133 | struct weston_transform transform; |
Kristian Høgsberg | 765e27b | 2012-01-27 13:36:13 -0500 | [diff] [blame] | 134 | struct weston_matrix rotation; |
Pekka Paalanen | 460099f | 2012-01-20 16:48:25 +0200 | [diff] [blame] | 135 | } rotation; |
| 136 | |
| 137 | struct { |
Giulio Camuffo | 5085a75 | 2013-03-25 21:42:45 +0100 | [diff] [blame] | 138 | struct wl_list grab_link; |
Kristian Høgsberg | b3cca0a | 2012-01-04 22:19:14 -0500 | [diff] [blame] | 139 | int32_t x, y; |
Giulio Camuffo | 5085a75 | 2013-03-25 21:42:45 +0100 | [diff] [blame] | 140 | struct shell_seat *shseat; |
Kristian Høgsberg | 3730f36 | 2012-04-13 12:40:07 -0400 | [diff] [blame] | 141 | uint32_t serial; |
Kristian Høgsberg | b3cca0a | 2012-01-04 22:19:14 -0500 | [diff] [blame] | 142 | } popup; |
| 143 | |
Alex Wu | 4539b08 | 2012-03-01 12:57:46 +0800 | [diff] [blame] | 144 | struct { |
Tiago Vignatti | 52e598c | 2012-05-07 15:23:08 +0300 | [diff] [blame] | 145 | int32_t x, y; |
Tiago Vignatti | 491bac1 | 2012-05-18 16:37:43 -0400 | [diff] [blame] | 146 | uint32_t flags; |
Tiago Vignatti | 52e598c | 2012-05-07 15:23:08 +0300 | [diff] [blame] | 147 | } transient; |
| 148 | |
| 149 | struct { |
Alex Wu | 4539b08 | 2012-03-01 12:57:46 +0800 | [diff] [blame] | 150 | enum wl_shell_surface_fullscreen_method type; |
| 151 | struct weston_transform transform; /* matrix from x, y */ |
| 152 | uint32_t framerate; |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 153 | struct weston_view *black_view; |
Alex Wu | 4539b08 | 2012-03-01 12:57:46 +0800 | [diff] [blame] | 154 | } fullscreen; |
| 155 | |
Jonas Ådahl | 62fcd04 | 2012-06-13 00:01:23 +0200 | [diff] [blame] | 156 | struct weston_transform workspace_transform; |
| 157 | |
Kristian Høgsberg | 1cbf326 | 2012-02-17 23:49:07 -0500 | [diff] [blame] | 158 | struct weston_output *fullscreen_output; |
Kristian Høgsberg | 8334bc1 | 2012-01-03 10:29:47 -0500 | [diff] [blame] | 159 | struct weston_output *output; |
Benjamin Franzke | d0f79ab | 2011-11-22 12:43:52 +0100 | [diff] [blame] | 160 | struct wl_list link; |
Kristian Høgsberg | a61ca06 | 2012-05-22 16:05:52 -0400 | [diff] [blame] | 161 | |
| 162 | const struct weston_shell_client *client; |
Rafael Antognolli | 03b1659 | 2013-12-03 15:35:42 -0200 | [diff] [blame] | 163 | |
Jasper St. Pierre | 6458ec3 | 2014-04-11 16:00:31 -0700 | [diff] [blame] | 164 | struct surface_state { |
Rafael Antognolli | 03b1659 | 2013-12-03 15:35:42 -0200 | [diff] [blame] | 165 | bool maximized; |
| 166 | bool fullscreen; |
Rafael Antognolli | ed207b4 | 2013-12-03 15:35:43 -0200 | [diff] [blame] | 167 | bool relative; |
Emilio Pozuelo Monfort | 9e7c759 | 2014-01-30 14:01:10 +0100 | [diff] [blame] | 168 | bool lowered; |
Jasper St. Pierre | 8c6aa45 | 2014-02-08 18:29:49 -0500 | [diff] [blame] | 169 | } state, next_state, requested_state; /* surface states */ |
Rafael Antognolli | 03b1659 | 2013-12-03 15:35:42 -0200 | [diff] [blame] | 170 | bool state_changed; |
Jasper St. Pierre | 8c6aa45 | 2014-02-08 18:29:49 -0500 | [diff] [blame] | 171 | bool state_requested; |
Jasper St. Pierre | faf27a9 | 2013-12-09 17:36:28 -0500 | [diff] [blame] | 172 | |
Kristian Høgsberg | ae356ae | 2014-04-29 16:03:54 -0700 | [diff] [blame] | 173 | struct { |
Jasper St. Pierre | ccf48fb | 2014-05-02 10:21:38 -0400 | [diff] [blame] | 174 | int32_t x, y, width, height; |
| 175 | } geometry, next_geometry; |
| 176 | bool has_set_geometry, has_next_geometry; |
Kristian Høgsberg | ae356ae | 2014-04-29 16:03:54 -0700 | [diff] [blame] | 177 | |
Jasper St. Pierre | faf27a9 | 2013-12-09 17:36:28 -0500 | [diff] [blame] | 178 | int focus_count; |
Pekka Paalanen | 56cdea9 | 2011-11-23 16:14:12 +0200 | [diff] [blame] | 179 | }; |
| 180 | |
Ander Conselvan de Oliveira | fe0444a | 2012-04-04 17:48:05 +0300 | [diff] [blame] | 181 | struct shell_grab { |
Kristian Høgsberg | 02bbabb | 2013-05-06 22:15:05 -0400 | [diff] [blame] | 182 | struct weston_pointer_grab grab; |
Ander Conselvan de Oliveira | fe0444a | 2012-04-04 17:48:05 +0300 | [diff] [blame] | 183 | struct shell_surface *shsurf; |
| 184 | struct wl_listener shsurf_destroy_listener; |
| 185 | }; |
| 186 | |
Rusty Lynch | 1084da5 | 2013-08-15 09:10:08 -0700 | [diff] [blame] | 187 | struct shell_touch_grab { |
| 188 | struct weston_touch_grab grab; |
| 189 | struct shell_surface *shsurf; |
| 190 | struct wl_listener shsurf_destroy_listener; |
| 191 | struct weston_touch *touch; |
| 192 | }; |
| 193 | |
Ander Conselvan de Oliveira | fe0444a | 2012-04-04 17:48:05 +0300 | [diff] [blame] | 194 | struct weston_move_grab { |
| 195 | struct shell_grab base; |
Daniel Stone | 103db7f | 2012-05-08 17:17:55 +0100 | [diff] [blame] | 196 | wl_fixed_t dx, dy; |
Kristian Høgsberg | ae356ae | 2014-04-29 16:03:54 -0700 | [diff] [blame] | 197 | int client_initiated; |
Kristian Høgsberg | 4cca349 | 2011-01-18 07:53:49 -0500 | [diff] [blame] | 198 | }; |
| 199 | |
Rusty Lynch | 1084da5 | 2013-08-15 09:10:08 -0700 | [diff] [blame] | 200 | struct weston_touch_move_grab { |
| 201 | struct shell_touch_grab base; |
Kristian Høgsberg | 8e80a31 | 2014-01-17 15:18:10 -0800 | [diff] [blame] | 202 | int active; |
Rusty Lynch | 1084da5 | 2013-08-15 09:10:08 -0700 | [diff] [blame] | 203 | wl_fixed_t dx, dy; |
| 204 | }; |
| 205 | |
Pekka Paalanen | 460099f | 2012-01-20 16:48:25 +0200 | [diff] [blame] | 206 | struct rotate_grab { |
Ander Conselvan de Oliveira | fe0444a | 2012-04-04 17:48:05 +0300 | [diff] [blame] | 207 | struct shell_grab base; |
Kristian Høgsberg | 765e27b | 2012-01-27 13:36:13 -0500 | [diff] [blame] | 208 | struct weston_matrix rotation; |
Pekka Paalanen | 460099f | 2012-01-20 16:48:25 +0200 | [diff] [blame] | 209 | struct { |
John Kåre Alsaker | 490d02a | 2012-09-30 02:57:21 +0200 | [diff] [blame] | 210 | float x; |
| 211 | float y; |
Pekka Paalanen | 460099f | 2012-01-20 16:48:25 +0200 | [diff] [blame] | 212 | } center; |
| 213 | }; |
| 214 | |
Giulio Camuffo | 5085a75 | 2013-03-25 21:42:45 +0100 | [diff] [blame] | 215 | struct shell_seat { |
| 216 | struct weston_seat *seat; |
| 217 | struct wl_listener seat_destroy_listener; |
Jasper St. Pierre | faf27a9 | 2013-12-09 17:36:28 -0500 | [diff] [blame] | 218 | struct weston_surface *focused_surface; |
Giulio Camuffo | 5085a75 | 2013-03-25 21:42:45 +0100 | [diff] [blame] | 219 | |
Jason Ekstrand | 024177c | 2014-04-21 19:42:58 -0500 | [diff] [blame] | 220 | struct wl_listener caps_changed_listener; |
| 221 | struct wl_listener pointer_focus_listener; |
| 222 | struct wl_listener keyboard_focus_listener; |
| 223 | |
Giulio Camuffo | 5085a75 | 2013-03-25 21:42:45 +0100 | [diff] [blame] | 224 | struct { |
Kristian Høgsberg | 02bbabb | 2013-05-06 22:15:05 -0400 | [diff] [blame] | 225 | struct weston_pointer_grab grab; |
Jonny Lamb | 76cf1fe | 2014-08-20 11:27:10 +0200 | [diff] [blame] | 226 | struct weston_touch_grab touch_grab; |
Giulio Camuffo | 5085a75 | 2013-03-25 21:42:45 +0100 | [diff] [blame] | 227 | struct wl_list surfaces_list; |
| 228 | struct wl_client *client; |
| 229 | int32_t initial_up; |
Jonny Lamb | 76cf1fe | 2014-08-20 11:27:10 +0200 | [diff] [blame] | 230 | enum { POINTER, TOUCH } type; |
Giulio Camuffo | 5085a75 | 2013-03-25 21:42:45 +0100 | [diff] [blame] | 231 | } popup_grab; |
| 232 | }; |
| 233 | |
Kristian Høgsberg | 2bff94e | 2014-02-11 12:22:51 -0800 | [diff] [blame] | 234 | struct shell_client { |
| 235 | struct wl_resource *resource; |
| 236 | struct wl_client *client; |
| 237 | struct desktop_shell *shell; |
| 238 | struct wl_listener destroy_listener; |
| 239 | struct wl_event_source *ping_timer; |
| 240 | uint32_t ping_serial; |
| 241 | int unresponsive; |
| 242 | }; |
| 243 | |
Alex Wu | bd3354b | 2012-04-17 17:20:49 +0800 | [diff] [blame] | 244 | static struct desktop_shell * |
| 245 | shell_surface_get_shell(struct shell_surface *shsurf); |
| 246 | |
Kristian Høgsberg | 0c36903 | 2013-02-14 21:31:44 -0500 | [diff] [blame] | 247 | static void |
Kristian Høgsberg | e314875 | 2013-05-06 23:19:49 -0400 | [diff] [blame] | 248 | surface_rotate(struct shell_surface *surface, struct weston_seat *seat); |
Kristian Høgsberg | 0c36903 | 2013-02-14 21:31:44 -0500 | [diff] [blame] | 249 | |
Pekka Paalanen | 79346ab | 2013-05-22 18:03:09 +0300 | [diff] [blame] | 250 | static void |
| 251 | shell_fade_startup(struct desktop_shell *shell); |
| 252 | |
Philip Withnall | becb77e | 2013-11-25 18:01:30 +0000 | [diff] [blame] | 253 | static struct shell_seat * |
| 254 | get_shell_seat(struct weston_seat *seat); |
| 255 | |
Jonny Lamb | d73c694 | 2014-08-20 15:53:20 +0200 | [diff] [blame] | 256 | static void |
| 257 | get_output_panel_size(struct desktop_shell *shell, |
| 258 | struct weston_output *output, |
| 259 | int *width, int *height); |
Kristian Høgsberg | ae356ae | 2014-04-29 16:03:54 -0700 | [diff] [blame] | 260 | |
Philip Withnall | 648a4dd | 2013-11-25 18:01:44 +0000 | [diff] [blame] | 261 | static void |
| 262 | shell_surface_update_child_surface_layers(struct shell_surface *shsurf); |
| 263 | |
Alex Wu | bd3354b | 2012-04-17 17:20:49 +0800 | [diff] [blame] | 264 | static bool |
Rafael Antognolli | e2a3455 | 2013-12-03 15:35:45 -0200 | [diff] [blame] | 265 | shell_surface_is_wl_shell_surface(struct shell_surface *shsurf); |
| 266 | |
| 267 | static bool |
| 268 | shell_surface_is_xdg_surface(struct shell_surface *shsurf); |
| 269 | |
| 270 | static bool |
| 271 | shell_surface_is_xdg_popup(struct shell_surface *shsurf); |
| 272 | |
| 273 | static void |
| 274 | shell_surface_set_parent(struct shell_surface *shsurf, |
| 275 | struct weston_surface *parent); |
| 276 | |
| 277 | static bool |
Alex Wu | bd3354b | 2012-04-17 17:20:49 +0800 | [diff] [blame] | 278 | shell_surface_is_top_fullscreen(struct shell_surface *shsurf) |
| 279 | { |
| 280 | struct desktop_shell *shell; |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 281 | struct weston_view *top_fs_ev; |
Alex Wu | bd3354b | 2012-04-17 17:20:49 +0800 | [diff] [blame] | 282 | |
| 283 | shell = shell_surface_get_shell(shsurf); |
Quentin Glidic | c0d79ce | 2013-01-29 14:16:13 +0100 | [diff] [blame] | 284 | |
Giulio Camuffo | 412e6a5 | 2014-07-09 22:12:56 +0300 | [diff] [blame] | 285 | if (wl_list_empty(&shell->fullscreen_layer.view_list.link)) |
Alex Wu | bd3354b | 2012-04-17 17:20:49 +0800 | [diff] [blame] | 286 | return false; |
| 287 | |
Giulio Camuffo | 412e6a5 | 2014-07-09 22:12:56 +0300 | [diff] [blame] | 288 | top_fs_ev = container_of(shell->fullscreen_layer.view_list.link.next, |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 289 | struct weston_view, |
Giulio Camuffo | 412e6a5 | 2014-07-09 22:12:56 +0300 | [diff] [blame] | 290 | layer_link.link); |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 291 | return (shsurf == get_shell_surface(top_fs_ev->surface)); |
Alex Wu | bd3354b | 2012-04-17 17:20:49 +0800 | [diff] [blame] | 292 | } |
| 293 | |
Kristian Høgsberg | 6af8eb9 | 2012-01-25 16:57:11 -0500 | [diff] [blame] | 294 | static void |
Kristian Høgsberg | 27e3052 | 2012-04-11 23:18:23 -0400 | [diff] [blame] | 295 | destroy_shell_grab_shsurf(struct wl_listener *listener, void *data) |
Ander Conselvan de Oliveira | fe0444a | 2012-04-04 17:48:05 +0300 | [diff] [blame] | 296 | { |
| 297 | struct shell_grab *grab; |
| 298 | |
| 299 | grab = container_of(listener, struct shell_grab, |
| 300 | shsurf_destroy_listener); |
| 301 | |
| 302 | grab->shsurf = NULL; |
| 303 | } |
| 304 | |
Kristian Høgsberg | 1ef2313 | 2013-12-04 00:20:01 -0800 | [diff] [blame] | 305 | struct weston_view * |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 306 | get_default_view(struct weston_surface *surface) |
| 307 | { |
| 308 | struct shell_surface *shsurf; |
| 309 | struct weston_view *view; |
| 310 | |
| 311 | if (!surface || wl_list_empty(&surface->views)) |
| 312 | return NULL; |
| 313 | |
| 314 | shsurf = get_shell_surface(surface); |
| 315 | if (shsurf) |
| 316 | return shsurf->view; |
| 317 | |
| 318 | wl_list_for_each(view, &surface->views, surface_link) |
| 319 | if (weston_view_is_mapped(view)) |
| 320 | return view; |
| 321 | |
| 322 | return container_of(surface->views.next, struct weston_view, surface_link); |
| 323 | } |
| 324 | |
Ander Conselvan de Oliveira | fe0444a | 2012-04-04 17:48:05 +0300 | [diff] [blame] | 325 | static void |
Kristian Høgsberg | 02bbabb | 2013-05-06 22:15:05 -0400 | [diff] [blame] | 326 | popup_grab_end(struct weston_pointer *pointer); |
Jonny Lamb | 76cf1fe | 2014-08-20 11:27:10 +0200 | [diff] [blame] | 327 | static void |
| 328 | touch_popup_grab_end(struct weston_touch *touch); |
Kristian Høgsberg | 57e0907 | 2012-10-30 14:07:27 -0400 | [diff] [blame] | 329 | |
| 330 | static void |
Ander Conselvan de Oliveira | b9d2a0f | 2012-06-28 18:08:05 +0300 | [diff] [blame] | 331 | shell_grab_start(struct shell_grab *grab, |
Kristian Høgsberg | 02bbabb | 2013-05-06 22:15:05 -0400 | [diff] [blame] | 332 | const struct weston_pointer_grab_interface *interface, |
Ander Conselvan de Oliveira | b9d2a0f | 2012-06-28 18:08:05 +0300 | [diff] [blame] | 333 | struct shell_surface *shsurf, |
Kristian Høgsberg | 02bbabb | 2013-05-06 22:15:05 -0400 | [diff] [blame] | 334 | struct weston_pointer *pointer, |
Ander Conselvan de Oliveira | b9d2a0f | 2012-06-28 18:08:05 +0300 | [diff] [blame] | 335 | enum desktop_shell_cursor cursor) |
Ander Conselvan de Oliveira | fe0444a | 2012-04-04 17:48:05 +0300 | [diff] [blame] | 336 | { |
Ander Conselvan de Oliveira | b9d2a0f | 2012-06-28 18:08:05 +0300 | [diff] [blame] | 337 | struct desktop_shell *shell = shsurf->shell; |
| 338 | |
Kristian Høgsberg | 57e0907 | 2012-10-30 14:07:27 -0400 | [diff] [blame] | 339 | popup_grab_end(pointer); |
Jonny Lamb | 76cf1fe | 2014-08-20 11:27:10 +0200 | [diff] [blame] | 340 | if (pointer->seat->touch) |
| 341 | touch_popup_grab_end(pointer->seat->touch); |
Kristian Høgsberg | 57e0907 | 2012-10-30 14:07:27 -0400 | [diff] [blame] | 342 | |
Ander Conselvan de Oliveira | fe0444a | 2012-04-04 17:48:05 +0300 | [diff] [blame] | 343 | grab->grab.interface = interface; |
| 344 | grab->shsurf = shsurf; |
Kristian Høgsberg | 27e3052 | 2012-04-11 23:18:23 -0400 | [diff] [blame] | 345 | grab->shsurf_destroy_listener.notify = destroy_shell_grab_shsurf; |
Jason Ekstrand | 651f00e | 2013-06-14 10:07:54 -0500 | [diff] [blame] | 346 | wl_signal_add(&shsurf->destroy_signal, |
Kristian Høgsberg | 27e3052 | 2012-04-11 23:18:23 -0400 | [diff] [blame] | 347 | &grab->shsurf_destroy_listener); |
Ander Conselvan de Oliveira | fe0444a | 2012-04-04 17:48:05 +0300 | [diff] [blame] | 348 | |
Kristian Høgsberg | c85f1d4 | 2013-10-24 16:52:00 -0700 | [diff] [blame] | 349 | shsurf->grabbed = 1; |
Kristian Høgsberg | 02bbabb | 2013-05-06 22:15:05 -0400 | [diff] [blame] | 350 | weston_pointer_start_grab(pointer, &grab->grab); |
Kristian Høgsberg | c9974a0 | 2013-07-03 19:24:57 -0400 | [diff] [blame] | 351 | if (shell->child.desktop_shell) { |
| 352 | desktop_shell_send_grab_cursor(shell->child.desktop_shell, |
| 353 | cursor); |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 354 | weston_pointer_set_focus(pointer, |
| 355 | get_default_view(shell->grab_surface), |
Kristian Høgsberg | c9974a0 | 2013-07-03 19:24:57 -0400 | [diff] [blame] | 356 | wl_fixed_from_int(0), |
| 357 | wl_fixed_from_int(0)); |
| 358 | } |
Ander Conselvan de Oliveira | fe0444a | 2012-04-04 17:48:05 +0300 | [diff] [blame] | 359 | } |
| 360 | |
Jonny Lamb | d73c694 | 2014-08-20 15:53:20 +0200 | [diff] [blame] | 361 | static void |
| 362 | get_output_panel_size(struct desktop_shell *shell, |
| 363 | struct weston_output *output, |
| 364 | int *width, |
| 365 | int *height) |
Jasper St. Pierre | 6458ec3 | 2014-04-11 16:00:31 -0700 | [diff] [blame] | 366 | { |
| 367 | struct weston_view *view; |
Jonny Lamb | d73c694 | 2014-08-20 15:53:20 +0200 | [diff] [blame] | 368 | |
| 369 | *width = 0; |
| 370 | *height = 0; |
Jasper St. Pierre | 6458ec3 | 2014-04-11 16:00:31 -0700 | [diff] [blame] | 371 | |
| 372 | if (!output) |
Jonny Lamb | d73c694 | 2014-08-20 15:53:20 +0200 | [diff] [blame] | 373 | return; |
Jasper St. Pierre | 6458ec3 | 2014-04-11 16:00:31 -0700 | [diff] [blame] | 374 | |
Giulio Camuffo | 412e6a5 | 2014-07-09 22:12:56 +0300 | [diff] [blame] | 375 | 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] | 376 | float x, y; |
| 377 | |
| 378 | if (view->surface->output != output) |
| 379 | continue; |
| 380 | |
| 381 | switch (shell->panel_position) { |
| 382 | case DESKTOP_SHELL_PANEL_POSITION_TOP: |
| 383 | case DESKTOP_SHELL_PANEL_POSITION_BOTTOM: |
| 384 | |
| 385 | weston_view_to_global_float(view, |
| 386 | view->surface->width, 0, |
| 387 | &x, &y); |
| 388 | |
| 389 | *width = (int) x; |
| 390 | *height = view->surface->height + (int) y; |
| 391 | return; |
| 392 | |
| 393 | case DESKTOP_SHELL_PANEL_POSITION_LEFT: |
| 394 | case DESKTOP_SHELL_PANEL_POSITION_RIGHT: |
| 395 | weston_view_to_global_float(view, |
| 396 | 0, view->surface->height, |
| 397 | &x, &y); |
| 398 | |
| 399 | *width = view->surface->width + (int) x; |
| 400 | *height = (int) y; |
| 401 | return; |
| 402 | |
| 403 | default: |
| 404 | /* we've already set width and height to |
| 405 | * fallback values. */ |
Jasper St. Pierre | 6458ec3 | 2014-04-11 16:00:31 -0700 | [diff] [blame] | 406 | break; |
| 407 | } |
| 408 | } |
| 409 | |
Jonny Lamb | d73c694 | 2014-08-20 15:53:20 +0200 | [diff] [blame] | 410 | /* the correct view wasn't found */ |
| 411 | } |
| 412 | |
| 413 | static void |
| 414 | get_output_work_area(struct desktop_shell *shell, |
| 415 | struct weston_output *output, |
| 416 | pixman_rectangle32_t *area) |
| 417 | { |
| 418 | int32_t panel_width = 0, panel_height = 0; |
| 419 | |
| 420 | area->x = 0; |
| 421 | area->y = 0; |
| 422 | |
| 423 | get_output_panel_size(shell, output, &panel_width, &panel_height); |
| 424 | |
| 425 | switch (shell->panel_position) { |
| 426 | case DESKTOP_SHELL_PANEL_POSITION_TOP: |
| 427 | default: |
| 428 | area->y = panel_height; |
| 429 | case DESKTOP_SHELL_PANEL_POSITION_BOTTOM: |
| 430 | area->width = output->width; |
| 431 | area->height = output->height - panel_height; |
| 432 | break; |
| 433 | case DESKTOP_SHELL_PANEL_POSITION_LEFT: |
| 434 | area->x = panel_width; |
| 435 | case DESKTOP_SHELL_PANEL_POSITION_RIGHT: |
| 436 | area->width = output->width - panel_width; |
| 437 | area->height = output->height; |
| 438 | break; |
| 439 | } |
Jasper St. Pierre | 6458ec3 | 2014-04-11 16:00:31 -0700 | [diff] [blame] | 440 | } |
| 441 | |
| 442 | static void |
| 443 | send_configure_for_surface(struct shell_surface *shsurf) |
| 444 | { |
| 445 | int32_t width, height; |
| 446 | struct surface_state *state; |
| 447 | |
| 448 | if (shsurf->state_requested) |
| 449 | state = &shsurf->requested_state; |
| 450 | else if (shsurf->state_changed) |
| 451 | state = &shsurf->next_state; |
| 452 | else |
| 453 | state = &shsurf->state; |
| 454 | |
| 455 | if (state->fullscreen) { |
| 456 | width = shsurf->output->width; |
| 457 | height = shsurf->output->height; |
| 458 | } else if (state->maximized) { |
| 459 | struct desktop_shell *shell; |
Jonny Lamb | d73c694 | 2014-08-20 15:53:20 +0200 | [diff] [blame] | 460 | pixman_rectangle32_t area; |
Jasper St. Pierre | 6458ec3 | 2014-04-11 16:00:31 -0700 | [diff] [blame] | 461 | |
| 462 | shell = shell_surface_get_shell(shsurf); |
Jonny Lamb | d73c694 | 2014-08-20 15:53:20 +0200 | [diff] [blame] | 463 | get_output_work_area(shell, shsurf->output, &area); |
Jasper St. Pierre | 6458ec3 | 2014-04-11 16:00:31 -0700 | [diff] [blame] | 464 | |
Jonny Lamb | d73c694 | 2014-08-20 15:53:20 +0200 | [diff] [blame] | 465 | width = area.width; |
| 466 | height = area.height; |
Jasper St. Pierre | 6458ec3 | 2014-04-11 16:00:31 -0700 | [diff] [blame] | 467 | } else { |
| 468 | width = 0; |
| 469 | height = 0; |
| 470 | } |
| 471 | |
| 472 | shsurf->client->send_configure(shsurf->surface, width, height); |
| 473 | } |
| 474 | |
Ander Conselvan de Oliveira | fe0444a | 2012-04-04 17:48:05 +0300 | [diff] [blame] | 475 | static void |
Jasper St. Pierre | 5befdda | 2014-05-06 08:50:47 -0400 | [diff] [blame] | 476 | shell_surface_state_changed(struct shell_surface *shsurf) |
| 477 | { |
Jasper St. Pierre | 6458ec3 | 2014-04-11 16:00:31 -0700 | [diff] [blame] | 478 | if (shell_surface_is_xdg_surface(shsurf)) |
| 479 | send_configure_for_surface(shsurf); |
Jasper St. Pierre | 5befdda | 2014-05-06 08:50:47 -0400 | [diff] [blame] | 480 | } |
| 481 | |
| 482 | static void |
Ander Conselvan de Oliveira | b9d2a0f | 2012-06-28 18:08:05 +0300 | [diff] [blame] | 483 | shell_grab_end(struct shell_grab *grab) |
Ander Conselvan de Oliveira | fe0444a | 2012-04-04 17:48:05 +0300 | [diff] [blame] | 484 | { |
Kristian Høgsberg | c85f1d4 | 2013-10-24 16:52:00 -0700 | [diff] [blame] | 485 | if (grab->shsurf) { |
Kristian Høgsberg | 47b5dca | 2012-06-07 18:08:04 -0400 | [diff] [blame] | 486 | wl_list_remove(&grab->shsurf_destroy_listener.link); |
Kristian Høgsberg | c85f1d4 | 2013-10-24 16:52:00 -0700 | [diff] [blame] | 487 | grab->shsurf->grabbed = 0; |
Jasper St. Pierre | 5befdda | 2014-05-06 08:50:47 -0400 | [diff] [blame] | 488 | |
| 489 | if (grab->shsurf->resize_edges) { |
| 490 | grab->shsurf->resize_edges = 0; |
| 491 | shell_surface_state_changed(grab->shsurf); |
| 492 | } |
Kristian Høgsberg | c85f1d4 | 2013-10-24 16:52:00 -0700 | [diff] [blame] | 493 | } |
Ander Conselvan de Oliveira | b9d2a0f | 2012-06-28 18:08:05 +0300 | [diff] [blame] | 494 | |
Kristian Høgsberg | 9e5d7d1 | 2013-07-22 16:31:53 -0700 | [diff] [blame] | 495 | weston_pointer_end_grab(grab->grab.pointer); |
Ander Conselvan de Oliveira | fe0444a | 2012-04-04 17:48:05 +0300 | [diff] [blame] | 496 | } |
| 497 | |
| 498 | static void |
Rusty Lynch | 1084da5 | 2013-08-15 09:10:08 -0700 | [diff] [blame] | 499 | shell_touch_grab_start(struct shell_touch_grab *grab, |
| 500 | const struct weston_touch_grab_interface *interface, |
| 501 | struct shell_surface *shsurf, |
| 502 | struct weston_touch *touch) |
| 503 | { |
| 504 | struct desktop_shell *shell = shsurf->shell; |
U. Artie Eoff | cf5737a | 2014-01-17 10:08:25 -0800 | [diff] [blame] | 505 | |
Jonny Lamb | 76cf1fe | 2014-08-20 11:27:10 +0200 | [diff] [blame] | 506 | touch_popup_grab_end(touch); |
Kristian Høgsberg | 74071e0 | 2014-04-29 15:01:16 -0700 | [diff] [blame] | 507 | if (touch->seat->pointer) |
| 508 | popup_grab_end(touch->seat->pointer); |
| 509 | |
Rusty Lynch | 1084da5 | 2013-08-15 09:10:08 -0700 | [diff] [blame] | 510 | grab->grab.interface = interface; |
| 511 | grab->shsurf = shsurf; |
| 512 | grab->shsurf_destroy_listener.notify = destroy_shell_grab_shsurf; |
| 513 | wl_signal_add(&shsurf->destroy_signal, |
| 514 | &grab->shsurf_destroy_listener); |
| 515 | |
| 516 | grab->touch = touch; |
Kristian Høgsberg | c85f1d4 | 2013-10-24 16:52:00 -0700 | [diff] [blame] | 517 | shsurf->grabbed = 1; |
Rusty Lynch | 1084da5 | 2013-08-15 09:10:08 -0700 | [diff] [blame] | 518 | |
| 519 | weston_touch_start_grab(touch, &grab->grab); |
| 520 | if (shell->child.desktop_shell) |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 521 | weston_touch_set_focus(touch->seat, |
| 522 | get_default_view(shell->grab_surface)); |
Rusty Lynch | 1084da5 | 2013-08-15 09:10:08 -0700 | [diff] [blame] | 523 | } |
| 524 | |
| 525 | static void |
| 526 | shell_touch_grab_end(struct shell_touch_grab *grab) |
| 527 | { |
Kristian Høgsberg | c85f1d4 | 2013-10-24 16:52:00 -0700 | [diff] [blame] | 528 | if (grab->shsurf) { |
Rusty Lynch | 1084da5 | 2013-08-15 09:10:08 -0700 | [diff] [blame] | 529 | wl_list_remove(&grab->shsurf_destroy_listener.link); |
Kristian Høgsberg | c85f1d4 | 2013-10-24 16:52:00 -0700 | [diff] [blame] | 530 | grab->shsurf->grabbed = 0; |
| 531 | } |
Rusty Lynch | 1084da5 | 2013-08-15 09:10:08 -0700 | [diff] [blame] | 532 | |
| 533 | weston_touch_end_grab(grab->touch); |
| 534 | } |
| 535 | |
| 536 | static void |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 537 | center_on_output(struct weston_view *view, |
Alex Wu | 4539b08 | 2012-03-01 12:57:46 +0800 | [diff] [blame] | 538 | struct weston_output *output); |
| 539 | |
Daniel Stone | 496ca17 | 2012-05-30 16:31:42 +0100 | [diff] [blame] | 540 | static enum weston_keyboard_modifier |
Tiago Vignatti | 0b52d48 | 2012-04-20 18:54:25 +0300 | [diff] [blame] | 541 | get_modifier(char *modifier) |
| 542 | { |
| 543 | if (!modifier) |
| 544 | return MODIFIER_SUPER; |
| 545 | |
| 546 | if (!strcmp("ctrl", modifier)) |
| 547 | return MODIFIER_CTRL; |
| 548 | else if (!strcmp("alt", modifier)) |
| 549 | return MODIFIER_ALT; |
| 550 | else if (!strcmp("super", modifier)) |
| 551 | return MODIFIER_SUPER; |
| 552 | else |
| 553 | return MODIFIER_SUPER; |
| 554 | } |
| 555 | |
Juan Zhao | e10d279 | 2012-04-25 19:09:52 +0800 | [diff] [blame] | 556 | static enum animation_type |
| 557 | get_animation_type(char *animation) |
| 558 | { |
U. Artie Eoff | b571910 | 2014-01-15 14:26:31 -0800 | [diff] [blame] | 559 | if (!animation) |
| 560 | return ANIMATION_NONE; |
| 561 | |
Juan Zhao | e10d279 | 2012-04-25 19:09:52 +0800 | [diff] [blame] | 562 | if (!strcmp("zoom", animation)) |
| 563 | return ANIMATION_ZOOM; |
| 564 | else if (!strcmp("fade", animation)) |
| 565 | return ANIMATION_FADE; |
Louis-Francis Ratté-Boulianne | b482dbd | 2013-11-19 11:37:11 +0100 | [diff] [blame] | 566 | else if (!strcmp("dim-layer", animation)) |
| 567 | return ANIMATION_DIM_LAYER; |
Juan Zhao | e10d279 | 2012-04-25 19:09:52 +0800 | [diff] [blame] | 568 | else |
| 569 | return ANIMATION_NONE; |
| 570 | } |
| 571 | |
Alex Wu | 4539b08 | 2012-03-01 12:57:46 +0800 | [diff] [blame] | 572 | static void |
Kristian Høgsberg | 14e438c | 2013-05-26 21:48:14 -0400 | [diff] [blame] | 573 | shell_configuration(struct desktop_shell *shell) |
Pekka Paalanen | e955f1e | 2011-12-07 11:49:52 +0200 | [diff] [blame] | 574 | { |
Kristian Høgsberg | 673a889 | 2013-05-23 21:40:56 -0400 | [diff] [blame] | 575 | struct weston_config_section *section; |
| 576 | int duration; |
Derek Foreman | c721043 | 2014-08-21 11:32:38 -0500 | [diff] [blame] | 577 | char *s, *client; |
Pekka Paalanen | 974c094 | 2014-09-05 14:45:09 +0300 | [diff] [blame] | 578 | int ret; |
Pekka Paalanen | e955f1e | 2011-12-07 11:49:52 +0200 | [diff] [blame] | 579 | |
Kristian Høgsberg | 673a889 | 2013-05-23 21:40:56 -0400 | [diff] [blame] | 580 | section = weston_config_get_section(shell->compositor->config, |
| 581 | "screensaver", NULL, NULL); |
| 582 | weston_config_section_get_string(section, |
| 583 | "path", &shell->screensaver.path, NULL); |
| 584 | weston_config_section_get_int(section, "duration", &duration, 60); |
Ander Conselvan de Oliveira | 859e885 | 2013-02-21 18:35:21 +0200 | [diff] [blame] | 585 | shell->screensaver.duration = duration * 1000; |
Kristian Høgsberg | 673a889 | 2013-05-23 21:40:56 -0400 | [diff] [blame] | 586 | |
| 587 | section = weston_config_get_section(shell->compositor->config, |
| 588 | "shell", NULL, NULL); |
Pekka Paalanen | 974c094 | 2014-09-05 14:45:09 +0300 | [diff] [blame] | 589 | ret = asprintf(&client, "%s/%s", weston_config_get_libexec_dir(), |
| 590 | WESTON_SHELL_CLIENT); |
| 591 | if (ret < 0) |
| 592 | client = NULL; |
Kristian Høgsberg | 673a889 | 2013-05-23 21:40:56 -0400 | [diff] [blame] | 593 | weston_config_section_get_string(section, |
Derek Foreman | c721043 | 2014-08-21 11:32:38 -0500 | [diff] [blame] | 594 | "client", &s, client); |
| 595 | free(client); |
Emilio Pozuelo Monfort | 46ce798 | 2013-11-20 13:22:29 +0100 | [diff] [blame] | 596 | shell->client = s; |
| 597 | weston_config_section_get_string(section, |
Kristian Høgsberg | 673a889 | 2013-05-23 21:40:56 -0400 | [diff] [blame] | 598 | "binding-modifier", &s, "super"); |
| 599 | shell->binding_modifier = get_modifier(s); |
Quentin Glidic | 8418c29 | 2013-06-18 09:11:03 +0200 | [diff] [blame] | 600 | free(s); |
Kristian Høgsberg | d56ab4e | 2014-01-16 16:51:52 -0800 | [diff] [blame] | 601 | |
| 602 | weston_config_section_get_string(section, |
| 603 | "exposay-modifier", &s, "none"); |
| 604 | if (strcmp(s, "none") == 0) |
| 605 | shell->exposay_modifier = 0; |
| 606 | else |
| 607 | shell->exposay_modifier = get_modifier(s); |
| 608 | free(s); |
| 609 | |
Kristian Høgsberg | 673a889 | 2013-05-23 21:40:56 -0400 | [diff] [blame] | 610 | weston_config_section_get_string(section, "animation", &s, "none"); |
| 611 | shell->win_animation_type = get_animation_type(s); |
Quentin Glidic | 8418c29 | 2013-06-18 09:11:03 +0200 | [diff] [blame] | 612 | free(s); |
Jonny Lamb | f322f8e | 2014-08-12 15:13:30 +0200 | [diff] [blame] | 613 | weston_config_section_get_string(section, "close-animation", &s, "fade"); |
| 614 | shell->win_close_animation_type = get_animation_type(s); |
| 615 | free(s); |
Kristian Høgsberg | 724c8d9 | 2013-10-16 11:38:24 -0700 | [diff] [blame] | 616 | weston_config_section_get_string(section, |
| 617 | "startup-animation", &s, "fade"); |
| 618 | shell->startup_animation_type = get_animation_type(s); |
| 619 | free(s); |
Kristian Høgsberg | 912e0a1 | 2013-10-30 08:59:55 -0700 | [diff] [blame] | 620 | if (shell->startup_animation_type == ANIMATION_ZOOM) |
| 621 | shell->startup_animation_type = ANIMATION_NONE; |
Louis-Francis Ratté-Boulianne | b482dbd | 2013-11-19 11:37:11 +0100 | [diff] [blame] | 622 | weston_config_section_get_string(section, "focus-animation", &s, "none"); |
| 623 | shell->focus_animation_type = get_animation_type(s); |
| 624 | free(s); |
Kristian Høgsberg | 673a889 | 2013-05-23 21:40:56 -0400 | [diff] [blame] | 625 | weston_config_section_get_uint(section, "num-workspaces", |
| 626 | &shell->workspaces.num, |
| 627 | DEFAULT_NUM_WORKSPACES); |
Jonas Ådahl | e3cddce | 2012-06-13 00:01:22 +0200 | [diff] [blame] | 628 | } |
| 629 | |
Kristian Høgsberg | 1ef2313 | 2013-12-04 00:20:01 -0800 | [diff] [blame] | 630 | struct weston_output * |
Louis-Francis Ratté-Boulianne | b482dbd | 2013-11-19 11:37:11 +0100 | [diff] [blame] | 631 | get_default_output(struct weston_compositor *compositor) |
| 632 | { |
| 633 | return container_of(compositor->output_list.next, |
| 634 | struct weston_output, link); |
| 635 | } |
| 636 | |
| 637 | |
| 638 | /* no-op func for checking focus surface */ |
| 639 | static void |
Jason Ekstrand | 918f2dd | 2013-12-02 21:01:53 -0600 | [diff] [blame] | 640 | 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] | 641 | { |
| 642 | } |
| 643 | |
| 644 | static struct focus_surface * |
| 645 | get_focus_surface(struct weston_surface *surface) |
| 646 | { |
| 647 | if (surface->configure == focus_surface_configure) |
| 648 | return surface->configure_private; |
| 649 | else |
| 650 | return NULL; |
| 651 | } |
| 652 | |
| 653 | static bool |
| 654 | is_focus_surface (struct weston_surface *es) |
| 655 | { |
| 656 | return (es->configure == focus_surface_configure); |
| 657 | } |
| 658 | |
| 659 | static bool |
| 660 | is_focus_view (struct weston_view *view) |
| 661 | { |
| 662 | return is_focus_surface (view->surface); |
| 663 | } |
| 664 | |
| 665 | static struct focus_surface * |
| 666 | create_focus_surface(struct weston_compositor *ec, |
| 667 | struct weston_output *output) |
| 668 | { |
| 669 | struct focus_surface *fsurf = NULL; |
| 670 | struct weston_surface *surface = NULL; |
| 671 | |
| 672 | fsurf = malloc(sizeof *fsurf); |
| 673 | if (!fsurf) |
| 674 | return NULL; |
| 675 | |
| 676 | fsurf->surface = weston_surface_create(ec); |
| 677 | surface = fsurf->surface; |
| 678 | if (surface == NULL) { |
| 679 | free(fsurf); |
| 680 | return NULL; |
| 681 | } |
| 682 | |
| 683 | surface->configure = focus_surface_configure; |
| 684 | surface->output = output; |
| 685 | surface->configure_private = fsurf; |
| 686 | |
U. Artie Eoff | 0b23b2b | 2014-01-15 14:45:59 -0800 | [diff] [blame] | 687 | fsurf->view = weston_view_create(surface); |
| 688 | if (fsurf->view == NULL) { |
| 689 | weston_surface_destroy(surface); |
| 690 | free(fsurf); |
| 691 | return NULL; |
| 692 | } |
Emilio Pozuelo Monfort | da64426 | 2013-11-19 11:37:19 +0100 | [diff] [blame] | 693 | fsurf->view->output = output; |
Louis-Francis Ratté-Boulianne | b482dbd | 2013-11-19 11:37:11 +0100 | [diff] [blame] | 694 | |
Jason Ekstrand | 5c11a33 | 2013-12-04 20:32:03 -0600 | [diff] [blame] | 695 | weston_surface_set_size(surface, output->width, output->height); |
Jason Ekstrand | 918f2dd | 2013-12-02 21:01:53 -0600 | [diff] [blame] | 696 | weston_view_set_position(fsurf->view, output->x, output->y); |
Louis-Francis Ratté-Boulianne | b482dbd | 2013-11-19 11:37:11 +0100 | [diff] [blame] | 697 | weston_surface_set_color(surface, 0.0, 0.0, 0.0, 1.0); |
| 698 | pixman_region32_fini(&surface->opaque); |
| 699 | pixman_region32_init_rect(&surface->opaque, output->x, output->y, |
| 700 | output->width, output->height); |
| 701 | pixman_region32_fini(&surface->input); |
| 702 | pixman_region32_init(&surface->input); |
| 703 | |
| 704 | wl_list_init(&fsurf->workspace_transform.link); |
| 705 | |
| 706 | return fsurf; |
| 707 | } |
| 708 | |
| 709 | static void |
| 710 | focus_surface_destroy(struct focus_surface *fsurf) |
| 711 | { |
| 712 | weston_surface_destroy(fsurf->surface); |
| 713 | free(fsurf); |
| 714 | } |
| 715 | |
| 716 | static void |
| 717 | focus_animation_done(struct weston_view_animation *animation, void *data) |
| 718 | { |
| 719 | struct workspace *ws = data; |
| 720 | |
| 721 | ws->focus_animation = NULL; |
| 722 | } |
| 723 | |
Jonas Ådahl | e3cddce | 2012-06-13 00:01:22 +0200 | [diff] [blame] | 724 | static void |
Jonas Ådahl | 0476974 | 2012-06-13 00:01:24 +0200 | [diff] [blame] | 725 | focus_state_destroy(struct focus_state *state) |
| 726 | { |
| 727 | wl_list_remove(&state->seat_destroy_listener.link); |
| 728 | wl_list_remove(&state->surface_destroy_listener.link); |
| 729 | free(state); |
| 730 | } |
| 731 | |
| 732 | static void |
| 733 | focus_state_seat_destroy(struct wl_listener *listener, void *data) |
| 734 | { |
| 735 | struct focus_state *state = container_of(listener, |
| 736 | struct focus_state, |
| 737 | seat_destroy_listener); |
| 738 | |
| 739 | wl_list_remove(&state->link); |
| 740 | focus_state_destroy(state); |
| 741 | } |
| 742 | |
| 743 | static void |
| 744 | focus_state_surface_destroy(struct wl_listener *listener, void *data) |
| 745 | { |
| 746 | struct focus_state *state = container_of(listener, |
| 747 | struct focus_state, |
Kristian Høgsberg | b8e0d0f | 2012-07-31 10:30:26 -0400 | [diff] [blame] | 748 | surface_destroy_listener); |
Kristian Høgsberg | e377822 | 2012-07-31 17:29:30 -0400 | [diff] [blame] | 749 | struct desktop_shell *shell; |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 750 | struct weston_surface *main_surface, *next; |
| 751 | struct weston_view *view; |
Jonas Ådahl | 0476974 | 2012-06-13 00:01:24 +0200 | [diff] [blame] | 752 | |
Pekka Paalanen | 01388e2 | 2013-04-25 13:57:44 +0300 | [diff] [blame] | 753 | main_surface = weston_surface_get_main_surface(state->keyboard_focus); |
| 754 | |
Kristian Høgsberg | e377822 | 2012-07-31 17:29:30 -0400 | [diff] [blame] | 755 | next = NULL; |
Giulio Camuffo | 412e6a5 | 2014-07-09 22:12:56 +0300 | [diff] [blame] | 756 | wl_list_for_each(view, |
| 757 | &state->ws->layer.view_list.link, layer_link.link) { |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 758 | if (view->surface == main_surface) |
Kristian Høgsberg | e377822 | 2012-07-31 17:29:30 -0400 | [diff] [blame] | 759 | continue; |
Louis-Francis Ratté-Boulianne | b482dbd | 2013-11-19 11:37:11 +0100 | [diff] [blame] | 760 | if (is_focus_view(view)) |
| 761 | continue; |
Kristian Høgsberg | e377822 | 2012-07-31 17:29:30 -0400 | [diff] [blame] | 762 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 763 | next = view->surface; |
Kristian Høgsberg | e377822 | 2012-07-31 17:29:30 -0400 | [diff] [blame] | 764 | break; |
| 765 | } |
| 766 | |
Pekka Paalanen | 01388e2 | 2013-04-25 13:57:44 +0300 | [diff] [blame] | 767 | /* if the focus was a sub-surface, activate its main surface */ |
| 768 | if (main_surface != state->keyboard_focus) |
| 769 | next = main_surface; |
| 770 | |
Louis-Francis Ratté-Boulianne | b482dbd | 2013-11-19 11:37:11 +0100 | [diff] [blame] | 771 | shell = state->seat->compositor->shell_interface.shell; |
Kristian Høgsberg | e377822 | 2012-07-31 17:29:30 -0400 | [diff] [blame] | 772 | if (next) { |
Louis-Francis Ratté-Boulianne | b482dbd | 2013-11-19 11:37:11 +0100 | [diff] [blame] | 773 | state->keyboard_focus = NULL; |
Emilio Pozuelo Monfort | 9e7c759 | 2014-01-30 14:01:10 +0100 | [diff] [blame] | 774 | activate(shell, next, state->seat, true); |
Kristian Høgsberg | e377822 | 2012-07-31 17:29:30 -0400 | [diff] [blame] | 775 | } else { |
Louis-Francis Ratté-Boulianne | b482dbd | 2013-11-19 11:37:11 +0100 | [diff] [blame] | 776 | if (shell->focus_animation_type == ANIMATION_DIM_LAYER) { |
| 777 | if (state->ws->focus_animation) |
| 778 | weston_view_animation_destroy(state->ws->focus_animation); |
| 779 | |
| 780 | state->ws->focus_animation = weston_fade_run( |
| 781 | state->ws->fsurf_front->view, |
| 782 | state->ws->fsurf_front->view->alpha, 0.0, 300, |
| 783 | focus_animation_done, state->ws); |
| 784 | } |
| 785 | |
Kristian Høgsberg | e377822 | 2012-07-31 17:29:30 -0400 | [diff] [blame] | 786 | wl_list_remove(&state->link); |
| 787 | focus_state_destroy(state); |
| 788 | } |
Jonas Ådahl | 0476974 | 2012-06-13 00:01:24 +0200 | [diff] [blame] | 789 | } |
| 790 | |
| 791 | static struct focus_state * |
Kristian Høgsberg | 2f5faff | 2012-07-31 16:36:34 -0400 | [diff] [blame] | 792 | focus_state_create(struct weston_seat *seat, struct workspace *ws) |
Jonas Ådahl | 0476974 | 2012-06-13 00:01:24 +0200 | [diff] [blame] | 793 | { |
Jonas Ådahl | 0476974 | 2012-06-13 00:01:24 +0200 | [diff] [blame] | 794 | struct focus_state *state; |
Jonas Ådahl | 0476974 | 2012-06-13 00:01:24 +0200 | [diff] [blame] | 795 | |
| 796 | state = malloc(sizeof *state); |
| 797 | if (state == NULL) |
| 798 | return NULL; |
| 799 | |
Louis-Francis Ratté-Boulianne | b482dbd | 2013-11-19 11:37:11 +0100 | [diff] [blame] | 800 | state->keyboard_focus = NULL; |
Kristian Høgsberg | 2f5faff | 2012-07-31 16:36:34 -0400 | [diff] [blame] | 801 | state->ws = ws; |
Jonas Ådahl | 0476974 | 2012-06-13 00:01:24 +0200 | [diff] [blame] | 802 | state->seat = seat; |
Kristian Høgsberg | 2f5faff | 2012-07-31 16:36:34 -0400 | [diff] [blame] | 803 | wl_list_insert(&ws->focus_list, &state->link); |
Jonas Ådahl | 0476974 | 2012-06-13 00:01:24 +0200 | [diff] [blame] | 804 | |
| 805 | state->seat_destroy_listener.notify = focus_state_seat_destroy; |
| 806 | state->surface_destroy_listener.notify = focus_state_surface_destroy; |
Kristian Høgsberg | 4912454 | 2013-05-06 22:27:40 -0400 | [diff] [blame] | 807 | wl_signal_add(&seat->destroy_signal, |
Jonas Ådahl | 0476974 | 2012-06-13 00:01:24 +0200 | [diff] [blame] | 808 | &state->seat_destroy_listener); |
Kristian Høgsberg | 2f5faff | 2012-07-31 16:36:34 -0400 | [diff] [blame] | 809 | wl_list_init(&state->surface_destroy_listener.link); |
Jonas Ådahl | 0476974 | 2012-06-13 00:01:24 +0200 | [diff] [blame] | 810 | |
| 811 | return state; |
| 812 | } |
| 813 | |
Jonas Ådahl | 8538b22 | 2012-08-29 22:13:03 +0200 | [diff] [blame] | 814 | static struct focus_state * |
| 815 | ensure_focus_state(struct desktop_shell *shell, struct weston_seat *seat) |
| 816 | { |
| 817 | struct workspace *ws = get_current_workspace(shell); |
| 818 | struct focus_state *state; |
| 819 | |
| 820 | wl_list_for_each(state, &ws->focus_list, link) |
| 821 | if (state->seat == seat) |
| 822 | break; |
| 823 | |
| 824 | if (&state->link == &ws->focus_list) |
| 825 | state = focus_state_create(seat, ws); |
| 826 | |
| 827 | return state; |
| 828 | } |
| 829 | |
Jonas Ådahl | 0476974 | 2012-06-13 00:01:24 +0200 | [diff] [blame] | 830 | static void |
Kristian Høgsberg | d500bf1 | 2014-01-22 12:25:20 -0800 | [diff] [blame] | 831 | focus_state_set_focus(struct focus_state *state, |
| 832 | struct weston_surface *surface) |
| 833 | { |
| 834 | if (state->keyboard_focus) { |
| 835 | wl_list_remove(&state->surface_destroy_listener.link); |
| 836 | wl_list_init(&state->surface_destroy_listener.link); |
| 837 | } |
| 838 | |
| 839 | state->keyboard_focus = surface; |
| 840 | if (surface) |
| 841 | wl_signal_add(&surface->destroy_signal, |
| 842 | &state->surface_destroy_listener); |
| 843 | } |
| 844 | |
| 845 | static void |
Kristian Høgsberg | 2f5faff | 2012-07-31 16:36:34 -0400 | [diff] [blame] | 846 | restore_focus_state(struct desktop_shell *shell, struct workspace *ws) |
Jonas Ådahl | 0476974 | 2012-06-13 00:01:24 +0200 | [diff] [blame] | 847 | { |
| 848 | struct focus_state *state, *next; |
Kristian Høgsberg | fe7aa90 | 2013-05-08 09:54:37 -0400 | [diff] [blame] | 849 | struct weston_surface *surface; |
Neil Roberts | 4237f50 | 2014-04-09 16:33:31 +0100 | [diff] [blame] | 850 | struct wl_list pending_seat_list; |
| 851 | struct weston_seat *seat, *next_seat; |
| 852 | |
| 853 | /* Temporarily steal the list of seats so that we can keep |
| 854 | * track of the seats we've already processed */ |
| 855 | wl_list_init(&pending_seat_list); |
| 856 | wl_list_insert_list(&pending_seat_list, &shell->compositor->seat_list); |
| 857 | wl_list_init(&shell->compositor->seat_list); |
Jonas Ådahl | 0476974 | 2012-06-13 00:01:24 +0200 | [diff] [blame] | 858 | |
| 859 | wl_list_for_each_safe(state, next, &ws->focus_list, link) { |
Neil Roberts | 4237f50 | 2014-04-09 16:33:31 +0100 | [diff] [blame] | 860 | wl_list_remove(&state->seat->link); |
| 861 | wl_list_insert(&shell->compositor->seat_list, |
| 862 | &state->seat->link); |
| 863 | |
Kristian Høgsberg | e61d2f4 | 2014-01-17 12:18:53 -0800 | [diff] [blame] | 864 | if (state->seat->keyboard == NULL) |
| 865 | continue; |
| 866 | |
Kristian Høgsberg | fe7aa90 | 2013-05-08 09:54:37 -0400 | [diff] [blame] | 867 | surface = state->keyboard_focus; |
Jonas Ådahl | 5689944 | 2012-08-29 22:12:59 +0200 | [diff] [blame] | 868 | |
Kristian Høgsberg | e314875 | 2013-05-06 23:19:49 -0400 | [diff] [blame] | 869 | weston_keyboard_set_focus(state->seat->keyboard, surface); |
Jonas Ådahl | 0476974 | 2012-06-13 00:01:24 +0200 | [diff] [blame] | 870 | } |
Neil Roberts | 4237f50 | 2014-04-09 16:33:31 +0100 | [diff] [blame] | 871 | |
| 872 | /* For any remaining seats that we don't have a focus state |
| 873 | * for we'll reset the keyboard focus to NULL */ |
| 874 | wl_list_for_each_safe(seat, next_seat, &pending_seat_list, link) { |
| 875 | wl_list_insert(&shell->compositor->seat_list, &seat->link); |
| 876 | |
Ander Conselvan de Oliveira | 6e56ab4 | 2014-05-07 11:57:28 +0300 | [diff] [blame] | 877 | if (seat->keyboard == NULL) |
Neil Roberts | 4237f50 | 2014-04-09 16:33:31 +0100 | [diff] [blame] | 878 | continue; |
| 879 | |
| 880 | weston_keyboard_set_focus(seat->keyboard, NULL); |
| 881 | } |
Jonas Ådahl | 0476974 | 2012-06-13 00:01:24 +0200 | [diff] [blame] | 882 | } |
| 883 | |
| 884 | static void |
Jonas Ådahl | 8de6a1d | 2012-08-29 22:13:00 +0200 | [diff] [blame] | 885 | replace_focus_state(struct desktop_shell *shell, struct workspace *ws, |
| 886 | struct weston_seat *seat) |
| 887 | { |
| 888 | struct focus_state *state; |
Jonas Ådahl | 8de6a1d | 2012-08-29 22:13:00 +0200 | [diff] [blame] | 889 | |
| 890 | wl_list_for_each(state, &ws->focus_list, link) { |
| 891 | if (state->seat == seat) { |
Kristian Høgsberg | d500bf1 | 2014-01-22 12:25:20 -0800 | [diff] [blame] | 892 | focus_state_set_focus(state, seat->keyboard->focus); |
Jonas Ådahl | 8de6a1d | 2012-08-29 22:13:00 +0200 | [diff] [blame] | 893 | return; |
| 894 | } |
| 895 | } |
| 896 | } |
| 897 | |
| 898 | static void |
| 899 | drop_focus_state(struct desktop_shell *shell, struct workspace *ws, |
| 900 | struct weston_surface *surface) |
| 901 | { |
| 902 | struct focus_state *state; |
| 903 | |
| 904 | wl_list_for_each(state, &ws->focus_list, link) |
| 905 | if (state->keyboard_focus == surface) |
Kristian Høgsberg | d500bf1 | 2014-01-22 12:25:20 -0800 | [diff] [blame] | 906 | focus_state_set_focus(state, NULL); |
Jonas Ådahl | 8de6a1d | 2012-08-29 22:13:00 +0200 | [diff] [blame] | 907 | } |
| 908 | |
| 909 | static void |
Louis-Francis Ratté-Boulianne | b482dbd | 2013-11-19 11:37:11 +0100 | [diff] [blame] | 910 | animate_focus_change(struct desktop_shell *shell, struct workspace *ws, |
| 911 | struct weston_view *from, struct weston_view *to) |
| 912 | { |
| 913 | struct weston_output *output; |
| 914 | bool focus_surface_created = false; |
| 915 | |
| 916 | /* FIXME: Only support dim animation using two layers */ |
| 917 | if (from == to || shell->focus_animation_type != ANIMATION_DIM_LAYER) |
| 918 | return; |
| 919 | |
| 920 | output = get_default_output(shell->compositor); |
| 921 | if (ws->fsurf_front == NULL && (from || to)) { |
| 922 | ws->fsurf_front = create_focus_surface(shell->compositor, output); |
U. Artie Eoff | 0b23b2b | 2014-01-15 14:45:59 -0800 | [diff] [blame] | 923 | if (ws->fsurf_front == NULL) |
| 924 | return; |
Louis-Francis Ratté-Boulianne | b482dbd | 2013-11-19 11:37:11 +0100 | [diff] [blame] | 925 | ws->fsurf_front->view->alpha = 0.0; |
U. Artie Eoff | 0b23b2b | 2014-01-15 14:45:59 -0800 | [diff] [blame] | 926 | |
| 927 | ws->fsurf_back = create_focus_surface(shell->compositor, output); |
| 928 | if (ws->fsurf_back == NULL) { |
| 929 | focus_surface_destroy(ws->fsurf_front); |
| 930 | return; |
| 931 | } |
Louis-Francis Ratté-Boulianne | b482dbd | 2013-11-19 11:37:11 +0100 | [diff] [blame] | 932 | ws->fsurf_back->view->alpha = 0.0; |
U. Artie Eoff | 0b23b2b | 2014-01-15 14:45:59 -0800 | [diff] [blame] | 933 | |
Louis-Francis Ratté-Boulianne | b482dbd | 2013-11-19 11:37:11 +0100 | [diff] [blame] | 934 | focus_surface_created = true; |
| 935 | } else { |
Giulio Camuffo | 412e6a5 | 2014-07-09 22:12:56 +0300 | [diff] [blame] | 936 | weston_layer_entry_remove(&ws->fsurf_front->view->layer_link); |
| 937 | weston_layer_entry_remove(&ws->fsurf_back->view->layer_link); |
Louis-Francis Ratté-Boulianne | b482dbd | 2013-11-19 11:37:11 +0100 | [diff] [blame] | 938 | } |
| 939 | |
| 940 | if (ws->focus_animation) { |
| 941 | weston_view_animation_destroy(ws->focus_animation); |
| 942 | ws->focus_animation = NULL; |
| 943 | } |
| 944 | |
| 945 | if (to) |
Giulio Camuffo | 412e6a5 | 2014-07-09 22:12:56 +0300 | [diff] [blame] | 946 | weston_layer_entry_insert(&to->layer_link, |
| 947 | &ws->fsurf_front->view->layer_link); |
Louis-Francis Ratté-Boulianne | b482dbd | 2013-11-19 11:37:11 +0100 | [diff] [blame] | 948 | else if (from) |
Giulio Camuffo | 412e6a5 | 2014-07-09 22:12:56 +0300 | [diff] [blame] | 949 | weston_layer_entry_insert(&ws->layer.view_list, |
| 950 | &ws->fsurf_front->view->layer_link); |
Louis-Francis Ratté-Boulianne | b482dbd | 2013-11-19 11:37:11 +0100 | [diff] [blame] | 951 | |
| 952 | if (focus_surface_created) { |
| 953 | ws->focus_animation = weston_fade_run( |
| 954 | ws->fsurf_front->view, |
Jonny Lamb | 7e7d485 | 2014-05-22 22:41:34 +0200 | [diff] [blame] | 955 | ws->fsurf_front->view->alpha, 0.4, 300, |
Louis-Francis Ratté-Boulianne | b482dbd | 2013-11-19 11:37:11 +0100 | [diff] [blame] | 956 | focus_animation_done, ws); |
| 957 | } else if (from) { |
Giulio Camuffo | 412e6a5 | 2014-07-09 22:12:56 +0300 | [diff] [blame] | 958 | weston_layer_entry_insert(&from->layer_link, |
| 959 | &ws->fsurf_back->view->layer_link); |
Louis-Francis Ratté-Boulianne | b482dbd | 2013-11-19 11:37:11 +0100 | [diff] [blame] | 960 | ws->focus_animation = weston_stable_fade_run( |
| 961 | ws->fsurf_front->view, 0.0, |
Jonny Lamb | 7e7d485 | 2014-05-22 22:41:34 +0200 | [diff] [blame] | 962 | ws->fsurf_back->view, 0.4, |
Louis-Francis Ratté-Boulianne | b482dbd | 2013-11-19 11:37:11 +0100 | [diff] [blame] | 963 | focus_animation_done, ws); |
| 964 | } else if (to) { |
Giulio Camuffo | 412e6a5 | 2014-07-09 22:12:56 +0300 | [diff] [blame] | 965 | weston_layer_entry_insert(&ws->layer.view_list, |
| 966 | &ws->fsurf_back->view->layer_link); |
Louis-Francis Ratté-Boulianne | b482dbd | 2013-11-19 11:37:11 +0100 | [diff] [blame] | 967 | ws->focus_animation = weston_stable_fade_run( |
| 968 | ws->fsurf_front->view, 0.0, |
Jonny Lamb | 7e7d485 | 2014-05-22 22:41:34 +0200 | [diff] [blame] | 969 | ws->fsurf_back->view, 0.4, |
Louis-Francis Ratté-Boulianne | b482dbd | 2013-11-19 11:37:11 +0100 | [diff] [blame] | 970 | focus_animation_done, ws); |
| 971 | } |
| 972 | } |
| 973 | |
| 974 | static void |
Jonas Ådahl | e3cddce | 2012-06-13 00:01:22 +0200 | [diff] [blame] | 975 | workspace_destroy(struct workspace *ws) |
| 976 | { |
Jonas Ådahl | 0476974 | 2012-06-13 00:01:24 +0200 | [diff] [blame] | 977 | struct focus_state *state, *next; |
| 978 | |
| 979 | wl_list_for_each_safe(state, next, &ws->focus_list, link) |
| 980 | focus_state_destroy(state); |
| 981 | |
Louis-Francis Ratté-Boulianne | b482dbd | 2013-11-19 11:37:11 +0100 | [diff] [blame] | 982 | if (ws->fsurf_front) |
| 983 | focus_surface_destroy(ws->fsurf_front); |
| 984 | if (ws->fsurf_back) |
| 985 | focus_surface_destroy(ws->fsurf_back); |
| 986 | |
Jonas Ådahl | e3cddce | 2012-06-13 00:01:22 +0200 | [diff] [blame] | 987 | free(ws); |
| 988 | } |
| 989 | |
Jonas Ådahl | 0476974 | 2012-06-13 00:01:24 +0200 | [diff] [blame] | 990 | static void |
| 991 | seat_destroyed(struct wl_listener *listener, void *data) |
| 992 | { |
| 993 | struct weston_seat *seat = data; |
| 994 | struct focus_state *state, *next; |
| 995 | struct workspace *ws = container_of(listener, |
| 996 | struct workspace, |
| 997 | seat_destroyed_listener); |
| 998 | |
| 999 | wl_list_for_each_safe(state, next, &ws->focus_list, link) |
| 1000 | if (state->seat == seat) |
| 1001 | wl_list_remove(&state->link); |
| 1002 | } |
| 1003 | |
Jonas Ådahl | e3cddce | 2012-06-13 00:01:22 +0200 | [diff] [blame] | 1004 | static struct workspace * |
| 1005 | workspace_create(void) |
| 1006 | { |
| 1007 | struct workspace *ws = malloc(sizeof *ws); |
| 1008 | if (ws == NULL) |
| 1009 | return NULL; |
| 1010 | |
| 1011 | weston_layer_init(&ws->layer, NULL); |
| 1012 | |
Jonas Ådahl | 0476974 | 2012-06-13 00:01:24 +0200 | [diff] [blame] | 1013 | wl_list_init(&ws->focus_list); |
| 1014 | wl_list_init(&ws->seat_destroyed_listener.link); |
| 1015 | ws->seat_destroyed_listener.notify = seat_destroyed; |
Louis-Francis Ratté-Boulianne | b482dbd | 2013-11-19 11:37:11 +0100 | [diff] [blame] | 1016 | ws->fsurf_front = NULL; |
| 1017 | ws->fsurf_back = NULL; |
| 1018 | ws->focus_animation = NULL; |
Jonas Ådahl | 0476974 | 2012-06-13 00:01:24 +0200 | [diff] [blame] | 1019 | |
Jonas Ådahl | e3cddce | 2012-06-13 00:01:22 +0200 | [diff] [blame] | 1020 | return ws; |
| 1021 | } |
| 1022 | |
Jonas Ådahl | 62fcd04 | 2012-06-13 00:01:23 +0200 | [diff] [blame] | 1023 | static int |
| 1024 | workspace_is_empty(struct workspace *ws) |
| 1025 | { |
Giulio Camuffo | 412e6a5 | 2014-07-09 22:12:56 +0300 | [diff] [blame] | 1026 | return wl_list_empty(&ws->layer.view_list.link); |
Jonas Ådahl | 62fcd04 | 2012-06-13 00:01:23 +0200 | [diff] [blame] | 1027 | } |
| 1028 | |
Jonas Ådahl | e3cddce | 2012-06-13 00:01:22 +0200 | [diff] [blame] | 1029 | static struct workspace * |
| 1030 | get_workspace(struct desktop_shell *shell, unsigned int index) |
| 1031 | { |
| 1032 | struct workspace **pws = shell->workspaces.array.data; |
Philipp Brüschweiler | 067abf6 | 2012-09-01 16:03:05 +0200 | [diff] [blame] | 1033 | assert(index < shell->workspaces.num); |
Jonas Ådahl | e3cddce | 2012-06-13 00:01:22 +0200 | [diff] [blame] | 1034 | pws += index; |
| 1035 | return *pws; |
| 1036 | } |
| 1037 | |
Kristian Høgsberg | 1ef2313 | 2013-12-04 00:20:01 -0800 | [diff] [blame] | 1038 | struct workspace * |
Jonas Ådahl | e3cddce | 2012-06-13 00:01:22 +0200 | [diff] [blame] | 1039 | get_current_workspace(struct desktop_shell *shell) |
| 1040 | { |
| 1041 | return get_workspace(shell, shell->workspaces.current); |
| 1042 | } |
| 1043 | |
| 1044 | static void |
| 1045 | activate_workspace(struct desktop_shell *shell, unsigned int index) |
| 1046 | { |
| 1047 | struct workspace *ws; |
| 1048 | |
| 1049 | ws = get_workspace(shell, index); |
| 1050 | wl_list_insert(&shell->panel_layer.link, &ws->layer.link); |
| 1051 | |
| 1052 | shell->workspaces.current = index; |
| 1053 | } |
| 1054 | |
Jonas Ådahl | 62fcd04 | 2012-06-13 00:01:23 +0200 | [diff] [blame] | 1055 | static unsigned int |
| 1056 | get_output_height(struct weston_output *output) |
| 1057 | { |
| 1058 | return abs(output->region.extents.y1 - output->region.extents.y2); |
| 1059 | } |
| 1060 | |
| 1061 | static void |
Louis-Francis Ratté-Boulianne | b482dbd | 2013-11-19 11:37:11 +0100 | [diff] [blame] | 1062 | view_translate(struct workspace *ws, struct weston_view *view, double d) |
Jonas Ådahl | 62fcd04 | 2012-06-13 00:01:23 +0200 | [diff] [blame] | 1063 | { |
Jonas Ådahl | 62fcd04 | 2012-06-13 00:01:23 +0200 | [diff] [blame] | 1064 | struct weston_transform *transform; |
| 1065 | |
Louis-Francis Ratté-Boulianne | b482dbd | 2013-11-19 11:37:11 +0100 | [diff] [blame] | 1066 | if (is_focus_view(view)) { |
| 1067 | struct focus_surface *fsurf = get_focus_surface(view->surface); |
| 1068 | transform = &fsurf->workspace_transform; |
| 1069 | } else { |
| 1070 | struct shell_surface *shsurf = get_shell_surface(view->surface); |
| 1071 | transform = &shsurf->workspace_transform; |
| 1072 | } |
| 1073 | |
Jonas Ådahl | 62fcd04 | 2012-06-13 00:01:23 +0200 | [diff] [blame] | 1074 | if (wl_list_empty(&transform->link)) |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 1075 | wl_list_insert(view->geometry.transformation_list.prev, |
Louis-Francis Ratté-Boulianne | b482dbd | 2013-11-19 11:37:11 +0100 | [diff] [blame] | 1076 | &transform->link); |
Jonas Ådahl | 62fcd04 | 2012-06-13 00:01:23 +0200 | [diff] [blame] | 1077 | |
Louis-Francis Ratté-Boulianne | b482dbd | 2013-11-19 11:37:11 +0100 | [diff] [blame] | 1078 | weston_matrix_init(&transform->matrix); |
| 1079 | weston_matrix_translate(&transform->matrix, |
Jonas Ådahl | 62fcd04 | 2012-06-13 00:01:23 +0200 | [diff] [blame] | 1080 | 0.0, d, 0.0); |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 1081 | weston_view_geometry_dirty(view); |
Jonas Ådahl | 62fcd04 | 2012-06-13 00:01:23 +0200 | [diff] [blame] | 1082 | } |
| 1083 | |
| 1084 | static void |
| 1085 | workspace_translate_out(struct workspace *ws, double fraction) |
| 1086 | { |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 1087 | struct weston_view *view; |
Jonas Ådahl | 62fcd04 | 2012-06-13 00:01:23 +0200 | [diff] [blame] | 1088 | unsigned int height; |
| 1089 | double d; |
| 1090 | |
Giulio Camuffo | 412e6a5 | 2014-07-09 22:12:56 +0300 | [diff] [blame] | 1091 | 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] | 1092 | height = get_output_height(view->surface->output); |
Jonas Ådahl | 62fcd04 | 2012-06-13 00:01:23 +0200 | [diff] [blame] | 1093 | d = height * fraction; |
| 1094 | |
Louis-Francis Ratté-Boulianne | b482dbd | 2013-11-19 11:37:11 +0100 | [diff] [blame] | 1095 | view_translate(ws, view, d); |
Jonas Ådahl | 62fcd04 | 2012-06-13 00:01:23 +0200 | [diff] [blame] | 1096 | } |
| 1097 | } |
| 1098 | |
| 1099 | static void |
| 1100 | workspace_translate_in(struct workspace *ws, double fraction) |
| 1101 | { |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 1102 | struct weston_view *view; |
Jonas Ådahl | 62fcd04 | 2012-06-13 00:01:23 +0200 | [diff] [blame] | 1103 | unsigned int height; |
| 1104 | double d; |
| 1105 | |
Giulio Camuffo | 412e6a5 | 2014-07-09 22:12:56 +0300 | [diff] [blame] | 1106 | 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] | 1107 | height = get_output_height(view->surface->output); |
Jonas Ådahl | 62fcd04 | 2012-06-13 00:01:23 +0200 | [diff] [blame] | 1108 | |
| 1109 | if (fraction > 0) |
| 1110 | d = -(height - height * fraction); |
| 1111 | else |
| 1112 | d = height + height * fraction; |
| 1113 | |
Louis-Francis Ratté-Boulianne | b482dbd | 2013-11-19 11:37:11 +0100 | [diff] [blame] | 1114 | view_translate(ws, view, d); |
Jonas Ådahl | 62fcd04 | 2012-06-13 00:01:23 +0200 | [diff] [blame] | 1115 | } |
| 1116 | } |
| 1117 | |
| 1118 | static void |
Jonas Ådahl | e9d2250 | 2012-08-29 22:13:01 +0200 | [diff] [blame] | 1119 | broadcast_current_workspace_state(struct desktop_shell *shell) |
| 1120 | { |
Kristian Høgsberg | 2e3c396 | 2013-09-11 12:00:47 -0700 | [diff] [blame] | 1121 | struct wl_resource *resource; |
Jonas Ådahl | e9d2250 | 2012-08-29 22:13:01 +0200 | [diff] [blame] | 1122 | |
Kristian Høgsberg | 2e3c396 | 2013-09-11 12:00:47 -0700 | [diff] [blame] | 1123 | wl_resource_for_each(resource, &shell->workspaces.client_list) |
| 1124 | workspace_manager_send_state(resource, |
Jonas Ådahl | e9d2250 | 2012-08-29 22:13:01 +0200 | [diff] [blame] | 1125 | shell->workspaces.current, |
| 1126 | shell->workspaces.num); |
| 1127 | } |
| 1128 | |
| 1129 | static void |
Jonas Ådahl | 62fcd04 | 2012-06-13 00:01:23 +0200 | [diff] [blame] | 1130 | reverse_workspace_change_animation(struct desktop_shell *shell, |
| 1131 | unsigned int index, |
| 1132 | struct workspace *from, |
| 1133 | struct workspace *to) |
| 1134 | { |
| 1135 | shell->workspaces.current = index; |
| 1136 | |
| 1137 | shell->workspaces.anim_to = to; |
| 1138 | shell->workspaces.anim_from = from; |
| 1139 | shell->workspaces.anim_dir = -1 * shell->workspaces.anim_dir; |
| 1140 | shell->workspaces.anim_timestamp = 0; |
| 1141 | |
Scott Moreau | 4272e63 | 2012-08-13 09:58:41 -0600 | [diff] [blame] | 1142 | weston_compositor_schedule_repaint(shell->compositor); |
Jonas Ådahl | 62fcd04 | 2012-06-13 00:01:23 +0200 | [diff] [blame] | 1143 | } |
| 1144 | |
| 1145 | static void |
| 1146 | workspace_deactivate_transforms(struct workspace *ws) |
| 1147 | { |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 1148 | struct weston_view *view; |
Louis-Francis Ratté-Boulianne | b482dbd | 2013-11-19 11:37:11 +0100 | [diff] [blame] | 1149 | struct weston_transform *transform; |
Jonas Ådahl | 62fcd04 | 2012-06-13 00:01:23 +0200 | [diff] [blame] | 1150 | |
Giulio Camuffo | 412e6a5 | 2014-07-09 22:12:56 +0300 | [diff] [blame] | 1151 | 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] | 1152 | if (is_focus_view(view)) { |
| 1153 | struct focus_surface *fsurf = get_focus_surface(view->surface); |
| 1154 | transform = &fsurf->workspace_transform; |
| 1155 | } else { |
| 1156 | struct shell_surface *shsurf = get_shell_surface(view->surface); |
| 1157 | transform = &shsurf->workspace_transform; |
| 1158 | } |
| 1159 | |
| 1160 | if (!wl_list_empty(&transform->link)) { |
| 1161 | wl_list_remove(&transform->link); |
| 1162 | wl_list_init(&transform->link); |
Jonas Ådahl | 8de6a1d | 2012-08-29 22:13:00 +0200 | [diff] [blame] | 1163 | } |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 1164 | weston_view_geometry_dirty(view); |
Jonas Ådahl | 62fcd04 | 2012-06-13 00:01:23 +0200 | [diff] [blame] | 1165 | } |
| 1166 | } |
| 1167 | |
| 1168 | static void |
| 1169 | finish_workspace_change_animation(struct desktop_shell *shell, |
| 1170 | struct workspace *from, |
| 1171 | struct workspace *to) |
| 1172 | { |
Ander Conselvan de Oliveira | 9c6217e | 2014-05-07 11:57:26 +0300 | [diff] [blame] | 1173 | struct weston_view *view; |
| 1174 | |
Scott Moreau | 4272e63 | 2012-08-13 09:58:41 -0600 | [diff] [blame] | 1175 | weston_compositor_schedule_repaint(shell->compositor); |
Jonas Ådahl | 62fcd04 | 2012-06-13 00:01:23 +0200 | [diff] [blame] | 1176 | |
Ander Conselvan de Oliveira | 9c6217e | 2014-05-07 11:57:26 +0300 | [diff] [blame] | 1177 | /* Views that extend past the bottom of the output are still |
| 1178 | * visible after the workspace animation ends but before its layer |
| 1179 | * is hidden. In that case, we need to damage below those views so |
| 1180 | * that the screen is properly repainted. */ |
Giulio Camuffo | 412e6a5 | 2014-07-09 22:12:56 +0300 | [diff] [blame] | 1181 | 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] | 1182 | weston_view_damage_below(view); |
| 1183 | |
Jonas Ådahl | 62fcd04 | 2012-06-13 00:01:23 +0200 | [diff] [blame] | 1184 | wl_list_remove(&shell->workspaces.animation.link); |
| 1185 | workspace_deactivate_transforms(from); |
| 1186 | workspace_deactivate_transforms(to); |
| 1187 | shell->workspaces.anim_to = NULL; |
| 1188 | |
| 1189 | wl_list_remove(&shell->workspaces.anim_from->layer.link); |
| 1190 | } |
| 1191 | |
| 1192 | static void |
| 1193 | animate_workspace_change_frame(struct weston_animation *animation, |
| 1194 | struct weston_output *output, uint32_t msecs) |
| 1195 | { |
| 1196 | struct desktop_shell *shell = |
| 1197 | container_of(animation, struct desktop_shell, |
| 1198 | workspaces.animation); |
| 1199 | struct workspace *from = shell->workspaces.anim_from; |
| 1200 | struct workspace *to = shell->workspaces.anim_to; |
| 1201 | uint32_t t; |
| 1202 | double x, y; |
| 1203 | |
| 1204 | if (workspace_is_empty(from) && workspace_is_empty(to)) { |
| 1205 | finish_workspace_change_animation(shell, from, to); |
| 1206 | return; |
| 1207 | } |
| 1208 | |
| 1209 | if (shell->workspaces.anim_timestamp == 0) { |
| 1210 | if (shell->workspaces.anim_current == 0.0) |
| 1211 | shell->workspaces.anim_timestamp = msecs; |
| 1212 | else |
| 1213 | shell->workspaces.anim_timestamp = |
| 1214 | msecs - |
| 1215 | /* Invers of movement function 'y' below. */ |
| 1216 | (asin(1.0 - shell->workspaces.anim_current) * |
| 1217 | DEFAULT_WORKSPACE_CHANGE_ANIMATION_LENGTH * |
| 1218 | M_2_PI); |
| 1219 | } |
| 1220 | |
| 1221 | t = msecs - shell->workspaces.anim_timestamp; |
| 1222 | |
| 1223 | /* |
| 1224 | * x = [0, π/2] |
| 1225 | * y(x) = sin(x) |
| 1226 | */ |
| 1227 | x = t * (1.0/DEFAULT_WORKSPACE_CHANGE_ANIMATION_LENGTH) * M_PI_2; |
| 1228 | y = sin(x); |
| 1229 | |
| 1230 | if (t < DEFAULT_WORKSPACE_CHANGE_ANIMATION_LENGTH) { |
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 | |
| 1233 | workspace_translate_out(from, shell->workspaces.anim_dir * y); |
| 1234 | workspace_translate_in(to, shell->workspaces.anim_dir * y); |
| 1235 | shell->workspaces.anim_current = y; |
| 1236 | |
Scott Moreau | 4272e63 | 2012-08-13 09:58:41 -0600 | [diff] [blame] | 1237 | weston_compositor_schedule_repaint(shell->compositor); |
Jonas Ådahl | 62fcd04 | 2012-06-13 00:01:23 +0200 | [diff] [blame] | 1238 | } |
Jonas Ådahl | 0476974 | 2012-06-13 00:01:24 +0200 | [diff] [blame] | 1239 | else |
Jonas Ådahl | 62fcd04 | 2012-06-13 00:01:23 +0200 | [diff] [blame] | 1240 | finish_workspace_change_animation(shell, from, to); |
Jonas Ådahl | 62fcd04 | 2012-06-13 00:01:23 +0200 | [diff] [blame] | 1241 | } |
| 1242 | |
| 1243 | static void |
| 1244 | animate_workspace_change(struct desktop_shell *shell, |
| 1245 | unsigned int index, |
| 1246 | struct workspace *from, |
| 1247 | struct workspace *to) |
| 1248 | { |
| 1249 | struct weston_output *output; |
| 1250 | |
| 1251 | int dir; |
| 1252 | |
| 1253 | if (index > shell->workspaces.current) |
| 1254 | dir = -1; |
| 1255 | else |
| 1256 | dir = 1; |
| 1257 | |
| 1258 | shell->workspaces.current = index; |
| 1259 | |
| 1260 | shell->workspaces.anim_dir = dir; |
| 1261 | shell->workspaces.anim_from = from; |
| 1262 | shell->workspaces.anim_to = to; |
| 1263 | shell->workspaces.anim_current = 0.0; |
| 1264 | shell->workspaces.anim_timestamp = 0; |
| 1265 | |
| 1266 | output = container_of(shell->compositor->output_list.next, |
| 1267 | struct weston_output, link); |
| 1268 | wl_list_insert(&output->animation_list, |
| 1269 | &shell->workspaces.animation.link); |
| 1270 | |
Jonas Ådahl | 8de6a1d | 2012-08-29 22:13:00 +0200 | [diff] [blame] | 1271 | wl_list_insert(from->layer.link.prev, &to->layer.link); |
Jonas Ådahl | 62fcd04 | 2012-06-13 00:01:23 +0200 | [diff] [blame] | 1272 | |
| 1273 | workspace_translate_in(to, 0); |
| 1274 | |
Kristian Høgsberg | 2f5faff | 2012-07-31 16:36:34 -0400 | [diff] [blame] | 1275 | restore_focus_state(shell, to); |
Jonas Ådahl | 0476974 | 2012-06-13 00:01:24 +0200 | [diff] [blame] | 1276 | |
Scott Moreau | 4272e63 | 2012-08-13 09:58:41 -0600 | [diff] [blame] | 1277 | weston_compositor_schedule_repaint(shell->compositor); |
Jonas Ådahl | 62fcd04 | 2012-06-13 00:01:23 +0200 | [diff] [blame] | 1278 | } |
| 1279 | |
Jonas Ådahl | e3cddce | 2012-06-13 00:01:22 +0200 | [diff] [blame] | 1280 | static void |
Jonas Ådahl | 8de6a1d | 2012-08-29 22:13:00 +0200 | [diff] [blame] | 1281 | update_workspace(struct desktop_shell *shell, unsigned int index, |
| 1282 | struct workspace *from, struct workspace *to) |
| 1283 | { |
| 1284 | shell->workspaces.current = index; |
| 1285 | wl_list_insert(&from->layer.link, &to->layer.link); |
| 1286 | wl_list_remove(&from->layer.link); |
| 1287 | } |
| 1288 | |
| 1289 | static void |
Jonas Ådahl | e3cddce | 2012-06-13 00:01:22 +0200 | [diff] [blame] | 1290 | change_workspace(struct desktop_shell *shell, unsigned int index) |
| 1291 | { |
| 1292 | struct workspace *from; |
| 1293 | struct workspace *to; |
Louis-Francis Ratté-Boulianne | b482dbd | 2013-11-19 11:37:11 +0100 | [diff] [blame] | 1294 | struct focus_state *state; |
Jonas Ådahl | e3cddce | 2012-06-13 00:01:22 +0200 | [diff] [blame] | 1295 | |
| 1296 | if (index == shell->workspaces.current) |
| 1297 | return; |
| 1298 | |
| 1299 | /* Don't change workspace when there is any fullscreen surfaces. */ |
Giulio Camuffo | 412e6a5 | 2014-07-09 22:12:56 +0300 | [diff] [blame] | 1300 | if (!wl_list_empty(&shell->fullscreen_layer.view_list.link)) |
Jonas Ådahl | e3cddce | 2012-06-13 00:01:22 +0200 | [diff] [blame] | 1301 | return; |
| 1302 | |
Jonas Ådahl | e3cddce | 2012-06-13 00:01:22 +0200 | [diff] [blame] | 1303 | from = get_current_workspace(shell); |
| 1304 | to = get_workspace(shell, index); |
| 1305 | |
Jonas Ådahl | 62fcd04 | 2012-06-13 00:01:23 +0200 | [diff] [blame] | 1306 | if (shell->workspaces.anim_from == to && |
| 1307 | shell->workspaces.anim_to == from) { |
Jonas Ådahl | 8de6a1d | 2012-08-29 22:13:00 +0200 | [diff] [blame] | 1308 | restore_focus_state(shell, to); |
Jonas Ådahl | 62fcd04 | 2012-06-13 00:01:23 +0200 | [diff] [blame] | 1309 | reverse_workspace_change_animation(shell, index, from, to); |
Jonas Ådahl | e9d2250 | 2012-08-29 22:13:01 +0200 | [diff] [blame] | 1310 | broadcast_current_workspace_state(shell); |
Jonas Ådahl | 62fcd04 | 2012-06-13 00:01:23 +0200 | [diff] [blame] | 1311 | return; |
| 1312 | } |
Jonas Ådahl | e3cddce | 2012-06-13 00:01:22 +0200 | [diff] [blame] | 1313 | |
Jonas Ådahl | 62fcd04 | 2012-06-13 00:01:23 +0200 | [diff] [blame] | 1314 | if (shell->workspaces.anim_to != NULL) |
| 1315 | finish_workspace_change_animation(shell, |
| 1316 | shell->workspaces.anim_from, |
| 1317 | shell->workspaces.anim_to); |
| 1318 | |
Jonas Ådahl | 8de6a1d | 2012-08-29 22:13:00 +0200 | [diff] [blame] | 1319 | restore_focus_state(shell, to); |
Jonas Ådahl | 0476974 | 2012-06-13 00:01:24 +0200 | [diff] [blame] | 1320 | |
Louis-Francis Ratté-Boulianne | b482dbd | 2013-11-19 11:37:11 +0100 | [diff] [blame] | 1321 | if (shell->focus_animation_type != ANIMATION_NONE) { |
| 1322 | wl_list_for_each(state, &from->focus_list, link) |
| 1323 | if (state->keyboard_focus) |
| 1324 | animate_focus_change(shell, from, |
| 1325 | get_default_view(state->keyboard_focus), NULL); |
| 1326 | |
| 1327 | wl_list_for_each(state, &to->focus_list, link) |
| 1328 | if (state->keyboard_focus) |
| 1329 | animate_focus_change(shell, to, |
| 1330 | NULL, get_default_view(state->keyboard_focus)); |
| 1331 | } |
| 1332 | |
Jonas Ådahl | 8de6a1d | 2012-08-29 22:13:00 +0200 | [diff] [blame] | 1333 | if (workspace_is_empty(to) && workspace_is_empty(from)) |
| 1334 | update_workspace(shell, index, from, to); |
Jonas Ådahl | 62fcd04 | 2012-06-13 00:01:23 +0200 | [diff] [blame] | 1335 | else |
| 1336 | animate_workspace_change(shell, index, from, to); |
Jonas Ådahl | e9d2250 | 2012-08-29 22:13:01 +0200 | [diff] [blame] | 1337 | |
| 1338 | broadcast_current_workspace_state(shell); |
Pekka Paalanen | e955f1e | 2011-12-07 11:49:52 +0200 | [diff] [blame] | 1339 | } |
| 1340 | |
Jonas Ådahl | 8de6a1d | 2012-08-29 22:13:00 +0200 | [diff] [blame] | 1341 | static bool |
| 1342 | workspace_has_only(struct workspace *ws, struct weston_surface *surface) |
| 1343 | { |
Giulio Camuffo | 412e6a5 | 2014-07-09 22:12:56 +0300 | [diff] [blame] | 1344 | struct wl_list *list = &ws->layer.view_list.link; |
Jonas Ådahl | 8de6a1d | 2012-08-29 22:13:00 +0200 | [diff] [blame] | 1345 | struct wl_list *e; |
| 1346 | |
| 1347 | if (wl_list_empty(list)) |
| 1348 | return false; |
| 1349 | |
| 1350 | e = list->next; |
| 1351 | |
| 1352 | if (e->next != list) |
| 1353 | return false; |
| 1354 | |
Giulio Camuffo | 412e6a5 | 2014-07-09 22:12:56 +0300 | [diff] [blame] | 1355 | return container_of(e, struct weston_view, layer_link.link)->surface == surface; |
Jonas Ådahl | 8de6a1d | 2012-08-29 22:13:00 +0200 | [diff] [blame] | 1356 | } |
| 1357 | |
| 1358 | static void |
Philip Withnall | 659163d | 2013-11-25 18:01:36 +0000 | [diff] [blame] | 1359 | move_surface_to_workspace(struct desktop_shell *shell, |
| 1360 | struct shell_surface *shsurf, |
| 1361 | uint32_t workspace) |
Jonas Ådahl | e9d2250 | 2012-08-29 22:13:01 +0200 | [diff] [blame] | 1362 | { |
| 1363 | struct workspace *from; |
| 1364 | struct workspace *to; |
| 1365 | struct weston_seat *seat; |
Pekka Paalanen | 01388e2 | 2013-04-25 13:57:44 +0300 | [diff] [blame] | 1366 | struct weston_surface *focus; |
Philip Withnall | 659163d | 2013-11-25 18:01:36 +0000 | [diff] [blame] | 1367 | struct weston_view *view; |
Jonas Ådahl | e9d2250 | 2012-08-29 22:13:01 +0200 | [diff] [blame] | 1368 | |
| 1369 | if (workspace == shell->workspaces.current) |
| 1370 | return; |
| 1371 | |
Philip Withnall | 659163d | 2013-11-25 18:01:36 +0000 | [diff] [blame] | 1372 | view = get_default_view(shsurf->surface); |
| 1373 | if (!view) |
| 1374 | return; |
| 1375 | |
| 1376 | assert(weston_surface_get_main_surface(view->surface) == view->surface); |
| 1377 | |
Philipp Brüschweiler | 067abf6 | 2012-09-01 16:03:05 +0200 | [diff] [blame] | 1378 | if (workspace >= shell->workspaces.num) |
| 1379 | workspace = shell->workspaces.num - 1; |
| 1380 | |
Jonas Ådahl | e9d2250 | 2012-08-29 22:13:01 +0200 | [diff] [blame] | 1381 | from = get_current_workspace(shell); |
| 1382 | to = get_workspace(shell, workspace); |
| 1383 | |
Giulio Camuffo | 412e6a5 | 2014-07-09 22:12:56 +0300 | [diff] [blame] | 1384 | weston_layer_entry_remove(&view->layer_link); |
| 1385 | weston_layer_entry_insert(&to->layer.view_list, &view->layer_link); |
Jonas Ådahl | e9d2250 | 2012-08-29 22:13:01 +0200 | [diff] [blame] | 1386 | |
Philip Withnall | 648a4dd | 2013-11-25 18:01:44 +0000 | [diff] [blame] | 1387 | shell_surface_update_child_surface_layers(shsurf); |
| 1388 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 1389 | drop_focus_state(shell, from, view->surface); |
Pekka Paalanen | 01388e2 | 2013-04-25 13:57:44 +0300 | [diff] [blame] | 1390 | wl_list_for_each(seat, &shell->compositor->seat_list, link) { |
| 1391 | if (!seat->keyboard) |
| 1392 | continue; |
| 1393 | |
| 1394 | focus = weston_surface_get_main_surface(seat->keyboard->focus); |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 1395 | if (focus == view->surface) |
Kristian Høgsberg | e314875 | 2013-05-06 23:19:49 -0400 | [diff] [blame] | 1396 | weston_keyboard_set_focus(seat->keyboard, NULL); |
Pekka Paalanen | 01388e2 | 2013-04-25 13:57:44 +0300 | [diff] [blame] | 1397 | } |
Jonas Ådahl | e9d2250 | 2012-08-29 22:13:01 +0200 | [diff] [blame] | 1398 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 1399 | weston_view_damage_below(view); |
Jonas Ådahl | e9d2250 | 2012-08-29 22:13:01 +0200 | [diff] [blame] | 1400 | } |
| 1401 | |
| 1402 | static void |
Jonas Ådahl | 8de6a1d | 2012-08-29 22:13:00 +0200 | [diff] [blame] | 1403 | take_surface_to_workspace_by_seat(struct desktop_shell *shell, |
Kristian Høgsberg | e314875 | 2013-05-06 23:19:49 -0400 | [diff] [blame] | 1404 | struct weston_seat *seat, |
Jonas Ådahl | 8de6a1d | 2012-08-29 22:13:00 +0200 | [diff] [blame] | 1405 | unsigned int index) |
| 1406 | { |
Pekka Paalanen | 01388e2 | 2013-04-25 13:57:44 +0300 | [diff] [blame] | 1407 | struct weston_surface *surface; |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 1408 | struct weston_view *view; |
Jonas Ådahl | 8de6a1d | 2012-08-29 22:13:00 +0200 | [diff] [blame] | 1409 | struct shell_surface *shsurf; |
| 1410 | struct workspace *from; |
| 1411 | struct workspace *to; |
Jonas Ådahl | 8538b22 | 2012-08-29 22:13:03 +0200 | [diff] [blame] | 1412 | struct focus_state *state; |
Jonas Ådahl | 8de6a1d | 2012-08-29 22:13:00 +0200 | [diff] [blame] | 1413 | |
Pekka Paalanen | 01388e2 | 2013-04-25 13:57:44 +0300 | [diff] [blame] | 1414 | surface = weston_surface_get_main_surface(seat->keyboard->focus); |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 1415 | view = get_default_view(surface); |
| 1416 | if (view == NULL || |
Louis-Francis Ratté-Boulianne | b482dbd | 2013-11-19 11:37:11 +0100 | [diff] [blame] | 1417 | index == shell->workspaces.current || |
| 1418 | is_focus_view(view)) |
Jonas Ådahl | 8de6a1d | 2012-08-29 22:13:00 +0200 | [diff] [blame] | 1419 | return; |
| 1420 | |
| 1421 | from = get_current_workspace(shell); |
| 1422 | to = get_workspace(shell, index); |
| 1423 | |
Giulio Camuffo | 412e6a5 | 2014-07-09 22:12:56 +0300 | [diff] [blame] | 1424 | weston_layer_entry_remove(&view->layer_link); |
| 1425 | weston_layer_entry_insert(&to->layer.view_list, &view->layer_link); |
Jonas Ådahl | 8de6a1d | 2012-08-29 22:13:00 +0200 | [diff] [blame] | 1426 | |
Philip Withnall | 659163d | 2013-11-25 18:01:36 +0000 | [diff] [blame] | 1427 | shsurf = get_shell_surface(surface); |
Philip Withnall | 648a4dd | 2013-11-25 18:01:44 +0000 | [diff] [blame] | 1428 | if (shsurf != NULL) |
| 1429 | shell_surface_update_child_surface_layers(shsurf); |
Philip Withnall | 659163d | 2013-11-25 18:01:36 +0000 | [diff] [blame] | 1430 | |
Jonas Ådahl | e9d2250 | 2012-08-29 22:13:01 +0200 | [diff] [blame] | 1431 | replace_focus_state(shell, to, seat); |
Jonas Ådahl | 8de6a1d | 2012-08-29 22:13:00 +0200 | [diff] [blame] | 1432 | drop_focus_state(shell, from, surface); |
| 1433 | |
| 1434 | if (shell->workspaces.anim_from == to && |
| 1435 | shell->workspaces.anim_to == from) { |
Jonas Ådahl | e9d2250 | 2012-08-29 22:13:01 +0200 | [diff] [blame] | 1436 | wl_list_remove(&to->layer.link); |
| 1437 | wl_list_insert(from->layer.link.prev, &to->layer.link); |
| 1438 | |
Jonas Ådahl | 8de6a1d | 2012-08-29 22:13:00 +0200 | [diff] [blame] | 1439 | reverse_workspace_change_animation(shell, index, from, to); |
Jonas Ådahl | e9d2250 | 2012-08-29 22:13:01 +0200 | [diff] [blame] | 1440 | broadcast_current_workspace_state(shell); |
| 1441 | |
Jonas Ådahl | 8de6a1d | 2012-08-29 22:13:00 +0200 | [diff] [blame] | 1442 | return; |
| 1443 | } |
| 1444 | |
| 1445 | if (shell->workspaces.anim_to != NULL) |
| 1446 | finish_workspace_change_animation(shell, |
| 1447 | shell->workspaces.anim_from, |
| 1448 | shell->workspaces.anim_to); |
| 1449 | |
| 1450 | if (workspace_is_empty(from) && |
| 1451 | workspace_has_only(to, surface)) |
| 1452 | update_workspace(shell, index, from, to); |
| 1453 | else { |
Philip Withnall | 2c3849b | 2013-11-25 18:01:45 +0000 | [diff] [blame] | 1454 | if (shsurf != NULL && |
| 1455 | wl_list_empty(&shsurf->workspace_transform.link)) |
Jonas Ådahl | 8de6a1d | 2012-08-29 22:13:00 +0200 | [diff] [blame] | 1456 | wl_list_insert(&shell->workspaces.anim_sticky_list, |
| 1457 | &shsurf->workspace_transform.link); |
| 1458 | |
| 1459 | animate_workspace_change(shell, index, from, to); |
| 1460 | } |
Jonas Ådahl | e9d2250 | 2012-08-29 22:13:01 +0200 | [diff] [blame] | 1461 | |
| 1462 | broadcast_current_workspace_state(shell); |
Jonas Ådahl | 8538b22 | 2012-08-29 22:13:03 +0200 | [diff] [blame] | 1463 | |
| 1464 | state = ensure_focus_state(shell, seat); |
| 1465 | if (state != NULL) |
Kristian Høgsberg | d500bf1 | 2014-01-22 12:25:20 -0800 | [diff] [blame] | 1466 | focus_state_set_focus(state, surface); |
Jonas Ådahl | e9d2250 | 2012-08-29 22:13:01 +0200 | [diff] [blame] | 1467 | } |
| 1468 | |
| 1469 | static void |
| 1470 | workspace_manager_move_surface(struct wl_client *client, |
| 1471 | struct wl_resource *resource, |
| 1472 | struct wl_resource *surface_resource, |
| 1473 | uint32_t workspace) |
| 1474 | { |
Jason Ekstrand | 651f00e | 2013-06-14 10:07:54 -0500 | [diff] [blame] | 1475 | struct desktop_shell *shell = wl_resource_get_user_data(resource); |
Jonas Ådahl | e9d2250 | 2012-08-29 22:13:01 +0200 | [diff] [blame] | 1476 | struct weston_surface *surface = |
Jason Ekstrand | 0f2ef7e | 2013-06-14 10:07:53 -0500 | [diff] [blame] | 1477 | wl_resource_get_user_data(surface_resource); |
Pekka Paalanen | 01388e2 | 2013-04-25 13:57:44 +0300 | [diff] [blame] | 1478 | struct weston_surface *main_surface; |
Philip Withnall | 659163d | 2013-11-25 18:01:36 +0000 | [diff] [blame] | 1479 | struct shell_surface *shell_surface; |
Jonas Ådahl | e9d2250 | 2012-08-29 22:13:01 +0200 | [diff] [blame] | 1480 | |
Pekka Paalanen | 01388e2 | 2013-04-25 13:57:44 +0300 | [diff] [blame] | 1481 | main_surface = weston_surface_get_main_surface(surface); |
Philip Withnall | 659163d | 2013-11-25 18:01:36 +0000 | [diff] [blame] | 1482 | shell_surface = get_shell_surface(main_surface); |
| 1483 | if (shell_surface == NULL) |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 1484 | return; |
Philip Withnall | 659163d | 2013-11-25 18:01:36 +0000 | [diff] [blame] | 1485 | |
| 1486 | move_surface_to_workspace(shell, shell_surface, workspace); |
Jonas Ådahl | e9d2250 | 2012-08-29 22:13:01 +0200 | [diff] [blame] | 1487 | } |
| 1488 | |
| 1489 | static const struct workspace_manager_interface workspace_manager_implementation = { |
| 1490 | workspace_manager_move_surface, |
| 1491 | }; |
| 1492 | |
| 1493 | static void |
| 1494 | unbind_resource(struct wl_resource *resource) |
| 1495 | { |
Jason Ekstrand | 651f00e | 2013-06-14 10:07:54 -0500 | [diff] [blame] | 1496 | wl_list_remove(wl_resource_get_link(resource)); |
Jonas Ådahl | e9d2250 | 2012-08-29 22:13:01 +0200 | [diff] [blame] | 1497 | } |
| 1498 | |
| 1499 | static void |
| 1500 | bind_workspace_manager(struct wl_client *client, |
| 1501 | void *data, uint32_t version, uint32_t id) |
| 1502 | { |
| 1503 | struct desktop_shell *shell = data; |
| 1504 | struct wl_resource *resource; |
| 1505 | |
Jason Ekstrand | a85118c | 2013-06-27 20:17:02 -0500 | [diff] [blame] | 1506 | resource = wl_resource_create(client, |
| 1507 | &workspace_manager_interface, 1, id); |
Jonas Ådahl | e9d2250 | 2012-08-29 22:13:01 +0200 | [diff] [blame] | 1508 | |
| 1509 | if (resource == NULL) { |
| 1510 | weston_log("couldn't add workspace manager object"); |
| 1511 | return; |
| 1512 | } |
| 1513 | |
Jason Ekstrand | a85118c | 2013-06-27 20:17:02 -0500 | [diff] [blame] | 1514 | wl_resource_set_implementation(resource, |
| 1515 | &workspace_manager_implementation, |
| 1516 | shell, unbind_resource); |
Jason Ekstrand | 651f00e | 2013-06-14 10:07:54 -0500 | [diff] [blame] | 1517 | wl_list_insert(&shell->workspaces.client_list, |
| 1518 | wl_resource_get_link(resource)); |
Jonas Ådahl | e9d2250 | 2012-08-29 22:13:01 +0200 | [diff] [blame] | 1519 | |
| 1520 | workspace_manager_send_state(resource, |
| 1521 | shell->workspaces.current, |
| 1522 | shell->workspaces.num); |
Jonas Ådahl | 8de6a1d | 2012-08-29 22:13:00 +0200 | [diff] [blame] | 1523 | } |
| 1524 | |
Pekka Paalanen | 56cdea9 | 2011-11-23 16:14:12 +0200 | [diff] [blame] | 1525 | static void |
Rusty Lynch | 1084da5 | 2013-08-15 09:10:08 -0700 | [diff] [blame] | 1526 | touch_move_grab_down(struct weston_touch_grab *grab, uint32_t time, |
| 1527 | int touch_id, wl_fixed_t sx, wl_fixed_t sy) |
| 1528 | { |
| 1529 | } |
| 1530 | |
| 1531 | static void |
| 1532 | touch_move_grab_up(struct weston_touch_grab *grab, uint32_t time, int touch_id) |
| 1533 | { |
Jonas Ådahl | 1c6e63e | 2013-10-25 23:18:04 +0200 | [diff] [blame] | 1534 | struct weston_touch_move_grab *move = |
| 1535 | (struct weston_touch_move_grab *) container_of( |
| 1536 | grab, struct shell_touch_grab, grab); |
Neil Roberts | e14aa4f | 2013-10-03 16:43:07 +0100 | [diff] [blame] | 1537 | |
Kristian Høgsberg | 8e80a31 | 2014-01-17 15:18:10 -0800 | [diff] [blame] | 1538 | if (touch_id == 0) |
| 1539 | move->active = 0; |
| 1540 | |
Jonas Ådahl | 9484b69 | 2013-12-02 22:05:03 +0100 | [diff] [blame] | 1541 | if (grab->touch->num_tp == 0) { |
Jonas Ådahl | 1c6e63e | 2013-10-25 23:18:04 +0200 | [diff] [blame] | 1542 | shell_touch_grab_end(&move->base); |
| 1543 | free(move); |
| 1544 | } |
Rusty Lynch | 1084da5 | 2013-08-15 09:10:08 -0700 | [diff] [blame] | 1545 | } |
| 1546 | |
| 1547 | static void |
| 1548 | touch_move_grab_motion(struct weston_touch_grab *grab, uint32_t time, |
| 1549 | int touch_id, wl_fixed_t sx, wl_fixed_t sy) |
| 1550 | { |
| 1551 | struct weston_touch_move_grab *move = (struct weston_touch_move_grab *) grab; |
| 1552 | struct shell_surface *shsurf = move->base.shsurf; |
| 1553 | struct weston_surface *es; |
| 1554 | int dx = wl_fixed_to_int(grab->touch->grab_x + move->dx); |
| 1555 | int dy = wl_fixed_to_int(grab->touch->grab_y + move->dy); |
| 1556 | |
Kristian Høgsberg | 8e80a31 | 2014-01-17 15:18:10 -0800 | [diff] [blame] | 1557 | if (!shsurf || !move->active) |
Rusty Lynch | 1084da5 | 2013-08-15 09:10:08 -0700 | [diff] [blame] | 1558 | return; |
| 1559 | |
| 1560 | es = shsurf->surface; |
| 1561 | |
Jason Ekstrand | 918f2dd | 2013-12-02 21:01:53 -0600 | [diff] [blame] | 1562 | weston_view_set_position(shsurf->view, dx, dy); |
Rusty Lynch | 1084da5 | 2013-08-15 09:10:08 -0700 | [diff] [blame] | 1563 | |
| 1564 | weston_compositor_schedule_repaint(es->compositor); |
| 1565 | } |
| 1566 | |
Jonas Ådahl | 1ea343e | 2013-10-25 23:18:05 +0200 | [diff] [blame] | 1567 | static void |
Jonas Ådahl | 1679f23 | 2014-04-12 09:39:51 +0200 | [diff] [blame] | 1568 | touch_move_grab_frame(struct weston_touch_grab *grab) |
| 1569 | { |
| 1570 | } |
| 1571 | |
| 1572 | static void |
Jonas Ådahl | 1ea343e | 2013-10-25 23:18:05 +0200 | [diff] [blame] | 1573 | touch_move_grab_cancel(struct weston_touch_grab *grab) |
| 1574 | { |
| 1575 | struct weston_touch_move_grab *move = |
| 1576 | (struct weston_touch_move_grab *) container_of( |
| 1577 | grab, struct shell_touch_grab, grab); |
| 1578 | |
| 1579 | shell_touch_grab_end(&move->base); |
| 1580 | free(move); |
| 1581 | } |
| 1582 | |
Rusty Lynch | 1084da5 | 2013-08-15 09:10:08 -0700 | [diff] [blame] | 1583 | static const struct weston_touch_grab_interface touch_move_grab_interface = { |
| 1584 | touch_move_grab_down, |
| 1585 | touch_move_grab_up, |
| 1586 | touch_move_grab_motion, |
Jonas Ådahl | 1679f23 | 2014-04-12 09:39:51 +0200 | [diff] [blame] | 1587 | touch_move_grab_frame, |
Jonas Ådahl | 1ea343e | 2013-10-25 23:18:05 +0200 | [diff] [blame] | 1588 | touch_move_grab_cancel, |
Rusty Lynch | 1084da5 | 2013-08-15 09:10:08 -0700 | [diff] [blame] | 1589 | }; |
| 1590 | |
| 1591 | static int |
| 1592 | surface_touch_move(struct shell_surface *shsurf, struct weston_seat *seat) |
| 1593 | { |
| 1594 | struct weston_touch_move_grab *move; |
| 1595 | |
| 1596 | if (!shsurf) |
| 1597 | return -1; |
| 1598 | |
Ander Conselvan de Oliveira | 6d43f04 | 2014-05-07 14:22:23 +0300 | [diff] [blame] | 1599 | if (shsurf->state.fullscreen || shsurf->state.maximized) |
Rusty Lynch | 1084da5 | 2013-08-15 09:10:08 -0700 | [diff] [blame] | 1600 | return 0; |
| 1601 | |
| 1602 | move = malloc(sizeof *move); |
| 1603 | if (!move) |
| 1604 | return -1; |
| 1605 | |
Kristian Høgsberg | 8e80a31 | 2014-01-17 15:18:10 -0800 | [diff] [blame] | 1606 | move->active = 1; |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 1607 | move->dx = wl_fixed_from_double(shsurf->view->geometry.x) - |
Rusty Lynch | 1084da5 | 2013-08-15 09:10:08 -0700 | [diff] [blame] | 1608 | seat->touch->grab_x; |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 1609 | move->dy = wl_fixed_from_double(shsurf->view->geometry.y) - |
Rusty Lynch | 1084da5 | 2013-08-15 09:10:08 -0700 | [diff] [blame] | 1610 | seat->touch->grab_y; |
| 1611 | |
| 1612 | shell_touch_grab_start(&move->base, &touch_move_grab_interface, shsurf, |
| 1613 | seat->touch); |
| 1614 | |
| 1615 | return 0; |
| 1616 | } |
| 1617 | |
| 1618 | static void |
Kristian Høgsberg | 6848c25 | 2013-05-08 22:02:59 -0400 | [diff] [blame] | 1619 | noop_grab_focus(struct weston_pointer_grab *grab) |
Kristian Høgsberg | 9ddb826 | 2012-01-04 21:30:29 -0500 | [diff] [blame] | 1620 | { |
Kristian Høgsberg | 9ddb826 | 2012-01-04 21:30:29 -0500 | [diff] [blame] | 1621 | } |
| 1622 | |
| 1623 | static void |
Kristian Høgsberg | ae356ae | 2014-04-29 16:03:54 -0700 | [diff] [blame] | 1624 | constrain_position(struct weston_move_grab *move, int *cx, int *cy) |
| 1625 | { |
| 1626 | struct shell_surface *shsurf = move->base.shsurf; |
| 1627 | struct weston_pointer *pointer = move->base.grab.pointer; |
Jonny Lamb | d73c694 | 2014-08-20 15:53:20 +0200 | [diff] [blame] | 1628 | int x, y, panel_width, panel_height, bottom; |
Kristian Høgsberg | ae356ae | 2014-04-29 16:03:54 -0700 | [diff] [blame] | 1629 | const int safety = 50; |
| 1630 | |
| 1631 | x = wl_fixed_to_int(pointer->x + move->dx); |
| 1632 | y = wl_fixed_to_int(pointer->y + move->dy); |
| 1633 | |
Jonny Lamb | d73c694 | 2014-08-20 15:53:20 +0200 | [diff] [blame] | 1634 | if (shsurf->shell->panel_position == DESKTOP_SHELL_PANEL_POSITION_TOP) { |
| 1635 | get_output_panel_size(shsurf->shell, shsurf->surface->output, |
| 1636 | &panel_width, &panel_height); |
Kristian Høgsberg | ae356ae | 2014-04-29 16:03:54 -0700 | [diff] [blame] | 1637 | |
Jonny Lamb | d73c694 | 2014-08-20 15:53:20 +0200 | [diff] [blame] | 1638 | bottom = y + shsurf->geometry.height; |
| 1639 | if (bottom - panel_height < safety) |
| 1640 | y = panel_height + safety - |
| 1641 | shsurf->geometry.height; |
| 1642 | |
| 1643 | if (move->client_initiated && |
| 1644 | y + shsurf->geometry.y < panel_height) |
| 1645 | y = panel_height - shsurf->geometry.y; |
| 1646 | } |
Kristian Høgsberg | ae356ae | 2014-04-29 16:03:54 -0700 | [diff] [blame] | 1647 | |
| 1648 | *cx = x; |
| 1649 | *cy = y; |
| 1650 | } |
| 1651 | |
| 1652 | static void |
Giulio Camuffo | 1959ab8 | 2013-11-14 23:42:52 +0100 | [diff] [blame] | 1653 | move_grab_motion(struct weston_pointer_grab *grab, uint32_t time, |
| 1654 | wl_fixed_t x, wl_fixed_t y) |
Kristian Høgsberg | 4cca349 | 2011-01-18 07:53:49 -0500 | [diff] [blame] | 1655 | { |
Kristian Høgsberg | 8334bc1 | 2012-01-03 10:29:47 -0500 | [diff] [blame] | 1656 | struct weston_move_grab *move = (struct weston_move_grab *) grab; |
Kristian Høgsberg | 02bbabb | 2013-05-06 22:15:05 -0400 | [diff] [blame] | 1657 | struct weston_pointer *pointer = grab->pointer; |
Ander Conselvan de Oliveira | fe0444a | 2012-04-04 17:48:05 +0300 | [diff] [blame] | 1658 | struct shell_surface *shsurf = move->base.shsurf; |
Kristian Høgsberg | ae356ae | 2014-04-29 16:03:54 -0700 | [diff] [blame] | 1659 | int cx, cy; |
Giulio Camuffo | 1959ab8 | 2013-11-14 23:42:52 +0100 | [diff] [blame] | 1660 | |
| 1661 | weston_pointer_move(pointer, x, y); |
Ander Conselvan de Oliveira | fe0444a | 2012-04-04 17:48:05 +0300 | [diff] [blame] | 1662 | if (!shsurf) |
| 1663 | return; |
| 1664 | |
Kristian Høgsberg | ae356ae | 2014-04-29 16:03:54 -0700 | [diff] [blame] | 1665 | constrain_position(move, &cx, &cy); |
| 1666 | |
| 1667 | weston_view_set_position(shsurf->view, cx, cy); |
Kristian Høgsberg | 4cca349 | 2011-01-18 07:53:49 -0500 | [diff] [blame] | 1668 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 1669 | weston_compositor_schedule_repaint(shsurf->surface->compositor); |
Kristian Høgsberg | 4cca349 | 2011-01-18 07:53:49 -0500 | [diff] [blame] | 1670 | } |
| 1671 | |
| 1672 | static void |
Kristian Høgsberg | 02bbabb | 2013-05-06 22:15:05 -0400 | [diff] [blame] | 1673 | move_grab_button(struct weston_pointer_grab *grab, |
Daniel Stone | 4dbadb1 | 2012-05-30 16:31:51 +0100 | [diff] [blame] | 1674 | uint32_t time, uint32_t button, uint32_t state_w) |
Kristian Høgsberg | 4cca349 | 2011-01-18 07:53:49 -0500 | [diff] [blame] | 1675 | { |
Ander Conselvan de Oliveira | fe0444a | 2012-04-04 17:48:05 +0300 | [diff] [blame] | 1676 | struct shell_grab *shell_grab = container_of(grab, struct shell_grab, |
| 1677 | grab); |
Kristian Høgsberg | 02bbabb | 2013-05-06 22:15:05 -0400 | [diff] [blame] | 1678 | struct weston_pointer *pointer = grab->pointer; |
Daniel Stone | 4dbadb1 | 2012-05-30 16:31:51 +0100 | [diff] [blame] | 1679 | enum wl_pointer_button_state state = state_w; |
Kristian Høgsberg | 4cca349 | 2011-01-18 07:53:49 -0500 | [diff] [blame] | 1680 | |
Daniel Stone | 4dbadb1 | 2012-05-30 16:31:51 +0100 | [diff] [blame] | 1681 | if (pointer->button_count == 0 && |
| 1682 | state == WL_POINTER_BUTTON_STATE_RELEASED) { |
Ander Conselvan de Oliveira | b9d2a0f | 2012-06-28 18:08:05 +0300 | [diff] [blame] | 1683 | shell_grab_end(shell_grab); |
Kristian Høgsberg | 9ddb826 | 2012-01-04 21:30:29 -0500 | [diff] [blame] | 1684 | free(grab); |
| 1685 | } |
Kristian Høgsberg | 4cca349 | 2011-01-18 07:53:49 -0500 | [diff] [blame] | 1686 | } |
| 1687 | |
Jonas Ådahl | 1ea343e | 2013-10-25 23:18:05 +0200 | [diff] [blame] | 1688 | static void |
| 1689 | move_grab_cancel(struct weston_pointer_grab *grab) |
| 1690 | { |
| 1691 | struct shell_grab *shell_grab = |
| 1692 | container_of(grab, struct shell_grab, grab); |
| 1693 | |
| 1694 | shell_grab_end(shell_grab); |
| 1695 | free(grab); |
| 1696 | } |
| 1697 | |
Kristian Høgsberg | 02bbabb | 2013-05-06 22:15:05 -0400 | [diff] [blame] | 1698 | static const struct weston_pointer_grab_interface move_grab_interface = { |
Kristian Høgsberg | 9ddb826 | 2012-01-04 21:30:29 -0500 | [diff] [blame] | 1699 | noop_grab_focus, |
Kristian Høgsberg | 4cca349 | 2011-01-18 07:53:49 -0500 | [diff] [blame] | 1700 | move_grab_motion, |
| 1701 | move_grab_button, |
Jonas Ådahl | 1ea343e | 2013-10-25 23:18:05 +0200 | [diff] [blame] | 1702 | move_grab_cancel, |
Kristian Høgsberg | 4cca349 | 2011-01-18 07:53:49 -0500 | [diff] [blame] | 1703 | }; |
| 1704 | |
Kristian Høgsberg | 9e31bff | 2012-08-01 00:08:07 -0400 | [diff] [blame] | 1705 | static int |
Kristian Høgsberg | ae356ae | 2014-04-29 16:03:54 -0700 | [diff] [blame] | 1706 | surface_move(struct shell_surface *shsurf, struct weston_seat *seat, |
| 1707 | int client_initiated) |
Kristian Høgsberg | 9e31bff | 2012-08-01 00:08:07 -0400 | [diff] [blame] | 1708 | { |
| 1709 | struct weston_move_grab *move; |
| 1710 | |
| 1711 | if (!shsurf) |
| 1712 | return -1; |
| 1713 | |
Kristian Høgsberg | a4b620e | 2014-04-30 16:05:49 -0700 | [diff] [blame] | 1714 | if (shsurf->grabbed || |
| 1715 | shsurf->state.fullscreen || shsurf->state.maximized) |
Kristian Høgsberg | 9e31bff | 2012-08-01 00:08:07 -0400 | [diff] [blame] | 1716 | return 0; |
| 1717 | |
| 1718 | move = malloc(sizeof *move); |
| 1719 | if (!move) |
| 1720 | return -1; |
| 1721 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 1722 | move->dx = wl_fixed_from_double(shsurf->view->geometry.x) - |
Kristian Høgsberg | e314875 | 2013-05-06 23:19:49 -0400 | [diff] [blame] | 1723 | seat->pointer->grab_x; |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 1724 | move->dy = wl_fixed_from_double(shsurf->view->geometry.y) - |
Kristian Høgsberg | e314875 | 2013-05-06 23:19:49 -0400 | [diff] [blame] | 1725 | seat->pointer->grab_y; |
Kristian Høgsberg | ae356ae | 2014-04-29 16:03:54 -0700 | [diff] [blame] | 1726 | move->client_initiated = client_initiated; |
Kristian Høgsberg | 9e31bff | 2012-08-01 00:08:07 -0400 | [diff] [blame] | 1727 | |
| 1728 | shell_grab_start(&move->base, &move_grab_interface, shsurf, |
Kristian Høgsberg | e314875 | 2013-05-06 23:19:49 -0400 | [diff] [blame] | 1729 | seat->pointer, DESKTOP_SHELL_CURSOR_MOVE); |
Kristian Høgsberg | 9e31bff | 2012-08-01 00:08:07 -0400 | [diff] [blame] | 1730 | |
| 1731 | return 0; |
| 1732 | } |
| 1733 | |
| 1734 | static void |
Rafael Antognolli | e2a3455 | 2013-12-03 15:35:45 -0200 | [diff] [blame] | 1735 | common_surface_move(struct wl_resource *resource, |
| 1736 | struct wl_resource *seat_resource, uint32_t serial) |
Kristian Høgsberg | 9e31bff | 2012-08-01 00:08:07 -0400 | [diff] [blame] | 1737 | { |
Jason Ekstrand | 44a3863 | 2013-06-14 10:08:00 -0500 | [diff] [blame] | 1738 | struct weston_seat *seat = wl_resource_get_user_data(seat_resource); |
Jason Ekstrand | 651f00e | 2013-06-14 10:07:54 -0500 | [diff] [blame] | 1739 | struct shell_surface *shsurf = wl_resource_get_user_data(resource); |
Giulio Camuffo | 61da3fc | 2013-04-25 13:57:45 +0300 | [diff] [blame] | 1740 | struct weston_surface *surface; |
Kristian Høgsberg | 9e31bff | 2012-08-01 00:08:07 -0400 | [diff] [blame] | 1741 | |
Kristian Høgsberg | e1b655d | 2013-08-28 23:16:20 -0700 | [diff] [blame] | 1742 | if (seat->pointer && |
Kristian Høgsberg | 70f2901 | 2014-01-09 15:43:17 -0800 | [diff] [blame] | 1743 | seat->pointer->focus && |
Kristian Høgsberg | e1b655d | 2013-08-28 23:16:20 -0700 | [diff] [blame] | 1744 | seat->pointer->button_count > 0 && |
| 1745 | seat->pointer->grab_serial == serial) { |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 1746 | surface = weston_surface_get_main_surface(seat->pointer->focus->surface); |
U. Artie Eoff | cf5737a | 2014-01-17 10:08:25 -0800 | [diff] [blame] | 1747 | if ((surface == shsurf->surface) && |
Kristian Høgsberg | ae356ae | 2014-04-29 16:03:54 -0700 | [diff] [blame] | 1748 | (surface_move(shsurf, seat, 1) < 0)) |
Rusty Lynch | 1084da5 | 2013-08-15 09:10:08 -0700 | [diff] [blame] | 1749 | wl_resource_post_no_memory(resource); |
Kristian Høgsberg | e1b655d | 2013-08-28 23:16:20 -0700 | [diff] [blame] | 1750 | } else if (seat->touch && |
Kristian Høgsberg | 70f2901 | 2014-01-09 15:43:17 -0800 | [diff] [blame] | 1751 | seat->touch->focus && |
Kristian Høgsberg | e1b655d | 2013-08-28 23:16:20 -0700 | [diff] [blame] | 1752 | seat->touch->grab_serial == serial) { |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 1753 | surface = weston_surface_get_main_surface(seat->touch->focus->surface); |
U. Artie Eoff | cf5737a | 2014-01-17 10:08:25 -0800 | [diff] [blame] | 1754 | if ((surface == shsurf->surface) && |
Rusty Lynch | 1084da5 | 2013-08-15 09:10:08 -0700 | [diff] [blame] | 1755 | (surface_touch_move(shsurf, seat) < 0)) |
| 1756 | wl_resource_post_no_memory(resource); |
| 1757 | } |
Kristian Høgsberg | 9e31bff | 2012-08-01 00:08:07 -0400 | [diff] [blame] | 1758 | } |
| 1759 | |
Rafael Antognolli | e2a3455 | 2013-12-03 15:35:45 -0200 | [diff] [blame] | 1760 | static void |
| 1761 | shell_surface_move(struct wl_client *client, struct wl_resource *resource, |
| 1762 | struct wl_resource *seat_resource, uint32_t serial) |
| 1763 | { |
| 1764 | common_surface_move(resource, seat_resource, serial); |
| 1765 | } |
| 1766 | |
Kristian Høgsberg | 9e31bff | 2012-08-01 00:08:07 -0400 | [diff] [blame] | 1767 | struct weston_resize_grab { |
| 1768 | struct shell_grab base; |
| 1769 | uint32_t edges; |
| 1770 | int32_t width, height; |
| 1771 | }; |
| 1772 | |
| 1773 | static void |
Giulio Camuffo | 1959ab8 | 2013-11-14 23:42:52 +0100 | [diff] [blame] | 1774 | resize_grab_motion(struct weston_pointer_grab *grab, uint32_t time, |
| 1775 | wl_fixed_t x, wl_fixed_t y) |
Kristian Høgsberg | 9e31bff | 2012-08-01 00:08:07 -0400 | [diff] [blame] | 1776 | { |
| 1777 | struct weston_resize_grab *resize = (struct weston_resize_grab *) grab; |
Kristian Høgsberg | 02bbabb | 2013-05-06 22:15:05 -0400 | [diff] [blame] | 1778 | struct weston_pointer *pointer = grab->pointer; |
Kristian Høgsberg | 9e31bff | 2012-08-01 00:08:07 -0400 | [diff] [blame] | 1779 | struct shell_surface *shsurf = resize->base.shsurf; |
| 1780 | int32_t width, height; |
| 1781 | wl_fixed_t from_x, from_y; |
| 1782 | wl_fixed_t to_x, to_y; |
| 1783 | |
Giulio Camuffo | 1959ab8 | 2013-11-14 23:42:52 +0100 | [diff] [blame] | 1784 | weston_pointer_move(pointer, x, y); |
| 1785 | |
Kristian Høgsberg | e0b9d5b | 2014-04-30 13:45:49 -0700 | [diff] [blame] | 1786 | if (!shsurf) |
Kristian Høgsberg | 9e31bff | 2012-08-01 00:08:07 -0400 | [diff] [blame] | 1787 | return; |
| 1788 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 1789 | weston_view_from_global_fixed(shsurf->view, |
| 1790 | pointer->grab_x, pointer->grab_y, |
| 1791 | &from_x, &from_y); |
| 1792 | weston_view_from_global_fixed(shsurf->view, |
| 1793 | pointer->x, pointer->y, &to_x, &to_y); |
Kristian Høgsberg | 9e31bff | 2012-08-01 00:08:07 -0400 | [diff] [blame] | 1794 | |
| 1795 | width = resize->width; |
| 1796 | if (resize->edges & WL_SHELL_SURFACE_RESIZE_LEFT) { |
| 1797 | width += wl_fixed_to_int(from_x - to_x); |
| 1798 | } else if (resize->edges & WL_SHELL_SURFACE_RESIZE_RIGHT) { |
| 1799 | width += wl_fixed_to_int(to_x - from_x); |
| 1800 | } |
| 1801 | |
| 1802 | height = resize->height; |
| 1803 | if (resize->edges & WL_SHELL_SURFACE_RESIZE_TOP) { |
| 1804 | height += wl_fixed_to_int(from_y - to_y); |
| 1805 | } else if (resize->edges & WL_SHELL_SURFACE_RESIZE_BOTTOM) { |
| 1806 | height += wl_fixed_to_int(to_y - from_y); |
| 1807 | } |
| 1808 | |
Jasper St. Pierre | ac985be | 2014-04-28 11:19:28 -0400 | [diff] [blame] | 1809 | shsurf->client->send_configure(shsurf->surface, width, height); |
Kristian Høgsberg | 9e31bff | 2012-08-01 00:08:07 -0400 | [diff] [blame] | 1810 | } |
| 1811 | |
| 1812 | static void |
Jasper St. Pierre | ac985be | 2014-04-28 11:19:28 -0400 | [diff] [blame] | 1813 | 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] | 1814 | { |
| 1815 | struct shell_surface *shsurf = get_shell_surface(surface); |
| 1816 | |
U. Artie Eoff | cf5737a | 2014-01-17 10:08:25 -0800 | [diff] [blame] | 1817 | assert(shsurf); |
| 1818 | |
Kristian Høgsberg | e0b9d5b | 2014-04-30 13:45:49 -0700 | [diff] [blame] | 1819 | if (shsurf->resource) |
| 1820 | wl_shell_surface_send_configure(shsurf->resource, |
Jasper St. Pierre | ac985be | 2014-04-28 11:19:28 -0400 | [diff] [blame] | 1821 | shsurf->resize_edges, |
| 1822 | width, height); |
Kristian Høgsberg | 9e31bff | 2012-08-01 00:08:07 -0400 | [diff] [blame] | 1823 | } |
| 1824 | |
| 1825 | static const struct weston_shell_client shell_client = { |
| 1826 | send_configure |
| 1827 | }; |
| 1828 | |
| 1829 | static void |
Kristian Høgsberg | 02bbabb | 2013-05-06 22:15:05 -0400 | [diff] [blame] | 1830 | resize_grab_button(struct weston_pointer_grab *grab, |
Kristian Høgsberg | 9e31bff | 2012-08-01 00:08:07 -0400 | [diff] [blame] | 1831 | uint32_t time, uint32_t button, uint32_t state_w) |
| 1832 | { |
| 1833 | struct weston_resize_grab *resize = (struct weston_resize_grab *) grab; |
Kristian Høgsberg | 02bbabb | 2013-05-06 22:15:05 -0400 | [diff] [blame] | 1834 | struct weston_pointer *pointer = grab->pointer; |
Kristian Høgsberg | 9e31bff | 2012-08-01 00:08:07 -0400 | [diff] [blame] | 1835 | enum wl_pointer_button_state state = state_w; |
| 1836 | |
| 1837 | if (pointer->button_count == 0 && |
| 1838 | state == WL_POINTER_BUTTON_STATE_RELEASED) { |
| 1839 | shell_grab_end(&resize->base); |
| 1840 | free(grab); |
| 1841 | } |
| 1842 | } |
| 1843 | |
Jonas Ådahl | 1ea343e | 2013-10-25 23:18:05 +0200 | [diff] [blame] | 1844 | static void |
| 1845 | resize_grab_cancel(struct weston_pointer_grab *grab) |
| 1846 | { |
| 1847 | struct weston_resize_grab *resize = (struct weston_resize_grab *) grab; |
| 1848 | |
| 1849 | shell_grab_end(&resize->base); |
| 1850 | free(grab); |
| 1851 | } |
| 1852 | |
Kristian Høgsberg | 02bbabb | 2013-05-06 22:15:05 -0400 | [diff] [blame] | 1853 | static const struct weston_pointer_grab_interface resize_grab_interface = { |
Kristian Høgsberg | 9e31bff | 2012-08-01 00:08:07 -0400 | [diff] [blame] | 1854 | noop_grab_focus, |
| 1855 | resize_grab_motion, |
| 1856 | resize_grab_button, |
Jonas Ådahl | 1ea343e | 2013-10-25 23:18:05 +0200 | [diff] [blame] | 1857 | resize_grab_cancel, |
Kristian Høgsberg | 9e31bff | 2012-08-01 00:08:07 -0400 | [diff] [blame] | 1858 | }; |
| 1859 | |
Giulio Camuffo | b836664 | 2013-04-25 13:57:46 +0300 | [diff] [blame] | 1860 | /* |
| 1861 | * Returns the bounding box of a surface and all its sub-surfaces, |
| 1862 | * in the surface coordinates system. */ |
| 1863 | static void |
| 1864 | surface_subsurfaces_boundingbox(struct weston_surface *surface, int32_t *x, |
| 1865 | int32_t *y, int32_t *w, int32_t *h) { |
| 1866 | pixman_region32_t region; |
| 1867 | pixman_box32_t *box; |
| 1868 | struct weston_subsurface *subsurface; |
| 1869 | |
| 1870 | pixman_region32_init_rect(®ion, 0, 0, |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 1871 | surface->width, |
| 1872 | surface->height); |
Giulio Camuffo | b836664 | 2013-04-25 13:57:46 +0300 | [diff] [blame] | 1873 | |
| 1874 | wl_list_for_each(subsurface, &surface->subsurface_list, parent_link) { |
| 1875 | pixman_region32_union_rect(®ion, ®ion, |
| 1876 | subsurface->position.x, |
| 1877 | subsurface->position.y, |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 1878 | subsurface->surface->width, |
| 1879 | subsurface->surface->height); |
Giulio Camuffo | b836664 | 2013-04-25 13:57:46 +0300 | [diff] [blame] | 1880 | } |
| 1881 | |
| 1882 | box = pixman_region32_extents(®ion); |
| 1883 | if (x) |
| 1884 | *x = box->x1; |
| 1885 | if (y) |
| 1886 | *y = box->y1; |
| 1887 | if (w) |
| 1888 | *w = box->x2 - box->x1; |
| 1889 | if (h) |
| 1890 | *h = box->y2 - box->y1; |
| 1891 | |
| 1892 | pixman_region32_fini(®ion); |
| 1893 | } |
| 1894 | |
Kristian Høgsberg | 9e31bff | 2012-08-01 00:08:07 -0400 | [diff] [blame] | 1895 | static int |
| 1896 | surface_resize(struct shell_surface *shsurf, |
Kristian Høgsberg | e314875 | 2013-05-06 23:19:49 -0400 | [diff] [blame] | 1897 | struct weston_seat *seat, uint32_t edges) |
Kristian Høgsberg | 9e31bff | 2012-08-01 00:08:07 -0400 | [diff] [blame] | 1898 | { |
| 1899 | struct weston_resize_grab *resize; |
Ondřej Majerech | ae9c4fc | 2014-08-21 15:47:22 +0200 | [diff] [blame] | 1900 | const unsigned resize_topbottom = |
| 1901 | WL_SHELL_SURFACE_RESIZE_TOP | WL_SHELL_SURFACE_RESIZE_BOTTOM; |
| 1902 | const unsigned resize_leftright = |
| 1903 | WL_SHELL_SURFACE_RESIZE_LEFT | WL_SHELL_SURFACE_RESIZE_RIGHT; |
| 1904 | const unsigned resize_any = resize_topbottom | resize_leftright; |
Kristian Høgsberg | 9e31bff | 2012-08-01 00:08:07 -0400 | [diff] [blame] | 1905 | |
Kristian Høgsberg | a4b620e | 2014-04-30 16:05:49 -0700 | [diff] [blame] | 1906 | if (shsurf->grabbed || |
| 1907 | shsurf->state.fullscreen || shsurf->state.maximized) |
Kristian Høgsberg | 9e31bff | 2012-08-01 00:08:07 -0400 | [diff] [blame] | 1908 | return 0; |
| 1909 | |
Ondřej Majerech | ae9c4fc | 2014-08-21 15:47:22 +0200 | [diff] [blame] | 1910 | /* Check for invalid edge combinations. */ |
| 1911 | if (edges == WL_SHELL_SURFACE_RESIZE_NONE || edges > resize_any || |
| 1912 | (edges & resize_topbottom) == resize_topbottom || |
| 1913 | (edges & resize_leftright) == resize_leftright) |
Kristian Høgsberg | 9e31bff | 2012-08-01 00:08:07 -0400 | [diff] [blame] | 1914 | return 0; |
| 1915 | |
| 1916 | resize = malloc(sizeof *resize); |
| 1917 | if (!resize) |
| 1918 | return -1; |
| 1919 | |
| 1920 | resize->edges = edges; |
Kristian Høgsberg | 9e31bff | 2012-08-01 00:08:07 -0400 | [diff] [blame] | 1921 | |
Jasper St. Pierre | ccf48fb | 2014-05-02 10:21:38 -0400 | [diff] [blame] | 1922 | resize->width = shsurf->geometry.width; |
| 1923 | resize->height = shsurf->geometry.height; |
Jasper St. Pierre | bd65e50 | 2014-07-14 16:28:48 -0400 | [diff] [blame] | 1924 | |
Kristian Høgsberg | 44cd196 | 2014-02-05 21:36:04 -0800 | [diff] [blame] | 1925 | shsurf->resize_edges = edges; |
Jasper St. Pierre | 5befdda | 2014-05-06 08:50:47 -0400 | [diff] [blame] | 1926 | shell_surface_state_changed(shsurf); |
Kristian Høgsberg | 9e31bff | 2012-08-01 00:08:07 -0400 | [diff] [blame] | 1927 | shell_grab_start(&resize->base, &resize_grab_interface, shsurf, |
Kristian Høgsberg | e314875 | 2013-05-06 23:19:49 -0400 | [diff] [blame] | 1928 | seat->pointer, edges); |
Kristian Høgsberg | 9e31bff | 2012-08-01 00:08:07 -0400 | [diff] [blame] | 1929 | |
| 1930 | return 0; |
| 1931 | } |
| 1932 | |
| 1933 | static void |
Rafael Antognolli | e2a3455 | 2013-12-03 15:35:45 -0200 | [diff] [blame] | 1934 | common_surface_resize(struct wl_resource *resource, |
| 1935 | struct wl_resource *seat_resource, uint32_t serial, |
| 1936 | uint32_t edges) |
Kristian Høgsberg | 9e31bff | 2012-08-01 00:08:07 -0400 | [diff] [blame] | 1937 | { |
Jason Ekstrand | 44a3863 | 2013-06-14 10:08:00 -0500 | [diff] [blame] | 1938 | struct weston_seat *seat = wl_resource_get_user_data(seat_resource); |
Jason Ekstrand | 651f00e | 2013-06-14 10:07:54 -0500 | [diff] [blame] | 1939 | struct shell_surface *shsurf = wl_resource_get_user_data(resource); |
Giulio Camuffo | 61da3fc | 2013-04-25 13:57:45 +0300 | [diff] [blame] | 1940 | struct weston_surface *surface; |
Kristian Høgsberg | 9e31bff | 2012-08-01 00:08:07 -0400 | [diff] [blame] | 1941 | |
Emilio Pozuelo Monfort | 5872b68 | 2014-06-18 17:48:58 +0200 | [diff] [blame] | 1942 | if (seat->pointer == NULL || |
| 1943 | seat->pointer->button_count == 0 || |
Kristian Høgsberg | e314875 | 2013-05-06 23:19:49 -0400 | [diff] [blame] | 1944 | seat->pointer->grab_serial != serial || |
Kristian Høgsberg | 70f2901 | 2014-01-09 15:43:17 -0800 | [diff] [blame] | 1945 | seat->pointer->focus == NULL) |
| 1946 | return; |
| 1947 | |
| 1948 | surface = weston_surface_get_main_surface(seat->pointer->focus->surface); |
| 1949 | if (surface != shsurf->surface) |
Kristian Høgsberg | 9e31bff | 2012-08-01 00:08:07 -0400 | [diff] [blame] | 1950 | return; |
| 1951 | |
Kristian Høgsberg | e314875 | 2013-05-06 23:19:49 -0400 | [diff] [blame] | 1952 | if (surface_resize(shsurf, seat, edges) < 0) |
Kristian Høgsberg | 9e31bff | 2012-08-01 00:08:07 -0400 | [diff] [blame] | 1953 | wl_resource_post_no_memory(resource); |
| 1954 | } |
| 1955 | |
Scott Moreau | c3e54eb | 2012-04-17 19:06:20 -0600 | [diff] [blame] | 1956 | static void |
Rafael Antognolli | e2a3455 | 2013-12-03 15:35:45 -0200 | [diff] [blame] | 1957 | shell_surface_resize(struct wl_client *client, struct wl_resource *resource, |
| 1958 | struct wl_resource *seat_resource, uint32_t serial, |
| 1959 | uint32_t edges) |
| 1960 | { |
| 1961 | common_surface_resize(resource, seat_resource, serial, edges); |
| 1962 | } |
| 1963 | |
| 1964 | static void |
Kristian Høgsberg | 6848c25 | 2013-05-08 22:02:59 -0400 | [diff] [blame] | 1965 | busy_cursor_grab_focus(struct weston_pointer_grab *base) |
Scott Moreau | c3e54eb | 2012-04-17 19:06:20 -0600 | [diff] [blame] | 1966 | { |
Kristian Høgsberg | d56bd90 | 2012-06-05 09:58:51 -0400 | [diff] [blame] | 1967 | struct shell_grab *grab = (struct shell_grab *) base; |
Kristian Høgsberg | 6848c25 | 2013-05-08 22:02:59 -0400 | [diff] [blame] | 1968 | struct weston_pointer *pointer = base->pointer; |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 1969 | struct weston_view *view; |
Kristian Høgsberg | 6848c25 | 2013-05-08 22:02:59 -0400 | [diff] [blame] | 1970 | wl_fixed_t sx, sy; |
| 1971 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 1972 | view = weston_compositor_pick_view(pointer->seat->compositor, |
| 1973 | pointer->x, pointer->y, |
| 1974 | &sx, &sy); |
Scott Moreau | c3e54eb | 2012-04-17 19:06:20 -0600 | [diff] [blame] | 1975 | |
Kristian Høgsberg | 2bff94e | 2014-02-11 12:22:51 -0800 | [diff] [blame] | 1976 | if (!grab->shsurf || grab->shsurf->surface != view->surface) { |
| 1977 | shell_grab_end(grab); |
| 1978 | free(grab); |
| 1979 | } |
Scott Moreau | c3e54eb | 2012-04-17 19:06:20 -0600 | [diff] [blame] | 1980 | } |
| 1981 | |
| 1982 | static void |
Giulio Camuffo | 1959ab8 | 2013-11-14 23:42:52 +0100 | [diff] [blame] | 1983 | busy_cursor_grab_motion(struct weston_pointer_grab *grab, uint32_t time, |
| 1984 | wl_fixed_t x, wl_fixed_t y) |
Scott Moreau | c3e54eb | 2012-04-17 19:06:20 -0600 | [diff] [blame] | 1985 | { |
Giulio Camuffo | 1959ab8 | 2013-11-14 23:42:52 +0100 | [diff] [blame] | 1986 | weston_pointer_move(grab->pointer, x, y); |
Kristian Høgsberg | d56bd90 | 2012-06-05 09:58:51 -0400 | [diff] [blame] | 1987 | } |
Scott Moreau | c3e54eb | 2012-04-17 19:06:20 -0600 | [diff] [blame] | 1988 | |
Kristian Høgsberg | d56bd90 | 2012-06-05 09:58:51 -0400 | [diff] [blame] | 1989 | static void |
Kristian Høgsberg | 02bbabb | 2013-05-06 22:15:05 -0400 | [diff] [blame] | 1990 | busy_cursor_grab_button(struct weston_pointer_grab *base, |
Kristian Høgsberg | d56bd90 | 2012-06-05 09:58:51 -0400 | [diff] [blame] | 1991 | uint32_t time, uint32_t button, uint32_t state) |
| 1992 | { |
Kristian Høgsberg | bbe9839 | 2012-08-01 00:20:21 -0400 | [diff] [blame] | 1993 | struct shell_grab *grab = (struct shell_grab *) base; |
Kristian Høgsberg | e122b7b | 2013-05-08 16:47:00 -0400 | [diff] [blame] | 1994 | struct shell_surface *shsurf = grab->shsurf; |
Kristian Høgsberg | e314875 | 2013-05-06 23:19:49 -0400 | [diff] [blame] | 1995 | struct weston_seat *seat = grab->grab.pointer->seat; |
Kristian Høgsberg | bbe9839 | 2012-08-01 00:20:21 -0400 | [diff] [blame] | 1996 | |
Kristian Høgsberg | bbe9839 | 2012-08-01 00:20:21 -0400 | [diff] [blame] | 1997 | if (shsurf && button == BTN_LEFT && state) { |
Emilio Pozuelo Monfort | 9e7c759 | 2014-01-30 14:01:10 +0100 | [diff] [blame] | 1998 | activate(shsurf->shell, shsurf->surface, seat, true); |
Kristian Høgsberg | ae356ae | 2014-04-29 16:03:54 -0700 | [diff] [blame] | 1999 | surface_move(shsurf, seat, 0); |
Kristian Høgsberg | 0c36903 | 2013-02-14 21:31:44 -0500 | [diff] [blame] | 2000 | } else if (shsurf && button == BTN_RIGHT && state) { |
Emilio Pozuelo Monfort | 9e7c759 | 2014-01-30 14:01:10 +0100 | [diff] [blame] | 2001 | activate(shsurf->shell, shsurf->surface, seat, true); |
Kristian Høgsberg | e314875 | 2013-05-06 23:19:49 -0400 | [diff] [blame] | 2002 | surface_rotate(shsurf, seat); |
Kristian Høgsberg | bbe9839 | 2012-08-01 00:20:21 -0400 | [diff] [blame] | 2003 | } |
Kristian Høgsberg | d56bd90 | 2012-06-05 09:58:51 -0400 | [diff] [blame] | 2004 | } |
| 2005 | |
Jonas Ådahl | 1ea343e | 2013-10-25 23:18:05 +0200 | [diff] [blame] | 2006 | static void |
| 2007 | busy_cursor_grab_cancel(struct weston_pointer_grab *base) |
| 2008 | { |
| 2009 | struct shell_grab *grab = (struct shell_grab *) base; |
| 2010 | |
| 2011 | shell_grab_end(grab); |
| 2012 | free(grab); |
| 2013 | } |
| 2014 | |
Kristian Høgsberg | 02bbabb | 2013-05-06 22:15:05 -0400 | [diff] [blame] | 2015 | static const struct weston_pointer_grab_interface busy_cursor_grab_interface = { |
Kristian Høgsberg | d56bd90 | 2012-06-05 09:58:51 -0400 | [diff] [blame] | 2016 | busy_cursor_grab_focus, |
| 2017 | busy_cursor_grab_motion, |
| 2018 | busy_cursor_grab_button, |
Jonas Ådahl | 1ea343e | 2013-10-25 23:18:05 +0200 | [diff] [blame] | 2019 | busy_cursor_grab_cancel, |
Kristian Høgsberg | d56bd90 | 2012-06-05 09:58:51 -0400 | [diff] [blame] | 2020 | }; |
| 2021 | |
| 2022 | static void |
Kristian Høgsberg | 02bbabb | 2013-05-06 22:15:05 -0400 | [diff] [blame] | 2023 | set_busy_cursor(struct shell_surface *shsurf, struct weston_pointer *pointer) |
Kristian Høgsberg | d56bd90 | 2012-06-05 09:58:51 -0400 | [diff] [blame] | 2024 | { |
| 2025 | struct shell_grab *grab; |
Kristian Høgsberg | d56bd90 | 2012-06-05 09:58:51 -0400 | [diff] [blame] | 2026 | |
Kristian Høgsberg | 2bff94e | 2014-02-11 12:22:51 -0800 | [diff] [blame] | 2027 | if (pointer->grab->interface == &busy_cursor_grab_interface) |
| 2028 | return; |
| 2029 | |
Kristian Høgsberg | d56bd90 | 2012-06-05 09:58:51 -0400 | [diff] [blame] | 2030 | grab = malloc(sizeof *grab); |
| 2031 | if (!grab) |
Scott Moreau | c3e54eb | 2012-04-17 19:06:20 -0600 | [diff] [blame] | 2032 | return; |
| 2033 | |
Ander Conselvan de Oliveira | b9d2a0f | 2012-06-28 18:08:05 +0300 | [diff] [blame] | 2034 | shell_grab_start(grab, &busy_cursor_grab_interface, shsurf, pointer, |
| 2035 | DESKTOP_SHELL_CURSOR_BUSY); |
Ander Conselvan de Oliveira | e5a1aee | 2014-04-09 17:39:39 +0300 | [diff] [blame] | 2036 | /* Mark the shsurf as ungrabbed so that button binding is able |
| 2037 | * to move it. */ |
| 2038 | shsurf->grabbed = 0; |
Kristian Høgsberg | d56bd90 | 2012-06-05 09:58:51 -0400 | [diff] [blame] | 2039 | } |
Scott Moreau | c3e54eb | 2012-04-17 19:06:20 -0600 | [diff] [blame] | 2040 | |
Kristian Høgsberg | d56bd90 | 2012-06-05 09:58:51 -0400 | [diff] [blame] | 2041 | static void |
Kristian Høgsberg | 2bff94e | 2014-02-11 12:22:51 -0800 | [diff] [blame] | 2042 | end_busy_cursor(struct weston_compositor *compositor, struct wl_client *client) |
Kristian Høgsberg | d56bd90 | 2012-06-05 09:58:51 -0400 | [diff] [blame] | 2043 | { |
Kristian Høgsberg | 2bff94e | 2014-02-11 12:22:51 -0800 | [diff] [blame] | 2044 | struct shell_grab *grab; |
| 2045 | struct weston_seat *seat; |
Kristian Høgsberg | d56bd90 | 2012-06-05 09:58:51 -0400 | [diff] [blame] | 2046 | |
Kristian Høgsberg | 2bff94e | 2014-02-11 12:22:51 -0800 | [diff] [blame] | 2047 | wl_list_for_each(seat, &compositor->seat_list, link) { |
| 2048 | if (seat->pointer == NULL) |
| 2049 | continue; |
| 2050 | |
| 2051 | grab = (struct shell_grab *) seat->pointer->grab; |
| 2052 | if (grab->grab.interface == &busy_cursor_grab_interface && |
| 2053 | wl_resource_get_client(grab->shsurf->resource) == client) { |
| 2054 | shell_grab_end(grab); |
| 2055 | free(grab); |
| 2056 | } |
Scott Moreau | c3e54eb | 2012-04-17 19:06:20 -0600 | [diff] [blame] | 2057 | } |
Scott Moreau | c3e54eb | 2012-04-17 19:06:20 -0600 | [diff] [blame] | 2058 | } |
| 2059 | |
Scott Moreau | 9521d5e | 2012-04-19 13:06:17 -0600 | [diff] [blame] | 2060 | static void |
Kristian Høgsberg | 2bff94e | 2014-02-11 12:22:51 -0800 | [diff] [blame] | 2061 | handle_shell_client_destroy(struct wl_listener *listener, void *data); |
| 2062 | |
| 2063 | static int |
| 2064 | xdg_ping_timeout_handler(void *data) |
| 2065 | { |
| 2066 | struct shell_client *sc = data; |
| 2067 | struct weston_seat *seat; |
| 2068 | struct shell_surface *shsurf; |
| 2069 | |
| 2070 | /* Client is not responding */ |
| 2071 | sc->unresponsive = 1; |
Kristian Høgsberg | 2bff94e | 2014-02-11 12:22:51 -0800 | [diff] [blame] | 2072 | wl_list_for_each(seat, &sc->shell->compositor->seat_list, link) { |
| 2073 | if (seat->pointer == NULL || seat->pointer->focus == NULL) |
| 2074 | continue; |
| 2075 | if (seat->pointer->focus->surface->resource == NULL) |
| 2076 | continue; |
| 2077 | |
| 2078 | shsurf = get_shell_surface(seat->pointer->focus->surface); |
| 2079 | if (shsurf && |
| 2080 | wl_resource_get_client(shsurf->resource) == sc->client) |
| 2081 | set_busy_cursor(shsurf, seat->pointer); |
| 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); |
| 2215 | } |
| 2216 | |
| 2217 | static void |
Jasper St. Pierre | ccf48fb | 2014-05-02 10:21:38 -0400 | [diff] [blame] | 2218 | set_window_geometry(struct shell_surface *shsurf, |
| 2219 | 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] | 2220 | { |
Jasper St. Pierre | ccf48fb | 2014-05-02 10:21:38 -0400 | [diff] [blame] | 2221 | shsurf->next_geometry.x = x; |
| 2222 | shsurf->next_geometry.y = y; |
| 2223 | shsurf->next_geometry.width = width; |
| 2224 | shsurf->next_geometry.height = height; |
| 2225 | shsurf->has_next_geometry = true; |
Kristian Høgsberg | e5c1ae9 | 2014-04-30 16:28:41 -0700 | [diff] [blame] | 2226 | } |
| 2227 | |
| 2228 | static void |
Kristian Høgsberg | e7afd91 | 2012-05-02 09:47:44 -0400 | [diff] [blame] | 2229 | shell_surface_set_title(struct wl_client *client, |
| 2230 | struct wl_resource *resource, const char *title) |
| 2231 | { |
Jason Ekstrand | 651f00e | 2013-06-14 10:07:54 -0500 | [diff] [blame] | 2232 | struct shell_surface *shsurf = wl_resource_get_user_data(resource); |
Kristian Høgsberg | e7afd91 | 2012-05-02 09:47:44 -0400 | [diff] [blame] | 2233 | |
Giulio Camuffo | 62942ad | 2013-09-11 18:20:47 +0200 | [diff] [blame] | 2234 | set_title(shsurf, title); |
Kristian Høgsberg | e7afd91 | 2012-05-02 09:47:44 -0400 | [diff] [blame] | 2235 | } |
| 2236 | |
| 2237 | static void |
| 2238 | shell_surface_set_class(struct wl_client *client, |
| 2239 | struct wl_resource *resource, const char *class) |
| 2240 | { |
Jason Ekstrand | 651f00e | 2013-06-14 10:07:54 -0500 | [diff] [blame] | 2241 | struct shell_surface *shsurf = wl_resource_get_user_data(resource); |
Kristian Høgsberg | e7afd91 | 2012-05-02 09:47:44 -0400 | [diff] [blame] | 2242 | |
| 2243 | free(shsurf->class); |
| 2244 | shsurf->class = strdup(class); |
| 2245 | } |
| 2246 | |
Alex Wu | 4539b08 | 2012-03-01 12:57:46 +0800 | [diff] [blame] | 2247 | static void |
Alexander Larsson | f82b6ca | 2013-05-28 16:23:39 +0200 | [diff] [blame] | 2248 | restore_output_mode(struct weston_output *output) |
| 2249 | { |
Hardening | 57388e4 | 2013-09-18 23:56:36 +0200 | [diff] [blame] | 2250 | if (output->current_mode != output->original_mode || |
| 2251 | (int32_t)output->current_scale != output->original_scale) |
Alexander Larsson | f82b6ca | 2013-05-28 16:23:39 +0200 | [diff] [blame] | 2252 | weston_output_switch_mode(output, |
Hardening | 57388e4 | 2013-09-18 23:56:36 +0200 | [diff] [blame] | 2253 | output->original_mode, |
| 2254 | output->original_scale, |
| 2255 | WESTON_MODE_SWITCH_RESTORE_NATIVE); |
Alexander Larsson | f82b6ca | 2013-05-28 16:23:39 +0200 | [diff] [blame] | 2256 | } |
| 2257 | |
| 2258 | static void |
| 2259 | restore_all_output_modes(struct weston_compositor *compositor) |
| 2260 | { |
| 2261 | struct weston_output *output; |
| 2262 | |
| 2263 | wl_list_for_each(output, &compositor->output_list, link) |
| 2264 | restore_output_mode(output); |
| 2265 | } |
| 2266 | |
Philip Withnall | 07926d9 | 2013-11-25 18:01:40 +0000 | [diff] [blame] | 2267 | /* The surface will be inserted into the list immediately after the link |
| 2268 | * returned by this function (i.e. will be stacked immediately above the |
| 2269 | * returned link). */ |
Giulio Camuffo | 412e6a5 | 2014-07-09 22:12:56 +0300 | [diff] [blame] | 2270 | static struct weston_layer_entry * |
Philip Withnall | 07926d9 | 2013-11-25 18:01:40 +0000 | [diff] [blame] | 2271 | shell_surface_calculate_layer_link (struct shell_surface *shsurf) |
| 2272 | { |
| 2273 | struct workspace *ws; |
Kristian Høgsberg | ead5242 | 2014-01-01 13:51:52 -0800 | [diff] [blame] | 2274 | struct weston_view *parent; |
Philip Withnall | 07926d9 | 2013-11-25 18:01:40 +0000 | [diff] [blame] | 2275 | |
| 2276 | switch (shsurf->type) { |
Ander Conselvan de Oliveira | ef6a7e4 | 2014-04-30 14:15:14 +0300 | [diff] [blame] | 2277 | case SHELL_SURFACE_XWAYLAND: |
| 2278 | return &shsurf->shell->fullscreen_layer.view_list; |
| 2279 | |
| 2280 | case SHELL_SURFACE_NONE: |
| 2281 | return NULL; |
| 2282 | |
Kristian Høgsberg | ead5242 | 2014-01-01 13:51:52 -0800 | [diff] [blame] | 2283 | case SHELL_SURFACE_POPUP: |
| 2284 | case SHELL_SURFACE_TOPLEVEL: |
Emilio Pozuelo Monfort | 9e7c759 | 2014-01-30 14:01:10 +0100 | [diff] [blame] | 2285 | if (shsurf->state.fullscreen && !shsurf->state.lowered) { |
Rafael Antognolli | 03b1659 | 2013-12-03 15:35:42 -0200 | [diff] [blame] | 2286 | return &shsurf->shell->fullscreen_layer.view_list; |
Rafael Antognolli | ed207b4 | 2013-12-03 15:35:43 -0200 | [diff] [blame] | 2287 | } else if (shsurf->parent) { |
Kristian Høgsberg | d55db69 | 2014-01-01 12:26:14 -0800 | [diff] [blame] | 2288 | /* Move the surface to its parent layer so |
| 2289 | * that surfaces which are transient for |
| 2290 | * fullscreen surfaces don't get hidden by the |
| 2291 | * fullscreen surfaces. */ |
Rafael Antognolli | ed207b4 | 2013-12-03 15:35:43 -0200 | [diff] [blame] | 2292 | |
| 2293 | /* TODO: Handle a parent with multiple views */ |
| 2294 | parent = get_default_view(shsurf->parent); |
| 2295 | if (parent) |
Giulio Camuffo | 412e6a5 | 2014-07-09 22:12:56 +0300 | [diff] [blame] | 2296 | return container_of(parent->layer_link.link.prev, |
| 2297 | struct weston_layer_entry, link); |
Rafael Antognolli | ed207b4 | 2013-12-03 15:35:43 -0200 | [diff] [blame] | 2298 | } |
Philip Withnall | 07926d9 | 2013-11-25 18:01:40 +0000 | [diff] [blame] | 2299 | |
Ander Conselvan de Oliveira | ef6a7e4 | 2014-04-30 14:15:14 +0300 | [diff] [blame] | 2300 | /* Move the surface to a normal workspace layer so that surfaces |
| 2301 | * which were previously fullscreen or transient are no longer |
| 2302 | * rendered on top. */ |
| 2303 | ws = get_current_workspace(shsurf->shell); |
| 2304 | return &ws->layer.view_list; |
Philip Withnall | 07926d9 | 2013-11-25 18:01:40 +0000 | [diff] [blame] | 2305 | } |
| 2306 | |
Ander Conselvan de Oliveira | ef6a7e4 | 2014-04-30 14:15:14 +0300 | [diff] [blame] | 2307 | assert(0 && "Unknown shell surface type"); |
Philip Withnall | 07926d9 | 2013-11-25 18:01:40 +0000 | [diff] [blame] | 2308 | } |
| 2309 | |
Philip Withnall | 648a4dd | 2013-11-25 18:01:44 +0000 | [diff] [blame] | 2310 | static void |
| 2311 | shell_surface_update_child_surface_layers (struct shell_surface *shsurf) |
| 2312 | { |
| 2313 | struct shell_surface *child; |
Giulio Camuffo | 412e6a5 | 2014-07-09 22:12:56 +0300 | [diff] [blame] | 2314 | struct weston_layer_entry *prev; |
Philip Withnall | 648a4dd | 2013-11-25 18:01:44 +0000 | [diff] [blame] | 2315 | |
| 2316 | /* Move the child layers to the same workspace as shsurf. They will be |
| 2317 | * stacked above shsurf. */ |
| 2318 | wl_list_for_each_reverse(child, &shsurf->children_list, children_link) { |
Giulio Camuffo | 412e6a5 | 2014-07-09 22:12:56 +0300 | [diff] [blame] | 2319 | 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] | 2320 | weston_view_damage_below(child->view); |
Philip Withnall | 648a4dd | 2013-11-25 18:01:44 +0000 | [diff] [blame] | 2321 | weston_view_geometry_dirty(child->view); |
Giulio Camuffo | 412e6a5 | 2014-07-09 22:12:56 +0300 | [diff] [blame] | 2322 | prev = container_of(shsurf->view->layer_link.link.prev, |
| 2323 | struct weston_layer_entry, link); |
| 2324 | weston_layer_entry_remove(&child->view->layer_link); |
| 2325 | weston_layer_entry_insert(prev, |
| 2326 | &child->view->layer_link); |
Philip Withnall | 648a4dd | 2013-11-25 18:01:44 +0000 | [diff] [blame] | 2327 | weston_view_geometry_dirty(child->view); |
| 2328 | weston_surface_damage(child->surface); |
| 2329 | |
| 2330 | /* Recurse. We don’t expect this to recurse very far (if |
| 2331 | * at all) because that would imply we have transient |
| 2332 | * (or popup) children of transient surfaces, which |
| 2333 | * would be unusual. */ |
| 2334 | shell_surface_update_child_surface_layers(child); |
| 2335 | } |
| 2336 | } |
| 2337 | } |
| 2338 | |
Philip Withnall | e1d75ae | 2013-11-25 18:01:41 +0000 | [diff] [blame] | 2339 | /* 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] | 2340 | * geometry to ensure the changes are redrawn. |
| 2341 | * |
| 2342 | * If any child surfaces exist and are mapped, ensure they’re in the same layer |
| 2343 | * as this surface. */ |
Philip Withnall | e1d75ae | 2013-11-25 18:01:41 +0000 | [diff] [blame] | 2344 | static void |
| 2345 | shell_surface_update_layer(struct shell_surface *shsurf) |
| 2346 | { |
Giulio Camuffo | 412e6a5 | 2014-07-09 22:12:56 +0300 | [diff] [blame] | 2347 | struct weston_layer_entry *new_layer_link; |
Philip Withnall | e1d75ae | 2013-11-25 18:01:41 +0000 | [diff] [blame] | 2348 | |
| 2349 | new_layer_link = shell_surface_calculate_layer_link(shsurf); |
| 2350 | |
Ander Conselvan de Oliveira | ef6a7e4 | 2014-04-30 14:15:14 +0300 | [diff] [blame] | 2351 | if (new_layer_link == NULL) |
| 2352 | return; |
Philip Withnall | e1d75ae | 2013-11-25 18:01:41 +0000 | [diff] [blame] | 2353 | if (new_layer_link == &shsurf->view->layer_link) |
| 2354 | return; |
| 2355 | |
| 2356 | weston_view_geometry_dirty(shsurf->view); |
Giulio Camuffo | 412e6a5 | 2014-07-09 22:12:56 +0300 | [diff] [blame] | 2357 | weston_layer_entry_remove(&shsurf->view->layer_link); |
| 2358 | weston_layer_entry_insert(new_layer_link, &shsurf->view->layer_link); |
Philip Withnall | e1d75ae | 2013-11-25 18:01:41 +0000 | [diff] [blame] | 2359 | weston_view_geometry_dirty(shsurf->view); |
| 2360 | weston_surface_damage(shsurf->surface); |
Philip Withnall | 648a4dd | 2013-11-25 18:01:44 +0000 | [diff] [blame] | 2361 | |
| 2362 | shell_surface_update_child_surface_layers(shsurf); |
Philip Withnall | e1d75ae | 2013-11-25 18:01:41 +0000 | [diff] [blame] | 2363 | } |
| 2364 | |
Alexander Larsson | f82b6ca | 2013-05-28 16:23:39 +0200 | [diff] [blame] | 2365 | static void |
Philip Withnall | dc4332f | 2013-11-25 18:01:38 +0000 | [diff] [blame] | 2366 | shell_surface_set_parent(struct shell_surface *shsurf, |
| 2367 | struct weston_surface *parent) |
| 2368 | { |
| 2369 | shsurf->parent = parent; |
Philip Withnall | 648a4dd | 2013-11-25 18:01:44 +0000 | [diff] [blame] | 2370 | |
| 2371 | wl_list_remove(&shsurf->children_link); |
| 2372 | wl_list_init(&shsurf->children_link); |
| 2373 | |
| 2374 | /* Insert into the parent surface’s child list. */ |
| 2375 | if (parent != NULL) { |
| 2376 | struct shell_surface *parent_shsurf = get_shell_surface(parent); |
| 2377 | if (parent_shsurf != NULL) |
| 2378 | wl_list_insert(&parent_shsurf->children_list, |
| 2379 | &shsurf->children_link); |
| 2380 | } |
Philip Withnall | dc4332f | 2013-11-25 18:01:38 +0000 | [diff] [blame] | 2381 | } |
| 2382 | |
| 2383 | static void |
Philip Withnall | 352e7ed | 2013-11-25 18:01:35 +0000 | [diff] [blame] | 2384 | shell_surface_set_output(struct shell_surface *shsurf, |
| 2385 | struct weston_output *output) |
| 2386 | { |
| 2387 | struct weston_surface *es = shsurf->surface; |
| 2388 | |
| 2389 | /* get the default output, if the client set it as NULL |
| 2390 | check whether the ouput is available */ |
| 2391 | if (output) |
| 2392 | shsurf->output = output; |
| 2393 | else if (es->output) |
| 2394 | shsurf->output = es->output; |
| 2395 | else |
| 2396 | shsurf->output = get_default_output(es->compositor); |
| 2397 | } |
| 2398 | |
| 2399 | static void |
Rafael Antognolli | 03b1659 | 2013-12-03 15:35:42 -0200 | [diff] [blame] | 2400 | surface_clear_next_states(struct shell_surface *shsurf) |
| 2401 | { |
| 2402 | shsurf->next_state.maximized = false; |
| 2403 | shsurf->next_state.fullscreen = false; |
| 2404 | |
| 2405 | if ((shsurf->next_state.maximized != shsurf->state.maximized) || |
| 2406 | (shsurf->next_state.fullscreen != shsurf->state.fullscreen)) |
| 2407 | shsurf->state_changed = true; |
| 2408 | } |
| 2409 | |
| 2410 | static void |
Philip Withnall | becb77e | 2013-11-25 18:01:30 +0000 | [diff] [blame] | 2411 | set_toplevel(struct shell_surface *shsurf) |
| 2412 | { |
Kristian Høgsberg | 41fbf6f | 2013-12-05 22:31:25 -0800 | [diff] [blame] | 2413 | shell_surface_set_parent(shsurf, NULL); |
| 2414 | surface_clear_next_states(shsurf); |
Kristian Høgsberg | c8f8dd8 | 2013-12-05 23:20:33 -0800 | [diff] [blame] | 2415 | shsurf->type = SHELL_SURFACE_TOPLEVEL; |
Philip Withnall | 648a4dd | 2013-11-25 18:01:44 +0000 | [diff] [blame] | 2416 | |
| 2417 | /* The layer_link is updated in set_surface_type(), |
| 2418 | * called from configure. */ |
Philip Withnall | becb77e | 2013-11-25 18:01:30 +0000 | [diff] [blame] | 2419 | } |
| 2420 | |
| 2421 | static void |
| 2422 | shell_surface_set_toplevel(struct wl_client *client, |
| 2423 | struct wl_resource *resource) |
| 2424 | { |
| 2425 | struct shell_surface *surface = wl_resource_get_user_data(resource); |
| 2426 | |
| 2427 | set_toplevel(surface); |
| 2428 | } |
| 2429 | |
| 2430 | static void |
| 2431 | set_transient(struct shell_surface *shsurf, |
| 2432 | struct weston_surface *parent, int x, int y, uint32_t flags) |
| 2433 | { |
Philip Withnall | dc4332f | 2013-11-25 18:01:38 +0000 | [diff] [blame] | 2434 | assert(parent != NULL); |
| 2435 | |
Kristian Høgsberg | 9f7e331 | 2014-01-02 22:40:37 -0800 | [diff] [blame] | 2436 | shell_surface_set_parent(shsurf, parent); |
| 2437 | |
| 2438 | surface_clear_next_states(shsurf); |
| 2439 | |
Philip Withnall | becb77e | 2013-11-25 18:01:30 +0000 | [diff] [blame] | 2440 | shsurf->transient.x = x; |
| 2441 | shsurf->transient.y = y; |
| 2442 | shsurf->transient.flags = flags; |
Philip Withnall | dc4332f | 2013-11-25 18:01:38 +0000 | [diff] [blame] | 2443 | |
Rafael Antognolli | ed207b4 | 2013-12-03 15:35:43 -0200 | [diff] [blame] | 2444 | shsurf->next_state.relative = true; |
Kristian Høgsberg | a1df7ac | 2013-12-31 15:01:01 -0800 | [diff] [blame] | 2445 | shsurf->state_changed = true; |
Kristian Høgsberg | c8f8dd8 | 2013-12-05 23:20:33 -0800 | [diff] [blame] | 2446 | shsurf->type = SHELL_SURFACE_TOPLEVEL; |
Philip Withnall | 648a4dd | 2013-11-25 18:01:44 +0000 | [diff] [blame] | 2447 | |
| 2448 | /* The layer_link is updated in set_surface_type(), |
| 2449 | * called from configure. */ |
Philip Withnall | becb77e | 2013-11-25 18:01:30 +0000 | [diff] [blame] | 2450 | } |
| 2451 | |
| 2452 | static void |
| 2453 | shell_surface_set_transient(struct wl_client *client, |
| 2454 | struct wl_resource *resource, |
| 2455 | struct wl_resource *parent_resource, |
| 2456 | int x, int y, uint32_t flags) |
| 2457 | { |
| 2458 | struct shell_surface *shsurf = wl_resource_get_user_data(resource); |
| 2459 | struct weston_surface *parent = |
| 2460 | wl_resource_get_user_data(parent_resource); |
| 2461 | |
| 2462 | set_transient(shsurf, parent, x, y, flags); |
| 2463 | } |
| 2464 | |
| 2465 | static void |
| 2466 | set_fullscreen(struct shell_surface *shsurf, |
| 2467 | uint32_t method, |
| 2468 | uint32_t framerate, |
| 2469 | struct weston_output *output) |
| 2470 | { |
Philip Withnall | 352e7ed | 2013-11-25 18:01:35 +0000 | [diff] [blame] | 2471 | shell_surface_set_output(shsurf, output); |
Jasper St. Pierre | 6458ec3 | 2014-04-11 16:00:31 -0700 | [diff] [blame] | 2472 | shsurf->type = SHELL_SURFACE_TOPLEVEL; |
Philip Withnall | becb77e | 2013-11-25 18:01:30 +0000 | [diff] [blame] | 2473 | |
| 2474 | shsurf->fullscreen_output = shsurf->output; |
| 2475 | shsurf->fullscreen.type = method; |
| 2476 | shsurf->fullscreen.framerate = framerate; |
Philip Withnall | dc4332f | 2013-11-25 18:01:38 +0000 | [diff] [blame] | 2477 | |
Jasper St. Pierre | 6458ec3 | 2014-04-11 16:00:31 -0700 | [diff] [blame] | 2478 | send_configure_for_surface(shsurf); |
Philip Withnall | becb77e | 2013-11-25 18:01:30 +0000 | [diff] [blame] | 2479 | } |
| 2480 | |
| 2481 | static void |
Zhang, Xiong Y | 3123693 | 2013-12-13 22:10:57 +0200 | [diff] [blame] | 2482 | weston_view_set_initial_position(struct weston_view *view, |
| 2483 | struct desktop_shell *shell); |
| 2484 | |
| 2485 | static void |
Philip Withnall | becb77e | 2013-11-25 18:01:30 +0000 | [diff] [blame] | 2486 | unset_fullscreen(struct shell_surface *shsurf) |
Alex Wu | 4539b08 | 2012-03-01 12:57:46 +0800 | [diff] [blame] | 2487 | { |
Philip Withnall | f85fe84 | 2013-11-25 18:01:37 +0000 | [diff] [blame] | 2488 | /* Unset the fullscreen output, driver configuration and transforms. */ |
Alex Wu | bd3354b | 2012-04-17 17:20:49 +0800 | [diff] [blame] | 2489 | if (shsurf->fullscreen.type == WL_SHELL_SURFACE_FULLSCREEN_METHOD_DRIVER && |
| 2490 | shell_surface_is_top_fullscreen(shsurf)) { |
Alexander Larsson | f82b6ca | 2013-05-28 16:23:39 +0200 | [diff] [blame] | 2491 | restore_output_mode(shsurf->fullscreen_output); |
Alex Wu | bd3354b | 2012-04-17 17:20:49 +0800 | [diff] [blame] | 2492 | } |
Philip Withnall | f85fe84 | 2013-11-25 18:01:37 +0000 | [diff] [blame] | 2493 | |
Alex Wu | 4539b08 | 2012-03-01 12:57:46 +0800 | [diff] [blame] | 2494 | shsurf->fullscreen.type = WL_SHELL_SURFACE_FULLSCREEN_METHOD_DEFAULT; |
| 2495 | shsurf->fullscreen.framerate = 0; |
Philip Withnall | f85fe84 | 2013-11-25 18:01:37 +0000 | [diff] [blame] | 2496 | |
Alex Wu | 4539b08 | 2012-03-01 12:57:46 +0800 | [diff] [blame] | 2497 | wl_list_remove(&shsurf->fullscreen.transform.link); |
| 2498 | wl_list_init(&shsurf->fullscreen.transform.link); |
Philip Withnall | f85fe84 | 2013-11-25 18:01:37 +0000 | [diff] [blame] | 2499 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 2500 | if (shsurf->fullscreen.black_view) |
| 2501 | weston_surface_destroy(shsurf->fullscreen.black_view->surface); |
| 2502 | shsurf->fullscreen.black_view = NULL; |
Philip Withnall | f85fe84 | 2013-11-25 18:01:37 +0000 | [diff] [blame] | 2503 | |
Zhang, Xiong Y | 3123693 | 2013-12-13 22:10:57 +0200 | [diff] [blame] | 2504 | if (shsurf->saved_position_valid) |
| 2505 | weston_view_set_position(shsurf->view, |
| 2506 | shsurf->saved_x, shsurf->saved_y); |
| 2507 | else |
| 2508 | weston_view_set_initial_position(shsurf->view, shsurf->shell); |
| 2509 | |
Alex Wu | 7bcb8bd | 2012-04-27 09:07:24 +0800 | [diff] [blame] | 2510 | if (shsurf->saved_rotation_valid) { |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 2511 | wl_list_insert(&shsurf->view->geometry.transformation_list, |
Philip Withnall | becb77e | 2013-11-25 18:01:30 +0000 | [diff] [blame] | 2512 | &shsurf->rotation.transform.link); |
Alex Wu | 7bcb8bd | 2012-04-27 09:07:24 +0800 | [diff] [blame] | 2513 | shsurf->saved_rotation_valid = false; |
| 2514 | } |
Rafal Mielniczuk | 3e3862c | 2012-10-07 20:25:36 +0200 | [diff] [blame] | 2515 | |
Philip Withnall | e1d75ae | 2013-11-25 18:01:41 +0000 | [diff] [blame] | 2516 | /* Layer is updated in set_surface_type(). */ |
Alex Wu | 4539b08 | 2012-03-01 12:57:46 +0800 | [diff] [blame] | 2517 | } |
| 2518 | |
Rafal Mielniczuk | fffdcdd | 2013-03-11 19:26:54 +0100 | [diff] [blame] | 2519 | static void |
Philip Withnall | becb77e | 2013-11-25 18:01:30 +0000 | [diff] [blame] | 2520 | shell_surface_set_fullscreen(struct wl_client *client, |
| 2521 | struct wl_resource *resource, |
| 2522 | uint32_t method, |
| 2523 | uint32_t framerate, |
| 2524 | struct wl_resource *output_resource) |
| 2525 | { |
| 2526 | struct shell_surface *shsurf = wl_resource_get_user_data(resource); |
| 2527 | struct weston_output *output; |
| 2528 | |
| 2529 | if (output_resource) |
| 2530 | output = wl_resource_get_user_data(output_resource); |
| 2531 | else |
| 2532 | output = NULL; |
| 2533 | |
Rafael Antognolli | 4b99a40 | 2013-12-03 15:35:44 -0200 | [diff] [blame] | 2534 | shell_surface_set_parent(shsurf, NULL); |
| 2535 | |
Rafael Antognolli | 03b1659 | 2013-12-03 15:35:42 -0200 | [diff] [blame] | 2536 | surface_clear_next_states(shsurf); |
Jasper St. Pierre | 8c6aa45 | 2014-02-08 18:29:49 -0500 | [diff] [blame] | 2537 | shsurf->next_state.fullscreen = true; |
| 2538 | shsurf->state_changed = true; |
Jasper St. Pierre | 6458ec3 | 2014-04-11 16:00:31 -0700 | [diff] [blame] | 2539 | set_fullscreen(shsurf, method, framerate, output); |
Philip Withnall | becb77e | 2013-11-25 18:01:30 +0000 | [diff] [blame] | 2540 | } |
| 2541 | |
| 2542 | static void |
| 2543 | set_popup(struct shell_surface *shsurf, |
| 2544 | struct weston_surface *parent, |
| 2545 | struct weston_seat *seat, |
| 2546 | uint32_t serial, |
| 2547 | int32_t x, |
| 2548 | int32_t y) |
| 2549 | { |
Philip Withnall | dc4332f | 2013-11-25 18:01:38 +0000 | [diff] [blame] | 2550 | assert(parent != NULL); |
| 2551 | |
Philip Withnall | becb77e | 2013-11-25 18:01:30 +0000 | [diff] [blame] | 2552 | shsurf->popup.shseat = get_shell_seat(seat); |
| 2553 | shsurf->popup.serial = serial; |
| 2554 | shsurf->popup.x = x; |
| 2555 | shsurf->popup.y = y; |
Philip Withnall | dc4332f | 2013-11-25 18:01:38 +0000 | [diff] [blame] | 2556 | |
Kristian Høgsberg | c8f8dd8 | 2013-12-05 23:20:33 -0800 | [diff] [blame] | 2557 | shsurf->type = SHELL_SURFACE_POPUP; |
Philip Withnall | becb77e | 2013-11-25 18:01:30 +0000 | [diff] [blame] | 2558 | } |
| 2559 | |
| 2560 | static void |
| 2561 | shell_surface_set_popup(struct wl_client *client, |
| 2562 | struct wl_resource *resource, |
| 2563 | struct wl_resource *seat_resource, |
| 2564 | uint32_t serial, |
| 2565 | struct wl_resource *parent_resource, |
| 2566 | int32_t x, int32_t y, uint32_t flags) |
| 2567 | { |
| 2568 | struct shell_surface *shsurf = wl_resource_get_user_data(resource); |
Rafael Antognolli | 4b99a40 | 2013-12-03 15:35:44 -0200 | [diff] [blame] | 2569 | struct weston_surface *parent = |
| 2570 | wl_resource_get_user_data(parent_resource); |
| 2571 | |
| 2572 | shell_surface_set_parent(shsurf, parent); |
Philip Withnall | becb77e | 2013-11-25 18:01:30 +0000 | [diff] [blame] | 2573 | |
Rafael Antognolli | 03b1659 | 2013-12-03 15:35:42 -0200 | [diff] [blame] | 2574 | surface_clear_next_states(shsurf); |
Philip Withnall | becb77e | 2013-11-25 18:01:30 +0000 | [diff] [blame] | 2575 | set_popup(shsurf, |
Rafael Antognolli | 4b99a40 | 2013-12-03 15:35:44 -0200 | [diff] [blame] | 2576 | parent, |
Philip Withnall | becb77e | 2013-11-25 18:01:30 +0000 | [diff] [blame] | 2577 | wl_resource_get_user_data(seat_resource), |
| 2578 | serial, x, y); |
| 2579 | } |
| 2580 | |
| 2581 | static void |
Philip Withnall | becb77e | 2013-11-25 18:01:30 +0000 | [diff] [blame] | 2582 | unset_maximized(struct shell_surface *shsurf) |
Rafal Mielniczuk | fffdcdd | 2013-03-11 19:26:54 +0100 | [diff] [blame] | 2583 | { |
Rafal Mielniczuk | fffdcdd | 2013-03-11 19:26:54 +0100 | [diff] [blame] | 2584 | /* undo all maximized things here */ |
| 2585 | shsurf->output = get_default_output(shsurf->surface->compositor); |
Zhang, Xiong Y | 3123693 | 2013-12-13 22:10:57 +0200 | [diff] [blame] | 2586 | |
| 2587 | if (shsurf->saved_position_valid) |
| 2588 | weston_view_set_position(shsurf->view, |
| 2589 | shsurf->saved_x, shsurf->saved_y); |
| 2590 | else |
| 2591 | weston_view_set_initial_position(shsurf->view, shsurf->shell); |
Rafal Mielniczuk | fffdcdd | 2013-03-11 19:26:54 +0100 | [diff] [blame] | 2592 | |
| 2593 | if (shsurf->saved_rotation_valid) { |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 2594 | wl_list_insert(&shsurf->view->geometry.transformation_list, |
| 2595 | &shsurf->rotation.transform.link); |
Rafal Mielniczuk | fffdcdd | 2013-03-11 19:26:54 +0100 | [diff] [blame] | 2596 | shsurf->saved_rotation_valid = false; |
| 2597 | } |
| 2598 | |
Philip Withnall | e1d75ae | 2013-11-25 18:01:41 +0000 | [diff] [blame] | 2599 | /* Layer is updated in set_surface_type(). */ |
Rafal Mielniczuk | fffdcdd | 2013-03-11 19:26:54 +0100 | [diff] [blame] | 2600 | } |
| 2601 | |
Philip Withnall | becb77e | 2013-11-25 18:01:30 +0000 | [diff] [blame] | 2602 | static void |
Manuel Bachmann | 50c87db | 2014-02-26 15:52:13 +0100 | [diff] [blame] | 2603 | set_minimized(struct weston_surface *surface, uint32_t is_true) |
| 2604 | { |
| 2605 | struct shell_surface *shsurf; |
| 2606 | struct workspace *current_ws; |
| 2607 | struct weston_seat *seat; |
| 2608 | struct weston_surface *focus; |
| 2609 | struct weston_view *view; |
| 2610 | |
| 2611 | view = get_default_view(surface); |
| 2612 | if (!view) |
| 2613 | return; |
| 2614 | |
| 2615 | assert(weston_surface_get_main_surface(view->surface) == view->surface); |
| 2616 | |
| 2617 | shsurf = get_shell_surface(surface); |
| 2618 | current_ws = get_current_workspace(shsurf->shell); |
| 2619 | |
Giulio Camuffo | 412e6a5 | 2014-07-09 22:12:56 +0300 | [diff] [blame] | 2620 | weston_layer_entry_remove(&view->layer_link); |
Manuel Bachmann | 50c87db | 2014-02-26 15:52:13 +0100 | [diff] [blame] | 2621 | /* hide or show, depending on the state */ |
| 2622 | if (is_true) { |
Giulio Camuffo | 412e6a5 | 2014-07-09 22:12:56 +0300 | [diff] [blame] | 2623 | 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] | 2624 | |
| 2625 | drop_focus_state(shsurf->shell, current_ws, view->surface); |
| 2626 | wl_list_for_each(seat, &shsurf->shell->compositor->seat_list, link) { |
| 2627 | if (!seat->keyboard) |
| 2628 | continue; |
| 2629 | focus = weston_surface_get_main_surface(seat->keyboard->focus); |
| 2630 | if (focus == view->surface) |
| 2631 | weston_keyboard_set_focus(seat->keyboard, NULL); |
| 2632 | } |
| 2633 | } |
| 2634 | else { |
Giulio Camuffo | 412e6a5 | 2014-07-09 22:12:56 +0300 | [diff] [blame] | 2635 | weston_layer_entry_insert(¤t_ws->layer.view_list, &view->layer_link); |
Manuel Bachmann | 50c87db | 2014-02-26 15:52:13 +0100 | [diff] [blame] | 2636 | |
| 2637 | wl_list_for_each(seat, &shsurf->shell->compositor->seat_list, link) { |
| 2638 | if (!seat->keyboard) |
| 2639 | continue; |
Emilio Pozuelo Monfort | 9e7c759 | 2014-01-30 14:01:10 +0100 | [diff] [blame] | 2640 | activate(shsurf->shell, view->surface, seat, true); |
Manuel Bachmann | 50c87db | 2014-02-26 15:52:13 +0100 | [diff] [blame] | 2641 | } |
| 2642 | } |
| 2643 | |
| 2644 | shell_surface_update_child_surface_layers(shsurf); |
| 2645 | |
| 2646 | weston_view_damage_below(view); |
| 2647 | } |
| 2648 | |
| 2649 | static void |
Philip Withnall | becb77e | 2013-11-25 18:01:30 +0000 | [diff] [blame] | 2650 | shell_surface_set_maximized(struct wl_client *client, |
| 2651 | struct wl_resource *resource, |
| 2652 | struct wl_resource *output_resource) |
| 2653 | { |
| 2654 | struct shell_surface *shsurf = wl_resource_get_user_data(resource); |
| 2655 | struct weston_output *output; |
| 2656 | |
Jasper St. Pierre | 9aa8ce6 | 2014-04-11 16:18:54 -0700 | [diff] [blame] | 2657 | surface_clear_next_states(shsurf); |
| 2658 | shsurf->next_state.maximized = true; |
| 2659 | shsurf->state_changed = true; |
| 2660 | |
| 2661 | shsurf->type = SHELL_SURFACE_TOPLEVEL; |
| 2662 | shell_surface_set_parent(shsurf, NULL); |
| 2663 | |
Philip Withnall | becb77e | 2013-11-25 18:01:30 +0000 | [diff] [blame] | 2664 | if (output_resource) |
| 2665 | output = wl_resource_get_user_data(output_resource); |
| 2666 | else |
| 2667 | output = NULL; |
| 2668 | |
Jasper St. Pierre | 9aa8ce6 | 2014-04-11 16:18:54 -0700 | [diff] [blame] | 2669 | shell_surface_set_output(shsurf, output); |
Rafael Antognolli | 4b99a40 | 2013-12-03 15:35:44 -0200 | [diff] [blame] | 2670 | |
Jasper St. Pierre | 9aa8ce6 | 2014-04-11 16:18:54 -0700 | [diff] [blame] | 2671 | send_configure_for_surface(shsurf); |
Philip Withnall | becb77e | 2013-11-25 18:01:30 +0000 | [diff] [blame] | 2672 | } |
| 2673 | |
Philip Withnall | e1d75ae | 2013-11-25 18:01:41 +0000 | [diff] [blame] | 2674 | /* This is only ever called from set_surface_type(), so there’s no need to |
| 2675 | * update layer_links here, since they’ll be updated when we return. */ |
Pekka Paalanen | 9826223 | 2011-12-01 10:42:22 +0200 | [diff] [blame] | 2676 | static int |
Philip Withnall | becb77e | 2013-11-25 18:01:30 +0000 | [diff] [blame] | 2677 | reset_surface_type(struct shell_surface *surface) |
Pekka Paalanen | 9826223 | 2011-12-01 10:42:22 +0200 | [diff] [blame] | 2678 | { |
Rafael Antognolli | 03b1659 | 2013-12-03 15:35:42 -0200 | [diff] [blame] | 2679 | if (surface->state.fullscreen) |
Philip Withnall | becb77e | 2013-11-25 18:01:30 +0000 | [diff] [blame] | 2680 | unset_fullscreen(surface); |
Rafael Antognolli | 03b1659 | 2013-12-03 15:35:42 -0200 | [diff] [blame] | 2681 | if (surface->state.maximized) |
Philip Withnall | becb77e | 2013-11-25 18:01:30 +0000 | [diff] [blame] | 2682 | unset_maximized(surface); |
Pekka Paalanen | 9826223 | 2011-12-01 10:42:22 +0200 | [diff] [blame] | 2683 | |
Pekka Paalanen | 9826223 | 2011-12-01 10:42:22 +0200 | [diff] [blame] | 2684 | return 0; |
| 2685 | } |
| 2686 | |
Kristian Høgsberg | 4cca349 | 2011-01-18 07:53:49 -0500 | [diff] [blame] | 2687 | static void |
Rafael Antognolli | 03b1659 | 2013-12-03 15:35:42 -0200 | [diff] [blame] | 2688 | set_full_output(struct shell_surface *shsurf) |
| 2689 | { |
| 2690 | shsurf->saved_x = shsurf->view->geometry.x; |
| 2691 | shsurf->saved_y = shsurf->view->geometry.y; |
Rafael Antognolli | 3c4e3f7 | 2013-12-03 15:35:46 -0200 | [diff] [blame] | 2692 | shsurf->saved_width = shsurf->surface->width; |
| 2693 | shsurf->saved_height = shsurf->surface->height; |
| 2694 | shsurf->saved_size_valid = true; |
Rafael Antognolli | 03b1659 | 2013-12-03 15:35:42 -0200 | [diff] [blame] | 2695 | shsurf->saved_position_valid = true; |
| 2696 | |
| 2697 | if (!wl_list_empty(&shsurf->rotation.transform.link)) { |
| 2698 | wl_list_remove(&shsurf->rotation.transform.link); |
| 2699 | wl_list_init(&shsurf->rotation.transform.link); |
| 2700 | weston_view_geometry_dirty(shsurf->view); |
| 2701 | shsurf->saved_rotation_valid = true; |
| 2702 | } |
| 2703 | } |
| 2704 | |
| 2705 | static void |
Kristian Høgsberg | 7f366e7 | 2012-04-27 17:20:01 -0400 | [diff] [blame] | 2706 | set_surface_type(struct shell_surface *shsurf) |
| 2707 | { |
Kristian Høgsberg | 8150b19 | 2012-06-27 10:22:58 -0400 | [diff] [blame] | 2708 | struct weston_surface *pes = shsurf->parent; |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 2709 | struct weston_view *pev = get_default_view(pes); |
Kristian Høgsberg | 7f366e7 | 2012-04-27 17:20:01 -0400 | [diff] [blame] | 2710 | |
Philip Withnall | becb77e | 2013-11-25 18:01:30 +0000 | [diff] [blame] | 2711 | reset_surface_type(shsurf); |
Kristian Høgsberg | 7f366e7 | 2012-04-27 17:20:01 -0400 | [diff] [blame] | 2712 | |
Rafael Antognolli | 03b1659 | 2013-12-03 15:35:42 -0200 | [diff] [blame] | 2713 | shsurf->state = shsurf->next_state; |
Rafael Antognolli | 03b1659 | 2013-12-03 15:35:42 -0200 | [diff] [blame] | 2714 | shsurf->state_changed = false; |
Kristian Høgsberg | 7f366e7 | 2012-04-27 17:20:01 -0400 | [diff] [blame] | 2715 | |
| 2716 | switch (shsurf->type) { |
| 2717 | case SHELL_SURFACE_TOPLEVEL: |
Rafael Antognolli | ed207b4 | 2013-12-03 15:35:43 -0200 | [diff] [blame] | 2718 | if (shsurf->state.maximized || shsurf->state.fullscreen) { |
Rafael Antognolli | 03b1659 | 2013-12-03 15:35:42 -0200 | [diff] [blame] | 2719 | set_full_output(shsurf); |
Rafael Antognolli | ed207b4 | 2013-12-03 15:35:43 -0200 | [diff] [blame] | 2720 | } else if (shsurf->state.relative && pev) { |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 2721 | weston_view_set_position(shsurf->view, |
| 2722 | pev->geometry.x + shsurf->transient.x, |
| 2723 | pev->geometry.y + shsurf->transient.y); |
Rafael Antognolli | ed207b4 | 2013-12-03 15:35:43 -0200 | [diff] [blame] | 2724 | } |
Rafael Antognolli | 44a3162 | 2013-12-04 18:37:16 -0200 | [diff] [blame] | 2725 | break; |
Kristian Høgsberg | 7f366e7 | 2012-04-27 17:20:01 -0400 | [diff] [blame] | 2726 | |
Tiago Vignatti | fb2adba | 2013-06-12 15:43:21 -0300 | [diff] [blame] | 2727 | case SHELL_SURFACE_XWAYLAND: |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 2728 | weston_view_set_position(shsurf->view, shsurf->transient.x, |
| 2729 | shsurf->transient.y); |
Tiago Vignatti | fb2adba | 2013-06-12 15:43:21 -0300 | [diff] [blame] | 2730 | break; |
| 2731 | |
Philip Withnall | 0f640e2 | 2013-11-25 18:01:31 +0000 | [diff] [blame] | 2732 | case SHELL_SURFACE_POPUP: |
| 2733 | case SHELL_SURFACE_NONE: |
Kristian Høgsberg | 7f366e7 | 2012-04-27 17:20:01 -0400 | [diff] [blame] | 2734 | default: |
| 2735 | break; |
| 2736 | } |
Philip Withnall | e1d75ae | 2013-11-25 18:01:41 +0000 | [diff] [blame] | 2737 | |
| 2738 | /* Update the surface’s layer. */ |
| 2739 | shell_surface_update_layer(shsurf); |
Kristian Høgsberg | 7f366e7 | 2012-04-27 17:20:01 -0400 | [diff] [blame] | 2740 | } |
| 2741 | |
Tiago Vignatti | be14326 | 2012-04-16 17:31:41 +0300 | [diff] [blame] | 2742 | static struct desktop_shell * |
Juan Zhao | 96879df | 2012-02-07 08:45:41 +0800 | [diff] [blame] | 2743 | shell_surface_get_shell(struct shell_surface *shsurf) |
Pekka Paalanen | af0e34c | 2011-12-02 10:59:17 +0200 | [diff] [blame] | 2744 | { |
Kristian Høgsberg | 02e79dc | 2012-04-12 09:55:26 -0400 | [diff] [blame] | 2745 | return shsurf->shell; |
Juan Zhao | 96879df | 2012-02-07 08:45:41 +0800 | [diff] [blame] | 2746 | } |
| 2747 | |
Alex Wu | 2185843 | 2012-04-01 20:13:08 +0800 | [diff] [blame] | 2748 | static void |
Jason Ekstrand | 918f2dd | 2013-12-02 21:01:53 -0600 | [diff] [blame] | 2749 | 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] | 2750 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 2751 | static struct weston_view * |
Alex Wu | 4539b08 | 2012-03-01 12:57:46 +0800 | [diff] [blame] | 2752 | create_black_surface(struct weston_compositor *ec, |
Alex Wu | 2185843 | 2012-04-01 20:13:08 +0800 | [diff] [blame] | 2753 | struct weston_surface *fs_surface, |
John Kåre Alsaker | 490d02a | 2012-09-30 02:57:21 +0200 | [diff] [blame] | 2754 | float x, float y, int w, int h) |
Alex Wu | 4539b08 | 2012-03-01 12:57:46 +0800 | [diff] [blame] | 2755 | { |
| 2756 | struct weston_surface *surface = NULL; |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 2757 | struct weston_view *view; |
Alex Wu | 4539b08 | 2012-03-01 12:57:46 +0800 | [diff] [blame] | 2758 | |
| 2759 | surface = weston_surface_create(ec); |
| 2760 | if (surface == NULL) { |
Martin Minarik | 6d11836 | 2012-06-07 18:01:59 +0200 | [diff] [blame] | 2761 | weston_log("no memory\n"); |
Alex Wu | 4539b08 | 2012-03-01 12:57:46 +0800 | [diff] [blame] | 2762 | return NULL; |
| 2763 | } |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 2764 | view = weston_view_create(surface); |
| 2765 | if (surface == NULL) { |
| 2766 | weston_log("no memory\n"); |
| 2767 | weston_surface_destroy(surface); |
| 2768 | return NULL; |
| 2769 | } |
Alex Wu | 4539b08 | 2012-03-01 12:57:46 +0800 | [diff] [blame] | 2770 | |
Alex Wu | 2185843 | 2012-04-01 20:13:08 +0800 | [diff] [blame] | 2771 | surface->configure = black_surface_configure; |
Giulio Camuffo | 7fe01b1 | 2013-03-28 18:02:42 +0100 | [diff] [blame] | 2772 | surface->configure_private = fs_surface; |
Alex Wu | 4539b08 | 2012-03-01 12:57:46 +0800 | [diff] [blame] | 2773 | weston_surface_set_color(surface, 0.0, 0.0, 0.0, 1); |
Pekka Paalanen | 71f6f3b | 2012-10-10 12:49:26 +0300 | [diff] [blame] | 2774 | pixman_region32_fini(&surface->opaque); |
Kristian Høgsberg | 61f00f5 | 2012-08-03 16:31:36 -0400 | [diff] [blame] | 2775 | pixman_region32_init_rect(&surface->opaque, 0, 0, w, h); |
Jonas Ådahl | 33619a4 | 2013-01-15 21:25:55 +0100 | [diff] [blame] | 2776 | pixman_region32_fini(&surface->input); |
| 2777 | pixman_region32_init_rect(&surface->input, 0, 0, w, h); |
Jason Ekstrand | 918f2dd | 2013-12-02 21:01:53 -0600 | [diff] [blame] | 2778 | |
Jason Ekstrand | 6228ee2 | 2014-01-01 15:58:57 -0600 | [diff] [blame] | 2779 | weston_surface_set_size(surface, w, h); |
Jason Ekstrand | 918f2dd | 2013-12-02 21:01:53 -0600 | [diff] [blame] | 2780 | weston_view_set_position(view, x, y); |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 2781 | |
| 2782 | return view; |
Alex Wu | 4539b08 | 2012-03-01 12:57:46 +0800 | [diff] [blame] | 2783 | } |
| 2784 | |
Philip Withnall | ed8f1a9 | 2013-11-25 18:01:43 +0000 | [diff] [blame] | 2785 | static void |
| 2786 | shell_ensure_fullscreen_black_view(struct shell_surface *shsurf) |
| 2787 | { |
| 2788 | struct weston_output *output = shsurf->fullscreen_output; |
| 2789 | |
Rafael Antognolli | 03b1659 | 2013-12-03 15:35:42 -0200 | [diff] [blame] | 2790 | assert(shsurf->state.fullscreen); |
Philip Withnall | ed8f1a9 | 2013-11-25 18:01:43 +0000 | [diff] [blame] | 2791 | |
| 2792 | if (!shsurf->fullscreen.black_view) |
| 2793 | shsurf->fullscreen.black_view = |
| 2794 | create_black_surface(shsurf->surface->compositor, |
| 2795 | shsurf->surface, |
| 2796 | output->x, output->y, |
| 2797 | output->width, |
| 2798 | output->height); |
| 2799 | |
| 2800 | weston_view_geometry_dirty(shsurf->fullscreen.black_view); |
Giulio Camuffo | 412e6a5 | 2014-07-09 22:12:56 +0300 | [diff] [blame] | 2801 | weston_layer_entry_remove(&shsurf->fullscreen.black_view->layer_link); |
| 2802 | weston_layer_entry_insert(&shsurf->view->layer_link, |
| 2803 | &shsurf->fullscreen.black_view->layer_link); |
Philip Withnall | ed8f1a9 | 2013-11-25 18:01:43 +0000 | [diff] [blame] | 2804 | weston_view_geometry_dirty(shsurf->fullscreen.black_view); |
| 2805 | weston_surface_damage(shsurf->surface); |
Emilio Pozuelo Monfort | 9e7c759 | 2014-01-30 14:01:10 +0100 | [diff] [blame] | 2806 | |
| 2807 | shsurf->state.lowered = false; |
Philip Withnall | ed8f1a9 | 2013-11-25 18:01:43 +0000 | [diff] [blame] | 2808 | } |
| 2809 | |
Alex Wu | 4539b08 | 2012-03-01 12:57:46 +0800 | [diff] [blame] | 2810 | /* Create black surface and append it to the associated fullscreen surface. |
| 2811 | * Handle size dismatch and positioning according to the method. */ |
| 2812 | static void |
| 2813 | shell_configure_fullscreen(struct shell_surface *shsurf) |
| 2814 | { |
| 2815 | struct weston_output *output = shsurf->fullscreen_output; |
| 2816 | struct weston_surface *surface = shsurf->surface; |
| 2817 | struct weston_matrix *matrix; |
Kristian Høgsberg | 240dfeb | 2012-07-12 12:32:31 -0400 | [diff] [blame] | 2818 | float scale, output_aspect, surface_aspect, x, y; |
Giulio Camuffo | b836664 | 2013-04-25 13:57:46 +0300 | [diff] [blame] | 2819 | int32_t surf_x, surf_y, surf_width, surf_height; |
Alex Wu | 4539b08 | 2012-03-01 12:57:46 +0800 | [diff] [blame] | 2820 | |
Alexander Larsson | f82b6ca | 2013-05-28 16:23:39 +0200 | [diff] [blame] | 2821 | if (shsurf->fullscreen.type != WL_SHELL_SURFACE_FULLSCREEN_METHOD_DRIVER) |
| 2822 | restore_output_mode(output); |
| 2823 | |
Emilio Pozuelo Monfort | 9e7c759 | 2014-01-30 14:01:10 +0100 | [diff] [blame] | 2824 | /* Reverse the effect of lower_fullscreen_layer() */ |
Giulio Camuffo | 412e6a5 | 2014-07-09 22:12:56 +0300 | [diff] [blame] | 2825 | weston_layer_entry_remove(&shsurf->view->layer_link); |
| 2826 | 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] | 2827 | |
Philip Withnall | ed8f1a9 | 2013-11-25 18:01:43 +0000 | [diff] [blame] | 2828 | shell_ensure_fullscreen_black_view(shsurf); |
Alex Wu | 4539b08 | 2012-03-01 12:57:46 +0800 | [diff] [blame] | 2829 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 2830 | surface_subsurfaces_boundingbox(shsurf->surface, &surf_x, &surf_y, |
Giulio Camuffo | b836664 | 2013-04-25 13:57:46 +0300 | [diff] [blame] | 2831 | &surf_width, &surf_height); |
| 2832 | |
Alex Wu | 4539b08 | 2012-03-01 12:57:46 +0800 | [diff] [blame] | 2833 | switch (shsurf->fullscreen.type) { |
| 2834 | case WL_SHELL_SURFACE_FULLSCREEN_METHOD_DEFAULT: |
Pekka Paalanen | de685b8 | 2012-12-04 15:58:12 +0200 | [diff] [blame] | 2835 | if (surface->buffer_ref.buffer) |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 2836 | center_on_output(shsurf->view, shsurf->fullscreen_output); |
Alex Wu | 4539b08 | 2012-03-01 12:57:46 +0800 | [diff] [blame] | 2837 | break; |
| 2838 | case WL_SHELL_SURFACE_FULLSCREEN_METHOD_SCALE: |
Rob Bradford | 9f3dd15 | 2013-02-12 11:53:47 +0000 | [diff] [blame] | 2839 | /* 1:1 mapping between surface and output dimensions */ |
Giulio Camuffo | b836664 | 2013-04-25 13:57:46 +0300 | [diff] [blame] | 2840 | if (output->width == surf_width && |
| 2841 | output->height == surf_height) { |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 2842 | weston_view_set_position(shsurf->view, |
| 2843 | output->x - surf_x, |
| 2844 | output->y - surf_y); |
Rob Bradford | 9f3dd15 | 2013-02-12 11:53:47 +0000 | [diff] [blame] | 2845 | break; |
| 2846 | } |
| 2847 | |
Alex Wu | 4539b08 | 2012-03-01 12:57:46 +0800 | [diff] [blame] | 2848 | matrix = &shsurf->fullscreen.transform.matrix; |
| 2849 | weston_matrix_init(matrix); |
Kristian Høgsberg | 240dfeb | 2012-07-12 12:32:31 -0400 | [diff] [blame] | 2850 | |
Scott Moreau | 1bad5db | 2012-08-18 01:04:05 -0600 | [diff] [blame] | 2851 | output_aspect = (float) output->width / |
| 2852 | (float) output->height; |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 2853 | /* XXX: Use surf_width and surf_height here? */ |
| 2854 | surface_aspect = (float) surface->width / |
| 2855 | (float) surface->height; |
Kristian Høgsberg | 240dfeb | 2012-07-12 12:32:31 -0400 | [diff] [blame] | 2856 | if (output_aspect < surface_aspect) |
Scott Moreau | 1bad5db | 2012-08-18 01:04:05 -0600 | [diff] [blame] | 2857 | scale = (float) output->width / |
Giulio Camuffo | b836664 | 2013-04-25 13:57:46 +0300 | [diff] [blame] | 2858 | (float) surf_width; |
Kristian Høgsberg | 240dfeb | 2012-07-12 12:32:31 -0400 | [diff] [blame] | 2859 | else |
Scott Moreau | 1bad5db | 2012-08-18 01:04:05 -0600 | [diff] [blame] | 2860 | scale = (float) output->height / |
Giulio Camuffo | b836664 | 2013-04-25 13:57:46 +0300 | [diff] [blame] | 2861 | (float) surf_height; |
Kristian Høgsberg | 240dfeb | 2012-07-12 12:32:31 -0400 | [diff] [blame] | 2862 | |
Alex Wu | 4539b08 | 2012-03-01 12:57:46 +0800 | [diff] [blame] | 2863 | weston_matrix_scale(matrix, scale, scale, 1); |
| 2864 | wl_list_remove(&shsurf->fullscreen.transform.link); |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 2865 | wl_list_insert(&shsurf->view->geometry.transformation_list, |
Alex Wu | 4539b08 | 2012-03-01 12:57:46 +0800 | [diff] [blame] | 2866 | &shsurf->fullscreen.transform.link); |
Giulio Camuffo | b836664 | 2013-04-25 13:57:46 +0300 | [diff] [blame] | 2867 | x = output->x + (output->width - surf_width * scale) / 2 - surf_x; |
| 2868 | y = output->y + (output->height - surf_height * scale) / 2 - surf_y; |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 2869 | weston_view_set_position(shsurf->view, x, y); |
Kristian Høgsberg | 240dfeb | 2012-07-12 12:32:31 -0400 | [diff] [blame] | 2870 | |
Alex Wu | 4539b08 | 2012-03-01 12:57:46 +0800 | [diff] [blame] | 2871 | break; |
| 2872 | case WL_SHELL_SURFACE_FULLSCREEN_METHOD_DRIVER: |
Alex Wu | bd3354b | 2012-04-17 17:20:49 +0800 | [diff] [blame] | 2873 | if (shell_surface_is_top_fullscreen(shsurf)) { |
Quentin Glidic | c0d79ce | 2013-01-29 14:16:13 +0100 | [diff] [blame] | 2874 | struct weston_mode mode = {0, |
Pekka Paalanen | 952b6c8 | 2014-03-14 14:38:15 +0200 | [diff] [blame] | 2875 | surf_width * surface->buffer_viewport.buffer.scale, |
| 2876 | surf_height * surface->buffer_viewport.buffer.scale, |
Alex Wu | bd3354b | 2012-04-17 17:20:49 +0800 | [diff] [blame] | 2877 | shsurf->fullscreen.framerate}; |
| 2878 | |
Pekka Paalanen | 952b6c8 | 2014-03-14 14:38:15 +0200 | [diff] [blame] | 2879 | if (weston_output_switch_mode(output, &mode, surface->buffer_viewport.buffer.scale, |
Hardening | 57388e4 | 2013-09-18 23:56:36 +0200 | [diff] [blame] | 2880 | WESTON_MODE_SWITCH_SET_TEMPORARY) == 0) { |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 2881 | weston_view_set_position(shsurf->view, |
| 2882 | output->x - surf_x, |
| 2883 | output->y - surf_y); |
Jason Ekstrand | 918f2dd | 2013-12-02 21:01:53 -0600 | [diff] [blame] | 2884 | shsurf->fullscreen.black_view->surface->width = output->width; |
| 2885 | shsurf->fullscreen.black_view->surface->height = output->height; |
| 2886 | weston_view_set_position(shsurf->fullscreen.black_view, |
| 2887 | output->x - surf_x, |
| 2888 | output->y - surf_y); |
Alex Wu | bd3354b | 2012-04-17 17:20:49 +0800 | [diff] [blame] | 2889 | break; |
Alexander Larsson | d622ed3 | 2013-05-28 16:23:40 +0200 | [diff] [blame] | 2890 | } else { |
Alexander Larsson | f82b6ca | 2013-05-28 16:23:39 +0200 | [diff] [blame] | 2891 | restore_output_mode(output); |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 2892 | center_on_output(shsurf->view, output); |
Alexander Larsson | d622ed3 | 2013-05-28 16:23:40 +0200 | [diff] [blame] | 2893 | } |
Alex Wu | bd3354b | 2012-04-17 17:20:49 +0800 | [diff] [blame] | 2894 | } |
Alex Wu | 4539b08 | 2012-03-01 12:57:46 +0800 | [diff] [blame] | 2895 | break; |
| 2896 | case WL_SHELL_SURFACE_FULLSCREEN_METHOD_FILL: |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 2897 | center_on_output(shsurf->view, output); |
Alex Wu | 4539b08 | 2012-03-01 12:57:46 +0800 | [diff] [blame] | 2898 | break; |
| 2899 | default: |
| 2900 | break; |
| 2901 | } |
| 2902 | } |
| 2903 | |
Alex Wu | 4539b08 | 2012-03-01 12:57:46 +0800 | [diff] [blame] | 2904 | static void |
| 2905 | shell_map_fullscreen(struct shell_surface *shsurf) |
| 2906 | { |
Alex Wu | bd3354b | 2012-04-17 17:20:49 +0800 | [diff] [blame] | 2907 | shell_configure_fullscreen(shsurf); |
Alex Wu | 4539b08 | 2012-03-01 12:57:46 +0800 | [diff] [blame] | 2908 | } |
| 2909 | |
Kristian Høgsberg | 7a5c979 | 2011-06-18 06:12:54 -0400 | [diff] [blame] | 2910 | static void |
Tiago Vignatti | fb2adba | 2013-06-12 15:43:21 -0300 | [diff] [blame] | 2911 | set_xwayland(struct shell_surface *shsurf, int x, int y, uint32_t flags) |
| 2912 | { |
| 2913 | /* XXX: using the same fields for transient type */ |
Rafael Antognolli | 03b1659 | 2013-12-03 15:35:42 -0200 | [diff] [blame] | 2914 | surface_clear_next_states(shsurf); |
Tiago Vignatti | fb2adba | 2013-06-12 15:43:21 -0300 | [diff] [blame] | 2915 | shsurf->transient.x = x; |
| 2916 | shsurf->transient.y = y; |
| 2917 | shsurf->transient.flags = flags; |
Philip Withnall | dc4332f | 2013-11-25 18:01:38 +0000 | [diff] [blame] | 2918 | |
| 2919 | shell_surface_set_parent(shsurf, NULL); |
| 2920 | |
Kristian Høgsberg | c8f8dd8 | 2013-12-05 23:20:33 -0800 | [diff] [blame] | 2921 | shsurf->type = SHELL_SURFACE_XWAYLAND; |
Kristian Høgsberg | 8bc525c | 2014-01-01 22:34:49 -0800 | [diff] [blame] | 2922 | shsurf->state_changed = true; |
Tiago Vignatti | fb2adba | 2013-06-12 15:43:21 -0300 | [diff] [blame] | 2923 | } |
| 2924 | |
Kristian Høgsberg | 4779241 | 2014-05-04 13:47:06 -0700 | [diff] [blame] | 2925 | static void |
| 2926 | shell_interface_set_fullscreen(struct shell_surface *shsurf, |
| 2927 | uint32_t method, |
| 2928 | uint32_t framerate, |
| 2929 | struct weston_output *output) |
| 2930 | { |
| 2931 | surface_clear_next_states(shsurf); |
| 2932 | set_fullscreen(shsurf, method, framerate, output); |
| 2933 | |
| 2934 | shsurf->next_state.fullscreen = true; |
| 2935 | shsurf->state_changed = true; |
| 2936 | } |
| 2937 | |
Kristian Høgsberg | ae356ae | 2014-04-29 16:03:54 -0700 | [diff] [blame] | 2938 | static int |
| 2939 | shell_interface_move(struct shell_surface *shsurf, struct weston_seat *ws) |
| 2940 | { |
| 2941 | return surface_move(shsurf, ws, 1); |
| 2942 | } |
| 2943 | |
Kristian Høgsberg | 02bbabb | 2013-05-06 22:15:05 -0400 | [diff] [blame] | 2944 | static const struct weston_pointer_grab_interface popup_grab_interface; |
Giulio Camuffo | 5085a75 | 2013-03-25 21:42:45 +0100 | [diff] [blame] | 2945 | |
| 2946 | static void |
| 2947 | destroy_shell_seat(struct wl_listener *listener, void *data) |
| 2948 | { |
| 2949 | struct shell_seat *shseat = |
| 2950 | container_of(listener, |
| 2951 | struct shell_seat, seat_destroy_listener); |
| 2952 | struct shell_surface *shsurf, *prev = NULL; |
| 2953 | |
| 2954 | if (shseat->popup_grab.grab.interface == &popup_grab_interface) { |
Kristian Høgsberg | 02bbabb | 2013-05-06 22:15:05 -0400 | [diff] [blame] | 2955 | weston_pointer_end_grab(shseat->popup_grab.grab.pointer); |
Giulio Camuffo | 5085a75 | 2013-03-25 21:42:45 +0100 | [diff] [blame] | 2956 | shseat->popup_grab.client = NULL; |
| 2957 | |
| 2958 | wl_list_for_each(shsurf, &shseat->popup_grab.surfaces_list, popup.grab_link) { |
| 2959 | shsurf->popup.shseat = NULL; |
| 2960 | if (prev) { |
| 2961 | wl_list_init(&prev->popup.grab_link); |
| 2962 | } |
| 2963 | prev = shsurf; |
| 2964 | } |
| 2965 | wl_list_init(&prev->popup.grab_link); |
| 2966 | } |
| 2967 | |
| 2968 | wl_list_remove(&shseat->seat_destroy_listener.link); |
| 2969 | free(shseat); |
| 2970 | } |
| 2971 | |
Jason Ekstrand | 024177c | 2014-04-21 19:42:58 -0500 | [diff] [blame] | 2972 | static void |
| 2973 | shell_seat_caps_changed(struct wl_listener *listener, void *data) |
| 2974 | { |
| 2975 | struct shell_seat *seat; |
| 2976 | |
| 2977 | seat = container_of(listener, struct shell_seat, caps_changed_listener); |
| 2978 | |
| 2979 | if (seat->seat->keyboard && |
| 2980 | wl_list_empty(&seat->keyboard_focus_listener.link)) { |
| 2981 | wl_signal_add(&seat->seat->keyboard->focus_signal, |
| 2982 | &seat->keyboard_focus_listener); |
| 2983 | } else if (!seat->seat->keyboard) { |
| 2984 | wl_list_init(&seat->keyboard_focus_listener.link); |
| 2985 | } |
| 2986 | |
| 2987 | if (seat->seat->pointer && |
| 2988 | wl_list_empty(&seat->pointer_focus_listener.link)) { |
| 2989 | wl_signal_add(&seat->seat->pointer->focus_signal, |
| 2990 | &seat->pointer_focus_listener); |
| 2991 | } else if (!seat->seat->pointer) { |
| 2992 | wl_list_init(&seat->pointer_focus_listener.link); |
| 2993 | } |
| 2994 | } |
| 2995 | |
Giulio Camuffo | 5085a75 | 2013-03-25 21:42:45 +0100 | [diff] [blame] | 2996 | static struct shell_seat * |
| 2997 | create_shell_seat(struct weston_seat *seat) |
| 2998 | { |
| 2999 | struct shell_seat *shseat; |
| 3000 | |
| 3001 | shseat = calloc(1, sizeof *shseat); |
| 3002 | if (!shseat) { |
| 3003 | weston_log("no memory to allocate shell seat\n"); |
| 3004 | return NULL; |
| 3005 | } |
| 3006 | |
| 3007 | shseat->seat = seat; |
| 3008 | wl_list_init(&shseat->popup_grab.surfaces_list); |
| 3009 | |
| 3010 | shseat->seat_destroy_listener.notify = destroy_shell_seat; |
| 3011 | wl_signal_add(&seat->destroy_signal, |
| 3012 | &shseat->seat_destroy_listener); |
| 3013 | |
Jason Ekstrand | 024177c | 2014-04-21 19:42:58 -0500 | [diff] [blame] | 3014 | shseat->keyboard_focus_listener.notify = handle_keyboard_focus; |
| 3015 | wl_list_init(&shseat->keyboard_focus_listener.link); |
| 3016 | |
| 3017 | shseat->pointer_focus_listener.notify = handle_pointer_focus; |
| 3018 | wl_list_init(&shseat->pointer_focus_listener.link); |
| 3019 | |
| 3020 | shseat->caps_changed_listener.notify = shell_seat_caps_changed; |
| 3021 | wl_signal_add(&seat->updated_caps_signal, |
| 3022 | &shseat->caps_changed_listener); |
| 3023 | shell_seat_caps_changed(&shseat->caps_changed_listener, NULL); |
| 3024 | |
Giulio Camuffo | 5085a75 | 2013-03-25 21:42:45 +0100 | [diff] [blame] | 3025 | return shseat; |
| 3026 | } |
| 3027 | |
| 3028 | static struct shell_seat * |
| 3029 | get_shell_seat(struct weston_seat *seat) |
| 3030 | { |
| 3031 | struct wl_listener *listener; |
| 3032 | |
| 3033 | listener = wl_signal_get(&seat->destroy_signal, destroy_shell_seat); |
Jason Ekstrand | 024177c | 2014-04-21 19:42:58 -0500 | [diff] [blame] | 3034 | assert(listener != NULL); |
Giulio Camuffo | 5085a75 | 2013-03-25 21:42:45 +0100 | [diff] [blame] | 3035 | |
| 3036 | return container_of(listener, |
| 3037 | struct shell_seat, seat_destroy_listener); |
| 3038 | } |
| 3039 | |
Kristian Høgsberg | b810eb5 | 2013-02-12 20:07:05 -0500 | [diff] [blame] | 3040 | static void |
Kristian Høgsberg | 6848c25 | 2013-05-08 22:02:59 -0400 | [diff] [blame] | 3041 | popup_grab_focus(struct weston_pointer_grab *grab) |
Kristian Høgsberg | b3cca0a | 2012-01-04 22:19:14 -0500 | [diff] [blame] | 3042 | { |
Kristian Høgsberg | 02bbabb | 2013-05-06 22:15:05 -0400 | [diff] [blame] | 3043 | struct weston_pointer *pointer = grab->pointer; |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 3044 | struct weston_view *view; |
Giulio Camuffo | 5085a75 | 2013-03-25 21:42:45 +0100 | [diff] [blame] | 3045 | struct shell_seat *shseat = |
| 3046 | container_of(grab, struct shell_seat, popup_grab.grab); |
| 3047 | struct wl_client *client = shseat->popup_grab.client; |
Kristian Høgsberg | 6848c25 | 2013-05-08 22:02:59 -0400 | [diff] [blame] | 3048 | wl_fixed_t sx, sy; |
| 3049 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 3050 | view = weston_compositor_pick_view(pointer->seat->compositor, |
| 3051 | pointer->x, pointer->y, |
| 3052 | &sx, &sy); |
Kristian Høgsberg | b3cca0a | 2012-01-04 22:19:14 -0500 | [diff] [blame] | 3053 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 3054 | if (view && view->surface->resource && |
| 3055 | wl_resource_get_client(view->surface->resource) == client) { |
| 3056 | weston_pointer_set_focus(pointer, view, sx, sy); |
Kristian Høgsberg | b3cca0a | 2012-01-04 22:19:14 -0500 | [diff] [blame] | 3057 | } else { |
Kristian Høgsberg | 02bbabb | 2013-05-06 22:15:05 -0400 | [diff] [blame] | 3058 | weston_pointer_set_focus(pointer, NULL, |
| 3059 | wl_fixed_from_int(0), |
| 3060 | wl_fixed_from_int(0)); |
Kristian Høgsberg | b3cca0a | 2012-01-04 22:19:14 -0500 | [diff] [blame] | 3061 | } |
| 3062 | } |
| 3063 | |
| 3064 | static void |
Giulio Camuffo | 1959ab8 | 2013-11-14 23:42:52 +0100 | [diff] [blame] | 3065 | popup_grab_motion(struct weston_pointer_grab *grab, uint32_t time, |
| 3066 | wl_fixed_t x, wl_fixed_t y) |
Kristian Høgsberg | b3cca0a | 2012-01-04 22:19:14 -0500 | [diff] [blame] | 3067 | { |
Kristian Høgsberg | be6403e | 2013-05-08 21:03:21 -0400 | [diff] [blame] | 3068 | struct weston_pointer *pointer = grab->pointer; |
Neil Roberts | 96d790e | 2013-09-19 17:32:00 +0100 | [diff] [blame] | 3069 | struct wl_resource *resource; |
Kristian Høgsberg | be6403e | 2013-05-08 21:03:21 -0400 | [diff] [blame] | 3070 | wl_fixed_t sx, sy; |
Kristian Høgsberg | b3cca0a | 2012-01-04 22:19:14 -0500 | [diff] [blame] | 3071 | |
Jonas Ådahl | 61917c8 | 2014-08-11 22:44:02 +0200 | [diff] [blame] | 3072 | if (pointer->focus) { |
| 3073 | weston_view_from_global_fixed(pointer->focus, x, y, |
| 3074 | &pointer->sx, &pointer->sy); |
| 3075 | } |
| 3076 | |
Giulio Camuffo | 1959ab8 | 2013-11-14 23:42:52 +0100 | [diff] [blame] | 3077 | weston_pointer_move(pointer, x, y); |
| 3078 | |
Neil Roberts | 96d790e | 2013-09-19 17:32:00 +0100 | [diff] [blame] | 3079 | wl_resource_for_each(resource, &pointer->focus_resource_list) { |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 3080 | weston_view_from_global_fixed(pointer->focus, |
| 3081 | pointer->x, pointer->y, |
| 3082 | &sx, &sy); |
Neil Roberts | 96d790e | 2013-09-19 17:32:00 +0100 | [diff] [blame] | 3083 | wl_pointer_send_motion(resource, time, sx, sy); |
Kristian Høgsberg | be6403e | 2013-05-08 21:03:21 -0400 | [diff] [blame] | 3084 | } |
Kristian Høgsberg | b3cca0a | 2012-01-04 22:19:14 -0500 | [diff] [blame] | 3085 | } |
| 3086 | |
| 3087 | static void |
Kristian Høgsberg | 02bbabb | 2013-05-06 22:15:05 -0400 | [diff] [blame] | 3088 | popup_grab_button(struct weston_pointer_grab *grab, |
Daniel Stone | 4dbadb1 | 2012-05-30 16:31:51 +0100 | [diff] [blame] | 3089 | uint32_t time, uint32_t button, uint32_t state_w) |
Kristian Høgsberg | b3cca0a | 2012-01-04 22:19:14 -0500 | [diff] [blame] | 3090 | { |
| 3091 | struct wl_resource *resource; |
Giulio Camuffo | 5085a75 | 2013-03-25 21:42:45 +0100 | [diff] [blame] | 3092 | struct shell_seat *shseat = |
| 3093 | container_of(grab, struct shell_seat, popup_grab.grab); |
Rob Bradford | 880ebc7 | 2013-07-22 17:31:38 +0100 | [diff] [blame] | 3094 | struct wl_display *display = shseat->seat->compositor->wl_display; |
Daniel Stone | 4dbadb1 | 2012-05-30 16:31:51 +0100 | [diff] [blame] | 3095 | enum wl_pointer_button_state state = state_w; |
Kristian Høgsberg | eae5de7 | 2012-04-11 22:42:15 -0400 | [diff] [blame] | 3096 | uint32_t serial; |
Neil Roberts | 96d790e | 2013-09-19 17:32:00 +0100 | [diff] [blame] | 3097 | struct wl_list *resource_list; |
Kristian Høgsberg | b3cca0a | 2012-01-04 22:19:14 -0500 | [diff] [blame] | 3098 | |
Neil Roberts | 96d790e | 2013-09-19 17:32:00 +0100 | [diff] [blame] | 3099 | resource_list = &grab->pointer->focus_resource_list; |
| 3100 | if (!wl_list_empty(resource_list)) { |
Kristian Høgsberg | eae5de7 | 2012-04-11 22:42:15 -0400 | [diff] [blame] | 3101 | serial = wl_display_get_serial(display); |
Neil Roberts | 96d790e | 2013-09-19 17:32:00 +0100 | [diff] [blame] | 3102 | wl_resource_for_each(resource, resource_list) { |
| 3103 | wl_pointer_send_button(resource, serial, |
| 3104 | time, button, state); |
| 3105 | } |
Daniel Stone | 4dbadb1 | 2012-05-30 16:31:51 +0100 | [diff] [blame] | 3106 | } else if (state == WL_POINTER_BUTTON_STATE_RELEASED && |
Giulio Camuffo | 5085a75 | 2013-03-25 21:42:45 +0100 | [diff] [blame] | 3107 | (shseat->popup_grab.initial_up || |
Kristian Høgsberg | e314875 | 2013-05-06 23:19:49 -0400 | [diff] [blame] | 3108 | time - shseat->seat->pointer->grab_time > 500)) { |
Kristian Høgsberg | 57e0907 | 2012-10-30 14:07:27 -0400 | [diff] [blame] | 3109 | popup_grab_end(grab->pointer); |
Kristian Høgsberg | b3cca0a | 2012-01-04 22:19:14 -0500 | [diff] [blame] | 3110 | } |
| 3111 | |
Daniel Stone | 4dbadb1 | 2012-05-30 16:31:51 +0100 | [diff] [blame] | 3112 | if (state == WL_POINTER_BUTTON_STATE_RELEASED) |
Giulio Camuffo | 5085a75 | 2013-03-25 21:42:45 +0100 | [diff] [blame] | 3113 | shseat->popup_grab.initial_up = 1; |
Kristian Høgsberg | b3cca0a | 2012-01-04 22:19:14 -0500 | [diff] [blame] | 3114 | } |
| 3115 | |
Jonas Ådahl | 1ea343e | 2013-10-25 23:18:05 +0200 | [diff] [blame] | 3116 | static void |
| 3117 | popup_grab_cancel(struct weston_pointer_grab *grab) |
| 3118 | { |
| 3119 | popup_grab_end(grab->pointer); |
| 3120 | } |
| 3121 | |
Kristian Høgsberg | 02bbabb | 2013-05-06 22:15:05 -0400 | [diff] [blame] | 3122 | static const struct weston_pointer_grab_interface popup_grab_interface = { |
Kristian Høgsberg | b3cca0a | 2012-01-04 22:19:14 -0500 | [diff] [blame] | 3123 | popup_grab_focus, |
| 3124 | popup_grab_motion, |
| 3125 | popup_grab_button, |
Jonas Ådahl | 1ea343e | 2013-10-25 23:18:05 +0200 | [diff] [blame] | 3126 | popup_grab_cancel, |
Kristian Høgsberg | b3cca0a | 2012-01-04 22:19:14 -0500 | [diff] [blame] | 3127 | }; |
| 3128 | |
| 3129 | static void |
Jonny Lamb | 76cf1fe | 2014-08-20 11:27:10 +0200 | [diff] [blame] | 3130 | touch_popup_grab_down(struct weston_touch_grab *grab, uint32_t time, |
| 3131 | int touch_id, wl_fixed_t sx, wl_fixed_t sy) |
| 3132 | { |
| 3133 | struct wl_resource *resource; |
| 3134 | struct shell_seat *shseat = |
| 3135 | container_of(grab, struct shell_seat, popup_grab.touch_grab); |
| 3136 | struct wl_display *display = shseat->seat->compositor->wl_display; |
| 3137 | uint32_t serial; |
| 3138 | struct wl_list *resource_list; |
| 3139 | |
| 3140 | resource_list = &grab->touch->focus_resource_list; |
| 3141 | if (!wl_list_empty(resource_list)) { |
| 3142 | serial = wl_display_get_serial(display); |
| 3143 | wl_resource_for_each(resource, resource_list) { |
| 3144 | wl_touch_send_down(resource, serial, time, |
| 3145 | grab->touch->focus->surface->resource, |
| 3146 | touch_id, sx, sy); |
| 3147 | } |
| 3148 | } |
| 3149 | } |
| 3150 | |
| 3151 | static void |
| 3152 | touch_popup_grab_up(struct weston_touch_grab *grab, uint32_t time, int touch_id) |
| 3153 | { |
| 3154 | struct wl_resource *resource; |
| 3155 | struct shell_seat *shseat = |
| 3156 | container_of(grab, struct shell_seat, popup_grab.touch_grab); |
| 3157 | struct wl_display *display = shseat->seat->compositor->wl_display; |
| 3158 | uint32_t serial; |
| 3159 | struct wl_list *resource_list; |
| 3160 | |
| 3161 | resource_list = &grab->touch->focus_resource_list; |
| 3162 | if (!wl_list_empty(resource_list)) { |
| 3163 | serial = wl_display_get_serial(display); |
| 3164 | wl_resource_for_each(resource, resource_list) { |
| 3165 | wl_touch_send_up(resource, serial, time, touch_id); |
| 3166 | } |
| 3167 | } |
| 3168 | } |
| 3169 | |
| 3170 | static void |
| 3171 | touch_popup_grab_motion(struct weston_touch_grab *grab, uint32_t time, |
| 3172 | int touch_id, wl_fixed_t sx, wl_fixed_t sy) |
| 3173 | { |
| 3174 | struct wl_resource *resource; |
| 3175 | struct wl_list *resource_list; |
| 3176 | |
| 3177 | resource_list = &grab->touch->focus_resource_list; |
| 3178 | if (!wl_list_empty(resource_list)) { |
| 3179 | wl_resource_for_each(resource, resource_list) { |
| 3180 | wl_touch_send_motion(resource, time, touch_id, sx, sy); |
| 3181 | } |
| 3182 | } |
| 3183 | } |
| 3184 | |
| 3185 | static void |
| 3186 | touch_popup_grab_frame(struct weston_touch_grab *grab) |
| 3187 | { |
| 3188 | } |
| 3189 | |
| 3190 | static void |
| 3191 | touch_popup_grab_cancel(struct weston_touch_grab *grab) |
| 3192 | { |
| 3193 | touch_popup_grab_end(grab->touch); |
| 3194 | } |
| 3195 | |
| 3196 | static const struct weston_touch_grab_interface touch_popup_grab_interface = { |
| 3197 | touch_popup_grab_down, |
| 3198 | touch_popup_grab_up, |
| 3199 | touch_popup_grab_motion, |
| 3200 | touch_popup_grab_frame, |
| 3201 | touch_popup_grab_cancel, |
| 3202 | }; |
| 3203 | |
| 3204 | static void |
Rafael Antognolli | e2a3455 | 2013-12-03 15:35:45 -0200 | [diff] [blame] | 3205 | shell_surface_send_popup_done(struct shell_surface *shsurf) |
| 3206 | { |
| 3207 | if (shell_surface_is_wl_shell_surface(shsurf)) |
| 3208 | wl_shell_surface_send_popup_done(shsurf->resource); |
| 3209 | else if (shell_surface_is_xdg_popup(shsurf)) |
| 3210 | xdg_popup_send_popup_done(shsurf->resource, |
| 3211 | shsurf->popup.serial); |
| 3212 | } |
| 3213 | |
| 3214 | static void |
Kristian Høgsberg | 02bbabb | 2013-05-06 22:15:05 -0400 | [diff] [blame] | 3215 | popup_grab_end(struct weston_pointer *pointer) |
Kristian Høgsberg | 57e0907 | 2012-10-30 14:07:27 -0400 | [diff] [blame] | 3216 | { |
Kristian Høgsberg | 02bbabb | 2013-05-06 22:15:05 -0400 | [diff] [blame] | 3217 | struct weston_pointer_grab *grab = pointer->grab; |
Giulio Camuffo | 5085a75 | 2013-03-25 21:42:45 +0100 | [diff] [blame] | 3218 | struct shell_seat *shseat = |
| 3219 | container_of(grab, struct shell_seat, popup_grab.grab); |
| 3220 | struct shell_surface *shsurf; |
| 3221 | struct shell_surface *prev = NULL; |
Kristian Høgsberg | 57e0907 | 2012-10-30 14:07:27 -0400 | [diff] [blame] | 3222 | |
| 3223 | if (pointer->grab->interface == &popup_grab_interface) { |
Kristian Høgsberg | 02bbabb | 2013-05-06 22:15:05 -0400 | [diff] [blame] | 3224 | weston_pointer_end_grab(grab->pointer); |
Giulio Camuffo | 5085a75 | 2013-03-25 21:42:45 +0100 | [diff] [blame] | 3225 | shseat->popup_grab.client = NULL; |
Philipp Brüschweiler | 63e7be6 | 2013-04-15 21:09:54 +0200 | [diff] [blame] | 3226 | shseat->popup_grab.grab.interface = NULL; |
| 3227 | assert(!wl_list_empty(&shseat->popup_grab.surfaces_list)); |
Giulio Camuffo | 5085a75 | 2013-03-25 21:42:45 +0100 | [diff] [blame] | 3228 | /* Send the popup_done event to all the popups open */ |
| 3229 | wl_list_for_each(shsurf, &shseat->popup_grab.surfaces_list, popup.grab_link) { |
Rafael Antognolli | e2a3455 | 2013-12-03 15:35:45 -0200 | [diff] [blame] | 3230 | shell_surface_send_popup_done(shsurf); |
Giulio Camuffo | 5085a75 | 2013-03-25 21:42:45 +0100 | [diff] [blame] | 3231 | shsurf->popup.shseat = NULL; |
| 3232 | if (prev) { |
| 3233 | wl_list_init(&prev->popup.grab_link); |
| 3234 | } |
| 3235 | prev = shsurf; |
| 3236 | } |
| 3237 | wl_list_init(&prev->popup.grab_link); |
| 3238 | wl_list_init(&shseat->popup_grab.surfaces_list); |
| 3239 | } |
| 3240 | } |
| 3241 | |
| 3242 | static void |
Jonny Lamb | 76cf1fe | 2014-08-20 11:27:10 +0200 | [diff] [blame] | 3243 | touch_popup_grab_end(struct weston_touch *touch) |
| 3244 | { |
| 3245 | struct weston_touch_grab *grab = touch->grab; |
| 3246 | struct shell_seat *shseat = |
| 3247 | container_of(grab, struct shell_seat, popup_grab.touch_grab); |
| 3248 | struct shell_surface *shsurf; |
| 3249 | struct shell_surface *prev = NULL; |
| 3250 | |
| 3251 | if (touch->grab->interface == &touch_popup_grab_interface) { |
| 3252 | weston_touch_end_grab(grab->touch); |
| 3253 | shseat->popup_grab.client = NULL; |
| 3254 | shseat->popup_grab.touch_grab.interface = NULL; |
| 3255 | assert(!wl_list_empty(&shseat->popup_grab.surfaces_list)); |
| 3256 | /* Send the popup_done event to all the popups open */ |
| 3257 | wl_list_for_each(shsurf, &shseat->popup_grab.surfaces_list, popup.grab_link) { |
| 3258 | shell_surface_send_popup_done(shsurf); |
| 3259 | shsurf->popup.shseat = NULL; |
| 3260 | if (prev) { |
| 3261 | wl_list_init(&prev->popup.grab_link); |
| 3262 | } |
| 3263 | prev = shsurf; |
| 3264 | } |
| 3265 | wl_list_init(&prev->popup.grab_link); |
| 3266 | wl_list_init(&shseat->popup_grab.surfaces_list); |
| 3267 | } |
| 3268 | } |
| 3269 | |
| 3270 | static void |
| 3271 | add_popup_grab(struct shell_surface *shsurf, struct shell_seat *shseat, int32_t type) |
Giulio Camuffo | 5085a75 | 2013-03-25 21:42:45 +0100 | [diff] [blame] | 3272 | { |
Kristian Høgsberg | e314875 | 2013-05-06 23:19:49 -0400 | [diff] [blame] | 3273 | struct weston_seat *seat = shseat->seat; |
Giulio Camuffo | 5085a75 | 2013-03-25 21:42:45 +0100 | [diff] [blame] | 3274 | |
| 3275 | if (wl_list_empty(&shseat->popup_grab.surfaces_list)) { |
Jonny Lamb | 76cf1fe | 2014-08-20 11:27:10 +0200 | [diff] [blame] | 3276 | shseat->popup_grab.type = type; |
Jason Ekstrand | 651f00e | 2013-06-14 10:07:54 -0500 | [diff] [blame] | 3277 | shseat->popup_grab.client = wl_resource_get_client(shsurf->resource); |
Jonny Lamb | 76cf1fe | 2014-08-20 11:27:10 +0200 | [diff] [blame] | 3278 | |
| 3279 | if (type == POINTER) { |
| 3280 | shseat->popup_grab.grab.interface = &popup_grab_interface; |
| 3281 | /* We must make sure here that this popup was opened after |
| 3282 | * a mouse press, and not just by moving around with other |
| 3283 | * popups already open. */ |
| 3284 | if (shseat->seat->pointer->button_count > 0) |
| 3285 | shseat->popup_grab.initial_up = 0; |
| 3286 | } else if (type == TOUCH) { |
| 3287 | shseat->popup_grab.touch_grab.interface = &touch_popup_grab_interface; |
| 3288 | } |
Giulio Camuffo | 5085a75 | 2013-03-25 21:42:45 +0100 | [diff] [blame] | 3289 | |
Rob Bradford | dfe3105 | 2013-06-26 19:49:11 +0100 | [diff] [blame] | 3290 | wl_list_insert(&shseat->popup_grab.surfaces_list, &shsurf->popup.grab_link); |
Jonny Lamb | 76cf1fe | 2014-08-20 11:27:10 +0200 | [diff] [blame] | 3291 | |
| 3292 | if (type == POINTER) |
| 3293 | weston_pointer_start_grab(seat->pointer, &shseat->popup_grab.grab); |
| 3294 | else if (type == TOUCH) |
| 3295 | weston_touch_start_grab(seat->touch, &shseat->popup_grab.touch_grab); |
Rob Bradford | dfe3105 | 2013-06-26 19:49:11 +0100 | [diff] [blame] | 3296 | } else { |
| 3297 | wl_list_insert(&shseat->popup_grab.surfaces_list, &shsurf->popup.grab_link); |
Giulio Camuffo | 5085a75 | 2013-03-25 21:42:45 +0100 | [diff] [blame] | 3298 | } |
Giulio Camuffo | 5085a75 | 2013-03-25 21:42:45 +0100 | [diff] [blame] | 3299 | } |
| 3300 | |
| 3301 | static void |
| 3302 | remove_popup_grab(struct shell_surface *shsurf) |
| 3303 | { |
| 3304 | struct shell_seat *shseat = shsurf->popup.shseat; |
| 3305 | |
| 3306 | wl_list_remove(&shsurf->popup.grab_link); |
| 3307 | wl_list_init(&shsurf->popup.grab_link); |
| 3308 | if (wl_list_empty(&shseat->popup_grab.surfaces_list)) { |
Jonny Lamb | 76cf1fe | 2014-08-20 11:27:10 +0200 | [diff] [blame] | 3309 | if (shseat->popup_grab.type == POINTER) { |
| 3310 | weston_pointer_end_grab(shseat->popup_grab.grab.pointer); |
| 3311 | shseat->popup_grab.grab.interface = NULL; |
| 3312 | } else if (shseat->popup_grab.type == TOUCH) { |
| 3313 | weston_touch_end_grab(shseat->popup_grab.touch_grab.touch); |
| 3314 | shseat->popup_grab.touch_grab.interface = NULL; |
| 3315 | } |
Kristian Høgsberg | 57e0907 | 2012-10-30 14:07:27 -0400 | [diff] [blame] | 3316 | } |
| 3317 | } |
| 3318 | |
| 3319 | static void |
Kristian Høgsberg | 3730f36 | 2012-04-13 12:40:07 -0400 | [diff] [blame] | 3320 | shell_map_popup(struct shell_surface *shsurf) |
Kristian Høgsberg | b3cca0a | 2012-01-04 22:19:14 -0500 | [diff] [blame] | 3321 | { |
Giulio Camuffo | 5085a75 | 2013-03-25 21:42:45 +0100 | [diff] [blame] | 3322 | struct shell_seat *shseat = shsurf->popup.shseat; |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 3323 | struct weston_view *parent_view = get_default_view(shsurf->parent); |
Kristian Høgsberg | b3cca0a | 2012-01-04 22:19:14 -0500 | [diff] [blame] | 3324 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 3325 | shsurf->surface->output = parent_view->output; |
| 3326 | shsurf->view->output = parent_view->output; |
Kristian Høgsberg | b3cca0a | 2012-01-04 22:19:14 -0500 | [diff] [blame] | 3327 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 3328 | weston_view_set_transform_parent(shsurf->view, parent_view); |
| 3329 | weston_view_set_position(shsurf->view, shsurf->popup.x, shsurf->popup.y); |
| 3330 | weston_view_update_transform(shsurf->view); |
Kristian Høgsberg | b3cca0a | 2012-01-04 22:19:14 -0500 | [diff] [blame] | 3331 | |
Jonny Lamb | e84ab4e | 2014-08-06 11:50:12 +0200 | [diff] [blame] | 3332 | if (shseat->seat->pointer && |
| 3333 | shseat->seat->pointer->grab_serial == shsurf->popup.serial) { |
Jonny Lamb | 76cf1fe | 2014-08-20 11:27:10 +0200 | [diff] [blame] | 3334 | add_popup_grab(shsurf, shseat, POINTER); |
| 3335 | } else if (shseat->seat->touch && |
| 3336 | shseat->seat->touch->grab_serial == shsurf->popup.serial) { |
| 3337 | add_popup_grab(shsurf, shseat, TOUCH); |
Kristian Høgsberg | 3730f36 | 2012-04-13 12:40:07 -0400 | [diff] [blame] | 3338 | } else { |
Rafael Antognolli | e2a3455 | 2013-12-03 15:35:45 -0200 | [diff] [blame] | 3339 | shell_surface_send_popup_done(shsurf); |
Giulio Camuffo | 5085a75 | 2013-03-25 21:42:45 +0100 | [diff] [blame] | 3340 | shseat->popup_grab.client = NULL; |
Kristian Høgsberg | 3730f36 | 2012-04-13 12:40:07 -0400 | [diff] [blame] | 3341 | } |
Kristian Høgsberg | b3cca0a | 2012-01-04 22:19:14 -0500 | [diff] [blame] | 3342 | } |
| 3343 | |
Pekka Paalanen | 9d1613e | 2011-11-25 12:09:16 +0200 | [diff] [blame] | 3344 | static const struct wl_shell_surface_interface shell_surface_implementation = { |
Scott Moreau | ff1db4a | 2012-04-17 19:06:18 -0600 | [diff] [blame] | 3345 | shell_surface_pong, |
Pekka Paalanen | 9d1613e | 2011-11-25 12:09:16 +0200 | [diff] [blame] | 3346 | shell_surface_move, |
| 3347 | shell_surface_resize, |
| 3348 | shell_surface_set_toplevel, |
| 3349 | shell_surface_set_transient, |
Kristian Høgsberg | b3cca0a | 2012-01-04 22:19:14 -0500 | [diff] [blame] | 3350 | shell_surface_set_fullscreen, |
Juan Zhao | 96879df | 2012-02-07 08:45:41 +0800 | [diff] [blame] | 3351 | shell_surface_set_popup, |
Kristian Høgsberg | e7afd91 | 2012-05-02 09:47:44 -0400 | [diff] [blame] | 3352 | shell_surface_set_maximized, |
| 3353 | shell_surface_set_title, |
| 3354 | shell_surface_set_class |
Pekka Paalanen | 9d1613e | 2011-11-25 12:09:16 +0200 | [diff] [blame] | 3355 | }; |
| 3356 | |
| 3357 | static void |
Tiago Vignatti | bc052c9 | 2012-04-19 16:18:18 +0300 | [diff] [blame] | 3358 | destroy_shell_surface(struct shell_surface *shsurf) |
Pekka Paalanen | 9d1613e | 2011-11-25 12:09:16 +0200 | [diff] [blame] | 3359 | { |
Kristian Høgsberg | 9046d24 | 2014-01-10 00:25:30 -0800 | [diff] [blame] | 3360 | struct shell_surface *child, *next; |
| 3361 | |
Jason Ekstrand | 651f00e | 2013-06-14 10:07:54 -0500 | [diff] [blame] | 3362 | wl_signal_emit(&shsurf->destroy_signal, shsurf); |
| 3363 | |
Giulio Camuffo | 5085a75 | 2013-03-25 21:42:45 +0100 | [diff] [blame] | 3364 | if (!wl_list_empty(&shsurf->popup.grab_link)) { |
| 3365 | remove_popup_grab(shsurf); |
| 3366 | } |
Kristian Høgsberg | b3cca0a | 2012-01-04 22:19:14 -0500 | [diff] [blame] | 3367 | |
Alex Wu | bd3354b | 2012-04-17 17:20:49 +0800 | [diff] [blame] | 3368 | if (shsurf->fullscreen.type == WL_SHELL_SURFACE_FULLSCREEN_METHOD_DRIVER && |
Alexander Larsson | f82b6ca | 2013-05-28 16:23:39 +0200 | [diff] [blame] | 3369 | shell_surface_is_top_fullscreen(shsurf)) |
| 3370 | restore_output_mode (shsurf->fullscreen_output); |
Pekka Paalanen | 9d1613e | 2011-11-25 12:09:16 +0200 | [diff] [blame] | 3371 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 3372 | if (shsurf->fullscreen.black_view) |
| 3373 | weston_surface_destroy(shsurf->fullscreen.black_view->surface); |
Alex Wu | aa08e2d | 2012-03-05 11:01:40 +0800 | [diff] [blame] | 3374 | |
Alex Wu | bd3354b | 2012-04-17 17:20:49 +0800 | [diff] [blame] | 3375 | /* As destroy_resource() use wl_list_for_each_safe(), |
| 3376 | * we can always remove the listener. |
| 3377 | */ |
| 3378 | wl_list_remove(&shsurf->surface_destroy_listener.link); |
| 3379 | shsurf->surface->configure = NULL; |
Scott Moreau | 976a050 | 2013-03-07 10:15:17 -0700 | [diff] [blame] | 3380 | free(shsurf->title); |
Alex Wu | bd3354b | 2012-04-17 17:20:49 +0800 | [diff] [blame] | 3381 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 3382 | weston_view_destroy(shsurf->view); |
| 3383 | |
Philip Withnall | 648a4dd | 2013-11-25 18:01:44 +0000 | [diff] [blame] | 3384 | wl_list_remove(&shsurf->children_link); |
Emilio Pozuelo Monfort | adaa20c | 2014-01-28 13:54:16 +0100 | [diff] [blame] | 3385 | wl_list_for_each_safe(child, next, &shsurf->children_list, children_link) |
| 3386 | shell_surface_set_parent(child, NULL); |
Philip Withnall | 648a4dd | 2013-11-25 18:01:44 +0000 | [diff] [blame] | 3387 | |
Pekka Paalanen | 9d1613e | 2011-11-25 12:09:16 +0200 | [diff] [blame] | 3388 | wl_list_remove(&shsurf->link); |
| 3389 | free(shsurf); |
| 3390 | } |
| 3391 | |
| 3392 | static void |
Tiago Vignatti | bc052c9 | 2012-04-19 16:18:18 +0300 | [diff] [blame] | 3393 | shell_destroy_shell_surface(struct wl_resource *resource) |
| 3394 | { |
Jason Ekstrand | 651f00e | 2013-06-14 10:07:54 -0500 | [diff] [blame] | 3395 | struct shell_surface *shsurf = wl_resource_get_user_data(resource); |
Tiago Vignatti | bc052c9 | 2012-04-19 16:18:18 +0300 | [diff] [blame] | 3396 | |
Bryan Cain | a46b946 | 2014-04-04 17:41:24 -0500 | [diff] [blame] | 3397 | if (!wl_list_empty(&shsurf->popup.grab_link)) |
| 3398 | remove_popup_grab(shsurf); |
Kristian Høgsberg | 160fe75 | 2014-03-11 10:19:10 -0700 | [diff] [blame] | 3399 | shsurf->resource = NULL; |
Tiago Vignatti | bc052c9 | 2012-04-19 16:18:18 +0300 | [diff] [blame] | 3400 | } |
| 3401 | |
| 3402 | static void |
Kristian Høgsberg | 27e3052 | 2012-04-11 23:18:23 -0400 | [diff] [blame] | 3403 | shell_handle_surface_destroy(struct wl_listener *listener, void *data) |
Pekka Paalanen | 9d1613e | 2011-11-25 12:09:16 +0200 | [diff] [blame] | 3404 | { |
| 3405 | struct shell_surface *shsurf = container_of(listener, |
| 3406 | struct shell_surface, |
| 3407 | surface_destroy_listener); |
| 3408 | |
Jason Ekstrand | 651f00e | 2013-06-14 10:07:54 -0500 | [diff] [blame] | 3409 | if (shsurf->resource) |
| 3410 | wl_resource_destroy(shsurf->resource); |
Ander Conselvan de Oliveira | 15f9a26 | 2014-04-29 17:54:02 +0300 | [diff] [blame] | 3411 | |
| 3412 | destroy_shell_surface(shsurf); |
Pekka Paalanen | 9d1613e | 2011-11-25 12:09:16 +0200 | [diff] [blame] | 3413 | } |
| 3414 | |
Kristian Høgsberg | d813445 | 2012-06-21 12:49:02 -0400 | [diff] [blame] | 3415 | static void |
Kristian Høgsberg | 160fe75 | 2014-03-11 10:19:10 -0700 | [diff] [blame] | 3416 | fade_out_done(struct weston_view_animation *animation, void *data) |
| 3417 | { |
| 3418 | struct shell_surface *shsurf = data; |
| 3419 | |
| 3420 | weston_surface_destroy(shsurf->surface); |
| 3421 | } |
| 3422 | |
| 3423 | static void |
| 3424 | handle_resource_destroy(struct wl_listener *listener, void *data) |
| 3425 | { |
| 3426 | struct shell_surface *shsurf = |
| 3427 | container_of(listener, struct shell_surface, |
| 3428 | resource_destroy_listener); |
| 3429 | |
Ander Conselvan de Oliveira | 15f9a26 | 2014-04-29 17:54:02 +0300 | [diff] [blame] | 3430 | if (!weston_surface_is_mapped(shsurf->surface)) |
| 3431 | return; |
| 3432 | |
Kristian Høgsberg | 160fe75 | 2014-03-11 10:19:10 -0700 | [diff] [blame] | 3433 | shsurf->surface->ref_count++; |
| 3434 | |
| 3435 | pixman_region32_fini(&shsurf->surface->pending.input); |
| 3436 | pixman_region32_init(&shsurf->surface->pending.input); |
| 3437 | pixman_region32_fini(&shsurf->surface->input); |
| 3438 | pixman_region32_init(&shsurf->surface->input); |
Jonny Lamb | f322f8e | 2014-08-12 15:13:30 +0200 | [diff] [blame] | 3439 | if (shsurf->shell->win_close_animation_type == ANIMATION_FADE) { |
| 3440 | weston_fade_run(shsurf->view, 1.0, 0.0, 300.0, |
| 3441 | fade_out_done, shsurf); |
| 3442 | } else { |
| 3443 | weston_surface_destroy(shsurf->surface); |
| 3444 | } |
Kristian Høgsberg | 160fe75 | 2014-03-11 10:19:10 -0700 | [diff] [blame] | 3445 | } |
| 3446 | |
| 3447 | static void |
Jason Ekstrand | 918f2dd | 2013-12-02 21:01:53 -0600 | [diff] [blame] | 3448 | shell_surface_configure(struct weston_surface *, int32_t, int32_t); |
Kristian Høgsberg | d813445 | 2012-06-21 12:49:02 -0400 | [diff] [blame] | 3449 | |
Kristian Høgsberg | 1ef2313 | 2013-12-04 00:20:01 -0800 | [diff] [blame] | 3450 | struct shell_surface * |
Kristian Høgsberg | 8334bc1 | 2012-01-03 10:29:47 -0500 | [diff] [blame] | 3451 | get_shell_surface(struct weston_surface *surface) |
Pekka Paalanen | ec2b32f | 2011-11-28 15:12:34 +0200 | [diff] [blame] | 3452 | { |
Kristian Høgsberg | d813445 | 2012-06-21 12:49:02 -0400 | [diff] [blame] | 3453 | if (surface->configure == shell_surface_configure) |
Giulio Camuffo | 7fe01b1 | 2013-03-28 18:02:42 +0100 | [diff] [blame] | 3454 | return surface->configure_private; |
Kristian Høgsberg | d813445 | 2012-06-21 12:49:02 -0400 | [diff] [blame] | 3455 | else |
| 3456 | return NULL; |
Pekka Paalanen | ec2b32f | 2011-11-28 15:12:34 +0200 | [diff] [blame] | 3457 | } |
| 3458 | |
Rafael Antognolli | e2a3455 | 2013-12-03 15:35:45 -0200 | [diff] [blame] | 3459 | static struct shell_surface * |
Jason Ekstrand | 9e9512f | 2014-04-16 21:12:10 -0500 | [diff] [blame] | 3460 | create_common_surface(struct shell_client *owner, void *shell, |
| 3461 | struct weston_surface *surface, |
Rafael Antognolli | e2a3455 | 2013-12-03 15:35:45 -0200 | [diff] [blame] | 3462 | const struct weston_shell_client *client) |
Pekka Paalanen | 9d1613e | 2011-11-25 12:09:16 +0200 | [diff] [blame] | 3463 | { |
Pekka Paalanen | 9d1613e | 2011-11-25 12:09:16 +0200 | [diff] [blame] | 3464 | struct shell_surface *shsurf; |
| 3465 | |
Ander Conselvan de Oliveira | 093bfa3 | 2012-03-27 17:36:41 +0300 | [diff] [blame] | 3466 | if (surface->configure) { |
Martin Minarik | 6d11836 | 2012-06-07 18:01:59 +0200 | [diff] [blame] | 3467 | weston_log("surface->configure already set\n"); |
Kristian Høgsberg | 45ba869 | 2012-05-21 14:27:33 -0400 | [diff] [blame] | 3468 | return NULL; |
Ander Conselvan de Oliveira | 093bfa3 | 2012-03-27 17:36:41 +0300 | [diff] [blame] | 3469 | } |
| 3470 | |
Pekka Paalanen | 9d1613e | 2011-11-25 12:09:16 +0200 | [diff] [blame] | 3471 | shsurf = calloc(1, sizeof *shsurf); |
| 3472 | if (!shsurf) { |
Martin Minarik | 6d11836 | 2012-06-07 18:01:59 +0200 | [diff] [blame] | 3473 | weston_log("no memory to allocate shell surface\n"); |
Kristian Høgsberg | 45ba869 | 2012-05-21 14:27:33 -0400 | [diff] [blame] | 3474 | return NULL; |
Pekka Paalanen | 9d1613e | 2011-11-25 12:09:16 +0200 | [diff] [blame] | 3475 | } |
| 3476 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 3477 | shsurf->view = weston_view_create(surface); |
| 3478 | if (!shsurf->view) { |
| 3479 | weston_log("no memory to allocate shell surface\n"); |
| 3480 | free(shsurf); |
| 3481 | return NULL; |
| 3482 | } |
| 3483 | |
Ander Conselvan de Oliveira | 093bfa3 | 2012-03-27 17:36:41 +0300 | [diff] [blame] | 3484 | surface->configure = shell_surface_configure; |
Giulio Camuffo | 7fe01b1 | 2013-03-28 18:02:42 +0100 | [diff] [blame] | 3485 | surface->configure_private = shsurf; |
Ander Conselvan de Oliveira | 093bfa3 | 2012-03-27 17:36:41 +0300 | [diff] [blame] | 3486 | |
Kristian Høgsberg | 160fe75 | 2014-03-11 10:19:10 -0700 | [diff] [blame] | 3487 | shsurf->resource_destroy_listener.notify = handle_resource_destroy; |
| 3488 | wl_resource_add_destroy_listener(surface->resource, |
| 3489 | &shsurf->resource_destroy_listener); |
Jason Ekstrand | 9e9512f | 2014-04-16 21:12:10 -0500 | [diff] [blame] | 3490 | shsurf->owner = owner; |
Kristian Høgsberg | 160fe75 | 2014-03-11 10:19:10 -0700 | [diff] [blame] | 3491 | |
Tiago Vignatti | bc052c9 | 2012-04-19 16:18:18 +0300 | [diff] [blame] | 3492 | shsurf->shell = (struct desktop_shell *) shell; |
Scott Moreau | ff1db4a | 2012-04-17 19:06:18 -0600 | [diff] [blame] | 3493 | shsurf->unresponsive = 0; |
Alex Wu | 4539b08 | 2012-03-01 12:57:46 +0800 | [diff] [blame] | 3494 | shsurf->saved_position_valid = false; |
Rafael Antognolli | 3c4e3f7 | 2013-12-03 15:35:46 -0200 | [diff] [blame] | 3495 | shsurf->saved_size_valid = false; |
Alex Wu | 7bcb8bd | 2012-04-27 09:07:24 +0800 | [diff] [blame] | 3496 | shsurf->saved_rotation_valid = false; |
Pekka Paalanen | 9d1613e | 2011-11-25 12:09:16 +0200 | [diff] [blame] | 3497 | shsurf->surface = surface; |
Alex Wu | 4539b08 | 2012-03-01 12:57:46 +0800 | [diff] [blame] | 3498 | shsurf->fullscreen.type = WL_SHELL_SURFACE_FULLSCREEN_METHOD_DEFAULT; |
| 3499 | shsurf->fullscreen.framerate = 0; |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 3500 | shsurf->fullscreen.black_view = NULL; |
Alex Wu | 4539b08 | 2012-03-01 12:57:46 +0800 | [diff] [blame] | 3501 | wl_list_init(&shsurf->fullscreen.transform.link); |
| 3502 | |
Jasper St. Pierre | 9aa8ce6 | 2014-04-11 16:18:54 -0700 | [diff] [blame] | 3503 | shsurf->output = get_default_output(shsurf->shell->compositor); |
| 3504 | |
Jason Ekstrand | 651f00e | 2013-06-14 10:07:54 -0500 | [diff] [blame] | 3505 | wl_signal_init(&shsurf->destroy_signal); |
Kristian Høgsberg | 27e3052 | 2012-04-11 23:18:23 -0400 | [diff] [blame] | 3506 | shsurf->surface_destroy_listener.notify = shell_handle_surface_destroy; |
Jason Ekstrand | 26ed73c | 2013-06-06 22:34:41 -0500 | [diff] [blame] | 3507 | wl_signal_add(&surface->destroy_signal, |
Kristian Høgsberg | 27e3052 | 2012-04-11 23:18:23 -0400 | [diff] [blame] | 3508 | &shsurf->surface_destroy_listener); |
Pekka Paalanen | 9d1613e | 2011-11-25 12:09:16 +0200 | [diff] [blame] | 3509 | |
| 3510 | /* init link so its safe to always remove it in destroy_shell_surface */ |
| 3511 | wl_list_init(&shsurf->link); |
Giulio Camuffo | 5085a75 | 2013-03-25 21:42:45 +0100 | [diff] [blame] | 3512 | wl_list_init(&shsurf->popup.grab_link); |
Pekka Paalanen | 9d1613e | 2011-11-25 12:09:16 +0200 | [diff] [blame] | 3513 | |
Pekka Paalanen | 460099f | 2012-01-20 16:48:25 +0200 | [diff] [blame] | 3514 | /* empty when not in use */ |
| 3515 | wl_list_init(&shsurf->rotation.transform.link); |
Kristian Høgsberg | 765e27b | 2012-01-27 13:36:13 -0500 | [diff] [blame] | 3516 | weston_matrix_init(&shsurf->rotation.rotation); |
Pekka Paalanen | 460099f | 2012-01-20 16:48:25 +0200 | [diff] [blame] | 3517 | |
Jonas Ådahl | 62fcd04 | 2012-06-13 00:01:23 +0200 | [diff] [blame] | 3518 | wl_list_init(&shsurf->workspace_transform.link); |
| 3519 | |
Philip Withnall | 648a4dd | 2013-11-25 18:01:44 +0000 | [diff] [blame] | 3520 | wl_list_init(&shsurf->children_link); |
| 3521 | wl_list_init(&shsurf->children_list); |
| 3522 | shsurf->parent = NULL; |
| 3523 | |
Pekka Paalanen | 9826223 | 2011-12-01 10:42:22 +0200 | [diff] [blame] | 3524 | shsurf->type = SHELL_SURFACE_NONE; |
Pekka Paalanen | 9d1613e | 2011-11-25 12:09:16 +0200 | [diff] [blame] | 3525 | |
Kristian Høgsberg | a61ca06 | 2012-05-22 16:05:52 -0400 | [diff] [blame] | 3526 | shsurf->client = client; |
| 3527 | |
Kristian Høgsberg | 45ba869 | 2012-05-21 14:27:33 -0400 | [diff] [blame] | 3528 | return shsurf; |
Tiago Vignatti | bc052c9 | 2012-04-19 16:18:18 +0300 | [diff] [blame] | 3529 | } |
| 3530 | |
Rafael Antognolli | e2a3455 | 2013-12-03 15:35:45 -0200 | [diff] [blame] | 3531 | static struct shell_surface * |
| 3532 | create_shell_surface(void *shell, struct weston_surface *surface, |
| 3533 | const struct weston_shell_client *client) |
| 3534 | { |
Jason Ekstrand | 9e9512f | 2014-04-16 21:12:10 -0500 | [diff] [blame] | 3535 | return create_common_surface(NULL, shell, surface, client); |
Rafael Antognolli | e2a3455 | 2013-12-03 15:35:45 -0200 | [diff] [blame] | 3536 | } |
| 3537 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 3538 | static struct weston_view * |
| 3539 | get_primary_view(void *shell, struct shell_surface *shsurf) |
| 3540 | { |
| 3541 | return shsurf->view; |
| 3542 | } |
| 3543 | |
Marek Chalupa | bfbb64b | 2014-09-08 12:34:20 +0200 | [diff] [blame] | 3544 | static struct weston_output * |
| 3545 | get_focused_output(struct weston_compositor *compositor) |
| 3546 | { |
| 3547 | struct weston_seat *seat; |
| 3548 | struct weston_output *output = NULL; |
| 3549 | |
| 3550 | wl_list_for_each(seat, &compositor->seat_list, link) { |
| 3551 | /* Priority has touch focus, then pointer and |
| 3552 | * then keyboard focus. We should probably have |
| 3553 | * three for loops and check frist for touch, |
| 3554 | * then for pointer, etc. but unless somebody has some |
| 3555 | * objections, I think this is sufficient. */ |
| 3556 | if (seat->touch && seat->touch->focus) |
| 3557 | output = seat->touch->focus->output; |
| 3558 | else if (seat->pointer && seat->pointer->focus) |
| 3559 | output = seat->pointer->focus->output; |
| 3560 | else if (seat->keyboard && seat->keyboard->focus) |
| 3561 | output = seat->keyboard->focus->output; |
| 3562 | |
| 3563 | if (output) |
| 3564 | break; |
| 3565 | } |
| 3566 | |
| 3567 | return output; |
| 3568 | } |
| 3569 | |
Tiago Vignatti | bc052c9 | 2012-04-19 16:18:18 +0300 | [diff] [blame] | 3570 | static void |
| 3571 | shell_get_shell_surface(struct wl_client *client, |
| 3572 | struct wl_resource *resource, |
| 3573 | uint32_t id, |
| 3574 | struct wl_resource *surface_resource) |
| 3575 | { |
Jason Ekstrand | 0f2ef7e | 2013-06-14 10:07:53 -0500 | [diff] [blame] | 3576 | struct weston_surface *surface = |
| 3577 | wl_resource_get_user_data(surface_resource); |
Jason Ekstrand | 9e9512f | 2014-04-16 21:12:10 -0500 | [diff] [blame] | 3578 | struct shell_client *sc = wl_resource_get_user_data(resource); |
| 3579 | struct desktop_shell *shell = sc->shell; |
Tiago Vignatti | bc052c9 | 2012-04-19 16:18:18 +0300 | [diff] [blame] | 3580 | struct shell_surface *shsurf; |
| 3581 | |
| 3582 | if (get_shell_surface(surface)) { |
| 3583 | wl_resource_post_error(surface_resource, |
Kristian Høgsberg | 9540ea6 | 2012-05-21 14:28:57 -0400 | [diff] [blame] | 3584 | WL_DISPLAY_ERROR_INVALID_OBJECT, |
| 3585 | "desktop_shell::get_shell_surface already requested"); |
Tiago Vignatti | bc052c9 | 2012-04-19 16:18:18 +0300 | [diff] [blame] | 3586 | return; |
| 3587 | } |
| 3588 | |
Jason Ekstrand | 9e9512f | 2014-04-16 21:12:10 -0500 | [diff] [blame] | 3589 | shsurf = create_common_surface(sc, shell, surface, &shell_client); |
Kristian Høgsberg | 9540ea6 | 2012-05-21 14:28:57 -0400 | [diff] [blame] | 3590 | if (!shsurf) { |
| 3591 | wl_resource_post_error(surface_resource, |
| 3592 | WL_DISPLAY_ERROR_INVALID_OBJECT, |
| 3593 | "surface->configure already set"); |
| 3594 | return; |
| 3595 | } |
Tiago Vignatti | bc052c9 | 2012-04-19 16:18:18 +0300 | [diff] [blame] | 3596 | |
Jason Ekstrand | a85118c | 2013-06-27 20:17:02 -0500 | [diff] [blame] | 3597 | shsurf->resource = |
| 3598 | wl_resource_create(client, |
| 3599 | &wl_shell_surface_interface, 1, id); |
| 3600 | wl_resource_set_implementation(shsurf->resource, |
| 3601 | &shell_surface_implementation, |
| 3602 | shsurf, shell_destroy_shell_surface); |
Pekka Paalanen | 9d1613e | 2011-11-25 12:09:16 +0200 | [diff] [blame] | 3603 | } |
| 3604 | |
Rafael Antognolli | e2a3455 | 2013-12-03 15:35:45 -0200 | [diff] [blame] | 3605 | static bool |
| 3606 | shell_surface_is_wl_shell_surface(struct shell_surface *shsurf) |
| 3607 | { |
Kristian Høgsberg | 0b7d995 | 2014-02-03 15:50:38 -0800 | [diff] [blame] | 3608 | /* A shell surface without a resource is created from xwayland |
| 3609 | * and is considered a wl_shell surface for now. */ |
| 3610 | |
| 3611 | return shsurf->resource == NULL || |
| 3612 | wl_resource_instance_of(shsurf->resource, |
| 3613 | &wl_shell_surface_interface, |
| 3614 | &shell_surface_implementation); |
Rafael Antognolli | e2a3455 | 2013-12-03 15:35:45 -0200 | [diff] [blame] | 3615 | } |
| 3616 | |
Pekka Paalanen | 9d1613e | 2011-11-25 12:09:16 +0200 | [diff] [blame] | 3617 | static const struct wl_shell_interface shell_implementation = { |
Pekka Paalanen | 4622967 | 2011-11-29 15:49:31 +0200 | [diff] [blame] | 3618 | shell_get_shell_surface |
Kristian Høgsberg | 4cca349 | 2011-01-18 07:53:49 -0500 | [diff] [blame] | 3619 | }; |
| 3620 | |
Rafael Antognolli | e2a3455 | 2013-12-03 15:35:45 -0200 | [diff] [blame] | 3621 | /**************************** |
| 3622 | * xdg-shell implementation */ |
| 3623 | |
| 3624 | static void |
| 3625 | xdg_surface_destroy(struct wl_client *client, |
| 3626 | struct wl_resource *resource) |
| 3627 | { |
| 3628 | wl_resource_destroy(resource); |
| 3629 | } |
| 3630 | |
| 3631 | static void |
Jasper St. Pierre | c815d62 | 2014-04-10 18:37:54 -0700 | [diff] [blame] | 3632 | xdg_surface_set_parent(struct wl_client *client, |
| 3633 | struct wl_resource *resource, |
| 3634 | struct wl_resource *parent_resource) |
Jasper St. Pierre | 63a9c33 | 2014-02-01 18:35:15 -0500 | [diff] [blame] | 3635 | { |
| 3636 | struct shell_surface *shsurf = wl_resource_get_user_data(resource); |
| 3637 | struct weston_surface *parent; |
| 3638 | |
| 3639 | if (parent_resource) |
| 3640 | parent = wl_resource_get_user_data(parent_resource); |
| 3641 | else |
| 3642 | parent = NULL; |
| 3643 | |
| 3644 | shell_surface_set_parent(shsurf, parent); |
| 3645 | } |
| 3646 | |
| 3647 | static void |
Rafael Antognolli | e2a3455 | 2013-12-03 15:35:45 -0200 | [diff] [blame] | 3648 | xdg_surface_set_app_id(struct wl_client *client, |
| 3649 | struct wl_resource *resource, |
| 3650 | const char *app_id) |
| 3651 | { |
| 3652 | struct shell_surface *shsurf = wl_resource_get_user_data(resource); |
| 3653 | |
| 3654 | free(shsurf->class); |
| 3655 | shsurf->class = strdup(app_id); |
| 3656 | } |
| 3657 | |
| 3658 | static void |
Jasper St. Pierre | 81ff075 | 2014-03-13 11:04:53 -0400 | [diff] [blame] | 3659 | xdg_surface_show_window_menu(struct wl_client *client, |
| 3660 | struct wl_resource *surface_resource, |
| 3661 | struct wl_resource *seat_resource, |
| 3662 | uint32_t serial, |
| 3663 | int32_t x, |
| 3664 | int32_t y) |
| 3665 | { |
| 3666 | /* TODO */ |
| 3667 | } |
| 3668 | |
| 3669 | static void |
Rafael Antognolli | e2a3455 | 2013-12-03 15:35:45 -0200 | [diff] [blame] | 3670 | xdg_surface_set_title(struct wl_client *client, |
| 3671 | struct wl_resource *resource, const char *title) |
| 3672 | { |
| 3673 | struct shell_surface *shsurf = wl_resource_get_user_data(resource); |
| 3674 | |
| 3675 | set_title(shsurf, title); |
| 3676 | } |
| 3677 | |
| 3678 | static void |
| 3679 | xdg_surface_move(struct wl_client *client, struct wl_resource *resource, |
| 3680 | struct wl_resource *seat_resource, uint32_t serial) |
| 3681 | { |
| 3682 | common_surface_move(resource, seat_resource, serial); |
| 3683 | } |
| 3684 | |
| 3685 | static void |
| 3686 | xdg_surface_resize(struct wl_client *client, struct wl_resource *resource, |
| 3687 | struct wl_resource *seat_resource, uint32_t serial, |
| 3688 | uint32_t edges) |
| 3689 | { |
| 3690 | common_surface_resize(resource, seat_resource, serial, edges); |
| 3691 | } |
| 3692 | |
| 3693 | static void |
Jasper St. Pierre | ab2c108 | 2014-04-10 10:41:46 -0700 | [diff] [blame] | 3694 | xdg_surface_ack_configure(struct wl_client *client, |
| 3695 | struct wl_resource *resource, |
| 3696 | uint32_t serial) |
Rafael Antognolli | e2a3455 | 2013-12-03 15:35:45 -0200 | [diff] [blame] | 3697 | { |
| 3698 | struct shell_surface *shsurf = wl_resource_get_user_data(resource); |
| 3699 | |
Jasper St. Pierre | 8c6aa45 | 2014-02-08 18:29:49 -0500 | [diff] [blame] | 3700 | if (shsurf->state_requested) { |
| 3701 | shsurf->next_state = shsurf->requested_state; |
| 3702 | shsurf->state_changed = true; |
| 3703 | shsurf->state_requested = false; |
Rafael Antognolli | 3c4e3f7 | 2013-12-03 15:35:46 -0200 | [diff] [blame] | 3704 | } |
Rafael Antognolli | e2a3455 | 2013-12-03 15:35:45 -0200 | [diff] [blame] | 3705 | } |
| 3706 | |
Manuel Bachmann | 50c87db | 2014-02-26 15:52:13 +0100 | [diff] [blame] | 3707 | static void |
Jasper St. Pierre | ccf48fb | 2014-05-02 10:21:38 -0400 | [diff] [blame] | 3708 | xdg_surface_set_window_geometry(struct wl_client *client, |
| 3709 | struct wl_resource *resource, |
| 3710 | int32_t x, |
| 3711 | int32_t y, |
| 3712 | int32_t width, |
| 3713 | int32_t height) |
| 3714 | { |
| 3715 | struct shell_surface *shsurf = wl_resource_get_user_data(resource); |
| 3716 | |
| 3717 | set_window_geometry(shsurf, x, y, width, height); |
| 3718 | } |
| 3719 | |
| 3720 | static void |
Jasper St. Pierre | ab2c108 | 2014-04-10 10:41:46 -0700 | [diff] [blame] | 3721 | xdg_surface_set_maximized(struct wl_client *client, |
| 3722 | struct wl_resource *resource) |
| 3723 | { |
| 3724 | struct shell_surface *shsurf = wl_resource_get_user_data(resource); |
Marek Chalupa | bfbb64b | 2014-09-08 12:34:20 +0200 | [diff] [blame] | 3725 | struct weston_output *output; |
Jasper St. Pierre | ab2c108 | 2014-04-10 10:41:46 -0700 | [diff] [blame] | 3726 | |
| 3727 | shsurf->state_requested = true; |
| 3728 | shsurf->requested_state.maximized = true; |
Marek Chalupa | bfbb64b | 2014-09-08 12:34:20 +0200 | [diff] [blame] | 3729 | |
| 3730 | if (!weston_surface_is_mapped(shsurf->surface)) |
| 3731 | output = get_focused_output(shsurf->surface->compositor); |
| 3732 | else |
| 3733 | output = shsurf->surface->output; |
| 3734 | |
| 3735 | shell_surface_set_output(shsurf, output); |
Jasper St. Pierre | 9aa8ce6 | 2014-04-11 16:18:54 -0700 | [diff] [blame] | 3736 | send_configure_for_surface(shsurf); |
Jasper St. Pierre | ab2c108 | 2014-04-10 10:41:46 -0700 | [diff] [blame] | 3737 | } |
| 3738 | |
| 3739 | static void |
| 3740 | xdg_surface_unset_maximized(struct wl_client *client, |
| 3741 | struct wl_resource *resource) |
| 3742 | { |
| 3743 | struct shell_surface *shsurf = wl_resource_get_user_data(resource); |
| 3744 | |
| 3745 | shsurf->state_requested = true; |
| 3746 | shsurf->requested_state.maximized = false; |
Jasper St. Pierre | 6458ec3 | 2014-04-11 16:00:31 -0700 | [diff] [blame] | 3747 | send_configure_for_surface(shsurf); |
Jasper St. Pierre | ab2c108 | 2014-04-10 10:41:46 -0700 | [diff] [blame] | 3748 | } |
| 3749 | |
| 3750 | static void |
| 3751 | xdg_surface_set_fullscreen(struct wl_client *client, |
| 3752 | struct wl_resource *resource, |
| 3753 | struct wl_resource *output_resource) |
| 3754 | { |
| 3755 | struct shell_surface *shsurf = wl_resource_get_user_data(resource); |
| 3756 | struct weston_output *output; |
| 3757 | |
| 3758 | shsurf->state_requested = true; |
| 3759 | shsurf->requested_state.fullscreen = true; |
| 3760 | |
| 3761 | if (output_resource) |
| 3762 | output = wl_resource_get_user_data(output_resource); |
| 3763 | else |
| 3764 | output = NULL; |
| 3765 | |
Marek Chalupa | 052917a | 2014-09-02 11:35:12 +0200 | [diff] [blame] | 3766 | /* handle clients launching in fullscreen */ |
| 3767 | if (output == NULL && !weston_surface_is_mapped(shsurf->surface)) { |
| 3768 | /* Set the output to the one that has focus currently. */ |
| 3769 | assert(shsurf->surface); |
| 3770 | output = get_focused_output(shsurf->surface->compositor); |
| 3771 | } |
| 3772 | |
Jasper St. Pierre | 9aa8ce6 | 2014-04-11 16:18:54 -0700 | [diff] [blame] | 3773 | shell_surface_set_output(shsurf, output); |
| 3774 | shsurf->fullscreen_output = shsurf->output; |
Jasper St. Pierre | ab2c108 | 2014-04-10 10:41:46 -0700 | [diff] [blame] | 3775 | |
Jasper St. Pierre | 9aa8ce6 | 2014-04-11 16:18:54 -0700 | [diff] [blame] | 3776 | send_configure_for_surface(shsurf); |
Jasper St. Pierre | ab2c108 | 2014-04-10 10:41:46 -0700 | [diff] [blame] | 3777 | } |
| 3778 | |
| 3779 | static void |
| 3780 | xdg_surface_unset_fullscreen(struct wl_client *client, |
| 3781 | struct wl_resource *resource) |
| 3782 | { |
| 3783 | struct shell_surface *shsurf = wl_resource_get_user_data(resource); |
| 3784 | |
| 3785 | shsurf->state_requested = true; |
| 3786 | shsurf->requested_state.fullscreen = false; |
Jasper St. Pierre | 6458ec3 | 2014-04-11 16:00:31 -0700 | [diff] [blame] | 3787 | send_configure_for_surface(shsurf); |
Jasper St. Pierre | ab2c108 | 2014-04-10 10:41:46 -0700 | [diff] [blame] | 3788 | } |
| 3789 | |
| 3790 | static void |
Manuel Bachmann | 50c87db | 2014-02-26 15:52:13 +0100 | [diff] [blame] | 3791 | xdg_surface_set_minimized(struct wl_client *client, |
| 3792 | struct wl_resource *resource) |
| 3793 | { |
| 3794 | struct shell_surface *shsurf = wl_resource_get_user_data(resource); |
| 3795 | |
| 3796 | if (shsurf->type != SHELL_SURFACE_TOPLEVEL) |
| 3797 | return; |
| 3798 | |
| 3799 | /* apply compositor's own minimization logic (hide) */ |
| 3800 | set_minimized(shsurf->surface, 1); |
| 3801 | } |
| 3802 | |
Rafael Antognolli | e2a3455 | 2013-12-03 15:35:45 -0200 | [diff] [blame] | 3803 | static const struct xdg_surface_interface xdg_surface_implementation = { |
| 3804 | xdg_surface_destroy, |
Jasper St. Pierre | c815d62 | 2014-04-10 18:37:54 -0700 | [diff] [blame] | 3805 | xdg_surface_set_parent, |
Rafael Antognolli | e2a3455 | 2013-12-03 15:35:45 -0200 | [diff] [blame] | 3806 | xdg_surface_set_title, |
| 3807 | xdg_surface_set_app_id, |
Jasper St. Pierre | 81ff075 | 2014-03-13 11:04:53 -0400 | [diff] [blame] | 3808 | xdg_surface_show_window_menu, |
Rafael Antognolli | e2a3455 | 2013-12-03 15:35:45 -0200 | [diff] [blame] | 3809 | xdg_surface_move, |
| 3810 | xdg_surface_resize, |
Jasper St. Pierre | ab2c108 | 2014-04-10 10:41:46 -0700 | [diff] [blame] | 3811 | xdg_surface_ack_configure, |
Jasper St. Pierre | ccf48fb | 2014-05-02 10:21:38 -0400 | [diff] [blame] | 3812 | xdg_surface_set_window_geometry, |
Jasper St. Pierre | ab2c108 | 2014-04-10 10:41:46 -0700 | [diff] [blame] | 3813 | xdg_surface_set_maximized, |
| 3814 | xdg_surface_unset_maximized, |
| 3815 | xdg_surface_set_fullscreen, |
| 3816 | xdg_surface_unset_fullscreen, |
| 3817 | xdg_surface_set_minimized, |
Rafael Antognolli | e2a3455 | 2013-12-03 15:35:45 -0200 | [diff] [blame] | 3818 | }; |
| 3819 | |
| 3820 | static void |
| 3821 | xdg_send_configure(struct weston_surface *surface, |
Jasper St. Pierre | ac985be | 2014-04-28 11:19:28 -0400 | [diff] [blame] | 3822 | int32_t width, int32_t height) |
Rafael Antognolli | e2a3455 | 2013-12-03 15:35:45 -0200 | [diff] [blame] | 3823 | { |
| 3824 | struct shell_surface *shsurf = get_shell_surface(surface); |
Jasper St. Pierre | ab2c108 | 2014-04-10 10:41:46 -0700 | [diff] [blame] | 3825 | uint32_t *s; |
| 3826 | struct wl_array states; |
| 3827 | uint32_t serial; |
Rafael Antognolli | e2a3455 | 2013-12-03 15:35:45 -0200 | [diff] [blame] | 3828 | |
U. Artie Eoff | cf5737a | 2014-01-17 10:08:25 -0800 | [diff] [blame] | 3829 | assert(shsurf); |
| 3830 | |
Jasper St. Pierre | ab2c108 | 2014-04-10 10:41:46 -0700 | [diff] [blame] | 3831 | if (!shsurf->resource) |
| 3832 | return; |
| 3833 | |
| 3834 | wl_array_init(&states); |
| 3835 | if (shsurf->requested_state.fullscreen) { |
| 3836 | s = wl_array_add(&states, sizeof *s); |
| 3837 | *s = XDG_SURFACE_STATE_FULLSCREEN; |
| 3838 | } else if (shsurf->requested_state.maximized) { |
| 3839 | s = wl_array_add(&states, sizeof *s); |
| 3840 | *s = XDG_SURFACE_STATE_MAXIMIZED; |
| 3841 | } |
Jasper St. Pierre | 5befdda | 2014-05-06 08:50:47 -0400 | [diff] [blame] | 3842 | if (shsurf->resize_edges != 0) { |
| 3843 | s = wl_array_add(&states, sizeof *s); |
| 3844 | *s = XDG_SURFACE_STATE_RESIZING; |
| 3845 | } |
Jasper St. Pierre | 973d787 | 2014-05-06 08:44:29 -0400 | [diff] [blame] | 3846 | if (shsurf->focus_count > 0) { |
| 3847 | s = wl_array_add(&states, sizeof *s); |
| 3848 | *s = XDG_SURFACE_STATE_ACTIVATED; |
| 3849 | } |
Jasper St. Pierre | ab2c108 | 2014-04-10 10:41:46 -0700 | [diff] [blame] | 3850 | |
| 3851 | serial = wl_display_next_serial(shsurf->surface->compositor->wl_display); |
| 3852 | xdg_surface_send_configure(shsurf->resource, width, height, &states, serial); |
| 3853 | |
| 3854 | wl_array_release(&states); |
Rafael Antognolli | e2a3455 | 2013-12-03 15:35:45 -0200 | [diff] [blame] | 3855 | } |
| 3856 | |
| 3857 | static const struct weston_shell_client xdg_client = { |
| 3858 | xdg_send_configure |
| 3859 | }; |
| 3860 | |
| 3861 | static void |
| 3862 | xdg_use_unstable_version(struct wl_client *client, |
| 3863 | struct wl_resource *resource, |
| 3864 | int32_t version) |
| 3865 | { |
| 3866 | if (version > 1) { |
| 3867 | wl_resource_post_error(resource, |
| 3868 | 1, |
| 3869 | "xdg-shell:: version not implemented yet."); |
| 3870 | return; |
| 3871 | } |
| 3872 | } |
| 3873 | |
| 3874 | static struct shell_surface * |
Jason Ekstrand | 9e9512f | 2014-04-16 21:12:10 -0500 | [diff] [blame] | 3875 | create_xdg_surface(struct shell_client *owner, void *shell, |
| 3876 | struct weston_surface *surface, |
Rafael Antognolli | e2a3455 | 2013-12-03 15:35:45 -0200 | [diff] [blame] | 3877 | const struct weston_shell_client *client) |
| 3878 | { |
| 3879 | struct shell_surface *shsurf; |
Rafael Antognolli | e2a3455 | 2013-12-03 15:35:45 -0200 | [diff] [blame] | 3880 | |
Jason Ekstrand | 9e9512f | 2014-04-16 21:12:10 -0500 | [diff] [blame] | 3881 | shsurf = create_common_surface(owner, shell, surface, client); |
Kristian Høgsberg | c8f8dd8 | 2013-12-05 23:20:33 -0800 | [diff] [blame] | 3882 | shsurf->type = SHELL_SURFACE_TOPLEVEL; |
Rafael Antognolli | e2a3455 | 2013-12-03 15:35:45 -0200 | [diff] [blame] | 3883 | |
| 3884 | return shsurf; |
| 3885 | } |
| 3886 | |
| 3887 | static void |
| 3888 | xdg_get_xdg_surface(struct wl_client *client, |
| 3889 | struct wl_resource *resource, |
| 3890 | uint32_t id, |
| 3891 | struct wl_resource *surface_resource) |
| 3892 | { |
| 3893 | struct weston_surface *surface = |
| 3894 | wl_resource_get_user_data(surface_resource); |
Kristian Høgsberg | 2bff94e | 2014-02-11 12:22:51 -0800 | [diff] [blame] | 3895 | struct shell_client *sc = wl_resource_get_user_data(resource); |
| 3896 | struct desktop_shell *shell = sc->shell; |
Rafael Antognolli | e2a3455 | 2013-12-03 15:35:45 -0200 | [diff] [blame] | 3897 | struct shell_surface *shsurf; |
| 3898 | |
| 3899 | if (get_shell_surface(surface)) { |
| 3900 | wl_resource_post_error(surface_resource, |
| 3901 | WL_DISPLAY_ERROR_INVALID_OBJECT, |
Jasper St. Pierre | fe9671e | 2014-03-25 13:31:44 -0400 | [diff] [blame] | 3902 | "xdg_shell::get_xdg_surface already requested"); |
Rafael Antognolli | e2a3455 | 2013-12-03 15:35:45 -0200 | [diff] [blame] | 3903 | return; |
| 3904 | } |
| 3905 | |
Jason Ekstrand | 9e9512f | 2014-04-16 21:12:10 -0500 | [diff] [blame] | 3906 | shsurf = create_xdg_surface(sc, shell, surface, &xdg_client); |
Rafael Antognolli | e2a3455 | 2013-12-03 15:35:45 -0200 | [diff] [blame] | 3907 | if (!shsurf) { |
| 3908 | wl_resource_post_error(surface_resource, |
| 3909 | WL_DISPLAY_ERROR_INVALID_OBJECT, |
| 3910 | "surface->configure already set"); |
| 3911 | return; |
| 3912 | } |
| 3913 | |
| 3914 | shsurf->resource = |
| 3915 | wl_resource_create(client, |
| 3916 | &xdg_surface_interface, 1, id); |
| 3917 | wl_resource_set_implementation(shsurf->resource, |
| 3918 | &xdg_surface_implementation, |
| 3919 | shsurf, shell_destroy_shell_surface); |
| 3920 | } |
| 3921 | |
| 3922 | static bool |
| 3923 | shell_surface_is_xdg_surface(struct shell_surface *shsurf) |
| 3924 | { |
Kristian Høgsberg | 0b7d995 | 2014-02-03 15:50:38 -0800 | [diff] [blame] | 3925 | return shsurf->resource && |
| 3926 | wl_resource_instance_of(shsurf->resource, |
| 3927 | &xdg_surface_interface, |
| 3928 | &xdg_surface_implementation); |
Rafael Antognolli | e2a3455 | 2013-12-03 15:35:45 -0200 | [diff] [blame] | 3929 | } |
| 3930 | |
| 3931 | /* xdg-popup implementation */ |
| 3932 | |
| 3933 | static void |
| 3934 | xdg_popup_destroy(struct wl_client *client, |
| 3935 | struct wl_resource *resource) |
| 3936 | { |
| 3937 | wl_resource_destroy(resource); |
| 3938 | } |
| 3939 | |
Rafael Antognolli | e2a3455 | 2013-12-03 15:35:45 -0200 | [diff] [blame] | 3940 | static const struct xdg_popup_interface xdg_popup_implementation = { |
| 3941 | xdg_popup_destroy, |
Rafael Antognolli | e2a3455 | 2013-12-03 15:35:45 -0200 | [diff] [blame] | 3942 | }; |
| 3943 | |
| 3944 | static void |
| 3945 | xdg_popup_send_configure(struct weston_surface *surface, |
Jasper St. Pierre | ac985be | 2014-04-28 11:19:28 -0400 | [diff] [blame] | 3946 | int32_t width, int32_t height) |
Rafael Antognolli | e2a3455 | 2013-12-03 15:35:45 -0200 | [diff] [blame] | 3947 | { |
| 3948 | } |
| 3949 | |
| 3950 | static const struct weston_shell_client xdg_popup_client = { |
| 3951 | xdg_popup_send_configure |
| 3952 | }; |
| 3953 | |
| 3954 | static struct shell_surface * |
Jason Ekstrand | 9e9512f | 2014-04-16 21:12:10 -0500 | [diff] [blame] | 3955 | create_xdg_popup(struct shell_client *owner, void *shell, |
| 3956 | struct weston_surface *surface, |
Rafael Antognolli | e2a3455 | 2013-12-03 15:35:45 -0200 | [diff] [blame] | 3957 | const struct weston_shell_client *client, |
| 3958 | struct weston_surface *parent, |
| 3959 | struct shell_seat *seat, |
| 3960 | uint32_t serial, |
| 3961 | int32_t x, int32_t y) |
| 3962 | { |
| 3963 | struct shell_surface *shsurf; |
Rafael Antognolli | e2a3455 | 2013-12-03 15:35:45 -0200 | [diff] [blame] | 3964 | |
Jason Ekstrand | 9e9512f | 2014-04-16 21:12:10 -0500 | [diff] [blame] | 3965 | shsurf = create_common_surface(owner, shell, surface, client); |
Kristian Høgsberg | c8f8dd8 | 2013-12-05 23:20:33 -0800 | [diff] [blame] | 3966 | shsurf->type = SHELL_SURFACE_POPUP; |
Rafael Antognolli | e2a3455 | 2013-12-03 15:35:45 -0200 | [diff] [blame] | 3967 | shsurf->popup.shseat = seat; |
| 3968 | shsurf->popup.serial = serial; |
| 3969 | shsurf->popup.x = x; |
| 3970 | shsurf->popup.y = y; |
| 3971 | shell_surface_set_parent(shsurf, parent); |
| 3972 | |
| 3973 | return shsurf; |
| 3974 | } |
| 3975 | |
| 3976 | static void |
| 3977 | xdg_get_xdg_popup(struct wl_client *client, |
| 3978 | struct wl_resource *resource, |
| 3979 | uint32_t id, |
| 3980 | struct wl_resource *surface_resource, |
| 3981 | struct wl_resource *parent_resource, |
| 3982 | struct wl_resource *seat_resource, |
| 3983 | uint32_t serial, |
| 3984 | int32_t x, int32_t y, uint32_t flags) |
| 3985 | { |
| 3986 | struct weston_surface *surface = |
| 3987 | wl_resource_get_user_data(surface_resource); |
Kristian Høgsberg | 2bff94e | 2014-02-11 12:22:51 -0800 | [diff] [blame] | 3988 | struct shell_client *sc = wl_resource_get_user_data(resource); |
| 3989 | struct desktop_shell *shell = sc->shell; |
Rafael Antognolli | e2a3455 | 2013-12-03 15:35:45 -0200 | [diff] [blame] | 3990 | struct shell_surface *shsurf; |
| 3991 | struct weston_surface *parent; |
| 3992 | struct shell_seat *seat; |
| 3993 | |
| 3994 | if (get_shell_surface(surface)) { |
| 3995 | wl_resource_post_error(surface_resource, |
| 3996 | WL_DISPLAY_ERROR_INVALID_OBJECT, |
Jasper St. Pierre | fe9671e | 2014-03-25 13:31:44 -0400 | [diff] [blame] | 3997 | "xdg_shell::get_xdg_popup already requested"); |
Rafael Antognolli | e2a3455 | 2013-12-03 15:35:45 -0200 | [diff] [blame] | 3998 | return; |
| 3999 | } |
| 4000 | |
| 4001 | if (!parent_resource) { |
| 4002 | wl_resource_post_error(surface_resource, |
| 4003 | WL_DISPLAY_ERROR_INVALID_OBJECT, |
| 4004 | "xdg_shell::get_xdg_popup requires a parent shell surface"); |
Jasper St. Pierre | 666bc92 | 2014-08-07 16:43:13 -0400 | [diff] [blame] | 4005 | return; |
Rafael Antognolli | e2a3455 | 2013-12-03 15:35:45 -0200 | [diff] [blame] | 4006 | } |
| 4007 | |
| 4008 | parent = wl_resource_get_user_data(parent_resource); |
| 4009 | seat = get_shell_seat(wl_resource_get_user_data(seat_resource));; |
| 4010 | |
Jason Ekstrand | 9e9512f | 2014-04-16 21:12:10 -0500 | [diff] [blame] | 4011 | shsurf = create_xdg_popup(sc, shell, surface, &xdg_popup_client, |
Rafael Antognolli | e2a3455 | 2013-12-03 15:35:45 -0200 | [diff] [blame] | 4012 | parent, seat, serial, x, y); |
| 4013 | if (!shsurf) { |
| 4014 | wl_resource_post_error(surface_resource, |
| 4015 | WL_DISPLAY_ERROR_INVALID_OBJECT, |
| 4016 | "surface->configure already set"); |
| 4017 | return; |
| 4018 | } |
| 4019 | |
| 4020 | shsurf->resource = |
| 4021 | wl_resource_create(client, |
| 4022 | &xdg_popup_interface, 1, id); |
| 4023 | wl_resource_set_implementation(shsurf->resource, |
| 4024 | &xdg_popup_implementation, |
| 4025 | shsurf, shell_destroy_shell_surface); |
| 4026 | } |
| 4027 | |
Kristian Høgsberg | 2bff94e | 2014-02-11 12:22:51 -0800 | [diff] [blame] | 4028 | static void |
| 4029 | xdg_pong(struct wl_client *client, |
| 4030 | struct wl_resource *resource, uint32_t serial) |
| 4031 | { |
| 4032 | struct shell_client *sc = wl_resource_get_user_data(resource); |
Kristian Høgsberg | 2bff94e | 2014-02-11 12:22:51 -0800 | [diff] [blame] | 4033 | |
Kristian Høgsberg | dd62aba | 2014-02-12 09:56:19 -0800 | [diff] [blame] | 4034 | shell_client_pong(sc, serial); |
Kristian Høgsberg | 2bff94e | 2014-02-11 12:22:51 -0800 | [diff] [blame] | 4035 | } |
| 4036 | |
Rafael Antognolli | e2a3455 | 2013-12-03 15:35:45 -0200 | [diff] [blame] | 4037 | static bool |
| 4038 | shell_surface_is_xdg_popup(struct shell_surface *shsurf) |
| 4039 | { |
| 4040 | return wl_resource_instance_of(shsurf->resource, |
| 4041 | &xdg_popup_interface, |
| 4042 | &xdg_popup_implementation); |
| 4043 | } |
| 4044 | |
| 4045 | static const struct xdg_shell_interface xdg_implementation = { |
| 4046 | xdg_use_unstable_version, |
| 4047 | xdg_get_xdg_surface, |
Kristian Høgsberg | 2bff94e | 2014-02-11 12:22:51 -0800 | [diff] [blame] | 4048 | xdg_get_xdg_popup, |
| 4049 | xdg_pong |
Rafael Antognolli | e2a3455 | 2013-12-03 15:35:45 -0200 | [diff] [blame] | 4050 | }; |
| 4051 | |
| 4052 | static int |
| 4053 | xdg_shell_unversioned_dispatch(const void *implementation, |
| 4054 | void *_target, uint32_t opcode, |
| 4055 | const struct wl_message *message, |
| 4056 | union wl_argument *args) |
| 4057 | { |
| 4058 | struct wl_resource *resource = _target; |
Kristian Høgsberg | 2bff94e | 2014-02-11 12:22:51 -0800 | [diff] [blame] | 4059 | struct shell_client *sc = wl_resource_get_user_data(resource); |
Rafael Antognolli | e2a3455 | 2013-12-03 15:35:45 -0200 | [diff] [blame] | 4060 | |
| 4061 | if (opcode != 0) { |
| 4062 | wl_resource_post_error(resource, |
| 4063 | WL_DISPLAY_ERROR_INVALID_OBJECT, |
| 4064 | "must call use_unstable_version first"); |
| 4065 | return 0; |
| 4066 | } |
| 4067 | |
Pekka Paalanen | 71182ae | 2014-08-21 17:47:20 +0300 | [diff] [blame] | 4068 | #define XDG_SERVER_VERSION 4 |
Rafael Antognolli | e2a3455 | 2013-12-03 15:35:45 -0200 | [diff] [blame] | 4069 | |
Kristian Høgsberg | 8d344a0 | 2013-12-08 22:27:11 -0800 | [diff] [blame] | 4070 | static_assert(XDG_SERVER_VERSION == XDG_SHELL_VERSION_CURRENT, |
| 4071 | "shell implementation doesn't match protocol version"); |
| 4072 | |
Rafael Antognolli | e2a3455 | 2013-12-03 15:35:45 -0200 | [diff] [blame] | 4073 | if (args[0].i != XDG_SERVER_VERSION) { |
| 4074 | wl_resource_post_error(resource, |
| 4075 | WL_DISPLAY_ERROR_INVALID_OBJECT, |
| 4076 | "incompatible version, server is %d " |
| 4077 | "client wants %d", |
| 4078 | XDG_SERVER_VERSION, args[0].i); |
| 4079 | return 0; |
| 4080 | } |
| 4081 | |
| 4082 | wl_resource_set_implementation(resource, &xdg_implementation, |
Kristian Høgsberg | 2bff94e | 2014-02-11 12:22:51 -0800 | [diff] [blame] | 4083 | sc, NULL); |
Rafael Antognolli | e2a3455 | 2013-12-03 15:35:45 -0200 | [diff] [blame] | 4084 | |
| 4085 | return 1; |
| 4086 | } |
| 4087 | |
| 4088 | /* end of xdg-shell implementation */ |
| 4089 | /***********************************/ |
| 4090 | |
Kristian Høgsberg | 0793756 | 2011-04-12 17:25:42 -0400 | [diff] [blame] | 4091 | static void |
Ander Conselvan de Oliveira | 859e885 | 2013-02-21 18:35:21 +0200 | [diff] [blame] | 4092 | shell_fade(struct desktop_shell *shell, enum fade_type type); |
| 4093 | |
| 4094 | static int |
| 4095 | screensaver_timeout(void *data) |
| 4096 | { |
| 4097 | struct desktop_shell *shell = data; |
| 4098 | |
| 4099 | shell_fade(shell, FADE_OUT); |
| 4100 | |
| 4101 | return 1; |
| 4102 | } |
| 4103 | |
| 4104 | static void |
Kristian Høgsberg | 8334bc1 | 2012-01-03 10:29:47 -0500 | [diff] [blame] | 4105 | handle_screensaver_sigchld(struct weston_process *proc, int status) |
Pekka Paalanen | 18027e5 | 2011-12-02 16:31:49 +0200 | [diff] [blame] | 4106 | { |
Ander Conselvan de Oliveira | 18639f8 | 2013-02-15 18:44:19 +0200 | [diff] [blame] | 4107 | struct desktop_shell *shell = |
| 4108 | container_of(proc, struct desktop_shell, screensaver.process); |
Ander Conselvan de Oliveira | 18639f8 | 2013-02-15 18:44:19 +0200 | [diff] [blame] | 4109 | |
Pekka Paalanen | 18027e5 | 2011-12-02 16:31:49 +0200 | [diff] [blame] | 4110 | proc->pid = 0; |
Ander Conselvan de Oliveira | 18639f8 | 2013-02-15 18:44:19 +0200 | [diff] [blame] | 4111 | |
| 4112 | if (shell->locked) |
Ander Conselvan de Oliveira | b17537e | 2013-02-22 14:16:18 +0200 | [diff] [blame] | 4113 | weston_compositor_sleep(shell->compositor); |
Pekka Paalanen | 18027e5 | 2011-12-02 16:31:49 +0200 | [diff] [blame] | 4114 | } |
| 4115 | |
| 4116 | static void |
Tiago Vignatti | be14326 | 2012-04-16 17:31:41 +0300 | [diff] [blame] | 4117 | launch_screensaver(struct desktop_shell *shell) |
Pekka Paalanen | 77346a6 | 2011-11-30 16:26:35 +0200 | [diff] [blame] | 4118 | { |
| 4119 | if (shell->screensaver.binding) |
| 4120 | return; |
| 4121 | |
Ander Conselvan de Oliveira | dda9d78 | 2013-02-22 14:16:19 +0200 | [diff] [blame] | 4122 | if (!shell->screensaver.path) { |
| 4123 | weston_compositor_sleep(shell->compositor); |
Pekka Paalanen | e955f1e | 2011-12-07 11:49:52 +0200 | [diff] [blame] | 4124 | return; |
Ander Conselvan de Oliveira | dda9d78 | 2013-02-22 14:16:19 +0200 | [diff] [blame] | 4125 | } |
Pekka Paalanen | e955f1e | 2011-12-07 11:49:52 +0200 | [diff] [blame] | 4126 | |
Kristian Høgsberg | 32bed57 | 2012-03-01 17:11:36 -0500 | [diff] [blame] | 4127 | if (shell->screensaver.process.pid != 0) { |
Martin Minarik | 6d11836 | 2012-06-07 18:01:59 +0200 | [diff] [blame] | 4128 | weston_log("old screensaver still running\n"); |
Kristian Høgsberg | 32bed57 | 2012-03-01 17:11:36 -0500 | [diff] [blame] | 4129 | return; |
| 4130 | } |
| 4131 | |
Kristian Høgsberg | 8334bc1 | 2012-01-03 10:29:47 -0500 | [diff] [blame] | 4132 | weston_client_launch(shell->compositor, |
Pekka Paalanen | 18027e5 | 2011-12-02 16:31:49 +0200 | [diff] [blame] | 4133 | &shell->screensaver.process, |
Pekka Paalanen | e955f1e | 2011-12-07 11:49:52 +0200 | [diff] [blame] | 4134 | shell->screensaver.path, |
Pekka Paalanen | 18027e5 | 2011-12-02 16:31:49 +0200 | [diff] [blame] | 4135 | handle_screensaver_sigchld); |
Pekka Paalanen | 77346a6 | 2011-11-30 16:26:35 +0200 | [diff] [blame] | 4136 | } |
| 4137 | |
| 4138 | static void |
Tiago Vignatti | be14326 | 2012-04-16 17:31:41 +0300 | [diff] [blame] | 4139 | terminate_screensaver(struct desktop_shell *shell) |
Pekka Paalanen | 77346a6 | 2011-11-30 16:26:35 +0200 | [diff] [blame] | 4140 | { |
Pekka Paalanen | 18027e5 | 2011-12-02 16:31:49 +0200 | [diff] [blame] | 4141 | if (shell->screensaver.process.pid == 0) |
| 4142 | return; |
| 4143 | |
Ander Conselvan de Oliveira | 4e20e9b | 2014-04-10 14:49:35 +0300 | [diff] [blame] | 4144 | /* Disarm the screensaver timer, otherwise it may fire when the |
| 4145 | * compositor is not in the idle state. In that case, the screen will |
| 4146 | * be locked, but the wake_signal won't fire on user input, making the |
| 4147 | * system unresponsive. */ |
| 4148 | wl_event_source_timer_update(shell->screensaver.timer, 0); |
| 4149 | |
Pekka Paalanen | 18027e5 | 2011-12-02 16:31:49 +0200 | [diff] [blame] | 4150 | kill(shell->screensaver.process.pid, SIGTERM); |
Pekka Paalanen | 77346a6 | 2011-11-30 16:26:35 +0200 | [diff] [blame] | 4151 | } |
| 4152 | |
| 4153 | static void |
Jason Ekstrand | 918f2dd | 2013-12-02 21:01:53 -0600 | [diff] [blame] | 4154 | configure_static_view(struct weston_view *ev, struct weston_layer *layer) |
Kristian Høgsberg | 962342c | 2012-06-26 16:29:50 -0400 | [diff] [blame] | 4155 | { |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 4156 | struct weston_view *v, *next; |
Kristian Høgsberg | 962342c | 2012-06-26 16:29:50 -0400 | [diff] [blame] | 4157 | |
Giulio Camuffo | 412e6a5 | 2014-07-09 22:12:56 +0300 | [diff] [blame] | 4158 | 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] | 4159 | if (v->output == ev->output && v != ev) { |
| 4160 | weston_view_unmap(v); |
| 4161 | v->surface->configure = NULL; |
Kristian Høgsberg | 962342c | 2012-06-26 16:29:50 -0400 | [diff] [blame] | 4162 | } |
| 4163 | } |
| 4164 | |
Jason Ekstrand | 918f2dd | 2013-12-02 21:01:53 -0600 | [diff] [blame] | 4165 | weston_view_set_position(ev, ev->output->x, ev->output->y); |
Kristian Høgsberg | 962342c | 2012-06-26 16:29:50 -0400 | [diff] [blame] | 4166 | |
Giulio Camuffo | 412e6a5 | 2014-07-09 22:12:56 +0300 | [diff] [blame] | 4167 | if (wl_list_empty(&ev->layer_link.link)) { |
| 4168 | weston_layer_entry_insert(&layer->view_list, &ev->layer_link); |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 4169 | weston_compositor_schedule_repaint(ev->surface->compositor); |
Kristian Høgsberg | 962342c | 2012-06-26 16:29:50 -0400 | [diff] [blame] | 4170 | } |
| 4171 | } |
| 4172 | |
| 4173 | static void |
Jason Ekstrand | 918f2dd | 2013-12-02 21:01:53 -0600 | [diff] [blame] | 4174 | 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] | 4175 | { |
Giulio Camuffo | 7fe01b1 | 2013-03-28 18:02:42 +0100 | [diff] [blame] | 4176 | struct desktop_shell *shell = es->configure_private; |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 4177 | struct weston_view *view; |
Kristian Høgsberg | af7b1ff | 2012-06-26 21:19:23 -0400 | [diff] [blame] | 4178 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 4179 | view = container_of(es->views.next, struct weston_view, surface_link); |
| 4180 | |
Jason Ekstrand | 918f2dd | 2013-12-02 21:01:53 -0600 | [diff] [blame] | 4181 | configure_static_view(view, &shell->background_layer); |
Kristian Høgsberg | af7b1ff | 2012-06-26 21:19:23 -0400 | [diff] [blame] | 4182 | } |
| 4183 | |
| 4184 | static void |
Kristian Høgsberg | 7584062 | 2011-09-06 13:48:16 -0400 | [diff] [blame] | 4185 | desktop_shell_set_background(struct wl_client *client, |
| 4186 | struct wl_resource *resource, |
Benjamin Franzke | d0f79ab | 2011-11-22 12:43:52 +0100 | [diff] [blame] | 4187 | struct wl_resource *output_resource, |
Kristian Høgsberg | 7584062 | 2011-09-06 13:48:16 -0400 | [diff] [blame] | 4188 | struct wl_resource *surface_resource) |
| 4189 | { |
Jason Ekstrand | 651f00e | 2013-06-14 10:07:54 -0500 | [diff] [blame] | 4190 | struct desktop_shell *shell = wl_resource_get_user_data(resource); |
Jason Ekstrand | 0f2ef7e | 2013-06-14 10:07:53 -0500 | [diff] [blame] | 4191 | struct weston_surface *surface = |
| 4192 | wl_resource_get_user_data(surface_resource); |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 4193 | struct weston_view *view, *next; |
Kristian Høgsberg | 7584062 | 2011-09-06 13:48:16 -0400 | [diff] [blame] | 4194 | |
Kristian Høgsberg | 962342c | 2012-06-26 16:29:50 -0400 | [diff] [blame] | 4195 | if (surface->configure) { |
| 4196 | wl_resource_post_error(surface_resource, |
| 4197 | WL_DISPLAY_ERROR_INVALID_OBJECT, |
| 4198 | "surface role already assigned"); |
| 4199 | return; |
| 4200 | } |
Benjamin Franzke | d0f79ab | 2011-11-22 12:43:52 +0100 | [diff] [blame] | 4201 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 4202 | wl_list_for_each_safe(view, next, &surface->views, surface_link) |
| 4203 | weston_view_destroy(view); |
| 4204 | view = weston_view_create(surface); |
| 4205 | |
Kristian Høgsberg | 962342c | 2012-06-26 16:29:50 -0400 | [diff] [blame] | 4206 | surface->configure = background_configure; |
Giulio Camuffo | 7fe01b1 | 2013-03-28 18:02:42 +0100 | [diff] [blame] | 4207 | surface->configure_private = shell; |
Jason Ekstrand | a0d2dde | 2013-06-14 10:08:01 -0500 | [diff] [blame] | 4208 | surface->output = wl_resource_get_user_data(output_resource); |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 4209 | view->output = surface->output; |
Kristian Høgsberg | eae5de7 | 2012-04-11 22:42:15 -0400 | [diff] [blame] | 4210 | desktop_shell_send_configure(resource, 0, |
Kristian Høgsberg | 0b5cd0c | 2012-03-04 21:57:37 -0500 | [diff] [blame] | 4211 | surface_resource, |
Scott Moreau | 1bad5db | 2012-08-18 01:04:05 -0600 | [diff] [blame] | 4212 | surface->output->width, |
| 4213 | surface->output->height); |
Kristian Høgsberg | 7584062 | 2011-09-06 13:48:16 -0400 | [diff] [blame] | 4214 | } |
| 4215 | |
| 4216 | static void |
Jason Ekstrand | 918f2dd | 2013-12-02 21:01:53 -0600 | [diff] [blame] | 4217 | 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] | 4218 | { |
Giulio Camuffo | 7fe01b1 | 2013-03-28 18:02:42 +0100 | [diff] [blame] | 4219 | struct desktop_shell *shell = es->configure_private; |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 4220 | struct weston_view *view; |
Kristian Høgsberg | af7b1ff | 2012-06-26 21:19:23 -0400 | [diff] [blame] | 4221 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 4222 | view = container_of(es->views.next, struct weston_view, surface_link); |
| 4223 | |
Jason Ekstrand | 918f2dd | 2013-12-02 21:01:53 -0600 | [diff] [blame] | 4224 | configure_static_view(view, &shell->panel_layer); |
Kristian Høgsberg | af7b1ff | 2012-06-26 21:19:23 -0400 | [diff] [blame] | 4225 | } |
| 4226 | |
| 4227 | static void |
Kristian Høgsberg | 7584062 | 2011-09-06 13:48:16 -0400 | [diff] [blame] | 4228 | desktop_shell_set_panel(struct wl_client *client, |
| 4229 | struct wl_resource *resource, |
Benjamin Franzke | d0f79ab | 2011-11-22 12:43:52 +0100 | [diff] [blame] | 4230 | struct wl_resource *output_resource, |
Kristian Høgsberg | 7584062 | 2011-09-06 13:48:16 -0400 | [diff] [blame] | 4231 | struct wl_resource *surface_resource) |
| 4232 | { |
Jason Ekstrand | 651f00e | 2013-06-14 10:07:54 -0500 | [diff] [blame] | 4233 | struct desktop_shell *shell = wl_resource_get_user_data(resource); |
Jason Ekstrand | 0f2ef7e | 2013-06-14 10:07:53 -0500 | [diff] [blame] | 4234 | struct weston_surface *surface = |
| 4235 | wl_resource_get_user_data(surface_resource); |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 4236 | struct weston_view *view, *next; |
Kristian Høgsberg | 7584062 | 2011-09-06 13:48:16 -0400 | [diff] [blame] | 4237 | |
Kristian Høgsberg | af7b1ff | 2012-06-26 21:19:23 -0400 | [diff] [blame] | 4238 | if (surface->configure) { |
| 4239 | wl_resource_post_error(surface_resource, |
| 4240 | WL_DISPLAY_ERROR_INVALID_OBJECT, |
| 4241 | "surface role already assigned"); |
| 4242 | return; |
| 4243 | } |
Benjamin Franzke | d0f79ab | 2011-11-22 12:43:52 +0100 | [diff] [blame] | 4244 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 4245 | wl_list_for_each_safe(view, next, &surface->views, surface_link) |
| 4246 | weston_view_destroy(view); |
| 4247 | view = weston_view_create(surface); |
| 4248 | |
Kristian Høgsberg | af7b1ff | 2012-06-26 21:19:23 -0400 | [diff] [blame] | 4249 | surface->configure = panel_configure; |
Giulio Camuffo | 7fe01b1 | 2013-03-28 18:02:42 +0100 | [diff] [blame] | 4250 | surface->configure_private = shell; |
Jason Ekstrand | a0d2dde | 2013-06-14 10:08:01 -0500 | [diff] [blame] | 4251 | surface->output = wl_resource_get_user_data(output_resource); |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 4252 | view->output = surface->output; |
Kristian Høgsberg | eae5de7 | 2012-04-11 22:42:15 -0400 | [diff] [blame] | 4253 | desktop_shell_send_configure(resource, 0, |
Kristian Høgsberg | af7b1ff | 2012-06-26 21:19:23 -0400 | [diff] [blame] | 4254 | surface_resource, |
Scott Moreau | 1bad5db | 2012-08-18 01:04:05 -0600 | [diff] [blame] | 4255 | surface->output->width, |
| 4256 | surface->output->height); |
Kristian Høgsberg | 7584062 | 2011-09-06 13:48:16 -0400 | [diff] [blame] | 4257 | } |
| 4258 | |
Pekka Paalanen | 9ef3e01 | 2011-11-15 13:34:48 +0200 | [diff] [blame] | 4259 | static void |
Jason Ekstrand | 918f2dd | 2013-12-02 21:01:53 -0600 | [diff] [blame] | 4260 | 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] | 4261 | { |
Giulio Camuffo | 7fe01b1 | 2013-03-28 18:02:42 +0100 | [diff] [blame] | 4262 | struct desktop_shell *shell = surface->configure_private; |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 4263 | struct weston_view *view; |
| 4264 | |
| 4265 | view = container_of(surface->views.next, struct weston_view, surface_link); |
Kristian Høgsberg | 730c94d | 2012-06-26 21:44:35 -0400 | [diff] [blame] | 4266 | |
Jason Ekstrand | 918f2dd | 2013-12-02 21:01:53 -0600 | [diff] [blame] | 4267 | if (surface->width == 0) |
Giulio Camuffo | 184df50 | 2013-02-21 11:29:21 +0100 | [diff] [blame] | 4268 | return; |
| 4269 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 4270 | center_on_output(view, get_default_output(shell->compositor)); |
Kristian Høgsberg | 730c94d | 2012-06-26 21:44:35 -0400 | [diff] [blame] | 4271 | |
| 4272 | if (!weston_surface_is_mapped(surface)) { |
Giulio Camuffo | 412e6a5 | 2014-07-09 22:12:56 +0300 | [diff] [blame] | 4273 | weston_layer_entry_insert(&shell->lock_layer.view_list, |
| 4274 | &view->layer_link); |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 4275 | weston_view_update_transform(view); |
Ander Conselvan de Oliveira | 87524b6 | 2013-02-21 18:35:22 +0200 | [diff] [blame] | 4276 | shell_fade(shell, FADE_IN); |
Kristian Høgsberg | 730c94d | 2012-06-26 21:44:35 -0400 | [diff] [blame] | 4277 | } |
| 4278 | } |
| 4279 | |
| 4280 | static void |
Kristian Høgsberg | 27e3052 | 2012-04-11 23:18:23 -0400 | [diff] [blame] | 4281 | handle_lock_surface_destroy(struct wl_listener *listener, void *data) |
Kristian Høgsberg | 1ec0c31 | 2011-11-15 16:39:55 -0500 | [diff] [blame] | 4282 | { |
Tiago Vignatti | be14326 | 2012-04-16 17:31:41 +0300 | [diff] [blame] | 4283 | struct desktop_shell *shell = |
| 4284 | container_of(listener, struct desktop_shell, lock_surface_listener); |
Kristian Høgsberg | 1ec0c31 | 2011-11-15 16:39:55 -0500 | [diff] [blame] | 4285 | |
Martin Minarik | 6d11836 | 2012-06-07 18:01:59 +0200 | [diff] [blame] | 4286 | weston_log("lock surface gone\n"); |
Kristian Høgsberg | 1ec0c31 | 2011-11-15 16:39:55 -0500 | [diff] [blame] | 4287 | shell->lock_surface = NULL; |
| 4288 | } |
| 4289 | |
| 4290 | static void |
Pekka Paalanen | 9ef3e01 | 2011-11-15 13:34:48 +0200 | [diff] [blame] | 4291 | desktop_shell_set_lock_surface(struct wl_client *client, |
| 4292 | struct wl_resource *resource, |
| 4293 | struct wl_resource *surface_resource) |
| 4294 | { |
Jason Ekstrand | 651f00e | 2013-06-14 10:07:54 -0500 | [diff] [blame] | 4295 | struct desktop_shell *shell = wl_resource_get_user_data(resource); |
Jason Ekstrand | 0f2ef7e | 2013-06-14 10:07:53 -0500 | [diff] [blame] | 4296 | struct weston_surface *surface = |
| 4297 | wl_resource_get_user_data(surface_resource); |
Pekka Paalanen | 9826223 | 2011-12-01 10:42:22 +0200 | [diff] [blame] | 4298 | |
Pekka Paalanen | f0fc70d | 2011-11-15 13:34:54 +0200 | [diff] [blame] | 4299 | shell->prepare_event_sent = false; |
Kristian Høgsberg | af867cc | 2011-11-15 13:34:49 +0200 | [diff] [blame] | 4300 | |
Pekka Paalanen | f0fc70d | 2011-11-15 13:34:54 +0200 | [diff] [blame] | 4301 | if (!shell->locked) |
| 4302 | return; |
| 4303 | |
Pekka Paalanen | 9826223 | 2011-12-01 10:42:22 +0200 | [diff] [blame] | 4304 | shell->lock_surface = surface; |
Pekka Paalanen | f0fc70d | 2011-11-15 13:34:54 +0200 | [diff] [blame] | 4305 | |
Kristian Høgsberg | 27e3052 | 2012-04-11 23:18:23 -0400 | [diff] [blame] | 4306 | shell->lock_surface_listener.notify = handle_lock_surface_destroy; |
Jason Ekstrand | 651f00e | 2013-06-14 10:07:54 -0500 | [diff] [blame] | 4307 | wl_signal_add(&surface->destroy_signal, |
Kristian Høgsberg | 27e3052 | 2012-04-11 23:18:23 -0400 | [diff] [blame] | 4308 | &shell->lock_surface_listener); |
Pekka Paalanen | 57da4a8 | 2011-11-23 16:42:16 +0200 | [diff] [blame] | 4309 | |
Kristian Høgsberg | aa2ee8b | 2013-10-30 15:49:45 -0700 | [diff] [blame] | 4310 | weston_view_create(surface); |
Kristian Høgsberg | 730c94d | 2012-06-26 21:44:35 -0400 | [diff] [blame] | 4311 | surface->configure = lock_surface_configure; |
Giulio Camuffo | 7fe01b1 | 2013-03-28 18:02:42 +0100 | [diff] [blame] | 4312 | surface->configure_private = shell; |
Pekka Paalanen | f0fc70d | 2011-11-15 13:34:54 +0200 | [diff] [blame] | 4313 | } |
| 4314 | |
| 4315 | static void |
Tiago Vignatti | be14326 | 2012-04-16 17:31:41 +0300 | [diff] [blame] | 4316 | resume_desktop(struct desktop_shell *shell) |
Pekka Paalanen | f0fc70d | 2011-11-15 13:34:54 +0200 | [diff] [blame] | 4317 | { |
Kristian Høgsberg | 4476aaf | 2012-06-25 14:03:13 -0400 | [diff] [blame] | 4318 | struct workspace *ws = get_current_workspace(shell); |
Pekka Paalanen | 77346a6 | 2011-11-30 16:26:35 +0200 | [diff] [blame] | 4319 | |
Pekka Paalanen | 77346a6 | 2011-11-30 16:26:35 +0200 | [diff] [blame] | 4320 | terminate_screensaver(shell); |
Pekka Paalanen | f0fc70d | 2011-11-15 13:34:54 +0200 | [diff] [blame] | 4321 | |
Kristian Høgsberg | 3be2ce9 | 2012-02-29 12:42:35 -0500 | [diff] [blame] | 4322 | wl_list_remove(&shell->lock_layer.link); |
Philipp Brüschweiler | 711fda8 | 2012-08-09 18:50:43 +0200 | [diff] [blame] | 4323 | if (shell->showing_input_panels) { |
Manuel Bachmann | 805d2f5 | 2014-03-05 12:21:34 +0100 | [diff] [blame] | 4324 | wl_list_insert(&shell->compositor->cursor_layer.link, |
Philipp Brüschweiler | 711fda8 | 2012-08-09 18:50:43 +0200 | [diff] [blame] | 4325 | &shell->input_panel_layer.link); |
| 4326 | wl_list_insert(&shell->input_panel_layer.link, |
Manuel Bachmann | 805d2f5 | 2014-03-05 12:21:34 +0100 | [diff] [blame] | 4327 | &shell->fullscreen_layer.link); |
Philipp Brüschweiler | 711fda8 | 2012-08-09 18:50:43 +0200 | [diff] [blame] | 4328 | } else { |
Manuel Bachmann | 805d2f5 | 2014-03-05 12:21:34 +0100 | [diff] [blame] | 4329 | wl_list_insert(&shell->compositor->cursor_layer.link, |
| 4330 | &shell->fullscreen_layer.link); |
Philipp Brüschweiler | 711fda8 | 2012-08-09 18:50:43 +0200 | [diff] [blame] | 4331 | } |
Manuel Bachmann | 805d2f5 | 2014-03-05 12:21:34 +0100 | [diff] [blame] | 4332 | wl_list_insert(&shell->fullscreen_layer.link, |
| 4333 | &shell->panel_layer.link); |
| 4334 | wl_list_insert(&shell->panel_layer.link, |
| 4335 | &ws->layer.link), |
Pekka Paalanen | f0fc70d | 2011-11-15 13:34:54 +0200 | [diff] [blame] | 4336 | |
Kristian Høgsberg | 2f5faff | 2012-07-31 16:36:34 -0400 | [diff] [blame] | 4337 | restore_focus_state(shell, get_current_workspace(shell)); |
Jonas Ådahl | 0476974 | 2012-06-13 00:01:24 +0200 | [diff] [blame] | 4338 | |
Pekka Paalanen | f0fc70d | 2011-11-15 13:34:54 +0200 | [diff] [blame] | 4339 | shell->locked = false; |
Ander Conselvan de Oliveira | 87524b6 | 2013-02-21 18:35:22 +0200 | [diff] [blame] | 4340 | shell_fade(shell, FADE_IN); |
Pekka Paalanen | fc6d91a | 2012-02-10 15:33:10 +0200 | [diff] [blame] | 4341 | weston_compositor_damage_all(shell->compositor); |
Pekka Paalanen | 9ef3e01 | 2011-11-15 13:34:48 +0200 | [diff] [blame] | 4342 | } |
| 4343 | |
| 4344 | static void |
| 4345 | desktop_shell_unlock(struct wl_client *client, |
| 4346 | struct wl_resource *resource) |
| 4347 | { |
Jason Ekstrand | 651f00e | 2013-06-14 10:07:54 -0500 | [diff] [blame] | 4348 | struct desktop_shell *shell = wl_resource_get_user_data(resource); |
Pekka Paalanen | 9ef3e01 | 2011-11-15 13:34:48 +0200 | [diff] [blame] | 4349 | |
Pekka Paalanen | 9ef3e01 | 2011-11-15 13:34:48 +0200 | [diff] [blame] | 4350 | shell->prepare_event_sent = false; |
Pekka Paalanen | f0fc70d | 2011-11-15 13:34:54 +0200 | [diff] [blame] | 4351 | |
| 4352 | if (shell->locked) |
| 4353 | resume_desktop(shell); |
Pekka Paalanen | 9ef3e01 | 2011-11-15 13:34:48 +0200 | [diff] [blame] | 4354 | } |
| 4355 | |
Kristian Høgsberg | d56bd90 | 2012-06-05 09:58:51 -0400 | [diff] [blame] | 4356 | static void |
Ander Conselvan de Oliveira | b9d2a0f | 2012-06-28 18:08:05 +0300 | [diff] [blame] | 4357 | desktop_shell_set_grab_surface(struct wl_client *client, |
Kristian Høgsberg | d56bd90 | 2012-06-05 09:58:51 -0400 | [diff] [blame] | 4358 | struct wl_resource *resource, |
| 4359 | struct wl_resource *surface_resource) |
| 4360 | { |
Jason Ekstrand | 651f00e | 2013-06-14 10:07:54 -0500 | [diff] [blame] | 4361 | struct desktop_shell *shell = wl_resource_get_user_data(resource); |
Kristian Høgsberg | d56bd90 | 2012-06-05 09:58:51 -0400 | [diff] [blame] | 4362 | |
Jason Ekstrand | 0f2ef7e | 2013-06-14 10:07:53 -0500 | [diff] [blame] | 4363 | shell->grab_surface = wl_resource_get_user_data(surface_resource); |
Kristian Høgsberg | 48588f8 | 2013-10-24 15:51:35 -0700 | [diff] [blame] | 4364 | weston_view_create(shell->grab_surface); |
Kristian Høgsberg | d56bd90 | 2012-06-05 09:58:51 -0400 | [diff] [blame] | 4365 | } |
| 4366 | |
Pekka Paalanen | 79346ab | 2013-05-22 18:03:09 +0300 | [diff] [blame] | 4367 | static void |
| 4368 | desktop_shell_desktop_ready(struct wl_client *client, |
| 4369 | struct wl_resource *resource) |
| 4370 | { |
Jason Ekstrand | 651f00e | 2013-06-14 10:07:54 -0500 | [diff] [blame] | 4371 | struct desktop_shell *shell = wl_resource_get_user_data(resource); |
Pekka Paalanen | 79346ab | 2013-05-22 18:03:09 +0300 | [diff] [blame] | 4372 | |
| 4373 | shell_fade_startup(shell); |
| 4374 | } |
| 4375 | |
Jonny Lamb | 765760d | 2014-08-20 15:53:19 +0200 | [diff] [blame] | 4376 | static void |
| 4377 | desktop_shell_set_panel_position(struct wl_client *client, |
| 4378 | struct wl_resource *resource, |
| 4379 | uint32_t position) |
| 4380 | { |
| 4381 | struct desktop_shell *shell = wl_resource_get_user_data(resource); |
| 4382 | |
| 4383 | if (position != DESKTOP_SHELL_PANEL_POSITION_TOP && |
| 4384 | position != DESKTOP_SHELL_PANEL_POSITION_BOTTOM && |
| 4385 | position != DESKTOP_SHELL_PANEL_POSITION_LEFT && |
| 4386 | position != DESKTOP_SHELL_PANEL_POSITION_RIGHT) { |
| 4387 | wl_resource_post_error(resource, |
| 4388 | DESKTOP_SHELL_ERROR_INVALID_ARGUMENT, |
| 4389 | "bad position argument"); |
| 4390 | return; |
| 4391 | } |
| 4392 | |
| 4393 | shell->panel_position = position; |
| 4394 | } |
| 4395 | |
Kristian Høgsberg | 7584062 | 2011-09-06 13:48:16 -0400 | [diff] [blame] | 4396 | static const struct desktop_shell_interface desktop_shell_implementation = { |
| 4397 | desktop_shell_set_background, |
Pekka Paalanen | 9ef3e01 | 2011-11-15 13:34:48 +0200 | [diff] [blame] | 4398 | desktop_shell_set_panel, |
| 4399 | desktop_shell_set_lock_surface, |
Kristian Høgsberg | d56bd90 | 2012-06-05 09:58:51 -0400 | [diff] [blame] | 4400 | desktop_shell_unlock, |
Pekka Paalanen | 79346ab | 2013-05-22 18:03:09 +0300 | [diff] [blame] | 4401 | desktop_shell_set_grab_surface, |
Jonny Lamb | 765760d | 2014-08-20 15:53:19 +0200 | [diff] [blame] | 4402 | desktop_shell_desktop_ready, |
| 4403 | desktop_shell_set_panel_position |
Kristian Høgsberg | 7584062 | 2011-09-06 13:48:16 -0400 | [diff] [blame] | 4404 | }; |
| 4405 | |
Pekka Paalanen | 92a0dc4 | 2011-11-28 15:34:13 +0200 | [diff] [blame] | 4406 | static enum shell_surface_type |
Kristian Høgsberg | 8334bc1 | 2012-01-03 10:29:47 -0500 | [diff] [blame] | 4407 | get_shell_surface_type(struct weston_surface *surface) |
Pekka Paalanen | 92a0dc4 | 2011-11-28 15:34:13 +0200 | [diff] [blame] | 4408 | { |
| 4409 | struct shell_surface *shsurf; |
| 4410 | |
| 4411 | shsurf = get_shell_surface(surface); |
| 4412 | if (!shsurf) |
Pekka Paalanen | 9826223 | 2011-12-01 10:42:22 +0200 | [diff] [blame] | 4413 | return SHELL_SURFACE_NONE; |
Pekka Paalanen | 92a0dc4 | 2011-11-28 15:34:13 +0200 | [diff] [blame] | 4414 | return shsurf->type; |
| 4415 | } |
| 4416 | |
Kristian Høgsberg | 7584062 | 2011-09-06 13:48:16 -0400 | [diff] [blame] | 4417 | static void |
Kristian Høgsberg | e314875 | 2013-05-06 23:19:49 -0400 | [diff] [blame] | 4418 | move_binding(struct weston_seat *seat, uint32_t time, uint32_t button, void *data) |
Kristian Høgsberg | 0793756 | 2011-04-12 17:25:42 -0400 | [diff] [blame] | 4419 | { |
Rafal Mielniczuk | b2917a2 | 2014-01-05 20:04:59 +0100 | [diff] [blame] | 4420 | struct weston_surface *focus; |
Pekka Paalanen | 01388e2 | 2013-04-25 13:57:44 +0300 | [diff] [blame] | 4421 | struct weston_surface *surface; |
Kristian Høgsberg | 938b8fa | 2012-05-18 13:46:27 -0400 | [diff] [blame] | 4422 | struct shell_surface *shsurf; |
Kristian Høgsberg | d2abb83 | 2011-11-23 10:52:40 -0500 | [diff] [blame] | 4423 | |
Rafal Mielniczuk | b2917a2 | 2014-01-05 20:04:59 +0100 | [diff] [blame] | 4424 | if (seat->pointer->focus == NULL) |
| 4425 | return; |
| 4426 | |
| 4427 | focus = seat->pointer->focus->surface; |
| 4428 | |
Pekka Paalanen | 01388e2 | 2013-04-25 13:57:44 +0300 | [diff] [blame] | 4429 | surface = weston_surface_get_main_surface(focus); |
Benjamin Franzke | d0f79ab | 2011-11-22 12:43:52 +0100 | [diff] [blame] | 4430 | if (surface == NULL) |
| 4431 | return; |
Kristian Høgsberg | 0793756 | 2011-04-12 17:25:42 -0400 | [diff] [blame] | 4432 | |
Kristian Høgsberg | 938b8fa | 2012-05-18 13:46:27 -0400 | [diff] [blame] | 4433 | shsurf = get_shell_surface(surface); |
Rafael Antognolli | 03b1659 | 2013-12-03 15:35:42 -0200 | [diff] [blame] | 4434 | if (shsurf == NULL || shsurf->state.fullscreen || |
| 4435 | shsurf->state.maximized) |
Kristian Høgsberg | 938b8fa | 2012-05-18 13:46:27 -0400 | [diff] [blame] | 4436 | return; |
| 4437 | |
Kristian Høgsberg | ae356ae | 2014-04-29 16:03:54 -0700 | [diff] [blame] | 4438 | surface_move(shsurf, (struct weston_seat *) seat, 0); |
Kristian Høgsberg | 0793756 | 2011-04-12 17:25:42 -0400 | [diff] [blame] | 4439 | } |
| 4440 | |
| 4441 | static void |
Rafael Antognolli | ea997ac | 2013-12-03 15:35:48 -0200 | [diff] [blame] | 4442 | maximize_binding(struct weston_seat *seat, uint32_t time, uint32_t button, void *data) |
| 4443 | { |
Emilio Pozuelo Monfort | 38b58eb | 2014-01-29 11:11:12 +0100 | [diff] [blame] | 4444 | struct weston_surface *focus = seat->keyboard->focus; |
Rafael Antognolli | ea997ac | 2013-12-03 15:35:48 -0200 | [diff] [blame] | 4445 | struct weston_surface *surface; |
| 4446 | struct shell_surface *shsurf; |
| 4447 | |
| 4448 | surface = weston_surface_get_main_surface(focus); |
| 4449 | if (surface == NULL) |
| 4450 | return; |
| 4451 | |
| 4452 | shsurf = get_shell_surface(surface); |
| 4453 | if (shsurf == NULL) |
| 4454 | return; |
| 4455 | |
| 4456 | if (!shell_surface_is_xdg_surface(shsurf)) |
| 4457 | return; |
| 4458 | |
Jasper St. Pierre | ab2c108 | 2014-04-10 10:41:46 -0700 | [diff] [blame] | 4459 | shsurf->state_requested = true; |
| 4460 | shsurf->requested_state.maximized = !shsurf->state.maximized; |
Jasper St. Pierre | 9aa8ce6 | 2014-04-11 16:18:54 -0700 | [diff] [blame] | 4461 | send_configure_for_surface(shsurf); |
Rafael Antognolli | ea997ac | 2013-12-03 15:35:48 -0200 | [diff] [blame] | 4462 | } |
| 4463 | |
| 4464 | static void |
| 4465 | fullscreen_binding(struct weston_seat *seat, uint32_t time, uint32_t button, void *data) |
| 4466 | { |
Emilio Pozuelo Monfort | 38b58eb | 2014-01-29 11:11:12 +0100 | [diff] [blame] | 4467 | struct weston_surface *focus = seat->keyboard->focus; |
Rafael Antognolli | ea997ac | 2013-12-03 15:35:48 -0200 | [diff] [blame] | 4468 | struct weston_surface *surface; |
| 4469 | struct shell_surface *shsurf; |
| 4470 | |
| 4471 | surface = weston_surface_get_main_surface(focus); |
| 4472 | if (surface == NULL) |
| 4473 | return; |
| 4474 | |
| 4475 | shsurf = get_shell_surface(surface); |
| 4476 | if (shsurf == NULL) |
| 4477 | return; |
| 4478 | |
| 4479 | if (!shell_surface_is_xdg_surface(shsurf)) |
| 4480 | return; |
| 4481 | |
Jasper St. Pierre | ab2c108 | 2014-04-10 10:41:46 -0700 | [diff] [blame] | 4482 | shsurf->state_requested = true; |
| 4483 | shsurf->requested_state.fullscreen = !shsurf->state.fullscreen; |
Boyan Ding | 32abdbb | 2014-06-26 10:19:32 +0800 | [diff] [blame] | 4484 | shsurf->fullscreen_output = shsurf->output; |
Jasper St. Pierre | 9aa8ce6 | 2014-04-11 16:18:54 -0700 | [diff] [blame] | 4485 | send_configure_for_surface(shsurf); |
Rafael Antognolli | ea997ac | 2013-12-03 15:35:48 -0200 | [diff] [blame] | 4486 | } |
| 4487 | |
| 4488 | static void |
Neil Roberts | aba0f25 | 2013-10-03 16:43:05 +0100 | [diff] [blame] | 4489 | touch_move_binding(struct weston_seat *seat, uint32_t time, void *data) |
| 4490 | { |
Derek Foreman | 362656b | 2014-09-04 10:23:05 -0500 | [diff] [blame] | 4491 | struct weston_surface *focus; |
Neil Roberts | aba0f25 | 2013-10-03 16:43:05 +0100 | [diff] [blame] | 4492 | struct weston_surface *surface; |
| 4493 | struct shell_surface *shsurf; |
| 4494 | |
Derek Foreman | 362656b | 2014-09-04 10:23:05 -0500 | [diff] [blame] | 4495 | if (seat->touch->focus == NULL) |
| 4496 | return; |
| 4497 | |
| 4498 | focus = seat->touch->focus->surface; |
Neil Roberts | aba0f25 | 2013-10-03 16:43:05 +0100 | [diff] [blame] | 4499 | surface = weston_surface_get_main_surface(focus); |
| 4500 | if (surface == NULL) |
| 4501 | return; |
| 4502 | |
| 4503 | shsurf = get_shell_surface(surface); |
Rafael Antognolli | 03b1659 | 2013-12-03 15:35:42 -0200 | [diff] [blame] | 4504 | if (shsurf == NULL || shsurf->state.fullscreen || |
| 4505 | shsurf->state.maximized) |
Neil Roberts | aba0f25 | 2013-10-03 16:43:05 +0100 | [diff] [blame] | 4506 | return; |
| 4507 | |
| 4508 | surface_touch_move(shsurf, (struct weston_seat *) seat); |
| 4509 | } |
| 4510 | |
| 4511 | static void |
Kristian Høgsberg | e314875 | 2013-05-06 23:19:49 -0400 | [diff] [blame] | 4512 | resize_binding(struct weston_seat *seat, uint32_t time, uint32_t button, void *data) |
Kristian Høgsberg | 0793756 | 2011-04-12 17:25:42 -0400 | [diff] [blame] | 4513 | { |
Rafal Mielniczuk | b2917a2 | 2014-01-05 20:04:59 +0100 | [diff] [blame] | 4514 | struct weston_surface *focus; |
Pekka Paalanen | 01388e2 | 2013-04-25 13:57:44 +0300 | [diff] [blame] | 4515 | struct weston_surface *surface; |
Kristian Høgsberg | 0793756 | 2011-04-12 17:25:42 -0400 | [diff] [blame] | 4516 | uint32_t edges = 0; |
| 4517 | int32_t x, y; |
Pekka Paalanen | 9d1613e | 2011-11-25 12:09:16 +0200 | [diff] [blame] | 4518 | struct shell_surface *shsurf; |
Kristian Høgsberg | d2abb83 | 2011-11-23 10:52:40 -0500 | [diff] [blame] | 4519 | |
Rafal Mielniczuk | b2917a2 | 2014-01-05 20:04:59 +0100 | [diff] [blame] | 4520 | if (seat->pointer->focus == NULL) |
| 4521 | return; |
| 4522 | |
| 4523 | focus = seat->pointer->focus->surface; |
| 4524 | |
Pekka Paalanen | 01388e2 | 2013-04-25 13:57:44 +0300 | [diff] [blame] | 4525 | surface = weston_surface_get_main_surface(focus); |
Benjamin Franzke | d0f79ab | 2011-11-22 12:43:52 +0100 | [diff] [blame] | 4526 | if (surface == NULL) |
| 4527 | return; |
Pekka Paalanen | 92a0dc4 | 2011-11-28 15:34:13 +0200 | [diff] [blame] | 4528 | |
Pekka Paalanen | 9d1613e | 2011-11-25 12:09:16 +0200 | [diff] [blame] | 4529 | shsurf = get_shell_surface(surface); |
Rafael Antognolli | 03b1659 | 2013-12-03 15:35:42 -0200 | [diff] [blame] | 4530 | if (shsurf == NULL || shsurf->state.fullscreen || |
| 4531 | shsurf->state.maximized) |
Pekka Paalanen | 92a0dc4 | 2011-11-28 15:34:13 +0200 | [diff] [blame] | 4532 | return; |
| 4533 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 4534 | weston_view_from_global(shsurf->view, |
| 4535 | wl_fixed_to_int(seat->pointer->grab_x), |
| 4536 | wl_fixed_to_int(seat->pointer->grab_y), |
| 4537 | &x, &y); |
Kristian Høgsberg | 0793756 | 2011-04-12 17:25:42 -0400 | [diff] [blame] | 4538 | |
Jason Ekstrand | 918f2dd | 2013-12-02 21:01:53 -0600 | [diff] [blame] | 4539 | if (x < shsurf->surface->width / 3) |
Pekka Paalanen | 9d1613e | 2011-11-25 12:09:16 +0200 | [diff] [blame] | 4540 | edges |= WL_SHELL_SURFACE_RESIZE_LEFT; |
Jason Ekstrand | 918f2dd | 2013-12-02 21:01:53 -0600 | [diff] [blame] | 4541 | else if (x < 2 * shsurf->surface->width / 3) |
Kristian Høgsberg | 0793756 | 2011-04-12 17:25:42 -0400 | [diff] [blame] | 4542 | edges |= 0; |
| 4543 | else |
Pekka Paalanen | 9d1613e | 2011-11-25 12:09:16 +0200 | [diff] [blame] | 4544 | edges |= WL_SHELL_SURFACE_RESIZE_RIGHT; |
Kristian Høgsberg | 0793756 | 2011-04-12 17:25:42 -0400 | [diff] [blame] | 4545 | |
Jason Ekstrand | 918f2dd | 2013-12-02 21:01:53 -0600 | [diff] [blame] | 4546 | if (y < shsurf->surface->height / 3) |
Pekka Paalanen | 9d1613e | 2011-11-25 12:09:16 +0200 | [diff] [blame] | 4547 | edges |= WL_SHELL_SURFACE_RESIZE_TOP; |
Jason Ekstrand | 918f2dd | 2013-12-02 21:01:53 -0600 | [diff] [blame] | 4548 | else if (y < 2 * shsurf->surface->height / 3) |
Kristian Høgsberg | 0793756 | 2011-04-12 17:25:42 -0400 | [diff] [blame] | 4549 | edges |= 0; |
| 4550 | else |
Pekka Paalanen | 9d1613e | 2011-11-25 12:09:16 +0200 | [diff] [blame] | 4551 | edges |= WL_SHELL_SURFACE_RESIZE_BOTTOM; |
Kristian Høgsberg | 0793756 | 2011-04-12 17:25:42 -0400 | [diff] [blame] | 4552 | |
Kristian Høgsberg | c1693f2 | 2012-05-22 16:56:23 -0400 | [diff] [blame] | 4553 | surface_resize(shsurf, (struct weston_seat *) seat, edges); |
Kristian Høgsberg | 02ec0a5 | 2011-04-23 13:04:11 -0400 | [diff] [blame] | 4554 | } |
| 4555 | |
| 4556 | static void |
Kristian Høgsberg | e314875 | 2013-05-06 23:19:49 -0400 | [diff] [blame] | 4557 | surface_opacity_binding(struct weston_seat *seat, uint32_t time, uint32_t axis, |
Daniel Stone | 0c1e46e | 2012-05-30 16:31:59 +0100 | [diff] [blame] | 4558 | wl_fixed_t value, void *data) |
Scott Moreau | a3aa9c9 | 2012-03-22 11:01:03 -0600 | [diff] [blame] | 4559 | { |
Jonas Ådahl | b0b87ba | 2012-09-27 18:40:42 +0200 | [diff] [blame] | 4560 | float step = 0.005; |
Scott Moreau | a3aa9c9 | 2012-03-22 11:01:03 -0600 | [diff] [blame] | 4561 | struct shell_surface *shsurf; |
Kristian Høgsberg | 7ab139c | 2013-10-24 16:21:39 -0700 | [diff] [blame] | 4562 | struct weston_surface *focus = seat->pointer->focus->surface; |
Pekka Paalanen | 01388e2 | 2013-04-25 13:57:44 +0300 | [diff] [blame] | 4563 | struct weston_surface *surface; |
Scott Moreau | a3aa9c9 | 2012-03-22 11:01:03 -0600 | [diff] [blame] | 4564 | |
Pekka Paalanen | 01388e2 | 2013-04-25 13:57:44 +0300 | [diff] [blame] | 4565 | /* XXX: broken for windows containing sub-surfaces */ |
| 4566 | surface = weston_surface_get_main_surface(focus); |
Scott Moreau | a3aa9c9 | 2012-03-22 11:01:03 -0600 | [diff] [blame] | 4567 | if (surface == NULL) |
| 4568 | return; |
| 4569 | |
| 4570 | shsurf = get_shell_surface(surface); |
| 4571 | if (!shsurf) |
| 4572 | return; |
| 4573 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 4574 | shsurf->view->alpha -= wl_fixed_to_double(value) * step; |
Scott Moreau | a3aa9c9 | 2012-03-22 11:01:03 -0600 | [diff] [blame] | 4575 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 4576 | if (shsurf->view->alpha > 1.0) |
| 4577 | shsurf->view->alpha = 1.0; |
| 4578 | if (shsurf->view->alpha < step) |
| 4579 | shsurf->view->alpha = step; |
Scott Moreau | a3aa9c9 | 2012-03-22 11:01:03 -0600 | [diff] [blame] | 4580 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 4581 | weston_view_geometry_dirty(shsurf->view); |
Scott Moreau | a3aa9c9 | 2012-03-22 11:01:03 -0600 | [diff] [blame] | 4582 | weston_surface_damage(surface); |
| 4583 | } |
| 4584 | |
| 4585 | static void |
Kristian Høgsberg | e314875 | 2013-05-06 23:19:49 -0400 | [diff] [blame] | 4586 | 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] | 4587 | wl_fixed_t value) |
Scott Moreau | ccbf29d | 2012-02-22 14:21:41 -0700 | [diff] [blame] | 4588 | { |
Daniel Stone | 37816df | 2012-05-16 18:45:18 +0100 | [diff] [blame] | 4589 | struct weston_seat *ws = (struct weston_seat *) seat; |
| 4590 | struct weston_compositor *compositor = ws->compositor; |
Scott Moreau | ccbf29d | 2012-02-22 14:21:41 -0700 | [diff] [blame] | 4591 | struct weston_output *output; |
Scott Moreau | e660398 | 2012-06-11 13:07:51 -0600 | [diff] [blame] | 4592 | float increment; |
Scott Moreau | ccbf29d | 2012-02-22 14:21:41 -0700 | [diff] [blame] | 4593 | |
| 4594 | wl_list_for_each(output, &compositor->output_list, link) { |
| 4595 | if (pixman_region32_contains_point(&output->region, |
Daniel Stone | 37816df | 2012-05-16 18:45:18 +0100 | [diff] [blame] | 4596 | wl_fixed_to_double(seat->pointer->x), |
| 4597 | wl_fixed_to_double(seat->pointer->y), |
Daniel Stone | 103db7f | 2012-05-08 17:17:55 +0100 | [diff] [blame] | 4598 | NULL)) { |
Daniel Stone | 325fc2d | 2012-05-30 16:31:58 +0100 | [diff] [blame] | 4599 | if (key == KEY_PAGEUP) |
Kristian Høgsberg | 9b68af0 | 2012-05-22 12:55:18 -0400 | [diff] [blame] | 4600 | increment = output->zoom.increment; |
Daniel Stone | 325fc2d | 2012-05-30 16:31:58 +0100 | [diff] [blame] | 4601 | else if (key == KEY_PAGEDOWN) |
Kristian Høgsberg | 9b68af0 | 2012-05-22 12:55:18 -0400 | [diff] [blame] | 4602 | increment = -output->zoom.increment; |
| 4603 | else if (axis == WL_POINTER_AXIS_VERTICAL_SCROLL) |
Jonas Ådahl | b0b87ba | 2012-09-27 18:40:42 +0200 | [diff] [blame] | 4604 | /* For every pixel zoom 20th of a step */ |
Daniel Stone | 0c1e46e | 2012-05-30 16:31:59 +0100 | [diff] [blame] | 4605 | increment = output->zoom.increment * |
Jonas Ådahl | b0b87ba | 2012-09-27 18:40:42 +0200 | [diff] [blame] | 4606 | -wl_fixed_to_double(value) / 20.0; |
Kristian Høgsberg | 9b68af0 | 2012-05-22 12:55:18 -0400 | [diff] [blame] | 4607 | else |
| 4608 | increment = 0; |
| 4609 | |
Kristian Høgsberg | 9b68af0 | 2012-05-22 12:55:18 -0400 | [diff] [blame] | 4610 | output->zoom.level += increment; |
Scott Moreau | c6d7f60 | 2012-02-23 22:28:37 -0700 | [diff] [blame] | 4611 | |
Scott Moreau | e660398 | 2012-06-11 13:07:51 -0600 | [diff] [blame] | 4612 | if (output->zoom.level < 0.0) |
Scott Moreau | 850ca42 | 2012-05-21 15:21:25 -0600 | [diff] [blame] | 4613 | output->zoom.level = 0.0; |
Scott Moreau | e660398 | 2012-06-11 13:07:51 -0600 | [diff] [blame] | 4614 | else if (output->zoom.level > output->zoom.max_level) |
| 4615 | output->zoom.level = output->zoom.max_level; |
Ville Syrjälä | aa628d0 | 2012-11-16 11:48:47 +0200 | [diff] [blame] | 4616 | else if (!output->zoom.active) { |
Giulio Camuffo | 412b024 | 2013-11-14 23:42:51 +0100 | [diff] [blame] | 4617 | weston_output_activate_zoom(output); |
Kristian Høgsberg | 79af73e | 2012-08-03 15:45:23 -0400 | [diff] [blame] | 4618 | } |
Scott Moreau | ccbf29d | 2012-02-22 14:21:41 -0700 | [diff] [blame] | 4619 | |
Scott Moreau | e660398 | 2012-06-11 13:07:51 -0600 | [diff] [blame] | 4620 | output->zoom.spring_z.target = output->zoom.level; |
Scott Moreau | ccbf29d | 2012-02-22 14:21:41 -0700 | [diff] [blame] | 4621 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 4622 | weston_output_update_zoom(output); |
Scott Moreau | ccbf29d | 2012-02-22 14:21:41 -0700 | [diff] [blame] | 4623 | } |
| 4624 | } |
| 4625 | } |
| 4626 | |
Scott Moreau | ccbf29d | 2012-02-22 14:21:41 -0700 | [diff] [blame] | 4627 | static void |
Kristian Høgsberg | e314875 | 2013-05-06 23:19:49 -0400 | [diff] [blame] | 4628 | zoom_axis_binding(struct weston_seat *seat, uint32_t time, uint32_t axis, |
Daniel Stone | 0c1e46e | 2012-05-30 16:31:59 +0100 | [diff] [blame] | 4629 | wl_fixed_t value, void *data) |
Daniel Stone | 325fc2d | 2012-05-30 16:31:58 +0100 | [diff] [blame] | 4630 | { |
| 4631 | do_zoom(seat, time, 0, axis, value); |
| 4632 | } |
| 4633 | |
| 4634 | static void |
Kristian Høgsberg | e314875 | 2013-05-06 23:19:49 -0400 | [diff] [blame] | 4635 | zoom_key_binding(struct weston_seat *seat, uint32_t time, uint32_t key, |
Daniel Stone | 325fc2d | 2012-05-30 16:31:58 +0100 | [diff] [blame] | 4636 | void *data) |
| 4637 | { |
| 4638 | do_zoom(seat, time, key, 0, 0); |
| 4639 | } |
| 4640 | |
| 4641 | static void |
Kristian Høgsberg | e314875 | 2013-05-06 23:19:49 -0400 | [diff] [blame] | 4642 | terminate_binding(struct weston_seat *seat, uint32_t time, uint32_t key, |
Daniel Stone | 325fc2d | 2012-05-30 16:31:58 +0100 | [diff] [blame] | 4643 | void *data) |
Kristian Høgsberg | e1a850e | 2011-12-19 15:18:05 -0500 | [diff] [blame] | 4644 | { |
Kristian Høgsberg | 8334bc1 | 2012-01-03 10:29:47 -0500 | [diff] [blame] | 4645 | struct weston_compositor *compositor = data; |
Kristian Høgsberg | e1a850e | 2011-12-19 15:18:05 -0500 | [diff] [blame] | 4646 | |
Daniel Stone | 325fc2d | 2012-05-30 16:31:58 +0100 | [diff] [blame] | 4647 | wl_display_terminate(compositor->wl_display); |
Kristian Høgsberg | e1a850e | 2011-12-19 15:18:05 -0500 | [diff] [blame] | 4648 | } |
| 4649 | |
Emilio Pozuelo Monfort | 03251b6 | 2013-11-19 11:37:16 +0100 | [diff] [blame] | 4650 | static void |
Giulio Camuffo | 1959ab8 | 2013-11-14 23:42:52 +0100 | [diff] [blame] | 4651 | rotate_grab_motion(struct weston_pointer_grab *grab, uint32_t time, |
| 4652 | wl_fixed_t x, wl_fixed_t y) |
Pekka Paalanen | 460099f | 2012-01-20 16:48:25 +0200 | [diff] [blame] | 4653 | { |
| 4654 | struct rotate_grab *rotate = |
Ander Conselvan de Oliveira | fe0444a | 2012-04-04 17:48:05 +0300 | [diff] [blame] | 4655 | container_of(grab, struct rotate_grab, base.grab); |
Kristian Høgsberg | 02bbabb | 2013-05-06 22:15:05 -0400 | [diff] [blame] | 4656 | struct weston_pointer *pointer = grab->pointer; |
Ander Conselvan de Oliveira | fe0444a | 2012-04-04 17:48:05 +0300 | [diff] [blame] | 4657 | struct shell_surface *shsurf = rotate->base.shsurf; |
John Kåre Alsaker | 490d02a | 2012-09-30 02:57:21 +0200 | [diff] [blame] | 4658 | float cx, cy, dx, dy, cposx, cposy, dposx, dposy, r; |
Ander Conselvan de Oliveira | fe0444a | 2012-04-04 17:48:05 +0300 | [diff] [blame] | 4659 | |
Giulio Camuffo | 1959ab8 | 2013-11-14 23:42:52 +0100 | [diff] [blame] | 4660 | weston_pointer_move(pointer, x, y); |
| 4661 | |
Ander Conselvan de Oliveira | fe0444a | 2012-04-04 17:48:05 +0300 | [diff] [blame] | 4662 | if (!shsurf) |
| 4663 | return; |
| 4664 | |
Jason Ekstrand | 918f2dd | 2013-12-02 21:01:53 -0600 | [diff] [blame] | 4665 | cx = 0.5f * shsurf->surface->width; |
| 4666 | cy = 0.5f * shsurf->surface->height; |
Pekka Paalanen | 460099f | 2012-01-20 16:48:25 +0200 | [diff] [blame] | 4667 | |
Daniel Stone | 37816df | 2012-05-16 18:45:18 +0100 | [diff] [blame] | 4668 | dx = wl_fixed_to_double(pointer->x) - rotate->center.x; |
| 4669 | dy = wl_fixed_to_double(pointer->y) - rotate->center.y; |
Pekka Paalanen | 460099f | 2012-01-20 16:48:25 +0200 | [diff] [blame] | 4670 | r = sqrtf(dx * dx + dy * dy); |
| 4671 | |
Ander Conselvan de Oliveira | fe0444a | 2012-04-04 17:48:05 +0300 | [diff] [blame] | 4672 | wl_list_remove(&shsurf->rotation.transform.link); |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 4673 | weston_view_geometry_dirty(shsurf->view); |
Pekka Paalanen | 460099f | 2012-01-20 16:48:25 +0200 | [diff] [blame] | 4674 | |
| 4675 | if (r > 20.0f) { |
Pekka Paalanen | 460099f | 2012-01-20 16:48:25 +0200 | [diff] [blame] | 4676 | struct weston_matrix *matrix = |
Ander Conselvan de Oliveira | fe0444a | 2012-04-04 17:48:05 +0300 | [diff] [blame] | 4677 | &shsurf->rotation.transform.matrix; |
Pekka Paalanen | 460099f | 2012-01-20 16:48:25 +0200 | [diff] [blame] | 4678 | |
Kristian Høgsberg | 765e27b | 2012-01-27 13:36:13 -0500 | [diff] [blame] | 4679 | weston_matrix_init(&rotate->rotation); |
Vasily Khoruzhick | 1bbf372 | 2013-01-28 22:40:28 +0300 | [diff] [blame] | 4680 | weston_matrix_rotate_xy(&rotate->rotation, dx / r, dy / r); |
Pekka Paalanen | 460099f | 2012-01-20 16:48:25 +0200 | [diff] [blame] | 4681 | |
| 4682 | weston_matrix_init(matrix); |
Pekka Paalanen | 7b3bd3d | 2012-01-30 14:16:34 +0200 | [diff] [blame] | 4683 | weston_matrix_translate(matrix, -cx, -cy, 0.0f); |
Ander Conselvan de Oliveira | fe0444a | 2012-04-04 17:48:05 +0300 | [diff] [blame] | 4684 | weston_matrix_multiply(matrix, &shsurf->rotation.rotation); |
Kristian Høgsberg | 765e27b | 2012-01-27 13:36:13 -0500 | [diff] [blame] | 4685 | weston_matrix_multiply(matrix, &rotate->rotation); |
Pekka Paalanen | 7b3bd3d | 2012-01-30 14:16:34 +0200 | [diff] [blame] | 4686 | weston_matrix_translate(matrix, cx, cy, 0.0f); |
Pekka Paalanen | 460099f | 2012-01-20 16:48:25 +0200 | [diff] [blame] | 4687 | |
Pekka Paalanen | bc0b7e7 | 2012-01-24 09:53:37 +0200 | [diff] [blame] | 4688 | wl_list_insert( |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 4689 | &shsurf->view->geometry.transformation_list, |
Ander Conselvan de Oliveira | fe0444a | 2012-04-04 17:48:05 +0300 | [diff] [blame] | 4690 | &shsurf->rotation.transform.link); |
Pekka Paalanen | 460099f | 2012-01-20 16:48:25 +0200 | [diff] [blame] | 4691 | } else { |
Ander Conselvan de Oliveira | fe0444a | 2012-04-04 17:48:05 +0300 | [diff] [blame] | 4692 | wl_list_init(&shsurf->rotation.transform.link); |
| 4693 | weston_matrix_init(&shsurf->rotation.rotation); |
Kristian Høgsberg | 765e27b | 2012-01-27 13:36:13 -0500 | [diff] [blame] | 4694 | weston_matrix_init(&rotate->rotation); |
Pekka Paalanen | 460099f | 2012-01-20 16:48:25 +0200 | [diff] [blame] | 4695 | } |
Pekka Paalanen | b45ac5e | 2012-02-09 15:58:44 +0200 | [diff] [blame] | 4696 | |
Rafal Mielniczuk | 2d7ab82 | 2012-03-22 22:22:04 +0100 | [diff] [blame] | 4697 | /* We need to adjust the position of the surface |
| 4698 | * in case it was resized in a rotated state before */ |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 4699 | cposx = shsurf->view->geometry.x + cx; |
| 4700 | cposy = shsurf->view->geometry.y + cy; |
Rafal Mielniczuk | 2d7ab82 | 2012-03-22 22:22:04 +0100 | [diff] [blame] | 4701 | dposx = rotate->center.x - cposx; |
| 4702 | dposy = rotate->center.y - cposy; |
| 4703 | if (dposx != 0.0f || dposy != 0.0f) { |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 4704 | weston_view_set_position(shsurf->view, |
| 4705 | shsurf->view->geometry.x + dposx, |
| 4706 | shsurf->view->geometry.y + dposy); |
Rafal Mielniczuk | 2d7ab82 | 2012-03-22 22:22:04 +0100 | [diff] [blame] | 4707 | } |
| 4708 | |
Derek Foreman | 4b1a0a1 | 2014-09-10 15:37:33 -0500 | [diff] [blame^] | 4709 | /* Repaint implies weston_view_update_transform(), which |
Pekka Paalanen | b45ac5e | 2012-02-09 15:58:44 +0200 | [diff] [blame] | 4710 | * lazily applies the damage due to rotation update. |
| 4711 | */ |
Ander Conselvan de Oliveira | fe0444a | 2012-04-04 17:48:05 +0300 | [diff] [blame] | 4712 | weston_compositor_schedule_repaint(shsurf->surface->compositor); |
Pekka Paalanen | 460099f | 2012-01-20 16:48:25 +0200 | [diff] [blame] | 4713 | } |
| 4714 | |
| 4715 | static void |
Kristian Høgsberg | 02bbabb | 2013-05-06 22:15:05 -0400 | [diff] [blame] | 4716 | rotate_grab_button(struct weston_pointer_grab *grab, |
| 4717 | uint32_t time, uint32_t button, uint32_t state_w) |
Pekka Paalanen | 460099f | 2012-01-20 16:48:25 +0200 | [diff] [blame] | 4718 | { |
| 4719 | struct rotate_grab *rotate = |
Ander Conselvan de Oliveira | fe0444a | 2012-04-04 17:48:05 +0300 | [diff] [blame] | 4720 | container_of(grab, struct rotate_grab, base.grab); |
Kristian Høgsberg | 02bbabb | 2013-05-06 22:15:05 -0400 | [diff] [blame] | 4721 | struct weston_pointer *pointer = grab->pointer; |
Ander Conselvan de Oliveira | fe0444a | 2012-04-04 17:48:05 +0300 | [diff] [blame] | 4722 | struct shell_surface *shsurf = rotate->base.shsurf; |
Daniel Stone | 4dbadb1 | 2012-05-30 16:31:51 +0100 | [diff] [blame] | 4723 | enum wl_pointer_button_state state = state_w; |
Pekka Paalanen | 460099f | 2012-01-20 16:48:25 +0200 | [diff] [blame] | 4724 | |
Daniel Stone | 4dbadb1 | 2012-05-30 16:31:51 +0100 | [diff] [blame] | 4725 | if (pointer->button_count == 0 && |
| 4726 | state == WL_POINTER_BUTTON_STATE_RELEASED) { |
Ander Conselvan de Oliveira | fe0444a | 2012-04-04 17:48:05 +0300 | [diff] [blame] | 4727 | if (shsurf) |
| 4728 | weston_matrix_multiply(&shsurf->rotation.rotation, |
| 4729 | &rotate->rotation); |
Ander Conselvan de Oliveira | b9d2a0f | 2012-06-28 18:08:05 +0300 | [diff] [blame] | 4730 | shell_grab_end(&rotate->base); |
Pekka Paalanen | 460099f | 2012-01-20 16:48:25 +0200 | [diff] [blame] | 4731 | free(rotate); |
| 4732 | } |
| 4733 | } |
| 4734 | |
Jonas Ådahl | 1ea343e | 2013-10-25 23:18:05 +0200 | [diff] [blame] | 4735 | static void |
| 4736 | rotate_grab_cancel(struct weston_pointer_grab *grab) |
| 4737 | { |
| 4738 | struct rotate_grab *rotate = |
| 4739 | container_of(grab, struct rotate_grab, base.grab); |
| 4740 | |
| 4741 | shell_grab_end(&rotate->base); |
| 4742 | free(rotate); |
| 4743 | } |
| 4744 | |
Kristian Høgsberg | 02bbabb | 2013-05-06 22:15:05 -0400 | [diff] [blame] | 4745 | static const struct weston_pointer_grab_interface rotate_grab_interface = { |
Pekka Paalanen | 460099f | 2012-01-20 16:48:25 +0200 | [diff] [blame] | 4746 | noop_grab_focus, |
| 4747 | rotate_grab_motion, |
| 4748 | rotate_grab_button, |
Jonas Ådahl | 1ea343e | 2013-10-25 23:18:05 +0200 | [diff] [blame] | 4749 | rotate_grab_cancel, |
Pekka Paalanen | 460099f | 2012-01-20 16:48:25 +0200 | [diff] [blame] | 4750 | }; |
| 4751 | |
| 4752 | static void |
Kristian Høgsberg | e314875 | 2013-05-06 23:19:49 -0400 | [diff] [blame] | 4753 | surface_rotate(struct shell_surface *surface, struct weston_seat *seat) |
Pekka Paalanen | 460099f | 2012-01-20 16:48:25 +0200 | [diff] [blame] | 4754 | { |
Pekka Paalanen | 460099f | 2012-01-20 16:48:25 +0200 | [diff] [blame] | 4755 | struct rotate_grab *rotate; |
John Kåre Alsaker | 490d02a | 2012-09-30 02:57:21 +0200 | [diff] [blame] | 4756 | float dx, dy; |
| 4757 | float r; |
Pekka Paalanen | 460099f | 2012-01-20 16:48:25 +0200 | [diff] [blame] | 4758 | |
Pekka Paalanen | 460099f | 2012-01-20 16:48:25 +0200 | [diff] [blame] | 4759 | rotate = malloc(sizeof *rotate); |
| 4760 | if (!rotate) |
| 4761 | return; |
| 4762 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 4763 | weston_view_to_global_float(surface->view, |
Jason Ekstrand | 918f2dd | 2013-12-02 21:01:53 -0600 | [diff] [blame] | 4764 | surface->surface->width * 0.5f, |
| 4765 | surface->surface->height * 0.5f, |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 4766 | &rotate->center.x, &rotate->center.y); |
Pekka Paalanen | 460099f | 2012-01-20 16:48:25 +0200 | [diff] [blame] | 4767 | |
Daniel Stone | 37816df | 2012-05-16 18:45:18 +0100 | [diff] [blame] | 4768 | dx = wl_fixed_to_double(seat->pointer->x) - rotate->center.x; |
| 4769 | dy = wl_fixed_to_double(seat->pointer->y) - rotate->center.y; |
Kristian Høgsberg | 765e27b | 2012-01-27 13:36:13 -0500 | [diff] [blame] | 4770 | r = sqrtf(dx * dx + dy * dy); |
| 4771 | if (r > 20.0f) { |
| 4772 | struct weston_matrix inverse; |
| 4773 | |
| 4774 | weston_matrix_init(&inverse); |
Vasily Khoruzhick | 1bbf372 | 2013-01-28 22:40:28 +0300 | [diff] [blame] | 4775 | weston_matrix_rotate_xy(&inverse, dx / r, -dy / r); |
Kristian Høgsberg | 765e27b | 2012-01-27 13:36:13 -0500 | [diff] [blame] | 4776 | weston_matrix_multiply(&surface->rotation.rotation, &inverse); |
Rafal Mielniczuk | 2d7ab82 | 2012-03-22 22:22:04 +0100 | [diff] [blame] | 4777 | |
| 4778 | weston_matrix_init(&rotate->rotation); |
Vasily Khoruzhick | 1bbf372 | 2013-01-28 22:40:28 +0300 | [diff] [blame] | 4779 | weston_matrix_rotate_xy(&rotate->rotation, dx / r, dy / r); |
Kristian Høgsberg | 765e27b | 2012-01-27 13:36:13 -0500 | [diff] [blame] | 4780 | } else { |
| 4781 | weston_matrix_init(&surface->rotation.rotation); |
| 4782 | weston_matrix_init(&rotate->rotation); |
| 4783 | } |
| 4784 | |
Ander Conselvan de Oliveira | b9d2a0f | 2012-06-28 18:08:05 +0300 | [diff] [blame] | 4785 | shell_grab_start(&rotate->base, &rotate_grab_interface, surface, |
| 4786 | seat->pointer, DESKTOP_SHELL_CURSOR_ARROW); |
Pekka Paalanen | 460099f | 2012-01-20 16:48:25 +0200 | [diff] [blame] | 4787 | } |
| 4788 | |
| 4789 | static void |
Kristian Høgsberg | e314875 | 2013-05-06 23:19:49 -0400 | [diff] [blame] | 4790 | rotate_binding(struct weston_seat *seat, uint32_t time, uint32_t button, |
Kristian Høgsberg | 0c36903 | 2013-02-14 21:31:44 -0500 | [diff] [blame] | 4791 | void *data) |
| 4792 | { |
Rafal Mielniczuk | b2917a2 | 2014-01-05 20:04:59 +0100 | [diff] [blame] | 4793 | struct weston_surface *focus; |
Pekka Paalanen | 01388e2 | 2013-04-25 13:57:44 +0300 | [diff] [blame] | 4794 | struct weston_surface *base_surface; |
Kristian Høgsberg | 0c36903 | 2013-02-14 21:31:44 -0500 | [diff] [blame] | 4795 | struct shell_surface *surface; |
| 4796 | |
Rafal Mielniczuk | b2917a2 | 2014-01-05 20:04:59 +0100 | [diff] [blame] | 4797 | if (seat->pointer->focus == NULL) |
| 4798 | return; |
| 4799 | |
| 4800 | focus = seat->pointer->focus->surface; |
| 4801 | |
Pekka Paalanen | 01388e2 | 2013-04-25 13:57:44 +0300 | [diff] [blame] | 4802 | base_surface = weston_surface_get_main_surface(focus); |
Kristian Høgsberg | 0c36903 | 2013-02-14 21:31:44 -0500 | [diff] [blame] | 4803 | if (base_surface == NULL) |
| 4804 | return; |
| 4805 | |
| 4806 | surface = get_shell_surface(base_surface); |
Rafael Antognolli | 03b1659 | 2013-12-03 15:35:42 -0200 | [diff] [blame] | 4807 | if (surface == NULL || surface->state.fullscreen || |
| 4808 | surface->state.maximized) |
Kristian Høgsberg | 0c36903 | 2013-02-14 21:31:44 -0500 | [diff] [blame] | 4809 | return; |
| 4810 | |
| 4811 | surface_rotate(surface, seat); |
| 4812 | } |
| 4813 | |
Emilio Pozuelo Monfort | 9e7c759 | 2014-01-30 14:01:10 +0100 | [diff] [blame] | 4814 | /* Move all fullscreen layers down to the current workspace and hide their |
| 4815 | * black views. The surfaces' state is set to both fullscreen and lowered, |
| 4816 | * and this is reversed when such a surface is re-configured, see |
| 4817 | * shell_configure_fullscreen() and shell_ensure_fullscreen_black_view(). |
| 4818 | * |
| 4819 | * This should be used when implementing shell-wide overlays, such as |
Philip Withnall | 83ffd9d | 2013-11-25 18:01:42 +0000 | [diff] [blame] | 4820 | * the alt-tab switcher, which need to de-promote fullscreen layers. */ |
Kristian Høgsberg | 1ef2313 | 2013-12-04 00:20:01 -0800 | [diff] [blame] | 4821 | void |
Kristian Høgsberg | b0d8e77 | 2012-06-18 16:34:58 -0400 | [diff] [blame] | 4822 | lower_fullscreen_layer(struct desktop_shell *shell) |
| 4823 | { |
| 4824 | struct workspace *ws; |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 4825 | struct weston_view *view, *prev; |
Kristian Høgsberg | b0d8e77 | 2012-06-18 16:34:58 -0400 | [diff] [blame] | 4826 | |
| 4827 | ws = get_current_workspace(shell); |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 4828 | wl_list_for_each_reverse_safe(view, prev, |
Giulio Camuffo | 412e6a5 | 2014-07-09 22:12:56 +0300 | [diff] [blame] | 4829 | &shell->fullscreen_layer.view_list.link, |
| 4830 | layer_link.link) { |
Emilio Pozuelo Monfort | 9e7c759 | 2014-01-30 14:01:10 +0100 | [diff] [blame] | 4831 | struct shell_surface *shsurf = get_shell_surface(view->surface); |
| 4832 | |
| 4833 | if (!shsurf) |
| 4834 | continue; |
| 4835 | |
| 4836 | /* We can have a non-fullscreen popup for a fullscreen surface |
| 4837 | * in the fullscreen layer. */ |
| 4838 | if (shsurf->state.fullscreen) { |
| 4839 | /* Hide the black view */ |
Giulio Camuffo | 412e6a5 | 2014-07-09 22:12:56 +0300 | [diff] [blame] | 4840 | weston_layer_entry_remove(&shsurf->fullscreen.black_view->layer_link); |
| 4841 | wl_list_init(&shsurf->fullscreen.black_view->layer_link.link); |
Kristian Høgsberg | c991513 | 2014-05-09 16:24:07 -0700 | [diff] [blame] | 4842 | weston_view_damage_below(shsurf->fullscreen.black_view); |
| 4843 | |
Emilio Pozuelo Monfort | 9e7c759 | 2014-01-30 14:01:10 +0100 | [diff] [blame] | 4844 | } |
| 4845 | |
| 4846 | /* Lower the view to the workspace layer */ |
Giulio Camuffo | 412e6a5 | 2014-07-09 22:12:56 +0300 | [diff] [blame] | 4847 | weston_layer_entry_remove(&view->layer_link); |
| 4848 | weston_layer_entry_insert(&ws->layer.view_list, &view->layer_link); |
Philip Withnall | 83ffd9d | 2013-11-25 18:01:42 +0000 | [diff] [blame] | 4849 | weston_view_damage_below(view); |
| 4850 | weston_surface_damage(view->surface); |
Emilio Pozuelo Monfort | 9e7c759 | 2014-01-30 14:01:10 +0100 | [diff] [blame] | 4851 | |
| 4852 | shsurf->state.lowered = true; |
Philip Withnall | 83ffd9d | 2013-11-25 18:01:42 +0000 | [diff] [blame] | 4853 | } |
Kristian Høgsberg | b0d8e77 | 2012-06-18 16:34:58 -0400 | [diff] [blame] | 4854 | } |
| 4855 | |
Kristian Høgsberg | 1ef2313 | 2013-12-04 00:20:01 -0800 | [diff] [blame] | 4856 | void |
Tiago Vignatti | be14326 | 2012-04-16 17:31:41 +0300 | [diff] [blame] | 4857 | activate(struct desktop_shell *shell, struct weston_surface *es, |
Emilio Pozuelo Monfort | 9e7c759 | 2014-01-30 14:01:10 +0100 | [diff] [blame] | 4858 | struct weston_seat *seat, bool configure) |
Kristian Høgsberg | 7584062 | 2011-09-06 13:48:16 -0400 | [diff] [blame] | 4859 | { |
Pekka Paalanen | 01388e2 | 2013-04-25 13:57:44 +0300 | [diff] [blame] | 4860 | struct weston_surface *main_surface; |
Kristian Høgsberg | 2f5faff | 2012-07-31 16:36:34 -0400 | [diff] [blame] | 4861 | struct focus_state *state; |
Jonas Ådahl | 8538b22 | 2012-08-29 22:13:03 +0200 | [diff] [blame] | 4862 | struct workspace *ws; |
Louis-Francis Ratté-Boulianne | b482dbd | 2013-11-19 11:37:11 +0100 | [diff] [blame] | 4863 | struct weston_surface *old_es; |
Rafael Antognolli | 03b1659 | 2013-12-03 15:35:42 -0200 | [diff] [blame] | 4864 | struct shell_surface *shsurf; |
Kristian Høgsberg | 7584062 | 2011-09-06 13:48:16 -0400 | [diff] [blame] | 4865 | |
Kristian Høgsberg | 6110d07 | 2014-04-29 15:15:45 -0700 | [diff] [blame] | 4866 | lower_fullscreen_layer(shell); |
| 4867 | |
Pekka Paalanen | 01388e2 | 2013-04-25 13:57:44 +0300 | [diff] [blame] | 4868 | main_surface = weston_surface_get_main_surface(es); |
| 4869 | |
Daniel Stone | 37816df | 2012-05-16 18:45:18 +0100 | [diff] [blame] | 4870 | weston_surface_activate(es, seat); |
Kristian Høgsberg | 7584062 | 2011-09-06 13:48:16 -0400 | [diff] [blame] | 4871 | |
Jonas Ådahl | 8538b22 | 2012-08-29 22:13:03 +0200 | [diff] [blame] | 4872 | state = ensure_focus_state(shell, seat); |
| 4873 | if (state == NULL) |
| 4874 | return; |
Kristian Høgsberg | 2f5faff | 2012-07-31 16:36:34 -0400 | [diff] [blame] | 4875 | |
Louis-Francis Ratté-Boulianne | b482dbd | 2013-11-19 11:37:11 +0100 | [diff] [blame] | 4876 | old_es = state->keyboard_focus; |
Kristian Høgsberg | d500bf1 | 2014-01-22 12:25:20 -0800 | [diff] [blame] | 4877 | focus_state_set_focus(state, es); |
Kristian Høgsberg | 2f5faff | 2012-07-31 16:36:34 -0400 | [diff] [blame] | 4878 | |
Rafael Antognolli | 03b1659 | 2013-12-03 15:35:42 -0200 | [diff] [blame] | 4879 | shsurf = get_shell_surface(main_surface); |
U. Artie Eoff | cf5737a | 2014-01-17 10:08:25 -0800 | [diff] [blame] | 4880 | assert(shsurf); |
| 4881 | |
Emilio Pozuelo Monfort | 9e7c759 | 2014-01-30 14:01:10 +0100 | [diff] [blame] | 4882 | if (shsurf->state.fullscreen && configure) |
Rafael Antognolli | 03b1659 | 2013-12-03 15:35:42 -0200 | [diff] [blame] | 4883 | shell_configure_fullscreen(shsurf); |
| 4884 | else |
Alexander Larsson | f82b6ca | 2013-05-28 16:23:39 +0200 | [diff] [blame] | 4885 | restore_all_output_modes(shell->compositor); |
Louis-Francis Ratté-Boulianne | b482dbd | 2013-11-19 11:37:11 +0100 | [diff] [blame] | 4886 | |
Emilio Pozuelo Monfort | 7908bff | 2014-01-30 13:49:39 +0100 | [diff] [blame] | 4887 | /* Update the surface’s layer. This brings it to the top of the stacking |
| 4888 | * order as appropriate. */ |
| 4889 | shell_surface_update_layer(shsurf); |
| 4890 | |
Philip Withnall | 83ffd9d | 2013-11-25 18:01:42 +0000 | [diff] [blame] | 4891 | if (shell->focus_animation_type != ANIMATION_NONE) { |
| 4892 | ws = get_current_workspace(shell); |
Louis-Francis Ratté-Boulianne | b482dbd | 2013-11-19 11:37:11 +0100 | [diff] [blame] | 4893 | 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] | 4894 | } |
Kristian Høgsberg | 7584062 | 2011-09-06 13:48:16 -0400 | [diff] [blame] | 4895 | } |
| 4896 | |
Alex Wu | 2185843 | 2012-04-01 20:13:08 +0800 | [diff] [blame] | 4897 | /* no-op func for checking black surface */ |
| 4898 | static void |
Jason Ekstrand | 918f2dd | 2013-12-02 21:01:53 -0600 | [diff] [blame] | 4899 | 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] | 4900 | { |
| 4901 | } |
| 4902 | |
Quentin Glidic | c0d79ce | 2013-01-29 14:16:13 +0100 | [diff] [blame] | 4903 | static bool |
Alex Wu | 2185843 | 2012-04-01 20:13:08 +0800 | [diff] [blame] | 4904 | is_black_surface (struct weston_surface *es, struct weston_surface **fs_surface) |
| 4905 | { |
| 4906 | if (es->configure == black_surface_configure) { |
| 4907 | if (fs_surface) |
Giulio Camuffo | 7fe01b1 | 2013-03-28 18:02:42 +0100 | [diff] [blame] | 4908 | *fs_surface = (struct weston_surface *)es->configure_private; |
Alex Wu | 2185843 | 2012-04-01 20:13:08 +0800 | [diff] [blame] | 4909 | return true; |
| 4910 | } |
| 4911 | return false; |
| 4912 | } |
| 4913 | |
Kristian Høgsberg | 7584062 | 2011-09-06 13:48:16 -0400 | [diff] [blame] | 4914 | static void |
Neil Roberts | a28c693 | 2013-10-03 16:43:04 +0100 | [diff] [blame] | 4915 | activate_binding(struct weston_seat *seat, |
| 4916 | struct desktop_shell *shell, |
| 4917 | struct weston_surface *focus) |
Kristian Høgsberg | e1a850e | 2011-12-19 15:18:05 -0500 | [diff] [blame] | 4918 | { |
Pekka Paalanen | 01388e2 | 2013-04-25 13:57:44 +0300 | [diff] [blame] | 4919 | struct weston_surface *main_surface; |
Kristian Høgsberg | e1a850e | 2011-12-19 15:18:05 -0500 | [diff] [blame] | 4920 | |
Alex Wu | 9c35e6b | 2012-03-05 14:13:13 +0800 | [diff] [blame] | 4921 | if (!focus) |
| 4922 | return; |
| 4923 | |
Pekka Paalanen | 01388e2 | 2013-04-25 13:57:44 +0300 | [diff] [blame] | 4924 | if (is_black_surface(focus, &main_surface)) |
| 4925 | focus = main_surface; |
Alex Wu | 4539b08 | 2012-03-01 12:57:46 +0800 | [diff] [blame] | 4926 | |
Pekka Paalanen | 01388e2 | 2013-04-25 13:57:44 +0300 | [diff] [blame] | 4927 | main_surface = weston_surface_get_main_surface(focus); |
| 4928 | if (get_shell_surface_type(main_surface) == SHELL_SURFACE_NONE) |
Kristian Høgsberg | 0636ac3 | 2012-06-27 10:22:15 -0400 | [diff] [blame] | 4929 | return; |
Kristian Høgsberg | 85b2e4b | 2012-06-21 16:49:42 -0400 | [diff] [blame] | 4930 | |
Emilio Pozuelo Monfort | 9e7c759 | 2014-01-30 14:01:10 +0100 | [diff] [blame] | 4931 | activate(shell, focus, seat, true); |
Neil Roberts | a28c693 | 2013-10-03 16:43:04 +0100 | [diff] [blame] | 4932 | } |
| 4933 | |
| 4934 | static void |
| 4935 | click_to_activate_binding(struct weston_seat *seat, uint32_t time, uint32_t button, |
| 4936 | void *data) |
| 4937 | { |
| 4938 | if (seat->pointer->grab != &seat->pointer->default_grab) |
| 4939 | return; |
Kristian Høgsberg | 7c4f6cc | 2014-01-01 16:28:32 -0800 | [diff] [blame] | 4940 | if (seat->pointer->focus == NULL) |
| 4941 | return; |
Neil Roberts | a28c693 | 2013-10-03 16:43:04 +0100 | [diff] [blame] | 4942 | |
Kristian Høgsberg | 7ab139c | 2013-10-24 16:21:39 -0700 | [diff] [blame] | 4943 | activate_binding(seat, data, seat->pointer->focus->surface); |
Neil Roberts | a28c693 | 2013-10-03 16:43:04 +0100 | [diff] [blame] | 4944 | } |
| 4945 | |
| 4946 | static void |
| 4947 | touch_to_activate_binding(struct weston_seat *seat, uint32_t time, void *data) |
| 4948 | { |
| 4949 | if (seat->touch->grab != &seat->touch->default_grab) |
| 4950 | return; |
Kristian Høgsberg | 0ed6750 | 2014-01-02 23:00:11 -0800 | [diff] [blame] | 4951 | if (seat->touch->focus == NULL) |
| 4952 | return; |
Neil Roberts | a28c693 | 2013-10-03 16:43:04 +0100 | [diff] [blame] | 4953 | |
Kristian Høgsberg | 7ab139c | 2013-10-24 16:21:39 -0700 | [diff] [blame] | 4954 | activate_binding(seat, data, seat->touch->focus->surface); |
Kristian Høgsberg | e1a850e | 2011-12-19 15:18:05 -0500 | [diff] [blame] | 4955 | } |
| 4956 | |
| 4957 | static void |
Neil Roberts | b4a9170 | 2014-04-09 16:33:32 +0100 | [diff] [blame] | 4958 | unfocus_all_seats(struct desktop_shell *shell) |
| 4959 | { |
| 4960 | struct weston_seat *seat, *next; |
| 4961 | |
| 4962 | wl_list_for_each_safe(seat, next, &shell->compositor->seat_list, link) { |
| 4963 | if (seat->keyboard == NULL) |
| 4964 | continue; |
| 4965 | |
| 4966 | weston_keyboard_set_focus(seat->keyboard, NULL); |
| 4967 | } |
| 4968 | } |
| 4969 | |
| 4970 | static void |
Ander Conselvan de Oliveira | 19d10ef | 2013-02-21 18:35:20 +0200 | [diff] [blame] | 4971 | lock(struct desktop_shell *shell) |
Kristian Høgsberg | 02ec0a5 | 2011-04-23 13:04:11 -0400 | [diff] [blame] | 4972 | { |
Kristian Høgsberg | 4476aaf | 2012-06-25 14:03:13 -0400 | [diff] [blame] | 4973 | struct workspace *ws = get_current_workspace(shell); |
Pekka Paalanen | f0fc70d | 2011-11-15 13:34:54 +0200 | [diff] [blame] | 4974 | |
Tiago Vignatti | 8e53c7f | 2012-02-29 19:53:50 +0200 | [diff] [blame] | 4975 | if (shell->locked) { |
Ander Conselvan de Oliveira | 87524b6 | 2013-02-21 18:35:22 +0200 | [diff] [blame] | 4976 | weston_compositor_sleep(shell->compositor); |
Pekka Paalanen | f0fc70d | 2011-11-15 13:34:54 +0200 | [diff] [blame] | 4977 | return; |
Tiago Vignatti | 8e53c7f | 2012-02-29 19:53:50 +0200 | [diff] [blame] | 4978 | } |
Pekka Paalanen | 9ef3e01 | 2011-11-15 13:34:48 +0200 | [diff] [blame] | 4979 | |
| 4980 | shell->locked = true; |
Pekka Paalanen | f0fc70d | 2011-11-15 13:34:54 +0200 | [diff] [blame] | 4981 | |
Kristian Høgsberg | 3be2ce9 | 2012-02-29 12:42:35 -0500 | [diff] [blame] | 4982 | /* Hide all surfaces by removing the fullscreen, panel and |
| 4983 | * toplevel layers. This way nothing else can show or receive |
| 4984 | * input events while we are locked. */ |
Pekka Paalanen | f0fc70d | 2011-11-15 13:34:54 +0200 | [diff] [blame] | 4985 | |
Kristian Høgsberg | 3be2ce9 | 2012-02-29 12:42:35 -0500 | [diff] [blame] | 4986 | wl_list_remove(&shell->panel_layer.link); |
Kristian Høgsberg | 3be2ce9 | 2012-02-29 12:42:35 -0500 | [diff] [blame] | 4987 | wl_list_remove(&shell->fullscreen_layer.link); |
Philipp Brüschweiler | 711fda8 | 2012-08-09 18:50:43 +0200 | [diff] [blame] | 4988 | if (shell->showing_input_panels) |
| 4989 | wl_list_remove(&shell->input_panel_layer.link); |
Kristian Høgsberg | 4476aaf | 2012-06-25 14:03:13 -0400 | [diff] [blame] | 4990 | wl_list_remove(&ws->layer.link); |
Kristian Høgsberg | 3be2ce9 | 2012-02-29 12:42:35 -0500 | [diff] [blame] | 4991 | wl_list_insert(&shell->compositor->cursor_layer.link, |
| 4992 | &shell->lock_layer.link); |
Pekka Paalanen | f0fc70d | 2011-11-15 13:34:54 +0200 | [diff] [blame] | 4993 | |
Pekka Paalanen | 77346a6 | 2011-11-30 16:26:35 +0200 | [diff] [blame] | 4994 | launch_screensaver(shell); |
| 4995 | |
Neil Roberts | b4a9170 | 2014-04-09 16:33:32 +0100 | [diff] [blame] | 4996 | /* Remove the keyboard focus on all seats. This will be |
| 4997 | * restored to the workspace's saved state via |
| 4998 | * restore_focus_state when the compositor is unlocked */ |
| 4999 | unfocus_all_seats(shell); |
| 5000 | |
Pekka Paalanen | f0fc70d | 2011-11-15 13:34:54 +0200 | [diff] [blame] | 5001 | /* TODO: disable bindings that should not work while locked. */ |
| 5002 | |
| 5003 | /* All this must be undone in resume_desktop(). */ |
Pekka Paalanen | 9ef3e01 | 2011-11-15 13:34:48 +0200 | [diff] [blame] | 5004 | } |
| 5005 | |
| 5006 | static void |
Ander Conselvan de Oliveira | 19d10ef | 2013-02-21 18:35:20 +0200 | [diff] [blame] | 5007 | unlock(struct desktop_shell *shell) |
Pekka Paalanen | 9ef3e01 | 2011-11-15 13:34:48 +0200 | [diff] [blame] | 5008 | { |
Pekka Paalanen | d81c216 | 2011-11-16 13:47:34 +0200 | [diff] [blame] | 5009 | if (!shell->locked || shell->lock_surface) { |
Ander Conselvan de Oliveira | 87524b6 | 2013-02-21 18:35:22 +0200 | [diff] [blame] | 5010 | shell_fade(shell, FADE_IN); |
Pekka Paalanen | 9ef3e01 | 2011-11-15 13:34:48 +0200 | [diff] [blame] | 5011 | return; |
| 5012 | } |
| 5013 | |
| 5014 | /* If desktop-shell client has gone away, unlock immediately. */ |
| 5015 | if (!shell->child.desktop_shell) { |
Pekka Paalanen | f0fc70d | 2011-11-15 13:34:54 +0200 | [diff] [blame] | 5016 | resume_desktop(shell); |
Pekka Paalanen | 9ef3e01 | 2011-11-15 13:34:48 +0200 | [diff] [blame] | 5017 | return; |
| 5018 | } |
| 5019 | |
| 5020 | if (shell->prepare_event_sent) |
| 5021 | return; |
| 5022 | |
Kristian Høgsberg | 0b5cd0c | 2012-03-04 21:57:37 -0500 | [diff] [blame] | 5023 | desktop_shell_send_prepare_lock_surface(shell->child.desktop_shell); |
Pekka Paalanen | 9ef3e01 | 2011-11-15 13:34:48 +0200 | [diff] [blame] | 5024 | shell->prepare_event_sent = true; |
Kristian Høgsberg | 02ec0a5 | 2011-04-23 13:04:11 -0400 | [diff] [blame] | 5025 | } |
| 5026 | |
| 5027 | static void |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 5028 | shell_fade_done(struct weston_view_animation *animation, void *data) |
Ander Conselvan de Oliveira | 19d10ef | 2013-02-21 18:35:20 +0200 | [diff] [blame] | 5029 | { |
| 5030 | struct desktop_shell *shell = data; |
| 5031 | |
| 5032 | shell->fade.animation = NULL; |
| 5033 | |
| 5034 | switch (shell->fade.type) { |
| 5035 | case FADE_IN: |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 5036 | weston_surface_destroy(shell->fade.view->surface); |
| 5037 | shell->fade.view = NULL; |
Ander Conselvan de Oliveira | 19d10ef | 2013-02-21 18:35:20 +0200 | [diff] [blame] | 5038 | break; |
| 5039 | case FADE_OUT: |
Ander Conselvan de Oliveira | 19d10ef | 2013-02-21 18:35:20 +0200 | [diff] [blame] | 5040 | lock(shell); |
| 5041 | break; |
Philip Withnall | 4a86a0a | 2013-11-25 18:01:32 +0000 | [diff] [blame] | 5042 | default: |
| 5043 | break; |
Ander Conselvan de Oliveira | 19d10ef | 2013-02-21 18:35:20 +0200 | [diff] [blame] | 5044 | } |
| 5045 | } |
| 5046 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 5047 | static struct weston_view * |
Pekka Paalanen | 79346ab | 2013-05-22 18:03:09 +0300 | [diff] [blame] | 5048 | shell_fade_create_surface(struct desktop_shell *shell) |
Ander Conselvan de Oliveira | 19d10ef | 2013-02-21 18:35:20 +0200 | [diff] [blame] | 5049 | { |
| 5050 | struct weston_compositor *compositor = shell->compositor; |
| 5051 | struct weston_surface *surface; |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 5052 | struct weston_view *view; |
Pekka Paalanen | 79346ab | 2013-05-22 18:03:09 +0300 | [diff] [blame] | 5053 | |
| 5054 | surface = weston_surface_create(compositor); |
| 5055 | if (!surface) |
| 5056 | return NULL; |
| 5057 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 5058 | view = weston_view_create(surface); |
| 5059 | if (!view) { |
| 5060 | weston_surface_destroy(surface); |
| 5061 | return NULL; |
| 5062 | } |
| 5063 | |
Jason Ekstrand | 5c11a33 | 2013-12-04 20:32:03 -0600 | [diff] [blame] | 5064 | weston_surface_set_size(surface, 8192, 8192); |
Jason Ekstrand | 918f2dd | 2013-12-02 21:01:53 -0600 | [diff] [blame] | 5065 | weston_view_set_position(view, 0, 0); |
Pekka Paalanen | 79346ab | 2013-05-22 18:03:09 +0300 | [diff] [blame] | 5066 | 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] | 5067 | weston_layer_entry_insert(&compositor->fade_layer.view_list, |
| 5068 | &view->layer_link); |
Pekka Paalanen | 79346ab | 2013-05-22 18:03:09 +0300 | [diff] [blame] | 5069 | pixman_region32_init(&surface->input); |
| 5070 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 5071 | return view; |
Pekka Paalanen | 79346ab | 2013-05-22 18:03:09 +0300 | [diff] [blame] | 5072 | } |
| 5073 | |
| 5074 | static void |
| 5075 | shell_fade(struct desktop_shell *shell, enum fade_type type) |
| 5076 | { |
Ander Conselvan de Oliveira | 19d10ef | 2013-02-21 18:35:20 +0200 | [diff] [blame] | 5077 | float tint; |
| 5078 | |
| 5079 | switch (type) { |
| 5080 | case FADE_IN: |
| 5081 | tint = 0.0; |
| 5082 | break; |
| 5083 | case FADE_OUT: |
| 5084 | tint = 1.0; |
| 5085 | break; |
| 5086 | default: |
| 5087 | weston_log("shell: invalid fade type\n"); |
| 5088 | return; |
| 5089 | } |
| 5090 | |
| 5091 | shell->fade.type = type; |
| 5092 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 5093 | if (shell->fade.view == NULL) { |
| 5094 | shell->fade.view = shell_fade_create_surface(shell); |
| 5095 | if (!shell->fade.view) |
Ander Conselvan de Oliveira | 19d10ef | 2013-02-21 18:35:20 +0200 | [diff] [blame] | 5096 | return; |
| 5097 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 5098 | shell->fade.view->alpha = 1.0 - tint; |
| 5099 | weston_view_update_transform(shell->fade.view); |
Ander Conselvan de Oliveira | 19d10ef | 2013-02-21 18:35:20 +0200 | [diff] [blame] | 5100 | } |
| 5101 | |
Kristian Høgsberg | 87d3b61 | 2014-01-19 21:48:10 -0800 | [diff] [blame] | 5102 | if (shell->fade.view->output == NULL) { |
| 5103 | /* If the black view gets a NULL output, we lost the |
| 5104 | * last output and we'll just cancel the fade. This |
| 5105 | * happens when you close the last window under the |
| 5106 | * X11 or Wayland backends. */ |
| 5107 | shell->locked = false; |
| 5108 | weston_surface_destroy(shell->fade.view->surface); |
| 5109 | shell->fade.view = NULL; |
| 5110 | } else if (shell->fade.animation) { |
Kristian Høgsberg | 5281fb1 | 2013-06-17 10:10:28 -0400 | [diff] [blame] | 5111 | weston_fade_update(shell->fade.animation, tint); |
Kristian Høgsberg | 87d3b61 | 2014-01-19 21:48:10 -0800 | [diff] [blame] | 5112 | } else { |
Ander Conselvan de Oliveira | 19d10ef | 2013-02-21 18:35:20 +0200 | [diff] [blame] | 5113 | shell->fade.animation = |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 5114 | weston_fade_run(shell->fade.view, |
Kristian Høgsberg | 5281fb1 | 2013-06-17 10:10:28 -0400 | [diff] [blame] | 5115 | 1.0 - tint, tint, 300.0, |
Ander Conselvan de Oliveira | 19d10ef | 2013-02-21 18:35:20 +0200 | [diff] [blame] | 5116 | shell_fade_done, shell); |
Kristian Høgsberg | 87d3b61 | 2014-01-19 21:48:10 -0800 | [diff] [blame] | 5117 | } |
Ander Conselvan de Oliveira | 19d10ef | 2013-02-21 18:35:20 +0200 | [diff] [blame] | 5118 | } |
| 5119 | |
| 5120 | static void |
Pekka Paalanen | 79346ab | 2013-05-22 18:03:09 +0300 | [diff] [blame] | 5121 | do_shell_fade_startup(void *data) |
| 5122 | { |
| 5123 | struct desktop_shell *shell = data; |
| 5124 | |
Kristian Høgsberg | 724c8d9 | 2013-10-16 11:38:24 -0700 | [diff] [blame] | 5125 | if (shell->startup_animation_type == ANIMATION_FADE) |
| 5126 | shell_fade(shell, FADE_IN); |
| 5127 | else if (shell->startup_animation_type == ANIMATION_NONE) { |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 5128 | weston_surface_destroy(shell->fade.view->surface); |
| 5129 | shell->fade.view = NULL; |
Kristian Høgsberg | 724c8d9 | 2013-10-16 11:38:24 -0700 | [diff] [blame] | 5130 | } |
Pekka Paalanen | 79346ab | 2013-05-22 18:03:09 +0300 | [diff] [blame] | 5131 | } |
| 5132 | |
| 5133 | static void |
| 5134 | shell_fade_startup(struct desktop_shell *shell) |
| 5135 | { |
| 5136 | struct wl_event_loop *loop; |
| 5137 | |
| 5138 | if (!shell->fade.startup_timer) |
| 5139 | return; |
| 5140 | |
| 5141 | wl_event_source_remove(shell->fade.startup_timer); |
| 5142 | shell->fade.startup_timer = NULL; |
| 5143 | |
| 5144 | loop = wl_display_get_event_loop(shell->compositor->wl_display); |
| 5145 | wl_event_loop_add_idle(loop, do_shell_fade_startup, shell); |
| 5146 | } |
| 5147 | |
| 5148 | static int |
| 5149 | fade_startup_timeout(void *data) |
| 5150 | { |
| 5151 | struct desktop_shell *shell = data; |
| 5152 | |
| 5153 | shell_fade_startup(shell); |
| 5154 | return 0; |
| 5155 | } |
| 5156 | |
| 5157 | static void |
| 5158 | shell_fade_init(struct desktop_shell *shell) |
| 5159 | { |
| 5160 | /* Make compositor output all black, and wait for the desktop-shell |
| 5161 | * client to signal it is ready, then fade in. The timer triggers a |
| 5162 | * fade-in, in case the desktop-shell client takes too long. |
| 5163 | */ |
| 5164 | |
| 5165 | struct wl_event_loop *loop; |
| 5166 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 5167 | if (shell->fade.view != NULL) { |
Pekka Paalanen | 79346ab | 2013-05-22 18:03:09 +0300 | [diff] [blame] | 5168 | weston_log("%s: warning: fade surface already exists\n", |
| 5169 | __func__); |
| 5170 | return; |
| 5171 | } |
| 5172 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 5173 | shell->fade.view = shell_fade_create_surface(shell); |
| 5174 | if (!shell->fade.view) |
Pekka Paalanen | 79346ab | 2013-05-22 18:03:09 +0300 | [diff] [blame] | 5175 | return; |
| 5176 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 5177 | weston_view_update_transform(shell->fade.view); |
| 5178 | weston_surface_damage(shell->fade.view->surface); |
Pekka Paalanen | 79346ab | 2013-05-22 18:03:09 +0300 | [diff] [blame] | 5179 | |
| 5180 | loop = wl_display_get_event_loop(shell->compositor->wl_display); |
| 5181 | shell->fade.startup_timer = |
| 5182 | wl_event_loop_add_timer(loop, fade_startup_timeout, shell); |
| 5183 | wl_event_source_timer_update(shell->fade.startup_timer, 15000); |
| 5184 | } |
| 5185 | |
| 5186 | static void |
Ander Conselvan de Oliveira | a457563 | 2013-02-21 18:35:23 +0200 | [diff] [blame] | 5187 | idle_handler(struct wl_listener *listener, void *data) |
Ander Conselvan de Oliveira | 19d10ef | 2013-02-21 18:35:20 +0200 | [diff] [blame] | 5188 | { |
| 5189 | struct desktop_shell *shell = |
Ander Conselvan de Oliveira | a457563 | 2013-02-21 18:35:23 +0200 | [diff] [blame] | 5190 | container_of(listener, struct desktop_shell, idle_listener); |
Kristian Høgsberg | 27d5fa8 | 2014-01-17 16:22:50 -0800 | [diff] [blame] | 5191 | struct weston_seat *seat; |
| 5192 | |
Jonny Lamb | 76cf1fe | 2014-08-20 11:27:10 +0200 | [diff] [blame] | 5193 | wl_list_for_each(seat, &shell->compositor->seat_list, link) { |
Kristian Høgsberg | 27d5fa8 | 2014-01-17 16:22:50 -0800 | [diff] [blame] | 5194 | if (seat->pointer) |
| 5195 | popup_grab_end(seat->pointer); |
Jonny Lamb | 76cf1fe | 2014-08-20 11:27:10 +0200 | [diff] [blame] | 5196 | if (seat->touch) |
| 5197 | touch_popup_grab_end(seat->touch); |
| 5198 | } |
Ander Conselvan de Oliveira | 19d10ef | 2013-02-21 18:35:20 +0200 | [diff] [blame] | 5199 | |
| 5200 | shell_fade(shell, FADE_OUT); |
| 5201 | /* lock() is called from shell_fade_done() */ |
| 5202 | } |
| 5203 | |
| 5204 | static void |
Ander Conselvan de Oliveira | a457563 | 2013-02-21 18:35:23 +0200 | [diff] [blame] | 5205 | wake_handler(struct wl_listener *listener, void *data) |
Ander Conselvan de Oliveira | 19d10ef | 2013-02-21 18:35:20 +0200 | [diff] [blame] | 5206 | { |
| 5207 | struct desktop_shell *shell = |
Ander Conselvan de Oliveira | a457563 | 2013-02-21 18:35:23 +0200 | [diff] [blame] | 5208 | container_of(listener, struct desktop_shell, wake_listener); |
Ander Conselvan de Oliveira | 19d10ef | 2013-02-21 18:35:20 +0200 | [diff] [blame] | 5209 | |
Ander Conselvan de Oliveira | 19d10ef | 2013-02-21 18:35:20 +0200 | [diff] [blame] | 5210 | unlock(shell); |
| 5211 | } |
| 5212 | |
| 5213 | static void |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 5214 | center_on_output(struct weston_view *view, struct weston_output *output) |
Pekka Paalanen | 77346a6 | 2011-11-30 16:26:35 +0200 | [diff] [blame] | 5215 | { |
Giulio Camuffo | b836664 | 2013-04-25 13:57:46 +0300 | [diff] [blame] | 5216 | int32_t surf_x, surf_y, width, height; |
Ander Conselvan de Oliveira | 012b4c7 | 2012-11-27 17:03:42 +0200 | [diff] [blame] | 5217 | float x, y; |
Pekka Paalanen | 77346a6 | 2011-11-30 16:26:35 +0200 | [diff] [blame] | 5218 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 5219 | surface_subsurfaces_boundingbox(view->surface, &surf_x, &surf_y, &width, &height); |
Giulio Camuffo | b836664 | 2013-04-25 13:57:46 +0300 | [diff] [blame] | 5220 | |
| 5221 | x = output->x + (output->width - width) / 2 - surf_x / 2; |
| 5222 | y = output->y + (output->height - height) / 2 - surf_y / 2; |
Ander Conselvan de Oliveira | 012b4c7 | 2012-11-27 17:03:42 +0200 | [diff] [blame] | 5223 | |
Jason Ekstrand | 918f2dd | 2013-12-02 21:01:53 -0600 | [diff] [blame] | 5224 | weston_view_set_position(view, x, y); |
Pekka Paalanen | 77346a6 | 2011-11-30 16:26:35 +0200 | [diff] [blame] | 5225 | } |
| 5226 | |
| 5227 | static void |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 5228 | weston_view_set_initial_position(struct weston_view *view, |
| 5229 | struct desktop_shell *shell) |
Rob Bradford | ac63e5b | 2012-08-13 14:07:52 +0100 | [diff] [blame] | 5230 | { |
| 5231 | struct weston_compositor *compositor = shell->compositor; |
| 5232 | int ix = 0, iy = 0; |
Jonny Lamb | d73c694 | 2014-08-20 15:53:20 +0200 | [diff] [blame] | 5233 | int32_t range_x, range_y; |
| 5234 | int32_t dx, dy, x, y; |
Rob Bradford | ac63e5b | 2012-08-13 14:07:52 +0100 | [diff] [blame] | 5235 | struct weston_output *output, *target_output = NULL; |
| 5236 | struct weston_seat *seat; |
Jonny Lamb | d73c694 | 2014-08-20 15:53:20 +0200 | [diff] [blame] | 5237 | pixman_rectangle32_t area; |
Rob Bradford | ac63e5b | 2012-08-13 14:07:52 +0100 | [diff] [blame] | 5238 | |
| 5239 | /* As a heuristic place the new window on the same output as the |
| 5240 | * pointer. Falling back to the output containing 0, 0. |
| 5241 | * |
| 5242 | * TODO: Do something clever for touch too? |
| 5243 | */ |
| 5244 | wl_list_for_each(seat, &compositor->seat_list, link) { |
Kristian Høgsberg | 2bf8762 | 2013-05-07 23:17:41 -0400 | [diff] [blame] | 5245 | if (seat->pointer) { |
Kristian Høgsberg | e314875 | 2013-05-06 23:19:49 -0400 | [diff] [blame] | 5246 | ix = wl_fixed_to_int(seat->pointer->x); |
| 5247 | iy = wl_fixed_to_int(seat->pointer->y); |
Rob Bradford | ac63e5b | 2012-08-13 14:07:52 +0100 | [diff] [blame] | 5248 | break; |
| 5249 | } |
| 5250 | } |
| 5251 | |
| 5252 | wl_list_for_each(output, &compositor->output_list, link) { |
| 5253 | if (pixman_region32_contains_point(&output->region, ix, iy, NULL)) { |
| 5254 | target_output = output; |
| 5255 | break; |
| 5256 | } |
| 5257 | } |
| 5258 | |
| 5259 | if (!target_output) { |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 5260 | weston_view_set_position(view, 10 + random() % 400, |
| 5261 | 10 + random() % 400); |
Rob Bradford | ac63e5b | 2012-08-13 14:07:52 +0100 | [diff] [blame] | 5262 | return; |
| 5263 | } |
| 5264 | |
| 5265 | /* Valid range within output where the surface will still be onscreen. |
| 5266 | * If this is negative it means that the surface is bigger than |
| 5267 | * output. |
| 5268 | */ |
Jonny Lamb | d73c694 | 2014-08-20 15:53:20 +0200 | [diff] [blame] | 5269 | get_output_work_area(shell, target_output, &area); |
| 5270 | |
| 5271 | dx = area.x; |
| 5272 | dy = area.y; |
| 5273 | range_x = area.width - view->surface->width; |
| 5274 | range_y = area.height - view->surface->height; |
Rob Bradford | ac63e5b | 2012-08-13 14:07:52 +0100 | [diff] [blame] | 5275 | |
Rob Bradford | 4cb88c7 | 2012-08-13 15:18:44 +0100 | [diff] [blame] | 5276 | if (range_x > 0) |
Jonny Lamb | d73c694 | 2014-08-20 15:53:20 +0200 | [diff] [blame] | 5277 | dx += random() % range_x; |
Rob Bradford | 4cb88c7 | 2012-08-13 15:18:44 +0100 | [diff] [blame] | 5278 | |
| 5279 | if (range_y > 0) |
Jonny Lamb | d73c694 | 2014-08-20 15:53:20 +0200 | [diff] [blame] | 5280 | dy += random() % range_y; |
Rob Bradford | ac63e5b | 2012-08-13 14:07:52 +0100 | [diff] [blame] | 5281 | |
| 5282 | x = target_output->x + dx; |
| 5283 | y = target_output->y + dy; |
| 5284 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 5285 | weston_view_set_position(view, x, y); |
Rob Bradford | ac63e5b | 2012-08-13 14:07:52 +0100 | [diff] [blame] | 5286 | } |
| 5287 | |
| 5288 | static void |
Jonny Lamb | d73c694 | 2014-08-20 15:53:20 +0200 | [diff] [blame] | 5289 | set_maximized_position(struct desktop_shell *shell, |
| 5290 | struct shell_surface *shsurf) |
| 5291 | { |
| 5292 | int32_t surf_x, surf_y; |
| 5293 | pixman_rectangle32_t area; |
Marek Chalupa | 8b771af | 2014-09-01 17:20:33 +0200 | [diff] [blame] | 5294 | pixman_box32_t *e; |
Jonny Lamb | d73c694 | 2014-08-20 15:53:20 +0200 | [diff] [blame] | 5295 | |
Jonny Lamb | d73c694 | 2014-08-20 15:53:20 +0200 | [diff] [blame] | 5296 | get_output_work_area(shell, shsurf->output, &area); |
| 5297 | surface_subsurfaces_boundingbox(shsurf->surface, |
| 5298 | &surf_x, &surf_y, NULL, NULL); |
Marek Chalupa | 8b771af | 2014-09-01 17:20:33 +0200 | [diff] [blame] | 5299 | e = pixman_region32_extents(&shsurf->output->region); |
Jonny Lamb | d73c694 | 2014-08-20 15:53:20 +0200 | [diff] [blame] | 5300 | |
| 5301 | weston_view_set_position(shsurf->view, |
Marek Chalupa | 8b771af | 2014-09-01 17:20:33 +0200 | [diff] [blame] | 5302 | e->x1 + area.x - surf_x, |
| 5303 | e->y1 + area.y - surf_y); |
Jonny Lamb | d73c694 | 2014-08-20 15:53:20 +0200 | [diff] [blame] | 5304 | } |
| 5305 | |
| 5306 | static void |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 5307 | map(struct desktop_shell *shell, struct shell_surface *shsurf, |
Jason Ekstrand | 918f2dd | 2013-12-02 21:01:53 -0600 | [diff] [blame] | 5308 | int32_t sx, int32_t sy) |
Kristian Høgsberg | 02ec0a5 | 2011-04-23 13:04:11 -0400 | [diff] [blame] | 5309 | { |
Kristian Høgsberg | 8334bc1 | 2012-01-03 10:29:47 -0500 | [diff] [blame] | 5310 | struct weston_compositor *compositor = shell->compositor; |
Daniel Stone | b210468 | 2012-05-30 16:31:56 +0100 | [diff] [blame] | 5311 | struct weston_seat *seat; |
Pekka Paalanen | 57da4a8 | 2011-11-23 16:42:16 +0200 | [diff] [blame] | 5312 | |
Pekka Paalanen | 77346a6 | 2011-11-30 16:26:35 +0200 | [diff] [blame] | 5313 | /* initial positioning, see also configure() */ |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 5314 | switch (shsurf->type) { |
Rafael Antognolli | ed207b4 | 2013-12-03 15:35:43 -0200 | [diff] [blame] | 5315 | case SHELL_SURFACE_TOPLEVEL: |
Rafael Antognolli | 03b1659 | 2013-12-03 15:35:42 -0200 | [diff] [blame] | 5316 | if (shsurf->state.fullscreen) { |
| 5317 | center_on_output(shsurf->view, shsurf->fullscreen_output); |
| 5318 | shell_map_fullscreen(shsurf); |
| 5319 | } else if (shsurf->state.maximized) { |
Jonny Lamb | d73c694 | 2014-08-20 15:53:20 +0200 | [diff] [blame] | 5320 | set_maximized_position(shell, shsurf); |
Rafael Antognolli | ed207b4 | 2013-12-03 15:35:43 -0200 | [diff] [blame] | 5321 | } else if (!shsurf->state.relative) { |
Rafael Antognolli | 03b1659 | 2013-12-03 15:35:42 -0200 | [diff] [blame] | 5322 | weston_view_set_initial_position(shsurf->view, shell); |
| 5323 | } |
Juan Zhao | 96879df | 2012-02-07 08:45:41 +0800 | [diff] [blame] | 5324 | break; |
Tiago Vignatti | 0f99701 | 2012-02-10 16:17:23 +0200 | [diff] [blame] | 5325 | case SHELL_SURFACE_POPUP: |
Kristian Høgsberg | 3730f36 | 2012-04-13 12:40:07 -0400 | [diff] [blame] | 5326 | shell_map_popup(shsurf); |
Rob Bradford | db99938 | 2012-12-06 12:07:48 +0000 | [diff] [blame] | 5327 | break; |
Ander Conselvan de Oliveira | e9e0515 | 2012-02-15 17:02:56 +0200 | [diff] [blame] | 5328 | case SHELL_SURFACE_NONE: |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 5329 | weston_view_set_position(shsurf->view, |
| 5330 | shsurf->view->geometry.x + sx, |
| 5331 | shsurf->view->geometry.y + sy); |
Tiago Vignatti | 0f99701 | 2012-02-10 16:17:23 +0200 | [diff] [blame] | 5332 | break; |
Philip Withnall | 0f640e2 | 2013-11-25 18:01:31 +0000 | [diff] [blame] | 5333 | case SHELL_SURFACE_XWAYLAND: |
Pekka Paalanen | 77346a6 | 2011-11-30 16:26:35 +0200 | [diff] [blame] | 5334 | default: |
| 5335 | ; |
| 5336 | } |
Kristian Høgsberg | 7584062 | 2011-09-06 13:48:16 -0400 | [diff] [blame] | 5337 | |
Philip Withnall | e1d75ae | 2013-11-25 18:01:41 +0000 | [diff] [blame] | 5338 | /* Surface stacking order, see also activate(). */ |
| 5339 | shell_surface_update_layer(shsurf); |
Pekka Paalanen | f0fc70d | 2011-11-15 13:34:54 +0200 | [diff] [blame] | 5340 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 5341 | if (shsurf->type != SHELL_SURFACE_NONE) { |
| 5342 | weston_view_update_transform(shsurf->view); |
Rafael Antognolli | 03b1659 | 2013-12-03 15:35:42 -0200 | [diff] [blame] | 5343 | if (shsurf->state.maximized) { |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 5344 | shsurf->surface->output = shsurf->output; |
| 5345 | shsurf->view->output = shsurf->output; |
| 5346 | } |
Ander Conselvan de Oliveira | de56c31 | 2012-03-05 15:39:23 +0200 | [diff] [blame] | 5347 | } |
Kristian Høgsberg | 2f88a40 | 2011-12-04 15:32:59 -0500 | [diff] [blame] | 5348 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 5349 | switch (shsurf->type) { |
Tiago Vignatti | fb2adba | 2013-06-12 15:43:21 -0300 | [diff] [blame] | 5350 | /* XXX: xwayland's using the same fields for transient type */ |
| 5351 | case SHELL_SURFACE_XWAYLAND: |
Tiago Vignatti | 99aeb1e | 2012-05-23 22:06:26 +0300 | [diff] [blame] | 5352 | if (shsurf->transient.flags == |
| 5353 | WL_SHELL_SURFACE_TRANSIENT_INACTIVE) |
| 5354 | break; |
| 5355 | case SHELL_SURFACE_TOPLEVEL: |
Rafael Antognolli | ed207b4 | 2013-12-03 15:35:43 -0200 | [diff] [blame] | 5356 | if (shsurf->state.relative && |
| 5357 | shsurf->transient.flags == WL_SHELL_SURFACE_TRANSIENT_INACTIVE) |
| 5358 | break; |
Rafael Antognolli | ba5d2d7 | 2013-12-04 17:49:55 -0200 | [diff] [blame] | 5359 | if (shell->locked) |
Rafael Antognolli | ed207b4 | 2013-12-03 15:35:43 -0200 | [diff] [blame] | 5360 | break; |
| 5361 | wl_list_for_each(seat, &compositor->seat_list, link) |
Emilio Pozuelo Monfort | 9e7c759 | 2014-01-30 14:01:10 +0100 | [diff] [blame] | 5362 | activate(shell, shsurf->surface, seat, true); |
Juan Zhao | 7bb92f0 | 2011-12-15 11:31:51 -0500 | [diff] [blame] | 5363 | break; |
Philip Withnall | 0f640e2 | 2013-11-25 18:01:31 +0000 | [diff] [blame] | 5364 | case SHELL_SURFACE_POPUP: |
| 5365 | case SHELL_SURFACE_NONE: |
Juan Zhao | 7bb92f0 | 2011-12-15 11:31:51 -0500 | [diff] [blame] | 5366 | default: |
| 5367 | break; |
| 5368 | } |
| 5369 | |
Rafael Antognolli | 03b1659 | 2013-12-03 15:35:42 -0200 | [diff] [blame] | 5370 | if (shsurf->type == SHELL_SURFACE_TOPLEVEL && |
| 5371 | !shsurf->state.maximized && !shsurf->state.fullscreen) |
Juan Zhao | e10d279 | 2012-04-25 19:09:52 +0800 | [diff] [blame] | 5372 | { |
| 5373 | switch (shell->win_animation_type) { |
| 5374 | case ANIMATION_FADE: |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 5375 | 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] | 5376 | break; |
| 5377 | case ANIMATION_ZOOM: |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 5378 | weston_zoom_run(shsurf->view, 0.5, 1.0, NULL, NULL); |
Juan Zhao | e10d279 | 2012-04-25 19:09:52 +0800 | [diff] [blame] | 5379 | break; |
Philip Withnall | 4a86a0a | 2013-11-25 18:01:32 +0000 | [diff] [blame] | 5380 | case ANIMATION_NONE: |
Juan Zhao | e10d279 | 2012-04-25 19:09:52 +0800 | [diff] [blame] | 5381 | default: |
| 5382 | break; |
| 5383 | } |
| 5384 | } |
Kristian Høgsberg | 32e24cc | 2011-11-09 12:07:35 -0500 | [diff] [blame] | 5385 | } |
| 5386 | |
| 5387 | static void |
Tiago Vignatti | be14326 | 2012-04-16 17:31:41 +0300 | [diff] [blame] | 5388 | configure(struct desktop_shell *shell, struct weston_surface *surface, |
Jason Ekstrand | 918f2dd | 2013-12-02 21:01:53 -0600 | [diff] [blame] | 5389 | float x, float y) |
Kristian Høgsberg | 32e24cc | 2011-11-09 12:07:35 -0500 | [diff] [blame] | 5390 | { |
Pekka Paalanen | 77346a6 | 2011-11-30 16:26:35 +0200 | [diff] [blame] | 5391 | struct shell_surface *shsurf; |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 5392 | struct weston_view *view; |
Kristian Høgsberg | 32e24cc | 2011-11-09 12:07:35 -0500 | [diff] [blame] | 5393 | |
Pekka Paalanen | 77346a6 | 2011-11-30 16:26:35 +0200 | [diff] [blame] | 5394 | shsurf = get_shell_surface(surface); |
Pekka Paalanen | 77346a6 | 2011-11-30 16:26:35 +0200 | [diff] [blame] | 5395 | |
U. Artie Eoff | cf5737a | 2014-01-17 10:08:25 -0800 | [diff] [blame] | 5396 | assert(shsurf); |
| 5397 | |
Rafael Antognolli | 03b1659 | 2013-12-03 15:35:42 -0200 | [diff] [blame] | 5398 | if (shsurf->state.fullscreen) |
Alex Wu | 4539b08 | 2012-03-01 12:57:46 +0800 | [diff] [blame] | 5399 | shell_configure_fullscreen(shsurf); |
Rafael Antognolli | 03b1659 | 2013-12-03 15:35:42 -0200 | [diff] [blame] | 5400 | else if (shsurf->state.maximized) { |
Jonny Lamb | d73c694 | 2014-08-20 15:53:20 +0200 | [diff] [blame] | 5401 | set_maximized_position(shell, shsurf); |
Rafael Antognolli | 03b1659 | 2013-12-03 15:35:42 -0200 | [diff] [blame] | 5402 | } else { |
Jason Ekstrand | 918f2dd | 2013-12-02 21:01:53 -0600 | [diff] [blame] | 5403 | weston_view_set_position(shsurf->view, x, y); |
Kristian Høgsberg | 7a5c979 | 2011-06-18 06:12:54 -0400 | [diff] [blame] | 5404 | } |
Kristian Høgsberg | 32e24cc | 2011-11-09 12:07:35 -0500 | [diff] [blame] | 5405 | |
Alex Wu | 4539b08 | 2012-03-01 12:57:46 +0800 | [diff] [blame] | 5406 | /* XXX: would a fullscreen surface need the same handling? */ |
Kristian Høgsberg | 6a8b553 | 2012-02-16 23:43:59 -0500 | [diff] [blame] | 5407 | if (surface->output) { |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 5408 | wl_list_for_each(view, &surface->views, surface_link) |
| 5409 | weston_view_update_transform(view); |
Pekka Paalanen | 77346a6 | 2011-11-30 16:26:35 +0200 | [diff] [blame] | 5410 | |
Rafael Antognolli | 03b1659 | 2013-12-03 15:35:42 -0200 | [diff] [blame] | 5411 | if (shsurf->state.maximized) |
Juan Zhao | 96879df | 2012-02-07 08:45:41 +0800 | [diff] [blame] | 5412 | surface->output = shsurf->output; |
Pekka Paalanen | 77346a6 | 2011-11-30 16:26:35 +0200 | [diff] [blame] | 5413 | } |
Kristian Høgsberg | 0793756 | 2011-04-12 17:25:42 -0400 | [diff] [blame] | 5414 | } |
| 5415 | |
Ander Conselvan de Oliveira | 093bfa3 | 2012-03-27 17:36:41 +0300 | [diff] [blame] | 5416 | static void |
Jason Ekstrand | 918f2dd | 2013-12-02 21:01:53 -0600 | [diff] [blame] | 5417 | 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] | 5418 | { |
Ander Conselvan de Oliveira | 7fb9f95 | 2012-03-27 17:36:42 +0300 | [diff] [blame] | 5419 | struct shell_surface *shsurf = get_shell_surface(es); |
U. Artie Eoff | cf5737a | 2014-01-17 10:08:25 -0800 | [diff] [blame] | 5420 | struct desktop_shell *shell; |
Tiago Vignatti | 70e5c9c | 2012-05-07 15:23:07 +0300 | [diff] [blame] | 5421 | int type_changed = 0; |
Ander Conselvan de Oliveira | 093bfa3 | 2012-03-27 17:36:41 +0300 | [diff] [blame] | 5422 | |
U. Artie Eoff | cf5737a | 2014-01-17 10:08:25 -0800 | [diff] [blame] | 5423 | assert(shsurf); |
| 5424 | |
| 5425 | shell = shsurf->shell; |
| 5426 | |
Kristian Høgsberg | 8eb0f4f | 2013-06-17 10:33:14 -0400 | [diff] [blame] | 5427 | if (!weston_surface_is_mapped(es) && |
| 5428 | !wl_list_empty(&shsurf->popup.grab_link)) { |
Giulio Camuffo | 5085a75 | 2013-03-25 21:42:45 +0100 | [diff] [blame] | 5429 | remove_popup_grab(shsurf); |
| 5430 | } |
| 5431 | |
Jason Ekstrand | 918f2dd | 2013-12-02 21:01:53 -0600 | [diff] [blame] | 5432 | if (es->width == 0) |
Giulio Camuffo | 184df50 | 2013-02-21 11:29:21 +0100 | [diff] [blame] | 5433 | return; |
| 5434 | |
Jasper St. Pierre | ccf48fb | 2014-05-02 10:21:38 -0400 | [diff] [blame] | 5435 | if (shsurf->has_next_geometry) { |
| 5436 | shsurf->geometry = shsurf->next_geometry; |
| 5437 | shsurf->has_next_geometry = false; |
| 5438 | shsurf->has_set_geometry = true; |
| 5439 | } else if (!shsurf->has_set_geometry) { |
| 5440 | surface_subsurfaces_boundingbox(shsurf->surface, |
| 5441 | &shsurf->geometry.x, |
| 5442 | &shsurf->geometry.y, |
| 5443 | &shsurf->geometry.width, |
| 5444 | &shsurf->geometry.height); |
Jasper St. Pierre | 851799e | 2014-05-02 10:14:07 -0400 | [diff] [blame] | 5445 | } |
| 5446 | |
Kristian Høgsberg | c8f8dd8 | 2013-12-05 23:20:33 -0800 | [diff] [blame] | 5447 | if (shsurf->state_changed) { |
Kristian Høgsberg | 7f366e7 | 2012-04-27 17:20:01 -0400 | [diff] [blame] | 5448 | set_surface_type(shsurf); |
Kristian Høgsberg | f7e23d5 | 2012-04-27 17:51:59 -0400 | [diff] [blame] | 5449 | type_changed = 1; |
| 5450 | } |
Kristian Høgsberg | 7f366e7 | 2012-04-27 17:20:01 -0400 | [diff] [blame] | 5451 | |
Ander Conselvan de Oliveira | 093bfa3 | 2012-03-27 17:36:41 +0300 | [diff] [blame] | 5452 | if (!weston_surface_is_mapped(es)) { |
Jason Ekstrand | 918f2dd | 2013-12-02 21:01:53 -0600 | [diff] [blame] | 5453 | map(shell, shsurf, sx, sy); |
Kristian Høgsberg | f7e23d5 | 2012-04-27 17:51:59 -0400 | [diff] [blame] | 5454 | } else if (type_changed || sx != 0 || sy != 0 || |
Jason Ekstrand | 918f2dd | 2013-12-02 21:01:53 -0600 | [diff] [blame] | 5455 | shsurf->last_width != es->width || |
| 5456 | shsurf->last_height != es->height) { |
John Kåre Alsaker | 490d02a | 2012-09-30 02:57:21 +0200 | [diff] [blame] | 5457 | float from_x, from_y; |
| 5458 | float to_x, to_y; |
Ander Conselvan de Oliveira | 093bfa3 | 2012-03-27 17:36:41 +0300 | [diff] [blame] | 5459 | |
Kristian Høgsberg | 44cd196 | 2014-02-05 21:36:04 -0800 | [diff] [blame] | 5460 | if (shsurf->resize_edges) { |
| 5461 | sx = 0; |
| 5462 | sy = 0; |
| 5463 | } |
| 5464 | |
| 5465 | if (shsurf->resize_edges & WL_SHELL_SURFACE_RESIZE_LEFT) |
| 5466 | sx = shsurf->last_width - es->width; |
| 5467 | if (shsurf->resize_edges & WL_SHELL_SURFACE_RESIZE_TOP) |
| 5468 | sy = shsurf->last_height - es->height; |
| 5469 | |
| 5470 | shsurf->last_width = es->width; |
| 5471 | shsurf->last_height = es->height; |
| 5472 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 5473 | weston_view_to_global_float(shsurf->view, 0, 0, &from_x, &from_y); |
| 5474 | 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] | 5475 | configure(shell, es, |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 5476 | shsurf->view->geometry.x + to_x - from_x, |
Jason Ekstrand | 918f2dd | 2013-12-02 21:01:53 -0600 | [diff] [blame] | 5477 | shsurf->view->geometry.y + to_y - from_y); |
Ander Conselvan de Oliveira | 093bfa3 | 2012-03-27 17:36:41 +0300 | [diff] [blame] | 5478 | } |
| 5479 | } |
| 5480 | |
Pekka Paalanen | 2e62e4a | 2014-08-28 11:41:26 +0300 | [diff] [blame] | 5481 | static bool |
| 5482 | check_desktop_shell_crash_too_early(struct desktop_shell *shell) |
| 5483 | { |
| 5484 | struct timespec now; |
| 5485 | |
| 5486 | if (clock_gettime(CLOCK_MONOTONIC, &now) < 0) |
| 5487 | return false; |
| 5488 | |
| 5489 | /* |
| 5490 | * If the shell helper client dies before the session has been |
| 5491 | * up for roughly 30 seconds, better just make Weston shut down, |
| 5492 | * because the user likely has no way to interact with the desktop |
| 5493 | * anyway. |
| 5494 | */ |
| 5495 | if (now.tv_sec - shell->startup_time.tv_sec < 30) { |
| 5496 | weston_log("Error: %s apparently cannot run at all.\n", |
| 5497 | shell->client); |
| 5498 | weston_log_continue(STAMP_SPACE "Quitting..."); |
| 5499 | wl_display_terminate(shell->compositor->wl_display); |
| 5500 | |
| 5501 | return true; |
| 5502 | } |
| 5503 | |
| 5504 | return false; |
| 5505 | } |
| 5506 | |
Tiago Vignatti | b7dbbd6 | 2012-09-25 17:57:01 +0300 | [diff] [blame] | 5507 | static void launch_desktop_shell_process(void *data); |
Pekka Paalanen | 4d733ee | 2012-01-17 14:36:27 +0200 | [diff] [blame] | 5508 | |
Kristian Høgsberg | 97d44aa | 2011-08-26 17:21:20 -0400 | [diff] [blame] | 5509 | static void |
Pekka Paalanen | 826dc14 | 2014-08-27 12:11:53 +0300 | [diff] [blame] | 5510 | respawn_desktop_shell_process(struct desktop_shell *shell) |
Pekka Paalanen | 6cd281a | 2011-11-03 14:11:32 +0200 | [diff] [blame] | 5511 | { |
Pekka Paalanen | 4d733ee | 2012-01-17 14:36:27 +0200 | [diff] [blame] | 5512 | uint32_t time; |
Pekka Paalanen | 4d733ee | 2012-01-17 14:36:27 +0200 | [diff] [blame] | 5513 | |
| 5514 | /* if desktop-shell dies more than 5 times in 30 seconds, give up */ |
| 5515 | time = weston_compositor_get_time(); |
Kristian Høgsberg | f03a616 | 2012-01-17 11:07:42 -0500 | [diff] [blame] | 5516 | if (time - shell->child.deathstamp > 30000) { |
Pekka Paalanen | 4d733ee | 2012-01-17 14:36:27 +0200 | [diff] [blame] | 5517 | shell->child.deathstamp = time; |
| 5518 | shell->child.deathcount = 0; |
| 5519 | } |
| 5520 | |
| 5521 | shell->child.deathcount++; |
| 5522 | if (shell->child.deathcount > 5) { |
Pekka Paalanen | 826dc14 | 2014-08-27 12:11:53 +0300 | [diff] [blame] | 5523 | weston_log("%s disconnected, giving up.\n", shell->client); |
Pekka Paalanen | 4d733ee | 2012-01-17 14:36:27 +0200 | [diff] [blame] | 5524 | return; |
| 5525 | } |
| 5526 | |
Pekka Paalanen | 826dc14 | 2014-08-27 12:11:53 +0300 | [diff] [blame] | 5527 | weston_log("%s disconnected, respawning...\n", shell->client); |
Pekka Paalanen | 4d733ee | 2012-01-17 14:36:27 +0200 | [diff] [blame] | 5528 | launch_desktop_shell_process(shell); |
Pekka Paalanen | 6cd281a | 2011-11-03 14:11:32 +0200 | [diff] [blame] | 5529 | } |
| 5530 | |
Tiago Vignatti | b7dbbd6 | 2012-09-25 17:57:01 +0300 | [diff] [blame] | 5531 | static void |
Ander Conselvan de Oliveira | 312ea4c | 2013-12-20 21:07:01 +0200 | [diff] [blame] | 5532 | desktop_shell_client_destroy(struct wl_listener *listener, void *data) |
| 5533 | { |
| 5534 | struct desktop_shell *shell; |
| 5535 | |
| 5536 | shell = container_of(listener, struct desktop_shell, |
| 5537 | child.client_destroy_listener); |
| 5538 | |
Pekka Paalanen | 826dc14 | 2014-08-27 12:11:53 +0300 | [diff] [blame] | 5539 | wl_list_remove(&shell->child.client_destroy_listener.link); |
Ander Conselvan de Oliveira | 312ea4c | 2013-12-20 21:07:01 +0200 | [diff] [blame] | 5540 | shell->child.client = NULL; |
Pekka Paalanen | 826dc14 | 2014-08-27 12:11:53 +0300 | [diff] [blame] | 5541 | /* |
| 5542 | * unbind_desktop_shell() will reset shell->child.desktop_shell |
| 5543 | * before the respawned process has a chance to create a new |
| 5544 | * desktop_shell object, because we are being called from the |
| 5545 | * wl_client destructor which destroys all wl_resources before |
| 5546 | * returning. |
| 5547 | */ |
| 5548 | |
Pekka Paalanen | 2e62e4a | 2014-08-28 11:41:26 +0300 | [diff] [blame] | 5549 | if (!check_desktop_shell_crash_too_early(shell)) |
| 5550 | respawn_desktop_shell_process(shell); |
| 5551 | |
Pekka Paalanen | 826dc14 | 2014-08-27 12:11:53 +0300 | [diff] [blame] | 5552 | shell_fade_startup(shell); |
Ander Conselvan de Oliveira | 312ea4c | 2013-12-20 21:07:01 +0200 | [diff] [blame] | 5553 | } |
| 5554 | |
| 5555 | static void |
Tiago Vignatti | b7dbbd6 | 2012-09-25 17:57:01 +0300 | [diff] [blame] | 5556 | launch_desktop_shell_process(void *data) |
Pekka Paalanen | 6cd281a | 2011-11-03 14:11:32 +0200 | [diff] [blame] | 5557 | { |
Tiago Vignatti | b7dbbd6 | 2012-09-25 17:57:01 +0300 | [diff] [blame] | 5558 | struct desktop_shell *shell = data; |
Pekka Paalanen | 6cd281a | 2011-11-03 14:11:32 +0200 | [diff] [blame] | 5559 | |
Pekka Paalanen | 826dc14 | 2014-08-27 12:11:53 +0300 | [diff] [blame] | 5560 | shell->child.client = weston_client_start(shell->compositor, |
| 5561 | shell->client); |
Pekka Paalanen | 409ef0a | 2011-12-02 15:30:21 +0200 | [diff] [blame] | 5562 | |
Arnaud Vrac | 4263119 | 2014-08-25 20:56:46 +0200 | [diff] [blame] | 5563 | if (!shell->child.client) { |
Emilio Pozuelo Monfort | 46ce798 | 2013-11-20 13:22:29 +0100 | [diff] [blame] | 5564 | weston_log("not able to start %s\n", shell->client); |
Arnaud Vrac | 4263119 | 2014-08-25 20:56:46 +0200 | [diff] [blame] | 5565 | return; |
| 5566 | } |
Ander Conselvan de Oliveira | 312ea4c | 2013-12-20 21:07:01 +0200 | [diff] [blame] | 5567 | |
| 5568 | shell->child.client_destroy_listener.notify = |
| 5569 | desktop_shell_client_destroy; |
| 5570 | wl_client_add_destroy_listener(shell->child.client, |
| 5571 | &shell->child.client_destroy_listener); |
Pekka Paalanen | 6cd281a | 2011-11-03 14:11:32 +0200 | [diff] [blame] | 5572 | } |
| 5573 | |
| 5574 | static void |
Kristian Høgsberg | 2bff94e | 2014-02-11 12:22:51 -0800 | [diff] [blame] | 5575 | handle_shell_client_destroy(struct wl_listener *listener, void *data) |
| 5576 | { |
| 5577 | struct shell_client *sc = |
| 5578 | container_of(listener, struct shell_client, destroy_listener); |
| 5579 | |
| 5580 | if (sc->ping_timer) |
| 5581 | wl_event_source_remove(sc->ping_timer); |
| 5582 | free(sc); |
| 5583 | } |
| 5584 | |
Kristian Høgsberg | dd62aba | 2014-02-12 09:56:19 -0800 | [diff] [blame] | 5585 | static struct shell_client * |
| 5586 | shell_client_create(struct wl_client *client, struct desktop_shell *shell, |
| 5587 | const struct wl_interface *interface, uint32_t id) |
Rafael Antognolli | e2a3455 | 2013-12-03 15:35:45 -0200 | [diff] [blame] | 5588 | { |
Kristian Høgsberg | 2bff94e | 2014-02-11 12:22:51 -0800 | [diff] [blame] | 5589 | struct shell_client *sc; |
Rafael Antognolli | e2a3455 | 2013-12-03 15:35:45 -0200 | [diff] [blame] | 5590 | |
Kristian Høgsberg | 2bff94e | 2014-02-11 12:22:51 -0800 | [diff] [blame] | 5591 | sc = zalloc(sizeof *sc); |
| 5592 | if (sc == NULL) { |
| 5593 | wl_client_post_no_memory(client); |
Kristian Høgsberg | dd62aba | 2014-02-12 09:56:19 -0800 | [diff] [blame] | 5594 | return NULL; |
Kristian Høgsberg | 2bff94e | 2014-02-11 12:22:51 -0800 | [diff] [blame] | 5595 | } |
Kristian Høgsberg | dd62aba | 2014-02-12 09:56:19 -0800 | [diff] [blame] | 5596 | |
| 5597 | sc->resource = wl_resource_create(client, interface, 1, id); |
Kristian Høgsberg | 2bff94e | 2014-02-11 12:22:51 -0800 | [diff] [blame] | 5598 | if (sc->resource == NULL) { |
| 5599 | free(sc); |
| 5600 | wl_client_post_no_memory(client); |
Kristian Høgsberg | dd62aba | 2014-02-12 09:56:19 -0800 | [diff] [blame] | 5601 | return NULL; |
Kristian Høgsberg | 2bff94e | 2014-02-11 12:22:51 -0800 | [diff] [blame] | 5602 | } |
| 5603 | |
| 5604 | sc->client = client; |
| 5605 | sc->shell = shell; |
| 5606 | sc->destroy_listener.notify = handle_shell_client_destroy; |
| 5607 | wl_client_add_destroy_listener(client, &sc->destroy_listener); |
| 5608 | |
Kristian Høgsberg | dd62aba | 2014-02-12 09:56:19 -0800 | [diff] [blame] | 5609 | return sc; |
| 5610 | } |
| 5611 | |
| 5612 | static void |
| 5613 | bind_shell(struct wl_client *client, void *data, uint32_t version, uint32_t id) |
| 5614 | { |
| 5615 | struct desktop_shell *shell = data; |
| 5616 | struct shell_client *sc; |
| 5617 | |
| 5618 | sc = shell_client_create(client, shell, &wl_shell_interface, id); |
| 5619 | if (sc) |
| 5620 | wl_resource_set_implementation(sc->resource, |
| 5621 | &shell_implementation, |
Jason Ekstrand | 9e9512f | 2014-04-16 21:12:10 -0500 | [diff] [blame] | 5622 | sc, NULL); |
Kristian Høgsberg | dd62aba | 2014-02-12 09:56:19 -0800 | [diff] [blame] | 5623 | } |
| 5624 | |
| 5625 | static void |
| 5626 | bind_xdg_shell(struct wl_client *client, void *data, uint32_t version, uint32_t id) |
| 5627 | { |
| 5628 | struct desktop_shell *shell = data; |
| 5629 | struct shell_client *sc; |
| 5630 | |
| 5631 | sc = shell_client_create(client, shell, &xdg_shell_interface, id); |
| 5632 | if (sc) |
| 5633 | wl_resource_set_dispatcher(sc->resource, |
| 5634 | xdg_shell_unversioned_dispatch, |
| 5635 | NULL, sc, NULL); |
Rafael Antognolli | e2a3455 | 2013-12-03 15:35:45 -0200 | [diff] [blame] | 5636 | } |
| 5637 | |
| 5638 | static void |
Pekka Paalanen | 9ef3e01 | 2011-11-15 13:34:48 +0200 | [diff] [blame] | 5639 | unbind_desktop_shell(struct wl_resource *resource) |
| 5640 | { |
Jason Ekstrand | 651f00e | 2013-06-14 10:07:54 -0500 | [diff] [blame] | 5641 | struct desktop_shell *shell = wl_resource_get_user_data(resource); |
Kristian Høgsberg | 1ec0c31 | 2011-11-15 16:39:55 -0500 | [diff] [blame] | 5642 | |
| 5643 | if (shell->locked) |
| 5644 | resume_desktop(shell); |
| 5645 | |
Pekka Paalanen | 9ef3e01 | 2011-11-15 13:34:48 +0200 | [diff] [blame] | 5646 | shell->child.desktop_shell = NULL; |
| 5647 | shell->prepare_event_sent = false; |
Pekka Paalanen | 9ef3e01 | 2011-11-15 13:34:48 +0200 | [diff] [blame] | 5648 | } |
| 5649 | |
| 5650 | static void |
Kristian Høgsberg | 7584062 | 2011-09-06 13:48:16 -0400 | [diff] [blame] | 5651 | bind_desktop_shell(struct wl_client *client, |
| 5652 | void *data, uint32_t version, uint32_t id) |
| 5653 | { |
Tiago Vignatti | be14326 | 2012-04-16 17:31:41 +0300 | [diff] [blame] | 5654 | struct desktop_shell *shell = data; |
Pekka Paalanen | bbe6052 | 2011-11-03 14:11:33 +0200 | [diff] [blame] | 5655 | struct wl_resource *resource; |
Kristian Høgsberg | 7584062 | 2011-09-06 13:48:16 -0400 | [diff] [blame] | 5656 | |
Jason Ekstrand | a85118c | 2013-06-27 20:17:02 -0500 | [diff] [blame] | 5657 | resource = wl_resource_create(client, &desktop_shell_interface, |
Jonny Lamb | 765760d | 2014-08-20 15:53:19 +0200 | [diff] [blame] | 5658 | MIN(version, 3), id); |
Pekka Paalanen | bbe6052 | 2011-11-03 14:11:33 +0200 | [diff] [blame] | 5659 | |
Pekka Paalanen | 9ef3e01 | 2011-11-15 13:34:48 +0200 | [diff] [blame] | 5660 | if (client == shell->child.client) { |
Jason Ekstrand | a85118c | 2013-06-27 20:17:02 -0500 | [diff] [blame] | 5661 | wl_resource_set_implementation(resource, |
| 5662 | &desktop_shell_implementation, |
| 5663 | shell, unbind_desktop_shell); |
Pekka Paalanen | 9ef3e01 | 2011-11-15 13:34:48 +0200 | [diff] [blame] | 5664 | shell->child.desktop_shell = resource; |
Pekka Paalanen | 79346ab | 2013-05-22 18:03:09 +0300 | [diff] [blame] | 5665 | |
| 5666 | if (version < 2) |
| 5667 | shell_fade_startup(shell); |
| 5668 | |
Pekka Paalanen | bbe6052 | 2011-11-03 14:11:33 +0200 | [diff] [blame] | 5669 | return; |
Pekka Paalanen | 9ef3e01 | 2011-11-15 13:34:48 +0200 | [diff] [blame] | 5670 | } |
Pekka Paalanen | bbe6052 | 2011-11-03 14:11:33 +0200 | [diff] [blame] | 5671 | |
| 5672 | wl_resource_post_error(resource, WL_DISPLAY_ERROR_INVALID_OBJECT, |
| 5673 | "permission to bind desktop_shell denied"); |
Kristian Høgsberg | 7584062 | 2011-09-06 13:48:16 -0400 | [diff] [blame] | 5674 | } |
| 5675 | |
Pekka Paalanen | 6e16811 | 2011-11-24 11:34:05 +0200 | [diff] [blame] | 5676 | static void |
Jason Ekstrand | 918f2dd | 2013-12-02 21:01:53 -0600 | [diff] [blame] | 5677 | screensaver_configure(struct weston_surface *surface, int32_t sx, int32_t sy) |
Kristian Høgsberg | 1a73a63 | 2012-06-26 22:15:53 -0400 | [diff] [blame] | 5678 | { |
Giulio Camuffo | 7fe01b1 | 2013-03-28 18:02:42 +0100 | [diff] [blame] | 5679 | struct desktop_shell *shell = surface->configure_private; |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 5680 | struct weston_view *view; |
Giulio Camuffo | 412e6a5 | 2014-07-09 22:12:56 +0300 | [diff] [blame] | 5681 | struct weston_layer_entry *prev; |
Kristian Høgsberg | 1a73a63 | 2012-06-26 22:15:53 -0400 | [diff] [blame] | 5682 | |
Jason Ekstrand | 918f2dd | 2013-12-02 21:01:53 -0600 | [diff] [blame] | 5683 | if (surface->width == 0) |
Giulio Camuffo | 184df50 | 2013-02-21 11:29:21 +0100 | [diff] [blame] | 5684 | return; |
| 5685 | |
Pekka Paalanen | 3a1d07d | 2012-12-20 14:02:13 +0200 | [diff] [blame] | 5686 | /* XXX: starting weston-screensaver beforehand does not work */ |
Kristian Høgsberg | 1a73a63 | 2012-06-26 22:15:53 -0400 | [diff] [blame] | 5687 | if (!shell->locked) |
| 5688 | return; |
| 5689 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 5690 | view = container_of(surface->views.next, struct weston_view, surface_link); |
| 5691 | center_on_output(view, surface->output); |
Kristian Høgsberg | 1a73a63 | 2012-06-26 22:15:53 -0400 | [diff] [blame] | 5692 | |
Giulio Camuffo | 412e6a5 | 2014-07-09 22:12:56 +0300 | [diff] [blame] | 5693 | if (wl_list_empty(&view->layer_link.link)) { |
| 5694 | prev = container_of(shell->lock_layer.view_list.link.prev, |
| 5695 | struct weston_layer_entry, link); |
| 5696 | weston_layer_entry_insert(prev, &view->layer_link); |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 5697 | weston_view_update_transform(view); |
Ander Conselvan de Oliveira | 859e885 | 2013-02-21 18:35:21 +0200 | [diff] [blame] | 5698 | wl_event_source_timer_update(shell->screensaver.timer, |
| 5699 | shell->screensaver.duration); |
Ander Conselvan de Oliveira | 19d10ef | 2013-02-21 18:35:20 +0200 | [diff] [blame] | 5700 | shell_fade(shell, FADE_IN); |
Kristian Høgsberg | 1a73a63 | 2012-06-26 22:15:53 -0400 | [diff] [blame] | 5701 | } |
| 5702 | } |
| 5703 | |
| 5704 | static void |
Pekka Paalanen | 6e16811 | 2011-11-24 11:34:05 +0200 | [diff] [blame] | 5705 | screensaver_set_surface(struct wl_client *client, |
| 5706 | struct wl_resource *resource, |
Kristian Høgsberg | 1a73a63 | 2012-06-26 22:15:53 -0400 | [diff] [blame] | 5707 | struct wl_resource *surface_resource, |
Pekka Paalanen | 6e16811 | 2011-11-24 11:34:05 +0200 | [diff] [blame] | 5708 | struct wl_resource *output_resource) |
| 5709 | { |
Jason Ekstrand | 651f00e | 2013-06-14 10:07:54 -0500 | [diff] [blame] | 5710 | struct desktop_shell *shell = wl_resource_get_user_data(resource); |
Jason Ekstrand | 0f2ef7e | 2013-06-14 10:07:53 -0500 | [diff] [blame] | 5711 | struct weston_surface *surface = |
| 5712 | wl_resource_get_user_data(surface_resource); |
Jason Ekstrand | a0d2dde | 2013-06-14 10:08:01 -0500 | [diff] [blame] | 5713 | struct weston_output *output = wl_resource_get_user_data(output_resource); |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 5714 | struct weston_view *view, *next; |
| 5715 | |
| 5716 | /* Make sure we only have one view */ |
| 5717 | wl_list_for_each_safe(view, next, &surface->views, surface_link) |
| 5718 | weston_view_destroy(view); |
| 5719 | weston_view_create(surface); |
Pekka Paalanen | 6e16811 | 2011-11-24 11:34:05 +0200 | [diff] [blame] | 5720 | |
Kristian Høgsberg | 1a73a63 | 2012-06-26 22:15:53 -0400 | [diff] [blame] | 5721 | surface->configure = screensaver_configure; |
Giulio Camuffo | 7fe01b1 | 2013-03-28 18:02:42 +0100 | [diff] [blame] | 5722 | surface->configure_private = shell; |
Pekka Paalanen | 77346a6 | 2011-11-30 16:26:35 +0200 | [diff] [blame] | 5723 | surface->output = output; |
Pekka Paalanen | 6e16811 | 2011-11-24 11:34:05 +0200 | [diff] [blame] | 5724 | } |
| 5725 | |
| 5726 | static const struct screensaver_interface screensaver_implementation = { |
| 5727 | screensaver_set_surface |
| 5728 | }; |
| 5729 | |
| 5730 | static void |
| 5731 | unbind_screensaver(struct wl_resource *resource) |
| 5732 | { |
Jason Ekstrand | 651f00e | 2013-06-14 10:07:54 -0500 | [diff] [blame] | 5733 | struct desktop_shell *shell = wl_resource_get_user_data(resource); |
Pekka Paalanen | 6e16811 | 2011-11-24 11:34:05 +0200 | [diff] [blame] | 5734 | |
Pekka Paalanen | 77346a6 | 2011-11-30 16:26:35 +0200 | [diff] [blame] | 5735 | shell->screensaver.binding = NULL; |
Pekka Paalanen | 6e16811 | 2011-11-24 11:34:05 +0200 | [diff] [blame] | 5736 | } |
| 5737 | |
| 5738 | static void |
| 5739 | bind_screensaver(struct wl_client *client, |
| 5740 | void *data, uint32_t version, uint32_t id) |
| 5741 | { |
Tiago Vignatti | be14326 | 2012-04-16 17:31:41 +0300 | [diff] [blame] | 5742 | struct desktop_shell *shell = data; |
Pekka Paalanen | 6e16811 | 2011-11-24 11:34:05 +0200 | [diff] [blame] | 5743 | struct wl_resource *resource; |
| 5744 | |
Jason Ekstrand | a85118c | 2013-06-27 20:17:02 -0500 | [diff] [blame] | 5745 | resource = wl_resource_create(client, &screensaver_interface, 1, id); |
Pekka Paalanen | 6e16811 | 2011-11-24 11:34:05 +0200 | [diff] [blame] | 5746 | |
Pekka Paalanen | 77346a6 | 2011-11-30 16:26:35 +0200 | [diff] [blame] | 5747 | if (shell->screensaver.binding == NULL) { |
Jason Ekstrand | a85118c | 2013-06-27 20:17:02 -0500 | [diff] [blame] | 5748 | wl_resource_set_implementation(resource, |
| 5749 | &screensaver_implementation, |
| 5750 | shell, unbind_screensaver); |
Pekka Paalanen | 77346a6 | 2011-11-30 16:26:35 +0200 | [diff] [blame] | 5751 | shell->screensaver.binding = resource; |
Pekka Paalanen | 6e16811 | 2011-11-24 11:34:05 +0200 | [diff] [blame] | 5752 | return; |
| 5753 | } |
| 5754 | |
| 5755 | wl_resource_post_error(resource, WL_DISPLAY_ERROR_INVALID_OBJECT, |
| 5756 | "interface object already bound"); |
Pekka Paalanen | 6e16811 | 2011-11-24 11:34:05 +0200 | [diff] [blame] | 5757 | } |
| 5758 | |
Kristian Høgsberg | 0704539 | 2012-02-19 18:52:44 -0500 | [diff] [blame] | 5759 | struct switcher { |
Tiago Vignatti | be14326 | 2012-04-16 17:31:41 +0300 | [diff] [blame] | 5760 | struct desktop_shell *shell; |
Kristian Høgsberg | 0704539 | 2012-02-19 18:52:44 -0500 | [diff] [blame] | 5761 | struct weston_surface *current; |
| 5762 | struct wl_listener listener; |
Kristian Høgsberg | 29139d4 | 2013-04-18 15:25:39 -0400 | [diff] [blame] | 5763 | struct weston_keyboard_grab grab; |
Manuel Bachmann | c1ae2e8 | 2014-02-26 15:53:11 +0100 | [diff] [blame] | 5764 | struct wl_array minimized_array; |
Kristian Høgsberg | 0704539 | 2012-02-19 18:52:44 -0500 | [diff] [blame] | 5765 | }; |
| 5766 | |
| 5767 | static void |
| 5768 | switcher_next(struct switcher *switcher) |
| 5769 | { |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 5770 | struct weston_view *view; |
Kristian Høgsberg | 0704539 | 2012-02-19 18:52:44 -0500 | [diff] [blame] | 5771 | struct weston_surface *first = NULL, *prev = NULL, *next = NULL; |
Kristian Høgsberg | 32e5686 | 2012-04-02 22:18:58 -0400 | [diff] [blame] | 5772 | struct shell_surface *shsurf; |
Kristian Høgsberg | b0d8e77 | 2012-06-18 16:34:58 -0400 | [diff] [blame] | 5773 | struct workspace *ws = get_current_workspace(switcher->shell); |
Kristian Høgsberg | 0704539 | 2012-02-19 18:52:44 -0500 | [diff] [blame] | 5774 | |
Manuel Bachmann | c1ae2e8 | 2014-02-26 15:53:11 +0100 | [diff] [blame] | 5775 | /* temporary re-display minimized surfaces */ |
| 5776 | struct weston_view *tmp; |
| 5777 | struct weston_view **minimized; |
Giulio Camuffo | 412e6a5 | 2014-07-09 22:12:56 +0300 | [diff] [blame] | 5778 | wl_list_for_each_safe(view, tmp, &switcher->shell->minimized_layer.view_list.link, layer_link.link) { |
| 5779 | weston_layer_entry_remove(&view->layer_link); |
| 5780 | weston_layer_entry_insert(&ws->layer.view_list, &view->layer_link); |
Manuel Bachmann | c1ae2e8 | 2014-02-26 15:53:11 +0100 | [diff] [blame] | 5781 | minimized = wl_array_add(&switcher->minimized_array, sizeof *minimized); |
| 5782 | *minimized = view; |
| 5783 | } |
| 5784 | |
Giulio Camuffo | 412e6a5 | 2014-07-09 22:12:56 +0300 | [diff] [blame] | 5785 | 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] | 5786 | shsurf = get_shell_surface(view->surface); |
Rafael Antognolli | 5031cbe | 2013-12-05 19:01:21 -0200 | [diff] [blame] | 5787 | if (shsurf && |
| 5788 | shsurf->type == SHELL_SURFACE_TOPLEVEL && |
| 5789 | shsurf->parent == NULL) { |
Kristian Høgsberg | 0704539 | 2012-02-19 18:52:44 -0500 | [diff] [blame] | 5790 | if (first == NULL) |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 5791 | first = view->surface; |
Kristian Høgsberg | 0704539 | 2012-02-19 18:52:44 -0500 | [diff] [blame] | 5792 | if (prev == switcher->current) |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 5793 | next = view->surface; |
| 5794 | prev = view->surface; |
| 5795 | view->alpha = 0.25; |
| 5796 | weston_view_geometry_dirty(view); |
| 5797 | weston_surface_damage(view->surface); |
Kristian Høgsberg | 0704539 | 2012-02-19 18:52:44 -0500 | [diff] [blame] | 5798 | } |
Alex Wu | 1659daa | 2012-04-01 20:13:09 +0800 | [diff] [blame] | 5799 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 5800 | if (is_black_surface(view->surface, NULL)) { |
| 5801 | view->alpha = 0.25; |
| 5802 | weston_view_geometry_dirty(view); |
| 5803 | weston_surface_damage(view->surface); |
Alex Wu | 1659daa | 2012-04-01 20:13:09 +0800 | [diff] [blame] | 5804 | } |
Kristian Høgsberg | 0704539 | 2012-02-19 18:52:44 -0500 | [diff] [blame] | 5805 | } |
| 5806 | |
| 5807 | if (next == NULL) |
| 5808 | next = first; |
| 5809 | |
Alex Wu | 07b2606 | 2012-03-12 16:06:01 +0800 | [diff] [blame] | 5810 | if (next == NULL) |
| 5811 | return; |
| 5812 | |
Kristian Høgsberg | 0704539 | 2012-02-19 18:52:44 -0500 | [diff] [blame] | 5813 | wl_list_remove(&switcher->listener.link); |
Jason Ekstrand | 26ed73c | 2013-06-06 22:34:41 -0500 | [diff] [blame] | 5814 | wl_signal_add(&next->destroy_signal, &switcher->listener); |
Kristian Høgsberg | 0704539 | 2012-02-19 18:52:44 -0500 | [diff] [blame] | 5815 | |
| 5816 | switcher->current = next; |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 5817 | wl_list_for_each(view, &next->views, surface_link) |
| 5818 | view->alpha = 1.0; |
Alex Wu | 1659daa | 2012-04-01 20:13:09 +0800 | [diff] [blame] | 5819 | |
Kristian Høgsberg | 32e5686 | 2012-04-02 22:18:58 -0400 | [diff] [blame] | 5820 | shsurf = get_shell_surface(switcher->current); |
Rafael Antognolli | 03b1659 | 2013-12-03 15:35:42 -0200 | [diff] [blame] | 5821 | if (shsurf && shsurf->state.fullscreen) |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 5822 | shsurf->fullscreen.black_view->alpha = 1.0; |
Kristian Høgsberg | 0704539 | 2012-02-19 18:52:44 -0500 | [diff] [blame] | 5823 | } |
| 5824 | |
| 5825 | static void |
Kristian Høgsberg | 27e3052 | 2012-04-11 23:18:23 -0400 | [diff] [blame] | 5826 | switcher_handle_surface_destroy(struct wl_listener *listener, void *data) |
Kristian Høgsberg | 0704539 | 2012-02-19 18:52:44 -0500 | [diff] [blame] | 5827 | { |
| 5828 | struct switcher *switcher = |
| 5829 | container_of(listener, struct switcher, listener); |
| 5830 | |
| 5831 | switcher_next(switcher); |
| 5832 | } |
| 5833 | |
| 5834 | static void |
Daniel Stone | 351eb61 | 2012-05-31 15:27:47 -0400 | [diff] [blame] | 5835 | switcher_destroy(struct switcher *switcher) |
Kristian Høgsberg | 0704539 | 2012-02-19 18:52:44 -0500 | [diff] [blame] | 5836 | { |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 5837 | struct weston_view *view; |
Kristian Høgsberg | 29139d4 | 2013-04-18 15:25:39 -0400 | [diff] [blame] | 5838 | struct weston_keyboard *keyboard = switcher->grab.keyboard; |
Kristian Høgsberg | b0d8e77 | 2012-06-18 16:34:58 -0400 | [diff] [blame] | 5839 | struct workspace *ws = get_current_workspace(switcher->shell); |
Kristian Høgsberg | 0704539 | 2012-02-19 18:52:44 -0500 | [diff] [blame] | 5840 | |
Giulio Camuffo | 412e6a5 | 2014-07-09 22:12:56 +0300 | [diff] [blame] | 5841 | 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] | 5842 | if (is_focus_view(view)) |
| 5843 | continue; |
| 5844 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 5845 | view->alpha = 1.0; |
| 5846 | weston_surface_damage(view->surface); |
Kristian Høgsberg | 0704539 | 2012-02-19 18:52:44 -0500 | [diff] [blame] | 5847 | } |
| 5848 | |
Alex Wu | 07b2606 | 2012-03-12 16:06:01 +0800 | [diff] [blame] | 5849 | if (switcher->current) |
Daniel Stone | 37816df | 2012-05-16 18:45:18 +0100 | [diff] [blame] | 5850 | activate(switcher->shell, switcher->current, |
Emilio Pozuelo Monfort | 9e7c759 | 2014-01-30 14:01:10 +0100 | [diff] [blame] | 5851 | (struct weston_seat *) keyboard->seat, true); |
Kristian Høgsberg | 0704539 | 2012-02-19 18:52:44 -0500 | [diff] [blame] | 5852 | wl_list_remove(&switcher->listener.link); |
Kristian Høgsberg | 29139d4 | 2013-04-18 15:25:39 -0400 | [diff] [blame] | 5853 | weston_keyboard_end_grab(keyboard); |
| 5854 | if (keyboard->input_method_resource) |
| 5855 | keyboard->grab = &keyboard->input_method_grab; |
Manuel Bachmann | c1ae2e8 | 2014-02-26 15:53:11 +0100 | [diff] [blame] | 5856 | |
| 5857 | /* re-hide surfaces that were temporary shown during the switch */ |
| 5858 | struct weston_view **minimized; |
| 5859 | wl_array_for_each(minimized, &switcher->minimized_array) { |
| 5860 | /* with the exception of the current selected */ |
| 5861 | if ((*minimized)->surface != switcher->current) { |
Giulio Camuffo | 412e6a5 | 2014-07-09 22:12:56 +0300 | [diff] [blame] | 5862 | weston_layer_entry_remove(&(*minimized)->layer_link); |
| 5863 | 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] | 5864 | weston_view_damage_below(*minimized); |
| 5865 | } |
| 5866 | } |
| 5867 | wl_array_release(&switcher->minimized_array); |
| 5868 | |
Kristian Høgsberg | 0704539 | 2012-02-19 18:52:44 -0500 | [diff] [blame] | 5869 | free(switcher); |
| 5870 | } |
| 5871 | |
| 5872 | static void |
Kristian Høgsberg | 29139d4 | 2013-04-18 15:25:39 -0400 | [diff] [blame] | 5873 | switcher_key(struct weston_keyboard_grab *grab, |
Daniel Stone | c9785ea | 2012-05-30 16:31:52 +0100 | [diff] [blame] | 5874 | uint32_t time, uint32_t key, uint32_t state_w) |
Kristian Høgsberg | 0704539 | 2012-02-19 18:52:44 -0500 | [diff] [blame] | 5875 | { |
| 5876 | struct switcher *switcher = container_of(grab, struct switcher, grab); |
Daniel Stone | c9785ea | 2012-05-30 16:31:52 +0100 | [diff] [blame] | 5877 | enum wl_keyboard_key_state state = state_w; |
Daniel Stone | 351eb61 | 2012-05-31 15:27:47 -0400 | [diff] [blame] | 5878 | |
Daniel Stone | c9785ea | 2012-05-30 16:31:52 +0100 | [diff] [blame] | 5879 | if (key == KEY_TAB && state == WL_KEYBOARD_KEY_STATE_PRESSED) |
Daniel Stone | 351eb61 | 2012-05-31 15:27:47 -0400 | [diff] [blame] | 5880 | switcher_next(switcher); |
| 5881 | } |
| 5882 | |
| 5883 | static void |
Kristian Høgsberg | 29139d4 | 2013-04-18 15:25:39 -0400 | [diff] [blame] | 5884 | switcher_modifier(struct weston_keyboard_grab *grab, uint32_t serial, |
Daniel Stone | 351eb61 | 2012-05-31 15:27:47 -0400 | [diff] [blame] | 5885 | uint32_t mods_depressed, uint32_t mods_latched, |
| 5886 | uint32_t mods_locked, uint32_t group) |
| 5887 | { |
| 5888 | struct switcher *switcher = container_of(grab, struct switcher, grab); |
Daniel Stone | 37816df | 2012-05-16 18:45:18 +0100 | [diff] [blame] | 5889 | struct weston_seat *seat = (struct weston_seat *) grab->keyboard->seat; |
Kristian Høgsberg | 0704539 | 2012-02-19 18:52:44 -0500 | [diff] [blame] | 5890 | |
Daniel Stone | 351eb61 | 2012-05-31 15:27:47 -0400 | [diff] [blame] | 5891 | if ((seat->modifier_state & switcher->shell->binding_modifier) == 0) |
| 5892 | switcher_destroy(switcher); |
Kristian Høgsberg | b71302e | 2012-05-10 12:28:35 -0400 | [diff] [blame] | 5893 | } |
Kristian Høgsberg | 0704539 | 2012-02-19 18:52:44 -0500 | [diff] [blame] | 5894 | |
Jonas Ådahl | 1ea343e | 2013-10-25 23:18:05 +0200 | [diff] [blame] | 5895 | static void |
| 5896 | switcher_cancel(struct weston_keyboard_grab *grab) |
| 5897 | { |
| 5898 | struct switcher *switcher = container_of(grab, struct switcher, grab); |
| 5899 | |
| 5900 | switcher_destroy(switcher); |
| 5901 | } |
| 5902 | |
Kristian Høgsberg | 29139d4 | 2013-04-18 15:25:39 -0400 | [diff] [blame] | 5903 | static const struct weston_keyboard_grab_interface switcher_grab = { |
Daniel Stone | 351eb61 | 2012-05-31 15:27:47 -0400 | [diff] [blame] | 5904 | switcher_key, |
| 5905 | switcher_modifier, |
Jonas Ådahl | 1ea343e | 2013-10-25 23:18:05 +0200 | [diff] [blame] | 5906 | switcher_cancel, |
Kristian Høgsberg | 0704539 | 2012-02-19 18:52:44 -0500 | [diff] [blame] | 5907 | }; |
| 5908 | |
| 5909 | static void |
Kristian Høgsberg | e314875 | 2013-05-06 23:19:49 -0400 | [diff] [blame] | 5910 | switcher_binding(struct weston_seat *seat, uint32_t time, uint32_t key, |
Daniel Stone | 325fc2d | 2012-05-30 16:31:58 +0100 | [diff] [blame] | 5911 | void *data) |
Kristian Høgsberg | 0704539 | 2012-02-19 18:52:44 -0500 | [diff] [blame] | 5912 | { |
Tiago Vignatti | be14326 | 2012-04-16 17:31:41 +0300 | [diff] [blame] | 5913 | struct desktop_shell *shell = data; |
Kristian Høgsberg | 0704539 | 2012-02-19 18:52:44 -0500 | [diff] [blame] | 5914 | struct switcher *switcher; |
| 5915 | |
| 5916 | switcher = malloc(sizeof *switcher); |
Kristian Høgsberg | 02e79dc | 2012-04-12 09:55:26 -0400 | [diff] [blame] | 5917 | switcher->shell = shell; |
Kristian Høgsberg | 0704539 | 2012-02-19 18:52:44 -0500 | [diff] [blame] | 5918 | switcher->current = NULL; |
Kristian Høgsberg | 27e3052 | 2012-04-11 23:18:23 -0400 | [diff] [blame] | 5919 | switcher->listener.notify = switcher_handle_surface_destroy; |
Kristian Høgsberg | 0704539 | 2012-02-19 18:52:44 -0500 | [diff] [blame] | 5920 | wl_list_init(&switcher->listener.link); |
Manuel Bachmann | c1ae2e8 | 2014-02-26 15:53:11 +0100 | [diff] [blame] | 5921 | wl_array_init(&switcher->minimized_array); |
Kristian Høgsberg | 0704539 | 2012-02-19 18:52:44 -0500 | [diff] [blame] | 5922 | |
Alexander Larsson | f82b6ca | 2013-05-28 16:23:39 +0200 | [diff] [blame] | 5923 | restore_all_output_modes(shell->compositor); |
Kristian Høgsberg | b0d8e77 | 2012-06-18 16:34:58 -0400 | [diff] [blame] | 5924 | lower_fullscreen_layer(switcher->shell); |
Kristian Høgsberg | 0704539 | 2012-02-19 18:52:44 -0500 | [diff] [blame] | 5925 | switcher->grab.interface = &switcher_grab; |
Kristian Høgsberg | 29139d4 | 2013-04-18 15:25:39 -0400 | [diff] [blame] | 5926 | weston_keyboard_start_grab(seat->keyboard, &switcher->grab); |
| 5927 | weston_keyboard_set_focus(seat->keyboard, NULL); |
Kristian Høgsberg | 0704539 | 2012-02-19 18:52:44 -0500 | [diff] [blame] | 5928 | switcher_next(switcher); |
| 5929 | } |
| 5930 | |
Pekka Paalanen | 3c64723 | 2011-12-22 13:43:43 +0200 | [diff] [blame] | 5931 | static void |
Kristian Høgsberg | e314875 | 2013-05-06 23:19:49 -0400 | [diff] [blame] | 5932 | backlight_binding(struct weston_seat *seat, uint32_t time, uint32_t key, |
Daniel Stone | 325fc2d | 2012-05-30 16:31:58 +0100 | [diff] [blame] | 5933 | void *data) |
Tiago Vignatti | 8e53c7f | 2012-02-29 19:53:50 +0200 | [diff] [blame] | 5934 | { |
| 5935 | struct weston_compositor *compositor = data; |
| 5936 | struct weston_output *output; |
Tiago Vignatti | 5ab91ad | 2012-03-12 19:40:09 -0300 | [diff] [blame] | 5937 | long backlight_new = 0; |
Tiago Vignatti | 8e53c7f | 2012-02-29 19:53:50 +0200 | [diff] [blame] | 5938 | |
| 5939 | /* TODO: we're limiting to simple use cases, where we assume just |
| 5940 | * control on the primary display. We'd have to extend later if we |
| 5941 | * ever get support for setting backlights on random desktop LCD |
| 5942 | * panels though */ |
| 5943 | output = get_default_output(compositor); |
| 5944 | if (!output) |
| 5945 | return; |
| 5946 | |
| 5947 | if (!output->set_backlight) |
| 5948 | return; |
| 5949 | |
Tiago Vignatti | 5ab91ad | 2012-03-12 19:40:09 -0300 | [diff] [blame] | 5950 | if (key == KEY_F9 || key == KEY_BRIGHTNESSDOWN) |
| 5951 | backlight_new = output->backlight_current - 25; |
| 5952 | else if (key == KEY_F10 || key == KEY_BRIGHTNESSUP) |
| 5953 | backlight_new = output->backlight_current + 25; |
Tiago Vignatti | 8e53c7f | 2012-02-29 19:53:50 +0200 | [diff] [blame] | 5954 | |
Tiago Vignatti | 5ab91ad | 2012-03-12 19:40:09 -0300 | [diff] [blame] | 5955 | if (backlight_new < 5) |
| 5956 | backlight_new = 5; |
| 5957 | if (backlight_new > 255) |
| 5958 | backlight_new = 255; |
| 5959 | |
| 5960 | output->backlight_current = backlight_new; |
Tiago Vignatti | 8e53c7f | 2012-02-29 19:53:50 +0200 | [diff] [blame] | 5961 | output->set_backlight(output, output->backlight_current); |
| 5962 | } |
| 5963 | |
Ander Conselvan de Oliveira | c509d2b | 2012-11-08 17:20:45 +0200 | [diff] [blame] | 5964 | struct debug_binding_grab { |
Kristian Høgsberg | 29139d4 | 2013-04-18 15:25:39 -0400 | [diff] [blame] | 5965 | struct weston_keyboard_grab grab; |
Ander Conselvan de Oliveira | c509d2b | 2012-11-08 17:20:45 +0200 | [diff] [blame] | 5966 | struct weston_seat *seat; |
| 5967 | uint32_t key[2]; |
| 5968 | int key_released[2]; |
| 5969 | }; |
| 5970 | |
| 5971 | static void |
Kristian Høgsberg | 29139d4 | 2013-04-18 15:25:39 -0400 | [diff] [blame] | 5972 | debug_binding_key(struct weston_keyboard_grab *grab, uint32_t time, |
Ander Conselvan de Oliveira | c509d2b | 2012-11-08 17:20:45 +0200 | [diff] [blame] | 5973 | uint32_t key, uint32_t state) |
| 5974 | { |
| 5975 | struct debug_binding_grab *db = (struct debug_binding_grab *) grab; |
Rob Bradford | 880ebc7 | 2013-07-22 17:31:38 +0100 | [diff] [blame] | 5976 | struct weston_compositor *ec = db->seat->compositor; |
| 5977 | struct wl_display *display = ec->wl_display; |
Ander Conselvan de Oliveira | c509d2b | 2012-11-08 17:20:45 +0200 | [diff] [blame] | 5978 | struct wl_resource *resource; |
Ander Conselvan de Oliveira | c509d2b | 2012-11-08 17:20:45 +0200 | [diff] [blame] | 5979 | uint32_t serial; |
| 5980 | int send = 0, terminate = 0; |
| 5981 | int check_binding = 1; |
| 5982 | int i; |
Neil Roberts | 96d790e | 2013-09-19 17:32:00 +0100 | [diff] [blame] | 5983 | struct wl_list *resource_list; |
Ander Conselvan de Oliveira | c509d2b | 2012-11-08 17:20:45 +0200 | [diff] [blame] | 5984 | |
| 5985 | if (state == WL_KEYBOARD_KEY_STATE_RELEASED) { |
| 5986 | /* Do not run bindings on key releases */ |
| 5987 | check_binding = 0; |
| 5988 | |
| 5989 | for (i = 0; i < 2; i++) |
| 5990 | if (key == db->key[i]) |
| 5991 | db->key_released[i] = 1; |
| 5992 | |
| 5993 | if (db->key_released[0] && db->key_released[1]) { |
| 5994 | /* All key releases been swalled so end the grab */ |
| 5995 | terminate = 1; |
| 5996 | } else if (key != db->key[0] && key != db->key[1]) { |
| 5997 | /* Should not swallow release of other keys */ |
| 5998 | send = 1; |
| 5999 | } |
| 6000 | } else if (key == db->key[0] && !db->key_released[0]) { |
| 6001 | /* Do not check bindings for the first press of the binding |
| 6002 | * key. This allows it to be used as a debug shortcut. |
| 6003 | * We still need to swallow this event. */ |
| 6004 | check_binding = 0; |
| 6005 | } else if (db->key[1]) { |
| 6006 | /* If we already ran a binding don't process another one since |
| 6007 | * we can't keep track of all the binding keys that were |
| 6008 | * pressed in order to swallow the release events. */ |
| 6009 | send = 1; |
| 6010 | check_binding = 0; |
| 6011 | } |
| 6012 | |
| 6013 | if (check_binding) { |
Ander Conselvan de Oliveira | c509d2b | 2012-11-08 17:20:45 +0200 | [diff] [blame] | 6014 | if (weston_compositor_run_debug_binding(ec, db->seat, time, |
| 6015 | key, state)) { |
| 6016 | /* We ran a binding so swallow the press and keep the |
| 6017 | * grab to swallow the released too. */ |
| 6018 | send = 0; |
| 6019 | terminate = 0; |
| 6020 | db->key[1] = key; |
| 6021 | } else { |
| 6022 | /* Terminate the grab since the key pressed is not a |
| 6023 | * debug binding key. */ |
| 6024 | send = 1; |
| 6025 | terminate = 1; |
| 6026 | } |
| 6027 | } |
| 6028 | |
| 6029 | if (send) { |
Neil Roberts | 96d790e | 2013-09-19 17:32:00 +0100 | [diff] [blame] | 6030 | serial = wl_display_next_serial(display); |
| 6031 | resource_list = &grab->keyboard->focus_resource_list; |
| 6032 | wl_resource_for_each(resource, resource_list) { |
Ander Conselvan de Oliveira | c509d2b | 2012-11-08 17:20:45 +0200 | [diff] [blame] | 6033 | wl_keyboard_send_key(resource, serial, time, key, state); |
| 6034 | } |
| 6035 | } |
| 6036 | |
| 6037 | if (terminate) { |
Kristian Høgsberg | 29139d4 | 2013-04-18 15:25:39 -0400 | [diff] [blame] | 6038 | weston_keyboard_end_grab(grab->keyboard); |
| 6039 | if (grab->keyboard->input_method_resource) |
| 6040 | grab->keyboard->grab = &grab->keyboard->input_method_grab; |
Ander Conselvan de Oliveira | c509d2b | 2012-11-08 17:20:45 +0200 | [diff] [blame] | 6041 | free(db); |
| 6042 | } |
| 6043 | } |
| 6044 | |
| 6045 | static void |
Kristian Høgsberg | 29139d4 | 2013-04-18 15:25:39 -0400 | [diff] [blame] | 6046 | debug_binding_modifiers(struct weston_keyboard_grab *grab, uint32_t serial, |
Ander Conselvan de Oliveira | c509d2b | 2012-11-08 17:20:45 +0200 | [diff] [blame] | 6047 | uint32_t mods_depressed, uint32_t mods_latched, |
| 6048 | uint32_t mods_locked, uint32_t group) |
| 6049 | { |
| 6050 | struct wl_resource *resource; |
Neil Roberts | 96d790e | 2013-09-19 17:32:00 +0100 | [diff] [blame] | 6051 | struct wl_list *resource_list; |
Ander Conselvan de Oliveira | c509d2b | 2012-11-08 17:20:45 +0200 | [diff] [blame] | 6052 | |
Neil Roberts | 96d790e | 2013-09-19 17:32:00 +0100 | [diff] [blame] | 6053 | resource_list = &grab->keyboard->focus_resource_list; |
Ander Conselvan de Oliveira | c509d2b | 2012-11-08 17:20:45 +0200 | [diff] [blame] | 6054 | |
Neil Roberts | 96d790e | 2013-09-19 17:32:00 +0100 | [diff] [blame] | 6055 | wl_resource_for_each(resource, resource_list) { |
| 6056 | wl_keyboard_send_modifiers(resource, serial, mods_depressed, |
| 6057 | mods_latched, mods_locked, group); |
| 6058 | } |
Ander Conselvan de Oliveira | c509d2b | 2012-11-08 17:20:45 +0200 | [diff] [blame] | 6059 | } |
| 6060 | |
Jonas Ådahl | 1ea343e | 2013-10-25 23:18:05 +0200 | [diff] [blame] | 6061 | static void |
| 6062 | debug_binding_cancel(struct weston_keyboard_grab *grab) |
| 6063 | { |
| 6064 | struct debug_binding_grab *db = (struct debug_binding_grab *) grab; |
| 6065 | |
| 6066 | weston_keyboard_end_grab(grab->keyboard); |
| 6067 | free(db); |
| 6068 | } |
| 6069 | |
Kristian Høgsberg | 29139d4 | 2013-04-18 15:25:39 -0400 | [diff] [blame] | 6070 | struct weston_keyboard_grab_interface debug_binding_keyboard_grab = { |
Ander Conselvan de Oliveira | c509d2b | 2012-11-08 17:20:45 +0200 | [diff] [blame] | 6071 | debug_binding_key, |
Jonas Ådahl | 1ea343e | 2013-10-25 23:18:05 +0200 | [diff] [blame] | 6072 | debug_binding_modifiers, |
| 6073 | debug_binding_cancel, |
Ander Conselvan de Oliveira | c509d2b | 2012-11-08 17:20:45 +0200 | [diff] [blame] | 6074 | }; |
| 6075 | |
| 6076 | static void |
Kristian Høgsberg | e314875 | 2013-05-06 23:19:49 -0400 | [diff] [blame] | 6077 | debug_binding(struct weston_seat *seat, uint32_t time, uint32_t key, void *data) |
Ander Conselvan de Oliveira | c509d2b | 2012-11-08 17:20:45 +0200 | [diff] [blame] | 6078 | { |
| 6079 | struct debug_binding_grab *grab; |
| 6080 | |
| 6081 | grab = calloc(1, sizeof *grab); |
| 6082 | if (!grab) |
| 6083 | return; |
| 6084 | |
| 6085 | grab->seat = (struct weston_seat *) seat; |
| 6086 | grab->key[0] = key; |
| 6087 | grab->grab.interface = &debug_binding_keyboard_grab; |
Kristian Høgsberg | 29139d4 | 2013-04-18 15:25:39 -0400 | [diff] [blame] | 6088 | weston_keyboard_start_grab(seat->keyboard, &grab->grab); |
Ander Conselvan de Oliveira | c509d2b | 2012-11-08 17:20:45 +0200 | [diff] [blame] | 6089 | } |
| 6090 | |
Kristian Høgsberg | b41c081 | 2012-03-04 14:53:40 -0500 | [diff] [blame] | 6091 | static void |
Kristian Høgsberg | e314875 | 2013-05-06 23:19:49 -0400 | [diff] [blame] | 6092 | force_kill_binding(struct weston_seat *seat, uint32_t time, uint32_t key, |
Daniel Stone | 325fc2d | 2012-05-30 16:31:58 +0100 | [diff] [blame] | 6093 | void *data) |
Kristian Høgsberg | 92a57db | 2012-05-26 13:41:06 -0400 | [diff] [blame] | 6094 | { |
Kristian Høgsberg | fe7aa90 | 2013-05-08 09:54:37 -0400 | [diff] [blame] | 6095 | struct weston_surface *focus_surface; |
Kristian Høgsberg | 92a57db | 2012-05-26 13:41:06 -0400 | [diff] [blame] | 6096 | struct wl_client *client; |
Tiago Vignatti | 1d01b01 | 2012-09-27 17:48:36 +0300 | [diff] [blame] | 6097 | struct desktop_shell *shell = data; |
| 6098 | struct weston_compositor *compositor = shell->compositor; |
Kristian Høgsberg | 92a57db | 2012-05-26 13:41:06 -0400 | [diff] [blame] | 6099 | pid_t pid; |
Kristian Høgsberg | 92a57db | 2012-05-26 13:41:06 -0400 | [diff] [blame] | 6100 | |
Philipp Brüschweiler | 6cef009 | 2012-08-13 21:27:27 +0200 | [diff] [blame] | 6101 | focus_surface = seat->keyboard->focus; |
| 6102 | if (!focus_surface) |
| 6103 | return; |
| 6104 | |
Tiago Vignatti | 1d01b01 | 2012-09-27 17:48:36 +0300 | [diff] [blame] | 6105 | wl_signal_emit(&compositor->kill_signal, focus_surface); |
| 6106 | |
Jason Ekstrand | 26ed73c | 2013-06-06 22:34:41 -0500 | [diff] [blame] | 6107 | client = wl_resource_get_client(focus_surface->resource); |
Tiago Vignatti | 920f197 | 2012-09-27 17:48:35 +0300 | [diff] [blame] | 6108 | wl_client_get_credentials(client, &pid, NULL, NULL); |
| 6109 | |
| 6110 | /* Skip clients that we launched ourselves (the credentials of |
| 6111 | * the socketpair is ours) */ |
| 6112 | if (pid == getpid()) |
| 6113 | return; |
Kristian Høgsberg | 92a57db | 2012-05-26 13:41:06 -0400 | [diff] [blame] | 6114 | |
Daniel Stone | 325fc2d | 2012-05-30 16:31:58 +0100 | [diff] [blame] | 6115 | kill(pid, SIGKILL); |
Kristian Høgsberg | 92a57db | 2012-05-26 13:41:06 -0400 | [diff] [blame] | 6116 | } |
| 6117 | |
| 6118 | static void |
Kristian Høgsberg | e314875 | 2013-05-06 23:19:49 -0400 | [diff] [blame] | 6119 | workspace_up_binding(struct weston_seat *seat, uint32_t time, |
Jonas Ådahl | e3cddce | 2012-06-13 00:01:22 +0200 | [diff] [blame] | 6120 | uint32_t key, void *data) |
| 6121 | { |
| 6122 | struct desktop_shell *shell = data; |
| 6123 | unsigned int new_index = shell->workspaces.current; |
| 6124 | |
Kristian Høgsberg | ce345b0 | 2012-06-25 21:35:29 -0400 | [diff] [blame] | 6125 | if (shell->locked) |
Kristian Høgsberg | 4476aaf | 2012-06-25 14:03:13 -0400 | [diff] [blame] | 6126 | return; |
Jonas Ådahl | e3cddce | 2012-06-13 00:01:22 +0200 | [diff] [blame] | 6127 | if (new_index != 0) |
| 6128 | new_index--; |
| 6129 | |
| 6130 | change_workspace(shell, new_index); |
| 6131 | } |
| 6132 | |
| 6133 | static void |
Kristian Høgsberg | e314875 | 2013-05-06 23:19:49 -0400 | [diff] [blame] | 6134 | workspace_down_binding(struct weston_seat *seat, uint32_t time, |
Jonas Ådahl | e3cddce | 2012-06-13 00:01:22 +0200 | [diff] [blame] | 6135 | uint32_t key, void *data) |
| 6136 | { |
| 6137 | struct desktop_shell *shell = data; |
| 6138 | unsigned int new_index = shell->workspaces.current; |
| 6139 | |
Kristian Høgsberg | ce345b0 | 2012-06-25 21:35:29 -0400 | [diff] [blame] | 6140 | if (shell->locked) |
Kristian Høgsberg | 4476aaf | 2012-06-25 14:03:13 -0400 | [diff] [blame] | 6141 | return; |
Jonas Ådahl | e3cddce | 2012-06-13 00:01:22 +0200 | [diff] [blame] | 6142 | if (new_index < shell->workspaces.num - 1) |
| 6143 | new_index++; |
| 6144 | |
| 6145 | change_workspace(shell, new_index); |
| 6146 | } |
| 6147 | |
| 6148 | static void |
Kristian Høgsberg | e314875 | 2013-05-06 23:19:49 -0400 | [diff] [blame] | 6149 | workspace_f_binding(struct weston_seat *seat, uint32_t time, |
Jonas Ådahl | e3cddce | 2012-06-13 00:01:22 +0200 | [diff] [blame] | 6150 | uint32_t key, void *data) |
| 6151 | { |
| 6152 | struct desktop_shell *shell = data; |
| 6153 | unsigned int new_index; |
| 6154 | |
Kristian Høgsberg | ce345b0 | 2012-06-25 21:35:29 -0400 | [diff] [blame] | 6155 | if (shell->locked) |
Kristian Høgsberg | 4476aaf | 2012-06-25 14:03:13 -0400 | [diff] [blame] | 6156 | return; |
Jonas Ådahl | e3cddce | 2012-06-13 00:01:22 +0200 | [diff] [blame] | 6157 | new_index = key - KEY_F1; |
| 6158 | if (new_index >= shell->workspaces.num) |
| 6159 | new_index = shell->workspaces.num - 1; |
| 6160 | |
| 6161 | change_workspace(shell, new_index); |
| 6162 | } |
| 6163 | |
Jonas Ådahl | 8de6a1d | 2012-08-29 22:13:00 +0200 | [diff] [blame] | 6164 | static void |
Kristian Høgsberg | e314875 | 2013-05-06 23:19:49 -0400 | [diff] [blame] | 6165 | workspace_move_surface_up_binding(struct weston_seat *seat, uint32_t time, |
Jonas Ådahl | 8de6a1d | 2012-08-29 22:13:00 +0200 | [diff] [blame] | 6166 | uint32_t key, void *data) |
| 6167 | { |
| 6168 | struct desktop_shell *shell = data; |
| 6169 | unsigned int new_index = shell->workspaces.current; |
| 6170 | |
| 6171 | if (shell->locked) |
| 6172 | return; |
| 6173 | |
| 6174 | if (new_index != 0) |
| 6175 | new_index--; |
| 6176 | |
| 6177 | take_surface_to_workspace_by_seat(shell, seat, new_index); |
| 6178 | } |
| 6179 | |
| 6180 | static void |
Kristian Høgsberg | e314875 | 2013-05-06 23:19:49 -0400 | [diff] [blame] | 6181 | workspace_move_surface_down_binding(struct weston_seat *seat, uint32_t time, |
Jonas Ådahl | 8de6a1d | 2012-08-29 22:13:00 +0200 | [diff] [blame] | 6182 | uint32_t key, void *data) |
| 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 < shell->workspaces.num - 1) |
| 6191 | new_index++; |
| 6192 | |
| 6193 | take_surface_to_workspace_by_seat(shell, seat, new_index); |
| 6194 | } |
Jonas Ådahl | e3cddce | 2012-06-13 00:01:22 +0200 | [diff] [blame] | 6195 | |
| 6196 | static void |
Ander Conselvan de Oliveira | c94d622 | 2014-01-29 18:47:54 +0200 | [diff] [blame] | 6197 | shell_reposition_view_on_output_destroy(struct weston_view *view) |
| 6198 | { |
| 6199 | struct weston_output *output, *first_output; |
| 6200 | struct weston_compositor *ec = view->surface->compositor; |
| 6201 | struct shell_surface *shsurf; |
| 6202 | float x, y; |
| 6203 | int visible; |
| 6204 | |
| 6205 | x = view->geometry.x; |
| 6206 | y = view->geometry.y; |
| 6207 | |
| 6208 | /* At this point the destroyed output is not in the list anymore. |
| 6209 | * If the view is still visible somewhere, we leave where it is, |
| 6210 | * otherwise, move it to the first output. */ |
| 6211 | visible = 0; |
| 6212 | wl_list_for_each(output, &ec->output_list, link) { |
| 6213 | if (pixman_region32_contains_point(&output->region, |
| 6214 | x, y, NULL)) { |
| 6215 | visible = 1; |
| 6216 | break; |
| 6217 | } |
| 6218 | } |
| 6219 | |
| 6220 | if (!visible) { |
| 6221 | first_output = container_of(ec->output_list.next, |
| 6222 | struct weston_output, link); |
| 6223 | |
| 6224 | x = first_output->x + first_output->width / 4; |
| 6225 | y = first_output->y + first_output->height / 4; |
Xiong Zhang | 62899f5 | 2014-03-07 16:27:19 +0800 | [diff] [blame] | 6226 | |
| 6227 | weston_view_set_position(view, x, y); |
| 6228 | } else { |
| 6229 | weston_view_geometry_dirty(view); |
Ander Conselvan de Oliveira | c94d622 | 2014-01-29 18:47:54 +0200 | [diff] [blame] | 6230 | } |
| 6231 | |
Ander Conselvan de Oliveira | c94d622 | 2014-01-29 18:47:54 +0200 | [diff] [blame] | 6232 | |
| 6233 | shsurf = get_shell_surface(view->surface); |
| 6234 | |
| 6235 | if (shsurf) { |
| 6236 | shsurf->saved_position_valid = false; |
| 6237 | shsurf->next_state.maximized = false; |
| 6238 | shsurf->next_state.fullscreen = false; |
| 6239 | shsurf->state_changed = true; |
| 6240 | } |
| 6241 | } |
| 6242 | |
Ander Conselvan de Oliveira | 304996d | 2014-04-11 13:57:15 +0300 | [diff] [blame] | 6243 | void |
| 6244 | shell_for_each_layer(struct desktop_shell *shell, |
| 6245 | shell_for_each_layer_func_t func, void *data) |
Ander Conselvan de Oliveira | c94d622 | 2014-01-29 18:47:54 +0200 | [diff] [blame] | 6246 | { |
Ander Conselvan de Oliveira | 304996d | 2014-04-11 13:57:15 +0300 | [diff] [blame] | 6247 | struct workspace **ws; |
| 6248 | |
| 6249 | func(shell, &shell->fullscreen_layer, data); |
| 6250 | func(shell, &shell->panel_layer, data); |
| 6251 | func(shell, &shell->background_layer, data); |
| 6252 | func(shell, &shell->lock_layer, data); |
| 6253 | func(shell, &shell->input_panel_layer, data); |
| 6254 | |
| 6255 | wl_array_for_each(ws, &shell->workspaces.array) |
| 6256 | func(shell, &(*ws)->layer, data); |
| 6257 | } |
| 6258 | |
| 6259 | static void |
| 6260 | shell_output_destroy_move_layer(struct desktop_shell *shell, |
| 6261 | struct weston_layer *layer, |
| 6262 | void *data) |
| 6263 | { |
| 6264 | struct weston_output *output = data; |
Ander Conselvan de Oliveira | c94d622 | 2014-01-29 18:47:54 +0200 | [diff] [blame] | 6265 | struct weston_view *view; |
| 6266 | |
Giulio Camuffo | 412e6a5 | 2014-07-09 22:12:56 +0300 | [diff] [blame] | 6267 | 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] | 6268 | if (view->output != output) |
| 6269 | continue; |
Ander Conselvan de Oliveira | c94d622 | 2014-01-29 18:47:54 +0200 | [diff] [blame] | 6270 | |
Ander Conselvan de Oliveira | 304996d | 2014-04-11 13:57:15 +0300 | [diff] [blame] | 6271 | shell_reposition_view_on_output_destroy(view); |
Ander Conselvan de Oliveira | c94d622 | 2014-01-29 18:47:54 +0200 | [diff] [blame] | 6272 | } |
| 6273 | } |
| 6274 | |
| 6275 | static void |
Xiong Zhang | 6b48142 | 2013-10-23 13:58:32 +0800 | [diff] [blame] | 6276 | handle_output_destroy(struct wl_listener *listener, void *data) |
| 6277 | { |
| 6278 | struct shell_output *output_listener = |
| 6279 | container_of(listener, struct shell_output, destroy_listener); |
Ander Conselvan de Oliveira | 304996d | 2014-04-11 13:57:15 +0300 | [diff] [blame] | 6280 | struct weston_output *output = output_listener->output; |
| 6281 | struct desktop_shell *shell = output_listener->shell; |
Xiong Zhang | 6b48142 | 2013-10-23 13:58:32 +0800 | [diff] [blame] | 6282 | |
Ander Conselvan de Oliveira | 304996d | 2014-04-11 13:57:15 +0300 | [diff] [blame] | 6283 | 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] | 6284 | |
Xiong Zhang | 6b48142 | 2013-10-23 13:58:32 +0800 | [diff] [blame] | 6285 | wl_list_remove(&output_listener->destroy_listener.link); |
| 6286 | wl_list_remove(&output_listener->link); |
| 6287 | free(output_listener); |
| 6288 | } |
| 6289 | |
| 6290 | static void |
| 6291 | create_shell_output(struct desktop_shell *shell, |
| 6292 | struct weston_output *output) |
| 6293 | { |
| 6294 | struct shell_output *shell_output; |
| 6295 | |
| 6296 | shell_output = zalloc(sizeof *shell_output); |
| 6297 | if (shell_output == NULL) |
| 6298 | return; |
| 6299 | |
| 6300 | shell_output->output = output; |
| 6301 | shell_output->shell = shell; |
| 6302 | shell_output->destroy_listener.notify = handle_output_destroy; |
| 6303 | wl_signal_add(&output->destroy_signal, |
| 6304 | &shell_output->destroy_listener); |
Kristian Høgsberg | a3a0e18 | 2013-10-23 23:36:04 -0700 | [diff] [blame] | 6305 | wl_list_insert(shell->output_list.prev, &shell_output->link); |
Xiong Zhang | 6b48142 | 2013-10-23 13:58:32 +0800 | [diff] [blame] | 6306 | } |
| 6307 | |
| 6308 | static void |
| 6309 | handle_output_create(struct wl_listener *listener, void *data) |
| 6310 | { |
| 6311 | struct desktop_shell *shell = |
| 6312 | container_of(listener, struct desktop_shell, output_create_listener); |
| 6313 | struct weston_output *output = (struct weston_output *)data; |
| 6314 | |
| 6315 | create_shell_output(shell, output); |
| 6316 | } |
| 6317 | |
| 6318 | static void |
Ander Conselvan de Oliveira | 304996d | 2014-04-11 13:57:15 +0300 | [diff] [blame] | 6319 | handle_output_move_layer(struct desktop_shell *shell, |
| 6320 | struct weston_layer *layer, void *data) |
Ander Conselvan de Oliveira | a8a9baf | 2014-01-29 18:47:52 +0200 | [diff] [blame] | 6321 | { |
Ander Conselvan de Oliveira | 304996d | 2014-04-11 13:57:15 +0300 | [diff] [blame] | 6322 | struct weston_output *output = data; |
Ander Conselvan de Oliveira | a8a9baf | 2014-01-29 18:47:52 +0200 | [diff] [blame] | 6323 | struct weston_view *view; |
| 6324 | float x, y; |
| 6325 | |
Giulio Camuffo | 412e6a5 | 2014-07-09 22:12:56 +0300 | [diff] [blame] | 6326 | 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] | 6327 | if (view->output != output) |
| 6328 | continue; |
| 6329 | |
| 6330 | x = view->geometry.x + output->move_x; |
| 6331 | y = view->geometry.y + output->move_y; |
| 6332 | weston_view_set_position(view, x, y); |
| 6333 | } |
| 6334 | } |
| 6335 | |
| 6336 | static void |
| 6337 | handle_output_move(struct wl_listener *listener, void *data) |
| 6338 | { |
| 6339 | struct desktop_shell *shell; |
| 6340 | |
Ander Conselvan de Oliveira | a8a9baf | 2014-01-29 18:47:52 +0200 | [diff] [blame] | 6341 | shell = container_of(listener, struct desktop_shell, |
| 6342 | output_move_listener); |
Ander Conselvan de Oliveira | a8a9baf | 2014-01-29 18:47:52 +0200 | [diff] [blame] | 6343 | |
Ander Conselvan de Oliveira | 304996d | 2014-04-11 13:57:15 +0300 | [diff] [blame] | 6344 | shell_for_each_layer(shell, handle_output_move_layer, data); |
Ander Conselvan de Oliveira | a8a9baf | 2014-01-29 18:47:52 +0200 | [diff] [blame] | 6345 | } |
| 6346 | |
| 6347 | static void |
Xiong Zhang | 6b48142 | 2013-10-23 13:58:32 +0800 | [diff] [blame] | 6348 | setup_output_destroy_handler(struct weston_compositor *ec, |
| 6349 | struct desktop_shell *shell) |
| 6350 | { |
| 6351 | struct weston_output *output; |
| 6352 | |
| 6353 | wl_list_init(&shell->output_list); |
| 6354 | wl_list_for_each(output, &ec->output_list, link) |
| 6355 | create_shell_output(shell, output); |
| 6356 | |
| 6357 | shell->output_create_listener.notify = handle_output_create; |
| 6358 | wl_signal_add(&ec->output_created_signal, |
| 6359 | &shell->output_create_listener); |
Ander Conselvan de Oliveira | a8a9baf | 2014-01-29 18:47:52 +0200 | [diff] [blame] | 6360 | |
| 6361 | shell->output_move_listener.notify = handle_output_move; |
| 6362 | wl_signal_add(&ec->output_moved_signal, &shell->output_move_listener); |
Xiong Zhang | 6b48142 | 2013-10-23 13:58:32 +0800 | [diff] [blame] | 6363 | } |
| 6364 | |
| 6365 | static void |
Kristian Høgsberg | 02e79dc | 2012-04-12 09:55:26 -0400 | [diff] [blame] | 6366 | shell_destroy(struct wl_listener *listener, void *data) |
Pekka Paalanen | 3c64723 | 2011-12-22 13:43:43 +0200 | [diff] [blame] | 6367 | { |
Tiago Vignatti | be14326 | 2012-04-16 17:31:41 +0300 | [diff] [blame] | 6368 | struct desktop_shell *shell = |
| 6369 | container_of(listener, struct desktop_shell, destroy_listener); |
Jonas Ådahl | e3cddce | 2012-06-13 00:01:22 +0200 | [diff] [blame] | 6370 | struct workspace **ws; |
Xiong Zhang | 6b48142 | 2013-10-23 13:58:32 +0800 | [diff] [blame] | 6371 | struct shell_output *shell_output, *tmp; |
Pekka Paalanen | 3c64723 | 2011-12-22 13:43:43 +0200 | [diff] [blame] | 6372 | |
Kristian Høgsberg | 17bccae | 2014-01-16 16:46:28 -0800 | [diff] [blame] | 6373 | /* Force state to unlocked so we don't try to fade */ |
| 6374 | shell->locked = false; |
Pekka Paalanen | 826dc14 | 2014-08-27 12:11:53 +0300 | [diff] [blame] | 6375 | |
| 6376 | if (shell->child.client) { |
| 6377 | /* disable respawn */ |
| 6378 | wl_list_remove(&shell->child.client_destroy_listener.link); |
Pekka Paalanen | 9cf5cc8 | 2012-01-02 16:00:24 +0200 | [diff] [blame] | 6379 | wl_client_destroy(shell->child.client); |
Pekka Paalanen | 826dc14 | 2014-08-27 12:11:53 +0300 | [diff] [blame] | 6380 | } |
Pekka Paalanen | 9cf5cc8 | 2012-01-02 16:00:24 +0200 | [diff] [blame] | 6381 | |
Ander Conselvan de Oliveira | a457563 | 2013-02-21 18:35:23 +0200 | [diff] [blame] | 6382 | wl_list_remove(&shell->idle_listener.link); |
| 6383 | wl_list_remove(&shell->wake_listener.link); |
Kristian Høgsberg | 677a5f5 | 2013-12-04 11:00:19 -0800 | [diff] [blame] | 6384 | |
| 6385 | input_panel_destroy(shell); |
Kristian Høgsberg | 88c1607 | 2012-05-16 08:04:19 -0400 | [diff] [blame] | 6386 | |
Xiong Zhang | 6b48142 | 2013-10-23 13:58:32 +0800 | [diff] [blame] | 6387 | wl_list_for_each_safe(shell_output, tmp, &shell->output_list, link) { |
| 6388 | wl_list_remove(&shell_output->destroy_listener.link); |
| 6389 | wl_list_remove(&shell_output->link); |
| 6390 | free(shell_output); |
| 6391 | } |
| 6392 | |
| 6393 | wl_list_remove(&shell->output_create_listener.link); |
Kristian Høgsberg | 6d50b0f | 2014-04-30 20:46:25 -0700 | [diff] [blame] | 6394 | wl_list_remove(&shell->output_move_listener.link); |
Xiong Zhang | 6b48142 | 2013-10-23 13:58:32 +0800 | [diff] [blame] | 6395 | |
Jonas Ådahl | e3cddce | 2012-06-13 00:01:22 +0200 | [diff] [blame] | 6396 | wl_array_for_each(ws, &shell->workspaces.array) |
| 6397 | workspace_destroy(*ws); |
| 6398 | wl_array_release(&shell->workspaces.array); |
| 6399 | |
Pekka Paalanen | 3c64723 | 2011-12-22 13:43:43 +0200 | [diff] [blame] | 6400 | free(shell->screensaver.path); |
Emilio Pozuelo Monfort | 46ce798 | 2013-11-20 13:22:29 +0100 | [diff] [blame] | 6401 | free(shell->client); |
Pekka Paalanen | 3c64723 | 2011-12-22 13:43:43 +0200 | [diff] [blame] | 6402 | free(shell); |
| 6403 | } |
| 6404 | |
Tiago Vignatti | 0b52d48 | 2012-04-20 18:54:25 +0300 | [diff] [blame] | 6405 | static void |
| 6406 | shell_add_bindings(struct weston_compositor *ec, struct desktop_shell *shell) |
| 6407 | { |
| 6408 | uint32_t mod; |
Jonas Ådahl | e3cddce | 2012-06-13 00:01:22 +0200 | [diff] [blame] | 6409 | int i, num_workspace_bindings; |
Tiago Vignatti | 0b52d48 | 2012-04-20 18:54:25 +0300 | [diff] [blame] | 6410 | |
| 6411 | /* fixed bindings */ |
Daniel Stone | 325fc2d | 2012-05-30 16:31:58 +0100 | [diff] [blame] | 6412 | weston_compositor_add_key_binding(ec, KEY_BACKSPACE, |
| 6413 | MODIFIER_CTRL | MODIFIER_ALT, |
| 6414 | terminate_binding, ec); |
| 6415 | weston_compositor_add_button_binding(ec, BTN_LEFT, 0, |
| 6416 | click_to_activate_binding, |
| 6417 | shell); |
Kristian Høgsberg | f0ce581 | 2014-04-07 11:52:17 -0700 | [diff] [blame] | 6418 | weston_compositor_add_button_binding(ec, BTN_RIGHT, 0, |
| 6419 | click_to_activate_binding, |
| 6420 | shell); |
Neil Roberts | a28c693 | 2013-10-03 16:43:04 +0100 | [diff] [blame] | 6421 | weston_compositor_add_touch_binding(ec, 0, |
| 6422 | touch_to_activate_binding, |
| 6423 | shell); |
Daniel Stone | 325fc2d | 2012-05-30 16:31:58 +0100 | [diff] [blame] | 6424 | weston_compositor_add_axis_binding(ec, WL_POINTER_AXIS_VERTICAL_SCROLL, |
| 6425 | MODIFIER_SUPER | MODIFIER_ALT, |
| 6426 | surface_opacity_binding, NULL); |
| 6427 | weston_compositor_add_axis_binding(ec, WL_POINTER_AXIS_VERTICAL_SCROLL, |
| 6428 | MODIFIER_SUPER, zoom_axis_binding, |
| 6429 | NULL); |
Tiago Vignatti | 0b52d48 | 2012-04-20 18:54:25 +0300 | [diff] [blame] | 6430 | |
| 6431 | /* configurable bindings */ |
| 6432 | mod = shell->binding_modifier; |
Daniel Stone | 325fc2d | 2012-05-30 16:31:58 +0100 | [diff] [blame] | 6433 | weston_compositor_add_key_binding(ec, KEY_PAGEUP, mod, |
| 6434 | zoom_key_binding, NULL); |
| 6435 | weston_compositor_add_key_binding(ec, KEY_PAGEDOWN, mod, |
| 6436 | zoom_key_binding, NULL); |
Kristian Høgsberg | 211b517 | 2014-01-11 13:10:21 -0800 | [diff] [blame] | 6437 | weston_compositor_add_key_binding(ec, KEY_M, mod | MODIFIER_SHIFT, |
| 6438 | maximize_binding, NULL); |
| 6439 | weston_compositor_add_key_binding(ec, KEY_F, mod | MODIFIER_SHIFT, |
| 6440 | fullscreen_binding, NULL); |
Daniel Stone | 325fc2d | 2012-05-30 16:31:58 +0100 | [diff] [blame] | 6441 | weston_compositor_add_button_binding(ec, BTN_LEFT, mod, move_binding, |
| 6442 | shell); |
Neil Roberts | aba0f25 | 2013-10-03 16:43:05 +0100 | [diff] [blame] | 6443 | weston_compositor_add_touch_binding(ec, mod, touch_move_binding, shell); |
Daniel Stone | 325fc2d | 2012-05-30 16:31:58 +0100 | [diff] [blame] | 6444 | weston_compositor_add_button_binding(ec, BTN_MIDDLE, mod, |
| 6445 | resize_binding, shell); |
Kristian Høgsberg | 0837fa9 | 2014-01-20 10:35:26 -0800 | [diff] [blame] | 6446 | weston_compositor_add_button_binding(ec, BTN_LEFT, |
| 6447 | mod | MODIFIER_SHIFT, |
| 6448 | resize_binding, shell); |
Pekka Paalanen | 7bb6510 | 2013-05-22 18:03:04 +0300 | [diff] [blame] | 6449 | |
| 6450 | if (ec->capabilities & WESTON_CAP_ROTATION_ANY) |
| 6451 | weston_compositor_add_button_binding(ec, BTN_RIGHT, mod, |
| 6452 | rotate_binding, NULL); |
| 6453 | |
Daniel Stone | 325fc2d | 2012-05-30 16:31:58 +0100 | [diff] [blame] | 6454 | weston_compositor_add_key_binding(ec, KEY_TAB, mod, switcher_binding, |
| 6455 | shell); |
| 6456 | weston_compositor_add_key_binding(ec, KEY_F9, mod, backlight_binding, |
| 6457 | ec); |
| 6458 | weston_compositor_add_key_binding(ec, KEY_BRIGHTNESSDOWN, 0, |
| 6459 | backlight_binding, ec); |
| 6460 | weston_compositor_add_key_binding(ec, KEY_F10, mod, backlight_binding, |
| 6461 | ec); |
| 6462 | weston_compositor_add_key_binding(ec, KEY_BRIGHTNESSUP, 0, |
| 6463 | backlight_binding, ec); |
Daniel Stone | 325fc2d | 2012-05-30 16:31:58 +0100 | [diff] [blame] | 6464 | weston_compositor_add_key_binding(ec, KEY_K, mod, |
| 6465 | force_kill_binding, shell); |
Jonas Ådahl | e3cddce | 2012-06-13 00:01:22 +0200 | [diff] [blame] | 6466 | weston_compositor_add_key_binding(ec, KEY_UP, mod, |
| 6467 | workspace_up_binding, shell); |
| 6468 | weston_compositor_add_key_binding(ec, KEY_DOWN, mod, |
| 6469 | workspace_down_binding, shell); |
Jonas Ådahl | 8de6a1d | 2012-08-29 22:13:00 +0200 | [diff] [blame] | 6470 | weston_compositor_add_key_binding(ec, KEY_UP, mod | MODIFIER_SHIFT, |
| 6471 | workspace_move_surface_up_binding, |
| 6472 | shell); |
| 6473 | weston_compositor_add_key_binding(ec, KEY_DOWN, mod | MODIFIER_SHIFT, |
| 6474 | workspace_move_surface_down_binding, |
| 6475 | shell); |
Jonas Ådahl | e3cddce | 2012-06-13 00:01:22 +0200 | [diff] [blame] | 6476 | |
Kristian Høgsberg | d56ab4e | 2014-01-16 16:51:52 -0800 | [diff] [blame] | 6477 | if (shell->exposay_modifier) |
| 6478 | weston_compositor_add_modifier_binding(ec, shell->exposay_modifier, |
| 6479 | exposay_binding, shell); |
Daniel Stone | df8133b | 2013-11-19 11:37:14 +0100 | [diff] [blame] | 6480 | |
Jonas Ådahl | e3cddce | 2012-06-13 00:01:22 +0200 | [diff] [blame] | 6481 | /* Add bindings for mod+F[1-6] for workspace 1 to 6. */ |
| 6482 | if (shell->workspaces.num > 1) { |
| 6483 | num_workspace_bindings = shell->workspaces.num; |
| 6484 | if (num_workspace_bindings > 6) |
| 6485 | num_workspace_bindings = 6; |
| 6486 | for (i = 0; i < num_workspace_bindings; i++) |
| 6487 | weston_compositor_add_key_binding(ec, KEY_F1 + i, mod, |
| 6488 | workspace_f_binding, |
| 6489 | shell); |
| 6490 | } |
Ander Conselvan de Oliveira | c509d2b | 2012-11-08 17:20:45 +0200 | [diff] [blame] | 6491 | |
| 6492 | /* Debug bindings */ |
| 6493 | weston_compositor_add_key_binding(ec, KEY_SPACE, mod | MODIFIER_SHIFT, |
| 6494 | debug_binding, shell); |
Tiago Vignatti | 0b52d48 | 2012-04-20 18:54:25 +0300 | [diff] [blame] | 6495 | } |
| 6496 | |
Jason Ekstrand | 024177c | 2014-04-21 19:42:58 -0500 | [diff] [blame] | 6497 | static void |
| 6498 | handle_seat_created(struct wl_listener *listener, void *data) |
| 6499 | { |
| 6500 | struct weston_seat *seat = data; |
| 6501 | |
| 6502 | create_shell_seat(seat); |
| 6503 | } |
| 6504 | |
Kristian Høgsberg | 1c56218 | 2011-05-02 22:09:20 -0400 | [diff] [blame] | 6505 | WL_EXPORT int |
Kristian Høgsberg | cb4685b | 2013-02-20 15:37:49 -0500 | [diff] [blame] | 6506 | module_init(struct weston_compositor *ec, |
Ossama Othman | a50e6e4 | 2013-05-14 09:48:26 -0700 | [diff] [blame] | 6507 | int *argc, char *argv[]) |
Kristian Høgsberg | 4cca349 | 2011-01-18 07:53:49 -0500 | [diff] [blame] | 6508 | { |
Kristian Høgsberg | f4d2f23 | 2012-08-10 10:05:39 -0400 | [diff] [blame] | 6509 | struct weston_seat *seat; |
Tiago Vignatti | be14326 | 2012-04-16 17:31:41 +0300 | [diff] [blame] | 6510 | struct desktop_shell *shell; |
Jonas Ådahl | e3cddce | 2012-06-13 00:01:22 +0200 | [diff] [blame] | 6511 | struct workspace **pws; |
| 6512 | unsigned int i; |
Tiago Vignatti | b7dbbd6 | 2012-09-25 17:57:01 +0300 | [diff] [blame] | 6513 | struct wl_event_loop *loop; |
Kristian Høgsberg | 02ec0a5 | 2011-04-23 13:04:11 -0400 | [diff] [blame] | 6514 | |
Peter Hutterer | f3d6227 | 2013-08-08 11:57:05 +1000 | [diff] [blame] | 6515 | shell = zalloc(sizeof *shell); |
Kristian Høgsberg | 02ec0a5 | 2011-04-23 13:04:11 -0400 | [diff] [blame] | 6516 | if (shell == NULL) |
| 6517 | return -1; |
| 6518 | |
Kristian Høgsberg | 7584062 | 2011-09-06 13:48:16 -0400 | [diff] [blame] | 6519 | shell->compositor = ec; |
Kristian Høgsberg | 02e79dc | 2012-04-12 09:55:26 -0400 | [diff] [blame] | 6520 | |
| 6521 | shell->destroy_listener.notify = shell_destroy; |
| 6522 | wl_signal_add(&ec->destroy_signal, &shell->destroy_listener); |
Ander Conselvan de Oliveira | a457563 | 2013-02-21 18:35:23 +0200 | [diff] [blame] | 6523 | shell->idle_listener.notify = idle_handler; |
| 6524 | wl_signal_add(&ec->idle_signal, &shell->idle_listener); |
| 6525 | shell->wake_listener.notify = wake_handler; |
| 6526 | wl_signal_add(&ec->wake_signal, &shell->wake_listener); |
Kristian Høgsberg | 677a5f5 | 2013-12-04 11:00:19 -0800 | [diff] [blame] | 6527 | |
Kristian Høgsberg | 82a1d11 | 2012-07-19 14:02:00 -0400 | [diff] [blame] | 6528 | ec->shell_interface.shell = shell; |
Tiago Vignatti | bc052c9 | 2012-04-19 16:18:18 +0300 | [diff] [blame] | 6529 | ec->shell_interface.create_shell_surface = create_shell_surface; |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 6530 | ec->shell_interface.get_primary_view = get_primary_view; |
Tiago Vignatti | bc052c9 | 2012-04-19 16:18:18 +0300 | [diff] [blame] | 6531 | ec->shell_interface.set_toplevel = set_toplevel; |
Tiago Vignatti | 491bac1 | 2012-05-18 16:37:43 -0400 | [diff] [blame] | 6532 | ec->shell_interface.set_transient = set_transient; |
Kristian Høgsberg | 4779241 | 2014-05-04 13:47:06 -0700 | [diff] [blame] | 6533 | ec->shell_interface.set_fullscreen = shell_interface_set_fullscreen; |
Tiago Vignatti | fb2adba | 2013-06-12 15:43:21 -0300 | [diff] [blame] | 6534 | ec->shell_interface.set_xwayland = set_xwayland; |
Kristian Høgsberg | ae356ae | 2014-04-29 16:03:54 -0700 | [diff] [blame] | 6535 | ec->shell_interface.move = shell_interface_move; |
Kristian Høgsberg | c1693f2 | 2012-05-22 16:56:23 -0400 | [diff] [blame] | 6536 | ec->shell_interface.resize = surface_resize; |
Giulio Camuffo | 62942ad | 2013-09-11 18:20:47 +0200 | [diff] [blame] | 6537 | ec->shell_interface.set_title = set_title; |
Jasper St. Pierre | ccf48fb | 2014-05-02 10:21:38 -0400 | [diff] [blame] | 6538 | ec->shell_interface.set_window_geometry = set_window_geometry; |
Kristian Høgsberg | 4cca349 | 2011-01-18 07:53:49 -0500 | [diff] [blame] | 6539 | |
Kristian Høgsberg | 3be2ce9 | 2012-02-29 12:42:35 -0500 | [diff] [blame] | 6540 | weston_layer_init(&shell->fullscreen_layer, &ec->cursor_layer.link); |
| 6541 | weston_layer_init(&shell->panel_layer, &shell->fullscreen_layer.link); |
Jonas Ådahl | e3cddce | 2012-06-13 00:01:22 +0200 | [diff] [blame] | 6542 | weston_layer_init(&shell->background_layer, &shell->panel_layer.link); |
| 6543 | weston_layer_init(&shell->lock_layer, NULL); |
Philipp Brüschweiler | 711fda8 | 2012-08-09 18:50:43 +0200 | [diff] [blame] | 6544 | weston_layer_init(&shell->input_panel_layer, NULL); |
Jonas Ådahl | e3cddce | 2012-06-13 00:01:22 +0200 | [diff] [blame] | 6545 | |
| 6546 | wl_array_init(&shell->workspaces.array); |
Jonas Ådahl | e9d2250 | 2012-08-29 22:13:01 +0200 | [diff] [blame] | 6547 | wl_list_init(&shell->workspaces.client_list); |
Kristian Høgsberg | 3be2ce9 | 2012-02-29 12:42:35 -0500 | [diff] [blame] | 6548 | |
Kristian Høgsberg | 677a5f5 | 2013-12-04 11:00:19 -0800 | [diff] [blame] | 6549 | if (input_panel_setup(shell) < 0) |
| 6550 | return -1; |
| 6551 | |
Kristian Høgsberg | 14e438c | 2013-05-26 21:48:14 -0400 | [diff] [blame] | 6552 | shell_configuration(shell); |
Pekka Paalanen | e955f1e | 2011-12-07 11:49:52 +0200 | [diff] [blame] | 6553 | |
Daniel Stone | df8133b | 2013-11-19 11:37:14 +0100 | [diff] [blame] | 6554 | shell->exposay.state_cur = EXPOSAY_LAYOUT_INACTIVE; |
| 6555 | shell->exposay.state_target = EXPOSAY_TARGET_CANCEL; |
| 6556 | |
Jonas Ådahl | e3cddce | 2012-06-13 00:01:22 +0200 | [diff] [blame] | 6557 | for (i = 0; i < shell->workspaces.num; i++) { |
| 6558 | pws = wl_array_add(&shell->workspaces.array, sizeof *pws); |
| 6559 | if (pws == NULL) |
| 6560 | return -1; |
| 6561 | |
| 6562 | *pws = workspace_create(); |
| 6563 | if (*pws == NULL) |
| 6564 | return -1; |
| 6565 | } |
| 6566 | activate_workspace(shell, 0); |
| 6567 | |
Manuel Bachmann | 50c87db | 2014-02-26 15:52:13 +0100 | [diff] [blame] | 6568 | weston_layer_init(&shell->minimized_layer, NULL); |
| 6569 | |
Jonas Ådahl | 8de6a1d | 2012-08-29 22:13:00 +0200 | [diff] [blame] | 6570 | wl_list_init(&shell->workspaces.anim_sticky_list); |
Jonas Ådahl | 62fcd04 | 2012-06-13 00:01:23 +0200 | [diff] [blame] | 6571 | wl_list_init(&shell->workspaces.animation.link); |
| 6572 | shell->workspaces.animation.frame = animate_workspace_change_frame; |
| 6573 | |
Kristian Høgsberg | 919cddb | 2013-07-08 19:03:57 -0400 | [diff] [blame] | 6574 | if (wl_global_create(ec->wl_display, &wl_shell_interface, 1, |
Kristian Høgsberg | 97d44aa | 2011-08-26 17:21:20 -0400 | [diff] [blame] | 6575 | shell, bind_shell) == NULL) |
Kristian Høgsberg | 4cca349 | 2011-01-18 07:53:49 -0500 | [diff] [blame] | 6576 | return -1; |
| 6577 | |
Rafael Antognolli | e2a3455 | 2013-12-03 15:35:45 -0200 | [diff] [blame] | 6578 | if (wl_global_create(ec->wl_display, &xdg_shell_interface, 1, |
| 6579 | shell, bind_xdg_shell) == NULL) |
| 6580 | return -1; |
| 6581 | |
Kristian Høgsberg | 919cddb | 2013-07-08 19:03:57 -0400 | [diff] [blame] | 6582 | if (wl_global_create(ec->wl_display, |
Jonny Lamb | 765760d | 2014-08-20 15:53:19 +0200 | [diff] [blame] | 6583 | &desktop_shell_interface, 3, |
Kristian Høgsberg | 919cddb | 2013-07-08 19:03:57 -0400 | [diff] [blame] | 6584 | shell, bind_desktop_shell) == NULL) |
Kristian Høgsberg | 7584062 | 2011-09-06 13:48:16 -0400 | [diff] [blame] | 6585 | return -1; |
| 6586 | |
Kristian Høgsberg | 919cddb | 2013-07-08 19:03:57 -0400 | [diff] [blame] | 6587 | if (wl_global_create(ec->wl_display, &screensaver_interface, 1, |
| 6588 | shell, bind_screensaver) == NULL) |
Pekka Paalanen | 6e16811 | 2011-11-24 11:34:05 +0200 | [diff] [blame] | 6589 | return -1; |
| 6590 | |
Kristian Høgsberg | 919cddb | 2013-07-08 19:03:57 -0400 | [diff] [blame] | 6591 | if (wl_global_create(ec->wl_display, &workspace_manager_interface, 1, |
| 6592 | shell, bind_workspace_manager) == NULL) |
Jonas Ådahl | e9d2250 | 2012-08-29 22:13:01 +0200 | [diff] [blame] | 6593 | return -1; |
| 6594 | |
Kristian Høgsberg | f03a616 | 2012-01-17 11:07:42 -0500 | [diff] [blame] | 6595 | shell->child.deathstamp = weston_compositor_get_time(); |
Tiago Vignatti | b7dbbd6 | 2012-09-25 17:57:01 +0300 | [diff] [blame] | 6596 | |
Jonny Lamb | 765760d | 2014-08-20 15:53:19 +0200 | [diff] [blame] | 6597 | shell->panel_position = DESKTOP_SHELL_PANEL_POSITION_TOP; |
| 6598 | |
Xiong Zhang | 6b48142 | 2013-10-23 13:58:32 +0800 | [diff] [blame] | 6599 | setup_output_destroy_handler(ec, shell); |
| 6600 | |
Tiago Vignatti | b7dbbd6 | 2012-09-25 17:57:01 +0300 | [diff] [blame] | 6601 | loop = wl_display_get_event_loop(ec->wl_display); |
| 6602 | wl_event_loop_add_idle(loop, launch_desktop_shell_process, shell); |
Pekka Paalanen | 6cd281a | 2011-11-03 14:11:32 +0200 | [diff] [blame] | 6603 | |
Ander Conselvan de Oliveira | 859e885 | 2013-02-21 18:35:21 +0200 | [diff] [blame] | 6604 | shell->screensaver.timer = |
| 6605 | wl_event_loop_add_timer(loop, screensaver_timeout, shell); |
| 6606 | |
Jason Ekstrand | 024177c | 2014-04-21 19:42:58 -0500 | [diff] [blame] | 6607 | wl_list_for_each(seat, &ec->seat_list, link) |
| 6608 | handle_seat_created(NULL, seat); |
| 6609 | shell->seat_create_listener.notify = handle_seat_created; |
| 6610 | wl_signal_add(&ec->seat_created_signal, &shell->seat_create_listener); |
Kristian Høgsberg | d56bd90 | 2012-06-05 09:58:51 -0400 | [diff] [blame] | 6611 | |
Giulio Camuffo | c6ab3d5 | 2013-12-11 23:45:12 +0100 | [diff] [blame] | 6612 | screenshooter_create(ec); |
| 6613 | |
Tiago Vignatti | 0b52d48 | 2012-04-20 18:54:25 +0300 | [diff] [blame] | 6614 | shell_add_bindings(ec, shell); |
Kristian Høgsberg | 0793756 | 2011-04-12 17:25:42 -0400 | [diff] [blame] | 6615 | |
Pekka Paalanen | 79346ab | 2013-05-22 18:03:09 +0300 | [diff] [blame] | 6616 | shell_fade_init(shell); |
Ander Conselvan de Oliveira | 19d10ef | 2013-02-21 18:35:20 +0200 | [diff] [blame] | 6617 | |
Pekka Paalanen | 2e62e4a | 2014-08-28 11:41:26 +0300 | [diff] [blame] | 6618 | clock_gettime(CLOCK_MONOTONIC, &shell->startup_time); |
| 6619 | |
Kristian Høgsberg | 4cca349 | 2011-01-18 07:53:49 -0500 | [diff] [blame] | 6620 | return 0; |
| 6621 | } |