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; |
Rafael Antognolli | 65f98d8 | 2013-12-03 15:35:47 -0200 | [diff] [blame] | 160 | struct weston_output *recommended_output; |
Benjamin Franzke | d0f79ab | 2011-11-22 12:43:52 +0100 | [diff] [blame] | 161 | struct wl_list link; |
Kristian Høgsberg | a61ca06 | 2012-05-22 16:05:52 -0400 | [diff] [blame] | 162 | |
| 163 | const struct weston_shell_client *client; |
Rafael Antognolli | 03b1659 | 2013-12-03 15:35:42 -0200 | [diff] [blame] | 164 | |
| 165 | struct { |
| 166 | bool maximized; |
| 167 | bool fullscreen; |
Rafael Antognolli | ed207b4 | 2013-12-03 15:35:43 -0200 | [diff] [blame] | 168 | bool relative; |
Emilio Pozuelo Monfort | 9e7c759 | 2014-01-30 14:01:10 +0100 | [diff] [blame] | 169 | bool lowered; |
Jasper St. Pierre | 8c6aa45 | 2014-02-08 18:29:49 -0500 | [diff] [blame] | 170 | } state, next_state, requested_state; /* surface states */ |
Rafael Antognolli | 03b1659 | 2013-12-03 15:35:42 -0200 | [diff] [blame] | 171 | bool state_changed; |
Jasper St. Pierre | 8c6aa45 | 2014-02-08 18:29:49 -0500 | [diff] [blame] | 172 | bool state_requested; |
Jasper St. Pierre | faf27a9 | 2013-12-09 17:36:28 -0500 | [diff] [blame] | 173 | |
Kristian Høgsberg | ae356ae | 2014-04-29 16:03:54 -0700 | [diff] [blame] | 174 | struct { |
| 175 | int left, right, top, bottom; |
| 176 | } margin; |
| 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; |
Giulio Camuffo | 5085a75 | 2013-03-25 21:42:45 +0100 | [diff] [blame] | 226 | struct wl_list surfaces_list; |
| 227 | struct wl_client *client; |
| 228 | int32_t initial_up; |
| 229 | } popup_grab; |
| 230 | }; |
| 231 | |
Kristian Høgsberg | 2bff94e | 2014-02-11 12:22:51 -0800 | [diff] [blame] | 232 | struct shell_client { |
| 233 | struct wl_resource *resource; |
| 234 | struct wl_client *client; |
| 235 | struct desktop_shell *shell; |
| 236 | struct wl_listener destroy_listener; |
| 237 | struct wl_event_source *ping_timer; |
| 238 | uint32_t ping_serial; |
| 239 | int unresponsive; |
| 240 | }; |
| 241 | |
Alex Wu | bd3354b | 2012-04-17 17:20:49 +0800 | [diff] [blame] | 242 | static struct desktop_shell * |
| 243 | shell_surface_get_shell(struct shell_surface *shsurf); |
| 244 | |
Kristian Høgsberg | 0c36903 | 2013-02-14 21:31:44 -0500 | [diff] [blame] | 245 | static void |
Kristian Høgsberg | e314875 | 2013-05-06 23:19:49 -0400 | [diff] [blame] | 246 | surface_rotate(struct shell_surface *surface, struct weston_seat *seat); |
Kristian Høgsberg | 0c36903 | 2013-02-14 21:31:44 -0500 | [diff] [blame] | 247 | |
Pekka Paalanen | 79346ab | 2013-05-22 18:03:09 +0300 | [diff] [blame] | 248 | static void |
| 249 | shell_fade_startup(struct desktop_shell *shell); |
| 250 | |
Philip Withnall | becb77e | 2013-11-25 18:01:30 +0000 | [diff] [blame] | 251 | static struct shell_seat * |
| 252 | get_shell_seat(struct weston_seat *seat); |
| 253 | |
Kristian Høgsberg | ae356ae | 2014-04-29 16:03:54 -0700 | [diff] [blame] | 254 | static int |
| 255 | get_output_panel_height(struct desktop_shell *shell, |
| 256 | struct weston_output *output); |
| 257 | |
Philip Withnall | 648a4dd | 2013-11-25 18:01:44 +0000 | [diff] [blame] | 258 | static void |
| 259 | shell_surface_update_child_surface_layers(struct shell_surface *shsurf); |
| 260 | |
Alex Wu | bd3354b | 2012-04-17 17:20:49 +0800 | [diff] [blame] | 261 | static bool |
Rafael Antognolli | e2a3455 | 2013-12-03 15:35:45 -0200 | [diff] [blame] | 262 | shell_surface_is_wl_shell_surface(struct shell_surface *shsurf); |
| 263 | |
| 264 | static bool |
| 265 | shell_surface_is_xdg_surface(struct shell_surface *shsurf); |
| 266 | |
| 267 | static bool |
| 268 | shell_surface_is_xdg_popup(struct shell_surface *shsurf); |
| 269 | |
| 270 | static void |
| 271 | shell_surface_set_parent(struct shell_surface *shsurf, |
| 272 | struct weston_surface *parent); |
| 273 | |
| 274 | static bool |
Alex Wu | bd3354b | 2012-04-17 17:20:49 +0800 | [diff] [blame] | 275 | shell_surface_is_top_fullscreen(struct shell_surface *shsurf) |
| 276 | { |
| 277 | struct desktop_shell *shell; |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 278 | struct weston_view *top_fs_ev; |
Alex Wu | bd3354b | 2012-04-17 17:20:49 +0800 | [diff] [blame] | 279 | |
| 280 | shell = shell_surface_get_shell(shsurf); |
Quentin Glidic | c0d79ce | 2013-01-29 14:16:13 +0100 | [diff] [blame] | 281 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 282 | if (wl_list_empty(&shell->fullscreen_layer.view_list)) |
Alex Wu | bd3354b | 2012-04-17 17:20:49 +0800 | [diff] [blame] | 283 | return false; |
| 284 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 285 | top_fs_ev = container_of(shell->fullscreen_layer.view_list.next, |
| 286 | struct weston_view, |
Alex Wu | bd3354b | 2012-04-17 17:20:49 +0800 | [diff] [blame] | 287 | layer_link); |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 288 | return (shsurf == get_shell_surface(top_fs_ev->surface)); |
Alex Wu | bd3354b | 2012-04-17 17:20:49 +0800 | [diff] [blame] | 289 | } |
| 290 | |
Kristian Høgsberg | 6af8eb9 | 2012-01-25 16:57:11 -0500 | [diff] [blame] | 291 | static void |
Kristian Høgsberg | 27e3052 | 2012-04-11 23:18:23 -0400 | [diff] [blame] | 292 | destroy_shell_grab_shsurf(struct wl_listener *listener, void *data) |
Ander Conselvan de Oliveira | fe0444a | 2012-04-04 17:48:05 +0300 | [diff] [blame] | 293 | { |
| 294 | struct shell_grab *grab; |
| 295 | |
| 296 | grab = container_of(listener, struct shell_grab, |
| 297 | shsurf_destroy_listener); |
| 298 | |
| 299 | grab->shsurf = NULL; |
| 300 | } |
| 301 | |
Kristian Høgsberg | 1ef2313 | 2013-12-04 00:20:01 -0800 | [diff] [blame] | 302 | struct weston_view * |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 303 | get_default_view(struct weston_surface *surface) |
| 304 | { |
| 305 | struct shell_surface *shsurf; |
| 306 | struct weston_view *view; |
| 307 | |
| 308 | if (!surface || wl_list_empty(&surface->views)) |
| 309 | return NULL; |
| 310 | |
| 311 | shsurf = get_shell_surface(surface); |
| 312 | if (shsurf) |
| 313 | return shsurf->view; |
| 314 | |
| 315 | wl_list_for_each(view, &surface->views, surface_link) |
| 316 | if (weston_view_is_mapped(view)) |
| 317 | return view; |
| 318 | |
| 319 | return container_of(surface->views.next, struct weston_view, surface_link); |
| 320 | } |
| 321 | |
Ander Conselvan de Oliveira | fe0444a | 2012-04-04 17:48:05 +0300 | [diff] [blame] | 322 | static void |
Kristian Høgsberg | 02bbabb | 2013-05-06 22:15:05 -0400 | [diff] [blame] | 323 | popup_grab_end(struct weston_pointer *pointer); |
Kristian Høgsberg | 57e0907 | 2012-10-30 14:07:27 -0400 | [diff] [blame] | 324 | |
| 325 | static void |
Ander Conselvan de Oliveira | b9d2a0f | 2012-06-28 18:08:05 +0300 | [diff] [blame] | 326 | shell_grab_start(struct shell_grab *grab, |
Kristian Høgsberg | 02bbabb | 2013-05-06 22:15:05 -0400 | [diff] [blame] | 327 | const struct weston_pointer_grab_interface *interface, |
Ander Conselvan de Oliveira | b9d2a0f | 2012-06-28 18:08:05 +0300 | [diff] [blame] | 328 | struct shell_surface *shsurf, |
Kristian Høgsberg | 02bbabb | 2013-05-06 22:15:05 -0400 | [diff] [blame] | 329 | struct weston_pointer *pointer, |
Ander Conselvan de Oliveira | b9d2a0f | 2012-06-28 18:08:05 +0300 | [diff] [blame] | 330 | enum desktop_shell_cursor cursor) |
Ander Conselvan de Oliveira | fe0444a | 2012-04-04 17:48:05 +0300 | [diff] [blame] | 331 | { |
Ander Conselvan de Oliveira | b9d2a0f | 2012-06-28 18:08:05 +0300 | [diff] [blame] | 332 | struct desktop_shell *shell = shsurf->shell; |
| 333 | |
Kristian Høgsberg | 57e0907 | 2012-10-30 14:07:27 -0400 | [diff] [blame] | 334 | popup_grab_end(pointer); |
| 335 | |
Ander Conselvan de Oliveira | fe0444a | 2012-04-04 17:48:05 +0300 | [diff] [blame] | 336 | grab->grab.interface = interface; |
| 337 | grab->shsurf = shsurf; |
Kristian Høgsberg | 27e3052 | 2012-04-11 23:18:23 -0400 | [diff] [blame] | 338 | grab->shsurf_destroy_listener.notify = destroy_shell_grab_shsurf; |
Jason Ekstrand | 651f00e | 2013-06-14 10:07:54 -0500 | [diff] [blame] | 339 | wl_signal_add(&shsurf->destroy_signal, |
Kristian Høgsberg | 27e3052 | 2012-04-11 23:18:23 -0400 | [diff] [blame] | 340 | &grab->shsurf_destroy_listener); |
Ander Conselvan de Oliveira | fe0444a | 2012-04-04 17:48:05 +0300 | [diff] [blame] | 341 | |
Kristian Høgsberg | c85f1d4 | 2013-10-24 16:52:00 -0700 | [diff] [blame] | 342 | shsurf->grabbed = 1; |
Kristian Høgsberg | 02bbabb | 2013-05-06 22:15:05 -0400 | [diff] [blame] | 343 | weston_pointer_start_grab(pointer, &grab->grab); |
Kristian Høgsberg | c9974a0 | 2013-07-03 19:24:57 -0400 | [diff] [blame] | 344 | if (shell->child.desktop_shell) { |
| 345 | desktop_shell_send_grab_cursor(shell->child.desktop_shell, |
| 346 | cursor); |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 347 | weston_pointer_set_focus(pointer, |
| 348 | get_default_view(shell->grab_surface), |
Kristian Høgsberg | c9974a0 | 2013-07-03 19:24:57 -0400 | [diff] [blame] | 349 | wl_fixed_from_int(0), |
| 350 | wl_fixed_from_int(0)); |
| 351 | } |
Ander Conselvan de Oliveira | fe0444a | 2012-04-04 17:48:05 +0300 | [diff] [blame] | 352 | } |
| 353 | |
| 354 | static void |
Ander Conselvan de Oliveira | b9d2a0f | 2012-06-28 18:08:05 +0300 | [diff] [blame] | 355 | shell_grab_end(struct shell_grab *grab) |
Ander Conselvan de Oliveira | fe0444a | 2012-04-04 17:48:05 +0300 | [diff] [blame] | 356 | { |
Kristian Høgsberg | c85f1d4 | 2013-10-24 16:52:00 -0700 | [diff] [blame] | 357 | if (grab->shsurf) { |
Kristian Høgsberg | 47b5dca | 2012-06-07 18:08:04 -0400 | [diff] [blame] | 358 | wl_list_remove(&grab->shsurf_destroy_listener.link); |
Kristian Høgsberg | c85f1d4 | 2013-10-24 16:52:00 -0700 | [diff] [blame] | 359 | grab->shsurf->grabbed = 0; |
Kristian Høgsberg | 44cd196 | 2014-02-05 21:36:04 -0800 | [diff] [blame] | 360 | grab->shsurf->resize_edges = 0; |
Kristian Høgsberg | c85f1d4 | 2013-10-24 16:52:00 -0700 | [diff] [blame] | 361 | } |
Ander Conselvan de Oliveira | b9d2a0f | 2012-06-28 18:08:05 +0300 | [diff] [blame] | 362 | |
Kristian Høgsberg | 9e5d7d1 | 2013-07-22 16:31:53 -0700 | [diff] [blame] | 363 | weston_pointer_end_grab(grab->grab.pointer); |
Ander Conselvan de Oliveira | fe0444a | 2012-04-04 17:48:05 +0300 | [diff] [blame] | 364 | } |
| 365 | |
| 366 | static void |
Rusty Lynch | 1084da5 | 2013-08-15 09:10:08 -0700 | [diff] [blame] | 367 | shell_touch_grab_start(struct shell_touch_grab *grab, |
| 368 | const struct weston_touch_grab_interface *interface, |
| 369 | struct shell_surface *shsurf, |
| 370 | struct weston_touch *touch) |
| 371 | { |
| 372 | struct desktop_shell *shell = shsurf->shell; |
U. Artie Eoff | cf5737a | 2014-01-17 10:08:25 -0800 | [diff] [blame] | 373 | |
Kristian Høgsberg | 74071e0 | 2014-04-29 15:01:16 -0700 | [diff] [blame] | 374 | if (touch->seat->pointer) |
| 375 | popup_grab_end(touch->seat->pointer); |
| 376 | |
Rusty Lynch | 1084da5 | 2013-08-15 09:10:08 -0700 | [diff] [blame] | 377 | grab->grab.interface = interface; |
| 378 | grab->shsurf = shsurf; |
| 379 | grab->shsurf_destroy_listener.notify = destroy_shell_grab_shsurf; |
| 380 | wl_signal_add(&shsurf->destroy_signal, |
| 381 | &grab->shsurf_destroy_listener); |
| 382 | |
| 383 | grab->touch = touch; |
Kristian Høgsberg | c85f1d4 | 2013-10-24 16:52:00 -0700 | [diff] [blame] | 384 | shsurf->grabbed = 1; |
Rusty Lynch | 1084da5 | 2013-08-15 09:10:08 -0700 | [diff] [blame] | 385 | |
| 386 | weston_touch_start_grab(touch, &grab->grab); |
| 387 | if (shell->child.desktop_shell) |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 388 | weston_touch_set_focus(touch->seat, |
| 389 | get_default_view(shell->grab_surface)); |
Rusty Lynch | 1084da5 | 2013-08-15 09:10:08 -0700 | [diff] [blame] | 390 | } |
| 391 | |
| 392 | static void |
| 393 | shell_touch_grab_end(struct shell_touch_grab *grab) |
| 394 | { |
Kristian Høgsberg | c85f1d4 | 2013-10-24 16:52:00 -0700 | [diff] [blame] | 395 | if (grab->shsurf) { |
Rusty Lynch | 1084da5 | 2013-08-15 09:10:08 -0700 | [diff] [blame] | 396 | wl_list_remove(&grab->shsurf_destroy_listener.link); |
Kristian Høgsberg | c85f1d4 | 2013-10-24 16:52:00 -0700 | [diff] [blame] | 397 | grab->shsurf->grabbed = 0; |
| 398 | } |
Rusty Lynch | 1084da5 | 2013-08-15 09:10:08 -0700 | [diff] [blame] | 399 | |
| 400 | weston_touch_end_grab(grab->touch); |
| 401 | } |
| 402 | |
| 403 | static void |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 404 | center_on_output(struct weston_view *view, |
Alex Wu | 4539b08 | 2012-03-01 12:57:46 +0800 | [diff] [blame] | 405 | struct weston_output *output); |
| 406 | |
Daniel Stone | 496ca17 | 2012-05-30 16:31:42 +0100 | [diff] [blame] | 407 | static enum weston_keyboard_modifier |
Tiago Vignatti | 0b52d48 | 2012-04-20 18:54:25 +0300 | [diff] [blame] | 408 | get_modifier(char *modifier) |
| 409 | { |
| 410 | if (!modifier) |
| 411 | return MODIFIER_SUPER; |
| 412 | |
| 413 | if (!strcmp("ctrl", modifier)) |
| 414 | return MODIFIER_CTRL; |
| 415 | else if (!strcmp("alt", modifier)) |
| 416 | return MODIFIER_ALT; |
| 417 | else if (!strcmp("super", modifier)) |
| 418 | return MODIFIER_SUPER; |
| 419 | else |
| 420 | return MODIFIER_SUPER; |
| 421 | } |
| 422 | |
Juan Zhao | e10d279 | 2012-04-25 19:09:52 +0800 | [diff] [blame] | 423 | static enum animation_type |
| 424 | get_animation_type(char *animation) |
| 425 | { |
U. Artie Eoff | b571910 | 2014-01-15 14:26:31 -0800 | [diff] [blame] | 426 | if (!animation) |
| 427 | return ANIMATION_NONE; |
| 428 | |
Juan Zhao | e10d279 | 2012-04-25 19:09:52 +0800 | [diff] [blame] | 429 | if (!strcmp("zoom", animation)) |
| 430 | return ANIMATION_ZOOM; |
| 431 | else if (!strcmp("fade", animation)) |
| 432 | return ANIMATION_FADE; |
Louis-Francis Ratté-Boulianne | b482dbd | 2013-11-19 11:37:11 +0100 | [diff] [blame] | 433 | else if (!strcmp("dim-layer", animation)) |
| 434 | return ANIMATION_DIM_LAYER; |
Juan Zhao | e10d279 | 2012-04-25 19:09:52 +0800 | [diff] [blame] | 435 | else |
| 436 | return ANIMATION_NONE; |
| 437 | } |
| 438 | |
Alex Wu | 4539b08 | 2012-03-01 12:57:46 +0800 | [diff] [blame] | 439 | static void |
Kristian Høgsberg | 14e438c | 2013-05-26 21:48:14 -0400 | [diff] [blame] | 440 | shell_configuration(struct desktop_shell *shell) |
Pekka Paalanen | e955f1e | 2011-12-07 11:49:52 +0200 | [diff] [blame] | 441 | { |
Kristian Høgsberg | 673a889 | 2013-05-23 21:40:56 -0400 | [diff] [blame] | 442 | struct weston_config_section *section; |
| 443 | int duration; |
| 444 | char *s; |
Pekka Paalanen | e955f1e | 2011-12-07 11:49:52 +0200 | [diff] [blame] | 445 | |
Kristian Høgsberg | 673a889 | 2013-05-23 21:40:56 -0400 | [diff] [blame] | 446 | section = weston_config_get_section(shell->compositor->config, |
| 447 | "screensaver", NULL, NULL); |
| 448 | weston_config_section_get_string(section, |
| 449 | "path", &shell->screensaver.path, NULL); |
| 450 | weston_config_section_get_int(section, "duration", &duration, 60); |
Ander Conselvan de Oliveira | 859e885 | 2013-02-21 18:35:21 +0200 | [diff] [blame] | 451 | shell->screensaver.duration = duration * 1000; |
Kristian Høgsberg | 673a889 | 2013-05-23 21:40:56 -0400 | [diff] [blame] | 452 | |
| 453 | section = weston_config_get_section(shell->compositor->config, |
| 454 | "shell", NULL, NULL); |
| 455 | weston_config_section_get_string(section, |
Emilio Pozuelo Monfort | 8a81b83 | 2013-12-02 12:53:32 +0100 | [diff] [blame] | 456 | "client", &s, LIBEXECDIR "/" WESTON_SHELL_CLIENT); |
Emilio Pozuelo Monfort | 46ce798 | 2013-11-20 13:22:29 +0100 | [diff] [blame] | 457 | shell->client = s; |
| 458 | weston_config_section_get_string(section, |
Kristian Høgsberg | 673a889 | 2013-05-23 21:40:56 -0400 | [diff] [blame] | 459 | "binding-modifier", &s, "super"); |
| 460 | shell->binding_modifier = get_modifier(s); |
Quentin Glidic | 8418c29 | 2013-06-18 09:11:03 +0200 | [diff] [blame] | 461 | free(s); |
Kristian Høgsberg | d56ab4e | 2014-01-16 16:51:52 -0800 | [diff] [blame] | 462 | |
| 463 | weston_config_section_get_string(section, |
| 464 | "exposay-modifier", &s, "none"); |
| 465 | if (strcmp(s, "none") == 0) |
| 466 | shell->exposay_modifier = 0; |
| 467 | else |
| 468 | shell->exposay_modifier = get_modifier(s); |
| 469 | free(s); |
| 470 | |
Kristian Høgsberg | 673a889 | 2013-05-23 21:40:56 -0400 | [diff] [blame] | 471 | weston_config_section_get_string(section, "animation", &s, "none"); |
| 472 | shell->win_animation_type = get_animation_type(s); |
Quentin Glidic | 8418c29 | 2013-06-18 09:11:03 +0200 | [diff] [blame] | 473 | free(s); |
Kristian Høgsberg | 724c8d9 | 2013-10-16 11:38:24 -0700 | [diff] [blame] | 474 | weston_config_section_get_string(section, |
| 475 | "startup-animation", &s, "fade"); |
| 476 | shell->startup_animation_type = get_animation_type(s); |
| 477 | free(s); |
Kristian Høgsberg | 912e0a1 | 2013-10-30 08:59:55 -0700 | [diff] [blame] | 478 | if (shell->startup_animation_type == ANIMATION_ZOOM) |
| 479 | shell->startup_animation_type = ANIMATION_NONE; |
Louis-Francis Ratté-Boulianne | b482dbd | 2013-11-19 11:37:11 +0100 | [diff] [blame] | 480 | weston_config_section_get_string(section, "focus-animation", &s, "none"); |
| 481 | shell->focus_animation_type = get_animation_type(s); |
| 482 | free(s); |
Kristian Høgsberg | 673a889 | 2013-05-23 21:40:56 -0400 | [diff] [blame] | 483 | weston_config_section_get_uint(section, "num-workspaces", |
| 484 | &shell->workspaces.num, |
| 485 | DEFAULT_NUM_WORKSPACES); |
Jonas Ådahl | e3cddce | 2012-06-13 00:01:22 +0200 | [diff] [blame] | 486 | } |
| 487 | |
Kristian Høgsberg | 1ef2313 | 2013-12-04 00:20:01 -0800 | [diff] [blame] | 488 | struct weston_output * |
Louis-Francis Ratté-Boulianne | b482dbd | 2013-11-19 11:37:11 +0100 | [diff] [blame] | 489 | get_default_output(struct weston_compositor *compositor) |
| 490 | { |
| 491 | return container_of(compositor->output_list.next, |
| 492 | struct weston_output, link); |
| 493 | } |
| 494 | |
| 495 | |
| 496 | /* no-op func for checking focus surface */ |
| 497 | static void |
Jason Ekstrand | 918f2dd | 2013-12-02 21:01:53 -0600 | [diff] [blame] | 498 | 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] | 499 | { |
| 500 | } |
| 501 | |
| 502 | static struct focus_surface * |
| 503 | get_focus_surface(struct weston_surface *surface) |
| 504 | { |
| 505 | if (surface->configure == focus_surface_configure) |
| 506 | return surface->configure_private; |
| 507 | else |
| 508 | return NULL; |
| 509 | } |
| 510 | |
| 511 | static bool |
| 512 | is_focus_surface (struct weston_surface *es) |
| 513 | { |
| 514 | return (es->configure == focus_surface_configure); |
| 515 | } |
| 516 | |
| 517 | static bool |
| 518 | is_focus_view (struct weston_view *view) |
| 519 | { |
| 520 | return is_focus_surface (view->surface); |
| 521 | } |
| 522 | |
| 523 | static struct focus_surface * |
| 524 | create_focus_surface(struct weston_compositor *ec, |
| 525 | struct weston_output *output) |
| 526 | { |
| 527 | struct focus_surface *fsurf = NULL; |
| 528 | struct weston_surface *surface = NULL; |
| 529 | |
| 530 | fsurf = malloc(sizeof *fsurf); |
| 531 | if (!fsurf) |
| 532 | return NULL; |
| 533 | |
| 534 | fsurf->surface = weston_surface_create(ec); |
| 535 | surface = fsurf->surface; |
| 536 | if (surface == NULL) { |
| 537 | free(fsurf); |
| 538 | return NULL; |
| 539 | } |
| 540 | |
| 541 | surface->configure = focus_surface_configure; |
| 542 | surface->output = output; |
| 543 | surface->configure_private = fsurf; |
| 544 | |
U. Artie Eoff | 0b23b2b | 2014-01-15 14:45:59 -0800 | [diff] [blame] | 545 | fsurf->view = weston_view_create(surface); |
| 546 | if (fsurf->view == NULL) { |
| 547 | weston_surface_destroy(surface); |
| 548 | free(fsurf); |
| 549 | return NULL; |
| 550 | } |
Emilio Pozuelo Monfort | da64426 | 2013-11-19 11:37:19 +0100 | [diff] [blame] | 551 | fsurf->view->output = output; |
Louis-Francis Ratté-Boulianne | b482dbd | 2013-11-19 11:37:11 +0100 | [diff] [blame] | 552 | |
Jason Ekstrand | 5c11a33 | 2013-12-04 20:32:03 -0600 | [diff] [blame] | 553 | weston_surface_set_size(surface, output->width, output->height); |
Jason Ekstrand | 918f2dd | 2013-12-02 21:01:53 -0600 | [diff] [blame] | 554 | weston_view_set_position(fsurf->view, output->x, output->y); |
Louis-Francis Ratté-Boulianne | b482dbd | 2013-11-19 11:37:11 +0100 | [diff] [blame] | 555 | weston_surface_set_color(surface, 0.0, 0.0, 0.0, 1.0); |
| 556 | pixman_region32_fini(&surface->opaque); |
| 557 | pixman_region32_init_rect(&surface->opaque, output->x, output->y, |
| 558 | output->width, output->height); |
| 559 | pixman_region32_fini(&surface->input); |
| 560 | pixman_region32_init(&surface->input); |
| 561 | |
| 562 | wl_list_init(&fsurf->workspace_transform.link); |
| 563 | |
| 564 | return fsurf; |
| 565 | } |
| 566 | |
| 567 | static void |
| 568 | focus_surface_destroy(struct focus_surface *fsurf) |
| 569 | { |
| 570 | weston_surface_destroy(fsurf->surface); |
| 571 | free(fsurf); |
| 572 | } |
| 573 | |
| 574 | static void |
| 575 | focus_animation_done(struct weston_view_animation *animation, void *data) |
| 576 | { |
| 577 | struct workspace *ws = data; |
| 578 | |
| 579 | ws->focus_animation = NULL; |
| 580 | } |
| 581 | |
Jonas Ådahl | e3cddce | 2012-06-13 00:01:22 +0200 | [diff] [blame] | 582 | static void |
Jonas Ådahl | 0476974 | 2012-06-13 00:01:24 +0200 | [diff] [blame] | 583 | focus_state_destroy(struct focus_state *state) |
| 584 | { |
| 585 | wl_list_remove(&state->seat_destroy_listener.link); |
| 586 | wl_list_remove(&state->surface_destroy_listener.link); |
| 587 | free(state); |
| 588 | } |
| 589 | |
| 590 | static void |
| 591 | focus_state_seat_destroy(struct wl_listener *listener, void *data) |
| 592 | { |
| 593 | struct focus_state *state = container_of(listener, |
| 594 | struct focus_state, |
| 595 | seat_destroy_listener); |
| 596 | |
| 597 | wl_list_remove(&state->link); |
| 598 | focus_state_destroy(state); |
| 599 | } |
| 600 | |
| 601 | static void |
| 602 | focus_state_surface_destroy(struct wl_listener *listener, void *data) |
| 603 | { |
| 604 | struct focus_state *state = container_of(listener, |
| 605 | struct focus_state, |
Kristian Høgsberg | b8e0d0f | 2012-07-31 10:30:26 -0400 | [diff] [blame] | 606 | surface_destroy_listener); |
Kristian Høgsberg | e377822 | 2012-07-31 17:29:30 -0400 | [diff] [blame] | 607 | struct desktop_shell *shell; |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 608 | struct weston_surface *main_surface, *next; |
| 609 | struct weston_view *view; |
Jonas Ådahl | 0476974 | 2012-06-13 00:01:24 +0200 | [diff] [blame] | 610 | |
Pekka Paalanen | 01388e2 | 2013-04-25 13:57:44 +0300 | [diff] [blame] | 611 | main_surface = weston_surface_get_main_surface(state->keyboard_focus); |
| 612 | |
Kristian Høgsberg | e377822 | 2012-07-31 17:29:30 -0400 | [diff] [blame] | 613 | next = NULL; |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 614 | wl_list_for_each(view, &state->ws->layer.view_list, layer_link) { |
| 615 | if (view->surface == main_surface) |
Kristian Høgsberg | e377822 | 2012-07-31 17:29:30 -0400 | [diff] [blame] | 616 | continue; |
Louis-Francis Ratté-Boulianne | b482dbd | 2013-11-19 11:37:11 +0100 | [diff] [blame] | 617 | if (is_focus_view(view)) |
| 618 | continue; |
Kristian Høgsberg | e377822 | 2012-07-31 17:29:30 -0400 | [diff] [blame] | 619 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 620 | next = view->surface; |
Kristian Høgsberg | e377822 | 2012-07-31 17:29:30 -0400 | [diff] [blame] | 621 | break; |
| 622 | } |
| 623 | |
Pekka Paalanen | 01388e2 | 2013-04-25 13:57:44 +0300 | [diff] [blame] | 624 | /* if the focus was a sub-surface, activate its main surface */ |
| 625 | if (main_surface != state->keyboard_focus) |
| 626 | next = main_surface; |
| 627 | |
Louis-Francis Ratté-Boulianne | b482dbd | 2013-11-19 11:37:11 +0100 | [diff] [blame] | 628 | shell = state->seat->compositor->shell_interface.shell; |
Kristian Høgsberg | e377822 | 2012-07-31 17:29:30 -0400 | [diff] [blame] | 629 | if (next) { |
Louis-Francis Ratté-Boulianne | b482dbd | 2013-11-19 11:37:11 +0100 | [diff] [blame] | 630 | state->keyboard_focus = NULL; |
Emilio Pozuelo Monfort | 9e7c759 | 2014-01-30 14:01:10 +0100 | [diff] [blame] | 631 | activate(shell, next, state->seat, true); |
Kristian Høgsberg | e377822 | 2012-07-31 17:29:30 -0400 | [diff] [blame] | 632 | } else { |
Louis-Francis Ratté-Boulianne | b482dbd | 2013-11-19 11:37:11 +0100 | [diff] [blame] | 633 | if (shell->focus_animation_type == ANIMATION_DIM_LAYER) { |
| 634 | if (state->ws->focus_animation) |
| 635 | weston_view_animation_destroy(state->ws->focus_animation); |
| 636 | |
| 637 | state->ws->focus_animation = weston_fade_run( |
| 638 | state->ws->fsurf_front->view, |
| 639 | state->ws->fsurf_front->view->alpha, 0.0, 300, |
| 640 | focus_animation_done, state->ws); |
| 641 | } |
| 642 | |
Kristian Høgsberg | e377822 | 2012-07-31 17:29:30 -0400 | [diff] [blame] | 643 | wl_list_remove(&state->link); |
| 644 | focus_state_destroy(state); |
| 645 | } |
Jonas Ådahl | 0476974 | 2012-06-13 00:01:24 +0200 | [diff] [blame] | 646 | } |
| 647 | |
| 648 | static struct focus_state * |
Kristian Høgsberg | 2f5faff | 2012-07-31 16:36:34 -0400 | [diff] [blame] | 649 | focus_state_create(struct weston_seat *seat, struct workspace *ws) |
Jonas Ådahl | 0476974 | 2012-06-13 00:01:24 +0200 | [diff] [blame] | 650 | { |
Jonas Ådahl | 0476974 | 2012-06-13 00:01:24 +0200 | [diff] [blame] | 651 | struct focus_state *state; |
Jonas Ådahl | 0476974 | 2012-06-13 00:01:24 +0200 | [diff] [blame] | 652 | |
| 653 | state = malloc(sizeof *state); |
| 654 | if (state == NULL) |
| 655 | return NULL; |
| 656 | |
Louis-Francis Ratté-Boulianne | b482dbd | 2013-11-19 11:37:11 +0100 | [diff] [blame] | 657 | state->keyboard_focus = NULL; |
Kristian Høgsberg | 2f5faff | 2012-07-31 16:36:34 -0400 | [diff] [blame] | 658 | state->ws = ws; |
Jonas Ådahl | 0476974 | 2012-06-13 00:01:24 +0200 | [diff] [blame] | 659 | state->seat = seat; |
Kristian Høgsberg | 2f5faff | 2012-07-31 16:36:34 -0400 | [diff] [blame] | 660 | wl_list_insert(&ws->focus_list, &state->link); |
Jonas Ådahl | 0476974 | 2012-06-13 00:01:24 +0200 | [diff] [blame] | 661 | |
| 662 | state->seat_destroy_listener.notify = focus_state_seat_destroy; |
| 663 | state->surface_destroy_listener.notify = focus_state_surface_destroy; |
Kristian Høgsberg | 4912454 | 2013-05-06 22:27:40 -0400 | [diff] [blame] | 664 | wl_signal_add(&seat->destroy_signal, |
Jonas Ådahl | 0476974 | 2012-06-13 00:01:24 +0200 | [diff] [blame] | 665 | &state->seat_destroy_listener); |
Kristian Høgsberg | 2f5faff | 2012-07-31 16:36:34 -0400 | [diff] [blame] | 666 | wl_list_init(&state->surface_destroy_listener.link); |
Jonas Ådahl | 0476974 | 2012-06-13 00:01:24 +0200 | [diff] [blame] | 667 | |
| 668 | return state; |
| 669 | } |
| 670 | |
Jonas Ådahl | 8538b22 | 2012-08-29 22:13:03 +0200 | [diff] [blame] | 671 | static struct focus_state * |
| 672 | ensure_focus_state(struct desktop_shell *shell, struct weston_seat *seat) |
| 673 | { |
| 674 | struct workspace *ws = get_current_workspace(shell); |
| 675 | struct focus_state *state; |
| 676 | |
| 677 | wl_list_for_each(state, &ws->focus_list, link) |
| 678 | if (state->seat == seat) |
| 679 | break; |
| 680 | |
| 681 | if (&state->link == &ws->focus_list) |
| 682 | state = focus_state_create(seat, ws); |
| 683 | |
| 684 | return state; |
| 685 | } |
| 686 | |
Jonas Ådahl | 0476974 | 2012-06-13 00:01:24 +0200 | [diff] [blame] | 687 | static void |
Kristian Høgsberg | d500bf1 | 2014-01-22 12:25:20 -0800 | [diff] [blame] | 688 | focus_state_set_focus(struct focus_state *state, |
| 689 | struct weston_surface *surface) |
| 690 | { |
| 691 | if (state->keyboard_focus) { |
| 692 | wl_list_remove(&state->surface_destroy_listener.link); |
| 693 | wl_list_init(&state->surface_destroy_listener.link); |
| 694 | } |
| 695 | |
| 696 | state->keyboard_focus = surface; |
| 697 | if (surface) |
| 698 | wl_signal_add(&surface->destroy_signal, |
| 699 | &state->surface_destroy_listener); |
| 700 | } |
| 701 | |
| 702 | static void |
Kristian Høgsberg | 2f5faff | 2012-07-31 16:36:34 -0400 | [diff] [blame] | 703 | restore_focus_state(struct desktop_shell *shell, struct workspace *ws) |
Jonas Ådahl | 0476974 | 2012-06-13 00:01:24 +0200 | [diff] [blame] | 704 | { |
| 705 | struct focus_state *state, *next; |
Kristian Høgsberg | fe7aa90 | 2013-05-08 09:54:37 -0400 | [diff] [blame] | 706 | struct weston_surface *surface; |
Neil Roberts | 4237f50 | 2014-04-09 16:33:31 +0100 | [diff] [blame] | 707 | struct wl_list pending_seat_list; |
| 708 | struct weston_seat *seat, *next_seat; |
| 709 | |
| 710 | /* Temporarily steal the list of seats so that we can keep |
| 711 | * track of the seats we've already processed */ |
| 712 | wl_list_init(&pending_seat_list); |
| 713 | wl_list_insert_list(&pending_seat_list, &shell->compositor->seat_list); |
| 714 | wl_list_init(&shell->compositor->seat_list); |
Jonas Ådahl | 0476974 | 2012-06-13 00:01:24 +0200 | [diff] [blame] | 715 | |
| 716 | wl_list_for_each_safe(state, next, &ws->focus_list, link) { |
Neil Roberts | 4237f50 | 2014-04-09 16:33:31 +0100 | [diff] [blame] | 717 | wl_list_remove(&state->seat->link); |
| 718 | wl_list_insert(&shell->compositor->seat_list, |
| 719 | &state->seat->link); |
| 720 | |
Kristian Høgsberg | e61d2f4 | 2014-01-17 12:18:53 -0800 | [diff] [blame] | 721 | if (state->seat->keyboard == NULL) |
| 722 | continue; |
| 723 | |
Kristian Høgsberg | fe7aa90 | 2013-05-08 09:54:37 -0400 | [diff] [blame] | 724 | surface = state->keyboard_focus; |
Jonas Ådahl | 5689944 | 2012-08-29 22:12:59 +0200 | [diff] [blame] | 725 | |
Kristian Høgsberg | e314875 | 2013-05-06 23:19:49 -0400 | [diff] [blame] | 726 | weston_keyboard_set_focus(state->seat->keyboard, surface); |
Jonas Ådahl | 0476974 | 2012-06-13 00:01:24 +0200 | [diff] [blame] | 727 | } |
Neil Roberts | 4237f50 | 2014-04-09 16:33:31 +0100 | [diff] [blame] | 728 | |
| 729 | /* For any remaining seats that we don't have a focus state |
| 730 | * for we'll reset the keyboard focus to NULL */ |
| 731 | wl_list_for_each_safe(seat, next_seat, &pending_seat_list, link) { |
| 732 | wl_list_insert(&shell->compositor->seat_list, &seat->link); |
| 733 | |
| 734 | if (state->seat->keyboard == NULL) |
| 735 | continue; |
| 736 | |
| 737 | weston_keyboard_set_focus(seat->keyboard, NULL); |
| 738 | } |
Jonas Ådahl | 0476974 | 2012-06-13 00:01:24 +0200 | [diff] [blame] | 739 | } |
| 740 | |
| 741 | static void |
Jonas Ådahl | 8de6a1d | 2012-08-29 22:13:00 +0200 | [diff] [blame] | 742 | replace_focus_state(struct desktop_shell *shell, struct workspace *ws, |
| 743 | struct weston_seat *seat) |
| 744 | { |
| 745 | struct focus_state *state; |
Jonas Ådahl | 8de6a1d | 2012-08-29 22:13:00 +0200 | [diff] [blame] | 746 | |
| 747 | wl_list_for_each(state, &ws->focus_list, link) { |
| 748 | if (state->seat == seat) { |
Kristian Høgsberg | d500bf1 | 2014-01-22 12:25:20 -0800 | [diff] [blame] | 749 | focus_state_set_focus(state, seat->keyboard->focus); |
Jonas Ådahl | 8de6a1d | 2012-08-29 22:13:00 +0200 | [diff] [blame] | 750 | return; |
| 751 | } |
| 752 | } |
| 753 | } |
| 754 | |
| 755 | static void |
| 756 | drop_focus_state(struct desktop_shell *shell, struct workspace *ws, |
| 757 | struct weston_surface *surface) |
| 758 | { |
| 759 | struct focus_state *state; |
| 760 | |
| 761 | wl_list_for_each(state, &ws->focus_list, link) |
| 762 | if (state->keyboard_focus == surface) |
Kristian Høgsberg | d500bf1 | 2014-01-22 12:25:20 -0800 | [diff] [blame] | 763 | focus_state_set_focus(state, NULL); |
Jonas Ådahl | 8de6a1d | 2012-08-29 22:13:00 +0200 | [diff] [blame] | 764 | } |
| 765 | |
| 766 | static void |
Louis-Francis Ratté-Boulianne | b482dbd | 2013-11-19 11:37:11 +0100 | [diff] [blame] | 767 | animate_focus_change(struct desktop_shell *shell, struct workspace *ws, |
| 768 | struct weston_view *from, struct weston_view *to) |
| 769 | { |
| 770 | struct weston_output *output; |
| 771 | bool focus_surface_created = false; |
| 772 | |
| 773 | /* FIXME: Only support dim animation using two layers */ |
| 774 | if (from == to || shell->focus_animation_type != ANIMATION_DIM_LAYER) |
| 775 | return; |
| 776 | |
| 777 | output = get_default_output(shell->compositor); |
| 778 | if (ws->fsurf_front == NULL && (from || to)) { |
| 779 | ws->fsurf_front = create_focus_surface(shell->compositor, output); |
U. Artie Eoff | 0b23b2b | 2014-01-15 14:45:59 -0800 | [diff] [blame] | 780 | if (ws->fsurf_front == NULL) |
| 781 | return; |
Louis-Francis Ratté-Boulianne | b482dbd | 2013-11-19 11:37:11 +0100 | [diff] [blame] | 782 | ws->fsurf_front->view->alpha = 0.0; |
U. Artie Eoff | 0b23b2b | 2014-01-15 14:45:59 -0800 | [diff] [blame] | 783 | |
| 784 | ws->fsurf_back = create_focus_surface(shell->compositor, output); |
| 785 | if (ws->fsurf_back == NULL) { |
| 786 | focus_surface_destroy(ws->fsurf_front); |
| 787 | return; |
| 788 | } |
Louis-Francis Ratté-Boulianne | b482dbd | 2013-11-19 11:37:11 +0100 | [diff] [blame] | 789 | ws->fsurf_back->view->alpha = 0.0; |
U. Artie Eoff | 0b23b2b | 2014-01-15 14:45:59 -0800 | [diff] [blame] | 790 | |
Louis-Francis Ratté-Boulianne | b482dbd | 2013-11-19 11:37:11 +0100 | [diff] [blame] | 791 | focus_surface_created = true; |
| 792 | } else { |
| 793 | wl_list_remove(&ws->fsurf_front->view->layer_link); |
| 794 | wl_list_remove(&ws->fsurf_back->view->layer_link); |
| 795 | } |
| 796 | |
| 797 | if (ws->focus_animation) { |
| 798 | weston_view_animation_destroy(ws->focus_animation); |
| 799 | ws->focus_animation = NULL; |
| 800 | } |
| 801 | |
| 802 | if (to) |
| 803 | wl_list_insert(&to->layer_link, |
| 804 | &ws->fsurf_front->view->layer_link); |
| 805 | else if (from) |
| 806 | wl_list_insert(&ws->layer.view_list, |
| 807 | &ws->fsurf_front->view->layer_link); |
| 808 | |
| 809 | if (focus_surface_created) { |
| 810 | ws->focus_animation = weston_fade_run( |
| 811 | ws->fsurf_front->view, |
| 812 | ws->fsurf_front->view->alpha, 0.6, 300, |
| 813 | focus_animation_done, ws); |
| 814 | } else if (from) { |
| 815 | wl_list_insert(&from->layer_link, |
| 816 | &ws->fsurf_back->view->layer_link); |
| 817 | ws->focus_animation = weston_stable_fade_run( |
| 818 | ws->fsurf_front->view, 0.0, |
| 819 | ws->fsurf_back->view, 0.6, |
| 820 | focus_animation_done, ws); |
| 821 | } else if (to) { |
| 822 | wl_list_insert(&ws->layer.view_list, |
| 823 | &ws->fsurf_back->view->layer_link); |
| 824 | ws->focus_animation = weston_stable_fade_run( |
| 825 | ws->fsurf_front->view, 0.0, |
| 826 | ws->fsurf_back->view, 0.6, |
| 827 | focus_animation_done, ws); |
| 828 | } |
| 829 | } |
| 830 | |
| 831 | static void |
Jonas Ådahl | e3cddce | 2012-06-13 00:01:22 +0200 | [diff] [blame] | 832 | workspace_destroy(struct workspace *ws) |
| 833 | { |
Jonas Ådahl | 0476974 | 2012-06-13 00:01:24 +0200 | [diff] [blame] | 834 | struct focus_state *state, *next; |
| 835 | |
| 836 | wl_list_for_each_safe(state, next, &ws->focus_list, link) |
| 837 | focus_state_destroy(state); |
| 838 | |
Louis-Francis Ratté-Boulianne | b482dbd | 2013-11-19 11:37:11 +0100 | [diff] [blame] | 839 | if (ws->fsurf_front) |
| 840 | focus_surface_destroy(ws->fsurf_front); |
| 841 | if (ws->fsurf_back) |
| 842 | focus_surface_destroy(ws->fsurf_back); |
| 843 | |
Jonas Ådahl | e3cddce | 2012-06-13 00:01:22 +0200 | [diff] [blame] | 844 | free(ws); |
| 845 | } |
| 846 | |
Jonas Ådahl | 0476974 | 2012-06-13 00:01:24 +0200 | [diff] [blame] | 847 | static void |
| 848 | seat_destroyed(struct wl_listener *listener, void *data) |
| 849 | { |
| 850 | struct weston_seat *seat = data; |
| 851 | struct focus_state *state, *next; |
| 852 | struct workspace *ws = container_of(listener, |
| 853 | struct workspace, |
| 854 | seat_destroyed_listener); |
| 855 | |
| 856 | wl_list_for_each_safe(state, next, &ws->focus_list, link) |
| 857 | if (state->seat == seat) |
| 858 | wl_list_remove(&state->link); |
| 859 | } |
| 860 | |
Jonas Ådahl | e3cddce | 2012-06-13 00:01:22 +0200 | [diff] [blame] | 861 | static struct workspace * |
| 862 | workspace_create(void) |
| 863 | { |
| 864 | struct workspace *ws = malloc(sizeof *ws); |
| 865 | if (ws == NULL) |
| 866 | return NULL; |
| 867 | |
| 868 | weston_layer_init(&ws->layer, NULL); |
| 869 | |
Jonas Ådahl | 0476974 | 2012-06-13 00:01:24 +0200 | [diff] [blame] | 870 | wl_list_init(&ws->focus_list); |
| 871 | wl_list_init(&ws->seat_destroyed_listener.link); |
| 872 | ws->seat_destroyed_listener.notify = seat_destroyed; |
Louis-Francis Ratté-Boulianne | b482dbd | 2013-11-19 11:37:11 +0100 | [diff] [blame] | 873 | ws->fsurf_front = NULL; |
| 874 | ws->fsurf_back = NULL; |
| 875 | ws->focus_animation = NULL; |
Jonas Ådahl | 0476974 | 2012-06-13 00:01:24 +0200 | [diff] [blame] | 876 | |
Jonas Ådahl | e3cddce | 2012-06-13 00:01:22 +0200 | [diff] [blame] | 877 | return ws; |
| 878 | } |
| 879 | |
Jonas Ådahl | 62fcd04 | 2012-06-13 00:01:23 +0200 | [diff] [blame] | 880 | static int |
| 881 | workspace_is_empty(struct workspace *ws) |
| 882 | { |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 883 | return wl_list_empty(&ws->layer.view_list); |
Jonas Ådahl | 62fcd04 | 2012-06-13 00:01:23 +0200 | [diff] [blame] | 884 | } |
| 885 | |
Jonas Ådahl | e3cddce | 2012-06-13 00:01:22 +0200 | [diff] [blame] | 886 | static struct workspace * |
| 887 | get_workspace(struct desktop_shell *shell, unsigned int index) |
| 888 | { |
| 889 | struct workspace **pws = shell->workspaces.array.data; |
Philipp Brüschweiler | 067abf6 | 2012-09-01 16:03:05 +0200 | [diff] [blame] | 890 | assert(index < shell->workspaces.num); |
Jonas Ådahl | e3cddce | 2012-06-13 00:01:22 +0200 | [diff] [blame] | 891 | pws += index; |
| 892 | return *pws; |
| 893 | } |
| 894 | |
Kristian Høgsberg | 1ef2313 | 2013-12-04 00:20:01 -0800 | [diff] [blame] | 895 | struct workspace * |
Jonas Ådahl | e3cddce | 2012-06-13 00:01:22 +0200 | [diff] [blame] | 896 | get_current_workspace(struct desktop_shell *shell) |
| 897 | { |
| 898 | return get_workspace(shell, shell->workspaces.current); |
| 899 | } |
| 900 | |
| 901 | static void |
| 902 | activate_workspace(struct desktop_shell *shell, unsigned int index) |
| 903 | { |
| 904 | struct workspace *ws; |
| 905 | |
| 906 | ws = get_workspace(shell, index); |
| 907 | wl_list_insert(&shell->panel_layer.link, &ws->layer.link); |
| 908 | |
| 909 | shell->workspaces.current = index; |
| 910 | } |
| 911 | |
Jonas Ådahl | 62fcd04 | 2012-06-13 00:01:23 +0200 | [diff] [blame] | 912 | static unsigned int |
| 913 | get_output_height(struct weston_output *output) |
| 914 | { |
| 915 | return abs(output->region.extents.y1 - output->region.extents.y2); |
| 916 | } |
| 917 | |
| 918 | static void |
Louis-Francis Ratté-Boulianne | b482dbd | 2013-11-19 11:37:11 +0100 | [diff] [blame] | 919 | view_translate(struct workspace *ws, struct weston_view *view, double d) |
Jonas Ådahl | 62fcd04 | 2012-06-13 00:01:23 +0200 | [diff] [blame] | 920 | { |
Jonas Ådahl | 62fcd04 | 2012-06-13 00:01:23 +0200 | [diff] [blame] | 921 | struct weston_transform *transform; |
| 922 | |
Louis-Francis Ratté-Boulianne | b482dbd | 2013-11-19 11:37:11 +0100 | [diff] [blame] | 923 | if (is_focus_view(view)) { |
| 924 | struct focus_surface *fsurf = get_focus_surface(view->surface); |
| 925 | transform = &fsurf->workspace_transform; |
| 926 | } else { |
| 927 | struct shell_surface *shsurf = get_shell_surface(view->surface); |
| 928 | transform = &shsurf->workspace_transform; |
| 929 | } |
| 930 | |
Jonas Ådahl | 62fcd04 | 2012-06-13 00:01:23 +0200 | [diff] [blame] | 931 | if (wl_list_empty(&transform->link)) |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 932 | wl_list_insert(view->geometry.transformation_list.prev, |
Louis-Francis Ratté-Boulianne | b482dbd | 2013-11-19 11:37:11 +0100 | [diff] [blame] | 933 | &transform->link); |
Jonas Ådahl | 62fcd04 | 2012-06-13 00:01:23 +0200 | [diff] [blame] | 934 | |
Louis-Francis Ratté-Boulianne | b482dbd | 2013-11-19 11:37:11 +0100 | [diff] [blame] | 935 | weston_matrix_init(&transform->matrix); |
| 936 | weston_matrix_translate(&transform->matrix, |
Jonas Ådahl | 62fcd04 | 2012-06-13 00:01:23 +0200 | [diff] [blame] | 937 | 0.0, d, 0.0); |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 938 | weston_view_geometry_dirty(view); |
Jonas Ådahl | 62fcd04 | 2012-06-13 00:01:23 +0200 | [diff] [blame] | 939 | } |
| 940 | |
| 941 | static void |
| 942 | workspace_translate_out(struct workspace *ws, double fraction) |
| 943 | { |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 944 | struct weston_view *view; |
Jonas Ådahl | 62fcd04 | 2012-06-13 00:01:23 +0200 | [diff] [blame] | 945 | unsigned int height; |
| 946 | double d; |
| 947 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 948 | wl_list_for_each(view, &ws->layer.view_list, layer_link) { |
| 949 | height = get_output_height(view->surface->output); |
Jonas Ådahl | 62fcd04 | 2012-06-13 00:01:23 +0200 | [diff] [blame] | 950 | d = height * fraction; |
| 951 | |
Louis-Francis Ratté-Boulianne | b482dbd | 2013-11-19 11:37:11 +0100 | [diff] [blame] | 952 | view_translate(ws, view, d); |
Jonas Ådahl | 62fcd04 | 2012-06-13 00:01:23 +0200 | [diff] [blame] | 953 | } |
| 954 | } |
| 955 | |
| 956 | static void |
| 957 | workspace_translate_in(struct workspace *ws, double fraction) |
| 958 | { |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 959 | struct weston_view *view; |
Jonas Ådahl | 62fcd04 | 2012-06-13 00:01:23 +0200 | [diff] [blame] | 960 | unsigned int height; |
| 961 | double d; |
| 962 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 963 | wl_list_for_each(view, &ws->layer.view_list, layer_link) { |
| 964 | height = get_output_height(view->surface->output); |
Jonas Ådahl | 62fcd04 | 2012-06-13 00:01:23 +0200 | [diff] [blame] | 965 | |
| 966 | if (fraction > 0) |
| 967 | d = -(height - height * fraction); |
| 968 | else |
| 969 | d = height + height * fraction; |
| 970 | |
Louis-Francis Ratté-Boulianne | b482dbd | 2013-11-19 11:37:11 +0100 | [diff] [blame] | 971 | view_translate(ws, view, d); |
Jonas Ådahl | 62fcd04 | 2012-06-13 00:01:23 +0200 | [diff] [blame] | 972 | } |
| 973 | } |
| 974 | |
| 975 | static void |
Jonas Ådahl | e9d2250 | 2012-08-29 22:13:01 +0200 | [diff] [blame] | 976 | broadcast_current_workspace_state(struct desktop_shell *shell) |
| 977 | { |
Kristian Høgsberg | 2e3c396 | 2013-09-11 12:00:47 -0700 | [diff] [blame] | 978 | struct wl_resource *resource; |
Jonas Ådahl | e9d2250 | 2012-08-29 22:13:01 +0200 | [diff] [blame] | 979 | |
Kristian Høgsberg | 2e3c396 | 2013-09-11 12:00:47 -0700 | [diff] [blame] | 980 | wl_resource_for_each(resource, &shell->workspaces.client_list) |
| 981 | workspace_manager_send_state(resource, |
Jonas Ådahl | e9d2250 | 2012-08-29 22:13:01 +0200 | [diff] [blame] | 982 | shell->workspaces.current, |
| 983 | shell->workspaces.num); |
| 984 | } |
| 985 | |
| 986 | static void |
Jonas Ådahl | 62fcd04 | 2012-06-13 00:01:23 +0200 | [diff] [blame] | 987 | reverse_workspace_change_animation(struct desktop_shell *shell, |
| 988 | unsigned int index, |
| 989 | struct workspace *from, |
| 990 | struct workspace *to) |
| 991 | { |
| 992 | shell->workspaces.current = index; |
| 993 | |
| 994 | shell->workspaces.anim_to = to; |
| 995 | shell->workspaces.anim_from = from; |
| 996 | shell->workspaces.anim_dir = -1 * shell->workspaces.anim_dir; |
| 997 | shell->workspaces.anim_timestamp = 0; |
| 998 | |
Scott Moreau | 4272e63 | 2012-08-13 09:58:41 -0600 | [diff] [blame] | 999 | weston_compositor_schedule_repaint(shell->compositor); |
Jonas Ådahl | 62fcd04 | 2012-06-13 00:01:23 +0200 | [diff] [blame] | 1000 | } |
| 1001 | |
| 1002 | static void |
| 1003 | workspace_deactivate_transforms(struct workspace *ws) |
| 1004 | { |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 1005 | struct weston_view *view; |
Louis-Francis Ratté-Boulianne | b482dbd | 2013-11-19 11:37:11 +0100 | [diff] [blame] | 1006 | struct weston_transform *transform; |
Jonas Ådahl | 62fcd04 | 2012-06-13 00:01:23 +0200 | [diff] [blame] | 1007 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 1008 | wl_list_for_each(view, &ws->layer.view_list, layer_link) { |
Louis-Francis Ratté-Boulianne | b482dbd | 2013-11-19 11:37:11 +0100 | [diff] [blame] | 1009 | if (is_focus_view(view)) { |
| 1010 | struct focus_surface *fsurf = get_focus_surface(view->surface); |
| 1011 | transform = &fsurf->workspace_transform; |
| 1012 | } else { |
| 1013 | struct shell_surface *shsurf = get_shell_surface(view->surface); |
| 1014 | transform = &shsurf->workspace_transform; |
| 1015 | } |
| 1016 | |
| 1017 | if (!wl_list_empty(&transform->link)) { |
| 1018 | wl_list_remove(&transform->link); |
| 1019 | wl_list_init(&transform->link); |
Jonas Ådahl | 8de6a1d | 2012-08-29 22:13:00 +0200 | [diff] [blame] | 1020 | } |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 1021 | weston_view_geometry_dirty(view); |
Jonas Ådahl | 62fcd04 | 2012-06-13 00:01:23 +0200 | [diff] [blame] | 1022 | } |
| 1023 | } |
| 1024 | |
| 1025 | static void |
| 1026 | finish_workspace_change_animation(struct desktop_shell *shell, |
| 1027 | struct workspace *from, |
| 1028 | struct workspace *to) |
| 1029 | { |
Scott Moreau | 4272e63 | 2012-08-13 09:58:41 -0600 | [diff] [blame] | 1030 | weston_compositor_schedule_repaint(shell->compositor); |
Jonas Ådahl | 62fcd04 | 2012-06-13 00:01:23 +0200 | [diff] [blame] | 1031 | |
| 1032 | wl_list_remove(&shell->workspaces.animation.link); |
| 1033 | workspace_deactivate_transforms(from); |
| 1034 | workspace_deactivate_transforms(to); |
| 1035 | shell->workspaces.anim_to = NULL; |
| 1036 | |
| 1037 | wl_list_remove(&shell->workspaces.anim_from->layer.link); |
| 1038 | } |
| 1039 | |
| 1040 | static void |
| 1041 | animate_workspace_change_frame(struct weston_animation *animation, |
| 1042 | struct weston_output *output, uint32_t msecs) |
| 1043 | { |
| 1044 | struct desktop_shell *shell = |
| 1045 | container_of(animation, struct desktop_shell, |
| 1046 | workspaces.animation); |
| 1047 | struct workspace *from = shell->workspaces.anim_from; |
| 1048 | struct workspace *to = shell->workspaces.anim_to; |
| 1049 | uint32_t t; |
| 1050 | double x, y; |
| 1051 | |
| 1052 | if (workspace_is_empty(from) && workspace_is_empty(to)) { |
| 1053 | finish_workspace_change_animation(shell, from, to); |
| 1054 | return; |
| 1055 | } |
| 1056 | |
| 1057 | if (shell->workspaces.anim_timestamp == 0) { |
| 1058 | if (shell->workspaces.anim_current == 0.0) |
| 1059 | shell->workspaces.anim_timestamp = msecs; |
| 1060 | else |
| 1061 | shell->workspaces.anim_timestamp = |
| 1062 | msecs - |
| 1063 | /* Invers of movement function 'y' below. */ |
| 1064 | (asin(1.0 - shell->workspaces.anim_current) * |
| 1065 | DEFAULT_WORKSPACE_CHANGE_ANIMATION_LENGTH * |
| 1066 | M_2_PI); |
| 1067 | } |
| 1068 | |
| 1069 | t = msecs - shell->workspaces.anim_timestamp; |
| 1070 | |
| 1071 | /* |
| 1072 | * x = [0, π/2] |
| 1073 | * y(x) = sin(x) |
| 1074 | */ |
| 1075 | x = t * (1.0/DEFAULT_WORKSPACE_CHANGE_ANIMATION_LENGTH) * M_PI_2; |
| 1076 | y = sin(x); |
| 1077 | |
| 1078 | if (t < DEFAULT_WORKSPACE_CHANGE_ANIMATION_LENGTH) { |
Scott Moreau | 4272e63 | 2012-08-13 09:58:41 -0600 | [diff] [blame] | 1079 | weston_compositor_schedule_repaint(shell->compositor); |
Jonas Ådahl | 62fcd04 | 2012-06-13 00:01:23 +0200 | [diff] [blame] | 1080 | |
| 1081 | workspace_translate_out(from, shell->workspaces.anim_dir * y); |
| 1082 | workspace_translate_in(to, shell->workspaces.anim_dir * y); |
| 1083 | shell->workspaces.anim_current = y; |
| 1084 | |
Scott Moreau | 4272e63 | 2012-08-13 09:58:41 -0600 | [diff] [blame] | 1085 | weston_compositor_schedule_repaint(shell->compositor); |
Jonas Ådahl | 62fcd04 | 2012-06-13 00:01:23 +0200 | [diff] [blame] | 1086 | } |
Jonas Ådahl | 0476974 | 2012-06-13 00:01:24 +0200 | [diff] [blame] | 1087 | else |
Jonas Ådahl | 62fcd04 | 2012-06-13 00:01:23 +0200 | [diff] [blame] | 1088 | finish_workspace_change_animation(shell, from, to); |
Jonas Ådahl | 62fcd04 | 2012-06-13 00:01:23 +0200 | [diff] [blame] | 1089 | } |
| 1090 | |
| 1091 | static void |
| 1092 | animate_workspace_change(struct desktop_shell *shell, |
| 1093 | unsigned int index, |
| 1094 | struct workspace *from, |
| 1095 | struct workspace *to) |
| 1096 | { |
| 1097 | struct weston_output *output; |
| 1098 | |
| 1099 | int dir; |
| 1100 | |
| 1101 | if (index > shell->workspaces.current) |
| 1102 | dir = -1; |
| 1103 | else |
| 1104 | dir = 1; |
| 1105 | |
| 1106 | shell->workspaces.current = index; |
| 1107 | |
| 1108 | shell->workspaces.anim_dir = dir; |
| 1109 | shell->workspaces.anim_from = from; |
| 1110 | shell->workspaces.anim_to = to; |
| 1111 | shell->workspaces.anim_current = 0.0; |
| 1112 | shell->workspaces.anim_timestamp = 0; |
| 1113 | |
| 1114 | output = container_of(shell->compositor->output_list.next, |
| 1115 | struct weston_output, link); |
| 1116 | wl_list_insert(&output->animation_list, |
| 1117 | &shell->workspaces.animation.link); |
| 1118 | |
Jonas Ådahl | 8de6a1d | 2012-08-29 22:13:00 +0200 | [diff] [blame] | 1119 | wl_list_insert(from->layer.link.prev, &to->layer.link); |
Jonas Ådahl | 62fcd04 | 2012-06-13 00:01:23 +0200 | [diff] [blame] | 1120 | |
| 1121 | workspace_translate_in(to, 0); |
| 1122 | |
Kristian Høgsberg | 2f5faff | 2012-07-31 16:36:34 -0400 | [diff] [blame] | 1123 | restore_focus_state(shell, to); |
Jonas Ådahl | 0476974 | 2012-06-13 00:01:24 +0200 | [diff] [blame] | 1124 | |
Scott Moreau | 4272e63 | 2012-08-13 09:58:41 -0600 | [diff] [blame] | 1125 | weston_compositor_schedule_repaint(shell->compositor); |
Jonas Ådahl | 62fcd04 | 2012-06-13 00:01:23 +0200 | [diff] [blame] | 1126 | } |
| 1127 | |
Jonas Ådahl | e3cddce | 2012-06-13 00:01:22 +0200 | [diff] [blame] | 1128 | static void |
Jonas Ådahl | 8de6a1d | 2012-08-29 22:13:00 +0200 | [diff] [blame] | 1129 | update_workspace(struct desktop_shell *shell, unsigned int index, |
| 1130 | struct workspace *from, struct workspace *to) |
| 1131 | { |
| 1132 | shell->workspaces.current = index; |
| 1133 | wl_list_insert(&from->layer.link, &to->layer.link); |
| 1134 | wl_list_remove(&from->layer.link); |
| 1135 | } |
| 1136 | |
| 1137 | static void |
Jonas Ådahl | e3cddce | 2012-06-13 00:01:22 +0200 | [diff] [blame] | 1138 | change_workspace(struct desktop_shell *shell, unsigned int index) |
| 1139 | { |
| 1140 | struct workspace *from; |
| 1141 | struct workspace *to; |
Louis-Francis Ratté-Boulianne | b482dbd | 2013-11-19 11:37:11 +0100 | [diff] [blame] | 1142 | struct focus_state *state; |
Jonas Ådahl | e3cddce | 2012-06-13 00:01:22 +0200 | [diff] [blame] | 1143 | |
| 1144 | if (index == shell->workspaces.current) |
| 1145 | return; |
| 1146 | |
| 1147 | /* Don't change workspace when there is any fullscreen surfaces. */ |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 1148 | if (!wl_list_empty(&shell->fullscreen_layer.view_list)) |
Jonas Ådahl | e3cddce | 2012-06-13 00:01:22 +0200 | [diff] [blame] | 1149 | return; |
| 1150 | |
Jonas Ådahl | e3cddce | 2012-06-13 00:01:22 +0200 | [diff] [blame] | 1151 | from = get_current_workspace(shell); |
| 1152 | to = get_workspace(shell, index); |
| 1153 | |
Jonas Ådahl | 62fcd04 | 2012-06-13 00:01:23 +0200 | [diff] [blame] | 1154 | if (shell->workspaces.anim_from == to && |
| 1155 | shell->workspaces.anim_to == from) { |
Jonas Ådahl | 8de6a1d | 2012-08-29 22:13:00 +0200 | [diff] [blame] | 1156 | restore_focus_state(shell, to); |
Jonas Ådahl | 62fcd04 | 2012-06-13 00:01:23 +0200 | [diff] [blame] | 1157 | reverse_workspace_change_animation(shell, index, from, to); |
Jonas Ådahl | e9d2250 | 2012-08-29 22:13:01 +0200 | [diff] [blame] | 1158 | broadcast_current_workspace_state(shell); |
Jonas Ådahl | 62fcd04 | 2012-06-13 00:01:23 +0200 | [diff] [blame] | 1159 | return; |
| 1160 | } |
Jonas Ådahl | e3cddce | 2012-06-13 00:01:22 +0200 | [diff] [blame] | 1161 | |
Jonas Ådahl | 62fcd04 | 2012-06-13 00:01:23 +0200 | [diff] [blame] | 1162 | if (shell->workspaces.anim_to != NULL) |
| 1163 | finish_workspace_change_animation(shell, |
| 1164 | shell->workspaces.anim_from, |
| 1165 | shell->workspaces.anim_to); |
| 1166 | |
Jonas Ådahl | 8de6a1d | 2012-08-29 22:13:00 +0200 | [diff] [blame] | 1167 | restore_focus_state(shell, to); |
Jonas Ådahl | 0476974 | 2012-06-13 00:01:24 +0200 | [diff] [blame] | 1168 | |
Louis-Francis Ratté-Boulianne | b482dbd | 2013-11-19 11:37:11 +0100 | [diff] [blame] | 1169 | if (shell->focus_animation_type != ANIMATION_NONE) { |
| 1170 | wl_list_for_each(state, &from->focus_list, link) |
| 1171 | if (state->keyboard_focus) |
| 1172 | animate_focus_change(shell, from, |
| 1173 | get_default_view(state->keyboard_focus), NULL); |
| 1174 | |
| 1175 | wl_list_for_each(state, &to->focus_list, link) |
| 1176 | if (state->keyboard_focus) |
| 1177 | animate_focus_change(shell, to, |
| 1178 | NULL, get_default_view(state->keyboard_focus)); |
| 1179 | } |
| 1180 | |
Jonas Ådahl | 8de6a1d | 2012-08-29 22:13:00 +0200 | [diff] [blame] | 1181 | if (workspace_is_empty(to) && workspace_is_empty(from)) |
| 1182 | update_workspace(shell, index, from, to); |
Jonas Ådahl | 62fcd04 | 2012-06-13 00:01:23 +0200 | [diff] [blame] | 1183 | else |
| 1184 | animate_workspace_change(shell, index, from, to); |
Jonas Ådahl | e9d2250 | 2012-08-29 22:13:01 +0200 | [diff] [blame] | 1185 | |
| 1186 | broadcast_current_workspace_state(shell); |
Pekka Paalanen | e955f1e | 2011-12-07 11:49:52 +0200 | [diff] [blame] | 1187 | } |
| 1188 | |
Jonas Ådahl | 8de6a1d | 2012-08-29 22:13:00 +0200 | [diff] [blame] | 1189 | static bool |
| 1190 | workspace_has_only(struct workspace *ws, struct weston_surface *surface) |
| 1191 | { |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 1192 | struct wl_list *list = &ws->layer.view_list; |
Jonas Ådahl | 8de6a1d | 2012-08-29 22:13:00 +0200 | [diff] [blame] | 1193 | struct wl_list *e; |
| 1194 | |
| 1195 | if (wl_list_empty(list)) |
| 1196 | return false; |
| 1197 | |
| 1198 | e = list->next; |
| 1199 | |
| 1200 | if (e->next != list) |
| 1201 | return false; |
| 1202 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 1203 | return container_of(e, struct weston_view, layer_link)->surface == surface; |
Jonas Ådahl | 8de6a1d | 2012-08-29 22:13:00 +0200 | [diff] [blame] | 1204 | } |
| 1205 | |
| 1206 | static void |
Philip Withnall | 659163d | 2013-11-25 18:01:36 +0000 | [diff] [blame] | 1207 | move_surface_to_workspace(struct desktop_shell *shell, |
| 1208 | struct shell_surface *shsurf, |
| 1209 | uint32_t workspace) |
Jonas Ådahl | e9d2250 | 2012-08-29 22:13:01 +0200 | [diff] [blame] | 1210 | { |
| 1211 | struct workspace *from; |
| 1212 | struct workspace *to; |
| 1213 | struct weston_seat *seat; |
Pekka Paalanen | 01388e2 | 2013-04-25 13:57:44 +0300 | [diff] [blame] | 1214 | struct weston_surface *focus; |
Philip Withnall | 659163d | 2013-11-25 18:01:36 +0000 | [diff] [blame] | 1215 | struct weston_view *view; |
Jonas Ådahl | e9d2250 | 2012-08-29 22:13:01 +0200 | [diff] [blame] | 1216 | |
| 1217 | if (workspace == shell->workspaces.current) |
| 1218 | return; |
| 1219 | |
Philip Withnall | 659163d | 2013-11-25 18:01:36 +0000 | [diff] [blame] | 1220 | view = get_default_view(shsurf->surface); |
| 1221 | if (!view) |
| 1222 | return; |
| 1223 | |
| 1224 | assert(weston_surface_get_main_surface(view->surface) == view->surface); |
| 1225 | |
Philipp Brüschweiler | 067abf6 | 2012-09-01 16:03:05 +0200 | [diff] [blame] | 1226 | if (workspace >= shell->workspaces.num) |
| 1227 | workspace = shell->workspaces.num - 1; |
| 1228 | |
Jonas Ådahl | e9d2250 | 2012-08-29 22:13:01 +0200 | [diff] [blame] | 1229 | from = get_current_workspace(shell); |
| 1230 | to = get_workspace(shell, workspace); |
| 1231 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 1232 | wl_list_remove(&view->layer_link); |
| 1233 | wl_list_insert(&to->layer.view_list, &view->layer_link); |
Jonas Ådahl | e9d2250 | 2012-08-29 22:13:01 +0200 | [diff] [blame] | 1234 | |
Philip Withnall | 648a4dd | 2013-11-25 18:01:44 +0000 | [diff] [blame] | 1235 | shell_surface_update_child_surface_layers(shsurf); |
| 1236 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 1237 | drop_focus_state(shell, from, view->surface); |
Pekka Paalanen | 01388e2 | 2013-04-25 13:57:44 +0300 | [diff] [blame] | 1238 | wl_list_for_each(seat, &shell->compositor->seat_list, link) { |
| 1239 | if (!seat->keyboard) |
| 1240 | continue; |
| 1241 | |
| 1242 | focus = weston_surface_get_main_surface(seat->keyboard->focus); |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 1243 | if (focus == view->surface) |
Kristian Høgsberg | e314875 | 2013-05-06 23:19:49 -0400 | [diff] [blame] | 1244 | weston_keyboard_set_focus(seat->keyboard, NULL); |
Pekka Paalanen | 01388e2 | 2013-04-25 13:57:44 +0300 | [diff] [blame] | 1245 | } |
Jonas Ådahl | e9d2250 | 2012-08-29 22:13:01 +0200 | [diff] [blame] | 1246 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 1247 | weston_view_damage_below(view); |
Jonas Ådahl | e9d2250 | 2012-08-29 22:13:01 +0200 | [diff] [blame] | 1248 | } |
| 1249 | |
| 1250 | static void |
Jonas Ådahl | 8de6a1d | 2012-08-29 22:13:00 +0200 | [diff] [blame] | 1251 | take_surface_to_workspace_by_seat(struct desktop_shell *shell, |
Kristian Høgsberg | e314875 | 2013-05-06 23:19:49 -0400 | [diff] [blame] | 1252 | struct weston_seat *seat, |
Jonas Ådahl | 8de6a1d | 2012-08-29 22:13:00 +0200 | [diff] [blame] | 1253 | unsigned int index) |
| 1254 | { |
Pekka Paalanen | 01388e2 | 2013-04-25 13:57:44 +0300 | [diff] [blame] | 1255 | struct weston_surface *surface; |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 1256 | struct weston_view *view; |
Jonas Ådahl | 8de6a1d | 2012-08-29 22:13:00 +0200 | [diff] [blame] | 1257 | struct shell_surface *shsurf; |
| 1258 | struct workspace *from; |
| 1259 | struct workspace *to; |
Jonas Ådahl | 8538b22 | 2012-08-29 22:13:03 +0200 | [diff] [blame] | 1260 | struct focus_state *state; |
Jonas Ådahl | 8de6a1d | 2012-08-29 22:13:00 +0200 | [diff] [blame] | 1261 | |
Pekka Paalanen | 01388e2 | 2013-04-25 13:57:44 +0300 | [diff] [blame] | 1262 | surface = weston_surface_get_main_surface(seat->keyboard->focus); |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 1263 | view = get_default_view(surface); |
| 1264 | if (view == NULL || |
Louis-Francis Ratté-Boulianne | b482dbd | 2013-11-19 11:37:11 +0100 | [diff] [blame] | 1265 | index == shell->workspaces.current || |
| 1266 | is_focus_view(view)) |
Jonas Ådahl | 8de6a1d | 2012-08-29 22:13:00 +0200 | [diff] [blame] | 1267 | return; |
| 1268 | |
| 1269 | from = get_current_workspace(shell); |
| 1270 | to = get_workspace(shell, index); |
| 1271 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 1272 | wl_list_remove(&view->layer_link); |
| 1273 | wl_list_insert(&to->layer.view_list, &view->layer_link); |
Jonas Ådahl | 8de6a1d | 2012-08-29 22:13:00 +0200 | [diff] [blame] | 1274 | |
Philip Withnall | 659163d | 2013-11-25 18:01:36 +0000 | [diff] [blame] | 1275 | shsurf = get_shell_surface(surface); |
Philip Withnall | 648a4dd | 2013-11-25 18:01:44 +0000 | [diff] [blame] | 1276 | if (shsurf != NULL) |
| 1277 | shell_surface_update_child_surface_layers(shsurf); |
Philip Withnall | 659163d | 2013-11-25 18:01:36 +0000 | [diff] [blame] | 1278 | |
Jonas Ådahl | e9d2250 | 2012-08-29 22:13:01 +0200 | [diff] [blame] | 1279 | replace_focus_state(shell, to, seat); |
Jonas Ådahl | 8de6a1d | 2012-08-29 22:13:00 +0200 | [diff] [blame] | 1280 | drop_focus_state(shell, from, surface); |
| 1281 | |
| 1282 | if (shell->workspaces.anim_from == to && |
| 1283 | shell->workspaces.anim_to == from) { |
Jonas Ådahl | e9d2250 | 2012-08-29 22:13:01 +0200 | [diff] [blame] | 1284 | wl_list_remove(&to->layer.link); |
| 1285 | wl_list_insert(from->layer.link.prev, &to->layer.link); |
| 1286 | |
Jonas Ådahl | 8de6a1d | 2012-08-29 22:13:00 +0200 | [diff] [blame] | 1287 | reverse_workspace_change_animation(shell, index, from, to); |
Jonas Ådahl | e9d2250 | 2012-08-29 22:13:01 +0200 | [diff] [blame] | 1288 | broadcast_current_workspace_state(shell); |
| 1289 | |
Jonas Ådahl | 8de6a1d | 2012-08-29 22:13:00 +0200 | [diff] [blame] | 1290 | return; |
| 1291 | } |
| 1292 | |
| 1293 | if (shell->workspaces.anim_to != NULL) |
| 1294 | finish_workspace_change_animation(shell, |
| 1295 | shell->workspaces.anim_from, |
| 1296 | shell->workspaces.anim_to); |
| 1297 | |
| 1298 | if (workspace_is_empty(from) && |
| 1299 | workspace_has_only(to, surface)) |
| 1300 | update_workspace(shell, index, from, to); |
| 1301 | else { |
Philip Withnall | 2c3849b | 2013-11-25 18:01:45 +0000 | [diff] [blame] | 1302 | if (shsurf != NULL && |
| 1303 | wl_list_empty(&shsurf->workspace_transform.link)) |
Jonas Ådahl | 8de6a1d | 2012-08-29 22:13:00 +0200 | [diff] [blame] | 1304 | wl_list_insert(&shell->workspaces.anim_sticky_list, |
| 1305 | &shsurf->workspace_transform.link); |
| 1306 | |
| 1307 | animate_workspace_change(shell, index, from, to); |
| 1308 | } |
Jonas Ådahl | e9d2250 | 2012-08-29 22:13:01 +0200 | [diff] [blame] | 1309 | |
| 1310 | broadcast_current_workspace_state(shell); |
Jonas Ådahl | 8538b22 | 2012-08-29 22:13:03 +0200 | [diff] [blame] | 1311 | |
| 1312 | state = ensure_focus_state(shell, seat); |
| 1313 | if (state != NULL) |
Kristian Høgsberg | d500bf1 | 2014-01-22 12:25:20 -0800 | [diff] [blame] | 1314 | focus_state_set_focus(state, surface); |
Jonas Ådahl | e9d2250 | 2012-08-29 22:13:01 +0200 | [diff] [blame] | 1315 | } |
| 1316 | |
| 1317 | static void |
| 1318 | workspace_manager_move_surface(struct wl_client *client, |
| 1319 | struct wl_resource *resource, |
| 1320 | struct wl_resource *surface_resource, |
| 1321 | uint32_t workspace) |
| 1322 | { |
Jason Ekstrand | 651f00e | 2013-06-14 10:07:54 -0500 | [diff] [blame] | 1323 | struct desktop_shell *shell = wl_resource_get_user_data(resource); |
Jonas Ådahl | e9d2250 | 2012-08-29 22:13:01 +0200 | [diff] [blame] | 1324 | struct weston_surface *surface = |
Jason Ekstrand | 0f2ef7e | 2013-06-14 10:07:53 -0500 | [diff] [blame] | 1325 | wl_resource_get_user_data(surface_resource); |
Pekka Paalanen | 01388e2 | 2013-04-25 13:57:44 +0300 | [diff] [blame] | 1326 | struct weston_surface *main_surface; |
Philip Withnall | 659163d | 2013-11-25 18:01:36 +0000 | [diff] [blame] | 1327 | struct shell_surface *shell_surface; |
Jonas Ådahl | e9d2250 | 2012-08-29 22:13:01 +0200 | [diff] [blame] | 1328 | |
Pekka Paalanen | 01388e2 | 2013-04-25 13:57:44 +0300 | [diff] [blame] | 1329 | main_surface = weston_surface_get_main_surface(surface); |
Philip Withnall | 659163d | 2013-11-25 18:01:36 +0000 | [diff] [blame] | 1330 | shell_surface = get_shell_surface(main_surface); |
| 1331 | if (shell_surface == NULL) |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 1332 | return; |
Philip Withnall | 659163d | 2013-11-25 18:01:36 +0000 | [diff] [blame] | 1333 | |
| 1334 | move_surface_to_workspace(shell, shell_surface, workspace); |
Jonas Ådahl | e9d2250 | 2012-08-29 22:13:01 +0200 | [diff] [blame] | 1335 | } |
| 1336 | |
| 1337 | static const struct workspace_manager_interface workspace_manager_implementation = { |
| 1338 | workspace_manager_move_surface, |
| 1339 | }; |
| 1340 | |
| 1341 | static void |
| 1342 | unbind_resource(struct wl_resource *resource) |
| 1343 | { |
Jason Ekstrand | 651f00e | 2013-06-14 10:07:54 -0500 | [diff] [blame] | 1344 | wl_list_remove(wl_resource_get_link(resource)); |
Jonas Ådahl | e9d2250 | 2012-08-29 22:13:01 +0200 | [diff] [blame] | 1345 | } |
| 1346 | |
| 1347 | static void |
| 1348 | bind_workspace_manager(struct wl_client *client, |
| 1349 | void *data, uint32_t version, uint32_t id) |
| 1350 | { |
| 1351 | struct desktop_shell *shell = data; |
| 1352 | struct wl_resource *resource; |
| 1353 | |
Jason Ekstrand | a85118c | 2013-06-27 20:17:02 -0500 | [diff] [blame] | 1354 | resource = wl_resource_create(client, |
| 1355 | &workspace_manager_interface, 1, id); |
Jonas Ådahl | e9d2250 | 2012-08-29 22:13:01 +0200 | [diff] [blame] | 1356 | |
| 1357 | if (resource == NULL) { |
| 1358 | weston_log("couldn't add workspace manager object"); |
| 1359 | return; |
| 1360 | } |
| 1361 | |
Jason Ekstrand | a85118c | 2013-06-27 20:17:02 -0500 | [diff] [blame] | 1362 | wl_resource_set_implementation(resource, |
| 1363 | &workspace_manager_implementation, |
| 1364 | shell, unbind_resource); |
Jason Ekstrand | 651f00e | 2013-06-14 10:07:54 -0500 | [diff] [blame] | 1365 | wl_list_insert(&shell->workspaces.client_list, |
| 1366 | wl_resource_get_link(resource)); |
Jonas Ådahl | e9d2250 | 2012-08-29 22:13:01 +0200 | [diff] [blame] | 1367 | |
| 1368 | workspace_manager_send_state(resource, |
| 1369 | shell->workspaces.current, |
| 1370 | shell->workspaces.num); |
Jonas Ådahl | 8de6a1d | 2012-08-29 22:13:00 +0200 | [diff] [blame] | 1371 | } |
| 1372 | |
Pekka Paalanen | 56cdea9 | 2011-11-23 16:14:12 +0200 | [diff] [blame] | 1373 | static void |
Rusty Lynch | 1084da5 | 2013-08-15 09:10:08 -0700 | [diff] [blame] | 1374 | touch_move_grab_down(struct weston_touch_grab *grab, uint32_t time, |
| 1375 | int touch_id, wl_fixed_t sx, wl_fixed_t sy) |
| 1376 | { |
| 1377 | } |
| 1378 | |
| 1379 | static void |
| 1380 | touch_move_grab_up(struct weston_touch_grab *grab, uint32_t time, int touch_id) |
| 1381 | { |
Jonas Ådahl | 1c6e63e | 2013-10-25 23:18:04 +0200 | [diff] [blame] | 1382 | struct weston_touch_move_grab *move = |
| 1383 | (struct weston_touch_move_grab *) container_of( |
| 1384 | grab, struct shell_touch_grab, grab); |
Neil Roberts | e14aa4f | 2013-10-03 16:43:07 +0100 | [diff] [blame] | 1385 | |
Kristian Høgsberg | 8e80a31 | 2014-01-17 15:18:10 -0800 | [diff] [blame] | 1386 | if (touch_id == 0) |
| 1387 | move->active = 0; |
| 1388 | |
Jonas Ådahl | 9484b69 | 2013-12-02 22:05:03 +0100 | [diff] [blame] | 1389 | if (grab->touch->num_tp == 0) { |
Jonas Ådahl | 1c6e63e | 2013-10-25 23:18:04 +0200 | [diff] [blame] | 1390 | shell_touch_grab_end(&move->base); |
| 1391 | free(move); |
| 1392 | } |
Rusty Lynch | 1084da5 | 2013-08-15 09:10:08 -0700 | [diff] [blame] | 1393 | } |
| 1394 | |
| 1395 | static void |
| 1396 | touch_move_grab_motion(struct weston_touch_grab *grab, uint32_t time, |
| 1397 | int touch_id, wl_fixed_t sx, wl_fixed_t sy) |
| 1398 | { |
| 1399 | struct weston_touch_move_grab *move = (struct weston_touch_move_grab *) grab; |
| 1400 | struct shell_surface *shsurf = move->base.shsurf; |
| 1401 | struct weston_surface *es; |
| 1402 | int dx = wl_fixed_to_int(grab->touch->grab_x + move->dx); |
| 1403 | int dy = wl_fixed_to_int(grab->touch->grab_y + move->dy); |
| 1404 | |
Kristian Høgsberg | 8e80a31 | 2014-01-17 15:18:10 -0800 | [diff] [blame] | 1405 | if (!shsurf || !move->active) |
Rusty Lynch | 1084da5 | 2013-08-15 09:10:08 -0700 | [diff] [blame] | 1406 | return; |
| 1407 | |
| 1408 | es = shsurf->surface; |
| 1409 | |
Jason Ekstrand | 918f2dd | 2013-12-02 21:01:53 -0600 | [diff] [blame] | 1410 | weston_view_set_position(shsurf->view, dx, dy); |
Rusty Lynch | 1084da5 | 2013-08-15 09:10:08 -0700 | [diff] [blame] | 1411 | |
| 1412 | weston_compositor_schedule_repaint(es->compositor); |
| 1413 | } |
| 1414 | |
Jonas Ådahl | 1ea343e | 2013-10-25 23:18:05 +0200 | [diff] [blame] | 1415 | static void |
Jonas Ådahl | 1679f23 | 2014-04-12 09:39:51 +0200 | [diff] [blame] | 1416 | touch_move_grab_frame(struct weston_touch_grab *grab) |
| 1417 | { |
| 1418 | } |
| 1419 | |
| 1420 | static void |
Jonas Ådahl | 1ea343e | 2013-10-25 23:18:05 +0200 | [diff] [blame] | 1421 | touch_move_grab_cancel(struct weston_touch_grab *grab) |
| 1422 | { |
| 1423 | struct weston_touch_move_grab *move = |
| 1424 | (struct weston_touch_move_grab *) container_of( |
| 1425 | grab, struct shell_touch_grab, grab); |
| 1426 | |
| 1427 | shell_touch_grab_end(&move->base); |
| 1428 | free(move); |
| 1429 | } |
| 1430 | |
Rusty Lynch | 1084da5 | 2013-08-15 09:10:08 -0700 | [diff] [blame] | 1431 | static const struct weston_touch_grab_interface touch_move_grab_interface = { |
| 1432 | touch_move_grab_down, |
| 1433 | touch_move_grab_up, |
| 1434 | touch_move_grab_motion, |
Jonas Ådahl | 1679f23 | 2014-04-12 09:39:51 +0200 | [diff] [blame] | 1435 | touch_move_grab_frame, |
Jonas Ådahl | 1ea343e | 2013-10-25 23:18:05 +0200 | [diff] [blame] | 1436 | touch_move_grab_cancel, |
Rusty Lynch | 1084da5 | 2013-08-15 09:10:08 -0700 | [diff] [blame] | 1437 | }; |
| 1438 | |
| 1439 | static int |
| 1440 | surface_touch_move(struct shell_surface *shsurf, struct weston_seat *seat) |
| 1441 | { |
| 1442 | struct weston_touch_move_grab *move; |
| 1443 | |
| 1444 | if (!shsurf) |
| 1445 | return -1; |
| 1446 | |
Rafael Antognolli | 03b1659 | 2013-12-03 15:35:42 -0200 | [diff] [blame] | 1447 | if (shsurf->state.fullscreen) |
Rusty Lynch | 1084da5 | 2013-08-15 09:10:08 -0700 | [diff] [blame] | 1448 | return 0; |
| 1449 | |
| 1450 | move = malloc(sizeof *move); |
| 1451 | if (!move) |
| 1452 | return -1; |
| 1453 | |
Kristian Høgsberg | 8e80a31 | 2014-01-17 15:18:10 -0800 | [diff] [blame] | 1454 | move->active = 1; |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 1455 | move->dx = wl_fixed_from_double(shsurf->view->geometry.x) - |
Rusty Lynch | 1084da5 | 2013-08-15 09:10:08 -0700 | [diff] [blame] | 1456 | seat->touch->grab_x; |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 1457 | move->dy = wl_fixed_from_double(shsurf->view->geometry.y) - |
Rusty Lynch | 1084da5 | 2013-08-15 09:10:08 -0700 | [diff] [blame] | 1458 | seat->touch->grab_y; |
| 1459 | |
| 1460 | shell_touch_grab_start(&move->base, &touch_move_grab_interface, shsurf, |
| 1461 | seat->touch); |
| 1462 | |
| 1463 | return 0; |
| 1464 | } |
| 1465 | |
| 1466 | static void |
Kristian Høgsberg | 6848c25 | 2013-05-08 22:02:59 -0400 | [diff] [blame] | 1467 | noop_grab_focus(struct weston_pointer_grab *grab) |
Kristian Høgsberg | 9ddb826 | 2012-01-04 21:30:29 -0500 | [diff] [blame] | 1468 | { |
Kristian Høgsberg | 9ddb826 | 2012-01-04 21:30:29 -0500 | [diff] [blame] | 1469 | } |
| 1470 | |
| 1471 | static void |
Kristian Høgsberg | ae356ae | 2014-04-29 16:03:54 -0700 | [diff] [blame] | 1472 | constrain_position(struct weston_move_grab *move, int *cx, int *cy) |
| 1473 | { |
| 1474 | struct shell_surface *shsurf = move->base.shsurf; |
| 1475 | struct weston_pointer *pointer = move->base.grab.pointer; |
Kristian Høgsberg | 3434b33 | 2014-04-29 16:38:23 -0700 | [diff] [blame] | 1476 | int x, y, panel_height, bottom; |
Kristian Høgsberg | ae356ae | 2014-04-29 16:03:54 -0700 | [diff] [blame] | 1477 | const int safety = 50; |
| 1478 | |
| 1479 | x = wl_fixed_to_int(pointer->x + move->dx); |
| 1480 | y = wl_fixed_to_int(pointer->y + move->dy); |
| 1481 | |
| 1482 | panel_height = get_output_panel_height(shsurf->shell, |
| 1483 | shsurf->surface->output); |
| 1484 | bottom = y + shsurf->surface->height - shsurf->margin.bottom; |
| 1485 | if (bottom - panel_height < safety) |
| 1486 | y = panel_height + safety - |
| 1487 | shsurf->surface->height + shsurf->margin.bottom; |
| 1488 | |
| 1489 | if (move->client_initiated && |
| 1490 | y + shsurf->margin.top < panel_height) |
| 1491 | y = panel_height - shsurf->margin.top; |
| 1492 | |
| 1493 | *cx = x; |
| 1494 | *cy = y; |
| 1495 | } |
| 1496 | |
| 1497 | static void |
Giulio Camuffo | 1959ab8 | 2013-11-14 23:42:52 +0100 | [diff] [blame] | 1498 | move_grab_motion(struct weston_pointer_grab *grab, uint32_t time, |
| 1499 | wl_fixed_t x, wl_fixed_t y) |
Kristian Høgsberg | 4cca349 | 2011-01-18 07:53:49 -0500 | [diff] [blame] | 1500 | { |
Kristian Høgsberg | 8334bc1 | 2012-01-03 10:29:47 -0500 | [diff] [blame] | 1501 | struct weston_move_grab *move = (struct weston_move_grab *) grab; |
Kristian Høgsberg | 02bbabb | 2013-05-06 22:15:05 -0400 | [diff] [blame] | 1502 | struct weston_pointer *pointer = grab->pointer; |
Ander Conselvan de Oliveira | fe0444a | 2012-04-04 17:48:05 +0300 | [diff] [blame] | 1503 | struct shell_surface *shsurf = move->base.shsurf; |
Kristian Høgsberg | ae356ae | 2014-04-29 16:03:54 -0700 | [diff] [blame] | 1504 | int cx, cy; |
Giulio Camuffo | 1959ab8 | 2013-11-14 23:42:52 +0100 | [diff] [blame] | 1505 | |
| 1506 | weston_pointer_move(pointer, x, y); |
Ander Conselvan de Oliveira | fe0444a | 2012-04-04 17:48:05 +0300 | [diff] [blame] | 1507 | if (!shsurf) |
| 1508 | return; |
| 1509 | |
Kristian Høgsberg | ae356ae | 2014-04-29 16:03:54 -0700 | [diff] [blame] | 1510 | constrain_position(move, &cx, &cy); |
| 1511 | |
| 1512 | weston_view_set_position(shsurf->view, cx, cy); |
Kristian Høgsberg | 4cca349 | 2011-01-18 07:53:49 -0500 | [diff] [blame] | 1513 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 1514 | weston_compositor_schedule_repaint(shsurf->surface->compositor); |
Kristian Høgsberg | 4cca349 | 2011-01-18 07:53:49 -0500 | [diff] [blame] | 1515 | } |
| 1516 | |
| 1517 | static void |
Kristian Høgsberg | 02bbabb | 2013-05-06 22:15:05 -0400 | [diff] [blame] | 1518 | move_grab_button(struct weston_pointer_grab *grab, |
Daniel Stone | 4dbadb1 | 2012-05-30 16:31:51 +0100 | [diff] [blame] | 1519 | uint32_t time, uint32_t button, uint32_t state_w) |
Kristian Høgsberg | 4cca349 | 2011-01-18 07:53:49 -0500 | [diff] [blame] | 1520 | { |
Ander Conselvan de Oliveira | fe0444a | 2012-04-04 17:48:05 +0300 | [diff] [blame] | 1521 | struct shell_grab *shell_grab = container_of(grab, struct shell_grab, |
| 1522 | grab); |
Kristian Høgsberg | 02bbabb | 2013-05-06 22:15:05 -0400 | [diff] [blame] | 1523 | struct weston_pointer *pointer = grab->pointer; |
Daniel Stone | 4dbadb1 | 2012-05-30 16:31:51 +0100 | [diff] [blame] | 1524 | enum wl_pointer_button_state state = state_w; |
Kristian Høgsberg | 4cca349 | 2011-01-18 07:53:49 -0500 | [diff] [blame] | 1525 | |
Daniel Stone | 4dbadb1 | 2012-05-30 16:31:51 +0100 | [diff] [blame] | 1526 | if (pointer->button_count == 0 && |
| 1527 | state == WL_POINTER_BUTTON_STATE_RELEASED) { |
Ander Conselvan de Oliveira | b9d2a0f | 2012-06-28 18:08:05 +0300 | [diff] [blame] | 1528 | shell_grab_end(shell_grab); |
Kristian Høgsberg | 9ddb826 | 2012-01-04 21:30:29 -0500 | [diff] [blame] | 1529 | free(grab); |
| 1530 | } |
Kristian Høgsberg | 4cca349 | 2011-01-18 07:53:49 -0500 | [diff] [blame] | 1531 | } |
| 1532 | |
Jonas Ådahl | 1ea343e | 2013-10-25 23:18:05 +0200 | [diff] [blame] | 1533 | static void |
| 1534 | move_grab_cancel(struct weston_pointer_grab *grab) |
| 1535 | { |
| 1536 | struct shell_grab *shell_grab = |
| 1537 | container_of(grab, struct shell_grab, grab); |
| 1538 | |
| 1539 | shell_grab_end(shell_grab); |
| 1540 | free(grab); |
| 1541 | } |
| 1542 | |
Kristian Høgsberg | 02bbabb | 2013-05-06 22:15:05 -0400 | [diff] [blame] | 1543 | static const struct weston_pointer_grab_interface move_grab_interface = { |
Kristian Høgsberg | 9ddb826 | 2012-01-04 21:30:29 -0500 | [diff] [blame] | 1544 | noop_grab_focus, |
Kristian Høgsberg | 4cca349 | 2011-01-18 07:53:49 -0500 | [diff] [blame] | 1545 | move_grab_motion, |
| 1546 | move_grab_button, |
Jonas Ådahl | 1ea343e | 2013-10-25 23:18:05 +0200 | [diff] [blame] | 1547 | move_grab_cancel, |
Kristian Høgsberg | 4cca349 | 2011-01-18 07:53:49 -0500 | [diff] [blame] | 1548 | }; |
| 1549 | |
Kristian Høgsberg | 9e31bff | 2012-08-01 00:08:07 -0400 | [diff] [blame] | 1550 | static int |
Kristian Høgsberg | ae356ae | 2014-04-29 16:03:54 -0700 | [diff] [blame] | 1551 | surface_move(struct shell_surface *shsurf, struct weston_seat *seat, |
| 1552 | int client_initiated) |
Kristian Høgsberg | 9e31bff | 2012-08-01 00:08:07 -0400 | [diff] [blame] | 1553 | { |
| 1554 | struct weston_move_grab *move; |
| 1555 | |
| 1556 | if (!shsurf) |
| 1557 | return -1; |
| 1558 | |
Kristian Høgsberg | a4b620e | 2014-04-30 16:05:49 -0700 | [diff] [blame^] | 1559 | if (shsurf->grabbed || |
| 1560 | shsurf->state.fullscreen || shsurf->state.maximized) |
Kristian Høgsberg | 9e31bff | 2012-08-01 00:08:07 -0400 | [diff] [blame] | 1561 | return 0; |
| 1562 | |
| 1563 | move = malloc(sizeof *move); |
| 1564 | if (!move) |
| 1565 | return -1; |
| 1566 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 1567 | move->dx = wl_fixed_from_double(shsurf->view->geometry.x) - |
Kristian Høgsberg | e314875 | 2013-05-06 23:19:49 -0400 | [diff] [blame] | 1568 | seat->pointer->grab_x; |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 1569 | move->dy = wl_fixed_from_double(shsurf->view->geometry.y) - |
Kristian Høgsberg | e314875 | 2013-05-06 23:19:49 -0400 | [diff] [blame] | 1570 | seat->pointer->grab_y; |
Kristian Høgsberg | ae356ae | 2014-04-29 16:03:54 -0700 | [diff] [blame] | 1571 | move->client_initiated = client_initiated; |
Kristian Høgsberg | 9e31bff | 2012-08-01 00:08:07 -0400 | [diff] [blame] | 1572 | |
| 1573 | shell_grab_start(&move->base, &move_grab_interface, shsurf, |
Kristian Høgsberg | e314875 | 2013-05-06 23:19:49 -0400 | [diff] [blame] | 1574 | seat->pointer, DESKTOP_SHELL_CURSOR_MOVE); |
Kristian Høgsberg | 9e31bff | 2012-08-01 00:08:07 -0400 | [diff] [blame] | 1575 | |
| 1576 | return 0; |
| 1577 | } |
| 1578 | |
| 1579 | static void |
Rafael Antognolli | e2a3455 | 2013-12-03 15:35:45 -0200 | [diff] [blame] | 1580 | common_surface_move(struct wl_resource *resource, |
| 1581 | struct wl_resource *seat_resource, uint32_t serial) |
Kristian Høgsberg | 9e31bff | 2012-08-01 00:08:07 -0400 | [diff] [blame] | 1582 | { |
Jason Ekstrand | 44a3863 | 2013-06-14 10:08:00 -0500 | [diff] [blame] | 1583 | struct weston_seat *seat = wl_resource_get_user_data(seat_resource); |
Jason Ekstrand | 651f00e | 2013-06-14 10:07:54 -0500 | [diff] [blame] | 1584 | struct shell_surface *shsurf = wl_resource_get_user_data(resource); |
Giulio Camuffo | 61da3fc | 2013-04-25 13:57:45 +0300 | [diff] [blame] | 1585 | struct weston_surface *surface; |
Kristian Høgsberg | 9e31bff | 2012-08-01 00:08:07 -0400 | [diff] [blame] | 1586 | |
Kristian Høgsberg | e1b655d | 2013-08-28 23:16:20 -0700 | [diff] [blame] | 1587 | if (seat->pointer && |
Kristian Høgsberg | 70f2901 | 2014-01-09 15:43:17 -0800 | [diff] [blame] | 1588 | seat->pointer->focus && |
Kristian Høgsberg | e1b655d | 2013-08-28 23:16:20 -0700 | [diff] [blame] | 1589 | seat->pointer->button_count > 0 && |
| 1590 | seat->pointer->grab_serial == serial) { |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 1591 | surface = weston_surface_get_main_surface(seat->pointer->focus->surface); |
U. Artie Eoff | cf5737a | 2014-01-17 10:08:25 -0800 | [diff] [blame] | 1592 | if ((surface == shsurf->surface) && |
Kristian Høgsberg | ae356ae | 2014-04-29 16:03:54 -0700 | [diff] [blame] | 1593 | (surface_move(shsurf, seat, 1) < 0)) |
Rusty Lynch | 1084da5 | 2013-08-15 09:10:08 -0700 | [diff] [blame] | 1594 | wl_resource_post_no_memory(resource); |
Kristian Høgsberg | e1b655d | 2013-08-28 23:16:20 -0700 | [diff] [blame] | 1595 | } else if (seat->touch && |
Kristian Høgsberg | 70f2901 | 2014-01-09 15:43:17 -0800 | [diff] [blame] | 1596 | seat->touch->focus && |
Kristian Høgsberg | e1b655d | 2013-08-28 23:16:20 -0700 | [diff] [blame] | 1597 | seat->touch->grab_serial == serial) { |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 1598 | surface = weston_surface_get_main_surface(seat->touch->focus->surface); |
U. Artie Eoff | cf5737a | 2014-01-17 10:08:25 -0800 | [diff] [blame] | 1599 | if ((surface == shsurf->surface) && |
Rusty Lynch | 1084da5 | 2013-08-15 09:10:08 -0700 | [diff] [blame] | 1600 | (surface_touch_move(shsurf, seat) < 0)) |
| 1601 | wl_resource_post_no_memory(resource); |
| 1602 | } |
Kristian Høgsberg | 9e31bff | 2012-08-01 00:08:07 -0400 | [diff] [blame] | 1603 | } |
| 1604 | |
Rafael Antognolli | e2a3455 | 2013-12-03 15:35:45 -0200 | [diff] [blame] | 1605 | static void |
| 1606 | shell_surface_move(struct wl_client *client, struct wl_resource *resource, |
| 1607 | struct wl_resource *seat_resource, uint32_t serial) |
| 1608 | { |
| 1609 | common_surface_move(resource, seat_resource, serial); |
| 1610 | } |
| 1611 | |
Kristian Høgsberg | 9e31bff | 2012-08-01 00:08:07 -0400 | [diff] [blame] | 1612 | struct weston_resize_grab { |
| 1613 | struct shell_grab base; |
| 1614 | uint32_t edges; |
| 1615 | int32_t width, height; |
| 1616 | }; |
| 1617 | |
| 1618 | static void |
Giulio Camuffo | 1959ab8 | 2013-11-14 23:42:52 +0100 | [diff] [blame] | 1619 | resize_grab_motion(struct weston_pointer_grab *grab, uint32_t time, |
| 1620 | wl_fixed_t x, wl_fixed_t y) |
Kristian Høgsberg | 9e31bff | 2012-08-01 00:08:07 -0400 | [diff] [blame] | 1621 | { |
| 1622 | struct weston_resize_grab *resize = (struct weston_resize_grab *) grab; |
Kristian Høgsberg | 02bbabb | 2013-05-06 22:15:05 -0400 | [diff] [blame] | 1623 | struct weston_pointer *pointer = grab->pointer; |
Kristian Høgsberg | 9e31bff | 2012-08-01 00:08:07 -0400 | [diff] [blame] | 1624 | struct shell_surface *shsurf = resize->base.shsurf; |
| 1625 | int32_t width, height; |
| 1626 | wl_fixed_t from_x, from_y; |
| 1627 | wl_fixed_t to_x, to_y; |
| 1628 | |
Giulio Camuffo | 1959ab8 | 2013-11-14 23:42:52 +0100 | [diff] [blame] | 1629 | weston_pointer_move(pointer, x, y); |
| 1630 | |
Kristian Høgsberg | e0b9d5b | 2014-04-30 13:45:49 -0700 | [diff] [blame] | 1631 | if (!shsurf) |
Kristian Høgsberg | 9e31bff | 2012-08-01 00:08:07 -0400 | [diff] [blame] | 1632 | return; |
| 1633 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 1634 | weston_view_from_global_fixed(shsurf->view, |
| 1635 | pointer->grab_x, pointer->grab_y, |
| 1636 | &from_x, &from_y); |
| 1637 | weston_view_from_global_fixed(shsurf->view, |
| 1638 | pointer->x, pointer->y, &to_x, &to_y); |
Kristian Høgsberg | 9e31bff | 2012-08-01 00:08:07 -0400 | [diff] [blame] | 1639 | |
| 1640 | width = resize->width; |
| 1641 | if (resize->edges & WL_SHELL_SURFACE_RESIZE_LEFT) { |
| 1642 | width += wl_fixed_to_int(from_x - to_x); |
| 1643 | } else if (resize->edges & WL_SHELL_SURFACE_RESIZE_RIGHT) { |
| 1644 | width += wl_fixed_to_int(to_x - from_x); |
| 1645 | } |
| 1646 | |
| 1647 | height = resize->height; |
| 1648 | if (resize->edges & WL_SHELL_SURFACE_RESIZE_TOP) { |
| 1649 | height += wl_fixed_to_int(from_y - to_y); |
| 1650 | } else if (resize->edges & WL_SHELL_SURFACE_RESIZE_BOTTOM) { |
| 1651 | height += wl_fixed_to_int(to_y - from_y); |
| 1652 | } |
| 1653 | |
| 1654 | shsurf->client->send_configure(shsurf->surface, |
| 1655 | resize->edges, width, height); |
| 1656 | } |
| 1657 | |
| 1658 | static void |
| 1659 | send_configure(struct weston_surface *surface, |
| 1660 | uint32_t edges, int32_t width, int32_t height) |
| 1661 | { |
| 1662 | struct shell_surface *shsurf = get_shell_surface(surface); |
| 1663 | |
U. Artie Eoff | cf5737a | 2014-01-17 10:08:25 -0800 | [diff] [blame] | 1664 | assert(shsurf); |
| 1665 | |
Kristian Høgsberg | e0b9d5b | 2014-04-30 13:45:49 -0700 | [diff] [blame] | 1666 | if (shsurf->resource) |
| 1667 | wl_shell_surface_send_configure(shsurf->resource, |
| 1668 | edges, width, height); |
Kristian Høgsberg | 9e31bff | 2012-08-01 00:08:07 -0400 | [diff] [blame] | 1669 | } |
| 1670 | |
| 1671 | static const struct weston_shell_client shell_client = { |
| 1672 | send_configure |
| 1673 | }; |
| 1674 | |
| 1675 | static void |
Kristian Høgsberg | 02bbabb | 2013-05-06 22:15:05 -0400 | [diff] [blame] | 1676 | resize_grab_button(struct weston_pointer_grab *grab, |
Kristian Høgsberg | 9e31bff | 2012-08-01 00:08:07 -0400 | [diff] [blame] | 1677 | uint32_t time, uint32_t button, uint32_t state_w) |
| 1678 | { |
| 1679 | struct weston_resize_grab *resize = (struct weston_resize_grab *) grab; |
Kristian Høgsberg | 02bbabb | 2013-05-06 22:15:05 -0400 | [diff] [blame] | 1680 | struct weston_pointer *pointer = grab->pointer; |
Kristian Høgsberg | 9e31bff | 2012-08-01 00:08:07 -0400 | [diff] [blame] | 1681 | enum wl_pointer_button_state state = state_w; |
| 1682 | |
| 1683 | if (pointer->button_count == 0 && |
| 1684 | state == WL_POINTER_BUTTON_STATE_RELEASED) { |
| 1685 | shell_grab_end(&resize->base); |
| 1686 | free(grab); |
| 1687 | } |
| 1688 | } |
| 1689 | |
Jonas Ådahl | 1ea343e | 2013-10-25 23:18:05 +0200 | [diff] [blame] | 1690 | static void |
| 1691 | resize_grab_cancel(struct weston_pointer_grab *grab) |
| 1692 | { |
| 1693 | struct weston_resize_grab *resize = (struct weston_resize_grab *) grab; |
| 1694 | |
| 1695 | shell_grab_end(&resize->base); |
| 1696 | free(grab); |
| 1697 | } |
| 1698 | |
Kristian Høgsberg | 02bbabb | 2013-05-06 22:15:05 -0400 | [diff] [blame] | 1699 | static const struct weston_pointer_grab_interface resize_grab_interface = { |
Kristian Høgsberg | 9e31bff | 2012-08-01 00:08:07 -0400 | [diff] [blame] | 1700 | noop_grab_focus, |
| 1701 | resize_grab_motion, |
| 1702 | resize_grab_button, |
Jonas Ådahl | 1ea343e | 2013-10-25 23:18:05 +0200 | [diff] [blame] | 1703 | resize_grab_cancel, |
Kristian Høgsberg | 9e31bff | 2012-08-01 00:08:07 -0400 | [diff] [blame] | 1704 | }; |
| 1705 | |
Giulio Camuffo | b836664 | 2013-04-25 13:57:46 +0300 | [diff] [blame] | 1706 | /* |
| 1707 | * Returns the bounding box of a surface and all its sub-surfaces, |
| 1708 | * in the surface coordinates system. */ |
| 1709 | static void |
| 1710 | surface_subsurfaces_boundingbox(struct weston_surface *surface, int32_t *x, |
| 1711 | int32_t *y, int32_t *w, int32_t *h) { |
| 1712 | pixman_region32_t region; |
| 1713 | pixman_box32_t *box; |
| 1714 | struct weston_subsurface *subsurface; |
| 1715 | |
| 1716 | pixman_region32_init_rect(®ion, 0, 0, |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 1717 | surface->width, |
| 1718 | surface->height); |
Giulio Camuffo | b836664 | 2013-04-25 13:57:46 +0300 | [diff] [blame] | 1719 | |
| 1720 | wl_list_for_each(subsurface, &surface->subsurface_list, parent_link) { |
| 1721 | pixman_region32_union_rect(®ion, ®ion, |
| 1722 | subsurface->position.x, |
| 1723 | subsurface->position.y, |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 1724 | subsurface->surface->width, |
| 1725 | subsurface->surface->height); |
Giulio Camuffo | b836664 | 2013-04-25 13:57:46 +0300 | [diff] [blame] | 1726 | } |
| 1727 | |
| 1728 | box = pixman_region32_extents(®ion); |
| 1729 | if (x) |
| 1730 | *x = box->x1; |
| 1731 | if (y) |
| 1732 | *y = box->y1; |
| 1733 | if (w) |
| 1734 | *w = box->x2 - box->x1; |
| 1735 | if (h) |
| 1736 | *h = box->y2 - box->y1; |
| 1737 | |
| 1738 | pixman_region32_fini(®ion); |
| 1739 | } |
| 1740 | |
Kristian Høgsberg | 9e31bff | 2012-08-01 00:08:07 -0400 | [diff] [blame] | 1741 | static int |
| 1742 | surface_resize(struct shell_surface *shsurf, |
Kristian Høgsberg | e314875 | 2013-05-06 23:19:49 -0400 | [diff] [blame] | 1743 | struct weston_seat *seat, uint32_t edges) |
Kristian Høgsberg | 9e31bff | 2012-08-01 00:08:07 -0400 | [diff] [blame] | 1744 | { |
| 1745 | struct weston_resize_grab *resize; |
| 1746 | |
Kristian Høgsberg | a4b620e | 2014-04-30 16:05:49 -0700 | [diff] [blame^] | 1747 | if (shsurf->grabbed || |
| 1748 | shsurf->state.fullscreen || shsurf->state.maximized) |
Kristian Høgsberg | 9e31bff | 2012-08-01 00:08:07 -0400 | [diff] [blame] | 1749 | return 0; |
| 1750 | |
| 1751 | if (edges == 0 || edges > 15 || |
| 1752 | (edges & 3) == 3 || (edges & 12) == 12) |
| 1753 | return 0; |
| 1754 | |
| 1755 | resize = malloc(sizeof *resize); |
| 1756 | if (!resize) |
| 1757 | return -1; |
| 1758 | |
| 1759 | resize->edges = edges; |
Giulio Camuffo | b836664 | 2013-04-25 13:57:46 +0300 | [diff] [blame] | 1760 | surface_subsurfaces_boundingbox(shsurf->surface, NULL, NULL, |
| 1761 | &resize->width, &resize->height); |
Kristian Høgsberg | 9e31bff | 2012-08-01 00:08:07 -0400 | [diff] [blame] | 1762 | |
Kristian Høgsberg | 44cd196 | 2014-02-05 21:36:04 -0800 | [diff] [blame] | 1763 | shsurf->resize_edges = edges; |
Kristian Høgsberg | 9e31bff | 2012-08-01 00:08:07 -0400 | [diff] [blame] | 1764 | shell_grab_start(&resize->base, &resize_grab_interface, shsurf, |
Kristian Høgsberg | e314875 | 2013-05-06 23:19:49 -0400 | [diff] [blame] | 1765 | seat->pointer, edges); |
Kristian Høgsberg | 9e31bff | 2012-08-01 00:08:07 -0400 | [diff] [blame] | 1766 | |
| 1767 | return 0; |
| 1768 | } |
| 1769 | |
| 1770 | static void |
Rafael Antognolli | e2a3455 | 2013-12-03 15:35:45 -0200 | [diff] [blame] | 1771 | common_surface_resize(struct wl_resource *resource, |
| 1772 | struct wl_resource *seat_resource, uint32_t serial, |
| 1773 | uint32_t edges) |
Kristian Høgsberg | 9e31bff | 2012-08-01 00:08:07 -0400 | [diff] [blame] | 1774 | { |
Jason Ekstrand | 44a3863 | 2013-06-14 10:08:00 -0500 | [diff] [blame] | 1775 | struct weston_seat *seat = wl_resource_get_user_data(seat_resource); |
Jason Ekstrand | 651f00e | 2013-06-14 10:07:54 -0500 | [diff] [blame] | 1776 | struct shell_surface *shsurf = wl_resource_get_user_data(resource); |
Giulio Camuffo | 61da3fc | 2013-04-25 13:57:45 +0300 | [diff] [blame] | 1777 | struct weston_surface *surface; |
Kristian Høgsberg | 9e31bff | 2012-08-01 00:08:07 -0400 | [diff] [blame] | 1778 | |
Kristian Høgsberg | e314875 | 2013-05-06 23:19:49 -0400 | [diff] [blame] | 1779 | if (seat->pointer->button_count == 0 || |
| 1780 | seat->pointer->grab_serial != serial || |
Kristian Høgsberg | 70f2901 | 2014-01-09 15:43:17 -0800 | [diff] [blame] | 1781 | seat->pointer->focus == NULL) |
| 1782 | return; |
| 1783 | |
| 1784 | surface = weston_surface_get_main_surface(seat->pointer->focus->surface); |
| 1785 | if (surface != shsurf->surface) |
Kristian Høgsberg | 9e31bff | 2012-08-01 00:08:07 -0400 | [diff] [blame] | 1786 | return; |
| 1787 | |
Kristian Høgsberg | e314875 | 2013-05-06 23:19:49 -0400 | [diff] [blame] | 1788 | if (surface_resize(shsurf, seat, edges) < 0) |
Kristian Høgsberg | 9e31bff | 2012-08-01 00:08:07 -0400 | [diff] [blame] | 1789 | wl_resource_post_no_memory(resource); |
| 1790 | } |
| 1791 | |
Scott Moreau | c3e54eb | 2012-04-17 19:06:20 -0600 | [diff] [blame] | 1792 | static void |
Rafael Antognolli | e2a3455 | 2013-12-03 15:35:45 -0200 | [diff] [blame] | 1793 | shell_surface_resize(struct wl_client *client, struct wl_resource *resource, |
| 1794 | struct wl_resource *seat_resource, uint32_t serial, |
| 1795 | uint32_t edges) |
| 1796 | { |
| 1797 | common_surface_resize(resource, seat_resource, serial, edges); |
| 1798 | } |
| 1799 | |
| 1800 | static void |
Kristian Høgsberg | 6848c25 | 2013-05-08 22:02:59 -0400 | [diff] [blame] | 1801 | busy_cursor_grab_focus(struct weston_pointer_grab *base) |
Scott Moreau | c3e54eb | 2012-04-17 19:06:20 -0600 | [diff] [blame] | 1802 | { |
Kristian Høgsberg | d56bd90 | 2012-06-05 09:58:51 -0400 | [diff] [blame] | 1803 | struct shell_grab *grab = (struct shell_grab *) base; |
Kristian Høgsberg | 6848c25 | 2013-05-08 22:02:59 -0400 | [diff] [blame] | 1804 | struct weston_pointer *pointer = base->pointer; |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 1805 | struct weston_view *view; |
Kristian Høgsberg | 6848c25 | 2013-05-08 22:02:59 -0400 | [diff] [blame] | 1806 | wl_fixed_t sx, sy; |
| 1807 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 1808 | view = weston_compositor_pick_view(pointer->seat->compositor, |
| 1809 | pointer->x, pointer->y, |
| 1810 | &sx, &sy); |
Scott Moreau | c3e54eb | 2012-04-17 19:06:20 -0600 | [diff] [blame] | 1811 | |
Kristian Høgsberg | 2bff94e | 2014-02-11 12:22:51 -0800 | [diff] [blame] | 1812 | if (!grab->shsurf || grab->shsurf->surface != view->surface) { |
| 1813 | shell_grab_end(grab); |
| 1814 | free(grab); |
| 1815 | } |
Scott Moreau | c3e54eb | 2012-04-17 19:06:20 -0600 | [diff] [blame] | 1816 | } |
| 1817 | |
| 1818 | static void |
Giulio Camuffo | 1959ab8 | 2013-11-14 23:42:52 +0100 | [diff] [blame] | 1819 | busy_cursor_grab_motion(struct weston_pointer_grab *grab, uint32_t time, |
| 1820 | wl_fixed_t x, wl_fixed_t y) |
Scott Moreau | c3e54eb | 2012-04-17 19:06:20 -0600 | [diff] [blame] | 1821 | { |
Giulio Camuffo | 1959ab8 | 2013-11-14 23:42:52 +0100 | [diff] [blame] | 1822 | weston_pointer_move(grab->pointer, x, y); |
Kristian Høgsberg | d56bd90 | 2012-06-05 09:58:51 -0400 | [diff] [blame] | 1823 | } |
Scott Moreau | c3e54eb | 2012-04-17 19:06:20 -0600 | [diff] [blame] | 1824 | |
Kristian Høgsberg | d56bd90 | 2012-06-05 09:58:51 -0400 | [diff] [blame] | 1825 | static void |
Kristian Høgsberg | 02bbabb | 2013-05-06 22:15:05 -0400 | [diff] [blame] | 1826 | busy_cursor_grab_button(struct weston_pointer_grab *base, |
Kristian Høgsberg | d56bd90 | 2012-06-05 09:58:51 -0400 | [diff] [blame] | 1827 | uint32_t time, uint32_t button, uint32_t state) |
| 1828 | { |
Kristian Høgsberg | bbe9839 | 2012-08-01 00:20:21 -0400 | [diff] [blame] | 1829 | struct shell_grab *grab = (struct shell_grab *) base; |
Kristian Høgsberg | e122b7b | 2013-05-08 16:47:00 -0400 | [diff] [blame] | 1830 | struct shell_surface *shsurf = grab->shsurf; |
Kristian Høgsberg | e314875 | 2013-05-06 23:19:49 -0400 | [diff] [blame] | 1831 | struct weston_seat *seat = grab->grab.pointer->seat; |
Kristian Høgsberg | bbe9839 | 2012-08-01 00:20:21 -0400 | [diff] [blame] | 1832 | |
Kristian Høgsberg | bbe9839 | 2012-08-01 00:20:21 -0400 | [diff] [blame] | 1833 | if (shsurf && button == BTN_LEFT && state) { |
Emilio Pozuelo Monfort | 9e7c759 | 2014-01-30 14:01:10 +0100 | [diff] [blame] | 1834 | activate(shsurf->shell, shsurf->surface, seat, true); |
Kristian Høgsberg | ae356ae | 2014-04-29 16:03:54 -0700 | [diff] [blame] | 1835 | surface_move(shsurf, seat, 0); |
Kristian Høgsberg | 0c36903 | 2013-02-14 21:31:44 -0500 | [diff] [blame] | 1836 | } else if (shsurf && button == BTN_RIGHT && state) { |
Emilio Pozuelo Monfort | 9e7c759 | 2014-01-30 14:01:10 +0100 | [diff] [blame] | 1837 | activate(shsurf->shell, shsurf->surface, seat, true); |
Kristian Høgsberg | e314875 | 2013-05-06 23:19:49 -0400 | [diff] [blame] | 1838 | surface_rotate(shsurf, seat); |
Kristian Høgsberg | bbe9839 | 2012-08-01 00:20:21 -0400 | [diff] [blame] | 1839 | } |
Kristian Høgsberg | d56bd90 | 2012-06-05 09:58:51 -0400 | [diff] [blame] | 1840 | } |
| 1841 | |
Jonas Ådahl | 1ea343e | 2013-10-25 23:18:05 +0200 | [diff] [blame] | 1842 | static void |
| 1843 | busy_cursor_grab_cancel(struct weston_pointer_grab *base) |
| 1844 | { |
| 1845 | struct shell_grab *grab = (struct shell_grab *) base; |
| 1846 | |
| 1847 | shell_grab_end(grab); |
| 1848 | free(grab); |
| 1849 | } |
| 1850 | |
Kristian Høgsberg | 02bbabb | 2013-05-06 22:15:05 -0400 | [diff] [blame] | 1851 | static const struct weston_pointer_grab_interface busy_cursor_grab_interface = { |
Kristian Høgsberg | d56bd90 | 2012-06-05 09:58:51 -0400 | [diff] [blame] | 1852 | busy_cursor_grab_focus, |
| 1853 | busy_cursor_grab_motion, |
| 1854 | busy_cursor_grab_button, |
Jonas Ådahl | 1ea343e | 2013-10-25 23:18:05 +0200 | [diff] [blame] | 1855 | busy_cursor_grab_cancel, |
Kristian Høgsberg | d56bd90 | 2012-06-05 09:58:51 -0400 | [diff] [blame] | 1856 | }; |
| 1857 | |
| 1858 | static void |
Kristian Høgsberg | 02bbabb | 2013-05-06 22:15:05 -0400 | [diff] [blame] | 1859 | set_busy_cursor(struct shell_surface *shsurf, struct weston_pointer *pointer) |
Kristian Høgsberg | d56bd90 | 2012-06-05 09:58:51 -0400 | [diff] [blame] | 1860 | { |
| 1861 | struct shell_grab *grab; |
Kristian Høgsberg | d56bd90 | 2012-06-05 09:58:51 -0400 | [diff] [blame] | 1862 | |
Kristian Høgsberg | 2bff94e | 2014-02-11 12:22:51 -0800 | [diff] [blame] | 1863 | if (pointer->grab->interface == &busy_cursor_grab_interface) |
| 1864 | return; |
| 1865 | |
Kristian Høgsberg | d56bd90 | 2012-06-05 09:58:51 -0400 | [diff] [blame] | 1866 | grab = malloc(sizeof *grab); |
| 1867 | if (!grab) |
Scott Moreau | c3e54eb | 2012-04-17 19:06:20 -0600 | [diff] [blame] | 1868 | return; |
| 1869 | |
Ander Conselvan de Oliveira | b9d2a0f | 2012-06-28 18:08:05 +0300 | [diff] [blame] | 1870 | shell_grab_start(grab, &busy_cursor_grab_interface, shsurf, pointer, |
| 1871 | DESKTOP_SHELL_CURSOR_BUSY); |
Ander Conselvan de Oliveira | e5a1aee | 2014-04-09 17:39:39 +0300 | [diff] [blame] | 1872 | /* Mark the shsurf as ungrabbed so that button binding is able |
| 1873 | * to move it. */ |
| 1874 | shsurf->grabbed = 0; |
Kristian Høgsberg | d56bd90 | 2012-06-05 09:58:51 -0400 | [diff] [blame] | 1875 | } |
Scott Moreau | c3e54eb | 2012-04-17 19:06:20 -0600 | [diff] [blame] | 1876 | |
Kristian Høgsberg | d56bd90 | 2012-06-05 09:58:51 -0400 | [diff] [blame] | 1877 | static void |
Kristian Høgsberg | 2bff94e | 2014-02-11 12:22:51 -0800 | [diff] [blame] | 1878 | end_busy_cursor(struct weston_compositor *compositor, struct wl_client *client) |
Kristian Høgsberg | d56bd90 | 2012-06-05 09:58:51 -0400 | [diff] [blame] | 1879 | { |
Kristian Høgsberg | 2bff94e | 2014-02-11 12:22:51 -0800 | [diff] [blame] | 1880 | struct shell_grab *grab; |
| 1881 | struct weston_seat *seat; |
Kristian Høgsberg | d56bd90 | 2012-06-05 09:58:51 -0400 | [diff] [blame] | 1882 | |
Kristian Høgsberg | 2bff94e | 2014-02-11 12:22:51 -0800 | [diff] [blame] | 1883 | wl_list_for_each(seat, &compositor->seat_list, link) { |
| 1884 | if (seat->pointer == NULL) |
| 1885 | continue; |
| 1886 | |
| 1887 | grab = (struct shell_grab *) seat->pointer->grab; |
| 1888 | if (grab->grab.interface == &busy_cursor_grab_interface && |
| 1889 | wl_resource_get_client(grab->shsurf->resource) == client) { |
| 1890 | shell_grab_end(grab); |
| 1891 | free(grab); |
| 1892 | } |
Scott Moreau | c3e54eb | 2012-04-17 19:06:20 -0600 | [diff] [blame] | 1893 | } |
Scott Moreau | c3e54eb | 2012-04-17 19:06:20 -0600 | [diff] [blame] | 1894 | } |
| 1895 | |
Scott Moreau | 9521d5e | 2012-04-19 13:06:17 -0600 | [diff] [blame] | 1896 | static void |
Kristian Høgsberg | 2bff94e | 2014-02-11 12:22:51 -0800 | [diff] [blame] | 1897 | handle_shell_client_destroy(struct wl_listener *listener, void *data); |
| 1898 | |
| 1899 | static int |
| 1900 | xdg_ping_timeout_handler(void *data) |
| 1901 | { |
| 1902 | struct shell_client *sc = data; |
| 1903 | struct weston_seat *seat; |
| 1904 | struct shell_surface *shsurf; |
| 1905 | |
| 1906 | /* Client is not responding */ |
| 1907 | sc->unresponsive = 1; |
Kristian Høgsberg | 2bff94e | 2014-02-11 12:22:51 -0800 | [diff] [blame] | 1908 | wl_list_for_each(seat, &sc->shell->compositor->seat_list, link) { |
| 1909 | if (seat->pointer == NULL || seat->pointer->focus == NULL) |
| 1910 | continue; |
| 1911 | if (seat->pointer->focus->surface->resource == NULL) |
| 1912 | continue; |
| 1913 | |
| 1914 | shsurf = get_shell_surface(seat->pointer->focus->surface); |
| 1915 | if (shsurf && |
| 1916 | wl_resource_get_client(shsurf->resource) == sc->client) |
| 1917 | set_busy_cursor(shsurf, seat->pointer); |
| 1918 | } |
| 1919 | |
| 1920 | return 1; |
| 1921 | } |
| 1922 | |
| 1923 | static void |
| 1924 | handle_xdg_ping(struct shell_surface *shsurf, uint32_t serial) |
| 1925 | { |
| 1926 | struct weston_compositor *compositor = shsurf->shell->compositor; |
Jason Ekstrand | 9e9512f | 2014-04-16 21:12:10 -0500 | [diff] [blame] | 1927 | struct shell_client *sc = shsurf->owner; |
Kristian Høgsberg | 2bff94e | 2014-02-11 12:22:51 -0800 | [diff] [blame] | 1928 | struct wl_event_loop *loop; |
Kristian Høgsberg | dd62aba | 2014-02-12 09:56:19 -0800 | [diff] [blame] | 1929 | static const int ping_timeout = 200; |
Kristian Høgsberg | 2bff94e | 2014-02-11 12:22:51 -0800 | [diff] [blame] | 1930 | |
Kristian Høgsberg | 2bff94e | 2014-02-11 12:22:51 -0800 | [diff] [blame] | 1931 | if (sc->unresponsive) { |
| 1932 | xdg_ping_timeout_handler(sc); |
| 1933 | return; |
| 1934 | } |
| 1935 | |
| 1936 | sc->ping_serial = serial; |
| 1937 | loop = wl_display_get_event_loop(compositor->wl_display); |
| 1938 | if (sc->ping_timer == NULL) |
| 1939 | sc->ping_timer = |
| 1940 | wl_event_loop_add_timer(loop, |
| 1941 | xdg_ping_timeout_handler, sc); |
| 1942 | if (sc->ping_timer == NULL) |
| 1943 | return; |
| 1944 | |
| 1945 | wl_event_source_timer_update(sc->ping_timer, ping_timeout); |
| 1946 | |
Kristian Høgsberg | dd62aba | 2014-02-12 09:56:19 -0800 | [diff] [blame] | 1947 | if (shell_surface_is_xdg_surface(shsurf) || |
| 1948 | shell_surface_is_xdg_popup(shsurf)) |
| 1949 | xdg_shell_send_ping(sc->resource, serial); |
| 1950 | else if (shell_surface_is_wl_shell_surface(shsurf)) |
| 1951 | wl_shell_surface_send_ping(shsurf->resource, serial); |
Kristian Høgsberg | 2bff94e | 2014-02-11 12:22:51 -0800 | [diff] [blame] | 1952 | } |
| 1953 | |
Scott Moreau | ff1db4a | 2012-04-17 19:06:18 -0600 | [diff] [blame] | 1954 | static void |
| 1955 | ping_handler(struct weston_surface *surface, uint32_t serial) |
| 1956 | { |
Kristian Høgsberg | b71302e | 2012-05-10 12:28:35 -0400 | [diff] [blame] | 1957 | struct shell_surface *shsurf = get_shell_surface(surface); |
Scott Moreau | ff1db4a | 2012-04-17 19:06:18 -0600 | [diff] [blame] | 1958 | |
| 1959 | if (!shsurf) |
| 1960 | return; |
Jason Ekstrand | 651f00e | 2013-06-14 10:07:54 -0500 | [diff] [blame] | 1961 | if (!shsurf->resource) |
Kristian Høgsberg | ca535c1 | 2012-04-21 23:20:07 -0400 | [diff] [blame] | 1962 | return; |
Ander Conselvan de Oliveira | eac9a46 | 2012-07-16 14:15:48 +0300 | [diff] [blame] | 1963 | if (shsurf->surface == shsurf->shell->grab_surface) |
| 1964 | return; |
| 1965 | |
Kristian Høgsberg | dd62aba | 2014-02-12 09:56:19 -0800 | [diff] [blame] | 1966 | handle_xdg_ping(shsurf, serial); |
Scott Moreau | ff1db4a | 2012-04-17 19:06:18 -0600 | [diff] [blame] | 1967 | } |
| 1968 | |
| 1969 | static void |
Kristian Høgsberg | d56bd90 | 2012-06-05 09:58:51 -0400 | [diff] [blame] | 1970 | handle_pointer_focus(struct wl_listener *listener, void *data) |
| 1971 | { |
Kristian Høgsberg | 02bbabb | 2013-05-06 22:15:05 -0400 | [diff] [blame] | 1972 | struct weston_pointer *pointer = data; |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 1973 | struct weston_view *view = pointer->focus; |
Kristian Høgsberg | d56bd90 | 2012-06-05 09:58:51 -0400 | [diff] [blame] | 1974 | struct weston_compositor *compositor; |
Kristian Høgsberg | d56bd90 | 2012-06-05 09:58:51 -0400 | [diff] [blame] | 1975 | uint32_t serial; |
| 1976 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 1977 | if (!view) |
Kristian Høgsberg | d56bd90 | 2012-06-05 09:58:51 -0400 | [diff] [blame] | 1978 | return; |
| 1979 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 1980 | compositor = view->surface->compositor; |
Kristian Høgsberg | e11ef64 | 2014-02-11 16:35:22 -0800 | [diff] [blame] | 1981 | serial = wl_display_next_serial(compositor->wl_display); |
| 1982 | ping_handler(view->surface, serial); |
Kristian Høgsberg | d56bd90 | 2012-06-05 09:58:51 -0400 | [diff] [blame] | 1983 | } |
| 1984 | |
| 1985 | static void |
Jasper St. Pierre | faf27a9 | 2013-12-09 17:36:28 -0500 | [diff] [blame] | 1986 | shell_surface_lose_keyboard_focus(struct shell_surface *shsurf) |
| 1987 | { |
| 1988 | if (--shsurf->focus_count == 0) |
| 1989 | if (shell_surface_is_xdg_surface(shsurf)) |
Jasper St. Pierre | b223a72 | 2014-02-08 18:11:53 -0500 | [diff] [blame] | 1990 | xdg_surface_send_deactivated(shsurf->resource); |
Jasper St. Pierre | faf27a9 | 2013-12-09 17:36:28 -0500 | [diff] [blame] | 1991 | } |
| 1992 | |
| 1993 | static void |
| 1994 | shell_surface_gain_keyboard_focus(struct shell_surface *shsurf) |
| 1995 | { |
| 1996 | if (shsurf->focus_count++ == 0) |
| 1997 | if (shell_surface_is_xdg_surface(shsurf)) |
Jasper St. Pierre | b223a72 | 2014-02-08 18:11:53 -0500 | [diff] [blame] | 1998 | xdg_surface_send_activated(shsurf->resource); |
Jasper St. Pierre | faf27a9 | 2013-12-09 17:36:28 -0500 | [diff] [blame] | 1999 | } |
| 2000 | |
| 2001 | static void |
| 2002 | handle_keyboard_focus(struct wl_listener *listener, void *data) |
| 2003 | { |
| 2004 | struct weston_keyboard *keyboard = data; |
| 2005 | struct shell_seat *seat = get_shell_seat(keyboard->seat); |
| 2006 | |
| 2007 | if (seat->focused_surface) { |
| 2008 | struct shell_surface *shsurf = get_shell_surface(seat->focused_surface); |
| 2009 | if (shsurf) |
| 2010 | shell_surface_lose_keyboard_focus(shsurf); |
| 2011 | } |
| 2012 | |
| 2013 | seat->focused_surface = keyboard->focus; |
| 2014 | |
| 2015 | if (seat->focused_surface) { |
| 2016 | struct shell_surface *shsurf = get_shell_surface(seat->focused_surface); |
| 2017 | if (shsurf) |
| 2018 | shell_surface_gain_keyboard_focus(shsurf); |
| 2019 | } |
| 2020 | } |
| 2021 | |
| 2022 | static void |
Kristian Høgsberg | dd62aba | 2014-02-12 09:56:19 -0800 | [diff] [blame] | 2023 | shell_client_pong(struct shell_client *sc, uint32_t serial) |
Rafael Antognolli | e2a3455 | 2013-12-03 15:35:45 -0200 | [diff] [blame] | 2024 | { |
Kristian Høgsberg | dd62aba | 2014-02-12 09:56:19 -0800 | [diff] [blame] | 2025 | if (sc->ping_serial != serial) |
| 2026 | return; |
Rafael Antognolli | e2a3455 | 2013-12-03 15:35:45 -0200 | [diff] [blame] | 2027 | |
Kristian Høgsberg | dd62aba | 2014-02-12 09:56:19 -0800 | [diff] [blame] | 2028 | sc->unresponsive = 0; |
| 2029 | end_busy_cursor(sc->shell->compositor, sc->client); |
Rafael Antognolli | e2a3455 | 2013-12-03 15:35:45 -0200 | [diff] [blame] | 2030 | |
Kristian Høgsberg | dd62aba | 2014-02-12 09:56:19 -0800 | [diff] [blame] | 2031 | if (sc->ping_timer) { |
| 2032 | wl_event_source_remove(sc->ping_timer); |
| 2033 | sc->ping_timer = NULL; |
| 2034 | } |
| 2035 | |
| 2036 | } |
| 2037 | |
| 2038 | static void |
| 2039 | shell_surface_pong(struct wl_client *client, |
| 2040 | struct wl_resource *resource, uint32_t serial) |
| 2041 | { |
Jason Ekstrand | 9e9512f | 2014-04-16 21:12:10 -0500 | [diff] [blame] | 2042 | struct shell_surface *shsurf = wl_resource_get_user_data(resource); |
| 2043 | struct shell_client *sc = shsurf->owner; |
Kristian Høgsberg | dd62aba | 2014-02-12 09:56:19 -0800 | [diff] [blame] | 2044 | |
Kristian Høgsberg | dd62aba | 2014-02-12 09:56:19 -0800 | [diff] [blame] | 2045 | shell_client_pong(sc, serial); |
Rafael Antognolli | e2a3455 | 2013-12-03 15:35:45 -0200 | [diff] [blame] | 2046 | } |
| 2047 | |
| 2048 | static void |
Giulio Camuffo | 62942ad | 2013-09-11 18:20:47 +0200 | [diff] [blame] | 2049 | set_title(struct shell_surface *shsurf, const char *title) |
| 2050 | { |
| 2051 | free(shsurf->title); |
| 2052 | shsurf->title = strdup(title); |
| 2053 | } |
| 2054 | |
| 2055 | static void |
Kristian Høgsberg | e7afd91 | 2012-05-02 09:47:44 -0400 | [diff] [blame] | 2056 | shell_surface_set_title(struct wl_client *client, |
| 2057 | struct wl_resource *resource, const char *title) |
| 2058 | { |
Jason Ekstrand | 651f00e | 2013-06-14 10:07:54 -0500 | [diff] [blame] | 2059 | struct shell_surface *shsurf = wl_resource_get_user_data(resource); |
Kristian Høgsberg | e7afd91 | 2012-05-02 09:47:44 -0400 | [diff] [blame] | 2060 | |
Giulio Camuffo | 62942ad | 2013-09-11 18:20:47 +0200 | [diff] [blame] | 2061 | set_title(shsurf, title); |
Kristian Høgsberg | e7afd91 | 2012-05-02 09:47:44 -0400 | [diff] [blame] | 2062 | } |
| 2063 | |
| 2064 | static void |
| 2065 | shell_surface_set_class(struct wl_client *client, |
| 2066 | struct wl_resource *resource, const char *class) |
| 2067 | { |
Jason Ekstrand | 651f00e | 2013-06-14 10:07:54 -0500 | [diff] [blame] | 2068 | struct shell_surface *shsurf = wl_resource_get_user_data(resource); |
Kristian Høgsberg | e7afd91 | 2012-05-02 09:47:44 -0400 | [diff] [blame] | 2069 | |
| 2070 | free(shsurf->class); |
| 2071 | shsurf->class = strdup(class); |
| 2072 | } |
| 2073 | |
Alex Wu | 4539b08 | 2012-03-01 12:57:46 +0800 | [diff] [blame] | 2074 | static void |
Alexander Larsson | f82b6ca | 2013-05-28 16:23:39 +0200 | [diff] [blame] | 2075 | restore_output_mode(struct weston_output *output) |
| 2076 | { |
Hardening | 57388e4 | 2013-09-18 23:56:36 +0200 | [diff] [blame] | 2077 | if (output->current_mode != output->original_mode || |
| 2078 | (int32_t)output->current_scale != output->original_scale) |
Alexander Larsson | f82b6ca | 2013-05-28 16:23:39 +0200 | [diff] [blame] | 2079 | weston_output_switch_mode(output, |
Hardening | 57388e4 | 2013-09-18 23:56:36 +0200 | [diff] [blame] | 2080 | output->original_mode, |
| 2081 | output->original_scale, |
| 2082 | WESTON_MODE_SWITCH_RESTORE_NATIVE); |
Alexander Larsson | f82b6ca | 2013-05-28 16:23:39 +0200 | [diff] [blame] | 2083 | } |
| 2084 | |
| 2085 | static void |
| 2086 | restore_all_output_modes(struct weston_compositor *compositor) |
| 2087 | { |
| 2088 | struct weston_output *output; |
| 2089 | |
| 2090 | wl_list_for_each(output, &compositor->output_list, link) |
| 2091 | restore_output_mode(output); |
| 2092 | } |
| 2093 | |
Philip Withnall | becb77e | 2013-11-25 18:01:30 +0000 | [diff] [blame] | 2094 | static int |
| 2095 | get_output_panel_height(struct desktop_shell *shell, |
| 2096 | struct weston_output *output) |
| 2097 | { |
| 2098 | struct weston_view *view; |
| 2099 | int panel_height = 0; |
| 2100 | |
| 2101 | if (!output) |
| 2102 | return 0; |
| 2103 | |
| 2104 | wl_list_for_each(view, &shell->panel_layer.view_list, layer_link) { |
| 2105 | if (view->surface->output == output) { |
Jason Ekstrand | 918f2dd | 2013-12-02 21:01:53 -0600 | [diff] [blame] | 2106 | panel_height = view->surface->height; |
Philip Withnall | becb77e | 2013-11-25 18:01:30 +0000 | [diff] [blame] | 2107 | break; |
| 2108 | } |
| 2109 | } |
| 2110 | |
| 2111 | return panel_height; |
| 2112 | } |
| 2113 | |
Philip Withnall | 07926d9 | 2013-11-25 18:01:40 +0000 | [diff] [blame] | 2114 | /* The surface will be inserted into the list immediately after the link |
| 2115 | * returned by this function (i.e. will be stacked immediately above the |
| 2116 | * returned link). */ |
| 2117 | static struct wl_list * |
| 2118 | shell_surface_calculate_layer_link (struct shell_surface *shsurf) |
| 2119 | { |
| 2120 | struct workspace *ws; |
Kristian Høgsberg | ead5242 | 2014-01-01 13:51:52 -0800 | [diff] [blame] | 2121 | struct weston_view *parent; |
Philip Withnall | 07926d9 | 2013-11-25 18:01:40 +0000 | [diff] [blame] | 2122 | |
| 2123 | switch (shsurf->type) { |
Ander Conselvan de Oliveira | ef6a7e4 | 2014-04-30 14:15:14 +0300 | [diff] [blame] | 2124 | case SHELL_SURFACE_XWAYLAND: |
| 2125 | return &shsurf->shell->fullscreen_layer.view_list; |
| 2126 | |
| 2127 | case SHELL_SURFACE_NONE: |
| 2128 | return NULL; |
| 2129 | |
Kristian Høgsberg | ead5242 | 2014-01-01 13:51:52 -0800 | [diff] [blame] | 2130 | case SHELL_SURFACE_POPUP: |
| 2131 | case SHELL_SURFACE_TOPLEVEL: |
Emilio Pozuelo Monfort | 9e7c759 | 2014-01-30 14:01:10 +0100 | [diff] [blame] | 2132 | if (shsurf->state.fullscreen && !shsurf->state.lowered) { |
Rafael Antognolli | 03b1659 | 2013-12-03 15:35:42 -0200 | [diff] [blame] | 2133 | return &shsurf->shell->fullscreen_layer.view_list; |
Rafael Antognolli | ed207b4 | 2013-12-03 15:35:43 -0200 | [diff] [blame] | 2134 | } else if (shsurf->parent) { |
Kristian Høgsberg | d55db69 | 2014-01-01 12:26:14 -0800 | [diff] [blame] | 2135 | /* Move the surface to its parent layer so |
| 2136 | * that surfaces which are transient for |
| 2137 | * fullscreen surfaces don't get hidden by the |
| 2138 | * fullscreen surfaces. */ |
Rafael Antognolli | ed207b4 | 2013-12-03 15:35:43 -0200 | [diff] [blame] | 2139 | |
| 2140 | /* TODO: Handle a parent with multiple views */ |
| 2141 | parent = get_default_view(shsurf->parent); |
| 2142 | if (parent) |
| 2143 | return parent->layer_link.prev; |
| 2144 | } |
Philip Withnall | 07926d9 | 2013-11-25 18:01:40 +0000 | [diff] [blame] | 2145 | |
Ander Conselvan de Oliveira | ef6a7e4 | 2014-04-30 14:15:14 +0300 | [diff] [blame] | 2146 | /* Move the surface to a normal workspace layer so that surfaces |
| 2147 | * which were previously fullscreen or transient are no longer |
| 2148 | * rendered on top. */ |
| 2149 | ws = get_current_workspace(shsurf->shell); |
| 2150 | return &ws->layer.view_list; |
Philip Withnall | 07926d9 | 2013-11-25 18:01:40 +0000 | [diff] [blame] | 2151 | } |
| 2152 | |
Ander Conselvan de Oliveira | ef6a7e4 | 2014-04-30 14:15:14 +0300 | [diff] [blame] | 2153 | assert(0 && "Unknown shell surface type"); |
Philip Withnall | 07926d9 | 2013-11-25 18:01:40 +0000 | [diff] [blame] | 2154 | } |
| 2155 | |
Philip Withnall | 648a4dd | 2013-11-25 18:01:44 +0000 | [diff] [blame] | 2156 | static void |
| 2157 | shell_surface_update_child_surface_layers (struct shell_surface *shsurf) |
| 2158 | { |
| 2159 | struct shell_surface *child; |
| 2160 | |
| 2161 | /* Move the child layers to the same workspace as shsurf. They will be |
| 2162 | * stacked above shsurf. */ |
| 2163 | wl_list_for_each_reverse(child, &shsurf->children_list, children_link) { |
| 2164 | if (shsurf->view->layer_link.prev != &child->view->layer_link) { |
Ander Conselvan de Oliveira | facc0cc | 2014-04-10 15:35:58 +0300 | [diff] [blame] | 2165 | weston_view_damage_below(child->view); |
Philip Withnall | 648a4dd | 2013-11-25 18:01:44 +0000 | [diff] [blame] | 2166 | weston_view_geometry_dirty(child->view); |
| 2167 | wl_list_remove(&child->view->layer_link); |
| 2168 | wl_list_insert(shsurf->view->layer_link.prev, |
| 2169 | &child->view->layer_link); |
| 2170 | weston_view_geometry_dirty(child->view); |
| 2171 | weston_surface_damage(child->surface); |
| 2172 | |
| 2173 | /* Recurse. We don’t expect this to recurse very far (if |
| 2174 | * at all) because that would imply we have transient |
| 2175 | * (or popup) children of transient surfaces, which |
| 2176 | * would be unusual. */ |
| 2177 | shell_surface_update_child_surface_layers(child); |
| 2178 | } |
| 2179 | } |
| 2180 | } |
| 2181 | |
Philip Withnall | e1d75ae | 2013-11-25 18:01:41 +0000 | [diff] [blame] | 2182 | /* 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] | 2183 | * geometry to ensure the changes are redrawn. |
| 2184 | * |
| 2185 | * If any child surfaces exist and are mapped, ensure they’re in the same layer |
| 2186 | * as this surface. */ |
Philip Withnall | e1d75ae | 2013-11-25 18:01:41 +0000 | [diff] [blame] | 2187 | static void |
| 2188 | shell_surface_update_layer(struct shell_surface *shsurf) |
| 2189 | { |
| 2190 | struct wl_list *new_layer_link; |
| 2191 | |
| 2192 | new_layer_link = shell_surface_calculate_layer_link(shsurf); |
| 2193 | |
Ander Conselvan de Oliveira | ef6a7e4 | 2014-04-30 14:15:14 +0300 | [diff] [blame] | 2194 | if (new_layer_link == NULL) |
| 2195 | return; |
Philip Withnall | e1d75ae | 2013-11-25 18:01:41 +0000 | [diff] [blame] | 2196 | if (new_layer_link == &shsurf->view->layer_link) |
| 2197 | return; |
| 2198 | |
| 2199 | weston_view_geometry_dirty(shsurf->view); |
| 2200 | wl_list_remove(&shsurf->view->layer_link); |
| 2201 | wl_list_insert(new_layer_link, &shsurf->view->layer_link); |
| 2202 | weston_view_geometry_dirty(shsurf->view); |
| 2203 | weston_surface_damage(shsurf->surface); |
Philip Withnall | 648a4dd | 2013-11-25 18:01:44 +0000 | [diff] [blame] | 2204 | |
| 2205 | shell_surface_update_child_surface_layers(shsurf); |
Philip Withnall | e1d75ae | 2013-11-25 18:01:41 +0000 | [diff] [blame] | 2206 | } |
| 2207 | |
Alexander Larsson | f82b6ca | 2013-05-28 16:23:39 +0200 | [diff] [blame] | 2208 | static void |
Philip Withnall | dc4332f | 2013-11-25 18:01:38 +0000 | [diff] [blame] | 2209 | shell_surface_set_parent(struct shell_surface *shsurf, |
| 2210 | struct weston_surface *parent) |
| 2211 | { |
| 2212 | shsurf->parent = parent; |
Philip Withnall | 648a4dd | 2013-11-25 18:01:44 +0000 | [diff] [blame] | 2213 | |
| 2214 | wl_list_remove(&shsurf->children_link); |
| 2215 | wl_list_init(&shsurf->children_link); |
| 2216 | |
| 2217 | /* Insert into the parent surface’s child list. */ |
| 2218 | if (parent != NULL) { |
| 2219 | struct shell_surface *parent_shsurf = get_shell_surface(parent); |
| 2220 | if (parent_shsurf != NULL) |
| 2221 | wl_list_insert(&parent_shsurf->children_list, |
| 2222 | &shsurf->children_link); |
| 2223 | } |
Philip Withnall | dc4332f | 2013-11-25 18:01:38 +0000 | [diff] [blame] | 2224 | } |
| 2225 | |
| 2226 | static void |
Philip Withnall | 352e7ed | 2013-11-25 18:01:35 +0000 | [diff] [blame] | 2227 | shell_surface_set_output(struct shell_surface *shsurf, |
| 2228 | struct weston_output *output) |
| 2229 | { |
| 2230 | struct weston_surface *es = shsurf->surface; |
| 2231 | |
| 2232 | /* get the default output, if the client set it as NULL |
| 2233 | check whether the ouput is available */ |
| 2234 | if (output) |
| 2235 | shsurf->output = output; |
| 2236 | else if (es->output) |
| 2237 | shsurf->output = es->output; |
| 2238 | else |
| 2239 | shsurf->output = get_default_output(es->compositor); |
| 2240 | } |
| 2241 | |
| 2242 | static void |
Rafael Antognolli | 03b1659 | 2013-12-03 15:35:42 -0200 | [diff] [blame] | 2243 | surface_clear_next_states(struct shell_surface *shsurf) |
| 2244 | { |
| 2245 | shsurf->next_state.maximized = false; |
| 2246 | shsurf->next_state.fullscreen = false; |
| 2247 | |
| 2248 | if ((shsurf->next_state.maximized != shsurf->state.maximized) || |
| 2249 | (shsurf->next_state.fullscreen != shsurf->state.fullscreen)) |
| 2250 | shsurf->state_changed = true; |
| 2251 | } |
| 2252 | |
| 2253 | static void |
Philip Withnall | becb77e | 2013-11-25 18:01:30 +0000 | [diff] [blame] | 2254 | set_toplevel(struct shell_surface *shsurf) |
| 2255 | { |
Kristian Høgsberg | 41fbf6f | 2013-12-05 22:31:25 -0800 | [diff] [blame] | 2256 | shell_surface_set_parent(shsurf, NULL); |
| 2257 | surface_clear_next_states(shsurf); |
Kristian Høgsberg | c8f8dd8 | 2013-12-05 23:20:33 -0800 | [diff] [blame] | 2258 | shsurf->type = SHELL_SURFACE_TOPLEVEL; |
Philip Withnall | 648a4dd | 2013-11-25 18:01:44 +0000 | [diff] [blame] | 2259 | |
| 2260 | /* The layer_link is updated in set_surface_type(), |
| 2261 | * called from configure. */ |
Philip Withnall | becb77e | 2013-11-25 18:01:30 +0000 | [diff] [blame] | 2262 | } |
| 2263 | |
| 2264 | static void |
| 2265 | shell_surface_set_toplevel(struct wl_client *client, |
| 2266 | struct wl_resource *resource) |
| 2267 | { |
| 2268 | struct shell_surface *surface = wl_resource_get_user_data(resource); |
| 2269 | |
| 2270 | set_toplevel(surface); |
| 2271 | } |
| 2272 | |
| 2273 | static void |
| 2274 | set_transient(struct shell_surface *shsurf, |
| 2275 | struct weston_surface *parent, int x, int y, uint32_t flags) |
| 2276 | { |
Philip Withnall | dc4332f | 2013-11-25 18:01:38 +0000 | [diff] [blame] | 2277 | assert(parent != NULL); |
| 2278 | |
Kristian Høgsberg | 9f7e331 | 2014-01-02 22:40:37 -0800 | [diff] [blame] | 2279 | shell_surface_set_parent(shsurf, parent); |
| 2280 | |
| 2281 | surface_clear_next_states(shsurf); |
| 2282 | |
Philip Withnall | becb77e | 2013-11-25 18:01:30 +0000 | [diff] [blame] | 2283 | shsurf->transient.x = x; |
| 2284 | shsurf->transient.y = y; |
| 2285 | shsurf->transient.flags = flags; |
Philip Withnall | dc4332f | 2013-11-25 18:01:38 +0000 | [diff] [blame] | 2286 | |
Rafael Antognolli | ed207b4 | 2013-12-03 15:35:43 -0200 | [diff] [blame] | 2287 | shsurf->next_state.relative = true; |
Kristian Høgsberg | a1df7ac | 2013-12-31 15:01:01 -0800 | [diff] [blame] | 2288 | shsurf->state_changed = true; |
Kristian Høgsberg | c8f8dd8 | 2013-12-05 23:20:33 -0800 | [diff] [blame] | 2289 | shsurf->type = SHELL_SURFACE_TOPLEVEL; |
Philip Withnall | 648a4dd | 2013-11-25 18:01:44 +0000 | [diff] [blame] | 2290 | |
| 2291 | /* The layer_link is updated in set_surface_type(), |
| 2292 | * called from configure. */ |
Philip Withnall | becb77e | 2013-11-25 18:01:30 +0000 | [diff] [blame] | 2293 | } |
| 2294 | |
| 2295 | static void |
| 2296 | shell_surface_set_transient(struct wl_client *client, |
| 2297 | struct wl_resource *resource, |
| 2298 | struct wl_resource *parent_resource, |
| 2299 | int x, int y, uint32_t flags) |
| 2300 | { |
| 2301 | struct shell_surface *shsurf = wl_resource_get_user_data(resource); |
| 2302 | struct weston_surface *parent = |
| 2303 | wl_resource_get_user_data(parent_resource); |
| 2304 | |
| 2305 | set_transient(shsurf, parent, x, y, flags); |
| 2306 | } |
| 2307 | |
| 2308 | static void |
| 2309 | set_fullscreen(struct shell_surface *shsurf, |
| 2310 | uint32_t method, |
| 2311 | uint32_t framerate, |
| 2312 | struct weston_output *output) |
| 2313 | { |
Philip Withnall | 352e7ed | 2013-11-25 18:01:35 +0000 | [diff] [blame] | 2314 | shell_surface_set_output(shsurf, output); |
Philip Withnall | becb77e | 2013-11-25 18:01:30 +0000 | [diff] [blame] | 2315 | |
| 2316 | shsurf->fullscreen_output = shsurf->output; |
| 2317 | shsurf->fullscreen.type = method; |
| 2318 | shsurf->fullscreen.framerate = framerate; |
Philip Withnall | dc4332f | 2013-11-25 18:01:38 +0000 | [diff] [blame] | 2319 | |
Kristian Høgsberg | c8f8dd8 | 2013-12-05 23:20:33 -0800 | [diff] [blame] | 2320 | shsurf->type = SHELL_SURFACE_TOPLEVEL; |
Philip Withnall | becb77e | 2013-11-25 18:01:30 +0000 | [diff] [blame] | 2321 | |
| 2322 | shsurf->client->send_configure(shsurf->surface, 0, |
| 2323 | shsurf->output->width, |
| 2324 | shsurf->output->height); |
Philip Withnall | 648a4dd | 2013-11-25 18:01:44 +0000 | [diff] [blame] | 2325 | |
| 2326 | /* The layer_link is updated in set_surface_type(), |
| 2327 | * called from configure. */ |
Philip Withnall | becb77e | 2013-11-25 18:01:30 +0000 | [diff] [blame] | 2328 | } |
| 2329 | |
| 2330 | static void |
Zhang, Xiong Y | 3123693 | 2013-12-13 22:10:57 +0200 | [diff] [blame] | 2331 | weston_view_set_initial_position(struct weston_view *view, |
| 2332 | struct desktop_shell *shell); |
| 2333 | |
| 2334 | static void |
Philip Withnall | becb77e | 2013-11-25 18:01:30 +0000 | [diff] [blame] | 2335 | unset_fullscreen(struct shell_surface *shsurf) |
Alex Wu | 4539b08 | 2012-03-01 12:57:46 +0800 | [diff] [blame] | 2336 | { |
Philip Withnall | f85fe84 | 2013-11-25 18:01:37 +0000 | [diff] [blame] | 2337 | /* Unset the fullscreen output, driver configuration and transforms. */ |
Alex Wu | bd3354b | 2012-04-17 17:20:49 +0800 | [diff] [blame] | 2338 | if (shsurf->fullscreen.type == WL_SHELL_SURFACE_FULLSCREEN_METHOD_DRIVER && |
| 2339 | shell_surface_is_top_fullscreen(shsurf)) { |
Alexander Larsson | f82b6ca | 2013-05-28 16:23:39 +0200 | [diff] [blame] | 2340 | restore_output_mode(shsurf->fullscreen_output); |
Alex Wu | bd3354b | 2012-04-17 17:20:49 +0800 | [diff] [blame] | 2341 | } |
Philip Withnall | f85fe84 | 2013-11-25 18:01:37 +0000 | [diff] [blame] | 2342 | |
Alex Wu | 4539b08 | 2012-03-01 12:57:46 +0800 | [diff] [blame] | 2343 | shsurf->fullscreen.type = WL_SHELL_SURFACE_FULLSCREEN_METHOD_DEFAULT; |
| 2344 | shsurf->fullscreen.framerate = 0; |
Philip Withnall | f85fe84 | 2013-11-25 18:01:37 +0000 | [diff] [blame] | 2345 | |
Alex Wu | 4539b08 | 2012-03-01 12:57:46 +0800 | [diff] [blame] | 2346 | wl_list_remove(&shsurf->fullscreen.transform.link); |
| 2347 | wl_list_init(&shsurf->fullscreen.transform.link); |
Philip Withnall | f85fe84 | 2013-11-25 18:01:37 +0000 | [diff] [blame] | 2348 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 2349 | if (shsurf->fullscreen.black_view) |
| 2350 | weston_surface_destroy(shsurf->fullscreen.black_view->surface); |
| 2351 | shsurf->fullscreen.black_view = NULL; |
Philip Withnall | f85fe84 | 2013-11-25 18:01:37 +0000 | [diff] [blame] | 2352 | |
Zhang, Xiong Y | 3123693 | 2013-12-13 22:10:57 +0200 | [diff] [blame] | 2353 | if (shsurf->saved_position_valid) |
| 2354 | weston_view_set_position(shsurf->view, |
| 2355 | shsurf->saved_x, shsurf->saved_y); |
| 2356 | else |
| 2357 | weston_view_set_initial_position(shsurf->view, shsurf->shell); |
| 2358 | |
Alex Wu | 7bcb8bd | 2012-04-27 09:07:24 +0800 | [diff] [blame] | 2359 | if (shsurf->saved_rotation_valid) { |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 2360 | wl_list_insert(&shsurf->view->geometry.transformation_list, |
Philip Withnall | becb77e | 2013-11-25 18:01:30 +0000 | [diff] [blame] | 2361 | &shsurf->rotation.transform.link); |
Alex Wu | 7bcb8bd | 2012-04-27 09:07:24 +0800 | [diff] [blame] | 2362 | shsurf->saved_rotation_valid = false; |
| 2363 | } |
Rafal Mielniczuk | 3e3862c | 2012-10-07 20:25:36 +0200 | [diff] [blame] | 2364 | |
Philip Withnall | e1d75ae | 2013-11-25 18:01:41 +0000 | [diff] [blame] | 2365 | /* Layer is updated in set_surface_type(). */ |
Alex Wu | 4539b08 | 2012-03-01 12:57:46 +0800 | [diff] [blame] | 2366 | } |
| 2367 | |
Rafal Mielniczuk | fffdcdd | 2013-03-11 19:26:54 +0100 | [diff] [blame] | 2368 | static void |
Philip Withnall | becb77e | 2013-11-25 18:01:30 +0000 | [diff] [blame] | 2369 | shell_surface_set_fullscreen(struct wl_client *client, |
| 2370 | struct wl_resource *resource, |
| 2371 | uint32_t method, |
| 2372 | uint32_t framerate, |
| 2373 | struct wl_resource *output_resource) |
| 2374 | { |
| 2375 | struct shell_surface *shsurf = wl_resource_get_user_data(resource); |
| 2376 | struct weston_output *output; |
| 2377 | |
| 2378 | if (output_resource) |
| 2379 | output = wl_resource_get_user_data(output_resource); |
| 2380 | else |
| 2381 | output = NULL; |
| 2382 | |
Rafael Antognolli | 4b99a40 | 2013-12-03 15:35:44 -0200 | [diff] [blame] | 2383 | shell_surface_set_parent(shsurf, NULL); |
| 2384 | |
Rafael Antognolli | 03b1659 | 2013-12-03 15:35:42 -0200 | [diff] [blame] | 2385 | surface_clear_next_states(shsurf); |
Philip Withnall | becb77e | 2013-11-25 18:01:30 +0000 | [diff] [blame] | 2386 | set_fullscreen(shsurf, method, framerate, output); |
Jasper St. Pierre | 8c6aa45 | 2014-02-08 18:29:49 -0500 | [diff] [blame] | 2387 | |
| 2388 | shsurf->next_state.fullscreen = true; |
| 2389 | shsurf->state_changed = true; |
Philip Withnall | becb77e | 2013-11-25 18:01:30 +0000 | [diff] [blame] | 2390 | } |
| 2391 | |
| 2392 | static void |
| 2393 | set_popup(struct shell_surface *shsurf, |
| 2394 | struct weston_surface *parent, |
| 2395 | struct weston_seat *seat, |
| 2396 | uint32_t serial, |
| 2397 | int32_t x, |
| 2398 | int32_t y) |
| 2399 | { |
Philip Withnall | dc4332f | 2013-11-25 18:01:38 +0000 | [diff] [blame] | 2400 | assert(parent != NULL); |
| 2401 | |
Philip Withnall | becb77e | 2013-11-25 18:01:30 +0000 | [diff] [blame] | 2402 | shsurf->popup.shseat = get_shell_seat(seat); |
| 2403 | shsurf->popup.serial = serial; |
| 2404 | shsurf->popup.x = x; |
| 2405 | shsurf->popup.y = y; |
Philip Withnall | dc4332f | 2013-11-25 18:01:38 +0000 | [diff] [blame] | 2406 | |
Kristian Høgsberg | c8f8dd8 | 2013-12-05 23:20:33 -0800 | [diff] [blame] | 2407 | shsurf->type = SHELL_SURFACE_POPUP; |
Philip Withnall | becb77e | 2013-11-25 18:01:30 +0000 | [diff] [blame] | 2408 | } |
| 2409 | |
| 2410 | static void |
| 2411 | shell_surface_set_popup(struct wl_client *client, |
| 2412 | struct wl_resource *resource, |
| 2413 | struct wl_resource *seat_resource, |
| 2414 | uint32_t serial, |
| 2415 | struct wl_resource *parent_resource, |
| 2416 | int32_t x, int32_t y, uint32_t flags) |
| 2417 | { |
| 2418 | struct shell_surface *shsurf = wl_resource_get_user_data(resource); |
Rafael Antognolli | 4b99a40 | 2013-12-03 15:35:44 -0200 | [diff] [blame] | 2419 | struct weston_surface *parent = |
| 2420 | wl_resource_get_user_data(parent_resource); |
| 2421 | |
| 2422 | shell_surface_set_parent(shsurf, parent); |
Philip Withnall | becb77e | 2013-11-25 18:01:30 +0000 | [diff] [blame] | 2423 | |
Rafael Antognolli | 03b1659 | 2013-12-03 15:35:42 -0200 | [diff] [blame] | 2424 | surface_clear_next_states(shsurf); |
Philip Withnall | becb77e | 2013-11-25 18:01:30 +0000 | [diff] [blame] | 2425 | set_popup(shsurf, |
Rafael Antognolli | 4b99a40 | 2013-12-03 15:35:44 -0200 | [diff] [blame] | 2426 | parent, |
Philip Withnall | becb77e | 2013-11-25 18:01:30 +0000 | [diff] [blame] | 2427 | wl_resource_get_user_data(seat_resource), |
| 2428 | serial, x, y); |
| 2429 | } |
| 2430 | |
| 2431 | static void |
| 2432 | set_maximized(struct shell_surface *shsurf, |
| 2433 | struct weston_output *output) |
| 2434 | { |
| 2435 | struct desktop_shell *shell; |
| 2436 | uint32_t edges = 0, panel_height = 0; |
Philip Withnall | becb77e | 2013-11-25 18:01:30 +0000 | [diff] [blame] | 2437 | |
Philip Withnall | 352e7ed | 2013-11-25 18:01:35 +0000 | [diff] [blame] | 2438 | shell_surface_set_output(shsurf, output); |
Philip Withnall | becb77e | 2013-11-25 18:01:30 +0000 | [diff] [blame] | 2439 | |
| 2440 | shell = shell_surface_get_shell(shsurf); |
| 2441 | panel_height = get_output_panel_height(shell, shsurf->output); |
| 2442 | edges = WL_SHELL_SURFACE_RESIZE_TOP | WL_SHELL_SURFACE_RESIZE_LEFT; |
| 2443 | |
| 2444 | shsurf->client->send_configure(shsurf->surface, edges, |
| 2445 | shsurf->output->width, |
| 2446 | shsurf->output->height - panel_height); |
| 2447 | |
Kristian Høgsberg | c8f8dd8 | 2013-12-05 23:20:33 -0800 | [diff] [blame] | 2448 | shsurf->type = SHELL_SURFACE_TOPLEVEL; |
Philip Withnall | becb77e | 2013-11-25 18:01:30 +0000 | [diff] [blame] | 2449 | } |
| 2450 | |
| 2451 | static void |
| 2452 | unset_maximized(struct shell_surface *shsurf) |
Rafal Mielniczuk | fffdcdd | 2013-03-11 19:26:54 +0100 | [diff] [blame] | 2453 | { |
Rafal Mielniczuk | fffdcdd | 2013-03-11 19:26:54 +0100 | [diff] [blame] | 2454 | /* undo all maximized things here */ |
| 2455 | shsurf->output = get_default_output(shsurf->surface->compositor); |
Zhang, Xiong Y | 3123693 | 2013-12-13 22:10:57 +0200 | [diff] [blame] | 2456 | |
| 2457 | if (shsurf->saved_position_valid) |
| 2458 | weston_view_set_position(shsurf->view, |
| 2459 | shsurf->saved_x, shsurf->saved_y); |
| 2460 | else |
| 2461 | weston_view_set_initial_position(shsurf->view, shsurf->shell); |
Rafal Mielniczuk | fffdcdd | 2013-03-11 19:26:54 +0100 | [diff] [blame] | 2462 | |
| 2463 | if (shsurf->saved_rotation_valid) { |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 2464 | wl_list_insert(&shsurf->view->geometry.transformation_list, |
| 2465 | &shsurf->rotation.transform.link); |
Rafal Mielniczuk | fffdcdd | 2013-03-11 19:26:54 +0100 | [diff] [blame] | 2466 | shsurf->saved_rotation_valid = false; |
| 2467 | } |
| 2468 | |
Philip Withnall | e1d75ae | 2013-11-25 18:01:41 +0000 | [diff] [blame] | 2469 | /* Layer is updated in set_surface_type(). */ |
Rafal Mielniczuk | fffdcdd | 2013-03-11 19:26:54 +0100 | [diff] [blame] | 2470 | } |
| 2471 | |
Philip Withnall | becb77e | 2013-11-25 18:01:30 +0000 | [diff] [blame] | 2472 | static void |
Manuel Bachmann | 50c87db | 2014-02-26 15:52:13 +0100 | [diff] [blame] | 2473 | set_minimized(struct weston_surface *surface, uint32_t is_true) |
| 2474 | { |
| 2475 | struct shell_surface *shsurf; |
| 2476 | struct workspace *current_ws; |
| 2477 | struct weston_seat *seat; |
| 2478 | struct weston_surface *focus; |
| 2479 | struct weston_view *view; |
| 2480 | |
| 2481 | view = get_default_view(surface); |
| 2482 | if (!view) |
| 2483 | return; |
| 2484 | |
| 2485 | assert(weston_surface_get_main_surface(view->surface) == view->surface); |
| 2486 | |
| 2487 | shsurf = get_shell_surface(surface); |
| 2488 | current_ws = get_current_workspace(shsurf->shell); |
| 2489 | |
| 2490 | wl_list_remove(&view->layer_link); |
| 2491 | /* hide or show, depending on the state */ |
| 2492 | if (is_true) { |
| 2493 | wl_list_insert(&shsurf->shell->minimized_layer.view_list, &view->layer_link); |
| 2494 | |
| 2495 | drop_focus_state(shsurf->shell, current_ws, view->surface); |
| 2496 | wl_list_for_each(seat, &shsurf->shell->compositor->seat_list, link) { |
| 2497 | if (!seat->keyboard) |
| 2498 | continue; |
| 2499 | focus = weston_surface_get_main_surface(seat->keyboard->focus); |
| 2500 | if (focus == view->surface) |
| 2501 | weston_keyboard_set_focus(seat->keyboard, NULL); |
| 2502 | } |
| 2503 | } |
| 2504 | else { |
| 2505 | wl_list_insert(¤t_ws->layer.view_list, &view->layer_link); |
| 2506 | |
| 2507 | wl_list_for_each(seat, &shsurf->shell->compositor->seat_list, link) { |
| 2508 | if (!seat->keyboard) |
| 2509 | continue; |
Emilio Pozuelo Monfort | 9e7c759 | 2014-01-30 14:01:10 +0100 | [diff] [blame] | 2510 | activate(shsurf->shell, view->surface, seat, true); |
Manuel Bachmann | 50c87db | 2014-02-26 15:52:13 +0100 | [diff] [blame] | 2511 | } |
| 2512 | } |
| 2513 | |
| 2514 | shell_surface_update_child_surface_layers(shsurf); |
| 2515 | |
| 2516 | weston_view_damage_below(view); |
| 2517 | } |
| 2518 | |
| 2519 | static void |
Philip Withnall | becb77e | 2013-11-25 18:01:30 +0000 | [diff] [blame] | 2520 | shell_surface_set_maximized(struct wl_client *client, |
| 2521 | struct wl_resource *resource, |
| 2522 | struct wl_resource *output_resource) |
| 2523 | { |
| 2524 | struct shell_surface *shsurf = wl_resource_get_user_data(resource); |
| 2525 | struct weston_output *output; |
| 2526 | |
| 2527 | if (output_resource) |
| 2528 | output = wl_resource_get_user_data(output_resource); |
| 2529 | else |
| 2530 | output = NULL; |
| 2531 | |
Rafael Antognolli | 4b99a40 | 2013-12-03 15:35:44 -0200 | [diff] [blame] | 2532 | shell_surface_set_parent(shsurf, NULL); |
| 2533 | |
Rafael Antognolli | 03b1659 | 2013-12-03 15:35:42 -0200 | [diff] [blame] | 2534 | surface_clear_next_states(shsurf); |
Philip Withnall | becb77e | 2013-11-25 18:01:30 +0000 | [diff] [blame] | 2535 | set_maximized(shsurf, output); |
Jasper St. Pierre | 8c6aa45 | 2014-02-08 18:29:49 -0500 | [diff] [blame] | 2536 | |
| 2537 | shsurf->next_state.maximized = true; |
| 2538 | shsurf->state_changed = true; |
Philip Withnall | becb77e | 2013-11-25 18:01:30 +0000 | [diff] [blame] | 2539 | } |
| 2540 | |
Philip Withnall | e1d75ae | 2013-11-25 18:01:41 +0000 | [diff] [blame] | 2541 | /* This is only ever called from set_surface_type(), so there’s no need to |
| 2542 | * update layer_links here, since they’ll be updated when we return. */ |
Pekka Paalanen | 9826223 | 2011-12-01 10:42:22 +0200 | [diff] [blame] | 2543 | static int |
Philip Withnall | becb77e | 2013-11-25 18:01:30 +0000 | [diff] [blame] | 2544 | reset_surface_type(struct shell_surface *surface) |
Pekka Paalanen | 9826223 | 2011-12-01 10:42:22 +0200 | [diff] [blame] | 2545 | { |
Rafael Antognolli | 03b1659 | 2013-12-03 15:35:42 -0200 | [diff] [blame] | 2546 | if (surface->state.fullscreen) |
Philip Withnall | becb77e | 2013-11-25 18:01:30 +0000 | [diff] [blame] | 2547 | unset_fullscreen(surface); |
Rafael Antognolli | 03b1659 | 2013-12-03 15:35:42 -0200 | [diff] [blame] | 2548 | if (surface->state.maximized) |
Philip Withnall | becb77e | 2013-11-25 18:01:30 +0000 | [diff] [blame] | 2549 | unset_maximized(surface); |
Pekka Paalanen | 9826223 | 2011-12-01 10:42:22 +0200 | [diff] [blame] | 2550 | |
Pekka Paalanen | 9826223 | 2011-12-01 10:42:22 +0200 | [diff] [blame] | 2551 | return 0; |
| 2552 | } |
| 2553 | |
Kristian Høgsberg | 4cca349 | 2011-01-18 07:53:49 -0500 | [diff] [blame] | 2554 | static void |
Rafael Antognolli | 03b1659 | 2013-12-03 15:35:42 -0200 | [diff] [blame] | 2555 | set_full_output(struct shell_surface *shsurf) |
| 2556 | { |
| 2557 | shsurf->saved_x = shsurf->view->geometry.x; |
| 2558 | shsurf->saved_y = shsurf->view->geometry.y; |
Rafael Antognolli | 3c4e3f7 | 2013-12-03 15:35:46 -0200 | [diff] [blame] | 2559 | shsurf->saved_width = shsurf->surface->width; |
| 2560 | shsurf->saved_height = shsurf->surface->height; |
| 2561 | shsurf->saved_size_valid = true; |
Rafael Antognolli | 03b1659 | 2013-12-03 15:35:42 -0200 | [diff] [blame] | 2562 | shsurf->saved_position_valid = true; |
| 2563 | |
| 2564 | if (!wl_list_empty(&shsurf->rotation.transform.link)) { |
| 2565 | wl_list_remove(&shsurf->rotation.transform.link); |
| 2566 | wl_list_init(&shsurf->rotation.transform.link); |
| 2567 | weston_view_geometry_dirty(shsurf->view); |
| 2568 | shsurf->saved_rotation_valid = true; |
| 2569 | } |
| 2570 | } |
| 2571 | |
| 2572 | static void |
Kristian Høgsberg | 7f366e7 | 2012-04-27 17:20:01 -0400 | [diff] [blame] | 2573 | set_surface_type(struct shell_surface *shsurf) |
| 2574 | { |
Kristian Høgsberg | 8150b19 | 2012-06-27 10:22:58 -0400 | [diff] [blame] | 2575 | struct weston_surface *pes = shsurf->parent; |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 2576 | struct weston_view *pev = get_default_view(pes); |
Kristian Høgsberg | 7f366e7 | 2012-04-27 17:20:01 -0400 | [diff] [blame] | 2577 | |
Philip Withnall | becb77e | 2013-11-25 18:01:30 +0000 | [diff] [blame] | 2578 | reset_surface_type(shsurf); |
Kristian Høgsberg | 7f366e7 | 2012-04-27 17:20:01 -0400 | [diff] [blame] | 2579 | |
Rafael Antognolli | 03b1659 | 2013-12-03 15:35:42 -0200 | [diff] [blame] | 2580 | shsurf->state = shsurf->next_state; |
Rafael Antognolli | 03b1659 | 2013-12-03 15:35:42 -0200 | [diff] [blame] | 2581 | shsurf->state_changed = false; |
Kristian Høgsberg | 7f366e7 | 2012-04-27 17:20:01 -0400 | [diff] [blame] | 2582 | |
| 2583 | switch (shsurf->type) { |
| 2584 | case SHELL_SURFACE_TOPLEVEL: |
Rafael Antognolli | ed207b4 | 2013-12-03 15:35:43 -0200 | [diff] [blame] | 2585 | if (shsurf->state.maximized || shsurf->state.fullscreen) { |
Rafael Antognolli | 03b1659 | 2013-12-03 15:35:42 -0200 | [diff] [blame] | 2586 | set_full_output(shsurf); |
Rafael Antognolli | ed207b4 | 2013-12-03 15:35:43 -0200 | [diff] [blame] | 2587 | } else if (shsurf->state.relative && pev) { |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 2588 | weston_view_set_position(shsurf->view, |
| 2589 | pev->geometry.x + shsurf->transient.x, |
| 2590 | pev->geometry.y + shsurf->transient.y); |
Rafael Antognolli | ed207b4 | 2013-12-03 15:35:43 -0200 | [diff] [blame] | 2591 | } |
Rafael Antognolli | 44a3162 | 2013-12-04 18:37:16 -0200 | [diff] [blame] | 2592 | break; |
Kristian Høgsberg | 7f366e7 | 2012-04-27 17:20:01 -0400 | [diff] [blame] | 2593 | |
Tiago Vignatti | fb2adba | 2013-06-12 15:43:21 -0300 | [diff] [blame] | 2594 | case SHELL_SURFACE_XWAYLAND: |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 2595 | weston_view_set_position(shsurf->view, shsurf->transient.x, |
| 2596 | shsurf->transient.y); |
Tiago Vignatti | fb2adba | 2013-06-12 15:43:21 -0300 | [diff] [blame] | 2597 | break; |
| 2598 | |
Philip Withnall | 0f640e2 | 2013-11-25 18:01:31 +0000 | [diff] [blame] | 2599 | case SHELL_SURFACE_POPUP: |
| 2600 | case SHELL_SURFACE_NONE: |
Kristian Høgsberg | 7f366e7 | 2012-04-27 17:20:01 -0400 | [diff] [blame] | 2601 | default: |
| 2602 | break; |
| 2603 | } |
Philip Withnall | e1d75ae | 2013-11-25 18:01:41 +0000 | [diff] [blame] | 2604 | |
| 2605 | /* Update the surface’s layer. */ |
| 2606 | shell_surface_update_layer(shsurf); |
Kristian Høgsberg | 7f366e7 | 2012-04-27 17:20:01 -0400 | [diff] [blame] | 2607 | } |
| 2608 | |
Tiago Vignatti | be14326 | 2012-04-16 17:31:41 +0300 | [diff] [blame] | 2609 | static struct desktop_shell * |
Juan Zhao | 96879df | 2012-02-07 08:45:41 +0800 | [diff] [blame] | 2610 | shell_surface_get_shell(struct shell_surface *shsurf) |
Pekka Paalanen | af0e34c | 2011-12-02 10:59:17 +0200 | [diff] [blame] | 2611 | { |
Kristian Høgsberg | 02e79dc | 2012-04-12 09:55:26 -0400 | [diff] [blame] | 2612 | return shsurf->shell; |
Juan Zhao | 96879df | 2012-02-07 08:45:41 +0800 | [diff] [blame] | 2613 | } |
| 2614 | |
Alex Wu | 2185843 | 2012-04-01 20:13:08 +0800 | [diff] [blame] | 2615 | static void |
Jason Ekstrand | 918f2dd | 2013-12-02 21:01:53 -0600 | [diff] [blame] | 2616 | 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] | 2617 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 2618 | static struct weston_view * |
Alex Wu | 4539b08 | 2012-03-01 12:57:46 +0800 | [diff] [blame] | 2619 | create_black_surface(struct weston_compositor *ec, |
Alex Wu | 2185843 | 2012-04-01 20:13:08 +0800 | [diff] [blame] | 2620 | struct weston_surface *fs_surface, |
John Kåre Alsaker | 490d02a | 2012-09-30 02:57:21 +0200 | [diff] [blame] | 2621 | float x, float y, int w, int h) |
Alex Wu | 4539b08 | 2012-03-01 12:57:46 +0800 | [diff] [blame] | 2622 | { |
| 2623 | struct weston_surface *surface = NULL; |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 2624 | struct weston_view *view; |
Alex Wu | 4539b08 | 2012-03-01 12:57:46 +0800 | [diff] [blame] | 2625 | |
| 2626 | surface = weston_surface_create(ec); |
| 2627 | if (surface == NULL) { |
Martin Minarik | 6d11836 | 2012-06-07 18:01:59 +0200 | [diff] [blame] | 2628 | weston_log("no memory\n"); |
Alex Wu | 4539b08 | 2012-03-01 12:57:46 +0800 | [diff] [blame] | 2629 | return NULL; |
| 2630 | } |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 2631 | view = weston_view_create(surface); |
| 2632 | if (surface == NULL) { |
| 2633 | weston_log("no memory\n"); |
| 2634 | weston_surface_destroy(surface); |
| 2635 | return NULL; |
| 2636 | } |
Alex Wu | 4539b08 | 2012-03-01 12:57:46 +0800 | [diff] [blame] | 2637 | |
Alex Wu | 2185843 | 2012-04-01 20:13:08 +0800 | [diff] [blame] | 2638 | surface->configure = black_surface_configure; |
Giulio Camuffo | 7fe01b1 | 2013-03-28 18:02:42 +0100 | [diff] [blame] | 2639 | surface->configure_private = fs_surface; |
Alex Wu | 4539b08 | 2012-03-01 12:57:46 +0800 | [diff] [blame] | 2640 | weston_surface_set_color(surface, 0.0, 0.0, 0.0, 1); |
Pekka Paalanen | 71f6f3b | 2012-10-10 12:49:26 +0300 | [diff] [blame] | 2641 | pixman_region32_fini(&surface->opaque); |
Kristian Høgsberg | 61f00f5 | 2012-08-03 16:31:36 -0400 | [diff] [blame] | 2642 | pixman_region32_init_rect(&surface->opaque, 0, 0, w, h); |
Jonas Ådahl | 33619a4 | 2013-01-15 21:25:55 +0100 | [diff] [blame] | 2643 | pixman_region32_fini(&surface->input); |
| 2644 | pixman_region32_init_rect(&surface->input, 0, 0, w, h); |
Jason Ekstrand | 918f2dd | 2013-12-02 21:01:53 -0600 | [diff] [blame] | 2645 | |
Jason Ekstrand | 6228ee2 | 2014-01-01 15:58:57 -0600 | [diff] [blame] | 2646 | weston_surface_set_size(surface, w, h); |
Jason Ekstrand | 918f2dd | 2013-12-02 21:01:53 -0600 | [diff] [blame] | 2647 | weston_view_set_position(view, x, y); |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 2648 | |
| 2649 | return view; |
Alex Wu | 4539b08 | 2012-03-01 12:57:46 +0800 | [diff] [blame] | 2650 | } |
| 2651 | |
Philip Withnall | ed8f1a9 | 2013-11-25 18:01:43 +0000 | [diff] [blame] | 2652 | static void |
| 2653 | shell_ensure_fullscreen_black_view(struct shell_surface *shsurf) |
| 2654 | { |
| 2655 | struct weston_output *output = shsurf->fullscreen_output; |
| 2656 | |
Rafael Antognolli | 03b1659 | 2013-12-03 15:35:42 -0200 | [diff] [blame] | 2657 | assert(shsurf->state.fullscreen); |
Philip Withnall | ed8f1a9 | 2013-11-25 18:01:43 +0000 | [diff] [blame] | 2658 | |
| 2659 | if (!shsurf->fullscreen.black_view) |
| 2660 | shsurf->fullscreen.black_view = |
| 2661 | create_black_surface(shsurf->surface->compositor, |
| 2662 | shsurf->surface, |
| 2663 | output->x, output->y, |
| 2664 | output->width, |
| 2665 | output->height); |
| 2666 | |
| 2667 | weston_view_geometry_dirty(shsurf->fullscreen.black_view); |
| 2668 | wl_list_remove(&shsurf->fullscreen.black_view->layer_link); |
| 2669 | wl_list_insert(&shsurf->view->layer_link, |
| 2670 | &shsurf->fullscreen.black_view->layer_link); |
| 2671 | weston_view_geometry_dirty(shsurf->fullscreen.black_view); |
| 2672 | weston_surface_damage(shsurf->surface); |
Emilio Pozuelo Monfort | 9e7c759 | 2014-01-30 14:01:10 +0100 | [diff] [blame] | 2673 | |
| 2674 | shsurf->state.lowered = false; |
Philip Withnall | ed8f1a9 | 2013-11-25 18:01:43 +0000 | [diff] [blame] | 2675 | } |
| 2676 | |
Alex Wu | 4539b08 | 2012-03-01 12:57:46 +0800 | [diff] [blame] | 2677 | /* Create black surface and append it to the associated fullscreen surface. |
| 2678 | * Handle size dismatch and positioning according to the method. */ |
| 2679 | static void |
| 2680 | shell_configure_fullscreen(struct shell_surface *shsurf) |
| 2681 | { |
| 2682 | struct weston_output *output = shsurf->fullscreen_output; |
| 2683 | struct weston_surface *surface = shsurf->surface; |
| 2684 | struct weston_matrix *matrix; |
Kristian Høgsberg | 240dfeb | 2012-07-12 12:32:31 -0400 | [diff] [blame] | 2685 | float scale, output_aspect, surface_aspect, x, y; |
Giulio Camuffo | b836664 | 2013-04-25 13:57:46 +0300 | [diff] [blame] | 2686 | int32_t surf_x, surf_y, surf_width, surf_height; |
Alex Wu | 4539b08 | 2012-03-01 12:57:46 +0800 | [diff] [blame] | 2687 | |
Alexander Larsson | f82b6ca | 2013-05-28 16:23:39 +0200 | [diff] [blame] | 2688 | if (shsurf->fullscreen.type != WL_SHELL_SURFACE_FULLSCREEN_METHOD_DRIVER) |
| 2689 | restore_output_mode(output); |
| 2690 | |
Emilio Pozuelo Monfort | 9e7c759 | 2014-01-30 14:01:10 +0100 | [diff] [blame] | 2691 | /* Reverse the effect of lower_fullscreen_layer() */ |
| 2692 | wl_list_remove(&shsurf->view->layer_link); |
| 2693 | wl_list_insert(&shsurf->shell->fullscreen_layer.view_list, &shsurf->view->layer_link); |
| 2694 | |
Philip Withnall | ed8f1a9 | 2013-11-25 18:01:43 +0000 | [diff] [blame] | 2695 | shell_ensure_fullscreen_black_view(shsurf); |
Alex Wu | 4539b08 | 2012-03-01 12:57:46 +0800 | [diff] [blame] | 2696 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 2697 | surface_subsurfaces_boundingbox(shsurf->surface, &surf_x, &surf_y, |
Giulio Camuffo | b836664 | 2013-04-25 13:57:46 +0300 | [diff] [blame] | 2698 | &surf_width, &surf_height); |
| 2699 | |
Alex Wu | 4539b08 | 2012-03-01 12:57:46 +0800 | [diff] [blame] | 2700 | switch (shsurf->fullscreen.type) { |
| 2701 | case WL_SHELL_SURFACE_FULLSCREEN_METHOD_DEFAULT: |
Pekka Paalanen | de685b8 | 2012-12-04 15:58:12 +0200 | [diff] [blame] | 2702 | if (surface->buffer_ref.buffer) |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 2703 | center_on_output(shsurf->view, shsurf->fullscreen_output); |
Alex Wu | 4539b08 | 2012-03-01 12:57:46 +0800 | [diff] [blame] | 2704 | break; |
| 2705 | case WL_SHELL_SURFACE_FULLSCREEN_METHOD_SCALE: |
Rob Bradford | 9f3dd15 | 2013-02-12 11:53:47 +0000 | [diff] [blame] | 2706 | /* 1:1 mapping between surface and output dimensions */ |
Giulio Camuffo | b836664 | 2013-04-25 13:57:46 +0300 | [diff] [blame] | 2707 | if (output->width == surf_width && |
| 2708 | output->height == surf_height) { |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 2709 | weston_view_set_position(shsurf->view, |
| 2710 | output->x - surf_x, |
| 2711 | output->y - surf_y); |
Rob Bradford | 9f3dd15 | 2013-02-12 11:53:47 +0000 | [diff] [blame] | 2712 | break; |
| 2713 | } |
| 2714 | |
Alex Wu | 4539b08 | 2012-03-01 12:57:46 +0800 | [diff] [blame] | 2715 | matrix = &shsurf->fullscreen.transform.matrix; |
| 2716 | weston_matrix_init(matrix); |
Kristian Høgsberg | 240dfeb | 2012-07-12 12:32:31 -0400 | [diff] [blame] | 2717 | |
Scott Moreau | 1bad5db | 2012-08-18 01:04:05 -0600 | [diff] [blame] | 2718 | output_aspect = (float) output->width / |
| 2719 | (float) output->height; |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 2720 | /* XXX: Use surf_width and surf_height here? */ |
| 2721 | surface_aspect = (float) surface->width / |
| 2722 | (float) surface->height; |
Kristian Høgsberg | 240dfeb | 2012-07-12 12:32:31 -0400 | [diff] [blame] | 2723 | if (output_aspect < surface_aspect) |
Scott Moreau | 1bad5db | 2012-08-18 01:04:05 -0600 | [diff] [blame] | 2724 | scale = (float) output->width / |
Giulio Camuffo | b836664 | 2013-04-25 13:57:46 +0300 | [diff] [blame] | 2725 | (float) surf_width; |
Kristian Høgsberg | 240dfeb | 2012-07-12 12:32:31 -0400 | [diff] [blame] | 2726 | else |
Scott Moreau | 1bad5db | 2012-08-18 01:04:05 -0600 | [diff] [blame] | 2727 | scale = (float) output->height / |
Giulio Camuffo | b836664 | 2013-04-25 13:57:46 +0300 | [diff] [blame] | 2728 | (float) surf_height; |
Kristian Høgsberg | 240dfeb | 2012-07-12 12:32:31 -0400 | [diff] [blame] | 2729 | |
Alex Wu | 4539b08 | 2012-03-01 12:57:46 +0800 | [diff] [blame] | 2730 | weston_matrix_scale(matrix, scale, scale, 1); |
| 2731 | wl_list_remove(&shsurf->fullscreen.transform.link); |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 2732 | wl_list_insert(&shsurf->view->geometry.transformation_list, |
Alex Wu | 4539b08 | 2012-03-01 12:57:46 +0800 | [diff] [blame] | 2733 | &shsurf->fullscreen.transform.link); |
Giulio Camuffo | b836664 | 2013-04-25 13:57:46 +0300 | [diff] [blame] | 2734 | x = output->x + (output->width - surf_width * scale) / 2 - surf_x; |
| 2735 | y = output->y + (output->height - surf_height * scale) / 2 - surf_y; |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 2736 | weston_view_set_position(shsurf->view, x, y); |
Kristian Høgsberg | 240dfeb | 2012-07-12 12:32:31 -0400 | [diff] [blame] | 2737 | |
Alex Wu | 4539b08 | 2012-03-01 12:57:46 +0800 | [diff] [blame] | 2738 | break; |
| 2739 | case WL_SHELL_SURFACE_FULLSCREEN_METHOD_DRIVER: |
Alex Wu | bd3354b | 2012-04-17 17:20:49 +0800 | [diff] [blame] | 2740 | if (shell_surface_is_top_fullscreen(shsurf)) { |
Quentin Glidic | c0d79ce | 2013-01-29 14:16:13 +0100 | [diff] [blame] | 2741 | struct weston_mode mode = {0, |
Pekka Paalanen | 952b6c8 | 2014-03-14 14:38:15 +0200 | [diff] [blame] | 2742 | surf_width * surface->buffer_viewport.buffer.scale, |
| 2743 | surf_height * surface->buffer_viewport.buffer.scale, |
Alex Wu | bd3354b | 2012-04-17 17:20:49 +0800 | [diff] [blame] | 2744 | shsurf->fullscreen.framerate}; |
| 2745 | |
Pekka Paalanen | 952b6c8 | 2014-03-14 14:38:15 +0200 | [diff] [blame] | 2746 | if (weston_output_switch_mode(output, &mode, surface->buffer_viewport.buffer.scale, |
Hardening | 57388e4 | 2013-09-18 23:56:36 +0200 | [diff] [blame] | 2747 | WESTON_MODE_SWITCH_SET_TEMPORARY) == 0) { |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 2748 | weston_view_set_position(shsurf->view, |
| 2749 | output->x - surf_x, |
| 2750 | output->y - surf_y); |
Jason Ekstrand | 918f2dd | 2013-12-02 21:01:53 -0600 | [diff] [blame] | 2751 | shsurf->fullscreen.black_view->surface->width = output->width; |
| 2752 | shsurf->fullscreen.black_view->surface->height = output->height; |
| 2753 | weston_view_set_position(shsurf->fullscreen.black_view, |
| 2754 | output->x - surf_x, |
| 2755 | output->y - surf_y); |
Alex Wu | bd3354b | 2012-04-17 17:20:49 +0800 | [diff] [blame] | 2756 | break; |
Alexander Larsson | d622ed3 | 2013-05-28 16:23:40 +0200 | [diff] [blame] | 2757 | } else { |
Alexander Larsson | f82b6ca | 2013-05-28 16:23:39 +0200 | [diff] [blame] | 2758 | restore_output_mode(output); |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 2759 | center_on_output(shsurf->view, output); |
Alexander Larsson | d622ed3 | 2013-05-28 16:23:40 +0200 | [diff] [blame] | 2760 | } |
Alex Wu | bd3354b | 2012-04-17 17:20:49 +0800 | [diff] [blame] | 2761 | } |
Alex Wu | 4539b08 | 2012-03-01 12:57:46 +0800 | [diff] [blame] | 2762 | break; |
| 2763 | case WL_SHELL_SURFACE_FULLSCREEN_METHOD_FILL: |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 2764 | center_on_output(shsurf->view, output); |
Alex Wu | 4539b08 | 2012-03-01 12:57:46 +0800 | [diff] [blame] | 2765 | break; |
| 2766 | default: |
| 2767 | break; |
| 2768 | } |
| 2769 | } |
| 2770 | |
Alex Wu | 4539b08 | 2012-03-01 12:57:46 +0800 | [diff] [blame] | 2771 | static void |
| 2772 | shell_map_fullscreen(struct shell_surface *shsurf) |
| 2773 | { |
Alex Wu | bd3354b | 2012-04-17 17:20:49 +0800 | [diff] [blame] | 2774 | shell_configure_fullscreen(shsurf); |
Alex Wu | 4539b08 | 2012-03-01 12:57:46 +0800 | [diff] [blame] | 2775 | } |
| 2776 | |
Kristian Høgsberg | 7a5c979 | 2011-06-18 06:12:54 -0400 | [diff] [blame] | 2777 | static void |
Tiago Vignatti | fb2adba | 2013-06-12 15:43:21 -0300 | [diff] [blame] | 2778 | set_xwayland(struct shell_surface *shsurf, int x, int y, uint32_t flags) |
| 2779 | { |
| 2780 | /* XXX: using the same fields for transient type */ |
Rafael Antognolli | 03b1659 | 2013-12-03 15:35:42 -0200 | [diff] [blame] | 2781 | surface_clear_next_states(shsurf); |
Tiago Vignatti | fb2adba | 2013-06-12 15:43:21 -0300 | [diff] [blame] | 2782 | shsurf->transient.x = x; |
| 2783 | shsurf->transient.y = y; |
| 2784 | shsurf->transient.flags = flags; |
Philip Withnall | dc4332f | 2013-11-25 18:01:38 +0000 | [diff] [blame] | 2785 | |
| 2786 | shell_surface_set_parent(shsurf, NULL); |
| 2787 | |
Kristian Høgsberg | c8f8dd8 | 2013-12-05 23:20:33 -0800 | [diff] [blame] | 2788 | shsurf->type = SHELL_SURFACE_XWAYLAND; |
Kristian Høgsberg | 8bc525c | 2014-01-01 22:34:49 -0800 | [diff] [blame] | 2789 | shsurf->state_changed = true; |
Tiago Vignatti | fb2adba | 2013-06-12 15:43:21 -0300 | [diff] [blame] | 2790 | } |
| 2791 | |
Kristian Høgsberg | ae356ae | 2014-04-29 16:03:54 -0700 | [diff] [blame] | 2792 | static int |
| 2793 | shell_interface_move(struct shell_surface *shsurf, struct weston_seat *ws) |
| 2794 | { |
| 2795 | return surface_move(shsurf, ws, 1); |
| 2796 | } |
| 2797 | |
Kristian Høgsberg | 02bbabb | 2013-05-06 22:15:05 -0400 | [diff] [blame] | 2798 | static const struct weston_pointer_grab_interface popup_grab_interface; |
Giulio Camuffo | 5085a75 | 2013-03-25 21:42:45 +0100 | [diff] [blame] | 2799 | |
| 2800 | static void |
| 2801 | destroy_shell_seat(struct wl_listener *listener, void *data) |
| 2802 | { |
| 2803 | struct shell_seat *shseat = |
| 2804 | container_of(listener, |
| 2805 | struct shell_seat, seat_destroy_listener); |
| 2806 | struct shell_surface *shsurf, *prev = NULL; |
| 2807 | |
| 2808 | if (shseat->popup_grab.grab.interface == &popup_grab_interface) { |
Kristian Høgsberg | 02bbabb | 2013-05-06 22:15:05 -0400 | [diff] [blame] | 2809 | weston_pointer_end_grab(shseat->popup_grab.grab.pointer); |
Giulio Camuffo | 5085a75 | 2013-03-25 21:42:45 +0100 | [diff] [blame] | 2810 | shseat->popup_grab.client = NULL; |
| 2811 | |
| 2812 | wl_list_for_each(shsurf, &shseat->popup_grab.surfaces_list, popup.grab_link) { |
| 2813 | shsurf->popup.shseat = NULL; |
| 2814 | if (prev) { |
| 2815 | wl_list_init(&prev->popup.grab_link); |
| 2816 | } |
| 2817 | prev = shsurf; |
| 2818 | } |
| 2819 | wl_list_init(&prev->popup.grab_link); |
| 2820 | } |
| 2821 | |
| 2822 | wl_list_remove(&shseat->seat_destroy_listener.link); |
| 2823 | free(shseat); |
| 2824 | } |
| 2825 | |
Jason Ekstrand | 024177c | 2014-04-21 19:42:58 -0500 | [diff] [blame] | 2826 | static void |
| 2827 | shell_seat_caps_changed(struct wl_listener *listener, void *data) |
| 2828 | { |
| 2829 | struct shell_seat *seat; |
| 2830 | |
| 2831 | seat = container_of(listener, struct shell_seat, caps_changed_listener); |
| 2832 | |
| 2833 | if (seat->seat->keyboard && |
| 2834 | wl_list_empty(&seat->keyboard_focus_listener.link)) { |
| 2835 | wl_signal_add(&seat->seat->keyboard->focus_signal, |
| 2836 | &seat->keyboard_focus_listener); |
| 2837 | } else if (!seat->seat->keyboard) { |
| 2838 | wl_list_init(&seat->keyboard_focus_listener.link); |
| 2839 | } |
| 2840 | |
| 2841 | if (seat->seat->pointer && |
| 2842 | wl_list_empty(&seat->pointer_focus_listener.link)) { |
| 2843 | wl_signal_add(&seat->seat->pointer->focus_signal, |
| 2844 | &seat->pointer_focus_listener); |
| 2845 | } else if (!seat->seat->pointer) { |
| 2846 | wl_list_init(&seat->pointer_focus_listener.link); |
| 2847 | } |
| 2848 | } |
| 2849 | |
Giulio Camuffo | 5085a75 | 2013-03-25 21:42:45 +0100 | [diff] [blame] | 2850 | static struct shell_seat * |
| 2851 | create_shell_seat(struct weston_seat *seat) |
| 2852 | { |
| 2853 | struct shell_seat *shseat; |
| 2854 | |
| 2855 | shseat = calloc(1, sizeof *shseat); |
| 2856 | if (!shseat) { |
| 2857 | weston_log("no memory to allocate shell seat\n"); |
| 2858 | return NULL; |
| 2859 | } |
| 2860 | |
| 2861 | shseat->seat = seat; |
| 2862 | wl_list_init(&shseat->popup_grab.surfaces_list); |
| 2863 | |
| 2864 | shseat->seat_destroy_listener.notify = destroy_shell_seat; |
| 2865 | wl_signal_add(&seat->destroy_signal, |
| 2866 | &shseat->seat_destroy_listener); |
| 2867 | |
Jason Ekstrand | 024177c | 2014-04-21 19:42:58 -0500 | [diff] [blame] | 2868 | shseat->keyboard_focus_listener.notify = handle_keyboard_focus; |
| 2869 | wl_list_init(&shseat->keyboard_focus_listener.link); |
| 2870 | |
| 2871 | shseat->pointer_focus_listener.notify = handle_pointer_focus; |
| 2872 | wl_list_init(&shseat->pointer_focus_listener.link); |
| 2873 | |
| 2874 | shseat->caps_changed_listener.notify = shell_seat_caps_changed; |
| 2875 | wl_signal_add(&seat->updated_caps_signal, |
| 2876 | &shseat->caps_changed_listener); |
| 2877 | shell_seat_caps_changed(&shseat->caps_changed_listener, NULL); |
| 2878 | |
Giulio Camuffo | 5085a75 | 2013-03-25 21:42:45 +0100 | [diff] [blame] | 2879 | return shseat; |
| 2880 | } |
| 2881 | |
| 2882 | static struct shell_seat * |
| 2883 | get_shell_seat(struct weston_seat *seat) |
| 2884 | { |
| 2885 | struct wl_listener *listener; |
| 2886 | |
| 2887 | listener = wl_signal_get(&seat->destroy_signal, destroy_shell_seat); |
Jason Ekstrand | 024177c | 2014-04-21 19:42:58 -0500 | [diff] [blame] | 2888 | assert(listener != NULL); |
Giulio Camuffo | 5085a75 | 2013-03-25 21:42:45 +0100 | [diff] [blame] | 2889 | |
| 2890 | return container_of(listener, |
| 2891 | struct shell_seat, seat_destroy_listener); |
| 2892 | } |
| 2893 | |
Kristian Høgsberg | b810eb5 | 2013-02-12 20:07:05 -0500 | [diff] [blame] | 2894 | static void |
Kristian Høgsberg | 6848c25 | 2013-05-08 22:02:59 -0400 | [diff] [blame] | 2895 | popup_grab_focus(struct weston_pointer_grab *grab) |
Kristian Høgsberg | b3cca0a | 2012-01-04 22:19:14 -0500 | [diff] [blame] | 2896 | { |
Kristian Høgsberg | 02bbabb | 2013-05-06 22:15:05 -0400 | [diff] [blame] | 2897 | struct weston_pointer *pointer = grab->pointer; |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 2898 | struct weston_view *view; |
Giulio Camuffo | 5085a75 | 2013-03-25 21:42:45 +0100 | [diff] [blame] | 2899 | struct shell_seat *shseat = |
| 2900 | container_of(grab, struct shell_seat, popup_grab.grab); |
| 2901 | struct wl_client *client = shseat->popup_grab.client; |
Kristian Høgsberg | 6848c25 | 2013-05-08 22:02:59 -0400 | [diff] [blame] | 2902 | wl_fixed_t sx, sy; |
| 2903 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 2904 | view = weston_compositor_pick_view(pointer->seat->compositor, |
| 2905 | pointer->x, pointer->y, |
| 2906 | &sx, &sy); |
Kristian Høgsberg | b3cca0a | 2012-01-04 22:19:14 -0500 | [diff] [blame] | 2907 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 2908 | if (view && view->surface->resource && |
| 2909 | wl_resource_get_client(view->surface->resource) == client) { |
| 2910 | weston_pointer_set_focus(pointer, view, sx, sy); |
Kristian Høgsberg | b3cca0a | 2012-01-04 22:19:14 -0500 | [diff] [blame] | 2911 | } else { |
Kristian Høgsberg | 02bbabb | 2013-05-06 22:15:05 -0400 | [diff] [blame] | 2912 | weston_pointer_set_focus(pointer, NULL, |
| 2913 | wl_fixed_from_int(0), |
| 2914 | wl_fixed_from_int(0)); |
Kristian Høgsberg | b3cca0a | 2012-01-04 22:19:14 -0500 | [diff] [blame] | 2915 | } |
| 2916 | } |
| 2917 | |
| 2918 | static void |
Giulio Camuffo | 1959ab8 | 2013-11-14 23:42:52 +0100 | [diff] [blame] | 2919 | popup_grab_motion(struct weston_pointer_grab *grab, uint32_t time, |
| 2920 | wl_fixed_t x, wl_fixed_t y) |
Kristian Høgsberg | b3cca0a | 2012-01-04 22:19:14 -0500 | [diff] [blame] | 2921 | { |
Kristian Høgsberg | be6403e | 2013-05-08 21:03:21 -0400 | [diff] [blame] | 2922 | struct weston_pointer *pointer = grab->pointer; |
Neil Roberts | 96d790e | 2013-09-19 17:32:00 +0100 | [diff] [blame] | 2923 | struct wl_resource *resource; |
Kristian Høgsberg | be6403e | 2013-05-08 21:03:21 -0400 | [diff] [blame] | 2924 | wl_fixed_t sx, sy; |
Kristian Høgsberg | b3cca0a | 2012-01-04 22:19:14 -0500 | [diff] [blame] | 2925 | |
Giulio Camuffo | 1959ab8 | 2013-11-14 23:42:52 +0100 | [diff] [blame] | 2926 | weston_pointer_move(pointer, x, y); |
| 2927 | |
Neil Roberts | 96d790e | 2013-09-19 17:32:00 +0100 | [diff] [blame] | 2928 | wl_resource_for_each(resource, &pointer->focus_resource_list) { |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 2929 | weston_view_from_global_fixed(pointer->focus, |
| 2930 | pointer->x, pointer->y, |
| 2931 | &sx, &sy); |
Neil Roberts | 96d790e | 2013-09-19 17:32:00 +0100 | [diff] [blame] | 2932 | wl_pointer_send_motion(resource, time, sx, sy); |
Kristian Høgsberg | be6403e | 2013-05-08 21:03:21 -0400 | [diff] [blame] | 2933 | } |
Kristian Høgsberg | b3cca0a | 2012-01-04 22:19:14 -0500 | [diff] [blame] | 2934 | } |
| 2935 | |
| 2936 | static void |
Kristian Høgsberg | 02bbabb | 2013-05-06 22:15:05 -0400 | [diff] [blame] | 2937 | popup_grab_button(struct weston_pointer_grab *grab, |
Daniel Stone | 4dbadb1 | 2012-05-30 16:31:51 +0100 | [diff] [blame] | 2938 | uint32_t time, uint32_t button, uint32_t state_w) |
Kristian Høgsberg | b3cca0a | 2012-01-04 22:19:14 -0500 | [diff] [blame] | 2939 | { |
| 2940 | struct wl_resource *resource; |
Giulio Camuffo | 5085a75 | 2013-03-25 21:42:45 +0100 | [diff] [blame] | 2941 | struct shell_seat *shseat = |
| 2942 | container_of(grab, struct shell_seat, popup_grab.grab); |
Rob Bradford | 880ebc7 | 2013-07-22 17:31:38 +0100 | [diff] [blame] | 2943 | struct wl_display *display = shseat->seat->compositor->wl_display; |
Daniel Stone | 4dbadb1 | 2012-05-30 16:31:51 +0100 | [diff] [blame] | 2944 | enum wl_pointer_button_state state = state_w; |
Kristian Høgsberg | eae5de7 | 2012-04-11 22:42:15 -0400 | [diff] [blame] | 2945 | uint32_t serial; |
Neil Roberts | 96d790e | 2013-09-19 17:32:00 +0100 | [diff] [blame] | 2946 | struct wl_list *resource_list; |
Kristian Høgsberg | b3cca0a | 2012-01-04 22:19:14 -0500 | [diff] [blame] | 2947 | |
Neil Roberts | 96d790e | 2013-09-19 17:32:00 +0100 | [diff] [blame] | 2948 | resource_list = &grab->pointer->focus_resource_list; |
| 2949 | if (!wl_list_empty(resource_list)) { |
Kristian Høgsberg | eae5de7 | 2012-04-11 22:42:15 -0400 | [diff] [blame] | 2950 | serial = wl_display_get_serial(display); |
Neil Roberts | 96d790e | 2013-09-19 17:32:00 +0100 | [diff] [blame] | 2951 | wl_resource_for_each(resource, resource_list) { |
| 2952 | wl_pointer_send_button(resource, serial, |
| 2953 | time, button, state); |
| 2954 | } |
Daniel Stone | 4dbadb1 | 2012-05-30 16:31:51 +0100 | [diff] [blame] | 2955 | } else if (state == WL_POINTER_BUTTON_STATE_RELEASED && |
Giulio Camuffo | 5085a75 | 2013-03-25 21:42:45 +0100 | [diff] [blame] | 2956 | (shseat->popup_grab.initial_up || |
Kristian Høgsberg | e314875 | 2013-05-06 23:19:49 -0400 | [diff] [blame] | 2957 | time - shseat->seat->pointer->grab_time > 500)) { |
Kristian Høgsberg | 57e0907 | 2012-10-30 14:07:27 -0400 | [diff] [blame] | 2958 | popup_grab_end(grab->pointer); |
Kristian Høgsberg | b3cca0a | 2012-01-04 22:19:14 -0500 | [diff] [blame] | 2959 | } |
| 2960 | |
Daniel Stone | 4dbadb1 | 2012-05-30 16:31:51 +0100 | [diff] [blame] | 2961 | if (state == WL_POINTER_BUTTON_STATE_RELEASED) |
Giulio Camuffo | 5085a75 | 2013-03-25 21:42:45 +0100 | [diff] [blame] | 2962 | shseat->popup_grab.initial_up = 1; |
Kristian Høgsberg | b3cca0a | 2012-01-04 22:19:14 -0500 | [diff] [blame] | 2963 | } |
| 2964 | |
Jonas Ådahl | 1ea343e | 2013-10-25 23:18:05 +0200 | [diff] [blame] | 2965 | static void |
| 2966 | popup_grab_cancel(struct weston_pointer_grab *grab) |
| 2967 | { |
| 2968 | popup_grab_end(grab->pointer); |
| 2969 | } |
| 2970 | |
Kristian Høgsberg | 02bbabb | 2013-05-06 22:15:05 -0400 | [diff] [blame] | 2971 | static const struct weston_pointer_grab_interface popup_grab_interface = { |
Kristian Høgsberg | b3cca0a | 2012-01-04 22:19:14 -0500 | [diff] [blame] | 2972 | popup_grab_focus, |
| 2973 | popup_grab_motion, |
| 2974 | popup_grab_button, |
Jonas Ådahl | 1ea343e | 2013-10-25 23:18:05 +0200 | [diff] [blame] | 2975 | popup_grab_cancel, |
Kristian Høgsberg | b3cca0a | 2012-01-04 22:19:14 -0500 | [diff] [blame] | 2976 | }; |
| 2977 | |
| 2978 | static void |
Rafael Antognolli | e2a3455 | 2013-12-03 15:35:45 -0200 | [diff] [blame] | 2979 | shell_surface_send_popup_done(struct shell_surface *shsurf) |
| 2980 | { |
| 2981 | if (shell_surface_is_wl_shell_surface(shsurf)) |
| 2982 | wl_shell_surface_send_popup_done(shsurf->resource); |
| 2983 | else if (shell_surface_is_xdg_popup(shsurf)) |
| 2984 | xdg_popup_send_popup_done(shsurf->resource, |
| 2985 | shsurf->popup.serial); |
| 2986 | } |
| 2987 | |
| 2988 | static void |
Kristian Høgsberg | 02bbabb | 2013-05-06 22:15:05 -0400 | [diff] [blame] | 2989 | popup_grab_end(struct weston_pointer *pointer) |
Kristian Høgsberg | 57e0907 | 2012-10-30 14:07:27 -0400 | [diff] [blame] | 2990 | { |
Kristian Høgsberg | 02bbabb | 2013-05-06 22:15:05 -0400 | [diff] [blame] | 2991 | struct weston_pointer_grab *grab = pointer->grab; |
Giulio Camuffo | 5085a75 | 2013-03-25 21:42:45 +0100 | [diff] [blame] | 2992 | struct shell_seat *shseat = |
| 2993 | container_of(grab, struct shell_seat, popup_grab.grab); |
| 2994 | struct shell_surface *shsurf; |
| 2995 | struct shell_surface *prev = NULL; |
Kristian Høgsberg | 57e0907 | 2012-10-30 14:07:27 -0400 | [diff] [blame] | 2996 | |
| 2997 | if (pointer->grab->interface == &popup_grab_interface) { |
Kristian Høgsberg | 02bbabb | 2013-05-06 22:15:05 -0400 | [diff] [blame] | 2998 | weston_pointer_end_grab(grab->pointer); |
Giulio Camuffo | 5085a75 | 2013-03-25 21:42:45 +0100 | [diff] [blame] | 2999 | shseat->popup_grab.client = NULL; |
Philipp Brüschweiler | 63e7be6 | 2013-04-15 21:09:54 +0200 | [diff] [blame] | 3000 | shseat->popup_grab.grab.interface = NULL; |
| 3001 | assert(!wl_list_empty(&shseat->popup_grab.surfaces_list)); |
Giulio Camuffo | 5085a75 | 2013-03-25 21:42:45 +0100 | [diff] [blame] | 3002 | /* Send the popup_done event to all the popups open */ |
| 3003 | 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] | 3004 | shell_surface_send_popup_done(shsurf); |
Giulio Camuffo | 5085a75 | 2013-03-25 21:42:45 +0100 | [diff] [blame] | 3005 | shsurf->popup.shseat = NULL; |
| 3006 | if (prev) { |
| 3007 | wl_list_init(&prev->popup.grab_link); |
| 3008 | } |
| 3009 | prev = shsurf; |
| 3010 | } |
| 3011 | wl_list_init(&prev->popup.grab_link); |
| 3012 | wl_list_init(&shseat->popup_grab.surfaces_list); |
| 3013 | } |
| 3014 | } |
| 3015 | |
| 3016 | static void |
| 3017 | add_popup_grab(struct shell_surface *shsurf, struct shell_seat *shseat) |
| 3018 | { |
Kristian Høgsberg | e314875 | 2013-05-06 23:19:49 -0400 | [diff] [blame] | 3019 | struct weston_seat *seat = shseat->seat; |
Giulio Camuffo | 5085a75 | 2013-03-25 21:42:45 +0100 | [diff] [blame] | 3020 | |
| 3021 | if (wl_list_empty(&shseat->popup_grab.surfaces_list)) { |
Jason Ekstrand | 651f00e | 2013-06-14 10:07:54 -0500 | [diff] [blame] | 3022 | shseat->popup_grab.client = wl_resource_get_client(shsurf->resource); |
Giulio Camuffo | 5085a75 | 2013-03-25 21:42:45 +0100 | [diff] [blame] | 3023 | shseat->popup_grab.grab.interface = &popup_grab_interface; |
Giulio Camuffo | 1b4b61a | 2013-03-27 18:05:26 +0100 | [diff] [blame] | 3024 | /* We must make sure here that this popup was opened after |
| 3025 | * a mouse press, and not just by moving around with other |
| 3026 | * popups already open. */ |
Kristian Høgsberg | e314875 | 2013-05-06 23:19:49 -0400 | [diff] [blame] | 3027 | if (shseat->seat->pointer->button_count > 0) |
Giulio Camuffo | 1b4b61a | 2013-03-27 18:05:26 +0100 | [diff] [blame] | 3028 | shseat->popup_grab.initial_up = 0; |
Giulio Camuffo | 5085a75 | 2013-03-25 21:42:45 +0100 | [diff] [blame] | 3029 | |
Rob Bradford | dfe3105 | 2013-06-26 19:49:11 +0100 | [diff] [blame] | 3030 | wl_list_insert(&shseat->popup_grab.surfaces_list, &shsurf->popup.grab_link); |
Kristian Høgsberg | 02bbabb | 2013-05-06 22:15:05 -0400 | [diff] [blame] | 3031 | weston_pointer_start_grab(seat->pointer, &shseat->popup_grab.grab); |
Rob Bradford | dfe3105 | 2013-06-26 19:49:11 +0100 | [diff] [blame] | 3032 | } else { |
| 3033 | wl_list_insert(&shseat->popup_grab.surfaces_list, &shsurf->popup.grab_link); |
Giulio Camuffo | 5085a75 | 2013-03-25 21:42:45 +0100 | [diff] [blame] | 3034 | } |
Giulio Camuffo | 5085a75 | 2013-03-25 21:42:45 +0100 | [diff] [blame] | 3035 | } |
| 3036 | |
| 3037 | static void |
| 3038 | remove_popup_grab(struct shell_surface *shsurf) |
| 3039 | { |
| 3040 | struct shell_seat *shseat = shsurf->popup.shseat; |
| 3041 | |
| 3042 | wl_list_remove(&shsurf->popup.grab_link); |
| 3043 | wl_list_init(&shsurf->popup.grab_link); |
| 3044 | if (wl_list_empty(&shseat->popup_grab.surfaces_list)) { |
Kristian Høgsberg | 02bbabb | 2013-05-06 22:15:05 -0400 | [diff] [blame] | 3045 | weston_pointer_end_grab(shseat->popup_grab.grab.pointer); |
Philipp Brüschweiler | 63e7be6 | 2013-04-15 21:09:54 +0200 | [diff] [blame] | 3046 | shseat->popup_grab.grab.interface = NULL; |
Kristian Høgsberg | 57e0907 | 2012-10-30 14:07:27 -0400 | [diff] [blame] | 3047 | } |
| 3048 | } |
| 3049 | |
| 3050 | static void |
Kristian Høgsberg | 3730f36 | 2012-04-13 12:40:07 -0400 | [diff] [blame] | 3051 | shell_map_popup(struct shell_surface *shsurf) |
Kristian Høgsberg | b3cca0a | 2012-01-04 22:19:14 -0500 | [diff] [blame] | 3052 | { |
Giulio Camuffo | 5085a75 | 2013-03-25 21:42:45 +0100 | [diff] [blame] | 3053 | struct shell_seat *shseat = shsurf->popup.shseat; |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 3054 | struct weston_view *parent_view = get_default_view(shsurf->parent); |
Kristian Høgsberg | b3cca0a | 2012-01-04 22:19:14 -0500 | [diff] [blame] | 3055 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 3056 | shsurf->surface->output = parent_view->output; |
| 3057 | shsurf->view->output = parent_view->output; |
Kristian Høgsberg | b3cca0a | 2012-01-04 22:19:14 -0500 | [diff] [blame] | 3058 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 3059 | weston_view_set_transform_parent(shsurf->view, parent_view); |
| 3060 | weston_view_set_position(shsurf->view, shsurf->popup.x, shsurf->popup.y); |
| 3061 | weston_view_update_transform(shsurf->view); |
Kristian Høgsberg | b3cca0a | 2012-01-04 22:19:14 -0500 | [diff] [blame] | 3062 | |
Kristian Høgsberg | e314875 | 2013-05-06 23:19:49 -0400 | [diff] [blame] | 3063 | if (shseat->seat->pointer->grab_serial == shsurf->popup.serial) { |
Giulio Camuffo | 5085a75 | 2013-03-25 21:42:45 +0100 | [diff] [blame] | 3064 | add_popup_grab(shsurf, shseat); |
Kristian Høgsberg | 3730f36 | 2012-04-13 12:40:07 -0400 | [diff] [blame] | 3065 | } else { |
Rafael Antognolli | e2a3455 | 2013-12-03 15:35:45 -0200 | [diff] [blame] | 3066 | shell_surface_send_popup_done(shsurf); |
Giulio Camuffo | 5085a75 | 2013-03-25 21:42:45 +0100 | [diff] [blame] | 3067 | shseat->popup_grab.client = NULL; |
Kristian Høgsberg | 3730f36 | 2012-04-13 12:40:07 -0400 | [diff] [blame] | 3068 | } |
Kristian Høgsberg | b3cca0a | 2012-01-04 22:19:14 -0500 | [diff] [blame] | 3069 | } |
| 3070 | |
Pekka Paalanen | 9d1613e | 2011-11-25 12:09:16 +0200 | [diff] [blame] | 3071 | static const struct wl_shell_surface_interface shell_surface_implementation = { |
Scott Moreau | ff1db4a | 2012-04-17 19:06:18 -0600 | [diff] [blame] | 3072 | shell_surface_pong, |
Pekka Paalanen | 9d1613e | 2011-11-25 12:09:16 +0200 | [diff] [blame] | 3073 | shell_surface_move, |
| 3074 | shell_surface_resize, |
| 3075 | shell_surface_set_toplevel, |
| 3076 | shell_surface_set_transient, |
Kristian Høgsberg | b3cca0a | 2012-01-04 22:19:14 -0500 | [diff] [blame] | 3077 | shell_surface_set_fullscreen, |
Juan Zhao | 96879df | 2012-02-07 08:45:41 +0800 | [diff] [blame] | 3078 | shell_surface_set_popup, |
Kristian Høgsberg | e7afd91 | 2012-05-02 09:47:44 -0400 | [diff] [blame] | 3079 | shell_surface_set_maximized, |
| 3080 | shell_surface_set_title, |
| 3081 | shell_surface_set_class |
Pekka Paalanen | 9d1613e | 2011-11-25 12:09:16 +0200 | [diff] [blame] | 3082 | }; |
| 3083 | |
| 3084 | static void |
Tiago Vignatti | bc052c9 | 2012-04-19 16:18:18 +0300 | [diff] [blame] | 3085 | destroy_shell_surface(struct shell_surface *shsurf) |
Pekka Paalanen | 9d1613e | 2011-11-25 12:09:16 +0200 | [diff] [blame] | 3086 | { |
Kristian Høgsberg | 9046d24 | 2014-01-10 00:25:30 -0800 | [diff] [blame] | 3087 | struct shell_surface *child, *next; |
| 3088 | |
Jason Ekstrand | 651f00e | 2013-06-14 10:07:54 -0500 | [diff] [blame] | 3089 | wl_signal_emit(&shsurf->destroy_signal, shsurf); |
| 3090 | |
Giulio Camuffo | 5085a75 | 2013-03-25 21:42:45 +0100 | [diff] [blame] | 3091 | if (!wl_list_empty(&shsurf->popup.grab_link)) { |
| 3092 | remove_popup_grab(shsurf); |
| 3093 | } |
Kristian Høgsberg | b3cca0a | 2012-01-04 22:19:14 -0500 | [diff] [blame] | 3094 | |
Alex Wu | bd3354b | 2012-04-17 17:20:49 +0800 | [diff] [blame] | 3095 | if (shsurf->fullscreen.type == WL_SHELL_SURFACE_FULLSCREEN_METHOD_DRIVER && |
Alexander Larsson | f82b6ca | 2013-05-28 16:23:39 +0200 | [diff] [blame] | 3096 | shell_surface_is_top_fullscreen(shsurf)) |
| 3097 | restore_output_mode (shsurf->fullscreen_output); |
Pekka Paalanen | 9d1613e | 2011-11-25 12:09:16 +0200 | [diff] [blame] | 3098 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 3099 | if (shsurf->fullscreen.black_view) |
| 3100 | weston_surface_destroy(shsurf->fullscreen.black_view->surface); |
Alex Wu | aa08e2d | 2012-03-05 11:01:40 +0800 | [diff] [blame] | 3101 | |
Alex Wu | bd3354b | 2012-04-17 17:20:49 +0800 | [diff] [blame] | 3102 | /* As destroy_resource() use wl_list_for_each_safe(), |
| 3103 | * we can always remove the listener. |
| 3104 | */ |
| 3105 | wl_list_remove(&shsurf->surface_destroy_listener.link); |
| 3106 | shsurf->surface->configure = NULL; |
Scott Moreau | 976a050 | 2013-03-07 10:15:17 -0700 | [diff] [blame] | 3107 | free(shsurf->title); |
Alex Wu | bd3354b | 2012-04-17 17:20:49 +0800 | [diff] [blame] | 3108 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 3109 | weston_view_destroy(shsurf->view); |
| 3110 | |
Philip Withnall | 648a4dd | 2013-11-25 18:01:44 +0000 | [diff] [blame] | 3111 | wl_list_remove(&shsurf->children_link); |
Emilio Pozuelo Monfort | adaa20c | 2014-01-28 13:54:16 +0100 | [diff] [blame] | 3112 | wl_list_for_each_safe(child, next, &shsurf->children_list, children_link) |
| 3113 | shell_surface_set_parent(child, NULL); |
Philip Withnall | 648a4dd | 2013-11-25 18:01:44 +0000 | [diff] [blame] | 3114 | |
Pekka Paalanen | 9d1613e | 2011-11-25 12:09:16 +0200 | [diff] [blame] | 3115 | wl_list_remove(&shsurf->link); |
| 3116 | free(shsurf); |
| 3117 | } |
| 3118 | |
| 3119 | static void |
Tiago Vignatti | bc052c9 | 2012-04-19 16:18:18 +0300 | [diff] [blame] | 3120 | shell_destroy_shell_surface(struct wl_resource *resource) |
| 3121 | { |
Jason Ekstrand | 651f00e | 2013-06-14 10:07:54 -0500 | [diff] [blame] | 3122 | struct shell_surface *shsurf = wl_resource_get_user_data(resource); |
Tiago Vignatti | bc052c9 | 2012-04-19 16:18:18 +0300 | [diff] [blame] | 3123 | |
Bryan Cain | a46b946 | 2014-04-04 17:41:24 -0500 | [diff] [blame] | 3124 | if (!wl_list_empty(&shsurf->popup.grab_link)) |
| 3125 | remove_popup_grab(shsurf); |
Kristian Høgsberg | 160fe75 | 2014-03-11 10:19:10 -0700 | [diff] [blame] | 3126 | shsurf->resource = NULL; |
Tiago Vignatti | bc052c9 | 2012-04-19 16:18:18 +0300 | [diff] [blame] | 3127 | } |
| 3128 | |
| 3129 | static void |
Kristian Høgsberg | 27e3052 | 2012-04-11 23:18:23 -0400 | [diff] [blame] | 3130 | shell_handle_surface_destroy(struct wl_listener *listener, void *data) |
Pekka Paalanen | 9d1613e | 2011-11-25 12:09:16 +0200 | [diff] [blame] | 3131 | { |
| 3132 | struct shell_surface *shsurf = container_of(listener, |
| 3133 | struct shell_surface, |
| 3134 | surface_destroy_listener); |
| 3135 | |
Jason Ekstrand | 651f00e | 2013-06-14 10:07:54 -0500 | [diff] [blame] | 3136 | if (shsurf->resource) |
| 3137 | wl_resource_destroy(shsurf->resource); |
Ander Conselvan de Oliveira | 15f9a26 | 2014-04-29 17:54:02 +0300 | [diff] [blame] | 3138 | |
| 3139 | destroy_shell_surface(shsurf); |
Pekka Paalanen | 9d1613e | 2011-11-25 12:09:16 +0200 | [diff] [blame] | 3140 | } |
| 3141 | |
Kristian Høgsberg | d813445 | 2012-06-21 12:49:02 -0400 | [diff] [blame] | 3142 | static void |
Kristian Høgsberg | 160fe75 | 2014-03-11 10:19:10 -0700 | [diff] [blame] | 3143 | fade_out_done(struct weston_view_animation *animation, void *data) |
| 3144 | { |
| 3145 | struct shell_surface *shsurf = data; |
| 3146 | |
| 3147 | weston_surface_destroy(shsurf->surface); |
| 3148 | } |
| 3149 | |
| 3150 | static void |
| 3151 | handle_resource_destroy(struct wl_listener *listener, void *data) |
| 3152 | { |
| 3153 | struct shell_surface *shsurf = |
| 3154 | container_of(listener, struct shell_surface, |
| 3155 | resource_destroy_listener); |
| 3156 | |
Ander Conselvan de Oliveira | 15f9a26 | 2014-04-29 17:54:02 +0300 | [diff] [blame] | 3157 | if (!weston_surface_is_mapped(shsurf->surface)) |
| 3158 | return; |
| 3159 | |
Kristian Høgsberg | 160fe75 | 2014-03-11 10:19:10 -0700 | [diff] [blame] | 3160 | shsurf->surface->ref_count++; |
| 3161 | |
| 3162 | pixman_region32_fini(&shsurf->surface->pending.input); |
| 3163 | pixman_region32_init(&shsurf->surface->pending.input); |
| 3164 | pixman_region32_fini(&shsurf->surface->input); |
| 3165 | pixman_region32_init(&shsurf->surface->input); |
Ander Conselvan de Oliveira | 15f9a26 | 2014-04-29 17:54:02 +0300 | [diff] [blame] | 3166 | weston_fade_run(shsurf->view, 1.0, 0.0, 300.0, |
| 3167 | fade_out_done, shsurf); |
Kristian Høgsberg | 160fe75 | 2014-03-11 10:19:10 -0700 | [diff] [blame] | 3168 | } |
| 3169 | |
| 3170 | static void |
Jason Ekstrand | 918f2dd | 2013-12-02 21:01:53 -0600 | [diff] [blame] | 3171 | shell_surface_configure(struct weston_surface *, int32_t, int32_t); |
Kristian Høgsberg | d813445 | 2012-06-21 12:49:02 -0400 | [diff] [blame] | 3172 | |
Kristian Høgsberg | 1ef2313 | 2013-12-04 00:20:01 -0800 | [diff] [blame] | 3173 | struct shell_surface * |
Kristian Høgsberg | 8334bc1 | 2012-01-03 10:29:47 -0500 | [diff] [blame] | 3174 | get_shell_surface(struct weston_surface *surface) |
Pekka Paalanen | ec2b32f | 2011-11-28 15:12:34 +0200 | [diff] [blame] | 3175 | { |
Kristian Høgsberg | d813445 | 2012-06-21 12:49:02 -0400 | [diff] [blame] | 3176 | if (surface->configure == shell_surface_configure) |
Giulio Camuffo | 7fe01b1 | 2013-03-28 18:02:42 +0100 | [diff] [blame] | 3177 | return surface->configure_private; |
Kristian Høgsberg | d813445 | 2012-06-21 12:49:02 -0400 | [diff] [blame] | 3178 | else |
| 3179 | return NULL; |
Pekka Paalanen | ec2b32f | 2011-11-28 15:12:34 +0200 | [diff] [blame] | 3180 | } |
| 3181 | |
Rafael Antognolli | e2a3455 | 2013-12-03 15:35:45 -0200 | [diff] [blame] | 3182 | static struct shell_surface * |
Jason Ekstrand | 9e9512f | 2014-04-16 21:12:10 -0500 | [diff] [blame] | 3183 | create_common_surface(struct shell_client *owner, void *shell, |
| 3184 | struct weston_surface *surface, |
Rafael Antognolli | e2a3455 | 2013-12-03 15:35:45 -0200 | [diff] [blame] | 3185 | const struct weston_shell_client *client) |
Pekka Paalanen | 9d1613e | 2011-11-25 12:09:16 +0200 | [diff] [blame] | 3186 | { |
Pekka Paalanen | 9d1613e | 2011-11-25 12:09:16 +0200 | [diff] [blame] | 3187 | struct shell_surface *shsurf; |
| 3188 | |
Ander Conselvan de Oliveira | 093bfa3 | 2012-03-27 17:36:41 +0300 | [diff] [blame] | 3189 | if (surface->configure) { |
Martin Minarik | 6d11836 | 2012-06-07 18:01:59 +0200 | [diff] [blame] | 3190 | weston_log("surface->configure already set\n"); |
Kristian Høgsberg | 45ba869 | 2012-05-21 14:27:33 -0400 | [diff] [blame] | 3191 | return NULL; |
Ander Conselvan de Oliveira | 093bfa3 | 2012-03-27 17:36:41 +0300 | [diff] [blame] | 3192 | } |
| 3193 | |
Pekka Paalanen | 9d1613e | 2011-11-25 12:09:16 +0200 | [diff] [blame] | 3194 | shsurf = calloc(1, sizeof *shsurf); |
| 3195 | if (!shsurf) { |
Martin Minarik | 6d11836 | 2012-06-07 18:01:59 +0200 | [diff] [blame] | 3196 | weston_log("no memory to allocate shell surface\n"); |
Kristian Høgsberg | 45ba869 | 2012-05-21 14:27:33 -0400 | [diff] [blame] | 3197 | return NULL; |
Pekka Paalanen | 9d1613e | 2011-11-25 12:09:16 +0200 | [diff] [blame] | 3198 | } |
| 3199 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 3200 | shsurf->view = weston_view_create(surface); |
| 3201 | if (!shsurf->view) { |
| 3202 | weston_log("no memory to allocate shell surface\n"); |
| 3203 | free(shsurf); |
| 3204 | return NULL; |
| 3205 | } |
| 3206 | |
Ander Conselvan de Oliveira | 093bfa3 | 2012-03-27 17:36:41 +0300 | [diff] [blame] | 3207 | surface->configure = shell_surface_configure; |
Giulio Camuffo | 7fe01b1 | 2013-03-28 18:02:42 +0100 | [diff] [blame] | 3208 | surface->configure_private = shsurf; |
Ander Conselvan de Oliveira | 093bfa3 | 2012-03-27 17:36:41 +0300 | [diff] [blame] | 3209 | |
Kristian Høgsberg | 160fe75 | 2014-03-11 10:19:10 -0700 | [diff] [blame] | 3210 | shsurf->resource_destroy_listener.notify = handle_resource_destroy; |
| 3211 | wl_resource_add_destroy_listener(surface->resource, |
| 3212 | &shsurf->resource_destroy_listener); |
Jason Ekstrand | 9e9512f | 2014-04-16 21:12:10 -0500 | [diff] [blame] | 3213 | shsurf->owner = owner; |
Kristian Høgsberg | 160fe75 | 2014-03-11 10:19:10 -0700 | [diff] [blame] | 3214 | |
Tiago Vignatti | bc052c9 | 2012-04-19 16:18:18 +0300 | [diff] [blame] | 3215 | shsurf->shell = (struct desktop_shell *) shell; |
Scott Moreau | ff1db4a | 2012-04-17 19:06:18 -0600 | [diff] [blame] | 3216 | shsurf->unresponsive = 0; |
Alex Wu | 4539b08 | 2012-03-01 12:57:46 +0800 | [diff] [blame] | 3217 | shsurf->saved_position_valid = false; |
Rafael Antognolli | 3c4e3f7 | 2013-12-03 15:35:46 -0200 | [diff] [blame] | 3218 | shsurf->saved_size_valid = false; |
Alex Wu | 7bcb8bd | 2012-04-27 09:07:24 +0800 | [diff] [blame] | 3219 | shsurf->saved_rotation_valid = false; |
Pekka Paalanen | 9d1613e | 2011-11-25 12:09:16 +0200 | [diff] [blame] | 3220 | shsurf->surface = surface; |
Alex Wu | 4539b08 | 2012-03-01 12:57:46 +0800 | [diff] [blame] | 3221 | shsurf->fullscreen.type = WL_SHELL_SURFACE_FULLSCREEN_METHOD_DEFAULT; |
| 3222 | shsurf->fullscreen.framerate = 0; |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 3223 | shsurf->fullscreen.black_view = NULL; |
Alex Wu | 4539b08 | 2012-03-01 12:57:46 +0800 | [diff] [blame] | 3224 | wl_list_init(&shsurf->fullscreen.transform.link); |
| 3225 | |
Jason Ekstrand | 651f00e | 2013-06-14 10:07:54 -0500 | [diff] [blame] | 3226 | wl_signal_init(&shsurf->destroy_signal); |
Kristian Høgsberg | 27e3052 | 2012-04-11 23:18:23 -0400 | [diff] [blame] | 3227 | shsurf->surface_destroy_listener.notify = shell_handle_surface_destroy; |
Jason Ekstrand | 26ed73c | 2013-06-06 22:34:41 -0500 | [diff] [blame] | 3228 | wl_signal_add(&surface->destroy_signal, |
Kristian Høgsberg | 27e3052 | 2012-04-11 23:18:23 -0400 | [diff] [blame] | 3229 | &shsurf->surface_destroy_listener); |
Pekka Paalanen | 9d1613e | 2011-11-25 12:09:16 +0200 | [diff] [blame] | 3230 | |
| 3231 | /* init link so its safe to always remove it in destroy_shell_surface */ |
| 3232 | wl_list_init(&shsurf->link); |
Giulio Camuffo | 5085a75 | 2013-03-25 21:42:45 +0100 | [diff] [blame] | 3233 | wl_list_init(&shsurf->popup.grab_link); |
Pekka Paalanen | 9d1613e | 2011-11-25 12:09:16 +0200 | [diff] [blame] | 3234 | |
Pekka Paalanen | 460099f | 2012-01-20 16:48:25 +0200 | [diff] [blame] | 3235 | /* empty when not in use */ |
| 3236 | wl_list_init(&shsurf->rotation.transform.link); |
Kristian Høgsberg | 765e27b | 2012-01-27 13:36:13 -0500 | [diff] [blame] | 3237 | weston_matrix_init(&shsurf->rotation.rotation); |
Pekka Paalanen | 460099f | 2012-01-20 16:48:25 +0200 | [diff] [blame] | 3238 | |
Jonas Ådahl | 62fcd04 | 2012-06-13 00:01:23 +0200 | [diff] [blame] | 3239 | wl_list_init(&shsurf->workspace_transform.link); |
| 3240 | |
Philip Withnall | 648a4dd | 2013-11-25 18:01:44 +0000 | [diff] [blame] | 3241 | wl_list_init(&shsurf->children_link); |
| 3242 | wl_list_init(&shsurf->children_list); |
| 3243 | shsurf->parent = NULL; |
| 3244 | |
Pekka Paalanen | 9826223 | 2011-12-01 10:42:22 +0200 | [diff] [blame] | 3245 | shsurf->type = SHELL_SURFACE_NONE; |
Pekka Paalanen | 9d1613e | 2011-11-25 12:09:16 +0200 | [diff] [blame] | 3246 | |
Kristian Høgsberg | a61ca06 | 2012-05-22 16:05:52 -0400 | [diff] [blame] | 3247 | shsurf->client = client; |
| 3248 | |
Kristian Høgsberg | 45ba869 | 2012-05-21 14:27:33 -0400 | [diff] [blame] | 3249 | return shsurf; |
Tiago Vignatti | bc052c9 | 2012-04-19 16:18:18 +0300 | [diff] [blame] | 3250 | } |
| 3251 | |
Rafael Antognolli | e2a3455 | 2013-12-03 15:35:45 -0200 | [diff] [blame] | 3252 | static struct shell_surface * |
| 3253 | create_shell_surface(void *shell, struct weston_surface *surface, |
| 3254 | const struct weston_shell_client *client) |
| 3255 | { |
Jason Ekstrand | 9e9512f | 2014-04-16 21:12:10 -0500 | [diff] [blame] | 3256 | return create_common_surface(NULL, shell, surface, client); |
Rafael Antognolli | e2a3455 | 2013-12-03 15:35:45 -0200 | [diff] [blame] | 3257 | } |
| 3258 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 3259 | static struct weston_view * |
| 3260 | get_primary_view(void *shell, struct shell_surface *shsurf) |
| 3261 | { |
| 3262 | return shsurf->view; |
| 3263 | } |
| 3264 | |
Tiago Vignatti | bc052c9 | 2012-04-19 16:18:18 +0300 | [diff] [blame] | 3265 | static void |
| 3266 | shell_get_shell_surface(struct wl_client *client, |
| 3267 | struct wl_resource *resource, |
| 3268 | uint32_t id, |
| 3269 | struct wl_resource *surface_resource) |
| 3270 | { |
Jason Ekstrand | 0f2ef7e | 2013-06-14 10:07:53 -0500 | [diff] [blame] | 3271 | struct weston_surface *surface = |
| 3272 | wl_resource_get_user_data(surface_resource); |
Jason Ekstrand | 9e9512f | 2014-04-16 21:12:10 -0500 | [diff] [blame] | 3273 | struct shell_client *sc = wl_resource_get_user_data(resource); |
| 3274 | struct desktop_shell *shell = sc->shell; |
Tiago Vignatti | bc052c9 | 2012-04-19 16:18:18 +0300 | [diff] [blame] | 3275 | struct shell_surface *shsurf; |
| 3276 | |
| 3277 | if (get_shell_surface(surface)) { |
| 3278 | wl_resource_post_error(surface_resource, |
Kristian Høgsberg | 9540ea6 | 2012-05-21 14:28:57 -0400 | [diff] [blame] | 3279 | WL_DISPLAY_ERROR_INVALID_OBJECT, |
| 3280 | "desktop_shell::get_shell_surface already requested"); |
Tiago Vignatti | bc052c9 | 2012-04-19 16:18:18 +0300 | [diff] [blame] | 3281 | return; |
| 3282 | } |
| 3283 | |
Jason Ekstrand | 9e9512f | 2014-04-16 21:12:10 -0500 | [diff] [blame] | 3284 | shsurf = create_common_surface(sc, shell, surface, &shell_client); |
Kristian Høgsberg | 9540ea6 | 2012-05-21 14:28:57 -0400 | [diff] [blame] | 3285 | if (!shsurf) { |
| 3286 | wl_resource_post_error(surface_resource, |
| 3287 | WL_DISPLAY_ERROR_INVALID_OBJECT, |
| 3288 | "surface->configure already set"); |
| 3289 | return; |
| 3290 | } |
Tiago Vignatti | bc052c9 | 2012-04-19 16:18:18 +0300 | [diff] [blame] | 3291 | |
Jason Ekstrand | a85118c | 2013-06-27 20:17:02 -0500 | [diff] [blame] | 3292 | shsurf->resource = |
| 3293 | wl_resource_create(client, |
| 3294 | &wl_shell_surface_interface, 1, id); |
| 3295 | wl_resource_set_implementation(shsurf->resource, |
| 3296 | &shell_surface_implementation, |
| 3297 | shsurf, shell_destroy_shell_surface); |
Pekka Paalanen | 9d1613e | 2011-11-25 12:09:16 +0200 | [diff] [blame] | 3298 | } |
| 3299 | |
Rafael Antognolli | e2a3455 | 2013-12-03 15:35:45 -0200 | [diff] [blame] | 3300 | static bool |
| 3301 | shell_surface_is_wl_shell_surface(struct shell_surface *shsurf) |
| 3302 | { |
Kristian Høgsberg | 0b7d995 | 2014-02-03 15:50:38 -0800 | [diff] [blame] | 3303 | /* A shell surface without a resource is created from xwayland |
| 3304 | * and is considered a wl_shell surface for now. */ |
| 3305 | |
| 3306 | return shsurf->resource == NULL || |
| 3307 | wl_resource_instance_of(shsurf->resource, |
| 3308 | &wl_shell_surface_interface, |
| 3309 | &shell_surface_implementation); |
Rafael Antognolli | e2a3455 | 2013-12-03 15:35:45 -0200 | [diff] [blame] | 3310 | } |
| 3311 | |
Pekka Paalanen | 9d1613e | 2011-11-25 12:09:16 +0200 | [diff] [blame] | 3312 | static const struct wl_shell_interface shell_implementation = { |
Pekka Paalanen | 4622967 | 2011-11-29 15:49:31 +0200 | [diff] [blame] | 3313 | shell_get_shell_surface |
Kristian Høgsberg | 4cca349 | 2011-01-18 07:53:49 -0500 | [diff] [blame] | 3314 | }; |
| 3315 | |
Rafael Antognolli | e2a3455 | 2013-12-03 15:35:45 -0200 | [diff] [blame] | 3316 | /**************************** |
| 3317 | * xdg-shell implementation */ |
| 3318 | |
| 3319 | static void |
| 3320 | xdg_surface_destroy(struct wl_client *client, |
| 3321 | struct wl_resource *resource) |
| 3322 | { |
| 3323 | wl_resource_destroy(resource); |
| 3324 | } |
| 3325 | |
| 3326 | static void |
Jasper St. Pierre | 63a9c33 | 2014-02-01 18:35:15 -0500 | [diff] [blame] | 3327 | xdg_surface_set_transient_for(struct wl_client *client, |
| 3328 | struct wl_resource *resource, |
| 3329 | struct wl_resource *parent_resource) |
| 3330 | { |
| 3331 | struct shell_surface *shsurf = wl_resource_get_user_data(resource); |
| 3332 | struct weston_surface *parent; |
| 3333 | |
| 3334 | if (parent_resource) |
| 3335 | parent = wl_resource_get_user_data(parent_resource); |
| 3336 | else |
| 3337 | parent = NULL; |
| 3338 | |
| 3339 | shell_surface_set_parent(shsurf, parent); |
| 3340 | } |
| 3341 | |
| 3342 | static void |
Jasper St. Pierre | 7407345 | 2014-02-01 18:36:41 -0500 | [diff] [blame] | 3343 | xdg_surface_set_margin(struct wl_client *client, |
| 3344 | struct wl_resource *resource, |
| 3345 | int32_t left, |
| 3346 | int32_t right, |
| 3347 | int32_t top, |
| 3348 | int32_t bottom) |
| 3349 | { |
Kristian Høgsberg | ae356ae | 2014-04-29 16:03:54 -0700 | [diff] [blame] | 3350 | struct shell_surface *shsurf = wl_resource_get_user_data(resource); |
| 3351 | |
| 3352 | shsurf->margin.left = left; |
| 3353 | shsurf->margin.right = right; |
| 3354 | shsurf->margin.top = top; |
| 3355 | shsurf->margin.bottom = bottom; |
Jasper St. Pierre | 7407345 | 2014-02-01 18:36:41 -0500 | [diff] [blame] | 3356 | } |
| 3357 | |
| 3358 | static void |
Rafael Antognolli | e2a3455 | 2013-12-03 15:35:45 -0200 | [diff] [blame] | 3359 | xdg_surface_set_app_id(struct wl_client *client, |
| 3360 | struct wl_resource *resource, |
| 3361 | const char *app_id) |
| 3362 | { |
| 3363 | struct shell_surface *shsurf = wl_resource_get_user_data(resource); |
| 3364 | |
| 3365 | free(shsurf->class); |
| 3366 | shsurf->class = strdup(app_id); |
| 3367 | } |
| 3368 | |
| 3369 | static void |
| 3370 | xdg_surface_set_title(struct wl_client *client, |
| 3371 | struct wl_resource *resource, const char *title) |
| 3372 | { |
| 3373 | struct shell_surface *shsurf = wl_resource_get_user_data(resource); |
| 3374 | |
| 3375 | set_title(shsurf, title); |
| 3376 | } |
| 3377 | |
| 3378 | static void |
| 3379 | xdg_surface_move(struct wl_client *client, struct wl_resource *resource, |
| 3380 | struct wl_resource *seat_resource, uint32_t serial) |
| 3381 | { |
| 3382 | common_surface_move(resource, seat_resource, serial); |
| 3383 | } |
| 3384 | |
| 3385 | static void |
| 3386 | xdg_surface_resize(struct wl_client *client, struct wl_resource *resource, |
| 3387 | struct wl_resource *seat_resource, uint32_t serial, |
| 3388 | uint32_t edges) |
| 3389 | { |
| 3390 | common_surface_resize(resource, seat_resource, serial, edges); |
| 3391 | } |
| 3392 | |
| 3393 | static void |
| 3394 | xdg_surface_set_output(struct wl_client *client, |
| 3395 | struct wl_resource *resource, |
| 3396 | struct wl_resource *output_resource) |
| 3397 | { |
| 3398 | struct shell_surface *shsurf = wl_resource_get_user_data(resource); |
| 3399 | struct weston_output *output; |
| 3400 | |
| 3401 | if (output_resource) |
| 3402 | output = wl_resource_get_user_data(output_resource); |
| 3403 | else |
| 3404 | output = NULL; |
| 3405 | |
Rafael Antognolli | 65f98d8 | 2013-12-03 15:35:47 -0200 | [diff] [blame] | 3406 | shsurf->recommended_output = output; |
Rafael Antognolli | e2a3455 | 2013-12-03 15:35:45 -0200 | [diff] [blame] | 3407 | } |
| 3408 | |
| 3409 | static void |
Kristian Høgsberg | 283bf37 | 2014-02-18 23:28:09 -0800 | [diff] [blame] | 3410 | xdg_surface_change_state(struct shell_surface *shsurf, |
| 3411 | uint32_t state, uint32_t value, uint32_t serial) |
Rafael Antognolli | e2a3455 | 2013-12-03 15:35:45 -0200 | [diff] [blame] | 3412 | { |
Kristian Høgsberg | 283bf37 | 2014-02-18 23:28:09 -0800 | [diff] [blame] | 3413 | xdg_surface_send_change_state(shsurf->resource, state, value, serial); |
Jasper St. Pierre | 8c6aa45 | 2014-02-08 18:29:49 -0500 | [diff] [blame] | 3414 | shsurf->state_requested = true; |
Rafael Antognolli | e2a3455 | 2013-12-03 15:35:45 -0200 | [diff] [blame] | 3415 | |
Kristian Høgsberg | 283bf37 | 2014-02-18 23:28:09 -0800 | [diff] [blame] | 3416 | switch (state) { |
| 3417 | case XDG_SURFACE_STATE_MAXIMIZED: |
| 3418 | shsurf->requested_state.maximized = value; |
| 3419 | if (value) |
| 3420 | set_maximized(shsurf, NULL); |
| 3421 | break; |
| 3422 | case XDG_SURFACE_STATE_FULLSCREEN: |
| 3423 | shsurf->requested_state.fullscreen = value; |
Rafael Antognolli | e2a3455 | 2013-12-03 15:35:45 -0200 | [diff] [blame] | 3424 | |
Kristian Høgsberg | 283bf37 | 2014-02-18 23:28:09 -0800 | [diff] [blame] | 3425 | if (value) |
| 3426 | set_fullscreen(shsurf, |
| 3427 | WL_SHELL_SURFACE_FULLSCREEN_METHOD_DEFAULT, |
| 3428 | 0, shsurf->recommended_output); |
| 3429 | break; |
| 3430 | } |
Jasper St. Pierre | 8c6aa45 | 2014-02-08 18:29:49 -0500 | [diff] [blame] | 3431 | } |
| 3432 | |
| 3433 | static void |
| 3434 | xdg_surface_request_change_state(struct wl_client *client, |
| 3435 | struct wl_resource *resource, |
| 3436 | uint32_t state, |
| 3437 | uint32_t value, |
| 3438 | uint32_t serial) |
Rafael Antognolli | e2a3455 | 2013-12-03 15:35:45 -0200 | [diff] [blame] | 3439 | { |
| 3440 | struct shell_surface *shsurf = wl_resource_get_user_data(resource); |
Jasper St. Pierre | 8c6aa45 | 2014-02-08 18:29:49 -0500 | [diff] [blame] | 3441 | |
| 3442 | /* The client can't know what the current state is, so we need |
| 3443 | to always send a state change in response. */ |
Rafael Antognolli | e2a3455 | 2013-12-03 15:35:45 -0200 | [diff] [blame] | 3444 | |
| 3445 | if (shsurf->type != SHELL_SURFACE_TOPLEVEL) |
| 3446 | return; |
| 3447 | |
Jasper St. Pierre | 8c6aa45 | 2014-02-08 18:29:49 -0500 | [diff] [blame] | 3448 | switch (state) { |
| 3449 | case XDG_SURFACE_STATE_MAXIMIZED: |
Jasper St. Pierre | 8c6aa45 | 2014-02-08 18:29:49 -0500 | [diff] [blame] | 3450 | case XDG_SURFACE_STATE_FULLSCREEN: |
Jasper St. Pierre | 8c6aa45 | 2014-02-08 18:29:49 -0500 | [diff] [blame] | 3451 | break; |
Kristian Høgsberg | 283bf37 | 2014-02-18 23:28:09 -0800 | [diff] [blame] | 3452 | default: |
| 3453 | /* send error? ignore? send change state with value 0? */ |
| 3454 | return; |
Rafael Antognolli | 3c4e3f7 | 2013-12-03 15:35:46 -0200 | [diff] [blame] | 3455 | } |
Kristian Høgsberg | 283bf37 | 2014-02-18 23:28:09 -0800 | [diff] [blame] | 3456 | |
| 3457 | xdg_surface_change_state(shsurf, state, value, serial); |
Rafael Antognolli | e2a3455 | 2013-12-03 15:35:45 -0200 | [diff] [blame] | 3458 | } |
| 3459 | |
| 3460 | static void |
Jasper St. Pierre | 8c6aa45 | 2014-02-08 18:29:49 -0500 | [diff] [blame] | 3461 | xdg_surface_ack_change_state(struct wl_client *client, |
| 3462 | struct wl_resource *resource, |
| 3463 | uint32_t state, |
| 3464 | uint32_t value, |
| 3465 | uint32_t serial) |
Rafael Antognolli | e2a3455 | 2013-12-03 15:35:45 -0200 | [diff] [blame] | 3466 | { |
| 3467 | struct shell_surface *shsurf = wl_resource_get_user_data(resource); |
| 3468 | |
Jasper St. Pierre | 8c6aa45 | 2014-02-08 18:29:49 -0500 | [diff] [blame] | 3469 | if (shsurf->state_requested) { |
| 3470 | shsurf->next_state = shsurf->requested_state; |
| 3471 | shsurf->state_changed = true; |
| 3472 | shsurf->state_requested = false; |
Rafael Antognolli | 3c4e3f7 | 2013-12-03 15:35:46 -0200 | [diff] [blame] | 3473 | } |
Rafael Antognolli | e2a3455 | 2013-12-03 15:35:45 -0200 | [diff] [blame] | 3474 | } |
| 3475 | |
Manuel Bachmann | 50c87db | 2014-02-26 15:52:13 +0100 | [diff] [blame] | 3476 | static void |
| 3477 | xdg_surface_set_minimized(struct wl_client *client, |
| 3478 | struct wl_resource *resource) |
| 3479 | { |
| 3480 | struct shell_surface *shsurf = wl_resource_get_user_data(resource); |
| 3481 | |
| 3482 | if (shsurf->type != SHELL_SURFACE_TOPLEVEL) |
| 3483 | return; |
| 3484 | |
| 3485 | /* apply compositor's own minimization logic (hide) */ |
| 3486 | set_minimized(shsurf->surface, 1); |
| 3487 | } |
| 3488 | |
Rafael Antognolli | e2a3455 | 2013-12-03 15:35:45 -0200 | [diff] [blame] | 3489 | static const struct xdg_surface_interface xdg_surface_implementation = { |
| 3490 | xdg_surface_destroy, |
| 3491 | xdg_surface_set_transient_for, |
Jasper St. Pierre | 7407345 | 2014-02-01 18:36:41 -0500 | [diff] [blame] | 3492 | xdg_surface_set_margin, |
Rafael Antognolli | e2a3455 | 2013-12-03 15:35:45 -0200 | [diff] [blame] | 3493 | xdg_surface_set_title, |
| 3494 | xdg_surface_set_app_id, |
Rafael Antognolli | e2a3455 | 2013-12-03 15:35:45 -0200 | [diff] [blame] | 3495 | xdg_surface_move, |
| 3496 | xdg_surface_resize, |
| 3497 | xdg_surface_set_output, |
Jasper St. Pierre | 8c6aa45 | 2014-02-08 18:29:49 -0500 | [diff] [blame] | 3498 | xdg_surface_request_change_state, |
| 3499 | xdg_surface_ack_change_state, |
Manuel Bachmann | 50c87db | 2014-02-26 15:52:13 +0100 | [diff] [blame] | 3500 | xdg_surface_set_minimized |
Rafael Antognolli | e2a3455 | 2013-12-03 15:35:45 -0200 | [diff] [blame] | 3501 | }; |
| 3502 | |
| 3503 | static void |
| 3504 | xdg_send_configure(struct weston_surface *surface, |
| 3505 | uint32_t edges, int32_t width, int32_t height) |
| 3506 | { |
| 3507 | struct shell_surface *shsurf = get_shell_surface(surface); |
| 3508 | |
U. Artie Eoff | cf5737a | 2014-01-17 10:08:25 -0800 | [diff] [blame] | 3509 | assert(shsurf); |
| 3510 | |
Kristian Høgsberg | e0b9d5b | 2014-04-30 13:45:49 -0700 | [diff] [blame] | 3511 | if (shsurf->resource) |
| 3512 | xdg_surface_send_configure(shsurf->resource, width, height); |
Rafael Antognolli | e2a3455 | 2013-12-03 15:35:45 -0200 | [diff] [blame] | 3513 | } |
| 3514 | |
| 3515 | static const struct weston_shell_client xdg_client = { |
| 3516 | xdg_send_configure |
| 3517 | }; |
| 3518 | |
| 3519 | static void |
| 3520 | xdg_use_unstable_version(struct wl_client *client, |
| 3521 | struct wl_resource *resource, |
| 3522 | int32_t version) |
| 3523 | { |
| 3524 | if (version > 1) { |
| 3525 | wl_resource_post_error(resource, |
| 3526 | 1, |
| 3527 | "xdg-shell:: version not implemented yet."); |
| 3528 | return; |
| 3529 | } |
| 3530 | } |
| 3531 | |
| 3532 | static struct shell_surface * |
Jason Ekstrand | 9e9512f | 2014-04-16 21:12:10 -0500 | [diff] [blame] | 3533 | create_xdg_surface(struct shell_client *owner, void *shell, |
| 3534 | struct weston_surface *surface, |
Rafael Antognolli | e2a3455 | 2013-12-03 15:35:45 -0200 | [diff] [blame] | 3535 | const struct weston_shell_client *client) |
| 3536 | { |
| 3537 | struct shell_surface *shsurf; |
Rafael Antognolli | e2a3455 | 2013-12-03 15:35:45 -0200 | [diff] [blame] | 3538 | |
Jason Ekstrand | 9e9512f | 2014-04-16 21:12:10 -0500 | [diff] [blame] | 3539 | shsurf = create_common_surface(owner, shell, surface, client); |
Kristian Høgsberg | c8f8dd8 | 2013-12-05 23:20:33 -0800 | [diff] [blame] | 3540 | shsurf->type = SHELL_SURFACE_TOPLEVEL; |
Rafael Antognolli | e2a3455 | 2013-12-03 15:35:45 -0200 | [diff] [blame] | 3541 | |
| 3542 | return shsurf; |
| 3543 | } |
| 3544 | |
| 3545 | static void |
| 3546 | xdg_get_xdg_surface(struct wl_client *client, |
| 3547 | struct wl_resource *resource, |
| 3548 | uint32_t id, |
| 3549 | struct wl_resource *surface_resource) |
| 3550 | { |
| 3551 | struct weston_surface *surface = |
| 3552 | wl_resource_get_user_data(surface_resource); |
Kristian Høgsberg | 2bff94e | 2014-02-11 12:22:51 -0800 | [diff] [blame] | 3553 | struct shell_client *sc = wl_resource_get_user_data(resource); |
| 3554 | struct desktop_shell *shell = sc->shell; |
Rafael Antognolli | e2a3455 | 2013-12-03 15:35:45 -0200 | [diff] [blame] | 3555 | struct shell_surface *shsurf; |
| 3556 | |
| 3557 | if (get_shell_surface(surface)) { |
| 3558 | wl_resource_post_error(surface_resource, |
| 3559 | WL_DISPLAY_ERROR_INVALID_OBJECT, |
Jasper St. Pierre | fe9671e | 2014-03-25 13:31:44 -0400 | [diff] [blame] | 3560 | "xdg_shell::get_xdg_surface already requested"); |
Rafael Antognolli | e2a3455 | 2013-12-03 15:35:45 -0200 | [diff] [blame] | 3561 | return; |
| 3562 | } |
| 3563 | |
Jason Ekstrand | 9e9512f | 2014-04-16 21:12:10 -0500 | [diff] [blame] | 3564 | shsurf = create_xdg_surface(sc, shell, surface, &xdg_client); |
Rafael Antognolli | e2a3455 | 2013-12-03 15:35:45 -0200 | [diff] [blame] | 3565 | if (!shsurf) { |
| 3566 | wl_resource_post_error(surface_resource, |
| 3567 | WL_DISPLAY_ERROR_INVALID_OBJECT, |
| 3568 | "surface->configure already set"); |
| 3569 | return; |
| 3570 | } |
| 3571 | |
| 3572 | shsurf->resource = |
| 3573 | wl_resource_create(client, |
| 3574 | &xdg_surface_interface, 1, id); |
| 3575 | wl_resource_set_implementation(shsurf->resource, |
| 3576 | &xdg_surface_implementation, |
| 3577 | shsurf, shell_destroy_shell_surface); |
| 3578 | } |
| 3579 | |
| 3580 | static bool |
| 3581 | shell_surface_is_xdg_surface(struct shell_surface *shsurf) |
| 3582 | { |
Kristian Høgsberg | 0b7d995 | 2014-02-03 15:50:38 -0800 | [diff] [blame] | 3583 | return shsurf->resource && |
| 3584 | wl_resource_instance_of(shsurf->resource, |
| 3585 | &xdg_surface_interface, |
| 3586 | &xdg_surface_implementation); |
Rafael Antognolli | e2a3455 | 2013-12-03 15:35:45 -0200 | [diff] [blame] | 3587 | } |
| 3588 | |
| 3589 | /* xdg-popup implementation */ |
| 3590 | |
| 3591 | static void |
| 3592 | xdg_popup_destroy(struct wl_client *client, |
| 3593 | struct wl_resource *resource) |
| 3594 | { |
| 3595 | wl_resource_destroy(resource); |
| 3596 | } |
| 3597 | |
Rafael Antognolli | e2a3455 | 2013-12-03 15:35:45 -0200 | [diff] [blame] | 3598 | static const struct xdg_popup_interface xdg_popup_implementation = { |
| 3599 | xdg_popup_destroy, |
Rafael Antognolli | e2a3455 | 2013-12-03 15:35:45 -0200 | [diff] [blame] | 3600 | }; |
| 3601 | |
| 3602 | static void |
| 3603 | xdg_popup_send_configure(struct weston_surface *surface, |
| 3604 | uint32_t edges, int32_t width, int32_t height) |
| 3605 | { |
| 3606 | } |
| 3607 | |
| 3608 | static const struct weston_shell_client xdg_popup_client = { |
| 3609 | xdg_popup_send_configure |
| 3610 | }; |
| 3611 | |
| 3612 | static struct shell_surface * |
Jason Ekstrand | 9e9512f | 2014-04-16 21:12:10 -0500 | [diff] [blame] | 3613 | create_xdg_popup(struct shell_client *owner, void *shell, |
| 3614 | struct weston_surface *surface, |
Rafael Antognolli | e2a3455 | 2013-12-03 15:35:45 -0200 | [diff] [blame] | 3615 | const struct weston_shell_client *client, |
| 3616 | struct weston_surface *parent, |
| 3617 | struct shell_seat *seat, |
| 3618 | uint32_t serial, |
| 3619 | int32_t x, int32_t y) |
| 3620 | { |
| 3621 | struct shell_surface *shsurf; |
Rafael Antognolli | e2a3455 | 2013-12-03 15:35:45 -0200 | [diff] [blame] | 3622 | |
Jason Ekstrand | 9e9512f | 2014-04-16 21:12:10 -0500 | [diff] [blame] | 3623 | shsurf = create_common_surface(owner, shell, surface, client); |
Kristian Høgsberg | c8f8dd8 | 2013-12-05 23:20:33 -0800 | [diff] [blame] | 3624 | shsurf->type = SHELL_SURFACE_POPUP; |
Rafael Antognolli | e2a3455 | 2013-12-03 15:35:45 -0200 | [diff] [blame] | 3625 | shsurf->popup.shseat = seat; |
| 3626 | shsurf->popup.serial = serial; |
| 3627 | shsurf->popup.x = x; |
| 3628 | shsurf->popup.y = y; |
| 3629 | shell_surface_set_parent(shsurf, parent); |
| 3630 | |
| 3631 | return shsurf; |
| 3632 | } |
| 3633 | |
| 3634 | static void |
| 3635 | xdg_get_xdg_popup(struct wl_client *client, |
| 3636 | struct wl_resource *resource, |
| 3637 | uint32_t id, |
| 3638 | struct wl_resource *surface_resource, |
| 3639 | struct wl_resource *parent_resource, |
| 3640 | struct wl_resource *seat_resource, |
| 3641 | uint32_t serial, |
| 3642 | int32_t x, int32_t y, uint32_t flags) |
| 3643 | { |
| 3644 | struct weston_surface *surface = |
| 3645 | wl_resource_get_user_data(surface_resource); |
Kristian Høgsberg | 2bff94e | 2014-02-11 12:22:51 -0800 | [diff] [blame] | 3646 | struct shell_client *sc = wl_resource_get_user_data(resource); |
| 3647 | struct desktop_shell *shell = sc->shell; |
Rafael Antognolli | e2a3455 | 2013-12-03 15:35:45 -0200 | [diff] [blame] | 3648 | struct shell_surface *shsurf; |
| 3649 | struct weston_surface *parent; |
| 3650 | struct shell_seat *seat; |
| 3651 | |
| 3652 | if (get_shell_surface(surface)) { |
| 3653 | wl_resource_post_error(surface_resource, |
| 3654 | WL_DISPLAY_ERROR_INVALID_OBJECT, |
Jasper St. Pierre | fe9671e | 2014-03-25 13:31:44 -0400 | [diff] [blame] | 3655 | "xdg_shell::get_xdg_popup already requested"); |
Rafael Antognolli | e2a3455 | 2013-12-03 15:35:45 -0200 | [diff] [blame] | 3656 | return; |
| 3657 | } |
| 3658 | |
| 3659 | if (!parent_resource) { |
| 3660 | wl_resource_post_error(surface_resource, |
| 3661 | WL_DISPLAY_ERROR_INVALID_OBJECT, |
| 3662 | "xdg_shell::get_xdg_popup requires a parent shell surface"); |
| 3663 | } |
| 3664 | |
| 3665 | parent = wl_resource_get_user_data(parent_resource); |
| 3666 | seat = get_shell_seat(wl_resource_get_user_data(seat_resource));; |
| 3667 | |
Jason Ekstrand | 9e9512f | 2014-04-16 21:12:10 -0500 | [diff] [blame] | 3668 | shsurf = create_xdg_popup(sc, shell, surface, &xdg_popup_client, |
Rafael Antognolli | e2a3455 | 2013-12-03 15:35:45 -0200 | [diff] [blame] | 3669 | parent, seat, serial, x, y); |
| 3670 | if (!shsurf) { |
| 3671 | wl_resource_post_error(surface_resource, |
| 3672 | WL_DISPLAY_ERROR_INVALID_OBJECT, |
| 3673 | "surface->configure already set"); |
| 3674 | return; |
| 3675 | } |
| 3676 | |
| 3677 | shsurf->resource = |
| 3678 | wl_resource_create(client, |
| 3679 | &xdg_popup_interface, 1, id); |
| 3680 | wl_resource_set_implementation(shsurf->resource, |
| 3681 | &xdg_popup_implementation, |
| 3682 | shsurf, shell_destroy_shell_surface); |
| 3683 | } |
| 3684 | |
Kristian Høgsberg | 2bff94e | 2014-02-11 12:22:51 -0800 | [diff] [blame] | 3685 | static void |
| 3686 | xdg_pong(struct wl_client *client, |
| 3687 | struct wl_resource *resource, uint32_t serial) |
| 3688 | { |
| 3689 | struct shell_client *sc = wl_resource_get_user_data(resource); |
Kristian Høgsberg | 2bff94e | 2014-02-11 12:22:51 -0800 | [diff] [blame] | 3690 | |
Kristian Høgsberg | dd62aba | 2014-02-12 09:56:19 -0800 | [diff] [blame] | 3691 | shell_client_pong(sc, serial); |
Kristian Høgsberg | 2bff94e | 2014-02-11 12:22:51 -0800 | [diff] [blame] | 3692 | } |
| 3693 | |
Rafael Antognolli | e2a3455 | 2013-12-03 15:35:45 -0200 | [diff] [blame] | 3694 | static bool |
| 3695 | shell_surface_is_xdg_popup(struct shell_surface *shsurf) |
| 3696 | { |
| 3697 | return wl_resource_instance_of(shsurf->resource, |
| 3698 | &xdg_popup_interface, |
| 3699 | &xdg_popup_implementation); |
| 3700 | } |
| 3701 | |
| 3702 | static const struct xdg_shell_interface xdg_implementation = { |
| 3703 | xdg_use_unstable_version, |
| 3704 | xdg_get_xdg_surface, |
Kristian Høgsberg | 2bff94e | 2014-02-11 12:22:51 -0800 | [diff] [blame] | 3705 | xdg_get_xdg_popup, |
| 3706 | xdg_pong |
Rafael Antognolli | e2a3455 | 2013-12-03 15:35:45 -0200 | [diff] [blame] | 3707 | }; |
| 3708 | |
| 3709 | static int |
| 3710 | xdg_shell_unversioned_dispatch(const void *implementation, |
| 3711 | void *_target, uint32_t opcode, |
| 3712 | const struct wl_message *message, |
| 3713 | union wl_argument *args) |
| 3714 | { |
| 3715 | struct wl_resource *resource = _target; |
Kristian Høgsberg | 2bff94e | 2014-02-11 12:22:51 -0800 | [diff] [blame] | 3716 | struct shell_client *sc = wl_resource_get_user_data(resource); |
Rafael Antognolli | e2a3455 | 2013-12-03 15:35:45 -0200 | [diff] [blame] | 3717 | |
| 3718 | if (opcode != 0) { |
| 3719 | wl_resource_post_error(resource, |
| 3720 | WL_DISPLAY_ERROR_INVALID_OBJECT, |
| 3721 | "must call use_unstable_version first"); |
| 3722 | return 0; |
| 3723 | } |
| 3724 | |
Kristian Høgsberg | c7680b0 | 2014-02-19 10:14:46 -0800 | [diff] [blame] | 3725 | #define XDG_SERVER_VERSION 3 |
Rafael Antognolli | e2a3455 | 2013-12-03 15:35:45 -0200 | [diff] [blame] | 3726 | |
Kristian Høgsberg | 8d344a0 | 2013-12-08 22:27:11 -0800 | [diff] [blame] | 3727 | static_assert(XDG_SERVER_VERSION == XDG_SHELL_VERSION_CURRENT, |
| 3728 | "shell implementation doesn't match protocol version"); |
| 3729 | |
Rafael Antognolli | e2a3455 | 2013-12-03 15:35:45 -0200 | [diff] [blame] | 3730 | if (args[0].i != XDG_SERVER_VERSION) { |
| 3731 | wl_resource_post_error(resource, |
| 3732 | WL_DISPLAY_ERROR_INVALID_OBJECT, |
| 3733 | "incompatible version, server is %d " |
| 3734 | "client wants %d", |
| 3735 | XDG_SERVER_VERSION, args[0].i); |
| 3736 | return 0; |
| 3737 | } |
| 3738 | |
| 3739 | wl_resource_set_implementation(resource, &xdg_implementation, |
Kristian Høgsberg | 2bff94e | 2014-02-11 12:22:51 -0800 | [diff] [blame] | 3740 | sc, NULL); |
Rafael Antognolli | e2a3455 | 2013-12-03 15:35:45 -0200 | [diff] [blame] | 3741 | |
| 3742 | return 1; |
| 3743 | } |
| 3744 | |
| 3745 | /* end of xdg-shell implementation */ |
| 3746 | /***********************************/ |
| 3747 | |
Kristian Høgsberg | 0793756 | 2011-04-12 17:25:42 -0400 | [diff] [blame] | 3748 | static void |
Ander Conselvan de Oliveira | 859e885 | 2013-02-21 18:35:21 +0200 | [diff] [blame] | 3749 | shell_fade(struct desktop_shell *shell, enum fade_type type); |
| 3750 | |
| 3751 | static int |
| 3752 | screensaver_timeout(void *data) |
| 3753 | { |
| 3754 | struct desktop_shell *shell = data; |
| 3755 | |
| 3756 | shell_fade(shell, FADE_OUT); |
| 3757 | |
| 3758 | return 1; |
| 3759 | } |
| 3760 | |
| 3761 | static void |
Kristian Høgsberg | 8334bc1 | 2012-01-03 10:29:47 -0500 | [diff] [blame] | 3762 | handle_screensaver_sigchld(struct weston_process *proc, int status) |
Pekka Paalanen | 18027e5 | 2011-12-02 16:31:49 +0200 | [diff] [blame] | 3763 | { |
Ander Conselvan de Oliveira | 18639f8 | 2013-02-15 18:44:19 +0200 | [diff] [blame] | 3764 | struct desktop_shell *shell = |
| 3765 | container_of(proc, struct desktop_shell, screensaver.process); |
Ander Conselvan de Oliveira | 18639f8 | 2013-02-15 18:44:19 +0200 | [diff] [blame] | 3766 | |
Pekka Paalanen | 18027e5 | 2011-12-02 16:31:49 +0200 | [diff] [blame] | 3767 | proc->pid = 0; |
Ander Conselvan de Oliveira | 18639f8 | 2013-02-15 18:44:19 +0200 | [diff] [blame] | 3768 | |
| 3769 | if (shell->locked) |
Ander Conselvan de Oliveira | b17537e | 2013-02-22 14:16:18 +0200 | [diff] [blame] | 3770 | weston_compositor_sleep(shell->compositor); |
Pekka Paalanen | 18027e5 | 2011-12-02 16:31:49 +0200 | [diff] [blame] | 3771 | } |
| 3772 | |
| 3773 | static void |
Tiago Vignatti | be14326 | 2012-04-16 17:31:41 +0300 | [diff] [blame] | 3774 | launch_screensaver(struct desktop_shell *shell) |
Pekka Paalanen | 77346a6 | 2011-11-30 16:26:35 +0200 | [diff] [blame] | 3775 | { |
| 3776 | if (shell->screensaver.binding) |
| 3777 | return; |
| 3778 | |
Ander Conselvan de Oliveira | dda9d78 | 2013-02-22 14:16:19 +0200 | [diff] [blame] | 3779 | if (!shell->screensaver.path) { |
| 3780 | weston_compositor_sleep(shell->compositor); |
Pekka Paalanen | e955f1e | 2011-12-07 11:49:52 +0200 | [diff] [blame] | 3781 | return; |
Ander Conselvan de Oliveira | dda9d78 | 2013-02-22 14:16:19 +0200 | [diff] [blame] | 3782 | } |
Pekka Paalanen | e955f1e | 2011-12-07 11:49:52 +0200 | [diff] [blame] | 3783 | |
Kristian Høgsberg | 32bed57 | 2012-03-01 17:11:36 -0500 | [diff] [blame] | 3784 | if (shell->screensaver.process.pid != 0) { |
Martin Minarik | 6d11836 | 2012-06-07 18:01:59 +0200 | [diff] [blame] | 3785 | weston_log("old screensaver still running\n"); |
Kristian Høgsberg | 32bed57 | 2012-03-01 17:11:36 -0500 | [diff] [blame] | 3786 | return; |
| 3787 | } |
| 3788 | |
Kristian Høgsberg | 8334bc1 | 2012-01-03 10:29:47 -0500 | [diff] [blame] | 3789 | weston_client_launch(shell->compositor, |
Pekka Paalanen | 18027e5 | 2011-12-02 16:31:49 +0200 | [diff] [blame] | 3790 | &shell->screensaver.process, |
Pekka Paalanen | e955f1e | 2011-12-07 11:49:52 +0200 | [diff] [blame] | 3791 | shell->screensaver.path, |
Pekka Paalanen | 18027e5 | 2011-12-02 16:31:49 +0200 | [diff] [blame] | 3792 | handle_screensaver_sigchld); |
Pekka Paalanen | 77346a6 | 2011-11-30 16:26:35 +0200 | [diff] [blame] | 3793 | } |
| 3794 | |
| 3795 | static void |
Tiago Vignatti | be14326 | 2012-04-16 17:31:41 +0300 | [diff] [blame] | 3796 | terminate_screensaver(struct desktop_shell *shell) |
Pekka Paalanen | 77346a6 | 2011-11-30 16:26:35 +0200 | [diff] [blame] | 3797 | { |
Pekka Paalanen | 18027e5 | 2011-12-02 16:31:49 +0200 | [diff] [blame] | 3798 | if (shell->screensaver.process.pid == 0) |
| 3799 | return; |
| 3800 | |
Ander Conselvan de Oliveira | 4e20e9b | 2014-04-10 14:49:35 +0300 | [diff] [blame] | 3801 | /* Disarm the screensaver timer, otherwise it may fire when the |
| 3802 | * compositor is not in the idle state. In that case, the screen will |
| 3803 | * be locked, but the wake_signal won't fire on user input, making the |
| 3804 | * system unresponsive. */ |
| 3805 | wl_event_source_timer_update(shell->screensaver.timer, 0); |
| 3806 | |
Pekka Paalanen | 18027e5 | 2011-12-02 16:31:49 +0200 | [diff] [blame] | 3807 | kill(shell->screensaver.process.pid, SIGTERM); |
Pekka Paalanen | 77346a6 | 2011-11-30 16:26:35 +0200 | [diff] [blame] | 3808 | } |
| 3809 | |
| 3810 | static void |
Jason Ekstrand | 918f2dd | 2013-12-02 21:01:53 -0600 | [diff] [blame] | 3811 | configure_static_view(struct weston_view *ev, struct weston_layer *layer) |
Kristian Høgsberg | 962342c | 2012-06-26 16:29:50 -0400 | [diff] [blame] | 3812 | { |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 3813 | struct weston_view *v, *next; |
Kristian Høgsberg | 962342c | 2012-06-26 16:29:50 -0400 | [diff] [blame] | 3814 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 3815 | wl_list_for_each_safe(v, next, &layer->view_list, layer_link) { |
| 3816 | if (v->output == ev->output && v != ev) { |
| 3817 | weston_view_unmap(v); |
| 3818 | v->surface->configure = NULL; |
Kristian Høgsberg | 962342c | 2012-06-26 16:29:50 -0400 | [diff] [blame] | 3819 | } |
| 3820 | } |
| 3821 | |
Jason Ekstrand | 918f2dd | 2013-12-02 21:01:53 -0600 | [diff] [blame] | 3822 | weston_view_set_position(ev, ev->output->x, ev->output->y); |
Kristian Høgsberg | 962342c | 2012-06-26 16:29:50 -0400 | [diff] [blame] | 3823 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 3824 | if (wl_list_empty(&ev->layer_link)) { |
| 3825 | wl_list_insert(&layer->view_list, &ev->layer_link); |
| 3826 | weston_compositor_schedule_repaint(ev->surface->compositor); |
Kristian Høgsberg | 962342c | 2012-06-26 16:29:50 -0400 | [diff] [blame] | 3827 | } |
| 3828 | } |
| 3829 | |
| 3830 | static void |
Jason Ekstrand | 918f2dd | 2013-12-02 21:01:53 -0600 | [diff] [blame] | 3831 | 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] | 3832 | { |
Giulio Camuffo | 7fe01b1 | 2013-03-28 18:02:42 +0100 | [diff] [blame] | 3833 | struct desktop_shell *shell = es->configure_private; |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 3834 | struct weston_view *view; |
Kristian Høgsberg | af7b1ff | 2012-06-26 21:19:23 -0400 | [diff] [blame] | 3835 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 3836 | view = container_of(es->views.next, struct weston_view, surface_link); |
| 3837 | |
Jason Ekstrand | 918f2dd | 2013-12-02 21:01:53 -0600 | [diff] [blame] | 3838 | configure_static_view(view, &shell->background_layer); |
Kristian Høgsberg | af7b1ff | 2012-06-26 21:19:23 -0400 | [diff] [blame] | 3839 | } |
| 3840 | |
| 3841 | static void |
Kristian Høgsberg | 7584062 | 2011-09-06 13:48:16 -0400 | [diff] [blame] | 3842 | desktop_shell_set_background(struct wl_client *client, |
| 3843 | struct wl_resource *resource, |
Benjamin Franzke | d0f79ab | 2011-11-22 12:43:52 +0100 | [diff] [blame] | 3844 | struct wl_resource *output_resource, |
Kristian Høgsberg | 7584062 | 2011-09-06 13:48:16 -0400 | [diff] [blame] | 3845 | struct wl_resource *surface_resource) |
| 3846 | { |
Jason Ekstrand | 651f00e | 2013-06-14 10:07:54 -0500 | [diff] [blame] | 3847 | struct desktop_shell *shell = wl_resource_get_user_data(resource); |
Jason Ekstrand | 0f2ef7e | 2013-06-14 10:07:53 -0500 | [diff] [blame] | 3848 | struct weston_surface *surface = |
| 3849 | wl_resource_get_user_data(surface_resource); |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 3850 | struct weston_view *view, *next; |
Kristian Høgsberg | 7584062 | 2011-09-06 13:48:16 -0400 | [diff] [blame] | 3851 | |
Kristian Høgsberg | 962342c | 2012-06-26 16:29:50 -0400 | [diff] [blame] | 3852 | if (surface->configure) { |
| 3853 | wl_resource_post_error(surface_resource, |
| 3854 | WL_DISPLAY_ERROR_INVALID_OBJECT, |
| 3855 | "surface role already assigned"); |
| 3856 | return; |
| 3857 | } |
Benjamin Franzke | d0f79ab | 2011-11-22 12:43:52 +0100 | [diff] [blame] | 3858 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 3859 | wl_list_for_each_safe(view, next, &surface->views, surface_link) |
| 3860 | weston_view_destroy(view); |
| 3861 | view = weston_view_create(surface); |
| 3862 | |
Kristian Høgsberg | 962342c | 2012-06-26 16:29:50 -0400 | [diff] [blame] | 3863 | surface->configure = background_configure; |
Giulio Camuffo | 7fe01b1 | 2013-03-28 18:02:42 +0100 | [diff] [blame] | 3864 | surface->configure_private = shell; |
Jason Ekstrand | a0d2dde | 2013-06-14 10:08:01 -0500 | [diff] [blame] | 3865 | surface->output = wl_resource_get_user_data(output_resource); |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 3866 | view->output = surface->output; |
Kristian Høgsberg | eae5de7 | 2012-04-11 22:42:15 -0400 | [diff] [blame] | 3867 | desktop_shell_send_configure(resource, 0, |
Kristian Høgsberg | 0b5cd0c | 2012-03-04 21:57:37 -0500 | [diff] [blame] | 3868 | surface_resource, |
Scott Moreau | 1bad5db | 2012-08-18 01:04:05 -0600 | [diff] [blame] | 3869 | surface->output->width, |
| 3870 | surface->output->height); |
Kristian Høgsberg | 7584062 | 2011-09-06 13:48:16 -0400 | [diff] [blame] | 3871 | } |
| 3872 | |
| 3873 | static void |
Jason Ekstrand | 918f2dd | 2013-12-02 21:01:53 -0600 | [diff] [blame] | 3874 | 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] | 3875 | { |
Giulio Camuffo | 7fe01b1 | 2013-03-28 18:02:42 +0100 | [diff] [blame] | 3876 | struct desktop_shell *shell = es->configure_private; |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 3877 | struct weston_view *view; |
Kristian Høgsberg | af7b1ff | 2012-06-26 21:19:23 -0400 | [diff] [blame] | 3878 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 3879 | view = container_of(es->views.next, struct weston_view, surface_link); |
| 3880 | |
Jason Ekstrand | 918f2dd | 2013-12-02 21:01:53 -0600 | [diff] [blame] | 3881 | configure_static_view(view, &shell->panel_layer); |
Kristian Høgsberg | af7b1ff | 2012-06-26 21:19:23 -0400 | [diff] [blame] | 3882 | } |
| 3883 | |
| 3884 | static void |
Kristian Høgsberg | 7584062 | 2011-09-06 13:48:16 -0400 | [diff] [blame] | 3885 | desktop_shell_set_panel(struct wl_client *client, |
| 3886 | struct wl_resource *resource, |
Benjamin Franzke | d0f79ab | 2011-11-22 12:43:52 +0100 | [diff] [blame] | 3887 | struct wl_resource *output_resource, |
Kristian Høgsberg | 7584062 | 2011-09-06 13:48:16 -0400 | [diff] [blame] | 3888 | struct wl_resource *surface_resource) |
| 3889 | { |
Jason Ekstrand | 651f00e | 2013-06-14 10:07:54 -0500 | [diff] [blame] | 3890 | struct desktop_shell *shell = wl_resource_get_user_data(resource); |
Jason Ekstrand | 0f2ef7e | 2013-06-14 10:07:53 -0500 | [diff] [blame] | 3891 | struct weston_surface *surface = |
| 3892 | wl_resource_get_user_data(surface_resource); |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 3893 | struct weston_view *view, *next; |
Kristian Høgsberg | 7584062 | 2011-09-06 13:48:16 -0400 | [diff] [blame] | 3894 | |
Kristian Høgsberg | af7b1ff | 2012-06-26 21:19:23 -0400 | [diff] [blame] | 3895 | if (surface->configure) { |
| 3896 | wl_resource_post_error(surface_resource, |
| 3897 | WL_DISPLAY_ERROR_INVALID_OBJECT, |
| 3898 | "surface role already assigned"); |
| 3899 | return; |
| 3900 | } |
Benjamin Franzke | d0f79ab | 2011-11-22 12:43:52 +0100 | [diff] [blame] | 3901 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 3902 | wl_list_for_each_safe(view, next, &surface->views, surface_link) |
| 3903 | weston_view_destroy(view); |
| 3904 | view = weston_view_create(surface); |
| 3905 | |
Kristian Høgsberg | af7b1ff | 2012-06-26 21:19:23 -0400 | [diff] [blame] | 3906 | surface->configure = panel_configure; |
Giulio Camuffo | 7fe01b1 | 2013-03-28 18:02:42 +0100 | [diff] [blame] | 3907 | surface->configure_private = shell; |
Jason Ekstrand | a0d2dde | 2013-06-14 10:08:01 -0500 | [diff] [blame] | 3908 | surface->output = wl_resource_get_user_data(output_resource); |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 3909 | view->output = surface->output; |
Kristian Høgsberg | eae5de7 | 2012-04-11 22:42:15 -0400 | [diff] [blame] | 3910 | desktop_shell_send_configure(resource, 0, |
Kristian Høgsberg | af7b1ff | 2012-06-26 21:19:23 -0400 | [diff] [blame] | 3911 | surface_resource, |
Scott Moreau | 1bad5db | 2012-08-18 01:04:05 -0600 | [diff] [blame] | 3912 | surface->output->width, |
| 3913 | surface->output->height); |
Kristian Høgsberg | 7584062 | 2011-09-06 13:48:16 -0400 | [diff] [blame] | 3914 | } |
| 3915 | |
Pekka Paalanen | 9ef3e01 | 2011-11-15 13:34:48 +0200 | [diff] [blame] | 3916 | static void |
Jason Ekstrand | 918f2dd | 2013-12-02 21:01:53 -0600 | [diff] [blame] | 3917 | 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] | 3918 | { |
Giulio Camuffo | 7fe01b1 | 2013-03-28 18:02:42 +0100 | [diff] [blame] | 3919 | struct desktop_shell *shell = surface->configure_private; |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 3920 | struct weston_view *view; |
| 3921 | |
| 3922 | view = container_of(surface->views.next, struct weston_view, surface_link); |
Kristian Høgsberg | 730c94d | 2012-06-26 21:44:35 -0400 | [diff] [blame] | 3923 | |
Jason Ekstrand | 918f2dd | 2013-12-02 21:01:53 -0600 | [diff] [blame] | 3924 | if (surface->width == 0) |
Giulio Camuffo | 184df50 | 2013-02-21 11:29:21 +0100 | [diff] [blame] | 3925 | return; |
| 3926 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 3927 | center_on_output(view, get_default_output(shell->compositor)); |
Kristian Høgsberg | 730c94d | 2012-06-26 21:44:35 -0400 | [diff] [blame] | 3928 | |
| 3929 | if (!weston_surface_is_mapped(surface)) { |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 3930 | wl_list_insert(&shell->lock_layer.view_list, |
| 3931 | &view->layer_link); |
| 3932 | weston_view_update_transform(view); |
Ander Conselvan de Oliveira | 87524b6 | 2013-02-21 18:35:22 +0200 | [diff] [blame] | 3933 | shell_fade(shell, FADE_IN); |
Kristian Høgsberg | 730c94d | 2012-06-26 21:44:35 -0400 | [diff] [blame] | 3934 | } |
| 3935 | } |
| 3936 | |
| 3937 | static void |
Kristian Høgsberg | 27e3052 | 2012-04-11 23:18:23 -0400 | [diff] [blame] | 3938 | handle_lock_surface_destroy(struct wl_listener *listener, void *data) |
Kristian Høgsberg | 1ec0c31 | 2011-11-15 16:39:55 -0500 | [diff] [blame] | 3939 | { |
Tiago Vignatti | be14326 | 2012-04-16 17:31:41 +0300 | [diff] [blame] | 3940 | struct desktop_shell *shell = |
| 3941 | container_of(listener, struct desktop_shell, lock_surface_listener); |
Kristian Høgsberg | 1ec0c31 | 2011-11-15 16:39:55 -0500 | [diff] [blame] | 3942 | |
Martin Minarik | 6d11836 | 2012-06-07 18:01:59 +0200 | [diff] [blame] | 3943 | weston_log("lock surface gone\n"); |
Kristian Høgsberg | 1ec0c31 | 2011-11-15 16:39:55 -0500 | [diff] [blame] | 3944 | shell->lock_surface = NULL; |
| 3945 | } |
| 3946 | |
| 3947 | static void |
Pekka Paalanen | 9ef3e01 | 2011-11-15 13:34:48 +0200 | [diff] [blame] | 3948 | desktop_shell_set_lock_surface(struct wl_client *client, |
| 3949 | struct wl_resource *resource, |
| 3950 | struct wl_resource *surface_resource) |
| 3951 | { |
Jason Ekstrand | 651f00e | 2013-06-14 10:07:54 -0500 | [diff] [blame] | 3952 | struct desktop_shell *shell = wl_resource_get_user_data(resource); |
Jason Ekstrand | 0f2ef7e | 2013-06-14 10:07:53 -0500 | [diff] [blame] | 3953 | struct weston_surface *surface = |
| 3954 | wl_resource_get_user_data(surface_resource); |
Pekka Paalanen | 9826223 | 2011-12-01 10:42:22 +0200 | [diff] [blame] | 3955 | |
Pekka Paalanen | f0fc70d | 2011-11-15 13:34:54 +0200 | [diff] [blame] | 3956 | shell->prepare_event_sent = false; |
Kristian Høgsberg | af867cc | 2011-11-15 13:34:49 +0200 | [diff] [blame] | 3957 | |
Pekka Paalanen | f0fc70d | 2011-11-15 13:34:54 +0200 | [diff] [blame] | 3958 | if (!shell->locked) |
| 3959 | return; |
| 3960 | |
Pekka Paalanen | 9826223 | 2011-12-01 10:42:22 +0200 | [diff] [blame] | 3961 | shell->lock_surface = surface; |
Pekka Paalanen | f0fc70d | 2011-11-15 13:34:54 +0200 | [diff] [blame] | 3962 | |
Kristian Høgsberg | 27e3052 | 2012-04-11 23:18:23 -0400 | [diff] [blame] | 3963 | shell->lock_surface_listener.notify = handle_lock_surface_destroy; |
Jason Ekstrand | 651f00e | 2013-06-14 10:07:54 -0500 | [diff] [blame] | 3964 | wl_signal_add(&surface->destroy_signal, |
Kristian Høgsberg | 27e3052 | 2012-04-11 23:18:23 -0400 | [diff] [blame] | 3965 | &shell->lock_surface_listener); |
Pekka Paalanen | 57da4a8 | 2011-11-23 16:42:16 +0200 | [diff] [blame] | 3966 | |
Kristian Høgsberg | aa2ee8b | 2013-10-30 15:49:45 -0700 | [diff] [blame] | 3967 | weston_view_create(surface); |
Kristian Høgsberg | 730c94d | 2012-06-26 21:44:35 -0400 | [diff] [blame] | 3968 | surface->configure = lock_surface_configure; |
Giulio Camuffo | 7fe01b1 | 2013-03-28 18:02:42 +0100 | [diff] [blame] | 3969 | surface->configure_private = shell; |
Pekka Paalanen | f0fc70d | 2011-11-15 13:34:54 +0200 | [diff] [blame] | 3970 | } |
| 3971 | |
| 3972 | static void |
Tiago Vignatti | be14326 | 2012-04-16 17:31:41 +0300 | [diff] [blame] | 3973 | resume_desktop(struct desktop_shell *shell) |
Pekka Paalanen | f0fc70d | 2011-11-15 13:34:54 +0200 | [diff] [blame] | 3974 | { |
Kristian Høgsberg | 4476aaf | 2012-06-25 14:03:13 -0400 | [diff] [blame] | 3975 | struct workspace *ws = get_current_workspace(shell); |
Pekka Paalanen | 77346a6 | 2011-11-30 16:26:35 +0200 | [diff] [blame] | 3976 | |
Pekka Paalanen | 77346a6 | 2011-11-30 16:26:35 +0200 | [diff] [blame] | 3977 | terminate_screensaver(shell); |
Pekka Paalanen | f0fc70d | 2011-11-15 13:34:54 +0200 | [diff] [blame] | 3978 | |
Kristian Høgsberg | 3be2ce9 | 2012-02-29 12:42:35 -0500 | [diff] [blame] | 3979 | wl_list_remove(&shell->lock_layer.link); |
Philipp Brüschweiler | 711fda8 | 2012-08-09 18:50:43 +0200 | [diff] [blame] | 3980 | if (shell->showing_input_panels) { |
Manuel Bachmann | 805d2f5 | 2014-03-05 12:21:34 +0100 | [diff] [blame] | 3981 | wl_list_insert(&shell->compositor->cursor_layer.link, |
Philipp Brüschweiler | 711fda8 | 2012-08-09 18:50:43 +0200 | [diff] [blame] | 3982 | &shell->input_panel_layer.link); |
| 3983 | wl_list_insert(&shell->input_panel_layer.link, |
Manuel Bachmann | 805d2f5 | 2014-03-05 12:21:34 +0100 | [diff] [blame] | 3984 | &shell->fullscreen_layer.link); |
Philipp Brüschweiler | 711fda8 | 2012-08-09 18:50:43 +0200 | [diff] [blame] | 3985 | } else { |
Manuel Bachmann | 805d2f5 | 2014-03-05 12:21:34 +0100 | [diff] [blame] | 3986 | wl_list_insert(&shell->compositor->cursor_layer.link, |
| 3987 | &shell->fullscreen_layer.link); |
Philipp Brüschweiler | 711fda8 | 2012-08-09 18:50:43 +0200 | [diff] [blame] | 3988 | } |
Manuel Bachmann | 805d2f5 | 2014-03-05 12:21:34 +0100 | [diff] [blame] | 3989 | wl_list_insert(&shell->fullscreen_layer.link, |
| 3990 | &shell->panel_layer.link); |
| 3991 | wl_list_insert(&shell->panel_layer.link, |
| 3992 | &ws->layer.link), |
Pekka Paalanen | f0fc70d | 2011-11-15 13:34:54 +0200 | [diff] [blame] | 3993 | |
Kristian Høgsberg | 2f5faff | 2012-07-31 16:36:34 -0400 | [diff] [blame] | 3994 | restore_focus_state(shell, get_current_workspace(shell)); |
Jonas Ådahl | 0476974 | 2012-06-13 00:01:24 +0200 | [diff] [blame] | 3995 | |
Pekka Paalanen | f0fc70d | 2011-11-15 13:34:54 +0200 | [diff] [blame] | 3996 | shell->locked = false; |
Ander Conselvan de Oliveira | 87524b6 | 2013-02-21 18:35:22 +0200 | [diff] [blame] | 3997 | shell_fade(shell, FADE_IN); |
Pekka Paalanen | fc6d91a | 2012-02-10 15:33:10 +0200 | [diff] [blame] | 3998 | weston_compositor_damage_all(shell->compositor); |
Pekka Paalanen | 9ef3e01 | 2011-11-15 13:34:48 +0200 | [diff] [blame] | 3999 | } |
| 4000 | |
| 4001 | static void |
| 4002 | desktop_shell_unlock(struct wl_client *client, |
| 4003 | struct wl_resource *resource) |
| 4004 | { |
Jason Ekstrand | 651f00e | 2013-06-14 10:07:54 -0500 | [diff] [blame] | 4005 | struct desktop_shell *shell = wl_resource_get_user_data(resource); |
Pekka Paalanen | 9ef3e01 | 2011-11-15 13:34:48 +0200 | [diff] [blame] | 4006 | |
Pekka Paalanen | 9ef3e01 | 2011-11-15 13:34:48 +0200 | [diff] [blame] | 4007 | shell->prepare_event_sent = false; |
Pekka Paalanen | f0fc70d | 2011-11-15 13:34:54 +0200 | [diff] [blame] | 4008 | |
| 4009 | if (shell->locked) |
| 4010 | resume_desktop(shell); |
Pekka Paalanen | 9ef3e01 | 2011-11-15 13:34:48 +0200 | [diff] [blame] | 4011 | } |
| 4012 | |
Kristian Høgsberg | d56bd90 | 2012-06-05 09:58:51 -0400 | [diff] [blame] | 4013 | static void |
Ander Conselvan de Oliveira | b9d2a0f | 2012-06-28 18:08:05 +0300 | [diff] [blame] | 4014 | desktop_shell_set_grab_surface(struct wl_client *client, |
Kristian Høgsberg | d56bd90 | 2012-06-05 09:58:51 -0400 | [diff] [blame] | 4015 | struct wl_resource *resource, |
| 4016 | struct wl_resource *surface_resource) |
| 4017 | { |
Jason Ekstrand | 651f00e | 2013-06-14 10:07:54 -0500 | [diff] [blame] | 4018 | struct desktop_shell *shell = wl_resource_get_user_data(resource); |
Kristian Høgsberg | d56bd90 | 2012-06-05 09:58:51 -0400 | [diff] [blame] | 4019 | |
Jason Ekstrand | 0f2ef7e | 2013-06-14 10:07:53 -0500 | [diff] [blame] | 4020 | shell->grab_surface = wl_resource_get_user_data(surface_resource); |
Kristian Høgsberg | 48588f8 | 2013-10-24 15:51:35 -0700 | [diff] [blame] | 4021 | weston_view_create(shell->grab_surface); |
Kristian Høgsberg | d56bd90 | 2012-06-05 09:58:51 -0400 | [diff] [blame] | 4022 | } |
| 4023 | |
Pekka Paalanen | 79346ab | 2013-05-22 18:03:09 +0300 | [diff] [blame] | 4024 | static void |
| 4025 | desktop_shell_desktop_ready(struct wl_client *client, |
| 4026 | struct wl_resource *resource) |
| 4027 | { |
Jason Ekstrand | 651f00e | 2013-06-14 10:07:54 -0500 | [diff] [blame] | 4028 | struct desktop_shell *shell = wl_resource_get_user_data(resource); |
Pekka Paalanen | 79346ab | 2013-05-22 18:03:09 +0300 | [diff] [blame] | 4029 | |
| 4030 | shell_fade_startup(shell); |
| 4031 | } |
| 4032 | |
Kristian Høgsberg | 7584062 | 2011-09-06 13:48:16 -0400 | [diff] [blame] | 4033 | static const struct desktop_shell_interface desktop_shell_implementation = { |
| 4034 | desktop_shell_set_background, |
Pekka Paalanen | 9ef3e01 | 2011-11-15 13:34:48 +0200 | [diff] [blame] | 4035 | desktop_shell_set_panel, |
| 4036 | desktop_shell_set_lock_surface, |
Kristian Høgsberg | d56bd90 | 2012-06-05 09:58:51 -0400 | [diff] [blame] | 4037 | desktop_shell_unlock, |
Pekka Paalanen | 79346ab | 2013-05-22 18:03:09 +0300 | [diff] [blame] | 4038 | desktop_shell_set_grab_surface, |
| 4039 | desktop_shell_desktop_ready |
Kristian Høgsberg | 7584062 | 2011-09-06 13:48:16 -0400 | [diff] [blame] | 4040 | }; |
| 4041 | |
Pekka Paalanen | 92a0dc4 | 2011-11-28 15:34:13 +0200 | [diff] [blame] | 4042 | static enum shell_surface_type |
Kristian Høgsberg | 8334bc1 | 2012-01-03 10:29:47 -0500 | [diff] [blame] | 4043 | get_shell_surface_type(struct weston_surface *surface) |
Pekka Paalanen | 92a0dc4 | 2011-11-28 15:34:13 +0200 | [diff] [blame] | 4044 | { |
| 4045 | struct shell_surface *shsurf; |
| 4046 | |
| 4047 | shsurf = get_shell_surface(surface); |
| 4048 | if (!shsurf) |
Pekka Paalanen | 9826223 | 2011-12-01 10:42:22 +0200 | [diff] [blame] | 4049 | return SHELL_SURFACE_NONE; |
Pekka Paalanen | 92a0dc4 | 2011-11-28 15:34:13 +0200 | [diff] [blame] | 4050 | return shsurf->type; |
| 4051 | } |
| 4052 | |
Kristian Høgsberg | 7584062 | 2011-09-06 13:48:16 -0400 | [diff] [blame] | 4053 | static void |
Kristian Høgsberg | e314875 | 2013-05-06 23:19:49 -0400 | [diff] [blame] | 4054 | 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] | 4055 | { |
Rafal Mielniczuk | b2917a2 | 2014-01-05 20:04:59 +0100 | [diff] [blame] | 4056 | struct weston_surface *focus; |
Pekka Paalanen | 01388e2 | 2013-04-25 13:57:44 +0300 | [diff] [blame] | 4057 | struct weston_surface *surface; |
Kristian Høgsberg | 938b8fa | 2012-05-18 13:46:27 -0400 | [diff] [blame] | 4058 | struct shell_surface *shsurf; |
Kristian Høgsberg | d2abb83 | 2011-11-23 10:52:40 -0500 | [diff] [blame] | 4059 | |
Rafal Mielniczuk | b2917a2 | 2014-01-05 20:04:59 +0100 | [diff] [blame] | 4060 | if (seat->pointer->focus == NULL) |
| 4061 | return; |
| 4062 | |
| 4063 | focus = seat->pointer->focus->surface; |
| 4064 | |
Pekka Paalanen | 01388e2 | 2013-04-25 13:57:44 +0300 | [diff] [blame] | 4065 | surface = weston_surface_get_main_surface(focus); |
Benjamin Franzke | d0f79ab | 2011-11-22 12:43:52 +0100 | [diff] [blame] | 4066 | if (surface == NULL) |
| 4067 | return; |
Kristian Høgsberg | 0793756 | 2011-04-12 17:25:42 -0400 | [diff] [blame] | 4068 | |
Kristian Høgsberg | 938b8fa | 2012-05-18 13:46:27 -0400 | [diff] [blame] | 4069 | shsurf = get_shell_surface(surface); |
Rafael Antognolli | 03b1659 | 2013-12-03 15:35:42 -0200 | [diff] [blame] | 4070 | if (shsurf == NULL || shsurf->state.fullscreen || |
| 4071 | shsurf->state.maximized) |
Kristian Høgsberg | 938b8fa | 2012-05-18 13:46:27 -0400 | [diff] [blame] | 4072 | return; |
| 4073 | |
Kristian Høgsberg | ae356ae | 2014-04-29 16:03:54 -0700 | [diff] [blame] | 4074 | surface_move(shsurf, (struct weston_seat *) seat, 0); |
Kristian Høgsberg | 0793756 | 2011-04-12 17:25:42 -0400 | [diff] [blame] | 4075 | } |
| 4076 | |
| 4077 | static void |
Rafael Antognolli | ea997ac | 2013-12-03 15:35:48 -0200 | [diff] [blame] | 4078 | maximize_binding(struct weston_seat *seat, uint32_t time, uint32_t button, void *data) |
| 4079 | { |
Emilio Pozuelo Monfort | 38b58eb | 2014-01-29 11:11:12 +0100 | [diff] [blame] | 4080 | struct weston_surface *focus = seat->keyboard->focus; |
Rafael Antognolli | ea997ac | 2013-12-03 15:35:48 -0200 | [diff] [blame] | 4081 | struct weston_surface *surface; |
| 4082 | struct shell_surface *shsurf; |
Kristian Høgsberg | 283bf37 | 2014-02-18 23:28:09 -0800 | [diff] [blame] | 4083 | uint32_t serial; |
Rafael Antognolli | ea997ac | 2013-12-03 15:35:48 -0200 | [diff] [blame] | 4084 | |
| 4085 | surface = weston_surface_get_main_surface(focus); |
| 4086 | if (surface == NULL) |
| 4087 | return; |
| 4088 | |
| 4089 | shsurf = get_shell_surface(surface); |
| 4090 | if (shsurf == NULL) |
| 4091 | return; |
| 4092 | |
| 4093 | if (!shell_surface_is_xdg_surface(shsurf)) |
| 4094 | return; |
| 4095 | |
Kristian Høgsberg | 283bf37 | 2014-02-18 23:28:09 -0800 | [diff] [blame] | 4096 | serial = wl_display_next_serial(seat->compositor->wl_display); |
| 4097 | xdg_surface_change_state(shsurf, XDG_SURFACE_STATE_MAXIMIZED, |
| 4098 | !shsurf->state.maximized, serial); |
Rafael Antognolli | ea997ac | 2013-12-03 15:35:48 -0200 | [diff] [blame] | 4099 | } |
| 4100 | |
| 4101 | static void |
| 4102 | fullscreen_binding(struct weston_seat *seat, uint32_t time, uint32_t button, void *data) |
| 4103 | { |
Emilio Pozuelo Monfort | 38b58eb | 2014-01-29 11:11:12 +0100 | [diff] [blame] | 4104 | struct weston_surface *focus = seat->keyboard->focus; |
Rafael Antognolli | ea997ac | 2013-12-03 15:35:48 -0200 | [diff] [blame] | 4105 | struct weston_surface *surface; |
| 4106 | struct shell_surface *shsurf; |
Kristian Høgsberg | 283bf37 | 2014-02-18 23:28:09 -0800 | [diff] [blame] | 4107 | uint32_t serial; |
Rafael Antognolli | ea997ac | 2013-12-03 15:35:48 -0200 | [diff] [blame] | 4108 | |
| 4109 | surface = weston_surface_get_main_surface(focus); |
| 4110 | if (surface == NULL) |
| 4111 | return; |
| 4112 | |
| 4113 | shsurf = get_shell_surface(surface); |
| 4114 | if (shsurf == NULL) |
| 4115 | return; |
| 4116 | |
| 4117 | if (!shell_surface_is_xdg_surface(shsurf)) |
| 4118 | return; |
| 4119 | |
Kristian Høgsberg | 283bf37 | 2014-02-18 23:28:09 -0800 | [diff] [blame] | 4120 | serial = wl_display_next_serial(seat->compositor->wl_display); |
| 4121 | xdg_surface_change_state(shsurf, XDG_SURFACE_STATE_FULLSCREEN, |
| 4122 | !shsurf->state.fullscreen, serial); |
Rafael Antognolli | ea997ac | 2013-12-03 15:35:48 -0200 | [diff] [blame] | 4123 | } |
| 4124 | |
| 4125 | static void |
Neil Roberts | aba0f25 | 2013-10-03 16:43:05 +0100 | [diff] [blame] | 4126 | touch_move_binding(struct weston_seat *seat, uint32_t time, void *data) |
| 4127 | { |
Kristian Høgsberg | 7ab139c | 2013-10-24 16:21:39 -0700 | [diff] [blame] | 4128 | struct weston_surface *focus = seat->touch->focus->surface; |
Neil Roberts | aba0f25 | 2013-10-03 16:43:05 +0100 | [diff] [blame] | 4129 | struct weston_surface *surface; |
| 4130 | struct shell_surface *shsurf; |
| 4131 | |
| 4132 | surface = weston_surface_get_main_surface(focus); |
| 4133 | if (surface == NULL) |
| 4134 | return; |
| 4135 | |
| 4136 | shsurf = get_shell_surface(surface); |
Rafael Antognolli | 03b1659 | 2013-12-03 15:35:42 -0200 | [diff] [blame] | 4137 | if (shsurf == NULL || shsurf->state.fullscreen || |
| 4138 | shsurf->state.maximized) |
Neil Roberts | aba0f25 | 2013-10-03 16:43:05 +0100 | [diff] [blame] | 4139 | return; |
| 4140 | |
| 4141 | surface_touch_move(shsurf, (struct weston_seat *) seat); |
| 4142 | } |
| 4143 | |
| 4144 | static void |
Kristian Høgsberg | e314875 | 2013-05-06 23:19:49 -0400 | [diff] [blame] | 4145 | 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] | 4146 | { |
Rafal Mielniczuk | b2917a2 | 2014-01-05 20:04:59 +0100 | [diff] [blame] | 4147 | struct weston_surface *focus; |
Pekka Paalanen | 01388e2 | 2013-04-25 13:57:44 +0300 | [diff] [blame] | 4148 | struct weston_surface *surface; |
Kristian Høgsberg | 0793756 | 2011-04-12 17:25:42 -0400 | [diff] [blame] | 4149 | uint32_t edges = 0; |
| 4150 | int32_t x, y; |
Pekka Paalanen | 9d1613e | 2011-11-25 12:09:16 +0200 | [diff] [blame] | 4151 | struct shell_surface *shsurf; |
Kristian Høgsberg | d2abb83 | 2011-11-23 10:52:40 -0500 | [diff] [blame] | 4152 | |
Rafal Mielniczuk | b2917a2 | 2014-01-05 20:04:59 +0100 | [diff] [blame] | 4153 | if (seat->pointer->focus == NULL) |
| 4154 | return; |
| 4155 | |
| 4156 | focus = seat->pointer->focus->surface; |
| 4157 | |
Pekka Paalanen | 01388e2 | 2013-04-25 13:57:44 +0300 | [diff] [blame] | 4158 | surface = weston_surface_get_main_surface(focus); |
Benjamin Franzke | d0f79ab | 2011-11-22 12:43:52 +0100 | [diff] [blame] | 4159 | if (surface == NULL) |
| 4160 | return; |
Pekka Paalanen | 92a0dc4 | 2011-11-28 15:34:13 +0200 | [diff] [blame] | 4161 | |
Pekka Paalanen | 9d1613e | 2011-11-25 12:09:16 +0200 | [diff] [blame] | 4162 | shsurf = get_shell_surface(surface); |
Rafael Antognolli | 03b1659 | 2013-12-03 15:35:42 -0200 | [diff] [blame] | 4163 | if (shsurf == NULL || shsurf->state.fullscreen || |
| 4164 | shsurf->state.maximized) |
Pekka Paalanen | 92a0dc4 | 2011-11-28 15:34:13 +0200 | [diff] [blame] | 4165 | return; |
| 4166 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 4167 | weston_view_from_global(shsurf->view, |
| 4168 | wl_fixed_to_int(seat->pointer->grab_x), |
| 4169 | wl_fixed_to_int(seat->pointer->grab_y), |
| 4170 | &x, &y); |
Kristian Høgsberg | 0793756 | 2011-04-12 17:25:42 -0400 | [diff] [blame] | 4171 | |
Jason Ekstrand | 918f2dd | 2013-12-02 21:01:53 -0600 | [diff] [blame] | 4172 | if (x < shsurf->surface->width / 3) |
Pekka Paalanen | 9d1613e | 2011-11-25 12:09:16 +0200 | [diff] [blame] | 4173 | edges |= WL_SHELL_SURFACE_RESIZE_LEFT; |
Jason Ekstrand | 918f2dd | 2013-12-02 21:01:53 -0600 | [diff] [blame] | 4174 | else if (x < 2 * shsurf->surface->width / 3) |
Kristian Høgsberg | 0793756 | 2011-04-12 17:25:42 -0400 | [diff] [blame] | 4175 | edges |= 0; |
| 4176 | else |
Pekka Paalanen | 9d1613e | 2011-11-25 12:09:16 +0200 | [diff] [blame] | 4177 | edges |= WL_SHELL_SURFACE_RESIZE_RIGHT; |
Kristian Høgsberg | 0793756 | 2011-04-12 17:25:42 -0400 | [diff] [blame] | 4178 | |
Jason Ekstrand | 918f2dd | 2013-12-02 21:01:53 -0600 | [diff] [blame] | 4179 | if (y < shsurf->surface->height / 3) |
Pekka Paalanen | 9d1613e | 2011-11-25 12:09:16 +0200 | [diff] [blame] | 4180 | edges |= WL_SHELL_SURFACE_RESIZE_TOP; |
Jason Ekstrand | 918f2dd | 2013-12-02 21:01:53 -0600 | [diff] [blame] | 4181 | else if (y < 2 * shsurf->surface->height / 3) |
Kristian Høgsberg | 0793756 | 2011-04-12 17:25:42 -0400 | [diff] [blame] | 4182 | edges |= 0; |
| 4183 | else |
Pekka Paalanen | 9d1613e | 2011-11-25 12:09:16 +0200 | [diff] [blame] | 4184 | edges |= WL_SHELL_SURFACE_RESIZE_BOTTOM; |
Kristian Høgsberg | 0793756 | 2011-04-12 17:25:42 -0400 | [diff] [blame] | 4185 | |
Kristian Høgsberg | c1693f2 | 2012-05-22 16:56:23 -0400 | [diff] [blame] | 4186 | surface_resize(shsurf, (struct weston_seat *) seat, edges); |
Kristian Høgsberg | 02ec0a5 | 2011-04-23 13:04:11 -0400 | [diff] [blame] | 4187 | } |
| 4188 | |
| 4189 | static void |
Kristian Høgsberg | e314875 | 2013-05-06 23:19:49 -0400 | [diff] [blame] | 4190 | 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] | 4191 | wl_fixed_t value, void *data) |
Scott Moreau | a3aa9c9 | 2012-03-22 11:01:03 -0600 | [diff] [blame] | 4192 | { |
Jonas Ådahl | b0b87ba | 2012-09-27 18:40:42 +0200 | [diff] [blame] | 4193 | float step = 0.005; |
Scott Moreau | a3aa9c9 | 2012-03-22 11:01:03 -0600 | [diff] [blame] | 4194 | struct shell_surface *shsurf; |
Kristian Høgsberg | 7ab139c | 2013-10-24 16:21:39 -0700 | [diff] [blame] | 4195 | struct weston_surface *focus = seat->pointer->focus->surface; |
Pekka Paalanen | 01388e2 | 2013-04-25 13:57:44 +0300 | [diff] [blame] | 4196 | struct weston_surface *surface; |
Scott Moreau | a3aa9c9 | 2012-03-22 11:01:03 -0600 | [diff] [blame] | 4197 | |
Pekka Paalanen | 01388e2 | 2013-04-25 13:57:44 +0300 | [diff] [blame] | 4198 | /* XXX: broken for windows containing sub-surfaces */ |
| 4199 | surface = weston_surface_get_main_surface(focus); |
Scott Moreau | a3aa9c9 | 2012-03-22 11:01:03 -0600 | [diff] [blame] | 4200 | if (surface == NULL) |
| 4201 | return; |
| 4202 | |
| 4203 | shsurf = get_shell_surface(surface); |
| 4204 | if (!shsurf) |
| 4205 | return; |
| 4206 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 4207 | shsurf->view->alpha -= wl_fixed_to_double(value) * step; |
Scott Moreau | a3aa9c9 | 2012-03-22 11:01:03 -0600 | [diff] [blame] | 4208 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 4209 | if (shsurf->view->alpha > 1.0) |
| 4210 | shsurf->view->alpha = 1.0; |
| 4211 | if (shsurf->view->alpha < step) |
| 4212 | shsurf->view->alpha = step; |
Scott Moreau | a3aa9c9 | 2012-03-22 11:01:03 -0600 | [diff] [blame] | 4213 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 4214 | weston_view_geometry_dirty(shsurf->view); |
Scott Moreau | a3aa9c9 | 2012-03-22 11:01:03 -0600 | [diff] [blame] | 4215 | weston_surface_damage(surface); |
| 4216 | } |
| 4217 | |
| 4218 | static void |
Kristian Høgsberg | e314875 | 2013-05-06 23:19:49 -0400 | [diff] [blame] | 4219 | 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] | 4220 | wl_fixed_t value) |
Scott Moreau | ccbf29d | 2012-02-22 14:21:41 -0700 | [diff] [blame] | 4221 | { |
Daniel Stone | 37816df | 2012-05-16 18:45:18 +0100 | [diff] [blame] | 4222 | struct weston_seat *ws = (struct weston_seat *) seat; |
| 4223 | struct weston_compositor *compositor = ws->compositor; |
Scott Moreau | ccbf29d | 2012-02-22 14:21:41 -0700 | [diff] [blame] | 4224 | struct weston_output *output; |
Scott Moreau | e660398 | 2012-06-11 13:07:51 -0600 | [diff] [blame] | 4225 | float increment; |
Scott Moreau | ccbf29d | 2012-02-22 14:21:41 -0700 | [diff] [blame] | 4226 | |
| 4227 | wl_list_for_each(output, &compositor->output_list, link) { |
| 4228 | if (pixman_region32_contains_point(&output->region, |
Daniel Stone | 37816df | 2012-05-16 18:45:18 +0100 | [diff] [blame] | 4229 | wl_fixed_to_double(seat->pointer->x), |
| 4230 | wl_fixed_to_double(seat->pointer->y), |
Daniel Stone | 103db7f | 2012-05-08 17:17:55 +0100 | [diff] [blame] | 4231 | NULL)) { |
Daniel Stone | 325fc2d | 2012-05-30 16:31:58 +0100 | [diff] [blame] | 4232 | if (key == KEY_PAGEUP) |
Kristian Høgsberg | 9b68af0 | 2012-05-22 12:55:18 -0400 | [diff] [blame] | 4233 | increment = output->zoom.increment; |
Daniel Stone | 325fc2d | 2012-05-30 16:31:58 +0100 | [diff] [blame] | 4234 | else if (key == KEY_PAGEDOWN) |
Kristian Høgsberg | 9b68af0 | 2012-05-22 12:55:18 -0400 | [diff] [blame] | 4235 | increment = -output->zoom.increment; |
| 4236 | else if (axis == WL_POINTER_AXIS_VERTICAL_SCROLL) |
Jonas Ådahl | b0b87ba | 2012-09-27 18:40:42 +0200 | [diff] [blame] | 4237 | /* For every pixel zoom 20th of a step */ |
Daniel Stone | 0c1e46e | 2012-05-30 16:31:59 +0100 | [diff] [blame] | 4238 | increment = output->zoom.increment * |
Jonas Ådahl | b0b87ba | 2012-09-27 18:40:42 +0200 | [diff] [blame] | 4239 | -wl_fixed_to_double(value) / 20.0; |
Kristian Høgsberg | 9b68af0 | 2012-05-22 12:55:18 -0400 | [diff] [blame] | 4240 | else |
| 4241 | increment = 0; |
| 4242 | |
Kristian Høgsberg | 9b68af0 | 2012-05-22 12:55:18 -0400 | [diff] [blame] | 4243 | output->zoom.level += increment; |
Scott Moreau | c6d7f60 | 2012-02-23 22:28:37 -0700 | [diff] [blame] | 4244 | |
Scott Moreau | e660398 | 2012-06-11 13:07:51 -0600 | [diff] [blame] | 4245 | if (output->zoom.level < 0.0) |
Scott Moreau | 850ca42 | 2012-05-21 15:21:25 -0600 | [diff] [blame] | 4246 | output->zoom.level = 0.0; |
Scott Moreau | e660398 | 2012-06-11 13:07:51 -0600 | [diff] [blame] | 4247 | else if (output->zoom.level > output->zoom.max_level) |
| 4248 | output->zoom.level = output->zoom.max_level; |
Ville Syrjälä | aa628d0 | 2012-11-16 11:48:47 +0200 | [diff] [blame] | 4249 | else if (!output->zoom.active) { |
Giulio Camuffo | 412b024 | 2013-11-14 23:42:51 +0100 | [diff] [blame] | 4250 | weston_output_activate_zoom(output); |
Kristian Høgsberg | 79af73e | 2012-08-03 15:45:23 -0400 | [diff] [blame] | 4251 | } |
Scott Moreau | ccbf29d | 2012-02-22 14:21:41 -0700 | [diff] [blame] | 4252 | |
Scott Moreau | e660398 | 2012-06-11 13:07:51 -0600 | [diff] [blame] | 4253 | output->zoom.spring_z.target = output->zoom.level; |
Scott Moreau | ccbf29d | 2012-02-22 14:21:41 -0700 | [diff] [blame] | 4254 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 4255 | weston_output_update_zoom(output); |
Scott Moreau | ccbf29d | 2012-02-22 14:21:41 -0700 | [diff] [blame] | 4256 | } |
| 4257 | } |
| 4258 | } |
| 4259 | |
Scott Moreau | ccbf29d | 2012-02-22 14:21:41 -0700 | [diff] [blame] | 4260 | static void |
Kristian Høgsberg | e314875 | 2013-05-06 23:19:49 -0400 | [diff] [blame] | 4261 | 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] | 4262 | wl_fixed_t value, void *data) |
Daniel Stone | 325fc2d | 2012-05-30 16:31:58 +0100 | [diff] [blame] | 4263 | { |
| 4264 | do_zoom(seat, time, 0, axis, value); |
| 4265 | } |
| 4266 | |
| 4267 | static void |
Kristian Høgsberg | e314875 | 2013-05-06 23:19:49 -0400 | [diff] [blame] | 4268 | 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] | 4269 | void *data) |
| 4270 | { |
| 4271 | do_zoom(seat, time, key, 0, 0); |
| 4272 | } |
| 4273 | |
| 4274 | static void |
Kristian Høgsberg | e314875 | 2013-05-06 23:19:49 -0400 | [diff] [blame] | 4275 | terminate_binding(struct weston_seat *seat, uint32_t time, uint32_t key, |
Daniel Stone | 325fc2d | 2012-05-30 16:31:58 +0100 | [diff] [blame] | 4276 | void *data) |
Kristian Høgsberg | e1a850e | 2011-12-19 15:18:05 -0500 | [diff] [blame] | 4277 | { |
Kristian Høgsberg | 8334bc1 | 2012-01-03 10:29:47 -0500 | [diff] [blame] | 4278 | struct weston_compositor *compositor = data; |
Kristian Høgsberg | e1a850e | 2011-12-19 15:18:05 -0500 | [diff] [blame] | 4279 | |
Daniel Stone | 325fc2d | 2012-05-30 16:31:58 +0100 | [diff] [blame] | 4280 | wl_display_terminate(compositor->wl_display); |
Kristian Høgsberg | e1a850e | 2011-12-19 15:18:05 -0500 | [diff] [blame] | 4281 | } |
| 4282 | |
Emilio Pozuelo Monfort | 03251b6 | 2013-11-19 11:37:16 +0100 | [diff] [blame] | 4283 | static void |
Giulio Camuffo | 1959ab8 | 2013-11-14 23:42:52 +0100 | [diff] [blame] | 4284 | rotate_grab_motion(struct weston_pointer_grab *grab, uint32_t time, |
| 4285 | wl_fixed_t x, wl_fixed_t y) |
Pekka Paalanen | 460099f | 2012-01-20 16:48:25 +0200 | [diff] [blame] | 4286 | { |
| 4287 | struct rotate_grab *rotate = |
Ander Conselvan de Oliveira | fe0444a | 2012-04-04 17:48:05 +0300 | [diff] [blame] | 4288 | container_of(grab, struct rotate_grab, base.grab); |
Kristian Høgsberg | 02bbabb | 2013-05-06 22:15:05 -0400 | [diff] [blame] | 4289 | struct weston_pointer *pointer = grab->pointer; |
Ander Conselvan de Oliveira | fe0444a | 2012-04-04 17:48:05 +0300 | [diff] [blame] | 4290 | struct shell_surface *shsurf = rotate->base.shsurf; |
John Kåre Alsaker | 490d02a | 2012-09-30 02:57:21 +0200 | [diff] [blame] | 4291 | float cx, cy, dx, dy, cposx, cposy, dposx, dposy, r; |
Ander Conselvan de Oliveira | fe0444a | 2012-04-04 17:48:05 +0300 | [diff] [blame] | 4292 | |
Giulio Camuffo | 1959ab8 | 2013-11-14 23:42:52 +0100 | [diff] [blame] | 4293 | weston_pointer_move(pointer, x, y); |
| 4294 | |
Ander Conselvan de Oliveira | fe0444a | 2012-04-04 17:48:05 +0300 | [diff] [blame] | 4295 | if (!shsurf) |
| 4296 | return; |
| 4297 | |
Jason Ekstrand | 918f2dd | 2013-12-02 21:01:53 -0600 | [diff] [blame] | 4298 | cx = 0.5f * shsurf->surface->width; |
| 4299 | cy = 0.5f * shsurf->surface->height; |
Pekka Paalanen | 460099f | 2012-01-20 16:48:25 +0200 | [diff] [blame] | 4300 | |
Daniel Stone | 37816df | 2012-05-16 18:45:18 +0100 | [diff] [blame] | 4301 | dx = wl_fixed_to_double(pointer->x) - rotate->center.x; |
| 4302 | dy = wl_fixed_to_double(pointer->y) - rotate->center.y; |
Pekka Paalanen | 460099f | 2012-01-20 16:48:25 +0200 | [diff] [blame] | 4303 | r = sqrtf(dx * dx + dy * dy); |
| 4304 | |
Ander Conselvan de Oliveira | fe0444a | 2012-04-04 17:48:05 +0300 | [diff] [blame] | 4305 | wl_list_remove(&shsurf->rotation.transform.link); |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 4306 | weston_view_geometry_dirty(shsurf->view); |
Pekka Paalanen | 460099f | 2012-01-20 16:48:25 +0200 | [diff] [blame] | 4307 | |
| 4308 | if (r > 20.0f) { |
Pekka Paalanen | 460099f | 2012-01-20 16:48:25 +0200 | [diff] [blame] | 4309 | struct weston_matrix *matrix = |
Ander Conselvan de Oliveira | fe0444a | 2012-04-04 17:48:05 +0300 | [diff] [blame] | 4310 | &shsurf->rotation.transform.matrix; |
Pekka Paalanen | 460099f | 2012-01-20 16:48:25 +0200 | [diff] [blame] | 4311 | |
Kristian Høgsberg | 765e27b | 2012-01-27 13:36:13 -0500 | [diff] [blame] | 4312 | weston_matrix_init(&rotate->rotation); |
Vasily Khoruzhick | 1bbf372 | 2013-01-28 22:40:28 +0300 | [diff] [blame] | 4313 | weston_matrix_rotate_xy(&rotate->rotation, dx / r, dy / r); |
Pekka Paalanen | 460099f | 2012-01-20 16:48:25 +0200 | [diff] [blame] | 4314 | |
| 4315 | weston_matrix_init(matrix); |
Pekka Paalanen | 7b3bd3d | 2012-01-30 14:16:34 +0200 | [diff] [blame] | 4316 | weston_matrix_translate(matrix, -cx, -cy, 0.0f); |
Ander Conselvan de Oliveira | fe0444a | 2012-04-04 17:48:05 +0300 | [diff] [blame] | 4317 | weston_matrix_multiply(matrix, &shsurf->rotation.rotation); |
Kristian Høgsberg | 765e27b | 2012-01-27 13:36:13 -0500 | [diff] [blame] | 4318 | weston_matrix_multiply(matrix, &rotate->rotation); |
Pekka Paalanen | 7b3bd3d | 2012-01-30 14:16:34 +0200 | [diff] [blame] | 4319 | weston_matrix_translate(matrix, cx, cy, 0.0f); |
Pekka Paalanen | 460099f | 2012-01-20 16:48:25 +0200 | [diff] [blame] | 4320 | |
Pekka Paalanen | bc0b7e7 | 2012-01-24 09:53:37 +0200 | [diff] [blame] | 4321 | wl_list_insert( |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 4322 | &shsurf->view->geometry.transformation_list, |
Ander Conselvan de Oliveira | fe0444a | 2012-04-04 17:48:05 +0300 | [diff] [blame] | 4323 | &shsurf->rotation.transform.link); |
Pekka Paalanen | 460099f | 2012-01-20 16:48:25 +0200 | [diff] [blame] | 4324 | } else { |
Ander Conselvan de Oliveira | fe0444a | 2012-04-04 17:48:05 +0300 | [diff] [blame] | 4325 | wl_list_init(&shsurf->rotation.transform.link); |
| 4326 | weston_matrix_init(&shsurf->rotation.rotation); |
Kristian Høgsberg | 765e27b | 2012-01-27 13:36:13 -0500 | [diff] [blame] | 4327 | weston_matrix_init(&rotate->rotation); |
Pekka Paalanen | 460099f | 2012-01-20 16:48:25 +0200 | [diff] [blame] | 4328 | } |
Pekka Paalanen | b45ac5e | 2012-02-09 15:58:44 +0200 | [diff] [blame] | 4329 | |
Rafal Mielniczuk | 2d7ab82 | 2012-03-22 22:22:04 +0100 | [diff] [blame] | 4330 | /* We need to adjust the position of the surface |
| 4331 | * in case it was resized in a rotated state before */ |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 4332 | cposx = shsurf->view->geometry.x + cx; |
| 4333 | cposy = shsurf->view->geometry.y + cy; |
Rafal Mielniczuk | 2d7ab82 | 2012-03-22 22:22:04 +0100 | [diff] [blame] | 4334 | dposx = rotate->center.x - cposx; |
| 4335 | dposy = rotate->center.y - cposy; |
| 4336 | if (dposx != 0.0f || dposy != 0.0f) { |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 4337 | weston_view_set_position(shsurf->view, |
| 4338 | shsurf->view->geometry.x + dposx, |
| 4339 | shsurf->view->geometry.y + dposy); |
Rafal Mielniczuk | 2d7ab82 | 2012-03-22 22:22:04 +0100 | [diff] [blame] | 4340 | } |
| 4341 | |
Pekka Paalanen | b45ac5e | 2012-02-09 15:58:44 +0200 | [diff] [blame] | 4342 | /* Repaint implies weston_surface_update_transform(), which |
| 4343 | * lazily applies the damage due to rotation update. |
| 4344 | */ |
Ander Conselvan de Oliveira | fe0444a | 2012-04-04 17:48:05 +0300 | [diff] [blame] | 4345 | weston_compositor_schedule_repaint(shsurf->surface->compositor); |
Pekka Paalanen | 460099f | 2012-01-20 16:48:25 +0200 | [diff] [blame] | 4346 | } |
| 4347 | |
| 4348 | static void |
Kristian Høgsberg | 02bbabb | 2013-05-06 22:15:05 -0400 | [diff] [blame] | 4349 | rotate_grab_button(struct weston_pointer_grab *grab, |
| 4350 | uint32_t time, uint32_t button, uint32_t state_w) |
Pekka Paalanen | 460099f | 2012-01-20 16:48:25 +0200 | [diff] [blame] | 4351 | { |
| 4352 | struct rotate_grab *rotate = |
Ander Conselvan de Oliveira | fe0444a | 2012-04-04 17:48:05 +0300 | [diff] [blame] | 4353 | container_of(grab, struct rotate_grab, base.grab); |
Kristian Høgsberg | 02bbabb | 2013-05-06 22:15:05 -0400 | [diff] [blame] | 4354 | struct weston_pointer *pointer = grab->pointer; |
Ander Conselvan de Oliveira | fe0444a | 2012-04-04 17:48:05 +0300 | [diff] [blame] | 4355 | struct shell_surface *shsurf = rotate->base.shsurf; |
Daniel Stone | 4dbadb1 | 2012-05-30 16:31:51 +0100 | [diff] [blame] | 4356 | enum wl_pointer_button_state state = state_w; |
Pekka Paalanen | 460099f | 2012-01-20 16:48:25 +0200 | [diff] [blame] | 4357 | |
Daniel Stone | 4dbadb1 | 2012-05-30 16:31:51 +0100 | [diff] [blame] | 4358 | if (pointer->button_count == 0 && |
| 4359 | state == WL_POINTER_BUTTON_STATE_RELEASED) { |
Ander Conselvan de Oliveira | fe0444a | 2012-04-04 17:48:05 +0300 | [diff] [blame] | 4360 | if (shsurf) |
| 4361 | weston_matrix_multiply(&shsurf->rotation.rotation, |
| 4362 | &rotate->rotation); |
Ander Conselvan de Oliveira | b9d2a0f | 2012-06-28 18:08:05 +0300 | [diff] [blame] | 4363 | shell_grab_end(&rotate->base); |
Pekka Paalanen | 460099f | 2012-01-20 16:48:25 +0200 | [diff] [blame] | 4364 | free(rotate); |
| 4365 | } |
| 4366 | } |
| 4367 | |
Jonas Ådahl | 1ea343e | 2013-10-25 23:18:05 +0200 | [diff] [blame] | 4368 | static void |
| 4369 | rotate_grab_cancel(struct weston_pointer_grab *grab) |
| 4370 | { |
| 4371 | struct rotate_grab *rotate = |
| 4372 | container_of(grab, struct rotate_grab, base.grab); |
| 4373 | |
| 4374 | shell_grab_end(&rotate->base); |
| 4375 | free(rotate); |
| 4376 | } |
| 4377 | |
Kristian Høgsberg | 02bbabb | 2013-05-06 22:15:05 -0400 | [diff] [blame] | 4378 | static const struct weston_pointer_grab_interface rotate_grab_interface = { |
Pekka Paalanen | 460099f | 2012-01-20 16:48:25 +0200 | [diff] [blame] | 4379 | noop_grab_focus, |
| 4380 | rotate_grab_motion, |
| 4381 | rotate_grab_button, |
Jonas Ådahl | 1ea343e | 2013-10-25 23:18:05 +0200 | [diff] [blame] | 4382 | rotate_grab_cancel, |
Pekka Paalanen | 460099f | 2012-01-20 16:48:25 +0200 | [diff] [blame] | 4383 | }; |
| 4384 | |
| 4385 | static void |
Kristian Høgsberg | e314875 | 2013-05-06 23:19:49 -0400 | [diff] [blame] | 4386 | surface_rotate(struct shell_surface *surface, struct weston_seat *seat) |
Pekka Paalanen | 460099f | 2012-01-20 16:48:25 +0200 | [diff] [blame] | 4387 | { |
Pekka Paalanen | 460099f | 2012-01-20 16:48:25 +0200 | [diff] [blame] | 4388 | struct rotate_grab *rotate; |
John Kåre Alsaker | 490d02a | 2012-09-30 02:57:21 +0200 | [diff] [blame] | 4389 | float dx, dy; |
| 4390 | float r; |
Pekka Paalanen | 460099f | 2012-01-20 16:48:25 +0200 | [diff] [blame] | 4391 | |
Pekka Paalanen | 460099f | 2012-01-20 16:48:25 +0200 | [diff] [blame] | 4392 | rotate = malloc(sizeof *rotate); |
| 4393 | if (!rotate) |
| 4394 | return; |
| 4395 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 4396 | weston_view_to_global_float(surface->view, |
Jason Ekstrand | 918f2dd | 2013-12-02 21:01:53 -0600 | [diff] [blame] | 4397 | surface->surface->width * 0.5f, |
| 4398 | surface->surface->height * 0.5f, |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 4399 | &rotate->center.x, &rotate->center.y); |
Pekka Paalanen | 460099f | 2012-01-20 16:48:25 +0200 | [diff] [blame] | 4400 | |
Daniel Stone | 37816df | 2012-05-16 18:45:18 +0100 | [diff] [blame] | 4401 | dx = wl_fixed_to_double(seat->pointer->x) - rotate->center.x; |
| 4402 | dy = wl_fixed_to_double(seat->pointer->y) - rotate->center.y; |
Kristian Høgsberg | 765e27b | 2012-01-27 13:36:13 -0500 | [diff] [blame] | 4403 | r = sqrtf(dx * dx + dy * dy); |
| 4404 | if (r > 20.0f) { |
| 4405 | struct weston_matrix inverse; |
| 4406 | |
| 4407 | weston_matrix_init(&inverse); |
Vasily Khoruzhick | 1bbf372 | 2013-01-28 22:40:28 +0300 | [diff] [blame] | 4408 | weston_matrix_rotate_xy(&inverse, dx / r, -dy / r); |
Kristian Høgsberg | 765e27b | 2012-01-27 13:36:13 -0500 | [diff] [blame] | 4409 | weston_matrix_multiply(&surface->rotation.rotation, &inverse); |
Rafal Mielniczuk | 2d7ab82 | 2012-03-22 22:22:04 +0100 | [diff] [blame] | 4410 | |
| 4411 | weston_matrix_init(&rotate->rotation); |
Vasily Khoruzhick | 1bbf372 | 2013-01-28 22:40:28 +0300 | [diff] [blame] | 4412 | weston_matrix_rotate_xy(&rotate->rotation, dx / r, dy / r); |
Kristian Høgsberg | 765e27b | 2012-01-27 13:36:13 -0500 | [diff] [blame] | 4413 | } else { |
| 4414 | weston_matrix_init(&surface->rotation.rotation); |
| 4415 | weston_matrix_init(&rotate->rotation); |
| 4416 | } |
| 4417 | |
Ander Conselvan de Oliveira | b9d2a0f | 2012-06-28 18:08:05 +0300 | [diff] [blame] | 4418 | shell_grab_start(&rotate->base, &rotate_grab_interface, surface, |
| 4419 | seat->pointer, DESKTOP_SHELL_CURSOR_ARROW); |
Pekka Paalanen | 460099f | 2012-01-20 16:48:25 +0200 | [diff] [blame] | 4420 | } |
| 4421 | |
| 4422 | static void |
Kristian Høgsberg | e314875 | 2013-05-06 23:19:49 -0400 | [diff] [blame] | 4423 | 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] | 4424 | void *data) |
| 4425 | { |
Rafal Mielniczuk | b2917a2 | 2014-01-05 20:04:59 +0100 | [diff] [blame] | 4426 | struct weston_surface *focus; |
Pekka Paalanen | 01388e2 | 2013-04-25 13:57:44 +0300 | [diff] [blame] | 4427 | struct weston_surface *base_surface; |
Kristian Høgsberg | 0c36903 | 2013-02-14 21:31:44 -0500 | [diff] [blame] | 4428 | struct shell_surface *surface; |
| 4429 | |
Rafal Mielniczuk | b2917a2 | 2014-01-05 20:04:59 +0100 | [diff] [blame] | 4430 | if (seat->pointer->focus == NULL) |
| 4431 | return; |
| 4432 | |
| 4433 | focus = seat->pointer->focus->surface; |
| 4434 | |
Pekka Paalanen | 01388e2 | 2013-04-25 13:57:44 +0300 | [diff] [blame] | 4435 | base_surface = weston_surface_get_main_surface(focus); |
Kristian Høgsberg | 0c36903 | 2013-02-14 21:31:44 -0500 | [diff] [blame] | 4436 | if (base_surface == NULL) |
| 4437 | return; |
| 4438 | |
| 4439 | surface = get_shell_surface(base_surface); |
Rafael Antognolli | 03b1659 | 2013-12-03 15:35:42 -0200 | [diff] [blame] | 4440 | if (surface == NULL || surface->state.fullscreen || |
| 4441 | surface->state.maximized) |
Kristian Høgsberg | 0c36903 | 2013-02-14 21:31:44 -0500 | [diff] [blame] | 4442 | return; |
| 4443 | |
| 4444 | surface_rotate(surface, seat); |
| 4445 | } |
| 4446 | |
Emilio Pozuelo Monfort | 9e7c759 | 2014-01-30 14:01:10 +0100 | [diff] [blame] | 4447 | /* Move all fullscreen layers down to the current workspace and hide their |
| 4448 | * black views. The surfaces' state is set to both fullscreen and lowered, |
| 4449 | * and this is reversed when such a surface is re-configured, see |
| 4450 | * shell_configure_fullscreen() and shell_ensure_fullscreen_black_view(). |
| 4451 | * |
| 4452 | * This should be used when implementing shell-wide overlays, such as |
Philip Withnall | 83ffd9d | 2013-11-25 18:01:42 +0000 | [diff] [blame] | 4453 | * the alt-tab switcher, which need to de-promote fullscreen layers. */ |
Kristian Høgsberg | 1ef2313 | 2013-12-04 00:20:01 -0800 | [diff] [blame] | 4454 | void |
Kristian Høgsberg | b0d8e77 | 2012-06-18 16:34:58 -0400 | [diff] [blame] | 4455 | lower_fullscreen_layer(struct desktop_shell *shell) |
| 4456 | { |
| 4457 | struct workspace *ws; |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 4458 | struct weston_view *view, *prev; |
Kristian Høgsberg | b0d8e77 | 2012-06-18 16:34:58 -0400 | [diff] [blame] | 4459 | |
| 4460 | ws = get_current_workspace(shell); |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 4461 | wl_list_for_each_reverse_safe(view, prev, |
| 4462 | &shell->fullscreen_layer.view_list, |
Philip Withnall | 83ffd9d | 2013-11-25 18:01:42 +0000 | [diff] [blame] | 4463 | layer_link) { |
Emilio Pozuelo Monfort | 9e7c759 | 2014-01-30 14:01:10 +0100 | [diff] [blame] | 4464 | struct shell_surface *shsurf = get_shell_surface(view->surface); |
| 4465 | |
| 4466 | if (!shsurf) |
| 4467 | continue; |
| 4468 | |
| 4469 | /* We can have a non-fullscreen popup for a fullscreen surface |
| 4470 | * in the fullscreen layer. */ |
| 4471 | if (shsurf->state.fullscreen) { |
| 4472 | /* Hide the black view */ |
| 4473 | wl_list_remove(&shsurf->fullscreen.black_view->layer_link); |
| 4474 | wl_list_init(&shsurf->fullscreen.black_view->layer_link); |
| 4475 | } |
| 4476 | |
| 4477 | /* Lower the view to the workspace layer */ |
Philip Withnall | 83ffd9d | 2013-11-25 18:01:42 +0000 | [diff] [blame] | 4478 | wl_list_remove(&view->layer_link); |
| 4479 | wl_list_insert(&ws->layer.view_list, &view->layer_link); |
| 4480 | weston_view_damage_below(view); |
| 4481 | weston_surface_damage(view->surface); |
Emilio Pozuelo Monfort | 9e7c759 | 2014-01-30 14:01:10 +0100 | [diff] [blame] | 4482 | |
| 4483 | shsurf->state.lowered = true; |
Philip Withnall | 83ffd9d | 2013-11-25 18:01:42 +0000 | [diff] [blame] | 4484 | } |
Kristian Høgsberg | b0d8e77 | 2012-06-18 16:34:58 -0400 | [diff] [blame] | 4485 | } |
| 4486 | |
Kristian Høgsberg | 1ef2313 | 2013-12-04 00:20:01 -0800 | [diff] [blame] | 4487 | void |
Tiago Vignatti | be14326 | 2012-04-16 17:31:41 +0300 | [diff] [blame] | 4488 | activate(struct desktop_shell *shell, struct weston_surface *es, |
Emilio Pozuelo Monfort | 9e7c759 | 2014-01-30 14:01:10 +0100 | [diff] [blame] | 4489 | struct weston_seat *seat, bool configure) |
Kristian Høgsberg | 7584062 | 2011-09-06 13:48:16 -0400 | [diff] [blame] | 4490 | { |
Pekka Paalanen | 01388e2 | 2013-04-25 13:57:44 +0300 | [diff] [blame] | 4491 | struct weston_surface *main_surface; |
Kristian Høgsberg | 2f5faff | 2012-07-31 16:36:34 -0400 | [diff] [blame] | 4492 | struct focus_state *state; |
Jonas Ådahl | 8538b22 | 2012-08-29 22:13:03 +0200 | [diff] [blame] | 4493 | struct workspace *ws; |
Louis-Francis Ratté-Boulianne | b482dbd | 2013-11-19 11:37:11 +0100 | [diff] [blame] | 4494 | struct weston_surface *old_es; |
Rafael Antognolli | 03b1659 | 2013-12-03 15:35:42 -0200 | [diff] [blame] | 4495 | struct shell_surface *shsurf; |
Kristian Høgsberg | 7584062 | 2011-09-06 13:48:16 -0400 | [diff] [blame] | 4496 | |
Kristian Høgsberg | 6110d07 | 2014-04-29 15:15:45 -0700 | [diff] [blame] | 4497 | lower_fullscreen_layer(shell); |
| 4498 | |
Pekka Paalanen | 01388e2 | 2013-04-25 13:57:44 +0300 | [diff] [blame] | 4499 | main_surface = weston_surface_get_main_surface(es); |
| 4500 | |
Daniel Stone | 37816df | 2012-05-16 18:45:18 +0100 | [diff] [blame] | 4501 | weston_surface_activate(es, seat); |
Kristian Høgsberg | 7584062 | 2011-09-06 13:48:16 -0400 | [diff] [blame] | 4502 | |
Jonas Ådahl | 8538b22 | 2012-08-29 22:13:03 +0200 | [diff] [blame] | 4503 | state = ensure_focus_state(shell, seat); |
| 4504 | if (state == NULL) |
| 4505 | return; |
Kristian Høgsberg | 2f5faff | 2012-07-31 16:36:34 -0400 | [diff] [blame] | 4506 | |
Louis-Francis Ratté-Boulianne | b482dbd | 2013-11-19 11:37:11 +0100 | [diff] [blame] | 4507 | old_es = state->keyboard_focus; |
Kristian Høgsberg | d500bf1 | 2014-01-22 12:25:20 -0800 | [diff] [blame] | 4508 | focus_state_set_focus(state, es); |
Kristian Høgsberg | 2f5faff | 2012-07-31 16:36:34 -0400 | [diff] [blame] | 4509 | |
Rafael Antognolli | 03b1659 | 2013-12-03 15:35:42 -0200 | [diff] [blame] | 4510 | shsurf = get_shell_surface(main_surface); |
U. Artie Eoff | cf5737a | 2014-01-17 10:08:25 -0800 | [diff] [blame] | 4511 | assert(shsurf); |
| 4512 | |
Emilio Pozuelo Monfort | 9e7c759 | 2014-01-30 14:01:10 +0100 | [diff] [blame] | 4513 | if (shsurf->state.fullscreen && configure) |
Rafael Antognolli | 03b1659 | 2013-12-03 15:35:42 -0200 | [diff] [blame] | 4514 | shell_configure_fullscreen(shsurf); |
| 4515 | else |
Alexander Larsson | f82b6ca | 2013-05-28 16:23:39 +0200 | [diff] [blame] | 4516 | restore_all_output_modes(shell->compositor); |
Louis-Francis Ratté-Boulianne | b482dbd | 2013-11-19 11:37:11 +0100 | [diff] [blame] | 4517 | |
Emilio Pozuelo Monfort | 7908bff | 2014-01-30 13:49:39 +0100 | [diff] [blame] | 4518 | /* Update the surface’s layer. This brings it to the top of the stacking |
| 4519 | * order as appropriate. */ |
| 4520 | shell_surface_update_layer(shsurf); |
| 4521 | |
Philip Withnall | 83ffd9d | 2013-11-25 18:01:42 +0000 | [diff] [blame] | 4522 | if (shell->focus_animation_type != ANIMATION_NONE) { |
| 4523 | ws = get_current_workspace(shell); |
Louis-Francis Ratté-Boulianne | b482dbd | 2013-11-19 11:37:11 +0100 | [diff] [blame] | 4524 | 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] | 4525 | } |
Kristian Høgsberg | 7584062 | 2011-09-06 13:48:16 -0400 | [diff] [blame] | 4526 | } |
| 4527 | |
Alex Wu | 2185843 | 2012-04-01 20:13:08 +0800 | [diff] [blame] | 4528 | /* no-op func for checking black surface */ |
| 4529 | static void |
Jason Ekstrand | 918f2dd | 2013-12-02 21:01:53 -0600 | [diff] [blame] | 4530 | 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] | 4531 | { |
| 4532 | } |
| 4533 | |
Quentin Glidic | c0d79ce | 2013-01-29 14:16:13 +0100 | [diff] [blame] | 4534 | static bool |
Alex Wu | 2185843 | 2012-04-01 20:13:08 +0800 | [diff] [blame] | 4535 | is_black_surface (struct weston_surface *es, struct weston_surface **fs_surface) |
| 4536 | { |
| 4537 | if (es->configure == black_surface_configure) { |
| 4538 | if (fs_surface) |
Giulio Camuffo | 7fe01b1 | 2013-03-28 18:02:42 +0100 | [diff] [blame] | 4539 | *fs_surface = (struct weston_surface *)es->configure_private; |
Alex Wu | 2185843 | 2012-04-01 20:13:08 +0800 | [diff] [blame] | 4540 | return true; |
| 4541 | } |
| 4542 | return false; |
| 4543 | } |
| 4544 | |
Kristian Høgsberg | 7584062 | 2011-09-06 13:48:16 -0400 | [diff] [blame] | 4545 | static void |
Neil Roberts | a28c693 | 2013-10-03 16:43:04 +0100 | [diff] [blame] | 4546 | activate_binding(struct weston_seat *seat, |
| 4547 | struct desktop_shell *shell, |
| 4548 | struct weston_surface *focus) |
Kristian Høgsberg | e1a850e | 2011-12-19 15:18:05 -0500 | [diff] [blame] | 4549 | { |
Pekka Paalanen | 01388e2 | 2013-04-25 13:57:44 +0300 | [diff] [blame] | 4550 | struct weston_surface *main_surface; |
Kristian Høgsberg | e1a850e | 2011-12-19 15:18:05 -0500 | [diff] [blame] | 4551 | |
Alex Wu | 9c35e6b | 2012-03-05 14:13:13 +0800 | [diff] [blame] | 4552 | if (!focus) |
| 4553 | return; |
| 4554 | |
Pekka Paalanen | 01388e2 | 2013-04-25 13:57:44 +0300 | [diff] [blame] | 4555 | if (is_black_surface(focus, &main_surface)) |
| 4556 | focus = main_surface; |
Alex Wu | 4539b08 | 2012-03-01 12:57:46 +0800 | [diff] [blame] | 4557 | |
Pekka Paalanen | 01388e2 | 2013-04-25 13:57:44 +0300 | [diff] [blame] | 4558 | main_surface = weston_surface_get_main_surface(focus); |
| 4559 | if (get_shell_surface_type(main_surface) == SHELL_SURFACE_NONE) |
Kristian Høgsberg | 0636ac3 | 2012-06-27 10:22:15 -0400 | [diff] [blame] | 4560 | return; |
Kristian Høgsberg | 85b2e4b | 2012-06-21 16:49:42 -0400 | [diff] [blame] | 4561 | |
Emilio Pozuelo Monfort | 9e7c759 | 2014-01-30 14:01:10 +0100 | [diff] [blame] | 4562 | activate(shell, focus, seat, true); |
Neil Roberts | a28c693 | 2013-10-03 16:43:04 +0100 | [diff] [blame] | 4563 | } |
| 4564 | |
| 4565 | static void |
| 4566 | click_to_activate_binding(struct weston_seat *seat, uint32_t time, uint32_t button, |
| 4567 | void *data) |
| 4568 | { |
| 4569 | if (seat->pointer->grab != &seat->pointer->default_grab) |
| 4570 | return; |
Kristian Høgsberg | 7c4f6cc | 2014-01-01 16:28:32 -0800 | [diff] [blame] | 4571 | if (seat->pointer->focus == NULL) |
| 4572 | return; |
Neil Roberts | a28c693 | 2013-10-03 16:43:04 +0100 | [diff] [blame] | 4573 | |
Kristian Høgsberg | 7ab139c | 2013-10-24 16:21:39 -0700 | [diff] [blame] | 4574 | activate_binding(seat, data, seat->pointer->focus->surface); |
Neil Roberts | a28c693 | 2013-10-03 16:43:04 +0100 | [diff] [blame] | 4575 | } |
| 4576 | |
| 4577 | static void |
| 4578 | touch_to_activate_binding(struct weston_seat *seat, uint32_t time, void *data) |
| 4579 | { |
| 4580 | if (seat->touch->grab != &seat->touch->default_grab) |
| 4581 | return; |
Kristian Høgsberg | 0ed6750 | 2014-01-02 23:00:11 -0800 | [diff] [blame] | 4582 | if (seat->touch->focus == NULL) |
| 4583 | return; |
Neil Roberts | a28c693 | 2013-10-03 16:43:04 +0100 | [diff] [blame] | 4584 | |
Kristian Høgsberg | 7ab139c | 2013-10-24 16:21:39 -0700 | [diff] [blame] | 4585 | activate_binding(seat, data, seat->touch->focus->surface); |
Kristian Høgsberg | e1a850e | 2011-12-19 15:18:05 -0500 | [diff] [blame] | 4586 | } |
| 4587 | |
| 4588 | static void |
Neil Roberts | b4a9170 | 2014-04-09 16:33:32 +0100 | [diff] [blame] | 4589 | unfocus_all_seats(struct desktop_shell *shell) |
| 4590 | { |
| 4591 | struct weston_seat *seat, *next; |
| 4592 | |
| 4593 | wl_list_for_each_safe(seat, next, &shell->compositor->seat_list, link) { |
| 4594 | if (seat->keyboard == NULL) |
| 4595 | continue; |
| 4596 | |
| 4597 | weston_keyboard_set_focus(seat->keyboard, NULL); |
| 4598 | } |
| 4599 | } |
| 4600 | |
| 4601 | static void |
Ander Conselvan de Oliveira | 19d10ef | 2013-02-21 18:35:20 +0200 | [diff] [blame] | 4602 | lock(struct desktop_shell *shell) |
Kristian Høgsberg | 02ec0a5 | 2011-04-23 13:04:11 -0400 | [diff] [blame] | 4603 | { |
Kristian Høgsberg | 4476aaf | 2012-06-25 14:03:13 -0400 | [diff] [blame] | 4604 | struct workspace *ws = get_current_workspace(shell); |
Pekka Paalanen | f0fc70d | 2011-11-15 13:34:54 +0200 | [diff] [blame] | 4605 | |
Tiago Vignatti | 8e53c7f | 2012-02-29 19:53:50 +0200 | [diff] [blame] | 4606 | if (shell->locked) { |
Ander Conselvan de Oliveira | 87524b6 | 2013-02-21 18:35:22 +0200 | [diff] [blame] | 4607 | weston_compositor_sleep(shell->compositor); |
Pekka Paalanen | f0fc70d | 2011-11-15 13:34:54 +0200 | [diff] [blame] | 4608 | return; |
Tiago Vignatti | 8e53c7f | 2012-02-29 19:53:50 +0200 | [diff] [blame] | 4609 | } |
Pekka Paalanen | 9ef3e01 | 2011-11-15 13:34:48 +0200 | [diff] [blame] | 4610 | |
| 4611 | shell->locked = true; |
Pekka Paalanen | f0fc70d | 2011-11-15 13:34:54 +0200 | [diff] [blame] | 4612 | |
Kristian Høgsberg | 3be2ce9 | 2012-02-29 12:42:35 -0500 | [diff] [blame] | 4613 | /* Hide all surfaces by removing the fullscreen, panel and |
| 4614 | * toplevel layers. This way nothing else can show or receive |
| 4615 | * input events while we are locked. */ |
Pekka Paalanen | f0fc70d | 2011-11-15 13:34:54 +0200 | [diff] [blame] | 4616 | |
Kristian Høgsberg | 3be2ce9 | 2012-02-29 12:42:35 -0500 | [diff] [blame] | 4617 | wl_list_remove(&shell->panel_layer.link); |
Kristian Høgsberg | 3be2ce9 | 2012-02-29 12:42:35 -0500 | [diff] [blame] | 4618 | wl_list_remove(&shell->fullscreen_layer.link); |
Philipp Brüschweiler | 711fda8 | 2012-08-09 18:50:43 +0200 | [diff] [blame] | 4619 | if (shell->showing_input_panels) |
| 4620 | wl_list_remove(&shell->input_panel_layer.link); |
Kristian Høgsberg | 4476aaf | 2012-06-25 14:03:13 -0400 | [diff] [blame] | 4621 | wl_list_remove(&ws->layer.link); |
Kristian Høgsberg | 3be2ce9 | 2012-02-29 12:42:35 -0500 | [diff] [blame] | 4622 | wl_list_insert(&shell->compositor->cursor_layer.link, |
| 4623 | &shell->lock_layer.link); |
Pekka Paalanen | f0fc70d | 2011-11-15 13:34:54 +0200 | [diff] [blame] | 4624 | |
Pekka Paalanen | 77346a6 | 2011-11-30 16:26:35 +0200 | [diff] [blame] | 4625 | launch_screensaver(shell); |
| 4626 | |
Neil Roberts | b4a9170 | 2014-04-09 16:33:32 +0100 | [diff] [blame] | 4627 | /* Remove the keyboard focus on all seats. This will be |
| 4628 | * restored to the workspace's saved state via |
| 4629 | * restore_focus_state when the compositor is unlocked */ |
| 4630 | unfocus_all_seats(shell); |
| 4631 | |
Pekka Paalanen | f0fc70d | 2011-11-15 13:34:54 +0200 | [diff] [blame] | 4632 | /* TODO: disable bindings that should not work while locked. */ |
| 4633 | |
| 4634 | /* All this must be undone in resume_desktop(). */ |
Pekka Paalanen | 9ef3e01 | 2011-11-15 13:34:48 +0200 | [diff] [blame] | 4635 | } |
| 4636 | |
| 4637 | static void |
Ander Conselvan de Oliveira | 19d10ef | 2013-02-21 18:35:20 +0200 | [diff] [blame] | 4638 | unlock(struct desktop_shell *shell) |
Pekka Paalanen | 9ef3e01 | 2011-11-15 13:34:48 +0200 | [diff] [blame] | 4639 | { |
Pekka Paalanen | d81c216 | 2011-11-16 13:47:34 +0200 | [diff] [blame] | 4640 | if (!shell->locked || shell->lock_surface) { |
Ander Conselvan de Oliveira | 87524b6 | 2013-02-21 18:35:22 +0200 | [diff] [blame] | 4641 | shell_fade(shell, FADE_IN); |
Pekka Paalanen | 9ef3e01 | 2011-11-15 13:34:48 +0200 | [diff] [blame] | 4642 | return; |
| 4643 | } |
| 4644 | |
| 4645 | /* If desktop-shell client has gone away, unlock immediately. */ |
| 4646 | if (!shell->child.desktop_shell) { |
Pekka Paalanen | f0fc70d | 2011-11-15 13:34:54 +0200 | [diff] [blame] | 4647 | resume_desktop(shell); |
Pekka Paalanen | 9ef3e01 | 2011-11-15 13:34:48 +0200 | [diff] [blame] | 4648 | return; |
| 4649 | } |
| 4650 | |
| 4651 | if (shell->prepare_event_sent) |
| 4652 | return; |
| 4653 | |
Kristian Høgsberg | 0b5cd0c | 2012-03-04 21:57:37 -0500 | [diff] [blame] | 4654 | desktop_shell_send_prepare_lock_surface(shell->child.desktop_shell); |
Pekka Paalanen | 9ef3e01 | 2011-11-15 13:34:48 +0200 | [diff] [blame] | 4655 | shell->prepare_event_sent = true; |
Kristian Høgsberg | 02ec0a5 | 2011-04-23 13:04:11 -0400 | [diff] [blame] | 4656 | } |
| 4657 | |
| 4658 | static void |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 4659 | shell_fade_done(struct weston_view_animation *animation, void *data) |
Ander Conselvan de Oliveira | 19d10ef | 2013-02-21 18:35:20 +0200 | [diff] [blame] | 4660 | { |
| 4661 | struct desktop_shell *shell = data; |
| 4662 | |
| 4663 | shell->fade.animation = NULL; |
| 4664 | |
| 4665 | switch (shell->fade.type) { |
| 4666 | case FADE_IN: |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 4667 | weston_surface_destroy(shell->fade.view->surface); |
| 4668 | shell->fade.view = NULL; |
Ander Conselvan de Oliveira | 19d10ef | 2013-02-21 18:35:20 +0200 | [diff] [blame] | 4669 | break; |
| 4670 | case FADE_OUT: |
Ander Conselvan de Oliveira | 19d10ef | 2013-02-21 18:35:20 +0200 | [diff] [blame] | 4671 | lock(shell); |
| 4672 | break; |
Philip Withnall | 4a86a0a | 2013-11-25 18:01:32 +0000 | [diff] [blame] | 4673 | default: |
| 4674 | break; |
Ander Conselvan de Oliveira | 19d10ef | 2013-02-21 18:35:20 +0200 | [diff] [blame] | 4675 | } |
| 4676 | } |
| 4677 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 4678 | static struct weston_view * |
Pekka Paalanen | 79346ab | 2013-05-22 18:03:09 +0300 | [diff] [blame] | 4679 | shell_fade_create_surface(struct desktop_shell *shell) |
Ander Conselvan de Oliveira | 19d10ef | 2013-02-21 18:35:20 +0200 | [diff] [blame] | 4680 | { |
| 4681 | struct weston_compositor *compositor = shell->compositor; |
| 4682 | struct weston_surface *surface; |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 4683 | struct weston_view *view; |
Pekka Paalanen | 79346ab | 2013-05-22 18:03:09 +0300 | [diff] [blame] | 4684 | |
| 4685 | surface = weston_surface_create(compositor); |
| 4686 | if (!surface) |
| 4687 | return NULL; |
| 4688 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 4689 | view = weston_view_create(surface); |
| 4690 | if (!view) { |
| 4691 | weston_surface_destroy(surface); |
| 4692 | return NULL; |
| 4693 | } |
| 4694 | |
Jason Ekstrand | 5c11a33 | 2013-12-04 20:32:03 -0600 | [diff] [blame] | 4695 | weston_surface_set_size(surface, 8192, 8192); |
Jason Ekstrand | 918f2dd | 2013-12-02 21:01:53 -0600 | [diff] [blame] | 4696 | weston_view_set_position(view, 0, 0); |
Pekka Paalanen | 79346ab | 2013-05-22 18:03:09 +0300 | [diff] [blame] | 4697 | weston_surface_set_color(surface, 0.0, 0.0, 0.0, 1.0); |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 4698 | wl_list_insert(&compositor->fade_layer.view_list, |
| 4699 | &view->layer_link); |
Pekka Paalanen | 79346ab | 2013-05-22 18:03:09 +0300 | [diff] [blame] | 4700 | pixman_region32_init(&surface->input); |
| 4701 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 4702 | return view; |
Pekka Paalanen | 79346ab | 2013-05-22 18:03:09 +0300 | [diff] [blame] | 4703 | } |
| 4704 | |
| 4705 | static void |
| 4706 | shell_fade(struct desktop_shell *shell, enum fade_type type) |
| 4707 | { |
Ander Conselvan de Oliveira | 19d10ef | 2013-02-21 18:35:20 +0200 | [diff] [blame] | 4708 | float tint; |
| 4709 | |
| 4710 | switch (type) { |
| 4711 | case FADE_IN: |
| 4712 | tint = 0.0; |
| 4713 | break; |
| 4714 | case FADE_OUT: |
| 4715 | tint = 1.0; |
| 4716 | break; |
| 4717 | default: |
| 4718 | weston_log("shell: invalid fade type\n"); |
| 4719 | return; |
| 4720 | } |
| 4721 | |
| 4722 | shell->fade.type = type; |
| 4723 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 4724 | if (shell->fade.view == NULL) { |
| 4725 | shell->fade.view = shell_fade_create_surface(shell); |
| 4726 | if (!shell->fade.view) |
Ander Conselvan de Oliveira | 19d10ef | 2013-02-21 18:35:20 +0200 | [diff] [blame] | 4727 | return; |
| 4728 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 4729 | shell->fade.view->alpha = 1.0 - tint; |
| 4730 | weston_view_update_transform(shell->fade.view); |
Ander Conselvan de Oliveira | 19d10ef | 2013-02-21 18:35:20 +0200 | [diff] [blame] | 4731 | } |
| 4732 | |
Kristian Høgsberg | 87d3b61 | 2014-01-19 21:48:10 -0800 | [diff] [blame] | 4733 | if (shell->fade.view->output == NULL) { |
| 4734 | /* If the black view gets a NULL output, we lost the |
| 4735 | * last output and we'll just cancel the fade. This |
| 4736 | * happens when you close the last window under the |
| 4737 | * X11 or Wayland backends. */ |
| 4738 | shell->locked = false; |
| 4739 | weston_surface_destroy(shell->fade.view->surface); |
| 4740 | shell->fade.view = NULL; |
| 4741 | } else if (shell->fade.animation) { |
Kristian Høgsberg | 5281fb1 | 2013-06-17 10:10:28 -0400 | [diff] [blame] | 4742 | weston_fade_update(shell->fade.animation, tint); |
Kristian Høgsberg | 87d3b61 | 2014-01-19 21:48:10 -0800 | [diff] [blame] | 4743 | } else { |
Ander Conselvan de Oliveira | 19d10ef | 2013-02-21 18:35:20 +0200 | [diff] [blame] | 4744 | shell->fade.animation = |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 4745 | weston_fade_run(shell->fade.view, |
Kristian Høgsberg | 5281fb1 | 2013-06-17 10:10:28 -0400 | [diff] [blame] | 4746 | 1.0 - tint, tint, 300.0, |
Ander Conselvan de Oliveira | 19d10ef | 2013-02-21 18:35:20 +0200 | [diff] [blame] | 4747 | shell_fade_done, shell); |
Kristian Høgsberg | 87d3b61 | 2014-01-19 21:48:10 -0800 | [diff] [blame] | 4748 | } |
Ander Conselvan de Oliveira | 19d10ef | 2013-02-21 18:35:20 +0200 | [diff] [blame] | 4749 | } |
| 4750 | |
| 4751 | static void |
Pekka Paalanen | 79346ab | 2013-05-22 18:03:09 +0300 | [diff] [blame] | 4752 | do_shell_fade_startup(void *data) |
| 4753 | { |
| 4754 | struct desktop_shell *shell = data; |
| 4755 | |
Kristian Høgsberg | 724c8d9 | 2013-10-16 11:38:24 -0700 | [diff] [blame] | 4756 | if (shell->startup_animation_type == ANIMATION_FADE) |
| 4757 | shell_fade(shell, FADE_IN); |
| 4758 | else if (shell->startup_animation_type == ANIMATION_NONE) { |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 4759 | weston_surface_destroy(shell->fade.view->surface); |
| 4760 | shell->fade.view = NULL; |
Kristian Høgsberg | 724c8d9 | 2013-10-16 11:38:24 -0700 | [diff] [blame] | 4761 | } |
Pekka Paalanen | 79346ab | 2013-05-22 18:03:09 +0300 | [diff] [blame] | 4762 | } |
| 4763 | |
| 4764 | static void |
| 4765 | shell_fade_startup(struct desktop_shell *shell) |
| 4766 | { |
| 4767 | struct wl_event_loop *loop; |
| 4768 | |
| 4769 | if (!shell->fade.startup_timer) |
| 4770 | return; |
| 4771 | |
| 4772 | wl_event_source_remove(shell->fade.startup_timer); |
| 4773 | shell->fade.startup_timer = NULL; |
| 4774 | |
| 4775 | loop = wl_display_get_event_loop(shell->compositor->wl_display); |
| 4776 | wl_event_loop_add_idle(loop, do_shell_fade_startup, shell); |
| 4777 | } |
| 4778 | |
| 4779 | static int |
| 4780 | fade_startup_timeout(void *data) |
| 4781 | { |
| 4782 | struct desktop_shell *shell = data; |
| 4783 | |
| 4784 | shell_fade_startup(shell); |
| 4785 | return 0; |
| 4786 | } |
| 4787 | |
| 4788 | static void |
| 4789 | shell_fade_init(struct desktop_shell *shell) |
| 4790 | { |
| 4791 | /* Make compositor output all black, and wait for the desktop-shell |
| 4792 | * client to signal it is ready, then fade in. The timer triggers a |
| 4793 | * fade-in, in case the desktop-shell client takes too long. |
| 4794 | */ |
| 4795 | |
| 4796 | struct wl_event_loop *loop; |
| 4797 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 4798 | if (shell->fade.view != NULL) { |
Pekka Paalanen | 79346ab | 2013-05-22 18:03:09 +0300 | [diff] [blame] | 4799 | weston_log("%s: warning: fade surface already exists\n", |
| 4800 | __func__); |
| 4801 | return; |
| 4802 | } |
| 4803 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 4804 | shell->fade.view = shell_fade_create_surface(shell); |
| 4805 | if (!shell->fade.view) |
Pekka Paalanen | 79346ab | 2013-05-22 18:03:09 +0300 | [diff] [blame] | 4806 | return; |
| 4807 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 4808 | weston_view_update_transform(shell->fade.view); |
| 4809 | weston_surface_damage(shell->fade.view->surface); |
Pekka Paalanen | 79346ab | 2013-05-22 18:03:09 +0300 | [diff] [blame] | 4810 | |
| 4811 | loop = wl_display_get_event_loop(shell->compositor->wl_display); |
| 4812 | shell->fade.startup_timer = |
| 4813 | wl_event_loop_add_timer(loop, fade_startup_timeout, shell); |
| 4814 | wl_event_source_timer_update(shell->fade.startup_timer, 15000); |
| 4815 | } |
| 4816 | |
| 4817 | static void |
Ander Conselvan de Oliveira | a457563 | 2013-02-21 18:35:23 +0200 | [diff] [blame] | 4818 | idle_handler(struct wl_listener *listener, void *data) |
Ander Conselvan de Oliveira | 19d10ef | 2013-02-21 18:35:20 +0200 | [diff] [blame] | 4819 | { |
| 4820 | struct desktop_shell *shell = |
Ander Conselvan de Oliveira | a457563 | 2013-02-21 18:35:23 +0200 | [diff] [blame] | 4821 | container_of(listener, struct desktop_shell, idle_listener); |
Kristian Høgsberg | 27d5fa8 | 2014-01-17 16:22:50 -0800 | [diff] [blame] | 4822 | struct weston_seat *seat; |
| 4823 | |
| 4824 | wl_list_for_each(seat, &shell->compositor->seat_list, link) |
| 4825 | if (seat->pointer) |
| 4826 | popup_grab_end(seat->pointer); |
Ander Conselvan de Oliveira | 19d10ef | 2013-02-21 18:35:20 +0200 | [diff] [blame] | 4827 | |
| 4828 | shell_fade(shell, FADE_OUT); |
| 4829 | /* lock() is called from shell_fade_done() */ |
| 4830 | } |
| 4831 | |
| 4832 | static void |
Ander Conselvan de Oliveira | a457563 | 2013-02-21 18:35:23 +0200 | [diff] [blame] | 4833 | wake_handler(struct wl_listener *listener, void *data) |
Ander Conselvan de Oliveira | 19d10ef | 2013-02-21 18:35:20 +0200 | [diff] [blame] | 4834 | { |
| 4835 | struct desktop_shell *shell = |
Ander Conselvan de Oliveira | a457563 | 2013-02-21 18:35:23 +0200 | [diff] [blame] | 4836 | container_of(listener, struct desktop_shell, wake_listener); |
Ander Conselvan de Oliveira | 19d10ef | 2013-02-21 18:35:20 +0200 | [diff] [blame] | 4837 | |
Ander Conselvan de Oliveira | 19d10ef | 2013-02-21 18:35:20 +0200 | [diff] [blame] | 4838 | unlock(shell); |
| 4839 | } |
| 4840 | |
| 4841 | static void |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 4842 | center_on_output(struct weston_view *view, struct weston_output *output) |
Pekka Paalanen | 77346a6 | 2011-11-30 16:26:35 +0200 | [diff] [blame] | 4843 | { |
Giulio Camuffo | b836664 | 2013-04-25 13:57:46 +0300 | [diff] [blame] | 4844 | int32_t surf_x, surf_y, width, height; |
Ander Conselvan de Oliveira | 012b4c7 | 2012-11-27 17:03:42 +0200 | [diff] [blame] | 4845 | float x, y; |
Pekka Paalanen | 77346a6 | 2011-11-30 16:26:35 +0200 | [diff] [blame] | 4846 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 4847 | surface_subsurfaces_boundingbox(view->surface, &surf_x, &surf_y, &width, &height); |
Giulio Camuffo | b836664 | 2013-04-25 13:57:46 +0300 | [diff] [blame] | 4848 | |
| 4849 | x = output->x + (output->width - width) / 2 - surf_x / 2; |
| 4850 | y = output->y + (output->height - height) / 2 - surf_y / 2; |
Ander Conselvan de Oliveira | 012b4c7 | 2012-11-27 17:03:42 +0200 | [diff] [blame] | 4851 | |
Jason Ekstrand | 918f2dd | 2013-12-02 21:01:53 -0600 | [diff] [blame] | 4852 | weston_view_set_position(view, x, y); |
Pekka Paalanen | 77346a6 | 2011-11-30 16:26:35 +0200 | [diff] [blame] | 4853 | } |
| 4854 | |
| 4855 | static void |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 4856 | weston_view_set_initial_position(struct weston_view *view, |
| 4857 | struct desktop_shell *shell) |
Rob Bradford | ac63e5b | 2012-08-13 14:07:52 +0100 | [diff] [blame] | 4858 | { |
| 4859 | struct weston_compositor *compositor = shell->compositor; |
| 4860 | int ix = 0, iy = 0; |
| 4861 | int range_x, range_y; |
| 4862 | int dx, dy, x, y, panel_height; |
| 4863 | struct weston_output *output, *target_output = NULL; |
| 4864 | struct weston_seat *seat; |
| 4865 | |
| 4866 | /* As a heuristic place the new window on the same output as the |
| 4867 | * pointer. Falling back to the output containing 0, 0. |
| 4868 | * |
| 4869 | * TODO: Do something clever for touch too? |
| 4870 | */ |
| 4871 | wl_list_for_each(seat, &compositor->seat_list, link) { |
Kristian Høgsberg | 2bf8762 | 2013-05-07 23:17:41 -0400 | [diff] [blame] | 4872 | if (seat->pointer) { |
Kristian Høgsberg | e314875 | 2013-05-06 23:19:49 -0400 | [diff] [blame] | 4873 | ix = wl_fixed_to_int(seat->pointer->x); |
| 4874 | iy = wl_fixed_to_int(seat->pointer->y); |
Rob Bradford | ac63e5b | 2012-08-13 14:07:52 +0100 | [diff] [blame] | 4875 | break; |
| 4876 | } |
| 4877 | } |
| 4878 | |
| 4879 | wl_list_for_each(output, &compositor->output_list, link) { |
| 4880 | if (pixman_region32_contains_point(&output->region, ix, iy, NULL)) { |
| 4881 | target_output = output; |
| 4882 | break; |
| 4883 | } |
| 4884 | } |
| 4885 | |
| 4886 | if (!target_output) { |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 4887 | weston_view_set_position(view, 10 + random() % 400, |
| 4888 | 10 + random() % 400); |
Rob Bradford | ac63e5b | 2012-08-13 14:07:52 +0100 | [diff] [blame] | 4889 | return; |
| 4890 | } |
| 4891 | |
| 4892 | /* Valid range within output where the surface will still be onscreen. |
| 4893 | * If this is negative it means that the surface is bigger than |
| 4894 | * output. |
| 4895 | */ |
| 4896 | panel_height = get_output_panel_height(shell, target_output); |
Jason Ekstrand | 918f2dd | 2013-12-02 21:01:53 -0600 | [diff] [blame] | 4897 | range_x = target_output->width - view->surface->width; |
Scott Moreau | 1bad5db | 2012-08-18 01:04:05 -0600 | [diff] [blame] | 4898 | range_y = (target_output->height - panel_height) - |
Jason Ekstrand | 918f2dd | 2013-12-02 21:01:53 -0600 | [diff] [blame] | 4899 | view->surface->height; |
Rob Bradford | ac63e5b | 2012-08-13 14:07:52 +0100 | [diff] [blame] | 4900 | |
Rob Bradford | 4cb88c7 | 2012-08-13 15:18:44 +0100 | [diff] [blame] | 4901 | if (range_x > 0) |
Rob Bradford | ac63e5b | 2012-08-13 14:07:52 +0100 | [diff] [blame] | 4902 | dx = random() % range_x; |
Rob Bradford | ac63e5b | 2012-08-13 14:07:52 +0100 | [diff] [blame] | 4903 | else |
Rob Bradford | 4cb88c7 | 2012-08-13 15:18:44 +0100 | [diff] [blame] | 4904 | dx = 0; |
| 4905 | |
| 4906 | if (range_y > 0) |
Rob Bradford | ac63e5b | 2012-08-13 14:07:52 +0100 | [diff] [blame] | 4907 | dy = panel_height + random() % range_y; |
Rob Bradford | 4cb88c7 | 2012-08-13 15:18:44 +0100 | [diff] [blame] | 4908 | else |
| 4909 | dy = panel_height; |
Rob Bradford | ac63e5b | 2012-08-13 14:07:52 +0100 | [diff] [blame] | 4910 | |
| 4911 | x = target_output->x + dx; |
| 4912 | y = target_output->y + dy; |
| 4913 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 4914 | weston_view_set_position(view, x, y); |
Rob Bradford | ac63e5b | 2012-08-13 14:07:52 +0100 | [diff] [blame] | 4915 | } |
| 4916 | |
| 4917 | static void |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 4918 | map(struct desktop_shell *shell, struct shell_surface *shsurf, |
Jason Ekstrand | 918f2dd | 2013-12-02 21:01:53 -0600 | [diff] [blame] | 4919 | int32_t sx, int32_t sy) |
Kristian Høgsberg | 02ec0a5 | 2011-04-23 13:04:11 -0400 | [diff] [blame] | 4920 | { |
Kristian Høgsberg | 8334bc1 | 2012-01-03 10:29:47 -0500 | [diff] [blame] | 4921 | struct weston_compositor *compositor = shell->compositor; |
Daniel Stone | b210468 | 2012-05-30 16:31:56 +0100 | [diff] [blame] | 4922 | struct weston_seat *seat; |
Juan Zhao | 96879df | 2012-02-07 08:45:41 +0800 | [diff] [blame] | 4923 | int panel_height = 0; |
Giulio Camuffo | b836664 | 2013-04-25 13:57:46 +0300 | [diff] [blame] | 4924 | int32_t surf_x, surf_y; |
Pekka Paalanen | 57da4a8 | 2011-11-23 16:42:16 +0200 | [diff] [blame] | 4925 | |
Pekka Paalanen | 77346a6 | 2011-11-30 16:26:35 +0200 | [diff] [blame] | 4926 | /* initial positioning, see also configure() */ |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 4927 | switch (shsurf->type) { |
Rafael Antognolli | ed207b4 | 2013-12-03 15:35:43 -0200 | [diff] [blame] | 4928 | case SHELL_SURFACE_TOPLEVEL: |
Rafael Antognolli | 03b1659 | 2013-12-03 15:35:42 -0200 | [diff] [blame] | 4929 | if (shsurf->state.fullscreen) { |
| 4930 | center_on_output(shsurf->view, shsurf->fullscreen_output); |
| 4931 | shell_map_fullscreen(shsurf); |
| 4932 | } else if (shsurf->state.maximized) { |
| 4933 | /* use surface configure to set the geometry */ |
| 4934 | panel_height = get_output_panel_height(shell, shsurf->output); |
| 4935 | surface_subsurfaces_boundingbox(shsurf->surface, |
| 4936 | &surf_x, &surf_y, NULL, NULL); |
| 4937 | weston_view_set_position(shsurf->view, |
| 4938 | shsurf->output->x - surf_x, |
| 4939 | shsurf->output->y + |
| 4940 | panel_height - surf_y); |
Rafael Antognolli | ed207b4 | 2013-12-03 15:35:43 -0200 | [diff] [blame] | 4941 | } else if (!shsurf->state.relative) { |
Rafael Antognolli | 03b1659 | 2013-12-03 15:35:42 -0200 | [diff] [blame] | 4942 | weston_view_set_initial_position(shsurf->view, shell); |
| 4943 | } |
Juan Zhao | 96879df | 2012-02-07 08:45:41 +0800 | [diff] [blame] | 4944 | break; |
Tiago Vignatti | 0f99701 | 2012-02-10 16:17:23 +0200 | [diff] [blame] | 4945 | case SHELL_SURFACE_POPUP: |
Kristian Høgsberg | 3730f36 | 2012-04-13 12:40:07 -0400 | [diff] [blame] | 4946 | shell_map_popup(shsurf); |
Rob Bradford | db99938 | 2012-12-06 12:07:48 +0000 | [diff] [blame] | 4947 | break; |
Ander Conselvan de Oliveira | e9e0515 | 2012-02-15 17:02:56 +0200 | [diff] [blame] | 4948 | case SHELL_SURFACE_NONE: |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 4949 | weston_view_set_position(shsurf->view, |
| 4950 | shsurf->view->geometry.x + sx, |
| 4951 | shsurf->view->geometry.y + sy); |
Tiago Vignatti | 0f99701 | 2012-02-10 16:17:23 +0200 | [diff] [blame] | 4952 | break; |
Philip Withnall | 0f640e2 | 2013-11-25 18:01:31 +0000 | [diff] [blame] | 4953 | case SHELL_SURFACE_XWAYLAND: |
Pekka Paalanen | 77346a6 | 2011-11-30 16:26:35 +0200 | [diff] [blame] | 4954 | default: |
| 4955 | ; |
| 4956 | } |
Kristian Høgsberg | 7584062 | 2011-09-06 13:48:16 -0400 | [diff] [blame] | 4957 | |
Philip Withnall | e1d75ae | 2013-11-25 18:01:41 +0000 | [diff] [blame] | 4958 | /* Surface stacking order, see also activate(). */ |
| 4959 | shell_surface_update_layer(shsurf); |
Pekka Paalanen | f0fc70d | 2011-11-15 13:34:54 +0200 | [diff] [blame] | 4960 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 4961 | if (shsurf->type != SHELL_SURFACE_NONE) { |
| 4962 | weston_view_update_transform(shsurf->view); |
Rafael Antognolli | 03b1659 | 2013-12-03 15:35:42 -0200 | [diff] [blame] | 4963 | if (shsurf->state.maximized) { |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 4964 | shsurf->surface->output = shsurf->output; |
| 4965 | shsurf->view->output = shsurf->output; |
| 4966 | } |
Ander Conselvan de Oliveira | de56c31 | 2012-03-05 15:39:23 +0200 | [diff] [blame] | 4967 | } |
Kristian Høgsberg | 2f88a40 | 2011-12-04 15:32:59 -0500 | [diff] [blame] | 4968 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 4969 | switch (shsurf->type) { |
Tiago Vignatti | fb2adba | 2013-06-12 15:43:21 -0300 | [diff] [blame] | 4970 | /* XXX: xwayland's using the same fields for transient type */ |
| 4971 | case SHELL_SURFACE_XWAYLAND: |
Tiago Vignatti | 99aeb1e | 2012-05-23 22:06:26 +0300 | [diff] [blame] | 4972 | if (shsurf->transient.flags == |
| 4973 | WL_SHELL_SURFACE_TRANSIENT_INACTIVE) |
| 4974 | break; |
| 4975 | case SHELL_SURFACE_TOPLEVEL: |
Rafael Antognolli | ed207b4 | 2013-12-03 15:35:43 -0200 | [diff] [blame] | 4976 | if (shsurf->state.relative && |
| 4977 | shsurf->transient.flags == WL_SHELL_SURFACE_TRANSIENT_INACTIVE) |
| 4978 | break; |
Rafael Antognolli | ba5d2d7 | 2013-12-04 17:49:55 -0200 | [diff] [blame] | 4979 | if (shell->locked) |
Rafael Antognolli | ed207b4 | 2013-12-03 15:35:43 -0200 | [diff] [blame] | 4980 | break; |
| 4981 | wl_list_for_each(seat, &compositor->seat_list, link) |
Emilio Pozuelo Monfort | 9e7c759 | 2014-01-30 14:01:10 +0100 | [diff] [blame] | 4982 | activate(shell, shsurf->surface, seat, true); |
Juan Zhao | 7bb92f0 | 2011-12-15 11:31:51 -0500 | [diff] [blame] | 4983 | break; |
Philip Withnall | 0f640e2 | 2013-11-25 18:01:31 +0000 | [diff] [blame] | 4984 | case SHELL_SURFACE_POPUP: |
| 4985 | case SHELL_SURFACE_NONE: |
Juan Zhao | 7bb92f0 | 2011-12-15 11:31:51 -0500 | [diff] [blame] | 4986 | default: |
| 4987 | break; |
| 4988 | } |
| 4989 | |
Rafael Antognolli | 03b1659 | 2013-12-03 15:35:42 -0200 | [diff] [blame] | 4990 | if (shsurf->type == SHELL_SURFACE_TOPLEVEL && |
| 4991 | !shsurf->state.maximized && !shsurf->state.fullscreen) |
Juan Zhao | e10d279 | 2012-04-25 19:09:52 +0800 | [diff] [blame] | 4992 | { |
| 4993 | switch (shell->win_animation_type) { |
| 4994 | case ANIMATION_FADE: |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 4995 | 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] | 4996 | break; |
| 4997 | case ANIMATION_ZOOM: |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 4998 | weston_zoom_run(shsurf->view, 0.5, 1.0, NULL, NULL); |
Juan Zhao | e10d279 | 2012-04-25 19:09:52 +0800 | [diff] [blame] | 4999 | break; |
Philip Withnall | 4a86a0a | 2013-11-25 18:01:32 +0000 | [diff] [blame] | 5000 | case ANIMATION_NONE: |
Juan Zhao | e10d279 | 2012-04-25 19:09:52 +0800 | [diff] [blame] | 5001 | default: |
| 5002 | break; |
| 5003 | } |
| 5004 | } |
Kristian Høgsberg | 32e24cc | 2011-11-09 12:07:35 -0500 | [diff] [blame] | 5005 | } |
| 5006 | |
| 5007 | static void |
Tiago Vignatti | be14326 | 2012-04-16 17:31:41 +0300 | [diff] [blame] | 5008 | configure(struct desktop_shell *shell, struct weston_surface *surface, |
Jason Ekstrand | 918f2dd | 2013-12-02 21:01:53 -0600 | [diff] [blame] | 5009 | float x, float y) |
Kristian Høgsberg | 32e24cc | 2011-11-09 12:07:35 -0500 | [diff] [blame] | 5010 | { |
Pekka Paalanen | 77346a6 | 2011-11-30 16:26:35 +0200 | [diff] [blame] | 5011 | struct shell_surface *shsurf; |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 5012 | struct weston_view *view; |
Jason Ekstrand | 918f2dd | 2013-12-02 21:01:53 -0600 | [diff] [blame] | 5013 | int32_t mx, my, surf_x, surf_y; |
Kristian Høgsberg | 32e24cc | 2011-11-09 12:07:35 -0500 | [diff] [blame] | 5014 | |
Pekka Paalanen | 77346a6 | 2011-11-30 16:26:35 +0200 | [diff] [blame] | 5015 | shsurf = get_shell_surface(surface); |
Pekka Paalanen | 77346a6 | 2011-11-30 16:26:35 +0200 | [diff] [blame] | 5016 | |
U. Artie Eoff | cf5737a | 2014-01-17 10:08:25 -0800 | [diff] [blame] | 5017 | assert(shsurf); |
| 5018 | |
Rafael Antognolli | 03b1659 | 2013-12-03 15:35:42 -0200 | [diff] [blame] | 5019 | if (shsurf->state.fullscreen) |
Alex Wu | 4539b08 | 2012-03-01 12:57:46 +0800 | [diff] [blame] | 5020 | shell_configure_fullscreen(shsurf); |
Rafael Antognolli | 03b1659 | 2013-12-03 15:35:42 -0200 | [diff] [blame] | 5021 | else if (shsurf->state.maximized) { |
Alex Wu | 4539b08 | 2012-03-01 12:57:46 +0800 | [diff] [blame] | 5022 | /* setting x, y and using configure to change that geometry */ |
Giulio Camuffo | b836664 | 2013-04-25 13:57:46 +0300 | [diff] [blame] | 5023 | surface_subsurfaces_boundingbox(shsurf->surface, &surf_x, &surf_y, |
| 5024 | NULL, NULL); |
Jason Ekstrand | 918f2dd | 2013-12-02 21:01:53 -0600 | [diff] [blame] | 5025 | mx = shsurf->output->x - surf_x; |
| 5026 | my = shsurf->output->y + |
| 5027 | get_output_panel_height(shell,shsurf->output) - surf_y; |
| 5028 | weston_view_set_position(shsurf->view, mx, my); |
Rafael Antognolli | 03b1659 | 2013-12-03 15:35:42 -0200 | [diff] [blame] | 5029 | } else { |
Jason Ekstrand | 918f2dd | 2013-12-02 21:01:53 -0600 | [diff] [blame] | 5030 | weston_view_set_position(shsurf->view, x, y); |
Kristian Høgsberg | 7a5c979 | 2011-06-18 06:12:54 -0400 | [diff] [blame] | 5031 | } |
Kristian Høgsberg | 32e24cc | 2011-11-09 12:07:35 -0500 | [diff] [blame] | 5032 | |
Alex Wu | 4539b08 | 2012-03-01 12:57:46 +0800 | [diff] [blame] | 5033 | /* XXX: would a fullscreen surface need the same handling? */ |
Kristian Høgsberg | 6a8b553 | 2012-02-16 23:43:59 -0500 | [diff] [blame] | 5034 | if (surface->output) { |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 5035 | wl_list_for_each(view, &surface->views, surface_link) |
| 5036 | weston_view_update_transform(view); |
Pekka Paalanen | 77346a6 | 2011-11-30 16:26:35 +0200 | [diff] [blame] | 5037 | |
Rafael Antognolli | 03b1659 | 2013-12-03 15:35:42 -0200 | [diff] [blame] | 5038 | if (shsurf->state.maximized) |
Juan Zhao | 96879df | 2012-02-07 08:45:41 +0800 | [diff] [blame] | 5039 | surface->output = shsurf->output; |
Pekka Paalanen | 77346a6 | 2011-11-30 16:26:35 +0200 | [diff] [blame] | 5040 | } |
Kristian Høgsberg | 0793756 | 2011-04-12 17:25:42 -0400 | [diff] [blame] | 5041 | } |
| 5042 | |
Ander Conselvan de Oliveira | 093bfa3 | 2012-03-27 17:36:41 +0300 | [diff] [blame] | 5043 | static void |
Jason Ekstrand | 918f2dd | 2013-12-02 21:01:53 -0600 | [diff] [blame] | 5044 | 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] | 5045 | { |
Ander Conselvan de Oliveira | 7fb9f95 | 2012-03-27 17:36:42 +0300 | [diff] [blame] | 5046 | struct shell_surface *shsurf = get_shell_surface(es); |
U. Artie Eoff | cf5737a | 2014-01-17 10:08:25 -0800 | [diff] [blame] | 5047 | struct desktop_shell *shell; |
Tiago Vignatti | 70e5c9c | 2012-05-07 15:23:07 +0300 | [diff] [blame] | 5048 | int type_changed = 0; |
Ander Conselvan de Oliveira | 093bfa3 | 2012-03-27 17:36:41 +0300 | [diff] [blame] | 5049 | |
U. Artie Eoff | cf5737a | 2014-01-17 10:08:25 -0800 | [diff] [blame] | 5050 | assert(shsurf); |
| 5051 | |
| 5052 | shell = shsurf->shell; |
| 5053 | |
Kristian Høgsberg | 8eb0f4f | 2013-06-17 10:33:14 -0400 | [diff] [blame] | 5054 | if (!weston_surface_is_mapped(es) && |
| 5055 | !wl_list_empty(&shsurf->popup.grab_link)) { |
Giulio Camuffo | 5085a75 | 2013-03-25 21:42:45 +0100 | [diff] [blame] | 5056 | remove_popup_grab(shsurf); |
| 5057 | } |
| 5058 | |
Jason Ekstrand | 918f2dd | 2013-12-02 21:01:53 -0600 | [diff] [blame] | 5059 | if (es->width == 0) |
Giulio Camuffo | 184df50 | 2013-02-21 11:29:21 +0100 | [diff] [blame] | 5060 | return; |
| 5061 | |
Kristian Høgsberg | c8f8dd8 | 2013-12-05 23:20:33 -0800 | [diff] [blame] | 5062 | if (shsurf->state_changed) { |
Kristian Høgsberg | 7f366e7 | 2012-04-27 17:20:01 -0400 | [diff] [blame] | 5063 | set_surface_type(shsurf); |
Kristian Høgsberg | f7e23d5 | 2012-04-27 17:51:59 -0400 | [diff] [blame] | 5064 | type_changed = 1; |
| 5065 | } |
Kristian Høgsberg | 7f366e7 | 2012-04-27 17:20:01 -0400 | [diff] [blame] | 5066 | |
Ander Conselvan de Oliveira | 093bfa3 | 2012-03-27 17:36:41 +0300 | [diff] [blame] | 5067 | if (!weston_surface_is_mapped(es)) { |
Jason Ekstrand | 918f2dd | 2013-12-02 21:01:53 -0600 | [diff] [blame] | 5068 | map(shell, shsurf, sx, sy); |
Kristian Høgsberg | f7e23d5 | 2012-04-27 17:51:59 -0400 | [diff] [blame] | 5069 | } else if (type_changed || sx != 0 || sy != 0 || |
Jason Ekstrand | 918f2dd | 2013-12-02 21:01:53 -0600 | [diff] [blame] | 5070 | shsurf->last_width != es->width || |
| 5071 | shsurf->last_height != es->height) { |
John Kåre Alsaker | 490d02a | 2012-09-30 02:57:21 +0200 | [diff] [blame] | 5072 | float from_x, from_y; |
| 5073 | float to_x, to_y; |
Ander Conselvan de Oliveira | 093bfa3 | 2012-03-27 17:36:41 +0300 | [diff] [blame] | 5074 | |
Kristian Høgsberg | 44cd196 | 2014-02-05 21:36:04 -0800 | [diff] [blame] | 5075 | if (shsurf->resize_edges) { |
| 5076 | sx = 0; |
| 5077 | sy = 0; |
| 5078 | } |
| 5079 | |
| 5080 | if (shsurf->resize_edges & WL_SHELL_SURFACE_RESIZE_LEFT) |
| 5081 | sx = shsurf->last_width - es->width; |
| 5082 | if (shsurf->resize_edges & WL_SHELL_SURFACE_RESIZE_TOP) |
| 5083 | sy = shsurf->last_height - es->height; |
| 5084 | |
| 5085 | shsurf->last_width = es->width; |
| 5086 | shsurf->last_height = es->height; |
| 5087 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 5088 | weston_view_to_global_float(shsurf->view, 0, 0, &from_x, &from_y); |
| 5089 | 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] | 5090 | configure(shell, es, |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 5091 | shsurf->view->geometry.x + to_x - from_x, |
Jason Ekstrand | 918f2dd | 2013-12-02 21:01:53 -0600 | [diff] [blame] | 5092 | shsurf->view->geometry.y + to_y - from_y); |
Ander Conselvan de Oliveira | 093bfa3 | 2012-03-27 17:36:41 +0300 | [diff] [blame] | 5093 | } |
| 5094 | } |
| 5095 | |
Tiago Vignatti | b7dbbd6 | 2012-09-25 17:57:01 +0300 | [diff] [blame] | 5096 | static void launch_desktop_shell_process(void *data); |
Pekka Paalanen | 4d733ee | 2012-01-17 14:36:27 +0200 | [diff] [blame] | 5097 | |
Kristian Høgsberg | 97d44aa | 2011-08-26 17:21:20 -0400 | [diff] [blame] | 5098 | static void |
Kristian Høgsberg | 8334bc1 | 2012-01-03 10:29:47 -0500 | [diff] [blame] | 5099 | desktop_shell_sigchld(struct weston_process *process, int status) |
Pekka Paalanen | 6cd281a | 2011-11-03 14:11:32 +0200 | [diff] [blame] | 5100 | { |
Pekka Paalanen | 4d733ee | 2012-01-17 14:36:27 +0200 | [diff] [blame] | 5101 | uint32_t time; |
Tiago Vignatti | be14326 | 2012-04-16 17:31:41 +0300 | [diff] [blame] | 5102 | struct desktop_shell *shell = |
| 5103 | container_of(process, struct desktop_shell, child.process); |
Pekka Paalanen | 6cd281a | 2011-11-03 14:11:32 +0200 | [diff] [blame] | 5104 | |
| 5105 | shell->child.process.pid = 0; |
| 5106 | shell->child.client = NULL; /* already destroyed by wayland */ |
Pekka Paalanen | 4d733ee | 2012-01-17 14:36:27 +0200 | [diff] [blame] | 5107 | |
| 5108 | /* if desktop-shell dies more than 5 times in 30 seconds, give up */ |
| 5109 | time = weston_compositor_get_time(); |
Kristian Høgsberg | f03a616 | 2012-01-17 11:07:42 -0500 | [diff] [blame] | 5110 | if (time - shell->child.deathstamp > 30000) { |
Pekka Paalanen | 4d733ee | 2012-01-17 14:36:27 +0200 | [diff] [blame] | 5111 | shell->child.deathstamp = time; |
| 5112 | shell->child.deathcount = 0; |
| 5113 | } |
| 5114 | |
| 5115 | shell->child.deathcount++; |
| 5116 | if (shell->child.deathcount > 5) { |
Emilio Pozuelo Monfort | 46ce798 | 2013-11-20 13:22:29 +0100 | [diff] [blame] | 5117 | weston_log("%s died, giving up.\n", shell->client); |
Pekka Paalanen | 4d733ee | 2012-01-17 14:36:27 +0200 | [diff] [blame] | 5118 | return; |
| 5119 | } |
| 5120 | |
Emilio Pozuelo Monfort | 46ce798 | 2013-11-20 13:22:29 +0100 | [diff] [blame] | 5121 | weston_log("%s died, respawning...\n", shell->client); |
Pekka Paalanen | 4d733ee | 2012-01-17 14:36:27 +0200 | [diff] [blame] | 5122 | launch_desktop_shell_process(shell); |
Pekka Paalanen | 79346ab | 2013-05-22 18:03:09 +0300 | [diff] [blame] | 5123 | shell_fade_startup(shell); |
Pekka Paalanen | 6cd281a | 2011-11-03 14:11:32 +0200 | [diff] [blame] | 5124 | } |
| 5125 | |
Tiago Vignatti | b7dbbd6 | 2012-09-25 17:57:01 +0300 | [diff] [blame] | 5126 | static void |
Ander Conselvan de Oliveira | 312ea4c | 2013-12-20 21:07:01 +0200 | [diff] [blame] | 5127 | desktop_shell_client_destroy(struct wl_listener *listener, void *data) |
| 5128 | { |
| 5129 | struct desktop_shell *shell; |
| 5130 | |
| 5131 | shell = container_of(listener, struct desktop_shell, |
| 5132 | child.client_destroy_listener); |
| 5133 | |
| 5134 | shell->child.client = NULL; |
| 5135 | } |
| 5136 | |
| 5137 | static void |
Tiago Vignatti | b7dbbd6 | 2012-09-25 17:57:01 +0300 | [diff] [blame] | 5138 | launch_desktop_shell_process(void *data) |
Pekka Paalanen | 6cd281a | 2011-11-03 14:11:32 +0200 | [diff] [blame] | 5139 | { |
Tiago Vignatti | b7dbbd6 | 2012-09-25 17:57:01 +0300 | [diff] [blame] | 5140 | struct desktop_shell *shell = data; |
Pekka Paalanen | 6cd281a | 2011-11-03 14:11:32 +0200 | [diff] [blame] | 5141 | |
Kristian Høgsberg | 8334bc1 | 2012-01-03 10:29:47 -0500 | [diff] [blame] | 5142 | shell->child.client = weston_client_launch(shell->compositor, |
Pekka Paalanen | 409ef0a | 2011-12-02 15:30:21 +0200 | [diff] [blame] | 5143 | &shell->child.process, |
Emilio Pozuelo Monfort | 46ce798 | 2013-11-20 13:22:29 +0100 | [diff] [blame] | 5144 | shell->client, |
Pekka Paalanen | 409ef0a | 2011-12-02 15:30:21 +0200 | [diff] [blame] | 5145 | desktop_shell_sigchld); |
| 5146 | |
| 5147 | if (!shell->child.client) |
Emilio Pozuelo Monfort | 46ce798 | 2013-11-20 13:22:29 +0100 | [diff] [blame] | 5148 | weston_log("not able to start %s\n", shell->client); |
Ander Conselvan de Oliveira | 312ea4c | 2013-12-20 21:07:01 +0200 | [diff] [blame] | 5149 | |
| 5150 | shell->child.client_destroy_listener.notify = |
| 5151 | desktop_shell_client_destroy; |
| 5152 | wl_client_add_destroy_listener(shell->child.client, |
| 5153 | &shell->child.client_destroy_listener); |
Pekka Paalanen | 6cd281a | 2011-11-03 14:11:32 +0200 | [diff] [blame] | 5154 | } |
| 5155 | |
| 5156 | static void |
Kristian Høgsberg | 2bff94e | 2014-02-11 12:22:51 -0800 | [diff] [blame] | 5157 | handle_shell_client_destroy(struct wl_listener *listener, void *data) |
| 5158 | { |
| 5159 | struct shell_client *sc = |
| 5160 | container_of(listener, struct shell_client, destroy_listener); |
| 5161 | |
| 5162 | if (sc->ping_timer) |
| 5163 | wl_event_source_remove(sc->ping_timer); |
| 5164 | free(sc); |
| 5165 | } |
| 5166 | |
Kristian Høgsberg | dd62aba | 2014-02-12 09:56:19 -0800 | [diff] [blame] | 5167 | static struct shell_client * |
| 5168 | shell_client_create(struct wl_client *client, struct desktop_shell *shell, |
| 5169 | const struct wl_interface *interface, uint32_t id) |
Rafael Antognolli | e2a3455 | 2013-12-03 15:35:45 -0200 | [diff] [blame] | 5170 | { |
Kristian Høgsberg | 2bff94e | 2014-02-11 12:22:51 -0800 | [diff] [blame] | 5171 | struct shell_client *sc; |
Rafael Antognolli | e2a3455 | 2013-12-03 15:35:45 -0200 | [diff] [blame] | 5172 | |
Kristian Høgsberg | 2bff94e | 2014-02-11 12:22:51 -0800 | [diff] [blame] | 5173 | sc = zalloc(sizeof *sc); |
| 5174 | if (sc == NULL) { |
| 5175 | wl_client_post_no_memory(client); |
Kristian Høgsberg | dd62aba | 2014-02-12 09:56:19 -0800 | [diff] [blame] | 5176 | return NULL; |
Kristian Høgsberg | 2bff94e | 2014-02-11 12:22:51 -0800 | [diff] [blame] | 5177 | } |
Kristian Høgsberg | dd62aba | 2014-02-12 09:56:19 -0800 | [diff] [blame] | 5178 | |
| 5179 | sc->resource = wl_resource_create(client, interface, 1, id); |
Kristian Høgsberg | 2bff94e | 2014-02-11 12:22:51 -0800 | [diff] [blame] | 5180 | if (sc->resource == NULL) { |
| 5181 | free(sc); |
| 5182 | wl_client_post_no_memory(client); |
Kristian Høgsberg | dd62aba | 2014-02-12 09:56:19 -0800 | [diff] [blame] | 5183 | return NULL; |
Kristian Høgsberg | 2bff94e | 2014-02-11 12:22:51 -0800 | [diff] [blame] | 5184 | } |
| 5185 | |
| 5186 | sc->client = client; |
| 5187 | sc->shell = shell; |
| 5188 | sc->destroy_listener.notify = handle_shell_client_destroy; |
| 5189 | wl_client_add_destroy_listener(client, &sc->destroy_listener); |
| 5190 | |
Kristian Høgsberg | dd62aba | 2014-02-12 09:56:19 -0800 | [diff] [blame] | 5191 | return sc; |
| 5192 | } |
| 5193 | |
| 5194 | static void |
| 5195 | bind_shell(struct wl_client *client, void *data, uint32_t version, uint32_t id) |
| 5196 | { |
| 5197 | struct desktop_shell *shell = data; |
| 5198 | struct shell_client *sc; |
| 5199 | |
| 5200 | sc = shell_client_create(client, shell, &wl_shell_interface, id); |
| 5201 | if (sc) |
| 5202 | wl_resource_set_implementation(sc->resource, |
| 5203 | &shell_implementation, |
Jason Ekstrand | 9e9512f | 2014-04-16 21:12:10 -0500 | [diff] [blame] | 5204 | sc, NULL); |
Kristian Høgsberg | dd62aba | 2014-02-12 09:56:19 -0800 | [diff] [blame] | 5205 | } |
| 5206 | |
| 5207 | static void |
| 5208 | bind_xdg_shell(struct wl_client *client, void *data, uint32_t version, uint32_t id) |
| 5209 | { |
| 5210 | struct desktop_shell *shell = data; |
| 5211 | struct shell_client *sc; |
| 5212 | |
| 5213 | sc = shell_client_create(client, shell, &xdg_shell_interface, id); |
| 5214 | if (sc) |
| 5215 | wl_resource_set_dispatcher(sc->resource, |
| 5216 | xdg_shell_unversioned_dispatch, |
| 5217 | NULL, sc, NULL); |
Rafael Antognolli | e2a3455 | 2013-12-03 15:35:45 -0200 | [diff] [blame] | 5218 | } |
| 5219 | |
| 5220 | static void |
Pekka Paalanen | 9ef3e01 | 2011-11-15 13:34:48 +0200 | [diff] [blame] | 5221 | unbind_desktop_shell(struct wl_resource *resource) |
| 5222 | { |
Jason Ekstrand | 651f00e | 2013-06-14 10:07:54 -0500 | [diff] [blame] | 5223 | struct desktop_shell *shell = wl_resource_get_user_data(resource); |
Kristian Høgsberg | 1ec0c31 | 2011-11-15 16:39:55 -0500 | [diff] [blame] | 5224 | |
| 5225 | if (shell->locked) |
| 5226 | resume_desktop(shell); |
| 5227 | |
Pekka Paalanen | 9ef3e01 | 2011-11-15 13:34:48 +0200 | [diff] [blame] | 5228 | shell->child.desktop_shell = NULL; |
| 5229 | shell->prepare_event_sent = false; |
Pekka Paalanen | 9ef3e01 | 2011-11-15 13:34:48 +0200 | [diff] [blame] | 5230 | } |
| 5231 | |
| 5232 | static void |
Kristian Høgsberg | 7584062 | 2011-09-06 13:48:16 -0400 | [diff] [blame] | 5233 | bind_desktop_shell(struct wl_client *client, |
| 5234 | void *data, uint32_t version, uint32_t id) |
| 5235 | { |
Tiago Vignatti | be14326 | 2012-04-16 17:31:41 +0300 | [diff] [blame] | 5236 | struct desktop_shell *shell = data; |
Pekka Paalanen | bbe6052 | 2011-11-03 14:11:33 +0200 | [diff] [blame] | 5237 | struct wl_resource *resource; |
Kristian Høgsberg | 7584062 | 2011-09-06 13:48:16 -0400 | [diff] [blame] | 5238 | |
Jason Ekstrand | a85118c | 2013-06-27 20:17:02 -0500 | [diff] [blame] | 5239 | resource = wl_resource_create(client, &desktop_shell_interface, |
| 5240 | MIN(version, 2), id); |
Pekka Paalanen | bbe6052 | 2011-11-03 14:11:33 +0200 | [diff] [blame] | 5241 | |
Pekka Paalanen | 9ef3e01 | 2011-11-15 13:34:48 +0200 | [diff] [blame] | 5242 | if (client == shell->child.client) { |
Jason Ekstrand | a85118c | 2013-06-27 20:17:02 -0500 | [diff] [blame] | 5243 | wl_resource_set_implementation(resource, |
| 5244 | &desktop_shell_implementation, |
| 5245 | shell, unbind_desktop_shell); |
Pekka Paalanen | 9ef3e01 | 2011-11-15 13:34:48 +0200 | [diff] [blame] | 5246 | shell->child.desktop_shell = resource; |
Pekka Paalanen | 79346ab | 2013-05-22 18:03:09 +0300 | [diff] [blame] | 5247 | |
| 5248 | if (version < 2) |
| 5249 | shell_fade_startup(shell); |
| 5250 | |
Pekka Paalanen | bbe6052 | 2011-11-03 14:11:33 +0200 | [diff] [blame] | 5251 | return; |
Pekka Paalanen | 9ef3e01 | 2011-11-15 13:34:48 +0200 | [diff] [blame] | 5252 | } |
Pekka Paalanen | bbe6052 | 2011-11-03 14:11:33 +0200 | [diff] [blame] | 5253 | |
| 5254 | wl_resource_post_error(resource, WL_DISPLAY_ERROR_INVALID_OBJECT, |
| 5255 | "permission to bind desktop_shell denied"); |
Kristian Høgsberg | eae5de7 | 2012-04-11 22:42:15 -0400 | [diff] [blame] | 5256 | wl_resource_destroy(resource); |
Kristian Høgsberg | 7584062 | 2011-09-06 13:48:16 -0400 | [diff] [blame] | 5257 | } |
| 5258 | |
Pekka Paalanen | 6e16811 | 2011-11-24 11:34:05 +0200 | [diff] [blame] | 5259 | static void |
Jason Ekstrand | 918f2dd | 2013-12-02 21:01:53 -0600 | [diff] [blame] | 5260 | 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] | 5261 | { |
Giulio Camuffo | 7fe01b1 | 2013-03-28 18:02:42 +0100 | [diff] [blame] | 5262 | struct desktop_shell *shell = surface->configure_private; |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 5263 | struct weston_view *view; |
Kristian Høgsberg | 1a73a63 | 2012-06-26 22:15:53 -0400 | [diff] [blame] | 5264 | |
Jason Ekstrand | 918f2dd | 2013-12-02 21:01:53 -0600 | [diff] [blame] | 5265 | if (surface->width == 0) |
Giulio Camuffo | 184df50 | 2013-02-21 11:29:21 +0100 | [diff] [blame] | 5266 | return; |
| 5267 | |
Pekka Paalanen | 3a1d07d | 2012-12-20 14:02:13 +0200 | [diff] [blame] | 5268 | /* XXX: starting weston-screensaver beforehand does not work */ |
Kristian Høgsberg | 1a73a63 | 2012-06-26 22:15:53 -0400 | [diff] [blame] | 5269 | if (!shell->locked) |
| 5270 | return; |
| 5271 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 5272 | view = container_of(surface->views.next, struct weston_view, surface_link); |
| 5273 | center_on_output(view, surface->output); |
Kristian Høgsberg | 1a73a63 | 2012-06-26 22:15:53 -0400 | [diff] [blame] | 5274 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 5275 | if (wl_list_empty(&view->layer_link)) { |
| 5276 | wl_list_insert(shell->lock_layer.view_list.prev, |
| 5277 | &view->layer_link); |
| 5278 | weston_view_update_transform(view); |
Ander Conselvan de Oliveira | 859e885 | 2013-02-21 18:35:21 +0200 | [diff] [blame] | 5279 | wl_event_source_timer_update(shell->screensaver.timer, |
| 5280 | shell->screensaver.duration); |
Ander Conselvan de Oliveira | 19d10ef | 2013-02-21 18:35:20 +0200 | [diff] [blame] | 5281 | shell_fade(shell, FADE_IN); |
Kristian Høgsberg | 1a73a63 | 2012-06-26 22:15:53 -0400 | [diff] [blame] | 5282 | } |
| 5283 | } |
| 5284 | |
| 5285 | static void |
Pekka Paalanen | 6e16811 | 2011-11-24 11:34:05 +0200 | [diff] [blame] | 5286 | screensaver_set_surface(struct wl_client *client, |
| 5287 | struct wl_resource *resource, |
Kristian Høgsberg | 1a73a63 | 2012-06-26 22:15:53 -0400 | [diff] [blame] | 5288 | struct wl_resource *surface_resource, |
Pekka Paalanen | 6e16811 | 2011-11-24 11:34:05 +0200 | [diff] [blame] | 5289 | struct wl_resource *output_resource) |
| 5290 | { |
Jason Ekstrand | 651f00e | 2013-06-14 10:07:54 -0500 | [diff] [blame] | 5291 | struct desktop_shell *shell = wl_resource_get_user_data(resource); |
Jason Ekstrand | 0f2ef7e | 2013-06-14 10:07:53 -0500 | [diff] [blame] | 5292 | struct weston_surface *surface = |
| 5293 | wl_resource_get_user_data(surface_resource); |
Jason Ekstrand | a0d2dde | 2013-06-14 10:08:01 -0500 | [diff] [blame] | 5294 | struct weston_output *output = wl_resource_get_user_data(output_resource); |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 5295 | struct weston_view *view, *next; |
| 5296 | |
| 5297 | /* Make sure we only have one view */ |
| 5298 | wl_list_for_each_safe(view, next, &surface->views, surface_link) |
| 5299 | weston_view_destroy(view); |
| 5300 | weston_view_create(surface); |
Pekka Paalanen | 6e16811 | 2011-11-24 11:34:05 +0200 | [diff] [blame] | 5301 | |
Kristian Høgsberg | 1a73a63 | 2012-06-26 22:15:53 -0400 | [diff] [blame] | 5302 | surface->configure = screensaver_configure; |
Giulio Camuffo | 7fe01b1 | 2013-03-28 18:02:42 +0100 | [diff] [blame] | 5303 | surface->configure_private = shell; |
Pekka Paalanen | 77346a6 | 2011-11-30 16:26:35 +0200 | [diff] [blame] | 5304 | surface->output = output; |
Pekka Paalanen | 6e16811 | 2011-11-24 11:34:05 +0200 | [diff] [blame] | 5305 | } |
| 5306 | |
| 5307 | static const struct screensaver_interface screensaver_implementation = { |
| 5308 | screensaver_set_surface |
| 5309 | }; |
| 5310 | |
| 5311 | static void |
| 5312 | unbind_screensaver(struct wl_resource *resource) |
| 5313 | { |
Jason Ekstrand | 651f00e | 2013-06-14 10:07:54 -0500 | [diff] [blame] | 5314 | struct desktop_shell *shell = wl_resource_get_user_data(resource); |
Pekka Paalanen | 6e16811 | 2011-11-24 11:34:05 +0200 | [diff] [blame] | 5315 | |
Pekka Paalanen | 77346a6 | 2011-11-30 16:26:35 +0200 | [diff] [blame] | 5316 | shell->screensaver.binding = NULL; |
Pekka Paalanen | 6e16811 | 2011-11-24 11:34:05 +0200 | [diff] [blame] | 5317 | } |
| 5318 | |
| 5319 | static void |
| 5320 | bind_screensaver(struct wl_client *client, |
| 5321 | void *data, uint32_t version, uint32_t id) |
| 5322 | { |
Tiago Vignatti | be14326 | 2012-04-16 17:31:41 +0300 | [diff] [blame] | 5323 | struct desktop_shell *shell = data; |
Pekka Paalanen | 6e16811 | 2011-11-24 11:34:05 +0200 | [diff] [blame] | 5324 | struct wl_resource *resource; |
| 5325 | |
Jason Ekstrand | a85118c | 2013-06-27 20:17:02 -0500 | [diff] [blame] | 5326 | resource = wl_resource_create(client, &screensaver_interface, 1, id); |
Pekka Paalanen | 6e16811 | 2011-11-24 11:34:05 +0200 | [diff] [blame] | 5327 | |
Pekka Paalanen | 77346a6 | 2011-11-30 16:26:35 +0200 | [diff] [blame] | 5328 | if (shell->screensaver.binding == NULL) { |
Jason Ekstrand | a85118c | 2013-06-27 20:17:02 -0500 | [diff] [blame] | 5329 | wl_resource_set_implementation(resource, |
| 5330 | &screensaver_implementation, |
| 5331 | shell, unbind_screensaver); |
Pekka Paalanen | 77346a6 | 2011-11-30 16:26:35 +0200 | [diff] [blame] | 5332 | shell->screensaver.binding = resource; |
Pekka Paalanen | 6e16811 | 2011-11-24 11:34:05 +0200 | [diff] [blame] | 5333 | return; |
| 5334 | } |
| 5335 | |
| 5336 | wl_resource_post_error(resource, WL_DISPLAY_ERROR_INVALID_OBJECT, |
| 5337 | "interface object already bound"); |
Kristian Høgsberg | eae5de7 | 2012-04-11 22:42:15 -0400 | [diff] [blame] | 5338 | wl_resource_destroy(resource); |
Pekka Paalanen | 6e16811 | 2011-11-24 11:34:05 +0200 | [diff] [blame] | 5339 | } |
| 5340 | |
Kristian Høgsberg | 0704539 | 2012-02-19 18:52:44 -0500 | [diff] [blame] | 5341 | struct switcher { |
Tiago Vignatti | be14326 | 2012-04-16 17:31:41 +0300 | [diff] [blame] | 5342 | struct desktop_shell *shell; |
Kristian Høgsberg | 0704539 | 2012-02-19 18:52:44 -0500 | [diff] [blame] | 5343 | struct weston_surface *current; |
| 5344 | struct wl_listener listener; |
Kristian Høgsberg | 29139d4 | 2013-04-18 15:25:39 -0400 | [diff] [blame] | 5345 | struct weston_keyboard_grab grab; |
Manuel Bachmann | c1ae2e8 | 2014-02-26 15:53:11 +0100 | [diff] [blame] | 5346 | struct wl_array minimized_array; |
Kristian Høgsberg | 0704539 | 2012-02-19 18:52:44 -0500 | [diff] [blame] | 5347 | }; |
| 5348 | |
| 5349 | static void |
| 5350 | switcher_next(struct switcher *switcher) |
| 5351 | { |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 5352 | struct weston_view *view; |
Kristian Høgsberg | 0704539 | 2012-02-19 18:52:44 -0500 | [diff] [blame] | 5353 | struct weston_surface *first = NULL, *prev = NULL, *next = NULL; |
Kristian Høgsberg | 32e5686 | 2012-04-02 22:18:58 -0400 | [diff] [blame] | 5354 | struct shell_surface *shsurf; |
Kristian Høgsberg | b0d8e77 | 2012-06-18 16:34:58 -0400 | [diff] [blame] | 5355 | struct workspace *ws = get_current_workspace(switcher->shell); |
Kristian Høgsberg | 0704539 | 2012-02-19 18:52:44 -0500 | [diff] [blame] | 5356 | |
Manuel Bachmann | c1ae2e8 | 2014-02-26 15:53:11 +0100 | [diff] [blame] | 5357 | /* temporary re-display minimized surfaces */ |
| 5358 | struct weston_view *tmp; |
| 5359 | struct weston_view **minimized; |
| 5360 | wl_list_for_each_safe(view, tmp, &switcher->shell->minimized_layer.view_list, layer_link) { |
| 5361 | wl_list_remove(&view->layer_link); |
| 5362 | wl_list_insert(&ws->layer.view_list, &view->layer_link); |
| 5363 | minimized = wl_array_add(&switcher->minimized_array, sizeof *minimized); |
| 5364 | *minimized = view; |
| 5365 | } |
| 5366 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 5367 | wl_list_for_each(view, &ws->layer.view_list, layer_link) { |
Rafael Antognolli | ed207b4 | 2013-12-03 15:35:43 -0200 | [diff] [blame] | 5368 | shsurf = get_shell_surface(view->surface); |
Rafael Antognolli | 5031cbe | 2013-12-05 19:01:21 -0200 | [diff] [blame] | 5369 | if (shsurf && |
| 5370 | shsurf->type == SHELL_SURFACE_TOPLEVEL && |
| 5371 | shsurf->parent == NULL) { |
Kristian Høgsberg | 0704539 | 2012-02-19 18:52:44 -0500 | [diff] [blame] | 5372 | if (first == NULL) |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 5373 | first = view->surface; |
Kristian Høgsberg | 0704539 | 2012-02-19 18:52:44 -0500 | [diff] [blame] | 5374 | if (prev == switcher->current) |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 5375 | next = view->surface; |
| 5376 | prev = view->surface; |
| 5377 | view->alpha = 0.25; |
| 5378 | weston_view_geometry_dirty(view); |
| 5379 | weston_surface_damage(view->surface); |
Kristian Høgsberg | 0704539 | 2012-02-19 18:52:44 -0500 | [diff] [blame] | 5380 | } |
Alex Wu | 1659daa | 2012-04-01 20:13:09 +0800 | [diff] [blame] | 5381 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 5382 | if (is_black_surface(view->surface, NULL)) { |
| 5383 | view->alpha = 0.25; |
| 5384 | weston_view_geometry_dirty(view); |
| 5385 | weston_surface_damage(view->surface); |
Alex Wu | 1659daa | 2012-04-01 20:13:09 +0800 | [diff] [blame] | 5386 | } |
Kristian Høgsberg | 0704539 | 2012-02-19 18:52:44 -0500 | [diff] [blame] | 5387 | } |
| 5388 | |
| 5389 | if (next == NULL) |
| 5390 | next = first; |
| 5391 | |
Alex Wu | 07b2606 | 2012-03-12 16:06:01 +0800 | [diff] [blame] | 5392 | if (next == NULL) |
| 5393 | return; |
| 5394 | |
Kristian Høgsberg | 0704539 | 2012-02-19 18:52:44 -0500 | [diff] [blame] | 5395 | wl_list_remove(&switcher->listener.link); |
Jason Ekstrand | 26ed73c | 2013-06-06 22:34:41 -0500 | [diff] [blame] | 5396 | wl_signal_add(&next->destroy_signal, &switcher->listener); |
Kristian Høgsberg | 0704539 | 2012-02-19 18:52:44 -0500 | [diff] [blame] | 5397 | |
| 5398 | switcher->current = next; |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 5399 | wl_list_for_each(view, &next->views, surface_link) |
| 5400 | view->alpha = 1.0; |
Alex Wu | 1659daa | 2012-04-01 20:13:09 +0800 | [diff] [blame] | 5401 | |
Kristian Høgsberg | 32e5686 | 2012-04-02 22:18:58 -0400 | [diff] [blame] | 5402 | shsurf = get_shell_surface(switcher->current); |
Rafael Antognolli | 03b1659 | 2013-12-03 15:35:42 -0200 | [diff] [blame] | 5403 | if (shsurf && shsurf->state.fullscreen) |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 5404 | shsurf->fullscreen.black_view->alpha = 1.0; |
Kristian Høgsberg | 0704539 | 2012-02-19 18:52:44 -0500 | [diff] [blame] | 5405 | } |
| 5406 | |
| 5407 | static void |
Kristian Høgsberg | 27e3052 | 2012-04-11 23:18:23 -0400 | [diff] [blame] | 5408 | switcher_handle_surface_destroy(struct wl_listener *listener, void *data) |
Kristian Høgsberg | 0704539 | 2012-02-19 18:52:44 -0500 | [diff] [blame] | 5409 | { |
| 5410 | struct switcher *switcher = |
| 5411 | container_of(listener, struct switcher, listener); |
| 5412 | |
| 5413 | switcher_next(switcher); |
| 5414 | } |
| 5415 | |
| 5416 | static void |
Daniel Stone | 351eb61 | 2012-05-31 15:27:47 -0400 | [diff] [blame] | 5417 | switcher_destroy(struct switcher *switcher) |
Kristian Høgsberg | 0704539 | 2012-02-19 18:52:44 -0500 | [diff] [blame] | 5418 | { |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 5419 | struct weston_view *view; |
Kristian Høgsberg | 29139d4 | 2013-04-18 15:25:39 -0400 | [diff] [blame] | 5420 | struct weston_keyboard *keyboard = switcher->grab.keyboard; |
Kristian Høgsberg | b0d8e77 | 2012-06-18 16:34:58 -0400 | [diff] [blame] | 5421 | struct workspace *ws = get_current_workspace(switcher->shell); |
Kristian Høgsberg | 0704539 | 2012-02-19 18:52:44 -0500 | [diff] [blame] | 5422 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 5423 | wl_list_for_each(view, &ws->layer.view_list, layer_link) { |
Louis-Francis Ratté-Boulianne | b482dbd | 2013-11-19 11:37:11 +0100 | [diff] [blame] | 5424 | if (is_focus_view(view)) |
| 5425 | continue; |
| 5426 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 5427 | view->alpha = 1.0; |
| 5428 | weston_surface_damage(view->surface); |
Kristian Høgsberg | 0704539 | 2012-02-19 18:52:44 -0500 | [diff] [blame] | 5429 | } |
| 5430 | |
Alex Wu | 07b2606 | 2012-03-12 16:06:01 +0800 | [diff] [blame] | 5431 | if (switcher->current) |
Daniel Stone | 37816df | 2012-05-16 18:45:18 +0100 | [diff] [blame] | 5432 | activate(switcher->shell, switcher->current, |
Emilio Pozuelo Monfort | 9e7c759 | 2014-01-30 14:01:10 +0100 | [diff] [blame] | 5433 | (struct weston_seat *) keyboard->seat, true); |
Kristian Høgsberg | 0704539 | 2012-02-19 18:52:44 -0500 | [diff] [blame] | 5434 | wl_list_remove(&switcher->listener.link); |
Kristian Høgsberg | 29139d4 | 2013-04-18 15:25:39 -0400 | [diff] [blame] | 5435 | weston_keyboard_end_grab(keyboard); |
| 5436 | if (keyboard->input_method_resource) |
| 5437 | keyboard->grab = &keyboard->input_method_grab; |
Manuel Bachmann | c1ae2e8 | 2014-02-26 15:53:11 +0100 | [diff] [blame] | 5438 | |
| 5439 | /* re-hide surfaces that were temporary shown during the switch */ |
| 5440 | struct weston_view **minimized; |
| 5441 | wl_array_for_each(minimized, &switcher->minimized_array) { |
| 5442 | /* with the exception of the current selected */ |
| 5443 | if ((*minimized)->surface != switcher->current) { |
| 5444 | wl_list_remove(&(*minimized)->layer_link); |
| 5445 | wl_list_insert(&switcher->shell->minimized_layer.view_list, &(*minimized)->layer_link); |
| 5446 | weston_view_damage_below(*minimized); |
| 5447 | } |
| 5448 | } |
| 5449 | wl_array_release(&switcher->minimized_array); |
| 5450 | |
Kristian Høgsberg | 0704539 | 2012-02-19 18:52:44 -0500 | [diff] [blame] | 5451 | free(switcher); |
| 5452 | } |
| 5453 | |
| 5454 | static void |
Kristian Høgsberg | 29139d4 | 2013-04-18 15:25:39 -0400 | [diff] [blame] | 5455 | switcher_key(struct weston_keyboard_grab *grab, |
Daniel Stone | c9785ea | 2012-05-30 16:31:52 +0100 | [diff] [blame] | 5456 | uint32_t time, uint32_t key, uint32_t state_w) |
Kristian Høgsberg | 0704539 | 2012-02-19 18:52:44 -0500 | [diff] [blame] | 5457 | { |
| 5458 | struct switcher *switcher = container_of(grab, struct switcher, grab); |
Daniel Stone | c9785ea | 2012-05-30 16:31:52 +0100 | [diff] [blame] | 5459 | enum wl_keyboard_key_state state = state_w; |
Daniel Stone | 351eb61 | 2012-05-31 15:27:47 -0400 | [diff] [blame] | 5460 | |
Daniel Stone | c9785ea | 2012-05-30 16:31:52 +0100 | [diff] [blame] | 5461 | if (key == KEY_TAB && state == WL_KEYBOARD_KEY_STATE_PRESSED) |
Daniel Stone | 351eb61 | 2012-05-31 15:27:47 -0400 | [diff] [blame] | 5462 | switcher_next(switcher); |
| 5463 | } |
| 5464 | |
| 5465 | static void |
Kristian Høgsberg | 29139d4 | 2013-04-18 15:25:39 -0400 | [diff] [blame] | 5466 | switcher_modifier(struct weston_keyboard_grab *grab, uint32_t serial, |
Daniel Stone | 351eb61 | 2012-05-31 15:27:47 -0400 | [diff] [blame] | 5467 | uint32_t mods_depressed, uint32_t mods_latched, |
| 5468 | uint32_t mods_locked, uint32_t group) |
| 5469 | { |
| 5470 | struct switcher *switcher = container_of(grab, struct switcher, grab); |
Daniel Stone | 37816df | 2012-05-16 18:45:18 +0100 | [diff] [blame] | 5471 | struct weston_seat *seat = (struct weston_seat *) grab->keyboard->seat; |
Kristian Høgsberg | 0704539 | 2012-02-19 18:52:44 -0500 | [diff] [blame] | 5472 | |
Daniel Stone | 351eb61 | 2012-05-31 15:27:47 -0400 | [diff] [blame] | 5473 | if ((seat->modifier_state & switcher->shell->binding_modifier) == 0) |
| 5474 | switcher_destroy(switcher); |
Kristian Høgsberg | b71302e | 2012-05-10 12:28:35 -0400 | [diff] [blame] | 5475 | } |
Kristian Høgsberg | 0704539 | 2012-02-19 18:52:44 -0500 | [diff] [blame] | 5476 | |
Jonas Ådahl | 1ea343e | 2013-10-25 23:18:05 +0200 | [diff] [blame] | 5477 | static void |
| 5478 | switcher_cancel(struct weston_keyboard_grab *grab) |
| 5479 | { |
| 5480 | struct switcher *switcher = container_of(grab, struct switcher, grab); |
| 5481 | |
| 5482 | switcher_destroy(switcher); |
| 5483 | } |
| 5484 | |
Kristian Høgsberg | 29139d4 | 2013-04-18 15:25:39 -0400 | [diff] [blame] | 5485 | static const struct weston_keyboard_grab_interface switcher_grab = { |
Daniel Stone | 351eb61 | 2012-05-31 15:27:47 -0400 | [diff] [blame] | 5486 | switcher_key, |
| 5487 | switcher_modifier, |
Jonas Ådahl | 1ea343e | 2013-10-25 23:18:05 +0200 | [diff] [blame] | 5488 | switcher_cancel, |
Kristian Høgsberg | 0704539 | 2012-02-19 18:52:44 -0500 | [diff] [blame] | 5489 | }; |
| 5490 | |
| 5491 | static void |
Kristian Høgsberg | e314875 | 2013-05-06 23:19:49 -0400 | [diff] [blame] | 5492 | switcher_binding(struct weston_seat *seat, uint32_t time, uint32_t key, |
Daniel Stone | 325fc2d | 2012-05-30 16:31:58 +0100 | [diff] [blame] | 5493 | void *data) |
Kristian Høgsberg | 0704539 | 2012-02-19 18:52:44 -0500 | [diff] [blame] | 5494 | { |
Tiago Vignatti | be14326 | 2012-04-16 17:31:41 +0300 | [diff] [blame] | 5495 | struct desktop_shell *shell = data; |
Kristian Høgsberg | 0704539 | 2012-02-19 18:52:44 -0500 | [diff] [blame] | 5496 | struct switcher *switcher; |
| 5497 | |
| 5498 | switcher = malloc(sizeof *switcher); |
Kristian Høgsberg | 02e79dc | 2012-04-12 09:55:26 -0400 | [diff] [blame] | 5499 | switcher->shell = shell; |
Kristian Høgsberg | 0704539 | 2012-02-19 18:52:44 -0500 | [diff] [blame] | 5500 | switcher->current = NULL; |
Kristian Høgsberg | 27e3052 | 2012-04-11 23:18:23 -0400 | [diff] [blame] | 5501 | switcher->listener.notify = switcher_handle_surface_destroy; |
Kristian Høgsberg | 0704539 | 2012-02-19 18:52:44 -0500 | [diff] [blame] | 5502 | wl_list_init(&switcher->listener.link); |
Manuel Bachmann | c1ae2e8 | 2014-02-26 15:53:11 +0100 | [diff] [blame] | 5503 | wl_array_init(&switcher->minimized_array); |
Kristian Høgsberg | 0704539 | 2012-02-19 18:52:44 -0500 | [diff] [blame] | 5504 | |
Alexander Larsson | f82b6ca | 2013-05-28 16:23:39 +0200 | [diff] [blame] | 5505 | restore_all_output_modes(shell->compositor); |
Kristian Høgsberg | b0d8e77 | 2012-06-18 16:34:58 -0400 | [diff] [blame] | 5506 | lower_fullscreen_layer(switcher->shell); |
Kristian Høgsberg | 0704539 | 2012-02-19 18:52:44 -0500 | [diff] [blame] | 5507 | switcher->grab.interface = &switcher_grab; |
Kristian Høgsberg | 29139d4 | 2013-04-18 15:25:39 -0400 | [diff] [blame] | 5508 | weston_keyboard_start_grab(seat->keyboard, &switcher->grab); |
| 5509 | weston_keyboard_set_focus(seat->keyboard, NULL); |
Kristian Høgsberg | 0704539 | 2012-02-19 18:52:44 -0500 | [diff] [blame] | 5510 | switcher_next(switcher); |
| 5511 | } |
| 5512 | |
Pekka Paalanen | 3c64723 | 2011-12-22 13:43:43 +0200 | [diff] [blame] | 5513 | static void |
Kristian Høgsberg | e314875 | 2013-05-06 23:19:49 -0400 | [diff] [blame] | 5514 | backlight_binding(struct weston_seat *seat, uint32_t time, uint32_t key, |
Daniel Stone | 325fc2d | 2012-05-30 16:31:58 +0100 | [diff] [blame] | 5515 | void *data) |
Tiago Vignatti | 8e53c7f | 2012-02-29 19:53:50 +0200 | [diff] [blame] | 5516 | { |
| 5517 | struct weston_compositor *compositor = data; |
| 5518 | struct weston_output *output; |
Tiago Vignatti | 5ab91ad | 2012-03-12 19:40:09 -0300 | [diff] [blame] | 5519 | long backlight_new = 0; |
Tiago Vignatti | 8e53c7f | 2012-02-29 19:53:50 +0200 | [diff] [blame] | 5520 | |
| 5521 | /* TODO: we're limiting to simple use cases, where we assume just |
| 5522 | * control on the primary display. We'd have to extend later if we |
| 5523 | * ever get support for setting backlights on random desktop LCD |
| 5524 | * panels though */ |
| 5525 | output = get_default_output(compositor); |
| 5526 | if (!output) |
| 5527 | return; |
| 5528 | |
| 5529 | if (!output->set_backlight) |
| 5530 | return; |
| 5531 | |
Tiago Vignatti | 5ab91ad | 2012-03-12 19:40:09 -0300 | [diff] [blame] | 5532 | if (key == KEY_F9 || key == KEY_BRIGHTNESSDOWN) |
| 5533 | backlight_new = output->backlight_current - 25; |
| 5534 | else if (key == KEY_F10 || key == KEY_BRIGHTNESSUP) |
| 5535 | backlight_new = output->backlight_current + 25; |
Tiago Vignatti | 8e53c7f | 2012-02-29 19:53:50 +0200 | [diff] [blame] | 5536 | |
Tiago Vignatti | 5ab91ad | 2012-03-12 19:40:09 -0300 | [diff] [blame] | 5537 | if (backlight_new < 5) |
| 5538 | backlight_new = 5; |
| 5539 | if (backlight_new > 255) |
| 5540 | backlight_new = 255; |
| 5541 | |
| 5542 | output->backlight_current = backlight_new; |
Tiago Vignatti | 8e53c7f | 2012-02-29 19:53:50 +0200 | [diff] [blame] | 5543 | output->set_backlight(output, output->backlight_current); |
| 5544 | } |
| 5545 | |
Ander Conselvan de Oliveira | c509d2b | 2012-11-08 17:20:45 +0200 | [diff] [blame] | 5546 | struct debug_binding_grab { |
Kristian Høgsberg | 29139d4 | 2013-04-18 15:25:39 -0400 | [diff] [blame] | 5547 | struct weston_keyboard_grab grab; |
Ander Conselvan de Oliveira | c509d2b | 2012-11-08 17:20:45 +0200 | [diff] [blame] | 5548 | struct weston_seat *seat; |
| 5549 | uint32_t key[2]; |
| 5550 | int key_released[2]; |
| 5551 | }; |
| 5552 | |
| 5553 | static void |
Kristian Høgsberg | 29139d4 | 2013-04-18 15:25:39 -0400 | [diff] [blame] | 5554 | 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] | 5555 | uint32_t key, uint32_t state) |
| 5556 | { |
| 5557 | struct debug_binding_grab *db = (struct debug_binding_grab *) grab; |
Rob Bradford | 880ebc7 | 2013-07-22 17:31:38 +0100 | [diff] [blame] | 5558 | struct weston_compositor *ec = db->seat->compositor; |
| 5559 | struct wl_display *display = ec->wl_display; |
Ander Conselvan de Oliveira | c509d2b | 2012-11-08 17:20:45 +0200 | [diff] [blame] | 5560 | struct wl_resource *resource; |
Ander Conselvan de Oliveira | c509d2b | 2012-11-08 17:20:45 +0200 | [diff] [blame] | 5561 | uint32_t serial; |
| 5562 | int send = 0, terminate = 0; |
| 5563 | int check_binding = 1; |
| 5564 | int i; |
Neil Roberts | 96d790e | 2013-09-19 17:32:00 +0100 | [diff] [blame] | 5565 | struct wl_list *resource_list; |
Ander Conselvan de Oliveira | c509d2b | 2012-11-08 17:20:45 +0200 | [diff] [blame] | 5566 | |
| 5567 | if (state == WL_KEYBOARD_KEY_STATE_RELEASED) { |
| 5568 | /* Do not run bindings on key releases */ |
| 5569 | check_binding = 0; |
| 5570 | |
| 5571 | for (i = 0; i < 2; i++) |
| 5572 | if (key == db->key[i]) |
| 5573 | db->key_released[i] = 1; |
| 5574 | |
| 5575 | if (db->key_released[0] && db->key_released[1]) { |
| 5576 | /* All key releases been swalled so end the grab */ |
| 5577 | terminate = 1; |
| 5578 | } else if (key != db->key[0] && key != db->key[1]) { |
| 5579 | /* Should not swallow release of other keys */ |
| 5580 | send = 1; |
| 5581 | } |
| 5582 | } else if (key == db->key[0] && !db->key_released[0]) { |
| 5583 | /* Do not check bindings for the first press of the binding |
| 5584 | * key. This allows it to be used as a debug shortcut. |
| 5585 | * We still need to swallow this event. */ |
| 5586 | check_binding = 0; |
| 5587 | } else if (db->key[1]) { |
| 5588 | /* If we already ran a binding don't process another one since |
| 5589 | * we can't keep track of all the binding keys that were |
| 5590 | * pressed in order to swallow the release events. */ |
| 5591 | send = 1; |
| 5592 | check_binding = 0; |
| 5593 | } |
| 5594 | |
| 5595 | if (check_binding) { |
Ander Conselvan de Oliveira | c509d2b | 2012-11-08 17:20:45 +0200 | [diff] [blame] | 5596 | if (weston_compositor_run_debug_binding(ec, db->seat, time, |
| 5597 | key, state)) { |
| 5598 | /* We ran a binding so swallow the press and keep the |
| 5599 | * grab to swallow the released too. */ |
| 5600 | send = 0; |
| 5601 | terminate = 0; |
| 5602 | db->key[1] = key; |
| 5603 | } else { |
| 5604 | /* Terminate the grab since the key pressed is not a |
| 5605 | * debug binding key. */ |
| 5606 | send = 1; |
| 5607 | terminate = 1; |
| 5608 | } |
| 5609 | } |
| 5610 | |
| 5611 | if (send) { |
Neil Roberts | 96d790e | 2013-09-19 17:32:00 +0100 | [diff] [blame] | 5612 | serial = wl_display_next_serial(display); |
| 5613 | resource_list = &grab->keyboard->focus_resource_list; |
| 5614 | wl_resource_for_each(resource, resource_list) { |
Ander Conselvan de Oliveira | c509d2b | 2012-11-08 17:20:45 +0200 | [diff] [blame] | 5615 | wl_keyboard_send_key(resource, serial, time, key, state); |
| 5616 | } |
| 5617 | } |
| 5618 | |
| 5619 | if (terminate) { |
Kristian Høgsberg | 29139d4 | 2013-04-18 15:25:39 -0400 | [diff] [blame] | 5620 | weston_keyboard_end_grab(grab->keyboard); |
| 5621 | if (grab->keyboard->input_method_resource) |
| 5622 | grab->keyboard->grab = &grab->keyboard->input_method_grab; |
Ander Conselvan de Oliveira | c509d2b | 2012-11-08 17:20:45 +0200 | [diff] [blame] | 5623 | free(db); |
| 5624 | } |
| 5625 | } |
| 5626 | |
| 5627 | static void |
Kristian Høgsberg | 29139d4 | 2013-04-18 15:25:39 -0400 | [diff] [blame] | 5628 | 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] | 5629 | uint32_t mods_depressed, uint32_t mods_latched, |
| 5630 | uint32_t mods_locked, uint32_t group) |
| 5631 | { |
| 5632 | struct wl_resource *resource; |
Neil Roberts | 96d790e | 2013-09-19 17:32:00 +0100 | [diff] [blame] | 5633 | struct wl_list *resource_list; |
Ander Conselvan de Oliveira | c509d2b | 2012-11-08 17:20:45 +0200 | [diff] [blame] | 5634 | |
Neil Roberts | 96d790e | 2013-09-19 17:32:00 +0100 | [diff] [blame] | 5635 | resource_list = &grab->keyboard->focus_resource_list; |
Ander Conselvan de Oliveira | c509d2b | 2012-11-08 17:20:45 +0200 | [diff] [blame] | 5636 | |
Neil Roberts | 96d790e | 2013-09-19 17:32:00 +0100 | [diff] [blame] | 5637 | wl_resource_for_each(resource, resource_list) { |
| 5638 | wl_keyboard_send_modifiers(resource, serial, mods_depressed, |
| 5639 | mods_latched, mods_locked, group); |
| 5640 | } |
Ander Conselvan de Oliveira | c509d2b | 2012-11-08 17:20:45 +0200 | [diff] [blame] | 5641 | } |
| 5642 | |
Jonas Ådahl | 1ea343e | 2013-10-25 23:18:05 +0200 | [diff] [blame] | 5643 | static void |
| 5644 | debug_binding_cancel(struct weston_keyboard_grab *grab) |
| 5645 | { |
| 5646 | struct debug_binding_grab *db = (struct debug_binding_grab *) grab; |
| 5647 | |
| 5648 | weston_keyboard_end_grab(grab->keyboard); |
| 5649 | free(db); |
| 5650 | } |
| 5651 | |
Kristian Høgsberg | 29139d4 | 2013-04-18 15:25:39 -0400 | [diff] [blame] | 5652 | struct weston_keyboard_grab_interface debug_binding_keyboard_grab = { |
Ander Conselvan de Oliveira | c509d2b | 2012-11-08 17:20:45 +0200 | [diff] [blame] | 5653 | debug_binding_key, |
Jonas Ådahl | 1ea343e | 2013-10-25 23:18:05 +0200 | [diff] [blame] | 5654 | debug_binding_modifiers, |
| 5655 | debug_binding_cancel, |
Ander Conselvan de Oliveira | c509d2b | 2012-11-08 17:20:45 +0200 | [diff] [blame] | 5656 | }; |
| 5657 | |
| 5658 | static void |
Kristian Høgsberg | e314875 | 2013-05-06 23:19:49 -0400 | [diff] [blame] | 5659 | 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] | 5660 | { |
| 5661 | struct debug_binding_grab *grab; |
| 5662 | |
| 5663 | grab = calloc(1, sizeof *grab); |
| 5664 | if (!grab) |
| 5665 | return; |
| 5666 | |
| 5667 | grab->seat = (struct weston_seat *) seat; |
| 5668 | grab->key[0] = key; |
| 5669 | grab->grab.interface = &debug_binding_keyboard_grab; |
Kristian Høgsberg | 29139d4 | 2013-04-18 15:25:39 -0400 | [diff] [blame] | 5670 | weston_keyboard_start_grab(seat->keyboard, &grab->grab); |
Ander Conselvan de Oliveira | c509d2b | 2012-11-08 17:20:45 +0200 | [diff] [blame] | 5671 | } |
| 5672 | |
Kristian Høgsberg | b41c081 | 2012-03-04 14:53:40 -0500 | [diff] [blame] | 5673 | static void |
Kristian Høgsberg | e314875 | 2013-05-06 23:19:49 -0400 | [diff] [blame] | 5674 | 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] | 5675 | void *data) |
Kristian Høgsberg | 92a57db | 2012-05-26 13:41:06 -0400 | [diff] [blame] | 5676 | { |
Kristian Høgsberg | fe7aa90 | 2013-05-08 09:54:37 -0400 | [diff] [blame] | 5677 | struct weston_surface *focus_surface; |
Kristian Høgsberg | 92a57db | 2012-05-26 13:41:06 -0400 | [diff] [blame] | 5678 | struct wl_client *client; |
Tiago Vignatti | 1d01b01 | 2012-09-27 17:48:36 +0300 | [diff] [blame] | 5679 | struct desktop_shell *shell = data; |
| 5680 | struct weston_compositor *compositor = shell->compositor; |
Kristian Høgsberg | 92a57db | 2012-05-26 13:41:06 -0400 | [diff] [blame] | 5681 | pid_t pid; |
Kristian Høgsberg | 92a57db | 2012-05-26 13:41:06 -0400 | [diff] [blame] | 5682 | |
Philipp Brüschweiler | 6cef009 | 2012-08-13 21:27:27 +0200 | [diff] [blame] | 5683 | focus_surface = seat->keyboard->focus; |
| 5684 | if (!focus_surface) |
| 5685 | return; |
| 5686 | |
Tiago Vignatti | 1d01b01 | 2012-09-27 17:48:36 +0300 | [diff] [blame] | 5687 | wl_signal_emit(&compositor->kill_signal, focus_surface); |
| 5688 | |
Jason Ekstrand | 26ed73c | 2013-06-06 22:34:41 -0500 | [diff] [blame] | 5689 | client = wl_resource_get_client(focus_surface->resource); |
Tiago Vignatti | 920f197 | 2012-09-27 17:48:35 +0300 | [diff] [blame] | 5690 | wl_client_get_credentials(client, &pid, NULL, NULL); |
| 5691 | |
| 5692 | /* Skip clients that we launched ourselves (the credentials of |
| 5693 | * the socketpair is ours) */ |
| 5694 | if (pid == getpid()) |
| 5695 | return; |
Kristian Høgsberg | 92a57db | 2012-05-26 13:41:06 -0400 | [diff] [blame] | 5696 | |
Daniel Stone | 325fc2d | 2012-05-30 16:31:58 +0100 | [diff] [blame] | 5697 | kill(pid, SIGKILL); |
Kristian Høgsberg | 92a57db | 2012-05-26 13:41:06 -0400 | [diff] [blame] | 5698 | } |
| 5699 | |
| 5700 | static void |
Kristian Høgsberg | e314875 | 2013-05-06 23:19:49 -0400 | [diff] [blame] | 5701 | workspace_up_binding(struct weston_seat *seat, uint32_t time, |
Jonas Ådahl | e3cddce | 2012-06-13 00:01:22 +0200 | [diff] [blame] | 5702 | uint32_t key, void *data) |
| 5703 | { |
| 5704 | struct desktop_shell *shell = data; |
| 5705 | unsigned int new_index = shell->workspaces.current; |
| 5706 | |
Kristian Høgsberg | ce345b0 | 2012-06-25 21:35:29 -0400 | [diff] [blame] | 5707 | if (shell->locked) |
Kristian Høgsberg | 4476aaf | 2012-06-25 14:03:13 -0400 | [diff] [blame] | 5708 | return; |
Jonas Ådahl | e3cddce | 2012-06-13 00:01:22 +0200 | [diff] [blame] | 5709 | if (new_index != 0) |
| 5710 | new_index--; |
| 5711 | |
| 5712 | change_workspace(shell, new_index); |
| 5713 | } |
| 5714 | |
| 5715 | static void |
Kristian Høgsberg | e314875 | 2013-05-06 23:19:49 -0400 | [diff] [blame] | 5716 | workspace_down_binding(struct weston_seat *seat, uint32_t time, |
Jonas Ådahl | e3cddce | 2012-06-13 00:01:22 +0200 | [diff] [blame] | 5717 | uint32_t key, void *data) |
| 5718 | { |
| 5719 | struct desktop_shell *shell = data; |
| 5720 | unsigned int new_index = shell->workspaces.current; |
| 5721 | |
Kristian Høgsberg | ce345b0 | 2012-06-25 21:35:29 -0400 | [diff] [blame] | 5722 | if (shell->locked) |
Kristian Høgsberg | 4476aaf | 2012-06-25 14:03:13 -0400 | [diff] [blame] | 5723 | return; |
Jonas Ådahl | e3cddce | 2012-06-13 00:01:22 +0200 | [diff] [blame] | 5724 | if (new_index < shell->workspaces.num - 1) |
| 5725 | new_index++; |
| 5726 | |
| 5727 | change_workspace(shell, new_index); |
| 5728 | } |
| 5729 | |
| 5730 | static void |
Kristian Høgsberg | e314875 | 2013-05-06 23:19:49 -0400 | [diff] [blame] | 5731 | workspace_f_binding(struct weston_seat *seat, uint32_t time, |
Jonas Ådahl | e3cddce | 2012-06-13 00:01:22 +0200 | [diff] [blame] | 5732 | uint32_t key, void *data) |
| 5733 | { |
| 5734 | struct desktop_shell *shell = data; |
| 5735 | unsigned int new_index; |
| 5736 | |
Kristian Høgsberg | ce345b0 | 2012-06-25 21:35:29 -0400 | [diff] [blame] | 5737 | if (shell->locked) |
Kristian Høgsberg | 4476aaf | 2012-06-25 14:03:13 -0400 | [diff] [blame] | 5738 | return; |
Jonas Ådahl | e3cddce | 2012-06-13 00:01:22 +0200 | [diff] [blame] | 5739 | new_index = key - KEY_F1; |
| 5740 | if (new_index >= shell->workspaces.num) |
| 5741 | new_index = shell->workspaces.num - 1; |
| 5742 | |
| 5743 | change_workspace(shell, new_index); |
| 5744 | } |
| 5745 | |
Jonas Ådahl | 8de6a1d | 2012-08-29 22:13:00 +0200 | [diff] [blame] | 5746 | static void |
Kristian Høgsberg | e314875 | 2013-05-06 23:19:49 -0400 | [diff] [blame] | 5747 | workspace_move_surface_up_binding(struct weston_seat *seat, uint32_t time, |
Jonas Ådahl | 8de6a1d | 2012-08-29 22:13:00 +0200 | [diff] [blame] | 5748 | uint32_t key, void *data) |
| 5749 | { |
| 5750 | struct desktop_shell *shell = data; |
| 5751 | unsigned int new_index = shell->workspaces.current; |
| 5752 | |
| 5753 | if (shell->locked) |
| 5754 | return; |
| 5755 | |
| 5756 | if (new_index != 0) |
| 5757 | new_index--; |
| 5758 | |
| 5759 | take_surface_to_workspace_by_seat(shell, seat, new_index); |
| 5760 | } |
| 5761 | |
| 5762 | static void |
Kristian Høgsberg | e314875 | 2013-05-06 23:19:49 -0400 | [diff] [blame] | 5763 | workspace_move_surface_down_binding(struct weston_seat *seat, uint32_t time, |
Jonas Ådahl | 8de6a1d | 2012-08-29 22:13:00 +0200 | [diff] [blame] | 5764 | uint32_t key, void *data) |
| 5765 | { |
| 5766 | struct desktop_shell *shell = data; |
| 5767 | unsigned int new_index = shell->workspaces.current; |
| 5768 | |
| 5769 | if (shell->locked) |
| 5770 | return; |
| 5771 | |
| 5772 | if (new_index < shell->workspaces.num - 1) |
| 5773 | new_index++; |
| 5774 | |
| 5775 | take_surface_to_workspace_by_seat(shell, seat, new_index); |
| 5776 | } |
Jonas Ådahl | e3cddce | 2012-06-13 00:01:22 +0200 | [diff] [blame] | 5777 | |
| 5778 | static void |
Ander Conselvan de Oliveira | c94d622 | 2014-01-29 18:47:54 +0200 | [diff] [blame] | 5779 | shell_reposition_view_on_output_destroy(struct weston_view *view) |
| 5780 | { |
| 5781 | struct weston_output *output, *first_output; |
| 5782 | struct weston_compositor *ec = view->surface->compositor; |
| 5783 | struct shell_surface *shsurf; |
| 5784 | float x, y; |
| 5785 | int visible; |
| 5786 | |
| 5787 | x = view->geometry.x; |
| 5788 | y = view->geometry.y; |
| 5789 | |
| 5790 | /* At this point the destroyed output is not in the list anymore. |
| 5791 | * If the view is still visible somewhere, we leave where it is, |
| 5792 | * otherwise, move it to the first output. */ |
| 5793 | visible = 0; |
| 5794 | wl_list_for_each(output, &ec->output_list, link) { |
| 5795 | if (pixman_region32_contains_point(&output->region, |
| 5796 | x, y, NULL)) { |
| 5797 | visible = 1; |
| 5798 | break; |
| 5799 | } |
| 5800 | } |
| 5801 | |
| 5802 | if (!visible) { |
| 5803 | first_output = container_of(ec->output_list.next, |
| 5804 | struct weston_output, link); |
| 5805 | |
| 5806 | x = first_output->x + first_output->width / 4; |
| 5807 | y = first_output->y + first_output->height / 4; |
Xiong Zhang | 62899f5 | 2014-03-07 16:27:19 +0800 | [diff] [blame] | 5808 | |
| 5809 | weston_view_set_position(view, x, y); |
| 5810 | } else { |
| 5811 | weston_view_geometry_dirty(view); |
Ander Conselvan de Oliveira | c94d622 | 2014-01-29 18:47:54 +0200 | [diff] [blame] | 5812 | } |
| 5813 | |
Ander Conselvan de Oliveira | c94d622 | 2014-01-29 18:47:54 +0200 | [diff] [blame] | 5814 | |
| 5815 | shsurf = get_shell_surface(view->surface); |
| 5816 | |
| 5817 | if (shsurf) { |
| 5818 | shsurf->saved_position_valid = false; |
| 5819 | shsurf->next_state.maximized = false; |
| 5820 | shsurf->next_state.fullscreen = false; |
| 5821 | shsurf->state_changed = true; |
| 5822 | } |
| 5823 | } |
| 5824 | |
Ander Conselvan de Oliveira | 304996d | 2014-04-11 13:57:15 +0300 | [diff] [blame] | 5825 | void |
| 5826 | shell_for_each_layer(struct desktop_shell *shell, |
| 5827 | shell_for_each_layer_func_t func, void *data) |
Ander Conselvan de Oliveira | c94d622 | 2014-01-29 18:47:54 +0200 | [diff] [blame] | 5828 | { |
Ander Conselvan de Oliveira | 304996d | 2014-04-11 13:57:15 +0300 | [diff] [blame] | 5829 | struct workspace **ws; |
| 5830 | |
| 5831 | func(shell, &shell->fullscreen_layer, data); |
| 5832 | func(shell, &shell->panel_layer, data); |
| 5833 | func(shell, &shell->background_layer, data); |
| 5834 | func(shell, &shell->lock_layer, data); |
| 5835 | func(shell, &shell->input_panel_layer, data); |
| 5836 | |
| 5837 | wl_array_for_each(ws, &shell->workspaces.array) |
| 5838 | func(shell, &(*ws)->layer, data); |
| 5839 | } |
| 5840 | |
| 5841 | static void |
| 5842 | shell_output_destroy_move_layer(struct desktop_shell *shell, |
| 5843 | struct weston_layer *layer, |
| 5844 | void *data) |
| 5845 | { |
| 5846 | struct weston_output *output = data; |
Ander Conselvan de Oliveira | c94d622 | 2014-01-29 18:47:54 +0200 | [diff] [blame] | 5847 | struct weston_view *view; |
| 5848 | |
Ander Conselvan de Oliveira | 304996d | 2014-04-11 13:57:15 +0300 | [diff] [blame] | 5849 | wl_list_for_each(view, &layer->view_list, layer_link) { |
| 5850 | if (view->output != output) |
| 5851 | continue; |
Ander Conselvan de Oliveira | c94d622 | 2014-01-29 18:47:54 +0200 | [diff] [blame] | 5852 | |
Ander Conselvan de Oliveira | 304996d | 2014-04-11 13:57:15 +0300 | [diff] [blame] | 5853 | shell_reposition_view_on_output_destroy(view); |
Ander Conselvan de Oliveira | c94d622 | 2014-01-29 18:47:54 +0200 | [diff] [blame] | 5854 | } |
| 5855 | } |
| 5856 | |
| 5857 | static void |
Xiong Zhang | 6b48142 | 2013-10-23 13:58:32 +0800 | [diff] [blame] | 5858 | handle_output_destroy(struct wl_listener *listener, void *data) |
| 5859 | { |
| 5860 | struct shell_output *output_listener = |
| 5861 | container_of(listener, struct shell_output, destroy_listener); |
Ander Conselvan de Oliveira | 304996d | 2014-04-11 13:57:15 +0300 | [diff] [blame] | 5862 | struct weston_output *output = output_listener->output; |
| 5863 | struct desktop_shell *shell = output_listener->shell; |
Xiong Zhang | 6b48142 | 2013-10-23 13:58:32 +0800 | [diff] [blame] | 5864 | |
Ander Conselvan de Oliveira | 304996d | 2014-04-11 13:57:15 +0300 | [diff] [blame] | 5865 | 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] | 5866 | |
Xiong Zhang | 6b48142 | 2013-10-23 13:58:32 +0800 | [diff] [blame] | 5867 | wl_list_remove(&output_listener->destroy_listener.link); |
| 5868 | wl_list_remove(&output_listener->link); |
| 5869 | free(output_listener); |
| 5870 | } |
| 5871 | |
| 5872 | static void |
| 5873 | create_shell_output(struct desktop_shell *shell, |
| 5874 | struct weston_output *output) |
| 5875 | { |
| 5876 | struct shell_output *shell_output; |
| 5877 | |
| 5878 | shell_output = zalloc(sizeof *shell_output); |
| 5879 | if (shell_output == NULL) |
| 5880 | return; |
| 5881 | |
| 5882 | shell_output->output = output; |
| 5883 | shell_output->shell = shell; |
| 5884 | shell_output->destroy_listener.notify = handle_output_destroy; |
| 5885 | wl_signal_add(&output->destroy_signal, |
| 5886 | &shell_output->destroy_listener); |
Kristian Høgsberg | a3a0e18 | 2013-10-23 23:36:04 -0700 | [diff] [blame] | 5887 | wl_list_insert(shell->output_list.prev, &shell_output->link); |
Xiong Zhang | 6b48142 | 2013-10-23 13:58:32 +0800 | [diff] [blame] | 5888 | } |
| 5889 | |
| 5890 | static void |
| 5891 | handle_output_create(struct wl_listener *listener, void *data) |
| 5892 | { |
| 5893 | struct desktop_shell *shell = |
| 5894 | container_of(listener, struct desktop_shell, output_create_listener); |
| 5895 | struct weston_output *output = (struct weston_output *)data; |
| 5896 | |
| 5897 | create_shell_output(shell, output); |
| 5898 | } |
| 5899 | |
| 5900 | static void |
Ander Conselvan de Oliveira | 304996d | 2014-04-11 13:57:15 +0300 | [diff] [blame] | 5901 | handle_output_move_layer(struct desktop_shell *shell, |
| 5902 | struct weston_layer *layer, void *data) |
Ander Conselvan de Oliveira | a8a9baf | 2014-01-29 18:47:52 +0200 | [diff] [blame] | 5903 | { |
Ander Conselvan de Oliveira | 304996d | 2014-04-11 13:57:15 +0300 | [diff] [blame] | 5904 | struct weston_output *output = data; |
Ander Conselvan de Oliveira | a8a9baf | 2014-01-29 18:47:52 +0200 | [diff] [blame] | 5905 | struct weston_view *view; |
| 5906 | float x, y; |
| 5907 | |
Ander Conselvan de Oliveira | 304996d | 2014-04-11 13:57:15 +0300 | [diff] [blame] | 5908 | wl_list_for_each(view, &layer->view_list, layer_link) { |
| 5909 | if (view->output != output) |
| 5910 | continue; |
| 5911 | |
| 5912 | x = view->geometry.x + output->move_x; |
| 5913 | y = view->geometry.y + output->move_y; |
| 5914 | weston_view_set_position(view, x, y); |
| 5915 | } |
| 5916 | } |
| 5917 | |
| 5918 | static void |
| 5919 | handle_output_move(struct wl_listener *listener, void *data) |
| 5920 | { |
| 5921 | struct desktop_shell *shell; |
| 5922 | |
Ander Conselvan de Oliveira | a8a9baf | 2014-01-29 18:47:52 +0200 | [diff] [blame] | 5923 | shell = container_of(listener, struct desktop_shell, |
| 5924 | output_move_listener); |
Ander Conselvan de Oliveira | a8a9baf | 2014-01-29 18:47:52 +0200 | [diff] [blame] | 5925 | |
Ander Conselvan de Oliveira | 304996d | 2014-04-11 13:57:15 +0300 | [diff] [blame] | 5926 | shell_for_each_layer(shell, handle_output_move_layer, data); |
Ander Conselvan de Oliveira | a8a9baf | 2014-01-29 18:47:52 +0200 | [diff] [blame] | 5927 | } |
| 5928 | |
| 5929 | static void |
Xiong Zhang | 6b48142 | 2013-10-23 13:58:32 +0800 | [diff] [blame] | 5930 | setup_output_destroy_handler(struct weston_compositor *ec, |
| 5931 | struct desktop_shell *shell) |
| 5932 | { |
| 5933 | struct weston_output *output; |
| 5934 | |
| 5935 | wl_list_init(&shell->output_list); |
| 5936 | wl_list_for_each(output, &ec->output_list, link) |
| 5937 | create_shell_output(shell, output); |
| 5938 | |
| 5939 | shell->output_create_listener.notify = handle_output_create; |
| 5940 | wl_signal_add(&ec->output_created_signal, |
| 5941 | &shell->output_create_listener); |
Ander Conselvan de Oliveira | a8a9baf | 2014-01-29 18:47:52 +0200 | [diff] [blame] | 5942 | |
| 5943 | shell->output_move_listener.notify = handle_output_move; |
| 5944 | wl_signal_add(&ec->output_moved_signal, &shell->output_move_listener); |
Xiong Zhang | 6b48142 | 2013-10-23 13:58:32 +0800 | [diff] [blame] | 5945 | } |
| 5946 | |
| 5947 | static void |
Kristian Høgsberg | 02e79dc | 2012-04-12 09:55:26 -0400 | [diff] [blame] | 5948 | shell_destroy(struct wl_listener *listener, void *data) |
Pekka Paalanen | 3c64723 | 2011-12-22 13:43:43 +0200 | [diff] [blame] | 5949 | { |
Tiago Vignatti | be14326 | 2012-04-16 17:31:41 +0300 | [diff] [blame] | 5950 | struct desktop_shell *shell = |
| 5951 | container_of(listener, struct desktop_shell, destroy_listener); |
Jonas Ådahl | e3cddce | 2012-06-13 00:01:22 +0200 | [diff] [blame] | 5952 | struct workspace **ws; |
Xiong Zhang | 6b48142 | 2013-10-23 13:58:32 +0800 | [diff] [blame] | 5953 | struct shell_output *shell_output, *tmp; |
Pekka Paalanen | 3c64723 | 2011-12-22 13:43:43 +0200 | [diff] [blame] | 5954 | |
Kristian Høgsberg | 17bccae | 2014-01-16 16:46:28 -0800 | [diff] [blame] | 5955 | /* Force state to unlocked so we don't try to fade */ |
| 5956 | shell->locked = false; |
Pekka Paalanen | 9cf5cc8 | 2012-01-02 16:00:24 +0200 | [diff] [blame] | 5957 | if (shell->child.client) |
| 5958 | wl_client_destroy(shell->child.client); |
| 5959 | |
Ander Conselvan de Oliveira | a457563 | 2013-02-21 18:35:23 +0200 | [diff] [blame] | 5960 | wl_list_remove(&shell->idle_listener.link); |
| 5961 | wl_list_remove(&shell->wake_listener.link); |
Kristian Høgsberg | 677a5f5 | 2013-12-04 11:00:19 -0800 | [diff] [blame] | 5962 | |
| 5963 | input_panel_destroy(shell); |
Kristian Høgsberg | 88c1607 | 2012-05-16 08:04:19 -0400 | [diff] [blame] | 5964 | |
Xiong Zhang | 6b48142 | 2013-10-23 13:58:32 +0800 | [diff] [blame] | 5965 | wl_list_for_each_safe(shell_output, tmp, &shell->output_list, link) { |
| 5966 | wl_list_remove(&shell_output->destroy_listener.link); |
| 5967 | wl_list_remove(&shell_output->link); |
| 5968 | free(shell_output); |
| 5969 | } |
| 5970 | |
| 5971 | wl_list_remove(&shell->output_create_listener.link); |
| 5972 | |
Jonas Ådahl | e3cddce | 2012-06-13 00:01:22 +0200 | [diff] [blame] | 5973 | wl_array_for_each(ws, &shell->workspaces.array) |
| 5974 | workspace_destroy(*ws); |
| 5975 | wl_array_release(&shell->workspaces.array); |
| 5976 | |
Pekka Paalanen | 3c64723 | 2011-12-22 13:43:43 +0200 | [diff] [blame] | 5977 | free(shell->screensaver.path); |
Emilio Pozuelo Monfort | 46ce798 | 2013-11-20 13:22:29 +0100 | [diff] [blame] | 5978 | free(shell->client); |
Pekka Paalanen | 3c64723 | 2011-12-22 13:43:43 +0200 | [diff] [blame] | 5979 | free(shell); |
| 5980 | } |
| 5981 | |
Tiago Vignatti | 0b52d48 | 2012-04-20 18:54:25 +0300 | [diff] [blame] | 5982 | static void |
| 5983 | shell_add_bindings(struct weston_compositor *ec, struct desktop_shell *shell) |
| 5984 | { |
| 5985 | uint32_t mod; |
Jonas Ådahl | e3cddce | 2012-06-13 00:01:22 +0200 | [diff] [blame] | 5986 | int i, num_workspace_bindings; |
Tiago Vignatti | 0b52d48 | 2012-04-20 18:54:25 +0300 | [diff] [blame] | 5987 | |
| 5988 | /* fixed bindings */ |
Daniel Stone | 325fc2d | 2012-05-30 16:31:58 +0100 | [diff] [blame] | 5989 | weston_compositor_add_key_binding(ec, KEY_BACKSPACE, |
| 5990 | MODIFIER_CTRL | MODIFIER_ALT, |
| 5991 | terminate_binding, ec); |
| 5992 | weston_compositor_add_button_binding(ec, BTN_LEFT, 0, |
| 5993 | click_to_activate_binding, |
| 5994 | shell); |
Kristian Høgsberg | f0ce581 | 2014-04-07 11:52:17 -0700 | [diff] [blame] | 5995 | weston_compositor_add_button_binding(ec, BTN_RIGHT, 0, |
| 5996 | click_to_activate_binding, |
| 5997 | shell); |
Neil Roberts | a28c693 | 2013-10-03 16:43:04 +0100 | [diff] [blame] | 5998 | weston_compositor_add_touch_binding(ec, 0, |
| 5999 | touch_to_activate_binding, |
| 6000 | shell); |
Daniel Stone | 325fc2d | 2012-05-30 16:31:58 +0100 | [diff] [blame] | 6001 | weston_compositor_add_axis_binding(ec, WL_POINTER_AXIS_VERTICAL_SCROLL, |
| 6002 | MODIFIER_SUPER | MODIFIER_ALT, |
| 6003 | surface_opacity_binding, NULL); |
| 6004 | weston_compositor_add_axis_binding(ec, WL_POINTER_AXIS_VERTICAL_SCROLL, |
| 6005 | MODIFIER_SUPER, zoom_axis_binding, |
| 6006 | NULL); |
Tiago Vignatti | 0b52d48 | 2012-04-20 18:54:25 +0300 | [diff] [blame] | 6007 | |
| 6008 | /* configurable bindings */ |
| 6009 | mod = shell->binding_modifier; |
Daniel Stone | 325fc2d | 2012-05-30 16:31:58 +0100 | [diff] [blame] | 6010 | weston_compositor_add_key_binding(ec, KEY_PAGEUP, mod, |
| 6011 | zoom_key_binding, NULL); |
| 6012 | weston_compositor_add_key_binding(ec, KEY_PAGEDOWN, mod, |
| 6013 | zoom_key_binding, NULL); |
Kristian Høgsberg | 211b517 | 2014-01-11 13:10:21 -0800 | [diff] [blame] | 6014 | weston_compositor_add_key_binding(ec, KEY_M, mod | MODIFIER_SHIFT, |
| 6015 | maximize_binding, NULL); |
| 6016 | weston_compositor_add_key_binding(ec, KEY_F, mod | MODIFIER_SHIFT, |
| 6017 | fullscreen_binding, NULL); |
Daniel Stone | 325fc2d | 2012-05-30 16:31:58 +0100 | [diff] [blame] | 6018 | weston_compositor_add_button_binding(ec, BTN_LEFT, mod, move_binding, |
| 6019 | shell); |
Neil Roberts | aba0f25 | 2013-10-03 16:43:05 +0100 | [diff] [blame] | 6020 | weston_compositor_add_touch_binding(ec, mod, touch_move_binding, shell); |
Daniel Stone | 325fc2d | 2012-05-30 16:31:58 +0100 | [diff] [blame] | 6021 | weston_compositor_add_button_binding(ec, BTN_MIDDLE, mod, |
| 6022 | resize_binding, shell); |
Kristian Høgsberg | 0837fa9 | 2014-01-20 10:35:26 -0800 | [diff] [blame] | 6023 | weston_compositor_add_button_binding(ec, BTN_LEFT, |
| 6024 | mod | MODIFIER_SHIFT, |
| 6025 | resize_binding, shell); |
Pekka Paalanen | 7bb6510 | 2013-05-22 18:03:04 +0300 | [diff] [blame] | 6026 | |
| 6027 | if (ec->capabilities & WESTON_CAP_ROTATION_ANY) |
| 6028 | weston_compositor_add_button_binding(ec, BTN_RIGHT, mod, |
| 6029 | rotate_binding, NULL); |
| 6030 | |
Daniel Stone | 325fc2d | 2012-05-30 16:31:58 +0100 | [diff] [blame] | 6031 | weston_compositor_add_key_binding(ec, KEY_TAB, mod, switcher_binding, |
| 6032 | shell); |
| 6033 | weston_compositor_add_key_binding(ec, KEY_F9, mod, backlight_binding, |
| 6034 | ec); |
| 6035 | weston_compositor_add_key_binding(ec, KEY_BRIGHTNESSDOWN, 0, |
| 6036 | backlight_binding, ec); |
| 6037 | weston_compositor_add_key_binding(ec, KEY_F10, mod, backlight_binding, |
| 6038 | ec); |
| 6039 | weston_compositor_add_key_binding(ec, KEY_BRIGHTNESSUP, 0, |
| 6040 | backlight_binding, ec); |
Daniel Stone | 325fc2d | 2012-05-30 16:31:58 +0100 | [diff] [blame] | 6041 | weston_compositor_add_key_binding(ec, KEY_K, mod, |
| 6042 | force_kill_binding, shell); |
Jonas Ådahl | e3cddce | 2012-06-13 00:01:22 +0200 | [diff] [blame] | 6043 | weston_compositor_add_key_binding(ec, KEY_UP, mod, |
| 6044 | workspace_up_binding, shell); |
| 6045 | weston_compositor_add_key_binding(ec, KEY_DOWN, mod, |
| 6046 | workspace_down_binding, shell); |
Jonas Ådahl | 8de6a1d | 2012-08-29 22:13:00 +0200 | [diff] [blame] | 6047 | weston_compositor_add_key_binding(ec, KEY_UP, mod | MODIFIER_SHIFT, |
| 6048 | workspace_move_surface_up_binding, |
| 6049 | shell); |
| 6050 | weston_compositor_add_key_binding(ec, KEY_DOWN, mod | MODIFIER_SHIFT, |
| 6051 | workspace_move_surface_down_binding, |
| 6052 | shell); |
Jonas Ådahl | e3cddce | 2012-06-13 00:01:22 +0200 | [diff] [blame] | 6053 | |
Kristian Høgsberg | d56ab4e | 2014-01-16 16:51:52 -0800 | [diff] [blame] | 6054 | if (shell->exposay_modifier) |
| 6055 | weston_compositor_add_modifier_binding(ec, shell->exposay_modifier, |
| 6056 | exposay_binding, shell); |
Daniel Stone | df8133b | 2013-11-19 11:37:14 +0100 | [diff] [blame] | 6057 | |
Jonas Ådahl | e3cddce | 2012-06-13 00:01:22 +0200 | [diff] [blame] | 6058 | /* Add bindings for mod+F[1-6] for workspace 1 to 6. */ |
| 6059 | if (shell->workspaces.num > 1) { |
| 6060 | num_workspace_bindings = shell->workspaces.num; |
| 6061 | if (num_workspace_bindings > 6) |
| 6062 | num_workspace_bindings = 6; |
| 6063 | for (i = 0; i < num_workspace_bindings; i++) |
| 6064 | weston_compositor_add_key_binding(ec, KEY_F1 + i, mod, |
| 6065 | workspace_f_binding, |
| 6066 | shell); |
| 6067 | } |
Ander Conselvan de Oliveira | c509d2b | 2012-11-08 17:20:45 +0200 | [diff] [blame] | 6068 | |
| 6069 | /* Debug bindings */ |
| 6070 | weston_compositor_add_key_binding(ec, KEY_SPACE, mod | MODIFIER_SHIFT, |
| 6071 | debug_binding, shell); |
Tiago Vignatti | 0b52d48 | 2012-04-20 18:54:25 +0300 | [diff] [blame] | 6072 | } |
| 6073 | |
Jason Ekstrand | 024177c | 2014-04-21 19:42:58 -0500 | [diff] [blame] | 6074 | static void |
| 6075 | handle_seat_created(struct wl_listener *listener, void *data) |
| 6076 | { |
| 6077 | struct weston_seat *seat = data; |
| 6078 | |
| 6079 | create_shell_seat(seat); |
| 6080 | } |
| 6081 | |
Kristian Høgsberg | 1c56218 | 2011-05-02 22:09:20 -0400 | [diff] [blame] | 6082 | WL_EXPORT int |
Kristian Høgsberg | cb4685b | 2013-02-20 15:37:49 -0500 | [diff] [blame] | 6083 | module_init(struct weston_compositor *ec, |
Ossama Othman | a50e6e4 | 2013-05-14 09:48:26 -0700 | [diff] [blame] | 6084 | int *argc, char *argv[]) |
Kristian Høgsberg | 4cca349 | 2011-01-18 07:53:49 -0500 | [diff] [blame] | 6085 | { |
Kristian Høgsberg | f4d2f23 | 2012-08-10 10:05:39 -0400 | [diff] [blame] | 6086 | struct weston_seat *seat; |
Tiago Vignatti | be14326 | 2012-04-16 17:31:41 +0300 | [diff] [blame] | 6087 | struct desktop_shell *shell; |
Jonas Ådahl | e3cddce | 2012-06-13 00:01:22 +0200 | [diff] [blame] | 6088 | struct workspace **pws; |
| 6089 | unsigned int i; |
Tiago Vignatti | b7dbbd6 | 2012-09-25 17:57:01 +0300 | [diff] [blame] | 6090 | struct wl_event_loop *loop; |
Kristian Høgsberg | 02ec0a5 | 2011-04-23 13:04:11 -0400 | [diff] [blame] | 6091 | |
Peter Hutterer | f3d6227 | 2013-08-08 11:57:05 +1000 | [diff] [blame] | 6092 | shell = zalloc(sizeof *shell); |
Kristian Høgsberg | 02ec0a5 | 2011-04-23 13:04:11 -0400 | [diff] [blame] | 6093 | if (shell == NULL) |
| 6094 | return -1; |
| 6095 | |
Kristian Høgsberg | 7584062 | 2011-09-06 13:48:16 -0400 | [diff] [blame] | 6096 | shell->compositor = ec; |
Kristian Høgsberg | 02e79dc | 2012-04-12 09:55:26 -0400 | [diff] [blame] | 6097 | |
| 6098 | shell->destroy_listener.notify = shell_destroy; |
| 6099 | wl_signal_add(&ec->destroy_signal, &shell->destroy_listener); |
Ander Conselvan de Oliveira | a457563 | 2013-02-21 18:35:23 +0200 | [diff] [blame] | 6100 | shell->idle_listener.notify = idle_handler; |
| 6101 | wl_signal_add(&ec->idle_signal, &shell->idle_listener); |
| 6102 | shell->wake_listener.notify = wake_handler; |
| 6103 | wl_signal_add(&ec->wake_signal, &shell->wake_listener); |
Kristian Høgsberg | 677a5f5 | 2013-12-04 11:00:19 -0800 | [diff] [blame] | 6104 | |
Kristian Høgsberg | 82a1d11 | 2012-07-19 14:02:00 -0400 | [diff] [blame] | 6105 | ec->shell_interface.shell = shell; |
Tiago Vignatti | bc052c9 | 2012-04-19 16:18:18 +0300 | [diff] [blame] | 6106 | ec->shell_interface.create_shell_surface = create_shell_surface; |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 6107 | ec->shell_interface.get_primary_view = get_primary_view; |
Tiago Vignatti | bc052c9 | 2012-04-19 16:18:18 +0300 | [diff] [blame] | 6108 | ec->shell_interface.set_toplevel = set_toplevel; |
Tiago Vignatti | 491bac1 | 2012-05-18 16:37:43 -0400 | [diff] [blame] | 6109 | ec->shell_interface.set_transient = set_transient; |
Kristian Høgsberg | b810eb5 | 2013-02-12 20:07:05 -0500 | [diff] [blame] | 6110 | ec->shell_interface.set_fullscreen = set_fullscreen; |
Tiago Vignatti | fb2adba | 2013-06-12 15:43:21 -0300 | [diff] [blame] | 6111 | ec->shell_interface.set_xwayland = set_xwayland; |
Kristian Høgsberg | ae356ae | 2014-04-29 16:03:54 -0700 | [diff] [blame] | 6112 | ec->shell_interface.move = shell_interface_move; |
Kristian Høgsberg | c1693f2 | 2012-05-22 16:56:23 -0400 | [diff] [blame] | 6113 | ec->shell_interface.resize = surface_resize; |
Giulio Camuffo | 62942ad | 2013-09-11 18:20:47 +0200 | [diff] [blame] | 6114 | ec->shell_interface.set_title = set_title; |
Kristian Høgsberg | 4cca349 | 2011-01-18 07:53:49 -0500 | [diff] [blame] | 6115 | |
Kristian Høgsberg | 3be2ce9 | 2012-02-29 12:42:35 -0500 | [diff] [blame] | 6116 | weston_layer_init(&shell->fullscreen_layer, &ec->cursor_layer.link); |
| 6117 | weston_layer_init(&shell->panel_layer, &shell->fullscreen_layer.link); |
Jonas Ådahl | e3cddce | 2012-06-13 00:01:22 +0200 | [diff] [blame] | 6118 | weston_layer_init(&shell->background_layer, &shell->panel_layer.link); |
| 6119 | weston_layer_init(&shell->lock_layer, NULL); |
Philipp Brüschweiler | 711fda8 | 2012-08-09 18:50:43 +0200 | [diff] [blame] | 6120 | weston_layer_init(&shell->input_panel_layer, NULL); |
Jonas Ådahl | e3cddce | 2012-06-13 00:01:22 +0200 | [diff] [blame] | 6121 | |
| 6122 | wl_array_init(&shell->workspaces.array); |
Jonas Ådahl | e9d2250 | 2012-08-29 22:13:01 +0200 | [diff] [blame] | 6123 | wl_list_init(&shell->workspaces.client_list); |
Kristian Høgsberg | 3be2ce9 | 2012-02-29 12:42:35 -0500 | [diff] [blame] | 6124 | |
Kristian Høgsberg | 677a5f5 | 2013-12-04 11:00:19 -0800 | [diff] [blame] | 6125 | if (input_panel_setup(shell) < 0) |
| 6126 | return -1; |
| 6127 | |
Kristian Høgsberg | 14e438c | 2013-05-26 21:48:14 -0400 | [diff] [blame] | 6128 | shell_configuration(shell); |
Pekka Paalanen | e955f1e | 2011-12-07 11:49:52 +0200 | [diff] [blame] | 6129 | |
Daniel Stone | df8133b | 2013-11-19 11:37:14 +0100 | [diff] [blame] | 6130 | shell->exposay.state_cur = EXPOSAY_LAYOUT_INACTIVE; |
| 6131 | shell->exposay.state_target = EXPOSAY_TARGET_CANCEL; |
| 6132 | |
Jonas Ådahl | e3cddce | 2012-06-13 00:01:22 +0200 | [diff] [blame] | 6133 | for (i = 0; i < shell->workspaces.num; i++) { |
| 6134 | pws = wl_array_add(&shell->workspaces.array, sizeof *pws); |
| 6135 | if (pws == NULL) |
| 6136 | return -1; |
| 6137 | |
| 6138 | *pws = workspace_create(); |
| 6139 | if (*pws == NULL) |
| 6140 | return -1; |
| 6141 | } |
| 6142 | activate_workspace(shell, 0); |
| 6143 | |
Manuel Bachmann | 50c87db | 2014-02-26 15:52:13 +0100 | [diff] [blame] | 6144 | weston_layer_init(&shell->minimized_layer, NULL); |
| 6145 | |
Jonas Ådahl | 8de6a1d | 2012-08-29 22:13:00 +0200 | [diff] [blame] | 6146 | wl_list_init(&shell->workspaces.anim_sticky_list); |
Jonas Ådahl | 62fcd04 | 2012-06-13 00:01:23 +0200 | [diff] [blame] | 6147 | wl_list_init(&shell->workspaces.animation.link); |
| 6148 | shell->workspaces.animation.frame = animate_workspace_change_frame; |
| 6149 | |
Kristian Høgsberg | 919cddb | 2013-07-08 19:03:57 -0400 | [diff] [blame] | 6150 | if (wl_global_create(ec->wl_display, &wl_shell_interface, 1, |
Kristian Høgsberg | 97d44aa | 2011-08-26 17:21:20 -0400 | [diff] [blame] | 6151 | shell, bind_shell) == NULL) |
Kristian Høgsberg | 4cca349 | 2011-01-18 07:53:49 -0500 | [diff] [blame] | 6152 | return -1; |
| 6153 | |
Rafael Antognolli | e2a3455 | 2013-12-03 15:35:45 -0200 | [diff] [blame] | 6154 | if (wl_global_create(ec->wl_display, &xdg_shell_interface, 1, |
| 6155 | shell, bind_xdg_shell) == NULL) |
| 6156 | return -1; |
| 6157 | |
Kristian Høgsberg | 919cddb | 2013-07-08 19:03:57 -0400 | [diff] [blame] | 6158 | if (wl_global_create(ec->wl_display, |
| 6159 | &desktop_shell_interface, 2, |
| 6160 | shell, bind_desktop_shell) == NULL) |
Kristian Høgsberg | 7584062 | 2011-09-06 13:48:16 -0400 | [diff] [blame] | 6161 | return -1; |
| 6162 | |
Kristian Høgsberg | 919cddb | 2013-07-08 19:03:57 -0400 | [diff] [blame] | 6163 | if (wl_global_create(ec->wl_display, &screensaver_interface, 1, |
| 6164 | shell, bind_screensaver) == NULL) |
Pekka Paalanen | 6e16811 | 2011-11-24 11:34:05 +0200 | [diff] [blame] | 6165 | return -1; |
| 6166 | |
Kristian Høgsberg | 919cddb | 2013-07-08 19:03:57 -0400 | [diff] [blame] | 6167 | if (wl_global_create(ec->wl_display, &workspace_manager_interface, 1, |
| 6168 | shell, bind_workspace_manager) == NULL) |
Jonas Ådahl | e9d2250 | 2012-08-29 22:13:01 +0200 | [diff] [blame] | 6169 | return -1; |
| 6170 | |
Kristian Høgsberg | f03a616 | 2012-01-17 11:07:42 -0500 | [diff] [blame] | 6171 | shell->child.deathstamp = weston_compositor_get_time(); |
Tiago Vignatti | b7dbbd6 | 2012-09-25 17:57:01 +0300 | [diff] [blame] | 6172 | |
Xiong Zhang | 6b48142 | 2013-10-23 13:58:32 +0800 | [diff] [blame] | 6173 | setup_output_destroy_handler(ec, shell); |
| 6174 | |
Tiago Vignatti | b7dbbd6 | 2012-09-25 17:57:01 +0300 | [diff] [blame] | 6175 | loop = wl_display_get_event_loop(ec->wl_display); |
| 6176 | wl_event_loop_add_idle(loop, launch_desktop_shell_process, shell); |
Pekka Paalanen | 6cd281a | 2011-11-03 14:11:32 +0200 | [diff] [blame] | 6177 | |
Ander Conselvan de Oliveira | 859e885 | 2013-02-21 18:35:21 +0200 | [diff] [blame] | 6178 | shell->screensaver.timer = |
| 6179 | wl_event_loop_add_timer(loop, screensaver_timeout, shell); |
| 6180 | |
Jason Ekstrand | 024177c | 2014-04-21 19:42:58 -0500 | [diff] [blame] | 6181 | wl_list_for_each(seat, &ec->seat_list, link) |
| 6182 | handle_seat_created(NULL, seat); |
| 6183 | shell->seat_create_listener.notify = handle_seat_created; |
| 6184 | wl_signal_add(&ec->seat_created_signal, &shell->seat_create_listener); |
Kristian Høgsberg | d56bd90 | 2012-06-05 09:58:51 -0400 | [diff] [blame] | 6185 | |
Giulio Camuffo | c6ab3d5 | 2013-12-11 23:45:12 +0100 | [diff] [blame] | 6186 | screenshooter_create(ec); |
| 6187 | |
Tiago Vignatti | 0b52d48 | 2012-04-20 18:54:25 +0300 | [diff] [blame] | 6188 | shell_add_bindings(ec, shell); |
Kristian Høgsberg | 0793756 | 2011-04-12 17:25:42 -0400 | [diff] [blame] | 6189 | |
Pekka Paalanen | 79346ab | 2013-05-22 18:03:09 +0300 | [diff] [blame] | 6190 | shell_fade_init(shell); |
Ander Conselvan de Oliveira | 19d10ef | 2013-02-21 18:35:20 +0200 | [diff] [blame] | 6191 | |
Kristian Høgsberg | 4cca349 | 2011-01-18 07:53:49 -0500 | [diff] [blame] | 6192 | return 0; |
| 6193 | } |