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; |
| 359 | |
| 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 | { |
Juan Zhao | e10d279 | 2012-04-25 19:09:52 +0800 | [diff] [blame] | 409 | if (!strcmp("zoom", animation)) |
| 410 | return ANIMATION_ZOOM; |
| 411 | else if (!strcmp("fade", animation)) |
| 412 | return ANIMATION_FADE; |
Louis-Francis Ratté-Boulianne | b482dbd | 2013-11-19 11:37:11 +0100 | [diff] [blame] | 413 | else if (!strcmp("dim-layer", animation)) |
| 414 | return ANIMATION_DIM_LAYER; |
Juan Zhao | e10d279 | 2012-04-25 19:09:52 +0800 | [diff] [blame] | 415 | else |
| 416 | return ANIMATION_NONE; |
| 417 | } |
| 418 | |
Alex Wu | 4539b08 | 2012-03-01 12:57:46 +0800 | [diff] [blame] | 419 | static void |
Kristian Høgsberg | 14e438c | 2013-05-26 21:48:14 -0400 | [diff] [blame] | 420 | shell_configuration(struct desktop_shell *shell) |
Pekka Paalanen | e955f1e | 2011-12-07 11:49:52 +0200 | [diff] [blame] | 421 | { |
Kristian Høgsberg | 673a889 | 2013-05-23 21:40:56 -0400 | [diff] [blame] | 422 | struct weston_config_section *section; |
| 423 | int duration; |
| 424 | char *s; |
Pekka Paalanen | e955f1e | 2011-12-07 11:49:52 +0200 | [diff] [blame] | 425 | |
Kristian Høgsberg | 673a889 | 2013-05-23 21:40:56 -0400 | [diff] [blame] | 426 | section = weston_config_get_section(shell->compositor->config, |
| 427 | "screensaver", NULL, NULL); |
| 428 | weston_config_section_get_string(section, |
| 429 | "path", &shell->screensaver.path, NULL); |
| 430 | weston_config_section_get_int(section, "duration", &duration, 60); |
Ander Conselvan de Oliveira | 859e885 | 2013-02-21 18:35:21 +0200 | [diff] [blame] | 431 | shell->screensaver.duration = duration * 1000; |
Kristian Høgsberg | 673a889 | 2013-05-23 21:40:56 -0400 | [diff] [blame] | 432 | |
| 433 | section = weston_config_get_section(shell->compositor->config, |
| 434 | "shell", NULL, NULL); |
| 435 | weston_config_section_get_string(section, |
Emilio Pozuelo Monfort | 8a81b83 | 2013-12-02 12:53:32 +0100 | [diff] [blame] | 436 | "client", &s, LIBEXECDIR "/" WESTON_SHELL_CLIENT); |
Emilio Pozuelo Monfort | 46ce798 | 2013-11-20 13:22:29 +0100 | [diff] [blame] | 437 | shell->client = s; |
| 438 | weston_config_section_get_string(section, |
Kristian Høgsberg | 673a889 | 2013-05-23 21:40:56 -0400 | [diff] [blame] | 439 | "binding-modifier", &s, "super"); |
| 440 | shell->binding_modifier = get_modifier(s); |
Quentin Glidic | 8418c29 | 2013-06-18 09:11:03 +0200 | [diff] [blame] | 441 | free(s); |
Kristian Høgsberg | d56ab4e | 2014-01-16 16:51:52 -0800 | [diff] [blame] | 442 | |
| 443 | weston_config_section_get_string(section, |
| 444 | "exposay-modifier", &s, "none"); |
| 445 | if (strcmp(s, "none") == 0) |
| 446 | shell->exposay_modifier = 0; |
| 447 | else |
| 448 | shell->exposay_modifier = get_modifier(s); |
| 449 | free(s); |
| 450 | |
Kristian Høgsberg | 673a889 | 2013-05-23 21:40:56 -0400 | [diff] [blame] | 451 | weston_config_section_get_string(section, "animation", &s, "none"); |
| 452 | shell->win_animation_type = get_animation_type(s); |
Quentin Glidic | 8418c29 | 2013-06-18 09:11:03 +0200 | [diff] [blame] | 453 | free(s); |
Kristian Høgsberg | 724c8d9 | 2013-10-16 11:38:24 -0700 | [diff] [blame] | 454 | weston_config_section_get_string(section, |
| 455 | "startup-animation", &s, "fade"); |
| 456 | shell->startup_animation_type = get_animation_type(s); |
| 457 | free(s); |
Kristian Høgsberg | 912e0a1 | 2013-10-30 08:59:55 -0700 | [diff] [blame] | 458 | if (shell->startup_animation_type == ANIMATION_ZOOM) |
| 459 | shell->startup_animation_type = ANIMATION_NONE; |
Louis-Francis Ratté-Boulianne | b482dbd | 2013-11-19 11:37:11 +0100 | [diff] [blame] | 460 | weston_config_section_get_string(section, "focus-animation", &s, "none"); |
| 461 | shell->focus_animation_type = get_animation_type(s); |
| 462 | free(s); |
Kristian Høgsberg | 673a889 | 2013-05-23 21:40:56 -0400 | [diff] [blame] | 463 | weston_config_section_get_uint(section, "num-workspaces", |
| 464 | &shell->workspaces.num, |
| 465 | DEFAULT_NUM_WORKSPACES); |
Jonas Ådahl | e3cddce | 2012-06-13 00:01:22 +0200 | [diff] [blame] | 466 | } |
| 467 | |
Kristian Høgsberg | 1ef2313 | 2013-12-04 00:20:01 -0800 | [diff] [blame] | 468 | struct weston_output * |
Louis-Francis Ratté-Boulianne | b482dbd | 2013-11-19 11:37:11 +0100 | [diff] [blame] | 469 | get_default_output(struct weston_compositor *compositor) |
| 470 | { |
| 471 | return container_of(compositor->output_list.next, |
| 472 | struct weston_output, link); |
| 473 | } |
| 474 | |
| 475 | |
| 476 | /* no-op func for checking focus surface */ |
| 477 | static void |
Jason Ekstrand | 918f2dd | 2013-12-02 21:01:53 -0600 | [diff] [blame] | 478 | 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] | 479 | { |
| 480 | } |
| 481 | |
| 482 | static struct focus_surface * |
| 483 | get_focus_surface(struct weston_surface *surface) |
| 484 | { |
| 485 | if (surface->configure == focus_surface_configure) |
| 486 | return surface->configure_private; |
| 487 | else |
| 488 | return NULL; |
| 489 | } |
| 490 | |
| 491 | static bool |
| 492 | is_focus_surface (struct weston_surface *es) |
| 493 | { |
| 494 | return (es->configure == focus_surface_configure); |
| 495 | } |
| 496 | |
| 497 | static bool |
| 498 | is_focus_view (struct weston_view *view) |
| 499 | { |
| 500 | return is_focus_surface (view->surface); |
| 501 | } |
| 502 | |
| 503 | static struct focus_surface * |
| 504 | create_focus_surface(struct weston_compositor *ec, |
| 505 | struct weston_output *output) |
| 506 | { |
| 507 | struct focus_surface *fsurf = NULL; |
| 508 | struct weston_surface *surface = NULL; |
| 509 | |
| 510 | fsurf = malloc(sizeof *fsurf); |
| 511 | if (!fsurf) |
| 512 | return NULL; |
| 513 | |
| 514 | fsurf->surface = weston_surface_create(ec); |
| 515 | surface = fsurf->surface; |
| 516 | if (surface == NULL) { |
| 517 | free(fsurf); |
| 518 | return NULL; |
| 519 | } |
| 520 | |
| 521 | surface->configure = focus_surface_configure; |
| 522 | surface->output = output; |
| 523 | surface->configure_private = fsurf; |
| 524 | |
| 525 | fsurf->view = weston_view_create (surface); |
Emilio Pozuelo Monfort | da64426 | 2013-11-19 11:37:19 +0100 | [diff] [blame] | 526 | fsurf->view->output = output; |
Louis-Francis Ratté-Boulianne | b482dbd | 2013-11-19 11:37:11 +0100 | [diff] [blame] | 527 | |
Jason Ekstrand | 5c11a33 | 2013-12-04 20:32:03 -0600 | [diff] [blame] | 528 | weston_surface_set_size(surface, output->width, output->height); |
Jason Ekstrand | 918f2dd | 2013-12-02 21:01:53 -0600 | [diff] [blame] | 529 | weston_view_set_position(fsurf->view, output->x, output->y); |
Louis-Francis Ratté-Boulianne | b482dbd | 2013-11-19 11:37:11 +0100 | [diff] [blame] | 530 | weston_surface_set_color(surface, 0.0, 0.0, 0.0, 1.0); |
| 531 | pixman_region32_fini(&surface->opaque); |
| 532 | pixman_region32_init_rect(&surface->opaque, output->x, output->y, |
| 533 | output->width, output->height); |
| 534 | pixman_region32_fini(&surface->input); |
| 535 | pixman_region32_init(&surface->input); |
| 536 | |
| 537 | wl_list_init(&fsurf->workspace_transform.link); |
| 538 | |
| 539 | return fsurf; |
| 540 | } |
| 541 | |
| 542 | static void |
| 543 | focus_surface_destroy(struct focus_surface *fsurf) |
| 544 | { |
| 545 | weston_surface_destroy(fsurf->surface); |
| 546 | free(fsurf); |
| 547 | } |
| 548 | |
| 549 | static void |
| 550 | focus_animation_done(struct weston_view_animation *animation, void *data) |
| 551 | { |
| 552 | struct workspace *ws = data; |
| 553 | |
| 554 | ws->focus_animation = NULL; |
| 555 | } |
| 556 | |
Jonas Ådahl | e3cddce | 2012-06-13 00:01:22 +0200 | [diff] [blame] | 557 | static void |
Jonas Ådahl | 0476974 | 2012-06-13 00:01:24 +0200 | [diff] [blame] | 558 | focus_state_destroy(struct focus_state *state) |
| 559 | { |
| 560 | wl_list_remove(&state->seat_destroy_listener.link); |
| 561 | wl_list_remove(&state->surface_destroy_listener.link); |
| 562 | free(state); |
| 563 | } |
| 564 | |
| 565 | static void |
| 566 | focus_state_seat_destroy(struct wl_listener *listener, void *data) |
| 567 | { |
| 568 | struct focus_state *state = container_of(listener, |
| 569 | struct focus_state, |
| 570 | seat_destroy_listener); |
| 571 | |
| 572 | wl_list_remove(&state->link); |
| 573 | focus_state_destroy(state); |
| 574 | } |
| 575 | |
| 576 | static void |
| 577 | focus_state_surface_destroy(struct wl_listener *listener, void *data) |
| 578 | { |
| 579 | struct focus_state *state = container_of(listener, |
| 580 | struct focus_state, |
Kristian Høgsberg | b8e0d0f | 2012-07-31 10:30:26 -0400 | [diff] [blame] | 581 | surface_destroy_listener); |
Kristian Høgsberg | e377822 | 2012-07-31 17:29:30 -0400 | [diff] [blame] | 582 | struct desktop_shell *shell; |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 583 | struct weston_surface *main_surface, *next; |
| 584 | struct weston_view *view; |
Jonas Ådahl | 0476974 | 2012-06-13 00:01:24 +0200 | [diff] [blame] | 585 | |
Pekka Paalanen | 01388e2 | 2013-04-25 13:57:44 +0300 | [diff] [blame] | 586 | main_surface = weston_surface_get_main_surface(state->keyboard_focus); |
| 587 | |
Kristian Høgsberg | e377822 | 2012-07-31 17:29:30 -0400 | [diff] [blame] | 588 | next = NULL; |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 589 | wl_list_for_each(view, &state->ws->layer.view_list, layer_link) { |
| 590 | if (view->surface == main_surface) |
Kristian Høgsberg | e377822 | 2012-07-31 17:29:30 -0400 | [diff] [blame] | 591 | continue; |
Louis-Francis Ratté-Boulianne | b482dbd | 2013-11-19 11:37:11 +0100 | [diff] [blame] | 592 | if (is_focus_view(view)) |
| 593 | continue; |
Kristian Høgsberg | e377822 | 2012-07-31 17:29:30 -0400 | [diff] [blame] | 594 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 595 | next = view->surface; |
Kristian Høgsberg | e377822 | 2012-07-31 17:29:30 -0400 | [diff] [blame] | 596 | break; |
| 597 | } |
| 598 | |
Pekka Paalanen | 01388e2 | 2013-04-25 13:57:44 +0300 | [diff] [blame] | 599 | /* if the focus was a sub-surface, activate its main surface */ |
| 600 | if (main_surface != state->keyboard_focus) |
| 601 | next = main_surface; |
| 602 | |
Louis-Francis Ratté-Boulianne | b482dbd | 2013-11-19 11:37:11 +0100 | [diff] [blame] | 603 | shell = state->seat->compositor->shell_interface.shell; |
Kristian Høgsberg | e377822 | 2012-07-31 17:29:30 -0400 | [diff] [blame] | 604 | if (next) { |
Louis-Francis Ratté-Boulianne | b482dbd | 2013-11-19 11:37:11 +0100 | [diff] [blame] | 605 | state->keyboard_focus = NULL; |
Kristian Høgsberg | e377822 | 2012-07-31 17:29:30 -0400 | [diff] [blame] | 606 | activate(shell, next, state->seat); |
| 607 | } else { |
Louis-Francis Ratté-Boulianne | b482dbd | 2013-11-19 11:37:11 +0100 | [diff] [blame] | 608 | if (shell->focus_animation_type == ANIMATION_DIM_LAYER) { |
| 609 | if (state->ws->focus_animation) |
| 610 | weston_view_animation_destroy(state->ws->focus_animation); |
| 611 | |
| 612 | state->ws->focus_animation = weston_fade_run( |
| 613 | state->ws->fsurf_front->view, |
| 614 | state->ws->fsurf_front->view->alpha, 0.0, 300, |
| 615 | focus_animation_done, state->ws); |
| 616 | } |
| 617 | |
Kristian Høgsberg | e377822 | 2012-07-31 17:29:30 -0400 | [diff] [blame] | 618 | wl_list_remove(&state->link); |
| 619 | focus_state_destroy(state); |
| 620 | } |
Jonas Ådahl | 0476974 | 2012-06-13 00:01:24 +0200 | [diff] [blame] | 621 | } |
| 622 | |
| 623 | static struct focus_state * |
Kristian Høgsberg | 2f5faff | 2012-07-31 16:36:34 -0400 | [diff] [blame] | 624 | focus_state_create(struct weston_seat *seat, struct workspace *ws) |
Jonas Ådahl | 0476974 | 2012-06-13 00:01:24 +0200 | [diff] [blame] | 625 | { |
Jonas Ådahl | 0476974 | 2012-06-13 00:01:24 +0200 | [diff] [blame] | 626 | struct focus_state *state; |
Jonas Ådahl | 0476974 | 2012-06-13 00:01:24 +0200 | [diff] [blame] | 627 | |
| 628 | state = malloc(sizeof *state); |
| 629 | if (state == NULL) |
| 630 | return NULL; |
| 631 | |
Louis-Francis Ratté-Boulianne | b482dbd | 2013-11-19 11:37:11 +0100 | [diff] [blame] | 632 | state->keyboard_focus = NULL; |
Kristian Høgsberg | 2f5faff | 2012-07-31 16:36:34 -0400 | [diff] [blame] | 633 | state->ws = ws; |
Jonas Ådahl | 0476974 | 2012-06-13 00:01:24 +0200 | [diff] [blame] | 634 | state->seat = seat; |
Kristian Høgsberg | 2f5faff | 2012-07-31 16:36:34 -0400 | [diff] [blame] | 635 | wl_list_insert(&ws->focus_list, &state->link); |
Jonas Ådahl | 0476974 | 2012-06-13 00:01:24 +0200 | [diff] [blame] | 636 | |
| 637 | state->seat_destroy_listener.notify = focus_state_seat_destroy; |
| 638 | state->surface_destroy_listener.notify = focus_state_surface_destroy; |
Kristian Høgsberg | 4912454 | 2013-05-06 22:27:40 -0400 | [diff] [blame] | 639 | wl_signal_add(&seat->destroy_signal, |
Jonas Ådahl | 0476974 | 2012-06-13 00:01:24 +0200 | [diff] [blame] | 640 | &state->seat_destroy_listener); |
Kristian Høgsberg | 2f5faff | 2012-07-31 16:36:34 -0400 | [diff] [blame] | 641 | wl_list_init(&state->surface_destroy_listener.link); |
Jonas Ådahl | 0476974 | 2012-06-13 00:01:24 +0200 | [diff] [blame] | 642 | |
| 643 | return state; |
| 644 | } |
| 645 | |
Jonas Ådahl | 8538b22 | 2012-08-29 22:13:03 +0200 | [diff] [blame] | 646 | static struct focus_state * |
| 647 | ensure_focus_state(struct desktop_shell *shell, struct weston_seat *seat) |
| 648 | { |
| 649 | struct workspace *ws = get_current_workspace(shell); |
| 650 | struct focus_state *state; |
| 651 | |
| 652 | wl_list_for_each(state, &ws->focus_list, link) |
| 653 | if (state->seat == seat) |
| 654 | break; |
| 655 | |
| 656 | if (&state->link == &ws->focus_list) |
| 657 | state = focus_state_create(seat, ws); |
| 658 | |
| 659 | return state; |
| 660 | } |
| 661 | |
Jonas Ådahl | 0476974 | 2012-06-13 00:01:24 +0200 | [diff] [blame] | 662 | static void |
Kristian Høgsberg | 2f5faff | 2012-07-31 16:36:34 -0400 | [diff] [blame] | 663 | restore_focus_state(struct desktop_shell *shell, struct workspace *ws) |
Jonas Ådahl | 0476974 | 2012-06-13 00:01:24 +0200 | [diff] [blame] | 664 | { |
| 665 | struct focus_state *state, *next; |
Kristian Høgsberg | fe7aa90 | 2013-05-08 09:54:37 -0400 | [diff] [blame] | 666 | struct weston_surface *surface; |
Jonas Ådahl | 0476974 | 2012-06-13 00:01:24 +0200 | [diff] [blame] | 667 | |
| 668 | wl_list_for_each_safe(state, next, &ws->focus_list, link) { |
Kristian Høgsberg | e61d2f4 | 2014-01-17 12:18:53 -0800 | [diff] [blame] | 669 | if (state->seat->keyboard == NULL) |
| 670 | continue; |
| 671 | |
Kristian Høgsberg | fe7aa90 | 2013-05-08 09:54:37 -0400 | [diff] [blame] | 672 | surface = state->keyboard_focus; |
Jonas Ådahl | 5689944 | 2012-08-29 22:12:59 +0200 | [diff] [blame] | 673 | |
Kristian Høgsberg | e314875 | 2013-05-06 23:19:49 -0400 | [diff] [blame] | 674 | weston_keyboard_set_focus(state->seat->keyboard, surface); |
Jonas Ådahl | 0476974 | 2012-06-13 00:01:24 +0200 | [diff] [blame] | 675 | } |
| 676 | } |
| 677 | |
| 678 | static void |
Jonas Ådahl | 8de6a1d | 2012-08-29 22:13:00 +0200 | [diff] [blame] | 679 | replace_focus_state(struct desktop_shell *shell, struct workspace *ws, |
| 680 | struct weston_seat *seat) |
| 681 | { |
| 682 | struct focus_state *state; |
Kristian Høgsberg | fe7aa90 | 2013-05-08 09:54:37 -0400 | [diff] [blame] | 683 | struct weston_surface *surface; |
Jonas Ådahl | 8de6a1d | 2012-08-29 22:13:00 +0200 | [diff] [blame] | 684 | |
| 685 | wl_list_for_each(state, &ws->focus_list, link) { |
| 686 | if (state->seat == seat) { |
Kristian Høgsberg | e314875 | 2013-05-06 23:19:49 -0400 | [diff] [blame] | 687 | surface = seat->keyboard->focus; |
Jason Ekstrand | 651f00e | 2013-06-14 10:07:54 -0500 | [diff] [blame] | 688 | state->keyboard_focus = surface; |
Jonas Ådahl | 8de6a1d | 2012-08-29 22:13:00 +0200 | [diff] [blame] | 689 | return; |
| 690 | } |
| 691 | } |
| 692 | } |
| 693 | |
| 694 | static void |
| 695 | drop_focus_state(struct desktop_shell *shell, struct workspace *ws, |
| 696 | struct weston_surface *surface) |
| 697 | { |
| 698 | struct focus_state *state; |
| 699 | |
| 700 | wl_list_for_each(state, &ws->focus_list, link) |
| 701 | if (state->keyboard_focus == surface) |
| 702 | state->keyboard_focus = NULL; |
| 703 | } |
| 704 | |
| 705 | static void |
Louis-Francis Ratté-Boulianne | b482dbd | 2013-11-19 11:37:11 +0100 | [diff] [blame] | 706 | animate_focus_change(struct desktop_shell *shell, struct workspace *ws, |
| 707 | struct weston_view *from, struct weston_view *to) |
| 708 | { |
| 709 | struct weston_output *output; |
| 710 | bool focus_surface_created = false; |
| 711 | |
| 712 | /* FIXME: Only support dim animation using two layers */ |
| 713 | if (from == to || shell->focus_animation_type != ANIMATION_DIM_LAYER) |
| 714 | return; |
| 715 | |
| 716 | output = get_default_output(shell->compositor); |
| 717 | if (ws->fsurf_front == NULL && (from || to)) { |
| 718 | ws->fsurf_front = create_focus_surface(shell->compositor, output); |
| 719 | ws->fsurf_back = create_focus_surface(shell->compositor, output); |
| 720 | ws->fsurf_front->view->alpha = 0.0; |
| 721 | ws->fsurf_back->view->alpha = 0.0; |
| 722 | focus_surface_created = true; |
| 723 | } else { |
| 724 | wl_list_remove(&ws->fsurf_front->view->layer_link); |
| 725 | wl_list_remove(&ws->fsurf_back->view->layer_link); |
| 726 | } |
| 727 | |
| 728 | if (ws->focus_animation) { |
| 729 | weston_view_animation_destroy(ws->focus_animation); |
| 730 | ws->focus_animation = NULL; |
| 731 | } |
| 732 | |
| 733 | if (to) |
| 734 | wl_list_insert(&to->layer_link, |
| 735 | &ws->fsurf_front->view->layer_link); |
| 736 | else if (from) |
| 737 | wl_list_insert(&ws->layer.view_list, |
| 738 | &ws->fsurf_front->view->layer_link); |
| 739 | |
| 740 | if (focus_surface_created) { |
| 741 | ws->focus_animation = weston_fade_run( |
| 742 | ws->fsurf_front->view, |
| 743 | ws->fsurf_front->view->alpha, 0.6, 300, |
| 744 | focus_animation_done, ws); |
| 745 | } else if (from) { |
| 746 | wl_list_insert(&from->layer_link, |
| 747 | &ws->fsurf_back->view->layer_link); |
| 748 | ws->focus_animation = weston_stable_fade_run( |
| 749 | ws->fsurf_front->view, 0.0, |
| 750 | ws->fsurf_back->view, 0.6, |
| 751 | focus_animation_done, ws); |
| 752 | } else if (to) { |
| 753 | wl_list_insert(&ws->layer.view_list, |
| 754 | &ws->fsurf_back->view->layer_link); |
| 755 | ws->focus_animation = weston_stable_fade_run( |
| 756 | ws->fsurf_front->view, 0.0, |
| 757 | ws->fsurf_back->view, 0.6, |
| 758 | focus_animation_done, ws); |
| 759 | } |
| 760 | } |
| 761 | |
| 762 | static void |
Jonas Ådahl | e3cddce | 2012-06-13 00:01:22 +0200 | [diff] [blame] | 763 | workspace_destroy(struct workspace *ws) |
| 764 | { |
Jonas Ådahl | 0476974 | 2012-06-13 00:01:24 +0200 | [diff] [blame] | 765 | struct focus_state *state, *next; |
| 766 | |
| 767 | wl_list_for_each_safe(state, next, &ws->focus_list, link) |
| 768 | focus_state_destroy(state); |
| 769 | |
Louis-Francis Ratté-Boulianne | b482dbd | 2013-11-19 11:37:11 +0100 | [diff] [blame] | 770 | if (ws->fsurf_front) |
| 771 | focus_surface_destroy(ws->fsurf_front); |
| 772 | if (ws->fsurf_back) |
| 773 | focus_surface_destroy(ws->fsurf_back); |
| 774 | |
Jonas Ådahl | e3cddce | 2012-06-13 00:01:22 +0200 | [diff] [blame] | 775 | free(ws); |
| 776 | } |
| 777 | |
Jonas Ådahl | 0476974 | 2012-06-13 00:01:24 +0200 | [diff] [blame] | 778 | static void |
| 779 | seat_destroyed(struct wl_listener *listener, void *data) |
| 780 | { |
| 781 | struct weston_seat *seat = data; |
| 782 | struct focus_state *state, *next; |
| 783 | struct workspace *ws = container_of(listener, |
| 784 | struct workspace, |
| 785 | seat_destroyed_listener); |
| 786 | |
| 787 | wl_list_for_each_safe(state, next, &ws->focus_list, link) |
| 788 | if (state->seat == seat) |
| 789 | wl_list_remove(&state->link); |
| 790 | } |
| 791 | |
Jonas Ådahl | e3cddce | 2012-06-13 00:01:22 +0200 | [diff] [blame] | 792 | static struct workspace * |
| 793 | workspace_create(void) |
| 794 | { |
| 795 | struct workspace *ws = malloc(sizeof *ws); |
| 796 | if (ws == NULL) |
| 797 | return NULL; |
| 798 | |
| 799 | weston_layer_init(&ws->layer, NULL); |
| 800 | |
Jonas Ådahl | 0476974 | 2012-06-13 00:01:24 +0200 | [diff] [blame] | 801 | wl_list_init(&ws->focus_list); |
| 802 | wl_list_init(&ws->seat_destroyed_listener.link); |
| 803 | ws->seat_destroyed_listener.notify = seat_destroyed; |
Louis-Francis Ratté-Boulianne | b482dbd | 2013-11-19 11:37:11 +0100 | [diff] [blame] | 804 | ws->fsurf_front = NULL; |
| 805 | ws->fsurf_back = NULL; |
| 806 | ws->focus_animation = NULL; |
Jonas Ådahl | 0476974 | 2012-06-13 00:01:24 +0200 | [diff] [blame] | 807 | |
Jonas Ådahl | e3cddce | 2012-06-13 00:01:22 +0200 | [diff] [blame] | 808 | return ws; |
| 809 | } |
| 810 | |
Jonas Ådahl | 62fcd04 | 2012-06-13 00:01:23 +0200 | [diff] [blame] | 811 | static int |
| 812 | workspace_is_empty(struct workspace *ws) |
| 813 | { |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 814 | return wl_list_empty(&ws->layer.view_list); |
Jonas Ådahl | 62fcd04 | 2012-06-13 00:01:23 +0200 | [diff] [blame] | 815 | } |
| 816 | |
Jonas Ådahl | e3cddce | 2012-06-13 00:01:22 +0200 | [diff] [blame] | 817 | static struct workspace * |
| 818 | get_workspace(struct desktop_shell *shell, unsigned int index) |
| 819 | { |
| 820 | struct workspace **pws = shell->workspaces.array.data; |
Philipp Brüschweiler | 067abf6 | 2012-09-01 16:03:05 +0200 | [diff] [blame] | 821 | assert(index < shell->workspaces.num); |
Jonas Ådahl | e3cddce | 2012-06-13 00:01:22 +0200 | [diff] [blame] | 822 | pws += index; |
| 823 | return *pws; |
| 824 | } |
| 825 | |
Kristian Høgsberg | 1ef2313 | 2013-12-04 00:20:01 -0800 | [diff] [blame] | 826 | struct workspace * |
Jonas Ådahl | e3cddce | 2012-06-13 00:01:22 +0200 | [diff] [blame] | 827 | get_current_workspace(struct desktop_shell *shell) |
| 828 | { |
| 829 | return get_workspace(shell, shell->workspaces.current); |
| 830 | } |
| 831 | |
| 832 | static void |
| 833 | activate_workspace(struct desktop_shell *shell, unsigned int index) |
| 834 | { |
| 835 | struct workspace *ws; |
| 836 | |
| 837 | ws = get_workspace(shell, index); |
| 838 | wl_list_insert(&shell->panel_layer.link, &ws->layer.link); |
| 839 | |
| 840 | shell->workspaces.current = index; |
| 841 | } |
| 842 | |
Jonas Ådahl | 62fcd04 | 2012-06-13 00:01:23 +0200 | [diff] [blame] | 843 | static unsigned int |
| 844 | get_output_height(struct weston_output *output) |
| 845 | { |
| 846 | return abs(output->region.extents.y1 - output->region.extents.y2); |
| 847 | } |
| 848 | |
| 849 | static void |
Louis-Francis Ratté-Boulianne | b482dbd | 2013-11-19 11:37:11 +0100 | [diff] [blame] | 850 | view_translate(struct workspace *ws, struct weston_view *view, double d) |
Jonas Ådahl | 62fcd04 | 2012-06-13 00:01:23 +0200 | [diff] [blame] | 851 | { |
Jonas Ådahl | 62fcd04 | 2012-06-13 00:01:23 +0200 | [diff] [blame] | 852 | struct weston_transform *transform; |
| 853 | |
Louis-Francis Ratté-Boulianne | b482dbd | 2013-11-19 11:37:11 +0100 | [diff] [blame] | 854 | if (is_focus_view(view)) { |
| 855 | struct focus_surface *fsurf = get_focus_surface(view->surface); |
| 856 | transform = &fsurf->workspace_transform; |
| 857 | } else { |
| 858 | struct shell_surface *shsurf = get_shell_surface(view->surface); |
| 859 | transform = &shsurf->workspace_transform; |
| 860 | } |
| 861 | |
Jonas Ådahl | 62fcd04 | 2012-06-13 00:01:23 +0200 | [diff] [blame] | 862 | if (wl_list_empty(&transform->link)) |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 863 | wl_list_insert(view->geometry.transformation_list.prev, |
Louis-Francis Ratté-Boulianne | b482dbd | 2013-11-19 11:37:11 +0100 | [diff] [blame] | 864 | &transform->link); |
Jonas Ådahl | 62fcd04 | 2012-06-13 00:01:23 +0200 | [diff] [blame] | 865 | |
Louis-Francis Ratté-Boulianne | b482dbd | 2013-11-19 11:37:11 +0100 | [diff] [blame] | 866 | weston_matrix_init(&transform->matrix); |
| 867 | weston_matrix_translate(&transform->matrix, |
Jonas Ådahl | 62fcd04 | 2012-06-13 00:01:23 +0200 | [diff] [blame] | 868 | 0.0, d, 0.0); |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 869 | weston_view_geometry_dirty(view); |
Jonas Ådahl | 62fcd04 | 2012-06-13 00:01:23 +0200 | [diff] [blame] | 870 | } |
| 871 | |
| 872 | static void |
| 873 | workspace_translate_out(struct workspace *ws, double fraction) |
| 874 | { |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 875 | struct weston_view *view; |
Jonas Ådahl | 62fcd04 | 2012-06-13 00:01:23 +0200 | [diff] [blame] | 876 | unsigned int height; |
| 877 | double d; |
| 878 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 879 | wl_list_for_each(view, &ws->layer.view_list, layer_link) { |
| 880 | height = get_output_height(view->surface->output); |
Jonas Ådahl | 62fcd04 | 2012-06-13 00:01:23 +0200 | [diff] [blame] | 881 | d = height * fraction; |
| 882 | |
Louis-Francis Ratté-Boulianne | b482dbd | 2013-11-19 11:37:11 +0100 | [diff] [blame] | 883 | view_translate(ws, view, d); |
Jonas Ådahl | 62fcd04 | 2012-06-13 00:01:23 +0200 | [diff] [blame] | 884 | } |
| 885 | } |
| 886 | |
| 887 | static void |
| 888 | workspace_translate_in(struct workspace *ws, double fraction) |
| 889 | { |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 890 | struct weston_view *view; |
Jonas Ådahl | 62fcd04 | 2012-06-13 00:01:23 +0200 | [diff] [blame] | 891 | unsigned int height; |
| 892 | double d; |
| 893 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 894 | wl_list_for_each(view, &ws->layer.view_list, layer_link) { |
| 895 | height = get_output_height(view->surface->output); |
Jonas Ådahl | 62fcd04 | 2012-06-13 00:01:23 +0200 | [diff] [blame] | 896 | |
| 897 | if (fraction > 0) |
| 898 | d = -(height - height * fraction); |
| 899 | else |
| 900 | d = height + height * fraction; |
| 901 | |
Louis-Francis Ratté-Boulianne | b482dbd | 2013-11-19 11:37:11 +0100 | [diff] [blame] | 902 | view_translate(ws, view, d); |
Jonas Ådahl | 62fcd04 | 2012-06-13 00:01:23 +0200 | [diff] [blame] | 903 | } |
| 904 | } |
| 905 | |
| 906 | static void |
Jonas Ådahl | e9d2250 | 2012-08-29 22:13:01 +0200 | [diff] [blame] | 907 | broadcast_current_workspace_state(struct desktop_shell *shell) |
| 908 | { |
Kristian Høgsberg | 2e3c396 | 2013-09-11 12:00:47 -0700 | [diff] [blame] | 909 | struct wl_resource *resource; |
Jonas Ådahl | e9d2250 | 2012-08-29 22:13:01 +0200 | [diff] [blame] | 910 | |
Kristian Høgsberg | 2e3c396 | 2013-09-11 12:00:47 -0700 | [diff] [blame] | 911 | wl_resource_for_each(resource, &shell->workspaces.client_list) |
| 912 | workspace_manager_send_state(resource, |
Jonas Ådahl | e9d2250 | 2012-08-29 22:13:01 +0200 | [diff] [blame] | 913 | shell->workspaces.current, |
| 914 | shell->workspaces.num); |
| 915 | } |
| 916 | |
| 917 | static void |
Jonas Ådahl | 62fcd04 | 2012-06-13 00:01:23 +0200 | [diff] [blame] | 918 | reverse_workspace_change_animation(struct desktop_shell *shell, |
| 919 | unsigned int index, |
| 920 | struct workspace *from, |
| 921 | struct workspace *to) |
| 922 | { |
| 923 | shell->workspaces.current = index; |
| 924 | |
| 925 | shell->workspaces.anim_to = to; |
| 926 | shell->workspaces.anim_from = from; |
| 927 | shell->workspaces.anim_dir = -1 * shell->workspaces.anim_dir; |
| 928 | shell->workspaces.anim_timestamp = 0; |
| 929 | |
Scott Moreau | 4272e63 | 2012-08-13 09:58:41 -0600 | [diff] [blame] | 930 | weston_compositor_schedule_repaint(shell->compositor); |
Jonas Ådahl | 62fcd04 | 2012-06-13 00:01:23 +0200 | [diff] [blame] | 931 | } |
| 932 | |
| 933 | static void |
| 934 | workspace_deactivate_transforms(struct workspace *ws) |
| 935 | { |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 936 | struct weston_view *view; |
Louis-Francis Ratté-Boulianne | b482dbd | 2013-11-19 11:37:11 +0100 | [diff] [blame] | 937 | struct weston_transform *transform; |
Jonas Ådahl | 62fcd04 | 2012-06-13 00:01:23 +0200 | [diff] [blame] | 938 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 939 | 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] | 940 | if (is_focus_view(view)) { |
| 941 | struct focus_surface *fsurf = get_focus_surface(view->surface); |
| 942 | transform = &fsurf->workspace_transform; |
| 943 | } else { |
| 944 | struct shell_surface *shsurf = get_shell_surface(view->surface); |
| 945 | transform = &shsurf->workspace_transform; |
| 946 | } |
| 947 | |
| 948 | if (!wl_list_empty(&transform->link)) { |
| 949 | wl_list_remove(&transform->link); |
| 950 | wl_list_init(&transform->link); |
Jonas Ådahl | 8de6a1d | 2012-08-29 22:13:00 +0200 | [diff] [blame] | 951 | } |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 952 | weston_view_geometry_dirty(view); |
Jonas Ådahl | 62fcd04 | 2012-06-13 00:01:23 +0200 | [diff] [blame] | 953 | } |
| 954 | } |
| 955 | |
| 956 | static void |
| 957 | finish_workspace_change_animation(struct desktop_shell *shell, |
| 958 | struct workspace *from, |
| 959 | struct workspace *to) |
| 960 | { |
Scott Moreau | 4272e63 | 2012-08-13 09:58:41 -0600 | [diff] [blame] | 961 | weston_compositor_schedule_repaint(shell->compositor); |
Jonas Ådahl | 62fcd04 | 2012-06-13 00:01:23 +0200 | [diff] [blame] | 962 | |
| 963 | wl_list_remove(&shell->workspaces.animation.link); |
| 964 | workspace_deactivate_transforms(from); |
| 965 | workspace_deactivate_transforms(to); |
| 966 | shell->workspaces.anim_to = NULL; |
| 967 | |
| 968 | wl_list_remove(&shell->workspaces.anim_from->layer.link); |
| 969 | } |
| 970 | |
| 971 | static void |
| 972 | animate_workspace_change_frame(struct weston_animation *animation, |
| 973 | struct weston_output *output, uint32_t msecs) |
| 974 | { |
| 975 | struct desktop_shell *shell = |
| 976 | container_of(animation, struct desktop_shell, |
| 977 | workspaces.animation); |
| 978 | struct workspace *from = shell->workspaces.anim_from; |
| 979 | struct workspace *to = shell->workspaces.anim_to; |
| 980 | uint32_t t; |
| 981 | double x, y; |
| 982 | |
| 983 | if (workspace_is_empty(from) && workspace_is_empty(to)) { |
| 984 | finish_workspace_change_animation(shell, from, to); |
| 985 | return; |
| 986 | } |
| 987 | |
| 988 | if (shell->workspaces.anim_timestamp == 0) { |
| 989 | if (shell->workspaces.anim_current == 0.0) |
| 990 | shell->workspaces.anim_timestamp = msecs; |
| 991 | else |
| 992 | shell->workspaces.anim_timestamp = |
| 993 | msecs - |
| 994 | /* Invers of movement function 'y' below. */ |
| 995 | (asin(1.0 - shell->workspaces.anim_current) * |
| 996 | DEFAULT_WORKSPACE_CHANGE_ANIMATION_LENGTH * |
| 997 | M_2_PI); |
| 998 | } |
| 999 | |
| 1000 | t = msecs - shell->workspaces.anim_timestamp; |
| 1001 | |
| 1002 | /* |
| 1003 | * x = [0, π/2] |
| 1004 | * y(x) = sin(x) |
| 1005 | */ |
| 1006 | x = t * (1.0/DEFAULT_WORKSPACE_CHANGE_ANIMATION_LENGTH) * M_PI_2; |
| 1007 | y = sin(x); |
| 1008 | |
| 1009 | if (t < DEFAULT_WORKSPACE_CHANGE_ANIMATION_LENGTH) { |
Scott Moreau | 4272e63 | 2012-08-13 09:58:41 -0600 | [diff] [blame] | 1010 | weston_compositor_schedule_repaint(shell->compositor); |
Jonas Ådahl | 62fcd04 | 2012-06-13 00:01:23 +0200 | [diff] [blame] | 1011 | |
| 1012 | workspace_translate_out(from, shell->workspaces.anim_dir * y); |
| 1013 | workspace_translate_in(to, shell->workspaces.anim_dir * y); |
| 1014 | shell->workspaces.anim_current = y; |
| 1015 | |
Scott Moreau | 4272e63 | 2012-08-13 09:58:41 -0600 | [diff] [blame] | 1016 | weston_compositor_schedule_repaint(shell->compositor); |
Jonas Ådahl | 62fcd04 | 2012-06-13 00:01:23 +0200 | [diff] [blame] | 1017 | } |
Jonas Ådahl | 0476974 | 2012-06-13 00:01:24 +0200 | [diff] [blame] | 1018 | else |
Jonas Ådahl | 62fcd04 | 2012-06-13 00:01:23 +0200 | [diff] [blame] | 1019 | finish_workspace_change_animation(shell, from, to); |
Jonas Ådahl | 62fcd04 | 2012-06-13 00:01:23 +0200 | [diff] [blame] | 1020 | } |
| 1021 | |
| 1022 | static void |
| 1023 | animate_workspace_change(struct desktop_shell *shell, |
| 1024 | unsigned int index, |
| 1025 | struct workspace *from, |
| 1026 | struct workspace *to) |
| 1027 | { |
| 1028 | struct weston_output *output; |
| 1029 | |
| 1030 | int dir; |
| 1031 | |
| 1032 | if (index > shell->workspaces.current) |
| 1033 | dir = -1; |
| 1034 | else |
| 1035 | dir = 1; |
| 1036 | |
| 1037 | shell->workspaces.current = index; |
| 1038 | |
| 1039 | shell->workspaces.anim_dir = dir; |
| 1040 | shell->workspaces.anim_from = from; |
| 1041 | shell->workspaces.anim_to = to; |
| 1042 | shell->workspaces.anim_current = 0.0; |
| 1043 | shell->workspaces.anim_timestamp = 0; |
| 1044 | |
| 1045 | output = container_of(shell->compositor->output_list.next, |
| 1046 | struct weston_output, link); |
| 1047 | wl_list_insert(&output->animation_list, |
| 1048 | &shell->workspaces.animation.link); |
| 1049 | |
Jonas Ådahl | 8de6a1d | 2012-08-29 22:13:00 +0200 | [diff] [blame] | 1050 | wl_list_insert(from->layer.link.prev, &to->layer.link); |
Jonas Ådahl | 62fcd04 | 2012-06-13 00:01:23 +0200 | [diff] [blame] | 1051 | |
| 1052 | workspace_translate_in(to, 0); |
| 1053 | |
Kristian Høgsberg | 2f5faff | 2012-07-31 16:36:34 -0400 | [diff] [blame] | 1054 | restore_focus_state(shell, to); |
Jonas Ådahl | 0476974 | 2012-06-13 00:01:24 +0200 | [diff] [blame] | 1055 | |
Scott Moreau | 4272e63 | 2012-08-13 09:58:41 -0600 | [diff] [blame] | 1056 | weston_compositor_schedule_repaint(shell->compositor); |
Jonas Ådahl | 62fcd04 | 2012-06-13 00:01:23 +0200 | [diff] [blame] | 1057 | } |
| 1058 | |
Jonas Ådahl | e3cddce | 2012-06-13 00:01:22 +0200 | [diff] [blame] | 1059 | static void |
Jonas Ådahl | 8de6a1d | 2012-08-29 22:13:00 +0200 | [diff] [blame] | 1060 | update_workspace(struct desktop_shell *shell, unsigned int index, |
| 1061 | struct workspace *from, struct workspace *to) |
| 1062 | { |
| 1063 | shell->workspaces.current = index; |
| 1064 | wl_list_insert(&from->layer.link, &to->layer.link); |
| 1065 | wl_list_remove(&from->layer.link); |
| 1066 | } |
| 1067 | |
| 1068 | static void |
Jonas Ådahl | e3cddce | 2012-06-13 00:01:22 +0200 | [diff] [blame] | 1069 | change_workspace(struct desktop_shell *shell, unsigned int index) |
| 1070 | { |
| 1071 | struct workspace *from; |
| 1072 | struct workspace *to; |
Louis-Francis Ratté-Boulianne | b482dbd | 2013-11-19 11:37:11 +0100 | [diff] [blame] | 1073 | struct focus_state *state; |
Jonas Ådahl | e3cddce | 2012-06-13 00:01:22 +0200 | [diff] [blame] | 1074 | |
| 1075 | if (index == shell->workspaces.current) |
| 1076 | return; |
| 1077 | |
| 1078 | /* Don't change workspace when there is any fullscreen surfaces. */ |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 1079 | if (!wl_list_empty(&shell->fullscreen_layer.view_list)) |
Jonas Ådahl | e3cddce | 2012-06-13 00:01:22 +0200 | [diff] [blame] | 1080 | return; |
| 1081 | |
Jonas Ådahl | e3cddce | 2012-06-13 00:01:22 +0200 | [diff] [blame] | 1082 | from = get_current_workspace(shell); |
| 1083 | to = get_workspace(shell, index); |
| 1084 | |
Jonas Ådahl | 62fcd04 | 2012-06-13 00:01:23 +0200 | [diff] [blame] | 1085 | if (shell->workspaces.anim_from == to && |
| 1086 | shell->workspaces.anim_to == from) { |
Jonas Ådahl | 8de6a1d | 2012-08-29 22:13:00 +0200 | [diff] [blame] | 1087 | restore_focus_state(shell, to); |
Jonas Ådahl | 62fcd04 | 2012-06-13 00:01:23 +0200 | [diff] [blame] | 1088 | reverse_workspace_change_animation(shell, index, from, to); |
Jonas Ådahl | e9d2250 | 2012-08-29 22:13:01 +0200 | [diff] [blame] | 1089 | broadcast_current_workspace_state(shell); |
Jonas Ådahl | 62fcd04 | 2012-06-13 00:01:23 +0200 | [diff] [blame] | 1090 | return; |
| 1091 | } |
Jonas Ådahl | e3cddce | 2012-06-13 00:01:22 +0200 | [diff] [blame] | 1092 | |
Jonas Ådahl | 62fcd04 | 2012-06-13 00:01:23 +0200 | [diff] [blame] | 1093 | if (shell->workspaces.anim_to != NULL) |
| 1094 | finish_workspace_change_animation(shell, |
| 1095 | shell->workspaces.anim_from, |
| 1096 | shell->workspaces.anim_to); |
| 1097 | |
Jonas Ådahl | 8de6a1d | 2012-08-29 22:13:00 +0200 | [diff] [blame] | 1098 | restore_focus_state(shell, to); |
Jonas Ådahl | 0476974 | 2012-06-13 00:01:24 +0200 | [diff] [blame] | 1099 | |
Louis-Francis Ratté-Boulianne | b482dbd | 2013-11-19 11:37:11 +0100 | [diff] [blame] | 1100 | if (shell->focus_animation_type != ANIMATION_NONE) { |
| 1101 | wl_list_for_each(state, &from->focus_list, link) |
| 1102 | if (state->keyboard_focus) |
| 1103 | animate_focus_change(shell, from, |
| 1104 | get_default_view(state->keyboard_focus), NULL); |
| 1105 | |
| 1106 | wl_list_for_each(state, &to->focus_list, link) |
| 1107 | if (state->keyboard_focus) |
| 1108 | animate_focus_change(shell, to, |
| 1109 | NULL, get_default_view(state->keyboard_focus)); |
| 1110 | } |
| 1111 | |
Jonas Ådahl | 8de6a1d | 2012-08-29 22:13:00 +0200 | [diff] [blame] | 1112 | if (workspace_is_empty(to) && workspace_is_empty(from)) |
| 1113 | update_workspace(shell, index, from, to); |
Jonas Ådahl | 62fcd04 | 2012-06-13 00:01:23 +0200 | [diff] [blame] | 1114 | else |
| 1115 | animate_workspace_change(shell, index, from, to); |
Jonas Ådahl | e9d2250 | 2012-08-29 22:13:01 +0200 | [diff] [blame] | 1116 | |
| 1117 | broadcast_current_workspace_state(shell); |
Pekka Paalanen | e955f1e | 2011-12-07 11:49:52 +0200 | [diff] [blame] | 1118 | } |
| 1119 | |
Jonas Ådahl | 8de6a1d | 2012-08-29 22:13:00 +0200 | [diff] [blame] | 1120 | static bool |
| 1121 | workspace_has_only(struct workspace *ws, struct weston_surface *surface) |
| 1122 | { |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 1123 | struct wl_list *list = &ws->layer.view_list; |
Jonas Ådahl | 8de6a1d | 2012-08-29 22:13:00 +0200 | [diff] [blame] | 1124 | struct wl_list *e; |
| 1125 | |
| 1126 | if (wl_list_empty(list)) |
| 1127 | return false; |
| 1128 | |
| 1129 | e = list->next; |
| 1130 | |
| 1131 | if (e->next != list) |
| 1132 | return false; |
| 1133 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 1134 | return container_of(e, struct weston_view, layer_link)->surface == surface; |
Jonas Ådahl | 8de6a1d | 2012-08-29 22:13:00 +0200 | [diff] [blame] | 1135 | } |
| 1136 | |
| 1137 | static void |
Philip Withnall | 659163d | 2013-11-25 18:01:36 +0000 | [diff] [blame] | 1138 | move_surface_to_workspace(struct desktop_shell *shell, |
| 1139 | struct shell_surface *shsurf, |
| 1140 | uint32_t workspace) |
Jonas Ådahl | e9d2250 | 2012-08-29 22:13:01 +0200 | [diff] [blame] | 1141 | { |
| 1142 | struct workspace *from; |
| 1143 | struct workspace *to; |
| 1144 | struct weston_seat *seat; |
Pekka Paalanen | 01388e2 | 2013-04-25 13:57:44 +0300 | [diff] [blame] | 1145 | struct weston_surface *focus; |
Philip Withnall | 659163d | 2013-11-25 18:01:36 +0000 | [diff] [blame] | 1146 | struct weston_view *view; |
Jonas Ådahl | e9d2250 | 2012-08-29 22:13:01 +0200 | [diff] [blame] | 1147 | |
| 1148 | if (workspace == shell->workspaces.current) |
| 1149 | return; |
| 1150 | |
Philip Withnall | 659163d | 2013-11-25 18:01:36 +0000 | [diff] [blame] | 1151 | view = get_default_view(shsurf->surface); |
| 1152 | if (!view) |
| 1153 | return; |
| 1154 | |
| 1155 | assert(weston_surface_get_main_surface(view->surface) == view->surface); |
| 1156 | |
Philipp Brüschweiler | 067abf6 | 2012-09-01 16:03:05 +0200 | [diff] [blame] | 1157 | if (workspace >= shell->workspaces.num) |
| 1158 | workspace = shell->workspaces.num - 1; |
| 1159 | |
Jonas Ådahl | e9d2250 | 2012-08-29 22:13:01 +0200 | [diff] [blame] | 1160 | from = get_current_workspace(shell); |
| 1161 | to = get_workspace(shell, workspace); |
| 1162 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 1163 | wl_list_remove(&view->layer_link); |
| 1164 | wl_list_insert(&to->layer.view_list, &view->layer_link); |
Jonas Ådahl | e9d2250 | 2012-08-29 22:13:01 +0200 | [diff] [blame] | 1165 | |
Philip Withnall | 648a4dd | 2013-11-25 18:01:44 +0000 | [diff] [blame] | 1166 | shell_surface_update_child_surface_layers(shsurf); |
| 1167 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 1168 | drop_focus_state(shell, from, view->surface); |
Pekka Paalanen | 01388e2 | 2013-04-25 13:57:44 +0300 | [diff] [blame] | 1169 | wl_list_for_each(seat, &shell->compositor->seat_list, link) { |
| 1170 | if (!seat->keyboard) |
| 1171 | continue; |
| 1172 | |
| 1173 | focus = weston_surface_get_main_surface(seat->keyboard->focus); |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 1174 | if (focus == view->surface) |
Kristian Høgsberg | e314875 | 2013-05-06 23:19:49 -0400 | [diff] [blame] | 1175 | weston_keyboard_set_focus(seat->keyboard, NULL); |
Pekka Paalanen | 01388e2 | 2013-04-25 13:57:44 +0300 | [diff] [blame] | 1176 | } |
Jonas Ådahl | e9d2250 | 2012-08-29 22:13:01 +0200 | [diff] [blame] | 1177 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 1178 | weston_view_damage_below(view); |
Jonas Ådahl | e9d2250 | 2012-08-29 22:13:01 +0200 | [diff] [blame] | 1179 | } |
| 1180 | |
| 1181 | static void |
Jonas Ådahl | 8de6a1d | 2012-08-29 22:13:00 +0200 | [diff] [blame] | 1182 | take_surface_to_workspace_by_seat(struct desktop_shell *shell, |
Kristian Høgsberg | e314875 | 2013-05-06 23:19:49 -0400 | [diff] [blame] | 1183 | struct weston_seat *seat, |
Jonas Ådahl | 8de6a1d | 2012-08-29 22:13:00 +0200 | [diff] [blame] | 1184 | unsigned int index) |
| 1185 | { |
Pekka Paalanen | 01388e2 | 2013-04-25 13:57:44 +0300 | [diff] [blame] | 1186 | struct weston_surface *surface; |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 1187 | struct weston_view *view; |
Jonas Ådahl | 8de6a1d | 2012-08-29 22:13:00 +0200 | [diff] [blame] | 1188 | struct shell_surface *shsurf; |
| 1189 | struct workspace *from; |
| 1190 | struct workspace *to; |
Jonas Ådahl | 8538b22 | 2012-08-29 22:13:03 +0200 | [diff] [blame] | 1191 | struct focus_state *state; |
Jonas Ådahl | 8de6a1d | 2012-08-29 22:13:00 +0200 | [diff] [blame] | 1192 | |
Pekka Paalanen | 01388e2 | 2013-04-25 13:57:44 +0300 | [diff] [blame] | 1193 | surface = weston_surface_get_main_surface(seat->keyboard->focus); |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 1194 | view = get_default_view(surface); |
| 1195 | if (view == NULL || |
Louis-Francis Ratté-Boulianne | b482dbd | 2013-11-19 11:37:11 +0100 | [diff] [blame] | 1196 | index == shell->workspaces.current || |
| 1197 | is_focus_view(view)) |
Jonas Ådahl | 8de6a1d | 2012-08-29 22:13:00 +0200 | [diff] [blame] | 1198 | return; |
| 1199 | |
| 1200 | from = get_current_workspace(shell); |
| 1201 | to = get_workspace(shell, index); |
| 1202 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 1203 | wl_list_remove(&view->layer_link); |
| 1204 | wl_list_insert(&to->layer.view_list, &view->layer_link); |
Jonas Ådahl | 8de6a1d | 2012-08-29 22:13:00 +0200 | [diff] [blame] | 1205 | |
Philip Withnall | 659163d | 2013-11-25 18:01:36 +0000 | [diff] [blame] | 1206 | shsurf = get_shell_surface(surface); |
Philip Withnall | 648a4dd | 2013-11-25 18:01:44 +0000 | [diff] [blame] | 1207 | if (shsurf != NULL) |
| 1208 | shell_surface_update_child_surface_layers(shsurf); |
Philip Withnall | 659163d | 2013-11-25 18:01:36 +0000 | [diff] [blame] | 1209 | |
Jonas Ådahl | e9d2250 | 2012-08-29 22:13:01 +0200 | [diff] [blame] | 1210 | replace_focus_state(shell, to, seat); |
Jonas Ådahl | 8de6a1d | 2012-08-29 22:13:00 +0200 | [diff] [blame] | 1211 | drop_focus_state(shell, from, surface); |
| 1212 | |
| 1213 | if (shell->workspaces.anim_from == to && |
| 1214 | shell->workspaces.anim_to == from) { |
Jonas Ådahl | e9d2250 | 2012-08-29 22:13:01 +0200 | [diff] [blame] | 1215 | wl_list_remove(&to->layer.link); |
| 1216 | wl_list_insert(from->layer.link.prev, &to->layer.link); |
| 1217 | |
Jonas Ådahl | 8de6a1d | 2012-08-29 22:13:00 +0200 | [diff] [blame] | 1218 | reverse_workspace_change_animation(shell, index, from, to); |
Jonas Ådahl | e9d2250 | 2012-08-29 22:13:01 +0200 | [diff] [blame] | 1219 | broadcast_current_workspace_state(shell); |
| 1220 | |
Jonas Ådahl | 8de6a1d | 2012-08-29 22:13:00 +0200 | [diff] [blame] | 1221 | return; |
| 1222 | } |
| 1223 | |
| 1224 | if (shell->workspaces.anim_to != NULL) |
| 1225 | finish_workspace_change_animation(shell, |
| 1226 | shell->workspaces.anim_from, |
| 1227 | shell->workspaces.anim_to); |
| 1228 | |
| 1229 | if (workspace_is_empty(from) && |
| 1230 | workspace_has_only(to, surface)) |
| 1231 | update_workspace(shell, index, from, to); |
| 1232 | else { |
Philip Withnall | 2c3849b | 2013-11-25 18:01:45 +0000 | [diff] [blame] | 1233 | if (shsurf != NULL && |
| 1234 | wl_list_empty(&shsurf->workspace_transform.link)) |
Jonas Ådahl | 8de6a1d | 2012-08-29 22:13:00 +0200 | [diff] [blame] | 1235 | wl_list_insert(&shell->workspaces.anim_sticky_list, |
| 1236 | &shsurf->workspace_transform.link); |
| 1237 | |
| 1238 | animate_workspace_change(shell, index, from, to); |
| 1239 | } |
Jonas Ådahl | e9d2250 | 2012-08-29 22:13:01 +0200 | [diff] [blame] | 1240 | |
| 1241 | broadcast_current_workspace_state(shell); |
Jonas Ådahl | 8538b22 | 2012-08-29 22:13:03 +0200 | [diff] [blame] | 1242 | |
| 1243 | state = ensure_focus_state(shell, seat); |
| 1244 | if (state != NULL) |
| 1245 | state->keyboard_focus = surface; |
Jonas Ådahl | e9d2250 | 2012-08-29 22:13:01 +0200 | [diff] [blame] | 1246 | } |
| 1247 | |
| 1248 | static void |
| 1249 | workspace_manager_move_surface(struct wl_client *client, |
| 1250 | struct wl_resource *resource, |
| 1251 | struct wl_resource *surface_resource, |
| 1252 | uint32_t workspace) |
| 1253 | { |
Jason Ekstrand | 651f00e | 2013-06-14 10:07:54 -0500 | [diff] [blame] | 1254 | struct desktop_shell *shell = wl_resource_get_user_data(resource); |
Jonas Ådahl | e9d2250 | 2012-08-29 22:13:01 +0200 | [diff] [blame] | 1255 | struct weston_surface *surface = |
Jason Ekstrand | 0f2ef7e | 2013-06-14 10:07:53 -0500 | [diff] [blame] | 1256 | wl_resource_get_user_data(surface_resource); |
Pekka Paalanen | 01388e2 | 2013-04-25 13:57:44 +0300 | [diff] [blame] | 1257 | struct weston_surface *main_surface; |
Philip Withnall | 659163d | 2013-11-25 18:01:36 +0000 | [diff] [blame] | 1258 | struct shell_surface *shell_surface; |
Jonas Ådahl | e9d2250 | 2012-08-29 22:13:01 +0200 | [diff] [blame] | 1259 | |
Pekka Paalanen | 01388e2 | 2013-04-25 13:57:44 +0300 | [diff] [blame] | 1260 | main_surface = weston_surface_get_main_surface(surface); |
Philip Withnall | 659163d | 2013-11-25 18:01:36 +0000 | [diff] [blame] | 1261 | shell_surface = get_shell_surface(main_surface); |
| 1262 | if (shell_surface == NULL) |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 1263 | return; |
Philip Withnall | 659163d | 2013-11-25 18:01:36 +0000 | [diff] [blame] | 1264 | |
| 1265 | move_surface_to_workspace(shell, shell_surface, workspace); |
Jonas Ådahl | e9d2250 | 2012-08-29 22:13:01 +0200 | [diff] [blame] | 1266 | } |
| 1267 | |
| 1268 | static const struct workspace_manager_interface workspace_manager_implementation = { |
| 1269 | workspace_manager_move_surface, |
| 1270 | }; |
| 1271 | |
| 1272 | static void |
| 1273 | unbind_resource(struct wl_resource *resource) |
| 1274 | { |
Jason Ekstrand | 651f00e | 2013-06-14 10:07:54 -0500 | [diff] [blame] | 1275 | wl_list_remove(wl_resource_get_link(resource)); |
Jonas Ådahl | e9d2250 | 2012-08-29 22:13:01 +0200 | [diff] [blame] | 1276 | } |
| 1277 | |
| 1278 | static void |
| 1279 | bind_workspace_manager(struct wl_client *client, |
| 1280 | void *data, uint32_t version, uint32_t id) |
| 1281 | { |
| 1282 | struct desktop_shell *shell = data; |
| 1283 | struct wl_resource *resource; |
| 1284 | |
Jason Ekstrand | a85118c | 2013-06-27 20:17:02 -0500 | [diff] [blame] | 1285 | resource = wl_resource_create(client, |
| 1286 | &workspace_manager_interface, 1, id); |
Jonas Ådahl | e9d2250 | 2012-08-29 22:13:01 +0200 | [diff] [blame] | 1287 | |
| 1288 | if (resource == NULL) { |
| 1289 | weston_log("couldn't add workspace manager object"); |
| 1290 | return; |
| 1291 | } |
| 1292 | |
Jason Ekstrand | a85118c | 2013-06-27 20:17:02 -0500 | [diff] [blame] | 1293 | wl_resource_set_implementation(resource, |
| 1294 | &workspace_manager_implementation, |
| 1295 | shell, unbind_resource); |
Jason Ekstrand | 651f00e | 2013-06-14 10:07:54 -0500 | [diff] [blame] | 1296 | wl_list_insert(&shell->workspaces.client_list, |
| 1297 | wl_resource_get_link(resource)); |
Jonas Ådahl | e9d2250 | 2012-08-29 22:13:01 +0200 | [diff] [blame] | 1298 | |
| 1299 | workspace_manager_send_state(resource, |
| 1300 | shell->workspaces.current, |
| 1301 | shell->workspaces.num); |
Jonas Ådahl | 8de6a1d | 2012-08-29 22:13:00 +0200 | [diff] [blame] | 1302 | } |
| 1303 | |
Pekka Paalanen | 56cdea9 | 2011-11-23 16:14:12 +0200 | [diff] [blame] | 1304 | static void |
Rusty Lynch | 1084da5 | 2013-08-15 09:10:08 -0700 | [diff] [blame] | 1305 | touch_move_grab_down(struct weston_touch_grab *grab, uint32_t time, |
| 1306 | int touch_id, wl_fixed_t sx, wl_fixed_t sy) |
| 1307 | { |
| 1308 | } |
| 1309 | |
| 1310 | static void |
| 1311 | touch_move_grab_up(struct weston_touch_grab *grab, uint32_t time, int touch_id) |
| 1312 | { |
Jonas Ådahl | 1c6e63e | 2013-10-25 23:18:04 +0200 | [diff] [blame] | 1313 | struct weston_touch_move_grab *move = |
| 1314 | (struct weston_touch_move_grab *) container_of( |
| 1315 | grab, struct shell_touch_grab, grab); |
Neil Roberts | e14aa4f | 2013-10-03 16:43:07 +0100 | [diff] [blame] | 1316 | |
Kristian Høgsberg | 8e80a31 | 2014-01-17 15:18:10 -0800 | [diff] [blame^] | 1317 | if (touch_id == 0) |
| 1318 | move->active = 0; |
| 1319 | |
Jonas Ådahl | 9484b69 | 2013-12-02 22:05:03 +0100 | [diff] [blame] | 1320 | if (grab->touch->num_tp == 0) { |
Jonas Ådahl | 1c6e63e | 2013-10-25 23:18:04 +0200 | [diff] [blame] | 1321 | shell_touch_grab_end(&move->base); |
| 1322 | free(move); |
| 1323 | } |
Rusty Lynch | 1084da5 | 2013-08-15 09:10:08 -0700 | [diff] [blame] | 1324 | } |
| 1325 | |
| 1326 | static void |
| 1327 | touch_move_grab_motion(struct weston_touch_grab *grab, uint32_t time, |
| 1328 | int touch_id, wl_fixed_t sx, wl_fixed_t sy) |
| 1329 | { |
| 1330 | struct weston_touch_move_grab *move = (struct weston_touch_move_grab *) grab; |
| 1331 | struct shell_surface *shsurf = move->base.shsurf; |
| 1332 | struct weston_surface *es; |
| 1333 | int dx = wl_fixed_to_int(grab->touch->grab_x + move->dx); |
| 1334 | int dy = wl_fixed_to_int(grab->touch->grab_y + move->dy); |
| 1335 | |
Kristian Høgsberg | 8e80a31 | 2014-01-17 15:18:10 -0800 | [diff] [blame^] | 1336 | if (!shsurf || !move->active) |
Rusty Lynch | 1084da5 | 2013-08-15 09:10:08 -0700 | [diff] [blame] | 1337 | return; |
| 1338 | |
| 1339 | es = shsurf->surface; |
| 1340 | |
Jason Ekstrand | 918f2dd | 2013-12-02 21:01:53 -0600 | [diff] [blame] | 1341 | weston_view_set_position(shsurf->view, dx, dy); |
Rusty Lynch | 1084da5 | 2013-08-15 09:10:08 -0700 | [diff] [blame] | 1342 | |
| 1343 | weston_compositor_schedule_repaint(es->compositor); |
| 1344 | } |
| 1345 | |
Jonas Ådahl | 1ea343e | 2013-10-25 23:18:05 +0200 | [diff] [blame] | 1346 | static void |
| 1347 | touch_move_grab_cancel(struct weston_touch_grab *grab) |
| 1348 | { |
| 1349 | struct weston_touch_move_grab *move = |
| 1350 | (struct weston_touch_move_grab *) container_of( |
| 1351 | grab, struct shell_touch_grab, grab); |
| 1352 | |
| 1353 | shell_touch_grab_end(&move->base); |
| 1354 | free(move); |
| 1355 | } |
| 1356 | |
Rusty Lynch | 1084da5 | 2013-08-15 09:10:08 -0700 | [diff] [blame] | 1357 | static const struct weston_touch_grab_interface touch_move_grab_interface = { |
| 1358 | touch_move_grab_down, |
| 1359 | touch_move_grab_up, |
| 1360 | touch_move_grab_motion, |
Jonas Ådahl | 1ea343e | 2013-10-25 23:18:05 +0200 | [diff] [blame] | 1361 | touch_move_grab_cancel, |
Rusty Lynch | 1084da5 | 2013-08-15 09:10:08 -0700 | [diff] [blame] | 1362 | }; |
| 1363 | |
| 1364 | static int |
| 1365 | surface_touch_move(struct shell_surface *shsurf, struct weston_seat *seat) |
| 1366 | { |
| 1367 | struct weston_touch_move_grab *move; |
| 1368 | |
| 1369 | if (!shsurf) |
| 1370 | return -1; |
| 1371 | |
Rafael Antognolli | 03b1659 | 2013-12-03 15:35:42 -0200 | [diff] [blame] | 1372 | if (shsurf->state.fullscreen) |
Rusty Lynch | 1084da5 | 2013-08-15 09:10:08 -0700 | [diff] [blame] | 1373 | return 0; |
Kristian Høgsberg | c85f1d4 | 2013-10-24 16:52:00 -0700 | [diff] [blame] | 1374 | if (shsurf->grabbed) |
| 1375 | return 0; |
Rusty Lynch | 1084da5 | 2013-08-15 09:10:08 -0700 | [diff] [blame] | 1376 | |
| 1377 | move = malloc(sizeof *move); |
| 1378 | if (!move) |
| 1379 | return -1; |
| 1380 | |
Kristian Høgsberg | 8e80a31 | 2014-01-17 15:18:10 -0800 | [diff] [blame^] | 1381 | move->active = 1; |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 1382 | move->dx = wl_fixed_from_double(shsurf->view->geometry.x) - |
Rusty Lynch | 1084da5 | 2013-08-15 09:10:08 -0700 | [diff] [blame] | 1383 | seat->touch->grab_x; |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 1384 | move->dy = wl_fixed_from_double(shsurf->view->geometry.y) - |
Rusty Lynch | 1084da5 | 2013-08-15 09:10:08 -0700 | [diff] [blame] | 1385 | seat->touch->grab_y; |
| 1386 | |
| 1387 | shell_touch_grab_start(&move->base, &touch_move_grab_interface, shsurf, |
| 1388 | seat->touch); |
| 1389 | |
| 1390 | return 0; |
| 1391 | } |
| 1392 | |
| 1393 | static void |
Kristian Høgsberg | 6848c25 | 2013-05-08 22:02:59 -0400 | [diff] [blame] | 1394 | noop_grab_focus(struct weston_pointer_grab *grab) |
Kristian Høgsberg | 9ddb826 | 2012-01-04 21:30:29 -0500 | [diff] [blame] | 1395 | { |
Kristian Høgsberg | 9ddb826 | 2012-01-04 21:30:29 -0500 | [diff] [blame] | 1396 | } |
| 1397 | |
| 1398 | static void |
Giulio Camuffo | 1959ab8 | 2013-11-14 23:42:52 +0100 | [diff] [blame] | 1399 | move_grab_motion(struct weston_pointer_grab *grab, uint32_t time, |
| 1400 | wl_fixed_t x, wl_fixed_t y) |
Kristian Høgsberg | 4cca349 | 2011-01-18 07:53:49 -0500 | [diff] [blame] | 1401 | { |
Kristian Høgsberg | 8334bc1 | 2012-01-03 10:29:47 -0500 | [diff] [blame] | 1402 | struct weston_move_grab *move = (struct weston_move_grab *) grab; |
Kristian Høgsberg | 02bbabb | 2013-05-06 22:15:05 -0400 | [diff] [blame] | 1403 | struct weston_pointer *pointer = grab->pointer; |
Ander Conselvan de Oliveira | fe0444a | 2012-04-04 17:48:05 +0300 | [diff] [blame] | 1404 | struct shell_surface *shsurf = move->base.shsurf; |
Giulio Camuffo | 1959ab8 | 2013-11-14 23:42:52 +0100 | [diff] [blame] | 1405 | int dx, dy; |
| 1406 | |
| 1407 | weston_pointer_move(pointer, x, y); |
| 1408 | dx = wl_fixed_to_int(pointer->x + move->dx); |
| 1409 | dy = wl_fixed_to_int(pointer->y + move->dy); |
Ander Conselvan de Oliveira | fe0444a | 2012-04-04 17:48:05 +0300 | [diff] [blame] | 1410 | |
| 1411 | if (!shsurf) |
| 1412 | return; |
| 1413 | |
Jason Ekstrand | 918f2dd | 2013-12-02 21:01:53 -0600 | [diff] [blame] | 1414 | weston_view_set_position(shsurf->view, dx, dy); |
Kristian Høgsberg | 4cca349 | 2011-01-18 07:53:49 -0500 | [diff] [blame] | 1415 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 1416 | weston_compositor_schedule_repaint(shsurf->surface->compositor); |
Kristian Høgsberg | 4cca349 | 2011-01-18 07:53:49 -0500 | [diff] [blame] | 1417 | } |
| 1418 | |
| 1419 | static void |
Kristian Høgsberg | 02bbabb | 2013-05-06 22:15:05 -0400 | [diff] [blame] | 1420 | move_grab_button(struct weston_pointer_grab *grab, |
Daniel Stone | 4dbadb1 | 2012-05-30 16:31:51 +0100 | [diff] [blame] | 1421 | uint32_t time, uint32_t button, uint32_t state_w) |
Kristian Høgsberg | 4cca349 | 2011-01-18 07:53:49 -0500 | [diff] [blame] | 1422 | { |
Ander Conselvan de Oliveira | fe0444a | 2012-04-04 17:48:05 +0300 | [diff] [blame] | 1423 | struct shell_grab *shell_grab = container_of(grab, struct shell_grab, |
| 1424 | grab); |
Kristian Høgsberg | 02bbabb | 2013-05-06 22:15:05 -0400 | [diff] [blame] | 1425 | struct weston_pointer *pointer = grab->pointer; |
Daniel Stone | 4dbadb1 | 2012-05-30 16:31:51 +0100 | [diff] [blame] | 1426 | enum wl_pointer_button_state state = state_w; |
Kristian Høgsberg | 4cca349 | 2011-01-18 07:53:49 -0500 | [diff] [blame] | 1427 | |
Daniel Stone | 4dbadb1 | 2012-05-30 16:31:51 +0100 | [diff] [blame] | 1428 | if (pointer->button_count == 0 && |
| 1429 | state == WL_POINTER_BUTTON_STATE_RELEASED) { |
Ander Conselvan de Oliveira | b9d2a0f | 2012-06-28 18:08:05 +0300 | [diff] [blame] | 1430 | shell_grab_end(shell_grab); |
Kristian Høgsberg | 9ddb826 | 2012-01-04 21:30:29 -0500 | [diff] [blame] | 1431 | free(grab); |
| 1432 | } |
Kristian Høgsberg | 4cca349 | 2011-01-18 07:53:49 -0500 | [diff] [blame] | 1433 | } |
| 1434 | |
Jonas Ådahl | 1ea343e | 2013-10-25 23:18:05 +0200 | [diff] [blame] | 1435 | static void |
| 1436 | move_grab_cancel(struct weston_pointer_grab *grab) |
| 1437 | { |
| 1438 | struct shell_grab *shell_grab = |
| 1439 | container_of(grab, struct shell_grab, grab); |
| 1440 | |
| 1441 | shell_grab_end(shell_grab); |
| 1442 | free(grab); |
| 1443 | } |
| 1444 | |
Kristian Høgsberg | 02bbabb | 2013-05-06 22:15:05 -0400 | [diff] [blame] | 1445 | static const struct weston_pointer_grab_interface move_grab_interface = { |
Kristian Høgsberg | 9ddb826 | 2012-01-04 21:30:29 -0500 | [diff] [blame] | 1446 | noop_grab_focus, |
Kristian Høgsberg | 4cca349 | 2011-01-18 07:53:49 -0500 | [diff] [blame] | 1447 | move_grab_motion, |
| 1448 | move_grab_button, |
Jonas Ådahl | 1ea343e | 2013-10-25 23:18:05 +0200 | [diff] [blame] | 1449 | move_grab_cancel, |
Kristian Høgsberg | 4cca349 | 2011-01-18 07:53:49 -0500 | [diff] [blame] | 1450 | }; |
| 1451 | |
Kristian Høgsberg | 9e31bff | 2012-08-01 00:08:07 -0400 | [diff] [blame] | 1452 | static int |
Kristian Høgsberg | e314875 | 2013-05-06 23:19:49 -0400 | [diff] [blame] | 1453 | surface_move(struct shell_surface *shsurf, struct weston_seat *seat) |
Kristian Høgsberg | 9e31bff | 2012-08-01 00:08:07 -0400 | [diff] [blame] | 1454 | { |
| 1455 | struct weston_move_grab *move; |
| 1456 | |
| 1457 | if (!shsurf) |
| 1458 | return -1; |
| 1459 | |
Kristian Høgsberg | c85f1d4 | 2013-10-24 16:52:00 -0700 | [diff] [blame] | 1460 | if (shsurf->grabbed) |
| 1461 | return 0; |
Rafael Antognolli | 03b1659 | 2013-12-03 15:35:42 -0200 | [diff] [blame] | 1462 | if (shsurf->state.fullscreen) |
Kristian Høgsberg | 9e31bff | 2012-08-01 00:08:07 -0400 | [diff] [blame] | 1463 | return 0; |
| 1464 | |
| 1465 | move = malloc(sizeof *move); |
| 1466 | if (!move) |
| 1467 | return -1; |
| 1468 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 1469 | move->dx = wl_fixed_from_double(shsurf->view->geometry.x) - |
Kristian Høgsberg | e314875 | 2013-05-06 23:19:49 -0400 | [diff] [blame] | 1470 | seat->pointer->grab_x; |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 1471 | move->dy = wl_fixed_from_double(shsurf->view->geometry.y) - |
Kristian Høgsberg | e314875 | 2013-05-06 23:19:49 -0400 | [diff] [blame] | 1472 | seat->pointer->grab_y; |
Kristian Høgsberg | 9e31bff | 2012-08-01 00:08:07 -0400 | [diff] [blame] | 1473 | |
| 1474 | shell_grab_start(&move->base, &move_grab_interface, shsurf, |
Kristian Høgsberg | e314875 | 2013-05-06 23:19:49 -0400 | [diff] [blame] | 1475 | seat->pointer, DESKTOP_SHELL_CURSOR_MOVE); |
Kristian Høgsberg | 9e31bff | 2012-08-01 00:08:07 -0400 | [diff] [blame] | 1476 | |
| 1477 | return 0; |
| 1478 | } |
| 1479 | |
| 1480 | static void |
Rafael Antognolli | e2a3455 | 2013-12-03 15:35:45 -0200 | [diff] [blame] | 1481 | common_surface_move(struct wl_resource *resource, |
| 1482 | struct wl_resource *seat_resource, uint32_t serial) |
Kristian Høgsberg | 9e31bff | 2012-08-01 00:08:07 -0400 | [diff] [blame] | 1483 | { |
Jason Ekstrand | 44a3863 | 2013-06-14 10:08:00 -0500 | [diff] [blame] | 1484 | struct weston_seat *seat = wl_resource_get_user_data(seat_resource); |
Jason Ekstrand | 651f00e | 2013-06-14 10:07:54 -0500 | [diff] [blame] | 1485 | struct shell_surface *shsurf = wl_resource_get_user_data(resource); |
Giulio Camuffo | 61da3fc | 2013-04-25 13:57:45 +0300 | [diff] [blame] | 1486 | struct weston_surface *surface; |
Kristian Høgsberg | 9e31bff | 2012-08-01 00:08:07 -0400 | [diff] [blame] | 1487 | |
Kristian Høgsberg | e1b655d | 2013-08-28 23:16:20 -0700 | [diff] [blame] | 1488 | if (seat->pointer && |
Kristian Høgsberg | 70f2901 | 2014-01-09 15:43:17 -0800 | [diff] [blame] | 1489 | seat->pointer->focus && |
Kristian Høgsberg | e1b655d | 2013-08-28 23:16:20 -0700 | [diff] [blame] | 1490 | seat->pointer->button_count > 0 && |
| 1491 | seat->pointer->grab_serial == serial) { |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 1492 | surface = weston_surface_get_main_surface(seat->pointer->focus->surface); |
Rusty Lynch | 1084da5 | 2013-08-15 09:10:08 -0700 | [diff] [blame] | 1493 | if ((surface == shsurf->surface) && |
| 1494 | (surface_move(shsurf, seat) < 0)) |
| 1495 | wl_resource_post_no_memory(resource); |
Kristian Høgsberg | e1b655d | 2013-08-28 23:16:20 -0700 | [diff] [blame] | 1496 | } else if (seat->touch && |
Kristian Høgsberg | 70f2901 | 2014-01-09 15:43:17 -0800 | [diff] [blame] | 1497 | seat->touch->focus && |
Kristian Høgsberg | e1b655d | 2013-08-28 23:16:20 -0700 | [diff] [blame] | 1498 | seat->touch->grab_serial == serial) { |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 1499 | surface = weston_surface_get_main_surface(seat->touch->focus->surface); |
Rusty Lynch | 1084da5 | 2013-08-15 09:10:08 -0700 | [diff] [blame] | 1500 | if ((surface == shsurf->surface) && |
| 1501 | (surface_touch_move(shsurf, seat) < 0)) |
| 1502 | wl_resource_post_no_memory(resource); |
| 1503 | } |
Kristian Høgsberg | 9e31bff | 2012-08-01 00:08:07 -0400 | [diff] [blame] | 1504 | } |
| 1505 | |
Rafael Antognolli | e2a3455 | 2013-12-03 15:35:45 -0200 | [diff] [blame] | 1506 | static void |
| 1507 | shell_surface_move(struct wl_client *client, struct wl_resource *resource, |
| 1508 | struct wl_resource *seat_resource, uint32_t serial) |
| 1509 | { |
| 1510 | common_surface_move(resource, seat_resource, serial); |
| 1511 | } |
| 1512 | |
Kristian Høgsberg | 9e31bff | 2012-08-01 00:08:07 -0400 | [diff] [blame] | 1513 | struct weston_resize_grab { |
| 1514 | struct shell_grab base; |
| 1515 | uint32_t edges; |
| 1516 | int32_t width, height; |
| 1517 | }; |
| 1518 | |
| 1519 | static void |
Giulio Camuffo | 1959ab8 | 2013-11-14 23:42:52 +0100 | [diff] [blame] | 1520 | resize_grab_motion(struct weston_pointer_grab *grab, uint32_t time, |
| 1521 | wl_fixed_t x, wl_fixed_t y) |
Kristian Høgsberg | 9e31bff | 2012-08-01 00:08:07 -0400 | [diff] [blame] | 1522 | { |
| 1523 | struct weston_resize_grab *resize = (struct weston_resize_grab *) grab; |
Kristian Høgsberg | 02bbabb | 2013-05-06 22:15:05 -0400 | [diff] [blame] | 1524 | struct weston_pointer *pointer = grab->pointer; |
Kristian Høgsberg | 9e31bff | 2012-08-01 00:08:07 -0400 | [diff] [blame] | 1525 | struct shell_surface *shsurf = resize->base.shsurf; |
| 1526 | int32_t width, height; |
| 1527 | wl_fixed_t from_x, from_y; |
| 1528 | wl_fixed_t to_x, to_y; |
| 1529 | |
Giulio Camuffo | 1959ab8 | 2013-11-14 23:42:52 +0100 | [diff] [blame] | 1530 | weston_pointer_move(pointer, x, y); |
| 1531 | |
Kristian Høgsberg | 9e31bff | 2012-08-01 00:08:07 -0400 | [diff] [blame] | 1532 | if (!shsurf) |
| 1533 | return; |
| 1534 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 1535 | weston_view_from_global_fixed(shsurf->view, |
| 1536 | pointer->grab_x, pointer->grab_y, |
| 1537 | &from_x, &from_y); |
| 1538 | weston_view_from_global_fixed(shsurf->view, |
| 1539 | pointer->x, pointer->y, &to_x, &to_y); |
Kristian Høgsberg | 9e31bff | 2012-08-01 00:08:07 -0400 | [diff] [blame] | 1540 | |
| 1541 | width = resize->width; |
| 1542 | if (resize->edges & WL_SHELL_SURFACE_RESIZE_LEFT) { |
| 1543 | width += wl_fixed_to_int(from_x - to_x); |
| 1544 | } else if (resize->edges & WL_SHELL_SURFACE_RESIZE_RIGHT) { |
| 1545 | width += wl_fixed_to_int(to_x - from_x); |
| 1546 | } |
| 1547 | |
| 1548 | height = resize->height; |
| 1549 | if (resize->edges & WL_SHELL_SURFACE_RESIZE_TOP) { |
| 1550 | height += wl_fixed_to_int(from_y - to_y); |
| 1551 | } else if (resize->edges & WL_SHELL_SURFACE_RESIZE_BOTTOM) { |
| 1552 | height += wl_fixed_to_int(to_y - from_y); |
| 1553 | } |
| 1554 | |
| 1555 | shsurf->client->send_configure(shsurf->surface, |
| 1556 | resize->edges, width, height); |
| 1557 | } |
| 1558 | |
| 1559 | static void |
| 1560 | send_configure(struct weston_surface *surface, |
| 1561 | uint32_t edges, int32_t width, int32_t height) |
| 1562 | { |
| 1563 | struct shell_surface *shsurf = get_shell_surface(surface); |
| 1564 | |
Jason Ekstrand | 651f00e | 2013-06-14 10:07:54 -0500 | [diff] [blame] | 1565 | wl_shell_surface_send_configure(shsurf->resource, |
Kristian Høgsberg | 9e31bff | 2012-08-01 00:08:07 -0400 | [diff] [blame] | 1566 | edges, width, height); |
| 1567 | } |
| 1568 | |
| 1569 | static const struct weston_shell_client shell_client = { |
| 1570 | send_configure |
| 1571 | }; |
| 1572 | |
| 1573 | static void |
Kristian Høgsberg | 02bbabb | 2013-05-06 22:15:05 -0400 | [diff] [blame] | 1574 | resize_grab_button(struct weston_pointer_grab *grab, |
Kristian Høgsberg | 9e31bff | 2012-08-01 00:08:07 -0400 | [diff] [blame] | 1575 | uint32_t time, uint32_t button, uint32_t state_w) |
| 1576 | { |
| 1577 | struct weston_resize_grab *resize = (struct weston_resize_grab *) grab; |
Kristian Høgsberg | 02bbabb | 2013-05-06 22:15:05 -0400 | [diff] [blame] | 1578 | struct weston_pointer *pointer = grab->pointer; |
Kristian Høgsberg | 9e31bff | 2012-08-01 00:08:07 -0400 | [diff] [blame] | 1579 | enum wl_pointer_button_state state = state_w; |
| 1580 | |
| 1581 | if (pointer->button_count == 0 && |
| 1582 | state == WL_POINTER_BUTTON_STATE_RELEASED) { |
| 1583 | shell_grab_end(&resize->base); |
| 1584 | free(grab); |
| 1585 | } |
| 1586 | } |
| 1587 | |
Jonas Ådahl | 1ea343e | 2013-10-25 23:18:05 +0200 | [diff] [blame] | 1588 | static void |
| 1589 | resize_grab_cancel(struct weston_pointer_grab *grab) |
| 1590 | { |
| 1591 | struct weston_resize_grab *resize = (struct weston_resize_grab *) grab; |
| 1592 | |
| 1593 | shell_grab_end(&resize->base); |
| 1594 | free(grab); |
| 1595 | } |
| 1596 | |
Kristian Høgsberg | 02bbabb | 2013-05-06 22:15:05 -0400 | [diff] [blame] | 1597 | static const struct weston_pointer_grab_interface resize_grab_interface = { |
Kristian Høgsberg | 9e31bff | 2012-08-01 00:08:07 -0400 | [diff] [blame] | 1598 | noop_grab_focus, |
| 1599 | resize_grab_motion, |
| 1600 | resize_grab_button, |
Jonas Ådahl | 1ea343e | 2013-10-25 23:18:05 +0200 | [diff] [blame] | 1601 | resize_grab_cancel, |
Kristian Høgsberg | 9e31bff | 2012-08-01 00:08:07 -0400 | [diff] [blame] | 1602 | }; |
| 1603 | |
Giulio Camuffo | b836664 | 2013-04-25 13:57:46 +0300 | [diff] [blame] | 1604 | /* |
| 1605 | * Returns the bounding box of a surface and all its sub-surfaces, |
| 1606 | * in the surface coordinates system. */ |
| 1607 | static void |
| 1608 | surface_subsurfaces_boundingbox(struct weston_surface *surface, int32_t *x, |
| 1609 | int32_t *y, int32_t *w, int32_t *h) { |
| 1610 | pixman_region32_t region; |
| 1611 | pixman_box32_t *box; |
| 1612 | struct weston_subsurface *subsurface; |
| 1613 | |
| 1614 | pixman_region32_init_rect(®ion, 0, 0, |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 1615 | surface->width, |
| 1616 | surface->height); |
Giulio Camuffo | b836664 | 2013-04-25 13:57:46 +0300 | [diff] [blame] | 1617 | |
| 1618 | wl_list_for_each(subsurface, &surface->subsurface_list, parent_link) { |
| 1619 | pixman_region32_union_rect(®ion, ®ion, |
| 1620 | subsurface->position.x, |
| 1621 | subsurface->position.y, |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 1622 | subsurface->surface->width, |
| 1623 | subsurface->surface->height); |
Giulio Camuffo | b836664 | 2013-04-25 13:57:46 +0300 | [diff] [blame] | 1624 | } |
| 1625 | |
| 1626 | box = pixman_region32_extents(®ion); |
| 1627 | if (x) |
| 1628 | *x = box->x1; |
| 1629 | if (y) |
| 1630 | *y = box->y1; |
| 1631 | if (w) |
| 1632 | *w = box->x2 - box->x1; |
| 1633 | if (h) |
| 1634 | *h = box->y2 - box->y1; |
| 1635 | |
| 1636 | pixman_region32_fini(®ion); |
| 1637 | } |
| 1638 | |
Kristian Høgsberg | 9e31bff | 2012-08-01 00:08:07 -0400 | [diff] [blame] | 1639 | static int |
| 1640 | surface_resize(struct shell_surface *shsurf, |
Kristian Høgsberg | e314875 | 2013-05-06 23:19:49 -0400 | [diff] [blame] | 1641 | struct weston_seat *seat, uint32_t edges) |
Kristian Høgsberg | 9e31bff | 2012-08-01 00:08:07 -0400 | [diff] [blame] | 1642 | { |
| 1643 | struct weston_resize_grab *resize; |
| 1644 | |
Rafael Antognolli | 03b1659 | 2013-12-03 15:35:42 -0200 | [diff] [blame] | 1645 | if (shsurf->state.fullscreen || shsurf->state.maximized) |
Kristian Høgsberg | 9e31bff | 2012-08-01 00:08:07 -0400 | [diff] [blame] | 1646 | return 0; |
| 1647 | |
| 1648 | if (edges == 0 || edges > 15 || |
| 1649 | (edges & 3) == 3 || (edges & 12) == 12) |
| 1650 | return 0; |
| 1651 | |
| 1652 | resize = malloc(sizeof *resize); |
| 1653 | if (!resize) |
| 1654 | return -1; |
| 1655 | |
| 1656 | resize->edges = edges; |
Giulio Camuffo | b836664 | 2013-04-25 13:57:46 +0300 | [diff] [blame] | 1657 | surface_subsurfaces_boundingbox(shsurf->surface, NULL, NULL, |
| 1658 | &resize->width, &resize->height); |
Kristian Høgsberg | 9e31bff | 2012-08-01 00:08:07 -0400 | [diff] [blame] | 1659 | |
| 1660 | shell_grab_start(&resize->base, &resize_grab_interface, shsurf, |
Kristian Høgsberg | e314875 | 2013-05-06 23:19:49 -0400 | [diff] [blame] | 1661 | seat->pointer, edges); |
Kristian Høgsberg | 9e31bff | 2012-08-01 00:08:07 -0400 | [diff] [blame] | 1662 | |
| 1663 | return 0; |
| 1664 | } |
| 1665 | |
| 1666 | static void |
Rafael Antognolli | e2a3455 | 2013-12-03 15:35:45 -0200 | [diff] [blame] | 1667 | common_surface_resize(struct wl_resource *resource, |
| 1668 | struct wl_resource *seat_resource, uint32_t serial, |
| 1669 | uint32_t edges) |
Kristian Høgsberg | 9e31bff | 2012-08-01 00:08:07 -0400 | [diff] [blame] | 1670 | { |
Jason Ekstrand | 44a3863 | 2013-06-14 10:08:00 -0500 | [diff] [blame] | 1671 | struct weston_seat *seat = wl_resource_get_user_data(seat_resource); |
Jason Ekstrand | 651f00e | 2013-06-14 10:07:54 -0500 | [diff] [blame] | 1672 | struct shell_surface *shsurf = wl_resource_get_user_data(resource); |
Giulio Camuffo | 61da3fc | 2013-04-25 13:57:45 +0300 | [diff] [blame] | 1673 | struct weston_surface *surface; |
Kristian Høgsberg | 9e31bff | 2012-08-01 00:08:07 -0400 | [diff] [blame] | 1674 | |
Rafael Antognolli | 03b1659 | 2013-12-03 15:35:42 -0200 | [diff] [blame] | 1675 | if (shsurf->state.fullscreen) |
Kristian Høgsberg | 9e31bff | 2012-08-01 00:08:07 -0400 | [diff] [blame] | 1676 | return; |
| 1677 | |
Kristian Høgsberg | e314875 | 2013-05-06 23:19:49 -0400 | [diff] [blame] | 1678 | if (seat->pointer->button_count == 0 || |
| 1679 | seat->pointer->grab_serial != serial || |
Kristian Høgsberg | 70f2901 | 2014-01-09 15:43:17 -0800 | [diff] [blame] | 1680 | seat->pointer->focus == NULL) |
| 1681 | return; |
| 1682 | |
| 1683 | surface = weston_surface_get_main_surface(seat->pointer->focus->surface); |
| 1684 | if (surface != shsurf->surface) |
Kristian Høgsberg | 9e31bff | 2012-08-01 00:08:07 -0400 | [diff] [blame] | 1685 | return; |
| 1686 | |
Kristian Høgsberg | e314875 | 2013-05-06 23:19:49 -0400 | [diff] [blame] | 1687 | if (surface_resize(shsurf, seat, edges) < 0) |
Kristian Høgsberg | 9e31bff | 2012-08-01 00:08:07 -0400 | [diff] [blame] | 1688 | wl_resource_post_no_memory(resource); |
| 1689 | } |
| 1690 | |
Scott Moreau | c3e54eb | 2012-04-17 19:06:20 -0600 | [diff] [blame] | 1691 | static void |
Rafael Antognolli | e2a3455 | 2013-12-03 15:35:45 -0200 | [diff] [blame] | 1692 | shell_surface_resize(struct wl_client *client, struct wl_resource *resource, |
| 1693 | struct wl_resource *seat_resource, uint32_t serial, |
| 1694 | uint32_t edges) |
| 1695 | { |
| 1696 | common_surface_resize(resource, seat_resource, serial, edges); |
| 1697 | } |
| 1698 | |
| 1699 | static void |
Kristian Høgsberg | 6780073 | 2013-07-04 01:12:17 -0400 | [diff] [blame] | 1700 | end_busy_cursor(struct shell_surface *shsurf, struct weston_pointer *pointer); |
| 1701 | |
| 1702 | static void |
Kristian Høgsberg | 6848c25 | 2013-05-08 22:02:59 -0400 | [diff] [blame] | 1703 | busy_cursor_grab_focus(struct weston_pointer_grab *base) |
Scott Moreau | c3e54eb | 2012-04-17 19:06:20 -0600 | [diff] [blame] | 1704 | { |
Kristian Høgsberg | d56bd90 | 2012-06-05 09:58:51 -0400 | [diff] [blame] | 1705 | struct shell_grab *grab = (struct shell_grab *) base; |
Kristian Høgsberg | 6848c25 | 2013-05-08 22:02:59 -0400 | [diff] [blame] | 1706 | struct weston_pointer *pointer = base->pointer; |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 1707 | struct weston_view *view; |
Kristian Høgsberg | 6848c25 | 2013-05-08 22:02:59 -0400 | [diff] [blame] | 1708 | wl_fixed_t sx, sy; |
| 1709 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 1710 | view = weston_compositor_pick_view(pointer->seat->compositor, |
| 1711 | pointer->x, pointer->y, |
| 1712 | &sx, &sy); |
Scott Moreau | c3e54eb | 2012-04-17 19:06:20 -0600 | [diff] [blame] | 1713 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 1714 | if (!grab->shsurf || grab->shsurf->surface != view->surface) |
Kristian Høgsberg | 6780073 | 2013-07-04 01:12:17 -0400 | [diff] [blame] | 1715 | end_busy_cursor(grab->shsurf, pointer); |
Scott Moreau | c3e54eb | 2012-04-17 19:06:20 -0600 | [diff] [blame] | 1716 | } |
| 1717 | |
| 1718 | static void |
Giulio Camuffo | 1959ab8 | 2013-11-14 23:42:52 +0100 | [diff] [blame] | 1719 | busy_cursor_grab_motion(struct weston_pointer_grab *grab, uint32_t time, |
| 1720 | wl_fixed_t x, wl_fixed_t y) |
Scott Moreau | c3e54eb | 2012-04-17 19:06:20 -0600 | [diff] [blame] | 1721 | { |
Giulio Camuffo | 1959ab8 | 2013-11-14 23:42:52 +0100 | [diff] [blame] | 1722 | weston_pointer_move(grab->pointer, x, y); |
Kristian Høgsberg | d56bd90 | 2012-06-05 09:58:51 -0400 | [diff] [blame] | 1723 | } |
Scott Moreau | c3e54eb | 2012-04-17 19:06:20 -0600 | [diff] [blame] | 1724 | |
Kristian Høgsberg | d56bd90 | 2012-06-05 09:58:51 -0400 | [diff] [blame] | 1725 | static void |
Kristian Høgsberg | 02bbabb | 2013-05-06 22:15:05 -0400 | [diff] [blame] | 1726 | busy_cursor_grab_button(struct weston_pointer_grab *base, |
Kristian Høgsberg | d56bd90 | 2012-06-05 09:58:51 -0400 | [diff] [blame] | 1727 | uint32_t time, uint32_t button, uint32_t state) |
| 1728 | { |
Kristian Høgsberg | bbe9839 | 2012-08-01 00:20:21 -0400 | [diff] [blame] | 1729 | struct shell_grab *grab = (struct shell_grab *) base; |
Kristian Høgsberg | e122b7b | 2013-05-08 16:47:00 -0400 | [diff] [blame] | 1730 | struct shell_surface *shsurf = grab->shsurf; |
Kristian Høgsberg | e314875 | 2013-05-06 23:19:49 -0400 | [diff] [blame] | 1731 | struct weston_seat *seat = grab->grab.pointer->seat; |
Kristian Høgsberg | bbe9839 | 2012-08-01 00:20:21 -0400 | [diff] [blame] | 1732 | |
Kristian Høgsberg | bbe9839 | 2012-08-01 00:20:21 -0400 | [diff] [blame] | 1733 | if (shsurf && button == BTN_LEFT && state) { |
| 1734 | activate(shsurf->shell, shsurf->surface, seat); |
| 1735 | surface_move(shsurf, seat); |
Kristian Høgsberg | 0c36903 | 2013-02-14 21:31:44 -0500 | [diff] [blame] | 1736 | } else if (shsurf && button == BTN_RIGHT && state) { |
| 1737 | activate(shsurf->shell, shsurf->surface, seat); |
Kristian Høgsberg | e314875 | 2013-05-06 23:19:49 -0400 | [diff] [blame] | 1738 | surface_rotate(shsurf, seat); |
Kristian Høgsberg | bbe9839 | 2012-08-01 00:20:21 -0400 | [diff] [blame] | 1739 | } |
Kristian Høgsberg | d56bd90 | 2012-06-05 09:58:51 -0400 | [diff] [blame] | 1740 | } |
| 1741 | |
Jonas Ådahl | 1ea343e | 2013-10-25 23:18:05 +0200 | [diff] [blame] | 1742 | static void |
| 1743 | busy_cursor_grab_cancel(struct weston_pointer_grab *base) |
| 1744 | { |
| 1745 | struct shell_grab *grab = (struct shell_grab *) base; |
| 1746 | |
| 1747 | shell_grab_end(grab); |
| 1748 | free(grab); |
| 1749 | } |
| 1750 | |
Kristian Høgsberg | 02bbabb | 2013-05-06 22:15:05 -0400 | [diff] [blame] | 1751 | static const struct weston_pointer_grab_interface busy_cursor_grab_interface = { |
Kristian Høgsberg | d56bd90 | 2012-06-05 09:58:51 -0400 | [diff] [blame] | 1752 | busy_cursor_grab_focus, |
| 1753 | busy_cursor_grab_motion, |
| 1754 | busy_cursor_grab_button, |
Jonas Ådahl | 1ea343e | 2013-10-25 23:18:05 +0200 | [diff] [blame] | 1755 | busy_cursor_grab_cancel, |
Kristian Høgsberg | d56bd90 | 2012-06-05 09:58:51 -0400 | [diff] [blame] | 1756 | }; |
| 1757 | |
| 1758 | static void |
Kristian Høgsberg | 02bbabb | 2013-05-06 22:15:05 -0400 | [diff] [blame] | 1759 | set_busy_cursor(struct shell_surface *shsurf, struct weston_pointer *pointer) |
Kristian Høgsberg | d56bd90 | 2012-06-05 09:58:51 -0400 | [diff] [blame] | 1760 | { |
| 1761 | struct shell_grab *grab; |
Kristian Høgsberg | d56bd90 | 2012-06-05 09:58:51 -0400 | [diff] [blame] | 1762 | |
| 1763 | grab = malloc(sizeof *grab); |
| 1764 | if (!grab) |
Scott Moreau | c3e54eb | 2012-04-17 19:06:20 -0600 | [diff] [blame] | 1765 | return; |
| 1766 | |
Ander Conselvan de Oliveira | b9d2a0f | 2012-06-28 18:08:05 +0300 | [diff] [blame] | 1767 | shell_grab_start(grab, &busy_cursor_grab_interface, shsurf, pointer, |
| 1768 | DESKTOP_SHELL_CURSOR_BUSY); |
Kristian Høgsberg | d56bd90 | 2012-06-05 09:58:51 -0400 | [diff] [blame] | 1769 | } |
Scott Moreau | c3e54eb | 2012-04-17 19:06:20 -0600 | [diff] [blame] | 1770 | |
Kristian Høgsberg | d56bd90 | 2012-06-05 09:58:51 -0400 | [diff] [blame] | 1771 | static void |
Kristian Høgsberg | 02bbabb | 2013-05-06 22:15:05 -0400 | [diff] [blame] | 1772 | end_busy_cursor(struct shell_surface *shsurf, struct weston_pointer *pointer) |
Kristian Høgsberg | d56bd90 | 2012-06-05 09:58:51 -0400 | [diff] [blame] | 1773 | { |
| 1774 | struct shell_grab *grab = (struct shell_grab *) pointer->grab; |
| 1775 | |
Kristian Høgsberg | e122b7b | 2013-05-08 16:47:00 -0400 | [diff] [blame] | 1776 | if (grab->grab.interface == &busy_cursor_grab_interface && |
| 1777 | grab->shsurf == shsurf) { |
Ander Conselvan de Oliveira | b9d2a0f | 2012-06-28 18:08:05 +0300 | [diff] [blame] | 1778 | shell_grab_end(grab); |
Kristian Høgsberg | d56bd90 | 2012-06-05 09:58:51 -0400 | [diff] [blame] | 1779 | free(grab); |
Scott Moreau | c3e54eb | 2012-04-17 19:06:20 -0600 | [diff] [blame] | 1780 | } |
Scott Moreau | c3e54eb | 2012-04-17 19:06:20 -0600 | [diff] [blame] | 1781 | } |
| 1782 | |
Scott Moreau | 9521d5e | 2012-04-19 13:06:17 -0600 | [diff] [blame] | 1783 | static void |
| 1784 | ping_timer_destroy(struct shell_surface *shsurf) |
| 1785 | { |
| 1786 | if (!shsurf || !shsurf->ping_timer) |
| 1787 | return; |
| 1788 | |
| 1789 | if (shsurf->ping_timer->source) |
| 1790 | wl_event_source_remove(shsurf->ping_timer->source); |
| 1791 | |
| 1792 | free(shsurf->ping_timer); |
| 1793 | shsurf->ping_timer = NULL; |
| 1794 | } |
| 1795 | |
Kristian Høgsberg | 97d44aa | 2011-08-26 17:21:20 -0400 | [diff] [blame] | 1796 | static int |
Scott Moreau | ff1db4a | 2012-04-17 19:06:18 -0600 | [diff] [blame] | 1797 | ping_timeout_handler(void *data) |
| 1798 | { |
| 1799 | struct shell_surface *shsurf = data; |
Kristian Høgsberg | d56bd90 | 2012-06-05 09:58:51 -0400 | [diff] [blame] | 1800 | struct weston_seat *seat; |
Scott Moreau | ff1db4a | 2012-04-17 19:06:18 -0600 | [diff] [blame] | 1801 | |
Scott Moreau | 9521d5e | 2012-04-19 13:06:17 -0600 | [diff] [blame] | 1802 | /* Client is not responding */ |
| 1803 | shsurf->unresponsive = 1; |
Kristian Høgsberg | d56bd90 | 2012-06-05 09:58:51 -0400 | [diff] [blame] | 1804 | |
| 1805 | wl_list_for_each(seat, &shsurf->surface->compositor->seat_list, link) |
Kristian Høgsberg | 17bccae | 2014-01-16 16:46:28 -0800 | [diff] [blame] | 1806 | if (seat->pointer->focus && |
Emilio Pozuelo Monfort | 3d0fc76 | 2013-11-22 16:21:20 +0100 | [diff] [blame] | 1807 | seat->pointer->focus->surface == shsurf->surface) |
Kristian Høgsberg | e314875 | 2013-05-06 23:19:49 -0400 | [diff] [blame] | 1808 | set_busy_cursor(shsurf, seat->pointer); |
Scott Moreau | ff1db4a | 2012-04-17 19:06:18 -0600 | [diff] [blame] | 1809 | |
| 1810 | return 1; |
| 1811 | } |
| 1812 | |
| 1813 | static void |
| 1814 | ping_handler(struct weston_surface *surface, uint32_t serial) |
| 1815 | { |
Kristian Høgsberg | b71302e | 2012-05-10 12:28:35 -0400 | [diff] [blame] | 1816 | struct shell_surface *shsurf = get_shell_surface(surface); |
Scott Moreau | ff1db4a | 2012-04-17 19:06:18 -0600 | [diff] [blame] | 1817 | struct wl_event_loop *loop; |
Kristian Høgsberg | d56bd90 | 2012-06-05 09:58:51 -0400 | [diff] [blame] | 1818 | int ping_timeout = 200; |
Scott Moreau | ff1db4a | 2012-04-17 19:06:18 -0600 | [diff] [blame] | 1819 | |
| 1820 | if (!shsurf) |
| 1821 | return; |
Jason Ekstrand | 651f00e | 2013-06-14 10:07:54 -0500 | [diff] [blame] | 1822 | if (!shsurf->resource) |
Kristian Høgsberg | ca535c1 | 2012-04-21 23:20:07 -0400 | [diff] [blame] | 1823 | return; |
Scott Moreau | ff1db4a | 2012-04-17 19:06:18 -0600 | [diff] [blame] | 1824 | |
Ander Conselvan de Oliveira | eac9a46 | 2012-07-16 14:15:48 +0300 | [diff] [blame] | 1825 | if (shsurf->surface == shsurf->shell->grab_surface) |
| 1826 | return; |
| 1827 | |
Scott Moreau | ff1db4a | 2012-04-17 19:06:18 -0600 | [diff] [blame] | 1828 | if (!shsurf->ping_timer) { |
Ander Conselvan de Oliveira | fb98089 | 2012-04-27 13:55:55 +0300 | [diff] [blame] | 1829 | shsurf->ping_timer = malloc(sizeof *shsurf->ping_timer); |
Scott Moreau | ff1db4a | 2012-04-17 19:06:18 -0600 | [diff] [blame] | 1830 | if (!shsurf->ping_timer) |
| 1831 | return; |
| 1832 | |
| 1833 | shsurf->ping_timer->serial = serial; |
Scott Moreau | ff1db4a | 2012-04-17 19:06:18 -0600 | [diff] [blame] | 1834 | loop = wl_display_get_event_loop(surface->compositor->wl_display); |
| 1835 | shsurf->ping_timer->source = |
| 1836 | wl_event_loop_add_timer(loop, ping_timeout_handler, shsurf); |
| 1837 | wl_event_source_timer_update(shsurf->ping_timer->source, ping_timeout); |
| 1838 | |
Rafael Antognolli | e2a3455 | 2013-12-03 15:35:45 -0200 | [diff] [blame] | 1839 | if (shell_surface_is_wl_shell_surface(shsurf)) |
| 1840 | wl_shell_surface_send_ping(shsurf->resource, serial); |
| 1841 | else if (shell_surface_is_xdg_surface(shsurf)) |
| 1842 | xdg_surface_send_ping(shsurf->resource, serial); |
| 1843 | else if (shell_surface_is_xdg_popup(shsurf)) |
| 1844 | xdg_popup_send_ping(shsurf->resource, serial); |
Scott Moreau | ff1db4a | 2012-04-17 19:06:18 -0600 | [diff] [blame] | 1845 | } |
| 1846 | } |
| 1847 | |
| 1848 | static void |
Kristian Høgsberg | d56bd90 | 2012-06-05 09:58:51 -0400 | [diff] [blame] | 1849 | handle_pointer_focus(struct wl_listener *listener, void *data) |
| 1850 | { |
Kristian Høgsberg | 02bbabb | 2013-05-06 22:15:05 -0400 | [diff] [blame] | 1851 | struct weston_pointer *pointer = data; |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 1852 | struct weston_view *view = pointer->focus; |
Kristian Høgsberg | d56bd90 | 2012-06-05 09:58:51 -0400 | [diff] [blame] | 1853 | struct weston_compositor *compositor; |
| 1854 | struct shell_surface *shsurf; |
| 1855 | uint32_t serial; |
| 1856 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 1857 | if (!view) |
Kristian Høgsberg | d56bd90 | 2012-06-05 09:58:51 -0400 | [diff] [blame] | 1858 | return; |
| 1859 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 1860 | compositor = view->surface->compositor; |
| 1861 | shsurf = get_shell_surface(view->surface); |
Kristian Høgsberg | d56bd90 | 2012-06-05 09:58:51 -0400 | [diff] [blame] | 1862 | |
Pekka Paalanen | 4e1f2ff | 2012-06-06 16:59:45 +0300 | [diff] [blame] | 1863 | if (shsurf && shsurf->unresponsive) { |
Kristian Høgsberg | d56bd90 | 2012-06-05 09:58:51 -0400 | [diff] [blame] | 1864 | set_busy_cursor(shsurf, pointer); |
| 1865 | } else { |
| 1866 | serial = wl_display_next_serial(compositor->wl_display); |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 1867 | ping_handler(view->surface, serial); |
Kristian Høgsberg | d56bd90 | 2012-06-05 09:58:51 -0400 | [diff] [blame] | 1868 | } |
| 1869 | } |
| 1870 | |
| 1871 | static void |
Kristian Høgsberg | f4d2f23 | 2012-08-10 10:05:39 -0400 | [diff] [blame] | 1872 | create_pointer_focus_listener(struct weston_seat *seat) |
| 1873 | { |
| 1874 | struct wl_listener *listener; |
| 1875 | |
Kristian Høgsberg | e314875 | 2013-05-06 23:19:49 -0400 | [diff] [blame] | 1876 | if (!seat->pointer) |
Kristian Høgsberg | f4d2f23 | 2012-08-10 10:05:39 -0400 | [diff] [blame] | 1877 | return; |
| 1878 | |
| 1879 | listener = malloc(sizeof *listener); |
| 1880 | listener->notify = handle_pointer_focus; |
Kristian Høgsberg | e314875 | 2013-05-06 23:19:49 -0400 | [diff] [blame] | 1881 | wl_signal_add(&seat->pointer->focus_signal, listener); |
Kristian Høgsberg | f4d2f23 | 2012-08-10 10:05:39 -0400 | [diff] [blame] | 1882 | } |
| 1883 | |
| 1884 | static void |
Rafael Antognolli | e2a3455 | 2013-12-03 15:35:45 -0200 | [diff] [blame] | 1885 | xdg_surface_set_transient_for(struct wl_client *client, |
| 1886 | struct wl_resource *resource, |
| 1887 | struct wl_resource *parent_resource) |
Scott Moreau | ff1db4a | 2012-04-17 19:06:18 -0600 | [diff] [blame] | 1888 | { |
Jason Ekstrand | 651f00e | 2013-06-14 10:07:54 -0500 | [diff] [blame] | 1889 | struct shell_surface *shsurf = wl_resource_get_user_data(resource); |
Jasper St. Pierre | 8f180d4 | 2013-12-07 13:49:28 -0500 | [diff] [blame] | 1890 | struct weston_surface *parent; |
| 1891 | |
| 1892 | if (parent_resource) |
| 1893 | parent = wl_resource_get_user_data(parent_resource); |
| 1894 | else |
| 1895 | parent = NULL; |
Rafael Antognolli | e2a3455 | 2013-12-03 15:35:45 -0200 | [diff] [blame] | 1896 | |
| 1897 | shell_surface_set_parent(shsurf, parent); |
| 1898 | } |
| 1899 | |
| 1900 | static void |
| 1901 | surface_pong(struct shell_surface *shsurf, uint32_t serial) |
| 1902 | { |
Kristian Høgsberg | d56bd90 | 2012-06-05 09:58:51 -0400 | [diff] [blame] | 1903 | struct weston_compositor *ec = shsurf->surface->compositor; |
Rafael Antognolli | e2a3455 | 2013-12-03 15:35:45 -0200 | [diff] [blame] | 1904 | struct weston_seat *seat; |
Scott Moreau | ff1db4a | 2012-04-17 19:06:18 -0600 | [diff] [blame] | 1905 | |
Kristian Høgsberg | 92374e1 | 2012-08-11 22:39:12 -0400 | [diff] [blame] | 1906 | if (shsurf->ping_timer == NULL) |
| 1907 | /* Just ignore unsolicited pong. */ |
| 1908 | return; |
| 1909 | |
Scott Moreau | ff1db4a | 2012-04-17 19:06:18 -0600 | [diff] [blame] | 1910 | if (shsurf->ping_timer->serial == serial) { |
Scott Moreau | ff1db4a | 2012-04-17 19:06:18 -0600 | [diff] [blame] | 1911 | shsurf->unresponsive = 0; |
Hardening | eb1e130 | 2013-05-17 18:07:41 +0200 | [diff] [blame] | 1912 | wl_list_for_each(seat, &ec->seat_list, link) { |
| 1913 | if(seat->pointer) |
| 1914 | end_busy_cursor(shsurf, seat->pointer); |
| 1915 | } |
Scott Moreau | 9521d5e | 2012-04-19 13:06:17 -0600 | [diff] [blame] | 1916 | ping_timer_destroy(shsurf); |
Scott Moreau | ff1db4a | 2012-04-17 19:06:18 -0600 | [diff] [blame] | 1917 | } |
| 1918 | } |
| 1919 | |
Kristian Høgsberg | e7afd91 | 2012-05-02 09:47:44 -0400 | [diff] [blame] | 1920 | static void |
Rafael Antognolli | e2a3455 | 2013-12-03 15:35:45 -0200 | [diff] [blame] | 1921 | shell_surface_pong(struct wl_client *client, struct wl_resource *resource, |
| 1922 | uint32_t serial) |
| 1923 | { |
| 1924 | struct shell_surface *shsurf = wl_resource_get_user_data(resource); |
| 1925 | |
| 1926 | surface_pong(shsurf, serial); |
| 1927 | |
| 1928 | } |
| 1929 | |
| 1930 | static void |
Giulio Camuffo | 62942ad | 2013-09-11 18:20:47 +0200 | [diff] [blame] | 1931 | set_title(struct shell_surface *shsurf, const char *title) |
| 1932 | { |
| 1933 | free(shsurf->title); |
| 1934 | shsurf->title = strdup(title); |
| 1935 | } |
| 1936 | |
| 1937 | static void |
Kristian Høgsberg | e7afd91 | 2012-05-02 09:47:44 -0400 | [diff] [blame] | 1938 | shell_surface_set_title(struct wl_client *client, |
| 1939 | struct wl_resource *resource, const char *title) |
| 1940 | { |
Jason Ekstrand | 651f00e | 2013-06-14 10:07:54 -0500 | [diff] [blame] | 1941 | struct shell_surface *shsurf = wl_resource_get_user_data(resource); |
Kristian Høgsberg | e7afd91 | 2012-05-02 09:47:44 -0400 | [diff] [blame] | 1942 | |
Giulio Camuffo | 62942ad | 2013-09-11 18:20:47 +0200 | [diff] [blame] | 1943 | set_title(shsurf, title); |
Kristian Høgsberg | e7afd91 | 2012-05-02 09:47:44 -0400 | [diff] [blame] | 1944 | } |
| 1945 | |
| 1946 | static void |
| 1947 | shell_surface_set_class(struct wl_client *client, |
| 1948 | struct wl_resource *resource, const char *class) |
| 1949 | { |
Jason Ekstrand | 651f00e | 2013-06-14 10:07:54 -0500 | [diff] [blame] | 1950 | struct shell_surface *shsurf = wl_resource_get_user_data(resource); |
Kristian Høgsberg | e7afd91 | 2012-05-02 09:47:44 -0400 | [diff] [blame] | 1951 | |
| 1952 | free(shsurf->class); |
| 1953 | shsurf->class = strdup(class); |
| 1954 | } |
| 1955 | |
Alex Wu | 4539b08 | 2012-03-01 12:57:46 +0800 | [diff] [blame] | 1956 | static void |
Alexander Larsson | f82b6ca | 2013-05-28 16:23:39 +0200 | [diff] [blame] | 1957 | restore_output_mode(struct weston_output *output) |
| 1958 | { |
Hardening | 57388e4 | 2013-09-18 23:56:36 +0200 | [diff] [blame] | 1959 | if (output->current_mode != output->original_mode || |
| 1960 | (int32_t)output->current_scale != output->original_scale) |
Alexander Larsson | f82b6ca | 2013-05-28 16:23:39 +0200 | [diff] [blame] | 1961 | weston_output_switch_mode(output, |
Hardening | 57388e4 | 2013-09-18 23:56:36 +0200 | [diff] [blame] | 1962 | output->original_mode, |
| 1963 | output->original_scale, |
| 1964 | WESTON_MODE_SWITCH_RESTORE_NATIVE); |
Alexander Larsson | f82b6ca | 2013-05-28 16:23:39 +0200 | [diff] [blame] | 1965 | } |
| 1966 | |
| 1967 | static void |
| 1968 | restore_all_output_modes(struct weston_compositor *compositor) |
| 1969 | { |
| 1970 | struct weston_output *output; |
| 1971 | |
| 1972 | wl_list_for_each(output, &compositor->output_list, link) |
| 1973 | restore_output_mode(output); |
| 1974 | } |
| 1975 | |
Philip Withnall | becb77e | 2013-11-25 18:01:30 +0000 | [diff] [blame] | 1976 | static int |
| 1977 | get_output_panel_height(struct desktop_shell *shell, |
| 1978 | struct weston_output *output) |
| 1979 | { |
| 1980 | struct weston_view *view; |
| 1981 | int panel_height = 0; |
| 1982 | |
| 1983 | if (!output) |
| 1984 | return 0; |
| 1985 | |
| 1986 | wl_list_for_each(view, &shell->panel_layer.view_list, layer_link) { |
| 1987 | if (view->surface->output == output) { |
Jason Ekstrand | 918f2dd | 2013-12-02 21:01:53 -0600 | [diff] [blame] | 1988 | panel_height = view->surface->height; |
Philip Withnall | becb77e | 2013-11-25 18:01:30 +0000 | [diff] [blame] | 1989 | break; |
| 1990 | } |
| 1991 | } |
| 1992 | |
| 1993 | return panel_height; |
| 1994 | } |
| 1995 | |
Philip Withnall | 07926d9 | 2013-11-25 18:01:40 +0000 | [diff] [blame] | 1996 | /* The surface will be inserted into the list immediately after the link |
| 1997 | * returned by this function (i.e. will be stacked immediately above the |
| 1998 | * returned link). */ |
| 1999 | static struct wl_list * |
| 2000 | shell_surface_calculate_layer_link (struct shell_surface *shsurf) |
| 2001 | { |
| 2002 | struct workspace *ws; |
Kristian Høgsberg | ead5242 | 2014-01-01 13:51:52 -0800 | [diff] [blame] | 2003 | struct weston_view *parent; |
Philip Withnall | 07926d9 | 2013-11-25 18:01:40 +0000 | [diff] [blame] | 2004 | |
| 2005 | switch (shsurf->type) { |
Kristian Høgsberg | ead5242 | 2014-01-01 13:51:52 -0800 | [diff] [blame] | 2006 | case SHELL_SURFACE_POPUP: |
| 2007 | case SHELL_SURFACE_TOPLEVEL: |
Rafael Antognolli | ed207b4 | 2013-12-03 15:35:43 -0200 | [diff] [blame] | 2008 | if (shsurf->state.fullscreen) { |
Rafael Antognolli | 03b1659 | 2013-12-03 15:35:42 -0200 | [diff] [blame] | 2009 | return &shsurf->shell->fullscreen_layer.view_list; |
Rafael Antognolli | ed207b4 | 2013-12-03 15:35:43 -0200 | [diff] [blame] | 2010 | } else if (shsurf->parent) { |
Kristian Høgsberg | d55db69 | 2014-01-01 12:26:14 -0800 | [diff] [blame] | 2011 | /* Move the surface to its parent layer so |
| 2012 | * that surfaces which are transient for |
| 2013 | * fullscreen surfaces don't get hidden by the |
| 2014 | * fullscreen surfaces. */ |
Rafael Antognolli | ed207b4 | 2013-12-03 15:35:43 -0200 | [diff] [blame] | 2015 | |
| 2016 | /* TODO: Handle a parent with multiple views */ |
| 2017 | parent = get_default_view(shsurf->parent); |
| 2018 | if (parent) |
| 2019 | return parent->layer_link.prev; |
| 2020 | } |
Rafael Antognolli | 03b1659 | 2013-12-03 15:35:42 -0200 | [diff] [blame] | 2021 | break; |
Philip Withnall | 07926d9 | 2013-11-25 18:01:40 +0000 | [diff] [blame] | 2022 | |
| 2023 | case SHELL_SURFACE_XWAYLAND: |
Kristian Høgsberg | 4804a30 | 2013-12-05 22:43:03 -0800 | [diff] [blame] | 2024 | return &shsurf->shell->fullscreen_layer.view_list; |
| 2025 | |
Philip Withnall | 07926d9 | 2013-11-25 18:01:40 +0000 | [diff] [blame] | 2026 | case SHELL_SURFACE_NONE: |
| 2027 | default: |
| 2028 | /* Go to the fallback, below. */ |
| 2029 | break; |
| 2030 | } |
| 2031 | |
| 2032 | /* Move the surface to a normal workspace layer so that surfaces |
| 2033 | * which were previously fullscreen or transient are no longer |
| 2034 | * rendered on top. */ |
| 2035 | ws = get_current_workspace(shsurf->shell); |
| 2036 | return &ws->layer.view_list; |
| 2037 | } |
| 2038 | |
Philip Withnall | 648a4dd | 2013-11-25 18:01:44 +0000 | [diff] [blame] | 2039 | static void |
| 2040 | shell_surface_update_child_surface_layers (struct shell_surface *shsurf) |
| 2041 | { |
| 2042 | struct shell_surface *child; |
| 2043 | |
| 2044 | /* Move the child layers to the same workspace as shsurf. They will be |
| 2045 | * stacked above shsurf. */ |
| 2046 | wl_list_for_each_reverse(child, &shsurf->children_list, children_link) { |
| 2047 | if (shsurf->view->layer_link.prev != &child->view->layer_link) { |
| 2048 | weston_view_geometry_dirty(child->view); |
| 2049 | wl_list_remove(&child->view->layer_link); |
| 2050 | wl_list_insert(shsurf->view->layer_link.prev, |
| 2051 | &child->view->layer_link); |
| 2052 | weston_view_geometry_dirty(child->view); |
| 2053 | weston_surface_damage(child->surface); |
| 2054 | |
| 2055 | /* Recurse. We don’t expect this to recurse very far (if |
| 2056 | * at all) because that would imply we have transient |
| 2057 | * (or popup) children of transient surfaces, which |
| 2058 | * would be unusual. */ |
| 2059 | shell_surface_update_child_surface_layers(child); |
| 2060 | } |
| 2061 | } |
| 2062 | } |
| 2063 | |
Philip Withnall | e1d75ae | 2013-11-25 18:01:41 +0000 | [diff] [blame] | 2064 | /* 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] | 2065 | * geometry to ensure the changes are redrawn. |
| 2066 | * |
| 2067 | * If any child surfaces exist and are mapped, ensure they’re in the same layer |
| 2068 | * as this surface. */ |
Philip Withnall | e1d75ae | 2013-11-25 18:01:41 +0000 | [diff] [blame] | 2069 | static void |
| 2070 | shell_surface_update_layer(struct shell_surface *shsurf) |
| 2071 | { |
| 2072 | struct wl_list *new_layer_link; |
| 2073 | |
| 2074 | new_layer_link = shell_surface_calculate_layer_link(shsurf); |
| 2075 | |
| 2076 | if (new_layer_link == &shsurf->view->layer_link) |
| 2077 | return; |
| 2078 | |
| 2079 | weston_view_geometry_dirty(shsurf->view); |
| 2080 | wl_list_remove(&shsurf->view->layer_link); |
| 2081 | wl_list_insert(new_layer_link, &shsurf->view->layer_link); |
| 2082 | weston_view_geometry_dirty(shsurf->view); |
| 2083 | weston_surface_damage(shsurf->surface); |
Philip Withnall | 648a4dd | 2013-11-25 18:01:44 +0000 | [diff] [blame] | 2084 | |
| 2085 | shell_surface_update_child_surface_layers(shsurf); |
Philip Withnall | e1d75ae | 2013-11-25 18:01:41 +0000 | [diff] [blame] | 2086 | } |
| 2087 | |
Alexander Larsson | f82b6ca | 2013-05-28 16:23:39 +0200 | [diff] [blame] | 2088 | static void |
Philip Withnall | dc4332f | 2013-11-25 18:01:38 +0000 | [diff] [blame] | 2089 | shell_surface_set_parent(struct shell_surface *shsurf, |
| 2090 | struct weston_surface *parent) |
| 2091 | { |
| 2092 | shsurf->parent = parent; |
Philip Withnall | 648a4dd | 2013-11-25 18:01:44 +0000 | [diff] [blame] | 2093 | |
| 2094 | wl_list_remove(&shsurf->children_link); |
| 2095 | wl_list_init(&shsurf->children_link); |
| 2096 | |
| 2097 | /* Insert into the parent surface’s child list. */ |
| 2098 | if (parent != NULL) { |
| 2099 | struct shell_surface *parent_shsurf = get_shell_surface(parent); |
| 2100 | if (parent_shsurf != NULL) |
| 2101 | wl_list_insert(&parent_shsurf->children_list, |
| 2102 | &shsurf->children_link); |
| 2103 | } |
Philip Withnall | dc4332f | 2013-11-25 18:01:38 +0000 | [diff] [blame] | 2104 | } |
| 2105 | |
| 2106 | static void |
Philip Withnall | 352e7ed | 2013-11-25 18:01:35 +0000 | [diff] [blame] | 2107 | shell_surface_set_output(struct shell_surface *shsurf, |
| 2108 | struct weston_output *output) |
| 2109 | { |
| 2110 | struct weston_surface *es = shsurf->surface; |
| 2111 | |
| 2112 | /* get the default output, if the client set it as NULL |
| 2113 | check whether the ouput is available */ |
| 2114 | if (output) |
| 2115 | shsurf->output = output; |
| 2116 | else if (es->output) |
| 2117 | shsurf->output = es->output; |
| 2118 | else |
| 2119 | shsurf->output = get_default_output(es->compositor); |
| 2120 | } |
| 2121 | |
| 2122 | static void |
Rafael Antognolli | 03b1659 | 2013-12-03 15:35:42 -0200 | [diff] [blame] | 2123 | surface_clear_next_states(struct shell_surface *shsurf) |
| 2124 | { |
| 2125 | shsurf->next_state.maximized = false; |
| 2126 | shsurf->next_state.fullscreen = false; |
| 2127 | |
| 2128 | if ((shsurf->next_state.maximized != shsurf->state.maximized) || |
| 2129 | (shsurf->next_state.fullscreen != shsurf->state.fullscreen)) |
| 2130 | shsurf->state_changed = true; |
| 2131 | } |
| 2132 | |
| 2133 | static void |
Philip Withnall | becb77e | 2013-11-25 18:01:30 +0000 | [diff] [blame] | 2134 | set_toplevel(struct shell_surface *shsurf) |
| 2135 | { |
Kristian Høgsberg | 41fbf6f | 2013-12-05 22:31:25 -0800 | [diff] [blame] | 2136 | shell_surface_set_parent(shsurf, NULL); |
| 2137 | surface_clear_next_states(shsurf); |
Kristian Høgsberg | c8f8dd8 | 2013-12-05 23:20:33 -0800 | [diff] [blame] | 2138 | shsurf->type = SHELL_SURFACE_TOPLEVEL; |
Philip Withnall | 648a4dd | 2013-11-25 18:01:44 +0000 | [diff] [blame] | 2139 | |
| 2140 | /* The layer_link is updated in set_surface_type(), |
| 2141 | * called from configure. */ |
Philip Withnall | becb77e | 2013-11-25 18:01:30 +0000 | [diff] [blame] | 2142 | } |
| 2143 | |
| 2144 | static void |
| 2145 | shell_surface_set_toplevel(struct wl_client *client, |
| 2146 | struct wl_resource *resource) |
| 2147 | { |
| 2148 | struct shell_surface *surface = wl_resource_get_user_data(resource); |
| 2149 | |
| 2150 | set_toplevel(surface); |
| 2151 | } |
| 2152 | |
| 2153 | static void |
| 2154 | set_transient(struct shell_surface *shsurf, |
| 2155 | struct weston_surface *parent, int x, int y, uint32_t flags) |
| 2156 | { |
Philip Withnall | dc4332f | 2013-11-25 18:01:38 +0000 | [diff] [blame] | 2157 | assert(parent != NULL); |
| 2158 | |
Kristian Høgsberg | 9f7e331 | 2014-01-02 22:40:37 -0800 | [diff] [blame] | 2159 | shell_surface_set_parent(shsurf, parent); |
| 2160 | |
| 2161 | surface_clear_next_states(shsurf); |
| 2162 | |
Philip Withnall | becb77e | 2013-11-25 18:01:30 +0000 | [diff] [blame] | 2163 | shsurf->transient.x = x; |
| 2164 | shsurf->transient.y = y; |
| 2165 | shsurf->transient.flags = flags; |
Philip Withnall | dc4332f | 2013-11-25 18:01:38 +0000 | [diff] [blame] | 2166 | |
Rafael Antognolli | ed207b4 | 2013-12-03 15:35:43 -0200 | [diff] [blame] | 2167 | shsurf->next_state.relative = true; |
Kristian Høgsberg | a1df7ac | 2013-12-31 15:01:01 -0800 | [diff] [blame] | 2168 | shsurf->state_changed = true; |
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_transient(struct wl_client *client, |
| 2177 | struct wl_resource *resource, |
| 2178 | struct wl_resource *parent_resource, |
| 2179 | int x, int y, uint32_t flags) |
| 2180 | { |
| 2181 | struct shell_surface *shsurf = wl_resource_get_user_data(resource); |
| 2182 | struct weston_surface *parent = |
| 2183 | wl_resource_get_user_data(parent_resource); |
| 2184 | |
| 2185 | set_transient(shsurf, parent, x, y, flags); |
| 2186 | } |
| 2187 | |
| 2188 | static void |
| 2189 | set_fullscreen(struct shell_surface *shsurf, |
| 2190 | uint32_t method, |
| 2191 | uint32_t framerate, |
| 2192 | struct weston_output *output) |
| 2193 | { |
Philip Withnall | 352e7ed | 2013-11-25 18:01:35 +0000 | [diff] [blame] | 2194 | shell_surface_set_output(shsurf, output); |
Philip Withnall | becb77e | 2013-11-25 18:01:30 +0000 | [diff] [blame] | 2195 | |
| 2196 | shsurf->fullscreen_output = shsurf->output; |
| 2197 | shsurf->fullscreen.type = method; |
| 2198 | shsurf->fullscreen.framerate = framerate; |
Philip Withnall | dc4332f | 2013-11-25 18:01:38 +0000 | [diff] [blame] | 2199 | |
Kristian Høgsberg | e960b3f | 2013-12-05 22:04:42 -0800 | [diff] [blame] | 2200 | shsurf->next_state.fullscreen = true; |
| 2201 | shsurf->state_changed = true; |
Kristian Høgsberg | c8f8dd8 | 2013-12-05 23:20:33 -0800 | [diff] [blame] | 2202 | shsurf->type = SHELL_SURFACE_TOPLEVEL; |
Philip Withnall | becb77e | 2013-11-25 18:01:30 +0000 | [diff] [blame] | 2203 | |
| 2204 | shsurf->client->send_configure(shsurf->surface, 0, |
| 2205 | shsurf->output->width, |
| 2206 | shsurf->output->height); |
Philip Withnall | 648a4dd | 2013-11-25 18:01:44 +0000 | [diff] [blame] | 2207 | |
| 2208 | /* The layer_link is updated in set_surface_type(), |
| 2209 | * called from configure. */ |
Philip Withnall | becb77e | 2013-11-25 18:01:30 +0000 | [diff] [blame] | 2210 | } |
| 2211 | |
| 2212 | static void |
Zhang, Xiong Y | 3123693 | 2013-12-13 22:10:57 +0200 | [diff] [blame] | 2213 | weston_view_set_initial_position(struct weston_view *view, |
| 2214 | struct desktop_shell *shell); |
| 2215 | |
| 2216 | static void |
Philip Withnall | becb77e | 2013-11-25 18:01:30 +0000 | [diff] [blame] | 2217 | unset_fullscreen(struct shell_surface *shsurf) |
Alex Wu | 4539b08 | 2012-03-01 12:57:46 +0800 | [diff] [blame] | 2218 | { |
Philip Withnall | f85fe84 | 2013-11-25 18:01:37 +0000 | [diff] [blame] | 2219 | /* Unset the fullscreen output, driver configuration and transforms. */ |
Alex Wu | bd3354b | 2012-04-17 17:20:49 +0800 | [diff] [blame] | 2220 | if (shsurf->fullscreen.type == WL_SHELL_SURFACE_FULLSCREEN_METHOD_DRIVER && |
| 2221 | shell_surface_is_top_fullscreen(shsurf)) { |
Alexander Larsson | f82b6ca | 2013-05-28 16:23:39 +0200 | [diff] [blame] | 2222 | restore_output_mode(shsurf->fullscreen_output); |
Alex Wu | bd3354b | 2012-04-17 17:20:49 +0800 | [diff] [blame] | 2223 | } |
Philip Withnall | f85fe84 | 2013-11-25 18:01:37 +0000 | [diff] [blame] | 2224 | shsurf->fullscreen_output = NULL; |
| 2225 | |
Alex Wu | 4539b08 | 2012-03-01 12:57:46 +0800 | [diff] [blame] | 2226 | shsurf->fullscreen.type = WL_SHELL_SURFACE_FULLSCREEN_METHOD_DEFAULT; |
| 2227 | shsurf->fullscreen.framerate = 0; |
Philip Withnall | f85fe84 | 2013-11-25 18:01:37 +0000 | [diff] [blame] | 2228 | |
Alex Wu | 4539b08 | 2012-03-01 12:57:46 +0800 | [diff] [blame] | 2229 | wl_list_remove(&shsurf->fullscreen.transform.link); |
| 2230 | wl_list_init(&shsurf->fullscreen.transform.link); |
Philip Withnall | f85fe84 | 2013-11-25 18:01:37 +0000 | [diff] [blame] | 2231 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 2232 | if (shsurf->fullscreen.black_view) |
| 2233 | weston_surface_destroy(shsurf->fullscreen.black_view->surface); |
| 2234 | shsurf->fullscreen.black_view = NULL; |
Philip Withnall | f85fe84 | 2013-11-25 18:01:37 +0000 | [diff] [blame] | 2235 | |
Zhang, Xiong Y | 3123693 | 2013-12-13 22:10:57 +0200 | [diff] [blame] | 2236 | if (shsurf->saved_position_valid) |
| 2237 | weston_view_set_position(shsurf->view, |
| 2238 | shsurf->saved_x, shsurf->saved_y); |
| 2239 | else |
| 2240 | weston_view_set_initial_position(shsurf->view, shsurf->shell); |
| 2241 | |
Alex Wu | 7bcb8bd | 2012-04-27 09:07:24 +0800 | [diff] [blame] | 2242 | if (shsurf->saved_rotation_valid) { |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 2243 | wl_list_insert(&shsurf->view->geometry.transformation_list, |
Philip Withnall | becb77e | 2013-11-25 18:01:30 +0000 | [diff] [blame] | 2244 | &shsurf->rotation.transform.link); |
Alex Wu | 7bcb8bd | 2012-04-27 09:07:24 +0800 | [diff] [blame] | 2245 | shsurf->saved_rotation_valid = false; |
| 2246 | } |
Rafal Mielniczuk | 3e3862c | 2012-10-07 20:25:36 +0200 | [diff] [blame] | 2247 | |
Philip Withnall | e1d75ae | 2013-11-25 18:01:41 +0000 | [diff] [blame] | 2248 | /* Layer is updated in set_surface_type(). */ |
Alex Wu | 4539b08 | 2012-03-01 12:57:46 +0800 | [diff] [blame] | 2249 | } |
| 2250 | |
Rafal Mielniczuk | fffdcdd | 2013-03-11 19:26:54 +0100 | [diff] [blame] | 2251 | static void |
Philip Withnall | becb77e | 2013-11-25 18:01:30 +0000 | [diff] [blame] | 2252 | shell_surface_set_fullscreen(struct wl_client *client, |
| 2253 | struct wl_resource *resource, |
| 2254 | uint32_t method, |
| 2255 | uint32_t framerate, |
| 2256 | struct wl_resource *output_resource) |
| 2257 | { |
| 2258 | struct shell_surface *shsurf = wl_resource_get_user_data(resource); |
| 2259 | struct weston_output *output; |
| 2260 | |
| 2261 | if (output_resource) |
| 2262 | output = wl_resource_get_user_data(output_resource); |
| 2263 | else |
| 2264 | output = NULL; |
| 2265 | |
Rafael Antognolli | 4b99a40 | 2013-12-03 15:35:44 -0200 | [diff] [blame] | 2266 | shell_surface_set_parent(shsurf, NULL); |
| 2267 | |
Rafael Antognolli | 03b1659 | 2013-12-03 15:35:42 -0200 | [diff] [blame] | 2268 | surface_clear_next_states(shsurf); |
Philip Withnall | becb77e | 2013-11-25 18:01:30 +0000 | [diff] [blame] | 2269 | set_fullscreen(shsurf, method, framerate, output); |
| 2270 | } |
| 2271 | |
| 2272 | static void |
| 2273 | set_popup(struct shell_surface *shsurf, |
| 2274 | struct weston_surface *parent, |
| 2275 | struct weston_seat *seat, |
| 2276 | uint32_t serial, |
| 2277 | int32_t x, |
| 2278 | int32_t y) |
| 2279 | { |
Philip Withnall | dc4332f | 2013-11-25 18:01:38 +0000 | [diff] [blame] | 2280 | assert(parent != NULL); |
| 2281 | |
Philip Withnall | becb77e | 2013-11-25 18:01:30 +0000 | [diff] [blame] | 2282 | shsurf->popup.shseat = get_shell_seat(seat); |
| 2283 | shsurf->popup.serial = serial; |
| 2284 | shsurf->popup.x = x; |
| 2285 | shsurf->popup.y = y; |
Philip Withnall | dc4332f | 2013-11-25 18:01:38 +0000 | [diff] [blame] | 2286 | |
Kristian Høgsberg | c8f8dd8 | 2013-12-05 23:20:33 -0800 | [diff] [blame] | 2287 | shsurf->type = SHELL_SURFACE_POPUP; |
Philip Withnall | becb77e | 2013-11-25 18:01:30 +0000 | [diff] [blame] | 2288 | } |
| 2289 | |
| 2290 | static void |
| 2291 | shell_surface_set_popup(struct wl_client *client, |
| 2292 | struct wl_resource *resource, |
| 2293 | struct wl_resource *seat_resource, |
| 2294 | uint32_t serial, |
| 2295 | struct wl_resource *parent_resource, |
| 2296 | int32_t x, int32_t y, uint32_t flags) |
| 2297 | { |
| 2298 | struct shell_surface *shsurf = wl_resource_get_user_data(resource); |
Rafael Antognolli | 4b99a40 | 2013-12-03 15:35:44 -0200 | [diff] [blame] | 2299 | struct weston_surface *parent = |
| 2300 | wl_resource_get_user_data(parent_resource); |
| 2301 | |
| 2302 | shell_surface_set_parent(shsurf, parent); |
Philip Withnall | becb77e | 2013-11-25 18:01:30 +0000 | [diff] [blame] | 2303 | |
Rafael Antognolli | 03b1659 | 2013-12-03 15:35:42 -0200 | [diff] [blame] | 2304 | surface_clear_next_states(shsurf); |
Philip Withnall | becb77e | 2013-11-25 18:01:30 +0000 | [diff] [blame] | 2305 | set_popup(shsurf, |
Rafael Antognolli | 4b99a40 | 2013-12-03 15:35:44 -0200 | [diff] [blame] | 2306 | parent, |
Philip Withnall | becb77e | 2013-11-25 18:01:30 +0000 | [diff] [blame] | 2307 | wl_resource_get_user_data(seat_resource), |
| 2308 | serial, x, y); |
| 2309 | } |
| 2310 | |
| 2311 | static void |
| 2312 | set_maximized(struct shell_surface *shsurf, |
| 2313 | struct weston_output *output) |
| 2314 | { |
| 2315 | struct desktop_shell *shell; |
| 2316 | uint32_t edges = 0, panel_height = 0; |
Philip Withnall | becb77e | 2013-11-25 18:01:30 +0000 | [diff] [blame] | 2317 | |
Philip Withnall | 352e7ed | 2013-11-25 18:01:35 +0000 | [diff] [blame] | 2318 | shell_surface_set_output(shsurf, output); |
Philip Withnall | becb77e | 2013-11-25 18:01:30 +0000 | [diff] [blame] | 2319 | |
| 2320 | shell = shell_surface_get_shell(shsurf); |
| 2321 | panel_height = get_output_panel_height(shell, shsurf->output); |
| 2322 | edges = WL_SHELL_SURFACE_RESIZE_TOP | WL_SHELL_SURFACE_RESIZE_LEFT; |
| 2323 | |
| 2324 | shsurf->client->send_configure(shsurf->surface, edges, |
| 2325 | shsurf->output->width, |
| 2326 | shsurf->output->height - panel_height); |
| 2327 | |
Kristian Høgsberg | c2745b1 | 2013-12-05 22:00:40 -0800 | [diff] [blame] | 2328 | shsurf->next_state.maximized = true; |
| 2329 | shsurf->state_changed = true; |
Kristian Høgsberg | c8f8dd8 | 2013-12-05 23:20:33 -0800 | [diff] [blame] | 2330 | shsurf->type = SHELL_SURFACE_TOPLEVEL; |
Philip Withnall | becb77e | 2013-11-25 18:01:30 +0000 | [diff] [blame] | 2331 | } |
| 2332 | |
| 2333 | static void |
| 2334 | unset_maximized(struct shell_surface *shsurf) |
Rafal Mielniczuk | fffdcdd | 2013-03-11 19:26:54 +0100 | [diff] [blame] | 2335 | { |
Rafal Mielniczuk | fffdcdd | 2013-03-11 19:26:54 +0100 | [diff] [blame] | 2336 | /* undo all maximized things here */ |
| 2337 | shsurf->output = get_default_output(shsurf->surface->compositor); |
Zhang, Xiong Y | 3123693 | 2013-12-13 22:10:57 +0200 | [diff] [blame] | 2338 | |
| 2339 | if (shsurf->saved_position_valid) |
| 2340 | weston_view_set_position(shsurf->view, |
| 2341 | shsurf->saved_x, shsurf->saved_y); |
| 2342 | else |
| 2343 | weston_view_set_initial_position(shsurf->view, shsurf->shell); |
Rafal Mielniczuk | fffdcdd | 2013-03-11 19:26:54 +0100 | [diff] [blame] | 2344 | |
| 2345 | if (shsurf->saved_rotation_valid) { |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 2346 | wl_list_insert(&shsurf->view->geometry.transformation_list, |
| 2347 | &shsurf->rotation.transform.link); |
Rafal Mielniczuk | fffdcdd | 2013-03-11 19:26:54 +0100 | [diff] [blame] | 2348 | shsurf->saved_rotation_valid = false; |
| 2349 | } |
| 2350 | |
Philip Withnall | e1d75ae | 2013-11-25 18:01:41 +0000 | [diff] [blame] | 2351 | /* Layer is updated in set_surface_type(). */ |
Rafal Mielniczuk | fffdcdd | 2013-03-11 19:26:54 +0100 | [diff] [blame] | 2352 | } |
| 2353 | |
Philip Withnall | becb77e | 2013-11-25 18:01:30 +0000 | [diff] [blame] | 2354 | static void |
| 2355 | shell_surface_set_maximized(struct wl_client *client, |
| 2356 | struct wl_resource *resource, |
| 2357 | struct wl_resource *output_resource) |
| 2358 | { |
| 2359 | struct shell_surface *shsurf = wl_resource_get_user_data(resource); |
| 2360 | struct weston_output *output; |
| 2361 | |
| 2362 | if (output_resource) |
| 2363 | output = wl_resource_get_user_data(output_resource); |
| 2364 | else |
| 2365 | output = NULL; |
| 2366 | |
Rafael Antognolli | 4b99a40 | 2013-12-03 15:35:44 -0200 | [diff] [blame] | 2367 | shell_surface_set_parent(shsurf, NULL); |
| 2368 | |
Rafael Antognolli | 03b1659 | 2013-12-03 15:35:42 -0200 | [diff] [blame] | 2369 | surface_clear_next_states(shsurf); |
Philip Withnall | becb77e | 2013-11-25 18:01:30 +0000 | [diff] [blame] | 2370 | set_maximized(shsurf, output); |
| 2371 | } |
| 2372 | |
Philip Withnall | e1d75ae | 2013-11-25 18:01:41 +0000 | [diff] [blame] | 2373 | /* This is only ever called from set_surface_type(), so there’s no need to |
| 2374 | * update layer_links here, since they’ll be updated when we return. */ |
Pekka Paalanen | 9826223 | 2011-12-01 10:42:22 +0200 | [diff] [blame] | 2375 | static int |
Philip Withnall | becb77e | 2013-11-25 18:01:30 +0000 | [diff] [blame] | 2376 | reset_surface_type(struct shell_surface *surface) |
Pekka Paalanen | 9826223 | 2011-12-01 10:42:22 +0200 | [diff] [blame] | 2377 | { |
Rafael Antognolli | 03b1659 | 2013-12-03 15:35:42 -0200 | [diff] [blame] | 2378 | if (surface->state.fullscreen) |
Philip Withnall | becb77e | 2013-11-25 18:01:30 +0000 | [diff] [blame] | 2379 | unset_fullscreen(surface); |
Rafael Antognolli | 03b1659 | 2013-12-03 15:35:42 -0200 | [diff] [blame] | 2380 | if (surface->state.maximized) |
Philip Withnall | becb77e | 2013-11-25 18:01:30 +0000 | [diff] [blame] | 2381 | unset_maximized(surface); |
Pekka Paalanen | 9826223 | 2011-12-01 10:42:22 +0200 | [diff] [blame] | 2382 | |
Pekka Paalanen | 9826223 | 2011-12-01 10:42:22 +0200 | [diff] [blame] | 2383 | return 0; |
| 2384 | } |
| 2385 | |
Kristian Høgsberg | 4cca349 | 2011-01-18 07:53:49 -0500 | [diff] [blame] | 2386 | static void |
Rafael Antognolli | 03b1659 | 2013-12-03 15:35:42 -0200 | [diff] [blame] | 2387 | set_full_output(struct shell_surface *shsurf) |
| 2388 | { |
| 2389 | shsurf->saved_x = shsurf->view->geometry.x; |
| 2390 | shsurf->saved_y = shsurf->view->geometry.y; |
Rafael Antognolli | 3c4e3f7 | 2013-12-03 15:35:46 -0200 | [diff] [blame] | 2391 | shsurf->saved_width = shsurf->surface->width; |
| 2392 | shsurf->saved_height = shsurf->surface->height; |
| 2393 | shsurf->saved_size_valid = true; |
Rafael Antognolli | 03b1659 | 2013-12-03 15:35:42 -0200 | [diff] [blame] | 2394 | shsurf->saved_position_valid = true; |
| 2395 | |
| 2396 | if (!wl_list_empty(&shsurf->rotation.transform.link)) { |
| 2397 | wl_list_remove(&shsurf->rotation.transform.link); |
| 2398 | wl_list_init(&shsurf->rotation.transform.link); |
| 2399 | weston_view_geometry_dirty(shsurf->view); |
| 2400 | shsurf->saved_rotation_valid = true; |
| 2401 | } |
| 2402 | } |
| 2403 | |
| 2404 | static void |
Kristian Høgsberg | 7f366e7 | 2012-04-27 17:20:01 -0400 | [diff] [blame] | 2405 | set_surface_type(struct shell_surface *shsurf) |
| 2406 | { |
Kristian Høgsberg | 8150b19 | 2012-06-27 10:22:58 -0400 | [diff] [blame] | 2407 | struct weston_surface *pes = shsurf->parent; |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 2408 | struct weston_view *pev = get_default_view(pes); |
Kristian Høgsberg | 7f366e7 | 2012-04-27 17:20:01 -0400 | [diff] [blame] | 2409 | |
Philip Withnall | becb77e | 2013-11-25 18:01:30 +0000 | [diff] [blame] | 2410 | reset_surface_type(shsurf); |
Kristian Høgsberg | 7f366e7 | 2012-04-27 17:20:01 -0400 | [diff] [blame] | 2411 | |
Rafael Antognolli | 03b1659 | 2013-12-03 15:35:42 -0200 | [diff] [blame] | 2412 | shsurf->state = shsurf->next_state; |
Rafael Antognolli | 03b1659 | 2013-12-03 15:35:42 -0200 | [diff] [blame] | 2413 | shsurf->state_changed = false; |
Kristian Høgsberg | 7f366e7 | 2012-04-27 17:20:01 -0400 | [diff] [blame] | 2414 | |
| 2415 | switch (shsurf->type) { |
| 2416 | case SHELL_SURFACE_TOPLEVEL: |
Rafael Antognolli | ed207b4 | 2013-12-03 15:35:43 -0200 | [diff] [blame] | 2417 | if (shsurf->state.maximized || shsurf->state.fullscreen) { |
Rafael Antognolli | 03b1659 | 2013-12-03 15:35:42 -0200 | [diff] [blame] | 2418 | set_full_output(shsurf); |
Rafael Antognolli | ed207b4 | 2013-12-03 15:35:43 -0200 | [diff] [blame] | 2419 | } else if (shsurf->state.relative && pev) { |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 2420 | weston_view_set_position(shsurf->view, |
| 2421 | pev->geometry.x + shsurf->transient.x, |
| 2422 | pev->geometry.y + shsurf->transient.y); |
Rafael Antognolli | ed207b4 | 2013-12-03 15:35:43 -0200 | [diff] [blame] | 2423 | } |
Rafael Antognolli | 44a3162 | 2013-12-04 18:37:16 -0200 | [diff] [blame] | 2424 | break; |
Kristian Høgsberg | 7f366e7 | 2012-04-27 17:20:01 -0400 | [diff] [blame] | 2425 | |
Tiago Vignatti | fb2adba | 2013-06-12 15:43:21 -0300 | [diff] [blame] | 2426 | case SHELL_SURFACE_XWAYLAND: |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 2427 | weston_view_set_position(shsurf->view, shsurf->transient.x, |
| 2428 | shsurf->transient.y); |
Tiago Vignatti | fb2adba | 2013-06-12 15:43:21 -0300 | [diff] [blame] | 2429 | break; |
| 2430 | |
Philip Withnall | 0f640e2 | 2013-11-25 18:01:31 +0000 | [diff] [blame] | 2431 | case SHELL_SURFACE_POPUP: |
| 2432 | case SHELL_SURFACE_NONE: |
Kristian Høgsberg | 7f366e7 | 2012-04-27 17:20:01 -0400 | [diff] [blame] | 2433 | default: |
| 2434 | break; |
| 2435 | } |
Philip Withnall | e1d75ae | 2013-11-25 18:01:41 +0000 | [diff] [blame] | 2436 | |
| 2437 | /* Update the surface’s layer. */ |
| 2438 | shell_surface_update_layer(shsurf); |
Kristian Høgsberg | 7f366e7 | 2012-04-27 17:20:01 -0400 | [diff] [blame] | 2439 | } |
| 2440 | |
Tiago Vignatti | be14326 | 2012-04-16 17:31:41 +0300 | [diff] [blame] | 2441 | static struct desktop_shell * |
Juan Zhao | 96879df | 2012-02-07 08:45:41 +0800 | [diff] [blame] | 2442 | shell_surface_get_shell(struct shell_surface *shsurf) |
Pekka Paalanen | af0e34c | 2011-12-02 10:59:17 +0200 | [diff] [blame] | 2443 | { |
Kristian Høgsberg | 02e79dc | 2012-04-12 09:55:26 -0400 | [diff] [blame] | 2444 | return shsurf->shell; |
Juan Zhao | 96879df | 2012-02-07 08:45:41 +0800 | [diff] [blame] | 2445 | } |
| 2446 | |
Alex Wu | 2185843 | 2012-04-01 20:13:08 +0800 | [diff] [blame] | 2447 | static void |
Jason Ekstrand | 918f2dd | 2013-12-02 21:01:53 -0600 | [diff] [blame] | 2448 | 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] | 2449 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 2450 | static struct weston_view * |
Alex Wu | 4539b08 | 2012-03-01 12:57:46 +0800 | [diff] [blame] | 2451 | create_black_surface(struct weston_compositor *ec, |
Alex Wu | 2185843 | 2012-04-01 20:13:08 +0800 | [diff] [blame] | 2452 | struct weston_surface *fs_surface, |
John Kåre Alsaker | 490d02a | 2012-09-30 02:57:21 +0200 | [diff] [blame] | 2453 | float x, float y, int w, int h) |
Alex Wu | 4539b08 | 2012-03-01 12:57:46 +0800 | [diff] [blame] | 2454 | { |
| 2455 | struct weston_surface *surface = NULL; |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 2456 | struct weston_view *view; |
Alex Wu | 4539b08 | 2012-03-01 12:57:46 +0800 | [diff] [blame] | 2457 | |
| 2458 | surface = weston_surface_create(ec); |
| 2459 | if (surface == NULL) { |
Martin Minarik | 6d11836 | 2012-06-07 18:01:59 +0200 | [diff] [blame] | 2460 | weston_log("no memory\n"); |
Alex Wu | 4539b08 | 2012-03-01 12:57:46 +0800 | [diff] [blame] | 2461 | return NULL; |
| 2462 | } |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 2463 | view = weston_view_create(surface); |
| 2464 | if (surface == NULL) { |
| 2465 | weston_log("no memory\n"); |
| 2466 | weston_surface_destroy(surface); |
| 2467 | return NULL; |
| 2468 | } |
Alex Wu | 4539b08 | 2012-03-01 12:57:46 +0800 | [diff] [blame] | 2469 | |
Alex Wu | 2185843 | 2012-04-01 20:13:08 +0800 | [diff] [blame] | 2470 | surface->configure = black_surface_configure; |
Giulio Camuffo | 7fe01b1 | 2013-03-28 18:02:42 +0100 | [diff] [blame] | 2471 | surface->configure_private = fs_surface; |
Alex Wu | 4539b08 | 2012-03-01 12:57:46 +0800 | [diff] [blame] | 2472 | weston_surface_set_color(surface, 0.0, 0.0, 0.0, 1); |
Pekka Paalanen | 71f6f3b | 2012-10-10 12:49:26 +0300 | [diff] [blame] | 2473 | pixman_region32_fini(&surface->opaque); |
Kristian Høgsberg | 61f00f5 | 2012-08-03 16:31:36 -0400 | [diff] [blame] | 2474 | pixman_region32_init_rect(&surface->opaque, 0, 0, w, h); |
Jonas Ådahl | 33619a4 | 2013-01-15 21:25:55 +0100 | [diff] [blame] | 2475 | pixman_region32_fini(&surface->input); |
| 2476 | pixman_region32_init_rect(&surface->input, 0, 0, w, h); |
Jason Ekstrand | 918f2dd | 2013-12-02 21:01:53 -0600 | [diff] [blame] | 2477 | |
Jason Ekstrand | 6228ee2 | 2014-01-01 15:58:57 -0600 | [diff] [blame] | 2478 | weston_surface_set_size(surface, w, h); |
Jason Ekstrand | 918f2dd | 2013-12-02 21:01:53 -0600 | [diff] [blame] | 2479 | weston_view_set_position(view, x, y); |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 2480 | |
| 2481 | return view; |
Alex Wu | 4539b08 | 2012-03-01 12:57:46 +0800 | [diff] [blame] | 2482 | } |
| 2483 | |
Philip Withnall | ed8f1a9 | 2013-11-25 18:01:43 +0000 | [diff] [blame] | 2484 | static void |
| 2485 | shell_ensure_fullscreen_black_view(struct shell_surface *shsurf) |
| 2486 | { |
| 2487 | struct weston_output *output = shsurf->fullscreen_output; |
| 2488 | |
Rafael Antognolli | 03b1659 | 2013-12-03 15:35:42 -0200 | [diff] [blame] | 2489 | assert(shsurf->state.fullscreen); |
Philip Withnall | ed8f1a9 | 2013-11-25 18:01:43 +0000 | [diff] [blame] | 2490 | |
| 2491 | if (!shsurf->fullscreen.black_view) |
| 2492 | shsurf->fullscreen.black_view = |
| 2493 | create_black_surface(shsurf->surface->compositor, |
| 2494 | shsurf->surface, |
| 2495 | output->x, output->y, |
| 2496 | output->width, |
| 2497 | output->height); |
| 2498 | |
| 2499 | weston_view_geometry_dirty(shsurf->fullscreen.black_view); |
| 2500 | wl_list_remove(&shsurf->fullscreen.black_view->layer_link); |
| 2501 | wl_list_insert(&shsurf->view->layer_link, |
| 2502 | &shsurf->fullscreen.black_view->layer_link); |
| 2503 | weston_view_geometry_dirty(shsurf->fullscreen.black_view); |
| 2504 | weston_surface_damage(shsurf->surface); |
| 2505 | } |
| 2506 | |
Alex Wu | 4539b08 | 2012-03-01 12:57:46 +0800 | [diff] [blame] | 2507 | /* Create black surface and append it to the associated fullscreen surface. |
| 2508 | * Handle size dismatch and positioning according to the method. */ |
| 2509 | static void |
| 2510 | shell_configure_fullscreen(struct shell_surface *shsurf) |
| 2511 | { |
| 2512 | struct weston_output *output = shsurf->fullscreen_output; |
| 2513 | struct weston_surface *surface = shsurf->surface; |
| 2514 | struct weston_matrix *matrix; |
Kristian Høgsberg | 240dfeb | 2012-07-12 12:32:31 -0400 | [diff] [blame] | 2515 | float scale, output_aspect, surface_aspect, x, y; |
Giulio Camuffo | b836664 | 2013-04-25 13:57:46 +0300 | [diff] [blame] | 2516 | int32_t surf_x, surf_y, surf_width, surf_height; |
Alex Wu | 4539b08 | 2012-03-01 12:57:46 +0800 | [diff] [blame] | 2517 | |
Alexander Larsson | f82b6ca | 2013-05-28 16:23:39 +0200 | [diff] [blame] | 2518 | if (shsurf->fullscreen.type != WL_SHELL_SURFACE_FULLSCREEN_METHOD_DRIVER) |
| 2519 | restore_output_mode(output); |
| 2520 | |
Philip Withnall | ed8f1a9 | 2013-11-25 18:01:43 +0000 | [diff] [blame] | 2521 | shell_ensure_fullscreen_black_view(shsurf); |
Alex Wu | 4539b08 | 2012-03-01 12:57:46 +0800 | [diff] [blame] | 2522 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 2523 | surface_subsurfaces_boundingbox(shsurf->surface, &surf_x, &surf_y, |
Giulio Camuffo | b836664 | 2013-04-25 13:57:46 +0300 | [diff] [blame] | 2524 | &surf_width, &surf_height); |
| 2525 | |
Alex Wu | 4539b08 | 2012-03-01 12:57:46 +0800 | [diff] [blame] | 2526 | switch (shsurf->fullscreen.type) { |
| 2527 | case WL_SHELL_SURFACE_FULLSCREEN_METHOD_DEFAULT: |
Pekka Paalanen | de685b8 | 2012-12-04 15:58:12 +0200 | [diff] [blame] | 2528 | if (surface->buffer_ref.buffer) |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 2529 | center_on_output(shsurf->view, shsurf->fullscreen_output); |
Alex Wu | 4539b08 | 2012-03-01 12:57:46 +0800 | [diff] [blame] | 2530 | break; |
| 2531 | case WL_SHELL_SURFACE_FULLSCREEN_METHOD_SCALE: |
Rob Bradford | 9f3dd15 | 2013-02-12 11:53:47 +0000 | [diff] [blame] | 2532 | /* 1:1 mapping between surface and output dimensions */ |
Giulio Camuffo | b836664 | 2013-04-25 13:57:46 +0300 | [diff] [blame] | 2533 | if (output->width == surf_width && |
| 2534 | output->height == surf_height) { |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 2535 | weston_view_set_position(shsurf->view, |
| 2536 | output->x - surf_x, |
| 2537 | output->y - surf_y); |
Rob Bradford | 9f3dd15 | 2013-02-12 11:53:47 +0000 | [diff] [blame] | 2538 | break; |
| 2539 | } |
| 2540 | |
Alex Wu | 4539b08 | 2012-03-01 12:57:46 +0800 | [diff] [blame] | 2541 | matrix = &shsurf->fullscreen.transform.matrix; |
| 2542 | weston_matrix_init(matrix); |
Kristian Høgsberg | 240dfeb | 2012-07-12 12:32:31 -0400 | [diff] [blame] | 2543 | |
Scott Moreau | 1bad5db | 2012-08-18 01:04:05 -0600 | [diff] [blame] | 2544 | output_aspect = (float) output->width / |
| 2545 | (float) output->height; |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 2546 | /* XXX: Use surf_width and surf_height here? */ |
| 2547 | surface_aspect = (float) surface->width / |
| 2548 | (float) surface->height; |
Kristian Høgsberg | 240dfeb | 2012-07-12 12:32:31 -0400 | [diff] [blame] | 2549 | if (output_aspect < surface_aspect) |
Scott Moreau | 1bad5db | 2012-08-18 01:04:05 -0600 | [diff] [blame] | 2550 | scale = (float) output->width / |
Giulio Camuffo | b836664 | 2013-04-25 13:57:46 +0300 | [diff] [blame] | 2551 | (float) surf_width; |
Kristian Høgsberg | 240dfeb | 2012-07-12 12:32:31 -0400 | [diff] [blame] | 2552 | else |
Scott Moreau | 1bad5db | 2012-08-18 01:04:05 -0600 | [diff] [blame] | 2553 | scale = (float) output->height / |
Giulio Camuffo | b836664 | 2013-04-25 13:57:46 +0300 | [diff] [blame] | 2554 | (float) surf_height; |
Kristian Høgsberg | 240dfeb | 2012-07-12 12:32:31 -0400 | [diff] [blame] | 2555 | |
Alex Wu | 4539b08 | 2012-03-01 12:57:46 +0800 | [diff] [blame] | 2556 | weston_matrix_scale(matrix, scale, scale, 1); |
| 2557 | wl_list_remove(&shsurf->fullscreen.transform.link); |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 2558 | wl_list_insert(&shsurf->view->geometry.transformation_list, |
Alex Wu | 4539b08 | 2012-03-01 12:57:46 +0800 | [diff] [blame] | 2559 | &shsurf->fullscreen.transform.link); |
Giulio Camuffo | b836664 | 2013-04-25 13:57:46 +0300 | [diff] [blame] | 2560 | x = output->x + (output->width - surf_width * scale) / 2 - surf_x; |
| 2561 | y = output->y + (output->height - surf_height * scale) / 2 - surf_y; |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 2562 | weston_view_set_position(shsurf->view, x, y); |
Kristian Høgsberg | 240dfeb | 2012-07-12 12:32:31 -0400 | [diff] [blame] | 2563 | |
Alex Wu | 4539b08 | 2012-03-01 12:57:46 +0800 | [diff] [blame] | 2564 | break; |
| 2565 | case WL_SHELL_SURFACE_FULLSCREEN_METHOD_DRIVER: |
Alex Wu | bd3354b | 2012-04-17 17:20:49 +0800 | [diff] [blame] | 2566 | if (shell_surface_is_top_fullscreen(shsurf)) { |
Quentin Glidic | c0d79ce | 2013-01-29 14:16:13 +0100 | [diff] [blame] | 2567 | struct weston_mode mode = {0, |
Pekka Paalanen | 1fd9c0f | 2013-11-26 18:19:41 +0100 | [diff] [blame] | 2568 | surf_width * surface->buffer_viewport.scale, |
| 2569 | surf_height * surface->buffer_viewport.scale, |
Alex Wu | bd3354b | 2012-04-17 17:20:49 +0800 | [diff] [blame] | 2570 | shsurf->fullscreen.framerate}; |
| 2571 | |
Pekka Paalanen | 1fd9c0f | 2013-11-26 18:19:41 +0100 | [diff] [blame] | 2572 | if (weston_output_switch_mode(output, &mode, surface->buffer_viewport.scale, |
Hardening | 57388e4 | 2013-09-18 23:56:36 +0200 | [diff] [blame] | 2573 | WESTON_MODE_SWITCH_SET_TEMPORARY) == 0) { |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 2574 | weston_view_set_position(shsurf->view, |
| 2575 | output->x - surf_x, |
| 2576 | output->y - surf_y); |
Jason Ekstrand | 918f2dd | 2013-12-02 21:01:53 -0600 | [diff] [blame] | 2577 | shsurf->fullscreen.black_view->surface->width = output->width; |
| 2578 | shsurf->fullscreen.black_view->surface->height = output->height; |
| 2579 | weston_view_set_position(shsurf->fullscreen.black_view, |
| 2580 | output->x - surf_x, |
| 2581 | output->y - surf_y); |
Alex Wu | bd3354b | 2012-04-17 17:20:49 +0800 | [diff] [blame] | 2582 | break; |
Alexander Larsson | d622ed3 | 2013-05-28 16:23:40 +0200 | [diff] [blame] | 2583 | } else { |
Alexander Larsson | f82b6ca | 2013-05-28 16:23:39 +0200 | [diff] [blame] | 2584 | restore_output_mode(output); |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 2585 | center_on_output(shsurf->view, output); |
Alexander Larsson | d622ed3 | 2013-05-28 16:23:40 +0200 | [diff] [blame] | 2586 | } |
Alex Wu | bd3354b | 2012-04-17 17:20:49 +0800 | [diff] [blame] | 2587 | } |
Alex Wu | 4539b08 | 2012-03-01 12:57:46 +0800 | [diff] [blame] | 2588 | break; |
| 2589 | case WL_SHELL_SURFACE_FULLSCREEN_METHOD_FILL: |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 2590 | center_on_output(shsurf->view, output); |
Alex Wu | 4539b08 | 2012-03-01 12:57:46 +0800 | [diff] [blame] | 2591 | break; |
| 2592 | default: |
| 2593 | break; |
| 2594 | } |
| 2595 | } |
| 2596 | |
Alex Wu | 4539b08 | 2012-03-01 12:57:46 +0800 | [diff] [blame] | 2597 | static void |
| 2598 | shell_map_fullscreen(struct shell_surface *shsurf) |
| 2599 | { |
Alex Wu | bd3354b | 2012-04-17 17:20:49 +0800 | [diff] [blame] | 2600 | shell_configure_fullscreen(shsurf); |
Alex Wu | 4539b08 | 2012-03-01 12:57:46 +0800 | [diff] [blame] | 2601 | } |
| 2602 | |
Kristian Høgsberg | 7a5c979 | 2011-06-18 06:12:54 -0400 | [diff] [blame] | 2603 | static void |
Tiago Vignatti | fb2adba | 2013-06-12 15:43:21 -0300 | [diff] [blame] | 2604 | set_xwayland(struct shell_surface *shsurf, int x, int y, uint32_t flags) |
| 2605 | { |
| 2606 | /* XXX: using the same fields for transient type */ |
Rafael Antognolli | 03b1659 | 2013-12-03 15:35:42 -0200 | [diff] [blame] | 2607 | surface_clear_next_states(shsurf); |
Tiago Vignatti | fb2adba | 2013-06-12 15:43:21 -0300 | [diff] [blame] | 2608 | shsurf->transient.x = x; |
| 2609 | shsurf->transient.y = y; |
| 2610 | shsurf->transient.flags = flags; |
Philip Withnall | dc4332f | 2013-11-25 18:01:38 +0000 | [diff] [blame] | 2611 | |
| 2612 | shell_surface_set_parent(shsurf, NULL); |
| 2613 | |
Kristian Høgsberg | c8f8dd8 | 2013-12-05 23:20:33 -0800 | [diff] [blame] | 2614 | shsurf->type = SHELL_SURFACE_XWAYLAND; |
Kristian Høgsberg | 8bc525c | 2014-01-01 22:34:49 -0800 | [diff] [blame] | 2615 | shsurf->state_changed = true; |
Tiago Vignatti | fb2adba | 2013-06-12 15:43:21 -0300 | [diff] [blame] | 2616 | } |
| 2617 | |
Kristian Høgsberg | 02bbabb | 2013-05-06 22:15:05 -0400 | [diff] [blame] | 2618 | static const struct weston_pointer_grab_interface popup_grab_interface; |
Giulio Camuffo | 5085a75 | 2013-03-25 21:42:45 +0100 | [diff] [blame] | 2619 | |
| 2620 | static void |
| 2621 | destroy_shell_seat(struct wl_listener *listener, void *data) |
| 2622 | { |
| 2623 | struct shell_seat *shseat = |
| 2624 | container_of(listener, |
| 2625 | struct shell_seat, seat_destroy_listener); |
| 2626 | struct shell_surface *shsurf, *prev = NULL; |
| 2627 | |
| 2628 | if (shseat->popup_grab.grab.interface == &popup_grab_interface) { |
Kristian Høgsberg | 02bbabb | 2013-05-06 22:15:05 -0400 | [diff] [blame] | 2629 | weston_pointer_end_grab(shseat->popup_grab.grab.pointer); |
Giulio Camuffo | 5085a75 | 2013-03-25 21:42:45 +0100 | [diff] [blame] | 2630 | shseat->popup_grab.client = NULL; |
| 2631 | |
| 2632 | wl_list_for_each(shsurf, &shseat->popup_grab.surfaces_list, popup.grab_link) { |
| 2633 | shsurf->popup.shseat = NULL; |
| 2634 | if (prev) { |
| 2635 | wl_list_init(&prev->popup.grab_link); |
| 2636 | } |
| 2637 | prev = shsurf; |
| 2638 | } |
| 2639 | wl_list_init(&prev->popup.grab_link); |
| 2640 | } |
| 2641 | |
| 2642 | wl_list_remove(&shseat->seat_destroy_listener.link); |
| 2643 | free(shseat); |
| 2644 | } |
| 2645 | |
| 2646 | static struct shell_seat * |
| 2647 | create_shell_seat(struct weston_seat *seat) |
| 2648 | { |
| 2649 | struct shell_seat *shseat; |
| 2650 | |
| 2651 | shseat = calloc(1, sizeof *shseat); |
| 2652 | if (!shseat) { |
| 2653 | weston_log("no memory to allocate shell seat\n"); |
| 2654 | return NULL; |
| 2655 | } |
| 2656 | |
| 2657 | shseat->seat = seat; |
| 2658 | wl_list_init(&shseat->popup_grab.surfaces_list); |
| 2659 | |
| 2660 | shseat->seat_destroy_listener.notify = destroy_shell_seat; |
| 2661 | wl_signal_add(&seat->destroy_signal, |
| 2662 | &shseat->seat_destroy_listener); |
| 2663 | |
| 2664 | return shseat; |
| 2665 | } |
| 2666 | |
| 2667 | static struct shell_seat * |
| 2668 | get_shell_seat(struct weston_seat *seat) |
| 2669 | { |
| 2670 | struct wl_listener *listener; |
| 2671 | |
| 2672 | listener = wl_signal_get(&seat->destroy_signal, destroy_shell_seat); |
| 2673 | if (listener == NULL) |
| 2674 | return create_shell_seat(seat); |
| 2675 | |
| 2676 | return container_of(listener, |
| 2677 | struct shell_seat, seat_destroy_listener); |
| 2678 | } |
| 2679 | |
Kristian Høgsberg | b810eb5 | 2013-02-12 20:07:05 -0500 | [diff] [blame] | 2680 | static void |
Kristian Høgsberg | 6848c25 | 2013-05-08 22:02:59 -0400 | [diff] [blame] | 2681 | popup_grab_focus(struct weston_pointer_grab *grab) |
Kristian Høgsberg | b3cca0a | 2012-01-04 22:19:14 -0500 | [diff] [blame] | 2682 | { |
Kristian Høgsberg | 02bbabb | 2013-05-06 22:15:05 -0400 | [diff] [blame] | 2683 | struct weston_pointer *pointer = grab->pointer; |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 2684 | struct weston_view *view; |
Giulio Camuffo | 5085a75 | 2013-03-25 21:42:45 +0100 | [diff] [blame] | 2685 | struct shell_seat *shseat = |
| 2686 | container_of(grab, struct shell_seat, popup_grab.grab); |
| 2687 | struct wl_client *client = shseat->popup_grab.client; |
Kristian Høgsberg | 6848c25 | 2013-05-08 22:02:59 -0400 | [diff] [blame] | 2688 | wl_fixed_t sx, sy; |
| 2689 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 2690 | view = weston_compositor_pick_view(pointer->seat->compositor, |
| 2691 | pointer->x, pointer->y, |
| 2692 | &sx, &sy); |
Kristian Høgsberg | b3cca0a | 2012-01-04 22:19:14 -0500 | [diff] [blame] | 2693 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 2694 | if (view && view->surface->resource && |
| 2695 | wl_resource_get_client(view->surface->resource) == client) { |
| 2696 | weston_pointer_set_focus(pointer, view, sx, sy); |
Kristian Høgsberg | b3cca0a | 2012-01-04 22:19:14 -0500 | [diff] [blame] | 2697 | } else { |
Kristian Høgsberg | 02bbabb | 2013-05-06 22:15:05 -0400 | [diff] [blame] | 2698 | weston_pointer_set_focus(pointer, NULL, |
| 2699 | wl_fixed_from_int(0), |
| 2700 | wl_fixed_from_int(0)); |
Kristian Høgsberg | b3cca0a | 2012-01-04 22:19:14 -0500 | [diff] [blame] | 2701 | } |
| 2702 | } |
| 2703 | |
| 2704 | static void |
Giulio Camuffo | 1959ab8 | 2013-11-14 23:42:52 +0100 | [diff] [blame] | 2705 | popup_grab_motion(struct weston_pointer_grab *grab, uint32_t time, |
| 2706 | wl_fixed_t x, wl_fixed_t y) |
Kristian Høgsberg | b3cca0a | 2012-01-04 22:19:14 -0500 | [diff] [blame] | 2707 | { |
Kristian Høgsberg | be6403e | 2013-05-08 21:03:21 -0400 | [diff] [blame] | 2708 | struct weston_pointer *pointer = grab->pointer; |
Neil Roberts | 96d790e | 2013-09-19 17:32:00 +0100 | [diff] [blame] | 2709 | struct wl_resource *resource; |
Kristian Høgsberg | be6403e | 2013-05-08 21:03:21 -0400 | [diff] [blame] | 2710 | wl_fixed_t sx, sy; |
Kristian Høgsberg | b3cca0a | 2012-01-04 22:19:14 -0500 | [diff] [blame] | 2711 | |
Giulio Camuffo | 1959ab8 | 2013-11-14 23:42:52 +0100 | [diff] [blame] | 2712 | weston_pointer_move(pointer, x, y); |
| 2713 | |
Neil Roberts | 96d790e | 2013-09-19 17:32:00 +0100 | [diff] [blame] | 2714 | wl_resource_for_each(resource, &pointer->focus_resource_list) { |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 2715 | weston_view_from_global_fixed(pointer->focus, |
| 2716 | pointer->x, pointer->y, |
| 2717 | &sx, &sy); |
Neil Roberts | 96d790e | 2013-09-19 17:32:00 +0100 | [diff] [blame] | 2718 | wl_pointer_send_motion(resource, time, sx, sy); |
Kristian Høgsberg | be6403e | 2013-05-08 21:03:21 -0400 | [diff] [blame] | 2719 | } |
Kristian Høgsberg | b3cca0a | 2012-01-04 22:19:14 -0500 | [diff] [blame] | 2720 | } |
| 2721 | |
| 2722 | static void |
Kristian Høgsberg | 02bbabb | 2013-05-06 22:15:05 -0400 | [diff] [blame] | 2723 | popup_grab_button(struct weston_pointer_grab *grab, |
Daniel Stone | 4dbadb1 | 2012-05-30 16:31:51 +0100 | [diff] [blame] | 2724 | uint32_t time, uint32_t button, uint32_t state_w) |
Kristian Høgsberg | b3cca0a | 2012-01-04 22:19:14 -0500 | [diff] [blame] | 2725 | { |
| 2726 | struct wl_resource *resource; |
Giulio Camuffo | 5085a75 | 2013-03-25 21:42:45 +0100 | [diff] [blame] | 2727 | struct shell_seat *shseat = |
| 2728 | container_of(grab, struct shell_seat, popup_grab.grab); |
Rob Bradford | 880ebc7 | 2013-07-22 17:31:38 +0100 | [diff] [blame] | 2729 | struct wl_display *display = shseat->seat->compositor->wl_display; |
Daniel Stone | 4dbadb1 | 2012-05-30 16:31:51 +0100 | [diff] [blame] | 2730 | enum wl_pointer_button_state state = state_w; |
Kristian Høgsberg | eae5de7 | 2012-04-11 22:42:15 -0400 | [diff] [blame] | 2731 | uint32_t serial; |
Neil Roberts | 96d790e | 2013-09-19 17:32:00 +0100 | [diff] [blame] | 2732 | struct wl_list *resource_list; |
Kristian Høgsberg | b3cca0a | 2012-01-04 22:19:14 -0500 | [diff] [blame] | 2733 | |
Neil Roberts | 96d790e | 2013-09-19 17:32:00 +0100 | [diff] [blame] | 2734 | resource_list = &grab->pointer->focus_resource_list; |
| 2735 | if (!wl_list_empty(resource_list)) { |
Kristian Høgsberg | eae5de7 | 2012-04-11 22:42:15 -0400 | [diff] [blame] | 2736 | serial = wl_display_get_serial(display); |
Neil Roberts | 96d790e | 2013-09-19 17:32:00 +0100 | [diff] [blame] | 2737 | wl_resource_for_each(resource, resource_list) { |
| 2738 | wl_pointer_send_button(resource, serial, |
| 2739 | time, button, state); |
| 2740 | } |
Daniel Stone | 4dbadb1 | 2012-05-30 16:31:51 +0100 | [diff] [blame] | 2741 | } else if (state == WL_POINTER_BUTTON_STATE_RELEASED && |
Giulio Camuffo | 5085a75 | 2013-03-25 21:42:45 +0100 | [diff] [blame] | 2742 | (shseat->popup_grab.initial_up || |
Kristian Høgsberg | e314875 | 2013-05-06 23:19:49 -0400 | [diff] [blame] | 2743 | time - shseat->seat->pointer->grab_time > 500)) { |
Kristian Høgsberg | 57e0907 | 2012-10-30 14:07:27 -0400 | [diff] [blame] | 2744 | popup_grab_end(grab->pointer); |
Kristian Høgsberg | b3cca0a | 2012-01-04 22:19:14 -0500 | [diff] [blame] | 2745 | } |
| 2746 | |
Daniel Stone | 4dbadb1 | 2012-05-30 16:31:51 +0100 | [diff] [blame] | 2747 | if (state == WL_POINTER_BUTTON_STATE_RELEASED) |
Giulio Camuffo | 5085a75 | 2013-03-25 21:42:45 +0100 | [diff] [blame] | 2748 | shseat->popup_grab.initial_up = 1; |
Kristian Høgsberg | b3cca0a | 2012-01-04 22:19:14 -0500 | [diff] [blame] | 2749 | } |
| 2750 | |
Jonas Ådahl | 1ea343e | 2013-10-25 23:18:05 +0200 | [diff] [blame] | 2751 | static void |
| 2752 | popup_grab_cancel(struct weston_pointer_grab *grab) |
| 2753 | { |
| 2754 | popup_grab_end(grab->pointer); |
| 2755 | } |
| 2756 | |
Kristian Høgsberg | 02bbabb | 2013-05-06 22:15:05 -0400 | [diff] [blame] | 2757 | static const struct weston_pointer_grab_interface popup_grab_interface = { |
Kristian Høgsberg | b3cca0a | 2012-01-04 22:19:14 -0500 | [diff] [blame] | 2758 | popup_grab_focus, |
| 2759 | popup_grab_motion, |
| 2760 | popup_grab_button, |
Jonas Ådahl | 1ea343e | 2013-10-25 23:18:05 +0200 | [diff] [blame] | 2761 | popup_grab_cancel, |
Kristian Høgsberg | b3cca0a | 2012-01-04 22:19:14 -0500 | [diff] [blame] | 2762 | }; |
| 2763 | |
| 2764 | static void |
Rafael Antognolli | e2a3455 | 2013-12-03 15:35:45 -0200 | [diff] [blame] | 2765 | shell_surface_send_popup_done(struct shell_surface *shsurf) |
| 2766 | { |
| 2767 | if (shell_surface_is_wl_shell_surface(shsurf)) |
| 2768 | wl_shell_surface_send_popup_done(shsurf->resource); |
| 2769 | else if (shell_surface_is_xdg_popup(shsurf)) |
| 2770 | xdg_popup_send_popup_done(shsurf->resource, |
| 2771 | shsurf->popup.serial); |
| 2772 | } |
| 2773 | |
| 2774 | static void |
Kristian Høgsberg | 02bbabb | 2013-05-06 22:15:05 -0400 | [diff] [blame] | 2775 | popup_grab_end(struct weston_pointer *pointer) |
Kristian Høgsberg | 57e0907 | 2012-10-30 14:07:27 -0400 | [diff] [blame] | 2776 | { |
Kristian Høgsberg | 02bbabb | 2013-05-06 22:15:05 -0400 | [diff] [blame] | 2777 | struct weston_pointer_grab *grab = pointer->grab; |
Giulio Camuffo | 5085a75 | 2013-03-25 21:42:45 +0100 | [diff] [blame] | 2778 | struct shell_seat *shseat = |
| 2779 | container_of(grab, struct shell_seat, popup_grab.grab); |
| 2780 | struct shell_surface *shsurf; |
| 2781 | struct shell_surface *prev = NULL; |
Kristian Høgsberg | 57e0907 | 2012-10-30 14:07:27 -0400 | [diff] [blame] | 2782 | |
| 2783 | if (pointer->grab->interface == &popup_grab_interface) { |
Kristian Høgsberg | 02bbabb | 2013-05-06 22:15:05 -0400 | [diff] [blame] | 2784 | weston_pointer_end_grab(grab->pointer); |
Giulio Camuffo | 5085a75 | 2013-03-25 21:42:45 +0100 | [diff] [blame] | 2785 | shseat->popup_grab.client = NULL; |
Philipp Brüschweiler | 63e7be6 | 2013-04-15 21:09:54 +0200 | [diff] [blame] | 2786 | shseat->popup_grab.grab.interface = NULL; |
| 2787 | assert(!wl_list_empty(&shseat->popup_grab.surfaces_list)); |
Giulio Camuffo | 5085a75 | 2013-03-25 21:42:45 +0100 | [diff] [blame] | 2788 | /* Send the popup_done event to all the popups open */ |
| 2789 | 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] | 2790 | shell_surface_send_popup_done(shsurf); |
Giulio Camuffo | 5085a75 | 2013-03-25 21:42:45 +0100 | [diff] [blame] | 2791 | shsurf->popup.shseat = NULL; |
| 2792 | if (prev) { |
| 2793 | wl_list_init(&prev->popup.grab_link); |
| 2794 | } |
| 2795 | prev = shsurf; |
| 2796 | } |
| 2797 | wl_list_init(&prev->popup.grab_link); |
| 2798 | wl_list_init(&shseat->popup_grab.surfaces_list); |
| 2799 | } |
| 2800 | } |
| 2801 | |
| 2802 | static void |
| 2803 | add_popup_grab(struct shell_surface *shsurf, struct shell_seat *shseat) |
| 2804 | { |
Kristian Høgsberg | e314875 | 2013-05-06 23:19:49 -0400 | [diff] [blame] | 2805 | struct weston_seat *seat = shseat->seat; |
Giulio Camuffo | 5085a75 | 2013-03-25 21:42:45 +0100 | [diff] [blame] | 2806 | |
| 2807 | if (wl_list_empty(&shseat->popup_grab.surfaces_list)) { |
Jason Ekstrand | 651f00e | 2013-06-14 10:07:54 -0500 | [diff] [blame] | 2808 | shseat->popup_grab.client = wl_resource_get_client(shsurf->resource); |
Giulio Camuffo | 5085a75 | 2013-03-25 21:42:45 +0100 | [diff] [blame] | 2809 | shseat->popup_grab.grab.interface = &popup_grab_interface; |
Giulio Camuffo | 1b4b61a | 2013-03-27 18:05:26 +0100 | [diff] [blame] | 2810 | /* We must make sure here that this popup was opened after |
| 2811 | * a mouse press, and not just by moving around with other |
| 2812 | * popups already open. */ |
Kristian Høgsberg | e314875 | 2013-05-06 23:19:49 -0400 | [diff] [blame] | 2813 | if (shseat->seat->pointer->button_count > 0) |
Giulio Camuffo | 1b4b61a | 2013-03-27 18:05:26 +0100 | [diff] [blame] | 2814 | shseat->popup_grab.initial_up = 0; |
Giulio Camuffo | 5085a75 | 2013-03-25 21:42:45 +0100 | [diff] [blame] | 2815 | |
Rob Bradford | dfe3105 | 2013-06-26 19:49:11 +0100 | [diff] [blame] | 2816 | 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] | 2817 | weston_pointer_start_grab(seat->pointer, &shseat->popup_grab.grab); |
Rob Bradford | dfe3105 | 2013-06-26 19:49:11 +0100 | [diff] [blame] | 2818 | } else { |
| 2819 | wl_list_insert(&shseat->popup_grab.surfaces_list, &shsurf->popup.grab_link); |
Giulio Camuffo | 5085a75 | 2013-03-25 21:42:45 +0100 | [diff] [blame] | 2820 | } |
Giulio Camuffo | 5085a75 | 2013-03-25 21:42:45 +0100 | [diff] [blame] | 2821 | } |
| 2822 | |
| 2823 | static void |
| 2824 | remove_popup_grab(struct shell_surface *shsurf) |
| 2825 | { |
| 2826 | struct shell_seat *shseat = shsurf->popup.shseat; |
| 2827 | |
| 2828 | wl_list_remove(&shsurf->popup.grab_link); |
| 2829 | wl_list_init(&shsurf->popup.grab_link); |
| 2830 | if (wl_list_empty(&shseat->popup_grab.surfaces_list)) { |
Kristian Høgsberg | 02bbabb | 2013-05-06 22:15:05 -0400 | [diff] [blame] | 2831 | weston_pointer_end_grab(shseat->popup_grab.grab.pointer); |
Philipp Brüschweiler | 63e7be6 | 2013-04-15 21:09:54 +0200 | [diff] [blame] | 2832 | shseat->popup_grab.grab.interface = NULL; |
Kristian Høgsberg | 57e0907 | 2012-10-30 14:07:27 -0400 | [diff] [blame] | 2833 | } |
| 2834 | } |
| 2835 | |
| 2836 | static void |
Kristian Høgsberg | 3730f36 | 2012-04-13 12:40:07 -0400 | [diff] [blame] | 2837 | shell_map_popup(struct shell_surface *shsurf) |
Kristian Høgsberg | b3cca0a | 2012-01-04 22:19:14 -0500 | [diff] [blame] | 2838 | { |
Giulio Camuffo | 5085a75 | 2013-03-25 21:42:45 +0100 | [diff] [blame] | 2839 | struct shell_seat *shseat = shsurf->popup.shseat; |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 2840 | struct weston_view *parent_view = get_default_view(shsurf->parent); |
Kristian Høgsberg | b3cca0a | 2012-01-04 22:19:14 -0500 | [diff] [blame] | 2841 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 2842 | shsurf->surface->output = parent_view->output; |
| 2843 | shsurf->view->output = parent_view->output; |
Kristian Høgsberg | b3cca0a | 2012-01-04 22:19:14 -0500 | [diff] [blame] | 2844 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 2845 | weston_view_set_transform_parent(shsurf->view, parent_view); |
| 2846 | weston_view_set_position(shsurf->view, shsurf->popup.x, shsurf->popup.y); |
| 2847 | weston_view_update_transform(shsurf->view); |
Kristian Høgsberg | b3cca0a | 2012-01-04 22:19:14 -0500 | [diff] [blame] | 2848 | |
Kristian Høgsberg | e314875 | 2013-05-06 23:19:49 -0400 | [diff] [blame] | 2849 | if (shseat->seat->pointer->grab_serial == shsurf->popup.serial) { |
Giulio Camuffo | 5085a75 | 2013-03-25 21:42:45 +0100 | [diff] [blame] | 2850 | add_popup_grab(shsurf, shseat); |
Kristian Høgsberg | 3730f36 | 2012-04-13 12:40:07 -0400 | [diff] [blame] | 2851 | } else { |
Rafael Antognolli | e2a3455 | 2013-12-03 15:35:45 -0200 | [diff] [blame] | 2852 | shell_surface_send_popup_done(shsurf); |
Giulio Camuffo | 5085a75 | 2013-03-25 21:42:45 +0100 | [diff] [blame] | 2853 | shseat->popup_grab.client = NULL; |
Kristian Høgsberg | 3730f36 | 2012-04-13 12:40:07 -0400 | [diff] [blame] | 2854 | } |
Kristian Høgsberg | b3cca0a | 2012-01-04 22:19:14 -0500 | [diff] [blame] | 2855 | } |
| 2856 | |
Pekka Paalanen | 9d1613e | 2011-11-25 12:09:16 +0200 | [diff] [blame] | 2857 | static const struct wl_shell_surface_interface shell_surface_implementation = { |
Scott Moreau | ff1db4a | 2012-04-17 19:06:18 -0600 | [diff] [blame] | 2858 | shell_surface_pong, |
Pekka Paalanen | 9d1613e | 2011-11-25 12:09:16 +0200 | [diff] [blame] | 2859 | shell_surface_move, |
| 2860 | shell_surface_resize, |
| 2861 | shell_surface_set_toplevel, |
| 2862 | shell_surface_set_transient, |
Kristian Høgsberg | b3cca0a | 2012-01-04 22:19:14 -0500 | [diff] [blame] | 2863 | shell_surface_set_fullscreen, |
Juan Zhao | 96879df | 2012-02-07 08:45:41 +0800 | [diff] [blame] | 2864 | shell_surface_set_popup, |
Kristian Høgsberg | e7afd91 | 2012-05-02 09:47:44 -0400 | [diff] [blame] | 2865 | shell_surface_set_maximized, |
| 2866 | shell_surface_set_title, |
| 2867 | shell_surface_set_class |
Pekka Paalanen | 9d1613e | 2011-11-25 12:09:16 +0200 | [diff] [blame] | 2868 | }; |
| 2869 | |
| 2870 | static void |
Tiago Vignatti | bc052c9 | 2012-04-19 16:18:18 +0300 | [diff] [blame] | 2871 | destroy_shell_surface(struct shell_surface *shsurf) |
Pekka Paalanen | 9d1613e | 2011-11-25 12:09:16 +0200 | [diff] [blame] | 2872 | { |
Kristian Høgsberg | 9046d24 | 2014-01-10 00:25:30 -0800 | [diff] [blame] | 2873 | struct shell_surface *child, *next; |
| 2874 | |
Jason Ekstrand | 651f00e | 2013-06-14 10:07:54 -0500 | [diff] [blame] | 2875 | wl_signal_emit(&shsurf->destroy_signal, shsurf); |
| 2876 | |
Giulio Camuffo | 5085a75 | 2013-03-25 21:42:45 +0100 | [diff] [blame] | 2877 | if (!wl_list_empty(&shsurf->popup.grab_link)) { |
| 2878 | remove_popup_grab(shsurf); |
| 2879 | } |
Kristian Høgsberg | b3cca0a | 2012-01-04 22:19:14 -0500 | [diff] [blame] | 2880 | |
Alex Wu | bd3354b | 2012-04-17 17:20:49 +0800 | [diff] [blame] | 2881 | if (shsurf->fullscreen.type == WL_SHELL_SURFACE_FULLSCREEN_METHOD_DRIVER && |
Alexander Larsson | f82b6ca | 2013-05-28 16:23:39 +0200 | [diff] [blame] | 2882 | shell_surface_is_top_fullscreen(shsurf)) |
| 2883 | restore_output_mode (shsurf->fullscreen_output); |
Pekka Paalanen | 9d1613e | 2011-11-25 12:09:16 +0200 | [diff] [blame] | 2884 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 2885 | if (shsurf->fullscreen.black_view) |
| 2886 | weston_surface_destroy(shsurf->fullscreen.black_view->surface); |
Alex Wu | aa08e2d | 2012-03-05 11:01:40 +0800 | [diff] [blame] | 2887 | |
Alex Wu | bd3354b | 2012-04-17 17:20:49 +0800 | [diff] [blame] | 2888 | /* As destroy_resource() use wl_list_for_each_safe(), |
| 2889 | * we can always remove the listener. |
| 2890 | */ |
| 2891 | wl_list_remove(&shsurf->surface_destroy_listener.link); |
| 2892 | shsurf->surface->configure = NULL; |
Scott Moreau | 9521d5e | 2012-04-19 13:06:17 -0600 | [diff] [blame] | 2893 | ping_timer_destroy(shsurf); |
Scott Moreau | 976a050 | 2013-03-07 10:15:17 -0700 | [diff] [blame] | 2894 | free(shsurf->title); |
Alex Wu | bd3354b | 2012-04-17 17:20:49 +0800 | [diff] [blame] | 2895 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 2896 | weston_view_destroy(shsurf->view); |
| 2897 | |
Philip Withnall | 648a4dd | 2013-11-25 18:01:44 +0000 | [diff] [blame] | 2898 | wl_list_remove(&shsurf->children_link); |
Kristian Høgsberg | 9046d24 | 2014-01-10 00:25:30 -0800 | [diff] [blame] | 2899 | wl_list_for_each_safe(child, next, &shsurf->children_list, children_link) { |
| 2900 | wl_list_remove(&child->children_link); |
| 2901 | child->parent = NULL; |
| 2902 | } |
Philip Withnall | 648a4dd | 2013-11-25 18:01:44 +0000 | [diff] [blame] | 2903 | |
Pekka Paalanen | 9d1613e | 2011-11-25 12:09:16 +0200 | [diff] [blame] | 2904 | wl_list_remove(&shsurf->link); |
| 2905 | free(shsurf); |
| 2906 | } |
| 2907 | |
| 2908 | static void |
Tiago Vignatti | bc052c9 | 2012-04-19 16:18:18 +0300 | [diff] [blame] | 2909 | shell_destroy_shell_surface(struct wl_resource *resource) |
| 2910 | { |
Jason Ekstrand | 651f00e | 2013-06-14 10:07:54 -0500 | [diff] [blame] | 2911 | struct shell_surface *shsurf = wl_resource_get_user_data(resource); |
Tiago Vignatti | bc052c9 | 2012-04-19 16:18:18 +0300 | [diff] [blame] | 2912 | |
| 2913 | destroy_shell_surface(shsurf); |
| 2914 | } |
| 2915 | |
| 2916 | static void |
Kristian Høgsberg | 27e3052 | 2012-04-11 23:18:23 -0400 | [diff] [blame] | 2917 | shell_handle_surface_destroy(struct wl_listener *listener, void *data) |
Pekka Paalanen | 9d1613e | 2011-11-25 12:09:16 +0200 | [diff] [blame] | 2918 | { |
| 2919 | struct shell_surface *shsurf = container_of(listener, |
| 2920 | struct shell_surface, |
| 2921 | surface_destroy_listener); |
| 2922 | |
Jason Ekstrand | 651f00e | 2013-06-14 10:07:54 -0500 | [diff] [blame] | 2923 | if (shsurf->resource) |
| 2924 | wl_resource_destroy(shsurf->resource); |
| 2925 | else |
Tiago Vignatti | bc052c9 | 2012-04-19 16:18:18 +0300 | [diff] [blame] | 2926 | destroy_shell_surface(shsurf); |
Pekka Paalanen | 9d1613e | 2011-11-25 12:09:16 +0200 | [diff] [blame] | 2927 | } |
| 2928 | |
Kristian Høgsberg | d813445 | 2012-06-21 12:49:02 -0400 | [diff] [blame] | 2929 | static void |
Jason Ekstrand | 918f2dd | 2013-12-02 21:01:53 -0600 | [diff] [blame] | 2930 | shell_surface_configure(struct weston_surface *, int32_t, int32_t); |
Zhang, Xiong Y | 3123693 | 2013-12-13 22:10:57 +0200 | [diff] [blame] | 2931 | static void |
| 2932 | shell_surface_output_destroyed(struct weston_surface *); |
Kristian Høgsberg | d813445 | 2012-06-21 12:49:02 -0400 | [diff] [blame] | 2933 | |
Kristian Høgsberg | 1ef2313 | 2013-12-04 00:20:01 -0800 | [diff] [blame] | 2934 | struct shell_surface * |
Kristian Høgsberg | 8334bc1 | 2012-01-03 10:29:47 -0500 | [diff] [blame] | 2935 | get_shell_surface(struct weston_surface *surface) |
Pekka Paalanen | ec2b32f | 2011-11-28 15:12:34 +0200 | [diff] [blame] | 2936 | { |
Kristian Høgsberg | d813445 | 2012-06-21 12:49:02 -0400 | [diff] [blame] | 2937 | if (surface->configure == shell_surface_configure) |
Giulio Camuffo | 7fe01b1 | 2013-03-28 18:02:42 +0100 | [diff] [blame] | 2938 | return surface->configure_private; |
Kristian Høgsberg | d813445 | 2012-06-21 12:49:02 -0400 | [diff] [blame] | 2939 | else |
| 2940 | return NULL; |
Pekka Paalanen | ec2b32f | 2011-11-28 15:12:34 +0200 | [diff] [blame] | 2941 | } |
| 2942 | |
Rafael Antognolli | e2a3455 | 2013-12-03 15:35:45 -0200 | [diff] [blame] | 2943 | static struct shell_surface * |
| 2944 | create_common_surface(void *shell, struct weston_surface *surface, |
| 2945 | const struct weston_shell_client *client) |
Pekka Paalanen | 9d1613e | 2011-11-25 12:09:16 +0200 | [diff] [blame] | 2946 | { |
Pekka Paalanen | 9d1613e | 2011-11-25 12:09:16 +0200 | [diff] [blame] | 2947 | struct shell_surface *shsurf; |
| 2948 | |
Ander Conselvan de Oliveira | 093bfa3 | 2012-03-27 17:36:41 +0300 | [diff] [blame] | 2949 | if (surface->configure) { |
Martin Minarik | 6d11836 | 2012-06-07 18:01:59 +0200 | [diff] [blame] | 2950 | weston_log("surface->configure already set\n"); |
Kristian Høgsberg | 45ba869 | 2012-05-21 14:27:33 -0400 | [diff] [blame] | 2951 | return NULL; |
Ander Conselvan de Oliveira | 093bfa3 | 2012-03-27 17:36:41 +0300 | [diff] [blame] | 2952 | } |
| 2953 | |
Pekka Paalanen | 9d1613e | 2011-11-25 12:09:16 +0200 | [diff] [blame] | 2954 | shsurf = calloc(1, sizeof *shsurf); |
| 2955 | if (!shsurf) { |
Martin Minarik | 6d11836 | 2012-06-07 18:01:59 +0200 | [diff] [blame] | 2956 | weston_log("no memory to allocate shell surface\n"); |
Kristian Høgsberg | 45ba869 | 2012-05-21 14:27:33 -0400 | [diff] [blame] | 2957 | return NULL; |
Pekka Paalanen | 9d1613e | 2011-11-25 12:09:16 +0200 | [diff] [blame] | 2958 | } |
| 2959 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 2960 | shsurf->view = weston_view_create(surface); |
| 2961 | if (!shsurf->view) { |
| 2962 | weston_log("no memory to allocate shell surface\n"); |
| 2963 | free(shsurf); |
| 2964 | return NULL; |
| 2965 | } |
| 2966 | |
Ander Conselvan de Oliveira | 093bfa3 | 2012-03-27 17:36:41 +0300 | [diff] [blame] | 2967 | surface->configure = shell_surface_configure; |
Giulio Camuffo | 7fe01b1 | 2013-03-28 18:02:42 +0100 | [diff] [blame] | 2968 | surface->configure_private = shsurf; |
Zhang, Xiong Y | 3123693 | 2013-12-13 22:10:57 +0200 | [diff] [blame] | 2969 | surface->output_destroyed = shell_surface_output_destroyed; |
Ander Conselvan de Oliveira | 093bfa3 | 2012-03-27 17:36:41 +0300 | [diff] [blame] | 2970 | |
Tiago Vignatti | bc052c9 | 2012-04-19 16:18:18 +0300 | [diff] [blame] | 2971 | shsurf->shell = (struct desktop_shell *) shell; |
Scott Moreau | ff1db4a | 2012-04-17 19:06:18 -0600 | [diff] [blame] | 2972 | shsurf->unresponsive = 0; |
Alex Wu | 4539b08 | 2012-03-01 12:57:46 +0800 | [diff] [blame] | 2973 | shsurf->saved_position_valid = false; |
Rafael Antognolli | 3c4e3f7 | 2013-12-03 15:35:46 -0200 | [diff] [blame] | 2974 | shsurf->saved_size_valid = false; |
Alex Wu | 7bcb8bd | 2012-04-27 09:07:24 +0800 | [diff] [blame] | 2975 | shsurf->saved_rotation_valid = false; |
Pekka Paalanen | 9d1613e | 2011-11-25 12:09:16 +0200 | [diff] [blame] | 2976 | shsurf->surface = surface; |
Alex Wu | 4539b08 | 2012-03-01 12:57:46 +0800 | [diff] [blame] | 2977 | shsurf->fullscreen.type = WL_SHELL_SURFACE_FULLSCREEN_METHOD_DEFAULT; |
| 2978 | shsurf->fullscreen.framerate = 0; |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 2979 | shsurf->fullscreen.black_view = NULL; |
Scott Moreau | ff1db4a | 2012-04-17 19:06:18 -0600 | [diff] [blame] | 2980 | shsurf->ping_timer = NULL; |
Alex Wu | 4539b08 | 2012-03-01 12:57:46 +0800 | [diff] [blame] | 2981 | wl_list_init(&shsurf->fullscreen.transform.link); |
| 2982 | |
Jason Ekstrand | 651f00e | 2013-06-14 10:07:54 -0500 | [diff] [blame] | 2983 | wl_signal_init(&shsurf->destroy_signal); |
Kristian Høgsberg | 27e3052 | 2012-04-11 23:18:23 -0400 | [diff] [blame] | 2984 | shsurf->surface_destroy_listener.notify = shell_handle_surface_destroy; |
Jason Ekstrand | 26ed73c | 2013-06-06 22:34:41 -0500 | [diff] [blame] | 2985 | wl_signal_add(&surface->destroy_signal, |
Kristian Høgsberg | 27e3052 | 2012-04-11 23:18:23 -0400 | [diff] [blame] | 2986 | &shsurf->surface_destroy_listener); |
Pekka Paalanen | 9d1613e | 2011-11-25 12:09:16 +0200 | [diff] [blame] | 2987 | |
| 2988 | /* init link so its safe to always remove it in destroy_shell_surface */ |
| 2989 | wl_list_init(&shsurf->link); |
Giulio Camuffo | 5085a75 | 2013-03-25 21:42:45 +0100 | [diff] [blame] | 2990 | wl_list_init(&shsurf->popup.grab_link); |
Pekka Paalanen | 9d1613e | 2011-11-25 12:09:16 +0200 | [diff] [blame] | 2991 | |
Pekka Paalanen | 460099f | 2012-01-20 16:48:25 +0200 | [diff] [blame] | 2992 | /* empty when not in use */ |
| 2993 | wl_list_init(&shsurf->rotation.transform.link); |
Kristian Høgsberg | 765e27b | 2012-01-27 13:36:13 -0500 | [diff] [blame] | 2994 | weston_matrix_init(&shsurf->rotation.rotation); |
Pekka Paalanen | 460099f | 2012-01-20 16:48:25 +0200 | [diff] [blame] | 2995 | |
Jonas Ådahl | 62fcd04 | 2012-06-13 00:01:23 +0200 | [diff] [blame] | 2996 | wl_list_init(&shsurf->workspace_transform.link); |
| 2997 | |
Philip Withnall | 648a4dd | 2013-11-25 18:01:44 +0000 | [diff] [blame] | 2998 | wl_list_init(&shsurf->children_link); |
| 2999 | wl_list_init(&shsurf->children_list); |
| 3000 | shsurf->parent = NULL; |
| 3001 | |
Pekka Paalanen | 9826223 | 2011-12-01 10:42:22 +0200 | [diff] [blame] | 3002 | shsurf->type = SHELL_SURFACE_NONE; |
Pekka Paalanen | 9d1613e | 2011-11-25 12:09:16 +0200 | [diff] [blame] | 3003 | |
Kristian Høgsberg | a61ca06 | 2012-05-22 16:05:52 -0400 | [diff] [blame] | 3004 | shsurf->client = client; |
| 3005 | |
Kristian Høgsberg | 45ba869 | 2012-05-21 14:27:33 -0400 | [diff] [blame] | 3006 | return shsurf; |
Tiago Vignatti | bc052c9 | 2012-04-19 16:18:18 +0300 | [diff] [blame] | 3007 | } |
| 3008 | |
Rafael Antognolli | e2a3455 | 2013-12-03 15:35:45 -0200 | [diff] [blame] | 3009 | static struct shell_surface * |
| 3010 | create_shell_surface(void *shell, struct weston_surface *surface, |
| 3011 | const struct weston_shell_client *client) |
| 3012 | { |
Kristian Høgsberg | c8f8dd8 | 2013-12-05 23:20:33 -0800 | [diff] [blame] | 3013 | return create_common_surface(shell, surface, client); |
Rafael Antognolli | e2a3455 | 2013-12-03 15:35:45 -0200 | [diff] [blame] | 3014 | } |
| 3015 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 3016 | static struct weston_view * |
| 3017 | get_primary_view(void *shell, struct shell_surface *shsurf) |
| 3018 | { |
| 3019 | return shsurf->view; |
| 3020 | } |
| 3021 | |
Tiago Vignatti | bc052c9 | 2012-04-19 16:18:18 +0300 | [diff] [blame] | 3022 | static void |
| 3023 | shell_get_shell_surface(struct wl_client *client, |
| 3024 | struct wl_resource *resource, |
| 3025 | uint32_t id, |
| 3026 | struct wl_resource *surface_resource) |
| 3027 | { |
Jason Ekstrand | 0f2ef7e | 2013-06-14 10:07:53 -0500 | [diff] [blame] | 3028 | struct weston_surface *surface = |
| 3029 | wl_resource_get_user_data(surface_resource); |
Jason Ekstrand | 651f00e | 2013-06-14 10:07:54 -0500 | [diff] [blame] | 3030 | struct desktop_shell *shell = wl_resource_get_user_data(resource); |
Tiago Vignatti | bc052c9 | 2012-04-19 16:18:18 +0300 | [diff] [blame] | 3031 | struct shell_surface *shsurf; |
| 3032 | |
| 3033 | if (get_shell_surface(surface)) { |
| 3034 | wl_resource_post_error(surface_resource, |
Kristian Høgsberg | 9540ea6 | 2012-05-21 14:28:57 -0400 | [diff] [blame] | 3035 | WL_DISPLAY_ERROR_INVALID_OBJECT, |
| 3036 | "desktop_shell::get_shell_surface already requested"); |
Tiago Vignatti | bc052c9 | 2012-04-19 16:18:18 +0300 | [diff] [blame] | 3037 | return; |
| 3038 | } |
| 3039 | |
Kristian Høgsberg | a61ca06 | 2012-05-22 16:05:52 -0400 | [diff] [blame] | 3040 | shsurf = create_shell_surface(shell, surface, &shell_client); |
Kristian Høgsberg | 9540ea6 | 2012-05-21 14:28:57 -0400 | [diff] [blame] | 3041 | if (!shsurf) { |
| 3042 | wl_resource_post_error(surface_resource, |
| 3043 | WL_DISPLAY_ERROR_INVALID_OBJECT, |
| 3044 | "surface->configure already set"); |
| 3045 | return; |
| 3046 | } |
Tiago Vignatti | bc052c9 | 2012-04-19 16:18:18 +0300 | [diff] [blame] | 3047 | |
Jason Ekstrand | a85118c | 2013-06-27 20:17:02 -0500 | [diff] [blame] | 3048 | shsurf->resource = |
| 3049 | wl_resource_create(client, |
| 3050 | &wl_shell_surface_interface, 1, id); |
| 3051 | wl_resource_set_implementation(shsurf->resource, |
| 3052 | &shell_surface_implementation, |
| 3053 | shsurf, shell_destroy_shell_surface); |
Pekka Paalanen | 9d1613e | 2011-11-25 12:09:16 +0200 | [diff] [blame] | 3054 | } |
| 3055 | |
Rafael Antognolli | e2a3455 | 2013-12-03 15:35:45 -0200 | [diff] [blame] | 3056 | static bool |
| 3057 | shell_surface_is_wl_shell_surface(struct shell_surface *shsurf) |
| 3058 | { |
| 3059 | return wl_resource_instance_of(shsurf->resource, |
| 3060 | &wl_shell_surface_interface, |
| 3061 | &shell_surface_implementation); |
| 3062 | } |
| 3063 | |
Pekka Paalanen | 9d1613e | 2011-11-25 12:09:16 +0200 | [diff] [blame] | 3064 | static const struct wl_shell_interface shell_implementation = { |
Pekka Paalanen | 4622967 | 2011-11-29 15:49:31 +0200 | [diff] [blame] | 3065 | shell_get_shell_surface |
Kristian Høgsberg | 4cca349 | 2011-01-18 07:53:49 -0500 | [diff] [blame] | 3066 | }; |
| 3067 | |
Rafael Antognolli | e2a3455 | 2013-12-03 15:35:45 -0200 | [diff] [blame] | 3068 | /**************************** |
| 3069 | * xdg-shell implementation */ |
| 3070 | |
| 3071 | static void |
| 3072 | xdg_surface_destroy(struct wl_client *client, |
| 3073 | struct wl_resource *resource) |
| 3074 | { |
| 3075 | wl_resource_destroy(resource); |
| 3076 | } |
| 3077 | |
| 3078 | static void |
| 3079 | xdg_surface_pong(struct wl_client *client, |
| 3080 | struct wl_resource *resource, |
| 3081 | uint32_t serial) |
| 3082 | { |
| 3083 | struct shell_surface *shsurf = wl_resource_get_user_data(resource); |
| 3084 | |
| 3085 | surface_pong(shsurf, serial); |
| 3086 | } |
| 3087 | |
| 3088 | static void |
| 3089 | xdg_surface_set_app_id(struct wl_client *client, |
| 3090 | struct wl_resource *resource, |
| 3091 | const char *app_id) |
| 3092 | { |
| 3093 | struct shell_surface *shsurf = wl_resource_get_user_data(resource); |
| 3094 | |
| 3095 | free(shsurf->class); |
| 3096 | shsurf->class = strdup(app_id); |
| 3097 | } |
| 3098 | |
| 3099 | static void |
| 3100 | xdg_surface_set_title(struct wl_client *client, |
| 3101 | struct wl_resource *resource, const char *title) |
| 3102 | { |
| 3103 | struct shell_surface *shsurf = wl_resource_get_user_data(resource); |
| 3104 | |
| 3105 | set_title(shsurf, title); |
| 3106 | } |
| 3107 | |
| 3108 | static void |
| 3109 | xdg_surface_move(struct wl_client *client, struct wl_resource *resource, |
| 3110 | struct wl_resource *seat_resource, uint32_t serial) |
| 3111 | { |
| 3112 | common_surface_move(resource, seat_resource, serial); |
| 3113 | } |
| 3114 | |
| 3115 | static void |
| 3116 | xdg_surface_resize(struct wl_client *client, struct wl_resource *resource, |
| 3117 | struct wl_resource *seat_resource, uint32_t serial, |
| 3118 | uint32_t edges) |
| 3119 | { |
| 3120 | common_surface_resize(resource, seat_resource, serial, edges); |
| 3121 | } |
| 3122 | |
| 3123 | static void |
| 3124 | xdg_surface_set_output(struct wl_client *client, |
| 3125 | struct wl_resource *resource, |
| 3126 | struct wl_resource *output_resource) |
| 3127 | { |
| 3128 | struct shell_surface *shsurf = wl_resource_get_user_data(resource); |
| 3129 | struct weston_output *output; |
| 3130 | |
| 3131 | if (output_resource) |
| 3132 | output = wl_resource_get_user_data(output_resource); |
| 3133 | else |
| 3134 | output = NULL; |
| 3135 | |
Rafael Antognolli | 65f98d8 | 2013-12-03 15:35:47 -0200 | [diff] [blame] | 3136 | shsurf->recommended_output = output; |
Rafael Antognolli | e2a3455 | 2013-12-03 15:35:45 -0200 | [diff] [blame] | 3137 | } |
| 3138 | |
| 3139 | static void |
| 3140 | xdg_surface_set_fullscreen(struct wl_client *client, |
| 3141 | struct wl_resource *resource) |
| 3142 | { |
| 3143 | struct shell_surface *shsurf = wl_resource_get_user_data(resource); |
| 3144 | |
| 3145 | if (shsurf->type != SHELL_SURFACE_TOPLEVEL) |
| 3146 | return; |
| 3147 | |
Kristian Høgsberg | e960b3f | 2013-12-05 22:04:42 -0800 | [diff] [blame] | 3148 | if (!shsurf->next_state.fullscreen) |
Rafael Antognolli | e2a3455 | 2013-12-03 15:35:45 -0200 | [diff] [blame] | 3149 | set_fullscreen(shsurf, |
| 3150 | WL_SHELL_SURFACE_FULLSCREEN_METHOD_DEFAULT, |
Rafael Antognolli | 65f98d8 | 2013-12-03 15:35:47 -0200 | [diff] [blame] | 3151 | 0, shsurf->recommended_output); |
Rafael Antognolli | e2a3455 | 2013-12-03 15:35:45 -0200 | [diff] [blame] | 3152 | } |
| 3153 | |
| 3154 | static void |
| 3155 | xdg_surface_unset_fullscreen(struct wl_client *client, |
| 3156 | struct wl_resource *resource) |
| 3157 | { |
| 3158 | struct shell_surface *shsurf = wl_resource_get_user_data(resource); |
Rafael Antognolli | 3c4e3f7 | 2013-12-03 15:35:46 -0200 | [diff] [blame] | 3159 | int32_t width, height; |
Rafael Antognolli | e2a3455 | 2013-12-03 15:35:45 -0200 | [diff] [blame] | 3160 | |
| 3161 | if (shsurf->type != SHELL_SURFACE_TOPLEVEL) |
| 3162 | return; |
| 3163 | |
Rafael Antognolli | 3c4e3f7 | 2013-12-03 15:35:46 -0200 | [diff] [blame] | 3164 | if (!shsurf->next_state.fullscreen) |
| 3165 | return; |
| 3166 | |
Rafael Antognolli | e2a3455 | 2013-12-03 15:35:45 -0200 | [diff] [blame] | 3167 | shsurf->next_state.fullscreen = false; |
| 3168 | shsurf->state_changed = true; |
Rafael Antognolli | 3c4e3f7 | 2013-12-03 15:35:46 -0200 | [diff] [blame] | 3169 | |
| 3170 | if (shsurf->saved_size_valid) { |
| 3171 | width = shsurf->saved_width; |
| 3172 | height = shsurf->saved_height; |
| 3173 | shsurf->saved_size_valid = false; |
| 3174 | } else { |
| 3175 | width = shsurf->surface->width; |
| 3176 | height = shsurf->surface->height; |
| 3177 | } |
| 3178 | |
| 3179 | shsurf->client->send_configure(shsurf->surface, 0, width, height); |
Rafael Antognolli | e2a3455 | 2013-12-03 15:35:45 -0200 | [diff] [blame] | 3180 | } |
| 3181 | |
| 3182 | static void |
| 3183 | xdg_surface_set_maximized(struct wl_client *client, |
| 3184 | struct wl_resource *resource) |
| 3185 | { |
| 3186 | struct shell_surface *shsurf = wl_resource_get_user_data(resource); |
| 3187 | |
| 3188 | if (shsurf->type != SHELL_SURFACE_TOPLEVEL) |
| 3189 | return; |
| 3190 | |
Kristian Høgsberg | c2745b1 | 2013-12-05 22:00:40 -0800 | [diff] [blame] | 3191 | if (!shsurf->next_state.maximized) |
Rafael Antognolli | 65f98d8 | 2013-12-03 15:35:47 -0200 | [diff] [blame] | 3192 | set_maximized(shsurf, NULL); |
Rafael Antognolli | e2a3455 | 2013-12-03 15:35:45 -0200 | [diff] [blame] | 3193 | } |
| 3194 | |
| 3195 | static void |
| 3196 | xdg_surface_unset_maximized(struct wl_client *client, |
| 3197 | struct wl_resource *resource) |
| 3198 | { |
| 3199 | struct shell_surface *shsurf = wl_resource_get_user_data(resource); |
Rafael Antognolli | 3c4e3f7 | 2013-12-03 15:35:46 -0200 | [diff] [blame] | 3200 | int32_t width, height; |
Rafael Antognolli | e2a3455 | 2013-12-03 15:35:45 -0200 | [diff] [blame] | 3201 | |
| 3202 | if (shsurf->type != SHELL_SURFACE_TOPLEVEL) |
| 3203 | return; |
| 3204 | |
Rafael Antognolli | 3c4e3f7 | 2013-12-03 15:35:46 -0200 | [diff] [blame] | 3205 | if (!shsurf->next_state.maximized) |
| 3206 | return; |
| 3207 | |
Rafael Antognolli | e2a3455 | 2013-12-03 15:35:45 -0200 | [diff] [blame] | 3208 | shsurf->next_state.maximized = false; |
| 3209 | shsurf->state_changed = true; |
Rafael Antognolli | 3c4e3f7 | 2013-12-03 15:35:46 -0200 | [diff] [blame] | 3210 | |
| 3211 | if (shsurf->saved_size_valid) { |
| 3212 | width = shsurf->saved_width; |
| 3213 | height = shsurf->saved_height; |
| 3214 | shsurf->saved_size_valid = false; |
| 3215 | } else { |
| 3216 | width = shsurf->surface->width; |
| 3217 | height = shsurf->surface->height; |
| 3218 | } |
| 3219 | |
| 3220 | shsurf->client->send_configure(shsurf->surface, 0, width, height); |
Rafael Antognolli | e2a3455 | 2013-12-03 15:35:45 -0200 | [diff] [blame] | 3221 | } |
| 3222 | |
| 3223 | static const struct xdg_surface_interface xdg_surface_implementation = { |
| 3224 | xdg_surface_destroy, |
| 3225 | xdg_surface_set_transient_for, |
| 3226 | xdg_surface_set_title, |
| 3227 | xdg_surface_set_app_id, |
| 3228 | xdg_surface_pong, |
| 3229 | xdg_surface_move, |
| 3230 | xdg_surface_resize, |
| 3231 | xdg_surface_set_output, |
| 3232 | xdg_surface_set_fullscreen, |
| 3233 | xdg_surface_unset_fullscreen, |
| 3234 | xdg_surface_set_maximized, |
| 3235 | xdg_surface_unset_maximized, |
| 3236 | NULL /* set_minimized */ |
| 3237 | }; |
| 3238 | |
| 3239 | static void |
| 3240 | xdg_send_configure(struct weston_surface *surface, |
| 3241 | uint32_t edges, int32_t width, int32_t height) |
| 3242 | { |
| 3243 | struct shell_surface *shsurf = get_shell_surface(surface); |
| 3244 | |
| 3245 | xdg_surface_send_configure(shsurf->resource, edges, width, height); |
| 3246 | } |
| 3247 | |
| 3248 | static const struct weston_shell_client xdg_client = { |
| 3249 | xdg_send_configure |
| 3250 | }; |
| 3251 | |
| 3252 | static void |
| 3253 | xdg_use_unstable_version(struct wl_client *client, |
| 3254 | struct wl_resource *resource, |
| 3255 | int32_t version) |
| 3256 | { |
| 3257 | if (version > 1) { |
| 3258 | wl_resource_post_error(resource, |
| 3259 | 1, |
| 3260 | "xdg-shell:: version not implemented yet."); |
| 3261 | return; |
| 3262 | } |
| 3263 | } |
| 3264 | |
| 3265 | static struct shell_surface * |
| 3266 | create_xdg_surface(void *shell, struct weston_surface *surface, |
| 3267 | const struct weston_shell_client *client) |
| 3268 | { |
| 3269 | struct shell_surface *shsurf; |
Rafael Antognolli | e2a3455 | 2013-12-03 15:35:45 -0200 | [diff] [blame] | 3270 | |
Kristian Høgsberg | c8f8dd8 | 2013-12-05 23:20:33 -0800 | [diff] [blame] | 3271 | shsurf = create_common_surface(shell, surface, client); |
| 3272 | shsurf->type = SHELL_SURFACE_TOPLEVEL; |
Rafael Antognolli | e2a3455 | 2013-12-03 15:35:45 -0200 | [diff] [blame] | 3273 | |
| 3274 | return shsurf; |
| 3275 | } |
| 3276 | |
| 3277 | static void |
| 3278 | xdg_get_xdg_surface(struct wl_client *client, |
| 3279 | struct wl_resource *resource, |
| 3280 | uint32_t id, |
| 3281 | struct wl_resource *surface_resource) |
| 3282 | { |
| 3283 | struct weston_surface *surface = |
| 3284 | wl_resource_get_user_data(surface_resource); |
| 3285 | struct desktop_shell *shell = wl_resource_get_user_data(resource); |
| 3286 | struct shell_surface *shsurf; |
| 3287 | |
| 3288 | if (get_shell_surface(surface)) { |
| 3289 | wl_resource_post_error(surface_resource, |
| 3290 | WL_DISPLAY_ERROR_INVALID_OBJECT, |
| 3291 | "desktop_shell::get_shell_surface already requested"); |
| 3292 | return; |
| 3293 | } |
| 3294 | |
| 3295 | shsurf = create_xdg_surface(shell, surface, &xdg_client); |
| 3296 | if (!shsurf) { |
| 3297 | wl_resource_post_error(surface_resource, |
| 3298 | WL_DISPLAY_ERROR_INVALID_OBJECT, |
| 3299 | "surface->configure already set"); |
| 3300 | return; |
| 3301 | } |
| 3302 | |
| 3303 | shsurf->resource = |
| 3304 | wl_resource_create(client, |
| 3305 | &xdg_surface_interface, 1, id); |
| 3306 | wl_resource_set_implementation(shsurf->resource, |
| 3307 | &xdg_surface_implementation, |
| 3308 | shsurf, shell_destroy_shell_surface); |
| 3309 | } |
| 3310 | |
| 3311 | static bool |
| 3312 | shell_surface_is_xdg_surface(struct shell_surface *shsurf) |
| 3313 | { |
| 3314 | return wl_resource_instance_of(shsurf->resource, |
| 3315 | &xdg_surface_interface, |
| 3316 | &xdg_surface_implementation); |
| 3317 | } |
| 3318 | |
| 3319 | /* xdg-popup implementation */ |
| 3320 | |
| 3321 | static void |
| 3322 | xdg_popup_destroy(struct wl_client *client, |
| 3323 | struct wl_resource *resource) |
| 3324 | { |
| 3325 | wl_resource_destroy(resource); |
| 3326 | } |
| 3327 | |
| 3328 | static void |
| 3329 | xdg_popup_pong(struct wl_client *client, |
| 3330 | struct wl_resource *resource, |
| 3331 | uint32_t serial) |
| 3332 | { |
| 3333 | struct shell_surface *shsurf = wl_resource_get_user_data(resource); |
| 3334 | |
| 3335 | surface_pong(shsurf, serial); |
| 3336 | } |
| 3337 | |
| 3338 | static const struct xdg_popup_interface xdg_popup_implementation = { |
| 3339 | xdg_popup_destroy, |
| 3340 | xdg_popup_pong |
| 3341 | }; |
| 3342 | |
| 3343 | static void |
| 3344 | xdg_popup_send_configure(struct weston_surface *surface, |
| 3345 | uint32_t edges, int32_t width, int32_t height) |
| 3346 | { |
| 3347 | } |
| 3348 | |
| 3349 | static const struct weston_shell_client xdg_popup_client = { |
| 3350 | xdg_popup_send_configure |
| 3351 | }; |
| 3352 | |
| 3353 | static struct shell_surface * |
| 3354 | create_xdg_popup(void *shell, struct weston_surface *surface, |
| 3355 | const struct weston_shell_client *client, |
| 3356 | struct weston_surface *parent, |
| 3357 | struct shell_seat *seat, |
| 3358 | uint32_t serial, |
| 3359 | int32_t x, int32_t y) |
| 3360 | { |
| 3361 | struct shell_surface *shsurf; |
Rafael Antognolli | e2a3455 | 2013-12-03 15:35:45 -0200 | [diff] [blame] | 3362 | |
Kristian Høgsberg | c8f8dd8 | 2013-12-05 23:20:33 -0800 | [diff] [blame] | 3363 | shsurf = create_common_surface(shell, surface, client); |
| 3364 | shsurf->type = SHELL_SURFACE_POPUP; |
Rafael Antognolli | e2a3455 | 2013-12-03 15:35:45 -0200 | [diff] [blame] | 3365 | shsurf->popup.shseat = seat; |
| 3366 | shsurf->popup.serial = serial; |
| 3367 | shsurf->popup.x = x; |
| 3368 | shsurf->popup.y = y; |
| 3369 | shell_surface_set_parent(shsurf, parent); |
| 3370 | |
| 3371 | return shsurf; |
| 3372 | } |
| 3373 | |
| 3374 | static void |
| 3375 | xdg_get_xdg_popup(struct wl_client *client, |
| 3376 | struct wl_resource *resource, |
| 3377 | uint32_t id, |
| 3378 | struct wl_resource *surface_resource, |
| 3379 | struct wl_resource *parent_resource, |
| 3380 | struct wl_resource *seat_resource, |
| 3381 | uint32_t serial, |
| 3382 | int32_t x, int32_t y, uint32_t flags) |
| 3383 | { |
| 3384 | struct weston_surface *surface = |
| 3385 | wl_resource_get_user_data(surface_resource); |
| 3386 | struct desktop_shell *shell = wl_resource_get_user_data(resource); |
| 3387 | struct shell_surface *shsurf; |
| 3388 | struct weston_surface *parent; |
| 3389 | struct shell_seat *seat; |
| 3390 | |
| 3391 | if (get_shell_surface(surface)) { |
| 3392 | wl_resource_post_error(surface_resource, |
| 3393 | WL_DISPLAY_ERROR_INVALID_OBJECT, |
| 3394 | "desktop_shell::get_shell_surface already requested"); |
| 3395 | return; |
| 3396 | } |
| 3397 | |
| 3398 | if (!parent_resource) { |
| 3399 | wl_resource_post_error(surface_resource, |
| 3400 | WL_DISPLAY_ERROR_INVALID_OBJECT, |
| 3401 | "xdg_shell::get_xdg_popup requires a parent shell surface"); |
| 3402 | } |
| 3403 | |
| 3404 | parent = wl_resource_get_user_data(parent_resource); |
| 3405 | seat = get_shell_seat(wl_resource_get_user_data(seat_resource));; |
| 3406 | |
| 3407 | shsurf = create_xdg_popup(shell, surface, &xdg_popup_client, |
| 3408 | parent, seat, serial, x, y); |
| 3409 | if (!shsurf) { |
| 3410 | wl_resource_post_error(surface_resource, |
| 3411 | WL_DISPLAY_ERROR_INVALID_OBJECT, |
| 3412 | "surface->configure already set"); |
| 3413 | return; |
| 3414 | } |
| 3415 | |
| 3416 | shsurf->resource = |
| 3417 | wl_resource_create(client, |
| 3418 | &xdg_popup_interface, 1, id); |
| 3419 | wl_resource_set_implementation(shsurf->resource, |
| 3420 | &xdg_popup_implementation, |
| 3421 | shsurf, shell_destroy_shell_surface); |
| 3422 | } |
| 3423 | |
| 3424 | static bool |
| 3425 | shell_surface_is_xdg_popup(struct shell_surface *shsurf) |
| 3426 | { |
| 3427 | return wl_resource_instance_of(shsurf->resource, |
| 3428 | &xdg_popup_interface, |
| 3429 | &xdg_popup_implementation); |
| 3430 | } |
| 3431 | |
| 3432 | static const struct xdg_shell_interface xdg_implementation = { |
| 3433 | xdg_use_unstable_version, |
| 3434 | xdg_get_xdg_surface, |
| 3435 | xdg_get_xdg_popup |
| 3436 | }; |
| 3437 | |
| 3438 | static int |
| 3439 | xdg_shell_unversioned_dispatch(const void *implementation, |
| 3440 | void *_target, uint32_t opcode, |
| 3441 | const struct wl_message *message, |
| 3442 | union wl_argument *args) |
| 3443 | { |
| 3444 | struct wl_resource *resource = _target; |
| 3445 | struct desktop_shell *shell = wl_resource_get_user_data(resource); |
| 3446 | |
| 3447 | if (opcode != 0) { |
| 3448 | wl_resource_post_error(resource, |
| 3449 | WL_DISPLAY_ERROR_INVALID_OBJECT, |
| 3450 | "must call use_unstable_version first"); |
| 3451 | return 0; |
| 3452 | } |
| 3453 | |
| 3454 | #define XDG_SERVER_VERSION 1 |
| 3455 | |
Kristian Høgsberg | 8d344a0 | 2013-12-08 22:27:11 -0800 | [diff] [blame] | 3456 | static_assert(XDG_SERVER_VERSION == XDG_SHELL_VERSION_CURRENT, |
| 3457 | "shell implementation doesn't match protocol version"); |
| 3458 | |
Rafael Antognolli | e2a3455 | 2013-12-03 15:35:45 -0200 | [diff] [blame] | 3459 | if (args[0].i != XDG_SERVER_VERSION) { |
| 3460 | wl_resource_post_error(resource, |
| 3461 | WL_DISPLAY_ERROR_INVALID_OBJECT, |
| 3462 | "incompatible version, server is %d " |
| 3463 | "client wants %d", |
| 3464 | XDG_SERVER_VERSION, args[0].i); |
| 3465 | return 0; |
| 3466 | } |
| 3467 | |
| 3468 | wl_resource_set_implementation(resource, &xdg_implementation, |
| 3469 | shell, NULL); |
| 3470 | |
| 3471 | return 1; |
| 3472 | } |
| 3473 | |
| 3474 | /* end of xdg-shell implementation */ |
| 3475 | /***********************************/ |
| 3476 | |
Kristian Høgsberg | 0793756 | 2011-04-12 17:25:42 -0400 | [diff] [blame] | 3477 | static void |
Ander Conselvan de Oliveira | 859e885 | 2013-02-21 18:35:21 +0200 | [diff] [blame] | 3478 | shell_fade(struct desktop_shell *shell, enum fade_type type); |
| 3479 | |
| 3480 | static int |
| 3481 | screensaver_timeout(void *data) |
| 3482 | { |
| 3483 | struct desktop_shell *shell = data; |
| 3484 | |
| 3485 | shell_fade(shell, FADE_OUT); |
| 3486 | |
| 3487 | return 1; |
| 3488 | } |
| 3489 | |
| 3490 | static void |
Kristian Høgsberg | 8334bc1 | 2012-01-03 10:29:47 -0500 | [diff] [blame] | 3491 | handle_screensaver_sigchld(struct weston_process *proc, int status) |
Pekka Paalanen | 18027e5 | 2011-12-02 16:31:49 +0200 | [diff] [blame] | 3492 | { |
Ander Conselvan de Oliveira | 18639f8 | 2013-02-15 18:44:19 +0200 | [diff] [blame] | 3493 | struct desktop_shell *shell = |
| 3494 | container_of(proc, struct desktop_shell, screensaver.process); |
Ander Conselvan de Oliveira | 18639f8 | 2013-02-15 18:44:19 +0200 | [diff] [blame] | 3495 | |
Pekka Paalanen | 18027e5 | 2011-12-02 16:31:49 +0200 | [diff] [blame] | 3496 | proc->pid = 0; |
Ander Conselvan de Oliveira | 18639f8 | 2013-02-15 18:44:19 +0200 | [diff] [blame] | 3497 | |
| 3498 | if (shell->locked) |
Ander Conselvan de Oliveira | b17537e | 2013-02-22 14:16:18 +0200 | [diff] [blame] | 3499 | weston_compositor_sleep(shell->compositor); |
Pekka Paalanen | 18027e5 | 2011-12-02 16:31:49 +0200 | [diff] [blame] | 3500 | } |
| 3501 | |
| 3502 | static void |
Tiago Vignatti | be14326 | 2012-04-16 17:31:41 +0300 | [diff] [blame] | 3503 | launch_screensaver(struct desktop_shell *shell) |
Pekka Paalanen | 77346a6 | 2011-11-30 16:26:35 +0200 | [diff] [blame] | 3504 | { |
| 3505 | if (shell->screensaver.binding) |
| 3506 | return; |
| 3507 | |
Ander Conselvan de Oliveira | dda9d78 | 2013-02-22 14:16:19 +0200 | [diff] [blame] | 3508 | if (!shell->screensaver.path) { |
| 3509 | weston_compositor_sleep(shell->compositor); |
Pekka Paalanen | e955f1e | 2011-12-07 11:49:52 +0200 | [diff] [blame] | 3510 | return; |
Ander Conselvan de Oliveira | dda9d78 | 2013-02-22 14:16:19 +0200 | [diff] [blame] | 3511 | } |
Pekka Paalanen | e955f1e | 2011-12-07 11:49:52 +0200 | [diff] [blame] | 3512 | |
Kristian Høgsberg | 32bed57 | 2012-03-01 17:11:36 -0500 | [diff] [blame] | 3513 | if (shell->screensaver.process.pid != 0) { |
Martin Minarik | 6d11836 | 2012-06-07 18:01:59 +0200 | [diff] [blame] | 3514 | weston_log("old screensaver still running\n"); |
Kristian Høgsberg | 32bed57 | 2012-03-01 17:11:36 -0500 | [diff] [blame] | 3515 | return; |
| 3516 | } |
| 3517 | |
Kristian Høgsberg | 8334bc1 | 2012-01-03 10:29:47 -0500 | [diff] [blame] | 3518 | weston_client_launch(shell->compositor, |
Pekka Paalanen | 18027e5 | 2011-12-02 16:31:49 +0200 | [diff] [blame] | 3519 | &shell->screensaver.process, |
Pekka Paalanen | e955f1e | 2011-12-07 11:49:52 +0200 | [diff] [blame] | 3520 | shell->screensaver.path, |
Pekka Paalanen | 18027e5 | 2011-12-02 16:31:49 +0200 | [diff] [blame] | 3521 | handle_screensaver_sigchld); |
Pekka Paalanen | 77346a6 | 2011-11-30 16:26:35 +0200 | [diff] [blame] | 3522 | } |
| 3523 | |
| 3524 | static void |
Tiago Vignatti | be14326 | 2012-04-16 17:31:41 +0300 | [diff] [blame] | 3525 | terminate_screensaver(struct desktop_shell *shell) |
Pekka Paalanen | 77346a6 | 2011-11-30 16:26:35 +0200 | [diff] [blame] | 3526 | { |
Pekka Paalanen | 18027e5 | 2011-12-02 16:31:49 +0200 | [diff] [blame] | 3527 | if (shell->screensaver.process.pid == 0) |
| 3528 | return; |
| 3529 | |
| 3530 | kill(shell->screensaver.process.pid, SIGTERM); |
Pekka Paalanen | 77346a6 | 2011-11-30 16:26:35 +0200 | [diff] [blame] | 3531 | } |
| 3532 | |
| 3533 | static void |
Jason Ekstrand | 918f2dd | 2013-12-02 21:01:53 -0600 | [diff] [blame] | 3534 | configure_static_view(struct weston_view *ev, struct weston_layer *layer) |
Kristian Høgsberg | 962342c | 2012-06-26 16:29:50 -0400 | [diff] [blame] | 3535 | { |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 3536 | struct weston_view *v, *next; |
Kristian Høgsberg | 962342c | 2012-06-26 16:29:50 -0400 | [diff] [blame] | 3537 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 3538 | wl_list_for_each_safe(v, next, &layer->view_list, layer_link) { |
| 3539 | if (v->output == ev->output && v != ev) { |
| 3540 | weston_view_unmap(v); |
| 3541 | v->surface->configure = NULL; |
Kristian Høgsberg | 962342c | 2012-06-26 16:29:50 -0400 | [diff] [blame] | 3542 | } |
| 3543 | } |
| 3544 | |
Jason Ekstrand | 918f2dd | 2013-12-02 21:01:53 -0600 | [diff] [blame] | 3545 | weston_view_set_position(ev, ev->output->x, ev->output->y); |
Kristian Høgsberg | 962342c | 2012-06-26 16:29:50 -0400 | [diff] [blame] | 3546 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 3547 | if (wl_list_empty(&ev->layer_link)) { |
| 3548 | wl_list_insert(&layer->view_list, &ev->layer_link); |
| 3549 | weston_compositor_schedule_repaint(ev->surface->compositor); |
Kristian Høgsberg | 962342c | 2012-06-26 16:29:50 -0400 | [diff] [blame] | 3550 | } |
| 3551 | } |
| 3552 | |
| 3553 | static void |
Jason Ekstrand | 918f2dd | 2013-12-02 21:01:53 -0600 | [diff] [blame] | 3554 | 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] | 3555 | { |
Giulio Camuffo | 7fe01b1 | 2013-03-28 18:02:42 +0100 | [diff] [blame] | 3556 | struct desktop_shell *shell = es->configure_private; |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 3557 | struct weston_view *view; |
Kristian Høgsberg | af7b1ff | 2012-06-26 21:19:23 -0400 | [diff] [blame] | 3558 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 3559 | view = container_of(es->views.next, struct weston_view, surface_link); |
| 3560 | |
Jason Ekstrand | 918f2dd | 2013-12-02 21:01:53 -0600 | [diff] [blame] | 3561 | configure_static_view(view, &shell->background_layer); |
Kristian Høgsberg | af7b1ff | 2012-06-26 21:19:23 -0400 | [diff] [blame] | 3562 | } |
| 3563 | |
| 3564 | static void |
Kristian Høgsberg | 7584062 | 2011-09-06 13:48:16 -0400 | [diff] [blame] | 3565 | desktop_shell_set_background(struct wl_client *client, |
| 3566 | struct wl_resource *resource, |
Benjamin Franzke | d0f79ab | 2011-11-22 12:43:52 +0100 | [diff] [blame] | 3567 | struct wl_resource *output_resource, |
Kristian Høgsberg | 7584062 | 2011-09-06 13:48:16 -0400 | [diff] [blame] | 3568 | struct wl_resource *surface_resource) |
| 3569 | { |
Jason Ekstrand | 651f00e | 2013-06-14 10:07:54 -0500 | [diff] [blame] | 3570 | struct desktop_shell *shell = wl_resource_get_user_data(resource); |
Jason Ekstrand | 0f2ef7e | 2013-06-14 10:07:53 -0500 | [diff] [blame] | 3571 | struct weston_surface *surface = |
| 3572 | wl_resource_get_user_data(surface_resource); |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 3573 | struct weston_view *view, *next; |
Kristian Høgsberg | 7584062 | 2011-09-06 13:48:16 -0400 | [diff] [blame] | 3574 | |
Kristian Høgsberg | 962342c | 2012-06-26 16:29:50 -0400 | [diff] [blame] | 3575 | if (surface->configure) { |
| 3576 | wl_resource_post_error(surface_resource, |
| 3577 | WL_DISPLAY_ERROR_INVALID_OBJECT, |
| 3578 | "surface role already assigned"); |
| 3579 | return; |
| 3580 | } |
Benjamin Franzke | d0f79ab | 2011-11-22 12:43:52 +0100 | [diff] [blame] | 3581 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 3582 | wl_list_for_each_safe(view, next, &surface->views, surface_link) |
| 3583 | weston_view_destroy(view); |
| 3584 | view = weston_view_create(surface); |
| 3585 | |
Kristian Høgsberg | 962342c | 2012-06-26 16:29:50 -0400 | [diff] [blame] | 3586 | surface->configure = background_configure; |
Giulio Camuffo | 7fe01b1 | 2013-03-28 18:02:42 +0100 | [diff] [blame] | 3587 | surface->configure_private = shell; |
Jason Ekstrand | a0d2dde | 2013-06-14 10:08:01 -0500 | [diff] [blame] | 3588 | surface->output = wl_resource_get_user_data(output_resource); |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 3589 | view->output = surface->output; |
Kristian Høgsberg | eae5de7 | 2012-04-11 22:42:15 -0400 | [diff] [blame] | 3590 | desktop_shell_send_configure(resource, 0, |
Kristian Høgsberg | 0b5cd0c | 2012-03-04 21:57:37 -0500 | [diff] [blame] | 3591 | surface_resource, |
Scott Moreau | 1bad5db | 2012-08-18 01:04:05 -0600 | [diff] [blame] | 3592 | surface->output->width, |
| 3593 | surface->output->height); |
Kristian Høgsberg | 7584062 | 2011-09-06 13:48:16 -0400 | [diff] [blame] | 3594 | } |
| 3595 | |
| 3596 | static void |
Jason Ekstrand | 918f2dd | 2013-12-02 21:01:53 -0600 | [diff] [blame] | 3597 | 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] | 3598 | { |
Giulio Camuffo | 7fe01b1 | 2013-03-28 18:02:42 +0100 | [diff] [blame] | 3599 | struct desktop_shell *shell = es->configure_private; |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 3600 | struct weston_view *view; |
Kristian Høgsberg | af7b1ff | 2012-06-26 21:19:23 -0400 | [diff] [blame] | 3601 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 3602 | view = container_of(es->views.next, struct weston_view, surface_link); |
| 3603 | |
Jason Ekstrand | 918f2dd | 2013-12-02 21:01:53 -0600 | [diff] [blame] | 3604 | configure_static_view(view, &shell->panel_layer); |
Kristian Høgsberg | af7b1ff | 2012-06-26 21:19:23 -0400 | [diff] [blame] | 3605 | } |
| 3606 | |
| 3607 | static void |
Kristian Høgsberg | 7584062 | 2011-09-06 13:48:16 -0400 | [diff] [blame] | 3608 | desktop_shell_set_panel(struct wl_client *client, |
| 3609 | struct wl_resource *resource, |
Benjamin Franzke | d0f79ab | 2011-11-22 12:43:52 +0100 | [diff] [blame] | 3610 | struct wl_resource *output_resource, |
Kristian Høgsberg | 7584062 | 2011-09-06 13:48:16 -0400 | [diff] [blame] | 3611 | struct wl_resource *surface_resource) |
| 3612 | { |
Jason Ekstrand | 651f00e | 2013-06-14 10:07:54 -0500 | [diff] [blame] | 3613 | struct desktop_shell *shell = wl_resource_get_user_data(resource); |
Jason Ekstrand | 0f2ef7e | 2013-06-14 10:07:53 -0500 | [diff] [blame] | 3614 | struct weston_surface *surface = |
| 3615 | wl_resource_get_user_data(surface_resource); |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 3616 | struct weston_view *view, *next; |
Kristian Høgsberg | 7584062 | 2011-09-06 13:48:16 -0400 | [diff] [blame] | 3617 | |
Kristian Høgsberg | af7b1ff | 2012-06-26 21:19:23 -0400 | [diff] [blame] | 3618 | if (surface->configure) { |
| 3619 | wl_resource_post_error(surface_resource, |
| 3620 | WL_DISPLAY_ERROR_INVALID_OBJECT, |
| 3621 | "surface role already assigned"); |
| 3622 | return; |
| 3623 | } |
Benjamin Franzke | d0f79ab | 2011-11-22 12:43:52 +0100 | [diff] [blame] | 3624 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 3625 | wl_list_for_each_safe(view, next, &surface->views, surface_link) |
| 3626 | weston_view_destroy(view); |
| 3627 | view = weston_view_create(surface); |
| 3628 | |
Kristian Høgsberg | af7b1ff | 2012-06-26 21:19:23 -0400 | [diff] [blame] | 3629 | surface->configure = panel_configure; |
Giulio Camuffo | 7fe01b1 | 2013-03-28 18:02:42 +0100 | [diff] [blame] | 3630 | surface->configure_private = shell; |
Jason Ekstrand | a0d2dde | 2013-06-14 10:08:01 -0500 | [diff] [blame] | 3631 | surface->output = wl_resource_get_user_data(output_resource); |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 3632 | view->output = surface->output; |
Kristian Høgsberg | eae5de7 | 2012-04-11 22:42:15 -0400 | [diff] [blame] | 3633 | desktop_shell_send_configure(resource, 0, |
Kristian Høgsberg | af7b1ff | 2012-06-26 21:19:23 -0400 | [diff] [blame] | 3634 | surface_resource, |
Scott Moreau | 1bad5db | 2012-08-18 01:04:05 -0600 | [diff] [blame] | 3635 | surface->output->width, |
| 3636 | surface->output->height); |
Kristian Høgsberg | 7584062 | 2011-09-06 13:48:16 -0400 | [diff] [blame] | 3637 | } |
| 3638 | |
Pekka Paalanen | 9ef3e01 | 2011-11-15 13:34:48 +0200 | [diff] [blame] | 3639 | static void |
Jason Ekstrand | 918f2dd | 2013-12-02 21:01:53 -0600 | [diff] [blame] | 3640 | 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] | 3641 | { |
Giulio Camuffo | 7fe01b1 | 2013-03-28 18:02:42 +0100 | [diff] [blame] | 3642 | struct desktop_shell *shell = surface->configure_private; |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 3643 | struct weston_view *view; |
| 3644 | |
| 3645 | view = container_of(surface->views.next, struct weston_view, surface_link); |
Kristian Høgsberg | 730c94d | 2012-06-26 21:44:35 -0400 | [diff] [blame] | 3646 | |
Jason Ekstrand | 918f2dd | 2013-12-02 21:01:53 -0600 | [diff] [blame] | 3647 | if (surface->width == 0) |
Giulio Camuffo | 184df50 | 2013-02-21 11:29:21 +0100 | [diff] [blame] | 3648 | return; |
| 3649 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 3650 | center_on_output(view, get_default_output(shell->compositor)); |
Kristian Høgsberg | 730c94d | 2012-06-26 21:44:35 -0400 | [diff] [blame] | 3651 | |
| 3652 | if (!weston_surface_is_mapped(surface)) { |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 3653 | wl_list_insert(&shell->lock_layer.view_list, |
| 3654 | &view->layer_link); |
| 3655 | weston_view_update_transform(view); |
Ander Conselvan de Oliveira | 87524b6 | 2013-02-21 18:35:22 +0200 | [diff] [blame] | 3656 | shell_fade(shell, FADE_IN); |
Kristian Høgsberg | 730c94d | 2012-06-26 21:44:35 -0400 | [diff] [blame] | 3657 | } |
| 3658 | } |
| 3659 | |
| 3660 | static void |
Kristian Høgsberg | 27e3052 | 2012-04-11 23:18:23 -0400 | [diff] [blame] | 3661 | handle_lock_surface_destroy(struct wl_listener *listener, void *data) |
Kristian Høgsberg | 1ec0c31 | 2011-11-15 16:39:55 -0500 | [diff] [blame] | 3662 | { |
Tiago Vignatti | be14326 | 2012-04-16 17:31:41 +0300 | [diff] [blame] | 3663 | struct desktop_shell *shell = |
| 3664 | container_of(listener, struct desktop_shell, lock_surface_listener); |
Kristian Høgsberg | 1ec0c31 | 2011-11-15 16:39:55 -0500 | [diff] [blame] | 3665 | |
Martin Minarik | 6d11836 | 2012-06-07 18:01:59 +0200 | [diff] [blame] | 3666 | weston_log("lock surface gone\n"); |
Kristian Høgsberg | 1ec0c31 | 2011-11-15 16:39:55 -0500 | [diff] [blame] | 3667 | shell->lock_surface = NULL; |
| 3668 | } |
| 3669 | |
| 3670 | static void |
Pekka Paalanen | 9ef3e01 | 2011-11-15 13:34:48 +0200 | [diff] [blame] | 3671 | desktop_shell_set_lock_surface(struct wl_client *client, |
| 3672 | struct wl_resource *resource, |
| 3673 | struct wl_resource *surface_resource) |
| 3674 | { |
Jason Ekstrand | 651f00e | 2013-06-14 10:07:54 -0500 | [diff] [blame] | 3675 | struct desktop_shell *shell = wl_resource_get_user_data(resource); |
Jason Ekstrand | 0f2ef7e | 2013-06-14 10:07:53 -0500 | [diff] [blame] | 3676 | struct weston_surface *surface = |
| 3677 | wl_resource_get_user_data(surface_resource); |
Pekka Paalanen | 9826223 | 2011-12-01 10:42:22 +0200 | [diff] [blame] | 3678 | |
Pekka Paalanen | f0fc70d | 2011-11-15 13:34:54 +0200 | [diff] [blame] | 3679 | shell->prepare_event_sent = false; |
Kristian Høgsberg | af867cc | 2011-11-15 13:34:49 +0200 | [diff] [blame] | 3680 | |
Pekka Paalanen | f0fc70d | 2011-11-15 13:34:54 +0200 | [diff] [blame] | 3681 | if (!shell->locked) |
| 3682 | return; |
| 3683 | |
Pekka Paalanen | 9826223 | 2011-12-01 10:42:22 +0200 | [diff] [blame] | 3684 | shell->lock_surface = surface; |
Pekka Paalanen | f0fc70d | 2011-11-15 13:34:54 +0200 | [diff] [blame] | 3685 | |
Kristian Høgsberg | 27e3052 | 2012-04-11 23:18:23 -0400 | [diff] [blame] | 3686 | shell->lock_surface_listener.notify = handle_lock_surface_destroy; |
Jason Ekstrand | 651f00e | 2013-06-14 10:07:54 -0500 | [diff] [blame] | 3687 | wl_signal_add(&surface->destroy_signal, |
Kristian Høgsberg | 27e3052 | 2012-04-11 23:18:23 -0400 | [diff] [blame] | 3688 | &shell->lock_surface_listener); |
Pekka Paalanen | 57da4a8 | 2011-11-23 16:42:16 +0200 | [diff] [blame] | 3689 | |
Kristian Høgsberg | aa2ee8b | 2013-10-30 15:49:45 -0700 | [diff] [blame] | 3690 | weston_view_create(surface); |
Kristian Høgsberg | 730c94d | 2012-06-26 21:44:35 -0400 | [diff] [blame] | 3691 | surface->configure = lock_surface_configure; |
Giulio Camuffo | 7fe01b1 | 2013-03-28 18:02:42 +0100 | [diff] [blame] | 3692 | surface->configure_private = shell; |
Pekka Paalanen | f0fc70d | 2011-11-15 13:34:54 +0200 | [diff] [blame] | 3693 | } |
| 3694 | |
| 3695 | static void |
Tiago Vignatti | be14326 | 2012-04-16 17:31:41 +0300 | [diff] [blame] | 3696 | resume_desktop(struct desktop_shell *shell) |
Pekka Paalanen | f0fc70d | 2011-11-15 13:34:54 +0200 | [diff] [blame] | 3697 | { |
Kristian Høgsberg | 4476aaf | 2012-06-25 14:03:13 -0400 | [diff] [blame] | 3698 | struct workspace *ws = get_current_workspace(shell); |
Pekka Paalanen | 77346a6 | 2011-11-30 16:26:35 +0200 | [diff] [blame] | 3699 | |
Pekka Paalanen | 77346a6 | 2011-11-30 16:26:35 +0200 | [diff] [blame] | 3700 | terminate_screensaver(shell); |
Pekka Paalanen | f0fc70d | 2011-11-15 13:34:54 +0200 | [diff] [blame] | 3701 | |
Kristian Høgsberg | 3be2ce9 | 2012-02-29 12:42:35 -0500 | [diff] [blame] | 3702 | wl_list_remove(&shell->lock_layer.link); |
| 3703 | wl_list_insert(&shell->compositor->cursor_layer.link, |
| 3704 | &shell->fullscreen_layer.link); |
| 3705 | wl_list_insert(&shell->fullscreen_layer.link, |
| 3706 | &shell->panel_layer.link); |
Philipp Brüschweiler | 711fda8 | 2012-08-09 18:50:43 +0200 | [diff] [blame] | 3707 | if (shell->showing_input_panels) { |
| 3708 | wl_list_insert(&shell->panel_layer.link, |
| 3709 | &shell->input_panel_layer.link); |
| 3710 | wl_list_insert(&shell->input_panel_layer.link, |
| 3711 | &ws->layer.link); |
| 3712 | } else { |
| 3713 | wl_list_insert(&shell->panel_layer.link, &ws->layer.link); |
| 3714 | } |
Pekka Paalanen | f0fc70d | 2011-11-15 13:34:54 +0200 | [diff] [blame] | 3715 | |
Kristian Høgsberg | 2f5faff | 2012-07-31 16:36:34 -0400 | [diff] [blame] | 3716 | restore_focus_state(shell, get_current_workspace(shell)); |
Jonas Ådahl | 0476974 | 2012-06-13 00:01:24 +0200 | [diff] [blame] | 3717 | |
Pekka Paalanen | f0fc70d | 2011-11-15 13:34:54 +0200 | [diff] [blame] | 3718 | shell->locked = false; |
Ander Conselvan de Oliveira | 87524b6 | 2013-02-21 18:35:22 +0200 | [diff] [blame] | 3719 | shell_fade(shell, FADE_IN); |
Pekka Paalanen | fc6d91a | 2012-02-10 15:33:10 +0200 | [diff] [blame] | 3720 | weston_compositor_damage_all(shell->compositor); |
Pekka Paalanen | 9ef3e01 | 2011-11-15 13:34:48 +0200 | [diff] [blame] | 3721 | } |
| 3722 | |
| 3723 | static void |
| 3724 | desktop_shell_unlock(struct wl_client *client, |
| 3725 | struct wl_resource *resource) |
| 3726 | { |
Jason Ekstrand | 651f00e | 2013-06-14 10:07:54 -0500 | [diff] [blame] | 3727 | struct desktop_shell *shell = wl_resource_get_user_data(resource); |
Pekka Paalanen | 9ef3e01 | 2011-11-15 13:34:48 +0200 | [diff] [blame] | 3728 | |
Pekka Paalanen | 9ef3e01 | 2011-11-15 13:34:48 +0200 | [diff] [blame] | 3729 | shell->prepare_event_sent = false; |
Pekka Paalanen | f0fc70d | 2011-11-15 13:34:54 +0200 | [diff] [blame] | 3730 | |
| 3731 | if (shell->locked) |
| 3732 | resume_desktop(shell); |
Pekka Paalanen | 9ef3e01 | 2011-11-15 13:34:48 +0200 | [diff] [blame] | 3733 | } |
| 3734 | |
Kristian Høgsberg | d56bd90 | 2012-06-05 09:58:51 -0400 | [diff] [blame] | 3735 | static void |
Ander Conselvan de Oliveira | b9d2a0f | 2012-06-28 18:08:05 +0300 | [diff] [blame] | 3736 | desktop_shell_set_grab_surface(struct wl_client *client, |
Kristian Høgsberg | d56bd90 | 2012-06-05 09:58:51 -0400 | [diff] [blame] | 3737 | struct wl_resource *resource, |
| 3738 | struct wl_resource *surface_resource) |
| 3739 | { |
Jason Ekstrand | 651f00e | 2013-06-14 10:07:54 -0500 | [diff] [blame] | 3740 | struct desktop_shell *shell = wl_resource_get_user_data(resource); |
Kristian Høgsberg | d56bd90 | 2012-06-05 09:58:51 -0400 | [diff] [blame] | 3741 | |
Jason Ekstrand | 0f2ef7e | 2013-06-14 10:07:53 -0500 | [diff] [blame] | 3742 | shell->grab_surface = wl_resource_get_user_data(surface_resource); |
Kristian Høgsberg | 48588f8 | 2013-10-24 15:51:35 -0700 | [diff] [blame] | 3743 | weston_view_create(shell->grab_surface); |
Kristian Høgsberg | d56bd90 | 2012-06-05 09:58:51 -0400 | [diff] [blame] | 3744 | } |
| 3745 | |
Pekka Paalanen | 79346ab | 2013-05-22 18:03:09 +0300 | [diff] [blame] | 3746 | static void |
| 3747 | desktop_shell_desktop_ready(struct wl_client *client, |
| 3748 | struct wl_resource *resource) |
| 3749 | { |
Jason Ekstrand | 651f00e | 2013-06-14 10:07:54 -0500 | [diff] [blame] | 3750 | struct desktop_shell *shell = wl_resource_get_user_data(resource); |
Pekka Paalanen | 79346ab | 2013-05-22 18:03:09 +0300 | [diff] [blame] | 3751 | |
| 3752 | shell_fade_startup(shell); |
| 3753 | } |
| 3754 | |
Kristian Høgsberg | 7584062 | 2011-09-06 13:48:16 -0400 | [diff] [blame] | 3755 | static const struct desktop_shell_interface desktop_shell_implementation = { |
| 3756 | desktop_shell_set_background, |
Pekka Paalanen | 9ef3e01 | 2011-11-15 13:34:48 +0200 | [diff] [blame] | 3757 | desktop_shell_set_panel, |
| 3758 | desktop_shell_set_lock_surface, |
Kristian Høgsberg | d56bd90 | 2012-06-05 09:58:51 -0400 | [diff] [blame] | 3759 | desktop_shell_unlock, |
Pekka Paalanen | 79346ab | 2013-05-22 18:03:09 +0300 | [diff] [blame] | 3760 | desktop_shell_set_grab_surface, |
| 3761 | desktop_shell_desktop_ready |
Kristian Høgsberg | 7584062 | 2011-09-06 13:48:16 -0400 | [diff] [blame] | 3762 | }; |
| 3763 | |
Pekka Paalanen | 92a0dc4 | 2011-11-28 15:34:13 +0200 | [diff] [blame] | 3764 | static enum shell_surface_type |
Kristian Høgsberg | 8334bc1 | 2012-01-03 10:29:47 -0500 | [diff] [blame] | 3765 | get_shell_surface_type(struct weston_surface *surface) |
Pekka Paalanen | 92a0dc4 | 2011-11-28 15:34:13 +0200 | [diff] [blame] | 3766 | { |
| 3767 | struct shell_surface *shsurf; |
| 3768 | |
| 3769 | shsurf = get_shell_surface(surface); |
| 3770 | if (!shsurf) |
Pekka Paalanen | 9826223 | 2011-12-01 10:42:22 +0200 | [diff] [blame] | 3771 | return SHELL_SURFACE_NONE; |
Pekka Paalanen | 92a0dc4 | 2011-11-28 15:34:13 +0200 | [diff] [blame] | 3772 | return shsurf->type; |
| 3773 | } |
| 3774 | |
Kristian Høgsberg | 7584062 | 2011-09-06 13:48:16 -0400 | [diff] [blame] | 3775 | static void |
Kristian Høgsberg | e314875 | 2013-05-06 23:19:49 -0400 | [diff] [blame] | 3776 | 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] | 3777 | { |
Rafal Mielniczuk | b2917a2 | 2014-01-05 20:04:59 +0100 | [diff] [blame] | 3778 | struct weston_surface *focus; |
Pekka Paalanen | 01388e2 | 2013-04-25 13:57:44 +0300 | [diff] [blame] | 3779 | struct weston_surface *surface; |
Kristian Høgsberg | 938b8fa | 2012-05-18 13:46:27 -0400 | [diff] [blame] | 3780 | struct shell_surface *shsurf; |
Kristian Høgsberg | d2abb83 | 2011-11-23 10:52:40 -0500 | [diff] [blame] | 3781 | |
Rafal Mielniczuk | b2917a2 | 2014-01-05 20:04:59 +0100 | [diff] [blame] | 3782 | if (seat->pointer->focus == NULL) |
| 3783 | return; |
| 3784 | |
| 3785 | focus = seat->pointer->focus->surface; |
| 3786 | |
Pekka Paalanen | 01388e2 | 2013-04-25 13:57:44 +0300 | [diff] [blame] | 3787 | surface = weston_surface_get_main_surface(focus); |
Benjamin Franzke | d0f79ab | 2011-11-22 12:43:52 +0100 | [diff] [blame] | 3788 | if (surface == NULL) |
| 3789 | return; |
Kristian Høgsberg | 0793756 | 2011-04-12 17:25:42 -0400 | [diff] [blame] | 3790 | |
Kristian Høgsberg | 938b8fa | 2012-05-18 13:46:27 -0400 | [diff] [blame] | 3791 | shsurf = get_shell_surface(surface); |
Rafael Antognolli | 03b1659 | 2013-12-03 15:35:42 -0200 | [diff] [blame] | 3792 | if (shsurf == NULL || shsurf->state.fullscreen || |
| 3793 | shsurf->state.maximized) |
Kristian Høgsberg | 938b8fa | 2012-05-18 13:46:27 -0400 | [diff] [blame] | 3794 | return; |
| 3795 | |
Kristian Høgsberg | 938b8fa | 2012-05-18 13:46:27 -0400 | [diff] [blame] | 3796 | surface_move(shsurf, (struct weston_seat *) seat); |
Kristian Høgsberg | 0793756 | 2011-04-12 17:25:42 -0400 | [diff] [blame] | 3797 | } |
| 3798 | |
| 3799 | static void |
Rafael Antognolli | ea997ac | 2013-12-03 15:35:48 -0200 | [diff] [blame] | 3800 | maximize_binding(struct weston_seat *seat, uint32_t time, uint32_t button, void *data) |
| 3801 | { |
| 3802 | struct weston_surface *focus = seat->pointer->focus->surface; |
| 3803 | struct weston_surface *surface; |
| 3804 | struct shell_surface *shsurf; |
| 3805 | |
| 3806 | surface = weston_surface_get_main_surface(focus); |
| 3807 | if (surface == NULL) |
| 3808 | return; |
| 3809 | |
| 3810 | shsurf = get_shell_surface(surface); |
| 3811 | if (shsurf == NULL) |
| 3812 | return; |
| 3813 | |
| 3814 | if (!shell_surface_is_xdg_surface(shsurf)) |
| 3815 | return; |
| 3816 | |
| 3817 | if (shsurf->state.maximized) |
| 3818 | xdg_surface_send_request_unset_maximized(shsurf->resource); |
| 3819 | else |
| 3820 | xdg_surface_send_request_set_maximized(shsurf->resource); |
| 3821 | } |
| 3822 | |
| 3823 | static void |
| 3824 | fullscreen_binding(struct weston_seat *seat, uint32_t time, uint32_t button, void *data) |
| 3825 | { |
| 3826 | struct weston_surface *focus = seat->pointer->focus->surface; |
| 3827 | struct weston_surface *surface; |
| 3828 | struct shell_surface *shsurf; |
| 3829 | |
| 3830 | surface = weston_surface_get_main_surface(focus); |
| 3831 | if (surface == NULL) |
| 3832 | return; |
| 3833 | |
| 3834 | shsurf = get_shell_surface(surface); |
| 3835 | if (shsurf == NULL) |
| 3836 | return; |
| 3837 | |
| 3838 | if (!shell_surface_is_xdg_surface(shsurf)) |
| 3839 | return; |
| 3840 | |
| 3841 | if (shsurf->state.fullscreen) |
| 3842 | xdg_surface_send_request_unset_fullscreen(shsurf->resource); |
| 3843 | else |
| 3844 | xdg_surface_send_request_set_fullscreen(shsurf->resource); |
| 3845 | } |
| 3846 | |
| 3847 | static void |
Neil Roberts | aba0f25 | 2013-10-03 16:43:05 +0100 | [diff] [blame] | 3848 | touch_move_binding(struct weston_seat *seat, uint32_t time, void *data) |
| 3849 | { |
Kristian Høgsberg | 7ab139c | 2013-10-24 16:21:39 -0700 | [diff] [blame] | 3850 | struct weston_surface *focus = seat->touch->focus->surface; |
Neil Roberts | aba0f25 | 2013-10-03 16:43:05 +0100 | [diff] [blame] | 3851 | struct weston_surface *surface; |
| 3852 | struct shell_surface *shsurf; |
| 3853 | |
| 3854 | surface = weston_surface_get_main_surface(focus); |
| 3855 | if (surface == NULL) |
| 3856 | return; |
| 3857 | |
| 3858 | shsurf = get_shell_surface(surface); |
Rafael Antognolli | 03b1659 | 2013-12-03 15:35:42 -0200 | [diff] [blame] | 3859 | if (shsurf == NULL || shsurf->state.fullscreen || |
| 3860 | shsurf->state.maximized) |
Neil Roberts | aba0f25 | 2013-10-03 16:43:05 +0100 | [diff] [blame] | 3861 | return; |
| 3862 | |
| 3863 | surface_touch_move(shsurf, (struct weston_seat *) seat); |
| 3864 | } |
| 3865 | |
| 3866 | static void |
Kristian Høgsberg | e314875 | 2013-05-06 23:19:49 -0400 | [diff] [blame] | 3867 | 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] | 3868 | { |
Rafal Mielniczuk | b2917a2 | 2014-01-05 20:04:59 +0100 | [diff] [blame] | 3869 | struct weston_surface *focus; |
Pekka Paalanen | 01388e2 | 2013-04-25 13:57:44 +0300 | [diff] [blame] | 3870 | struct weston_surface *surface; |
Kristian Høgsberg | 0793756 | 2011-04-12 17:25:42 -0400 | [diff] [blame] | 3871 | uint32_t edges = 0; |
| 3872 | int32_t x, y; |
Pekka Paalanen | 9d1613e | 2011-11-25 12:09:16 +0200 | [diff] [blame] | 3873 | struct shell_surface *shsurf; |
Kristian Høgsberg | d2abb83 | 2011-11-23 10:52:40 -0500 | [diff] [blame] | 3874 | |
Rafal Mielniczuk | b2917a2 | 2014-01-05 20:04:59 +0100 | [diff] [blame] | 3875 | if (seat->pointer->focus == NULL) |
| 3876 | return; |
| 3877 | |
| 3878 | focus = seat->pointer->focus->surface; |
| 3879 | |
Pekka Paalanen | 01388e2 | 2013-04-25 13:57:44 +0300 | [diff] [blame] | 3880 | surface = weston_surface_get_main_surface(focus); |
Benjamin Franzke | d0f79ab | 2011-11-22 12:43:52 +0100 | [diff] [blame] | 3881 | if (surface == NULL) |
| 3882 | return; |
Pekka Paalanen | 92a0dc4 | 2011-11-28 15:34:13 +0200 | [diff] [blame] | 3883 | |
Pekka Paalanen | 9d1613e | 2011-11-25 12:09:16 +0200 | [diff] [blame] | 3884 | shsurf = get_shell_surface(surface); |
Rafael Antognolli | 03b1659 | 2013-12-03 15:35:42 -0200 | [diff] [blame] | 3885 | if (shsurf == NULL || shsurf->state.fullscreen || |
| 3886 | shsurf->state.maximized) |
Pekka Paalanen | 92a0dc4 | 2011-11-28 15:34:13 +0200 | [diff] [blame] | 3887 | return; |
| 3888 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 3889 | weston_view_from_global(shsurf->view, |
| 3890 | wl_fixed_to_int(seat->pointer->grab_x), |
| 3891 | wl_fixed_to_int(seat->pointer->grab_y), |
| 3892 | &x, &y); |
Kristian Høgsberg | 0793756 | 2011-04-12 17:25:42 -0400 | [diff] [blame] | 3893 | |
Jason Ekstrand | 918f2dd | 2013-12-02 21:01:53 -0600 | [diff] [blame] | 3894 | if (x < shsurf->surface->width / 3) |
Pekka Paalanen | 9d1613e | 2011-11-25 12:09:16 +0200 | [diff] [blame] | 3895 | edges |= WL_SHELL_SURFACE_RESIZE_LEFT; |
Jason Ekstrand | 918f2dd | 2013-12-02 21:01:53 -0600 | [diff] [blame] | 3896 | else if (x < 2 * shsurf->surface->width / 3) |
Kristian Høgsberg | 0793756 | 2011-04-12 17:25:42 -0400 | [diff] [blame] | 3897 | edges |= 0; |
| 3898 | else |
Pekka Paalanen | 9d1613e | 2011-11-25 12:09:16 +0200 | [diff] [blame] | 3899 | edges |= WL_SHELL_SURFACE_RESIZE_RIGHT; |
Kristian Høgsberg | 0793756 | 2011-04-12 17:25:42 -0400 | [diff] [blame] | 3900 | |
Jason Ekstrand | 918f2dd | 2013-12-02 21:01:53 -0600 | [diff] [blame] | 3901 | if (y < shsurf->surface->height / 3) |
Pekka Paalanen | 9d1613e | 2011-11-25 12:09:16 +0200 | [diff] [blame] | 3902 | edges |= WL_SHELL_SURFACE_RESIZE_TOP; |
Jason Ekstrand | 918f2dd | 2013-12-02 21:01:53 -0600 | [diff] [blame] | 3903 | else if (y < 2 * shsurf->surface->height / 3) |
Kristian Høgsberg | 0793756 | 2011-04-12 17:25:42 -0400 | [diff] [blame] | 3904 | edges |= 0; |
| 3905 | else |
Pekka Paalanen | 9d1613e | 2011-11-25 12:09:16 +0200 | [diff] [blame] | 3906 | edges |= WL_SHELL_SURFACE_RESIZE_BOTTOM; |
Kristian Høgsberg | 0793756 | 2011-04-12 17:25:42 -0400 | [diff] [blame] | 3907 | |
Kristian Høgsberg | c1693f2 | 2012-05-22 16:56:23 -0400 | [diff] [blame] | 3908 | surface_resize(shsurf, (struct weston_seat *) seat, edges); |
Kristian Høgsberg | 02ec0a5 | 2011-04-23 13:04:11 -0400 | [diff] [blame] | 3909 | } |
| 3910 | |
| 3911 | static void |
Kristian Høgsberg | e314875 | 2013-05-06 23:19:49 -0400 | [diff] [blame] | 3912 | 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] | 3913 | wl_fixed_t value, void *data) |
Scott Moreau | a3aa9c9 | 2012-03-22 11:01:03 -0600 | [diff] [blame] | 3914 | { |
Jonas Ådahl | b0b87ba | 2012-09-27 18:40:42 +0200 | [diff] [blame] | 3915 | float step = 0.005; |
Scott Moreau | a3aa9c9 | 2012-03-22 11:01:03 -0600 | [diff] [blame] | 3916 | struct shell_surface *shsurf; |
Kristian Høgsberg | 7ab139c | 2013-10-24 16:21:39 -0700 | [diff] [blame] | 3917 | struct weston_surface *focus = seat->pointer->focus->surface; |
Pekka Paalanen | 01388e2 | 2013-04-25 13:57:44 +0300 | [diff] [blame] | 3918 | struct weston_surface *surface; |
Scott Moreau | a3aa9c9 | 2012-03-22 11:01:03 -0600 | [diff] [blame] | 3919 | |
Pekka Paalanen | 01388e2 | 2013-04-25 13:57:44 +0300 | [diff] [blame] | 3920 | /* XXX: broken for windows containing sub-surfaces */ |
| 3921 | surface = weston_surface_get_main_surface(focus); |
Scott Moreau | a3aa9c9 | 2012-03-22 11:01:03 -0600 | [diff] [blame] | 3922 | if (surface == NULL) |
| 3923 | return; |
| 3924 | |
| 3925 | shsurf = get_shell_surface(surface); |
| 3926 | if (!shsurf) |
| 3927 | return; |
| 3928 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 3929 | shsurf->view->alpha -= wl_fixed_to_double(value) * step; |
Scott Moreau | a3aa9c9 | 2012-03-22 11:01:03 -0600 | [diff] [blame] | 3930 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 3931 | if (shsurf->view->alpha > 1.0) |
| 3932 | shsurf->view->alpha = 1.0; |
| 3933 | if (shsurf->view->alpha < step) |
| 3934 | shsurf->view->alpha = step; |
Scott Moreau | a3aa9c9 | 2012-03-22 11:01:03 -0600 | [diff] [blame] | 3935 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 3936 | weston_view_geometry_dirty(shsurf->view); |
Scott Moreau | a3aa9c9 | 2012-03-22 11:01:03 -0600 | [diff] [blame] | 3937 | weston_surface_damage(surface); |
| 3938 | } |
| 3939 | |
| 3940 | static void |
Kristian Høgsberg | e314875 | 2013-05-06 23:19:49 -0400 | [diff] [blame] | 3941 | 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] | 3942 | wl_fixed_t value) |
Scott Moreau | ccbf29d | 2012-02-22 14:21:41 -0700 | [diff] [blame] | 3943 | { |
Daniel Stone | 37816df | 2012-05-16 18:45:18 +0100 | [diff] [blame] | 3944 | struct weston_seat *ws = (struct weston_seat *) seat; |
| 3945 | struct weston_compositor *compositor = ws->compositor; |
Scott Moreau | ccbf29d | 2012-02-22 14:21:41 -0700 | [diff] [blame] | 3946 | struct weston_output *output; |
Scott Moreau | e660398 | 2012-06-11 13:07:51 -0600 | [diff] [blame] | 3947 | float increment; |
Scott Moreau | ccbf29d | 2012-02-22 14:21:41 -0700 | [diff] [blame] | 3948 | |
| 3949 | wl_list_for_each(output, &compositor->output_list, link) { |
| 3950 | if (pixman_region32_contains_point(&output->region, |
Daniel Stone | 37816df | 2012-05-16 18:45:18 +0100 | [diff] [blame] | 3951 | wl_fixed_to_double(seat->pointer->x), |
| 3952 | wl_fixed_to_double(seat->pointer->y), |
Daniel Stone | 103db7f | 2012-05-08 17:17:55 +0100 | [diff] [blame] | 3953 | NULL)) { |
Daniel Stone | 325fc2d | 2012-05-30 16:31:58 +0100 | [diff] [blame] | 3954 | if (key == KEY_PAGEUP) |
Kristian Høgsberg | 9b68af0 | 2012-05-22 12:55:18 -0400 | [diff] [blame] | 3955 | increment = output->zoom.increment; |
Daniel Stone | 325fc2d | 2012-05-30 16:31:58 +0100 | [diff] [blame] | 3956 | else if (key == KEY_PAGEDOWN) |
Kristian Høgsberg | 9b68af0 | 2012-05-22 12:55:18 -0400 | [diff] [blame] | 3957 | increment = -output->zoom.increment; |
| 3958 | else if (axis == WL_POINTER_AXIS_VERTICAL_SCROLL) |
Jonas Ådahl | b0b87ba | 2012-09-27 18:40:42 +0200 | [diff] [blame] | 3959 | /* For every pixel zoom 20th of a step */ |
Daniel Stone | 0c1e46e | 2012-05-30 16:31:59 +0100 | [diff] [blame] | 3960 | increment = output->zoom.increment * |
Jonas Ådahl | b0b87ba | 2012-09-27 18:40:42 +0200 | [diff] [blame] | 3961 | -wl_fixed_to_double(value) / 20.0; |
Kristian Høgsberg | 9b68af0 | 2012-05-22 12:55:18 -0400 | [diff] [blame] | 3962 | else |
| 3963 | increment = 0; |
| 3964 | |
Kristian Høgsberg | 9b68af0 | 2012-05-22 12:55:18 -0400 | [diff] [blame] | 3965 | output->zoom.level += increment; |
Scott Moreau | c6d7f60 | 2012-02-23 22:28:37 -0700 | [diff] [blame] | 3966 | |
Scott Moreau | e660398 | 2012-06-11 13:07:51 -0600 | [diff] [blame] | 3967 | if (output->zoom.level < 0.0) |
Scott Moreau | 850ca42 | 2012-05-21 15:21:25 -0600 | [diff] [blame] | 3968 | output->zoom.level = 0.0; |
Scott Moreau | e660398 | 2012-06-11 13:07:51 -0600 | [diff] [blame] | 3969 | else if (output->zoom.level > output->zoom.max_level) |
| 3970 | output->zoom.level = output->zoom.max_level; |
Ville Syrjälä | aa628d0 | 2012-11-16 11:48:47 +0200 | [diff] [blame] | 3971 | else if (!output->zoom.active) { |
Giulio Camuffo | 412b024 | 2013-11-14 23:42:51 +0100 | [diff] [blame] | 3972 | weston_output_activate_zoom(output); |
Kristian Høgsberg | 79af73e | 2012-08-03 15:45:23 -0400 | [diff] [blame] | 3973 | } |
Scott Moreau | ccbf29d | 2012-02-22 14:21:41 -0700 | [diff] [blame] | 3974 | |
Scott Moreau | e660398 | 2012-06-11 13:07:51 -0600 | [diff] [blame] | 3975 | output->zoom.spring_z.target = output->zoom.level; |
Scott Moreau | ccbf29d | 2012-02-22 14:21:41 -0700 | [diff] [blame] | 3976 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 3977 | weston_output_update_zoom(output); |
Scott Moreau | ccbf29d | 2012-02-22 14:21:41 -0700 | [diff] [blame] | 3978 | } |
| 3979 | } |
| 3980 | } |
| 3981 | |
Scott Moreau | ccbf29d | 2012-02-22 14:21:41 -0700 | [diff] [blame] | 3982 | static void |
Kristian Høgsberg | e314875 | 2013-05-06 23:19:49 -0400 | [diff] [blame] | 3983 | 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] | 3984 | wl_fixed_t value, void *data) |
Daniel Stone | 325fc2d | 2012-05-30 16:31:58 +0100 | [diff] [blame] | 3985 | { |
| 3986 | do_zoom(seat, time, 0, axis, value); |
| 3987 | } |
| 3988 | |
| 3989 | static void |
Kristian Høgsberg | e314875 | 2013-05-06 23:19:49 -0400 | [diff] [blame] | 3990 | 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] | 3991 | void *data) |
| 3992 | { |
| 3993 | do_zoom(seat, time, key, 0, 0); |
| 3994 | } |
| 3995 | |
| 3996 | static void |
Kristian Høgsberg | e314875 | 2013-05-06 23:19:49 -0400 | [diff] [blame] | 3997 | terminate_binding(struct weston_seat *seat, uint32_t time, uint32_t key, |
Daniel Stone | 325fc2d | 2012-05-30 16:31:58 +0100 | [diff] [blame] | 3998 | void *data) |
Kristian Høgsberg | e1a850e | 2011-12-19 15:18:05 -0500 | [diff] [blame] | 3999 | { |
Kristian Høgsberg | 8334bc1 | 2012-01-03 10:29:47 -0500 | [diff] [blame] | 4000 | struct weston_compositor *compositor = data; |
Kristian Høgsberg | e1a850e | 2011-12-19 15:18:05 -0500 | [diff] [blame] | 4001 | |
Daniel Stone | 325fc2d | 2012-05-30 16:31:58 +0100 | [diff] [blame] | 4002 | wl_display_terminate(compositor->wl_display); |
Kristian Høgsberg | e1a850e | 2011-12-19 15:18:05 -0500 | [diff] [blame] | 4003 | } |
| 4004 | |
Emilio Pozuelo Monfort | 03251b6 | 2013-11-19 11:37:16 +0100 | [diff] [blame] | 4005 | static void |
Giulio Camuffo | 1959ab8 | 2013-11-14 23:42:52 +0100 | [diff] [blame] | 4006 | rotate_grab_motion(struct weston_pointer_grab *grab, uint32_t time, |
| 4007 | wl_fixed_t x, wl_fixed_t y) |
Pekka Paalanen | 460099f | 2012-01-20 16:48:25 +0200 | [diff] [blame] | 4008 | { |
| 4009 | struct rotate_grab *rotate = |
Ander Conselvan de Oliveira | fe0444a | 2012-04-04 17:48:05 +0300 | [diff] [blame] | 4010 | container_of(grab, struct rotate_grab, base.grab); |
Kristian Høgsberg | 02bbabb | 2013-05-06 22:15:05 -0400 | [diff] [blame] | 4011 | struct weston_pointer *pointer = grab->pointer; |
Ander Conselvan de Oliveira | fe0444a | 2012-04-04 17:48:05 +0300 | [diff] [blame] | 4012 | struct shell_surface *shsurf = rotate->base.shsurf; |
John Kåre Alsaker | 490d02a | 2012-09-30 02:57:21 +0200 | [diff] [blame] | 4013 | float cx, cy, dx, dy, cposx, cposy, dposx, dposy, r; |
Ander Conselvan de Oliveira | fe0444a | 2012-04-04 17:48:05 +0300 | [diff] [blame] | 4014 | |
Giulio Camuffo | 1959ab8 | 2013-11-14 23:42:52 +0100 | [diff] [blame] | 4015 | weston_pointer_move(pointer, x, y); |
| 4016 | |
Ander Conselvan de Oliveira | fe0444a | 2012-04-04 17:48:05 +0300 | [diff] [blame] | 4017 | if (!shsurf) |
| 4018 | return; |
| 4019 | |
Jason Ekstrand | 918f2dd | 2013-12-02 21:01:53 -0600 | [diff] [blame] | 4020 | cx = 0.5f * shsurf->surface->width; |
| 4021 | cy = 0.5f * shsurf->surface->height; |
Pekka Paalanen | 460099f | 2012-01-20 16:48:25 +0200 | [diff] [blame] | 4022 | |
Daniel Stone | 37816df | 2012-05-16 18:45:18 +0100 | [diff] [blame] | 4023 | dx = wl_fixed_to_double(pointer->x) - rotate->center.x; |
| 4024 | dy = wl_fixed_to_double(pointer->y) - rotate->center.y; |
Pekka Paalanen | 460099f | 2012-01-20 16:48:25 +0200 | [diff] [blame] | 4025 | r = sqrtf(dx * dx + dy * dy); |
| 4026 | |
Ander Conselvan de Oliveira | fe0444a | 2012-04-04 17:48:05 +0300 | [diff] [blame] | 4027 | wl_list_remove(&shsurf->rotation.transform.link); |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 4028 | weston_view_geometry_dirty(shsurf->view); |
Pekka Paalanen | 460099f | 2012-01-20 16:48:25 +0200 | [diff] [blame] | 4029 | |
| 4030 | if (r > 20.0f) { |
Pekka Paalanen | 460099f | 2012-01-20 16:48:25 +0200 | [diff] [blame] | 4031 | struct weston_matrix *matrix = |
Ander Conselvan de Oliveira | fe0444a | 2012-04-04 17:48:05 +0300 | [diff] [blame] | 4032 | &shsurf->rotation.transform.matrix; |
Pekka Paalanen | 460099f | 2012-01-20 16:48:25 +0200 | [diff] [blame] | 4033 | |
Kristian Høgsberg | 765e27b | 2012-01-27 13:36:13 -0500 | [diff] [blame] | 4034 | weston_matrix_init(&rotate->rotation); |
Vasily Khoruzhick | 1bbf372 | 2013-01-28 22:40:28 +0300 | [diff] [blame] | 4035 | weston_matrix_rotate_xy(&rotate->rotation, dx / r, dy / r); |
Pekka Paalanen | 460099f | 2012-01-20 16:48:25 +0200 | [diff] [blame] | 4036 | |
| 4037 | weston_matrix_init(matrix); |
Pekka Paalanen | 7b3bd3d | 2012-01-30 14:16:34 +0200 | [diff] [blame] | 4038 | weston_matrix_translate(matrix, -cx, -cy, 0.0f); |
Ander Conselvan de Oliveira | fe0444a | 2012-04-04 17:48:05 +0300 | [diff] [blame] | 4039 | weston_matrix_multiply(matrix, &shsurf->rotation.rotation); |
Kristian Høgsberg | 765e27b | 2012-01-27 13:36:13 -0500 | [diff] [blame] | 4040 | weston_matrix_multiply(matrix, &rotate->rotation); |
Pekka Paalanen | 7b3bd3d | 2012-01-30 14:16:34 +0200 | [diff] [blame] | 4041 | weston_matrix_translate(matrix, cx, cy, 0.0f); |
Pekka Paalanen | 460099f | 2012-01-20 16:48:25 +0200 | [diff] [blame] | 4042 | |
Pekka Paalanen | bc0b7e7 | 2012-01-24 09:53:37 +0200 | [diff] [blame] | 4043 | wl_list_insert( |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 4044 | &shsurf->view->geometry.transformation_list, |
Ander Conselvan de Oliveira | fe0444a | 2012-04-04 17:48:05 +0300 | [diff] [blame] | 4045 | &shsurf->rotation.transform.link); |
Pekka Paalanen | 460099f | 2012-01-20 16:48:25 +0200 | [diff] [blame] | 4046 | } else { |
Ander Conselvan de Oliveira | fe0444a | 2012-04-04 17:48:05 +0300 | [diff] [blame] | 4047 | wl_list_init(&shsurf->rotation.transform.link); |
| 4048 | weston_matrix_init(&shsurf->rotation.rotation); |
Kristian Høgsberg | 765e27b | 2012-01-27 13:36:13 -0500 | [diff] [blame] | 4049 | weston_matrix_init(&rotate->rotation); |
Pekka Paalanen | 460099f | 2012-01-20 16:48:25 +0200 | [diff] [blame] | 4050 | } |
Pekka Paalanen | b45ac5e | 2012-02-09 15:58:44 +0200 | [diff] [blame] | 4051 | |
Rafal Mielniczuk | 2d7ab82 | 2012-03-22 22:22:04 +0100 | [diff] [blame] | 4052 | /* We need to adjust the position of the surface |
| 4053 | * in case it was resized in a rotated state before */ |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 4054 | cposx = shsurf->view->geometry.x + cx; |
| 4055 | cposy = shsurf->view->geometry.y + cy; |
Rafal Mielniczuk | 2d7ab82 | 2012-03-22 22:22:04 +0100 | [diff] [blame] | 4056 | dposx = rotate->center.x - cposx; |
| 4057 | dposy = rotate->center.y - cposy; |
| 4058 | if (dposx != 0.0f || dposy != 0.0f) { |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 4059 | weston_view_set_position(shsurf->view, |
| 4060 | shsurf->view->geometry.x + dposx, |
| 4061 | shsurf->view->geometry.y + dposy); |
Rafal Mielniczuk | 2d7ab82 | 2012-03-22 22:22:04 +0100 | [diff] [blame] | 4062 | } |
| 4063 | |
Pekka Paalanen | b45ac5e | 2012-02-09 15:58:44 +0200 | [diff] [blame] | 4064 | /* Repaint implies weston_surface_update_transform(), which |
| 4065 | * lazily applies the damage due to rotation update. |
| 4066 | */ |
Ander Conselvan de Oliveira | fe0444a | 2012-04-04 17:48:05 +0300 | [diff] [blame] | 4067 | weston_compositor_schedule_repaint(shsurf->surface->compositor); |
Pekka Paalanen | 460099f | 2012-01-20 16:48:25 +0200 | [diff] [blame] | 4068 | } |
| 4069 | |
| 4070 | static void |
Kristian Høgsberg | 02bbabb | 2013-05-06 22:15:05 -0400 | [diff] [blame] | 4071 | rotate_grab_button(struct weston_pointer_grab *grab, |
| 4072 | uint32_t time, uint32_t button, uint32_t state_w) |
Pekka Paalanen | 460099f | 2012-01-20 16:48:25 +0200 | [diff] [blame] | 4073 | { |
| 4074 | struct rotate_grab *rotate = |
Ander Conselvan de Oliveira | fe0444a | 2012-04-04 17:48:05 +0300 | [diff] [blame] | 4075 | container_of(grab, struct rotate_grab, base.grab); |
Kristian Høgsberg | 02bbabb | 2013-05-06 22:15:05 -0400 | [diff] [blame] | 4076 | struct weston_pointer *pointer = grab->pointer; |
Ander Conselvan de Oliveira | fe0444a | 2012-04-04 17:48:05 +0300 | [diff] [blame] | 4077 | struct shell_surface *shsurf = rotate->base.shsurf; |
Daniel Stone | 4dbadb1 | 2012-05-30 16:31:51 +0100 | [diff] [blame] | 4078 | enum wl_pointer_button_state state = state_w; |
Pekka Paalanen | 460099f | 2012-01-20 16:48:25 +0200 | [diff] [blame] | 4079 | |
Daniel Stone | 4dbadb1 | 2012-05-30 16:31:51 +0100 | [diff] [blame] | 4080 | if (pointer->button_count == 0 && |
| 4081 | state == WL_POINTER_BUTTON_STATE_RELEASED) { |
Ander Conselvan de Oliveira | fe0444a | 2012-04-04 17:48:05 +0300 | [diff] [blame] | 4082 | if (shsurf) |
| 4083 | weston_matrix_multiply(&shsurf->rotation.rotation, |
| 4084 | &rotate->rotation); |
Ander Conselvan de Oliveira | b9d2a0f | 2012-06-28 18:08:05 +0300 | [diff] [blame] | 4085 | shell_grab_end(&rotate->base); |
Pekka Paalanen | 460099f | 2012-01-20 16:48:25 +0200 | [diff] [blame] | 4086 | free(rotate); |
| 4087 | } |
| 4088 | } |
| 4089 | |
Jonas Ådahl | 1ea343e | 2013-10-25 23:18:05 +0200 | [diff] [blame] | 4090 | static void |
| 4091 | rotate_grab_cancel(struct weston_pointer_grab *grab) |
| 4092 | { |
| 4093 | struct rotate_grab *rotate = |
| 4094 | container_of(grab, struct rotate_grab, base.grab); |
| 4095 | |
| 4096 | shell_grab_end(&rotate->base); |
| 4097 | free(rotate); |
| 4098 | } |
| 4099 | |
Kristian Høgsberg | 02bbabb | 2013-05-06 22:15:05 -0400 | [diff] [blame] | 4100 | static const struct weston_pointer_grab_interface rotate_grab_interface = { |
Pekka Paalanen | 460099f | 2012-01-20 16:48:25 +0200 | [diff] [blame] | 4101 | noop_grab_focus, |
| 4102 | rotate_grab_motion, |
| 4103 | rotate_grab_button, |
Jonas Ådahl | 1ea343e | 2013-10-25 23:18:05 +0200 | [diff] [blame] | 4104 | rotate_grab_cancel, |
Pekka Paalanen | 460099f | 2012-01-20 16:48:25 +0200 | [diff] [blame] | 4105 | }; |
| 4106 | |
| 4107 | static void |
Kristian Høgsberg | e314875 | 2013-05-06 23:19:49 -0400 | [diff] [blame] | 4108 | surface_rotate(struct shell_surface *surface, struct weston_seat *seat) |
Pekka Paalanen | 460099f | 2012-01-20 16:48:25 +0200 | [diff] [blame] | 4109 | { |
Pekka Paalanen | 460099f | 2012-01-20 16:48:25 +0200 | [diff] [blame] | 4110 | struct rotate_grab *rotate; |
John Kåre Alsaker | 490d02a | 2012-09-30 02:57:21 +0200 | [diff] [blame] | 4111 | float dx, dy; |
| 4112 | float r; |
Pekka Paalanen | 460099f | 2012-01-20 16:48:25 +0200 | [diff] [blame] | 4113 | |
Pekka Paalanen | 460099f | 2012-01-20 16:48:25 +0200 | [diff] [blame] | 4114 | rotate = malloc(sizeof *rotate); |
| 4115 | if (!rotate) |
| 4116 | return; |
| 4117 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 4118 | weston_view_to_global_float(surface->view, |
Jason Ekstrand | 918f2dd | 2013-12-02 21:01:53 -0600 | [diff] [blame] | 4119 | surface->surface->width * 0.5f, |
| 4120 | surface->surface->height * 0.5f, |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 4121 | &rotate->center.x, &rotate->center.y); |
Pekka Paalanen | 460099f | 2012-01-20 16:48:25 +0200 | [diff] [blame] | 4122 | |
Daniel Stone | 37816df | 2012-05-16 18:45:18 +0100 | [diff] [blame] | 4123 | dx = wl_fixed_to_double(seat->pointer->x) - rotate->center.x; |
| 4124 | dy = wl_fixed_to_double(seat->pointer->y) - rotate->center.y; |
Kristian Høgsberg | 765e27b | 2012-01-27 13:36:13 -0500 | [diff] [blame] | 4125 | r = sqrtf(dx * dx + dy * dy); |
| 4126 | if (r > 20.0f) { |
| 4127 | struct weston_matrix inverse; |
| 4128 | |
| 4129 | weston_matrix_init(&inverse); |
Vasily Khoruzhick | 1bbf372 | 2013-01-28 22:40:28 +0300 | [diff] [blame] | 4130 | weston_matrix_rotate_xy(&inverse, dx / r, -dy / r); |
Kristian Høgsberg | 765e27b | 2012-01-27 13:36:13 -0500 | [diff] [blame] | 4131 | weston_matrix_multiply(&surface->rotation.rotation, &inverse); |
Rafal Mielniczuk | 2d7ab82 | 2012-03-22 22:22:04 +0100 | [diff] [blame] | 4132 | |
| 4133 | weston_matrix_init(&rotate->rotation); |
Vasily Khoruzhick | 1bbf372 | 2013-01-28 22:40:28 +0300 | [diff] [blame] | 4134 | weston_matrix_rotate_xy(&rotate->rotation, dx / r, dy / r); |
Kristian Høgsberg | 765e27b | 2012-01-27 13:36:13 -0500 | [diff] [blame] | 4135 | } else { |
| 4136 | weston_matrix_init(&surface->rotation.rotation); |
| 4137 | weston_matrix_init(&rotate->rotation); |
| 4138 | } |
| 4139 | |
Ander Conselvan de Oliveira | b9d2a0f | 2012-06-28 18:08:05 +0300 | [diff] [blame] | 4140 | shell_grab_start(&rotate->base, &rotate_grab_interface, surface, |
| 4141 | seat->pointer, DESKTOP_SHELL_CURSOR_ARROW); |
Pekka Paalanen | 460099f | 2012-01-20 16:48:25 +0200 | [diff] [blame] | 4142 | } |
| 4143 | |
| 4144 | static void |
Kristian Høgsberg | e314875 | 2013-05-06 23:19:49 -0400 | [diff] [blame] | 4145 | 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] | 4146 | void *data) |
| 4147 | { |
Rafal Mielniczuk | b2917a2 | 2014-01-05 20:04:59 +0100 | [diff] [blame] | 4148 | struct weston_surface *focus; |
Pekka Paalanen | 01388e2 | 2013-04-25 13:57:44 +0300 | [diff] [blame] | 4149 | struct weston_surface *base_surface; |
Kristian Høgsberg | 0c36903 | 2013-02-14 21:31:44 -0500 | [diff] [blame] | 4150 | struct shell_surface *surface; |
| 4151 | |
Rafal Mielniczuk | b2917a2 | 2014-01-05 20:04:59 +0100 | [diff] [blame] | 4152 | if (seat->pointer->focus == NULL) |
| 4153 | return; |
| 4154 | |
| 4155 | focus = seat->pointer->focus->surface; |
| 4156 | |
Pekka Paalanen | 01388e2 | 2013-04-25 13:57:44 +0300 | [diff] [blame] | 4157 | base_surface = weston_surface_get_main_surface(focus); |
Kristian Høgsberg | 0c36903 | 2013-02-14 21:31:44 -0500 | [diff] [blame] | 4158 | if (base_surface == NULL) |
| 4159 | return; |
| 4160 | |
| 4161 | surface = get_shell_surface(base_surface); |
Rafael Antognolli | 03b1659 | 2013-12-03 15:35:42 -0200 | [diff] [blame] | 4162 | if (surface == NULL || surface->state.fullscreen || |
| 4163 | surface->state.maximized) |
Kristian Høgsberg | 0c36903 | 2013-02-14 21:31:44 -0500 | [diff] [blame] | 4164 | return; |
| 4165 | |
| 4166 | surface_rotate(surface, seat); |
| 4167 | } |
| 4168 | |
Philip Withnall | 83ffd9d | 2013-11-25 18:01:42 +0000 | [diff] [blame] | 4169 | /* Move all fullscreen layers down to the current workspace in a non-reversible |
| 4170 | * manner. This should be used when implementing shell-wide overlays, such as |
| 4171 | * the alt-tab switcher, which need to de-promote fullscreen layers. */ |
Kristian Høgsberg | 1ef2313 | 2013-12-04 00:20:01 -0800 | [diff] [blame] | 4172 | void |
Kristian Høgsberg | b0d8e77 | 2012-06-18 16:34:58 -0400 | [diff] [blame] | 4173 | lower_fullscreen_layer(struct desktop_shell *shell) |
| 4174 | { |
| 4175 | struct workspace *ws; |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 4176 | struct weston_view *view, *prev; |
Kristian Høgsberg | b0d8e77 | 2012-06-18 16:34:58 -0400 | [diff] [blame] | 4177 | |
| 4178 | ws = get_current_workspace(shell); |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 4179 | wl_list_for_each_reverse_safe(view, prev, |
| 4180 | &shell->fullscreen_layer.view_list, |
Philip Withnall | 83ffd9d | 2013-11-25 18:01:42 +0000 | [diff] [blame] | 4181 | layer_link) { |
| 4182 | wl_list_remove(&view->layer_link); |
| 4183 | wl_list_insert(&ws->layer.view_list, &view->layer_link); |
| 4184 | weston_view_damage_below(view); |
| 4185 | weston_surface_damage(view->surface); |
| 4186 | } |
Kristian Høgsberg | b0d8e77 | 2012-06-18 16:34:58 -0400 | [diff] [blame] | 4187 | } |
| 4188 | |
Kristian Høgsberg | 1ef2313 | 2013-12-04 00:20:01 -0800 | [diff] [blame] | 4189 | void |
Tiago Vignatti | be14326 | 2012-04-16 17:31:41 +0300 | [diff] [blame] | 4190 | activate(struct desktop_shell *shell, struct weston_surface *es, |
Daniel Stone | 37816df | 2012-05-16 18:45:18 +0100 | [diff] [blame] | 4191 | struct weston_seat *seat) |
Kristian Høgsberg | 7584062 | 2011-09-06 13:48:16 -0400 | [diff] [blame] | 4192 | { |
Pekka Paalanen | 01388e2 | 2013-04-25 13:57:44 +0300 | [diff] [blame] | 4193 | struct weston_surface *main_surface; |
Kristian Høgsberg | 2f5faff | 2012-07-31 16:36:34 -0400 | [diff] [blame] | 4194 | struct focus_state *state; |
Jonas Ådahl | 8538b22 | 2012-08-29 22:13:03 +0200 | [diff] [blame] | 4195 | struct workspace *ws; |
Louis-Francis Ratté-Boulianne | b482dbd | 2013-11-19 11:37:11 +0100 | [diff] [blame] | 4196 | struct weston_surface *old_es; |
Rafael Antognolli | 03b1659 | 2013-12-03 15:35:42 -0200 | [diff] [blame] | 4197 | struct shell_surface *shsurf; |
Kristian Høgsberg | 7584062 | 2011-09-06 13:48:16 -0400 | [diff] [blame] | 4198 | |
Pekka Paalanen | 01388e2 | 2013-04-25 13:57:44 +0300 | [diff] [blame] | 4199 | main_surface = weston_surface_get_main_surface(es); |
| 4200 | |
Daniel Stone | 37816df | 2012-05-16 18:45:18 +0100 | [diff] [blame] | 4201 | weston_surface_activate(es, seat); |
Kristian Høgsberg | 7584062 | 2011-09-06 13:48:16 -0400 | [diff] [blame] | 4202 | |
Jonas Ådahl | 8538b22 | 2012-08-29 22:13:03 +0200 | [diff] [blame] | 4203 | state = ensure_focus_state(shell, seat); |
| 4204 | if (state == NULL) |
| 4205 | return; |
Kristian Høgsberg | 2f5faff | 2012-07-31 16:36:34 -0400 | [diff] [blame] | 4206 | |
Louis-Francis Ratté-Boulianne | b482dbd | 2013-11-19 11:37:11 +0100 | [diff] [blame] | 4207 | old_es = state->keyboard_focus; |
Kristian Høgsberg | 2f5faff | 2012-07-31 16:36:34 -0400 | [diff] [blame] | 4208 | state->keyboard_focus = es; |
| 4209 | wl_list_remove(&state->surface_destroy_listener.link); |
Jason Ekstrand | 26ed73c | 2013-06-06 22:34:41 -0500 | [diff] [blame] | 4210 | wl_signal_add(&es->destroy_signal, &state->surface_destroy_listener); |
Kristian Høgsberg | 2f5faff | 2012-07-31 16:36:34 -0400 | [diff] [blame] | 4211 | |
Rafael Antognolli | 03b1659 | 2013-12-03 15:35:42 -0200 | [diff] [blame] | 4212 | shsurf = get_shell_surface(main_surface); |
| 4213 | if (shsurf->state.fullscreen) |
| 4214 | shell_configure_fullscreen(shsurf); |
| 4215 | else |
Alexander Larsson | f82b6ca | 2013-05-28 16:23:39 +0200 | [diff] [blame] | 4216 | restore_all_output_modes(shell->compositor); |
Louis-Francis Ratté-Boulianne | b482dbd | 2013-11-19 11:37:11 +0100 | [diff] [blame] | 4217 | |
Philip Withnall | 83ffd9d | 2013-11-25 18:01:42 +0000 | [diff] [blame] | 4218 | if (shell->focus_animation_type != ANIMATION_NONE) { |
| 4219 | ws = get_current_workspace(shell); |
Louis-Francis Ratté-Boulianne | b482dbd | 2013-11-19 11:37:11 +0100 | [diff] [blame] | 4220 | 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] | 4221 | } |
| 4222 | |
| 4223 | /* Update the surface’s layer. This brings it to the top of the stacking |
| 4224 | * order as appropriate. */ |
| 4225 | shell_surface_update_layer(get_shell_surface(main_surface)); |
Kristian Høgsberg | 7584062 | 2011-09-06 13:48:16 -0400 | [diff] [blame] | 4226 | } |
| 4227 | |
Alex Wu | 2185843 | 2012-04-01 20:13:08 +0800 | [diff] [blame] | 4228 | /* no-op func for checking black surface */ |
| 4229 | static void |
Jason Ekstrand | 918f2dd | 2013-12-02 21:01:53 -0600 | [diff] [blame] | 4230 | 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] | 4231 | { |
| 4232 | } |
| 4233 | |
Quentin Glidic | c0d79ce | 2013-01-29 14:16:13 +0100 | [diff] [blame] | 4234 | static bool |
Alex Wu | 2185843 | 2012-04-01 20:13:08 +0800 | [diff] [blame] | 4235 | is_black_surface (struct weston_surface *es, struct weston_surface **fs_surface) |
| 4236 | { |
| 4237 | if (es->configure == black_surface_configure) { |
| 4238 | if (fs_surface) |
Giulio Camuffo | 7fe01b1 | 2013-03-28 18:02:42 +0100 | [diff] [blame] | 4239 | *fs_surface = (struct weston_surface *)es->configure_private; |
Alex Wu | 2185843 | 2012-04-01 20:13:08 +0800 | [diff] [blame] | 4240 | return true; |
| 4241 | } |
| 4242 | return false; |
| 4243 | } |
| 4244 | |
Kristian Høgsberg | 7584062 | 2011-09-06 13:48:16 -0400 | [diff] [blame] | 4245 | static void |
Neil Roberts | a28c693 | 2013-10-03 16:43:04 +0100 | [diff] [blame] | 4246 | activate_binding(struct weston_seat *seat, |
| 4247 | struct desktop_shell *shell, |
| 4248 | struct weston_surface *focus) |
Kristian Høgsberg | e1a850e | 2011-12-19 15:18:05 -0500 | [diff] [blame] | 4249 | { |
Pekka Paalanen | 01388e2 | 2013-04-25 13:57:44 +0300 | [diff] [blame] | 4250 | struct weston_surface *main_surface; |
Kristian Høgsberg | e1a850e | 2011-12-19 15:18:05 -0500 | [diff] [blame] | 4251 | |
Alex Wu | 9c35e6b | 2012-03-05 14:13:13 +0800 | [diff] [blame] | 4252 | if (!focus) |
| 4253 | return; |
| 4254 | |
Pekka Paalanen | 01388e2 | 2013-04-25 13:57:44 +0300 | [diff] [blame] | 4255 | if (is_black_surface(focus, &main_surface)) |
| 4256 | focus = main_surface; |
Alex Wu | 4539b08 | 2012-03-01 12:57:46 +0800 | [diff] [blame] | 4257 | |
Pekka Paalanen | 01388e2 | 2013-04-25 13:57:44 +0300 | [diff] [blame] | 4258 | main_surface = weston_surface_get_main_surface(focus); |
| 4259 | if (get_shell_surface_type(main_surface) == SHELL_SURFACE_NONE) |
Kristian Høgsberg | 0636ac3 | 2012-06-27 10:22:15 -0400 | [diff] [blame] | 4260 | return; |
Kristian Høgsberg | 85b2e4b | 2012-06-21 16:49:42 -0400 | [diff] [blame] | 4261 | |
Neil Roberts | a28c693 | 2013-10-03 16:43:04 +0100 | [diff] [blame] | 4262 | activate(shell, focus, seat); |
| 4263 | } |
| 4264 | |
| 4265 | static void |
| 4266 | click_to_activate_binding(struct weston_seat *seat, uint32_t time, uint32_t button, |
| 4267 | void *data) |
| 4268 | { |
| 4269 | if (seat->pointer->grab != &seat->pointer->default_grab) |
| 4270 | return; |
Kristian Høgsberg | 7c4f6cc | 2014-01-01 16:28:32 -0800 | [diff] [blame] | 4271 | if (seat->pointer->focus == NULL) |
| 4272 | return; |
Neil Roberts | a28c693 | 2013-10-03 16:43:04 +0100 | [diff] [blame] | 4273 | |
Kristian Høgsberg | 7ab139c | 2013-10-24 16:21:39 -0700 | [diff] [blame] | 4274 | activate_binding(seat, data, seat->pointer->focus->surface); |
Neil Roberts | a28c693 | 2013-10-03 16:43:04 +0100 | [diff] [blame] | 4275 | } |
| 4276 | |
| 4277 | static void |
| 4278 | touch_to_activate_binding(struct weston_seat *seat, uint32_t time, void *data) |
| 4279 | { |
| 4280 | if (seat->touch->grab != &seat->touch->default_grab) |
| 4281 | return; |
Kristian Høgsberg | 0ed6750 | 2014-01-02 23:00:11 -0800 | [diff] [blame] | 4282 | if (seat->touch->focus == NULL) |
| 4283 | return; |
Neil Roberts | a28c693 | 2013-10-03 16:43:04 +0100 | [diff] [blame] | 4284 | |
Kristian Høgsberg | 7ab139c | 2013-10-24 16:21:39 -0700 | [diff] [blame] | 4285 | activate_binding(seat, data, seat->touch->focus->surface); |
Kristian Høgsberg | e1a850e | 2011-12-19 15:18:05 -0500 | [diff] [blame] | 4286 | } |
| 4287 | |
| 4288 | static void |
Ander Conselvan de Oliveira | 19d10ef | 2013-02-21 18:35:20 +0200 | [diff] [blame] | 4289 | lock(struct desktop_shell *shell) |
Kristian Høgsberg | 02ec0a5 | 2011-04-23 13:04:11 -0400 | [diff] [blame] | 4290 | { |
Kristian Høgsberg | 4476aaf | 2012-06-25 14:03:13 -0400 | [diff] [blame] | 4291 | struct workspace *ws = get_current_workspace(shell); |
Pekka Paalanen | f0fc70d | 2011-11-15 13:34:54 +0200 | [diff] [blame] | 4292 | |
Tiago Vignatti | 8e53c7f | 2012-02-29 19:53:50 +0200 | [diff] [blame] | 4293 | if (shell->locked) { |
Ander Conselvan de Oliveira | 87524b6 | 2013-02-21 18:35:22 +0200 | [diff] [blame] | 4294 | weston_compositor_sleep(shell->compositor); |
Pekka Paalanen | f0fc70d | 2011-11-15 13:34:54 +0200 | [diff] [blame] | 4295 | return; |
Tiago Vignatti | 8e53c7f | 2012-02-29 19:53:50 +0200 | [diff] [blame] | 4296 | } |
Pekka Paalanen | 9ef3e01 | 2011-11-15 13:34:48 +0200 | [diff] [blame] | 4297 | |
| 4298 | shell->locked = true; |
Pekka Paalanen | f0fc70d | 2011-11-15 13:34:54 +0200 | [diff] [blame] | 4299 | |
Kristian Høgsberg | 3be2ce9 | 2012-02-29 12:42:35 -0500 | [diff] [blame] | 4300 | /* Hide all surfaces by removing the fullscreen, panel and |
| 4301 | * toplevel layers. This way nothing else can show or receive |
| 4302 | * input events while we are locked. */ |
Pekka Paalanen | f0fc70d | 2011-11-15 13:34:54 +0200 | [diff] [blame] | 4303 | |
Kristian Høgsberg | 3be2ce9 | 2012-02-29 12:42:35 -0500 | [diff] [blame] | 4304 | wl_list_remove(&shell->panel_layer.link); |
Kristian Høgsberg | 3be2ce9 | 2012-02-29 12:42:35 -0500 | [diff] [blame] | 4305 | wl_list_remove(&shell->fullscreen_layer.link); |
Philipp Brüschweiler | 711fda8 | 2012-08-09 18:50:43 +0200 | [diff] [blame] | 4306 | if (shell->showing_input_panels) |
| 4307 | wl_list_remove(&shell->input_panel_layer.link); |
Kristian Høgsberg | 4476aaf | 2012-06-25 14:03:13 -0400 | [diff] [blame] | 4308 | wl_list_remove(&ws->layer.link); |
Kristian Høgsberg | 3be2ce9 | 2012-02-29 12:42:35 -0500 | [diff] [blame] | 4309 | wl_list_insert(&shell->compositor->cursor_layer.link, |
| 4310 | &shell->lock_layer.link); |
Pekka Paalanen | f0fc70d | 2011-11-15 13:34:54 +0200 | [diff] [blame] | 4311 | |
Pekka Paalanen | 77346a6 | 2011-11-30 16:26:35 +0200 | [diff] [blame] | 4312 | launch_screensaver(shell); |
| 4313 | |
Pekka Paalanen | f0fc70d | 2011-11-15 13:34:54 +0200 | [diff] [blame] | 4314 | /* TODO: disable bindings that should not work while locked. */ |
| 4315 | |
| 4316 | /* All this must be undone in resume_desktop(). */ |
Pekka Paalanen | 9ef3e01 | 2011-11-15 13:34:48 +0200 | [diff] [blame] | 4317 | } |
| 4318 | |
| 4319 | static void |
Ander Conselvan de Oliveira | 19d10ef | 2013-02-21 18:35:20 +0200 | [diff] [blame] | 4320 | unlock(struct desktop_shell *shell) |
Pekka Paalanen | 9ef3e01 | 2011-11-15 13:34:48 +0200 | [diff] [blame] | 4321 | { |
Pekka Paalanen | d81c216 | 2011-11-16 13:47:34 +0200 | [diff] [blame] | 4322 | if (!shell->locked || shell->lock_surface) { |
Ander Conselvan de Oliveira | 87524b6 | 2013-02-21 18:35:22 +0200 | [diff] [blame] | 4323 | shell_fade(shell, FADE_IN); |
Pekka Paalanen | 9ef3e01 | 2011-11-15 13:34:48 +0200 | [diff] [blame] | 4324 | return; |
| 4325 | } |
| 4326 | |
| 4327 | /* If desktop-shell client has gone away, unlock immediately. */ |
| 4328 | if (!shell->child.desktop_shell) { |
Pekka Paalanen | f0fc70d | 2011-11-15 13:34:54 +0200 | [diff] [blame] | 4329 | resume_desktop(shell); |
Pekka Paalanen | 9ef3e01 | 2011-11-15 13:34:48 +0200 | [diff] [blame] | 4330 | return; |
| 4331 | } |
| 4332 | |
| 4333 | if (shell->prepare_event_sent) |
| 4334 | return; |
| 4335 | |
Kristian Høgsberg | 0b5cd0c | 2012-03-04 21:57:37 -0500 | [diff] [blame] | 4336 | desktop_shell_send_prepare_lock_surface(shell->child.desktop_shell); |
Pekka Paalanen | 9ef3e01 | 2011-11-15 13:34:48 +0200 | [diff] [blame] | 4337 | shell->prepare_event_sent = true; |
Kristian Høgsberg | 02ec0a5 | 2011-04-23 13:04:11 -0400 | [diff] [blame] | 4338 | } |
| 4339 | |
| 4340 | static void |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 4341 | shell_fade_done(struct weston_view_animation *animation, void *data) |
Ander Conselvan de Oliveira | 19d10ef | 2013-02-21 18:35:20 +0200 | [diff] [blame] | 4342 | { |
| 4343 | struct desktop_shell *shell = data; |
| 4344 | |
| 4345 | shell->fade.animation = NULL; |
| 4346 | |
| 4347 | switch (shell->fade.type) { |
| 4348 | case FADE_IN: |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 4349 | weston_surface_destroy(shell->fade.view->surface); |
| 4350 | shell->fade.view = NULL; |
Ander Conselvan de Oliveira | 19d10ef | 2013-02-21 18:35:20 +0200 | [diff] [blame] | 4351 | break; |
| 4352 | case FADE_OUT: |
Ander Conselvan de Oliveira | 19d10ef | 2013-02-21 18:35:20 +0200 | [diff] [blame] | 4353 | lock(shell); |
| 4354 | break; |
Philip Withnall | 4a86a0a | 2013-11-25 18:01:32 +0000 | [diff] [blame] | 4355 | default: |
| 4356 | break; |
Ander Conselvan de Oliveira | 19d10ef | 2013-02-21 18:35:20 +0200 | [diff] [blame] | 4357 | } |
| 4358 | } |
| 4359 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 4360 | static struct weston_view * |
Pekka Paalanen | 79346ab | 2013-05-22 18:03:09 +0300 | [diff] [blame] | 4361 | shell_fade_create_surface(struct desktop_shell *shell) |
Ander Conselvan de Oliveira | 19d10ef | 2013-02-21 18:35:20 +0200 | [diff] [blame] | 4362 | { |
| 4363 | struct weston_compositor *compositor = shell->compositor; |
| 4364 | struct weston_surface *surface; |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 4365 | struct weston_view *view; |
Pekka Paalanen | 79346ab | 2013-05-22 18:03:09 +0300 | [diff] [blame] | 4366 | |
| 4367 | surface = weston_surface_create(compositor); |
| 4368 | if (!surface) |
| 4369 | return NULL; |
| 4370 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 4371 | view = weston_view_create(surface); |
| 4372 | if (!view) { |
| 4373 | weston_surface_destroy(surface); |
| 4374 | return NULL; |
| 4375 | } |
| 4376 | |
Jason Ekstrand | 5c11a33 | 2013-12-04 20:32:03 -0600 | [diff] [blame] | 4377 | weston_surface_set_size(surface, 8192, 8192); |
Jason Ekstrand | 918f2dd | 2013-12-02 21:01:53 -0600 | [diff] [blame] | 4378 | weston_view_set_position(view, 0, 0); |
Pekka Paalanen | 79346ab | 2013-05-22 18:03:09 +0300 | [diff] [blame] | 4379 | 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] | 4380 | wl_list_insert(&compositor->fade_layer.view_list, |
| 4381 | &view->layer_link); |
Pekka Paalanen | 79346ab | 2013-05-22 18:03:09 +0300 | [diff] [blame] | 4382 | pixman_region32_init(&surface->input); |
| 4383 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 4384 | return view; |
Pekka Paalanen | 79346ab | 2013-05-22 18:03:09 +0300 | [diff] [blame] | 4385 | } |
| 4386 | |
| 4387 | static void |
| 4388 | shell_fade(struct desktop_shell *shell, enum fade_type type) |
| 4389 | { |
Ander Conselvan de Oliveira | 19d10ef | 2013-02-21 18:35:20 +0200 | [diff] [blame] | 4390 | float tint; |
| 4391 | |
| 4392 | switch (type) { |
| 4393 | case FADE_IN: |
| 4394 | tint = 0.0; |
| 4395 | break; |
| 4396 | case FADE_OUT: |
| 4397 | tint = 1.0; |
| 4398 | break; |
| 4399 | default: |
| 4400 | weston_log("shell: invalid fade type\n"); |
| 4401 | return; |
| 4402 | } |
| 4403 | |
| 4404 | shell->fade.type = type; |
| 4405 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 4406 | if (shell->fade.view == NULL) { |
| 4407 | shell->fade.view = shell_fade_create_surface(shell); |
| 4408 | if (!shell->fade.view) |
Ander Conselvan de Oliveira | 19d10ef | 2013-02-21 18:35:20 +0200 | [diff] [blame] | 4409 | return; |
| 4410 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 4411 | shell->fade.view->alpha = 1.0 - tint; |
| 4412 | weston_view_update_transform(shell->fade.view); |
Ander Conselvan de Oliveira | 19d10ef | 2013-02-21 18:35:20 +0200 | [diff] [blame] | 4413 | } |
| 4414 | |
| 4415 | if (shell->fade.animation) |
Kristian Høgsberg | 5281fb1 | 2013-06-17 10:10:28 -0400 | [diff] [blame] | 4416 | weston_fade_update(shell->fade.animation, tint); |
Ander Conselvan de Oliveira | 19d10ef | 2013-02-21 18:35:20 +0200 | [diff] [blame] | 4417 | else |
| 4418 | shell->fade.animation = |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 4419 | weston_fade_run(shell->fade.view, |
Kristian Høgsberg | 5281fb1 | 2013-06-17 10:10:28 -0400 | [diff] [blame] | 4420 | 1.0 - tint, tint, 300.0, |
Ander Conselvan de Oliveira | 19d10ef | 2013-02-21 18:35:20 +0200 | [diff] [blame] | 4421 | shell_fade_done, shell); |
| 4422 | } |
| 4423 | |
| 4424 | static void |
Pekka Paalanen | 79346ab | 2013-05-22 18:03:09 +0300 | [diff] [blame] | 4425 | do_shell_fade_startup(void *data) |
| 4426 | { |
| 4427 | struct desktop_shell *shell = data; |
| 4428 | |
Kristian Høgsberg | 724c8d9 | 2013-10-16 11:38:24 -0700 | [diff] [blame] | 4429 | if (shell->startup_animation_type == ANIMATION_FADE) |
| 4430 | shell_fade(shell, FADE_IN); |
| 4431 | else if (shell->startup_animation_type == ANIMATION_NONE) { |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 4432 | weston_surface_destroy(shell->fade.view->surface); |
| 4433 | shell->fade.view = NULL; |
Kristian Høgsberg | 724c8d9 | 2013-10-16 11:38:24 -0700 | [diff] [blame] | 4434 | } |
Pekka Paalanen | 79346ab | 2013-05-22 18:03:09 +0300 | [diff] [blame] | 4435 | } |
| 4436 | |
| 4437 | static void |
| 4438 | shell_fade_startup(struct desktop_shell *shell) |
| 4439 | { |
| 4440 | struct wl_event_loop *loop; |
| 4441 | |
| 4442 | if (!shell->fade.startup_timer) |
| 4443 | return; |
| 4444 | |
| 4445 | wl_event_source_remove(shell->fade.startup_timer); |
| 4446 | shell->fade.startup_timer = NULL; |
| 4447 | |
| 4448 | loop = wl_display_get_event_loop(shell->compositor->wl_display); |
| 4449 | wl_event_loop_add_idle(loop, do_shell_fade_startup, shell); |
| 4450 | } |
| 4451 | |
| 4452 | static int |
| 4453 | fade_startup_timeout(void *data) |
| 4454 | { |
| 4455 | struct desktop_shell *shell = data; |
| 4456 | |
| 4457 | shell_fade_startup(shell); |
| 4458 | return 0; |
| 4459 | } |
| 4460 | |
| 4461 | static void |
| 4462 | shell_fade_init(struct desktop_shell *shell) |
| 4463 | { |
| 4464 | /* Make compositor output all black, and wait for the desktop-shell |
| 4465 | * client to signal it is ready, then fade in. The timer triggers a |
| 4466 | * fade-in, in case the desktop-shell client takes too long. |
| 4467 | */ |
| 4468 | |
| 4469 | struct wl_event_loop *loop; |
| 4470 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 4471 | if (shell->fade.view != NULL) { |
Pekka Paalanen | 79346ab | 2013-05-22 18:03:09 +0300 | [diff] [blame] | 4472 | weston_log("%s: warning: fade surface already exists\n", |
| 4473 | __func__); |
| 4474 | return; |
| 4475 | } |
| 4476 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 4477 | shell->fade.view = shell_fade_create_surface(shell); |
| 4478 | if (!shell->fade.view) |
Pekka Paalanen | 79346ab | 2013-05-22 18:03:09 +0300 | [diff] [blame] | 4479 | return; |
| 4480 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 4481 | weston_view_update_transform(shell->fade.view); |
| 4482 | weston_surface_damage(shell->fade.view->surface); |
Pekka Paalanen | 79346ab | 2013-05-22 18:03:09 +0300 | [diff] [blame] | 4483 | |
| 4484 | loop = wl_display_get_event_loop(shell->compositor->wl_display); |
| 4485 | shell->fade.startup_timer = |
| 4486 | wl_event_loop_add_timer(loop, fade_startup_timeout, shell); |
| 4487 | wl_event_source_timer_update(shell->fade.startup_timer, 15000); |
| 4488 | } |
| 4489 | |
| 4490 | static void |
Ander Conselvan de Oliveira | a457563 | 2013-02-21 18:35:23 +0200 | [diff] [blame] | 4491 | idle_handler(struct wl_listener *listener, void *data) |
Ander Conselvan de Oliveira | 19d10ef | 2013-02-21 18:35:20 +0200 | [diff] [blame] | 4492 | { |
| 4493 | struct desktop_shell *shell = |
Ander Conselvan de Oliveira | a457563 | 2013-02-21 18:35:23 +0200 | [diff] [blame] | 4494 | container_of(listener, struct desktop_shell, idle_listener); |
Ander Conselvan de Oliveira | 19d10ef | 2013-02-21 18:35:20 +0200 | [diff] [blame] | 4495 | |
| 4496 | shell_fade(shell, FADE_OUT); |
| 4497 | /* lock() is called from shell_fade_done() */ |
| 4498 | } |
| 4499 | |
| 4500 | static void |
Ander Conselvan de Oliveira | a457563 | 2013-02-21 18:35:23 +0200 | [diff] [blame] | 4501 | wake_handler(struct wl_listener *listener, void *data) |
Ander Conselvan de Oliveira | 19d10ef | 2013-02-21 18:35:20 +0200 | [diff] [blame] | 4502 | { |
| 4503 | struct desktop_shell *shell = |
Ander Conselvan de Oliveira | a457563 | 2013-02-21 18:35:23 +0200 | [diff] [blame] | 4504 | container_of(listener, struct desktop_shell, wake_listener); |
Ander Conselvan de Oliveira | 19d10ef | 2013-02-21 18:35:20 +0200 | [diff] [blame] | 4505 | |
Ander Conselvan de Oliveira | 19d10ef | 2013-02-21 18:35:20 +0200 | [diff] [blame] | 4506 | unlock(shell); |
| 4507 | } |
| 4508 | |
| 4509 | static void |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 4510 | center_on_output(struct weston_view *view, struct weston_output *output) |
Pekka Paalanen | 77346a6 | 2011-11-30 16:26:35 +0200 | [diff] [blame] | 4511 | { |
Giulio Camuffo | b836664 | 2013-04-25 13:57:46 +0300 | [diff] [blame] | 4512 | int32_t surf_x, surf_y, width, height; |
Ander Conselvan de Oliveira | 012b4c7 | 2012-11-27 17:03:42 +0200 | [diff] [blame] | 4513 | float x, y; |
Pekka Paalanen | 77346a6 | 2011-11-30 16:26:35 +0200 | [diff] [blame] | 4514 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 4515 | surface_subsurfaces_boundingbox(view->surface, &surf_x, &surf_y, &width, &height); |
Giulio Camuffo | b836664 | 2013-04-25 13:57:46 +0300 | [diff] [blame] | 4516 | |
| 4517 | x = output->x + (output->width - width) / 2 - surf_x / 2; |
| 4518 | y = output->y + (output->height - height) / 2 - surf_y / 2; |
Ander Conselvan de Oliveira | 012b4c7 | 2012-11-27 17:03:42 +0200 | [diff] [blame] | 4519 | |
Jason Ekstrand | 918f2dd | 2013-12-02 21:01:53 -0600 | [diff] [blame] | 4520 | weston_view_set_position(view, x, y); |
Pekka Paalanen | 77346a6 | 2011-11-30 16:26:35 +0200 | [diff] [blame] | 4521 | } |
| 4522 | |
| 4523 | static void |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 4524 | weston_view_set_initial_position(struct weston_view *view, |
| 4525 | struct desktop_shell *shell) |
Rob Bradford | ac63e5b | 2012-08-13 14:07:52 +0100 | [diff] [blame] | 4526 | { |
| 4527 | struct weston_compositor *compositor = shell->compositor; |
| 4528 | int ix = 0, iy = 0; |
| 4529 | int range_x, range_y; |
| 4530 | int dx, dy, x, y, panel_height; |
| 4531 | struct weston_output *output, *target_output = NULL; |
| 4532 | struct weston_seat *seat; |
| 4533 | |
| 4534 | /* As a heuristic place the new window on the same output as the |
| 4535 | * pointer. Falling back to the output containing 0, 0. |
| 4536 | * |
| 4537 | * TODO: Do something clever for touch too? |
| 4538 | */ |
| 4539 | wl_list_for_each(seat, &compositor->seat_list, link) { |
Kristian Høgsberg | 2bf8762 | 2013-05-07 23:17:41 -0400 | [diff] [blame] | 4540 | if (seat->pointer) { |
Kristian Høgsberg | e314875 | 2013-05-06 23:19:49 -0400 | [diff] [blame] | 4541 | ix = wl_fixed_to_int(seat->pointer->x); |
| 4542 | iy = wl_fixed_to_int(seat->pointer->y); |
Rob Bradford | ac63e5b | 2012-08-13 14:07:52 +0100 | [diff] [blame] | 4543 | break; |
| 4544 | } |
| 4545 | } |
| 4546 | |
| 4547 | wl_list_for_each(output, &compositor->output_list, link) { |
| 4548 | if (pixman_region32_contains_point(&output->region, ix, iy, NULL)) { |
| 4549 | target_output = output; |
| 4550 | break; |
| 4551 | } |
| 4552 | } |
| 4553 | |
| 4554 | if (!target_output) { |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 4555 | weston_view_set_position(view, 10 + random() % 400, |
| 4556 | 10 + random() % 400); |
Rob Bradford | ac63e5b | 2012-08-13 14:07:52 +0100 | [diff] [blame] | 4557 | return; |
| 4558 | } |
| 4559 | |
| 4560 | /* Valid range within output where the surface will still be onscreen. |
| 4561 | * If this is negative it means that the surface is bigger than |
| 4562 | * output. |
| 4563 | */ |
| 4564 | panel_height = get_output_panel_height(shell, target_output); |
Jason Ekstrand | 918f2dd | 2013-12-02 21:01:53 -0600 | [diff] [blame] | 4565 | range_x = target_output->width - view->surface->width; |
Scott Moreau | 1bad5db | 2012-08-18 01:04:05 -0600 | [diff] [blame] | 4566 | range_y = (target_output->height - panel_height) - |
Jason Ekstrand | 918f2dd | 2013-12-02 21:01:53 -0600 | [diff] [blame] | 4567 | view->surface->height; |
Rob Bradford | ac63e5b | 2012-08-13 14:07:52 +0100 | [diff] [blame] | 4568 | |
Rob Bradford | 4cb88c7 | 2012-08-13 15:18:44 +0100 | [diff] [blame] | 4569 | if (range_x > 0) |
Rob Bradford | ac63e5b | 2012-08-13 14:07:52 +0100 | [diff] [blame] | 4570 | dx = random() % range_x; |
Rob Bradford | ac63e5b | 2012-08-13 14:07:52 +0100 | [diff] [blame] | 4571 | else |
Rob Bradford | 4cb88c7 | 2012-08-13 15:18:44 +0100 | [diff] [blame] | 4572 | dx = 0; |
| 4573 | |
| 4574 | if (range_y > 0) |
Rob Bradford | ac63e5b | 2012-08-13 14:07:52 +0100 | [diff] [blame] | 4575 | dy = panel_height + random() % range_y; |
Rob Bradford | 4cb88c7 | 2012-08-13 15:18:44 +0100 | [diff] [blame] | 4576 | else |
| 4577 | dy = panel_height; |
Rob Bradford | ac63e5b | 2012-08-13 14:07:52 +0100 | [diff] [blame] | 4578 | |
| 4579 | x = target_output->x + dx; |
| 4580 | y = target_output->y + dy; |
| 4581 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 4582 | weston_view_set_position(view, x, y); |
Rob Bradford | ac63e5b | 2012-08-13 14:07:52 +0100 | [diff] [blame] | 4583 | } |
| 4584 | |
| 4585 | static void |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 4586 | map(struct desktop_shell *shell, struct shell_surface *shsurf, |
Jason Ekstrand | 918f2dd | 2013-12-02 21:01:53 -0600 | [diff] [blame] | 4587 | int32_t sx, int32_t sy) |
Kristian Høgsberg | 02ec0a5 | 2011-04-23 13:04:11 -0400 | [diff] [blame] | 4588 | { |
Kristian Høgsberg | 8334bc1 | 2012-01-03 10:29:47 -0500 | [diff] [blame] | 4589 | struct weston_compositor *compositor = shell->compositor; |
Daniel Stone | b210468 | 2012-05-30 16:31:56 +0100 | [diff] [blame] | 4590 | struct weston_seat *seat; |
Juan Zhao | 96879df | 2012-02-07 08:45:41 +0800 | [diff] [blame] | 4591 | int panel_height = 0; |
Giulio Camuffo | b836664 | 2013-04-25 13:57:46 +0300 | [diff] [blame] | 4592 | int32_t surf_x, surf_y; |
Pekka Paalanen | 57da4a8 | 2011-11-23 16:42:16 +0200 | [diff] [blame] | 4593 | |
Pekka Paalanen | 77346a6 | 2011-11-30 16:26:35 +0200 | [diff] [blame] | 4594 | /* initial positioning, see also configure() */ |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 4595 | switch (shsurf->type) { |
Rafael Antognolli | ed207b4 | 2013-12-03 15:35:43 -0200 | [diff] [blame] | 4596 | case SHELL_SURFACE_TOPLEVEL: |
Rafael Antognolli | 03b1659 | 2013-12-03 15:35:42 -0200 | [diff] [blame] | 4597 | if (shsurf->state.fullscreen) { |
| 4598 | center_on_output(shsurf->view, shsurf->fullscreen_output); |
| 4599 | shell_map_fullscreen(shsurf); |
| 4600 | } else if (shsurf->state.maximized) { |
| 4601 | /* use surface configure to set the geometry */ |
| 4602 | panel_height = get_output_panel_height(shell, shsurf->output); |
| 4603 | surface_subsurfaces_boundingbox(shsurf->surface, |
| 4604 | &surf_x, &surf_y, NULL, NULL); |
| 4605 | weston_view_set_position(shsurf->view, |
| 4606 | shsurf->output->x - surf_x, |
| 4607 | shsurf->output->y + |
| 4608 | panel_height - surf_y); |
Rafael Antognolli | ed207b4 | 2013-12-03 15:35:43 -0200 | [diff] [blame] | 4609 | } else if (!shsurf->state.relative) { |
Rafael Antognolli | 03b1659 | 2013-12-03 15:35:42 -0200 | [diff] [blame] | 4610 | weston_view_set_initial_position(shsurf->view, shell); |
| 4611 | } |
Juan Zhao | 96879df | 2012-02-07 08:45:41 +0800 | [diff] [blame] | 4612 | break; |
Tiago Vignatti | 0f99701 | 2012-02-10 16:17:23 +0200 | [diff] [blame] | 4613 | case SHELL_SURFACE_POPUP: |
Kristian Høgsberg | 3730f36 | 2012-04-13 12:40:07 -0400 | [diff] [blame] | 4614 | shell_map_popup(shsurf); |
Rob Bradford | db99938 | 2012-12-06 12:07:48 +0000 | [diff] [blame] | 4615 | break; |
Ander Conselvan de Oliveira | e9e0515 | 2012-02-15 17:02:56 +0200 | [diff] [blame] | 4616 | case SHELL_SURFACE_NONE: |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 4617 | weston_view_set_position(shsurf->view, |
| 4618 | shsurf->view->geometry.x + sx, |
| 4619 | shsurf->view->geometry.y + sy); |
Tiago Vignatti | 0f99701 | 2012-02-10 16:17:23 +0200 | [diff] [blame] | 4620 | break; |
Philip Withnall | 0f640e2 | 2013-11-25 18:01:31 +0000 | [diff] [blame] | 4621 | case SHELL_SURFACE_XWAYLAND: |
Pekka Paalanen | 77346a6 | 2011-11-30 16:26:35 +0200 | [diff] [blame] | 4622 | default: |
| 4623 | ; |
| 4624 | } |
Kristian Høgsberg | 7584062 | 2011-09-06 13:48:16 -0400 | [diff] [blame] | 4625 | |
Philip Withnall | e1d75ae | 2013-11-25 18:01:41 +0000 | [diff] [blame] | 4626 | /* Surface stacking order, see also activate(). */ |
| 4627 | shell_surface_update_layer(shsurf); |
Pekka Paalanen | f0fc70d | 2011-11-15 13:34:54 +0200 | [diff] [blame] | 4628 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 4629 | if (shsurf->type != SHELL_SURFACE_NONE) { |
| 4630 | weston_view_update_transform(shsurf->view); |
Rafael Antognolli | 03b1659 | 2013-12-03 15:35:42 -0200 | [diff] [blame] | 4631 | if (shsurf->state.maximized) { |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 4632 | shsurf->surface->output = shsurf->output; |
| 4633 | shsurf->view->output = shsurf->output; |
| 4634 | } |
Ander Conselvan de Oliveira | de56c31 | 2012-03-05 15:39:23 +0200 | [diff] [blame] | 4635 | } |
Kristian Høgsberg | 2f88a40 | 2011-12-04 15:32:59 -0500 | [diff] [blame] | 4636 | |
Rafael Antognolli | ed207b4 | 2013-12-03 15:35:43 -0200 | [diff] [blame] | 4637 | if ((shsurf->type == SHELL_SURFACE_XWAYLAND || shsurf->state.relative) && |
| 4638 | shsurf->transient.flags == WL_SHELL_SURFACE_TRANSIENT_INACTIVE) { |
| 4639 | } |
| 4640 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 4641 | switch (shsurf->type) { |
Tiago Vignatti | fb2adba | 2013-06-12 15:43:21 -0300 | [diff] [blame] | 4642 | /* XXX: xwayland's using the same fields for transient type */ |
| 4643 | case SHELL_SURFACE_XWAYLAND: |
Tiago Vignatti | 99aeb1e | 2012-05-23 22:06:26 +0300 | [diff] [blame] | 4644 | if (shsurf->transient.flags == |
| 4645 | WL_SHELL_SURFACE_TRANSIENT_INACTIVE) |
| 4646 | break; |
| 4647 | case SHELL_SURFACE_TOPLEVEL: |
Rafael Antognolli | ed207b4 | 2013-12-03 15:35:43 -0200 | [diff] [blame] | 4648 | if (shsurf->state.relative && |
| 4649 | shsurf->transient.flags == WL_SHELL_SURFACE_TRANSIENT_INACTIVE) |
| 4650 | break; |
Rafael Antognolli | ba5d2d7 | 2013-12-04 17:49:55 -0200 | [diff] [blame] | 4651 | if (shell->locked) |
Rafael Antognolli | ed207b4 | 2013-12-03 15:35:43 -0200 | [diff] [blame] | 4652 | break; |
| 4653 | wl_list_for_each(seat, &compositor->seat_list, link) |
| 4654 | activate(shell, shsurf->surface, seat); |
Juan Zhao | 7bb92f0 | 2011-12-15 11:31:51 -0500 | [diff] [blame] | 4655 | break; |
Philip Withnall | 0f640e2 | 2013-11-25 18:01:31 +0000 | [diff] [blame] | 4656 | case SHELL_SURFACE_POPUP: |
| 4657 | case SHELL_SURFACE_NONE: |
Juan Zhao | 7bb92f0 | 2011-12-15 11:31:51 -0500 | [diff] [blame] | 4658 | default: |
| 4659 | break; |
| 4660 | } |
| 4661 | |
Rafael Antognolli | 03b1659 | 2013-12-03 15:35:42 -0200 | [diff] [blame] | 4662 | if (shsurf->type == SHELL_SURFACE_TOPLEVEL && |
| 4663 | !shsurf->state.maximized && !shsurf->state.fullscreen) |
Juan Zhao | e10d279 | 2012-04-25 19:09:52 +0800 | [diff] [blame] | 4664 | { |
| 4665 | switch (shell->win_animation_type) { |
| 4666 | case ANIMATION_FADE: |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 4667 | 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] | 4668 | break; |
| 4669 | case ANIMATION_ZOOM: |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 4670 | weston_zoom_run(shsurf->view, 0.5, 1.0, NULL, NULL); |
Juan Zhao | e10d279 | 2012-04-25 19:09:52 +0800 | [diff] [blame] | 4671 | break; |
Philip Withnall | 4a86a0a | 2013-11-25 18:01:32 +0000 | [diff] [blame] | 4672 | case ANIMATION_NONE: |
Juan Zhao | e10d279 | 2012-04-25 19:09:52 +0800 | [diff] [blame] | 4673 | default: |
| 4674 | break; |
| 4675 | } |
| 4676 | } |
Kristian Høgsberg | 32e24cc | 2011-11-09 12:07:35 -0500 | [diff] [blame] | 4677 | } |
| 4678 | |
| 4679 | static void |
Tiago Vignatti | be14326 | 2012-04-16 17:31:41 +0300 | [diff] [blame] | 4680 | configure(struct desktop_shell *shell, struct weston_surface *surface, |
Jason Ekstrand | 918f2dd | 2013-12-02 21:01:53 -0600 | [diff] [blame] | 4681 | float x, float y) |
Kristian Høgsberg | 32e24cc | 2011-11-09 12:07:35 -0500 | [diff] [blame] | 4682 | { |
Pekka Paalanen | 77346a6 | 2011-11-30 16:26:35 +0200 | [diff] [blame] | 4683 | struct shell_surface *shsurf; |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 4684 | struct weston_view *view; |
Jason Ekstrand | 918f2dd | 2013-12-02 21:01:53 -0600 | [diff] [blame] | 4685 | int32_t mx, my, surf_x, surf_y; |
Kristian Høgsberg | 32e24cc | 2011-11-09 12:07:35 -0500 | [diff] [blame] | 4686 | |
Pekka Paalanen | 77346a6 | 2011-11-30 16:26:35 +0200 | [diff] [blame] | 4687 | shsurf = get_shell_surface(surface); |
Pekka Paalanen | 77346a6 | 2011-11-30 16:26:35 +0200 | [diff] [blame] | 4688 | |
Rafael Antognolli | 03b1659 | 2013-12-03 15:35:42 -0200 | [diff] [blame] | 4689 | if (shsurf->state.fullscreen) |
Alex Wu | 4539b08 | 2012-03-01 12:57:46 +0800 | [diff] [blame] | 4690 | shell_configure_fullscreen(shsurf); |
Rafael Antognolli | 03b1659 | 2013-12-03 15:35:42 -0200 | [diff] [blame] | 4691 | else if (shsurf->state.maximized) { |
Alex Wu | 4539b08 | 2012-03-01 12:57:46 +0800 | [diff] [blame] | 4692 | /* setting x, y and using configure to change that geometry */ |
Giulio Camuffo | b836664 | 2013-04-25 13:57:46 +0300 | [diff] [blame] | 4693 | surface_subsurfaces_boundingbox(shsurf->surface, &surf_x, &surf_y, |
| 4694 | NULL, NULL); |
Jason Ekstrand | 918f2dd | 2013-12-02 21:01:53 -0600 | [diff] [blame] | 4695 | mx = shsurf->output->x - surf_x; |
| 4696 | my = shsurf->output->y + |
| 4697 | get_output_panel_height(shell,shsurf->output) - surf_y; |
| 4698 | weston_view_set_position(shsurf->view, mx, my); |
Rafael Antognolli | 03b1659 | 2013-12-03 15:35:42 -0200 | [diff] [blame] | 4699 | } else { |
Jason Ekstrand | 918f2dd | 2013-12-02 21:01:53 -0600 | [diff] [blame] | 4700 | weston_view_set_position(shsurf->view, x, y); |
Kristian Høgsberg | 7a5c979 | 2011-06-18 06:12:54 -0400 | [diff] [blame] | 4701 | } |
Kristian Høgsberg | 32e24cc | 2011-11-09 12:07:35 -0500 | [diff] [blame] | 4702 | |
Alex Wu | 4539b08 | 2012-03-01 12:57:46 +0800 | [diff] [blame] | 4703 | /* XXX: would a fullscreen surface need the same handling? */ |
Kristian Høgsberg | 6a8b553 | 2012-02-16 23:43:59 -0500 | [diff] [blame] | 4704 | if (surface->output) { |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 4705 | wl_list_for_each(view, &surface->views, surface_link) |
| 4706 | weston_view_update_transform(view); |
Pekka Paalanen | 77346a6 | 2011-11-30 16:26:35 +0200 | [diff] [blame] | 4707 | |
Rafael Antognolli | 03b1659 | 2013-12-03 15:35:42 -0200 | [diff] [blame] | 4708 | if (shsurf->state.maximized) |
Juan Zhao | 96879df | 2012-02-07 08:45:41 +0800 | [diff] [blame] | 4709 | surface->output = shsurf->output; |
Pekka Paalanen | 77346a6 | 2011-11-30 16:26:35 +0200 | [diff] [blame] | 4710 | } |
Kristian Høgsberg | 0793756 | 2011-04-12 17:25:42 -0400 | [diff] [blame] | 4711 | } |
| 4712 | |
Ander Conselvan de Oliveira | 093bfa3 | 2012-03-27 17:36:41 +0300 | [diff] [blame] | 4713 | static void |
Jason Ekstrand | 918f2dd | 2013-12-02 21:01:53 -0600 | [diff] [blame] | 4714 | 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] | 4715 | { |
Ander Conselvan de Oliveira | 7fb9f95 | 2012-03-27 17:36:42 +0300 | [diff] [blame] | 4716 | struct shell_surface *shsurf = get_shell_surface(es); |
Tiago Vignatti | be14326 | 2012-04-16 17:31:41 +0300 | [diff] [blame] | 4717 | struct desktop_shell *shell = shsurf->shell; |
Giulio Camuffo | 184df50 | 2013-02-21 11:29:21 +0100 | [diff] [blame] | 4718 | |
Tiago Vignatti | 70e5c9c | 2012-05-07 15:23:07 +0300 | [diff] [blame] | 4719 | int type_changed = 0; |
Ander Conselvan de Oliveira | 093bfa3 | 2012-03-27 17:36:41 +0300 | [diff] [blame] | 4720 | |
Kristian Høgsberg | 8eb0f4f | 2013-06-17 10:33:14 -0400 | [diff] [blame] | 4721 | if (!weston_surface_is_mapped(es) && |
| 4722 | !wl_list_empty(&shsurf->popup.grab_link)) { |
Giulio Camuffo | 5085a75 | 2013-03-25 21:42:45 +0100 | [diff] [blame] | 4723 | remove_popup_grab(shsurf); |
| 4724 | } |
| 4725 | |
Jason Ekstrand | 918f2dd | 2013-12-02 21:01:53 -0600 | [diff] [blame] | 4726 | if (es->width == 0) |
Giulio Camuffo | 184df50 | 2013-02-21 11:29:21 +0100 | [diff] [blame] | 4727 | return; |
| 4728 | |
Kristian Høgsberg | c8f8dd8 | 2013-12-05 23:20:33 -0800 | [diff] [blame] | 4729 | if (shsurf->state_changed) { |
Kristian Høgsberg | 7f366e7 | 2012-04-27 17:20:01 -0400 | [diff] [blame] | 4730 | set_surface_type(shsurf); |
Kristian Høgsberg | f7e23d5 | 2012-04-27 17:51:59 -0400 | [diff] [blame] | 4731 | type_changed = 1; |
| 4732 | } |
Kristian Høgsberg | 7f366e7 | 2012-04-27 17:20:01 -0400 | [diff] [blame] | 4733 | |
Ander Conselvan de Oliveira | 093bfa3 | 2012-03-27 17:36:41 +0300 | [diff] [blame] | 4734 | if (!weston_surface_is_mapped(es)) { |
Jason Ekstrand | 918f2dd | 2013-12-02 21:01:53 -0600 | [diff] [blame] | 4735 | map(shell, shsurf, sx, sy); |
Kristian Høgsberg | f7e23d5 | 2012-04-27 17:51:59 -0400 | [diff] [blame] | 4736 | } else if (type_changed || sx != 0 || sy != 0 || |
Jason Ekstrand | 918f2dd | 2013-12-02 21:01:53 -0600 | [diff] [blame] | 4737 | shsurf->last_width != es->width || |
| 4738 | shsurf->last_height != es->height) { |
| 4739 | shsurf->last_width = es->width; |
| 4740 | shsurf->last_height = es->height; |
John Kåre Alsaker | 490d02a | 2012-09-30 02:57:21 +0200 | [diff] [blame] | 4741 | float from_x, from_y; |
| 4742 | float to_x, to_y; |
Ander Conselvan de Oliveira | 093bfa3 | 2012-03-27 17:36:41 +0300 | [diff] [blame] | 4743 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 4744 | weston_view_to_global_float(shsurf->view, 0, 0, &from_x, &from_y); |
| 4745 | 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] | 4746 | configure(shell, es, |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 4747 | shsurf->view->geometry.x + to_x - from_x, |
Jason Ekstrand | 918f2dd | 2013-12-02 21:01:53 -0600 | [diff] [blame] | 4748 | shsurf->view->geometry.y + to_y - from_y); |
Ander Conselvan de Oliveira | 093bfa3 | 2012-03-27 17:36:41 +0300 | [diff] [blame] | 4749 | } |
| 4750 | } |
| 4751 | |
Zhang, Xiong Y | 3123693 | 2013-12-13 22:10:57 +0200 | [diff] [blame] | 4752 | static void |
| 4753 | shell_surface_output_destroyed(struct weston_surface *es) |
| 4754 | { |
| 4755 | struct shell_surface *shsurf = get_shell_surface(es); |
| 4756 | |
| 4757 | shsurf->saved_position_valid = false; |
Ander Conselvan de Oliveira | fc63fdd | 2013-12-13 22:10:58 +0200 | [diff] [blame] | 4758 | shsurf->next_state.maximized = false; |
| 4759 | shsurf->next_state.fullscreen = false; |
| 4760 | shsurf->state_changed = true; |
Zhang, Xiong Y | 3123693 | 2013-12-13 22:10:57 +0200 | [diff] [blame] | 4761 | } |
| 4762 | |
Tiago Vignatti | b7dbbd6 | 2012-09-25 17:57:01 +0300 | [diff] [blame] | 4763 | static void launch_desktop_shell_process(void *data); |
Pekka Paalanen | 4d733ee | 2012-01-17 14:36:27 +0200 | [diff] [blame] | 4764 | |
Kristian Høgsberg | 97d44aa | 2011-08-26 17:21:20 -0400 | [diff] [blame] | 4765 | static void |
Kristian Høgsberg | 8334bc1 | 2012-01-03 10:29:47 -0500 | [diff] [blame] | 4766 | desktop_shell_sigchld(struct weston_process *process, int status) |
Pekka Paalanen | 6cd281a | 2011-11-03 14:11:32 +0200 | [diff] [blame] | 4767 | { |
Pekka Paalanen | 4d733ee | 2012-01-17 14:36:27 +0200 | [diff] [blame] | 4768 | uint32_t time; |
Tiago Vignatti | be14326 | 2012-04-16 17:31:41 +0300 | [diff] [blame] | 4769 | struct desktop_shell *shell = |
| 4770 | container_of(process, struct desktop_shell, child.process); |
Pekka Paalanen | 6cd281a | 2011-11-03 14:11:32 +0200 | [diff] [blame] | 4771 | |
| 4772 | shell->child.process.pid = 0; |
| 4773 | shell->child.client = NULL; /* already destroyed by wayland */ |
Pekka Paalanen | 4d733ee | 2012-01-17 14:36:27 +0200 | [diff] [blame] | 4774 | |
| 4775 | /* if desktop-shell dies more than 5 times in 30 seconds, give up */ |
| 4776 | time = weston_compositor_get_time(); |
Kristian Høgsberg | f03a616 | 2012-01-17 11:07:42 -0500 | [diff] [blame] | 4777 | if (time - shell->child.deathstamp > 30000) { |
Pekka Paalanen | 4d733ee | 2012-01-17 14:36:27 +0200 | [diff] [blame] | 4778 | shell->child.deathstamp = time; |
| 4779 | shell->child.deathcount = 0; |
| 4780 | } |
| 4781 | |
| 4782 | shell->child.deathcount++; |
| 4783 | if (shell->child.deathcount > 5) { |
Emilio Pozuelo Monfort | 46ce798 | 2013-11-20 13:22:29 +0100 | [diff] [blame] | 4784 | weston_log("%s died, giving up.\n", shell->client); |
Pekka Paalanen | 4d733ee | 2012-01-17 14:36:27 +0200 | [diff] [blame] | 4785 | return; |
| 4786 | } |
| 4787 | |
Emilio Pozuelo Monfort | 46ce798 | 2013-11-20 13:22:29 +0100 | [diff] [blame] | 4788 | weston_log("%s died, respawning...\n", shell->client); |
Pekka Paalanen | 4d733ee | 2012-01-17 14:36:27 +0200 | [diff] [blame] | 4789 | launch_desktop_shell_process(shell); |
Pekka Paalanen | 79346ab | 2013-05-22 18:03:09 +0300 | [diff] [blame] | 4790 | shell_fade_startup(shell); |
Pekka Paalanen | 6cd281a | 2011-11-03 14:11:32 +0200 | [diff] [blame] | 4791 | } |
| 4792 | |
Tiago Vignatti | b7dbbd6 | 2012-09-25 17:57:01 +0300 | [diff] [blame] | 4793 | static void |
Ander Conselvan de Oliveira | 312ea4c | 2013-12-20 21:07:01 +0200 | [diff] [blame] | 4794 | desktop_shell_client_destroy(struct wl_listener *listener, void *data) |
| 4795 | { |
| 4796 | struct desktop_shell *shell; |
| 4797 | |
| 4798 | shell = container_of(listener, struct desktop_shell, |
| 4799 | child.client_destroy_listener); |
| 4800 | |
| 4801 | shell->child.client = NULL; |
| 4802 | } |
| 4803 | |
| 4804 | static void |
Tiago Vignatti | b7dbbd6 | 2012-09-25 17:57:01 +0300 | [diff] [blame] | 4805 | launch_desktop_shell_process(void *data) |
Pekka Paalanen | 6cd281a | 2011-11-03 14:11:32 +0200 | [diff] [blame] | 4806 | { |
Tiago Vignatti | b7dbbd6 | 2012-09-25 17:57:01 +0300 | [diff] [blame] | 4807 | struct desktop_shell *shell = data; |
Pekka Paalanen | 6cd281a | 2011-11-03 14:11:32 +0200 | [diff] [blame] | 4808 | |
Kristian Høgsberg | 8334bc1 | 2012-01-03 10:29:47 -0500 | [diff] [blame] | 4809 | shell->child.client = weston_client_launch(shell->compositor, |
Pekka Paalanen | 409ef0a | 2011-12-02 15:30:21 +0200 | [diff] [blame] | 4810 | &shell->child.process, |
Emilio Pozuelo Monfort | 46ce798 | 2013-11-20 13:22:29 +0100 | [diff] [blame] | 4811 | shell->client, |
Pekka Paalanen | 409ef0a | 2011-12-02 15:30:21 +0200 | [diff] [blame] | 4812 | desktop_shell_sigchld); |
| 4813 | |
| 4814 | if (!shell->child.client) |
Emilio Pozuelo Monfort | 46ce798 | 2013-11-20 13:22:29 +0100 | [diff] [blame] | 4815 | weston_log("not able to start %s\n", shell->client); |
Ander Conselvan de Oliveira | 312ea4c | 2013-12-20 21:07:01 +0200 | [diff] [blame] | 4816 | |
| 4817 | shell->child.client_destroy_listener.notify = |
| 4818 | desktop_shell_client_destroy; |
| 4819 | wl_client_add_destroy_listener(shell->child.client, |
| 4820 | &shell->child.client_destroy_listener); |
Pekka Paalanen | 6cd281a | 2011-11-03 14:11:32 +0200 | [diff] [blame] | 4821 | } |
| 4822 | |
| 4823 | static void |
Kristian Høgsberg | 97d44aa | 2011-08-26 17:21:20 -0400 | [diff] [blame] | 4824 | bind_shell(struct wl_client *client, void *data, uint32_t version, uint32_t id) |
| 4825 | { |
Tiago Vignatti | be14326 | 2012-04-16 17:31:41 +0300 | [diff] [blame] | 4826 | struct desktop_shell *shell = data; |
Jason Ekstrand | a85118c | 2013-06-27 20:17:02 -0500 | [diff] [blame] | 4827 | struct wl_resource *resource; |
Kristian Høgsberg | 97d44aa | 2011-08-26 17:21:20 -0400 | [diff] [blame] | 4828 | |
Jason Ekstrand | a85118c | 2013-06-27 20:17:02 -0500 | [diff] [blame] | 4829 | resource = wl_resource_create(client, &wl_shell_interface, 1, id); |
| 4830 | if (resource) |
| 4831 | wl_resource_set_implementation(resource, &shell_implementation, |
| 4832 | shell, NULL); |
Kristian Høgsberg | 97d44aa | 2011-08-26 17:21:20 -0400 | [diff] [blame] | 4833 | } |
| 4834 | |
Kristian Høgsberg | 7584062 | 2011-09-06 13:48:16 -0400 | [diff] [blame] | 4835 | static void |
Rafael Antognolli | e2a3455 | 2013-12-03 15:35:45 -0200 | [diff] [blame] | 4836 | bind_xdg_shell(struct wl_client *client, void *data, uint32_t version, uint32_t id) |
| 4837 | { |
| 4838 | struct desktop_shell *shell = data; |
| 4839 | struct wl_resource *resource; |
| 4840 | |
| 4841 | resource = wl_resource_create(client, &xdg_shell_interface, 1, id); |
| 4842 | if (resource) |
| 4843 | wl_resource_set_dispatcher(resource, |
| 4844 | xdg_shell_unversioned_dispatch, |
| 4845 | NULL, shell, NULL); |
| 4846 | } |
| 4847 | |
| 4848 | static void |
Pekka Paalanen | 9ef3e01 | 2011-11-15 13:34:48 +0200 | [diff] [blame] | 4849 | unbind_desktop_shell(struct wl_resource *resource) |
| 4850 | { |
Jason Ekstrand | 651f00e | 2013-06-14 10:07:54 -0500 | [diff] [blame] | 4851 | struct desktop_shell *shell = wl_resource_get_user_data(resource); |
Kristian Høgsberg | 1ec0c31 | 2011-11-15 16:39:55 -0500 | [diff] [blame] | 4852 | |
| 4853 | if (shell->locked) |
| 4854 | resume_desktop(shell); |
| 4855 | |
Pekka Paalanen | 9ef3e01 | 2011-11-15 13:34:48 +0200 | [diff] [blame] | 4856 | shell->child.desktop_shell = NULL; |
| 4857 | shell->prepare_event_sent = false; |
Pekka Paalanen | 9ef3e01 | 2011-11-15 13:34:48 +0200 | [diff] [blame] | 4858 | } |
| 4859 | |
| 4860 | static void |
Kristian Høgsberg | 7584062 | 2011-09-06 13:48:16 -0400 | [diff] [blame] | 4861 | bind_desktop_shell(struct wl_client *client, |
| 4862 | void *data, uint32_t version, uint32_t id) |
| 4863 | { |
Tiago Vignatti | be14326 | 2012-04-16 17:31:41 +0300 | [diff] [blame] | 4864 | struct desktop_shell *shell = data; |
Pekka Paalanen | bbe6052 | 2011-11-03 14:11:33 +0200 | [diff] [blame] | 4865 | struct wl_resource *resource; |
Kristian Høgsberg | 7584062 | 2011-09-06 13:48:16 -0400 | [diff] [blame] | 4866 | |
Jason Ekstrand | a85118c | 2013-06-27 20:17:02 -0500 | [diff] [blame] | 4867 | resource = wl_resource_create(client, &desktop_shell_interface, |
| 4868 | MIN(version, 2), id); |
Pekka Paalanen | bbe6052 | 2011-11-03 14:11:33 +0200 | [diff] [blame] | 4869 | |
Pekka Paalanen | 9ef3e01 | 2011-11-15 13:34:48 +0200 | [diff] [blame] | 4870 | if (client == shell->child.client) { |
Jason Ekstrand | a85118c | 2013-06-27 20:17:02 -0500 | [diff] [blame] | 4871 | wl_resource_set_implementation(resource, |
| 4872 | &desktop_shell_implementation, |
| 4873 | shell, unbind_desktop_shell); |
Pekka Paalanen | 9ef3e01 | 2011-11-15 13:34:48 +0200 | [diff] [blame] | 4874 | shell->child.desktop_shell = resource; |
Pekka Paalanen | 79346ab | 2013-05-22 18:03:09 +0300 | [diff] [blame] | 4875 | |
| 4876 | if (version < 2) |
| 4877 | shell_fade_startup(shell); |
| 4878 | |
Pekka Paalanen | bbe6052 | 2011-11-03 14:11:33 +0200 | [diff] [blame] | 4879 | return; |
Pekka Paalanen | 9ef3e01 | 2011-11-15 13:34:48 +0200 | [diff] [blame] | 4880 | } |
Pekka Paalanen | bbe6052 | 2011-11-03 14:11:33 +0200 | [diff] [blame] | 4881 | |
| 4882 | wl_resource_post_error(resource, WL_DISPLAY_ERROR_INVALID_OBJECT, |
| 4883 | "permission to bind desktop_shell denied"); |
Kristian Høgsberg | eae5de7 | 2012-04-11 22:42:15 -0400 | [diff] [blame] | 4884 | wl_resource_destroy(resource); |
Kristian Høgsberg | 7584062 | 2011-09-06 13:48:16 -0400 | [diff] [blame] | 4885 | } |
| 4886 | |
Pekka Paalanen | 6e16811 | 2011-11-24 11:34:05 +0200 | [diff] [blame] | 4887 | static void |
Jason Ekstrand | 918f2dd | 2013-12-02 21:01:53 -0600 | [diff] [blame] | 4888 | 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] | 4889 | { |
Giulio Camuffo | 7fe01b1 | 2013-03-28 18:02:42 +0100 | [diff] [blame] | 4890 | struct desktop_shell *shell = surface->configure_private; |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 4891 | struct weston_view *view; |
Kristian Høgsberg | 1a73a63 | 2012-06-26 22:15:53 -0400 | [diff] [blame] | 4892 | |
Jason Ekstrand | 918f2dd | 2013-12-02 21:01:53 -0600 | [diff] [blame] | 4893 | if (surface->width == 0) |
Giulio Camuffo | 184df50 | 2013-02-21 11:29:21 +0100 | [diff] [blame] | 4894 | return; |
| 4895 | |
Pekka Paalanen | 3a1d07d | 2012-12-20 14:02:13 +0200 | [diff] [blame] | 4896 | /* XXX: starting weston-screensaver beforehand does not work */ |
Kristian Høgsberg | 1a73a63 | 2012-06-26 22:15:53 -0400 | [diff] [blame] | 4897 | if (!shell->locked) |
| 4898 | return; |
| 4899 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 4900 | view = container_of(surface->views.next, struct weston_view, surface_link); |
| 4901 | center_on_output(view, surface->output); |
Kristian Høgsberg | 1a73a63 | 2012-06-26 22:15:53 -0400 | [diff] [blame] | 4902 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 4903 | if (wl_list_empty(&view->layer_link)) { |
| 4904 | wl_list_insert(shell->lock_layer.view_list.prev, |
| 4905 | &view->layer_link); |
| 4906 | weston_view_update_transform(view); |
Ander Conselvan de Oliveira | 859e885 | 2013-02-21 18:35:21 +0200 | [diff] [blame] | 4907 | wl_event_source_timer_update(shell->screensaver.timer, |
| 4908 | shell->screensaver.duration); |
Ander Conselvan de Oliveira | 19d10ef | 2013-02-21 18:35:20 +0200 | [diff] [blame] | 4909 | shell_fade(shell, FADE_IN); |
Kristian Høgsberg | 1a73a63 | 2012-06-26 22:15:53 -0400 | [diff] [blame] | 4910 | } |
| 4911 | } |
| 4912 | |
| 4913 | static void |
Pekka Paalanen | 6e16811 | 2011-11-24 11:34:05 +0200 | [diff] [blame] | 4914 | screensaver_set_surface(struct wl_client *client, |
| 4915 | struct wl_resource *resource, |
Kristian Høgsberg | 1a73a63 | 2012-06-26 22:15:53 -0400 | [diff] [blame] | 4916 | struct wl_resource *surface_resource, |
Pekka Paalanen | 6e16811 | 2011-11-24 11:34:05 +0200 | [diff] [blame] | 4917 | struct wl_resource *output_resource) |
| 4918 | { |
Jason Ekstrand | 651f00e | 2013-06-14 10:07:54 -0500 | [diff] [blame] | 4919 | struct desktop_shell *shell = wl_resource_get_user_data(resource); |
Jason Ekstrand | 0f2ef7e | 2013-06-14 10:07:53 -0500 | [diff] [blame] | 4920 | struct weston_surface *surface = |
| 4921 | wl_resource_get_user_data(surface_resource); |
Jason Ekstrand | a0d2dde | 2013-06-14 10:08:01 -0500 | [diff] [blame] | 4922 | struct weston_output *output = wl_resource_get_user_data(output_resource); |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 4923 | struct weston_view *view, *next; |
| 4924 | |
| 4925 | /* Make sure we only have one view */ |
| 4926 | wl_list_for_each_safe(view, next, &surface->views, surface_link) |
| 4927 | weston_view_destroy(view); |
| 4928 | weston_view_create(surface); |
Pekka Paalanen | 6e16811 | 2011-11-24 11:34:05 +0200 | [diff] [blame] | 4929 | |
Kristian Høgsberg | 1a73a63 | 2012-06-26 22:15:53 -0400 | [diff] [blame] | 4930 | surface->configure = screensaver_configure; |
Giulio Camuffo | 7fe01b1 | 2013-03-28 18:02:42 +0100 | [diff] [blame] | 4931 | surface->configure_private = shell; |
Pekka Paalanen | 77346a6 | 2011-11-30 16:26:35 +0200 | [diff] [blame] | 4932 | surface->output = output; |
Pekka Paalanen | 6e16811 | 2011-11-24 11:34:05 +0200 | [diff] [blame] | 4933 | } |
| 4934 | |
| 4935 | static const struct screensaver_interface screensaver_implementation = { |
| 4936 | screensaver_set_surface |
| 4937 | }; |
| 4938 | |
| 4939 | static void |
| 4940 | unbind_screensaver(struct wl_resource *resource) |
| 4941 | { |
Jason Ekstrand | 651f00e | 2013-06-14 10:07:54 -0500 | [diff] [blame] | 4942 | struct desktop_shell *shell = wl_resource_get_user_data(resource); |
Pekka Paalanen | 6e16811 | 2011-11-24 11:34:05 +0200 | [diff] [blame] | 4943 | |
Pekka Paalanen | 77346a6 | 2011-11-30 16:26:35 +0200 | [diff] [blame] | 4944 | shell->screensaver.binding = NULL; |
Pekka Paalanen | 6e16811 | 2011-11-24 11:34:05 +0200 | [diff] [blame] | 4945 | } |
| 4946 | |
| 4947 | static void |
| 4948 | bind_screensaver(struct wl_client *client, |
| 4949 | void *data, uint32_t version, uint32_t id) |
| 4950 | { |
Tiago Vignatti | be14326 | 2012-04-16 17:31:41 +0300 | [diff] [blame] | 4951 | struct desktop_shell *shell = data; |
Pekka Paalanen | 6e16811 | 2011-11-24 11:34:05 +0200 | [diff] [blame] | 4952 | struct wl_resource *resource; |
| 4953 | |
Jason Ekstrand | a85118c | 2013-06-27 20:17:02 -0500 | [diff] [blame] | 4954 | resource = wl_resource_create(client, &screensaver_interface, 1, id); |
Pekka Paalanen | 6e16811 | 2011-11-24 11:34:05 +0200 | [diff] [blame] | 4955 | |
Pekka Paalanen | 77346a6 | 2011-11-30 16:26:35 +0200 | [diff] [blame] | 4956 | if (shell->screensaver.binding == NULL) { |
Jason Ekstrand | a85118c | 2013-06-27 20:17:02 -0500 | [diff] [blame] | 4957 | wl_resource_set_implementation(resource, |
| 4958 | &screensaver_implementation, |
| 4959 | shell, unbind_screensaver); |
Pekka Paalanen | 77346a6 | 2011-11-30 16:26:35 +0200 | [diff] [blame] | 4960 | shell->screensaver.binding = resource; |
Pekka Paalanen | 6e16811 | 2011-11-24 11:34:05 +0200 | [diff] [blame] | 4961 | return; |
| 4962 | } |
| 4963 | |
| 4964 | wl_resource_post_error(resource, WL_DISPLAY_ERROR_INVALID_OBJECT, |
| 4965 | "interface object already bound"); |
Kristian Høgsberg | eae5de7 | 2012-04-11 22:42:15 -0400 | [diff] [blame] | 4966 | wl_resource_destroy(resource); |
Pekka Paalanen | 6e16811 | 2011-11-24 11:34:05 +0200 | [diff] [blame] | 4967 | } |
| 4968 | |
Kristian Høgsberg | 0704539 | 2012-02-19 18:52:44 -0500 | [diff] [blame] | 4969 | struct switcher { |
Tiago Vignatti | be14326 | 2012-04-16 17:31:41 +0300 | [diff] [blame] | 4970 | struct desktop_shell *shell; |
Kristian Høgsberg | 0704539 | 2012-02-19 18:52:44 -0500 | [diff] [blame] | 4971 | struct weston_surface *current; |
| 4972 | struct wl_listener listener; |
Kristian Høgsberg | 29139d4 | 2013-04-18 15:25:39 -0400 | [diff] [blame] | 4973 | struct weston_keyboard_grab grab; |
Kristian Høgsberg | 0704539 | 2012-02-19 18:52:44 -0500 | [diff] [blame] | 4974 | }; |
| 4975 | |
| 4976 | static void |
| 4977 | switcher_next(struct switcher *switcher) |
| 4978 | { |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 4979 | struct weston_view *view; |
Kristian Høgsberg | 0704539 | 2012-02-19 18:52:44 -0500 | [diff] [blame] | 4980 | struct weston_surface *first = NULL, *prev = NULL, *next = NULL; |
Kristian Høgsberg | 32e5686 | 2012-04-02 22:18:58 -0400 | [diff] [blame] | 4981 | struct shell_surface *shsurf; |
Kristian Høgsberg | b0d8e77 | 2012-06-18 16:34:58 -0400 | [diff] [blame] | 4982 | struct workspace *ws = get_current_workspace(switcher->shell); |
Kristian Høgsberg | 0704539 | 2012-02-19 18:52:44 -0500 | [diff] [blame] | 4983 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 4984 | wl_list_for_each(view, &ws->layer.view_list, layer_link) { |
Rafael Antognolli | ed207b4 | 2013-12-03 15:35:43 -0200 | [diff] [blame] | 4985 | shsurf = get_shell_surface(view->surface); |
Rafael Antognolli | 5031cbe | 2013-12-05 19:01:21 -0200 | [diff] [blame] | 4986 | if (shsurf && |
| 4987 | shsurf->type == SHELL_SURFACE_TOPLEVEL && |
| 4988 | shsurf->parent == NULL) { |
Kristian Høgsberg | 0704539 | 2012-02-19 18:52:44 -0500 | [diff] [blame] | 4989 | if (first == NULL) |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 4990 | first = view->surface; |
Kristian Høgsberg | 0704539 | 2012-02-19 18:52:44 -0500 | [diff] [blame] | 4991 | if (prev == switcher->current) |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 4992 | next = view->surface; |
| 4993 | prev = view->surface; |
| 4994 | view->alpha = 0.25; |
| 4995 | weston_view_geometry_dirty(view); |
| 4996 | weston_surface_damage(view->surface); |
Kristian Høgsberg | 0704539 | 2012-02-19 18:52:44 -0500 | [diff] [blame] | 4997 | } |
Alex Wu | 1659daa | 2012-04-01 20:13:09 +0800 | [diff] [blame] | 4998 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 4999 | if (is_black_surface(view->surface, NULL)) { |
| 5000 | view->alpha = 0.25; |
| 5001 | weston_view_geometry_dirty(view); |
| 5002 | weston_surface_damage(view->surface); |
Alex Wu | 1659daa | 2012-04-01 20:13:09 +0800 | [diff] [blame] | 5003 | } |
Kristian Høgsberg | 0704539 | 2012-02-19 18:52:44 -0500 | [diff] [blame] | 5004 | } |
| 5005 | |
| 5006 | if (next == NULL) |
| 5007 | next = first; |
| 5008 | |
Alex Wu | 07b2606 | 2012-03-12 16:06:01 +0800 | [diff] [blame] | 5009 | if (next == NULL) |
| 5010 | return; |
| 5011 | |
Kristian Høgsberg | 0704539 | 2012-02-19 18:52:44 -0500 | [diff] [blame] | 5012 | wl_list_remove(&switcher->listener.link); |
Jason Ekstrand | 26ed73c | 2013-06-06 22:34:41 -0500 | [diff] [blame] | 5013 | wl_signal_add(&next->destroy_signal, &switcher->listener); |
Kristian Høgsberg | 0704539 | 2012-02-19 18:52:44 -0500 | [diff] [blame] | 5014 | |
| 5015 | switcher->current = next; |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 5016 | wl_list_for_each(view, &next->views, surface_link) |
| 5017 | view->alpha = 1.0; |
Alex Wu | 1659daa | 2012-04-01 20:13:09 +0800 | [diff] [blame] | 5018 | |
Kristian Høgsberg | 32e5686 | 2012-04-02 22:18:58 -0400 | [diff] [blame] | 5019 | shsurf = get_shell_surface(switcher->current); |
Rafael Antognolli | 03b1659 | 2013-12-03 15:35:42 -0200 | [diff] [blame] | 5020 | if (shsurf && shsurf->state.fullscreen) |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 5021 | shsurf->fullscreen.black_view->alpha = 1.0; |
Kristian Høgsberg | 0704539 | 2012-02-19 18:52:44 -0500 | [diff] [blame] | 5022 | } |
| 5023 | |
| 5024 | static void |
Kristian Høgsberg | 27e3052 | 2012-04-11 23:18:23 -0400 | [diff] [blame] | 5025 | switcher_handle_surface_destroy(struct wl_listener *listener, void *data) |
Kristian Høgsberg | 0704539 | 2012-02-19 18:52:44 -0500 | [diff] [blame] | 5026 | { |
| 5027 | struct switcher *switcher = |
| 5028 | container_of(listener, struct switcher, listener); |
| 5029 | |
| 5030 | switcher_next(switcher); |
| 5031 | } |
| 5032 | |
| 5033 | static void |
Daniel Stone | 351eb61 | 2012-05-31 15:27:47 -0400 | [diff] [blame] | 5034 | switcher_destroy(struct switcher *switcher) |
Kristian Høgsberg | 0704539 | 2012-02-19 18:52:44 -0500 | [diff] [blame] | 5035 | { |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 5036 | struct weston_view *view; |
Kristian Høgsberg | 29139d4 | 2013-04-18 15:25:39 -0400 | [diff] [blame] | 5037 | struct weston_keyboard *keyboard = switcher->grab.keyboard; |
Kristian Høgsberg | b0d8e77 | 2012-06-18 16:34:58 -0400 | [diff] [blame] | 5038 | struct workspace *ws = get_current_workspace(switcher->shell); |
Kristian Høgsberg | 0704539 | 2012-02-19 18:52:44 -0500 | [diff] [blame] | 5039 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 5040 | 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] | 5041 | if (is_focus_view(view)) |
| 5042 | continue; |
| 5043 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 5044 | view->alpha = 1.0; |
| 5045 | weston_surface_damage(view->surface); |
Kristian Høgsberg | 0704539 | 2012-02-19 18:52:44 -0500 | [diff] [blame] | 5046 | } |
| 5047 | |
Alex Wu | 07b2606 | 2012-03-12 16:06:01 +0800 | [diff] [blame] | 5048 | if (switcher->current) |
Daniel Stone | 37816df | 2012-05-16 18:45:18 +0100 | [diff] [blame] | 5049 | activate(switcher->shell, switcher->current, |
| 5050 | (struct weston_seat *) keyboard->seat); |
Kristian Høgsberg | 0704539 | 2012-02-19 18:52:44 -0500 | [diff] [blame] | 5051 | wl_list_remove(&switcher->listener.link); |
Kristian Høgsberg | 29139d4 | 2013-04-18 15:25:39 -0400 | [diff] [blame] | 5052 | weston_keyboard_end_grab(keyboard); |
| 5053 | if (keyboard->input_method_resource) |
| 5054 | keyboard->grab = &keyboard->input_method_grab; |
Kristian Høgsberg | 0704539 | 2012-02-19 18:52:44 -0500 | [diff] [blame] | 5055 | free(switcher); |
| 5056 | } |
| 5057 | |
| 5058 | static void |
Kristian Høgsberg | 29139d4 | 2013-04-18 15:25:39 -0400 | [diff] [blame] | 5059 | switcher_key(struct weston_keyboard_grab *grab, |
Daniel Stone | c9785ea | 2012-05-30 16:31:52 +0100 | [diff] [blame] | 5060 | uint32_t time, uint32_t key, uint32_t state_w) |
Kristian Høgsberg | 0704539 | 2012-02-19 18:52:44 -0500 | [diff] [blame] | 5061 | { |
| 5062 | struct switcher *switcher = container_of(grab, struct switcher, grab); |
Daniel Stone | c9785ea | 2012-05-30 16:31:52 +0100 | [diff] [blame] | 5063 | enum wl_keyboard_key_state state = state_w; |
Daniel Stone | 351eb61 | 2012-05-31 15:27:47 -0400 | [diff] [blame] | 5064 | |
Daniel Stone | c9785ea | 2012-05-30 16:31:52 +0100 | [diff] [blame] | 5065 | if (key == KEY_TAB && state == WL_KEYBOARD_KEY_STATE_PRESSED) |
Daniel Stone | 351eb61 | 2012-05-31 15:27:47 -0400 | [diff] [blame] | 5066 | switcher_next(switcher); |
| 5067 | } |
| 5068 | |
| 5069 | static void |
Kristian Høgsberg | 29139d4 | 2013-04-18 15:25:39 -0400 | [diff] [blame] | 5070 | switcher_modifier(struct weston_keyboard_grab *grab, uint32_t serial, |
Daniel Stone | 351eb61 | 2012-05-31 15:27:47 -0400 | [diff] [blame] | 5071 | uint32_t mods_depressed, uint32_t mods_latched, |
| 5072 | uint32_t mods_locked, uint32_t group) |
| 5073 | { |
| 5074 | struct switcher *switcher = container_of(grab, struct switcher, grab); |
Daniel Stone | 37816df | 2012-05-16 18:45:18 +0100 | [diff] [blame] | 5075 | struct weston_seat *seat = (struct weston_seat *) grab->keyboard->seat; |
Kristian Høgsberg | 0704539 | 2012-02-19 18:52:44 -0500 | [diff] [blame] | 5076 | |
Daniel Stone | 351eb61 | 2012-05-31 15:27:47 -0400 | [diff] [blame] | 5077 | if ((seat->modifier_state & switcher->shell->binding_modifier) == 0) |
| 5078 | switcher_destroy(switcher); |
Kristian Høgsberg | b71302e | 2012-05-10 12:28:35 -0400 | [diff] [blame] | 5079 | } |
Kristian Høgsberg | 0704539 | 2012-02-19 18:52:44 -0500 | [diff] [blame] | 5080 | |
Jonas Ådahl | 1ea343e | 2013-10-25 23:18:05 +0200 | [diff] [blame] | 5081 | static void |
| 5082 | switcher_cancel(struct weston_keyboard_grab *grab) |
| 5083 | { |
| 5084 | struct switcher *switcher = container_of(grab, struct switcher, grab); |
| 5085 | |
| 5086 | switcher_destroy(switcher); |
| 5087 | } |
| 5088 | |
Kristian Høgsberg | 29139d4 | 2013-04-18 15:25:39 -0400 | [diff] [blame] | 5089 | static const struct weston_keyboard_grab_interface switcher_grab = { |
Daniel Stone | 351eb61 | 2012-05-31 15:27:47 -0400 | [diff] [blame] | 5090 | switcher_key, |
| 5091 | switcher_modifier, |
Jonas Ådahl | 1ea343e | 2013-10-25 23:18:05 +0200 | [diff] [blame] | 5092 | switcher_cancel, |
Kristian Høgsberg | 0704539 | 2012-02-19 18:52:44 -0500 | [diff] [blame] | 5093 | }; |
| 5094 | |
| 5095 | static void |
Kristian Høgsberg | e314875 | 2013-05-06 23:19:49 -0400 | [diff] [blame] | 5096 | switcher_binding(struct weston_seat *seat, uint32_t time, uint32_t key, |
Daniel Stone | 325fc2d | 2012-05-30 16:31:58 +0100 | [diff] [blame] | 5097 | void *data) |
Kristian Høgsberg | 0704539 | 2012-02-19 18:52:44 -0500 | [diff] [blame] | 5098 | { |
Tiago Vignatti | be14326 | 2012-04-16 17:31:41 +0300 | [diff] [blame] | 5099 | struct desktop_shell *shell = data; |
Kristian Høgsberg | 0704539 | 2012-02-19 18:52:44 -0500 | [diff] [blame] | 5100 | struct switcher *switcher; |
| 5101 | |
| 5102 | switcher = malloc(sizeof *switcher); |
Kristian Høgsberg | 02e79dc | 2012-04-12 09:55:26 -0400 | [diff] [blame] | 5103 | switcher->shell = shell; |
Kristian Høgsberg | 0704539 | 2012-02-19 18:52:44 -0500 | [diff] [blame] | 5104 | switcher->current = NULL; |
Kristian Høgsberg | 27e3052 | 2012-04-11 23:18:23 -0400 | [diff] [blame] | 5105 | switcher->listener.notify = switcher_handle_surface_destroy; |
Kristian Høgsberg | 0704539 | 2012-02-19 18:52:44 -0500 | [diff] [blame] | 5106 | wl_list_init(&switcher->listener.link); |
| 5107 | |
Alexander Larsson | f82b6ca | 2013-05-28 16:23:39 +0200 | [diff] [blame] | 5108 | restore_all_output_modes(shell->compositor); |
Kristian Høgsberg | b0d8e77 | 2012-06-18 16:34:58 -0400 | [diff] [blame] | 5109 | lower_fullscreen_layer(switcher->shell); |
Kristian Høgsberg | 0704539 | 2012-02-19 18:52:44 -0500 | [diff] [blame] | 5110 | switcher->grab.interface = &switcher_grab; |
Kristian Høgsberg | 29139d4 | 2013-04-18 15:25:39 -0400 | [diff] [blame] | 5111 | weston_keyboard_start_grab(seat->keyboard, &switcher->grab); |
| 5112 | weston_keyboard_set_focus(seat->keyboard, NULL); |
Kristian Høgsberg | 0704539 | 2012-02-19 18:52:44 -0500 | [diff] [blame] | 5113 | switcher_next(switcher); |
| 5114 | } |
| 5115 | |
Pekka Paalanen | 3c64723 | 2011-12-22 13:43:43 +0200 | [diff] [blame] | 5116 | static void |
Kristian Høgsberg | e314875 | 2013-05-06 23:19:49 -0400 | [diff] [blame] | 5117 | backlight_binding(struct weston_seat *seat, uint32_t time, uint32_t key, |
Daniel Stone | 325fc2d | 2012-05-30 16:31:58 +0100 | [diff] [blame] | 5118 | void *data) |
Tiago Vignatti | 8e53c7f | 2012-02-29 19:53:50 +0200 | [diff] [blame] | 5119 | { |
| 5120 | struct weston_compositor *compositor = data; |
| 5121 | struct weston_output *output; |
Tiago Vignatti | 5ab91ad | 2012-03-12 19:40:09 -0300 | [diff] [blame] | 5122 | long backlight_new = 0; |
Tiago Vignatti | 8e53c7f | 2012-02-29 19:53:50 +0200 | [diff] [blame] | 5123 | |
| 5124 | /* TODO: we're limiting to simple use cases, where we assume just |
| 5125 | * control on the primary display. We'd have to extend later if we |
| 5126 | * ever get support for setting backlights on random desktop LCD |
| 5127 | * panels though */ |
| 5128 | output = get_default_output(compositor); |
| 5129 | if (!output) |
| 5130 | return; |
| 5131 | |
| 5132 | if (!output->set_backlight) |
| 5133 | return; |
| 5134 | |
Tiago Vignatti | 5ab91ad | 2012-03-12 19:40:09 -0300 | [diff] [blame] | 5135 | if (key == KEY_F9 || key == KEY_BRIGHTNESSDOWN) |
| 5136 | backlight_new = output->backlight_current - 25; |
| 5137 | else if (key == KEY_F10 || key == KEY_BRIGHTNESSUP) |
| 5138 | backlight_new = output->backlight_current + 25; |
Tiago Vignatti | 8e53c7f | 2012-02-29 19:53:50 +0200 | [diff] [blame] | 5139 | |
Tiago Vignatti | 5ab91ad | 2012-03-12 19:40:09 -0300 | [diff] [blame] | 5140 | if (backlight_new < 5) |
| 5141 | backlight_new = 5; |
| 5142 | if (backlight_new > 255) |
| 5143 | backlight_new = 255; |
| 5144 | |
| 5145 | output->backlight_current = backlight_new; |
Tiago Vignatti | 8e53c7f | 2012-02-29 19:53:50 +0200 | [diff] [blame] | 5146 | output->set_backlight(output, output->backlight_current); |
| 5147 | } |
| 5148 | |
Ander Conselvan de Oliveira | c509d2b | 2012-11-08 17:20:45 +0200 | [diff] [blame] | 5149 | struct debug_binding_grab { |
Kristian Høgsberg | 29139d4 | 2013-04-18 15:25:39 -0400 | [diff] [blame] | 5150 | struct weston_keyboard_grab grab; |
Ander Conselvan de Oliveira | c509d2b | 2012-11-08 17:20:45 +0200 | [diff] [blame] | 5151 | struct weston_seat *seat; |
| 5152 | uint32_t key[2]; |
| 5153 | int key_released[2]; |
| 5154 | }; |
| 5155 | |
| 5156 | static void |
Kristian Høgsberg | 29139d4 | 2013-04-18 15:25:39 -0400 | [diff] [blame] | 5157 | 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] | 5158 | uint32_t key, uint32_t state) |
| 5159 | { |
| 5160 | struct debug_binding_grab *db = (struct debug_binding_grab *) grab; |
Rob Bradford | 880ebc7 | 2013-07-22 17:31:38 +0100 | [diff] [blame] | 5161 | struct weston_compositor *ec = db->seat->compositor; |
| 5162 | struct wl_display *display = ec->wl_display; |
Ander Conselvan de Oliveira | c509d2b | 2012-11-08 17:20:45 +0200 | [diff] [blame] | 5163 | struct wl_resource *resource; |
Ander Conselvan de Oliveira | c509d2b | 2012-11-08 17:20:45 +0200 | [diff] [blame] | 5164 | uint32_t serial; |
| 5165 | int send = 0, terminate = 0; |
| 5166 | int check_binding = 1; |
| 5167 | int i; |
Neil Roberts | 96d790e | 2013-09-19 17:32:00 +0100 | [diff] [blame] | 5168 | struct wl_list *resource_list; |
Ander Conselvan de Oliveira | c509d2b | 2012-11-08 17:20:45 +0200 | [diff] [blame] | 5169 | |
| 5170 | if (state == WL_KEYBOARD_KEY_STATE_RELEASED) { |
| 5171 | /* Do not run bindings on key releases */ |
| 5172 | check_binding = 0; |
| 5173 | |
| 5174 | for (i = 0; i < 2; i++) |
| 5175 | if (key == db->key[i]) |
| 5176 | db->key_released[i] = 1; |
| 5177 | |
| 5178 | if (db->key_released[0] && db->key_released[1]) { |
| 5179 | /* All key releases been swalled so end the grab */ |
| 5180 | terminate = 1; |
| 5181 | } else if (key != db->key[0] && key != db->key[1]) { |
| 5182 | /* Should not swallow release of other keys */ |
| 5183 | send = 1; |
| 5184 | } |
| 5185 | } else if (key == db->key[0] && !db->key_released[0]) { |
| 5186 | /* Do not check bindings for the first press of the binding |
| 5187 | * key. This allows it to be used as a debug shortcut. |
| 5188 | * We still need to swallow this event. */ |
| 5189 | check_binding = 0; |
| 5190 | } else if (db->key[1]) { |
| 5191 | /* If we already ran a binding don't process another one since |
| 5192 | * we can't keep track of all the binding keys that were |
| 5193 | * pressed in order to swallow the release events. */ |
| 5194 | send = 1; |
| 5195 | check_binding = 0; |
| 5196 | } |
| 5197 | |
| 5198 | if (check_binding) { |
Ander Conselvan de Oliveira | c509d2b | 2012-11-08 17:20:45 +0200 | [diff] [blame] | 5199 | if (weston_compositor_run_debug_binding(ec, db->seat, time, |
| 5200 | key, state)) { |
| 5201 | /* We ran a binding so swallow the press and keep the |
| 5202 | * grab to swallow the released too. */ |
| 5203 | send = 0; |
| 5204 | terminate = 0; |
| 5205 | db->key[1] = key; |
| 5206 | } else { |
| 5207 | /* Terminate the grab since the key pressed is not a |
| 5208 | * debug binding key. */ |
| 5209 | send = 1; |
| 5210 | terminate = 1; |
| 5211 | } |
| 5212 | } |
| 5213 | |
| 5214 | if (send) { |
Neil Roberts | 96d790e | 2013-09-19 17:32:00 +0100 | [diff] [blame] | 5215 | serial = wl_display_next_serial(display); |
| 5216 | resource_list = &grab->keyboard->focus_resource_list; |
| 5217 | wl_resource_for_each(resource, resource_list) { |
Ander Conselvan de Oliveira | c509d2b | 2012-11-08 17:20:45 +0200 | [diff] [blame] | 5218 | wl_keyboard_send_key(resource, serial, time, key, state); |
| 5219 | } |
| 5220 | } |
| 5221 | |
| 5222 | if (terminate) { |
Kristian Høgsberg | 29139d4 | 2013-04-18 15:25:39 -0400 | [diff] [blame] | 5223 | weston_keyboard_end_grab(grab->keyboard); |
| 5224 | if (grab->keyboard->input_method_resource) |
| 5225 | grab->keyboard->grab = &grab->keyboard->input_method_grab; |
Ander Conselvan de Oliveira | c509d2b | 2012-11-08 17:20:45 +0200 | [diff] [blame] | 5226 | free(db); |
| 5227 | } |
| 5228 | } |
| 5229 | |
| 5230 | static void |
Kristian Høgsberg | 29139d4 | 2013-04-18 15:25:39 -0400 | [diff] [blame] | 5231 | 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] | 5232 | uint32_t mods_depressed, uint32_t mods_latched, |
| 5233 | uint32_t mods_locked, uint32_t group) |
| 5234 | { |
| 5235 | struct wl_resource *resource; |
Neil Roberts | 96d790e | 2013-09-19 17:32:00 +0100 | [diff] [blame] | 5236 | struct wl_list *resource_list; |
Ander Conselvan de Oliveira | c509d2b | 2012-11-08 17:20:45 +0200 | [diff] [blame] | 5237 | |
Neil Roberts | 96d790e | 2013-09-19 17:32:00 +0100 | [diff] [blame] | 5238 | resource_list = &grab->keyboard->focus_resource_list; |
Ander Conselvan de Oliveira | c509d2b | 2012-11-08 17:20:45 +0200 | [diff] [blame] | 5239 | |
Neil Roberts | 96d790e | 2013-09-19 17:32:00 +0100 | [diff] [blame] | 5240 | wl_resource_for_each(resource, resource_list) { |
| 5241 | wl_keyboard_send_modifiers(resource, serial, mods_depressed, |
| 5242 | mods_latched, mods_locked, group); |
| 5243 | } |
Ander Conselvan de Oliveira | c509d2b | 2012-11-08 17:20:45 +0200 | [diff] [blame] | 5244 | } |
| 5245 | |
Jonas Ådahl | 1ea343e | 2013-10-25 23:18:05 +0200 | [diff] [blame] | 5246 | static void |
| 5247 | debug_binding_cancel(struct weston_keyboard_grab *grab) |
| 5248 | { |
| 5249 | struct debug_binding_grab *db = (struct debug_binding_grab *) grab; |
| 5250 | |
| 5251 | weston_keyboard_end_grab(grab->keyboard); |
| 5252 | free(db); |
| 5253 | } |
| 5254 | |
Kristian Høgsberg | 29139d4 | 2013-04-18 15:25:39 -0400 | [diff] [blame] | 5255 | struct weston_keyboard_grab_interface debug_binding_keyboard_grab = { |
Ander Conselvan de Oliveira | c509d2b | 2012-11-08 17:20:45 +0200 | [diff] [blame] | 5256 | debug_binding_key, |
Jonas Ådahl | 1ea343e | 2013-10-25 23:18:05 +0200 | [diff] [blame] | 5257 | debug_binding_modifiers, |
| 5258 | debug_binding_cancel, |
Ander Conselvan de Oliveira | c509d2b | 2012-11-08 17:20:45 +0200 | [diff] [blame] | 5259 | }; |
| 5260 | |
| 5261 | static void |
Kristian Høgsberg | e314875 | 2013-05-06 23:19:49 -0400 | [diff] [blame] | 5262 | 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] | 5263 | { |
| 5264 | struct debug_binding_grab *grab; |
| 5265 | |
| 5266 | grab = calloc(1, sizeof *grab); |
| 5267 | if (!grab) |
| 5268 | return; |
| 5269 | |
| 5270 | grab->seat = (struct weston_seat *) seat; |
| 5271 | grab->key[0] = key; |
| 5272 | grab->grab.interface = &debug_binding_keyboard_grab; |
Kristian Høgsberg | 29139d4 | 2013-04-18 15:25:39 -0400 | [diff] [blame] | 5273 | weston_keyboard_start_grab(seat->keyboard, &grab->grab); |
Ander Conselvan de Oliveira | c509d2b | 2012-11-08 17:20:45 +0200 | [diff] [blame] | 5274 | } |
| 5275 | |
Kristian Høgsberg | b41c081 | 2012-03-04 14:53:40 -0500 | [diff] [blame] | 5276 | static void |
Kristian Høgsberg | e314875 | 2013-05-06 23:19:49 -0400 | [diff] [blame] | 5277 | 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] | 5278 | void *data) |
Kristian Høgsberg | 92a57db | 2012-05-26 13:41:06 -0400 | [diff] [blame] | 5279 | { |
Kristian Høgsberg | fe7aa90 | 2013-05-08 09:54:37 -0400 | [diff] [blame] | 5280 | struct weston_surface *focus_surface; |
Kristian Høgsberg | 92a57db | 2012-05-26 13:41:06 -0400 | [diff] [blame] | 5281 | struct wl_client *client; |
Tiago Vignatti | 1d01b01 | 2012-09-27 17:48:36 +0300 | [diff] [blame] | 5282 | struct desktop_shell *shell = data; |
| 5283 | struct weston_compositor *compositor = shell->compositor; |
Kristian Høgsberg | 92a57db | 2012-05-26 13:41:06 -0400 | [diff] [blame] | 5284 | pid_t pid; |
Kristian Høgsberg | 92a57db | 2012-05-26 13:41:06 -0400 | [diff] [blame] | 5285 | |
Philipp Brüschweiler | 6cef009 | 2012-08-13 21:27:27 +0200 | [diff] [blame] | 5286 | focus_surface = seat->keyboard->focus; |
| 5287 | if (!focus_surface) |
| 5288 | return; |
| 5289 | |
Tiago Vignatti | 1d01b01 | 2012-09-27 17:48:36 +0300 | [diff] [blame] | 5290 | wl_signal_emit(&compositor->kill_signal, focus_surface); |
| 5291 | |
Jason Ekstrand | 26ed73c | 2013-06-06 22:34:41 -0500 | [diff] [blame] | 5292 | client = wl_resource_get_client(focus_surface->resource); |
Tiago Vignatti | 920f197 | 2012-09-27 17:48:35 +0300 | [diff] [blame] | 5293 | wl_client_get_credentials(client, &pid, NULL, NULL); |
| 5294 | |
| 5295 | /* Skip clients that we launched ourselves (the credentials of |
| 5296 | * the socketpair is ours) */ |
| 5297 | if (pid == getpid()) |
| 5298 | return; |
Kristian Høgsberg | 92a57db | 2012-05-26 13:41:06 -0400 | [diff] [blame] | 5299 | |
Daniel Stone | 325fc2d | 2012-05-30 16:31:58 +0100 | [diff] [blame] | 5300 | kill(pid, SIGKILL); |
Kristian Høgsberg | 92a57db | 2012-05-26 13:41:06 -0400 | [diff] [blame] | 5301 | } |
| 5302 | |
| 5303 | static void |
Kristian Høgsberg | e314875 | 2013-05-06 23:19:49 -0400 | [diff] [blame] | 5304 | workspace_up_binding(struct weston_seat *seat, uint32_t time, |
Jonas Ådahl | e3cddce | 2012-06-13 00:01:22 +0200 | [diff] [blame] | 5305 | uint32_t key, void *data) |
| 5306 | { |
| 5307 | struct desktop_shell *shell = data; |
| 5308 | unsigned int new_index = shell->workspaces.current; |
| 5309 | |
Kristian Høgsberg | ce345b0 | 2012-06-25 21:35:29 -0400 | [diff] [blame] | 5310 | if (shell->locked) |
Kristian Høgsberg | 4476aaf | 2012-06-25 14:03:13 -0400 | [diff] [blame] | 5311 | return; |
Jonas Ådahl | e3cddce | 2012-06-13 00:01:22 +0200 | [diff] [blame] | 5312 | if (new_index != 0) |
| 5313 | new_index--; |
| 5314 | |
| 5315 | change_workspace(shell, new_index); |
| 5316 | } |
| 5317 | |
| 5318 | static void |
Kristian Høgsberg | e314875 | 2013-05-06 23:19:49 -0400 | [diff] [blame] | 5319 | workspace_down_binding(struct weston_seat *seat, uint32_t time, |
Jonas Ådahl | e3cddce | 2012-06-13 00:01:22 +0200 | [diff] [blame] | 5320 | uint32_t key, void *data) |
| 5321 | { |
| 5322 | struct desktop_shell *shell = data; |
| 5323 | unsigned int new_index = shell->workspaces.current; |
| 5324 | |
Kristian Høgsberg | ce345b0 | 2012-06-25 21:35:29 -0400 | [diff] [blame] | 5325 | if (shell->locked) |
Kristian Høgsberg | 4476aaf | 2012-06-25 14:03:13 -0400 | [diff] [blame] | 5326 | return; |
Jonas Ådahl | e3cddce | 2012-06-13 00:01:22 +0200 | [diff] [blame] | 5327 | if (new_index < shell->workspaces.num - 1) |
| 5328 | new_index++; |
| 5329 | |
| 5330 | change_workspace(shell, new_index); |
| 5331 | } |
| 5332 | |
| 5333 | static void |
Kristian Høgsberg | e314875 | 2013-05-06 23:19:49 -0400 | [diff] [blame] | 5334 | workspace_f_binding(struct weston_seat *seat, uint32_t time, |
Jonas Ådahl | e3cddce | 2012-06-13 00:01:22 +0200 | [diff] [blame] | 5335 | uint32_t key, void *data) |
| 5336 | { |
| 5337 | struct desktop_shell *shell = data; |
| 5338 | unsigned int new_index; |
| 5339 | |
Kristian Høgsberg | ce345b0 | 2012-06-25 21:35:29 -0400 | [diff] [blame] | 5340 | if (shell->locked) |
Kristian Høgsberg | 4476aaf | 2012-06-25 14:03:13 -0400 | [diff] [blame] | 5341 | return; |
Jonas Ådahl | e3cddce | 2012-06-13 00:01:22 +0200 | [diff] [blame] | 5342 | new_index = key - KEY_F1; |
| 5343 | if (new_index >= shell->workspaces.num) |
| 5344 | new_index = shell->workspaces.num - 1; |
| 5345 | |
| 5346 | change_workspace(shell, new_index); |
| 5347 | } |
| 5348 | |
Jonas Ådahl | 8de6a1d | 2012-08-29 22:13:00 +0200 | [diff] [blame] | 5349 | static void |
Kristian Høgsberg | e314875 | 2013-05-06 23:19:49 -0400 | [diff] [blame] | 5350 | workspace_move_surface_up_binding(struct weston_seat *seat, uint32_t time, |
Jonas Ådahl | 8de6a1d | 2012-08-29 22:13:00 +0200 | [diff] [blame] | 5351 | uint32_t key, void *data) |
| 5352 | { |
| 5353 | struct desktop_shell *shell = data; |
| 5354 | unsigned int new_index = shell->workspaces.current; |
| 5355 | |
| 5356 | if (shell->locked) |
| 5357 | return; |
| 5358 | |
| 5359 | if (new_index != 0) |
| 5360 | new_index--; |
| 5361 | |
| 5362 | take_surface_to_workspace_by_seat(shell, seat, new_index); |
| 5363 | } |
| 5364 | |
| 5365 | static void |
Kristian Høgsberg | e314875 | 2013-05-06 23:19:49 -0400 | [diff] [blame] | 5366 | workspace_move_surface_down_binding(struct weston_seat *seat, uint32_t time, |
Jonas Ådahl | 8de6a1d | 2012-08-29 22:13:00 +0200 | [diff] [blame] | 5367 | uint32_t key, void *data) |
| 5368 | { |
| 5369 | struct desktop_shell *shell = data; |
| 5370 | unsigned int new_index = shell->workspaces.current; |
| 5371 | |
| 5372 | if (shell->locked) |
| 5373 | return; |
| 5374 | |
| 5375 | if (new_index < shell->workspaces.num - 1) |
| 5376 | new_index++; |
| 5377 | |
| 5378 | take_surface_to_workspace_by_seat(shell, seat, new_index); |
| 5379 | } |
Jonas Ådahl | e3cddce | 2012-06-13 00:01:22 +0200 | [diff] [blame] | 5380 | |
| 5381 | static void |
Xiong Zhang | 6b48142 | 2013-10-23 13:58:32 +0800 | [diff] [blame] | 5382 | handle_output_destroy(struct wl_listener *listener, void *data) |
| 5383 | { |
| 5384 | struct shell_output *output_listener = |
| 5385 | container_of(listener, struct shell_output, destroy_listener); |
| 5386 | |
| 5387 | wl_list_remove(&output_listener->destroy_listener.link); |
| 5388 | wl_list_remove(&output_listener->link); |
| 5389 | free(output_listener); |
| 5390 | } |
| 5391 | |
| 5392 | static void |
| 5393 | create_shell_output(struct desktop_shell *shell, |
| 5394 | struct weston_output *output) |
| 5395 | { |
| 5396 | struct shell_output *shell_output; |
| 5397 | |
| 5398 | shell_output = zalloc(sizeof *shell_output); |
| 5399 | if (shell_output == NULL) |
| 5400 | return; |
| 5401 | |
| 5402 | shell_output->output = output; |
| 5403 | shell_output->shell = shell; |
| 5404 | shell_output->destroy_listener.notify = handle_output_destroy; |
| 5405 | wl_signal_add(&output->destroy_signal, |
| 5406 | &shell_output->destroy_listener); |
Kristian Høgsberg | a3a0e18 | 2013-10-23 23:36:04 -0700 | [diff] [blame] | 5407 | wl_list_insert(shell->output_list.prev, &shell_output->link); |
Xiong Zhang | 6b48142 | 2013-10-23 13:58:32 +0800 | [diff] [blame] | 5408 | } |
| 5409 | |
| 5410 | static void |
| 5411 | handle_output_create(struct wl_listener *listener, void *data) |
| 5412 | { |
| 5413 | struct desktop_shell *shell = |
| 5414 | container_of(listener, struct desktop_shell, output_create_listener); |
| 5415 | struct weston_output *output = (struct weston_output *)data; |
| 5416 | |
| 5417 | create_shell_output(shell, output); |
| 5418 | } |
| 5419 | |
| 5420 | static void |
| 5421 | setup_output_destroy_handler(struct weston_compositor *ec, |
| 5422 | struct desktop_shell *shell) |
| 5423 | { |
| 5424 | struct weston_output *output; |
| 5425 | |
| 5426 | wl_list_init(&shell->output_list); |
| 5427 | wl_list_for_each(output, &ec->output_list, link) |
| 5428 | create_shell_output(shell, output); |
| 5429 | |
| 5430 | shell->output_create_listener.notify = handle_output_create; |
| 5431 | wl_signal_add(&ec->output_created_signal, |
| 5432 | &shell->output_create_listener); |
| 5433 | } |
| 5434 | |
| 5435 | static void |
Kristian Høgsberg | 02e79dc | 2012-04-12 09:55:26 -0400 | [diff] [blame] | 5436 | shell_destroy(struct wl_listener *listener, void *data) |
Pekka Paalanen | 3c64723 | 2011-12-22 13:43:43 +0200 | [diff] [blame] | 5437 | { |
Tiago Vignatti | be14326 | 2012-04-16 17:31:41 +0300 | [diff] [blame] | 5438 | struct desktop_shell *shell = |
| 5439 | container_of(listener, struct desktop_shell, destroy_listener); |
Jonas Ådahl | e3cddce | 2012-06-13 00:01:22 +0200 | [diff] [blame] | 5440 | struct workspace **ws; |
Xiong Zhang | 6b48142 | 2013-10-23 13:58:32 +0800 | [diff] [blame] | 5441 | struct shell_output *shell_output, *tmp; |
Pekka Paalanen | 3c64723 | 2011-12-22 13:43:43 +0200 | [diff] [blame] | 5442 | |
Kristian Høgsberg | 17bccae | 2014-01-16 16:46:28 -0800 | [diff] [blame] | 5443 | /* Force state to unlocked so we don't try to fade */ |
| 5444 | shell->locked = false; |
Pekka Paalanen | 9cf5cc8 | 2012-01-02 16:00:24 +0200 | [diff] [blame] | 5445 | if (shell->child.client) |
| 5446 | wl_client_destroy(shell->child.client); |
| 5447 | |
Ander Conselvan de Oliveira | a457563 | 2013-02-21 18:35:23 +0200 | [diff] [blame] | 5448 | wl_list_remove(&shell->idle_listener.link); |
| 5449 | wl_list_remove(&shell->wake_listener.link); |
Kristian Høgsberg | 677a5f5 | 2013-12-04 11:00:19 -0800 | [diff] [blame] | 5450 | |
| 5451 | input_panel_destroy(shell); |
Kristian Høgsberg | 88c1607 | 2012-05-16 08:04:19 -0400 | [diff] [blame] | 5452 | |
Xiong Zhang | 6b48142 | 2013-10-23 13:58:32 +0800 | [diff] [blame] | 5453 | wl_list_for_each_safe(shell_output, tmp, &shell->output_list, link) { |
| 5454 | wl_list_remove(&shell_output->destroy_listener.link); |
| 5455 | wl_list_remove(&shell_output->link); |
| 5456 | free(shell_output); |
| 5457 | } |
| 5458 | |
| 5459 | wl_list_remove(&shell->output_create_listener.link); |
| 5460 | |
Jonas Ådahl | e3cddce | 2012-06-13 00:01:22 +0200 | [diff] [blame] | 5461 | wl_array_for_each(ws, &shell->workspaces.array) |
| 5462 | workspace_destroy(*ws); |
| 5463 | wl_array_release(&shell->workspaces.array); |
| 5464 | |
Pekka Paalanen | 3c64723 | 2011-12-22 13:43:43 +0200 | [diff] [blame] | 5465 | free(shell->screensaver.path); |
Emilio Pozuelo Monfort | 46ce798 | 2013-11-20 13:22:29 +0100 | [diff] [blame] | 5466 | free(shell->client); |
Pekka Paalanen | 3c64723 | 2011-12-22 13:43:43 +0200 | [diff] [blame] | 5467 | free(shell); |
| 5468 | } |
| 5469 | |
Tiago Vignatti | 0b52d48 | 2012-04-20 18:54:25 +0300 | [diff] [blame] | 5470 | static void |
| 5471 | shell_add_bindings(struct weston_compositor *ec, struct desktop_shell *shell) |
| 5472 | { |
| 5473 | uint32_t mod; |
Jonas Ådahl | e3cddce | 2012-06-13 00:01:22 +0200 | [diff] [blame] | 5474 | int i, num_workspace_bindings; |
Tiago Vignatti | 0b52d48 | 2012-04-20 18:54:25 +0300 | [diff] [blame] | 5475 | |
| 5476 | /* fixed bindings */ |
Daniel Stone | 325fc2d | 2012-05-30 16:31:58 +0100 | [diff] [blame] | 5477 | weston_compositor_add_key_binding(ec, KEY_BACKSPACE, |
| 5478 | MODIFIER_CTRL | MODIFIER_ALT, |
| 5479 | terminate_binding, ec); |
| 5480 | weston_compositor_add_button_binding(ec, BTN_LEFT, 0, |
| 5481 | click_to_activate_binding, |
| 5482 | shell); |
Neil Roberts | a28c693 | 2013-10-03 16:43:04 +0100 | [diff] [blame] | 5483 | weston_compositor_add_touch_binding(ec, 0, |
| 5484 | touch_to_activate_binding, |
| 5485 | shell); |
Daniel Stone | 325fc2d | 2012-05-30 16:31:58 +0100 | [diff] [blame] | 5486 | weston_compositor_add_axis_binding(ec, WL_POINTER_AXIS_VERTICAL_SCROLL, |
| 5487 | MODIFIER_SUPER | MODIFIER_ALT, |
| 5488 | surface_opacity_binding, NULL); |
| 5489 | weston_compositor_add_axis_binding(ec, WL_POINTER_AXIS_VERTICAL_SCROLL, |
| 5490 | MODIFIER_SUPER, zoom_axis_binding, |
| 5491 | NULL); |
Tiago Vignatti | 0b52d48 | 2012-04-20 18:54:25 +0300 | [diff] [blame] | 5492 | |
| 5493 | /* configurable bindings */ |
| 5494 | mod = shell->binding_modifier; |
Daniel Stone | 325fc2d | 2012-05-30 16:31:58 +0100 | [diff] [blame] | 5495 | weston_compositor_add_key_binding(ec, KEY_PAGEUP, mod, |
| 5496 | zoom_key_binding, NULL); |
| 5497 | weston_compositor_add_key_binding(ec, KEY_PAGEDOWN, mod, |
| 5498 | zoom_key_binding, NULL); |
Kristian Høgsberg | 211b517 | 2014-01-11 13:10:21 -0800 | [diff] [blame] | 5499 | weston_compositor_add_key_binding(ec, KEY_M, mod | MODIFIER_SHIFT, |
| 5500 | maximize_binding, NULL); |
| 5501 | weston_compositor_add_key_binding(ec, KEY_F, mod | MODIFIER_SHIFT, |
| 5502 | fullscreen_binding, NULL); |
Daniel Stone | 325fc2d | 2012-05-30 16:31:58 +0100 | [diff] [blame] | 5503 | weston_compositor_add_button_binding(ec, BTN_LEFT, mod, move_binding, |
| 5504 | shell); |
Neil Roberts | aba0f25 | 2013-10-03 16:43:05 +0100 | [diff] [blame] | 5505 | weston_compositor_add_touch_binding(ec, mod, touch_move_binding, shell); |
Daniel Stone | 325fc2d | 2012-05-30 16:31:58 +0100 | [diff] [blame] | 5506 | weston_compositor_add_button_binding(ec, BTN_MIDDLE, mod, |
| 5507 | resize_binding, shell); |
Pekka Paalanen | 7bb6510 | 2013-05-22 18:03:04 +0300 | [diff] [blame] | 5508 | |
| 5509 | if (ec->capabilities & WESTON_CAP_ROTATION_ANY) |
| 5510 | weston_compositor_add_button_binding(ec, BTN_RIGHT, mod, |
| 5511 | rotate_binding, NULL); |
| 5512 | |
Daniel Stone | 325fc2d | 2012-05-30 16:31:58 +0100 | [diff] [blame] | 5513 | weston_compositor_add_key_binding(ec, KEY_TAB, mod, switcher_binding, |
| 5514 | shell); |
| 5515 | weston_compositor_add_key_binding(ec, KEY_F9, mod, backlight_binding, |
| 5516 | ec); |
| 5517 | weston_compositor_add_key_binding(ec, KEY_BRIGHTNESSDOWN, 0, |
| 5518 | backlight_binding, ec); |
| 5519 | weston_compositor_add_key_binding(ec, KEY_F10, mod, backlight_binding, |
| 5520 | ec); |
| 5521 | weston_compositor_add_key_binding(ec, KEY_BRIGHTNESSUP, 0, |
| 5522 | backlight_binding, ec); |
Daniel Stone | 325fc2d | 2012-05-30 16:31:58 +0100 | [diff] [blame] | 5523 | weston_compositor_add_key_binding(ec, KEY_K, mod, |
| 5524 | force_kill_binding, shell); |
Jonas Ådahl | e3cddce | 2012-06-13 00:01:22 +0200 | [diff] [blame] | 5525 | weston_compositor_add_key_binding(ec, KEY_UP, mod, |
| 5526 | workspace_up_binding, shell); |
| 5527 | weston_compositor_add_key_binding(ec, KEY_DOWN, mod, |
| 5528 | workspace_down_binding, shell); |
Jonas Ådahl | 8de6a1d | 2012-08-29 22:13:00 +0200 | [diff] [blame] | 5529 | weston_compositor_add_key_binding(ec, KEY_UP, mod | MODIFIER_SHIFT, |
| 5530 | workspace_move_surface_up_binding, |
| 5531 | shell); |
| 5532 | weston_compositor_add_key_binding(ec, KEY_DOWN, mod | MODIFIER_SHIFT, |
| 5533 | workspace_move_surface_down_binding, |
| 5534 | shell); |
Jonas Ådahl | e3cddce | 2012-06-13 00:01:22 +0200 | [diff] [blame] | 5535 | |
Kristian Høgsberg | d56ab4e | 2014-01-16 16:51:52 -0800 | [diff] [blame] | 5536 | if (shell->exposay_modifier) |
| 5537 | weston_compositor_add_modifier_binding(ec, shell->exposay_modifier, |
| 5538 | exposay_binding, shell); |
Daniel Stone | df8133b | 2013-11-19 11:37:14 +0100 | [diff] [blame] | 5539 | |
Jonas Ådahl | e3cddce | 2012-06-13 00:01:22 +0200 | [diff] [blame] | 5540 | /* Add bindings for mod+F[1-6] for workspace 1 to 6. */ |
| 5541 | if (shell->workspaces.num > 1) { |
| 5542 | num_workspace_bindings = shell->workspaces.num; |
| 5543 | if (num_workspace_bindings > 6) |
| 5544 | num_workspace_bindings = 6; |
| 5545 | for (i = 0; i < num_workspace_bindings; i++) |
| 5546 | weston_compositor_add_key_binding(ec, KEY_F1 + i, mod, |
| 5547 | workspace_f_binding, |
| 5548 | shell); |
| 5549 | } |
Ander Conselvan de Oliveira | c509d2b | 2012-11-08 17:20:45 +0200 | [diff] [blame] | 5550 | |
| 5551 | /* Debug bindings */ |
| 5552 | weston_compositor_add_key_binding(ec, KEY_SPACE, mod | MODIFIER_SHIFT, |
| 5553 | debug_binding, shell); |
Tiago Vignatti | 0b52d48 | 2012-04-20 18:54:25 +0300 | [diff] [blame] | 5554 | } |
| 5555 | |
Kristian Høgsberg | 1c56218 | 2011-05-02 22:09:20 -0400 | [diff] [blame] | 5556 | WL_EXPORT int |
Kristian Høgsberg | cb4685b | 2013-02-20 15:37:49 -0500 | [diff] [blame] | 5557 | module_init(struct weston_compositor *ec, |
Ossama Othman | a50e6e4 | 2013-05-14 09:48:26 -0700 | [diff] [blame] | 5558 | int *argc, char *argv[]) |
Kristian Høgsberg | 4cca349 | 2011-01-18 07:53:49 -0500 | [diff] [blame] | 5559 | { |
Kristian Høgsberg | f4d2f23 | 2012-08-10 10:05:39 -0400 | [diff] [blame] | 5560 | struct weston_seat *seat; |
Tiago Vignatti | be14326 | 2012-04-16 17:31:41 +0300 | [diff] [blame] | 5561 | struct desktop_shell *shell; |
Jonas Ådahl | e3cddce | 2012-06-13 00:01:22 +0200 | [diff] [blame] | 5562 | struct workspace **pws; |
| 5563 | unsigned int i; |
Tiago Vignatti | b7dbbd6 | 2012-09-25 17:57:01 +0300 | [diff] [blame] | 5564 | struct wl_event_loop *loop; |
Kristian Høgsberg | 02ec0a5 | 2011-04-23 13:04:11 -0400 | [diff] [blame] | 5565 | |
Peter Hutterer | f3d6227 | 2013-08-08 11:57:05 +1000 | [diff] [blame] | 5566 | shell = zalloc(sizeof *shell); |
Kristian Høgsberg | 02ec0a5 | 2011-04-23 13:04:11 -0400 | [diff] [blame] | 5567 | if (shell == NULL) |
| 5568 | return -1; |
| 5569 | |
Kristian Høgsberg | 7584062 | 2011-09-06 13:48:16 -0400 | [diff] [blame] | 5570 | shell->compositor = ec; |
Kristian Høgsberg | 02e79dc | 2012-04-12 09:55:26 -0400 | [diff] [blame] | 5571 | |
| 5572 | shell->destroy_listener.notify = shell_destroy; |
| 5573 | wl_signal_add(&ec->destroy_signal, &shell->destroy_listener); |
Ander Conselvan de Oliveira | a457563 | 2013-02-21 18:35:23 +0200 | [diff] [blame] | 5574 | shell->idle_listener.notify = idle_handler; |
| 5575 | wl_signal_add(&ec->idle_signal, &shell->idle_listener); |
| 5576 | shell->wake_listener.notify = wake_handler; |
| 5577 | wl_signal_add(&ec->wake_signal, &shell->wake_listener); |
Kristian Høgsberg | 677a5f5 | 2013-12-04 11:00:19 -0800 | [diff] [blame] | 5578 | |
Scott Moreau | ff1db4a | 2012-04-17 19:06:18 -0600 | [diff] [blame] | 5579 | ec->ping_handler = ping_handler; |
Kristian Høgsberg | 82a1d11 | 2012-07-19 14:02:00 -0400 | [diff] [blame] | 5580 | ec->shell_interface.shell = shell; |
Tiago Vignatti | bc052c9 | 2012-04-19 16:18:18 +0300 | [diff] [blame] | 5581 | ec->shell_interface.create_shell_surface = create_shell_surface; |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 5582 | ec->shell_interface.get_primary_view = get_primary_view; |
Tiago Vignatti | bc052c9 | 2012-04-19 16:18:18 +0300 | [diff] [blame] | 5583 | ec->shell_interface.set_toplevel = set_toplevel; |
Tiago Vignatti | 491bac1 | 2012-05-18 16:37:43 -0400 | [diff] [blame] | 5584 | ec->shell_interface.set_transient = set_transient; |
Kristian Høgsberg | b810eb5 | 2013-02-12 20:07:05 -0500 | [diff] [blame] | 5585 | ec->shell_interface.set_fullscreen = set_fullscreen; |
Tiago Vignatti | fb2adba | 2013-06-12 15:43:21 -0300 | [diff] [blame] | 5586 | ec->shell_interface.set_xwayland = set_xwayland; |
Kristian Høgsberg | 938b8fa | 2012-05-18 13:46:27 -0400 | [diff] [blame] | 5587 | ec->shell_interface.move = surface_move; |
Kristian Høgsberg | c1693f2 | 2012-05-22 16:56:23 -0400 | [diff] [blame] | 5588 | ec->shell_interface.resize = surface_resize; |
Giulio Camuffo | 62942ad | 2013-09-11 18:20:47 +0200 | [diff] [blame] | 5589 | ec->shell_interface.set_title = set_title; |
Kristian Høgsberg | 4cca349 | 2011-01-18 07:53:49 -0500 | [diff] [blame] | 5590 | |
Kristian Høgsberg | 3be2ce9 | 2012-02-29 12:42:35 -0500 | [diff] [blame] | 5591 | weston_layer_init(&shell->fullscreen_layer, &ec->cursor_layer.link); |
| 5592 | weston_layer_init(&shell->panel_layer, &shell->fullscreen_layer.link); |
Jonas Ådahl | e3cddce | 2012-06-13 00:01:22 +0200 | [diff] [blame] | 5593 | weston_layer_init(&shell->background_layer, &shell->panel_layer.link); |
| 5594 | weston_layer_init(&shell->lock_layer, NULL); |
Philipp Brüschweiler | 711fda8 | 2012-08-09 18:50:43 +0200 | [diff] [blame] | 5595 | weston_layer_init(&shell->input_panel_layer, NULL); |
Jonas Ådahl | e3cddce | 2012-06-13 00:01:22 +0200 | [diff] [blame] | 5596 | |
| 5597 | wl_array_init(&shell->workspaces.array); |
Jonas Ådahl | e9d2250 | 2012-08-29 22:13:01 +0200 | [diff] [blame] | 5598 | wl_list_init(&shell->workspaces.client_list); |
Kristian Høgsberg | 3be2ce9 | 2012-02-29 12:42:35 -0500 | [diff] [blame] | 5599 | |
Kristian Høgsberg | 677a5f5 | 2013-12-04 11:00:19 -0800 | [diff] [blame] | 5600 | if (input_panel_setup(shell) < 0) |
| 5601 | return -1; |
| 5602 | |
Kristian Høgsberg | 14e438c | 2013-05-26 21:48:14 -0400 | [diff] [blame] | 5603 | shell_configuration(shell); |
Pekka Paalanen | e955f1e | 2011-12-07 11:49:52 +0200 | [diff] [blame] | 5604 | |
Daniel Stone | df8133b | 2013-11-19 11:37:14 +0100 | [diff] [blame] | 5605 | shell->exposay.state_cur = EXPOSAY_LAYOUT_INACTIVE; |
| 5606 | shell->exposay.state_target = EXPOSAY_TARGET_CANCEL; |
| 5607 | |
Jonas Ådahl | e3cddce | 2012-06-13 00:01:22 +0200 | [diff] [blame] | 5608 | for (i = 0; i < shell->workspaces.num; i++) { |
| 5609 | pws = wl_array_add(&shell->workspaces.array, sizeof *pws); |
| 5610 | if (pws == NULL) |
| 5611 | return -1; |
| 5612 | |
| 5613 | *pws = workspace_create(); |
| 5614 | if (*pws == NULL) |
| 5615 | return -1; |
| 5616 | } |
| 5617 | activate_workspace(shell, 0); |
| 5618 | |
Jonas Ådahl | 8de6a1d | 2012-08-29 22:13:00 +0200 | [diff] [blame] | 5619 | wl_list_init(&shell->workspaces.anim_sticky_list); |
Jonas Ådahl | 62fcd04 | 2012-06-13 00:01:23 +0200 | [diff] [blame] | 5620 | wl_list_init(&shell->workspaces.animation.link); |
| 5621 | shell->workspaces.animation.frame = animate_workspace_change_frame; |
| 5622 | |
Kristian Høgsberg | 919cddb | 2013-07-08 19:03:57 -0400 | [diff] [blame] | 5623 | if (wl_global_create(ec->wl_display, &wl_shell_interface, 1, |
Kristian Høgsberg | 97d44aa | 2011-08-26 17:21:20 -0400 | [diff] [blame] | 5624 | shell, bind_shell) == NULL) |
Kristian Høgsberg | 4cca349 | 2011-01-18 07:53:49 -0500 | [diff] [blame] | 5625 | return -1; |
| 5626 | |
Rafael Antognolli | e2a3455 | 2013-12-03 15:35:45 -0200 | [diff] [blame] | 5627 | if (wl_global_create(ec->wl_display, &xdg_shell_interface, 1, |
| 5628 | shell, bind_xdg_shell) == NULL) |
| 5629 | return -1; |
| 5630 | |
Kristian Høgsberg | 919cddb | 2013-07-08 19:03:57 -0400 | [diff] [blame] | 5631 | if (wl_global_create(ec->wl_display, |
| 5632 | &desktop_shell_interface, 2, |
| 5633 | shell, bind_desktop_shell) == NULL) |
Kristian Høgsberg | 7584062 | 2011-09-06 13:48:16 -0400 | [diff] [blame] | 5634 | return -1; |
| 5635 | |
Kristian Høgsberg | 919cddb | 2013-07-08 19:03:57 -0400 | [diff] [blame] | 5636 | if (wl_global_create(ec->wl_display, &screensaver_interface, 1, |
| 5637 | shell, bind_screensaver) == NULL) |
Pekka Paalanen | 6e16811 | 2011-11-24 11:34:05 +0200 | [diff] [blame] | 5638 | return -1; |
| 5639 | |
Kristian Høgsberg | 919cddb | 2013-07-08 19:03:57 -0400 | [diff] [blame] | 5640 | if (wl_global_create(ec->wl_display, &workspace_manager_interface, 1, |
| 5641 | shell, bind_workspace_manager) == NULL) |
Jonas Ådahl | e9d2250 | 2012-08-29 22:13:01 +0200 | [diff] [blame] | 5642 | return -1; |
| 5643 | |
Kristian Høgsberg | f03a616 | 2012-01-17 11:07:42 -0500 | [diff] [blame] | 5644 | shell->child.deathstamp = weston_compositor_get_time(); |
Tiago Vignatti | b7dbbd6 | 2012-09-25 17:57:01 +0300 | [diff] [blame] | 5645 | |
Xiong Zhang | 6b48142 | 2013-10-23 13:58:32 +0800 | [diff] [blame] | 5646 | setup_output_destroy_handler(ec, shell); |
| 5647 | |
Tiago Vignatti | b7dbbd6 | 2012-09-25 17:57:01 +0300 | [diff] [blame] | 5648 | loop = wl_display_get_event_loop(ec->wl_display); |
| 5649 | wl_event_loop_add_idle(loop, launch_desktop_shell_process, shell); |
Pekka Paalanen | 6cd281a | 2011-11-03 14:11:32 +0200 | [diff] [blame] | 5650 | |
Ander Conselvan de Oliveira | 859e885 | 2013-02-21 18:35:21 +0200 | [diff] [blame] | 5651 | shell->screensaver.timer = |
| 5652 | wl_event_loop_add_timer(loop, screensaver_timeout, shell); |
| 5653 | |
Kristian Høgsberg | f4d2f23 | 2012-08-10 10:05:39 -0400 | [diff] [blame] | 5654 | wl_list_for_each(seat, &ec->seat_list, link) |
| 5655 | create_pointer_focus_listener(seat); |
Kristian Høgsberg | d56bd90 | 2012-06-05 09:58:51 -0400 | [diff] [blame] | 5656 | |
Tiago Vignatti | 0b52d48 | 2012-04-20 18:54:25 +0300 | [diff] [blame] | 5657 | shell_add_bindings(ec, shell); |
Kristian Høgsberg | 0793756 | 2011-04-12 17:25:42 -0400 | [diff] [blame] | 5658 | |
Pekka Paalanen | 79346ab | 2013-05-22 18:03:09 +0300 | [diff] [blame] | 5659 | shell_fade_init(shell); |
Ander Conselvan de Oliveira | 19d10ef | 2013-02-21 18:35:20 +0200 | [diff] [blame] | 5660 | |
Kristian Høgsberg | 4cca349 | 2011-01-18 07:53:49 -0500 | [diff] [blame] | 5661 | return 0; |
| 5662 | } |