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 | |
Philip Withnall | 648a4dd | 2013-11-25 18:01:44 +0000 | [diff] [blame] | 66 | /* |
| 67 | * Surface stacking and ordering. |
| 68 | * |
| 69 | * This is handled using several linked lists of surfaces, organised into |
| 70 | * ‘layers’. The layers are ordered, and each of the surfaces in one layer are |
| 71 | * above all of the surfaces in the layer below. The set of layers is static and |
| 72 | * in the following order (top-most first): |
| 73 | * • Lock layer (only ever displayed on its own) |
| 74 | * • Cursor layer |
| 75 | * • Fullscreen layer |
| 76 | * • Panel layer |
| 77 | * • Input panel layer |
| 78 | * • Workspace layers |
| 79 | * • Background layer |
| 80 | * |
| 81 | * The list of layers may be manipulated to remove whole layers of surfaces from |
| 82 | * display. For example, when locking the screen, all layers except the lock |
| 83 | * layer are removed. |
| 84 | * |
| 85 | * A surface’s layer is modified on configuring the surface, in |
| 86 | * set_surface_type() (which is only called when the surface’s type change is |
| 87 | * _committed_). If a surface’s type changes (e.g. when making a window |
| 88 | * fullscreen) its layer changes too. |
| 89 | * |
| 90 | * In order to allow popup and transient surfaces to be correctly stacked above |
| 91 | * their parent surfaces, each surface tracks both its parent surface, and a |
| 92 | * linked list of its children. When a surface’s layer is updated, so are the |
| 93 | * layers of its children. Note that child surfaces are *not* the same as |
| 94 | * subsurfaces — child/parent surfaces are purely for maintaining stacking |
| 95 | * order. |
| 96 | * |
| 97 | * The children_link list of siblings of a surface (i.e. those surfaces which |
| 98 | * have the same parent) only contains weston_surfaces which have a |
| 99 | * shell_surface. Stacking is not implemented for non-shell_surface |
| 100 | * weston_surfaces. This means that the following implication does *not* hold: |
| 101 | * (shsurf->parent != NULL) ⇒ !wl_list_is_empty(shsurf->children_link) |
| 102 | */ |
| 103 | |
Pekka Paalanen | 56cdea9 | 2011-11-23 16:14:12 +0200 | [diff] [blame] | 104 | struct shell_surface { |
Jason Ekstrand | 651f00e | 2013-06-14 10:07:54 -0500 | [diff] [blame] | 105 | struct wl_resource *resource; |
| 106 | struct wl_signal destroy_signal; |
Pekka Paalanen | 9d1613e | 2011-11-25 12:09:16 +0200 | [diff] [blame] | 107 | |
Kristian Høgsberg | 8334bc1 | 2012-01-03 10:29:47 -0500 | [diff] [blame] | 108 | struct weston_surface *surface; |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 109 | struct weston_view *view; |
Jason Ekstrand | 918f2dd | 2013-12-02 21:01:53 -0600 | [diff] [blame] | 110 | int32_t last_width, last_height; |
Pekka Paalanen | 9d1613e | 2011-11-25 12:09:16 +0200 | [diff] [blame] | 111 | struct wl_listener surface_destroy_listener; |
Kristian Høgsberg | 160fe75 | 2014-03-11 10:19:10 -0700 | [diff] [blame^] | 112 | struct wl_listener resource_destroy_listener; |
| 113 | |
Kristian Høgsberg | 8150b19 | 2012-06-27 10:22:58 -0400 | [diff] [blame] | 114 | struct weston_surface *parent; |
Philip Withnall | 648a4dd | 2013-11-25 18:01:44 +0000 | [diff] [blame] | 115 | struct wl_list children_list; /* child surfaces of this one */ |
| 116 | struct wl_list children_link; /* sibling surfaces of this one */ |
Tiago Vignatti | be14326 | 2012-04-16 17:31:41 +0300 | [diff] [blame] | 117 | struct desktop_shell *shell; |
Pekka Paalanen | 57da4a8 | 2011-11-23 16:42:16 +0200 | [diff] [blame] | 118 | |
Kristian Høgsberg | c8f8dd8 | 2013-12-05 23:20:33 -0800 | [diff] [blame] | 119 | enum shell_surface_type type; |
Kristian Høgsberg | e7afd91 | 2012-05-02 09:47:44 -0400 | [diff] [blame] | 120 | char *title, *class; |
Kristian Høgsberg | d2abb83 | 2011-11-23 10:52:40 -0500 | [diff] [blame] | 121 | int32_t saved_x, saved_y; |
Rafael Antognolli | 3c4e3f7 | 2013-12-03 15:35:46 -0200 | [diff] [blame] | 122 | int32_t saved_width, saved_height; |
Alex Wu | 4539b08 | 2012-03-01 12:57:46 +0800 | [diff] [blame] | 123 | bool saved_position_valid; |
Rafael Antognolli | 3c4e3f7 | 2013-12-03 15:35:46 -0200 | [diff] [blame] | 124 | bool saved_size_valid; |
Alex Wu | 7bcb8bd | 2012-04-27 09:07:24 +0800 | [diff] [blame] | 125 | bool saved_rotation_valid; |
Kristian Høgsberg | c85f1d4 | 2013-10-24 16:52:00 -0700 | [diff] [blame] | 126 | int unresponsive, grabbed; |
Kristian Høgsberg | 44cd196 | 2014-02-05 21:36:04 -0800 | [diff] [blame] | 127 | uint32_t resize_edges; |
Benjamin Franzke | d0f79ab | 2011-11-22 12:43:52 +0100 | [diff] [blame] | 128 | |
Kristian Høgsberg | b3cca0a | 2012-01-04 22:19:14 -0500 | [diff] [blame] | 129 | struct { |
Pekka Paalanen | 460099f | 2012-01-20 16:48:25 +0200 | [diff] [blame] | 130 | struct weston_transform transform; |
Kristian Høgsberg | 765e27b | 2012-01-27 13:36:13 -0500 | [diff] [blame] | 131 | struct weston_matrix rotation; |
Pekka Paalanen | 460099f | 2012-01-20 16:48:25 +0200 | [diff] [blame] | 132 | } rotation; |
| 133 | |
| 134 | struct { |
Giulio Camuffo | 5085a75 | 2013-03-25 21:42:45 +0100 | [diff] [blame] | 135 | struct wl_list grab_link; |
Kristian Høgsberg | b3cca0a | 2012-01-04 22:19:14 -0500 | [diff] [blame] | 136 | int32_t x, y; |
Giulio Camuffo | 5085a75 | 2013-03-25 21:42:45 +0100 | [diff] [blame] | 137 | struct shell_seat *shseat; |
Kristian Høgsberg | 3730f36 | 2012-04-13 12:40:07 -0400 | [diff] [blame] | 138 | uint32_t serial; |
Kristian Høgsberg | b3cca0a | 2012-01-04 22:19:14 -0500 | [diff] [blame] | 139 | } popup; |
| 140 | |
Alex Wu | 4539b08 | 2012-03-01 12:57:46 +0800 | [diff] [blame] | 141 | struct { |
Tiago Vignatti | 52e598c | 2012-05-07 15:23:08 +0300 | [diff] [blame] | 142 | int32_t x, y; |
Tiago Vignatti | 491bac1 | 2012-05-18 16:37:43 -0400 | [diff] [blame] | 143 | uint32_t flags; |
Tiago Vignatti | 52e598c | 2012-05-07 15:23:08 +0300 | [diff] [blame] | 144 | } transient; |
| 145 | |
| 146 | struct { |
Alex Wu | 4539b08 | 2012-03-01 12:57:46 +0800 | [diff] [blame] | 147 | enum wl_shell_surface_fullscreen_method type; |
| 148 | struct weston_transform transform; /* matrix from x, y */ |
| 149 | uint32_t framerate; |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 150 | struct weston_view *black_view; |
Alex Wu | 4539b08 | 2012-03-01 12:57:46 +0800 | [diff] [blame] | 151 | } fullscreen; |
| 152 | |
Jonas Ådahl | 62fcd04 | 2012-06-13 00:01:23 +0200 | [diff] [blame] | 153 | struct weston_transform workspace_transform; |
| 154 | |
Kristian Høgsberg | 1cbf326 | 2012-02-17 23:49:07 -0500 | [diff] [blame] | 155 | struct weston_output *fullscreen_output; |
Kristian Høgsberg | 8334bc1 | 2012-01-03 10:29:47 -0500 | [diff] [blame] | 156 | struct weston_output *output; |
Rafael Antognolli | 65f98d8 | 2013-12-03 15:35:47 -0200 | [diff] [blame] | 157 | struct weston_output *recommended_output; |
Benjamin Franzke | d0f79ab | 2011-11-22 12:43:52 +0100 | [diff] [blame] | 158 | struct wl_list link; |
Kristian Høgsberg | a61ca06 | 2012-05-22 16:05:52 -0400 | [diff] [blame] | 159 | |
| 160 | const struct weston_shell_client *client; |
Rafael Antognolli | 03b1659 | 2013-12-03 15:35:42 -0200 | [diff] [blame] | 161 | |
| 162 | struct { |
| 163 | bool maximized; |
| 164 | bool fullscreen; |
Rafael Antognolli | ed207b4 | 2013-12-03 15:35:43 -0200 | [diff] [blame] | 165 | bool relative; |
Jasper St. Pierre | 8c6aa45 | 2014-02-08 18:29:49 -0500 | [diff] [blame] | 166 | } state, next_state, requested_state; /* surface states */ |
Rafael Antognolli | 03b1659 | 2013-12-03 15:35:42 -0200 | [diff] [blame] | 167 | bool state_changed; |
Jasper St. Pierre | 8c6aa45 | 2014-02-08 18:29:49 -0500 | [diff] [blame] | 168 | bool state_requested; |
Jasper St. Pierre | faf27a9 | 2013-12-09 17:36:28 -0500 | [diff] [blame] | 169 | |
| 170 | int focus_count; |
Pekka Paalanen | 56cdea9 | 2011-11-23 16:14:12 +0200 | [diff] [blame] | 171 | }; |
| 172 | |
Ander Conselvan de Oliveira | fe0444a | 2012-04-04 17:48:05 +0300 | [diff] [blame] | 173 | struct shell_grab { |
Kristian Høgsberg | 02bbabb | 2013-05-06 22:15:05 -0400 | [diff] [blame] | 174 | struct weston_pointer_grab grab; |
Ander Conselvan de Oliveira | fe0444a | 2012-04-04 17:48:05 +0300 | [diff] [blame] | 175 | struct shell_surface *shsurf; |
| 176 | struct wl_listener shsurf_destroy_listener; |
| 177 | }; |
| 178 | |
Rusty Lynch | 1084da5 | 2013-08-15 09:10:08 -0700 | [diff] [blame] | 179 | struct shell_touch_grab { |
| 180 | struct weston_touch_grab grab; |
| 181 | struct shell_surface *shsurf; |
| 182 | struct wl_listener shsurf_destroy_listener; |
| 183 | struct weston_touch *touch; |
| 184 | }; |
| 185 | |
Ander Conselvan de Oliveira | fe0444a | 2012-04-04 17:48:05 +0300 | [diff] [blame] | 186 | struct weston_move_grab { |
| 187 | struct shell_grab base; |
Daniel Stone | 103db7f | 2012-05-08 17:17:55 +0100 | [diff] [blame] | 188 | wl_fixed_t dx, dy; |
Kristian Høgsberg | 4cca349 | 2011-01-18 07:53:49 -0500 | [diff] [blame] | 189 | }; |
| 190 | |
Rusty Lynch | 1084da5 | 2013-08-15 09:10:08 -0700 | [diff] [blame] | 191 | struct weston_touch_move_grab { |
| 192 | struct shell_touch_grab base; |
Kristian Høgsberg | 8e80a31 | 2014-01-17 15:18:10 -0800 | [diff] [blame] | 193 | int active; |
Rusty Lynch | 1084da5 | 2013-08-15 09:10:08 -0700 | [diff] [blame] | 194 | wl_fixed_t dx, dy; |
| 195 | }; |
| 196 | |
Pekka Paalanen | 460099f | 2012-01-20 16:48:25 +0200 | [diff] [blame] | 197 | struct rotate_grab { |
Ander Conselvan de Oliveira | fe0444a | 2012-04-04 17:48:05 +0300 | [diff] [blame] | 198 | struct shell_grab base; |
Kristian Høgsberg | 765e27b | 2012-01-27 13:36:13 -0500 | [diff] [blame] | 199 | struct weston_matrix rotation; |
Pekka Paalanen | 460099f | 2012-01-20 16:48:25 +0200 | [diff] [blame] | 200 | struct { |
John Kåre Alsaker | 490d02a | 2012-09-30 02:57:21 +0200 | [diff] [blame] | 201 | float x; |
| 202 | float y; |
Pekka Paalanen | 460099f | 2012-01-20 16:48:25 +0200 | [diff] [blame] | 203 | } center; |
| 204 | }; |
| 205 | |
Giulio Camuffo | 5085a75 | 2013-03-25 21:42:45 +0100 | [diff] [blame] | 206 | struct shell_seat { |
| 207 | struct weston_seat *seat; |
| 208 | struct wl_listener seat_destroy_listener; |
Jasper St. Pierre | faf27a9 | 2013-12-09 17:36:28 -0500 | [diff] [blame] | 209 | struct weston_surface *focused_surface; |
Giulio Camuffo | 5085a75 | 2013-03-25 21:42:45 +0100 | [diff] [blame] | 210 | |
| 211 | struct { |
Kristian Høgsberg | 02bbabb | 2013-05-06 22:15:05 -0400 | [diff] [blame] | 212 | struct weston_pointer_grab grab; |
Giulio Camuffo | 5085a75 | 2013-03-25 21:42:45 +0100 | [diff] [blame] | 213 | struct wl_list surfaces_list; |
| 214 | struct wl_client *client; |
| 215 | int32_t initial_up; |
| 216 | } popup_grab; |
| 217 | }; |
| 218 | |
Kristian Høgsberg | 2bff94e | 2014-02-11 12:22:51 -0800 | [diff] [blame] | 219 | struct shell_client { |
| 220 | struct wl_resource *resource; |
| 221 | struct wl_client *client; |
| 222 | struct desktop_shell *shell; |
| 223 | struct wl_listener destroy_listener; |
| 224 | struct wl_event_source *ping_timer; |
| 225 | uint32_t ping_serial; |
| 226 | int unresponsive; |
| 227 | }; |
| 228 | |
Emilio Pozuelo Monfort | 1a26f1b | 2014-01-07 16:41:40 +0100 | [diff] [blame] | 229 | void |
| 230 | set_alpha_if_fullscreen(struct shell_surface *shsurf) |
| 231 | { |
| 232 | if (shsurf && shsurf->state.fullscreen) |
| 233 | shsurf->fullscreen.black_view->alpha = 0.25; |
| 234 | } |
| 235 | |
Kristian Høgsberg | dd62aba | 2014-02-12 09:56:19 -0800 | [diff] [blame] | 236 | static struct shell_client * |
| 237 | get_shell_client(struct wl_client *client); |
| 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 | |
Rusty Lynch | 1084da5 | 2013-08-15 09:10:08 -0700 | [diff] [blame] | 367 | grab->grab.interface = interface; |
| 368 | grab->shsurf = shsurf; |
| 369 | grab->shsurf_destroy_listener.notify = destroy_shell_grab_shsurf; |
| 370 | wl_signal_add(&shsurf->destroy_signal, |
| 371 | &grab->shsurf_destroy_listener); |
| 372 | |
| 373 | grab->touch = touch; |
Kristian Høgsberg | c85f1d4 | 2013-10-24 16:52:00 -0700 | [diff] [blame] | 374 | shsurf->grabbed = 1; |
Rusty Lynch | 1084da5 | 2013-08-15 09:10:08 -0700 | [diff] [blame] | 375 | |
| 376 | weston_touch_start_grab(touch, &grab->grab); |
| 377 | if (shell->child.desktop_shell) |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 378 | weston_touch_set_focus(touch->seat, |
| 379 | get_default_view(shell->grab_surface)); |
Rusty Lynch | 1084da5 | 2013-08-15 09:10:08 -0700 | [diff] [blame] | 380 | } |
| 381 | |
| 382 | static void |
| 383 | shell_touch_grab_end(struct shell_touch_grab *grab) |
| 384 | { |
Kristian Høgsberg | c85f1d4 | 2013-10-24 16:52:00 -0700 | [diff] [blame] | 385 | if (grab->shsurf) { |
Rusty Lynch | 1084da5 | 2013-08-15 09:10:08 -0700 | [diff] [blame] | 386 | wl_list_remove(&grab->shsurf_destroy_listener.link); |
Kristian Høgsberg | c85f1d4 | 2013-10-24 16:52:00 -0700 | [diff] [blame] | 387 | grab->shsurf->grabbed = 0; |
| 388 | } |
Rusty Lynch | 1084da5 | 2013-08-15 09:10:08 -0700 | [diff] [blame] | 389 | |
| 390 | weston_touch_end_grab(grab->touch); |
| 391 | } |
| 392 | |
| 393 | static void |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 394 | center_on_output(struct weston_view *view, |
Alex Wu | 4539b08 | 2012-03-01 12:57:46 +0800 | [diff] [blame] | 395 | struct weston_output *output); |
| 396 | |
Daniel Stone | 496ca17 | 2012-05-30 16:31:42 +0100 | [diff] [blame] | 397 | static enum weston_keyboard_modifier |
Tiago Vignatti | 0b52d48 | 2012-04-20 18:54:25 +0300 | [diff] [blame] | 398 | get_modifier(char *modifier) |
| 399 | { |
| 400 | if (!modifier) |
| 401 | return MODIFIER_SUPER; |
| 402 | |
| 403 | if (!strcmp("ctrl", modifier)) |
| 404 | return MODIFIER_CTRL; |
| 405 | else if (!strcmp("alt", modifier)) |
| 406 | return MODIFIER_ALT; |
| 407 | else if (!strcmp("super", modifier)) |
| 408 | return MODIFIER_SUPER; |
| 409 | else |
| 410 | return MODIFIER_SUPER; |
| 411 | } |
| 412 | |
Juan Zhao | e10d279 | 2012-04-25 19:09:52 +0800 | [diff] [blame] | 413 | static enum animation_type |
| 414 | get_animation_type(char *animation) |
| 415 | { |
U. Artie Eoff | b571910 | 2014-01-15 14:26:31 -0800 | [diff] [blame] | 416 | if (!animation) |
| 417 | return ANIMATION_NONE; |
| 418 | |
Juan Zhao | e10d279 | 2012-04-25 19:09:52 +0800 | [diff] [blame] | 419 | if (!strcmp("zoom", animation)) |
| 420 | return ANIMATION_ZOOM; |
| 421 | else if (!strcmp("fade", animation)) |
| 422 | return ANIMATION_FADE; |
Louis-Francis Ratté-Boulianne | b482dbd | 2013-11-19 11:37:11 +0100 | [diff] [blame] | 423 | else if (!strcmp("dim-layer", animation)) |
| 424 | return ANIMATION_DIM_LAYER; |
Juan Zhao | e10d279 | 2012-04-25 19:09:52 +0800 | [diff] [blame] | 425 | else |
| 426 | return ANIMATION_NONE; |
| 427 | } |
| 428 | |
Alex Wu | 4539b08 | 2012-03-01 12:57:46 +0800 | [diff] [blame] | 429 | static void |
Kristian Høgsberg | 14e438c | 2013-05-26 21:48:14 -0400 | [diff] [blame] | 430 | shell_configuration(struct desktop_shell *shell) |
Pekka Paalanen | e955f1e | 2011-12-07 11:49:52 +0200 | [diff] [blame] | 431 | { |
Kristian Høgsberg | 673a889 | 2013-05-23 21:40:56 -0400 | [diff] [blame] | 432 | struct weston_config_section *section; |
| 433 | int duration; |
| 434 | char *s; |
Pekka Paalanen | e955f1e | 2011-12-07 11:49:52 +0200 | [diff] [blame] | 435 | |
Kristian Høgsberg | 673a889 | 2013-05-23 21:40:56 -0400 | [diff] [blame] | 436 | section = weston_config_get_section(shell->compositor->config, |
| 437 | "screensaver", NULL, NULL); |
| 438 | weston_config_section_get_string(section, |
| 439 | "path", &shell->screensaver.path, NULL); |
| 440 | weston_config_section_get_int(section, "duration", &duration, 60); |
Ander Conselvan de Oliveira | 859e885 | 2013-02-21 18:35:21 +0200 | [diff] [blame] | 441 | shell->screensaver.duration = duration * 1000; |
Kristian Høgsberg | 673a889 | 2013-05-23 21:40:56 -0400 | [diff] [blame] | 442 | |
| 443 | section = weston_config_get_section(shell->compositor->config, |
| 444 | "shell", NULL, NULL); |
| 445 | weston_config_section_get_string(section, |
Emilio Pozuelo Monfort | 8a81b83 | 2013-12-02 12:53:32 +0100 | [diff] [blame] | 446 | "client", &s, LIBEXECDIR "/" WESTON_SHELL_CLIENT); |
Emilio Pozuelo Monfort | 46ce798 | 2013-11-20 13:22:29 +0100 | [diff] [blame] | 447 | shell->client = s; |
| 448 | weston_config_section_get_string(section, |
Kristian Høgsberg | 673a889 | 2013-05-23 21:40:56 -0400 | [diff] [blame] | 449 | "binding-modifier", &s, "super"); |
| 450 | shell->binding_modifier = get_modifier(s); |
Quentin Glidic | 8418c29 | 2013-06-18 09:11:03 +0200 | [diff] [blame] | 451 | free(s); |
Kristian Høgsberg | d56ab4e | 2014-01-16 16:51:52 -0800 | [diff] [blame] | 452 | |
| 453 | weston_config_section_get_string(section, |
| 454 | "exposay-modifier", &s, "none"); |
| 455 | if (strcmp(s, "none") == 0) |
| 456 | shell->exposay_modifier = 0; |
| 457 | else |
| 458 | shell->exposay_modifier = get_modifier(s); |
| 459 | free(s); |
| 460 | |
Kristian Høgsberg | 673a889 | 2013-05-23 21:40:56 -0400 | [diff] [blame] | 461 | weston_config_section_get_string(section, "animation", &s, "none"); |
| 462 | shell->win_animation_type = get_animation_type(s); |
Quentin Glidic | 8418c29 | 2013-06-18 09:11:03 +0200 | [diff] [blame] | 463 | free(s); |
Kristian Høgsberg | 724c8d9 | 2013-10-16 11:38:24 -0700 | [diff] [blame] | 464 | weston_config_section_get_string(section, |
| 465 | "startup-animation", &s, "fade"); |
| 466 | shell->startup_animation_type = get_animation_type(s); |
| 467 | free(s); |
Kristian Høgsberg | 912e0a1 | 2013-10-30 08:59:55 -0700 | [diff] [blame] | 468 | if (shell->startup_animation_type == ANIMATION_ZOOM) |
| 469 | shell->startup_animation_type = ANIMATION_NONE; |
Louis-Francis Ratté-Boulianne | b482dbd | 2013-11-19 11:37:11 +0100 | [diff] [blame] | 470 | weston_config_section_get_string(section, "focus-animation", &s, "none"); |
| 471 | shell->focus_animation_type = get_animation_type(s); |
| 472 | free(s); |
Kristian Høgsberg | 673a889 | 2013-05-23 21:40:56 -0400 | [diff] [blame] | 473 | weston_config_section_get_uint(section, "num-workspaces", |
| 474 | &shell->workspaces.num, |
| 475 | DEFAULT_NUM_WORKSPACES); |
Jonas Ådahl | e3cddce | 2012-06-13 00:01:22 +0200 | [diff] [blame] | 476 | } |
| 477 | |
Kristian Høgsberg | 1ef2313 | 2013-12-04 00:20:01 -0800 | [diff] [blame] | 478 | struct weston_output * |
Louis-Francis Ratté-Boulianne | b482dbd | 2013-11-19 11:37:11 +0100 | [diff] [blame] | 479 | get_default_output(struct weston_compositor *compositor) |
| 480 | { |
| 481 | return container_of(compositor->output_list.next, |
| 482 | struct weston_output, link); |
| 483 | } |
| 484 | |
| 485 | |
| 486 | /* no-op func for checking focus surface */ |
| 487 | static void |
Jason Ekstrand | 918f2dd | 2013-12-02 21:01:53 -0600 | [diff] [blame] | 488 | 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] | 489 | { |
| 490 | } |
| 491 | |
| 492 | static struct focus_surface * |
| 493 | get_focus_surface(struct weston_surface *surface) |
| 494 | { |
| 495 | if (surface->configure == focus_surface_configure) |
| 496 | return surface->configure_private; |
| 497 | else |
| 498 | return NULL; |
| 499 | } |
| 500 | |
| 501 | static bool |
| 502 | is_focus_surface (struct weston_surface *es) |
| 503 | { |
| 504 | return (es->configure == focus_surface_configure); |
| 505 | } |
| 506 | |
| 507 | static bool |
| 508 | is_focus_view (struct weston_view *view) |
| 509 | { |
| 510 | return is_focus_surface (view->surface); |
| 511 | } |
| 512 | |
| 513 | static struct focus_surface * |
| 514 | create_focus_surface(struct weston_compositor *ec, |
| 515 | struct weston_output *output) |
| 516 | { |
| 517 | struct focus_surface *fsurf = NULL; |
| 518 | struct weston_surface *surface = NULL; |
| 519 | |
| 520 | fsurf = malloc(sizeof *fsurf); |
| 521 | if (!fsurf) |
| 522 | return NULL; |
| 523 | |
| 524 | fsurf->surface = weston_surface_create(ec); |
| 525 | surface = fsurf->surface; |
| 526 | if (surface == NULL) { |
| 527 | free(fsurf); |
| 528 | return NULL; |
| 529 | } |
| 530 | |
| 531 | surface->configure = focus_surface_configure; |
| 532 | surface->output = output; |
| 533 | surface->configure_private = fsurf; |
| 534 | |
U. Artie Eoff | 0b23b2b | 2014-01-15 14:45:59 -0800 | [diff] [blame] | 535 | fsurf->view = weston_view_create(surface); |
| 536 | if (fsurf->view == NULL) { |
| 537 | weston_surface_destroy(surface); |
| 538 | free(fsurf); |
| 539 | return NULL; |
| 540 | } |
Emilio Pozuelo Monfort | da64426 | 2013-11-19 11:37:19 +0100 | [diff] [blame] | 541 | fsurf->view->output = output; |
Louis-Francis Ratté-Boulianne | b482dbd | 2013-11-19 11:37:11 +0100 | [diff] [blame] | 542 | |
Jason Ekstrand | 5c11a33 | 2013-12-04 20:32:03 -0600 | [diff] [blame] | 543 | weston_surface_set_size(surface, output->width, output->height); |
Jason Ekstrand | 918f2dd | 2013-12-02 21:01:53 -0600 | [diff] [blame] | 544 | weston_view_set_position(fsurf->view, output->x, output->y); |
Louis-Francis Ratté-Boulianne | b482dbd | 2013-11-19 11:37:11 +0100 | [diff] [blame] | 545 | weston_surface_set_color(surface, 0.0, 0.0, 0.0, 1.0); |
| 546 | pixman_region32_fini(&surface->opaque); |
| 547 | pixman_region32_init_rect(&surface->opaque, output->x, output->y, |
| 548 | output->width, output->height); |
| 549 | pixman_region32_fini(&surface->input); |
| 550 | pixman_region32_init(&surface->input); |
| 551 | |
| 552 | wl_list_init(&fsurf->workspace_transform.link); |
| 553 | |
| 554 | return fsurf; |
| 555 | } |
| 556 | |
| 557 | static void |
| 558 | focus_surface_destroy(struct focus_surface *fsurf) |
| 559 | { |
| 560 | weston_surface_destroy(fsurf->surface); |
| 561 | free(fsurf); |
| 562 | } |
| 563 | |
| 564 | static void |
| 565 | focus_animation_done(struct weston_view_animation *animation, void *data) |
| 566 | { |
| 567 | struct workspace *ws = data; |
| 568 | |
| 569 | ws->focus_animation = NULL; |
| 570 | } |
| 571 | |
Jonas Ådahl | e3cddce | 2012-06-13 00:01:22 +0200 | [diff] [blame] | 572 | static void |
Jonas Ådahl | 0476974 | 2012-06-13 00:01:24 +0200 | [diff] [blame] | 573 | focus_state_destroy(struct focus_state *state) |
| 574 | { |
| 575 | wl_list_remove(&state->seat_destroy_listener.link); |
| 576 | wl_list_remove(&state->surface_destroy_listener.link); |
| 577 | free(state); |
| 578 | } |
| 579 | |
| 580 | static void |
| 581 | focus_state_seat_destroy(struct wl_listener *listener, void *data) |
| 582 | { |
| 583 | struct focus_state *state = container_of(listener, |
| 584 | struct focus_state, |
| 585 | seat_destroy_listener); |
| 586 | |
| 587 | wl_list_remove(&state->link); |
| 588 | focus_state_destroy(state); |
| 589 | } |
| 590 | |
| 591 | static void |
| 592 | focus_state_surface_destroy(struct wl_listener *listener, void *data) |
| 593 | { |
| 594 | struct focus_state *state = container_of(listener, |
| 595 | struct focus_state, |
Kristian Høgsberg | b8e0d0f | 2012-07-31 10:30:26 -0400 | [diff] [blame] | 596 | surface_destroy_listener); |
Kristian Høgsberg | e377822 | 2012-07-31 17:29:30 -0400 | [diff] [blame] | 597 | struct desktop_shell *shell; |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 598 | struct weston_surface *main_surface, *next; |
| 599 | struct weston_view *view; |
Jonas Ådahl | 0476974 | 2012-06-13 00:01:24 +0200 | [diff] [blame] | 600 | |
Pekka Paalanen | 01388e2 | 2013-04-25 13:57:44 +0300 | [diff] [blame] | 601 | main_surface = weston_surface_get_main_surface(state->keyboard_focus); |
| 602 | |
Kristian Høgsberg | e377822 | 2012-07-31 17:29:30 -0400 | [diff] [blame] | 603 | next = NULL; |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 604 | wl_list_for_each(view, &state->ws->layer.view_list, layer_link) { |
| 605 | if (view->surface == main_surface) |
Kristian Høgsberg | e377822 | 2012-07-31 17:29:30 -0400 | [diff] [blame] | 606 | continue; |
Louis-Francis Ratté-Boulianne | b482dbd | 2013-11-19 11:37:11 +0100 | [diff] [blame] | 607 | if (is_focus_view(view)) |
| 608 | continue; |
Kristian Høgsberg | e377822 | 2012-07-31 17:29:30 -0400 | [diff] [blame] | 609 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 610 | next = view->surface; |
Kristian Høgsberg | e377822 | 2012-07-31 17:29:30 -0400 | [diff] [blame] | 611 | break; |
| 612 | } |
| 613 | |
Pekka Paalanen | 01388e2 | 2013-04-25 13:57:44 +0300 | [diff] [blame] | 614 | /* if the focus was a sub-surface, activate its main surface */ |
| 615 | if (main_surface != state->keyboard_focus) |
| 616 | next = main_surface; |
| 617 | |
Louis-Francis Ratté-Boulianne | b482dbd | 2013-11-19 11:37:11 +0100 | [diff] [blame] | 618 | shell = state->seat->compositor->shell_interface.shell; |
Kristian Høgsberg | e377822 | 2012-07-31 17:29:30 -0400 | [diff] [blame] | 619 | if (next) { |
Louis-Francis Ratté-Boulianne | b482dbd | 2013-11-19 11:37:11 +0100 | [diff] [blame] | 620 | state->keyboard_focus = NULL; |
Kristian Høgsberg | e377822 | 2012-07-31 17:29:30 -0400 | [diff] [blame] | 621 | activate(shell, next, state->seat); |
| 622 | } else { |
Louis-Francis Ratté-Boulianne | b482dbd | 2013-11-19 11:37:11 +0100 | [diff] [blame] | 623 | if (shell->focus_animation_type == ANIMATION_DIM_LAYER) { |
| 624 | if (state->ws->focus_animation) |
| 625 | weston_view_animation_destroy(state->ws->focus_animation); |
| 626 | |
| 627 | state->ws->focus_animation = weston_fade_run( |
| 628 | state->ws->fsurf_front->view, |
| 629 | state->ws->fsurf_front->view->alpha, 0.0, 300, |
| 630 | focus_animation_done, state->ws); |
| 631 | } |
| 632 | |
Kristian Høgsberg | e377822 | 2012-07-31 17:29:30 -0400 | [diff] [blame] | 633 | wl_list_remove(&state->link); |
| 634 | focus_state_destroy(state); |
| 635 | } |
Jonas Ådahl | 0476974 | 2012-06-13 00:01:24 +0200 | [diff] [blame] | 636 | } |
| 637 | |
| 638 | static struct focus_state * |
Kristian Høgsberg | 2f5faff | 2012-07-31 16:36:34 -0400 | [diff] [blame] | 639 | focus_state_create(struct weston_seat *seat, struct workspace *ws) |
Jonas Ådahl | 0476974 | 2012-06-13 00:01:24 +0200 | [diff] [blame] | 640 | { |
Jonas Ådahl | 0476974 | 2012-06-13 00:01:24 +0200 | [diff] [blame] | 641 | struct focus_state *state; |
Jonas Ådahl | 0476974 | 2012-06-13 00:01:24 +0200 | [diff] [blame] | 642 | |
| 643 | state = malloc(sizeof *state); |
| 644 | if (state == NULL) |
| 645 | return NULL; |
| 646 | |
Louis-Francis Ratté-Boulianne | b482dbd | 2013-11-19 11:37:11 +0100 | [diff] [blame] | 647 | state->keyboard_focus = NULL; |
Kristian Høgsberg | 2f5faff | 2012-07-31 16:36:34 -0400 | [diff] [blame] | 648 | state->ws = ws; |
Jonas Ådahl | 0476974 | 2012-06-13 00:01:24 +0200 | [diff] [blame] | 649 | state->seat = seat; |
Kristian Høgsberg | 2f5faff | 2012-07-31 16:36:34 -0400 | [diff] [blame] | 650 | wl_list_insert(&ws->focus_list, &state->link); |
Jonas Ådahl | 0476974 | 2012-06-13 00:01:24 +0200 | [diff] [blame] | 651 | |
| 652 | state->seat_destroy_listener.notify = focus_state_seat_destroy; |
| 653 | state->surface_destroy_listener.notify = focus_state_surface_destroy; |
Kristian Høgsberg | 4912454 | 2013-05-06 22:27:40 -0400 | [diff] [blame] | 654 | wl_signal_add(&seat->destroy_signal, |
Jonas Ådahl | 0476974 | 2012-06-13 00:01:24 +0200 | [diff] [blame] | 655 | &state->seat_destroy_listener); |
Kristian Høgsberg | 2f5faff | 2012-07-31 16:36:34 -0400 | [diff] [blame] | 656 | wl_list_init(&state->surface_destroy_listener.link); |
Jonas Ådahl | 0476974 | 2012-06-13 00:01:24 +0200 | [diff] [blame] | 657 | |
| 658 | return state; |
| 659 | } |
| 660 | |
Jonas Ådahl | 8538b22 | 2012-08-29 22:13:03 +0200 | [diff] [blame] | 661 | static struct focus_state * |
| 662 | ensure_focus_state(struct desktop_shell *shell, struct weston_seat *seat) |
| 663 | { |
| 664 | struct workspace *ws = get_current_workspace(shell); |
| 665 | struct focus_state *state; |
| 666 | |
| 667 | wl_list_for_each(state, &ws->focus_list, link) |
| 668 | if (state->seat == seat) |
| 669 | break; |
| 670 | |
| 671 | if (&state->link == &ws->focus_list) |
| 672 | state = focus_state_create(seat, ws); |
| 673 | |
| 674 | return state; |
| 675 | } |
| 676 | |
Jonas Ådahl | 0476974 | 2012-06-13 00:01:24 +0200 | [diff] [blame] | 677 | static void |
Kristian Høgsberg | d500bf1 | 2014-01-22 12:25:20 -0800 | [diff] [blame] | 678 | focus_state_set_focus(struct focus_state *state, |
| 679 | struct weston_surface *surface) |
| 680 | { |
| 681 | if (state->keyboard_focus) { |
| 682 | wl_list_remove(&state->surface_destroy_listener.link); |
| 683 | wl_list_init(&state->surface_destroy_listener.link); |
| 684 | } |
| 685 | |
| 686 | state->keyboard_focus = surface; |
| 687 | if (surface) |
| 688 | wl_signal_add(&surface->destroy_signal, |
| 689 | &state->surface_destroy_listener); |
| 690 | } |
| 691 | |
| 692 | static void |
Kristian Høgsberg | 2f5faff | 2012-07-31 16:36:34 -0400 | [diff] [blame] | 693 | restore_focus_state(struct desktop_shell *shell, struct workspace *ws) |
Jonas Ådahl | 0476974 | 2012-06-13 00:01:24 +0200 | [diff] [blame] | 694 | { |
| 695 | struct focus_state *state, *next; |
Kristian Høgsberg | fe7aa90 | 2013-05-08 09:54:37 -0400 | [diff] [blame] | 696 | struct weston_surface *surface; |
Jonas Ådahl | 0476974 | 2012-06-13 00:01:24 +0200 | [diff] [blame] | 697 | |
| 698 | wl_list_for_each_safe(state, next, &ws->focus_list, link) { |
Kristian Høgsberg | e61d2f4 | 2014-01-17 12:18:53 -0800 | [diff] [blame] | 699 | if (state->seat->keyboard == NULL) |
| 700 | continue; |
| 701 | |
Kristian Høgsberg | fe7aa90 | 2013-05-08 09:54:37 -0400 | [diff] [blame] | 702 | surface = state->keyboard_focus; |
Jonas Ådahl | 5689944 | 2012-08-29 22:12:59 +0200 | [diff] [blame] | 703 | |
Kristian Høgsberg | e314875 | 2013-05-06 23:19:49 -0400 | [diff] [blame] | 704 | weston_keyboard_set_focus(state->seat->keyboard, surface); |
Jonas Ådahl | 0476974 | 2012-06-13 00:01:24 +0200 | [diff] [blame] | 705 | } |
| 706 | } |
| 707 | |
| 708 | static void |
Jonas Ådahl | 8de6a1d | 2012-08-29 22:13:00 +0200 | [diff] [blame] | 709 | replace_focus_state(struct desktop_shell *shell, struct workspace *ws, |
| 710 | struct weston_seat *seat) |
| 711 | { |
| 712 | struct focus_state *state; |
Jonas Ådahl | 8de6a1d | 2012-08-29 22:13:00 +0200 | [diff] [blame] | 713 | |
| 714 | wl_list_for_each(state, &ws->focus_list, link) { |
| 715 | if (state->seat == seat) { |
Kristian Høgsberg | d500bf1 | 2014-01-22 12:25:20 -0800 | [diff] [blame] | 716 | focus_state_set_focus(state, seat->keyboard->focus); |
Jonas Ådahl | 8de6a1d | 2012-08-29 22:13:00 +0200 | [diff] [blame] | 717 | return; |
| 718 | } |
| 719 | } |
| 720 | } |
| 721 | |
| 722 | static void |
| 723 | drop_focus_state(struct desktop_shell *shell, struct workspace *ws, |
| 724 | struct weston_surface *surface) |
| 725 | { |
| 726 | struct focus_state *state; |
| 727 | |
| 728 | wl_list_for_each(state, &ws->focus_list, link) |
| 729 | if (state->keyboard_focus == surface) |
Kristian Høgsberg | d500bf1 | 2014-01-22 12:25:20 -0800 | [diff] [blame] | 730 | focus_state_set_focus(state, NULL); |
Jonas Ådahl | 8de6a1d | 2012-08-29 22:13:00 +0200 | [diff] [blame] | 731 | } |
| 732 | |
| 733 | static void |
Louis-Francis Ratté-Boulianne | b482dbd | 2013-11-19 11:37:11 +0100 | [diff] [blame] | 734 | animate_focus_change(struct desktop_shell *shell, struct workspace *ws, |
| 735 | struct weston_view *from, struct weston_view *to) |
| 736 | { |
| 737 | struct weston_output *output; |
| 738 | bool focus_surface_created = false; |
| 739 | |
| 740 | /* FIXME: Only support dim animation using two layers */ |
| 741 | if (from == to || shell->focus_animation_type != ANIMATION_DIM_LAYER) |
| 742 | return; |
| 743 | |
| 744 | output = get_default_output(shell->compositor); |
| 745 | if (ws->fsurf_front == NULL && (from || to)) { |
| 746 | ws->fsurf_front = create_focus_surface(shell->compositor, output); |
U. Artie Eoff | 0b23b2b | 2014-01-15 14:45:59 -0800 | [diff] [blame] | 747 | if (ws->fsurf_front == NULL) |
| 748 | return; |
Louis-Francis Ratté-Boulianne | b482dbd | 2013-11-19 11:37:11 +0100 | [diff] [blame] | 749 | ws->fsurf_front->view->alpha = 0.0; |
U. Artie Eoff | 0b23b2b | 2014-01-15 14:45:59 -0800 | [diff] [blame] | 750 | |
| 751 | ws->fsurf_back = create_focus_surface(shell->compositor, output); |
| 752 | if (ws->fsurf_back == NULL) { |
| 753 | focus_surface_destroy(ws->fsurf_front); |
| 754 | return; |
| 755 | } |
Louis-Francis Ratté-Boulianne | b482dbd | 2013-11-19 11:37:11 +0100 | [diff] [blame] | 756 | ws->fsurf_back->view->alpha = 0.0; |
U. Artie Eoff | 0b23b2b | 2014-01-15 14:45:59 -0800 | [diff] [blame] | 757 | |
Louis-Francis Ratté-Boulianne | b482dbd | 2013-11-19 11:37:11 +0100 | [diff] [blame] | 758 | focus_surface_created = true; |
| 759 | } else { |
| 760 | wl_list_remove(&ws->fsurf_front->view->layer_link); |
| 761 | wl_list_remove(&ws->fsurf_back->view->layer_link); |
| 762 | } |
| 763 | |
| 764 | if (ws->focus_animation) { |
| 765 | weston_view_animation_destroy(ws->focus_animation); |
| 766 | ws->focus_animation = NULL; |
| 767 | } |
| 768 | |
| 769 | if (to) |
| 770 | wl_list_insert(&to->layer_link, |
| 771 | &ws->fsurf_front->view->layer_link); |
| 772 | else if (from) |
| 773 | wl_list_insert(&ws->layer.view_list, |
| 774 | &ws->fsurf_front->view->layer_link); |
| 775 | |
| 776 | if (focus_surface_created) { |
| 777 | ws->focus_animation = weston_fade_run( |
| 778 | ws->fsurf_front->view, |
| 779 | ws->fsurf_front->view->alpha, 0.6, 300, |
| 780 | focus_animation_done, ws); |
| 781 | } else if (from) { |
| 782 | wl_list_insert(&from->layer_link, |
| 783 | &ws->fsurf_back->view->layer_link); |
| 784 | ws->focus_animation = weston_stable_fade_run( |
| 785 | ws->fsurf_front->view, 0.0, |
| 786 | ws->fsurf_back->view, 0.6, |
| 787 | focus_animation_done, ws); |
| 788 | } else if (to) { |
| 789 | wl_list_insert(&ws->layer.view_list, |
| 790 | &ws->fsurf_back->view->layer_link); |
| 791 | ws->focus_animation = weston_stable_fade_run( |
| 792 | ws->fsurf_front->view, 0.0, |
| 793 | ws->fsurf_back->view, 0.6, |
| 794 | focus_animation_done, ws); |
| 795 | } |
| 796 | } |
| 797 | |
| 798 | static void |
Jonas Ådahl | e3cddce | 2012-06-13 00:01:22 +0200 | [diff] [blame] | 799 | workspace_destroy(struct workspace *ws) |
| 800 | { |
Jonas Ådahl | 0476974 | 2012-06-13 00:01:24 +0200 | [diff] [blame] | 801 | struct focus_state *state, *next; |
| 802 | |
| 803 | wl_list_for_each_safe(state, next, &ws->focus_list, link) |
| 804 | focus_state_destroy(state); |
| 805 | |
Louis-Francis Ratté-Boulianne | b482dbd | 2013-11-19 11:37:11 +0100 | [diff] [blame] | 806 | if (ws->fsurf_front) |
| 807 | focus_surface_destroy(ws->fsurf_front); |
| 808 | if (ws->fsurf_back) |
| 809 | focus_surface_destroy(ws->fsurf_back); |
| 810 | |
Jonas Ådahl | e3cddce | 2012-06-13 00:01:22 +0200 | [diff] [blame] | 811 | free(ws); |
| 812 | } |
| 813 | |
Jonas Ådahl | 0476974 | 2012-06-13 00:01:24 +0200 | [diff] [blame] | 814 | static void |
| 815 | seat_destroyed(struct wl_listener *listener, void *data) |
| 816 | { |
| 817 | struct weston_seat *seat = data; |
| 818 | struct focus_state *state, *next; |
| 819 | struct workspace *ws = container_of(listener, |
| 820 | struct workspace, |
| 821 | seat_destroyed_listener); |
| 822 | |
| 823 | wl_list_for_each_safe(state, next, &ws->focus_list, link) |
| 824 | if (state->seat == seat) |
| 825 | wl_list_remove(&state->link); |
| 826 | } |
| 827 | |
Jonas Ådahl | e3cddce | 2012-06-13 00:01:22 +0200 | [diff] [blame] | 828 | static struct workspace * |
| 829 | workspace_create(void) |
| 830 | { |
| 831 | struct workspace *ws = malloc(sizeof *ws); |
| 832 | if (ws == NULL) |
| 833 | return NULL; |
| 834 | |
| 835 | weston_layer_init(&ws->layer, NULL); |
| 836 | |
Jonas Ådahl | 0476974 | 2012-06-13 00:01:24 +0200 | [diff] [blame] | 837 | wl_list_init(&ws->focus_list); |
| 838 | wl_list_init(&ws->seat_destroyed_listener.link); |
| 839 | ws->seat_destroyed_listener.notify = seat_destroyed; |
Louis-Francis Ratté-Boulianne | b482dbd | 2013-11-19 11:37:11 +0100 | [diff] [blame] | 840 | ws->fsurf_front = NULL; |
| 841 | ws->fsurf_back = NULL; |
| 842 | ws->focus_animation = NULL; |
Jonas Ådahl | 0476974 | 2012-06-13 00:01:24 +0200 | [diff] [blame] | 843 | |
Jonas Ådahl | e3cddce | 2012-06-13 00:01:22 +0200 | [diff] [blame] | 844 | return ws; |
| 845 | } |
| 846 | |
Jonas Ådahl | 62fcd04 | 2012-06-13 00:01:23 +0200 | [diff] [blame] | 847 | static int |
| 848 | workspace_is_empty(struct workspace *ws) |
| 849 | { |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 850 | return wl_list_empty(&ws->layer.view_list); |
Jonas Ådahl | 62fcd04 | 2012-06-13 00:01:23 +0200 | [diff] [blame] | 851 | } |
| 852 | |
Jonas Ådahl | e3cddce | 2012-06-13 00:01:22 +0200 | [diff] [blame] | 853 | static struct workspace * |
| 854 | get_workspace(struct desktop_shell *shell, unsigned int index) |
| 855 | { |
| 856 | struct workspace **pws = shell->workspaces.array.data; |
Philipp Brüschweiler | 067abf6 | 2012-09-01 16:03:05 +0200 | [diff] [blame] | 857 | assert(index < shell->workspaces.num); |
Jonas Ådahl | e3cddce | 2012-06-13 00:01:22 +0200 | [diff] [blame] | 858 | pws += index; |
| 859 | return *pws; |
| 860 | } |
| 861 | |
Kristian Høgsberg | 1ef2313 | 2013-12-04 00:20:01 -0800 | [diff] [blame] | 862 | struct workspace * |
Jonas Ådahl | e3cddce | 2012-06-13 00:01:22 +0200 | [diff] [blame] | 863 | get_current_workspace(struct desktop_shell *shell) |
| 864 | { |
| 865 | return get_workspace(shell, shell->workspaces.current); |
| 866 | } |
| 867 | |
| 868 | static void |
| 869 | activate_workspace(struct desktop_shell *shell, unsigned int index) |
| 870 | { |
| 871 | struct workspace *ws; |
| 872 | |
| 873 | ws = get_workspace(shell, index); |
| 874 | wl_list_insert(&shell->panel_layer.link, &ws->layer.link); |
| 875 | |
| 876 | shell->workspaces.current = index; |
| 877 | } |
| 878 | |
Jonas Ådahl | 62fcd04 | 2012-06-13 00:01:23 +0200 | [diff] [blame] | 879 | static unsigned int |
| 880 | get_output_height(struct weston_output *output) |
| 881 | { |
| 882 | return abs(output->region.extents.y1 - output->region.extents.y2); |
| 883 | } |
| 884 | |
| 885 | static void |
Louis-Francis Ratté-Boulianne | b482dbd | 2013-11-19 11:37:11 +0100 | [diff] [blame] | 886 | view_translate(struct workspace *ws, struct weston_view *view, double d) |
Jonas Ådahl | 62fcd04 | 2012-06-13 00:01:23 +0200 | [diff] [blame] | 887 | { |
Jonas Ådahl | 62fcd04 | 2012-06-13 00:01:23 +0200 | [diff] [blame] | 888 | struct weston_transform *transform; |
| 889 | |
Louis-Francis Ratté-Boulianne | b482dbd | 2013-11-19 11:37:11 +0100 | [diff] [blame] | 890 | if (is_focus_view(view)) { |
| 891 | struct focus_surface *fsurf = get_focus_surface(view->surface); |
| 892 | transform = &fsurf->workspace_transform; |
| 893 | } else { |
| 894 | struct shell_surface *shsurf = get_shell_surface(view->surface); |
| 895 | transform = &shsurf->workspace_transform; |
| 896 | } |
| 897 | |
Jonas Ådahl | 62fcd04 | 2012-06-13 00:01:23 +0200 | [diff] [blame] | 898 | if (wl_list_empty(&transform->link)) |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 899 | wl_list_insert(view->geometry.transformation_list.prev, |
Louis-Francis Ratté-Boulianne | b482dbd | 2013-11-19 11:37:11 +0100 | [diff] [blame] | 900 | &transform->link); |
Jonas Ådahl | 62fcd04 | 2012-06-13 00:01:23 +0200 | [diff] [blame] | 901 | |
Louis-Francis Ratté-Boulianne | b482dbd | 2013-11-19 11:37:11 +0100 | [diff] [blame] | 902 | weston_matrix_init(&transform->matrix); |
| 903 | weston_matrix_translate(&transform->matrix, |
Jonas Ådahl | 62fcd04 | 2012-06-13 00:01:23 +0200 | [diff] [blame] | 904 | 0.0, d, 0.0); |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 905 | weston_view_geometry_dirty(view); |
Jonas Ådahl | 62fcd04 | 2012-06-13 00:01:23 +0200 | [diff] [blame] | 906 | } |
| 907 | |
| 908 | static void |
| 909 | workspace_translate_out(struct workspace *ws, double fraction) |
| 910 | { |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 911 | struct weston_view *view; |
Jonas Ådahl | 62fcd04 | 2012-06-13 00:01:23 +0200 | [diff] [blame] | 912 | unsigned int height; |
| 913 | double d; |
| 914 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 915 | wl_list_for_each(view, &ws->layer.view_list, layer_link) { |
| 916 | height = get_output_height(view->surface->output); |
Jonas Ådahl | 62fcd04 | 2012-06-13 00:01:23 +0200 | [diff] [blame] | 917 | d = height * fraction; |
| 918 | |
Louis-Francis Ratté-Boulianne | b482dbd | 2013-11-19 11:37:11 +0100 | [diff] [blame] | 919 | view_translate(ws, view, d); |
Jonas Ådahl | 62fcd04 | 2012-06-13 00:01:23 +0200 | [diff] [blame] | 920 | } |
| 921 | } |
| 922 | |
| 923 | static void |
| 924 | workspace_translate_in(struct workspace *ws, double fraction) |
| 925 | { |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 926 | struct weston_view *view; |
Jonas Ådahl | 62fcd04 | 2012-06-13 00:01:23 +0200 | [diff] [blame] | 927 | unsigned int height; |
| 928 | double d; |
| 929 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 930 | wl_list_for_each(view, &ws->layer.view_list, layer_link) { |
| 931 | height = get_output_height(view->surface->output); |
Jonas Ådahl | 62fcd04 | 2012-06-13 00:01:23 +0200 | [diff] [blame] | 932 | |
| 933 | if (fraction > 0) |
| 934 | d = -(height - height * fraction); |
| 935 | else |
| 936 | d = height + height * fraction; |
| 937 | |
Louis-Francis Ratté-Boulianne | b482dbd | 2013-11-19 11:37:11 +0100 | [diff] [blame] | 938 | view_translate(ws, view, d); |
Jonas Ådahl | 62fcd04 | 2012-06-13 00:01:23 +0200 | [diff] [blame] | 939 | } |
| 940 | } |
| 941 | |
| 942 | static void |
Jonas Ådahl | e9d2250 | 2012-08-29 22:13:01 +0200 | [diff] [blame] | 943 | broadcast_current_workspace_state(struct desktop_shell *shell) |
| 944 | { |
Kristian Høgsberg | 2e3c396 | 2013-09-11 12:00:47 -0700 | [diff] [blame] | 945 | struct wl_resource *resource; |
Jonas Ådahl | e9d2250 | 2012-08-29 22:13:01 +0200 | [diff] [blame] | 946 | |
Kristian Høgsberg | 2e3c396 | 2013-09-11 12:00:47 -0700 | [diff] [blame] | 947 | wl_resource_for_each(resource, &shell->workspaces.client_list) |
| 948 | workspace_manager_send_state(resource, |
Jonas Ådahl | e9d2250 | 2012-08-29 22:13:01 +0200 | [diff] [blame] | 949 | shell->workspaces.current, |
| 950 | shell->workspaces.num); |
| 951 | } |
| 952 | |
| 953 | static void |
Jonas Ådahl | 62fcd04 | 2012-06-13 00:01:23 +0200 | [diff] [blame] | 954 | reverse_workspace_change_animation(struct desktop_shell *shell, |
| 955 | unsigned int index, |
| 956 | struct workspace *from, |
| 957 | struct workspace *to) |
| 958 | { |
| 959 | shell->workspaces.current = index; |
| 960 | |
| 961 | shell->workspaces.anim_to = to; |
| 962 | shell->workspaces.anim_from = from; |
| 963 | shell->workspaces.anim_dir = -1 * shell->workspaces.anim_dir; |
| 964 | shell->workspaces.anim_timestamp = 0; |
| 965 | |
Scott Moreau | 4272e63 | 2012-08-13 09:58:41 -0600 | [diff] [blame] | 966 | weston_compositor_schedule_repaint(shell->compositor); |
Jonas Ådahl | 62fcd04 | 2012-06-13 00:01:23 +0200 | [diff] [blame] | 967 | } |
| 968 | |
| 969 | static void |
| 970 | workspace_deactivate_transforms(struct workspace *ws) |
| 971 | { |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 972 | struct weston_view *view; |
Louis-Francis Ratté-Boulianne | b482dbd | 2013-11-19 11:37:11 +0100 | [diff] [blame] | 973 | struct weston_transform *transform; |
Jonas Ådahl | 62fcd04 | 2012-06-13 00:01:23 +0200 | [diff] [blame] | 974 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 975 | 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] | 976 | if (is_focus_view(view)) { |
| 977 | struct focus_surface *fsurf = get_focus_surface(view->surface); |
| 978 | transform = &fsurf->workspace_transform; |
| 979 | } else { |
| 980 | struct shell_surface *shsurf = get_shell_surface(view->surface); |
| 981 | transform = &shsurf->workspace_transform; |
| 982 | } |
| 983 | |
| 984 | if (!wl_list_empty(&transform->link)) { |
| 985 | wl_list_remove(&transform->link); |
| 986 | wl_list_init(&transform->link); |
Jonas Ådahl | 8de6a1d | 2012-08-29 22:13:00 +0200 | [diff] [blame] | 987 | } |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 988 | weston_view_geometry_dirty(view); |
Jonas Ådahl | 62fcd04 | 2012-06-13 00:01:23 +0200 | [diff] [blame] | 989 | } |
| 990 | } |
| 991 | |
| 992 | static void |
| 993 | finish_workspace_change_animation(struct desktop_shell *shell, |
| 994 | struct workspace *from, |
| 995 | struct workspace *to) |
| 996 | { |
Scott Moreau | 4272e63 | 2012-08-13 09:58:41 -0600 | [diff] [blame] | 997 | weston_compositor_schedule_repaint(shell->compositor); |
Jonas Ådahl | 62fcd04 | 2012-06-13 00:01:23 +0200 | [diff] [blame] | 998 | |
| 999 | wl_list_remove(&shell->workspaces.animation.link); |
| 1000 | workspace_deactivate_transforms(from); |
| 1001 | workspace_deactivate_transforms(to); |
| 1002 | shell->workspaces.anim_to = NULL; |
| 1003 | |
| 1004 | wl_list_remove(&shell->workspaces.anim_from->layer.link); |
| 1005 | } |
| 1006 | |
| 1007 | static void |
| 1008 | animate_workspace_change_frame(struct weston_animation *animation, |
| 1009 | struct weston_output *output, uint32_t msecs) |
| 1010 | { |
| 1011 | struct desktop_shell *shell = |
| 1012 | container_of(animation, struct desktop_shell, |
| 1013 | workspaces.animation); |
| 1014 | struct workspace *from = shell->workspaces.anim_from; |
| 1015 | struct workspace *to = shell->workspaces.anim_to; |
| 1016 | uint32_t t; |
| 1017 | double x, y; |
| 1018 | |
| 1019 | if (workspace_is_empty(from) && workspace_is_empty(to)) { |
| 1020 | finish_workspace_change_animation(shell, from, to); |
| 1021 | return; |
| 1022 | } |
| 1023 | |
| 1024 | if (shell->workspaces.anim_timestamp == 0) { |
| 1025 | if (shell->workspaces.anim_current == 0.0) |
| 1026 | shell->workspaces.anim_timestamp = msecs; |
| 1027 | else |
| 1028 | shell->workspaces.anim_timestamp = |
| 1029 | msecs - |
| 1030 | /* Invers of movement function 'y' below. */ |
| 1031 | (asin(1.0 - shell->workspaces.anim_current) * |
| 1032 | DEFAULT_WORKSPACE_CHANGE_ANIMATION_LENGTH * |
| 1033 | M_2_PI); |
| 1034 | } |
| 1035 | |
| 1036 | t = msecs - shell->workspaces.anim_timestamp; |
| 1037 | |
| 1038 | /* |
| 1039 | * x = [0, π/2] |
| 1040 | * y(x) = sin(x) |
| 1041 | */ |
| 1042 | x = t * (1.0/DEFAULT_WORKSPACE_CHANGE_ANIMATION_LENGTH) * M_PI_2; |
| 1043 | y = sin(x); |
| 1044 | |
| 1045 | if (t < DEFAULT_WORKSPACE_CHANGE_ANIMATION_LENGTH) { |
Scott Moreau | 4272e63 | 2012-08-13 09:58:41 -0600 | [diff] [blame] | 1046 | weston_compositor_schedule_repaint(shell->compositor); |
Jonas Ådahl | 62fcd04 | 2012-06-13 00:01:23 +0200 | [diff] [blame] | 1047 | |
| 1048 | workspace_translate_out(from, shell->workspaces.anim_dir * y); |
| 1049 | workspace_translate_in(to, shell->workspaces.anim_dir * y); |
| 1050 | shell->workspaces.anim_current = y; |
| 1051 | |
Scott Moreau | 4272e63 | 2012-08-13 09:58:41 -0600 | [diff] [blame] | 1052 | weston_compositor_schedule_repaint(shell->compositor); |
Jonas Ådahl | 62fcd04 | 2012-06-13 00:01:23 +0200 | [diff] [blame] | 1053 | } |
Jonas Ådahl | 0476974 | 2012-06-13 00:01:24 +0200 | [diff] [blame] | 1054 | else |
Jonas Ådahl | 62fcd04 | 2012-06-13 00:01:23 +0200 | [diff] [blame] | 1055 | finish_workspace_change_animation(shell, from, to); |
Jonas Ådahl | 62fcd04 | 2012-06-13 00:01:23 +0200 | [diff] [blame] | 1056 | } |
| 1057 | |
| 1058 | static void |
| 1059 | animate_workspace_change(struct desktop_shell *shell, |
| 1060 | unsigned int index, |
| 1061 | struct workspace *from, |
| 1062 | struct workspace *to) |
| 1063 | { |
| 1064 | struct weston_output *output; |
| 1065 | |
| 1066 | int dir; |
| 1067 | |
| 1068 | if (index > shell->workspaces.current) |
| 1069 | dir = -1; |
| 1070 | else |
| 1071 | dir = 1; |
| 1072 | |
| 1073 | shell->workspaces.current = index; |
| 1074 | |
| 1075 | shell->workspaces.anim_dir = dir; |
| 1076 | shell->workspaces.anim_from = from; |
| 1077 | shell->workspaces.anim_to = to; |
| 1078 | shell->workspaces.anim_current = 0.0; |
| 1079 | shell->workspaces.anim_timestamp = 0; |
| 1080 | |
| 1081 | output = container_of(shell->compositor->output_list.next, |
| 1082 | struct weston_output, link); |
| 1083 | wl_list_insert(&output->animation_list, |
| 1084 | &shell->workspaces.animation.link); |
| 1085 | |
Jonas Ådahl | 8de6a1d | 2012-08-29 22:13:00 +0200 | [diff] [blame] | 1086 | wl_list_insert(from->layer.link.prev, &to->layer.link); |
Jonas Ådahl | 62fcd04 | 2012-06-13 00:01:23 +0200 | [diff] [blame] | 1087 | |
| 1088 | workspace_translate_in(to, 0); |
| 1089 | |
Kristian Høgsberg | 2f5faff | 2012-07-31 16:36:34 -0400 | [diff] [blame] | 1090 | restore_focus_state(shell, to); |
Jonas Ådahl | 0476974 | 2012-06-13 00:01:24 +0200 | [diff] [blame] | 1091 | |
Scott Moreau | 4272e63 | 2012-08-13 09:58:41 -0600 | [diff] [blame] | 1092 | weston_compositor_schedule_repaint(shell->compositor); |
Jonas Ådahl | 62fcd04 | 2012-06-13 00:01:23 +0200 | [diff] [blame] | 1093 | } |
| 1094 | |
Jonas Ådahl | e3cddce | 2012-06-13 00:01:22 +0200 | [diff] [blame] | 1095 | static void |
Jonas Ådahl | 8de6a1d | 2012-08-29 22:13:00 +0200 | [diff] [blame] | 1096 | update_workspace(struct desktop_shell *shell, unsigned int index, |
| 1097 | struct workspace *from, struct workspace *to) |
| 1098 | { |
| 1099 | shell->workspaces.current = index; |
| 1100 | wl_list_insert(&from->layer.link, &to->layer.link); |
| 1101 | wl_list_remove(&from->layer.link); |
| 1102 | } |
| 1103 | |
| 1104 | static void |
Jonas Ådahl | e3cddce | 2012-06-13 00:01:22 +0200 | [diff] [blame] | 1105 | change_workspace(struct desktop_shell *shell, unsigned int index) |
| 1106 | { |
| 1107 | struct workspace *from; |
| 1108 | struct workspace *to; |
Louis-Francis Ratté-Boulianne | b482dbd | 2013-11-19 11:37:11 +0100 | [diff] [blame] | 1109 | struct focus_state *state; |
Jonas Ådahl | e3cddce | 2012-06-13 00:01:22 +0200 | [diff] [blame] | 1110 | |
| 1111 | if (index == shell->workspaces.current) |
| 1112 | return; |
| 1113 | |
| 1114 | /* Don't change workspace when there is any fullscreen surfaces. */ |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 1115 | if (!wl_list_empty(&shell->fullscreen_layer.view_list)) |
Jonas Ådahl | e3cddce | 2012-06-13 00:01:22 +0200 | [diff] [blame] | 1116 | return; |
| 1117 | |
Jonas Ådahl | e3cddce | 2012-06-13 00:01:22 +0200 | [diff] [blame] | 1118 | from = get_current_workspace(shell); |
| 1119 | to = get_workspace(shell, index); |
| 1120 | |
Jonas Ådahl | 62fcd04 | 2012-06-13 00:01:23 +0200 | [diff] [blame] | 1121 | if (shell->workspaces.anim_from == to && |
| 1122 | shell->workspaces.anim_to == from) { |
Jonas Ådahl | 8de6a1d | 2012-08-29 22:13:00 +0200 | [diff] [blame] | 1123 | restore_focus_state(shell, to); |
Jonas Ådahl | 62fcd04 | 2012-06-13 00:01:23 +0200 | [diff] [blame] | 1124 | reverse_workspace_change_animation(shell, index, from, to); |
Jonas Ådahl | e9d2250 | 2012-08-29 22:13:01 +0200 | [diff] [blame] | 1125 | broadcast_current_workspace_state(shell); |
Jonas Ådahl | 62fcd04 | 2012-06-13 00:01:23 +0200 | [diff] [blame] | 1126 | return; |
| 1127 | } |
Jonas Ådahl | e3cddce | 2012-06-13 00:01:22 +0200 | [diff] [blame] | 1128 | |
Jonas Ådahl | 62fcd04 | 2012-06-13 00:01:23 +0200 | [diff] [blame] | 1129 | if (shell->workspaces.anim_to != NULL) |
| 1130 | finish_workspace_change_animation(shell, |
| 1131 | shell->workspaces.anim_from, |
| 1132 | shell->workspaces.anim_to); |
| 1133 | |
Jonas Ådahl | 8de6a1d | 2012-08-29 22:13:00 +0200 | [diff] [blame] | 1134 | restore_focus_state(shell, to); |
Jonas Ådahl | 0476974 | 2012-06-13 00:01:24 +0200 | [diff] [blame] | 1135 | |
Louis-Francis Ratté-Boulianne | b482dbd | 2013-11-19 11:37:11 +0100 | [diff] [blame] | 1136 | if (shell->focus_animation_type != ANIMATION_NONE) { |
| 1137 | wl_list_for_each(state, &from->focus_list, link) |
| 1138 | if (state->keyboard_focus) |
| 1139 | animate_focus_change(shell, from, |
| 1140 | get_default_view(state->keyboard_focus), NULL); |
| 1141 | |
| 1142 | wl_list_for_each(state, &to->focus_list, link) |
| 1143 | if (state->keyboard_focus) |
| 1144 | animate_focus_change(shell, to, |
| 1145 | NULL, get_default_view(state->keyboard_focus)); |
| 1146 | } |
| 1147 | |
Jonas Ådahl | 8de6a1d | 2012-08-29 22:13:00 +0200 | [diff] [blame] | 1148 | if (workspace_is_empty(to) && workspace_is_empty(from)) |
| 1149 | update_workspace(shell, index, from, to); |
Jonas Ådahl | 62fcd04 | 2012-06-13 00:01:23 +0200 | [diff] [blame] | 1150 | else |
| 1151 | animate_workspace_change(shell, index, from, to); |
Jonas Ådahl | e9d2250 | 2012-08-29 22:13:01 +0200 | [diff] [blame] | 1152 | |
| 1153 | broadcast_current_workspace_state(shell); |
Pekka Paalanen | e955f1e | 2011-12-07 11:49:52 +0200 | [diff] [blame] | 1154 | } |
| 1155 | |
Jonas Ådahl | 8de6a1d | 2012-08-29 22:13:00 +0200 | [diff] [blame] | 1156 | static bool |
| 1157 | workspace_has_only(struct workspace *ws, struct weston_surface *surface) |
| 1158 | { |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 1159 | struct wl_list *list = &ws->layer.view_list; |
Jonas Ådahl | 8de6a1d | 2012-08-29 22:13:00 +0200 | [diff] [blame] | 1160 | struct wl_list *e; |
| 1161 | |
| 1162 | if (wl_list_empty(list)) |
| 1163 | return false; |
| 1164 | |
| 1165 | e = list->next; |
| 1166 | |
| 1167 | if (e->next != list) |
| 1168 | return false; |
| 1169 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 1170 | return container_of(e, struct weston_view, layer_link)->surface == surface; |
Jonas Ådahl | 8de6a1d | 2012-08-29 22:13:00 +0200 | [diff] [blame] | 1171 | } |
| 1172 | |
| 1173 | static void |
Philip Withnall | 659163d | 2013-11-25 18:01:36 +0000 | [diff] [blame] | 1174 | move_surface_to_workspace(struct desktop_shell *shell, |
| 1175 | struct shell_surface *shsurf, |
| 1176 | uint32_t workspace) |
Jonas Ådahl | e9d2250 | 2012-08-29 22:13:01 +0200 | [diff] [blame] | 1177 | { |
| 1178 | struct workspace *from; |
| 1179 | struct workspace *to; |
| 1180 | struct weston_seat *seat; |
Pekka Paalanen | 01388e2 | 2013-04-25 13:57:44 +0300 | [diff] [blame] | 1181 | struct weston_surface *focus; |
Philip Withnall | 659163d | 2013-11-25 18:01:36 +0000 | [diff] [blame] | 1182 | struct weston_view *view; |
Jonas Ådahl | e9d2250 | 2012-08-29 22:13:01 +0200 | [diff] [blame] | 1183 | |
| 1184 | if (workspace == shell->workspaces.current) |
| 1185 | return; |
| 1186 | |
Philip Withnall | 659163d | 2013-11-25 18:01:36 +0000 | [diff] [blame] | 1187 | view = get_default_view(shsurf->surface); |
| 1188 | if (!view) |
| 1189 | return; |
| 1190 | |
| 1191 | assert(weston_surface_get_main_surface(view->surface) == view->surface); |
| 1192 | |
Philipp Brüschweiler | 067abf6 | 2012-09-01 16:03:05 +0200 | [diff] [blame] | 1193 | if (workspace >= shell->workspaces.num) |
| 1194 | workspace = shell->workspaces.num - 1; |
| 1195 | |
Jonas Ådahl | e9d2250 | 2012-08-29 22:13:01 +0200 | [diff] [blame] | 1196 | from = get_current_workspace(shell); |
| 1197 | to = get_workspace(shell, workspace); |
| 1198 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 1199 | wl_list_remove(&view->layer_link); |
| 1200 | wl_list_insert(&to->layer.view_list, &view->layer_link); |
Jonas Ådahl | e9d2250 | 2012-08-29 22:13:01 +0200 | [diff] [blame] | 1201 | |
Philip Withnall | 648a4dd | 2013-11-25 18:01:44 +0000 | [diff] [blame] | 1202 | shell_surface_update_child_surface_layers(shsurf); |
| 1203 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 1204 | drop_focus_state(shell, from, view->surface); |
Pekka Paalanen | 01388e2 | 2013-04-25 13:57:44 +0300 | [diff] [blame] | 1205 | wl_list_for_each(seat, &shell->compositor->seat_list, link) { |
| 1206 | if (!seat->keyboard) |
| 1207 | continue; |
| 1208 | |
| 1209 | focus = weston_surface_get_main_surface(seat->keyboard->focus); |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 1210 | if (focus == view->surface) |
Kristian Høgsberg | e314875 | 2013-05-06 23:19:49 -0400 | [diff] [blame] | 1211 | weston_keyboard_set_focus(seat->keyboard, NULL); |
Pekka Paalanen | 01388e2 | 2013-04-25 13:57:44 +0300 | [diff] [blame] | 1212 | } |
Jonas Ådahl | e9d2250 | 2012-08-29 22:13:01 +0200 | [diff] [blame] | 1213 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 1214 | weston_view_damage_below(view); |
Jonas Ådahl | e9d2250 | 2012-08-29 22:13:01 +0200 | [diff] [blame] | 1215 | } |
| 1216 | |
| 1217 | static void |
Jonas Ådahl | 8de6a1d | 2012-08-29 22:13:00 +0200 | [diff] [blame] | 1218 | take_surface_to_workspace_by_seat(struct desktop_shell *shell, |
Kristian Høgsberg | e314875 | 2013-05-06 23:19:49 -0400 | [diff] [blame] | 1219 | struct weston_seat *seat, |
Jonas Ådahl | 8de6a1d | 2012-08-29 22:13:00 +0200 | [diff] [blame] | 1220 | unsigned int index) |
| 1221 | { |
Pekka Paalanen | 01388e2 | 2013-04-25 13:57:44 +0300 | [diff] [blame] | 1222 | struct weston_surface *surface; |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 1223 | struct weston_view *view; |
Jonas Ådahl | 8de6a1d | 2012-08-29 22:13:00 +0200 | [diff] [blame] | 1224 | struct shell_surface *shsurf; |
| 1225 | struct workspace *from; |
| 1226 | struct workspace *to; |
Jonas Ådahl | 8538b22 | 2012-08-29 22:13:03 +0200 | [diff] [blame] | 1227 | struct focus_state *state; |
Jonas Ådahl | 8de6a1d | 2012-08-29 22:13:00 +0200 | [diff] [blame] | 1228 | |
Pekka Paalanen | 01388e2 | 2013-04-25 13:57:44 +0300 | [diff] [blame] | 1229 | surface = weston_surface_get_main_surface(seat->keyboard->focus); |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 1230 | view = get_default_view(surface); |
| 1231 | if (view == NULL || |
Louis-Francis Ratté-Boulianne | b482dbd | 2013-11-19 11:37:11 +0100 | [diff] [blame] | 1232 | index == shell->workspaces.current || |
| 1233 | is_focus_view(view)) |
Jonas Ådahl | 8de6a1d | 2012-08-29 22:13:00 +0200 | [diff] [blame] | 1234 | return; |
| 1235 | |
| 1236 | from = get_current_workspace(shell); |
| 1237 | to = get_workspace(shell, index); |
| 1238 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 1239 | wl_list_remove(&view->layer_link); |
| 1240 | wl_list_insert(&to->layer.view_list, &view->layer_link); |
Jonas Ådahl | 8de6a1d | 2012-08-29 22:13:00 +0200 | [diff] [blame] | 1241 | |
Philip Withnall | 659163d | 2013-11-25 18:01:36 +0000 | [diff] [blame] | 1242 | shsurf = get_shell_surface(surface); |
Philip Withnall | 648a4dd | 2013-11-25 18:01:44 +0000 | [diff] [blame] | 1243 | if (shsurf != NULL) |
| 1244 | shell_surface_update_child_surface_layers(shsurf); |
Philip Withnall | 659163d | 2013-11-25 18:01:36 +0000 | [diff] [blame] | 1245 | |
Jonas Ådahl | e9d2250 | 2012-08-29 22:13:01 +0200 | [diff] [blame] | 1246 | replace_focus_state(shell, to, seat); |
Jonas Ådahl | 8de6a1d | 2012-08-29 22:13:00 +0200 | [diff] [blame] | 1247 | drop_focus_state(shell, from, surface); |
| 1248 | |
| 1249 | if (shell->workspaces.anim_from == to && |
| 1250 | shell->workspaces.anim_to == from) { |
Jonas Ådahl | e9d2250 | 2012-08-29 22:13:01 +0200 | [diff] [blame] | 1251 | wl_list_remove(&to->layer.link); |
| 1252 | wl_list_insert(from->layer.link.prev, &to->layer.link); |
| 1253 | |
Jonas Ådahl | 8de6a1d | 2012-08-29 22:13:00 +0200 | [diff] [blame] | 1254 | reverse_workspace_change_animation(shell, index, from, to); |
Jonas Ådahl | e9d2250 | 2012-08-29 22:13:01 +0200 | [diff] [blame] | 1255 | broadcast_current_workspace_state(shell); |
| 1256 | |
Jonas Ådahl | 8de6a1d | 2012-08-29 22:13:00 +0200 | [diff] [blame] | 1257 | return; |
| 1258 | } |
| 1259 | |
| 1260 | if (shell->workspaces.anim_to != NULL) |
| 1261 | finish_workspace_change_animation(shell, |
| 1262 | shell->workspaces.anim_from, |
| 1263 | shell->workspaces.anim_to); |
| 1264 | |
| 1265 | if (workspace_is_empty(from) && |
| 1266 | workspace_has_only(to, surface)) |
| 1267 | update_workspace(shell, index, from, to); |
| 1268 | else { |
Philip Withnall | 2c3849b | 2013-11-25 18:01:45 +0000 | [diff] [blame] | 1269 | if (shsurf != NULL && |
| 1270 | wl_list_empty(&shsurf->workspace_transform.link)) |
Jonas Ådahl | 8de6a1d | 2012-08-29 22:13:00 +0200 | [diff] [blame] | 1271 | wl_list_insert(&shell->workspaces.anim_sticky_list, |
| 1272 | &shsurf->workspace_transform.link); |
| 1273 | |
| 1274 | animate_workspace_change(shell, index, from, to); |
| 1275 | } |
Jonas Ådahl | e9d2250 | 2012-08-29 22:13:01 +0200 | [diff] [blame] | 1276 | |
| 1277 | broadcast_current_workspace_state(shell); |
Jonas Ådahl | 8538b22 | 2012-08-29 22:13:03 +0200 | [diff] [blame] | 1278 | |
| 1279 | state = ensure_focus_state(shell, seat); |
| 1280 | if (state != NULL) |
Kristian Høgsberg | d500bf1 | 2014-01-22 12:25:20 -0800 | [diff] [blame] | 1281 | focus_state_set_focus(state, surface); |
Jonas Ådahl | e9d2250 | 2012-08-29 22:13:01 +0200 | [diff] [blame] | 1282 | } |
| 1283 | |
| 1284 | static void |
| 1285 | workspace_manager_move_surface(struct wl_client *client, |
| 1286 | struct wl_resource *resource, |
| 1287 | struct wl_resource *surface_resource, |
| 1288 | uint32_t workspace) |
| 1289 | { |
Jason Ekstrand | 651f00e | 2013-06-14 10:07:54 -0500 | [diff] [blame] | 1290 | struct desktop_shell *shell = wl_resource_get_user_data(resource); |
Jonas Ådahl | e9d2250 | 2012-08-29 22:13:01 +0200 | [diff] [blame] | 1291 | struct weston_surface *surface = |
Jason Ekstrand | 0f2ef7e | 2013-06-14 10:07:53 -0500 | [diff] [blame] | 1292 | wl_resource_get_user_data(surface_resource); |
Pekka Paalanen | 01388e2 | 2013-04-25 13:57:44 +0300 | [diff] [blame] | 1293 | struct weston_surface *main_surface; |
Philip Withnall | 659163d | 2013-11-25 18:01:36 +0000 | [diff] [blame] | 1294 | struct shell_surface *shell_surface; |
Jonas Ådahl | e9d2250 | 2012-08-29 22:13:01 +0200 | [diff] [blame] | 1295 | |
Pekka Paalanen | 01388e2 | 2013-04-25 13:57:44 +0300 | [diff] [blame] | 1296 | main_surface = weston_surface_get_main_surface(surface); |
Philip Withnall | 659163d | 2013-11-25 18:01:36 +0000 | [diff] [blame] | 1297 | shell_surface = get_shell_surface(main_surface); |
| 1298 | if (shell_surface == NULL) |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 1299 | return; |
Philip Withnall | 659163d | 2013-11-25 18:01:36 +0000 | [diff] [blame] | 1300 | |
| 1301 | move_surface_to_workspace(shell, shell_surface, workspace); |
Jonas Ådahl | e9d2250 | 2012-08-29 22:13:01 +0200 | [diff] [blame] | 1302 | } |
| 1303 | |
| 1304 | static const struct workspace_manager_interface workspace_manager_implementation = { |
| 1305 | workspace_manager_move_surface, |
| 1306 | }; |
| 1307 | |
| 1308 | static void |
| 1309 | unbind_resource(struct wl_resource *resource) |
| 1310 | { |
Jason Ekstrand | 651f00e | 2013-06-14 10:07:54 -0500 | [diff] [blame] | 1311 | wl_list_remove(wl_resource_get_link(resource)); |
Jonas Ådahl | e9d2250 | 2012-08-29 22:13:01 +0200 | [diff] [blame] | 1312 | } |
| 1313 | |
| 1314 | static void |
| 1315 | bind_workspace_manager(struct wl_client *client, |
| 1316 | void *data, uint32_t version, uint32_t id) |
| 1317 | { |
| 1318 | struct desktop_shell *shell = data; |
| 1319 | struct wl_resource *resource; |
| 1320 | |
Jason Ekstrand | a85118c | 2013-06-27 20:17:02 -0500 | [diff] [blame] | 1321 | resource = wl_resource_create(client, |
| 1322 | &workspace_manager_interface, 1, id); |
Jonas Ådahl | e9d2250 | 2012-08-29 22:13:01 +0200 | [diff] [blame] | 1323 | |
| 1324 | if (resource == NULL) { |
| 1325 | weston_log("couldn't add workspace manager object"); |
| 1326 | return; |
| 1327 | } |
| 1328 | |
Jason Ekstrand | a85118c | 2013-06-27 20:17:02 -0500 | [diff] [blame] | 1329 | wl_resource_set_implementation(resource, |
| 1330 | &workspace_manager_implementation, |
| 1331 | shell, unbind_resource); |
Jason Ekstrand | 651f00e | 2013-06-14 10:07:54 -0500 | [diff] [blame] | 1332 | wl_list_insert(&shell->workspaces.client_list, |
| 1333 | wl_resource_get_link(resource)); |
Jonas Ådahl | e9d2250 | 2012-08-29 22:13:01 +0200 | [diff] [blame] | 1334 | |
| 1335 | workspace_manager_send_state(resource, |
| 1336 | shell->workspaces.current, |
| 1337 | shell->workspaces.num); |
Jonas Ådahl | 8de6a1d | 2012-08-29 22:13:00 +0200 | [diff] [blame] | 1338 | } |
| 1339 | |
Pekka Paalanen | 56cdea9 | 2011-11-23 16:14:12 +0200 | [diff] [blame] | 1340 | static void |
Rusty Lynch | 1084da5 | 2013-08-15 09:10:08 -0700 | [diff] [blame] | 1341 | touch_move_grab_down(struct weston_touch_grab *grab, uint32_t time, |
| 1342 | int touch_id, wl_fixed_t sx, wl_fixed_t sy) |
| 1343 | { |
| 1344 | } |
| 1345 | |
| 1346 | static void |
| 1347 | touch_move_grab_up(struct weston_touch_grab *grab, uint32_t time, int touch_id) |
| 1348 | { |
Jonas Ådahl | 1c6e63e | 2013-10-25 23:18:04 +0200 | [diff] [blame] | 1349 | struct weston_touch_move_grab *move = |
| 1350 | (struct weston_touch_move_grab *) container_of( |
| 1351 | grab, struct shell_touch_grab, grab); |
Neil Roberts | e14aa4f | 2013-10-03 16:43:07 +0100 | [diff] [blame] | 1352 | |
Kristian Høgsberg | 8e80a31 | 2014-01-17 15:18:10 -0800 | [diff] [blame] | 1353 | if (touch_id == 0) |
| 1354 | move->active = 0; |
| 1355 | |
Jonas Ådahl | 9484b69 | 2013-12-02 22:05:03 +0100 | [diff] [blame] | 1356 | if (grab->touch->num_tp == 0) { |
Jonas Ådahl | 1c6e63e | 2013-10-25 23:18:04 +0200 | [diff] [blame] | 1357 | shell_touch_grab_end(&move->base); |
| 1358 | free(move); |
| 1359 | } |
Rusty Lynch | 1084da5 | 2013-08-15 09:10:08 -0700 | [diff] [blame] | 1360 | } |
| 1361 | |
| 1362 | static void |
| 1363 | touch_move_grab_motion(struct weston_touch_grab *grab, uint32_t time, |
| 1364 | int touch_id, wl_fixed_t sx, wl_fixed_t sy) |
| 1365 | { |
| 1366 | struct weston_touch_move_grab *move = (struct weston_touch_move_grab *) grab; |
| 1367 | struct shell_surface *shsurf = move->base.shsurf; |
| 1368 | struct weston_surface *es; |
| 1369 | int dx = wl_fixed_to_int(grab->touch->grab_x + move->dx); |
| 1370 | int dy = wl_fixed_to_int(grab->touch->grab_y + move->dy); |
| 1371 | |
Kristian Høgsberg | 8e80a31 | 2014-01-17 15:18:10 -0800 | [diff] [blame] | 1372 | if (!shsurf || !move->active) |
Rusty Lynch | 1084da5 | 2013-08-15 09:10:08 -0700 | [diff] [blame] | 1373 | return; |
| 1374 | |
| 1375 | es = shsurf->surface; |
| 1376 | |
Jason Ekstrand | 918f2dd | 2013-12-02 21:01:53 -0600 | [diff] [blame] | 1377 | weston_view_set_position(shsurf->view, dx, dy); |
Rusty Lynch | 1084da5 | 2013-08-15 09:10:08 -0700 | [diff] [blame] | 1378 | |
| 1379 | weston_compositor_schedule_repaint(es->compositor); |
| 1380 | } |
| 1381 | |
Jonas Ådahl | 1ea343e | 2013-10-25 23:18:05 +0200 | [diff] [blame] | 1382 | static void |
| 1383 | touch_move_grab_cancel(struct weston_touch_grab *grab) |
| 1384 | { |
| 1385 | struct weston_touch_move_grab *move = |
| 1386 | (struct weston_touch_move_grab *) container_of( |
| 1387 | grab, struct shell_touch_grab, grab); |
| 1388 | |
| 1389 | shell_touch_grab_end(&move->base); |
| 1390 | free(move); |
| 1391 | } |
| 1392 | |
Rusty Lynch | 1084da5 | 2013-08-15 09:10:08 -0700 | [diff] [blame] | 1393 | static const struct weston_touch_grab_interface touch_move_grab_interface = { |
| 1394 | touch_move_grab_down, |
| 1395 | touch_move_grab_up, |
| 1396 | touch_move_grab_motion, |
Jonas Ådahl | 1ea343e | 2013-10-25 23:18:05 +0200 | [diff] [blame] | 1397 | touch_move_grab_cancel, |
Rusty Lynch | 1084da5 | 2013-08-15 09:10:08 -0700 | [diff] [blame] | 1398 | }; |
| 1399 | |
| 1400 | static int |
| 1401 | surface_touch_move(struct shell_surface *shsurf, struct weston_seat *seat) |
| 1402 | { |
| 1403 | struct weston_touch_move_grab *move; |
| 1404 | |
| 1405 | if (!shsurf) |
| 1406 | return -1; |
| 1407 | |
Rafael Antognolli | 03b1659 | 2013-12-03 15:35:42 -0200 | [diff] [blame] | 1408 | if (shsurf->state.fullscreen) |
Rusty Lynch | 1084da5 | 2013-08-15 09:10:08 -0700 | [diff] [blame] | 1409 | return 0; |
Kristian Høgsberg | c85f1d4 | 2013-10-24 16:52:00 -0700 | [diff] [blame] | 1410 | if (shsurf->grabbed) |
| 1411 | return 0; |
Rusty Lynch | 1084da5 | 2013-08-15 09:10:08 -0700 | [diff] [blame] | 1412 | |
| 1413 | move = malloc(sizeof *move); |
| 1414 | if (!move) |
| 1415 | return -1; |
| 1416 | |
Kristian Høgsberg | 8e80a31 | 2014-01-17 15:18:10 -0800 | [diff] [blame] | 1417 | move->active = 1; |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 1418 | move->dx = wl_fixed_from_double(shsurf->view->geometry.x) - |
Rusty Lynch | 1084da5 | 2013-08-15 09:10:08 -0700 | [diff] [blame] | 1419 | seat->touch->grab_x; |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 1420 | move->dy = wl_fixed_from_double(shsurf->view->geometry.y) - |
Rusty Lynch | 1084da5 | 2013-08-15 09:10:08 -0700 | [diff] [blame] | 1421 | seat->touch->grab_y; |
| 1422 | |
| 1423 | shell_touch_grab_start(&move->base, &touch_move_grab_interface, shsurf, |
| 1424 | seat->touch); |
| 1425 | |
| 1426 | return 0; |
| 1427 | } |
| 1428 | |
| 1429 | static void |
Kristian Høgsberg | 6848c25 | 2013-05-08 22:02:59 -0400 | [diff] [blame] | 1430 | noop_grab_focus(struct weston_pointer_grab *grab) |
Kristian Høgsberg | 9ddb826 | 2012-01-04 21:30:29 -0500 | [diff] [blame] | 1431 | { |
Kristian Høgsberg | 9ddb826 | 2012-01-04 21:30:29 -0500 | [diff] [blame] | 1432 | } |
| 1433 | |
| 1434 | static void |
Giulio Camuffo | 1959ab8 | 2013-11-14 23:42:52 +0100 | [diff] [blame] | 1435 | move_grab_motion(struct weston_pointer_grab *grab, uint32_t time, |
| 1436 | wl_fixed_t x, wl_fixed_t y) |
Kristian Høgsberg | 4cca349 | 2011-01-18 07:53:49 -0500 | [diff] [blame] | 1437 | { |
Kristian Høgsberg | 8334bc1 | 2012-01-03 10:29:47 -0500 | [diff] [blame] | 1438 | struct weston_move_grab *move = (struct weston_move_grab *) grab; |
Kristian Høgsberg | 02bbabb | 2013-05-06 22:15:05 -0400 | [diff] [blame] | 1439 | struct weston_pointer *pointer = grab->pointer; |
Ander Conselvan de Oliveira | fe0444a | 2012-04-04 17:48:05 +0300 | [diff] [blame] | 1440 | struct shell_surface *shsurf = move->base.shsurf; |
Giulio Camuffo | 1959ab8 | 2013-11-14 23:42:52 +0100 | [diff] [blame] | 1441 | int dx, dy; |
| 1442 | |
| 1443 | weston_pointer_move(pointer, x, y); |
| 1444 | dx = wl_fixed_to_int(pointer->x + move->dx); |
| 1445 | dy = wl_fixed_to_int(pointer->y + move->dy); |
Ander Conselvan de Oliveira | fe0444a | 2012-04-04 17:48:05 +0300 | [diff] [blame] | 1446 | |
| 1447 | if (!shsurf) |
| 1448 | return; |
| 1449 | |
Jason Ekstrand | 918f2dd | 2013-12-02 21:01:53 -0600 | [diff] [blame] | 1450 | weston_view_set_position(shsurf->view, dx, dy); |
Kristian Høgsberg | 4cca349 | 2011-01-18 07:53:49 -0500 | [diff] [blame] | 1451 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 1452 | weston_compositor_schedule_repaint(shsurf->surface->compositor); |
Kristian Høgsberg | 4cca349 | 2011-01-18 07:53:49 -0500 | [diff] [blame] | 1453 | } |
| 1454 | |
| 1455 | static void |
Kristian Høgsberg | 02bbabb | 2013-05-06 22:15:05 -0400 | [diff] [blame] | 1456 | move_grab_button(struct weston_pointer_grab *grab, |
Daniel Stone | 4dbadb1 | 2012-05-30 16:31:51 +0100 | [diff] [blame] | 1457 | uint32_t time, uint32_t button, uint32_t state_w) |
Kristian Høgsberg | 4cca349 | 2011-01-18 07:53:49 -0500 | [diff] [blame] | 1458 | { |
Ander Conselvan de Oliveira | fe0444a | 2012-04-04 17:48:05 +0300 | [diff] [blame] | 1459 | struct shell_grab *shell_grab = container_of(grab, struct shell_grab, |
| 1460 | grab); |
Kristian Høgsberg | 02bbabb | 2013-05-06 22:15:05 -0400 | [diff] [blame] | 1461 | struct weston_pointer *pointer = grab->pointer; |
Daniel Stone | 4dbadb1 | 2012-05-30 16:31:51 +0100 | [diff] [blame] | 1462 | enum wl_pointer_button_state state = state_w; |
Kristian Høgsberg | 4cca349 | 2011-01-18 07:53:49 -0500 | [diff] [blame] | 1463 | |
Daniel Stone | 4dbadb1 | 2012-05-30 16:31:51 +0100 | [diff] [blame] | 1464 | if (pointer->button_count == 0 && |
| 1465 | state == WL_POINTER_BUTTON_STATE_RELEASED) { |
Ander Conselvan de Oliveira | b9d2a0f | 2012-06-28 18:08:05 +0300 | [diff] [blame] | 1466 | shell_grab_end(shell_grab); |
Kristian Høgsberg | 9ddb826 | 2012-01-04 21:30:29 -0500 | [diff] [blame] | 1467 | free(grab); |
| 1468 | } |
Kristian Høgsberg | 4cca349 | 2011-01-18 07:53:49 -0500 | [diff] [blame] | 1469 | } |
| 1470 | |
Jonas Ådahl | 1ea343e | 2013-10-25 23:18:05 +0200 | [diff] [blame] | 1471 | static void |
| 1472 | move_grab_cancel(struct weston_pointer_grab *grab) |
| 1473 | { |
| 1474 | struct shell_grab *shell_grab = |
| 1475 | container_of(grab, struct shell_grab, grab); |
| 1476 | |
| 1477 | shell_grab_end(shell_grab); |
| 1478 | free(grab); |
| 1479 | } |
| 1480 | |
Kristian Høgsberg | 02bbabb | 2013-05-06 22:15:05 -0400 | [diff] [blame] | 1481 | static const struct weston_pointer_grab_interface move_grab_interface = { |
Kristian Høgsberg | 9ddb826 | 2012-01-04 21:30:29 -0500 | [diff] [blame] | 1482 | noop_grab_focus, |
Kristian Høgsberg | 4cca349 | 2011-01-18 07:53:49 -0500 | [diff] [blame] | 1483 | move_grab_motion, |
| 1484 | move_grab_button, |
Jonas Ådahl | 1ea343e | 2013-10-25 23:18:05 +0200 | [diff] [blame] | 1485 | move_grab_cancel, |
Kristian Høgsberg | 4cca349 | 2011-01-18 07:53:49 -0500 | [diff] [blame] | 1486 | }; |
| 1487 | |
Kristian Høgsberg | 9e31bff | 2012-08-01 00:08:07 -0400 | [diff] [blame] | 1488 | static int |
Kristian Høgsberg | e314875 | 2013-05-06 23:19:49 -0400 | [diff] [blame] | 1489 | surface_move(struct shell_surface *shsurf, struct weston_seat *seat) |
Kristian Høgsberg | 9e31bff | 2012-08-01 00:08:07 -0400 | [diff] [blame] | 1490 | { |
| 1491 | struct weston_move_grab *move; |
| 1492 | |
| 1493 | if (!shsurf) |
| 1494 | return -1; |
| 1495 | |
Kristian Høgsberg | c85f1d4 | 2013-10-24 16:52:00 -0700 | [diff] [blame] | 1496 | if (shsurf->grabbed) |
| 1497 | return 0; |
Ricardo Vieira | f1c3bd8 | 2014-01-18 16:30:50 +0000 | [diff] [blame] | 1498 | if (shsurf->state.fullscreen || shsurf->state.maximized) |
Kristian Høgsberg | 9e31bff | 2012-08-01 00:08:07 -0400 | [diff] [blame] | 1499 | return 0; |
| 1500 | |
| 1501 | move = malloc(sizeof *move); |
| 1502 | if (!move) |
| 1503 | return -1; |
| 1504 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 1505 | move->dx = wl_fixed_from_double(shsurf->view->geometry.x) - |
Kristian Høgsberg | e314875 | 2013-05-06 23:19:49 -0400 | [diff] [blame] | 1506 | seat->pointer->grab_x; |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 1507 | move->dy = wl_fixed_from_double(shsurf->view->geometry.y) - |
Kristian Høgsberg | e314875 | 2013-05-06 23:19:49 -0400 | [diff] [blame] | 1508 | seat->pointer->grab_y; |
Kristian Høgsberg | 9e31bff | 2012-08-01 00:08:07 -0400 | [diff] [blame] | 1509 | |
| 1510 | shell_grab_start(&move->base, &move_grab_interface, shsurf, |
Kristian Høgsberg | e314875 | 2013-05-06 23:19:49 -0400 | [diff] [blame] | 1511 | seat->pointer, DESKTOP_SHELL_CURSOR_MOVE); |
Kristian Høgsberg | 9e31bff | 2012-08-01 00:08:07 -0400 | [diff] [blame] | 1512 | |
| 1513 | return 0; |
| 1514 | } |
| 1515 | |
| 1516 | static void |
Rafael Antognolli | e2a3455 | 2013-12-03 15:35:45 -0200 | [diff] [blame] | 1517 | common_surface_move(struct wl_resource *resource, |
| 1518 | struct wl_resource *seat_resource, uint32_t serial) |
Kristian Høgsberg | 9e31bff | 2012-08-01 00:08:07 -0400 | [diff] [blame] | 1519 | { |
Jason Ekstrand | 44a3863 | 2013-06-14 10:08:00 -0500 | [diff] [blame] | 1520 | struct weston_seat *seat = wl_resource_get_user_data(seat_resource); |
Jason Ekstrand | 651f00e | 2013-06-14 10:07:54 -0500 | [diff] [blame] | 1521 | struct shell_surface *shsurf = wl_resource_get_user_data(resource); |
Giulio Camuffo | 61da3fc | 2013-04-25 13:57:45 +0300 | [diff] [blame] | 1522 | struct weston_surface *surface; |
Kristian Høgsberg | 9e31bff | 2012-08-01 00:08:07 -0400 | [diff] [blame] | 1523 | |
Kristian Høgsberg | e1b655d | 2013-08-28 23:16:20 -0700 | [diff] [blame] | 1524 | if (seat->pointer && |
Kristian Høgsberg | 70f2901 | 2014-01-09 15:43:17 -0800 | [diff] [blame] | 1525 | seat->pointer->focus && |
Kristian Høgsberg | e1b655d | 2013-08-28 23:16:20 -0700 | [diff] [blame] | 1526 | seat->pointer->button_count > 0 && |
| 1527 | seat->pointer->grab_serial == serial) { |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 1528 | surface = weston_surface_get_main_surface(seat->pointer->focus->surface); |
U. Artie Eoff | cf5737a | 2014-01-17 10:08:25 -0800 | [diff] [blame] | 1529 | if ((surface == shsurf->surface) && |
Rusty Lynch | 1084da5 | 2013-08-15 09:10:08 -0700 | [diff] [blame] | 1530 | (surface_move(shsurf, seat) < 0)) |
| 1531 | wl_resource_post_no_memory(resource); |
Kristian Høgsberg | e1b655d | 2013-08-28 23:16:20 -0700 | [diff] [blame] | 1532 | } else if (seat->touch && |
Kristian Høgsberg | 70f2901 | 2014-01-09 15:43:17 -0800 | [diff] [blame] | 1533 | seat->touch->focus && |
Kristian Høgsberg | e1b655d | 2013-08-28 23:16:20 -0700 | [diff] [blame] | 1534 | seat->touch->grab_serial == serial) { |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 1535 | surface = weston_surface_get_main_surface(seat->touch->focus->surface); |
U. Artie Eoff | cf5737a | 2014-01-17 10:08:25 -0800 | [diff] [blame] | 1536 | if ((surface == shsurf->surface) && |
Rusty Lynch | 1084da5 | 2013-08-15 09:10:08 -0700 | [diff] [blame] | 1537 | (surface_touch_move(shsurf, seat) < 0)) |
| 1538 | wl_resource_post_no_memory(resource); |
| 1539 | } |
Kristian Høgsberg | 9e31bff | 2012-08-01 00:08:07 -0400 | [diff] [blame] | 1540 | } |
| 1541 | |
Rafael Antognolli | e2a3455 | 2013-12-03 15:35:45 -0200 | [diff] [blame] | 1542 | static void |
| 1543 | shell_surface_move(struct wl_client *client, struct wl_resource *resource, |
| 1544 | struct wl_resource *seat_resource, uint32_t serial) |
| 1545 | { |
| 1546 | common_surface_move(resource, seat_resource, serial); |
| 1547 | } |
| 1548 | |
Kristian Høgsberg | 9e31bff | 2012-08-01 00:08:07 -0400 | [diff] [blame] | 1549 | struct weston_resize_grab { |
| 1550 | struct shell_grab base; |
| 1551 | uint32_t edges; |
| 1552 | int32_t width, height; |
| 1553 | }; |
| 1554 | |
| 1555 | static void |
Giulio Camuffo | 1959ab8 | 2013-11-14 23:42:52 +0100 | [diff] [blame] | 1556 | resize_grab_motion(struct weston_pointer_grab *grab, uint32_t time, |
| 1557 | wl_fixed_t x, wl_fixed_t y) |
Kristian Høgsberg | 9e31bff | 2012-08-01 00:08:07 -0400 | [diff] [blame] | 1558 | { |
| 1559 | struct weston_resize_grab *resize = (struct weston_resize_grab *) grab; |
Kristian Høgsberg | 02bbabb | 2013-05-06 22:15:05 -0400 | [diff] [blame] | 1560 | struct weston_pointer *pointer = grab->pointer; |
Kristian Høgsberg | 9e31bff | 2012-08-01 00:08:07 -0400 | [diff] [blame] | 1561 | struct shell_surface *shsurf = resize->base.shsurf; |
| 1562 | int32_t width, height; |
| 1563 | wl_fixed_t from_x, from_y; |
| 1564 | wl_fixed_t to_x, to_y; |
| 1565 | |
Giulio Camuffo | 1959ab8 | 2013-11-14 23:42:52 +0100 | [diff] [blame] | 1566 | weston_pointer_move(pointer, x, y); |
| 1567 | |
Kristian Høgsberg | 9e31bff | 2012-08-01 00:08:07 -0400 | [diff] [blame] | 1568 | if (!shsurf) |
| 1569 | return; |
| 1570 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 1571 | weston_view_from_global_fixed(shsurf->view, |
| 1572 | pointer->grab_x, pointer->grab_y, |
| 1573 | &from_x, &from_y); |
| 1574 | weston_view_from_global_fixed(shsurf->view, |
| 1575 | pointer->x, pointer->y, &to_x, &to_y); |
Kristian Høgsberg | 9e31bff | 2012-08-01 00:08:07 -0400 | [diff] [blame] | 1576 | |
| 1577 | width = resize->width; |
| 1578 | if (resize->edges & WL_SHELL_SURFACE_RESIZE_LEFT) { |
| 1579 | width += wl_fixed_to_int(from_x - to_x); |
| 1580 | } else if (resize->edges & WL_SHELL_SURFACE_RESIZE_RIGHT) { |
| 1581 | width += wl_fixed_to_int(to_x - from_x); |
| 1582 | } |
| 1583 | |
| 1584 | height = resize->height; |
| 1585 | if (resize->edges & WL_SHELL_SURFACE_RESIZE_TOP) { |
| 1586 | height += wl_fixed_to_int(from_y - to_y); |
| 1587 | } else if (resize->edges & WL_SHELL_SURFACE_RESIZE_BOTTOM) { |
| 1588 | height += wl_fixed_to_int(to_y - from_y); |
| 1589 | } |
| 1590 | |
| 1591 | shsurf->client->send_configure(shsurf->surface, |
| 1592 | resize->edges, width, height); |
| 1593 | } |
| 1594 | |
| 1595 | static void |
| 1596 | send_configure(struct weston_surface *surface, |
| 1597 | uint32_t edges, int32_t width, int32_t height) |
| 1598 | { |
| 1599 | struct shell_surface *shsurf = get_shell_surface(surface); |
| 1600 | |
U. Artie Eoff | cf5737a | 2014-01-17 10:08:25 -0800 | [diff] [blame] | 1601 | assert(shsurf); |
| 1602 | |
Jason Ekstrand | 651f00e | 2013-06-14 10:07:54 -0500 | [diff] [blame] | 1603 | wl_shell_surface_send_configure(shsurf->resource, |
Kristian Høgsberg | 9e31bff | 2012-08-01 00:08:07 -0400 | [diff] [blame] | 1604 | edges, width, height); |
| 1605 | } |
| 1606 | |
| 1607 | static const struct weston_shell_client shell_client = { |
| 1608 | send_configure |
| 1609 | }; |
| 1610 | |
| 1611 | static void |
Kristian Høgsberg | 02bbabb | 2013-05-06 22:15:05 -0400 | [diff] [blame] | 1612 | resize_grab_button(struct weston_pointer_grab *grab, |
Kristian Høgsberg | 9e31bff | 2012-08-01 00:08:07 -0400 | [diff] [blame] | 1613 | uint32_t time, uint32_t button, uint32_t state_w) |
| 1614 | { |
| 1615 | struct weston_resize_grab *resize = (struct weston_resize_grab *) grab; |
Kristian Høgsberg | 02bbabb | 2013-05-06 22:15:05 -0400 | [diff] [blame] | 1616 | struct weston_pointer *pointer = grab->pointer; |
Kristian Høgsberg | 9e31bff | 2012-08-01 00:08:07 -0400 | [diff] [blame] | 1617 | enum wl_pointer_button_state state = state_w; |
| 1618 | |
| 1619 | if (pointer->button_count == 0 && |
| 1620 | state == WL_POINTER_BUTTON_STATE_RELEASED) { |
| 1621 | shell_grab_end(&resize->base); |
| 1622 | free(grab); |
| 1623 | } |
| 1624 | } |
| 1625 | |
Jonas Ådahl | 1ea343e | 2013-10-25 23:18:05 +0200 | [diff] [blame] | 1626 | static void |
| 1627 | resize_grab_cancel(struct weston_pointer_grab *grab) |
| 1628 | { |
| 1629 | struct weston_resize_grab *resize = (struct weston_resize_grab *) grab; |
| 1630 | |
| 1631 | shell_grab_end(&resize->base); |
| 1632 | free(grab); |
| 1633 | } |
| 1634 | |
Kristian Høgsberg | 02bbabb | 2013-05-06 22:15:05 -0400 | [diff] [blame] | 1635 | static const struct weston_pointer_grab_interface resize_grab_interface = { |
Kristian Høgsberg | 9e31bff | 2012-08-01 00:08:07 -0400 | [diff] [blame] | 1636 | noop_grab_focus, |
| 1637 | resize_grab_motion, |
| 1638 | resize_grab_button, |
Jonas Ådahl | 1ea343e | 2013-10-25 23:18:05 +0200 | [diff] [blame] | 1639 | resize_grab_cancel, |
Kristian Høgsberg | 9e31bff | 2012-08-01 00:08:07 -0400 | [diff] [blame] | 1640 | }; |
| 1641 | |
Giulio Camuffo | b836664 | 2013-04-25 13:57:46 +0300 | [diff] [blame] | 1642 | /* |
| 1643 | * Returns the bounding box of a surface and all its sub-surfaces, |
| 1644 | * in the surface coordinates system. */ |
| 1645 | static void |
| 1646 | surface_subsurfaces_boundingbox(struct weston_surface *surface, int32_t *x, |
| 1647 | int32_t *y, int32_t *w, int32_t *h) { |
| 1648 | pixman_region32_t region; |
| 1649 | pixman_box32_t *box; |
| 1650 | struct weston_subsurface *subsurface; |
| 1651 | |
| 1652 | pixman_region32_init_rect(®ion, 0, 0, |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 1653 | surface->width, |
| 1654 | surface->height); |
Giulio Camuffo | b836664 | 2013-04-25 13:57:46 +0300 | [diff] [blame] | 1655 | |
| 1656 | wl_list_for_each(subsurface, &surface->subsurface_list, parent_link) { |
| 1657 | pixman_region32_union_rect(®ion, ®ion, |
| 1658 | subsurface->position.x, |
| 1659 | subsurface->position.y, |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 1660 | subsurface->surface->width, |
| 1661 | subsurface->surface->height); |
Giulio Camuffo | b836664 | 2013-04-25 13:57:46 +0300 | [diff] [blame] | 1662 | } |
| 1663 | |
| 1664 | box = pixman_region32_extents(®ion); |
| 1665 | if (x) |
| 1666 | *x = box->x1; |
| 1667 | if (y) |
| 1668 | *y = box->y1; |
| 1669 | if (w) |
| 1670 | *w = box->x2 - box->x1; |
| 1671 | if (h) |
| 1672 | *h = box->y2 - box->y1; |
| 1673 | |
| 1674 | pixman_region32_fini(®ion); |
| 1675 | } |
| 1676 | |
Kristian Høgsberg | 9e31bff | 2012-08-01 00:08:07 -0400 | [diff] [blame] | 1677 | static int |
| 1678 | surface_resize(struct shell_surface *shsurf, |
Kristian Høgsberg | e314875 | 2013-05-06 23:19:49 -0400 | [diff] [blame] | 1679 | struct weston_seat *seat, uint32_t edges) |
Kristian Høgsberg | 9e31bff | 2012-08-01 00:08:07 -0400 | [diff] [blame] | 1680 | { |
| 1681 | struct weston_resize_grab *resize; |
| 1682 | |
Rafael Antognolli | 03b1659 | 2013-12-03 15:35:42 -0200 | [diff] [blame] | 1683 | if (shsurf->state.fullscreen || shsurf->state.maximized) |
Kristian Høgsberg | 9e31bff | 2012-08-01 00:08:07 -0400 | [diff] [blame] | 1684 | return 0; |
| 1685 | |
| 1686 | if (edges == 0 || edges > 15 || |
| 1687 | (edges & 3) == 3 || (edges & 12) == 12) |
| 1688 | return 0; |
| 1689 | |
| 1690 | resize = malloc(sizeof *resize); |
| 1691 | if (!resize) |
| 1692 | return -1; |
| 1693 | |
| 1694 | resize->edges = edges; |
Giulio Camuffo | b836664 | 2013-04-25 13:57:46 +0300 | [diff] [blame] | 1695 | surface_subsurfaces_boundingbox(shsurf->surface, NULL, NULL, |
| 1696 | &resize->width, &resize->height); |
Kristian Høgsberg | 9e31bff | 2012-08-01 00:08:07 -0400 | [diff] [blame] | 1697 | |
Kristian Høgsberg | 44cd196 | 2014-02-05 21:36:04 -0800 | [diff] [blame] | 1698 | shsurf->resize_edges = edges; |
Kristian Høgsberg | 9e31bff | 2012-08-01 00:08:07 -0400 | [diff] [blame] | 1699 | shell_grab_start(&resize->base, &resize_grab_interface, shsurf, |
Kristian Høgsberg | e314875 | 2013-05-06 23:19:49 -0400 | [diff] [blame] | 1700 | seat->pointer, edges); |
Kristian Høgsberg | 9e31bff | 2012-08-01 00:08:07 -0400 | [diff] [blame] | 1701 | |
| 1702 | return 0; |
| 1703 | } |
| 1704 | |
| 1705 | static void |
Rafael Antognolli | e2a3455 | 2013-12-03 15:35:45 -0200 | [diff] [blame] | 1706 | common_surface_resize(struct wl_resource *resource, |
| 1707 | struct wl_resource *seat_resource, uint32_t serial, |
| 1708 | uint32_t edges) |
Kristian Høgsberg | 9e31bff | 2012-08-01 00:08:07 -0400 | [diff] [blame] | 1709 | { |
Jason Ekstrand | 44a3863 | 2013-06-14 10:08:00 -0500 | [diff] [blame] | 1710 | struct weston_seat *seat = wl_resource_get_user_data(seat_resource); |
Jason Ekstrand | 651f00e | 2013-06-14 10:07:54 -0500 | [diff] [blame] | 1711 | struct shell_surface *shsurf = wl_resource_get_user_data(resource); |
Giulio Camuffo | 61da3fc | 2013-04-25 13:57:45 +0300 | [diff] [blame] | 1712 | struct weston_surface *surface; |
Kristian Høgsberg | 9e31bff | 2012-08-01 00:08:07 -0400 | [diff] [blame] | 1713 | |
Rafael Antognolli | 03b1659 | 2013-12-03 15:35:42 -0200 | [diff] [blame] | 1714 | if (shsurf->state.fullscreen) |
Kristian Høgsberg | 9e31bff | 2012-08-01 00:08:07 -0400 | [diff] [blame] | 1715 | return; |
| 1716 | |
Kristian Høgsberg | e314875 | 2013-05-06 23:19:49 -0400 | [diff] [blame] | 1717 | if (seat->pointer->button_count == 0 || |
| 1718 | seat->pointer->grab_serial != serial || |
Kristian Høgsberg | 70f2901 | 2014-01-09 15:43:17 -0800 | [diff] [blame] | 1719 | seat->pointer->focus == NULL) |
| 1720 | return; |
| 1721 | |
| 1722 | surface = weston_surface_get_main_surface(seat->pointer->focus->surface); |
| 1723 | if (surface != shsurf->surface) |
Kristian Høgsberg | 9e31bff | 2012-08-01 00:08:07 -0400 | [diff] [blame] | 1724 | return; |
| 1725 | |
Kristian Høgsberg | e314875 | 2013-05-06 23:19:49 -0400 | [diff] [blame] | 1726 | if (surface_resize(shsurf, seat, edges) < 0) |
Kristian Høgsberg | 9e31bff | 2012-08-01 00:08:07 -0400 | [diff] [blame] | 1727 | wl_resource_post_no_memory(resource); |
| 1728 | } |
| 1729 | |
Scott Moreau | c3e54eb | 2012-04-17 19:06:20 -0600 | [diff] [blame] | 1730 | static void |
Rafael Antognolli | e2a3455 | 2013-12-03 15:35:45 -0200 | [diff] [blame] | 1731 | shell_surface_resize(struct wl_client *client, struct wl_resource *resource, |
| 1732 | struct wl_resource *seat_resource, uint32_t serial, |
| 1733 | uint32_t edges) |
| 1734 | { |
| 1735 | common_surface_resize(resource, seat_resource, serial, edges); |
| 1736 | } |
| 1737 | |
| 1738 | static void |
Kristian Høgsberg | 6848c25 | 2013-05-08 22:02:59 -0400 | [diff] [blame] | 1739 | busy_cursor_grab_focus(struct weston_pointer_grab *base) |
Scott Moreau | c3e54eb | 2012-04-17 19:06:20 -0600 | [diff] [blame] | 1740 | { |
Kristian Høgsberg | d56bd90 | 2012-06-05 09:58:51 -0400 | [diff] [blame] | 1741 | struct shell_grab *grab = (struct shell_grab *) base; |
Kristian Høgsberg | 6848c25 | 2013-05-08 22:02:59 -0400 | [diff] [blame] | 1742 | struct weston_pointer *pointer = base->pointer; |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 1743 | struct weston_view *view; |
Kristian Høgsberg | 6848c25 | 2013-05-08 22:02:59 -0400 | [diff] [blame] | 1744 | wl_fixed_t sx, sy; |
| 1745 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 1746 | view = weston_compositor_pick_view(pointer->seat->compositor, |
| 1747 | pointer->x, pointer->y, |
| 1748 | &sx, &sy); |
Scott Moreau | c3e54eb | 2012-04-17 19:06:20 -0600 | [diff] [blame] | 1749 | |
Kristian Høgsberg | 2bff94e | 2014-02-11 12:22:51 -0800 | [diff] [blame] | 1750 | if (!grab->shsurf || grab->shsurf->surface != view->surface) { |
| 1751 | shell_grab_end(grab); |
| 1752 | free(grab); |
| 1753 | } |
Scott Moreau | c3e54eb | 2012-04-17 19:06:20 -0600 | [diff] [blame] | 1754 | } |
| 1755 | |
| 1756 | static void |
Giulio Camuffo | 1959ab8 | 2013-11-14 23:42:52 +0100 | [diff] [blame] | 1757 | busy_cursor_grab_motion(struct weston_pointer_grab *grab, uint32_t time, |
| 1758 | wl_fixed_t x, wl_fixed_t y) |
Scott Moreau | c3e54eb | 2012-04-17 19:06:20 -0600 | [diff] [blame] | 1759 | { |
Giulio Camuffo | 1959ab8 | 2013-11-14 23:42:52 +0100 | [diff] [blame] | 1760 | weston_pointer_move(grab->pointer, x, y); |
Kristian Høgsberg | d56bd90 | 2012-06-05 09:58:51 -0400 | [diff] [blame] | 1761 | } |
Scott Moreau | c3e54eb | 2012-04-17 19:06:20 -0600 | [diff] [blame] | 1762 | |
Kristian Høgsberg | d56bd90 | 2012-06-05 09:58:51 -0400 | [diff] [blame] | 1763 | static void |
Kristian Høgsberg | 02bbabb | 2013-05-06 22:15:05 -0400 | [diff] [blame] | 1764 | busy_cursor_grab_button(struct weston_pointer_grab *base, |
Kristian Høgsberg | d56bd90 | 2012-06-05 09:58:51 -0400 | [diff] [blame] | 1765 | uint32_t time, uint32_t button, uint32_t state) |
| 1766 | { |
Kristian Høgsberg | bbe9839 | 2012-08-01 00:20:21 -0400 | [diff] [blame] | 1767 | struct shell_grab *grab = (struct shell_grab *) base; |
Kristian Høgsberg | e122b7b | 2013-05-08 16:47:00 -0400 | [diff] [blame] | 1768 | struct shell_surface *shsurf = grab->shsurf; |
Kristian Høgsberg | e314875 | 2013-05-06 23:19:49 -0400 | [diff] [blame] | 1769 | struct weston_seat *seat = grab->grab.pointer->seat; |
Kristian Høgsberg | bbe9839 | 2012-08-01 00:20:21 -0400 | [diff] [blame] | 1770 | |
Kristian Høgsberg | bbe9839 | 2012-08-01 00:20:21 -0400 | [diff] [blame] | 1771 | if (shsurf && button == BTN_LEFT && state) { |
| 1772 | activate(shsurf->shell, shsurf->surface, seat); |
| 1773 | surface_move(shsurf, seat); |
Kristian Høgsberg | 0c36903 | 2013-02-14 21:31:44 -0500 | [diff] [blame] | 1774 | } else if (shsurf && button == BTN_RIGHT && state) { |
| 1775 | activate(shsurf->shell, shsurf->surface, seat); |
Kristian Høgsberg | e314875 | 2013-05-06 23:19:49 -0400 | [diff] [blame] | 1776 | surface_rotate(shsurf, seat); |
Kristian Høgsberg | bbe9839 | 2012-08-01 00:20:21 -0400 | [diff] [blame] | 1777 | } |
Kristian Høgsberg | d56bd90 | 2012-06-05 09:58:51 -0400 | [diff] [blame] | 1778 | } |
| 1779 | |
Jonas Ådahl | 1ea343e | 2013-10-25 23:18:05 +0200 | [diff] [blame] | 1780 | static void |
| 1781 | busy_cursor_grab_cancel(struct weston_pointer_grab *base) |
| 1782 | { |
| 1783 | struct shell_grab *grab = (struct shell_grab *) base; |
| 1784 | |
| 1785 | shell_grab_end(grab); |
| 1786 | free(grab); |
| 1787 | } |
| 1788 | |
Kristian Høgsberg | 02bbabb | 2013-05-06 22:15:05 -0400 | [diff] [blame] | 1789 | static const struct weston_pointer_grab_interface busy_cursor_grab_interface = { |
Kristian Høgsberg | d56bd90 | 2012-06-05 09:58:51 -0400 | [diff] [blame] | 1790 | busy_cursor_grab_focus, |
| 1791 | busy_cursor_grab_motion, |
| 1792 | busy_cursor_grab_button, |
Jonas Ådahl | 1ea343e | 2013-10-25 23:18:05 +0200 | [diff] [blame] | 1793 | busy_cursor_grab_cancel, |
Kristian Høgsberg | d56bd90 | 2012-06-05 09:58:51 -0400 | [diff] [blame] | 1794 | }; |
| 1795 | |
| 1796 | static void |
Kristian Høgsberg | 02bbabb | 2013-05-06 22:15:05 -0400 | [diff] [blame] | 1797 | set_busy_cursor(struct shell_surface *shsurf, struct weston_pointer *pointer) |
Kristian Høgsberg | d56bd90 | 2012-06-05 09:58:51 -0400 | [diff] [blame] | 1798 | { |
| 1799 | struct shell_grab *grab; |
Kristian Høgsberg | d56bd90 | 2012-06-05 09:58:51 -0400 | [diff] [blame] | 1800 | |
Kristian Høgsberg | 2bff94e | 2014-02-11 12:22:51 -0800 | [diff] [blame] | 1801 | if (pointer->grab->interface == &busy_cursor_grab_interface) |
| 1802 | return; |
| 1803 | |
Kristian Høgsberg | d56bd90 | 2012-06-05 09:58:51 -0400 | [diff] [blame] | 1804 | grab = malloc(sizeof *grab); |
| 1805 | if (!grab) |
Scott Moreau | c3e54eb | 2012-04-17 19:06:20 -0600 | [diff] [blame] | 1806 | return; |
| 1807 | |
Ander Conselvan de Oliveira | b9d2a0f | 2012-06-28 18:08:05 +0300 | [diff] [blame] | 1808 | shell_grab_start(grab, &busy_cursor_grab_interface, shsurf, pointer, |
| 1809 | DESKTOP_SHELL_CURSOR_BUSY); |
Kristian Høgsberg | d56bd90 | 2012-06-05 09:58:51 -0400 | [diff] [blame] | 1810 | } |
Scott Moreau | c3e54eb | 2012-04-17 19:06:20 -0600 | [diff] [blame] | 1811 | |
Kristian Høgsberg | d56bd90 | 2012-06-05 09:58:51 -0400 | [diff] [blame] | 1812 | static void |
Kristian Høgsberg | 2bff94e | 2014-02-11 12:22:51 -0800 | [diff] [blame] | 1813 | end_busy_cursor(struct weston_compositor *compositor, struct wl_client *client) |
Kristian Høgsberg | d56bd90 | 2012-06-05 09:58:51 -0400 | [diff] [blame] | 1814 | { |
Kristian Høgsberg | 2bff94e | 2014-02-11 12:22:51 -0800 | [diff] [blame] | 1815 | struct shell_grab *grab; |
| 1816 | struct weston_seat *seat; |
Kristian Høgsberg | d56bd90 | 2012-06-05 09:58:51 -0400 | [diff] [blame] | 1817 | |
Kristian Høgsberg | 2bff94e | 2014-02-11 12:22:51 -0800 | [diff] [blame] | 1818 | wl_list_for_each(seat, &compositor->seat_list, link) { |
| 1819 | if (seat->pointer == NULL) |
| 1820 | continue; |
| 1821 | |
| 1822 | grab = (struct shell_grab *) seat->pointer->grab; |
| 1823 | if (grab->grab.interface == &busy_cursor_grab_interface && |
| 1824 | wl_resource_get_client(grab->shsurf->resource) == client) { |
| 1825 | shell_grab_end(grab); |
| 1826 | free(grab); |
| 1827 | } |
Scott Moreau | c3e54eb | 2012-04-17 19:06:20 -0600 | [diff] [blame] | 1828 | } |
Scott Moreau | c3e54eb | 2012-04-17 19:06:20 -0600 | [diff] [blame] | 1829 | } |
| 1830 | |
Scott Moreau | 9521d5e | 2012-04-19 13:06:17 -0600 | [diff] [blame] | 1831 | static void |
Kristian Høgsberg | 2bff94e | 2014-02-11 12:22:51 -0800 | [diff] [blame] | 1832 | handle_shell_client_destroy(struct wl_listener *listener, void *data); |
| 1833 | |
| 1834 | static int |
| 1835 | xdg_ping_timeout_handler(void *data) |
| 1836 | { |
| 1837 | struct shell_client *sc = data; |
| 1838 | struct weston_seat *seat; |
| 1839 | struct shell_surface *shsurf; |
| 1840 | |
| 1841 | /* Client is not responding */ |
| 1842 | sc->unresponsive = 1; |
Kristian Høgsberg | 2bff94e | 2014-02-11 12:22:51 -0800 | [diff] [blame] | 1843 | wl_list_for_each(seat, &sc->shell->compositor->seat_list, link) { |
| 1844 | if (seat->pointer == NULL || seat->pointer->focus == NULL) |
| 1845 | continue; |
| 1846 | if (seat->pointer->focus->surface->resource == NULL) |
| 1847 | continue; |
| 1848 | |
| 1849 | shsurf = get_shell_surface(seat->pointer->focus->surface); |
| 1850 | if (shsurf && |
| 1851 | wl_resource_get_client(shsurf->resource) == sc->client) |
| 1852 | set_busy_cursor(shsurf, seat->pointer); |
| 1853 | } |
| 1854 | |
| 1855 | return 1; |
| 1856 | } |
| 1857 | |
| 1858 | static void |
| 1859 | handle_xdg_ping(struct shell_surface *shsurf, uint32_t serial) |
| 1860 | { |
| 1861 | struct weston_compositor *compositor = shsurf->shell->compositor; |
Kristian Høgsberg | 2bff94e | 2014-02-11 12:22:51 -0800 | [diff] [blame] | 1862 | struct wl_client *client = wl_resource_get_client(shsurf->resource); |
| 1863 | struct shell_client *sc; |
| 1864 | struct wl_event_loop *loop; |
Kristian Høgsberg | dd62aba | 2014-02-12 09:56:19 -0800 | [diff] [blame] | 1865 | static const int ping_timeout = 200; |
Kristian Høgsberg | 2bff94e | 2014-02-11 12:22:51 -0800 | [diff] [blame] | 1866 | |
Kristian Høgsberg | dd62aba | 2014-02-12 09:56:19 -0800 | [diff] [blame] | 1867 | sc = get_shell_client(client); |
Kristian Høgsberg | 2bff94e | 2014-02-11 12:22:51 -0800 | [diff] [blame] | 1868 | if (sc->unresponsive) { |
| 1869 | xdg_ping_timeout_handler(sc); |
| 1870 | return; |
| 1871 | } |
| 1872 | |
| 1873 | sc->ping_serial = serial; |
| 1874 | loop = wl_display_get_event_loop(compositor->wl_display); |
| 1875 | if (sc->ping_timer == NULL) |
| 1876 | sc->ping_timer = |
| 1877 | wl_event_loop_add_timer(loop, |
| 1878 | xdg_ping_timeout_handler, sc); |
| 1879 | if (sc->ping_timer == NULL) |
| 1880 | return; |
| 1881 | |
| 1882 | wl_event_source_timer_update(sc->ping_timer, ping_timeout); |
| 1883 | |
Kristian Høgsberg | dd62aba | 2014-02-12 09:56:19 -0800 | [diff] [blame] | 1884 | if (shell_surface_is_xdg_surface(shsurf) || |
| 1885 | shell_surface_is_xdg_popup(shsurf)) |
| 1886 | xdg_shell_send_ping(sc->resource, serial); |
| 1887 | else if (shell_surface_is_wl_shell_surface(shsurf)) |
| 1888 | wl_shell_surface_send_ping(shsurf->resource, serial); |
Kristian Høgsberg | 2bff94e | 2014-02-11 12:22:51 -0800 | [diff] [blame] | 1889 | } |
| 1890 | |
Scott Moreau | ff1db4a | 2012-04-17 19:06:18 -0600 | [diff] [blame] | 1891 | static void |
| 1892 | ping_handler(struct weston_surface *surface, uint32_t serial) |
| 1893 | { |
Kristian Høgsberg | b71302e | 2012-05-10 12:28:35 -0400 | [diff] [blame] | 1894 | struct shell_surface *shsurf = get_shell_surface(surface); |
Scott Moreau | ff1db4a | 2012-04-17 19:06:18 -0600 | [diff] [blame] | 1895 | |
| 1896 | if (!shsurf) |
| 1897 | return; |
Jason Ekstrand | 651f00e | 2013-06-14 10:07:54 -0500 | [diff] [blame] | 1898 | if (!shsurf->resource) |
Kristian Høgsberg | ca535c1 | 2012-04-21 23:20:07 -0400 | [diff] [blame] | 1899 | return; |
Ander Conselvan de Oliveira | eac9a46 | 2012-07-16 14:15:48 +0300 | [diff] [blame] | 1900 | if (shsurf->surface == shsurf->shell->grab_surface) |
| 1901 | return; |
| 1902 | |
Kristian Høgsberg | dd62aba | 2014-02-12 09:56:19 -0800 | [diff] [blame] | 1903 | handle_xdg_ping(shsurf, serial); |
Scott Moreau | ff1db4a | 2012-04-17 19:06:18 -0600 | [diff] [blame] | 1904 | } |
| 1905 | |
| 1906 | static void |
Kristian Høgsberg | d56bd90 | 2012-06-05 09:58:51 -0400 | [diff] [blame] | 1907 | handle_pointer_focus(struct wl_listener *listener, void *data) |
| 1908 | { |
Kristian Høgsberg | 02bbabb | 2013-05-06 22:15:05 -0400 | [diff] [blame] | 1909 | struct weston_pointer *pointer = data; |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 1910 | struct weston_view *view = pointer->focus; |
Kristian Høgsberg | d56bd90 | 2012-06-05 09:58:51 -0400 | [diff] [blame] | 1911 | struct weston_compositor *compositor; |
Kristian Høgsberg | d56bd90 | 2012-06-05 09:58:51 -0400 | [diff] [blame] | 1912 | uint32_t serial; |
| 1913 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 1914 | if (!view) |
Kristian Høgsberg | d56bd90 | 2012-06-05 09:58:51 -0400 | [diff] [blame] | 1915 | return; |
| 1916 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 1917 | compositor = view->surface->compositor; |
Kristian Høgsberg | e11ef64 | 2014-02-11 16:35:22 -0800 | [diff] [blame] | 1918 | serial = wl_display_next_serial(compositor->wl_display); |
| 1919 | ping_handler(view->surface, serial); |
Kristian Høgsberg | d56bd90 | 2012-06-05 09:58:51 -0400 | [diff] [blame] | 1920 | } |
| 1921 | |
| 1922 | static void |
Kristian Høgsberg | f4d2f23 | 2012-08-10 10:05:39 -0400 | [diff] [blame] | 1923 | create_pointer_focus_listener(struct weston_seat *seat) |
| 1924 | { |
| 1925 | struct wl_listener *listener; |
| 1926 | |
Kristian Høgsberg | e314875 | 2013-05-06 23:19:49 -0400 | [diff] [blame] | 1927 | if (!seat->pointer) |
Kristian Høgsberg | f4d2f23 | 2012-08-10 10:05:39 -0400 | [diff] [blame] | 1928 | return; |
| 1929 | |
| 1930 | listener = malloc(sizeof *listener); |
| 1931 | listener->notify = handle_pointer_focus; |
Kristian Høgsberg | e314875 | 2013-05-06 23:19:49 -0400 | [diff] [blame] | 1932 | wl_signal_add(&seat->pointer->focus_signal, listener); |
Kristian Høgsberg | f4d2f23 | 2012-08-10 10:05:39 -0400 | [diff] [blame] | 1933 | } |
| 1934 | |
| 1935 | static void |
Jasper St. Pierre | faf27a9 | 2013-12-09 17:36:28 -0500 | [diff] [blame] | 1936 | shell_surface_lose_keyboard_focus(struct shell_surface *shsurf) |
| 1937 | { |
| 1938 | if (--shsurf->focus_count == 0) |
| 1939 | if (shell_surface_is_xdg_surface(shsurf)) |
Jasper St. Pierre | b223a72 | 2014-02-08 18:11:53 -0500 | [diff] [blame] | 1940 | xdg_surface_send_deactivated(shsurf->resource); |
Jasper St. Pierre | faf27a9 | 2013-12-09 17:36:28 -0500 | [diff] [blame] | 1941 | } |
| 1942 | |
| 1943 | static void |
| 1944 | shell_surface_gain_keyboard_focus(struct shell_surface *shsurf) |
| 1945 | { |
| 1946 | if (shsurf->focus_count++ == 0) |
| 1947 | if (shell_surface_is_xdg_surface(shsurf)) |
Jasper St. Pierre | b223a72 | 2014-02-08 18:11:53 -0500 | [diff] [blame] | 1948 | xdg_surface_send_activated(shsurf->resource); |
Jasper St. Pierre | faf27a9 | 2013-12-09 17:36:28 -0500 | [diff] [blame] | 1949 | } |
| 1950 | |
| 1951 | static void |
| 1952 | handle_keyboard_focus(struct wl_listener *listener, void *data) |
| 1953 | { |
| 1954 | struct weston_keyboard *keyboard = data; |
| 1955 | struct shell_seat *seat = get_shell_seat(keyboard->seat); |
| 1956 | |
| 1957 | if (seat->focused_surface) { |
| 1958 | struct shell_surface *shsurf = get_shell_surface(seat->focused_surface); |
| 1959 | if (shsurf) |
| 1960 | shell_surface_lose_keyboard_focus(shsurf); |
| 1961 | } |
| 1962 | |
| 1963 | seat->focused_surface = keyboard->focus; |
| 1964 | |
| 1965 | if (seat->focused_surface) { |
| 1966 | struct shell_surface *shsurf = get_shell_surface(seat->focused_surface); |
| 1967 | if (shsurf) |
| 1968 | shell_surface_gain_keyboard_focus(shsurf); |
| 1969 | } |
| 1970 | } |
| 1971 | |
| 1972 | static void |
| 1973 | create_keyboard_focus_listener(struct weston_seat *seat) |
| 1974 | { |
| 1975 | struct wl_listener *listener; |
| 1976 | |
| 1977 | if (!seat->keyboard) |
| 1978 | return; |
| 1979 | |
| 1980 | listener = malloc(sizeof *listener); |
| 1981 | listener->notify = handle_keyboard_focus; |
| 1982 | wl_signal_add(&seat->keyboard->focus_signal, listener); |
| 1983 | } |
| 1984 | |
Kristian Høgsberg | dd62aba | 2014-02-12 09:56:19 -0800 | [diff] [blame] | 1985 | static struct shell_client * |
| 1986 | get_shell_client(struct wl_client *client) |
Rafael Antognolli | e2a3455 | 2013-12-03 15:35:45 -0200 | [diff] [blame] | 1987 | { |
Kristian Høgsberg | dd62aba | 2014-02-12 09:56:19 -0800 | [diff] [blame] | 1988 | struct wl_listener *listener; |
Scott Moreau | ff1db4a | 2012-04-17 19:06:18 -0600 | [diff] [blame] | 1989 | |
Kristian Høgsberg | dd62aba | 2014-02-12 09:56:19 -0800 | [diff] [blame] | 1990 | listener = wl_client_get_destroy_listener(client, |
| 1991 | handle_shell_client_destroy); |
| 1992 | if (listener == NULL) |
| 1993 | return NULL; |
Kristian Høgsberg | 92374e1 | 2012-08-11 22:39:12 -0400 | [diff] [blame] | 1994 | |
Kristian Høgsberg | dd62aba | 2014-02-12 09:56:19 -0800 | [diff] [blame] | 1995 | return container_of(listener, struct shell_client, destroy_listener); |
Scott Moreau | ff1db4a | 2012-04-17 19:06:18 -0600 | [diff] [blame] | 1996 | } |
| 1997 | |
Kristian Høgsberg | e7afd91 | 2012-05-02 09:47:44 -0400 | [diff] [blame] | 1998 | static void |
Kristian Høgsberg | dd62aba | 2014-02-12 09:56:19 -0800 | [diff] [blame] | 1999 | shell_client_pong(struct shell_client *sc, uint32_t serial) |
Rafael Antognolli | e2a3455 | 2013-12-03 15:35:45 -0200 | [diff] [blame] | 2000 | { |
Kristian Høgsberg | dd62aba | 2014-02-12 09:56:19 -0800 | [diff] [blame] | 2001 | if (sc->ping_serial != serial) |
| 2002 | return; |
Rafael Antognolli | e2a3455 | 2013-12-03 15:35:45 -0200 | [diff] [blame] | 2003 | |
Kristian Høgsberg | dd62aba | 2014-02-12 09:56:19 -0800 | [diff] [blame] | 2004 | sc->unresponsive = 0; |
| 2005 | end_busy_cursor(sc->shell->compositor, sc->client); |
Rafael Antognolli | e2a3455 | 2013-12-03 15:35:45 -0200 | [diff] [blame] | 2006 | |
Kristian Høgsberg | dd62aba | 2014-02-12 09:56:19 -0800 | [diff] [blame] | 2007 | if (sc->ping_timer) { |
| 2008 | wl_event_source_remove(sc->ping_timer); |
| 2009 | sc->ping_timer = NULL; |
| 2010 | } |
| 2011 | |
| 2012 | } |
| 2013 | |
| 2014 | static void |
| 2015 | shell_surface_pong(struct wl_client *client, |
| 2016 | struct wl_resource *resource, uint32_t serial) |
| 2017 | { |
| 2018 | struct shell_client *sc; |
| 2019 | |
| 2020 | sc = get_shell_client(client); |
| 2021 | shell_client_pong(sc, serial); |
Rafael Antognolli | e2a3455 | 2013-12-03 15:35:45 -0200 | [diff] [blame] | 2022 | } |
| 2023 | |
| 2024 | static void |
Giulio Camuffo | 62942ad | 2013-09-11 18:20:47 +0200 | [diff] [blame] | 2025 | set_title(struct shell_surface *shsurf, const char *title) |
| 2026 | { |
| 2027 | free(shsurf->title); |
| 2028 | shsurf->title = strdup(title); |
| 2029 | } |
| 2030 | |
| 2031 | static void |
Kristian Høgsberg | e7afd91 | 2012-05-02 09:47:44 -0400 | [diff] [blame] | 2032 | shell_surface_set_title(struct wl_client *client, |
| 2033 | struct wl_resource *resource, const char *title) |
| 2034 | { |
Jason Ekstrand | 651f00e | 2013-06-14 10:07:54 -0500 | [diff] [blame] | 2035 | struct shell_surface *shsurf = wl_resource_get_user_data(resource); |
Kristian Høgsberg | e7afd91 | 2012-05-02 09:47:44 -0400 | [diff] [blame] | 2036 | |
Giulio Camuffo | 62942ad | 2013-09-11 18:20:47 +0200 | [diff] [blame] | 2037 | set_title(shsurf, title); |
Kristian Høgsberg | e7afd91 | 2012-05-02 09:47:44 -0400 | [diff] [blame] | 2038 | } |
| 2039 | |
| 2040 | static void |
| 2041 | shell_surface_set_class(struct wl_client *client, |
| 2042 | struct wl_resource *resource, const char *class) |
| 2043 | { |
Jason Ekstrand | 651f00e | 2013-06-14 10:07:54 -0500 | [diff] [blame] | 2044 | struct shell_surface *shsurf = wl_resource_get_user_data(resource); |
Kristian Høgsberg | e7afd91 | 2012-05-02 09:47:44 -0400 | [diff] [blame] | 2045 | |
| 2046 | free(shsurf->class); |
| 2047 | shsurf->class = strdup(class); |
| 2048 | } |
| 2049 | |
Alex Wu | 4539b08 | 2012-03-01 12:57:46 +0800 | [diff] [blame] | 2050 | static void |
Alexander Larsson | f82b6ca | 2013-05-28 16:23:39 +0200 | [diff] [blame] | 2051 | restore_output_mode(struct weston_output *output) |
| 2052 | { |
Hardening | 57388e4 | 2013-09-18 23:56:36 +0200 | [diff] [blame] | 2053 | if (output->current_mode != output->original_mode || |
| 2054 | (int32_t)output->current_scale != output->original_scale) |
Alexander Larsson | f82b6ca | 2013-05-28 16:23:39 +0200 | [diff] [blame] | 2055 | weston_output_switch_mode(output, |
Hardening | 57388e4 | 2013-09-18 23:56:36 +0200 | [diff] [blame] | 2056 | output->original_mode, |
| 2057 | output->original_scale, |
| 2058 | WESTON_MODE_SWITCH_RESTORE_NATIVE); |
Alexander Larsson | f82b6ca | 2013-05-28 16:23:39 +0200 | [diff] [blame] | 2059 | } |
| 2060 | |
| 2061 | static void |
| 2062 | restore_all_output_modes(struct weston_compositor *compositor) |
| 2063 | { |
| 2064 | struct weston_output *output; |
| 2065 | |
| 2066 | wl_list_for_each(output, &compositor->output_list, link) |
| 2067 | restore_output_mode(output); |
| 2068 | } |
| 2069 | |
Philip Withnall | becb77e | 2013-11-25 18:01:30 +0000 | [diff] [blame] | 2070 | static int |
| 2071 | get_output_panel_height(struct desktop_shell *shell, |
| 2072 | struct weston_output *output) |
| 2073 | { |
| 2074 | struct weston_view *view; |
| 2075 | int panel_height = 0; |
| 2076 | |
| 2077 | if (!output) |
| 2078 | return 0; |
| 2079 | |
| 2080 | wl_list_for_each(view, &shell->panel_layer.view_list, layer_link) { |
| 2081 | if (view->surface->output == output) { |
Jason Ekstrand | 918f2dd | 2013-12-02 21:01:53 -0600 | [diff] [blame] | 2082 | panel_height = view->surface->height; |
Philip Withnall | becb77e | 2013-11-25 18:01:30 +0000 | [diff] [blame] | 2083 | break; |
| 2084 | } |
| 2085 | } |
| 2086 | |
| 2087 | return panel_height; |
| 2088 | } |
| 2089 | |
Philip Withnall | 07926d9 | 2013-11-25 18:01:40 +0000 | [diff] [blame] | 2090 | /* The surface will be inserted into the list immediately after the link |
| 2091 | * returned by this function (i.e. will be stacked immediately above the |
| 2092 | * returned link). */ |
| 2093 | static struct wl_list * |
| 2094 | shell_surface_calculate_layer_link (struct shell_surface *shsurf) |
| 2095 | { |
| 2096 | struct workspace *ws; |
Kristian Høgsberg | ead5242 | 2014-01-01 13:51:52 -0800 | [diff] [blame] | 2097 | struct weston_view *parent; |
Philip Withnall | 07926d9 | 2013-11-25 18:01:40 +0000 | [diff] [blame] | 2098 | |
| 2099 | switch (shsurf->type) { |
Kristian Høgsberg | ead5242 | 2014-01-01 13:51:52 -0800 | [diff] [blame] | 2100 | case SHELL_SURFACE_POPUP: |
| 2101 | case SHELL_SURFACE_TOPLEVEL: |
Rafael Antognolli | ed207b4 | 2013-12-03 15:35:43 -0200 | [diff] [blame] | 2102 | if (shsurf->state.fullscreen) { |
Rafael Antognolli | 03b1659 | 2013-12-03 15:35:42 -0200 | [diff] [blame] | 2103 | return &shsurf->shell->fullscreen_layer.view_list; |
Rafael Antognolli | ed207b4 | 2013-12-03 15:35:43 -0200 | [diff] [blame] | 2104 | } else if (shsurf->parent) { |
Kristian Høgsberg | d55db69 | 2014-01-01 12:26:14 -0800 | [diff] [blame] | 2105 | /* Move the surface to its parent layer so |
| 2106 | * that surfaces which are transient for |
| 2107 | * fullscreen surfaces don't get hidden by the |
| 2108 | * fullscreen surfaces. */ |
Rafael Antognolli | ed207b4 | 2013-12-03 15:35:43 -0200 | [diff] [blame] | 2109 | |
| 2110 | /* TODO: Handle a parent with multiple views */ |
| 2111 | parent = get_default_view(shsurf->parent); |
| 2112 | if (parent) |
| 2113 | return parent->layer_link.prev; |
| 2114 | } |
Rafael Antognolli | 03b1659 | 2013-12-03 15:35:42 -0200 | [diff] [blame] | 2115 | break; |
Philip Withnall | 07926d9 | 2013-11-25 18:01:40 +0000 | [diff] [blame] | 2116 | |
| 2117 | case SHELL_SURFACE_XWAYLAND: |
Kristian Høgsberg | 4804a30 | 2013-12-05 22:43:03 -0800 | [diff] [blame] | 2118 | return &shsurf->shell->fullscreen_layer.view_list; |
| 2119 | |
Philip Withnall | 07926d9 | 2013-11-25 18:01:40 +0000 | [diff] [blame] | 2120 | case SHELL_SURFACE_NONE: |
| 2121 | default: |
| 2122 | /* Go to the fallback, below. */ |
| 2123 | break; |
| 2124 | } |
| 2125 | |
| 2126 | /* Move the surface to a normal workspace layer so that surfaces |
| 2127 | * which were previously fullscreen or transient are no longer |
| 2128 | * rendered on top. */ |
| 2129 | ws = get_current_workspace(shsurf->shell); |
| 2130 | return &ws->layer.view_list; |
| 2131 | } |
| 2132 | |
Philip Withnall | 648a4dd | 2013-11-25 18:01:44 +0000 | [diff] [blame] | 2133 | static void |
| 2134 | shell_surface_update_child_surface_layers (struct shell_surface *shsurf) |
| 2135 | { |
| 2136 | struct shell_surface *child; |
| 2137 | |
| 2138 | /* Move the child layers to the same workspace as shsurf. They will be |
| 2139 | * stacked above shsurf. */ |
| 2140 | wl_list_for_each_reverse(child, &shsurf->children_list, children_link) { |
| 2141 | if (shsurf->view->layer_link.prev != &child->view->layer_link) { |
| 2142 | weston_view_geometry_dirty(child->view); |
| 2143 | wl_list_remove(&child->view->layer_link); |
| 2144 | wl_list_insert(shsurf->view->layer_link.prev, |
| 2145 | &child->view->layer_link); |
| 2146 | weston_view_geometry_dirty(child->view); |
| 2147 | weston_surface_damage(child->surface); |
| 2148 | |
| 2149 | /* Recurse. We don’t expect this to recurse very far (if |
| 2150 | * at all) because that would imply we have transient |
| 2151 | * (or popup) children of transient surfaces, which |
| 2152 | * would be unusual. */ |
| 2153 | shell_surface_update_child_surface_layers(child); |
| 2154 | } |
| 2155 | } |
| 2156 | } |
| 2157 | |
Philip Withnall | e1d75ae | 2013-11-25 18:01:41 +0000 | [diff] [blame] | 2158 | /* 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] | 2159 | * geometry to ensure the changes are redrawn. |
| 2160 | * |
| 2161 | * If any child surfaces exist and are mapped, ensure they’re in the same layer |
| 2162 | * as this surface. */ |
Philip Withnall | e1d75ae | 2013-11-25 18:01:41 +0000 | [diff] [blame] | 2163 | static void |
| 2164 | shell_surface_update_layer(struct shell_surface *shsurf) |
| 2165 | { |
| 2166 | struct wl_list *new_layer_link; |
| 2167 | |
| 2168 | new_layer_link = shell_surface_calculate_layer_link(shsurf); |
| 2169 | |
| 2170 | if (new_layer_link == &shsurf->view->layer_link) |
| 2171 | return; |
| 2172 | |
| 2173 | weston_view_geometry_dirty(shsurf->view); |
| 2174 | wl_list_remove(&shsurf->view->layer_link); |
| 2175 | wl_list_insert(new_layer_link, &shsurf->view->layer_link); |
| 2176 | weston_view_geometry_dirty(shsurf->view); |
| 2177 | weston_surface_damage(shsurf->surface); |
Philip Withnall | 648a4dd | 2013-11-25 18:01:44 +0000 | [diff] [blame] | 2178 | |
| 2179 | shell_surface_update_child_surface_layers(shsurf); |
Philip Withnall | e1d75ae | 2013-11-25 18:01:41 +0000 | [diff] [blame] | 2180 | } |
| 2181 | |
Alexander Larsson | f82b6ca | 2013-05-28 16:23:39 +0200 | [diff] [blame] | 2182 | static void |
Philip Withnall | dc4332f | 2013-11-25 18:01:38 +0000 | [diff] [blame] | 2183 | shell_surface_set_parent(struct shell_surface *shsurf, |
| 2184 | struct weston_surface *parent) |
| 2185 | { |
| 2186 | shsurf->parent = parent; |
Philip Withnall | 648a4dd | 2013-11-25 18:01:44 +0000 | [diff] [blame] | 2187 | |
| 2188 | wl_list_remove(&shsurf->children_link); |
| 2189 | wl_list_init(&shsurf->children_link); |
| 2190 | |
| 2191 | /* Insert into the parent surface’s child list. */ |
| 2192 | if (parent != NULL) { |
| 2193 | struct shell_surface *parent_shsurf = get_shell_surface(parent); |
| 2194 | if (parent_shsurf != NULL) |
| 2195 | wl_list_insert(&parent_shsurf->children_list, |
| 2196 | &shsurf->children_link); |
| 2197 | } |
Philip Withnall | dc4332f | 2013-11-25 18:01:38 +0000 | [diff] [blame] | 2198 | } |
| 2199 | |
| 2200 | static void |
Philip Withnall | 352e7ed | 2013-11-25 18:01:35 +0000 | [diff] [blame] | 2201 | shell_surface_set_output(struct shell_surface *shsurf, |
| 2202 | struct weston_output *output) |
| 2203 | { |
| 2204 | struct weston_surface *es = shsurf->surface; |
| 2205 | |
| 2206 | /* get the default output, if the client set it as NULL |
| 2207 | check whether the ouput is available */ |
| 2208 | if (output) |
| 2209 | shsurf->output = output; |
| 2210 | else if (es->output) |
| 2211 | shsurf->output = es->output; |
| 2212 | else |
| 2213 | shsurf->output = get_default_output(es->compositor); |
| 2214 | } |
| 2215 | |
| 2216 | static void |
Rafael Antognolli | 03b1659 | 2013-12-03 15:35:42 -0200 | [diff] [blame] | 2217 | surface_clear_next_states(struct shell_surface *shsurf) |
| 2218 | { |
| 2219 | shsurf->next_state.maximized = false; |
| 2220 | shsurf->next_state.fullscreen = false; |
| 2221 | |
| 2222 | if ((shsurf->next_state.maximized != shsurf->state.maximized) || |
| 2223 | (shsurf->next_state.fullscreen != shsurf->state.fullscreen)) |
| 2224 | shsurf->state_changed = true; |
| 2225 | } |
| 2226 | |
| 2227 | static void |
Philip Withnall | becb77e | 2013-11-25 18:01:30 +0000 | [diff] [blame] | 2228 | set_toplevel(struct shell_surface *shsurf) |
| 2229 | { |
Kristian Høgsberg | 41fbf6f | 2013-12-05 22:31:25 -0800 | [diff] [blame] | 2230 | shell_surface_set_parent(shsurf, NULL); |
| 2231 | surface_clear_next_states(shsurf); |
Kristian Høgsberg | c8f8dd8 | 2013-12-05 23:20:33 -0800 | [diff] [blame] | 2232 | shsurf->type = SHELL_SURFACE_TOPLEVEL; |
Philip Withnall | 648a4dd | 2013-11-25 18:01:44 +0000 | [diff] [blame] | 2233 | |
| 2234 | /* The layer_link is updated in set_surface_type(), |
| 2235 | * called from configure. */ |
Philip Withnall | becb77e | 2013-11-25 18:01:30 +0000 | [diff] [blame] | 2236 | } |
| 2237 | |
| 2238 | static void |
| 2239 | shell_surface_set_toplevel(struct wl_client *client, |
| 2240 | struct wl_resource *resource) |
| 2241 | { |
| 2242 | struct shell_surface *surface = wl_resource_get_user_data(resource); |
| 2243 | |
| 2244 | set_toplevel(surface); |
| 2245 | } |
| 2246 | |
| 2247 | static void |
| 2248 | set_transient(struct shell_surface *shsurf, |
| 2249 | struct weston_surface *parent, int x, int y, uint32_t flags) |
| 2250 | { |
Philip Withnall | dc4332f | 2013-11-25 18:01:38 +0000 | [diff] [blame] | 2251 | assert(parent != NULL); |
| 2252 | |
Kristian Høgsberg | 9f7e331 | 2014-01-02 22:40:37 -0800 | [diff] [blame] | 2253 | shell_surface_set_parent(shsurf, parent); |
| 2254 | |
| 2255 | surface_clear_next_states(shsurf); |
| 2256 | |
Philip Withnall | becb77e | 2013-11-25 18:01:30 +0000 | [diff] [blame] | 2257 | shsurf->transient.x = x; |
| 2258 | shsurf->transient.y = y; |
| 2259 | shsurf->transient.flags = flags; |
Philip Withnall | dc4332f | 2013-11-25 18:01:38 +0000 | [diff] [blame] | 2260 | |
Rafael Antognolli | ed207b4 | 2013-12-03 15:35:43 -0200 | [diff] [blame] | 2261 | shsurf->next_state.relative = true; |
Kristian Høgsberg | a1df7ac | 2013-12-31 15:01:01 -0800 | [diff] [blame] | 2262 | shsurf->state_changed = true; |
Kristian Høgsberg | c8f8dd8 | 2013-12-05 23:20:33 -0800 | [diff] [blame] | 2263 | shsurf->type = SHELL_SURFACE_TOPLEVEL; |
Philip Withnall | 648a4dd | 2013-11-25 18:01:44 +0000 | [diff] [blame] | 2264 | |
| 2265 | /* The layer_link is updated in set_surface_type(), |
| 2266 | * called from configure. */ |
Philip Withnall | becb77e | 2013-11-25 18:01:30 +0000 | [diff] [blame] | 2267 | } |
| 2268 | |
| 2269 | static void |
| 2270 | shell_surface_set_transient(struct wl_client *client, |
| 2271 | struct wl_resource *resource, |
| 2272 | struct wl_resource *parent_resource, |
| 2273 | int x, int y, uint32_t flags) |
| 2274 | { |
| 2275 | struct shell_surface *shsurf = wl_resource_get_user_data(resource); |
| 2276 | struct weston_surface *parent = |
| 2277 | wl_resource_get_user_data(parent_resource); |
| 2278 | |
| 2279 | set_transient(shsurf, parent, x, y, flags); |
| 2280 | } |
| 2281 | |
| 2282 | static void |
| 2283 | set_fullscreen(struct shell_surface *shsurf, |
| 2284 | uint32_t method, |
| 2285 | uint32_t framerate, |
| 2286 | struct weston_output *output) |
| 2287 | { |
Philip Withnall | 352e7ed | 2013-11-25 18:01:35 +0000 | [diff] [blame] | 2288 | shell_surface_set_output(shsurf, output); |
Philip Withnall | becb77e | 2013-11-25 18:01:30 +0000 | [diff] [blame] | 2289 | |
| 2290 | shsurf->fullscreen_output = shsurf->output; |
| 2291 | shsurf->fullscreen.type = method; |
| 2292 | shsurf->fullscreen.framerate = framerate; |
Philip Withnall | dc4332f | 2013-11-25 18:01:38 +0000 | [diff] [blame] | 2293 | |
Kristian Høgsberg | c8f8dd8 | 2013-12-05 23:20:33 -0800 | [diff] [blame] | 2294 | shsurf->type = SHELL_SURFACE_TOPLEVEL; |
Philip Withnall | becb77e | 2013-11-25 18:01:30 +0000 | [diff] [blame] | 2295 | |
| 2296 | shsurf->client->send_configure(shsurf->surface, 0, |
| 2297 | shsurf->output->width, |
| 2298 | shsurf->output->height); |
Philip Withnall | 648a4dd | 2013-11-25 18:01:44 +0000 | [diff] [blame] | 2299 | |
| 2300 | /* The layer_link is updated in set_surface_type(), |
| 2301 | * called from configure. */ |
Philip Withnall | becb77e | 2013-11-25 18:01:30 +0000 | [diff] [blame] | 2302 | } |
| 2303 | |
| 2304 | static void |
Zhang, Xiong Y | 3123693 | 2013-12-13 22:10:57 +0200 | [diff] [blame] | 2305 | weston_view_set_initial_position(struct weston_view *view, |
| 2306 | struct desktop_shell *shell); |
| 2307 | |
| 2308 | static void |
Philip Withnall | becb77e | 2013-11-25 18:01:30 +0000 | [diff] [blame] | 2309 | unset_fullscreen(struct shell_surface *shsurf) |
Alex Wu | 4539b08 | 2012-03-01 12:57:46 +0800 | [diff] [blame] | 2310 | { |
Philip Withnall | f85fe84 | 2013-11-25 18:01:37 +0000 | [diff] [blame] | 2311 | /* Unset the fullscreen output, driver configuration and transforms. */ |
Alex Wu | bd3354b | 2012-04-17 17:20:49 +0800 | [diff] [blame] | 2312 | if (shsurf->fullscreen.type == WL_SHELL_SURFACE_FULLSCREEN_METHOD_DRIVER && |
| 2313 | shell_surface_is_top_fullscreen(shsurf)) { |
Alexander Larsson | f82b6ca | 2013-05-28 16:23:39 +0200 | [diff] [blame] | 2314 | restore_output_mode(shsurf->fullscreen_output); |
Alex Wu | bd3354b | 2012-04-17 17:20:49 +0800 | [diff] [blame] | 2315 | } |
Philip Withnall | f85fe84 | 2013-11-25 18:01:37 +0000 | [diff] [blame] | 2316 | shsurf->fullscreen_output = NULL; |
| 2317 | |
Alex Wu | 4539b08 | 2012-03-01 12:57:46 +0800 | [diff] [blame] | 2318 | shsurf->fullscreen.type = WL_SHELL_SURFACE_FULLSCREEN_METHOD_DEFAULT; |
| 2319 | shsurf->fullscreen.framerate = 0; |
Philip Withnall | f85fe84 | 2013-11-25 18:01:37 +0000 | [diff] [blame] | 2320 | |
Alex Wu | 4539b08 | 2012-03-01 12:57:46 +0800 | [diff] [blame] | 2321 | wl_list_remove(&shsurf->fullscreen.transform.link); |
| 2322 | wl_list_init(&shsurf->fullscreen.transform.link); |
Philip Withnall | f85fe84 | 2013-11-25 18:01:37 +0000 | [diff] [blame] | 2323 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 2324 | if (shsurf->fullscreen.black_view) |
| 2325 | weston_surface_destroy(shsurf->fullscreen.black_view->surface); |
| 2326 | shsurf->fullscreen.black_view = NULL; |
Philip Withnall | f85fe84 | 2013-11-25 18:01:37 +0000 | [diff] [blame] | 2327 | |
Zhang, Xiong Y | 3123693 | 2013-12-13 22:10:57 +0200 | [diff] [blame] | 2328 | if (shsurf->saved_position_valid) |
| 2329 | weston_view_set_position(shsurf->view, |
| 2330 | shsurf->saved_x, shsurf->saved_y); |
| 2331 | else |
| 2332 | weston_view_set_initial_position(shsurf->view, shsurf->shell); |
| 2333 | |
Alex Wu | 7bcb8bd | 2012-04-27 09:07:24 +0800 | [diff] [blame] | 2334 | if (shsurf->saved_rotation_valid) { |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 2335 | wl_list_insert(&shsurf->view->geometry.transformation_list, |
Philip Withnall | becb77e | 2013-11-25 18:01:30 +0000 | [diff] [blame] | 2336 | &shsurf->rotation.transform.link); |
Alex Wu | 7bcb8bd | 2012-04-27 09:07:24 +0800 | [diff] [blame] | 2337 | shsurf->saved_rotation_valid = false; |
| 2338 | } |
Rafal Mielniczuk | 3e3862c | 2012-10-07 20:25:36 +0200 | [diff] [blame] | 2339 | |
Philip Withnall | e1d75ae | 2013-11-25 18:01:41 +0000 | [diff] [blame] | 2340 | /* Layer is updated in set_surface_type(). */ |
Alex Wu | 4539b08 | 2012-03-01 12:57:46 +0800 | [diff] [blame] | 2341 | } |
| 2342 | |
Rafal Mielniczuk | fffdcdd | 2013-03-11 19:26:54 +0100 | [diff] [blame] | 2343 | static void |
Philip Withnall | becb77e | 2013-11-25 18:01:30 +0000 | [diff] [blame] | 2344 | shell_surface_set_fullscreen(struct wl_client *client, |
| 2345 | struct wl_resource *resource, |
| 2346 | uint32_t method, |
| 2347 | uint32_t framerate, |
| 2348 | struct wl_resource *output_resource) |
| 2349 | { |
| 2350 | struct shell_surface *shsurf = wl_resource_get_user_data(resource); |
| 2351 | struct weston_output *output; |
| 2352 | |
| 2353 | if (output_resource) |
| 2354 | output = wl_resource_get_user_data(output_resource); |
| 2355 | else |
| 2356 | output = NULL; |
| 2357 | |
Rafael Antognolli | 4b99a40 | 2013-12-03 15:35:44 -0200 | [diff] [blame] | 2358 | shell_surface_set_parent(shsurf, NULL); |
| 2359 | |
Rafael Antognolli | 03b1659 | 2013-12-03 15:35:42 -0200 | [diff] [blame] | 2360 | surface_clear_next_states(shsurf); |
Philip Withnall | becb77e | 2013-11-25 18:01:30 +0000 | [diff] [blame] | 2361 | set_fullscreen(shsurf, method, framerate, output); |
Jasper St. Pierre | 8c6aa45 | 2014-02-08 18:29:49 -0500 | [diff] [blame] | 2362 | |
| 2363 | shsurf->next_state.fullscreen = true; |
| 2364 | shsurf->state_changed = true; |
Philip Withnall | becb77e | 2013-11-25 18:01:30 +0000 | [diff] [blame] | 2365 | } |
| 2366 | |
| 2367 | static void |
| 2368 | set_popup(struct shell_surface *shsurf, |
| 2369 | struct weston_surface *parent, |
| 2370 | struct weston_seat *seat, |
| 2371 | uint32_t serial, |
| 2372 | int32_t x, |
| 2373 | int32_t y) |
| 2374 | { |
Philip Withnall | dc4332f | 2013-11-25 18:01:38 +0000 | [diff] [blame] | 2375 | assert(parent != NULL); |
| 2376 | |
Philip Withnall | becb77e | 2013-11-25 18:01:30 +0000 | [diff] [blame] | 2377 | shsurf->popup.shseat = get_shell_seat(seat); |
| 2378 | shsurf->popup.serial = serial; |
| 2379 | shsurf->popup.x = x; |
| 2380 | shsurf->popup.y = y; |
Philip Withnall | dc4332f | 2013-11-25 18:01:38 +0000 | [diff] [blame] | 2381 | |
Kristian Høgsberg | c8f8dd8 | 2013-12-05 23:20:33 -0800 | [diff] [blame] | 2382 | shsurf->type = SHELL_SURFACE_POPUP; |
Philip Withnall | becb77e | 2013-11-25 18:01:30 +0000 | [diff] [blame] | 2383 | } |
| 2384 | |
| 2385 | static void |
| 2386 | shell_surface_set_popup(struct wl_client *client, |
| 2387 | struct wl_resource *resource, |
| 2388 | struct wl_resource *seat_resource, |
| 2389 | uint32_t serial, |
| 2390 | struct wl_resource *parent_resource, |
| 2391 | int32_t x, int32_t y, uint32_t flags) |
| 2392 | { |
| 2393 | struct shell_surface *shsurf = wl_resource_get_user_data(resource); |
Rafael Antognolli | 4b99a40 | 2013-12-03 15:35:44 -0200 | [diff] [blame] | 2394 | struct weston_surface *parent = |
| 2395 | wl_resource_get_user_data(parent_resource); |
| 2396 | |
| 2397 | shell_surface_set_parent(shsurf, parent); |
Philip Withnall | becb77e | 2013-11-25 18:01:30 +0000 | [diff] [blame] | 2398 | |
Rafael Antognolli | 03b1659 | 2013-12-03 15:35:42 -0200 | [diff] [blame] | 2399 | surface_clear_next_states(shsurf); |
Philip Withnall | becb77e | 2013-11-25 18:01:30 +0000 | [diff] [blame] | 2400 | set_popup(shsurf, |
Rafael Antognolli | 4b99a40 | 2013-12-03 15:35:44 -0200 | [diff] [blame] | 2401 | parent, |
Philip Withnall | becb77e | 2013-11-25 18:01:30 +0000 | [diff] [blame] | 2402 | wl_resource_get_user_data(seat_resource), |
| 2403 | serial, x, y); |
| 2404 | } |
| 2405 | |
| 2406 | static void |
| 2407 | set_maximized(struct shell_surface *shsurf, |
| 2408 | struct weston_output *output) |
| 2409 | { |
| 2410 | struct desktop_shell *shell; |
| 2411 | uint32_t edges = 0, panel_height = 0; |
Philip Withnall | becb77e | 2013-11-25 18:01:30 +0000 | [diff] [blame] | 2412 | |
Philip Withnall | 352e7ed | 2013-11-25 18:01:35 +0000 | [diff] [blame] | 2413 | shell_surface_set_output(shsurf, output); |
Philip Withnall | becb77e | 2013-11-25 18:01:30 +0000 | [diff] [blame] | 2414 | |
| 2415 | shell = shell_surface_get_shell(shsurf); |
| 2416 | panel_height = get_output_panel_height(shell, shsurf->output); |
| 2417 | edges = WL_SHELL_SURFACE_RESIZE_TOP | WL_SHELL_SURFACE_RESIZE_LEFT; |
| 2418 | |
| 2419 | shsurf->client->send_configure(shsurf->surface, edges, |
| 2420 | shsurf->output->width, |
| 2421 | shsurf->output->height - panel_height); |
| 2422 | |
Kristian Høgsberg | c8f8dd8 | 2013-12-05 23:20:33 -0800 | [diff] [blame] | 2423 | shsurf->type = SHELL_SURFACE_TOPLEVEL; |
Philip Withnall | becb77e | 2013-11-25 18:01:30 +0000 | [diff] [blame] | 2424 | } |
| 2425 | |
| 2426 | static void |
| 2427 | unset_maximized(struct shell_surface *shsurf) |
Rafal Mielniczuk | fffdcdd | 2013-03-11 19:26:54 +0100 | [diff] [blame] | 2428 | { |
Rafal Mielniczuk | fffdcdd | 2013-03-11 19:26:54 +0100 | [diff] [blame] | 2429 | /* undo all maximized things here */ |
| 2430 | shsurf->output = get_default_output(shsurf->surface->compositor); |
Zhang, Xiong Y | 3123693 | 2013-12-13 22:10:57 +0200 | [diff] [blame] | 2431 | |
| 2432 | if (shsurf->saved_position_valid) |
| 2433 | weston_view_set_position(shsurf->view, |
| 2434 | shsurf->saved_x, shsurf->saved_y); |
| 2435 | else |
| 2436 | weston_view_set_initial_position(shsurf->view, shsurf->shell); |
Rafal Mielniczuk | fffdcdd | 2013-03-11 19:26:54 +0100 | [diff] [blame] | 2437 | |
| 2438 | if (shsurf->saved_rotation_valid) { |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 2439 | wl_list_insert(&shsurf->view->geometry.transformation_list, |
| 2440 | &shsurf->rotation.transform.link); |
Rafal Mielniczuk | fffdcdd | 2013-03-11 19:26:54 +0100 | [diff] [blame] | 2441 | shsurf->saved_rotation_valid = false; |
| 2442 | } |
| 2443 | |
Philip Withnall | e1d75ae | 2013-11-25 18:01:41 +0000 | [diff] [blame] | 2444 | /* Layer is updated in set_surface_type(). */ |
Rafal Mielniczuk | fffdcdd | 2013-03-11 19:26:54 +0100 | [diff] [blame] | 2445 | } |
| 2446 | |
Philip Withnall | becb77e | 2013-11-25 18:01:30 +0000 | [diff] [blame] | 2447 | static void |
| 2448 | shell_surface_set_maximized(struct wl_client *client, |
| 2449 | struct wl_resource *resource, |
| 2450 | struct wl_resource *output_resource) |
| 2451 | { |
| 2452 | struct shell_surface *shsurf = wl_resource_get_user_data(resource); |
| 2453 | struct weston_output *output; |
| 2454 | |
| 2455 | if (output_resource) |
| 2456 | output = wl_resource_get_user_data(output_resource); |
| 2457 | else |
| 2458 | output = NULL; |
| 2459 | |
Rafael Antognolli | 4b99a40 | 2013-12-03 15:35:44 -0200 | [diff] [blame] | 2460 | shell_surface_set_parent(shsurf, NULL); |
| 2461 | |
Rafael Antognolli | 03b1659 | 2013-12-03 15:35:42 -0200 | [diff] [blame] | 2462 | surface_clear_next_states(shsurf); |
Philip Withnall | becb77e | 2013-11-25 18:01:30 +0000 | [diff] [blame] | 2463 | set_maximized(shsurf, output); |
Jasper St. Pierre | 8c6aa45 | 2014-02-08 18:29:49 -0500 | [diff] [blame] | 2464 | |
| 2465 | shsurf->next_state.maximized = true; |
| 2466 | shsurf->state_changed = true; |
Philip Withnall | becb77e | 2013-11-25 18:01:30 +0000 | [diff] [blame] | 2467 | } |
| 2468 | |
Philip Withnall | e1d75ae | 2013-11-25 18:01:41 +0000 | [diff] [blame] | 2469 | /* This is only ever called from set_surface_type(), so there’s no need to |
| 2470 | * update layer_links here, since they’ll be updated when we return. */ |
Pekka Paalanen | 9826223 | 2011-12-01 10:42:22 +0200 | [diff] [blame] | 2471 | static int |
Philip Withnall | becb77e | 2013-11-25 18:01:30 +0000 | [diff] [blame] | 2472 | reset_surface_type(struct shell_surface *surface) |
Pekka Paalanen | 9826223 | 2011-12-01 10:42:22 +0200 | [diff] [blame] | 2473 | { |
Rafael Antognolli | 03b1659 | 2013-12-03 15:35:42 -0200 | [diff] [blame] | 2474 | if (surface->state.fullscreen) |
Philip Withnall | becb77e | 2013-11-25 18:01:30 +0000 | [diff] [blame] | 2475 | unset_fullscreen(surface); |
Rafael Antognolli | 03b1659 | 2013-12-03 15:35:42 -0200 | [diff] [blame] | 2476 | if (surface->state.maximized) |
Philip Withnall | becb77e | 2013-11-25 18:01:30 +0000 | [diff] [blame] | 2477 | unset_maximized(surface); |
Pekka Paalanen | 9826223 | 2011-12-01 10:42:22 +0200 | [diff] [blame] | 2478 | |
Pekka Paalanen | 9826223 | 2011-12-01 10:42:22 +0200 | [diff] [blame] | 2479 | return 0; |
| 2480 | } |
| 2481 | |
Kristian Høgsberg | 4cca349 | 2011-01-18 07:53:49 -0500 | [diff] [blame] | 2482 | static void |
Rafael Antognolli | 03b1659 | 2013-12-03 15:35:42 -0200 | [diff] [blame] | 2483 | set_full_output(struct shell_surface *shsurf) |
| 2484 | { |
| 2485 | shsurf->saved_x = shsurf->view->geometry.x; |
| 2486 | shsurf->saved_y = shsurf->view->geometry.y; |
Rafael Antognolli | 3c4e3f7 | 2013-12-03 15:35:46 -0200 | [diff] [blame] | 2487 | shsurf->saved_width = shsurf->surface->width; |
| 2488 | shsurf->saved_height = shsurf->surface->height; |
| 2489 | shsurf->saved_size_valid = true; |
Rafael Antognolli | 03b1659 | 2013-12-03 15:35:42 -0200 | [diff] [blame] | 2490 | shsurf->saved_position_valid = true; |
| 2491 | |
| 2492 | if (!wl_list_empty(&shsurf->rotation.transform.link)) { |
| 2493 | wl_list_remove(&shsurf->rotation.transform.link); |
| 2494 | wl_list_init(&shsurf->rotation.transform.link); |
| 2495 | weston_view_geometry_dirty(shsurf->view); |
| 2496 | shsurf->saved_rotation_valid = true; |
| 2497 | } |
| 2498 | } |
| 2499 | |
| 2500 | static void |
Kristian Høgsberg | 7f366e7 | 2012-04-27 17:20:01 -0400 | [diff] [blame] | 2501 | set_surface_type(struct shell_surface *shsurf) |
| 2502 | { |
Kristian Høgsberg | 8150b19 | 2012-06-27 10:22:58 -0400 | [diff] [blame] | 2503 | struct weston_surface *pes = shsurf->parent; |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 2504 | struct weston_view *pev = get_default_view(pes); |
Kristian Høgsberg | 7f366e7 | 2012-04-27 17:20:01 -0400 | [diff] [blame] | 2505 | |
Philip Withnall | becb77e | 2013-11-25 18:01:30 +0000 | [diff] [blame] | 2506 | reset_surface_type(shsurf); |
Kristian Høgsberg | 7f366e7 | 2012-04-27 17:20:01 -0400 | [diff] [blame] | 2507 | |
Rafael Antognolli | 03b1659 | 2013-12-03 15:35:42 -0200 | [diff] [blame] | 2508 | shsurf->state = shsurf->next_state; |
Rafael Antognolli | 03b1659 | 2013-12-03 15:35:42 -0200 | [diff] [blame] | 2509 | shsurf->state_changed = false; |
Kristian Høgsberg | 7f366e7 | 2012-04-27 17:20:01 -0400 | [diff] [blame] | 2510 | |
| 2511 | switch (shsurf->type) { |
| 2512 | case SHELL_SURFACE_TOPLEVEL: |
Rafael Antognolli | ed207b4 | 2013-12-03 15:35:43 -0200 | [diff] [blame] | 2513 | if (shsurf->state.maximized || shsurf->state.fullscreen) { |
Rafael Antognolli | 03b1659 | 2013-12-03 15:35:42 -0200 | [diff] [blame] | 2514 | set_full_output(shsurf); |
Rafael Antognolli | ed207b4 | 2013-12-03 15:35:43 -0200 | [diff] [blame] | 2515 | } else if (shsurf->state.relative && pev) { |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 2516 | weston_view_set_position(shsurf->view, |
| 2517 | pev->geometry.x + shsurf->transient.x, |
| 2518 | pev->geometry.y + shsurf->transient.y); |
Rafael Antognolli | ed207b4 | 2013-12-03 15:35:43 -0200 | [diff] [blame] | 2519 | } |
Rafael Antognolli | 44a3162 | 2013-12-04 18:37:16 -0200 | [diff] [blame] | 2520 | break; |
Kristian Høgsberg | 7f366e7 | 2012-04-27 17:20:01 -0400 | [diff] [blame] | 2521 | |
Tiago Vignatti | fb2adba | 2013-06-12 15:43:21 -0300 | [diff] [blame] | 2522 | case SHELL_SURFACE_XWAYLAND: |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 2523 | weston_view_set_position(shsurf->view, shsurf->transient.x, |
| 2524 | shsurf->transient.y); |
Tiago Vignatti | fb2adba | 2013-06-12 15:43:21 -0300 | [diff] [blame] | 2525 | break; |
| 2526 | |
Philip Withnall | 0f640e2 | 2013-11-25 18:01:31 +0000 | [diff] [blame] | 2527 | case SHELL_SURFACE_POPUP: |
| 2528 | case SHELL_SURFACE_NONE: |
Kristian Høgsberg | 7f366e7 | 2012-04-27 17:20:01 -0400 | [diff] [blame] | 2529 | default: |
| 2530 | break; |
| 2531 | } |
Philip Withnall | e1d75ae | 2013-11-25 18:01:41 +0000 | [diff] [blame] | 2532 | |
| 2533 | /* Update the surface’s layer. */ |
| 2534 | shell_surface_update_layer(shsurf); |
Kristian Høgsberg | 7f366e7 | 2012-04-27 17:20:01 -0400 | [diff] [blame] | 2535 | } |
| 2536 | |
Tiago Vignatti | be14326 | 2012-04-16 17:31:41 +0300 | [diff] [blame] | 2537 | static struct desktop_shell * |
Juan Zhao | 96879df | 2012-02-07 08:45:41 +0800 | [diff] [blame] | 2538 | shell_surface_get_shell(struct shell_surface *shsurf) |
Pekka Paalanen | af0e34c | 2011-12-02 10:59:17 +0200 | [diff] [blame] | 2539 | { |
Kristian Høgsberg | 02e79dc | 2012-04-12 09:55:26 -0400 | [diff] [blame] | 2540 | return shsurf->shell; |
Juan Zhao | 96879df | 2012-02-07 08:45:41 +0800 | [diff] [blame] | 2541 | } |
| 2542 | |
Alex Wu | 2185843 | 2012-04-01 20:13:08 +0800 | [diff] [blame] | 2543 | static void |
Jason Ekstrand | 918f2dd | 2013-12-02 21:01:53 -0600 | [diff] [blame] | 2544 | 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] | 2545 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 2546 | static struct weston_view * |
Alex Wu | 4539b08 | 2012-03-01 12:57:46 +0800 | [diff] [blame] | 2547 | create_black_surface(struct weston_compositor *ec, |
Alex Wu | 2185843 | 2012-04-01 20:13:08 +0800 | [diff] [blame] | 2548 | struct weston_surface *fs_surface, |
John Kåre Alsaker | 490d02a | 2012-09-30 02:57:21 +0200 | [diff] [blame] | 2549 | float x, float y, int w, int h) |
Alex Wu | 4539b08 | 2012-03-01 12:57:46 +0800 | [diff] [blame] | 2550 | { |
| 2551 | struct weston_surface *surface = NULL; |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 2552 | struct weston_view *view; |
Alex Wu | 4539b08 | 2012-03-01 12:57:46 +0800 | [diff] [blame] | 2553 | |
| 2554 | surface = weston_surface_create(ec); |
| 2555 | if (surface == NULL) { |
Martin Minarik | 6d11836 | 2012-06-07 18:01:59 +0200 | [diff] [blame] | 2556 | weston_log("no memory\n"); |
Alex Wu | 4539b08 | 2012-03-01 12:57:46 +0800 | [diff] [blame] | 2557 | return NULL; |
| 2558 | } |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 2559 | view = weston_view_create(surface); |
| 2560 | if (surface == NULL) { |
| 2561 | weston_log("no memory\n"); |
| 2562 | weston_surface_destroy(surface); |
| 2563 | return NULL; |
| 2564 | } |
Alex Wu | 4539b08 | 2012-03-01 12:57:46 +0800 | [diff] [blame] | 2565 | |
Alex Wu | 2185843 | 2012-04-01 20:13:08 +0800 | [diff] [blame] | 2566 | surface->configure = black_surface_configure; |
Giulio Camuffo | 7fe01b1 | 2013-03-28 18:02:42 +0100 | [diff] [blame] | 2567 | surface->configure_private = fs_surface; |
Alex Wu | 4539b08 | 2012-03-01 12:57:46 +0800 | [diff] [blame] | 2568 | weston_surface_set_color(surface, 0.0, 0.0, 0.0, 1); |
Pekka Paalanen | 71f6f3b | 2012-10-10 12:49:26 +0300 | [diff] [blame] | 2569 | pixman_region32_fini(&surface->opaque); |
Kristian Høgsberg | 61f00f5 | 2012-08-03 16:31:36 -0400 | [diff] [blame] | 2570 | pixman_region32_init_rect(&surface->opaque, 0, 0, w, h); |
Jonas Ådahl | 33619a4 | 2013-01-15 21:25:55 +0100 | [diff] [blame] | 2571 | pixman_region32_fini(&surface->input); |
| 2572 | pixman_region32_init_rect(&surface->input, 0, 0, w, h); |
Jason Ekstrand | 918f2dd | 2013-12-02 21:01:53 -0600 | [diff] [blame] | 2573 | |
Jason Ekstrand | 6228ee2 | 2014-01-01 15:58:57 -0600 | [diff] [blame] | 2574 | weston_surface_set_size(surface, w, h); |
Jason Ekstrand | 918f2dd | 2013-12-02 21:01:53 -0600 | [diff] [blame] | 2575 | weston_view_set_position(view, x, y); |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 2576 | |
| 2577 | return view; |
Alex Wu | 4539b08 | 2012-03-01 12:57:46 +0800 | [diff] [blame] | 2578 | } |
| 2579 | |
Philip Withnall | ed8f1a9 | 2013-11-25 18:01:43 +0000 | [diff] [blame] | 2580 | static void |
| 2581 | shell_ensure_fullscreen_black_view(struct shell_surface *shsurf) |
| 2582 | { |
| 2583 | struct weston_output *output = shsurf->fullscreen_output; |
| 2584 | |
Rafael Antognolli | 03b1659 | 2013-12-03 15:35:42 -0200 | [diff] [blame] | 2585 | assert(shsurf->state.fullscreen); |
Philip Withnall | ed8f1a9 | 2013-11-25 18:01:43 +0000 | [diff] [blame] | 2586 | |
| 2587 | if (!shsurf->fullscreen.black_view) |
| 2588 | shsurf->fullscreen.black_view = |
| 2589 | create_black_surface(shsurf->surface->compositor, |
| 2590 | shsurf->surface, |
| 2591 | output->x, output->y, |
| 2592 | output->width, |
| 2593 | output->height); |
| 2594 | |
| 2595 | weston_view_geometry_dirty(shsurf->fullscreen.black_view); |
| 2596 | wl_list_remove(&shsurf->fullscreen.black_view->layer_link); |
| 2597 | wl_list_insert(&shsurf->view->layer_link, |
| 2598 | &shsurf->fullscreen.black_view->layer_link); |
| 2599 | weston_view_geometry_dirty(shsurf->fullscreen.black_view); |
| 2600 | weston_surface_damage(shsurf->surface); |
| 2601 | } |
| 2602 | |
Alex Wu | 4539b08 | 2012-03-01 12:57:46 +0800 | [diff] [blame] | 2603 | /* Create black surface and append it to the associated fullscreen surface. |
| 2604 | * Handle size dismatch and positioning according to the method. */ |
| 2605 | static void |
| 2606 | shell_configure_fullscreen(struct shell_surface *shsurf) |
| 2607 | { |
| 2608 | struct weston_output *output = shsurf->fullscreen_output; |
| 2609 | struct weston_surface *surface = shsurf->surface; |
| 2610 | struct weston_matrix *matrix; |
Kristian Høgsberg | 240dfeb | 2012-07-12 12:32:31 -0400 | [diff] [blame] | 2611 | float scale, output_aspect, surface_aspect, x, y; |
Giulio Camuffo | b836664 | 2013-04-25 13:57:46 +0300 | [diff] [blame] | 2612 | int32_t surf_x, surf_y, surf_width, surf_height; |
Alex Wu | 4539b08 | 2012-03-01 12:57:46 +0800 | [diff] [blame] | 2613 | |
Alexander Larsson | f82b6ca | 2013-05-28 16:23:39 +0200 | [diff] [blame] | 2614 | if (shsurf->fullscreen.type != WL_SHELL_SURFACE_FULLSCREEN_METHOD_DRIVER) |
| 2615 | restore_output_mode(output); |
| 2616 | |
Philip Withnall | ed8f1a9 | 2013-11-25 18:01:43 +0000 | [diff] [blame] | 2617 | shell_ensure_fullscreen_black_view(shsurf); |
Alex Wu | 4539b08 | 2012-03-01 12:57:46 +0800 | [diff] [blame] | 2618 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 2619 | surface_subsurfaces_boundingbox(shsurf->surface, &surf_x, &surf_y, |
Giulio Camuffo | b836664 | 2013-04-25 13:57:46 +0300 | [diff] [blame] | 2620 | &surf_width, &surf_height); |
| 2621 | |
Alex Wu | 4539b08 | 2012-03-01 12:57:46 +0800 | [diff] [blame] | 2622 | switch (shsurf->fullscreen.type) { |
| 2623 | case WL_SHELL_SURFACE_FULLSCREEN_METHOD_DEFAULT: |
Pekka Paalanen | de685b8 | 2012-12-04 15:58:12 +0200 | [diff] [blame] | 2624 | if (surface->buffer_ref.buffer) |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 2625 | center_on_output(shsurf->view, shsurf->fullscreen_output); |
Alex Wu | 4539b08 | 2012-03-01 12:57:46 +0800 | [diff] [blame] | 2626 | break; |
| 2627 | case WL_SHELL_SURFACE_FULLSCREEN_METHOD_SCALE: |
Rob Bradford | 9f3dd15 | 2013-02-12 11:53:47 +0000 | [diff] [blame] | 2628 | /* 1:1 mapping between surface and output dimensions */ |
Giulio Camuffo | b836664 | 2013-04-25 13:57:46 +0300 | [diff] [blame] | 2629 | if (output->width == surf_width && |
| 2630 | output->height == surf_height) { |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 2631 | weston_view_set_position(shsurf->view, |
| 2632 | output->x - surf_x, |
| 2633 | output->y - surf_y); |
Rob Bradford | 9f3dd15 | 2013-02-12 11:53:47 +0000 | [diff] [blame] | 2634 | break; |
| 2635 | } |
| 2636 | |
Alex Wu | 4539b08 | 2012-03-01 12:57:46 +0800 | [diff] [blame] | 2637 | matrix = &shsurf->fullscreen.transform.matrix; |
| 2638 | weston_matrix_init(matrix); |
Kristian Høgsberg | 240dfeb | 2012-07-12 12:32:31 -0400 | [diff] [blame] | 2639 | |
Scott Moreau | 1bad5db | 2012-08-18 01:04:05 -0600 | [diff] [blame] | 2640 | output_aspect = (float) output->width / |
| 2641 | (float) output->height; |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 2642 | /* XXX: Use surf_width and surf_height here? */ |
| 2643 | surface_aspect = (float) surface->width / |
| 2644 | (float) surface->height; |
Kristian Høgsberg | 240dfeb | 2012-07-12 12:32:31 -0400 | [diff] [blame] | 2645 | if (output_aspect < surface_aspect) |
Scott Moreau | 1bad5db | 2012-08-18 01:04:05 -0600 | [diff] [blame] | 2646 | scale = (float) output->width / |
Giulio Camuffo | b836664 | 2013-04-25 13:57:46 +0300 | [diff] [blame] | 2647 | (float) surf_width; |
Kristian Høgsberg | 240dfeb | 2012-07-12 12:32:31 -0400 | [diff] [blame] | 2648 | else |
Scott Moreau | 1bad5db | 2012-08-18 01:04:05 -0600 | [diff] [blame] | 2649 | scale = (float) output->height / |
Giulio Camuffo | b836664 | 2013-04-25 13:57:46 +0300 | [diff] [blame] | 2650 | (float) surf_height; |
Kristian Høgsberg | 240dfeb | 2012-07-12 12:32:31 -0400 | [diff] [blame] | 2651 | |
Alex Wu | 4539b08 | 2012-03-01 12:57:46 +0800 | [diff] [blame] | 2652 | weston_matrix_scale(matrix, scale, scale, 1); |
| 2653 | wl_list_remove(&shsurf->fullscreen.transform.link); |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 2654 | wl_list_insert(&shsurf->view->geometry.transformation_list, |
Alex Wu | 4539b08 | 2012-03-01 12:57:46 +0800 | [diff] [blame] | 2655 | &shsurf->fullscreen.transform.link); |
Giulio Camuffo | b836664 | 2013-04-25 13:57:46 +0300 | [diff] [blame] | 2656 | x = output->x + (output->width - surf_width * scale) / 2 - surf_x; |
| 2657 | y = output->y + (output->height - surf_height * scale) / 2 - surf_y; |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 2658 | weston_view_set_position(shsurf->view, x, y); |
Kristian Høgsberg | 240dfeb | 2012-07-12 12:32:31 -0400 | [diff] [blame] | 2659 | |
Alex Wu | 4539b08 | 2012-03-01 12:57:46 +0800 | [diff] [blame] | 2660 | break; |
| 2661 | case WL_SHELL_SURFACE_FULLSCREEN_METHOD_DRIVER: |
Alex Wu | bd3354b | 2012-04-17 17:20:49 +0800 | [diff] [blame] | 2662 | if (shell_surface_is_top_fullscreen(shsurf)) { |
Quentin Glidic | c0d79ce | 2013-01-29 14:16:13 +0100 | [diff] [blame] | 2663 | struct weston_mode mode = {0, |
Pekka Paalanen | 1fd9c0f | 2013-11-26 18:19:41 +0100 | [diff] [blame] | 2664 | surf_width * surface->buffer_viewport.scale, |
| 2665 | surf_height * surface->buffer_viewport.scale, |
Alex Wu | bd3354b | 2012-04-17 17:20:49 +0800 | [diff] [blame] | 2666 | shsurf->fullscreen.framerate}; |
| 2667 | |
Pekka Paalanen | 1fd9c0f | 2013-11-26 18:19:41 +0100 | [diff] [blame] | 2668 | if (weston_output_switch_mode(output, &mode, surface->buffer_viewport.scale, |
Hardening | 57388e4 | 2013-09-18 23:56:36 +0200 | [diff] [blame] | 2669 | WESTON_MODE_SWITCH_SET_TEMPORARY) == 0) { |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 2670 | weston_view_set_position(shsurf->view, |
| 2671 | output->x - surf_x, |
| 2672 | output->y - surf_y); |
Jason Ekstrand | 918f2dd | 2013-12-02 21:01:53 -0600 | [diff] [blame] | 2673 | shsurf->fullscreen.black_view->surface->width = output->width; |
| 2674 | shsurf->fullscreen.black_view->surface->height = output->height; |
| 2675 | weston_view_set_position(shsurf->fullscreen.black_view, |
| 2676 | output->x - surf_x, |
| 2677 | output->y - surf_y); |
Alex Wu | bd3354b | 2012-04-17 17:20:49 +0800 | [diff] [blame] | 2678 | break; |
Alexander Larsson | d622ed3 | 2013-05-28 16:23:40 +0200 | [diff] [blame] | 2679 | } else { |
Alexander Larsson | f82b6ca | 2013-05-28 16:23:39 +0200 | [diff] [blame] | 2680 | restore_output_mode(output); |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 2681 | center_on_output(shsurf->view, output); |
Alexander Larsson | d622ed3 | 2013-05-28 16:23:40 +0200 | [diff] [blame] | 2682 | } |
Alex Wu | bd3354b | 2012-04-17 17:20:49 +0800 | [diff] [blame] | 2683 | } |
Alex Wu | 4539b08 | 2012-03-01 12:57:46 +0800 | [diff] [blame] | 2684 | break; |
| 2685 | case WL_SHELL_SURFACE_FULLSCREEN_METHOD_FILL: |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 2686 | center_on_output(shsurf->view, output); |
Alex Wu | 4539b08 | 2012-03-01 12:57:46 +0800 | [diff] [blame] | 2687 | break; |
| 2688 | default: |
| 2689 | break; |
| 2690 | } |
| 2691 | } |
| 2692 | |
Alex Wu | 4539b08 | 2012-03-01 12:57:46 +0800 | [diff] [blame] | 2693 | static void |
| 2694 | shell_map_fullscreen(struct shell_surface *shsurf) |
| 2695 | { |
Alex Wu | bd3354b | 2012-04-17 17:20:49 +0800 | [diff] [blame] | 2696 | shell_configure_fullscreen(shsurf); |
Alex Wu | 4539b08 | 2012-03-01 12:57:46 +0800 | [diff] [blame] | 2697 | } |
| 2698 | |
Kristian Høgsberg | 7a5c979 | 2011-06-18 06:12:54 -0400 | [diff] [blame] | 2699 | static void |
Tiago Vignatti | fb2adba | 2013-06-12 15:43:21 -0300 | [diff] [blame] | 2700 | set_xwayland(struct shell_surface *shsurf, int x, int y, uint32_t flags) |
| 2701 | { |
| 2702 | /* XXX: using the same fields for transient type */ |
Rafael Antognolli | 03b1659 | 2013-12-03 15:35:42 -0200 | [diff] [blame] | 2703 | surface_clear_next_states(shsurf); |
Tiago Vignatti | fb2adba | 2013-06-12 15:43:21 -0300 | [diff] [blame] | 2704 | shsurf->transient.x = x; |
| 2705 | shsurf->transient.y = y; |
| 2706 | shsurf->transient.flags = flags; |
Philip Withnall | dc4332f | 2013-11-25 18:01:38 +0000 | [diff] [blame] | 2707 | |
| 2708 | shell_surface_set_parent(shsurf, NULL); |
| 2709 | |
Kristian Høgsberg | c8f8dd8 | 2013-12-05 23:20:33 -0800 | [diff] [blame] | 2710 | shsurf->type = SHELL_SURFACE_XWAYLAND; |
Kristian Høgsberg | 8bc525c | 2014-01-01 22:34:49 -0800 | [diff] [blame] | 2711 | shsurf->state_changed = true; |
Tiago Vignatti | fb2adba | 2013-06-12 15:43:21 -0300 | [diff] [blame] | 2712 | } |
| 2713 | |
Kristian Høgsberg | 02bbabb | 2013-05-06 22:15:05 -0400 | [diff] [blame] | 2714 | static const struct weston_pointer_grab_interface popup_grab_interface; |
Giulio Camuffo | 5085a75 | 2013-03-25 21:42:45 +0100 | [diff] [blame] | 2715 | |
| 2716 | static void |
| 2717 | destroy_shell_seat(struct wl_listener *listener, void *data) |
| 2718 | { |
| 2719 | struct shell_seat *shseat = |
| 2720 | container_of(listener, |
| 2721 | struct shell_seat, seat_destroy_listener); |
| 2722 | struct shell_surface *shsurf, *prev = NULL; |
| 2723 | |
| 2724 | if (shseat->popup_grab.grab.interface == &popup_grab_interface) { |
Kristian Høgsberg | 02bbabb | 2013-05-06 22:15:05 -0400 | [diff] [blame] | 2725 | weston_pointer_end_grab(shseat->popup_grab.grab.pointer); |
Giulio Camuffo | 5085a75 | 2013-03-25 21:42:45 +0100 | [diff] [blame] | 2726 | shseat->popup_grab.client = NULL; |
| 2727 | |
| 2728 | wl_list_for_each(shsurf, &shseat->popup_grab.surfaces_list, popup.grab_link) { |
| 2729 | shsurf->popup.shseat = NULL; |
| 2730 | if (prev) { |
| 2731 | wl_list_init(&prev->popup.grab_link); |
| 2732 | } |
| 2733 | prev = shsurf; |
| 2734 | } |
| 2735 | wl_list_init(&prev->popup.grab_link); |
| 2736 | } |
| 2737 | |
| 2738 | wl_list_remove(&shseat->seat_destroy_listener.link); |
| 2739 | free(shseat); |
| 2740 | } |
| 2741 | |
| 2742 | static struct shell_seat * |
| 2743 | create_shell_seat(struct weston_seat *seat) |
| 2744 | { |
| 2745 | struct shell_seat *shseat; |
| 2746 | |
| 2747 | shseat = calloc(1, sizeof *shseat); |
| 2748 | if (!shseat) { |
| 2749 | weston_log("no memory to allocate shell seat\n"); |
| 2750 | return NULL; |
| 2751 | } |
| 2752 | |
| 2753 | shseat->seat = seat; |
| 2754 | wl_list_init(&shseat->popup_grab.surfaces_list); |
| 2755 | |
| 2756 | shseat->seat_destroy_listener.notify = destroy_shell_seat; |
| 2757 | wl_signal_add(&seat->destroy_signal, |
| 2758 | &shseat->seat_destroy_listener); |
| 2759 | |
| 2760 | return shseat; |
| 2761 | } |
| 2762 | |
| 2763 | static struct shell_seat * |
| 2764 | get_shell_seat(struct weston_seat *seat) |
| 2765 | { |
| 2766 | struct wl_listener *listener; |
| 2767 | |
| 2768 | listener = wl_signal_get(&seat->destroy_signal, destroy_shell_seat); |
| 2769 | if (listener == NULL) |
| 2770 | return create_shell_seat(seat); |
| 2771 | |
| 2772 | return container_of(listener, |
| 2773 | struct shell_seat, seat_destroy_listener); |
| 2774 | } |
| 2775 | |
Kristian Høgsberg | b810eb5 | 2013-02-12 20:07:05 -0500 | [diff] [blame] | 2776 | static void |
Kristian Høgsberg | 6848c25 | 2013-05-08 22:02:59 -0400 | [diff] [blame] | 2777 | popup_grab_focus(struct weston_pointer_grab *grab) |
Kristian Høgsberg | b3cca0a | 2012-01-04 22:19:14 -0500 | [diff] [blame] | 2778 | { |
Kristian Høgsberg | 02bbabb | 2013-05-06 22:15:05 -0400 | [diff] [blame] | 2779 | struct weston_pointer *pointer = grab->pointer; |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 2780 | struct weston_view *view; |
Giulio Camuffo | 5085a75 | 2013-03-25 21:42:45 +0100 | [diff] [blame] | 2781 | struct shell_seat *shseat = |
| 2782 | container_of(grab, struct shell_seat, popup_grab.grab); |
| 2783 | struct wl_client *client = shseat->popup_grab.client; |
Kristian Høgsberg | 6848c25 | 2013-05-08 22:02:59 -0400 | [diff] [blame] | 2784 | wl_fixed_t sx, sy; |
| 2785 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 2786 | view = weston_compositor_pick_view(pointer->seat->compositor, |
| 2787 | pointer->x, pointer->y, |
| 2788 | &sx, &sy); |
Kristian Høgsberg | b3cca0a | 2012-01-04 22:19:14 -0500 | [diff] [blame] | 2789 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 2790 | if (view && view->surface->resource && |
| 2791 | wl_resource_get_client(view->surface->resource) == client) { |
| 2792 | weston_pointer_set_focus(pointer, view, sx, sy); |
Kristian Høgsberg | b3cca0a | 2012-01-04 22:19:14 -0500 | [diff] [blame] | 2793 | } else { |
Kristian Høgsberg | 02bbabb | 2013-05-06 22:15:05 -0400 | [diff] [blame] | 2794 | weston_pointer_set_focus(pointer, NULL, |
| 2795 | wl_fixed_from_int(0), |
| 2796 | wl_fixed_from_int(0)); |
Kristian Høgsberg | b3cca0a | 2012-01-04 22:19:14 -0500 | [diff] [blame] | 2797 | } |
| 2798 | } |
| 2799 | |
| 2800 | static void |
Giulio Camuffo | 1959ab8 | 2013-11-14 23:42:52 +0100 | [diff] [blame] | 2801 | popup_grab_motion(struct weston_pointer_grab *grab, uint32_t time, |
| 2802 | wl_fixed_t x, wl_fixed_t y) |
Kristian Høgsberg | b3cca0a | 2012-01-04 22:19:14 -0500 | [diff] [blame] | 2803 | { |
Kristian Høgsberg | be6403e | 2013-05-08 21:03:21 -0400 | [diff] [blame] | 2804 | struct weston_pointer *pointer = grab->pointer; |
Neil Roberts | 96d790e | 2013-09-19 17:32:00 +0100 | [diff] [blame] | 2805 | struct wl_resource *resource; |
Kristian Høgsberg | be6403e | 2013-05-08 21:03:21 -0400 | [diff] [blame] | 2806 | wl_fixed_t sx, sy; |
Kristian Høgsberg | b3cca0a | 2012-01-04 22:19:14 -0500 | [diff] [blame] | 2807 | |
Giulio Camuffo | 1959ab8 | 2013-11-14 23:42:52 +0100 | [diff] [blame] | 2808 | weston_pointer_move(pointer, x, y); |
| 2809 | |
Neil Roberts | 96d790e | 2013-09-19 17:32:00 +0100 | [diff] [blame] | 2810 | wl_resource_for_each(resource, &pointer->focus_resource_list) { |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 2811 | weston_view_from_global_fixed(pointer->focus, |
| 2812 | pointer->x, pointer->y, |
| 2813 | &sx, &sy); |
Neil Roberts | 96d790e | 2013-09-19 17:32:00 +0100 | [diff] [blame] | 2814 | wl_pointer_send_motion(resource, time, sx, sy); |
Kristian Høgsberg | be6403e | 2013-05-08 21:03:21 -0400 | [diff] [blame] | 2815 | } |
Kristian Høgsberg | b3cca0a | 2012-01-04 22:19:14 -0500 | [diff] [blame] | 2816 | } |
| 2817 | |
| 2818 | static void |
Kristian Høgsberg | 02bbabb | 2013-05-06 22:15:05 -0400 | [diff] [blame] | 2819 | popup_grab_button(struct weston_pointer_grab *grab, |
Daniel Stone | 4dbadb1 | 2012-05-30 16:31:51 +0100 | [diff] [blame] | 2820 | uint32_t time, uint32_t button, uint32_t state_w) |
Kristian Høgsberg | b3cca0a | 2012-01-04 22:19:14 -0500 | [diff] [blame] | 2821 | { |
| 2822 | struct wl_resource *resource; |
Giulio Camuffo | 5085a75 | 2013-03-25 21:42:45 +0100 | [diff] [blame] | 2823 | struct shell_seat *shseat = |
| 2824 | container_of(grab, struct shell_seat, popup_grab.grab); |
Rob Bradford | 880ebc7 | 2013-07-22 17:31:38 +0100 | [diff] [blame] | 2825 | struct wl_display *display = shseat->seat->compositor->wl_display; |
Daniel Stone | 4dbadb1 | 2012-05-30 16:31:51 +0100 | [diff] [blame] | 2826 | enum wl_pointer_button_state state = state_w; |
Kristian Høgsberg | eae5de7 | 2012-04-11 22:42:15 -0400 | [diff] [blame] | 2827 | uint32_t serial; |
Neil Roberts | 96d790e | 2013-09-19 17:32:00 +0100 | [diff] [blame] | 2828 | struct wl_list *resource_list; |
Kristian Høgsberg | b3cca0a | 2012-01-04 22:19:14 -0500 | [diff] [blame] | 2829 | |
Neil Roberts | 96d790e | 2013-09-19 17:32:00 +0100 | [diff] [blame] | 2830 | resource_list = &grab->pointer->focus_resource_list; |
| 2831 | if (!wl_list_empty(resource_list)) { |
Kristian Høgsberg | eae5de7 | 2012-04-11 22:42:15 -0400 | [diff] [blame] | 2832 | serial = wl_display_get_serial(display); |
Neil Roberts | 96d790e | 2013-09-19 17:32:00 +0100 | [diff] [blame] | 2833 | wl_resource_for_each(resource, resource_list) { |
| 2834 | wl_pointer_send_button(resource, serial, |
| 2835 | time, button, state); |
| 2836 | } |
Daniel Stone | 4dbadb1 | 2012-05-30 16:31:51 +0100 | [diff] [blame] | 2837 | } else if (state == WL_POINTER_BUTTON_STATE_RELEASED && |
Giulio Camuffo | 5085a75 | 2013-03-25 21:42:45 +0100 | [diff] [blame] | 2838 | (shseat->popup_grab.initial_up || |
Kristian Høgsberg | e314875 | 2013-05-06 23:19:49 -0400 | [diff] [blame] | 2839 | time - shseat->seat->pointer->grab_time > 500)) { |
Kristian Høgsberg | 57e0907 | 2012-10-30 14:07:27 -0400 | [diff] [blame] | 2840 | popup_grab_end(grab->pointer); |
Kristian Høgsberg | b3cca0a | 2012-01-04 22:19:14 -0500 | [diff] [blame] | 2841 | } |
| 2842 | |
Daniel Stone | 4dbadb1 | 2012-05-30 16:31:51 +0100 | [diff] [blame] | 2843 | if (state == WL_POINTER_BUTTON_STATE_RELEASED) |
Giulio Camuffo | 5085a75 | 2013-03-25 21:42:45 +0100 | [diff] [blame] | 2844 | shseat->popup_grab.initial_up = 1; |
Kristian Høgsberg | b3cca0a | 2012-01-04 22:19:14 -0500 | [diff] [blame] | 2845 | } |
| 2846 | |
Jonas Ådahl | 1ea343e | 2013-10-25 23:18:05 +0200 | [diff] [blame] | 2847 | static void |
| 2848 | popup_grab_cancel(struct weston_pointer_grab *grab) |
| 2849 | { |
| 2850 | popup_grab_end(grab->pointer); |
| 2851 | } |
| 2852 | |
Kristian Høgsberg | 02bbabb | 2013-05-06 22:15:05 -0400 | [diff] [blame] | 2853 | static const struct weston_pointer_grab_interface popup_grab_interface = { |
Kristian Høgsberg | b3cca0a | 2012-01-04 22:19:14 -0500 | [diff] [blame] | 2854 | popup_grab_focus, |
| 2855 | popup_grab_motion, |
| 2856 | popup_grab_button, |
Jonas Ådahl | 1ea343e | 2013-10-25 23:18:05 +0200 | [diff] [blame] | 2857 | popup_grab_cancel, |
Kristian Høgsberg | b3cca0a | 2012-01-04 22:19:14 -0500 | [diff] [blame] | 2858 | }; |
| 2859 | |
| 2860 | static void |
Rafael Antognolli | e2a3455 | 2013-12-03 15:35:45 -0200 | [diff] [blame] | 2861 | shell_surface_send_popup_done(struct shell_surface *shsurf) |
| 2862 | { |
| 2863 | if (shell_surface_is_wl_shell_surface(shsurf)) |
| 2864 | wl_shell_surface_send_popup_done(shsurf->resource); |
| 2865 | else if (shell_surface_is_xdg_popup(shsurf)) |
| 2866 | xdg_popup_send_popup_done(shsurf->resource, |
| 2867 | shsurf->popup.serial); |
| 2868 | } |
| 2869 | |
| 2870 | static void |
Kristian Høgsberg | 02bbabb | 2013-05-06 22:15:05 -0400 | [diff] [blame] | 2871 | popup_grab_end(struct weston_pointer *pointer) |
Kristian Høgsberg | 57e0907 | 2012-10-30 14:07:27 -0400 | [diff] [blame] | 2872 | { |
Kristian Høgsberg | 02bbabb | 2013-05-06 22:15:05 -0400 | [diff] [blame] | 2873 | struct weston_pointer_grab *grab = pointer->grab; |
Giulio Camuffo | 5085a75 | 2013-03-25 21:42:45 +0100 | [diff] [blame] | 2874 | struct shell_seat *shseat = |
| 2875 | container_of(grab, struct shell_seat, popup_grab.grab); |
| 2876 | struct shell_surface *shsurf; |
| 2877 | struct shell_surface *prev = NULL; |
Kristian Høgsberg | 57e0907 | 2012-10-30 14:07:27 -0400 | [diff] [blame] | 2878 | |
| 2879 | if (pointer->grab->interface == &popup_grab_interface) { |
Kristian Høgsberg | 02bbabb | 2013-05-06 22:15:05 -0400 | [diff] [blame] | 2880 | weston_pointer_end_grab(grab->pointer); |
Giulio Camuffo | 5085a75 | 2013-03-25 21:42:45 +0100 | [diff] [blame] | 2881 | shseat->popup_grab.client = NULL; |
Philipp Brüschweiler | 63e7be6 | 2013-04-15 21:09:54 +0200 | [diff] [blame] | 2882 | shseat->popup_grab.grab.interface = NULL; |
| 2883 | assert(!wl_list_empty(&shseat->popup_grab.surfaces_list)); |
Giulio Camuffo | 5085a75 | 2013-03-25 21:42:45 +0100 | [diff] [blame] | 2884 | /* Send the popup_done event to all the popups open */ |
| 2885 | 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] | 2886 | shell_surface_send_popup_done(shsurf); |
Giulio Camuffo | 5085a75 | 2013-03-25 21:42:45 +0100 | [diff] [blame] | 2887 | shsurf->popup.shseat = NULL; |
| 2888 | if (prev) { |
| 2889 | wl_list_init(&prev->popup.grab_link); |
| 2890 | } |
| 2891 | prev = shsurf; |
| 2892 | } |
| 2893 | wl_list_init(&prev->popup.grab_link); |
| 2894 | wl_list_init(&shseat->popup_grab.surfaces_list); |
| 2895 | } |
| 2896 | } |
| 2897 | |
| 2898 | static void |
| 2899 | add_popup_grab(struct shell_surface *shsurf, struct shell_seat *shseat) |
| 2900 | { |
Kristian Høgsberg | e314875 | 2013-05-06 23:19:49 -0400 | [diff] [blame] | 2901 | struct weston_seat *seat = shseat->seat; |
Giulio Camuffo | 5085a75 | 2013-03-25 21:42:45 +0100 | [diff] [blame] | 2902 | |
| 2903 | if (wl_list_empty(&shseat->popup_grab.surfaces_list)) { |
Jason Ekstrand | 651f00e | 2013-06-14 10:07:54 -0500 | [diff] [blame] | 2904 | shseat->popup_grab.client = wl_resource_get_client(shsurf->resource); |
Giulio Camuffo | 5085a75 | 2013-03-25 21:42:45 +0100 | [diff] [blame] | 2905 | shseat->popup_grab.grab.interface = &popup_grab_interface; |
Giulio Camuffo | 1b4b61a | 2013-03-27 18:05:26 +0100 | [diff] [blame] | 2906 | /* We must make sure here that this popup was opened after |
| 2907 | * a mouse press, and not just by moving around with other |
| 2908 | * popups already open. */ |
Kristian Høgsberg | e314875 | 2013-05-06 23:19:49 -0400 | [diff] [blame] | 2909 | if (shseat->seat->pointer->button_count > 0) |
Giulio Camuffo | 1b4b61a | 2013-03-27 18:05:26 +0100 | [diff] [blame] | 2910 | shseat->popup_grab.initial_up = 0; |
Giulio Camuffo | 5085a75 | 2013-03-25 21:42:45 +0100 | [diff] [blame] | 2911 | |
Rob Bradford | dfe3105 | 2013-06-26 19:49:11 +0100 | [diff] [blame] | 2912 | 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] | 2913 | weston_pointer_start_grab(seat->pointer, &shseat->popup_grab.grab); |
Rob Bradford | dfe3105 | 2013-06-26 19:49:11 +0100 | [diff] [blame] | 2914 | } else { |
| 2915 | wl_list_insert(&shseat->popup_grab.surfaces_list, &shsurf->popup.grab_link); |
Giulio Camuffo | 5085a75 | 2013-03-25 21:42:45 +0100 | [diff] [blame] | 2916 | } |
Giulio Camuffo | 5085a75 | 2013-03-25 21:42:45 +0100 | [diff] [blame] | 2917 | } |
| 2918 | |
| 2919 | static void |
| 2920 | remove_popup_grab(struct shell_surface *shsurf) |
| 2921 | { |
| 2922 | struct shell_seat *shseat = shsurf->popup.shseat; |
| 2923 | |
| 2924 | wl_list_remove(&shsurf->popup.grab_link); |
| 2925 | wl_list_init(&shsurf->popup.grab_link); |
| 2926 | if (wl_list_empty(&shseat->popup_grab.surfaces_list)) { |
Kristian Høgsberg | 02bbabb | 2013-05-06 22:15:05 -0400 | [diff] [blame] | 2927 | weston_pointer_end_grab(shseat->popup_grab.grab.pointer); |
Philipp Brüschweiler | 63e7be6 | 2013-04-15 21:09:54 +0200 | [diff] [blame] | 2928 | shseat->popup_grab.grab.interface = NULL; |
Kristian Høgsberg | 57e0907 | 2012-10-30 14:07:27 -0400 | [diff] [blame] | 2929 | } |
| 2930 | } |
| 2931 | |
| 2932 | static void |
Kristian Høgsberg | 3730f36 | 2012-04-13 12:40:07 -0400 | [diff] [blame] | 2933 | shell_map_popup(struct shell_surface *shsurf) |
Kristian Høgsberg | b3cca0a | 2012-01-04 22:19:14 -0500 | [diff] [blame] | 2934 | { |
Giulio Camuffo | 5085a75 | 2013-03-25 21:42:45 +0100 | [diff] [blame] | 2935 | struct shell_seat *shseat = shsurf->popup.shseat; |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 2936 | struct weston_view *parent_view = get_default_view(shsurf->parent); |
Kristian Høgsberg | b3cca0a | 2012-01-04 22:19:14 -0500 | [diff] [blame] | 2937 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 2938 | shsurf->surface->output = parent_view->output; |
| 2939 | shsurf->view->output = parent_view->output; |
Kristian Høgsberg | b3cca0a | 2012-01-04 22:19:14 -0500 | [diff] [blame] | 2940 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 2941 | weston_view_set_transform_parent(shsurf->view, parent_view); |
| 2942 | weston_view_set_position(shsurf->view, shsurf->popup.x, shsurf->popup.y); |
| 2943 | weston_view_update_transform(shsurf->view); |
Kristian Høgsberg | b3cca0a | 2012-01-04 22:19:14 -0500 | [diff] [blame] | 2944 | |
Kristian Høgsberg | e314875 | 2013-05-06 23:19:49 -0400 | [diff] [blame] | 2945 | if (shseat->seat->pointer->grab_serial == shsurf->popup.serial) { |
Giulio Camuffo | 5085a75 | 2013-03-25 21:42:45 +0100 | [diff] [blame] | 2946 | add_popup_grab(shsurf, shseat); |
Kristian Høgsberg | 3730f36 | 2012-04-13 12:40:07 -0400 | [diff] [blame] | 2947 | } else { |
Rafael Antognolli | e2a3455 | 2013-12-03 15:35:45 -0200 | [diff] [blame] | 2948 | shell_surface_send_popup_done(shsurf); |
Giulio Camuffo | 5085a75 | 2013-03-25 21:42:45 +0100 | [diff] [blame] | 2949 | shseat->popup_grab.client = NULL; |
Kristian Høgsberg | 3730f36 | 2012-04-13 12:40:07 -0400 | [diff] [blame] | 2950 | } |
Kristian Høgsberg | b3cca0a | 2012-01-04 22:19:14 -0500 | [diff] [blame] | 2951 | } |
| 2952 | |
Pekka Paalanen | 9d1613e | 2011-11-25 12:09:16 +0200 | [diff] [blame] | 2953 | static const struct wl_shell_surface_interface shell_surface_implementation = { |
Scott Moreau | ff1db4a | 2012-04-17 19:06:18 -0600 | [diff] [blame] | 2954 | shell_surface_pong, |
Pekka Paalanen | 9d1613e | 2011-11-25 12:09:16 +0200 | [diff] [blame] | 2955 | shell_surface_move, |
| 2956 | shell_surface_resize, |
| 2957 | shell_surface_set_toplevel, |
| 2958 | shell_surface_set_transient, |
Kristian Høgsberg | b3cca0a | 2012-01-04 22:19:14 -0500 | [diff] [blame] | 2959 | shell_surface_set_fullscreen, |
Juan Zhao | 96879df | 2012-02-07 08:45:41 +0800 | [diff] [blame] | 2960 | shell_surface_set_popup, |
Kristian Høgsberg | e7afd91 | 2012-05-02 09:47:44 -0400 | [diff] [blame] | 2961 | shell_surface_set_maximized, |
| 2962 | shell_surface_set_title, |
| 2963 | shell_surface_set_class |
Pekka Paalanen | 9d1613e | 2011-11-25 12:09:16 +0200 | [diff] [blame] | 2964 | }; |
| 2965 | |
| 2966 | static void |
Tiago Vignatti | bc052c9 | 2012-04-19 16:18:18 +0300 | [diff] [blame] | 2967 | destroy_shell_surface(struct shell_surface *shsurf) |
Pekka Paalanen | 9d1613e | 2011-11-25 12:09:16 +0200 | [diff] [blame] | 2968 | { |
Kristian Høgsberg | 9046d24 | 2014-01-10 00:25:30 -0800 | [diff] [blame] | 2969 | struct shell_surface *child, *next; |
| 2970 | |
Jason Ekstrand | 651f00e | 2013-06-14 10:07:54 -0500 | [diff] [blame] | 2971 | wl_signal_emit(&shsurf->destroy_signal, shsurf); |
| 2972 | |
Giulio Camuffo | 5085a75 | 2013-03-25 21:42:45 +0100 | [diff] [blame] | 2973 | if (!wl_list_empty(&shsurf->popup.grab_link)) { |
| 2974 | remove_popup_grab(shsurf); |
| 2975 | } |
Kristian Høgsberg | b3cca0a | 2012-01-04 22:19:14 -0500 | [diff] [blame] | 2976 | |
Alex Wu | bd3354b | 2012-04-17 17:20:49 +0800 | [diff] [blame] | 2977 | if (shsurf->fullscreen.type == WL_SHELL_SURFACE_FULLSCREEN_METHOD_DRIVER && |
Alexander Larsson | f82b6ca | 2013-05-28 16:23:39 +0200 | [diff] [blame] | 2978 | shell_surface_is_top_fullscreen(shsurf)) |
| 2979 | restore_output_mode (shsurf->fullscreen_output); |
Pekka Paalanen | 9d1613e | 2011-11-25 12:09:16 +0200 | [diff] [blame] | 2980 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 2981 | if (shsurf->fullscreen.black_view) |
| 2982 | weston_surface_destroy(shsurf->fullscreen.black_view->surface); |
Alex Wu | aa08e2d | 2012-03-05 11:01:40 +0800 | [diff] [blame] | 2983 | |
Alex Wu | bd3354b | 2012-04-17 17:20:49 +0800 | [diff] [blame] | 2984 | /* As destroy_resource() use wl_list_for_each_safe(), |
| 2985 | * we can always remove the listener. |
| 2986 | */ |
| 2987 | wl_list_remove(&shsurf->surface_destroy_listener.link); |
| 2988 | shsurf->surface->configure = NULL; |
Scott Moreau | 976a050 | 2013-03-07 10:15:17 -0700 | [diff] [blame] | 2989 | free(shsurf->title); |
Alex Wu | bd3354b | 2012-04-17 17:20:49 +0800 | [diff] [blame] | 2990 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 2991 | weston_view_destroy(shsurf->view); |
| 2992 | |
Philip Withnall | 648a4dd | 2013-11-25 18:01:44 +0000 | [diff] [blame] | 2993 | wl_list_remove(&shsurf->children_link); |
Emilio Pozuelo Monfort | adaa20c | 2014-01-28 13:54:16 +0100 | [diff] [blame] | 2994 | wl_list_for_each_safe(child, next, &shsurf->children_list, children_link) |
| 2995 | shell_surface_set_parent(child, NULL); |
Philip Withnall | 648a4dd | 2013-11-25 18:01:44 +0000 | [diff] [blame] | 2996 | |
Pekka Paalanen | 9d1613e | 2011-11-25 12:09:16 +0200 | [diff] [blame] | 2997 | wl_list_remove(&shsurf->link); |
| 2998 | free(shsurf); |
| 2999 | } |
| 3000 | |
| 3001 | static void |
Tiago Vignatti | bc052c9 | 2012-04-19 16:18:18 +0300 | [diff] [blame] | 3002 | shell_destroy_shell_surface(struct wl_resource *resource) |
| 3003 | { |
Jason Ekstrand | 651f00e | 2013-06-14 10:07:54 -0500 | [diff] [blame] | 3004 | struct shell_surface *shsurf = wl_resource_get_user_data(resource); |
Tiago Vignatti | bc052c9 | 2012-04-19 16:18:18 +0300 | [diff] [blame] | 3005 | |
Kristian Høgsberg | 160fe75 | 2014-03-11 10:19:10 -0700 | [diff] [blame^] | 3006 | shsurf->resource = NULL; |
Tiago Vignatti | bc052c9 | 2012-04-19 16:18:18 +0300 | [diff] [blame] | 3007 | } |
| 3008 | |
| 3009 | static void |
Kristian Høgsberg | 27e3052 | 2012-04-11 23:18:23 -0400 | [diff] [blame] | 3010 | shell_handle_surface_destroy(struct wl_listener *listener, void *data) |
Pekka Paalanen | 9d1613e | 2011-11-25 12:09:16 +0200 | [diff] [blame] | 3011 | { |
| 3012 | struct shell_surface *shsurf = container_of(listener, |
| 3013 | struct shell_surface, |
| 3014 | surface_destroy_listener); |
| 3015 | |
Jason Ekstrand | 651f00e | 2013-06-14 10:07:54 -0500 | [diff] [blame] | 3016 | if (shsurf->resource) |
| 3017 | wl_resource_destroy(shsurf->resource); |
| 3018 | else |
Tiago Vignatti | bc052c9 | 2012-04-19 16:18:18 +0300 | [diff] [blame] | 3019 | destroy_shell_surface(shsurf); |
Pekka Paalanen | 9d1613e | 2011-11-25 12:09:16 +0200 | [diff] [blame] | 3020 | } |
| 3021 | |
Kristian Høgsberg | d813445 | 2012-06-21 12:49:02 -0400 | [diff] [blame] | 3022 | static void |
Kristian Høgsberg | 160fe75 | 2014-03-11 10:19:10 -0700 | [diff] [blame^] | 3023 | fade_out_done(struct weston_view_animation *animation, void *data) |
| 3024 | { |
| 3025 | struct shell_surface *shsurf = data; |
| 3026 | |
| 3027 | weston_surface_destroy(shsurf->surface); |
| 3028 | } |
| 3029 | |
| 3030 | static void |
| 3031 | handle_resource_destroy(struct wl_listener *listener, void *data) |
| 3032 | { |
| 3033 | struct shell_surface *shsurf = |
| 3034 | container_of(listener, struct shell_surface, |
| 3035 | resource_destroy_listener); |
| 3036 | |
| 3037 | shsurf->surface->ref_count++; |
| 3038 | |
| 3039 | pixman_region32_fini(&shsurf->surface->pending.input); |
| 3040 | pixman_region32_init(&shsurf->surface->pending.input); |
| 3041 | pixman_region32_fini(&shsurf->surface->input); |
| 3042 | pixman_region32_init(&shsurf->surface->input); |
| 3043 | weston_fade_run(shsurf->view, 1.0, 0.0, 300.0, fade_out_done, shsurf); |
| 3044 | } |
| 3045 | |
| 3046 | static void |
Jason Ekstrand | 918f2dd | 2013-12-02 21:01:53 -0600 | [diff] [blame] | 3047 | shell_surface_configure(struct weston_surface *, int32_t, int32_t); |
Kristian Høgsberg | d813445 | 2012-06-21 12:49:02 -0400 | [diff] [blame] | 3048 | |
Kristian Høgsberg | 1ef2313 | 2013-12-04 00:20:01 -0800 | [diff] [blame] | 3049 | struct shell_surface * |
Kristian Høgsberg | 8334bc1 | 2012-01-03 10:29:47 -0500 | [diff] [blame] | 3050 | get_shell_surface(struct weston_surface *surface) |
Pekka Paalanen | ec2b32f | 2011-11-28 15:12:34 +0200 | [diff] [blame] | 3051 | { |
Kristian Høgsberg | d813445 | 2012-06-21 12:49:02 -0400 | [diff] [blame] | 3052 | if (surface->configure == shell_surface_configure) |
Giulio Camuffo | 7fe01b1 | 2013-03-28 18:02:42 +0100 | [diff] [blame] | 3053 | return surface->configure_private; |
Kristian Høgsberg | d813445 | 2012-06-21 12:49:02 -0400 | [diff] [blame] | 3054 | else |
| 3055 | return NULL; |
Pekka Paalanen | ec2b32f | 2011-11-28 15:12:34 +0200 | [diff] [blame] | 3056 | } |
| 3057 | |
Rafael Antognolli | e2a3455 | 2013-12-03 15:35:45 -0200 | [diff] [blame] | 3058 | static struct shell_surface * |
| 3059 | create_common_surface(void *shell, struct weston_surface *surface, |
| 3060 | const struct weston_shell_client *client) |
Pekka Paalanen | 9d1613e | 2011-11-25 12:09:16 +0200 | [diff] [blame] | 3061 | { |
Pekka Paalanen | 9d1613e | 2011-11-25 12:09:16 +0200 | [diff] [blame] | 3062 | struct shell_surface *shsurf; |
| 3063 | |
Ander Conselvan de Oliveira | 093bfa3 | 2012-03-27 17:36:41 +0300 | [diff] [blame] | 3064 | if (surface->configure) { |
Martin Minarik | 6d11836 | 2012-06-07 18:01:59 +0200 | [diff] [blame] | 3065 | weston_log("surface->configure already set\n"); |
Kristian Høgsberg | 45ba869 | 2012-05-21 14:27:33 -0400 | [diff] [blame] | 3066 | return NULL; |
Ander Conselvan de Oliveira | 093bfa3 | 2012-03-27 17:36:41 +0300 | [diff] [blame] | 3067 | } |
| 3068 | |
Pekka Paalanen | 9d1613e | 2011-11-25 12:09:16 +0200 | [diff] [blame] | 3069 | shsurf = calloc(1, sizeof *shsurf); |
| 3070 | if (!shsurf) { |
Martin Minarik | 6d11836 | 2012-06-07 18:01:59 +0200 | [diff] [blame] | 3071 | weston_log("no memory to allocate shell surface\n"); |
Kristian Høgsberg | 45ba869 | 2012-05-21 14:27:33 -0400 | [diff] [blame] | 3072 | return NULL; |
Pekka Paalanen | 9d1613e | 2011-11-25 12:09:16 +0200 | [diff] [blame] | 3073 | } |
| 3074 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 3075 | shsurf->view = weston_view_create(surface); |
| 3076 | if (!shsurf->view) { |
| 3077 | weston_log("no memory to allocate shell surface\n"); |
| 3078 | free(shsurf); |
| 3079 | return NULL; |
| 3080 | } |
| 3081 | |
Ander Conselvan de Oliveira | 093bfa3 | 2012-03-27 17:36:41 +0300 | [diff] [blame] | 3082 | surface->configure = shell_surface_configure; |
Giulio Camuffo | 7fe01b1 | 2013-03-28 18:02:42 +0100 | [diff] [blame] | 3083 | surface->configure_private = shsurf; |
Ander Conselvan de Oliveira | 093bfa3 | 2012-03-27 17:36:41 +0300 | [diff] [blame] | 3084 | |
Kristian Høgsberg | 160fe75 | 2014-03-11 10:19:10 -0700 | [diff] [blame^] | 3085 | shsurf->resource_destroy_listener.notify = handle_resource_destroy; |
| 3086 | wl_resource_add_destroy_listener(surface->resource, |
| 3087 | &shsurf->resource_destroy_listener); |
| 3088 | |
Tiago Vignatti | bc052c9 | 2012-04-19 16:18:18 +0300 | [diff] [blame] | 3089 | shsurf->shell = (struct desktop_shell *) shell; |
Scott Moreau | ff1db4a | 2012-04-17 19:06:18 -0600 | [diff] [blame] | 3090 | shsurf->unresponsive = 0; |
Alex Wu | 4539b08 | 2012-03-01 12:57:46 +0800 | [diff] [blame] | 3091 | shsurf->saved_position_valid = false; |
Rafael Antognolli | 3c4e3f7 | 2013-12-03 15:35:46 -0200 | [diff] [blame] | 3092 | shsurf->saved_size_valid = false; |
Alex Wu | 7bcb8bd | 2012-04-27 09:07:24 +0800 | [diff] [blame] | 3093 | shsurf->saved_rotation_valid = false; |
Pekka Paalanen | 9d1613e | 2011-11-25 12:09:16 +0200 | [diff] [blame] | 3094 | shsurf->surface = surface; |
Alex Wu | 4539b08 | 2012-03-01 12:57:46 +0800 | [diff] [blame] | 3095 | shsurf->fullscreen.type = WL_SHELL_SURFACE_FULLSCREEN_METHOD_DEFAULT; |
| 3096 | shsurf->fullscreen.framerate = 0; |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 3097 | shsurf->fullscreen.black_view = NULL; |
Alex Wu | 4539b08 | 2012-03-01 12:57:46 +0800 | [diff] [blame] | 3098 | wl_list_init(&shsurf->fullscreen.transform.link); |
| 3099 | |
Jason Ekstrand | 651f00e | 2013-06-14 10:07:54 -0500 | [diff] [blame] | 3100 | wl_signal_init(&shsurf->destroy_signal); |
Kristian Høgsberg | 27e3052 | 2012-04-11 23:18:23 -0400 | [diff] [blame] | 3101 | shsurf->surface_destroy_listener.notify = shell_handle_surface_destroy; |
Jason Ekstrand | 26ed73c | 2013-06-06 22:34:41 -0500 | [diff] [blame] | 3102 | wl_signal_add(&surface->destroy_signal, |
Kristian Høgsberg | 27e3052 | 2012-04-11 23:18:23 -0400 | [diff] [blame] | 3103 | &shsurf->surface_destroy_listener); |
Pekka Paalanen | 9d1613e | 2011-11-25 12:09:16 +0200 | [diff] [blame] | 3104 | |
| 3105 | /* init link so its safe to always remove it in destroy_shell_surface */ |
| 3106 | wl_list_init(&shsurf->link); |
Giulio Camuffo | 5085a75 | 2013-03-25 21:42:45 +0100 | [diff] [blame] | 3107 | wl_list_init(&shsurf->popup.grab_link); |
Pekka Paalanen | 9d1613e | 2011-11-25 12:09:16 +0200 | [diff] [blame] | 3108 | |
Pekka Paalanen | 460099f | 2012-01-20 16:48:25 +0200 | [diff] [blame] | 3109 | /* empty when not in use */ |
| 3110 | wl_list_init(&shsurf->rotation.transform.link); |
Kristian Høgsberg | 765e27b | 2012-01-27 13:36:13 -0500 | [diff] [blame] | 3111 | weston_matrix_init(&shsurf->rotation.rotation); |
Pekka Paalanen | 460099f | 2012-01-20 16:48:25 +0200 | [diff] [blame] | 3112 | |
Jonas Ådahl | 62fcd04 | 2012-06-13 00:01:23 +0200 | [diff] [blame] | 3113 | wl_list_init(&shsurf->workspace_transform.link); |
| 3114 | |
Philip Withnall | 648a4dd | 2013-11-25 18:01:44 +0000 | [diff] [blame] | 3115 | wl_list_init(&shsurf->children_link); |
| 3116 | wl_list_init(&shsurf->children_list); |
| 3117 | shsurf->parent = NULL; |
| 3118 | |
Pekka Paalanen | 9826223 | 2011-12-01 10:42:22 +0200 | [diff] [blame] | 3119 | shsurf->type = SHELL_SURFACE_NONE; |
Pekka Paalanen | 9d1613e | 2011-11-25 12:09:16 +0200 | [diff] [blame] | 3120 | |
Kristian Høgsberg | a61ca06 | 2012-05-22 16:05:52 -0400 | [diff] [blame] | 3121 | shsurf->client = client; |
| 3122 | |
Kristian Høgsberg | 45ba869 | 2012-05-21 14:27:33 -0400 | [diff] [blame] | 3123 | return shsurf; |
Tiago Vignatti | bc052c9 | 2012-04-19 16:18:18 +0300 | [diff] [blame] | 3124 | } |
| 3125 | |
Rafael Antognolli | e2a3455 | 2013-12-03 15:35:45 -0200 | [diff] [blame] | 3126 | static struct shell_surface * |
| 3127 | create_shell_surface(void *shell, struct weston_surface *surface, |
| 3128 | const struct weston_shell_client *client) |
| 3129 | { |
Kristian Høgsberg | c8f8dd8 | 2013-12-05 23:20:33 -0800 | [diff] [blame] | 3130 | return create_common_surface(shell, surface, client); |
Rafael Antognolli | e2a3455 | 2013-12-03 15:35:45 -0200 | [diff] [blame] | 3131 | } |
| 3132 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 3133 | static struct weston_view * |
| 3134 | get_primary_view(void *shell, struct shell_surface *shsurf) |
| 3135 | { |
| 3136 | return shsurf->view; |
| 3137 | } |
| 3138 | |
Tiago Vignatti | bc052c9 | 2012-04-19 16:18:18 +0300 | [diff] [blame] | 3139 | static void |
| 3140 | shell_get_shell_surface(struct wl_client *client, |
| 3141 | struct wl_resource *resource, |
| 3142 | uint32_t id, |
| 3143 | struct wl_resource *surface_resource) |
| 3144 | { |
Jason Ekstrand | 0f2ef7e | 2013-06-14 10:07:53 -0500 | [diff] [blame] | 3145 | struct weston_surface *surface = |
| 3146 | wl_resource_get_user_data(surface_resource); |
Jason Ekstrand | 651f00e | 2013-06-14 10:07:54 -0500 | [diff] [blame] | 3147 | struct desktop_shell *shell = wl_resource_get_user_data(resource); |
Tiago Vignatti | bc052c9 | 2012-04-19 16:18:18 +0300 | [diff] [blame] | 3148 | struct shell_surface *shsurf; |
| 3149 | |
| 3150 | if (get_shell_surface(surface)) { |
| 3151 | wl_resource_post_error(surface_resource, |
Kristian Høgsberg | 9540ea6 | 2012-05-21 14:28:57 -0400 | [diff] [blame] | 3152 | WL_DISPLAY_ERROR_INVALID_OBJECT, |
| 3153 | "desktop_shell::get_shell_surface already requested"); |
Tiago Vignatti | bc052c9 | 2012-04-19 16:18:18 +0300 | [diff] [blame] | 3154 | return; |
| 3155 | } |
| 3156 | |
Kristian Høgsberg | a61ca06 | 2012-05-22 16:05:52 -0400 | [diff] [blame] | 3157 | shsurf = create_shell_surface(shell, surface, &shell_client); |
Kristian Høgsberg | 9540ea6 | 2012-05-21 14:28:57 -0400 | [diff] [blame] | 3158 | if (!shsurf) { |
| 3159 | wl_resource_post_error(surface_resource, |
| 3160 | WL_DISPLAY_ERROR_INVALID_OBJECT, |
| 3161 | "surface->configure already set"); |
| 3162 | return; |
| 3163 | } |
Tiago Vignatti | bc052c9 | 2012-04-19 16:18:18 +0300 | [diff] [blame] | 3164 | |
Jason Ekstrand | a85118c | 2013-06-27 20:17:02 -0500 | [diff] [blame] | 3165 | shsurf->resource = |
| 3166 | wl_resource_create(client, |
| 3167 | &wl_shell_surface_interface, 1, id); |
| 3168 | wl_resource_set_implementation(shsurf->resource, |
| 3169 | &shell_surface_implementation, |
| 3170 | shsurf, shell_destroy_shell_surface); |
Pekka Paalanen | 9d1613e | 2011-11-25 12:09:16 +0200 | [diff] [blame] | 3171 | } |
| 3172 | |
Rafael Antognolli | e2a3455 | 2013-12-03 15:35:45 -0200 | [diff] [blame] | 3173 | static bool |
| 3174 | shell_surface_is_wl_shell_surface(struct shell_surface *shsurf) |
| 3175 | { |
Kristian Høgsberg | 0b7d995 | 2014-02-03 15:50:38 -0800 | [diff] [blame] | 3176 | /* A shell surface without a resource is created from xwayland |
| 3177 | * and is considered a wl_shell surface for now. */ |
| 3178 | |
| 3179 | return shsurf->resource == NULL || |
| 3180 | wl_resource_instance_of(shsurf->resource, |
| 3181 | &wl_shell_surface_interface, |
| 3182 | &shell_surface_implementation); |
Rafael Antognolli | e2a3455 | 2013-12-03 15:35:45 -0200 | [diff] [blame] | 3183 | } |
| 3184 | |
Pekka Paalanen | 9d1613e | 2011-11-25 12:09:16 +0200 | [diff] [blame] | 3185 | static const struct wl_shell_interface shell_implementation = { |
Pekka Paalanen | 4622967 | 2011-11-29 15:49:31 +0200 | [diff] [blame] | 3186 | shell_get_shell_surface |
Kristian Høgsberg | 4cca349 | 2011-01-18 07:53:49 -0500 | [diff] [blame] | 3187 | }; |
| 3188 | |
Rafael Antognolli | e2a3455 | 2013-12-03 15:35:45 -0200 | [diff] [blame] | 3189 | /**************************** |
| 3190 | * xdg-shell implementation */ |
| 3191 | |
| 3192 | static void |
| 3193 | xdg_surface_destroy(struct wl_client *client, |
| 3194 | struct wl_resource *resource) |
| 3195 | { |
| 3196 | wl_resource_destroy(resource); |
| 3197 | } |
| 3198 | |
| 3199 | static void |
Jasper St. Pierre | 63a9c33 | 2014-02-01 18:35:15 -0500 | [diff] [blame] | 3200 | xdg_surface_set_transient_for(struct wl_client *client, |
| 3201 | struct wl_resource *resource, |
| 3202 | struct wl_resource *parent_resource) |
| 3203 | { |
| 3204 | struct shell_surface *shsurf = wl_resource_get_user_data(resource); |
| 3205 | struct weston_surface *parent; |
| 3206 | |
| 3207 | if (parent_resource) |
| 3208 | parent = wl_resource_get_user_data(parent_resource); |
| 3209 | else |
| 3210 | parent = NULL; |
| 3211 | |
| 3212 | shell_surface_set_parent(shsurf, parent); |
| 3213 | } |
| 3214 | |
| 3215 | static void |
Jasper St. Pierre | 7407345 | 2014-02-01 18:36:41 -0500 | [diff] [blame] | 3216 | xdg_surface_set_margin(struct wl_client *client, |
| 3217 | struct wl_resource *resource, |
| 3218 | int32_t left, |
| 3219 | int32_t right, |
| 3220 | int32_t top, |
| 3221 | int32_t bottom) |
| 3222 | { |
| 3223 | /* Do nothing, Weston doesn't try to constrain or place |
| 3224 | * surfaces in any special manner... */ |
| 3225 | } |
| 3226 | |
| 3227 | static void |
Rafael Antognolli | e2a3455 | 2013-12-03 15:35:45 -0200 | [diff] [blame] | 3228 | xdg_surface_set_app_id(struct wl_client *client, |
| 3229 | struct wl_resource *resource, |
| 3230 | const char *app_id) |
| 3231 | { |
| 3232 | struct shell_surface *shsurf = wl_resource_get_user_data(resource); |
| 3233 | |
| 3234 | free(shsurf->class); |
| 3235 | shsurf->class = strdup(app_id); |
| 3236 | } |
| 3237 | |
| 3238 | static void |
| 3239 | xdg_surface_set_title(struct wl_client *client, |
| 3240 | struct wl_resource *resource, const char *title) |
| 3241 | { |
| 3242 | struct shell_surface *shsurf = wl_resource_get_user_data(resource); |
| 3243 | |
| 3244 | set_title(shsurf, title); |
| 3245 | } |
| 3246 | |
| 3247 | static void |
| 3248 | xdg_surface_move(struct wl_client *client, struct wl_resource *resource, |
| 3249 | struct wl_resource *seat_resource, uint32_t serial) |
| 3250 | { |
| 3251 | common_surface_move(resource, seat_resource, serial); |
| 3252 | } |
| 3253 | |
| 3254 | static void |
| 3255 | xdg_surface_resize(struct wl_client *client, struct wl_resource *resource, |
| 3256 | struct wl_resource *seat_resource, uint32_t serial, |
| 3257 | uint32_t edges) |
| 3258 | { |
| 3259 | common_surface_resize(resource, seat_resource, serial, edges); |
| 3260 | } |
| 3261 | |
| 3262 | static void |
| 3263 | xdg_surface_set_output(struct wl_client *client, |
| 3264 | struct wl_resource *resource, |
| 3265 | struct wl_resource *output_resource) |
| 3266 | { |
| 3267 | struct shell_surface *shsurf = wl_resource_get_user_data(resource); |
| 3268 | struct weston_output *output; |
| 3269 | |
| 3270 | if (output_resource) |
| 3271 | output = wl_resource_get_user_data(output_resource); |
| 3272 | else |
| 3273 | output = NULL; |
| 3274 | |
Rafael Antognolli | 65f98d8 | 2013-12-03 15:35:47 -0200 | [diff] [blame] | 3275 | shsurf->recommended_output = output; |
Rafael Antognolli | e2a3455 | 2013-12-03 15:35:45 -0200 | [diff] [blame] | 3276 | } |
| 3277 | |
| 3278 | static void |
Kristian Høgsberg | 283bf37 | 2014-02-18 23:28:09 -0800 | [diff] [blame] | 3279 | xdg_surface_change_state(struct shell_surface *shsurf, |
| 3280 | uint32_t state, uint32_t value, uint32_t serial) |
Rafael Antognolli | e2a3455 | 2013-12-03 15:35:45 -0200 | [diff] [blame] | 3281 | { |
Kristian Høgsberg | 283bf37 | 2014-02-18 23:28:09 -0800 | [diff] [blame] | 3282 | xdg_surface_send_change_state(shsurf->resource, state, value, serial); |
Jasper St. Pierre | 8c6aa45 | 2014-02-08 18:29:49 -0500 | [diff] [blame] | 3283 | shsurf->state_requested = true; |
Rafael Antognolli | e2a3455 | 2013-12-03 15:35:45 -0200 | [diff] [blame] | 3284 | |
Kristian Høgsberg | 283bf37 | 2014-02-18 23:28:09 -0800 | [diff] [blame] | 3285 | switch (state) { |
| 3286 | case XDG_SURFACE_STATE_MAXIMIZED: |
| 3287 | shsurf->requested_state.maximized = value; |
| 3288 | if (value) |
| 3289 | set_maximized(shsurf, NULL); |
| 3290 | break; |
| 3291 | case XDG_SURFACE_STATE_FULLSCREEN: |
| 3292 | shsurf->requested_state.fullscreen = value; |
Rafael Antognolli | e2a3455 | 2013-12-03 15:35:45 -0200 | [diff] [blame] | 3293 | |
Kristian Høgsberg | 283bf37 | 2014-02-18 23:28:09 -0800 | [diff] [blame] | 3294 | if (value) |
| 3295 | set_fullscreen(shsurf, |
| 3296 | WL_SHELL_SURFACE_FULLSCREEN_METHOD_DEFAULT, |
| 3297 | 0, shsurf->recommended_output); |
| 3298 | break; |
| 3299 | } |
Jasper St. Pierre | 8c6aa45 | 2014-02-08 18:29:49 -0500 | [diff] [blame] | 3300 | } |
| 3301 | |
| 3302 | static void |
| 3303 | xdg_surface_request_change_state(struct wl_client *client, |
| 3304 | struct wl_resource *resource, |
| 3305 | uint32_t state, |
| 3306 | uint32_t value, |
| 3307 | uint32_t serial) |
Rafael Antognolli | e2a3455 | 2013-12-03 15:35:45 -0200 | [diff] [blame] | 3308 | { |
| 3309 | struct shell_surface *shsurf = wl_resource_get_user_data(resource); |
Jasper St. Pierre | 8c6aa45 | 2014-02-08 18:29:49 -0500 | [diff] [blame] | 3310 | |
| 3311 | /* The client can't know what the current state is, so we need |
| 3312 | to always send a state change in response. */ |
Rafael Antognolli | e2a3455 | 2013-12-03 15:35:45 -0200 | [diff] [blame] | 3313 | |
| 3314 | if (shsurf->type != SHELL_SURFACE_TOPLEVEL) |
| 3315 | return; |
| 3316 | |
Jasper St. Pierre | 8c6aa45 | 2014-02-08 18:29:49 -0500 | [diff] [blame] | 3317 | switch (state) { |
| 3318 | case XDG_SURFACE_STATE_MAXIMIZED: |
Jasper St. Pierre | 8c6aa45 | 2014-02-08 18:29:49 -0500 | [diff] [blame] | 3319 | case XDG_SURFACE_STATE_FULLSCREEN: |
Jasper St. Pierre | 8c6aa45 | 2014-02-08 18:29:49 -0500 | [diff] [blame] | 3320 | break; |
Kristian Høgsberg | 283bf37 | 2014-02-18 23:28:09 -0800 | [diff] [blame] | 3321 | default: |
| 3322 | /* send error? ignore? send change state with value 0? */ |
| 3323 | return; |
Rafael Antognolli | 3c4e3f7 | 2013-12-03 15:35:46 -0200 | [diff] [blame] | 3324 | } |
Kristian Høgsberg | 283bf37 | 2014-02-18 23:28:09 -0800 | [diff] [blame] | 3325 | |
| 3326 | xdg_surface_change_state(shsurf, state, value, serial); |
Rafael Antognolli | e2a3455 | 2013-12-03 15:35:45 -0200 | [diff] [blame] | 3327 | } |
| 3328 | |
| 3329 | static void |
Jasper St. Pierre | 8c6aa45 | 2014-02-08 18:29:49 -0500 | [diff] [blame] | 3330 | xdg_surface_ack_change_state(struct wl_client *client, |
| 3331 | struct wl_resource *resource, |
| 3332 | uint32_t state, |
| 3333 | uint32_t value, |
| 3334 | uint32_t serial) |
Rafael Antognolli | e2a3455 | 2013-12-03 15:35:45 -0200 | [diff] [blame] | 3335 | { |
| 3336 | struct shell_surface *shsurf = wl_resource_get_user_data(resource); |
| 3337 | |
Jasper St. Pierre | 8c6aa45 | 2014-02-08 18:29:49 -0500 | [diff] [blame] | 3338 | if (shsurf->state_requested) { |
| 3339 | shsurf->next_state = shsurf->requested_state; |
| 3340 | shsurf->state_changed = true; |
| 3341 | shsurf->state_requested = false; |
Rafael Antognolli | 3c4e3f7 | 2013-12-03 15:35:46 -0200 | [diff] [blame] | 3342 | } |
Rafael Antognolli | e2a3455 | 2013-12-03 15:35:45 -0200 | [diff] [blame] | 3343 | } |
| 3344 | |
| 3345 | static const struct xdg_surface_interface xdg_surface_implementation = { |
| 3346 | xdg_surface_destroy, |
| 3347 | xdg_surface_set_transient_for, |
Jasper St. Pierre | 7407345 | 2014-02-01 18:36:41 -0500 | [diff] [blame] | 3348 | xdg_surface_set_margin, |
Rafael Antognolli | e2a3455 | 2013-12-03 15:35:45 -0200 | [diff] [blame] | 3349 | xdg_surface_set_title, |
| 3350 | xdg_surface_set_app_id, |
Rafael Antognolli | e2a3455 | 2013-12-03 15:35:45 -0200 | [diff] [blame] | 3351 | xdg_surface_move, |
| 3352 | xdg_surface_resize, |
| 3353 | xdg_surface_set_output, |
Jasper St. Pierre | 8c6aa45 | 2014-02-08 18:29:49 -0500 | [diff] [blame] | 3354 | xdg_surface_request_change_state, |
| 3355 | xdg_surface_ack_change_state, |
Rafael Antognolli | e2a3455 | 2013-12-03 15:35:45 -0200 | [diff] [blame] | 3356 | NULL /* set_minimized */ |
| 3357 | }; |
| 3358 | |
| 3359 | static void |
| 3360 | xdg_send_configure(struct weston_surface *surface, |
| 3361 | uint32_t edges, int32_t width, int32_t height) |
| 3362 | { |
| 3363 | struct shell_surface *shsurf = get_shell_surface(surface); |
| 3364 | |
U. Artie Eoff | cf5737a | 2014-01-17 10:08:25 -0800 | [diff] [blame] | 3365 | assert(shsurf); |
| 3366 | |
Kristian Høgsberg | 44cd196 | 2014-02-05 21:36:04 -0800 | [diff] [blame] | 3367 | xdg_surface_send_configure(shsurf->resource, width, height); |
Rafael Antognolli | e2a3455 | 2013-12-03 15:35:45 -0200 | [diff] [blame] | 3368 | } |
| 3369 | |
| 3370 | static const struct weston_shell_client xdg_client = { |
| 3371 | xdg_send_configure |
| 3372 | }; |
| 3373 | |
| 3374 | static void |
| 3375 | xdg_use_unstable_version(struct wl_client *client, |
| 3376 | struct wl_resource *resource, |
| 3377 | int32_t version) |
| 3378 | { |
| 3379 | if (version > 1) { |
| 3380 | wl_resource_post_error(resource, |
| 3381 | 1, |
| 3382 | "xdg-shell:: version not implemented yet."); |
| 3383 | return; |
| 3384 | } |
| 3385 | } |
| 3386 | |
| 3387 | static struct shell_surface * |
| 3388 | create_xdg_surface(void *shell, struct weston_surface *surface, |
| 3389 | const struct weston_shell_client *client) |
| 3390 | { |
| 3391 | struct shell_surface *shsurf; |
Rafael Antognolli | e2a3455 | 2013-12-03 15:35:45 -0200 | [diff] [blame] | 3392 | |
Kristian Høgsberg | c8f8dd8 | 2013-12-05 23:20:33 -0800 | [diff] [blame] | 3393 | shsurf = create_common_surface(shell, surface, client); |
| 3394 | shsurf->type = SHELL_SURFACE_TOPLEVEL; |
Rafael Antognolli | e2a3455 | 2013-12-03 15:35:45 -0200 | [diff] [blame] | 3395 | |
| 3396 | return shsurf; |
| 3397 | } |
| 3398 | |
| 3399 | static void |
| 3400 | xdg_get_xdg_surface(struct wl_client *client, |
| 3401 | struct wl_resource *resource, |
| 3402 | uint32_t id, |
| 3403 | struct wl_resource *surface_resource) |
| 3404 | { |
| 3405 | struct weston_surface *surface = |
| 3406 | wl_resource_get_user_data(surface_resource); |
Kristian Høgsberg | 2bff94e | 2014-02-11 12:22:51 -0800 | [diff] [blame] | 3407 | struct shell_client *sc = wl_resource_get_user_data(resource); |
| 3408 | struct desktop_shell *shell = sc->shell; |
Rafael Antognolli | e2a3455 | 2013-12-03 15:35:45 -0200 | [diff] [blame] | 3409 | struct shell_surface *shsurf; |
| 3410 | |
| 3411 | if (get_shell_surface(surface)) { |
| 3412 | wl_resource_post_error(surface_resource, |
| 3413 | WL_DISPLAY_ERROR_INVALID_OBJECT, |
| 3414 | "desktop_shell::get_shell_surface already requested"); |
| 3415 | return; |
| 3416 | } |
| 3417 | |
| 3418 | shsurf = create_xdg_surface(shell, surface, &xdg_client); |
| 3419 | if (!shsurf) { |
| 3420 | wl_resource_post_error(surface_resource, |
| 3421 | WL_DISPLAY_ERROR_INVALID_OBJECT, |
| 3422 | "surface->configure already set"); |
| 3423 | return; |
| 3424 | } |
| 3425 | |
| 3426 | shsurf->resource = |
| 3427 | wl_resource_create(client, |
| 3428 | &xdg_surface_interface, 1, id); |
| 3429 | wl_resource_set_implementation(shsurf->resource, |
| 3430 | &xdg_surface_implementation, |
| 3431 | shsurf, shell_destroy_shell_surface); |
| 3432 | } |
| 3433 | |
| 3434 | static bool |
| 3435 | shell_surface_is_xdg_surface(struct shell_surface *shsurf) |
| 3436 | { |
Kristian Høgsberg | 0b7d995 | 2014-02-03 15:50:38 -0800 | [diff] [blame] | 3437 | return shsurf->resource && |
| 3438 | wl_resource_instance_of(shsurf->resource, |
| 3439 | &xdg_surface_interface, |
| 3440 | &xdg_surface_implementation); |
Rafael Antognolli | e2a3455 | 2013-12-03 15:35:45 -0200 | [diff] [blame] | 3441 | } |
| 3442 | |
| 3443 | /* xdg-popup implementation */ |
| 3444 | |
| 3445 | static void |
| 3446 | xdg_popup_destroy(struct wl_client *client, |
| 3447 | struct wl_resource *resource) |
| 3448 | { |
| 3449 | wl_resource_destroy(resource); |
| 3450 | } |
| 3451 | |
Rafael Antognolli | e2a3455 | 2013-12-03 15:35:45 -0200 | [diff] [blame] | 3452 | static const struct xdg_popup_interface xdg_popup_implementation = { |
| 3453 | xdg_popup_destroy, |
Rafael Antognolli | e2a3455 | 2013-12-03 15:35:45 -0200 | [diff] [blame] | 3454 | }; |
| 3455 | |
| 3456 | static void |
| 3457 | xdg_popup_send_configure(struct weston_surface *surface, |
| 3458 | uint32_t edges, int32_t width, int32_t height) |
| 3459 | { |
| 3460 | } |
| 3461 | |
| 3462 | static const struct weston_shell_client xdg_popup_client = { |
| 3463 | xdg_popup_send_configure |
| 3464 | }; |
| 3465 | |
| 3466 | static struct shell_surface * |
| 3467 | create_xdg_popup(void *shell, struct weston_surface *surface, |
| 3468 | const struct weston_shell_client *client, |
| 3469 | struct weston_surface *parent, |
| 3470 | struct shell_seat *seat, |
| 3471 | uint32_t serial, |
| 3472 | int32_t x, int32_t y) |
| 3473 | { |
| 3474 | struct shell_surface *shsurf; |
Rafael Antognolli | e2a3455 | 2013-12-03 15:35:45 -0200 | [diff] [blame] | 3475 | |
Kristian Høgsberg | c8f8dd8 | 2013-12-05 23:20:33 -0800 | [diff] [blame] | 3476 | shsurf = create_common_surface(shell, surface, client); |
| 3477 | shsurf->type = SHELL_SURFACE_POPUP; |
Rafael Antognolli | e2a3455 | 2013-12-03 15:35:45 -0200 | [diff] [blame] | 3478 | shsurf->popup.shseat = seat; |
| 3479 | shsurf->popup.serial = serial; |
| 3480 | shsurf->popup.x = x; |
| 3481 | shsurf->popup.y = y; |
| 3482 | shell_surface_set_parent(shsurf, parent); |
| 3483 | |
| 3484 | return shsurf; |
| 3485 | } |
| 3486 | |
| 3487 | static void |
| 3488 | xdg_get_xdg_popup(struct wl_client *client, |
| 3489 | struct wl_resource *resource, |
| 3490 | uint32_t id, |
| 3491 | struct wl_resource *surface_resource, |
| 3492 | struct wl_resource *parent_resource, |
| 3493 | struct wl_resource *seat_resource, |
| 3494 | uint32_t serial, |
| 3495 | int32_t x, int32_t y, uint32_t flags) |
| 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 | struct weston_surface *parent; |
| 3503 | struct shell_seat *seat; |
| 3504 | |
| 3505 | if (get_shell_surface(surface)) { |
| 3506 | wl_resource_post_error(surface_resource, |
| 3507 | WL_DISPLAY_ERROR_INVALID_OBJECT, |
| 3508 | "desktop_shell::get_shell_surface already requested"); |
| 3509 | return; |
| 3510 | } |
| 3511 | |
| 3512 | if (!parent_resource) { |
| 3513 | wl_resource_post_error(surface_resource, |
| 3514 | WL_DISPLAY_ERROR_INVALID_OBJECT, |
| 3515 | "xdg_shell::get_xdg_popup requires a parent shell surface"); |
| 3516 | } |
| 3517 | |
| 3518 | parent = wl_resource_get_user_data(parent_resource); |
| 3519 | seat = get_shell_seat(wl_resource_get_user_data(seat_resource));; |
| 3520 | |
| 3521 | shsurf = create_xdg_popup(shell, surface, &xdg_popup_client, |
| 3522 | parent, seat, serial, x, y); |
| 3523 | if (!shsurf) { |
| 3524 | wl_resource_post_error(surface_resource, |
| 3525 | WL_DISPLAY_ERROR_INVALID_OBJECT, |
| 3526 | "surface->configure already set"); |
| 3527 | return; |
| 3528 | } |
| 3529 | |
| 3530 | shsurf->resource = |
| 3531 | wl_resource_create(client, |
| 3532 | &xdg_popup_interface, 1, id); |
| 3533 | wl_resource_set_implementation(shsurf->resource, |
| 3534 | &xdg_popup_implementation, |
| 3535 | shsurf, shell_destroy_shell_surface); |
| 3536 | } |
| 3537 | |
Kristian Høgsberg | 2bff94e | 2014-02-11 12:22:51 -0800 | [diff] [blame] | 3538 | static void |
| 3539 | xdg_pong(struct wl_client *client, |
| 3540 | struct wl_resource *resource, uint32_t serial) |
| 3541 | { |
| 3542 | struct shell_client *sc = wl_resource_get_user_data(resource); |
Kristian Høgsberg | 2bff94e | 2014-02-11 12:22:51 -0800 | [diff] [blame] | 3543 | |
Kristian Høgsberg | dd62aba | 2014-02-12 09:56:19 -0800 | [diff] [blame] | 3544 | shell_client_pong(sc, serial); |
Kristian Høgsberg | 2bff94e | 2014-02-11 12:22:51 -0800 | [diff] [blame] | 3545 | } |
| 3546 | |
Rafael Antognolli | e2a3455 | 2013-12-03 15:35:45 -0200 | [diff] [blame] | 3547 | static bool |
| 3548 | shell_surface_is_xdg_popup(struct shell_surface *shsurf) |
| 3549 | { |
| 3550 | return wl_resource_instance_of(shsurf->resource, |
| 3551 | &xdg_popup_interface, |
| 3552 | &xdg_popup_implementation); |
| 3553 | } |
| 3554 | |
| 3555 | static const struct xdg_shell_interface xdg_implementation = { |
| 3556 | xdg_use_unstable_version, |
| 3557 | xdg_get_xdg_surface, |
Kristian Høgsberg | 2bff94e | 2014-02-11 12:22:51 -0800 | [diff] [blame] | 3558 | xdg_get_xdg_popup, |
| 3559 | xdg_pong |
Rafael Antognolli | e2a3455 | 2013-12-03 15:35:45 -0200 | [diff] [blame] | 3560 | }; |
| 3561 | |
| 3562 | static int |
| 3563 | xdg_shell_unversioned_dispatch(const void *implementation, |
| 3564 | void *_target, uint32_t opcode, |
| 3565 | const struct wl_message *message, |
| 3566 | union wl_argument *args) |
| 3567 | { |
| 3568 | struct wl_resource *resource = _target; |
Kristian Høgsberg | 2bff94e | 2014-02-11 12:22:51 -0800 | [diff] [blame] | 3569 | struct shell_client *sc = wl_resource_get_user_data(resource); |
Rafael Antognolli | e2a3455 | 2013-12-03 15:35:45 -0200 | [diff] [blame] | 3570 | |
| 3571 | if (opcode != 0) { |
| 3572 | wl_resource_post_error(resource, |
| 3573 | WL_DISPLAY_ERROR_INVALID_OBJECT, |
| 3574 | "must call use_unstable_version first"); |
| 3575 | return 0; |
| 3576 | } |
| 3577 | |
Kristian Høgsberg | c7680b0 | 2014-02-19 10:14:46 -0800 | [diff] [blame] | 3578 | #define XDG_SERVER_VERSION 3 |
Rafael Antognolli | e2a3455 | 2013-12-03 15:35:45 -0200 | [diff] [blame] | 3579 | |
Kristian Høgsberg | 8d344a0 | 2013-12-08 22:27:11 -0800 | [diff] [blame] | 3580 | static_assert(XDG_SERVER_VERSION == XDG_SHELL_VERSION_CURRENT, |
| 3581 | "shell implementation doesn't match protocol version"); |
| 3582 | |
Rafael Antognolli | e2a3455 | 2013-12-03 15:35:45 -0200 | [diff] [blame] | 3583 | if (args[0].i != XDG_SERVER_VERSION) { |
| 3584 | wl_resource_post_error(resource, |
| 3585 | WL_DISPLAY_ERROR_INVALID_OBJECT, |
| 3586 | "incompatible version, server is %d " |
| 3587 | "client wants %d", |
| 3588 | XDG_SERVER_VERSION, args[0].i); |
| 3589 | return 0; |
| 3590 | } |
| 3591 | |
| 3592 | wl_resource_set_implementation(resource, &xdg_implementation, |
Kristian Høgsberg | 2bff94e | 2014-02-11 12:22:51 -0800 | [diff] [blame] | 3593 | sc, NULL); |
Rafael Antognolli | e2a3455 | 2013-12-03 15:35:45 -0200 | [diff] [blame] | 3594 | |
| 3595 | return 1; |
| 3596 | } |
| 3597 | |
| 3598 | /* end of xdg-shell implementation */ |
| 3599 | /***********************************/ |
| 3600 | |
Kristian Høgsberg | 0793756 | 2011-04-12 17:25:42 -0400 | [diff] [blame] | 3601 | static void |
Ander Conselvan de Oliveira | 859e885 | 2013-02-21 18:35:21 +0200 | [diff] [blame] | 3602 | shell_fade(struct desktop_shell *shell, enum fade_type type); |
| 3603 | |
| 3604 | static int |
| 3605 | screensaver_timeout(void *data) |
| 3606 | { |
| 3607 | struct desktop_shell *shell = data; |
| 3608 | |
| 3609 | shell_fade(shell, FADE_OUT); |
| 3610 | |
| 3611 | return 1; |
| 3612 | } |
| 3613 | |
| 3614 | static void |
Kristian Høgsberg | 8334bc1 | 2012-01-03 10:29:47 -0500 | [diff] [blame] | 3615 | handle_screensaver_sigchld(struct weston_process *proc, int status) |
Pekka Paalanen | 18027e5 | 2011-12-02 16:31:49 +0200 | [diff] [blame] | 3616 | { |
Ander Conselvan de Oliveira | 18639f8 | 2013-02-15 18:44:19 +0200 | [diff] [blame] | 3617 | struct desktop_shell *shell = |
| 3618 | container_of(proc, struct desktop_shell, screensaver.process); |
Ander Conselvan de Oliveira | 18639f8 | 2013-02-15 18:44:19 +0200 | [diff] [blame] | 3619 | |
Pekka Paalanen | 18027e5 | 2011-12-02 16:31:49 +0200 | [diff] [blame] | 3620 | proc->pid = 0; |
Ander Conselvan de Oliveira | 18639f8 | 2013-02-15 18:44:19 +0200 | [diff] [blame] | 3621 | |
| 3622 | if (shell->locked) |
Ander Conselvan de Oliveira | b17537e | 2013-02-22 14:16:18 +0200 | [diff] [blame] | 3623 | weston_compositor_sleep(shell->compositor); |
Pekka Paalanen | 18027e5 | 2011-12-02 16:31:49 +0200 | [diff] [blame] | 3624 | } |
| 3625 | |
| 3626 | static void |
Tiago Vignatti | be14326 | 2012-04-16 17:31:41 +0300 | [diff] [blame] | 3627 | launch_screensaver(struct desktop_shell *shell) |
Pekka Paalanen | 77346a6 | 2011-11-30 16:26:35 +0200 | [diff] [blame] | 3628 | { |
| 3629 | if (shell->screensaver.binding) |
| 3630 | return; |
| 3631 | |
Ander Conselvan de Oliveira | dda9d78 | 2013-02-22 14:16:19 +0200 | [diff] [blame] | 3632 | if (!shell->screensaver.path) { |
| 3633 | weston_compositor_sleep(shell->compositor); |
Pekka Paalanen | e955f1e | 2011-12-07 11:49:52 +0200 | [diff] [blame] | 3634 | return; |
Ander Conselvan de Oliveira | dda9d78 | 2013-02-22 14:16:19 +0200 | [diff] [blame] | 3635 | } |
Pekka Paalanen | e955f1e | 2011-12-07 11:49:52 +0200 | [diff] [blame] | 3636 | |
Kristian Høgsberg | 32bed57 | 2012-03-01 17:11:36 -0500 | [diff] [blame] | 3637 | if (shell->screensaver.process.pid != 0) { |
Martin Minarik | 6d11836 | 2012-06-07 18:01:59 +0200 | [diff] [blame] | 3638 | weston_log("old screensaver still running\n"); |
Kristian Høgsberg | 32bed57 | 2012-03-01 17:11:36 -0500 | [diff] [blame] | 3639 | return; |
| 3640 | } |
| 3641 | |
Kristian Høgsberg | 8334bc1 | 2012-01-03 10:29:47 -0500 | [diff] [blame] | 3642 | weston_client_launch(shell->compositor, |
Pekka Paalanen | 18027e5 | 2011-12-02 16:31:49 +0200 | [diff] [blame] | 3643 | &shell->screensaver.process, |
Pekka Paalanen | e955f1e | 2011-12-07 11:49:52 +0200 | [diff] [blame] | 3644 | shell->screensaver.path, |
Pekka Paalanen | 18027e5 | 2011-12-02 16:31:49 +0200 | [diff] [blame] | 3645 | handle_screensaver_sigchld); |
Pekka Paalanen | 77346a6 | 2011-11-30 16:26:35 +0200 | [diff] [blame] | 3646 | } |
| 3647 | |
| 3648 | static void |
Tiago Vignatti | be14326 | 2012-04-16 17:31:41 +0300 | [diff] [blame] | 3649 | terminate_screensaver(struct desktop_shell *shell) |
Pekka Paalanen | 77346a6 | 2011-11-30 16:26:35 +0200 | [diff] [blame] | 3650 | { |
Pekka Paalanen | 18027e5 | 2011-12-02 16:31:49 +0200 | [diff] [blame] | 3651 | if (shell->screensaver.process.pid == 0) |
| 3652 | return; |
| 3653 | |
| 3654 | kill(shell->screensaver.process.pid, SIGTERM); |
Pekka Paalanen | 77346a6 | 2011-11-30 16:26:35 +0200 | [diff] [blame] | 3655 | } |
| 3656 | |
| 3657 | static void |
Jason Ekstrand | 918f2dd | 2013-12-02 21:01:53 -0600 | [diff] [blame] | 3658 | configure_static_view(struct weston_view *ev, struct weston_layer *layer) |
Kristian Høgsberg | 962342c | 2012-06-26 16:29:50 -0400 | [diff] [blame] | 3659 | { |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 3660 | struct weston_view *v, *next; |
Kristian Høgsberg | 962342c | 2012-06-26 16:29:50 -0400 | [diff] [blame] | 3661 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 3662 | wl_list_for_each_safe(v, next, &layer->view_list, layer_link) { |
| 3663 | if (v->output == ev->output && v != ev) { |
| 3664 | weston_view_unmap(v); |
| 3665 | v->surface->configure = NULL; |
Kristian Høgsberg | 962342c | 2012-06-26 16:29:50 -0400 | [diff] [blame] | 3666 | } |
| 3667 | } |
| 3668 | |
Jason Ekstrand | 918f2dd | 2013-12-02 21:01:53 -0600 | [diff] [blame] | 3669 | weston_view_set_position(ev, ev->output->x, ev->output->y); |
Kristian Høgsberg | 962342c | 2012-06-26 16:29:50 -0400 | [diff] [blame] | 3670 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 3671 | if (wl_list_empty(&ev->layer_link)) { |
| 3672 | wl_list_insert(&layer->view_list, &ev->layer_link); |
| 3673 | weston_compositor_schedule_repaint(ev->surface->compositor); |
Kristian Høgsberg | 962342c | 2012-06-26 16:29:50 -0400 | [diff] [blame] | 3674 | } |
| 3675 | } |
| 3676 | |
| 3677 | static void |
Jason Ekstrand | 918f2dd | 2013-12-02 21:01:53 -0600 | [diff] [blame] | 3678 | 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] | 3679 | { |
Giulio Camuffo | 7fe01b1 | 2013-03-28 18:02:42 +0100 | [diff] [blame] | 3680 | struct desktop_shell *shell = es->configure_private; |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 3681 | struct weston_view *view; |
Kristian Høgsberg | af7b1ff | 2012-06-26 21:19:23 -0400 | [diff] [blame] | 3682 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 3683 | view = container_of(es->views.next, struct weston_view, surface_link); |
| 3684 | |
Jason Ekstrand | 918f2dd | 2013-12-02 21:01:53 -0600 | [diff] [blame] | 3685 | configure_static_view(view, &shell->background_layer); |
Kristian Høgsberg | af7b1ff | 2012-06-26 21:19:23 -0400 | [diff] [blame] | 3686 | } |
| 3687 | |
| 3688 | static void |
Kristian Høgsberg | 7584062 | 2011-09-06 13:48:16 -0400 | [diff] [blame] | 3689 | desktop_shell_set_background(struct wl_client *client, |
| 3690 | struct wl_resource *resource, |
Benjamin Franzke | d0f79ab | 2011-11-22 12:43:52 +0100 | [diff] [blame] | 3691 | struct wl_resource *output_resource, |
Kristian Høgsberg | 7584062 | 2011-09-06 13:48:16 -0400 | [diff] [blame] | 3692 | struct wl_resource *surface_resource) |
| 3693 | { |
Jason Ekstrand | 651f00e | 2013-06-14 10:07:54 -0500 | [diff] [blame] | 3694 | struct desktop_shell *shell = wl_resource_get_user_data(resource); |
Jason Ekstrand | 0f2ef7e | 2013-06-14 10:07:53 -0500 | [diff] [blame] | 3695 | struct weston_surface *surface = |
| 3696 | wl_resource_get_user_data(surface_resource); |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 3697 | struct weston_view *view, *next; |
Kristian Høgsberg | 7584062 | 2011-09-06 13:48:16 -0400 | [diff] [blame] | 3698 | |
Kristian Høgsberg | 962342c | 2012-06-26 16:29:50 -0400 | [diff] [blame] | 3699 | if (surface->configure) { |
| 3700 | wl_resource_post_error(surface_resource, |
| 3701 | WL_DISPLAY_ERROR_INVALID_OBJECT, |
| 3702 | "surface role already assigned"); |
| 3703 | return; |
| 3704 | } |
Benjamin Franzke | d0f79ab | 2011-11-22 12:43:52 +0100 | [diff] [blame] | 3705 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 3706 | wl_list_for_each_safe(view, next, &surface->views, surface_link) |
| 3707 | weston_view_destroy(view); |
| 3708 | view = weston_view_create(surface); |
| 3709 | |
Kristian Høgsberg | 962342c | 2012-06-26 16:29:50 -0400 | [diff] [blame] | 3710 | surface->configure = background_configure; |
Giulio Camuffo | 7fe01b1 | 2013-03-28 18:02:42 +0100 | [diff] [blame] | 3711 | surface->configure_private = shell; |
Jason Ekstrand | a0d2dde | 2013-06-14 10:08:01 -0500 | [diff] [blame] | 3712 | surface->output = wl_resource_get_user_data(output_resource); |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 3713 | view->output = surface->output; |
Kristian Høgsberg | eae5de7 | 2012-04-11 22:42:15 -0400 | [diff] [blame] | 3714 | desktop_shell_send_configure(resource, 0, |
Kristian Høgsberg | 0b5cd0c | 2012-03-04 21:57:37 -0500 | [diff] [blame] | 3715 | surface_resource, |
Scott Moreau | 1bad5db | 2012-08-18 01:04:05 -0600 | [diff] [blame] | 3716 | surface->output->width, |
| 3717 | surface->output->height); |
Kristian Høgsberg | 7584062 | 2011-09-06 13:48:16 -0400 | [diff] [blame] | 3718 | } |
| 3719 | |
| 3720 | static void |
Jason Ekstrand | 918f2dd | 2013-12-02 21:01:53 -0600 | [diff] [blame] | 3721 | 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] | 3722 | { |
Giulio Camuffo | 7fe01b1 | 2013-03-28 18:02:42 +0100 | [diff] [blame] | 3723 | struct desktop_shell *shell = es->configure_private; |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 3724 | struct weston_view *view; |
Kristian Høgsberg | af7b1ff | 2012-06-26 21:19:23 -0400 | [diff] [blame] | 3725 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 3726 | view = container_of(es->views.next, struct weston_view, surface_link); |
| 3727 | |
Jason Ekstrand | 918f2dd | 2013-12-02 21:01:53 -0600 | [diff] [blame] | 3728 | configure_static_view(view, &shell->panel_layer); |
Kristian Høgsberg | af7b1ff | 2012-06-26 21:19:23 -0400 | [diff] [blame] | 3729 | } |
| 3730 | |
| 3731 | static void |
Kristian Høgsberg | 7584062 | 2011-09-06 13:48:16 -0400 | [diff] [blame] | 3732 | desktop_shell_set_panel(struct wl_client *client, |
| 3733 | struct wl_resource *resource, |
Benjamin Franzke | d0f79ab | 2011-11-22 12:43:52 +0100 | [diff] [blame] | 3734 | struct wl_resource *output_resource, |
Kristian Høgsberg | 7584062 | 2011-09-06 13:48:16 -0400 | [diff] [blame] | 3735 | struct wl_resource *surface_resource) |
| 3736 | { |
Jason Ekstrand | 651f00e | 2013-06-14 10:07:54 -0500 | [diff] [blame] | 3737 | struct desktop_shell *shell = wl_resource_get_user_data(resource); |
Jason Ekstrand | 0f2ef7e | 2013-06-14 10:07:53 -0500 | [diff] [blame] | 3738 | struct weston_surface *surface = |
| 3739 | wl_resource_get_user_data(surface_resource); |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 3740 | struct weston_view *view, *next; |
Kristian Høgsberg | 7584062 | 2011-09-06 13:48:16 -0400 | [diff] [blame] | 3741 | |
Kristian Høgsberg | af7b1ff | 2012-06-26 21:19:23 -0400 | [diff] [blame] | 3742 | if (surface->configure) { |
| 3743 | wl_resource_post_error(surface_resource, |
| 3744 | WL_DISPLAY_ERROR_INVALID_OBJECT, |
| 3745 | "surface role already assigned"); |
| 3746 | return; |
| 3747 | } |
Benjamin Franzke | d0f79ab | 2011-11-22 12:43:52 +0100 | [diff] [blame] | 3748 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 3749 | wl_list_for_each_safe(view, next, &surface->views, surface_link) |
| 3750 | weston_view_destroy(view); |
| 3751 | view = weston_view_create(surface); |
| 3752 | |
Kristian Høgsberg | af7b1ff | 2012-06-26 21:19:23 -0400 | [diff] [blame] | 3753 | surface->configure = panel_configure; |
Giulio Camuffo | 7fe01b1 | 2013-03-28 18:02:42 +0100 | [diff] [blame] | 3754 | surface->configure_private = shell; |
Jason Ekstrand | a0d2dde | 2013-06-14 10:08:01 -0500 | [diff] [blame] | 3755 | surface->output = wl_resource_get_user_data(output_resource); |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 3756 | view->output = surface->output; |
Kristian Høgsberg | eae5de7 | 2012-04-11 22:42:15 -0400 | [diff] [blame] | 3757 | desktop_shell_send_configure(resource, 0, |
Kristian Høgsberg | af7b1ff | 2012-06-26 21:19:23 -0400 | [diff] [blame] | 3758 | surface_resource, |
Scott Moreau | 1bad5db | 2012-08-18 01:04:05 -0600 | [diff] [blame] | 3759 | surface->output->width, |
| 3760 | surface->output->height); |
Kristian Høgsberg | 7584062 | 2011-09-06 13:48:16 -0400 | [diff] [blame] | 3761 | } |
| 3762 | |
Pekka Paalanen | 9ef3e01 | 2011-11-15 13:34:48 +0200 | [diff] [blame] | 3763 | static void |
Jason Ekstrand | 918f2dd | 2013-12-02 21:01:53 -0600 | [diff] [blame] | 3764 | 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] | 3765 | { |
Giulio Camuffo | 7fe01b1 | 2013-03-28 18:02:42 +0100 | [diff] [blame] | 3766 | struct desktop_shell *shell = surface->configure_private; |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 3767 | struct weston_view *view; |
| 3768 | |
| 3769 | view = container_of(surface->views.next, struct weston_view, surface_link); |
Kristian Høgsberg | 730c94d | 2012-06-26 21:44:35 -0400 | [diff] [blame] | 3770 | |
Jason Ekstrand | 918f2dd | 2013-12-02 21:01:53 -0600 | [diff] [blame] | 3771 | if (surface->width == 0) |
Giulio Camuffo | 184df50 | 2013-02-21 11:29:21 +0100 | [diff] [blame] | 3772 | return; |
| 3773 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 3774 | center_on_output(view, get_default_output(shell->compositor)); |
Kristian Høgsberg | 730c94d | 2012-06-26 21:44:35 -0400 | [diff] [blame] | 3775 | |
| 3776 | if (!weston_surface_is_mapped(surface)) { |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 3777 | wl_list_insert(&shell->lock_layer.view_list, |
| 3778 | &view->layer_link); |
| 3779 | weston_view_update_transform(view); |
Ander Conselvan de Oliveira | 87524b6 | 2013-02-21 18:35:22 +0200 | [diff] [blame] | 3780 | shell_fade(shell, FADE_IN); |
Kristian Høgsberg | 730c94d | 2012-06-26 21:44:35 -0400 | [diff] [blame] | 3781 | } |
| 3782 | } |
| 3783 | |
| 3784 | static void |
Kristian Høgsberg | 27e3052 | 2012-04-11 23:18:23 -0400 | [diff] [blame] | 3785 | handle_lock_surface_destroy(struct wl_listener *listener, void *data) |
Kristian Høgsberg | 1ec0c31 | 2011-11-15 16:39:55 -0500 | [diff] [blame] | 3786 | { |
Tiago Vignatti | be14326 | 2012-04-16 17:31:41 +0300 | [diff] [blame] | 3787 | struct desktop_shell *shell = |
| 3788 | container_of(listener, struct desktop_shell, lock_surface_listener); |
Kristian Høgsberg | 1ec0c31 | 2011-11-15 16:39:55 -0500 | [diff] [blame] | 3789 | |
Martin Minarik | 6d11836 | 2012-06-07 18:01:59 +0200 | [diff] [blame] | 3790 | weston_log("lock surface gone\n"); |
Kristian Høgsberg | 1ec0c31 | 2011-11-15 16:39:55 -0500 | [diff] [blame] | 3791 | shell->lock_surface = NULL; |
| 3792 | } |
| 3793 | |
| 3794 | static void |
Pekka Paalanen | 9ef3e01 | 2011-11-15 13:34:48 +0200 | [diff] [blame] | 3795 | desktop_shell_set_lock_surface(struct wl_client *client, |
| 3796 | struct wl_resource *resource, |
| 3797 | struct wl_resource *surface_resource) |
| 3798 | { |
Jason Ekstrand | 651f00e | 2013-06-14 10:07:54 -0500 | [diff] [blame] | 3799 | struct desktop_shell *shell = wl_resource_get_user_data(resource); |
Jason Ekstrand | 0f2ef7e | 2013-06-14 10:07:53 -0500 | [diff] [blame] | 3800 | struct weston_surface *surface = |
| 3801 | wl_resource_get_user_data(surface_resource); |
Pekka Paalanen | 9826223 | 2011-12-01 10:42:22 +0200 | [diff] [blame] | 3802 | |
Pekka Paalanen | f0fc70d | 2011-11-15 13:34:54 +0200 | [diff] [blame] | 3803 | shell->prepare_event_sent = false; |
Kristian Høgsberg | af867cc | 2011-11-15 13:34:49 +0200 | [diff] [blame] | 3804 | |
Pekka Paalanen | f0fc70d | 2011-11-15 13:34:54 +0200 | [diff] [blame] | 3805 | if (!shell->locked) |
| 3806 | return; |
| 3807 | |
Pekka Paalanen | 9826223 | 2011-12-01 10:42:22 +0200 | [diff] [blame] | 3808 | shell->lock_surface = surface; |
Pekka Paalanen | f0fc70d | 2011-11-15 13:34:54 +0200 | [diff] [blame] | 3809 | |
Kristian Høgsberg | 27e3052 | 2012-04-11 23:18:23 -0400 | [diff] [blame] | 3810 | shell->lock_surface_listener.notify = handle_lock_surface_destroy; |
Jason Ekstrand | 651f00e | 2013-06-14 10:07:54 -0500 | [diff] [blame] | 3811 | wl_signal_add(&surface->destroy_signal, |
Kristian Høgsberg | 27e3052 | 2012-04-11 23:18:23 -0400 | [diff] [blame] | 3812 | &shell->lock_surface_listener); |
Pekka Paalanen | 57da4a8 | 2011-11-23 16:42:16 +0200 | [diff] [blame] | 3813 | |
Kristian Høgsberg | aa2ee8b | 2013-10-30 15:49:45 -0700 | [diff] [blame] | 3814 | weston_view_create(surface); |
Kristian Høgsberg | 730c94d | 2012-06-26 21:44:35 -0400 | [diff] [blame] | 3815 | surface->configure = lock_surface_configure; |
Giulio Camuffo | 7fe01b1 | 2013-03-28 18:02:42 +0100 | [diff] [blame] | 3816 | surface->configure_private = shell; |
Pekka Paalanen | f0fc70d | 2011-11-15 13:34:54 +0200 | [diff] [blame] | 3817 | } |
| 3818 | |
| 3819 | static void |
Tiago Vignatti | be14326 | 2012-04-16 17:31:41 +0300 | [diff] [blame] | 3820 | resume_desktop(struct desktop_shell *shell) |
Pekka Paalanen | f0fc70d | 2011-11-15 13:34:54 +0200 | [diff] [blame] | 3821 | { |
Kristian Høgsberg | 4476aaf | 2012-06-25 14:03:13 -0400 | [diff] [blame] | 3822 | struct workspace *ws = get_current_workspace(shell); |
Pekka Paalanen | 77346a6 | 2011-11-30 16:26:35 +0200 | [diff] [blame] | 3823 | |
Pekka Paalanen | 77346a6 | 2011-11-30 16:26:35 +0200 | [diff] [blame] | 3824 | terminate_screensaver(shell); |
Pekka Paalanen | f0fc70d | 2011-11-15 13:34:54 +0200 | [diff] [blame] | 3825 | |
Kristian Høgsberg | 3be2ce9 | 2012-02-29 12:42:35 -0500 | [diff] [blame] | 3826 | wl_list_remove(&shell->lock_layer.link); |
| 3827 | wl_list_insert(&shell->compositor->cursor_layer.link, |
| 3828 | &shell->fullscreen_layer.link); |
| 3829 | wl_list_insert(&shell->fullscreen_layer.link, |
| 3830 | &shell->panel_layer.link); |
Philipp Brüschweiler | 711fda8 | 2012-08-09 18:50:43 +0200 | [diff] [blame] | 3831 | if (shell->showing_input_panels) { |
| 3832 | wl_list_insert(&shell->panel_layer.link, |
| 3833 | &shell->input_panel_layer.link); |
| 3834 | wl_list_insert(&shell->input_panel_layer.link, |
| 3835 | &ws->layer.link); |
| 3836 | } else { |
| 3837 | wl_list_insert(&shell->panel_layer.link, &ws->layer.link); |
| 3838 | } |
Pekka Paalanen | f0fc70d | 2011-11-15 13:34:54 +0200 | [diff] [blame] | 3839 | |
Kristian Høgsberg | 2f5faff | 2012-07-31 16:36:34 -0400 | [diff] [blame] | 3840 | restore_focus_state(shell, get_current_workspace(shell)); |
Jonas Ådahl | 0476974 | 2012-06-13 00:01:24 +0200 | [diff] [blame] | 3841 | |
Pekka Paalanen | f0fc70d | 2011-11-15 13:34:54 +0200 | [diff] [blame] | 3842 | shell->locked = false; |
Ander Conselvan de Oliveira | 87524b6 | 2013-02-21 18:35:22 +0200 | [diff] [blame] | 3843 | shell_fade(shell, FADE_IN); |
Pekka Paalanen | fc6d91a | 2012-02-10 15:33:10 +0200 | [diff] [blame] | 3844 | weston_compositor_damage_all(shell->compositor); |
Pekka Paalanen | 9ef3e01 | 2011-11-15 13:34:48 +0200 | [diff] [blame] | 3845 | } |
| 3846 | |
| 3847 | static void |
| 3848 | desktop_shell_unlock(struct wl_client *client, |
| 3849 | struct wl_resource *resource) |
| 3850 | { |
Jason Ekstrand | 651f00e | 2013-06-14 10:07:54 -0500 | [diff] [blame] | 3851 | struct desktop_shell *shell = wl_resource_get_user_data(resource); |
Pekka Paalanen | 9ef3e01 | 2011-11-15 13:34:48 +0200 | [diff] [blame] | 3852 | |
Pekka Paalanen | 9ef3e01 | 2011-11-15 13:34:48 +0200 | [diff] [blame] | 3853 | shell->prepare_event_sent = false; |
Pekka Paalanen | f0fc70d | 2011-11-15 13:34:54 +0200 | [diff] [blame] | 3854 | |
| 3855 | if (shell->locked) |
| 3856 | resume_desktop(shell); |
Pekka Paalanen | 9ef3e01 | 2011-11-15 13:34:48 +0200 | [diff] [blame] | 3857 | } |
| 3858 | |
Kristian Høgsberg | d56bd90 | 2012-06-05 09:58:51 -0400 | [diff] [blame] | 3859 | static void |
Ander Conselvan de Oliveira | b9d2a0f | 2012-06-28 18:08:05 +0300 | [diff] [blame] | 3860 | desktop_shell_set_grab_surface(struct wl_client *client, |
Kristian Høgsberg | d56bd90 | 2012-06-05 09:58:51 -0400 | [diff] [blame] | 3861 | struct wl_resource *resource, |
| 3862 | struct wl_resource *surface_resource) |
| 3863 | { |
Jason Ekstrand | 651f00e | 2013-06-14 10:07:54 -0500 | [diff] [blame] | 3864 | struct desktop_shell *shell = wl_resource_get_user_data(resource); |
Kristian Høgsberg | d56bd90 | 2012-06-05 09:58:51 -0400 | [diff] [blame] | 3865 | |
Jason Ekstrand | 0f2ef7e | 2013-06-14 10:07:53 -0500 | [diff] [blame] | 3866 | shell->grab_surface = wl_resource_get_user_data(surface_resource); |
Kristian Høgsberg | 48588f8 | 2013-10-24 15:51:35 -0700 | [diff] [blame] | 3867 | weston_view_create(shell->grab_surface); |
Kristian Høgsberg | d56bd90 | 2012-06-05 09:58:51 -0400 | [diff] [blame] | 3868 | } |
| 3869 | |
Pekka Paalanen | 79346ab | 2013-05-22 18:03:09 +0300 | [diff] [blame] | 3870 | static void |
| 3871 | desktop_shell_desktop_ready(struct wl_client *client, |
| 3872 | struct wl_resource *resource) |
| 3873 | { |
Jason Ekstrand | 651f00e | 2013-06-14 10:07:54 -0500 | [diff] [blame] | 3874 | struct desktop_shell *shell = wl_resource_get_user_data(resource); |
Pekka Paalanen | 79346ab | 2013-05-22 18:03:09 +0300 | [diff] [blame] | 3875 | |
| 3876 | shell_fade_startup(shell); |
| 3877 | } |
| 3878 | |
Kristian Høgsberg | 7584062 | 2011-09-06 13:48:16 -0400 | [diff] [blame] | 3879 | static const struct desktop_shell_interface desktop_shell_implementation = { |
| 3880 | desktop_shell_set_background, |
Pekka Paalanen | 9ef3e01 | 2011-11-15 13:34:48 +0200 | [diff] [blame] | 3881 | desktop_shell_set_panel, |
| 3882 | desktop_shell_set_lock_surface, |
Kristian Høgsberg | d56bd90 | 2012-06-05 09:58:51 -0400 | [diff] [blame] | 3883 | desktop_shell_unlock, |
Pekka Paalanen | 79346ab | 2013-05-22 18:03:09 +0300 | [diff] [blame] | 3884 | desktop_shell_set_grab_surface, |
| 3885 | desktop_shell_desktop_ready |
Kristian Høgsberg | 7584062 | 2011-09-06 13:48:16 -0400 | [diff] [blame] | 3886 | }; |
| 3887 | |
Pekka Paalanen | 92a0dc4 | 2011-11-28 15:34:13 +0200 | [diff] [blame] | 3888 | static enum shell_surface_type |
Kristian Høgsberg | 8334bc1 | 2012-01-03 10:29:47 -0500 | [diff] [blame] | 3889 | get_shell_surface_type(struct weston_surface *surface) |
Pekka Paalanen | 92a0dc4 | 2011-11-28 15:34:13 +0200 | [diff] [blame] | 3890 | { |
| 3891 | struct shell_surface *shsurf; |
| 3892 | |
| 3893 | shsurf = get_shell_surface(surface); |
| 3894 | if (!shsurf) |
Pekka Paalanen | 9826223 | 2011-12-01 10:42:22 +0200 | [diff] [blame] | 3895 | return SHELL_SURFACE_NONE; |
Pekka Paalanen | 92a0dc4 | 2011-11-28 15:34:13 +0200 | [diff] [blame] | 3896 | return shsurf->type; |
| 3897 | } |
| 3898 | |
Kristian Høgsberg | 7584062 | 2011-09-06 13:48:16 -0400 | [diff] [blame] | 3899 | static void |
Kristian Høgsberg | e314875 | 2013-05-06 23:19:49 -0400 | [diff] [blame] | 3900 | 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] | 3901 | { |
Rafal Mielniczuk | b2917a2 | 2014-01-05 20:04:59 +0100 | [diff] [blame] | 3902 | struct weston_surface *focus; |
Pekka Paalanen | 01388e2 | 2013-04-25 13:57:44 +0300 | [diff] [blame] | 3903 | struct weston_surface *surface; |
Kristian Høgsberg | 938b8fa | 2012-05-18 13:46:27 -0400 | [diff] [blame] | 3904 | struct shell_surface *shsurf; |
Kristian Høgsberg | d2abb83 | 2011-11-23 10:52:40 -0500 | [diff] [blame] | 3905 | |
Rafal Mielniczuk | b2917a2 | 2014-01-05 20:04:59 +0100 | [diff] [blame] | 3906 | if (seat->pointer->focus == NULL) |
| 3907 | return; |
| 3908 | |
| 3909 | focus = seat->pointer->focus->surface; |
| 3910 | |
Pekka Paalanen | 01388e2 | 2013-04-25 13:57:44 +0300 | [diff] [blame] | 3911 | surface = weston_surface_get_main_surface(focus); |
Benjamin Franzke | d0f79ab | 2011-11-22 12:43:52 +0100 | [diff] [blame] | 3912 | if (surface == NULL) |
| 3913 | return; |
Kristian Høgsberg | 0793756 | 2011-04-12 17:25:42 -0400 | [diff] [blame] | 3914 | |
Kristian Høgsberg | 938b8fa | 2012-05-18 13:46:27 -0400 | [diff] [blame] | 3915 | shsurf = get_shell_surface(surface); |
Rafael Antognolli | 03b1659 | 2013-12-03 15:35:42 -0200 | [diff] [blame] | 3916 | if (shsurf == NULL || shsurf->state.fullscreen || |
| 3917 | shsurf->state.maximized) |
Kristian Høgsberg | 938b8fa | 2012-05-18 13:46:27 -0400 | [diff] [blame] | 3918 | return; |
| 3919 | |
Kristian Høgsberg | 938b8fa | 2012-05-18 13:46:27 -0400 | [diff] [blame] | 3920 | surface_move(shsurf, (struct weston_seat *) seat); |
Kristian Høgsberg | 0793756 | 2011-04-12 17:25:42 -0400 | [diff] [blame] | 3921 | } |
| 3922 | |
| 3923 | static void |
Rafael Antognolli | ea997ac | 2013-12-03 15:35:48 -0200 | [diff] [blame] | 3924 | maximize_binding(struct weston_seat *seat, uint32_t time, uint32_t button, void *data) |
| 3925 | { |
Emilio Pozuelo Monfort | 38b58eb | 2014-01-29 11:11:12 +0100 | [diff] [blame] | 3926 | struct weston_surface *focus = seat->keyboard->focus; |
Rafael Antognolli | ea997ac | 2013-12-03 15:35:48 -0200 | [diff] [blame] | 3927 | struct weston_surface *surface; |
| 3928 | struct shell_surface *shsurf; |
Kristian Høgsberg | 283bf37 | 2014-02-18 23:28:09 -0800 | [diff] [blame] | 3929 | uint32_t serial; |
Rafael Antognolli | ea997ac | 2013-12-03 15:35:48 -0200 | [diff] [blame] | 3930 | |
| 3931 | surface = weston_surface_get_main_surface(focus); |
| 3932 | if (surface == NULL) |
| 3933 | return; |
| 3934 | |
| 3935 | shsurf = get_shell_surface(surface); |
| 3936 | if (shsurf == NULL) |
| 3937 | return; |
| 3938 | |
| 3939 | if (!shell_surface_is_xdg_surface(shsurf)) |
| 3940 | return; |
| 3941 | |
Kristian Høgsberg | 283bf37 | 2014-02-18 23:28:09 -0800 | [diff] [blame] | 3942 | serial = wl_display_next_serial(seat->compositor->wl_display); |
| 3943 | xdg_surface_change_state(shsurf, XDG_SURFACE_STATE_MAXIMIZED, |
| 3944 | !shsurf->state.maximized, serial); |
Rafael Antognolli | ea997ac | 2013-12-03 15:35:48 -0200 | [diff] [blame] | 3945 | } |
| 3946 | |
| 3947 | static void |
| 3948 | fullscreen_binding(struct weston_seat *seat, uint32_t time, uint32_t button, void *data) |
| 3949 | { |
Emilio Pozuelo Monfort | 38b58eb | 2014-01-29 11:11:12 +0100 | [diff] [blame] | 3950 | struct weston_surface *focus = seat->keyboard->focus; |
Rafael Antognolli | ea997ac | 2013-12-03 15:35:48 -0200 | [diff] [blame] | 3951 | struct weston_surface *surface; |
| 3952 | struct shell_surface *shsurf; |
Kristian Høgsberg | 283bf37 | 2014-02-18 23:28:09 -0800 | [diff] [blame] | 3953 | uint32_t serial; |
Rafael Antognolli | ea997ac | 2013-12-03 15:35:48 -0200 | [diff] [blame] | 3954 | |
| 3955 | surface = weston_surface_get_main_surface(focus); |
| 3956 | if (surface == NULL) |
| 3957 | return; |
| 3958 | |
| 3959 | shsurf = get_shell_surface(surface); |
| 3960 | if (shsurf == NULL) |
| 3961 | return; |
| 3962 | |
| 3963 | if (!shell_surface_is_xdg_surface(shsurf)) |
| 3964 | return; |
| 3965 | |
Kristian Høgsberg | 283bf37 | 2014-02-18 23:28:09 -0800 | [diff] [blame] | 3966 | serial = wl_display_next_serial(seat->compositor->wl_display); |
| 3967 | xdg_surface_change_state(shsurf, XDG_SURFACE_STATE_FULLSCREEN, |
| 3968 | !shsurf->state.fullscreen, serial); |
Rafael Antognolli | ea997ac | 2013-12-03 15:35:48 -0200 | [diff] [blame] | 3969 | } |
| 3970 | |
| 3971 | static void |
Neil Roberts | aba0f25 | 2013-10-03 16:43:05 +0100 | [diff] [blame] | 3972 | touch_move_binding(struct weston_seat *seat, uint32_t time, void *data) |
| 3973 | { |
Kristian Høgsberg | 7ab139c | 2013-10-24 16:21:39 -0700 | [diff] [blame] | 3974 | struct weston_surface *focus = seat->touch->focus->surface; |
Neil Roberts | aba0f25 | 2013-10-03 16:43:05 +0100 | [diff] [blame] | 3975 | struct weston_surface *surface; |
| 3976 | struct shell_surface *shsurf; |
| 3977 | |
| 3978 | surface = weston_surface_get_main_surface(focus); |
| 3979 | if (surface == NULL) |
| 3980 | return; |
| 3981 | |
| 3982 | shsurf = get_shell_surface(surface); |
Rafael Antognolli | 03b1659 | 2013-12-03 15:35:42 -0200 | [diff] [blame] | 3983 | if (shsurf == NULL || shsurf->state.fullscreen || |
| 3984 | shsurf->state.maximized) |
Neil Roberts | aba0f25 | 2013-10-03 16:43:05 +0100 | [diff] [blame] | 3985 | return; |
| 3986 | |
| 3987 | surface_touch_move(shsurf, (struct weston_seat *) seat); |
| 3988 | } |
| 3989 | |
| 3990 | static void |
Kristian Høgsberg | e314875 | 2013-05-06 23:19:49 -0400 | [diff] [blame] | 3991 | 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] | 3992 | { |
Rafal Mielniczuk | b2917a2 | 2014-01-05 20:04:59 +0100 | [diff] [blame] | 3993 | struct weston_surface *focus; |
Pekka Paalanen | 01388e2 | 2013-04-25 13:57:44 +0300 | [diff] [blame] | 3994 | struct weston_surface *surface; |
Kristian Høgsberg | 0793756 | 2011-04-12 17:25:42 -0400 | [diff] [blame] | 3995 | uint32_t edges = 0; |
| 3996 | int32_t x, y; |
Pekka Paalanen | 9d1613e | 2011-11-25 12:09:16 +0200 | [diff] [blame] | 3997 | struct shell_surface *shsurf; |
Kristian Høgsberg | d2abb83 | 2011-11-23 10:52:40 -0500 | [diff] [blame] | 3998 | |
Rafal Mielniczuk | b2917a2 | 2014-01-05 20:04:59 +0100 | [diff] [blame] | 3999 | if (seat->pointer->focus == NULL) |
| 4000 | return; |
| 4001 | |
| 4002 | focus = seat->pointer->focus->surface; |
| 4003 | |
Pekka Paalanen | 01388e2 | 2013-04-25 13:57:44 +0300 | [diff] [blame] | 4004 | surface = weston_surface_get_main_surface(focus); |
Benjamin Franzke | d0f79ab | 2011-11-22 12:43:52 +0100 | [diff] [blame] | 4005 | if (surface == NULL) |
| 4006 | return; |
Pekka Paalanen | 92a0dc4 | 2011-11-28 15:34:13 +0200 | [diff] [blame] | 4007 | |
Pekka Paalanen | 9d1613e | 2011-11-25 12:09:16 +0200 | [diff] [blame] | 4008 | shsurf = get_shell_surface(surface); |
Rafael Antognolli | 03b1659 | 2013-12-03 15:35:42 -0200 | [diff] [blame] | 4009 | if (shsurf == NULL || shsurf->state.fullscreen || |
| 4010 | shsurf->state.maximized) |
Pekka Paalanen | 92a0dc4 | 2011-11-28 15:34:13 +0200 | [diff] [blame] | 4011 | return; |
| 4012 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 4013 | weston_view_from_global(shsurf->view, |
| 4014 | wl_fixed_to_int(seat->pointer->grab_x), |
| 4015 | wl_fixed_to_int(seat->pointer->grab_y), |
| 4016 | &x, &y); |
Kristian Høgsberg | 0793756 | 2011-04-12 17:25:42 -0400 | [diff] [blame] | 4017 | |
Jason Ekstrand | 918f2dd | 2013-12-02 21:01:53 -0600 | [diff] [blame] | 4018 | if (x < shsurf->surface->width / 3) |
Pekka Paalanen | 9d1613e | 2011-11-25 12:09:16 +0200 | [diff] [blame] | 4019 | edges |= WL_SHELL_SURFACE_RESIZE_LEFT; |
Jason Ekstrand | 918f2dd | 2013-12-02 21:01:53 -0600 | [diff] [blame] | 4020 | else if (x < 2 * shsurf->surface->width / 3) |
Kristian Høgsberg | 0793756 | 2011-04-12 17:25:42 -0400 | [diff] [blame] | 4021 | edges |= 0; |
| 4022 | else |
Pekka Paalanen | 9d1613e | 2011-11-25 12:09:16 +0200 | [diff] [blame] | 4023 | edges |= WL_SHELL_SURFACE_RESIZE_RIGHT; |
Kristian Høgsberg | 0793756 | 2011-04-12 17:25:42 -0400 | [diff] [blame] | 4024 | |
Jason Ekstrand | 918f2dd | 2013-12-02 21:01:53 -0600 | [diff] [blame] | 4025 | if (y < shsurf->surface->height / 3) |
Pekka Paalanen | 9d1613e | 2011-11-25 12:09:16 +0200 | [diff] [blame] | 4026 | edges |= WL_SHELL_SURFACE_RESIZE_TOP; |
Jason Ekstrand | 918f2dd | 2013-12-02 21:01:53 -0600 | [diff] [blame] | 4027 | else if (y < 2 * shsurf->surface->height / 3) |
Kristian Høgsberg | 0793756 | 2011-04-12 17:25:42 -0400 | [diff] [blame] | 4028 | edges |= 0; |
| 4029 | else |
Pekka Paalanen | 9d1613e | 2011-11-25 12:09:16 +0200 | [diff] [blame] | 4030 | edges |= WL_SHELL_SURFACE_RESIZE_BOTTOM; |
Kristian Høgsberg | 0793756 | 2011-04-12 17:25:42 -0400 | [diff] [blame] | 4031 | |
Kristian Høgsberg | c1693f2 | 2012-05-22 16:56:23 -0400 | [diff] [blame] | 4032 | surface_resize(shsurf, (struct weston_seat *) seat, edges); |
Kristian Høgsberg | 02ec0a5 | 2011-04-23 13:04:11 -0400 | [diff] [blame] | 4033 | } |
| 4034 | |
| 4035 | static void |
Kristian Høgsberg | e314875 | 2013-05-06 23:19:49 -0400 | [diff] [blame] | 4036 | 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] | 4037 | wl_fixed_t value, void *data) |
Scott Moreau | a3aa9c9 | 2012-03-22 11:01:03 -0600 | [diff] [blame] | 4038 | { |
Jonas Ådahl | b0b87ba | 2012-09-27 18:40:42 +0200 | [diff] [blame] | 4039 | float step = 0.005; |
Scott Moreau | a3aa9c9 | 2012-03-22 11:01:03 -0600 | [diff] [blame] | 4040 | struct shell_surface *shsurf; |
Kristian Høgsberg | 7ab139c | 2013-10-24 16:21:39 -0700 | [diff] [blame] | 4041 | struct weston_surface *focus = seat->pointer->focus->surface; |
Pekka Paalanen | 01388e2 | 2013-04-25 13:57:44 +0300 | [diff] [blame] | 4042 | struct weston_surface *surface; |
Scott Moreau | a3aa9c9 | 2012-03-22 11:01:03 -0600 | [diff] [blame] | 4043 | |
Pekka Paalanen | 01388e2 | 2013-04-25 13:57:44 +0300 | [diff] [blame] | 4044 | /* XXX: broken for windows containing sub-surfaces */ |
| 4045 | surface = weston_surface_get_main_surface(focus); |
Scott Moreau | a3aa9c9 | 2012-03-22 11:01:03 -0600 | [diff] [blame] | 4046 | if (surface == NULL) |
| 4047 | return; |
| 4048 | |
| 4049 | shsurf = get_shell_surface(surface); |
| 4050 | if (!shsurf) |
| 4051 | return; |
| 4052 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 4053 | shsurf->view->alpha -= wl_fixed_to_double(value) * step; |
Scott Moreau | a3aa9c9 | 2012-03-22 11:01:03 -0600 | [diff] [blame] | 4054 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 4055 | if (shsurf->view->alpha > 1.0) |
| 4056 | shsurf->view->alpha = 1.0; |
| 4057 | if (shsurf->view->alpha < step) |
| 4058 | shsurf->view->alpha = step; |
Scott Moreau | a3aa9c9 | 2012-03-22 11:01:03 -0600 | [diff] [blame] | 4059 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 4060 | weston_view_geometry_dirty(shsurf->view); |
Scott Moreau | a3aa9c9 | 2012-03-22 11:01:03 -0600 | [diff] [blame] | 4061 | weston_surface_damage(surface); |
| 4062 | } |
| 4063 | |
| 4064 | static void |
Kristian Høgsberg | e314875 | 2013-05-06 23:19:49 -0400 | [diff] [blame] | 4065 | 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] | 4066 | wl_fixed_t value) |
Scott Moreau | ccbf29d | 2012-02-22 14:21:41 -0700 | [diff] [blame] | 4067 | { |
Daniel Stone | 37816df | 2012-05-16 18:45:18 +0100 | [diff] [blame] | 4068 | struct weston_seat *ws = (struct weston_seat *) seat; |
| 4069 | struct weston_compositor *compositor = ws->compositor; |
Scott Moreau | ccbf29d | 2012-02-22 14:21:41 -0700 | [diff] [blame] | 4070 | struct weston_output *output; |
Scott Moreau | e660398 | 2012-06-11 13:07:51 -0600 | [diff] [blame] | 4071 | float increment; |
Scott Moreau | ccbf29d | 2012-02-22 14:21:41 -0700 | [diff] [blame] | 4072 | |
| 4073 | wl_list_for_each(output, &compositor->output_list, link) { |
| 4074 | if (pixman_region32_contains_point(&output->region, |
Daniel Stone | 37816df | 2012-05-16 18:45:18 +0100 | [diff] [blame] | 4075 | wl_fixed_to_double(seat->pointer->x), |
| 4076 | wl_fixed_to_double(seat->pointer->y), |
Daniel Stone | 103db7f | 2012-05-08 17:17:55 +0100 | [diff] [blame] | 4077 | NULL)) { |
Daniel Stone | 325fc2d | 2012-05-30 16:31:58 +0100 | [diff] [blame] | 4078 | if (key == KEY_PAGEUP) |
Kristian Høgsberg | 9b68af0 | 2012-05-22 12:55:18 -0400 | [diff] [blame] | 4079 | increment = output->zoom.increment; |
Daniel Stone | 325fc2d | 2012-05-30 16:31:58 +0100 | [diff] [blame] | 4080 | else if (key == KEY_PAGEDOWN) |
Kristian Høgsberg | 9b68af0 | 2012-05-22 12:55:18 -0400 | [diff] [blame] | 4081 | increment = -output->zoom.increment; |
| 4082 | else if (axis == WL_POINTER_AXIS_VERTICAL_SCROLL) |
Jonas Ådahl | b0b87ba | 2012-09-27 18:40:42 +0200 | [diff] [blame] | 4083 | /* For every pixel zoom 20th of a step */ |
Daniel Stone | 0c1e46e | 2012-05-30 16:31:59 +0100 | [diff] [blame] | 4084 | increment = output->zoom.increment * |
Jonas Ådahl | b0b87ba | 2012-09-27 18:40:42 +0200 | [diff] [blame] | 4085 | -wl_fixed_to_double(value) / 20.0; |
Kristian Høgsberg | 9b68af0 | 2012-05-22 12:55:18 -0400 | [diff] [blame] | 4086 | else |
| 4087 | increment = 0; |
| 4088 | |
Kristian Høgsberg | 9b68af0 | 2012-05-22 12:55:18 -0400 | [diff] [blame] | 4089 | output->zoom.level += increment; |
Scott Moreau | c6d7f60 | 2012-02-23 22:28:37 -0700 | [diff] [blame] | 4090 | |
Scott Moreau | e660398 | 2012-06-11 13:07:51 -0600 | [diff] [blame] | 4091 | if (output->zoom.level < 0.0) |
Scott Moreau | 850ca42 | 2012-05-21 15:21:25 -0600 | [diff] [blame] | 4092 | output->zoom.level = 0.0; |
Scott Moreau | e660398 | 2012-06-11 13:07:51 -0600 | [diff] [blame] | 4093 | else if (output->zoom.level > output->zoom.max_level) |
| 4094 | output->zoom.level = output->zoom.max_level; |
Ville Syrjälä | aa628d0 | 2012-11-16 11:48:47 +0200 | [diff] [blame] | 4095 | else if (!output->zoom.active) { |
Giulio Camuffo | 412b024 | 2013-11-14 23:42:51 +0100 | [diff] [blame] | 4096 | weston_output_activate_zoom(output); |
Kristian Høgsberg | 79af73e | 2012-08-03 15:45:23 -0400 | [diff] [blame] | 4097 | } |
Scott Moreau | ccbf29d | 2012-02-22 14:21:41 -0700 | [diff] [blame] | 4098 | |
Scott Moreau | e660398 | 2012-06-11 13:07:51 -0600 | [diff] [blame] | 4099 | output->zoom.spring_z.target = output->zoom.level; |
Scott Moreau | ccbf29d | 2012-02-22 14:21:41 -0700 | [diff] [blame] | 4100 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 4101 | weston_output_update_zoom(output); |
Scott Moreau | ccbf29d | 2012-02-22 14:21:41 -0700 | [diff] [blame] | 4102 | } |
| 4103 | } |
| 4104 | } |
| 4105 | |
Scott Moreau | ccbf29d | 2012-02-22 14:21:41 -0700 | [diff] [blame] | 4106 | static void |
Kristian Høgsberg | e314875 | 2013-05-06 23:19:49 -0400 | [diff] [blame] | 4107 | 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] | 4108 | wl_fixed_t value, void *data) |
Daniel Stone | 325fc2d | 2012-05-30 16:31:58 +0100 | [diff] [blame] | 4109 | { |
| 4110 | do_zoom(seat, time, 0, axis, value); |
| 4111 | } |
| 4112 | |
| 4113 | static void |
Kristian Høgsberg | e314875 | 2013-05-06 23:19:49 -0400 | [diff] [blame] | 4114 | 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] | 4115 | void *data) |
| 4116 | { |
| 4117 | do_zoom(seat, time, key, 0, 0); |
| 4118 | } |
| 4119 | |
| 4120 | static void |
Kristian Høgsberg | e314875 | 2013-05-06 23:19:49 -0400 | [diff] [blame] | 4121 | terminate_binding(struct weston_seat *seat, uint32_t time, uint32_t key, |
Daniel Stone | 325fc2d | 2012-05-30 16:31:58 +0100 | [diff] [blame] | 4122 | void *data) |
Kristian Høgsberg | e1a850e | 2011-12-19 15:18:05 -0500 | [diff] [blame] | 4123 | { |
Kristian Høgsberg | 8334bc1 | 2012-01-03 10:29:47 -0500 | [diff] [blame] | 4124 | struct weston_compositor *compositor = data; |
Kristian Høgsberg | e1a850e | 2011-12-19 15:18:05 -0500 | [diff] [blame] | 4125 | |
Daniel Stone | 325fc2d | 2012-05-30 16:31:58 +0100 | [diff] [blame] | 4126 | wl_display_terminate(compositor->wl_display); |
Kristian Høgsberg | e1a850e | 2011-12-19 15:18:05 -0500 | [diff] [blame] | 4127 | } |
| 4128 | |
Emilio Pozuelo Monfort | 03251b6 | 2013-11-19 11:37:16 +0100 | [diff] [blame] | 4129 | static void |
Giulio Camuffo | 1959ab8 | 2013-11-14 23:42:52 +0100 | [diff] [blame] | 4130 | rotate_grab_motion(struct weston_pointer_grab *grab, uint32_t time, |
| 4131 | wl_fixed_t x, wl_fixed_t y) |
Pekka Paalanen | 460099f | 2012-01-20 16:48:25 +0200 | [diff] [blame] | 4132 | { |
| 4133 | struct rotate_grab *rotate = |
Ander Conselvan de Oliveira | fe0444a | 2012-04-04 17:48:05 +0300 | [diff] [blame] | 4134 | container_of(grab, struct rotate_grab, base.grab); |
Kristian Høgsberg | 02bbabb | 2013-05-06 22:15:05 -0400 | [diff] [blame] | 4135 | struct weston_pointer *pointer = grab->pointer; |
Ander Conselvan de Oliveira | fe0444a | 2012-04-04 17:48:05 +0300 | [diff] [blame] | 4136 | struct shell_surface *shsurf = rotate->base.shsurf; |
John Kåre Alsaker | 490d02a | 2012-09-30 02:57:21 +0200 | [diff] [blame] | 4137 | float cx, cy, dx, dy, cposx, cposy, dposx, dposy, r; |
Ander Conselvan de Oliveira | fe0444a | 2012-04-04 17:48:05 +0300 | [diff] [blame] | 4138 | |
Giulio Camuffo | 1959ab8 | 2013-11-14 23:42:52 +0100 | [diff] [blame] | 4139 | weston_pointer_move(pointer, x, y); |
| 4140 | |
Ander Conselvan de Oliveira | fe0444a | 2012-04-04 17:48:05 +0300 | [diff] [blame] | 4141 | if (!shsurf) |
| 4142 | return; |
| 4143 | |
Jason Ekstrand | 918f2dd | 2013-12-02 21:01:53 -0600 | [diff] [blame] | 4144 | cx = 0.5f * shsurf->surface->width; |
| 4145 | cy = 0.5f * shsurf->surface->height; |
Pekka Paalanen | 460099f | 2012-01-20 16:48:25 +0200 | [diff] [blame] | 4146 | |
Daniel Stone | 37816df | 2012-05-16 18:45:18 +0100 | [diff] [blame] | 4147 | dx = wl_fixed_to_double(pointer->x) - rotate->center.x; |
| 4148 | dy = wl_fixed_to_double(pointer->y) - rotate->center.y; |
Pekka Paalanen | 460099f | 2012-01-20 16:48:25 +0200 | [diff] [blame] | 4149 | r = sqrtf(dx * dx + dy * dy); |
| 4150 | |
Ander Conselvan de Oliveira | fe0444a | 2012-04-04 17:48:05 +0300 | [diff] [blame] | 4151 | wl_list_remove(&shsurf->rotation.transform.link); |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 4152 | weston_view_geometry_dirty(shsurf->view); |
Pekka Paalanen | 460099f | 2012-01-20 16:48:25 +0200 | [diff] [blame] | 4153 | |
| 4154 | if (r > 20.0f) { |
Pekka Paalanen | 460099f | 2012-01-20 16:48:25 +0200 | [diff] [blame] | 4155 | struct weston_matrix *matrix = |
Ander Conselvan de Oliveira | fe0444a | 2012-04-04 17:48:05 +0300 | [diff] [blame] | 4156 | &shsurf->rotation.transform.matrix; |
Pekka Paalanen | 460099f | 2012-01-20 16:48:25 +0200 | [diff] [blame] | 4157 | |
Kristian Høgsberg | 765e27b | 2012-01-27 13:36:13 -0500 | [diff] [blame] | 4158 | weston_matrix_init(&rotate->rotation); |
Vasily Khoruzhick | 1bbf372 | 2013-01-28 22:40:28 +0300 | [diff] [blame] | 4159 | weston_matrix_rotate_xy(&rotate->rotation, dx / r, dy / r); |
Pekka Paalanen | 460099f | 2012-01-20 16:48:25 +0200 | [diff] [blame] | 4160 | |
| 4161 | weston_matrix_init(matrix); |
Pekka Paalanen | 7b3bd3d | 2012-01-30 14:16:34 +0200 | [diff] [blame] | 4162 | weston_matrix_translate(matrix, -cx, -cy, 0.0f); |
Ander Conselvan de Oliveira | fe0444a | 2012-04-04 17:48:05 +0300 | [diff] [blame] | 4163 | weston_matrix_multiply(matrix, &shsurf->rotation.rotation); |
Kristian Høgsberg | 765e27b | 2012-01-27 13:36:13 -0500 | [diff] [blame] | 4164 | weston_matrix_multiply(matrix, &rotate->rotation); |
Pekka Paalanen | 7b3bd3d | 2012-01-30 14:16:34 +0200 | [diff] [blame] | 4165 | weston_matrix_translate(matrix, cx, cy, 0.0f); |
Pekka Paalanen | 460099f | 2012-01-20 16:48:25 +0200 | [diff] [blame] | 4166 | |
Pekka Paalanen | bc0b7e7 | 2012-01-24 09:53:37 +0200 | [diff] [blame] | 4167 | wl_list_insert( |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 4168 | &shsurf->view->geometry.transformation_list, |
Ander Conselvan de Oliveira | fe0444a | 2012-04-04 17:48:05 +0300 | [diff] [blame] | 4169 | &shsurf->rotation.transform.link); |
Pekka Paalanen | 460099f | 2012-01-20 16:48:25 +0200 | [diff] [blame] | 4170 | } else { |
Ander Conselvan de Oliveira | fe0444a | 2012-04-04 17:48:05 +0300 | [diff] [blame] | 4171 | wl_list_init(&shsurf->rotation.transform.link); |
| 4172 | weston_matrix_init(&shsurf->rotation.rotation); |
Kristian Høgsberg | 765e27b | 2012-01-27 13:36:13 -0500 | [diff] [blame] | 4173 | weston_matrix_init(&rotate->rotation); |
Pekka Paalanen | 460099f | 2012-01-20 16:48:25 +0200 | [diff] [blame] | 4174 | } |
Pekka Paalanen | b45ac5e | 2012-02-09 15:58:44 +0200 | [diff] [blame] | 4175 | |
Rafal Mielniczuk | 2d7ab82 | 2012-03-22 22:22:04 +0100 | [diff] [blame] | 4176 | /* We need to adjust the position of the surface |
| 4177 | * in case it was resized in a rotated state before */ |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 4178 | cposx = shsurf->view->geometry.x + cx; |
| 4179 | cposy = shsurf->view->geometry.y + cy; |
Rafal Mielniczuk | 2d7ab82 | 2012-03-22 22:22:04 +0100 | [diff] [blame] | 4180 | dposx = rotate->center.x - cposx; |
| 4181 | dposy = rotate->center.y - cposy; |
| 4182 | if (dposx != 0.0f || dposy != 0.0f) { |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 4183 | weston_view_set_position(shsurf->view, |
| 4184 | shsurf->view->geometry.x + dposx, |
| 4185 | shsurf->view->geometry.y + dposy); |
Rafal Mielniczuk | 2d7ab82 | 2012-03-22 22:22:04 +0100 | [diff] [blame] | 4186 | } |
| 4187 | |
Pekka Paalanen | b45ac5e | 2012-02-09 15:58:44 +0200 | [diff] [blame] | 4188 | /* Repaint implies weston_surface_update_transform(), which |
| 4189 | * lazily applies the damage due to rotation update. |
| 4190 | */ |
Ander Conselvan de Oliveira | fe0444a | 2012-04-04 17:48:05 +0300 | [diff] [blame] | 4191 | weston_compositor_schedule_repaint(shsurf->surface->compositor); |
Pekka Paalanen | 460099f | 2012-01-20 16:48:25 +0200 | [diff] [blame] | 4192 | } |
| 4193 | |
| 4194 | static void |
Kristian Høgsberg | 02bbabb | 2013-05-06 22:15:05 -0400 | [diff] [blame] | 4195 | rotate_grab_button(struct weston_pointer_grab *grab, |
| 4196 | uint32_t time, uint32_t button, uint32_t state_w) |
Pekka Paalanen | 460099f | 2012-01-20 16:48:25 +0200 | [diff] [blame] | 4197 | { |
| 4198 | struct rotate_grab *rotate = |
Ander Conselvan de Oliveira | fe0444a | 2012-04-04 17:48:05 +0300 | [diff] [blame] | 4199 | container_of(grab, struct rotate_grab, base.grab); |
Kristian Høgsberg | 02bbabb | 2013-05-06 22:15:05 -0400 | [diff] [blame] | 4200 | struct weston_pointer *pointer = grab->pointer; |
Ander Conselvan de Oliveira | fe0444a | 2012-04-04 17:48:05 +0300 | [diff] [blame] | 4201 | struct shell_surface *shsurf = rotate->base.shsurf; |
Daniel Stone | 4dbadb1 | 2012-05-30 16:31:51 +0100 | [diff] [blame] | 4202 | enum wl_pointer_button_state state = state_w; |
Pekka Paalanen | 460099f | 2012-01-20 16:48:25 +0200 | [diff] [blame] | 4203 | |
Daniel Stone | 4dbadb1 | 2012-05-30 16:31:51 +0100 | [diff] [blame] | 4204 | if (pointer->button_count == 0 && |
| 4205 | state == WL_POINTER_BUTTON_STATE_RELEASED) { |
Ander Conselvan de Oliveira | fe0444a | 2012-04-04 17:48:05 +0300 | [diff] [blame] | 4206 | if (shsurf) |
| 4207 | weston_matrix_multiply(&shsurf->rotation.rotation, |
| 4208 | &rotate->rotation); |
Ander Conselvan de Oliveira | b9d2a0f | 2012-06-28 18:08:05 +0300 | [diff] [blame] | 4209 | shell_grab_end(&rotate->base); |
Pekka Paalanen | 460099f | 2012-01-20 16:48:25 +0200 | [diff] [blame] | 4210 | free(rotate); |
| 4211 | } |
| 4212 | } |
| 4213 | |
Jonas Ådahl | 1ea343e | 2013-10-25 23:18:05 +0200 | [diff] [blame] | 4214 | static void |
| 4215 | rotate_grab_cancel(struct weston_pointer_grab *grab) |
| 4216 | { |
| 4217 | struct rotate_grab *rotate = |
| 4218 | container_of(grab, struct rotate_grab, base.grab); |
| 4219 | |
| 4220 | shell_grab_end(&rotate->base); |
| 4221 | free(rotate); |
| 4222 | } |
| 4223 | |
Kristian Høgsberg | 02bbabb | 2013-05-06 22:15:05 -0400 | [diff] [blame] | 4224 | static const struct weston_pointer_grab_interface rotate_grab_interface = { |
Pekka Paalanen | 460099f | 2012-01-20 16:48:25 +0200 | [diff] [blame] | 4225 | noop_grab_focus, |
| 4226 | rotate_grab_motion, |
| 4227 | rotate_grab_button, |
Jonas Ådahl | 1ea343e | 2013-10-25 23:18:05 +0200 | [diff] [blame] | 4228 | rotate_grab_cancel, |
Pekka Paalanen | 460099f | 2012-01-20 16:48:25 +0200 | [diff] [blame] | 4229 | }; |
| 4230 | |
| 4231 | static void |
Kristian Høgsberg | e314875 | 2013-05-06 23:19:49 -0400 | [diff] [blame] | 4232 | surface_rotate(struct shell_surface *surface, struct weston_seat *seat) |
Pekka Paalanen | 460099f | 2012-01-20 16:48:25 +0200 | [diff] [blame] | 4233 | { |
Pekka Paalanen | 460099f | 2012-01-20 16:48:25 +0200 | [diff] [blame] | 4234 | struct rotate_grab *rotate; |
John Kåre Alsaker | 490d02a | 2012-09-30 02:57:21 +0200 | [diff] [blame] | 4235 | float dx, dy; |
| 4236 | float r; |
Pekka Paalanen | 460099f | 2012-01-20 16:48:25 +0200 | [diff] [blame] | 4237 | |
Pekka Paalanen | 460099f | 2012-01-20 16:48:25 +0200 | [diff] [blame] | 4238 | rotate = malloc(sizeof *rotate); |
| 4239 | if (!rotate) |
| 4240 | return; |
| 4241 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 4242 | weston_view_to_global_float(surface->view, |
Jason Ekstrand | 918f2dd | 2013-12-02 21:01:53 -0600 | [diff] [blame] | 4243 | surface->surface->width * 0.5f, |
| 4244 | surface->surface->height * 0.5f, |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 4245 | &rotate->center.x, &rotate->center.y); |
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(seat->pointer->x) - rotate->center.x; |
| 4248 | dy = wl_fixed_to_double(seat->pointer->y) - rotate->center.y; |
Kristian Høgsberg | 765e27b | 2012-01-27 13:36:13 -0500 | [diff] [blame] | 4249 | r = sqrtf(dx * dx + dy * dy); |
| 4250 | if (r > 20.0f) { |
| 4251 | struct weston_matrix inverse; |
| 4252 | |
| 4253 | weston_matrix_init(&inverse); |
Vasily Khoruzhick | 1bbf372 | 2013-01-28 22:40:28 +0300 | [diff] [blame] | 4254 | weston_matrix_rotate_xy(&inverse, dx / r, -dy / r); |
Kristian Høgsberg | 765e27b | 2012-01-27 13:36:13 -0500 | [diff] [blame] | 4255 | weston_matrix_multiply(&surface->rotation.rotation, &inverse); |
Rafal Mielniczuk | 2d7ab82 | 2012-03-22 22:22:04 +0100 | [diff] [blame] | 4256 | |
| 4257 | weston_matrix_init(&rotate->rotation); |
Vasily Khoruzhick | 1bbf372 | 2013-01-28 22:40:28 +0300 | [diff] [blame] | 4258 | weston_matrix_rotate_xy(&rotate->rotation, dx / r, dy / r); |
Kristian Høgsberg | 765e27b | 2012-01-27 13:36:13 -0500 | [diff] [blame] | 4259 | } else { |
| 4260 | weston_matrix_init(&surface->rotation.rotation); |
| 4261 | weston_matrix_init(&rotate->rotation); |
| 4262 | } |
| 4263 | |
Ander Conselvan de Oliveira | b9d2a0f | 2012-06-28 18:08:05 +0300 | [diff] [blame] | 4264 | shell_grab_start(&rotate->base, &rotate_grab_interface, surface, |
| 4265 | seat->pointer, DESKTOP_SHELL_CURSOR_ARROW); |
Pekka Paalanen | 460099f | 2012-01-20 16:48:25 +0200 | [diff] [blame] | 4266 | } |
| 4267 | |
| 4268 | static void |
Kristian Høgsberg | e314875 | 2013-05-06 23:19:49 -0400 | [diff] [blame] | 4269 | 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] | 4270 | void *data) |
| 4271 | { |
Rafal Mielniczuk | b2917a2 | 2014-01-05 20:04:59 +0100 | [diff] [blame] | 4272 | struct weston_surface *focus; |
Pekka Paalanen | 01388e2 | 2013-04-25 13:57:44 +0300 | [diff] [blame] | 4273 | struct weston_surface *base_surface; |
Kristian Høgsberg | 0c36903 | 2013-02-14 21:31:44 -0500 | [diff] [blame] | 4274 | struct shell_surface *surface; |
| 4275 | |
Rafal Mielniczuk | b2917a2 | 2014-01-05 20:04:59 +0100 | [diff] [blame] | 4276 | if (seat->pointer->focus == NULL) |
| 4277 | return; |
| 4278 | |
| 4279 | focus = seat->pointer->focus->surface; |
| 4280 | |
Pekka Paalanen | 01388e2 | 2013-04-25 13:57:44 +0300 | [diff] [blame] | 4281 | base_surface = weston_surface_get_main_surface(focus); |
Kristian Høgsberg | 0c36903 | 2013-02-14 21:31:44 -0500 | [diff] [blame] | 4282 | if (base_surface == NULL) |
| 4283 | return; |
| 4284 | |
| 4285 | surface = get_shell_surface(base_surface); |
Rafael Antognolli | 03b1659 | 2013-12-03 15:35:42 -0200 | [diff] [blame] | 4286 | if (surface == NULL || surface->state.fullscreen || |
| 4287 | surface->state.maximized) |
Kristian Høgsberg | 0c36903 | 2013-02-14 21:31:44 -0500 | [diff] [blame] | 4288 | return; |
| 4289 | |
| 4290 | surface_rotate(surface, seat); |
| 4291 | } |
| 4292 | |
Philip Withnall | 83ffd9d | 2013-11-25 18:01:42 +0000 | [diff] [blame] | 4293 | /* Move all fullscreen layers down to the current workspace in a non-reversible |
| 4294 | * manner. This should be used when implementing shell-wide overlays, such as |
| 4295 | * the alt-tab switcher, which need to de-promote fullscreen layers. */ |
Kristian Høgsberg | 1ef2313 | 2013-12-04 00:20:01 -0800 | [diff] [blame] | 4296 | void |
Kristian Høgsberg | b0d8e77 | 2012-06-18 16:34:58 -0400 | [diff] [blame] | 4297 | lower_fullscreen_layer(struct desktop_shell *shell) |
| 4298 | { |
| 4299 | struct workspace *ws; |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 4300 | struct weston_view *view, *prev; |
Kristian Høgsberg | b0d8e77 | 2012-06-18 16:34:58 -0400 | [diff] [blame] | 4301 | |
| 4302 | ws = get_current_workspace(shell); |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 4303 | wl_list_for_each_reverse_safe(view, prev, |
| 4304 | &shell->fullscreen_layer.view_list, |
Philip Withnall | 83ffd9d | 2013-11-25 18:01:42 +0000 | [diff] [blame] | 4305 | layer_link) { |
| 4306 | wl_list_remove(&view->layer_link); |
| 4307 | wl_list_insert(&ws->layer.view_list, &view->layer_link); |
| 4308 | weston_view_damage_below(view); |
| 4309 | weston_surface_damage(view->surface); |
| 4310 | } |
Kristian Høgsberg | b0d8e77 | 2012-06-18 16:34:58 -0400 | [diff] [blame] | 4311 | } |
| 4312 | |
Kristian Høgsberg | 1ef2313 | 2013-12-04 00:20:01 -0800 | [diff] [blame] | 4313 | void |
Tiago Vignatti | be14326 | 2012-04-16 17:31:41 +0300 | [diff] [blame] | 4314 | activate(struct desktop_shell *shell, struct weston_surface *es, |
Daniel Stone | 37816df | 2012-05-16 18:45:18 +0100 | [diff] [blame] | 4315 | struct weston_seat *seat) |
Kristian Høgsberg | 7584062 | 2011-09-06 13:48:16 -0400 | [diff] [blame] | 4316 | { |
Pekka Paalanen | 01388e2 | 2013-04-25 13:57:44 +0300 | [diff] [blame] | 4317 | struct weston_surface *main_surface; |
Kristian Høgsberg | 2f5faff | 2012-07-31 16:36:34 -0400 | [diff] [blame] | 4318 | struct focus_state *state; |
Jonas Ådahl | 8538b22 | 2012-08-29 22:13:03 +0200 | [diff] [blame] | 4319 | struct workspace *ws; |
Louis-Francis Ratté-Boulianne | b482dbd | 2013-11-19 11:37:11 +0100 | [diff] [blame] | 4320 | struct weston_surface *old_es; |
Rafael Antognolli | 03b1659 | 2013-12-03 15:35:42 -0200 | [diff] [blame] | 4321 | struct shell_surface *shsurf; |
Kristian Høgsberg | 7584062 | 2011-09-06 13:48:16 -0400 | [diff] [blame] | 4322 | |
Pekka Paalanen | 01388e2 | 2013-04-25 13:57:44 +0300 | [diff] [blame] | 4323 | main_surface = weston_surface_get_main_surface(es); |
| 4324 | |
Daniel Stone | 37816df | 2012-05-16 18:45:18 +0100 | [diff] [blame] | 4325 | weston_surface_activate(es, seat); |
Kristian Høgsberg | 7584062 | 2011-09-06 13:48:16 -0400 | [diff] [blame] | 4326 | |
Jonas Ådahl | 8538b22 | 2012-08-29 22:13:03 +0200 | [diff] [blame] | 4327 | state = ensure_focus_state(shell, seat); |
| 4328 | if (state == NULL) |
| 4329 | return; |
Kristian Høgsberg | 2f5faff | 2012-07-31 16:36:34 -0400 | [diff] [blame] | 4330 | |
Louis-Francis Ratté-Boulianne | b482dbd | 2013-11-19 11:37:11 +0100 | [diff] [blame] | 4331 | old_es = state->keyboard_focus; |
Kristian Høgsberg | d500bf1 | 2014-01-22 12:25:20 -0800 | [diff] [blame] | 4332 | focus_state_set_focus(state, es); |
Kristian Høgsberg | 2f5faff | 2012-07-31 16:36:34 -0400 | [diff] [blame] | 4333 | |
Rafael Antognolli | 03b1659 | 2013-12-03 15:35:42 -0200 | [diff] [blame] | 4334 | shsurf = get_shell_surface(main_surface); |
U. Artie Eoff | cf5737a | 2014-01-17 10:08:25 -0800 | [diff] [blame] | 4335 | assert(shsurf); |
| 4336 | |
Rafael Antognolli | 03b1659 | 2013-12-03 15:35:42 -0200 | [diff] [blame] | 4337 | if (shsurf->state.fullscreen) |
| 4338 | shell_configure_fullscreen(shsurf); |
| 4339 | else |
Alexander Larsson | f82b6ca | 2013-05-28 16:23:39 +0200 | [diff] [blame] | 4340 | restore_all_output_modes(shell->compositor); |
Louis-Francis Ratté-Boulianne | b482dbd | 2013-11-19 11:37:11 +0100 | [diff] [blame] | 4341 | |
Emilio Pozuelo Monfort | 7908bff | 2014-01-30 13:49:39 +0100 | [diff] [blame] | 4342 | /* Update the surface’s layer. This brings it to the top of the stacking |
| 4343 | * order as appropriate. */ |
| 4344 | shell_surface_update_layer(shsurf); |
| 4345 | |
Philip Withnall | 83ffd9d | 2013-11-25 18:01:42 +0000 | [diff] [blame] | 4346 | if (shell->focus_animation_type != ANIMATION_NONE) { |
| 4347 | ws = get_current_workspace(shell); |
Louis-Francis Ratté-Boulianne | b482dbd | 2013-11-19 11:37:11 +0100 | [diff] [blame] | 4348 | 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] | 4349 | } |
Kristian Høgsberg | 7584062 | 2011-09-06 13:48:16 -0400 | [diff] [blame] | 4350 | } |
| 4351 | |
Alex Wu | 2185843 | 2012-04-01 20:13:08 +0800 | [diff] [blame] | 4352 | /* no-op func for checking black surface */ |
| 4353 | static void |
Jason Ekstrand | 918f2dd | 2013-12-02 21:01:53 -0600 | [diff] [blame] | 4354 | 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] | 4355 | { |
| 4356 | } |
| 4357 | |
Quentin Glidic | c0d79ce | 2013-01-29 14:16:13 +0100 | [diff] [blame] | 4358 | static bool |
Alex Wu | 2185843 | 2012-04-01 20:13:08 +0800 | [diff] [blame] | 4359 | is_black_surface (struct weston_surface *es, struct weston_surface **fs_surface) |
| 4360 | { |
| 4361 | if (es->configure == black_surface_configure) { |
| 4362 | if (fs_surface) |
Giulio Camuffo | 7fe01b1 | 2013-03-28 18:02:42 +0100 | [diff] [blame] | 4363 | *fs_surface = (struct weston_surface *)es->configure_private; |
Alex Wu | 2185843 | 2012-04-01 20:13:08 +0800 | [diff] [blame] | 4364 | return true; |
| 4365 | } |
| 4366 | return false; |
| 4367 | } |
| 4368 | |
Kristian Høgsberg | 7584062 | 2011-09-06 13:48:16 -0400 | [diff] [blame] | 4369 | static void |
Neil Roberts | a28c693 | 2013-10-03 16:43:04 +0100 | [diff] [blame] | 4370 | activate_binding(struct weston_seat *seat, |
| 4371 | struct desktop_shell *shell, |
| 4372 | struct weston_surface *focus) |
Kristian Høgsberg | e1a850e | 2011-12-19 15:18:05 -0500 | [diff] [blame] | 4373 | { |
Pekka Paalanen | 01388e2 | 2013-04-25 13:57:44 +0300 | [diff] [blame] | 4374 | struct weston_surface *main_surface; |
Kristian Høgsberg | e1a850e | 2011-12-19 15:18:05 -0500 | [diff] [blame] | 4375 | |
Alex Wu | 9c35e6b | 2012-03-05 14:13:13 +0800 | [diff] [blame] | 4376 | if (!focus) |
| 4377 | return; |
| 4378 | |
Pekka Paalanen | 01388e2 | 2013-04-25 13:57:44 +0300 | [diff] [blame] | 4379 | if (is_black_surface(focus, &main_surface)) |
| 4380 | focus = main_surface; |
Alex Wu | 4539b08 | 2012-03-01 12:57:46 +0800 | [diff] [blame] | 4381 | |
Pekka Paalanen | 01388e2 | 2013-04-25 13:57:44 +0300 | [diff] [blame] | 4382 | main_surface = weston_surface_get_main_surface(focus); |
| 4383 | if (get_shell_surface_type(main_surface) == SHELL_SURFACE_NONE) |
Kristian Høgsberg | 0636ac3 | 2012-06-27 10:22:15 -0400 | [diff] [blame] | 4384 | return; |
Kristian Høgsberg | 85b2e4b | 2012-06-21 16:49:42 -0400 | [diff] [blame] | 4385 | |
Neil Roberts | a28c693 | 2013-10-03 16:43:04 +0100 | [diff] [blame] | 4386 | activate(shell, focus, seat); |
| 4387 | } |
| 4388 | |
| 4389 | static void |
| 4390 | click_to_activate_binding(struct weston_seat *seat, uint32_t time, uint32_t button, |
| 4391 | void *data) |
| 4392 | { |
| 4393 | if (seat->pointer->grab != &seat->pointer->default_grab) |
| 4394 | return; |
Kristian Høgsberg | 7c4f6cc | 2014-01-01 16:28:32 -0800 | [diff] [blame] | 4395 | if (seat->pointer->focus == NULL) |
| 4396 | return; |
Neil Roberts | a28c693 | 2013-10-03 16:43:04 +0100 | [diff] [blame] | 4397 | |
Kristian Høgsberg | 7ab139c | 2013-10-24 16:21:39 -0700 | [diff] [blame] | 4398 | activate_binding(seat, data, seat->pointer->focus->surface); |
Neil Roberts | a28c693 | 2013-10-03 16:43:04 +0100 | [diff] [blame] | 4399 | } |
| 4400 | |
| 4401 | static void |
| 4402 | touch_to_activate_binding(struct weston_seat *seat, uint32_t time, void *data) |
| 4403 | { |
| 4404 | if (seat->touch->grab != &seat->touch->default_grab) |
| 4405 | return; |
Kristian Høgsberg | 0ed6750 | 2014-01-02 23:00:11 -0800 | [diff] [blame] | 4406 | if (seat->touch->focus == NULL) |
| 4407 | return; |
Neil Roberts | a28c693 | 2013-10-03 16:43:04 +0100 | [diff] [blame] | 4408 | |
Kristian Høgsberg | 7ab139c | 2013-10-24 16:21:39 -0700 | [diff] [blame] | 4409 | activate_binding(seat, data, seat->touch->focus->surface); |
Kristian Høgsberg | e1a850e | 2011-12-19 15:18:05 -0500 | [diff] [blame] | 4410 | } |
| 4411 | |
| 4412 | static void |
Ander Conselvan de Oliveira | 19d10ef | 2013-02-21 18:35:20 +0200 | [diff] [blame] | 4413 | lock(struct desktop_shell *shell) |
Kristian Høgsberg | 02ec0a5 | 2011-04-23 13:04:11 -0400 | [diff] [blame] | 4414 | { |
Kristian Høgsberg | 4476aaf | 2012-06-25 14:03:13 -0400 | [diff] [blame] | 4415 | struct workspace *ws = get_current_workspace(shell); |
Pekka Paalanen | f0fc70d | 2011-11-15 13:34:54 +0200 | [diff] [blame] | 4416 | |
Tiago Vignatti | 8e53c7f | 2012-02-29 19:53:50 +0200 | [diff] [blame] | 4417 | if (shell->locked) { |
Ander Conselvan de Oliveira | 87524b6 | 2013-02-21 18:35:22 +0200 | [diff] [blame] | 4418 | weston_compositor_sleep(shell->compositor); |
Pekka Paalanen | f0fc70d | 2011-11-15 13:34:54 +0200 | [diff] [blame] | 4419 | return; |
Tiago Vignatti | 8e53c7f | 2012-02-29 19:53:50 +0200 | [diff] [blame] | 4420 | } |
Pekka Paalanen | 9ef3e01 | 2011-11-15 13:34:48 +0200 | [diff] [blame] | 4421 | |
| 4422 | shell->locked = true; |
Pekka Paalanen | f0fc70d | 2011-11-15 13:34:54 +0200 | [diff] [blame] | 4423 | |
Kristian Høgsberg | 3be2ce9 | 2012-02-29 12:42:35 -0500 | [diff] [blame] | 4424 | /* Hide all surfaces by removing the fullscreen, panel and |
| 4425 | * toplevel layers. This way nothing else can show or receive |
| 4426 | * input events while we are locked. */ |
Pekka Paalanen | f0fc70d | 2011-11-15 13:34:54 +0200 | [diff] [blame] | 4427 | |
Kristian Høgsberg | 3be2ce9 | 2012-02-29 12:42:35 -0500 | [diff] [blame] | 4428 | wl_list_remove(&shell->panel_layer.link); |
Kristian Høgsberg | 3be2ce9 | 2012-02-29 12:42:35 -0500 | [diff] [blame] | 4429 | wl_list_remove(&shell->fullscreen_layer.link); |
Philipp Brüschweiler | 711fda8 | 2012-08-09 18:50:43 +0200 | [diff] [blame] | 4430 | if (shell->showing_input_panels) |
| 4431 | wl_list_remove(&shell->input_panel_layer.link); |
Kristian Høgsberg | 4476aaf | 2012-06-25 14:03:13 -0400 | [diff] [blame] | 4432 | wl_list_remove(&ws->layer.link); |
Kristian Høgsberg | 3be2ce9 | 2012-02-29 12:42:35 -0500 | [diff] [blame] | 4433 | wl_list_insert(&shell->compositor->cursor_layer.link, |
| 4434 | &shell->lock_layer.link); |
Pekka Paalanen | f0fc70d | 2011-11-15 13:34:54 +0200 | [diff] [blame] | 4435 | |
Pekka Paalanen | 77346a6 | 2011-11-30 16:26:35 +0200 | [diff] [blame] | 4436 | launch_screensaver(shell); |
| 4437 | |
Pekka Paalanen | f0fc70d | 2011-11-15 13:34:54 +0200 | [diff] [blame] | 4438 | /* TODO: disable bindings that should not work while locked. */ |
| 4439 | |
| 4440 | /* All this must be undone in resume_desktop(). */ |
Pekka Paalanen | 9ef3e01 | 2011-11-15 13:34:48 +0200 | [diff] [blame] | 4441 | } |
| 4442 | |
| 4443 | static void |
Ander Conselvan de Oliveira | 19d10ef | 2013-02-21 18:35:20 +0200 | [diff] [blame] | 4444 | unlock(struct desktop_shell *shell) |
Pekka Paalanen | 9ef3e01 | 2011-11-15 13:34:48 +0200 | [diff] [blame] | 4445 | { |
Pekka Paalanen | d81c216 | 2011-11-16 13:47:34 +0200 | [diff] [blame] | 4446 | if (!shell->locked || shell->lock_surface) { |
Ander Conselvan de Oliveira | 87524b6 | 2013-02-21 18:35:22 +0200 | [diff] [blame] | 4447 | shell_fade(shell, FADE_IN); |
Pekka Paalanen | 9ef3e01 | 2011-11-15 13:34:48 +0200 | [diff] [blame] | 4448 | return; |
| 4449 | } |
| 4450 | |
| 4451 | /* If desktop-shell client has gone away, unlock immediately. */ |
| 4452 | if (!shell->child.desktop_shell) { |
Pekka Paalanen | f0fc70d | 2011-11-15 13:34:54 +0200 | [diff] [blame] | 4453 | resume_desktop(shell); |
Pekka Paalanen | 9ef3e01 | 2011-11-15 13:34:48 +0200 | [diff] [blame] | 4454 | return; |
| 4455 | } |
| 4456 | |
| 4457 | if (shell->prepare_event_sent) |
| 4458 | return; |
| 4459 | |
Kristian Høgsberg | 0b5cd0c | 2012-03-04 21:57:37 -0500 | [diff] [blame] | 4460 | desktop_shell_send_prepare_lock_surface(shell->child.desktop_shell); |
Pekka Paalanen | 9ef3e01 | 2011-11-15 13:34:48 +0200 | [diff] [blame] | 4461 | shell->prepare_event_sent = true; |
Kristian Høgsberg | 02ec0a5 | 2011-04-23 13:04:11 -0400 | [diff] [blame] | 4462 | } |
| 4463 | |
| 4464 | static void |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 4465 | shell_fade_done(struct weston_view_animation *animation, void *data) |
Ander Conselvan de Oliveira | 19d10ef | 2013-02-21 18:35:20 +0200 | [diff] [blame] | 4466 | { |
| 4467 | struct desktop_shell *shell = data; |
| 4468 | |
| 4469 | shell->fade.animation = NULL; |
| 4470 | |
| 4471 | switch (shell->fade.type) { |
| 4472 | case FADE_IN: |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 4473 | weston_surface_destroy(shell->fade.view->surface); |
| 4474 | shell->fade.view = NULL; |
Ander Conselvan de Oliveira | 19d10ef | 2013-02-21 18:35:20 +0200 | [diff] [blame] | 4475 | break; |
| 4476 | case FADE_OUT: |
Ander Conselvan de Oliveira | 19d10ef | 2013-02-21 18:35:20 +0200 | [diff] [blame] | 4477 | lock(shell); |
| 4478 | break; |
Philip Withnall | 4a86a0a | 2013-11-25 18:01:32 +0000 | [diff] [blame] | 4479 | default: |
| 4480 | break; |
Ander Conselvan de Oliveira | 19d10ef | 2013-02-21 18:35:20 +0200 | [diff] [blame] | 4481 | } |
| 4482 | } |
| 4483 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 4484 | static struct weston_view * |
Pekka Paalanen | 79346ab | 2013-05-22 18:03:09 +0300 | [diff] [blame] | 4485 | shell_fade_create_surface(struct desktop_shell *shell) |
Ander Conselvan de Oliveira | 19d10ef | 2013-02-21 18:35:20 +0200 | [diff] [blame] | 4486 | { |
| 4487 | struct weston_compositor *compositor = shell->compositor; |
| 4488 | struct weston_surface *surface; |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 4489 | struct weston_view *view; |
Pekka Paalanen | 79346ab | 2013-05-22 18:03:09 +0300 | [diff] [blame] | 4490 | |
| 4491 | surface = weston_surface_create(compositor); |
| 4492 | if (!surface) |
| 4493 | return NULL; |
| 4494 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 4495 | view = weston_view_create(surface); |
| 4496 | if (!view) { |
| 4497 | weston_surface_destroy(surface); |
| 4498 | return NULL; |
| 4499 | } |
| 4500 | |
Jason Ekstrand | 5c11a33 | 2013-12-04 20:32:03 -0600 | [diff] [blame] | 4501 | weston_surface_set_size(surface, 8192, 8192); |
Jason Ekstrand | 918f2dd | 2013-12-02 21:01:53 -0600 | [diff] [blame] | 4502 | weston_view_set_position(view, 0, 0); |
Pekka Paalanen | 79346ab | 2013-05-22 18:03:09 +0300 | [diff] [blame] | 4503 | 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] | 4504 | wl_list_insert(&compositor->fade_layer.view_list, |
| 4505 | &view->layer_link); |
Pekka Paalanen | 79346ab | 2013-05-22 18:03:09 +0300 | [diff] [blame] | 4506 | pixman_region32_init(&surface->input); |
| 4507 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 4508 | return view; |
Pekka Paalanen | 79346ab | 2013-05-22 18:03:09 +0300 | [diff] [blame] | 4509 | } |
| 4510 | |
| 4511 | static void |
| 4512 | shell_fade(struct desktop_shell *shell, enum fade_type type) |
| 4513 | { |
Ander Conselvan de Oliveira | 19d10ef | 2013-02-21 18:35:20 +0200 | [diff] [blame] | 4514 | float tint; |
| 4515 | |
| 4516 | switch (type) { |
| 4517 | case FADE_IN: |
| 4518 | tint = 0.0; |
| 4519 | break; |
| 4520 | case FADE_OUT: |
| 4521 | tint = 1.0; |
| 4522 | break; |
| 4523 | default: |
| 4524 | weston_log("shell: invalid fade type\n"); |
| 4525 | return; |
| 4526 | } |
| 4527 | |
| 4528 | shell->fade.type = type; |
| 4529 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 4530 | if (shell->fade.view == NULL) { |
| 4531 | shell->fade.view = shell_fade_create_surface(shell); |
| 4532 | if (!shell->fade.view) |
Ander Conselvan de Oliveira | 19d10ef | 2013-02-21 18:35:20 +0200 | [diff] [blame] | 4533 | return; |
| 4534 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 4535 | shell->fade.view->alpha = 1.0 - tint; |
| 4536 | weston_view_update_transform(shell->fade.view); |
Ander Conselvan de Oliveira | 19d10ef | 2013-02-21 18:35:20 +0200 | [diff] [blame] | 4537 | } |
| 4538 | |
Kristian Høgsberg | 87d3b61 | 2014-01-19 21:48:10 -0800 | [diff] [blame] | 4539 | if (shell->fade.view->output == NULL) { |
| 4540 | /* If the black view gets a NULL output, we lost the |
| 4541 | * last output and we'll just cancel the fade. This |
| 4542 | * happens when you close the last window under the |
| 4543 | * X11 or Wayland backends. */ |
| 4544 | shell->locked = false; |
| 4545 | weston_surface_destroy(shell->fade.view->surface); |
| 4546 | shell->fade.view = NULL; |
| 4547 | } else if (shell->fade.animation) { |
Kristian Høgsberg | 5281fb1 | 2013-06-17 10:10:28 -0400 | [diff] [blame] | 4548 | weston_fade_update(shell->fade.animation, tint); |
Kristian Høgsberg | 87d3b61 | 2014-01-19 21:48:10 -0800 | [diff] [blame] | 4549 | } else { |
Ander Conselvan de Oliveira | 19d10ef | 2013-02-21 18:35:20 +0200 | [diff] [blame] | 4550 | shell->fade.animation = |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 4551 | weston_fade_run(shell->fade.view, |
Kristian Høgsberg | 5281fb1 | 2013-06-17 10:10:28 -0400 | [diff] [blame] | 4552 | 1.0 - tint, tint, 300.0, |
Ander Conselvan de Oliveira | 19d10ef | 2013-02-21 18:35:20 +0200 | [diff] [blame] | 4553 | shell_fade_done, shell); |
Kristian Høgsberg | 87d3b61 | 2014-01-19 21:48:10 -0800 | [diff] [blame] | 4554 | } |
Ander Conselvan de Oliveira | 19d10ef | 2013-02-21 18:35:20 +0200 | [diff] [blame] | 4555 | } |
| 4556 | |
| 4557 | static void |
Pekka Paalanen | 79346ab | 2013-05-22 18:03:09 +0300 | [diff] [blame] | 4558 | do_shell_fade_startup(void *data) |
| 4559 | { |
| 4560 | struct desktop_shell *shell = data; |
| 4561 | |
Kristian Høgsberg | 724c8d9 | 2013-10-16 11:38:24 -0700 | [diff] [blame] | 4562 | if (shell->startup_animation_type == ANIMATION_FADE) |
| 4563 | shell_fade(shell, FADE_IN); |
| 4564 | else if (shell->startup_animation_type == ANIMATION_NONE) { |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 4565 | weston_surface_destroy(shell->fade.view->surface); |
| 4566 | shell->fade.view = NULL; |
Kristian Høgsberg | 724c8d9 | 2013-10-16 11:38:24 -0700 | [diff] [blame] | 4567 | } |
Pekka Paalanen | 79346ab | 2013-05-22 18:03:09 +0300 | [diff] [blame] | 4568 | } |
| 4569 | |
| 4570 | static void |
| 4571 | shell_fade_startup(struct desktop_shell *shell) |
| 4572 | { |
| 4573 | struct wl_event_loop *loop; |
| 4574 | |
| 4575 | if (!shell->fade.startup_timer) |
| 4576 | return; |
| 4577 | |
| 4578 | wl_event_source_remove(shell->fade.startup_timer); |
| 4579 | shell->fade.startup_timer = NULL; |
| 4580 | |
| 4581 | loop = wl_display_get_event_loop(shell->compositor->wl_display); |
| 4582 | wl_event_loop_add_idle(loop, do_shell_fade_startup, shell); |
| 4583 | } |
| 4584 | |
| 4585 | static int |
| 4586 | fade_startup_timeout(void *data) |
| 4587 | { |
| 4588 | struct desktop_shell *shell = data; |
| 4589 | |
| 4590 | shell_fade_startup(shell); |
| 4591 | return 0; |
| 4592 | } |
| 4593 | |
| 4594 | static void |
| 4595 | shell_fade_init(struct desktop_shell *shell) |
| 4596 | { |
| 4597 | /* Make compositor output all black, and wait for the desktop-shell |
| 4598 | * client to signal it is ready, then fade in. The timer triggers a |
| 4599 | * fade-in, in case the desktop-shell client takes too long. |
| 4600 | */ |
| 4601 | |
| 4602 | struct wl_event_loop *loop; |
| 4603 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 4604 | if (shell->fade.view != NULL) { |
Pekka Paalanen | 79346ab | 2013-05-22 18:03:09 +0300 | [diff] [blame] | 4605 | weston_log("%s: warning: fade surface already exists\n", |
| 4606 | __func__); |
| 4607 | return; |
| 4608 | } |
| 4609 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 4610 | shell->fade.view = shell_fade_create_surface(shell); |
| 4611 | if (!shell->fade.view) |
Pekka Paalanen | 79346ab | 2013-05-22 18:03:09 +0300 | [diff] [blame] | 4612 | return; |
| 4613 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 4614 | weston_view_update_transform(shell->fade.view); |
| 4615 | weston_surface_damage(shell->fade.view->surface); |
Pekka Paalanen | 79346ab | 2013-05-22 18:03:09 +0300 | [diff] [blame] | 4616 | |
| 4617 | loop = wl_display_get_event_loop(shell->compositor->wl_display); |
| 4618 | shell->fade.startup_timer = |
| 4619 | wl_event_loop_add_timer(loop, fade_startup_timeout, shell); |
| 4620 | wl_event_source_timer_update(shell->fade.startup_timer, 15000); |
| 4621 | } |
| 4622 | |
| 4623 | static void |
Ander Conselvan de Oliveira | a457563 | 2013-02-21 18:35:23 +0200 | [diff] [blame] | 4624 | idle_handler(struct wl_listener *listener, void *data) |
Ander Conselvan de Oliveira | 19d10ef | 2013-02-21 18:35:20 +0200 | [diff] [blame] | 4625 | { |
| 4626 | struct desktop_shell *shell = |
Ander Conselvan de Oliveira | a457563 | 2013-02-21 18:35:23 +0200 | [diff] [blame] | 4627 | container_of(listener, struct desktop_shell, idle_listener); |
Kristian Høgsberg | 27d5fa8 | 2014-01-17 16:22:50 -0800 | [diff] [blame] | 4628 | struct weston_seat *seat; |
| 4629 | |
| 4630 | wl_list_for_each(seat, &shell->compositor->seat_list, link) |
| 4631 | if (seat->pointer) |
| 4632 | popup_grab_end(seat->pointer); |
Ander Conselvan de Oliveira | 19d10ef | 2013-02-21 18:35:20 +0200 | [diff] [blame] | 4633 | |
| 4634 | shell_fade(shell, FADE_OUT); |
| 4635 | /* lock() is called from shell_fade_done() */ |
| 4636 | } |
| 4637 | |
| 4638 | static void |
Ander Conselvan de Oliveira | a457563 | 2013-02-21 18:35:23 +0200 | [diff] [blame] | 4639 | wake_handler(struct wl_listener *listener, void *data) |
Ander Conselvan de Oliveira | 19d10ef | 2013-02-21 18:35:20 +0200 | [diff] [blame] | 4640 | { |
| 4641 | struct desktop_shell *shell = |
Ander Conselvan de Oliveira | a457563 | 2013-02-21 18:35:23 +0200 | [diff] [blame] | 4642 | container_of(listener, struct desktop_shell, wake_listener); |
Ander Conselvan de Oliveira | 19d10ef | 2013-02-21 18:35:20 +0200 | [diff] [blame] | 4643 | |
Ander Conselvan de Oliveira | 19d10ef | 2013-02-21 18:35:20 +0200 | [diff] [blame] | 4644 | unlock(shell); |
| 4645 | } |
| 4646 | |
| 4647 | static void |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 4648 | center_on_output(struct weston_view *view, struct weston_output *output) |
Pekka Paalanen | 77346a6 | 2011-11-30 16:26:35 +0200 | [diff] [blame] | 4649 | { |
Giulio Camuffo | b836664 | 2013-04-25 13:57:46 +0300 | [diff] [blame] | 4650 | int32_t surf_x, surf_y, width, height; |
Ander Conselvan de Oliveira | 012b4c7 | 2012-11-27 17:03:42 +0200 | [diff] [blame] | 4651 | float x, y; |
Pekka Paalanen | 77346a6 | 2011-11-30 16:26:35 +0200 | [diff] [blame] | 4652 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 4653 | surface_subsurfaces_boundingbox(view->surface, &surf_x, &surf_y, &width, &height); |
Giulio Camuffo | b836664 | 2013-04-25 13:57:46 +0300 | [diff] [blame] | 4654 | |
| 4655 | x = output->x + (output->width - width) / 2 - surf_x / 2; |
| 4656 | y = output->y + (output->height - height) / 2 - surf_y / 2; |
Ander Conselvan de Oliveira | 012b4c7 | 2012-11-27 17:03:42 +0200 | [diff] [blame] | 4657 | |
Jason Ekstrand | 918f2dd | 2013-12-02 21:01:53 -0600 | [diff] [blame] | 4658 | weston_view_set_position(view, x, y); |
Pekka Paalanen | 77346a6 | 2011-11-30 16:26:35 +0200 | [diff] [blame] | 4659 | } |
| 4660 | |
| 4661 | static void |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 4662 | weston_view_set_initial_position(struct weston_view *view, |
| 4663 | struct desktop_shell *shell) |
Rob Bradford | ac63e5b | 2012-08-13 14:07:52 +0100 | [diff] [blame] | 4664 | { |
| 4665 | struct weston_compositor *compositor = shell->compositor; |
| 4666 | int ix = 0, iy = 0; |
| 4667 | int range_x, range_y; |
| 4668 | int dx, dy, x, y, panel_height; |
| 4669 | struct weston_output *output, *target_output = NULL; |
| 4670 | struct weston_seat *seat; |
| 4671 | |
| 4672 | /* As a heuristic place the new window on the same output as the |
| 4673 | * pointer. Falling back to the output containing 0, 0. |
| 4674 | * |
| 4675 | * TODO: Do something clever for touch too? |
| 4676 | */ |
| 4677 | wl_list_for_each(seat, &compositor->seat_list, link) { |
Kristian Høgsberg | 2bf8762 | 2013-05-07 23:17:41 -0400 | [diff] [blame] | 4678 | if (seat->pointer) { |
Kristian Høgsberg | e314875 | 2013-05-06 23:19:49 -0400 | [diff] [blame] | 4679 | ix = wl_fixed_to_int(seat->pointer->x); |
| 4680 | iy = wl_fixed_to_int(seat->pointer->y); |
Rob Bradford | ac63e5b | 2012-08-13 14:07:52 +0100 | [diff] [blame] | 4681 | break; |
| 4682 | } |
| 4683 | } |
| 4684 | |
| 4685 | wl_list_for_each(output, &compositor->output_list, link) { |
| 4686 | if (pixman_region32_contains_point(&output->region, ix, iy, NULL)) { |
| 4687 | target_output = output; |
| 4688 | break; |
| 4689 | } |
| 4690 | } |
| 4691 | |
| 4692 | if (!target_output) { |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 4693 | weston_view_set_position(view, 10 + random() % 400, |
| 4694 | 10 + random() % 400); |
Rob Bradford | ac63e5b | 2012-08-13 14:07:52 +0100 | [diff] [blame] | 4695 | return; |
| 4696 | } |
| 4697 | |
| 4698 | /* Valid range within output where the surface will still be onscreen. |
| 4699 | * If this is negative it means that the surface is bigger than |
| 4700 | * output. |
| 4701 | */ |
| 4702 | panel_height = get_output_panel_height(shell, target_output); |
Jason Ekstrand | 918f2dd | 2013-12-02 21:01:53 -0600 | [diff] [blame] | 4703 | range_x = target_output->width - view->surface->width; |
Scott Moreau | 1bad5db | 2012-08-18 01:04:05 -0600 | [diff] [blame] | 4704 | range_y = (target_output->height - panel_height) - |
Jason Ekstrand | 918f2dd | 2013-12-02 21:01:53 -0600 | [diff] [blame] | 4705 | view->surface->height; |
Rob Bradford | ac63e5b | 2012-08-13 14:07:52 +0100 | [diff] [blame] | 4706 | |
Rob Bradford | 4cb88c7 | 2012-08-13 15:18:44 +0100 | [diff] [blame] | 4707 | if (range_x > 0) |
Rob Bradford | ac63e5b | 2012-08-13 14:07:52 +0100 | [diff] [blame] | 4708 | dx = random() % range_x; |
Rob Bradford | ac63e5b | 2012-08-13 14:07:52 +0100 | [diff] [blame] | 4709 | else |
Rob Bradford | 4cb88c7 | 2012-08-13 15:18:44 +0100 | [diff] [blame] | 4710 | dx = 0; |
| 4711 | |
| 4712 | if (range_y > 0) |
Rob Bradford | ac63e5b | 2012-08-13 14:07:52 +0100 | [diff] [blame] | 4713 | dy = panel_height + random() % range_y; |
Rob Bradford | 4cb88c7 | 2012-08-13 15:18:44 +0100 | [diff] [blame] | 4714 | else |
| 4715 | dy = panel_height; |
Rob Bradford | ac63e5b | 2012-08-13 14:07:52 +0100 | [diff] [blame] | 4716 | |
| 4717 | x = target_output->x + dx; |
| 4718 | y = target_output->y + dy; |
| 4719 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 4720 | weston_view_set_position(view, x, y); |
Rob Bradford | ac63e5b | 2012-08-13 14:07:52 +0100 | [diff] [blame] | 4721 | } |
| 4722 | |
| 4723 | static void |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 4724 | map(struct desktop_shell *shell, struct shell_surface *shsurf, |
Jason Ekstrand | 918f2dd | 2013-12-02 21:01:53 -0600 | [diff] [blame] | 4725 | int32_t sx, int32_t sy) |
Kristian Høgsberg | 02ec0a5 | 2011-04-23 13:04:11 -0400 | [diff] [blame] | 4726 | { |
Kristian Høgsberg | 8334bc1 | 2012-01-03 10:29:47 -0500 | [diff] [blame] | 4727 | struct weston_compositor *compositor = shell->compositor; |
Daniel Stone | b210468 | 2012-05-30 16:31:56 +0100 | [diff] [blame] | 4728 | struct weston_seat *seat; |
Juan Zhao | 96879df | 2012-02-07 08:45:41 +0800 | [diff] [blame] | 4729 | int panel_height = 0; |
Giulio Camuffo | b836664 | 2013-04-25 13:57:46 +0300 | [diff] [blame] | 4730 | int32_t surf_x, surf_y; |
Pekka Paalanen | 57da4a8 | 2011-11-23 16:42:16 +0200 | [diff] [blame] | 4731 | |
Pekka Paalanen | 77346a6 | 2011-11-30 16:26:35 +0200 | [diff] [blame] | 4732 | /* initial positioning, see also configure() */ |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 4733 | switch (shsurf->type) { |
Rafael Antognolli | ed207b4 | 2013-12-03 15:35:43 -0200 | [diff] [blame] | 4734 | case SHELL_SURFACE_TOPLEVEL: |
Rafael Antognolli | 03b1659 | 2013-12-03 15:35:42 -0200 | [diff] [blame] | 4735 | if (shsurf->state.fullscreen) { |
| 4736 | center_on_output(shsurf->view, shsurf->fullscreen_output); |
| 4737 | shell_map_fullscreen(shsurf); |
| 4738 | } else if (shsurf->state.maximized) { |
| 4739 | /* use surface configure to set the geometry */ |
| 4740 | panel_height = get_output_panel_height(shell, shsurf->output); |
| 4741 | surface_subsurfaces_boundingbox(shsurf->surface, |
| 4742 | &surf_x, &surf_y, NULL, NULL); |
| 4743 | weston_view_set_position(shsurf->view, |
| 4744 | shsurf->output->x - surf_x, |
| 4745 | shsurf->output->y + |
| 4746 | panel_height - surf_y); |
Rafael Antognolli | ed207b4 | 2013-12-03 15:35:43 -0200 | [diff] [blame] | 4747 | } else if (!shsurf->state.relative) { |
Rafael Antognolli | 03b1659 | 2013-12-03 15:35:42 -0200 | [diff] [blame] | 4748 | weston_view_set_initial_position(shsurf->view, shell); |
| 4749 | } |
Juan Zhao | 96879df | 2012-02-07 08:45:41 +0800 | [diff] [blame] | 4750 | break; |
Tiago Vignatti | 0f99701 | 2012-02-10 16:17:23 +0200 | [diff] [blame] | 4751 | case SHELL_SURFACE_POPUP: |
Kristian Høgsberg | 3730f36 | 2012-04-13 12:40:07 -0400 | [diff] [blame] | 4752 | shell_map_popup(shsurf); |
Rob Bradford | db99938 | 2012-12-06 12:07:48 +0000 | [diff] [blame] | 4753 | break; |
Ander Conselvan de Oliveira | e9e0515 | 2012-02-15 17:02:56 +0200 | [diff] [blame] | 4754 | case SHELL_SURFACE_NONE: |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 4755 | weston_view_set_position(shsurf->view, |
| 4756 | shsurf->view->geometry.x + sx, |
| 4757 | shsurf->view->geometry.y + sy); |
Tiago Vignatti | 0f99701 | 2012-02-10 16:17:23 +0200 | [diff] [blame] | 4758 | break; |
Philip Withnall | 0f640e2 | 2013-11-25 18:01:31 +0000 | [diff] [blame] | 4759 | case SHELL_SURFACE_XWAYLAND: |
Pekka Paalanen | 77346a6 | 2011-11-30 16:26:35 +0200 | [diff] [blame] | 4760 | default: |
| 4761 | ; |
| 4762 | } |
Kristian Høgsberg | 7584062 | 2011-09-06 13:48:16 -0400 | [diff] [blame] | 4763 | |
Philip Withnall | e1d75ae | 2013-11-25 18:01:41 +0000 | [diff] [blame] | 4764 | /* Surface stacking order, see also activate(). */ |
| 4765 | shell_surface_update_layer(shsurf); |
Pekka Paalanen | f0fc70d | 2011-11-15 13:34:54 +0200 | [diff] [blame] | 4766 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 4767 | if (shsurf->type != SHELL_SURFACE_NONE) { |
| 4768 | weston_view_update_transform(shsurf->view); |
Rafael Antognolli | 03b1659 | 2013-12-03 15:35:42 -0200 | [diff] [blame] | 4769 | if (shsurf->state.maximized) { |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 4770 | shsurf->surface->output = shsurf->output; |
| 4771 | shsurf->view->output = shsurf->output; |
| 4772 | } |
Ander Conselvan de Oliveira | de56c31 | 2012-03-05 15:39:23 +0200 | [diff] [blame] | 4773 | } |
Kristian Høgsberg | 2f88a40 | 2011-12-04 15:32:59 -0500 | [diff] [blame] | 4774 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 4775 | switch (shsurf->type) { |
Tiago Vignatti | fb2adba | 2013-06-12 15:43:21 -0300 | [diff] [blame] | 4776 | /* XXX: xwayland's using the same fields for transient type */ |
| 4777 | case SHELL_SURFACE_XWAYLAND: |
Tiago Vignatti | 99aeb1e | 2012-05-23 22:06:26 +0300 | [diff] [blame] | 4778 | if (shsurf->transient.flags == |
| 4779 | WL_SHELL_SURFACE_TRANSIENT_INACTIVE) |
| 4780 | break; |
| 4781 | case SHELL_SURFACE_TOPLEVEL: |
Rafael Antognolli | ed207b4 | 2013-12-03 15:35:43 -0200 | [diff] [blame] | 4782 | if (shsurf->state.relative && |
| 4783 | shsurf->transient.flags == WL_SHELL_SURFACE_TRANSIENT_INACTIVE) |
| 4784 | break; |
Rafael Antognolli | ba5d2d7 | 2013-12-04 17:49:55 -0200 | [diff] [blame] | 4785 | if (shell->locked) |
Rafael Antognolli | ed207b4 | 2013-12-03 15:35:43 -0200 | [diff] [blame] | 4786 | break; |
| 4787 | wl_list_for_each(seat, &compositor->seat_list, link) |
| 4788 | activate(shell, shsurf->surface, seat); |
Juan Zhao | 7bb92f0 | 2011-12-15 11:31:51 -0500 | [diff] [blame] | 4789 | break; |
Philip Withnall | 0f640e2 | 2013-11-25 18:01:31 +0000 | [diff] [blame] | 4790 | case SHELL_SURFACE_POPUP: |
| 4791 | case SHELL_SURFACE_NONE: |
Juan Zhao | 7bb92f0 | 2011-12-15 11:31:51 -0500 | [diff] [blame] | 4792 | default: |
| 4793 | break; |
| 4794 | } |
| 4795 | |
Rafael Antognolli | 03b1659 | 2013-12-03 15:35:42 -0200 | [diff] [blame] | 4796 | if (shsurf->type == SHELL_SURFACE_TOPLEVEL && |
| 4797 | !shsurf->state.maximized && !shsurf->state.fullscreen) |
Juan Zhao | e10d279 | 2012-04-25 19:09:52 +0800 | [diff] [blame] | 4798 | { |
| 4799 | switch (shell->win_animation_type) { |
| 4800 | case ANIMATION_FADE: |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 4801 | 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] | 4802 | break; |
| 4803 | case ANIMATION_ZOOM: |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 4804 | weston_zoom_run(shsurf->view, 0.5, 1.0, NULL, NULL); |
Juan Zhao | e10d279 | 2012-04-25 19:09:52 +0800 | [diff] [blame] | 4805 | break; |
Philip Withnall | 4a86a0a | 2013-11-25 18:01:32 +0000 | [diff] [blame] | 4806 | case ANIMATION_NONE: |
Juan Zhao | e10d279 | 2012-04-25 19:09:52 +0800 | [diff] [blame] | 4807 | default: |
| 4808 | break; |
| 4809 | } |
| 4810 | } |
Kristian Høgsberg | 32e24cc | 2011-11-09 12:07:35 -0500 | [diff] [blame] | 4811 | } |
| 4812 | |
| 4813 | static void |
Tiago Vignatti | be14326 | 2012-04-16 17:31:41 +0300 | [diff] [blame] | 4814 | configure(struct desktop_shell *shell, struct weston_surface *surface, |
Jason Ekstrand | 918f2dd | 2013-12-02 21:01:53 -0600 | [diff] [blame] | 4815 | float x, float y) |
Kristian Høgsberg | 32e24cc | 2011-11-09 12:07:35 -0500 | [diff] [blame] | 4816 | { |
Pekka Paalanen | 77346a6 | 2011-11-30 16:26:35 +0200 | [diff] [blame] | 4817 | struct shell_surface *shsurf; |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 4818 | struct weston_view *view; |
Jason Ekstrand | 918f2dd | 2013-12-02 21:01:53 -0600 | [diff] [blame] | 4819 | int32_t mx, my, surf_x, surf_y; |
Kristian Høgsberg | 32e24cc | 2011-11-09 12:07:35 -0500 | [diff] [blame] | 4820 | |
Pekka Paalanen | 77346a6 | 2011-11-30 16:26:35 +0200 | [diff] [blame] | 4821 | shsurf = get_shell_surface(surface); |
Pekka Paalanen | 77346a6 | 2011-11-30 16:26:35 +0200 | [diff] [blame] | 4822 | |
U. Artie Eoff | cf5737a | 2014-01-17 10:08:25 -0800 | [diff] [blame] | 4823 | assert(shsurf); |
| 4824 | |
Rafael Antognolli | 03b1659 | 2013-12-03 15:35:42 -0200 | [diff] [blame] | 4825 | if (shsurf->state.fullscreen) |
Alex Wu | 4539b08 | 2012-03-01 12:57:46 +0800 | [diff] [blame] | 4826 | shell_configure_fullscreen(shsurf); |
Rafael Antognolli | 03b1659 | 2013-12-03 15:35:42 -0200 | [diff] [blame] | 4827 | else if (shsurf->state.maximized) { |
Alex Wu | 4539b08 | 2012-03-01 12:57:46 +0800 | [diff] [blame] | 4828 | /* setting x, y and using configure to change that geometry */ |
Giulio Camuffo | b836664 | 2013-04-25 13:57:46 +0300 | [diff] [blame] | 4829 | surface_subsurfaces_boundingbox(shsurf->surface, &surf_x, &surf_y, |
| 4830 | NULL, NULL); |
Jason Ekstrand | 918f2dd | 2013-12-02 21:01:53 -0600 | [diff] [blame] | 4831 | mx = shsurf->output->x - surf_x; |
| 4832 | my = shsurf->output->y + |
| 4833 | get_output_panel_height(shell,shsurf->output) - surf_y; |
| 4834 | weston_view_set_position(shsurf->view, mx, my); |
Rafael Antognolli | 03b1659 | 2013-12-03 15:35:42 -0200 | [diff] [blame] | 4835 | } else { |
Jason Ekstrand | 918f2dd | 2013-12-02 21:01:53 -0600 | [diff] [blame] | 4836 | weston_view_set_position(shsurf->view, x, y); |
Kristian Høgsberg | 7a5c979 | 2011-06-18 06:12:54 -0400 | [diff] [blame] | 4837 | } |
Kristian Høgsberg | 32e24cc | 2011-11-09 12:07:35 -0500 | [diff] [blame] | 4838 | |
Alex Wu | 4539b08 | 2012-03-01 12:57:46 +0800 | [diff] [blame] | 4839 | /* XXX: would a fullscreen surface need the same handling? */ |
Kristian Høgsberg | 6a8b553 | 2012-02-16 23:43:59 -0500 | [diff] [blame] | 4840 | if (surface->output) { |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 4841 | wl_list_for_each(view, &surface->views, surface_link) |
| 4842 | weston_view_update_transform(view); |
Pekka Paalanen | 77346a6 | 2011-11-30 16:26:35 +0200 | [diff] [blame] | 4843 | |
Rafael Antognolli | 03b1659 | 2013-12-03 15:35:42 -0200 | [diff] [blame] | 4844 | if (shsurf->state.maximized) |
Juan Zhao | 96879df | 2012-02-07 08:45:41 +0800 | [diff] [blame] | 4845 | surface->output = shsurf->output; |
Pekka Paalanen | 77346a6 | 2011-11-30 16:26:35 +0200 | [diff] [blame] | 4846 | } |
Kristian Høgsberg | 0793756 | 2011-04-12 17:25:42 -0400 | [diff] [blame] | 4847 | } |
| 4848 | |
Ander Conselvan de Oliveira | 093bfa3 | 2012-03-27 17:36:41 +0300 | [diff] [blame] | 4849 | static void |
Jason Ekstrand | 918f2dd | 2013-12-02 21:01:53 -0600 | [diff] [blame] | 4850 | 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] | 4851 | { |
Ander Conselvan de Oliveira | 7fb9f95 | 2012-03-27 17:36:42 +0300 | [diff] [blame] | 4852 | struct shell_surface *shsurf = get_shell_surface(es); |
U. Artie Eoff | cf5737a | 2014-01-17 10:08:25 -0800 | [diff] [blame] | 4853 | struct desktop_shell *shell; |
Tiago Vignatti | 70e5c9c | 2012-05-07 15:23:07 +0300 | [diff] [blame] | 4854 | int type_changed = 0; |
Ander Conselvan de Oliveira | 093bfa3 | 2012-03-27 17:36:41 +0300 | [diff] [blame] | 4855 | |
U. Artie Eoff | cf5737a | 2014-01-17 10:08:25 -0800 | [diff] [blame] | 4856 | assert(shsurf); |
| 4857 | |
| 4858 | shell = shsurf->shell; |
| 4859 | |
Kristian Høgsberg | 8eb0f4f | 2013-06-17 10:33:14 -0400 | [diff] [blame] | 4860 | if (!weston_surface_is_mapped(es) && |
| 4861 | !wl_list_empty(&shsurf->popup.grab_link)) { |
Giulio Camuffo | 5085a75 | 2013-03-25 21:42:45 +0100 | [diff] [blame] | 4862 | remove_popup_grab(shsurf); |
| 4863 | } |
| 4864 | |
Jason Ekstrand | 918f2dd | 2013-12-02 21:01:53 -0600 | [diff] [blame] | 4865 | if (es->width == 0) |
Giulio Camuffo | 184df50 | 2013-02-21 11:29:21 +0100 | [diff] [blame] | 4866 | return; |
| 4867 | |
Kristian Høgsberg | c8f8dd8 | 2013-12-05 23:20:33 -0800 | [diff] [blame] | 4868 | if (shsurf->state_changed) { |
Kristian Høgsberg | 7f366e7 | 2012-04-27 17:20:01 -0400 | [diff] [blame] | 4869 | set_surface_type(shsurf); |
Kristian Høgsberg | f7e23d5 | 2012-04-27 17:51:59 -0400 | [diff] [blame] | 4870 | type_changed = 1; |
| 4871 | } |
Kristian Høgsberg | 7f366e7 | 2012-04-27 17:20:01 -0400 | [diff] [blame] | 4872 | |
Ander Conselvan de Oliveira | 093bfa3 | 2012-03-27 17:36:41 +0300 | [diff] [blame] | 4873 | if (!weston_surface_is_mapped(es)) { |
Jason Ekstrand | 918f2dd | 2013-12-02 21:01:53 -0600 | [diff] [blame] | 4874 | map(shell, shsurf, sx, sy); |
Kristian Høgsberg | f7e23d5 | 2012-04-27 17:51:59 -0400 | [diff] [blame] | 4875 | } else if (type_changed || sx != 0 || sy != 0 || |
Jason Ekstrand | 918f2dd | 2013-12-02 21:01:53 -0600 | [diff] [blame] | 4876 | shsurf->last_width != es->width || |
| 4877 | shsurf->last_height != es->height) { |
John Kåre Alsaker | 490d02a | 2012-09-30 02:57:21 +0200 | [diff] [blame] | 4878 | float from_x, from_y; |
| 4879 | float to_x, to_y; |
Ander Conselvan de Oliveira | 093bfa3 | 2012-03-27 17:36:41 +0300 | [diff] [blame] | 4880 | |
Kristian Høgsberg | 44cd196 | 2014-02-05 21:36:04 -0800 | [diff] [blame] | 4881 | if (shsurf->resize_edges) { |
| 4882 | sx = 0; |
| 4883 | sy = 0; |
| 4884 | } |
| 4885 | |
| 4886 | if (shsurf->resize_edges & WL_SHELL_SURFACE_RESIZE_LEFT) |
| 4887 | sx = shsurf->last_width - es->width; |
| 4888 | if (shsurf->resize_edges & WL_SHELL_SURFACE_RESIZE_TOP) |
| 4889 | sy = shsurf->last_height - es->height; |
| 4890 | |
| 4891 | shsurf->last_width = es->width; |
| 4892 | shsurf->last_height = es->height; |
| 4893 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 4894 | weston_view_to_global_float(shsurf->view, 0, 0, &from_x, &from_y); |
| 4895 | 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] | 4896 | configure(shell, es, |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 4897 | shsurf->view->geometry.x + to_x - from_x, |
Jason Ekstrand | 918f2dd | 2013-12-02 21:01:53 -0600 | [diff] [blame] | 4898 | shsurf->view->geometry.y + to_y - from_y); |
Ander Conselvan de Oliveira | 093bfa3 | 2012-03-27 17:36:41 +0300 | [diff] [blame] | 4899 | } |
| 4900 | } |
| 4901 | |
Tiago Vignatti | b7dbbd6 | 2012-09-25 17:57:01 +0300 | [diff] [blame] | 4902 | static void launch_desktop_shell_process(void *data); |
Pekka Paalanen | 4d733ee | 2012-01-17 14:36:27 +0200 | [diff] [blame] | 4903 | |
Kristian Høgsberg | 97d44aa | 2011-08-26 17:21:20 -0400 | [diff] [blame] | 4904 | static void |
Kristian Høgsberg | 8334bc1 | 2012-01-03 10:29:47 -0500 | [diff] [blame] | 4905 | desktop_shell_sigchld(struct weston_process *process, int status) |
Pekka Paalanen | 6cd281a | 2011-11-03 14:11:32 +0200 | [diff] [blame] | 4906 | { |
Pekka Paalanen | 4d733ee | 2012-01-17 14:36:27 +0200 | [diff] [blame] | 4907 | uint32_t time; |
Tiago Vignatti | be14326 | 2012-04-16 17:31:41 +0300 | [diff] [blame] | 4908 | struct desktop_shell *shell = |
| 4909 | container_of(process, struct desktop_shell, child.process); |
Pekka Paalanen | 6cd281a | 2011-11-03 14:11:32 +0200 | [diff] [blame] | 4910 | |
| 4911 | shell->child.process.pid = 0; |
| 4912 | shell->child.client = NULL; /* already destroyed by wayland */ |
Pekka Paalanen | 4d733ee | 2012-01-17 14:36:27 +0200 | [diff] [blame] | 4913 | |
| 4914 | /* if desktop-shell dies more than 5 times in 30 seconds, give up */ |
| 4915 | time = weston_compositor_get_time(); |
Kristian Høgsberg | f03a616 | 2012-01-17 11:07:42 -0500 | [diff] [blame] | 4916 | if (time - shell->child.deathstamp > 30000) { |
Pekka Paalanen | 4d733ee | 2012-01-17 14:36:27 +0200 | [diff] [blame] | 4917 | shell->child.deathstamp = time; |
| 4918 | shell->child.deathcount = 0; |
| 4919 | } |
| 4920 | |
| 4921 | shell->child.deathcount++; |
| 4922 | if (shell->child.deathcount > 5) { |
Emilio Pozuelo Monfort | 46ce798 | 2013-11-20 13:22:29 +0100 | [diff] [blame] | 4923 | weston_log("%s died, giving up.\n", shell->client); |
Pekka Paalanen | 4d733ee | 2012-01-17 14:36:27 +0200 | [diff] [blame] | 4924 | return; |
| 4925 | } |
| 4926 | |
Emilio Pozuelo Monfort | 46ce798 | 2013-11-20 13:22:29 +0100 | [diff] [blame] | 4927 | weston_log("%s died, respawning...\n", shell->client); |
Pekka Paalanen | 4d733ee | 2012-01-17 14:36:27 +0200 | [diff] [blame] | 4928 | launch_desktop_shell_process(shell); |
Pekka Paalanen | 79346ab | 2013-05-22 18:03:09 +0300 | [diff] [blame] | 4929 | shell_fade_startup(shell); |
Pekka Paalanen | 6cd281a | 2011-11-03 14:11:32 +0200 | [diff] [blame] | 4930 | } |
| 4931 | |
Tiago Vignatti | b7dbbd6 | 2012-09-25 17:57:01 +0300 | [diff] [blame] | 4932 | static void |
Ander Conselvan de Oliveira | 312ea4c | 2013-12-20 21:07:01 +0200 | [diff] [blame] | 4933 | desktop_shell_client_destroy(struct wl_listener *listener, void *data) |
| 4934 | { |
| 4935 | struct desktop_shell *shell; |
| 4936 | |
| 4937 | shell = container_of(listener, struct desktop_shell, |
| 4938 | child.client_destroy_listener); |
| 4939 | |
| 4940 | shell->child.client = NULL; |
| 4941 | } |
| 4942 | |
| 4943 | static void |
Tiago Vignatti | b7dbbd6 | 2012-09-25 17:57:01 +0300 | [diff] [blame] | 4944 | launch_desktop_shell_process(void *data) |
Pekka Paalanen | 6cd281a | 2011-11-03 14:11:32 +0200 | [diff] [blame] | 4945 | { |
Tiago Vignatti | b7dbbd6 | 2012-09-25 17:57:01 +0300 | [diff] [blame] | 4946 | struct desktop_shell *shell = data; |
Pekka Paalanen | 6cd281a | 2011-11-03 14:11:32 +0200 | [diff] [blame] | 4947 | |
Kristian Høgsberg | 8334bc1 | 2012-01-03 10:29:47 -0500 | [diff] [blame] | 4948 | shell->child.client = weston_client_launch(shell->compositor, |
Pekka Paalanen | 409ef0a | 2011-12-02 15:30:21 +0200 | [diff] [blame] | 4949 | &shell->child.process, |
Emilio Pozuelo Monfort | 46ce798 | 2013-11-20 13:22:29 +0100 | [diff] [blame] | 4950 | shell->client, |
Pekka Paalanen | 409ef0a | 2011-12-02 15:30:21 +0200 | [diff] [blame] | 4951 | desktop_shell_sigchld); |
| 4952 | |
| 4953 | if (!shell->child.client) |
Emilio Pozuelo Monfort | 46ce798 | 2013-11-20 13:22:29 +0100 | [diff] [blame] | 4954 | weston_log("not able to start %s\n", shell->client); |
Ander Conselvan de Oliveira | 312ea4c | 2013-12-20 21:07:01 +0200 | [diff] [blame] | 4955 | |
| 4956 | shell->child.client_destroy_listener.notify = |
| 4957 | desktop_shell_client_destroy; |
| 4958 | wl_client_add_destroy_listener(shell->child.client, |
| 4959 | &shell->child.client_destroy_listener); |
Pekka Paalanen | 6cd281a | 2011-11-03 14:11:32 +0200 | [diff] [blame] | 4960 | } |
| 4961 | |
| 4962 | static void |
Kristian Høgsberg | 2bff94e | 2014-02-11 12:22:51 -0800 | [diff] [blame] | 4963 | handle_shell_client_destroy(struct wl_listener *listener, void *data) |
| 4964 | { |
| 4965 | struct shell_client *sc = |
| 4966 | container_of(listener, struct shell_client, destroy_listener); |
| 4967 | |
| 4968 | if (sc->ping_timer) |
| 4969 | wl_event_source_remove(sc->ping_timer); |
| 4970 | free(sc); |
| 4971 | } |
| 4972 | |
Kristian Høgsberg | dd62aba | 2014-02-12 09:56:19 -0800 | [diff] [blame] | 4973 | static struct shell_client * |
| 4974 | shell_client_create(struct wl_client *client, struct desktop_shell *shell, |
| 4975 | const struct wl_interface *interface, uint32_t id) |
Rafael Antognolli | e2a3455 | 2013-12-03 15:35:45 -0200 | [diff] [blame] | 4976 | { |
Kristian Høgsberg | 2bff94e | 2014-02-11 12:22:51 -0800 | [diff] [blame] | 4977 | struct shell_client *sc; |
Rafael Antognolli | e2a3455 | 2013-12-03 15:35:45 -0200 | [diff] [blame] | 4978 | |
Kristian Høgsberg | 2bff94e | 2014-02-11 12:22:51 -0800 | [diff] [blame] | 4979 | sc = zalloc(sizeof *sc); |
| 4980 | if (sc == NULL) { |
| 4981 | wl_client_post_no_memory(client); |
Kristian Høgsberg | dd62aba | 2014-02-12 09:56:19 -0800 | [diff] [blame] | 4982 | return NULL; |
Kristian Høgsberg | 2bff94e | 2014-02-11 12:22:51 -0800 | [diff] [blame] | 4983 | } |
Kristian Høgsberg | dd62aba | 2014-02-12 09:56:19 -0800 | [diff] [blame] | 4984 | |
| 4985 | sc->resource = wl_resource_create(client, interface, 1, id); |
Kristian Høgsberg | 2bff94e | 2014-02-11 12:22:51 -0800 | [diff] [blame] | 4986 | if (sc->resource == NULL) { |
| 4987 | free(sc); |
| 4988 | wl_client_post_no_memory(client); |
Kristian Høgsberg | dd62aba | 2014-02-12 09:56:19 -0800 | [diff] [blame] | 4989 | return NULL; |
Kristian Høgsberg | 2bff94e | 2014-02-11 12:22:51 -0800 | [diff] [blame] | 4990 | } |
| 4991 | |
| 4992 | sc->client = client; |
| 4993 | sc->shell = shell; |
| 4994 | sc->destroy_listener.notify = handle_shell_client_destroy; |
| 4995 | wl_client_add_destroy_listener(client, &sc->destroy_listener); |
| 4996 | |
Kristian Høgsberg | dd62aba | 2014-02-12 09:56:19 -0800 | [diff] [blame] | 4997 | return sc; |
| 4998 | } |
| 4999 | |
| 5000 | static void |
| 5001 | bind_shell(struct wl_client *client, void *data, uint32_t version, uint32_t id) |
| 5002 | { |
| 5003 | struct desktop_shell *shell = data; |
| 5004 | struct shell_client *sc; |
| 5005 | |
| 5006 | sc = shell_client_create(client, shell, &wl_shell_interface, id); |
| 5007 | if (sc) |
| 5008 | wl_resource_set_implementation(sc->resource, |
| 5009 | &shell_implementation, |
| 5010 | shell, NULL); |
| 5011 | } |
| 5012 | |
| 5013 | static void |
| 5014 | bind_xdg_shell(struct wl_client *client, void *data, uint32_t version, uint32_t id) |
| 5015 | { |
| 5016 | struct desktop_shell *shell = data; |
| 5017 | struct shell_client *sc; |
| 5018 | |
| 5019 | sc = shell_client_create(client, shell, &xdg_shell_interface, id); |
| 5020 | if (sc) |
| 5021 | wl_resource_set_dispatcher(sc->resource, |
| 5022 | xdg_shell_unversioned_dispatch, |
| 5023 | NULL, sc, NULL); |
Rafael Antognolli | e2a3455 | 2013-12-03 15:35:45 -0200 | [diff] [blame] | 5024 | } |
| 5025 | |
| 5026 | static void |
Pekka Paalanen | 9ef3e01 | 2011-11-15 13:34:48 +0200 | [diff] [blame] | 5027 | unbind_desktop_shell(struct wl_resource *resource) |
| 5028 | { |
Jason Ekstrand | 651f00e | 2013-06-14 10:07:54 -0500 | [diff] [blame] | 5029 | struct desktop_shell *shell = wl_resource_get_user_data(resource); |
Kristian Høgsberg | 1ec0c31 | 2011-11-15 16:39:55 -0500 | [diff] [blame] | 5030 | |
| 5031 | if (shell->locked) |
| 5032 | resume_desktop(shell); |
| 5033 | |
Pekka Paalanen | 9ef3e01 | 2011-11-15 13:34:48 +0200 | [diff] [blame] | 5034 | shell->child.desktop_shell = NULL; |
| 5035 | shell->prepare_event_sent = false; |
Pekka Paalanen | 9ef3e01 | 2011-11-15 13:34:48 +0200 | [diff] [blame] | 5036 | } |
| 5037 | |
| 5038 | static void |
Kristian Høgsberg | 7584062 | 2011-09-06 13:48:16 -0400 | [diff] [blame] | 5039 | bind_desktop_shell(struct wl_client *client, |
| 5040 | void *data, uint32_t version, uint32_t id) |
| 5041 | { |
Tiago Vignatti | be14326 | 2012-04-16 17:31:41 +0300 | [diff] [blame] | 5042 | struct desktop_shell *shell = data; |
Pekka Paalanen | bbe6052 | 2011-11-03 14:11:33 +0200 | [diff] [blame] | 5043 | struct wl_resource *resource; |
Kristian Høgsberg | 7584062 | 2011-09-06 13:48:16 -0400 | [diff] [blame] | 5044 | |
Jason Ekstrand | a85118c | 2013-06-27 20:17:02 -0500 | [diff] [blame] | 5045 | resource = wl_resource_create(client, &desktop_shell_interface, |
| 5046 | MIN(version, 2), id); |
Pekka Paalanen | bbe6052 | 2011-11-03 14:11:33 +0200 | [diff] [blame] | 5047 | |
Pekka Paalanen | 9ef3e01 | 2011-11-15 13:34:48 +0200 | [diff] [blame] | 5048 | if (client == shell->child.client) { |
Jason Ekstrand | a85118c | 2013-06-27 20:17:02 -0500 | [diff] [blame] | 5049 | wl_resource_set_implementation(resource, |
| 5050 | &desktop_shell_implementation, |
| 5051 | shell, unbind_desktop_shell); |
Pekka Paalanen | 9ef3e01 | 2011-11-15 13:34:48 +0200 | [diff] [blame] | 5052 | shell->child.desktop_shell = resource; |
Pekka Paalanen | 79346ab | 2013-05-22 18:03:09 +0300 | [diff] [blame] | 5053 | |
| 5054 | if (version < 2) |
| 5055 | shell_fade_startup(shell); |
| 5056 | |
Pekka Paalanen | bbe6052 | 2011-11-03 14:11:33 +0200 | [diff] [blame] | 5057 | return; |
Pekka Paalanen | 9ef3e01 | 2011-11-15 13:34:48 +0200 | [diff] [blame] | 5058 | } |
Pekka Paalanen | bbe6052 | 2011-11-03 14:11:33 +0200 | [diff] [blame] | 5059 | |
| 5060 | wl_resource_post_error(resource, WL_DISPLAY_ERROR_INVALID_OBJECT, |
| 5061 | "permission to bind desktop_shell denied"); |
Kristian Høgsberg | eae5de7 | 2012-04-11 22:42:15 -0400 | [diff] [blame] | 5062 | wl_resource_destroy(resource); |
Kristian Høgsberg | 7584062 | 2011-09-06 13:48:16 -0400 | [diff] [blame] | 5063 | } |
| 5064 | |
Pekka Paalanen | 6e16811 | 2011-11-24 11:34:05 +0200 | [diff] [blame] | 5065 | static void |
Jason Ekstrand | 918f2dd | 2013-12-02 21:01:53 -0600 | [diff] [blame] | 5066 | 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] | 5067 | { |
Giulio Camuffo | 7fe01b1 | 2013-03-28 18:02:42 +0100 | [diff] [blame] | 5068 | struct desktop_shell *shell = surface->configure_private; |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 5069 | struct weston_view *view; |
Kristian Høgsberg | 1a73a63 | 2012-06-26 22:15:53 -0400 | [diff] [blame] | 5070 | |
Jason Ekstrand | 918f2dd | 2013-12-02 21:01:53 -0600 | [diff] [blame] | 5071 | if (surface->width == 0) |
Giulio Camuffo | 184df50 | 2013-02-21 11:29:21 +0100 | [diff] [blame] | 5072 | return; |
| 5073 | |
Pekka Paalanen | 3a1d07d | 2012-12-20 14:02:13 +0200 | [diff] [blame] | 5074 | /* XXX: starting weston-screensaver beforehand does not work */ |
Kristian Høgsberg | 1a73a63 | 2012-06-26 22:15:53 -0400 | [diff] [blame] | 5075 | if (!shell->locked) |
| 5076 | return; |
| 5077 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 5078 | view = container_of(surface->views.next, struct weston_view, surface_link); |
| 5079 | center_on_output(view, surface->output); |
Kristian Høgsberg | 1a73a63 | 2012-06-26 22:15:53 -0400 | [diff] [blame] | 5080 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 5081 | if (wl_list_empty(&view->layer_link)) { |
| 5082 | wl_list_insert(shell->lock_layer.view_list.prev, |
| 5083 | &view->layer_link); |
| 5084 | weston_view_update_transform(view); |
Ander Conselvan de Oliveira | 859e885 | 2013-02-21 18:35:21 +0200 | [diff] [blame] | 5085 | wl_event_source_timer_update(shell->screensaver.timer, |
| 5086 | shell->screensaver.duration); |
Ander Conselvan de Oliveira | 19d10ef | 2013-02-21 18:35:20 +0200 | [diff] [blame] | 5087 | shell_fade(shell, FADE_IN); |
Kristian Høgsberg | 1a73a63 | 2012-06-26 22:15:53 -0400 | [diff] [blame] | 5088 | } |
| 5089 | } |
| 5090 | |
| 5091 | static void |
Pekka Paalanen | 6e16811 | 2011-11-24 11:34:05 +0200 | [diff] [blame] | 5092 | screensaver_set_surface(struct wl_client *client, |
| 5093 | struct wl_resource *resource, |
Kristian Høgsberg | 1a73a63 | 2012-06-26 22:15:53 -0400 | [diff] [blame] | 5094 | struct wl_resource *surface_resource, |
Pekka Paalanen | 6e16811 | 2011-11-24 11:34:05 +0200 | [diff] [blame] | 5095 | struct wl_resource *output_resource) |
| 5096 | { |
Jason Ekstrand | 651f00e | 2013-06-14 10:07:54 -0500 | [diff] [blame] | 5097 | struct desktop_shell *shell = wl_resource_get_user_data(resource); |
Jason Ekstrand | 0f2ef7e | 2013-06-14 10:07:53 -0500 | [diff] [blame] | 5098 | struct weston_surface *surface = |
| 5099 | wl_resource_get_user_data(surface_resource); |
Jason Ekstrand | a0d2dde | 2013-06-14 10:08:01 -0500 | [diff] [blame] | 5100 | struct weston_output *output = wl_resource_get_user_data(output_resource); |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 5101 | struct weston_view *view, *next; |
| 5102 | |
| 5103 | /* Make sure we only have one view */ |
| 5104 | wl_list_for_each_safe(view, next, &surface->views, surface_link) |
| 5105 | weston_view_destroy(view); |
| 5106 | weston_view_create(surface); |
Pekka Paalanen | 6e16811 | 2011-11-24 11:34:05 +0200 | [diff] [blame] | 5107 | |
Kristian Høgsberg | 1a73a63 | 2012-06-26 22:15:53 -0400 | [diff] [blame] | 5108 | surface->configure = screensaver_configure; |
Giulio Camuffo | 7fe01b1 | 2013-03-28 18:02:42 +0100 | [diff] [blame] | 5109 | surface->configure_private = shell; |
Pekka Paalanen | 77346a6 | 2011-11-30 16:26:35 +0200 | [diff] [blame] | 5110 | surface->output = output; |
Pekka Paalanen | 6e16811 | 2011-11-24 11:34:05 +0200 | [diff] [blame] | 5111 | } |
| 5112 | |
| 5113 | static const struct screensaver_interface screensaver_implementation = { |
| 5114 | screensaver_set_surface |
| 5115 | }; |
| 5116 | |
| 5117 | static void |
| 5118 | unbind_screensaver(struct wl_resource *resource) |
| 5119 | { |
Jason Ekstrand | 651f00e | 2013-06-14 10:07:54 -0500 | [diff] [blame] | 5120 | struct desktop_shell *shell = wl_resource_get_user_data(resource); |
Pekka Paalanen | 6e16811 | 2011-11-24 11:34:05 +0200 | [diff] [blame] | 5121 | |
Pekka Paalanen | 77346a6 | 2011-11-30 16:26:35 +0200 | [diff] [blame] | 5122 | shell->screensaver.binding = NULL; |
Pekka Paalanen | 6e16811 | 2011-11-24 11:34:05 +0200 | [diff] [blame] | 5123 | } |
| 5124 | |
| 5125 | static void |
| 5126 | bind_screensaver(struct wl_client *client, |
| 5127 | void *data, uint32_t version, uint32_t id) |
| 5128 | { |
Tiago Vignatti | be14326 | 2012-04-16 17:31:41 +0300 | [diff] [blame] | 5129 | struct desktop_shell *shell = data; |
Pekka Paalanen | 6e16811 | 2011-11-24 11:34:05 +0200 | [diff] [blame] | 5130 | struct wl_resource *resource; |
| 5131 | |
Jason Ekstrand | a85118c | 2013-06-27 20:17:02 -0500 | [diff] [blame] | 5132 | resource = wl_resource_create(client, &screensaver_interface, 1, id); |
Pekka Paalanen | 6e16811 | 2011-11-24 11:34:05 +0200 | [diff] [blame] | 5133 | |
Pekka Paalanen | 77346a6 | 2011-11-30 16:26:35 +0200 | [diff] [blame] | 5134 | if (shell->screensaver.binding == NULL) { |
Jason Ekstrand | a85118c | 2013-06-27 20:17:02 -0500 | [diff] [blame] | 5135 | wl_resource_set_implementation(resource, |
| 5136 | &screensaver_implementation, |
| 5137 | shell, unbind_screensaver); |
Pekka Paalanen | 77346a6 | 2011-11-30 16:26:35 +0200 | [diff] [blame] | 5138 | shell->screensaver.binding = resource; |
Pekka Paalanen | 6e16811 | 2011-11-24 11:34:05 +0200 | [diff] [blame] | 5139 | return; |
| 5140 | } |
| 5141 | |
| 5142 | wl_resource_post_error(resource, WL_DISPLAY_ERROR_INVALID_OBJECT, |
| 5143 | "interface object already bound"); |
Kristian Høgsberg | eae5de7 | 2012-04-11 22:42:15 -0400 | [diff] [blame] | 5144 | wl_resource_destroy(resource); |
Pekka Paalanen | 6e16811 | 2011-11-24 11:34:05 +0200 | [diff] [blame] | 5145 | } |
| 5146 | |
Kristian Høgsberg | 0704539 | 2012-02-19 18:52:44 -0500 | [diff] [blame] | 5147 | struct switcher { |
Tiago Vignatti | be14326 | 2012-04-16 17:31:41 +0300 | [diff] [blame] | 5148 | struct desktop_shell *shell; |
Kristian Høgsberg | 0704539 | 2012-02-19 18:52:44 -0500 | [diff] [blame] | 5149 | struct weston_surface *current; |
| 5150 | struct wl_listener listener; |
Kristian Høgsberg | 29139d4 | 2013-04-18 15:25:39 -0400 | [diff] [blame] | 5151 | struct weston_keyboard_grab grab; |
Kristian Høgsberg | 0704539 | 2012-02-19 18:52:44 -0500 | [diff] [blame] | 5152 | }; |
| 5153 | |
| 5154 | static void |
| 5155 | switcher_next(struct switcher *switcher) |
| 5156 | { |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 5157 | struct weston_view *view; |
Kristian Høgsberg | 0704539 | 2012-02-19 18:52:44 -0500 | [diff] [blame] | 5158 | struct weston_surface *first = NULL, *prev = NULL, *next = NULL; |
Kristian Høgsberg | 32e5686 | 2012-04-02 22:18:58 -0400 | [diff] [blame] | 5159 | struct shell_surface *shsurf; |
Kristian Høgsberg | b0d8e77 | 2012-06-18 16:34:58 -0400 | [diff] [blame] | 5160 | struct workspace *ws = get_current_workspace(switcher->shell); |
Kristian Høgsberg | 0704539 | 2012-02-19 18:52:44 -0500 | [diff] [blame] | 5161 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 5162 | wl_list_for_each(view, &ws->layer.view_list, layer_link) { |
Rafael Antognolli | ed207b4 | 2013-12-03 15:35:43 -0200 | [diff] [blame] | 5163 | shsurf = get_shell_surface(view->surface); |
Rafael Antognolli | 5031cbe | 2013-12-05 19:01:21 -0200 | [diff] [blame] | 5164 | if (shsurf && |
| 5165 | shsurf->type == SHELL_SURFACE_TOPLEVEL && |
| 5166 | shsurf->parent == NULL) { |
Kristian Høgsberg | 0704539 | 2012-02-19 18:52:44 -0500 | [diff] [blame] | 5167 | if (first == NULL) |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 5168 | first = view->surface; |
Kristian Høgsberg | 0704539 | 2012-02-19 18:52:44 -0500 | [diff] [blame] | 5169 | if (prev == switcher->current) |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 5170 | next = view->surface; |
| 5171 | prev = view->surface; |
| 5172 | view->alpha = 0.25; |
| 5173 | weston_view_geometry_dirty(view); |
| 5174 | weston_surface_damage(view->surface); |
Kristian Høgsberg | 0704539 | 2012-02-19 18:52:44 -0500 | [diff] [blame] | 5175 | } |
Alex Wu | 1659daa | 2012-04-01 20:13:09 +0800 | [diff] [blame] | 5176 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 5177 | if (is_black_surface(view->surface, NULL)) { |
| 5178 | view->alpha = 0.25; |
| 5179 | weston_view_geometry_dirty(view); |
| 5180 | weston_surface_damage(view->surface); |
Alex Wu | 1659daa | 2012-04-01 20:13:09 +0800 | [diff] [blame] | 5181 | } |
Kristian Høgsberg | 0704539 | 2012-02-19 18:52:44 -0500 | [diff] [blame] | 5182 | } |
| 5183 | |
| 5184 | if (next == NULL) |
| 5185 | next = first; |
| 5186 | |
Alex Wu | 07b2606 | 2012-03-12 16:06:01 +0800 | [diff] [blame] | 5187 | if (next == NULL) |
| 5188 | return; |
| 5189 | |
Kristian Høgsberg | 0704539 | 2012-02-19 18:52:44 -0500 | [diff] [blame] | 5190 | wl_list_remove(&switcher->listener.link); |
Jason Ekstrand | 26ed73c | 2013-06-06 22:34:41 -0500 | [diff] [blame] | 5191 | wl_signal_add(&next->destroy_signal, &switcher->listener); |
Kristian Høgsberg | 0704539 | 2012-02-19 18:52:44 -0500 | [diff] [blame] | 5192 | |
| 5193 | switcher->current = next; |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 5194 | wl_list_for_each(view, &next->views, surface_link) |
| 5195 | view->alpha = 1.0; |
Alex Wu | 1659daa | 2012-04-01 20:13:09 +0800 | [diff] [blame] | 5196 | |
Kristian Høgsberg | 32e5686 | 2012-04-02 22:18:58 -0400 | [diff] [blame] | 5197 | shsurf = get_shell_surface(switcher->current); |
Rafael Antognolli | 03b1659 | 2013-12-03 15:35:42 -0200 | [diff] [blame] | 5198 | if (shsurf && shsurf->state.fullscreen) |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 5199 | shsurf->fullscreen.black_view->alpha = 1.0; |
Kristian Høgsberg | 0704539 | 2012-02-19 18:52:44 -0500 | [diff] [blame] | 5200 | } |
| 5201 | |
| 5202 | static void |
Kristian Høgsberg | 27e3052 | 2012-04-11 23:18:23 -0400 | [diff] [blame] | 5203 | switcher_handle_surface_destroy(struct wl_listener *listener, void *data) |
Kristian Høgsberg | 0704539 | 2012-02-19 18:52:44 -0500 | [diff] [blame] | 5204 | { |
| 5205 | struct switcher *switcher = |
| 5206 | container_of(listener, struct switcher, listener); |
| 5207 | |
| 5208 | switcher_next(switcher); |
| 5209 | } |
| 5210 | |
| 5211 | static void |
Daniel Stone | 351eb61 | 2012-05-31 15:27:47 -0400 | [diff] [blame] | 5212 | switcher_destroy(struct switcher *switcher) |
Kristian Høgsberg | 0704539 | 2012-02-19 18:52:44 -0500 | [diff] [blame] | 5213 | { |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 5214 | struct weston_view *view; |
Kristian Høgsberg | 29139d4 | 2013-04-18 15:25:39 -0400 | [diff] [blame] | 5215 | struct weston_keyboard *keyboard = switcher->grab.keyboard; |
Kristian Høgsberg | b0d8e77 | 2012-06-18 16:34:58 -0400 | [diff] [blame] | 5216 | struct workspace *ws = get_current_workspace(switcher->shell); |
Kristian Høgsberg | 0704539 | 2012-02-19 18:52:44 -0500 | [diff] [blame] | 5217 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 5218 | 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] | 5219 | if (is_focus_view(view)) |
| 5220 | continue; |
| 5221 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 5222 | view->alpha = 1.0; |
| 5223 | weston_surface_damage(view->surface); |
Kristian Høgsberg | 0704539 | 2012-02-19 18:52:44 -0500 | [diff] [blame] | 5224 | } |
| 5225 | |
Alex Wu | 07b2606 | 2012-03-12 16:06:01 +0800 | [diff] [blame] | 5226 | if (switcher->current) |
Daniel Stone | 37816df | 2012-05-16 18:45:18 +0100 | [diff] [blame] | 5227 | activate(switcher->shell, switcher->current, |
| 5228 | (struct weston_seat *) keyboard->seat); |
Kristian Høgsberg | 0704539 | 2012-02-19 18:52:44 -0500 | [diff] [blame] | 5229 | wl_list_remove(&switcher->listener.link); |
Kristian Høgsberg | 29139d4 | 2013-04-18 15:25:39 -0400 | [diff] [blame] | 5230 | weston_keyboard_end_grab(keyboard); |
| 5231 | if (keyboard->input_method_resource) |
| 5232 | keyboard->grab = &keyboard->input_method_grab; |
Kristian Høgsberg | 0704539 | 2012-02-19 18:52:44 -0500 | [diff] [blame] | 5233 | free(switcher); |
| 5234 | } |
| 5235 | |
| 5236 | static void |
Kristian Høgsberg | 29139d4 | 2013-04-18 15:25:39 -0400 | [diff] [blame] | 5237 | switcher_key(struct weston_keyboard_grab *grab, |
Daniel Stone | c9785ea | 2012-05-30 16:31:52 +0100 | [diff] [blame] | 5238 | uint32_t time, uint32_t key, uint32_t state_w) |
Kristian Høgsberg | 0704539 | 2012-02-19 18:52:44 -0500 | [diff] [blame] | 5239 | { |
| 5240 | struct switcher *switcher = container_of(grab, struct switcher, grab); |
Daniel Stone | c9785ea | 2012-05-30 16:31:52 +0100 | [diff] [blame] | 5241 | enum wl_keyboard_key_state state = state_w; |
Daniel Stone | 351eb61 | 2012-05-31 15:27:47 -0400 | [diff] [blame] | 5242 | |
Daniel Stone | c9785ea | 2012-05-30 16:31:52 +0100 | [diff] [blame] | 5243 | if (key == KEY_TAB && state == WL_KEYBOARD_KEY_STATE_PRESSED) |
Daniel Stone | 351eb61 | 2012-05-31 15:27:47 -0400 | [diff] [blame] | 5244 | switcher_next(switcher); |
| 5245 | } |
| 5246 | |
| 5247 | static void |
Kristian Høgsberg | 29139d4 | 2013-04-18 15:25:39 -0400 | [diff] [blame] | 5248 | switcher_modifier(struct weston_keyboard_grab *grab, uint32_t serial, |
Daniel Stone | 351eb61 | 2012-05-31 15:27:47 -0400 | [diff] [blame] | 5249 | uint32_t mods_depressed, uint32_t mods_latched, |
| 5250 | uint32_t mods_locked, uint32_t group) |
| 5251 | { |
| 5252 | struct switcher *switcher = container_of(grab, struct switcher, grab); |
Daniel Stone | 37816df | 2012-05-16 18:45:18 +0100 | [diff] [blame] | 5253 | struct weston_seat *seat = (struct weston_seat *) grab->keyboard->seat; |
Kristian Høgsberg | 0704539 | 2012-02-19 18:52:44 -0500 | [diff] [blame] | 5254 | |
Daniel Stone | 351eb61 | 2012-05-31 15:27:47 -0400 | [diff] [blame] | 5255 | if ((seat->modifier_state & switcher->shell->binding_modifier) == 0) |
| 5256 | switcher_destroy(switcher); |
Kristian Høgsberg | b71302e | 2012-05-10 12:28:35 -0400 | [diff] [blame] | 5257 | } |
Kristian Høgsberg | 0704539 | 2012-02-19 18:52:44 -0500 | [diff] [blame] | 5258 | |
Jonas Ådahl | 1ea343e | 2013-10-25 23:18:05 +0200 | [diff] [blame] | 5259 | static void |
| 5260 | switcher_cancel(struct weston_keyboard_grab *grab) |
| 5261 | { |
| 5262 | struct switcher *switcher = container_of(grab, struct switcher, grab); |
| 5263 | |
| 5264 | switcher_destroy(switcher); |
| 5265 | } |
| 5266 | |
Kristian Høgsberg | 29139d4 | 2013-04-18 15:25:39 -0400 | [diff] [blame] | 5267 | static const struct weston_keyboard_grab_interface switcher_grab = { |
Daniel Stone | 351eb61 | 2012-05-31 15:27:47 -0400 | [diff] [blame] | 5268 | switcher_key, |
| 5269 | switcher_modifier, |
Jonas Ådahl | 1ea343e | 2013-10-25 23:18:05 +0200 | [diff] [blame] | 5270 | switcher_cancel, |
Kristian Høgsberg | 0704539 | 2012-02-19 18:52:44 -0500 | [diff] [blame] | 5271 | }; |
| 5272 | |
| 5273 | static void |
Kristian Høgsberg | e314875 | 2013-05-06 23:19:49 -0400 | [diff] [blame] | 5274 | switcher_binding(struct weston_seat *seat, uint32_t time, uint32_t key, |
Daniel Stone | 325fc2d | 2012-05-30 16:31:58 +0100 | [diff] [blame] | 5275 | void *data) |
Kristian Høgsberg | 0704539 | 2012-02-19 18:52:44 -0500 | [diff] [blame] | 5276 | { |
Tiago Vignatti | be14326 | 2012-04-16 17:31:41 +0300 | [diff] [blame] | 5277 | struct desktop_shell *shell = data; |
Kristian Høgsberg | 0704539 | 2012-02-19 18:52:44 -0500 | [diff] [blame] | 5278 | struct switcher *switcher; |
| 5279 | |
| 5280 | switcher = malloc(sizeof *switcher); |
Kristian Høgsberg | 02e79dc | 2012-04-12 09:55:26 -0400 | [diff] [blame] | 5281 | switcher->shell = shell; |
Kristian Høgsberg | 0704539 | 2012-02-19 18:52:44 -0500 | [diff] [blame] | 5282 | switcher->current = NULL; |
Kristian Høgsberg | 27e3052 | 2012-04-11 23:18:23 -0400 | [diff] [blame] | 5283 | switcher->listener.notify = switcher_handle_surface_destroy; |
Kristian Høgsberg | 0704539 | 2012-02-19 18:52:44 -0500 | [diff] [blame] | 5284 | wl_list_init(&switcher->listener.link); |
| 5285 | |
Alexander Larsson | f82b6ca | 2013-05-28 16:23:39 +0200 | [diff] [blame] | 5286 | restore_all_output_modes(shell->compositor); |
Kristian Høgsberg | b0d8e77 | 2012-06-18 16:34:58 -0400 | [diff] [blame] | 5287 | lower_fullscreen_layer(switcher->shell); |
Kristian Høgsberg | 0704539 | 2012-02-19 18:52:44 -0500 | [diff] [blame] | 5288 | switcher->grab.interface = &switcher_grab; |
Kristian Høgsberg | 29139d4 | 2013-04-18 15:25:39 -0400 | [diff] [blame] | 5289 | weston_keyboard_start_grab(seat->keyboard, &switcher->grab); |
| 5290 | weston_keyboard_set_focus(seat->keyboard, NULL); |
Kristian Høgsberg | 0704539 | 2012-02-19 18:52:44 -0500 | [diff] [blame] | 5291 | switcher_next(switcher); |
| 5292 | } |
| 5293 | |
Pekka Paalanen | 3c64723 | 2011-12-22 13:43:43 +0200 | [diff] [blame] | 5294 | static void |
Kristian Høgsberg | e314875 | 2013-05-06 23:19:49 -0400 | [diff] [blame] | 5295 | backlight_binding(struct weston_seat *seat, uint32_t time, uint32_t key, |
Daniel Stone | 325fc2d | 2012-05-30 16:31:58 +0100 | [diff] [blame] | 5296 | void *data) |
Tiago Vignatti | 8e53c7f | 2012-02-29 19:53:50 +0200 | [diff] [blame] | 5297 | { |
| 5298 | struct weston_compositor *compositor = data; |
| 5299 | struct weston_output *output; |
Tiago Vignatti | 5ab91ad | 2012-03-12 19:40:09 -0300 | [diff] [blame] | 5300 | long backlight_new = 0; |
Tiago Vignatti | 8e53c7f | 2012-02-29 19:53:50 +0200 | [diff] [blame] | 5301 | |
| 5302 | /* TODO: we're limiting to simple use cases, where we assume just |
| 5303 | * control on the primary display. We'd have to extend later if we |
| 5304 | * ever get support for setting backlights on random desktop LCD |
| 5305 | * panels though */ |
| 5306 | output = get_default_output(compositor); |
| 5307 | if (!output) |
| 5308 | return; |
| 5309 | |
| 5310 | if (!output->set_backlight) |
| 5311 | return; |
| 5312 | |
Tiago Vignatti | 5ab91ad | 2012-03-12 19:40:09 -0300 | [diff] [blame] | 5313 | if (key == KEY_F9 || key == KEY_BRIGHTNESSDOWN) |
| 5314 | backlight_new = output->backlight_current - 25; |
| 5315 | else if (key == KEY_F10 || key == KEY_BRIGHTNESSUP) |
| 5316 | backlight_new = output->backlight_current + 25; |
Tiago Vignatti | 8e53c7f | 2012-02-29 19:53:50 +0200 | [diff] [blame] | 5317 | |
Tiago Vignatti | 5ab91ad | 2012-03-12 19:40:09 -0300 | [diff] [blame] | 5318 | if (backlight_new < 5) |
| 5319 | backlight_new = 5; |
| 5320 | if (backlight_new > 255) |
| 5321 | backlight_new = 255; |
| 5322 | |
| 5323 | output->backlight_current = backlight_new; |
Tiago Vignatti | 8e53c7f | 2012-02-29 19:53:50 +0200 | [diff] [blame] | 5324 | output->set_backlight(output, output->backlight_current); |
| 5325 | } |
| 5326 | |
Ander Conselvan de Oliveira | c509d2b | 2012-11-08 17:20:45 +0200 | [diff] [blame] | 5327 | struct debug_binding_grab { |
Kristian Høgsberg | 29139d4 | 2013-04-18 15:25:39 -0400 | [diff] [blame] | 5328 | struct weston_keyboard_grab grab; |
Ander Conselvan de Oliveira | c509d2b | 2012-11-08 17:20:45 +0200 | [diff] [blame] | 5329 | struct weston_seat *seat; |
| 5330 | uint32_t key[2]; |
| 5331 | int key_released[2]; |
| 5332 | }; |
| 5333 | |
| 5334 | static void |
Kristian Høgsberg | 29139d4 | 2013-04-18 15:25:39 -0400 | [diff] [blame] | 5335 | 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] | 5336 | uint32_t key, uint32_t state) |
| 5337 | { |
| 5338 | struct debug_binding_grab *db = (struct debug_binding_grab *) grab; |
Rob Bradford | 880ebc7 | 2013-07-22 17:31:38 +0100 | [diff] [blame] | 5339 | struct weston_compositor *ec = db->seat->compositor; |
| 5340 | struct wl_display *display = ec->wl_display; |
Ander Conselvan de Oliveira | c509d2b | 2012-11-08 17:20:45 +0200 | [diff] [blame] | 5341 | struct wl_resource *resource; |
Ander Conselvan de Oliveira | c509d2b | 2012-11-08 17:20:45 +0200 | [diff] [blame] | 5342 | uint32_t serial; |
| 5343 | int send = 0, terminate = 0; |
| 5344 | int check_binding = 1; |
| 5345 | int i; |
Neil Roberts | 96d790e | 2013-09-19 17:32:00 +0100 | [diff] [blame] | 5346 | struct wl_list *resource_list; |
Ander Conselvan de Oliveira | c509d2b | 2012-11-08 17:20:45 +0200 | [diff] [blame] | 5347 | |
| 5348 | if (state == WL_KEYBOARD_KEY_STATE_RELEASED) { |
| 5349 | /* Do not run bindings on key releases */ |
| 5350 | check_binding = 0; |
| 5351 | |
| 5352 | for (i = 0; i < 2; i++) |
| 5353 | if (key == db->key[i]) |
| 5354 | db->key_released[i] = 1; |
| 5355 | |
| 5356 | if (db->key_released[0] && db->key_released[1]) { |
| 5357 | /* All key releases been swalled so end the grab */ |
| 5358 | terminate = 1; |
| 5359 | } else if (key != db->key[0] && key != db->key[1]) { |
| 5360 | /* Should not swallow release of other keys */ |
| 5361 | send = 1; |
| 5362 | } |
| 5363 | } else if (key == db->key[0] && !db->key_released[0]) { |
| 5364 | /* Do not check bindings for the first press of the binding |
| 5365 | * key. This allows it to be used as a debug shortcut. |
| 5366 | * We still need to swallow this event. */ |
| 5367 | check_binding = 0; |
| 5368 | } else if (db->key[1]) { |
| 5369 | /* If we already ran a binding don't process another one since |
| 5370 | * we can't keep track of all the binding keys that were |
| 5371 | * pressed in order to swallow the release events. */ |
| 5372 | send = 1; |
| 5373 | check_binding = 0; |
| 5374 | } |
| 5375 | |
| 5376 | if (check_binding) { |
Ander Conselvan de Oliveira | c509d2b | 2012-11-08 17:20:45 +0200 | [diff] [blame] | 5377 | if (weston_compositor_run_debug_binding(ec, db->seat, time, |
| 5378 | key, state)) { |
| 5379 | /* We ran a binding so swallow the press and keep the |
| 5380 | * grab to swallow the released too. */ |
| 5381 | send = 0; |
| 5382 | terminate = 0; |
| 5383 | db->key[1] = key; |
| 5384 | } else { |
| 5385 | /* Terminate the grab since the key pressed is not a |
| 5386 | * debug binding key. */ |
| 5387 | send = 1; |
| 5388 | terminate = 1; |
| 5389 | } |
| 5390 | } |
| 5391 | |
| 5392 | if (send) { |
Neil Roberts | 96d790e | 2013-09-19 17:32:00 +0100 | [diff] [blame] | 5393 | serial = wl_display_next_serial(display); |
| 5394 | resource_list = &grab->keyboard->focus_resource_list; |
| 5395 | wl_resource_for_each(resource, resource_list) { |
Ander Conselvan de Oliveira | c509d2b | 2012-11-08 17:20:45 +0200 | [diff] [blame] | 5396 | wl_keyboard_send_key(resource, serial, time, key, state); |
| 5397 | } |
| 5398 | } |
| 5399 | |
| 5400 | if (terminate) { |
Kristian Høgsberg | 29139d4 | 2013-04-18 15:25:39 -0400 | [diff] [blame] | 5401 | weston_keyboard_end_grab(grab->keyboard); |
| 5402 | if (grab->keyboard->input_method_resource) |
| 5403 | grab->keyboard->grab = &grab->keyboard->input_method_grab; |
Ander Conselvan de Oliveira | c509d2b | 2012-11-08 17:20:45 +0200 | [diff] [blame] | 5404 | free(db); |
| 5405 | } |
| 5406 | } |
| 5407 | |
| 5408 | static void |
Kristian Høgsberg | 29139d4 | 2013-04-18 15:25:39 -0400 | [diff] [blame] | 5409 | 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] | 5410 | uint32_t mods_depressed, uint32_t mods_latched, |
| 5411 | uint32_t mods_locked, uint32_t group) |
| 5412 | { |
| 5413 | struct wl_resource *resource; |
Neil Roberts | 96d790e | 2013-09-19 17:32:00 +0100 | [diff] [blame] | 5414 | struct wl_list *resource_list; |
Ander Conselvan de Oliveira | c509d2b | 2012-11-08 17:20:45 +0200 | [diff] [blame] | 5415 | |
Neil Roberts | 96d790e | 2013-09-19 17:32:00 +0100 | [diff] [blame] | 5416 | resource_list = &grab->keyboard->focus_resource_list; |
Ander Conselvan de Oliveira | c509d2b | 2012-11-08 17:20:45 +0200 | [diff] [blame] | 5417 | |
Neil Roberts | 96d790e | 2013-09-19 17:32:00 +0100 | [diff] [blame] | 5418 | wl_resource_for_each(resource, resource_list) { |
| 5419 | wl_keyboard_send_modifiers(resource, serial, mods_depressed, |
| 5420 | mods_latched, mods_locked, group); |
| 5421 | } |
Ander Conselvan de Oliveira | c509d2b | 2012-11-08 17:20:45 +0200 | [diff] [blame] | 5422 | } |
| 5423 | |
Jonas Ådahl | 1ea343e | 2013-10-25 23:18:05 +0200 | [diff] [blame] | 5424 | static void |
| 5425 | debug_binding_cancel(struct weston_keyboard_grab *grab) |
| 5426 | { |
| 5427 | struct debug_binding_grab *db = (struct debug_binding_grab *) grab; |
| 5428 | |
| 5429 | weston_keyboard_end_grab(grab->keyboard); |
| 5430 | free(db); |
| 5431 | } |
| 5432 | |
Kristian Høgsberg | 29139d4 | 2013-04-18 15:25:39 -0400 | [diff] [blame] | 5433 | struct weston_keyboard_grab_interface debug_binding_keyboard_grab = { |
Ander Conselvan de Oliveira | c509d2b | 2012-11-08 17:20:45 +0200 | [diff] [blame] | 5434 | debug_binding_key, |
Jonas Ådahl | 1ea343e | 2013-10-25 23:18:05 +0200 | [diff] [blame] | 5435 | debug_binding_modifiers, |
| 5436 | debug_binding_cancel, |
Ander Conselvan de Oliveira | c509d2b | 2012-11-08 17:20:45 +0200 | [diff] [blame] | 5437 | }; |
| 5438 | |
| 5439 | static void |
Kristian Høgsberg | e314875 | 2013-05-06 23:19:49 -0400 | [diff] [blame] | 5440 | 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] | 5441 | { |
| 5442 | struct debug_binding_grab *grab; |
| 5443 | |
| 5444 | grab = calloc(1, sizeof *grab); |
| 5445 | if (!grab) |
| 5446 | return; |
| 5447 | |
| 5448 | grab->seat = (struct weston_seat *) seat; |
| 5449 | grab->key[0] = key; |
| 5450 | grab->grab.interface = &debug_binding_keyboard_grab; |
Kristian Høgsberg | 29139d4 | 2013-04-18 15:25:39 -0400 | [diff] [blame] | 5451 | weston_keyboard_start_grab(seat->keyboard, &grab->grab); |
Ander Conselvan de Oliveira | c509d2b | 2012-11-08 17:20:45 +0200 | [diff] [blame] | 5452 | } |
| 5453 | |
Kristian Høgsberg | b41c081 | 2012-03-04 14:53:40 -0500 | [diff] [blame] | 5454 | static void |
Kristian Høgsberg | e314875 | 2013-05-06 23:19:49 -0400 | [diff] [blame] | 5455 | 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] | 5456 | void *data) |
Kristian Høgsberg | 92a57db | 2012-05-26 13:41:06 -0400 | [diff] [blame] | 5457 | { |
Kristian Høgsberg | fe7aa90 | 2013-05-08 09:54:37 -0400 | [diff] [blame] | 5458 | struct weston_surface *focus_surface; |
Kristian Høgsberg | 92a57db | 2012-05-26 13:41:06 -0400 | [diff] [blame] | 5459 | struct wl_client *client; |
Tiago Vignatti | 1d01b01 | 2012-09-27 17:48:36 +0300 | [diff] [blame] | 5460 | struct desktop_shell *shell = data; |
| 5461 | struct weston_compositor *compositor = shell->compositor; |
Kristian Høgsberg | 92a57db | 2012-05-26 13:41:06 -0400 | [diff] [blame] | 5462 | pid_t pid; |
Kristian Høgsberg | 92a57db | 2012-05-26 13:41:06 -0400 | [diff] [blame] | 5463 | |
Philipp Brüschweiler | 6cef009 | 2012-08-13 21:27:27 +0200 | [diff] [blame] | 5464 | focus_surface = seat->keyboard->focus; |
| 5465 | if (!focus_surface) |
| 5466 | return; |
| 5467 | |
Tiago Vignatti | 1d01b01 | 2012-09-27 17:48:36 +0300 | [diff] [blame] | 5468 | wl_signal_emit(&compositor->kill_signal, focus_surface); |
| 5469 | |
Jason Ekstrand | 26ed73c | 2013-06-06 22:34:41 -0500 | [diff] [blame] | 5470 | client = wl_resource_get_client(focus_surface->resource); |
Tiago Vignatti | 920f197 | 2012-09-27 17:48:35 +0300 | [diff] [blame] | 5471 | wl_client_get_credentials(client, &pid, NULL, NULL); |
| 5472 | |
| 5473 | /* Skip clients that we launched ourselves (the credentials of |
| 5474 | * the socketpair is ours) */ |
| 5475 | if (pid == getpid()) |
| 5476 | return; |
Kristian Høgsberg | 92a57db | 2012-05-26 13:41:06 -0400 | [diff] [blame] | 5477 | |
Daniel Stone | 325fc2d | 2012-05-30 16:31:58 +0100 | [diff] [blame] | 5478 | kill(pid, SIGKILL); |
Kristian Høgsberg | 92a57db | 2012-05-26 13:41:06 -0400 | [diff] [blame] | 5479 | } |
| 5480 | |
| 5481 | static void |
Kristian Høgsberg | e314875 | 2013-05-06 23:19:49 -0400 | [diff] [blame] | 5482 | workspace_up_binding(struct weston_seat *seat, uint32_t time, |
Jonas Ådahl | e3cddce | 2012-06-13 00:01:22 +0200 | [diff] [blame] | 5483 | uint32_t key, void *data) |
| 5484 | { |
| 5485 | struct desktop_shell *shell = data; |
| 5486 | unsigned int new_index = shell->workspaces.current; |
| 5487 | |
Kristian Høgsberg | ce345b0 | 2012-06-25 21:35:29 -0400 | [diff] [blame] | 5488 | if (shell->locked) |
Kristian Høgsberg | 4476aaf | 2012-06-25 14:03:13 -0400 | [diff] [blame] | 5489 | return; |
Jonas Ådahl | e3cddce | 2012-06-13 00:01:22 +0200 | [diff] [blame] | 5490 | if (new_index != 0) |
| 5491 | new_index--; |
| 5492 | |
| 5493 | change_workspace(shell, new_index); |
| 5494 | } |
| 5495 | |
| 5496 | static void |
Kristian Høgsberg | e314875 | 2013-05-06 23:19:49 -0400 | [diff] [blame] | 5497 | workspace_down_binding(struct weston_seat *seat, uint32_t time, |
Jonas Ådahl | e3cddce | 2012-06-13 00:01:22 +0200 | [diff] [blame] | 5498 | uint32_t key, void *data) |
| 5499 | { |
| 5500 | struct desktop_shell *shell = data; |
| 5501 | unsigned int new_index = shell->workspaces.current; |
| 5502 | |
Kristian Høgsberg | ce345b0 | 2012-06-25 21:35:29 -0400 | [diff] [blame] | 5503 | if (shell->locked) |
Kristian Høgsberg | 4476aaf | 2012-06-25 14:03:13 -0400 | [diff] [blame] | 5504 | return; |
Jonas Ådahl | e3cddce | 2012-06-13 00:01:22 +0200 | [diff] [blame] | 5505 | if (new_index < shell->workspaces.num - 1) |
| 5506 | new_index++; |
| 5507 | |
| 5508 | change_workspace(shell, new_index); |
| 5509 | } |
| 5510 | |
| 5511 | static void |
Kristian Høgsberg | e314875 | 2013-05-06 23:19:49 -0400 | [diff] [blame] | 5512 | workspace_f_binding(struct weston_seat *seat, uint32_t time, |
Jonas Ådahl | e3cddce | 2012-06-13 00:01:22 +0200 | [diff] [blame] | 5513 | uint32_t key, void *data) |
| 5514 | { |
| 5515 | struct desktop_shell *shell = data; |
| 5516 | unsigned int new_index; |
| 5517 | |
Kristian Høgsberg | ce345b0 | 2012-06-25 21:35:29 -0400 | [diff] [blame] | 5518 | if (shell->locked) |
Kristian Høgsberg | 4476aaf | 2012-06-25 14:03:13 -0400 | [diff] [blame] | 5519 | return; |
Jonas Ådahl | e3cddce | 2012-06-13 00:01:22 +0200 | [diff] [blame] | 5520 | new_index = key - KEY_F1; |
| 5521 | if (new_index >= shell->workspaces.num) |
| 5522 | new_index = shell->workspaces.num - 1; |
| 5523 | |
| 5524 | change_workspace(shell, new_index); |
| 5525 | } |
| 5526 | |
Jonas Ådahl | 8de6a1d | 2012-08-29 22:13:00 +0200 | [diff] [blame] | 5527 | static void |
Kristian Høgsberg | e314875 | 2013-05-06 23:19:49 -0400 | [diff] [blame] | 5528 | workspace_move_surface_up_binding(struct weston_seat *seat, uint32_t time, |
Jonas Ådahl | 8de6a1d | 2012-08-29 22:13:00 +0200 | [diff] [blame] | 5529 | uint32_t key, void *data) |
| 5530 | { |
| 5531 | struct desktop_shell *shell = data; |
| 5532 | unsigned int new_index = shell->workspaces.current; |
| 5533 | |
| 5534 | if (shell->locked) |
| 5535 | return; |
| 5536 | |
| 5537 | if (new_index != 0) |
| 5538 | new_index--; |
| 5539 | |
| 5540 | take_surface_to_workspace_by_seat(shell, seat, new_index); |
| 5541 | } |
| 5542 | |
| 5543 | static void |
Kristian Høgsberg | e314875 | 2013-05-06 23:19:49 -0400 | [diff] [blame] | 5544 | workspace_move_surface_down_binding(struct weston_seat *seat, uint32_t time, |
Jonas Ådahl | 8de6a1d | 2012-08-29 22:13:00 +0200 | [diff] [blame] | 5545 | uint32_t key, void *data) |
| 5546 | { |
| 5547 | struct desktop_shell *shell = data; |
| 5548 | unsigned int new_index = shell->workspaces.current; |
| 5549 | |
| 5550 | if (shell->locked) |
| 5551 | return; |
| 5552 | |
| 5553 | if (new_index < shell->workspaces.num - 1) |
| 5554 | new_index++; |
| 5555 | |
| 5556 | take_surface_to_workspace_by_seat(shell, seat, new_index); |
| 5557 | } |
Jonas Ådahl | e3cddce | 2012-06-13 00:01:22 +0200 | [diff] [blame] | 5558 | |
| 5559 | static void |
Ander Conselvan de Oliveira | c94d622 | 2014-01-29 18:47:54 +0200 | [diff] [blame] | 5560 | shell_reposition_view_on_output_destroy(struct weston_view *view) |
| 5561 | { |
| 5562 | struct weston_output *output, *first_output; |
| 5563 | struct weston_compositor *ec = view->surface->compositor; |
| 5564 | struct shell_surface *shsurf; |
| 5565 | float x, y; |
| 5566 | int visible; |
| 5567 | |
| 5568 | x = view->geometry.x; |
| 5569 | y = view->geometry.y; |
| 5570 | |
| 5571 | /* At this point the destroyed output is not in the list anymore. |
| 5572 | * If the view is still visible somewhere, we leave where it is, |
| 5573 | * otherwise, move it to the first output. */ |
| 5574 | visible = 0; |
| 5575 | wl_list_for_each(output, &ec->output_list, link) { |
| 5576 | if (pixman_region32_contains_point(&output->region, |
| 5577 | x, y, NULL)) { |
| 5578 | visible = 1; |
| 5579 | break; |
| 5580 | } |
| 5581 | } |
| 5582 | |
| 5583 | if (!visible) { |
| 5584 | first_output = container_of(ec->output_list.next, |
| 5585 | struct weston_output, link); |
| 5586 | |
| 5587 | x = first_output->x + first_output->width / 4; |
| 5588 | y = first_output->y + first_output->height / 4; |
| 5589 | } |
| 5590 | |
| 5591 | weston_view_set_position(view, x, y); |
| 5592 | |
| 5593 | shsurf = get_shell_surface(view->surface); |
| 5594 | |
| 5595 | if (shsurf) { |
| 5596 | shsurf->saved_position_valid = false; |
| 5597 | shsurf->next_state.maximized = false; |
| 5598 | shsurf->next_state.fullscreen = false; |
| 5599 | shsurf->state_changed = true; |
| 5600 | } |
| 5601 | } |
| 5602 | |
| 5603 | static void |
| 5604 | shell_reposition_views_on_output_destroy(struct shell_output *shell_output) |
| 5605 | { |
| 5606 | struct desktop_shell *shell = shell_output->shell; |
| 5607 | struct weston_output *output = shell_output->output; |
| 5608 | struct weston_layer *layer; |
| 5609 | struct weston_view *view; |
| 5610 | |
| 5611 | /* Move all views in the layers owned by the shell */ |
| 5612 | wl_list_for_each(layer, shell->fullscreen_layer.link.prev, link) { |
| 5613 | wl_list_for_each(view, &layer->view_list, layer_link) { |
| 5614 | if (view->output != output) |
| 5615 | continue; |
| 5616 | |
| 5617 | shell_reposition_view_on_output_destroy(view); |
| 5618 | } |
| 5619 | |
| 5620 | /* We don't start from the beggining of the layer list, so |
| 5621 | * make sure we don't wrap around it. */ |
| 5622 | if (layer == &shell->background_layer) |
| 5623 | break; |
| 5624 | } |
| 5625 | } |
| 5626 | |
| 5627 | static void |
Xiong Zhang | 6b48142 | 2013-10-23 13:58:32 +0800 | [diff] [blame] | 5628 | handle_output_destroy(struct wl_listener *listener, void *data) |
| 5629 | { |
| 5630 | struct shell_output *output_listener = |
| 5631 | container_of(listener, struct shell_output, destroy_listener); |
| 5632 | |
Ander Conselvan de Oliveira | c94d622 | 2014-01-29 18:47:54 +0200 | [diff] [blame] | 5633 | shell_reposition_views_on_output_destroy(output_listener); |
| 5634 | |
Xiong Zhang | 6b48142 | 2013-10-23 13:58:32 +0800 | [diff] [blame] | 5635 | wl_list_remove(&output_listener->destroy_listener.link); |
| 5636 | wl_list_remove(&output_listener->link); |
| 5637 | free(output_listener); |
| 5638 | } |
| 5639 | |
| 5640 | static void |
| 5641 | create_shell_output(struct desktop_shell *shell, |
| 5642 | struct weston_output *output) |
| 5643 | { |
| 5644 | struct shell_output *shell_output; |
| 5645 | |
| 5646 | shell_output = zalloc(sizeof *shell_output); |
| 5647 | if (shell_output == NULL) |
| 5648 | return; |
| 5649 | |
| 5650 | shell_output->output = output; |
| 5651 | shell_output->shell = shell; |
| 5652 | shell_output->destroy_listener.notify = handle_output_destroy; |
| 5653 | wl_signal_add(&output->destroy_signal, |
| 5654 | &shell_output->destroy_listener); |
Kristian Høgsberg | a3a0e18 | 2013-10-23 23:36:04 -0700 | [diff] [blame] | 5655 | wl_list_insert(shell->output_list.prev, &shell_output->link); |
Xiong Zhang | 6b48142 | 2013-10-23 13:58:32 +0800 | [diff] [blame] | 5656 | } |
| 5657 | |
| 5658 | static void |
| 5659 | handle_output_create(struct wl_listener *listener, void *data) |
| 5660 | { |
| 5661 | struct desktop_shell *shell = |
| 5662 | container_of(listener, struct desktop_shell, output_create_listener); |
| 5663 | struct weston_output *output = (struct weston_output *)data; |
| 5664 | |
| 5665 | create_shell_output(shell, output); |
| 5666 | } |
| 5667 | |
| 5668 | static void |
Ander Conselvan de Oliveira | a8a9baf | 2014-01-29 18:47:52 +0200 | [diff] [blame] | 5669 | handle_output_move(struct wl_listener *listener, void *data) |
| 5670 | { |
| 5671 | struct desktop_shell *shell; |
| 5672 | struct weston_output *output; |
| 5673 | struct weston_layer *layer; |
| 5674 | struct weston_view *view; |
| 5675 | float x, y; |
| 5676 | |
| 5677 | shell = container_of(listener, struct desktop_shell, |
| 5678 | output_move_listener); |
| 5679 | output = data; |
| 5680 | |
| 5681 | /* Move all views in the layers owned by the shell */ |
| 5682 | wl_list_for_each(layer, shell->fullscreen_layer.link.prev, link) { |
| 5683 | wl_list_for_each(view, &layer->view_list, layer_link) { |
| 5684 | if (view->output != output) |
| 5685 | continue; |
| 5686 | |
| 5687 | x = view->geometry.x + output->move_x; |
| 5688 | y = view->geometry.y + output->move_y; |
| 5689 | weston_view_set_position(view, x, y); |
| 5690 | } |
| 5691 | |
| 5692 | /* We don't start from the beggining of the layer list, so |
| 5693 | * make sure we don't wrap around it. */ |
| 5694 | if (layer == &shell->background_layer) |
| 5695 | break; |
| 5696 | } |
| 5697 | } |
| 5698 | |
| 5699 | static void |
Xiong Zhang | 6b48142 | 2013-10-23 13:58:32 +0800 | [diff] [blame] | 5700 | setup_output_destroy_handler(struct weston_compositor *ec, |
| 5701 | struct desktop_shell *shell) |
| 5702 | { |
| 5703 | struct weston_output *output; |
| 5704 | |
| 5705 | wl_list_init(&shell->output_list); |
| 5706 | wl_list_for_each(output, &ec->output_list, link) |
| 5707 | create_shell_output(shell, output); |
| 5708 | |
| 5709 | shell->output_create_listener.notify = handle_output_create; |
| 5710 | wl_signal_add(&ec->output_created_signal, |
| 5711 | &shell->output_create_listener); |
Ander Conselvan de Oliveira | a8a9baf | 2014-01-29 18:47:52 +0200 | [diff] [blame] | 5712 | |
| 5713 | shell->output_move_listener.notify = handle_output_move; |
| 5714 | wl_signal_add(&ec->output_moved_signal, &shell->output_move_listener); |
Xiong Zhang | 6b48142 | 2013-10-23 13:58:32 +0800 | [diff] [blame] | 5715 | } |
| 5716 | |
| 5717 | static void |
Kristian Høgsberg | 02e79dc | 2012-04-12 09:55:26 -0400 | [diff] [blame] | 5718 | shell_destroy(struct wl_listener *listener, void *data) |
Pekka Paalanen | 3c64723 | 2011-12-22 13:43:43 +0200 | [diff] [blame] | 5719 | { |
Tiago Vignatti | be14326 | 2012-04-16 17:31:41 +0300 | [diff] [blame] | 5720 | struct desktop_shell *shell = |
| 5721 | container_of(listener, struct desktop_shell, destroy_listener); |
Jonas Ådahl | e3cddce | 2012-06-13 00:01:22 +0200 | [diff] [blame] | 5722 | struct workspace **ws; |
Xiong Zhang | 6b48142 | 2013-10-23 13:58:32 +0800 | [diff] [blame] | 5723 | struct shell_output *shell_output, *tmp; |
Pekka Paalanen | 3c64723 | 2011-12-22 13:43:43 +0200 | [diff] [blame] | 5724 | |
Kristian Høgsberg | 17bccae | 2014-01-16 16:46:28 -0800 | [diff] [blame] | 5725 | /* Force state to unlocked so we don't try to fade */ |
| 5726 | shell->locked = false; |
Pekka Paalanen | 9cf5cc8 | 2012-01-02 16:00:24 +0200 | [diff] [blame] | 5727 | if (shell->child.client) |
| 5728 | wl_client_destroy(shell->child.client); |
| 5729 | |
Ander Conselvan de Oliveira | a457563 | 2013-02-21 18:35:23 +0200 | [diff] [blame] | 5730 | wl_list_remove(&shell->idle_listener.link); |
| 5731 | wl_list_remove(&shell->wake_listener.link); |
Kristian Høgsberg | 677a5f5 | 2013-12-04 11:00:19 -0800 | [diff] [blame] | 5732 | |
| 5733 | input_panel_destroy(shell); |
Kristian Høgsberg | 88c1607 | 2012-05-16 08:04:19 -0400 | [diff] [blame] | 5734 | |
Xiong Zhang | 6b48142 | 2013-10-23 13:58:32 +0800 | [diff] [blame] | 5735 | wl_list_for_each_safe(shell_output, tmp, &shell->output_list, link) { |
| 5736 | wl_list_remove(&shell_output->destroy_listener.link); |
| 5737 | wl_list_remove(&shell_output->link); |
| 5738 | free(shell_output); |
| 5739 | } |
| 5740 | |
| 5741 | wl_list_remove(&shell->output_create_listener.link); |
| 5742 | |
Jonas Ådahl | e3cddce | 2012-06-13 00:01:22 +0200 | [diff] [blame] | 5743 | wl_array_for_each(ws, &shell->workspaces.array) |
| 5744 | workspace_destroy(*ws); |
| 5745 | wl_array_release(&shell->workspaces.array); |
| 5746 | |
Pekka Paalanen | 3c64723 | 2011-12-22 13:43:43 +0200 | [diff] [blame] | 5747 | free(shell->screensaver.path); |
Emilio Pozuelo Monfort | 46ce798 | 2013-11-20 13:22:29 +0100 | [diff] [blame] | 5748 | free(shell->client); |
Pekka Paalanen | 3c64723 | 2011-12-22 13:43:43 +0200 | [diff] [blame] | 5749 | free(shell); |
| 5750 | } |
| 5751 | |
Tiago Vignatti | 0b52d48 | 2012-04-20 18:54:25 +0300 | [diff] [blame] | 5752 | static void |
| 5753 | shell_add_bindings(struct weston_compositor *ec, struct desktop_shell *shell) |
| 5754 | { |
| 5755 | uint32_t mod; |
Jonas Ådahl | e3cddce | 2012-06-13 00:01:22 +0200 | [diff] [blame] | 5756 | int i, num_workspace_bindings; |
Tiago Vignatti | 0b52d48 | 2012-04-20 18:54:25 +0300 | [diff] [blame] | 5757 | |
| 5758 | /* fixed bindings */ |
Daniel Stone | 325fc2d | 2012-05-30 16:31:58 +0100 | [diff] [blame] | 5759 | weston_compositor_add_key_binding(ec, KEY_BACKSPACE, |
| 5760 | MODIFIER_CTRL | MODIFIER_ALT, |
| 5761 | terminate_binding, ec); |
| 5762 | weston_compositor_add_button_binding(ec, BTN_LEFT, 0, |
| 5763 | click_to_activate_binding, |
| 5764 | shell); |
Neil Roberts | a28c693 | 2013-10-03 16:43:04 +0100 | [diff] [blame] | 5765 | weston_compositor_add_touch_binding(ec, 0, |
| 5766 | touch_to_activate_binding, |
| 5767 | shell); |
Daniel Stone | 325fc2d | 2012-05-30 16:31:58 +0100 | [diff] [blame] | 5768 | weston_compositor_add_axis_binding(ec, WL_POINTER_AXIS_VERTICAL_SCROLL, |
| 5769 | MODIFIER_SUPER | MODIFIER_ALT, |
| 5770 | surface_opacity_binding, NULL); |
| 5771 | weston_compositor_add_axis_binding(ec, WL_POINTER_AXIS_VERTICAL_SCROLL, |
| 5772 | MODIFIER_SUPER, zoom_axis_binding, |
| 5773 | NULL); |
Tiago Vignatti | 0b52d48 | 2012-04-20 18:54:25 +0300 | [diff] [blame] | 5774 | |
| 5775 | /* configurable bindings */ |
| 5776 | mod = shell->binding_modifier; |
Daniel Stone | 325fc2d | 2012-05-30 16:31:58 +0100 | [diff] [blame] | 5777 | weston_compositor_add_key_binding(ec, KEY_PAGEUP, mod, |
| 5778 | zoom_key_binding, NULL); |
| 5779 | weston_compositor_add_key_binding(ec, KEY_PAGEDOWN, mod, |
| 5780 | zoom_key_binding, NULL); |
Kristian Høgsberg | 211b517 | 2014-01-11 13:10:21 -0800 | [diff] [blame] | 5781 | weston_compositor_add_key_binding(ec, KEY_M, mod | MODIFIER_SHIFT, |
| 5782 | maximize_binding, NULL); |
| 5783 | weston_compositor_add_key_binding(ec, KEY_F, mod | MODIFIER_SHIFT, |
| 5784 | fullscreen_binding, NULL); |
Daniel Stone | 325fc2d | 2012-05-30 16:31:58 +0100 | [diff] [blame] | 5785 | weston_compositor_add_button_binding(ec, BTN_LEFT, mod, move_binding, |
| 5786 | shell); |
Neil Roberts | aba0f25 | 2013-10-03 16:43:05 +0100 | [diff] [blame] | 5787 | weston_compositor_add_touch_binding(ec, mod, touch_move_binding, shell); |
Daniel Stone | 325fc2d | 2012-05-30 16:31:58 +0100 | [diff] [blame] | 5788 | weston_compositor_add_button_binding(ec, BTN_MIDDLE, mod, |
| 5789 | resize_binding, shell); |
Kristian Høgsberg | 0837fa9 | 2014-01-20 10:35:26 -0800 | [diff] [blame] | 5790 | weston_compositor_add_button_binding(ec, BTN_LEFT, |
| 5791 | mod | MODIFIER_SHIFT, |
| 5792 | resize_binding, shell); |
Pekka Paalanen | 7bb6510 | 2013-05-22 18:03:04 +0300 | [diff] [blame] | 5793 | |
| 5794 | if (ec->capabilities & WESTON_CAP_ROTATION_ANY) |
| 5795 | weston_compositor_add_button_binding(ec, BTN_RIGHT, mod, |
| 5796 | rotate_binding, NULL); |
| 5797 | |
Daniel Stone | 325fc2d | 2012-05-30 16:31:58 +0100 | [diff] [blame] | 5798 | weston_compositor_add_key_binding(ec, KEY_TAB, mod, switcher_binding, |
| 5799 | shell); |
| 5800 | weston_compositor_add_key_binding(ec, KEY_F9, mod, backlight_binding, |
| 5801 | ec); |
| 5802 | weston_compositor_add_key_binding(ec, KEY_BRIGHTNESSDOWN, 0, |
| 5803 | backlight_binding, ec); |
| 5804 | weston_compositor_add_key_binding(ec, KEY_F10, mod, backlight_binding, |
| 5805 | ec); |
| 5806 | weston_compositor_add_key_binding(ec, KEY_BRIGHTNESSUP, 0, |
| 5807 | backlight_binding, ec); |
Daniel Stone | 325fc2d | 2012-05-30 16:31:58 +0100 | [diff] [blame] | 5808 | weston_compositor_add_key_binding(ec, KEY_K, mod, |
| 5809 | force_kill_binding, shell); |
Jonas Ådahl | e3cddce | 2012-06-13 00:01:22 +0200 | [diff] [blame] | 5810 | weston_compositor_add_key_binding(ec, KEY_UP, mod, |
| 5811 | workspace_up_binding, shell); |
| 5812 | weston_compositor_add_key_binding(ec, KEY_DOWN, mod, |
| 5813 | workspace_down_binding, shell); |
Jonas Ådahl | 8de6a1d | 2012-08-29 22:13:00 +0200 | [diff] [blame] | 5814 | weston_compositor_add_key_binding(ec, KEY_UP, mod | MODIFIER_SHIFT, |
| 5815 | workspace_move_surface_up_binding, |
| 5816 | shell); |
| 5817 | weston_compositor_add_key_binding(ec, KEY_DOWN, mod | MODIFIER_SHIFT, |
| 5818 | workspace_move_surface_down_binding, |
| 5819 | shell); |
Jonas Ådahl | e3cddce | 2012-06-13 00:01:22 +0200 | [diff] [blame] | 5820 | |
Kristian Høgsberg | d56ab4e | 2014-01-16 16:51:52 -0800 | [diff] [blame] | 5821 | if (shell->exposay_modifier) |
| 5822 | weston_compositor_add_modifier_binding(ec, shell->exposay_modifier, |
| 5823 | exposay_binding, shell); |
Daniel Stone | df8133b | 2013-11-19 11:37:14 +0100 | [diff] [blame] | 5824 | |
Jonas Ådahl | e3cddce | 2012-06-13 00:01:22 +0200 | [diff] [blame] | 5825 | /* Add bindings for mod+F[1-6] for workspace 1 to 6. */ |
| 5826 | if (shell->workspaces.num > 1) { |
| 5827 | num_workspace_bindings = shell->workspaces.num; |
| 5828 | if (num_workspace_bindings > 6) |
| 5829 | num_workspace_bindings = 6; |
| 5830 | for (i = 0; i < num_workspace_bindings; i++) |
| 5831 | weston_compositor_add_key_binding(ec, KEY_F1 + i, mod, |
| 5832 | workspace_f_binding, |
| 5833 | shell); |
| 5834 | } |
Ander Conselvan de Oliveira | c509d2b | 2012-11-08 17:20:45 +0200 | [diff] [blame] | 5835 | |
| 5836 | /* Debug bindings */ |
| 5837 | weston_compositor_add_key_binding(ec, KEY_SPACE, mod | MODIFIER_SHIFT, |
| 5838 | debug_binding, shell); |
Tiago Vignatti | 0b52d48 | 2012-04-20 18:54:25 +0300 | [diff] [blame] | 5839 | } |
| 5840 | |
Kristian Høgsberg | 1c56218 | 2011-05-02 22:09:20 -0400 | [diff] [blame] | 5841 | WL_EXPORT int |
Kristian Høgsberg | cb4685b | 2013-02-20 15:37:49 -0500 | [diff] [blame] | 5842 | module_init(struct weston_compositor *ec, |
Ossama Othman | a50e6e4 | 2013-05-14 09:48:26 -0700 | [diff] [blame] | 5843 | int *argc, char *argv[]) |
Kristian Høgsberg | 4cca349 | 2011-01-18 07:53:49 -0500 | [diff] [blame] | 5844 | { |
Kristian Høgsberg | f4d2f23 | 2012-08-10 10:05:39 -0400 | [diff] [blame] | 5845 | struct weston_seat *seat; |
Tiago Vignatti | be14326 | 2012-04-16 17:31:41 +0300 | [diff] [blame] | 5846 | struct desktop_shell *shell; |
Jonas Ådahl | e3cddce | 2012-06-13 00:01:22 +0200 | [diff] [blame] | 5847 | struct workspace **pws; |
| 5848 | unsigned int i; |
Tiago Vignatti | b7dbbd6 | 2012-09-25 17:57:01 +0300 | [diff] [blame] | 5849 | struct wl_event_loop *loop; |
Kristian Høgsberg | 02ec0a5 | 2011-04-23 13:04:11 -0400 | [diff] [blame] | 5850 | |
Peter Hutterer | f3d6227 | 2013-08-08 11:57:05 +1000 | [diff] [blame] | 5851 | shell = zalloc(sizeof *shell); |
Kristian Høgsberg | 02ec0a5 | 2011-04-23 13:04:11 -0400 | [diff] [blame] | 5852 | if (shell == NULL) |
| 5853 | return -1; |
| 5854 | |
Kristian Høgsberg | 7584062 | 2011-09-06 13:48:16 -0400 | [diff] [blame] | 5855 | shell->compositor = ec; |
Kristian Høgsberg | 02e79dc | 2012-04-12 09:55:26 -0400 | [diff] [blame] | 5856 | |
| 5857 | shell->destroy_listener.notify = shell_destroy; |
| 5858 | wl_signal_add(&ec->destroy_signal, &shell->destroy_listener); |
Ander Conselvan de Oliveira | a457563 | 2013-02-21 18:35:23 +0200 | [diff] [blame] | 5859 | shell->idle_listener.notify = idle_handler; |
| 5860 | wl_signal_add(&ec->idle_signal, &shell->idle_listener); |
| 5861 | shell->wake_listener.notify = wake_handler; |
| 5862 | wl_signal_add(&ec->wake_signal, &shell->wake_listener); |
Kristian Høgsberg | 677a5f5 | 2013-12-04 11:00:19 -0800 | [diff] [blame] | 5863 | |
Kristian Høgsberg | 82a1d11 | 2012-07-19 14:02:00 -0400 | [diff] [blame] | 5864 | ec->shell_interface.shell = shell; |
Tiago Vignatti | bc052c9 | 2012-04-19 16:18:18 +0300 | [diff] [blame] | 5865 | ec->shell_interface.create_shell_surface = create_shell_surface; |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 5866 | ec->shell_interface.get_primary_view = get_primary_view; |
Tiago Vignatti | bc052c9 | 2012-04-19 16:18:18 +0300 | [diff] [blame] | 5867 | ec->shell_interface.set_toplevel = set_toplevel; |
Tiago Vignatti | 491bac1 | 2012-05-18 16:37:43 -0400 | [diff] [blame] | 5868 | ec->shell_interface.set_transient = set_transient; |
Kristian Høgsberg | b810eb5 | 2013-02-12 20:07:05 -0500 | [diff] [blame] | 5869 | ec->shell_interface.set_fullscreen = set_fullscreen; |
Tiago Vignatti | fb2adba | 2013-06-12 15:43:21 -0300 | [diff] [blame] | 5870 | ec->shell_interface.set_xwayland = set_xwayland; |
Kristian Høgsberg | 938b8fa | 2012-05-18 13:46:27 -0400 | [diff] [blame] | 5871 | ec->shell_interface.move = surface_move; |
Kristian Høgsberg | c1693f2 | 2012-05-22 16:56:23 -0400 | [diff] [blame] | 5872 | ec->shell_interface.resize = surface_resize; |
Giulio Camuffo | 62942ad | 2013-09-11 18:20:47 +0200 | [diff] [blame] | 5873 | ec->shell_interface.set_title = set_title; |
Kristian Høgsberg | 4cca349 | 2011-01-18 07:53:49 -0500 | [diff] [blame] | 5874 | |
Kristian Høgsberg | 3be2ce9 | 2012-02-29 12:42:35 -0500 | [diff] [blame] | 5875 | weston_layer_init(&shell->fullscreen_layer, &ec->cursor_layer.link); |
| 5876 | weston_layer_init(&shell->panel_layer, &shell->fullscreen_layer.link); |
Jonas Ådahl | e3cddce | 2012-06-13 00:01:22 +0200 | [diff] [blame] | 5877 | weston_layer_init(&shell->background_layer, &shell->panel_layer.link); |
| 5878 | weston_layer_init(&shell->lock_layer, NULL); |
Philipp Brüschweiler | 711fda8 | 2012-08-09 18:50:43 +0200 | [diff] [blame] | 5879 | weston_layer_init(&shell->input_panel_layer, NULL); |
Jonas Ådahl | e3cddce | 2012-06-13 00:01:22 +0200 | [diff] [blame] | 5880 | |
| 5881 | wl_array_init(&shell->workspaces.array); |
Jonas Ådahl | e9d2250 | 2012-08-29 22:13:01 +0200 | [diff] [blame] | 5882 | wl_list_init(&shell->workspaces.client_list); |
Kristian Høgsberg | 3be2ce9 | 2012-02-29 12:42:35 -0500 | [diff] [blame] | 5883 | |
Kristian Høgsberg | 677a5f5 | 2013-12-04 11:00:19 -0800 | [diff] [blame] | 5884 | if (input_panel_setup(shell) < 0) |
| 5885 | return -1; |
| 5886 | |
Kristian Høgsberg | 14e438c | 2013-05-26 21:48:14 -0400 | [diff] [blame] | 5887 | shell_configuration(shell); |
Pekka Paalanen | e955f1e | 2011-12-07 11:49:52 +0200 | [diff] [blame] | 5888 | |
Daniel Stone | df8133b | 2013-11-19 11:37:14 +0100 | [diff] [blame] | 5889 | shell->exposay.state_cur = EXPOSAY_LAYOUT_INACTIVE; |
| 5890 | shell->exposay.state_target = EXPOSAY_TARGET_CANCEL; |
| 5891 | |
Jonas Ådahl | e3cddce | 2012-06-13 00:01:22 +0200 | [diff] [blame] | 5892 | for (i = 0; i < shell->workspaces.num; i++) { |
| 5893 | pws = wl_array_add(&shell->workspaces.array, sizeof *pws); |
| 5894 | if (pws == NULL) |
| 5895 | return -1; |
| 5896 | |
| 5897 | *pws = workspace_create(); |
| 5898 | if (*pws == NULL) |
| 5899 | return -1; |
| 5900 | } |
| 5901 | activate_workspace(shell, 0); |
| 5902 | |
Jonas Ådahl | 8de6a1d | 2012-08-29 22:13:00 +0200 | [diff] [blame] | 5903 | wl_list_init(&shell->workspaces.anim_sticky_list); |
Jonas Ådahl | 62fcd04 | 2012-06-13 00:01:23 +0200 | [diff] [blame] | 5904 | wl_list_init(&shell->workspaces.animation.link); |
| 5905 | shell->workspaces.animation.frame = animate_workspace_change_frame; |
| 5906 | |
Kristian Høgsberg | 919cddb | 2013-07-08 19:03:57 -0400 | [diff] [blame] | 5907 | if (wl_global_create(ec->wl_display, &wl_shell_interface, 1, |
Kristian Høgsberg | 97d44aa | 2011-08-26 17:21:20 -0400 | [diff] [blame] | 5908 | shell, bind_shell) == NULL) |
Kristian Høgsberg | 4cca349 | 2011-01-18 07:53:49 -0500 | [diff] [blame] | 5909 | return -1; |
| 5910 | |
Rafael Antognolli | e2a3455 | 2013-12-03 15:35:45 -0200 | [diff] [blame] | 5911 | if (wl_global_create(ec->wl_display, &xdg_shell_interface, 1, |
| 5912 | shell, bind_xdg_shell) == NULL) |
| 5913 | return -1; |
| 5914 | |
Kristian Høgsberg | 919cddb | 2013-07-08 19:03:57 -0400 | [diff] [blame] | 5915 | if (wl_global_create(ec->wl_display, |
| 5916 | &desktop_shell_interface, 2, |
| 5917 | shell, bind_desktop_shell) == NULL) |
Kristian Høgsberg | 7584062 | 2011-09-06 13:48:16 -0400 | [diff] [blame] | 5918 | return -1; |
| 5919 | |
Kristian Høgsberg | 919cddb | 2013-07-08 19:03:57 -0400 | [diff] [blame] | 5920 | if (wl_global_create(ec->wl_display, &screensaver_interface, 1, |
| 5921 | shell, bind_screensaver) == NULL) |
Pekka Paalanen | 6e16811 | 2011-11-24 11:34:05 +0200 | [diff] [blame] | 5922 | return -1; |
| 5923 | |
Kristian Høgsberg | 919cddb | 2013-07-08 19:03:57 -0400 | [diff] [blame] | 5924 | if (wl_global_create(ec->wl_display, &workspace_manager_interface, 1, |
| 5925 | shell, bind_workspace_manager) == NULL) |
Jonas Ådahl | e9d2250 | 2012-08-29 22:13:01 +0200 | [diff] [blame] | 5926 | return -1; |
| 5927 | |
Kristian Høgsberg | f03a616 | 2012-01-17 11:07:42 -0500 | [diff] [blame] | 5928 | shell->child.deathstamp = weston_compositor_get_time(); |
Tiago Vignatti | b7dbbd6 | 2012-09-25 17:57:01 +0300 | [diff] [blame] | 5929 | |
Xiong Zhang | 6b48142 | 2013-10-23 13:58:32 +0800 | [diff] [blame] | 5930 | setup_output_destroy_handler(ec, shell); |
| 5931 | |
Tiago Vignatti | b7dbbd6 | 2012-09-25 17:57:01 +0300 | [diff] [blame] | 5932 | loop = wl_display_get_event_loop(ec->wl_display); |
| 5933 | wl_event_loop_add_idle(loop, launch_desktop_shell_process, shell); |
Pekka Paalanen | 6cd281a | 2011-11-03 14:11:32 +0200 | [diff] [blame] | 5934 | |
Ander Conselvan de Oliveira | 859e885 | 2013-02-21 18:35:21 +0200 | [diff] [blame] | 5935 | shell->screensaver.timer = |
| 5936 | wl_event_loop_add_timer(loop, screensaver_timeout, shell); |
| 5937 | |
Jasper St. Pierre | faf27a9 | 2013-12-09 17:36:28 -0500 | [diff] [blame] | 5938 | wl_list_for_each(seat, &ec->seat_list, link) { |
Kristian Høgsberg | f4d2f23 | 2012-08-10 10:05:39 -0400 | [diff] [blame] | 5939 | create_pointer_focus_listener(seat); |
Jasper St. Pierre | faf27a9 | 2013-12-09 17:36:28 -0500 | [diff] [blame] | 5940 | create_keyboard_focus_listener(seat); |
| 5941 | } |
Kristian Høgsberg | d56bd90 | 2012-06-05 09:58:51 -0400 | [diff] [blame] | 5942 | |
Tiago Vignatti | 0b52d48 | 2012-04-20 18:54:25 +0300 | [diff] [blame] | 5943 | shell_add_bindings(ec, shell); |
Kristian Høgsberg | 0793756 | 2011-04-12 17:25:42 -0400 | [diff] [blame] | 5944 | |
Pekka Paalanen | 79346ab | 2013-05-22 18:03:09 +0300 | [diff] [blame] | 5945 | shell_fade_init(shell); |
Ander Conselvan de Oliveira | 19d10ef | 2013-02-21 18:35:20 +0200 | [diff] [blame] | 5946 | |
Kristian Høgsberg | 4cca349 | 2011-01-18 07:53:49 -0500 | [diff] [blame] | 5947 | return 0; |
| 5948 | } |