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; |
Jasper St. Pierre | 8c6aa45 | 2014-02-08 18:29:49 -0500 | [diff] [blame] | 169 | } state, next_state, requested_state; /* surface states */ |
Rafael Antognolli | 03b1659 | 2013-12-03 15:35:42 -0200 | [diff] [blame] | 170 | bool state_changed; |
Jasper St. Pierre | 8c6aa45 | 2014-02-08 18:29:49 -0500 | [diff] [blame] | 171 | bool state_requested; |
Jasper St. Pierre | faf27a9 | 2013-12-09 17:36:28 -0500 | [diff] [blame] | 172 | |
| 173 | int focus_count; |
Pekka Paalanen | 56cdea9 | 2011-11-23 16:14:12 +0200 | [diff] [blame] | 174 | }; |
| 175 | |
Ander Conselvan de Oliveira | fe0444a | 2012-04-04 17:48:05 +0300 | [diff] [blame] | 176 | struct shell_grab { |
Kristian Høgsberg | 02bbabb | 2013-05-06 22:15:05 -0400 | [diff] [blame] | 177 | struct weston_pointer_grab grab; |
Ander Conselvan de Oliveira | fe0444a | 2012-04-04 17:48:05 +0300 | [diff] [blame] | 178 | struct shell_surface *shsurf; |
| 179 | struct wl_listener shsurf_destroy_listener; |
| 180 | }; |
| 181 | |
Rusty Lynch | 1084da5 | 2013-08-15 09:10:08 -0700 | [diff] [blame] | 182 | struct shell_touch_grab { |
| 183 | struct weston_touch_grab grab; |
| 184 | struct shell_surface *shsurf; |
| 185 | struct wl_listener shsurf_destroy_listener; |
| 186 | struct weston_touch *touch; |
| 187 | }; |
| 188 | |
Ander Conselvan de Oliveira | fe0444a | 2012-04-04 17:48:05 +0300 | [diff] [blame] | 189 | struct weston_move_grab { |
| 190 | struct shell_grab base; |
Daniel Stone | 103db7f | 2012-05-08 17:17:55 +0100 | [diff] [blame] | 191 | wl_fixed_t dx, dy; |
Kristian Høgsberg | 4cca349 | 2011-01-18 07:53:49 -0500 | [diff] [blame] | 192 | }; |
| 193 | |
Rusty Lynch | 1084da5 | 2013-08-15 09:10:08 -0700 | [diff] [blame] | 194 | struct weston_touch_move_grab { |
| 195 | struct shell_touch_grab base; |
Kristian Høgsberg | 8e80a31 | 2014-01-17 15:18:10 -0800 | [diff] [blame] | 196 | int active; |
Rusty Lynch | 1084da5 | 2013-08-15 09:10:08 -0700 | [diff] [blame] | 197 | wl_fixed_t dx, dy; |
| 198 | }; |
| 199 | |
Pekka Paalanen | 460099f | 2012-01-20 16:48:25 +0200 | [diff] [blame] | 200 | struct rotate_grab { |
Ander Conselvan de Oliveira | fe0444a | 2012-04-04 17:48:05 +0300 | [diff] [blame] | 201 | struct shell_grab base; |
Kristian Høgsberg | 765e27b | 2012-01-27 13:36:13 -0500 | [diff] [blame] | 202 | struct weston_matrix rotation; |
Pekka Paalanen | 460099f | 2012-01-20 16:48:25 +0200 | [diff] [blame] | 203 | struct { |
John Kåre Alsaker | 490d02a | 2012-09-30 02:57:21 +0200 | [diff] [blame] | 204 | float x; |
| 205 | float y; |
Pekka Paalanen | 460099f | 2012-01-20 16:48:25 +0200 | [diff] [blame] | 206 | } center; |
| 207 | }; |
| 208 | |
Giulio Camuffo | 5085a75 | 2013-03-25 21:42:45 +0100 | [diff] [blame] | 209 | struct shell_seat { |
| 210 | struct weston_seat *seat; |
| 211 | struct wl_listener seat_destroy_listener; |
Jasper St. Pierre | faf27a9 | 2013-12-09 17:36:28 -0500 | [diff] [blame] | 212 | struct weston_surface *focused_surface; |
Giulio Camuffo | 5085a75 | 2013-03-25 21:42:45 +0100 | [diff] [blame] | 213 | |
| 214 | struct { |
Kristian Høgsberg | 02bbabb | 2013-05-06 22:15:05 -0400 | [diff] [blame] | 215 | struct weston_pointer_grab grab; |
Giulio Camuffo | 5085a75 | 2013-03-25 21:42:45 +0100 | [diff] [blame] | 216 | struct wl_list surfaces_list; |
| 217 | struct wl_client *client; |
| 218 | int32_t initial_up; |
| 219 | } popup_grab; |
| 220 | }; |
| 221 | |
Kristian Høgsberg | 2bff94e | 2014-02-11 12:22:51 -0800 | [diff] [blame] | 222 | struct shell_client { |
| 223 | struct wl_resource *resource; |
| 224 | struct wl_client *client; |
| 225 | struct desktop_shell *shell; |
| 226 | struct wl_listener destroy_listener; |
| 227 | struct wl_event_source *ping_timer; |
| 228 | uint32_t ping_serial; |
| 229 | int unresponsive; |
| 230 | }; |
| 231 | |
Emilio Pozuelo Monfort | 1a26f1b | 2014-01-07 16:41:40 +0100 | [diff] [blame] | 232 | void |
| 233 | set_alpha_if_fullscreen(struct shell_surface *shsurf) |
| 234 | { |
| 235 | if (shsurf && shsurf->state.fullscreen) |
| 236 | shsurf->fullscreen.black_view->alpha = 0.25; |
| 237 | } |
| 238 | |
Alex Wu | bd3354b | 2012-04-17 17:20:49 +0800 | [diff] [blame] | 239 | static struct desktop_shell * |
| 240 | shell_surface_get_shell(struct shell_surface *shsurf); |
| 241 | |
Kristian Høgsberg | 0c36903 | 2013-02-14 21:31:44 -0500 | [diff] [blame] | 242 | static void |
Kristian Høgsberg | e314875 | 2013-05-06 23:19:49 -0400 | [diff] [blame] | 243 | surface_rotate(struct shell_surface *surface, struct weston_seat *seat); |
Kristian Høgsberg | 0c36903 | 2013-02-14 21:31:44 -0500 | [diff] [blame] | 244 | |
Pekka Paalanen | 79346ab | 2013-05-22 18:03:09 +0300 | [diff] [blame] | 245 | static void |
| 246 | shell_fade_startup(struct desktop_shell *shell); |
| 247 | |
Philip Withnall | becb77e | 2013-11-25 18:01:30 +0000 | [diff] [blame] | 248 | static struct shell_seat * |
| 249 | get_shell_seat(struct weston_seat *seat); |
| 250 | |
Philip Withnall | 648a4dd | 2013-11-25 18:01:44 +0000 | [diff] [blame] | 251 | static void |
| 252 | shell_surface_update_child_surface_layers(struct shell_surface *shsurf); |
| 253 | |
Alex Wu | bd3354b | 2012-04-17 17:20:49 +0800 | [diff] [blame] | 254 | static bool |
Rafael Antognolli | e2a3455 | 2013-12-03 15:35:45 -0200 | [diff] [blame] | 255 | shell_surface_is_wl_shell_surface(struct shell_surface *shsurf); |
| 256 | |
| 257 | static bool |
| 258 | shell_surface_is_xdg_surface(struct shell_surface *shsurf); |
| 259 | |
| 260 | static bool |
| 261 | shell_surface_is_xdg_popup(struct shell_surface *shsurf); |
| 262 | |
| 263 | static void |
| 264 | shell_surface_set_parent(struct shell_surface *shsurf, |
| 265 | struct weston_surface *parent); |
| 266 | |
| 267 | static bool |
Alex Wu | bd3354b | 2012-04-17 17:20:49 +0800 | [diff] [blame] | 268 | shell_surface_is_top_fullscreen(struct shell_surface *shsurf) |
| 269 | { |
| 270 | struct desktop_shell *shell; |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 271 | struct weston_view *top_fs_ev; |
Alex Wu | bd3354b | 2012-04-17 17:20:49 +0800 | [diff] [blame] | 272 | |
| 273 | shell = shell_surface_get_shell(shsurf); |
Quentin Glidic | c0d79ce | 2013-01-29 14:16:13 +0100 | [diff] [blame] | 274 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 275 | if (wl_list_empty(&shell->fullscreen_layer.view_list)) |
Alex Wu | bd3354b | 2012-04-17 17:20:49 +0800 | [diff] [blame] | 276 | return false; |
| 277 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 278 | top_fs_ev = container_of(shell->fullscreen_layer.view_list.next, |
| 279 | struct weston_view, |
Alex Wu | bd3354b | 2012-04-17 17:20:49 +0800 | [diff] [blame] | 280 | layer_link); |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 281 | return (shsurf == get_shell_surface(top_fs_ev->surface)); |
Alex Wu | bd3354b | 2012-04-17 17:20:49 +0800 | [diff] [blame] | 282 | } |
| 283 | |
Kristian Høgsberg | 6af8eb9 | 2012-01-25 16:57:11 -0500 | [diff] [blame] | 284 | static void |
Kristian Høgsberg | 27e3052 | 2012-04-11 23:18:23 -0400 | [diff] [blame] | 285 | destroy_shell_grab_shsurf(struct wl_listener *listener, void *data) |
Ander Conselvan de Oliveira | fe0444a | 2012-04-04 17:48:05 +0300 | [diff] [blame] | 286 | { |
| 287 | struct shell_grab *grab; |
| 288 | |
| 289 | grab = container_of(listener, struct shell_grab, |
| 290 | shsurf_destroy_listener); |
| 291 | |
| 292 | grab->shsurf = NULL; |
| 293 | } |
| 294 | |
Kristian Høgsberg | 1ef2313 | 2013-12-04 00:20:01 -0800 | [diff] [blame] | 295 | struct weston_view * |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 296 | get_default_view(struct weston_surface *surface) |
| 297 | { |
| 298 | struct shell_surface *shsurf; |
| 299 | struct weston_view *view; |
| 300 | |
| 301 | if (!surface || wl_list_empty(&surface->views)) |
| 302 | return NULL; |
| 303 | |
| 304 | shsurf = get_shell_surface(surface); |
| 305 | if (shsurf) |
| 306 | return shsurf->view; |
| 307 | |
| 308 | wl_list_for_each(view, &surface->views, surface_link) |
| 309 | if (weston_view_is_mapped(view)) |
| 310 | return view; |
| 311 | |
| 312 | return container_of(surface->views.next, struct weston_view, surface_link); |
| 313 | } |
| 314 | |
Ander Conselvan de Oliveira | fe0444a | 2012-04-04 17:48:05 +0300 | [diff] [blame] | 315 | static void |
Kristian Høgsberg | 02bbabb | 2013-05-06 22:15:05 -0400 | [diff] [blame] | 316 | popup_grab_end(struct weston_pointer *pointer); |
Kristian Høgsberg | 57e0907 | 2012-10-30 14:07:27 -0400 | [diff] [blame] | 317 | |
| 318 | static void |
Ander Conselvan de Oliveira | b9d2a0f | 2012-06-28 18:08:05 +0300 | [diff] [blame] | 319 | shell_grab_start(struct shell_grab *grab, |
Kristian Høgsberg | 02bbabb | 2013-05-06 22:15:05 -0400 | [diff] [blame] | 320 | const struct weston_pointer_grab_interface *interface, |
Ander Conselvan de Oliveira | b9d2a0f | 2012-06-28 18:08:05 +0300 | [diff] [blame] | 321 | struct shell_surface *shsurf, |
Kristian Høgsberg | 02bbabb | 2013-05-06 22:15:05 -0400 | [diff] [blame] | 322 | struct weston_pointer *pointer, |
Ander Conselvan de Oliveira | b9d2a0f | 2012-06-28 18:08:05 +0300 | [diff] [blame] | 323 | enum desktop_shell_cursor cursor) |
Ander Conselvan de Oliveira | fe0444a | 2012-04-04 17:48:05 +0300 | [diff] [blame] | 324 | { |
Ander Conselvan de Oliveira | b9d2a0f | 2012-06-28 18:08:05 +0300 | [diff] [blame] | 325 | struct desktop_shell *shell = shsurf->shell; |
| 326 | |
Kristian Høgsberg | 57e0907 | 2012-10-30 14:07:27 -0400 | [diff] [blame] | 327 | popup_grab_end(pointer); |
| 328 | |
Ander Conselvan de Oliveira | fe0444a | 2012-04-04 17:48:05 +0300 | [diff] [blame] | 329 | grab->grab.interface = interface; |
| 330 | grab->shsurf = shsurf; |
Kristian Høgsberg | 27e3052 | 2012-04-11 23:18:23 -0400 | [diff] [blame] | 331 | grab->shsurf_destroy_listener.notify = destroy_shell_grab_shsurf; |
Jason Ekstrand | 651f00e | 2013-06-14 10:07:54 -0500 | [diff] [blame] | 332 | wl_signal_add(&shsurf->destroy_signal, |
Kristian Høgsberg | 27e3052 | 2012-04-11 23:18:23 -0400 | [diff] [blame] | 333 | &grab->shsurf_destroy_listener); |
Ander Conselvan de Oliveira | fe0444a | 2012-04-04 17:48:05 +0300 | [diff] [blame] | 334 | |
Kristian Høgsberg | c85f1d4 | 2013-10-24 16:52:00 -0700 | [diff] [blame] | 335 | shsurf->grabbed = 1; |
Kristian Høgsberg | 02bbabb | 2013-05-06 22:15:05 -0400 | [diff] [blame] | 336 | weston_pointer_start_grab(pointer, &grab->grab); |
Kristian Høgsberg | c9974a0 | 2013-07-03 19:24:57 -0400 | [diff] [blame] | 337 | if (shell->child.desktop_shell) { |
| 338 | desktop_shell_send_grab_cursor(shell->child.desktop_shell, |
| 339 | cursor); |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 340 | weston_pointer_set_focus(pointer, |
| 341 | get_default_view(shell->grab_surface), |
Kristian Høgsberg | c9974a0 | 2013-07-03 19:24:57 -0400 | [diff] [blame] | 342 | wl_fixed_from_int(0), |
| 343 | wl_fixed_from_int(0)); |
| 344 | } |
Ander Conselvan de Oliveira | fe0444a | 2012-04-04 17:48:05 +0300 | [diff] [blame] | 345 | } |
| 346 | |
| 347 | static void |
Ander Conselvan de Oliveira | b9d2a0f | 2012-06-28 18:08:05 +0300 | [diff] [blame] | 348 | shell_grab_end(struct shell_grab *grab) |
Ander Conselvan de Oliveira | fe0444a | 2012-04-04 17:48:05 +0300 | [diff] [blame] | 349 | { |
Kristian Høgsberg | c85f1d4 | 2013-10-24 16:52:00 -0700 | [diff] [blame] | 350 | if (grab->shsurf) { |
Kristian Høgsberg | 47b5dca | 2012-06-07 18:08:04 -0400 | [diff] [blame] | 351 | wl_list_remove(&grab->shsurf_destroy_listener.link); |
Kristian Høgsberg | c85f1d4 | 2013-10-24 16:52:00 -0700 | [diff] [blame] | 352 | grab->shsurf->grabbed = 0; |
Kristian Høgsberg | 44cd196 | 2014-02-05 21:36:04 -0800 | [diff] [blame] | 353 | grab->shsurf->resize_edges = 0; |
Kristian Høgsberg | c85f1d4 | 2013-10-24 16:52:00 -0700 | [diff] [blame] | 354 | } |
Ander Conselvan de Oliveira | b9d2a0f | 2012-06-28 18:08:05 +0300 | [diff] [blame] | 355 | |
Kristian Høgsberg | 9e5d7d1 | 2013-07-22 16:31:53 -0700 | [diff] [blame] | 356 | weston_pointer_end_grab(grab->grab.pointer); |
Ander Conselvan de Oliveira | fe0444a | 2012-04-04 17:48:05 +0300 | [diff] [blame] | 357 | } |
| 358 | |
| 359 | static void |
Rusty Lynch | 1084da5 | 2013-08-15 09:10:08 -0700 | [diff] [blame] | 360 | shell_touch_grab_start(struct shell_touch_grab *grab, |
| 361 | const struct weston_touch_grab_interface *interface, |
| 362 | struct shell_surface *shsurf, |
| 363 | struct weston_touch *touch) |
| 364 | { |
| 365 | struct desktop_shell *shell = shsurf->shell; |
U. Artie Eoff | cf5737a | 2014-01-17 10:08:25 -0800 | [diff] [blame] | 366 | |
Kristian Høgsberg | 74071e0 | 2014-04-29 15:01:16 -0700 | [diff] [blame^] | 367 | if (touch->seat->pointer) |
| 368 | popup_grab_end(touch->seat->pointer); |
| 369 | |
Rusty Lynch | 1084da5 | 2013-08-15 09:10:08 -0700 | [diff] [blame] | 370 | grab->grab.interface = interface; |
| 371 | grab->shsurf = shsurf; |
| 372 | grab->shsurf_destroy_listener.notify = destroy_shell_grab_shsurf; |
| 373 | wl_signal_add(&shsurf->destroy_signal, |
| 374 | &grab->shsurf_destroy_listener); |
| 375 | |
| 376 | grab->touch = touch; |
Kristian Høgsberg | c85f1d4 | 2013-10-24 16:52:00 -0700 | [diff] [blame] | 377 | shsurf->grabbed = 1; |
Rusty Lynch | 1084da5 | 2013-08-15 09:10:08 -0700 | [diff] [blame] | 378 | |
| 379 | weston_touch_start_grab(touch, &grab->grab); |
| 380 | if (shell->child.desktop_shell) |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 381 | weston_touch_set_focus(touch->seat, |
| 382 | get_default_view(shell->grab_surface)); |
Rusty Lynch | 1084da5 | 2013-08-15 09:10:08 -0700 | [diff] [blame] | 383 | } |
| 384 | |
| 385 | static void |
| 386 | shell_touch_grab_end(struct shell_touch_grab *grab) |
| 387 | { |
Kristian Høgsberg | c85f1d4 | 2013-10-24 16:52:00 -0700 | [diff] [blame] | 388 | if (grab->shsurf) { |
Rusty Lynch | 1084da5 | 2013-08-15 09:10:08 -0700 | [diff] [blame] | 389 | wl_list_remove(&grab->shsurf_destroy_listener.link); |
Kristian Høgsberg | c85f1d4 | 2013-10-24 16:52:00 -0700 | [diff] [blame] | 390 | grab->shsurf->grabbed = 0; |
| 391 | } |
Rusty Lynch | 1084da5 | 2013-08-15 09:10:08 -0700 | [diff] [blame] | 392 | |
| 393 | weston_touch_end_grab(grab->touch); |
| 394 | } |
| 395 | |
| 396 | static void |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 397 | center_on_output(struct weston_view *view, |
Alex Wu | 4539b08 | 2012-03-01 12:57:46 +0800 | [diff] [blame] | 398 | struct weston_output *output); |
| 399 | |
Daniel Stone | 496ca17 | 2012-05-30 16:31:42 +0100 | [diff] [blame] | 400 | static enum weston_keyboard_modifier |
Tiago Vignatti | 0b52d48 | 2012-04-20 18:54:25 +0300 | [diff] [blame] | 401 | get_modifier(char *modifier) |
| 402 | { |
| 403 | if (!modifier) |
| 404 | return MODIFIER_SUPER; |
| 405 | |
| 406 | if (!strcmp("ctrl", modifier)) |
| 407 | return MODIFIER_CTRL; |
| 408 | else if (!strcmp("alt", modifier)) |
| 409 | return MODIFIER_ALT; |
| 410 | else if (!strcmp("super", modifier)) |
| 411 | return MODIFIER_SUPER; |
| 412 | else |
| 413 | return MODIFIER_SUPER; |
| 414 | } |
| 415 | |
Juan Zhao | e10d279 | 2012-04-25 19:09:52 +0800 | [diff] [blame] | 416 | static enum animation_type |
| 417 | get_animation_type(char *animation) |
| 418 | { |
U. Artie Eoff | b571910 | 2014-01-15 14:26:31 -0800 | [diff] [blame] | 419 | if (!animation) |
| 420 | return ANIMATION_NONE; |
| 421 | |
Juan Zhao | e10d279 | 2012-04-25 19:09:52 +0800 | [diff] [blame] | 422 | if (!strcmp("zoom", animation)) |
| 423 | return ANIMATION_ZOOM; |
| 424 | else if (!strcmp("fade", animation)) |
| 425 | return ANIMATION_FADE; |
Louis-Francis Ratté-Boulianne | b482dbd | 2013-11-19 11:37:11 +0100 | [diff] [blame] | 426 | else if (!strcmp("dim-layer", animation)) |
| 427 | return ANIMATION_DIM_LAYER; |
Juan Zhao | e10d279 | 2012-04-25 19:09:52 +0800 | [diff] [blame] | 428 | else |
| 429 | return ANIMATION_NONE; |
| 430 | } |
| 431 | |
Alex Wu | 4539b08 | 2012-03-01 12:57:46 +0800 | [diff] [blame] | 432 | static void |
Kristian Høgsberg | 14e438c | 2013-05-26 21:48:14 -0400 | [diff] [blame] | 433 | shell_configuration(struct desktop_shell *shell) |
Pekka Paalanen | e955f1e | 2011-12-07 11:49:52 +0200 | [diff] [blame] | 434 | { |
Kristian Høgsberg | 673a889 | 2013-05-23 21:40:56 -0400 | [diff] [blame] | 435 | struct weston_config_section *section; |
| 436 | int duration; |
| 437 | char *s; |
Pekka Paalanen | e955f1e | 2011-12-07 11:49:52 +0200 | [diff] [blame] | 438 | |
Kristian Høgsberg | 673a889 | 2013-05-23 21:40:56 -0400 | [diff] [blame] | 439 | section = weston_config_get_section(shell->compositor->config, |
| 440 | "screensaver", NULL, NULL); |
| 441 | weston_config_section_get_string(section, |
| 442 | "path", &shell->screensaver.path, NULL); |
| 443 | weston_config_section_get_int(section, "duration", &duration, 60); |
Ander Conselvan de Oliveira | 859e885 | 2013-02-21 18:35:21 +0200 | [diff] [blame] | 444 | shell->screensaver.duration = duration * 1000; |
Kristian Høgsberg | 673a889 | 2013-05-23 21:40:56 -0400 | [diff] [blame] | 445 | |
| 446 | section = weston_config_get_section(shell->compositor->config, |
| 447 | "shell", NULL, NULL); |
| 448 | weston_config_section_get_string(section, |
Emilio Pozuelo Monfort | 8a81b83 | 2013-12-02 12:53:32 +0100 | [diff] [blame] | 449 | "client", &s, LIBEXECDIR "/" WESTON_SHELL_CLIENT); |
Emilio Pozuelo Monfort | 46ce798 | 2013-11-20 13:22:29 +0100 | [diff] [blame] | 450 | shell->client = s; |
| 451 | weston_config_section_get_string(section, |
Kristian Høgsberg | 673a889 | 2013-05-23 21:40:56 -0400 | [diff] [blame] | 452 | "binding-modifier", &s, "super"); |
| 453 | shell->binding_modifier = get_modifier(s); |
Quentin Glidic | 8418c29 | 2013-06-18 09:11:03 +0200 | [diff] [blame] | 454 | free(s); |
Kristian Høgsberg | d56ab4e | 2014-01-16 16:51:52 -0800 | [diff] [blame] | 455 | |
| 456 | weston_config_section_get_string(section, |
| 457 | "exposay-modifier", &s, "none"); |
| 458 | if (strcmp(s, "none") == 0) |
| 459 | shell->exposay_modifier = 0; |
| 460 | else |
| 461 | shell->exposay_modifier = get_modifier(s); |
| 462 | free(s); |
| 463 | |
Kristian Høgsberg | 673a889 | 2013-05-23 21:40:56 -0400 | [diff] [blame] | 464 | weston_config_section_get_string(section, "animation", &s, "none"); |
| 465 | shell->win_animation_type = get_animation_type(s); |
Quentin Glidic | 8418c29 | 2013-06-18 09:11:03 +0200 | [diff] [blame] | 466 | free(s); |
Kristian Høgsberg | 724c8d9 | 2013-10-16 11:38:24 -0700 | [diff] [blame] | 467 | weston_config_section_get_string(section, |
| 468 | "startup-animation", &s, "fade"); |
| 469 | shell->startup_animation_type = get_animation_type(s); |
| 470 | free(s); |
Kristian Høgsberg | 912e0a1 | 2013-10-30 08:59:55 -0700 | [diff] [blame] | 471 | if (shell->startup_animation_type == ANIMATION_ZOOM) |
| 472 | shell->startup_animation_type = ANIMATION_NONE; |
Louis-Francis Ratté-Boulianne | b482dbd | 2013-11-19 11:37:11 +0100 | [diff] [blame] | 473 | weston_config_section_get_string(section, "focus-animation", &s, "none"); |
| 474 | shell->focus_animation_type = get_animation_type(s); |
| 475 | free(s); |
Kristian Høgsberg | 673a889 | 2013-05-23 21:40:56 -0400 | [diff] [blame] | 476 | weston_config_section_get_uint(section, "num-workspaces", |
| 477 | &shell->workspaces.num, |
| 478 | DEFAULT_NUM_WORKSPACES); |
Jonas Ådahl | e3cddce | 2012-06-13 00:01:22 +0200 | [diff] [blame] | 479 | } |
| 480 | |
Kristian Høgsberg | 1ef2313 | 2013-12-04 00:20:01 -0800 | [diff] [blame] | 481 | struct weston_output * |
Louis-Francis Ratté-Boulianne | b482dbd | 2013-11-19 11:37:11 +0100 | [diff] [blame] | 482 | get_default_output(struct weston_compositor *compositor) |
| 483 | { |
| 484 | return container_of(compositor->output_list.next, |
| 485 | struct weston_output, link); |
| 486 | } |
| 487 | |
| 488 | |
| 489 | /* no-op func for checking focus surface */ |
| 490 | static void |
Jason Ekstrand | 918f2dd | 2013-12-02 21:01:53 -0600 | [diff] [blame] | 491 | 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] | 492 | { |
| 493 | } |
| 494 | |
| 495 | static struct focus_surface * |
| 496 | get_focus_surface(struct weston_surface *surface) |
| 497 | { |
| 498 | if (surface->configure == focus_surface_configure) |
| 499 | return surface->configure_private; |
| 500 | else |
| 501 | return NULL; |
| 502 | } |
| 503 | |
| 504 | static bool |
| 505 | is_focus_surface (struct weston_surface *es) |
| 506 | { |
| 507 | return (es->configure == focus_surface_configure); |
| 508 | } |
| 509 | |
| 510 | static bool |
| 511 | is_focus_view (struct weston_view *view) |
| 512 | { |
| 513 | return is_focus_surface (view->surface); |
| 514 | } |
| 515 | |
| 516 | static struct focus_surface * |
| 517 | create_focus_surface(struct weston_compositor *ec, |
| 518 | struct weston_output *output) |
| 519 | { |
| 520 | struct focus_surface *fsurf = NULL; |
| 521 | struct weston_surface *surface = NULL; |
| 522 | |
| 523 | fsurf = malloc(sizeof *fsurf); |
| 524 | if (!fsurf) |
| 525 | return NULL; |
| 526 | |
| 527 | fsurf->surface = weston_surface_create(ec); |
| 528 | surface = fsurf->surface; |
| 529 | if (surface == NULL) { |
| 530 | free(fsurf); |
| 531 | return NULL; |
| 532 | } |
| 533 | |
| 534 | surface->configure = focus_surface_configure; |
| 535 | surface->output = output; |
| 536 | surface->configure_private = fsurf; |
| 537 | |
U. Artie Eoff | 0b23b2b | 2014-01-15 14:45:59 -0800 | [diff] [blame] | 538 | fsurf->view = weston_view_create(surface); |
| 539 | if (fsurf->view == NULL) { |
| 540 | weston_surface_destroy(surface); |
| 541 | free(fsurf); |
| 542 | return NULL; |
| 543 | } |
Emilio Pozuelo Monfort | da64426 | 2013-11-19 11:37:19 +0100 | [diff] [blame] | 544 | fsurf->view->output = output; |
Louis-Francis Ratté-Boulianne | b482dbd | 2013-11-19 11:37:11 +0100 | [diff] [blame] | 545 | |
Jason Ekstrand | 5c11a33 | 2013-12-04 20:32:03 -0600 | [diff] [blame] | 546 | weston_surface_set_size(surface, output->width, output->height); |
Jason Ekstrand | 918f2dd | 2013-12-02 21:01:53 -0600 | [diff] [blame] | 547 | weston_view_set_position(fsurf->view, output->x, output->y); |
Louis-Francis Ratté-Boulianne | b482dbd | 2013-11-19 11:37:11 +0100 | [diff] [blame] | 548 | weston_surface_set_color(surface, 0.0, 0.0, 0.0, 1.0); |
| 549 | pixman_region32_fini(&surface->opaque); |
| 550 | pixman_region32_init_rect(&surface->opaque, output->x, output->y, |
| 551 | output->width, output->height); |
| 552 | pixman_region32_fini(&surface->input); |
| 553 | pixman_region32_init(&surface->input); |
| 554 | |
| 555 | wl_list_init(&fsurf->workspace_transform.link); |
| 556 | |
| 557 | return fsurf; |
| 558 | } |
| 559 | |
| 560 | static void |
| 561 | focus_surface_destroy(struct focus_surface *fsurf) |
| 562 | { |
| 563 | weston_surface_destroy(fsurf->surface); |
| 564 | free(fsurf); |
| 565 | } |
| 566 | |
| 567 | static void |
| 568 | focus_animation_done(struct weston_view_animation *animation, void *data) |
| 569 | { |
| 570 | struct workspace *ws = data; |
| 571 | |
| 572 | ws->focus_animation = NULL; |
| 573 | } |
| 574 | |
Jonas Ådahl | e3cddce | 2012-06-13 00:01:22 +0200 | [diff] [blame] | 575 | static void |
Jonas Ådahl | 0476974 | 2012-06-13 00:01:24 +0200 | [diff] [blame] | 576 | focus_state_destroy(struct focus_state *state) |
| 577 | { |
| 578 | wl_list_remove(&state->seat_destroy_listener.link); |
| 579 | wl_list_remove(&state->surface_destroy_listener.link); |
| 580 | free(state); |
| 581 | } |
| 582 | |
| 583 | static void |
| 584 | focus_state_seat_destroy(struct wl_listener *listener, void *data) |
| 585 | { |
| 586 | struct focus_state *state = container_of(listener, |
| 587 | struct focus_state, |
| 588 | seat_destroy_listener); |
| 589 | |
| 590 | wl_list_remove(&state->link); |
| 591 | focus_state_destroy(state); |
| 592 | } |
| 593 | |
| 594 | static void |
| 595 | focus_state_surface_destroy(struct wl_listener *listener, void *data) |
| 596 | { |
| 597 | struct focus_state *state = container_of(listener, |
| 598 | struct focus_state, |
Kristian Høgsberg | b8e0d0f | 2012-07-31 10:30:26 -0400 | [diff] [blame] | 599 | surface_destroy_listener); |
Kristian Høgsberg | e377822 | 2012-07-31 17:29:30 -0400 | [diff] [blame] | 600 | struct desktop_shell *shell; |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 601 | struct weston_surface *main_surface, *next; |
| 602 | struct weston_view *view; |
Jonas Ådahl | 0476974 | 2012-06-13 00:01:24 +0200 | [diff] [blame] | 603 | |
Pekka Paalanen | 01388e2 | 2013-04-25 13:57:44 +0300 | [diff] [blame] | 604 | main_surface = weston_surface_get_main_surface(state->keyboard_focus); |
| 605 | |
Kristian Høgsberg | e377822 | 2012-07-31 17:29:30 -0400 | [diff] [blame] | 606 | next = NULL; |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 607 | wl_list_for_each(view, &state->ws->layer.view_list, layer_link) { |
| 608 | if (view->surface == main_surface) |
Kristian Høgsberg | e377822 | 2012-07-31 17:29:30 -0400 | [diff] [blame] | 609 | continue; |
Louis-Francis Ratté-Boulianne | b482dbd | 2013-11-19 11:37:11 +0100 | [diff] [blame] | 610 | if (is_focus_view(view)) |
| 611 | continue; |
Kristian Høgsberg | e377822 | 2012-07-31 17:29:30 -0400 | [diff] [blame] | 612 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 613 | next = view->surface; |
Kristian Høgsberg | e377822 | 2012-07-31 17:29:30 -0400 | [diff] [blame] | 614 | break; |
| 615 | } |
| 616 | |
Pekka Paalanen | 01388e2 | 2013-04-25 13:57:44 +0300 | [diff] [blame] | 617 | /* if the focus was a sub-surface, activate its main surface */ |
| 618 | if (main_surface != state->keyboard_focus) |
| 619 | next = main_surface; |
| 620 | |
Louis-Francis Ratté-Boulianne | b482dbd | 2013-11-19 11:37:11 +0100 | [diff] [blame] | 621 | shell = state->seat->compositor->shell_interface.shell; |
Kristian Høgsberg | e377822 | 2012-07-31 17:29:30 -0400 | [diff] [blame] | 622 | if (next) { |
Louis-Francis Ratté-Boulianne | b482dbd | 2013-11-19 11:37:11 +0100 | [diff] [blame] | 623 | state->keyboard_focus = NULL; |
Kristian Høgsberg | e377822 | 2012-07-31 17:29:30 -0400 | [diff] [blame] | 624 | activate(shell, next, state->seat); |
| 625 | } else { |
Louis-Francis Ratté-Boulianne | b482dbd | 2013-11-19 11:37:11 +0100 | [diff] [blame] | 626 | if (shell->focus_animation_type == ANIMATION_DIM_LAYER) { |
| 627 | if (state->ws->focus_animation) |
| 628 | weston_view_animation_destroy(state->ws->focus_animation); |
| 629 | |
| 630 | state->ws->focus_animation = weston_fade_run( |
| 631 | state->ws->fsurf_front->view, |
| 632 | state->ws->fsurf_front->view->alpha, 0.0, 300, |
| 633 | focus_animation_done, state->ws); |
| 634 | } |
| 635 | |
Kristian Høgsberg | e377822 | 2012-07-31 17:29:30 -0400 | [diff] [blame] | 636 | wl_list_remove(&state->link); |
| 637 | focus_state_destroy(state); |
| 638 | } |
Jonas Ådahl | 0476974 | 2012-06-13 00:01:24 +0200 | [diff] [blame] | 639 | } |
| 640 | |
| 641 | static struct focus_state * |
Kristian Høgsberg | 2f5faff | 2012-07-31 16:36:34 -0400 | [diff] [blame] | 642 | focus_state_create(struct weston_seat *seat, struct workspace *ws) |
Jonas Ådahl | 0476974 | 2012-06-13 00:01:24 +0200 | [diff] [blame] | 643 | { |
Jonas Ådahl | 0476974 | 2012-06-13 00:01:24 +0200 | [diff] [blame] | 644 | struct focus_state *state; |
Jonas Ådahl | 0476974 | 2012-06-13 00:01:24 +0200 | [diff] [blame] | 645 | |
| 646 | state = malloc(sizeof *state); |
| 647 | if (state == NULL) |
| 648 | return NULL; |
| 649 | |
Louis-Francis Ratté-Boulianne | b482dbd | 2013-11-19 11:37:11 +0100 | [diff] [blame] | 650 | state->keyboard_focus = NULL; |
Kristian Høgsberg | 2f5faff | 2012-07-31 16:36:34 -0400 | [diff] [blame] | 651 | state->ws = ws; |
Jonas Ådahl | 0476974 | 2012-06-13 00:01:24 +0200 | [diff] [blame] | 652 | state->seat = seat; |
Kristian Høgsberg | 2f5faff | 2012-07-31 16:36:34 -0400 | [diff] [blame] | 653 | wl_list_insert(&ws->focus_list, &state->link); |
Jonas Ådahl | 0476974 | 2012-06-13 00:01:24 +0200 | [diff] [blame] | 654 | |
| 655 | state->seat_destroy_listener.notify = focus_state_seat_destroy; |
| 656 | state->surface_destroy_listener.notify = focus_state_surface_destroy; |
Kristian Høgsberg | 4912454 | 2013-05-06 22:27:40 -0400 | [diff] [blame] | 657 | wl_signal_add(&seat->destroy_signal, |
Jonas Ådahl | 0476974 | 2012-06-13 00:01:24 +0200 | [diff] [blame] | 658 | &state->seat_destroy_listener); |
Kristian Høgsberg | 2f5faff | 2012-07-31 16:36:34 -0400 | [diff] [blame] | 659 | wl_list_init(&state->surface_destroy_listener.link); |
Jonas Ådahl | 0476974 | 2012-06-13 00:01:24 +0200 | [diff] [blame] | 660 | |
| 661 | return state; |
| 662 | } |
| 663 | |
Jonas Ådahl | 8538b22 | 2012-08-29 22:13:03 +0200 | [diff] [blame] | 664 | static struct focus_state * |
| 665 | ensure_focus_state(struct desktop_shell *shell, struct weston_seat *seat) |
| 666 | { |
| 667 | struct workspace *ws = get_current_workspace(shell); |
| 668 | struct focus_state *state; |
| 669 | |
| 670 | wl_list_for_each(state, &ws->focus_list, link) |
| 671 | if (state->seat == seat) |
| 672 | break; |
| 673 | |
| 674 | if (&state->link == &ws->focus_list) |
| 675 | state = focus_state_create(seat, ws); |
| 676 | |
| 677 | return state; |
| 678 | } |
| 679 | |
Jonas Ådahl | 0476974 | 2012-06-13 00:01:24 +0200 | [diff] [blame] | 680 | static void |
Kristian Høgsberg | d500bf1 | 2014-01-22 12:25:20 -0800 | [diff] [blame] | 681 | focus_state_set_focus(struct focus_state *state, |
| 682 | struct weston_surface *surface) |
| 683 | { |
| 684 | if (state->keyboard_focus) { |
| 685 | wl_list_remove(&state->surface_destroy_listener.link); |
| 686 | wl_list_init(&state->surface_destroy_listener.link); |
| 687 | } |
| 688 | |
| 689 | state->keyboard_focus = surface; |
| 690 | if (surface) |
| 691 | wl_signal_add(&surface->destroy_signal, |
| 692 | &state->surface_destroy_listener); |
| 693 | } |
| 694 | |
| 695 | static void |
Kristian Høgsberg | 2f5faff | 2012-07-31 16:36:34 -0400 | [diff] [blame] | 696 | restore_focus_state(struct desktop_shell *shell, struct workspace *ws) |
Jonas Ådahl | 0476974 | 2012-06-13 00:01:24 +0200 | [diff] [blame] | 697 | { |
| 698 | struct focus_state *state, *next; |
Kristian Høgsberg | fe7aa90 | 2013-05-08 09:54:37 -0400 | [diff] [blame] | 699 | struct weston_surface *surface; |
Neil Roberts | 4237f50 | 2014-04-09 16:33:31 +0100 | [diff] [blame] | 700 | struct wl_list pending_seat_list; |
| 701 | struct weston_seat *seat, *next_seat; |
| 702 | |
| 703 | /* Temporarily steal the list of seats so that we can keep |
| 704 | * track of the seats we've already processed */ |
| 705 | wl_list_init(&pending_seat_list); |
| 706 | wl_list_insert_list(&pending_seat_list, &shell->compositor->seat_list); |
| 707 | wl_list_init(&shell->compositor->seat_list); |
Jonas Ådahl | 0476974 | 2012-06-13 00:01:24 +0200 | [diff] [blame] | 708 | |
| 709 | wl_list_for_each_safe(state, next, &ws->focus_list, link) { |
Neil Roberts | 4237f50 | 2014-04-09 16:33:31 +0100 | [diff] [blame] | 710 | wl_list_remove(&state->seat->link); |
| 711 | wl_list_insert(&shell->compositor->seat_list, |
| 712 | &state->seat->link); |
| 713 | |
Kristian Høgsberg | e61d2f4 | 2014-01-17 12:18:53 -0800 | [diff] [blame] | 714 | if (state->seat->keyboard == NULL) |
| 715 | continue; |
| 716 | |
Kristian Høgsberg | fe7aa90 | 2013-05-08 09:54:37 -0400 | [diff] [blame] | 717 | surface = state->keyboard_focus; |
Jonas Ådahl | 5689944 | 2012-08-29 22:12:59 +0200 | [diff] [blame] | 718 | |
Kristian Høgsberg | e314875 | 2013-05-06 23:19:49 -0400 | [diff] [blame] | 719 | weston_keyboard_set_focus(state->seat->keyboard, surface); |
Jonas Ådahl | 0476974 | 2012-06-13 00:01:24 +0200 | [diff] [blame] | 720 | } |
Neil Roberts | 4237f50 | 2014-04-09 16:33:31 +0100 | [diff] [blame] | 721 | |
| 722 | /* For any remaining seats that we don't have a focus state |
| 723 | * for we'll reset the keyboard focus to NULL */ |
| 724 | wl_list_for_each_safe(seat, next_seat, &pending_seat_list, link) { |
| 725 | wl_list_insert(&shell->compositor->seat_list, &seat->link); |
| 726 | |
| 727 | if (state->seat->keyboard == NULL) |
| 728 | continue; |
| 729 | |
| 730 | weston_keyboard_set_focus(seat->keyboard, NULL); |
| 731 | } |
Jonas Ådahl | 0476974 | 2012-06-13 00:01:24 +0200 | [diff] [blame] | 732 | } |
| 733 | |
| 734 | static void |
Jonas Ådahl | 8de6a1d | 2012-08-29 22:13:00 +0200 | [diff] [blame] | 735 | replace_focus_state(struct desktop_shell *shell, struct workspace *ws, |
| 736 | struct weston_seat *seat) |
| 737 | { |
| 738 | struct focus_state *state; |
Jonas Ådahl | 8de6a1d | 2012-08-29 22:13:00 +0200 | [diff] [blame] | 739 | |
| 740 | wl_list_for_each(state, &ws->focus_list, link) { |
| 741 | if (state->seat == seat) { |
Kristian Høgsberg | d500bf1 | 2014-01-22 12:25:20 -0800 | [diff] [blame] | 742 | focus_state_set_focus(state, seat->keyboard->focus); |
Jonas Ådahl | 8de6a1d | 2012-08-29 22:13:00 +0200 | [diff] [blame] | 743 | return; |
| 744 | } |
| 745 | } |
| 746 | } |
| 747 | |
| 748 | static void |
| 749 | drop_focus_state(struct desktop_shell *shell, struct workspace *ws, |
| 750 | struct weston_surface *surface) |
| 751 | { |
| 752 | struct focus_state *state; |
| 753 | |
| 754 | wl_list_for_each(state, &ws->focus_list, link) |
| 755 | if (state->keyboard_focus == surface) |
Kristian Høgsberg | d500bf1 | 2014-01-22 12:25:20 -0800 | [diff] [blame] | 756 | focus_state_set_focus(state, NULL); |
Jonas Ådahl | 8de6a1d | 2012-08-29 22:13:00 +0200 | [diff] [blame] | 757 | } |
| 758 | |
| 759 | static void |
Louis-Francis Ratté-Boulianne | b482dbd | 2013-11-19 11:37:11 +0100 | [diff] [blame] | 760 | animate_focus_change(struct desktop_shell *shell, struct workspace *ws, |
| 761 | struct weston_view *from, struct weston_view *to) |
| 762 | { |
| 763 | struct weston_output *output; |
| 764 | bool focus_surface_created = false; |
| 765 | |
| 766 | /* FIXME: Only support dim animation using two layers */ |
| 767 | if (from == to || shell->focus_animation_type != ANIMATION_DIM_LAYER) |
| 768 | return; |
| 769 | |
| 770 | output = get_default_output(shell->compositor); |
| 771 | if (ws->fsurf_front == NULL && (from || to)) { |
| 772 | ws->fsurf_front = create_focus_surface(shell->compositor, output); |
U. Artie Eoff | 0b23b2b | 2014-01-15 14:45:59 -0800 | [diff] [blame] | 773 | if (ws->fsurf_front == NULL) |
| 774 | return; |
Louis-Francis Ratté-Boulianne | b482dbd | 2013-11-19 11:37:11 +0100 | [diff] [blame] | 775 | ws->fsurf_front->view->alpha = 0.0; |
U. Artie Eoff | 0b23b2b | 2014-01-15 14:45:59 -0800 | [diff] [blame] | 776 | |
| 777 | ws->fsurf_back = create_focus_surface(shell->compositor, output); |
| 778 | if (ws->fsurf_back == NULL) { |
| 779 | focus_surface_destroy(ws->fsurf_front); |
| 780 | return; |
| 781 | } |
Louis-Francis Ratté-Boulianne | b482dbd | 2013-11-19 11:37:11 +0100 | [diff] [blame] | 782 | ws->fsurf_back->view->alpha = 0.0; |
U. Artie Eoff | 0b23b2b | 2014-01-15 14:45:59 -0800 | [diff] [blame] | 783 | |
Louis-Francis Ratté-Boulianne | b482dbd | 2013-11-19 11:37:11 +0100 | [diff] [blame] | 784 | focus_surface_created = true; |
| 785 | } else { |
| 786 | wl_list_remove(&ws->fsurf_front->view->layer_link); |
| 787 | wl_list_remove(&ws->fsurf_back->view->layer_link); |
| 788 | } |
| 789 | |
| 790 | if (ws->focus_animation) { |
| 791 | weston_view_animation_destroy(ws->focus_animation); |
| 792 | ws->focus_animation = NULL; |
| 793 | } |
| 794 | |
| 795 | if (to) |
| 796 | wl_list_insert(&to->layer_link, |
| 797 | &ws->fsurf_front->view->layer_link); |
| 798 | else if (from) |
| 799 | wl_list_insert(&ws->layer.view_list, |
| 800 | &ws->fsurf_front->view->layer_link); |
| 801 | |
| 802 | if (focus_surface_created) { |
| 803 | ws->focus_animation = weston_fade_run( |
| 804 | ws->fsurf_front->view, |
| 805 | ws->fsurf_front->view->alpha, 0.6, 300, |
| 806 | focus_animation_done, ws); |
| 807 | } else if (from) { |
| 808 | wl_list_insert(&from->layer_link, |
| 809 | &ws->fsurf_back->view->layer_link); |
| 810 | ws->focus_animation = weston_stable_fade_run( |
| 811 | ws->fsurf_front->view, 0.0, |
| 812 | ws->fsurf_back->view, 0.6, |
| 813 | focus_animation_done, ws); |
| 814 | } else if (to) { |
| 815 | wl_list_insert(&ws->layer.view_list, |
| 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 | } |
| 822 | } |
| 823 | |
| 824 | static void |
Jonas Ådahl | e3cddce | 2012-06-13 00:01:22 +0200 | [diff] [blame] | 825 | workspace_destroy(struct workspace *ws) |
| 826 | { |
Jonas Ådahl | 0476974 | 2012-06-13 00:01:24 +0200 | [diff] [blame] | 827 | struct focus_state *state, *next; |
| 828 | |
| 829 | wl_list_for_each_safe(state, next, &ws->focus_list, link) |
| 830 | focus_state_destroy(state); |
| 831 | |
Louis-Francis Ratté-Boulianne | b482dbd | 2013-11-19 11:37:11 +0100 | [diff] [blame] | 832 | if (ws->fsurf_front) |
| 833 | focus_surface_destroy(ws->fsurf_front); |
| 834 | if (ws->fsurf_back) |
| 835 | focus_surface_destroy(ws->fsurf_back); |
| 836 | |
Jonas Ådahl | e3cddce | 2012-06-13 00:01:22 +0200 | [diff] [blame] | 837 | free(ws); |
| 838 | } |
| 839 | |
Jonas Ådahl | 0476974 | 2012-06-13 00:01:24 +0200 | [diff] [blame] | 840 | static void |
| 841 | seat_destroyed(struct wl_listener *listener, void *data) |
| 842 | { |
| 843 | struct weston_seat *seat = data; |
| 844 | struct focus_state *state, *next; |
| 845 | struct workspace *ws = container_of(listener, |
| 846 | struct workspace, |
| 847 | seat_destroyed_listener); |
| 848 | |
| 849 | wl_list_for_each_safe(state, next, &ws->focus_list, link) |
| 850 | if (state->seat == seat) |
| 851 | wl_list_remove(&state->link); |
| 852 | } |
| 853 | |
Jonas Ådahl | e3cddce | 2012-06-13 00:01:22 +0200 | [diff] [blame] | 854 | static struct workspace * |
| 855 | workspace_create(void) |
| 856 | { |
| 857 | struct workspace *ws = malloc(sizeof *ws); |
| 858 | if (ws == NULL) |
| 859 | return NULL; |
| 860 | |
| 861 | weston_layer_init(&ws->layer, NULL); |
| 862 | |
Jonas Ådahl | 0476974 | 2012-06-13 00:01:24 +0200 | [diff] [blame] | 863 | wl_list_init(&ws->focus_list); |
| 864 | wl_list_init(&ws->seat_destroyed_listener.link); |
| 865 | ws->seat_destroyed_listener.notify = seat_destroyed; |
Louis-Francis Ratté-Boulianne | b482dbd | 2013-11-19 11:37:11 +0100 | [diff] [blame] | 866 | ws->fsurf_front = NULL; |
| 867 | ws->fsurf_back = NULL; |
| 868 | ws->focus_animation = NULL; |
Jonas Ådahl | 0476974 | 2012-06-13 00:01:24 +0200 | [diff] [blame] | 869 | |
Jonas Ådahl | e3cddce | 2012-06-13 00:01:22 +0200 | [diff] [blame] | 870 | return ws; |
| 871 | } |
| 872 | |
Jonas Ådahl | 62fcd04 | 2012-06-13 00:01:23 +0200 | [diff] [blame] | 873 | static int |
| 874 | workspace_is_empty(struct workspace *ws) |
| 875 | { |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 876 | return wl_list_empty(&ws->layer.view_list); |
Jonas Ådahl | 62fcd04 | 2012-06-13 00:01:23 +0200 | [diff] [blame] | 877 | } |
| 878 | |
Jonas Ådahl | e3cddce | 2012-06-13 00:01:22 +0200 | [diff] [blame] | 879 | static struct workspace * |
| 880 | get_workspace(struct desktop_shell *shell, unsigned int index) |
| 881 | { |
| 882 | struct workspace **pws = shell->workspaces.array.data; |
Philipp Brüschweiler | 067abf6 | 2012-09-01 16:03:05 +0200 | [diff] [blame] | 883 | assert(index < shell->workspaces.num); |
Jonas Ådahl | e3cddce | 2012-06-13 00:01:22 +0200 | [diff] [blame] | 884 | pws += index; |
| 885 | return *pws; |
| 886 | } |
| 887 | |
Kristian Høgsberg | 1ef2313 | 2013-12-04 00:20:01 -0800 | [diff] [blame] | 888 | struct workspace * |
Jonas Ådahl | e3cddce | 2012-06-13 00:01:22 +0200 | [diff] [blame] | 889 | get_current_workspace(struct desktop_shell *shell) |
| 890 | { |
| 891 | return get_workspace(shell, shell->workspaces.current); |
| 892 | } |
| 893 | |
| 894 | static void |
| 895 | activate_workspace(struct desktop_shell *shell, unsigned int index) |
| 896 | { |
| 897 | struct workspace *ws; |
| 898 | |
| 899 | ws = get_workspace(shell, index); |
| 900 | wl_list_insert(&shell->panel_layer.link, &ws->layer.link); |
| 901 | |
| 902 | shell->workspaces.current = index; |
| 903 | } |
| 904 | |
Jonas Ådahl | 62fcd04 | 2012-06-13 00:01:23 +0200 | [diff] [blame] | 905 | static unsigned int |
| 906 | get_output_height(struct weston_output *output) |
| 907 | { |
| 908 | return abs(output->region.extents.y1 - output->region.extents.y2); |
| 909 | } |
| 910 | |
| 911 | static void |
Louis-Francis Ratté-Boulianne | b482dbd | 2013-11-19 11:37:11 +0100 | [diff] [blame] | 912 | view_translate(struct workspace *ws, struct weston_view *view, double d) |
Jonas Ådahl | 62fcd04 | 2012-06-13 00:01:23 +0200 | [diff] [blame] | 913 | { |
Jonas Ådahl | 62fcd04 | 2012-06-13 00:01:23 +0200 | [diff] [blame] | 914 | struct weston_transform *transform; |
| 915 | |
Louis-Francis Ratté-Boulianne | b482dbd | 2013-11-19 11:37:11 +0100 | [diff] [blame] | 916 | if (is_focus_view(view)) { |
| 917 | struct focus_surface *fsurf = get_focus_surface(view->surface); |
| 918 | transform = &fsurf->workspace_transform; |
| 919 | } else { |
| 920 | struct shell_surface *shsurf = get_shell_surface(view->surface); |
| 921 | transform = &shsurf->workspace_transform; |
| 922 | } |
| 923 | |
Jonas Ådahl | 62fcd04 | 2012-06-13 00:01:23 +0200 | [diff] [blame] | 924 | if (wl_list_empty(&transform->link)) |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 925 | wl_list_insert(view->geometry.transformation_list.prev, |
Louis-Francis Ratté-Boulianne | b482dbd | 2013-11-19 11:37:11 +0100 | [diff] [blame] | 926 | &transform->link); |
Jonas Ådahl | 62fcd04 | 2012-06-13 00:01:23 +0200 | [diff] [blame] | 927 | |
Louis-Francis Ratté-Boulianne | b482dbd | 2013-11-19 11:37:11 +0100 | [diff] [blame] | 928 | weston_matrix_init(&transform->matrix); |
| 929 | weston_matrix_translate(&transform->matrix, |
Jonas Ådahl | 62fcd04 | 2012-06-13 00:01:23 +0200 | [diff] [blame] | 930 | 0.0, d, 0.0); |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 931 | weston_view_geometry_dirty(view); |
Jonas Ådahl | 62fcd04 | 2012-06-13 00:01:23 +0200 | [diff] [blame] | 932 | } |
| 933 | |
| 934 | static void |
| 935 | workspace_translate_out(struct workspace *ws, double fraction) |
| 936 | { |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 937 | struct weston_view *view; |
Jonas Ådahl | 62fcd04 | 2012-06-13 00:01:23 +0200 | [diff] [blame] | 938 | unsigned int height; |
| 939 | double d; |
| 940 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 941 | wl_list_for_each(view, &ws->layer.view_list, layer_link) { |
| 942 | height = get_output_height(view->surface->output); |
Jonas Ådahl | 62fcd04 | 2012-06-13 00:01:23 +0200 | [diff] [blame] | 943 | d = height * fraction; |
| 944 | |
Louis-Francis Ratté-Boulianne | b482dbd | 2013-11-19 11:37:11 +0100 | [diff] [blame] | 945 | view_translate(ws, view, d); |
Jonas Ådahl | 62fcd04 | 2012-06-13 00:01:23 +0200 | [diff] [blame] | 946 | } |
| 947 | } |
| 948 | |
| 949 | static void |
| 950 | workspace_translate_in(struct workspace *ws, double fraction) |
| 951 | { |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 952 | struct weston_view *view; |
Jonas Ådahl | 62fcd04 | 2012-06-13 00:01:23 +0200 | [diff] [blame] | 953 | unsigned int height; |
| 954 | double d; |
| 955 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 956 | wl_list_for_each(view, &ws->layer.view_list, layer_link) { |
| 957 | height = get_output_height(view->surface->output); |
Jonas Ådahl | 62fcd04 | 2012-06-13 00:01:23 +0200 | [diff] [blame] | 958 | |
| 959 | if (fraction > 0) |
| 960 | d = -(height - height * fraction); |
| 961 | else |
| 962 | d = height + height * fraction; |
| 963 | |
Louis-Francis Ratté-Boulianne | b482dbd | 2013-11-19 11:37:11 +0100 | [diff] [blame] | 964 | view_translate(ws, view, d); |
Jonas Ådahl | 62fcd04 | 2012-06-13 00:01:23 +0200 | [diff] [blame] | 965 | } |
| 966 | } |
| 967 | |
| 968 | static void |
Jonas Ådahl | e9d2250 | 2012-08-29 22:13:01 +0200 | [diff] [blame] | 969 | broadcast_current_workspace_state(struct desktop_shell *shell) |
| 970 | { |
Kristian Høgsberg | 2e3c396 | 2013-09-11 12:00:47 -0700 | [diff] [blame] | 971 | struct wl_resource *resource; |
Jonas Ådahl | e9d2250 | 2012-08-29 22:13:01 +0200 | [diff] [blame] | 972 | |
Kristian Høgsberg | 2e3c396 | 2013-09-11 12:00:47 -0700 | [diff] [blame] | 973 | wl_resource_for_each(resource, &shell->workspaces.client_list) |
| 974 | workspace_manager_send_state(resource, |
Jonas Ådahl | e9d2250 | 2012-08-29 22:13:01 +0200 | [diff] [blame] | 975 | shell->workspaces.current, |
| 976 | shell->workspaces.num); |
| 977 | } |
| 978 | |
| 979 | static void |
Jonas Ådahl | 62fcd04 | 2012-06-13 00:01:23 +0200 | [diff] [blame] | 980 | reverse_workspace_change_animation(struct desktop_shell *shell, |
| 981 | unsigned int index, |
| 982 | struct workspace *from, |
| 983 | struct workspace *to) |
| 984 | { |
| 985 | shell->workspaces.current = index; |
| 986 | |
| 987 | shell->workspaces.anim_to = to; |
| 988 | shell->workspaces.anim_from = from; |
| 989 | shell->workspaces.anim_dir = -1 * shell->workspaces.anim_dir; |
| 990 | shell->workspaces.anim_timestamp = 0; |
| 991 | |
Scott Moreau | 4272e63 | 2012-08-13 09:58:41 -0600 | [diff] [blame] | 992 | weston_compositor_schedule_repaint(shell->compositor); |
Jonas Ådahl | 62fcd04 | 2012-06-13 00:01:23 +0200 | [diff] [blame] | 993 | } |
| 994 | |
| 995 | static void |
| 996 | workspace_deactivate_transforms(struct workspace *ws) |
| 997 | { |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 998 | struct weston_view *view; |
Louis-Francis Ratté-Boulianne | b482dbd | 2013-11-19 11:37:11 +0100 | [diff] [blame] | 999 | struct weston_transform *transform; |
Jonas Ådahl | 62fcd04 | 2012-06-13 00:01:23 +0200 | [diff] [blame] | 1000 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 1001 | 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] | 1002 | if (is_focus_view(view)) { |
| 1003 | struct focus_surface *fsurf = get_focus_surface(view->surface); |
| 1004 | transform = &fsurf->workspace_transform; |
| 1005 | } else { |
| 1006 | struct shell_surface *shsurf = get_shell_surface(view->surface); |
| 1007 | transform = &shsurf->workspace_transform; |
| 1008 | } |
| 1009 | |
| 1010 | if (!wl_list_empty(&transform->link)) { |
| 1011 | wl_list_remove(&transform->link); |
| 1012 | wl_list_init(&transform->link); |
Jonas Ådahl | 8de6a1d | 2012-08-29 22:13:00 +0200 | [diff] [blame] | 1013 | } |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 1014 | weston_view_geometry_dirty(view); |
Jonas Ådahl | 62fcd04 | 2012-06-13 00:01:23 +0200 | [diff] [blame] | 1015 | } |
| 1016 | } |
| 1017 | |
| 1018 | static void |
| 1019 | finish_workspace_change_animation(struct desktop_shell *shell, |
| 1020 | struct workspace *from, |
| 1021 | struct workspace *to) |
| 1022 | { |
Scott Moreau | 4272e63 | 2012-08-13 09:58:41 -0600 | [diff] [blame] | 1023 | weston_compositor_schedule_repaint(shell->compositor); |
Jonas Ådahl | 62fcd04 | 2012-06-13 00:01:23 +0200 | [diff] [blame] | 1024 | |
| 1025 | wl_list_remove(&shell->workspaces.animation.link); |
| 1026 | workspace_deactivate_transforms(from); |
| 1027 | workspace_deactivate_transforms(to); |
| 1028 | shell->workspaces.anim_to = NULL; |
| 1029 | |
| 1030 | wl_list_remove(&shell->workspaces.anim_from->layer.link); |
| 1031 | } |
| 1032 | |
| 1033 | static void |
| 1034 | animate_workspace_change_frame(struct weston_animation *animation, |
| 1035 | struct weston_output *output, uint32_t msecs) |
| 1036 | { |
| 1037 | struct desktop_shell *shell = |
| 1038 | container_of(animation, struct desktop_shell, |
| 1039 | workspaces.animation); |
| 1040 | struct workspace *from = shell->workspaces.anim_from; |
| 1041 | struct workspace *to = shell->workspaces.anim_to; |
| 1042 | uint32_t t; |
| 1043 | double x, y; |
| 1044 | |
| 1045 | if (workspace_is_empty(from) && workspace_is_empty(to)) { |
| 1046 | finish_workspace_change_animation(shell, from, to); |
| 1047 | return; |
| 1048 | } |
| 1049 | |
| 1050 | if (shell->workspaces.anim_timestamp == 0) { |
| 1051 | if (shell->workspaces.anim_current == 0.0) |
| 1052 | shell->workspaces.anim_timestamp = msecs; |
| 1053 | else |
| 1054 | shell->workspaces.anim_timestamp = |
| 1055 | msecs - |
| 1056 | /* Invers of movement function 'y' below. */ |
| 1057 | (asin(1.0 - shell->workspaces.anim_current) * |
| 1058 | DEFAULT_WORKSPACE_CHANGE_ANIMATION_LENGTH * |
| 1059 | M_2_PI); |
| 1060 | } |
| 1061 | |
| 1062 | t = msecs - shell->workspaces.anim_timestamp; |
| 1063 | |
| 1064 | /* |
| 1065 | * x = [0, π/2] |
| 1066 | * y(x) = sin(x) |
| 1067 | */ |
| 1068 | x = t * (1.0/DEFAULT_WORKSPACE_CHANGE_ANIMATION_LENGTH) * M_PI_2; |
| 1069 | y = sin(x); |
| 1070 | |
| 1071 | if (t < DEFAULT_WORKSPACE_CHANGE_ANIMATION_LENGTH) { |
Scott Moreau | 4272e63 | 2012-08-13 09:58:41 -0600 | [diff] [blame] | 1072 | weston_compositor_schedule_repaint(shell->compositor); |
Jonas Ådahl | 62fcd04 | 2012-06-13 00:01:23 +0200 | [diff] [blame] | 1073 | |
| 1074 | workspace_translate_out(from, shell->workspaces.anim_dir * y); |
| 1075 | workspace_translate_in(to, shell->workspaces.anim_dir * y); |
| 1076 | shell->workspaces.anim_current = y; |
| 1077 | |
Scott Moreau | 4272e63 | 2012-08-13 09:58:41 -0600 | [diff] [blame] | 1078 | weston_compositor_schedule_repaint(shell->compositor); |
Jonas Ådahl | 62fcd04 | 2012-06-13 00:01:23 +0200 | [diff] [blame] | 1079 | } |
Jonas Ådahl | 0476974 | 2012-06-13 00:01:24 +0200 | [diff] [blame] | 1080 | else |
Jonas Ådahl | 62fcd04 | 2012-06-13 00:01:23 +0200 | [diff] [blame] | 1081 | finish_workspace_change_animation(shell, from, to); |
Jonas Ådahl | 62fcd04 | 2012-06-13 00:01:23 +0200 | [diff] [blame] | 1082 | } |
| 1083 | |
| 1084 | static void |
| 1085 | animate_workspace_change(struct desktop_shell *shell, |
| 1086 | unsigned int index, |
| 1087 | struct workspace *from, |
| 1088 | struct workspace *to) |
| 1089 | { |
| 1090 | struct weston_output *output; |
| 1091 | |
| 1092 | int dir; |
| 1093 | |
| 1094 | if (index > shell->workspaces.current) |
| 1095 | dir = -1; |
| 1096 | else |
| 1097 | dir = 1; |
| 1098 | |
| 1099 | shell->workspaces.current = index; |
| 1100 | |
| 1101 | shell->workspaces.anim_dir = dir; |
| 1102 | shell->workspaces.anim_from = from; |
| 1103 | shell->workspaces.anim_to = to; |
| 1104 | shell->workspaces.anim_current = 0.0; |
| 1105 | shell->workspaces.anim_timestamp = 0; |
| 1106 | |
| 1107 | output = container_of(shell->compositor->output_list.next, |
| 1108 | struct weston_output, link); |
| 1109 | wl_list_insert(&output->animation_list, |
| 1110 | &shell->workspaces.animation.link); |
| 1111 | |
Jonas Ådahl | 8de6a1d | 2012-08-29 22:13:00 +0200 | [diff] [blame] | 1112 | wl_list_insert(from->layer.link.prev, &to->layer.link); |
Jonas Ådahl | 62fcd04 | 2012-06-13 00:01:23 +0200 | [diff] [blame] | 1113 | |
| 1114 | workspace_translate_in(to, 0); |
| 1115 | |
Kristian Høgsberg | 2f5faff | 2012-07-31 16:36:34 -0400 | [diff] [blame] | 1116 | restore_focus_state(shell, to); |
Jonas Ådahl | 0476974 | 2012-06-13 00:01:24 +0200 | [diff] [blame] | 1117 | |
Scott Moreau | 4272e63 | 2012-08-13 09:58:41 -0600 | [diff] [blame] | 1118 | weston_compositor_schedule_repaint(shell->compositor); |
Jonas Ådahl | 62fcd04 | 2012-06-13 00:01:23 +0200 | [diff] [blame] | 1119 | } |
| 1120 | |
Jonas Ådahl | e3cddce | 2012-06-13 00:01:22 +0200 | [diff] [blame] | 1121 | static void |
Jonas Ådahl | 8de6a1d | 2012-08-29 22:13:00 +0200 | [diff] [blame] | 1122 | update_workspace(struct desktop_shell *shell, unsigned int index, |
| 1123 | struct workspace *from, struct workspace *to) |
| 1124 | { |
| 1125 | shell->workspaces.current = index; |
| 1126 | wl_list_insert(&from->layer.link, &to->layer.link); |
| 1127 | wl_list_remove(&from->layer.link); |
| 1128 | } |
| 1129 | |
| 1130 | static void |
Jonas Ådahl | e3cddce | 2012-06-13 00:01:22 +0200 | [diff] [blame] | 1131 | change_workspace(struct desktop_shell *shell, unsigned int index) |
| 1132 | { |
| 1133 | struct workspace *from; |
| 1134 | struct workspace *to; |
Louis-Francis Ratté-Boulianne | b482dbd | 2013-11-19 11:37:11 +0100 | [diff] [blame] | 1135 | struct focus_state *state; |
Jonas Ådahl | e3cddce | 2012-06-13 00:01:22 +0200 | [diff] [blame] | 1136 | |
| 1137 | if (index == shell->workspaces.current) |
| 1138 | return; |
| 1139 | |
| 1140 | /* Don't change workspace when there is any fullscreen surfaces. */ |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 1141 | if (!wl_list_empty(&shell->fullscreen_layer.view_list)) |
Jonas Ådahl | e3cddce | 2012-06-13 00:01:22 +0200 | [diff] [blame] | 1142 | return; |
| 1143 | |
Jonas Ådahl | e3cddce | 2012-06-13 00:01:22 +0200 | [diff] [blame] | 1144 | from = get_current_workspace(shell); |
| 1145 | to = get_workspace(shell, index); |
| 1146 | |
Jonas Ådahl | 62fcd04 | 2012-06-13 00:01:23 +0200 | [diff] [blame] | 1147 | if (shell->workspaces.anim_from == to && |
| 1148 | shell->workspaces.anim_to == from) { |
Jonas Ådahl | 8de6a1d | 2012-08-29 22:13:00 +0200 | [diff] [blame] | 1149 | restore_focus_state(shell, to); |
Jonas Ådahl | 62fcd04 | 2012-06-13 00:01:23 +0200 | [diff] [blame] | 1150 | reverse_workspace_change_animation(shell, index, from, to); |
Jonas Ådahl | e9d2250 | 2012-08-29 22:13:01 +0200 | [diff] [blame] | 1151 | broadcast_current_workspace_state(shell); |
Jonas Ådahl | 62fcd04 | 2012-06-13 00:01:23 +0200 | [diff] [blame] | 1152 | return; |
| 1153 | } |
Jonas Ådahl | e3cddce | 2012-06-13 00:01:22 +0200 | [diff] [blame] | 1154 | |
Jonas Ådahl | 62fcd04 | 2012-06-13 00:01:23 +0200 | [diff] [blame] | 1155 | if (shell->workspaces.anim_to != NULL) |
| 1156 | finish_workspace_change_animation(shell, |
| 1157 | shell->workspaces.anim_from, |
| 1158 | shell->workspaces.anim_to); |
| 1159 | |
Jonas Ådahl | 8de6a1d | 2012-08-29 22:13:00 +0200 | [diff] [blame] | 1160 | restore_focus_state(shell, to); |
Jonas Ådahl | 0476974 | 2012-06-13 00:01:24 +0200 | [diff] [blame] | 1161 | |
Louis-Francis Ratté-Boulianne | b482dbd | 2013-11-19 11:37:11 +0100 | [diff] [blame] | 1162 | if (shell->focus_animation_type != ANIMATION_NONE) { |
| 1163 | wl_list_for_each(state, &from->focus_list, link) |
| 1164 | if (state->keyboard_focus) |
| 1165 | animate_focus_change(shell, from, |
| 1166 | get_default_view(state->keyboard_focus), NULL); |
| 1167 | |
| 1168 | wl_list_for_each(state, &to->focus_list, link) |
| 1169 | if (state->keyboard_focus) |
| 1170 | animate_focus_change(shell, to, |
| 1171 | NULL, get_default_view(state->keyboard_focus)); |
| 1172 | } |
| 1173 | |
Jonas Ådahl | 8de6a1d | 2012-08-29 22:13:00 +0200 | [diff] [blame] | 1174 | if (workspace_is_empty(to) && workspace_is_empty(from)) |
| 1175 | update_workspace(shell, index, from, to); |
Jonas Ådahl | 62fcd04 | 2012-06-13 00:01:23 +0200 | [diff] [blame] | 1176 | else |
| 1177 | animate_workspace_change(shell, index, from, to); |
Jonas Ådahl | e9d2250 | 2012-08-29 22:13:01 +0200 | [diff] [blame] | 1178 | |
| 1179 | broadcast_current_workspace_state(shell); |
Pekka Paalanen | e955f1e | 2011-12-07 11:49:52 +0200 | [diff] [blame] | 1180 | } |
| 1181 | |
Jonas Ådahl | 8de6a1d | 2012-08-29 22:13:00 +0200 | [diff] [blame] | 1182 | static bool |
| 1183 | workspace_has_only(struct workspace *ws, struct weston_surface *surface) |
| 1184 | { |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 1185 | struct wl_list *list = &ws->layer.view_list; |
Jonas Ådahl | 8de6a1d | 2012-08-29 22:13:00 +0200 | [diff] [blame] | 1186 | struct wl_list *e; |
| 1187 | |
| 1188 | if (wl_list_empty(list)) |
| 1189 | return false; |
| 1190 | |
| 1191 | e = list->next; |
| 1192 | |
| 1193 | if (e->next != list) |
| 1194 | return false; |
| 1195 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 1196 | return container_of(e, struct weston_view, layer_link)->surface == surface; |
Jonas Ådahl | 8de6a1d | 2012-08-29 22:13:00 +0200 | [diff] [blame] | 1197 | } |
| 1198 | |
| 1199 | static void |
Philip Withnall | 659163d | 2013-11-25 18:01:36 +0000 | [diff] [blame] | 1200 | move_surface_to_workspace(struct desktop_shell *shell, |
| 1201 | struct shell_surface *shsurf, |
| 1202 | uint32_t workspace) |
Jonas Ådahl | e9d2250 | 2012-08-29 22:13:01 +0200 | [diff] [blame] | 1203 | { |
| 1204 | struct workspace *from; |
| 1205 | struct workspace *to; |
| 1206 | struct weston_seat *seat; |
Pekka Paalanen | 01388e2 | 2013-04-25 13:57:44 +0300 | [diff] [blame] | 1207 | struct weston_surface *focus; |
Philip Withnall | 659163d | 2013-11-25 18:01:36 +0000 | [diff] [blame] | 1208 | struct weston_view *view; |
Jonas Ådahl | e9d2250 | 2012-08-29 22:13:01 +0200 | [diff] [blame] | 1209 | |
| 1210 | if (workspace == shell->workspaces.current) |
| 1211 | return; |
| 1212 | |
Philip Withnall | 659163d | 2013-11-25 18:01:36 +0000 | [diff] [blame] | 1213 | view = get_default_view(shsurf->surface); |
| 1214 | if (!view) |
| 1215 | return; |
| 1216 | |
| 1217 | assert(weston_surface_get_main_surface(view->surface) == view->surface); |
| 1218 | |
Philipp Brüschweiler | 067abf6 | 2012-09-01 16:03:05 +0200 | [diff] [blame] | 1219 | if (workspace >= shell->workspaces.num) |
| 1220 | workspace = shell->workspaces.num - 1; |
| 1221 | |
Jonas Ådahl | e9d2250 | 2012-08-29 22:13:01 +0200 | [diff] [blame] | 1222 | from = get_current_workspace(shell); |
| 1223 | to = get_workspace(shell, workspace); |
| 1224 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 1225 | wl_list_remove(&view->layer_link); |
| 1226 | wl_list_insert(&to->layer.view_list, &view->layer_link); |
Jonas Ådahl | e9d2250 | 2012-08-29 22:13:01 +0200 | [diff] [blame] | 1227 | |
Philip Withnall | 648a4dd | 2013-11-25 18:01:44 +0000 | [diff] [blame] | 1228 | shell_surface_update_child_surface_layers(shsurf); |
| 1229 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 1230 | drop_focus_state(shell, from, view->surface); |
Pekka Paalanen | 01388e2 | 2013-04-25 13:57:44 +0300 | [diff] [blame] | 1231 | wl_list_for_each(seat, &shell->compositor->seat_list, link) { |
| 1232 | if (!seat->keyboard) |
| 1233 | continue; |
| 1234 | |
| 1235 | focus = weston_surface_get_main_surface(seat->keyboard->focus); |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 1236 | if (focus == view->surface) |
Kristian Høgsberg | e314875 | 2013-05-06 23:19:49 -0400 | [diff] [blame] | 1237 | weston_keyboard_set_focus(seat->keyboard, NULL); |
Pekka Paalanen | 01388e2 | 2013-04-25 13:57:44 +0300 | [diff] [blame] | 1238 | } |
Jonas Ådahl | e9d2250 | 2012-08-29 22:13:01 +0200 | [diff] [blame] | 1239 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 1240 | weston_view_damage_below(view); |
Jonas Ådahl | e9d2250 | 2012-08-29 22:13:01 +0200 | [diff] [blame] | 1241 | } |
| 1242 | |
| 1243 | static void |
Jonas Ådahl | 8de6a1d | 2012-08-29 22:13:00 +0200 | [diff] [blame] | 1244 | take_surface_to_workspace_by_seat(struct desktop_shell *shell, |
Kristian Høgsberg | e314875 | 2013-05-06 23:19:49 -0400 | [diff] [blame] | 1245 | struct weston_seat *seat, |
Jonas Ådahl | 8de6a1d | 2012-08-29 22:13:00 +0200 | [diff] [blame] | 1246 | unsigned int index) |
| 1247 | { |
Pekka Paalanen | 01388e2 | 2013-04-25 13:57:44 +0300 | [diff] [blame] | 1248 | struct weston_surface *surface; |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 1249 | struct weston_view *view; |
Jonas Ådahl | 8de6a1d | 2012-08-29 22:13:00 +0200 | [diff] [blame] | 1250 | struct shell_surface *shsurf; |
| 1251 | struct workspace *from; |
| 1252 | struct workspace *to; |
Jonas Ådahl | 8538b22 | 2012-08-29 22:13:03 +0200 | [diff] [blame] | 1253 | struct focus_state *state; |
Jonas Ådahl | 8de6a1d | 2012-08-29 22:13:00 +0200 | [diff] [blame] | 1254 | |
Pekka Paalanen | 01388e2 | 2013-04-25 13:57:44 +0300 | [diff] [blame] | 1255 | surface = weston_surface_get_main_surface(seat->keyboard->focus); |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 1256 | view = get_default_view(surface); |
| 1257 | if (view == NULL || |
Louis-Francis Ratté-Boulianne | b482dbd | 2013-11-19 11:37:11 +0100 | [diff] [blame] | 1258 | index == shell->workspaces.current || |
| 1259 | is_focus_view(view)) |
Jonas Ådahl | 8de6a1d | 2012-08-29 22:13:00 +0200 | [diff] [blame] | 1260 | return; |
| 1261 | |
| 1262 | from = get_current_workspace(shell); |
| 1263 | to = get_workspace(shell, index); |
| 1264 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 1265 | wl_list_remove(&view->layer_link); |
| 1266 | wl_list_insert(&to->layer.view_list, &view->layer_link); |
Jonas Ådahl | 8de6a1d | 2012-08-29 22:13:00 +0200 | [diff] [blame] | 1267 | |
Philip Withnall | 659163d | 2013-11-25 18:01:36 +0000 | [diff] [blame] | 1268 | shsurf = get_shell_surface(surface); |
Philip Withnall | 648a4dd | 2013-11-25 18:01:44 +0000 | [diff] [blame] | 1269 | if (shsurf != NULL) |
| 1270 | shell_surface_update_child_surface_layers(shsurf); |
Philip Withnall | 659163d | 2013-11-25 18:01:36 +0000 | [diff] [blame] | 1271 | |
Jonas Ådahl | e9d2250 | 2012-08-29 22:13:01 +0200 | [diff] [blame] | 1272 | replace_focus_state(shell, to, seat); |
Jonas Ådahl | 8de6a1d | 2012-08-29 22:13:00 +0200 | [diff] [blame] | 1273 | drop_focus_state(shell, from, surface); |
| 1274 | |
| 1275 | if (shell->workspaces.anim_from == to && |
| 1276 | shell->workspaces.anim_to == from) { |
Jonas Ådahl | e9d2250 | 2012-08-29 22:13:01 +0200 | [diff] [blame] | 1277 | wl_list_remove(&to->layer.link); |
| 1278 | wl_list_insert(from->layer.link.prev, &to->layer.link); |
| 1279 | |
Jonas Ådahl | 8de6a1d | 2012-08-29 22:13:00 +0200 | [diff] [blame] | 1280 | reverse_workspace_change_animation(shell, index, from, to); |
Jonas Ådahl | e9d2250 | 2012-08-29 22:13:01 +0200 | [diff] [blame] | 1281 | broadcast_current_workspace_state(shell); |
| 1282 | |
Jonas Ådahl | 8de6a1d | 2012-08-29 22:13:00 +0200 | [diff] [blame] | 1283 | return; |
| 1284 | } |
| 1285 | |
| 1286 | if (shell->workspaces.anim_to != NULL) |
| 1287 | finish_workspace_change_animation(shell, |
| 1288 | shell->workspaces.anim_from, |
| 1289 | shell->workspaces.anim_to); |
| 1290 | |
| 1291 | if (workspace_is_empty(from) && |
| 1292 | workspace_has_only(to, surface)) |
| 1293 | update_workspace(shell, index, from, to); |
| 1294 | else { |
Philip Withnall | 2c3849b | 2013-11-25 18:01:45 +0000 | [diff] [blame] | 1295 | if (shsurf != NULL && |
| 1296 | wl_list_empty(&shsurf->workspace_transform.link)) |
Jonas Ådahl | 8de6a1d | 2012-08-29 22:13:00 +0200 | [diff] [blame] | 1297 | wl_list_insert(&shell->workspaces.anim_sticky_list, |
| 1298 | &shsurf->workspace_transform.link); |
| 1299 | |
| 1300 | animate_workspace_change(shell, index, from, to); |
| 1301 | } |
Jonas Ådahl | e9d2250 | 2012-08-29 22:13:01 +0200 | [diff] [blame] | 1302 | |
| 1303 | broadcast_current_workspace_state(shell); |
Jonas Ådahl | 8538b22 | 2012-08-29 22:13:03 +0200 | [diff] [blame] | 1304 | |
| 1305 | state = ensure_focus_state(shell, seat); |
| 1306 | if (state != NULL) |
Kristian Høgsberg | d500bf1 | 2014-01-22 12:25:20 -0800 | [diff] [blame] | 1307 | focus_state_set_focus(state, surface); |
Jonas Ådahl | e9d2250 | 2012-08-29 22:13:01 +0200 | [diff] [blame] | 1308 | } |
| 1309 | |
| 1310 | static void |
| 1311 | workspace_manager_move_surface(struct wl_client *client, |
| 1312 | struct wl_resource *resource, |
| 1313 | struct wl_resource *surface_resource, |
| 1314 | uint32_t workspace) |
| 1315 | { |
Jason Ekstrand | 651f00e | 2013-06-14 10:07:54 -0500 | [diff] [blame] | 1316 | struct desktop_shell *shell = wl_resource_get_user_data(resource); |
Jonas Ådahl | e9d2250 | 2012-08-29 22:13:01 +0200 | [diff] [blame] | 1317 | struct weston_surface *surface = |
Jason Ekstrand | 0f2ef7e | 2013-06-14 10:07:53 -0500 | [diff] [blame] | 1318 | wl_resource_get_user_data(surface_resource); |
Pekka Paalanen | 01388e2 | 2013-04-25 13:57:44 +0300 | [diff] [blame] | 1319 | struct weston_surface *main_surface; |
Philip Withnall | 659163d | 2013-11-25 18:01:36 +0000 | [diff] [blame] | 1320 | struct shell_surface *shell_surface; |
Jonas Ådahl | e9d2250 | 2012-08-29 22:13:01 +0200 | [diff] [blame] | 1321 | |
Pekka Paalanen | 01388e2 | 2013-04-25 13:57:44 +0300 | [diff] [blame] | 1322 | main_surface = weston_surface_get_main_surface(surface); |
Philip Withnall | 659163d | 2013-11-25 18:01:36 +0000 | [diff] [blame] | 1323 | shell_surface = get_shell_surface(main_surface); |
| 1324 | if (shell_surface == NULL) |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 1325 | return; |
Philip Withnall | 659163d | 2013-11-25 18:01:36 +0000 | [diff] [blame] | 1326 | |
| 1327 | move_surface_to_workspace(shell, shell_surface, workspace); |
Jonas Ådahl | e9d2250 | 2012-08-29 22:13:01 +0200 | [diff] [blame] | 1328 | } |
| 1329 | |
| 1330 | static const struct workspace_manager_interface workspace_manager_implementation = { |
| 1331 | workspace_manager_move_surface, |
| 1332 | }; |
| 1333 | |
| 1334 | static void |
| 1335 | unbind_resource(struct wl_resource *resource) |
| 1336 | { |
Jason Ekstrand | 651f00e | 2013-06-14 10:07:54 -0500 | [diff] [blame] | 1337 | wl_list_remove(wl_resource_get_link(resource)); |
Jonas Ådahl | e9d2250 | 2012-08-29 22:13:01 +0200 | [diff] [blame] | 1338 | } |
| 1339 | |
| 1340 | static void |
| 1341 | bind_workspace_manager(struct wl_client *client, |
| 1342 | void *data, uint32_t version, uint32_t id) |
| 1343 | { |
| 1344 | struct desktop_shell *shell = data; |
| 1345 | struct wl_resource *resource; |
| 1346 | |
Jason Ekstrand | a85118c | 2013-06-27 20:17:02 -0500 | [diff] [blame] | 1347 | resource = wl_resource_create(client, |
| 1348 | &workspace_manager_interface, 1, id); |
Jonas Ådahl | e9d2250 | 2012-08-29 22:13:01 +0200 | [diff] [blame] | 1349 | |
| 1350 | if (resource == NULL) { |
| 1351 | weston_log("couldn't add workspace manager object"); |
| 1352 | return; |
| 1353 | } |
| 1354 | |
Jason Ekstrand | a85118c | 2013-06-27 20:17:02 -0500 | [diff] [blame] | 1355 | wl_resource_set_implementation(resource, |
| 1356 | &workspace_manager_implementation, |
| 1357 | shell, unbind_resource); |
Jason Ekstrand | 651f00e | 2013-06-14 10:07:54 -0500 | [diff] [blame] | 1358 | wl_list_insert(&shell->workspaces.client_list, |
| 1359 | wl_resource_get_link(resource)); |
Jonas Ådahl | e9d2250 | 2012-08-29 22:13:01 +0200 | [diff] [blame] | 1360 | |
| 1361 | workspace_manager_send_state(resource, |
| 1362 | shell->workspaces.current, |
| 1363 | shell->workspaces.num); |
Jonas Ådahl | 8de6a1d | 2012-08-29 22:13:00 +0200 | [diff] [blame] | 1364 | } |
| 1365 | |
Pekka Paalanen | 56cdea9 | 2011-11-23 16:14:12 +0200 | [diff] [blame] | 1366 | static void |
Rusty Lynch | 1084da5 | 2013-08-15 09:10:08 -0700 | [diff] [blame] | 1367 | touch_move_grab_down(struct weston_touch_grab *grab, uint32_t time, |
| 1368 | int touch_id, wl_fixed_t sx, wl_fixed_t sy) |
| 1369 | { |
| 1370 | } |
| 1371 | |
| 1372 | static void |
| 1373 | touch_move_grab_up(struct weston_touch_grab *grab, uint32_t time, int touch_id) |
| 1374 | { |
Jonas Ådahl | 1c6e63e | 2013-10-25 23:18:04 +0200 | [diff] [blame] | 1375 | struct weston_touch_move_grab *move = |
| 1376 | (struct weston_touch_move_grab *) container_of( |
| 1377 | grab, struct shell_touch_grab, grab); |
Neil Roberts | e14aa4f | 2013-10-03 16:43:07 +0100 | [diff] [blame] | 1378 | |
Kristian Høgsberg | 8e80a31 | 2014-01-17 15:18:10 -0800 | [diff] [blame] | 1379 | if (touch_id == 0) |
| 1380 | move->active = 0; |
| 1381 | |
Jonas Ådahl | 9484b69 | 2013-12-02 22:05:03 +0100 | [diff] [blame] | 1382 | if (grab->touch->num_tp == 0) { |
Jonas Ådahl | 1c6e63e | 2013-10-25 23:18:04 +0200 | [diff] [blame] | 1383 | shell_touch_grab_end(&move->base); |
| 1384 | free(move); |
| 1385 | } |
Rusty Lynch | 1084da5 | 2013-08-15 09:10:08 -0700 | [diff] [blame] | 1386 | } |
| 1387 | |
| 1388 | static void |
| 1389 | touch_move_grab_motion(struct weston_touch_grab *grab, uint32_t time, |
| 1390 | int touch_id, wl_fixed_t sx, wl_fixed_t sy) |
| 1391 | { |
| 1392 | struct weston_touch_move_grab *move = (struct weston_touch_move_grab *) grab; |
| 1393 | struct shell_surface *shsurf = move->base.shsurf; |
| 1394 | struct weston_surface *es; |
| 1395 | int dx = wl_fixed_to_int(grab->touch->grab_x + move->dx); |
| 1396 | int dy = wl_fixed_to_int(grab->touch->grab_y + move->dy); |
| 1397 | |
Kristian Høgsberg | 8e80a31 | 2014-01-17 15:18:10 -0800 | [diff] [blame] | 1398 | if (!shsurf || !move->active) |
Rusty Lynch | 1084da5 | 2013-08-15 09:10:08 -0700 | [diff] [blame] | 1399 | return; |
| 1400 | |
| 1401 | es = shsurf->surface; |
| 1402 | |
Jason Ekstrand | 918f2dd | 2013-12-02 21:01:53 -0600 | [diff] [blame] | 1403 | weston_view_set_position(shsurf->view, dx, dy); |
Rusty Lynch | 1084da5 | 2013-08-15 09:10:08 -0700 | [diff] [blame] | 1404 | |
| 1405 | weston_compositor_schedule_repaint(es->compositor); |
| 1406 | } |
| 1407 | |
Jonas Ådahl | 1ea343e | 2013-10-25 23:18:05 +0200 | [diff] [blame] | 1408 | static void |
Jonas Ådahl | 1679f23 | 2014-04-12 09:39:51 +0200 | [diff] [blame] | 1409 | touch_move_grab_frame(struct weston_touch_grab *grab) |
| 1410 | { |
| 1411 | } |
| 1412 | |
| 1413 | static void |
Jonas Ådahl | 1ea343e | 2013-10-25 23:18:05 +0200 | [diff] [blame] | 1414 | touch_move_grab_cancel(struct weston_touch_grab *grab) |
| 1415 | { |
| 1416 | struct weston_touch_move_grab *move = |
| 1417 | (struct weston_touch_move_grab *) container_of( |
| 1418 | grab, struct shell_touch_grab, grab); |
| 1419 | |
| 1420 | shell_touch_grab_end(&move->base); |
| 1421 | free(move); |
| 1422 | } |
| 1423 | |
Rusty Lynch | 1084da5 | 2013-08-15 09:10:08 -0700 | [diff] [blame] | 1424 | static const struct weston_touch_grab_interface touch_move_grab_interface = { |
| 1425 | touch_move_grab_down, |
| 1426 | touch_move_grab_up, |
| 1427 | touch_move_grab_motion, |
Jonas Ådahl | 1679f23 | 2014-04-12 09:39:51 +0200 | [diff] [blame] | 1428 | touch_move_grab_frame, |
Jonas Ådahl | 1ea343e | 2013-10-25 23:18:05 +0200 | [diff] [blame] | 1429 | touch_move_grab_cancel, |
Rusty Lynch | 1084da5 | 2013-08-15 09:10:08 -0700 | [diff] [blame] | 1430 | }; |
| 1431 | |
| 1432 | static int |
| 1433 | surface_touch_move(struct shell_surface *shsurf, struct weston_seat *seat) |
| 1434 | { |
| 1435 | struct weston_touch_move_grab *move; |
| 1436 | |
| 1437 | if (!shsurf) |
| 1438 | return -1; |
| 1439 | |
Rafael Antognolli | 03b1659 | 2013-12-03 15:35:42 -0200 | [diff] [blame] | 1440 | if (shsurf->state.fullscreen) |
Rusty Lynch | 1084da5 | 2013-08-15 09:10:08 -0700 | [diff] [blame] | 1441 | return 0; |
| 1442 | |
| 1443 | move = malloc(sizeof *move); |
| 1444 | if (!move) |
| 1445 | return -1; |
| 1446 | |
Kristian Høgsberg | 8e80a31 | 2014-01-17 15:18:10 -0800 | [diff] [blame] | 1447 | move->active = 1; |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 1448 | move->dx = wl_fixed_from_double(shsurf->view->geometry.x) - |
Rusty Lynch | 1084da5 | 2013-08-15 09:10:08 -0700 | [diff] [blame] | 1449 | seat->touch->grab_x; |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 1450 | move->dy = wl_fixed_from_double(shsurf->view->geometry.y) - |
Rusty Lynch | 1084da5 | 2013-08-15 09:10:08 -0700 | [diff] [blame] | 1451 | seat->touch->grab_y; |
| 1452 | |
| 1453 | shell_touch_grab_start(&move->base, &touch_move_grab_interface, shsurf, |
| 1454 | seat->touch); |
| 1455 | |
| 1456 | return 0; |
| 1457 | } |
| 1458 | |
| 1459 | static void |
Kristian Høgsberg | 6848c25 | 2013-05-08 22:02:59 -0400 | [diff] [blame] | 1460 | noop_grab_focus(struct weston_pointer_grab *grab) |
Kristian Høgsberg | 9ddb826 | 2012-01-04 21:30:29 -0500 | [diff] [blame] | 1461 | { |
Kristian Høgsberg | 9ddb826 | 2012-01-04 21:30:29 -0500 | [diff] [blame] | 1462 | } |
| 1463 | |
| 1464 | static void |
Giulio Camuffo | 1959ab8 | 2013-11-14 23:42:52 +0100 | [diff] [blame] | 1465 | move_grab_motion(struct weston_pointer_grab *grab, uint32_t time, |
| 1466 | wl_fixed_t x, wl_fixed_t y) |
Kristian Høgsberg | 4cca349 | 2011-01-18 07:53:49 -0500 | [diff] [blame] | 1467 | { |
Kristian Høgsberg | 8334bc1 | 2012-01-03 10:29:47 -0500 | [diff] [blame] | 1468 | struct weston_move_grab *move = (struct weston_move_grab *) grab; |
Kristian Høgsberg | 02bbabb | 2013-05-06 22:15:05 -0400 | [diff] [blame] | 1469 | struct weston_pointer *pointer = grab->pointer; |
Ander Conselvan de Oliveira | fe0444a | 2012-04-04 17:48:05 +0300 | [diff] [blame] | 1470 | struct shell_surface *shsurf = move->base.shsurf; |
Giulio Camuffo | 1959ab8 | 2013-11-14 23:42:52 +0100 | [diff] [blame] | 1471 | int dx, dy; |
| 1472 | |
| 1473 | weston_pointer_move(pointer, x, y); |
| 1474 | dx = wl_fixed_to_int(pointer->x + move->dx); |
| 1475 | dy = wl_fixed_to_int(pointer->y + move->dy); |
Ander Conselvan de Oliveira | fe0444a | 2012-04-04 17:48:05 +0300 | [diff] [blame] | 1476 | |
| 1477 | if (!shsurf) |
| 1478 | return; |
| 1479 | |
Jason Ekstrand | 918f2dd | 2013-12-02 21:01:53 -0600 | [diff] [blame] | 1480 | weston_view_set_position(shsurf->view, dx, dy); |
Kristian Høgsberg | 4cca349 | 2011-01-18 07:53:49 -0500 | [diff] [blame] | 1481 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 1482 | weston_compositor_schedule_repaint(shsurf->surface->compositor); |
Kristian Høgsberg | 4cca349 | 2011-01-18 07:53:49 -0500 | [diff] [blame] | 1483 | } |
| 1484 | |
| 1485 | static void |
Kristian Høgsberg | 02bbabb | 2013-05-06 22:15:05 -0400 | [diff] [blame] | 1486 | move_grab_button(struct weston_pointer_grab *grab, |
Daniel Stone | 4dbadb1 | 2012-05-30 16:31:51 +0100 | [diff] [blame] | 1487 | uint32_t time, uint32_t button, uint32_t state_w) |
Kristian Høgsberg | 4cca349 | 2011-01-18 07:53:49 -0500 | [diff] [blame] | 1488 | { |
Ander Conselvan de Oliveira | fe0444a | 2012-04-04 17:48:05 +0300 | [diff] [blame] | 1489 | struct shell_grab *shell_grab = container_of(grab, struct shell_grab, |
| 1490 | grab); |
Kristian Høgsberg | 02bbabb | 2013-05-06 22:15:05 -0400 | [diff] [blame] | 1491 | struct weston_pointer *pointer = grab->pointer; |
Daniel Stone | 4dbadb1 | 2012-05-30 16:31:51 +0100 | [diff] [blame] | 1492 | enum wl_pointer_button_state state = state_w; |
Kristian Høgsberg | 4cca349 | 2011-01-18 07:53:49 -0500 | [diff] [blame] | 1493 | |
Daniel Stone | 4dbadb1 | 2012-05-30 16:31:51 +0100 | [diff] [blame] | 1494 | if (pointer->button_count == 0 && |
| 1495 | state == WL_POINTER_BUTTON_STATE_RELEASED) { |
Ander Conselvan de Oliveira | b9d2a0f | 2012-06-28 18:08:05 +0300 | [diff] [blame] | 1496 | shell_grab_end(shell_grab); |
Kristian Høgsberg | 9ddb826 | 2012-01-04 21:30:29 -0500 | [diff] [blame] | 1497 | free(grab); |
| 1498 | } |
Kristian Høgsberg | 4cca349 | 2011-01-18 07:53:49 -0500 | [diff] [blame] | 1499 | } |
| 1500 | |
Jonas Ådahl | 1ea343e | 2013-10-25 23:18:05 +0200 | [diff] [blame] | 1501 | static void |
| 1502 | move_grab_cancel(struct weston_pointer_grab *grab) |
| 1503 | { |
| 1504 | struct shell_grab *shell_grab = |
| 1505 | container_of(grab, struct shell_grab, grab); |
| 1506 | |
| 1507 | shell_grab_end(shell_grab); |
| 1508 | free(grab); |
| 1509 | } |
| 1510 | |
Kristian Høgsberg | 02bbabb | 2013-05-06 22:15:05 -0400 | [diff] [blame] | 1511 | static const struct weston_pointer_grab_interface move_grab_interface = { |
Kristian Høgsberg | 9ddb826 | 2012-01-04 21:30:29 -0500 | [diff] [blame] | 1512 | noop_grab_focus, |
Kristian Høgsberg | 4cca349 | 2011-01-18 07:53:49 -0500 | [diff] [blame] | 1513 | move_grab_motion, |
| 1514 | move_grab_button, |
Jonas Ådahl | 1ea343e | 2013-10-25 23:18:05 +0200 | [diff] [blame] | 1515 | move_grab_cancel, |
Kristian Høgsberg | 4cca349 | 2011-01-18 07:53:49 -0500 | [diff] [blame] | 1516 | }; |
| 1517 | |
Kristian Høgsberg | 9e31bff | 2012-08-01 00:08:07 -0400 | [diff] [blame] | 1518 | static int |
Kristian Høgsberg | e314875 | 2013-05-06 23:19:49 -0400 | [diff] [blame] | 1519 | surface_move(struct shell_surface *shsurf, struct weston_seat *seat) |
Kristian Høgsberg | 9e31bff | 2012-08-01 00:08:07 -0400 | [diff] [blame] | 1520 | { |
| 1521 | struct weston_move_grab *move; |
| 1522 | |
| 1523 | if (!shsurf) |
| 1524 | return -1; |
| 1525 | |
Ricardo Vieira | f1c3bd8 | 2014-01-18 16:30:50 +0000 | [diff] [blame] | 1526 | if (shsurf->state.fullscreen || shsurf->state.maximized) |
Kristian Høgsberg | 9e31bff | 2012-08-01 00:08:07 -0400 | [diff] [blame] | 1527 | return 0; |
| 1528 | |
| 1529 | move = malloc(sizeof *move); |
| 1530 | if (!move) |
| 1531 | return -1; |
| 1532 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 1533 | move->dx = wl_fixed_from_double(shsurf->view->geometry.x) - |
Kristian Høgsberg | e314875 | 2013-05-06 23:19:49 -0400 | [diff] [blame] | 1534 | seat->pointer->grab_x; |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 1535 | move->dy = wl_fixed_from_double(shsurf->view->geometry.y) - |
Kristian Høgsberg | e314875 | 2013-05-06 23:19:49 -0400 | [diff] [blame] | 1536 | seat->pointer->grab_y; |
Kristian Høgsberg | 9e31bff | 2012-08-01 00:08:07 -0400 | [diff] [blame] | 1537 | |
| 1538 | shell_grab_start(&move->base, &move_grab_interface, shsurf, |
Kristian Høgsberg | e314875 | 2013-05-06 23:19:49 -0400 | [diff] [blame] | 1539 | seat->pointer, DESKTOP_SHELL_CURSOR_MOVE); |
Kristian Høgsberg | 9e31bff | 2012-08-01 00:08:07 -0400 | [diff] [blame] | 1540 | |
| 1541 | return 0; |
| 1542 | } |
| 1543 | |
| 1544 | static void |
Rafael Antognolli | e2a3455 | 2013-12-03 15:35:45 -0200 | [diff] [blame] | 1545 | common_surface_move(struct wl_resource *resource, |
| 1546 | struct wl_resource *seat_resource, uint32_t serial) |
Kristian Høgsberg | 9e31bff | 2012-08-01 00:08:07 -0400 | [diff] [blame] | 1547 | { |
Jason Ekstrand | 44a3863 | 2013-06-14 10:08:00 -0500 | [diff] [blame] | 1548 | struct weston_seat *seat = wl_resource_get_user_data(seat_resource); |
Jason Ekstrand | 651f00e | 2013-06-14 10:07:54 -0500 | [diff] [blame] | 1549 | struct shell_surface *shsurf = wl_resource_get_user_data(resource); |
Giulio Camuffo | 61da3fc | 2013-04-25 13:57:45 +0300 | [diff] [blame] | 1550 | struct weston_surface *surface; |
Kristian Høgsberg | 9e31bff | 2012-08-01 00:08:07 -0400 | [diff] [blame] | 1551 | |
Kristian Høgsberg | d0b40ed | 2014-04-29 14:47:46 -0700 | [diff] [blame] | 1552 | if (shsurf->grabbed) |
| 1553 | return; |
| 1554 | |
Kristian Høgsberg | e1b655d | 2013-08-28 23:16:20 -0700 | [diff] [blame] | 1555 | if (seat->pointer && |
Kristian Høgsberg | 70f2901 | 2014-01-09 15:43:17 -0800 | [diff] [blame] | 1556 | seat->pointer->focus && |
Kristian Høgsberg | e1b655d | 2013-08-28 23:16:20 -0700 | [diff] [blame] | 1557 | seat->pointer->button_count > 0 && |
| 1558 | seat->pointer->grab_serial == serial) { |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 1559 | surface = weston_surface_get_main_surface(seat->pointer->focus->surface); |
U. Artie Eoff | cf5737a | 2014-01-17 10:08:25 -0800 | [diff] [blame] | 1560 | if ((surface == shsurf->surface) && |
Rusty Lynch | 1084da5 | 2013-08-15 09:10:08 -0700 | [diff] [blame] | 1561 | (surface_move(shsurf, seat) < 0)) |
| 1562 | wl_resource_post_no_memory(resource); |
Kristian Høgsberg | e1b655d | 2013-08-28 23:16:20 -0700 | [diff] [blame] | 1563 | } else if (seat->touch && |
Kristian Høgsberg | 70f2901 | 2014-01-09 15:43:17 -0800 | [diff] [blame] | 1564 | seat->touch->focus && |
Kristian Høgsberg | e1b655d | 2013-08-28 23:16:20 -0700 | [diff] [blame] | 1565 | seat->touch->grab_serial == serial) { |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 1566 | surface = weston_surface_get_main_surface(seat->touch->focus->surface); |
U. Artie Eoff | cf5737a | 2014-01-17 10:08:25 -0800 | [diff] [blame] | 1567 | if ((surface == shsurf->surface) && |
Rusty Lynch | 1084da5 | 2013-08-15 09:10:08 -0700 | [diff] [blame] | 1568 | (surface_touch_move(shsurf, seat) < 0)) |
| 1569 | wl_resource_post_no_memory(resource); |
| 1570 | } |
Kristian Høgsberg | 9e31bff | 2012-08-01 00:08:07 -0400 | [diff] [blame] | 1571 | } |
| 1572 | |
Rafael Antognolli | e2a3455 | 2013-12-03 15:35:45 -0200 | [diff] [blame] | 1573 | static void |
| 1574 | shell_surface_move(struct wl_client *client, struct wl_resource *resource, |
| 1575 | struct wl_resource *seat_resource, uint32_t serial) |
| 1576 | { |
| 1577 | common_surface_move(resource, seat_resource, serial); |
| 1578 | } |
| 1579 | |
Kristian Høgsberg | 9e31bff | 2012-08-01 00:08:07 -0400 | [diff] [blame] | 1580 | struct weston_resize_grab { |
| 1581 | struct shell_grab base; |
| 1582 | uint32_t edges; |
| 1583 | int32_t width, height; |
| 1584 | }; |
| 1585 | |
| 1586 | static void |
Giulio Camuffo | 1959ab8 | 2013-11-14 23:42:52 +0100 | [diff] [blame] | 1587 | resize_grab_motion(struct weston_pointer_grab *grab, uint32_t time, |
| 1588 | wl_fixed_t x, wl_fixed_t y) |
Kristian Høgsberg | 9e31bff | 2012-08-01 00:08:07 -0400 | [diff] [blame] | 1589 | { |
| 1590 | struct weston_resize_grab *resize = (struct weston_resize_grab *) grab; |
Kristian Høgsberg | 02bbabb | 2013-05-06 22:15:05 -0400 | [diff] [blame] | 1591 | struct weston_pointer *pointer = grab->pointer; |
Kristian Høgsberg | 9e31bff | 2012-08-01 00:08:07 -0400 | [diff] [blame] | 1592 | struct shell_surface *shsurf = resize->base.shsurf; |
| 1593 | int32_t width, height; |
| 1594 | wl_fixed_t from_x, from_y; |
| 1595 | wl_fixed_t to_x, to_y; |
| 1596 | |
Giulio Camuffo | 1959ab8 | 2013-11-14 23:42:52 +0100 | [diff] [blame] | 1597 | weston_pointer_move(pointer, x, y); |
| 1598 | |
Ander Conselvan de Oliveira | 9c376b5 | 2014-04-29 17:54:03 +0300 | [diff] [blame] | 1599 | if (!shsurf || !shsurf->resource) |
Kristian Høgsberg | 9e31bff | 2012-08-01 00:08:07 -0400 | [diff] [blame] | 1600 | return; |
| 1601 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 1602 | weston_view_from_global_fixed(shsurf->view, |
| 1603 | pointer->grab_x, pointer->grab_y, |
| 1604 | &from_x, &from_y); |
| 1605 | weston_view_from_global_fixed(shsurf->view, |
| 1606 | pointer->x, pointer->y, &to_x, &to_y); |
Kristian Høgsberg | 9e31bff | 2012-08-01 00:08:07 -0400 | [diff] [blame] | 1607 | |
| 1608 | width = resize->width; |
| 1609 | if (resize->edges & WL_SHELL_SURFACE_RESIZE_LEFT) { |
| 1610 | width += wl_fixed_to_int(from_x - to_x); |
| 1611 | } else if (resize->edges & WL_SHELL_SURFACE_RESIZE_RIGHT) { |
| 1612 | width += wl_fixed_to_int(to_x - from_x); |
| 1613 | } |
| 1614 | |
| 1615 | height = resize->height; |
| 1616 | if (resize->edges & WL_SHELL_SURFACE_RESIZE_TOP) { |
| 1617 | height += wl_fixed_to_int(from_y - to_y); |
| 1618 | } else if (resize->edges & WL_SHELL_SURFACE_RESIZE_BOTTOM) { |
| 1619 | height += wl_fixed_to_int(to_y - from_y); |
| 1620 | } |
| 1621 | |
| 1622 | shsurf->client->send_configure(shsurf->surface, |
| 1623 | resize->edges, width, height); |
| 1624 | } |
| 1625 | |
| 1626 | static void |
| 1627 | send_configure(struct weston_surface *surface, |
| 1628 | uint32_t edges, int32_t width, int32_t height) |
| 1629 | { |
| 1630 | struct shell_surface *shsurf = get_shell_surface(surface); |
| 1631 | |
U. Artie Eoff | cf5737a | 2014-01-17 10:08:25 -0800 | [diff] [blame] | 1632 | assert(shsurf); |
| 1633 | |
Jason Ekstrand | 651f00e | 2013-06-14 10:07:54 -0500 | [diff] [blame] | 1634 | wl_shell_surface_send_configure(shsurf->resource, |
Kristian Høgsberg | 9e31bff | 2012-08-01 00:08:07 -0400 | [diff] [blame] | 1635 | edges, width, height); |
| 1636 | } |
| 1637 | |
| 1638 | static const struct weston_shell_client shell_client = { |
| 1639 | send_configure |
| 1640 | }; |
| 1641 | |
| 1642 | static void |
Kristian Høgsberg | 02bbabb | 2013-05-06 22:15:05 -0400 | [diff] [blame] | 1643 | resize_grab_button(struct weston_pointer_grab *grab, |
Kristian Høgsberg | 9e31bff | 2012-08-01 00:08:07 -0400 | [diff] [blame] | 1644 | uint32_t time, uint32_t button, uint32_t state_w) |
| 1645 | { |
| 1646 | struct weston_resize_grab *resize = (struct weston_resize_grab *) grab; |
Kristian Høgsberg | 02bbabb | 2013-05-06 22:15:05 -0400 | [diff] [blame] | 1647 | struct weston_pointer *pointer = grab->pointer; |
Kristian Høgsberg | 9e31bff | 2012-08-01 00:08:07 -0400 | [diff] [blame] | 1648 | enum wl_pointer_button_state state = state_w; |
| 1649 | |
| 1650 | if (pointer->button_count == 0 && |
| 1651 | state == WL_POINTER_BUTTON_STATE_RELEASED) { |
| 1652 | shell_grab_end(&resize->base); |
| 1653 | free(grab); |
| 1654 | } |
| 1655 | } |
| 1656 | |
Jonas Ådahl | 1ea343e | 2013-10-25 23:18:05 +0200 | [diff] [blame] | 1657 | static void |
| 1658 | resize_grab_cancel(struct weston_pointer_grab *grab) |
| 1659 | { |
| 1660 | struct weston_resize_grab *resize = (struct weston_resize_grab *) grab; |
| 1661 | |
| 1662 | shell_grab_end(&resize->base); |
| 1663 | free(grab); |
| 1664 | } |
| 1665 | |
Kristian Høgsberg | 02bbabb | 2013-05-06 22:15:05 -0400 | [diff] [blame] | 1666 | static const struct weston_pointer_grab_interface resize_grab_interface = { |
Kristian Høgsberg | 9e31bff | 2012-08-01 00:08:07 -0400 | [diff] [blame] | 1667 | noop_grab_focus, |
| 1668 | resize_grab_motion, |
| 1669 | resize_grab_button, |
Jonas Ådahl | 1ea343e | 2013-10-25 23:18:05 +0200 | [diff] [blame] | 1670 | resize_grab_cancel, |
Kristian Høgsberg | 9e31bff | 2012-08-01 00:08:07 -0400 | [diff] [blame] | 1671 | }; |
| 1672 | |
Giulio Camuffo | b836664 | 2013-04-25 13:57:46 +0300 | [diff] [blame] | 1673 | /* |
| 1674 | * Returns the bounding box of a surface and all its sub-surfaces, |
| 1675 | * in the surface coordinates system. */ |
| 1676 | static void |
| 1677 | surface_subsurfaces_boundingbox(struct weston_surface *surface, int32_t *x, |
| 1678 | int32_t *y, int32_t *w, int32_t *h) { |
| 1679 | pixman_region32_t region; |
| 1680 | pixman_box32_t *box; |
| 1681 | struct weston_subsurface *subsurface; |
| 1682 | |
| 1683 | pixman_region32_init_rect(®ion, 0, 0, |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 1684 | surface->width, |
| 1685 | surface->height); |
Giulio Camuffo | b836664 | 2013-04-25 13:57:46 +0300 | [diff] [blame] | 1686 | |
| 1687 | wl_list_for_each(subsurface, &surface->subsurface_list, parent_link) { |
| 1688 | pixman_region32_union_rect(®ion, ®ion, |
| 1689 | subsurface->position.x, |
| 1690 | subsurface->position.y, |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 1691 | subsurface->surface->width, |
| 1692 | subsurface->surface->height); |
Giulio Camuffo | b836664 | 2013-04-25 13:57:46 +0300 | [diff] [blame] | 1693 | } |
| 1694 | |
| 1695 | box = pixman_region32_extents(®ion); |
| 1696 | if (x) |
| 1697 | *x = box->x1; |
| 1698 | if (y) |
| 1699 | *y = box->y1; |
| 1700 | if (w) |
| 1701 | *w = box->x2 - box->x1; |
| 1702 | if (h) |
| 1703 | *h = box->y2 - box->y1; |
| 1704 | |
| 1705 | pixman_region32_fini(®ion); |
| 1706 | } |
| 1707 | |
Kristian Høgsberg | 9e31bff | 2012-08-01 00:08:07 -0400 | [diff] [blame] | 1708 | static int |
| 1709 | surface_resize(struct shell_surface *shsurf, |
Kristian Høgsberg | e314875 | 2013-05-06 23:19:49 -0400 | [diff] [blame] | 1710 | struct weston_seat *seat, uint32_t edges) |
Kristian Høgsberg | 9e31bff | 2012-08-01 00:08:07 -0400 | [diff] [blame] | 1711 | { |
| 1712 | struct weston_resize_grab *resize; |
| 1713 | |
Rafael Antognolli | 03b1659 | 2013-12-03 15:35:42 -0200 | [diff] [blame] | 1714 | if (shsurf->state.fullscreen || shsurf->state.maximized) |
Kristian Høgsberg | 9e31bff | 2012-08-01 00:08:07 -0400 | [diff] [blame] | 1715 | return 0; |
| 1716 | |
| 1717 | if (edges == 0 || edges > 15 || |
| 1718 | (edges & 3) == 3 || (edges & 12) == 12) |
| 1719 | return 0; |
| 1720 | |
| 1721 | resize = malloc(sizeof *resize); |
| 1722 | if (!resize) |
| 1723 | return -1; |
| 1724 | |
| 1725 | resize->edges = edges; |
Giulio Camuffo | b836664 | 2013-04-25 13:57:46 +0300 | [diff] [blame] | 1726 | surface_subsurfaces_boundingbox(shsurf->surface, NULL, NULL, |
| 1727 | &resize->width, &resize->height); |
Kristian Høgsberg | 9e31bff | 2012-08-01 00:08:07 -0400 | [diff] [blame] | 1728 | |
Kristian Høgsberg | 44cd196 | 2014-02-05 21:36:04 -0800 | [diff] [blame] | 1729 | shsurf->resize_edges = edges; |
Kristian Høgsberg | 9e31bff | 2012-08-01 00:08:07 -0400 | [diff] [blame] | 1730 | shell_grab_start(&resize->base, &resize_grab_interface, shsurf, |
Kristian Høgsberg | e314875 | 2013-05-06 23:19:49 -0400 | [diff] [blame] | 1731 | seat->pointer, edges); |
Kristian Høgsberg | 9e31bff | 2012-08-01 00:08:07 -0400 | [diff] [blame] | 1732 | |
| 1733 | return 0; |
| 1734 | } |
| 1735 | |
| 1736 | static void |
Rafael Antognolli | e2a3455 | 2013-12-03 15:35:45 -0200 | [diff] [blame] | 1737 | common_surface_resize(struct wl_resource *resource, |
| 1738 | struct wl_resource *seat_resource, uint32_t serial, |
| 1739 | uint32_t edges) |
Kristian Høgsberg | 9e31bff | 2012-08-01 00:08:07 -0400 | [diff] [blame] | 1740 | { |
Jason Ekstrand | 44a3863 | 2013-06-14 10:08:00 -0500 | [diff] [blame] | 1741 | struct weston_seat *seat = wl_resource_get_user_data(seat_resource); |
Jason Ekstrand | 651f00e | 2013-06-14 10:07:54 -0500 | [diff] [blame] | 1742 | struct shell_surface *shsurf = wl_resource_get_user_data(resource); |
Giulio Camuffo | 61da3fc | 2013-04-25 13:57:45 +0300 | [diff] [blame] | 1743 | struct weston_surface *surface; |
Kristian Høgsberg | 9e31bff | 2012-08-01 00:08:07 -0400 | [diff] [blame] | 1744 | |
Rafael Antognolli | 03b1659 | 2013-12-03 15:35:42 -0200 | [diff] [blame] | 1745 | if (shsurf->state.fullscreen) |
Kristian Høgsberg | 9e31bff | 2012-08-01 00:08:07 -0400 | [diff] [blame] | 1746 | return; |
| 1747 | |
Kristian Høgsberg | 7b83ae4 | 2014-04-29 14:50:25 -0700 | [diff] [blame] | 1748 | if (shsurf->grabbed) |
| 1749 | return; |
| 1750 | |
Kristian Høgsberg | e314875 | 2013-05-06 23:19:49 -0400 | [diff] [blame] | 1751 | if (seat->pointer->button_count == 0 || |
| 1752 | seat->pointer->grab_serial != serial || |
Kristian Høgsberg | 70f2901 | 2014-01-09 15:43:17 -0800 | [diff] [blame] | 1753 | seat->pointer->focus == NULL) |
| 1754 | return; |
| 1755 | |
| 1756 | surface = weston_surface_get_main_surface(seat->pointer->focus->surface); |
| 1757 | if (surface != shsurf->surface) |
Kristian Høgsberg | 9e31bff | 2012-08-01 00:08:07 -0400 | [diff] [blame] | 1758 | return; |
| 1759 | |
Kristian Høgsberg | e314875 | 2013-05-06 23:19:49 -0400 | [diff] [blame] | 1760 | if (surface_resize(shsurf, seat, edges) < 0) |
Kristian Høgsberg | 9e31bff | 2012-08-01 00:08:07 -0400 | [diff] [blame] | 1761 | wl_resource_post_no_memory(resource); |
| 1762 | } |
| 1763 | |
Scott Moreau | c3e54eb | 2012-04-17 19:06:20 -0600 | [diff] [blame] | 1764 | static void |
Rafael Antognolli | e2a3455 | 2013-12-03 15:35:45 -0200 | [diff] [blame] | 1765 | shell_surface_resize(struct wl_client *client, struct wl_resource *resource, |
| 1766 | struct wl_resource *seat_resource, uint32_t serial, |
| 1767 | uint32_t edges) |
| 1768 | { |
| 1769 | common_surface_resize(resource, seat_resource, serial, edges); |
| 1770 | } |
| 1771 | |
| 1772 | static void |
Kristian Høgsberg | 6848c25 | 2013-05-08 22:02:59 -0400 | [diff] [blame] | 1773 | busy_cursor_grab_focus(struct weston_pointer_grab *base) |
Scott Moreau | c3e54eb | 2012-04-17 19:06:20 -0600 | [diff] [blame] | 1774 | { |
Kristian Høgsberg | d56bd90 | 2012-06-05 09:58:51 -0400 | [diff] [blame] | 1775 | struct shell_grab *grab = (struct shell_grab *) base; |
Kristian Høgsberg | 6848c25 | 2013-05-08 22:02:59 -0400 | [diff] [blame] | 1776 | struct weston_pointer *pointer = base->pointer; |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 1777 | struct weston_view *view; |
Kristian Høgsberg | 6848c25 | 2013-05-08 22:02:59 -0400 | [diff] [blame] | 1778 | wl_fixed_t sx, sy; |
| 1779 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 1780 | view = weston_compositor_pick_view(pointer->seat->compositor, |
| 1781 | pointer->x, pointer->y, |
| 1782 | &sx, &sy); |
Scott Moreau | c3e54eb | 2012-04-17 19:06:20 -0600 | [diff] [blame] | 1783 | |
Kristian Høgsberg | 2bff94e | 2014-02-11 12:22:51 -0800 | [diff] [blame] | 1784 | if (!grab->shsurf || grab->shsurf->surface != view->surface) { |
| 1785 | shell_grab_end(grab); |
| 1786 | free(grab); |
| 1787 | } |
Scott Moreau | c3e54eb | 2012-04-17 19:06:20 -0600 | [diff] [blame] | 1788 | } |
| 1789 | |
| 1790 | static void |
Giulio Camuffo | 1959ab8 | 2013-11-14 23:42:52 +0100 | [diff] [blame] | 1791 | busy_cursor_grab_motion(struct weston_pointer_grab *grab, uint32_t time, |
| 1792 | wl_fixed_t x, wl_fixed_t y) |
Scott Moreau | c3e54eb | 2012-04-17 19:06:20 -0600 | [diff] [blame] | 1793 | { |
Giulio Camuffo | 1959ab8 | 2013-11-14 23:42:52 +0100 | [diff] [blame] | 1794 | weston_pointer_move(grab->pointer, x, y); |
Kristian Høgsberg | d56bd90 | 2012-06-05 09:58:51 -0400 | [diff] [blame] | 1795 | } |
Scott Moreau | c3e54eb | 2012-04-17 19:06:20 -0600 | [diff] [blame] | 1796 | |
Kristian Høgsberg | d56bd90 | 2012-06-05 09:58:51 -0400 | [diff] [blame] | 1797 | static void |
Kristian Høgsberg | 02bbabb | 2013-05-06 22:15:05 -0400 | [diff] [blame] | 1798 | busy_cursor_grab_button(struct weston_pointer_grab *base, |
Kristian Høgsberg | d56bd90 | 2012-06-05 09:58:51 -0400 | [diff] [blame] | 1799 | uint32_t time, uint32_t button, uint32_t state) |
| 1800 | { |
Kristian Høgsberg | bbe9839 | 2012-08-01 00:20:21 -0400 | [diff] [blame] | 1801 | struct shell_grab *grab = (struct shell_grab *) base; |
Kristian Høgsberg | e122b7b | 2013-05-08 16:47:00 -0400 | [diff] [blame] | 1802 | struct shell_surface *shsurf = grab->shsurf; |
Kristian Høgsberg | e314875 | 2013-05-06 23:19:49 -0400 | [diff] [blame] | 1803 | struct weston_seat *seat = grab->grab.pointer->seat; |
Kristian Høgsberg | bbe9839 | 2012-08-01 00:20:21 -0400 | [diff] [blame] | 1804 | |
Kristian Høgsberg | bbe9839 | 2012-08-01 00:20:21 -0400 | [diff] [blame] | 1805 | if (shsurf && button == BTN_LEFT && state) { |
| 1806 | activate(shsurf->shell, shsurf->surface, seat); |
| 1807 | surface_move(shsurf, seat); |
Kristian Høgsberg | 0c36903 | 2013-02-14 21:31:44 -0500 | [diff] [blame] | 1808 | } else if (shsurf && button == BTN_RIGHT && state) { |
| 1809 | activate(shsurf->shell, shsurf->surface, seat); |
Kristian Høgsberg | e314875 | 2013-05-06 23:19:49 -0400 | [diff] [blame] | 1810 | surface_rotate(shsurf, seat); |
Kristian Høgsberg | bbe9839 | 2012-08-01 00:20:21 -0400 | [diff] [blame] | 1811 | } |
Kristian Høgsberg | d56bd90 | 2012-06-05 09:58:51 -0400 | [diff] [blame] | 1812 | } |
| 1813 | |
Jonas Ådahl | 1ea343e | 2013-10-25 23:18:05 +0200 | [diff] [blame] | 1814 | static void |
| 1815 | busy_cursor_grab_cancel(struct weston_pointer_grab *base) |
| 1816 | { |
| 1817 | struct shell_grab *grab = (struct shell_grab *) base; |
| 1818 | |
| 1819 | shell_grab_end(grab); |
| 1820 | free(grab); |
| 1821 | } |
| 1822 | |
Kristian Høgsberg | 02bbabb | 2013-05-06 22:15:05 -0400 | [diff] [blame] | 1823 | static const struct weston_pointer_grab_interface busy_cursor_grab_interface = { |
Kristian Høgsberg | d56bd90 | 2012-06-05 09:58:51 -0400 | [diff] [blame] | 1824 | busy_cursor_grab_focus, |
| 1825 | busy_cursor_grab_motion, |
| 1826 | busy_cursor_grab_button, |
Jonas Ådahl | 1ea343e | 2013-10-25 23:18:05 +0200 | [diff] [blame] | 1827 | busy_cursor_grab_cancel, |
Kristian Høgsberg | d56bd90 | 2012-06-05 09:58:51 -0400 | [diff] [blame] | 1828 | }; |
| 1829 | |
| 1830 | static void |
Kristian Høgsberg | 02bbabb | 2013-05-06 22:15:05 -0400 | [diff] [blame] | 1831 | set_busy_cursor(struct shell_surface *shsurf, struct weston_pointer *pointer) |
Kristian Høgsberg | d56bd90 | 2012-06-05 09:58:51 -0400 | [diff] [blame] | 1832 | { |
| 1833 | struct shell_grab *grab; |
Kristian Høgsberg | d56bd90 | 2012-06-05 09:58:51 -0400 | [diff] [blame] | 1834 | |
Kristian Høgsberg | 2bff94e | 2014-02-11 12:22:51 -0800 | [diff] [blame] | 1835 | if (pointer->grab->interface == &busy_cursor_grab_interface) |
| 1836 | return; |
| 1837 | |
Kristian Høgsberg | d56bd90 | 2012-06-05 09:58:51 -0400 | [diff] [blame] | 1838 | grab = malloc(sizeof *grab); |
| 1839 | if (!grab) |
Scott Moreau | c3e54eb | 2012-04-17 19:06:20 -0600 | [diff] [blame] | 1840 | return; |
| 1841 | |
Ander Conselvan de Oliveira | b9d2a0f | 2012-06-28 18:08:05 +0300 | [diff] [blame] | 1842 | shell_grab_start(grab, &busy_cursor_grab_interface, shsurf, pointer, |
| 1843 | DESKTOP_SHELL_CURSOR_BUSY); |
Ander Conselvan de Oliveira | e5a1aee | 2014-04-09 17:39:39 +0300 | [diff] [blame] | 1844 | /* Mark the shsurf as ungrabbed so that button binding is able |
| 1845 | * to move it. */ |
| 1846 | shsurf->grabbed = 0; |
Kristian Høgsberg | d56bd90 | 2012-06-05 09:58:51 -0400 | [diff] [blame] | 1847 | } |
Scott Moreau | c3e54eb | 2012-04-17 19:06:20 -0600 | [diff] [blame] | 1848 | |
Kristian Høgsberg | d56bd90 | 2012-06-05 09:58:51 -0400 | [diff] [blame] | 1849 | static void |
Kristian Høgsberg | 2bff94e | 2014-02-11 12:22:51 -0800 | [diff] [blame] | 1850 | end_busy_cursor(struct weston_compositor *compositor, struct wl_client *client) |
Kristian Høgsberg | d56bd90 | 2012-06-05 09:58:51 -0400 | [diff] [blame] | 1851 | { |
Kristian Høgsberg | 2bff94e | 2014-02-11 12:22:51 -0800 | [diff] [blame] | 1852 | struct shell_grab *grab; |
| 1853 | struct weston_seat *seat; |
Kristian Høgsberg | d56bd90 | 2012-06-05 09:58:51 -0400 | [diff] [blame] | 1854 | |
Kristian Høgsberg | 2bff94e | 2014-02-11 12:22:51 -0800 | [diff] [blame] | 1855 | wl_list_for_each(seat, &compositor->seat_list, link) { |
| 1856 | if (seat->pointer == NULL) |
| 1857 | continue; |
| 1858 | |
| 1859 | grab = (struct shell_grab *) seat->pointer->grab; |
| 1860 | if (grab->grab.interface == &busy_cursor_grab_interface && |
| 1861 | wl_resource_get_client(grab->shsurf->resource) == client) { |
| 1862 | shell_grab_end(grab); |
| 1863 | free(grab); |
| 1864 | } |
Scott Moreau | c3e54eb | 2012-04-17 19:06:20 -0600 | [diff] [blame] | 1865 | } |
Scott Moreau | c3e54eb | 2012-04-17 19:06:20 -0600 | [diff] [blame] | 1866 | } |
| 1867 | |
Scott Moreau | 9521d5e | 2012-04-19 13:06:17 -0600 | [diff] [blame] | 1868 | static void |
Kristian Høgsberg | 2bff94e | 2014-02-11 12:22:51 -0800 | [diff] [blame] | 1869 | handle_shell_client_destroy(struct wl_listener *listener, void *data); |
| 1870 | |
| 1871 | static int |
| 1872 | xdg_ping_timeout_handler(void *data) |
| 1873 | { |
| 1874 | struct shell_client *sc = data; |
| 1875 | struct weston_seat *seat; |
| 1876 | struct shell_surface *shsurf; |
| 1877 | |
| 1878 | /* Client is not responding */ |
| 1879 | sc->unresponsive = 1; |
Kristian Høgsberg | 2bff94e | 2014-02-11 12:22:51 -0800 | [diff] [blame] | 1880 | wl_list_for_each(seat, &sc->shell->compositor->seat_list, link) { |
| 1881 | if (seat->pointer == NULL || seat->pointer->focus == NULL) |
| 1882 | continue; |
| 1883 | if (seat->pointer->focus->surface->resource == NULL) |
| 1884 | continue; |
| 1885 | |
| 1886 | shsurf = get_shell_surface(seat->pointer->focus->surface); |
| 1887 | if (shsurf && |
| 1888 | wl_resource_get_client(shsurf->resource) == sc->client) |
| 1889 | set_busy_cursor(shsurf, seat->pointer); |
| 1890 | } |
| 1891 | |
| 1892 | return 1; |
| 1893 | } |
| 1894 | |
| 1895 | static void |
| 1896 | handle_xdg_ping(struct shell_surface *shsurf, uint32_t serial) |
| 1897 | { |
| 1898 | struct weston_compositor *compositor = shsurf->shell->compositor; |
Jason Ekstrand | 9e9512f | 2014-04-16 21:12:10 -0500 | [diff] [blame] | 1899 | struct shell_client *sc = shsurf->owner; |
Kristian Høgsberg | 2bff94e | 2014-02-11 12:22:51 -0800 | [diff] [blame] | 1900 | struct wl_event_loop *loop; |
Kristian Høgsberg | dd62aba | 2014-02-12 09:56:19 -0800 | [diff] [blame] | 1901 | static const int ping_timeout = 200; |
Kristian Høgsberg | 2bff94e | 2014-02-11 12:22:51 -0800 | [diff] [blame] | 1902 | |
Kristian Høgsberg | 2bff94e | 2014-02-11 12:22:51 -0800 | [diff] [blame] | 1903 | if (sc->unresponsive) { |
| 1904 | xdg_ping_timeout_handler(sc); |
| 1905 | return; |
| 1906 | } |
| 1907 | |
| 1908 | sc->ping_serial = serial; |
| 1909 | loop = wl_display_get_event_loop(compositor->wl_display); |
| 1910 | if (sc->ping_timer == NULL) |
| 1911 | sc->ping_timer = |
| 1912 | wl_event_loop_add_timer(loop, |
| 1913 | xdg_ping_timeout_handler, sc); |
| 1914 | if (sc->ping_timer == NULL) |
| 1915 | return; |
| 1916 | |
| 1917 | wl_event_source_timer_update(sc->ping_timer, ping_timeout); |
| 1918 | |
Kristian Høgsberg | dd62aba | 2014-02-12 09:56:19 -0800 | [diff] [blame] | 1919 | if (shell_surface_is_xdg_surface(shsurf) || |
| 1920 | shell_surface_is_xdg_popup(shsurf)) |
| 1921 | xdg_shell_send_ping(sc->resource, serial); |
| 1922 | else if (shell_surface_is_wl_shell_surface(shsurf)) |
| 1923 | wl_shell_surface_send_ping(shsurf->resource, serial); |
Kristian Høgsberg | 2bff94e | 2014-02-11 12:22:51 -0800 | [diff] [blame] | 1924 | } |
| 1925 | |
Scott Moreau | ff1db4a | 2012-04-17 19:06:18 -0600 | [diff] [blame] | 1926 | static void |
| 1927 | ping_handler(struct weston_surface *surface, uint32_t serial) |
| 1928 | { |
Kristian Høgsberg | b71302e | 2012-05-10 12:28:35 -0400 | [diff] [blame] | 1929 | struct shell_surface *shsurf = get_shell_surface(surface); |
Scott Moreau | ff1db4a | 2012-04-17 19:06:18 -0600 | [diff] [blame] | 1930 | |
| 1931 | if (!shsurf) |
| 1932 | return; |
Jason Ekstrand | 651f00e | 2013-06-14 10:07:54 -0500 | [diff] [blame] | 1933 | if (!shsurf->resource) |
Kristian Høgsberg | ca535c1 | 2012-04-21 23:20:07 -0400 | [diff] [blame] | 1934 | return; |
Ander Conselvan de Oliveira | eac9a46 | 2012-07-16 14:15:48 +0300 | [diff] [blame] | 1935 | if (shsurf->surface == shsurf->shell->grab_surface) |
| 1936 | return; |
| 1937 | |
Kristian Høgsberg | dd62aba | 2014-02-12 09:56:19 -0800 | [diff] [blame] | 1938 | handle_xdg_ping(shsurf, serial); |
Scott Moreau | ff1db4a | 2012-04-17 19:06:18 -0600 | [diff] [blame] | 1939 | } |
| 1940 | |
| 1941 | static void |
Kristian Høgsberg | d56bd90 | 2012-06-05 09:58:51 -0400 | [diff] [blame] | 1942 | handle_pointer_focus(struct wl_listener *listener, void *data) |
| 1943 | { |
Kristian Høgsberg | 02bbabb | 2013-05-06 22:15:05 -0400 | [diff] [blame] | 1944 | struct weston_pointer *pointer = data; |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 1945 | struct weston_view *view = pointer->focus; |
Kristian Høgsberg | d56bd90 | 2012-06-05 09:58:51 -0400 | [diff] [blame] | 1946 | struct weston_compositor *compositor; |
Kristian Høgsberg | d56bd90 | 2012-06-05 09:58:51 -0400 | [diff] [blame] | 1947 | uint32_t serial; |
| 1948 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 1949 | if (!view) |
Kristian Høgsberg | d56bd90 | 2012-06-05 09:58:51 -0400 | [diff] [blame] | 1950 | return; |
| 1951 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 1952 | compositor = view->surface->compositor; |
Kristian Høgsberg | e11ef64 | 2014-02-11 16:35:22 -0800 | [diff] [blame] | 1953 | serial = wl_display_next_serial(compositor->wl_display); |
| 1954 | ping_handler(view->surface, serial); |
Kristian Høgsberg | d56bd90 | 2012-06-05 09:58:51 -0400 | [diff] [blame] | 1955 | } |
| 1956 | |
| 1957 | static void |
Kristian Høgsberg | f4d2f23 | 2012-08-10 10:05:39 -0400 | [diff] [blame] | 1958 | create_pointer_focus_listener(struct weston_seat *seat) |
| 1959 | { |
| 1960 | struct wl_listener *listener; |
| 1961 | |
Kristian Høgsberg | e314875 | 2013-05-06 23:19:49 -0400 | [diff] [blame] | 1962 | if (!seat->pointer) |
Kristian Høgsberg | f4d2f23 | 2012-08-10 10:05:39 -0400 | [diff] [blame] | 1963 | return; |
| 1964 | |
| 1965 | listener = malloc(sizeof *listener); |
| 1966 | listener->notify = handle_pointer_focus; |
Kristian Høgsberg | e314875 | 2013-05-06 23:19:49 -0400 | [diff] [blame] | 1967 | wl_signal_add(&seat->pointer->focus_signal, listener); |
Kristian Høgsberg | f4d2f23 | 2012-08-10 10:05:39 -0400 | [diff] [blame] | 1968 | } |
| 1969 | |
| 1970 | static void |
Jasper St. Pierre | faf27a9 | 2013-12-09 17:36:28 -0500 | [diff] [blame] | 1971 | shell_surface_lose_keyboard_focus(struct shell_surface *shsurf) |
| 1972 | { |
| 1973 | if (--shsurf->focus_count == 0) |
| 1974 | if (shell_surface_is_xdg_surface(shsurf)) |
Jasper St. Pierre | b223a72 | 2014-02-08 18:11:53 -0500 | [diff] [blame] | 1975 | xdg_surface_send_deactivated(shsurf->resource); |
Jasper St. Pierre | faf27a9 | 2013-12-09 17:36:28 -0500 | [diff] [blame] | 1976 | } |
| 1977 | |
| 1978 | static void |
| 1979 | shell_surface_gain_keyboard_focus(struct shell_surface *shsurf) |
| 1980 | { |
| 1981 | if (shsurf->focus_count++ == 0) |
| 1982 | if (shell_surface_is_xdg_surface(shsurf)) |
Jasper St. Pierre | b223a72 | 2014-02-08 18:11:53 -0500 | [diff] [blame] | 1983 | xdg_surface_send_activated(shsurf->resource); |
Jasper St. Pierre | faf27a9 | 2013-12-09 17:36:28 -0500 | [diff] [blame] | 1984 | } |
| 1985 | |
| 1986 | static void |
| 1987 | handle_keyboard_focus(struct wl_listener *listener, void *data) |
| 1988 | { |
| 1989 | struct weston_keyboard *keyboard = data; |
| 1990 | struct shell_seat *seat = get_shell_seat(keyboard->seat); |
| 1991 | |
| 1992 | if (seat->focused_surface) { |
| 1993 | struct shell_surface *shsurf = get_shell_surface(seat->focused_surface); |
| 1994 | if (shsurf) |
| 1995 | shell_surface_lose_keyboard_focus(shsurf); |
| 1996 | } |
| 1997 | |
| 1998 | seat->focused_surface = keyboard->focus; |
| 1999 | |
| 2000 | if (seat->focused_surface) { |
| 2001 | struct shell_surface *shsurf = get_shell_surface(seat->focused_surface); |
| 2002 | if (shsurf) |
| 2003 | shell_surface_gain_keyboard_focus(shsurf); |
| 2004 | } |
| 2005 | } |
| 2006 | |
| 2007 | static void |
| 2008 | create_keyboard_focus_listener(struct weston_seat *seat) |
| 2009 | { |
| 2010 | struct wl_listener *listener; |
| 2011 | |
| 2012 | if (!seat->keyboard) |
| 2013 | return; |
| 2014 | |
| 2015 | listener = malloc(sizeof *listener); |
| 2016 | listener->notify = handle_keyboard_focus; |
| 2017 | wl_signal_add(&seat->keyboard->focus_signal, listener); |
| 2018 | } |
| 2019 | |
Kristian Høgsberg | e7afd91 | 2012-05-02 09:47:44 -0400 | [diff] [blame] | 2020 | static void |
Kristian Høgsberg | dd62aba | 2014-02-12 09:56:19 -0800 | [diff] [blame] | 2021 | shell_client_pong(struct shell_client *sc, uint32_t serial) |
Rafael Antognolli | e2a3455 | 2013-12-03 15:35:45 -0200 | [diff] [blame] | 2022 | { |
Kristian Høgsberg | dd62aba | 2014-02-12 09:56:19 -0800 | [diff] [blame] | 2023 | if (sc->ping_serial != serial) |
| 2024 | return; |
Rafael Antognolli | e2a3455 | 2013-12-03 15:35:45 -0200 | [diff] [blame] | 2025 | |
Kristian Høgsberg | dd62aba | 2014-02-12 09:56:19 -0800 | [diff] [blame] | 2026 | sc->unresponsive = 0; |
| 2027 | end_busy_cursor(sc->shell->compositor, sc->client); |
Rafael Antognolli | e2a3455 | 2013-12-03 15:35:45 -0200 | [diff] [blame] | 2028 | |
Kristian Høgsberg | dd62aba | 2014-02-12 09:56:19 -0800 | [diff] [blame] | 2029 | if (sc->ping_timer) { |
| 2030 | wl_event_source_remove(sc->ping_timer); |
| 2031 | sc->ping_timer = NULL; |
| 2032 | } |
| 2033 | |
| 2034 | } |
| 2035 | |
| 2036 | static void |
| 2037 | shell_surface_pong(struct wl_client *client, |
| 2038 | struct wl_resource *resource, uint32_t serial) |
| 2039 | { |
Jason Ekstrand | 9e9512f | 2014-04-16 21:12:10 -0500 | [diff] [blame] | 2040 | struct shell_surface *shsurf = wl_resource_get_user_data(resource); |
| 2041 | struct shell_client *sc = shsurf->owner; |
Kristian Høgsberg | dd62aba | 2014-02-12 09:56:19 -0800 | [diff] [blame] | 2042 | |
Kristian Høgsberg | dd62aba | 2014-02-12 09:56:19 -0800 | [diff] [blame] | 2043 | shell_client_pong(sc, serial); |
Rafael Antognolli | e2a3455 | 2013-12-03 15:35:45 -0200 | [diff] [blame] | 2044 | } |
| 2045 | |
| 2046 | static void |
Giulio Camuffo | 62942ad | 2013-09-11 18:20:47 +0200 | [diff] [blame] | 2047 | set_title(struct shell_surface *shsurf, const char *title) |
| 2048 | { |
| 2049 | free(shsurf->title); |
| 2050 | shsurf->title = strdup(title); |
| 2051 | } |
| 2052 | |
| 2053 | static void |
Kristian Høgsberg | e7afd91 | 2012-05-02 09:47:44 -0400 | [diff] [blame] | 2054 | shell_surface_set_title(struct wl_client *client, |
| 2055 | struct wl_resource *resource, const char *title) |
| 2056 | { |
Jason Ekstrand | 651f00e | 2013-06-14 10:07:54 -0500 | [diff] [blame] | 2057 | struct shell_surface *shsurf = wl_resource_get_user_data(resource); |
Kristian Høgsberg | e7afd91 | 2012-05-02 09:47:44 -0400 | [diff] [blame] | 2058 | |
Giulio Camuffo | 62942ad | 2013-09-11 18:20:47 +0200 | [diff] [blame] | 2059 | set_title(shsurf, title); |
Kristian Høgsberg | e7afd91 | 2012-05-02 09:47:44 -0400 | [diff] [blame] | 2060 | } |
| 2061 | |
| 2062 | static void |
| 2063 | shell_surface_set_class(struct wl_client *client, |
| 2064 | struct wl_resource *resource, const char *class) |
| 2065 | { |
Jason Ekstrand | 651f00e | 2013-06-14 10:07:54 -0500 | [diff] [blame] | 2066 | struct shell_surface *shsurf = wl_resource_get_user_data(resource); |
Kristian Høgsberg | e7afd91 | 2012-05-02 09:47:44 -0400 | [diff] [blame] | 2067 | |
| 2068 | free(shsurf->class); |
| 2069 | shsurf->class = strdup(class); |
| 2070 | } |
| 2071 | |
Alex Wu | 4539b08 | 2012-03-01 12:57:46 +0800 | [diff] [blame] | 2072 | static void |
Alexander Larsson | f82b6ca | 2013-05-28 16:23:39 +0200 | [diff] [blame] | 2073 | restore_output_mode(struct weston_output *output) |
| 2074 | { |
Hardening | 57388e4 | 2013-09-18 23:56:36 +0200 | [diff] [blame] | 2075 | if (output->current_mode != output->original_mode || |
| 2076 | (int32_t)output->current_scale != output->original_scale) |
Alexander Larsson | f82b6ca | 2013-05-28 16:23:39 +0200 | [diff] [blame] | 2077 | weston_output_switch_mode(output, |
Hardening | 57388e4 | 2013-09-18 23:56:36 +0200 | [diff] [blame] | 2078 | output->original_mode, |
| 2079 | output->original_scale, |
| 2080 | WESTON_MODE_SWITCH_RESTORE_NATIVE); |
Alexander Larsson | f82b6ca | 2013-05-28 16:23:39 +0200 | [diff] [blame] | 2081 | } |
| 2082 | |
| 2083 | static void |
| 2084 | restore_all_output_modes(struct weston_compositor *compositor) |
| 2085 | { |
| 2086 | struct weston_output *output; |
| 2087 | |
| 2088 | wl_list_for_each(output, &compositor->output_list, link) |
| 2089 | restore_output_mode(output); |
| 2090 | } |
| 2091 | |
Philip Withnall | becb77e | 2013-11-25 18:01:30 +0000 | [diff] [blame] | 2092 | static int |
| 2093 | get_output_panel_height(struct desktop_shell *shell, |
| 2094 | struct weston_output *output) |
| 2095 | { |
| 2096 | struct weston_view *view; |
| 2097 | int panel_height = 0; |
| 2098 | |
| 2099 | if (!output) |
| 2100 | return 0; |
| 2101 | |
| 2102 | wl_list_for_each(view, &shell->panel_layer.view_list, layer_link) { |
| 2103 | if (view->surface->output == output) { |
Jason Ekstrand | 918f2dd | 2013-12-02 21:01:53 -0600 | [diff] [blame] | 2104 | panel_height = view->surface->height; |
Philip Withnall | becb77e | 2013-11-25 18:01:30 +0000 | [diff] [blame] | 2105 | break; |
| 2106 | } |
| 2107 | } |
| 2108 | |
| 2109 | return panel_height; |
| 2110 | } |
| 2111 | |
Philip Withnall | 07926d9 | 2013-11-25 18:01:40 +0000 | [diff] [blame] | 2112 | /* The surface will be inserted into the list immediately after the link |
| 2113 | * returned by this function (i.e. will be stacked immediately above the |
| 2114 | * returned link). */ |
| 2115 | static struct wl_list * |
| 2116 | shell_surface_calculate_layer_link (struct shell_surface *shsurf) |
| 2117 | { |
| 2118 | struct workspace *ws; |
Kristian Høgsberg | ead5242 | 2014-01-01 13:51:52 -0800 | [diff] [blame] | 2119 | struct weston_view *parent; |
Philip Withnall | 07926d9 | 2013-11-25 18:01:40 +0000 | [diff] [blame] | 2120 | |
| 2121 | switch (shsurf->type) { |
Kristian Høgsberg | ead5242 | 2014-01-01 13:51:52 -0800 | [diff] [blame] | 2122 | case SHELL_SURFACE_POPUP: |
| 2123 | case SHELL_SURFACE_TOPLEVEL: |
Rafael Antognolli | ed207b4 | 2013-12-03 15:35:43 -0200 | [diff] [blame] | 2124 | if (shsurf->state.fullscreen) { |
Rafael Antognolli | 03b1659 | 2013-12-03 15:35:42 -0200 | [diff] [blame] | 2125 | return &shsurf->shell->fullscreen_layer.view_list; |
Rafael Antognolli | ed207b4 | 2013-12-03 15:35:43 -0200 | [diff] [blame] | 2126 | } else if (shsurf->parent) { |
Kristian Høgsberg | d55db69 | 2014-01-01 12:26:14 -0800 | [diff] [blame] | 2127 | /* Move the surface to its parent layer so |
| 2128 | * that surfaces which are transient for |
| 2129 | * fullscreen surfaces don't get hidden by the |
| 2130 | * fullscreen surfaces. */ |
Rafael Antognolli | ed207b4 | 2013-12-03 15:35:43 -0200 | [diff] [blame] | 2131 | |
| 2132 | /* TODO: Handle a parent with multiple views */ |
| 2133 | parent = get_default_view(shsurf->parent); |
| 2134 | if (parent) |
| 2135 | return parent->layer_link.prev; |
| 2136 | } |
Rafael Antognolli | 03b1659 | 2013-12-03 15:35:42 -0200 | [diff] [blame] | 2137 | break; |
Philip Withnall | 07926d9 | 2013-11-25 18:01:40 +0000 | [diff] [blame] | 2138 | |
| 2139 | case SHELL_SURFACE_XWAYLAND: |
Kristian Høgsberg | 4804a30 | 2013-12-05 22:43:03 -0800 | [diff] [blame] | 2140 | return &shsurf->shell->fullscreen_layer.view_list; |
| 2141 | |
Philip Withnall | 07926d9 | 2013-11-25 18:01:40 +0000 | [diff] [blame] | 2142 | case SHELL_SURFACE_NONE: |
| 2143 | default: |
| 2144 | /* Go to the fallback, below. */ |
| 2145 | break; |
| 2146 | } |
| 2147 | |
| 2148 | /* Move the surface to a normal workspace layer so that surfaces |
| 2149 | * which were previously fullscreen or transient are no longer |
| 2150 | * rendered on top. */ |
| 2151 | ws = get_current_workspace(shsurf->shell); |
| 2152 | return &ws->layer.view_list; |
| 2153 | } |
| 2154 | |
Philip Withnall | 648a4dd | 2013-11-25 18:01:44 +0000 | [diff] [blame] | 2155 | static void |
| 2156 | shell_surface_update_child_surface_layers (struct shell_surface *shsurf) |
| 2157 | { |
| 2158 | struct shell_surface *child; |
| 2159 | |
| 2160 | /* Move the child layers to the same workspace as shsurf. They will be |
| 2161 | * stacked above shsurf. */ |
| 2162 | wl_list_for_each_reverse(child, &shsurf->children_list, children_link) { |
| 2163 | if (shsurf->view->layer_link.prev != &child->view->layer_link) { |
Ander Conselvan de Oliveira | facc0cc | 2014-04-10 15:35:58 +0300 | [diff] [blame] | 2164 | weston_view_damage_below(child->view); |
Philip Withnall | 648a4dd | 2013-11-25 18:01:44 +0000 | [diff] [blame] | 2165 | weston_view_geometry_dirty(child->view); |
| 2166 | wl_list_remove(&child->view->layer_link); |
| 2167 | wl_list_insert(shsurf->view->layer_link.prev, |
| 2168 | &child->view->layer_link); |
| 2169 | weston_view_geometry_dirty(child->view); |
| 2170 | weston_surface_damage(child->surface); |
| 2171 | |
| 2172 | /* Recurse. We don’t expect this to recurse very far (if |
| 2173 | * at all) because that would imply we have transient |
| 2174 | * (or popup) children of transient surfaces, which |
| 2175 | * would be unusual. */ |
| 2176 | shell_surface_update_child_surface_layers(child); |
| 2177 | } |
| 2178 | } |
| 2179 | } |
| 2180 | |
Philip Withnall | e1d75ae | 2013-11-25 18:01:41 +0000 | [diff] [blame] | 2181 | /* 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] | 2182 | * geometry to ensure the changes are redrawn. |
| 2183 | * |
| 2184 | * If any child surfaces exist and are mapped, ensure they’re in the same layer |
| 2185 | * as this surface. */ |
Philip Withnall | e1d75ae | 2013-11-25 18:01:41 +0000 | [diff] [blame] | 2186 | static void |
| 2187 | shell_surface_update_layer(struct shell_surface *shsurf) |
| 2188 | { |
| 2189 | struct wl_list *new_layer_link; |
| 2190 | |
| 2191 | new_layer_link = shell_surface_calculate_layer_link(shsurf); |
| 2192 | |
| 2193 | if (new_layer_link == &shsurf->view->layer_link) |
| 2194 | return; |
| 2195 | |
| 2196 | weston_view_geometry_dirty(shsurf->view); |
| 2197 | wl_list_remove(&shsurf->view->layer_link); |
| 2198 | wl_list_insert(new_layer_link, &shsurf->view->layer_link); |
| 2199 | weston_view_geometry_dirty(shsurf->view); |
| 2200 | weston_surface_damage(shsurf->surface); |
Philip Withnall | 648a4dd | 2013-11-25 18:01:44 +0000 | [diff] [blame] | 2201 | |
| 2202 | shell_surface_update_child_surface_layers(shsurf); |
Philip Withnall | e1d75ae | 2013-11-25 18:01:41 +0000 | [diff] [blame] | 2203 | } |
| 2204 | |
Alexander Larsson | f82b6ca | 2013-05-28 16:23:39 +0200 | [diff] [blame] | 2205 | static void |
Philip Withnall | dc4332f | 2013-11-25 18:01:38 +0000 | [diff] [blame] | 2206 | shell_surface_set_parent(struct shell_surface *shsurf, |
| 2207 | struct weston_surface *parent) |
| 2208 | { |
| 2209 | shsurf->parent = parent; |
Philip Withnall | 648a4dd | 2013-11-25 18:01:44 +0000 | [diff] [blame] | 2210 | |
| 2211 | wl_list_remove(&shsurf->children_link); |
| 2212 | wl_list_init(&shsurf->children_link); |
| 2213 | |
| 2214 | /* Insert into the parent surface’s child list. */ |
| 2215 | if (parent != NULL) { |
| 2216 | struct shell_surface *parent_shsurf = get_shell_surface(parent); |
| 2217 | if (parent_shsurf != NULL) |
| 2218 | wl_list_insert(&parent_shsurf->children_list, |
| 2219 | &shsurf->children_link); |
| 2220 | } |
Philip Withnall | dc4332f | 2013-11-25 18:01:38 +0000 | [diff] [blame] | 2221 | } |
| 2222 | |
| 2223 | static void |
Philip Withnall | 352e7ed | 2013-11-25 18:01:35 +0000 | [diff] [blame] | 2224 | shell_surface_set_output(struct shell_surface *shsurf, |
| 2225 | struct weston_output *output) |
| 2226 | { |
| 2227 | struct weston_surface *es = shsurf->surface; |
| 2228 | |
| 2229 | /* get the default output, if the client set it as NULL |
| 2230 | check whether the ouput is available */ |
| 2231 | if (output) |
| 2232 | shsurf->output = output; |
| 2233 | else if (es->output) |
| 2234 | shsurf->output = es->output; |
| 2235 | else |
| 2236 | shsurf->output = get_default_output(es->compositor); |
| 2237 | } |
| 2238 | |
| 2239 | static void |
Rafael Antognolli | 03b1659 | 2013-12-03 15:35:42 -0200 | [diff] [blame] | 2240 | surface_clear_next_states(struct shell_surface *shsurf) |
| 2241 | { |
| 2242 | shsurf->next_state.maximized = false; |
| 2243 | shsurf->next_state.fullscreen = false; |
| 2244 | |
| 2245 | if ((shsurf->next_state.maximized != shsurf->state.maximized) || |
| 2246 | (shsurf->next_state.fullscreen != shsurf->state.fullscreen)) |
| 2247 | shsurf->state_changed = true; |
| 2248 | } |
| 2249 | |
| 2250 | static void |
Philip Withnall | becb77e | 2013-11-25 18:01:30 +0000 | [diff] [blame] | 2251 | set_toplevel(struct shell_surface *shsurf) |
| 2252 | { |
Kristian Høgsberg | 41fbf6f | 2013-12-05 22:31:25 -0800 | [diff] [blame] | 2253 | shell_surface_set_parent(shsurf, NULL); |
| 2254 | surface_clear_next_states(shsurf); |
Kristian Høgsberg | c8f8dd8 | 2013-12-05 23:20:33 -0800 | [diff] [blame] | 2255 | shsurf->type = SHELL_SURFACE_TOPLEVEL; |
Philip Withnall | 648a4dd | 2013-11-25 18:01:44 +0000 | [diff] [blame] | 2256 | |
| 2257 | /* The layer_link is updated in set_surface_type(), |
| 2258 | * called from configure. */ |
Philip Withnall | becb77e | 2013-11-25 18:01:30 +0000 | [diff] [blame] | 2259 | } |
| 2260 | |
| 2261 | static void |
| 2262 | shell_surface_set_toplevel(struct wl_client *client, |
| 2263 | struct wl_resource *resource) |
| 2264 | { |
| 2265 | struct shell_surface *surface = wl_resource_get_user_data(resource); |
| 2266 | |
| 2267 | set_toplevel(surface); |
| 2268 | } |
| 2269 | |
| 2270 | static void |
| 2271 | set_transient(struct shell_surface *shsurf, |
| 2272 | struct weston_surface *parent, int x, int y, uint32_t flags) |
| 2273 | { |
Philip Withnall | dc4332f | 2013-11-25 18:01:38 +0000 | [diff] [blame] | 2274 | assert(parent != NULL); |
| 2275 | |
Kristian Høgsberg | 9f7e331 | 2014-01-02 22:40:37 -0800 | [diff] [blame] | 2276 | shell_surface_set_parent(shsurf, parent); |
| 2277 | |
| 2278 | surface_clear_next_states(shsurf); |
| 2279 | |
Philip Withnall | becb77e | 2013-11-25 18:01:30 +0000 | [diff] [blame] | 2280 | shsurf->transient.x = x; |
| 2281 | shsurf->transient.y = y; |
| 2282 | shsurf->transient.flags = flags; |
Philip Withnall | dc4332f | 2013-11-25 18:01:38 +0000 | [diff] [blame] | 2283 | |
Rafael Antognolli | ed207b4 | 2013-12-03 15:35:43 -0200 | [diff] [blame] | 2284 | shsurf->next_state.relative = true; |
Kristian Høgsberg | a1df7ac | 2013-12-31 15:01:01 -0800 | [diff] [blame] | 2285 | shsurf->state_changed = true; |
Kristian Høgsberg | c8f8dd8 | 2013-12-05 23:20:33 -0800 | [diff] [blame] | 2286 | shsurf->type = SHELL_SURFACE_TOPLEVEL; |
Philip Withnall | 648a4dd | 2013-11-25 18:01:44 +0000 | [diff] [blame] | 2287 | |
| 2288 | /* The layer_link is updated in set_surface_type(), |
| 2289 | * called from configure. */ |
Philip Withnall | becb77e | 2013-11-25 18:01:30 +0000 | [diff] [blame] | 2290 | } |
| 2291 | |
| 2292 | static void |
| 2293 | shell_surface_set_transient(struct wl_client *client, |
| 2294 | struct wl_resource *resource, |
| 2295 | struct wl_resource *parent_resource, |
| 2296 | int x, int y, uint32_t flags) |
| 2297 | { |
| 2298 | struct shell_surface *shsurf = wl_resource_get_user_data(resource); |
| 2299 | struct weston_surface *parent = |
| 2300 | wl_resource_get_user_data(parent_resource); |
| 2301 | |
| 2302 | set_transient(shsurf, parent, x, y, flags); |
| 2303 | } |
| 2304 | |
| 2305 | static void |
| 2306 | set_fullscreen(struct shell_surface *shsurf, |
| 2307 | uint32_t method, |
| 2308 | uint32_t framerate, |
| 2309 | struct weston_output *output) |
| 2310 | { |
Philip Withnall | 352e7ed | 2013-11-25 18:01:35 +0000 | [diff] [blame] | 2311 | shell_surface_set_output(shsurf, output); |
Philip Withnall | becb77e | 2013-11-25 18:01:30 +0000 | [diff] [blame] | 2312 | |
| 2313 | shsurf->fullscreen_output = shsurf->output; |
| 2314 | shsurf->fullscreen.type = method; |
| 2315 | shsurf->fullscreen.framerate = framerate; |
Philip Withnall | dc4332f | 2013-11-25 18:01:38 +0000 | [diff] [blame] | 2316 | |
Kristian Høgsberg | c8f8dd8 | 2013-12-05 23:20:33 -0800 | [diff] [blame] | 2317 | shsurf->type = SHELL_SURFACE_TOPLEVEL; |
Philip Withnall | becb77e | 2013-11-25 18:01:30 +0000 | [diff] [blame] | 2318 | |
| 2319 | shsurf->client->send_configure(shsurf->surface, 0, |
| 2320 | shsurf->output->width, |
| 2321 | shsurf->output->height); |
Philip Withnall | 648a4dd | 2013-11-25 18:01:44 +0000 | [diff] [blame] | 2322 | |
| 2323 | /* The layer_link is updated in set_surface_type(), |
| 2324 | * called from configure. */ |
Philip Withnall | becb77e | 2013-11-25 18:01:30 +0000 | [diff] [blame] | 2325 | } |
| 2326 | |
| 2327 | static void |
Zhang, Xiong Y | 3123693 | 2013-12-13 22:10:57 +0200 | [diff] [blame] | 2328 | weston_view_set_initial_position(struct weston_view *view, |
| 2329 | struct desktop_shell *shell); |
| 2330 | |
| 2331 | static void |
Philip Withnall | becb77e | 2013-11-25 18:01:30 +0000 | [diff] [blame] | 2332 | unset_fullscreen(struct shell_surface *shsurf) |
Alex Wu | 4539b08 | 2012-03-01 12:57:46 +0800 | [diff] [blame] | 2333 | { |
Philip Withnall | f85fe84 | 2013-11-25 18:01:37 +0000 | [diff] [blame] | 2334 | /* Unset the fullscreen output, driver configuration and transforms. */ |
Alex Wu | bd3354b | 2012-04-17 17:20:49 +0800 | [diff] [blame] | 2335 | if (shsurf->fullscreen.type == WL_SHELL_SURFACE_FULLSCREEN_METHOD_DRIVER && |
| 2336 | shell_surface_is_top_fullscreen(shsurf)) { |
Alexander Larsson | f82b6ca | 2013-05-28 16:23:39 +0200 | [diff] [blame] | 2337 | restore_output_mode(shsurf->fullscreen_output); |
Alex Wu | bd3354b | 2012-04-17 17:20:49 +0800 | [diff] [blame] | 2338 | } |
Philip Withnall | f85fe84 | 2013-11-25 18:01:37 +0000 | [diff] [blame] | 2339 | |
Alex Wu | 4539b08 | 2012-03-01 12:57:46 +0800 | [diff] [blame] | 2340 | shsurf->fullscreen.type = WL_SHELL_SURFACE_FULLSCREEN_METHOD_DEFAULT; |
| 2341 | shsurf->fullscreen.framerate = 0; |
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 | wl_list_remove(&shsurf->fullscreen.transform.link); |
| 2344 | wl_list_init(&shsurf->fullscreen.transform.link); |
Philip Withnall | f85fe84 | 2013-11-25 18:01:37 +0000 | [diff] [blame] | 2345 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 2346 | if (shsurf->fullscreen.black_view) |
| 2347 | weston_surface_destroy(shsurf->fullscreen.black_view->surface); |
| 2348 | shsurf->fullscreen.black_view = NULL; |
Philip Withnall | f85fe84 | 2013-11-25 18:01:37 +0000 | [diff] [blame] | 2349 | |
Zhang, Xiong Y | 3123693 | 2013-12-13 22:10:57 +0200 | [diff] [blame] | 2350 | if (shsurf->saved_position_valid) |
| 2351 | weston_view_set_position(shsurf->view, |
| 2352 | shsurf->saved_x, shsurf->saved_y); |
| 2353 | else |
| 2354 | weston_view_set_initial_position(shsurf->view, shsurf->shell); |
| 2355 | |
Alex Wu | 7bcb8bd | 2012-04-27 09:07:24 +0800 | [diff] [blame] | 2356 | if (shsurf->saved_rotation_valid) { |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 2357 | wl_list_insert(&shsurf->view->geometry.transformation_list, |
Philip Withnall | becb77e | 2013-11-25 18:01:30 +0000 | [diff] [blame] | 2358 | &shsurf->rotation.transform.link); |
Alex Wu | 7bcb8bd | 2012-04-27 09:07:24 +0800 | [diff] [blame] | 2359 | shsurf->saved_rotation_valid = false; |
| 2360 | } |
Rafal Mielniczuk | 3e3862c | 2012-10-07 20:25:36 +0200 | [diff] [blame] | 2361 | |
Philip Withnall | e1d75ae | 2013-11-25 18:01:41 +0000 | [diff] [blame] | 2362 | /* Layer is updated in set_surface_type(). */ |
Alex Wu | 4539b08 | 2012-03-01 12:57:46 +0800 | [diff] [blame] | 2363 | } |
| 2364 | |
Rafal Mielniczuk | fffdcdd | 2013-03-11 19:26:54 +0100 | [diff] [blame] | 2365 | static void |
Philip Withnall | becb77e | 2013-11-25 18:01:30 +0000 | [diff] [blame] | 2366 | shell_surface_set_fullscreen(struct wl_client *client, |
| 2367 | struct wl_resource *resource, |
| 2368 | uint32_t method, |
| 2369 | uint32_t framerate, |
| 2370 | struct wl_resource *output_resource) |
| 2371 | { |
| 2372 | struct shell_surface *shsurf = wl_resource_get_user_data(resource); |
| 2373 | struct weston_output *output; |
| 2374 | |
| 2375 | if (output_resource) |
| 2376 | output = wl_resource_get_user_data(output_resource); |
| 2377 | else |
| 2378 | output = NULL; |
| 2379 | |
Rafael Antognolli | 4b99a40 | 2013-12-03 15:35:44 -0200 | [diff] [blame] | 2380 | shell_surface_set_parent(shsurf, NULL); |
| 2381 | |
Rafael Antognolli | 03b1659 | 2013-12-03 15:35:42 -0200 | [diff] [blame] | 2382 | surface_clear_next_states(shsurf); |
Philip Withnall | becb77e | 2013-11-25 18:01:30 +0000 | [diff] [blame] | 2383 | set_fullscreen(shsurf, method, framerate, output); |
Jasper St. Pierre | 8c6aa45 | 2014-02-08 18:29:49 -0500 | [diff] [blame] | 2384 | |
| 2385 | shsurf->next_state.fullscreen = true; |
| 2386 | shsurf->state_changed = true; |
Philip Withnall | becb77e | 2013-11-25 18:01:30 +0000 | [diff] [blame] | 2387 | } |
| 2388 | |
| 2389 | static void |
| 2390 | set_popup(struct shell_surface *shsurf, |
| 2391 | struct weston_surface *parent, |
| 2392 | struct weston_seat *seat, |
| 2393 | uint32_t serial, |
| 2394 | int32_t x, |
| 2395 | int32_t y) |
| 2396 | { |
Philip Withnall | dc4332f | 2013-11-25 18:01:38 +0000 | [diff] [blame] | 2397 | assert(parent != NULL); |
| 2398 | |
Philip Withnall | becb77e | 2013-11-25 18:01:30 +0000 | [diff] [blame] | 2399 | shsurf->popup.shseat = get_shell_seat(seat); |
| 2400 | shsurf->popup.serial = serial; |
| 2401 | shsurf->popup.x = x; |
| 2402 | shsurf->popup.y = y; |
Philip Withnall | dc4332f | 2013-11-25 18:01:38 +0000 | [diff] [blame] | 2403 | |
Kristian Høgsberg | c8f8dd8 | 2013-12-05 23:20:33 -0800 | [diff] [blame] | 2404 | shsurf->type = SHELL_SURFACE_POPUP; |
Philip Withnall | becb77e | 2013-11-25 18:01:30 +0000 | [diff] [blame] | 2405 | } |
| 2406 | |
| 2407 | static void |
| 2408 | shell_surface_set_popup(struct wl_client *client, |
| 2409 | struct wl_resource *resource, |
| 2410 | struct wl_resource *seat_resource, |
| 2411 | uint32_t serial, |
| 2412 | struct wl_resource *parent_resource, |
| 2413 | int32_t x, int32_t y, uint32_t flags) |
| 2414 | { |
| 2415 | struct shell_surface *shsurf = wl_resource_get_user_data(resource); |
Rafael Antognolli | 4b99a40 | 2013-12-03 15:35:44 -0200 | [diff] [blame] | 2416 | struct weston_surface *parent = |
| 2417 | wl_resource_get_user_data(parent_resource); |
| 2418 | |
| 2419 | shell_surface_set_parent(shsurf, parent); |
Philip Withnall | becb77e | 2013-11-25 18:01:30 +0000 | [diff] [blame] | 2420 | |
Rafael Antognolli | 03b1659 | 2013-12-03 15:35:42 -0200 | [diff] [blame] | 2421 | surface_clear_next_states(shsurf); |
Philip Withnall | becb77e | 2013-11-25 18:01:30 +0000 | [diff] [blame] | 2422 | set_popup(shsurf, |
Rafael Antognolli | 4b99a40 | 2013-12-03 15:35:44 -0200 | [diff] [blame] | 2423 | parent, |
Philip Withnall | becb77e | 2013-11-25 18:01:30 +0000 | [diff] [blame] | 2424 | wl_resource_get_user_data(seat_resource), |
| 2425 | serial, x, y); |
| 2426 | } |
| 2427 | |
| 2428 | static void |
| 2429 | set_maximized(struct shell_surface *shsurf, |
| 2430 | struct weston_output *output) |
| 2431 | { |
| 2432 | struct desktop_shell *shell; |
| 2433 | uint32_t edges = 0, panel_height = 0; |
Philip Withnall | becb77e | 2013-11-25 18:01:30 +0000 | [diff] [blame] | 2434 | |
Philip Withnall | 352e7ed | 2013-11-25 18:01:35 +0000 | [diff] [blame] | 2435 | shell_surface_set_output(shsurf, output); |
Philip Withnall | becb77e | 2013-11-25 18:01:30 +0000 | [diff] [blame] | 2436 | |
| 2437 | shell = shell_surface_get_shell(shsurf); |
| 2438 | panel_height = get_output_panel_height(shell, shsurf->output); |
| 2439 | edges = WL_SHELL_SURFACE_RESIZE_TOP | WL_SHELL_SURFACE_RESIZE_LEFT; |
| 2440 | |
| 2441 | shsurf->client->send_configure(shsurf->surface, edges, |
| 2442 | shsurf->output->width, |
| 2443 | shsurf->output->height - panel_height); |
| 2444 | |
Kristian Høgsberg | c8f8dd8 | 2013-12-05 23:20:33 -0800 | [diff] [blame] | 2445 | shsurf->type = SHELL_SURFACE_TOPLEVEL; |
Philip Withnall | becb77e | 2013-11-25 18:01:30 +0000 | [diff] [blame] | 2446 | } |
| 2447 | |
| 2448 | static void |
| 2449 | unset_maximized(struct shell_surface *shsurf) |
Rafal Mielniczuk | fffdcdd | 2013-03-11 19:26:54 +0100 | [diff] [blame] | 2450 | { |
Rafal Mielniczuk | fffdcdd | 2013-03-11 19:26:54 +0100 | [diff] [blame] | 2451 | /* undo all maximized things here */ |
| 2452 | shsurf->output = get_default_output(shsurf->surface->compositor); |
Zhang, Xiong Y | 3123693 | 2013-12-13 22:10:57 +0200 | [diff] [blame] | 2453 | |
| 2454 | if (shsurf->saved_position_valid) |
| 2455 | weston_view_set_position(shsurf->view, |
| 2456 | shsurf->saved_x, shsurf->saved_y); |
| 2457 | else |
| 2458 | weston_view_set_initial_position(shsurf->view, shsurf->shell); |
Rafal Mielniczuk | fffdcdd | 2013-03-11 19:26:54 +0100 | [diff] [blame] | 2459 | |
| 2460 | if (shsurf->saved_rotation_valid) { |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 2461 | wl_list_insert(&shsurf->view->geometry.transformation_list, |
| 2462 | &shsurf->rotation.transform.link); |
Rafal Mielniczuk | fffdcdd | 2013-03-11 19:26:54 +0100 | [diff] [blame] | 2463 | shsurf->saved_rotation_valid = false; |
| 2464 | } |
| 2465 | |
Philip Withnall | e1d75ae | 2013-11-25 18:01:41 +0000 | [diff] [blame] | 2466 | /* Layer is updated in set_surface_type(). */ |
Rafal Mielniczuk | fffdcdd | 2013-03-11 19:26:54 +0100 | [diff] [blame] | 2467 | } |
| 2468 | |
Philip Withnall | becb77e | 2013-11-25 18:01:30 +0000 | [diff] [blame] | 2469 | static void |
Manuel Bachmann | 50c87db | 2014-02-26 15:52:13 +0100 | [diff] [blame] | 2470 | set_minimized(struct weston_surface *surface, uint32_t is_true) |
| 2471 | { |
| 2472 | struct shell_surface *shsurf; |
| 2473 | struct workspace *current_ws; |
| 2474 | struct weston_seat *seat; |
| 2475 | struct weston_surface *focus; |
| 2476 | struct weston_view *view; |
| 2477 | |
| 2478 | view = get_default_view(surface); |
| 2479 | if (!view) |
| 2480 | return; |
| 2481 | |
| 2482 | assert(weston_surface_get_main_surface(view->surface) == view->surface); |
| 2483 | |
| 2484 | shsurf = get_shell_surface(surface); |
| 2485 | current_ws = get_current_workspace(shsurf->shell); |
| 2486 | |
| 2487 | wl_list_remove(&view->layer_link); |
| 2488 | /* hide or show, depending on the state */ |
| 2489 | if (is_true) { |
| 2490 | wl_list_insert(&shsurf->shell->minimized_layer.view_list, &view->layer_link); |
| 2491 | |
| 2492 | drop_focus_state(shsurf->shell, current_ws, view->surface); |
| 2493 | wl_list_for_each(seat, &shsurf->shell->compositor->seat_list, link) { |
| 2494 | if (!seat->keyboard) |
| 2495 | continue; |
| 2496 | focus = weston_surface_get_main_surface(seat->keyboard->focus); |
| 2497 | if (focus == view->surface) |
| 2498 | weston_keyboard_set_focus(seat->keyboard, NULL); |
| 2499 | } |
| 2500 | } |
| 2501 | else { |
| 2502 | wl_list_insert(¤t_ws->layer.view_list, &view->layer_link); |
| 2503 | |
| 2504 | wl_list_for_each(seat, &shsurf->shell->compositor->seat_list, link) { |
| 2505 | if (!seat->keyboard) |
| 2506 | continue; |
| 2507 | activate(shsurf->shell, view->surface, seat); |
| 2508 | } |
| 2509 | } |
| 2510 | |
| 2511 | shell_surface_update_child_surface_layers(shsurf); |
| 2512 | |
| 2513 | weston_view_damage_below(view); |
| 2514 | } |
| 2515 | |
| 2516 | static void |
Philip Withnall | becb77e | 2013-11-25 18:01:30 +0000 | [diff] [blame] | 2517 | shell_surface_set_maximized(struct wl_client *client, |
| 2518 | struct wl_resource *resource, |
| 2519 | struct wl_resource *output_resource) |
| 2520 | { |
| 2521 | struct shell_surface *shsurf = wl_resource_get_user_data(resource); |
| 2522 | struct weston_output *output; |
| 2523 | |
| 2524 | if (output_resource) |
| 2525 | output = wl_resource_get_user_data(output_resource); |
| 2526 | else |
| 2527 | output = NULL; |
| 2528 | |
Rafael Antognolli | 4b99a40 | 2013-12-03 15:35:44 -0200 | [diff] [blame] | 2529 | shell_surface_set_parent(shsurf, NULL); |
| 2530 | |
Rafael Antognolli | 03b1659 | 2013-12-03 15:35:42 -0200 | [diff] [blame] | 2531 | surface_clear_next_states(shsurf); |
Philip Withnall | becb77e | 2013-11-25 18:01:30 +0000 | [diff] [blame] | 2532 | set_maximized(shsurf, output); |
Jasper St. Pierre | 8c6aa45 | 2014-02-08 18:29:49 -0500 | [diff] [blame] | 2533 | |
| 2534 | shsurf->next_state.maximized = true; |
| 2535 | shsurf->state_changed = true; |
Philip Withnall | becb77e | 2013-11-25 18:01:30 +0000 | [diff] [blame] | 2536 | } |
| 2537 | |
Philip Withnall | e1d75ae | 2013-11-25 18:01:41 +0000 | [diff] [blame] | 2538 | /* This is only ever called from set_surface_type(), so there’s no need to |
| 2539 | * update layer_links here, since they’ll be updated when we return. */ |
Pekka Paalanen | 9826223 | 2011-12-01 10:42:22 +0200 | [diff] [blame] | 2540 | static int |
Philip Withnall | becb77e | 2013-11-25 18:01:30 +0000 | [diff] [blame] | 2541 | reset_surface_type(struct shell_surface *surface) |
Pekka Paalanen | 9826223 | 2011-12-01 10:42:22 +0200 | [diff] [blame] | 2542 | { |
Rafael Antognolli | 03b1659 | 2013-12-03 15:35:42 -0200 | [diff] [blame] | 2543 | if (surface->state.fullscreen) |
Philip Withnall | becb77e | 2013-11-25 18:01:30 +0000 | [diff] [blame] | 2544 | unset_fullscreen(surface); |
Rafael Antognolli | 03b1659 | 2013-12-03 15:35:42 -0200 | [diff] [blame] | 2545 | if (surface->state.maximized) |
Philip Withnall | becb77e | 2013-11-25 18:01:30 +0000 | [diff] [blame] | 2546 | unset_maximized(surface); |
Pekka Paalanen | 9826223 | 2011-12-01 10:42:22 +0200 | [diff] [blame] | 2547 | |
Pekka Paalanen | 9826223 | 2011-12-01 10:42:22 +0200 | [diff] [blame] | 2548 | return 0; |
| 2549 | } |
| 2550 | |
Kristian Høgsberg | 4cca349 | 2011-01-18 07:53:49 -0500 | [diff] [blame] | 2551 | static void |
Rafael Antognolli | 03b1659 | 2013-12-03 15:35:42 -0200 | [diff] [blame] | 2552 | set_full_output(struct shell_surface *shsurf) |
| 2553 | { |
| 2554 | shsurf->saved_x = shsurf->view->geometry.x; |
| 2555 | shsurf->saved_y = shsurf->view->geometry.y; |
Rafael Antognolli | 3c4e3f7 | 2013-12-03 15:35:46 -0200 | [diff] [blame] | 2556 | shsurf->saved_width = shsurf->surface->width; |
| 2557 | shsurf->saved_height = shsurf->surface->height; |
| 2558 | shsurf->saved_size_valid = true; |
Rafael Antognolli | 03b1659 | 2013-12-03 15:35:42 -0200 | [diff] [blame] | 2559 | shsurf->saved_position_valid = true; |
| 2560 | |
| 2561 | if (!wl_list_empty(&shsurf->rotation.transform.link)) { |
| 2562 | wl_list_remove(&shsurf->rotation.transform.link); |
| 2563 | wl_list_init(&shsurf->rotation.transform.link); |
| 2564 | weston_view_geometry_dirty(shsurf->view); |
| 2565 | shsurf->saved_rotation_valid = true; |
| 2566 | } |
| 2567 | } |
| 2568 | |
| 2569 | static void |
Kristian Høgsberg | 7f366e7 | 2012-04-27 17:20:01 -0400 | [diff] [blame] | 2570 | set_surface_type(struct shell_surface *shsurf) |
| 2571 | { |
Kristian Høgsberg | 8150b19 | 2012-06-27 10:22:58 -0400 | [diff] [blame] | 2572 | struct weston_surface *pes = shsurf->parent; |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 2573 | struct weston_view *pev = get_default_view(pes); |
Kristian Høgsberg | 7f366e7 | 2012-04-27 17:20:01 -0400 | [diff] [blame] | 2574 | |
Philip Withnall | becb77e | 2013-11-25 18:01:30 +0000 | [diff] [blame] | 2575 | reset_surface_type(shsurf); |
Kristian Høgsberg | 7f366e7 | 2012-04-27 17:20:01 -0400 | [diff] [blame] | 2576 | |
Rafael Antognolli | 03b1659 | 2013-12-03 15:35:42 -0200 | [diff] [blame] | 2577 | shsurf->state = shsurf->next_state; |
Rafael Antognolli | 03b1659 | 2013-12-03 15:35:42 -0200 | [diff] [blame] | 2578 | shsurf->state_changed = false; |
Kristian Høgsberg | 7f366e7 | 2012-04-27 17:20:01 -0400 | [diff] [blame] | 2579 | |
| 2580 | switch (shsurf->type) { |
| 2581 | case SHELL_SURFACE_TOPLEVEL: |
Rafael Antognolli | ed207b4 | 2013-12-03 15:35:43 -0200 | [diff] [blame] | 2582 | if (shsurf->state.maximized || shsurf->state.fullscreen) { |
Rafael Antognolli | 03b1659 | 2013-12-03 15:35:42 -0200 | [diff] [blame] | 2583 | set_full_output(shsurf); |
Rafael Antognolli | ed207b4 | 2013-12-03 15:35:43 -0200 | [diff] [blame] | 2584 | } else if (shsurf->state.relative && pev) { |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 2585 | weston_view_set_position(shsurf->view, |
| 2586 | pev->geometry.x + shsurf->transient.x, |
| 2587 | pev->geometry.y + shsurf->transient.y); |
Rafael Antognolli | ed207b4 | 2013-12-03 15:35:43 -0200 | [diff] [blame] | 2588 | } |
Rafael Antognolli | 44a3162 | 2013-12-04 18:37:16 -0200 | [diff] [blame] | 2589 | break; |
Kristian Høgsberg | 7f366e7 | 2012-04-27 17:20:01 -0400 | [diff] [blame] | 2590 | |
Tiago Vignatti | fb2adba | 2013-06-12 15:43:21 -0300 | [diff] [blame] | 2591 | case SHELL_SURFACE_XWAYLAND: |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 2592 | weston_view_set_position(shsurf->view, shsurf->transient.x, |
| 2593 | shsurf->transient.y); |
Tiago Vignatti | fb2adba | 2013-06-12 15:43:21 -0300 | [diff] [blame] | 2594 | break; |
| 2595 | |
Philip Withnall | 0f640e2 | 2013-11-25 18:01:31 +0000 | [diff] [blame] | 2596 | case SHELL_SURFACE_POPUP: |
| 2597 | case SHELL_SURFACE_NONE: |
Kristian Høgsberg | 7f366e7 | 2012-04-27 17:20:01 -0400 | [diff] [blame] | 2598 | default: |
| 2599 | break; |
| 2600 | } |
Philip Withnall | e1d75ae | 2013-11-25 18:01:41 +0000 | [diff] [blame] | 2601 | |
| 2602 | /* Update the surface’s layer. */ |
| 2603 | shell_surface_update_layer(shsurf); |
Kristian Høgsberg | 7f366e7 | 2012-04-27 17:20:01 -0400 | [diff] [blame] | 2604 | } |
| 2605 | |
Tiago Vignatti | be14326 | 2012-04-16 17:31:41 +0300 | [diff] [blame] | 2606 | static struct desktop_shell * |
Juan Zhao | 96879df | 2012-02-07 08:45:41 +0800 | [diff] [blame] | 2607 | shell_surface_get_shell(struct shell_surface *shsurf) |
Pekka Paalanen | af0e34c | 2011-12-02 10:59:17 +0200 | [diff] [blame] | 2608 | { |
Kristian Høgsberg | 02e79dc | 2012-04-12 09:55:26 -0400 | [diff] [blame] | 2609 | return shsurf->shell; |
Juan Zhao | 96879df | 2012-02-07 08:45:41 +0800 | [diff] [blame] | 2610 | } |
| 2611 | |
Alex Wu | 2185843 | 2012-04-01 20:13:08 +0800 | [diff] [blame] | 2612 | static void |
Jason Ekstrand | 918f2dd | 2013-12-02 21:01:53 -0600 | [diff] [blame] | 2613 | 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] | 2614 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 2615 | static struct weston_view * |
Alex Wu | 4539b08 | 2012-03-01 12:57:46 +0800 | [diff] [blame] | 2616 | create_black_surface(struct weston_compositor *ec, |
Alex Wu | 2185843 | 2012-04-01 20:13:08 +0800 | [diff] [blame] | 2617 | struct weston_surface *fs_surface, |
John Kåre Alsaker | 490d02a | 2012-09-30 02:57:21 +0200 | [diff] [blame] | 2618 | float x, float y, int w, int h) |
Alex Wu | 4539b08 | 2012-03-01 12:57:46 +0800 | [diff] [blame] | 2619 | { |
| 2620 | struct weston_surface *surface = NULL; |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 2621 | struct weston_view *view; |
Alex Wu | 4539b08 | 2012-03-01 12:57:46 +0800 | [diff] [blame] | 2622 | |
| 2623 | surface = weston_surface_create(ec); |
| 2624 | if (surface == NULL) { |
Martin Minarik | 6d11836 | 2012-06-07 18:01:59 +0200 | [diff] [blame] | 2625 | weston_log("no memory\n"); |
Alex Wu | 4539b08 | 2012-03-01 12:57:46 +0800 | [diff] [blame] | 2626 | return NULL; |
| 2627 | } |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 2628 | view = weston_view_create(surface); |
| 2629 | if (surface == NULL) { |
| 2630 | weston_log("no memory\n"); |
| 2631 | weston_surface_destroy(surface); |
| 2632 | return NULL; |
| 2633 | } |
Alex Wu | 4539b08 | 2012-03-01 12:57:46 +0800 | [diff] [blame] | 2634 | |
Alex Wu | 2185843 | 2012-04-01 20:13:08 +0800 | [diff] [blame] | 2635 | surface->configure = black_surface_configure; |
Giulio Camuffo | 7fe01b1 | 2013-03-28 18:02:42 +0100 | [diff] [blame] | 2636 | surface->configure_private = fs_surface; |
Alex Wu | 4539b08 | 2012-03-01 12:57:46 +0800 | [diff] [blame] | 2637 | weston_surface_set_color(surface, 0.0, 0.0, 0.0, 1); |
Pekka Paalanen | 71f6f3b | 2012-10-10 12:49:26 +0300 | [diff] [blame] | 2638 | pixman_region32_fini(&surface->opaque); |
Kristian Høgsberg | 61f00f5 | 2012-08-03 16:31:36 -0400 | [diff] [blame] | 2639 | pixman_region32_init_rect(&surface->opaque, 0, 0, w, h); |
Jonas Ådahl | 33619a4 | 2013-01-15 21:25:55 +0100 | [diff] [blame] | 2640 | pixman_region32_fini(&surface->input); |
| 2641 | pixman_region32_init_rect(&surface->input, 0, 0, w, h); |
Jason Ekstrand | 918f2dd | 2013-12-02 21:01:53 -0600 | [diff] [blame] | 2642 | |
Jason Ekstrand | 6228ee2 | 2014-01-01 15:58:57 -0600 | [diff] [blame] | 2643 | weston_surface_set_size(surface, w, h); |
Jason Ekstrand | 918f2dd | 2013-12-02 21:01:53 -0600 | [diff] [blame] | 2644 | weston_view_set_position(view, x, y); |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 2645 | |
| 2646 | return view; |
Alex Wu | 4539b08 | 2012-03-01 12:57:46 +0800 | [diff] [blame] | 2647 | } |
| 2648 | |
Philip Withnall | ed8f1a9 | 2013-11-25 18:01:43 +0000 | [diff] [blame] | 2649 | static void |
| 2650 | shell_ensure_fullscreen_black_view(struct shell_surface *shsurf) |
| 2651 | { |
| 2652 | struct weston_output *output = shsurf->fullscreen_output; |
| 2653 | |
Rafael Antognolli | 03b1659 | 2013-12-03 15:35:42 -0200 | [diff] [blame] | 2654 | assert(shsurf->state.fullscreen); |
Philip Withnall | ed8f1a9 | 2013-11-25 18:01:43 +0000 | [diff] [blame] | 2655 | |
| 2656 | if (!shsurf->fullscreen.black_view) |
| 2657 | shsurf->fullscreen.black_view = |
| 2658 | create_black_surface(shsurf->surface->compositor, |
| 2659 | shsurf->surface, |
| 2660 | output->x, output->y, |
| 2661 | output->width, |
| 2662 | output->height); |
| 2663 | |
| 2664 | weston_view_geometry_dirty(shsurf->fullscreen.black_view); |
| 2665 | wl_list_remove(&shsurf->fullscreen.black_view->layer_link); |
| 2666 | wl_list_insert(&shsurf->view->layer_link, |
| 2667 | &shsurf->fullscreen.black_view->layer_link); |
| 2668 | weston_view_geometry_dirty(shsurf->fullscreen.black_view); |
| 2669 | weston_surface_damage(shsurf->surface); |
| 2670 | } |
| 2671 | |
Alex Wu | 4539b08 | 2012-03-01 12:57:46 +0800 | [diff] [blame] | 2672 | /* Create black surface and append it to the associated fullscreen surface. |
| 2673 | * Handle size dismatch and positioning according to the method. */ |
| 2674 | static void |
| 2675 | shell_configure_fullscreen(struct shell_surface *shsurf) |
| 2676 | { |
| 2677 | struct weston_output *output = shsurf->fullscreen_output; |
| 2678 | struct weston_surface *surface = shsurf->surface; |
| 2679 | struct weston_matrix *matrix; |
Kristian Høgsberg | 240dfeb | 2012-07-12 12:32:31 -0400 | [diff] [blame] | 2680 | float scale, output_aspect, surface_aspect, x, y; |
Giulio Camuffo | b836664 | 2013-04-25 13:57:46 +0300 | [diff] [blame] | 2681 | int32_t surf_x, surf_y, surf_width, surf_height; |
Alex Wu | 4539b08 | 2012-03-01 12:57:46 +0800 | [diff] [blame] | 2682 | |
Alexander Larsson | f82b6ca | 2013-05-28 16:23:39 +0200 | [diff] [blame] | 2683 | if (shsurf->fullscreen.type != WL_SHELL_SURFACE_FULLSCREEN_METHOD_DRIVER) |
| 2684 | restore_output_mode(output); |
| 2685 | |
Philip Withnall | ed8f1a9 | 2013-11-25 18:01:43 +0000 | [diff] [blame] | 2686 | shell_ensure_fullscreen_black_view(shsurf); |
Alex Wu | 4539b08 | 2012-03-01 12:57:46 +0800 | [diff] [blame] | 2687 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 2688 | surface_subsurfaces_boundingbox(shsurf->surface, &surf_x, &surf_y, |
Giulio Camuffo | b836664 | 2013-04-25 13:57:46 +0300 | [diff] [blame] | 2689 | &surf_width, &surf_height); |
| 2690 | |
Alex Wu | 4539b08 | 2012-03-01 12:57:46 +0800 | [diff] [blame] | 2691 | switch (shsurf->fullscreen.type) { |
| 2692 | case WL_SHELL_SURFACE_FULLSCREEN_METHOD_DEFAULT: |
Pekka Paalanen | de685b8 | 2012-12-04 15:58:12 +0200 | [diff] [blame] | 2693 | if (surface->buffer_ref.buffer) |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 2694 | center_on_output(shsurf->view, shsurf->fullscreen_output); |
Alex Wu | 4539b08 | 2012-03-01 12:57:46 +0800 | [diff] [blame] | 2695 | break; |
| 2696 | case WL_SHELL_SURFACE_FULLSCREEN_METHOD_SCALE: |
Rob Bradford | 9f3dd15 | 2013-02-12 11:53:47 +0000 | [diff] [blame] | 2697 | /* 1:1 mapping between surface and output dimensions */ |
Giulio Camuffo | b836664 | 2013-04-25 13:57:46 +0300 | [diff] [blame] | 2698 | if (output->width == surf_width && |
| 2699 | output->height == surf_height) { |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 2700 | weston_view_set_position(shsurf->view, |
| 2701 | output->x - surf_x, |
| 2702 | output->y - surf_y); |
Rob Bradford | 9f3dd15 | 2013-02-12 11:53:47 +0000 | [diff] [blame] | 2703 | break; |
| 2704 | } |
| 2705 | |
Alex Wu | 4539b08 | 2012-03-01 12:57:46 +0800 | [diff] [blame] | 2706 | matrix = &shsurf->fullscreen.transform.matrix; |
| 2707 | weston_matrix_init(matrix); |
Kristian Høgsberg | 240dfeb | 2012-07-12 12:32:31 -0400 | [diff] [blame] | 2708 | |
Scott Moreau | 1bad5db | 2012-08-18 01:04:05 -0600 | [diff] [blame] | 2709 | output_aspect = (float) output->width / |
| 2710 | (float) output->height; |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 2711 | /* XXX: Use surf_width and surf_height here? */ |
| 2712 | surface_aspect = (float) surface->width / |
| 2713 | (float) surface->height; |
Kristian Høgsberg | 240dfeb | 2012-07-12 12:32:31 -0400 | [diff] [blame] | 2714 | if (output_aspect < surface_aspect) |
Scott Moreau | 1bad5db | 2012-08-18 01:04:05 -0600 | [diff] [blame] | 2715 | scale = (float) output->width / |
Giulio Camuffo | b836664 | 2013-04-25 13:57:46 +0300 | [diff] [blame] | 2716 | (float) surf_width; |
Kristian Høgsberg | 240dfeb | 2012-07-12 12:32:31 -0400 | [diff] [blame] | 2717 | else |
Scott Moreau | 1bad5db | 2012-08-18 01:04:05 -0600 | [diff] [blame] | 2718 | scale = (float) output->height / |
Giulio Camuffo | b836664 | 2013-04-25 13:57:46 +0300 | [diff] [blame] | 2719 | (float) surf_height; |
Kristian Høgsberg | 240dfeb | 2012-07-12 12:32:31 -0400 | [diff] [blame] | 2720 | |
Alex Wu | 4539b08 | 2012-03-01 12:57:46 +0800 | [diff] [blame] | 2721 | weston_matrix_scale(matrix, scale, scale, 1); |
| 2722 | wl_list_remove(&shsurf->fullscreen.transform.link); |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 2723 | wl_list_insert(&shsurf->view->geometry.transformation_list, |
Alex Wu | 4539b08 | 2012-03-01 12:57:46 +0800 | [diff] [blame] | 2724 | &shsurf->fullscreen.transform.link); |
Giulio Camuffo | b836664 | 2013-04-25 13:57:46 +0300 | [diff] [blame] | 2725 | x = output->x + (output->width - surf_width * scale) / 2 - surf_x; |
| 2726 | y = output->y + (output->height - surf_height * scale) / 2 - surf_y; |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 2727 | weston_view_set_position(shsurf->view, x, y); |
Kristian Høgsberg | 240dfeb | 2012-07-12 12:32:31 -0400 | [diff] [blame] | 2728 | |
Alex Wu | 4539b08 | 2012-03-01 12:57:46 +0800 | [diff] [blame] | 2729 | break; |
| 2730 | case WL_SHELL_SURFACE_FULLSCREEN_METHOD_DRIVER: |
Alex Wu | bd3354b | 2012-04-17 17:20:49 +0800 | [diff] [blame] | 2731 | if (shell_surface_is_top_fullscreen(shsurf)) { |
Quentin Glidic | c0d79ce | 2013-01-29 14:16:13 +0100 | [diff] [blame] | 2732 | struct weston_mode mode = {0, |
Pekka Paalanen | 952b6c8 | 2014-03-14 14:38:15 +0200 | [diff] [blame] | 2733 | surf_width * surface->buffer_viewport.buffer.scale, |
| 2734 | surf_height * surface->buffer_viewport.buffer.scale, |
Alex Wu | bd3354b | 2012-04-17 17:20:49 +0800 | [diff] [blame] | 2735 | shsurf->fullscreen.framerate}; |
| 2736 | |
Pekka Paalanen | 952b6c8 | 2014-03-14 14:38:15 +0200 | [diff] [blame] | 2737 | if (weston_output_switch_mode(output, &mode, surface->buffer_viewport.buffer.scale, |
Hardening | 57388e4 | 2013-09-18 23:56:36 +0200 | [diff] [blame] | 2738 | WESTON_MODE_SWITCH_SET_TEMPORARY) == 0) { |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 2739 | weston_view_set_position(shsurf->view, |
| 2740 | output->x - surf_x, |
| 2741 | output->y - surf_y); |
Jason Ekstrand | 918f2dd | 2013-12-02 21:01:53 -0600 | [diff] [blame] | 2742 | shsurf->fullscreen.black_view->surface->width = output->width; |
| 2743 | shsurf->fullscreen.black_view->surface->height = output->height; |
| 2744 | weston_view_set_position(shsurf->fullscreen.black_view, |
| 2745 | output->x - surf_x, |
| 2746 | output->y - surf_y); |
Alex Wu | bd3354b | 2012-04-17 17:20:49 +0800 | [diff] [blame] | 2747 | break; |
Alexander Larsson | d622ed3 | 2013-05-28 16:23:40 +0200 | [diff] [blame] | 2748 | } else { |
Alexander Larsson | f82b6ca | 2013-05-28 16:23:39 +0200 | [diff] [blame] | 2749 | restore_output_mode(output); |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 2750 | center_on_output(shsurf->view, output); |
Alexander Larsson | d622ed3 | 2013-05-28 16:23:40 +0200 | [diff] [blame] | 2751 | } |
Alex Wu | bd3354b | 2012-04-17 17:20:49 +0800 | [diff] [blame] | 2752 | } |
Alex Wu | 4539b08 | 2012-03-01 12:57:46 +0800 | [diff] [blame] | 2753 | break; |
| 2754 | case WL_SHELL_SURFACE_FULLSCREEN_METHOD_FILL: |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 2755 | center_on_output(shsurf->view, output); |
Alex Wu | 4539b08 | 2012-03-01 12:57:46 +0800 | [diff] [blame] | 2756 | break; |
| 2757 | default: |
| 2758 | break; |
| 2759 | } |
| 2760 | } |
| 2761 | |
Alex Wu | 4539b08 | 2012-03-01 12:57:46 +0800 | [diff] [blame] | 2762 | static void |
| 2763 | shell_map_fullscreen(struct shell_surface *shsurf) |
| 2764 | { |
Alex Wu | bd3354b | 2012-04-17 17:20:49 +0800 | [diff] [blame] | 2765 | shell_configure_fullscreen(shsurf); |
Alex Wu | 4539b08 | 2012-03-01 12:57:46 +0800 | [diff] [blame] | 2766 | } |
| 2767 | |
Kristian Høgsberg | 7a5c979 | 2011-06-18 06:12:54 -0400 | [diff] [blame] | 2768 | static void |
Tiago Vignatti | fb2adba | 2013-06-12 15:43:21 -0300 | [diff] [blame] | 2769 | set_xwayland(struct shell_surface *shsurf, int x, int y, uint32_t flags) |
| 2770 | { |
| 2771 | /* XXX: using the same fields for transient type */ |
Rafael Antognolli | 03b1659 | 2013-12-03 15:35:42 -0200 | [diff] [blame] | 2772 | surface_clear_next_states(shsurf); |
Tiago Vignatti | fb2adba | 2013-06-12 15:43:21 -0300 | [diff] [blame] | 2773 | shsurf->transient.x = x; |
| 2774 | shsurf->transient.y = y; |
| 2775 | shsurf->transient.flags = flags; |
Philip Withnall | dc4332f | 2013-11-25 18:01:38 +0000 | [diff] [blame] | 2776 | |
| 2777 | shell_surface_set_parent(shsurf, NULL); |
| 2778 | |
Kristian Høgsberg | c8f8dd8 | 2013-12-05 23:20:33 -0800 | [diff] [blame] | 2779 | shsurf->type = SHELL_SURFACE_XWAYLAND; |
Kristian Høgsberg | 8bc525c | 2014-01-01 22:34:49 -0800 | [diff] [blame] | 2780 | shsurf->state_changed = true; |
Tiago Vignatti | fb2adba | 2013-06-12 15:43:21 -0300 | [diff] [blame] | 2781 | } |
| 2782 | |
Kristian Høgsberg | 02bbabb | 2013-05-06 22:15:05 -0400 | [diff] [blame] | 2783 | static const struct weston_pointer_grab_interface popup_grab_interface; |
Giulio Camuffo | 5085a75 | 2013-03-25 21:42:45 +0100 | [diff] [blame] | 2784 | |
| 2785 | static void |
| 2786 | destroy_shell_seat(struct wl_listener *listener, void *data) |
| 2787 | { |
| 2788 | struct shell_seat *shseat = |
| 2789 | container_of(listener, |
| 2790 | struct shell_seat, seat_destroy_listener); |
| 2791 | struct shell_surface *shsurf, *prev = NULL; |
| 2792 | |
| 2793 | if (shseat->popup_grab.grab.interface == &popup_grab_interface) { |
Kristian Høgsberg | 02bbabb | 2013-05-06 22:15:05 -0400 | [diff] [blame] | 2794 | weston_pointer_end_grab(shseat->popup_grab.grab.pointer); |
Giulio Camuffo | 5085a75 | 2013-03-25 21:42:45 +0100 | [diff] [blame] | 2795 | shseat->popup_grab.client = NULL; |
| 2796 | |
| 2797 | wl_list_for_each(shsurf, &shseat->popup_grab.surfaces_list, popup.grab_link) { |
| 2798 | shsurf->popup.shseat = NULL; |
| 2799 | if (prev) { |
| 2800 | wl_list_init(&prev->popup.grab_link); |
| 2801 | } |
| 2802 | prev = shsurf; |
| 2803 | } |
| 2804 | wl_list_init(&prev->popup.grab_link); |
| 2805 | } |
| 2806 | |
| 2807 | wl_list_remove(&shseat->seat_destroy_listener.link); |
| 2808 | free(shseat); |
| 2809 | } |
| 2810 | |
| 2811 | static struct shell_seat * |
| 2812 | create_shell_seat(struct weston_seat *seat) |
| 2813 | { |
| 2814 | struct shell_seat *shseat; |
| 2815 | |
| 2816 | shseat = calloc(1, sizeof *shseat); |
| 2817 | if (!shseat) { |
| 2818 | weston_log("no memory to allocate shell seat\n"); |
| 2819 | return NULL; |
| 2820 | } |
| 2821 | |
| 2822 | shseat->seat = seat; |
| 2823 | wl_list_init(&shseat->popup_grab.surfaces_list); |
| 2824 | |
| 2825 | shseat->seat_destroy_listener.notify = destroy_shell_seat; |
| 2826 | wl_signal_add(&seat->destroy_signal, |
| 2827 | &shseat->seat_destroy_listener); |
| 2828 | |
| 2829 | return shseat; |
| 2830 | } |
| 2831 | |
| 2832 | static struct shell_seat * |
| 2833 | get_shell_seat(struct weston_seat *seat) |
| 2834 | { |
| 2835 | struct wl_listener *listener; |
| 2836 | |
| 2837 | listener = wl_signal_get(&seat->destroy_signal, destroy_shell_seat); |
| 2838 | if (listener == NULL) |
| 2839 | return create_shell_seat(seat); |
| 2840 | |
| 2841 | return container_of(listener, |
| 2842 | struct shell_seat, seat_destroy_listener); |
| 2843 | } |
| 2844 | |
Kristian Høgsberg | b810eb5 | 2013-02-12 20:07:05 -0500 | [diff] [blame] | 2845 | static void |
Kristian Høgsberg | 6848c25 | 2013-05-08 22:02:59 -0400 | [diff] [blame] | 2846 | popup_grab_focus(struct weston_pointer_grab *grab) |
Kristian Høgsberg | b3cca0a | 2012-01-04 22:19:14 -0500 | [diff] [blame] | 2847 | { |
Kristian Høgsberg | 02bbabb | 2013-05-06 22:15:05 -0400 | [diff] [blame] | 2848 | struct weston_pointer *pointer = grab->pointer; |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 2849 | struct weston_view *view; |
Giulio Camuffo | 5085a75 | 2013-03-25 21:42:45 +0100 | [diff] [blame] | 2850 | struct shell_seat *shseat = |
| 2851 | container_of(grab, struct shell_seat, popup_grab.grab); |
| 2852 | struct wl_client *client = shseat->popup_grab.client; |
Kristian Høgsberg | 6848c25 | 2013-05-08 22:02:59 -0400 | [diff] [blame] | 2853 | wl_fixed_t sx, sy; |
| 2854 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 2855 | view = weston_compositor_pick_view(pointer->seat->compositor, |
| 2856 | pointer->x, pointer->y, |
| 2857 | &sx, &sy); |
Kristian Høgsberg | b3cca0a | 2012-01-04 22:19:14 -0500 | [diff] [blame] | 2858 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 2859 | if (view && view->surface->resource && |
| 2860 | wl_resource_get_client(view->surface->resource) == client) { |
| 2861 | weston_pointer_set_focus(pointer, view, sx, sy); |
Kristian Høgsberg | b3cca0a | 2012-01-04 22:19:14 -0500 | [diff] [blame] | 2862 | } else { |
Kristian Høgsberg | 02bbabb | 2013-05-06 22:15:05 -0400 | [diff] [blame] | 2863 | weston_pointer_set_focus(pointer, NULL, |
| 2864 | wl_fixed_from_int(0), |
| 2865 | wl_fixed_from_int(0)); |
Kristian Høgsberg | b3cca0a | 2012-01-04 22:19:14 -0500 | [diff] [blame] | 2866 | } |
| 2867 | } |
| 2868 | |
| 2869 | static void |
Giulio Camuffo | 1959ab8 | 2013-11-14 23:42:52 +0100 | [diff] [blame] | 2870 | popup_grab_motion(struct weston_pointer_grab *grab, uint32_t time, |
| 2871 | wl_fixed_t x, wl_fixed_t y) |
Kristian Høgsberg | b3cca0a | 2012-01-04 22:19:14 -0500 | [diff] [blame] | 2872 | { |
Kristian Høgsberg | be6403e | 2013-05-08 21:03:21 -0400 | [diff] [blame] | 2873 | struct weston_pointer *pointer = grab->pointer; |
Neil Roberts | 96d790e | 2013-09-19 17:32:00 +0100 | [diff] [blame] | 2874 | struct wl_resource *resource; |
Kristian Høgsberg | be6403e | 2013-05-08 21:03:21 -0400 | [diff] [blame] | 2875 | wl_fixed_t sx, sy; |
Kristian Høgsberg | b3cca0a | 2012-01-04 22:19:14 -0500 | [diff] [blame] | 2876 | |
Giulio Camuffo | 1959ab8 | 2013-11-14 23:42:52 +0100 | [diff] [blame] | 2877 | weston_pointer_move(pointer, x, y); |
| 2878 | |
Neil Roberts | 96d790e | 2013-09-19 17:32:00 +0100 | [diff] [blame] | 2879 | wl_resource_for_each(resource, &pointer->focus_resource_list) { |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 2880 | weston_view_from_global_fixed(pointer->focus, |
| 2881 | pointer->x, pointer->y, |
| 2882 | &sx, &sy); |
Neil Roberts | 96d790e | 2013-09-19 17:32:00 +0100 | [diff] [blame] | 2883 | wl_pointer_send_motion(resource, time, sx, sy); |
Kristian Høgsberg | be6403e | 2013-05-08 21:03:21 -0400 | [diff] [blame] | 2884 | } |
Kristian Høgsberg | b3cca0a | 2012-01-04 22:19:14 -0500 | [diff] [blame] | 2885 | } |
| 2886 | |
| 2887 | static void |
Kristian Høgsberg | 02bbabb | 2013-05-06 22:15:05 -0400 | [diff] [blame] | 2888 | popup_grab_button(struct weston_pointer_grab *grab, |
Daniel Stone | 4dbadb1 | 2012-05-30 16:31:51 +0100 | [diff] [blame] | 2889 | uint32_t time, uint32_t button, uint32_t state_w) |
Kristian Høgsberg | b3cca0a | 2012-01-04 22:19:14 -0500 | [diff] [blame] | 2890 | { |
| 2891 | struct wl_resource *resource; |
Giulio Camuffo | 5085a75 | 2013-03-25 21:42:45 +0100 | [diff] [blame] | 2892 | struct shell_seat *shseat = |
| 2893 | container_of(grab, struct shell_seat, popup_grab.grab); |
Rob Bradford | 880ebc7 | 2013-07-22 17:31:38 +0100 | [diff] [blame] | 2894 | struct wl_display *display = shseat->seat->compositor->wl_display; |
Daniel Stone | 4dbadb1 | 2012-05-30 16:31:51 +0100 | [diff] [blame] | 2895 | enum wl_pointer_button_state state = state_w; |
Kristian Høgsberg | eae5de7 | 2012-04-11 22:42:15 -0400 | [diff] [blame] | 2896 | uint32_t serial; |
Neil Roberts | 96d790e | 2013-09-19 17:32:00 +0100 | [diff] [blame] | 2897 | struct wl_list *resource_list; |
Kristian Høgsberg | b3cca0a | 2012-01-04 22:19:14 -0500 | [diff] [blame] | 2898 | |
Neil Roberts | 96d790e | 2013-09-19 17:32:00 +0100 | [diff] [blame] | 2899 | resource_list = &grab->pointer->focus_resource_list; |
| 2900 | if (!wl_list_empty(resource_list)) { |
Kristian Høgsberg | eae5de7 | 2012-04-11 22:42:15 -0400 | [diff] [blame] | 2901 | serial = wl_display_get_serial(display); |
Neil Roberts | 96d790e | 2013-09-19 17:32:00 +0100 | [diff] [blame] | 2902 | wl_resource_for_each(resource, resource_list) { |
| 2903 | wl_pointer_send_button(resource, serial, |
| 2904 | time, button, state); |
| 2905 | } |
Daniel Stone | 4dbadb1 | 2012-05-30 16:31:51 +0100 | [diff] [blame] | 2906 | } else if (state == WL_POINTER_BUTTON_STATE_RELEASED && |
Giulio Camuffo | 5085a75 | 2013-03-25 21:42:45 +0100 | [diff] [blame] | 2907 | (shseat->popup_grab.initial_up || |
Kristian Høgsberg | e314875 | 2013-05-06 23:19:49 -0400 | [diff] [blame] | 2908 | time - shseat->seat->pointer->grab_time > 500)) { |
Kristian Høgsberg | 57e0907 | 2012-10-30 14:07:27 -0400 | [diff] [blame] | 2909 | popup_grab_end(grab->pointer); |
Kristian Høgsberg | b3cca0a | 2012-01-04 22:19:14 -0500 | [diff] [blame] | 2910 | } |
| 2911 | |
Daniel Stone | 4dbadb1 | 2012-05-30 16:31:51 +0100 | [diff] [blame] | 2912 | if (state == WL_POINTER_BUTTON_STATE_RELEASED) |
Giulio Camuffo | 5085a75 | 2013-03-25 21:42:45 +0100 | [diff] [blame] | 2913 | shseat->popup_grab.initial_up = 1; |
Kristian Høgsberg | b3cca0a | 2012-01-04 22:19:14 -0500 | [diff] [blame] | 2914 | } |
| 2915 | |
Jonas Ådahl | 1ea343e | 2013-10-25 23:18:05 +0200 | [diff] [blame] | 2916 | static void |
| 2917 | popup_grab_cancel(struct weston_pointer_grab *grab) |
| 2918 | { |
| 2919 | popup_grab_end(grab->pointer); |
| 2920 | } |
| 2921 | |
Kristian Høgsberg | 02bbabb | 2013-05-06 22:15:05 -0400 | [diff] [blame] | 2922 | static const struct weston_pointer_grab_interface popup_grab_interface = { |
Kristian Høgsberg | b3cca0a | 2012-01-04 22:19:14 -0500 | [diff] [blame] | 2923 | popup_grab_focus, |
| 2924 | popup_grab_motion, |
| 2925 | popup_grab_button, |
Jonas Ådahl | 1ea343e | 2013-10-25 23:18:05 +0200 | [diff] [blame] | 2926 | popup_grab_cancel, |
Kristian Høgsberg | b3cca0a | 2012-01-04 22:19:14 -0500 | [diff] [blame] | 2927 | }; |
| 2928 | |
| 2929 | static void |
Rafael Antognolli | e2a3455 | 2013-12-03 15:35:45 -0200 | [diff] [blame] | 2930 | shell_surface_send_popup_done(struct shell_surface *shsurf) |
| 2931 | { |
| 2932 | if (shell_surface_is_wl_shell_surface(shsurf)) |
| 2933 | wl_shell_surface_send_popup_done(shsurf->resource); |
| 2934 | else if (shell_surface_is_xdg_popup(shsurf)) |
| 2935 | xdg_popup_send_popup_done(shsurf->resource, |
| 2936 | shsurf->popup.serial); |
| 2937 | } |
| 2938 | |
| 2939 | static void |
Kristian Høgsberg | 02bbabb | 2013-05-06 22:15:05 -0400 | [diff] [blame] | 2940 | popup_grab_end(struct weston_pointer *pointer) |
Kristian Høgsberg | 57e0907 | 2012-10-30 14:07:27 -0400 | [diff] [blame] | 2941 | { |
Kristian Høgsberg | 02bbabb | 2013-05-06 22:15:05 -0400 | [diff] [blame] | 2942 | struct weston_pointer_grab *grab = pointer->grab; |
Giulio Camuffo | 5085a75 | 2013-03-25 21:42:45 +0100 | [diff] [blame] | 2943 | struct shell_seat *shseat = |
| 2944 | container_of(grab, struct shell_seat, popup_grab.grab); |
| 2945 | struct shell_surface *shsurf; |
| 2946 | struct shell_surface *prev = NULL; |
Kristian Høgsberg | 57e0907 | 2012-10-30 14:07:27 -0400 | [diff] [blame] | 2947 | |
| 2948 | if (pointer->grab->interface == &popup_grab_interface) { |
Kristian Høgsberg | 02bbabb | 2013-05-06 22:15:05 -0400 | [diff] [blame] | 2949 | weston_pointer_end_grab(grab->pointer); |
Giulio Camuffo | 5085a75 | 2013-03-25 21:42:45 +0100 | [diff] [blame] | 2950 | shseat->popup_grab.client = NULL; |
Philipp Brüschweiler | 63e7be6 | 2013-04-15 21:09:54 +0200 | [diff] [blame] | 2951 | shseat->popup_grab.grab.interface = NULL; |
| 2952 | assert(!wl_list_empty(&shseat->popup_grab.surfaces_list)); |
Giulio Camuffo | 5085a75 | 2013-03-25 21:42:45 +0100 | [diff] [blame] | 2953 | /* Send the popup_done event to all the popups open */ |
| 2954 | 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] | 2955 | shell_surface_send_popup_done(shsurf); |
Giulio Camuffo | 5085a75 | 2013-03-25 21:42:45 +0100 | [diff] [blame] | 2956 | shsurf->popup.shseat = NULL; |
| 2957 | if (prev) { |
| 2958 | wl_list_init(&prev->popup.grab_link); |
| 2959 | } |
| 2960 | prev = shsurf; |
| 2961 | } |
| 2962 | wl_list_init(&prev->popup.grab_link); |
| 2963 | wl_list_init(&shseat->popup_grab.surfaces_list); |
| 2964 | } |
| 2965 | } |
| 2966 | |
| 2967 | static void |
| 2968 | add_popup_grab(struct shell_surface *shsurf, struct shell_seat *shseat) |
| 2969 | { |
Kristian Høgsberg | e314875 | 2013-05-06 23:19:49 -0400 | [diff] [blame] | 2970 | struct weston_seat *seat = shseat->seat; |
Giulio Camuffo | 5085a75 | 2013-03-25 21:42:45 +0100 | [diff] [blame] | 2971 | |
| 2972 | if (wl_list_empty(&shseat->popup_grab.surfaces_list)) { |
Jason Ekstrand | 651f00e | 2013-06-14 10:07:54 -0500 | [diff] [blame] | 2973 | shseat->popup_grab.client = wl_resource_get_client(shsurf->resource); |
Giulio Camuffo | 5085a75 | 2013-03-25 21:42:45 +0100 | [diff] [blame] | 2974 | shseat->popup_grab.grab.interface = &popup_grab_interface; |
Giulio Camuffo | 1b4b61a | 2013-03-27 18:05:26 +0100 | [diff] [blame] | 2975 | /* We must make sure here that this popup was opened after |
| 2976 | * a mouse press, and not just by moving around with other |
| 2977 | * popups already open. */ |
Kristian Høgsberg | e314875 | 2013-05-06 23:19:49 -0400 | [diff] [blame] | 2978 | if (shseat->seat->pointer->button_count > 0) |
Giulio Camuffo | 1b4b61a | 2013-03-27 18:05:26 +0100 | [diff] [blame] | 2979 | shseat->popup_grab.initial_up = 0; |
Giulio Camuffo | 5085a75 | 2013-03-25 21:42:45 +0100 | [diff] [blame] | 2980 | |
Rob Bradford | dfe3105 | 2013-06-26 19:49:11 +0100 | [diff] [blame] | 2981 | 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] | 2982 | weston_pointer_start_grab(seat->pointer, &shseat->popup_grab.grab); |
Rob Bradford | dfe3105 | 2013-06-26 19:49:11 +0100 | [diff] [blame] | 2983 | } else { |
| 2984 | wl_list_insert(&shseat->popup_grab.surfaces_list, &shsurf->popup.grab_link); |
Giulio Camuffo | 5085a75 | 2013-03-25 21:42:45 +0100 | [diff] [blame] | 2985 | } |
Giulio Camuffo | 5085a75 | 2013-03-25 21:42:45 +0100 | [diff] [blame] | 2986 | } |
| 2987 | |
| 2988 | static void |
| 2989 | remove_popup_grab(struct shell_surface *shsurf) |
| 2990 | { |
| 2991 | struct shell_seat *shseat = shsurf->popup.shseat; |
| 2992 | |
| 2993 | wl_list_remove(&shsurf->popup.grab_link); |
| 2994 | wl_list_init(&shsurf->popup.grab_link); |
| 2995 | if (wl_list_empty(&shseat->popup_grab.surfaces_list)) { |
Kristian Høgsberg | 02bbabb | 2013-05-06 22:15:05 -0400 | [diff] [blame] | 2996 | weston_pointer_end_grab(shseat->popup_grab.grab.pointer); |
Philipp Brüschweiler | 63e7be6 | 2013-04-15 21:09:54 +0200 | [diff] [blame] | 2997 | shseat->popup_grab.grab.interface = NULL; |
Kristian Høgsberg | 57e0907 | 2012-10-30 14:07:27 -0400 | [diff] [blame] | 2998 | } |
| 2999 | } |
| 3000 | |
| 3001 | static void |
Kristian Høgsberg | 3730f36 | 2012-04-13 12:40:07 -0400 | [diff] [blame] | 3002 | shell_map_popup(struct shell_surface *shsurf) |
Kristian Høgsberg | b3cca0a | 2012-01-04 22:19:14 -0500 | [diff] [blame] | 3003 | { |
Giulio Camuffo | 5085a75 | 2013-03-25 21:42:45 +0100 | [diff] [blame] | 3004 | struct shell_seat *shseat = shsurf->popup.shseat; |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 3005 | struct weston_view *parent_view = get_default_view(shsurf->parent); |
Kristian Høgsberg | b3cca0a | 2012-01-04 22:19:14 -0500 | [diff] [blame] | 3006 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 3007 | shsurf->surface->output = parent_view->output; |
| 3008 | shsurf->view->output = parent_view->output; |
Kristian Høgsberg | b3cca0a | 2012-01-04 22:19:14 -0500 | [diff] [blame] | 3009 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 3010 | weston_view_set_transform_parent(shsurf->view, parent_view); |
| 3011 | weston_view_set_position(shsurf->view, shsurf->popup.x, shsurf->popup.y); |
| 3012 | weston_view_update_transform(shsurf->view); |
Kristian Høgsberg | b3cca0a | 2012-01-04 22:19:14 -0500 | [diff] [blame] | 3013 | |
Kristian Høgsberg | e314875 | 2013-05-06 23:19:49 -0400 | [diff] [blame] | 3014 | if (shseat->seat->pointer->grab_serial == shsurf->popup.serial) { |
Giulio Camuffo | 5085a75 | 2013-03-25 21:42:45 +0100 | [diff] [blame] | 3015 | add_popup_grab(shsurf, shseat); |
Kristian Høgsberg | 3730f36 | 2012-04-13 12:40:07 -0400 | [diff] [blame] | 3016 | } else { |
Rafael Antognolli | e2a3455 | 2013-12-03 15:35:45 -0200 | [diff] [blame] | 3017 | shell_surface_send_popup_done(shsurf); |
Giulio Camuffo | 5085a75 | 2013-03-25 21:42:45 +0100 | [diff] [blame] | 3018 | shseat->popup_grab.client = NULL; |
Kristian Høgsberg | 3730f36 | 2012-04-13 12:40:07 -0400 | [diff] [blame] | 3019 | } |
Kristian Høgsberg | b3cca0a | 2012-01-04 22:19:14 -0500 | [diff] [blame] | 3020 | } |
| 3021 | |
Pekka Paalanen | 9d1613e | 2011-11-25 12:09:16 +0200 | [diff] [blame] | 3022 | static const struct wl_shell_surface_interface shell_surface_implementation = { |
Scott Moreau | ff1db4a | 2012-04-17 19:06:18 -0600 | [diff] [blame] | 3023 | shell_surface_pong, |
Pekka Paalanen | 9d1613e | 2011-11-25 12:09:16 +0200 | [diff] [blame] | 3024 | shell_surface_move, |
| 3025 | shell_surface_resize, |
| 3026 | shell_surface_set_toplevel, |
| 3027 | shell_surface_set_transient, |
Kristian Høgsberg | b3cca0a | 2012-01-04 22:19:14 -0500 | [diff] [blame] | 3028 | shell_surface_set_fullscreen, |
Juan Zhao | 96879df | 2012-02-07 08:45:41 +0800 | [diff] [blame] | 3029 | shell_surface_set_popup, |
Kristian Høgsberg | e7afd91 | 2012-05-02 09:47:44 -0400 | [diff] [blame] | 3030 | shell_surface_set_maximized, |
| 3031 | shell_surface_set_title, |
| 3032 | shell_surface_set_class |
Pekka Paalanen | 9d1613e | 2011-11-25 12:09:16 +0200 | [diff] [blame] | 3033 | }; |
| 3034 | |
| 3035 | static void |
Tiago Vignatti | bc052c9 | 2012-04-19 16:18:18 +0300 | [diff] [blame] | 3036 | destroy_shell_surface(struct shell_surface *shsurf) |
Pekka Paalanen | 9d1613e | 2011-11-25 12:09:16 +0200 | [diff] [blame] | 3037 | { |
Kristian Høgsberg | 9046d24 | 2014-01-10 00:25:30 -0800 | [diff] [blame] | 3038 | struct shell_surface *child, *next; |
| 3039 | |
Jason Ekstrand | 651f00e | 2013-06-14 10:07:54 -0500 | [diff] [blame] | 3040 | wl_signal_emit(&shsurf->destroy_signal, shsurf); |
| 3041 | |
Giulio Camuffo | 5085a75 | 2013-03-25 21:42:45 +0100 | [diff] [blame] | 3042 | if (!wl_list_empty(&shsurf->popup.grab_link)) { |
| 3043 | remove_popup_grab(shsurf); |
| 3044 | } |
Kristian Høgsberg | b3cca0a | 2012-01-04 22:19:14 -0500 | [diff] [blame] | 3045 | |
Alex Wu | bd3354b | 2012-04-17 17:20:49 +0800 | [diff] [blame] | 3046 | if (shsurf->fullscreen.type == WL_SHELL_SURFACE_FULLSCREEN_METHOD_DRIVER && |
Alexander Larsson | f82b6ca | 2013-05-28 16:23:39 +0200 | [diff] [blame] | 3047 | shell_surface_is_top_fullscreen(shsurf)) |
| 3048 | restore_output_mode (shsurf->fullscreen_output); |
Pekka Paalanen | 9d1613e | 2011-11-25 12:09:16 +0200 | [diff] [blame] | 3049 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 3050 | if (shsurf->fullscreen.black_view) |
| 3051 | weston_surface_destroy(shsurf->fullscreen.black_view->surface); |
Alex Wu | aa08e2d | 2012-03-05 11:01:40 +0800 | [diff] [blame] | 3052 | |
Alex Wu | bd3354b | 2012-04-17 17:20:49 +0800 | [diff] [blame] | 3053 | /* As destroy_resource() use wl_list_for_each_safe(), |
| 3054 | * we can always remove the listener. |
| 3055 | */ |
| 3056 | wl_list_remove(&shsurf->surface_destroy_listener.link); |
| 3057 | shsurf->surface->configure = NULL; |
Scott Moreau | 976a050 | 2013-03-07 10:15:17 -0700 | [diff] [blame] | 3058 | free(shsurf->title); |
Alex Wu | bd3354b | 2012-04-17 17:20:49 +0800 | [diff] [blame] | 3059 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 3060 | weston_view_destroy(shsurf->view); |
| 3061 | |
Philip Withnall | 648a4dd | 2013-11-25 18:01:44 +0000 | [diff] [blame] | 3062 | wl_list_remove(&shsurf->children_link); |
Emilio Pozuelo Monfort | adaa20c | 2014-01-28 13:54:16 +0100 | [diff] [blame] | 3063 | wl_list_for_each_safe(child, next, &shsurf->children_list, children_link) |
| 3064 | shell_surface_set_parent(child, NULL); |
Philip Withnall | 648a4dd | 2013-11-25 18:01:44 +0000 | [diff] [blame] | 3065 | |
Pekka Paalanen | 9d1613e | 2011-11-25 12:09:16 +0200 | [diff] [blame] | 3066 | wl_list_remove(&shsurf->link); |
| 3067 | free(shsurf); |
| 3068 | } |
| 3069 | |
| 3070 | static void |
Tiago Vignatti | bc052c9 | 2012-04-19 16:18:18 +0300 | [diff] [blame] | 3071 | shell_destroy_shell_surface(struct wl_resource *resource) |
| 3072 | { |
Jason Ekstrand | 651f00e | 2013-06-14 10:07:54 -0500 | [diff] [blame] | 3073 | struct shell_surface *shsurf = wl_resource_get_user_data(resource); |
Tiago Vignatti | bc052c9 | 2012-04-19 16:18:18 +0300 | [diff] [blame] | 3074 | |
Bryan Cain | a46b946 | 2014-04-04 17:41:24 -0500 | [diff] [blame] | 3075 | if (!wl_list_empty(&shsurf->popup.grab_link)) |
| 3076 | remove_popup_grab(shsurf); |
Kristian Høgsberg | 160fe75 | 2014-03-11 10:19:10 -0700 | [diff] [blame] | 3077 | shsurf->resource = NULL; |
Tiago Vignatti | bc052c9 | 2012-04-19 16:18:18 +0300 | [diff] [blame] | 3078 | } |
| 3079 | |
| 3080 | static void |
Kristian Høgsberg | 27e3052 | 2012-04-11 23:18:23 -0400 | [diff] [blame] | 3081 | shell_handle_surface_destroy(struct wl_listener *listener, void *data) |
Pekka Paalanen | 9d1613e | 2011-11-25 12:09:16 +0200 | [diff] [blame] | 3082 | { |
| 3083 | struct shell_surface *shsurf = container_of(listener, |
| 3084 | struct shell_surface, |
| 3085 | surface_destroy_listener); |
| 3086 | |
Jason Ekstrand | 651f00e | 2013-06-14 10:07:54 -0500 | [diff] [blame] | 3087 | if (shsurf->resource) |
| 3088 | wl_resource_destroy(shsurf->resource); |
Ander Conselvan de Oliveira | 15f9a26 | 2014-04-29 17:54:02 +0300 | [diff] [blame] | 3089 | |
| 3090 | destroy_shell_surface(shsurf); |
Pekka Paalanen | 9d1613e | 2011-11-25 12:09:16 +0200 | [diff] [blame] | 3091 | } |
| 3092 | |
Kristian Høgsberg | d813445 | 2012-06-21 12:49:02 -0400 | [diff] [blame] | 3093 | static void |
Kristian Høgsberg | 160fe75 | 2014-03-11 10:19:10 -0700 | [diff] [blame] | 3094 | fade_out_done(struct weston_view_animation *animation, void *data) |
| 3095 | { |
| 3096 | struct shell_surface *shsurf = data; |
| 3097 | |
| 3098 | weston_surface_destroy(shsurf->surface); |
| 3099 | } |
| 3100 | |
| 3101 | static void |
| 3102 | handle_resource_destroy(struct wl_listener *listener, void *data) |
| 3103 | { |
| 3104 | struct shell_surface *shsurf = |
| 3105 | container_of(listener, struct shell_surface, |
| 3106 | resource_destroy_listener); |
| 3107 | |
Ander Conselvan de Oliveira | 15f9a26 | 2014-04-29 17:54:02 +0300 | [diff] [blame] | 3108 | if (!weston_surface_is_mapped(shsurf->surface)) |
| 3109 | return; |
| 3110 | |
Kristian Høgsberg | 160fe75 | 2014-03-11 10:19:10 -0700 | [diff] [blame] | 3111 | shsurf->surface->ref_count++; |
| 3112 | |
| 3113 | pixman_region32_fini(&shsurf->surface->pending.input); |
| 3114 | pixman_region32_init(&shsurf->surface->pending.input); |
| 3115 | pixman_region32_fini(&shsurf->surface->input); |
| 3116 | pixman_region32_init(&shsurf->surface->input); |
Ander Conselvan de Oliveira | 15f9a26 | 2014-04-29 17:54:02 +0300 | [diff] [blame] | 3117 | weston_fade_run(shsurf->view, 1.0, 0.0, 300.0, |
| 3118 | fade_out_done, shsurf); |
Kristian Høgsberg | 160fe75 | 2014-03-11 10:19:10 -0700 | [diff] [blame] | 3119 | } |
| 3120 | |
| 3121 | static void |
Jason Ekstrand | 918f2dd | 2013-12-02 21:01:53 -0600 | [diff] [blame] | 3122 | shell_surface_configure(struct weston_surface *, int32_t, int32_t); |
Kristian Høgsberg | d813445 | 2012-06-21 12:49:02 -0400 | [diff] [blame] | 3123 | |
Kristian Høgsberg | 1ef2313 | 2013-12-04 00:20:01 -0800 | [diff] [blame] | 3124 | struct shell_surface * |
Kristian Høgsberg | 8334bc1 | 2012-01-03 10:29:47 -0500 | [diff] [blame] | 3125 | get_shell_surface(struct weston_surface *surface) |
Pekka Paalanen | ec2b32f | 2011-11-28 15:12:34 +0200 | [diff] [blame] | 3126 | { |
Kristian Høgsberg | d813445 | 2012-06-21 12:49:02 -0400 | [diff] [blame] | 3127 | if (surface->configure == shell_surface_configure) |
Giulio Camuffo | 7fe01b1 | 2013-03-28 18:02:42 +0100 | [diff] [blame] | 3128 | return surface->configure_private; |
Kristian Høgsberg | d813445 | 2012-06-21 12:49:02 -0400 | [diff] [blame] | 3129 | else |
| 3130 | return NULL; |
Pekka Paalanen | ec2b32f | 2011-11-28 15:12:34 +0200 | [diff] [blame] | 3131 | } |
| 3132 | |
Rafael Antognolli | e2a3455 | 2013-12-03 15:35:45 -0200 | [diff] [blame] | 3133 | static struct shell_surface * |
Jason Ekstrand | 9e9512f | 2014-04-16 21:12:10 -0500 | [diff] [blame] | 3134 | create_common_surface(struct shell_client *owner, void *shell, |
| 3135 | struct weston_surface *surface, |
Rafael Antognolli | e2a3455 | 2013-12-03 15:35:45 -0200 | [diff] [blame] | 3136 | const struct weston_shell_client *client) |
Pekka Paalanen | 9d1613e | 2011-11-25 12:09:16 +0200 | [diff] [blame] | 3137 | { |
Pekka Paalanen | 9d1613e | 2011-11-25 12:09:16 +0200 | [diff] [blame] | 3138 | struct shell_surface *shsurf; |
| 3139 | |
Ander Conselvan de Oliveira | 093bfa3 | 2012-03-27 17:36:41 +0300 | [diff] [blame] | 3140 | if (surface->configure) { |
Martin Minarik | 6d11836 | 2012-06-07 18:01:59 +0200 | [diff] [blame] | 3141 | weston_log("surface->configure already set\n"); |
Kristian Høgsberg | 45ba869 | 2012-05-21 14:27:33 -0400 | [diff] [blame] | 3142 | return NULL; |
Ander Conselvan de Oliveira | 093bfa3 | 2012-03-27 17:36:41 +0300 | [diff] [blame] | 3143 | } |
| 3144 | |
Pekka Paalanen | 9d1613e | 2011-11-25 12:09:16 +0200 | [diff] [blame] | 3145 | shsurf = calloc(1, sizeof *shsurf); |
| 3146 | if (!shsurf) { |
Martin Minarik | 6d11836 | 2012-06-07 18:01:59 +0200 | [diff] [blame] | 3147 | weston_log("no memory to allocate shell surface\n"); |
Kristian Høgsberg | 45ba869 | 2012-05-21 14:27:33 -0400 | [diff] [blame] | 3148 | return NULL; |
Pekka Paalanen | 9d1613e | 2011-11-25 12:09:16 +0200 | [diff] [blame] | 3149 | } |
| 3150 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 3151 | shsurf->view = weston_view_create(surface); |
| 3152 | if (!shsurf->view) { |
| 3153 | weston_log("no memory to allocate shell surface\n"); |
| 3154 | free(shsurf); |
| 3155 | return NULL; |
| 3156 | } |
| 3157 | |
Ander Conselvan de Oliveira | 093bfa3 | 2012-03-27 17:36:41 +0300 | [diff] [blame] | 3158 | surface->configure = shell_surface_configure; |
Giulio Camuffo | 7fe01b1 | 2013-03-28 18:02:42 +0100 | [diff] [blame] | 3159 | surface->configure_private = shsurf; |
Ander Conselvan de Oliveira | 093bfa3 | 2012-03-27 17:36:41 +0300 | [diff] [blame] | 3160 | |
Kristian Høgsberg | 160fe75 | 2014-03-11 10:19:10 -0700 | [diff] [blame] | 3161 | shsurf->resource_destroy_listener.notify = handle_resource_destroy; |
| 3162 | wl_resource_add_destroy_listener(surface->resource, |
| 3163 | &shsurf->resource_destroy_listener); |
Jason Ekstrand | 9e9512f | 2014-04-16 21:12:10 -0500 | [diff] [blame] | 3164 | shsurf->owner = owner; |
Kristian Høgsberg | 160fe75 | 2014-03-11 10:19:10 -0700 | [diff] [blame] | 3165 | |
Tiago Vignatti | bc052c9 | 2012-04-19 16:18:18 +0300 | [diff] [blame] | 3166 | shsurf->shell = (struct desktop_shell *) shell; |
Scott Moreau | ff1db4a | 2012-04-17 19:06:18 -0600 | [diff] [blame] | 3167 | shsurf->unresponsive = 0; |
Alex Wu | 4539b08 | 2012-03-01 12:57:46 +0800 | [diff] [blame] | 3168 | shsurf->saved_position_valid = false; |
Rafael Antognolli | 3c4e3f7 | 2013-12-03 15:35:46 -0200 | [diff] [blame] | 3169 | shsurf->saved_size_valid = false; |
Alex Wu | 7bcb8bd | 2012-04-27 09:07:24 +0800 | [diff] [blame] | 3170 | shsurf->saved_rotation_valid = false; |
Pekka Paalanen | 9d1613e | 2011-11-25 12:09:16 +0200 | [diff] [blame] | 3171 | shsurf->surface = surface; |
Alex Wu | 4539b08 | 2012-03-01 12:57:46 +0800 | [diff] [blame] | 3172 | shsurf->fullscreen.type = WL_SHELL_SURFACE_FULLSCREEN_METHOD_DEFAULT; |
| 3173 | shsurf->fullscreen.framerate = 0; |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 3174 | shsurf->fullscreen.black_view = NULL; |
Alex Wu | 4539b08 | 2012-03-01 12:57:46 +0800 | [diff] [blame] | 3175 | wl_list_init(&shsurf->fullscreen.transform.link); |
| 3176 | |
Jason Ekstrand | 651f00e | 2013-06-14 10:07:54 -0500 | [diff] [blame] | 3177 | wl_signal_init(&shsurf->destroy_signal); |
Kristian Høgsberg | 27e3052 | 2012-04-11 23:18:23 -0400 | [diff] [blame] | 3178 | shsurf->surface_destroy_listener.notify = shell_handle_surface_destroy; |
Jason Ekstrand | 26ed73c | 2013-06-06 22:34:41 -0500 | [diff] [blame] | 3179 | wl_signal_add(&surface->destroy_signal, |
Kristian Høgsberg | 27e3052 | 2012-04-11 23:18:23 -0400 | [diff] [blame] | 3180 | &shsurf->surface_destroy_listener); |
Pekka Paalanen | 9d1613e | 2011-11-25 12:09:16 +0200 | [diff] [blame] | 3181 | |
| 3182 | /* init link so its safe to always remove it in destroy_shell_surface */ |
| 3183 | wl_list_init(&shsurf->link); |
Giulio Camuffo | 5085a75 | 2013-03-25 21:42:45 +0100 | [diff] [blame] | 3184 | wl_list_init(&shsurf->popup.grab_link); |
Pekka Paalanen | 9d1613e | 2011-11-25 12:09:16 +0200 | [diff] [blame] | 3185 | |
Pekka Paalanen | 460099f | 2012-01-20 16:48:25 +0200 | [diff] [blame] | 3186 | /* empty when not in use */ |
| 3187 | wl_list_init(&shsurf->rotation.transform.link); |
Kristian Høgsberg | 765e27b | 2012-01-27 13:36:13 -0500 | [diff] [blame] | 3188 | weston_matrix_init(&shsurf->rotation.rotation); |
Pekka Paalanen | 460099f | 2012-01-20 16:48:25 +0200 | [diff] [blame] | 3189 | |
Jonas Ådahl | 62fcd04 | 2012-06-13 00:01:23 +0200 | [diff] [blame] | 3190 | wl_list_init(&shsurf->workspace_transform.link); |
| 3191 | |
Philip Withnall | 648a4dd | 2013-11-25 18:01:44 +0000 | [diff] [blame] | 3192 | wl_list_init(&shsurf->children_link); |
| 3193 | wl_list_init(&shsurf->children_list); |
| 3194 | shsurf->parent = NULL; |
| 3195 | |
Pekka Paalanen | 9826223 | 2011-12-01 10:42:22 +0200 | [diff] [blame] | 3196 | shsurf->type = SHELL_SURFACE_NONE; |
Pekka Paalanen | 9d1613e | 2011-11-25 12:09:16 +0200 | [diff] [blame] | 3197 | |
Kristian Høgsberg | a61ca06 | 2012-05-22 16:05:52 -0400 | [diff] [blame] | 3198 | shsurf->client = client; |
| 3199 | |
Kristian Høgsberg | 45ba869 | 2012-05-21 14:27:33 -0400 | [diff] [blame] | 3200 | return shsurf; |
Tiago Vignatti | bc052c9 | 2012-04-19 16:18:18 +0300 | [diff] [blame] | 3201 | } |
| 3202 | |
Rafael Antognolli | e2a3455 | 2013-12-03 15:35:45 -0200 | [diff] [blame] | 3203 | static struct shell_surface * |
| 3204 | create_shell_surface(void *shell, struct weston_surface *surface, |
| 3205 | const struct weston_shell_client *client) |
| 3206 | { |
Jason Ekstrand | 9e9512f | 2014-04-16 21:12:10 -0500 | [diff] [blame] | 3207 | return create_common_surface(NULL, shell, surface, client); |
Rafael Antognolli | e2a3455 | 2013-12-03 15:35:45 -0200 | [diff] [blame] | 3208 | } |
| 3209 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 3210 | static struct weston_view * |
| 3211 | get_primary_view(void *shell, struct shell_surface *shsurf) |
| 3212 | { |
| 3213 | return shsurf->view; |
| 3214 | } |
| 3215 | |
Tiago Vignatti | bc052c9 | 2012-04-19 16:18:18 +0300 | [diff] [blame] | 3216 | static void |
| 3217 | shell_get_shell_surface(struct wl_client *client, |
| 3218 | struct wl_resource *resource, |
| 3219 | uint32_t id, |
| 3220 | struct wl_resource *surface_resource) |
| 3221 | { |
Jason Ekstrand | 0f2ef7e | 2013-06-14 10:07:53 -0500 | [diff] [blame] | 3222 | struct weston_surface *surface = |
| 3223 | wl_resource_get_user_data(surface_resource); |
Jason Ekstrand | 9e9512f | 2014-04-16 21:12:10 -0500 | [diff] [blame] | 3224 | struct shell_client *sc = wl_resource_get_user_data(resource); |
| 3225 | struct desktop_shell *shell = sc->shell; |
Tiago Vignatti | bc052c9 | 2012-04-19 16:18:18 +0300 | [diff] [blame] | 3226 | struct shell_surface *shsurf; |
| 3227 | |
| 3228 | if (get_shell_surface(surface)) { |
| 3229 | wl_resource_post_error(surface_resource, |
Kristian Høgsberg | 9540ea6 | 2012-05-21 14:28:57 -0400 | [diff] [blame] | 3230 | WL_DISPLAY_ERROR_INVALID_OBJECT, |
| 3231 | "desktop_shell::get_shell_surface already requested"); |
Tiago Vignatti | bc052c9 | 2012-04-19 16:18:18 +0300 | [diff] [blame] | 3232 | return; |
| 3233 | } |
| 3234 | |
Jason Ekstrand | 9e9512f | 2014-04-16 21:12:10 -0500 | [diff] [blame] | 3235 | shsurf = create_common_surface(sc, shell, surface, &shell_client); |
Kristian Høgsberg | 9540ea6 | 2012-05-21 14:28:57 -0400 | [diff] [blame] | 3236 | if (!shsurf) { |
| 3237 | wl_resource_post_error(surface_resource, |
| 3238 | WL_DISPLAY_ERROR_INVALID_OBJECT, |
| 3239 | "surface->configure already set"); |
| 3240 | return; |
| 3241 | } |
Tiago Vignatti | bc052c9 | 2012-04-19 16:18:18 +0300 | [diff] [blame] | 3242 | |
Jason Ekstrand | a85118c | 2013-06-27 20:17:02 -0500 | [diff] [blame] | 3243 | shsurf->resource = |
| 3244 | wl_resource_create(client, |
| 3245 | &wl_shell_surface_interface, 1, id); |
| 3246 | wl_resource_set_implementation(shsurf->resource, |
| 3247 | &shell_surface_implementation, |
| 3248 | shsurf, shell_destroy_shell_surface); |
Pekka Paalanen | 9d1613e | 2011-11-25 12:09:16 +0200 | [diff] [blame] | 3249 | } |
| 3250 | |
Rafael Antognolli | e2a3455 | 2013-12-03 15:35:45 -0200 | [diff] [blame] | 3251 | static bool |
| 3252 | shell_surface_is_wl_shell_surface(struct shell_surface *shsurf) |
| 3253 | { |
Kristian Høgsberg | 0b7d995 | 2014-02-03 15:50:38 -0800 | [diff] [blame] | 3254 | /* A shell surface without a resource is created from xwayland |
| 3255 | * and is considered a wl_shell surface for now. */ |
| 3256 | |
| 3257 | return shsurf->resource == NULL || |
| 3258 | wl_resource_instance_of(shsurf->resource, |
| 3259 | &wl_shell_surface_interface, |
| 3260 | &shell_surface_implementation); |
Rafael Antognolli | e2a3455 | 2013-12-03 15:35:45 -0200 | [diff] [blame] | 3261 | } |
| 3262 | |
Pekka Paalanen | 9d1613e | 2011-11-25 12:09:16 +0200 | [diff] [blame] | 3263 | static const struct wl_shell_interface shell_implementation = { |
Pekka Paalanen | 4622967 | 2011-11-29 15:49:31 +0200 | [diff] [blame] | 3264 | shell_get_shell_surface |
Kristian Høgsberg | 4cca349 | 2011-01-18 07:53:49 -0500 | [diff] [blame] | 3265 | }; |
| 3266 | |
Rafael Antognolli | e2a3455 | 2013-12-03 15:35:45 -0200 | [diff] [blame] | 3267 | /**************************** |
| 3268 | * xdg-shell implementation */ |
| 3269 | |
| 3270 | static void |
| 3271 | xdg_surface_destroy(struct wl_client *client, |
| 3272 | struct wl_resource *resource) |
| 3273 | { |
| 3274 | wl_resource_destroy(resource); |
| 3275 | } |
| 3276 | |
| 3277 | static void |
Jasper St. Pierre | 63a9c33 | 2014-02-01 18:35:15 -0500 | [diff] [blame] | 3278 | xdg_surface_set_transient_for(struct wl_client *client, |
| 3279 | struct wl_resource *resource, |
| 3280 | struct wl_resource *parent_resource) |
| 3281 | { |
| 3282 | struct shell_surface *shsurf = wl_resource_get_user_data(resource); |
| 3283 | struct weston_surface *parent; |
| 3284 | |
| 3285 | if (parent_resource) |
| 3286 | parent = wl_resource_get_user_data(parent_resource); |
| 3287 | else |
| 3288 | parent = NULL; |
| 3289 | |
| 3290 | shell_surface_set_parent(shsurf, parent); |
| 3291 | } |
| 3292 | |
| 3293 | static void |
Jasper St. Pierre | 7407345 | 2014-02-01 18:36:41 -0500 | [diff] [blame] | 3294 | xdg_surface_set_margin(struct wl_client *client, |
| 3295 | struct wl_resource *resource, |
| 3296 | int32_t left, |
| 3297 | int32_t right, |
| 3298 | int32_t top, |
| 3299 | int32_t bottom) |
| 3300 | { |
| 3301 | /* Do nothing, Weston doesn't try to constrain or place |
| 3302 | * surfaces in any special manner... */ |
| 3303 | } |
| 3304 | |
| 3305 | static void |
Rafael Antognolli | e2a3455 | 2013-12-03 15:35:45 -0200 | [diff] [blame] | 3306 | xdg_surface_set_app_id(struct wl_client *client, |
| 3307 | struct wl_resource *resource, |
| 3308 | const char *app_id) |
| 3309 | { |
| 3310 | struct shell_surface *shsurf = wl_resource_get_user_data(resource); |
| 3311 | |
| 3312 | free(shsurf->class); |
| 3313 | shsurf->class = strdup(app_id); |
| 3314 | } |
| 3315 | |
| 3316 | static void |
| 3317 | xdg_surface_set_title(struct wl_client *client, |
| 3318 | struct wl_resource *resource, const char *title) |
| 3319 | { |
| 3320 | struct shell_surface *shsurf = wl_resource_get_user_data(resource); |
| 3321 | |
| 3322 | set_title(shsurf, title); |
| 3323 | } |
| 3324 | |
| 3325 | static void |
| 3326 | xdg_surface_move(struct wl_client *client, struct wl_resource *resource, |
| 3327 | struct wl_resource *seat_resource, uint32_t serial) |
| 3328 | { |
| 3329 | common_surface_move(resource, seat_resource, serial); |
| 3330 | } |
| 3331 | |
| 3332 | static void |
| 3333 | xdg_surface_resize(struct wl_client *client, struct wl_resource *resource, |
| 3334 | struct wl_resource *seat_resource, uint32_t serial, |
| 3335 | uint32_t edges) |
| 3336 | { |
| 3337 | common_surface_resize(resource, seat_resource, serial, edges); |
| 3338 | } |
| 3339 | |
| 3340 | static void |
| 3341 | xdg_surface_set_output(struct wl_client *client, |
| 3342 | struct wl_resource *resource, |
| 3343 | struct wl_resource *output_resource) |
| 3344 | { |
| 3345 | struct shell_surface *shsurf = wl_resource_get_user_data(resource); |
| 3346 | struct weston_output *output; |
| 3347 | |
| 3348 | if (output_resource) |
| 3349 | output = wl_resource_get_user_data(output_resource); |
| 3350 | else |
| 3351 | output = NULL; |
| 3352 | |
Rafael Antognolli | 65f98d8 | 2013-12-03 15:35:47 -0200 | [diff] [blame] | 3353 | shsurf->recommended_output = output; |
Rafael Antognolli | e2a3455 | 2013-12-03 15:35:45 -0200 | [diff] [blame] | 3354 | } |
| 3355 | |
| 3356 | static void |
Kristian Høgsberg | 283bf37 | 2014-02-18 23:28:09 -0800 | [diff] [blame] | 3357 | xdg_surface_change_state(struct shell_surface *shsurf, |
| 3358 | uint32_t state, uint32_t value, uint32_t serial) |
Rafael Antognolli | e2a3455 | 2013-12-03 15:35:45 -0200 | [diff] [blame] | 3359 | { |
Kristian Høgsberg | 283bf37 | 2014-02-18 23:28:09 -0800 | [diff] [blame] | 3360 | xdg_surface_send_change_state(shsurf->resource, state, value, serial); |
Jasper St. Pierre | 8c6aa45 | 2014-02-08 18:29:49 -0500 | [diff] [blame] | 3361 | shsurf->state_requested = true; |
Rafael Antognolli | e2a3455 | 2013-12-03 15:35:45 -0200 | [diff] [blame] | 3362 | |
Kristian Høgsberg | 283bf37 | 2014-02-18 23:28:09 -0800 | [diff] [blame] | 3363 | switch (state) { |
| 3364 | case XDG_SURFACE_STATE_MAXIMIZED: |
| 3365 | shsurf->requested_state.maximized = value; |
| 3366 | if (value) |
| 3367 | set_maximized(shsurf, NULL); |
| 3368 | break; |
| 3369 | case XDG_SURFACE_STATE_FULLSCREEN: |
| 3370 | shsurf->requested_state.fullscreen = value; |
Rafael Antognolli | e2a3455 | 2013-12-03 15:35:45 -0200 | [diff] [blame] | 3371 | |
Kristian Høgsberg | 283bf37 | 2014-02-18 23:28:09 -0800 | [diff] [blame] | 3372 | if (value) |
| 3373 | set_fullscreen(shsurf, |
| 3374 | WL_SHELL_SURFACE_FULLSCREEN_METHOD_DEFAULT, |
| 3375 | 0, shsurf->recommended_output); |
| 3376 | break; |
| 3377 | } |
Jasper St. Pierre | 8c6aa45 | 2014-02-08 18:29:49 -0500 | [diff] [blame] | 3378 | } |
| 3379 | |
| 3380 | static void |
| 3381 | xdg_surface_request_change_state(struct wl_client *client, |
| 3382 | struct wl_resource *resource, |
| 3383 | uint32_t state, |
| 3384 | uint32_t value, |
| 3385 | uint32_t serial) |
Rafael Antognolli | e2a3455 | 2013-12-03 15:35:45 -0200 | [diff] [blame] | 3386 | { |
| 3387 | struct shell_surface *shsurf = wl_resource_get_user_data(resource); |
Jasper St. Pierre | 8c6aa45 | 2014-02-08 18:29:49 -0500 | [diff] [blame] | 3388 | |
| 3389 | /* The client can't know what the current state is, so we need |
| 3390 | to always send a state change in response. */ |
Rafael Antognolli | e2a3455 | 2013-12-03 15:35:45 -0200 | [diff] [blame] | 3391 | |
| 3392 | if (shsurf->type != SHELL_SURFACE_TOPLEVEL) |
| 3393 | return; |
| 3394 | |
Jasper St. Pierre | 8c6aa45 | 2014-02-08 18:29:49 -0500 | [diff] [blame] | 3395 | switch (state) { |
| 3396 | case XDG_SURFACE_STATE_MAXIMIZED: |
Jasper St. Pierre | 8c6aa45 | 2014-02-08 18:29:49 -0500 | [diff] [blame] | 3397 | case XDG_SURFACE_STATE_FULLSCREEN: |
Jasper St. Pierre | 8c6aa45 | 2014-02-08 18:29:49 -0500 | [diff] [blame] | 3398 | break; |
Kristian Høgsberg | 283bf37 | 2014-02-18 23:28:09 -0800 | [diff] [blame] | 3399 | default: |
| 3400 | /* send error? ignore? send change state with value 0? */ |
| 3401 | return; |
Rafael Antognolli | 3c4e3f7 | 2013-12-03 15:35:46 -0200 | [diff] [blame] | 3402 | } |
Kristian Høgsberg | 283bf37 | 2014-02-18 23:28:09 -0800 | [diff] [blame] | 3403 | |
| 3404 | xdg_surface_change_state(shsurf, state, value, serial); |
Rafael Antognolli | e2a3455 | 2013-12-03 15:35:45 -0200 | [diff] [blame] | 3405 | } |
| 3406 | |
| 3407 | static void |
Jasper St. Pierre | 8c6aa45 | 2014-02-08 18:29:49 -0500 | [diff] [blame] | 3408 | xdg_surface_ack_change_state(struct wl_client *client, |
| 3409 | struct wl_resource *resource, |
| 3410 | uint32_t state, |
| 3411 | uint32_t value, |
| 3412 | uint32_t serial) |
Rafael Antognolli | e2a3455 | 2013-12-03 15:35:45 -0200 | [diff] [blame] | 3413 | { |
| 3414 | struct shell_surface *shsurf = wl_resource_get_user_data(resource); |
| 3415 | |
Jasper St. Pierre | 8c6aa45 | 2014-02-08 18:29:49 -0500 | [diff] [blame] | 3416 | if (shsurf->state_requested) { |
| 3417 | shsurf->next_state = shsurf->requested_state; |
| 3418 | shsurf->state_changed = true; |
| 3419 | shsurf->state_requested = false; |
Rafael Antognolli | 3c4e3f7 | 2013-12-03 15:35:46 -0200 | [diff] [blame] | 3420 | } |
Rafael Antognolli | e2a3455 | 2013-12-03 15:35:45 -0200 | [diff] [blame] | 3421 | } |
| 3422 | |
Manuel Bachmann | 50c87db | 2014-02-26 15:52:13 +0100 | [diff] [blame] | 3423 | static void |
| 3424 | xdg_surface_set_minimized(struct wl_client *client, |
| 3425 | struct wl_resource *resource) |
| 3426 | { |
| 3427 | struct shell_surface *shsurf = wl_resource_get_user_data(resource); |
| 3428 | |
| 3429 | if (shsurf->type != SHELL_SURFACE_TOPLEVEL) |
| 3430 | return; |
| 3431 | |
| 3432 | /* apply compositor's own minimization logic (hide) */ |
| 3433 | set_minimized(shsurf->surface, 1); |
| 3434 | } |
| 3435 | |
Rafael Antognolli | e2a3455 | 2013-12-03 15:35:45 -0200 | [diff] [blame] | 3436 | static const struct xdg_surface_interface xdg_surface_implementation = { |
| 3437 | xdg_surface_destroy, |
| 3438 | xdg_surface_set_transient_for, |
Jasper St. Pierre | 7407345 | 2014-02-01 18:36:41 -0500 | [diff] [blame] | 3439 | xdg_surface_set_margin, |
Rafael Antognolli | e2a3455 | 2013-12-03 15:35:45 -0200 | [diff] [blame] | 3440 | xdg_surface_set_title, |
| 3441 | xdg_surface_set_app_id, |
Rafael Antognolli | e2a3455 | 2013-12-03 15:35:45 -0200 | [diff] [blame] | 3442 | xdg_surface_move, |
| 3443 | xdg_surface_resize, |
| 3444 | xdg_surface_set_output, |
Jasper St. Pierre | 8c6aa45 | 2014-02-08 18:29:49 -0500 | [diff] [blame] | 3445 | xdg_surface_request_change_state, |
| 3446 | xdg_surface_ack_change_state, |
Manuel Bachmann | 50c87db | 2014-02-26 15:52:13 +0100 | [diff] [blame] | 3447 | xdg_surface_set_minimized |
Rafael Antognolli | e2a3455 | 2013-12-03 15:35:45 -0200 | [diff] [blame] | 3448 | }; |
| 3449 | |
| 3450 | static void |
| 3451 | xdg_send_configure(struct weston_surface *surface, |
| 3452 | uint32_t edges, int32_t width, int32_t height) |
| 3453 | { |
| 3454 | struct shell_surface *shsurf = get_shell_surface(surface); |
| 3455 | |
U. Artie Eoff | cf5737a | 2014-01-17 10:08:25 -0800 | [diff] [blame] | 3456 | assert(shsurf); |
| 3457 | |
Kristian Høgsberg | 44cd196 | 2014-02-05 21:36:04 -0800 | [diff] [blame] | 3458 | xdg_surface_send_configure(shsurf->resource, width, height); |
Rafael Antognolli | e2a3455 | 2013-12-03 15:35:45 -0200 | [diff] [blame] | 3459 | } |
| 3460 | |
| 3461 | static const struct weston_shell_client xdg_client = { |
| 3462 | xdg_send_configure |
| 3463 | }; |
| 3464 | |
| 3465 | static void |
| 3466 | xdg_use_unstable_version(struct wl_client *client, |
| 3467 | struct wl_resource *resource, |
| 3468 | int32_t version) |
| 3469 | { |
| 3470 | if (version > 1) { |
| 3471 | wl_resource_post_error(resource, |
| 3472 | 1, |
| 3473 | "xdg-shell:: version not implemented yet."); |
| 3474 | return; |
| 3475 | } |
| 3476 | } |
| 3477 | |
| 3478 | static struct shell_surface * |
Jason Ekstrand | 9e9512f | 2014-04-16 21:12:10 -0500 | [diff] [blame] | 3479 | create_xdg_surface(struct shell_client *owner, void *shell, |
| 3480 | struct weston_surface *surface, |
Rafael Antognolli | e2a3455 | 2013-12-03 15:35:45 -0200 | [diff] [blame] | 3481 | const struct weston_shell_client *client) |
| 3482 | { |
| 3483 | struct shell_surface *shsurf; |
Rafael Antognolli | e2a3455 | 2013-12-03 15:35:45 -0200 | [diff] [blame] | 3484 | |
Jason Ekstrand | 9e9512f | 2014-04-16 21:12:10 -0500 | [diff] [blame] | 3485 | shsurf = create_common_surface(owner, shell, surface, client); |
Kristian Høgsberg | c8f8dd8 | 2013-12-05 23:20:33 -0800 | [diff] [blame] | 3486 | shsurf->type = SHELL_SURFACE_TOPLEVEL; |
Rafael Antognolli | e2a3455 | 2013-12-03 15:35:45 -0200 | [diff] [blame] | 3487 | |
| 3488 | return shsurf; |
| 3489 | } |
| 3490 | |
| 3491 | static void |
| 3492 | xdg_get_xdg_surface(struct wl_client *client, |
| 3493 | struct wl_resource *resource, |
| 3494 | uint32_t id, |
| 3495 | struct wl_resource *surface_resource) |
| 3496 | { |
| 3497 | struct weston_surface *surface = |
| 3498 | wl_resource_get_user_data(surface_resource); |
Kristian Høgsberg | 2bff94e | 2014-02-11 12:22:51 -0800 | [diff] [blame] | 3499 | struct shell_client *sc = wl_resource_get_user_data(resource); |
| 3500 | struct desktop_shell *shell = sc->shell; |
Rafael Antognolli | e2a3455 | 2013-12-03 15:35:45 -0200 | [diff] [blame] | 3501 | struct shell_surface *shsurf; |
| 3502 | |
| 3503 | if (get_shell_surface(surface)) { |
| 3504 | wl_resource_post_error(surface_resource, |
| 3505 | WL_DISPLAY_ERROR_INVALID_OBJECT, |
Jasper St. Pierre | fe9671e | 2014-03-25 13:31:44 -0400 | [diff] [blame] | 3506 | "xdg_shell::get_xdg_surface already requested"); |
Rafael Antognolli | e2a3455 | 2013-12-03 15:35:45 -0200 | [diff] [blame] | 3507 | return; |
| 3508 | } |
| 3509 | |
Jason Ekstrand | 9e9512f | 2014-04-16 21:12:10 -0500 | [diff] [blame] | 3510 | shsurf = create_xdg_surface(sc, shell, surface, &xdg_client); |
Rafael Antognolli | e2a3455 | 2013-12-03 15:35:45 -0200 | [diff] [blame] | 3511 | if (!shsurf) { |
| 3512 | wl_resource_post_error(surface_resource, |
| 3513 | WL_DISPLAY_ERROR_INVALID_OBJECT, |
| 3514 | "surface->configure already set"); |
| 3515 | return; |
| 3516 | } |
| 3517 | |
| 3518 | shsurf->resource = |
| 3519 | wl_resource_create(client, |
| 3520 | &xdg_surface_interface, 1, id); |
| 3521 | wl_resource_set_implementation(shsurf->resource, |
| 3522 | &xdg_surface_implementation, |
| 3523 | shsurf, shell_destroy_shell_surface); |
| 3524 | } |
| 3525 | |
| 3526 | static bool |
| 3527 | shell_surface_is_xdg_surface(struct shell_surface *shsurf) |
| 3528 | { |
Kristian Høgsberg | 0b7d995 | 2014-02-03 15:50:38 -0800 | [diff] [blame] | 3529 | return shsurf->resource && |
| 3530 | wl_resource_instance_of(shsurf->resource, |
| 3531 | &xdg_surface_interface, |
| 3532 | &xdg_surface_implementation); |
Rafael Antognolli | e2a3455 | 2013-12-03 15:35:45 -0200 | [diff] [blame] | 3533 | } |
| 3534 | |
| 3535 | /* xdg-popup implementation */ |
| 3536 | |
| 3537 | static void |
| 3538 | xdg_popup_destroy(struct wl_client *client, |
| 3539 | struct wl_resource *resource) |
| 3540 | { |
| 3541 | wl_resource_destroy(resource); |
| 3542 | } |
| 3543 | |
Rafael Antognolli | e2a3455 | 2013-12-03 15:35:45 -0200 | [diff] [blame] | 3544 | static const struct xdg_popup_interface xdg_popup_implementation = { |
| 3545 | xdg_popup_destroy, |
Rafael Antognolli | e2a3455 | 2013-12-03 15:35:45 -0200 | [diff] [blame] | 3546 | }; |
| 3547 | |
| 3548 | static void |
| 3549 | xdg_popup_send_configure(struct weston_surface *surface, |
| 3550 | uint32_t edges, int32_t width, int32_t height) |
| 3551 | { |
| 3552 | } |
| 3553 | |
| 3554 | static const struct weston_shell_client xdg_popup_client = { |
| 3555 | xdg_popup_send_configure |
| 3556 | }; |
| 3557 | |
| 3558 | static struct shell_surface * |
Jason Ekstrand | 9e9512f | 2014-04-16 21:12:10 -0500 | [diff] [blame] | 3559 | create_xdg_popup(struct shell_client *owner, void *shell, |
| 3560 | struct weston_surface *surface, |
Rafael Antognolli | e2a3455 | 2013-12-03 15:35:45 -0200 | [diff] [blame] | 3561 | const struct weston_shell_client *client, |
| 3562 | struct weston_surface *parent, |
| 3563 | struct shell_seat *seat, |
| 3564 | uint32_t serial, |
| 3565 | int32_t x, int32_t y) |
| 3566 | { |
| 3567 | struct shell_surface *shsurf; |
Rafael Antognolli | e2a3455 | 2013-12-03 15:35:45 -0200 | [diff] [blame] | 3568 | |
Jason Ekstrand | 9e9512f | 2014-04-16 21:12:10 -0500 | [diff] [blame] | 3569 | shsurf = create_common_surface(owner, shell, surface, client); |
Kristian Høgsberg | c8f8dd8 | 2013-12-05 23:20:33 -0800 | [diff] [blame] | 3570 | shsurf->type = SHELL_SURFACE_POPUP; |
Rafael Antognolli | e2a3455 | 2013-12-03 15:35:45 -0200 | [diff] [blame] | 3571 | shsurf->popup.shseat = seat; |
| 3572 | shsurf->popup.serial = serial; |
| 3573 | shsurf->popup.x = x; |
| 3574 | shsurf->popup.y = y; |
| 3575 | shell_surface_set_parent(shsurf, parent); |
| 3576 | |
| 3577 | return shsurf; |
| 3578 | } |
| 3579 | |
| 3580 | static void |
| 3581 | xdg_get_xdg_popup(struct wl_client *client, |
| 3582 | struct wl_resource *resource, |
| 3583 | uint32_t id, |
| 3584 | struct wl_resource *surface_resource, |
| 3585 | struct wl_resource *parent_resource, |
| 3586 | struct wl_resource *seat_resource, |
| 3587 | uint32_t serial, |
| 3588 | int32_t x, int32_t y, uint32_t flags) |
| 3589 | { |
| 3590 | struct weston_surface *surface = |
| 3591 | wl_resource_get_user_data(surface_resource); |
Kristian Høgsberg | 2bff94e | 2014-02-11 12:22:51 -0800 | [diff] [blame] | 3592 | struct shell_client *sc = wl_resource_get_user_data(resource); |
| 3593 | struct desktop_shell *shell = sc->shell; |
Rafael Antognolli | e2a3455 | 2013-12-03 15:35:45 -0200 | [diff] [blame] | 3594 | struct shell_surface *shsurf; |
| 3595 | struct weston_surface *parent; |
| 3596 | struct shell_seat *seat; |
| 3597 | |
| 3598 | if (get_shell_surface(surface)) { |
| 3599 | wl_resource_post_error(surface_resource, |
| 3600 | WL_DISPLAY_ERROR_INVALID_OBJECT, |
Jasper St. Pierre | fe9671e | 2014-03-25 13:31:44 -0400 | [diff] [blame] | 3601 | "xdg_shell::get_xdg_popup already requested"); |
Rafael Antognolli | e2a3455 | 2013-12-03 15:35:45 -0200 | [diff] [blame] | 3602 | return; |
| 3603 | } |
| 3604 | |
| 3605 | if (!parent_resource) { |
| 3606 | wl_resource_post_error(surface_resource, |
| 3607 | WL_DISPLAY_ERROR_INVALID_OBJECT, |
| 3608 | "xdg_shell::get_xdg_popup requires a parent shell surface"); |
| 3609 | } |
| 3610 | |
| 3611 | parent = wl_resource_get_user_data(parent_resource); |
| 3612 | seat = get_shell_seat(wl_resource_get_user_data(seat_resource));; |
| 3613 | |
Jason Ekstrand | 9e9512f | 2014-04-16 21:12:10 -0500 | [diff] [blame] | 3614 | shsurf = create_xdg_popup(sc, shell, surface, &xdg_popup_client, |
Rafael Antognolli | e2a3455 | 2013-12-03 15:35:45 -0200 | [diff] [blame] | 3615 | parent, seat, serial, x, y); |
| 3616 | if (!shsurf) { |
| 3617 | wl_resource_post_error(surface_resource, |
| 3618 | WL_DISPLAY_ERROR_INVALID_OBJECT, |
| 3619 | "surface->configure already set"); |
| 3620 | return; |
| 3621 | } |
| 3622 | |
| 3623 | shsurf->resource = |
| 3624 | wl_resource_create(client, |
| 3625 | &xdg_popup_interface, 1, id); |
| 3626 | wl_resource_set_implementation(shsurf->resource, |
| 3627 | &xdg_popup_implementation, |
| 3628 | shsurf, shell_destroy_shell_surface); |
| 3629 | } |
| 3630 | |
Kristian Høgsberg | 2bff94e | 2014-02-11 12:22:51 -0800 | [diff] [blame] | 3631 | static void |
| 3632 | xdg_pong(struct wl_client *client, |
| 3633 | struct wl_resource *resource, uint32_t serial) |
| 3634 | { |
| 3635 | struct shell_client *sc = wl_resource_get_user_data(resource); |
Kristian Høgsberg | 2bff94e | 2014-02-11 12:22:51 -0800 | [diff] [blame] | 3636 | |
Kristian Høgsberg | dd62aba | 2014-02-12 09:56:19 -0800 | [diff] [blame] | 3637 | shell_client_pong(sc, serial); |
Kristian Høgsberg | 2bff94e | 2014-02-11 12:22:51 -0800 | [diff] [blame] | 3638 | } |
| 3639 | |
Rafael Antognolli | e2a3455 | 2013-12-03 15:35:45 -0200 | [diff] [blame] | 3640 | static bool |
| 3641 | shell_surface_is_xdg_popup(struct shell_surface *shsurf) |
| 3642 | { |
| 3643 | return wl_resource_instance_of(shsurf->resource, |
| 3644 | &xdg_popup_interface, |
| 3645 | &xdg_popup_implementation); |
| 3646 | } |
| 3647 | |
| 3648 | static const struct xdg_shell_interface xdg_implementation = { |
| 3649 | xdg_use_unstable_version, |
| 3650 | xdg_get_xdg_surface, |
Kristian Høgsberg | 2bff94e | 2014-02-11 12:22:51 -0800 | [diff] [blame] | 3651 | xdg_get_xdg_popup, |
| 3652 | xdg_pong |
Rafael Antognolli | e2a3455 | 2013-12-03 15:35:45 -0200 | [diff] [blame] | 3653 | }; |
| 3654 | |
| 3655 | static int |
| 3656 | xdg_shell_unversioned_dispatch(const void *implementation, |
| 3657 | void *_target, uint32_t opcode, |
| 3658 | const struct wl_message *message, |
| 3659 | union wl_argument *args) |
| 3660 | { |
| 3661 | struct wl_resource *resource = _target; |
Kristian Høgsberg | 2bff94e | 2014-02-11 12:22:51 -0800 | [diff] [blame] | 3662 | struct shell_client *sc = wl_resource_get_user_data(resource); |
Rafael Antognolli | e2a3455 | 2013-12-03 15:35:45 -0200 | [diff] [blame] | 3663 | |
| 3664 | if (opcode != 0) { |
| 3665 | wl_resource_post_error(resource, |
| 3666 | WL_DISPLAY_ERROR_INVALID_OBJECT, |
| 3667 | "must call use_unstable_version first"); |
| 3668 | return 0; |
| 3669 | } |
| 3670 | |
Kristian Høgsberg | c7680b0 | 2014-02-19 10:14:46 -0800 | [diff] [blame] | 3671 | #define XDG_SERVER_VERSION 3 |
Rafael Antognolli | e2a3455 | 2013-12-03 15:35:45 -0200 | [diff] [blame] | 3672 | |
Kristian Høgsberg | 8d344a0 | 2013-12-08 22:27:11 -0800 | [diff] [blame] | 3673 | static_assert(XDG_SERVER_VERSION == XDG_SHELL_VERSION_CURRENT, |
| 3674 | "shell implementation doesn't match protocol version"); |
| 3675 | |
Rafael Antognolli | e2a3455 | 2013-12-03 15:35:45 -0200 | [diff] [blame] | 3676 | if (args[0].i != XDG_SERVER_VERSION) { |
| 3677 | wl_resource_post_error(resource, |
| 3678 | WL_DISPLAY_ERROR_INVALID_OBJECT, |
| 3679 | "incompatible version, server is %d " |
| 3680 | "client wants %d", |
| 3681 | XDG_SERVER_VERSION, args[0].i); |
| 3682 | return 0; |
| 3683 | } |
| 3684 | |
| 3685 | wl_resource_set_implementation(resource, &xdg_implementation, |
Kristian Høgsberg | 2bff94e | 2014-02-11 12:22:51 -0800 | [diff] [blame] | 3686 | sc, NULL); |
Rafael Antognolli | e2a3455 | 2013-12-03 15:35:45 -0200 | [diff] [blame] | 3687 | |
| 3688 | return 1; |
| 3689 | } |
| 3690 | |
| 3691 | /* end of xdg-shell implementation */ |
| 3692 | /***********************************/ |
| 3693 | |
Kristian Høgsberg | 0793756 | 2011-04-12 17:25:42 -0400 | [diff] [blame] | 3694 | static void |
Ander Conselvan de Oliveira | 859e885 | 2013-02-21 18:35:21 +0200 | [diff] [blame] | 3695 | shell_fade(struct desktop_shell *shell, enum fade_type type); |
| 3696 | |
| 3697 | static int |
| 3698 | screensaver_timeout(void *data) |
| 3699 | { |
| 3700 | struct desktop_shell *shell = data; |
| 3701 | |
| 3702 | shell_fade(shell, FADE_OUT); |
| 3703 | |
| 3704 | return 1; |
| 3705 | } |
| 3706 | |
| 3707 | static void |
Kristian Høgsberg | 8334bc1 | 2012-01-03 10:29:47 -0500 | [diff] [blame] | 3708 | handle_screensaver_sigchld(struct weston_process *proc, int status) |
Pekka Paalanen | 18027e5 | 2011-12-02 16:31:49 +0200 | [diff] [blame] | 3709 | { |
Ander Conselvan de Oliveira | 18639f8 | 2013-02-15 18:44:19 +0200 | [diff] [blame] | 3710 | struct desktop_shell *shell = |
| 3711 | container_of(proc, struct desktop_shell, screensaver.process); |
Ander Conselvan de Oliveira | 18639f8 | 2013-02-15 18:44:19 +0200 | [diff] [blame] | 3712 | |
Pekka Paalanen | 18027e5 | 2011-12-02 16:31:49 +0200 | [diff] [blame] | 3713 | proc->pid = 0; |
Ander Conselvan de Oliveira | 18639f8 | 2013-02-15 18:44:19 +0200 | [diff] [blame] | 3714 | |
| 3715 | if (shell->locked) |
Ander Conselvan de Oliveira | b17537e | 2013-02-22 14:16:18 +0200 | [diff] [blame] | 3716 | weston_compositor_sleep(shell->compositor); |
Pekka Paalanen | 18027e5 | 2011-12-02 16:31:49 +0200 | [diff] [blame] | 3717 | } |
| 3718 | |
| 3719 | static void |
Tiago Vignatti | be14326 | 2012-04-16 17:31:41 +0300 | [diff] [blame] | 3720 | launch_screensaver(struct desktop_shell *shell) |
Pekka Paalanen | 77346a6 | 2011-11-30 16:26:35 +0200 | [diff] [blame] | 3721 | { |
| 3722 | if (shell->screensaver.binding) |
| 3723 | return; |
| 3724 | |
Ander Conselvan de Oliveira | dda9d78 | 2013-02-22 14:16:19 +0200 | [diff] [blame] | 3725 | if (!shell->screensaver.path) { |
| 3726 | weston_compositor_sleep(shell->compositor); |
Pekka Paalanen | e955f1e | 2011-12-07 11:49:52 +0200 | [diff] [blame] | 3727 | return; |
Ander Conselvan de Oliveira | dda9d78 | 2013-02-22 14:16:19 +0200 | [diff] [blame] | 3728 | } |
Pekka Paalanen | e955f1e | 2011-12-07 11:49:52 +0200 | [diff] [blame] | 3729 | |
Kristian Høgsberg | 32bed57 | 2012-03-01 17:11:36 -0500 | [diff] [blame] | 3730 | if (shell->screensaver.process.pid != 0) { |
Martin Minarik | 6d11836 | 2012-06-07 18:01:59 +0200 | [diff] [blame] | 3731 | weston_log("old screensaver still running\n"); |
Kristian Høgsberg | 32bed57 | 2012-03-01 17:11:36 -0500 | [diff] [blame] | 3732 | return; |
| 3733 | } |
| 3734 | |
Kristian Høgsberg | 8334bc1 | 2012-01-03 10:29:47 -0500 | [diff] [blame] | 3735 | weston_client_launch(shell->compositor, |
Pekka Paalanen | 18027e5 | 2011-12-02 16:31:49 +0200 | [diff] [blame] | 3736 | &shell->screensaver.process, |
Pekka Paalanen | e955f1e | 2011-12-07 11:49:52 +0200 | [diff] [blame] | 3737 | shell->screensaver.path, |
Pekka Paalanen | 18027e5 | 2011-12-02 16:31:49 +0200 | [diff] [blame] | 3738 | handle_screensaver_sigchld); |
Pekka Paalanen | 77346a6 | 2011-11-30 16:26:35 +0200 | [diff] [blame] | 3739 | } |
| 3740 | |
| 3741 | static void |
Tiago Vignatti | be14326 | 2012-04-16 17:31:41 +0300 | [diff] [blame] | 3742 | terminate_screensaver(struct desktop_shell *shell) |
Pekka Paalanen | 77346a6 | 2011-11-30 16:26:35 +0200 | [diff] [blame] | 3743 | { |
Pekka Paalanen | 18027e5 | 2011-12-02 16:31:49 +0200 | [diff] [blame] | 3744 | if (shell->screensaver.process.pid == 0) |
| 3745 | return; |
| 3746 | |
Ander Conselvan de Oliveira | 4e20e9b | 2014-04-10 14:49:35 +0300 | [diff] [blame] | 3747 | /* Disarm the screensaver timer, otherwise it may fire when the |
| 3748 | * compositor is not in the idle state. In that case, the screen will |
| 3749 | * be locked, but the wake_signal won't fire on user input, making the |
| 3750 | * system unresponsive. */ |
| 3751 | wl_event_source_timer_update(shell->screensaver.timer, 0); |
| 3752 | |
Pekka Paalanen | 18027e5 | 2011-12-02 16:31:49 +0200 | [diff] [blame] | 3753 | kill(shell->screensaver.process.pid, SIGTERM); |
Pekka Paalanen | 77346a6 | 2011-11-30 16:26:35 +0200 | [diff] [blame] | 3754 | } |
| 3755 | |
| 3756 | static void |
Jason Ekstrand | 918f2dd | 2013-12-02 21:01:53 -0600 | [diff] [blame] | 3757 | configure_static_view(struct weston_view *ev, struct weston_layer *layer) |
Kristian Høgsberg | 962342c | 2012-06-26 16:29:50 -0400 | [diff] [blame] | 3758 | { |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 3759 | struct weston_view *v, *next; |
Kristian Høgsberg | 962342c | 2012-06-26 16:29:50 -0400 | [diff] [blame] | 3760 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 3761 | wl_list_for_each_safe(v, next, &layer->view_list, layer_link) { |
| 3762 | if (v->output == ev->output && v != ev) { |
| 3763 | weston_view_unmap(v); |
| 3764 | v->surface->configure = NULL; |
Kristian Høgsberg | 962342c | 2012-06-26 16:29:50 -0400 | [diff] [blame] | 3765 | } |
| 3766 | } |
| 3767 | |
Jason Ekstrand | 918f2dd | 2013-12-02 21:01:53 -0600 | [diff] [blame] | 3768 | weston_view_set_position(ev, ev->output->x, ev->output->y); |
Kristian Høgsberg | 962342c | 2012-06-26 16:29:50 -0400 | [diff] [blame] | 3769 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 3770 | if (wl_list_empty(&ev->layer_link)) { |
| 3771 | wl_list_insert(&layer->view_list, &ev->layer_link); |
| 3772 | weston_compositor_schedule_repaint(ev->surface->compositor); |
Kristian Høgsberg | 962342c | 2012-06-26 16:29:50 -0400 | [diff] [blame] | 3773 | } |
| 3774 | } |
| 3775 | |
| 3776 | static void |
Jason Ekstrand | 918f2dd | 2013-12-02 21:01:53 -0600 | [diff] [blame] | 3777 | 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] | 3778 | { |
Giulio Camuffo | 7fe01b1 | 2013-03-28 18:02:42 +0100 | [diff] [blame] | 3779 | struct desktop_shell *shell = es->configure_private; |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 3780 | struct weston_view *view; |
Kristian Høgsberg | af7b1ff | 2012-06-26 21:19:23 -0400 | [diff] [blame] | 3781 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 3782 | view = container_of(es->views.next, struct weston_view, surface_link); |
| 3783 | |
Jason Ekstrand | 918f2dd | 2013-12-02 21:01:53 -0600 | [diff] [blame] | 3784 | configure_static_view(view, &shell->background_layer); |
Kristian Høgsberg | af7b1ff | 2012-06-26 21:19:23 -0400 | [diff] [blame] | 3785 | } |
| 3786 | |
| 3787 | static void |
Kristian Høgsberg | 7584062 | 2011-09-06 13:48:16 -0400 | [diff] [blame] | 3788 | desktop_shell_set_background(struct wl_client *client, |
| 3789 | struct wl_resource *resource, |
Benjamin Franzke | d0f79ab | 2011-11-22 12:43:52 +0100 | [diff] [blame] | 3790 | struct wl_resource *output_resource, |
Kristian Høgsberg | 7584062 | 2011-09-06 13:48:16 -0400 | [diff] [blame] | 3791 | struct wl_resource *surface_resource) |
| 3792 | { |
Jason Ekstrand | 651f00e | 2013-06-14 10:07:54 -0500 | [diff] [blame] | 3793 | struct desktop_shell *shell = wl_resource_get_user_data(resource); |
Jason Ekstrand | 0f2ef7e | 2013-06-14 10:07:53 -0500 | [diff] [blame] | 3794 | struct weston_surface *surface = |
| 3795 | wl_resource_get_user_data(surface_resource); |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 3796 | struct weston_view *view, *next; |
Kristian Høgsberg | 7584062 | 2011-09-06 13:48:16 -0400 | [diff] [blame] | 3797 | |
Kristian Høgsberg | 962342c | 2012-06-26 16:29:50 -0400 | [diff] [blame] | 3798 | if (surface->configure) { |
| 3799 | wl_resource_post_error(surface_resource, |
| 3800 | WL_DISPLAY_ERROR_INVALID_OBJECT, |
| 3801 | "surface role already assigned"); |
| 3802 | return; |
| 3803 | } |
Benjamin Franzke | d0f79ab | 2011-11-22 12:43:52 +0100 | [diff] [blame] | 3804 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 3805 | wl_list_for_each_safe(view, next, &surface->views, surface_link) |
| 3806 | weston_view_destroy(view); |
| 3807 | view = weston_view_create(surface); |
| 3808 | |
Kristian Høgsberg | 962342c | 2012-06-26 16:29:50 -0400 | [diff] [blame] | 3809 | surface->configure = background_configure; |
Giulio Camuffo | 7fe01b1 | 2013-03-28 18:02:42 +0100 | [diff] [blame] | 3810 | surface->configure_private = shell; |
Jason Ekstrand | a0d2dde | 2013-06-14 10:08:01 -0500 | [diff] [blame] | 3811 | surface->output = wl_resource_get_user_data(output_resource); |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 3812 | view->output = surface->output; |
Kristian Høgsberg | eae5de7 | 2012-04-11 22:42:15 -0400 | [diff] [blame] | 3813 | desktop_shell_send_configure(resource, 0, |
Kristian Høgsberg | 0b5cd0c | 2012-03-04 21:57:37 -0500 | [diff] [blame] | 3814 | surface_resource, |
Scott Moreau | 1bad5db | 2012-08-18 01:04:05 -0600 | [diff] [blame] | 3815 | surface->output->width, |
| 3816 | surface->output->height); |
Kristian Høgsberg | 7584062 | 2011-09-06 13:48:16 -0400 | [diff] [blame] | 3817 | } |
| 3818 | |
| 3819 | static void |
Jason Ekstrand | 918f2dd | 2013-12-02 21:01:53 -0600 | [diff] [blame] | 3820 | 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] | 3821 | { |
Giulio Camuffo | 7fe01b1 | 2013-03-28 18:02:42 +0100 | [diff] [blame] | 3822 | struct desktop_shell *shell = es->configure_private; |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 3823 | struct weston_view *view; |
Kristian Høgsberg | af7b1ff | 2012-06-26 21:19:23 -0400 | [diff] [blame] | 3824 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 3825 | view = container_of(es->views.next, struct weston_view, surface_link); |
| 3826 | |
Jason Ekstrand | 918f2dd | 2013-12-02 21:01:53 -0600 | [diff] [blame] | 3827 | configure_static_view(view, &shell->panel_layer); |
Kristian Høgsberg | af7b1ff | 2012-06-26 21:19:23 -0400 | [diff] [blame] | 3828 | } |
| 3829 | |
| 3830 | static void |
Kristian Høgsberg | 7584062 | 2011-09-06 13:48:16 -0400 | [diff] [blame] | 3831 | desktop_shell_set_panel(struct wl_client *client, |
| 3832 | struct wl_resource *resource, |
Benjamin Franzke | d0f79ab | 2011-11-22 12:43:52 +0100 | [diff] [blame] | 3833 | struct wl_resource *output_resource, |
Kristian Høgsberg | 7584062 | 2011-09-06 13:48:16 -0400 | [diff] [blame] | 3834 | struct wl_resource *surface_resource) |
| 3835 | { |
Jason Ekstrand | 651f00e | 2013-06-14 10:07:54 -0500 | [diff] [blame] | 3836 | struct desktop_shell *shell = wl_resource_get_user_data(resource); |
Jason Ekstrand | 0f2ef7e | 2013-06-14 10:07:53 -0500 | [diff] [blame] | 3837 | struct weston_surface *surface = |
| 3838 | wl_resource_get_user_data(surface_resource); |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 3839 | struct weston_view *view, *next; |
Kristian Høgsberg | 7584062 | 2011-09-06 13:48:16 -0400 | [diff] [blame] | 3840 | |
Kristian Høgsberg | af7b1ff | 2012-06-26 21:19:23 -0400 | [diff] [blame] | 3841 | if (surface->configure) { |
| 3842 | wl_resource_post_error(surface_resource, |
| 3843 | WL_DISPLAY_ERROR_INVALID_OBJECT, |
| 3844 | "surface role already assigned"); |
| 3845 | return; |
| 3846 | } |
Benjamin Franzke | d0f79ab | 2011-11-22 12:43:52 +0100 | [diff] [blame] | 3847 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 3848 | wl_list_for_each_safe(view, next, &surface->views, surface_link) |
| 3849 | weston_view_destroy(view); |
| 3850 | view = weston_view_create(surface); |
| 3851 | |
Kristian Høgsberg | af7b1ff | 2012-06-26 21:19:23 -0400 | [diff] [blame] | 3852 | surface->configure = panel_configure; |
Giulio Camuffo | 7fe01b1 | 2013-03-28 18:02:42 +0100 | [diff] [blame] | 3853 | surface->configure_private = shell; |
Jason Ekstrand | a0d2dde | 2013-06-14 10:08:01 -0500 | [diff] [blame] | 3854 | surface->output = wl_resource_get_user_data(output_resource); |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 3855 | view->output = surface->output; |
Kristian Høgsberg | eae5de7 | 2012-04-11 22:42:15 -0400 | [diff] [blame] | 3856 | desktop_shell_send_configure(resource, 0, |
Kristian Høgsberg | af7b1ff | 2012-06-26 21:19:23 -0400 | [diff] [blame] | 3857 | surface_resource, |
Scott Moreau | 1bad5db | 2012-08-18 01:04:05 -0600 | [diff] [blame] | 3858 | surface->output->width, |
| 3859 | surface->output->height); |
Kristian Høgsberg | 7584062 | 2011-09-06 13:48:16 -0400 | [diff] [blame] | 3860 | } |
| 3861 | |
Pekka Paalanen | 9ef3e01 | 2011-11-15 13:34:48 +0200 | [diff] [blame] | 3862 | static void |
Jason Ekstrand | 918f2dd | 2013-12-02 21:01:53 -0600 | [diff] [blame] | 3863 | 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] | 3864 | { |
Giulio Camuffo | 7fe01b1 | 2013-03-28 18:02:42 +0100 | [diff] [blame] | 3865 | struct desktop_shell *shell = surface->configure_private; |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 3866 | struct weston_view *view; |
| 3867 | |
| 3868 | view = container_of(surface->views.next, struct weston_view, surface_link); |
Kristian Høgsberg | 730c94d | 2012-06-26 21:44:35 -0400 | [diff] [blame] | 3869 | |
Jason Ekstrand | 918f2dd | 2013-12-02 21:01:53 -0600 | [diff] [blame] | 3870 | if (surface->width == 0) |
Giulio Camuffo | 184df50 | 2013-02-21 11:29:21 +0100 | [diff] [blame] | 3871 | return; |
| 3872 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 3873 | center_on_output(view, get_default_output(shell->compositor)); |
Kristian Høgsberg | 730c94d | 2012-06-26 21:44:35 -0400 | [diff] [blame] | 3874 | |
| 3875 | if (!weston_surface_is_mapped(surface)) { |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 3876 | wl_list_insert(&shell->lock_layer.view_list, |
| 3877 | &view->layer_link); |
| 3878 | weston_view_update_transform(view); |
Ander Conselvan de Oliveira | 87524b6 | 2013-02-21 18:35:22 +0200 | [diff] [blame] | 3879 | shell_fade(shell, FADE_IN); |
Kristian Høgsberg | 730c94d | 2012-06-26 21:44:35 -0400 | [diff] [blame] | 3880 | } |
| 3881 | } |
| 3882 | |
| 3883 | static void |
Kristian Høgsberg | 27e3052 | 2012-04-11 23:18:23 -0400 | [diff] [blame] | 3884 | handle_lock_surface_destroy(struct wl_listener *listener, void *data) |
Kristian Høgsberg | 1ec0c31 | 2011-11-15 16:39:55 -0500 | [diff] [blame] | 3885 | { |
Tiago Vignatti | be14326 | 2012-04-16 17:31:41 +0300 | [diff] [blame] | 3886 | struct desktop_shell *shell = |
| 3887 | container_of(listener, struct desktop_shell, lock_surface_listener); |
Kristian Høgsberg | 1ec0c31 | 2011-11-15 16:39:55 -0500 | [diff] [blame] | 3888 | |
Martin Minarik | 6d11836 | 2012-06-07 18:01:59 +0200 | [diff] [blame] | 3889 | weston_log("lock surface gone\n"); |
Kristian Høgsberg | 1ec0c31 | 2011-11-15 16:39:55 -0500 | [diff] [blame] | 3890 | shell->lock_surface = NULL; |
| 3891 | } |
| 3892 | |
| 3893 | static void |
Pekka Paalanen | 9ef3e01 | 2011-11-15 13:34:48 +0200 | [diff] [blame] | 3894 | desktop_shell_set_lock_surface(struct wl_client *client, |
| 3895 | struct wl_resource *resource, |
| 3896 | struct wl_resource *surface_resource) |
| 3897 | { |
Jason Ekstrand | 651f00e | 2013-06-14 10:07:54 -0500 | [diff] [blame] | 3898 | struct desktop_shell *shell = wl_resource_get_user_data(resource); |
Jason Ekstrand | 0f2ef7e | 2013-06-14 10:07:53 -0500 | [diff] [blame] | 3899 | struct weston_surface *surface = |
| 3900 | wl_resource_get_user_data(surface_resource); |
Pekka Paalanen | 9826223 | 2011-12-01 10:42:22 +0200 | [diff] [blame] | 3901 | |
Pekka Paalanen | f0fc70d | 2011-11-15 13:34:54 +0200 | [diff] [blame] | 3902 | shell->prepare_event_sent = false; |
Kristian Høgsberg | af867cc | 2011-11-15 13:34:49 +0200 | [diff] [blame] | 3903 | |
Pekka Paalanen | f0fc70d | 2011-11-15 13:34:54 +0200 | [diff] [blame] | 3904 | if (!shell->locked) |
| 3905 | return; |
| 3906 | |
Pekka Paalanen | 9826223 | 2011-12-01 10:42:22 +0200 | [diff] [blame] | 3907 | shell->lock_surface = surface; |
Pekka Paalanen | f0fc70d | 2011-11-15 13:34:54 +0200 | [diff] [blame] | 3908 | |
Kristian Høgsberg | 27e3052 | 2012-04-11 23:18:23 -0400 | [diff] [blame] | 3909 | shell->lock_surface_listener.notify = handle_lock_surface_destroy; |
Jason Ekstrand | 651f00e | 2013-06-14 10:07:54 -0500 | [diff] [blame] | 3910 | wl_signal_add(&surface->destroy_signal, |
Kristian Høgsberg | 27e3052 | 2012-04-11 23:18:23 -0400 | [diff] [blame] | 3911 | &shell->lock_surface_listener); |
Pekka Paalanen | 57da4a8 | 2011-11-23 16:42:16 +0200 | [diff] [blame] | 3912 | |
Kristian Høgsberg | aa2ee8b | 2013-10-30 15:49:45 -0700 | [diff] [blame] | 3913 | weston_view_create(surface); |
Kristian Høgsberg | 730c94d | 2012-06-26 21:44:35 -0400 | [diff] [blame] | 3914 | surface->configure = lock_surface_configure; |
Giulio Camuffo | 7fe01b1 | 2013-03-28 18:02:42 +0100 | [diff] [blame] | 3915 | surface->configure_private = shell; |
Pekka Paalanen | f0fc70d | 2011-11-15 13:34:54 +0200 | [diff] [blame] | 3916 | } |
| 3917 | |
| 3918 | static void |
Tiago Vignatti | be14326 | 2012-04-16 17:31:41 +0300 | [diff] [blame] | 3919 | resume_desktop(struct desktop_shell *shell) |
Pekka Paalanen | f0fc70d | 2011-11-15 13:34:54 +0200 | [diff] [blame] | 3920 | { |
Kristian Høgsberg | 4476aaf | 2012-06-25 14:03:13 -0400 | [diff] [blame] | 3921 | struct workspace *ws = get_current_workspace(shell); |
Pekka Paalanen | 77346a6 | 2011-11-30 16:26:35 +0200 | [diff] [blame] | 3922 | |
Pekka Paalanen | 77346a6 | 2011-11-30 16:26:35 +0200 | [diff] [blame] | 3923 | terminate_screensaver(shell); |
Pekka Paalanen | f0fc70d | 2011-11-15 13:34:54 +0200 | [diff] [blame] | 3924 | |
Kristian Høgsberg | 3be2ce9 | 2012-02-29 12:42:35 -0500 | [diff] [blame] | 3925 | wl_list_remove(&shell->lock_layer.link); |
Philipp Brüschweiler | 711fda8 | 2012-08-09 18:50:43 +0200 | [diff] [blame] | 3926 | if (shell->showing_input_panels) { |
Manuel Bachmann | 805d2f5 | 2014-03-05 12:21:34 +0100 | [diff] [blame] | 3927 | wl_list_insert(&shell->compositor->cursor_layer.link, |
Philipp Brüschweiler | 711fda8 | 2012-08-09 18:50:43 +0200 | [diff] [blame] | 3928 | &shell->input_panel_layer.link); |
| 3929 | wl_list_insert(&shell->input_panel_layer.link, |
Manuel Bachmann | 805d2f5 | 2014-03-05 12:21:34 +0100 | [diff] [blame] | 3930 | &shell->fullscreen_layer.link); |
Philipp Brüschweiler | 711fda8 | 2012-08-09 18:50:43 +0200 | [diff] [blame] | 3931 | } else { |
Manuel Bachmann | 805d2f5 | 2014-03-05 12:21:34 +0100 | [diff] [blame] | 3932 | wl_list_insert(&shell->compositor->cursor_layer.link, |
| 3933 | &shell->fullscreen_layer.link); |
Philipp Brüschweiler | 711fda8 | 2012-08-09 18:50:43 +0200 | [diff] [blame] | 3934 | } |
Manuel Bachmann | 805d2f5 | 2014-03-05 12:21:34 +0100 | [diff] [blame] | 3935 | wl_list_insert(&shell->fullscreen_layer.link, |
| 3936 | &shell->panel_layer.link); |
| 3937 | wl_list_insert(&shell->panel_layer.link, |
| 3938 | &ws->layer.link), |
Pekka Paalanen | f0fc70d | 2011-11-15 13:34:54 +0200 | [diff] [blame] | 3939 | |
Kristian Høgsberg | 2f5faff | 2012-07-31 16:36:34 -0400 | [diff] [blame] | 3940 | restore_focus_state(shell, get_current_workspace(shell)); |
Jonas Ådahl | 0476974 | 2012-06-13 00:01:24 +0200 | [diff] [blame] | 3941 | |
Pekka Paalanen | f0fc70d | 2011-11-15 13:34:54 +0200 | [diff] [blame] | 3942 | shell->locked = false; |
Ander Conselvan de Oliveira | 87524b6 | 2013-02-21 18:35:22 +0200 | [diff] [blame] | 3943 | shell_fade(shell, FADE_IN); |
Pekka Paalanen | fc6d91a | 2012-02-10 15:33:10 +0200 | [diff] [blame] | 3944 | weston_compositor_damage_all(shell->compositor); |
Pekka Paalanen | 9ef3e01 | 2011-11-15 13:34:48 +0200 | [diff] [blame] | 3945 | } |
| 3946 | |
| 3947 | static void |
| 3948 | desktop_shell_unlock(struct wl_client *client, |
| 3949 | struct wl_resource *resource) |
| 3950 | { |
Jason Ekstrand | 651f00e | 2013-06-14 10:07:54 -0500 | [diff] [blame] | 3951 | struct desktop_shell *shell = wl_resource_get_user_data(resource); |
Pekka Paalanen | 9ef3e01 | 2011-11-15 13:34:48 +0200 | [diff] [blame] | 3952 | |
Pekka Paalanen | 9ef3e01 | 2011-11-15 13:34:48 +0200 | [diff] [blame] | 3953 | shell->prepare_event_sent = false; |
Pekka Paalanen | f0fc70d | 2011-11-15 13:34:54 +0200 | [diff] [blame] | 3954 | |
| 3955 | if (shell->locked) |
| 3956 | resume_desktop(shell); |
Pekka Paalanen | 9ef3e01 | 2011-11-15 13:34:48 +0200 | [diff] [blame] | 3957 | } |
| 3958 | |
Kristian Høgsberg | d56bd90 | 2012-06-05 09:58:51 -0400 | [diff] [blame] | 3959 | static void |
Ander Conselvan de Oliveira | b9d2a0f | 2012-06-28 18:08:05 +0300 | [diff] [blame] | 3960 | desktop_shell_set_grab_surface(struct wl_client *client, |
Kristian Høgsberg | d56bd90 | 2012-06-05 09:58:51 -0400 | [diff] [blame] | 3961 | struct wl_resource *resource, |
| 3962 | struct wl_resource *surface_resource) |
| 3963 | { |
Jason Ekstrand | 651f00e | 2013-06-14 10:07:54 -0500 | [diff] [blame] | 3964 | struct desktop_shell *shell = wl_resource_get_user_data(resource); |
Kristian Høgsberg | d56bd90 | 2012-06-05 09:58:51 -0400 | [diff] [blame] | 3965 | |
Jason Ekstrand | 0f2ef7e | 2013-06-14 10:07:53 -0500 | [diff] [blame] | 3966 | shell->grab_surface = wl_resource_get_user_data(surface_resource); |
Kristian Høgsberg | 48588f8 | 2013-10-24 15:51:35 -0700 | [diff] [blame] | 3967 | weston_view_create(shell->grab_surface); |
Kristian Høgsberg | d56bd90 | 2012-06-05 09:58:51 -0400 | [diff] [blame] | 3968 | } |
| 3969 | |
Pekka Paalanen | 79346ab | 2013-05-22 18:03:09 +0300 | [diff] [blame] | 3970 | static void |
| 3971 | desktop_shell_desktop_ready(struct wl_client *client, |
| 3972 | struct wl_resource *resource) |
| 3973 | { |
Jason Ekstrand | 651f00e | 2013-06-14 10:07:54 -0500 | [diff] [blame] | 3974 | struct desktop_shell *shell = wl_resource_get_user_data(resource); |
Pekka Paalanen | 79346ab | 2013-05-22 18:03:09 +0300 | [diff] [blame] | 3975 | |
| 3976 | shell_fade_startup(shell); |
| 3977 | } |
| 3978 | |
Kristian Høgsberg | 7584062 | 2011-09-06 13:48:16 -0400 | [diff] [blame] | 3979 | static const struct desktop_shell_interface desktop_shell_implementation = { |
| 3980 | desktop_shell_set_background, |
Pekka Paalanen | 9ef3e01 | 2011-11-15 13:34:48 +0200 | [diff] [blame] | 3981 | desktop_shell_set_panel, |
| 3982 | desktop_shell_set_lock_surface, |
Kristian Høgsberg | d56bd90 | 2012-06-05 09:58:51 -0400 | [diff] [blame] | 3983 | desktop_shell_unlock, |
Pekka Paalanen | 79346ab | 2013-05-22 18:03:09 +0300 | [diff] [blame] | 3984 | desktop_shell_set_grab_surface, |
| 3985 | desktop_shell_desktop_ready |
Kristian Høgsberg | 7584062 | 2011-09-06 13:48:16 -0400 | [diff] [blame] | 3986 | }; |
| 3987 | |
Pekka Paalanen | 92a0dc4 | 2011-11-28 15:34:13 +0200 | [diff] [blame] | 3988 | static enum shell_surface_type |
Kristian Høgsberg | 8334bc1 | 2012-01-03 10:29:47 -0500 | [diff] [blame] | 3989 | get_shell_surface_type(struct weston_surface *surface) |
Pekka Paalanen | 92a0dc4 | 2011-11-28 15:34:13 +0200 | [diff] [blame] | 3990 | { |
| 3991 | struct shell_surface *shsurf; |
| 3992 | |
| 3993 | shsurf = get_shell_surface(surface); |
| 3994 | if (!shsurf) |
Pekka Paalanen | 9826223 | 2011-12-01 10:42:22 +0200 | [diff] [blame] | 3995 | return SHELL_SURFACE_NONE; |
Pekka Paalanen | 92a0dc4 | 2011-11-28 15:34:13 +0200 | [diff] [blame] | 3996 | return shsurf->type; |
| 3997 | } |
| 3998 | |
Kristian Høgsberg | 7584062 | 2011-09-06 13:48:16 -0400 | [diff] [blame] | 3999 | static void |
Kristian Høgsberg | e314875 | 2013-05-06 23:19:49 -0400 | [diff] [blame] | 4000 | 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] | 4001 | { |
Rafal Mielniczuk | b2917a2 | 2014-01-05 20:04:59 +0100 | [diff] [blame] | 4002 | struct weston_surface *focus; |
Pekka Paalanen | 01388e2 | 2013-04-25 13:57:44 +0300 | [diff] [blame] | 4003 | struct weston_surface *surface; |
Kristian Høgsberg | 938b8fa | 2012-05-18 13:46:27 -0400 | [diff] [blame] | 4004 | struct shell_surface *shsurf; |
Kristian Høgsberg | d2abb83 | 2011-11-23 10:52:40 -0500 | [diff] [blame] | 4005 | |
Rafal Mielniczuk | b2917a2 | 2014-01-05 20:04:59 +0100 | [diff] [blame] | 4006 | if (seat->pointer->focus == NULL) |
| 4007 | return; |
| 4008 | |
| 4009 | focus = seat->pointer->focus->surface; |
| 4010 | |
Pekka Paalanen | 01388e2 | 2013-04-25 13:57:44 +0300 | [diff] [blame] | 4011 | surface = weston_surface_get_main_surface(focus); |
Benjamin Franzke | d0f79ab | 2011-11-22 12:43:52 +0100 | [diff] [blame] | 4012 | if (surface == NULL) |
| 4013 | return; |
Kristian Høgsberg | 0793756 | 2011-04-12 17:25:42 -0400 | [diff] [blame] | 4014 | |
Kristian Høgsberg | 938b8fa | 2012-05-18 13:46:27 -0400 | [diff] [blame] | 4015 | shsurf = get_shell_surface(surface); |
Rafael Antognolli | 03b1659 | 2013-12-03 15:35:42 -0200 | [diff] [blame] | 4016 | if (shsurf == NULL || shsurf->state.fullscreen || |
| 4017 | shsurf->state.maximized) |
Kristian Høgsberg | 938b8fa | 2012-05-18 13:46:27 -0400 | [diff] [blame] | 4018 | return; |
| 4019 | |
Kristian Høgsberg | 938b8fa | 2012-05-18 13:46:27 -0400 | [diff] [blame] | 4020 | surface_move(shsurf, (struct weston_seat *) seat); |
Kristian Høgsberg | 0793756 | 2011-04-12 17:25:42 -0400 | [diff] [blame] | 4021 | } |
| 4022 | |
| 4023 | static void |
Rafael Antognolli | ea997ac | 2013-12-03 15:35:48 -0200 | [diff] [blame] | 4024 | maximize_binding(struct weston_seat *seat, uint32_t time, uint32_t button, void *data) |
| 4025 | { |
Emilio Pozuelo Monfort | 38b58eb | 2014-01-29 11:11:12 +0100 | [diff] [blame] | 4026 | struct weston_surface *focus = seat->keyboard->focus; |
Rafael Antognolli | ea997ac | 2013-12-03 15:35:48 -0200 | [diff] [blame] | 4027 | struct weston_surface *surface; |
| 4028 | struct shell_surface *shsurf; |
Kristian Høgsberg | 283bf37 | 2014-02-18 23:28:09 -0800 | [diff] [blame] | 4029 | uint32_t serial; |
Rafael Antognolli | ea997ac | 2013-12-03 15:35:48 -0200 | [diff] [blame] | 4030 | |
| 4031 | surface = weston_surface_get_main_surface(focus); |
| 4032 | if (surface == NULL) |
| 4033 | return; |
| 4034 | |
| 4035 | shsurf = get_shell_surface(surface); |
| 4036 | if (shsurf == NULL) |
| 4037 | return; |
| 4038 | |
| 4039 | if (!shell_surface_is_xdg_surface(shsurf)) |
| 4040 | return; |
| 4041 | |
Kristian Høgsberg | 283bf37 | 2014-02-18 23:28:09 -0800 | [diff] [blame] | 4042 | serial = wl_display_next_serial(seat->compositor->wl_display); |
| 4043 | xdg_surface_change_state(shsurf, XDG_SURFACE_STATE_MAXIMIZED, |
| 4044 | !shsurf->state.maximized, serial); |
Rafael Antognolli | ea997ac | 2013-12-03 15:35:48 -0200 | [diff] [blame] | 4045 | } |
| 4046 | |
| 4047 | static void |
| 4048 | fullscreen_binding(struct weston_seat *seat, uint32_t time, uint32_t button, void *data) |
| 4049 | { |
Emilio Pozuelo Monfort | 38b58eb | 2014-01-29 11:11:12 +0100 | [diff] [blame] | 4050 | struct weston_surface *focus = seat->keyboard->focus; |
Rafael Antognolli | ea997ac | 2013-12-03 15:35:48 -0200 | [diff] [blame] | 4051 | struct weston_surface *surface; |
| 4052 | struct shell_surface *shsurf; |
Kristian Høgsberg | 283bf37 | 2014-02-18 23:28:09 -0800 | [diff] [blame] | 4053 | uint32_t serial; |
Rafael Antognolli | ea997ac | 2013-12-03 15:35:48 -0200 | [diff] [blame] | 4054 | |
| 4055 | surface = weston_surface_get_main_surface(focus); |
| 4056 | if (surface == NULL) |
| 4057 | return; |
| 4058 | |
| 4059 | shsurf = get_shell_surface(surface); |
| 4060 | if (shsurf == NULL) |
| 4061 | return; |
| 4062 | |
| 4063 | if (!shell_surface_is_xdg_surface(shsurf)) |
| 4064 | return; |
| 4065 | |
Kristian Høgsberg | 283bf37 | 2014-02-18 23:28:09 -0800 | [diff] [blame] | 4066 | serial = wl_display_next_serial(seat->compositor->wl_display); |
| 4067 | xdg_surface_change_state(shsurf, XDG_SURFACE_STATE_FULLSCREEN, |
| 4068 | !shsurf->state.fullscreen, serial); |
Rafael Antognolli | ea997ac | 2013-12-03 15:35:48 -0200 | [diff] [blame] | 4069 | } |
| 4070 | |
| 4071 | static void |
Neil Roberts | aba0f25 | 2013-10-03 16:43:05 +0100 | [diff] [blame] | 4072 | touch_move_binding(struct weston_seat *seat, uint32_t time, void *data) |
| 4073 | { |
Kristian Høgsberg | 7ab139c | 2013-10-24 16:21:39 -0700 | [diff] [blame] | 4074 | struct weston_surface *focus = seat->touch->focus->surface; |
Neil Roberts | aba0f25 | 2013-10-03 16:43:05 +0100 | [diff] [blame] | 4075 | struct weston_surface *surface; |
| 4076 | struct shell_surface *shsurf; |
| 4077 | |
| 4078 | surface = weston_surface_get_main_surface(focus); |
| 4079 | if (surface == NULL) |
| 4080 | return; |
| 4081 | |
| 4082 | shsurf = get_shell_surface(surface); |
Rafael Antognolli | 03b1659 | 2013-12-03 15:35:42 -0200 | [diff] [blame] | 4083 | if (shsurf == NULL || shsurf->state.fullscreen || |
| 4084 | shsurf->state.maximized) |
Neil Roberts | aba0f25 | 2013-10-03 16:43:05 +0100 | [diff] [blame] | 4085 | return; |
| 4086 | |
| 4087 | surface_touch_move(shsurf, (struct weston_seat *) seat); |
| 4088 | } |
| 4089 | |
| 4090 | static void |
Kristian Høgsberg | e314875 | 2013-05-06 23:19:49 -0400 | [diff] [blame] | 4091 | 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] | 4092 | { |
Rafal Mielniczuk | b2917a2 | 2014-01-05 20:04:59 +0100 | [diff] [blame] | 4093 | struct weston_surface *focus; |
Pekka Paalanen | 01388e2 | 2013-04-25 13:57:44 +0300 | [diff] [blame] | 4094 | struct weston_surface *surface; |
Kristian Høgsberg | 0793756 | 2011-04-12 17:25:42 -0400 | [diff] [blame] | 4095 | uint32_t edges = 0; |
| 4096 | int32_t x, y; |
Pekka Paalanen | 9d1613e | 2011-11-25 12:09:16 +0200 | [diff] [blame] | 4097 | struct shell_surface *shsurf; |
Kristian Høgsberg | d2abb83 | 2011-11-23 10:52:40 -0500 | [diff] [blame] | 4098 | |
Rafal Mielniczuk | b2917a2 | 2014-01-05 20:04:59 +0100 | [diff] [blame] | 4099 | if (seat->pointer->focus == NULL) |
| 4100 | return; |
| 4101 | |
| 4102 | focus = seat->pointer->focus->surface; |
| 4103 | |
Pekka Paalanen | 01388e2 | 2013-04-25 13:57:44 +0300 | [diff] [blame] | 4104 | surface = weston_surface_get_main_surface(focus); |
Benjamin Franzke | d0f79ab | 2011-11-22 12:43:52 +0100 | [diff] [blame] | 4105 | if (surface == NULL) |
| 4106 | return; |
Pekka Paalanen | 92a0dc4 | 2011-11-28 15:34:13 +0200 | [diff] [blame] | 4107 | |
Pekka Paalanen | 9d1613e | 2011-11-25 12:09:16 +0200 | [diff] [blame] | 4108 | shsurf = get_shell_surface(surface); |
Rafael Antognolli | 03b1659 | 2013-12-03 15:35:42 -0200 | [diff] [blame] | 4109 | if (shsurf == NULL || shsurf->state.fullscreen || |
| 4110 | shsurf->state.maximized) |
Pekka Paalanen | 92a0dc4 | 2011-11-28 15:34:13 +0200 | [diff] [blame] | 4111 | return; |
| 4112 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 4113 | weston_view_from_global(shsurf->view, |
| 4114 | wl_fixed_to_int(seat->pointer->grab_x), |
| 4115 | wl_fixed_to_int(seat->pointer->grab_y), |
| 4116 | &x, &y); |
Kristian Høgsberg | 0793756 | 2011-04-12 17:25:42 -0400 | [diff] [blame] | 4117 | |
Jason Ekstrand | 918f2dd | 2013-12-02 21:01:53 -0600 | [diff] [blame] | 4118 | if (x < shsurf->surface->width / 3) |
Pekka Paalanen | 9d1613e | 2011-11-25 12:09:16 +0200 | [diff] [blame] | 4119 | edges |= WL_SHELL_SURFACE_RESIZE_LEFT; |
Jason Ekstrand | 918f2dd | 2013-12-02 21:01:53 -0600 | [diff] [blame] | 4120 | else if (x < 2 * shsurf->surface->width / 3) |
Kristian Høgsberg | 0793756 | 2011-04-12 17:25:42 -0400 | [diff] [blame] | 4121 | edges |= 0; |
| 4122 | else |
Pekka Paalanen | 9d1613e | 2011-11-25 12:09:16 +0200 | [diff] [blame] | 4123 | edges |= WL_SHELL_SURFACE_RESIZE_RIGHT; |
Kristian Høgsberg | 0793756 | 2011-04-12 17:25:42 -0400 | [diff] [blame] | 4124 | |
Jason Ekstrand | 918f2dd | 2013-12-02 21:01:53 -0600 | [diff] [blame] | 4125 | if (y < shsurf->surface->height / 3) |
Pekka Paalanen | 9d1613e | 2011-11-25 12:09:16 +0200 | [diff] [blame] | 4126 | edges |= WL_SHELL_SURFACE_RESIZE_TOP; |
Jason Ekstrand | 918f2dd | 2013-12-02 21:01:53 -0600 | [diff] [blame] | 4127 | else if (y < 2 * shsurf->surface->height / 3) |
Kristian Høgsberg | 0793756 | 2011-04-12 17:25:42 -0400 | [diff] [blame] | 4128 | edges |= 0; |
| 4129 | else |
Pekka Paalanen | 9d1613e | 2011-11-25 12:09:16 +0200 | [diff] [blame] | 4130 | edges |= WL_SHELL_SURFACE_RESIZE_BOTTOM; |
Kristian Høgsberg | 0793756 | 2011-04-12 17:25:42 -0400 | [diff] [blame] | 4131 | |
Kristian Høgsberg | c1693f2 | 2012-05-22 16:56:23 -0400 | [diff] [blame] | 4132 | surface_resize(shsurf, (struct weston_seat *) seat, edges); |
Kristian Høgsberg | 02ec0a5 | 2011-04-23 13:04:11 -0400 | [diff] [blame] | 4133 | } |
| 4134 | |
| 4135 | static void |
Kristian Høgsberg | e314875 | 2013-05-06 23:19:49 -0400 | [diff] [blame] | 4136 | 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] | 4137 | wl_fixed_t value, void *data) |
Scott Moreau | a3aa9c9 | 2012-03-22 11:01:03 -0600 | [diff] [blame] | 4138 | { |
Jonas Ådahl | b0b87ba | 2012-09-27 18:40:42 +0200 | [diff] [blame] | 4139 | float step = 0.005; |
Scott Moreau | a3aa9c9 | 2012-03-22 11:01:03 -0600 | [diff] [blame] | 4140 | struct shell_surface *shsurf; |
Kristian Høgsberg | 7ab139c | 2013-10-24 16:21:39 -0700 | [diff] [blame] | 4141 | struct weston_surface *focus = seat->pointer->focus->surface; |
Pekka Paalanen | 01388e2 | 2013-04-25 13:57:44 +0300 | [diff] [blame] | 4142 | struct weston_surface *surface; |
Scott Moreau | a3aa9c9 | 2012-03-22 11:01:03 -0600 | [diff] [blame] | 4143 | |
Pekka Paalanen | 01388e2 | 2013-04-25 13:57:44 +0300 | [diff] [blame] | 4144 | /* XXX: broken for windows containing sub-surfaces */ |
| 4145 | surface = weston_surface_get_main_surface(focus); |
Scott Moreau | a3aa9c9 | 2012-03-22 11:01:03 -0600 | [diff] [blame] | 4146 | if (surface == NULL) |
| 4147 | return; |
| 4148 | |
| 4149 | shsurf = get_shell_surface(surface); |
| 4150 | if (!shsurf) |
| 4151 | return; |
| 4152 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 4153 | shsurf->view->alpha -= wl_fixed_to_double(value) * step; |
Scott Moreau | a3aa9c9 | 2012-03-22 11:01:03 -0600 | [diff] [blame] | 4154 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 4155 | if (shsurf->view->alpha > 1.0) |
| 4156 | shsurf->view->alpha = 1.0; |
| 4157 | if (shsurf->view->alpha < step) |
| 4158 | shsurf->view->alpha = step; |
Scott Moreau | a3aa9c9 | 2012-03-22 11:01:03 -0600 | [diff] [blame] | 4159 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 4160 | weston_view_geometry_dirty(shsurf->view); |
Scott Moreau | a3aa9c9 | 2012-03-22 11:01:03 -0600 | [diff] [blame] | 4161 | weston_surface_damage(surface); |
| 4162 | } |
| 4163 | |
| 4164 | static void |
Kristian Høgsberg | e314875 | 2013-05-06 23:19:49 -0400 | [diff] [blame] | 4165 | 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] | 4166 | wl_fixed_t value) |
Scott Moreau | ccbf29d | 2012-02-22 14:21:41 -0700 | [diff] [blame] | 4167 | { |
Daniel Stone | 37816df | 2012-05-16 18:45:18 +0100 | [diff] [blame] | 4168 | struct weston_seat *ws = (struct weston_seat *) seat; |
| 4169 | struct weston_compositor *compositor = ws->compositor; |
Scott Moreau | ccbf29d | 2012-02-22 14:21:41 -0700 | [diff] [blame] | 4170 | struct weston_output *output; |
Scott Moreau | e660398 | 2012-06-11 13:07:51 -0600 | [diff] [blame] | 4171 | float increment; |
Scott Moreau | ccbf29d | 2012-02-22 14:21:41 -0700 | [diff] [blame] | 4172 | |
| 4173 | wl_list_for_each(output, &compositor->output_list, link) { |
| 4174 | if (pixman_region32_contains_point(&output->region, |
Daniel Stone | 37816df | 2012-05-16 18:45:18 +0100 | [diff] [blame] | 4175 | wl_fixed_to_double(seat->pointer->x), |
| 4176 | wl_fixed_to_double(seat->pointer->y), |
Daniel Stone | 103db7f | 2012-05-08 17:17:55 +0100 | [diff] [blame] | 4177 | NULL)) { |
Daniel Stone | 325fc2d | 2012-05-30 16:31:58 +0100 | [diff] [blame] | 4178 | if (key == KEY_PAGEUP) |
Kristian Høgsberg | 9b68af0 | 2012-05-22 12:55:18 -0400 | [diff] [blame] | 4179 | increment = output->zoom.increment; |
Daniel Stone | 325fc2d | 2012-05-30 16:31:58 +0100 | [diff] [blame] | 4180 | else if (key == KEY_PAGEDOWN) |
Kristian Høgsberg | 9b68af0 | 2012-05-22 12:55:18 -0400 | [diff] [blame] | 4181 | increment = -output->zoom.increment; |
| 4182 | else if (axis == WL_POINTER_AXIS_VERTICAL_SCROLL) |
Jonas Ådahl | b0b87ba | 2012-09-27 18:40:42 +0200 | [diff] [blame] | 4183 | /* For every pixel zoom 20th of a step */ |
Daniel Stone | 0c1e46e | 2012-05-30 16:31:59 +0100 | [diff] [blame] | 4184 | increment = output->zoom.increment * |
Jonas Ådahl | b0b87ba | 2012-09-27 18:40:42 +0200 | [diff] [blame] | 4185 | -wl_fixed_to_double(value) / 20.0; |
Kristian Høgsberg | 9b68af0 | 2012-05-22 12:55:18 -0400 | [diff] [blame] | 4186 | else |
| 4187 | increment = 0; |
| 4188 | |
Kristian Høgsberg | 9b68af0 | 2012-05-22 12:55:18 -0400 | [diff] [blame] | 4189 | output->zoom.level += increment; |
Scott Moreau | c6d7f60 | 2012-02-23 22:28:37 -0700 | [diff] [blame] | 4190 | |
Scott Moreau | e660398 | 2012-06-11 13:07:51 -0600 | [diff] [blame] | 4191 | if (output->zoom.level < 0.0) |
Scott Moreau | 850ca42 | 2012-05-21 15:21:25 -0600 | [diff] [blame] | 4192 | output->zoom.level = 0.0; |
Scott Moreau | e660398 | 2012-06-11 13:07:51 -0600 | [diff] [blame] | 4193 | else if (output->zoom.level > output->zoom.max_level) |
| 4194 | output->zoom.level = output->zoom.max_level; |
Ville Syrjälä | aa628d0 | 2012-11-16 11:48:47 +0200 | [diff] [blame] | 4195 | else if (!output->zoom.active) { |
Giulio Camuffo | 412b024 | 2013-11-14 23:42:51 +0100 | [diff] [blame] | 4196 | weston_output_activate_zoom(output); |
Kristian Høgsberg | 79af73e | 2012-08-03 15:45:23 -0400 | [diff] [blame] | 4197 | } |
Scott Moreau | ccbf29d | 2012-02-22 14:21:41 -0700 | [diff] [blame] | 4198 | |
Scott Moreau | e660398 | 2012-06-11 13:07:51 -0600 | [diff] [blame] | 4199 | output->zoom.spring_z.target = output->zoom.level; |
Scott Moreau | ccbf29d | 2012-02-22 14:21:41 -0700 | [diff] [blame] | 4200 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 4201 | weston_output_update_zoom(output); |
Scott Moreau | ccbf29d | 2012-02-22 14:21:41 -0700 | [diff] [blame] | 4202 | } |
| 4203 | } |
| 4204 | } |
| 4205 | |
Scott Moreau | ccbf29d | 2012-02-22 14:21:41 -0700 | [diff] [blame] | 4206 | static void |
Kristian Høgsberg | e314875 | 2013-05-06 23:19:49 -0400 | [diff] [blame] | 4207 | 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] | 4208 | wl_fixed_t value, void *data) |
Daniel Stone | 325fc2d | 2012-05-30 16:31:58 +0100 | [diff] [blame] | 4209 | { |
| 4210 | do_zoom(seat, time, 0, axis, value); |
| 4211 | } |
| 4212 | |
| 4213 | static void |
Kristian Høgsberg | e314875 | 2013-05-06 23:19:49 -0400 | [diff] [blame] | 4214 | 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] | 4215 | void *data) |
| 4216 | { |
| 4217 | do_zoom(seat, time, key, 0, 0); |
| 4218 | } |
| 4219 | |
| 4220 | static void |
Kristian Høgsberg | e314875 | 2013-05-06 23:19:49 -0400 | [diff] [blame] | 4221 | terminate_binding(struct weston_seat *seat, uint32_t time, uint32_t key, |
Daniel Stone | 325fc2d | 2012-05-30 16:31:58 +0100 | [diff] [blame] | 4222 | void *data) |
Kristian Høgsberg | e1a850e | 2011-12-19 15:18:05 -0500 | [diff] [blame] | 4223 | { |
Kristian Høgsberg | 8334bc1 | 2012-01-03 10:29:47 -0500 | [diff] [blame] | 4224 | struct weston_compositor *compositor = data; |
Kristian Høgsberg | e1a850e | 2011-12-19 15:18:05 -0500 | [diff] [blame] | 4225 | |
Daniel Stone | 325fc2d | 2012-05-30 16:31:58 +0100 | [diff] [blame] | 4226 | wl_display_terminate(compositor->wl_display); |
Kristian Høgsberg | e1a850e | 2011-12-19 15:18:05 -0500 | [diff] [blame] | 4227 | } |
| 4228 | |
Emilio Pozuelo Monfort | 03251b6 | 2013-11-19 11:37:16 +0100 | [diff] [blame] | 4229 | static void |
Giulio Camuffo | 1959ab8 | 2013-11-14 23:42:52 +0100 | [diff] [blame] | 4230 | rotate_grab_motion(struct weston_pointer_grab *grab, uint32_t time, |
| 4231 | wl_fixed_t x, wl_fixed_t y) |
Pekka Paalanen | 460099f | 2012-01-20 16:48:25 +0200 | [diff] [blame] | 4232 | { |
| 4233 | struct rotate_grab *rotate = |
Ander Conselvan de Oliveira | fe0444a | 2012-04-04 17:48:05 +0300 | [diff] [blame] | 4234 | container_of(grab, struct rotate_grab, base.grab); |
Kristian Høgsberg | 02bbabb | 2013-05-06 22:15:05 -0400 | [diff] [blame] | 4235 | struct weston_pointer *pointer = grab->pointer; |
Ander Conselvan de Oliveira | fe0444a | 2012-04-04 17:48:05 +0300 | [diff] [blame] | 4236 | struct shell_surface *shsurf = rotate->base.shsurf; |
John Kåre Alsaker | 490d02a | 2012-09-30 02:57:21 +0200 | [diff] [blame] | 4237 | float cx, cy, dx, dy, cposx, cposy, dposx, dposy, r; |
Ander Conselvan de Oliveira | fe0444a | 2012-04-04 17:48:05 +0300 | [diff] [blame] | 4238 | |
Giulio Camuffo | 1959ab8 | 2013-11-14 23:42:52 +0100 | [diff] [blame] | 4239 | weston_pointer_move(pointer, x, y); |
| 4240 | |
Ander Conselvan de Oliveira | fe0444a | 2012-04-04 17:48:05 +0300 | [diff] [blame] | 4241 | if (!shsurf) |
| 4242 | return; |
| 4243 | |
Jason Ekstrand | 918f2dd | 2013-12-02 21:01:53 -0600 | [diff] [blame] | 4244 | cx = 0.5f * shsurf->surface->width; |
| 4245 | cy = 0.5f * shsurf->surface->height; |
Pekka Paalanen | 460099f | 2012-01-20 16:48:25 +0200 | [diff] [blame] | 4246 | |
Daniel Stone | 37816df | 2012-05-16 18:45:18 +0100 | [diff] [blame] | 4247 | dx = wl_fixed_to_double(pointer->x) - rotate->center.x; |
| 4248 | dy = wl_fixed_to_double(pointer->y) - rotate->center.y; |
Pekka Paalanen | 460099f | 2012-01-20 16:48:25 +0200 | [diff] [blame] | 4249 | r = sqrtf(dx * dx + dy * dy); |
| 4250 | |
Ander Conselvan de Oliveira | fe0444a | 2012-04-04 17:48:05 +0300 | [diff] [blame] | 4251 | wl_list_remove(&shsurf->rotation.transform.link); |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 4252 | weston_view_geometry_dirty(shsurf->view); |
Pekka Paalanen | 460099f | 2012-01-20 16:48:25 +0200 | [diff] [blame] | 4253 | |
| 4254 | if (r > 20.0f) { |
Pekka Paalanen | 460099f | 2012-01-20 16:48:25 +0200 | [diff] [blame] | 4255 | struct weston_matrix *matrix = |
Ander Conselvan de Oliveira | fe0444a | 2012-04-04 17:48:05 +0300 | [diff] [blame] | 4256 | &shsurf->rotation.transform.matrix; |
Pekka Paalanen | 460099f | 2012-01-20 16:48:25 +0200 | [diff] [blame] | 4257 | |
Kristian Høgsberg | 765e27b | 2012-01-27 13:36:13 -0500 | [diff] [blame] | 4258 | weston_matrix_init(&rotate->rotation); |
Vasily Khoruzhick | 1bbf372 | 2013-01-28 22:40:28 +0300 | [diff] [blame] | 4259 | weston_matrix_rotate_xy(&rotate->rotation, dx / r, dy / r); |
Pekka Paalanen | 460099f | 2012-01-20 16:48:25 +0200 | [diff] [blame] | 4260 | |
| 4261 | weston_matrix_init(matrix); |
Pekka Paalanen | 7b3bd3d | 2012-01-30 14:16:34 +0200 | [diff] [blame] | 4262 | weston_matrix_translate(matrix, -cx, -cy, 0.0f); |
Ander Conselvan de Oliveira | fe0444a | 2012-04-04 17:48:05 +0300 | [diff] [blame] | 4263 | weston_matrix_multiply(matrix, &shsurf->rotation.rotation); |
Kristian Høgsberg | 765e27b | 2012-01-27 13:36:13 -0500 | [diff] [blame] | 4264 | weston_matrix_multiply(matrix, &rotate->rotation); |
Pekka Paalanen | 7b3bd3d | 2012-01-30 14:16:34 +0200 | [diff] [blame] | 4265 | weston_matrix_translate(matrix, cx, cy, 0.0f); |
Pekka Paalanen | 460099f | 2012-01-20 16:48:25 +0200 | [diff] [blame] | 4266 | |
Pekka Paalanen | bc0b7e7 | 2012-01-24 09:53:37 +0200 | [diff] [blame] | 4267 | wl_list_insert( |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 4268 | &shsurf->view->geometry.transformation_list, |
Ander Conselvan de Oliveira | fe0444a | 2012-04-04 17:48:05 +0300 | [diff] [blame] | 4269 | &shsurf->rotation.transform.link); |
Pekka Paalanen | 460099f | 2012-01-20 16:48:25 +0200 | [diff] [blame] | 4270 | } else { |
Ander Conselvan de Oliveira | fe0444a | 2012-04-04 17:48:05 +0300 | [diff] [blame] | 4271 | wl_list_init(&shsurf->rotation.transform.link); |
| 4272 | weston_matrix_init(&shsurf->rotation.rotation); |
Kristian Høgsberg | 765e27b | 2012-01-27 13:36:13 -0500 | [diff] [blame] | 4273 | weston_matrix_init(&rotate->rotation); |
Pekka Paalanen | 460099f | 2012-01-20 16:48:25 +0200 | [diff] [blame] | 4274 | } |
Pekka Paalanen | b45ac5e | 2012-02-09 15:58:44 +0200 | [diff] [blame] | 4275 | |
Rafal Mielniczuk | 2d7ab82 | 2012-03-22 22:22:04 +0100 | [diff] [blame] | 4276 | /* We need to adjust the position of the surface |
| 4277 | * in case it was resized in a rotated state before */ |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 4278 | cposx = shsurf->view->geometry.x + cx; |
| 4279 | cposy = shsurf->view->geometry.y + cy; |
Rafal Mielniczuk | 2d7ab82 | 2012-03-22 22:22:04 +0100 | [diff] [blame] | 4280 | dposx = rotate->center.x - cposx; |
| 4281 | dposy = rotate->center.y - cposy; |
| 4282 | if (dposx != 0.0f || dposy != 0.0f) { |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 4283 | weston_view_set_position(shsurf->view, |
| 4284 | shsurf->view->geometry.x + dposx, |
| 4285 | shsurf->view->geometry.y + dposy); |
Rafal Mielniczuk | 2d7ab82 | 2012-03-22 22:22:04 +0100 | [diff] [blame] | 4286 | } |
| 4287 | |
Pekka Paalanen | b45ac5e | 2012-02-09 15:58:44 +0200 | [diff] [blame] | 4288 | /* Repaint implies weston_surface_update_transform(), which |
| 4289 | * lazily applies the damage due to rotation update. |
| 4290 | */ |
Ander Conselvan de Oliveira | fe0444a | 2012-04-04 17:48:05 +0300 | [diff] [blame] | 4291 | weston_compositor_schedule_repaint(shsurf->surface->compositor); |
Pekka Paalanen | 460099f | 2012-01-20 16:48:25 +0200 | [diff] [blame] | 4292 | } |
| 4293 | |
| 4294 | static void |
Kristian Høgsberg | 02bbabb | 2013-05-06 22:15:05 -0400 | [diff] [blame] | 4295 | rotate_grab_button(struct weston_pointer_grab *grab, |
| 4296 | uint32_t time, uint32_t button, uint32_t state_w) |
Pekka Paalanen | 460099f | 2012-01-20 16:48:25 +0200 | [diff] [blame] | 4297 | { |
| 4298 | struct rotate_grab *rotate = |
Ander Conselvan de Oliveira | fe0444a | 2012-04-04 17:48:05 +0300 | [diff] [blame] | 4299 | container_of(grab, struct rotate_grab, base.grab); |
Kristian Høgsberg | 02bbabb | 2013-05-06 22:15:05 -0400 | [diff] [blame] | 4300 | struct weston_pointer *pointer = grab->pointer; |
Ander Conselvan de Oliveira | fe0444a | 2012-04-04 17:48:05 +0300 | [diff] [blame] | 4301 | struct shell_surface *shsurf = rotate->base.shsurf; |
Daniel Stone | 4dbadb1 | 2012-05-30 16:31:51 +0100 | [diff] [blame] | 4302 | enum wl_pointer_button_state state = state_w; |
Pekka Paalanen | 460099f | 2012-01-20 16:48:25 +0200 | [diff] [blame] | 4303 | |
Daniel Stone | 4dbadb1 | 2012-05-30 16:31:51 +0100 | [diff] [blame] | 4304 | if (pointer->button_count == 0 && |
| 4305 | state == WL_POINTER_BUTTON_STATE_RELEASED) { |
Ander Conselvan de Oliveira | fe0444a | 2012-04-04 17:48:05 +0300 | [diff] [blame] | 4306 | if (shsurf) |
| 4307 | weston_matrix_multiply(&shsurf->rotation.rotation, |
| 4308 | &rotate->rotation); |
Ander Conselvan de Oliveira | b9d2a0f | 2012-06-28 18:08:05 +0300 | [diff] [blame] | 4309 | shell_grab_end(&rotate->base); |
Pekka Paalanen | 460099f | 2012-01-20 16:48:25 +0200 | [diff] [blame] | 4310 | free(rotate); |
| 4311 | } |
| 4312 | } |
| 4313 | |
Jonas Ådahl | 1ea343e | 2013-10-25 23:18:05 +0200 | [diff] [blame] | 4314 | static void |
| 4315 | rotate_grab_cancel(struct weston_pointer_grab *grab) |
| 4316 | { |
| 4317 | struct rotate_grab *rotate = |
| 4318 | container_of(grab, struct rotate_grab, base.grab); |
| 4319 | |
| 4320 | shell_grab_end(&rotate->base); |
| 4321 | free(rotate); |
| 4322 | } |
| 4323 | |
Kristian Høgsberg | 02bbabb | 2013-05-06 22:15:05 -0400 | [diff] [blame] | 4324 | static const struct weston_pointer_grab_interface rotate_grab_interface = { |
Pekka Paalanen | 460099f | 2012-01-20 16:48:25 +0200 | [diff] [blame] | 4325 | noop_grab_focus, |
| 4326 | rotate_grab_motion, |
| 4327 | rotate_grab_button, |
Jonas Ådahl | 1ea343e | 2013-10-25 23:18:05 +0200 | [diff] [blame] | 4328 | rotate_grab_cancel, |
Pekka Paalanen | 460099f | 2012-01-20 16:48:25 +0200 | [diff] [blame] | 4329 | }; |
| 4330 | |
| 4331 | static void |
Kristian Høgsberg | e314875 | 2013-05-06 23:19:49 -0400 | [diff] [blame] | 4332 | surface_rotate(struct shell_surface *surface, struct weston_seat *seat) |
Pekka Paalanen | 460099f | 2012-01-20 16:48:25 +0200 | [diff] [blame] | 4333 | { |
Pekka Paalanen | 460099f | 2012-01-20 16:48:25 +0200 | [diff] [blame] | 4334 | struct rotate_grab *rotate; |
John Kåre Alsaker | 490d02a | 2012-09-30 02:57:21 +0200 | [diff] [blame] | 4335 | float dx, dy; |
| 4336 | float r; |
Pekka Paalanen | 460099f | 2012-01-20 16:48:25 +0200 | [diff] [blame] | 4337 | |
Pekka Paalanen | 460099f | 2012-01-20 16:48:25 +0200 | [diff] [blame] | 4338 | rotate = malloc(sizeof *rotate); |
| 4339 | if (!rotate) |
| 4340 | return; |
| 4341 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 4342 | weston_view_to_global_float(surface->view, |
Jason Ekstrand | 918f2dd | 2013-12-02 21:01:53 -0600 | [diff] [blame] | 4343 | surface->surface->width * 0.5f, |
| 4344 | surface->surface->height * 0.5f, |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 4345 | &rotate->center.x, &rotate->center.y); |
Pekka Paalanen | 460099f | 2012-01-20 16:48:25 +0200 | [diff] [blame] | 4346 | |
Daniel Stone | 37816df | 2012-05-16 18:45:18 +0100 | [diff] [blame] | 4347 | dx = wl_fixed_to_double(seat->pointer->x) - rotate->center.x; |
| 4348 | dy = wl_fixed_to_double(seat->pointer->y) - rotate->center.y; |
Kristian Høgsberg | 765e27b | 2012-01-27 13:36:13 -0500 | [diff] [blame] | 4349 | r = sqrtf(dx * dx + dy * dy); |
| 4350 | if (r > 20.0f) { |
| 4351 | struct weston_matrix inverse; |
| 4352 | |
| 4353 | weston_matrix_init(&inverse); |
Vasily Khoruzhick | 1bbf372 | 2013-01-28 22:40:28 +0300 | [diff] [blame] | 4354 | weston_matrix_rotate_xy(&inverse, dx / r, -dy / r); |
Kristian Høgsberg | 765e27b | 2012-01-27 13:36:13 -0500 | [diff] [blame] | 4355 | weston_matrix_multiply(&surface->rotation.rotation, &inverse); |
Rafal Mielniczuk | 2d7ab82 | 2012-03-22 22:22:04 +0100 | [diff] [blame] | 4356 | |
| 4357 | weston_matrix_init(&rotate->rotation); |
Vasily Khoruzhick | 1bbf372 | 2013-01-28 22:40:28 +0300 | [diff] [blame] | 4358 | weston_matrix_rotate_xy(&rotate->rotation, dx / r, dy / r); |
Kristian Høgsberg | 765e27b | 2012-01-27 13:36:13 -0500 | [diff] [blame] | 4359 | } else { |
| 4360 | weston_matrix_init(&surface->rotation.rotation); |
| 4361 | weston_matrix_init(&rotate->rotation); |
| 4362 | } |
| 4363 | |
Ander Conselvan de Oliveira | b9d2a0f | 2012-06-28 18:08:05 +0300 | [diff] [blame] | 4364 | shell_grab_start(&rotate->base, &rotate_grab_interface, surface, |
| 4365 | seat->pointer, DESKTOP_SHELL_CURSOR_ARROW); |
Pekka Paalanen | 460099f | 2012-01-20 16:48:25 +0200 | [diff] [blame] | 4366 | } |
| 4367 | |
| 4368 | static void |
Kristian Høgsberg | e314875 | 2013-05-06 23:19:49 -0400 | [diff] [blame] | 4369 | 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] | 4370 | void *data) |
| 4371 | { |
Rafal Mielniczuk | b2917a2 | 2014-01-05 20:04:59 +0100 | [diff] [blame] | 4372 | struct weston_surface *focus; |
Pekka Paalanen | 01388e2 | 2013-04-25 13:57:44 +0300 | [diff] [blame] | 4373 | struct weston_surface *base_surface; |
Kristian Høgsberg | 0c36903 | 2013-02-14 21:31:44 -0500 | [diff] [blame] | 4374 | struct shell_surface *surface; |
| 4375 | |
Rafal Mielniczuk | b2917a2 | 2014-01-05 20:04:59 +0100 | [diff] [blame] | 4376 | if (seat->pointer->focus == NULL) |
| 4377 | return; |
| 4378 | |
| 4379 | focus = seat->pointer->focus->surface; |
| 4380 | |
Pekka Paalanen | 01388e2 | 2013-04-25 13:57:44 +0300 | [diff] [blame] | 4381 | base_surface = weston_surface_get_main_surface(focus); |
Kristian Høgsberg | 0c36903 | 2013-02-14 21:31:44 -0500 | [diff] [blame] | 4382 | if (base_surface == NULL) |
| 4383 | return; |
| 4384 | |
| 4385 | surface = get_shell_surface(base_surface); |
Rafael Antognolli | 03b1659 | 2013-12-03 15:35:42 -0200 | [diff] [blame] | 4386 | if (surface == NULL || surface->state.fullscreen || |
| 4387 | surface->state.maximized) |
Kristian Høgsberg | 0c36903 | 2013-02-14 21:31:44 -0500 | [diff] [blame] | 4388 | return; |
| 4389 | |
| 4390 | surface_rotate(surface, seat); |
| 4391 | } |
| 4392 | |
Philip Withnall | 83ffd9d | 2013-11-25 18:01:42 +0000 | [diff] [blame] | 4393 | /* Move all fullscreen layers down to the current workspace in a non-reversible |
| 4394 | * manner. This should be used when implementing shell-wide overlays, such as |
| 4395 | * the alt-tab switcher, which need to de-promote fullscreen layers. */ |
Kristian Høgsberg | 1ef2313 | 2013-12-04 00:20:01 -0800 | [diff] [blame] | 4396 | void |
Kristian Høgsberg | b0d8e77 | 2012-06-18 16:34:58 -0400 | [diff] [blame] | 4397 | lower_fullscreen_layer(struct desktop_shell *shell) |
| 4398 | { |
| 4399 | struct workspace *ws; |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 4400 | struct weston_view *view, *prev; |
Kristian Høgsberg | b0d8e77 | 2012-06-18 16:34:58 -0400 | [diff] [blame] | 4401 | |
| 4402 | ws = get_current_workspace(shell); |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 4403 | wl_list_for_each_reverse_safe(view, prev, |
| 4404 | &shell->fullscreen_layer.view_list, |
Philip Withnall | 83ffd9d | 2013-11-25 18:01:42 +0000 | [diff] [blame] | 4405 | layer_link) { |
| 4406 | wl_list_remove(&view->layer_link); |
| 4407 | wl_list_insert(&ws->layer.view_list, &view->layer_link); |
| 4408 | weston_view_damage_below(view); |
| 4409 | weston_surface_damage(view->surface); |
| 4410 | } |
Kristian Høgsberg | b0d8e77 | 2012-06-18 16:34:58 -0400 | [diff] [blame] | 4411 | } |
| 4412 | |
Kristian Høgsberg | 1ef2313 | 2013-12-04 00:20:01 -0800 | [diff] [blame] | 4413 | void |
Tiago Vignatti | be14326 | 2012-04-16 17:31:41 +0300 | [diff] [blame] | 4414 | activate(struct desktop_shell *shell, struct weston_surface *es, |
Daniel Stone | 37816df | 2012-05-16 18:45:18 +0100 | [diff] [blame] | 4415 | struct weston_seat *seat) |
Kristian Høgsberg | 7584062 | 2011-09-06 13:48:16 -0400 | [diff] [blame] | 4416 | { |
Pekka Paalanen | 01388e2 | 2013-04-25 13:57:44 +0300 | [diff] [blame] | 4417 | struct weston_surface *main_surface; |
Kristian Høgsberg | 2f5faff | 2012-07-31 16:36:34 -0400 | [diff] [blame] | 4418 | struct focus_state *state; |
Jonas Ådahl | 8538b22 | 2012-08-29 22:13:03 +0200 | [diff] [blame] | 4419 | struct workspace *ws; |
Louis-Francis Ratté-Boulianne | b482dbd | 2013-11-19 11:37:11 +0100 | [diff] [blame] | 4420 | struct weston_surface *old_es; |
Rafael Antognolli | 03b1659 | 2013-12-03 15:35:42 -0200 | [diff] [blame] | 4421 | struct shell_surface *shsurf; |
Kristian Høgsberg | 7584062 | 2011-09-06 13:48:16 -0400 | [diff] [blame] | 4422 | |
Pekka Paalanen | 01388e2 | 2013-04-25 13:57:44 +0300 | [diff] [blame] | 4423 | main_surface = weston_surface_get_main_surface(es); |
| 4424 | |
Daniel Stone | 37816df | 2012-05-16 18:45:18 +0100 | [diff] [blame] | 4425 | weston_surface_activate(es, seat); |
Kristian Høgsberg | 7584062 | 2011-09-06 13:48:16 -0400 | [diff] [blame] | 4426 | |
Jonas Ådahl | 8538b22 | 2012-08-29 22:13:03 +0200 | [diff] [blame] | 4427 | state = ensure_focus_state(shell, seat); |
| 4428 | if (state == NULL) |
| 4429 | return; |
Kristian Høgsberg | 2f5faff | 2012-07-31 16:36:34 -0400 | [diff] [blame] | 4430 | |
Louis-Francis Ratté-Boulianne | b482dbd | 2013-11-19 11:37:11 +0100 | [diff] [blame] | 4431 | old_es = state->keyboard_focus; |
Kristian Høgsberg | d500bf1 | 2014-01-22 12:25:20 -0800 | [diff] [blame] | 4432 | focus_state_set_focus(state, es); |
Kristian Høgsberg | 2f5faff | 2012-07-31 16:36:34 -0400 | [diff] [blame] | 4433 | |
Rafael Antognolli | 03b1659 | 2013-12-03 15:35:42 -0200 | [diff] [blame] | 4434 | shsurf = get_shell_surface(main_surface); |
U. Artie Eoff | cf5737a | 2014-01-17 10:08:25 -0800 | [diff] [blame] | 4435 | assert(shsurf); |
| 4436 | |
Rafael Antognolli | 03b1659 | 2013-12-03 15:35:42 -0200 | [diff] [blame] | 4437 | if (shsurf->state.fullscreen) |
| 4438 | shell_configure_fullscreen(shsurf); |
| 4439 | else |
Alexander Larsson | f82b6ca | 2013-05-28 16:23:39 +0200 | [diff] [blame] | 4440 | restore_all_output_modes(shell->compositor); |
Louis-Francis Ratté-Boulianne | b482dbd | 2013-11-19 11:37:11 +0100 | [diff] [blame] | 4441 | |
Emilio Pozuelo Monfort | 7908bff | 2014-01-30 13:49:39 +0100 | [diff] [blame] | 4442 | /* Update the surface’s layer. This brings it to the top of the stacking |
| 4443 | * order as appropriate. */ |
| 4444 | shell_surface_update_layer(shsurf); |
| 4445 | |
Philip Withnall | 83ffd9d | 2013-11-25 18:01:42 +0000 | [diff] [blame] | 4446 | if (shell->focus_animation_type != ANIMATION_NONE) { |
| 4447 | ws = get_current_workspace(shell); |
Louis-Francis Ratté-Boulianne | b482dbd | 2013-11-19 11:37:11 +0100 | [diff] [blame] | 4448 | 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] | 4449 | } |
Kristian Høgsberg | 7584062 | 2011-09-06 13:48:16 -0400 | [diff] [blame] | 4450 | } |
| 4451 | |
Alex Wu | 2185843 | 2012-04-01 20:13:08 +0800 | [diff] [blame] | 4452 | /* no-op func for checking black surface */ |
| 4453 | static void |
Jason Ekstrand | 918f2dd | 2013-12-02 21:01:53 -0600 | [diff] [blame] | 4454 | 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] | 4455 | { |
| 4456 | } |
| 4457 | |
Quentin Glidic | c0d79ce | 2013-01-29 14:16:13 +0100 | [diff] [blame] | 4458 | static bool |
Alex Wu | 2185843 | 2012-04-01 20:13:08 +0800 | [diff] [blame] | 4459 | is_black_surface (struct weston_surface *es, struct weston_surface **fs_surface) |
| 4460 | { |
| 4461 | if (es->configure == black_surface_configure) { |
| 4462 | if (fs_surface) |
Giulio Camuffo | 7fe01b1 | 2013-03-28 18:02:42 +0100 | [diff] [blame] | 4463 | *fs_surface = (struct weston_surface *)es->configure_private; |
Alex Wu | 2185843 | 2012-04-01 20:13:08 +0800 | [diff] [blame] | 4464 | return true; |
| 4465 | } |
| 4466 | return false; |
| 4467 | } |
| 4468 | |
Kristian Høgsberg | 7584062 | 2011-09-06 13:48:16 -0400 | [diff] [blame] | 4469 | static void |
Neil Roberts | a28c693 | 2013-10-03 16:43:04 +0100 | [diff] [blame] | 4470 | activate_binding(struct weston_seat *seat, |
| 4471 | struct desktop_shell *shell, |
| 4472 | struct weston_surface *focus) |
Kristian Høgsberg | e1a850e | 2011-12-19 15:18:05 -0500 | [diff] [blame] | 4473 | { |
Pekka Paalanen | 01388e2 | 2013-04-25 13:57:44 +0300 | [diff] [blame] | 4474 | struct weston_surface *main_surface; |
Kristian Høgsberg | e1a850e | 2011-12-19 15:18:05 -0500 | [diff] [blame] | 4475 | |
Alex Wu | 9c35e6b | 2012-03-05 14:13:13 +0800 | [diff] [blame] | 4476 | if (!focus) |
| 4477 | return; |
| 4478 | |
Pekka Paalanen | 01388e2 | 2013-04-25 13:57:44 +0300 | [diff] [blame] | 4479 | if (is_black_surface(focus, &main_surface)) |
| 4480 | focus = main_surface; |
Alex Wu | 4539b08 | 2012-03-01 12:57:46 +0800 | [diff] [blame] | 4481 | |
Pekka Paalanen | 01388e2 | 2013-04-25 13:57:44 +0300 | [diff] [blame] | 4482 | main_surface = weston_surface_get_main_surface(focus); |
| 4483 | if (get_shell_surface_type(main_surface) == SHELL_SURFACE_NONE) |
Kristian Høgsberg | 0636ac3 | 2012-06-27 10:22:15 -0400 | [diff] [blame] | 4484 | return; |
Kristian Høgsberg | 85b2e4b | 2012-06-21 16:49:42 -0400 | [diff] [blame] | 4485 | |
Neil Roberts | a28c693 | 2013-10-03 16:43:04 +0100 | [diff] [blame] | 4486 | activate(shell, focus, seat); |
| 4487 | } |
| 4488 | |
| 4489 | static void |
| 4490 | click_to_activate_binding(struct weston_seat *seat, uint32_t time, uint32_t button, |
| 4491 | void *data) |
| 4492 | { |
| 4493 | if (seat->pointer->grab != &seat->pointer->default_grab) |
| 4494 | return; |
Kristian Høgsberg | 7c4f6cc | 2014-01-01 16:28:32 -0800 | [diff] [blame] | 4495 | if (seat->pointer->focus == NULL) |
| 4496 | return; |
Neil Roberts | a28c693 | 2013-10-03 16:43:04 +0100 | [diff] [blame] | 4497 | |
Kristian Høgsberg | 7ab139c | 2013-10-24 16:21:39 -0700 | [diff] [blame] | 4498 | activate_binding(seat, data, seat->pointer->focus->surface); |
Neil Roberts | a28c693 | 2013-10-03 16:43:04 +0100 | [diff] [blame] | 4499 | } |
| 4500 | |
| 4501 | static void |
| 4502 | touch_to_activate_binding(struct weston_seat *seat, uint32_t time, void *data) |
| 4503 | { |
| 4504 | if (seat->touch->grab != &seat->touch->default_grab) |
| 4505 | return; |
Kristian Høgsberg | 0ed6750 | 2014-01-02 23:00:11 -0800 | [diff] [blame] | 4506 | if (seat->touch->focus == NULL) |
| 4507 | return; |
Neil Roberts | a28c693 | 2013-10-03 16:43:04 +0100 | [diff] [blame] | 4508 | |
Kristian Høgsberg | 7ab139c | 2013-10-24 16:21:39 -0700 | [diff] [blame] | 4509 | activate_binding(seat, data, seat->touch->focus->surface); |
Kristian Høgsberg | e1a850e | 2011-12-19 15:18:05 -0500 | [diff] [blame] | 4510 | } |
| 4511 | |
| 4512 | static void |
Neil Roberts | b4a9170 | 2014-04-09 16:33:32 +0100 | [diff] [blame] | 4513 | unfocus_all_seats(struct desktop_shell *shell) |
| 4514 | { |
| 4515 | struct weston_seat *seat, *next; |
| 4516 | |
| 4517 | wl_list_for_each_safe(seat, next, &shell->compositor->seat_list, link) { |
| 4518 | if (seat->keyboard == NULL) |
| 4519 | continue; |
| 4520 | |
| 4521 | weston_keyboard_set_focus(seat->keyboard, NULL); |
| 4522 | } |
| 4523 | } |
| 4524 | |
| 4525 | static void |
Ander Conselvan de Oliveira | 19d10ef | 2013-02-21 18:35:20 +0200 | [diff] [blame] | 4526 | lock(struct desktop_shell *shell) |
Kristian Høgsberg | 02ec0a5 | 2011-04-23 13:04:11 -0400 | [diff] [blame] | 4527 | { |
Kristian Høgsberg | 4476aaf | 2012-06-25 14:03:13 -0400 | [diff] [blame] | 4528 | struct workspace *ws = get_current_workspace(shell); |
Pekka Paalanen | f0fc70d | 2011-11-15 13:34:54 +0200 | [diff] [blame] | 4529 | |
Tiago Vignatti | 8e53c7f | 2012-02-29 19:53:50 +0200 | [diff] [blame] | 4530 | if (shell->locked) { |
Ander Conselvan de Oliveira | 87524b6 | 2013-02-21 18:35:22 +0200 | [diff] [blame] | 4531 | weston_compositor_sleep(shell->compositor); |
Pekka Paalanen | f0fc70d | 2011-11-15 13:34:54 +0200 | [diff] [blame] | 4532 | return; |
Tiago Vignatti | 8e53c7f | 2012-02-29 19:53:50 +0200 | [diff] [blame] | 4533 | } |
Pekka Paalanen | 9ef3e01 | 2011-11-15 13:34:48 +0200 | [diff] [blame] | 4534 | |
| 4535 | shell->locked = true; |
Pekka Paalanen | f0fc70d | 2011-11-15 13:34:54 +0200 | [diff] [blame] | 4536 | |
Kristian Høgsberg | 3be2ce9 | 2012-02-29 12:42:35 -0500 | [diff] [blame] | 4537 | /* Hide all surfaces by removing the fullscreen, panel and |
| 4538 | * toplevel layers. This way nothing else can show or receive |
| 4539 | * input events while we are locked. */ |
Pekka Paalanen | f0fc70d | 2011-11-15 13:34:54 +0200 | [diff] [blame] | 4540 | |
Kristian Høgsberg | 3be2ce9 | 2012-02-29 12:42:35 -0500 | [diff] [blame] | 4541 | wl_list_remove(&shell->panel_layer.link); |
Kristian Høgsberg | 3be2ce9 | 2012-02-29 12:42:35 -0500 | [diff] [blame] | 4542 | wl_list_remove(&shell->fullscreen_layer.link); |
Philipp Brüschweiler | 711fda8 | 2012-08-09 18:50:43 +0200 | [diff] [blame] | 4543 | if (shell->showing_input_panels) |
| 4544 | wl_list_remove(&shell->input_panel_layer.link); |
Kristian Høgsberg | 4476aaf | 2012-06-25 14:03:13 -0400 | [diff] [blame] | 4545 | wl_list_remove(&ws->layer.link); |
Kristian Høgsberg | 3be2ce9 | 2012-02-29 12:42:35 -0500 | [diff] [blame] | 4546 | wl_list_insert(&shell->compositor->cursor_layer.link, |
| 4547 | &shell->lock_layer.link); |
Pekka Paalanen | f0fc70d | 2011-11-15 13:34:54 +0200 | [diff] [blame] | 4548 | |
Pekka Paalanen | 77346a6 | 2011-11-30 16:26:35 +0200 | [diff] [blame] | 4549 | launch_screensaver(shell); |
| 4550 | |
Neil Roberts | b4a9170 | 2014-04-09 16:33:32 +0100 | [diff] [blame] | 4551 | /* Remove the keyboard focus on all seats. This will be |
| 4552 | * restored to the workspace's saved state via |
| 4553 | * restore_focus_state when the compositor is unlocked */ |
| 4554 | unfocus_all_seats(shell); |
| 4555 | |
Pekka Paalanen | f0fc70d | 2011-11-15 13:34:54 +0200 | [diff] [blame] | 4556 | /* TODO: disable bindings that should not work while locked. */ |
| 4557 | |
| 4558 | /* All this must be undone in resume_desktop(). */ |
Pekka Paalanen | 9ef3e01 | 2011-11-15 13:34:48 +0200 | [diff] [blame] | 4559 | } |
| 4560 | |
| 4561 | static void |
Ander Conselvan de Oliveira | 19d10ef | 2013-02-21 18:35:20 +0200 | [diff] [blame] | 4562 | unlock(struct desktop_shell *shell) |
Pekka Paalanen | 9ef3e01 | 2011-11-15 13:34:48 +0200 | [diff] [blame] | 4563 | { |
Pekka Paalanen | d81c216 | 2011-11-16 13:47:34 +0200 | [diff] [blame] | 4564 | if (!shell->locked || shell->lock_surface) { |
Ander Conselvan de Oliveira | 87524b6 | 2013-02-21 18:35:22 +0200 | [diff] [blame] | 4565 | shell_fade(shell, FADE_IN); |
Pekka Paalanen | 9ef3e01 | 2011-11-15 13:34:48 +0200 | [diff] [blame] | 4566 | return; |
| 4567 | } |
| 4568 | |
| 4569 | /* If desktop-shell client has gone away, unlock immediately. */ |
| 4570 | if (!shell->child.desktop_shell) { |
Pekka Paalanen | f0fc70d | 2011-11-15 13:34:54 +0200 | [diff] [blame] | 4571 | resume_desktop(shell); |
Pekka Paalanen | 9ef3e01 | 2011-11-15 13:34:48 +0200 | [diff] [blame] | 4572 | return; |
| 4573 | } |
| 4574 | |
| 4575 | if (shell->prepare_event_sent) |
| 4576 | return; |
| 4577 | |
Kristian Høgsberg | 0b5cd0c | 2012-03-04 21:57:37 -0500 | [diff] [blame] | 4578 | desktop_shell_send_prepare_lock_surface(shell->child.desktop_shell); |
Pekka Paalanen | 9ef3e01 | 2011-11-15 13:34:48 +0200 | [diff] [blame] | 4579 | shell->prepare_event_sent = true; |
Kristian Høgsberg | 02ec0a5 | 2011-04-23 13:04:11 -0400 | [diff] [blame] | 4580 | } |
| 4581 | |
| 4582 | static void |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 4583 | shell_fade_done(struct weston_view_animation *animation, void *data) |
Ander Conselvan de Oliveira | 19d10ef | 2013-02-21 18:35:20 +0200 | [diff] [blame] | 4584 | { |
| 4585 | struct desktop_shell *shell = data; |
| 4586 | |
| 4587 | shell->fade.animation = NULL; |
| 4588 | |
| 4589 | switch (shell->fade.type) { |
| 4590 | case FADE_IN: |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 4591 | weston_surface_destroy(shell->fade.view->surface); |
| 4592 | shell->fade.view = NULL; |
Ander Conselvan de Oliveira | 19d10ef | 2013-02-21 18:35:20 +0200 | [diff] [blame] | 4593 | break; |
| 4594 | case FADE_OUT: |
Ander Conselvan de Oliveira | 19d10ef | 2013-02-21 18:35:20 +0200 | [diff] [blame] | 4595 | lock(shell); |
| 4596 | break; |
Philip Withnall | 4a86a0a | 2013-11-25 18:01:32 +0000 | [diff] [blame] | 4597 | default: |
| 4598 | break; |
Ander Conselvan de Oliveira | 19d10ef | 2013-02-21 18:35:20 +0200 | [diff] [blame] | 4599 | } |
| 4600 | } |
| 4601 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 4602 | static struct weston_view * |
Pekka Paalanen | 79346ab | 2013-05-22 18:03:09 +0300 | [diff] [blame] | 4603 | shell_fade_create_surface(struct desktop_shell *shell) |
Ander Conselvan de Oliveira | 19d10ef | 2013-02-21 18:35:20 +0200 | [diff] [blame] | 4604 | { |
| 4605 | struct weston_compositor *compositor = shell->compositor; |
| 4606 | struct weston_surface *surface; |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 4607 | struct weston_view *view; |
Pekka Paalanen | 79346ab | 2013-05-22 18:03:09 +0300 | [diff] [blame] | 4608 | |
| 4609 | surface = weston_surface_create(compositor); |
| 4610 | if (!surface) |
| 4611 | return NULL; |
| 4612 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 4613 | view = weston_view_create(surface); |
| 4614 | if (!view) { |
| 4615 | weston_surface_destroy(surface); |
| 4616 | return NULL; |
| 4617 | } |
| 4618 | |
Jason Ekstrand | 5c11a33 | 2013-12-04 20:32:03 -0600 | [diff] [blame] | 4619 | weston_surface_set_size(surface, 8192, 8192); |
Jason Ekstrand | 918f2dd | 2013-12-02 21:01:53 -0600 | [diff] [blame] | 4620 | weston_view_set_position(view, 0, 0); |
Pekka Paalanen | 79346ab | 2013-05-22 18:03:09 +0300 | [diff] [blame] | 4621 | 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] | 4622 | wl_list_insert(&compositor->fade_layer.view_list, |
| 4623 | &view->layer_link); |
Pekka Paalanen | 79346ab | 2013-05-22 18:03:09 +0300 | [diff] [blame] | 4624 | pixman_region32_init(&surface->input); |
| 4625 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 4626 | return view; |
Pekka Paalanen | 79346ab | 2013-05-22 18:03:09 +0300 | [diff] [blame] | 4627 | } |
| 4628 | |
| 4629 | static void |
| 4630 | shell_fade(struct desktop_shell *shell, enum fade_type type) |
| 4631 | { |
Ander Conselvan de Oliveira | 19d10ef | 2013-02-21 18:35:20 +0200 | [diff] [blame] | 4632 | float tint; |
| 4633 | |
| 4634 | switch (type) { |
| 4635 | case FADE_IN: |
| 4636 | tint = 0.0; |
| 4637 | break; |
| 4638 | case FADE_OUT: |
| 4639 | tint = 1.0; |
| 4640 | break; |
| 4641 | default: |
| 4642 | weston_log("shell: invalid fade type\n"); |
| 4643 | return; |
| 4644 | } |
| 4645 | |
| 4646 | shell->fade.type = type; |
| 4647 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 4648 | if (shell->fade.view == NULL) { |
| 4649 | shell->fade.view = shell_fade_create_surface(shell); |
| 4650 | if (!shell->fade.view) |
Ander Conselvan de Oliveira | 19d10ef | 2013-02-21 18:35:20 +0200 | [diff] [blame] | 4651 | return; |
| 4652 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 4653 | shell->fade.view->alpha = 1.0 - tint; |
| 4654 | weston_view_update_transform(shell->fade.view); |
Ander Conselvan de Oliveira | 19d10ef | 2013-02-21 18:35:20 +0200 | [diff] [blame] | 4655 | } |
| 4656 | |
Kristian Høgsberg | 87d3b61 | 2014-01-19 21:48:10 -0800 | [diff] [blame] | 4657 | if (shell->fade.view->output == NULL) { |
| 4658 | /* If the black view gets a NULL output, we lost the |
| 4659 | * last output and we'll just cancel the fade. This |
| 4660 | * happens when you close the last window under the |
| 4661 | * X11 or Wayland backends. */ |
| 4662 | shell->locked = false; |
| 4663 | weston_surface_destroy(shell->fade.view->surface); |
| 4664 | shell->fade.view = NULL; |
| 4665 | } else if (shell->fade.animation) { |
Kristian Høgsberg | 5281fb1 | 2013-06-17 10:10:28 -0400 | [diff] [blame] | 4666 | weston_fade_update(shell->fade.animation, tint); |
Kristian Høgsberg | 87d3b61 | 2014-01-19 21:48:10 -0800 | [diff] [blame] | 4667 | } else { |
Ander Conselvan de Oliveira | 19d10ef | 2013-02-21 18:35:20 +0200 | [diff] [blame] | 4668 | shell->fade.animation = |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 4669 | weston_fade_run(shell->fade.view, |
Kristian Høgsberg | 5281fb1 | 2013-06-17 10:10:28 -0400 | [diff] [blame] | 4670 | 1.0 - tint, tint, 300.0, |
Ander Conselvan de Oliveira | 19d10ef | 2013-02-21 18:35:20 +0200 | [diff] [blame] | 4671 | shell_fade_done, shell); |
Kristian Høgsberg | 87d3b61 | 2014-01-19 21:48:10 -0800 | [diff] [blame] | 4672 | } |
Ander Conselvan de Oliveira | 19d10ef | 2013-02-21 18:35:20 +0200 | [diff] [blame] | 4673 | } |
| 4674 | |
| 4675 | static void |
Pekka Paalanen | 79346ab | 2013-05-22 18:03:09 +0300 | [diff] [blame] | 4676 | do_shell_fade_startup(void *data) |
| 4677 | { |
| 4678 | struct desktop_shell *shell = data; |
| 4679 | |
Kristian Høgsberg | 724c8d9 | 2013-10-16 11:38:24 -0700 | [diff] [blame] | 4680 | if (shell->startup_animation_type == ANIMATION_FADE) |
| 4681 | shell_fade(shell, FADE_IN); |
| 4682 | else if (shell->startup_animation_type == ANIMATION_NONE) { |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 4683 | weston_surface_destroy(shell->fade.view->surface); |
| 4684 | shell->fade.view = NULL; |
Kristian Høgsberg | 724c8d9 | 2013-10-16 11:38:24 -0700 | [diff] [blame] | 4685 | } |
Pekka Paalanen | 79346ab | 2013-05-22 18:03:09 +0300 | [diff] [blame] | 4686 | } |
| 4687 | |
| 4688 | static void |
| 4689 | shell_fade_startup(struct desktop_shell *shell) |
| 4690 | { |
| 4691 | struct wl_event_loop *loop; |
| 4692 | |
| 4693 | if (!shell->fade.startup_timer) |
| 4694 | return; |
| 4695 | |
| 4696 | wl_event_source_remove(shell->fade.startup_timer); |
| 4697 | shell->fade.startup_timer = NULL; |
| 4698 | |
| 4699 | loop = wl_display_get_event_loop(shell->compositor->wl_display); |
| 4700 | wl_event_loop_add_idle(loop, do_shell_fade_startup, shell); |
| 4701 | } |
| 4702 | |
| 4703 | static int |
| 4704 | fade_startup_timeout(void *data) |
| 4705 | { |
| 4706 | struct desktop_shell *shell = data; |
| 4707 | |
| 4708 | shell_fade_startup(shell); |
| 4709 | return 0; |
| 4710 | } |
| 4711 | |
| 4712 | static void |
| 4713 | shell_fade_init(struct desktop_shell *shell) |
| 4714 | { |
| 4715 | /* Make compositor output all black, and wait for the desktop-shell |
| 4716 | * client to signal it is ready, then fade in. The timer triggers a |
| 4717 | * fade-in, in case the desktop-shell client takes too long. |
| 4718 | */ |
| 4719 | |
| 4720 | struct wl_event_loop *loop; |
| 4721 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 4722 | if (shell->fade.view != NULL) { |
Pekka Paalanen | 79346ab | 2013-05-22 18:03:09 +0300 | [diff] [blame] | 4723 | weston_log("%s: warning: fade surface already exists\n", |
| 4724 | __func__); |
| 4725 | return; |
| 4726 | } |
| 4727 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 4728 | shell->fade.view = shell_fade_create_surface(shell); |
| 4729 | if (!shell->fade.view) |
Pekka Paalanen | 79346ab | 2013-05-22 18:03:09 +0300 | [diff] [blame] | 4730 | return; |
| 4731 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 4732 | weston_view_update_transform(shell->fade.view); |
| 4733 | weston_surface_damage(shell->fade.view->surface); |
Pekka Paalanen | 79346ab | 2013-05-22 18:03:09 +0300 | [diff] [blame] | 4734 | |
| 4735 | loop = wl_display_get_event_loop(shell->compositor->wl_display); |
| 4736 | shell->fade.startup_timer = |
| 4737 | wl_event_loop_add_timer(loop, fade_startup_timeout, shell); |
| 4738 | wl_event_source_timer_update(shell->fade.startup_timer, 15000); |
| 4739 | } |
| 4740 | |
| 4741 | static void |
Ander Conselvan de Oliveira | a457563 | 2013-02-21 18:35:23 +0200 | [diff] [blame] | 4742 | idle_handler(struct wl_listener *listener, void *data) |
Ander Conselvan de Oliveira | 19d10ef | 2013-02-21 18:35:20 +0200 | [diff] [blame] | 4743 | { |
| 4744 | struct desktop_shell *shell = |
Ander Conselvan de Oliveira | a457563 | 2013-02-21 18:35:23 +0200 | [diff] [blame] | 4745 | container_of(listener, struct desktop_shell, idle_listener); |
Kristian Høgsberg | 27d5fa8 | 2014-01-17 16:22:50 -0800 | [diff] [blame] | 4746 | struct weston_seat *seat; |
| 4747 | |
| 4748 | wl_list_for_each(seat, &shell->compositor->seat_list, link) |
| 4749 | if (seat->pointer) |
| 4750 | popup_grab_end(seat->pointer); |
Ander Conselvan de Oliveira | 19d10ef | 2013-02-21 18:35:20 +0200 | [diff] [blame] | 4751 | |
| 4752 | shell_fade(shell, FADE_OUT); |
| 4753 | /* lock() is called from shell_fade_done() */ |
| 4754 | } |
| 4755 | |
| 4756 | static void |
Ander Conselvan de Oliveira | a457563 | 2013-02-21 18:35:23 +0200 | [diff] [blame] | 4757 | wake_handler(struct wl_listener *listener, void *data) |
Ander Conselvan de Oliveira | 19d10ef | 2013-02-21 18:35:20 +0200 | [diff] [blame] | 4758 | { |
| 4759 | struct desktop_shell *shell = |
Ander Conselvan de Oliveira | a457563 | 2013-02-21 18:35:23 +0200 | [diff] [blame] | 4760 | container_of(listener, struct desktop_shell, wake_listener); |
Ander Conselvan de Oliveira | 19d10ef | 2013-02-21 18:35:20 +0200 | [diff] [blame] | 4761 | |
Ander Conselvan de Oliveira | 19d10ef | 2013-02-21 18:35:20 +0200 | [diff] [blame] | 4762 | unlock(shell); |
| 4763 | } |
| 4764 | |
| 4765 | static void |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 4766 | center_on_output(struct weston_view *view, struct weston_output *output) |
Pekka Paalanen | 77346a6 | 2011-11-30 16:26:35 +0200 | [diff] [blame] | 4767 | { |
Giulio Camuffo | b836664 | 2013-04-25 13:57:46 +0300 | [diff] [blame] | 4768 | int32_t surf_x, surf_y, width, height; |
Ander Conselvan de Oliveira | 012b4c7 | 2012-11-27 17:03:42 +0200 | [diff] [blame] | 4769 | float x, y; |
Pekka Paalanen | 77346a6 | 2011-11-30 16:26:35 +0200 | [diff] [blame] | 4770 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 4771 | surface_subsurfaces_boundingbox(view->surface, &surf_x, &surf_y, &width, &height); |
Giulio Camuffo | b836664 | 2013-04-25 13:57:46 +0300 | [diff] [blame] | 4772 | |
| 4773 | x = output->x + (output->width - width) / 2 - surf_x / 2; |
| 4774 | y = output->y + (output->height - height) / 2 - surf_y / 2; |
Ander Conselvan de Oliveira | 012b4c7 | 2012-11-27 17:03:42 +0200 | [diff] [blame] | 4775 | |
Jason Ekstrand | 918f2dd | 2013-12-02 21:01:53 -0600 | [diff] [blame] | 4776 | weston_view_set_position(view, x, y); |
Pekka Paalanen | 77346a6 | 2011-11-30 16:26:35 +0200 | [diff] [blame] | 4777 | } |
| 4778 | |
| 4779 | static void |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 4780 | weston_view_set_initial_position(struct weston_view *view, |
| 4781 | struct desktop_shell *shell) |
Rob Bradford | ac63e5b | 2012-08-13 14:07:52 +0100 | [diff] [blame] | 4782 | { |
| 4783 | struct weston_compositor *compositor = shell->compositor; |
| 4784 | int ix = 0, iy = 0; |
| 4785 | int range_x, range_y; |
| 4786 | int dx, dy, x, y, panel_height; |
| 4787 | struct weston_output *output, *target_output = NULL; |
| 4788 | struct weston_seat *seat; |
| 4789 | |
| 4790 | /* As a heuristic place the new window on the same output as the |
| 4791 | * pointer. Falling back to the output containing 0, 0. |
| 4792 | * |
| 4793 | * TODO: Do something clever for touch too? |
| 4794 | */ |
| 4795 | wl_list_for_each(seat, &compositor->seat_list, link) { |
Kristian Høgsberg | 2bf8762 | 2013-05-07 23:17:41 -0400 | [diff] [blame] | 4796 | if (seat->pointer) { |
Kristian Høgsberg | e314875 | 2013-05-06 23:19:49 -0400 | [diff] [blame] | 4797 | ix = wl_fixed_to_int(seat->pointer->x); |
| 4798 | iy = wl_fixed_to_int(seat->pointer->y); |
Rob Bradford | ac63e5b | 2012-08-13 14:07:52 +0100 | [diff] [blame] | 4799 | break; |
| 4800 | } |
| 4801 | } |
| 4802 | |
| 4803 | wl_list_for_each(output, &compositor->output_list, link) { |
| 4804 | if (pixman_region32_contains_point(&output->region, ix, iy, NULL)) { |
| 4805 | target_output = output; |
| 4806 | break; |
| 4807 | } |
| 4808 | } |
| 4809 | |
| 4810 | if (!target_output) { |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 4811 | weston_view_set_position(view, 10 + random() % 400, |
| 4812 | 10 + random() % 400); |
Rob Bradford | ac63e5b | 2012-08-13 14:07:52 +0100 | [diff] [blame] | 4813 | return; |
| 4814 | } |
| 4815 | |
| 4816 | /* Valid range within output where the surface will still be onscreen. |
| 4817 | * If this is negative it means that the surface is bigger than |
| 4818 | * output. |
| 4819 | */ |
| 4820 | panel_height = get_output_panel_height(shell, target_output); |
Jason Ekstrand | 918f2dd | 2013-12-02 21:01:53 -0600 | [diff] [blame] | 4821 | range_x = target_output->width - view->surface->width; |
Scott Moreau | 1bad5db | 2012-08-18 01:04:05 -0600 | [diff] [blame] | 4822 | range_y = (target_output->height - panel_height) - |
Jason Ekstrand | 918f2dd | 2013-12-02 21:01:53 -0600 | [diff] [blame] | 4823 | view->surface->height; |
Rob Bradford | ac63e5b | 2012-08-13 14:07:52 +0100 | [diff] [blame] | 4824 | |
Rob Bradford | 4cb88c7 | 2012-08-13 15:18:44 +0100 | [diff] [blame] | 4825 | if (range_x > 0) |
Rob Bradford | ac63e5b | 2012-08-13 14:07:52 +0100 | [diff] [blame] | 4826 | dx = random() % range_x; |
Rob Bradford | ac63e5b | 2012-08-13 14:07:52 +0100 | [diff] [blame] | 4827 | else |
Rob Bradford | 4cb88c7 | 2012-08-13 15:18:44 +0100 | [diff] [blame] | 4828 | dx = 0; |
| 4829 | |
| 4830 | if (range_y > 0) |
Rob Bradford | ac63e5b | 2012-08-13 14:07:52 +0100 | [diff] [blame] | 4831 | dy = panel_height + random() % range_y; |
Rob Bradford | 4cb88c7 | 2012-08-13 15:18:44 +0100 | [diff] [blame] | 4832 | else |
| 4833 | dy = panel_height; |
Rob Bradford | ac63e5b | 2012-08-13 14:07:52 +0100 | [diff] [blame] | 4834 | |
| 4835 | x = target_output->x + dx; |
| 4836 | y = target_output->y + dy; |
| 4837 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 4838 | weston_view_set_position(view, x, y); |
Rob Bradford | ac63e5b | 2012-08-13 14:07:52 +0100 | [diff] [blame] | 4839 | } |
| 4840 | |
| 4841 | static void |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 4842 | map(struct desktop_shell *shell, struct shell_surface *shsurf, |
Jason Ekstrand | 918f2dd | 2013-12-02 21:01:53 -0600 | [diff] [blame] | 4843 | int32_t sx, int32_t sy) |
Kristian Høgsberg | 02ec0a5 | 2011-04-23 13:04:11 -0400 | [diff] [blame] | 4844 | { |
Kristian Høgsberg | 8334bc1 | 2012-01-03 10:29:47 -0500 | [diff] [blame] | 4845 | struct weston_compositor *compositor = shell->compositor; |
Daniel Stone | b210468 | 2012-05-30 16:31:56 +0100 | [diff] [blame] | 4846 | struct weston_seat *seat; |
Juan Zhao | 96879df | 2012-02-07 08:45:41 +0800 | [diff] [blame] | 4847 | int panel_height = 0; |
Giulio Camuffo | b836664 | 2013-04-25 13:57:46 +0300 | [diff] [blame] | 4848 | int32_t surf_x, surf_y; |
Pekka Paalanen | 57da4a8 | 2011-11-23 16:42:16 +0200 | [diff] [blame] | 4849 | |
Pekka Paalanen | 77346a6 | 2011-11-30 16:26:35 +0200 | [diff] [blame] | 4850 | /* initial positioning, see also configure() */ |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 4851 | switch (shsurf->type) { |
Rafael Antognolli | ed207b4 | 2013-12-03 15:35:43 -0200 | [diff] [blame] | 4852 | case SHELL_SURFACE_TOPLEVEL: |
Rafael Antognolli | 03b1659 | 2013-12-03 15:35:42 -0200 | [diff] [blame] | 4853 | if (shsurf->state.fullscreen) { |
| 4854 | center_on_output(shsurf->view, shsurf->fullscreen_output); |
| 4855 | shell_map_fullscreen(shsurf); |
| 4856 | } else if (shsurf->state.maximized) { |
| 4857 | /* use surface configure to set the geometry */ |
| 4858 | panel_height = get_output_panel_height(shell, shsurf->output); |
| 4859 | surface_subsurfaces_boundingbox(shsurf->surface, |
| 4860 | &surf_x, &surf_y, NULL, NULL); |
| 4861 | weston_view_set_position(shsurf->view, |
| 4862 | shsurf->output->x - surf_x, |
| 4863 | shsurf->output->y + |
| 4864 | panel_height - surf_y); |
Rafael Antognolli | ed207b4 | 2013-12-03 15:35:43 -0200 | [diff] [blame] | 4865 | } else if (!shsurf->state.relative) { |
Rafael Antognolli | 03b1659 | 2013-12-03 15:35:42 -0200 | [diff] [blame] | 4866 | weston_view_set_initial_position(shsurf->view, shell); |
| 4867 | } |
Juan Zhao | 96879df | 2012-02-07 08:45:41 +0800 | [diff] [blame] | 4868 | break; |
Tiago Vignatti | 0f99701 | 2012-02-10 16:17:23 +0200 | [diff] [blame] | 4869 | case SHELL_SURFACE_POPUP: |
Kristian Høgsberg | 3730f36 | 2012-04-13 12:40:07 -0400 | [diff] [blame] | 4870 | shell_map_popup(shsurf); |
Rob Bradford | db99938 | 2012-12-06 12:07:48 +0000 | [diff] [blame] | 4871 | break; |
Ander Conselvan de Oliveira | e9e0515 | 2012-02-15 17:02:56 +0200 | [diff] [blame] | 4872 | case SHELL_SURFACE_NONE: |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 4873 | weston_view_set_position(shsurf->view, |
| 4874 | shsurf->view->geometry.x + sx, |
| 4875 | shsurf->view->geometry.y + sy); |
Tiago Vignatti | 0f99701 | 2012-02-10 16:17:23 +0200 | [diff] [blame] | 4876 | break; |
Philip Withnall | 0f640e2 | 2013-11-25 18:01:31 +0000 | [diff] [blame] | 4877 | case SHELL_SURFACE_XWAYLAND: |
Pekka Paalanen | 77346a6 | 2011-11-30 16:26:35 +0200 | [diff] [blame] | 4878 | default: |
| 4879 | ; |
| 4880 | } |
Kristian Høgsberg | 7584062 | 2011-09-06 13:48:16 -0400 | [diff] [blame] | 4881 | |
Philip Withnall | e1d75ae | 2013-11-25 18:01:41 +0000 | [diff] [blame] | 4882 | /* Surface stacking order, see also activate(). */ |
| 4883 | shell_surface_update_layer(shsurf); |
Pekka Paalanen | f0fc70d | 2011-11-15 13:34:54 +0200 | [diff] [blame] | 4884 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 4885 | if (shsurf->type != SHELL_SURFACE_NONE) { |
| 4886 | weston_view_update_transform(shsurf->view); |
Rafael Antognolli | 03b1659 | 2013-12-03 15:35:42 -0200 | [diff] [blame] | 4887 | if (shsurf->state.maximized) { |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 4888 | shsurf->surface->output = shsurf->output; |
| 4889 | shsurf->view->output = shsurf->output; |
| 4890 | } |
Ander Conselvan de Oliveira | de56c31 | 2012-03-05 15:39:23 +0200 | [diff] [blame] | 4891 | } |
Kristian Høgsberg | 2f88a40 | 2011-12-04 15:32:59 -0500 | [diff] [blame] | 4892 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 4893 | switch (shsurf->type) { |
Tiago Vignatti | fb2adba | 2013-06-12 15:43:21 -0300 | [diff] [blame] | 4894 | /* XXX: xwayland's using the same fields for transient type */ |
| 4895 | case SHELL_SURFACE_XWAYLAND: |
Tiago Vignatti | 99aeb1e | 2012-05-23 22:06:26 +0300 | [diff] [blame] | 4896 | if (shsurf->transient.flags == |
| 4897 | WL_SHELL_SURFACE_TRANSIENT_INACTIVE) |
| 4898 | break; |
| 4899 | case SHELL_SURFACE_TOPLEVEL: |
Rafael Antognolli | ed207b4 | 2013-12-03 15:35:43 -0200 | [diff] [blame] | 4900 | if (shsurf->state.relative && |
| 4901 | shsurf->transient.flags == WL_SHELL_SURFACE_TRANSIENT_INACTIVE) |
| 4902 | break; |
Rafael Antognolli | ba5d2d7 | 2013-12-04 17:49:55 -0200 | [diff] [blame] | 4903 | if (shell->locked) |
Rafael Antognolli | ed207b4 | 2013-12-03 15:35:43 -0200 | [diff] [blame] | 4904 | break; |
| 4905 | wl_list_for_each(seat, &compositor->seat_list, link) |
| 4906 | activate(shell, shsurf->surface, seat); |
Juan Zhao | 7bb92f0 | 2011-12-15 11:31:51 -0500 | [diff] [blame] | 4907 | break; |
Philip Withnall | 0f640e2 | 2013-11-25 18:01:31 +0000 | [diff] [blame] | 4908 | case SHELL_SURFACE_POPUP: |
| 4909 | case SHELL_SURFACE_NONE: |
Juan Zhao | 7bb92f0 | 2011-12-15 11:31:51 -0500 | [diff] [blame] | 4910 | default: |
| 4911 | break; |
| 4912 | } |
| 4913 | |
Rafael Antognolli | 03b1659 | 2013-12-03 15:35:42 -0200 | [diff] [blame] | 4914 | if (shsurf->type == SHELL_SURFACE_TOPLEVEL && |
| 4915 | !shsurf->state.maximized && !shsurf->state.fullscreen) |
Juan Zhao | e10d279 | 2012-04-25 19:09:52 +0800 | [diff] [blame] | 4916 | { |
| 4917 | switch (shell->win_animation_type) { |
| 4918 | case ANIMATION_FADE: |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 4919 | 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] | 4920 | break; |
| 4921 | case ANIMATION_ZOOM: |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 4922 | weston_zoom_run(shsurf->view, 0.5, 1.0, NULL, NULL); |
Juan Zhao | e10d279 | 2012-04-25 19:09:52 +0800 | [diff] [blame] | 4923 | break; |
Philip Withnall | 4a86a0a | 2013-11-25 18:01:32 +0000 | [diff] [blame] | 4924 | case ANIMATION_NONE: |
Juan Zhao | e10d279 | 2012-04-25 19:09:52 +0800 | [diff] [blame] | 4925 | default: |
| 4926 | break; |
| 4927 | } |
| 4928 | } |
Kristian Høgsberg | 32e24cc | 2011-11-09 12:07:35 -0500 | [diff] [blame] | 4929 | } |
| 4930 | |
| 4931 | static void |
Tiago Vignatti | be14326 | 2012-04-16 17:31:41 +0300 | [diff] [blame] | 4932 | configure(struct desktop_shell *shell, struct weston_surface *surface, |
Jason Ekstrand | 918f2dd | 2013-12-02 21:01:53 -0600 | [diff] [blame] | 4933 | float x, float y) |
Kristian Høgsberg | 32e24cc | 2011-11-09 12:07:35 -0500 | [diff] [blame] | 4934 | { |
Pekka Paalanen | 77346a6 | 2011-11-30 16:26:35 +0200 | [diff] [blame] | 4935 | struct shell_surface *shsurf; |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 4936 | struct weston_view *view; |
Jason Ekstrand | 918f2dd | 2013-12-02 21:01:53 -0600 | [diff] [blame] | 4937 | int32_t mx, my, surf_x, surf_y; |
Kristian Høgsberg | 32e24cc | 2011-11-09 12:07:35 -0500 | [diff] [blame] | 4938 | |
Pekka Paalanen | 77346a6 | 2011-11-30 16:26:35 +0200 | [diff] [blame] | 4939 | shsurf = get_shell_surface(surface); |
Pekka Paalanen | 77346a6 | 2011-11-30 16:26:35 +0200 | [diff] [blame] | 4940 | |
U. Artie Eoff | cf5737a | 2014-01-17 10:08:25 -0800 | [diff] [blame] | 4941 | assert(shsurf); |
| 4942 | |
Rafael Antognolli | 03b1659 | 2013-12-03 15:35:42 -0200 | [diff] [blame] | 4943 | if (shsurf->state.fullscreen) |
Alex Wu | 4539b08 | 2012-03-01 12:57:46 +0800 | [diff] [blame] | 4944 | shell_configure_fullscreen(shsurf); |
Rafael Antognolli | 03b1659 | 2013-12-03 15:35:42 -0200 | [diff] [blame] | 4945 | else if (shsurf->state.maximized) { |
Alex Wu | 4539b08 | 2012-03-01 12:57:46 +0800 | [diff] [blame] | 4946 | /* setting x, y and using configure to change that geometry */ |
Giulio Camuffo | b836664 | 2013-04-25 13:57:46 +0300 | [diff] [blame] | 4947 | surface_subsurfaces_boundingbox(shsurf->surface, &surf_x, &surf_y, |
| 4948 | NULL, NULL); |
Jason Ekstrand | 918f2dd | 2013-12-02 21:01:53 -0600 | [diff] [blame] | 4949 | mx = shsurf->output->x - surf_x; |
| 4950 | my = shsurf->output->y + |
| 4951 | get_output_panel_height(shell,shsurf->output) - surf_y; |
| 4952 | weston_view_set_position(shsurf->view, mx, my); |
Rafael Antognolli | 03b1659 | 2013-12-03 15:35:42 -0200 | [diff] [blame] | 4953 | } else { |
Jason Ekstrand | 918f2dd | 2013-12-02 21:01:53 -0600 | [diff] [blame] | 4954 | weston_view_set_position(shsurf->view, x, y); |
Kristian Høgsberg | 7a5c979 | 2011-06-18 06:12:54 -0400 | [diff] [blame] | 4955 | } |
Kristian Høgsberg | 32e24cc | 2011-11-09 12:07:35 -0500 | [diff] [blame] | 4956 | |
Alex Wu | 4539b08 | 2012-03-01 12:57:46 +0800 | [diff] [blame] | 4957 | /* XXX: would a fullscreen surface need the same handling? */ |
Kristian Høgsberg | 6a8b553 | 2012-02-16 23:43:59 -0500 | [diff] [blame] | 4958 | if (surface->output) { |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 4959 | wl_list_for_each(view, &surface->views, surface_link) |
| 4960 | weston_view_update_transform(view); |
Pekka Paalanen | 77346a6 | 2011-11-30 16:26:35 +0200 | [diff] [blame] | 4961 | |
Rafael Antognolli | 03b1659 | 2013-12-03 15:35:42 -0200 | [diff] [blame] | 4962 | if (shsurf->state.maximized) |
Juan Zhao | 96879df | 2012-02-07 08:45:41 +0800 | [diff] [blame] | 4963 | surface->output = shsurf->output; |
Pekka Paalanen | 77346a6 | 2011-11-30 16:26:35 +0200 | [diff] [blame] | 4964 | } |
Kristian Høgsberg | 0793756 | 2011-04-12 17:25:42 -0400 | [diff] [blame] | 4965 | } |
| 4966 | |
Ander Conselvan de Oliveira | 093bfa3 | 2012-03-27 17:36:41 +0300 | [diff] [blame] | 4967 | static void |
Jason Ekstrand | 918f2dd | 2013-12-02 21:01:53 -0600 | [diff] [blame] | 4968 | 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] | 4969 | { |
Ander Conselvan de Oliveira | 7fb9f95 | 2012-03-27 17:36:42 +0300 | [diff] [blame] | 4970 | struct shell_surface *shsurf = get_shell_surface(es); |
U. Artie Eoff | cf5737a | 2014-01-17 10:08:25 -0800 | [diff] [blame] | 4971 | struct desktop_shell *shell; |
Tiago Vignatti | 70e5c9c | 2012-05-07 15:23:07 +0300 | [diff] [blame] | 4972 | int type_changed = 0; |
Ander Conselvan de Oliveira | 093bfa3 | 2012-03-27 17:36:41 +0300 | [diff] [blame] | 4973 | |
U. Artie Eoff | cf5737a | 2014-01-17 10:08:25 -0800 | [diff] [blame] | 4974 | assert(shsurf); |
| 4975 | |
| 4976 | shell = shsurf->shell; |
| 4977 | |
Kristian Høgsberg | 8eb0f4f | 2013-06-17 10:33:14 -0400 | [diff] [blame] | 4978 | if (!weston_surface_is_mapped(es) && |
| 4979 | !wl_list_empty(&shsurf->popup.grab_link)) { |
Giulio Camuffo | 5085a75 | 2013-03-25 21:42:45 +0100 | [diff] [blame] | 4980 | remove_popup_grab(shsurf); |
| 4981 | } |
| 4982 | |
Jason Ekstrand | 918f2dd | 2013-12-02 21:01:53 -0600 | [diff] [blame] | 4983 | if (es->width == 0) |
Giulio Camuffo | 184df50 | 2013-02-21 11:29:21 +0100 | [diff] [blame] | 4984 | return; |
| 4985 | |
Kristian Høgsberg | c8f8dd8 | 2013-12-05 23:20:33 -0800 | [diff] [blame] | 4986 | if (shsurf->state_changed) { |
Kristian Høgsberg | 7f366e7 | 2012-04-27 17:20:01 -0400 | [diff] [blame] | 4987 | set_surface_type(shsurf); |
Kristian Høgsberg | f7e23d5 | 2012-04-27 17:51:59 -0400 | [diff] [blame] | 4988 | type_changed = 1; |
| 4989 | } |
Kristian Høgsberg | 7f366e7 | 2012-04-27 17:20:01 -0400 | [diff] [blame] | 4990 | |
Ander Conselvan de Oliveira | 093bfa3 | 2012-03-27 17:36:41 +0300 | [diff] [blame] | 4991 | if (!weston_surface_is_mapped(es)) { |
Jason Ekstrand | 918f2dd | 2013-12-02 21:01:53 -0600 | [diff] [blame] | 4992 | map(shell, shsurf, sx, sy); |
Kristian Høgsberg | f7e23d5 | 2012-04-27 17:51:59 -0400 | [diff] [blame] | 4993 | } else if (type_changed || sx != 0 || sy != 0 || |
Jason Ekstrand | 918f2dd | 2013-12-02 21:01:53 -0600 | [diff] [blame] | 4994 | shsurf->last_width != es->width || |
| 4995 | shsurf->last_height != es->height) { |
John Kåre Alsaker | 490d02a | 2012-09-30 02:57:21 +0200 | [diff] [blame] | 4996 | float from_x, from_y; |
| 4997 | float to_x, to_y; |
Ander Conselvan de Oliveira | 093bfa3 | 2012-03-27 17:36:41 +0300 | [diff] [blame] | 4998 | |
Kristian Høgsberg | 44cd196 | 2014-02-05 21:36:04 -0800 | [diff] [blame] | 4999 | if (shsurf->resize_edges) { |
| 5000 | sx = 0; |
| 5001 | sy = 0; |
| 5002 | } |
| 5003 | |
| 5004 | if (shsurf->resize_edges & WL_SHELL_SURFACE_RESIZE_LEFT) |
| 5005 | sx = shsurf->last_width - es->width; |
| 5006 | if (shsurf->resize_edges & WL_SHELL_SURFACE_RESIZE_TOP) |
| 5007 | sy = shsurf->last_height - es->height; |
| 5008 | |
| 5009 | shsurf->last_width = es->width; |
| 5010 | shsurf->last_height = es->height; |
| 5011 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 5012 | weston_view_to_global_float(shsurf->view, 0, 0, &from_x, &from_y); |
| 5013 | 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] | 5014 | configure(shell, es, |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 5015 | shsurf->view->geometry.x + to_x - from_x, |
Jason Ekstrand | 918f2dd | 2013-12-02 21:01:53 -0600 | [diff] [blame] | 5016 | shsurf->view->geometry.y + to_y - from_y); |
Ander Conselvan de Oliveira | 093bfa3 | 2012-03-27 17:36:41 +0300 | [diff] [blame] | 5017 | } |
| 5018 | } |
| 5019 | |
Tiago Vignatti | b7dbbd6 | 2012-09-25 17:57:01 +0300 | [diff] [blame] | 5020 | static void launch_desktop_shell_process(void *data); |
Pekka Paalanen | 4d733ee | 2012-01-17 14:36:27 +0200 | [diff] [blame] | 5021 | |
Kristian Høgsberg | 97d44aa | 2011-08-26 17:21:20 -0400 | [diff] [blame] | 5022 | static void |
Kristian Høgsberg | 8334bc1 | 2012-01-03 10:29:47 -0500 | [diff] [blame] | 5023 | desktop_shell_sigchld(struct weston_process *process, int status) |
Pekka Paalanen | 6cd281a | 2011-11-03 14:11:32 +0200 | [diff] [blame] | 5024 | { |
Pekka Paalanen | 4d733ee | 2012-01-17 14:36:27 +0200 | [diff] [blame] | 5025 | uint32_t time; |
Tiago Vignatti | be14326 | 2012-04-16 17:31:41 +0300 | [diff] [blame] | 5026 | struct desktop_shell *shell = |
| 5027 | container_of(process, struct desktop_shell, child.process); |
Pekka Paalanen | 6cd281a | 2011-11-03 14:11:32 +0200 | [diff] [blame] | 5028 | |
| 5029 | shell->child.process.pid = 0; |
| 5030 | shell->child.client = NULL; /* already destroyed by wayland */ |
Pekka Paalanen | 4d733ee | 2012-01-17 14:36:27 +0200 | [diff] [blame] | 5031 | |
| 5032 | /* if desktop-shell dies more than 5 times in 30 seconds, give up */ |
| 5033 | time = weston_compositor_get_time(); |
Kristian Høgsberg | f03a616 | 2012-01-17 11:07:42 -0500 | [diff] [blame] | 5034 | if (time - shell->child.deathstamp > 30000) { |
Pekka Paalanen | 4d733ee | 2012-01-17 14:36:27 +0200 | [diff] [blame] | 5035 | shell->child.deathstamp = time; |
| 5036 | shell->child.deathcount = 0; |
| 5037 | } |
| 5038 | |
| 5039 | shell->child.deathcount++; |
| 5040 | if (shell->child.deathcount > 5) { |
Emilio Pozuelo Monfort | 46ce798 | 2013-11-20 13:22:29 +0100 | [diff] [blame] | 5041 | weston_log("%s died, giving up.\n", shell->client); |
Pekka Paalanen | 4d733ee | 2012-01-17 14:36:27 +0200 | [diff] [blame] | 5042 | return; |
| 5043 | } |
| 5044 | |
Emilio Pozuelo Monfort | 46ce798 | 2013-11-20 13:22:29 +0100 | [diff] [blame] | 5045 | weston_log("%s died, respawning...\n", shell->client); |
Pekka Paalanen | 4d733ee | 2012-01-17 14:36:27 +0200 | [diff] [blame] | 5046 | launch_desktop_shell_process(shell); |
Pekka Paalanen | 79346ab | 2013-05-22 18:03:09 +0300 | [diff] [blame] | 5047 | shell_fade_startup(shell); |
Pekka Paalanen | 6cd281a | 2011-11-03 14:11:32 +0200 | [diff] [blame] | 5048 | } |
| 5049 | |
Tiago Vignatti | b7dbbd6 | 2012-09-25 17:57:01 +0300 | [diff] [blame] | 5050 | static void |
Ander Conselvan de Oliveira | 312ea4c | 2013-12-20 21:07:01 +0200 | [diff] [blame] | 5051 | desktop_shell_client_destroy(struct wl_listener *listener, void *data) |
| 5052 | { |
| 5053 | struct desktop_shell *shell; |
| 5054 | |
| 5055 | shell = container_of(listener, struct desktop_shell, |
| 5056 | child.client_destroy_listener); |
| 5057 | |
| 5058 | shell->child.client = NULL; |
| 5059 | } |
| 5060 | |
| 5061 | static void |
Tiago Vignatti | b7dbbd6 | 2012-09-25 17:57:01 +0300 | [diff] [blame] | 5062 | launch_desktop_shell_process(void *data) |
Pekka Paalanen | 6cd281a | 2011-11-03 14:11:32 +0200 | [diff] [blame] | 5063 | { |
Tiago Vignatti | b7dbbd6 | 2012-09-25 17:57:01 +0300 | [diff] [blame] | 5064 | struct desktop_shell *shell = data; |
Pekka Paalanen | 6cd281a | 2011-11-03 14:11:32 +0200 | [diff] [blame] | 5065 | |
Kristian Høgsberg | 8334bc1 | 2012-01-03 10:29:47 -0500 | [diff] [blame] | 5066 | shell->child.client = weston_client_launch(shell->compositor, |
Pekka Paalanen | 409ef0a | 2011-12-02 15:30:21 +0200 | [diff] [blame] | 5067 | &shell->child.process, |
Emilio Pozuelo Monfort | 46ce798 | 2013-11-20 13:22:29 +0100 | [diff] [blame] | 5068 | shell->client, |
Pekka Paalanen | 409ef0a | 2011-12-02 15:30:21 +0200 | [diff] [blame] | 5069 | desktop_shell_sigchld); |
| 5070 | |
| 5071 | if (!shell->child.client) |
Emilio Pozuelo Monfort | 46ce798 | 2013-11-20 13:22:29 +0100 | [diff] [blame] | 5072 | weston_log("not able to start %s\n", shell->client); |
Ander Conselvan de Oliveira | 312ea4c | 2013-12-20 21:07:01 +0200 | [diff] [blame] | 5073 | |
| 5074 | shell->child.client_destroy_listener.notify = |
| 5075 | desktop_shell_client_destroy; |
| 5076 | wl_client_add_destroy_listener(shell->child.client, |
| 5077 | &shell->child.client_destroy_listener); |
Pekka Paalanen | 6cd281a | 2011-11-03 14:11:32 +0200 | [diff] [blame] | 5078 | } |
| 5079 | |
| 5080 | static void |
Kristian Høgsberg | 2bff94e | 2014-02-11 12:22:51 -0800 | [diff] [blame] | 5081 | handle_shell_client_destroy(struct wl_listener *listener, void *data) |
| 5082 | { |
| 5083 | struct shell_client *sc = |
| 5084 | container_of(listener, struct shell_client, destroy_listener); |
| 5085 | |
| 5086 | if (sc->ping_timer) |
| 5087 | wl_event_source_remove(sc->ping_timer); |
| 5088 | free(sc); |
| 5089 | } |
| 5090 | |
Kristian Høgsberg | dd62aba | 2014-02-12 09:56:19 -0800 | [diff] [blame] | 5091 | static struct shell_client * |
| 5092 | shell_client_create(struct wl_client *client, struct desktop_shell *shell, |
| 5093 | const struct wl_interface *interface, uint32_t id) |
Rafael Antognolli | e2a3455 | 2013-12-03 15:35:45 -0200 | [diff] [blame] | 5094 | { |
Kristian Høgsberg | 2bff94e | 2014-02-11 12:22:51 -0800 | [diff] [blame] | 5095 | struct shell_client *sc; |
Rafael Antognolli | e2a3455 | 2013-12-03 15:35:45 -0200 | [diff] [blame] | 5096 | |
Kristian Høgsberg | 2bff94e | 2014-02-11 12:22:51 -0800 | [diff] [blame] | 5097 | sc = zalloc(sizeof *sc); |
| 5098 | if (sc == NULL) { |
| 5099 | wl_client_post_no_memory(client); |
Kristian Høgsberg | dd62aba | 2014-02-12 09:56:19 -0800 | [diff] [blame] | 5100 | return NULL; |
Kristian Høgsberg | 2bff94e | 2014-02-11 12:22:51 -0800 | [diff] [blame] | 5101 | } |
Kristian Høgsberg | dd62aba | 2014-02-12 09:56:19 -0800 | [diff] [blame] | 5102 | |
| 5103 | sc->resource = wl_resource_create(client, interface, 1, id); |
Kristian Høgsberg | 2bff94e | 2014-02-11 12:22:51 -0800 | [diff] [blame] | 5104 | if (sc->resource == NULL) { |
| 5105 | free(sc); |
| 5106 | wl_client_post_no_memory(client); |
Kristian Høgsberg | dd62aba | 2014-02-12 09:56:19 -0800 | [diff] [blame] | 5107 | return NULL; |
Kristian Høgsberg | 2bff94e | 2014-02-11 12:22:51 -0800 | [diff] [blame] | 5108 | } |
| 5109 | |
| 5110 | sc->client = client; |
| 5111 | sc->shell = shell; |
| 5112 | sc->destroy_listener.notify = handle_shell_client_destroy; |
| 5113 | wl_client_add_destroy_listener(client, &sc->destroy_listener); |
| 5114 | |
Kristian Høgsberg | dd62aba | 2014-02-12 09:56:19 -0800 | [diff] [blame] | 5115 | return sc; |
| 5116 | } |
| 5117 | |
| 5118 | static void |
| 5119 | bind_shell(struct wl_client *client, void *data, uint32_t version, uint32_t id) |
| 5120 | { |
| 5121 | struct desktop_shell *shell = data; |
| 5122 | struct shell_client *sc; |
| 5123 | |
| 5124 | sc = shell_client_create(client, shell, &wl_shell_interface, id); |
| 5125 | if (sc) |
| 5126 | wl_resource_set_implementation(sc->resource, |
| 5127 | &shell_implementation, |
Jason Ekstrand | 9e9512f | 2014-04-16 21:12:10 -0500 | [diff] [blame] | 5128 | sc, NULL); |
Kristian Høgsberg | dd62aba | 2014-02-12 09:56:19 -0800 | [diff] [blame] | 5129 | } |
| 5130 | |
| 5131 | static void |
| 5132 | bind_xdg_shell(struct wl_client *client, void *data, uint32_t version, uint32_t id) |
| 5133 | { |
| 5134 | struct desktop_shell *shell = data; |
| 5135 | struct shell_client *sc; |
| 5136 | |
| 5137 | sc = shell_client_create(client, shell, &xdg_shell_interface, id); |
| 5138 | if (sc) |
| 5139 | wl_resource_set_dispatcher(sc->resource, |
| 5140 | xdg_shell_unversioned_dispatch, |
| 5141 | NULL, sc, NULL); |
Rafael Antognolli | e2a3455 | 2013-12-03 15:35:45 -0200 | [diff] [blame] | 5142 | } |
| 5143 | |
| 5144 | static void |
Pekka Paalanen | 9ef3e01 | 2011-11-15 13:34:48 +0200 | [diff] [blame] | 5145 | unbind_desktop_shell(struct wl_resource *resource) |
| 5146 | { |
Jason Ekstrand | 651f00e | 2013-06-14 10:07:54 -0500 | [diff] [blame] | 5147 | struct desktop_shell *shell = wl_resource_get_user_data(resource); |
Kristian Høgsberg | 1ec0c31 | 2011-11-15 16:39:55 -0500 | [diff] [blame] | 5148 | |
| 5149 | if (shell->locked) |
| 5150 | resume_desktop(shell); |
| 5151 | |
Pekka Paalanen | 9ef3e01 | 2011-11-15 13:34:48 +0200 | [diff] [blame] | 5152 | shell->child.desktop_shell = NULL; |
| 5153 | shell->prepare_event_sent = false; |
Pekka Paalanen | 9ef3e01 | 2011-11-15 13:34:48 +0200 | [diff] [blame] | 5154 | } |
| 5155 | |
| 5156 | static void |
Kristian Høgsberg | 7584062 | 2011-09-06 13:48:16 -0400 | [diff] [blame] | 5157 | bind_desktop_shell(struct wl_client *client, |
| 5158 | void *data, uint32_t version, uint32_t id) |
| 5159 | { |
Tiago Vignatti | be14326 | 2012-04-16 17:31:41 +0300 | [diff] [blame] | 5160 | struct desktop_shell *shell = data; |
Pekka Paalanen | bbe6052 | 2011-11-03 14:11:33 +0200 | [diff] [blame] | 5161 | struct wl_resource *resource; |
Kristian Høgsberg | 7584062 | 2011-09-06 13:48:16 -0400 | [diff] [blame] | 5162 | |
Jason Ekstrand | a85118c | 2013-06-27 20:17:02 -0500 | [diff] [blame] | 5163 | resource = wl_resource_create(client, &desktop_shell_interface, |
| 5164 | MIN(version, 2), id); |
Pekka Paalanen | bbe6052 | 2011-11-03 14:11:33 +0200 | [diff] [blame] | 5165 | |
Pekka Paalanen | 9ef3e01 | 2011-11-15 13:34:48 +0200 | [diff] [blame] | 5166 | if (client == shell->child.client) { |
Jason Ekstrand | a85118c | 2013-06-27 20:17:02 -0500 | [diff] [blame] | 5167 | wl_resource_set_implementation(resource, |
| 5168 | &desktop_shell_implementation, |
| 5169 | shell, unbind_desktop_shell); |
Pekka Paalanen | 9ef3e01 | 2011-11-15 13:34:48 +0200 | [diff] [blame] | 5170 | shell->child.desktop_shell = resource; |
Pekka Paalanen | 79346ab | 2013-05-22 18:03:09 +0300 | [diff] [blame] | 5171 | |
| 5172 | if (version < 2) |
| 5173 | shell_fade_startup(shell); |
| 5174 | |
Pekka Paalanen | bbe6052 | 2011-11-03 14:11:33 +0200 | [diff] [blame] | 5175 | return; |
Pekka Paalanen | 9ef3e01 | 2011-11-15 13:34:48 +0200 | [diff] [blame] | 5176 | } |
Pekka Paalanen | bbe6052 | 2011-11-03 14:11:33 +0200 | [diff] [blame] | 5177 | |
| 5178 | wl_resource_post_error(resource, WL_DISPLAY_ERROR_INVALID_OBJECT, |
| 5179 | "permission to bind desktop_shell denied"); |
Kristian Høgsberg | eae5de7 | 2012-04-11 22:42:15 -0400 | [diff] [blame] | 5180 | wl_resource_destroy(resource); |
Kristian Høgsberg | 7584062 | 2011-09-06 13:48:16 -0400 | [diff] [blame] | 5181 | } |
| 5182 | |
Pekka Paalanen | 6e16811 | 2011-11-24 11:34:05 +0200 | [diff] [blame] | 5183 | static void |
Jason Ekstrand | 918f2dd | 2013-12-02 21:01:53 -0600 | [diff] [blame] | 5184 | 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] | 5185 | { |
Giulio Camuffo | 7fe01b1 | 2013-03-28 18:02:42 +0100 | [diff] [blame] | 5186 | struct desktop_shell *shell = surface->configure_private; |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 5187 | struct weston_view *view; |
Kristian Høgsberg | 1a73a63 | 2012-06-26 22:15:53 -0400 | [diff] [blame] | 5188 | |
Jason Ekstrand | 918f2dd | 2013-12-02 21:01:53 -0600 | [diff] [blame] | 5189 | if (surface->width == 0) |
Giulio Camuffo | 184df50 | 2013-02-21 11:29:21 +0100 | [diff] [blame] | 5190 | return; |
| 5191 | |
Pekka Paalanen | 3a1d07d | 2012-12-20 14:02:13 +0200 | [diff] [blame] | 5192 | /* XXX: starting weston-screensaver beforehand does not work */ |
Kristian Høgsberg | 1a73a63 | 2012-06-26 22:15:53 -0400 | [diff] [blame] | 5193 | if (!shell->locked) |
| 5194 | return; |
| 5195 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 5196 | view = container_of(surface->views.next, struct weston_view, surface_link); |
| 5197 | center_on_output(view, surface->output); |
Kristian Høgsberg | 1a73a63 | 2012-06-26 22:15:53 -0400 | [diff] [blame] | 5198 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 5199 | if (wl_list_empty(&view->layer_link)) { |
| 5200 | wl_list_insert(shell->lock_layer.view_list.prev, |
| 5201 | &view->layer_link); |
| 5202 | weston_view_update_transform(view); |
Ander Conselvan de Oliveira | 859e885 | 2013-02-21 18:35:21 +0200 | [diff] [blame] | 5203 | wl_event_source_timer_update(shell->screensaver.timer, |
| 5204 | shell->screensaver.duration); |
Ander Conselvan de Oliveira | 19d10ef | 2013-02-21 18:35:20 +0200 | [diff] [blame] | 5205 | shell_fade(shell, FADE_IN); |
Kristian Høgsberg | 1a73a63 | 2012-06-26 22:15:53 -0400 | [diff] [blame] | 5206 | } |
| 5207 | } |
| 5208 | |
| 5209 | static void |
Pekka Paalanen | 6e16811 | 2011-11-24 11:34:05 +0200 | [diff] [blame] | 5210 | screensaver_set_surface(struct wl_client *client, |
| 5211 | struct wl_resource *resource, |
Kristian Høgsberg | 1a73a63 | 2012-06-26 22:15:53 -0400 | [diff] [blame] | 5212 | struct wl_resource *surface_resource, |
Pekka Paalanen | 6e16811 | 2011-11-24 11:34:05 +0200 | [diff] [blame] | 5213 | struct wl_resource *output_resource) |
| 5214 | { |
Jason Ekstrand | 651f00e | 2013-06-14 10:07:54 -0500 | [diff] [blame] | 5215 | struct desktop_shell *shell = wl_resource_get_user_data(resource); |
Jason Ekstrand | 0f2ef7e | 2013-06-14 10:07:53 -0500 | [diff] [blame] | 5216 | struct weston_surface *surface = |
| 5217 | wl_resource_get_user_data(surface_resource); |
Jason Ekstrand | a0d2dde | 2013-06-14 10:08:01 -0500 | [diff] [blame] | 5218 | struct weston_output *output = wl_resource_get_user_data(output_resource); |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 5219 | struct weston_view *view, *next; |
| 5220 | |
| 5221 | /* Make sure we only have one view */ |
| 5222 | wl_list_for_each_safe(view, next, &surface->views, surface_link) |
| 5223 | weston_view_destroy(view); |
| 5224 | weston_view_create(surface); |
Pekka Paalanen | 6e16811 | 2011-11-24 11:34:05 +0200 | [diff] [blame] | 5225 | |
Kristian Høgsberg | 1a73a63 | 2012-06-26 22:15:53 -0400 | [diff] [blame] | 5226 | surface->configure = screensaver_configure; |
Giulio Camuffo | 7fe01b1 | 2013-03-28 18:02:42 +0100 | [diff] [blame] | 5227 | surface->configure_private = shell; |
Pekka Paalanen | 77346a6 | 2011-11-30 16:26:35 +0200 | [diff] [blame] | 5228 | surface->output = output; |
Pekka Paalanen | 6e16811 | 2011-11-24 11:34:05 +0200 | [diff] [blame] | 5229 | } |
| 5230 | |
| 5231 | static const struct screensaver_interface screensaver_implementation = { |
| 5232 | screensaver_set_surface |
| 5233 | }; |
| 5234 | |
| 5235 | static void |
| 5236 | unbind_screensaver(struct wl_resource *resource) |
| 5237 | { |
Jason Ekstrand | 651f00e | 2013-06-14 10:07:54 -0500 | [diff] [blame] | 5238 | struct desktop_shell *shell = wl_resource_get_user_data(resource); |
Pekka Paalanen | 6e16811 | 2011-11-24 11:34:05 +0200 | [diff] [blame] | 5239 | |
Pekka Paalanen | 77346a6 | 2011-11-30 16:26:35 +0200 | [diff] [blame] | 5240 | shell->screensaver.binding = NULL; |
Pekka Paalanen | 6e16811 | 2011-11-24 11:34:05 +0200 | [diff] [blame] | 5241 | } |
| 5242 | |
| 5243 | static void |
| 5244 | bind_screensaver(struct wl_client *client, |
| 5245 | void *data, uint32_t version, uint32_t id) |
| 5246 | { |
Tiago Vignatti | be14326 | 2012-04-16 17:31:41 +0300 | [diff] [blame] | 5247 | struct desktop_shell *shell = data; |
Pekka Paalanen | 6e16811 | 2011-11-24 11:34:05 +0200 | [diff] [blame] | 5248 | struct wl_resource *resource; |
| 5249 | |
Jason Ekstrand | a85118c | 2013-06-27 20:17:02 -0500 | [diff] [blame] | 5250 | resource = wl_resource_create(client, &screensaver_interface, 1, id); |
Pekka Paalanen | 6e16811 | 2011-11-24 11:34:05 +0200 | [diff] [blame] | 5251 | |
Pekka Paalanen | 77346a6 | 2011-11-30 16:26:35 +0200 | [diff] [blame] | 5252 | if (shell->screensaver.binding == NULL) { |
Jason Ekstrand | a85118c | 2013-06-27 20:17:02 -0500 | [diff] [blame] | 5253 | wl_resource_set_implementation(resource, |
| 5254 | &screensaver_implementation, |
| 5255 | shell, unbind_screensaver); |
Pekka Paalanen | 77346a6 | 2011-11-30 16:26:35 +0200 | [diff] [blame] | 5256 | shell->screensaver.binding = resource; |
Pekka Paalanen | 6e16811 | 2011-11-24 11:34:05 +0200 | [diff] [blame] | 5257 | return; |
| 5258 | } |
| 5259 | |
| 5260 | wl_resource_post_error(resource, WL_DISPLAY_ERROR_INVALID_OBJECT, |
| 5261 | "interface object already bound"); |
Kristian Høgsberg | eae5de7 | 2012-04-11 22:42:15 -0400 | [diff] [blame] | 5262 | wl_resource_destroy(resource); |
Pekka Paalanen | 6e16811 | 2011-11-24 11:34:05 +0200 | [diff] [blame] | 5263 | } |
| 5264 | |
Kristian Høgsberg | 0704539 | 2012-02-19 18:52:44 -0500 | [diff] [blame] | 5265 | struct switcher { |
Tiago Vignatti | be14326 | 2012-04-16 17:31:41 +0300 | [diff] [blame] | 5266 | struct desktop_shell *shell; |
Kristian Høgsberg | 0704539 | 2012-02-19 18:52:44 -0500 | [diff] [blame] | 5267 | struct weston_surface *current; |
| 5268 | struct wl_listener listener; |
Kristian Høgsberg | 29139d4 | 2013-04-18 15:25:39 -0400 | [diff] [blame] | 5269 | struct weston_keyboard_grab grab; |
Manuel Bachmann | c1ae2e8 | 2014-02-26 15:53:11 +0100 | [diff] [blame] | 5270 | struct wl_array minimized_array; |
Kristian Høgsberg | 0704539 | 2012-02-19 18:52:44 -0500 | [diff] [blame] | 5271 | }; |
| 5272 | |
| 5273 | static void |
| 5274 | switcher_next(struct switcher *switcher) |
| 5275 | { |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 5276 | struct weston_view *view; |
Kristian Høgsberg | 0704539 | 2012-02-19 18:52:44 -0500 | [diff] [blame] | 5277 | struct weston_surface *first = NULL, *prev = NULL, *next = NULL; |
Kristian Høgsberg | 32e5686 | 2012-04-02 22:18:58 -0400 | [diff] [blame] | 5278 | struct shell_surface *shsurf; |
Kristian Høgsberg | b0d8e77 | 2012-06-18 16:34:58 -0400 | [diff] [blame] | 5279 | struct workspace *ws = get_current_workspace(switcher->shell); |
Kristian Høgsberg | 0704539 | 2012-02-19 18:52:44 -0500 | [diff] [blame] | 5280 | |
Manuel Bachmann | c1ae2e8 | 2014-02-26 15:53:11 +0100 | [diff] [blame] | 5281 | /* temporary re-display minimized surfaces */ |
| 5282 | struct weston_view *tmp; |
| 5283 | struct weston_view **minimized; |
| 5284 | wl_list_for_each_safe(view, tmp, &switcher->shell->minimized_layer.view_list, layer_link) { |
| 5285 | wl_list_remove(&view->layer_link); |
| 5286 | wl_list_insert(&ws->layer.view_list, &view->layer_link); |
| 5287 | minimized = wl_array_add(&switcher->minimized_array, sizeof *minimized); |
| 5288 | *minimized = view; |
| 5289 | } |
| 5290 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 5291 | wl_list_for_each(view, &ws->layer.view_list, layer_link) { |
Rafael Antognolli | ed207b4 | 2013-12-03 15:35:43 -0200 | [diff] [blame] | 5292 | shsurf = get_shell_surface(view->surface); |
Rafael Antognolli | 5031cbe | 2013-12-05 19:01:21 -0200 | [diff] [blame] | 5293 | if (shsurf && |
| 5294 | shsurf->type == SHELL_SURFACE_TOPLEVEL && |
| 5295 | shsurf->parent == NULL) { |
Kristian Høgsberg | 0704539 | 2012-02-19 18:52:44 -0500 | [diff] [blame] | 5296 | if (first == NULL) |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 5297 | first = view->surface; |
Kristian Høgsberg | 0704539 | 2012-02-19 18:52:44 -0500 | [diff] [blame] | 5298 | if (prev == switcher->current) |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 5299 | next = view->surface; |
| 5300 | prev = view->surface; |
| 5301 | view->alpha = 0.25; |
| 5302 | weston_view_geometry_dirty(view); |
| 5303 | weston_surface_damage(view->surface); |
Kristian Høgsberg | 0704539 | 2012-02-19 18:52:44 -0500 | [diff] [blame] | 5304 | } |
Alex Wu | 1659daa | 2012-04-01 20:13:09 +0800 | [diff] [blame] | 5305 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 5306 | if (is_black_surface(view->surface, NULL)) { |
| 5307 | view->alpha = 0.25; |
| 5308 | weston_view_geometry_dirty(view); |
| 5309 | weston_surface_damage(view->surface); |
Alex Wu | 1659daa | 2012-04-01 20:13:09 +0800 | [diff] [blame] | 5310 | } |
Kristian Høgsberg | 0704539 | 2012-02-19 18:52:44 -0500 | [diff] [blame] | 5311 | } |
| 5312 | |
| 5313 | if (next == NULL) |
| 5314 | next = first; |
| 5315 | |
Alex Wu | 07b2606 | 2012-03-12 16:06:01 +0800 | [diff] [blame] | 5316 | if (next == NULL) |
| 5317 | return; |
| 5318 | |
Kristian Høgsberg | 0704539 | 2012-02-19 18:52:44 -0500 | [diff] [blame] | 5319 | wl_list_remove(&switcher->listener.link); |
Jason Ekstrand | 26ed73c | 2013-06-06 22:34:41 -0500 | [diff] [blame] | 5320 | wl_signal_add(&next->destroy_signal, &switcher->listener); |
Kristian Høgsberg | 0704539 | 2012-02-19 18:52:44 -0500 | [diff] [blame] | 5321 | |
| 5322 | switcher->current = next; |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 5323 | wl_list_for_each(view, &next->views, surface_link) |
| 5324 | view->alpha = 1.0; |
Alex Wu | 1659daa | 2012-04-01 20:13:09 +0800 | [diff] [blame] | 5325 | |
Kristian Høgsberg | 32e5686 | 2012-04-02 22:18:58 -0400 | [diff] [blame] | 5326 | shsurf = get_shell_surface(switcher->current); |
Rafael Antognolli | 03b1659 | 2013-12-03 15:35:42 -0200 | [diff] [blame] | 5327 | if (shsurf && shsurf->state.fullscreen) |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 5328 | shsurf->fullscreen.black_view->alpha = 1.0; |
Kristian Høgsberg | 0704539 | 2012-02-19 18:52:44 -0500 | [diff] [blame] | 5329 | } |
| 5330 | |
| 5331 | static void |
Kristian Høgsberg | 27e3052 | 2012-04-11 23:18:23 -0400 | [diff] [blame] | 5332 | switcher_handle_surface_destroy(struct wl_listener *listener, void *data) |
Kristian Høgsberg | 0704539 | 2012-02-19 18:52:44 -0500 | [diff] [blame] | 5333 | { |
| 5334 | struct switcher *switcher = |
| 5335 | container_of(listener, struct switcher, listener); |
| 5336 | |
| 5337 | switcher_next(switcher); |
| 5338 | } |
| 5339 | |
| 5340 | static void |
Daniel Stone | 351eb61 | 2012-05-31 15:27:47 -0400 | [diff] [blame] | 5341 | switcher_destroy(struct switcher *switcher) |
Kristian Høgsberg | 0704539 | 2012-02-19 18:52:44 -0500 | [diff] [blame] | 5342 | { |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 5343 | struct weston_view *view; |
Kristian Høgsberg | 29139d4 | 2013-04-18 15:25:39 -0400 | [diff] [blame] | 5344 | struct weston_keyboard *keyboard = switcher->grab.keyboard; |
Kristian Høgsberg | b0d8e77 | 2012-06-18 16:34:58 -0400 | [diff] [blame] | 5345 | struct workspace *ws = get_current_workspace(switcher->shell); |
Kristian Høgsberg | 0704539 | 2012-02-19 18:52:44 -0500 | [diff] [blame] | 5346 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 5347 | 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] | 5348 | if (is_focus_view(view)) |
| 5349 | continue; |
| 5350 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 5351 | view->alpha = 1.0; |
| 5352 | weston_surface_damage(view->surface); |
Kristian Høgsberg | 0704539 | 2012-02-19 18:52:44 -0500 | [diff] [blame] | 5353 | } |
| 5354 | |
Alex Wu | 07b2606 | 2012-03-12 16:06:01 +0800 | [diff] [blame] | 5355 | if (switcher->current) |
Daniel Stone | 37816df | 2012-05-16 18:45:18 +0100 | [diff] [blame] | 5356 | activate(switcher->shell, switcher->current, |
| 5357 | (struct weston_seat *) keyboard->seat); |
Kristian Høgsberg | 0704539 | 2012-02-19 18:52:44 -0500 | [diff] [blame] | 5358 | wl_list_remove(&switcher->listener.link); |
Kristian Høgsberg | 29139d4 | 2013-04-18 15:25:39 -0400 | [diff] [blame] | 5359 | weston_keyboard_end_grab(keyboard); |
| 5360 | if (keyboard->input_method_resource) |
| 5361 | keyboard->grab = &keyboard->input_method_grab; |
Manuel Bachmann | c1ae2e8 | 2014-02-26 15:53:11 +0100 | [diff] [blame] | 5362 | |
| 5363 | /* re-hide surfaces that were temporary shown during the switch */ |
| 5364 | struct weston_view **minimized; |
| 5365 | wl_array_for_each(minimized, &switcher->minimized_array) { |
| 5366 | /* with the exception of the current selected */ |
| 5367 | if ((*minimized)->surface != switcher->current) { |
| 5368 | wl_list_remove(&(*minimized)->layer_link); |
| 5369 | wl_list_insert(&switcher->shell->minimized_layer.view_list, &(*minimized)->layer_link); |
| 5370 | weston_view_damage_below(*minimized); |
| 5371 | } |
| 5372 | } |
| 5373 | wl_array_release(&switcher->minimized_array); |
| 5374 | |
Kristian Høgsberg | 0704539 | 2012-02-19 18:52:44 -0500 | [diff] [blame] | 5375 | free(switcher); |
| 5376 | } |
| 5377 | |
| 5378 | static void |
Kristian Høgsberg | 29139d4 | 2013-04-18 15:25:39 -0400 | [diff] [blame] | 5379 | switcher_key(struct weston_keyboard_grab *grab, |
Daniel Stone | c9785ea | 2012-05-30 16:31:52 +0100 | [diff] [blame] | 5380 | uint32_t time, uint32_t key, uint32_t state_w) |
Kristian Høgsberg | 0704539 | 2012-02-19 18:52:44 -0500 | [diff] [blame] | 5381 | { |
| 5382 | struct switcher *switcher = container_of(grab, struct switcher, grab); |
Daniel Stone | c9785ea | 2012-05-30 16:31:52 +0100 | [diff] [blame] | 5383 | enum wl_keyboard_key_state state = state_w; |
Daniel Stone | 351eb61 | 2012-05-31 15:27:47 -0400 | [diff] [blame] | 5384 | |
Daniel Stone | c9785ea | 2012-05-30 16:31:52 +0100 | [diff] [blame] | 5385 | if (key == KEY_TAB && state == WL_KEYBOARD_KEY_STATE_PRESSED) |
Daniel Stone | 351eb61 | 2012-05-31 15:27:47 -0400 | [diff] [blame] | 5386 | switcher_next(switcher); |
| 5387 | } |
| 5388 | |
| 5389 | static void |
Kristian Høgsberg | 29139d4 | 2013-04-18 15:25:39 -0400 | [diff] [blame] | 5390 | switcher_modifier(struct weston_keyboard_grab *grab, uint32_t serial, |
Daniel Stone | 351eb61 | 2012-05-31 15:27:47 -0400 | [diff] [blame] | 5391 | uint32_t mods_depressed, uint32_t mods_latched, |
| 5392 | uint32_t mods_locked, uint32_t group) |
| 5393 | { |
| 5394 | struct switcher *switcher = container_of(grab, struct switcher, grab); |
Daniel Stone | 37816df | 2012-05-16 18:45:18 +0100 | [diff] [blame] | 5395 | struct weston_seat *seat = (struct weston_seat *) grab->keyboard->seat; |
Kristian Høgsberg | 0704539 | 2012-02-19 18:52:44 -0500 | [diff] [blame] | 5396 | |
Daniel Stone | 351eb61 | 2012-05-31 15:27:47 -0400 | [diff] [blame] | 5397 | if ((seat->modifier_state & switcher->shell->binding_modifier) == 0) |
| 5398 | switcher_destroy(switcher); |
Kristian Høgsberg | b71302e | 2012-05-10 12:28:35 -0400 | [diff] [blame] | 5399 | } |
Kristian Høgsberg | 0704539 | 2012-02-19 18:52:44 -0500 | [diff] [blame] | 5400 | |
Jonas Ådahl | 1ea343e | 2013-10-25 23:18:05 +0200 | [diff] [blame] | 5401 | static void |
| 5402 | switcher_cancel(struct weston_keyboard_grab *grab) |
| 5403 | { |
| 5404 | struct switcher *switcher = container_of(grab, struct switcher, grab); |
| 5405 | |
| 5406 | switcher_destroy(switcher); |
| 5407 | } |
| 5408 | |
Kristian Høgsberg | 29139d4 | 2013-04-18 15:25:39 -0400 | [diff] [blame] | 5409 | static const struct weston_keyboard_grab_interface switcher_grab = { |
Daniel Stone | 351eb61 | 2012-05-31 15:27:47 -0400 | [diff] [blame] | 5410 | switcher_key, |
| 5411 | switcher_modifier, |
Jonas Ådahl | 1ea343e | 2013-10-25 23:18:05 +0200 | [diff] [blame] | 5412 | switcher_cancel, |
Kristian Høgsberg | 0704539 | 2012-02-19 18:52:44 -0500 | [diff] [blame] | 5413 | }; |
| 5414 | |
| 5415 | static void |
Kristian Høgsberg | e314875 | 2013-05-06 23:19:49 -0400 | [diff] [blame] | 5416 | switcher_binding(struct weston_seat *seat, uint32_t time, uint32_t key, |
Daniel Stone | 325fc2d | 2012-05-30 16:31:58 +0100 | [diff] [blame] | 5417 | void *data) |
Kristian Høgsberg | 0704539 | 2012-02-19 18:52:44 -0500 | [diff] [blame] | 5418 | { |
Tiago Vignatti | be14326 | 2012-04-16 17:31:41 +0300 | [diff] [blame] | 5419 | struct desktop_shell *shell = data; |
Kristian Høgsberg | 0704539 | 2012-02-19 18:52:44 -0500 | [diff] [blame] | 5420 | struct switcher *switcher; |
| 5421 | |
| 5422 | switcher = malloc(sizeof *switcher); |
Kristian Høgsberg | 02e79dc | 2012-04-12 09:55:26 -0400 | [diff] [blame] | 5423 | switcher->shell = shell; |
Kristian Høgsberg | 0704539 | 2012-02-19 18:52:44 -0500 | [diff] [blame] | 5424 | switcher->current = NULL; |
Kristian Høgsberg | 27e3052 | 2012-04-11 23:18:23 -0400 | [diff] [blame] | 5425 | switcher->listener.notify = switcher_handle_surface_destroy; |
Kristian Høgsberg | 0704539 | 2012-02-19 18:52:44 -0500 | [diff] [blame] | 5426 | wl_list_init(&switcher->listener.link); |
Manuel Bachmann | c1ae2e8 | 2014-02-26 15:53:11 +0100 | [diff] [blame] | 5427 | wl_array_init(&switcher->minimized_array); |
Kristian Høgsberg | 0704539 | 2012-02-19 18:52:44 -0500 | [diff] [blame] | 5428 | |
Alexander Larsson | f82b6ca | 2013-05-28 16:23:39 +0200 | [diff] [blame] | 5429 | restore_all_output_modes(shell->compositor); |
Kristian Høgsberg | b0d8e77 | 2012-06-18 16:34:58 -0400 | [diff] [blame] | 5430 | lower_fullscreen_layer(switcher->shell); |
Kristian Høgsberg | 0704539 | 2012-02-19 18:52:44 -0500 | [diff] [blame] | 5431 | switcher->grab.interface = &switcher_grab; |
Kristian Høgsberg | 29139d4 | 2013-04-18 15:25:39 -0400 | [diff] [blame] | 5432 | weston_keyboard_start_grab(seat->keyboard, &switcher->grab); |
| 5433 | weston_keyboard_set_focus(seat->keyboard, NULL); |
Kristian Høgsberg | 0704539 | 2012-02-19 18:52:44 -0500 | [diff] [blame] | 5434 | switcher_next(switcher); |
| 5435 | } |
| 5436 | |
Pekka Paalanen | 3c64723 | 2011-12-22 13:43:43 +0200 | [diff] [blame] | 5437 | static void |
Kristian Høgsberg | e314875 | 2013-05-06 23:19:49 -0400 | [diff] [blame] | 5438 | backlight_binding(struct weston_seat *seat, uint32_t time, uint32_t key, |
Daniel Stone | 325fc2d | 2012-05-30 16:31:58 +0100 | [diff] [blame] | 5439 | void *data) |
Tiago Vignatti | 8e53c7f | 2012-02-29 19:53:50 +0200 | [diff] [blame] | 5440 | { |
| 5441 | struct weston_compositor *compositor = data; |
| 5442 | struct weston_output *output; |
Tiago Vignatti | 5ab91ad | 2012-03-12 19:40:09 -0300 | [diff] [blame] | 5443 | long backlight_new = 0; |
Tiago Vignatti | 8e53c7f | 2012-02-29 19:53:50 +0200 | [diff] [blame] | 5444 | |
| 5445 | /* TODO: we're limiting to simple use cases, where we assume just |
| 5446 | * control on the primary display. We'd have to extend later if we |
| 5447 | * ever get support for setting backlights on random desktop LCD |
| 5448 | * panels though */ |
| 5449 | output = get_default_output(compositor); |
| 5450 | if (!output) |
| 5451 | return; |
| 5452 | |
| 5453 | if (!output->set_backlight) |
| 5454 | return; |
| 5455 | |
Tiago Vignatti | 5ab91ad | 2012-03-12 19:40:09 -0300 | [diff] [blame] | 5456 | if (key == KEY_F9 || key == KEY_BRIGHTNESSDOWN) |
| 5457 | backlight_new = output->backlight_current - 25; |
| 5458 | else if (key == KEY_F10 || key == KEY_BRIGHTNESSUP) |
| 5459 | backlight_new = output->backlight_current + 25; |
Tiago Vignatti | 8e53c7f | 2012-02-29 19:53:50 +0200 | [diff] [blame] | 5460 | |
Tiago Vignatti | 5ab91ad | 2012-03-12 19:40:09 -0300 | [diff] [blame] | 5461 | if (backlight_new < 5) |
| 5462 | backlight_new = 5; |
| 5463 | if (backlight_new > 255) |
| 5464 | backlight_new = 255; |
| 5465 | |
| 5466 | output->backlight_current = backlight_new; |
Tiago Vignatti | 8e53c7f | 2012-02-29 19:53:50 +0200 | [diff] [blame] | 5467 | output->set_backlight(output, output->backlight_current); |
| 5468 | } |
| 5469 | |
Ander Conselvan de Oliveira | c509d2b | 2012-11-08 17:20:45 +0200 | [diff] [blame] | 5470 | struct debug_binding_grab { |
Kristian Høgsberg | 29139d4 | 2013-04-18 15:25:39 -0400 | [diff] [blame] | 5471 | struct weston_keyboard_grab grab; |
Ander Conselvan de Oliveira | c509d2b | 2012-11-08 17:20:45 +0200 | [diff] [blame] | 5472 | struct weston_seat *seat; |
| 5473 | uint32_t key[2]; |
| 5474 | int key_released[2]; |
| 5475 | }; |
| 5476 | |
| 5477 | static void |
Kristian Høgsberg | 29139d4 | 2013-04-18 15:25:39 -0400 | [diff] [blame] | 5478 | 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] | 5479 | uint32_t key, uint32_t state) |
| 5480 | { |
| 5481 | struct debug_binding_grab *db = (struct debug_binding_grab *) grab; |
Rob Bradford | 880ebc7 | 2013-07-22 17:31:38 +0100 | [diff] [blame] | 5482 | struct weston_compositor *ec = db->seat->compositor; |
| 5483 | struct wl_display *display = ec->wl_display; |
Ander Conselvan de Oliveira | c509d2b | 2012-11-08 17:20:45 +0200 | [diff] [blame] | 5484 | struct wl_resource *resource; |
Ander Conselvan de Oliveira | c509d2b | 2012-11-08 17:20:45 +0200 | [diff] [blame] | 5485 | uint32_t serial; |
| 5486 | int send = 0, terminate = 0; |
| 5487 | int check_binding = 1; |
| 5488 | int i; |
Neil Roberts | 96d790e | 2013-09-19 17:32:00 +0100 | [diff] [blame] | 5489 | struct wl_list *resource_list; |
Ander Conselvan de Oliveira | c509d2b | 2012-11-08 17:20:45 +0200 | [diff] [blame] | 5490 | |
| 5491 | if (state == WL_KEYBOARD_KEY_STATE_RELEASED) { |
| 5492 | /* Do not run bindings on key releases */ |
| 5493 | check_binding = 0; |
| 5494 | |
| 5495 | for (i = 0; i < 2; i++) |
| 5496 | if (key == db->key[i]) |
| 5497 | db->key_released[i] = 1; |
| 5498 | |
| 5499 | if (db->key_released[0] && db->key_released[1]) { |
| 5500 | /* All key releases been swalled so end the grab */ |
| 5501 | terminate = 1; |
| 5502 | } else if (key != db->key[0] && key != db->key[1]) { |
| 5503 | /* Should not swallow release of other keys */ |
| 5504 | send = 1; |
| 5505 | } |
| 5506 | } else if (key == db->key[0] && !db->key_released[0]) { |
| 5507 | /* Do not check bindings for the first press of the binding |
| 5508 | * key. This allows it to be used as a debug shortcut. |
| 5509 | * We still need to swallow this event. */ |
| 5510 | check_binding = 0; |
| 5511 | } else if (db->key[1]) { |
| 5512 | /* If we already ran a binding don't process another one since |
| 5513 | * we can't keep track of all the binding keys that were |
| 5514 | * pressed in order to swallow the release events. */ |
| 5515 | send = 1; |
| 5516 | check_binding = 0; |
| 5517 | } |
| 5518 | |
| 5519 | if (check_binding) { |
Ander Conselvan de Oliveira | c509d2b | 2012-11-08 17:20:45 +0200 | [diff] [blame] | 5520 | if (weston_compositor_run_debug_binding(ec, db->seat, time, |
| 5521 | key, state)) { |
| 5522 | /* We ran a binding so swallow the press and keep the |
| 5523 | * grab to swallow the released too. */ |
| 5524 | send = 0; |
| 5525 | terminate = 0; |
| 5526 | db->key[1] = key; |
| 5527 | } else { |
| 5528 | /* Terminate the grab since the key pressed is not a |
| 5529 | * debug binding key. */ |
| 5530 | send = 1; |
| 5531 | terminate = 1; |
| 5532 | } |
| 5533 | } |
| 5534 | |
| 5535 | if (send) { |
Neil Roberts | 96d790e | 2013-09-19 17:32:00 +0100 | [diff] [blame] | 5536 | serial = wl_display_next_serial(display); |
| 5537 | resource_list = &grab->keyboard->focus_resource_list; |
| 5538 | wl_resource_for_each(resource, resource_list) { |
Ander Conselvan de Oliveira | c509d2b | 2012-11-08 17:20:45 +0200 | [diff] [blame] | 5539 | wl_keyboard_send_key(resource, serial, time, key, state); |
| 5540 | } |
| 5541 | } |
| 5542 | |
| 5543 | if (terminate) { |
Kristian Høgsberg | 29139d4 | 2013-04-18 15:25:39 -0400 | [diff] [blame] | 5544 | weston_keyboard_end_grab(grab->keyboard); |
| 5545 | if (grab->keyboard->input_method_resource) |
| 5546 | grab->keyboard->grab = &grab->keyboard->input_method_grab; |
Ander Conselvan de Oliveira | c509d2b | 2012-11-08 17:20:45 +0200 | [diff] [blame] | 5547 | free(db); |
| 5548 | } |
| 5549 | } |
| 5550 | |
| 5551 | static void |
Kristian Høgsberg | 29139d4 | 2013-04-18 15:25:39 -0400 | [diff] [blame] | 5552 | 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] | 5553 | uint32_t mods_depressed, uint32_t mods_latched, |
| 5554 | uint32_t mods_locked, uint32_t group) |
| 5555 | { |
| 5556 | struct wl_resource *resource; |
Neil Roberts | 96d790e | 2013-09-19 17:32:00 +0100 | [diff] [blame] | 5557 | struct wl_list *resource_list; |
Ander Conselvan de Oliveira | c509d2b | 2012-11-08 17:20:45 +0200 | [diff] [blame] | 5558 | |
Neil Roberts | 96d790e | 2013-09-19 17:32:00 +0100 | [diff] [blame] | 5559 | resource_list = &grab->keyboard->focus_resource_list; |
Ander Conselvan de Oliveira | c509d2b | 2012-11-08 17:20:45 +0200 | [diff] [blame] | 5560 | |
Neil Roberts | 96d790e | 2013-09-19 17:32:00 +0100 | [diff] [blame] | 5561 | wl_resource_for_each(resource, resource_list) { |
| 5562 | wl_keyboard_send_modifiers(resource, serial, mods_depressed, |
| 5563 | mods_latched, mods_locked, group); |
| 5564 | } |
Ander Conselvan de Oliveira | c509d2b | 2012-11-08 17:20:45 +0200 | [diff] [blame] | 5565 | } |
| 5566 | |
Jonas Ådahl | 1ea343e | 2013-10-25 23:18:05 +0200 | [diff] [blame] | 5567 | static void |
| 5568 | debug_binding_cancel(struct weston_keyboard_grab *grab) |
| 5569 | { |
| 5570 | struct debug_binding_grab *db = (struct debug_binding_grab *) grab; |
| 5571 | |
| 5572 | weston_keyboard_end_grab(grab->keyboard); |
| 5573 | free(db); |
| 5574 | } |
| 5575 | |
Kristian Høgsberg | 29139d4 | 2013-04-18 15:25:39 -0400 | [diff] [blame] | 5576 | struct weston_keyboard_grab_interface debug_binding_keyboard_grab = { |
Ander Conselvan de Oliveira | c509d2b | 2012-11-08 17:20:45 +0200 | [diff] [blame] | 5577 | debug_binding_key, |
Jonas Ådahl | 1ea343e | 2013-10-25 23:18:05 +0200 | [diff] [blame] | 5578 | debug_binding_modifiers, |
| 5579 | debug_binding_cancel, |
Ander Conselvan de Oliveira | c509d2b | 2012-11-08 17:20:45 +0200 | [diff] [blame] | 5580 | }; |
| 5581 | |
| 5582 | static void |
Kristian Høgsberg | e314875 | 2013-05-06 23:19:49 -0400 | [diff] [blame] | 5583 | 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] | 5584 | { |
| 5585 | struct debug_binding_grab *grab; |
| 5586 | |
| 5587 | grab = calloc(1, sizeof *grab); |
| 5588 | if (!grab) |
| 5589 | return; |
| 5590 | |
| 5591 | grab->seat = (struct weston_seat *) seat; |
| 5592 | grab->key[0] = key; |
| 5593 | grab->grab.interface = &debug_binding_keyboard_grab; |
Kristian Høgsberg | 29139d4 | 2013-04-18 15:25:39 -0400 | [diff] [blame] | 5594 | weston_keyboard_start_grab(seat->keyboard, &grab->grab); |
Ander Conselvan de Oliveira | c509d2b | 2012-11-08 17:20:45 +0200 | [diff] [blame] | 5595 | } |
| 5596 | |
Kristian Høgsberg | b41c081 | 2012-03-04 14:53:40 -0500 | [diff] [blame] | 5597 | static void |
Kristian Høgsberg | e314875 | 2013-05-06 23:19:49 -0400 | [diff] [blame] | 5598 | 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] | 5599 | void *data) |
Kristian Høgsberg | 92a57db | 2012-05-26 13:41:06 -0400 | [diff] [blame] | 5600 | { |
Kristian Høgsberg | fe7aa90 | 2013-05-08 09:54:37 -0400 | [diff] [blame] | 5601 | struct weston_surface *focus_surface; |
Kristian Høgsberg | 92a57db | 2012-05-26 13:41:06 -0400 | [diff] [blame] | 5602 | struct wl_client *client; |
Tiago Vignatti | 1d01b01 | 2012-09-27 17:48:36 +0300 | [diff] [blame] | 5603 | struct desktop_shell *shell = data; |
| 5604 | struct weston_compositor *compositor = shell->compositor; |
Kristian Høgsberg | 92a57db | 2012-05-26 13:41:06 -0400 | [diff] [blame] | 5605 | pid_t pid; |
Kristian Høgsberg | 92a57db | 2012-05-26 13:41:06 -0400 | [diff] [blame] | 5606 | |
Philipp Brüschweiler | 6cef009 | 2012-08-13 21:27:27 +0200 | [diff] [blame] | 5607 | focus_surface = seat->keyboard->focus; |
| 5608 | if (!focus_surface) |
| 5609 | return; |
| 5610 | |
Tiago Vignatti | 1d01b01 | 2012-09-27 17:48:36 +0300 | [diff] [blame] | 5611 | wl_signal_emit(&compositor->kill_signal, focus_surface); |
| 5612 | |
Jason Ekstrand | 26ed73c | 2013-06-06 22:34:41 -0500 | [diff] [blame] | 5613 | client = wl_resource_get_client(focus_surface->resource); |
Tiago Vignatti | 920f197 | 2012-09-27 17:48:35 +0300 | [diff] [blame] | 5614 | wl_client_get_credentials(client, &pid, NULL, NULL); |
| 5615 | |
| 5616 | /* Skip clients that we launched ourselves (the credentials of |
| 5617 | * the socketpair is ours) */ |
| 5618 | if (pid == getpid()) |
| 5619 | return; |
Kristian Høgsberg | 92a57db | 2012-05-26 13:41:06 -0400 | [diff] [blame] | 5620 | |
Daniel Stone | 325fc2d | 2012-05-30 16:31:58 +0100 | [diff] [blame] | 5621 | kill(pid, SIGKILL); |
Kristian Høgsberg | 92a57db | 2012-05-26 13:41:06 -0400 | [diff] [blame] | 5622 | } |
| 5623 | |
| 5624 | static void |
Kristian Høgsberg | e314875 | 2013-05-06 23:19:49 -0400 | [diff] [blame] | 5625 | workspace_up_binding(struct weston_seat *seat, uint32_t time, |
Jonas Ådahl | e3cddce | 2012-06-13 00:01:22 +0200 | [diff] [blame] | 5626 | uint32_t key, void *data) |
| 5627 | { |
| 5628 | struct desktop_shell *shell = data; |
| 5629 | unsigned int new_index = shell->workspaces.current; |
| 5630 | |
Kristian Høgsberg | ce345b0 | 2012-06-25 21:35:29 -0400 | [diff] [blame] | 5631 | if (shell->locked) |
Kristian Høgsberg | 4476aaf | 2012-06-25 14:03:13 -0400 | [diff] [blame] | 5632 | return; |
Jonas Ådahl | e3cddce | 2012-06-13 00:01:22 +0200 | [diff] [blame] | 5633 | if (new_index != 0) |
| 5634 | new_index--; |
| 5635 | |
| 5636 | change_workspace(shell, new_index); |
| 5637 | } |
| 5638 | |
| 5639 | static void |
Kristian Høgsberg | e314875 | 2013-05-06 23:19:49 -0400 | [diff] [blame] | 5640 | workspace_down_binding(struct weston_seat *seat, uint32_t time, |
Jonas Ådahl | e3cddce | 2012-06-13 00:01:22 +0200 | [diff] [blame] | 5641 | uint32_t key, void *data) |
| 5642 | { |
| 5643 | struct desktop_shell *shell = data; |
| 5644 | unsigned int new_index = shell->workspaces.current; |
| 5645 | |
Kristian Høgsberg | ce345b0 | 2012-06-25 21:35:29 -0400 | [diff] [blame] | 5646 | if (shell->locked) |
Kristian Høgsberg | 4476aaf | 2012-06-25 14:03:13 -0400 | [diff] [blame] | 5647 | return; |
Jonas Ådahl | e3cddce | 2012-06-13 00:01:22 +0200 | [diff] [blame] | 5648 | if (new_index < shell->workspaces.num - 1) |
| 5649 | new_index++; |
| 5650 | |
| 5651 | change_workspace(shell, new_index); |
| 5652 | } |
| 5653 | |
| 5654 | static void |
Kristian Høgsberg | e314875 | 2013-05-06 23:19:49 -0400 | [diff] [blame] | 5655 | workspace_f_binding(struct weston_seat *seat, uint32_t time, |
Jonas Ådahl | e3cddce | 2012-06-13 00:01:22 +0200 | [diff] [blame] | 5656 | uint32_t key, void *data) |
| 5657 | { |
| 5658 | struct desktop_shell *shell = data; |
| 5659 | unsigned int new_index; |
| 5660 | |
Kristian Høgsberg | ce345b0 | 2012-06-25 21:35:29 -0400 | [diff] [blame] | 5661 | if (shell->locked) |
Kristian Høgsberg | 4476aaf | 2012-06-25 14:03:13 -0400 | [diff] [blame] | 5662 | return; |
Jonas Ådahl | e3cddce | 2012-06-13 00:01:22 +0200 | [diff] [blame] | 5663 | new_index = key - KEY_F1; |
| 5664 | if (new_index >= shell->workspaces.num) |
| 5665 | new_index = shell->workspaces.num - 1; |
| 5666 | |
| 5667 | change_workspace(shell, new_index); |
| 5668 | } |
| 5669 | |
Jonas Ådahl | 8de6a1d | 2012-08-29 22:13:00 +0200 | [diff] [blame] | 5670 | static void |
Kristian Høgsberg | e314875 | 2013-05-06 23:19:49 -0400 | [diff] [blame] | 5671 | workspace_move_surface_up_binding(struct weston_seat *seat, uint32_t time, |
Jonas Ådahl | 8de6a1d | 2012-08-29 22:13:00 +0200 | [diff] [blame] | 5672 | uint32_t key, void *data) |
| 5673 | { |
| 5674 | struct desktop_shell *shell = data; |
| 5675 | unsigned int new_index = shell->workspaces.current; |
| 5676 | |
| 5677 | if (shell->locked) |
| 5678 | return; |
| 5679 | |
| 5680 | if (new_index != 0) |
| 5681 | new_index--; |
| 5682 | |
| 5683 | take_surface_to_workspace_by_seat(shell, seat, new_index); |
| 5684 | } |
| 5685 | |
| 5686 | static void |
Kristian Høgsberg | e314875 | 2013-05-06 23:19:49 -0400 | [diff] [blame] | 5687 | workspace_move_surface_down_binding(struct weston_seat *seat, uint32_t time, |
Jonas Ådahl | 8de6a1d | 2012-08-29 22:13:00 +0200 | [diff] [blame] | 5688 | uint32_t key, void *data) |
| 5689 | { |
| 5690 | struct desktop_shell *shell = data; |
| 5691 | unsigned int new_index = shell->workspaces.current; |
| 5692 | |
| 5693 | if (shell->locked) |
| 5694 | return; |
| 5695 | |
| 5696 | if (new_index < shell->workspaces.num - 1) |
| 5697 | new_index++; |
| 5698 | |
| 5699 | take_surface_to_workspace_by_seat(shell, seat, new_index); |
| 5700 | } |
Jonas Ådahl | e3cddce | 2012-06-13 00:01:22 +0200 | [diff] [blame] | 5701 | |
| 5702 | static void |
Ander Conselvan de Oliveira | c94d622 | 2014-01-29 18:47:54 +0200 | [diff] [blame] | 5703 | shell_reposition_view_on_output_destroy(struct weston_view *view) |
| 5704 | { |
| 5705 | struct weston_output *output, *first_output; |
| 5706 | struct weston_compositor *ec = view->surface->compositor; |
| 5707 | struct shell_surface *shsurf; |
| 5708 | float x, y; |
| 5709 | int visible; |
| 5710 | |
| 5711 | x = view->geometry.x; |
| 5712 | y = view->geometry.y; |
| 5713 | |
| 5714 | /* At this point the destroyed output is not in the list anymore. |
| 5715 | * If the view is still visible somewhere, we leave where it is, |
| 5716 | * otherwise, move it to the first output. */ |
| 5717 | visible = 0; |
| 5718 | wl_list_for_each(output, &ec->output_list, link) { |
| 5719 | if (pixman_region32_contains_point(&output->region, |
| 5720 | x, y, NULL)) { |
| 5721 | visible = 1; |
| 5722 | break; |
| 5723 | } |
| 5724 | } |
| 5725 | |
| 5726 | if (!visible) { |
| 5727 | first_output = container_of(ec->output_list.next, |
| 5728 | struct weston_output, link); |
| 5729 | |
| 5730 | x = first_output->x + first_output->width / 4; |
| 5731 | y = first_output->y + first_output->height / 4; |
| 5732 | } |
| 5733 | |
| 5734 | weston_view_set_position(view, x, y); |
| 5735 | |
| 5736 | shsurf = get_shell_surface(view->surface); |
| 5737 | |
| 5738 | if (shsurf) { |
| 5739 | shsurf->saved_position_valid = false; |
| 5740 | shsurf->next_state.maximized = false; |
| 5741 | shsurf->next_state.fullscreen = false; |
| 5742 | shsurf->state_changed = true; |
| 5743 | } |
| 5744 | } |
| 5745 | |
Ander Conselvan de Oliveira | 304996d | 2014-04-11 13:57:15 +0300 | [diff] [blame] | 5746 | void |
| 5747 | shell_for_each_layer(struct desktop_shell *shell, |
| 5748 | shell_for_each_layer_func_t func, void *data) |
Ander Conselvan de Oliveira | c94d622 | 2014-01-29 18:47:54 +0200 | [diff] [blame] | 5749 | { |
Ander Conselvan de Oliveira | 304996d | 2014-04-11 13:57:15 +0300 | [diff] [blame] | 5750 | struct workspace **ws; |
| 5751 | |
| 5752 | func(shell, &shell->fullscreen_layer, data); |
| 5753 | func(shell, &shell->panel_layer, data); |
| 5754 | func(shell, &shell->background_layer, data); |
| 5755 | func(shell, &shell->lock_layer, data); |
| 5756 | func(shell, &shell->input_panel_layer, data); |
| 5757 | |
| 5758 | wl_array_for_each(ws, &shell->workspaces.array) |
| 5759 | func(shell, &(*ws)->layer, data); |
| 5760 | } |
| 5761 | |
| 5762 | static void |
| 5763 | shell_output_destroy_move_layer(struct desktop_shell *shell, |
| 5764 | struct weston_layer *layer, |
| 5765 | void *data) |
| 5766 | { |
| 5767 | struct weston_output *output = data; |
Ander Conselvan de Oliveira | c94d622 | 2014-01-29 18:47:54 +0200 | [diff] [blame] | 5768 | struct weston_view *view; |
| 5769 | |
Ander Conselvan de Oliveira | 304996d | 2014-04-11 13:57:15 +0300 | [diff] [blame] | 5770 | wl_list_for_each(view, &layer->view_list, layer_link) { |
| 5771 | if (view->output != output) |
| 5772 | continue; |
Ander Conselvan de Oliveira | c94d622 | 2014-01-29 18:47:54 +0200 | [diff] [blame] | 5773 | |
Ander Conselvan de Oliveira | 304996d | 2014-04-11 13:57:15 +0300 | [diff] [blame] | 5774 | shell_reposition_view_on_output_destroy(view); |
Ander Conselvan de Oliveira | c94d622 | 2014-01-29 18:47:54 +0200 | [diff] [blame] | 5775 | } |
| 5776 | } |
| 5777 | |
| 5778 | static void |
Xiong Zhang | 6b48142 | 2013-10-23 13:58:32 +0800 | [diff] [blame] | 5779 | handle_output_destroy(struct wl_listener *listener, void *data) |
| 5780 | { |
| 5781 | struct shell_output *output_listener = |
| 5782 | container_of(listener, struct shell_output, destroy_listener); |
Ander Conselvan de Oliveira | 304996d | 2014-04-11 13:57:15 +0300 | [diff] [blame] | 5783 | struct weston_output *output = output_listener->output; |
| 5784 | struct desktop_shell *shell = output_listener->shell; |
Xiong Zhang | 6b48142 | 2013-10-23 13:58:32 +0800 | [diff] [blame] | 5785 | |
Ander Conselvan de Oliveira | 304996d | 2014-04-11 13:57:15 +0300 | [diff] [blame] | 5786 | 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] | 5787 | |
Xiong Zhang | 6b48142 | 2013-10-23 13:58:32 +0800 | [diff] [blame] | 5788 | wl_list_remove(&output_listener->destroy_listener.link); |
| 5789 | wl_list_remove(&output_listener->link); |
| 5790 | free(output_listener); |
| 5791 | } |
| 5792 | |
| 5793 | static void |
| 5794 | create_shell_output(struct desktop_shell *shell, |
| 5795 | struct weston_output *output) |
| 5796 | { |
| 5797 | struct shell_output *shell_output; |
| 5798 | |
| 5799 | shell_output = zalloc(sizeof *shell_output); |
| 5800 | if (shell_output == NULL) |
| 5801 | return; |
| 5802 | |
| 5803 | shell_output->output = output; |
| 5804 | shell_output->shell = shell; |
| 5805 | shell_output->destroy_listener.notify = handle_output_destroy; |
| 5806 | wl_signal_add(&output->destroy_signal, |
| 5807 | &shell_output->destroy_listener); |
Kristian Høgsberg | a3a0e18 | 2013-10-23 23:36:04 -0700 | [diff] [blame] | 5808 | wl_list_insert(shell->output_list.prev, &shell_output->link); |
Xiong Zhang | 6b48142 | 2013-10-23 13:58:32 +0800 | [diff] [blame] | 5809 | } |
| 5810 | |
| 5811 | static void |
| 5812 | handle_output_create(struct wl_listener *listener, void *data) |
| 5813 | { |
| 5814 | struct desktop_shell *shell = |
| 5815 | container_of(listener, struct desktop_shell, output_create_listener); |
| 5816 | struct weston_output *output = (struct weston_output *)data; |
| 5817 | |
| 5818 | create_shell_output(shell, output); |
| 5819 | } |
| 5820 | |
| 5821 | static void |
Ander Conselvan de Oliveira | 304996d | 2014-04-11 13:57:15 +0300 | [diff] [blame] | 5822 | handle_output_move_layer(struct desktop_shell *shell, |
| 5823 | struct weston_layer *layer, void *data) |
Ander Conselvan de Oliveira | a8a9baf | 2014-01-29 18:47:52 +0200 | [diff] [blame] | 5824 | { |
Ander Conselvan de Oliveira | 304996d | 2014-04-11 13:57:15 +0300 | [diff] [blame] | 5825 | struct weston_output *output = data; |
Ander Conselvan de Oliveira | a8a9baf | 2014-01-29 18:47:52 +0200 | [diff] [blame] | 5826 | struct weston_view *view; |
| 5827 | float x, y; |
| 5828 | |
Ander Conselvan de Oliveira | 304996d | 2014-04-11 13:57:15 +0300 | [diff] [blame] | 5829 | wl_list_for_each(view, &layer->view_list, layer_link) { |
| 5830 | if (view->output != output) |
| 5831 | continue; |
| 5832 | |
| 5833 | x = view->geometry.x + output->move_x; |
| 5834 | y = view->geometry.y + output->move_y; |
| 5835 | weston_view_set_position(view, x, y); |
| 5836 | } |
| 5837 | } |
| 5838 | |
| 5839 | static void |
| 5840 | handle_output_move(struct wl_listener *listener, void *data) |
| 5841 | { |
| 5842 | struct desktop_shell *shell; |
| 5843 | |
Ander Conselvan de Oliveira | a8a9baf | 2014-01-29 18:47:52 +0200 | [diff] [blame] | 5844 | shell = container_of(listener, struct desktop_shell, |
| 5845 | output_move_listener); |
Ander Conselvan de Oliveira | a8a9baf | 2014-01-29 18:47:52 +0200 | [diff] [blame] | 5846 | |
Ander Conselvan de Oliveira | 304996d | 2014-04-11 13:57:15 +0300 | [diff] [blame] | 5847 | shell_for_each_layer(shell, handle_output_move_layer, data); |
Ander Conselvan de Oliveira | a8a9baf | 2014-01-29 18:47:52 +0200 | [diff] [blame] | 5848 | } |
| 5849 | |
| 5850 | static void |
Xiong Zhang | 6b48142 | 2013-10-23 13:58:32 +0800 | [diff] [blame] | 5851 | setup_output_destroy_handler(struct weston_compositor *ec, |
| 5852 | struct desktop_shell *shell) |
| 5853 | { |
| 5854 | struct weston_output *output; |
| 5855 | |
| 5856 | wl_list_init(&shell->output_list); |
| 5857 | wl_list_for_each(output, &ec->output_list, link) |
| 5858 | create_shell_output(shell, output); |
| 5859 | |
| 5860 | shell->output_create_listener.notify = handle_output_create; |
| 5861 | wl_signal_add(&ec->output_created_signal, |
| 5862 | &shell->output_create_listener); |
Ander Conselvan de Oliveira | a8a9baf | 2014-01-29 18:47:52 +0200 | [diff] [blame] | 5863 | |
| 5864 | shell->output_move_listener.notify = handle_output_move; |
| 5865 | wl_signal_add(&ec->output_moved_signal, &shell->output_move_listener); |
Xiong Zhang | 6b48142 | 2013-10-23 13:58:32 +0800 | [diff] [blame] | 5866 | } |
| 5867 | |
| 5868 | static void |
Kristian Høgsberg | 02e79dc | 2012-04-12 09:55:26 -0400 | [diff] [blame] | 5869 | shell_destroy(struct wl_listener *listener, void *data) |
Pekka Paalanen | 3c64723 | 2011-12-22 13:43:43 +0200 | [diff] [blame] | 5870 | { |
Tiago Vignatti | be14326 | 2012-04-16 17:31:41 +0300 | [diff] [blame] | 5871 | struct desktop_shell *shell = |
| 5872 | container_of(listener, struct desktop_shell, destroy_listener); |
Jonas Ådahl | e3cddce | 2012-06-13 00:01:22 +0200 | [diff] [blame] | 5873 | struct workspace **ws; |
Xiong Zhang | 6b48142 | 2013-10-23 13:58:32 +0800 | [diff] [blame] | 5874 | struct shell_output *shell_output, *tmp; |
Pekka Paalanen | 3c64723 | 2011-12-22 13:43:43 +0200 | [diff] [blame] | 5875 | |
Kristian Høgsberg | 17bccae | 2014-01-16 16:46:28 -0800 | [diff] [blame] | 5876 | /* Force state to unlocked so we don't try to fade */ |
| 5877 | shell->locked = false; |
Pekka Paalanen | 9cf5cc8 | 2012-01-02 16:00:24 +0200 | [diff] [blame] | 5878 | if (shell->child.client) |
| 5879 | wl_client_destroy(shell->child.client); |
| 5880 | |
Ander Conselvan de Oliveira | a457563 | 2013-02-21 18:35:23 +0200 | [diff] [blame] | 5881 | wl_list_remove(&shell->idle_listener.link); |
| 5882 | wl_list_remove(&shell->wake_listener.link); |
Kristian Høgsberg | 677a5f5 | 2013-12-04 11:00:19 -0800 | [diff] [blame] | 5883 | |
| 5884 | input_panel_destroy(shell); |
Kristian Høgsberg | 88c1607 | 2012-05-16 08:04:19 -0400 | [diff] [blame] | 5885 | |
Xiong Zhang | 6b48142 | 2013-10-23 13:58:32 +0800 | [diff] [blame] | 5886 | wl_list_for_each_safe(shell_output, tmp, &shell->output_list, link) { |
| 5887 | wl_list_remove(&shell_output->destroy_listener.link); |
| 5888 | wl_list_remove(&shell_output->link); |
| 5889 | free(shell_output); |
| 5890 | } |
| 5891 | |
| 5892 | wl_list_remove(&shell->output_create_listener.link); |
| 5893 | |
Jonas Ådahl | e3cddce | 2012-06-13 00:01:22 +0200 | [diff] [blame] | 5894 | wl_array_for_each(ws, &shell->workspaces.array) |
| 5895 | workspace_destroy(*ws); |
| 5896 | wl_array_release(&shell->workspaces.array); |
| 5897 | |
Pekka Paalanen | 3c64723 | 2011-12-22 13:43:43 +0200 | [diff] [blame] | 5898 | free(shell->screensaver.path); |
Emilio Pozuelo Monfort | 46ce798 | 2013-11-20 13:22:29 +0100 | [diff] [blame] | 5899 | free(shell->client); |
Pekka Paalanen | 3c64723 | 2011-12-22 13:43:43 +0200 | [diff] [blame] | 5900 | free(shell); |
| 5901 | } |
| 5902 | |
Tiago Vignatti | 0b52d48 | 2012-04-20 18:54:25 +0300 | [diff] [blame] | 5903 | static void |
| 5904 | shell_add_bindings(struct weston_compositor *ec, struct desktop_shell *shell) |
| 5905 | { |
| 5906 | uint32_t mod; |
Jonas Ådahl | e3cddce | 2012-06-13 00:01:22 +0200 | [diff] [blame] | 5907 | int i, num_workspace_bindings; |
Tiago Vignatti | 0b52d48 | 2012-04-20 18:54:25 +0300 | [diff] [blame] | 5908 | |
| 5909 | /* fixed bindings */ |
Daniel Stone | 325fc2d | 2012-05-30 16:31:58 +0100 | [diff] [blame] | 5910 | weston_compositor_add_key_binding(ec, KEY_BACKSPACE, |
| 5911 | MODIFIER_CTRL | MODIFIER_ALT, |
| 5912 | terminate_binding, ec); |
| 5913 | weston_compositor_add_button_binding(ec, BTN_LEFT, 0, |
| 5914 | click_to_activate_binding, |
| 5915 | shell); |
Kristian Høgsberg | f0ce581 | 2014-04-07 11:52:17 -0700 | [diff] [blame] | 5916 | weston_compositor_add_button_binding(ec, BTN_RIGHT, 0, |
| 5917 | click_to_activate_binding, |
| 5918 | shell); |
Neil Roberts | a28c693 | 2013-10-03 16:43:04 +0100 | [diff] [blame] | 5919 | weston_compositor_add_touch_binding(ec, 0, |
| 5920 | touch_to_activate_binding, |
| 5921 | shell); |
Daniel Stone | 325fc2d | 2012-05-30 16:31:58 +0100 | [diff] [blame] | 5922 | weston_compositor_add_axis_binding(ec, WL_POINTER_AXIS_VERTICAL_SCROLL, |
| 5923 | MODIFIER_SUPER | MODIFIER_ALT, |
| 5924 | surface_opacity_binding, NULL); |
| 5925 | weston_compositor_add_axis_binding(ec, WL_POINTER_AXIS_VERTICAL_SCROLL, |
| 5926 | MODIFIER_SUPER, zoom_axis_binding, |
| 5927 | NULL); |
Tiago Vignatti | 0b52d48 | 2012-04-20 18:54:25 +0300 | [diff] [blame] | 5928 | |
| 5929 | /* configurable bindings */ |
| 5930 | mod = shell->binding_modifier; |
Daniel Stone | 325fc2d | 2012-05-30 16:31:58 +0100 | [diff] [blame] | 5931 | weston_compositor_add_key_binding(ec, KEY_PAGEUP, mod, |
| 5932 | zoom_key_binding, NULL); |
| 5933 | weston_compositor_add_key_binding(ec, KEY_PAGEDOWN, mod, |
| 5934 | zoom_key_binding, NULL); |
Kristian Høgsberg | 211b517 | 2014-01-11 13:10:21 -0800 | [diff] [blame] | 5935 | weston_compositor_add_key_binding(ec, KEY_M, mod | MODIFIER_SHIFT, |
| 5936 | maximize_binding, NULL); |
| 5937 | weston_compositor_add_key_binding(ec, KEY_F, mod | MODIFIER_SHIFT, |
| 5938 | fullscreen_binding, NULL); |
Daniel Stone | 325fc2d | 2012-05-30 16:31:58 +0100 | [diff] [blame] | 5939 | weston_compositor_add_button_binding(ec, BTN_LEFT, mod, move_binding, |
| 5940 | shell); |
Neil Roberts | aba0f25 | 2013-10-03 16:43:05 +0100 | [diff] [blame] | 5941 | weston_compositor_add_touch_binding(ec, mod, touch_move_binding, shell); |
Daniel Stone | 325fc2d | 2012-05-30 16:31:58 +0100 | [diff] [blame] | 5942 | weston_compositor_add_button_binding(ec, BTN_MIDDLE, mod, |
| 5943 | resize_binding, shell); |
Kristian Høgsberg | 0837fa9 | 2014-01-20 10:35:26 -0800 | [diff] [blame] | 5944 | weston_compositor_add_button_binding(ec, BTN_LEFT, |
| 5945 | mod | MODIFIER_SHIFT, |
| 5946 | resize_binding, shell); |
Pekka Paalanen | 7bb6510 | 2013-05-22 18:03:04 +0300 | [diff] [blame] | 5947 | |
| 5948 | if (ec->capabilities & WESTON_CAP_ROTATION_ANY) |
| 5949 | weston_compositor_add_button_binding(ec, BTN_RIGHT, mod, |
| 5950 | rotate_binding, NULL); |
| 5951 | |
Daniel Stone | 325fc2d | 2012-05-30 16:31:58 +0100 | [diff] [blame] | 5952 | weston_compositor_add_key_binding(ec, KEY_TAB, mod, switcher_binding, |
| 5953 | shell); |
| 5954 | weston_compositor_add_key_binding(ec, KEY_F9, mod, backlight_binding, |
| 5955 | ec); |
| 5956 | weston_compositor_add_key_binding(ec, KEY_BRIGHTNESSDOWN, 0, |
| 5957 | backlight_binding, ec); |
| 5958 | weston_compositor_add_key_binding(ec, KEY_F10, mod, backlight_binding, |
| 5959 | ec); |
| 5960 | weston_compositor_add_key_binding(ec, KEY_BRIGHTNESSUP, 0, |
| 5961 | backlight_binding, ec); |
Daniel Stone | 325fc2d | 2012-05-30 16:31:58 +0100 | [diff] [blame] | 5962 | weston_compositor_add_key_binding(ec, KEY_K, mod, |
| 5963 | force_kill_binding, shell); |
Jonas Ådahl | e3cddce | 2012-06-13 00:01:22 +0200 | [diff] [blame] | 5964 | weston_compositor_add_key_binding(ec, KEY_UP, mod, |
| 5965 | workspace_up_binding, shell); |
| 5966 | weston_compositor_add_key_binding(ec, KEY_DOWN, mod, |
| 5967 | workspace_down_binding, shell); |
Jonas Ådahl | 8de6a1d | 2012-08-29 22:13:00 +0200 | [diff] [blame] | 5968 | weston_compositor_add_key_binding(ec, KEY_UP, mod | MODIFIER_SHIFT, |
| 5969 | workspace_move_surface_up_binding, |
| 5970 | shell); |
| 5971 | weston_compositor_add_key_binding(ec, KEY_DOWN, mod | MODIFIER_SHIFT, |
| 5972 | workspace_move_surface_down_binding, |
| 5973 | shell); |
Jonas Ådahl | e3cddce | 2012-06-13 00:01:22 +0200 | [diff] [blame] | 5974 | |
Kristian Høgsberg | d56ab4e | 2014-01-16 16:51:52 -0800 | [diff] [blame] | 5975 | if (shell->exposay_modifier) |
| 5976 | weston_compositor_add_modifier_binding(ec, shell->exposay_modifier, |
| 5977 | exposay_binding, shell); |
Daniel Stone | df8133b | 2013-11-19 11:37:14 +0100 | [diff] [blame] | 5978 | |
Jonas Ådahl | e3cddce | 2012-06-13 00:01:22 +0200 | [diff] [blame] | 5979 | /* Add bindings for mod+F[1-6] for workspace 1 to 6. */ |
| 5980 | if (shell->workspaces.num > 1) { |
| 5981 | num_workspace_bindings = shell->workspaces.num; |
| 5982 | if (num_workspace_bindings > 6) |
| 5983 | num_workspace_bindings = 6; |
| 5984 | for (i = 0; i < num_workspace_bindings; i++) |
| 5985 | weston_compositor_add_key_binding(ec, KEY_F1 + i, mod, |
| 5986 | workspace_f_binding, |
| 5987 | shell); |
| 5988 | } |
Ander Conselvan de Oliveira | c509d2b | 2012-11-08 17:20:45 +0200 | [diff] [blame] | 5989 | |
| 5990 | /* Debug bindings */ |
| 5991 | weston_compositor_add_key_binding(ec, KEY_SPACE, mod | MODIFIER_SHIFT, |
| 5992 | debug_binding, shell); |
Tiago Vignatti | 0b52d48 | 2012-04-20 18:54:25 +0300 | [diff] [blame] | 5993 | } |
| 5994 | |
Kristian Høgsberg | 1c56218 | 2011-05-02 22:09:20 -0400 | [diff] [blame] | 5995 | WL_EXPORT int |
Kristian Høgsberg | cb4685b | 2013-02-20 15:37:49 -0500 | [diff] [blame] | 5996 | module_init(struct weston_compositor *ec, |
Ossama Othman | a50e6e4 | 2013-05-14 09:48:26 -0700 | [diff] [blame] | 5997 | int *argc, char *argv[]) |
Kristian Høgsberg | 4cca349 | 2011-01-18 07:53:49 -0500 | [diff] [blame] | 5998 | { |
Kristian Høgsberg | f4d2f23 | 2012-08-10 10:05:39 -0400 | [diff] [blame] | 5999 | struct weston_seat *seat; |
Tiago Vignatti | be14326 | 2012-04-16 17:31:41 +0300 | [diff] [blame] | 6000 | struct desktop_shell *shell; |
Jonas Ådahl | e3cddce | 2012-06-13 00:01:22 +0200 | [diff] [blame] | 6001 | struct workspace **pws; |
| 6002 | unsigned int i; |
Tiago Vignatti | b7dbbd6 | 2012-09-25 17:57:01 +0300 | [diff] [blame] | 6003 | struct wl_event_loop *loop; |
Kristian Høgsberg | 02ec0a5 | 2011-04-23 13:04:11 -0400 | [diff] [blame] | 6004 | |
Peter Hutterer | f3d6227 | 2013-08-08 11:57:05 +1000 | [diff] [blame] | 6005 | shell = zalloc(sizeof *shell); |
Kristian Høgsberg | 02ec0a5 | 2011-04-23 13:04:11 -0400 | [diff] [blame] | 6006 | if (shell == NULL) |
| 6007 | return -1; |
| 6008 | |
Kristian Høgsberg | 7584062 | 2011-09-06 13:48:16 -0400 | [diff] [blame] | 6009 | shell->compositor = ec; |
Kristian Høgsberg | 02e79dc | 2012-04-12 09:55:26 -0400 | [diff] [blame] | 6010 | |
| 6011 | shell->destroy_listener.notify = shell_destroy; |
| 6012 | wl_signal_add(&ec->destroy_signal, &shell->destroy_listener); |
Ander Conselvan de Oliveira | a457563 | 2013-02-21 18:35:23 +0200 | [diff] [blame] | 6013 | shell->idle_listener.notify = idle_handler; |
| 6014 | wl_signal_add(&ec->idle_signal, &shell->idle_listener); |
| 6015 | shell->wake_listener.notify = wake_handler; |
| 6016 | wl_signal_add(&ec->wake_signal, &shell->wake_listener); |
Kristian Høgsberg | 677a5f5 | 2013-12-04 11:00:19 -0800 | [diff] [blame] | 6017 | |
Kristian Høgsberg | 82a1d11 | 2012-07-19 14:02:00 -0400 | [diff] [blame] | 6018 | ec->shell_interface.shell = shell; |
Tiago Vignatti | bc052c9 | 2012-04-19 16:18:18 +0300 | [diff] [blame] | 6019 | ec->shell_interface.create_shell_surface = create_shell_surface; |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 6020 | ec->shell_interface.get_primary_view = get_primary_view; |
Tiago Vignatti | bc052c9 | 2012-04-19 16:18:18 +0300 | [diff] [blame] | 6021 | ec->shell_interface.set_toplevel = set_toplevel; |
Tiago Vignatti | 491bac1 | 2012-05-18 16:37:43 -0400 | [diff] [blame] | 6022 | ec->shell_interface.set_transient = set_transient; |
Kristian Høgsberg | b810eb5 | 2013-02-12 20:07:05 -0500 | [diff] [blame] | 6023 | ec->shell_interface.set_fullscreen = set_fullscreen; |
Tiago Vignatti | fb2adba | 2013-06-12 15:43:21 -0300 | [diff] [blame] | 6024 | ec->shell_interface.set_xwayland = set_xwayland; |
Kristian Høgsberg | 938b8fa | 2012-05-18 13:46:27 -0400 | [diff] [blame] | 6025 | ec->shell_interface.move = surface_move; |
Kristian Høgsberg | c1693f2 | 2012-05-22 16:56:23 -0400 | [diff] [blame] | 6026 | ec->shell_interface.resize = surface_resize; |
Giulio Camuffo | 62942ad | 2013-09-11 18:20:47 +0200 | [diff] [blame] | 6027 | ec->shell_interface.set_title = set_title; |
Kristian Høgsberg | 4cca349 | 2011-01-18 07:53:49 -0500 | [diff] [blame] | 6028 | |
Kristian Høgsberg | 3be2ce9 | 2012-02-29 12:42:35 -0500 | [diff] [blame] | 6029 | weston_layer_init(&shell->fullscreen_layer, &ec->cursor_layer.link); |
| 6030 | weston_layer_init(&shell->panel_layer, &shell->fullscreen_layer.link); |
Jonas Ådahl | e3cddce | 2012-06-13 00:01:22 +0200 | [diff] [blame] | 6031 | weston_layer_init(&shell->background_layer, &shell->panel_layer.link); |
| 6032 | weston_layer_init(&shell->lock_layer, NULL); |
Philipp Brüschweiler | 711fda8 | 2012-08-09 18:50:43 +0200 | [diff] [blame] | 6033 | weston_layer_init(&shell->input_panel_layer, NULL); |
Jonas Ådahl | e3cddce | 2012-06-13 00:01:22 +0200 | [diff] [blame] | 6034 | |
| 6035 | wl_array_init(&shell->workspaces.array); |
Jonas Ådahl | e9d2250 | 2012-08-29 22:13:01 +0200 | [diff] [blame] | 6036 | wl_list_init(&shell->workspaces.client_list); |
Kristian Høgsberg | 3be2ce9 | 2012-02-29 12:42:35 -0500 | [diff] [blame] | 6037 | |
Kristian Høgsberg | 677a5f5 | 2013-12-04 11:00:19 -0800 | [diff] [blame] | 6038 | if (input_panel_setup(shell) < 0) |
| 6039 | return -1; |
| 6040 | |
Kristian Høgsberg | 14e438c | 2013-05-26 21:48:14 -0400 | [diff] [blame] | 6041 | shell_configuration(shell); |
Pekka Paalanen | e955f1e | 2011-12-07 11:49:52 +0200 | [diff] [blame] | 6042 | |
Daniel Stone | df8133b | 2013-11-19 11:37:14 +0100 | [diff] [blame] | 6043 | shell->exposay.state_cur = EXPOSAY_LAYOUT_INACTIVE; |
| 6044 | shell->exposay.state_target = EXPOSAY_TARGET_CANCEL; |
| 6045 | |
Jonas Ådahl | e3cddce | 2012-06-13 00:01:22 +0200 | [diff] [blame] | 6046 | for (i = 0; i < shell->workspaces.num; i++) { |
| 6047 | pws = wl_array_add(&shell->workspaces.array, sizeof *pws); |
| 6048 | if (pws == NULL) |
| 6049 | return -1; |
| 6050 | |
| 6051 | *pws = workspace_create(); |
| 6052 | if (*pws == NULL) |
| 6053 | return -1; |
| 6054 | } |
| 6055 | activate_workspace(shell, 0); |
| 6056 | |
Manuel Bachmann | 50c87db | 2014-02-26 15:52:13 +0100 | [diff] [blame] | 6057 | weston_layer_init(&shell->minimized_layer, NULL); |
| 6058 | |
Jonas Ådahl | 8de6a1d | 2012-08-29 22:13:00 +0200 | [diff] [blame] | 6059 | wl_list_init(&shell->workspaces.anim_sticky_list); |
Jonas Ådahl | 62fcd04 | 2012-06-13 00:01:23 +0200 | [diff] [blame] | 6060 | wl_list_init(&shell->workspaces.animation.link); |
| 6061 | shell->workspaces.animation.frame = animate_workspace_change_frame; |
| 6062 | |
Kristian Høgsberg | 919cddb | 2013-07-08 19:03:57 -0400 | [diff] [blame] | 6063 | if (wl_global_create(ec->wl_display, &wl_shell_interface, 1, |
Kristian Høgsberg | 97d44aa | 2011-08-26 17:21:20 -0400 | [diff] [blame] | 6064 | shell, bind_shell) == NULL) |
Kristian Høgsberg | 4cca349 | 2011-01-18 07:53:49 -0500 | [diff] [blame] | 6065 | return -1; |
| 6066 | |
Rafael Antognolli | e2a3455 | 2013-12-03 15:35:45 -0200 | [diff] [blame] | 6067 | if (wl_global_create(ec->wl_display, &xdg_shell_interface, 1, |
| 6068 | shell, bind_xdg_shell) == NULL) |
| 6069 | return -1; |
| 6070 | |
Kristian Høgsberg | 919cddb | 2013-07-08 19:03:57 -0400 | [diff] [blame] | 6071 | if (wl_global_create(ec->wl_display, |
| 6072 | &desktop_shell_interface, 2, |
| 6073 | shell, bind_desktop_shell) == NULL) |
Kristian Høgsberg | 7584062 | 2011-09-06 13:48:16 -0400 | [diff] [blame] | 6074 | return -1; |
| 6075 | |
Kristian Høgsberg | 919cddb | 2013-07-08 19:03:57 -0400 | [diff] [blame] | 6076 | if (wl_global_create(ec->wl_display, &screensaver_interface, 1, |
| 6077 | shell, bind_screensaver) == NULL) |
Pekka Paalanen | 6e16811 | 2011-11-24 11:34:05 +0200 | [diff] [blame] | 6078 | return -1; |
| 6079 | |
Kristian Høgsberg | 919cddb | 2013-07-08 19:03:57 -0400 | [diff] [blame] | 6080 | if (wl_global_create(ec->wl_display, &workspace_manager_interface, 1, |
| 6081 | shell, bind_workspace_manager) == NULL) |
Jonas Ådahl | e9d2250 | 2012-08-29 22:13:01 +0200 | [diff] [blame] | 6082 | return -1; |
| 6083 | |
Kristian Høgsberg | f03a616 | 2012-01-17 11:07:42 -0500 | [diff] [blame] | 6084 | shell->child.deathstamp = weston_compositor_get_time(); |
Tiago Vignatti | b7dbbd6 | 2012-09-25 17:57:01 +0300 | [diff] [blame] | 6085 | |
Xiong Zhang | 6b48142 | 2013-10-23 13:58:32 +0800 | [diff] [blame] | 6086 | setup_output_destroy_handler(ec, shell); |
| 6087 | |
Tiago Vignatti | b7dbbd6 | 2012-09-25 17:57:01 +0300 | [diff] [blame] | 6088 | loop = wl_display_get_event_loop(ec->wl_display); |
| 6089 | wl_event_loop_add_idle(loop, launch_desktop_shell_process, shell); |
Pekka Paalanen | 6cd281a | 2011-11-03 14:11:32 +0200 | [diff] [blame] | 6090 | |
Ander Conselvan de Oliveira | 859e885 | 2013-02-21 18:35:21 +0200 | [diff] [blame] | 6091 | shell->screensaver.timer = |
| 6092 | wl_event_loop_add_timer(loop, screensaver_timeout, shell); |
| 6093 | |
Jasper St. Pierre | faf27a9 | 2013-12-09 17:36:28 -0500 | [diff] [blame] | 6094 | wl_list_for_each(seat, &ec->seat_list, link) { |
Kristian Høgsberg | f4d2f23 | 2012-08-10 10:05:39 -0400 | [diff] [blame] | 6095 | create_pointer_focus_listener(seat); |
Jasper St. Pierre | faf27a9 | 2013-12-09 17:36:28 -0500 | [diff] [blame] | 6096 | create_keyboard_focus_listener(seat); |
| 6097 | } |
Kristian Høgsberg | d56bd90 | 2012-06-05 09:58:51 -0400 | [diff] [blame] | 6098 | |
Giulio Camuffo | c6ab3d5 | 2013-12-11 23:45:12 +0100 | [diff] [blame] | 6099 | screenshooter_create(ec); |
| 6100 | |
Tiago Vignatti | 0b52d48 | 2012-04-20 18:54:25 +0300 | [diff] [blame] | 6101 | shell_add_bindings(ec, shell); |
Kristian Høgsberg | 0793756 | 2011-04-12 17:25:42 -0400 | [diff] [blame] | 6102 | |
Pekka Paalanen | 79346ab | 2013-05-22 18:03:09 +0300 | [diff] [blame] | 6103 | shell_fade_init(shell); |
Ander Conselvan de Oliveira | 19d10ef | 2013-02-21 18:35:20 +0200 | [diff] [blame] | 6104 | |
Kristian Høgsberg | 4cca349 | 2011-01-18 07:53:49 -0500 | [diff] [blame] | 6105 | return 0; |
| 6106 | } |