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 | |
Xiong Zhang | 6b48142 | 2013-10-23 13:58:32 +0800 | [diff] [blame] | 59 | struct shell_output { |
| 60 | struct desktop_shell *shell; |
| 61 | struct weston_output *output; |
| 62 | struct wl_listener destroy_listener; |
| 63 | struct wl_list link; |
| 64 | }; |
| 65 | |
Kristian Høgsberg | d2abb83 | 2011-11-23 10:52:40 -0500 | [diff] [blame] | 66 | enum shell_surface_type { |
Pekka Paalanen | 9826223 | 2011-12-01 10:42:22 +0200 | [diff] [blame] | 67 | SHELL_SURFACE_NONE, |
Kristian Høgsberg | d2abb83 | 2011-11-23 10:52:40 -0500 | [diff] [blame] | 68 | SHELL_SURFACE_TOPLEVEL, |
Tiago Vignatti | fb2adba | 2013-06-12 15:43:21 -0300 | [diff] [blame] | 69 | SHELL_SURFACE_POPUP, |
| 70 | SHELL_SURFACE_XWAYLAND |
Pekka Paalanen | 57da4a8 | 2011-11-23 16:42:16 +0200 | [diff] [blame] | 71 | }; |
| 72 | |
Scott Moreau | ff1db4a | 2012-04-17 19:06:18 -0600 | [diff] [blame] | 73 | struct ping_timer { |
| 74 | struct wl_event_source *source; |
Scott Moreau | ff1db4a | 2012-04-17 19:06:18 -0600 | [diff] [blame] | 75 | uint32_t serial; |
| 76 | }; |
| 77 | |
Philip Withnall | 648a4dd | 2013-11-25 18:01:44 +0000 | [diff] [blame] | 78 | /* |
| 79 | * Surface stacking and ordering. |
| 80 | * |
| 81 | * This is handled using several linked lists of surfaces, organised into |
| 82 | * ‘layers’. The layers are ordered, and each of the surfaces in one layer are |
| 83 | * above all of the surfaces in the layer below. The set of layers is static and |
| 84 | * in the following order (top-most first): |
| 85 | * • Lock layer (only ever displayed on its own) |
| 86 | * • Cursor layer |
| 87 | * • Fullscreen layer |
| 88 | * • Panel layer |
| 89 | * • Input panel layer |
| 90 | * • Workspace layers |
| 91 | * • Background layer |
| 92 | * |
| 93 | * The list of layers may be manipulated to remove whole layers of surfaces from |
| 94 | * display. For example, when locking the screen, all layers except the lock |
| 95 | * layer are removed. |
| 96 | * |
| 97 | * A surface’s layer is modified on configuring the surface, in |
| 98 | * set_surface_type() (which is only called when the surface’s type change is |
| 99 | * _committed_). If a surface’s type changes (e.g. when making a window |
| 100 | * fullscreen) its layer changes too. |
| 101 | * |
| 102 | * In order to allow popup and transient surfaces to be correctly stacked above |
| 103 | * their parent surfaces, each surface tracks both its parent surface, and a |
| 104 | * linked list of its children. When a surface’s layer is updated, so are the |
| 105 | * layers of its children. Note that child surfaces are *not* the same as |
| 106 | * subsurfaces — child/parent surfaces are purely for maintaining stacking |
| 107 | * order. |
| 108 | * |
| 109 | * The children_link list of siblings of a surface (i.e. those surfaces which |
| 110 | * have the same parent) only contains weston_surfaces which have a |
| 111 | * shell_surface. Stacking is not implemented for non-shell_surface |
| 112 | * weston_surfaces. This means that the following implication does *not* hold: |
| 113 | * (shsurf->parent != NULL) ⇒ !wl_list_is_empty(shsurf->children_link) |
| 114 | */ |
| 115 | |
Pekka Paalanen | 56cdea9 | 2011-11-23 16:14:12 +0200 | [diff] [blame] | 116 | struct shell_surface { |
Jason Ekstrand | 651f00e | 2013-06-14 10:07:54 -0500 | [diff] [blame] | 117 | struct wl_resource *resource; |
| 118 | struct wl_signal destroy_signal; |
Pekka Paalanen | 9d1613e | 2011-11-25 12:09:16 +0200 | [diff] [blame] | 119 | |
Kristian Høgsberg | 8334bc1 | 2012-01-03 10:29:47 -0500 | [diff] [blame] | 120 | struct weston_surface *surface; |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 121 | struct weston_view *view; |
Jason Ekstrand | 918f2dd | 2013-12-02 21:01:53 -0600 | [diff] [blame] | 122 | int32_t last_width, last_height; |
Pekka Paalanen | 9d1613e | 2011-11-25 12:09:16 +0200 | [diff] [blame] | 123 | struct wl_listener surface_destroy_listener; |
Kristian Høgsberg | 8150b19 | 2012-06-27 10:22:58 -0400 | [diff] [blame] | 124 | struct weston_surface *parent; |
Philip Withnall | 648a4dd | 2013-11-25 18:01:44 +0000 | [diff] [blame] | 125 | struct wl_list children_list; /* child surfaces of this one */ |
| 126 | struct wl_list children_link; /* sibling surfaces of this one */ |
Tiago Vignatti | be14326 | 2012-04-16 17:31:41 +0300 | [diff] [blame] | 127 | struct desktop_shell *shell; |
Pekka Paalanen | 57da4a8 | 2011-11-23 16:42:16 +0200 | [diff] [blame] | 128 | |
Kristian Høgsberg | c8f8dd8 | 2013-12-05 23:20:33 -0800 | [diff] [blame] | 129 | enum shell_surface_type type; |
Kristian Høgsberg | e7afd91 | 2012-05-02 09:47:44 -0400 | [diff] [blame] | 130 | char *title, *class; |
Kristian Høgsberg | d2abb83 | 2011-11-23 10:52:40 -0500 | [diff] [blame] | 131 | int32_t saved_x, saved_y; |
Rafael Antognolli | 3c4e3f7 | 2013-12-03 15:35:46 -0200 | [diff] [blame] | 132 | int32_t saved_width, saved_height; |
Alex Wu | 4539b08 | 2012-03-01 12:57:46 +0800 | [diff] [blame] | 133 | bool saved_position_valid; |
Rafael Antognolli | 3c4e3f7 | 2013-12-03 15:35:46 -0200 | [diff] [blame] | 134 | bool saved_size_valid; |
Alex Wu | 7bcb8bd | 2012-04-27 09:07:24 +0800 | [diff] [blame] | 135 | bool saved_rotation_valid; |
Kristian Høgsberg | c85f1d4 | 2013-10-24 16:52:00 -0700 | [diff] [blame] | 136 | int unresponsive, grabbed; |
Benjamin Franzke | d0f79ab | 2011-11-22 12:43:52 +0100 | [diff] [blame] | 137 | |
Kristian Høgsberg | b3cca0a | 2012-01-04 22:19:14 -0500 | [diff] [blame] | 138 | struct { |
Pekka Paalanen | 460099f | 2012-01-20 16:48:25 +0200 | [diff] [blame] | 139 | struct weston_transform transform; |
Kristian Høgsberg | 765e27b | 2012-01-27 13:36:13 -0500 | [diff] [blame] | 140 | struct weston_matrix rotation; |
Pekka Paalanen | 460099f | 2012-01-20 16:48:25 +0200 | [diff] [blame] | 141 | } rotation; |
| 142 | |
| 143 | struct { |
Giulio Camuffo | 5085a75 | 2013-03-25 21:42:45 +0100 | [diff] [blame] | 144 | struct wl_list grab_link; |
Kristian Høgsberg | b3cca0a | 2012-01-04 22:19:14 -0500 | [diff] [blame] | 145 | int32_t x, y; |
Giulio Camuffo | 5085a75 | 2013-03-25 21:42:45 +0100 | [diff] [blame] | 146 | struct shell_seat *shseat; |
Kristian Høgsberg | 3730f36 | 2012-04-13 12:40:07 -0400 | [diff] [blame] | 147 | uint32_t serial; |
Kristian Høgsberg | b3cca0a | 2012-01-04 22:19:14 -0500 | [diff] [blame] | 148 | } popup; |
| 149 | |
Alex Wu | 4539b08 | 2012-03-01 12:57:46 +0800 | [diff] [blame] | 150 | struct { |
Tiago Vignatti | 52e598c | 2012-05-07 15:23:08 +0300 | [diff] [blame] | 151 | int32_t x, y; |
Tiago Vignatti | 491bac1 | 2012-05-18 16:37:43 -0400 | [diff] [blame] | 152 | uint32_t flags; |
Tiago Vignatti | 52e598c | 2012-05-07 15:23:08 +0300 | [diff] [blame] | 153 | } transient; |
| 154 | |
| 155 | struct { |
Alex Wu | 4539b08 | 2012-03-01 12:57:46 +0800 | [diff] [blame] | 156 | enum wl_shell_surface_fullscreen_method type; |
| 157 | struct weston_transform transform; /* matrix from x, y */ |
| 158 | uint32_t framerate; |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 159 | struct weston_view *black_view; |
Alex Wu | 4539b08 | 2012-03-01 12:57:46 +0800 | [diff] [blame] | 160 | } fullscreen; |
| 161 | |
Scott Moreau | ff1db4a | 2012-04-17 19:06:18 -0600 | [diff] [blame] | 162 | struct ping_timer *ping_timer; |
| 163 | |
Jonas Ådahl | 62fcd04 | 2012-06-13 00:01:23 +0200 | [diff] [blame] | 164 | struct weston_transform workspace_transform; |
| 165 | |
Kristian Høgsberg | 1cbf326 | 2012-02-17 23:49:07 -0500 | [diff] [blame] | 166 | struct weston_output *fullscreen_output; |
Kristian Høgsberg | 8334bc1 | 2012-01-03 10:29:47 -0500 | [diff] [blame] | 167 | struct weston_output *output; |
Rafael Antognolli | 65f98d8 | 2013-12-03 15:35:47 -0200 | [diff] [blame] | 168 | struct weston_output *recommended_output; |
Benjamin Franzke | d0f79ab | 2011-11-22 12:43:52 +0100 | [diff] [blame] | 169 | struct wl_list link; |
Kristian Høgsberg | a61ca06 | 2012-05-22 16:05:52 -0400 | [diff] [blame] | 170 | |
| 171 | const struct weston_shell_client *client; |
Rafael Antognolli | 03b1659 | 2013-12-03 15:35:42 -0200 | [diff] [blame] | 172 | |
| 173 | struct { |
| 174 | bool maximized; |
| 175 | bool fullscreen; |
Rafael Antognolli | ed207b4 | 2013-12-03 15:35:43 -0200 | [diff] [blame] | 176 | bool relative; |
Rafael Antognolli | 03b1659 | 2013-12-03 15:35:42 -0200 | [diff] [blame] | 177 | } state, next_state; /* surface states */ |
| 178 | bool state_changed; |
Pekka Paalanen | 56cdea9 | 2011-11-23 16:14:12 +0200 | [diff] [blame] | 179 | }; |
| 180 | |
Ander Conselvan de Oliveira | fe0444a | 2012-04-04 17:48:05 +0300 | [diff] [blame] | 181 | struct shell_grab { |
Kristian Høgsberg | 02bbabb | 2013-05-06 22:15:05 -0400 | [diff] [blame] | 182 | struct weston_pointer_grab grab; |
Ander Conselvan de Oliveira | fe0444a | 2012-04-04 17:48:05 +0300 | [diff] [blame] | 183 | struct shell_surface *shsurf; |
| 184 | struct wl_listener shsurf_destroy_listener; |
| 185 | }; |
| 186 | |
Rusty Lynch | 1084da5 | 2013-08-15 09:10:08 -0700 | [diff] [blame] | 187 | struct shell_touch_grab { |
| 188 | struct weston_touch_grab grab; |
| 189 | struct shell_surface *shsurf; |
| 190 | struct wl_listener shsurf_destroy_listener; |
| 191 | struct weston_touch *touch; |
| 192 | }; |
| 193 | |
Ander Conselvan de Oliveira | fe0444a | 2012-04-04 17:48:05 +0300 | [diff] [blame] | 194 | struct weston_move_grab { |
| 195 | struct shell_grab base; |
Daniel Stone | 103db7f | 2012-05-08 17:17:55 +0100 | [diff] [blame] | 196 | wl_fixed_t dx, dy; |
Kristian Høgsberg | 4cca349 | 2011-01-18 07:53:49 -0500 | [diff] [blame] | 197 | }; |
| 198 | |
Rusty Lynch | 1084da5 | 2013-08-15 09:10:08 -0700 | [diff] [blame] | 199 | struct weston_touch_move_grab { |
| 200 | struct shell_touch_grab base; |
Kristian Høgsberg | 8e80a31 | 2014-01-17 15:18:10 -0800 | [diff] [blame] | 201 | int active; |
Rusty Lynch | 1084da5 | 2013-08-15 09:10:08 -0700 | [diff] [blame] | 202 | wl_fixed_t dx, dy; |
| 203 | }; |
| 204 | |
Pekka Paalanen | 460099f | 2012-01-20 16:48:25 +0200 | [diff] [blame] | 205 | struct rotate_grab { |
Ander Conselvan de Oliveira | fe0444a | 2012-04-04 17:48:05 +0300 | [diff] [blame] | 206 | struct shell_grab base; |
Kristian Høgsberg | 765e27b | 2012-01-27 13:36:13 -0500 | [diff] [blame] | 207 | struct weston_matrix rotation; |
Pekka Paalanen | 460099f | 2012-01-20 16:48:25 +0200 | [diff] [blame] | 208 | struct { |
John Kåre Alsaker | 490d02a | 2012-09-30 02:57:21 +0200 | [diff] [blame] | 209 | float x; |
| 210 | float y; |
Pekka Paalanen | 460099f | 2012-01-20 16:48:25 +0200 | [diff] [blame] | 211 | } center; |
| 212 | }; |
| 213 | |
Giulio Camuffo | 5085a75 | 2013-03-25 21:42:45 +0100 | [diff] [blame] | 214 | struct shell_seat { |
| 215 | struct weston_seat *seat; |
| 216 | struct wl_listener seat_destroy_listener; |
| 217 | |
| 218 | struct { |
Kristian Høgsberg | 02bbabb | 2013-05-06 22:15:05 -0400 | [diff] [blame] | 219 | struct weston_pointer_grab grab; |
Giulio Camuffo | 5085a75 | 2013-03-25 21:42:45 +0100 | [diff] [blame] | 220 | struct wl_list surfaces_list; |
| 221 | struct wl_client *client; |
| 222 | int32_t initial_up; |
| 223 | } popup_grab; |
| 224 | }; |
| 225 | |
Emilio Pozuelo Monfort | 1a26f1b | 2014-01-07 16:41:40 +0100 | [diff] [blame] | 226 | void |
| 227 | set_alpha_if_fullscreen(struct shell_surface *shsurf) |
| 228 | { |
| 229 | if (shsurf && shsurf->state.fullscreen) |
| 230 | shsurf->fullscreen.black_view->alpha = 0.25; |
| 231 | } |
| 232 | |
Alex Wu | bd3354b | 2012-04-17 17:20:49 +0800 | [diff] [blame] | 233 | static struct desktop_shell * |
| 234 | shell_surface_get_shell(struct shell_surface *shsurf); |
| 235 | |
Kristian Høgsberg | 0c36903 | 2013-02-14 21:31:44 -0500 | [diff] [blame] | 236 | static void |
Kristian Høgsberg | e314875 | 2013-05-06 23:19:49 -0400 | [diff] [blame] | 237 | surface_rotate(struct shell_surface *surface, struct weston_seat *seat); |
Kristian Høgsberg | 0c36903 | 2013-02-14 21:31:44 -0500 | [diff] [blame] | 238 | |
Pekka Paalanen | 79346ab | 2013-05-22 18:03:09 +0300 | [diff] [blame] | 239 | static void |
| 240 | shell_fade_startup(struct desktop_shell *shell); |
| 241 | |
Philip Withnall | becb77e | 2013-11-25 18:01:30 +0000 | [diff] [blame] | 242 | static struct shell_seat * |
| 243 | get_shell_seat(struct weston_seat *seat); |
| 244 | |
Philip Withnall | 648a4dd | 2013-11-25 18:01:44 +0000 | [diff] [blame] | 245 | static void |
| 246 | shell_surface_update_child_surface_layers(struct shell_surface *shsurf); |
| 247 | |
Alex Wu | bd3354b | 2012-04-17 17:20:49 +0800 | [diff] [blame] | 248 | static bool |
Rafael Antognolli | e2a3455 | 2013-12-03 15:35:45 -0200 | [diff] [blame] | 249 | shell_surface_is_wl_shell_surface(struct shell_surface *shsurf); |
| 250 | |
| 251 | static bool |
| 252 | shell_surface_is_xdg_surface(struct shell_surface *shsurf); |
| 253 | |
| 254 | static bool |
| 255 | shell_surface_is_xdg_popup(struct shell_surface *shsurf); |
| 256 | |
| 257 | static void |
| 258 | shell_surface_set_parent(struct shell_surface *shsurf, |
| 259 | struct weston_surface *parent); |
| 260 | |
| 261 | static bool |
Alex Wu | bd3354b | 2012-04-17 17:20:49 +0800 | [diff] [blame] | 262 | shell_surface_is_top_fullscreen(struct shell_surface *shsurf) |
| 263 | { |
| 264 | struct desktop_shell *shell; |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 265 | struct weston_view *top_fs_ev; |
Alex Wu | bd3354b | 2012-04-17 17:20:49 +0800 | [diff] [blame] | 266 | |
| 267 | shell = shell_surface_get_shell(shsurf); |
Quentin Glidic | c0d79ce | 2013-01-29 14:16:13 +0100 | [diff] [blame] | 268 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 269 | if (wl_list_empty(&shell->fullscreen_layer.view_list)) |
Alex Wu | bd3354b | 2012-04-17 17:20:49 +0800 | [diff] [blame] | 270 | return false; |
| 271 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 272 | top_fs_ev = container_of(shell->fullscreen_layer.view_list.next, |
| 273 | struct weston_view, |
Alex Wu | bd3354b | 2012-04-17 17:20:49 +0800 | [diff] [blame] | 274 | layer_link); |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 275 | return (shsurf == get_shell_surface(top_fs_ev->surface)); |
Alex Wu | bd3354b | 2012-04-17 17:20:49 +0800 | [diff] [blame] | 276 | } |
| 277 | |
Kristian Høgsberg | 6af8eb9 | 2012-01-25 16:57:11 -0500 | [diff] [blame] | 278 | static void |
Kristian Høgsberg | 27e3052 | 2012-04-11 23:18:23 -0400 | [diff] [blame] | 279 | destroy_shell_grab_shsurf(struct wl_listener *listener, void *data) |
Ander Conselvan de Oliveira | fe0444a | 2012-04-04 17:48:05 +0300 | [diff] [blame] | 280 | { |
| 281 | struct shell_grab *grab; |
| 282 | |
| 283 | grab = container_of(listener, struct shell_grab, |
| 284 | shsurf_destroy_listener); |
| 285 | |
| 286 | grab->shsurf = NULL; |
| 287 | } |
| 288 | |
Kristian Høgsberg | 1ef2313 | 2013-12-04 00:20:01 -0800 | [diff] [blame] | 289 | struct weston_view * |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 290 | get_default_view(struct weston_surface *surface) |
| 291 | { |
| 292 | struct shell_surface *shsurf; |
| 293 | struct weston_view *view; |
| 294 | |
| 295 | if (!surface || wl_list_empty(&surface->views)) |
| 296 | return NULL; |
| 297 | |
| 298 | shsurf = get_shell_surface(surface); |
| 299 | if (shsurf) |
| 300 | return shsurf->view; |
| 301 | |
| 302 | wl_list_for_each(view, &surface->views, surface_link) |
| 303 | if (weston_view_is_mapped(view)) |
| 304 | return view; |
| 305 | |
| 306 | return container_of(surface->views.next, struct weston_view, surface_link); |
| 307 | } |
| 308 | |
Ander Conselvan de Oliveira | fe0444a | 2012-04-04 17:48:05 +0300 | [diff] [blame] | 309 | static void |
Kristian Høgsberg | 02bbabb | 2013-05-06 22:15:05 -0400 | [diff] [blame] | 310 | popup_grab_end(struct weston_pointer *pointer); |
Kristian Høgsberg | 57e0907 | 2012-10-30 14:07:27 -0400 | [diff] [blame] | 311 | |
| 312 | static void |
Ander Conselvan de Oliveira | b9d2a0f | 2012-06-28 18:08:05 +0300 | [diff] [blame] | 313 | shell_grab_start(struct shell_grab *grab, |
Kristian Høgsberg | 02bbabb | 2013-05-06 22:15:05 -0400 | [diff] [blame] | 314 | const struct weston_pointer_grab_interface *interface, |
Ander Conselvan de Oliveira | b9d2a0f | 2012-06-28 18:08:05 +0300 | [diff] [blame] | 315 | struct shell_surface *shsurf, |
Kristian Høgsberg | 02bbabb | 2013-05-06 22:15:05 -0400 | [diff] [blame] | 316 | struct weston_pointer *pointer, |
Ander Conselvan de Oliveira | b9d2a0f | 2012-06-28 18:08:05 +0300 | [diff] [blame] | 317 | enum desktop_shell_cursor cursor) |
Ander Conselvan de Oliveira | fe0444a | 2012-04-04 17:48:05 +0300 | [diff] [blame] | 318 | { |
Ander Conselvan de Oliveira | b9d2a0f | 2012-06-28 18:08:05 +0300 | [diff] [blame] | 319 | struct desktop_shell *shell = shsurf->shell; |
| 320 | |
Kristian Høgsberg | 57e0907 | 2012-10-30 14:07:27 -0400 | [diff] [blame] | 321 | popup_grab_end(pointer); |
| 322 | |
Ander Conselvan de Oliveira | fe0444a | 2012-04-04 17:48:05 +0300 | [diff] [blame] | 323 | grab->grab.interface = interface; |
| 324 | grab->shsurf = shsurf; |
Kristian Høgsberg | 27e3052 | 2012-04-11 23:18:23 -0400 | [diff] [blame] | 325 | grab->shsurf_destroy_listener.notify = destroy_shell_grab_shsurf; |
Jason Ekstrand | 651f00e | 2013-06-14 10:07:54 -0500 | [diff] [blame] | 326 | wl_signal_add(&shsurf->destroy_signal, |
Kristian Høgsberg | 27e3052 | 2012-04-11 23:18:23 -0400 | [diff] [blame] | 327 | &grab->shsurf_destroy_listener); |
Ander Conselvan de Oliveira | fe0444a | 2012-04-04 17:48:05 +0300 | [diff] [blame] | 328 | |
Kristian Høgsberg | c85f1d4 | 2013-10-24 16:52:00 -0700 | [diff] [blame] | 329 | shsurf->grabbed = 1; |
Kristian Høgsberg | 02bbabb | 2013-05-06 22:15:05 -0400 | [diff] [blame] | 330 | weston_pointer_start_grab(pointer, &grab->grab); |
Kristian Høgsberg | c9974a0 | 2013-07-03 19:24:57 -0400 | [diff] [blame] | 331 | if (shell->child.desktop_shell) { |
| 332 | desktop_shell_send_grab_cursor(shell->child.desktop_shell, |
| 333 | cursor); |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 334 | weston_pointer_set_focus(pointer, |
| 335 | get_default_view(shell->grab_surface), |
Kristian Høgsberg | c9974a0 | 2013-07-03 19:24:57 -0400 | [diff] [blame] | 336 | wl_fixed_from_int(0), |
| 337 | wl_fixed_from_int(0)); |
| 338 | } |
Ander Conselvan de Oliveira | fe0444a | 2012-04-04 17:48:05 +0300 | [diff] [blame] | 339 | } |
| 340 | |
| 341 | static void |
Ander Conselvan de Oliveira | b9d2a0f | 2012-06-28 18:08:05 +0300 | [diff] [blame] | 342 | shell_grab_end(struct shell_grab *grab) |
Ander Conselvan de Oliveira | fe0444a | 2012-04-04 17:48:05 +0300 | [diff] [blame] | 343 | { |
Kristian Høgsberg | c85f1d4 | 2013-10-24 16:52:00 -0700 | [diff] [blame] | 344 | if (grab->shsurf) { |
Kristian Høgsberg | 47b5dca | 2012-06-07 18:08:04 -0400 | [diff] [blame] | 345 | wl_list_remove(&grab->shsurf_destroy_listener.link); |
Kristian Høgsberg | c85f1d4 | 2013-10-24 16:52:00 -0700 | [diff] [blame] | 346 | grab->shsurf->grabbed = 0; |
| 347 | } |
Ander Conselvan de Oliveira | b9d2a0f | 2012-06-28 18:08:05 +0300 | [diff] [blame] | 348 | |
Kristian Høgsberg | 9e5d7d1 | 2013-07-22 16:31:53 -0700 | [diff] [blame] | 349 | weston_pointer_end_grab(grab->grab.pointer); |
Ander Conselvan de Oliveira | fe0444a | 2012-04-04 17:48:05 +0300 | [diff] [blame] | 350 | } |
| 351 | |
| 352 | static void |
Rusty Lynch | 1084da5 | 2013-08-15 09:10:08 -0700 | [diff] [blame] | 353 | shell_touch_grab_start(struct shell_touch_grab *grab, |
| 354 | const struct weston_touch_grab_interface *interface, |
| 355 | struct shell_surface *shsurf, |
| 356 | struct weston_touch *touch) |
| 357 | { |
| 358 | struct desktop_shell *shell = shsurf->shell; |
U. Artie Eoff | cf5737a | 2014-01-17 10:08:25 -0800 | [diff] [blame] | 359 | |
Rusty Lynch | 1084da5 | 2013-08-15 09:10:08 -0700 | [diff] [blame] | 360 | grab->grab.interface = interface; |
| 361 | grab->shsurf = shsurf; |
| 362 | grab->shsurf_destroy_listener.notify = destroy_shell_grab_shsurf; |
| 363 | wl_signal_add(&shsurf->destroy_signal, |
| 364 | &grab->shsurf_destroy_listener); |
| 365 | |
| 366 | grab->touch = touch; |
Kristian Høgsberg | c85f1d4 | 2013-10-24 16:52:00 -0700 | [diff] [blame] | 367 | shsurf->grabbed = 1; |
Rusty Lynch | 1084da5 | 2013-08-15 09:10:08 -0700 | [diff] [blame] | 368 | |
| 369 | weston_touch_start_grab(touch, &grab->grab); |
| 370 | if (shell->child.desktop_shell) |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 371 | weston_touch_set_focus(touch->seat, |
| 372 | get_default_view(shell->grab_surface)); |
Rusty Lynch | 1084da5 | 2013-08-15 09:10:08 -0700 | [diff] [blame] | 373 | } |
| 374 | |
| 375 | static void |
| 376 | shell_touch_grab_end(struct shell_touch_grab *grab) |
| 377 | { |
Kristian Høgsberg | c85f1d4 | 2013-10-24 16:52:00 -0700 | [diff] [blame] | 378 | if (grab->shsurf) { |
Rusty Lynch | 1084da5 | 2013-08-15 09:10:08 -0700 | [diff] [blame] | 379 | wl_list_remove(&grab->shsurf_destroy_listener.link); |
Kristian Høgsberg | c85f1d4 | 2013-10-24 16:52:00 -0700 | [diff] [blame] | 380 | grab->shsurf->grabbed = 0; |
| 381 | } |
Rusty Lynch | 1084da5 | 2013-08-15 09:10:08 -0700 | [diff] [blame] | 382 | |
| 383 | weston_touch_end_grab(grab->touch); |
| 384 | } |
| 385 | |
| 386 | static void |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 387 | center_on_output(struct weston_view *view, |
Alex Wu | 4539b08 | 2012-03-01 12:57:46 +0800 | [diff] [blame] | 388 | struct weston_output *output); |
| 389 | |
Daniel Stone | 496ca17 | 2012-05-30 16:31:42 +0100 | [diff] [blame] | 390 | static enum weston_keyboard_modifier |
Tiago Vignatti | 0b52d48 | 2012-04-20 18:54:25 +0300 | [diff] [blame] | 391 | get_modifier(char *modifier) |
| 392 | { |
| 393 | if (!modifier) |
| 394 | return MODIFIER_SUPER; |
| 395 | |
| 396 | if (!strcmp("ctrl", modifier)) |
| 397 | return MODIFIER_CTRL; |
| 398 | else if (!strcmp("alt", modifier)) |
| 399 | return MODIFIER_ALT; |
| 400 | else if (!strcmp("super", modifier)) |
| 401 | return MODIFIER_SUPER; |
| 402 | else |
| 403 | return MODIFIER_SUPER; |
| 404 | } |
| 405 | |
Juan Zhao | e10d279 | 2012-04-25 19:09:52 +0800 | [diff] [blame] | 406 | static enum animation_type |
| 407 | get_animation_type(char *animation) |
| 408 | { |
U. Artie Eoff | b571910 | 2014-01-15 14:26:31 -0800 | [diff] [blame] | 409 | if (!animation) |
| 410 | return ANIMATION_NONE; |
| 411 | |
Juan Zhao | e10d279 | 2012-04-25 19:09:52 +0800 | [diff] [blame] | 412 | if (!strcmp("zoom", animation)) |
| 413 | return ANIMATION_ZOOM; |
| 414 | else if (!strcmp("fade", animation)) |
| 415 | return ANIMATION_FADE; |
Louis-Francis Ratté-Boulianne | b482dbd | 2013-11-19 11:37:11 +0100 | [diff] [blame] | 416 | else if (!strcmp("dim-layer", animation)) |
| 417 | return ANIMATION_DIM_LAYER; |
Juan Zhao | e10d279 | 2012-04-25 19:09:52 +0800 | [diff] [blame] | 418 | else |
| 419 | return ANIMATION_NONE; |
| 420 | } |
| 421 | |
Alex Wu | 4539b08 | 2012-03-01 12:57:46 +0800 | [diff] [blame] | 422 | static void |
Kristian Høgsberg | 14e438c | 2013-05-26 21:48:14 -0400 | [diff] [blame] | 423 | shell_configuration(struct desktop_shell *shell) |
Pekka Paalanen | e955f1e | 2011-12-07 11:49:52 +0200 | [diff] [blame] | 424 | { |
Kristian Høgsberg | 673a889 | 2013-05-23 21:40:56 -0400 | [diff] [blame] | 425 | struct weston_config_section *section; |
| 426 | int duration; |
| 427 | char *s; |
Pekka Paalanen | e955f1e | 2011-12-07 11:49:52 +0200 | [diff] [blame] | 428 | |
Kristian Høgsberg | 673a889 | 2013-05-23 21:40:56 -0400 | [diff] [blame] | 429 | section = weston_config_get_section(shell->compositor->config, |
| 430 | "screensaver", NULL, NULL); |
| 431 | weston_config_section_get_string(section, |
| 432 | "path", &shell->screensaver.path, NULL); |
| 433 | weston_config_section_get_int(section, "duration", &duration, 60); |
Ander Conselvan de Oliveira | 859e885 | 2013-02-21 18:35:21 +0200 | [diff] [blame] | 434 | shell->screensaver.duration = duration * 1000; |
Kristian Høgsberg | 673a889 | 2013-05-23 21:40:56 -0400 | [diff] [blame] | 435 | |
| 436 | section = weston_config_get_section(shell->compositor->config, |
| 437 | "shell", NULL, NULL); |
| 438 | weston_config_section_get_string(section, |
Emilio Pozuelo Monfort | 8a81b83 | 2013-12-02 12:53:32 +0100 | [diff] [blame] | 439 | "client", &s, LIBEXECDIR "/" WESTON_SHELL_CLIENT); |
Emilio Pozuelo Monfort | 46ce798 | 2013-11-20 13:22:29 +0100 | [diff] [blame] | 440 | shell->client = s; |
| 441 | weston_config_section_get_string(section, |
Kristian Høgsberg | 673a889 | 2013-05-23 21:40:56 -0400 | [diff] [blame] | 442 | "binding-modifier", &s, "super"); |
| 443 | shell->binding_modifier = get_modifier(s); |
Quentin Glidic | 8418c29 | 2013-06-18 09:11:03 +0200 | [diff] [blame] | 444 | free(s); |
Kristian Høgsberg | d56ab4e | 2014-01-16 16:51:52 -0800 | [diff] [blame] | 445 | |
| 446 | weston_config_section_get_string(section, |
| 447 | "exposay-modifier", &s, "none"); |
| 448 | if (strcmp(s, "none") == 0) |
| 449 | shell->exposay_modifier = 0; |
| 450 | else |
| 451 | shell->exposay_modifier = get_modifier(s); |
| 452 | free(s); |
| 453 | |
Kristian Høgsberg | 673a889 | 2013-05-23 21:40:56 -0400 | [diff] [blame] | 454 | weston_config_section_get_string(section, "animation", &s, "none"); |
| 455 | shell->win_animation_type = get_animation_type(s); |
Quentin Glidic | 8418c29 | 2013-06-18 09:11:03 +0200 | [diff] [blame] | 456 | free(s); |
Kristian Høgsberg | 724c8d9 | 2013-10-16 11:38:24 -0700 | [diff] [blame] | 457 | weston_config_section_get_string(section, |
| 458 | "startup-animation", &s, "fade"); |
| 459 | shell->startup_animation_type = get_animation_type(s); |
| 460 | free(s); |
Kristian Høgsberg | 912e0a1 | 2013-10-30 08:59:55 -0700 | [diff] [blame] | 461 | if (shell->startup_animation_type == ANIMATION_ZOOM) |
| 462 | shell->startup_animation_type = ANIMATION_NONE; |
Louis-Francis Ratté-Boulianne | b482dbd | 2013-11-19 11:37:11 +0100 | [diff] [blame] | 463 | weston_config_section_get_string(section, "focus-animation", &s, "none"); |
| 464 | shell->focus_animation_type = get_animation_type(s); |
| 465 | free(s); |
Kristian Høgsberg | 673a889 | 2013-05-23 21:40:56 -0400 | [diff] [blame] | 466 | weston_config_section_get_uint(section, "num-workspaces", |
| 467 | &shell->workspaces.num, |
| 468 | DEFAULT_NUM_WORKSPACES); |
Jonas Ådahl | e3cddce | 2012-06-13 00:01:22 +0200 | [diff] [blame] | 469 | } |
| 470 | |
Kristian Høgsberg | 1ef2313 | 2013-12-04 00:20:01 -0800 | [diff] [blame] | 471 | struct weston_output * |
Louis-Francis Ratté-Boulianne | b482dbd | 2013-11-19 11:37:11 +0100 | [diff] [blame] | 472 | get_default_output(struct weston_compositor *compositor) |
| 473 | { |
| 474 | return container_of(compositor->output_list.next, |
| 475 | struct weston_output, link); |
| 476 | } |
| 477 | |
| 478 | |
| 479 | /* no-op func for checking focus surface */ |
| 480 | static void |
Jason Ekstrand | 918f2dd | 2013-12-02 21:01:53 -0600 | [diff] [blame] | 481 | 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] | 482 | { |
| 483 | } |
| 484 | |
| 485 | static struct focus_surface * |
| 486 | get_focus_surface(struct weston_surface *surface) |
| 487 | { |
| 488 | if (surface->configure == focus_surface_configure) |
| 489 | return surface->configure_private; |
| 490 | else |
| 491 | return NULL; |
| 492 | } |
| 493 | |
| 494 | static bool |
| 495 | is_focus_surface (struct weston_surface *es) |
| 496 | { |
| 497 | return (es->configure == focus_surface_configure); |
| 498 | } |
| 499 | |
| 500 | static bool |
| 501 | is_focus_view (struct weston_view *view) |
| 502 | { |
| 503 | return is_focus_surface (view->surface); |
| 504 | } |
| 505 | |
| 506 | static struct focus_surface * |
| 507 | create_focus_surface(struct weston_compositor *ec, |
| 508 | struct weston_output *output) |
| 509 | { |
| 510 | struct focus_surface *fsurf = NULL; |
| 511 | struct weston_surface *surface = NULL; |
| 512 | |
| 513 | fsurf = malloc(sizeof *fsurf); |
| 514 | if (!fsurf) |
| 515 | return NULL; |
| 516 | |
| 517 | fsurf->surface = weston_surface_create(ec); |
| 518 | surface = fsurf->surface; |
| 519 | if (surface == NULL) { |
| 520 | free(fsurf); |
| 521 | return NULL; |
| 522 | } |
| 523 | |
| 524 | surface->configure = focus_surface_configure; |
| 525 | surface->output = output; |
| 526 | surface->configure_private = fsurf; |
| 527 | |
U. Artie Eoff | 0b23b2b | 2014-01-15 14:45:59 -0800 | [diff] [blame] | 528 | fsurf->view = weston_view_create(surface); |
| 529 | if (fsurf->view == NULL) { |
| 530 | weston_surface_destroy(surface); |
| 531 | free(fsurf); |
| 532 | return NULL; |
| 533 | } |
Emilio Pozuelo Monfort | da64426 | 2013-11-19 11:37:19 +0100 | [diff] [blame] | 534 | fsurf->view->output = output; |
Louis-Francis Ratté-Boulianne | b482dbd | 2013-11-19 11:37:11 +0100 | [diff] [blame] | 535 | |
Jason Ekstrand | 5c11a33 | 2013-12-04 20:32:03 -0600 | [diff] [blame] | 536 | weston_surface_set_size(surface, output->width, output->height); |
Jason Ekstrand | 918f2dd | 2013-12-02 21:01:53 -0600 | [diff] [blame] | 537 | weston_view_set_position(fsurf->view, output->x, output->y); |
Louis-Francis Ratté-Boulianne | b482dbd | 2013-11-19 11:37:11 +0100 | [diff] [blame] | 538 | weston_surface_set_color(surface, 0.0, 0.0, 0.0, 1.0); |
| 539 | pixman_region32_fini(&surface->opaque); |
| 540 | pixman_region32_init_rect(&surface->opaque, output->x, output->y, |
| 541 | output->width, output->height); |
| 542 | pixman_region32_fini(&surface->input); |
| 543 | pixman_region32_init(&surface->input); |
| 544 | |
| 545 | wl_list_init(&fsurf->workspace_transform.link); |
| 546 | |
| 547 | return fsurf; |
| 548 | } |
| 549 | |
| 550 | static void |
| 551 | focus_surface_destroy(struct focus_surface *fsurf) |
| 552 | { |
| 553 | weston_surface_destroy(fsurf->surface); |
| 554 | free(fsurf); |
| 555 | } |
| 556 | |
| 557 | static void |
| 558 | focus_animation_done(struct weston_view_animation *animation, void *data) |
| 559 | { |
| 560 | struct workspace *ws = data; |
| 561 | |
| 562 | ws->focus_animation = NULL; |
| 563 | } |
| 564 | |
Jonas Ådahl | e3cddce | 2012-06-13 00:01:22 +0200 | [diff] [blame] | 565 | static void |
Jonas Ådahl | 0476974 | 2012-06-13 00:01:24 +0200 | [diff] [blame] | 566 | focus_state_destroy(struct focus_state *state) |
| 567 | { |
| 568 | wl_list_remove(&state->seat_destroy_listener.link); |
| 569 | wl_list_remove(&state->surface_destroy_listener.link); |
| 570 | free(state); |
| 571 | } |
| 572 | |
| 573 | static void |
| 574 | focus_state_seat_destroy(struct wl_listener *listener, void *data) |
| 575 | { |
| 576 | struct focus_state *state = container_of(listener, |
| 577 | struct focus_state, |
| 578 | seat_destroy_listener); |
| 579 | |
| 580 | wl_list_remove(&state->link); |
| 581 | focus_state_destroy(state); |
| 582 | } |
| 583 | |
| 584 | static void |
| 585 | focus_state_surface_destroy(struct wl_listener *listener, void *data) |
| 586 | { |
| 587 | struct focus_state *state = container_of(listener, |
| 588 | struct focus_state, |
Kristian Høgsberg | b8e0d0f | 2012-07-31 10:30:26 -0400 | [diff] [blame] | 589 | surface_destroy_listener); |
Kristian Høgsberg | e377822 | 2012-07-31 17:29:30 -0400 | [diff] [blame] | 590 | struct desktop_shell *shell; |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 591 | struct weston_surface *main_surface, *next; |
| 592 | struct weston_view *view; |
Jonas Ådahl | 0476974 | 2012-06-13 00:01:24 +0200 | [diff] [blame] | 593 | |
Pekka Paalanen | 01388e2 | 2013-04-25 13:57:44 +0300 | [diff] [blame] | 594 | main_surface = weston_surface_get_main_surface(state->keyboard_focus); |
| 595 | |
Kristian Høgsberg | e377822 | 2012-07-31 17:29:30 -0400 | [diff] [blame] | 596 | next = NULL; |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 597 | wl_list_for_each(view, &state->ws->layer.view_list, layer_link) { |
| 598 | if (view->surface == main_surface) |
Kristian Høgsberg | e377822 | 2012-07-31 17:29:30 -0400 | [diff] [blame] | 599 | continue; |
Louis-Francis Ratté-Boulianne | b482dbd | 2013-11-19 11:37:11 +0100 | [diff] [blame] | 600 | if (is_focus_view(view)) |
| 601 | continue; |
Kristian Høgsberg | e377822 | 2012-07-31 17:29:30 -0400 | [diff] [blame] | 602 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 603 | next = view->surface; |
Kristian Høgsberg | e377822 | 2012-07-31 17:29:30 -0400 | [diff] [blame] | 604 | break; |
| 605 | } |
| 606 | |
Pekka Paalanen | 01388e2 | 2013-04-25 13:57:44 +0300 | [diff] [blame] | 607 | /* if the focus was a sub-surface, activate its main surface */ |
| 608 | if (main_surface != state->keyboard_focus) |
| 609 | next = main_surface; |
| 610 | |
Louis-Francis Ratté-Boulianne | b482dbd | 2013-11-19 11:37:11 +0100 | [diff] [blame] | 611 | shell = state->seat->compositor->shell_interface.shell; |
Kristian Høgsberg | e377822 | 2012-07-31 17:29:30 -0400 | [diff] [blame] | 612 | if (next) { |
Louis-Francis Ratté-Boulianne | b482dbd | 2013-11-19 11:37:11 +0100 | [diff] [blame] | 613 | state->keyboard_focus = NULL; |
Kristian Høgsberg | e377822 | 2012-07-31 17:29:30 -0400 | [diff] [blame] | 614 | activate(shell, next, state->seat); |
| 615 | } else { |
Louis-Francis Ratté-Boulianne | b482dbd | 2013-11-19 11:37:11 +0100 | [diff] [blame] | 616 | if (shell->focus_animation_type == ANIMATION_DIM_LAYER) { |
| 617 | if (state->ws->focus_animation) |
| 618 | weston_view_animation_destroy(state->ws->focus_animation); |
| 619 | |
| 620 | state->ws->focus_animation = weston_fade_run( |
| 621 | state->ws->fsurf_front->view, |
| 622 | state->ws->fsurf_front->view->alpha, 0.0, 300, |
| 623 | focus_animation_done, state->ws); |
| 624 | } |
| 625 | |
Kristian Høgsberg | e377822 | 2012-07-31 17:29:30 -0400 | [diff] [blame] | 626 | wl_list_remove(&state->link); |
| 627 | focus_state_destroy(state); |
| 628 | } |
Jonas Ådahl | 0476974 | 2012-06-13 00:01:24 +0200 | [diff] [blame] | 629 | } |
| 630 | |
| 631 | static struct focus_state * |
Kristian Høgsberg | 2f5faff | 2012-07-31 16:36:34 -0400 | [diff] [blame] | 632 | focus_state_create(struct weston_seat *seat, struct workspace *ws) |
Jonas Ådahl | 0476974 | 2012-06-13 00:01:24 +0200 | [diff] [blame] | 633 | { |
Jonas Ådahl | 0476974 | 2012-06-13 00:01:24 +0200 | [diff] [blame] | 634 | struct focus_state *state; |
Jonas Ådahl | 0476974 | 2012-06-13 00:01:24 +0200 | [diff] [blame] | 635 | |
| 636 | state = malloc(sizeof *state); |
| 637 | if (state == NULL) |
| 638 | return NULL; |
| 639 | |
Louis-Francis Ratté-Boulianne | b482dbd | 2013-11-19 11:37:11 +0100 | [diff] [blame] | 640 | state->keyboard_focus = NULL; |
Kristian Høgsberg | 2f5faff | 2012-07-31 16:36:34 -0400 | [diff] [blame] | 641 | state->ws = ws; |
Jonas Ådahl | 0476974 | 2012-06-13 00:01:24 +0200 | [diff] [blame] | 642 | state->seat = seat; |
Kristian Høgsberg | 2f5faff | 2012-07-31 16:36:34 -0400 | [diff] [blame] | 643 | wl_list_insert(&ws->focus_list, &state->link); |
Jonas Ådahl | 0476974 | 2012-06-13 00:01:24 +0200 | [diff] [blame] | 644 | |
| 645 | state->seat_destroy_listener.notify = focus_state_seat_destroy; |
| 646 | state->surface_destroy_listener.notify = focus_state_surface_destroy; |
Kristian Høgsberg | 4912454 | 2013-05-06 22:27:40 -0400 | [diff] [blame] | 647 | wl_signal_add(&seat->destroy_signal, |
Jonas Ådahl | 0476974 | 2012-06-13 00:01:24 +0200 | [diff] [blame] | 648 | &state->seat_destroy_listener); |
Kristian Høgsberg | 2f5faff | 2012-07-31 16:36:34 -0400 | [diff] [blame] | 649 | wl_list_init(&state->surface_destroy_listener.link); |
Jonas Ådahl | 0476974 | 2012-06-13 00:01:24 +0200 | [diff] [blame] | 650 | |
| 651 | return state; |
| 652 | } |
| 653 | |
Jonas Ådahl | 8538b22 | 2012-08-29 22:13:03 +0200 | [diff] [blame] | 654 | static struct focus_state * |
| 655 | ensure_focus_state(struct desktop_shell *shell, struct weston_seat *seat) |
| 656 | { |
| 657 | struct workspace *ws = get_current_workspace(shell); |
| 658 | struct focus_state *state; |
| 659 | |
| 660 | wl_list_for_each(state, &ws->focus_list, link) |
| 661 | if (state->seat == seat) |
| 662 | break; |
| 663 | |
| 664 | if (&state->link == &ws->focus_list) |
| 665 | state = focus_state_create(seat, ws); |
| 666 | |
| 667 | return state; |
| 668 | } |
| 669 | |
Jonas Ådahl | 0476974 | 2012-06-13 00:01:24 +0200 | [diff] [blame] | 670 | static void |
Kristian Høgsberg | d500bf1 | 2014-01-22 12:25:20 -0800 | [diff] [blame^] | 671 | focus_state_set_focus(struct focus_state *state, |
| 672 | struct weston_surface *surface) |
| 673 | { |
| 674 | if (state->keyboard_focus) { |
| 675 | wl_list_remove(&state->surface_destroy_listener.link); |
| 676 | wl_list_init(&state->surface_destroy_listener.link); |
| 677 | } |
| 678 | |
| 679 | state->keyboard_focus = surface; |
| 680 | if (surface) |
| 681 | wl_signal_add(&surface->destroy_signal, |
| 682 | &state->surface_destroy_listener); |
| 683 | } |
| 684 | |
| 685 | static void |
Kristian Høgsberg | 2f5faff | 2012-07-31 16:36:34 -0400 | [diff] [blame] | 686 | restore_focus_state(struct desktop_shell *shell, struct workspace *ws) |
Jonas Ådahl | 0476974 | 2012-06-13 00:01:24 +0200 | [diff] [blame] | 687 | { |
| 688 | struct focus_state *state, *next; |
Kristian Høgsberg | fe7aa90 | 2013-05-08 09:54:37 -0400 | [diff] [blame] | 689 | struct weston_surface *surface; |
Jonas Ådahl | 0476974 | 2012-06-13 00:01:24 +0200 | [diff] [blame] | 690 | |
| 691 | wl_list_for_each_safe(state, next, &ws->focus_list, link) { |
Kristian Høgsberg | e61d2f4 | 2014-01-17 12:18:53 -0800 | [diff] [blame] | 692 | if (state->seat->keyboard == NULL) |
| 693 | continue; |
| 694 | |
Kristian Høgsberg | fe7aa90 | 2013-05-08 09:54:37 -0400 | [diff] [blame] | 695 | surface = state->keyboard_focus; |
Jonas Ådahl | 5689944 | 2012-08-29 22:12:59 +0200 | [diff] [blame] | 696 | |
Kristian Høgsberg | e314875 | 2013-05-06 23:19:49 -0400 | [diff] [blame] | 697 | weston_keyboard_set_focus(state->seat->keyboard, surface); |
Jonas Ådahl | 0476974 | 2012-06-13 00:01:24 +0200 | [diff] [blame] | 698 | } |
| 699 | } |
| 700 | |
| 701 | static void |
Jonas Ådahl | 8de6a1d | 2012-08-29 22:13:00 +0200 | [diff] [blame] | 702 | replace_focus_state(struct desktop_shell *shell, struct workspace *ws, |
| 703 | struct weston_seat *seat) |
| 704 | { |
| 705 | struct focus_state *state; |
Jonas Ådahl | 8de6a1d | 2012-08-29 22:13:00 +0200 | [diff] [blame] | 706 | |
| 707 | wl_list_for_each(state, &ws->focus_list, link) { |
| 708 | if (state->seat == seat) { |
Kristian Høgsberg | d500bf1 | 2014-01-22 12:25:20 -0800 | [diff] [blame^] | 709 | focus_state_set_focus(state, seat->keyboard->focus); |
Jonas Ådahl | 8de6a1d | 2012-08-29 22:13:00 +0200 | [diff] [blame] | 710 | return; |
| 711 | } |
| 712 | } |
| 713 | } |
| 714 | |
| 715 | static void |
| 716 | drop_focus_state(struct desktop_shell *shell, struct workspace *ws, |
| 717 | struct weston_surface *surface) |
| 718 | { |
| 719 | struct focus_state *state; |
| 720 | |
| 721 | wl_list_for_each(state, &ws->focus_list, link) |
| 722 | if (state->keyboard_focus == surface) |
Kristian Høgsberg | d500bf1 | 2014-01-22 12:25:20 -0800 | [diff] [blame^] | 723 | focus_state_set_focus(state, NULL); |
Jonas Ådahl | 8de6a1d | 2012-08-29 22:13:00 +0200 | [diff] [blame] | 724 | } |
| 725 | |
| 726 | static void |
Louis-Francis Ratté-Boulianne | b482dbd | 2013-11-19 11:37:11 +0100 | [diff] [blame] | 727 | animate_focus_change(struct desktop_shell *shell, struct workspace *ws, |
| 728 | struct weston_view *from, struct weston_view *to) |
| 729 | { |
| 730 | struct weston_output *output; |
| 731 | bool focus_surface_created = false; |
| 732 | |
| 733 | /* FIXME: Only support dim animation using two layers */ |
| 734 | if (from == to || shell->focus_animation_type != ANIMATION_DIM_LAYER) |
| 735 | return; |
| 736 | |
| 737 | output = get_default_output(shell->compositor); |
| 738 | if (ws->fsurf_front == NULL && (from || to)) { |
| 739 | ws->fsurf_front = create_focus_surface(shell->compositor, output); |
U. Artie Eoff | 0b23b2b | 2014-01-15 14:45:59 -0800 | [diff] [blame] | 740 | if (ws->fsurf_front == NULL) |
| 741 | return; |
Louis-Francis Ratté-Boulianne | b482dbd | 2013-11-19 11:37:11 +0100 | [diff] [blame] | 742 | ws->fsurf_front->view->alpha = 0.0; |
U. Artie Eoff | 0b23b2b | 2014-01-15 14:45:59 -0800 | [diff] [blame] | 743 | |
| 744 | ws->fsurf_back = create_focus_surface(shell->compositor, output); |
| 745 | if (ws->fsurf_back == NULL) { |
| 746 | focus_surface_destroy(ws->fsurf_front); |
| 747 | return; |
| 748 | } |
Louis-Francis Ratté-Boulianne | b482dbd | 2013-11-19 11:37:11 +0100 | [diff] [blame] | 749 | ws->fsurf_back->view->alpha = 0.0; |
U. Artie Eoff | 0b23b2b | 2014-01-15 14:45:59 -0800 | [diff] [blame] | 750 | |
Louis-Francis Ratté-Boulianne | b482dbd | 2013-11-19 11:37:11 +0100 | [diff] [blame] | 751 | focus_surface_created = true; |
| 752 | } else { |
| 753 | wl_list_remove(&ws->fsurf_front->view->layer_link); |
| 754 | wl_list_remove(&ws->fsurf_back->view->layer_link); |
| 755 | } |
| 756 | |
| 757 | if (ws->focus_animation) { |
| 758 | weston_view_animation_destroy(ws->focus_animation); |
| 759 | ws->focus_animation = NULL; |
| 760 | } |
| 761 | |
| 762 | if (to) |
| 763 | wl_list_insert(&to->layer_link, |
| 764 | &ws->fsurf_front->view->layer_link); |
| 765 | else if (from) |
| 766 | wl_list_insert(&ws->layer.view_list, |
| 767 | &ws->fsurf_front->view->layer_link); |
| 768 | |
| 769 | if (focus_surface_created) { |
| 770 | ws->focus_animation = weston_fade_run( |
| 771 | ws->fsurf_front->view, |
| 772 | ws->fsurf_front->view->alpha, 0.6, 300, |
| 773 | focus_animation_done, ws); |
| 774 | } else if (from) { |
| 775 | wl_list_insert(&from->layer_link, |
| 776 | &ws->fsurf_back->view->layer_link); |
| 777 | ws->focus_animation = weston_stable_fade_run( |
| 778 | ws->fsurf_front->view, 0.0, |
| 779 | ws->fsurf_back->view, 0.6, |
| 780 | focus_animation_done, ws); |
| 781 | } else if (to) { |
| 782 | wl_list_insert(&ws->layer.view_list, |
| 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 | } |
| 789 | } |
| 790 | |
| 791 | static void |
Jonas Ådahl | e3cddce | 2012-06-13 00:01:22 +0200 | [diff] [blame] | 792 | workspace_destroy(struct workspace *ws) |
| 793 | { |
Jonas Ådahl | 0476974 | 2012-06-13 00:01:24 +0200 | [diff] [blame] | 794 | struct focus_state *state, *next; |
| 795 | |
| 796 | wl_list_for_each_safe(state, next, &ws->focus_list, link) |
| 797 | focus_state_destroy(state); |
| 798 | |
Louis-Francis Ratté-Boulianne | b482dbd | 2013-11-19 11:37:11 +0100 | [diff] [blame] | 799 | if (ws->fsurf_front) |
| 800 | focus_surface_destroy(ws->fsurf_front); |
| 801 | if (ws->fsurf_back) |
| 802 | focus_surface_destroy(ws->fsurf_back); |
| 803 | |
Jonas Ådahl | e3cddce | 2012-06-13 00:01:22 +0200 | [diff] [blame] | 804 | free(ws); |
| 805 | } |
| 806 | |
Jonas Ådahl | 0476974 | 2012-06-13 00:01:24 +0200 | [diff] [blame] | 807 | static void |
| 808 | seat_destroyed(struct wl_listener *listener, void *data) |
| 809 | { |
| 810 | struct weston_seat *seat = data; |
| 811 | struct focus_state *state, *next; |
| 812 | struct workspace *ws = container_of(listener, |
| 813 | struct workspace, |
| 814 | seat_destroyed_listener); |
| 815 | |
| 816 | wl_list_for_each_safe(state, next, &ws->focus_list, link) |
| 817 | if (state->seat == seat) |
| 818 | wl_list_remove(&state->link); |
| 819 | } |
| 820 | |
Jonas Ådahl | e3cddce | 2012-06-13 00:01:22 +0200 | [diff] [blame] | 821 | static struct workspace * |
| 822 | workspace_create(void) |
| 823 | { |
| 824 | struct workspace *ws = malloc(sizeof *ws); |
| 825 | if (ws == NULL) |
| 826 | return NULL; |
| 827 | |
| 828 | weston_layer_init(&ws->layer, NULL); |
| 829 | |
Jonas Ådahl | 0476974 | 2012-06-13 00:01:24 +0200 | [diff] [blame] | 830 | wl_list_init(&ws->focus_list); |
| 831 | wl_list_init(&ws->seat_destroyed_listener.link); |
| 832 | ws->seat_destroyed_listener.notify = seat_destroyed; |
Louis-Francis Ratté-Boulianne | b482dbd | 2013-11-19 11:37:11 +0100 | [diff] [blame] | 833 | ws->fsurf_front = NULL; |
| 834 | ws->fsurf_back = NULL; |
| 835 | ws->focus_animation = NULL; |
Jonas Ådahl | 0476974 | 2012-06-13 00:01:24 +0200 | [diff] [blame] | 836 | |
Jonas Ådahl | e3cddce | 2012-06-13 00:01:22 +0200 | [diff] [blame] | 837 | return ws; |
| 838 | } |
| 839 | |
Jonas Ådahl | 62fcd04 | 2012-06-13 00:01:23 +0200 | [diff] [blame] | 840 | static int |
| 841 | workspace_is_empty(struct workspace *ws) |
| 842 | { |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 843 | return wl_list_empty(&ws->layer.view_list); |
Jonas Ådahl | 62fcd04 | 2012-06-13 00:01:23 +0200 | [diff] [blame] | 844 | } |
| 845 | |
Jonas Ådahl | e3cddce | 2012-06-13 00:01:22 +0200 | [diff] [blame] | 846 | static struct workspace * |
| 847 | get_workspace(struct desktop_shell *shell, unsigned int index) |
| 848 | { |
| 849 | struct workspace **pws = shell->workspaces.array.data; |
Philipp Brüschweiler | 067abf6 | 2012-09-01 16:03:05 +0200 | [diff] [blame] | 850 | assert(index < shell->workspaces.num); |
Jonas Ådahl | e3cddce | 2012-06-13 00:01:22 +0200 | [diff] [blame] | 851 | pws += index; |
| 852 | return *pws; |
| 853 | } |
| 854 | |
Kristian Høgsberg | 1ef2313 | 2013-12-04 00:20:01 -0800 | [diff] [blame] | 855 | struct workspace * |
Jonas Ådahl | e3cddce | 2012-06-13 00:01:22 +0200 | [diff] [blame] | 856 | get_current_workspace(struct desktop_shell *shell) |
| 857 | { |
| 858 | return get_workspace(shell, shell->workspaces.current); |
| 859 | } |
| 860 | |
| 861 | static void |
| 862 | activate_workspace(struct desktop_shell *shell, unsigned int index) |
| 863 | { |
| 864 | struct workspace *ws; |
| 865 | |
| 866 | ws = get_workspace(shell, index); |
| 867 | wl_list_insert(&shell->panel_layer.link, &ws->layer.link); |
| 868 | |
| 869 | shell->workspaces.current = index; |
| 870 | } |
| 871 | |
Jonas Ådahl | 62fcd04 | 2012-06-13 00:01:23 +0200 | [diff] [blame] | 872 | static unsigned int |
| 873 | get_output_height(struct weston_output *output) |
| 874 | { |
| 875 | return abs(output->region.extents.y1 - output->region.extents.y2); |
| 876 | } |
| 877 | |
| 878 | static void |
Louis-Francis Ratté-Boulianne | b482dbd | 2013-11-19 11:37:11 +0100 | [diff] [blame] | 879 | view_translate(struct workspace *ws, struct weston_view *view, double d) |
Jonas Ådahl | 62fcd04 | 2012-06-13 00:01:23 +0200 | [diff] [blame] | 880 | { |
Jonas Ådahl | 62fcd04 | 2012-06-13 00:01:23 +0200 | [diff] [blame] | 881 | struct weston_transform *transform; |
| 882 | |
Louis-Francis Ratté-Boulianne | b482dbd | 2013-11-19 11:37:11 +0100 | [diff] [blame] | 883 | if (is_focus_view(view)) { |
| 884 | struct focus_surface *fsurf = get_focus_surface(view->surface); |
| 885 | transform = &fsurf->workspace_transform; |
| 886 | } else { |
| 887 | struct shell_surface *shsurf = get_shell_surface(view->surface); |
| 888 | transform = &shsurf->workspace_transform; |
| 889 | } |
| 890 | |
Jonas Ådahl | 62fcd04 | 2012-06-13 00:01:23 +0200 | [diff] [blame] | 891 | if (wl_list_empty(&transform->link)) |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 892 | wl_list_insert(view->geometry.transformation_list.prev, |
Louis-Francis Ratté-Boulianne | b482dbd | 2013-11-19 11:37:11 +0100 | [diff] [blame] | 893 | &transform->link); |
Jonas Ådahl | 62fcd04 | 2012-06-13 00:01:23 +0200 | [diff] [blame] | 894 | |
Louis-Francis Ratté-Boulianne | b482dbd | 2013-11-19 11:37:11 +0100 | [diff] [blame] | 895 | weston_matrix_init(&transform->matrix); |
| 896 | weston_matrix_translate(&transform->matrix, |
Jonas Ådahl | 62fcd04 | 2012-06-13 00:01:23 +0200 | [diff] [blame] | 897 | 0.0, d, 0.0); |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 898 | weston_view_geometry_dirty(view); |
Jonas Ådahl | 62fcd04 | 2012-06-13 00:01:23 +0200 | [diff] [blame] | 899 | } |
| 900 | |
| 901 | static void |
| 902 | workspace_translate_out(struct workspace *ws, double fraction) |
| 903 | { |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 904 | struct weston_view *view; |
Jonas Ådahl | 62fcd04 | 2012-06-13 00:01:23 +0200 | [diff] [blame] | 905 | unsigned int height; |
| 906 | double d; |
| 907 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 908 | wl_list_for_each(view, &ws->layer.view_list, layer_link) { |
| 909 | height = get_output_height(view->surface->output); |
Jonas Ådahl | 62fcd04 | 2012-06-13 00:01:23 +0200 | [diff] [blame] | 910 | d = height * fraction; |
| 911 | |
Louis-Francis Ratté-Boulianne | b482dbd | 2013-11-19 11:37:11 +0100 | [diff] [blame] | 912 | view_translate(ws, view, d); |
Jonas Ådahl | 62fcd04 | 2012-06-13 00:01:23 +0200 | [diff] [blame] | 913 | } |
| 914 | } |
| 915 | |
| 916 | static void |
| 917 | workspace_translate_in(struct workspace *ws, double fraction) |
| 918 | { |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 919 | struct weston_view *view; |
Jonas Ådahl | 62fcd04 | 2012-06-13 00:01:23 +0200 | [diff] [blame] | 920 | unsigned int height; |
| 921 | double d; |
| 922 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 923 | wl_list_for_each(view, &ws->layer.view_list, layer_link) { |
| 924 | height = get_output_height(view->surface->output); |
Jonas Ådahl | 62fcd04 | 2012-06-13 00:01:23 +0200 | [diff] [blame] | 925 | |
| 926 | if (fraction > 0) |
| 927 | d = -(height - height * fraction); |
| 928 | else |
| 929 | d = height + height * fraction; |
| 930 | |
Louis-Francis Ratté-Boulianne | b482dbd | 2013-11-19 11:37:11 +0100 | [diff] [blame] | 931 | view_translate(ws, view, d); |
Jonas Ådahl | 62fcd04 | 2012-06-13 00:01:23 +0200 | [diff] [blame] | 932 | } |
| 933 | } |
| 934 | |
| 935 | static void |
Jonas Ådahl | e9d2250 | 2012-08-29 22:13:01 +0200 | [diff] [blame] | 936 | broadcast_current_workspace_state(struct desktop_shell *shell) |
| 937 | { |
Kristian Høgsberg | 2e3c396 | 2013-09-11 12:00:47 -0700 | [diff] [blame] | 938 | struct wl_resource *resource; |
Jonas Ådahl | e9d2250 | 2012-08-29 22:13:01 +0200 | [diff] [blame] | 939 | |
Kristian Høgsberg | 2e3c396 | 2013-09-11 12:00:47 -0700 | [diff] [blame] | 940 | wl_resource_for_each(resource, &shell->workspaces.client_list) |
| 941 | workspace_manager_send_state(resource, |
Jonas Ådahl | e9d2250 | 2012-08-29 22:13:01 +0200 | [diff] [blame] | 942 | shell->workspaces.current, |
| 943 | shell->workspaces.num); |
| 944 | } |
| 945 | |
| 946 | static void |
Jonas Ådahl | 62fcd04 | 2012-06-13 00:01:23 +0200 | [diff] [blame] | 947 | reverse_workspace_change_animation(struct desktop_shell *shell, |
| 948 | unsigned int index, |
| 949 | struct workspace *from, |
| 950 | struct workspace *to) |
| 951 | { |
| 952 | shell->workspaces.current = index; |
| 953 | |
| 954 | shell->workspaces.anim_to = to; |
| 955 | shell->workspaces.anim_from = from; |
| 956 | shell->workspaces.anim_dir = -1 * shell->workspaces.anim_dir; |
| 957 | shell->workspaces.anim_timestamp = 0; |
| 958 | |
Scott Moreau | 4272e63 | 2012-08-13 09:58:41 -0600 | [diff] [blame] | 959 | weston_compositor_schedule_repaint(shell->compositor); |
Jonas Ådahl | 62fcd04 | 2012-06-13 00:01:23 +0200 | [diff] [blame] | 960 | } |
| 961 | |
| 962 | static void |
| 963 | workspace_deactivate_transforms(struct workspace *ws) |
| 964 | { |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 965 | struct weston_view *view; |
Louis-Francis Ratté-Boulianne | b482dbd | 2013-11-19 11:37:11 +0100 | [diff] [blame] | 966 | struct weston_transform *transform; |
Jonas Ådahl | 62fcd04 | 2012-06-13 00:01:23 +0200 | [diff] [blame] | 967 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 968 | 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] | 969 | if (is_focus_view(view)) { |
| 970 | struct focus_surface *fsurf = get_focus_surface(view->surface); |
| 971 | transform = &fsurf->workspace_transform; |
| 972 | } else { |
| 973 | struct shell_surface *shsurf = get_shell_surface(view->surface); |
| 974 | transform = &shsurf->workspace_transform; |
| 975 | } |
| 976 | |
| 977 | if (!wl_list_empty(&transform->link)) { |
| 978 | wl_list_remove(&transform->link); |
| 979 | wl_list_init(&transform->link); |
Jonas Ådahl | 8de6a1d | 2012-08-29 22:13:00 +0200 | [diff] [blame] | 980 | } |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 981 | weston_view_geometry_dirty(view); |
Jonas Ådahl | 62fcd04 | 2012-06-13 00:01:23 +0200 | [diff] [blame] | 982 | } |
| 983 | } |
| 984 | |
| 985 | static void |
| 986 | finish_workspace_change_animation(struct desktop_shell *shell, |
| 987 | struct workspace *from, |
| 988 | struct workspace *to) |
| 989 | { |
Scott Moreau | 4272e63 | 2012-08-13 09:58:41 -0600 | [diff] [blame] | 990 | weston_compositor_schedule_repaint(shell->compositor); |
Jonas Ådahl | 62fcd04 | 2012-06-13 00:01:23 +0200 | [diff] [blame] | 991 | |
| 992 | wl_list_remove(&shell->workspaces.animation.link); |
| 993 | workspace_deactivate_transforms(from); |
| 994 | workspace_deactivate_transforms(to); |
| 995 | shell->workspaces.anim_to = NULL; |
| 996 | |
| 997 | wl_list_remove(&shell->workspaces.anim_from->layer.link); |
| 998 | } |
| 999 | |
| 1000 | static void |
| 1001 | animate_workspace_change_frame(struct weston_animation *animation, |
| 1002 | struct weston_output *output, uint32_t msecs) |
| 1003 | { |
| 1004 | struct desktop_shell *shell = |
| 1005 | container_of(animation, struct desktop_shell, |
| 1006 | workspaces.animation); |
| 1007 | struct workspace *from = shell->workspaces.anim_from; |
| 1008 | struct workspace *to = shell->workspaces.anim_to; |
| 1009 | uint32_t t; |
| 1010 | double x, y; |
| 1011 | |
| 1012 | if (workspace_is_empty(from) && workspace_is_empty(to)) { |
| 1013 | finish_workspace_change_animation(shell, from, to); |
| 1014 | return; |
| 1015 | } |
| 1016 | |
| 1017 | if (shell->workspaces.anim_timestamp == 0) { |
| 1018 | if (shell->workspaces.anim_current == 0.0) |
| 1019 | shell->workspaces.anim_timestamp = msecs; |
| 1020 | else |
| 1021 | shell->workspaces.anim_timestamp = |
| 1022 | msecs - |
| 1023 | /* Invers of movement function 'y' below. */ |
| 1024 | (asin(1.0 - shell->workspaces.anim_current) * |
| 1025 | DEFAULT_WORKSPACE_CHANGE_ANIMATION_LENGTH * |
| 1026 | M_2_PI); |
| 1027 | } |
| 1028 | |
| 1029 | t = msecs - shell->workspaces.anim_timestamp; |
| 1030 | |
| 1031 | /* |
| 1032 | * x = [0, π/2] |
| 1033 | * y(x) = sin(x) |
| 1034 | */ |
| 1035 | x = t * (1.0/DEFAULT_WORKSPACE_CHANGE_ANIMATION_LENGTH) * M_PI_2; |
| 1036 | y = sin(x); |
| 1037 | |
| 1038 | if (t < DEFAULT_WORKSPACE_CHANGE_ANIMATION_LENGTH) { |
Scott Moreau | 4272e63 | 2012-08-13 09:58:41 -0600 | [diff] [blame] | 1039 | weston_compositor_schedule_repaint(shell->compositor); |
Jonas Ådahl | 62fcd04 | 2012-06-13 00:01:23 +0200 | [diff] [blame] | 1040 | |
| 1041 | workspace_translate_out(from, shell->workspaces.anim_dir * y); |
| 1042 | workspace_translate_in(to, shell->workspaces.anim_dir * y); |
| 1043 | shell->workspaces.anim_current = y; |
| 1044 | |
Scott Moreau | 4272e63 | 2012-08-13 09:58:41 -0600 | [diff] [blame] | 1045 | weston_compositor_schedule_repaint(shell->compositor); |
Jonas Ådahl | 62fcd04 | 2012-06-13 00:01:23 +0200 | [diff] [blame] | 1046 | } |
Jonas Ådahl | 0476974 | 2012-06-13 00:01:24 +0200 | [diff] [blame] | 1047 | else |
Jonas Ådahl | 62fcd04 | 2012-06-13 00:01:23 +0200 | [diff] [blame] | 1048 | finish_workspace_change_animation(shell, from, to); |
Jonas Ådahl | 62fcd04 | 2012-06-13 00:01:23 +0200 | [diff] [blame] | 1049 | } |
| 1050 | |
| 1051 | static void |
| 1052 | animate_workspace_change(struct desktop_shell *shell, |
| 1053 | unsigned int index, |
| 1054 | struct workspace *from, |
| 1055 | struct workspace *to) |
| 1056 | { |
| 1057 | struct weston_output *output; |
| 1058 | |
| 1059 | int dir; |
| 1060 | |
| 1061 | if (index > shell->workspaces.current) |
| 1062 | dir = -1; |
| 1063 | else |
| 1064 | dir = 1; |
| 1065 | |
| 1066 | shell->workspaces.current = index; |
| 1067 | |
| 1068 | shell->workspaces.anim_dir = dir; |
| 1069 | shell->workspaces.anim_from = from; |
| 1070 | shell->workspaces.anim_to = to; |
| 1071 | shell->workspaces.anim_current = 0.0; |
| 1072 | shell->workspaces.anim_timestamp = 0; |
| 1073 | |
| 1074 | output = container_of(shell->compositor->output_list.next, |
| 1075 | struct weston_output, link); |
| 1076 | wl_list_insert(&output->animation_list, |
| 1077 | &shell->workspaces.animation.link); |
| 1078 | |
Jonas Ådahl | 8de6a1d | 2012-08-29 22:13:00 +0200 | [diff] [blame] | 1079 | wl_list_insert(from->layer.link.prev, &to->layer.link); |
Jonas Ådahl | 62fcd04 | 2012-06-13 00:01:23 +0200 | [diff] [blame] | 1080 | |
| 1081 | workspace_translate_in(to, 0); |
| 1082 | |
Kristian Høgsberg | 2f5faff | 2012-07-31 16:36:34 -0400 | [diff] [blame] | 1083 | restore_focus_state(shell, to); |
Jonas Ådahl | 0476974 | 2012-06-13 00:01:24 +0200 | [diff] [blame] | 1084 | |
Scott Moreau | 4272e63 | 2012-08-13 09:58:41 -0600 | [diff] [blame] | 1085 | weston_compositor_schedule_repaint(shell->compositor); |
Jonas Ådahl | 62fcd04 | 2012-06-13 00:01:23 +0200 | [diff] [blame] | 1086 | } |
| 1087 | |
Jonas Ådahl | e3cddce | 2012-06-13 00:01:22 +0200 | [diff] [blame] | 1088 | static void |
Jonas Ådahl | 8de6a1d | 2012-08-29 22:13:00 +0200 | [diff] [blame] | 1089 | update_workspace(struct desktop_shell *shell, unsigned int index, |
| 1090 | struct workspace *from, struct workspace *to) |
| 1091 | { |
| 1092 | shell->workspaces.current = index; |
| 1093 | wl_list_insert(&from->layer.link, &to->layer.link); |
| 1094 | wl_list_remove(&from->layer.link); |
| 1095 | } |
| 1096 | |
| 1097 | static void |
Jonas Ådahl | e3cddce | 2012-06-13 00:01:22 +0200 | [diff] [blame] | 1098 | change_workspace(struct desktop_shell *shell, unsigned int index) |
| 1099 | { |
| 1100 | struct workspace *from; |
| 1101 | struct workspace *to; |
Louis-Francis Ratté-Boulianne | b482dbd | 2013-11-19 11:37:11 +0100 | [diff] [blame] | 1102 | struct focus_state *state; |
Jonas Ådahl | e3cddce | 2012-06-13 00:01:22 +0200 | [diff] [blame] | 1103 | |
| 1104 | if (index == shell->workspaces.current) |
| 1105 | return; |
| 1106 | |
| 1107 | /* Don't change workspace when there is any fullscreen surfaces. */ |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 1108 | if (!wl_list_empty(&shell->fullscreen_layer.view_list)) |
Jonas Ådahl | e3cddce | 2012-06-13 00:01:22 +0200 | [diff] [blame] | 1109 | return; |
| 1110 | |
Jonas Ådahl | e3cddce | 2012-06-13 00:01:22 +0200 | [diff] [blame] | 1111 | from = get_current_workspace(shell); |
| 1112 | to = get_workspace(shell, index); |
| 1113 | |
Jonas Ådahl | 62fcd04 | 2012-06-13 00:01:23 +0200 | [diff] [blame] | 1114 | if (shell->workspaces.anim_from == to && |
| 1115 | shell->workspaces.anim_to == from) { |
Jonas Ådahl | 8de6a1d | 2012-08-29 22:13:00 +0200 | [diff] [blame] | 1116 | restore_focus_state(shell, to); |
Jonas Ådahl | 62fcd04 | 2012-06-13 00:01:23 +0200 | [diff] [blame] | 1117 | reverse_workspace_change_animation(shell, index, from, to); |
Jonas Ådahl | e9d2250 | 2012-08-29 22:13:01 +0200 | [diff] [blame] | 1118 | broadcast_current_workspace_state(shell); |
Jonas Ådahl | 62fcd04 | 2012-06-13 00:01:23 +0200 | [diff] [blame] | 1119 | return; |
| 1120 | } |
Jonas Ådahl | e3cddce | 2012-06-13 00:01:22 +0200 | [diff] [blame] | 1121 | |
Jonas Ådahl | 62fcd04 | 2012-06-13 00:01:23 +0200 | [diff] [blame] | 1122 | if (shell->workspaces.anim_to != NULL) |
| 1123 | finish_workspace_change_animation(shell, |
| 1124 | shell->workspaces.anim_from, |
| 1125 | shell->workspaces.anim_to); |
| 1126 | |
Jonas Ådahl | 8de6a1d | 2012-08-29 22:13:00 +0200 | [diff] [blame] | 1127 | restore_focus_state(shell, to); |
Jonas Ådahl | 0476974 | 2012-06-13 00:01:24 +0200 | [diff] [blame] | 1128 | |
Louis-Francis Ratté-Boulianne | b482dbd | 2013-11-19 11:37:11 +0100 | [diff] [blame] | 1129 | if (shell->focus_animation_type != ANIMATION_NONE) { |
| 1130 | wl_list_for_each(state, &from->focus_list, link) |
| 1131 | if (state->keyboard_focus) |
| 1132 | animate_focus_change(shell, from, |
| 1133 | get_default_view(state->keyboard_focus), NULL); |
| 1134 | |
| 1135 | wl_list_for_each(state, &to->focus_list, link) |
| 1136 | if (state->keyboard_focus) |
| 1137 | animate_focus_change(shell, to, |
| 1138 | NULL, get_default_view(state->keyboard_focus)); |
| 1139 | } |
| 1140 | |
Jonas Ådahl | 8de6a1d | 2012-08-29 22:13:00 +0200 | [diff] [blame] | 1141 | if (workspace_is_empty(to) && workspace_is_empty(from)) |
| 1142 | update_workspace(shell, index, from, to); |
Jonas Ådahl | 62fcd04 | 2012-06-13 00:01:23 +0200 | [diff] [blame] | 1143 | else |
| 1144 | animate_workspace_change(shell, index, from, to); |
Jonas Ådahl | e9d2250 | 2012-08-29 22:13:01 +0200 | [diff] [blame] | 1145 | |
| 1146 | broadcast_current_workspace_state(shell); |
Pekka Paalanen | e955f1e | 2011-12-07 11:49:52 +0200 | [diff] [blame] | 1147 | } |
| 1148 | |
Jonas Ådahl | 8de6a1d | 2012-08-29 22:13:00 +0200 | [diff] [blame] | 1149 | static bool |
| 1150 | workspace_has_only(struct workspace *ws, struct weston_surface *surface) |
| 1151 | { |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 1152 | struct wl_list *list = &ws->layer.view_list; |
Jonas Ådahl | 8de6a1d | 2012-08-29 22:13:00 +0200 | [diff] [blame] | 1153 | struct wl_list *e; |
| 1154 | |
| 1155 | if (wl_list_empty(list)) |
| 1156 | return false; |
| 1157 | |
| 1158 | e = list->next; |
| 1159 | |
| 1160 | if (e->next != list) |
| 1161 | return false; |
| 1162 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 1163 | return container_of(e, struct weston_view, layer_link)->surface == surface; |
Jonas Ådahl | 8de6a1d | 2012-08-29 22:13:00 +0200 | [diff] [blame] | 1164 | } |
| 1165 | |
| 1166 | static void |
Philip Withnall | 659163d | 2013-11-25 18:01:36 +0000 | [diff] [blame] | 1167 | move_surface_to_workspace(struct desktop_shell *shell, |
| 1168 | struct shell_surface *shsurf, |
| 1169 | uint32_t workspace) |
Jonas Ådahl | e9d2250 | 2012-08-29 22:13:01 +0200 | [diff] [blame] | 1170 | { |
| 1171 | struct workspace *from; |
| 1172 | struct workspace *to; |
| 1173 | struct weston_seat *seat; |
Pekka Paalanen | 01388e2 | 2013-04-25 13:57:44 +0300 | [diff] [blame] | 1174 | struct weston_surface *focus; |
Philip Withnall | 659163d | 2013-11-25 18:01:36 +0000 | [diff] [blame] | 1175 | struct weston_view *view; |
Jonas Ådahl | e9d2250 | 2012-08-29 22:13:01 +0200 | [diff] [blame] | 1176 | |
| 1177 | if (workspace == shell->workspaces.current) |
| 1178 | return; |
| 1179 | |
Philip Withnall | 659163d | 2013-11-25 18:01:36 +0000 | [diff] [blame] | 1180 | view = get_default_view(shsurf->surface); |
| 1181 | if (!view) |
| 1182 | return; |
| 1183 | |
| 1184 | assert(weston_surface_get_main_surface(view->surface) == view->surface); |
| 1185 | |
Philipp Brüschweiler | 067abf6 | 2012-09-01 16:03:05 +0200 | [diff] [blame] | 1186 | if (workspace >= shell->workspaces.num) |
| 1187 | workspace = shell->workspaces.num - 1; |
| 1188 | |
Jonas Ådahl | e9d2250 | 2012-08-29 22:13:01 +0200 | [diff] [blame] | 1189 | from = get_current_workspace(shell); |
| 1190 | to = get_workspace(shell, workspace); |
| 1191 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 1192 | wl_list_remove(&view->layer_link); |
| 1193 | wl_list_insert(&to->layer.view_list, &view->layer_link); |
Jonas Ådahl | e9d2250 | 2012-08-29 22:13:01 +0200 | [diff] [blame] | 1194 | |
Philip Withnall | 648a4dd | 2013-11-25 18:01:44 +0000 | [diff] [blame] | 1195 | shell_surface_update_child_surface_layers(shsurf); |
| 1196 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 1197 | drop_focus_state(shell, from, view->surface); |
Pekka Paalanen | 01388e2 | 2013-04-25 13:57:44 +0300 | [diff] [blame] | 1198 | wl_list_for_each(seat, &shell->compositor->seat_list, link) { |
| 1199 | if (!seat->keyboard) |
| 1200 | continue; |
| 1201 | |
| 1202 | focus = weston_surface_get_main_surface(seat->keyboard->focus); |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 1203 | if (focus == view->surface) |
Kristian Høgsberg | e314875 | 2013-05-06 23:19:49 -0400 | [diff] [blame] | 1204 | weston_keyboard_set_focus(seat->keyboard, NULL); |
Pekka Paalanen | 01388e2 | 2013-04-25 13:57:44 +0300 | [diff] [blame] | 1205 | } |
Jonas Ådahl | e9d2250 | 2012-08-29 22:13:01 +0200 | [diff] [blame] | 1206 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 1207 | weston_view_damage_below(view); |
Jonas Ådahl | e9d2250 | 2012-08-29 22:13:01 +0200 | [diff] [blame] | 1208 | } |
| 1209 | |
| 1210 | static void |
Jonas Ådahl | 8de6a1d | 2012-08-29 22:13:00 +0200 | [diff] [blame] | 1211 | take_surface_to_workspace_by_seat(struct desktop_shell *shell, |
Kristian Høgsberg | e314875 | 2013-05-06 23:19:49 -0400 | [diff] [blame] | 1212 | struct weston_seat *seat, |
Jonas Ådahl | 8de6a1d | 2012-08-29 22:13:00 +0200 | [diff] [blame] | 1213 | unsigned int index) |
| 1214 | { |
Pekka Paalanen | 01388e2 | 2013-04-25 13:57:44 +0300 | [diff] [blame] | 1215 | struct weston_surface *surface; |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 1216 | struct weston_view *view; |
Jonas Ådahl | 8de6a1d | 2012-08-29 22:13:00 +0200 | [diff] [blame] | 1217 | struct shell_surface *shsurf; |
| 1218 | struct workspace *from; |
| 1219 | struct workspace *to; |
Jonas Ådahl | 8538b22 | 2012-08-29 22:13:03 +0200 | [diff] [blame] | 1220 | struct focus_state *state; |
Jonas Ådahl | 8de6a1d | 2012-08-29 22:13:00 +0200 | [diff] [blame] | 1221 | |
Pekka Paalanen | 01388e2 | 2013-04-25 13:57:44 +0300 | [diff] [blame] | 1222 | surface = weston_surface_get_main_surface(seat->keyboard->focus); |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 1223 | view = get_default_view(surface); |
| 1224 | if (view == NULL || |
Louis-Francis Ratté-Boulianne | b482dbd | 2013-11-19 11:37:11 +0100 | [diff] [blame] | 1225 | index == shell->workspaces.current || |
| 1226 | is_focus_view(view)) |
Jonas Ådahl | 8de6a1d | 2012-08-29 22:13:00 +0200 | [diff] [blame] | 1227 | return; |
| 1228 | |
| 1229 | from = get_current_workspace(shell); |
| 1230 | to = get_workspace(shell, index); |
| 1231 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 1232 | wl_list_remove(&view->layer_link); |
| 1233 | wl_list_insert(&to->layer.view_list, &view->layer_link); |
Jonas Ådahl | 8de6a1d | 2012-08-29 22:13:00 +0200 | [diff] [blame] | 1234 | |
Philip Withnall | 659163d | 2013-11-25 18:01:36 +0000 | [diff] [blame] | 1235 | shsurf = get_shell_surface(surface); |
Philip Withnall | 648a4dd | 2013-11-25 18:01:44 +0000 | [diff] [blame] | 1236 | if (shsurf != NULL) |
| 1237 | shell_surface_update_child_surface_layers(shsurf); |
Philip Withnall | 659163d | 2013-11-25 18:01:36 +0000 | [diff] [blame] | 1238 | |
Jonas Ådahl | e9d2250 | 2012-08-29 22:13:01 +0200 | [diff] [blame] | 1239 | replace_focus_state(shell, to, seat); |
Jonas Ådahl | 8de6a1d | 2012-08-29 22:13:00 +0200 | [diff] [blame] | 1240 | drop_focus_state(shell, from, surface); |
| 1241 | |
| 1242 | if (shell->workspaces.anim_from == to && |
| 1243 | shell->workspaces.anim_to == from) { |
Jonas Ådahl | e9d2250 | 2012-08-29 22:13:01 +0200 | [diff] [blame] | 1244 | wl_list_remove(&to->layer.link); |
| 1245 | wl_list_insert(from->layer.link.prev, &to->layer.link); |
| 1246 | |
Jonas Ådahl | 8de6a1d | 2012-08-29 22:13:00 +0200 | [diff] [blame] | 1247 | reverse_workspace_change_animation(shell, index, from, to); |
Jonas Ådahl | e9d2250 | 2012-08-29 22:13:01 +0200 | [diff] [blame] | 1248 | broadcast_current_workspace_state(shell); |
| 1249 | |
Jonas Ådahl | 8de6a1d | 2012-08-29 22:13:00 +0200 | [diff] [blame] | 1250 | return; |
| 1251 | } |
| 1252 | |
| 1253 | if (shell->workspaces.anim_to != NULL) |
| 1254 | finish_workspace_change_animation(shell, |
| 1255 | shell->workspaces.anim_from, |
| 1256 | shell->workspaces.anim_to); |
| 1257 | |
| 1258 | if (workspace_is_empty(from) && |
| 1259 | workspace_has_only(to, surface)) |
| 1260 | update_workspace(shell, index, from, to); |
| 1261 | else { |
Philip Withnall | 2c3849b | 2013-11-25 18:01:45 +0000 | [diff] [blame] | 1262 | if (shsurf != NULL && |
| 1263 | wl_list_empty(&shsurf->workspace_transform.link)) |
Jonas Ådahl | 8de6a1d | 2012-08-29 22:13:00 +0200 | [diff] [blame] | 1264 | wl_list_insert(&shell->workspaces.anim_sticky_list, |
| 1265 | &shsurf->workspace_transform.link); |
| 1266 | |
| 1267 | animate_workspace_change(shell, index, from, to); |
| 1268 | } |
Jonas Ådahl | e9d2250 | 2012-08-29 22:13:01 +0200 | [diff] [blame] | 1269 | |
| 1270 | broadcast_current_workspace_state(shell); |
Jonas Ådahl | 8538b22 | 2012-08-29 22:13:03 +0200 | [diff] [blame] | 1271 | |
| 1272 | state = ensure_focus_state(shell, seat); |
| 1273 | if (state != NULL) |
Kristian Høgsberg | d500bf1 | 2014-01-22 12:25:20 -0800 | [diff] [blame^] | 1274 | focus_state_set_focus(state, surface); |
Jonas Ådahl | e9d2250 | 2012-08-29 22:13:01 +0200 | [diff] [blame] | 1275 | } |
| 1276 | |
| 1277 | static void |
| 1278 | workspace_manager_move_surface(struct wl_client *client, |
| 1279 | struct wl_resource *resource, |
| 1280 | struct wl_resource *surface_resource, |
| 1281 | uint32_t workspace) |
| 1282 | { |
Jason Ekstrand | 651f00e | 2013-06-14 10:07:54 -0500 | [diff] [blame] | 1283 | struct desktop_shell *shell = wl_resource_get_user_data(resource); |
Jonas Ådahl | e9d2250 | 2012-08-29 22:13:01 +0200 | [diff] [blame] | 1284 | struct weston_surface *surface = |
Jason Ekstrand | 0f2ef7e | 2013-06-14 10:07:53 -0500 | [diff] [blame] | 1285 | wl_resource_get_user_data(surface_resource); |
Pekka Paalanen | 01388e2 | 2013-04-25 13:57:44 +0300 | [diff] [blame] | 1286 | struct weston_surface *main_surface; |
Philip Withnall | 659163d | 2013-11-25 18:01:36 +0000 | [diff] [blame] | 1287 | struct shell_surface *shell_surface; |
Jonas Ådahl | e9d2250 | 2012-08-29 22:13:01 +0200 | [diff] [blame] | 1288 | |
Pekka Paalanen | 01388e2 | 2013-04-25 13:57:44 +0300 | [diff] [blame] | 1289 | main_surface = weston_surface_get_main_surface(surface); |
Philip Withnall | 659163d | 2013-11-25 18:01:36 +0000 | [diff] [blame] | 1290 | shell_surface = get_shell_surface(main_surface); |
| 1291 | if (shell_surface == NULL) |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 1292 | return; |
Philip Withnall | 659163d | 2013-11-25 18:01:36 +0000 | [diff] [blame] | 1293 | |
| 1294 | move_surface_to_workspace(shell, shell_surface, workspace); |
Jonas Ådahl | e9d2250 | 2012-08-29 22:13:01 +0200 | [diff] [blame] | 1295 | } |
| 1296 | |
| 1297 | static const struct workspace_manager_interface workspace_manager_implementation = { |
| 1298 | workspace_manager_move_surface, |
| 1299 | }; |
| 1300 | |
| 1301 | static void |
| 1302 | unbind_resource(struct wl_resource *resource) |
| 1303 | { |
Jason Ekstrand | 651f00e | 2013-06-14 10:07:54 -0500 | [diff] [blame] | 1304 | wl_list_remove(wl_resource_get_link(resource)); |
Jonas Ådahl | e9d2250 | 2012-08-29 22:13:01 +0200 | [diff] [blame] | 1305 | } |
| 1306 | |
| 1307 | static void |
| 1308 | bind_workspace_manager(struct wl_client *client, |
| 1309 | void *data, uint32_t version, uint32_t id) |
| 1310 | { |
| 1311 | struct desktop_shell *shell = data; |
| 1312 | struct wl_resource *resource; |
| 1313 | |
Jason Ekstrand | a85118c | 2013-06-27 20:17:02 -0500 | [diff] [blame] | 1314 | resource = wl_resource_create(client, |
| 1315 | &workspace_manager_interface, 1, id); |
Jonas Ådahl | e9d2250 | 2012-08-29 22:13:01 +0200 | [diff] [blame] | 1316 | |
| 1317 | if (resource == NULL) { |
| 1318 | weston_log("couldn't add workspace manager object"); |
| 1319 | return; |
| 1320 | } |
| 1321 | |
Jason Ekstrand | a85118c | 2013-06-27 20:17:02 -0500 | [diff] [blame] | 1322 | wl_resource_set_implementation(resource, |
| 1323 | &workspace_manager_implementation, |
| 1324 | shell, unbind_resource); |
Jason Ekstrand | 651f00e | 2013-06-14 10:07:54 -0500 | [diff] [blame] | 1325 | wl_list_insert(&shell->workspaces.client_list, |
| 1326 | wl_resource_get_link(resource)); |
Jonas Ådahl | e9d2250 | 2012-08-29 22:13:01 +0200 | [diff] [blame] | 1327 | |
| 1328 | workspace_manager_send_state(resource, |
| 1329 | shell->workspaces.current, |
| 1330 | shell->workspaces.num); |
Jonas Ådahl | 8de6a1d | 2012-08-29 22:13:00 +0200 | [diff] [blame] | 1331 | } |
| 1332 | |
Pekka Paalanen | 56cdea9 | 2011-11-23 16:14:12 +0200 | [diff] [blame] | 1333 | static void |
Rusty Lynch | 1084da5 | 2013-08-15 09:10:08 -0700 | [diff] [blame] | 1334 | touch_move_grab_down(struct weston_touch_grab *grab, uint32_t time, |
| 1335 | int touch_id, wl_fixed_t sx, wl_fixed_t sy) |
| 1336 | { |
| 1337 | } |
| 1338 | |
| 1339 | static void |
| 1340 | touch_move_grab_up(struct weston_touch_grab *grab, uint32_t time, int touch_id) |
| 1341 | { |
Jonas Ådahl | 1c6e63e | 2013-10-25 23:18:04 +0200 | [diff] [blame] | 1342 | struct weston_touch_move_grab *move = |
| 1343 | (struct weston_touch_move_grab *) container_of( |
| 1344 | grab, struct shell_touch_grab, grab); |
Neil Roberts | e14aa4f | 2013-10-03 16:43:07 +0100 | [diff] [blame] | 1345 | |
Kristian Høgsberg | 8e80a31 | 2014-01-17 15:18:10 -0800 | [diff] [blame] | 1346 | if (touch_id == 0) |
| 1347 | move->active = 0; |
| 1348 | |
Jonas Ådahl | 9484b69 | 2013-12-02 22:05:03 +0100 | [diff] [blame] | 1349 | if (grab->touch->num_tp == 0) { |
Jonas Ådahl | 1c6e63e | 2013-10-25 23:18:04 +0200 | [diff] [blame] | 1350 | shell_touch_grab_end(&move->base); |
| 1351 | free(move); |
| 1352 | } |
Rusty Lynch | 1084da5 | 2013-08-15 09:10:08 -0700 | [diff] [blame] | 1353 | } |
| 1354 | |
| 1355 | static void |
| 1356 | touch_move_grab_motion(struct weston_touch_grab *grab, uint32_t time, |
| 1357 | int touch_id, wl_fixed_t sx, wl_fixed_t sy) |
| 1358 | { |
| 1359 | struct weston_touch_move_grab *move = (struct weston_touch_move_grab *) grab; |
| 1360 | struct shell_surface *shsurf = move->base.shsurf; |
| 1361 | struct weston_surface *es; |
| 1362 | int dx = wl_fixed_to_int(grab->touch->grab_x + move->dx); |
| 1363 | int dy = wl_fixed_to_int(grab->touch->grab_y + move->dy); |
| 1364 | |
Kristian Høgsberg | 8e80a31 | 2014-01-17 15:18:10 -0800 | [diff] [blame] | 1365 | if (!shsurf || !move->active) |
Rusty Lynch | 1084da5 | 2013-08-15 09:10:08 -0700 | [diff] [blame] | 1366 | return; |
| 1367 | |
| 1368 | es = shsurf->surface; |
| 1369 | |
Jason Ekstrand | 918f2dd | 2013-12-02 21:01:53 -0600 | [diff] [blame] | 1370 | weston_view_set_position(shsurf->view, dx, dy); |
Rusty Lynch | 1084da5 | 2013-08-15 09:10:08 -0700 | [diff] [blame] | 1371 | |
| 1372 | weston_compositor_schedule_repaint(es->compositor); |
| 1373 | } |
| 1374 | |
Jonas Ådahl | 1ea343e | 2013-10-25 23:18:05 +0200 | [diff] [blame] | 1375 | static void |
| 1376 | touch_move_grab_cancel(struct weston_touch_grab *grab) |
| 1377 | { |
| 1378 | struct weston_touch_move_grab *move = |
| 1379 | (struct weston_touch_move_grab *) container_of( |
| 1380 | grab, struct shell_touch_grab, grab); |
| 1381 | |
| 1382 | shell_touch_grab_end(&move->base); |
| 1383 | free(move); |
| 1384 | } |
| 1385 | |
Rusty Lynch | 1084da5 | 2013-08-15 09:10:08 -0700 | [diff] [blame] | 1386 | static const struct weston_touch_grab_interface touch_move_grab_interface = { |
| 1387 | touch_move_grab_down, |
| 1388 | touch_move_grab_up, |
| 1389 | touch_move_grab_motion, |
Jonas Ådahl | 1ea343e | 2013-10-25 23:18:05 +0200 | [diff] [blame] | 1390 | touch_move_grab_cancel, |
Rusty Lynch | 1084da5 | 2013-08-15 09:10:08 -0700 | [diff] [blame] | 1391 | }; |
| 1392 | |
| 1393 | static int |
| 1394 | surface_touch_move(struct shell_surface *shsurf, struct weston_seat *seat) |
| 1395 | { |
| 1396 | struct weston_touch_move_grab *move; |
| 1397 | |
| 1398 | if (!shsurf) |
| 1399 | return -1; |
| 1400 | |
Rafael Antognolli | 03b1659 | 2013-12-03 15:35:42 -0200 | [diff] [blame] | 1401 | if (shsurf->state.fullscreen) |
Rusty Lynch | 1084da5 | 2013-08-15 09:10:08 -0700 | [diff] [blame] | 1402 | return 0; |
Kristian Høgsberg | c85f1d4 | 2013-10-24 16:52:00 -0700 | [diff] [blame] | 1403 | if (shsurf->grabbed) |
| 1404 | return 0; |
Rusty Lynch | 1084da5 | 2013-08-15 09:10:08 -0700 | [diff] [blame] | 1405 | |
| 1406 | move = malloc(sizeof *move); |
| 1407 | if (!move) |
| 1408 | return -1; |
| 1409 | |
Kristian Høgsberg | 8e80a31 | 2014-01-17 15:18:10 -0800 | [diff] [blame] | 1410 | move->active = 1; |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 1411 | move->dx = wl_fixed_from_double(shsurf->view->geometry.x) - |
Rusty Lynch | 1084da5 | 2013-08-15 09:10:08 -0700 | [diff] [blame] | 1412 | seat->touch->grab_x; |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 1413 | move->dy = wl_fixed_from_double(shsurf->view->geometry.y) - |
Rusty Lynch | 1084da5 | 2013-08-15 09:10:08 -0700 | [diff] [blame] | 1414 | seat->touch->grab_y; |
| 1415 | |
| 1416 | shell_touch_grab_start(&move->base, &touch_move_grab_interface, shsurf, |
| 1417 | seat->touch); |
| 1418 | |
| 1419 | return 0; |
| 1420 | } |
| 1421 | |
| 1422 | static void |
Kristian Høgsberg | 6848c25 | 2013-05-08 22:02:59 -0400 | [diff] [blame] | 1423 | noop_grab_focus(struct weston_pointer_grab *grab) |
Kristian Høgsberg | 9ddb826 | 2012-01-04 21:30:29 -0500 | [diff] [blame] | 1424 | { |
Kristian Høgsberg | 9ddb826 | 2012-01-04 21:30:29 -0500 | [diff] [blame] | 1425 | } |
| 1426 | |
| 1427 | static void |
Giulio Camuffo | 1959ab8 | 2013-11-14 23:42:52 +0100 | [diff] [blame] | 1428 | move_grab_motion(struct weston_pointer_grab *grab, uint32_t time, |
| 1429 | wl_fixed_t x, wl_fixed_t y) |
Kristian Høgsberg | 4cca349 | 2011-01-18 07:53:49 -0500 | [diff] [blame] | 1430 | { |
Kristian Høgsberg | 8334bc1 | 2012-01-03 10:29:47 -0500 | [diff] [blame] | 1431 | struct weston_move_grab *move = (struct weston_move_grab *) grab; |
Kristian Høgsberg | 02bbabb | 2013-05-06 22:15:05 -0400 | [diff] [blame] | 1432 | struct weston_pointer *pointer = grab->pointer; |
Ander Conselvan de Oliveira | fe0444a | 2012-04-04 17:48:05 +0300 | [diff] [blame] | 1433 | struct shell_surface *shsurf = move->base.shsurf; |
Giulio Camuffo | 1959ab8 | 2013-11-14 23:42:52 +0100 | [diff] [blame] | 1434 | int dx, dy; |
| 1435 | |
| 1436 | weston_pointer_move(pointer, x, y); |
| 1437 | dx = wl_fixed_to_int(pointer->x + move->dx); |
| 1438 | dy = wl_fixed_to_int(pointer->y + move->dy); |
Ander Conselvan de Oliveira | fe0444a | 2012-04-04 17:48:05 +0300 | [diff] [blame] | 1439 | |
| 1440 | if (!shsurf) |
| 1441 | return; |
| 1442 | |
Jason Ekstrand | 918f2dd | 2013-12-02 21:01:53 -0600 | [diff] [blame] | 1443 | weston_view_set_position(shsurf->view, dx, dy); |
Kristian Høgsberg | 4cca349 | 2011-01-18 07:53:49 -0500 | [diff] [blame] | 1444 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 1445 | weston_compositor_schedule_repaint(shsurf->surface->compositor); |
Kristian Høgsberg | 4cca349 | 2011-01-18 07:53:49 -0500 | [diff] [blame] | 1446 | } |
| 1447 | |
| 1448 | static void |
Kristian Høgsberg | 02bbabb | 2013-05-06 22:15:05 -0400 | [diff] [blame] | 1449 | move_grab_button(struct weston_pointer_grab *grab, |
Daniel Stone | 4dbadb1 | 2012-05-30 16:31:51 +0100 | [diff] [blame] | 1450 | uint32_t time, uint32_t button, uint32_t state_w) |
Kristian Høgsberg | 4cca349 | 2011-01-18 07:53:49 -0500 | [diff] [blame] | 1451 | { |
Ander Conselvan de Oliveira | fe0444a | 2012-04-04 17:48:05 +0300 | [diff] [blame] | 1452 | struct shell_grab *shell_grab = container_of(grab, struct shell_grab, |
| 1453 | grab); |
Kristian Høgsberg | 02bbabb | 2013-05-06 22:15:05 -0400 | [diff] [blame] | 1454 | struct weston_pointer *pointer = grab->pointer; |
Daniel Stone | 4dbadb1 | 2012-05-30 16:31:51 +0100 | [diff] [blame] | 1455 | enum wl_pointer_button_state state = state_w; |
Kristian Høgsberg | 4cca349 | 2011-01-18 07:53:49 -0500 | [diff] [blame] | 1456 | |
Daniel Stone | 4dbadb1 | 2012-05-30 16:31:51 +0100 | [diff] [blame] | 1457 | if (pointer->button_count == 0 && |
| 1458 | state == WL_POINTER_BUTTON_STATE_RELEASED) { |
Ander Conselvan de Oliveira | b9d2a0f | 2012-06-28 18:08:05 +0300 | [diff] [blame] | 1459 | shell_grab_end(shell_grab); |
Kristian Høgsberg | 9ddb826 | 2012-01-04 21:30:29 -0500 | [diff] [blame] | 1460 | free(grab); |
| 1461 | } |
Kristian Høgsberg | 4cca349 | 2011-01-18 07:53:49 -0500 | [diff] [blame] | 1462 | } |
| 1463 | |
Jonas Ådahl | 1ea343e | 2013-10-25 23:18:05 +0200 | [diff] [blame] | 1464 | static void |
| 1465 | move_grab_cancel(struct weston_pointer_grab *grab) |
| 1466 | { |
| 1467 | struct shell_grab *shell_grab = |
| 1468 | container_of(grab, struct shell_grab, grab); |
| 1469 | |
| 1470 | shell_grab_end(shell_grab); |
| 1471 | free(grab); |
| 1472 | } |
| 1473 | |
Kristian Høgsberg | 02bbabb | 2013-05-06 22:15:05 -0400 | [diff] [blame] | 1474 | static const struct weston_pointer_grab_interface move_grab_interface = { |
Kristian Høgsberg | 9ddb826 | 2012-01-04 21:30:29 -0500 | [diff] [blame] | 1475 | noop_grab_focus, |
Kristian Høgsberg | 4cca349 | 2011-01-18 07:53:49 -0500 | [diff] [blame] | 1476 | move_grab_motion, |
| 1477 | move_grab_button, |
Jonas Ådahl | 1ea343e | 2013-10-25 23:18:05 +0200 | [diff] [blame] | 1478 | move_grab_cancel, |
Kristian Høgsberg | 4cca349 | 2011-01-18 07:53:49 -0500 | [diff] [blame] | 1479 | }; |
| 1480 | |
Kristian Høgsberg | 9e31bff | 2012-08-01 00:08:07 -0400 | [diff] [blame] | 1481 | static int |
Kristian Høgsberg | e314875 | 2013-05-06 23:19:49 -0400 | [diff] [blame] | 1482 | surface_move(struct shell_surface *shsurf, struct weston_seat *seat) |
Kristian Høgsberg | 9e31bff | 2012-08-01 00:08:07 -0400 | [diff] [blame] | 1483 | { |
| 1484 | struct weston_move_grab *move; |
| 1485 | |
| 1486 | if (!shsurf) |
| 1487 | return -1; |
| 1488 | |
Kristian Høgsberg | c85f1d4 | 2013-10-24 16:52:00 -0700 | [diff] [blame] | 1489 | if (shsurf->grabbed) |
| 1490 | return 0; |
Ricardo Vieira | f1c3bd8 | 2014-01-18 16:30:50 +0000 | [diff] [blame] | 1491 | if (shsurf->state.fullscreen || shsurf->state.maximized) |
Kristian Høgsberg | 9e31bff | 2012-08-01 00:08:07 -0400 | [diff] [blame] | 1492 | return 0; |
| 1493 | |
| 1494 | move = malloc(sizeof *move); |
| 1495 | if (!move) |
| 1496 | return -1; |
| 1497 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 1498 | move->dx = wl_fixed_from_double(shsurf->view->geometry.x) - |
Kristian Høgsberg | e314875 | 2013-05-06 23:19:49 -0400 | [diff] [blame] | 1499 | seat->pointer->grab_x; |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 1500 | move->dy = wl_fixed_from_double(shsurf->view->geometry.y) - |
Kristian Høgsberg | e314875 | 2013-05-06 23:19:49 -0400 | [diff] [blame] | 1501 | seat->pointer->grab_y; |
Kristian Høgsberg | 9e31bff | 2012-08-01 00:08:07 -0400 | [diff] [blame] | 1502 | |
| 1503 | shell_grab_start(&move->base, &move_grab_interface, shsurf, |
Kristian Høgsberg | e314875 | 2013-05-06 23:19:49 -0400 | [diff] [blame] | 1504 | seat->pointer, DESKTOP_SHELL_CURSOR_MOVE); |
Kristian Høgsberg | 9e31bff | 2012-08-01 00:08:07 -0400 | [diff] [blame] | 1505 | |
| 1506 | return 0; |
| 1507 | } |
| 1508 | |
| 1509 | static void |
Rafael Antognolli | e2a3455 | 2013-12-03 15:35:45 -0200 | [diff] [blame] | 1510 | common_surface_move(struct wl_resource *resource, |
| 1511 | struct wl_resource *seat_resource, uint32_t serial) |
Kristian Høgsberg | 9e31bff | 2012-08-01 00:08:07 -0400 | [diff] [blame] | 1512 | { |
Jason Ekstrand | 44a3863 | 2013-06-14 10:08:00 -0500 | [diff] [blame] | 1513 | struct weston_seat *seat = wl_resource_get_user_data(seat_resource); |
Jason Ekstrand | 651f00e | 2013-06-14 10:07:54 -0500 | [diff] [blame] | 1514 | struct shell_surface *shsurf = wl_resource_get_user_data(resource); |
Giulio Camuffo | 61da3fc | 2013-04-25 13:57:45 +0300 | [diff] [blame] | 1515 | struct weston_surface *surface; |
Kristian Høgsberg | 9e31bff | 2012-08-01 00:08:07 -0400 | [diff] [blame] | 1516 | |
Kristian Høgsberg | e1b655d | 2013-08-28 23:16:20 -0700 | [diff] [blame] | 1517 | if (seat->pointer && |
Kristian Høgsberg | 70f2901 | 2014-01-09 15:43:17 -0800 | [diff] [blame] | 1518 | seat->pointer->focus && |
Kristian Høgsberg | e1b655d | 2013-08-28 23:16:20 -0700 | [diff] [blame] | 1519 | seat->pointer->button_count > 0 && |
| 1520 | seat->pointer->grab_serial == serial) { |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 1521 | surface = weston_surface_get_main_surface(seat->pointer->focus->surface); |
U. Artie Eoff | cf5737a | 2014-01-17 10:08:25 -0800 | [diff] [blame] | 1522 | if ((surface == shsurf->surface) && |
Rusty Lynch | 1084da5 | 2013-08-15 09:10:08 -0700 | [diff] [blame] | 1523 | (surface_move(shsurf, seat) < 0)) |
| 1524 | wl_resource_post_no_memory(resource); |
Kristian Høgsberg | e1b655d | 2013-08-28 23:16:20 -0700 | [diff] [blame] | 1525 | } else if (seat->touch && |
Kristian Høgsberg | 70f2901 | 2014-01-09 15:43:17 -0800 | [diff] [blame] | 1526 | seat->touch->focus && |
Kristian Høgsberg | e1b655d | 2013-08-28 23:16:20 -0700 | [diff] [blame] | 1527 | seat->touch->grab_serial == serial) { |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 1528 | surface = weston_surface_get_main_surface(seat->touch->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_touch_move(shsurf, seat) < 0)) |
| 1531 | wl_resource_post_no_memory(resource); |
| 1532 | } |
Kristian Høgsberg | 9e31bff | 2012-08-01 00:08:07 -0400 | [diff] [blame] | 1533 | } |
| 1534 | |
Rafael Antognolli | e2a3455 | 2013-12-03 15:35:45 -0200 | [diff] [blame] | 1535 | static void |
| 1536 | shell_surface_move(struct wl_client *client, struct wl_resource *resource, |
| 1537 | struct wl_resource *seat_resource, uint32_t serial) |
| 1538 | { |
| 1539 | common_surface_move(resource, seat_resource, serial); |
| 1540 | } |
| 1541 | |
Kristian Høgsberg | 9e31bff | 2012-08-01 00:08:07 -0400 | [diff] [blame] | 1542 | struct weston_resize_grab { |
| 1543 | struct shell_grab base; |
| 1544 | uint32_t edges; |
| 1545 | int32_t width, height; |
| 1546 | }; |
| 1547 | |
| 1548 | static void |
Giulio Camuffo | 1959ab8 | 2013-11-14 23:42:52 +0100 | [diff] [blame] | 1549 | resize_grab_motion(struct weston_pointer_grab *grab, uint32_t time, |
| 1550 | wl_fixed_t x, wl_fixed_t y) |
Kristian Høgsberg | 9e31bff | 2012-08-01 00:08:07 -0400 | [diff] [blame] | 1551 | { |
| 1552 | struct weston_resize_grab *resize = (struct weston_resize_grab *) grab; |
Kristian Høgsberg | 02bbabb | 2013-05-06 22:15:05 -0400 | [diff] [blame] | 1553 | struct weston_pointer *pointer = grab->pointer; |
Kristian Høgsberg | 9e31bff | 2012-08-01 00:08:07 -0400 | [diff] [blame] | 1554 | struct shell_surface *shsurf = resize->base.shsurf; |
| 1555 | int32_t width, height; |
| 1556 | wl_fixed_t from_x, from_y; |
| 1557 | wl_fixed_t to_x, to_y; |
| 1558 | |
Giulio Camuffo | 1959ab8 | 2013-11-14 23:42:52 +0100 | [diff] [blame] | 1559 | weston_pointer_move(pointer, x, y); |
| 1560 | |
Kristian Høgsberg | 9e31bff | 2012-08-01 00:08:07 -0400 | [diff] [blame] | 1561 | if (!shsurf) |
| 1562 | return; |
| 1563 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 1564 | weston_view_from_global_fixed(shsurf->view, |
| 1565 | pointer->grab_x, pointer->grab_y, |
| 1566 | &from_x, &from_y); |
| 1567 | weston_view_from_global_fixed(shsurf->view, |
| 1568 | pointer->x, pointer->y, &to_x, &to_y); |
Kristian Høgsberg | 9e31bff | 2012-08-01 00:08:07 -0400 | [diff] [blame] | 1569 | |
| 1570 | width = resize->width; |
| 1571 | if (resize->edges & WL_SHELL_SURFACE_RESIZE_LEFT) { |
| 1572 | width += wl_fixed_to_int(from_x - to_x); |
| 1573 | } else if (resize->edges & WL_SHELL_SURFACE_RESIZE_RIGHT) { |
| 1574 | width += wl_fixed_to_int(to_x - from_x); |
| 1575 | } |
| 1576 | |
| 1577 | height = resize->height; |
| 1578 | if (resize->edges & WL_SHELL_SURFACE_RESIZE_TOP) { |
| 1579 | height += wl_fixed_to_int(from_y - to_y); |
| 1580 | } else if (resize->edges & WL_SHELL_SURFACE_RESIZE_BOTTOM) { |
| 1581 | height += wl_fixed_to_int(to_y - from_y); |
| 1582 | } |
| 1583 | |
| 1584 | shsurf->client->send_configure(shsurf->surface, |
| 1585 | resize->edges, width, height); |
| 1586 | } |
| 1587 | |
| 1588 | static void |
| 1589 | send_configure(struct weston_surface *surface, |
| 1590 | uint32_t edges, int32_t width, int32_t height) |
| 1591 | { |
| 1592 | struct shell_surface *shsurf = get_shell_surface(surface); |
| 1593 | |
U. Artie Eoff | cf5737a | 2014-01-17 10:08:25 -0800 | [diff] [blame] | 1594 | assert(shsurf); |
| 1595 | |
Jason Ekstrand | 651f00e | 2013-06-14 10:07:54 -0500 | [diff] [blame] | 1596 | wl_shell_surface_send_configure(shsurf->resource, |
Kristian Høgsberg | 9e31bff | 2012-08-01 00:08:07 -0400 | [diff] [blame] | 1597 | edges, width, height); |
| 1598 | } |
| 1599 | |
| 1600 | static const struct weston_shell_client shell_client = { |
| 1601 | send_configure |
| 1602 | }; |
| 1603 | |
| 1604 | static void |
Kristian Høgsberg | 02bbabb | 2013-05-06 22:15:05 -0400 | [diff] [blame] | 1605 | resize_grab_button(struct weston_pointer_grab *grab, |
Kristian Høgsberg | 9e31bff | 2012-08-01 00:08:07 -0400 | [diff] [blame] | 1606 | uint32_t time, uint32_t button, uint32_t state_w) |
| 1607 | { |
| 1608 | struct weston_resize_grab *resize = (struct weston_resize_grab *) grab; |
Kristian Høgsberg | 02bbabb | 2013-05-06 22:15:05 -0400 | [diff] [blame] | 1609 | struct weston_pointer *pointer = grab->pointer; |
Kristian Høgsberg | 9e31bff | 2012-08-01 00:08:07 -0400 | [diff] [blame] | 1610 | enum wl_pointer_button_state state = state_w; |
| 1611 | |
| 1612 | if (pointer->button_count == 0 && |
| 1613 | state == WL_POINTER_BUTTON_STATE_RELEASED) { |
| 1614 | shell_grab_end(&resize->base); |
| 1615 | free(grab); |
| 1616 | } |
| 1617 | } |
| 1618 | |
Jonas Ådahl | 1ea343e | 2013-10-25 23:18:05 +0200 | [diff] [blame] | 1619 | static void |
| 1620 | resize_grab_cancel(struct weston_pointer_grab *grab) |
| 1621 | { |
| 1622 | struct weston_resize_grab *resize = (struct weston_resize_grab *) grab; |
| 1623 | |
| 1624 | shell_grab_end(&resize->base); |
| 1625 | free(grab); |
| 1626 | } |
| 1627 | |
Kristian Høgsberg | 02bbabb | 2013-05-06 22:15:05 -0400 | [diff] [blame] | 1628 | static const struct weston_pointer_grab_interface resize_grab_interface = { |
Kristian Høgsberg | 9e31bff | 2012-08-01 00:08:07 -0400 | [diff] [blame] | 1629 | noop_grab_focus, |
| 1630 | resize_grab_motion, |
| 1631 | resize_grab_button, |
Jonas Ådahl | 1ea343e | 2013-10-25 23:18:05 +0200 | [diff] [blame] | 1632 | resize_grab_cancel, |
Kristian Høgsberg | 9e31bff | 2012-08-01 00:08:07 -0400 | [diff] [blame] | 1633 | }; |
| 1634 | |
Giulio Camuffo | b836664 | 2013-04-25 13:57:46 +0300 | [diff] [blame] | 1635 | /* |
| 1636 | * Returns the bounding box of a surface and all its sub-surfaces, |
| 1637 | * in the surface coordinates system. */ |
| 1638 | static void |
| 1639 | surface_subsurfaces_boundingbox(struct weston_surface *surface, int32_t *x, |
| 1640 | int32_t *y, int32_t *w, int32_t *h) { |
| 1641 | pixman_region32_t region; |
| 1642 | pixman_box32_t *box; |
| 1643 | struct weston_subsurface *subsurface; |
| 1644 | |
| 1645 | pixman_region32_init_rect(®ion, 0, 0, |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 1646 | surface->width, |
| 1647 | surface->height); |
Giulio Camuffo | b836664 | 2013-04-25 13:57:46 +0300 | [diff] [blame] | 1648 | |
| 1649 | wl_list_for_each(subsurface, &surface->subsurface_list, parent_link) { |
| 1650 | pixman_region32_union_rect(®ion, ®ion, |
| 1651 | subsurface->position.x, |
| 1652 | subsurface->position.y, |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 1653 | subsurface->surface->width, |
| 1654 | subsurface->surface->height); |
Giulio Camuffo | b836664 | 2013-04-25 13:57:46 +0300 | [diff] [blame] | 1655 | } |
| 1656 | |
| 1657 | box = pixman_region32_extents(®ion); |
| 1658 | if (x) |
| 1659 | *x = box->x1; |
| 1660 | if (y) |
| 1661 | *y = box->y1; |
| 1662 | if (w) |
| 1663 | *w = box->x2 - box->x1; |
| 1664 | if (h) |
| 1665 | *h = box->y2 - box->y1; |
| 1666 | |
| 1667 | pixman_region32_fini(®ion); |
| 1668 | } |
| 1669 | |
Kristian Høgsberg | 9e31bff | 2012-08-01 00:08:07 -0400 | [diff] [blame] | 1670 | static int |
| 1671 | surface_resize(struct shell_surface *shsurf, |
Kristian Høgsberg | e314875 | 2013-05-06 23:19:49 -0400 | [diff] [blame] | 1672 | struct weston_seat *seat, uint32_t edges) |
Kristian Høgsberg | 9e31bff | 2012-08-01 00:08:07 -0400 | [diff] [blame] | 1673 | { |
| 1674 | struct weston_resize_grab *resize; |
| 1675 | |
Rafael Antognolli | 03b1659 | 2013-12-03 15:35:42 -0200 | [diff] [blame] | 1676 | if (shsurf->state.fullscreen || shsurf->state.maximized) |
Kristian Høgsberg | 9e31bff | 2012-08-01 00:08:07 -0400 | [diff] [blame] | 1677 | return 0; |
| 1678 | |
| 1679 | if (edges == 0 || edges > 15 || |
| 1680 | (edges & 3) == 3 || (edges & 12) == 12) |
| 1681 | return 0; |
| 1682 | |
| 1683 | resize = malloc(sizeof *resize); |
| 1684 | if (!resize) |
| 1685 | return -1; |
| 1686 | |
| 1687 | resize->edges = edges; |
Giulio Camuffo | b836664 | 2013-04-25 13:57:46 +0300 | [diff] [blame] | 1688 | surface_subsurfaces_boundingbox(shsurf->surface, NULL, NULL, |
| 1689 | &resize->width, &resize->height); |
Kristian Høgsberg | 9e31bff | 2012-08-01 00:08:07 -0400 | [diff] [blame] | 1690 | |
| 1691 | shell_grab_start(&resize->base, &resize_grab_interface, shsurf, |
Kristian Høgsberg | e314875 | 2013-05-06 23:19:49 -0400 | [diff] [blame] | 1692 | seat->pointer, edges); |
Kristian Høgsberg | 9e31bff | 2012-08-01 00:08:07 -0400 | [diff] [blame] | 1693 | |
| 1694 | return 0; |
| 1695 | } |
| 1696 | |
| 1697 | static void |
Rafael Antognolli | e2a3455 | 2013-12-03 15:35:45 -0200 | [diff] [blame] | 1698 | common_surface_resize(struct wl_resource *resource, |
| 1699 | struct wl_resource *seat_resource, uint32_t serial, |
| 1700 | uint32_t edges) |
Kristian Høgsberg | 9e31bff | 2012-08-01 00:08:07 -0400 | [diff] [blame] | 1701 | { |
Jason Ekstrand | 44a3863 | 2013-06-14 10:08:00 -0500 | [diff] [blame] | 1702 | struct weston_seat *seat = wl_resource_get_user_data(seat_resource); |
Jason Ekstrand | 651f00e | 2013-06-14 10:07:54 -0500 | [diff] [blame] | 1703 | struct shell_surface *shsurf = wl_resource_get_user_data(resource); |
Giulio Camuffo | 61da3fc | 2013-04-25 13:57:45 +0300 | [diff] [blame] | 1704 | struct weston_surface *surface; |
Kristian Høgsberg | 9e31bff | 2012-08-01 00:08:07 -0400 | [diff] [blame] | 1705 | |
Rafael Antognolli | 03b1659 | 2013-12-03 15:35:42 -0200 | [diff] [blame] | 1706 | if (shsurf->state.fullscreen) |
Kristian Høgsberg | 9e31bff | 2012-08-01 00:08:07 -0400 | [diff] [blame] | 1707 | return; |
| 1708 | |
Kristian Høgsberg | e314875 | 2013-05-06 23:19:49 -0400 | [diff] [blame] | 1709 | if (seat->pointer->button_count == 0 || |
| 1710 | seat->pointer->grab_serial != serial || |
Kristian Høgsberg | 70f2901 | 2014-01-09 15:43:17 -0800 | [diff] [blame] | 1711 | seat->pointer->focus == NULL) |
| 1712 | return; |
| 1713 | |
| 1714 | surface = weston_surface_get_main_surface(seat->pointer->focus->surface); |
| 1715 | if (surface != shsurf->surface) |
Kristian Høgsberg | 9e31bff | 2012-08-01 00:08:07 -0400 | [diff] [blame] | 1716 | return; |
| 1717 | |
Kristian Høgsberg | e314875 | 2013-05-06 23:19:49 -0400 | [diff] [blame] | 1718 | if (surface_resize(shsurf, seat, edges) < 0) |
Kristian Høgsberg | 9e31bff | 2012-08-01 00:08:07 -0400 | [diff] [blame] | 1719 | wl_resource_post_no_memory(resource); |
| 1720 | } |
| 1721 | |
Scott Moreau | c3e54eb | 2012-04-17 19:06:20 -0600 | [diff] [blame] | 1722 | static void |
Rafael Antognolli | e2a3455 | 2013-12-03 15:35:45 -0200 | [diff] [blame] | 1723 | shell_surface_resize(struct wl_client *client, struct wl_resource *resource, |
| 1724 | struct wl_resource *seat_resource, uint32_t serial, |
| 1725 | uint32_t edges) |
| 1726 | { |
| 1727 | common_surface_resize(resource, seat_resource, serial, edges); |
| 1728 | } |
| 1729 | |
| 1730 | static void |
Kristian Høgsberg | 6780073 | 2013-07-04 01:12:17 -0400 | [diff] [blame] | 1731 | end_busy_cursor(struct shell_surface *shsurf, struct weston_pointer *pointer); |
| 1732 | |
| 1733 | static void |
Kristian Høgsberg | 6848c25 | 2013-05-08 22:02:59 -0400 | [diff] [blame] | 1734 | busy_cursor_grab_focus(struct weston_pointer_grab *base) |
Scott Moreau | c3e54eb | 2012-04-17 19:06:20 -0600 | [diff] [blame] | 1735 | { |
Kristian Høgsberg | d56bd90 | 2012-06-05 09:58:51 -0400 | [diff] [blame] | 1736 | struct shell_grab *grab = (struct shell_grab *) base; |
Kristian Høgsberg | 6848c25 | 2013-05-08 22:02:59 -0400 | [diff] [blame] | 1737 | struct weston_pointer *pointer = base->pointer; |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 1738 | struct weston_view *view; |
Kristian Høgsberg | 6848c25 | 2013-05-08 22:02:59 -0400 | [diff] [blame] | 1739 | wl_fixed_t sx, sy; |
| 1740 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 1741 | view = weston_compositor_pick_view(pointer->seat->compositor, |
| 1742 | pointer->x, pointer->y, |
| 1743 | &sx, &sy); |
Scott Moreau | c3e54eb | 2012-04-17 19:06:20 -0600 | [diff] [blame] | 1744 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 1745 | if (!grab->shsurf || grab->shsurf->surface != view->surface) |
Kristian Høgsberg | 6780073 | 2013-07-04 01:12:17 -0400 | [diff] [blame] | 1746 | end_busy_cursor(grab->shsurf, pointer); |
Scott Moreau | c3e54eb | 2012-04-17 19:06:20 -0600 | [diff] [blame] | 1747 | } |
| 1748 | |
| 1749 | static void |
Giulio Camuffo | 1959ab8 | 2013-11-14 23:42:52 +0100 | [diff] [blame] | 1750 | busy_cursor_grab_motion(struct weston_pointer_grab *grab, uint32_t time, |
| 1751 | wl_fixed_t x, wl_fixed_t y) |
Scott Moreau | c3e54eb | 2012-04-17 19:06:20 -0600 | [diff] [blame] | 1752 | { |
Giulio Camuffo | 1959ab8 | 2013-11-14 23:42:52 +0100 | [diff] [blame] | 1753 | weston_pointer_move(grab->pointer, x, y); |
Kristian Høgsberg | d56bd90 | 2012-06-05 09:58:51 -0400 | [diff] [blame] | 1754 | } |
Scott Moreau | c3e54eb | 2012-04-17 19:06:20 -0600 | [diff] [blame] | 1755 | |
Kristian Høgsberg | d56bd90 | 2012-06-05 09:58:51 -0400 | [diff] [blame] | 1756 | static void |
Kristian Høgsberg | 02bbabb | 2013-05-06 22:15:05 -0400 | [diff] [blame] | 1757 | busy_cursor_grab_button(struct weston_pointer_grab *base, |
Kristian Høgsberg | d56bd90 | 2012-06-05 09:58:51 -0400 | [diff] [blame] | 1758 | uint32_t time, uint32_t button, uint32_t state) |
| 1759 | { |
Kristian Høgsberg | bbe9839 | 2012-08-01 00:20:21 -0400 | [diff] [blame] | 1760 | struct shell_grab *grab = (struct shell_grab *) base; |
Kristian Høgsberg | e122b7b | 2013-05-08 16:47:00 -0400 | [diff] [blame] | 1761 | struct shell_surface *shsurf = grab->shsurf; |
Kristian Høgsberg | e314875 | 2013-05-06 23:19:49 -0400 | [diff] [blame] | 1762 | struct weston_seat *seat = grab->grab.pointer->seat; |
Kristian Høgsberg | bbe9839 | 2012-08-01 00:20:21 -0400 | [diff] [blame] | 1763 | |
Kristian Høgsberg | bbe9839 | 2012-08-01 00:20:21 -0400 | [diff] [blame] | 1764 | if (shsurf && button == BTN_LEFT && state) { |
| 1765 | activate(shsurf->shell, shsurf->surface, seat); |
| 1766 | surface_move(shsurf, seat); |
Kristian Høgsberg | 0c36903 | 2013-02-14 21:31:44 -0500 | [diff] [blame] | 1767 | } else if (shsurf && button == BTN_RIGHT && state) { |
| 1768 | activate(shsurf->shell, shsurf->surface, seat); |
Kristian Høgsberg | e314875 | 2013-05-06 23:19:49 -0400 | [diff] [blame] | 1769 | surface_rotate(shsurf, seat); |
Kristian Høgsberg | bbe9839 | 2012-08-01 00:20:21 -0400 | [diff] [blame] | 1770 | } |
Kristian Høgsberg | d56bd90 | 2012-06-05 09:58:51 -0400 | [diff] [blame] | 1771 | } |
| 1772 | |
Jonas Ådahl | 1ea343e | 2013-10-25 23:18:05 +0200 | [diff] [blame] | 1773 | static void |
| 1774 | busy_cursor_grab_cancel(struct weston_pointer_grab *base) |
| 1775 | { |
| 1776 | struct shell_grab *grab = (struct shell_grab *) base; |
| 1777 | |
| 1778 | shell_grab_end(grab); |
| 1779 | free(grab); |
| 1780 | } |
| 1781 | |
Kristian Høgsberg | 02bbabb | 2013-05-06 22:15:05 -0400 | [diff] [blame] | 1782 | static const struct weston_pointer_grab_interface busy_cursor_grab_interface = { |
Kristian Høgsberg | d56bd90 | 2012-06-05 09:58:51 -0400 | [diff] [blame] | 1783 | busy_cursor_grab_focus, |
| 1784 | busy_cursor_grab_motion, |
| 1785 | busy_cursor_grab_button, |
Jonas Ådahl | 1ea343e | 2013-10-25 23:18:05 +0200 | [diff] [blame] | 1786 | busy_cursor_grab_cancel, |
Kristian Høgsberg | d56bd90 | 2012-06-05 09:58:51 -0400 | [diff] [blame] | 1787 | }; |
| 1788 | |
| 1789 | static void |
Kristian Høgsberg | 02bbabb | 2013-05-06 22:15:05 -0400 | [diff] [blame] | 1790 | set_busy_cursor(struct shell_surface *shsurf, struct weston_pointer *pointer) |
Kristian Høgsberg | d56bd90 | 2012-06-05 09:58:51 -0400 | [diff] [blame] | 1791 | { |
| 1792 | struct shell_grab *grab; |
Kristian Høgsberg | d56bd90 | 2012-06-05 09:58:51 -0400 | [diff] [blame] | 1793 | |
| 1794 | grab = malloc(sizeof *grab); |
| 1795 | if (!grab) |
Scott Moreau | c3e54eb | 2012-04-17 19:06:20 -0600 | [diff] [blame] | 1796 | return; |
| 1797 | |
Ander Conselvan de Oliveira | b9d2a0f | 2012-06-28 18:08:05 +0300 | [diff] [blame] | 1798 | shell_grab_start(grab, &busy_cursor_grab_interface, shsurf, pointer, |
| 1799 | DESKTOP_SHELL_CURSOR_BUSY); |
Kristian Høgsberg | d56bd90 | 2012-06-05 09:58:51 -0400 | [diff] [blame] | 1800 | } |
Scott Moreau | c3e54eb | 2012-04-17 19:06:20 -0600 | [diff] [blame] | 1801 | |
Kristian Høgsberg | d56bd90 | 2012-06-05 09:58:51 -0400 | [diff] [blame] | 1802 | static void |
Kristian Høgsberg | 02bbabb | 2013-05-06 22:15:05 -0400 | [diff] [blame] | 1803 | end_busy_cursor(struct shell_surface *shsurf, struct weston_pointer *pointer) |
Kristian Høgsberg | d56bd90 | 2012-06-05 09:58:51 -0400 | [diff] [blame] | 1804 | { |
| 1805 | struct shell_grab *grab = (struct shell_grab *) pointer->grab; |
| 1806 | |
Kristian Høgsberg | e122b7b | 2013-05-08 16:47:00 -0400 | [diff] [blame] | 1807 | if (grab->grab.interface == &busy_cursor_grab_interface && |
| 1808 | grab->shsurf == shsurf) { |
Ander Conselvan de Oliveira | b9d2a0f | 2012-06-28 18:08:05 +0300 | [diff] [blame] | 1809 | shell_grab_end(grab); |
Kristian Høgsberg | d56bd90 | 2012-06-05 09:58:51 -0400 | [diff] [blame] | 1810 | free(grab); |
Scott Moreau | c3e54eb | 2012-04-17 19:06:20 -0600 | [diff] [blame] | 1811 | } |
Scott Moreau | c3e54eb | 2012-04-17 19:06:20 -0600 | [diff] [blame] | 1812 | } |
| 1813 | |
Scott Moreau | 9521d5e | 2012-04-19 13:06:17 -0600 | [diff] [blame] | 1814 | static void |
| 1815 | ping_timer_destroy(struct shell_surface *shsurf) |
| 1816 | { |
| 1817 | if (!shsurf || !shsurf->ping_timer) |
| 1818 | return; |
| 1819 | |
| 1820 | if (shsurf->ping_timer->source) |
| 1821 | wl_event_source_remove(shsurf->ping_timer->source); |
| 1822 | |
| 1823 | free(shsurf->ping_timer); |
| 1824 | shsurf->ping_timer = NULL; |
| 1825 | } |
| 1826 | |
Kristian Høgsberg | 97d44aa | 2011-08-26 17:21:20 -0400 | [diff] [blame] | 1827 | static int |
Scott Moreau | ff1db4a | 2012-04-17 19:06:18 -0600 | [diff] [blame] | 1828 | ping_timeout_handler(void *data) |
| 1829 | { |
| 1830 | struct shell_surface *shsurf = data; |
Kristian Høgsberg | d56bd90 | 2012-06-05 09:58:51 -0400 | [diff] [blame] | 1831 | struct weston_seat *seat; |
Scott Moreau | ff1db4a | 2012-04-17 19:06:18 -0600 | [diff] [blame] | 1832 | |
Scott Moreau | 9521d5e | 2012-04-19 13:06:17 -0600 | [diff] [blame] | 1833 | /* Client is not responding */ |
| 1834 | shsurf->unresponsive = 1; |
Kristian Høgsberg | d56bd90 | 2012-06-05 09:58:51 -0400 | [diff] [blame] | 1835 | |
| 1836 | wl_list_for_each(seat, &shsurf->surface->compositor->seat_list, link) |
Kristian Høgsberg | 8fe412d | 2014-01-17 16:39:17 -0800 | [diff] [blame] | 1837 | if (seat->pointer && seat->pointer->focus && |
Emilio Pozuelo Monfort | 3d0fc76 | 2013-11-22 16:21:20 +0100 | [diff] [blame] | 1838 | seat->pointer->focus->surface == shsurf->surface) |
Kristian Høgsberg | e314875 | 2013-05-06 23:19:49 -0400 | [diff] [blame] | 1839 | set_busy_cursor(shsurf, seat->pointer); |
Scott Moreau | ff1db4a | 2012-04-17 19:06:18 -0600 | [diff] [blame] | 1840 | |
| 1841 | return 1; |
| 1842 | } |
| 1843 | |
| 1844 | static void |
| 1845 | ping_handler(struct weston_surface *surface, uint32_t serial) |
| 1846 | { |
Kristian Høgsberg | b71302e | 2012-05-10 12:28:35 -0400 | [diff] [blame] | 1847 | struct shell_surface *shsurf = get_shell_surface(surface); |
Scott Moreau | ff1db4a | 2012-04-17 19:06:18 -0600 | [diff] [blame] | 1848 | struct wl_event_loop *loop; |
Kristian Høgsberg | d56bd90 | 2012-06-05 09:58:51 -0400 | [diff] [blame] | 1849 | int ping_timeout = 200; |
Scott Moreau | ff1db4a | 2012-04-17 19:06:18 -0600 | [diff] [blame] | 1850 | |
| 1851 | if (!shsurf) |
| 1852 | return; |
Jason Ekstrand | 651f00e | 2013-06-14 10:07:54 -0500 | [diff] [blame] | 1853 | if (!shsurf->resource) |
Kristian Høgsberg | ca535c1 | 2012-04-21 23:20:07 -0400 | [diff] [blame] | 1854 | return; |
Scott Moreau | ff1db4a | 2012-04-17 19:06:18 -0600 | [diff] [blame] | 1855 | |
Ander Conselvan de Oliveira | eac9a46 | 2012-07-16 14:15:48 +0300 | [diff] [blame] | 1856 | if (shsurf->surface == shsurf->shell->grab_surface) |
| 1857 | return; |
| 1858 | |
Scott Moreau | ff1db4a | 2012-04-17 19:06:18 -0600 | [diff] [blame] | 1859 | if (!shsurf->ping_timer) { |
Ander Conselvan de Oliveira | fb98089 | 2012-04-27 13:55:55 +0300 | [diff] [blame] | 1860 | shsurf->ping_timer = malloc(sizeof *shsurf->ping_timer); |
Scott Moreau | ff1db4a | 2012-04-17 19:06:18 -0600 | [diff] [blame] | 1861 | if (!shsurf->ping_timer) |
| 1862 | return; |
| 1863 | |
| 1864 | shsurf->ping_timer->serial = serial; |
Scott Moreau | ff1db4a | 2012-04-17 19:06:18 -0600 | [diff] [blame] | 1865 | loop = wl_display_get_event_loop(surface->compositor->wl_display); |
| 1866 | shsurf->ping_timer->source = |
| 1867 | wl_event_loop_add_timer(loop, ping_timeout_handler, shsurf); |
| 1868 | wl_event_source_timer_update(shsurf->ping_timer->source, ping_timeout); |
| 1869 | |
Rafael Antognolli | e2a3455 | 2013-12-03 15:35:45 -0200 | [diff] [blame] | 1870 | if (shell_surface_is_wl_shell_surface(shsurf)) |
| 1871 | wl_shell_surface_send_ping(shsurf->resource, serial); |
| 1872 | else if (shell_surface_is_xdg_surface(shsurf)) |
| 1873 | xdg_surface_send_ping(shsurf->resource, serial); |
| 1874 | else if (shell_surface_is_xdg_popup(shsurf)) |
| 1875 | xdg_popup_send_ping(shsurf->resource, serial); |
Scott Moreau | ff1db4a | 2012-04-17 19:06:18 -0600 | [diff] [blame] | 1876 | } |
| 1877 | } |
| 1878 | |
| 1879 | static void |
Kristian Høgsberg | d56bd90 | 2012-06-05 09:58:51 -0400 | [diff] [blame] | 1880 | handle_pointer_focus(struct wl_listener *listener, void *data) |
| 1881 | { |
Kristian Høgsberg | 02bbabb | 2013-05-06 22:15:05 -0400 | [diff] [blame] | 1882 | struct weston_pointer *pointer = data; |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 1883 | struct weston_view *view = pointer->focus; |
Kristian Høgsberg | d56bd90 | 2012-06-05 09:58:51 -0400 | [diff] [blame] | 1884 | struct weston_compositor *compositor; |
| 1885 | struct shell_surface *shsurf; |
| 1886 | uint32_t serial; |
| 1887 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 1888 | if (!view) |
Kristian Høgsberg | d56bd90 | 2012-06-05 09:58:51 -0400 | [diff] [blame] | 1889 | return; |
| 1890 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 1891 | compositor = view->surface->compositor; |
| 1892 | shsurf = get_shell_surface(view->surface); |
Kristian Høgsberg | d56bd90 | 2012-06-05 09:58:51 -0400 | [diff] [blame] | 1893 | |
Pekka Paalanen | 4e1f2ff | 2012-06-06 16:59:45 +0300 | [diff] [blame] | 1894 | if (shsurf && shsurf->unresponsive) { |
Kristian Høgsberg | d56bd90 | 2012-06-05 09:58:51 -0400 | [diff] [blame] | 1895 | set_busy_cursor(shsurf, pointer); |
| 1896 | } else { |
| 1897 | serial = wl_display_next_serial(compositor->wl_display); |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 1898 | ping_handler(view->surface, serial); |
Kristian Høgsberg | d56bd90 | 2012-06-05 09:58:51 -0400 | [diff] [blame] | 1899 | } |
| 1900 | } |
| 1901 | |
| 1902 | static void |
Kristian Høgsberg | f4d2f23 | 2012-08-10 10:05:39 -0400 | [diff] [blame] | 1903 | create_pointer_focus_listener(struct weston_seat *seat) |
| 1904 | { |
| 1905 | struct wl_listener *listener; |
| 1906 | |
Kristian Høgsberg | e314875 | 2013-05-06 23:19:49 -0400 | [diff] [blame] | 1907 | if (!seat->pointer) |
Kristian Høgsberg | f4d2f23 | 2012-08-10 10:05:39 -0400 | [diff] [blame] | 1908 | return; |
| 1909 | |
| 1910 | listener = malloc(sizeof *listener); |
| 1911 | listener->notify = handle_pointer_focus; |
Kristian Høgsberg | e314875 | 2013-05-06 23:19:49 -0400 | [diff] [blame] | 1912 | wl_signal_add(&seat->pointer->focus_signal, listener); |
Kristian Høgsberg | f4d2f23 | 2012-08-10 10:05:39 -0400 | [diff] [blame] | 1913 | } |
| 1914 | |
| 1915 | static void |
Rafael Antognolli | e2a3455 | 2013-12-03 15:35:45 -0200 | [diff] [blame] | 1916 | xdg_surface_set_transient_for(struct wl_client *client, |
| 1917 | struct wl_resource *resource, |
| 1918 | struct wl_resource *parent_resource) |
Scott Moreau | ff1db4a | 2012-04-17 19:06:18 -0600 | [diff] [blame] | 1919 | { |
Jason Ekstrand | 651f00e | 2013-06-14 10:07:54 -0500 | [diff] [blame] | 1920 | struct shell_surface *shsurf = wl_resource_get_user_data(resource); |
Jasper St. Pierre | 8f180d4 | 2013-12-07 13:49:28 -0500 | [diff] [blame] | 1921 | struct weston_surface *parent; |
| 1922 | |
| 1923 | if (parent_resource) |
| 1924 | parent = wl_resource_get_user_data(parent_resource); |
| 1925 | else |
| 1926 | parent = NULL; |
Rafael Antognolli | e2a3455 | 2013-12-03 15:35:45 -0200 | [diff] [blame] | 1927 | |
| 1928 | shell_surface_set_parent(shsurf, parent); |
| 1929 | } |
| 1930 | |
| 1931 | static void |
| 1932 | surface_pong(struct shell_surface *shsurf, uint32_t serial) |
| 1933 | { |
Kristian Høgsberg | d56bd90 | 2012-06-05 09:58:51 -0400 | [diff] [blame] | 1934 | struct weston_compositor *ec = shsurf->surface->compositor; |
Rafael Antognolli | e2a3455 | 2013-12-03 15:35:45 -0200 | [diff] [blame] | 1935 | struct weston_seat *seat; |
Scott Moreau | ff1db4a | 2012-04-17 19:06:18 -0600 | [diff] [blame] | 1936 | |
Kristian Høgsberg | 92374e1 | 2012-08-11 22:39:12 -0400 | [diff] [blame] | 1937 | if (shsurf->ping_timer == NULL) |
| 1938 | /* Just ignore unsolicited pong. */ |
| 1939 | return; |
| 1940 | |
Scott Moreau | ff1db4a | 2012-04-17 19:06:18 -0600 | [diff] [blame] | 1941 | if (shsurf->ping_timer->serial == serial) { |
Scott Moreau | ff1db4a | 2012-04-17 19:06:18 -0600 | [diff] [blame] | 1942 | shsurf->unresponsive = 0; |
Hardening | eb1e130 | 2013-05-17 18:07:41 +0200 | [diff] [blame] | 1943 | wl_list_for_each(seat, &ec->seat_list, link) { |
| 1944 | if(seat->pointer) |
| 1945 | end_busy_cursor(shsurf, seat->pointer); |
| 1946 | } |
Scott Moreau | 9521d5e | 2012-04-19 13:06:17 -0600 | [diff] [blame] | 1947 | ping_timer_destroy(shsurf); |
Scott Moreau | ff1db4a | 2012-04-17 19:06:18 -0600 | [diff] [blame] | 1948 | } |
| 1949 | } |
| 1950 | |
Kristian Høgsberg | e7afd91 | 2012-05-02 09:47:44 -0400 | [diff] [blame] | 1951 | static void |
Rafael Antognolli | e2a3455 | 2013-12-03 15:35:45 -0200 | [diff] [blame] | 1952 | shell_surface_pong(struct wl_client *client, struct wl_resource *resource, |
| 1953 | uint32_t serial) |
| 1954 | { |
| 1955 | struct shell_surface *shsurf = wl_resource_get_user_data(resource); |
| 1956 | |
| 1957 | surface_pong(shsurf, serial); |
| 1958 | |
| 1959 | } |
| 1960 | |
| 1961 | static void |
Giulio Camuffo | 62942ad | 2013-09-11 18:20:47 +0200 | [diff] [blame] | 1962 | set_title(struct shell_surface *shsurf, const char *title) |
| 1963 | { |
| 1964 | free(shsurf->title); |
| 1965 | shsurf->title = strdup(title); |
| 1966 | } |
| 1967 | |
| 1968 | static void |
Kristian Høgsberg | e7afd91 | 2012-05-02 09:47:44 -0400 | [diff] [blame] | 1969 | shell_surface_set_title(struct wl_client *client, |
| 1970 | struct wl_resource *resource, const char *title) |
| 1971 | { |
Jason Ekstrand | 651f00e | 2013-06-14 10:07:54 -0500 | [diff] [blame] | 1972 | struct shell_surface *shsurf = wl_resource_get_user_data(resource); |
Kristian Høgsberg | e7afd91 | 2012-05-02 09:47:44 -0400 | [diff] [blame] | 1973 | |
Giulio Camuffo | 62942ad | 2013-09-11 18:20:47 +0200 | [diff] [blame] | 1974 | set_title(shsurf, title); |
Kristian Høgsberg | e7afd91 | 2012-05-02 09:47:44 -0400 | [diff] [blame] | 1975 | } |
| 1976 | |
| 1977 | static void |
| 1978 | shell_surface_set_class(struct wl_client *client, |
| 1979 | struct wl_resource *resource, const char *class) |
| 1980 | { |
Jason Ekstrand | 651f00e | 2013-06-14 10:07:54 -0500 | [diff] [blame] | 1981 | struct shell_surface *shsurf = wl_resource_get_user_data(resource); |
Kristian Høgsberg | e7afd91 | 2012-05-02 09:47:44 -0400 | [diff] [blame] | 1982 | |
| 1983 | free(shsurf->class); |
| 1984 | shsurf->class = strdup(class); |
| 1985 | } |
| 1986 | |
Alex Wu | 4539b08 | 2012-03-01 12:57:46 +0800 | [diff] [blame] | 1987 | static void |
Alexander Larsson | f82b6ca | 2013-05-28 16:23:39 +0200 | [diff] [blame] | 1988 | restore_output_mode(struct weston_output *output) |
| 1989 | { |
Hardening | 57388e4 | 2013-09-18 23:56:36 +0200 | [diff] [blame] | 1990 | if (output->current_mode != output->original_mode || |
| 1991 | (int32_t)output->current_scale != output->original_scale) |
Alexander Larsson | f82b6ca | 2013-05-28 16:23:39 +0200 | [diff] [blame] | 1992 | weston_output_switch_mode(output, |
Hardening | 57388e4 | 2013-09-18 23:56:36 +0200 | [diff] [blame] | 1993 | output->original_mode, |
| 1994 | output->original_scale, |
| 1995 | WESTON_MODE_SWITCH_RESTORE_NATIVE); |
Alexander Larsson | f82b6ca | 2013-05-28 16:23:39 +0200 | [diff] [blame] | 1996 | } |
| 1997 | |
| 1998 | static void |
| 1999 | restore_all_output_modes(struct weston_compositor *compositor) |
| 2000 | { |
| 2001 | struct weston_output *output; |
| 2002 | |
| 2003 | wl_list_for_each(output, &compositor->output_list, link) |
| 2004 | restore_output_mode(output); |
| 2005 | } |
| 2006 | |
Philip Withnall | becb77e | 2013-11-25 18:01:30 +0000 | [diff] [blame] | 2007 | static int |
| 2008 | get_output_panel_height(struct desktop_shell *shell, |
| 2009 | struct weston_output *output) |
| 2010 | { |
| 2011 | struct weston_view *view; |
| 2012 | int panel_height = 0; |
| 2013 | |
| 2014 | if (!output) |
| 2015 | return 0; |
| 2016 | |
| 2017 | wl_list_for_each(view, &shell->panel_layer.view_list, layer_link) { |
| 2018 | if (view->surface->output == output) { |
Jason Ekstrand | 918f2dd | 2013-12-02 21:01:53 -0600 | [diff] [blame] | 2019 | panel_height = view->surface->height; |
Philip Withnall | becb77e | 2013-11-25 18:01:30 +0000 | [diff] [blame] | 2020 | break; |
| 2021 | } |
| 2022 | } |
| 2023 | |
| 2024 | return panel_height; |
| 2025 | } |
| 2026 | |
Philip Withnall | 07926d9 | 2013-11-25 18:01:40 +0000 | [diff] [blame] | 2027 | /* The surface will be inserted into the list immediately after the link |
| 2028 | * returned by this function (i.e. will be stacked immediately above the |
| 2029 | * returned link). */ |
| 2030 | static struct wl_list * |
| 2031 | shell_surface_calculate_layer_link (struct shell_surface *shsurf) |
| 2032 | { |
| 2033 | struct workspace *ws; |
Kristian Høgsberg | ead5242 | 2014-01-01 13:51:52 -0800 | [diff] [blame] | 2034 | struct weston_view *parent; |
Philip Withnall | 07926d9 | 2013-11-25 18:01:40 +0000 | [diff] [blame] | 2035 | |
| 2036 | switch (shsurf->type) { |
Kristian Høgsberg | ead5242 | 2014-01-01 13:51:52 -0800 | [diff] [blame] | 2037 | case SHELL_SURFACE_POPUP: |
| 2038 | case SHELL_SURFACE_TOPLEVEL: |
Rafael Antognolli | ed207b4 | 2013-12-03 15:35:43 -0200 | [diff] [blame] | 2039 | if (shsurf->state.fullscreen) { |
Rafael Antognolli | 03b1659 | 2013-12-03 15:35:42 -0200 | [diff] [blame] | 2040 | return &shsurf->shell->fullscreen_layer.view_list; |
Rafael Antognolli | ed207b4 | 2013-12-03 15:35:43 -0200 | [diff] [blame] | 2041 | } else if (shsurf->parent) { |
Kristian Høgsberg | d55db69 | 2014-01-01 12:26:14 -0800 | [diff] [blame] | 2042 | /* Move the surface to its parent layer so |
| 2043 | * that surfaces which are transient for |
| 2044 | * fullscreen surfaces don't get hidden by the |
| 2045 | * fullscreen surfaces. */ |
Rafael Antognolli | ed207b4 | 2013-12-03 15:35:43 -0200 | [diff] [blame] | 2046 | |
| 2047 | /* TODO: Handle a parent with multiple views */ |
| 2048 | parent = get_default_view(shsurf->parent); |
| 2049 | if (parent) |
| 2050 | return parent->layer_link.prev; |
| 2051 | } |
Rafael Antognolli | 03b1659 | 2013-12-03 15:35:42 -0200 | [diff] [blame] | 2052 | break; |
Philip Withnall | 07926d9 | 2013-11-25 18:01:40 +0000 | [diff] [blame] | 2053 | |
| 2054 | case SHELL_SURFACE_XWAYLAND: |
Kristian Høgsberg | 4804a30 | 2013-12-05 22:43:03 -0800 | [diff] [blame] | 2055 | return &shsurf->shell->fullscreen_layer.view_list; |
| 2056 | |
Philip Withnall | 07926d9 | 2013-11-25 18:01:40 +0000 | [diff] [blame] | 2057 | case SHELL_SURFACE_NONE: |
| 2058 | default: |
| 2059 | /* Go to the fallback, below. */ |
| 2060 | break; |
| 2061 | } |
| 2062 | |
| 2063 | /* Move the surface to a normal workspace layer so that surfaces |
| 2064 | * which were previously fullscreen or transient are no longer |
| 2065 | * rendered on top. */ |
| 2066 | ws = get_current_workspace(shsurf->shell); |
| 2067 | return &ws->layer.view_list; |
| 2068 | } |
| 2069 | |
Philip Withnall | 648a4dd | 2013-11-25 18:01:44 +0000 | [diff] [blame] | 2070 | static void |
| 2071 | shell_surface_update_child_surface_layers (struct shell_surface *shsurf) |
| 2072 | { |
| 2073 | struct shell_surface *child; |
| 2074 | |
| 2075 | /* Move the child layers to the same workspace as shsurf. They will be |
| 2076 | * stacked above shsurf. */ |
| 2077 | wl_list_for_each_reverse(child, &shsurf->children_list, children_link) { |
| 2078 | if (shsurf->view->layer_link.prev != &child->view->layer_link) { |
| 2079 | weston_view_geometry_dirty(child->view); |
| 2080 | wl_list_remove(&child->view->layer_link); |
| 2081 | wl_list_insert(shsurf->view->layer_link.prev, |
| 2082 | &child->view->layer_link); |
| 2083 | weston_view_geometry_dirty(child->view); |
| 2084 | weston_surface_damage(child->surface); |
| 2085 | |
| 2086 | /* Recurse. We don’t expect this to recurse very far (if |
| 2087 | * at all) because that would imply we have transient |
| 2088 | * (or popup) children of transient surfaces, which |
| 2089 | * would be unusual. */ |
| 2090 | shell_surface_update_child_surface_layers(child); |
| 2091 | } |
| 2092 | } |
| 2093 | } |
| 2094 | |
Philip Withnall | e1d75ae | 2013-11-25 18:01:41 +0000 | [diff] [blame] | 2095 | /* 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] | 2096 | * geometry to ensure the changes are redrawn. |
| 2097 | * |
| 2098 | * If any child surfaces exist and are mapped, ensure they’re in the same layer |
| 2099 | * as this surface. */ |
Philip Withnall | e1d75ae | 2013-11-25 18:01:41 +0000 | [diff] [blame] | 2100 | static void |
| 2101 | shell_surface_update_layer(struct shell_surface *shsurf) |
| 2102 | { |
| 2103 | struct wl_list *new_layer_link; |
| 2104 | |
| 2105 | new_layer_link = shell_surface_calculate_layer_link(shsurf); |
| 2106 | |
| 2107 | if (new_layer_link == &shsurf->view->layer_link) |
| 2108 | return; |
| 2109 | |
| 2110 | weston_view_geometry_dirty(shsurf->view); |
| 2111 | wl_list_remove(&shsurf->view->layer_link); |
| 2112 | wl_list_insert(new_layer_link, &shsurf->view->layer_link); |
| 2113 | weston_view_geometry_dirty(shsurf->view); |
| 2114 | weston_surface_damage(shsurf->surface); |
Philip Withnall | 648a4dd | 2013-11-25 18:01:44 +0000 | [diff] [blame] | 2115 | |
| 2116 | shell_surface_update_child_surface_layers(shsurf); |
Philip Withnall | e1d75ae | 2013-11-25 18:01:41 +0000 | [diff] [blame] | 2117 | } |
| 2118 | |
Alexander Larsson | f82b6ca | 2013-05-28 16:23:39 +0200 | [diff] [blame] | 2119 | static void |
Philip Withnall | dc4332f | 2013-11-25 18:01:38 +0000 | [diff] [blame] | 2120 | shell_surface_set_parent(struct shell_surface *shsurf, |
| 2121 | struct weston_surface *parent) |
| 2122 | { |
| 2123 | shsurf->parent = parent; |
Philip Withnall | 648a4dd | 2013-11-25 18:01:44 +0000 | [diff] [blame] | 2124 | |
| 2125 | wl_list_remove(&shsurf->children_link); |
| 2126 | wl_list_init(&shsurf->children_link); |
| 2127 | |
| 2128 | /* Insert into the parent surface’s child list. */ |
| 2129 | if (parent != NULL) { |
| 2130 | struct shell_surface *parent_shsurf = get_shell_surface(parent); |
| 2131 | if (parent_shsurf != NULL) |
| 2132 | wl_list_insert(&parent_shsurf->children_list, |
| 2133 | &shsurf->children_link); |
| 2134 | } |
Philip Withnall | dc4332f | 2013-11-25 18:01:38 +0000 | [diff] [blame] | 2135 | } |
| 2136 | |
| 2137 | static void |
Philip Withnall | 352e7ed | 2013-11-25 18:01:35 +0000 | [diff] [blame] | 2138 | shell_surface_set_output(struct shell_surface *shsurf, |
| 2139 | struct weston_output *output) |
| 2140 | { |
| 2141 | struct weston_surface *es = shsurf->surface; |
| 2142 | |
| 2143 | /* get the default output, if the client set it as NULL |
| 2144 | check whether the ouput is available */ |
| 2145 | if (output) |
| 2146 | shsurf->output = output; |
| 2147 | else if (es->output) |
| 2148 | shsurf->output = es->output; |
| 2149 | else |
| 2150 | shsurf->output = get_default_output(es->compositor); |
| 2151 | } |
| 2152 | |
| 2153 | static void |
Rafael Antognolli | 03b1659 | 2013-12-03 15:35:42 -0200 | [diff] [blame] | 2154 | surface_clear_next_states(struct shell_surface *shsurf) |
| 2155 | { |
| 2156 | shsurf->next_state.maximized = false; |
| 2157 | shsurf->next_state.fullscreen = false; |
| 2158 | |
| 2159 | if ((shsurf->next_state.maximized != shsurf->state.maximized) || |
| 2160 | (shsurf->next_state.fullscreen != shsurf->state.fullscreen)) |
| 2161 | shsurf->state_changed = true; |
| 2162 | } |
| 2163 | |
| 2164 | static void |
Philip Withnall | becb77e | 2013-11-25 18:01:30 +0000 | [diff] [blame] | 2165 | set_toplevel(struct shell_surface *shsurf) |
| 2166 | { |
Kristian Høgsberg | 41fbf6f | 2013-12-05 22:31:25 -0800 | [diff] [blame] | 2167 | shell_surface_set_parent(shsurf, NULL); |
| 2168 | surface_clear_next_states(shsurf); |
Kristian Høgsberg | c8f8dd8 | 2013-12-05 23:20:33 -0800 | [diff] [blame] | 2169 | shsurf->type = SHELL_SURFACE_TOPLEVEL; |
Philip Withnall | 648a4dd | 2013-11-25 18:01:44 +0000 | [diff] [blame] | 2170 | |
| 2171 | /* The layer_link is updated in set_surface_type(), |
| 2172 | * called from configure. */ |
Philip Withnall | becb77e | 2013-11-25 18:01:30 +0000 | [diff] [blame] | 2173 | } |
| 2174 | |
| 2175 | static void |
| 2176 | shell_surface_set_toplevel(struct wl_client *client, |
| 2177 | struct wl_resource *resource) |
| 2178 | { |
| 2179 | struct shell_surface *surface = wl_resource_get_user_data(resource); |
| 2180 | |
| 2181 | set_toplevel(surface); |
| 2182 | } |
| 2183 | |
| 2184 | static void |
| 2185 | set_transient(struct shell_surface *shsurf, |
| 2186 | struct weston_surface *parent, int x, int y, uint32_t flags) |
| 2187 | { |
Philip Withnall | dc4332f | 2013-11-25 18:01:38 +0000 | [diff] [blame] | 2188 | assert(parent != NULL); |
| 2189 | |
Kristian Høgsberg | 9f7e331 | 2014-01-02 22:40:37 -0800 | [diff] [blame] | 2190 | shell_surface_set_parent(shsurf, parent); |
| 2191 | |
| 2192 | surface_clear_next_states(shsurf); |
| 2193 | |
Philip Withnall | becb77e | 2013-11-25 18:01:30 +0000 | [diff] [blame] | 2194 | shsurf->transient.x = x; |
| 2195 | shsurf->transient.y = y; |
| 2196 | shsurf->transient.flags = flags; |
Philip Withnall | dc4332f | 2013-11-25 18:01:38 +0000 | [diff] [blame] | 2197 | |
Rafael Antognolli | ed207b4 | 2013-12-03 15:35:43 -0200 | [diff] [blame] | 2198 | shsurf->next_state.relative = true; |
Kristian Høgsberg | a1df7ac | 2013-12-31 15:01:01 -0800 | [diff] [blame] | 2199 | shsurf->state_changed = true; |
Kristian Høgsberg | c8f8dd8 | 2013-12-05 23:20:33 -0800 | [diff] [blame] | 2200 | shsurf->type = SHELL_SURFACE_TOPLEVEL; |
Philip Withnall | 648a4dd | 2013-11-25 18:01:44 +0000 | [diff] [blame] | 2201 | |
| 2202 | /* The layer_link is updated in set_surface_type(), |
| 2203 | * called from configure. */ |
Philip Withnall | becb77e | 2013-11-25 18:01:30 +0000 | [diff] [blame] | 2204 | } |
| 2205 | |
| 2206 | static void |
| 2207 | shell_surface_set_transient(struct wl_client *client, |
| 2208 | struct wl_resource *resource, |
| 2209 | struct wl_resource *parent_resource, |
| 2210 | int x, int y, uint32_t flags) |
| 2211 | { |
| 2212 | struct shell_surface *shsurf = wl_resource_get_user_data(resource); |
| 2213 | struct weston_surface *parent = |
| 2214 | wl_resource_get_user_data(parent_resource); |
| 2215 | |
| 2216 | set_transient(shsurf, parent, x, y, flags); |
| 2217 | } |
| 2218 | |
| 2219 | static void |
| 2220 | set_fullscreen(struct shell_surface *shsurf, |
| 2221 | uint32_t method, |
| 2222 | uint32_t framerate, |
| 2223 | struct weston_output *output) |
| 2224 | { |
Philip Withnall | 352e7ed | 2013-11-25 18:01:35 +0000 | [diff] [blame] | 2225 | shell_surface_set_output(shsurf, output); |
Philip Withnall | becb77e | 2013-11-25 18:01:30 +0000 | [diff] [blame] | 2226 | |
| 2227 | shsurf->fullscreen_output = shsurf->output; |
| 2228 | shsurf->fullscreen.type = method; |
| 2229 | shsurf->fullscreen.framerate = framerate; |
Philip Withnall | dc4332f | 2013-11-25 18:01:38 +0000 | [diff] [blame] | 2230 | |
Kristian Høgsberg | e960b3f | 2013-12-05 22:04:42 -0800 | [diff] [blame] | 2231 | shsurf->next_state.fullscreen = true; |
| 2232 | shsurf->state_changed = true; |
Kristian Høgsberg | c8f8dd8 | 2013-12-05 23:20:33 -0800 | [diff] [blame] | 2233 | shsurf->type = SHELL_SURFACE_TOPLEVEL; |
Philip Withnall | becb77e | 2013-11-25 18:01:30 +0000 | [diff] [blame] | 2234 | |
| 2235 | shsurf->client->send_configure(shsurf->surface, 0, |
| 2236 | shsurf->output->width, |
| 2237 | shsurf->output->height); |
Philip Withnall | 648a4dd | 2013-11-25 18:01:44 +0000 | [diff] [blame] | 2238 | |
| 2239 | /* The layer_link is updated in set_surface_type(), |
| 2240 | * called from configure. */ |
Philip Withnall | becb77e | 2013-11-25 18:01:30 +0000 | [diff] [blame] | 2241 | } |
| 2242 | |
| 2243 | static void |
Zhang, Xiong Y | 3123693 | 2013-12-13 22:10:57 +0200 | [diff] [blame] | 2244 | weston_view_set_initial_position(struct weston_view *view, |
| 2245 | struct desktop_shell *shell); |
| 2246 | |
| 2247 | static void |
Philip Withnall | becb77e | 2013-11-25 18:01:30 +0000 | [diff] [blame] | 2248 | unset_fullscreen(struct shell_surface *shsurf) |
Alex Wu | 4539b08 | 2012-03-01 12:57:46 +0800 | [diff] [blame] | 2249 | { |
Philip Withnall | f85fe84 | 2013-11-25 18:01:37 +0000 | [diff] [blame] | 2250 | /* Unset the fullscreen output, driver configuration and transforms. */ |
Alex Wu | bd3354b | 2012-04-17 17:20:49 +0800 | [diff] [blame] | 2251 | if (shsurf->fullscreen.type == WL_SHELL_SURFACE_FULLSCREEN_METHOD_DRIVER && |
| 2252 | shell_surface_is_top_fullscreen(shsurf)) { |
Alexander Larsson | f82b6ca | 2013-05-28 16:23:39 +0200 | [diff] [blame] | 2253 | restore_output_mode(shsurf->fullscreen_output); |
Alex Wu | bd3354b | 2012-04-17 17:20:49 +0800 | [diff] [blame] | 2254 | } |
Philip Withnall | f85fe84 | 2013-11-25 18:01:37 +0000 | [diff] [blame] | 2255 | shsurf->fullscreen_output = NULL; |
| 2256 | |
Alex Wu | 4539b08 | 2012-03-01 12:57:46 +0800 | [diff] [blame] | 2257 | shsurf->fullscreen.type = WL_SHELL_SURFACE_FULLSCREEN_METHOD_DEFAULT; |
| 2258 | shsurf->fullscreen.framerate = 0; |
Philip Withnall | f85fe84 | 2013-11-25 18:01:37 +0000 | [diff] [blame] | 2259 | |
Alex Wu | 4539b08 | 2012-03-01 12:57:46 +0800 | [diff] [blame] | 2260 | wl_list_remove(&shsurf->fullscreen.transform.link); |
| 2261 | wl_list_init(&shsurf->fullscreen.transform.link); |
Philip Withnall | f85fe84 | 2013-11-25 18:01:37 +0000 | [diff] [blame] | 2262 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 2263 | if (shsurf->fullscreen.black_view) |
| 2264 | weston_surface_destroy(shsurf->fullscreen.black_view->surface); |
| 2265 | shsurf->fullscreen.black_view = NULL; |
Philip Withnall | f85fe84 | 2013-11-25 18:01:37 +0000 | [diff] [blame] | 2266 | |
Zhang, Xiong Y | 3123693 | 2013-12-13 22:10:57 +0200 | [diff] [blame] | 2267 | if (shsurf->saved_position_valid) |
| 2268 | weston_view_set_position(shsurf->view, |
| 2269 | shsurf->saved_x, shsurf->saved_y); |
| 2270 | else |
| 2271 | weston_view_set_initial_position(shsurf->view, shsurf->shell); |
| 2272 | |
Alex Wu | 7bcb8bd | 2012-04-27 09:07:24 +0800 | [diff] [blame] | 2273 | if (shsurf->saved_rotation_valid) { |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 2274 | wl_list_insert(&shsurf->view->geometry.transformation_list, |
Philip Withnall | becb77e | 2013-11-25 18:01:30 +0000 | [diff] [blame] | 2275 | &shsurf->rotation.transform.link); |
Alex Wu | 7bcb8bd | 2012-04-27 09:07:24 +0800 | [diff] [blame] | 2276 | shsurf->saved_rotation_valid = false; |
| 2277 | } |
Rafal Mielniczuk | 3e3862c | 2012-10-07 20:25:36 +0200 | [diff] [blame] | 2278 | |
Philip Withnall | e1d75ae | 2013-11-25 18:01:41 +0000 | [diff] [blame] | 2279 | /* Layer is updated in set_surface_type(). */ |
Alex Wu | 4539b08 | 2012-03-01 12:57:46 +0800 | [diff] [blame] | 2280 | } |
| 2281 | |
Rafal Mielniczuk | fffdcdd | 2013-03-11 19:26:54 +0100 | [diff] [blame] | 2282 | static void |
Philip Withnall | becb77e | 2013-11-25 18:01:30 +0000 | [diff] [blame] | 2283 | shell_surface_set_fullscreen(struct wl_client *client, |
| 2284 | struct wl_resource *resource, |
| 2285 | uint32_t method, |
| 2286 | uint32_t framerate, |
| 2287 | struct wl_resource *output_resource) |
| 2288 | { |
| 2289 | struct shell_surface *shsurf = wl_resource_get_user_data(resource); |
| 2290 | struct weston_output *output; |
| 2291 | |
| 2292 | if (output_resource) |
| 2293 | output = wl_resource_get_user_data(output_resource); |
| 2294 | else |
| 2295 | output = NULL; |
| 2296 | |
Rafael Antognolli | 4b99a40 | 2013-12-03 15:35:44 -0200 | [diff] [blame] | 2297 | shell_surface_set_parent(shsurf, NULL); |
| 2298 | |
Rafael Antognolli | 03b1659 | 2013-12-03 15:35:42 -0200 | [diff] [blame] | 2299 | surface_clear_next_states(shsurf); |
Philip Withnall | becb77e | 2013-11-25 18:01:30 +0000 | [diff] [blame] | 2300 | set_fullscreen(shsurf, method, framerate, output); |
| 2301 | } |
| 2302 | |
| 2303 | static void |
| 2304 | set_popup(struct shell_surface *shsurf, |
| 2305 | struct weston_surface *parent, |
| 2306 | struct weston_seat *seat, |
| 2307 | uint32_t serial, |
| 2308 | int32_t x, |
| 2309 | int32_t y) |
| 2310 | { |
Philip Withnall | dc4332f | 2013-11-25 18:01:38 +0000 | [diff] [blame] | 2311 | assert(parent != NULL); |
| 2312 | |
Philip Withnall | becb77e | 2013-11-25 18:01:30 +0000 | [diff] [blame] | 2313 | shsurf->popup.shseat = get_shell_seat(seat); |
| 2314 | shsurf->popup.serial = serial; |
| 2315 | shsurf->popup.x = x; |
| 2316 | shsurf->popup.y = y; |
Philip Withnall | dc4332f | 2013-11-25 18:01:38 +0000 | [diff] [blame] | 2317 | |
Kristian Høgsberg | c8f8dd8 | 2013-12-05 23:20:33 -0800 | [diff] [blame] | 2318 | shsurf->type = SHELL_SURFACE_POPUP; |
Philip Withnall | becb77e | 2013-11-25 18:01:30 +0000 | [diff] [blame] | 2319 | } |
| 2320 | |
| 2321 | static void |
| 2322 | shell_surface_set_popup(struct wl_client *client, |
| 2323 | struct wl_resource *resource, |
| 2324 | struct wl_resource *seat_resource, |
| 2325 | uint32_t serial, |
| 2326 | struct wl_resource *parent_resource, |
| 2327 | int32_t x, int32_t y, uint32_t flags) |
| 2328 | { |
| 2329 | struct shell_surface *shsurf = wl_resource_get_user_data(resource); |
Rafael Antognolli | 4b99a40 | 2013-12-03 15:35:44 -0200 | [diff] [blame] | 2330 | struct weston_surface *parent = |
| 2331 | wl_resource_get_user_data(parent_resource); |
| 2332 | |
| 2333 | shell_surface_set_parent(shsurf, parent); |
Philip Withnall | becb77e | 2013-11-25 18:01:30 +0000 | [diff] [blame] | 2334 | |
Rafael Antognolli | 03b1659 | 2013-12-03 15:35:42 -0200 | [diff] [blame] | 2335 | surface_clear_next_states(shsurf); |
Philip Withnall | becb77e | 2013-11-25 18:01:30 +0000 | [diff] [blame] | 2336 | set_popup(shsurf, |
Rafael Antognolli | 4b99a40 | 2013-12-03 15:35:44 -0200 | [diff] [blame] | 2337 | parent, |
Philip Withnall | becb77e | 2013-11-25 18:01:30 +0000 | [diff] [blame] | 2338 | wl_resource_get_user_data(seat_resource), |
| 2339 | serial, x, y); |
| 2340 | } |
| 2341 | |
| 2342 | static void |
| 2343 | set_maximized(struct shell_surface *shsurf, |
| 2344 | struct weston_output *output) |
| 2345 | { |
| 2346 | struct desktop_shell *shell; |
| 2347 | uint32_t edges = 0, panel_height = 0; |
Philip Withnall | becb77e | 2013-11-25 18:01:30 +0000 | [diff] [blame] | 2348 | |
Philip Withnall | 352e7ed | 2013-11-25 18:01:35 +0000 | [diff] [blame] | 2349 | shell_surface_set_output(shsurf, output); |
Philip Withnall | becb77e | 2013-11-25 18:01:30 +0000 | [diff] [blame] | 2350 | |
| 2351 | shell = shell_surface_get_shell(shsurf); |
| 2352 | panel_height = get_output_panel_height(shell, shsurf->output); |
| 2353 | edges = WL_SHELL_SURFACE_RESIZE_TOP | WL_SHELL_SURFACE_RESIZE_LEFT; |
| 2354 | |
| 2355 | shsurf->client->send_configure(shsurf->surface, edges, |
| 2356 | shsurf->output->width, |
| 2357 | shsurf->output->height - panel_height); |
| 2358 | |
Kristian Høgsberg | c2745b1 | 2013-12-05 22:00:40 -0800 | [diff] [blame] | 2359 | shsurf->next_state.maximized = true; |
| 2360 | shsurf->state_changed = true; |
Kristian Høgsberg | c8f8dd8 | 2013-12-05 23:20:33 -0800 | [diff] [blame] | 2361 | shsurf->type = SHELL_SURFACE_TOPLEVEL; |
Philip Withnall | becb77e | 2013-11-25 18:01:30 +0000 | [diff] [blame] | 2362 | } |
| 2363 | |
| 2364 | static void |
| 2365 | unset_maximized(struct shell_surface *shsurf) |
Rafal Mielniczuk | fffdcdd | 2013-03-11 19:26:54 +0100 | [diff] [blame] | 2366 | { |
Rafal Mielniczuk | fffdcdd | 2013-03-11 19:26:54 +0100 | [diff] [blame] | 2367 | /* undo all maximized things here */ |
| 2368 | shsurf->output = get_default_output(shsurf->surface->compositor); |
Zhang, Xiong Y | 3123693 | 2013-12-13 22:10:57 +0200 | [diff] [blame] | 2369 | |
| 2370 | if (shsurf->saved_position_valid) |
| 2371 | weston_view_set_position(shsurf->view, |
| 2372 | shsurf->saved_x, shsurf->saved_y); |
| 2373 | else |
| 2374 | weston_view_set_initial_position(shsurf->view, shsurf->shell); |
Rafal Mielniczuk | fffdcdd | 2013-03-11 19:26:54 +0100 | [diff] [blame] | 2375 | |
| 2376 | if (shsurf->saved_rotation_valid) { |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 2377 | wl_list_insert(&shsurf->view->geometry.transformation_list, |
| 2378 | &shsurf->rotation.transform.link); |
Rafal Mielniczuk | fffdcdd | 2013-03-11 19:26:54 +0100 | [diff] [blame] | 2379 | shsurf->saved_rotation_valid = false; |
| 2380 | } |
| 2381 | |
Philip Withnall | e1d75ae | 2013-11-25 18:01:41 +0000 | [diff] [blame] | 2382 | /* Layer is updated in set_surface_type(). */ |
Rafal Mielniczuk | fffdcdd | 2013-03-11 19:26:54 +0100 | [diff] [blame] | 2383 | } |
| 2384 | |
Philip Withnall | becb77e | 2013-11-25 18:01:30 +0000 | [diff] [blame] | 2385 | static void |
| 2386 | shell_surface_set_maximized(struct wl_client *client, |
| 2387 | struct wl_resource *resource, |
| 2388 | struct wl_resource *output_resource) |
| 2389 | { |
| 2390 | struct shell_surface *shsurf = wl_resource_get_user_data(resource); |
| 2391 | struct weston_output *output; |
| 2392 | |
| 2393 | if (output_resource) |
| 2394 | output = wl_resource_get_user_data(output_resource); |
| 2395 | else |
| 2396 | output = NULL; |
| 2397 | |
Rafael Antognolli | 4b99a40 | 2013-12-03 15:35:44 -0200 | [diff] [blame] | 2398 | shell_surface_set_parent(shsurf, NULL); |
| 2399 | |
Rafael Antognolli | 03b1659 | 2013-12-03 15:35:42 -0200 | [diff] [blame] | 2400 | surface_clear_next_states(shsurf); |
Philip Withnall | becb77e | 2013-11-25 18:01:30 +0000 | [diff] [blame] | 2401 | set_maximized(shsurf, output); |
| 2402 | } |
| 2403 | |
Philip Withnall | e1d75ae | 2013-11-25 18:01:41 +0000 | [diff] [blame] | 2404 | /* This is only ever called from set_surface_type(), so there’s no need to |
| 2405 | * update layer_links here, since they’ll be updated when we return. */ |
Pekka Paalanen | 9826223 | 2011-12-01 10:42:22 +0200 | [diff] [blame] | 2406 | static int |
Philip Withnall | becb77e | 2013-11-25 18:01:30 +0000 | [diff] [blame] | 2407 | reset_surface_type(struct shell_surface *surface) |
Pekka Paalanen | 9826223 | 2011-12-01 10:42:22 +0200 | [diff] [blame] | 2408 | { |
Rafael Antognolli | 03b1659 | 2013-12-03 15:35:42 -0200 | [diff] [blame] | 2409 | if (surface->state.fullscreen) |
Philip Withnall | becb77e | 2013-11-25 18:01:30 +0000 | [diff] [blame] | 2410 | unset_fullscreen(surface); |
Rafael Antognolli | 03b1659 | 2013-12-03 15:35:42 -0200 | [diff] [blame] | 2411 | if (surface->state.maximized) |
Philip Withnall | becb77e | 2013-11-25 18:01:30 +0000 | [diff] [blame] | 2412 | unset_maximized(surface); |
Pekka Paalanen | 9826223 | 2011-12-01 10:42:22 +0200 | [diff] [blame] | 2413 | |
Pekka Paalanen | 9826223 | 2011-12-01 10:42:22 +0200 | [diff] [blame] | 2414 | return 0; |
| 2415 | } |
| 2416 | |
Kristian Høgsberg | 4cca349 | 2011-01-18 07:53:49 -0500 | [diff] [blame] | 2417 | static void |
Rafael Antognolli | 03b1659 | 2013-12-03 15:35:42 -0200 | [diff] [blame] | 2418 | set_full_output(struct shell_surface *shsurf) |
| 2419 | { |
| 2420 | shsurf->saved_x = shsurf->view->geometry.x; |
| 2421 | shsurf->saved_y = shsurf->view->geometry.y; |
Rafael Antognolli | 3c4e3f7 | 2013-12-03 15:35:46 -0200 | [diff] [blame] | 2422 | shsurf->saved_width = shsurf->surface->width; |
| 2423 | shsurf->saved_height = shsurf->surface->height; |
| 2424 | shsurf->saved_size_valid = true; |
Rafael Antognolli | 03b1659 | 2013-12-03 15:35:42 -0200 | [diff] [blame] | 2425 | shsurf->saved_position_valid = true; |
| 2426 | |
| 2427 | if (!wl_list_empty(&shsurf->rotation.transform.link)) { |
| 2428 | wl_list_remove(&shsurf->rotation.transform.link); |
| 2429 | wl_list_init(&shsurf->rotation.transform.link); |
| 2430 | weston_view_geometry_dirty(shsurf->view); |
| 2431 | shsurf->saved_rotation_valid = true; |
| 2432 | } |
| 2433 | } |
| 2434 | |
| 2435 | static void |
Kristian Høgsberg | 7f366e7 | 2012-04-27 17:20:01 -0400 | [diff] [blame] | 2436 | set_surface_type(struct shell_surface *shsurf) |
| 2437 | { |
Kristian Høgsberg | 8150b19 | 2012-06-27 10:22:58 -0400 | [diff] [blame] | 2438 | struct weston_surface *pes = shsurf->parent; |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 2439 | struct weston_view *pev = get_default_view(pes); |
Kristian Høgsberg | 7f366e7 | 2012-04-27 17:20:01 -0400 | [diff] [blame] | 2440 | |
Philip Withnall | becb77e | 2013-11-25 18:01:30 +0000 | [diff] [blame] | 2441 | reset_surface_type(shsurf); |
Kristian Høgsberg | 7f366e7 | 2012-04-27 17:20:01 -0400 | [diff] [blame] | 2442 | |
Rafael Antognolli | 03b1659 | 2013-12-03 15:35:42 -0200 | [diff] [blame] | 2443 | shsurf->state = shsurf->next_state; |
Rafael Antognolli | 03b1659 | 2013-12-03 15:35:42 -0200 | [diff] [blame] | 2444 | shsurf->state_changed = false; |
Kristian Høgsberg | 7f366e7 | 2012-04-27 17:20:01 -0400 | [diff] [blame] | 2445 | |
| 2446 | switch (shsurf->type) { |
| 2447 | case SHELL_SURFACE_TOPLEVEL: |
Rafael Antognolli | ed207b4 | 2013-12-03 15:35:43 -0200 | [diff] [blame] | 2448 | if (shsurf->state.maximized || shsurf->state.fullscreen) { |
Rafael Antognolli | 03b1659 | 2013-12-03 15:35:42 -0200 | [diff] [blame] | 2449 | set_full_output(shsurf); |
Rafael Antognolli | ed207b4 | 2013-12-03 15:35:43 -0200 | [diff] [blame] | 2450 | } else if (shsurf->state.relative && pev) { |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 2451 | weston_view_set_position(shsurf->view, |
| 2452 | pev->geometry.x + shsurf->transient.x, |
| 2453 | pev->geometry.y + shsurf->transient.y); |
Rafael Antognolli | ed207b4 | 2013-12-03 15:35:43 -0200 | [diff] [blame] | 2454 | } |
Rafael Antognolli | 44a3162 | 2013-12-04 18:37:16 -0200 | [diff] [blame] | 2455 | break; |
Kristian Høgsberg | 7f366e7 | 2012-04-27 17:20:01 -0400 | [diff] [blame] | 2456 | |
Tiago Vignatti | fb2adba | 2013-06-12 15:43:21 -0300 | [diff] [blame] | 2457 | case SHELL_SURFACE_XWAYLAND: |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 2458 | weston_view_set_position(shsurf->view, shsurf->transient.x, |
| 2459 | shsurf->transient.y); |
Tiago Vignatti | fb2adba | 2013-06-12 15:43:21 -0300 | [diff] [blame] | 2460 | break; |
| 2461 | |
Philip Withnall | 0f640e2 | 2013-11-25 18:01:31 +0000 | [diff] [blame] | 2462 | case SHELL_SURFACE_POPUP: |
| 2463 | case SHELL_SURFACE_NONE: |
Kristian Høgsberg | 7f366e7 | 2012-04-27 17:20:01 -0400 | [diff] [blame] | 2464 | default: |
| 2465 | break; |
| 2466 | } |
Philip Withnall | e1d75ae | 2013-11-25 18:01:41 +0000 | [diff] [blame] | 2467 | |
| 2468 | /* Update the surface’s layer. */ |
| 2469 | shell_surface_update_layer(shsurf); |
Kristian Høgsberg | 7f366e7 | 2012-04-27 17:20:01 -0400 | [diff] [blame] | 2470 | } |
| 2471 | |
Tiago Vignatti | be14326 | 2012-04-16 17:31:41 +0300 | [diff] [blame] | 2472 | static struct desktop_shell * |
Juan Zhao | 96879df | 2012-02-07 08:45:41 +0800 | [diff] [blame] | 2473 | shell_surface_get_shell(struct shell_surface *shsurf) |
Pekka Paalanen | af0e34c | 2011-12-02 10:59:17 +0200 | [diff] [blame] | 2474 | { |
Kristian Høgsberg | 02e79dc | 2012-04-12 09:55:26 -0400 | [diff] [blame] | 2475 | return shsurf->shell; |
Juan Zhao | 96879df | 2012-02-07 08:45:41 +0800 | [diff] [blame] | 2476 | } |
| 2477 | |
Alex Wu | 2185843 | 2012-04-01 20:13:08 +0800 | [diff] [blame] | 2478 | static void |
Jason Ekstrand | 918f2dd | 2013-12-02 21:01:53 -0600 | [diff] [blame] | 2479 | 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] | 2480 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 2481 | static struct weston_view * |
Alex Wu | 4539b08 | 2012-03-01 12:57:46 +0800 | [diff] [blame] | 2482 | create_black_surface(struct weston_compositor *ec, |
Alex Wu | 2185843 | 2012-04-01 20:13:08 +0800 | [diff] [blame] | 2483 | struct weston_surface *fs_surface, |
John Kåre Alsaker | 490d02a | 2012-09-30 02:57:21 +0200 | [diff] [blame] | 2484 | float x, float y, int w, int h) |
Alex Wu | 4539b08 | 2012-03-01 12:57:46 +0800 | [diff] [blame] | 2485 | { |
| 2486 | struct weston_surface *surface = NULL; |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 2487 | struct weston_view *view; |
Alex Wu | 4539b08 | 2012-03-01 12:57:46 +0800 | [diff] [blame] | 2488 | |
| 2489 | surface = weston_surface_create(ec); |
| 2490 | if (surface == NULL) { |
Martin Minarik | 6d11836 | 2012-06-07 18:01:59 +0200 | [diff] [blame] | 2491 | weston_log("no memory\n"); |
Alex Wu | 4539b08 | 2012-03-01 12:57:46 +0800 | [diff] [blame] | 2492 | return NULL; |
| 2493 | } |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 2494 | view = weston_view_create(surface); |
| 2495 | if (surface == NULL) { |
| 2496 | weston_log("no memory\n"); |
| 2497 | weston_surface_destroy(surface); |
| 2498 | return NULL; |
| 2499 | } |
Alex Wu | 4539b08 | 2012-03-01 12:57:46 +0800 | [diff] [blame] | 2500 | |
Alex Wu | 2185843 | 2012-04-01 20:13:08 +0800 | [diff] [blame] | 2501 | surface->configure = black_surface_configure; |
Giulio Camuffo | 7fe01b1 | 2013-03-28 18:02:42 +0100 | [diff] [blame] | 2502 | surface->configure_private = fs_surface; |
Alex Wu | 4539b08 | 2012-03-01 12:57:46 +0800 | [diff] [blame] | 2503 | weston_surface_set_color(surface, 0.0, 0.0, 0.0, 1); |
Pekka Paalanen | 71f6f3b | 2012-10-10 12:49:26 +0300 | [diff] [blame] | 2504 | pixman_region32_fini(&surface->opaque); |
Kristian Høgsberg | 61f00f5 | 2012-08-03 16:31:36 -0400 | [diff] [blame] | 2505 | pixman_region32_init_rect(&surface->opaque, 0, 0, w, h); |
Jonas Ådahl | 33619a4 | 2013-01-15 21:25:55 +0100 | [diff] [blame] | 2506 | pixman_region32_fini(&surface->input); |
| 2507 | pixman_region32_init_rect(&surface->input, 0, 0, w, h); |
Jason Ekstrand | 918f2dd | 2013-12-02 21:01:53 -0600 | [diff] [blame] | 2508 | |
Jason Ekstrand | 6228ee2 | 2014-01-01 15:58:57 -0600 | [diff] [blame] | 2509 | weston_surface_set_size(surface, w, h); |
Jason Ekstrand | 918f2dd | 2013-12-02 21:01:53 -0600 | [diff] [blame] | 2510 | weston_view_set_position(view, x, y); |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 2511 | |
| 2512 | return view; |
Alex Wu | 4539b08 | 2012-03-01 12:57:46 +0800 | [diff] [blame] | 2513 | } |
| 2514 | |
Philip Withnall | ed8f1a9 | 2013-11-25 18:01:43 +0000 | [diff] [blame] | 2515 | static void |
| 2516 | shell_ensure_fullscreen_black_view(struct shell_surface *shsurf) |
| 2517 | { |
| 2518 | struct weston_output *output = shsurf->fullscreen_output; |
| 2519 | |
Rafael Antognolli | 03b1659 | 2013-12-03 15:35:42 -0200 | [diff] [blame] | 2520 | assert(shsurf->state.fullscreen); |
Philip Withnall | ed8f1a9 | 2013-11-25 18:01:43 +0000 | [diff] [blame] | 2521 | |
| 2522 | if (!shsurf->fullscreen.black_view) |
| 2523 | shsurf->fullscreen.black_view = |
| 2524 | create_black_surface(shsurf->surface->compositor, |
| 2525 | shsurf->surface, |
| 2526 | output->x, output->y, |
| 2527 | output->width, |
| 2528 | output->height); |
| 2529 | |
| 2530 | weston_view_geometry_dirty(shsurf->fullscreen.black_view); |
| 2531 | wl_list_remove(&shsurf->fullscreen.black_view->layer_link); |
| 2532 | wl_list_insert(&shsurf->view->layer_link, |
| 2533 | &shsurf->fullscreen.black_view->layer_link); |
| 2534 | weston_view_geometry_dirty(shsurf->fullscreen.black_view); |
| 2535 | weston_surface_damage(shsurf->surface); |
| 2536 | } |
| 2537 | |
Alex Wu | 4539b08 | 2012-03-01 12:57:46 +0800 | [diff] [blame] | 2538 | /* Create black surface and append it to the associated fullscreen surface. |
| 2539 | * Handle size dismatch and positioning according to the method. */ |
| 2540 | static void |
| 2541 | shell_configure_fullscreen(struct shell_surface *shsurf) |
| 2542 | { |
| 2543 | struct weston_output *output = shsurf->fullscreen_output; |
| 2544 | struct weston_surface *surface = shsurf->surface; |
| 2545 | struct weston_matrix *matrix; |
Kristian Høgsberg | 240dfeb | 2012-07-12 12:32:31 -0400 | [diff] [blame] | 2546 | float scale, output_aspect, surface_aspect, x, y; |
Giulio Camuffo | b836664 | 2013-04-25 13:57:46 +0300 | [diff] [blame] | 2547 | int32_t surf_x, surf_y, surf_width, surf_height; |
Alex Wu | 4539b08 | 2012-03-01 12:57:46 +0800 | [diff] [blame] | 2548 | |
Alexander Larsson | f82b6ca | 2013-05-28 16:23:39 +0200 | [diff] [blame] | 2549 | if (shsurf->fullscreen.type != WL_SHELL_SURFACE_FULLSCREEN_METHOD_DRIVER) |
| 2550 | restore_output_mode(output); |
| 2551 | |
Philip Withnall | ed8f1a9 | 2013-11-25 18:01:43 +0000 | [diff] [blame] | 2552 | shell_ensure_fullscreen_black_view(shsurf); |
Alex Wu | 4539b08 | 2012-03-01 12:57:46 +0800 | [diff] [blame] | 2553 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 2554 | surface_subsurfaces_boundingbox(shsurf->surface, &surf_x, &surf_y, |
Giulio Camuffo | b836664 | 2013-04-25 13:57:46 +0300 | [diff] [blame] | 2555 | &surf_width, &surf_height); |
| 2556 | |
Alex Wu | 4539b08 | 2012-03-01 12:57:46 +0800 | [diff] [blame] | 2557 | switch (shsurf->fullscreen.type) { |
| 2558 | case WL_SHELL_SURFACE_FULLSCREEN_METHOD_DEFAULT: |
Pekka Paalanen | de685b8 | 2012-12-04 15:58:12 +0200 | [diff] [blame] | 2559 | if (surface->buffer_ref.buffer) |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 2560 | center_on_output(shsurf->view, shsurf->fullscreen_output); |
Alex Wu | 4539b08 | 2012-03-01 12:57:46 +0800 | [diff] [blame] | 2561 | break; |
| 2562 | case WL_SHELL_SURFACE_FULLSCREEN_METHOD_SCALE: |
Rob Bradford | 9f3dd15 | 2013-02-12 11:53:47 +0000 | [diff] [blame] | 2563 | /* 1:1 mapping between surface and output dimensions */ |
Giulio Camuffo | b836664 | 2013-04-25 13:57:46 +0300 | [diff] [blame] | 2564 | if (output->width == surf_width && |
| 2565 | output->height == surf_height) { |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 2566 | weston_view_set_position(shsurf->view, |
| 2567 | output->x - surf_x, |
| 2568 | output->y - surf_y); |
Rob Bradford | 9f3dd15 | 2013-02-12 11:53:47 +0000 | [diff] [blame] | 2569 | break; |
| 2570 | } |
| 2571 | |
Alex Wu | 4539b08 | 2012-03-01 12:57:46 +0800 | [diff] [blame] | 2572 | matrix = &shsurf->fullscreen.transform.matrix; |
| 2573 | weston_matrix_init(matrix); |
Kristian Høgsberg | 240dfeb | 2012-07-12 12:32:31 -0400 | [diff] [blame] | 2574 | |
Scott Moreau | 1bad5db | 2012-08-18 01:04:05 -0600 | [diff] [blame] | 2575 | output_aspect = (float) output->width / |
| 2576 | (float) output->height; |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 2577 | /* XXX: Use surf_width and surf_height here? */ |
| 2578 | surface_aspect = (float) surface->width / |
| 2579 | (float) surface->height; |
Kristian Høgsberg | 240dfeb | 2012-07-12 12:32:31 -0400 | [diff] [blame] | 2580 | if (output_aspect < surface_aspect) |
Scott Moreau | 1bad5db | 2012-08-18 01:04:05 -0600 | [diff] [blame] | 2581 | scale = (float) output->width / |
Giulio Camuffo | b836664 | 2013-04-25 13:57:46 +0300 | [diff] [blame] | 2582 | (float) surf_width; |
Kristian Høgsberg | 240dfeb | 2012-07-12 12:32:31 -0400 | [diff] [blame] | 2583 | else |
Scott Moreau | 1bad5db | 2012-08-18 01:04:05 -0600 | [diff] [blame] | 2584 | scale = (float) output->height / |
Giulio Camuffo | b836664 | 2013-04-25 13:57:46 +0300 | [diff] [blame] | 2585 | (float) surf_height; |
Kristian Høgsberg | 240dfeb | 2012-07-12 12:32:31 -0400 | [diff] [blame] | 2586 | |
Alex Wu | 4539b08 | 2012-03-01 12:57:46 +0800 | [diff] [blame] | 2587 | weston_matrix_scale(matrix, scale, scale, 1); |
| 2588 | wl_list_remove(&shsurf->fullscreen.transform.link); |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 2589 | wl_list_insert(&shsurf->view->geometry.transformation_list, |
Alex Wu | 4539b08 | 2012-03-01 12:57:46 +0800 | [diff] [blame] | 2590 | &shsurf->fullscreen.transform.link); |
Giulio Camuffo | b836664 | 2013-04-25 13:57:46 +0300 | [diff] [blame] | 2591 | x = output->x + (output->width - surf_width * scale) / 2 - surf_x; |
| 2592 | y = output->y + (output->height - surf_height * scale) / 2 - surf_y; |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 2593 | weston_view_set_position(shsurf->view, x, y); |
Kristian Høgsberg | 240dfeb | 2012-07-12 12:32:31 -0400 | [diff] [blame] | 2594 | |
Alex Wu | 4539b08 | 2012-03-01 12:57:46 +0800 | [diff] [blame] | 2595 | break; |
| 2596 | case WL_SHELL_SURFACE_FULLSCREEN_METHOD_DRIVER: |
Alex Wu | bd3354b | 2012-04-17 17:20:49 +0800 | [diff] [blame] | 2597 | if (shell_surface_is_top_fullscreen(shsurf)) { |
Quentin Glidic | c0d79ce | 2013-01-29 14:16:13 +0100 | [diff] [blame] | 2598 | struct weston_mode mode = {0, |
Pekka Paalanen | 1fd9c0f | 2013-11-26 18:19:41 +0100 | [diff] [blame] | 2599 | surf_width * surface->buffer_viewport.scale, |
| 2600 | surf_height * surface->buffer_viewport.scale, |
Alex Wu | bd3354b | 2012-04-17 17:20:49 +0800 | [diff] [blame] | 2601 | shsurf->fullscreen.framerate}; |
| 2602 | |
Pekka Paalanen | 1fd9c0f | 2013-11-26 18:19:41 +0100 | [diff] [blame] | 2603 | if (weston_output_switch_mode(output, &mode, surface->buffer_viewport.scale, |
Hardening | 57388e4 | 2013-09-18 23:56:36 +0200 | [diff] [blame] | 2604 | WESTON_MODE_SWITCH_SET_TEMPORARY) == 0) { |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 2605 | weston_view_set_position(shsurf->view, |
| 2606 | output->x - surf_x, |
| 2607 | output->y - surf_y); |
Jason Ekstrand | 918f2dd | 2013-12-02 21:01:53 -0600 | [diff] [blame] | 2608 | shsurf->fullscreen.black_view->surface->width = output->width; |
| 2609 | shsurf->fullscreen.black_view->surface->height = output->height; |
| 2610 | weston_view_set_position(shsurf->fullscreen.black_view, |
| 2611 | output->x - surf_x, |
| 2612 | output->y - surf_y); |
Alex Wu | bd3354b | 2012-04-17 17:20:49 +0800 | [diff] [blame] | 2613 | break; |
Alexander Larsson | d622ed3 | 2013-05-28 16:23:40 +0200 | [diff] [blame] | 2614 | } else { |
Alexander Larsson | f82b6ca | 2013-05-28 16:23:39 +0200 | [diff] [blame] | 2615 | restore_output_mode(output); |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 2616 | center_on_output(shsurf->view, output); |
Alexander Larsson | d622ed3 | 2013-05-28 16:23:40 +0200 | [diff] [blame] | 2617 | } |
Alex Wu | bd3354b | 2012-04-17 17:20:49 +0800 | [diff] [blame] | 2618 | } |
Alex Wu | 4539b08 | 2012-03-01 12:57:46 +0800 | [diff] [blame] | 2619 | break; |
| 2620 | case WL_SHELL_SURFACE_FULLSCREEN_METHOD_FILL: |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 2621 | center_on_output(shsurf->view, output); |
Alex Wu | 4539b08 | 2012-03-01 12:57:46 +0800 | [diff] [blame] | 2622 | break; |
| 2623 | default: |
| 2624 | break; |
| 2625 | } |
| 2626 | } |
| 2627 | |
Alex Wu | 4539b08 | 2012-03-01 12:57:46 +0800 | [diff] [blame] | 2628 | static void |
| 2629 | shell_map_fullscreen(struct shell_surface *shsurf) |
| 2630 | { |
Alex Wu | bd3354b | 2012-04-17 17:20:49 +0800 | [diff] [blame] | 2631 | shell_configure_fullscreen(shsurf); |
Alex Wu | 4539b08 | 2012-03-01 12:57:46 +0800 | [diff] [blame] | 2632 | } |
| 2633 | |
Kristian Høgsberg | 7a5c979 | 2011-06-18 06:12:54 -0400 | [diff] [blame] | 2634 | static void |
Tiago Vignatti | fb2adba | 2013-06-12 15:43:21 -0300 | [diff] [blame] | 2635 | set_xwayland(struct shell_surface *shsurf, int x, int y, uint32_t flags) |
| 2636 | { |
| 2637 | /* XXX: using the same fields for transient type */ |
Rafael Antognolli | 03b1659 | 2013-12-03 15:35:42 -0200 | [diff] [blame] | 2638 | surface_clear_next_states(shsurf); |
Tiago Vignatti | fb2adba | 2013-06-12 15:43:21 -0300 | [diff] [blame] | 2639 | shsurf->transient.x = x; |
| 2640 | shsurf->transient.y = y; |
| 2641 | shsurf->transient.flags = flags; |
Philip Withnall | dc4332f | 2013-11-25 18:01:38 +0000 | [diff] [blame] | 2642 | |
| 2643 | shell_surface_set_parent(shsurf, NULL); |
| 2644 | |
Kristian Høgsberg | c8f8dd8 | 2013-12-05 23:20:33 -0800 | [diff] [blame] | 2645 | shsurf->type = SHELL_SURFACE_XWAYLAND; |
Kristian Høgsberg | 8bc525c | 2014-01-01 22:34:49 -0800 | [diff] [blame] | 2646 | shsurf->state_changed = true; |
Tiago Vignatti | fb2adba | 2013-06-12 15:43:21 -0300 | [diff] [blame] | 2647 | } |
| 2648 | |
Kristian Høgsberg | 02bbabb | 2013-05-06 22:15:05 -0400 | [diff] [blame] | 2649 | static const struct weston_pointer_grab_interface popup_grab_interface; |
Giulio Camuffo | 5085a75 | 2013-03-25 21:42:45 +0100 | [diff] [blame] | 2650 | |
| 2651 | static void |
| 2652 | destroy_shell_seat(struct wl_listener *listener, void *data) |
| 2653 | { |
| 2654 | struct shell_seat *shseat = |
| 2655 | container_of(listener, |
| 2656 | struct shell_seat, seat_destroy_listener); |
| 2657 | struct shell_surface *shsurf, *prev = NULL; |
| 2658 | |
| 2659 | if (shseat->popup_grab.grab.interface == &popup_grab_interface) { |
Kristian Høgsberg | 02bbabb | 2013-05-06 22:15:05 -0400 | [diff] [blame] | 2660 | weston_pointer_end_grab(shseat->popup_grab.grab.pointer); |
Giulio Camuffo | 5085a75 | 2013-03-25 21:42:45 +0100 | [diff] [blame] | 2661 | shseat->popup_grab.client = NULL; |
| 2662 | |
| 2663 | wl_list_for_each(shsurf, &shseat->popup_grab.surfaces_list, popup.grab_link) { |
| 2664 | shsurf->popup.shseat = NULL; |
| 2665 | if (prev) { |
| 2666 | wl_list_init(&prev->popup.grab_link); |
| 2667 | } |
| 2668 | prev = shsurf; |
| 2669 | } |
| 2670 | wl_list_init(&prev->popup.grab_link); |
| 2671 | } |
| 2672 | |
| 2673 | wl_list_remove(&shseat->seat_destroy_listener.link); |
| 2674 | free(shseat); |
| 2675 | } |
| 2676 | |
| 2677 | static struct shell_seat * |
| 2678 | create_shell_seat(struct weston_seat *seat) |
| 2679 | { |
| 2680 | struct shell_seat *shseat; |
| 2681 | |
| 2682 | shseat = calloc(1, sizeof *shseat); |
| 2683 | if (!shseat) { |
| 2684 | weston_log("no memory to allocate shell seat\n"); |
| 2685 | return NULL; |
| 2686 | } |
| 2687 | |
| 2688 | shseat->seat = seat; |
| 2689 | wl_list_init(&shseat->popup_grab.surfaces_list); |
| 2690 | |
| 2691 | shseat->seat_destroy_listener.notify = destroy_shell_seat; |
| 2692 | wl_signal_add(&seat->destroy_signal, |
| 2693 | &shseat->seat_destroy_listener); |
| 2694 | |
| 2695 | return shseat; |
| 2696 | } |
| 2697 | |
| 2698 | static struct shell_seat * |
| 2699 | get_shell_seat(struct weston_seat *seat) |
| 2700 | { |
| 2701 | struct wl_listener *listener; |
| 2702 | |
| 2703 | listener = wl_signal_get(&seat->destroy_signal, destroy_shell_seat); |
| 2704 | if (listener == NULL) |
| 2705 | return create_shell_seat(seat); |
| 2706 | |
| 2707 | return container_of(listener, |
| 2708 | struct shell_seat, seat_destroy_listener); |
| 2709 | } |
| 2710 | |
Kristian Høgsberg | b810eb5 | 2013-02-12 20:07:05 -0500 | [diff] [blame] | 2711 | static void |
Kristian Høgsberg | 6848c25 | 2013-05-08 22:02:59 -0400 | [diff] [blame] | 2712 | popup_grab_focus(struct weston_pointer_grab *grab) |
Kristian Høgsberg | b3cca0a | 2012-01-04 22:19:14 -0500 | [diff] [blame] | 2713 | { |
Kristian Høgsberg | 02bbabb | 2013-05-06 22:15:05 -0400 | [diff] [blame] | 2714 | struct weston_pointer *pointer = grab->pointer; |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 2715 | struct weston_view *view; |
Giulio Camuffo | 5085a75 | 2013-03-25 21:42:45 +0100 | [diff] [blame] | 2716 | struct shell_seat *shseat = |
| 2717 | container_of(grab, struct shell_seat, popup_grab.grab); |
| 2718 | struct wl_client *client = shseat->popup_grab.client; |
Kristian Høgsberg | 6848c25 | 2013-05-08 22:02:59 -0400 | [diff] [blame] | 2719 | wl_fixed_t sx, sy; |
| 2720 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 2721 | view = weston_compositor_pick_view(pointer->seat->compositor, |
| 2722 | pointer->x, pointer->y, |
| 2723 | &sx, &sy); |
Kristian Høgsberg | b3cca0a | 2012-01-04 22:19:14 -0500 | [diff] [blame] | 2724 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 2725 | if (view && view->surface->resource && |
| 2726 | wl_resource_get_client(view->surface->resource) == client) { |
| 2727 | weston_pointer_set_focus(pointer, view, sx, sy); |
Kristian Høgsberg | b3cca0a | 2012-01-04 22:19:14 -0500 | [diff] [blame] | 2728 | } else { |
Kristian Høgsberg | 02bbabb | 2013-05-06 22:15:05 -0400 | [diff] [blame] | 2729 | weston_pointer_set_focus(pointer, NULL, |
| 2730 | wl_fixed_from_int(0), |
| 2731 | wl_fixed_from_int(0)); |
Kristian Høgsberg | b3cca0a | 2012-01-04 22:19:14 -0500 | [diff] [blame] | 2732 | } |
| 2733 | } |
| 2734 | |
| 2735 | static void |
Giulio Camuffo | 1959ab8 | 2013-11-14 23:42:52 +0100 | [diff] [blame] | 2736 | popup_grab_motion(struct weston_pointer_grab *grab, uint32_t time, |
| 2737 | wl_fixed_t x, wl_fixed_t y) |
Kristian Høgsberg | b3cca0a | 2012-01-04 22:19:14 -0500 | [diff] [blame] | 2738 | { |
Kristian Høgsberg | be6403e | 2013-05-08 21:03:21 -0400 | [diff] [blame] | 2739 | struct weston_pointer *pointer = grab->pointer; |
Neil Roberts | 96d790e | 2013-09-19 17:32:00 +0100 | [diff] [blame] | 2740 | struct wl_resource *resource; |
Kristian Høgsberg | be6403e | 2013-05-08 21:03:21 -0400 | [diff] [blame] | 2741 | wl_fixed_t sx, sy; |
Kristian Høgsberg | b3cca0a | 2012-01-04 22:19:14 -0500 | [diff] [blame] | 2742 | |
Giulio Camuffo | 1959ab8 | 2013-11-14 23:42:52 +0100 | [diff] [blame] | 2743 | weston_pointer_move(pointer, x, y); |
| 2744 | |
Neil Roberts | 96d790e | 2013-09-19 17:32:00 +0100 | [diff] [blame] | 2745 | wl_resource_for_each(resource, &pointer->focus_resource_list) { |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 2746 | weston_view_from_global_fixed(pointer->focus, |
| 2747 | pointer->x, pointer->y, |
| 2748 | &sx, &sy); |
Neil Roberts | 96d790e | 2013-09-19 17:32:00 +0100 | [diff] [blame] | 2749 | wl_pointer_send_motion(resource, time, sx, sy); |
Kristian Høgsberg | be6403e | 2013-05-08 21:03:21 -0400 | [diff] [blame] | 2750 | } |
Kristian Høgsberg | b3cca0a | 2012-01-04 22:19:14 -0500 | [diff] [blame] | 2751 | } |
| 2752 | |
| 2753 | static void |
Kristian Høgsberg | 02bbabb | 2013-05-06 22:15:05 -0400 | [diff] [blame] | 2754 | popup_grab_button(struct weston_pointer_grab *grab, |
Daniel Stone | 4dbadb1 | 2012-05-30 16:31:51 +0100 | [diff] [blame] | 2755 | uint32_t time, uint32_t button, uint32_t state_w) |
Kristian Høgsberg | b3cca0a | 2012-01-04 22:19:14 -0500 | [diff] [blame] | 2756 | { |
| 2757 | struct wl_resource *resource; |
Giulio Camuffo | 5085a75 | 2013-03-25 21:42:45 +0100 | [diff] [blame] | 2758 | struct shell_seat *shseat = |
| 2759 | container_of(grab, struct shell_seat, popup_grab.grab); |
Rob Bradford | 880ebc7 | 2013-07-22 17:31:38 +0100 | [diff] [blame] | 2760 | struct wl_display *display = shseat->seat->compositor->wl_display; |
Daniel Stone | 4dbadb1 | 2012-05-30 16:31:51 +0100 | [diff] [blame] | 2761 | enum wl_pointer_button_state state = state_w; |
Kristian Høgsberg | eae5de7 | 2012-04-11 22:42:15 -0400 | [diff] [blame] | 2762 | uint32_t serial; |
Neil Roberts | 96d790e | 2013-09-19 17:32:00 +0100 | [diff] [blame] | 2763 | struct wl_list *resource_list; |
Kristian Høgsberg | b3cca0a | 2012-01-04 22:19:14 -0500 | [diff] [blame] | 2764 | |
Neil Roberts | 96d790e | 2013-09-19 17:32:00 +0100 | [diff] [blame] | 2765 | resource_list = &grab->pointer->focus_resource_list; |
| 2766 | if (!wl_list_empty(resource_list)) { |
Kristian Høgsberg | eae5de7 | 2012-04-11 22:42:15 -0400 | [diff] [blame] | 2767 | serial = wl_display_get_serial(display); |
Neil Roberts | 96d790e | 2013-09-19 17:32:00 +0100 | [diff] [blame] | 2768 | wl_resource_for_each(resource, resource_list) { |
| 2769 | wl_pointer_send_button(resource, serial, |
| 2770 | time, button, state); |
| 2771 | } |
Daniel Stone | 4dbadb1 | 2012-05-30 16:31:51 +0100 | [diff] [blame] | 2772 | } else if (state == WL_POINTER_BUTTON_STATE_RELEASED && |
Giulio Camuffo | 5085a75 | 2013-03-25 21:42:45 +0100 | [diff] [blame] | 2773 | (shseat->popup_grab.initial_up || |
Kristian Høgsberg | e314875 | 2013-05-06 23:19:49 -0400 | [diff] [blame] | 2774 | time - shseat->seat->pointer->grab_time > 500)) { |
Kristian Høgsberg | 57e0907 | 2012-10-30 14:07:27 -0400 | [diff] [blame] | 2775 | popup_grab_end(grab->pointer); |
Kristian Høgsberg | b3cca0a | 2012-01-04 22:19:14 -0500 | [diff] [blame] | 2776 | } |
| 2777 | |
Daniel Stone | 4dbadb1 | 2012-05-30 16:31:51 +0100 | [diff] [blame] | 2778 | if (state == WL_POINTER_BUTTON_STATE_RELEASED) |
Giulio Camuffo | 5085a75 | 2013-03-25 21:42:45 +0100 | [diff] [blame] | 2779 | shseat->popup_grab.initial_up = 1; |
Kristian Høgsberg | b3cca0a | 2012-01-04 22:19:14 -0500 | [diff] [blame] | 2780 | } |
| 2781 | |
Jonas Ådahl | 1ea343e | 2013-10-25 23:18:05 +0200 | [diff] [blame] | 2782 | static void |
| 2783 | popup_grab_cancel(struct weston_pointer_grab *grab) |
| 2784 | { |
| 2785 | popup_grab_end(grab->pointer); |
| 2786 | } |
| 2787 | |
Kristian Høgsberg | 02bbabb | 2013-05-06 22:15:05 -0400 | [diff] [blame] | 2788 | static const struct weston_pointer_grab_interface popup_grab_interface = { |
Kristian Høgsberg | b3cca0a | 2012-01-04 22:19:14 -0500 | [diff] [blame] | 2789 | popup_grab_focus, |
| 2790 | popup_grab_motion, |
| 2791 | popup_grab_button, |
Jonas Ådahl | 1ea343e | 2013-10-25 23:18:05 +0200 | [diff] [blame] | 2792 | popup_grab_cancel, |
Kristian Høgsberg | b3cca0a | 2012-01-04 22:19:14 -0500 | [diff] [blame] | 2793 | }; |
| 2794 | |
| 2795 | static void |
Rafael Antognolli | e2a3455 | 2013-12-03 15:35:45 -0200 | [diff] [blame] | 2796 | shell_surface_send_popup_done(struct shell_surface *shsurf) |
| 2797 | { |
| 2798 | if (shell_surface_is_wl_shell_surface(shsurf)) |
| 2799 | wl_shell_surface_send_popup_done(shsurf->resource); |
| 2800 | else if (shell_surface_is_xdg_popup(shsurf)) |
| 2801 | xdg_popup_send_popup_done(shsurf->resource, |
| 2802 | shsurf->popup.serial); |
| 2803 | } |
| 2804 | |
| 2805 | static void |
Kristian Høgsberg | 02bbabb | 2013-05-06 22:15:05 -0400 | [diff] [blame] | 2806 | popup_grab_end(struct weston_pointer *pointer) |
Kristian Høgsberg | 57e0907 | 2012-10-30 14:07:27 -0400 | [diff] [blame] | 2807 | { |
Kristian Høgsberg | 02bbabb | 2013-05-06 22:15:05 -0400 | [diff] [blame] | 2808 | struct weston_pointer_grab *grab = pointer->grab; |
Giulio Camuffo | 5085a75 | 2013-03-25 21:42:45 +0100 | [diff] [blame] | 2809 | struct shell_seat *shseat = |
| 2810 | container_of(grab, struct shell_seat, popup_grab.grab); |
| 2811 | struct shell_surface *shsurf; |
| 2812 | struct shell_surface *prev = NULL; |
Kristian Høgsberg | 57e0907 | 2012-10-30 14:07:27 -0400 | [diff] [blame] | 2813 | |
| 2814 | if (pointer->grab->interface == &popup_grab_interface) { |
Kristian Høgsberg | 02bbabb | 2013-05-06 22:15:05 -0400 | [diff] [blame] | 2815 | weston_pointer_end_grab(grab->pointer); |
Giulio Camuffo | 5085a75 | 2013-03-25 21:42:45 +0100 | [diff] [blame] | 2816 | shseat->popup_grab.client = NULL; |
Philipp Brüschweiler | 63e7be6 | 2013-04-15 21:09:54 +0200 | [diff] [blame] | 2817 | shseat->popup_grab.grab.interface = NULL; |
| 2818 | assert(!wl_list_empty(&shseat->popup_grab.surfaces_list)); |
Giulio Camuffo | 5085a75 | 2013-03-25 21:42:45 +0100 | [diff] [blame] | 2819 | /* Send the popup_done event to all the popups open */ |
| 2820 | 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] | 2821 | shell_surface_send_popup_done(shsurf); |
Giulio Camuffo | 5085a75 | 2013-03-25 21:42:45 +0100 | [diff] [blame] | 2822 | shsurf->popup.shseat = NULL; |
| 2823 | if (prev) { |
| 2824 | wl_list_init(&prev->popup.grab_link); |
| 2825 | } |
| 2826 | prev = shsurf; |
| 2827 | } |
| 2828 | wl_list_init(&prev->popup.grab_link); |
| 2829 | wl_list_init(&shseat->popup_grab.surfaces_list); |
| 2830 | } |
| 2831 | } |
| 2832 | |
| 2833 | static void |
| 2834 | add_popup_grab(struct shell_surface *shsurf, struct shell_seat *shseat) |
| 2835 | { |
Kristian Høgsberg | e314875 | 2013-05-06 23:19:49 -0400 | [diff] [blame] | 2836 | struct weston_seat *seat = shseat->seat; |
Giulio Camuffo | 5085a75 | 2013-03-25 21:42:45 +0100 | [diff] [blame] | 2837 | |
| 2838 | if (wl_list_empty(&shseat->popup_grab.surfaces_list)) { |
Jason Ekstrand | 651f00e | 2013-06-14 10:07:54 -0500 | [diff] [blame] | 2839 | shseat->popup_grab.client = wl_resource_get_client(shsurf->resource); |
Giulio Camuffo | 5085a75 | 2013-03-25 21:42:45 +0100 | [diff] [blame] | 2840 | shseat->popup_grab.grab.interface = &popup_grab_interface; |
Giulio Camuffo | 1b4b61a | 2013-03-27 18:05:26 +0100 | [diff] [blame] | 2841 | /* We must make sure here that this popup was opened after |
| 2842 | * a mouse press, and not just by moving around with other |
| 2843 | * popups already open. */ |
Kristian Høgsberg | e314875 | 2013-05-06 23:19:49 -0400 | [diff] [blame] | 2844 | if (shseat->seat->pointer->button_count > 0) |
Giulio Camuffo | 1b4b61a | 2013-03-27 18:05:26 +0100 | [diff] [blame] | 2845 | shseat->popup_grab.initial_up = 0; |
Giulio Camuffo | 5085a75 | 2013-03-25 21:42:45 +0100 | [diff] [blame] | 2846 | |
Rob Bradford | dfe3105 | 2013-06-26 19:49:11 +0100 | [diff] [blame] | 2847 | 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] | 2848 | weston_pointer_start_grab(seat->pointer, &shseat->popup_grab.grab); |
Rob Bradford | dfe3105 | 2013-06-26 19:49:11 +0100 | [diff] [blame] | 2849 | } else { |
| 2850 | wl_list_insert(&shseat->popup_grab.surfaces_list, &shsurf->popup.grab_link); |
Giulio Camuffo | 5085a75 | 2013-03-25 21:42:45 +0100 | [diff] [blame] | 2851 | } |
Giulio Camuffo | 5085a75 | 2013-03-25 21:42:45 +0100 | [diff] [blame] | 2852 | } |
| 2853 | |
| 2854 | static void |
| 2855 | remove_popup_grab(struct shell_surface *shsurf) |
| 2856 | { |
| 2857 | struct shell_seat *shseat = shsurf->popup.shseat; |
| 2858 | |
| 2859 | wl_list_remove(&shsurf->popup.grab_link); |
| 2860 | wl_list_init(&shsurf->popup.grab_link); |
| 2861 | if (wl_list_empty(&shseat->popup_grab.surfaces_list)) { |
Kristian Høgsberg | 02bbabb | 2013-05-06 22:15:05 -0400 | [diff] [blame] | 2862 | weston_pointer_end_grab(shseat->popup_grab.grab.pointer); |
Philipp Brüschweiler | 63e7be6 | 2013-04-15 21:09:54 +0200 | [diff] [blame] | 2863 | shseat->popup_grab.grab.interface = NULL; |
Kristian Høgsberg | 57e0907 | 2012-10-30 14:07:27 -0400 | [diff] [blame] | 2864 | } |
| 2865 | } |
| 2866 | |
| 2867 | static void |
Kristian Høgsberg | 3730f36 | 2012-04-13 12:40:07 -0400 | [diff] [blame] | 2868 | shell_map_popup(struct shell_surface *shsurf) |
Kristian Høgsberg | b3cca0a | 2012-01-04 22:19:14 -0500 | [diff] [blame] | 2869 | { |
Giulio Camuffo | 5085a75 | 2013-03-25 21:42:45 +0100 | [diff] [blame] | 2870 | struct shell_seat *shseat = shsurf->popup.shseat; |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 2871 | struct weston_view *parent_view = get_default_view(shsurf->parent); |
Kristian Høgsberg | b3cca0a | 2012-01-04 22:19:14 -0500 | [diff] [blame] | 2872 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 2873 | shsurf->surface->output = parent_view->output; |
| 2874 | shsurf->view->output = parent_view->output; |
Kristian Høgsberg | b3cca0a | 2012-01-04 22:19:14 -0500 | [diff] [blame] | 2875 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 2876 | weston_view_set_transform_parent(shsurf->view, parent_view); |
| 2877 | weston_view_set_position(shsurf->view, shsurf->popup.x, shsurf->popup.y); |
| 2878 | weston_view_update_transform(shsurf->view); |
Kristian Høgsberg | b3cca0a | 2012-01-04 22:19:14 -0500 | [diff] [blame] | 2879 | |
Kristian Høgsberg | e314875 | 2013-05-06 23:19:49 -0400 | [diff] [blame] | 2880 | if (shseat->seat->pointer->grab_serial == shsurf->popup.serial) { |
Giulio Camuffo | 5085a75 | 2013-03-25 21:42:45 +0100 | [diff] [blame] | 2881 | add_popup_grab(shsurf, shseat); |
Kristian Høgsberg | 3730f36 | 2012-04-13 12:40:07 -0400 | [diff] [blame] | 2882 | } else { |
Rafael Antognolli | e2a3455 | 2013-12-03 15:35:45 -0200 | [diff] [blame] | 2883 | shell_surface_send_popup_done(shsurf); |
Giulio Camuffo | 5085a75 | 2013-03-25 21:42:45 +0100 | [diff] [blame] | 2884 | shseat->popup_grab.client = NULL; |
Kristian Høgsberg | 3730f36 | 2012-04-13 12:40:07 -0400 | [diff] [blame] | 2885 | } |
Kristian Høgsberg | b3cca0a | 2012-01-04 22:19:14 -0500 | [diff] [blame] | 2886 | } |
| 2887 | |
Pekka Paalanen | 9d1613e | 2011-11-25 12:09:16 +0200 | [diff] [blame] | 2888 | static const struct wl_shell_surface_interface shell_surface_implementation = { |
Scott Moreau | ff1db4a | 2012-04-17 19:06:18 -0600 | [diff] [blame] | 2889 | shell_surface_pong, |
Pekka Paalanen | 9d1613e | 2011-11-25 12:09:16 +0200 | [diff] [blame] | 2890 | shell_surface_move, |
| 2891 | shell_surface_resize, |
| 2892 | shell_surface_set_toplevel, |
| 2893 | shell_surface_set_transient, |
Kristian Høgsberg | b3cca0a | 2012-01-04 22:19:14 -0500 | [diff] [blame] | 2894 | shell_surface_set_fullscreen, |
Juan Zhao | 96879df | 2012-02-07 08:45:41 +0800 | [diff] [blame] | 2895 | shell_surface_set_popup, |
Kristian Høgsberg | e7afd91 | 2012-05-02 09:47:44 -0400 | [diff] [blame] | 2896 | shell_surface_set_maximized, |
| 2897 | shell_surface_set_title, |
| 2898 | shell_surface_set_class |
Pekka Paalanen | 9d1613e | 2011-11-25 12:09:16 +0200 | [diff] [blame] | 2899 | }; |
| 2900 | |
| 2901 | static void |
Tiago Vignatti | bc052c9 | 2012-04-19 16:18:18 +0300 | [diff] [blame] | 2902 | destroy_shell_surface(struct shell_surface *shsurf) |
Pekka Paalanen | 9d1613e | 2011-11-25 12:09:16 +0200 | [diff] [blame] | 2903 | { |
Kristian Høgsberg | 9046d24 | 2014-01-10 00:25:30 -0800 | [diff] [blame] | 2904 | struct shell_surface *child, *next; |
| 2905 | |
Jason Ekstrand | 651f00e | 2013-06-14 10:07:54 -0500 | [diff] [blame] | 2906 | wl_signal_emit(&shsurf->destroy_signal, shsurf); |
| 2907 | |
Giulio Camuffo | 5085a75 | 2013-03-25 21:42:45 +0100 | [diff] [blame] | 2908 | if (!wl_list_empty(&shsurf->popup.grab_link)) { |
| 2909 | remove_popup_grab(shsurf); |
| 2910 | } |
Kristian Høgsberg | b3cca0a | 2012-01-04 22:19:14 -0500 | [diff] [blame] | 2911 | |
Alex Wu | bd3354b | 2012-04-17 17:20:49 +0800 | [diff] [blame] | 2912 | if (shsurf->fullscreen.type == WL_SHELL_SURFACE_FULLSCREEN_METHOD_DRIVER && |
Alexander Larsson | f82b6ca | 2013-05-28 16:23:39 +0200 | [diff] [blame] | 2913 | shell_surface_is_top_fullscreen(shsurf)) |
| 2914 | restore_output_mode (shsurf->fullscreen_output); |
Pekka Paalanen | 9d1613e | 2011-11-25 12:09:16 +0200 | [diff] [blame] | 2915 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 2916 | if (shsurf->fullscreen.black_view) |
| 2917 | weston_surface_destroy(shsurf->fullscreen.black_view->surface); |
Alex Wu | aa08e2d | 2012-03-05 11:01:40 +0800 | [diff] [blame] | 2918 | |
Alex Wu | bd3354b | 2012-04-17 17:20:49 +0800 | [diff] [blame] | 2919 | /* As destroy_resource() use wl_list_for_each_safe(), |
| 2920 | * we can always remove the listener. |
| 2921 | */ |
| 2922 | wl_list_remove(&shsurf->surface_destroy_listener.link); |
| 2923 | shsurf->surface->configure = NULL; |
Scott Moreau | 9521d5e | 2012-04-19 13:06:17 -0600 | [diff] [blame] | 2924 | ping_timer_destroy(shsurf); |
Scott Moreau | 976a050 | 2013-03-07 10:15:17 -0700 | [diff] [blame] | 2925 | free(shsurf->title); |
Alex Wu | bd3354b | 2012-04-17 17:20:49 +0800 | [diff] [blame] | 2926 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 2927 | weston_view_destroy(shsurf->view); |
| 2928 | |
Philip Withnall | 648a4dd | 2013-11-25 18:01:44 +0000 | [diff] [blame] | 2929 | wl_list_remove(&shsurf->children_link); |
Kristian Høgsberg | 9046d24 | 2014-01-10 00:25:30 -0800 | [diff] [blame] | 2930 | wl_list_for_each_safe(child, next, &shsurf->children_list, children_link) { |
| 2931 | wl_list_remove(&child->children_link); |
| 2932 | child->parent = NULL; |
| 2933 | } |
Philip Withnall | 648a4dd | 2013-11-25 18:01:44 +0000 | [diff] [blame] | 2934 | |
Pekka Paalanen | 9d1613e | 2011-11-25 12:09:16 +0200 | [diff] [blame] | 2935 | wl_list_remove(&shsurf->link); |
| 2936 | free(shsurf); |
| 2937 | } |
| 2938 | |
| 2939 | static void |
Tiago Vignatti | bc052c9 | 2012-04-19 16:18:18 +0300 | [diff] [blame] | 2940 | shell_destroy_shell_surface(struct wl_resource *resource) |
| 2941 | { |
Jason Ekstrand | 651f00e | 2013-06-14 10:07:54 -0500 | [diff] [blame] | 2942 | struct shell_surface *shsurf = wl_resource_get_user_data(resource); |
Tiago Vignatti | bc052c9 | 2012-04-19 16:18:18 +0300 | [diff] [blame] | 2943 | |
| 2944 | destroy_shell_surface(shsurf); |
| 2945 | } |
| 2946 | |
| 2947 | static void |
Kristian Høgsberg | 27e3052 | 2012-04-11 23:18:23 -0400 | [diff] [blame] | 2948 | shell_handle_surface_destroy(struct wl_listener *listener, void *data) |
Pekka Paalanen | 9d1613e | 2011-11-25 12:09:16 +0200 | [diff] [blame] | 2949 | { |
| 2950 | struct shell_surface *shsurf = container_of(listener, |
| 2951 | struct shell_surface, |
| 2952 | surface_destroy_listener); |
| 2953 | |
Jason Ekstrand | 651f00e | 2013-06-14 10:07:54 -0500 | [diff] [blame] | 2954 | if (shsurf->resource) |
| 2955 | wl_resource_destroy(shsurf->resource); |
| 2956 | else |
Tiago Vignatti | bc052c9 | 2012-04-19 16:18:18 +0300 | [diff] [blame] | 2957 | destroy_shell_surface(shsurf); |
Pekka Paalanen | 9d1613e | 2011-11-25 12:09:16 +0200 | [diff] [blame] | 2958 | } |
| 2959 | |
Kristian Høgsberg | d813445 | 2012-06-21 12:49:02 -0400 | [diff] [blame] | 2960 | static void |
Jason Ekstrand | 918f2dd | 2013-12-02 21:01:53 -0600 | [diff] [blame] | 2961 | shell_surface_configure(struct weston_surface *, int32_t, int32_t); |
Zhang, Xiong Y | 3123693 | 2013-12-13 22:10:57 +0200 | [diff] [blame] | 2962 | static void |
| 2963 | shell_surface_output_destroyed(struct weston_surface *); |
Kristian Høgsberg | d813445 | 2012-06-21 12:49:02 -0400 | [diff] [blame] | 2964 | |
Kristian Høgsberg | 1ef2313 | 2013-12-04 00:20:01 -0800 | [diff] [blame] | 2965 | struct shell_surface * |
Kristian Høgsberg | 8334bc1 | 2012-01-03 10:29:47 -0500 | [diff] [blame] | 2966 | get_shell_surface(struct weston_surface *surface) |
Pekka Paalanen | ec2b32f | 2011-11-28 15:12:34 +0200 | [diff] [blame] | 2967 | { |
Kristian Høgsberg | d813445 | 2012-06-21 12:49:02 -0400 | [diff] [blame] | 2968 | if (surface->configure == shell_surface_configure) |
Giulio Camuffo | 7fe01b1 | 2013-03-28 18:02:42 +0100 | [diff] [blame] | 2969 | return surface->configure_private; |
Kristian Høgsberg | d813445 | 2012-06-21 12:49:02 -0400 | [diff] [blame] | 2970 | else |
| 2971 | return NULL; |
Pekka Paalanen | ec2b32f | 2011-11-28 15:12:34 +0200 | [diff] [blame] | 2972 | } |
| 2973 | |
Rafael Antognolli | e2a3455 | 2013-12-03 15:35:45 -0200 | [diff] [blame] | 2974 | static struct shell_surface * |
| 2975 | create_common_surface(void *shell, struct weston_surface *surface, |
| 2976 | const struct weston_shell_client *client) |
Pekka Paalanen | 9d1613e | 2011-11-25 12:09:16 +0200 | [diff] [blame] | 2977 | { |
Pekka Paalanen | 9d1613e | 2011-11-25 12:09:16 +0200 | [diff] [blame] | 2978 | struct shell_surface *shsurf; |
| 2979 | |
Ander Conselvan de Oliveira | 093bfa3 | 2012-03-27 17:36:41 +0300 | [diff] [blame] | 2980 | if (surface->configure) { |
Martin Minarik | 6d11836 | 2012-06-07 18:01:59 +0200 | [diff] [blame] | 2981 | weston_log("surface->configure already set\n"); |
Kristian Høgsberg | 45ba869 | 2012-05-21 14:27:33 -0400 | [diff] [blame] | 2982 | return NULL; |
Ander Conselvan de Oliveira | 093bfa3 | 2012-03-27 17:36:41 +0300 | [diff] [blame] | 2983 | } |
| 2984 | |
Pekka Paalanen | 9d1613e | 2011-11-25 12:09:16 +0200 | [diff] [blame] | 2985 | shsurf = calloc(1, sizeof *shsurf); |
| 2986 | if (!shsurf) { |
Martin Minarik | 6d11836 | 2012-06-07 18:01:59 +0200 | [diff] [blame] | 2987 | weston_log("no memory to allocate shell surface\n"); |
Kristian Høgsberg | 45ba869 | 2012-05-21 14:27:33 -0400 | [diff] [blame] | 2988 | return NULL; |
Pekka Paalanen | 9d1613e | 2011-11-25 12:09:16 +0200 | [diff] [blame] | 2989 | } |
| 2990 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 2991 | shsurf->view = weston_view_create(surface); |
| 2992 | if (!shsurf->view) { |
| 2993 | weston_log("no memory to allocate shell surface\n"); |
| 2994 | free(shsurf); |
| 2995 | return NULL; |
| 2996 | } |
| 2997 | |
Ander Conselvan de Oliveira | 093bfa3 | 2012-03-27 17:36:41 +0300 | [diff] [blame] | 2998 | surface->configure = shell_surface_configure; |
Giulio Camuffo | 7fe01b1 | 2013-03-28 18:02:42 +0100 | [diff] [blame] | 2999 | surface->configure_private = shsurf; |
Zhang, Xiong Y | 3123693 | 2013-12-13 22:10:57 +0200 | [diff] [blame] | 3000 | surface->output_destroyed = shell_surface_output_destroyed; |
Ander Conselvan de Oliveira | 093bfa3 | 2012-03-27 17:36:41 +0300 | [diff] [blame] | 3001 | |
Tiago Vignatti | bc052c9 | 2012-04-19 16:18:18 +0300 | [diff] [blame] | 3002 | shsurf->shell = (struct desktop_shell *) shell; |
Scott Moreau | ff1db4a | 2012-04-17 19:06:18 -0600 | [diff] [blame] | 3003 | shsurf->unresponsive = 0; |
Alex Wu | 4539b08 | 2012-03-01 12:57:46 +0800 | [diff] [blame] | 3004 | shsurf->saved_position_valid = false; |
Rafael Antognolli | 3c4e3f7 | 2013-12-03 15:35:46 -0200 | [diff] [blame] | 3005 | shsurf->saved_size_valid = false; |
Alex Wu | 7bcb8bd | 2012-04-27 09:07:24 +0800 | [diff] [blame] | 3006 | shsurf->saved_rotation_valid = false; |
Pekka Paalanen | 9d1613e | 2011-11-25 12:09:16 +0200 | [diff] [blame] | 3007 | shsurf->surface = surface; |
Alex Wu | 4539b08 | 2012-03-01 12:57:46 +0800 | [diff] [blame] | 3008 | shsurf->fullscreen.type = WL_SHELL_SURFACE_FULLSCREEN_METHOD_DEFAULT; |
| 3009 | shsurf->fullscreen.framerate = 0; |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 3010 | shsurf->fullscreen.black_view = NULL; |
Scott Moreau | ff1db4a | 2012-04-17 19:06:18 -0600 | [diff] [blame] | 3011 | shsurf->ping_timer = NULL; |
Alex Wu | 4539b08 | 2012-03-01 12:57:46 +0800 | [diff] [blame] | 3012 | wl_list_init(&shsurf->fullscreen.transform.link); |
| 3013 | |
Jason Ekstrand | 651f00e | 2013-06-14 10:07:54 -0500 | [diff] [blame] | 3014 | wl_signal_init(&shsurf->destroy_signal); |
Kristian Høgsberg | 27e3052 | 2012-04-11 23:18:23 -0400 | [diff] [blame] | 3015 | shsurf->surface_destroy_listener.notify = shell_handle_surface_destroy; |
Jason Ekstrand | 26ed73c | 2013-06-06 22:34:41 -0500 | [diff] [blame] | 3016 | wl_signal_add(&surface->destroy_signal, |
Kristian Høgsberg | 27e3052 | 2012-04-11 23:18:23 -0400 | [diff] [blame] | 3017 | &shsurf->surface_destroy_listener); |
Pekka Paalanen | 9d1613e | 2011-11-25 12:09:16 +0200 | [diff] [blame] | 3018 | |
| 3019 | /* init link so its safe to always remove it in destroy_shell_surface */ |
| 3020 | wl_list_init(&shsurf->link); |
Giulio Camuffo | 5085a75 | 2013-03-25 21:42:45 +0100 | [diff] [blame] | 3021 | wl_list_init(&shsurf->popup.grab_link); |
Pekka Paalanen | 9d1613e | 2011-11-25 12:09:16 +0200 | [diff] [blame] | 3022 | |
Pekka Paalanen | 460099f | 2012-01-20 16:48:25 +0200 | [diff] [blame] | 3023 | /* empty when not in use */ |
| 3024 | wl_list_init(&shsurf->rotation.transform.link); |
Kristian Høgsberg | 765e27b | 2012-01-27 13:36:13 -0500 | [diff] [blame] | 3025 | weston_matrix_init(&shsurf->rotation.rotation); |
Pekka Paalanen | 460099f | 2012-01-20 16:48:25 +0200 | [diff] [blame] | 3026 | |
Jonas Ådahl | 62fcd04 | 2012-06-13 00:01:23 +0200 | [diff] [blame] | 3027 | wl_list_init(&shsurf->workspace_transform.link); |
| 3028 | |
Philip Withnall | 648a4dd | 2013-11-25 18:01:44 +0000 | [diff] [blame] | 3029 | wl_list_init(&shsurf->children_link); |
| 3030 | wl_list_init(&shsurf->children_list); |
| 3031 | shsurf->parent = NULL; |
| 3032 | |
Pekka Paalanen | 9826223 | 2011-12-01 10:42:22 +0200 | [diff] [blame] | 3033 | shsurf->type = SHELL_SURFACE_NONE; |
Pekka Paalanen | 9d1613e | 2011-11-25 12:09:16 +0200 | [diff] [blame] | 3034 | |
Kristian Høgsberg | a61ca06 | 2012-05-22 16:05:52 -0400 | [diff] [blame] | 3035 | shsurf->client = client; |
| 3036 | |
Kristian Høgsberg | 45ba869 | 2012-05-21 14:27:33 -0400 | [diff] [blame] | 3037 | return shsurf; |
Tiago Vignatti | bc052c9 | 2012-04-19 16:18:18 +0300 | [diff] [blame] | 3038 | } |
| 3039 | |
Rafael Antognolli | e2a3455 | 2013-12-03 15:35:45 -0200 | [diff] [blame] | 3040 | static struct shell_surface * |
| 3041 | create_shell_surface(void *shell, struct weston_surface *surface, |
| 3042 | const struct weston_shell_client *client) |
| 3043 | { |
Kristian Høgsberg | c8f8dd8 | 2013-12-05 23:20:33 -0800 | [diff] [blame] | 3044 | return create_common_surface(shell, surface, client); |
Rafael Antognolli | e2a3455 | 2013-12-03 15:35:45 -0200 | [diff] [blame] | 3045 | } |
| 3046 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 3047 | static struct weston_view * |
| 3048 | get_primary_view(void *shell, struct shell_surface *shsurf) |
| 3049 | { |
| 3050 | return shsurf->view; |
| 3051 | } |
| 3052 | |
Tiago Vignatti | bc052c9 | 2012-04-19 16:18:18 +0300 | [diff] [blame] | 3053 | static void |
| 3054 | shell_get_shell_surface(struct wl_client *client, |
| 3055 | struct wl_resource *resource, |
| 3056 | uint32_t id, |
| 3057 | struct wl_resource *surface_resource) |
| 3058 | { |
Jason Ekstrand | 0f2ef7e | 2013-06-14 10:07:53 -0500 | [diff] [blame] | 3059 | struct weston_surface *surface = |
| 3060 | wl_resource_get_user_data(surface_resource); |
Jason Ekstrand | 651f00e | 2013-06-14 10:07:54 -0500 | [diff] [blame] | 3061 | struct desktop_shell *shell = wl_resource_get_user_data(resource); |
Tiago Vignatti | bc052c9 | 2012-04-19 16:18:18 +0300 | [diff] [blame] | 3062 | struct shell_surface *shsurf; |
| 3063 | |
| 3064 | if (get_shell_surface(surface)) { |
| 3065 | wl_resource_post_error(surface_resource, |
Kristian Høgsberg | 9540ea6 | 2012-05-21 14:28:57 -0400 | [diff] [blame] | 3066 | WL_DISPLAY_ERROR_INVALID_OBJECT, |
| 3067 | "desktop_shell::get_shell_surface already requested"); |
Tiago Vignatti | bc052c9 | 2012-04-19 16:18:18 +0300 | [diff] [blame] | 3068 | return; |
| 3069 | } |
| 3070 | |
Kristian Høgsberg | a61ca06 | 2012-05-22 16:05:52 -0400 | [diff] [blame] | 3071 | shsurf = create_shell_surface(shell, surface, &shell_client); |
Kristian Høgsberg | 9540ea6 | 2012-05-21 14:28:57 -0400 | [diff] [blame] | 3072 | if (!shsurf) { |
| 3073 | wl_resource_post_error(surface_resource, |
| 3074 | WL_DISPLAY_ERROR_INVALID_OBJECT, |
| 3075 | "surface->configure already set"); |
| 3076 | return; |
| 3077 | } |
Tiago Vignatti | bc052c9 | 2012-04-19 16:18:18 +0300 | [diff] [blame] | 3078 | |
Jason Ekstrand | a85118c | 2013-06-27 20:17:02 -0500 | [diff] [blame] | 3079 | shsurf->resource = |
| 3080 | wl_resource_create(client, |
| 3081 | &wl_shell_surface_interface, 1, id); |
| 3082 | wl_resource_set_implementation(shsurf->resource, |
| 3083 | &shell_surface_implementation, |
| 3084 | shsurf, shell_destroy_shell_surface); |
Pekka Paalanen | 9d1613e | 2011-11-25 12:09:16 +0200 | [diff] [blame] | 3085 | } |
| 3086 | |
Rafael Antognolli | e2a3455 | 2013-12-03 15:35:45 -0200 | [diff] [blame] | 3087 | static bool |
| 3088 | shell_surface_is_wl_shell_surface(struct shell_surface *shsurf) |
| 3089 | { |
| 3090 | return wl_resource_instance_of(shsurf->resource, |
| 3091 | &wl_shell_surface_interface, |
| 3092 | &shell_surface_implementation); |
| 3093 | } |
| 3094 | |
Pekka Paalanen | 9d1613e | 2011-11-25 12:09:16 +0200 | [diff] [blame] | 3095 | static const struct wl_shell_interface shell_implementation = { |
Pekka Paalanen | 4622967 | 2011-11-29 15:49:31 +0200 | [diff] [blame] | 3096 | shell_get_shell_surface |
Kristian Høgsberg | 4cca349 | 2011-01-18 07:53:49 -0500 | [diff] [blame] | 3097 | }; |
| 3098 | |
Rafael Antognolli | e2a3455 | 2013-12-03 15:35:45 -0200 | [diff] [blame] | 3099 | /**************************** |
| 3100 | * xdg-shell implementation */ |
| 3101 | |
| 3102 | static void |
| 3103 | xdg_surface_destroy(struct wl_client *client, |
| 3104 | struct wl_resource *resource) |
| 3105 | { |
| 3106 | wl_resource_destroy(resource); |
| 3107 | } |
| 3108 | |
| 3109 | static void |
| 3110 | xdg_surface_pong(struct wl_client *client, |
| 3111 | struct wl_resource *resource, |
| 3112 | uint32_t serial) |
| 3113 | { |
| 3114 | struct shell_surface *shsurf = wl_resource_get_user_data(resource); |
| 3115 | |
| 3116 | surface_pong(shsurf, serial); |
| 3117 | } |
| 3118 | |
| 3119 | static void |
| 3120 | xdg_surface_set_app_id(struct wl_client *client, |
| 3121 | struct wl_resource *resource, |
| 3122 | const char *app_id) |
| 3123 | { |
| 3124 | struct shell_surface *shsurf = wl_resource_get_user_data(resource); |
| 3125 | |
| 3126 | free(shsurf->class); |
| 3127 | shsurf->class = strdup(app_id); |
| 3128 | } |
| 3129 | |
| 3130 | static void |
| 3131 | xdg_surface_set_title(struct wl_client *client, |
| 3132 | struct wl_resource *resource, const char *title) |
| 3133 | { |
| 3134 | struct shell_surface *shsurf = wl_resource_get_user_data(resource); |
| 3135 | |
| 3136 | set_title(shsurf, title); |
| 3137 | } |
| 3138 | |
| 3139 | static void |
| 3140 | xdg_surface_move(struct wl_client *client, struct wl_resource *resource, |
| 3141 | struct wl_resource *seat_resource, uint32_t serial) |
| 3142 | { |
| 3143 | common_surface_move(resource, seat_resource, serial); |
| 3144 | } |
| 3145 | |
| 3146 | static void |
| 3147 | xdg_surface_resize(struct wl_client *client, struct wl_resource *resource, |
| 3148 | struct wl_resource *seat_resource, uint32_t serial, |
| 3149 | uint32_t edges) |
| 3150 | { |
| 3151 | common_surface_resize(resource, seat_resource, serial, edges); |
| 3152 | } |
| 3153 | |
| 3154 | static void |
| 3155 | xdg_surface_set_output(struct wl_client *client, |
| 3156 | struct wl_resource *resource, |
| 3157 | struct wl_resource *output_resource) |
| 3158 | { |
| 3159 | struct shell_surface *shsurf = wl_resource_get_user_data(resource); |
| 3160 | struct weston_output *output; |
| 3161 | |
| 3162 | if (output_resource) |
| 3163 | output = wl_resource_get_user_data(output_resource); |
| 3164 | else |
| 3165 | output = NULL; |
| 3166 | |
Rafael Antognolli | 65f98d8 | 2013-12-03 15:35:47 -0200 | [diff] [blame] | 3167 | shsurf->recommended_output = output; |
Rafael Antognolli | e2a3455 | 2013-12-03 15:35:45 -0200 | [diff] [blame] | 3168 | } |
| 3169 | |
| 3170 | static void |
| 3171 | xdg_surface_set_fullscreen(struct wl_client *client, |
| 3172 | struct wl_resource *resource) |
| 3173 | { |
| 3174 | struct shell_surface *shsurf = wl_resource_get_user_data(resource); |
| 3175 | |
| 3176 | if (shsurf->type != SHELL_SURFACE_TOPLEVEL) |
| 3177 | return; |
| 3178 | |
Kristian Høgsberg | e960b3f | 2013-12-05 22:04:42 -0800 | [diff] [blame] | 3179 | if (!shsurf->next_state.fullscreen) |
Rafael Antognolli | e2a3455 | 2013-12-03 15:35:45 -0200 | [diff] [blame] | 3180 | set_fullscreen(shsurf, |
| 3181 | WL_SHELL_SURFACE_FULLSCREEN_METHOD_DEFAULT, |
Rafael Antognolli | 65f98d8 | 2013-12-03 15:35:47 -0200 | [diff] [blame] | 3182 | 0, shsurf->recommended_output); |
Rafael Antognolli | e2a3455 | 2013-12-03 15:35:45 -0200 | [diff] [blame] | 3183 | } |
| 3184 | |
| 3185 | static void |
| 3186 | xdg_surface_unset_fullscreen(struct wl_client *client, |
| 3187 | struct wl_resource *resource) |
| 3188 | { |
| 3189 | struct shell_surface *shsurf = wl_resource_get_user_data(resource); |
Rafael Antognolli | 3c4e3f7 | 2013-12-03 15:35:46 -0200 | [diff] [blame] | 3190 | int32_t width, height; |
Rafael Antognolli | e2a3455 | 2013-12-03 15:35:45 -0200 | [diff] [blame] | 3191 | |
| 3192 | if (shsurf->type != SHELL_SURFACE_TOPLEVEL) |
| 3193 | return; |
| 3194 | |
Rafael Antognolli | 3c4e3f7 | 2013-12-03 15:35:46 -0200 | [diff] [blame] | 3195 | if (!shsurf->next_state.fullscreen) |
| 3196 | return; |
| 3197 | |
Rafael Antognolli | e2a3455 | 2013-12-03 15:35:45 -0200 | [diff] [blame] | 3198 | shsurf->next_state.fullscreen = false; |
| 3199 | shsurf->state_changed = true; |
Rafael Antognolli | 3c4e3f7 | 2013-12-03 15:35:46 -0200 | [diff] [blame] | 3200 | |
| 3201 | if (shsurf->saved_size_valid) { |
| 3202 | width = shsurf->saved_width; |
| 3203 | height = shsurf->saved_height; |
| 3204 | shsurf->saved_size_valid = false; |
| 3205 | } else { |
| 3206 | width = shsurf->surface->width; |
| 3207 | height = shsurf->surface->height; |
| 3208 | } |
| 3209 | |
| 3210 | shsurf->client->send_configure(shsurf->surface, 0, width, height); |
Rafael Antognolli | e2a3455 | 2013-12-03 15:35:45 -0200 | [diff] [blame] | 3211 | } |
| 3212 | |
| 3213 | static void |
| 3214 | xdg_surface_set_maximized(struct wl_client *client, |
| 3215 | struct wl_resource *resource) |
| 3216 | { |
| 3217 | struct shell_surface *shsurf = wl_resource_get_user_data(resource); |
| 3218 | |
| 3219 | if (shsurf->type != SHELL_SURFACE_TOPLEVEL) |
| 3220 | return; |
| 3221 | |
Kristian Høgsberg | c2745b1 | 2013-12-05 22:00:40 -0800 | [diff] [blame] | 3222 | if (!shsurf->next_state.maximized) |
Rafael Antognolli | 65f98d8 | 2013-12-03 15:35:47 -0200 | [diff] [blame] | 3223 | set_maximized(shsurf, NULL); |
Rafael Antognolli | e2a3455 | 2013-12-03 15:35:45 -0200 | [diff] [blame] | 3224 | } |
| 3225 | |
| 3226 | static void |
| 3227 | xdg_surface_unset_maximized(struct wl_client *client, |
| 3228 | struct wl_resource *resource) |
| 3229 | { |
| 3230 | struct shell_surface *shsurf = wl_resource_get_user_data(resource); |
Rafael Antognolli | 3c4e3f7 | 2013-12-03 15:35:46 -0200 | [diff] [blame] | 3231 | int32_t width, height; |
Rafael Antognolli | e2a3455 | 2013-12-03 15:35:45 -0200 | [diff] [blame] | 3232 | |
| 3233 | if (shsurf->type != SHELL_SURFACE_TOPLEVEL) |
| 3234 | return; |
| 3235 | |
Rafael Antognolli | 3c4e3f7 | 2013-12-03 15:35:46 -0200 | [diff] [blame] | 3236 | if (!shsurf->next_state.maximized) |
| 3237 | return; |
| 3238 | |
Rafael Antognolli | e2a3455 | 2013-12-03 15:35:45 -0200 | [diff] [blame] | 3239 | shsurf->next_state.maximized = false; |
| 3240 | shsurf->state_changed = true; |
Rafael Antognolli | 3c4e3f7 | 2013-12-03 15:35:46 -0200 | [diff] [blame] | 3241 | |
| 3242 | if (shsurf->saved_size_valid) { |
| 3243 | width = shsurf->saved_width; |
| 3244 | height = shsurf->saved_height; |
| 3245 | shsurf->saved_size_valid = false; |
| 3246 | } else { |
| 3247 | width = shsurf->surface->width; |
| 3248 | height = shsurf->surface->height; |
| 3249 | } |
| 3250 | |
| 3251 | shsurf->client->send_configure(shsurf->surface, 0, width, height); |
Rafael Antognolli | e2a3455 | 2013-12-03 15:35:45 -0200 | [diff] [blame] | 3252 | } |
| 3253 | |
| 3254 | static const struct xdg_surface_interface xdg_surface_implementation = { |
| 3255 | xdg_surface_destroy, |
| 3256 | xdg_surface_set_transient_for, |
| 3257 | xdg_surface_set_title, |
| 3258 | xdg_surface_set_app_id, |
| 3259 | xdg_surface_pong, |
| 3260 | xdg_surface_move, |
| 3261 | xdg_surface_resize, |
| 3262 | xdg_surface_set_output, |
| 3263 | xdg_surface_set_fullscreen, |
| 3264 | xdg_surface_unset_fullscreen, |
| 3265 | xdg_surface_set_maximized, |
| 3266 | xdg_surface_unset_maximized, |
| 3267 | NULL /* set_minimized */ |
| 3268 | }; |
| 3269 | |
| 3270 | static void |
| 3271 | xdg_send_configure(struct weston_surface *surface, |
| 3272 | uint32_t edges, int32_t width, int32_t height) |
| 3273 | { |
| 3274 | struct shell_surface *shsurf = get_shell_surface(surface); |
| 3275 | |
U. Artie Eoff | cf5737a | 2014-01-17 10:08:25 -0800 | [diff] [blame] | 3276 | assert(shsurf); |
| 3277 | |
Rafael Antognolli | e2a3455 | 2013-12-03 15:35:45 -0200 | [diff] [blame] | 3278 | xdg_surface_send_configure(shsurf->resource, edges, width, height); |
| 3279 | } |
| 3280 | |
| 3281 | static const struct weston_shell_client xdg_client = { |
| 3282 | xdg_send_configure |
| 3283 | }; |
| 3284 | |
| 3285 | static void |
| 3286 | xdg_use_unstable_version(struct wl_client *client, |
| 3287 | struct wl_resource *resource, |
| 3288 | int32_t version) |
| 3289 | { |
| 3290 | if (version > 1) { |
| 3291 | wl_resource_post_error(resource, |
| 3292 | 1, |
| 3293 | "xdg-shell:: version not implemented yet."); |
| 3294 | return; |
| 3295 | } |
| 3296 | } |
| 3297 | |
| 3298 | static struct shell_surface * |
| 3299 | create_xdg_surface(void *shell, struct weston_surface *surface, |
| 3300 | const struct weston_shell_client *client) |
| 3301 | { |
| 3302 | struct shell_surface *shsurf; |
Rafael Antognolli | e2a3455 | 2013-12-03 15:35:45 -0200 | [diff] [blame] | 3303 | |
Kristian Høgsberg | c8f8dd8 | 2013-12-05 23:20:33 -0800 | [diff] [blame] | 3304 | shsurf = create_common_surface(shell, surface, client); |
| 3305 | shsurf->type = SHELL_SURFACE_TOPLEVEL; |
Rafael Antognolli | e2a3455 | 2013-12-03 15:35:45 -0200 | [diff] [blame] | 3306 | |
| 3307 | return shsurf; |
| 3308 | } |
| 3309 | |
| 3310 | static void |
| 3311 | xdg_get_xdg_surface(struct wl_client *client, |
| 3312 | struct wl_resource *resource, |
| 3313 | uint32_t id, |
| 3314 | struct wl_resource *surface_resource) |
| 3315 | { |
| 3316 | struct weston_surface *surface = |
| 3317 | wl_resource_get_user_data(surface_resource); |
| 3318 | struct desktop_shell *shell = wl_resource_get_user_data(resource); |
| 3319 | struct shell_surface *shsurf; |
| 3320 | |
| 3321 | if (get_shell_surface(surface)) { |
| 3322 | wl_resource_post_error(surface_resource, |
| 3323 | WL_DISPLAY_ERROR_INVALID_OBJECT, |
| 3324 | "desktop_shell::get_shell_surface already requested"); |
| 3325 | return; |
| 3326 | } |
| 3327 | |
| 3328 | shsurf = create_xdg_surface(shell, surface, &xdg_client); |
| 3329 | if (!shsurf) { |
| 3330 | wl_resource_post_error(surface_resource, |
| 3331 | WL_DISPLAY_ERROR_INVALID_OBJECT, |
| 3332 | "surface->configure already set"); |
| 3333 | return; |
| 3334 | } |
| 3335 | |
| 3336 | shsurf->resource = |
| 3337 | wl_resource_create(client, |
| 3338 | &xdg_surface_interface, 1, id); |
| 3339 | wl_resource_set_implementation(shsurf->resource, |
| 3340 | &xdg_surface_implementation, |
| 3341 | shsurf, shell_destroy_shell_surface); |
| 3342 | } |
| 3343 | |
| 3344 | static bool |
| 3345 | shell_surface_is_xdg_surface(struct shell_surface *shsurf) |
| 3346 | { |
| 3347 | return wl_resource_instance_of(shsurf->resource, |
| 3348 | &xdg_surface_interface, |
| 3349 | &xdg_surface_implementation); |
| 3350 | } |
| 3351 | |
| 3352 | /* xdg-popup implementation */ |
| 3353 | |
| 3354 | static void |
| 3355 | xdg_popup_destroy(struct wl_client *client, |
| 3356 | struct wl_resource *resource) |
| 3357 | { |
| 3358 | wl_resource_destroy(resource); |
| 3359 | } |
| 3360 | |
| 3361 | static void |
| 3362 | xdg_popup_pong(struct wl_client *client, |
| 3363 | struct wl_resource *resource, |
| 3364 | uint32_t serial) |
| 3365 | { |
| 3366 | struct shell_surface *shsurf = wl_resource_get_user_data(resource); |
| 3367 | |
| 3368 | surface_pong(shsurf, serial); |
| 3369 | } |
| 3370 | |
| 3371 | static const struct xdg_popup_interface xdg_popup_implementation = { |
| 3372 | xdg_popup_destroy, |
| 3373 | xdg_popup_pong |
| 3374 | }; |
| 3375 | |
| 3376 | static void |
| 3377 | xdg_popup_send_configure(struct weston_surface *surface, |
| 3378 | uint32_t edges, int32_t width, int32_t height) |
| 3379 | { |
| 3380 | } |
| 3381 | |
| 3382 | static const struct weston_shell_client xdg_popup_client = { |
| 3383 | xdg_popup_send_configure |
| 3384 | }; |
| 3385 | |
| 3386 | static struct shell_surface * |
| 3387 | create_xdg_popup(void *shell, struct weston_surface *surface, |
| 3388 | const struct weston_shell_client *client, |
| 3389 | struct weston_surface *parent, |
| 3390 | struct shell_seat *seat, |
| 3391 | uint32_t serial, |
| 3392 | int32_t x, int32_t y) |
| 3393 | { |
| 3394 | struct shell_surface *shsurf; |
Rafael Antognolli | e2a3455 | 2013-12-03 15:35:45 -0200 | [diff] [blame] | 3395 | |
Kristian Høgsberg | c8f8dd8 | 2013-12-05 23:20:33 -0800 | [diff] [blame] | 3396 | shsurf = create_common_surface(shell, surface, client); |
| 3397 | shsurf->type = SHELL_SURFACE_POPUP; |
Rafael Antognolli | e2a3455 | 2013-12-03 15:35:45 -0200 | [diff] [blame] | 3398 | shsurf->popup.shseat = seat; |
| 3399 | shsurf->popup.serial = serial; |
| 3400 | shsurf->popup.x = x; |
| 3401 | shsurf->popup.y = y; |
| 3402 | shell_surface_set_parent(shsurf, parent); |
| 3403 | |
| 3404 | return shsurf; |
| 3405 | } |
| 3406 | |
| 3407 | static void |
| 3408 | xdg_get_xdg_popup(struct wl_client *client, |
| 3409 | struct wl_resource *resource, |
| 3410 | uint32_t id, |
| 3411 | struct wl_resource *surface_resource, |
| 3412 | struct wl_resource *parent_resource, |
| 3413 | struct wl_resource *seat_resource, |
| 3414 | uint32_t serial, |
| 3415 | int32_t x, int32_t y, uint32_t flags) |
| 3416 | { |
| 3417 | struct weston_surface *surface = |
| 3418 | wl_resource_get_user_data(surface_resource); |
| 3419 | struct desktop_shell *shell = wl_resource_get_user_data(resource); |
| 3420 | struct shell_surface *shsurf; |
| 3421 | struct weston_surface *parent; |
| 3422 | struct shell_seat *seat; |
| 3423 | |
| 3424 | if (get_shell_surface(surface)) { |
| 3425 | wl_resource_post_error(surface_resource, |
| 3426 | WL_DISPLAY_ERROR_INVALID_OBJECT, |
| 3427 | "desktop_shell::get_shell_surface already requested"); |
| 3428 | return; |
| 3429 | } |
| 3430 | |
| 3431 | if (!parent_resource) { |
| 3432 | wl_resource_post_error(surface_resource, |
| 3433 | WL_DISPLAY_ERROR_INVALID_OBJECT, |
| 3434 | "xdg_shell::get_xdg_popup requires a parent shell surface"); |
| 3435 | } |
| 3436 | |
| 3437 | parent = wl_resource_get_user_data(parent_resource); |
| 3438 | seat = get_shell_seat(wl_resource_get_user_data(seat_resource));; |
| 3439 | |
| 3440 | shsurf = create_xdg_popup(shell, surface, &xdg_popup_client, |
| 3441 | parent, seat, serial, x, y); |
| 3442 | if (!shsurf) { |
| 3443 | wl_resource_post_error(surface_resource, |
| 3444 | WL_DISPLAY_ERROR_INVALID_OBJECT, |
| 3445 | "surface->configure already set"); |
| 3446 | return; |
| 3447 | } |
| 3448 | |
| 3449 | shsurf->resource = |
| 3450 | wl_resource_create(client, |
| 3451 | &xdg_popup_interface, 1, id); |
| 3452 | wl_resource_set_implementation(shsurf->resource, |
| 3453 | &xdg_popup_implementation, |
| 3454 | shsurf, shell_destroy_shell_surface); |
| 3455 | } |
| 3456 | |
| 3457 | static bool |
| 3458 | shell_surface_is_xdg_popup(struct shell_surface *shsurf) |
| 3459 | { |
| 3460 | return wl_resource_instance_of(shsurf->resource, |
| 3461 | &xdg_popup_interface, |
| 3462 | &xdg_popup_implementation); |
| 3463 | } |
| 3464 | |
| 3465 | static const struct xdg_shell_interface xdg_implementation = { |
| 3466 | xdg_use_unstable_version, |
| 3467 | xdg_get_xdg_surface, |
| 3468 | xdg_get_xdg_popup |
| 3469 | }; |
| 3470 | |
| 3471 | static int |
| 3472 | xdg_shell_unversioned_dispatch(const void *implementation, |
| 3473 | void *_target, uint32_t opcode, |
| 3474 | const struct wl_message *message, |
| 3475 | union wl_argument *args) |
| 3476 | { |
| 3477 | struct wl_resource *resource = _target; |
| 3478 | struct desktop_shell *shell = wl_resource_get_user_data(resource); |
| 3479 | |
| 3480 | if (opcode != 0) { |
| 3481 | wl_resource_post_error(resource, |
| 3482 | WL_DISPLAY_ERROR_INVALID_OBJECT, |
| 3483 | "must call use_unstable_version first"); |
| 3484 | return 0; |
| 3485 | } |
| 3486 | |
| 3487 | #define XDG_SERVER_VERSION 1 |
| 3488 | |
Kristian Høgsberg | 8d344a0 | 2013-12-08 22:27:11 -0800 | [diff] [blame] | 3489 | static_assert(XDG_SERVER_VERSION == XDG_SHELL_VERSION_CURRENT, |
| 3490 | "shell implementation doesn't match protocol version"); |
| 3491 | |
Rafael Antognolli | e2a3455 | 2013-12-03 15:35:45 -0200 | [diff] [blame] | 3492 | if (args[0].i != XDG_SERVER_VERSION) { |
| 3493 | wl_resource_post_error(resource, |
| 3494 | WL_DISPLAY_ERROR_INVALID_OBJECT, |
| 3495 | "incompatible version, server is %d " |
| 3496 | "client wants %d", |
| 3497 | XDG_SERVER_VERSION, args[0].i); |
| 3498 | return 0; |
| 3499 | } |
| 3500 | |
| 3501 | wl_resource_set_implementation(resource, &xdg_implementation, |
| 3502 | shell, NULL); |
| 3503 | |
| 3504 | return 1; |
| 3505 | } |
| 3506 | |
| 3507 | /* end of xdg-shell implementation */ |
| 3508 | /***********************************/ |
| 3509 | |
Kristian Høgsberg | 0793756 | 2011-04-12 17:25:42 -0400 | [diff] [blame] | 3510 | static void |
Ander Conselvan de Oliveira | 859e885 | 2013-02-21 18:35:21 +0200 | [diff] [blame] | 3511 | shell_fade(struct desktop_shell *shell, enum fade_type type); |
| 3512 | |
| 3513 | static int |
| 3514 | screensaver_timeout(void *data) |
| 3515 | { |
| 3516 | struct desktop_shell *shell = data; |
| 3517 | |
| 3518 | shell_fade(shell, FADE_OUT); |
| 3519 | |
| 3520 | return 1; |
| 3521 | } |
| 3522 | |
| 3523 | static void |
Kristian Høgsberg | 8334bc1 | 2012-01-03 10:29:47 -0500 | [diff] [blame] | 3524 | handle_screensaver_sigchld(struct weston_process *proc, int status) |
Pekka Paalanen | 18027e5 | 2011-12-02 16:31:49 +0200 | [diff] [blame] | 3525 | { |
Ander Conselvan de Oliveira | 18639f8 | 2013-02-15 18:44:19 +0200 | [diff] [blame] | 3526 | struct desktop_shell *shell = |
| 3527 | container_of(proc, struct desktop_shell, screensaver.process); |
Ander Conselvan de Oliveira | 18639f8 | 2013-02-15 18:44:19 +0200 | [diff] [blame] | 3528 | |
Pekka Paalanen | 18027e5 | 2011-12-02 16:31:49 +0200 | [diff] [blame] | 3529 | proc->pid = 0; |
Ander Conselvan de Oliveira | 18639f8 | 2013-02-15 18:44:19 +0200 | [diff] [blame] | 3530 | |
| 3531 | if (shell->locked) |
Ander Conselvan de Oliveira | b17537e | 2013-02-22 14:16:18 +0200 | [diff] [blame] | 3532 | weston_compositor_sleep(shell->compositor); |
Pekka Paalanen | 18027e5 | 2011-12-02 16:31:49 +0200 | [diff] [blame] | 3533 | } |
| 3534 | |
| 3535 | static void |
Tiago Vignatti | be14326 | 2012-04-16 17:31:41 +0300 | [diff] [blame] | 3536 | launch_screensaver(struct desktop_shell *shell) |
Pekka Paalanen | 77346a6 | 2011-11-30 16:26:35 +0200 | [diff] [blame] | 3537 | { |
| 3538 | if (shell->screensaver.binding) |
| 3539 | return; |
| 3540 | |
Ander Conselvan de Oliveira | dda9d78 | 2013-02-22 14:16:19 +0200 | [diff] [blame] | 3541 | if (!shell->screensaver.path) { |
| 3542 | weston_compositor_sleep(shell->compositor); |
Pekka Paalanen | e955f1e | 2011-12-07 11:49:52 +0200 | [diff] [blame] | 3543 | return; |
Ander Conselvan de Oliveira | dda9d78 | 2013-02-22 14:16:19 +0200 | [diff] [blame] | 3544 | } |
Pekka Paalanen | e955f1e | 2011-12-07 11:49:52 +0200 | [diff] [blame] | 3545 | |
Kristian Høgsberg | 32bed57 | 2012-03-01 17:11:36 -0500 | [diff] [blame] | 3546 | if (shell->screensaver.process.pid != 0) { |
Martin Minarik | 6d11836 | 2012-06-07 18:01:59 +0200 | [diff] [blame] | 3547 | weston_log("old screensaver still running\n"); |
Kristian Høgsberg | 32bed57 | 2012-03-01 17:11:36 -0500 | [diff] [blame] | 3548 | return; |
| 3549 | } |
| 3550 | |
Kristian Høgsberg | 8334bc1 | 2012-01-03 10:29:47 -0500 | [diff] [blame] | 3551 | weston_client_launch(shell->compositor, |
Pekka Paalanen | 18027e5 | 2011-12-02 16:31:49 +0200 | [diff] [blame] | 3552 | &shell->screensaver.process, |
Pekka Paalanen | e955f1e | 2011-12-07 11:49:52 +0200 | [diff] [blame] | 3553 | shell->screensaver.path, |
Pekka Paalanen | 18027e5 | 2011-12-02 16:31:49 +0200 | [diff] [blame] | 3554 | handle_screensaver_sigchld); |
Pekka Paalanen | 77346a6 | 2011-11-30 16:26:35 +0200 | [diff] [blame] | 3555 | } |
| 3556 | |
| 3557 | static void |
Tiago Vignatti | be14326 | 2012-04-16 17:31:41 +0300 | [diff] [blame] | 3558 | terminate_screensaver(struct desktop_shell *shell) |
Pekka Paalanen | 77346a6 | 2011-11-30 16:26:35 +0200 | [diff] [blame] | 3559 | { |
Pekka Paalanen | 18027e5 | 2011-12-02 16:31:49 +0200 | [diff] [blame] | 3560 | if (shell->screensaver.process.pid == 0) |
| 3561 | return; |
| 3562 | |
| 3563 | kill(shell->screensaver.process.pid, SIGTERM); |
Pekka Paalanen | 77346a6 | 2011-11-30 16:26:35 +0200 | [diff] [blame] | 3564 | } |
| 3565 | |
| 3566 | static void |
Jason Ekstrand | 918f2dd | 2013-12-02 21:01:53 -0600 | [diff] [blame] | 3567 | configure_static_view(struct weston_view *ev, struct weston_layer *layer) |
Kristian Høgsberg | 962342c | 2012-06-26 16:29:50 -0400 | [diff] [blame] | 3568 | { |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 3569 | struct weston_view *v, *next; |
Kristian Høgsberg | 962342c | 2012-06-26 16:29:50 -0400 | [diff] [blame] | 3570 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 3571 | wl_list_for_each_safe(v, next, &layer->view_list, layer_link) { |
| 3572 | if (v->output == ev->output && v != ev) { |
| 3573 | weston_view_unmap(v); |
| 3574 | v->surface->configure = NULL; |
Kristian Høgsberg | 962342c | 2012-06-26 16:29:50 -0400 | [diff] [blame] | 3575 | } |
| 3576 | } |
| 3577 | |
Jason Ekstrand | 918f2dd | 2013-12-02 21:01:53 -0600 | [diff] [blame] | 3578 | weston_view_set_position(ev, ev->output->x, ev->output->y); |
Kristian Høgsberg | 962342c | 2012-06-26 16:29:50 -0400 | [diff] [blame] | 3579 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 3580 | if (wl_list_empty(&ev->layer_link)) { |
| 3581 | wl_list_insert(&layer->view_list, &ev->layer_link); |
| 3582 | weston_compositor_schedule_repaint(ev->surface->compositor); |
Kristian Høgsberg | 962342c | 2012-06-26 16:29:50 -0400 | [diff] [blame] | 3583 | } |
| 3584 | } |
| 3585 | |
| 3586 | static void |
Jason Ekstrand | 918f2dd | 2013-12-02 21:01:53 -0600 | [diff] [blame] | 3587 | 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] | 3588 | { |
Giulio Camuffo | 7fe01b1 | 2013-03-28 18:02:42 +0100 | [diff] [blame] | 3589 | struct desktop_shell *shell = es->configure_private; |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 3590 | struct weston_view *view; |
Kristian Høgsberg | af7b1ff | 2012-06-26 21:19:23 -0400 | [diff] [blame] | 3591 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 3592 | view = container_of(es->views.next, struct weston_view, surface_link); |
| 3593 | |
Jason Ekstrand | 918f2dd | 2013-12-02 21:01:53 -0600 | [diff] [blame] | 3594 | configure_static_view(view, &shell->background_layer); |
Kristian Høgsberg | af7b1ff | 2012-06-26 21:19:23 -0400 | [diff] [blame] | 3595 | } |
| 3596 | |
| 3597 | static void |
Kristian Høgsberg | 7584062 | 2011-09-06 13:48:16 -0400 | [diff] [blame] | 3598 | desktop_shell_set_background(struct wl_client *client, |
| 3599 | struct wl_resource *resource, |
Benjamin Franzke | d0f79ab | 2011-11-22 12:43:52 +0100 | [diff] [blame] | 3600 | struct wl_resource *output_resource, |
Kristian Høgsberg | 7584062 | 2011-09-06 13:48:16 -0400 | [diff] [blame] | 3601 | struct wl_resource *surface_resource) |
| 3602 | { |
Jason Ekstrand | 651f00e | 2013-06-14 10:07:54 -0500 | [diff] [blame] | 3603 | struct desktop_shell *shell = wl_resource_get_user_data(resource); |
Jason Ekstrand | 0f2ef7e | 2013-06-14 10:07:53 -0500 | [diff] [blame] | 3604 | struct weston_surface *surface = |
| 3605 | wl_resource_get_user_data(surface_resource); |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 3606 | struct weston_view *view, *next; |
Kristian Høgsberg | 7584062 | 2011-09-06 13:48:16 -0400 | [diff] [blame] | 3607 | |
Kristian Høgsberg | 962342c | 2012-06-26 16:29:50 -0400 | [diff] [blame] | 3608 | if (surface->configure) { |
| 3609 | wl_resource_post_error(surface_resource, |
| 3610 | WL_DISPLAY_ERROR_INVALID_OBJECT, |
| 3611 | "surface role already assigned"); |
| 3612 | return; |
| 3613 | } |
Benjamin Franzke | d0f79ab | 2011-11-22 12:43:52 +0100 | [diff] [blame] | 3614 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 3615 | wl_list_for_each_safe(view, next, &surface->views, surface_link) |
| 3616 | weston_view_destroy(view); |
| 3617 | view = weston_view_create(surface); |
| 3618 | |
Kristian Høgsberg | 962342c | 2012-06-26 16:29:50 -0400 | [diff] [blame] | 3619 | surface->configure = background_configure; |
Giulio Camuffo | 7fe01b1 | 2013-03-28 18:02:42 +0100 | [diff] [blame] | 3620 | surface->configure_private = shell; |
Jason Ekstrand | a0d2dde | 2013-06-14 10:08:01 -0500 | [diff] [blame] | 3621 | surface->output = wl_resource_get_user_data(output_resource); |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 3622 | view->output = surface->output; |
Kristian Høgsberg | eae5de7 | 2012-04-11 22:42:15 -0400 | [diff] [blame] | 3623 | desktop_shell_send_configure(resource, 0, |
Kristian Høgsberg | 0b5cd0c | 2012-03-04 21:57:37 -0500 | [diff] [blame] | 3624 | surface_resource, |
Scott Moreau | 1bad5db | 2012-08-18 01:04:05 -0600 | [diff] [blame] | 3625 | surface->output->width, |
| 3626 | surface->output->height); |
Kristian Høgsberg | 7584062 | 2011-09-06 13:48:16 -0400 | [diff] [blame] | 3627 | } |
| 3628 | |
| 3629 | static void |
Jason Ekstrand | 918f2dd | 2013-12-02 21:01:53 -0600 | [diff] [blame] | 3630 | 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] | 3631 | { |
Giulio Camuffo | 7fe01b1 | 2013-03-28 18:02:42 +0100 | [diff] [blame] | 3632 | struct desktop_shell *shell = es->configure_private; |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 3633 | struct weston_view *view; |
Kristian Høgsberg | af7b1ff | 2012-06-26 21:19:23 -0400 | [diff] [blame] | 3634 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 3635 | view = container_of(es->views.next, struct weston_view, surface_link); |
| 3636 | |
Jason Ekstrand | 918f2dd | 2013-12-02 21:01:53 -0600 | [diff] [blame] | 3637 | configure_static_view(view, &shell->panel_layer); |
Kristian Høgsberg | af7b1ff | 2012-06-26 21:19:23 -0400 | [diff] [blame] | 3638 | } |
| 3639 | |
| 3640 | static void |
Kristian Høgsberg | 7584062 | 2011-09-06 13:48:16 -0400 | [diff] [blame] | 3641 | desktop_shell_set_panel(struct wl_client *client, |
| 3642 | struct wl_resource *resource, |
Benjamin Franzke | d0f79ab | 2011-11-22 12:43:52 +0100 | [diff] [blame] | 3643 | struct wl_resource *output_resource, |
Kristian Høgsberg | 7584062 | 2011-09-06 13:48:16 -0400 | [diff] [blame] | 3644 | struct wl_resource *surface_resource) |
| 3645 | { |
Jason Ekstrand | 651f00e | 2013-06-14 10:07:54 -0500 | [diff] [blame] | 3646 | struct desktop_shell *shell = wl_resource_get_user_data(resource); |
Jason Ekstrand | 0f2ef7e | 2013-06-14 10:07:53 -0500 | [diff] [blame] | 3647 | struct weston_surface *surface = |
| 3648 | wl_resource_get_user_data(surface_resource); |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 3649 | struct weston_view *view, *next; |
Kristian Høgsberg | 7584062 | 2011-09-06 13:48:16 -0400 | [diff] [blame] | 3650 | |
Kristian Høgsberg | af7b1ff | 2012-06-26 21:19:23 -0400 | [diff] [blame] | 3651 | if (surface->configure) { |
| 3652 | wl_resource_post_error(surface_resource, |
| 3653 | WL_DISPLAY_ERROR_INVALID_OBJECT, |
| 3654 | "surface role already assigned"); |
| 3655 | return; |
| 3656 | } |
Benjamin Franzke | d0f79ab | 2011-11-22 12:43:52 +0100 | [diff] [blame] | 3657 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 3658 | wl_list_for_each_safe(view, next, &surface->views, surface_link) |
| 3659 | weston_view_destroy(view); |
| 3660 | view = weston_view_create(surface); |
| 3661 | |
Kristian Høgsberg | af7b1ff | 2012-06-26 21:19:23 -0400 | [diff] [blame] | 3662 | surface->configure = panel_configure; |
Giulio Camuffo | 7fe01b1 | 2013-03-28 18:02:42 +0100 | [diff] [blame] | 3663 | surface->configure_private = shell; |
Jason Ekstrand | a0d2dde | 2013-06-14 10:08:01 -0500 | [diff] [blame] | 3664 | surface->output = wl_resource_get_user_data(output_resource); |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 3665 | view->output = surface->output; |
Kristian Høgsberg | eae5de7 | 2012-04-11 22:42:15 -0400 | [diff] [blame] | 3666 | desktop_shell_send_configure(resource, 0, |
Kristian Høgsberg | af7b1ff | 2012-06-26 21:19:23 -0400 | [diff] [blame] | 3667 | surface_resource, |
Scott Moreau | 1bad5db | 2012-08-18 01:04:05 -0600 | [diff] [blame] | 3668 | surface->output->width, |
| 3669 | surface->output->height); |
Kristian Høgsberg | 7584062 | 2011-09-06 13:48:16 -0400 | [diff] [blame] | 3670 | } |
| 3671 | |
Pekka Paalanen | 9ef3e01 | 2011-11-15 13:34:48 +0200 | [diff] [blame] | 3672 | static void |
Jason Ekstrand | 918f2dd | 2013-12-02 21:01:53 -0600 | [diff] [blame] | 3673 | 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] | 3674 | { |
Giulio Camuffo | 7fe01b1 | 2013-03-28 18:02:42 +0100 | [diff] [blame] | 3675 | struct desktop_shell *shell = surface->configure_private; |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 3676 | struct weston_view *view; |
| 3677 | |
| 3678 | view = container_of(surface->views.next, struct weston_view, surface_link); |
Kristian Høgsberg | 730c94d | 2012-06-26 21:44:35 -0400 | [diff] [blame] | 3679 | |
Jason Ekstrand | 918f2dd | 2013-12-02 21:01:53 -0600 | [diff] [blame] | 3680 | if (surface->width == 0) |
Giulio Camuffo | 184df50 | 2013-02-21 11:29:21 +0100 | [diff] [blame] | 3681 | return; |
| 3682 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 3683 | center_on_output(view, get_default_output(shell->compositor)); |
Kristian Høgsberg | 730c94d | 2012-06-26 21:44:35 -0400 | [diff] [blame] | 3684 | |
| 3685 | if (!weston_surface_is_mapped(surface)) { |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 3686 | wl_list_insert(&shell->lock_layer.view_list, |
| 3687 | &view->layer_link); |
| 3688 | weston_view_update_transform(view); |
Ander Conselvan de Oliveira | 87524b6 | 2013-02-21 18:35:22 +0200 | [diff] [blame] | 3689 | shell_fade(shell, FADE_IN); |
Kristian Høgsberg | 730c94d | 2012-06-26 21:44:35 -0400 | [diff] [blame] | 3690 | } |
| 3691 | } |
| 3692 | |
| 3693 | static void |
Kristian Høgsberg | 27e3052 | 2012-04-11 23:18:23 -0400 | [diff] [blame] | 3694 | handle_lock_surface_destroy(struct wl_listener *listener, void *data) |
Kristian Høgsberg | 1ec0c31 | 2011-11-15 16:39:55 -0500 | [diff] [blame] | 3695 | { |
Tiago Vignatti | be14326 | 2012-04-16 17:31:41 +0300 | [diff] [blame] | 3696 | struct desktop_shell *shell = |
| 3697 | container_of(listener, struct desktop_shell, lock_surface_listener); |
Kristian Høgsberg | 1ec0c31 | 2011-11-15 16:39:55 -0500 | [diff] [blame] | 3698 | |
Martin Minarik | 6d11836 | 2012-06-07 18:01:59 +0200 | [diff] [blame] | 3699 | weston_log("lock surface gone\n"); |
Kristian Høgsberg | 1ec0c31 | 2011-11-15 16:39:55 -0500 | [diff] [blame] | 3700 | shell->lock_surface = NULL; |
| 3701 | } |
| 3702 | |
| 3703 | static void |
Pekka Paalanen | 9ef3e01 | 2011-11-15 13:34:48 +0200 | [diff] [blame] | 3704 | desktop_shell_set_lock_surface(struct wl_client *client, |
| 3705 | struct wl_resource *resource, |
| 3706 | struct wl_resource *surface_resource) |
| 3707 | { |
Jason Ekstrand | 651f00e | 2013-06-14 10:07:54 -0500 | [diff] [blame] | 3708 | struct desktop_shell *shell = wl_resource_get_user_data(resource); |
Jason Ekstrand | 0f2ef7e | 2013-06-14 10:07:53 -0500 | [diff] [blame] | 3709 | struct weston_surface *surface = |
| 3710 | wl_resource_get_user_data(surface_resource); |
Pekka Paalanen | 9826223 | 2011-12-01 10:42:22 +0200 | [diff] [blame] | 3711 | |
Pekka Paalanen | f0fc70d | 2011-11-15 13:34:54 +0200 | [diff] [blame] | 3712 | shell->prepare_event_sent = false; |
Kristian Høgsberg | af867cc | 2011-11-15 13:34:49 +0200 | [diff] [blame] | 3713 | |
Pekka Paalanen | f0fc70d | 2011-11-15 13:34:54 +0200 | [diff] [blame] | 3714 | if (!shell->locked) |
| 3715 | return; |
| 3716 | |
Pekka Paalanen | 9826223 | 2011-12-01 10:42:22 +0200 | [diff] [blame] | 3717 | shell->lock_surface = surface; |
Pekka Paalanen | f0fc70d | 2011-11-15 13:34:54 +0200 | [diff] [blame] | 3718 | |
Kristian Høgsberg | 27e3052 | 2012-04-11 23:18:23 -0400 | [diff] [blame] | 3719 | shell->lock_surface_listener.notify = handle_lock_surface_destroy; |
Jason Ekstrand | 651f00e | 2013-06-14 10:07:54 -0500 | [diff] [blame] | 3720 | wl_signal_add(&surface->destroy_signal, |
Kristian Høgsberg | 27e3052 | 2012-04-11 23:18:23 -0400 | [diff] [blame] | 3721 | &shell->lock_surface_listener); |
Pekka Paalanen | 57da4a8 | 2011-11-23 16:42:16 +0200 | [diff] [blame] | 3722 | |
Kristian Høgsberg | aa2ee8b | 2013-10-30 15:49:45 -0700 | [diff] [blame] | 3723 | weston_view_create(surface); |
Kristian Høgsberg | 730c94d | 2012-06-26 21:44:35 -0400 | [diff] [blame] | 3724 | surface->configure = lock_surface_configure; |
Giulio Camuffo | 7fe01b1 | 2013-03-28 18:02:42 +0100 | [diff] [blame] | 3725 | surface->configure_private = shell; |
Pekka Paalanen | f0fc70d | 2011-11-15 13:34:54 +0200 | [diff] [blame] | 3726 | } |
| 3727 | |
| 3728 | static void |
Tiago Vignatti | be14326 | 2012-04-16 17:31:41 +0300 | [diff] [blame] | 3729 | resume_desktop(struct desktop_shell *shell) |
Pekka Paalanen | f0fc70d | 2011-11-15 13:34:54 +0200 | [diff] [blame] | 3730 | { |
Kristian Høgsberg | 4476aaf | 2012-06-25 14:03:13 -0400 | [diff] [blame] | 3731 | struct workspace *ws = get_current_workspace(shell); |
Pekka Paalanen | 77346a6 | 2011-11-30 16:26:35 +0200 | [diff] [blame] | 3732 | |
Pekka Paalanen | 77346a6 | 2011-11-30 16:26:35 +0200 | [diff] [blame] | 3733 | terminate_screensaver(shell); |
Pekka Paalanen | f0fc70d | 2011-11-15 13:34:54 +0200 | [diff] [blame] | 3734 | |
Kristian Høgsberg | 3be2ce9 | 2012-02-29 12:42:35 -0500 | [diff] [blame] | 3735 | wl_list_remove(&shell->lock_layer.link); |
| 3736 | wl_list_insert(&shell->compositor->cursor_layer.link, |
| 3737 | &shell->fullscreen_layer.link); |
| 3738 | wl_list_insert(&shell->fullscreen_layer.link, |
| 3739 | &shell->panel_layer.link); |
Philipp Brüschweiler | 711fda8 | 2012-08-09 18:50:43 +0200 | [diff] [blame] | 3740 | if (shell->showing_input_panels) { |
| 3741 | wl_list_insert(&shell->panel_layer.link, |
| 3742 | &shell->input_panel_layer.link); |
| 3743 | wl_list_insert(&shell->input_panel_layer.link, |
| 3744 | &ws->layer.link); |
| 3745 | } else { |
| 3746 | wl_list_insert(&shell->panel_layer.link, &ws->layer.link); |
| 3747 | } |
Pekka Paalanen | f0fc70d | 2011-11-15 13:34:54 +0200 | [diff] [blame] | 3748 | |
Kristian Høgsberg | 2f5faff | 2012-07-31 16:36:34 -0400 | [diff] [blame] | 3749 | restore_focus_state(shell, get_current_workspace(shell)); |
Jonas Ådahl | 0476974 | 2012-06-13 00:01:24 +0200 | [diff] [blame] | 3750 | |
Pekka Paalanen | f0fc70d | 2011-11-15 13:34:54 +0200 | [diff] [blame] | 3751 | shell->locked = false; |
Ander Conselvan de Oliveira | 87524b6 | 2013-02-21 18:35:22 +0200 | [diff] [blame] | 3752 | shell_fade(shell, FADE_IN); |
Pekka Paalanen | fc6d91a | 2012-02-10 15:33:10 +0200 | [diff] [blame] | 3753 | weston_compositor_damage_all(shell->compositor); |
Pekka Paalanen | 9ef3e01 | 2011-11-15 13:34:48 +0200 | [diff] [blame] | 3754 | } |
| 3755 | |
| 3756 | static void |
| 3757 | desktop_shell_unlock(struct wl_client *client, |
| 3758 | struct wl_resource *resource) |
| 3759 | { |
Jason Ekstrand | 651f00e | 2013-06-14 10:07:54 -0500 | [diff] [blame] | 3760 | struct desktop_shell *shell = wl_resource_get_user_data(resource); |
Pekka Paalanen | 9ef3e01 | 2011-11-15 13:34:48 +0200 | [diff] [blame] | 3761 | |
Pekka Paalanen | 9ef3e01 | 2011-11-15 13:34:48 +0200 | [diff] [blame] | 3762 | shell->prepare_event_sent = false; |
Pekka Paalanen | f0fc70d | 2011-11-15 13:34:54 +0200 | [diff] [blame] | 3763 | |
| 3764 | if (shell->locked) |
| 3765 | resume_desktop(shell); |
Pekka Paalanen | 9ef3e01 | 2011-11-15 13:34:48 +0200 | [diff] [blame] | 3766 | } |
| 3767 | |
Kristian Høgsberg | d56bd90 | 2012-06-05 09:58:51 -0400 | [diff] [blame] | 3768 | static void |
Ander Conselvan de Oliveira | b9d2a0f | 2012-06-28 18:08:05 +0300 | [diff] [blame] | 3769 | desktop_shell_set_grab_surface(struct wl_client *client, |
Kristian Høgsberg | d56bd90 | 2012-06-05 09:58:51 -0400 | [diff] [blame] | 3770 | struct wl_resource *resource, |
| 3771 | struct wl_resource *surface_resource) |
| 3772 | { |
Jason Ekstrand | 651f00e | 2013-06-14 10:07:54 -0500 | [diff] [blame] | 3773 | struct desktop_shell *shell = wl_resource_get_user_data(resource); |
Kristian Høgsberg | d56bd90 | 2012-06-05 09:58:51 -0400 | [diff] [blame] | 3774 | |
Jason Ekstrand | 0f2ef7e | 2013-06-14 10:07:53 -0500 | [diff] [blame] | 3775 | shell->grab_surface = wl_resource_get_user_data(surface_resource); |
Kristian Høgsberg | 48588f8 | 2013-10-24 15:51:35 -0700 | [diff] [blame] | 3776 | weston_view_create(shell->grab_surface); |
Kristian Høgsberg | d56bd90 | 2012-06-05 09:58:51 -0400 | [diff] [blame] | 3777 | } |
| 3778 | |
Pekka Paalanen | 79346ab | 2013-05-22 18:03:09 +0300 | [diff] [blame] | 3779 | static void |
| 3780 | desktop_shell_desktop_ready(struct wl_client *client, |
| 3781 | struct wl_resource *resource) |
| 3782 | { |
Jason Ekstrand | 651f00e | 2013-06-14 10:07:54 -0500 | [diff] [blame] | 3783 | struct desktop_shell *shell = wl_resource_get_user_data(resource); |
Pekka Paalanen | 79346ab | 2013-05-22 18:03:09 +0300 | [diff] [blame] | 3784 | |
| 3785 | shell_fade_startup(shell); |
| 3786 | } |
| 3787 | |
Kristian Høgsberg | 7584062 | 2011-09-06 13:48:16 -0400 | [diff] [blame] | 3788 | static const struct desktop_shell_interface desktop_shell_implementation = { |
| 3789 | desktop_shell_set_background, |
Pekka Paalanen | 9ef3e01 | 2011-11-15 13:34:48 +0200 | [diff] [blame] | 3790 | desktop_shell_set_panel, |
| 3791 | desktop_shell_set_lock_surface, |
Kristian Høgsberg | d56bd90 | 2012-06-05 09:58:51 -0400 | [diff] [blame] | 3792 | desktop_shell_unlock, |
Pekka Paalanen | 79346ab | 2013-05-22 18:03:09 +0300 | [diff] [blame] | 3793 | desktop_shell_set_grab_surface, |
| 3794 | desktop_shell_desktop_ready |
Kristian Høgsberg | 7584062 | 2011-09-06 13:48:16 -0400 | [diff] [blame] | 3795 | }; |
| 3796 | |
Pekka Paalanen | 92a0dc4 | 2011-11-28 15:34:13 +0200 | [diff] [blame] | 3797 | static enum shell_surface_type |
Kristian Høgsberg | 8334bc1 | 2012-01-03 10:29:47 -0500 | [diff] [blame] | 3798 | get_shell_surface_type(struct weston_surface *surface) |
Pekka Paalanen | 92a0dc4 | 2011-11-28 15:34:13 +0200 | [diff] [blame] | 3799 | { |
| 3800 | struct shell_surface *shsurf; |
| 3801 | |
| 3802 | shsurf = get_shell_surface(surface); |
| 3803 | if (!shsurf) |
Pekka Paalanen | 9826223 | 2011-12-01 10:42:22 +0200 | [diff] [blame] | 3804 | return SHELL_SURFACE_NONE; |
Pekka Paalanen | 92a0dc4 | 2011-11-28 15:34:13 +0200 | [diff] [blame] | 3805 | return shsurf->type; |
| 3806 | } |
| 3807 | |
Kristian Høgsberg | 7584062 | 2011-09-06 13:48:16 -0400 | [diff] [blame] | 3808 | static void |
Kristian Høgsberg | e314875 | 2013-05-06 23:19:49 -0400 | [diff] [blame] | 3809 | 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] | 3810 | { |
Rafal Mielniczuk | b2917a2 | 2014-01-05 20:04:59 +0100 | [diff] [blame] | 3811 | struct weston_surface *focus; |
Pekka Paalanen | 01388e2 | 2013-04-25 13:57:44 +0300 | [diff] [blame] | 3812 | struct weston_surface *surface; |
Kristian Høgsberg | 938b8fa | 2012-05-18 13:46:27 -0400 | [diff] [blame] | 3813 | struct shell_surface *shsurf; |
Kristian Høgsberg | d2abb83 | 2011-11-23 10:52:40 -0500 | [diff] [blame] | 3814 | |
Rafal Mielniczuk | b2917a2 | 2014-01-05 20:04:59 +0100 | [diff] [blame] | 3815 | if (seat->pointer->focus == NULL) |
| 3816 | return; |
| 3817 | |
| 3818 | focus = seat->pointer->focus->surface; |
| 3819 | |
Pekka Paalanen | 01388e2 | 2013-04-25 13:57:44 +0300 | [diff] [blame] | 3820 | surface = weston_surface_get_main_surface(focus); |
Benjamin Franzke | d0f79ab | 2011-11-22 12:43:52 +0100 | [diff] [blame] | 3821 | if (surface == NULL) |
| 3822 | return; |
Kristian Høgsberg | 0793756 | 2011-04-12 17:25:42 -0400 | [diff] [blame] | 3823 | |
Kristian Høgsberg | 938b8fa | 2012-05-18 13:46:27 -0400 | [diff] [blame] | 3824 | shsurf = get_shell_surface(surface); |
Rafael Antognolli | 03b1659 | 2013-12-03 15:35:42 -0200 | [diff] [blame] | 3825 | if (shsurf == NULL || shsurf->state.fullscreen || |
| 3826 | shsurf->state.maximized) |
Kristian Høgsberg | 938b8fa | 2012-05-18 13:46:27 -0400 | [diff] [blame] | 3827 | return; |
| 3828 | |
Kristian Høgsberg | 938b8fa | 2012-05-18 13:46:27 -0400 | [diff] [blame] | 3829 | surface_move(shsurf, (struct weston_seat *) seat); |
Kristian Høgsberg | 0793756 | 2011-04-12 17:25:42 -0400 | [diff] [blame] | 3830 | } |
| 3831 | |
| 3832 | static void |
Rafael Antognolli | ea997ac | 2013-12-03 15:35:48 -0200 | [diff] [blame] | 3833 | maximize_binding(struct weston_seat *seat, uint32_t time, uint32_t button, void *data) |
| 3834 | { |
| 3835 | struct weston_surface *focus = seat->pointer->focus->surface; |
| 3836 | struct weston_surface *surface; |
| 3837 | struct shell_surface *shsurf; |
| 3838 | |
| 3839 | surface = weston_surface_get_main_surface(focus); |
| 3840 | if (surface == NULL) |
| 3841 | return; |
| 3842 | |
| 3843 | shsurf = get_shell_surface(surface); |
| 3844 | if (shsurf == NULL) |
| 3845 | return; |
| 3846 | |
| 3847 | if (!shell_surface_is_xdg_surface(shsurf)) |
| 3848 | return; |
| 3849 | |
| 3850 | if (shsurf->state.maximized) |
| 3851 | xdg_surface_send_request_unset_maximized(shsurf->resource); |
| 3852 | else |
| 3853 | xdg_surface_send_request_set_maximized(shsurf->resource); |
| 3854 | } |
| 3855 | |
| 3856 | static void |
| 3857 | fullscreen_binding(struct weston_seat *seat, uint32_t time, uint32_t button, void *data) |
| 3858 | { |
| 3859 | struct weston_surface *focus = seat->pointer->focus->surface; |
| 3860 | struct weston_surface *surface; |
| 3861 | struct shell_surface *shsurf; |
| 3862 | |
| 3863 | surface = weston_surface_get_main_surface(focus); |
| 3864 | if (surface == NULL) |
| 3865 | return; |
| 3866 | |
| 3867 | shsurf = get_shell_surface(surface); |
| 3868 | if (shsurf == NULL) |
| 3869 | return; |
| 3870 | |
| 3871 | if (!shell_surface_is_xdg_surface(shsurf)) |
| 3872 | return; |
| 3873 | |
| 3874 | if (shsurf->state.fullscreen) |
| 3875 | xdg_surface_send_request_unset_fullscreen(shsurf->resource); |
| 3876 | else |
| 3877 | xdg_surface_send_request_set_fullscreen(shsurf->resource); |
| 3878 | } |
| 3879 | |
| 3880 | static void |
Neil Roberts | aba0f25 | 2013-10-03 16:43:05 +0100 | [diff] [blame] | 3881 | touch_move_binding(struct weston_seat *seat, uint32_t time, void *data) |
| 3882 | { |
Kristian Høgsberg | 7ab139c | 2013-10-24 16:21:39 -0700 | [diff] [blame] | 3883 | struct weston_surface *focus = seat->touch->focus->surface; |
Neil Roberts | aba0f25 | 2013-10-03 16:43:05 +0100 | [diff] [blame] | 3884 | struct weston_surface *surface; |
| 3885 | struct shell_surface *shsurf; |
| 3886 | |
| 3887 | surface = weston_surface_get_main_surface(focus); |
| 3888 | if (surface == NULL) |
| 3889 | return; |
| 3890 | |
| 3891 | shsurf = get_shell_surface(surface); |
Rafael Antognolli | 03b1659 | 2013-12-03 15:35:42 -0200 | [diff] [blame] | 3892 | if (shsurf == NULL || shsurf->state.fullscreen || |
| 3893 | shsurf->state.maximized) |
Neil Roberts | aba0f25 | 2013-10-03 16:43:05 +0100 | [diff] [blame] | 3894 | return; |
| 3895 | |
| 3896 | surface_touch_move(shsurf, (struct weston_seat *) seat); |
| 3897 | } |
| 3898 | |
| 3899 | static void |
Kristian Høgsberg | e314875 | 2013-05-06 23:19:49 -0400 | [diff] [blame] | 3900 | 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] | 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 | 0793756 | 2011-04-12 17:25:42 -0400 | [diff] [blame] | 3904 | uint32_t edges = 0; |
| 3905 | int32_t x, y; |
Pekka Paalanen | 9d1613e | 2011-11-25 12:09:16 +0200 | [diff] [blame] | 3906 | struct shell_surface *shsurf; |
Kristian Høgsberg | d2abb83 | 2011-11-23 10:52:40 -0500 | [diff] [blame] | 3907 | |
Rafal Mielniczuk | b2917a2 | 2014-01-05 20:04:59 +0100 | [diff] [blame] | 3908 | if (seat->pointer->focus == NULL) |
| 3909 | return; |
| 3910 | |
| 3911 | focus = seat->pointer->focus->surface; |
| 3912 | |
Pekka Paalanen | 01388e2 | 2013-04-25 13:57:44 +0300 | [diff] [blame] | 3913 | surface = weston_surface_get_main_surface(focus); |
Benjamin Franzke | d0f79ab | 2011-11-22 12:43:52 +0100 | [diff] [blame] | 3914 | if (surface == NULL) |
| 3915 | return; |
Pekka Paalanen | 92a0dc4 | 2011-11-28 15:34:13 +0200 | [diff] [blame] | 3916 | |
Pekka Paalanen | 9d1613e | 2011-11-25 12:09:16 +0200 | [diff] [blame] | 3917 | shsurf = get_shell_surface(surface); |
Rafael Antognolli | 03b1659 | 2013-12-03 15:35:42 -0200 | [diff] [blame] | 3918 | if (shsurf == NULL || shsurf->state.fullscreen || |
| 3919 | shsurf->state.maximized) |
Pekka Paalanen | 92a0dc4 | 2011-11-28 15:34:13 +0200 | [diff] [blame] | 3920 | return; |
| 3921 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 3922 | weston_view_from_global(shsurf->view, |
| 3923 | wl_fixed_to_int(seat->pointer->grab_x), |
| 3924 | wl_fixed_to_int(seat->pointer->grab_y), |
| 3925 | &x, &y); |
Kristian Høgsberg | 0793756 | 2011-04-12 17:25:42 -0400 | [diff] [blame] | 3926 | |
Jason Ekstrand | 918f2dd | 2013-12-02 21:01:53 -0600 | [diff] [blame] | 3927 | if (x < shsurf->surface->width / 3) |
Pekka Paalanen | 9d1613e | 2011-11-25 12:09:16 +0200 | [diff] [blame] | 3928 | edges |= WL_SHELL_SURFACE_RESIZE_LEFT; |
Jason Ekstrand | 918f2dd | 2013-12-02 21:01:53 -0600 | [diff] [blame] | 3929 | else if (x < 2 * shsurf->surface->width / 3) |
Kristian Høgsberg | 0793756 | 2011-04-12 17:25:42 -0400 | [diff] [blame] | 3930 | edges |= 0; |
| 3931 | else |
Pekka Paalanen | 9d1613e | 2011-11-25 12:09:16 +0200 | [diff] [blame] | 3932 | edges |= WL_SHELL_SURFACE_RESIZE_RIGHT; |
Kristian Høgsberg | 0793756 | 2011-04-12 17:25:42 -0400 | [diff] [blame] | 3933 | |
Jason Ekstrand | 918f2dd | 2013-12-02 21:01:53 -0600 | [diff] [blame] | 3934 | if (y < shsurf->surface->height / 3) |
Pekka Paalanen | 9d1613e | 2011-11-25 12:09:16 +0200 | [diff] [blame] | 3935 | edges |= WL_SHELL_SURFACE_RESIZE_TOP; |
Jason Ekstrand | 918f2dd | 2013-12-02 21:01:53 -0600 | [diff] [blame] | 3936 | else if (y < 2 * shsurf->surface->height / 3) |
Kristian Høgsberg | 0793756 | 2011-04-12 17:25:42 -0400 | [diff] [blame] | 3937 | edges |= 0; |
| 3938 | else |
Pekka Paalanen | 9d1613e | 2011-11-25 12:09:16 +0200 | [diff] [blame] | 3939 | edges |= WL_SHELL_SURFACE_RESIZE_BOTTOM; |
Kristian Høgsberg | 0793756 | 2011-04-12 17:25:42 -0400 | [diff] [blame] | 3940 | |
Kristian Høgsberg | c1693f2 | 2012-05-22 16:56:23 -0400 | [diff] [blame] | 3941 | surface_resize(shsurf, (struct weston_seat *) seat, edges); |
Kristian Høgsberg | 02ec0a5 | 2011-04-23 13:04:11 -0400 | [diff] [blame] | 3942 | } |
| 3943 | |
| 3944 | static void |
Kristian Høgsberg | e314875 | 2013-05-06 23:19:49 -0400 | [diff] [blame] | 3945 | 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] | 3946 | wl_fixed_t value, void *data) |
Scott Moreau | a3aa9c9 | 2012-03-22 11:01:03 -0600 | [diff] [blame] | 3947 | { |
Jonas Ådahl | b0b87ba | 2012-09-27 18:40:42 +0200 | [diff] [blame] | 3948 | float step = 0.005; |
Scott Moreau | a3aa9c9 | 2012-03-22 11:01:03 -0600 | [diff] [blame] | 3949 | struct shell_surface *shsurf; |
Kristian Høgsberg | 7ab139c | 2013-10-24 16:21:39 -0700 | [diff] [blame] | 3950 | struct weston_surface *focus = seat->pointer->focus->surface; |
Pekka Paalanen | 01388e2 | 2013-04-25 13:57:44 +0300 | [diff] [blame] | 3951 | struct weston_surface *surface; |
Scott Moreau | a3aa9c9 | 2012-03-22 11:01:03 -0600 | [diff] [blame] | 3952 | |
Pekka Paalanen | 01388e2 | 2013-04-25 13:57:44 +0300 | [diff] [blame] | 3953 | /* XXX: broken for windows containing sub-surfaces */ |
| 3954 | surface = weston_surface_get_main_surface(focus); |
Scott Moreau | a3aa9c9 | 2012-03-22 11:01:03 -0600 | [diff] [blame] | 3955 | if (surface == NULL) |
| 3956 | return; |
| 3957 | |
| 3958 | shsurf = get_shell_surface(surface); |
| 3959 | if (!shsurf) |
| 3960 | return; |
| 3961 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 3962 | shsurf->view->alpha -= wl_fixed_to_double(value) * step; |
Scott Moreau | a3aa9c9 | 2012-03-22 11:01:03 -0600 | [diff] [blame] | 3963 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 3964 | if (shsurf->view->alpha > 1.0) |
| 3965 | shsurf->view->alpha = 1.0; |
| 3966 | if (shsurf->view->alpha < step) |
| 3967 | shsurf->view->alpha = step; |
Scott Moreau | a3aa9c9 | 2012-03-22 11:01:03 -0600 | [diff] [blame] | 3968 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 3969 | weston_view_geometry_dirty(shsurf->view); |
Scott Moreau | a3aa9c9 | 2012-03-22 11:01:03 -0600 | [diff] [blame] | 3970 | weston_surface_damage(surface); |
| 3971 | } |
| 3972 | |
| 3973 | static void |
Kristian Høgsberg | e314875 | 2013-05-06 23:19:49 -0400 | [diff] [blame] | 3974 | 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] | 3975 | wl_fixed_t value) |
Scott Moreau | ccbf29d | 2012-02-22 14:21:41 -0700 | [diff] [blame] | 3976 | { |
Daniel Stone | 37816df | 2012-05-16 18:45:18 +0100 | [diff] [blame] | 3977 | struct weston_seat *ws = (struct weston_seat *) seat; |
| 3978 | struct weston_compositor *compositor = ws->compositor; |
Scott Moreau | ccbf29d | 2012-02-22 14:21:41 -0700 | [diff] [blame] | 3979 | struct weston_output *output; |
Scott Moreau | e660398 | 2012-06-11 13:07:51 -0600 | [diff] [blame] | 3980 | float increment; |
Scott Moreau | ccbf29d | 2012-02-22 14:21:41 -0700 | [diff] [blame] | 3981 | |
| 3982 | wl_list_for_each(output, &compositor->output_list, link) { |
| 3983 | if (pixman_region32_contains_point(&output->region, |
Daniel Stone | 37816df | 2012-05-16 18:45:18 +0100 | [diff] [blame] | 3984 | wl_fixed_to_double(seat->pointer->x), |
| 3985 | wl_fixed_to_double(seat->pointer->y), |
Daniel Stone | 103db7f | 2012-05-08 17:17:55 +0100 | [diff] [blame] | 3986 | NULL)) { |
Daniel Stone | 325fc2d | 2012-05-30 16:31:58 +0100 | [diff] [blame] | 3987 | if (key == KEY_PAGEUP) |
Kristian Høgsberg | 9b68af0 | 2012-05-22 12:55:18 -0400 | [diff] [blame] | 3988 | increment = output->zoom.increment; |
Daniel Stone | 325fc2d | 2012-05-30 16:31:58 +0100 | [diff] [blame] | 3989 | else if (key == KEY_PAGEDOWN) |
Kristian Høgsberg | 9b68af0 | 2012-05-22 12:55:18 -0400 | [diff] [blame] | 3990 | increment = -output->zoom.increment; |
| 3991 | else if (axis == WL_POINTER_AXIS_VERTICAL_SCROLL) |
Jonas Ådahl | b0b87ba | 2012-09-27 18:40:42 +0200 | [diff] [blame] | 3992 | /* For every pixel zoom 20th of a step */ |
Daniel Stone | 0c1e46e | 2012-05-30 16:31:59 +0100 | [diff] [blame] | 3993 | increment = output->zoom.increment * |
Jonas Ådahl | b0b87ba | 2012-09-27 18:40:42 +0200 | [diff] [blame] | 3994 | -wl_fixed_to_double(value) / 20.0; |
Kristian Høgsberg | 9b68af0 | 2012-05-22 12:55:18 -0400 | [diff] [blame] | 3995 | else |
| 3996 | increment = 0; |
| 3997 | |
Kristian Høgsberg | 9b68af0 | 2012-05-22 12:55:18 -0400 | [diff] [blame] | 3998 | output->zoom.level += increment; |
Scott Moreau | c6d7f60 | 2012-02-23 22:28:37 -0700 | [diff] [blame] | 3999 | |
Scott Moreau | e660398 | 2012-06-11 13:07:51 -0600 | [diff] [blame] | 4000 | if (output->zoom.level < 0.0) |
Scott Moreau | 850ca42 | 2012-05-21 15:21:25 -0600 | [diff] [blame] | 4001 | output->zoom.level = 0.0; |
Scott Moreau | e660398 | 2012-06-11 13:07:51 -0600 | [diff] [blame] | 4002 | else if (output->zoom.level > output->zoom.max_level) |
| 4003 | output->zoom.level = output->zoom.max_level; |
Ville Syrjälä | aa628d0 | 2012-11-16 11:48:47 +0200 | [diff] [blame] | 4004 | else if (!output->zoom.active) { |
Giulio Camuffo | 412b024 | 2013-11-14 23:42:51 +0100 | [diff] [blame] | 4005 | weston_output_activate_zoom(output); |
Kristian Høgsberg | 79af73e | 2012-08-03 15:45:23 -0400 | [diff] [blame] | 4006 | } |
Scott Moreau | ccbf29d | 2012-02-22 14:21:41 -0700 | [diff] [blame] | 4007 | |
Scott Moreau | e660398 | 2012-06-11 13:07:51 -0600 | [diff] [blame] | 4008 | output->zoom.spring_z.target = output->zoom.level; |
Scott Moreau | ccbf29d | 2012-02-22 14:21:41 -0700 | [diff] [blame] | 4009 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 4010 | weston_output_update_zoom(output); |
Scott Moreau | ccbf29d | 2012-02-22 14:21:41 -0700 | [diff] [blame] | 4011 | } |
| 4012 | } |
| 4013 | } |
| 4014 | |
Scott Moreau | ccbf29d | 2012-02-22 14:21:41 -0700 | [diff] [blame] | 4015 | static void |
Kristian Høgsberg | e314875 | 2013-05-06 23:19:49 -0400 | [diff] [blame] | 4016 | 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] | 4017 | wl_fixed_t value, void *data) |
Daniel Stone | 325fc2d | 2012-05-30 16:31:58 +0100 | [diff] [blame] | 4018 | { |
| 4019 | do_zoom(seat, time, 0, axis, value); |
| 4020 | } |
| 4021 | |
| 4022 | static void |
Kristian Høgsberg | e314875 | 2013-05-06 23:19:49 -0400 | [diff] [blame] | 4023 | 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] | 4024 | void *data) |
| 4025 | { |
| 4026 | do_zoom(seat, time, key, 0, 0); |
| 4027 | } |
| 4028 | |
| 4029 | static void |
Kristian Høgsberg | e314875 | 2013-05-06 23:19:49 -0400 | [diff] [blame] | 4030 | terminate_binding(struct weston_seat *seat, uint32_t time, uint32_t key, |
Daniel Stone | 325fc2d | 2012-05-30 16:31:58 +0100 | [diff] [blame] | 4031 | void *data) |
Kristian Høgsberg | e1a850e | 2011-12-19 15:18:05 -0500 | [diff] [blame] | 4032 | { |
Kristian Høgsberg | 8334bc1 | 2012-01-03 10:29:47 -0500 | [diff] [blame] | 4033 | struct weston_compositor *compositor = data; |
Kristian Høgsberg | e1a850e | 2011-12-19 15:18:05 -0500 | [diff] [blame] | 4034 | |
Daniel Stone | 325fc2d | 2012-05-30 16:31:58 +0100 | [diff] [blame] | 4035 | wl_display_terminate(compositor->wl_display); |
Kristian Høgsberg | e1a850e | 2011-12-19 15:18:05 -0500 | [diff] [blame] | 4036 | } |
| 4037 | |
Emilio Pozuelo Monfort | 03251b6 | 2013-11-19 11:37:16 +0100 | [diff] [blame] | 4038 | static void |
Giulio Camuffo | 1959ab8 | 2013-11-14 23:42:52 +0100 | [diff] [blame] | 4039 | rotate_grab_motion(struct weston_pointer_grab *grab, uint32_t time, |
| 4040 | wl_fixed_t x, wl_fixed_t y) |
Pekka Paalanen | 460099f | 2012-01-20 16:48:25 +0200 | [diff] [blame] | 4041 | { |
| 4042 | struct rotate_grab *rotate = |
Ander Conselvan de Oliveira | fe0444a | 2012-04-04 17:48:05 +0300 | [diff] [blame] | 4043 | container_of(grab, struct rotate_grab, base.grab); |
Kristian Høgsberg | 02bbabb | 2013-05-06 22:15:05 -0400 | [diff] [blame] | 4044 | struct weston_pointer *pointer = grab->pointer; |
Ander Conselvan de Oliveira | fe0444a | 2012-04-04 17:48:05 +0300 | [diff] [blame] | 4045 | struct shell_surface *shsurf = rotate->base.shsurf; |
John Kåre Alsaker | 490d02a | 2012-09-30 02:57:21 +0200 | [diff] [blame] | 4046 | float cx, cy, dx, dy, cposx, cposy, dposx, dposy, r; |
Ander Conselvan de Oliveira | fe0444a | 2012-04-04 17:48:05 +0300 | [diff] [blame] | 4047 | |
Giulio Camuffo | 1959ab8 | 2013-11-14 23:42:52 +0100 | [diff] [blame] | 4048 | weston_pointer_move(pointer, x, y); |
| 4049 | |
Ander Conselvan de Oliveira | fe0444a | 2012-04-04 17:48:05 +0300 | [diff] [blame] | 4050 | if (!shsurf) |
| 4051 | return; |
| 4052 | |
Jason Ekstrand | 918f2dd | 2013-12-02 21:01:53 -0600 | [diff] [blame] | 4053 | cx = 0.5f * shsurf->surface->width; |
| 4054 | cy = 0.5f * shsurf->surface->height; |
Pekka Paalanen | 460099f | 2012-01-20 16:48:25 +0200 | [diff] [blame] | 4055 | |
Daniel Stone | 37816df | 2012-05-16 18:45:18 +0100 | [diff] [blame] | 4056 | dx = wl_fixed_to_double(pointer->x) - rotate->center.x; |
| 4057 | dy = wl_fixed_to_double(pointer->y) - rotate->center.y; |
Pekka Paalanen | 460099f | 2012-01-20 16:48:25 +0200 | [diff] [blame] | 4058 | r = sqrtf(dx * dx + dy * dy); |
| 4059 | |
Ander Conselvan de Oliveira | fe0444a | 2012-04-04 17:48:05 +0300 | [diff] [blame] | 4060 | wl_list_remove(&shsurf->rotation.transform.link); |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 4061 | weston_view_geometry_dirty(shsurf->view); |
Pekka Paalanen | 460099f | 2012-01-20 16:48:25 +0200 | [diff] [blame] | 4062 | |
| 4063 | if (r > 20.0f) { |
Pekka Paalanen | 460099f | 2012-01-20 16:48:25 +0200 | [diff] [blame] | 4064 | struct weston_matrix *matrix = |
Ander Conselvan de Oliveira | fe0444a | 2012-04-04 17:48:05 +0300 | [diff] [blame] | 4065 | &shsurf->rotation.transform.matrix; |
Pekka Paalanen | 460099f | 2012-01-20 16:48:25 +0200 | [diff] [blame] | 4066 | |
Kristian Høgsberg | 765e27b | 2012-01-27 13:36:13 -0500 | [diff] [blame] | 4067 | weston_matrix_init(&rotate->rotation); |
Vasily Khoruzhick | 1bbf372 | 2013-01-28 22:40:28 +0300 | [diff] [blame] | 4068 | weston_matrix_rotate_xy(&rotate->rotation, dx / r, dy / r); |
Pekka Paalanen | 460099f | 2012-01-20 16:48:25 +0200 | [diff] [blame] | 4069 | |
| 4070 | weston_matrix_init(matrix); |
Pekka Paalanen | 7b3bd3d | 2012-01-30 14:16:34 +0200 | [diff] [blame] | 4071 | weston_matrix_translate(matrix, -cx, -cy, 0.0f); |
Ander Conselvan de Oliveira | fe0444a | 2012-04-04 17:48:05 +0300 | [diff] [blame] | 4072 | weston_matrix_multiply(matrix, &shsurf->rotation.rotation); |
Kristian Høgsberg | 765e27b | 2012-01-27 13:36:13 -0500 | [diff] [blame] | 4073 | weston_matrix_multiply(matrix, &rotate->rotation); |
Pekka Paalanen | 7b3bd3d | 2012-01-30 14:16:34 +0200 | [diff] [blame] | 4074 | weston_matrix_translate(matrix, cx, cy, 0.0f); |
Pekka Paalanen | 460099f | 2012-01-20 16:48:25 +0200 | [diff] [blame] | 4075 | |
Pekka Paalanen | bc0b7e7 | 2012-01-24 09:53:37 +0200 | [diff] [blame] | 4076 | wl_list_insert( |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 4077 | &shsurf->view->geometry.transformation_list, |
Ander Conselvan de Oliveira | fe0444a | 2012-04-04 17:48:05 +0300 | [diff] [blame] | 4078 | &shsurf->rotation.transform.link); |
Pekka Paalanen | 460099f | 2012-01-20 16:48:25 +0200 | [diff] [blame] | 4079 | } else { |
Ander Conselvan de Oliveira | fe0444a | 2012-04-04 17:48:05 +0300 | [diff] [blame] | 4080 | wl_list_init(&shsurf->rotation.transform.link); |
| 4081 | weston_matrix_init(&shsurf->rotation.rotation); |
Kristian Høgsberg | 765e27b | 2012-01-27 13:36:13 -0500 | [diff] [blame] | 4082 | weston_matrix_init(&rotate->rotation); |
Pekka Paalanen | 460099f | 2012-01-20 16:48:25 +0200 | [diff] [blame] | 4083 | } |
Pekka Paalanen | b45ac5e | 2012-02-09 15:58:44 +0200 | [diff] [blame] | 4084 | |
Rafal Mielniczuk | 2d7ab82 | 2012-03-22 22:22:04 +0100 | [diff] [blame] | 4085 | /* We need to adjust the position of the surface |
| 4086 | * in case it was resized in a rotated state before */ |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 4087 | cposx = shsurf->view->geometry.x + cx; |
| 4088 | cposy = shsurf->view->geometry.y + cy; |
Rafal Mielniczuk | 2d7ab82 | 2012-03-22 22:22:04 +0100 | [diff] [blame] | 4089 | dposx = rotate->center.x - cposx; |
| 4090 | dposy = rotate->center.y - cposy; |
| 4091 | if (dposx != 0.0f || dposy != 0.0f) { |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 4092 | weston_view_set_position(shsurf->view, |
| 4093 | shsurf->view->geometry.x + dposx, |
| 4094 | shsurf->view->geometry.y + dposy); |
Rafal Mielniczuk | 2d7ab82 | 2012-03-22 22:22:04 +0100 | [diff] [blame] | 4095 | } |
| 4096 | |
Pekka Paalanen | b45ac5e | 2012-02-09 15:58:44 +0200 | [diff] [blame] | 4097 | /* Repaint implies weston_surface_update_transform(), which |
| 4098 | * lazily applies the damage due to rotation update. |
| 4099 | */ |
Ander Conselvan de Oliveira | fe0444a | 2012-04-04 17:48:05 +0300 | [diff] [blame] | 4100 | weston_compositor_schedule_repaint(shsurf->surface->compositor); |
Pekka Paalanen | 460099f | 2012-01-20 16:48:25 +0200 | [diff] [blame] | 4101 | } |
| 4102 | |
| 4103 | static void |
Kristian Høgsberg | 02bbabb | 2013-05-06 22:15:05 -0400 | [diff] [blame] | 4104 | rotate_grab_button(struct weston_pointer_grab *grab, |
| 4105 | uint32_t time, uint32_t button, uint32_t state_w) |
Pekka Paalanen | 460099f | 2012-01-20 16:48:25 +0200 | [diff] [blame] | 4106 | { |
| 4107 | struct rotate_grab *rotate = |
Ander Conselvan de Oliveira | fe0444a | 2012-04-04 17:48:05 +0300 | [diff] [blame] | 4108 | container_of(grab, struct rotate_grab, base.grab); |
Kristian Høgsberg | 02bbabb | 2013-05-06 22:15:05 -0400 | [diff] [blame] | 4109 | struct weston_pointer *pointer = grab->pointer; |
Ander Conselvan de Oliveira | fe0444a | 2012-04-04 17:48:05 +0300 | [diff] [blame] | 4110 | struct shell_surface *shsurf = rotate->base.shsurf; |
Daniel Stone | 4dbadb1 | 2012-05-30 16:31:51 +0100 | [diff] [blame] | 4111 | enum wl_pointer_button_state state = state_w; |
Pekka Paalanen | 460099f | 2012-01-20 16:48:25 +0200 | [diff] [blame] | 4112 | |
Daniel Stone | 4dbadb1 | 2012-05-30 16:31:51 +0100 | [diff] [blame] | 4113 | if (pointer->button_count == 0 && |
| 4114 | state == WL_POINTER_BUTTON_STATE_RELEASED) { |
Ander Conselvan de Oliveira | fe0444a | 2012-04-04 17:48:05 +0300 | [diff] [blame] | 4115 | if (shsurf) |
| 4116 | weston_matrix_multiply(&shsurf->rotation.rotation, |
| 4117 | &rotate->rotation); |
Ander Conselvan de Oliveira | b9d2a0f | 2012-06-28 18:08:05 +0300 | [diff] [blame] | 4118 | shell_grab_end(&rotate->base); |
Pekka Paalanen | 460099f | 2012-01-20 16:48:25 +0200 | [diff] [blame] | 4119 | free(rotate); |
| 4120 | } |
| 4121 | } |
| 4122 | |
Jonas Ådahl | 1ea343e | 2013-10-25 23:18:05 +0200 | [diff] [blame] | 4123 | static void |
| 4124 | rotate_grab_cancel(struct weston_pointer_grab *grab) |
| 4125 | { |
| 4126 | struct rotate_grab *rotate = |
| 4127 | container_of(grab, struct rotate_grab, base.grab); |
| 4128 | |
| 4129 | shell_grab_end(&rotate->base); |
| 4130 | free(rotate); |
| 4131 | } |
| 4132 | |
Kristian Høgsberg | 02bbabb | 2013-05-06 22:15:05 -0400 | [diff] [blame] | 4133 | static const struct weston_pointer_grab_interface rotate_grab_interface = { |
Pekka Paalanen | 460099f | 2012-01-20 16:48:25 +0200 | [diff] [blame] | 4134 | noop_grab_focus, |
| 4135 | rotate_grab_motion, |
| 4136 | rotate_grab_button, |
Jonas Ådahl | 1ea343e | 2013-10-25 23:18:05 +0200 | [diff] [blame] | 4137 | rotate_grab_cancel, |
Pekka Paalanen | 460099f | 2012-01-20 16:48:25 +0200 | [diff] [blame] | 4138 | }; |
| 4139 | |
| 4140 | static void |
Kristian Høgsberg | e314875 | 2013-05-06 23:19:49 -0400 | [diff] [blame] | 4141 | surface_rotate(struct shell_surface *surface, struct weston_seat *seat) |
Pekka Paalanen | 460099f | 2012-01-20 16:48:25 +0200 | [diff] [blame] | 4142 | { |
Pekka Paalanen | 460099f | 2012-01-20 16:48:25 +0200 | [diff] [blame] | 4143 | struct rotate_grab *rotate; |
John Kåre Alsaker | 490d02a | 2012-09-30 02:57:21 +0200 | [diff] [blame] | 4144 | float dx, dy; |
| 4145 | float r; |
Pekka Paalanen | 460099f | 2012-01-20 16:48:25 +0200 | [diff] [blame] | 4146 | |
Pekka Paalanen | 460099f | 2012-01-20 16:48:25 +0200 | [diff] [blame] | 4147 | rotate = malloc(sizeof *rotate); |
| 4148 | if (!rotate) |
| 4149 | return; |
| 4150 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 4151 | weston_view_to_global_float(surface->view, |
Jason Ekstrand | 918f2dd | 2013-12-02 21:01:53 -0600 | [diff] [blame] | 4152 | surface->surface->width * 0.5f, |
| 4153 | surface->surface->height * 0.5f, |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 4154 | &rotate->center.x, &rotate->center.y); |
Pekka Paalanen | 460099f | 2012-01-20 16:48:25 +0200 | [diff] [blame] | 4155 | |
Daniel Stone | 37816df | 2012-05-16 18:45:18 +0100 | [diff] [blame] | 4156 | dx = wl_fixed_to_double(seat->pointer->x) - rotate->center.x; |
| 4157 | dy = wl_fixed_to_double(seat->pointer->y) - rotate->center.y; |
Kristian Høgsberg | 765e27b | 2012-01-27 13:36:13 -0500 | [diff] [blame] | 4158 | r = sqrtf(dx * dx + dy * dy); |
| 4159 | if (r > 20.0f) { |
| 4160 | struct weston_matrix inverse; |
| 4161 | |
| 4162 | weston_matrix_init(&inverse); |
Vasily Khoruzhick | 1bbf372 | 2013-01-28 22:40:28 +0300 | [diff] [blame] | 4163 | weston_matrix_rotate_xy(&inverse, dx / r, -dy / r); |
Kristian Høgsberg | 765e27b | 2012-01-27 13:36:13 -0500 | [diff] [blame] | 4164 | weston_matrix_multiply(&surface->rotation.rotation, &inverse); |
Rafal Mielniczuk | 2d7ab82 | 2012-03-22 22:22:04 +0100 | [diff] [blame] | 4165 | |
| 4166 | weston_matrix_init(&rotate->rotation); |
Vasily Khoruzhick | 1bbf372 | 2013-01-28 22:40:28 +0300 | [diff] [blame] | 4167 | weston_matrix_rotate_xy(&rotate->rotation, dx / r, dy / r); |
Kristian Høgsberg | 765e27b | 2012-01-27 13:36:13 -0500 | [diff] [blame] | 4168 | } else { |
| 4169 | weston_matrix_init(&surface->rotation.rotation); |
| 4170 | weston_matrix_init(&rotate->rotation); |
| 4171 | } |
| 4172 | |
Ander Conselvan de Oliveira | b9d2a0f | 2012-06-28 18:08:05 +0300 | [diff] [blame] | 4173 | shell_grab_start(&rotate->base, &rotate_grab_interface, surface, |
| 4174 | seat->pointer, DESKTOP_SHELL_CURSOR_ARROW); |
Pekka Paalanen | 460099f | 2012-01-20 16:48:25 +0200 | [diff] [blame] | 4175 | } |
| 4176 | |
| 4177 | static void |
Kristian Høgsberg | e314875 | 2013-05-06 23:19:49 -0400 | [diff] [blame] | 4178 | 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] | 4179 | void *data) |
| 4180 | { |
Rafal Mielniczuk | b2917a2 | 2014-01-05 20:04:59 +0100 | [diff] [blame] | 4181 | struct weston_surface *focus; |
Pekka Paalanen | 01388e2 | 2013-04-25 13:57:44 +0300 | [diff] [blame] | 4182 | struct weston_surface *base_surface; |
Kristian Høgsberg | 0c36903 | 2013-02-14 21:31:44 -0500 | [diff] [blame] | 4183 | struct shell_surface *surface; |
| 4184 | |
Rafal Mielniczuk | b2917a2 | 2014-01-05 20:04:59 +0100 | [diff] [blame] | 4185 | if (seat->pointer->focus == NULL) |
| 4186 | return; |
| 4187 | |
| 4188 | focus = seat->pointer->focus->surface; |
| 4189 | |
Pekka Paalanen | 01388e2 | 2013-04-25 13:57:44 +0300 | [diff] [blame] | 4190 | base_surface = weston_surface_get_main_surface(focus); |
Kristian Høgsberg | 0c36903 | 2013-02-14 21:31:44 -0500 | [diff] [blame] | 4191 | if (base_surface == NULL) |
| 4192 | return; |
| 4193 | |
| 4194 | surface = get_shell_surface(base_surface); |
Rafael Antognolli | 03b1659 | 2013-12-03 15:35:42 -0200 | [diff] [blame] | 4195 | if (surface == NULL || surface->state.fullscreen || |
| 4196 | surface->state.maximized) |
Kristian Høgsberg | 0c36903 | 2013-02-14 21:31:44 -0500 | [diff] [blame] | 4197 | return; |
| 4198 | |
| 4199 | surface_rotate(surface, seat); |
| 4200 | } |
| 4201 | |
Philip Withnall | 83ffd9d | 2013-11-25 18:01:42 +0000 | [diff] [blame] | 4202 | /* Move all fullscreen layers down to the current workspace in a non-reversible |
| 4203 | * manner. This should be used when implementing shell-wide overlays, such as |
| 4204 | * the alt-tab switcher, which need to de-promote fullscreen layers. */ |
Kristian Høgsberg | 1ef2313 | 2013-12-04 00:20:01 -0800 | [diff] [blame] | 4205 | void |
Kristian Høgsberg | b0d8e77 | 2012-06-18 16:34:58 -0400 | [diff] [blame] | 4206 | lower_fullscreen_layer(struct desktop_shell *shell) |
| 4207 | { |
| 4208 | struct workspace *ws; |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 4209 | struct weston_view *view, *prev; |
Kristian Høgsberg | b0d8e77 | 2012-06-18 16:34:58 -0400 | [diff] [blame] | 4210 | |
| 4211 | ws = get_current_workspace(shell); |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 4212 | wl_list_for_each_reverse_safe(view, prev, |
| 4213 | &shell->fullscreen_layer.view_list, |
Philip Withnall | 83ffd9d | 2013-11-25 18:01:42 +0000 | [diff] [blame] | 4214 | layer_link) { |
| 4215 | wl_list_remove(&view->layer_link); |
| 4216 | wl_list_insert(&ws->layer.view_list, &view->layer_link); |
| 4217 | weston_view_damage_below(view); |
| 4218 | weston_surface_damage(view->surface); |
| 4219 | } |
Kristian Høgsberg | b0d8e77 | 2012-06-18 16:34:58 -0400 | [diff] [blame] | 4220 | } |
| 4221 | |
Kristian Høgsberg | 1ef2313 | 2013-12-04 00:20:01 -0800 | [diff] [blame] | 4222 | void |
Tiago Vignatti | be14326 | 2012-04-16 17:31:41 +0300 | [diff] [blame] | 4223 | activate(struct desktop_shell *shell, struct weston_surface *es, |
Daniel Stone | 37816df | 2012-05-16 18:45:18 +0100 | [diff] [blame] | 4224 | struct weston_seat *seat) |
Kristian Høgsberg | 7584062 | 2011-09-06 13:48:16 -0400 | [diff] [blame] | 4225 | { |
Pekka Paalanen | 01388e2 | 2013-04-25 13:57:44 +0300 | [diff] [blame] | 4226 | struct weston_surface *main_surface; |
Kristian Høgsberg | 2f5faff | 2012-07-31 16:36:34 -0400 | [diff] [blame] | 4227 | struct focus_state *state; |
Jonas Ådahl | 8538b22 | 2012-08-29 22:13:03 +0200 | [diff] [blame] | 4228 | struct workspace *ws; |
Louis-Francis Ratté-Boulianne | b482dbd | 2013-11-19 11:37:11 +0100 | [diff] [blame] | 4229 | struct weston_surface *old_es; |
Rafael Antognolli | 03b1659 | 2013-12-03 15:35:42 -0200 | [diff] [blame] | 4230 | struct shell_surface *shsurf; |
Kristian Høgsberg | 7584062 | 2011-09-06 13:48:16 -0400 | [diff] [blame] | 4231 | |
Pekka Paalanen | 01388e2 | 2013-04-25 13:57:44 +0300 | [diff] [blame] | 4232 | main_surface = weston_surface_get_main_surface(es); |
| 4233 | |
Daniel Stone | 37816df | 2012-05-16 18:45:18 +0100 | [diff] [blame] | 4234 | weston_surface_activate(es, seat); |
Kristian Høgsberg | 7584062 | 2011-09-06 13:48:16 -0400 | [diff] [blame] | 4235 | |
Jonas Ådahl | 8538b22 | 2012-08-29 22:13:03 +0200 | [diff] [blame] | 4236 | state = ensure_focus_state(shell, seat); |
| 4237 | if (state == NULL) |
| 4238 | return; |
Kristian Høgsberg | 2f5faff | 2012-07-31 16:36:34 -0400 | [diff] [blame] | 4239 | |
Louis-Francis Ratté-Boulianne | b482dbd | 2013-11-19 11:37:11 +0100 | [diff] [blame] | 4240 | old_es = state->keyboard_focus; |
Kristian Høgsberg | d500bf1 | 2014-01-22 12:25:20 -0800 | [diff] [blame^] | 4241 | focus_state_set_focus(state, es); |
Kristian Høgsberg | 2f5faff | 2012-07-31 16:36:34 -0400 | [diff] [blame] | 4242 | |
Rafael Antognolli | 03b1659 | 2013-12-03 15:35:42 -0200 | [diff] [blame] | 4243 | shsurf = get_shell_surface(main_surface); |
U. Artie Eoff | cf5737a | 2014-01-17 10:08:25 -0800 | [diff] [blame] | 4244 | assert(shsurf); |
| 4245 | |
Rafael Antognolli | 03b1659 | 2013-12-03 15:35:42 -0200 | [diff] [blame] | 4246 | if (shsurf->state.fullscreen) |
| 4247 | shell_configure_fullscreen(shsurf); |
| 4248 | else |
Alexander Larsson | f82b6ca | 2013-05-28 16:23:39 +0200 | [diff] [blame] | 4249 | restore_all_output_modes(shell->compositor); |
Louis-Francis Ratté-Boulianne | b482dbd | 2013-11-19 11:37:11 +0100 | [diff] [blame] | 4250 | |
Philip Withnall | 83ffd9d | 2013-11-25 18:01:42 +0000 | [diff] [blame] | 4251 | if (shell->focus_animation_type != ANIMATION_NONE) { |
| 4252 | ws = get_current_workspace(shell); |
Louis-Francis Ratté-Boulianne | b482dbd | 2013-11-19 11:37:11 +0100 | [diff] [blame] | 4253 | 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] | 4254 | } |
| 4255 | |
| 4256 | /* Update the surface’s layer. This brings it to the top of the stacking |
| 4257 | * order as appropriate. */ |
U. Artie Eoff | cf5737a | 2014-01-17 10:08:25 -0800 | [diff] [blame] | 4258 | shell_surface_update_layer(shsurf); |
Kristian Høgsberg | 7584062 | 2011-09-06 13:48:16 -0400 | [diff] [blame] | 4259 | } |
| 4260 | |
Alex Wu | 2185843 | 2012-04-01 20:13:08 +0800 | [diff] [blame] | 4261 | /* no-op func for checking black surface */ |
| 4262 | static void |
Jason Ekstrand | 918f2dd | 2013-12-02 21:01:53 -0600 | [diff] [blame] | 4263 | 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] | 4264 | { |
| 4265 | } |
| 4266 | |
Quentin Glidic | c0d79ce | 2013-01-29 14:16:13 +0100 | [diff] [blame] | 4267 | static bool |
Alex Wu | 2185843 | 2012-04-01 20:13:08 +0800 | [diff] [blame] | 4268 | is_black_surface (struct weston_surface *es, struct weston_surface **fs_surface) |
| 4269 | { |
| 4270 | if (es->configure == black_surface_configure) { |
| 4271 | if (fs_surface) |
Giulio Camuffo | 7fe01b1 | 2013-03-28 18:02:42 +0100 | [diff] [blame] | 4272 | *fs_surface = (struct weston_surface *)es->configure_private; |
Alex Wu | 2185843 | 2012-04-01 20:13:08 +0800 | [diff] [blame] | 4273 | return true; |
| 4274 | } |
| 4275 | return false; |
| 4276 | } |
| 4277 | |
Kristian Høgsberg | 7584062 | 2011-09-06 13:48:16 -0400 | [diff] [blame] | 4278 | static void |
Neil Roberts | a28c693 | 2013-10-03 16:43:04 +0100 | [diff] [blame] | 4279 | activate_binding(struct weston_seat *seat, |
| 4280 | struct desktop_shell *shell, |
| 4281 | struct weston_surface *focus) |
Kristian Høgsberg | e1a850e | 2011-12-19 15:18:05 -0500 | [diff] [blame] | 4282 | { |
Pekka Paalanen | 01388e2 | 2013-04-25 13:57:44 +0300 | [diff] [blame] | 4283 | struct weston_surface *main_surface; |
Kristian Høgsberg | e1a850e | 2011-12-19 15:18:05 -0500 | [diff] [blame] | 4284 | |
Alex Wu | 9c35e6b | 2012-03-05 14:13:13 +0800 | [diff] [blame] | 4285 | if (!focus) |
| 4286 | return; |
| 4287 | |
Pekka Paalanen | 01388e2 | 2013-04-25 13:57:44 +0300 | [diff] [blame] | 4288 | if (is_black_surface(focus, &main_surface)) |
| 4289 | focus = main_surface; |
Alex Wu | 4539b08 | 2012-03-01 12:57:46 +0800 | [diff] [blame] | 4290 | |
Pekka Paalanen | 01388e2 | 2013-04-25 13:57:44 +0300 | [diff] [blame] | 4291 | main_surface = weston_surface_get_main_surface(focus); |
| 4292 | if (get_shell_surface_type(main_surface) == SHELL_SURFACE_NONE) |
Kristian Høgsberg | 0636ac3 | 2012-06-27 10:22:15 -0400 | [diff] [blame] | 4293 | return; |
Kristian Høgsberg | 85b2e4b | 2012-06-21 16:49:42 -0400 | [diff] [blame] | 4294 | |
Neil Roberts | a28c693 | 2013-10-03 16:43:04 +0100 | [diff] [blame] | 4295 | activate(shell, focus, seat); |
| 4296 | } |
| 4297 | |
| 4298 | static void |
| 4299 | click_to_activate_binding(struct weston_seat *seat, uint32_t time, uint32_t button, |
| 4300 | void *data) |
| 4301 | { |
| 4302 | if (seat->pointer->grab != &seat->pointer->default_grab) |
| 4303 | return; |
Kristian Høgsberg | 7c4f6cc | 2014-01-01 16:28:32 -0800 | [diff] [blame] | 4304 | if (seat->pointer->focus == NULL) |
| 4305 | return; |
Neil Roberts | a28c693 | 2013-10-03 16:43:04 +0100 | [diff] [blame] | 4306 | |
Kristian Høgsberg | 7ab139c | 2013-10-24 16:21:39 -0700 | [diff] [blame] | 4307 | activate_binding(seat, data, seat->pointer->focus->surface); |
Neil Roberts | a28c693 | 2013-10-03 16:43:04 +0100 | [diff] [blame] | 4308 | } |
| 4309 | |
| 4310 | static void |
| 4311 | touch_to_activate_binding(struct weston_seat *seat, uint32_t time, void *data) |
| 4312 | { |
| 4313 | if (seat->touch->grab != &seat->touch->default_grab) |
| 4314 | return; |
Kristian Høgsberg | 0ed6750 | 2014-01-02 23:00:11 -0800 | [diff] [blame] | 4315 | if (seat->touch->focus == NULL) |
| 4316 | return; |
Neil Roberts | a28c693 | 2013-10-03 16:43:04 +0100 | [diff] [blame] | 4317 | |
Kristian Høgsberg | 7ab139c | 2013-10-24 16:21:39 -0700 | [diff] [blame] | 4318 | activate_binding(seat, data, seat->touch->focus->surface); |
Kristian Høgsberg | e1a850e | 2011-12-19 15:18:05 -0500 | [diff] [blame] | 4319 | } |
| 4320 | |
| 4321 | static void |
Ander Conselvan de Oliveira | 19d10ef | 2013-02-21 18:35:20 +0200 | [diff] [blame] | 4322 | lock(struct desktop_shell *shell) |
Kristian Høgsberg | 02ec0a5 | 2011-04-23 13:04:11 -0400 | [diff] [blame] | 4323 | { |
Kristian Høgsberg | 4476aaf | 2012-06-25 14:03:13 -0400 | [diff] [blame] | 4324 | struct workspace *ws = get_current_workspace(shell); |
Pekka Paalanen | f0fc70d | 2011-11-15 13:34:54 +0200 | [diff] [blame] | 4325 | |
Tiago Vignatti | 8e53c7f | 2012-02-29 19:53:50 +0200 | [diff] [blame] | 4326 | if (shell->locked) { |
Ander Conselvan de Oliveira | 87524b6 | 2013-02-21 18:35:22 +0200 | [diff] [blame] | 4327 | weston_compositor_sleep(shell->compositor); |
Pekka Paalanen | f0fc70d | 2011-11-15 13:34:54 +0200 | [diff] [blame] | 4328 | return; |
Tiago Vignatti | 8e53c7f | 2012-02-29 19:53:50 +0200 | [diff] [blame] | 4329 | } |
Pekka Paalanen | 9ef3e01 | 2011-11-15 13:34:48 +0200 | [diff] [blame] | 4330 | |
| 4331 | shell->locked = true; |
Pekka Paalanen | f0fc70d | 2011-11-15 13:34:54 +0200 | [diff] [blame] | 4332 | |
Kristian Høgsberg | 3be2ce9 | 2012-02-29 12:42:35 -0500 | [diff] [blame] | 4333 | /* Hide all surfaces by removing the fullscreen, panel and |
| 4334 | * toplevel layers. This way nothing else can show or receive |
| 4335 | * input events while we are locked. */ |
Pekka Paalanen | f0fc70d | 2011-11-15 13:34:54 +0200 | [diff] [blame] | 4336 | |
Kristian Høgsberg | 3be2ce9 | 2012-02-29 12:42:35 -0500 | [diff] [blame] | 4337 | wl_list_remove(&shell->panel_layer.link); |
Kristian Høgsberg | 3be2ce9 | 2012-02-29 12:42:35 -0500 | [diff] [blame] | 4338 | wl_list_remove(&shell->fullscreen_layer.link); |
Philipp Brüschweiler | 711fda8 | 2012-08-09 18:50:43 +0200 | [diff] [blame] | 4339 | if (shell->showing_input_panels) |
| 4340 | wl_list_remove(&shell->input_panel_layer.link); |
Kristian Høgsberg | 4476aaf | 2012-06-25 14:03:13 -0400 | [diff] [blame] | 4341 | wl_list_remove(&ws->layer.link); |
Kristian Høgsberg | 3be2ce9 | 2012-02-29 12:42:35 -0500 | [diff] [blame] | 4342 | wl_list_insert(&shell->compositor->cursor_layer.link, |
| 4343 | &shell->lock_layer.link); |
Pekka Paalanen | f0fc70d | 2011-11-15 13:34:54 +0200 | [diff] [blame] | 4344 | |
Pekka Paalanen | 77346a6 | 2011-11-30 16:26:35 +0200 | [diff] [blame] | 4345 | launch_screensaver(shell); |
| 4346 | |
Pekka Paalanen | f0fc70d | 2011-11-15 13:34:54 +0200 | [diff] [blame] | 4347 | /* TODO: disable bindings that should not work while locked. */ |
| 4348 | |
| 4349 | /* All this must be undone in resume_desktop(). */ |
Pekka Paalanen | 9ef3e01 | 2011-11-15 13:34:48 +0200 | [diff] [blame] | 4350 | } |
| 4351 | |
| 4352 | static void |
Ander Conselvan de Oliveira | 19d10ef | 2013-02-21 18:35:20 +0200 | [diff] [blame] | 4353 | unlock(struct desktop_shell *shell) |
Pekka Paalanen | 9ef3e01 | 2011-11-15 13:34:48 +0200 | [diff] [blame] | 4354 | { |
Pekka Paalanen | d81c216 | 2011-11-16 13:47:34 +0200 | [diff] [blame] | 4355 | if (!shell->locked || shell->lock_surface) { |
Ander Conselvan de Oliveira | 87524b6 | 2013-02-21 18:35:22 +0200 | [diff] [blame] | 4356 | shell_fade(shell, FADE_IN); |
Pekka Paalanen | 9ef3e01 | 2011-11-15 13:34:48 +0200 | [diff] [blame] | 4357 | return; |
| 4358 | } |
| 4359 | |
| 4360 | /* If desktop-shell client has gone away, unlock immediately. */ |
| 4361 | if (!shell->child.desktop_shell) { |
Pekka Paalanen | f0fc70d | 2011-11-15 13:34:54 +0200 | [diff] [blame] | 4362 | resume_desktop(shell); |
Pekka Paalanen | 9ef3e01 | 2011-11-15 13:34:48 +0200 | [diff] [blame] | 4363 | return; |
| 4364 | } |
| 4365 | |
| 4366 | if (shell->prepare_event_sent) |
| 4367 | return; |
| 4368 | |
Kristian Høgsberg | 0b5cd0c | 2012-03-04 21:57:37 -0500 | [diff] [blame] | 4369 | desktop_shell_send_prepare_lock_surface(shell->child.desktop_shell); |
Pekka Paalanen | 9ef3e01 | 2011-11-15 13:34:48 +0200 | [diff] [blame] | 4370 | shell->prepare_event_sent = true; |
Kristian Høgsberg | 02ec0a5 | 2011-04-23 13:04:11 -0400 | [diff] [blame] | 4371 | } |
| 4372 | |
| 4373 | static void |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 4374 | shell_fade_done(struct weston_view_animation *animation, void *data) |
Ander Conselvan de Oliveira | 19d10ef | 2013-02-21 18:35:20 +0200 | [diff] [blame] | 4375 | { |
| 4376 | struct desktop_shell *shell = data; |
| 4377 | |
| 4378 | shell->fade.animation = NULL; |
| 4379 | |
| 4380 | switch (shell->fade.type) { |
| 4381 | case FADE_IN: |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 4382 | weston_surface_destroy(shell->fade.view->surface); |
| 4383 | shell->fade.view = NULL; |
Ander Conselvan de Oliveira | 19d10ef | 2013-02-21 18:35:20 +0200 | [diff] [blame] | 4384 | break; |
| 4385 | case FADE_OUT: |
Ander Conselvan de Oliveira | 19d10ef | 2013-02-21 18:35:20 +0200 | [diff] [blame] | 4386 | lock(shell); |
| 4387 | break; |
Philip Withnall | 4a86a0a | 2013-11-25 18:01:32 +0000 | [diff] [blame] | 4388 | default: |
| 4389 | break; |
Ander Conselvan de Oliveira | 19d10ef | 2013-02-21 18:35:20 +0200 | [diff] [blame] | 4390 | } |
| 4391 | } |
| 4392 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 4393 | static struct weston_view * |
Pekka Paalanen | 79346ab | 2013-05-22 18:03:09 +0300 | [diff] [blame] | 4394 | shell_fade_create_surface(struct desktop_shell *shell) |
Ander Conselvan de Oliveira | 19d10ef | 2013-02-21 18:35:20 +0200 | [diff] [blame] | 4395 | { |
| 4396 | struct weston_compositor *compositor = shell->compositor; |
| 4397 | struct weston_surface *surface; |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 4398 | struct weston_view *view; |
Pekka Paalanen | 79346ab | 2013-05-22 18:03:09 +0300 | [diff] [blame] | 4399 | |
| 4400 | surface = weston_surface_create(compositor); |
| 4401 | if (!surface) |
| 4402 | return NULL; |
| 4403 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 4404 | view = weston_view_create(surface); |
| 4405 | if (!view) { |
| 4406 | weston_surface_destroy(surface); |
| 4407 | return NULL; |
| 4408 | } |
| 4409 | |
Jason Ekstrand | 5c11a33 | 2013-12-04 20:32:03 -0600 | [diff] [blame] | 4410 | weston_surface_set_size(surface, 8192, 8192); |
Jason Ekstrand | 918f2dd | 2013-12-02 21:01:53 -0600 | [diff] [blame] | 4411 | weston_view_set_position(view, 0, 0); |
Pekka Paalanen | 79346ab | 2013-05-22 18:03:09 +0300 | [diff] [blame] | 4412 | 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] | 4413 | wl_list_insert(&compositor->fade_layer.view_list, |
| 4414 | &view->layer_link); |
Pekka Paalanen | 79346ab | 2013-05-22 18:03:09 +0300 | [diff] [blame] | 4415 | pixman_region32_init(&surface->input); |
| 4416 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 4417 | return view; |
Pekka Paalanen | 79346ab | 2013-05-22 18:03:09 +0300 | [diff] [blame] | 4418 | } |
| 4419 | |
| 4420 | static void |
| 4421 | shell_fade(struct desktop_shell *shell, enum fade_type type) |
| 4422 | { |
Ander Conselvan de Oliveira | 19d10ef | 2013-02-21 18:35:20 +0200 | [diff] [blame] | 4423 | float tint; |
| 4424 | |
| 4425 | switch (type) { |
| 4426 | case FADE_IN: |
| 4427 | tint = 0.0; |
| 4428 | break; |
| 4429 | case FADE_OUT: |
| 4430 | tint = 1.0; |
| 4431 | break; |
| 4432 | default: |
| 4433 | weston_log("shell: invalid fade type\n"); |
| 4434 | return; |
| 4435 | } |
| 4436 | |
| 4437 | shell->fade.type = type; |
| 4438 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 4439 | if (shell->fade.view == NULL) { |
| 4440 | shell->fade.view = shell_fade_create_surface(shell); |
| 4441 | if (!shell->fade.view) |
Ander Conselvan de Oliveira | 19d10ef | 2013-02-21 18:35:20 +0200 | [diff] [blame] | 4442 | return; |
| 4443 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 4444 | shell->fade.view->alpha = 1.0 - tint; |
| 4445 | weston_view_update_transform(shell->fade.view); |
Ander Conselvan de Oliveira | 19d10ef | 2013-02-21 18:35:20 +0200 | [diff] [blame] | 4446 | } |
| 4447 | |
Kristian Høgsberg | 87d3b61 | 2014-01-19 21:48:10 -0800 | [diff] [blame] | 4448 | if (shell->fade.view->output == NULL) { |
| 4449 | /* If the black view gets a NULL output, we lost the |
| 4450 | * last output and we'll just cancel the fade. This |
| 4451 | * happens when you close the last window under the |
| 4452 | * X11 or Wayland backends. */ |
| 4453 | shell->locked = false; |
| 4454 | weston_surface_destroy(shell->fade.view->surface); |
| 4455 | shell->fade.view = NULL; |
| 4456 | } else if (shell->fade.animation) { |
Kristian Høgsberg | 5281fb1 | 2013-06-17 10:10:28 -0400 | [diff] [blame] | 4457 | weston_fade_update(shell->fade.animation, tint); |
Kristian Høgsberg | 87d3b61 | 2014-01-19 21:48:10 -0800 | [diff] [blame] | 4458 | } else { |
Ander Conselvan de Oliveira | 19d10ef | 2013-02-21 18:35:20 +0200 | [diff] [blame] | 4459 | shell->fade.animation = |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 4460 | weston_fade_run(shell->fade.view, |
Kristian Høgsberg | 5281fb1 | 2013-06-17 10:10:28 -0400 | [diff] [blame] | 4461 | 1.0 - tint, tint, 300.0, |
Ander Conselvan de Oliveira | 19d10ef | 2013-02-21 18:35:20 +0200 | [diff] [blame] | 4462 | shell_fade_done, shell); |
Kristian Høgsberg | 87d3b61 | 2014-01-19 21:48:10 -0800 | [diff] [blame] | 4463 | } |
Ander Conselvan de Oliveira | 19d10ef | 2013-02-21 18:35:20 +0200 | [diff] [blame] | 4464 | } |
| 4465 | |
| 4466 | static void |
Pekka Paalanen | 79346ab | 2013-05-22 18:03:09 +0300 | [diff] [blame] | 4467 | do_shell_fade_startup(void *data) |
| 4468 | { |
| 4469 | struct desktop_shell *shell = data; |
| 4470 | |
Kristian Høgsberg | 724c8d9 | 2013-10-16 11:38:24 -0700 | [diff] [blame] | 4471 | if (shell->startup_animation_type == ANIMATION_FADE) |
| 4472 | shell_fade(shell, FADE_IN); |
| 4473 | else if (shell->startup_animation_type == ANIMATION_NONE) { |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 4474 | weston_surface_destroy(shell->fade.view->surface); |
| 4475 | shell->fade.view = NULL; |
Kristian Høgsberg | 724c8d9 | 2013-10-16 11:38:24 -0700 | [diff] [blame] | 4476 | } |
Pekka Paalanen | 79346ab | 2013-05-22 18:03:09 +0300 | [diff] [blame] | 4477 | } |
| 4478 | |
| 4479 | static void |
| 4480 | shell_fade_startup(struct desktop_shell *shell) |
| 4481 | { |
| 4482 | struct wl_event_loop *loop; |
| 4483 | |
| 4484 | if (!shell->fade.startup_timer) |
| 4485 | return; |
| 4486 | |
| 4487 | wl_event_source_remove(shell->fade.startup_timer); |
| 4488 | shell->fade.startup_timer = NULL; |
| 4489 | |
| 4490 | loop = wl_display_get_event_loop(shell->compositor->wl_display); |
| 4491 | wl_event_loop_add_idle(loop, do_shell_fade_startup, shell); |
| 4492 | } |
| 4493 | |
| 4494 | static int |
| 4495 | fade_startup_timeout(void *data) |
| 4496 | { |
| 4497 | struct desktop_shell *shell = data; |
| 4498 | |
| 4499 | shell_fade_startup(shell); |
| 4500 | return 0; |
| 4501 | } |
| 4502 | |
| 4503 | static void |
| 4504 | shell_fade_init(struct desktop_shell *shell) |
| 4505 | { |
| 4506 | /* Make compositor output all black, and wait for the desktop-shell |
| 4507 | * client to signal it is ready, then fade in. The timer triggers a |
| 4508 | * fade-in, in case the desktop-shell client takes too long. |
| 4509 | */ |
| 4510 | |
| 4511 | struct wl_event_loop *loop; |
| 4512 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 4513 | if (shell->fade.view != NULL) { |
Pekka Paalanen | 79346ab | 2013-05-22 18:03:09 +0300 | [diff] [blame] | 4514 | weston_log("%s: warning: fade surface already exists\n", |
| 4515 | __func__); |
| 4516 | return; |
| 4517 | } |
| 4518 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 4519 | shell->fade.view = shell_fade_create_surface(shell); |
| 4520 | if (!shell->fade.view) |
Pekka Paalanen | 79346ab | 2013-05-22 18:03:09 +0300 | [diff] [blame] | 4521 | return; |
| 4522 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 4523 | weston_view_update_transform(shell->fade.view); |
| 4524 | weston_surface_damage(shell->fade.view->surface); |
Pekka Paalanen | 79346ab | 2013-05-22 18:03:09 +0300 | [diff] [blame] | 4525 | |
| 4526 | loop = wl_display_get_event_loop(shell->compositor->wl_display); |
| 4527 | shell->fade.startup_timer = |
| 4528 | wl_event_loop_add_timer(loop, fade_startup_timeout, shell); |
| 4529 | wl_event_source_timer_update(shell->fade.startup_timer, 15000); |
| 4530 | } |
| 4531 | |
| 4532 | static void |
Ander Conselvan de Oliveira | a457563 | 2013-02-21 18:35:23 +0200 | [diff] [blame] | 4533 | idle_handler(struct wl_listener *listener, void *data) |
Ander Conselvan de Oliveira | 19d10ef | 2013-02-21 18:35:20 +0200 | [diff] [blame] | 4534 | { |
| 4535 | struct desktop_shell *shell = |
Ander Conselvan de Oliveira | a457563 | 2013-02-21 18:35:23 +0200 | [diff] [blame] | 4536 | container_of(listener, struct desktop_shell, idle_listener); |
Kristian Høgsberg | 27d5fa8 | 2014-01-17 16:22:50 -0800 | [diff] [blame] | 4537 | struct weston_seat *seat; |
| 4538 | |
| 4539 | wl_list_for_each(seat, &shell->compositor->seat_list, link) |
| 4540 | if (seat->pointer) |
| 4541 | popup_grab_end(seat->pointer); |
Ander Conselvan de Oliveira | 19d10ef | 2013-02-21 18:35:20 +0200 | [diff] [blame] | 4542 | |
| 4543 | shell_fade(shell, FADE_OUT); |
| 4544 | /* lock() is called from shell_fade_done() */ |
| 4545 | } |
| 4546 | |
| 4547 | static void |
Ander Conselvan de Oliveira | a457563 | 2013-02-21 18:35:23 +0200 | [diff] [blame] | 4548 | wake_handler(struct wl_listener *listener, void *data) |
Ander Conselvan de Oliveira | 19d10ef | 2013-02-21 18:35:20 +0200 | [diff] [blame] | 4549 | { |
| 4550 | struct desktop_shell *shell = |
Ander Conselvan de Oliveira | a457563 | 2013-02-21 18:35:23 +0200 | [diff] [blame] | 4551 | container_of(listener, struct desktop_shell, wake_listener); |
Ander Conselvan de Oliveira | 19d10ef | 2013-02-21 18:35:20 +0200 | [diff] [blame] | 4552 | |
Ander Conselvan de Oliveira | 19d10ef | 2013-02-21 18:35:20 +0200 | [diff] [blame] | 4553 | unlock(shell); |
| 4554 | } |
| 4555 | |
| 4556 | static void |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 4557 | center_on_output(struct weston_view *view, struct weston_output *output) |
Pekka Paalanen | 77346a6 | 2011-11-30 16:26:35 +0200 | [diff] [blame] | 4558 | { |
Giulio Camuffo | b836664 | 2013-04-25 13:57:46 +0300 | [diff] [blame] | 4559 | int32_t surf_x, surf_y, width, height; |
Ander Conselvan de Oliveira | 012b4c7 | 2012-11-27 17:03:42 +0200 | [diff] [blame] | 4560 | float x, y; |
Pekka Paalanen | 77346a6 | 2011-11-30 16:26:35 +0200 | [diff] [blame] | 4561 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 4562 | surface_subsurfaces_boundingbox(view->surface, &surf_x, &surf_y, &width, &height); |
Giulio Camuffo | b836664 | 2013-04-25 13:57:46 +0300 | [diff] [blame] | 4563 | |
| 4564 | x = output->x + (output->width - width) / 2 - surf_x / 2; |
| 4565 | y = output->y + (output->height - height) / 2 - surf_y / 2; |
Ander Conselvan de Oliveira | 012b4c7 | 2012-11-27 17:03:42 +0200 | [diff] [blame] | 4566 | |
Jason Ekstrand | 918f2dd | 2013-12-02 21:01:53 -0600 | [diff] [blame] | 4567 | weston_view_set_position(view, x, y); |
Pekka Paalanen | 77346a6 | 2011-11-30 16:26:35 +0200 | [diff] [blame] | 4568 | } |
| 4569 | |
| 4570 | static void |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 4571 | weston_view_set_initial_position(struct weston_view *view, |
| 4572 | struct desktop_shell *shell) |
Rob Bradford | ac63e5b | 2012-08-13 14:07:52 +0100 | [diff] [blame] | 4573 | { |
| 4574 | struct weston_compositor *compositor = shell->compositor; |
| 4575 | int ix = 0, iy = 0; |
| 4576 | int range_x, range_y; |
| 4577 | int dx, dy, x, y, panel_height; |
| 4578 | struct weston_output *output, *target_output = NULL; |
| 4579 | struct weston_seat *seat; |
| 4580 | |
| 4581 | /* As a heuristic place the new window on the same output as the |
| 4582 | * pointer. Falling back to the output containing 0, 0. |
| 4583 | * |
| 4584 | * TODO: Do something clever for touch too? |
| 4585 | */ |
| 4586 | wl_list_for_each(seat, &compositor->seat_list, link) { |
Kristian Høgsberg | 2bf8762 | 2013-05-07 23:17:41 -0400 | [diff] [blame] | 4587 | if (seat->pointer) { |
Kristian Høgsberg | e314875 | 2013-05-06 23:19:49 -0400 | [diff] [blame] | 4588 | ix = wl_fixed_to_int(seat->pointer->x); |
| 4589 | iy = wl_fixed_to_int(seat->pointer->y); |
Rob Bradford | ac63e5b | 2012-08-13 14:07:52 +0100 | [diff] [blame] | 4590 | break; |
| 4591 | } |
| 4592 | } |
| 4593 | |
| 4594 | wl_list_for_each(output, &compositor->output_list, link) { |
| 4595 | if (pixman_region32_contains_point(&output->region, ix, iy, NULL)) { |
| 4596 | target_output = output; |
| 4597 | break; |
| 4598 | } |
| 4599 | } |
| 4600 | |
| 4601 | if (!target_output) { |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 4602 | weston_view_set_position(view, 10 + random() % 400, |
| 4603 | 10 + random() % 400); |
Rob Bradford | ac63e5b | 2012-08-13 14:07:52 +0100 | [diff] [blame] | 4604 | return; |
| 4605 | } |
| 4606 | |
| 4607 | /* Valid range within output where the surface will still be onscreen. |
| 4608 | * If this is negative it means that the surface is bigger than |
| 4609 | * output. |
| 4610 | */ |
| 4611 | panel_height = get_output_panel_height(shell, target_output); |
Jason Ekstrand | 918f2dd | 2013-12-02 21:01:53 -0600 | [diff] [blame] | 4612 | range_x = target_output->width - view->surface->width; |
Scott Moreau | 1bad5db | 2012-08-18 01:04:05 -0600 | [diff] [blame] | 4613 | range_y = (target_output->height - panel_height) - |
Jason Ekstrand | 918f2dd | 2013-12-02 21:01:53 -0600 | [diff] [blame] | 4614 | view->surface->height; |
Rob Bradford | ac63e5b | 2012-08-13 14:07:52 +0100 | [diff] [blame] | 4615 | |
Rob Bradford | 4cb88c7 | 2012-08-13 15:18:44 +0100 | [diff] [blame] | 4616 | if (range_x > 0) |
Rob Bradford | ac63e5b | 2012-08-13 14:07:52 +0100 | [diff] [blame] | 4617 | dx = random() % range_x; |
Rob Bradford | ac63e5b | 2012-08-13 14:07:52 +0100 | [diff] [blame] | 4618 | else |
Rob Bradford | 4cb88c7 | 2012-08-13 15:18:44 +0100 | [diff] [blame] | 4619 | dx = 0; |
| 4620 | |
| 4621 | if (range_y > 0) |
Rob Bradford | ac63e5b | 2012-08-13 14:07:52 +0100 | [diff] [blame] | 4622 | dy = panel_height + random() % range_y; |
Rob Bradford | 4cb88c7 | 2012-08-13 15:18:44 +0100 | [diff] [blame] | 4623 | else |
| 4624 | dy = panel_height; |
Rob Bradford | ac63e5b | 2012-08-13 14:07:52 +0100 | [diff] [blame] | 4625 | |
| 4626 | x = target_output->x + dx; |
| 4627 | y = target_output->y + dy; |
| 4628 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 4629 | weston_view_set_position(view, x, y); |
Rob Bradford | ac63e5b | 2012-08-13 14:07:52 +0100 | [diff] [blame] | 4630 | } |
| 4631 | |
| 4632 | static void |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 4633 | map(struct desktop_shell *shell, struct shell_surface *shsurf, |
Jason Ekstrand | 918f2dd | 2013-12-02 21:01:53 -0600 | [diff] [blame] | 4634 | int32_t sx, int32_t sy) |
Kristian Høgsberg | 02ec0a5 | 2011-04-23 13:04:11 -0400 | [diff] [blame] | 4635 | { |
Kristian Høgsberg | 8334bc1 | 2012-01-03 10:29:47 -0500 | [diff] [blame] | 4636 | struct weston_compositor *compositor = shell->compositor; |
Daniel Stone | b210468 | 2012-05-30 16:31:56 +0100 | [diff] [blame] | 4637 | struct weston_seat *seat; |
Juan Zhao | 96879df | 2012-02-07 08:45:41 +0800 | [diff] [blame] | 4638 | int panel_height = 0; |
Giulio Camuffo | b836664 | 2013-04-25 13:57:46 +0300 | [diff] [blame] | 4639 | int32_t surf_x, surf_y; |
Pekka Paalanen | 57da4a8 | 2011-11-23 16:42:16 +0200 | [diff] [blame] | 4640 | |
Pekka Paalanen | 77346a6 | 2011-11-30 16:26:35 +0200 | [diff] [blame] | 4641 | /* initial positioning, see also configure() */ |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 4642 | switch (shsurf->type) { |
Rafael Antognolli | ed207b4 | 2013-12-03 15:35:43 -0200 | [diff] [blame] | 4643 | case SHELL_SURFACE_TOPLEVEL: |
Rafael Antognolli | 03b1659 | 2013-12-03 15:35:42 -0200 | [diff] [blame] | 4644 | if (shsurf->state.fullscreen) { |
| 4645 | center_on_output(shsurf->view, shsurf->fullscreen_output); |
| 4646 | shell_map_fullscreen(shsurf); |
| 4647 | } else if (shsurf->state.maximized) { |
| 4648 | /* use surface configure to set the geometry */ |
| 4649 | panel_height = get_output_panel_height(shell, shsurf->output); |
| 4650 | surface_subsurfaces_boundingbox(shsurf->surface, |
| 4651 | &surf_x, &surf_y, NULL, NULL); |
| 4652 | weston_view_set_position(shsurf->view, |
| 4653 | shsurf->output->x - surf_x, |
| 4654 | shsurf->output->y + |
| 4655 | panel_height - surf_y); |
Rafael Antognolli | ed207b4 | 2013-12-03 15:35:43 -0200 | [diff] [blame] | 4656 | } else if (!shsurf->state.relative) { |
Rafael Antognolli | 03b1659 | 2013-12-03 15:35:42 -0200 | [diff] [blame] | 4657 | weston_view_set_initial_position(shsurf->view, shell); |
| 4658 | } |
Juan Zhao | 96879df | 2012-02-07 08:45:41 +0800 | [diff] [blame] | 4659 | break; |
Tiago Vignatti | 0f99701 | 2012-02-10 16:17:23 +0200 | [diff] [blame] | 4660 | case SHELL_SURFACE_POPUP: |
Kristian Høgsberg | 3730f36 | 2012-04-13 12:40:07 -0400 | [diff] [blame] | 4661 | shell_map_popup(shsurf); |
Rob Bradford | db99938 | 2012-12-06 12:07:48 +0000 | [diff] [blame] | 4662 | break; |
Ander Conselvan de Oliveira | e9e0515 | 2012-02-15 17:02:56 +0200 | [diff] [blame] | 4663 | case SHELL_SURFACE_NONE: |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 4664 | weston_view_set_position(shsurf->view, |
| 4665 | shsurf->view->geometry.x + sx, |
| 4666 | shsurf->view->geometry.y + sy); |
Tiago Vignatti | 0f99701 | 2012-02-10 16:17:23 +0200 | [diff] [blame] | 4667 | break; |
Philip Withnall | 0f640e2 | 2013-11-25 18:01:31 +0000 | [diff] [blame] | 4668 | case SHELL_SURFACE_XWAYLAND: |
Pekka Paalanen | 77346a6 | 2011-11-30 16:26:35 +0200 | [diff] [blame] | 4669 | default: |
| 4670 | ; |
| 4671 | } |
Kristian Høgsberg | 7584062 | 2011-09-06 13:48:16 -0400 | [diff] [blame] | 4672 | |
Philip Withnall | e1d75ae | 2013-11-25 18:01:41 +0000 | [diff] [blame] | 4673 | /* Surface stacking order, see also activate(). */ |
| 4674 | shell_surface_update_layer(shsurf); |
Pekka Paalanen | f0fc70d | 2011-11-15 13:34:54 +0200 | [diff] [blame] | 4675 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 4676 | if (shsurf->type != SHELL_SURFACE_NONE) { |
| 4677 | weston_view_update_transform(shsurf->view); |
Rafael Antognolli | 03b1659 | 2013-12-03 15:35:42 -0200 | [diff] [blame] | 4678 | if (shsurf->state.maximized) { |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 4679 | shsurf->surface->output = shsurf->output; |
| 4680 | shsurf->view->output = shsurf->output; |
| 4681 | } |
Ander Conselvan de Oliveira | de56c31 | 2012-03-05 15:39:23 +0200 | [diff] [blame] | 4682 | } |
Kristian Høgsberg | 2f88a40 | 2011-12-04 15:32:59 -0500 | [diff] [blame] | 4683 | |
Rafael Antognolli | ed207b4 | 2013-12-03 15:35:43 -0200 | [diff] [blame] | 4684 | if ((shsurf->type == SHELL_SURFACE_XWAYLAND || shsurf->state.relative) && |
| 4685 | shsurf->transient.flags == WL_SHELL_SURFACE_TRANSIENT_INACTIVE) { |
| 4686 | } |
| 4687 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 4688 | switch (shsurf->type) { |
Tiago Vignatti | fb2adba | 2013-06-12 15:43:21 -0300 | [diff] [blame] | 4689 | /* XXX: xwayland's using the same fields for transient type */ |
| 4690 | case SHELL_SURFACE_XWAYLAND: |
Tiago Vignatti | 99aeb1e | 2012-05-23 22:06:26 +0300 | [diff] [blame] | 4691 | if (shsurf->transient.flags == |
| 4692 | WL_SHELL_SURFACE_TRANSIENT_INACTIVE) |
| 4693 | break; |
| 4694 | case SHELL_SURFACE_TOPLEVEL: |
Rafael Antognolli | ed207b4 | 2013-12-03 15:35:43 -0200 | [diff] [blame] | 4695 | if (shsurf->state.relative && |
| 4696 | shsurf->transient.flags == WL_SHELL_SURFACE_TRANSIENT_INACTIVE) |
| 4697 | break; |
Rafael Antognolli | ba5d2d7 | 2013-12-04 17:49:55 -0200 | [diff] [blame] | 4698 | if (shell->locked) |
Rafael Antognolli | ed207b4 | 2013-12-03 15:35:43 -0200 | [diff] [blame] | 4699 | break; |
| 4700 | wl_list_for_each(seat, &compositor->seat_list, link) |
| 4701 | activate(shell, shsurf->surface, seat); |
Juan Zhao | 7bb92f0 | 2011-12-15 11:31:51 -0500 | [diff] [blame] | 4702 | break; |
Philip Withnall | 0f640e2 | 2013-11-25 18:01:31 +0000 | [diff] [blame] | 4703 | case SHELL_SURFACE_POPUP: |
| 4704 | case SHELL_SURFACE_NONE: |
Juan Zhao | 7bb92f0 | 2011-12-15 11:31:51 -0500 | [diff] [blame] | 4705 | default: |
| 4706 | break; |
| 4707 | } |
| 4708 | |
Rafael Antognolli | 03b1659 | 2013-12-03 15:35:42 -0200 | [diff] [blame] | 4709 | if (shsurf->type == SHELL_SURFACE_TOPLEVEL && |
| 4710 | !shsurf->state.maximized && !shsurf->state.fullscreen) |
Juan Zhao | e10d279 | 2012-04-25 19:09:52 +0800 | [diff] [blame] | 4711 | { |
| 4712 | switch (shell->win_animation_type) { |
| 4713 | case ANIMATION_FADE: |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 4714 | 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] | 4715 | break; |
| 4716 | case ANIMATION_ZOOM: |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 4717 | weston_zoom_run(shsurf->view, 0.5, 1.0, NULL, NULL); |
Juan Zhao | e10d279 | 2012-04-25 19:09:52 +0800 | [diff] [blame] | 4718 | break; |
Philip Withnall | 4a86a0a | 2013-11-25 18:01:32 +0000 | [diff] [blame] | 4719 | case ANIMATION_NONE: |
Juan Zhao | e10d279 | 2012-04-25 19:09:52 +0800 | [diff] [blame] | 4720 | default: |
| 4721 | break; |
| 4722 | } |
| 4723 | } |
Kristian Høgsberg | 32e24cc | 2011-11-09 12:07:35 -0500 | [diff] [blame] | 4724 | } |
| 4725 | |
| 4726 | static void |
Tiago Vignatti | be14326 | 2012-04-16 17:31:41 +0300 | [diff] [blame] | 4727 | configure(struct desktop_shell *shell, struct weston_surface *surface, |
Jason Ekstrand | 918f2dd | 2013-12-02 21:01:53 -0600 | [diff] [blame] | 4728 | float x, float y) |
Kristian Høgsberg | 32e24cc | 2011-11-09 12:07:35 -0500 | [diff] [blame] | 4729 | { |
Pekka Paalanen | 77346a6 | 2011-11-30 16:26:35 +0200 | [diff] [blame] | 4730 | struct shell_surface *shsurf; |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 4731 | struct weston_view *view; |
Jason Ekstrand | 918f2dd | 2013-12-02 21:01:53 -0600 | [diff] [blame] | 4732 | int32_t mx, my, surf_x, surf_y; |
Kristian Høgsberg | 32e24cc | 2011-11-09 12:07:35 -0500 | [diff] [blame] | 4733 | |
Pekka Paalanen | 77346a6 | 2011-11-30 16:26:35 +0200 | [diff] [blame] | 4734 | shsurf = get_shell_surface(surface); |
Pekka Paalanen | 77346a6 | 2011-11-30 16:26:35 +0200 | [diff] [blame] | 4735 | |
U. Artie Eoff | cf5737a | 2014-01-17 10:08:25 -0800 | [diff] [blame] | 4736 | assert(shsurf); |
| 4737 | |
Rafael Antognolli | 03b1659 | 2013-12-03 15:35:42 -0200 | [diff] [blame] | 4738 | if (shsurf->state.fullscreen) |
Alex Wu | 4539b08 | 2012-03-01 12:57:46 +0800 | [diff] [blame] | 4739 | shell_configure_fullscreen(shsurf); |
Rafael Antognolli | 03b1659 | 2013-12-03 15:35:42 -0200 | [diff] [blame] | 4740 | else if (shsurf->state.maximized) { |
Alex Wu | 4539b08 | 2012-03-01 12:57:46 +0800 | [diff] [blame] | 4741 | /* setting x, y and using configure to change that geometry */ |
Giulio Camuffo | b836664 | 2013-04-25 13:57:46 +0300 | [diff] [blame] | 4742 | surface_subsurfaces_boundingbox(shsurf->surface, &surf_x, &surf_y, |
| 4743 | NULL, NULL); |
Jason Ekstrand | 918f2dd | 2013-12-02 21:01:53 -0600 | [diff] [blame] | 4744 | mx = shsurf->output->x - surf_x; |
| 4745 | my = shsurf->output->y + |
| 4746 | get_output_panel_height(shell,shsurf->output) - surf_y; |
| 4747 | weston_view_set_position(shsurf->view, mx, my); |
Rafael Antognolli | 03b1659 | 2013-12-03 15:35:42 -0200 | [diff] [blame] | 4748 | } else { |
Jason Ekstrand | 918f2dd | 2013-12-02 21:01:53 -0600 | [diff] [blame] | 4749 | weston_view_set_position(shsurf->view, x, y); |
Kristian Høgsberg | 7a5c979 | 2011-06-18 06:12:54 -0400 | [diff] [blame] | 4750 | } |
Kristian Høgsberg | 32e24cc | 2011-11-09 12:07:35 -0500 | [diff] [blame] | 4751 | |
Alex Wu | 4539b08 | 2012-03-01 12:57:46 +0800 | [diff] [blame] | 4752 | /* XXX: would a fullscreen surface need the same handling? */ |
Kristian Høgsberg | 6a8b553 | 2012-02-16 23:43:59 -0500 | [diff] [blame] | 4753 | if (surface->output) { |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 4754 | wl_list_for_each(view, &surface->views, surface_link) |
| 4755 | weston_view_update_transform(view); |
Pekka Paalanen | 77346a6 | 2011-11-30 16:26:35 +0200 | [diff] [blame] | 4756 | |
Rafael Antognolli | 03b1659 | 2013-12-03 15:35:42 -0200 | [diff] [blame] | 4757 | if (shsurf->state.maximized) |
Juan Zhao | 96879df | 2012-02-07 08:45:41 +0800 | [diff] [blame] | 4758 | surface->output = shsurf->output; |
Pekka Paalanen | 77346a6 | 2011-11-30 16:26:35 +0200 | [diff] [blame] | 4759 | } |
Kristian Høgsberg | 0793756 | 2011-04-12 17:25:42 -0400 | [diff] [blame] | 4760 | } |
| 4761 | |
Ander Conselvan de Oliveira | 093bfa3 | 2012-03-27 17:36:41 +0300 | [diff] [blame] | 4762 | static void |
Jason Ekstrand | 918f2dd | 2013-12-02 21:01:53 -0600 | [diff] [blame] | 4763 | 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] | 4764 | { |
Ander Conselvan de Oliveira | 7fb9f95 | 2012-03-27 17:36:42 +0300 | [diff] [blame] | 4765 | struct shell_surface *shsurf = get_shell_surface(es); |
U. Artie Eoff | cf5737a | 2014-01-17 10:08:25 -0800 | [diff] [blame] | 4766 | struct desktop_shell *shell; |
Tiago Vignatti | 70e5c9c | 2012-05-07 15:23:07 +0300 | [diff] [blame] | 4767 | int type_changed = 0; |
Ander Conselvan de Oliveira | 093bfa3 | 2012-03-27 17:36:41 +0300 | [diff] [blame] | 4768 | |
U. Artie Eoff | cf5737a | 2014-01-17 10:08:25 -0800 | [diff] [blame] | 4769 | assert(shsurf); |
| 4770 | |
| 4771 | shell = shsurf->shell; |
| 4772 | |
Kristian Høgsberg | 8eb0f4f | 2013-06-17 10:33:14 -0400 | [diff] [blame] | 4773 | if (!weston_surface_is_mapped(es) && |
| 4774 | !wl_list_empty(&shsurf->popup.grab_link)) { |
Giulio Camuffo | 5085a75 | 2013-03-25 21:42:45 +0100 | [diff] [blame] | 4775 | remove_popup_grab(shsurf); |
| 4776 | } |
| 4777 | |
Jason Ekstrand | 918f2dd | 2013-12-02 21:01:53 -0600 | [diff] [blame] | 4778 | if (es->width == 0) |
Giulio Camuffo | 184df50 | 2013-02-21 11:29:21 +0100 | [diff] [blame] | 4779 | return; |
| 4780 | |
Kristian Høgsberg | c8f8dd8 | 2013-12-05 23:20:33 -0800 | [diff] [blame] | 4781 | if (shsurf->state_changed) { |
Kristian Høgsberg | 7f366e7 | 2012-04-27 17:20:01 -0400 | [diff] [blame] | 4782 | set_surface_type(shsurf); |
Kristian Høgsberg | f7e23d5 | 2012-04-27 17:51:59 -0400 | [diff] [blame] | 4783 | type_changed = 1; |
| 4784 | } |
Kristian Høgsberg | 7f366e7 | 2012-04-27 17:20:01 -0400 | [diff] [blame] | 4785 | |
Ander Conselvan de Oliveira | 093bfa3 | 2012-03-27 17:36:41 +0300 | [diff] [blame] | 4786 | if (!weston_surface_is_mapped(es)) { |
Jason Ekstrand | 918f2dd | 2013-12-02 21:01:53 -0600 | [diff] [blame] | 4787 | map(shell, shsurf, sx, sy); |
Kristian Høgsberg | f7e23d5 | 2012-04-27 17:51:59 -0400 | [diff] [blame] | 4788 | } else if (type_changed || sx != 0 || sy != 0 || |
Jason Ekstrand | 918f2dd | 2013-12-02 21:01:53 -0600 | [diff] [blame] | 4789 | shsurf->last_width != es->width || |
| 4790 | shsurf->last_height != es->height) { |
| 4791 | shsurf->last_width = es->width; |
| 4792 | shsurf->last_height = es->height; |
John Kåre Alsaker | 490d02a | 2012-09-30 02:57:21 +0200 | [diff] [blame] | 4793 | float from_x, from_y; |
| 4794 | float to_x, to_y; |
Ander Conselvan de Oliveira | 093bfa3 | 2012-03-27 17:36:41 +0300 | [diff] [blame] | 4795 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 4796 | weston_view_to_global_float(shsurf->view, 0, 0, &from_x, &from_y); |
| 4797 | 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] | 4798 | configure(shell, es, |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 4799 | shsurf->view->geometry.x + to_x - from_x, |
Jason Ekstrand | 918f2dd | 2013-12-02 21:01:53 -0600 | [diff] [blame] | 4800 | shsurf->view->geometry.y + to_y - from_y); |
Ander Conselvan de Oliveira | 093bfa3 | 2012-03-27 17:36:41 +0300 | [diff] [blame] | 4801 | } |
| 4802 | } |
| 4803 | |
Zhang, Xiong Y | 3123693 | 2013-12-13 22:10:57 +0200 | [diff] [blame] | 4804 | static void |
| 4805 | shell_surface_output_destroyed(struct weston_surface *es) |
| 4806 | { |
| 4807 | struct shell_surface *shsurf = get_shell_surface(es); |
| 4808 | |
U. Artie Eoff | cf5737a | 2014-01-17 10:08:25 -0800 | [diff] [blame] | 4809 | assert(shsurf); |
| 4810 | |
Zhang, Xiong Y | 3123693 | 2013-12-13 22:10:57 +0200 | [diff] [blame] | 4811 | shsurf->saved_position_valid = false; |
Ander Conselvan de Oliveira | fc63fdd | 2013-12-13 22:10:58 +0200 | [diff] [blame] | 4812 | shsurf->next_state.maximized = false; |
| 4813 | shsurf->next_state.fullscreen = false; |
| 4814 | shsurf->state_changed = true; |
Zhang, Xiong Y | 3123693 | 2013-12-13 22:10:57 +0200 | [diff] [blame] | 4815 | } |
| 4816 | |
Tiago Vignatti | b7dbbd6 | 2012-09-25 17:57:01 +0300 | [diff] [blame] | 4817 | static void launch_desktop_shell_process(void *data); |
Pekka Paalanen | 4d733ee | 2012-01-17 14:36:27 +0200 | [diff] [blame] | 4818 | |
Kristian Høgsberg | 97d44aa | 2011-08-26 17:21:20 -0400 | [diff] [blame] | 4819 | static void |
Kristian Høgsberg | 8334bc1 | 2012-01-03 10:29:47 -0500 | [diff] [blame] | 4820 | desktop_shell_sigchld(struct weston_process *process, int status) |
Pekka Paalanen | 6cd281a | 2011-11-03 14:11:32 +0200 | [diff] [blame] | 4821 | { |
Pekka Paalanen | 4d733ee | 2012-01-17 14:36:27 +0200 | [diff] [blame] | 4822 | uint32_t time; |
Tiago Vignatti | be14326 | 2012-04-16 17:31:41 +0300 | [diff] [blame] | 4823 | struct desktop_shell *shell = |
| 4824 | container_of(process, struct desktop_shell, child.process); |
Pekka Paalanen | 6cd281a | 2011-11-03 14:11:32 +0200 | [diff] [blame] | 4825 | |
| 4826 | shell->child.process.pid = 0; |
| 4827 | shell->child.client = NULL; /* already destroyed by wayland */ |
Pekka Paalanen | 4d733ee | 2012-01-17 14:36:27 +0200 | [diff] [blame] | 4828 | |
| 4829 | /* if desktop-shell dies more than 5 times in 30 seconds, give up */ |
| 4830 | time = weston_compositor_get_time(); |
Kristian Høgsberg | f03a616 | 2012-01-17 11:07:42 -0500 | [diff] [blame] | 4831 | if (time - shell->child.deathstamp > 30000) { |
Pekka Paalanen | 4d733ee | 2012-01-17 14:36:27 +0200 | [diff] [blame] | 4832 | shell->child.deathstamp = time; |
| 4833 | shell->child.deathcount = 0; |
| 4834 | } |
| 4835 | |
| 4836 | shell->child.deathcount++; |
| 4837 | if (shell->child.deathcount > 5) { |
Emilio Pozuelo Monfort | 46ce798 | 2013-11-20 13:22:29 +0100 | [diff] [blame] | 4838 | weston_log("%s died, giving up.\n", shell->client); |
Pekka Paalanen | 4d733ee | 2012-01-17 14:36:27 +0200 | [diff] [blame] | 4839 | return; |
| 4840 | } |
| 4841 | |
Emilio Pozuelo Monfort | 46ce798 | 2013-11-20 13:22:29 +0100 | [diff] [blame] | 4842 | weston_log("%s died, respawning...\n", shell->client); |
Pekka Paalanen | 4d733ee | 2012-01-17 14:36:27 +0200 | [diff] [blame] | 4843 | launch_desktop_shell_process(shell); |
Pekka Paalanen | 79346ab | 2013-05-22 18:03:09 +0300 | [diff] [blame] | 4844 | shell_fade_startup(shell); |
Pekka Paalanen | 6cd281a | 2011-11-03 14:11:32 +0200 | [diff] [blame] | 4845 | } |
| 4846 | |
Tiago Vignatti | b7dbbd6 | 2012-09-25 17:57:01 +0300 | [diff] [blame] | 4847 | static void |
Ander Conselvan de Oliveira | 312ea4c | 2013-12-20 21:07:01 +0200 | [diff] [blame] | 4848 | desktop_shell_client_destroy(struct wl_listener *listener, void *data) |
| 4849 | { |
| 4850 | struct desktop_shell *shell; |
| 4851 | |
| 4852 | shell = container_of(listener, struct desktop_shell, |
| 4853 | child.client_destroy_listener); |
| 4854 | |
| 4855 | shell->child.client = NULL; |
| 4856 | } |
| 4857 | |
| 4858 | static void |
Tiago Vignatti | b7dbbd6 | 2012-09-25 17:57:01 +0300 | [diff] [blame] | 4859 | launch_desktop_shell_process(void *data) |
Pekka Paalanen | 6cd281a | 2011-11-03 14:11:32 +0200 | [diff] [blame] | 4860 | { |
Tiago Vignatti | b7dbbd6 | 2012-09-25 17:57:01 +0300 | [diff] [blame] | 4861 | struct desktop_shell *shell = data; |
Pekka Paalanen | 6cd281a | 2011-11-03 14:11:32 +0200 | [diff] [blame] | 4862 | |
Kristian Høgsberg | 8334bc1 | 2012-01-03 10:29:47 -0500 | [diff] [blame] | 4863 | shell->child.client = weston_client_launch(shell->compositor, |
Pekka Paalanen | 409ef0a | 2011-12-02 15:30:21 +0200 | [diff] [blame] | 4864 | &shell->child.process, |
Emilio Pozuelo Monfort | 46ce798 | 2013-11-20 13:22:29 +0100 | [diff] [blame] | 4865 | shell->client, |
Pekka Paalanen | 409ef0a | 2011-12-02 15:30:21 +0200 | [diff] [blame] | 4866 | desktop_shell_sigchld); |
| 4867 | |
| 4868 | if (!shell->child.client) |
Emilio Pozuelo Monfort | 46ce798 | 2013-11-20 13:22:29 +0100 | [diff] [blame] | 4869 | weston_log("not able to start %s\n", shell->client); |
Ander Conselvan de Oliveira | 312ea4c | 2013-12-20 21:07:01 +0200 | [diff] [blame] | 4870 | |
| 4871 | shell->child.client_destroy_listener.notify = |
| 4872 | desktop_shell_client_destroy; |
| 4873 | wl_client_add_destroy_listener(shell->child.client, |
| 4874 | &shell->child.client_destroy_listener); |
Pekka Paalanen | 6cd281a | 2011-11-03 14:11:32 +0200 | [diff] [blame] | 4875 | } |
| 4876 | |
| 4877 | static void |
Kristian Høgsberg | 97d44aa | 2011-08-26 17:21:20 -0400 | [diff] [blame] | 4878 | bind_shell(struct wl_client *client, void *data, uint32_t version, uint32_t id) |
| 4879 | { |
Tiago Vignatti | be14326 | 2012-04-16 17:31:41 +0300 | [diff] [blame] | 4880 | struct desktop_shell *shell = data; |
Jason Ekstrand | a85118c | 2013-06-27 20:17:02 -0500 | [diff] [blame] | 4881 | struct wl_resource *resource; |
Kristian Høgsberg | 97d44aa | 2011-08-26 17:21:20 -0400 | [diff] [blame] | 4882 | |
Jason Ekstrand | a85118c | 2013-06-27 20:17:02 -0500 | [diff] [blame] | 4883 | resource = wl_resource_create(client, &wl_shell_interface, 1, id); |
| 4884 | if (resource) |
| 4885 | wl_resource_set_implementation(resource, &shell_implementation, |
| 4886 | shell, NULL); |
Kristian Høgsberg | 97d44aa | 2011-08-26 17:21:20 -0400 | [diff] [blame] | 4887 | } |
| 4888 | |
Kristian Høgsberg | 7584062 | 2011-09-06 13:48:16 -0400 | [diff] [blame] | 4889 | static void |
Rafael Antognolli | e2a3455 | 2013-12-03 15:35:45 -0200 | [diff] [blame] | 4890 | bind_xdg_shell(struct wl_client *client, void *data, uint32_t version, uint32_t id) |
| 4891 | { |
| 4892 | struct desktop_shell *shell = data; |
| 4893 | struct wl_resource *resource; |
| 4894 | |
| 4895 | resource = wl_resource_create(client, &xdg_shell_interface, 1, id); |
| 4896 | if (resource) |
| 4897 | wl_resource_set_dispatcher(resource, |
| 4898 | xdg_shell_unversioned_dispatch, |
| 4899 | NULL, shell, NULL); |
| 4900 | } |
| 4901 | |
| 4902 | static void |
Pekka Paalanen | 9ef3e01 | 2011-11-15 13:34:48 +0200 | [diff] [blame] | 4903 | unbind_desktop_shell(struct wl_resource *resource) |
| 4904 | { |
Jason Ekstrand | 651f00e | 2013-06-14 10:07:54 -0500 | [diff] [blame] | 4905 | struct desktop_shell *shell = wl_resource_get_user_data(resource); |
Kristian Høgsberg | 1ec0c31 | 2011-11-15 16:39:55 -0500 | [diff] [blame] | 4906 | |
| 4907 | if (shell->locked) |
| 4908 | resume_desktop(shell); |
| 4909 | |
Pekka Paalanen | 9ef3e01 | 2011-11-15 13:34:48 +0200 | [diff] [blame] | 4910 | shell->child.desktop_shell = NULL; |
| 4911 | shell->prepare_event_sent = false; |
Pekka Paalanen | 9ef3e01 | 2011-11-15 13:34:48 +0200 | [diff] [blame] | 4912 | } |
| 4913 | |
| 4914 | static void |
Kristian Høgsberg | 7584062 | 2011-09-06 13:48:16 -0400 | [diff] [blame] | 4915 | bind_desktop_shell(struct wl_client *client, |
| 4916 | void *data, uint32_t version, uint32_t id) |
| 4917 | { |
Tiago Vignatti | be14326 | 2012-04-16 17:31:41 +0300 | [diff] [blame] | 4918 | struct desktop_shell *shell = data; |
Pekka Paalanen | bbe6052 | 2011-11-03 14:11:33 +0200 | [diff] [blame] | 4919 | struct wl_resource *resource; |
Kristian Høgsberg | 7584062 | 2011-09-06 13:48:16 -0400 | [diff] [blame] | 4920 | |
Jason Ekstrand | a85118c | 2013-06-27 20:17:02 -0500 | [diff] [blame] | 4921 | resource = wl_resource_create(client, &desktop_shell_interface, |
| 4922 | MIN(version, 2), id); |
Pekka Paalanen | bbe6052 | 2011-11-03 14:11:33 +0200 | [diff] [blame] | 4923 | |
Pekka Paalanen | 9ef3e01 | 2011-11-15 13:34:48 +0200 | [diff] [blame] | 4924 | if (client == shell->child.client) { |
Jason Ekstrand | a85118c | 2013-06-27 20:17:02 -0500 | [diff] [blame] | 4925 | wl_resource_set_implementation(resource, |
| 4926 | &desktop_shell_implementation, |
| 4927 | shell, unbind_desktop_shell); |
Pekka Paalanen | 9ef3e01 | 2011-11-15 13:34:48 +0200 | [diff] [blame] | 4928 | shell->child.desktop_shell = resource; |
Pekka Paalanen | 79346ab | 2013-05-22 18:03:09 +0300 | [diff] [blame] | 4929 | |
| 4930 | if (version < 2) |
| 4931 | shell_fade_startup(shell); |
| 4932 | |
Pekka Paalanen | bbe6052 | 2011-11-03 14:11:33 +0200 | [diff] [blame] | 4933 | return; |
Pekka Paalanen | 9ef3e01 | 2011-11-15 13:34:48 +0200 | [diff] [blame] | 4934 | } |
Pekka Paalanen | bbe6052 | 2011-11-03 14:11:33 +0200 | [diff] [blame] | 4935 | |
| 4936 | wl_resource_post_error(resource, WL_DISPLAY_ERROR_INVALID_OBJECT, |
| 4937 | "permission to bind desktop_shell denied"); |
Kristian Høgsberg | eae5de7 | 2012-04-11 22:42:15 -0400 | [diff] [blame] | 4938 | wl_resource_destroy(resource); |
Kristian Høgsberg | 7584062 | 2011-09-06 13:48:16 -0400 | [diff] [blame] | 4939 | } |
| 4940 | |
Pekka Paalanen | 6e16811 | 2011-11-24 11:34:05 +0200 | [diff] [blame] | 4941 | static void |
Jason Ekstrand | 918f2dd | 2013-12-02 21:01:53 -0600 | [diff] [blame] | 4942 | 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] | 4943 | { |
Giulio Camuffo | 7fe01b1 | 2013-03-28 18:02:42 +0100 | [diff] [blame] | 4944 | struct desktop_shell *shell = surface->configure_private; |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 4945 | struct weston_view *view; |
Kristian Høgsberg | 1a73a63 | 2012-06-26 22:15:53 -0400 | [diff] [blame] | 4946 | |
Jason Ekstrand | 918f2dd | 2013-12-02 21:01:53 -0600 | [diff] [blame] | 4947 | if (surface->width == 0) |
Giulio Camuffo | 184df50 | 2013-02-21 11:29:21 +0100 | [diff] [blame] | 4948 | return; |
| 4949 | |
Pekka Paalanen | 3a1d07d | 2012-12-20 14:02:13 +0200 | [diff] [blame] | 4950 | /* XXX: starting weston-screensaver beforehand does not work */ |
Kristian Høgsberg | 1a73a63 | 2012-06-26 22:15:53 -0400 | [diff] [blame] | 4951 | if (!shell->locked) |
| 4952 | return; |
| 4953 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 4954 | view = container_of(surface->views.next, struct weston_view, surface_link); |
| 4955 | center_on_output(view, surface->output); |
Kristian Høgsberg | 1a73a63 | 2012-06-26 22:15:53 -0400 | [diff] [blame] | 4956 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 4957 | if (wl_list_empty(&view->layer_link)) { |
| 4958 | wl_list_insert(shell->lock_layer.view_list.prev, |
| 4959 | &view->layer_link); |
| 4960 | weston_view_update_transform(view); |
Ander Conselvan de Oliveira | 859e885 | 2013-02-21 18:35:21 +0200 | [diff] [blame] | 4961 | wl_event_source_timer_update(shell->screensaver.timer, |
| 4962 | shell->screensaver.duration); |
Ander Conselvan de Oliveira | 19d10ef | 2013-02-21 18:35:20 +0200 | [diff] [blame] | 4963 | shell_fade(shell, FADE_IN); |
Kristian Høgsberg | 1a73a63 | 2012-06-26 22:15:53 -0400 | [diff] [blame] | 4964 | } |
| 4965 | } |
| 4966 | |
| 4967 | static void |
Pekka Paalanen | 6e16811 | 2011-11-24 11:34:05 +0200 | [diff] [blame] | 4968 | screensaver_set_surface(struct wl_client *client, |
| 4969 | struct wl_resource *resource, |
Kristian Høgsberg | 1a73a63 | 2012-06-26 22:15:53 -0400 | [diff] [blame] | 4970 | struct wl_resource *surface_resource, |
Pekka Paalanen | 6e16811 | 2011-11-24 11:34:05 +0200 | [diff] [blame] | 4971 | struct wl_resource *output_resource) |
| 4972 | { |
Jason Ekstrand | 651f00e | 2013-06-14 10:07:54 -0500 | [diff] [blame] | 4973 | struct desktop_shell *shell = wl_resource_get_user_data(resource); |
Jason Ekstrand | 0f2ef7e | 2013-06-14 10:07:53 -0500 | [diff] [blame] | 4974 | struct weston_surface *surface = |
| 4975 | wl_resource_get_user_data(surface_resource); |
Jason Ekstrand | a0d2dde | 2013-06-14 10:08:01 -0500 | [diff] [blame] | 4976 | struct weston_output *output = wl_resource_get_user_data(output_resource); |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 4977 | struct weston_view *view, *next; |
| 4978 | |
| 4979 | /* Make sure we only have one view */ |
| 4980 | wl_list_for_each_safe(view, next, &surface->views, surface_link) |
| 4981 | weston_view_destroy(view); |
| 4982 | weston_view_create(surface); |
Pekka Paalanen | 6e16811 | 2011-11-24 11:34:05 +0200 | [diff] [blame] | 4983 | |
Kristian Høgsberg | 1a73a63 | 2012-06-26 22:15:53 -0400 | [diff] [blame] | 4984 | surface->configure = screensaver_configure; |
Giulio Camuffo | 7fe01b1 | 2013-03-28 18:02:42 +0100 | [diff] [blame] | 4985 | surface->configure_private = shell; |
Pekka Paalanen | 77346a6 | 2011-11-30 16:26:35 +0200 | [diff] [blame] | 4986 | surface->output = output; |
Pekka Paalanen | 6e16811 | 2011-11-24 11:34:05 +0200 | [diff] [blame] | 4987 | } |
| 4988 | |
| 4989 | static const struct screensaver_interface screensaver_implementation = { |
| 4990 | screensaver_set_surface |
| 4991 | }; |
| 4992 | |
| 4993 | static void |
| 4994 | unbind_screensaver(struct wl_resource *resource) |
| 4995 | { |
Jason Ekstrand | 651f00e | 2013-06-14 10:07:54 -0500 | [diff] [blame] | 4996 | struct desktop_shell *shell = wl_resource_get_user_data(resource); |
Pekka Paalanen | 6e16811 | 2011-11-24 11:34:05 +0200 | [diff] [blame] | 4997 | |
Pekka Paalanen | 77346a6 | 2011-11-30 16:26:35 +0200 | [diff] [blame] | 4998 | shell->screensaver.binding = NULL; |
Pekka Paalanen | 6e16811 | 2011-11-24 11:34:05 +0200 | [diff] [blame] | 4999 | } |
| 5000 | |
| 5001 | static void |
| 5002 | bind_screensaver(struct wl_client *client, |
| 5003 | void *data, uint32_t version, uint32_t id) |
| 5004 | { |
Tiago Vignatti | be14326 | 2012-04-16 17:31:41 +0300 | [diff] [blame] | 5005 | struct desktop_shell *shell = data; |
Pekka Paalanen | 6e16811 | 2011-11-24 11:34:05 +0200 | [diff] [blame] | 5006 | struct wl_resource *resource; |
| 5007 | |
Jason Ekstrand | a85118c | 2013-06-27 20:17:02 -0500 | [diff] [blame] | 5008 | resource = wl_resource_create(client, &screensaver_interface, 1, id); |
Pekka Paalanen | 6e16811 | 2011-11-24 11:34:05 +0200 | [diff] [blame] | 5009 | |
Pekka Paalanen | 77346a6 | 2011-11-30 16:26:35 +0200 | [diff] [blame] | 5010 | if (shell->screensaver.binding == NULL) { |
Jason Ekstrand | a85118c | 2013-06-27 20:17:02 -0500 | [diff] [blame] | 5011 | wl_resource_set_implementation(resource, |
| 5012 | &screensaver_implementation, |
| 5013 | shell, unbind_screensaver); |
Pekka Paalanen | 77346a6 | 2011-11-30 16:26:35 +0200 | [diff] [blame] | 5014 | shell->screensaver.binding = resource; |
Pekka Paalanen | 6e16811 | 2011-11-24 11:34:05 +0200 | [diff] [blame] | 5015 | return; |
| 5016 | } |
| 5017 | |
| 5018 | wl_resource_post_error(resource, WL_DISPLAY_ERROR_INVALID_OBJECT, |
| 5019 | "interface object already bound"); |
Kristian Høgsberg | eae5de7 | 2012-04-11 22:42:15 -0400 | [diff] [blame] | 5020 | wl_resource_destroy(resource); |
Pekka Paalanen | 6e16811 | 2011-11-24 11:34:05 +0200 | [diff] [blame] | 5021 | } |
| 5022 | |
Kristian Høgsberg | 0704539 | 2012-02-19 18:52:44 -0500 | [diff] [blame] | 5023 | struct switcher { |
Tiago Vignatti | be14326 | 2012-04-16 17:31:41 +0300 | [diff] [blame] | 5024 | struct desktop_shell *shell; |
Kristian Høgsberg | 0704539 | 2012-02-19 18:52:44 -0500 | [diff] [blame] | 5025 | struct weston_surface *current; |
| 5026 | struct wl_listener listener; |
Kristian Høgsberg | 29139d4 | 2013-04-18 15:25:39 -0400 | [diff] [blame] | 5027 | struct weston_keyboard_grab grab; |
Kristian Høgsberg | 0704539 | 2012-02-19 18:52:44 -0500 | [diff] [blame] | 5028 | }; |
| 5029 | |
| 5030 | static void |
| 5031 | switcher_next(struct switcher *switcher) |
| 5032 | { |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 5033 | struct weston_view *view; |
Kristian Høgsberg | 0704539 | 2012-02-19 18:52:44 -0500 | [diff] [blame] | 5034 | struct weston_surface *first = NULL, *prev = NULL, *next = NULL; |
Kristian Høgsberg | 32e5686 | 2012-04-02 22:18:58 -0400 | [diff] [blame] | 5035 | struct shell_surface *shsurf; |
Kristian Høgsberg | b0d8e77 | 2012-06-18 16:34:58 -0400 | [diff] [blame] | 5036 | struct workspace *ws = get_current_workspace(switcher->shell); |
Kristian Høgsberg | 0704539 | 2012-02-19 18:52:44 -0500 | [diff] [blame] | 5037 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 5038 | wl_list_for_each(view, &ws->layer.view_list, layer_link) { |
Rafael Antognolli | ed207b4 | 2013-12-03 15:35:43 -0200 | [diff] [blame] | 5039 | shsurf = get_shell_surface(view->surface); |
Rafael Antognolli | 5031cbe | 2013-12-05 19:01:21 -0200 | [diff] [blame] | 5040 | if (shsurf && |
| 5041 | shsurf->type == SHELL_SURFACE_TOPLEVEL && |
| 5042 | shsurf->parent == NULL) { |
Kristian Høgsberg | 0704539 | 2012-02-19 18:52:44 -0500 | [diff] [blame] | 5043 | if (first == NULL) |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 5044 | first = view->surface; |
Kristian Høgsberg | 0704539 | 2012-02-19 18:52:44 -0500 | [diff] [blame] | 5045 | if (prev == switcher->current) |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 5046 | next = view->surface; |
| 5047 | prev = view->surface; |
| 5048 | view->alpha = 0.25; |
| 5049 | weston_view_geometry_dirty(view); |
| 5050 | weston_surface_damage(view->surface); |
Kristian Høgsberg | 0704539 | 2012-02-19 18:52:44 -0500 | [diff] [blame] | 5051 | } |
Alex Wu | 1659daa | 2012-04-01 20:13:09 +0800 | [diff] [blame] | 5052 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 5053 | if (is_black_surface(view->surface, NULL)) { |
| 5054 | view->alpha = 0.25; |
| 5055 | weston_view_geometry_dirty(view); |
| 5056 | weston_surface_damage(view->surface); |
Alex Wu | 1659daa | 2012-04-01 20:13:09 +0800 | [diff] [blame] | 5057 | } |
Kristian Høgsberg | 0704539 | 2012-02-19 18:52:44 -0500 | [diff] [blame] | 5058 | } |
| 5059 | |
| 5060 | if (next == NULL) |
| 5061 | next = first; |
| 5062 | |
Alex Wu | 07b2606 | 2012-03-12 16:06:01 +0800 | [diff] [blame] | 5063 | if (next == NULL) |
| 5064 | return; |
| 5065 | |
Kristian Høgsberg | 0704539 | 2012-02-19 18:52:44 -0500 | [diff] [blame] | 5066 | wl_list_remove(&switcher->listener.link); |
Jason Ekstrand | 26ed73c | 2013-06-06 22:34:41 -0500 | [diff] [blame] | 5067 | wl_signal_add(&next->destroy_signal, &switcher->listener); |
Kristian Høgsberg | 0704539 | 2012-02-19 18:52:44 -0500 | [diff] [blame] | 5068 | |
| 5069 | switcher->current = next; |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 5070 | wl_list_for_each(view, &next->views, surface_link) |
| 5071 | view->alpha = 1.0; |
Alex Wu | 1659daa | 2012-04-01 20:13:09 +0800 | [diff] [blame] | 5072 | |
Kristian Høgsberg | 32e5686 | 2012-04-02 22:18:58 -0400 | [diff] [blame] | 5073 | shsurf = get_shell_surface(switcher->current); |
Rafael Antognolli | 03b1659 | 2013-12-03 15:35:42 -0200 | [diff] [blame] | 5074 | if (shsurf && shsurf->state.fullscreen) |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 5075 | shsurf->fullscreen.black_view->alpha = 1.0; |
Kristian Høgsberg | 0704539 | 2012-02-19 18:52:44 -0500 | [diff] [blame] | 5076 | } |
| 5077 | |
| 5078 | static void |
Kristian Høgsberg | 27e3052 | 2012-04-11 23:18:23 -0400 | [diff] [blame] | 5079 | switcher_handle_surface_destroy(struct wl_listener *listener, void *data) |
Kristian Høgsberg | 0704539 | 2012-02-19 18:52:44 -0500 | [diff] [blame] | 5080 | { |
| 5081 | struct switcher *switcher = |
| 5082 | container_of(listener, struct switcher, listener); |
| 5083 | |
| 5084 | switcher_next(switcher); |
| 5085 | } |
| 5086 | |
| 5087 | static void |
Daniel Stone | 351eb61 | 2012-05-31 15:27:47 -0400 | [diff] [blame] | 5088 | switcher_destroy(struct switcher *switcher) |
Kristian Høgsberg | 0704539 | 2012-02-19 18:52:44 -0500 | [diff] [blame] | 5089 | { |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 5090 | struct weston_view *view; |
Kristian Høgsberg | 29139d4 | 2013-04-18 15:25:39 -0400 | [diff] [blame] | 5091 | struct weston_keyboard *keyboard = switcher->grab.keyboard; |
Kristian Høgsberg | b0d8e77 | 2012-06-18 16:34:58 -0400 | [diff] [blame] | 5092 | struct workspace *ws = get_current_workspace(switcher->shell); |
Kristian Høgsberg | 0704539 | 2012-02-19 18:52:44 -0500 | [diff] [blame] | 5093 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 5094 | 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] | 5095 | if (is_focus_view(view)) |
| 5096 | continue; |
| 5097 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 5098 | view->alpha = 1.0; |
| 5099 | weston_surface_damage(view->surface); |
Kristian Høgsberg | 0704539 | 2012-02-19 18:52:44 -0500 | [diff] [blame] | 5100 | } |
| 5101 | |
Alex Wu | 07b2606 | 2012-03-12 16:06:01 +0800 | [diff] [blame] | 5102 | if (switcher->current) |
Daniel Stone | 37816df | 2012-05-16 18:45:18 +0100 | [diff] [blame] | 5103 | activate(switcher->shell, switcher->current, |
| 5104 | (struct weston_seat *) keyboard->seat); |
Kristian Høgsberg | 0704539 | 2012-02-19 18:52:44 -0500 | [diff] [blame] | 5105 | wl_list_remove(&switcher->listener.link); |
Kristian Høgsberg | 29139d4 | 2013-04-18 15:25:39 -0400 | [diff] [blame] | 5106 | weston_keyboard_end_grab(keyboard); |
| 5107 | if (keyboard->input_method_resource) |
| 5108 | keyboard->grab = &keyboard->input_method_grab; |
Kristian Høgsberg | 0704539 | 2012-02-19 18:52:44 -0500 | [diff] [blame] | 5109 | free(switcher); |
| 5110 | } |
| 5111 | |
| 5112 | static void |
Kristian Høgsberg | 29139d4 | 2013-04-18 15:25:39 -0400 | [diff] [blame] | 5113 | switcher_key(struct weston_keyboard_grab *grab, |
Daniel Stone | c9785ea | 2012-05-30 16:31:52 +0100 | [diff] [blame] | 5114 | uint32_t time, uint32_t key, uint32_t state_w) |
Kristian Høgsberg | 0704539 | 2012-02-19 18:52:44 -0500 | [diff] [blame] | 5115 | { |
| 5116 | struct switcher *switcher = container_of(grab, struct switcher, grab); |
Daniel Stone | c9785ea | 2012-05-30 16:31:52 +0100 | [diff] [blame] | 5117 | enum wl_keyboard_key_state state = state_w; |
Daniel Stone | 351eb61 | 2012-05-31 15:27:47 -0400 | [diff] [blame] | 5118 | |
Daniel Stone | c9785ea | 2012-05-30 16:31:52 +0100 | [diff] [blame] | 5119 | if (key == KEY_TAB && state == WL_KEYBOARD_KEY_STATE_PRESSED) |
Daniel Stone | 351eb61 | 2012-05-31 15:27:47 -0400 | [diff] [blame] | 5120 | switcher_next(switcher); |
| 5121 | } |
| 5122 | |
| 5123 | static void |
Kristian Høgsberg | 29139d4 | 2013-04-18 15:25:39 -0400 | [diff] [blame] | 5124 | switcher_modifier(struct weston_keyboard_grab *grab, uint32_t serial, |
Daniel Stone | 351eb61 | 2012-05-31 15:27:47 -0400 | [diff] [blame] | 5125 | uint32_t mods_depressed, uint32_t mods_latched, |
| 5126 | uint32_t mods_locked, uint32_t group) |
| 5127 | { |
| 5128 | struct switcher *switcher = container_of(grab, struct switcher, grab); |
Daniel Stone | 37816df | 2012-05-16 18:45:18 +0100 | [diff] [blame] | 5129 | struct weston_seat *seat = (struct weston_seat *) grab->keyboard->seat; |
Kristian Høgsberg | 0704539 | 2012-02-19 18:52:44 -0500 | [diff] [blame] | 5130 | |
Daniel Stone | 351eb61 | 2012-05-31 15:27:47 -0400 | [diff] [blame] | 5131 | if ((seat->modifier_state & switcher->shell->binding_modifier) == 0) |
| 5132 | switcher_destroy(switcher); |
Kristian Høgsberg | b71302e | 2012-05-10 12:28:35 -0400 | [diff] [blame] | 5133 | } |
Kristian Høgsberg | 0704539 | 2012-02-19 18:52:44 -0500 | [diff] [blame] | 5134 | |
Jonas Ådahl | 1ea343e | 2013-10-25 23:18:05 +0200 | [diff] [blame] | 5135 | static void |
| 5136 | switcher_cancel(struct weston_keyboard_grab *grab) |
| 5137 | { |
| 5138 | struct switcher *switcher = container_of(grab, struct switcher, grab); |
| 5139 | |
| 5140 | switcher_destroy(switcher); |
| 5141 | } |
| 5142 | |
Kristian Høgsberg | 29139d4 | 2013-04-18 15:25:39 -0400 | [diff] [blame] | 5143 | static const struct weston_keyboard_grab_interface switcher_grab = { |
Daniel Stone | 351eb61 | 2012-05-31 15:27:47 -0400 | [diff] [blame] | 5144 | switcher_key, |
| 5145 | switcher_modifier, |
Jonas Ådahl | 1ea343e | 2013-10-25 23:18:05 +0200 | [diff] [blame] | 5146 | switcher_cancel, |
Kristian Høgsberg | 0704539 | 2012-02-19 18:52:44 -0500 | [diff] [blame] | 5147 | }; |
| 5148 | |
| 5149 | static void |
Kristian Høgsberg | e314875 | 2013-05-06 23:19:49 -0400 | [diff] [blame] | 5150 | switcher_binding(struct weston_seat *seat, uint32_t time, uint32_t key, |
Daniel Stone | 325fc2d | 2012-05-30 16:31:58 +0100 | [diff] [blame] | 5151 | void *data) |
Kristian Høgsberg | 0704539 | 2012-02-19 18:52:44 -0500 | [diff] [blame] | 5152 | { |
Tiago Vignatti | be14326 | 2012-04-16 17:31:41 +0300 | [diff] [blame] | 5153 | struct desktop_shell *shell = data; |
Kristian Høgsberg | 0704539 | 2012-02-19 18:52:44 -0500 | [diff] [blame] | 5154 | struct switcher *switcher; |
| 5155 | |
| 5156 | switcher = malloc(sizeof *switcher); |
Kristian Høgsberg | 02e79dc | 2012-04-12 09:55:26 -0400 | [diff] [blame] | 5157 | switcher->shell = shell; |
Kristian Høgsberg | 0704539 | 2012-02-19 18:52:44 -0500 | [diff] [blame] | 5158 | switcher->current = NULL; |
Kristian Høgsberg | 27e3052 | 2012-04-11 23:18:23 -0400 | [diff] [blame] | 5159 | switcher->listener.notify = switcher_handle_surface_destroy; |
Kristian Høgsberg | 0704539 | 2012-02-19 18:52:44 -0500 | [diff] [blame] | 5160 | wl_list_init(&switcher->listener.link); |
| 5161 | |
Alexander Larsson | f82b6ca | 2013-05-28 16:23:39 +0200 | [diff] [blame] | 5162 | restore_all_output_modes(shell->compositor); |
Kristian Høgsberg | b0d8e77 | 2012-06-18 16:34:58 -0400 | [diff] [blame] | 5163 | lower_fullscreen_layer(switcher->shell); |
Kristian Høgsberg | 0704539 | 2012-02-19 18:52:44 -0500 | [diff] [blame] | 5164 | switcher->grab.interface = &switcher_grab; |
Kristian Høgsberg | 29139d4 | 2013-04-18 15:25:39 -0400 | [diff] [blame] | 5165 | weston_keyboard_start_grab(seat->keyboard, &switcher->grab); |
| 5166 | weston_keyboard_set_focus(seat->keyboard, NULL); |
Kristian Høgsberg | 0704539 | 2012-02-19 18:52:44 -0500 | [diff] [blame] | 5167 | switcher_next(switcher); |
| 5168 | } |
| 5169 | |
Pekka Paalanen | 3c64723 | 2011-12-22 13:43:43 +0200 | [diff] [blame] | 5170 | static void |
Kristian Høgsberg | e314875 | 2013-05-06 23:19:49 -0400 | [diff] [blame] | 5171 | backlight_binding(struct weston_seat *seat, uint32_t time, uint32_t key, |
Daniel Stone | 325fc2d | 2012-05-30 16:31:58 +0100 | [diff] [blame] | 5172 | void *data) |
Tiago Vignatti | 8e53c7f | 2012-02-29 19:53:50 +0200 | [diff] [blame] | 5173 | { |
| 5174 | struct weston_compositor *compositor = data; |
| 5175 | struct weston_output *output; |
Tiago Vignatti | 5ab91ad | 2012-03-12 19:40:09 -0300 | [diff] [blame] | 5176 | long backlight_new = 0; |
Tiago Vignatti | 8e53c7f | 2012-02-29 19:53:50 +0200 | [diff] [blame] | 5177 | |
| 5178 | /* TODO: we're limiting to simple use cases, where we assume just |
| 5179 | * control on the primary display. We'd have to extend later if we |
| 5180 | * ever get support for setting backlights on random desktop LCD |
| 5181 | * panels though */ |
| 5182 | output = get_default_output(compositor); |
| 5183 | if (!output) |
| 5184 | return; |
| 5185 | |
| 5186 | if (!output->set_backlight) |
| 5187 | return; |
| 5188 | |
Tiago Vignatti | 5ab91ad | 2012-03-12 19:40:09 -0300 | [diff] [blame] | 5189 | if (key == KEY_F9 || key == KEY_BRIGHTNESSDOWN) |
| 5190 | backlight_new = output->backlight_current - 25; |
| 5191 | else if (key == KEY_F10 || key == KEY_BRIGHTNESSUP) |
| 5192 | backlight_new = output->backlight_current + 25; |
Tiago Vignatti | 8e53c7f | 2012-02-29 19:53:50 +0200 | [diff] [blame] | 5193 | |
Tiago Vignatti | 5ab91ad | 2012-03-12 19:40:09 -0300 | [diff] [blame] | 5194 | if (backlight_new < 5) |
| 5195 | backlight_new = 5; |
| 5196 | if (backlight_new > 255) |
| 5197 | backlight_new = 255; |
| 5198 | |
| 5199 | output->backlight_current = backlight_new; |
Tiago Vignatti | 8e53c7f | 2012-02-29 19:53:50 +0200 | [diff] [blame] | 5200 | output->set_backlight(output, output->backlight_current); |
| 5201 | } |
| 5202 | |
Ander Conselvan de Oliveira | c509d2b | 2012-11-08 17:20:45 +0200 | [diff] [blame] | 5203 | struct debug_binding_grab { |
Kristian Høgsberg | 29139d4 | 2013-04-18 15:25:39 -0400 | [diff] [blame] | 5204 | struct weston_keyboard_grab grab; |
Ander Conselvan de Oliveira | c509d2b | 2012-11-08 17:20:45 +0200 | [diff] [blame] | 5205 | struct weston_seat *seat; |
| 5206 | uint32_t key[2]; |
| 5207 | int key_released[2]; |
| 5208 | }; |
| 5209 | |
| 5210 | static void |
Kristian Høgsberg | 29139d4 | 2013-04-18 15:25:39 -0400 | [diff] [blame] | 5211 | 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] | 5212 | uint32_t key, uint32_t state) |
| 5213 | { |
| 5214 | struct debug_binding_grab *db = (struct debug_binding_grab *) grab; |
Rob Bradford | 880ebc7 | 2013-07-22 17:31:38 +0100 | [diff] [blame] | 5215 | struct weston_compositor *ec = db->seat->compositor; |
| 5216 | struct wl_display *display = ec->wl_display; |
Ander Conselvan de Oliveira | c509d2b | 2012-11-08 17:20:45 +0200 | [diff] [blame] | 5217 | struct wl_resource *resource; |
Ander Conselvan de Oliveira | c509d2b | 2012-11-08 17:20:45 +0200 | [diff] [blame] | 5218 | uint32_t serial; |
| 5219 | int send = 0, terminate = 0; |
| 5220 | int check_binding = 1; |
| 5221 | int i; |
Neil Roberts | 96d790e | 2013-09-19 17:32:00 +0100 | [diff] [blame] | 5222 | struct wl_list *resource_list; |
Ander Conselvan de Oliveira | c509d2b | 2012-11-08 17:20:45 +0200 | [diff] [blame] | 5223 | |
| 5224 | if (state == WL_KEYBOARD_KEY_STATE_RELEASED) { |
| 5225 | /* Do not run bindings on key releases */ |
| 5226 | check_binding = 0; |
| 5227 | |
| 5228 | for (i = 0; i < 2; i++) |
| 5229 | if (key == db->key[i]) |
| 5230 | db->key_released[i] = 1; |
| 5231 | |
| 5232 | if (db->key_released[0] && db->key_released[1]) { |
| 5233 | /* All key releases been swalled so end the grab */ |
| 5234 | terminate = 1; |
| 5235 | } else if (key != db->key[0] && key != db->key[1]) { |
| 5236 | /* Should not swallow release of other keys */ |
| 5237 | send = 1; |
| 5238 | } |
| 5239 | } else if (key == db->key[0] && !db->key_released[0]) { |
| 5240 | /* Do not check bindings for the first press of the binding |
| 5241 | * key. This allows it to be used as a debug shortcut. |
| 5242 | * We still need to swallow this event. */ |
| 5243 | check_binding = 0; |
| 5244 | } else if (db->key[1]) { |
| 5245 | /* If we already ran a binding don't process another one since |
| 5246 | * we can't keep track of all the binding keys that were |
| 5247 | * pressed in order to swallow the release events. */ |
| 5248 | send = 1; |
| 5249 | check_binding = 0; |
| 5250 | } |
| 5251 | |
| 5252 | if (check_binding) { |
Ander Conselvan de Oliveira | c509d2b | 2012-11-08 17:20:45 +0200 | [diff] [blame] | 5253 | if (weston_compositor_run_debug_binding(ec, db->seat, time, |
| 5254 | key, state)) { |
| 5255 | /* We ran a binding so swallow the press and keep the |
| 5256 | * grab to swallow the released too. */ |
| 5257 | send = 0; |
| 5258 | terminate = 0; |
| 5259 | db->key[1] = key; |
| 5260 | } else { |
| 5261 | /* Terminate the grab since the key pressed is not a |
| 5262 | * debug binding key. */ |
| 5263 | send = 1; |
| 5264 | terminate = 1; |
| 5265 | } |
| 5266 | } |
| 5267 | |
| 5268 | if (send) { |
Neil Roberts | 96d790e | 2013-09-19 17:32:00 +0100 | [diff] [blame] | 5269 | serial = wl_display_next_serial(display); |
| 5270 | resource_list = &grab->keyboard->focus_resource_list; |
| 5271 | wl_resource_for_each(resource, resource_list) { |
Ander Conselvan de Oliveira | c509d2b | 2012-11-08 17:20:45 +0200 | [diff] [blame] | 5272 | wl_keyboard_send_key(resource, serial, time, key, state); |
| 5273 | } |
| 5274 | } |
| 5275 | |
| 5276 | if (terminate) { |
Kristian Høgsberg | 29139d4 | 2013-04-18 15:25:39 -0400 | [diff] [blame] | 5277 | weston_keyboard_end_grab(grab->keyboard); |
| 5278 | if (grab->keyboard->input_method_resource) |
| 5279 | grab->keyboard->grab = &grab->keyboard->input_method_grab; |
Ander Conselvan de Oliveira | c509d2b | 2012-11-08 17:20:45 +0200 | [diff] [blame] | 5280 | free(db); |
| 5281 | } |
| 5282 | } |
| 5283 | |
| 5284 | static void |
Kristian Høgsberg | 29139d4 | 2013-04-18 15:25:39 -0400 | [diff] [blame] | 5285 | 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] | 5286 | uint32_t mods_depressed, uint32_t mods_latched, |
| 5287 | uint32_t mods_locked, uint32_t group) |
| 5288 | { |
| 5289 | struct wl_resource *resource; |
Neil Roberts | 96d790e | 2013-09-19 17:32:00 +0100 | [diff] [blame] | 5290 | struct wl_list *resource_list; |
Ander Conselvan de Oliveira | c509d2b | 2012-11-08 17:20:45 +0200 | [diff] [blame] | 5291 | |
Neil Roberts | 96d790e | 2013-09-19 17:32:00 +0100 | [diff] [blame] | 5292 | resource_list = &grab->keyboard->focus_resource_list; |
Ander Conselvan de Oliveira | c509d2b | 2012-11-08 17:20:45 +0200 | [diff] [blame] | 5293 | |
Neil Roberts | 96d790e | 2013-09-19 17:32:00 +0100 | [diff] [blame] | 5294 | wl_resource_for_each(resource, resource_list) { |
| 5295 | wl_keyboard_send_modifiers(resource, serial, mods_depressed, |
| 5296 | mods_latched, mods_locked, group); |
| 5297 | } |
Ander Conselvan de Oliveira | c509d2b | 2012-11-08 17:20:45 +0200 | [diff] [blame] | 5298 | } |
| 5299 | |
Jonas Ådahl | 1ea343e | 2013-10-25 23:18:05 +0200 | [diff] [blame] | 5300 | static void |
| 5301 | debug_binding_cancel(struct weston_keyboard_grab *grab) |
| 5302 | { |
| 5303 | struct debug_binding_grab *db = (struct debug_binding_grab *) grab; |
| 5304 | |
| 5305 | weston_keyboard_end_grab(grab->keyboard); |
| 5306 | free(db); |
| 5307 | } |
| 5308 | |
Kristian Høgsberg | 29139d4 | 2013-04-18 15:25:39 -0400 | [diff] [blame] | 5309 | struct weston_keyboard_grab_interface debug_binding_keyboard_grab = { |
Ander Conselvan de Oliveira | c509d2b | 2012-11-08 17:20:45 +0200 | [diff] [blame] | 5310 | debug_binding_key, |
Jonas Ådahl | 1ea343e | 2013-10-25 23:18:05 +0200 | [diff] [blame] | 5311 | debug_binding_modifiers, |
| 5312 | debug_binding_cancel, |
Ander Conselvan de Oliveira | c509d2b | 2012-11-08 17:20:45 +0200 | [diff] [blame] | 5313 | }; |
| 5314 | |
| 5315 | static void |
Kristian Høgsberg | e314875 | 2013-05-06 23:19:49 -0400 | [diff] [blame] | 5316 | 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] | 5317 | { |
| 5318 | struct debug_binding_grab *grab; |
| 5319 | |
| 5320 | grab = calloc(1, sizeof *grab); |
| 5321 | if (!grab) |
| 5322 | return; |
| 5323 | |
| 5324 | grab->seat = (struct weston_seat *) seat; |
| 5325 | grab->key[0] = key; |
| 5326 | grab->grab.interface = &debug_binding_keyboard_grab; |
Kristian Høgsberg | 29139d4 | 2013-04-18 15:25:39 -0400 | [diff] [blame] | 5327 | weston_keyboard_start_grab(seat->keyboard, &grab->grab); |
Ander Conselvan de Oliveira | c509d2b | 2012-11-08 17:20:45 +0200 | [diff] [blame] | 5328 | } |
| 5329 | |
Kristian Høgsberg | b41c081 | 2012-03-04 14:53:40 -0500 | [diff] [blame] | 5330 | static void |
Kristian Høgsberg | e314875 | 2013-05-06 23:19:49 -0400 | [diff] [blame] | 5331 | 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] | 5332 | void *data) |
Kristian Høgsberg | 92a57db | 2012-05-26 13:41:06 -0400 | [diff] [blame] | 5333 | { |
Kristian Høgsberg | fe7aa90 | 2013-05-08 09:54:37 -0400 | [diff] [blame] | 5334 | struct weston_surface *focus_surface; |
Kristian Høgsberg | 92a57db | 2012-05-26 13:41:06 -0400 | [diff] [blame] | 5335 | struct wl_client *client; |
Tiago Vignatti | 1d01b01 | 2012-09-27 17:48:36 +0300 | [diff] [blame] | 5336 | struct desktop_shell *shell = data; |
| 5337 | struct weston_compositor *compositor = shell->compositor; |
Kristian Høgsberg | 92a57db | 2012-05-26 13:41:06 -0400 | [diff] [blame] | 5338 | pid_t pid; |
Kristian Høgsberg | 92a57db | 2012-05-26 13:41:06 -0400 | [diff] [blame] | 5339 | |
Philipp Brüschweiler | 6cef009 | 2012-08-13 21:27:27 +0200 | [diff] [blame] | 5340 | focus_surface = seat->keyboard->focus; |
| 5341 | if (!focus_surface) |
| 5342 | return; |
| 5343 | |
Tiago Vignatti | 1d01b01 | 2012-09-27 17:48:36 +0300 | [diff] [blame] | 5344 | wl_signal_emit(&compositor->kill_signal, focus_surface); |
| 5345 | |
Jason Ekstrand | 26ed73c | 2013-06-06 22:34:41 -0500 | [diff] [blame] | 5346 | client = wl_resource_get_client(focus_surface->resource); |
Tiago Vignatti | 920f197 | 2012-09-27 17:48:35 +0300 | [diff] [blame] | 5347 | wl_client_get_credentials(client, &pid, NULL, NULL); |
| 5348 | |
| 5349 | /* Skip clients that we launched ourselves (the credentials of |
| 5350 | * the socketpair is ours) */ |
| 5351 | if (pid == getpid()) |
| 5352 | return; |
Kristian Høgsberg | 92a57db | 2012-05-26 13:41:06 -0400 | [diff] [blame] | 5353 | |
Daniel Stone | 325fc2d | 2012-05-30 16:31:58 +0100 | [diff] [blame] | 5354 | kill(pid, SIGKILL); |
Kristian Høgsberg | 92a57db | 2012-05-26 13:41:06 -0400 | [diff] [blame] | 5355 | } |
| 5356 | |
| 5357 | static void |
Kristian Høgsberg | e314875 | 2013-05-06 23:19:49 -0400 | [diff] [blame] | 5358 | workspace_up_binding(struct weston_seat *seat, uint32_t time, |
Jonas Ådahl | e3cddce | 2012-06-13 00:01:22 +0200 | [diff] [blame] | 5359 | uint32_t key, void *data) |
| 5360 | { |
| 5361 | struct desktop_shell *shell = data; |
| 5362 | unsigned int new_index = shell->workspaces.current; |
| 5363 | |
Kristian Høgsberg | ce345b0 | 2012-06-25 21:35:29 -0400 | [diff] [blame] | 5364 | if (shell->locked) |
Kristian Høgsberg | 4476aaf | 2012-06-25 14:03:13 -0400 | [diff] [blame] | 5365 | return; |
Jonas Ådahl | e3cddce | 2012-06-13 00:01:22 +0200 | [diff] [blame] | 5366 | if (new_index != 0) |
| 5367 | new_index--; |
| 5368 | |
| 5369 | change_workspace(shell, new_index); |
| 5370 | } |
| 5371 | |
| 5372 | static void |
Kristian Høgsberg | e314875 | 2013-05-06 23:19:49 -0400 | [diff] [blame] | 5373 | workspace_down_binding(struct weston_seat *seat, uint32_t time, |
Jonas Ådahl | e3cddce | 2012-06-13 00:01:22 +0200 | [diff] [blame] | 5374 | uint32_t key, void *data) |
| 5375 | { |
| 5376 | struct desktop_shell *shell = data; |
| 5377 | unsigned int new_index = shell->workspaces.current; |
| 5378 | |
Kristian Høgsberg | ce345b0 | 2012-06-25 21:35:29 -0400 | [diff] [blame] | 5379 | if (shell->locked) |
Kristian Høgsberg | 4476aaf | 2012-06-25 14:03:13 -0400 | [diff] [blame] | 5380 | return; |
Jonas Ådahl | e3cddce | 2012-06-13 00:01:22 +0200 | [diff] [blame] | 5381 | if (new_index < shell->workspaces.num - 1) |
| 5382 | new_index++; |
| 5383 | |
| 5384 | change_workspace(shell, new_index); |
| 5385 | } |
| 5386 | |
| 5387 | static void |
Kristian Høgsberg | e314875 | 2013-05-06 23:19:49 -0400 | [diff] [blame] | 5388 | workspace_f_binding(struct weston_seat *seat, uint32_t time, |
Jonas Ådahl | e3cddce | 2012-06-13 00:01:22 +0200 | [diff] [blame] | 5389 | uint32_t key, void *data) |
| 5390 | { |
| 5391 | struct desktop_shell *shell = data; |
| 5392 | unsigned int new_index; |
| 5393 | |
Kristian Høgsberg | ce345b0 | 2012-06-25 21:35:29 -0400 | [diff] [blame] | 5394 | if (shell->locked) |
Kristian Høgsberg | 4476aaf | 2012-06-25 14:03:13 -0400 | [diff] [blame] | 5395 | return; |
Jonas Ådahl | e3cddce | 2012-06-13 00:01:22 +0200 | [diff] [blame] | 5396 | new_index = key - KEY_F1; |
| 5397 | if (new_index >= shell->workspaces.num) |
| 5398 | new_index = shell->workspaces.num - 1; |
| 5399 | |
| 5400 | change_workspace(shell, new_index); |
| 5401 | } |
| 5402 | |
Jonas Ådahl | 8de6a1d | 2012-08-29 22:13:00 +0200 | [diff] [blame] | 5403 | static void |
Kristian Høgsberg | e314875 | 2013-05-06 23:19:49 -0400 | [diff] [blame] | 5404 | workspace_move_surface_up_binding(struct weston_seat *seat, uint32_t time, |
Jonas Ådahl | 8de6a1d | 2012-08-29 22:13:00 +0200 | [diff] [blame] | 5405 | uint32_t key, void *data) |
| 5406 | { |
| 5407 | struct desktop_shell *shell = data; |
| 5408 | unsigned int new_index = shell->workspaces.current; |
| 5409 | |
| 5410 | if (shell->locked) |
| 5411 | return; |
| 5412 | |
| 5413 | if (new_index != 0) |
| 5414 | new_index--; |
| 5415 | |
| 5416 | take_surface_to_workspace_by_seat(shell, seat, new_index); |
| 5417 | } |
| 5418 | |
| 5419 | static void |
Kristian Høgsberg | e314875 | 2013-05-06 23:19:49 -0400 | [diff] [blame] | 5420 | workspace_move_surface_down_binding(struct weston_seat *seat, uint32_t time, |
Jonas Ådahl | 8de6a1d | 2012-08-29 22:13:00 +0200 | [diff] [blame] | 5421 | uint32_t key, void *data) |
| 5422 | { |
| 5423 | struct desktop_shell *shell = data; |
| 5424 | unsigned int new_index = shell->workspaces.current; |
| 5425 | |
| 5426 | if (shell->locked) |
| 5427 | return; |
| 5428 | |
| 5429 | if (new_index < shell->workspaces.num - 1) |
| 5430 | new_index++; |
| 5431 | |
| 5432 | take_surface_to_workspace_by_seat(shell, seat, new_index); |
| 5433 | } |
Jonas Ådahl | e3cddce | 2012-06-13 00:01:22 +0200 | [diff] [blame] | 5434 | |
| 5435 | static void |
Xiong Zhang | 6b48142 | 2013-10-23 13:58:32 +0800 | [diff] [blame] | 5436 | handle_output_destroy(struct wl_listener *listener, void *data) |
| 5437 | { |
| 5438 | struct shell_output *output_listener = |
| 5439 | container_of(listener, struct shell_output, destroy_listener); |
| 5440 | |
| 5441 | wl_list_remove(&output_listener->destroy_listener.link); |
| 5442 | wl_list_remove(&output_listener->link); |
| 5443 | free(output_listener); |
| 5444 | } |
| 5445 | |
| 5446 | static void |
| 5447 | create_shell_output(struct desktop_shell *shell, |
| 5448 | struct weston_output *output) |
| 5449 | { |
| 5450 | struct shell_output *shell_output; |
| 5451 | |
| 5452 | shell_output = zalloc(sizeof *shell_output); |
| 5453 | if (shell_output == NULL) |
| 5454 | return; |
| 5455 | |
| 5456 | shell_output->output = output; |
| 5457 | shell_output->shell = shell; |
| 5458 | shell_output->destroy_listener.notify = handle_output_destroy; |
| 5459 | wl_signal_add(&output->destroy_signal, |
| 5460 | &shell_output->destroy_listener); |
Kristian Høgsberg | a3a0e18 | 2013-10-23 23:36:04 -0700 | [diff] [blame] | 5461 | wl_list_insert(shell->output_list.prev, &shell_output->link); |
Xiong Zhang | 6b48142 | 2013-10-23 13:58:32 +0800 | [diff] [blame] | 5462 | } |
| 5463 | |
| 5464 | static void |
| 5465 | handle_output_create(struct wl_listener *listener, void *data) |
| 5466 | { |
| 5467 | struct desktop_shell *shell = |
| 5468 | container_of(listener, struct desktop_shell, output_create_listener); |
| 5469 | struct weston_output *output = (struct weston_output *)data; |
| 5470 | |
| 5471 | create_shell_output(shell, output); |
| 5472 | } |
| 5473 | |
| 5474 | static void |
| 5475 | setup_output_destroy_handler(struct weston_compositor *ec, |
| 5476 | struct desktop_shell *shell) |
| 5477 | { |
| 5478 | struct weston_output *output; |
| 5479 | |
| 5480 | wl_list_init(&shell->output_list); |
| 5481 | wl_list_for_each(output, &ec->output_list, link) |
| 5482 | create_shell_output(shell, output); |
| 5483 | |
| 5484 | shell->output_create_listener.notify = handle_output_create; |
| 5485 | wl_signal_add(&ec->output_created_signal, |
| 5486 | &shell->output_create_listener); |
| 5487 | } |
| 5488 | |
| 5489 | static void |
Kristian Høgsberg | 02e79dc | 2012-04-12 09:55:26 -0400 | [diff] [blame] | 5490 | shell_destroy(struct wl_listener *listener, void *data) |
Pekka Paalanen | 3c64723 | 2011-12-22 13:43:43 +0200 | [diff] [blame] | 5491 | { |
Tiago Vignatti | be14326 | 2012-04-16 17:31:41 +0300 | [diff] [blame] | 5492 | struct desktop_shell *shell = |
| 5493 | container_of(listener, struct desktop_shell, destroy_listener); |
Jonas Ådahl | e3cddce | 2012-06-13 00:01:22 +0200 | [diff] [blame] | 5494 | struct workspace **ws; |
Xiong Zhang | 6b48142 | 2013-10-23 13:58:32 +0800 | [diff] [blame] | 5495 | struct shell_output *shell_output, *tmp; |
Pekka Paalanen | 3c64723 | 2011-12-22 13:43:43 +0200 | [diff] [blame] | 5496 | |
Kristian Høgsberg | 17bccae | 2014-01-16 16:46:28 -0800 | [diff] [blame] | 5497 | /* Force state to unlocked so we don't try to fade */ |
| 5498 | shell->locked = false; |
Pekka Paalanen | 9cf5cc8 | 2012-01-02 16:00:24 +0200 | [diff] [blame] | 5499 | if (shell->child.client) |
| 5500 | wl_client_destroy(shell->child.client); |
| 5501 | |
Ander Conselvan de Oliveira | a457563 | 2013-02-21 18:35:23 +0200 | [diff] [blame] | 5502 | wl_list_remove(&shell->idle_listener.link); |
| 5503 | wl_list_remove(&shell->wake_listener.link); |
Kristian Høgsberg | 677a5f5 | 2013-12-04 11:00:19 -0800 | [diff] [blame] | 5504 | |
| 5505 | input_panel_destroy(shell); |
Kristian Høgsberg | 88c1607 | 2012-05-16 08:04:19 -0400 | [diff] [blame] | 5506 | |
Xiong Zhang | 6b48142 | 2013-10-23 13:58:32 +0800 | [diff] [blame] | 5507 | wl_list_for_each_safe(shell_output, tmp, &shell->output_list, link) { |
| 5508 | wl_list_remove(&shell_output->destroy_listener.link); |
| 5509 | wl_list_remove(&shell_output->link); |
| 5510 | free(shell_output); |
| 5511 | } |
| 5512 | |
| 5513 | wl_list_remove(&shell->output_create_listener.link); |
| 5514 | |
Jonas Ådahl | e3cddce | 2012-06-13 00:01:22 +0200 | [diff] [blame] | 5515 | wl_array_for_each(ws, &shell->workspaces.array) |
| 5516 | workspace_destroy(*ws); |
| 5517 | wl_array_release(&shell->workspaces.array); |
| 5518 | |
Pekka Paalanen | 3c64723 | 2011-12-22 13:43:43 +0200 | [diff] [blame] | 5519 | free(shell->screensaver.path); |
Emilio Pozuelo Monfort | 46ce798 | 2013-11-20 13:22:29 +0100 | [diff] [blame] | 5520 | free(shell->client); |
Pekka Paalanen | 3c64723 | 2011-12-22 13:43:43 +0200 | [diff] [blame] | 5521 | free(shell); |
| 5522 | } |
| 5523 | |
Tiago Vignatti | 0b52d48 | 2012-04-20 18:54:25 +0300 | [diff] [blame] | 5524 | static void |
| 5525 | shell_add_bindings(struct weston_compositor *ec, struct desktop_shell *shell) |
| 5526 | { |
| 5527 | uint32_t mod; |
Jonas Ådahl | e3cddce | 2012-06-13 00:01:22 +0200 | [diff] [blame] | 5528 | int i, num_workspace_bindings; |
Tiago Vignatti | 0b52d48 | 2012-04-20 18:54:25 +0300 | [diff] [blame] | 5529 | |
| 5530 | /* fixed bindings */ |
Daniel Stone | 325fc2d | 2012-05-30 16:31:58 +0100 | [diff] [blame] | 5531 | weston_compositor_add_key_binding(ec, KEY_BACKSPACE, |
| 5532 | MODIFIER_CTRL | MODIFIER_ALT, |
| 5533 | terminate_binding, ec); |
| 5534 | weston_compositor_add_button_binding(ec, BTN_LEFT, 0, |
| 5535 | click_to_activate_binding, |
| 5536 | shell); |
Neil Roberts | a28c693 | 2013-10-03 16:43:04 +0100 | [diff] [blame] | 5537 | weston_compositor_add_touch_binding(ec, 0, |
| 5538 | touch_to_activate_binding, |
| 5539 | shell); |
Daniel Stone | 325fc2d | 2012-05-30 16:31:58 +0100 | [diff] [blame] | 5540 | weston_compositor_add_axis_binding(ec, WL_POINTER_AXIS_VERTICAL_SCROLL, |
| 5541 | MODIFIER_SUPER | MODIFIER_ALT, |
| 5542 | surface_opacity_binding, NULL); |
| 5543 | weston_compositor_add_axis_binding(ec, WL_POINTER_AXIS_VERTICAL_SCROLL, |
| 5544 | MODIFIER_SUPER, zoom_axis_binding, |
| 5545 | NULL); |
Tiago Vignatti | 0b52d48 | 2012-04-20 18:54:25 +0300 | [diff] [blame] | 5546 | |
| 5547 | /* configurable bindings */ |
| 5548 | mod = shell->binding_modifier; |
Daniel Stone | 325fc2d | 2012-05-30 16:31:58 +0100 | [diff] [blame] | 5549 | weston_compositor_add_key_binding(ec, KEY_PAGEUP, mod, |
| 5550 | zoom_key_binding, NULL); |
| 5551 | weston_compositor_add_key_binding(ec, KEY_PAGEDOWN, mod, |
| 5552 | zoom_key_binding, NULL); |
Kristian Høgsberg | 211b517 | 2014-01-11 13:10:21 -0800 | [diff] [blame] | 5553 | weston_compositor_add_key_binding(ec, KEY_M, mod | MODIFIER_SHIFT, |
| 5554 | maximize_binding, NULL); |
| 5555 | weston_compositor_add_key_binding(ec, KEY_F, mod | MODIFIER_SHIFT, |
| 5556 | fullscreen_binding, NULL); |
Daniel Stone | 325fc2d | 2012-05-30 16:31:58 +0100 | [diff] [blame] | 5557 | weston_compositor_add_button_binding(ec, BTN_LEFT, mod, move_binding, |
| 5558 | shell); |
Neil Roberts | aba0f25 | 2013-10-03 16:43:05 +0100 | [diff] [blame] | 5559 | weston_compositor_add_touch_binding(ec, mod, touch_move_binding, shell); |
Daniel Stone | 325fc2d | 2012-05-30 16:31:58 +0100 | [diff] [blame] | 5560 | weston_compositor_add_button_binding(ec, BTN_MIDDLE, mod, |
| 5561 | resize_binding, shell); |
Kristian Høgsberg | 0837fa9 | 2014-01-20 10:35:26 -0800 | [diff] [blame] | 5562 | weston_compositor_add_button_binding(ec, BTN_LEFT, |
| 5563 | mod | MODIFIER_SHIFT, |
| 5564 | resize_binding, shell); |
Pekka Paalanen | 7bb6510 | 2013-05-22 18:03:04 +0300 | [diff] [blame] | 5565 | |
| 5566 | if (ec->capabilities & WESTON_CAP_ROTATION_ANY) |
| 5567 | weston_compositor_add_button_binding(ec, BTN_RIGHT, mod, |
| 5568 | rotate_binding, NULL); |
| 5569 | |
Daniel Stone | 325fc2d | 2012-05-30 16:31:58 +0100 | [diff] [blame] | 5570 | weston_compositor_add_key_binding(ec, KEY_TAB, mod, switcher_binding, |
| 5571 | shell); |
| 5572 | weston_compositor_add_key_binding(ec, KEY_F9, mod, backlight_binding, |
| 5573 | ec); |
| 5574 | weston_compositor_add_key_binding(ec, KEY_BRIGHTNESSDOWN, 0, |
| 5575 | backlight_binding, ec); |
| 5576 | weston_compositor_add_key_binding(ec, KEY_F10, mod, backlight_binding, |
| 5577 | ec); |
| 5578 | weston_compositor_add_key_binding(ec, KEY_BRIGHTNESSUP, 0, |
| 5579 | backlight_binding, ec); |
Daniel Stone | 325fc2d | 2012-05-30 16:31:58 +0100 | [diff] [blame] | 5580 | weston_compositor_add_key_binding(ec, KEY_K, mod, |
| 5581 | force_kill_binding, shell); |
Jonas Ådahl | e3cddce | 2012-06-13 00:01:22 +0200 | [diff] [blame] | 5582 | weston_compositor_add_key_binding(ec, KEY_UP, mod, |
| 5583 | workspace_up_binding, shell); |
| 5584 | weston_compositor_add_key_binding(ec, KEY_DOWN, mod, |
| 5585 | workspace_down_binding, shell); |
Jonas Ådahl | 8de6a1d | 2012-08-29 22:13:00 +0200 | [diff] [blame] | 5586 | weston_compositor_add_key_binding(ec, KEY_UP, mod | MODIFIER_SHIFT, |
| 5587 | workspace_move_surface_up_binding, |
| 5588 | shell); |
| 5589 | weston_compositor_add_key_binding(ec, KEY_DOWN, mod | MODIFIER_SHIFT, |
| 5590 | workspace_move_surface_down_binding, |
| 5591 | shell); |
Jonas Ådahl | e3cddce | 2012-06-13 00:01:22 +0200 | [diff] [blame] | 5592 | |
Kristian Høgsberg | d56ab4e | 2014-01-16 16:51:52 -0800 | [diff] [blame] | 5593 | if (shell->exposay_modifier) |
| 5594 | weston_compositor_add_modifier_binding(ec, shell->exposay_modifier, |
| 5595 | exposay_binding, shell); |
Daniel Stone | df8133b | 2013-11-19 11:37:14 +0100 | [diff] [blame] | 5596 | |
Jonas Ådahl | e3cddce | 2012-06-13 00:01:22 +0200 | [diff] [blame] | 5597 | /* Add bindings for mod+F[1-6] for workspace 1 to 6. */ |
| 5598 | if (shell->workspaces.num > 1) { |
| 5599 | num_workspace_bindings = shell->workspaces.num; |
| 5600 | if (num_workspace_bindings > 6) |
| 5601 | num_workspace_bindings = 6; |
| 5602 | for (i = 0; i < num_workspace_bindings; i++) |
| 5603 | weston_compositor_add_key_binding(ec, KEY_F1 + i, mod, |
| 5604 | workspace_f_binding, |
| 5605 | shell); |
| 5606 | } |
Ander Conselvan de Oliveira | c509d2b | 2012-11-08 17:20:45 +0200 | [diff] [blame] | 5607 | |
| 5608 | /* Debug bindings */ |
| 5609 | weston_compositor_add_key_binding(ec, KEY_SPACE, mod | MODIFIER_SHIFT, |
| 5610 | debug_binding, shell); |
Tiago Vignatti | 0b52d48 | 2012-04-20 18:54:25 +0300 | [diff] [blame] | 5611 | } |
| 5612 | |
Kristian Høgsberg | 1c56218 | 2011-05-02 22:09:20 -0400 | [diff] [blame] | 5613 | WL_EXPORT int |
Kristian Høgsberg | cb4685b | 2013-02-20 15:37:49 -0500 | [diff] [blame] | 5614 | module_init(struct weston_compositor *ec, |
Ossama Othman | a50e6e4 | 2013-05-14 09:48:26 -0700 | [diff] [blame] | 5615 | int *argc, char *argv[]) |
Kristian Høgsberg | 4cca349 | 2011-01-18 07:53:49 -0500 | [diff] [blame] | 5616 | { |
Kristian Høgsberg | f4d2f23 | 2012-08-10 10:05:39 -0400 | [diff] [blame] | 5617 | struct weston_seat *seat; |
Tiago Vignatti | be14326 | 2012-04-16 17:31:41 +0300 | [diff] [blame] | 5618 | struct desktop_shell *shell; |
Jonas Ådahl | e3cddce | 2012-06-13 00:01:22 +0200 | [diff] [blame] | 5619 | struct workspace **pws; |
| 5620 | unsigned int i; |
Tiago Vignatti | b7dbbd6 | 2012-09-25 17:57:01 +0300 | [diff] [blame] | 5621 | struct wl_event_loop *loop; |
Kristian Høgsberg | 02ec0a5 | 2011-04-23 13:04:11 -0400 | [diff] [blame] | 5622 | |
Peter Hutterer | f3d6227 | 2013-08-08 11:57:05 +1000 | [diff] [blame] | 5623 | shell = zalloc(sizeof *shell); |
Kristian Høgsberg | 02ec0a5 | 2011-04-23 13:04:11 -0400 | [diff] [blame] | 5624 | if (shell == NULL) |
| 5625 | return -1; |
| 5626 | |
Kristian Høgsberg | 7584062 | 2011-09-06 13:48:16 -0400 | [diff] [blame] | 5627 | shell->compositor = ec; |
Kristian Høgsberg | 02e79dc | 2012-04-12 09:55:26 -0400 | [diff] [blame] | 5628 | |
| 5629 | shell->destroy_listener.notify = shell_destroy; |
| 5630 | wl_signal_add(&ec->destroy_signal, &shell->destroy_listener); |
Ander Conselvan de Oliveira | a457563 | 2013-02-21 18:35:23 +0200 | [diff] [blame] | 5631 | shell->idle_listener.notify = idle_handler; |
| 5632 | wl_signal_add(&ec->idle_signal, &shell->idle_listener); |
| 5633 | shell->wake_listener.notify = wake_handler; |
| 5634 | wl_signal_add(&ec->wake_signal, &shell->wake_listener); |
Kristian Høgsberg | 677a5f5 | 2013-12-04 11:00:19 -0800 | [diff] [blame] | 5635 | |
Scott Moreau | ff1db4a | 2012-04-17 19:06:18 -0600 | [diff] [blame] | 5636 | ec->ping_handler = ping_handler; |
Kristian Høgsberg | 82a1d11 | 2012-07-19 14:02:00 -0400 | [diff] [blame] | 5637 | ec->shell_interface.shell = shell; |
Tiago Vignatti | bc052c9 | 2012-04-19 16:18:18 +0300 | [diff] [blame] | 5638 | ec->shell_interface.create_shell_surface = create_shell_surface; |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 5639 | ec->shell_interface.get_primary_view = get_primary_view; |
Tiago Vignatti | bc052c9 | 2012-04-19 16:18:18 +0300 | [diff] [blame] | 5640 | ec->shell_interface.set_toplevel = set_toplevel; |
Tiago Vignatti | 491bac1 | 2012-05-18 16:37:43 -0400 | [diff] [blame] | 5641 | ec->shell_interface.set_transient = set_transient; |
Kristian Høgsberg | b810eb5 | 2013-02-12 20:07:05 -0500 | [diff] [blame] | 5642 | ec->shell_interface.set_fullscreen = set_fullscreen; |
Tiago Vignatti | fb2adba | 2013-06-12 15:43:21 -0300 | [diff] [blame] | 5643 | ec->shell_interface.set_xwayland = set_xwayland; |
Kristian Høgsberg | 938b8fa | 2012-05-18 13:46:27 -0400 | [diff] [blame] | 5644 | ec->shell_interface.move = surface_move; |
Kristian Høgsberg | c1693f2 | 2012-05-22 16:56:23 -0400 | [diff] [blame] | 5645 | ec->shell_interface.resize = surface_resize; |
Giulio Camuffo | 62942ad | 2013-09-11 18:20:47 +0200 | [diff] [blame] | 5646 | ec->shell_interface.set_title = set_title; |
Kristian Høgsberg | 4cca349 | 2011-01-18 07:53:49 -0500 | [diff] [blame] | 5647 | |
Kristian Høgsberg | 3be2ce9 | 2012-02-29 12:42:35 -0500 | [diff] [blame] | 5648 | weston_layer_init(&shell->fullscreen_layer, &ec->cursor_layer.link); |
| 5649 | weston_layer_init(&shell->panel_layer, &shell->fullscreen_layer.link); |
Jonas Ådahl | e3cddce | 2012-06-13 00:01:22 +0200 | [diff] [blame] | 5650 | weston_layer_init(&shell->background_layer, &shell->panel_layer.link); |
| 5651 | weston_layer_init(&shell->lock_layer, NULL); |
Philipp Brüschweiler | 711fda8 | 2012-08-09 18:50:43 +0200 | [diff] [blame] | 5652 | weston_layer_init(&shell->input_panel_layer, NULL); |
Jonas Ådahl | e3cddce | 2012-06-13 00:01:22 +0200 | [diff] [blame] | 5653 | |
| 5654 | wl_array_init(&shell->workspaces.array); |
Jonas Ådahl | e9d2250 | 2012-08-29 22:13:01 +0200 | [diff] [blame] | 5655 | wl_list_init(&shell->workspaces.client_list); |
Kristian Høgsberg | 3be2ce9 | 2012-02-29 12:42:35 -0500 | [diff] [blame] | 5656 | |
Kristian Høgsberg | 677a5f5 | 2013-12-04 11:00:19 -0800 | [diff] [blame] | 5657 | if (input_panel_setup(shell) < 0) |
| 5658 | return -1; |
| 5659 | |
Kristian Høgsberg | 14e438c | 2013-05-26 21:48:14 -0400 | [diff] [blame] | 5660 | shell_configuration(shell); |
Pekka Paalanen | e955f1e | 2011-12-07 11:49:52 +0200 | [diff] [blame] | 5661 | |
Daniel Stone | df8133b | 2013-11-19 11:37:14 +0100 | [diff] [blame] | 5662 | shell->exposay.state_cur = EXPOSAY_LAYOUT_INACTIVE; |
| 5663 | shell->exposay.state_target = EXPOSAY_TARGET_CANCEL; |
| 5664 | |
Jonas Ådahl | e3cddce | 2012-06-13 00:01:22 +0200 | [diff] [blame] | 5665 | for (i = 0; i < shell->workspaces.num; i++) { |
| 5666 | pws = wl_array_add(&shell->workspaces.array, sizeof *pws); |
| 5667 | if (pws == NULL) |
| 5668 | return -1; |
| 5669 | |
| 5670 | *pws = workspace_create(); |
| 5671 | if (*pws == NULL) |
| 5672 | return -1; |
| 5673 | } |
| 5674 | activate_workspace(shell, 0); |
| 5675 | |
Jonas Ådahl | 8de6a1d | 2012-08-29 22:13:00 +0200 | [diff] [blame] | 5676 | wl_list_init(&shell->workspaces.anim_sticky_list); |
Jonas Ådahl | 62fcd04 | 2012-06-13 00:01:23 +0200 | [diff] [blame] | 5677 | wl_list_init(&shell->workspaces.animation.link); |
| 5678 | shell->workspaces.animation.frame = animate_workspace_change_frame; |
| 5679 | |
Kristian Høgsberg | 919cddb | 2013-07-08 19:03:57 -0400 | [diff] [blame] | 5680 | if (wl_global_create(ec->wl_display, &wl_shell_interface, 1, |
Kristian Høgsberg | 97d44aa | 2011-08-26 17:21:20 -0400 | [diff] [blame] | 5681 | shell, bind_shell) == NULL) |
Kristian Høgsberg | 4cca349 | 2011-01-18 07:53:49 -0500 | [diff] [blame] | 5682 | return -1; |
| 5683 | |
Rafael Antognolli | e2a3455 | 2013-12-03 15:35:45 -0200 | [diff] [blame] | 5684 | if (wl_global_create(ec->wl_display, &xdg_shell_interface, 1, |
| 5685 | shell, bind_xdg_shell) == NULL) |
| 5686 | return -1; |
| 5687 | |
Kristian Høgsberg | 919cddb | 2013-07-08 19:03:57 -0400 | [diff] [blame] | 5688 | if (wl_global_create(ec->wl_display, |
| 5689 | &desktop_shell_interface, 2, |
| 5690 | shell, bind_desktop_shell) == NULL) |
Kristian Høgsberg | 7584062 | 2011-09-06 13:48:16 -0400 | [diff] [blame] | 5691 | return -1; |
| 5692 | |
Kristian Høgsberg | 919cddb | 2013-07-08 19:03:57 -0400 | [diff] [blame] | 5693 | if (wl_global_create(ec->wl_display, &screensaver_interface, 1, |
| 5694 | shell, bind_screensaver) == NULL) |
Pekka Paalanen | 6e16811 | 2011-11-24 11:34:05 +0200 | [diff] [blame] | 5695 | return -1; |
| 5696 | |
Kristian Høgsberg | 919cddb | 2013-07-08 19:03:57 -0400 | [diff] [blame] | 5697 | if (wl_global_create(ec->wl_display, &workspace_manager_interface, 1, |
| 5698 | shell, bind_workspace_manager) == NULL) |
Jonas Ådahl | e9d2250 | 2012-08-29 22:13:01 +0200 | [diff] [blame] | 5699 | return -1; |
| 5700 | |
Kristian Høgsberg | f03a616 | 2012-01-17 11:07:42 -0500 | [diff] [blame] | 5701 | shell->child.deathstamp = weston_compositor_get_time(); |
Tiago Vignatti | b7dbbd6 | 2012-09-25 17:57:01 +0300 | [diff] [blame] | 5702 | |
Xiong Zhang | 6b48142 | 2013-10-23 13:58:32 +0800 | [diff] [blame] | 5703 | setup_output_destroy_handler(ec, shell); |
| 5704 | |
Tiago Vignatti | b7dbbd6 | 2012-09-25 17:57:01 +0300 | [diff] [blame] | 5705 | loop = wl_display_get_event_loop(ec->wl_display); |
| 5706 | wl_event_loop_add_idle(loop, launch_desktop_shell_process, shell); |
Pekka Paalanen | 6cd281a | 2011-11-03 14:11:32 +0200 | [diff] [blame] | 5707 | |
Ander Conselvan de Oliveira | 859e885 | 2013-02-21 18:35:21 +0200 | [diff] [blame] | 5708 | shell->screensaver.timer = |
| 5709 | wl_event_loop_add_timer(loop, screensaver_timeout, shell); |
| 5710 | |
Kristian Høgsberg | f4d2f23 | 2012-08-10 10:05:39 -0400 | [diff] [blame] | 5711 | wl_list_for_each(seat, &ec->seat_list, link) |
| 5712 | create_pointer_focus_listener(seat); |
Kristian Høgsberg | d56bd90 | 2012-06-05 09:58:51 -0400 | [diff] [blame] | 5713 | |
Tiago Vignatti | 0b52d48 | 2012-04-20 18:54:25 +0300 | [diff] [blame] | 5714 | shell_add_bindings(ec, shell); |
Kristian Høgsberg | 0793756 | 2011-04-12 17:25:42 -0400 | [diff] [blame] | 5715 | |
Pekka Paalanen | 79346ab | 2013-05-22 18:03:09 +0300 | [diff] [blame] | 5716 | shell_fade_init(shell); |
Ander Conselvan de Oliveira | 19d10ef | 2013-02-21 18:35:20 +0200 | [diff] [blame] | 5717 | |
Kristian Høgsberg | 4cca349 | 2011-01-18 07:53:49 -0500 | [diff] [blame] | 5718 | return 0; |
| 5719 | } |