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; |
| 201 | wl_fixed_t dx, dy; |
| 202 | }; |
| 203 | |
Pekka Paalanen | 460099f | 2012-01-20 16:48:25 +0200 | [diff] [blame] | 204 | struct rotate_grab { |
Ander Conselvan de Oliveira | fe0444a | 2012-04-04 17:48:05 +0300 | [diff] [blame] | 205 | struct shell_grab base; |
Kristian Høgsberg | 765e27b | 2012-01-27 13:36:13 -0500 | [diff] [blame] | 206 | struct weston_matrix rotation; |
Pekka Paalanen | 460099f | 2012-01-20 16:48:25 +0200 | [diff] [blame] | 207 | struct { |
John Kåre Alsaker | 490d02a | 2012-09-30 02:57:21 +0200 | [diff] [blame] | 208 | float x; |
| 209 | float y; |
Pekka Paalanen | 460099f | 2012-01-20 16:48:25 +0200 | [diff] [blame] | 210 | } center; |
| 211 | }; |
| 212 | |
Giulio Camuffo | 5085a75 | 2013-03-25 21:42:45 +0100 | [diff] [blame] | 213 | struct shell_seat { |
| 214 | struct weston_seat *seat; |
| 215 | struct wl_listener seat_destroy_listener; |
| 216 | |
| 217 | struct { |
Kristian Høgsberg | 02bbabb | 2013-05-06 22:15:05 -0400 | [diff] [blame] | 218 | struct weston_pointer_grab grab; |
Giulio Camuffo | 5085a75 | 2013-03-25 21:42:45 +0100 | [diff] [blame] | 219 | struct wl_list surfaces_list; |
| 220 | struct wl_client *client; |
| 221 | int32_t initial_up; |
| 222 | } popup_grab; |
| 223 | }; |
| 224 | |
Emilio Pozuelo Monfort | 1a26f1b | 2014-01-07 16:41:40 +0100 | [diff] [blame] | 225 | void |
| 226 | set_alpha_if_fullscreen(struct shell_surface *shsurf) |
| 227 | { |
| 228 | if (shsurf && shsurf->state.fullscreen) |
| 229 | shsurf->fullscreen.black_view->alpha = 0.25; |
| 230 | } |
| 231 | |
Alex Wu | bd3354b | 2012-04-17 17:20:49 +0800 | [diff] [blame] | 232 | static struct desktop_shell * |
| 233 | shell_surface_get_shell(struct shell_surface *shsurf); |
| 234 | |
Kristian Høgsberg | 0c36903 | 2013-02-14 21:31:44 -0500 | [diff] [blame] | 235 | static void |
Kristian Høgsberg | e314875 | 2013-05-06 23:19:49 -0400 | [diff] [blame] | 236 | surface_rotate(struct shell_surface *surface, struct weston_seat *seat); |
Kristian Høgsberg | 0c36903 | 2013-02-14 21:31:44 -0500 | [diff] [blame] | 237 | |
Pekka Paalanen | 79346ab | 2013-05-22 18:03:09 +0300 | [diff] [blame] | 238 | static void |
| 239 | shell_fade_startup(struct desktop_shell *shell); |
| 240 | |
Philip Withnall | becb77e | 2013-11-25 18:01:30 +0000 | [diff] [blame] | 241 | static struct shell_seat * |
| 242 | get_shell_seat(struct weston_seat *seat); |
| 243 | |
Philip Withnall | 648a4dd | 2013-11-25 18:01:44 +0000 | [diff] [blame] | 244 | static void |
| 245 | shell_surface_update_child_surface_layers(struct shell_surface *shsurf); |
| 246 | |
Alex Wu | bd3354b | 2012-04-17 17:20:49 +0800 | [diff] [blame] | 247 | static bool |
Rafael Antognolli | e2a3455 | 2013-12-03 15:35:45 -0200 | [diff] [blame] | 248 | shell_surface_is_wl_shell_surface(struct shell_surface *shsurf); |
| 249 | |
| 250 | static bool |
| 251 | shell_surface_is_xdg_surface(struct shell_surface *shsurf); |
| 252 | |
| 253 | static bool |
| 254 | shell_surface_is_xdg_popup(struct shell_surface *shsurf); |
| 255 | |
| 256 | static void |
| 257 | shell_surface_set_parent(struct shell_surface *shsurf, |
| 258 | struct weston_surface *parent); |
| 259 | |
| 260 | static bool |
Alex Wu | bd3354b | 2012-04-17 17:20:49 +0800 | [diff] [blame] | 261 | shell_surface_is_top_fullscreen(struct shell_surface *shsurf) |
| 262 | { |
| 263 | struct desktop_shell *shell; |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 264 | struct weston_view *top_fs_ev; |
Alex Wu | bd3354b | 2012-04-17 17:20:49 +0800 | [diff] [blame] | 265 | |
| 266 | shell = shell_surface_get_shell(shsurf); |
Quentin Glidic | c0d79ce | 2013-01-29 14:16:13 +0100 | [diff] [blame] | 267 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 268 | if (wl_list_empty(&shell->fullscreen_layer.view_list)) |
Alex Wu | bd3354b | 2012-04-17 17:20:49 +0800 | [diff] [blame] | 269 | return false; |
| 270 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 271 | top_fs_ev = container_of(shell->fullscreen_layer.view_list.next, |
| 272 | struct weston_view, |
Alex Wu | bd3354b | 2012-04-17 17:20:49 +0800 | [diff] [blame] | 273 | layer_link); |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 274 | return (shsurf == get_shell_surface(top_fs_ev->surface)); |
Alex Wu | bd3354b | 2012-04-17 17:20:49 +0800 | [diff] [blame] | 275 | } |
| 276 | |
Kristian Høgsberg | 6af8eb9 | 2012-01-25 16:57:11 -0500 | [diff] [blame] | 277 | static void |
Kristian Høgsberg | 27e3052 | 2012-04-11 23:18:23 -0400 | [diff] [blame] | 278 | destroy_shell_grab_shsurf(struct wl_listener *listener, void *data) |
Ander Conselvan de Oliveira | fe0444a | 2012-04-04 17:48:05 +0300 | [diff] [blame] | 279 | { |
| 280 | struct shell_grab *grab; |
| 281 | |
| 282 | grab = container_of(listener, struct shell_grab, |
| 283 | shsurf_destroy_listener); |
| 284 | |
| 285 | grab->shsurf = NULL; |
| 286 | } |
| 287 | |
Kristian Høgsberg | 1ef2313 | 2013-12-04 00:20:01 -0800 | [diff] [blame] | 288 | struct weston_view * |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 289 | get_default_view(struct weston_surface *surface) |
| 290 | { |
| 291 | struct shell_surface *shsurf; |
| 292 | struct weston_view *view; |
| 293 | |
| 294 | if (!surface || wl_list_empty(&surface->views)) |
| 295 | return NULL; |
| 296 | |
| 297 | shsurf = get_shell_surface(surface); |
| 298 | if (shsurf) |
| 299 | return shsurf->view; |
| 300 | |
| 301 | wl_list_for_each(view, &surface->views, surface_link) |
| 302 | if (weston_view_is_mapped(view)) |
| 303 | return view; |
| 304 | |
| 305 | return container_of(surface->views.next, struct weston_view, surface_link); |
| 306 | } |
| 307 | |
Ander Conselvan de Oliveira | fe0444a | 2012-04-04 17:48:05 +0300 | [diff] [blame] | 308 | static void |
Kristian Høgsberg | 02bbabb | 2013-05-06 22:15:05 -0400 | [diff] [blame] | 309 | popup_grab_end(struct weston_pointer *pointer); |
Kristian Høgsberg | 57e0907 | 2012-10-30 14:07:27 -0400 | [diff] [blame] | 310 | |
| 311 | static void |
Ander Conselvan de Oliveira | b9d2a0f | 2012-06-28 18:08:05 +0300 | [diff] [blame] | 312 | shell_grab_start(struct shell_grab *grab, |
Kristian Høgsberg | 02bbabb | 2013-05-06 22:15:05 -0400 | [diff] [blame] | 313 | const struct weston_pointer_grab_interface *interface, |
Ander Conselvan de Oliveira | b9d2a0f | 2012-06-28 18:08:05 +0300 | [diff] [blame] | 314 | struct shell_surface *shsurf, |
Kristian Høgsberg | 02bbabb | 2013-05-06 22:15:05 -0400 | [diff] [blame] | 315 | struct weston_pointer *pointer, |
Ander Conselvan de Oliveira | b9d2a0f | 2012-06-28 18:08:05 +0300 | [diff] [blame] | 316 | enum desktop_shell_cursor cursor) |
Ander Conselvan de Oliveira | fe0444a | 2012-04-04 17:48:05 +0300 | [diff] [blame] | 317 | { |
Ander Conselvan de Oliveira | b9d2a0f | 2012-06-28 18:08:05 +0300 | [diff] [blame] | 318 | struct desktop_shell *shell = shsurf->shell; |
| 319 | |
Kristian Høgsberg | 57e0907 | 2012-10-30 14:07:27 -0400 | [diff] [blame] | 320 | popup_grab_end(pointer); |
| 321 | |
Ander Conselvan de Oliveira | fe0444a | 2012-04-04 17:48:05 +0300 | [diff] [blame] | 322 | grab->grab.interface = interface; |
| 323 | grab->shsurf = shsurf; |
Kristian Høgsberg | 27e3052 | 2012-04-11 23:18:23 -0400 | [diff] [blame] | 324 | grab->shsurf_destroy_listener.notify = destroy_shell_grab_shsurf; |
Jason Ekstrand | 651f00e | 2013-06-14 10:07:54 -0500 | [diff] [blame] | 325 | wl_signal_add(&shsurf->destroy_signal, |
Kristian Høgsberg | 27e3052 | 2012-04-11 23:18:23 -0400 | [diff] [blame] | 326 | &grab->shsurf_destroy_listener); |
Ander Conselvan de Oliveira | fe0444a | 2012-04-04 17:48:05 +0300 | [diff] [blame] | 327 | |
Kristian Høgsberg | c85f1d4 | 2013-10-24 16:52:00 -0700 | [diff] [blame] | 328 | shsurf->grabbed = 1; |
Kristian Høgsberg | 02bbabb | 2013-05-06 22:15:05 -0400 | [diff] [blame] | 329 | weston_pointer_start_grab(pointer, &grab->grab); |
Kristian Høgsberg | c9974a0 | 2013-07-03 19:24:57 -0400 | [diff] [blame] | 330 | if (shell->child.desktop_shell) { |
| 331 | desktop_shell_send_grab_cursor(shell->child.desktop_shell, |
| 332 | cursor); |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 333 | weston_pointer_set_focus(pointer, |
| 334 | get_default_view(shell->grab_surface), |
Kristian Høgsberg | c9974a0 | 2013-07-03 19:24:57 -0400 | [diff] [blame] | 335 | wl_fixed_from_int(0), |
| 336 | wl_fixed_from_int(0)); |
| 337 | } |
Ander Conselvan de Oliveira | fe0444a | 2012-04-04 17:48:05 +0300 | [diff] [blame] | 338 | } |
| 339 | |
| 340 | static void |
Ander Conselvan de Oliveira | b9d2a0f | 2012-06-28 18:08:05 +0300 | [diff] [blame] | 341 | shell_grab_end(struct shell_grab *grab) |
Ander Conselvan de Oliveira | fe0444a | 2012-04-04 17:48:05 +0300 | [diff] [blame] | 342 | { |
Kristian Høgsberg | c85f1d4 | 2013-10-24 16:52:00 -0700 | [diff] [blame] | 343 | if (grab->shsurf) { |
Kristian Høgsberg | 47b5dca | 2012-06-07 18:08:04 -0400 | [diff] [blame] | 344 | wl_list_remove(&grab->shsurf_destroy_listener.link); |
Kristian Høgsberg | c85f1d4 | 2013-10-24 16:52:00 -0700 | [diff] [blame] | 345 | grab->shsurf->grabbed = 0; |
| 346 | } |
Ander Conselvan de Oliveira | b9d2a0f | 2012-06-28 18:08:05 +0300 | [diff] [blame] | 347 | |
Kristian Høgsberg | 9e5d7d1 | 2013-07-22 16:31:53 -0700 | [diff] [blame] | 348 | weston_pointer_end_grab(grab->grab.pointer); |
Ander Conselvan de Oliveira | fe0444a | 2012-04-04 17:48:05 +0300 | [diff] [blame] | 349 | } |
| 350 | |
| 351 | static void |
Rusty Lynch | 1084da5 | 2013-08-15 09:10:08 -0700 | [diff] [blame] | 352 | shell_touch_grab_start(struct shell_touch_grab *grab, |
| 353 | const struct weston_touch_grab_interface *interface, |
| 354 | struct shell_surface *shsurf, |
| 355 | struct weston_touch *touch) |
| 356 | { |
| 357 | struct desktop_shell *shell = shsurf->shell; |
| 358 | |
| 359 | grab->grab.interface = interface; |
| 360 | grab->shsurf = shsurf; |
| 361 | grab->shsurf_destroy_listener.notify = destroy_shell_grab_shsurf; |
| 362 | wl_signal_add(&shsurf->destroy_signal, |
| 363 | &grab->shsurf_destroy_listener); |
| 364 | |
| 365 | grab->touch = touch; |
Kristian Høgsberg | c85f1d4 | 2013-10-24 16:52:00 -0700 | [diff] [blame] | 366 | shsurf->grabbed = 1; |
Rusty Lynch | 1084da5 | 2013-08-15 09:10:08 -0700 | [diff] [blame] | 367 | |
| 368 | weston_touch_start_grab(touch, &grab->grab); |
| 369 | if (shell->child.desktop_shell) |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 370 | weston_touch_set_focus(touch->seat, |
| 371 | get_default_view(shell->grab_surface)); |
Rusty Lynch | 1084da5 | 2013-08-15 09:10:08 -0700 | [diff] [blame] | 372 | } |
| 373 | |
| 374 | static void |
| 375 | shell_touch_grab_end(struct shell_touch_grab *grab) |
| 376 | { |
Kristian Høgsberg | c85f1d4 | 2013-10-24 16:52:00 -0700 | [diff] [blame] | 377 | if (grab->shsurf) { |
Rusty Lynch | 1084da5 | 2013-08-15 09:10:08 -0700 | [diff] [blame] | 378 | wl_list_remove(&grab->shsurf_destroy_listener.link); |
Kristian Høgsberg | c85f1d4 | 2013-10-24 16:52:00 -0700 | [diff] [blame] | 379 | grab->shsurf->grabbed = 0; |
| 380 | } |
Rusty Lynch | 1084da5 | 2013-08-15 09:10:08 -0700 | [diff] [blame] | 381 | |
| 382 | weston_touch_end_grab(grab->touch); |
| 383 | } |
| 384 | |
| 385 | static void |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 386 | center_on_output(struct weston_view *view, |
Alex Wu | 4539b08 | 2012-03-01 12:57:46 +0800 | [diff] [blame] | 387 | struct weston_output *output); |
| 388 | |
Daniel Stone | 496ca17 | 2012-05-30 16:31:42 +0100 | [diff] [blame] | 389 | static enum weston_keyboard_modifier |
Tiago Vignatti | 0b52d48 | 2012-04-20 18:54:25 +0300 | [diff] [blame] | 390 | get_modifier(char *modifier) |
| 391 | { |
| 392 | if (!modifier) |
| 393 | return MODIFIER_SUPER; |
| 394 | |
| 395 | if (!strcmp("ctrl", modifier)) |
| 396 | return MODIFIER_CTRL; |
| 397 | else if (!strcmp("alt", modifier)) |
| 398 | return MODIFIER_ALT; |
| 399 | else if (!strcmp("super", modifier)) |
| 400 | return MODIFIER_SUPER; |
| 401 | else |
| 402 | return MODIFIER_SUPER; |
| 403 | } |
| 404 | |
Juan Zhao | e10d279 | 2012-04-25 19:09:52 +0800 | [diff] [blame] | 405 | static enum animation_type |
| 406 | get_animation_type(char *animation) |
| 407 | { |
Juan Zhao | e10d279 | 2012-04-25 19:09:52 +0800 | [diff] [blame] | 408 | if (!strcmp("zoom", animation)) |
| 409 | return ANIMATION_ZOOM; |
| 410 | else if (!strcmp("fade", animation)) |
| 411 | return ANIMATION_FADE; |
Louis-Francis Ratté-Boulianne | b482dbd | 2013-11-19 11:37:11 +0100 | [diff] [blame] | 412 | else if (!strcmp("dim-layer", animation)) |
| 413 | return ANIMATION_DIM_LAYER; |
Juan Zhao | e10d279 | 2012-04-25 19:09:52 +0800 | [diff] [blame] | 414 | else |
| 415 | return ANIMATION_NONE; |
| 416 | } |
| 417 | |
Alex Wu | 4539b08 | 2012-03-01 12:57:46 +0800 | [diff] [blame] | 418 | static void |
Kristian Høgsberg | 14e438c | 2013-05-26 21:48:14 -0400 | [diff] [blame] | 419 | shell_configuration(struct desktop_shell *shell) |
Pekka Paalanen | e955f1e | 2011-12-07 11:49:52 +0200 | [diff] [blame] | 420 | { |
Kristian Høgsberg | 673a889 | 2013-05-23 21:40:56 -0400 | [diff] [blame] | 421 | struct weston_config_section *section; |
| 422 | int duration; |
| 423 | char *s; |
Pekka Paalanen | e955f1e | 2011-12-07 11:49:52 +0200 | [diff] [blame] | 424 | |
Kristian Høgsberg | 673a889 | 2013-05-23 21:40:56 -0400 | [diff] [blame] | 425 | section = weston_config_get_section(shell->compositor->config, |
| 426 | "screensaver", NULL, NULL); |
| 427 | weston_config_section_get_string(section, |
| 428 | "path", &shell->screensaver.path, NULL); |
| 429 | weston_config_section_get_int(section, "duration", &duration, 60); |
Ander Conselvan de Oliveira | 859e885 | 2013-02-21 18:35:21 +0200 | [diff] [blame] | 430 | shell->screensaver.duration = duration * 1000; |
Kristian Høgsberg | 673a889 | 2013-05-23 21:40:56 -0400 | [diff] [blame] | 431 | |
| 432 | section = weston_config_get_section(shell->compositor->config, |
| 433 | "shell", NULL, NULL); |
| 434 | weston_config_section_get_string(section, |
Emilio Pozuelo Monfort | 8a81b83 | 2013-12-02 12:53:32 +0100 | [diff] [blame] | 435 | "client", &s, LIBEXECDIR "/" WESTON_SHELL_CLIENT); |
Emilio Pozuelo Monfort | 46ce798 | 2013-11-20 13:22:29 +0100 | [diff] [blame] | 436 | shell->client = s; |
| 437 | weston_config_section_get_string(section, |
Kristian Høgsberg | 673a889 | 2013-05-23 21:40:56 -0400 | [diff] [blame] | 438 | "binding-modifier", &s, "super"); |
| 439 | shell->binding_modifier = get_modifier(s); |
Quentin Glidic | 8418c29 | 2013-06-18 09:11:03 +0200 | [diff] [blame] | 440 | free(s); |
Kristian Høgsberg | 673a889 | 2013-05-23 21:40:56 -0400 | [diff] [blame] | 441 | weston_config_section_get_string(section, "animation", &s, "none"); |
| 442 | shell->win_animation_type = get_animation_type(s); |
Quentin Glidic | 8418c29 | 2013-06-18 09:11:03 +0200 | [diff] [blame] | 443 | free(s); |
Kristian Høgsberg | 724c8d9 | 2013-10-16 11:38:24 -0700 | [diff] [blame] | 444 | weston_config_section_get_string(section, |
| 445 | "startup-animation", &s, "fade"); |
| 446 | shell->startup_animation_type = get_animation_type(s); |
| 447 | free(s); |
Kristian Høgsberg | 912e0a1 | 2013-10-30 08:59:55 -0700 | [diff] [blame] | 448 | if (shell->startup_animation_type == ANIMATION_ZOOM) |
| 449 | shell->startup_animation_type = ANIMATION_NONE; |
Louis-Francis Ratté-Boulianne | b482dbd | 2013-11-19 11:37:11 +0100 | [diff] [blame] | 450 | weston_config_section_get_string(section, "focus-animation", &s, "none"); |
| 451 | shell->focus_animation_type = get_animation_type(s); |
| 452 | free(s); |
Kristian Høgsberg | 673a889 | 2013-05-23 21:40:56 -0400 | [diff] [blame] | 453 | weston_config_section_get_uint(section, "num-workspaces", |
| 454 | &shell->workspaces.num, |
| 455 | DEFAULT_NUM_WORKSPACES); |
Jonas Ådahl | e3cddce | 2012-06-13 00:01:22 +0200 | [diff] [blame] | 456 | } |
| 457 | |
Kristian Høgsberg | 1ef2313 | 2013-12-04 00:20:01 -0800 | [diff] [blame] | 458 | struct weston_output * |
Louis-Francis Ratté-Boulianne | b482dbd | 2013-11-19 11:37:11 +0100 | [diff] [blame] | 459 | get_default_output(struct weston_compositor *compositor) |
| 460 | { |
| 461 | return container_of(compositor->output_list.next, |
| 462 | struct weston_output, link); |
| 463 | } |
| 464 | |
| 465 | |
| 466 | /* no-op func for checking focus surface */ |
| 467 | static void |
Jason Ekstrand | 918f2dd | 2013-12-02 21:01:53 -0600 | [diff] [blame] | 468 | 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] | 469 | { |
| 470 | } |
| 471 | |
| 472 | static struct focus_surface * |
| 473 | get_focus_surface(struct weston_surface *surface) |
| 474 | { |
| 475 | if (surface->configure == focus_surface_configure) |
| 476 | return surface->configure_private; |
| 477 | else |
| 478 | return NULL; |
| 479 | } |
| 480 | |
| 481 | static bool |
| 482 | is_focus_surface (struct weston_surface *es) |
| 483 | { |
| 484 | return (es->configure == focus_surface_configure); |
| 485 | } |
| 486 | |
| 487 | static bool |
| 488 | is_focus_view (struct weston_view *view) |
| 489 | { |
| 490 | return is_focus_surface (view->surface); |
| 491 | } |
| 492 | |
| 493 | static struct focus_surface * |
| 494 | create_focus_surface(struct weston_compositor *ec, |
| 495 | struct weston_output *output) |
| 496 | { |
| 497 | struct focus_surface *fsurf = NULL; |
| 498 | struct weston_surface *surface = NULL; |
| 499 | |
| 500 | fsurf = malloc(sizeof *fsurf); |
| 501 | if (!fsurf) |
| 502 | return NULL; |
| 503 | |
| 504 | fsurf->surface = weston_surface_create(ec); |
| 505 | surface = fsurf->surface; |
| 506 | if (surface == NULL) { |
| 507 | free(fsurf); |
| 508 | return NULL; |
| 509 | } |
| 510 | |
| 511 | surface->configure = focus_surface_configure; |
| 512 | surface->output = output; |
| 513 | surface->configure_private = fsurf; |
| 514 | |
| 515 | fsurf->view = weston_view_create (surface); |
Emilio Pozuelo Monfort | da64426 | 2013-11-19 11:37:19 +0100 | [diff] [blame] | 516 | fsurf->view->output = output; |
Louis-Francis Ratté-Boulianne | b482dbd | 2013-11-19 11:37:11 +0100 | [diff] [blame] | 517 | |
Jason Ekstrand | 5c11a33 | 2013-12-04 20:32:03 -0600 | [diff] [blame] | 518 | weston_surface_set_size(surface, output->width, output->height); |
Jason Ekstrand | 918f2dd | 2013-12-02 21:01:53 -0600 | [diff] [blame] | 519 | weston_view_set_position(fsurf->view, output->x, output->y); |
Louis-Francis Ratté-Boulianne | b482dbd | 2013-11-19 11:37:11 +0100 | [diff] [blame] | 520 | weston_surface_set_color(surface, 0.0, 0.0, 0.0, 1.0); |
| 521 | pixman_region32_fini(&surface->opaque); |
| 522 | pixman_region32_init_rect(&surface->opaque, output->x, output->y, |
| 523 | output->width, output->height); |
| 524 | pixman_region32_fini(&surface->input); |
| 525 | pixman_region32_init(&surface->input); |
| 526 | |
| 527 | wl_list_init(&fsurf->workspace_transform.link); |
| 528 | |
| 529 | return fsurf; |
| 530 | } |
| 531 | |
| 532 | static void |
| 533 | focus_surface_destroy(struct focus_surface *fsurf) |
| 534 | { |
| 535 | weston_surface_destroy(fsurf->surface); |
| 536 | free(fsurf); |
| 537 | } |
| 538 | |
| 539 | static void |
| 540 | focus_animation_done(struct weston_view_animation *animation, void *data) |
| 541 | { |
| 542 | struct workspace *ws = data; |
| 543 | |
| 544 | ws->focus_animation = NULL; |
| 545 | } |
| 546 | |
Jonas Ådahl | e3cddce | 2012-06-13 00:01:22 +0200 | [diff] [blame] | 547 | static void |
Jonas Ådahl | 0476974 | 2012-06-13 00:01:24 +0200 | [diff] [blame] | 548 | focus_state_destroy(struct focus_state *state) |
| 549 | { |
| 550 | wl_list_remove(&state->seat_destroy_listener.link); |
| 551 | wl_list_remove(&state->surface_destroy_listener.link); |
| 552 | free(state); |
| 553 | } |
| 554 | |
| 555 | static void |
| 556 | focus_state_seat_destroy(struct wl_listener *listener, void *data) |
| 557 | { |
| 558 | struct focus_state *state = container_of(listener, |
| 559 | struct focus_state, |
| 560 | seat_destroy_listener); |
| 561 | |
| 562 | wl_list_remove(&state->link); |
| 563 | focus_state_destroy(state); |
| 564 | } |
| 565 | |
| 566 | static void |
| 567 | focus_state_surface_destroy(struct wl_listener *listener, void *data) |
| 568 | { |
| 569 | struct focus_state *state = container_of(listener, |
| 570 | struct focus_state, |
Kristian Høgsberg | b8e0d0f | 2012-07-31 10:30:26 -0400 | [diff] [blame] | 571 | surface_destroy_listener); |
Kristian Høgsberg | e377822 | 2012-07-31 17:29:30 -0400 | [diff] [blame] | 572 | struct desktop_shell *shell; |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 573 | struct weston_surface *main_surface, *next; |
| 574 | struct weston_view *view; |
Jonas Ådahl | 0476974 | 2012-06-13 00:01:24 +0200 | [diff] [blame] | 575 | |
Pekka Paalanen | 01388e2 | 2013-04-25 13:57:44 +0300 | [diff] [blame] | 576 | main_surface = weston_surface_get_main_surface(state->keyboard_focus); |
| 577 | |
Kristian Høgsberg | e377822 | 2012-07-31 17:29:30 -0400 | [diff] [blame] | 578 | next = NULL; |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 579 | wl_list_for_each(view, &state->ws->layer.view_list, layer_link) { |
| 580 | if (view->surface == main_surface) |
Kristian Høgsberg | e377822 | 2012-07-31 17:29:30 -0400 | [diff] [blame] | 581 | continue; |
Louis-Francis Ratté-Boulianne | b482dbd | 2013-11-19 11:37:11 +0100 | [diff] [blame] | 582 | if (is_focus_view(view)) |
| 583 | continue; |
Kristian Høgsberg | e377822 | 2012-07-31 17:29:30 -0400 | [diff] [blame] | 584 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 585 | next = view->surface; |
Kristian Høgsberg | e377822 | 2012-07-31 17:29:30 -0400 | [diff] [blame] | 586 | break; |
| 587 | } |
| 588 | |
Pekka Paalanen | 01388e2 | 2013-04-25 13:57:44 +0300 | [diff] [blame] | 589 | /* if the focus was a sub-surface, activate its main surface */ |
| 590 | if (main_surface != state->keyboard_focus) |
| 591 | next = main_surface; |
| 592 | |
Louis-Francis Ratté-Boulianne | b482dbd | 2013-11-19 11:37:11 +0100 | [diff] [blame] | 593 | shell = state->seat->compositor->shell_interface.shell; |
Kristian Høgsberg | e377822 | 2012-07-31 17:29:30 -0400 | [diff] [blame] | 594 | if (next) { |
Louis-Francis Ratté-Boulianne | b482dbd | 2013-11-19 11:37:11 +0100 | [diff] [blame] | 595 | state->keyboard_focus = NULL; |
Kristian Høgsberg | e377822 | 2012-07-31 17:29:30 -0400 | [diff] [blame] | 596 | activate(shell, next, state->seat); |
| 597 | } else { |
Louis-Francis Ratté-Boulianne | b482dbd | 2013-11-19 11:37:11 +0100 | [diff] [blame] | 598 | if (shell->focus_animation_type == ANIMATION_DIM_LAYER) { |
| 599 | if (state->ws->focus_animation) |
| 600 | weston_view_animation_destroy(state->ws->focus_animation); |
| 601 | |
| 602 | state->ws->focus_animation = weston_fade_run( |
| 603 | state->ws->fsurf_front->view, |
| 604 | state->ws->fsurf_front->view->alpha, 0.0, 300, |
| 605 | focus_animation_done, state->ws); |
| 606 | } |
| 607 | |
Kristian Høgsberg | e377822 | 2012-07-31 17:29:30 -0400 | [diff] [blame] | 608 | wl_list_remove(&state->link); |
| 609 | focus_state_destroy(state); |
| 610 | } |
Jonas Ådahl | 0476974 | 2012-06-13 00:01:24 +0200 | [diff] [blame] | 611 | } |
| 612 | |
| 613 | static struct focus_state * |
Kristian Høgsberg | 2f5faff | 2012-07-31 16:36:34 -0400 | [diff] [blame] | 614 | focus_state_create(struct weston_seat *seat, struct workspace *ws) |
Jonas Ådahl | 0476974 | 2012-06-13 00:01:24 +0200 | [diff] [blame] | 615 | { |
Jonas Ådahl | 0476974 | 2012-06-13 00:01:24 +0200 | [diff] [blame] | 616 | struct focus_state *state; |
Jonas Ådahl | 0476974 | 2012-06-13 00:01:24 +0200 | [diff] [blame] | 617 | |
| 618 | state = malloc(sizeof *state); |
| 619 | if (state == NULL) |
| 620 | return NULL; |
| 621 | |
Louis-Francis Ratté-Boulianne | b482dbd | 2013-11-19 11:37:11 +0100 | [diff] [blame] | 622 | state->keyboard_focus = NULL; |
Kristian Høgsberg | 2f5faff | 2012-07-31 16:36:34 -0400 | [diff] [blame] | 623 | state->ws = ws; |
Jonas Ådahl | 0476974 | 2012-06-13 00:01:24 +0200 | [diff] [blame] | 624 | state->seat = seat; |
Kristian Høgsberg | 2f5faff | 2012-07-31 16:36:34 -0400 | [diff] [blame] | 625 | wl_list_insert(&ws->focus_list, &state->link); |
Jonas Ådahl | 0476974 | 2012-06-13 00:01:24 +0200 | [diff] [blame] | 626 | |
| 627 | state->seat_destroy_listener.notify = focus_state_seat_destroy; |
| 628 | state->surface_destroy_listener.notify = focus_state_surface_destroy; |
Kristian Høgsberg | 4912454 | 2013-05-06 22:27:40 -0400 | [diff] [blame] | 629 | wl_signal_add(&seat->destroy_signal, |
Jonas Ådahl | 0476974 | 2012-06-13 00:01:24 +0200 | [diff] [blame] | 630 | &state->seat_destroy_listener); |
Kristian Høgsberg | 2f5faff | 2012-07-31 16:36:34 -0400 | [diff] [blame] | 631 | wl_list_init(&state->surface_destroy_listener.link); |
Jonas Ådahl | 0476974 | 2012-06-13 00:01:24 +0200 | [diff] [blame] | 632 | |
| 633 | return state; |
| 634 | } |
| 635 | |
Jonas Ådahl | 8538b22 | 2012-08-29 22:13:03 +0200 | [diff] [blame] | 636 | static struct focus_state * |
| 637 | ensure_focus_state(struct desktop_shell *shell, struct weston_seat *seat) |
| 638 | { |
| 639 | struct workspace *ws = get_current_workspace(shell); |
| 640 | struct focus_state *state; |
| 641 | |
| 642 | wl_list_for_each(state, &ws->focus_list, link) |
| 643 | if (state->seat == seat) |
| 644 | break; |
| 645 | |
| 646 | if (&state->link == &ws->focus_list) |
| 647 | state = focus_state_create(seat, ws); |
| 648 | |
| 649 | return state; |
| 650 | } |
| 651 | |
Jonas Ådahl | 0476974 | 2012-06-13 00:01:24 +0200 | [diff] [blame] | 652 | static void |
Kristian Høgsberg | 2f5faff | 2012-07-31 16:36:34 -0400 | [diff] [blame] | 653 | restore_focus_state(struct desktop_shell *shell, struct workspace *ws) |
Jonas Ådahl | 0476974 | 2012-06-13 00:01:24 +0200 | [diff] [blame] | 654 | { |
| 655 | struct focus_state *state, *next; |
Kristian Høgsberg | fe7aa90 | 2013-05-08 09:54:37 -0400 | [diff] [blame] | 656 | struct weston_surface *surface; |
Jonas Ådahl | 0476974 | 2012-06-13 00:01:24 +0200 | [diff] [blame] | 657 | |
| 658 | wl_list_for_each_safe(state, next, &ws->focus_list, link) { |
Kristian Høgsberg | fe7aa90 | 2013-05-08 09:54:37 -0400 | [diff] [blame] | 659 | surface = state->keyboard_focus; |
Jonas Ådahl | 5689944 | 2012-08-29 22:12:59 +0200 | [diff] [blame] | 660 | |
Kristian Høgsberg | e314875 | 2013-05-06 23:19:49 -0400 | [diff] [blame] | 661 | weston_keyboard_set_focus(state->seat->keyboard, surface); |
Jonas Ådahl | 0476974 | 2012-06-13 00:01:24 +0200 | [diff] [blame] | 662 | } |
| 663 | } |
| 664 | |
| 665 | static void |
Jonas Ådahl | 8de6a1d | 2012-08-29 22:13:00 +0200 | [diff] [blame] | 666 | replace_focus_state(struct desktop_shell *shell, struct workspace *ws, |
| 667 | struct weston_seat *seat) |
| 668 | { |
| 669 | struct focus_state *state; |
Kristian Høgsberg | fe7aa90 | 2013-05-08 09:54:37 -0400 | [diff] [blame] | 670 | struct weston_surface *surface; |
Jonas Ådahl | 8de6a1d | 2012-08-29 22:13:00 +0200 | [diff] [blame] | 671 | |
| 672 | wl_list_for_each(state, &ws->focus_list, link) { |
| 673 | if (state->seat == seat) { |
Kristian Høgsberg | e314875 | 2013-05-06 23:19:49 -0400 | [diff] [blame] | 674 | surface = seat->keyboard->focus; |
Jason Ekstrand | 651f00e | 2013-06-14 10:07:54 -0500 | [diff] [blame] | 675 | state->keyboard_focus = surface; |
Jonas Ådahl | 8de6a1d | 2012-08-29 22:13:00 +0200 | [diff] [blame] | 676 | return; |
| 677 | } |
| 678 | } |
| 679 | } |
| 680 | |
| 681 | static void |
| 682 | drop_focus_state(struct desktop_shell *shell, struct workspace *ws, |
| 683 | struct weston_surface *surface) |
| 684 | { |
| 685 | struct focus_state *state; |
| 686 | |
| 687 | wl_list_for_each(state, &ws->focus_list, link) |
| 688 | if (state->keyboard_focus == surface) |
| 689 | state->keyboard_focus = NULL; |
| 690 | } |
| 691 | |
| 692 | static void |
Louis-Francis Ratté-Boulianne | b482dbd | 2013-11-19 11:37:11 +0100 | [diff] [blame] | 693 | animate_focus_change(struct desktop_shell *shell, struct workspace *ws, |
| 694 | struct weston_view *from, struct weston_view *to) |
| 695 | { |
| 696 | struct weston_output *output; |
| 697 | bool focus_surface_created = false; |
| 698 | |
| 699 | /* FIXME: Only support dim animation using two layers */ |
| 700 | if (from == to || shell->focus_animation_type != ANIMATION_DIM_LAYER) |
| 701 | return; |
| 702 | |
| 703 | output = get_default_output(shell->compositor); |
| 704 | if (ws->fsurf_front == NULL && (from || to)) { |
| 705 | ws->fsurf_front = create_focus_surface(shell->compositor, output); |
| 706 | ws->fsurf_back = create_focus_surface(shell->compositor, output); |
| 707 | ws->fsurf_front->view->alpha = 0.0; |
| 708 | ws->fsurf_back->view->alpha = 0.0; |
| 709 | focus_surface_created = true; |
| 710 | } else { |
| 711 | wl_list_remove(&ws->fsurf_front->view->layer_link); |
| 712 | wl_list_remove(&ws->fsurf_back->view->layer_link); |
| 713 | } |
| 714 | |
| 715 | if (ws->focus_animation) { |
| 716 | weston_view_animation_destroy(ws->focus_animation); |
| 717 | ws->focus_animation = NULL; |
| 718 | } |
| 719 | |
| 720 | if (to) |
| 721 | wl_list_insert(&to->layer_link, |
| 722 | &ws->fsurf_front->view->layer_link); |
| 723 | else if (from) |
| 724 | wl_list_insert(&ws->layer.view_list, |
| 725 | &ws->fsurf_front->view->layer_link); |
| 726 | |
| 727 | if (focus_surface_created) { |
| 728 | ws->focus_animation = weston_fade_run( |
| 729 | ws->fsurf_front->view, |
| 730 | ws->fsurf_front->view->alpha, 0.6, 300, |
| 731 | focus_animation_done, ws); |
| 732 | } else if (from) { |
| 733 | wl_list_insert(&from->layer_link, |
| 734 | &ws->fsurf_back->view->layer_link); |
| 735 | ws->focus_animation = weston_stable_fade_run( |
| 736 | ws->fsurf_front->view, 0.0, |
| 737 | ws->fsurf_back->view, 0.6, |
| 738 | focus_animation_done, ws); |
| 739 | } else if (to) { |
| 740 | wl_list_insert(&ws->layer.view_list, |
| 741 | &ws->fsurf_back->view->layer_link); |
| 742 | ws->focus_animation = weston_stable_fade_run( |
| 743 | ws->fsurf_front->view, 0.0, |
| 744 | ws->fsurf_back->view, 0.6, |
| 745 | focus_animation_done, ws); |
| 746 | } |
| 747 | } |
| 748 | |
| 749 | static void |
Jonas Ådahl | e3cddce | 2012-06-13 00:01:22 +0200 | [diff] [blame] | 750 | workspace_destroy(struct workspace *ws) |
| 751 | { |
Jonas Ådahl | 0476974 | 2012-06-13 00:01:24 +0200 | [diff] [blame] | 752 | struct focus_state *state, *next; |
| 753 | |
| 754 | wl_list_for_each_safe(state, next, &ws->focus_list, link) |
| 755 | focus_state_destroy(state); |
| 756 | |
Louis-Francis Ratté-Boulianne | b482dbd | 2013-11-19 11:37:11 +0100 | [diff] [blame] | 757 | if (ws->fsurf_front) |
| 758 | focus_surface_destroy(ws->fsurf_front); |
| 759 | if (ws->fsurf_back) |
| 760 | focus_surface_destroy(ws->fsurf_back); |
| 761 | |
Jonas Ådahl | e3cddce | 2012-06-13 00:01:22 +0200 | [diff] [blame] | 762 | free(ws); |
| 763 | } |
| 764 | |
Jonas Ådahl | 0476974 | 2012-06-13 00:01:24 +0200 | [diff] [blame] | 765 | static void |
| 766 | seat_destroyed(struct wl_listener *listener, void *data) |
| 767 | { |
| 768 | struct weston_seat *seat = data; |
| 769 | struct focus_state *state, *next; |
| 770 | struct workspace *ws = container_of(listener, |
| 771 | struct workspace, |
| 772 | seat_destroyed_listener); |
| 773 | |
| 774 | wl_list_for_each_safe(state, next, &ws->focus_list, link) |
| 775 | if (state->seat == seat) |
| 776 | wl_list_remove(&state->link); |
| 777 | } |
| 778 | |
Jonas Ådahl | e3cddce | 2012-06-13 00:01:22 +0200 | [diff] [blame] | 779 | static struct workspace * |
| 780 | workspace_create(void) |
| 781 | { |
| 782 | struct workspace *ws = malloc(sizeof *ws); |
| 783 | if (ws == NULL) |
| 784 | return NULL; |
| 785 | |
| 786 | weston_layer_init(&ws->layer, NULL); |
| 787 | |
Jonas Ådahl | 0476974 | 2012-06-13 00:01:24 +0200 | [diff] [blame] | 788 | wl_list_init(&ws->focus_list); |
| 789 | wl_list_init(&ws->seat_destroyed_listener.link); |
| 790 | ws->seat_destroyed_listener.notify = seat_destroyed; |
Louis-Francis Ratté-Boulianne | b482dbd | 2013-11-19 11:37:11 +0100 | [diff] [blame] | 791 | ws->fsurf_front = NULL; |
| 792 | ws->fsurf_back = NULL; |
| 793 | ws->focus_animation = NULL; |
Jonas Ådahl | 0476974 | 2012-06-13 00:01:24 +0200 | [diff] [blame] | 794 | |
Jonas Ådahl | e3cddce | 2012-06-13 00:01:22 +0200 | [diff] [blame] | 795 | return ws; |
| 796 | } |
| 797 | |
Jonas Ådahl | 62fcd04 | 2012-06-13 00:01:23 +0200 | [diff] [blame] | 798 | static int |
| 799 | workspace_is_empty(struct workspace *ws) |
| 800 | { |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 801 | return wl_list_empty(&ws->layer.view_list); |
Jonas Ådahl | 62fcd04 | 2012-06-13 00:01:23 +0200 | [diff] [blame] | 802 | } |
| 803 | |
Jonas Ådahl | e3cddce | 2012-06-13 00:01:22 +0200 | [diff] [blame] | 804 | static struct workspace * |
| 805 | get_workspace(struct desktop_shell *shell, unsigned int index) |
| 806 | { |
| 807 | struct workspace **pws = shell->workspaces.array.data; |
Philipp Brüschweiler | 067abf6 | 2012-09-01 16:03:05 +0200 | [diff] [blame] | 808 | assert(index < shell->workspaces.num); |
Jonas Ådahl | e3cddce | 2012-06-13 00:01:22 +0200 | [diff] [blame] | 809 | pws += index; |
| 810 | return *pws; |
| 811 | } |
| 812 | |
Kristian Høgsberg | 1ef2313 | 2013-12-04 00:20:01 -0800 | [diff] [blame] | 813 | struct workspace * |
Jonas Ådahl | e3cddce | 2012-06-13 00:01:22 +0200 | [diff] [blame] | 814 | get_current_workspace(struct desktop_shell *shell) |
| 815 | { |
| 816 | return get_workspace(shell, shell->workspaces.current); |
| 817 | } |
| 818 | |
| 819 | static void |
| 820 | activate_workspace(struct desktop_shell *shell, unsigned int index) |
| 821 | { |
| 822 | struct workspace *ws; |
| 823 | |
| 824 | ws = get_workspace(shell, index); |
| 825 | wl_list_insert(&shell->panel_layer.link, &ws->layer.link); |
| 826 | |
| 827 | shell->workspaces.current = index; |
| 828 | } |
| 829 | |
Jonas Ådahl | 62fcd04 | 2012-06-13 00:01:23 +0200 | [diff] [blame] | 830 | static unsigned int |
| 831 | get_output_height(struct weston_output *output) |
| 832 | { |
| 833 | return abs(output->region.extents.y1 - output->region.extents.y2); |
| 834 | } |
| 835 | |
| 836 | static void |
Louis-Francis Ratté-Boulianne | b482dbd | 2013-11-19 11:37:11 +0100 | [diff] [blame] | 837 | view_translate(struct workspace *ws, struct weston_view *view, double d) |
Jonas Ådahl | 62fcd04 | 2012-06-13 00:01:23 +0200 | [diff] [blame] | 838 | { |
Jonas Ådahl | 62fcd04 | 2012-06-13 00:01:23 +0200 | [diff] [blame] | 839 | struct weston_transform *transform; |
| 840 | |
Louis-Francis Ratté-Boulianne | b482dbd | 2013-11-19 11:37:11 +0100 | [diff] [blame] | 841 | if (is_focus_view(view)) { |
| 842 | struct focus_surface *fsurf = get_focus_surface(view->surface); |
| 843 | transform = &fsurf->workspace_transform; |
| 844 | } else { |
| 845 | struct shell_surface *shsurf = get_shell_surface(view->surface); |
| 846 | transform = &shsurf->workspace_transform; |
| 847 | } |
| 848 | |
Jonas Ådahl | 62fcd04 | 2012-06-13 00:01:23 +0200 | [diff] [blame] | 849 | if (wl_list_empty(&transform->link)) |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 850 | wl_list_insert(view->geometry.transformation_list.prev, |
Louis-Francis Ratté-Boulianne | b482dbd | 2013-11-19 11:37:11 +0100 | [diff] [blame] | 851 | &transform->link); |
Jonas Ådahl | 62fcd04 | 2012-06-13 00:01:23 +0200 | [diff] [blame] | 852 | |
Louis-Francis Ratté-Boulianne | b482dbd | 2013-11-19 11:37:11 +0100 | [diff] [blame] | 853 | weston_matrix_init(&transform->matrix); |
| 854 | weston_matrix_translate(&transform->matrix, |
Jonas Ådahl | 62fcd04 | 2012-06-13 00:01:23 +0200 | [diff] [blame] | 855 | 0.0, d, 0.0); |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 856 | weston_view_geometry_dirty(view); |
Jonas Ådahl | 62fcd04 | 2012-06-13 00:01:23 +0200 | [diff] [blame] | 857 | } |
| 858 | |
| 859 | static void |
| 860 | workspace_translate_out(struct workspace *ws, double fraction) |
| 861 | { |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 862 | struct weston_view *view; |
Jonas Ådahl | 62fcd04 | 2012-06-13 00:01:23 +0200 | [diff] [blame] | 863 | unsigned int height; |
| 864 | double d; |
| 865 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 866 | wl_list_for_each(view, &ws->layer.view_list, layer_link) { |
| 867 | height = get_output_height(view->surface->output); |
Jonas Ådahl | 62fcd04 | 2012-06-13 00:01:23 +0200 | [diff] [blame] | 868 | d = height * fraction; |
| 869 | |
Louis-Francis Ratté-Boulianne | b482dbd | 2013-11-19 11:37:11 +0100 | [diff] [blame] | 870 | view_translate(ws, view, d); |
Jonas Ådahl | 62fcd04 | 2012-06-13 00:01:23 +0200 | [diff] [blame] | 871 | } |
| 872 | } |
| 873 | |
| 874 | static void |
| 875 | workspace_translate_in(struct workspace *ws, double fraction) |
| 876 | { |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 877 | struct weston_view *view; |
Jonas Ådahl | 62fcd04 | 2012-06-13 00:01:23 +0200 | [diff] [blame] | 878 | unsigned int height; |
| 879 | double d; |
| 880 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 881 | wl_list_for_each(view, &ws->layer.view_list, layer_link) { |
| 882 | height = get_output_height(view->surface->output); |
Jonas Ådahl | 62fcd04 | 2012-06-13 00:01:23 +0200 | [diff] [blame] | 883 | |
| 884 | if (fraction > 0) |
| 885 | d = -(height - height * fraction); |
| 886 | else |
| 887 | d = height + height * fraction; |
| 888 | |
Louis-Francis Ratté-Boulianne | b482dbd | 2013-11-19 11:37:11 +0100 | [diff] [blame] | 889 | view_translate(ws, view, d); |
Jonas Ådahl | 62fcd04 | 2012-06-13 00:01:23 +0200 | [diff] [blame] | 890 | } |
| 891 | } |
| 892 | |
| 893 | static void |
Jonas Ådahl | e9d2250 | 2012-08-29 22:13:01 +0200 | [diff] [blame] | 894 | broadcast_current_workspace_state(struct desktop_shell *shell) |
| 895 | { |
Kristian Høgsberg | 2e3c396 | 2013-09-11 12:00:47 -0700 | [diff] [blame] | 896 | struct wl_resource *resource; |
Jonas Ådahl | e9d2250 | 2012-08-29 22:13:01 +0200 | [diff] [blame] | 897 | |
Kristian Høgsberg | 2e3c396 | 2013-09-11 12:00:47 -0700 | [diff] [blame] | 898 | wl_resource_for_each(resource, &shell->workspaces.client_list) |
| 899 | workspace_manager_send_state(resource, |
Jonas Ådahl | e9d2250 | 2012-08-29 22:13:01 +0200 | [diff] [blame] | 900 | shell->workspaces.current, |
| 901 | shell->workspaces.num); |
| 902 | } |
| 903 | |
| 904 | static void |
Jonas Ådahl | 62fcd04 | 2012-06-13 00:01:23 +0200 | [diff] [blame] | 905 | reverse_workspace_change_animation(struct desktop_shell *shell, |
| 906 | unsigned int index, |
| 907 | struct workspace *from, |
| 908 | struct workspace *to) |
| 909 | { |
| 910 | shell->workspaces.current = index; |
| 911 | |
| 912 | shell->workspaces.anim_to = to; |
| 913 | shell->workspaces.anim_from = from; |
| 914 | shell->workspaces.anim_dir = -1 * shell->workspaces.anim_dir; |
| 915 | shell->workspaces.anim_timestamp = 0; |
| 916 | |
Scott Moreau | 4272e63 | 2012-08-13 09:58:41 -0600 | [diff] [blame] | 917 | weston_compositor_schedule_repaint(shell->compositor); |
Jonas Ådahl | 62fcd04 | 2012-06-13 00:01:23 +0200 | [diff] [blame] | 918 | } |
| 919 | |
| 920 | static void |
| 921 | workspace_deactivate_transforms(struct workspace *ws) |
| 922 | { |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 923 | struct weston_view *view; |
Louis-Francis Ratté-Boulianne | b482dbd | 2013-11-19 11:37:11 +0100 | [diff] [blame] | 924 | struct weston_transform *transform; |
Jonas Ådahl | 62fcd04 | 2012-06-13 00:01:23 +0200 | [diff] [blame] | 925 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 926 | 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] | 927 | if (is_focus_view(view)) { |
| 928 | struct focus_surface *fsurf = get_focus_surface(view->surface); |
| 929 | transform = &fsurf->workspace_transform; |
| 930 | } else { |
| 931 | struct shell_surface *shsurf = get_shell_surface(view->surface); |
| 932 | transform = &shsurf->workspace_transform; |
| 933 | } |
| 934 | |
| 935 | if (!wl_list_empty(&transform->link)) { |
| 936 | wl_list_remove(&transform->link); |
| 937 | wl_list_init(&transform->link); |
Jonas Ådahl | 8de6a1d | 2012-08-29 22:13:00 +0200 | [diff] [blame] | 938 | } |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 939 | weston_view_geometry_dirty(view); |
Jonas Ådahl | 62fcd04 | 2012-06-13 00:01:23 +0200 | [diff] [blame] | 940 | } |
| 941 | } |
| 942 | |
| 943 | static void |
| 944 | finish_workspace_change_animation(struct desktop_shell *shell, |
| 945 | struct workspace *from, |
| 946 | struct workspace *to) |
| 947 | { |
Scott Moreau | 4272e63 | 2012-08-13 09:58:41 -0600 | [diff] [blame] | 948 | weston_compositor_schedule_repaint(shell->compositor); |
Jonas Ådahl | 62fcd04 | 2012-06-13 00:01:23 +0200 | [diff] [blame] | 949 | |
| 950 | wl_list_remove(&shell->workspaces.animation.link); |
| 951 | workspace_deactivate_transforms(from); |
| 952 | workspace_deactivate_transforms(to); |
| 953 | shell->workspaces.anim_to = NULL; |
| 954 | |
| 955 | wl_list_remove(&shell->workspaces.anim_from->layer.link); |
| 956 | } |
| 957 | |
| 958 | static void |
| 959 | animate_workspace_change_frame(struct weston_animation *animation, |
| 960 | struct weston_output *output, uint32_t msecs) |
| 961 | { |
| 962 | struct desktop_shell *shell = |
| 963 | container_of(animation, struct desktop_shell, |
| 964 | workspaces.animation); |
| 965 | struct workspace *from = shell->workspaces.anim_from; |
| 966 | struct workspace *to = shell->workspaces.anim_to; |
| 967 | uint32_t t; |
| 968 | double x, y; |
| 969 | |
| 970 | if (workspace_is_empty(from) && workspace_is_empty(to)) { |
| 971 | finish_workspace_change_animation(shell, from, to); |
| 972 | return; |
| 973 | } |
| 974 | |
| 975 | if (shell->workspaces.anim_timestamp == 0) { |
| 976 | if (shell->workspaces.anim_current == 0.0) |
| 977 | shell->workspaces.anim_timestamp = msecs; |
| 978 | else |
| 979 | shell->workspaces.anim_timestamp = |
| 980 | msecs - |
| 981 | /* Invers of movement function 'y' below. */ |
| 982 | (asin(1.0 - shell->workspaces.anim_current) * |
| 983 | DEFAULT_WORKSPACE_CHANGE_ANIMATION_LENGTH * |
| 984 | M_2_PI); |
| 985 | } |
| 986 | |
| 987 | t = msecs - shell->workspaces.anim_timestamp; |
| 988 | |
| 989 | /* |
| 990 | * x = [0, π/2] |
| 991 | * y(x) = sin(x) |
| 992 | */ |
| 993 | x = t * (1.0/DEFAULT_WORKSPACE_CHANGE_ANIMATION_LENGTH) * M_PI_2; |
| 994 | y = sin(x); |
| 995 | |
| 996 | if (t < DEFAULT_WORKSPACE_CHANGE_ANIMATION_LENGTH) { |
Scott Moreau | 4272e63 | 2012-08-13 09:58:41 -0600 | [diff] [blame] | 997 | weston_compositor_schedule_repaint(shell->compositor); |
Jonas Ådahl | 62fcd04 | 2012-06-13 00:01:23 +0200 | [diff] [blame] | 998 | |
| 999 | workspace_translate_out(from, shell->workspaces.anim_dir * y); |
| 1000 | workspace_translate_in(to, shell->workspaces.anim_dir * y); |
| 1001 | shell->workspaces.anim_current = y; |
| 1002 | |
Scott Moreau | 4272e63 | 2012-08-13 09:58:41 -0600 | [diff] [blame] | 1003 | weston_compositor_schedule_repaint(shell->compositor); |
Jonas Ådahl | 62fcd04 | 2012-06-13 00:01:23 +0200 | [diff] [blame] | 1004 | } |
Jonas Ådahl | 0476974 | 2012-06-13 00:01:24 +0200 | [diff] [blame] | 1005 | else |
Jonas Ådahl | 62fcd04 | 2012-06-13 00:01:23 +0200 | [diff] [blame] | 1006 | finish_workspace_change_animation(shell, from, to); |
Jonas Ådahl | 62fcd04 | 2012-06-13 00:01:23 +0200 | [diff] [blame] | 1007 | } |
| 1008 | |
| 1009 | static void |
| 1010 | animate_workspace_change(struct desktop_shell *shell, |
| 1011 | unsigned int index, |
| 1012 | struct workspace *from, |
| 1013 | struct workspace *to) |
| 1014 | { |
| 1015 | struct weston_output *output; |
| 1016 | |
| 1017 | int dir; |
| 1018 | |
| 1019 | if (index > shell->workspaces.current) |
| 1020 | dir = -1; |
| 1021 | else |
| 1022 | dir = 1; |
| 1023 | |
| 1024 | shell->workspaces.current = index; |
| 1025 | |
| 1026 | shell->workspaces.anim_dir = dir; |
| 1027 | shell->workspaces.anim_from = from; |
| 1028 | shell->workspaces.anim_to = to; |
| 1029 | shell->workspaces.anim_current = 0.0; |
| 1030 | shell->workspaces.anim_timestamp = 0; |
| 1031 | |
| 1032 | output = container_of(shell->compositor->output_list.next, |
| 1033 | struct weston_output, link); |
| 1034 | wl_list_insert(&output->animation_list, |
| 1035 | &shell->workspaces.animation.link); |
| 1036 | |
Jonas Ådahl | 8de6a1d | 2012-08-29 22:13:00 +0200 | [diff] [blame] | 1037 | wl_list_insert(from->layer.link.prev, &to->layer.link); |
Jonas Ådahl | 62fcd04 | 2012-06-13 00:01:23 +0200 | [diff] [blame] | 1038 | |
| 1039 | workspace_translate_in(to, 0); |
| 1040 | |
Kristian Høgsberg | 2f5faff | 2012-07-31 16:36:34 -0400 | [diff] [blame] | 1041 | restore_focus_state(shell, to); |
Jonas Ådahl | 0476974 | 2012-06-13 00:01:24 +0200 | [diff] [blame] | 1042 | |
Scott Moreau | 4272e63 | 2012-08-13 09:58:41 -0600 | [diff] [blame] | 1043 | weston_compositor_schedule_repaint(shell->compositor); |
Jonas Ådahl | 62fcd04 | 2012-06-13 00:01:23 +0200 | [diff] [blame] | 1044 | } |
| 1045 | |
Jonas Ådahl | e3cddce | 2012-06-13 00:01:22 +0200 | [diff] [blame] | 1046 | static void |
Jonas Ådahl | 8de6a1d | 2012-08-29 22:13:00 +0200 | [diff] [blame] | 1047 | update_workspace(struct desktop_shell *shell, unsigned int index, |
| 1048 | struct workspace *from, struct workspace *to) |
| 1049 | { |
| 1050 | shell->workspaces.current = index; |
| 1051 | wl_list_insert(&from->layer.link, &to->layer.link); |
| 1052 | wl_list_remove(&from->layer.link); |
| 1053 | } |
| 1054 | |
| 1055 | static void |
Jonas Ådahl | e3cddce | 2012-06-13 00:01:22 +0200 | [diff] [blame] | 1056 | change_workspace(struct desktop_shell *shell, unsigned int index) |
| 1057 | { |
| 1058 | struct workspace *from; |
| 1059 | struct workspace *to; |
Louis-Francis Ratté-Boulianne | b482dbd | 2013-11-19 11:37:11 +0100 | [diff] [blame] | 1060 | struct focus_state *state; |
Jonas Ådahl | e3cddce | 2012-06-13 00:01:22 +0200 | [diff] [blame] | 1061 | |
| 1062 | if (index == shell->workspaces.current) |
| 1063 | return; |
| 1064 | |
| 1065 | /* Don't change workspace when there is any fullscreen surfaces. */ |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 1066 | if (!wl_list_empty(&shell->fullscreen_layer.view_list)) |
Jonas Ådahl | e3cddce | 2012-06-13 00:01:22 +0200 | [diff] [blame] | 1067 | return; |
| 1068 | |
Jonas Ådahl | e3cddce | 2012-06-13 00:01:22 +0200 | [diff] [blame] | 1069 | from = get_current_workspace(shell); |
| 1070 | to = get_workspace(shell, index); |
| 1071 | |
Jonas Ådahl | 62fcd04 | 2012-06-13 00:01:23 +0200 | [diff] [blame] | 1072 | if (shell->workspaces.anim_from == to && |
| 1073 | shell->workspaces.anim_to == from) { |
Jonas Ådahl | 8de6a1d | 2012-08-29 22:13:00 +0200 | [diff] [blame] | 1074 | restore_focus_state(shell, to); |
Jonas Ådahl | 62fcd04 | 2012-06-13 00:01:23 +0200 | [diff] [blame] | 1075 | reverse_workspace_change_animation(shell, index, from, to); |
Jonas Ådahl | e9d2250 | 2012-08-29 22:13:01 +0200 | [diff] [blame] | 1076 | broadcast_current_workspace_state(shell); |
Jonas Ådahl | 62fcd04 | 2012-06-13 00:01:23 +0200 | [diff] [blame] | 1077 | return; |
| 1078 | } |
Jonas Ådahl | e3cddce | 2012-06-13 00:01:22 +0200 | [diff] [blame] | 1079 | |
Jonas Ådahl | 62fcd04 | 2012-06-13 00:01:23 +0200 | [diff] [blame] | 1080 | if (shell->workspaces.anim_to != NULL) |
| 1081 | finish_workspace_change_animation(shell, |
| 1082 | shell->workspaces.anim_from, |
| 1083 | shell->workspaces.anim_to); |
| 1084 | |
Jonas Ådahl | 8de6a1d | 2012-08-29 22:13:00 +0200 | [diff] [blame] | 1085 | restore_focus_state(shell, to); |
Jonas Ådahl | 0476974 | 2012-06-13 00:01:24 +0200 | [diff] [blame] | 1086 | |
Louis-Francis Ratté-Boulianne | b482dbd | 2013-11-19 11:37:11 +0100 | [diff] [blame] | 1087 | if (shell->focus_animation_type != ANIMATION_NONE) { |
| 1088 | wl_list_for_each(state, &from->focus_list, link) |
| 1089 | if (state->keyboard_focus) |
| 1090 | animate_focus_change(shell, from, |
| 1091 | get_default_view(state->keyboard_focus), NULL); |
| 1092 | |
| 1093 | wl_list_for_each(state, &to->focus_list, link) |
| 1094 | if (state->keyboard_focus) |
| 1095 | animate_focus_change(shell, to, |
| 1096 | NULL, get_default_view(state->keyboard_focus)); |
| 1097 | } |
| 1098 | |
Jonas Ådahl | 8de6a1d | 2012-08-29 22:13:00 +0200 | [diff] [blame] | 1099 | if (workspace_is_empty(to) && workspace_is_empty(from)) |
| 1100 | update_workspace(shell, index, from, to); |
Jonas Ådahl | 62fcd04 | 2012-06-13 00:01:23 +0200 | [diff] [blame] | 1101 | else |
| 1102 | animate_workspace_change(shell, index, from, to); |
Jonas Ådahl | e9d2250 | 2012-08-29 22:13:01 +0200 | [diff] [blame] | 1103 | |
| 1104 | broadcast_current_workspace_state(shell); |
Pekka Paalanen | e955f1e | 2011-12-07 11:49:52 +0200 | [diff] [blame] | 1105 | } |
| 1106 | |
Jonas Ådahl | 8de6a1d | 2012-08-29 22:13:00 +0200 | [diff] [blame] | 1107 | static bool |
| 1108 | workspace_has_only(struct workspace *ws, struct weston_surface *surface) |
| 1109 | { |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 1110 | struct wl_list *list = &ws->layer.view_list; |
Jonas Ådahl | 8de6a1d | 2012-08-29 22:13:00 +0200 | [diff] [blame] | 1111 | struct wl_list *e; |
| 1112 | |
| 1113 | if (wl_list_empty(list)) |
| 1114 | return false; |
| 1115 | |
| 1116 | e = list->next; |
| 1117 | |
| 1118 | if (e->next != list) |
| 1119 | return false; |
| 1120 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 1121 | return container_of(e, struct weston_view, layer_link)->surface == surface; |
Jonas Ådahl | 8de6a1d | 2012-08-29 22:13:00 +0200 | [diff] [blame] | 1122 | } |
| 1123 | |
| 1124 | static void |
Philip Withnall | 659163d | 2013-11-25 18:01:36 +0000 | [diff] [blame] | 1125 | move_surface_to_workspace(struct desktop_shell *shell, |
| 1126 | struct shell_surface *shsurf, |
| 1127 | uint32_t workspace) |
Jonas Ådahl | e9d2250 | 2012-08-29 22:13:01 +0200 | [diff] [blame] | 1128 | { |
| 1129 | struct workspace *from; |
| 1130 | struct workspace *to; |
| 1131 | struct weston_seat *seat; |
Pekka Paalanen | 01388e2 | 2013-04-25 13:57:44 +0300 | [diff] [blame] | 1132 | struct weston_surface *focus; |
Philip Withnall | 659163d | 2013-11-25 18:01:36 +0000 | [diff] [blame] | 1133 | struct weston_view *view; |
Jonas Ådahl | e9d2250 | 2012-08-29 22:13:01 +0200 | [diff] [blame] | 1134 | |
| 1135 | if (workspace == shell->workspaces.current) |
| 1136 | return; |
| 1137 | |
Philip Withnall | 659163d | 2013-11-25 18:01:36 +0000 | [diff] [blame] | 1138 | view = get_default_view(shsurf->surface); |
| 1139 | if (!view) |
| 1140 | return; |
| 1141 | |
| 1142 | assert(weston_surface_get_main_surface(view->surface) == view->surface); |
| 1143 | |
Philipp Brüschweiler | 067abf6 | 2012-09-01 16:03:05 +0200 | [diff] [blame] | 1144 | if (workspace >= shell->workspaces.num) |
| 1145 | workspace = shell->workspaces.num - 1; |
| 1146 | |
Jonas Ådahl | e9d2250 | 2012-08-29 22:13:01 +0200 | [diff] [blame] | 1147 | from = get_current_workspace(shell); |
| 1148 | to = get_workspace(shell, workspace); |
| 1149 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 1150 | wl_list_remove(&view->layer_link); |
| 1151 | wl_list_insert(&to->layer.view_list, &view->layer_link); |
Jonas Ådahl | e9d2250 | 2012-08-29 22:13:01 +0200 | [diff] [blame] | 1152 | |
Philip Withnall | 648a4dd | 2013-11-25 18:01:44 +0000 | [diff] [blame] | 1153 | shell_surface_update_child_surface_layers(shsurf); |
| 1154 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 1155 | drop_focus_state(shell, from, view->surface); |
Pekka Paalanen | 01388e2 | 2013-04-25 13:57:44 +0300 | [diff] [blame] | 1156 | wl_list_for_each(seat, &shell->compositor->seat_list, link) { |
| 1157 | if (!seat->keyboard) |
| 1158 | continue; |
| 1159 | |
| 1160 | focus = weston_surface_get_main_surface(seat->keyboard->focus); |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 1161 | if (focus == view->surface) |
Kristian Høgsberg | e314875 | 2013-05-06 23:19:49 -0400 | [diff] [blame] | 1162 | weston_keyboard_set_focus(seat->keyboard, NULL); |
Pekka Paalanen | 01388e2 | 2013-04-25 13:57:44 +0300 | [diff] [blame] | 1163 | } |
Jonas Ådahl | e9d2250 | 2012-08-29 22:13:01 +0200 | [diff] [blame] | 1164 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 1165 | weston_view_damage_below(view); |
Jonas Ådahl | e9d2250 | 2012-08-29 22:13:01 +0200 | [diff] [blame] | 1166 | } |
| 1167 | |
| 1168 | static void |
Jonas Ådahl | 8de6a1d | 2012-08-29 22:13:00 +0200 | [diff] [blame] | 1169 | take_surface_to_workspace_by_seat(struct desktop_shell *shell, |
Kristian Høgsberg | e314875 | 2013-05-06 23:19:49 -0400 | [diff] [blame] | 1170 | struct weston_seat *seat, |
Jonas Ådahl | 8de6a1d | 2012-08-29 22:13:00 +0200 | [diff] [blame] | 1171 | unsigned int index) |
| 1172 | { |
Pekka Paalanen | 01388e2 | 2013-04-25 13:57:44 +0300 | [diff] [blame] | 1173 | struct weston_surface *surface; |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 1174 | struct weston_view *view; |
Jonas Ådahl | 8de6a1d | 2012-08-29 22:13:00 +0200 | [diff] [blame] | 1175 | struct shell_surface *shsurf; |
| 1176 | struct workspace *from; |
| 1177 | struct workspace *to; |
Jonas Ådahl | 8538b22 | 2012-08-29 22:13:03 +0200 | [diff] [blame] | 1178 | struct focus_state *state; |
Jonas Ådahl | 8de6a1d | 2012-08-29 22:13:00 +0200 | [diff] [blame] | 1179 | |
Pekka Paalanen | 01388e2 | 2013-04-25 13:57:44 +0300 | [diff] [blame] | 1180 | surface = weston_surface_get_main_surface(seat->keyboard->focus); |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 1181 | view = get_default_view(surface); |
| 1182 | if (view == NULL || |
Louis-Francis Ratté-Boulianne | b482dbd | 2013-11-19 11:37:11 +0100 | [diff] [blame] | 1183 | index == shell->workspaces.current || |
| 1184 | is_focus_view(view)) |
Jonas Ådahl | 8de6a1d | 2012-08-29 22:13:00 +0200 | [diff] [blame] | 1185 | return; |
| 1186 | |
| 1187 | from = get_current_workspace(shell); |
| 1188 | to = get_workspace(shell, index); |
| 1189 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 1190 | wl_list_remove(&view->layer_link); |
| 1191 | wl_list_insert(&to->layer.view_list, &view->layer_link); |
Jonas Ådahl | 8de6a1d | 2012-08-29 22:13:00 +0200 | [diff] [blame] | 1192 | |
Philip Withnall | 659163d | 2013-11-25 18:01:36 +0000 | [diff] [blame] | 1193 | shsurf = get_shell_surface(surface); |
Philip Withnall | 648a4dd | 2013-11-25 18:01:44 +0000 | [diff] [blame] | 1194 | if (shsurf != NULL) |
| 1195 | shell_surface_update_child_surface_layers(shsurf); |
Philip Withnall | 659163d | 2013-11-25 18:01:36 +0000 | [diff] [blame] | 1196 | |
Jonas Ådahl | e9d2250 | 2012-08-29 22:13:01 +0200 | [diff] [blame] | 1197 | replace_focus_state(shell, to, seat); |
Jonas Ådahl | 8de6a1d | 2012-08-29 22:13:00 +0200 | [diff] [blame] | 1198 | drop_focus_state(shell, from, surface); |
| 1199 | |
| 1200 | if (shell->workspaces.anim_from == to && |
| 1201 | shell->workspaces.anim_to == from) { |
Jonas Ådahl | e9d2250 | 2012-08-29 22:13:01 +0200 | [diff] [blame] | 1202 | wl_list_remove(&to->layer.link); |
| 1203 | wl_list_insert(from->layer.link.prev, &to->layer.link); |
| 1204 | |
Jonas Ådahl | 8de6a1d | 2012-08-29 22:13:00 +0200 | [diff] [blame] | 1205 | reverse_workspace_change_animation(shell, index, from, to); |
Jonas Ådahl | e9d2250 | 2012-08-29 22:13:01 +0200 | [diff] [blame] | 1206 | broadcast_current_workspace_state(shell); |
| 1207 | |
Jonas Ådahl | 8de6a1d | 2012-08-29 22:13:00 +0200 | [diff] [blame] | 1208 | return; |
| 1209 | } |
| 1210 | |
| 1211 | if (shell->workspaces.anim_to != NULL) |
| 1212 | finish_workspace_change_animation(shell, |
| 1213 | shell->workspaces.anim_from, |
| 1214 | shell->workspaces.anim_to); |
| 1215 | |
| 1216 | if (workspace_is_empty(from) && |
| 1217 | workspace_has_only(to, surface)) |
| 1218 | update_workspace(shell, index, from, to); |
| 1219 | else { |
Philip Withnall | 2c3849b | 2013-11-25 18:01:45 +0000 | [diff] [blame] | 1220 | if (shsurf != NULL && |
| 1221 | wl_list_empty(&shsurf->workspace_transform.link)) |
Jonas Ådahl | 8de6a1d | 2012-08-29 22:13:00 +0200 | [diff] [blame] | 1222 | wl_list_insert(&shell->workspaces.anim_sticky_list, |
| 1223 | &shsurf->workspace_transform.link); |
| 1224 | |
| 1225 | animate_workspace_change(shell, index, from, to); |
| 1226 | } |
Jonas Ådahl | e9d2250 | 2012-08-29 22:13:01 +0200 | [diff] [blame] | 1227 | |
| 1228 | broadcast_current_workspace_state(shell); |
Jonas Ådahl | 8538b22 | 2012-08-29 22:13:03 +0200 | [diff] [blame] | 1229 | |
| 1230 | state = ensure_focus_state(shell, seat); |
| 1231 | if (state != NULL) |
| 1232 | state->keyboard_focus = surface; |
Jonas Ådahl | e9d2250 | 2012-08-29 22:13:01 +0200 | [diff] [blame] | 1233 | } |
| 1234 | |
| 1235 | static void |
| 1236 | workspace_manager_move_surface(struct wl_client *client, |
| 1237 | struct wl_resource *resource, |
| 1238 | struct wl_resource *surface_resource, |
| 1239 | uint32_t workspace) |
| 1240 | { |
Jason Ekstrand | 651f00e | 2013-06-14 10:07:54 -0500 | [diff] [blame] | 1241 | struct desktop_shell *shell = wl_resource_get_user_data(resource); |
Jonas Ådahl | e9d2250 | 2012-08-29 22:13:01 +0200 | [diff] [blame] | 1242 | struct weston_surface *surface = |
Jason Ekstrand | 0f2ef7e | 2013-06-14 10:07:53 -0500 | [diff] [blame] | 1243 | wl_resource_get_user_data(surface_resource); |
Pekka Paalanen | 01388e2 | 2013-04-25 13:57:44 +0300 | [diff] [blame] | 1244 | struct weston_surface *main_surface; |
Philip Withnall | 659163d | 2013-11-25 18:01:36 +0000 | [diff] [blame] | 1245 | struct shell_surface *shell_surface; |
Jonas Ådahl | e9d2250 | 2012-08-29 22:13:01 +0200 | [diff] [blame] | 1246 | |
Pekka Paalanen | 01388e2 | 2013-04-25 13:57:44 +0300 | [diff] [blame] | 1247 | main_surface = weston_surface_get_main_surface(surface); |
Philip Withnall | 659163d | 2013-11-25 18:01:36 +0000 | [diff] [blame] | 1248 | shell_surface = get_shell_surface(main_surface); |
| 1249 | if (shell_surface == NULL) |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 1250 | return; |
Philip Withnall | 659163d | 2013-11-25 18:01:36 +0000 | [diff] [blame] | 1251 | |
| 1252 | move_surface_to_workspace(shell, shell_surface, workspace); |
Jonas Ådahl | e9d2250 | 2012-08-29 22:13:01 +0200 | [diff] [blame] | 1253 | } |
| 1254 | |
| 1255 | static const struct workspace_manager_interface workspace_manager_implementation = { |
| 1256 | workspace_manager_move_surface, |
| 1257 | }; |
| 1258 | |
| 1259 | static void |
| 1260 | unbind_resource(struct wl_resource *resource) |
| 1261 | { |
Jason Ekstrand | 651f00e | 2013-06-14 10:07:54 -0500 | [diff] [blame] | 1262 | wl_list_remove(wl_resource_get_link(resource)); |
Jonas Ådahl | e9d2250 | 2012-08-29 22:13:01 +0200 | [diff] [blame] | 1263 | } |
| 1264 | |
| 1265 | static void |
| 1266 | bind_workspace_manager(struct wl_client *client, |
| 1267 | void *data, uint32_t version, uint32_t id) |
| 1268 | { |
| 1269 | struct desktop_shell *shell = data; |
| 1270 | struct wl_resource *resource; |
| 1271 | |
Jason Ekstrand | a85118c | 2013-06-27 20:17:02 -0500 | [diff] [blame] | 1272 | resource = wl_resource_create(client, |
| 1273 | &workspace_manager_interface, 1, id); |
Jonas Ådahl | e9d2250 | 2012-08-29 22:13:01 +0200 | [diff] [blame] | 1274 | |
| 1275 | if (resource == NULL) { |
| 1276 | weston_log("couldn't add workspace manager object"); |
| 1277 | return; |
| 1278 | } |
| 1279 | |
Jason Ekstrand | a85118c | 2013-06-27 20:17:02 -0500 | [diff] [blame] | 1280 | wl_resource_set_implementation(resource, |
| 1281 | &workspace_manager_implementation, |
| 1282 | shell, unbind_resource); |
Jason Ekstrand | 651f00e | 2013-06-14 10:07:54 -0500 | [diff] [blame] | 1283 | wl_list_insert(&shell->workspaces.client_list, |
| 1284 | wl_resource_get_link(resource)); |
Jonas Ådahl | e9d2250 | 2012-08-29 22:13:01 +0200 | [diff] [blame] | 1285 | |
| 1286 | workspace_manager_send_state(resource, |
| 1287 | shell->workspaces.current, |
| 1288 | shell->workspaces.num); |
Jonas Ådahl | 8de6a1d | 2012-08-29 22:13:00 +0200 | [diff] [blame] | 1289 | } |
| 1290 | |
Pekka Paalanen | 56cdea9 | 2011-11-23 16:14:12 +0200 | [diff] [blame] | 1291 | static void |
Rusty Lynch | 1084da5 | 2013-08-15 09:10:08 -0700 | [diff] [blame] | 1292 | touch_move_grab_down(struct weston_touch_grab *grab, uint32_t time, |
| 1293 | int touch_id, wl_fixed_t sx, wl_fixed_t sy) |
| 1294 | { |
| 1295 | } |
| 1296 | |
| 1297 | static void |
| 1298 | touch_move_grab_up(struct weston_touch_grab *grab, uint32_t time, int touch_id) |
| 1299 | { |
Jonas Ådahl | 1c6e63e | 2013-10-25 23:18:04 +0200 | [diff] [blame] | 1300 | struct weston_touch_move_grab *move = |
| 1301 | (struct weston_touch_move_grab *) container_of( |
| 1302 | grab, struct shell_touch_grab, grab); |
Neil Roberts | e14aa4f | 2013-10-03 16:43:07 +0100 | [diff] [blame] | 1303 | |
Jonas Ådahl | 9484b69 | 2013-12-02 22:05:03 +0100 | [diff] [blame] | 1304 | if (grab->touch->num_tp == 0) { |
Jonas Ådahl | 1c6e63e | 2013-10-25 23:18:04 +0200 | [diff] [blame] | 1305 | shell_touch_grab_end(&move->base); |
| 1306 | free(move); |
| 1307 | } |
Rusty Lynch | 1084da5 | 2013-08-15 09:10:08 -0700 | [diff] [blame] | 1308 | } |
| 1309 | |
| 1310 | static void |
| 1311 | touch_move_grab_motion(struct weston_touch_grab *grab, uint32_t time, |
| 1312 | int touch_id, wl_fixed_t sx, wl_fixed_t sy) |
| 1313 | { |
| 1314 | struct weston_touch_move_grab *move = (struct weston_touch_move_grab *) grab; |
| 1315 | struct shell_surface *shsurf = move->base.shsurf; |
| 1316 | struct weston_surface *es; |
| 1317 | int dx = wl_fixed_to_int(grab->touch->grab_x + move->dx); |
| 1318 | int dy = wl_fixed_to_int(grab->touch->grab_y + move->dy); |
| 1319 | |
| 1320 | if (!shsurf) |
| 1321 | return; |
| 1322 | |
| 1323 | es = shsurf->surface; |
| 1324 | |
Jason Ekstrand | 918f2dd | 2013-12-02 21:01:53 -0600 | [diff] [blame] | 1325 | weston_view_set_position(shsurf->view, dx, dy); |
Rusty Lynch | 1084da5 | 2013-08-15 09:10:08 -0700 | [diff] [blame] | 1326 | |
| 1327 | weston_compositor_schedule_repaint(es->compositor); |
| 1328 | } |
| 1329 | |
Jonas Ådahl | 1ea343e | 2013-10-25 23:18:05 +0200 | [diff] [blame] | 1330 | static void |
| 1331 | touch_move_grab_cancel(struct weston_touch_grab *grab) |
| 1332 | { |
| 1333 | struct weston_touch_move_grab *move = |
| 1334 | (struct weston_touch_move_grab *) container_of( |
| 1335 | grab, struct shell_touch_grab, grab); |
| 1336 | |
| 1337 | shell_touch_grab_end(&move->base); |
| 1338 | free(move); |
| 1339 | } |
| 1340 | |
Rusty Lynch | 1084da5 | 2013-08-15 09:10:08 -0700 | [diff] [blame] | 1341 | static const struct weston_touch_grab_interface touch_move_grab_interface = { |
| 1342 | touch_move_grab_down, |
| 1343 | touch_move_grab_up, |
| 1344 | touch_move_grab_motion, |
Jonas Ådahl | 1ea343e | 2013-10-25 23:18:05 +0200 | [diff] [blame] | 1345 | touch_move_grab_cancel, |
Rusty Lynch | 1084da5 | 2013-08-15 09:10:08 -0700 | [diff] [blame] | 1346 | }; |
| 1347 | |
| 1348 | static int |
| 1349 | surface_touch_move(struct shell_surface *shsurf, struct weston_seat *seat) |
| 1350 | { |
| 1351 | struct weston_touch_move_grab *move; |
| 1352 | |
| 1353 | if (!shsurf) |
| 1354 | return -1; |
| 1355 | |
Rafael Antognolli | 03b1659 | 2013-12-03 15:35:42 -0200 | [diff] [blame] | 1356 | if (shsurf->state.fullscreen) |
Rusty Lynch | 1084da5 | 2013-08-15 09:10:08 -0700 | [diff] [blame] | 1357 | return 0; |
Kristian Høgsberg | c85f1d4 | 2013-10-24 16:52:00 -0700 | [diff] [blame] | 1358 | if (shsurf->grabbed) |
| 1359 | return 0; |
Rusty Lynch | 1084da5 | 2013-08-15 09:10:08 -0700 | [diff] [blame] | 1360 | |
| 1361 | move = malloc(sizeof *move); |
| 1362 | if (!move) |
| 1363 | return -1; |
| 1364 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 1365 | move->dx = wl_fixed_from_double(shsurf->view->geometry.x) - |
Rusty Lynch | 1084da5 | 2013-08-15 09:10:08 -0700 | [diff] [blame] | 1366 | seat->touch->grab_x; |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 1367 | move->dy = wl_fixed_from_double(shsurf->view->geometry.y) - |
Rusty Lynch | 1084da5 | 2013-08-15 09:10:08 -0700 | [diff] [blame] | 1368 | seat->touch->grab_y; |
| 1369 | |
| 1370 | shell_touch_grab_start(&move->base, &touch_move_grab_interface, shsurf, |
| 1371 | seat->touch); |
| 1372 | |
| 1373 | return 0; |
| 1374 | } |
| 1375 | |
| 1376 | static void |
Kristian Høgsberg | 6848c25 | 2013-05-08 22:02:59 -0400 | [diff] [blame] | 1377 | noop_grab_focus(struct weston_pointer_grab *grab) |
Kristian Høgsberg | 9ddb826 | 2012-01-04 21:30:29 -0500 | [diff] [blame] | 1378 | { |
Kristian Høgsberg | 9ddb826 | 2012-01-04 21:30:29 -0500 | [diff] [blame] | 1379 | } |
| 1380 | |
| 1381 | static void |
Giulio Camuffo | 1959ab8 | 2013-11-14 23:42:52 +0100 | [diff] [blame] | 1382 | move_grab_motion(struct weston_pointer_grab *grab, uint32_t time, |
| 1383 | wl_fixed_t x, wl_fixed_t y) |
Kristian Høgsberg | 4cca349 | 2011-01-18 07:53:49 -0500 | [diff] [blame] | 1384 | { |
Kristian Høgsberg | 8334bc1 | 2012-01-03 10:29:47 -0500 | [diff] [blame] | 1385 | struct weston_move_grab *move = (struct weston_move_grab *) grab; |
Kristian Høgsberg | 02bbabb | 2013-05-06 22:15:05 -0400 | [diff] [blame] | 1386 | struct weston_pointer *pointer = grab->pointer; |
Ander Conselvan de Oliveira | fe0444a | 2012-04-04 17:48:05 +0300 | [diff] [blame] | 1387 | struct shell_surface *shsurf = move->base.shsurf; |
Giulio Camuffo | 1959ab8 | 2013-11-14 23:42:52 +0100 | [diff] [blame] | 1388 | int dx, dy; |
| 1389 | |
| 1390 | weston_pointer_move(pointer, x, y); |
| 1391 | dx = wl_fixed_to_int(pointer->x + move->dx); |
| 1392 | dy = wl_fixed_to_int(pointer->y + move->dy); |
Ander Conselvan de Oliveira | fe0444a | 2012-04-04 17:48:05 +0300 | [diff] [blame] | 1393 | |
| 1394 | if (!shsurf) |
| 1395 | return; |
| 1396 | |
Jason Ekstrand | 918f2dd | 2013-12-02 21:01:53 -0600 | [diff] [blame] | 1397 | weston_view_set_position(shsurf->view, dx, dy); |
Kristian Høgsberg | 4cca349 | 2011-01-18 07:53:49 -0500 | [diff] [blame] | 1398 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 1399 | weston_compositor_schedule_repaint(shsurf->surface->compositor); |
Kristian Høgsberg | 4cca349 | 2011-01-18 07:53:49 -0500 | [diff] [blame] | 1400 | } |
| 1401 | |
| 1402 | static void |
Kristian Høgsberg | 02bbabb | 2013-05-06 22:15:05 -0400 | [diff] [blame] | 1403 | move_grab_button(struct weston_pointer_grab *grab, |
Daniel Stone | 4dbadb1 | 2012-05-30 16:31:51 +0100 | [diff] [blame] | 1404 | uint32_t time, uint32_t button, uint32_t state_w) |
Kristian Høgsberg | 4cca349 | 2011-01-18 07:53:49 -0500 | [diff] [blame] | 1405 | { |
Ander Conselvan de Oliveira | fe0444a | 2012-04-04 17:48:05 +0300 | [diff] [blame] | 1406 | struct shell_grab *shell_grab = container_of(grab, struct shell_grab, |
| 1407 | grab); |
Kristian Høgsberg | 02bbabb | 2013-05-06 22:15:05 -0400 | [diff] [blame] | 1408 | struct weston_pointer *pointer = grab->pointer; |
Daniel Stone | 4dbadb1 | 2012-05-30 16:31:51 +0100 | [diff] [blame] | 1409 | enum wl_pointer_button_state state = state_w; |
Kristian Høgsberg | 4cca349 | 2011-01-18 07:53:49 -0500 | [diff] [blame] | 1410 | |
Daniel Stone | 4dbadb1 | 2012-05-30 16:31:51 +0100 | [diff] [blame] | 1411 | if (pointer->button_count == 0 && |
| 1412 | state == WL_POINTER_BUTTON_STATE_RELEASED) { |
Ander Conselvan de Oliveira | b9d2a0f | 2012-06-28 18:08:05 +0300 | [diff] [blame] | 1413 | shell_grab_end(shell_grab); |
Kristian Høgsberg | 9ddb826 | 2012-01-04 21:30:29 -0500 | [diff] [blame] | 1414 | free(grab); |
| 1415 | } |
Kristian Høgsberg | 4cca349 | 2011-01-18 07:53:49 -0500 | [diff] [blame] | 1416 | } |
| 1417 | |
Jonas Ådahl | 1ea343e | 2013-10-25 23:18:05 +0200 | [diff] [blame] | 1418 | static void |
| 1419 | move_grab_cancel(struct weston_pointer_grab *grab) |
| 1420 | { |
| 1421 | struct shell_grab *shell_grab = |
| 1422 | container_of(grab, struct shell_grab, grab); |
| 1423 | |
| 1424 | shell_grab_end(shell_grab); |
| 1425 | free(grab); |
| 1426 | } |
| 1427 | |
Kristian Høgsberg | 02bbabb | 2013-05-06 22:15:05 -0400 | [diff] [blame] | 1428 | static const struct weston_pointer_grab_interface move_grab_interface = { |
Kristian Høgsberg | 9ddb826 | 2012-01-04 21:30:29 -0500 | [diff] [blame] | 1429 | noop_grab_focus, |
Kristian Høgsberg | 4cca349 | 2011-01-18 07:53:49 -0500 | [diff] [blame] | 1430 | move_grab_motion, |
| 1431 | move_grab_button, |
Jonas Ådahl | 1ea343e | 2013-10-25 23:18:05 +0200 | [diff] [blame] | 1432 | move_grab_cancel, |
Kristian Høgsberg | 4cca349 | 2011-01-18 07:53:49 -0500 | [diff] [blame] | 1433 | }; |
| 1434 | |
Kristian Høgsberg | 9e31bff | 2012-08-01 00:08:07 -0400 | [diff] [blame] | 1435 | static int |
Kristian Høgsberg | e314875 | 2013-05-06 23:19:49 -0400 | [diff] [blame] | 1436 | surface_move(struct shell_surface *shsurf, struct weston_seat *seat) |
Kristian Høgsberg | 9e31bff | 2012-08-01 00:08:07 -0400 | [diff] [blame] | 1437 | { |
| 1438 | struct weston_move_grab *move; |
| 1439 | |
| 1440 | if (!shsurf) |
| 1441 | return -1; |
| 1442 | |
Kristian Høgsberg | c85f1d4 | 2013-10-24 16:52:00 -0700 | [diff] [blame] | 1443 | if (shsurf->grabbed) |
| 1444 | return 0; |
Rafael Antognolli | 03b1659 | 2013-12-03 15:35:42 -0200 | [diff] [blame] | 1445 | if (shsurf->state.fullscreen) |
Kristian Høgsberg | 9e31bff | 2012-08-01 00:08:07 -0400 | [diff] [blame] | 1446 | return 0; |
| 1447 | |
| 1448 | move = malloc(sizeof *move); |
| 1449 | if (!move) |
| 1450 | return -1; |
| 1451 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 1452 | move->dx = wl_fixed_from_double(shsurf->view->geometry.x) - |
Kristian Høgsberg | e314875 | 2013-05-06 23:19:49 -0400 | [diff] [blame] | 1453 | seat->pointer->grab_x; |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 1454 | move->dy = wl_fixed_from_double(shsurf->view->geometry.y) - |
Kristian Høgsberg | e314875 | 2013-05-06 23:19:49 -0400 | [diff] [blame] | 1455 | seat->pointer->grab_y; |
Kristian Høgsberg | 9e31bff | 2012-08-01 00:08:07 -0400 | [diff] [blame] | 1456 | |
| 1457 | shell_grab_start(&move->base, &move_grab_interface, shsurf, |
Kristian Høgsberg | e314875 | 2013-05-06 23:19:49 -0400 | [diff] [blame] | 1458 | seat->pointer, DESKTOP_SHELL_CURSOR_MOVE); |
Kristian Høgsberg | 9e31bff | 2012-08-01 00:08:07 -0400 | [diff] [blame] | 1459 | |
| 1460 | return 0; |
| 1461 | } |
| 1462 | |
| 1463 | static void |
Rafael Antognolli | e2a3455 | 2013-12-03 15:35:45 -0200 | [diff] [blame] | 1464 | common_surface_move(struct wl_resource *resource, |
| 1465 | struct wl_resource *seat_resource, uint32_t serial) |
Kristian Høgsberg | 9e31bff | 2012-08-01 00:08:07 -0400 | [diff] [blame] | 1466 | { |
Jason Ekstrand | 44a3863 | 2013-06-14 10:08:00 -0500 | [diff] [blame] | 1467 | struct weston_seat *seat = wl_resource_get_user_data(seat_resource); |
Jason Ekstrand | 651f00e | 2013-06-14 10:07:54 -0500 | [diff] [blame] | 1468 | struct shell_surface *shsurf = wl_resource_get_user_data(resource); |
Giulio Camuffo | 61da3fc | 2013-04-25 13:57:45 +0300 | [diff] [blame] | 1469 | struct weston_surface *surface; |
Kristian Høgsberg | 9e31bff | 2012-08-01 00:08:07 -0400 | [diff] [blame] | 1470 | |
Kristian Høgsberg | e1b655d | 2013-08-28 23:16:20 -0700 | [diff] [blame] | 1471 | if (seat->pointer && |
| 1472 | seat->pointer->button_count > 0 && |
| 1473 | seat->pointer->grab_serial == serial) { |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 1474 | surface = weston_surface_get_main_surface(seat->pointer->focus->surface); |
Rusty Lynch | 1084da5 | 2013-08-15 09:10:08 -0700 | [diff] [blame] | 1475 | if ((surface == shsurf->surface) && |
| 1476 | (surface_move(shsurf, seat) < 0)) |
| 1477 | wl_resource_post_no_memory(resource); |
Kristian Høgsberg | e1b655d | 2013-08-28 23:16:20 -0700 | [diff] [blame] | 1478 | } else if (seat->touch && |
| 1479 | seat->touch->grab_serial == serial) { |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 1480 | surface = weston_surface_get_main_surface(seat->touch->focus->surface); |
Rusty Lynch | 1084da5 | 2013-08-15 09:10:08 -0700 | [diff] [blame] | 1481 | if ((surface == shsurf->surface) && |
| 1482 | (surface_touch_move(shsurf, seat) < 0)) |
| 1483 | wl_resource_post_no_memory(resource); |
| 1484 | } |
Kristian Høgsberg | 9e31bff | 2012-08-01 00:08:07 -0400 | [diff] [blame] | 1485 | } |
| 1486 | |
Rafael Antognolli | e2a3455 | 2013-12-03 15:35:45 -0200 | [diff] [blame] | 1487 | static void |
| 1488 | shell_surface_move(struct wl_client *client, struct wl_resource *resource, |
| 1489 | struct wl_resource *seat_resource, uint32_t serial) |
| 1490 | { |
| 1491 | common_surface_move(resource, seat_resource, serial); |
| 1492 | } |
| 1493 | |
Kristian Høgsberg | 9e31bff | 2012-08-01 00:08:07 -0400 | [diff] [blame] | 1494 | struct weston_resize_grab { |
| 1495 | struct shell_grab base; |
| 1496 | uint32_t edges; |
| 1497 | int32_t width, height; |
| 1498 | }; |
| 1499 | |
| 1500 | static void |
Giulio Camuffo | 1959ab8 | 2013-11-14 23:42:52 +0100 | [diff] [blame] | 1501 | resize_grab_motion(struct weston_pointer_grab *grab, uint32_t time, |
| 1502 | wl_fixed_t x, wl_fixed_t y) |
Kristian Høgsberg | 9e31bff | 2012-08-01 00:08:07 -0400 | [diff] [blame] | 1503 | { |
| 1504 | struct weston_resize_grab *resize = (struct weston_resize_grab *) grab; |
Kristian Høgsberg | 02bbabb | 2013-05-06 22:15:05 -0400 | [diff] [blame] | 1505 | struct weston_pointer *pointer = grab->pointer; |
Kristian Høgsberg | 9e31bff | 2012-08-01 00:08:07 -0400 | [diff] [blame] | 1506 | struct shell_surface *shsurf = resize->base.shsurf; |
| 1507 | int32_t width, height; |
| 1508 | wl_fixed_t from_x, from_y; |
| 1509 | wl_fixed_t to_x, to_y; |
| 1510 | |
Giulio Camuffo | 1959ab8 | 2013-11-14 23:42:52 +0100 | [diff] [blame] | 1511 | weston_pointer_move(pointer, x, y); |
| 1512 | |
Kristian Høgsberg | 9e31bff | 2012-08-01 00:08:07 -0400 | [diff] [blame] | 1513 | if (!shsurf) |
| 1514 | return; |
| 1515 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 1516 | weston_view_from_global_fixed(shsurf->view, |
| 1517 | pointer->grab_x, pointer->grab_y, |
| 1518 | &from_x, &from_y); |
| 1519 | weston_view_from_global_fixed(shsurf->view, |
| 1520 | pointer->x, pointer->y, &to_x, &to_y); |
Kristian Høgsberg | 9e31bff | 2012-08-01 00:08:07 -0400 | [diff] [blame] | 1521 | |
| 1522 | width = resize->width; |
| 1523 | if (resize->edges & WL_SHELL_SURFACE_RESIZE_LEFT) { |
| 1524 | width += wl_fixed_to_int(from_x - to_x); |
| 1525 | } else if (resize->edges & WL_SHELL_SURFACE_RESIZE_RIGHT) { |
| 1526 | width += wl_fixed_to_int(to_x - from_x); |
| 1527 | } |
| 1528 | |
| 1529 | height = resize->height; |
| 1530 | if (resize->edges & WL_SHELL_SURFACE_RESIZE_TOP) { |
| 1531 | height += wl_fixed_to_int(from_y - to_y); |
| 1532 | } else if (resize->edges & WL_SHELL_SURFACE_RESIZE_BOTTOM) { |
| 1533 | height += wl_fixed_to_int(to_y - from_y); |
| 1534 | } |
| 1535 | |
| 1536 | shsurf->client->send_configure(shsurf->surface, |
| 1537 | resize->edges, width, height); |
| 1538 | } |
| 1539 | |
| 1540 | static void |
| 1541 | send_configure(struct weston_surface *surface, |
| 1542 | uint32_t edges, int32_t width, int32_t height) |
| 1543 | { |
| 1544 | struct shell_surface *shsurf = get_shell_surface(surface); |
| 1545 | |
Jason Ekstrand | 651f00e | 2013-06-14 10:07:54 -0500 | [diff] [blame] | 1546 | wl_shell_surface_send_configure(shsurf->resource, |
Kristian Høgsberg | 9e31bff | 2012-08-01 00:08:07 -0400 | [diff] [blame] | 1547 | edges, width, height); |
| 1548 | } |
| 1549 | |
| 1550 | static const struct weston_shell_client shell_client = { |
| 1551 | send_configure |
| 1552 | }; |
| 1553 | |
| 1554 | static void |
Kristian Høgsberg | 02bbabb | 2013-05-06 22:15:05 -0400 | [diff] [blame] | 1555 | resize_grab_button(struct weston_pointer_grab *grab, |
Kristian Høgsberg | 9e31bff | 2012-08-01 00:08:07 -0400 | [diff] [blame] | 1556 | uint32_t time, uint32_t button, uint32_t state_w) |
| 1557 | { |
| 1558 | struct weston_resize_grab *resize = (struct weston_resize_grab *) grab; |
Kristian Høgsberg | 02bbabb | 2013-05-06 22:15:05 -0400 | [diff] [blame] | 1559 | struct weston_pointer *pointer = grab->pointer; |
Kristian Høgsberg | 9e31bff | 2012-08-01 00:08:07 -0400 | [diff] [blame] | 1560 | enum wl_pointer_button_state state = state_w; |
| 1561 | |
| 1562 | if (pointer->button_count == 0 && |
| 1563 | state == WL_POINTER_BUTTON_STATE_RELEASED) { |
| 1564 | shell_grab_end(&resize->base); |
| 1565 | free(grab); |
| 1566 | } |
| 1567 | } |
| 1568 | |
Jonas Ådahl | 1ea343e | 2013-10-25 23:18:05 +0200 | [diff] [blame] | 1569 | static void |
| 1570 | resize_grab_cancel(struct weston_pointer_grab *grab) |
| 1571 | { |
| 1572 | struct weston_resize_grab *resize = (struct weston_resize_grab *) grab; |
| 1573 | |
| 1574 | shell_grab_end(&resize->base); |
| 1575 | free(grab); |
| 1576 | } |
| 1577 | |
Kristian Høgsberg | 02bbabb | 2013-05-06 22:15:05 -0400 | [diff] [blame] | 1578 | static const struct weston_pointer_grab_interface resize_grab_interface = { |
Kristian Høgsberg | 9e31bff | 2012-08-01 00:08:07 -0400 | [diff] [blame] | 1579 | noop_grab_focus, |
| 1580 | resize_grab_motion, |
| 1581 | resize_grab_button, |
Jonas Ådahl | 1ea343e | 2013-10-25 23:18:05 +0200 | [diff] [blame] | 1582 | resize_grab_cancel, |
Kristian Høgsberg | 9e31bff | 2012-08-01 00:08:07 -0400 | [diff] [blame] | 1583 | }; |
| 1584 | |
Giulio Camuffo | b836664 | 2013-04-25 13:57:46 +0300 | [diff] [blame] | 1585 | /* |
| 1586 | * Returns the bounding box of a surface and all its sub-surfaces, |
| 1587 | * in the surface coordinates system. */ |
| 1588 | static void |
| 1589 | surface_subsurfaces_boundingbox(struct weston_surface *surface, int32_t *x, |
| 1590 | int32_t *y, int32_t *w, int32_t *h) { |
| 1591 | pixman_region32_t region; |
| 1592 | pixman_box32_t *box; |
| 1593 | struct weston_subsurface *subsurface; |
| 1594 | |
| 1595 | pixman_region32_init_rect(®ion, 0, 0, |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 1596 | surface->width, |
| 1597 | surface->height); |
Giulio Camuffo | b836664 | 2013-04-25 13:57:46 +0300 | [diff] [blame] | 1598 | |
| 1599 | wl_list_for_each(subsurface, &surface->subsurface_list, parent_link) { |
| 1600 | pixman_region32_union_rect(®ion, ®ion, |
| 1601 | subsurface->position.x, |
| 1602 | subsurface->position.y, |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 1603 | subsurface->surface->width, |
| 1604 | subsurface->surface->height); |
Giulio Camuffo | b836664 | 2013-04-25 13:57:46 +0300 | [diff] [blame] | 1605 | } |
| 1606 | |
| 1607 | box = pixman_region32_extents(®ion); |
| 1608 | if (x) |
| 1609 | *x = box->x1; |
| 1610 | if (y) |
| 1611 | *y = box->y1; |
| 1612 | if (w) |
| 1613 | *w = box->x2 - box->x1; |
| 1614 | if (h) |
| 1615 | *h = box->y2 - box->y1; |
| 1616 | |
| 1617 | pixman_region32_fini(®ion); |
| 1618 | } |
| 1619 | |
Kristian Høgsberg | 9e31bff | 2012-08-01 00:08:07 -0400 | [diff] [blame] | 1620 | static int |
| 1621 | surface_resize(struct shell_surface *shsurf, |
Kristian Høgsberg | e314875 | 2013-05-06 23:19:49 -0400 | [diff] [blame] | 1622 | struct weston_seat *seat, uint32_t edges) |
Kristian Høgsberg | 9e31bff | 2012-08-01 00:08:07 -0400 | [diff] [blame] | 1623 | { |
| 1624 | struct weston_resize_grab *resize; |
| 1625 | |
Rafael Antognolli | 03b1659 | 2013-12-03 15:35:42 -0200 | [diff] [blame] | 1626 | if (shsurf->state.fullscreen || shsurf->state.maximized) |
Kristian Høgsberg | 9e31bff | 2012-08-01 00:08:07 -0400 | [diff] [blame] | 1627 | return 0; |
| 1628 | |
| 1629 | if (edges == 0 || edges > 15 || |
| 1630 | (edges & 3) == 3 || (edges & 12) == 12) |
| 1631 | return 0; |
| 1632 | |
| 1633 | resize = malloc(sizeof *resize); |
| 1634 | if (!resize) |
| 1635 | return -1; |
| 1636 | |
| 1637 | resize->edges = edges; |
Giulio Camuffo | b836664 | 2013-04-25 13:57:46 +0300 | [diff] [blame] | 1638 | surface_subsurfaces_boundingbox(shsurf->surface, NULL, NULL, |
| 1639 | &resize->width, &resize->height); |
Kristian Høgsberg | 9e31bff | 2012-08-01 00:08:07 -0400 | [diff] [blame] | 1640 | |
| 1641 | shell_grab_start(&resize->base, &resize_grab_interface, shsurf, |
Kristian Høgsberg | e314875 | 2013-05-06 23:19:49 -0400 | [diff] [blame] | 1642 | seat->pointer, edges); |
Kristian Høgsberg | 9e31bff | 2012-08-01 00:08:07 -0400 | [diff] [blame] | 1643 | |
| 1644 | return 0; |
| 1645 | } |
| 1646 | |
| 1647 | static void |
Rafael Antognolli | e2a3455 | 2013-12-03 15:35:45 -0200 | [diff] [blame] | 1648 | common_surface_resize(struct wl_resource *resource, |
| 1649 | struct wl_resource *seat_resource, uint32_t serial, |
| 1650 | uint32_t edges) |
Kristian Høgsberg | 9e31bff | 2012-08-01 00:08:07 -0400 | [diff] [blame] | 1651 | { |
Jason Ekstrand | 44a3863 | 2013-06-14 10:08:00 -0500 | [diff] [blame] | 1652 | struct weston_seat *seat = wl_resource_get_user_data(seat_resource); |
Jason Ekstrand | 651f00e | 2013-06-14 10:07:54 -0500 | [diff] [blame] | 1653 | struct shell_surface *shsurf = wl_resource_get_user_data(resource); |
Giulio Camuffo | 61da3fc | 2013-04-25 13:57:45 +0300 | [diff] [blame] | 1654 | struct weston_surface *surface; |
Kristian Høgsberg | 9e31bff | 2012-08-01 00:08:07 -0400 | [diff] [blame] | 1655 | |
Rafael Antognolli | 03b1659 | 2013-12-03 15:35:42 -0200 | [diff] [blame] | 1656 | if (shsurf->state.fullscreen) |
Kristian Høgsberg | 9e31bff | 2012-08-01 00:08:07 -0400 | [diff] [blame] | 1657 | return; |
| 1658 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 1659 | surface = weston_surface_get_main_surface(seat->pointer->focus->surface); |
Kristian Høgsberg | e314875 | 2013-05-06 23:19:49 -0400 | [diff] [blame] | 1660 | if (seat->pointer->button_count == 0 || |
| 1661 | seat->pointer->grab_serial != serial || |
Giulio Camuffo | 61da3fc | 2013-04-25 13:57:45 +0300 | [diff] [blame] | 1662 | surface != shsurf->surface) |
Kristian Høgsberg | 9e31bff | 2012-08-01 00:08:07 -0400 | [diff] [blame] | 1663 | return; |
| 1664 | |
Kristian Høgsberg | e314875 | 2013-05-06 23:19:49 -0400 | [diff] [blame] | 1665 | if (surface_resize(shsurf, seat, edges) < 0) |
Kristian Høgsberg | 9e31bff | 2012-08-01 00:08:07 -0400 | [diff] [blame] | 1666 | wl_resource_post_no_memory(resource); |
| 1667 | } |
| 1668 | |
Scott Moreau | c3e54eb | 2012-04-17 19:06:20 -0600 | [diff] [blame] | 1669 | static void |
Rafael Antognolli | e2a3455 | 2013-12-03 15:35:45 -0200 | [diff] [blame] | 1670 | shell_surface_resize(struct wl_client *client, struct wl_resource *resource, |
| 1671 | struct wl_resource *seat_resource, uint32_t serial, |
| 1672 | uint32_t edges) |
| 1673 | { |
| 1674 | common_surface_resize(resource, seat_resource, serial, edges); |
| 1675 | } |
| 1676 | |
| 1677 | static void |
Kristian Høgsberg | 6780073 | 2013-07-04 01:12:17 -0400 | [diff] [blame] | 1678 | end_busy_cursor(struct shell_surface *shsurf, struct weston_pointer *pointer); |
| 1679 | |
| 1680 | static void |
Kristian Høgsberg | 6848c25 | 2013-05-08 22:02:59 -0400 | [diff] [blame] | 1681 | busy_cursor_grab_focus(struct weston_pointer_grab *base) |
Scott Moreau | c3e54eb | 2012-04-17 19:06:20 -0600 | [diff] [blame] | 1682 | { |
Kristian Høgsberg | d56bd90 | 2012-06-05 09:58:51 -0400 | [diff] [blame] | 1683 | struct shell_grab *grab = (struct shell_grab *) base; |
Kristian Høgsberg | 6848c25 | 2013-05-08 22:02:59 -0400 | [diff] [blame] | 1684 | struct weston_pointer *pointer = base->pointer; |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 1685 | struct weston_view *view; |
Kristian Høgsberg | 6848c25 | 2013-05-08 22:02:59 -0400 | [diff] [blame] | 1686 | wl_fixed_t sx, sy; |
| 1687 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 1688 | view = weston_compositor_pick_view(pointer->seat->compositor, |
| 1689 | pointer->x, pointer->y, |
| 1690 | &sx, &sy); |
Scott Moreau | c3e54eb | 2012-04-17 19:06:20 -0600 | [diff] [blame] | 1691 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 1692 | if (!grab->shsurf || grab->shsurf->surface != view->surface) |
Kristian Høgsberg | 6780073 | 2013-07-04 01:12:17 -0400 | [diff] [blame] | 1693 | end_busy_cursor(grab->shsurf, pointer); |
Scott Moreau | c3e54eb | 2012-04-17 19:06:20 -0600 | [diff] [blame] | 1694 | } |
| 1695 | |
| 1696 | static void |
Giulio Camuffo | 1959ab8 | 2013-11-14 23:42:52 +0100 | [diff] [blame] | 1697 | busy_cursor_grab_motion(struct weston_pointer_grab *grab, uint32_t time, |
| 1698 | wl_fixed_t x, wl_fixed_t y) |
Scott Moreau | c3e54eb | 2012-04-17 19:06:20 -0600 | [diff] [blame] | 1699 | { |
Giulio Camuffo | 1959ab8 | 2013-11-14 23:42:52 +0100 | [diff] [blame] | 1700 | weston_pointer_move(grab->pointer, x, y); |
Kristian Høgsberg | d56bd90 | 2012-06-05 09:58:51 -0400 | [diff] [blame] | 1701 | } |
Scott Moreau | c3e54eb | 2012-04-17 19:06:20 -0600 | [diff] [blame] | 1702 | |
Kristian Høgsberg | d56bd90 | 2012-06-05 09:58:51 -0400 | [diff] [blame] | 1703 | static void |
Kristian Høgsberg | 02bbabb | 2013-05-06 22:15:05 -0400 | [diff] [blame] | 1704 | busy_cursor_grab_button(struct weston_pointer_grab *base, |
Kristian Høgsberg | d56bd90 | 2012-06-05 09:58:51 -0400 | [diff] [blame] | 1705 | uint32_t time, uint32_t button, uint32_t state) |
| 1706 | { |
Kristian Høgsberg | bbe9839 | 2012-08-01 00:20:21 -0400 | [diff] [blame] | 1707 | struct shell_grab *grab = (struct shell_grab *) base; |
Kristian Høgsberg | e122b7b | 2013-05-08 16:47:00 -0400 | [diff] [blame] | 1708 | struct shell_surface *shsurf = grab->shsurf; |
Kristian Høgsberg | e314875 | 2013-05-06 23:19:49 -0400 | [diff] [blame] | 1709 | struct weston_seat *seat = grab->grab.pointer->seat; |
Kristian Høgsberg | bbe9839 | 2012-08-01 00:20:21 -0400 | [diff] [blame] | 1710 | |
Kristian Høgsberg | bbe9839 | 2012-08-01 00:20:21 -0400 | [diff] [blame] | 1711 | if (shsurf && button == BTN_LEFT && state) { |
| 1712 | activate(shsurf->shell, shsurf->surface, seat); |
| 1713 | surface_move(shsurf, seat); |
Kristian Høgsberg | 0c36903 | 2013-02-14 21:31:44 -0500 | [diff] [blame] | 1714 | } else if (shsurf && button == BTN_RIGHT && state) { |
| 1715 | activate(shsurf->shell, shsurf->surface, seat); |
Kristian Høgsberg | e314875 | 2013-05-06 23:19:49 -0400 | [diff] [blame] | 1716 | surface_rotate(shsurf, seat); |
Kristian Høgsberg | bbe9839 | 2012-08-01 00:20:21 -0400 | [diff] [blame] | 1717 | } |
Kristian Høgsberg | d56bd90 | 2012-06-05 09:58:51 -0400 | [diff] [blame] | 1718 | } |
| 1719 | |
Jonas Ådahl | 1ea343e | 2013-10-25 23:18:05 +0200 | [diff] [blame] | 1720 | static void |
| 1721 | busy_cursor_grab_cancel(struct weston_pointer_grab *base) |
| 1722 | { |
| 1723 | struct shell_grab *grab = (struct shell_grab *) base; |
| 1724 | |
| 1725 | shell_grab_end(grab); |
| 1726 | free(grab); |
| 1727 | } |
| 1728 | |
Kristian Høgsberg | 02bbabb | 2013-05-06 22:15:05 -0400 | [diff] [blame] | 1729 | static const struct weston_pointer_grab_interface busy_cursor_grab_interface = { |
Kristian Høgsberg | d56bd90 | 2012-06-05 09:58:51 -0400 | [diff] [blame] | 1730 | busy_cursor_grab_focus, |
| 1731 | busy_cursor_grab_motion, |
| 1732 | busy_cursor_grab_button, |
Jonas Ådahl | 1ea343e | 2013-10-25 23:18:05 +0200 | [diff] [blame] | 1733 | busy_cursor_grab_cancel, |
Kristian Høgsberg | d56bd90 | 2012-06-05 09:58:51 -0400 | [diff] [blame] | 1734 | }; |
| 1735 | |
| 1736 | static void |
Kristian Høgsberg | 02bbabb | 2013-05-06 22:15:05 -0400 | [diff] [blame] | 1737 | set_busy_cursor(struct shell_surface *shsurf, struct weston_pointer *pointer) |
Kristian Høgsberg | d56bd90 | 2012-06-05 09:58:51 -0400 | [diff] [blame] | 1738 | { |
| 1739 | struct shell_grab *grab; |
Kristian Høgsberg | d56bd90 | 2012-06-05 09:58:51 -0400 | [diff] [blame] | 1740 | |
| 1741 | grab = malloc(sizeof *grab); |
| 1742 | if (!grab) |
Scott Moreau | c3e54eb | 2012-04-17 19:06:20 -0600 | [diff] [blame] | 1743 | return; |
| 1744 | |
Ander Conselvan de Oliveira | b9d2a0f | 2012-06-28 18:08:05 +0300 | [diff] [blame] | 1745 | shell_grab_start(grab, &busy_cursor_grab_interface, shsurf, pointer, |
| 1746 | DESKTOP_SHELL_CURSOR_BUSY); |
Kristian Høgsberg | d56bd90 | 2012-06-05 09:58:51 -0400 | [diff] [blame] | 1747 | } |
Scott Moreau | c3e54eb | 2012-04-17 19:06:20 -0600 | [diff] [blame] | 1748 | |
Kristian Høgsberg | d56bd90 | 2012-06-05 09:58:51 -0400 | [diff] [blame] | 1749 | static void |
Kristian Høgsberg | 02bbabb | 2013-05-06 22:15:05 -0400 | [diff] [blame] | 1750 | end_busy_cursor(struct shell_surface *shsurf, struct weston_pointer *pointer) |
Kristian Høgsberg | d56bd90 | 2012-06-05 09:58:51 -0400 | [diff] [blame] | 1751 | { |
| 1752 | struct shell_grab *grab = (struct shell_grab *) pointer->grab; |
| 1753 | |
Kristian Høgsberg | e122b7b | 2013-05-08 16:47:00 -0400 | [diff] [blame] | 1754 | if (grab->grab.interface == &busy_cursor_grab_interface && |
| 1755 | grab->shsurf == shsurf) { |
Ander Conselvan de Oliveira | b9d2a0f | 2012-06-28 18:08:05 +0300 | [diff] [blame] | 1756 | shell_grab_end(grab); |
Kristian Høgsberg | d56bd90 | 2012-06-05 09:58:51 -0400 | [diff] [blame] | 1757 | free(grab); |
Scott Moreau | c3e54eb | 2012-04-17 19:06:20 -0600 | [diff] [blame] | 1758 | } |
Scott Moreau | c3e54eb | 2012-04-17 19:06:20 -0600 | [diff] [blame] | 1759 | } |
| 1760 | |
Scott Moreau | 9521d5e | 2012-04-19 13:06:17 -0600 | [diff] [blame] | 1761 | static void |
| 1762 | ping_timer_destroy(struct shell_surface *shsurf) |
| 1763 | { |
| 1764 | if (!shsurf || !shsurf->ping_timer) |
| 1765 | return; |
| 1766 | |
| 1767 | if (shsurf->ping_timer->source) |
| 1768 | wl_event_source_remove(shsurf->ping_timer->source); |
| 1769 | |
| 1770 | free(shsurf->ping_timer); |
| 1771 | shsurf->ping_timer = NULL; |
| 1772 | } |
| 1773 | |
Kristian Høgsberg | 97d44aa | 2011-08-26 17:21:20 -0400 | [diff] [blame] | 1774 | static int |
Scott Moreau | ff1db4a | 2012-04-17 19:06:18 -0600 | [diff] [blame] | 1775 | ping_timeout_handler(void *data) |
| 1776 | { |
| 1777 | struct shell_surface *shsurf = data; |
Kristian Høgsberg | d56bd90 | 2012-06-05 09:58:51 -0400 | [diff] [blame] | 1778 | struct weston_seat *seat; |
Scott Moreau | ff1db4a | 2012-04-17 19:06:18 -0600 | [diff] [blame] | 1779 | |
Scott Moreau | 9521d5e | 2012-04-19 13:06:17 -0600 | [diff] [blame] | 1780 | /* Client is not responding */ |
| 1781 | shsurf->unresponsive = 1; |
Kristian Høgsberg | d56bd90 | 2012-06-05 09:58:51 -0400 | [diff] [blame] | 1782 | |
| 1783 | wl_list_for_each(seat, &shsurf->surface->compositor->seat_list, link) |
Emilio Pozuelo Monfort | 3d0fc76 | 2013-11-22 16:21:20 +0100 | [diff] [blame] | 1784 | if (seat->pointer->focus && |
| 1785 | seat->pointer->focus->surface == shsurf->surface) |
Kristian Høgsberg | e314875 | 2013-05-06 23:19:49 -0400 | [diff] [blame] | 1786 | set_busy_cursor(shsurf, seat->pointer); |
Scott Moreau | ff1db4a | 2012-04-17 19:06:18 -0600 | [diff] [blame] | 1787 | |
| 1788 | return 1; |
| 1789 | } |
| 1790 | |
| 1791 | static void |
| 1792 | ping_handler(struct weston_surface *surface, uint32_t serial) |
| 1793 | { |
Kristian Høgsberg | b71302e | 2012-05-10 12:28:35 -0400 | [diff] [blame] | 1794 | struct shell_surface *shsurf = get_shell_surface(surface); |
Scott Moreau | ff1db4a | 2012-04-17 19:06:18 -0600 | [diff] [blame] | 1795 | struct wl_event_loop *loop; |
Kristian Høgsberg | d56bd90 | 2012-06-05 09:58:51 -0400 | [diff] [blame] | 1796 | int ping_timeout = 200; |
Scott Moreau | ff1db4a | 2012-04-17 19:06:18 -0600 | [diff] [blame] | 1797 | |
| 1798 | if (!shsurf) |
| 1799 | return; |
Jason Ekstrand | 651f00e | 2013-06-14 10:07:54 -0500 | [diff] [blame] | 1800 | if (!shsurf->resource) |
Kristian Høgsberg | ca535c1 | 2012-04-21 23:20:07 -0400 | [diff] [blame] | 1801 | return; |
Scott Moreau | ff1db4a | 2012-04-17 19:06:18 -0600 | [diff] [blame] | 1802 | |
Ander Conselvan de Oliveira | eac9a46 | 2012-07-16 14:15:48 +0300 | [diff] [blame] | 1803 | if (shsurf->surface == shsurf->shell->grab_surface) |
| 1804 | return; |
| 1805 | |
Scott Moreau | ff1db4a | 2012-04-17 19:06:18 -0600 | [diff] [blame] | 1806 | if (!shsurf->ping_timer) { |
Ander Conselvan de Oliveira | fb98089 | 2012-04-27 13:55:55 +0300 | [diff] [blame] | 1807 | shsurf->ping_timer = malloc(sizeof *shsurf->ping_timer); |
Scott Moreau | ff1db4a | 2012-04-17 19:06:18 -0600 | [diff] [blame] | 1808 | if (!shsurf->ping_timer) |
| 1809 | return; |
| 1810 | |
| 1811 | shsurf->ping_timer->serial = serial; |
Scott Moreau | ff1db4a | 2012-04-17 19:06:18 -0600 | [diff] [blame] | 1812 | loop = wl_display_get_event_loop(surface->compositor->wl_display); |
| 1813 | shsurf->ping_timer->source = |
| 1814 | wl_event_loop_add_timer(loop, ping_timeout_handler, shsurf); |
| 1815 | wl_event_source_timer_update(shsurf->ping_timer->source, ping_timeout); |
| 1816 | |
Rafael Antognolli | e2a3455 | 2013-12-03 15:35:45 -0200 | [diff] [blame] | 1817 | if (shell_surface_is_wl_shell_surface(shsurf)) |
| 1818 | wl_shell_surface_send_ping(shsurf->resource, serial); |
| 1819 | else if (shell_surface_is_xdg_surface(shsurf)) |
| 1820 | xdg_surface_send_ping(shsurf->resource, serial); |
| 1821 | else if (shell_surface_is_xdg_popup(shsurf)) |
| 1822 | xdg_popup_send_ping(shsurf->resource, serial); |
Scott Moreau | ff1db4a | 2012-04-17 19:06:18 -0600 | [diff] [blame] | 1823 | } |
| 1824 | } |
| 1825 | |
| 1826 | static void |
Kristian Høgsberg | d56bd90 | 2012-06-05 09:58:51 -0400 | [diff] [blame] | 1827 | handle_pointer_focus(struct wl_listener *listener, void *data) |
| 1828 | { |
Kristian Høgsberg | 02bbabb | 2013-05-06 22:15:05 -0400 | [diff] [blame] | 1829 | struct weston_pointer *pointer = data; |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 1830 | struct weston_view *view = pointer->focus; |
Kristian Høgsberg | d56bd90 | 2012-06-05 09:58:51 -0400 | [diff] [blame] | 1831 | struct weston_compositor *compositor; |
| 1832 | struct shell_surface *shsurf; |
| 1833 | uint32_t serial; |
| 1834 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 1835 | if (!view) |
Kristian Høgsberg | d56bd90 | 2012-06-05 09:58:51 -0400 | [diff] [blame] | 1836 | return; |
| 1837 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 1838 | compositor = view->surface->compositor; |
| 1839 | shsurf = get_shell_surface(view->surface); |
Kristian Høgsberg | d56bd90 | 2012-06-05 09:58:51 -0400 | [diff] [blame] | 1840 | |
Pekka Paalanen | 4e1f2ff | 2012-06-06 16:59:45 +0300 | [diff] [blame] | 1841 | if (shsurf && shsurf->unresponsive) { |
Kristian Høgsberg | d56bd90 | 2012-06-05 09:58:51 -0400 | [diff] [blame] | 1842 | set_busy_cursor(shsurf, pointer); |
| 1843 | } else { |
| 1844 | serial = wl_display_next_serial(compositor->wl_display); |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 1845 | ping_handler(view->surface, serial); |
Kristian Høgsberg | d56bd90 | 2012-06-05 09:58:51 -0400 | [diff] [blame] | 1846 | } |
| 1847 | } |
| 1848 | |
| 1849 | static void |
Kristian Høgsberg | f4d2f23 | 2012-08-10 10:05:39 -0400 | [diff] [blame] | 1850 | create_pointer_focus_listener(struct weston_seat *seat) |
| 1851 | { |
| 1852 | struct wl_listener *listener; |
| 1853 | |
Kristian Høgsberg | e314875 | 2013-05-06 23:19:49 -0400 | [diff] [blame] | 1854 | if (!seat->pointer) |
Kristian Høgsberg | f4d2f23 | 2012-08-10 10:05:39 -0400 | [diff] [blame] | 1855 | return; |
| 1856 | |
| 1857 | listener = malloc(sizeof *listener); |
| 1858 | listener->notify = handle_pointer_focus; |
Kristian Høgsberg | e314875 | 2013-05-06 23:19:49 -0400 | [diff] [blame] | 1859 | wl_signal_add(&seat->pointer->focus_signal, listener); |
Kristian Høgsberg | f4d2f23 | 2012-08-10 10:05:39 -0400 | [diff] [blame] | 1860 | } |
| 1861 | |
| 1862 | static void |
Rafael Antognolli | e2a3455 | 2013-12-03 15:35:45 -0200 | [diff] [blame] | 1863 | xdg_surface_set_transient_for(struct wl_client *client, |
| 1864 | struct wl_resource *resource, |
| 1865 | struct wl_resource *parent_resource) |
Scott Moreau | ff1db4a | 2012-04-17 19:06:18 -0600 | [diff] [blame] | 1866 | { |
Jason Ekstrand | 651f00e | 2013-06-14 10:07:54 -0500 | [diff] [blame] | 1867 | struct shell_surface *shsurf = wl_resource_get_user_data(resource); |
Jasper St. Pierre | 8f180d4 | 2013-12-07 13:49:28 -0500 | [diff] [blame] | 1868 | struct weston_surface *parent; |
| 1869 | |
| 1870 | if (parent_resource) |
| 1871 | parent = wl_resource_get_user_data(parent_resource); |
| 1872 | else |
| 1873 | parent = NULL; |
Rafael Antognolli | e2a3455 | 2013-12-03 15:35:45 -0200 | [diff] [blame] | 1874 | |
| 1875 | shell_surface_set_parent(shsurf, parent); |
| 1876 | } |
| 1877 | |
| 1878 | static void |
| 1879 | surface_pong(struct shell_surface *shsurf, uint32_t serial) |
| 1880 | { |
Kristian Høgsberg | d56bd90 | 2012-06-05 09:58:51 -0400 | [diff] [blame] | 1881 | struct weston_compositor *ec = shsurf->surface->compositor; |
Rafael Antognolli | e2a3455 | 2013-12-03 15:35:45 -0200 | [diff] [blame] | 1882 | struct weston_seat *seat; |
Scott Moreau | ff1db4a | 2012-04-17 19:06:18 -0600 | [diff] [blame] | 1883 | |
Kristian Høgsberg | 92374e1 | 2012-08-11 22:39:12 -0400 | [diff] [blame] | 1884 | if (shsurf->ping_timer == NULL) |
| 1885 | /* Just ignore unsolicited pong. */ |
| 1886 | return; |
| 1887 | |
Scott Moreau | ff1db4a | 2012-04-17 19:06:18 -0600 | [diff] [blame] | 1888 | if (shsurf->ping_timer->serial == serial) { |
Scott Moreau | ff1db4a | 2012-04-17 19:06:18 -0600 | [diff] [blame] | 1889 | shsurf->unresponsive = 0; |
Hardening | eb1e130 | 2013-05-17 18:07:41 +0200 | [diff] [blame] | 1890 | wl_list_for_each(seat, &ec->seat_list, link) { |
| 1891 | if(seat->pointer) |
| 1892 | end_busy_cursor(shsurf, seat->pointer); |
| 1893 | } |
Scott Moreau | 9521d5e | 2012-04-19 13:06:17 -0600 | [diff] [blame] | 1894 | ping_timer_destroy(shsurf); |
Scott Moreau | ff1db4a | 2012-04-17 19:06:18 -0600 | [diff] [blame] | 1895 | } |
| 1896 | } |
| 1897 | |
Kristian Høgsberg | e7afd91 | 2012-05-02 09:47:44 -0400 | [diff] [blame] | 1898 | static void |
Rafael Antognolli | e2a3455 | 2013-12-03 15:35:45 -0200 | [diff] [blame] | 1899 | shell_surface_pong(struct wl_client *client, struct wl_resource *resource, |
| 1900 | uint32_t serial) |
| 1901 | { |
| 1902 | struct shell_surface *shsurf = wl_resource_get_user_data(resource); |
| 1903 | |
| 1904 | surface_pong(shsurf, serial); |
| 1905 | |
| 1906 | } |
| 1907 | |
| 1908 | static void |
Giulio Camuffo | 62942ad | 2013-09-11 18:20:47 +0200 | [diff] [blame] | 1909 | set_title(struct shell_surface *shsurf, const char *title) |
| 1910 | { |
| 1911 | free(shsurf->title); |
| 1912 | shsurf->title = strdup(title); |
| 1913 | } |
| 1914 | |
| 1915 | static void |
Kristian Høgsberg | e7afd91 | 2012-05-02 09:47:44 -0400 | [diff] [blame] | 1916 | shell_surface_set_title(struct wl_client *client, |
| 1917 | struct wl_resource *resource, const char *title) |
| 1918 | { |
Jason Ekstrand | 651f00e | 2013-06-14 10:07:54 -0500 | [diff] [blame] | 1919 | struct shell_surface *shsurf = wl_resource_get_user_data(resource); |
Kristian Høgsberg | e7afd91 | 2012-05-02 09:47:44 -0400 | [diff] [blame] | 1920 | |
Giulio Camuffo | 62942ad | 2013-09-11 18:20:47 +0200 | [diff] [blame] | 1921 | set_title(shsurf, title); |
Kristian Høgsberg | e7afd91 | 2012-05-02 09:47:44 -0400 | [diff] [blame] | 1922 | } |
| 1923 | |
| 1924 | static void |
| 1925 | shell_surface_set_class(struct wl_client *client, |
| 1926 | struct wl_resource *resource, const char *class) |
| 1927 | { |
Jason Ekstrand | 651f00e | 2013-06-14 10:07:54 -0500 | [diff] [blame] | 1928 | struct shell_surface *shsurf = wl_resource_get_user_data(resource); |
Kristian Høgsberg | e7afd91 | 2012-05-02 09:47:44 -0400 | [diff] [blame] | 1929 | |
| 1930 | free(shsurf->class); |
| 1931 | shsurf->class = strdup(class); |
| 1932 | } |
| 1933 | |
Alex Wu | 4539b08 | 2012-03-01 12:57:46 +0800 | [diff] [blame] | 1934 | static void |
Alexander Larsson | f82b6ca | 2013-05-28 16:23:39 +0200 | [diff] [blame] | 1935 | restore_output_mode(struct weston_output *output) |
| 1936 | { |
Hardening | 57388e4 | 2013-09-18 23:56:36 +0200 | [diff] [blame] | 1937 | if (output->current_mode != output->original_mode || |
| 1938 | (int32_t)output->current_scale != output->original_scale) |
Alexander Larsson | f82b6ca | 2013-05-28 16:23:39 +0200 | [diff] [blame] | 1939 | weston_output_switch_mode(output, |
Hardening | 57388e4 | 2013-09-18 23:56:36 +0200 | [diff] [blame] | 1940 | output->original_mode, |
| 1941 | output->original_scale, |
| 1942 | WESTON_MODE_SWITCH_RESTORE_NATIVE); |
Alexander Larsson | f82b6ca | 2013-05-28 16:23:39 +0200 | [diff] [blame] | 1943 | } |
| 1944 | |
| 1945 | static void |
| 1946 | restore_all_output_modes(struct weston_compositor *compositor) |
| 1947 | { |
| 1948 | struct weston_output *output; |
| 1949 | |
| 1950 | wl_list_for_each(output, &compositor->output_list, link) |
| 1951 | restore_output_mode(output); |
| 1952 | } |
| 1953 | |
Philip Withnall | becb77e | 2013-11-25 18:01:30 +0000 | [diff] [blame] | 1954 | static int |
| 1955 | get_output_panel_height(struct desktop_shell *shell, |
| 1956 | struct weston_output *output) |
| 1957 | { |
| 1958 | struct weston_view *view; |
| 1959 | int panel_height = 0; |
| 1960 | |
| 1961 | if (!output) |
| 1962 | return 0; |
| 1963 | |
| 1964 | wl_list_for_each(view, &shell->panel_layer.view_list, layer_link) { |
| 1965 | if (view->surface->output == output) { |
Jason Ekstrand | 918f2dd | 2013-12-02 21:01:53 -0600 | [diff] [blame] | 1966 | panel_height = view->surface->height; |
Philip Withnall | becb77e | 2013-11-25 18:01:30 +0000 | [diff] [blame] | 1967 | break; |
| 1968 | } |
| 1969 | } |
| 1970 | |
| 1971 | return panel_height; |
| 1972 | } |
| 1973 | |
Philip Withnall | 07926d9 | 2013-11-25 18:01:40 +0000 | [diff] [blame] | 1974 | /* The surface will be inserted into the list immediately after the link |
| 1975 | * returned by this function (i.e. will be stacked immediately above the |
| 1976 | * returned link). */ |
| 1977 | static struct wl_list * |
| 1978 | shell_surface_calculate_layer_link (struct shell_surface *shsurf) |
| 1979 | { |
| 1980 | struct workspace *ws; |
Kristian Høgsberg | ead5242 | 2014-01-01 13:51:52 -0800 | [diff] [blame] | 1981 | struct weston_view *parent; |
Philip Withnall | 07926d9 | 2013-11-25 18:01:40 +0000 | [diff] [blame] | 1982 | |
| 1983 | switch (shsurf->type) { |
Kristian Høgsberg | ead5242 | 2014-01-01 13:51:52 -0800 | [diff] [blame] | 1984 | case SHELL_SURFACE_POPUP: |
| 1985 | case SHELL_SURFACE_TOPLEVEL: |
Rafael Antognolli | ed207b4 | 2013-12-03 15:35:43 -0200 | [diff] [blame] | 1986 | if (shsurf->state.fullscreen) { |
Rafael Antognolli | 03b1659 | 2013-12-03 15:35:42 -0200 | [diff] [blame] | 1987 | return &shsurf->shell->fullscreen_layer.view_list; |
Rafael Antognolli | ed207b4 | 2013-12-03 15:35:43 -0200 | [diff] [blame] | 1988 | } else if (shsurf->parent) { |
Kristian Høgsberg | d55db69 | 2014-01-01 12:26:14 -0800 | [diff] [blame] | 1989 | /* Move the surface to its parent layer so |
| 1990 | * that surfaces which are transient for |
| 1991 | * fullscreen surfaces don't get hidden by the |
| 1992 | * fullscreen surfaces. */ |
Rafael Antognolli | ed207b4 | 2013-12-03 15:35:43 -0200 | [diff] [blame] | 1993 | |
| 1994 | /* TODO: Handle a parent with multiple views */ |
| 1995 | parent = get_default_view(shsurf->parent); |
| 1996 | if (parent) |
| 1997 | return parent->layer_link.prev; |
| 1998 | } |
Rafael Antognolli | 03b1659 | 2013-12-03 15:35:42 -0200 | [diff] [blame] | 1999 | break; |
Philip Withnall | 07926d9 | 2013-11-25 18:01:40 +0000 | [diff] [blame] | 2000 | |
| 2001 | case SHELL_SURFACE_XWAYLAND: |
Kristian Høgsberg | 4804a30 | 2013-12-05 22:43:03 -0800 | [diff] [blame] | 2002 | return &shsurf->shell->fullscreen_layer.view_list; |
| 2003 | |
Philip Withnall | 07926d9 | 2013-11-25 18:01:40 +0000 | [diff] [blame] | 2004 | case SHELL_SURFACE_NONE: |
| 2005 | default: |
| 2006 | /* Go to the fallback, below. */ |
| 2007 | break; |
| 2008 | } |
| 2009 | |
| 2010 | /* Move the surface to a normal workspace layer so that surfaces |
| 2011 | * which were previously fullscreen or transient are no longer |
| 2012 | * rendered on top. */ |
| 2013 | ws = get_current_workspace(shsurf->shell); |
| 2014 | return &ws->layer.view_list; |
| 2015 | } |
| 2016 | |
Philip Withnall | 648a4dd | 2013-11-25 18:01:44 +0000 | [diff] [blame] | 2017 | static void |
| 2018 | shell_surface_update_child_surface_layers (struct shell_surface *shsurf) |
| 2019 | { |
| 2020 | struct shell_surface *child; |
| 2021 | |
| 2022 | /* Move the child layers to the same workspace as shsurf. They will be |
| 2023 | * stacked above shsurf. */ |
| 2024 | wl_list_for_each_reverse(child, &shsurf->children_list, children_link) { |
| 2025 | if (shsurf->view->layer_link.prev != &child->view->layer_link) { |
| 2026 | weston_view_geometry_dirty(child->view); |
| 2027 | wl_list_remove(&child->view->layer_link); |
| 2028 | wl_list_insert(shsurf->view->layer_link.prev, |
| 2029 | &child->view->layer_link); |
| 2030 | weston_view_geometry_dirty(child->view); |
| 2031 | weston_surface_damage(child->surface); |
| 2032 | |
| 2033 | /* Recurse. We don’t expect this to recurse very far (if |
| 2034 | * at all) because that would imply we have transient |
| 2035 | * (or popup) children of transient surfaces, which |
| 2036 | * would be unusual. */ |
| 2037 | shell_surface_update_child_surface_layers(child); |
| 2038 | } |
| 2039 | } |
| 2040 | } |
| 2041 | |
Philip Withnall | e1d75ae | 2013-11-25 18:01:41 +0000 | [diff] [blame] | 2042 | /* 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] | 2043 | * geometry to ensure the changes are redrawn. |
| 2044 | * |
| 2045 | * If any child surfaces exist and are mapped, ensure they’re in the same layer |
| 2046 | * as this surface. */ |
Philip Withnall | e1d75ae | 2013-11-25 18:01:41 +0000 | [diff] [blame] | 2047 | static void |
| 2048 | shell_surface_update_layer(struct shell_surface *shsurf) |
| 2049 | { |
| 2050 | struct wl_list *new_layer_link; |
| 2051 | |
| 2052 | new_layer_link = shell_surface_calculate_layer_link(shsurf); |
| 2053 | |
| 2054 | if (new_layer_link == &shsurf->view->layer_link) |
| 2055 | return; |
| 2056 | |
| 2057 | weston_view_geometry_dirty(shsurf->view); |
| 2058 | wl_list_remove(&shsurf->view->layer_link); |
| 2059 | wl_list_insert(new_layer_link, &shsurf->view->layer_link); |
| 2060 | weston_view_geometry_dirty(shsurf->view); |
| 2061 | weston_surface_damage(shsurf->surface); |
Philip Withnall | 648a4dd | 2013-11-25 18:01:44 +0000 | [diff] [blame] | 2062 | |
| 2063 | shell_surface_update_child_surface_layers(shsurf); |
Philip Withnall | e1d75ae | 2013-11-25 18:01:41 +0000 | [diff] [blame] | 2064 | } |
| 2065 | |
Alexander Larsson | f82b6ca | 2013-05-28 16:23:39 +0200 | [diff] [blame] | 2066 | static void |
Philip Withnall | dc4332f | 2013-11-25 18:01:38 +0000 | [diff] [blame] | 2067 | shell_surface_set_parent(struct shell_surface *shsurf, |
| 2068 | struct weston_surface *parent) |
| 2069 | { |
| 2070 | shsurf->parent = parent; |
Philip Withnall | 648a4dd | 2013-11-25 18:01:44 +0000 | [diff] [blame] | 2071 | |
| 2072 | wl_list_remove(&shsurf->children_link); |
| 2073 | wl_list_init(&shsurf->children_link); |
| 2074 | |
| 2075 | /* Insert into the parent surface’s child list. */ |
| 2076 | if (parent != NULL) { |
| 2077 | struct shell_surface *parent_shsurf = get_shell_surface(parent); |
| 2078 | if (parent_shsurf != NULL) |
| 2079 | wl_list_insert(&parent_shsurf->children_list, |
| 2080 | &shsurf->children_link); |
| 2081 | } |
Philip Withnall | dc4332f | 2013-11-25 18:01:38 +0000 | [diff] [blame] | 2082 | } |
| 2083 | |
| 2084 | static void |
Philip Withnall | 352e7ed | 2013-11-25 18:01:35 +0000 | [diff] [blame] | 2085 | shell_surface_set_output(struct shell_surface *shsurf, |
| 2086 | struct weston_output *output) |
| 2087 | { |
| 2088 | struct weston_surface *es = shsurf->surface; |
| 2089 | |
| 2090 | /* get the default output, if the client set it as NULL |
| 2091 | check whether the ouput is available */ |
| 2092 | if (output) |
| 2093 | shsurf->output = output; |
| 2094 | else if (es->output) |
| 2095 | shsurf->output = es->output; |
| 2096 | else |
| 2097 | shsurf->output = get_default_output(es->compositor); |
| 2098 | } |
| 2099 | |
| 2100 | static void |
Rafael Antognolli | 03b1659 | 2013-12-03 15:35:42 -0200 | [diff] [blame] | 2101 | surface_clear_next_states(struct shell_surface *shsurf) |
| 2102 | { |
| 2103 | shsurf->next_state.maximized = false; |
| 2104 | shsurf->next_state.fullscreen = false; |
| 2105 | |
| 2106 | if ((shsurf->next_state.maximized != shsurf->state.maximized) || |
| 2107 | (shsurf->next_state.fullscreen != shsurf->state.fullscreen)) |
| 2108 | shsurf->state_changed = true; |
| 2109 | } |
| 2110 | |
| 2111 | static void |
Philip Withnall | becb77e | 2013-11-25 18:01:30 +0000 | [diff] [blame] | 2112 | set_toplevel(struct shell_surface *shsurf) |
| 2113 | { |
Kristian Høgsberg | 41fbf6f | 2013-12-05 22:31:25 -0800 | [diff] [blame] | 2114 | shell_surface_set_parent(shsurf, NULL); |
| 2115 | surface_clear_next_states(shsurf); |
Kristian Høgsberg | c8f8dd8 | 2013-12-05 23:20:33 -0800 | [diff] [blame] | 2116 | shsurf->type = SHELL_SURFACE_TOPLEVEL; |
Philip Withnall | 648a4dd | 2013-11-25 18:01:44 +0000 | [diff] [blame] | 2117 | |
| 2118 | /* The layer_link is updated in set_surface_type(), |
| 2119 | * called from configure. */ |
Philip Withnall | becb77e | 2013-11-25 18:01:30 +0000 | [diff] [blame] | 2120 | } |
| 2121 | |
| 2122 | static void |
| 2123 | shell_surface_set_toplevel(struct wl_client *client, |
| 2124 | struct wl_resource *resource) |
| 2125 | { |
| 2126 | struct shell_surface *surface = wl_resource_get_user_data(resource); |
| 2127 | |
| 2128 | set_toplevel(surface); |
| 2129 | } |
| 2130 | |
| 2131 | static void |
| 2132 | set_transient(struct shell_surface *shsurf, |
| 2133 | struct weston_surface *parent, int x, int y, uint32_t flags) |
| 2134 | { |
Philip Withnall | dc4332f | 2013-11-25 18:01:38 +0000 | [diff] [blame] | 2135 | assert(parent != NULL); |
| 2136 | |
Kristian Høgsberg | 9f7e331 | 2014-01-02 22:40:37 -0800 | [diff] [blame] | 2137 | shell_surface_set_parent(shsurf, parent); |
| 2138 | |
| 2139 | surface_clear_next_states(shsurf); |
| 2140 | |
Philip Withnall | becb77e | 2013-11-25 18:01:30 +0000 | [diff] [blame] | 2141 | shsurf->transient.x = x; |
| 2142 | shsurf->transient.y = y; |
| 2143 | shsurf->transient.flags = flags; |
Philip Withnall | dc4332f | 2013-11-25 18:01:38 +0000 | [diff] [blame] | 2144 | |
Rafael Antognolli | ed207b4 | 2013-12-03 15:35:43 -0200 | [diff] [blame] | 2145 | shsurf->next_state.relative = true; |
Kristian Høgsberg | a1df7ac | 2013-12-31 15:01:01 -0800 | [diff] [blame] | 2146 | shsurf->state_changed = true; |
Kristian Høgsberg | c8f8dd8 | 2013-12-05 23:20:33 -0800 | [diff] [blame] | 2147 | shsurf->type = SHELL_SURFACE_TOPLEVEL; |
Philip Withnall | 648a4dd | 2013-11-25 18:01:44 +0000 | [diff] [blame] | 2148 | |
| 2149 | /* The layer_link is updated in set_surface_type(), |
| 2150 | * called from configure. */ |
Philip Withnall | becb77e | 2013-11-25 18:01:30 +0000 | [diff] [blame] | 2151 | } |
| 2152 | |
| 2153 | static void |
| 2154 | shell_surface_set_transient(struct wl_client *client, |
| 2155 | struct wl_resource *resource, |
| 2156 | struct wl_resource *parent_resource, |
| 2157 | int x, int y, uint32_t flags) |
| 2158 | { |
| 2159 | struct shell_surface *shsurf = wl_resource_get_user_data(resource); |
| 2160 | struct weston_surface *parent = |
| 2161 | wl_resource_get_user_data(parent_resource); |
| 2162 | |
| 2163 | set_transient(shsurf, parent, x, y, flags); |
| 2164 | } |
| 2165 | |
| 2166 | static void |
| 2167 | set_fullscreen(struct shell_surface *shsurf, |
| 2168 | uint32_t method, |
| 2169 | uint32_t framerate, |
| 2170 | struct weston_output *output) |
| 2171 | { |
Philip Withnall | 352e7ed | 2013-11-25 18:01:35 +0000 | [diff] [blame] | 2172 | shell_surface_set_output(shsurf, output); |
Philip Withnall | becb77e | 2013-11-25 18:01:30 +0000 | [diff] [blame] | 2173 | |
| 2174 | shsurf->fullscreen_output = shsurf->output; |
| 2175 | shsurf->fullscreen.type = method; |
| 2176 | shsurf->fullscreen.framerate = framerate; |
Philip Withnall | dc4332f | 2013-11-25 18:01:38 +0000 | [diff] [blame] | 2177 | |
Kristian Høgsberg | e960b3f | 2013-12-05 22:04:42 -0800 | [diff] [blame] | 2178 | shsurf->next_state.fullscreen = true; |
| 2179 | shsurf->state_changed = true; |
Kristian Høgsberg | c8f8dd8 | 2013-12-05 23:20:33 -0800 | [diff] [blame] | 2180 | shsurf->type = SHELL_SURFACE_TOPLEVEL; |
Philip Withnall | becb77e | 2013-11-25 18:01:30 +0000 | [diff] [blame] | 2181 | |
| 2182 | shsurf->client->send_configure(shsurf->surface, 0, |
| 2183 | shsurf->output->width, |
| 2184 | shsurf->output->height); |
Philip Withnall | 648a4dd | 2013-11-25 18:01:44 +0000 | [diff] [blame] | 2185 | |
| 2186 | /* The layer_link is updated in set_surface_type(), |
| 2187 | * called from configure. */ |
Philip Withnall | becb77e | 2013-11-25 18:01:30 +0000 | [diff] [blame] | 2188 | } |
| 2189 | |
| 2190 | static void |
Zhang, Xiong Y | 3123693 | 2013-12-13 22:10:57 +0200 | [diff] [blame] | 2191 | weston_view_set_initial_position(struct weston_view *view, |
| 2192 | struct desktop_shell *shell); |
| 2193 | |
| 2194 | static void |
Philip Withnall | becb77e | 2013-11-25 18:01:30 +0000 | [diff] [blame] | 2195 | unset_fullscreen(struct shell_surface *shsurf) |
Alex Wu | 4539b08 | 2012-03-01 12:57:46 +0800 | [diff] [blame] | 2196 | { |
Philip Withnall | f85fe84 | 2013-11-25 18:01:37 +0000 | [diff] [blame] | 2197 | /* Unset the fullscreen output, driver configuration and transforms. */ |
Alex Wu | bd3354b | 2012-04-17 17:20:49 +0800 | [diff] [blame] | 2198 | if (shsurf->fullscreen.type == WL_SHELL_SURFACE_FULLSCREEN_METHOD_DRIVER && |
| 2199 | shell_surface_is_top_fullscreen(shsurf)) { |
Alexander Larsson | f82b6ca | 2013-05-28 16:23:39 +0200 | [diff] [blame] | 2200 | restore_output_mode(shsurf->fullscreen_output); |
Alex Wu | bd3354b | 2012-04-17 17:20:49 +0800 | [diff] [blame] | 2201 | } |
Philip Withnall | f85fe84 | 2013-11-25 18:01:37 +0000 | [diff] [blame] | 2202 | shsurf->fullscreen_output = NULL; |
| 2203 | |
Alex Wu | 4539b08 | 2012-03-01 12:57:46 +0800 | [diff] [blame] | 2204 | shsurf->fullscreen.type = WL_SHELL_SURFACE_FULLSCREEN_METHOD_DEFAULT; |
| 2205 | shsurf->fullscreen.framerate = 0; |
Philip Withnall | f85fe84 | 2013-11-25 18:01:37 +0000 | [diff] [blame] | 2206 | |
Alex Wu | 4539b08 | 2012-03-01 12:57:46 +0800 | [diff] [blame] | 2207 | wl_list_remove(&shsurf->fullscreen.transform.link); |
| 2208 | wl_list_init(&shsurf->fullscreen.transform.link); |
Philip Withnall | f85fe84 | 2013-11-25 18:01:37 +0000 | [diff] [blame] | 2209 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 2210 | if (shsurf->fullscreen.black_view) |
| 2211 | weston_surface_destroy(shsurf->fullscreen.black_view->surface); |
| 2212 | shsurf->fullscreen.black_view = NULL; |
Philip Withnall | f85fe84 | 2013-11-25 18:01:37 +0000 | [diff] [blame] | 2213 | |
Zhang, Xiong Y | 3123693 | 2013-12-13 22:10:57 +0200 | [diff] [blame] | 2214 | if (shsurf->saved_position_valid) |
| 2215 | weston_view_set_position(shsurf->view, |
| 2216 | shsurf->saved_x, shsurf->saved_y); |
| 2217 | else |
| 2218 | weston_view_set_initial_position(shsurf->view, shsurf->shell); |
| 2219 | |
Alex Wu | 7bcb8bd | 2012-04-27 09:07:24 +0800 | [diff] [blame] | 2220 | if (shsurf->saved_rotation_valid) { |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 2221 | wl_list_insert(&shsurf->view->geometry.transformation_list, |
Philip Withnall | becb77e | 2013-11-25 18:01:30 +0000 | [diff] [blame] | 2222 | &shsurf->rotation.transform.link); |
Alex Wu | 7bcb8bd | 2012-04-27 09:07:24 +0800 | [diff] [blame] | 2223 | shsurf->saved_rotation_valid = false; |
| 2224 | } |
Rafal Mielniczuk | 3e3862c | 2012-10-07 20:25:36 +0200 | [diff] [blame] | 2225 | |
Philip Withnall | e1d75ae | 2013-11-25 18:01:41 +0000 | [diff] [blame] | 2226 | /* Layer is updated in set_surface_type(). */ |
Alex Wu | 4539b08 | 2012-03-01 12:57:46 +0800 | [diff] [blame] | 2227 | } |
| 2228 | |
Rafal Mielniczuk | fffdcdd | 2013-03-11 19:26:54 +0100 | [diff] [blame] | 2229 | static void |
Philip Withnall | becb77e | 2013-11-25 18:01:30 +0000 | [diff] [blame] | 2230 | shell_surface_set_fullscreen(struct wl_client *client, |
| 2231 | struct wl_resource *resource, |
| 2232 | uint32_t method, |
| 2233 | uint32_t framerate, |
| 2234 | struct wl_resource *output_resource) |
| 2235 | { |
| 2236 | struct shell_surface *shsurf = wl_resource_get_user_data(resource); |
| 2237 | struct weston_output *output; |
| 2238 | |
| 2239 | if (output_resource) |
| 2240 | output = wl_resource_get_user_data(output_resource); |
| 2241 | else |
| 2242 | output = NULL; |
| 2243 | |
Rafael Antognolli | 4b99a40 | 2013-12-03 15:35:44 -0200 | [diff] [blame] | 2244 | shell_surface_set_parent(shsurf, NULL); |
| 2245 | |
Rafael Antognolli | 03b1659 | 2013-12-03 15:35:42 -0200 | [diff] [blame] | 2246 | surface_clear_next_states(shsurf); |
Philip Withnall | becb77e | 2013-11-25 18:01:30 +0000 | [diff] [blame] | 2247 | set_fullscreen(shsurf, method, framerate, output); |
| 2248 | } |
| 2249 | |
| 2250 | static void |
| 2251 | set_popup(struct shell_surface *shsurf, |
| 2252 | struct weston_surface *parent, |
| 2253 | struct weston_seat *seat, |
| 2254 | uint32_t serial, |
| 2255 | int32_t x, |
| 2256 | int32_t y) |
| 2257 | { |
Philip Withnall | dc4332f | 2013-11-25 18:01:38 +0000 | [diff] [blame] | 2258 | assert(parent != NULL); |
| 2259 | |
Philip Withnall | becb77e | 2013-11-25 18:01:30 +0000 | [diff] [blame] | 2260 | shsurf->popup.shseat = get_shell_seat(seat); |
| 2261 | shsurf->popup.serial = serial; |
| 2262 | shsurf->popup.x = x; |
| 2263 | shsurf->popup.y = y; |
Philip Withnall | dc4332f | 2013-11-25 18:01:38 +0000 | [diff] [blame] | 2264 | |
Kristian Høgsberg | c8f8dd8 | 2013-12-05 23:20:33 -0800 | [diff] [blame] | 2265 | shsurf->type = SHELL_SURFACE_POPUP; |
Philip Withnall | becb77e | 2013-11-25 18:01:30 +0000 | [diff] [blame] | 2266 | } |
| 2267 | |
| 2268 | static void |
| 2269 | shell_surface_set_popup(struct wl_client *client, |
| 2270 | struct wl_resource *resource, |
| 2271 | struct wl_resource *seat_resource, |
| 2272 | uint32_t serial, |
| 2273 | struct wl_resource *parent_resource, |
| 2274 | int32_t x, int32_t y, uint32_t flags) |
| 2275 | { |
| 2276 | struct shell_surface *shsurf = wl_resource_get_user_data(resource); |
Rafael Antognolli | 4b99a40 | 2013-12-03 15:35:44 -0200 | [diff] [blame] | 2277 | struct weston_surface *parent = |
| 2278 | wl_resource_get_user_data(parent_resource); |
| 2279 | |
| 2280 | shell_surface_set_parent(shsurf, parent); |
Philip Withnall | becb77e | 2013-11-25 18:01:30 +0000 | [diff] [blame] | 2281 | |
Rafael Antognolli | 03b1659 | 2013-12-03 15:35:42 -0200 | [diff] [blame] | 2282 | surface_clear_next_states(shsurf); |
Philip Withnall | becb77e | 2013-11-25 18:01:30 +0000 | [diff] [blame] | 2283 | set_popup(shsurf, |
Rafael Antognolli | 4b99a40 | 2013-12-03 15:35:44 -0200 | [diff] [blame] | 2284 | parent, |
Philip Withnall | becb77e | 2013-11-25 18:01:30 +0000 | [diff] [blame] | 2285 | wl_resource_get_user_data(seat_resource), |
| 2286 | serial, x, y); |
| 2287 | } |
| 2288 | |
| 2289 | static void |
| 2290 | set_maximized(struct shell_surface *shsurf, |
| 2291 | struct weston_output *output) |
| 2292 | { |
| 2293 | struct desktop_shell *shell; |
| 2294 | uint32_t edges = 0, panel_height = 0; |
Philip Withnall | becb77e | 2013-11-25 18:01:30 +0000 | [diff] [blame] | 2295 | |
Philip Withnall | 352e7ed | 2013-11-25 18:01:35 +0000 | [diff] [blame] | 2296 | shell_surface_set_output(shsurf, output); |
Philip Withnall | becb77e | 2013-11-25 18:01:30 +0000 | [diff] [blame] | 2297 | |
| 2298 | shell = shell_surface_get_shell(shsurf); |
| 2299 | panel_height = get_output_panel_height(shell, shsurf->output); |
| 2300 | edges = WL_SHELL_SURFACE_RESIZE_TOP | WL_SHELL_SURFACE_RESIZE_LEFT; |
| 2301 | |
| 2302 | shsurf->client->send_configure(shsurf->surface, edges, |
| 2303 | shsurf->output->width, |
| 2304 | shsurf->output->height - panel_height); |
| 2305 | |
Kristian Høgsberg | c2745b1 | 2013-12-05 22:00:40 -0800 | [diff] [blame] | 2306 | shsurf->next_state.maximized = true; |
| 2307 | shsurf->state_changed = true; |
Kristian Høgsberg | c8f8dd8 | 2013-12-05 23:20:33 -0800 | [diff] [blame] | 2308 | shsurf->type = SHELL_SURFACE_TOPLEVEL; |
Philip Withnall | becb77e | 2013-11-25 18:01:30 +0000 | [diff] [blame] | 2309 | } |
| 2310 | |
| 2311 | static void |
| 2312 | unset_maximized(struct shell_surface *shsurf) |
Rafal Mielniczuk | fffdcdd | 2013-03-11 19:26:54 +0100 | [diff] [blame] | 2313 | { |
Rafal Mielniczuk | fffdcdd | 2013-03-11 19:26:54 +0100 | [diff] [blame] | 2314 | /* undo all maximized things here */ |
| 2315 | shsurf->output = get_default_output(shsurf->surface->compositor); |
Zhang, Xiong Y | 3123693 | 2013-12-13 22:10:57 +0200 | [diff] [blame] | 2316 | |
| 2317 | if (shsurf->saved_position_valid) |
| 2318 | weston_view_set_position(shsurf->view, |
| 2319 | shsurf->saved_x, shsurf->saved_y); |
| 2320 | else |
| 2321 | weston_view_set_initial_position(shsurf->view, shsurf->shell); |
Rafal Mielniczuk | fffdcdd | 2013-03-11 19:26:54 +0100 | [diff] [blame] | 2322 | |
| 2323 | if (shsurf->saved_rotation_valid) { |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 2324 | wl_list_insert(&shsurf->view->geometry.transformation_list, |
| 2325 | &shsurf->rotation.transform.link); |
Rafal Mielniczuk | fffdcdd | 2013-03-11 19:26:54 +0100 | [diff] [blame] | 2326 | shsurf->saved_rotation_valid = false; |
| 2327 | } |
| 2328 | |
Philip Withnall | e1d75ae | 2013-11-25 18:01:41 +0000 | [diff] [blame] | 2329 | /* Layer is updated in set_surface_type(). */ |
Rafal Mielniczuk | fffdcdd | 2013-03-11 19:26:54 +0100 | [diff] [blame] | 2330 | } |
| 2331 | |
Philip Withnall | becb77e | 2013-11-25 18:01:30 +0000 | [diff] [blame] | 2332 | static void |
| 2333 | shell_surface_set_maximized(struct wl_client *client, |
| 2334 | struct wl_resource *resource, |
| 2335 | struct wl_resource *output_resource) |
| 2336 | { |
| 2337 | struct shell_surface *shsurf = wl_resource_get_user_data(resource); |
| 2338 | struct weston_output *output; |
| 2339 | |
| 2340 | if (output_resource) |
| 2341 | output = wl_resource_get_user_data(output_resource); |
| 2342 | else |
| 2343 | output = NULL; |
| 2344 | |
Rafael Antognolli | 4b99a40 | 2013-12-03 15:35:44 -0200 | [diff] [blame] | 2345 | shell_surface_set_parent(shsurf, NULL); |
| 2346 | |
Rafael Antognolli | 03b1659 | 2013-12-03 15:35:42 -0200 | [diff] [blame] | 2347 | surface_clear_next_states(shsurf); |
Philip Withnall | becb77e | 2013-11-25 18:01:30 +0000 | [diff] [blame] | 2348 | set_maximized(shsurf, output); |
| 2349 | } |
| 2350 | |
Philip Withnall | e1d75ae | 2013-11-25 18:01:41 +0000 | [diff] [blame] | 2351 | /* This is only ever called from set_surface_type(), so there’s no need to |
| 2352 | * update layer_links here, since they’ll be updated when we return. */ |
Pekka Paalanen | 9826223 | 2011-12-01 10:42:22 +0200 | [diff] [blame] | 2353 | static int |
Philip Withnall | becb77e | 2013-11-25 18:01:30 +0000 | [diff] [blame] | 2354 | reset_surface_type(struct shell_surface *surface) |
Pekka Paalanen | 9826223 | 2011-12-01 10:42:22 +0200 | [diff] [blame] | 2355 | { |
Rafael Antognolli | 03b1659 | 2013-12-03 15:35:42 -0200 | [diff] [blame] | 2356 | if (surface->state.fullscreen) |
Philip Withnall | becb77e | 2013-11-25 18:01:30 +0000 | [diff] [blame] | 2357 | unset_fullscreen(surface); |
Rafael Antognolli | 03b1659 | 2013-12-03 15:35:42 -0200 | [diff] [blame] | 2358 | if (surface->state.maximized) |
Philip Withnall | becb77e | 2013-11-25 18:01:30 +0000 | [diff] [blame] | 2359 | unset_maximized(surface); |
Pekka Paalanen | 9826223 | 2011-12-01 10:42:22 +0200 | [diff] [blame] | 2360 | |
Pekka Paalanen | 9826223 | 2011-12-01 10:42:22 +0200 | [diff] [blame] | 2361 | return 0; |
| 2362 | } |
| 2363 | |
Kristian Høgsberg | 4cca349 | 2011-01-18 07:53:49 -0500 | [diff] [blame] | 2364 | static void |
Rafael Antognolli | 03b1659 | 2013-12-03 15:35:42 -0200 | [diff] [blame] | 2365 | set_full_output(struct shell_surface *shsurf) |
| 2366 | { |
| 2367 | shsurf->saved_x = shsurf->view->geometry.x; |
| 2368 | shsurf->saved_y = shsurf->view->geometry.y; |
Rafael Antognolli | 3c4e3f7 | 2013-12-03 15:35:46 -0200 | [diff] [blame] | 2369 | shsurf->saved_width = shsurf->surface->width; |
| 2370 | shsurf->saved_height = shsurf->surface->height; |
| 2371 | shsurf->saved_size_valid = true; |
Rafael Antognolli | 03b1659 | 2013-12-03 15:35:42 -0200 | [diff] [blame] | 2372 | shsurf->saved_position_valid = true; |
| 2373 | |
| 2374 | if (!wl_list_empty(&shsurf->rotation.transform.link)) { |
| 2375 | wl_list_remove(&shsurf->rotation.transform.link); |
| 2376 | wl_list_init(&shsurf->rotation.transform.link); |
| 2377 | weston_view_geometry_dirty(shsurf->view); |
| 2378 | shsurf->saved_rotation_valid = true; |
| 2379 | } |
| 2380 | } |
| 2381 | |
| 2382 | static void |
Kristian Høgsberg | 7f366e7 | 2012-04-27 17:20:01 -0400 | [diff] [blame] | 2383 | set_surface_type(struct shell_surface *shsurf) |
| 2384 | { |
Kristian Høgsberg | 8150b19 | 2012-06-27 10:22:58 -0400 | [diff] [blame] | 2385 | struct weston_surface *pes = shsurf->parent; |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 2386 | struct weston_view *pev = get_default_view(pes); |
Kristian Høgsberg | 7f366e7 | 2012-04-27 17:20:01 -0400 | [diff] [blame] | 2387 | |
Philip Withnall | becb77e | 2013-11-25 18:01:30 +0000 | [diff] [blame] | 2388 | reset_surface_type(shsurf); |
Kristian Høgsberg | 7f366e7 | 2012-04-27 17:20:01 -0400 | [diff] [blame] | 2389 | |
Rafael Antognolli | 03b1659 | 2013-12-03 15:35:42 -0200 | [diff] [blame] | 2390 | shsurf->state = shsurf->next_state; |
Rafael Antognolli | 03b1659 | 2013-12-03 15:35:42 -0200 | [diff] [blame] | 2391 | shsurf->state_changed = false; |
Kristian Høgsberg | 7f366e7 | 2012-04-27 17:20:01 -0400 | [diff] [blame] | 2392 | |
| 2393 | switch (shsurf->type) { |
| 2394 | case SHELL_SURFACE_TOPLEVEL: |
Rafael Antognolli | ed207b4 | 2013-12-03 15:35:43 -0200 | [diff] [blame] | 2395 | if (shsurf->state.maximized || shsurf->state.fullscreen) { |
Rafael Antognolli | 03b1659 | 2013-12-03 15:35:42 -0200 | [diff] [blame] | 2396 | set_full_output(shsurf); |
Rafael Antognolli | ed207b4 | 2013-12-03 15:35:43 -0200 | [diff] [blame] | 2397 | } else if (shsurf->state.relative && pev) { |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 2398 | weston_view_set_position(shsurf->view, |
| 2399 | pev->geometry.x + shsurf->transient.x, |
| 2400 | pev->geometry.y + shsurf->transient.y); |
Rafael Antognolli | ed207b4 | 2013-12-03 15:35:43 -0200 | [diff] [blame] | 2401 | } |
Rafael Antognolli | 44a3162 | 2013-12-04 18:37:16 -0200 | [diff] [blame] | 2402 | break; |
Kristian Høgsberg | 7f366e7 | 2012-04-27 17:20:01 -0400 | [diff] [blame] | 2403 | |
Tiago Vignatti | fb2adba | 2013-06-12 15:43:21 -0300 | [diff] [blame] | 2404 | case SHELL_SURFACE_XWAYLAND: |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 2405 | weston_view_set_position(shsurf->view, shsurf->transient.x, |
| 2406 | shsurf->transient.y); |
Tiago Vignatti | fb2adba | 2013-06-12 15:43:21 -0300 | [diff] [blame] | 2407 | break; |
| 2408 | |
Philip Withnall | 0f640e2 | 2013-11-25 18:01:31 +0000 | [diff] [blame] | 2409 | case SHELL_SURFACE_POPUP: |
| 2410 | case SHELL_SURFACE_NONE: |
Kristian Høgsberg | 7f366e7 | 2012-04-27 17:20:01 -0400 | [diff] [blame] | 2411 | default: |
| 2412 | break; |
| 2413 | } |
Philip Withnall | e1d75ae | 2013-11-25 18:01:41 +0000 | [diff] [blame] | 2414 | |
| 2415 | /* Update the surface’s layer. */ |
| 2416 | shell_surface_update_layer(shsurf); |
Kristian Høgsberg | 7f366e7 | 2012-04-27 17:20:01 -0400 | [diff] [blame] | 2417 | } |
| 2418 | |
Tiago Vignatti | be14326 | 2012-04-16 17:31:41 +0300 | [diff] [blame] | 2419 | static struct desktop_shell * |
Juan Zhao | 96879df | 2012-02-07 08:45:41 +0800 | [diff] [blame] | 2420 | shell_surface_get_shell(struct shell_surface *shsurf) |
Pekka Paalanen | af0e34c | 2011-12-02 10:59:17 +0200 | [diff] [blame] | 2421 | { |
Kristian Høgsberg | 02e79dc | 2012-04-12 09:55:26 -0400 | [diff] [blame] | 2422 | return shsurf->shell; |
Juan Zhao | 96879df | 2012-02-07 08:45:41 +0800 | [diff] [blame] | 2423 | } |
| 2424 | |
Alex Wu | 2185843 | 2012-04-01 20:13:08 +0800 | [diff] [blame] | 2425 | static void |
Jason Ekstrand | 918f2dd | 2013-12-02 21:01:53 -0600 | [diff] [blame] | 2426 | 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] | 2427 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 2428 | static struct weston_view * |
Alex Wu | 4539b08 | 2012-03-01 12:57:46 +0800 | [diff] [blame] | 2429 | create_black_surface(struct weston_compositor *ec, |
Alex Wu | 2185843 | 2012-04-01 20:13:08 +0800 | [diff] [blame] | 2430 | struct weston_surface *fs_surface, |
John Kåre Alsaker | 490d02a | 2012-09-30 02:57:21 +0200 | [diff] [blame] | 2431 | float x, float y, int w, int h) |
Alex Wu | 4539b08 | 2012-03-01 12:57:46 +0800 | [diff] [blame] | 2432 | { |
| 2433 | struct weston_surface *surface = NULL; |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 2434 | struct weston_view *view; |
Alex Wu | 4539b08 | 2012-03-01 12:57:46 +0800 | [diff] [blame] | 2435 | |
| 2436 | surface = weston_surface_create(ec); |
| 2437 | if (surface == NULL) { |
Martin Minarik | 6d11836 | 2012-06-07 18:01:59 +0200 | [diff] [blame] | 2438 | weston_log("no memory\n"); |
Alex Wu | 4539b08 | 2012-03-01 12:57:46 +0800 | [diff] [blame] | 2439 | return NULL; |
| 2440 | } |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 2441 | view = weston_view_create(surface); |
| 2442 | if (surface == NULL) { |
| 2443 | weston_log("no memory\n"); |
| 2444 | weston_surface_destroy(surface); |
| 2445 | return NULL; |
| 2446 | } |
Alex Wu | 4539b08 | 2012-03-01 12:57:46 +0800 | [diff] [blame] | 2447 | |
Alex Wu | 2185843 | 2012-04-01 20:13:08 +0800 | [diff] [blame] | 2448 | surface->configure = black_surface_configure; |
Giulio Camuffo | 7fe01b1 | 2013-03-28 18:02:42 +0100 | [diff] [blame] | 2449 | surface->configure_private = fs_surface; |
Alex Wu | 4539b08 | 2012-03-01 12:57:46 +0800 | [diff] [blame] | 2450 | weston_surface_set_color(surface, 0.0, 0.0, 0.0, 1); |
Pekka Paalanen | 71f6f3b | 2012-10-10 12:49:26 +0300 | [diff] [blame] | 2451 | pixman_region32_fini(&surface->opaque); |
Kristian Høgsberg | 61f00f5 | 2012-08-03 16:31:36 -0400 | [diff] [blame] | 2452 | pixman_region32_init_rect(&surface->opaque, 0, 0, w, h); |
Jonas Ådahl | 33619a4 | 2013-01-15 21:25:55 +0100 | [diff] [blame] | 2453 | pixman_region32_fini(&surface->input); |
| 2454 | pixman_region32_init_rect(&surface->input, 0, 0, w, h); |
Jason Ekstrand | 918f2dd | 2013-12-02 21:01:53 -0600 | [diff] [blame] | 2455 | |
Jason Ekstrand | 6228ee2 | 2014-01-01 15:58:57 -0600 | [diff] [blame] | 2456 | weston_surface_set_size(surface, w, h); |
Jason Ekstrand | 918f2dd | 2013-12-02 21:01:53 -0600 | [diff] [blame] | 2457 | weston_view_set_position(view, x, y); |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 2458 | |
| 2459 | return view; |
Alex Wu | 4539b08 | 2012-03-01 12:57:46 +0800 | [diff] [blame] | 2460 | } |
| 2461 | |
Philip Withnall | ed8f1a9 | 2013-11-25 18:01:43 +0000 | [diff] [blame] | 2462 | static void |
| 2463 | shell_ensure_fullscreen_black_view(struct shell_surface *shsurf) |
| 2464 | { |
| 2465 | struct weston_output *output = shsurf->fullscreen_output; |
| 2466 | |
Rafael Antognolli | 03b1659 | 2013-12-03 15:35:42 -0200 | [diff] [blame] | 2467 | assert(shsurf->state.fullscreen); |
Philip Withnall | ed8f1a9 | 2013-11-25 18:01:43 +0000 | [diff] [blame] | 2468 | |
| 2469 | if (!shsurf->fullscreen.black_view) |
| 2470 | shsurf->fullscreen.black_view = |
| 2471 | create_black_surface(shsurf->surface->compositor, |
| 2472 | shsurf->surface, |
| 2473 | output->x, output->y, |
| 2474 | output->width, |
| 2475 | output->height); |
| 2476 | |
| 2477 | weston_view_geometry_dirty(shsurf->fullscreen.black_view); |
| 2478 | wl_list_remove(&shsurf->fullscreen.black_view->layer_link); |
| 2479 | wl_list_insert(&shsurf->view->layer_link, |
| 2480 | &shsurf->fullscreen.black_view->layer_link); |
| 2481 | weston_view_geometry_dirty(shsurf->fullscreen.black_view); |
| 2482 | weston_surface_damage(shsurf->surface); |
| 2483 | } |
| 2484 | |
Alex Wu | 4539b08 | 2012-03-01 12:57:46 +0800 | [diff] [blame] | 2485 | /* Create black surface and append it to the associated fullscreen surface. |
| 2486 | * Handle size dismatch and positioning according to the method. */ |
| 2487 | static void |
| 2488 | shell_configure_fullscreen(struct shell_surface *shsurf) |
| 2489 | { |
| 2490 | struct weston_output *output = shsurf->fullscreen_output; |
| 2491 | struct weston_surface *surface = shsurf->surface; |
| 2492 | struct weston_matrix *matrix; |
Kristian Høgsberg | 240dfeb | 2012-07-12 12:32:31 -0400 | [diff] [blame] | 2493 | float scale, output_aspect, surface_aspect, x, y; |
Giulio Camuffo | b836664 | 2013-04-25 13:57:46 +0300 | [diff] [blame] | 2494 | int32_t surf_x, surf_y, surf_width, surf_height; |
Alex Wu | 4539b08 | 2012-03-01 12:57:46 +0800 | [diff] [blame] | 2495 | |
Alexander Larsson | f82b6ca | 2013-05-28 16:23:39 +0200 | [diff] [blame] | 2496 | if (shsurf->fullscreen.type != WL_SHELL_SURFACE_FULLSCREEN_METHOD_DRIVER) |
| 2497 | restore_output_mode(output); |
| 2498 | |
Philip Withnall | ed8f1a9 | 2013-11-25 18:01:43 +0000 | [diff] [blame] | 2499 | shell_ensure_fullscreen_black_view(shsurf); |
Alex Wu | 4539b08 | 2012-03-01 12:57:46 +0800 | [diff] [blame] | 2500 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 2501 | surface_subsurfaces_boundingbox(shsurf->surface, &surf_x, &surf_y, |
Giulio Camuffo | b836664 | 2013-04-25 13:57:46 +0300 | [diff] [blame] | 2502 | &surf_width, &surf_height); |
| 2503 | |
Alex Wu | 4539b08 | 2012-03-01 12:57:46 +0800 | [diff] [blame] | 2504 | switch (shsurf->fullscreen.type) { |
| 2505 | case WL_SHELL_SURFACE_FULLSCREEN_METHOD_DEFAULT: |
Pekka Paalanen | de685b8 | 2012-12-04 15:58:12 +0200 | [diff] [blame] | 2506 | if (surface->buffer_ref.buffer) |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 2507 | center_on_output(shsurf->view, shsurf->fullscreen_output); |
Alex Wu | 4539b08 | 2012-03-01 12:57:46 +0800 | [diff] [blame] | 2508 | break; |
| 2509 | case WL_SHELL_SURFACE_FULLSCREEN_METHOD_SCALE: |
Rob Bradford | 9f3dd15 | 2013-02-12 11:53:47 +0000 | [diff] [blame] | 2510 | /* 1:1 mapping between surface and output dimensions */ |
Giulio Camuffo | b836664 | 2013-04-25 13:57:46 +0300 | [diff] [blame] | 2511 | if (output->width == surf_width && |
| 2512 | output->height == surf_height) { |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 2513 | weston_view_set_position(shsurf->view, |
| 2514 | output->x - surf_x, |
| 2515 | output->y - surf_y); |
Rob Bradford | 9f3dd15 | 2013-02-12 11:53:47 +0000 | [diff] [blame] | 2516 | break; |
| 2517 | } |
| 2518 | |
Alex Wu | 4539b08 | 2012-03-01 12:57:46 +0800 | [diff] [blame] | 2519 | matrix = &shsurf->fullscreen.transform.matrix; |
| 2520 | weston_matrix_init(matrix); |
Kristian Høgsberg | 240dfeb | 2012-07-12 12:32:31 -0400 | [diff] [blame] | 2521 | |
Scott Moreau | 1bad5db | 2012-08-18 01:04:05 -0600 | [diff] [blame] | 2522 | output_aspect = (float) output->width / |
| 2523 | (float) output->height; |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 2524 | /* XXX: Use surf_width and surf_height here? */ |
| 2525 | surface_aspect = (float) surface->width / |
| 2526 | (float) surface->height; |
Kristian Høgsberg | 240dfeb | 2012-07-12 12:32:31 -0400 | [diff] [blame] | 2527 | if (output_aspect < surface_aspect) |
Scott Moreau | 1bad5db | 2012-08-18 01:04:05 -0600 | [diff] [blame] | 2528 | scale = (float) output->width / |
Giulio Camuffo | b836664 | 2013-04-25 13:57:46 +0300 | [diff] [blame] | 2529 | (float) surf_width; |
Kristian Høgsberg | 240dfeb | 2012-07-12 12:32:31 -0400 | [diff] [blame] | 2530 | else |
Scott Moreau | 1bad5db | 2012-08-18 01:04:05 -0600 | [diff] [blame] | 2531 | scale = (float) output->height / |
Giulio Camuffo | b836664 | 2013-04-25 13:57:46 +0300 | [diff] [blame] | 2532 | (float) surf_height; |
Kristian Høgsberg | 240dfeb | 2012-07-12 12:32:31 -0400 | [diff] [blame] | 2533 | |
Alex Wu | 4539b08 | 2012-03-01 12:57:46 +0800 | [diff] [blame] | 2534 | weston_matrix_scale(matrix, scale, scale, 1); |
| 2535 | wl_list_remove(&shsurf->fullscreen.transform.link); |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 2536 | wl_list_insert(&shsurf->view->geometry.transformation_list, |
Alex Wu | 4539b08 | 2012-03-01 12:57:46 +0800 | [diff] [blame] | 2537 | &shsurf->fullscreen.transform.link); |
Giulio Camuffo | b836664 | 2013-04-25 13:57:46 +0300 | [diff] [blame] | 2538 | x = output->x + (output->width - surf_width * scale) / 2 - surf_x; |
| 2539 | y = output->y + (output->height - surf_height * scale) / 2 - surf_y; |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 2540 | weston_view_set_position(shsurf->view, x, y); |
Kristian Høgsberg | 240dfeb | 2012-07-12 12:32:31 -0400 | [diff] [blame] | 2541 | |
Alex Wu | 4539b08 | 2012-03-01 12:57:46 +0800 | [diff] [blame] | 2542 | break; |
| 2543 | case WL_SHELL_SURFACE_FULLSCREEN_METHOD_DRIVER: |
Alex Wu | bd3354b | 2012-04-17 17:20:49 +0800 | [diff] [blame] | 2544 | if (shell_surface_is_top_fullscreen(shsurf)) { |
Quentin Glidic | c0d79ce | 2013-01-29 14:16:13 +0100 | [diff] [blame] | 2545 | struct weston_mode mode = {0, |
Pekka Paalanen | 1fd9c0f | 2013-11-26 18:19:41 +0100 | [diff] [blame] | 2546 | surf_width * surface->buffer_viewport.scale, |
| 2547 | surf_height * surface->buffer_viewport.scale, |
Alex Wu | bd3354b | 2012-04-17 17:20:49 +0800 | [diff] [blame] | 2548 | shsurf->fullscreen.framerate}; |
| 2549 | |
Pekka Paalanen | 1fd9c0f | 2013-11-26 18:19:41 +0100 | [diff] [blame] | 2550 | if (weston_output_switch_mode(output, &mode, surface->buffer_viewport.scale, |
Hardening | 57388e4 | 2013-09-18 23:56:36 +0200 | [diff] [blame] | 2551 | WESTON_MODE_SWITCH_SET_TEMPORARY) == 0) { |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 2552 | weston_view_set_position(shsurf->view, |
| 2553 | output->x - surf_x, |
| 2554 | output->y - surf_y); |
Jason Ekstrand | 918f2dd | 2013-12-02 21:01:53 -0600 | [diff] [blame] | 2555 | shsurf->fullscreen.black_view->surface->width = output->width; |
| 2556 | shsurf->fullscreen.black_view->surface->height = output->height; |
| 2557 | weston_view_set_position(shsurf->fullscreen.black_view, |
| 2558 | output->x - surf_x, |
| 2559 | output->y - surf_y); |
Alex Wu | bd3354b | 2012-04-17 17:20:49 +0800 | [diff] [blame] | 2560 | break; |
Alexander Larsson | d622ed3 | 2013-05-28 16:23:40 +0200 | [diff] [blame] | 2561 | } else { |
Alexander Larsson | f82b6ca | 2013-05-28 16:23:39 +0200 | [diff] [blame] | 2562 | restore_output_mode(output); |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 2563 | center_on_output(shsurf->view, output); |
Alexander Larsson | d622ed3 | 2013-05-28 16:23:40 +0200 | [diff] [blame] | 2564 | } |
Alex Wu | bd3354b | 2012-04-17 17:20:49 +0800 | [diff] [blame] | 2565 | } |
Alex Wu | 4539b08 | 2012-03-01 12:57:46 +0800 | [diff] [blame] | 2566 | break; |
| 2567 | case WL_SHELL_SURFACE_FULLSCREEN_METHOD_FILL: |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 2568 | center_on_output(shsurf->view, output); |
Alex Wu | 4539b08 | 2012-03-01 12:57:46 +0800 | [diff] [blame] | 2569 | break; |
| 2570 | default: |
| 2571 | break; |
| 2572 | } |
| 2573 | } |
| 2574 | |
Alex Wu | 4539b08 | 2012-03-01 12:57:46 +0800 | [diff] [blame] | 2575 | static void |
| 2576 | shell_map_fullscreen(struct shell_surface *shsurf) |
| 2577 | { |
Alex Wu | bd3354b | 2012-04-17 17:20:49 +0800 | [diff] [blame] | 2578 | shell_configure_fullscreen(shsurf); |
Alex Wu | 4539b08 | 2012-03-01 12:57:46 +0800 | [diff] [blame] | 2579 | } |
| 2580 | |
Kristian Høgsberg | 7a5c979 | 2011-06-18 06:12:54 -0400 | [diff] [blame] | 2581 | static void |
Tiago Vignatti | fb2adba | 2013-06-12 15:43:21 -0300 | [diff] [blame] | 2582 | set_xwayland(struct shell_surface *shsurf, int x, int y, uint32_t flags) |
| 2583 | { |
| 2584 | /* XXX: using the same fields for transient type */ |
Rafael Antognolli | 03b1659 | 2013-12-03 15:35:42 -0200 | [diff] [blame] | 2585 | surface_clear_next_states(shsurf); |
Tiago Vignatti | fb2adba | 2013-06-12 15:43:21 -0300 | [diff] [blame] | 2586 | shsurf->transient.x = x; |
| 2587 | shsurf->transient.y = y; |
| 2588 | shsurf->transient.flags = flags; |
Philip Withnall | dc4332f | 2013-11-25 18:01:38 +0000 | [diff] [blame] | 2589 | |
| 2590 | shell_surface_set_parent(shsurf, NULL); |
| 2591 | |
Kristian Høgsberg | c8f8dd8 | 2013-12-05 23:20:33 -0800 | [diff] [blame] | 2592 | shsurf->type = SHELL_SURFACE_XWAYLAND; |
Kristian Høgsberg | 8bc525c | 2014-01-01 22:34:49 -0800 | [diff] [blame] | 2593 | shsurf->state_changed = true; |
Tiago Vignatti | fb2adba | 2013-06-12 15:43:21 -0300 | [diff] [blame] | 2594 | } |
| 2595 | |
Kristian Høgsberg | 02bbabb | 2013-05-06 22:15:05 -0400 | [diff] [blame] | 2596 | static const struct weston_pointer_grab_interface popup_grab_interface; |
Giulio Camuffo | 5085a75 | 2013-03-25 21:42:45 +0100 | [diff] [blame] | 2597 | |
| 2598 | static void |
| 2599 | destroy_shell_seat(struct wl_listener *listener, void *data) |
| 2600 | { |
| 2601 | struct shell_seat *shseat = |
| 2602 | container_of(listener, |
| 2603 | struct shell_seat, seat_destroy_listener); |
| 2604 | struct shell_surface *shsurf, *prev = NULL; |
| 2605 | |
| 2606 | if (shseat->popup_grab.grab.interface == &popup_grab_interface) { |
Kristian Høgsberg | 02bbabb | 2013-05-06 22:15:05 -0400 | [diff] [blame] | 2607 | weston_pointer_end_grab(shseat->popup_grab.grab.pointer); |
Giulio Camuffo | 5085a75 | 2013-03-25 21:42:45 +0100 | [diff] [blame] | 2608 | shseat->popup_grab.client = NULL; |
| 2609 | |
| 2610 | wl_list_for_each(shsurf, &shseat->popup_grab.surfaces_list, popup.grab_link) { |
| 2611 | shsurf->popup.shseat = NULL; |
| 2612 | if (prev) { |
| 2613 | wl_list_init(&prev->popup.grab_link); |
| 2614 | } |
| 2615 | prev = shsurf; |
| 2616 | } |
| 2617 | wl_list_init(&prev->popup.grab_link); |
| 2618 | } |
| 2619 | |
| 2620 | wl_list_remove(&shseat->seat_destroy_listener.link); |
| 2621 | free(shseat); |
| 2622 | } |
| 2623 | |
| 2624 | static struct shell_seat * |
| 2625 | create_shell_seat(struct weston_seat *seat) |
| 2626 | { |
| 2627 | struct shell_seat *shseat; |
| 2628 | |
| 2629 | shseat = calloc(1, sizeof *shseat); |
| 2630 | if (!shseat) { |
| 2631 | weston_log("no memory to allocate shell seat\n"); |
| 2632 | return NULL; |
| 2633 | } |
| 2634 | |
| 2635 | shseat->seat = seat; |
| 2636 | wl_list_init(&shseat->popup_grab.surfaces_list); |
| 2637 | |
| 2638 | shseat->seat_destroy_listener.notify = destroy_shell_seat; |
| 2639 | wl_signal_add(&seat->destroy_signal, |
| 2640 | &shseat->seat_destroy_listener); |
| 2641 | |
| 2642 | return shseat; |
| 2643 | } |
| 2644 | |
| 2645 | static struct shell_seat * |
| 2646 | get_shell_seat(struct weston_seat *seat) |
| 2647 | { |
| 2648 | struct wl_listener *listener; |
| 2649 | |
| 2650 | listener = wl_signal_get(&seat->destroy_signal, destroy_shell_seat); |
| 2651 | if (listener == NULL) |
| 2652 | return create_shell_seat(seat); |
| 2653 | |
| 2654 | return container_of(listener, |
| 2655 | struct shell_seat, seat_destroy_listener); |
| 2656 | } |
| 2657 | |
Kristian Høgsberg | b810eb5 | 2013-02-12 20:07:05 -0500 | [diff] [blame] | 2658 | static void |
Kristian Høgsberg | 6848c25 | 2013-05-08 22:02:59 -0400 | [diff] [blame] | 2659 | popup_grab_focus(struct weston_pointer_grab *grab) |
Kristian Høgsberg | b3cca0a | 2012-01-04 22:19:14 -0500 | [diff] [blame] | 2660 | { |
Kristian Høgsberg | 02bbabb | 2013-05-06 22:15:05 -0400 | [diff] [blame] | 2661 | struct weston_pointer *pointer = grab->pointer; |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 2662 | struct weston_view *view; |
Giulio Camuffo | 5085a75 | 2013-03-25 21:42:45 +0100 | [diff] [blame] | 2663 | struct shell_seat *shseat = |
| 2664 | container_of(grab, struct shell_seat, popup_grab.grab); |
| 2665 | struct wl_client *client = shseat->popup_grab.client; |
Kristian Høgsberg | 6848c25 | 2013-05-08 22:02:59 -0400 | [diff] [blame] | 2666 | wl_fixed_t sx, sy; |
| 2667 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 2668 | view = weston_compositor_pick_view(pointer->seat->compositor, |
| 2669 | pointer->x, pointer->y, |
| 2670 | &sx, &sy); |
Kristian Høgsberg | b3cca0a | 2012-01-04 22:19:14 -0500 | [diff] [blame] | 2671 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 2672 | if (view && view->surface->resource && |
| 2673 | wl_resource_get_client(view->surface->resource) == client) { |
| 2674 | weston_pointer_set_focus(pointer, view, sx, sy); |
Kristian Høgsberg | b3cca0a | 2012-01-04 22:19:14 -0500 | [diff] [blame] | 2675 | } else { |
Kristian Høgsberg | 02bbabb | 2013-05-06 22:15:05 -0400 | [diff] [blame] | 2676 | weston_pointer_set_focus(pointer, NULL, |
| 2677 | wl_fixed_from_int(0), |
| 2678 | wl_fixed_from_int(0)); |
Kristian Høgsberg | b3cca0a | 2012-01-04 22:19:14 -0500 | [diff] [blame] | 2679 | } |
| 2680 | } |
| 2681 | |
| 2682 | static void |
Giulio Camuffo | 1959ab8 | 2013-11-14 23:42:52 +0100 | [diff] [blame] | 2683 | popup_grab_motion(struct weston_pointer_grab *grab, uint32_t time, |
| 2684 | wl_fixed_t x, wl_fixed_t y) |
Kristian Høgsberg | b3cca0a | 2012-01-04 22:19:14 -0500 | [diff] [blame] | 2685 | { |
Kristian Høgsberg | be6403e | 2013-05-08 21:03:21 -0400 | [diff] [blame] | 2686 | struct weston_pointer *pointer = grab->pointer; |
Neil Roberts | 96d790e | 2013-09-19 17:32:00 +0100 | [diff] [blame] | 2687 | struct wl_resource *resource; |
Kristian Høgsberg | be6403e | 2013-05-08 21:03:21 -0400 | [diff] [blame] | 2688 | wl_fixed_t sx, sy; |
Kristian Høgsberg | b3cca0a | 2012-01-04 22:19:14 -0500 | [diff] [blame] | 2689 | |
Giulio Camuffo | 1959ab8 | 2013-11-14 23:42:52 +0100 | [diff] [blame] | 2690 | weston_pointer_move(pointer, x, y); |
| 2691 | |
Neil Roberts | 96d790e | 2013-09-19 17:32:00 +0100 | [diff] [blame] | 2692 | wl_resource_for_each(resource, &pointer->focus_resource_list) { |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 2693 | weston_view_from_global_fixed(pointer->focus, |
| 2694 | pointer->x, pointer->y, |
| 2695 | &sx, &sy); |
Neil Roberts | 96d790e | 2013-09-19 17:32:00 +0100 | [diff] [blame] | 2696 | wl_pointer_send_motion(resource, time, sx, sy); |
Kristian Høgsberg | be6403e | 2013-05-08 21:03:21 -0400 | [diff] [blame] | 2697 | } |
Kristian Høgsberg | b3cca0a | 2012-01-04 22:19:14 -0500 | [diff] [blame] | 2698 | } |
| 2699 | |
| 2700 | static void |
Kristian Høgsberg | 02bbabb | 2013-05-06 22:15:05 -0400 | [diff] [blame] | 2701 | popup_grab_button(struct weston_pointer_grab *grab, |
Daniel Stone | 4dbadb1 | 2012-05-30 16:31:51 +0100 | [diff] [blame] | 2702 | uint32_t time, uint32_t button, uint32_t state_w) |
Kristian Høgsberg | b3cca0a | 2012-01-04 22:19:14 -0500 | [diff] [blame] | 2703 | { |
| 2704 | struct wl_resource *resource; |
Giulio Camuffo | 5085a75 | 2013-03-25 21:42:45 +0100 | [diff] [blame] | 2705 | struct shell_seat *shseat = |
| 2706 | container_of(grab, struct shell_seat, popup_grab.grab); |
Rob Bradford | 880ebc7 | 2013-07-22 17:31:38 +0100 | [diff] [blame] | 2707 | struct wl_display *display = shseat->seat->compositor->wl_display; |
Daniel Stone | 4dbadb1 | 2012-05-30 16:31:51 +0100 | [diff] [blame] | 2708 | enum wl_pointer_button_state state = state_w; |
Kristian Høgsberg | eae5de7 | 2012-04-11 22:42:15 -0400 | [diff] [blame] | 2709 | uint32_t serial; |
Neil Roberts | 96d790e | 2013-09-19 17:32:00 +0100 | [diff] [blame] | 2710 | struct wl_list *resource_list; |
Kristian Høgsberg | b3cca0a | 2012-01-04 22:19:14 -0500 | [diff] [blame] | 2711 | |
Neil Roberts | 96d790e | 2013-09-19 17:32:00 +0100 | [diff] [blame] | 2712 | resource_list = &grab->pointer->focus_resource_list; |
| 2713 | if (!wl_list_empty(resource_list)) { |
Kristian Høgsberg | eae5de7 | 2012-04-11 22:42:15 -0400 | [diff] [blame] | 2714 | serial = wl_display_get_serial(display); |
Neil Roberts | 96d790e | 2013-09-19 17:32:00 +0100 | [diff] [blame] | 2715 | wl_resource_for_each(resource, resource_list) { |
| 2716 | wl_pointer_send_button(resource, serial, |
| 2717 | time, button, state); |
| 2718 | } |
Daniel Stone | 4dbadb1 | 2012-05-30 16:31:51 +0100 | [diff] [blame] | 2719 | } else if (state == WL_POINTER_BUTTON_STATE_RELEASED && |
Giulio Camuffo | 5085a75 | 2013-03-25 21:42:45 +0100 | [diff] [blame] | 2720 | (shseat->popup_grab.initial_up || |
Kristian Høgsberg | e314875 | 2013-05-06 23:19:49 -0400 | [diff] [blame] | 2721 | time - shseat->seat->pointer->grab_time > 500)) { |
Kristian Høgsberg | 57e0907 | 2012-10-30 14:07:27 -0400 | [diff] [blame] | 2722 | popup_grab_end(grab->pointer); |
Kristian Høgsberg | b3cca0a | 2012-01-04 22:19:14 -0500 | [diff] [blame] | 2723 | } |
| 2724 | |
Daniel Stone | 4dbadb1 | 2012-05-30 16:31:51 +0100 | [diff] [blame] | 2725 | if (state == WL_POINTER_BUTTON_STATE_RELEASED) |
Giulio Camuffo | 5085a75 | 2013-03-25 21:42:45 +0100 | [diff] [blame] | 2726 | shseat->popup_grab.initial_up = 1; |
Kristian Høgsberg | b3cca0a | 2012-01-04 22:19:14 -0500 | [diff] [blame] | 2727 | } |
| 2728 | |
Jonas Ådahl | 1ea343e | 2013-10-25 23:18:05 +0200 | [diff] [blame] | 2729 | static void |
| 2730 | popup_grab_cancel(struct weston_pointer_grab *grab) |
| 2731 | { |
| 2732 | popup_grab_end(grab->pointer); |
| 2733 | } |
| 2734 | |
Kristian Høgsberg | 02bbabb | 2013-05-06 22:15:05 -0400 | [diff] [blame] | 2735 | static const struct weston_pointer_grab_interface popup_grab_interface = { |
Kristian Høgsberg | b3cca0a | 2012-01-04 22:19:14 -0500 | [diff] [blame] | 2736 | popup_grab_focus, |
| 2737 | popup_grab_motion, |
| 2738 | popup_grab_button, |
Jonas Ådahl | 1ea343e | 2013-10-25 23:18:05 +0200 | [diff] [blame] | 2739 | popup_grab_cancel, |
Kristian Høgsberg | b3cca0a | 2012-01-04 22:19:14 -0500 | [diff] [blame] | 2740 | }; |
| 2741 | |
| 2742 | static void |
Rafael Antognolli | e2a3455 | 2013-12-03 15:35:45 -0200 | [diff] [blame] | 2743 | shell_surface_send_popup_done(struct shell_surface *shsurf) |
| 2744 | { |
| 2745 | if (shell_surface_is_wl_shell_surface(shsurf)) |
| 2746 | wl_shell_surface_send_popup_done(shsurf->resource); |
| 2747 | else if (shell_surface_is_xdg_popup(shsurf)) |
| 2748 | xdg_popup_send_popup_done(shsurf->resource, |
| 2749 | shsurf->popup.serial); |
| 2750 | } |
| 2751 | |
| 2752 | static void |
Kristian Høgsberg | 02bbabb | 2013-05-06 22:15:05 -0400 | [diff] [blame] | 2753 | popup_grab_end(struct weston_pointer *pointer) |
Kristian Høgsberg | 57e0907 | 2012-10-30 14:07:27 -0400 | [diff] [blame] | 2754 | { |
Kristian Høgsberg | 02bbabb | 2013-05-06 22:15:05 -0400 | [diff] [blame] | 2755 | struct weston_pointer_grab *grab = pointer->grab; |
Giulio Camuffo | 5085a75 | 2013-03-25 21:42:45 +0100 | [diff] [blame] | 2756 | struct shell_seat *shseat = |
| 2757 | container_of(grab, struct shell_seat, popup_grab.grab); |
| 2758 | struct shell_surface *shsurf; |
| 2759 | struct shell_surface *prev = NULL; |
Kristian Høgsberg | 57e0907 | 2012-10-30 14:07:27 -0400 | [diff] [blame] | 2760 | |
| 2761 | if (pointer->grab->interface == &popup_grab_interface) { |
Kristian Høgsberg | 02bbabb | 2013-05-06 22:15:05 -0400 | [diff] [blame] | 2762 | weston_pointer_end_grab(grab->pointer); |
Giulio Camuffo | 5085a75 | 2013-03-25 21:42:45 +0100 | [diff] [blame] | 2763 | shseat->popup_grab.client = NULL; |
Philipp Brüschweiler | 63e7be6 | 2013-04-15 21:09:54 +0200 | [diff] [blame] | 2764 | shseat->popup_grab.grab.interface = NULL; |
| 2765 | assert(!wl_list_empty(&shseat->popup_grab.surfaces_list)); |
Giulio Camuffo | 5085a75 | 2013-03-25 21:42:45 +0100 | [diff] [blame] | 2766 | /* Send the popup_done event to all the popups open */ |
| 2767 | 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] | 2768 | shell_surface_send_popup_done(shsurf); |
Giulio Camuffo | 5085a75 | 2013-03-25 21:42:45 +0100 | [diff] [blame] | 2769 | shsurf->popup.shseat = NULL; |
| 2770 | if (prev) { |
| 2771 | wl_list_init(&prev->popup.grab_link); |
| 2772 | } |
| 2773 | prev = shsurf; |
| 2774 | } |
| 2775 | wl_list_init(&prev->popup.grab_link); |
| 2776 | wl_list_init(&shseat->popup_grab.surfaces_list); |
| 2777 | } |
| 2778 | } |
| 2779 | |
| 2780 | static void |
| 2781 | add_popup_grab(struct shell_surface *shsurf, struct shell_seat *shseat) |
| 2782 | { |
Kristian Høgsberg | e314875 | 2013-05-06 23:19:49 -0400 | [diff] [blame] | 2783 | struct weston_seat *seat = shseat->seat; |
Giulio Camuffo | 5085a75 | 2013-03-25 21:42:45 +0100 | [diff] [blame] | 2784 | |
| 2785 | if (wl_list_empty(&shseat->popup_grab.surfaces_list)) { |
Jason Ekstrand | 651f00e | 2013-06-14 10:07:54 -0500 | [diff] [blame] | 2786 | shseat->popup_grab.client = wl_resource_get_client(shsurf->resource); |
Giulio Camuffo | 5085a75 | 2013-03-25 21:42:45 +0100 | [diff] [blame] | 2787 | shseat->popup_grab.grab.interface = &popup_grab_interface; |
Giulio Camuffo | 1b4b61a | 2013-03-27 18:05:26 +0100 | [diff] [blame] | 2788 | /* We must make sure here that this popup was opened after |
| 2789 | * a mouse press, and not just by moving around with other |
| 2790 | * popups already open. */ |
Kristian Høgsberg | e314875 | 2013-05-06 23:19:49 -0400 | [diff] [blame] | 2791 | if (shseat->seat->pointer->button_count > 0) |
Giulio Camuffo | 1b4b61a | 2013-03-27 18:05:26 +0100 | [diff] [blame] | 2792 | shseat->popup_grab.initial_up = 0; |
Giulio Camuffo | 5085a75 | 2013-03-25 21:42:45 +0100 | [diff] [blame] | 2793 | |
Rob Bradford | dfe3105 | 2013-06-26 19:49:11 +0100 | [diff] [blame] | 2794 | 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] | 2795 | weston_pointer_start_grab(seat->pointer, &shseat->popup_grab.grab); |
Rob Bradford | dfe3105 | 2013-06-26 19:49:11 +0100 | [diff] [blame] | 2796 | } else { |
| 2797 | wl_list_insert(&shseat->popup_grab.surfaces_list, &shsurf->popup.grab_link); |
Giulio Camuffo | 5085a75 | 2013-03-25 21:42:45 +0100 | [diff] [blame] | 2798 | } |
Giulio Camuffo | 5085a75 | 2013-03-25 21:42:45 +0100 | [diff] [blame] | 2799 | } |
| 2800 | |
| 2801 | static void |
| 2802 | remove_popup_grab(struct shell_surface *shsurf) |
| 2803 | { |
| 2804 | struct shell_seat *shseat = shsurf->popup.shseat; |
| 2805 | |
| 2806 | wl_list_remove(&shsurf->popup.grab_link); |
| 2807 | wl_list_init(&shsurf->popup.grab_link); |
| 2808 | if (wl_list_empty(&shseat->popup_grab.surfaces_list)) { |
Kristian Høgsberg | 02bbabb | 2013-05-06 22:15:05 -0400 | [diff] [blame] | 2809 | weston_pointer_end_grab(shseat->popup_grab.grab.pointer); |
Philipp Brüschweiler | 63e7be6 | 2013-04-15 21:09:54 +0200 | [diff] [blame] | 2810 | shseat->popup_grab.grab.interface = NULL; |
Kristian Høgsberg | 57e0907 | 2012-10-30 14:07:27 -0400 | [diff] [blame] | 2811 | } |
| 2812 | } |
| 2813 | |
| 2814 | static void |
Kristian Høgsberg | 3730f36 | 2012-04-13 12:40:07 -0400 | [diff] [blame] | 2815 | shell_map_popup(struct shell_surface *shsurf) |
Kristian Høgsberg | b3cca0a | 2012-01-04 22:19:14 -0500 | [diff] [blame] | 2816 | { |
Giulio Camuffo | 5085a75 | 2013-03-25 21:42:45 +0100 | [diff] [blame] | 2817 | struct shell_seat *shseat = shsurf->popup.shseat; |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 2818 | struct weston_view *parent_view = get_default_view(shsurf->parent); |
Kristian Høgsberg | b3cca0a | 2012-01-04 22:19:14 -0500 | [diff] [blame] | 2819 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 2820 | shsurf->surface->output = parent_view->output; |
| 2821 | shsurf->view->output = parent_view->output; |
Kristian Høgsberg | b3cca0a | 2012-01-04 22:19:14 -0500 | [diff] [blame] | 2822 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 2823 | weston_view_set_transform_parent(shsurf->view, parent_view); |
| 2824 | weston_view_set_position(shsurf->view, shsurf->popup.x, shsurf->popup.y); |
| 2825 | weston_view_update_transform(shsurf->view); |
Kristian Høgsberg | b3cca0a | 2012-01-04 22:19:14 -0500 | [diff] [blame] | 2826 | |
Kristian Høgsberg | e314875 | 2013-05-06 23:19:49 -0400 | [diff] [blame] | 2827 | if (shseat->seat->pointer->grab_serial == shsurf->popup.serial) { |
Giulio Camuffo | 5085a75 | 2013-03-25 21:42:45 +0100 | [diff] [blame] | 2828 | add_popup_grab(shsurf, shseat); |
Kristian Høgsberg | 3730f36 | 2012-04-13 12:40:07 -0400 | [diff] [blame] | 2829 | } else { |
Rafael Antognolli | e2a3455 | 2013-12-03 15:35:45 -0200 | [diff] [blame] | 2830 | shell_surface_send_popup_done(shsurf); |
Giulio Camuffo | 5085a75 | 2013-03-25 21:42:45 +0100 | [diff] [blame] | 2831 | shseat->popup_grab.client = NULL; |
Kristian Høgsberg | 3730f36 | 2012-04-13 12:40:07 -0400 | [diff] [blame] | 2832 | } |
Kristian Høgsberg | b3cca0a | 2012-01-04 22:19:14 -0500 | [diff] [blame] | 2833 | } |
| 2834 | |
Pekka Paalanen | 9d1613e | 2011-11-25 12:09:16 +0200 | [diff] [blame] | 2835 | static const struct wl_shell_surface_interface shell_surface_implementation = { |
Scott Moreau | ff1db4a | 2012-04-17 19:06:18 -0600 | [diff] [blame] | 2836 | shell_surface_pong, |
Pekka Paalanen | 9d1613e | 2011-11-25 12:09:16 +0200 | [diff] [blame] | 2837 | shell_surface_move, |
| 2838 | shell_surface_resize, |
| 2839 | shell_surface_set_toplevel, |
| 2840 | shell_surface_set_transient, |
Kristian Høgsberg | b3cca0a | 2012-01-04 22:19:14 -0500 | [diff] [blame] | 2841 | shell_surface_set_fullscreen, |
Juan Zhao | 96879df | 2012-02-07 08:45:41 +0800 | [diff] [blame] | 2842 | shell_surface_set_popup, |
Kristian Høgsberg | e7afd91 | 2012-05-02 09:47:44 -0400 | [diff] [blame] | 2843 | shell_surface_set_maximized, |
| 2844 | shell_surface_set_title, |
| 2845 | shell_surface_set_class |
Pekka Paalanen | 9d1613e | 2011-11-25 12:09:16 +0200 | [diff] [blame] | 2846 | }; |
| 2847 | |
| 2848 | static void |
Tiago Vignatti | bc052c9 | 2012-04-19 16:18:18 +0300 | [diff] [blame] | 2849 | destroy_shell_surface(struct shell_surface *shsurf) |
Pekka Paalanen | 9d1613e | 2011-11-25 12:09:16 +0200 | [diff] [blame] | 2850 | { |
Jason Ekstrand | 651f00e | 2013-06-14 10:07:54 -0500 | [diff] [blame] | 2851 | wl_signal_emit(&shsurf->destroy_signal, shsurf); |
| 2852 | |
Giulio Camuffo | 5085a75 | 2013-03-25 21:42:45 +0100 | [diff] [blame] | 2853 | if (!wl_list_empty(&shsurf->popup.grab_link)) { |
| 2854 | remove_popup_grab(shsurf); |
| 2855 | } |
Kristian Høgsberg | b3cca0a | 2012-01-04 22:19:14 -0500 | [diff] [blame] | 2856 | |
Alex Wu | bd3354b | 2012-04-17 17:20:49 +0800 | [diff] [blame] | 2857 | if (shsurf->fullscreen.type == WL_SHELL_SURFACE_FULLSCREEN_METHOD_DRIVER && |
Alexander Larsson | f82b6ca | 2013-05-28 16:23:39 +0200 | [diff] [blame] | 2858 | shell_surface_is_top_fullscreen(shsurf)) |
| 2859 | restore_output_mode (shsurf->fullscreen_output); |
Pekka Paalanen | 9d1613e | 2011-11-25 12:09:16 +0200 | [diff] [blame] | 2860 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 2861 | if (shsurf->fullscreen.black_view) |
| 2862 | weston_surface_destroy(shsurf->fullscreen.black_view->surface); |
Alex Wu | aa08e2d | 2012-03-05 11:01:40 +0800 | [diff] [blame] | 2863 | |
Alex Wu | bd3354b | 2012-04-17 17:20:49 +0800 | [diff] [blame] | 2864 | /* As destroy_resource() use wl_list_for_each_safe(), |
| 2865 | * we can always remove the listener. |
| 2866 | */ |
| 2867 | wl_list_remove(&shsurf->surface_destroy_listener.link); |
| 2868 | shsurf->surface->configure = NULL; |
Scott Moreau | 9521d5e | 2012-04-19 13:06:17 -0600 | [diff] [blame] | 2869 | ping_timer_destroy(shsurf); |
Scott Moreau | 976a050 | 2013-03-07 10:15:17 -0700 | [diff] [blame] | 2870 | free(shsurf->title); |
Alex Wu | bd3354b | 2012-04-17 17:20:49 +0800 | [diff] [blame] | 2871 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 2872 | weston_view_destroy(shsurf->view); |
| 2873 | |
Philip Withnall | 648a4dd | 2013-11-25 18:01:44 +0000 | [diff] [blame] | 2874 | wl_list_remove(&shsurf->children_link); |
| 2875 | |
Pekka Paalanen | 9d1613e | 2011-11-25 12:09:16 +0200 | [diff] [blame] | 2876 | wl_list_remove(&shsurf->link); |
| 2877 | free(shsurf); |
| 2878 | } |
| 2879 | |
| 2880 | static void |
Tiago Vignatti | bc052c9 | 2012-04-19 16:18:18 +0300 | [diff] [blame] | 2881 | shell_destroy_shell_surface(struct wl_resource *resource) |
| 2882 | { |
Jason Ekstrand | 651f00e | 2013-06-14 10:07:54 -0500 | [diff] [blame] | 2883 | struct shell_surface *shsurf = wl_resource_get_user_data(resource); |
Tiago Vignatti | bc052c9 | 2012-04-19 16:18:18 +0300 | [diff] [blame] | 2884 | |
| 2885 | destroy_shell_surface(shsurf); |
| 2886 | } |
| 2887 | |
| 2888 | static void |
Kristian Høgsberg | 27e3052 | 2012-04-11 23:18:23 -0400 | [diff] [blame] | 2889 | shell_handle_surface_destroy(struct wl_listener *listener, void *data) |
Pekka Paalanen | 9d1613e | 2011-11-25 12:09:16 +0200 | [diff] [blame] | 2890 | { |
| 2891 | struct shell_surface *shsurf = container_of(listener, |
| 2892 | struct shell_surface, |
| 2893 | surface_destroy_listener); |
| 2894 | |
Jason Ekstrand | 651f00e | 2013-06-14 10:07:54 -0500 | [diff] [blame] | 2895 | if (shsurf->resource) |
| 2896 | wl_resource_destroy(shsurf->resource); |
| 2897 | else |
Tiago Vignatti | bc052c9 | 2012-04-19 16:18:18 +0300 | [diff] [blame] | 2898 | destroy_shell_surface(shsurf); |
Pekka Paalanen | 9d1613e | 2011-11-25 12:09:16 +0200 | [diff] [blame] | 2899 | } |
| 2900 | |
Kristian Høgsberg | d813445 | 2012-06-21 12:49:02 -0400 | [diff] [blame] | 2901 | static void |
Jason Ekstrand | 918f2dd | 2013-12-02 21:01:53 -0600 | [diff] [blame] | 2902 | shell_surface_configure(struct weston_surface *, int32_t, int32_t); |
Zhang, Xiong Y | 3123693 | 2013-12-13 22:10:57 +0200 | [diff] [blame] | 2903 | static void |
| 2904 | shell_surface_output_destroyed(struct weston_surface *); |
Kristian Høgsberg | d813445 | 2012-06-21 12:49:02 -0400 | [diff] [blame] | 2905 | |
Kristian Høgsberg | 1ef2313 | 2013-12-04 00:20:01 -0800 | [diff] [blame] | 2906 | struct shell_surface * |
Kristian Høgsberg | 8334bc1 | 2012-01-03 10:29:47 -0500 | [diff] [blame] | 2907 | get_shell_surface(struct weston_surface *surface) |
Pekka Paalanen | ec2b32f | 2011-11-28 15:12:34 +0200 | [diff] [blame] | 2908 | { |
Kristian Høgsberg | d813445 | 2012-06-21 12:49:02 -0400 | [diff] [blame] | 2909 | if (surface->configure == shell_surface_configure) |
Giulio Camuffo | 7fe01b1 | 2013-03-28 18:02:42 +0100 | [diff] [blame] | 2910 | return surface->configure_private; |
Kristian Høgsberg | d813445 | 2012-06-21 12:49:02 -0400 | [diff] [blame] | 2911 | else |
| 2912 | return NULL; |
Pekka Paalanen | ec2b32f | 2011-11-28 15:12:34 +0200 | [diff] [blame] | 2913 | } |
| 2914 | |
Rafael Antognolli | e2a3455 | 2013-12-03 15:35:45 -0200 | [diff] [blame] | 2915 | static struct shell_surface * |
| 2916 | create_common_surface(void *shell, struct weston_surface *surface, |
| 2917 | const struct weston_shell_client *client) |
Pekka Paalanen | 9d1613e | 2011-11-25 12:09:16 +0200 | [diff] [blame] | 2918 | { |
Pekka Paalanen | 9d1613e | 2011-11-25 12:09:16 +0200 | [diff] [blame] | 2919 | struct shell_surface *shsurf; |
| 2920 | |
Ander Conselvan de Oliveira | 093bfa3 | 2012-03-27 17:36:41 +0300 | [diff] [blame] | 2921 | if (surface->configure) { |
Martin Minarik | 6d11836 | 2012-06-07 18:01:59 +0200 | [diff] [blame] | 2922 | weston_log("surface->configure already set\n"); |
Kristian Høgsberg | 45ba869 | 2012-05-21 14:27:33 -0400 | [diff] [blame] | 2923 | return NULL; |
Ander Conselvan de Oliveira | 093bfa3 | 2012-03-27 17:36:41 +0300 | [diff] [blame] | 2924 | } |
| 2925 | |
Pekka Paalanen | 9d1613e | 2011-11-25 12:09:16 +0200 | [diff] [blame] | 2926 | shsurf = calloc(1, sizeof *shsurf); |
| 2927 | if (!shsurf) { |
Martin Minarik | 6d11836 | 2012-06-07 18:01:59 +0200 | [diff] [blame] | 2928 | weston_log("no memory to allocate shell surface\n"); |
Kristian Høgsberg | 45ba869 | 2012-05-21 14:27:33 -0400 | [diff] [blame] | 2929 | return NULL; |
Pekka Paalanen | 9d1613e | 2011-11-25 12:09:16 +0200 | [diff] [blame] | 2930 | } |
| 2931 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 2932 | shsurf->view = weston_view_create(surface); |
| 2933 | if (!shsurf->view) { |
| 2934 | weston_log("no memory to allocate shell surface\n"); |
| 2935 | free(shsurf); |
| 2936 | return NULL; |
| 2937 | } |
| 2938 | |
Ander Conselvan de Oliveira | 093bfa3 | 2012-03-27 17:36:41 +0300 | [diff] [blame] | 2939 | surface->configure = shell_surface_configure; |
Giulio Camuffo | 7fe01b1 | 2013-03-28 18:02:42 +0100 | [diff] [blame] | 2940 | surface->configure_private = shsurf; |
Zhang, Xiong Y | 3123693 | 2013-12-13 22:10:57 +0200 | [diff] [blame] | 2941 | surface->output_destroyed = shell_surface_output_destroyed; |
Ander Conselvan de Oliveira | 093bfa3 | 2012-03-27 17:36:41 +0300 | [diff] [blame] | 2942 | |
Tiago Vignatti | bc052c9 | 2012-04-19 16:18:18 +0300 | [diff] [blame] | 2943 | shsurf->shell = (struct desktop_shell *) shell; |
Scott Moreau | ff1db4a | 2012-04-17 19:06:18 -0600 | [diff] [blame] | 2944 | shsurf->unresponsive = 0; |
Alex Wu | 4539b08 | 2012-03-01 12:57:46 +0800 | [diff] [blame] | 2945 | shsurf->saved_position_valid = false; |
Rafael Antognolli | 3c4e3f7 | 2013-12-03 15:35:46 -0200 | [diff] [blame] | 2946 | shsurf->saved_size_valid = false; |
Alex Wu | 7bcb8bd | 2012-04-27 09:07:24 +0800 | [diff] [blame] | 2947 | shsurf->saved_rotation_valid = false; |
Pekka Paalanen | 9d1613e | 2011-11-25 12:09:16 +0200 | [diff] [blame] | 2948 | shsurf->surface = surface; |
Alex Wu | 4539b08 | 2012-03-01 12:57:46 +0800 | [diff] [blame] | 2949 | shsurf->fullscreen.type = WL_SHELL_SURFACE_FULLSCREEN_METHOD_DEFAULT; |
| 2950 | shsurf->fullscreen.framerate = 0; |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 2951 | shsurf->fullscreen.black_view = NULL; |
Scott Moreau | ff1db4a | 2012-04-17 19:06:18 -0600 | [diff] [blame] | 2952 | shsurf->ping_timer = NULL; |
Alex Wu | 4539b08 | 2012-03-01 12:57:46 +0800 | [diff] [blame] | 2953 | wl_list_init(&shsurf->fullscreen.transform.link); |
| 2954 | |
Jason Ekstrand | 651f00e | 2013-06-14 10:07:54 -0500 | [diff] [blame] | 2955 | wl_signal_init(&shsurf->destroy_signal); |
Kristian Høgsberg | 27e3052 | 2012-04-11 23:18:23 -0400 | [diff] [blame] | 2956 | shsurf->surface_destroy_listener.notify = shell_handle_surface_destroy; |
Jason Ekstrand | 26ed73c | 2013-06-06 22:34:41 -0500 | [diff] [blame] | 2957 | wl_signal_add(&surface->destroy_signal, |
Kristian Høgsberg | 27e3052 | 2012-04-11 23:18:23 -0400 | [diff] [blame] | 2958 | &shsurf->surface_destroy_listener); |
Pekka Paalanen | 9d1613e | 2011-11-25 12:09:16 +0200 | [diff] [blame] | 2959 | |
| 2960 | /* init link so its safe to always remove it in destroy_shell_surface */ |
| 2961 | wl_list_init(&shsurf->link); |
Giulio Camuffo | 5085a75 | 2013-03-25 21:42:45 +0100 | [diff] [blame] | 2962 | wl_list_init(&shsurf->popup.grab_link); |
Pekka Paalanen | 9d1613e | 2011-11-25 12:09:16 +0200 | [diff] [blame] | 2963 | |
Pekka Paalanen | 460099f | 2012-01-20 16:48:25 +0200 | [diff] [blame] | 2964 | /* empty when not in use */ |
| 2965 | wl_list_init(&shsurf->rotation.transform.link); |
Kristian Høgsberg | 765e27b | 2012-01-27 13:36:13 -0500 | [diff] [blame] | 2966 | weston_matrix_init(&shsurf->rotation.rotation); |
Pekka Paalanen | 460099f | 2012-01-20 16:48:25 +0200 | [diff] [blame] | 2967 | |
Jonas Ådahl | 62fcd04 | 2012-06-13 00:01:23 +0200 | [diff] [blame] | 2968 | wl_list_init(&shsurf->workspace_transform.link); |
| 2969 | |
Philip Withnall | 648a4dd | 2013-11-25 18:01:44 +0000 | [diff] [blame] | 2970 | wl_list_init(&shsurf->children_link); |
| 2971 | wl_list_init(&shsurf->children_list); |
| 2972 | shsurf->parent = NULL; |
| 2973 | |
Pekka Paalanen | 9826223 | 2011-12-01 10:42:22 +0200 | [diff] [blame] | 2974 | shsurf->type = SHELL_SURFACE_NONE; |
Pekka Paalanen | 9d1613e | 2011-11-25 12:09:16 +0200 | [diff] [blame] | 2975 | |
Kristian Høgsberg | a61ca06 | 2012-05-22 16:05:52 -0400 | [diff] [blame] | 2976 | shsurf->client = client; |
| 2977 | |
Kristian Høgsberg | 45ba869 | 2012-05-21 14:27:33 -0400 | [diff] [blame] | 2978 | return shsurf; |
Tiago Vignatti | bc052c9 | 2012-04-19 16:18:18 +0300 | [diff] [blame] | 2979 | } |
| 2980 | |
Rafael Antognolli | e2a3455 | 2013-12-03 15:35:45 -0200 | [diff] [blame] | 2981 | static struct shell_surface * |
| 2982 | create_shell_surface(void *shell, struct weston_surface *surface, |
| 2983 | const struct weston_shell_client *client) |
| 2984 | { |
Kristian Høgsberg | c8f8dd8 | 2013-12-05 23:20:33 -0800 | [diff] [blame] | 2985 | return create_common_surface(shell, surface, client); |
Rafael Antognolli | e2a3455 | 2013-12-03 15:35:45 -0200 | [diff] [blame] | 2986 | } |
| 2987 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 2988 | static struct weston_view * |
| 2989 | get_primary_view(void *shell, struct shell_surface *shsurf) |
| 2990 | { |
| 2991 | return shsurf->view; |
| 2992 | } |
| 2993 | |
Tiago Vignatti | bc052c9 | 2012-04-19 16:18:18 +0300 | [diff] [blame] | 2994 | static void |
| 2995 | shell_get_shell_surface(struct wl_client *client, |
| 2996 | struct wl_resource *resource, |
| 2997 | uint32_t id, |
| 2998 | struct wl_resource *surface_resource) |
| 2999 | { |
Jason Ekstrand | 0f2ef7e | 2013-06-14 10:07:53 -0500 | [diff] [blame] | 3000 | struct weston_surface *surface = |
| 3001 | wl_resource_get_user_data(surface_resource); |
Jason Ekstrand | 651f00e | 2013-06-14 10:07:54 -0500 | [diff] [blame] | 3002 | struct desktop_shell *shell = wl_resource_get_user_data(resource); |
Tiago Vignatti | bc052c9 | 2012-04-19 16:18:18 +0300 | [diff] [blame] | 3003 | struct shell_surface *shsurf; |
| 3004 | |
| 3005 | if (get_shell_surface(surface)) { |
| 3006 | wl_resource_post_error(surface_resource, |
Kristian Høgsberg | 9540ea6 | 2012-05-21 14:28:57 -0400 | [diff] [blame] | 3007 | WL_DISPLAY_ERROR_INVALID_OBJECT, |
| 3008 | "desktop_shell::get_shell_surface already requested"); |
Tiago Vignatti | bc052c9 | 2012-04-19 16:18:18 +0300 | [diff] [blame] | 3009 | return; |
| 3010 | } |
| 3011 | |
Kristian Høgsberg | a61ca06 | 2012-05-22 16:05:52 -0400 | [diff] [blame] | 3012 | shsurf = create_shell_surface(shell, surface, &shell_client); |
Kristian Høgsberg | 9540ea6 | 2012-05-21 14:28:57 -0400 | [diff] [blame] | 3013 | if (!shsurf) { |
| 3014 | wl_resource_post_error(surface_resource, |
| 3015 | WL_DISPLAY_ERROR_INVALID_OBJECT, |
| 3016 | "surface->configure already set"); |
| 3017 | return; |
| 3018 | } |
Tiago Vignatti | bc052c9 | 2012-04-19 16:18:18 +0300 | [diff] [blame] | 3019 | |
Jason Ekstrand | a85118c | 2013-06-27 20:17:02 -0500 | [diff] [blame] | 3020 | shsurf->resource = |
| 3021 | wl_resource_create(client, |
| 3022 | &wl_shell_surface_interface, 1, id); |
| 3023 | wl_resource_set_implementation(shsurf->resource, |
| 3024 | &shell_surface_implementation, |
| 3025 | shsurf, shell_destroy_shell_surface); |
Pekka Paalanen | 9d1613e | 2011-11-25 12:09:16 +0200 | [diff] [blame] | 3026 | } |
| 3027 | |
Rafael Antognolli | e2a3455 | 2013-12-03 15:35:45 -0200 | [diff] [blame] | 3028 | static bool |
| 3029 | shell_surface_is_wl_shell_surface(struct shell_surface *shsurf) |
| 3030 | { |
| 3031 | return wl_resource_instance_of(shsurf->resource, |
| 3032 | &wl_shell_surface_interface, |
| 3033 | &shell_surface_implementation); |
| 3034 | } |
| 3035 | |
Pekka Paalanen | 9d1613e | 2011-11-25 12:09:16 +0200 | [diff] [blame] | 3036 | static const struct wl_shell_interface shell_implementation = { |
Pekka Paalanen | 4622967 | 2011-11-29 15:49:31 +0200 | [diff] [blame] | 3037 | shell_get_shell_surface |
Kristian Høgsberg | 4cca349 | 2011-01-18 07:53:49 -0500 | [diff] [blame] | 3038 | }; |
| 3039 | |
Rafael Antognolli | e2a3455 | 2013-12-03 15:35:45 -0200 | [diff] [blame] | 3040 | /**************************** |
| 3041 | * xdg-shell implementation */ |
| 3042 | |
| 3043 | static void |
| 3044 | xdg_surface_destroy(struct wl_client *client, |
| 3045 | struct wl_resource *resource) |
| 3046 | { |
| 3047 | wl_resource_destroy(resource); |
| 3048 | } |
| 3049 | |
| 3050 | static void |
| 3051 | xdg_surface_pong(struct wl_client *client, |
| 3052 | struct wl_resource *resource, |
| 3053 | uint32_t serial) |
| 3054 | { |
| 3055 | struct shell_surface *shsurf = wl_resource_get_user_data(resource); |
| 3056 | |
| 3057 | surface_pong(shsurf, serial); |
| 3058 | } |
| 3059 | |
| 3060 | static void |
| 3061 | xdg_surface_set_app_id(struct wl_client *client, |
| 3062 | struct wl_resource *resource, |
| 3063 | const char *app_id) |
| 3064 | { |
| 3065 | struct shell_surface *shsurf = wl_resource_get_user_data(resource); |
| 3066 | |
| 3067 | free(shsurf->class); |
| 3068 | shsurf->class = strdup(app_id); |
| 3069 | } |
| 3070 | |
| 3071 | static void |
| 3072 | xdg_surface_set_title(struct wl_client *client, |
| 3073 | struct wl_resource *resource, const char *title) |
| 3074 | { |
| 3075 | struct shell_surface *shsurf = wl_resource_get_user_data(resource); |
| 3076 | |
| 3077 | set_title(shsurf, title); |
| 3078 | } |
| 3079 | |
| 3080 | static void |
| 3081 | xdg_surface_move(struct wl_client *client, struct wl_resource *resource, |
| 3082 | struct wl_resource *seat_resource, uint32_t serial) |
| 3083 | { |
| 3084 | common_surface_move(resource, seat_resource, serial); |
| 3085 | } |
| 3086 | |
| 3087 | static void |
| 3088 | xdg_surface_resize(struct wl_client *client, struct wl_resource *resource, |
| 3089 | struct wl_resource *seat_resource, uint32_t serial, |
| 3090 | uint32_t edges) |
| 3091 | { |
| 3092 | common_surface_resize(resource, seat_resource, serial, edges); |
| 3093 | } |
| 3094 | |
| 3095 | static void |
| 3096 | xdg_surface_set_output(struct wl_client *client, |
| 3097 | struct wl_resource *resource, |
| 3098 | struct wl_resource *output_resource) |
| 3099 | { |
| 3100 | struct shell_surface *shsurf = wl_resource_get_user_data(resource); |
| 3101 | struct weston_output *output; |
| 3102 | |
| 3103 | if (output_resource) |
| 3104 | output = wl_resource_get_user_data(output_resource); |
| 3105 | else |
| 3106 | output = NULL; |
| 3107 | |
Rafael Antognolli | 65f98d8 | 2013-12-03 15:35:47 -0200 | [diff] [blame] | 3108 | shsurf->recommended_output = output; |
Rafael Antognolli | e2a3455 | 2013-12-03 15:35:45 -0200 | [diff] [blame] | 3109 | } |
| 3110 | |
| 3111 | static void |
| 3112 | xdg_surface_set_fullscreen(struct wl_client *client, |
| 3113 | struct wl_resource *resource) |
| 3114 | { |
| 3115 | struct shell_surface *shsurf = wl_resource_get_user_data(resource); |
| 3116 | |
| 3117 | if (shsurf->type != SHELL_SURFACE_TOPLEVEL) |
| 3118 | return; |
| 3119 | |
Kristian Høgsberg | e960b3f | 2013-12-05 22:04:42 -0800 | [diff] [blame] | 3120 | if (!shsurf->next_state.fullscreen) |
Rafael Antognolli | e2a3455 | 2013-12-03 15:35:45 -0200 | [diff] [blame] | 3121 | set_fullscreen(shsurf, |
| 3122 | WL_SHELL_SURFACE_FULLSCREEN_METHOD_DEFAULT, |
Rafael Antognolli | 65f98d8 | 2013-12-03 15:35:47 -0200 | [diff] [blame] | 3123 | 0, shsurf->recommended_output); |
Rafael Antognolli | e2a3455 | 2013-12-03 15:35:45 -0200 | [diff] [blame] | 3124 | } |
| 3125 | |
| 3126 | static void |
| 3127 | xdg_surface_unset_fullscreen(struct wl_client *client, |
| 3128 | struct wl_resource *resource) |
| 3129 | { |
| 3130 | struct shell_surface *shsurf = wl_resource_get_user_data(resource); |
Rafael Antognolli | 3c4e3f7 | 2013-12-03 15:35:46 -0200 | [diff] [blame] | 3131 | int32_t width, height; |
Rafael Antognolli | e2a3455 | 2013-12-03 15:35:45 -0200 | [diff] [blame] | 3132 | |
| 3133 | if (shsurf->type != SHELL_SURFACE_TOPLEVEL) |
| 3134 | return; |
| 3135 | |
Rafael Antognolli | 3c4e3f7 | 2013-12-03 15:35:46 -0200 | [diff] [blame] | 3136 | if (!shsurf->next_state.fullscreen) |
| 3137 | return; |
| 3138 | |
Rafael Antognolli | e2a3455 | 2013-12-03 15:35:45 -0200 | [diff] [blame] | 3139 | shsurf->next_state.fullscreen = false; |
| 3140 | shsurf->state_changed = true; |
Rafael Antognolli | 3c4e3f7 | 2013-12-03 15:35:46 -0200 | [diff] [blame] | 3141 | |
| 3142 | if (shsurf->saved_size_valid) { |
| 3143 | width = shsurf->saved_width; |
| 3144 | height = shsurf->saved_height; |
| 3145 | shsurf->saved_size_valid = false; |
| 3146 | } else { |
| 3147 | width = shsurf->surface->width; |
| 3148 | height = shsurf->surface->height; |
| 3149 | } |
| 3150 | |
| 3151 | shsurf->client->send_configure(shsurf->surface, 0, width, height); |
Rafael Antognolli | e2a3455 | 2013-12-03 15:35:45 -0200 | [diff] [blame] | 3152 | } |
| 3153 | |
| 3154 | static void |
| 3155 | xdg_surface_set_maximized(struct wl_client *client, |
| 3156 | struct wl_resource *resource) |
| 3157 | { |
| 3158 | struct shell_surface *shsurf = wl_resource_get_user_data(resource); |
| 3159 | |
| 3160 | if (shsurf->type != SHELL_SURFACE_TOPLEVEL) |
| 3161 | return; |
| 3162 | |
Kristian Høgsberg | c2745b1 | 2013-12-05 22:00:40 -0800 | [diff] [blame] | 3163 | if (!shsurf->next_state.maximized) |
Rafael Antognolli | 65f98d8 | 2013-12-03 15:35:47 -0200 | [diff] [blame] | 3164 | set_maximized(shsurf, NULL); |
Rafael Antognolli | e2a3455 | 2013-12-03 15:35:45 -0200 | [diff] [blame] | 3165 | } |
| 3166 | |
| 3167 | static void |
| 3168 | xdg_surface_unset_maximized(struct wl_client *client, |
| 3169 | struct wl_resource *resource) |
| 3170 | { |
| 3171 | struct shell_surface *shsurf = wl_resource_get_user_data(resource); |
Rafael Antognolli | 3c4e3f7 | 2013-12-03 15:35:46 -0200 | [diff] [blame] | 3172 | int32_t width, height; |
Rafael Antognolli | e2a3455 | 2013-12-03 15:35:45 -0200 | [diff] [blame] | 3173 | |
| 3174 | if (shsurf->type != SHELL_SURFACE_TOPLEVEL) |
| 3175 | return; |
| 3176 | |
Rafael Antognolli | 3c4e3f7 | 2013-12-03 15:35:46 -0200 | [diff] [blame] | 3177 | if (!shsurf->next_state.maximized) |
| 3178 | return; |
| 3179 | |
Rafael Antognolli | e2a3455 | 2013-12-03 15:35:45 -0200 | [diff] [blame] | 3180 | shsurf->next_state.maximized = false; |
| 3181 | shsurf->state_changed = true; |
Rafael Antognolli | 3c4e3f7 | 2013-12-03 15:35:46 -0200 | [diff] [blame] | 3182 | |
| 3183 | if (shsurf->saved_size_valid) { |
| 3184 | width = shsurf->saved_width; |
| 3185 | height = shsurf->saved_height; |
| 3186 | shsurf->saved_size_valid = false; |
| 3187 | } else { |
| 3188 | width = shsurf->surface->width; |
| 3189 | height = shsurf->surface->height; |
| 3190 | } |
| 3191 | |
| 3192 | shsurf->client->send_configure(shsurf->surface, 0, width, height); |
Rafael Antognolli | e2a3455 | 2013-12-03 15:35:45 -0200 | [diff] [blame] | 3193 | } |
| 3194 | |
| 3195 | static const struct xdg_surface_interface xdg_surface_implementation = { |
| 3196 | xdg_surface_destroy, |
| 3197 | xdg_surface_set_transient_for, |
| 3198 | xdg_surface_set_title, |
| 3199 | xdg_surface_set_app_id, |
| 3200 | xdg_surface_pong, |
| 3201 | xdg_surface_move, |
| 3202 | xdg_surface_resize, |
| 3203 | xdg_surface_set_output, |
| 3204 | xdg_surface_set_fullscreen, |
| 3205 | xdg_surface_unset_fullscreen, |
| 3206 | xdg_surface_set_maximized, |
| 3207 | xdg_surface_unset_maximized, |
| 3208 | NULL /* set_minimized */ |
| 3209 | }; |
| 3210 | |
| 3211 | static void |
| 3212 | xdg_send_configure(struct weston_surface *surface, |
| 3213 | uint32_t edges, int32_t width, int32_t height) |
| 3214 | { |
| 3215 | struct shell_surface *shsurf = get_shell_surface(surface); |
| 3216 | |
| 3217 | xdg_surface_send_configure(shsurf->resource, edges, width, height); |
| 3218 | } |
| 3219 | |
| 3220 | static const struct weston_shell_client xdg_client = { |
| 3221 | xdg_send_configure |
| 3222 | }; |
| 3223 | |
| 3224 | static void |
| 3225 | xdg_use_unstable_version(struct wl_client *client, |
| 3226 | struct wl_resource *resource, |
| 3227 | int32_t version) |
| 3228 | { |
| 3229 | if (version > 1) { |
| 3230 | wl_resource_post_error(resource, |
| 3231 | 1, |
| 3232 | "xdg-shell:: version not implemented yet."); |
| 3233 | return; |
| 3234 | } |
| 3235 | } |
| 3236 | |
| 3237 | static struct shell_surface * |
| 3238 | create_xdg_surface(void *shell, struct weston_surface *surface, |
| 3239 | const struct weston_shell_client *client) |
| 3240 | { |
| 3241 | struct shell_surface *shsurf; |
Rafael Antognolli | e2a3455 | 2013-12-03 15:35:45 -0200 | [diff] [blame] | 3242 | |
Kristian Høgsberg | c8f8dd8 | 2013-12-05 23:20:33 -0800 | [diff] [blame] | 3243 | shsurf = create_common_surface(shell, surface, client); |
| 3244 | shsurf->type = SHELL_SURFACE_TOPLEVEL; |
Rafael Antognolli | e2a3455 | 2013-12-03 15:35:45 -0200 | [diff] [blame] | 3245 | |
| 3246 | return shsurf; |
| 3247 | } |
| 3248 | |
| 3249 | static void |
| 3250 | xdg_get_xdg_surface(struct wl_client *client, |
| 3251 | struct wl_resource *resource, |
| 3252 | uint32_t id, |
| 3253 | struct wl_resource *surface_resource) |
| 3254 | { |
| 3255 | struct weston_surface *surface = |
| 3256 | wl_resource_get_user_data(surface_resource); |
| 3257 | struct desktop_shell *shell = wl_resource_get_user_data(resource); |
| 3258 | struct shell_surface *shsurf; |
| 3259 | |
| 3260 | if (get_shell_surface(surface)) { |
| 3261 | wl_resource_post_error(surface_resource, |
| 3262 | WL_DISPLAY_ERROR_INVALID_OBJECT, |
| 3263 | "desktop_shell::get_shell_surface already requested"); |
| 3264 | return; |
| 3265 | } |
| 3266 | |
| 3267 | shsurf = create_xdg_surface(shell, surface, &xdg_client); |
| 3268 | if (!shsurf) { |
| 3269 | wl_resource_post_error(surface_resource, |
| 3270 | WL_DISPLAY_ERROR_INVALID_OBJECT, |
| 3271 | "surface->configure already set"); |
| 3272 | return; |
| 3273 | } |
| 3274 | |
| 3275 | shsurf->resource = |
| 3276 | wl_resource_create(client, |
| 3277 | &xdg_surface_interface, 1, id); |
| 3278 | wl_resource_set_implementation(shsurf->resource, |
| 3279 | &xdg_surface_implementation, |
| 3280 | shsurf, shell_destroy_shell_surface); |
| 3281 | } |
| 3282 | |
| 3283 | static bool |
| 3284 | shell_surface_is_xdg_surface(struct shell_surface *shsurf) |
| 3285 | { |
| 3286 | return wl_resource_instance_of(shsurf->resource, |
| 3287 | &xdg_surface_interface, |
| 3288 | &xdg_surface_implementation); |
| 3289 | } |
| 3290 | |
| 3291 | /* xdg-popup implementation */ |
| 3292 | |
| 3293 | static void |
| 3294 | xdg_popup_destroy(struct wl_client *client, |
| 3295 | struct wl_resource *resource) |
| 3296 | { |
| 3297 | wl_resource_destroy(resource); |
| 3298 | } |
| 3299 | |
| 3300 | static void |
| 3301 | xdg_popup_pong(struct wl_client *client, |
| 3302 | struct wl_resource *resource, |
| 3303 | uint32_t serial) |
| 3304 | { |
| 3305 | struct shell_surface *shsurf = wl_resource_get_user_data(resource); |
| 3306 | |
| 3307 | surface_pong(shsurf, serial); |
| 3308 | } |
| 3309 | |
| 3310 | static const struct xdg_popup_interface xdg_popup_implementation = { |
| 3311 | xdg_popup_destroy, |
| 3312 | xdg_popup_pong |
| 3313 | }; |
| 3314 | |
| 3315 | static void |
| 3316 | xdg_popup_send_configure(struct weston_surface *surface, |
| 3317 | uint32_t edges, int32_t width, int32_t height) |
| 3318 | { |
| 3319 | } |
| 3320 | |
| 3321 | static const struct weston_shell_client xdg_popup_client = { |
| 3322 | xdg_popup_send_configure |
| 3323 | }; |
| 3324 | |
| 3325 | static struct shell_surface * |
| 3326 | create_xdg_popup(void *shell, struct weston_surface *surface, |
| 3327 | const struct weston_shell_client *client, |
| 3328 | struct weston_surface *parent, |
| 3329 | struct shell_seat *seat, |
| 3330 | uint32_t serial, |
| 3331 | int32_t x, int32_t y) |
| 3332 | { |
| 3333 | struct shell_surface *shsurf; |
Rafael Antognolli | e2a3455 | 2013-12-03 15:35:45 -0200 | [diff] [blame] | 3334 | |
Kristian Høgsberg | c8f8dd8 | 2013-12-05 23:20:33 -0800 | [diff] [blame] | 3335 | shsurf = create_common_surface(shell, surface, client); |
| 3336 | shsurf->type = SHELL_SURFACE_POPUP; |
Rafael Antognolli | e2a3455 | 2013-12-03 15:35:45 -0200 | [diff] [blame] | 3337 | shsurf->popup.shseat = seat; |
| 3338 | shsurf->popup.serial = serial; |
| 3339 | shsurf->popup.x = x; |
| 3340 | shsurf->popup.y = y; |
| 3341 | shell_surface_set_parent(shsurf, parent); |
| 3342 | |
| 3343 | return shsurf; |
| 3344 | } |
| 3345 | |
| 3346 | static void |
| 3347 | xdg_get_xdg_popup(struct wl_client *client, |
| 3348 | struct wl_resource *resource, |
| 3349 | uint32_t id, |
| 3350 | struct wl_resource *surface_resource, |
| 3351 | struct wl_resource *parent_resource, |
| 3352 | struct wl_resource *seat_resource, |
| 3353 | uint32_t serial, |
| 3354 | int32_t x, int32_t y, uint32_t flags) |
| 3355 | { |
| 3356 | struct weston_surface *surface = |
| 3357 | wl_resource_get_user_data(surface_resource); |
| 3358 | struct desktop_shell *shell = wl_resource_get_user_data(resource); |
| 3359 | struct shell_surface *shsurf; |
| 3360 | struct weston_surface *parent; |
| 3361 | struct shell_seat *seat; |
| 3362 | |
| 3363 | if (get_shell_surface(surface)) { |
| 3364 | wl_resource_post_error(surface_resource, |
| 3365 | WL_DISPLAY_ERROR_INVALID_OBJECT, |
| 3366 | "desktop_shell::get_shell_surface already requested"); |
| 3367 | return; |
| 3368 | } |
| 3369 | |
| 3370 | if (!parent_resource) { |
| 3371 | wl_resource_post_error(surface_resource, |
| 3372 | WL_DISPLAY_ERROR_INVALID_OBJECT, |
| 3373 | "xdg_shell::get_xdg_popup requires a parent shell surface"); |
| 3374 | } |
| 3375 | |
| 3376 | parent = wl_resource_get_user_data(parent_resource); |
| 3377 | seat = get_shell_seat(wl_resource_get_user_data(seat_resource));; |
| 3378 | |
| 3379 | shsurf = create_xdg_popup(shell, surface, &xdg_popup_client, |
| 3380 | parent, seat, serial, x, y); |
| 3381 | if (!shsurf) { |
| 3382 | wl_resource_post_error(surface_resource, |
| 3383 | WL_DISPLAY_ERROR_INVALID_OBJECT, |
| 3384 | "surface->configure already set"); |
| 3385 | return; |
| 3386 | } |
| 3387 | |
| 3388 | shsurf->resource = |
| 3389 | wl_resource_create(client, |
| 3390 | &xdg_popup_interface, 1, id); |
| 3391 | wl_resource_set_implementation(shsurf->resource, |
| 3392 | &xdg_popup_implementation, |
| 3393 | shsurf, shell_destroy_shell_surface); |
| 3394 | } |
| 3395 | |
| 3396 | static bool |
| 3397 | shell_surface_is_xdg_popup(struct shell_surface *shsurf) |
| 3398 | { |
| 3399 | return wl_resource_instance_of(shsurf->resource, |
| 3400 | &xdg_popup_interface, |
| 3401 | &xdg_popup_implementation); |
| 3402 | } |
| 3403 | |
| 3404 | static const struct xdg_shell_interface xdg_implementation = { |
| 3405 | xdg_use_unstable_version, |
| 3406 | xdg_get_xdg_surface, |
| 3407 | xdg_get_xdg_popup |
| 3408 | }; |
| 3409 | |
| 3410 | static int |
| 3411 | xdg_shell_unversioned_dispatch(const void *implementation, |
| 3412 | void *_target, uint32_t opcode, |
| 3413 | const struct wl_message *message, |
| 3414 | union wl_argument *args) |
| 3415 | { |
| 3416 | struct wl_resource *resource = _target; |
| 3417 | struct desktop_shell *shell = wl_resource_get_user_data(resource); |
| 3418 | |
| 3419 | if (opcode != 0) { |
| 3420 | wl_resource_post_error(resource, |
| 3421 | WL_DISPLAY_ERROR_INVALID_OBJECT, |
| 3422 | "must call use_unstable_version first"); |
| 3423 | return 0; |
| 3424 | } |
| 3425 | |
| 3426 | #define XDG_SERVER_VERSION 1 |
| 3427 | |
Kristian Høgsberg | 8d344a0 | 2013-12-08 22:27:11 -0800 | [diff] [blame] | 3428 | static_assert(XDG_SERVER_VERSION == XDG_SHELL_VERSION_CURRENT, |
| 3429 | "shell implementation doesn't match protocol version"); |
| 3430 | |
Rafael Antognolli | e2a3455 | 2013-12-03 15:35:45 -0200 | [diff] [blame] | 3431 | if (args[0].i != XDG_SERVER_VERSION) { |
| 3432 | wl_resource_post_error(resource, |
| 3433 | WL_DISPLAY_ERROR_INVALID_OBJECT, |
| 3434 | "incompatible version, server is %d " |
| 3435 | "client wants %d", |
| 3436 | XDG_SERVER_VERSION, args[0].i); |
| 3437 | return 0; |
| 3438 | } |
| 3439 | |
| 3440 | wl_resource_set_implementation(resource, &xdg_implementation, |
| 3441 | shell, NULL); |
| 3442 | |
| 3443 | return 1; |
| 3444 | } |
| 3445 | |
| 3446 | /* end of xdg-shell implementation */ |
| 3447 | /***********************************/ |
| 3448 | |
Kristian Høgsberg | 0793756 | 2011-04-12 17:25:42 -0400 | [diff] [blame] | 3449 | static void |
Ander Conselvan de Oliveira | 859e885 | 2013-02-21 18:35:21 +0200 | [diff] [blame] | 3450 | shell_fade(struct desktop_shell *shell, enum fade_type type); |
| 3451 | |
| 3452 | static int |
| 3453 | screensaver_timeout(void *data) |
| 3454 | { |
| 3455 | struct desktop_shell *shell = data; |
| 3456 | |
| 3457 | shell_fade(shell, FADE_OUT); |
| 3458 | |
| 3459 | return 1; |
| 3460 | } |
| 3461 | |
| 3462 | static void |
Kristian Høgsberg | 8334bc1 | 2012-01-03 10:29:47 -0500 | [diff] [blame] | 3463 | handle_screensaver_sigchld(struct weston_process *proc, int status) |
Pekka Paalanen | 18027e5 | 2011-12-02 16:31:49 +0200 | [diff] [blame] | 3464 | { |
Ander Conselvan de Oliveira | 18639f8 | 2013-02-15 18:44:19 +0200 | [diff] [blame] | 3465 | struct desktop_shell *shell = |
| 3466 | container_of(proc, struct desktop_shell, screensaver.process); |
Ander Conselvan de Oliveira | 18639f8 | 2013-02-15 18:44:19 +0200 | [diff] [blame] | 3467 | |
Pekka Paalanen | 18027e5 | 2011-12-02 16:31:49 +0200 | [diff] [blame] | 3468 | proc->pid = 0; |
Ander Conselvan de Oliveira | 18639f8 | 2013-02-15 18:44:19 +0200 | [diff] [blame] | 3469 | |
| 3470 | if (shell->locked) |
Ander Conselvan de Oliveira | b17537e | 2013-02-22 14:16:18 +0200 | [diff] [blame] | 3471 | weston_compositor_sleep(shell->compositor); |
Pekka Paalanen | 18027e5 | 2011-12-02 16:31:49 +0200 | [diff] [blame] | 3472 | } |
| 3473 | |
| 3474 | static void |
Tiago Vignatti | be14326 | 2012-04-16 17:31:41 +0300 | [diff] [blame] | 3475 | launch_screensaver(struct desktop_shell *shell) |
Pekka Paalanen | 77346a6 | 2011-11-30 16:26:35 +0200 | [diff] [blame] | 3476 | { |
| 3477 | if (shell->screensaver.binding) |
| 3478 | return; |
| 3479 | |
Ander Conselvan de Oliveira | dda9d78 | 2013-02-22 14:16:19 +0200 | [diff] [blame] | 3480 | if (!shell->screensaver.path) { |
| 3481 | weston_compositor_sleep(shell->compositor); |
Pekka Paalanen | e955f1e | 2011-12-07 11:49:52 +0200 | [diff] [blame] | 3482 | return; |
Ander Conselvan de Oliveira | dda9d78 | 2013-02-22 14:16:19 +0200 | [diff] [blame] | 3483 | } |
Pekka Paalanen | e955f1e | 2011-12-07 11:49:52 +0200 | [diff] [blame] | 3484 | |
Kristian Høgsberg | 32bed57 | 2012-03-01 17:11:36 -0500 | [diff] [blame] | 3485 | if (shell->screensaver.process.pid != 0) { |
Martin Minarik | 6d11836 | 2012-06-07 18:01:59 +0200 | [diff] [blame] | 3486 | weston_log("old screensaver still running\n"); |
Kristian Høgsberg | 32bed57 | 2012-03-01 17:11:36 -0500 | [diff] [blame] | 3487 | return; |
| 3488 | } |
| 3489 | |
Kristian Høgsberg | 8334bc1 | 2012-01-03 10:29:47 -0500 | [diff] [blame] | 3490 | weston_client_launch(shell->compositor, |
Pekka Paalanen | 18027e5 | 2011-12-02 16:31:49 +0200 | [diff] [blame] | 3491 | &shell->screensaver.process, |
Pekka Paalanen | e955f1e | 2011-12-07 11:49:52 +0200 | [diff] [blame] | 3492 | shell->screensaver.path, |
Pekka Paalanen | 18027e5 | 2011-12-02 16:31:49 +0200 | [diff] [blame] | 3493 | handle_screensaver_sigchld); |
Pekka Paalanen | 77346a6 | 2011-11-30 16:26:35 +0200 | [diff] [blame] | 3494 | } |
| 3495 | |
| 3496 | static void |
Tiago Vignatti | be14326 | 2012-04-16 17:31:41 +0300 | [diff] [blame] | 3497 | terminate_screensaver(struct desktop_shell *shell) |
Pekka Paalanen | 77346a6 | 2011-11-30 16:26:35 +0200 | [diff] [blame] | 3498 | { |
Pekka Paalanen | 18027e5 | 2011-12-02 16:31:49 +0200 | [diff] [blame] | 3499 | if (shell->screensaver.process.pid == 0) |
| 3500 | return; |
| 3501 | |
| 3502 | kill(shell->screensaver.process.pid, SIGTERM); |
Pekka Paalanen | 77346a6 | 2011-11-30 16:26:35 +0200 | [diff] [blame] | 3503 | } |
| 3504 | |
| 3505 | static void |
Jason Ekstrand | 918f2dd | 2013-12-02 21:01:53 -0600 | [diff] [blame] | 3506 | configure_static_view(struct weston_view *ev, struct weston_layer *layer) |
Kristian Høgsberg | 962342c | 2012-06-26 16:29:50 -0400 | [diff] [blame] | 3507 | { |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 3508 | struct weston_view *v, *next; |
Kristian Høgsberg | 962342c | 2012-06-26 16:29:50 -0400 | [diff] [blame] | 3509 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 3510 | wl_list_for_each_safe(v, next, &layer->view_list, layer_link) { |
| 3511 | if (v->output == ev->output && v != ev) { |
| 3512 | weston_view_unmap(v); |
| 3513 | v->surface->configure = NULL; |
Kristian Høgsberg | 962342c | 2012-06-26 16:29:50 -0400 | [diff] [blame] | 3514 | } |
| 3515 | } |
| 3516 | |
Jason Ekstrand | 918f2dd | 2013-12-02 21:01:53 -0600 | [diff] [blame] | 3517 | weston_view_set_position(ev, ev->output->x, ev->output->y); |
Kristian Høgsberg | 962342c | 2012-06-26 16:29:50 -0400 | [diff] [blame] | 3518 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 3519 | if (wl_list_empty(&ev->layer_link)) { |
| 3520 | wl_list_insert(&layer->view_list, &ev->layer_link); |
| 3521 | weston_compositor_schedule_repaint(ev->surface->compositor); |
Kristian Høgsberg | 962342c | 2012-06-26 16:29:50 -0400 | [diff] [blame] | 3522 | } |
| 3523 | } |
| 3524 | |
| 3525 | static void |
Jason Ekstrand | 918f2dd | 2013-12-02 21:01:53 -0600 | [diff] [blame] | 3526 | 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] | 3527 | { |
Giulio Camuffo | 7fe01b1 | 2013-03-28 18:02:42 +0100 | [diff] [blame] | 3528 | struct desktop_shell *shell = es->configure_private; |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 3529 | struct weston_view *view; |
Kristian Høgsberg | af7b1ff | 2012-06-26 21:19:23 -0400 | [diff] [blame] | 3530 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 3531 | view = container_of(es->views.next, struct weston_view, surface_link); |
| 3532 | |
Jason Ekstrand | 918f2dd | 2013-12-02 21:01:53 -0600 | [diff] [blame] | 3533 | configure_static_view(view, &shell->background_layer); |
Kristian Høgsberg | af7b1ff | 2012-06-26 21:19:23 -0400 | [diff] [blame] | 3534 | } |
| 3535 | |
| 3536 | static void |
Kristian Høgsberg | 7584062 | 2011-09-06 13:48:16 -0400 | [diff] [blame] | 3537 | desktop_shell_set_background(struct wl_client *client, |
| 3538 | struct wl_resource *resource, |
Benjamin Franzke | d0f79ab | 2011-11-22 12:43:52 +0100 | [diff] [blame] | 3539 | struct wl_resource *output_resource, |
Kristian Høgsberg | 7584062 | 2011-09-06 13:48:16 -0400 | [diff] [blame] | 3540 | struct wl_resource *surface_resource) |
| 3541 | { |
Jason Ekstrand | 651f00e | 2013-06-14 10:07:54 -0500 | [diff] [blame] | 3542 | struct desktop_shell *shell = wl_resource_get_user_data(resource); |
Jason Ekstrand | 0f2ef7e | 2013-06-14 10:07:53 -0500 | [diff] [blame] | 3543 | struct weston_surface *surface = |
| 3544 | wl_resource_get_user_data(surface_resource); |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 3545 | struct weston_view *view, *next; |
Kristian Høgsberg | 7584062 | 2011-09-06 13:48:16 -0400 | [diff] [blame] | 3546 | |
Kristian Høgsberg | 962342c | 2012-06-26 16:29:50 -0400 | [diff] [blame] | 3547 | if (surface->configure) { |
| 3548 | wl_resource_post_error(surface_resource, |
| 3549 | WL_DISPLAY_ERROR_INVALID_OBJECT, |
| 3550 | "surface role already assigned"); |
| 3551 | return; |
| 3552 | } |
Benjamin Franzke | d0f79ab | 2011-11-22 12:43:52 +0100 | [diff] [blame] | 3553 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 3554 | wl_list_for_each_safe(view, next, &surface->views, surface_link) |
| 3555 | weston_view_destroy(view); |
| 3556 | view = weston_view_create(surface); |
| 3557 | |
Kristian Høgsberg | 962342c | 2012-06-26 16:29:50 -0400 | [diff] [blame] | 3558 | surface->configure = background_configure; |
Giulio Camuffo | 7fe01b1 | 2013-03-28 18:02:42 +0100 | [diff] [blame] | 3559 | surface->configure_private = shell; |
Jason Ekstrand | a0d2dde | 2013-06-14 10:08:01 -0500 | [diff] [blame] | 3560 | surface->output = wl_resource_get_user_data(output_resource); |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 3561 | view->output = surface->output; |
Kristian Høgsberg | eae5de7 | 2012-04-11 22:42:15 -0400 | [diff] [blame] | 3562 | desktop_shell_send_configure(resource, 0, |
Kristian Høgsberg | 0b5cd0c | 2012-03-04 21:57:37 -0500 | [diff] [blame] | 3563 | surface_resource, |
Scott Moreau | 1bad5db | 2012-08-18 01:04:05 -0600 | [diff] [blame] | 3564 | surface->output->width, |
| 3565 | surface->output->height); |
Kristian Høgsberg | 7584062 | 2011-09-06 13:48:16 -0400 | [diff] [blame] | 3566 | } |
| 3567 | |
| 3568 | static void |
Jason Ekstrand | 918f2dd | 2013-12-02 21:01:53 -0600 | [diff] [blame] | 3569 | 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] | 3570 | { |
Giulio Camuffo | 7fe01b1 | 2013-03-28 18:02:42 +0100 | [diff] [blame] | 3571 | struct desktop_shell *shell = es->configure_private; |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 3572 | struct weston_view *view; |
Kristian Høgsberg | af7b1ff | 2012-06-26 21:19:23 -0400 | [diff] [blame] | 3573 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 3574 | view = container_of(es->views.next, struct weston_view, surface_link); |
| 3575 | |
Jason Ekstrand | 918f2dd | 2013-12-02 21:01:53 -0600 | [diff] [blame] | 3576 | configure_static_view(view, &shell->panel_layer); |
Kristian Høgsberg | af7b1ff | 2012-06-26 21:19:23 -0400 | [diff] [blame] | 3577 | } |
| 3578 | |
| 3579 | static void |
Kristian Høgsberg | 7584062 | 2011-09-06 13:48:16 -0400 | [diff] [blame] | 3580 | desktop_shell_set_panel(struct wl_client *client, |
| 3581 | struct wl_resource *resource, |
Benjamin Franzke | d0f79ab | 2011-11-22 12:43:52 +0100 | [diff] [blame] | 3582 | struct wl_resource *output_resource, |
Kristian Høgsberg | 7584062 | 2011-09-06 13:48:16 -0400 | [diff] [blame] | 3583 | struct wl_resource *surface_resource) |
| 3584 | { |
Jason Ekstrand | 651f00e | 2013-06-14 10:07:54 -0500 | [diff] [blame] | 3585 | struct desktop_shell *shell = wl_resource_get_user_data(resource); |
Jason Ekstrand | 0f2ef7e | 2013-06-14 10:07:53 -0500 | [diff] [blame] | 3586 | struct weston_surface *surface = |
| 3587 | wl_resource_get_user_data(surface_resource); |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 3588 | struct weston_view *view, *next; |
Kristian Høgsberg | 7584062 | 2011-09-06 13:48:16 -0400 | [diff] [blame] | 3589 | |
Kristian Høgsberg | af7b1ff | 2012-06-26 21:19:23 -0400 | [diff] [blame] | 3590 | if (surface->configure) { |
| 3591 | wl_resource_post_error(surface_resource, |
| 3592 | WL_DISPLAY_ERROR_INVALID_OBJECT, |
| 3593 | "surface role already assigned"); |
| 3594 | return; |
| 3595 | } |
Benjamin Franzke | d0f79ab | 2011-11-22 12:43:52 +0100 | [diff] [blame] | 3596 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 3597 | wl_list_for_each_safe(view, next, &surface->views, surface_link) |
| 3598 | weston_view_destroy(view); |
| 3599 | view = weston_view_create(surface); |
| 3600 | |
Kristian Høgsberg | af7b1ff | 2012-06-26 21:19:23 -0400 | [diff] [blame] | 3601 | surface->configure = panel_configure; |
Giulio Camuffo | 7fe01b1 | 2013-03-28 18:02:42 +0100 | [diff] [blame] | 3602 | surface->configure_private = shell; |
Jason Ekstrand | a0d2dde | 2013-06-14 10:08:01 -0500 | [diff] [blame] | 3603 | surface->output = wl_resource_get_user_data(output_resource); |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 3604 | view->output = surface->output; |
Kristian Høgsberg | eae5de7 | 2012-04-11 22:42:15 -0400 | [diff] [blame] | 3605 | desktop_shell_send_configure(resource, 0, |
Kristian Høgsberg | af7b1ff | 2012-06-26 21:19:23 -0400 | [diff] [blame] | 3606 | surface_resource, |
Scott Moreau | 1bad5db | 2012-08-18 01:04:05 -0600 | [diff] [blame] | 3607 | surface->output->width, |
| 3608 | surface->output->height); |
Kristian Høgsberg | 7584062 | 2011-09-06 13:48:16 -0400 | [diff] [blame] | 3609 | } |
| 3610 | |
Pekka Paalanen | 9ef3e01 | 2011-11-15 13:34:48 +0200 | [diff] [blame] | 3611 | static void |
Jason Ekstrand | 918f2dd | 2013-12-02 21:01:53 -0600 | [diff] [blame] | 3612 | 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] | 3613 | { |
Giulio Camuffo | 7fe01b1 | 2013-03-28 18:02:42 +0100 | [diff] [blame] | 3614 | struct desktop_shell *shell = surface->configure_private; |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 3615 | struct weston_view *view; |
| 3616 | |
| 3617 | view = container_of(surface->views.next, struct weston_view, surface_link); |
Kristian Høgsberg | 730c94d | 2012-06-26 21:44:35 -0400 | [diff] [blame] | 3618 | |
Jason Ekstrand | 918f2dd | 2013-12-02 21:01:53 -0600 | [diff] [blame] | 3619 | if (surface->width == 0) |
Giulio Camuffo | 184df50 | 2013-02-21 11:29:21 +0100 | [diff] [blame] | 3620 | return; |
| 3621 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 3622 | center_on_output(view, get_default_output(shell->compositor)); |
Kristian Høgsberg | 730c94d | 2012-06-26 21:44:35 -0400 | [diff] [blame] | 3623 | |
| 3624 | if (!weston_surface_is_mapped(surface)) { |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 3625 | wl_list_insert(&shell->lock_layer.view_list, |
| 3626 | &view->layer_link); |
| 3627 | weston_view_update_transform(view); |
Ander Conselvan de Oliveira | 87524b6 | 2013-02-21 18:35:22 +0200 | [diff] [blame] | 3628 | shell_fade(shell, FADE_IN); |
Kristian Høgsberg | 730c94d | 2012-06-26 21:44:35 -0400 | [diff] [blame] | 3629 | } |
| 3630 | } |
| 3631 | |
| 3632 | static void |
Kristian Høgsberg | 27e3052 | 2012-04-11 23:18:23 -0400 | [diff] [blame] | 3633 | handle_lock_surface_destroy(struct wl_listener *listener, void *data) |
Kristian Høgsberg | 1ec0c31 | 2011-11-15 16:39:55 -0500 | [diff] [blame] | 3634 | { |
Tiago Vignatti | be14326 | 2012-04-16 17:31:41 +0300 | [diff] [blame] | 3635 | struct desktop_shell *shell = |
| 3636 | container_of(listener, struct desktop_shell, lock_surface_listener); |
Kristian Høgsberg | 1ec0c31 | 2011-11-15 16:39:55 -0500 | [diff] [blame] | 3637 | |
Martin Minarik | 6d11836 | 2012-06-07 18:01:59 +0200 | [diff] [blame] | 3638 | weston_log("lock surface gone\n"); |
Kristian Høgsberg | 1ec0c31 | 2011-11-15 16:39:55 -0500 | [diff] [blame] | 3639 | shell->lock_surface = NULL; |
| 3640 | } |
| 3641 | |
| 3642 | static void |
Pekka Paalanen | 9ef3e01 | 2011-11-15 13:34:48 +0200 | [diff] [blame] | 3643 | desktop_shell_set_lock_surface(struct wl_client *client, |
| 3644 | struct wl_resource *resource, |
| 3645 | struct wl_resource *surface_resource) |
| 3646 | { |
Jason Ekstrand | 651f00e | 2013-06-14 10:07:54 -0500 | [diff] [blame] | 3647 | struct desktop_shell *shell = wl_resource_get_user_data(resource); |
Jason Ekstrand | 0f2ef7e | 2013-06-14 10:07:53 -0500 | [diff] [blame] | 3648 | struct weston_surface *surface = |
| 3649 | wl_resource_get_user_data(surface_resource); |
Pekka Paalanen | 9826223 | 2011-12-01 10:42:22 +0200 | [diff] [blame] | 3650 | |
Pekka Paalanen | f0fc70d | 2011-11-15 13:34:54 +0200 | [diff] [blame] | 3651 | shell->prepare_event_sent = false; |
Kristian Høgsberg | af867cc | 2011-11-15 13:34:49 +0200 | [diff] [blame] | 3652 | |
Pekka Paalanen | f0fc70d | 2011-11-15 13:34:54 +0200 | [diff] [blame] | 3653 | if (!shell->locked) |
| 3654 | return; |
| 3655 | |
Pekka Paalanen | 9826223 | 2011-12-01 10:42:22 +0200 | [diff] [blame] | 3656 | shell->lock_surface = surface; |
Pekka Paalanen | f0fc70d | 2011-11-15 13:34:54 +0200 | [diff] [blame] | 3657 | |
Kristian Høgsberg | 27e3052 | 2012-04-11 23:18:23 -0400 | [diff] [blame] | 3658 | shell->lock_surface_listener.notify = handle_lock_surface_destroy; |
Jason Ekstrand | 651f00e | 2013-06-14 10:07:54 -0500 | [diff] [blame] | 3659 | wl_signal_add(&surface->destroy_signal, |
Kristian Høgsberg | 27e3052 | 2012-04-11 23:18:23 -0400 | [diff] [blame] | 3660 | &shell->lock_surface_listener); |
Pekka Paalanen | 57da4a8 | 2011-11-23 16:42:16 +0200 | [diff] [blame] | 3661 | |
Kristian Høgsberg | aa2ee8b | 2013-10-30 15:49:45 -0700 | [diff] [blame] | 3662 | weston_view_create(surface); |
Kristian Høgsberg | 730c94d | 2012-06-26 21:44:35 -0400 | [diff] [blame] | 3663 | surface->configure = lock_surface_configure; |
Giulio Camuffo | 7fe01b1 | 2013-03-28 18:02:42 +0100 | [diff] [blame] | 3664 | surface->configure_private = shell; |
Pekka Paalanen | f0fc70d | 2011-11-15 13:34:54 +0200 | [diff] [blame] | 3665 | } |
| 3666 | |
| 3667 | static void |
Tiago Vignatti | be14326 | 2012-04-16 17:31:41 +0300 | [diff] [blame] | 3668 | resume_desktop(struct desktop_shell *shell) |
Pekka Paalanen | f0fc70d | 2011-11-15 13:34:54 +0200 | [diff] [blame] | 3669 | { |
Kristian Høgsberg | 4476aaf | 2012-06-25 14:03:13 -0400 | [diff] [blame] | 3670 | struct workspace *ws = get_current_workspace(shell); |
Pekka Paalanen | 77346a6 | 2011-11-30 16:26:35 +0200 | [diff] [blame] | 3671 | |
Pekka Paalanen | 77346a6 | 2011-11-30 16:26:35 +0200 | [diff] [blame] | 3672 | terminate_screensaver(shell); |
Pekka Paalanen | f0fc70d | 2011-11-15 13:34:54 +0200 | [diff] [blame] | 3673 | |
Kristian Høgsberg | 3be2ce9 | 2012-02-29 12:42:35 -0500 | [diff] [blame] | 3674 | wl_list_remove(&shell->lock_layer.link); |
| 3675 | wl_list_insert(&shell->compositor->cursor_layer.link, |
| 3676 | &shell->fullscreen_layer.link); |
| 3677 | wl_list_insert(&shell->fullscreen_layer.link, |
| 3678 | &shell->panel_layer.link); |
Philipp Brüschweiler | 711fda8 | 2012-08-09 18:50:43 +0200 | [diff] [blame] | 3679 | if (shell->showing_input_panels) { |
| 3680 | wl_list_insert(&shell->panel_layer.link, |
| 3681 | &shell->input_panel_layer.link); |
| 3682 | wl_list_insert(&shell->input_panel_layer.link, |
| 3683 | &ws->layer.link); |
| 3684 | } else { |
| 3685 | wl_list_insert(&shell->panel_layer.link, &ws->layer.link); |
| 3686 | } |
Pekka Paalanen | f0fc70d | 2011-11-15 13:34:54 +0200 | [diff] [blame] | 3687 | |
Kristian Høgsberg | 2f5faff | 2012-07-31 16:36:34 -0400 | [diff] [blame] | 3688 | restore_focus_state(shell, get_current_workspace(shell)); |
Jonas Ådahl | 0476974 | 2012-06-13 00:01:24 +0200 | [diff] [blame] | 3689 | |
Pekka Paalanen | f0fc70d | 2011-11-15 13:34:54 +0200 | [diff] [blame] | 3690 | shell->locked = false; |
Ander Conselvan de Oliveira | 87524b6 | 2013-02-21 18:35:22 +0200 | [diff] [blame] | 3691 | shell_fade(shell, FADE_IN); |
Pekka Paalanen | fc6d91a | 2012-02-10 15:33:10 +0200 | [diff] [blame] | 3692 | weston_compositor_damage_all(shell->compositor); |
Pekka Paalanen | 9ef3e01 | 2011-11-15 13:34:48 +0200 | [diff] [blame] | 3693 | } |
| 3694 | |
| 3695 | static void |
| 3696 | desktop_shell_unlock(struct wl_client *client, |
| 3697 | struct wl_resource *resource) |
| 3698 | { |
Jason Ekstrand | 651f00e | 2013-06-14 10:07:54 -0500 | [diff] [blame] | 3699 | struct desktop_shell *shell = wl_resource_get_user_data(resource); |
Pekka Paalanen | 9ef3e01 | 2011-11-15 13:34:48 +0200 | [diff] [blame] | 3700 | |
Pekka Paalanen | 9ef3e01 | 2011-11-15 13:34:48 +0200 | [diff] [blame] | 3701 | shell->prepare_event_sent = false; |
Pekka Paalanen | f0fc70d | 2011-11-15 13:34:54 +0200 | [diff] [blame] | 3702 | |
| 3703 | if (shell->locked) |
| 3704 | resume_desktop(shell); |
Pekka Paalanen | 9ef3e01 | 2011-11-15 13:34:48 +0200 | [diff] [blame] | 3705 | } |
| 3706 | |
Kristian Høgsberg | d56bd90 | 2012-06-05 09:58:51 -0400 | [diff] [blame] | 3707 | static void |
Ander Conselvan de Oliveira | b9d2a0f | 2012-06-28 18:08:05 +0300 | [diff] [blame] | 3708 | desktop_shell_set_grab_surface(struct wl_client *client, |
Kristian Høgsberg | d56bd90 | 2012-06-05 09:58:51 -0400 | [diff] [blame] | 3709 | struct wl_resource *resource, |
| 3710 | struct wl_resource *surface_resource) |
| 3711 | { |
Jason Ekstrand | 651f00e | 2013-06-14 10:07:54 -0500 | [diff] [blame] | 3712 | struct desktop_shell *shell = wl_resource_get_user_data(resource); |
Kristian Høgsberg | d56bd90 | 2012-06-05 09:58:51 -0400 | [diff] [blame] | 3713 | |
Jason Ekstrand | 0f2ef7e | 2013-06-14 10:07:53 -0500 | [diff] [blame] | 3714 | shell->grab_surface = wl_resource_get_user_data(surface_resource); |
Kristian Høgsberg | 48588f8 | 2013-10-24 15:51:35 -0700 | [diff] [blame] | 3715 | weston_view_create(shell->grab_surface); |
Kristian Høgsberg | d56bd90 | 2012-06-05 09:58:51 -0400 | [diff] [blame] | 3716 | } |
| 3717 | |
Pekka Paalanen | 79346ab | 2013-05-22 18:03:09 +0300 | [diff] [blame] | 3718 | static void |
| 3719 | desktop_shell_desktop_ready(struct wl_client *client, |
| 3720 | struct wl_resource *resource) |
| 3721 | { |
Jason Ekstrand | 651f00e | 2013-06-14 10:07:54 -0500 | [diff] [blame] | 3722 | struct desktop_shell *shell = wl_resource_get_user_data(resource); |
Pekka Paalanen | 79346ab | 2013-05-22 18:03:09 +0300 | [diff] [blame] | 3723 | |
| 3724 | shell_fade_startup(shell); |
| 3725 | } |
| 3726 | |
Kristian Høgsberg | 7584062 | 2011-09-06 13:48:16 -0400 | [diff] [blame] | 3727 | static const struct desktop_shell_interface desktop_shell_implementation = { |
| 3728 | desktop_shell_set_background, |
Pekka Paalanen | 9ef3e01 | 2011-11-15 13:34:48 +0200 | [diff] [blame] | 3729 | desktop_shell_set_panel, |
| 3730 | desktop_shell_set_lock_surface, |
Kristian Høgsberg | d56bd90 | 2012-06-05 09:58:51 -0400 | [diff] [blame] | 3731 | desktop_shell_unlock, |
Pekka Paalanen | 79346ab | 2013-05-22 18:03:09 +0300 | [diff] [blame] | 3732 | desktop_shell_set_grab_surface, |
| 3733 | desktop_shell_desktop_ready |
Kristian Høgsberg | 7584062 | 2011-09-06 13:48:16 -0400 | [diff] [blame] | 3734 | }; |
| 3735 | |
Pekka Paalanen | 92a0dc4 | 2011-11-28 15:34:13 +0200 | [diff] [blame] | 3736 | static enum shell_surface_type |
Kristian Høgsberg | 8334bc1 | 2012-01-03 10:29:47 -0500 | [diff] [blame] | 3737 | get_shell_surface_type(struct weston_surface *surface) |
Pekka Paalanen | 92a0dc4 | 2011-11-28 15:34:13 +0200 | [diff] [blame] | 3738 | { |
| 3739 | struct shell_surface *shsurf; |
| 3740 | |
| 3741 | shsurf = get_shell_surface(surface); |
| 3742 | if (!shsurf) |
Pekka Paalanen | 9826223 | 2011-12-01 10:42:22 +0200 | [diff] [blame] | 3743 | return SHELL_SURFACE_NONE; |
Pekka Paalanen | 92a0dc4 | 2011-11-28 15:34:13 +0200 | [diff] [blame] | 3744 | return shsurf->type; |
| 3745 | } |
| 3746 | |
Kristian Høgsberg | 7584062 | 2011-09-06 13:48:16 -0400 | [diff] [blame] | 3747 | static void |
Kristian Høgsberg | e314875 | 2013-05-06 23:19:49 -0400 | [diff] [blame] | 3748 | 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] | 3749 | { |
Rafal Mielniczuk | b2917a2 | 2014-01-05 20:04:59 +0100 | [diff] [blame^] | 3750 | struct weston_surface *focus; |
Pekka Paalanen | 01388e2 | 2013-04-25 13:57:44 +0300 | [diff] [blame] | 3751 | struct weston_surface *surface; |
Kristian Høgsberg | 938b8fa | 2012-05-18 13:46:27 -0400 | [diff] [blame] | 3752 | struct shell_surface *shsurf; |
Kristian Høgsberg | d2abb83 | 2011-11-23 10:52:40 -0500 | [diff] [blame] | 3753 | |
Rafal Mielniczuk | b2917a2 | 2014-01-05 20:04:59 +0100 | [diff] [blame^] | 3754 | if (seat->pointer->focus == NULL) |
| 3755 | return; |
| 3756 | |
| 3757 | focus = seat->pointer->focus->surface; |
| 3758 | |
Pekka Paalanen | 01388e2 | 2013-04-25 13:57:44 +0300 | [diff] [blame] | 3759 | surface = weston_surface_get_main_surface(focus); |
Benjamin Franzke | d0f79ab | 2011-11-22 12:43:52 +0100 | [diff] [blame] | 3760 | if (surface == NULL) |
| 3761 | return; |
Kristian Høgsberg | 0793756 | 2011-04-12 17:25:42 -0400 | [diff] [blame] | 3762 | |
Kristian Høgsberg | 938b8fa | 2012-05-18 13:46:27 -0400 | [diff] [blame] | 3763 | shsurf = get_shell_surface(surface); |
Rafael Antognolli | 03b1659 | 2013-12-03 15:35:42 -0200 | [diff] [blame] | 3764 | if (shsurf == NULL || shsurf->state.fullscreen || |
| 3765 | shsurf->state.maximized) |
Kristian Høgsberg | 938b8fa | 2012-05-18 13:46:27 -0400 | [diff] [blame] | 3766 | return; |
| 3767 | |
Kristian Høgsberg | 938b8fa | 2012-05-18 13:46:27 -0400 | [diff] [blame] | 3768 | surface_move(shsurf, (struct weston_seat *) seat); |
Kristian Høgsberg | 0793756 | 2011-04-12 17:25:42 -0400 | [diff] [blame] | 3769 | } |
| 3770 | |
| 3771 | static void |
Rafael Antognolli | ea997ac | 2013-12-03 15:35:48 -0200 | [diff] [blame] | 3772 | maximize_binding(struct weston_seat *seat, uint32_t time, uint32_t button, void *data) |
| 3773 | { |
| 3774 | struct weston_surface *focus = seat->pointer->focus->surface; |
| 3775 | struct weston_surface *surface; |
| 3776 | struct shell_surface *shsurf; |
| 3777 | |
| 3778 | surface = weston_surface_get_main_surface(focus); |
| 3779 | if (surface == NULL) |
| 3780 | return; |
| 3781 | |
| 3782 | shsurf = get_shell_surface(surface); |
| 3783 | if (shsurf == NULL) |
| 3784 | return; |
| 3785 | |
| 3786 | if (!shell_surface_is_xdg_surface(shsurf)) |
| 3787 | return; |
| 3788 | |
| 3789 | if (shsurf->state.maximized) |
| 3790 | xdg_surface_send_request_unset_maximized(shsurf->resource); |
| 3791 | else |
| 3792 | xdg_surface_send_request_set_maximized(shsurf->resource); |
| 3793 | } |
| 3794 | |
| 3795 | static void |
| 3796 | fullscreen_binding(struct weston_seat *seat, uint32_t time, uint32_t button, void *data) |
| 3797 | { |
| 3798 | struct weston_surface *focus = seat->pointer->focus->surface; |
| 3799 | struct weston_surface *surface; |
| 3800 | struct shell_surface *shsurf; |
| 3801 | |
| 3802 | surface = weston_surface_get_main_surface(focus); |
| 3803 | if (surface == NULL) |
| 3804 | return; |
| 3805 | |
| 3806 | shsurf = get_shell_surface(surface); |
| 3807 | if (shsurf == NULL) |
| 3808 | return; |
| 3809 | |
| 3810 | if (!shell_surface_is_xdg_surface(shsurf)) |
| 3811 | return; |
| 3812 | |
| 3813 | if (shsurf->state.fullscreen) |
| 3814 | xdg_surface_send_request_unset_fullscreen(shsurf->resource); |
| 3815 | else |
| 3816 | xdg_surface_send_request_set_fullscreen(shsurf->resource); |
| 3817 | } |
| 3818 | |
| 3819 | static void |
Neil Roberts | aba0f25 | 2013-10-03 16:43:05 +0100 | [diff] [blame] | 3820 | touch_move_binding(struct weston_seat *seat, uint32_t time, void *data) |
| 3821 | { |
Kristian Høgsberg | 7ab139c | 2013-10-24 16:21:39 -0700 | [diff] [blame] | 3822 | struct weston_surface *focus = seat->touch->focus->surface; |
Neil Roberts | aba0f25 | 2013-10-03 16:43:05 +0100 | [diff] [blame] | 3823 | struct weston_surface *surface; |
| 3824 | struct shell_surface *shsurf; |
| 3825 | |
| 3826 | surface = weston_surface_get_main_surface(focus); |
| 3827 | if (surface == NULL) |
| 3828 | return; |
| 3829 | |
| 3830 | shsurf = get_shell_surface(surface); |
Rafael Antognolli | 03b1659 | 2013-12-03 15:35:42 -0200 | [diff] [blame] | 3831 | if (shsurf == NULL || shsurf->state.fullscreen || |
| 3832 | shsurf->state.maximized) |
Neil Roberts | aba0f25 | 2013-10-03 16:43:05 +0100 | [diff] [blame] | 3833 | return; |
| 3834 | |
| 3835 | surface_touch_move(shsurf, (struct weston_seat *) seat); |
| 3836 | } |
| 3837 | |
| 3838 | static void |
Kristian Høgsberg | e314875 | 2013-05-06 23:19:49 -0400 | [diff] [blame] | 3839 | 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] | 3840 | { |
Rafal Mielniczuk | b2917a2 | 2014-01-05 20:04:59 +0100 | [diff] [blame^] | 3841 | struct weston_surface *focus; |
Pekka Paalanen | 01388e2 | 2013-04-25 13:57:44 +0300 | [diff] [blame] | 3842 | struct weston_surface *surface; |
Kristian Høgsberg | 0793756 | 2011-04-12 17:25:42 -0400 | [diff] [blame] | 3843 | uint32_t edges = 0; |
| 3844 | int32_t x, y; |
Pekka Paalanen | 9d1613e | 2011-11-25 12:09:16 +0200 | [diff] [blame] | 3845 | struct shell_surface *shsurf; |
Kristian Høgsberg | d2abb83 | 2011-11-23 10:52:40 -0500 | [diff] [blame] | 3846 | |
Rafal Mielniczuk | b2917a2 | 2014-01-05 20:04:59 +0100 | [diff] [blame^] | 3847 | if (seat->pointer->focus == NULL) |
| 3848 | return; |
| 3849 | |
| 3850 | focus = seat->pointer->focus->surface; |
| 3851 | |
Pekka Paalanen | 01388e2 | 2013-04-25 13:57:44 +0300 | [diff] [blame] | 3852 | surface = weston_surface_get_main_surface(focus); |
Benjamin Franzke | d0f79ab | 2011-11-22 12:43:52 +0100 | [diff] [blame] | 3853 | if (surface == NULL) |
| 3854 | return; |
Pekka Paalanen | 92a0dc4 | 2011-11-28 15:34:13 +0200 | [diff] [blame] | 3855 | |
Pekka Paalanen | 9d1613e | 2011-11-25 12:09:16 +0200 | [diff] [blame] | 3856 | shsurf = get_shell_surface(surface); |
Rafael Antognolli | 03b1659 | 2013-12-03 15:35:42 -0200 | [diff] [blame] | 3857 | if (shsurf == NULL || shsurf->state.fullscreen || |
| 3858 | shsurf->state.maximized) |
Pekka Paalanen | 92a0dc4 | 2011-11-28 15:34:13 +0200 | [diff] [blame] | 3859 | return; |
| 3860 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 3861 | weston_view_from_global(shsurf->view, |
| 3862 | wl_fixed_to_int(seat->pointer->grab_x), |
| 3863 | wl_fixed_to_int(seat->pointer->grab_y), |
| 3864 | &x, &y); |
Kristian Høgsberg | 0793756 | 2011-04-12 17:25:42 -0400 | [diff] [blame] | 3865 | |
Jason Ekstrand | 918f2dd | 2013-12-02 21:01:53 -0600 | [diff] [blame] | 3866 | if (x < shsurf->surface->width / 3) |
Pekka Paalanen | 9d1613e | 2011-11-25 12:09:16 +0200 | [diff] [blame] | 3867 | edges |= WL_SHELL_SURFACE_RESIZE_LEFT; |
Jason Ekstrand | 918f2dd | 2013-12-02 21:01:53 -0600 | [diff] [blame] | 3868 | else if (x < 2 * shsurf->surface->width / 3) |
Kristian Høgsberg | 0793756 | 2011-04-12 17:25:42 -0400 | [diff] [blame] | 3869 | edges |= 0; |
| 3870 | else |
Pekka Paalanen | 9d1613e | 2011-11-25 12:09:16 +0200 | [diff] [blame] | 3871 | edges |= WL_SHELL_SURFACE_RESIZE_RIGHT; |
Kristian Høgsberg | 0793756 | 2011-04-12 17:25:42 -0400 | [diff] [blame] | 3872 | |
Jason Ekstrand | 918f2dd | 2013-12-02 21:01:53 -0600 | [diff] [blame] | 3873 | if (y < shsurf->surface->height / 3) |
Pekka Paalanen | 9d1613e | 2011-11-25 12:09:16 +0200 | [diff] [blame] | 3874 | edges |= WL_SHELL_SURFACE_RESIZE_TOP; |
Jason Ekstrand | 918f2dd | 2013-12-02 21:01:53 -0600 | [diff] [blame] | 3875 | else if (y < 2 * shsurf->surface->height / 3) |
Kristian Høgsberg | 0793756 | 2011-04-12 17:25:42 -0400 | [diff] [blame] | 3876 | edges |= 0; |
| 3877 | else |
Pekka Paalanen | 9d1613e | 2011-11-25 12:09:16 +0200 | [diff] [blame] | 3878 | edges |= WL_SHELL_SURFACE_RESIZE_BOTTOM; |
Kristian Høgsberg | 0793756 | 2011-04-12 17:25:42 -0400 | [diff] [blame] | 3879 | |
Kristian Høgsberg | c1693f2 | 2012-05-22 16:56:23 -0400 | [diff] [blame] | 3880 | surface_resize(shsurf, (struct weston_seat *) seat, edges); |
Kristian Høgsberg | 02ec0a5 | 2011-04-23 13:04:11 -0400 | [diff] [blame] | 3881 | } |
| 3882 | |
| 3883 | static void |
Kristian Høgsberg | e314875 | 2013-05-06 23:19:49 -0400 | [diff] [blame] | 3884 | 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] | 3885 | wl_fixed_t value, void *data) |
Scott Moreau | a3aa9c9 | 2012-03-22 11:01:03 -0600 | [diff] [blame] | 3886 | { |
Jonas Ådahl | b0b87ba | 2012-09-27 18:40:42 +0200 | [diff] [blame] | 3887 | float step = 0.005; |
Scott Moreau | a3aa9c9 | 2012-03-22 11:01:03 -0600 | [diff] [blame] | 3888 | struct shell_surface *shsurf; |
Kristian Høgsberg | 7ab139c | 2013-10-24 16:21:39 -0700 | [diff] [blame] | 3889 | struct weston_surface *focus = seat->pointer->focus->surface; |
Pekka Paalanen | 01388e2 | 2013-04-25 13:57:44 +0300 | [diff] [blame] | 3890 | struct weston_surface *surface; |
Scott Moreau | a3aa9c9 | 2012-03-22 11:01:03 -0600 | [diff] [blame] | 3891 | |
Pekka Paalanen | 01388e2 | 2013-04-25 13:57:44 +0300 | [diff] [blame] | 3892 | /* XXX: broken for windows containing sub-surfaces */ |
| 3893 | surface = weston_surface_get_main_surface(focus); |
Scott Moreau | a3aa9c9 | 2012-03-22 11:01:03 -0600 | [diff] [blame] | 3894 | if (surface == NULL) |
| 3895 | return; |
| 3896 | |
| 3897 | shsurf = get_shell_surface(surface); |
| 3898 | if (!shsurf) |
| 3899 | return; |
| 3900 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 3901 | shsurf->view->alpha -= wl_fixed_to_double(value) * step; |
Scott Moreau | a3aa9c9 | 2012-03-22 11:01:03 -0600 | [diff] [blame] | 3902 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 3903 | if (shsurf->view->alpha > 1.0) |
| 3904 | shsurf->view->alpha = 1.0; |
| 3905 | if (shsurf->view->alpha < step) |
| 3906 | shsurf->view->alpha = step; |
Scott Moreau | a3aa9c9 | 2012-03-22 11:01:03 -0600 | [diff] [blame] | 3907 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 3908 | weston_view_geometry_dirty(shsurf->view); |
Scott Moreau | a3aa9c9 | 2012-03-22 11:01:03 -0600 | [diff] [blame] | 3909 | weston_surface_damage(surface); |
| 3910 | } |
| 3911 | |
| 3912 | static void |
Kristian Høgsberg | e314875 | 2013-05-06 23:19:49 -0400 | [diff] [blame] | 3913 | 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] | 3914 | wl_fixed_t value) |
Scott Moreau | ccbf29d | 2012-02-22 14:21:41 -0700 | [diff] [blame] | 3915 | { |
Daniel Stone | 37816df | 2012-05-16 18:45:18 +0100 | [diff] [blame] | 3916 | struct weston_seat *ws = (struct weston_seat *) seat; |
| 3917 | struct weston_compositor *compositor = ws->compositor; |
Scott Moreau | ccbf29d | 2012-02-22 14:21:41 -0700 | [diff] [blame] | 3918 | struct weston_output *output; |
Scott Moreau | e660398 | 2012-06-11 13:07:51 -0600 | [diff] [blame] | 3919 | float increment; |
Scott Moreau | ccbf29d | 2012-02-22 14:21:41 -0700 | [diff] [blame] | 3920 | |
| 3921 | wl_list_for_each(output, &compositor->output_list, link) { |
| 3922 | if (pixman_region32_contains_point(&output->region, |
Daniel Stone | 37816df | 2012-05-16 18:45:18 +0100 | [diff] [blame] | 3923 | wl_fixed_to_double(seat->pointer->x), |
| 3924 | wl_fixed_to_double(seat->pointer->y), |
Daniel Stone | 103db7f | 2012-05-08 17:17:55 +0100 | [diff] [blame] | 3925 | NULL)) { |
Daniel Stone | 325fc2d | 2012-05-30 16:31:58 +0100 | [diff] [blame] | 3926 | if (key == KEY_PAGEUP) |
Kristian Høgsberg | 9b68af0 | 2012-05-22 12:55:18 -0400 | [diff] [blame] | 3927 | increment = output->zoom.increment; |
Daniel Stone | 325fc2d | 2012-05-30 16:31:58 +0100 | [diff] [blame] | 3928 | else if (key == KEY_PAGEDOWN) |
Kristian Høgsberg | 9b68af0 | 2012-05-22 12:55:18 -0400 | [diff] [blame] | 3929 | increment = -output->zoom.increment; |
| 3930 | else if (axis == WL_POINTER_AXIS_VERTICAL_SCROLL) |
Jonas Ådahl | b0b87ba | 2012-09-27 18:40:42 +0200 | [diff] [blame] | 3931 | /* For every pixel zoom 20th of a step */ |
Daniel Stone | 0c1e46e | 2012-05-30 16:31:59 +0100 | [diff] [blame] | 3932 | increment = output->zoom.increment * |
Jonas Ådahl | b0b87ba | 2012-09-27 18:40:42 +0200 | [diff] [blame] | 3933 | -wl_fixed_to_double(value) / 20.0; |
Kristian Høgsberg | 9b68af0 | 2012-05-22 12:55:18 -0400 | [diff] [blame] | 3934 | else |
| 3935 | increment = 0; |
| 3936 | |
Kristian Høgsberg | 9b68af0 | 2012-05-22 12:55:18 -0400 | [diff] [blame] | 3937 | output->zoom.level += increment; |
Scott Moreau | c6d7f60 | 2012-02-23 22:28:37 -0700 | [diff] [blame] | 3938 | |
Scott Moreau | e660398 | 2012-06-11 13:07:51 -0600 | [diff] [blame] | 3939 | if (output->zoom.level < 0.0) |
Scott Moreau | 850ca42 | 2012-05-21 15:21:25 -0600 | [diff] [blame] | 3940 | output->zoom.level = 0.0; |
Scott Moreau | e660398 | 2012-06-11 13:07:51 -0600 | [diff] [blame] | 3941 | else if (output->zoom.level > output->zoom.max_level) |
| 3942 | output->zoom.level = output->zoom.max_level; |
Ville Syrjälä | aa628d0 | 2012-11-16 11:48:47 +0200 | [diff] [blame] | 3943 | else if (!output->zoom.active) { |
Giulio Camuffo | 412b024 | 2013-11-14 23:42:51 +0100 | [diff] [blame] | 3944 | weston_output_activate_zoom(output); |
Kristian Høgsberg | 79af73e | 2012-08-03 15:45:23 -0400 | [diff] [blame] | 3945 | } |
Scott Moreau | ccbf29d | 2012-02-22 14:21:41 -0700 | [diff] [blame] | 3946 | |
Scott Moreau | e660398 | 2012-06-11 13:07:51 -0600 | [diff] [blame] | 3947 | output->zoom.spring_z.target = output->zoom.level; |
Scott Moreau | ccbf29d | 2012-02-22 14:21:41 -0700 | [diff] [blame] | 3948 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 3949 | weston_output_update_zoom(output); |
Scott Moreau | ccbf29d | 2012-02-22 14:21:41 -0700 | [diff] [blame] | 3950 | } |
| 3951 | } |
| 3952 | } |
| 3953 | |
Scott Moreau | ccbf29d | 2012-02-22 14:21:41 -0700 | [diff] [blame] | 3954 | static void |
Kristian Høgsberg | e314875 | 2013-05-06 23:19:49 -0400 | [diff] [blame] | 3955 | 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] | 3956 | wl_fixed_t value, void *data) |
Daniel Stone | 325fc2d | 2012-05-30 16:31:58 +0100 | [diff] [blame] | 3957 | { |
| 3958 | do_zoom(seat, time, 0, axis, value); |
| 3959 | } |
| 3960 | |
| 3961 | static void |
Kristian Høgsberg | e314875 | 2013-05-06 23:19:49 -0400 | [diff] [blame] | 3962 | 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] | 3963 | void *data) |
| 3964 | { |
| 3965 | do_zoom(seat, time, key, 0, 0); |
| 3966 | } |
| 3967 | |
| 3968 | static void |
Kristian Høgsberg | e314875 | 2013-05-06 23:19:49 -0400 | [diff] [blame] | 3969 | terminate_binding(struct weston_seat *seat, uint32_t time, uint32_t key, |
Daniel Stone | 325fc2d | 2012-05-30 16:31:58 +0100 | [diff] [blame] | 3970 | void *data) |
Kristian Høgsberg | e1a850e | 2011-12-19 15:18:05 -0500 | [diff] [blame] | 3971 | { |
Kristian Høgsberg | 8334bc1 | 2012-01-03 10:29:47 -0500 | [diff] [blame] | 3972 | struct weston_compositor *compositor = data; |
Kristian Høgsberg | e1a850e | 2011-12-19 15:18:05 -0500 | [diff] [blame] | 3973 | |
Daniel Stone | 325fc2d | 2012-05-30 16:31:58 +0100 | [diff] [blame] | 3974 | wl_display_terminate(compositor->wl_display); |
Kristian Høgsberg | e1a850e | 2011-12-19 15:18:05 -0500 | [diff] [blame] | 3975 | } |
| 3976 | |
Emilio Pozuelo Monfort | 03251b6 | 2013-11-19 11:37:16 +0100 | [diff] [blame] | 3977 | static void |
Giulio Camuffo | 1959ab8 | 2013-11-14 23:42:52 +0100 | [diff] [blame] | 3978 | rotate_grab_motion(struct weston_pointer_grab *grab, uint32_t time, |
| 3979 | wl_fixed_t x, wl_fixed_t y) |
Pekka Paalanen | 460099f | 2012-01-20 16:48:25 +0200 | [diff] [blame] | 3980 | { |
| 3981 | struct rotate_grab *rotate = |
Ander Conselvan de Oliveira | fe0444a | 2012-04-04 17:48:05 +0300 | [diff] [blame] | 3982 | container_of(grab, struct rotate_grab, base.grab); |
Kristian Høgsberg | 02bbabb | 2013-05-06 22:15:05 -0400 | [diff] [blame] | 3983 | struct weston_pointer *pointer = grab->pointer; |
Ander Conselvan de Oliveira | fe0444a | 2012-04-04 17:48:05 +0300 | [diff] [blame] | 3984 | struct shell_surface *shsurf = rotate->base.shsurf; |
John Kåre Alsaker | 490d02a | 2012-09-30 02:57:21 +0200 | [diff] [blame] | 3985 | float cx, cy, dx, dy, cposx, cposy, dposx, dposy, r; |
Ander Conselvan de Oliveira | fe0444a | 2012-04-04 17:48:05 +0300 | [diff] [blame] | 3986 | |
Giulio Camuffo | 1959ab8 | 2013-11-14 23:42:52 +0100 | [diff] [blame] | 3987 | weston_pointer_move(pointer, x, y); |
| 3988 | |
Ander Conselvan de Oliveira | fe0444a | 2012-04-04 17:48:05 +0300 | [diff] [blame] | 3989 | if (!shsurf) |
| 3990 | return; |
| 3991 | |
Jason Ekstrand | 918f2dd | 2013-12-02 21:01:53 -0600 | [diff] [blame] | 3992 | cx = 0.5f * shsurf->surface->width; |
| 3993 | cy = 0.5f * shsurf->surface->height; |
Pekka Paalanen | 460099f | 2012-01-20 16:48:25 +0200 | [diff] [blame] | 3994 | |
Daniel Stone | 37816df | 2012-05-16 18:45:18 +0100 | [diff] [blame] | 3995 | dx = wl_fixed_to_double(pointer->x) - rotate->center.x; |
| 3996 | dy = wl_fixed_to_double(pointer->y) - rotate->center.y; |
Pekka Paalanen | 460099f | 2012-01-20 16:48:25 +0200 | [diff] [blame] | 3997 | r = sqrtf(dx * dx + dy * dy); |
| 3998 | |
Ander Conselvan de Oliveira | fe0444a | 2012-04-04 17:48:05 +0300 | [diff] [blame] | 3999 | wl_list_remove(&shsurf->rotation.transform.link); |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 4000 | weston_view_geometry_dirty(shsurf->view); |
Pekka Paalanen | 460099f | 2012-01-20 16:48:25 +0200 | [diff] [blame] | 4001 | |
| 4002 | if (r > 20.0f) { |
Pekka Paalanen | 460099f | 2012-01-20 16:48:25 +0200 | [diff] [blame] | 4003 | struct weston_matrix *matrix = |
Ander Conselvan de Oliveira | fe0444a | 2012-04-04 17:48:05 +0300 | [diff] [blame] | 4004 | &shsurf->rotation.transform.matrix; |
Pekka Paalanen | 460099f | 2012-01-20 16:48:25 +0200 | [diff] [blame] | 4005 | |
Kristian Høgsberg | 765e27b | 2012-01-27 13:36:13 -0500 | [diff] [blame] | 4006 | weston_matrix_init(&rotate->rotation); |
Vasily Khoruzhick | 1bbf372 | 2013-01-28 22:40:28 +0300 | [diff] [blame] | 4007 | weston_matrix_rotate_xy(&rotate->rotation, dx / r, dy / r); |
Pekka Paalanen | 460099f | 2012-01-20 16:48:25 +0200 | [diff] [blame] | 4008 | |
| 4009 | weston_matrix_init(matrix); |
Pekka Paalanen | 7b3bd3d | 2012-01-30 14:16:34 +0200 | [diff] [blame] | 4010 | weston_matrix_translate(matrix, -cx, -cy, 0.0f); |
Ander Conselvan de Oliveira | fe0444a | 2012-04-04 17:48:05 +0300 | [diff] [blame] | 4011 | weston_matrix_multiply(matrix, &shsurf->rotation.rotation); |
Kristian Høgsberg | 765e27b | 2012-01-27 13:36:13 -0500 | [diff] [blame] | 4012 | weston_matrix_multiply(matrix, &rotate->rotation); |
Pekka Paalanen | 7b3bd3d | 2012-01-30 14:16:34 +0200 | [diff] [blame] | 4013 | weston_matrix_translate(matrix, cx, cy, 0.0f); |
Pekka Paalanen | 460099f | 2012-01-20 16:48:25 +0200 | [diff] [blame] | 4014 | |
Pekka Paalanen | bc0b7e7 | 2012-01-24 09:53:37 +0200 | [diff] [blame] | 4015 | wl_list_insert( |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 4016 | &shsurf->view->geometry.transformation_list, |
Ander Conselvan de Oliveira | fe0444a | 2012-04-04 17:48:05 +0300 | [diff] [blame] | 4017 | &shsurf->rotation.transform.link); |
Pekka Paalanen | 460099f | 2012-01-20 16:48:25 +0200 | [diff] [blame] | 4018 | } else { |
Ander Conselvan de Oliveira | fe0444a | 2012-04-04 17:48:05 +0300 | [diff] [blame] | 4019 | wl_list_init(&shsurf->rotation.transform.link); |
| 4020 | weston_matrix_init(&shsurf->rotation.rotation); |
Kristian Høgsberg | 765e27b | 2012-01-27 13:36:13 -0500 | [diff] [blame] | 4021 | weston_matrix_init(&rotate->rotation); |
Pekka Paalanen | 460099f | 2012-01-20 16:48:25 +0200 | [diff] [blame] | 4022 | } |
Pekka Paalanen | b45ac5e | 2012-02-09 15:58:44 +0200 | [diff] [blame] | 4023 | |
Rafal Mielniczuk | 2d7ab82 | 2012-03-22 22:22:04 +0100 | [diff] [blame] | 4024 | /* We need to adjust the position of the surface |
| 4025 | * in case it was resized in a rotated state before */ |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 4026 | cposx = shsurf->view->geometry.x + cx; |
| 4027 | cposy = shsurf->view->geometry.y + cy; |
Rafal Mielniczuk | 2d7ab82 | 2012-03-22 22:22:04 +0100 | [diff] [blame] | 4028 | dposx = rotate->center.x - cposx; |
| 4029 | dposy = rotate->center.y - cposy; |
| 4030 | if (dposx != 0.0f || dposy != 0.0f) { |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 4031 | weston_view_set_position(shsurf->view, |
| 4032 | shsurf->view->geometry.x + dposx, |
| 4033 | shsurf->view->geometry.y + dposy); |
Rafal Mielniczuk | 2d7ab82 | 2012-03-22 22:22:04 +0100 | [diff] [blame] | 4034 | } |
| 4035 | |
Pekka Paalanen | b45ac5e | 2012-02-09 15:58:44 +0200 | [diff] [blame] | 4036 | /* Repaint implies weston_surface_update_transform(), which |
| 4037 | * lazily applies the damage due to rotation update. |
| 4038 | */ |
Ander Conselvan de Oliveira | fe0444a | 2012-04-04 17:48:05 +0300 | [diff] [blame] | 4039 | weston_compositor_schedule_repaint(shsurf->surface->compositor); |
Pekka Paalanen | 460099f | 2012-01-20 16:48:25 +0200 | [diff] [blame] | 4040 | } |
| 4041 | |
| 4042 | static void |
Kristian Høgsberg | 02bbabb | 2013-05-06 22:15:05 -0400 | [diff] [blame] | 4043 | rotate_grab_button(struct weston_pointer_grab *grab, |
| 4044 | uint32_t time, uint32_t button, uint32_t state_w) |
Pekka Paalanen | 460099f | 2012-01-20 16:48:25 +0200 | [diff] [blame] | 4045 | { |
| 4046 | struct rotate_grab *rotate = |
Ander Conselvan de Oliveira | fe0444a | 2012-04-04 17:48:05 +0300 | [diff] [blame] | 4047 | container_of(grab, struct rotate_grab, base.grab); |
Kristian Høgsberg | 02bbabb | 2013-05-06 22:15:05 -0400 | [diff] [blame] | 4048 | struct weston_pointer *pointer = grab->pointer; |
Ander Conselvan de Oliveira | fe0444a | 2012-04-04 17:48:05 +0300 | [diff] [blame] | 4049 | struct shell_surface *shsurf = rotate->base.shsurf; |
Daniel Stone | 4dbadb1 | 2012-05-30 16:31:51 +0100 | [diff] [blame] | 4050 | enum wl_pointer_button_state state = state_w; |
Pekka Paalanen | 460099f | 2012-01-20 16:48:25 +0200 | [diff] [blame] | 4051 | |
Daniel Stone | 4dbadb1 | 2012-05-30 16:31:51 +0100 | [diff] [blame] | 4052 | if (pointer->button_count == 0 && |
| 4053 | state == WL_POINTER_BUTTON_STATE_RELEASED) { |
Ander Conselvan de Oliveira | fe0444a | 2012-04-04 17:48:05 +0300 | [diff] [blame] | 4054 | if (shsurf) |
| 4055 | weston_matrix_multiply(&shsurf->rotation.rotation, |
| 4056 | &rotate->rotation); |
Ander Conselvan de Oliveira | b9d2a0f | 2012-06-28 18:08:05 +0300 | [diff] [blame] | 4057 | shell_grab_end(&rotate->base); |
Pekka Paalanen | 460099f | 2012-01-20 16:48:25 +0200 | [diff] [blame] | 4058 | free(rotate); |
| 4059 | } |
| 4060 | } |
| 4061 | |
Jonas Ådahl | 1ea343e | 2013-10-25 23:18:05 +0200 | [diff] [blame] | 4062 | static void |
| 4063 | rotate_grab_cancel(struct weston_pointer_grab *grab) |
| 4064 | { |
| 4065 | struct rotate_grab *rotate = |
| 4066 | container_of(grab, struct rotate_grab, base.grab); |
| 4067 | |
| 4068 | shell_grab_end(&rotate->base); |
| 4069 | free(rotate); |
| 4070 | } |
| 4071 | |
Kristian Høgsberg | 02bbabb | 2013-05-06 22:15:05 -0400 | [diff] [blame] | 4072 | static const struct weston_pointer_grab_interface rotate_grab_interface = { |
Pekka Paalanen | 460099f | 2012-01-20 16:48:25 +0200 | [diff] [blame] | 4073 | noop_grab_focus, |
| 4074 | rotate_grab_motion, |
| 4075 | rotate_grab_button, |
Jonas Ådahl | 1ea343e | 2013-10-25 23:18:05 +0200 | [diff] [blame] | 4076 | rotate_grab_cancel, |
Pekka Paalanen | 460099f | 2012-01-20 16:48:25 +0200 | [diff] [blame] | 4077 | }; |
| 4078 | |
| 4079 | static void |
Kristian Høgsberg | e314875 | 2013-05-06 23:19:49 -0400 | [diff] [blame] | 4080 | surface_rotate(struct shell_surface *surface, struct weston_seat *seat) |
Pekka Paalanen | 460099f | 2012-01-20 16:48:25 +0200 | [diff] [blame] | 4081 | { |
Pekka Paalanen | 460099f | 2012-01-20 16:48:25 +0200 | [diff] [blame] | 4082 | struct rotate_grab *rotate; |
John Kåre Alsaker | 490d02a | 2012-09-30 02:57:21 +0200 | [diff] [blame] | 4083 | float dx, dy; |
| 4084 | float r; |
Pekka Paalanen | 460099f | 2012-01-20 16:48:25 +0200 | [diff] [blame] | 4085 | |
Pekka Paalanen | 460099f | 2012-01-20 16:48:25 +0200 | [diff] [blame] | 4086 | rotate = malloc(sizeof *rotate); |
| 4087 | if (!rotate) |
| 4088 | return; |
| 4089 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 4090 | weston_view_to_global_float(surface->view, |
Jason Ekstrand | 918f2dd | 2013-12-02 21:01:53 -0600 | [diff] [blame] | 4091 | surface->surface->width * 0.5f, |
| 4092 | surface->surface->height * 0.5f, |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 4093 | &rotate->center.x, &rotate->center.y); |
Pekka Paalanen | 460099f | 2012-01-20 16:48:25 +0200 | [diff] [blame] | 4094 | |
Daniel Stone | 37816df | 2012-05-16 18:45:18 +0100 | [diff] [blame] | 4095 | dx = wl_fixed_to_double(seat->pointer->x) - rotate->center.x; |
| 4096 | dy = wl_fixed_to_double(seat->pointer->y) - rotate->center.y; |
Kristian Høgsberg | 765e27b | 2012-01-27 13:36:13 -0500 | [diff] [blame] | 4097 | r = sqrtf(dx * dx + dy * dy); |
| 4098 | if (r > 20.0f) { |
| 4099 | struct weston_matrix inverse; |
| 4100 | |
| 4101 | weston_matrix_init(&inverse); |
Vasily Khoruzhick | 1bbf372 | 2013-01-28 22:40:28 +0300 | [diff] [blame] | 4102 | weston_matrix_rotate_xy(&inverse, dx / r, -dy / r); |
Kristian Høgsberg | 765e27b | 2012-01-27 13:36:13 -0500 | [diff] [blame] | 4103 | weston_matrix_multiply(&surface->rotation.rotation, &inverse); |
Rafal Mielniczuk | 2d7ab82 | 2012-03-22 22:22:04 +0100 | [diff] [blame] | 4104 | |
| 4105 | weston_matrix_init(&rotate->rotation); |
Vasily Khoruzhick | 1bbf372 | 2013-01-28 22:40:28 +0300 | [diff] [blame] | 4106 | weston_matrix_rotate_xy(&rotate->rotation, dx / r, dy / r); |
Kristian Høgsberg | 765e27b | 2012-01-27 13:36:13 -0500 | [diff] [blame] | 4107 | } else { |
| 4108 | weston_matrix_init(&surface->rotation.rotation); |
| 4109 | weston_matrix_init(&rotate->rotation); |
| 4110 | } |
| 4111 | |
Ander Conselvan de Oliveira | b9d2a0f | 2012-06-28 18:08:05 +0300 | [diff] [blame] | 4112 | shell_grab_start(&rotate->base, &rotate_grab_interface, surface, |
| 4113 | seat->pointer, DESKTOP_SHELL_CURSOR_ARROW); |
Pekka Paalanen | 460099f | 2012-01-20 16:48:25 +0200 | [diff] [blame] | 4114 | } |
| 4115 | |
| 4116 | static void |
Kristian Høgsberg | e314875 | 2013-05-06 23:19:49 -0400 | [diff] [blame] | 4117 | 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] | 4118 | void *data) |
| 4119 | { |
Rafal Mielniczuk | b2917a2 | 2014-01-05 20:04:59 +0100 | [diff] [blame^] | 4120 | struct weston_surface *focus; |
Pekka Paalanen | 01388e2 | 2013-04-25 13:57:44 +0300 | [diff] [blame] | 4121 | struct weston_surface *base_surface; |
Kristian Høgsberg | 0c36903 | 2013-02-14 21:31:44 -0500 | [diff] [blame] | 4122 | struct shell_surface *surface; |
| 4123 | |
Rafal Mielniczuk | b2917a2 | 2014-01-05 20:04:59 +0100 | [diff] [blame^] | 4124 | if (seat->pointer->focus == NULL) |
| 4125 | return; |
| 4126 | |
| 4127 | focus = seat->pointer->focus->surface; |
| 4128 | |
Pekka Paalanen | 01388e2 | 2013-04-25 13:57:44 +0300 | [diff] [blame] | 4129 | base_surface = weston_surface_get_main_surface(focus); |
Kristian Høgsberg | 0c36903 | 2013-02-14 21:31:44 -0500 | [diff] [blame] | 4130 | if (base_surface == NULL) |
| 4131 | return; |
| 4132 | |
| 4133 | surface = get_shell_surface(base_surface); |
Rafael Antognolli | 03b1659 | 2013-12-03 15:35:42 -0200 | [diff] [blame] | 4134 | if (surface == NULL || surface->state.fullscreen || |
| 4135 | surface->state.maximized) |
Kristian Høgsberg | 0c36903 | 2013-02-14 21:31:44 -0500 | [diff] [blame] | 4136 | return; |
| 4137 | |
| 4138 | surface_rotate(surface, seat); |
| 4139 | } |
| 4140 | |
Philip Withnall | 83ffd9d | 2013-11-25 18:01:42 +0000 | [diff] [blame] | 4141 | /* Move all fullscreen layers down to the current workspace in a non-reversible |
| 4142 | * manner. This should be used when implementing shell-wide overlays, such as |
| 4143 | * the alt-tab switcher, which need to de-promote fullscreen layers. */ |
Kristian Høgsberg | 1ef2313 | 2013-12-04 00:20:01 -0800 | [diff] [blame] | 4144 | void |
Kristian Høgsberg | b0d8e77 | 2012-06-18 16:34:58 -0400 | [diff] [blame] | 4145 | lower_fullscreen_layer(struct desktop_shell *shell) |
| 4146 | { |
| 4147 | struct workspace *ws; |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 4148 | struct weston_view *view, *prev; |
Kristian Høgsberg | b0d8e77 | 2012-06-18 16:34:58 -0400 | [diff] [blame] | 4149 | |
| 4150 | ws = get_current_workspace(shell); |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 4151 | wl_list_for_each_reverse_safe(view, prev, |
| 4152 | &shell->fullscreen_layer.view_list, |
Philip Withnall | 83ffd9d | 2013-11-25 18:01:42 +0000 | [diff] [blame] | 4153 | layer_link) { |
| 4154 | wl_list_remove(&view->layer_link); |
| 4155 | wl_list_insert(&ws->layer.view_list, &view->layer_link); |
| 4156 | weston_view_damage_below(view); |
| 4157 | weston_surface_damage(view->surface); |
| 4158 | } |
Kristian Høgsberg | b0d8e77 | 2012-06-18 16:34:58 -0400 | [diff] [blame] | 4159 | } |
| 4160 | |
Kristian Høgsberg | 1ef2313 | 2013-12-04 00:20:01 -0800 | [diff] [blame] | 4161 | void |
Tiago Vignatti | be14326 | 2012-04-16 17:31:41 +0300 | [diff] [blame] | 4162 | activate(struct desktop_shell *shell, struct weston_surface *es, |
Daniel Stone | 37816df | 2012-05-16 18:45:18 +0100 | [diff] [blame] | 4163 | struct weston_seat *seat) |
Kristian Høgsberg | 7584062 | 2011-09-06 13:48:16 -0400 | [diff] [blame] | 4164 | { |
Pekka Paalanen | 01388e2 | 2013-04-25 13:57:44 +0300 | [diff] [blame] | 4165 | struct weston_surface *main_surface; |
Kristian Høgsberg | 2f5faff | 2012-07-31 16:36:34 -0400 | [diff] [blame] | 4166 | struct focus_state *state; |
Jonas Ådahl | 8538b22 | 2012-08-29 22:13:03 +0200 | [diff] [blame] | 4167 | struct workspace *ws; |
Louis-Francis Ratté-Boulianne | b482dbd | 2013-11-19 11:37:11 +0100 | [diff] [blame] | 4168 | struct weston_surface *old_es; |
Rafael Antognolli | 03b1659 | 2013-12-03 15:35:42 -0200 | [diff] [blame] | 4169 | struct shell_surface *shsurf; |
Kristian Høgsberg | 7584062 | 2011-09-06 13:48:16 -0400 | [diff] [blame] | 4170 | |
Pekka Paalanen | 01388e2 | 2013-04-25 13:57:44 +0300 | [diff] [blame] | 4171 | main_surface = weston_surface_get_main_surface(es); |
| 4172 | |
Daniel Stone | 37816df | 2012-05-16 18:45:18 +0100 | [diff] [blame] | 4173 | weston_surface_activate(es, seat); |
Kristian Høgsberg | 7584062 | 2011-09-06 13:48:16 -0400 | [diff] [blame] | 4174 | |
Jonas Ådahl | 8538b22 | 2012-08-29 22:13:03 +0200 | [diff] [blame] | 4175 | state = ensure_focus_state(shell, seat); |
| 4176 | if (state == NULL) |
| 4177 | return; |
Kristian Høgsberg | 2f5faff | 2012-07-31 16:36:34 -0400 | [diff] [blame] | 4178 | |
Louis-Francis Ratté-Boulianne | b482dbd | 2013-11-19 11:37:11 +0100 | [diff] [blame] | 4179 | old_es = state->keyboard_focus; |
Kristian Høgsberg | 2f5faff | 2012-07-31 16:36:34 -0400 | [diff] [blame] | 4180 | state->keyboard_focus = es; |
| 4181 | wl_list_remove(&state->surface_destroy_listener.link); |
Jason Ekstrand | 26ed73c | 2013-06-06 22:34:41 -0500 | [diff] [blame] | 4182 | wl_signal_add(&es->destroy_signal, &state->surface_destroy_listener); |
Kristian Høgsberg | 2f5faff | 2012-07-31 16:36:34 -0400 | [diff] [blame] | 4183 | |
Rafael Antognolli | 03b1659 | 2013-12-03 15:35:42 -0200 | [diff] [blame] | 4184 | shsurf = get_shell_surface(main_surface); |
| 4185 | if (shsurf->state.fullscreen) |
| 4186 | shell_configure_fullscreen(shsurf); |
| 4187 | else |
Alexander Larsson | f82b6ca | 2013-05-28 16:23:39 +0200 | [diff] [blame] | 4188 | restore_all_output_modes(shell->compositor); |
Louis-Francis Ratté-Boulianne | b482dbd | 2013-11-19 11:37:11 +0100 | [diff] [blame] | 4189 | |
Philip Withnall | 83ffd9d | 2013-11-25 18:01:42 +0000 | [diff] [blame] | 4190 | if (shell->focus_animation_type != ANIMATION_NONE) { |
| 4191 | ws = get_current_workspace(shell); |
Louis-Francis Ratté-Boulianne | b482dbd | 2013-11-19 11:37:11 +0100 | [diff] [blame] | 4192 | 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] | 4193 | } |
| 4194 | |
| 4195 | /* Update the surface’s layer. This brings it to the top of the stacking |
| 4196 | * order as appropriate. */ |
| 4197 | shell_surface_update_layer(get_shell_surface(main_surface)); |
Kristian Høgsberg | 7584062 | 2011-09-06 13:48:16 -0400 | [diff] [blame] | 4198 | } |
| 4199 | |
Alex Wu | 2185843 | 2012-04-01 20:13:08 +0800 | [diff] [blame] | 4200 | /* no-op func for checking black surface */ |
| 4201 | static void |
Jason Ekstrand | 918f2dd | 2013-12-02 21:01:53 -0600 | [diff] [blame] | 4202 | 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] | 4203 | { |
| 4204 | } |
| 4205 | |
Quentin Glidic | c0d79ce | 2013-01-29 14:16:13 +0100 | [diff] [blame] | 4206 | static bool |
Alex Wu | 2185843 | 2012-04-01 20:13:08 +0800 | [diff] [blame] | 4207 | is_black_surface (struct weston_surface *es, struct weston_surface **fs_surface) |
| 4208 | { |
| 4209 | if (es->configure == black_surface_configure) { |
| 4210 | if (fs_surface) |
Giulio Camuffo | 7fe01b1 | 2013-03-28 18:02:42 +0100 | [diff] [blame] | 4211 | *fs_surface = (struct weston_surface *)es->configure_private; |
Alex Wu | 2185843 | 2012-04-01 20:13:08 +0800 | [diff] [blame] | 4212 | return true; |
| 4213 | } |
| 4214 | return false; |
| 4215 | } |
| 4216 | |
Kristian Høgsberg | 7584062 | 2011-09-06 13:48:16 -0400 | [diff] [blame] | 4217 | static void |
Neil Roberts | a28c693 | 2013-10-03 16:43:04 +0100 | [diff] [blame] | 4218 | activate_binding(struct weston_seat *seat, |
| 4219 | struct desktop_shell *shell, |
| 4220 | struct weston_surface *focus) |
Kristian Høgsberg | e1a850e | 2011-12-19 15:18:05 -0500 | [diff] [blame] | 4221 | { |
Pekka Paalanen | 01388e2 | 2013-04-25 13:57:44 +0300 | [diff] [blame] | 4222 | struct weston_surface *main_surface; |
Kristian Høgsberg | e1a850e | 2011-12-19 15:18:05 -0500 | [diff] [blame] | 4223 | |
Alex Wu | 9c35e6b | 2012-03-05 14:13:13 +0800 | [diff] [blame] | 4224 | if (!focus) |
| 4225 | return; |
| 4226 | |
Pekka Paalanen | 01388e2 | 2013-04-25 13:57:44 +0300 | [diff] [blame] | 4227 | if (is_black_surface(focus, &main_surface)) |
| 4228 | focus = main_surface; |
Alex Wu | 4539b08 | 2012-03-01 12:57:46 +0800 | [diff] [blame] | 4229 | |
Pekka Paalanen | 01388e2 | 2013-04-25 13:57:44 +0300 | [diff] [blame] | 4230 | main_surface = weston_surface_get_main_surface(focus); |
| 4231 | if (get_shell_surface_type(main_surface) == SHELL_SURFACE_NONE) |
Kristian Høgsberg | 0636ac3 | 2012-06-27 10:22:15 -0400 | [diff] [blame] | 4232 | return; |
Kristian Høgsberg | 85b2e4b | 2012-06-21 16:49:42 -0400 | [diff] [blame] | 4233 | |
Neil Roberts | a28c693 | 2013-10-03 16:43:04 +0100 | [diff] [blame] | 4234 | activate(shell, focus, seat); |
| 4235 | } |
| 4236 | |
| 4237 | static void |
| 4238 | click_to_activate_binding(struct weston_seat *seat, uint32_t time, uint32_t button, |
| 4239 | void *data) |
| 4240 | { |
| 4241 | if (seat->pointer->grab != &seat->pointer->default_grab) |
| 4242 | return; |
Kristian Høgsberg | 7c4f6cc | 2014-01-01 16:28:32 -0800 | [diff] [blame] | 4243 | if (seat->pointer->focus == NULL) |
| 4244 | return; |
Neil Roberts | a28c693 | 2013-10-03 16:43:04 +0100 | [diff] [blame] | 4245 | |
Kristian Høgsberg | 7ab139c | 2013-10-24 16:21:39 -0700 | [diff] [blame] | 4246 | activate_binding(seat, data, seat->pointer->focus->surface); |
Neil Roberts | a28c693 | 2013-10-03 16:43:04 +0100 | [diff] [blame] | 4247 | } |
| 4248 | |
| 4249 | static void |
| 4250 | touch_to_activate_binding(struct weston_seat *seat, uint32_t time, void *data) |
| 4251 | { |
| 4252 | if (seat->touch->grab != &seat->touch->default_grab) |
| 4253 | return; |
Kristian Høgsberg | 0ed6750 | 2014-01-02 23:00:11 -0800 | [diff] [blame] | 4254 | if (seat->touch->focus == NULL) |
| 4255 | return; |
Neil Roberts | a28c693 | 2013-10-03 16:43:04 +0100 | [diff] [blame] | 4256 | |
Kristian Høgsberg | 7ab139c | 2013-10-24 16:21:39 -0700 | [diff] [blame] | 4257 | activate_binding(seat, data, seat->touch->focus->surface); |
Kristian Høgsberg | e1a850e | 2011-12-19 15:18:05 -0500 | [diff] [blame] | 4258 | } |
| 4259 | |
| 4260 | static void |
Ander Conselvan de Oliveira | 19d10ef | 2013-02-21 18:35:20 +0200 | [diff] [blame] | 4261 | lock(struct desktop_shell *shell) |
Kristian Høgsberg | 02ec0a5 | 2011-04-23 13:04:11 -0400 | [diff] [blame] | 4262 | { |
Kristian Høgsberg | 4476aaf | 2012-06-25 14:03:13 -0400 | [diff] [blame] | 4263 | struct workspace *ws = get_current_workspace(shell); |
Pekka Paalanen | f0fc70d | 2011-11-15 13:34:54 +0200 | [diff] [blame] | 4264 | |
Tiago Vignatti | 8e53c7f | 2012-02-29 19:53:50 +0200 | [diff] [blame] | 4265 | if (shell->locked) { |
Ander Conselvan de Oliveira | 87524b6 | 2013-02-21 18:35:22 +0200 | [diff] [blame] | 4266 | weston_compositor_sleep(shell->compositor); |
Pekka Paalanen | f0fc70d | 2011-11-15 13:34:54 +0200 | [diff] [blame] | 4267 | return; |
Tiago Vignatti | 8e53c7f | 2012-02-29 19:53:50 +0200 | [diff] [blame] | 4268 | } |
Pekka Paalanen | 9ef3e01 | 2011-11-15 13:34:48 +0200 | [diff] [blame] | 4269 | |
| 4270 | shell->locked = true; |
Pekka Paalanen | f0fc70d | 2011-11-15 13:34:54 +0200 | [diff] [blame] | 4271 | |
Kristian Høgsberg | 3be2ce9 | 2012-02-29 12:42:35 -0500 | [diff] [blame] | 4272 | /* Hide all surfaces by removing the fullscreen, panel and |
| 4273 | * toplevel layers. This way nothing else can show or receive |
| 4274 | * input events while we are locked. */ |
Pekka Paalanen | f0fc70d | 2011-11-15 13:34:54 +0200 | [diff] [blame] | 4275 | |
Kristian Høgsberg | 3be2ce9 | 2012-02-29 12:42:35 -0500 | [diff] [blame] | 4276 | wl_list_remove(&shell->panel_layer.link); |
Kristian Høgsberg | 3be2ce9 | 2012-02-29 12:42:35 -0500 | [diff] [blame] | 4277 | wl_list_remove(&shell->fullscreen_layer.link); |
Philipp Brüschweiler | 711fda8 | 2012-08-09 18:50:43 +0200 | [diff] [blame] | 4278 | if (shell->showing_input_panels) |
| 4279 | wl_list_remove(&shell->input_panel_layer.link); |
Kristian Høgsberg | 4476aaf | 2012-06-25 14:03:13 -0400 | [diff] [blame] | 4280 | wl_list_remove(&ws->layer.link); |
Kristian Høgsberg | 3be2ce9 | 2012-02-29 12:42:35 -0500 | [diff] [blame] | 4281 | wl_list_insert(&shell->compositor->cursor_layer.link, |
| 4282 | &shell->lock_layer.link); |
Pekka Paalanen | f0fc70d | 2011-11-15 13:34:54 +0200 | [diff] [blame] | 4283 | |
Pekka Paalanen | 77346a6 | 2011-11-30 16:26:35 +0200 | [diff] [blame] | 4284 | launch_screensaver(shell); |
| 4285 | |
Pekka Paalanen | f0fc70d | 2011-11-15 13:34:54 +0200 | [diff] [blame] | 4286 | /* TODO: disable bindings that should not work while locked. */ |
| 4287 | |
| 4288 | /* All this must be undone in resume_desktop(). */ |
Pekka Paalanen | 9ef3e01 | 2011-11-15 13:34:48 +0200 | [diff] [blame] | 4289 | } |
| 4290 | |
| 4291 | static void |
Ander Conselvan de Oliveira | 19d10ef | 2013-02-21 18:35:20 +0200 | [diff] [blame] | 4292 | unlock(struct desktop_shell *shell) |
Pekka Paalanen | 9ef3e01 | 2011-11-15 13:34:48 +0200 | [diff] [blame] | 4293 | { |
Pekka Paalanen | d81c216 | 2011-11-16 13:47:34 +0200 | [diff] [blame] | 4294 | if (!shell->locked || shell->lock_surface) { |
Ander Conselvan de Oliveira | 87524b6 | 2013-02-21 18:35:22 +0200 | [diff] [blame] | 4295 | shell_fade(shell, FADE_IN); |
Pekka Paalanen | 9ef3e01 | 2011-11-15 13:34:48 +0200 | [diff] [blame] | 4296 | return; |
| 4297 | } |
| 4298 | |
| 4299 | /* If desktop-shell client has gone away, unlock immediately. */ |
| 4300 | if (!shell->child.desktop_shell) { |
Pekka Paalanen | f0fc70d | 2011-11-15 13:34:54 +0200 | [diff] [blame] | 4301 | resume_desktop(shell); |
Pekka Paalanen | 9ef3e01 | 2011-11-15 13:34:48 +0200 | [diff] [blame] | 4302 | return; |
| 4303 | } |
| 4304 | |
| 4305 | if (shell->prepare_event_sent) |
| 4306 | return; |
| 4307 | |
Kristian Høgsberg | 0b5cd0c | 2012-03-04 21:57:37 -0500 | [diff] [blame] | 4308 | desktop_shell_send_prepare_lock_surface(shell->child.desktop_shell); |
Pekka Paalanen | 9ef3e01 | 2011-11-15 13:34:48 +0200 | [diff] [blame] | 4309 | shell->prepare_event_sent = true; |
Kristian Høgsberg | 02ec0a5 | 2011-04-23 13:04:11 -0400 | [diff] [blame] | 4310 | } |
| 4311 | |
| 4312 | static void |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 4313 | shell_fade_done(struct weston_view_animation *animation, void *data) |
Ander Conselvan de Oliveira | 19d10ef | 2013-02-21 18:35:20 +0200 | [diff] [blame] | 4314 | { |
| 4315 | struct desktop_shell *shell = data; |
| 4316 | |
| 4317 | shell->fade.animation = NULL; |
| 4318 | |
| 4319 | switch (shell->fade.type) { |
| 4320 | case FADE_IN: |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 4321 | weston_surface_destroy(shell->fade.view->surface); |
| 4322 | shell->fade.view = NULL; |
Ander Conselvan de Oliveira | 19d10ef | 2013-02-21 18:35:20 +0200 | [diff] [blame] | 4323 | break; |
| 4324 | case FADE_OUT: |
Ander Conselvan de Oliveira | 19d10ef | 2013-02-21 18:35:20 +0200 | [diff] [blame] | 4325 | lock(shell); |
| 4326 | break; |
Philip Withnall | 4a86a0a | 2013-11-25 18:01:32 +0000 | [diff] [blame] | 4327 | default: |
| 4328 | break; |
Ander Conselvan de Oliveira | 19d10ef | 2013-02-21 18:35:20 +0200 | [diff] [blame] | 4329 | } |
| 4330 | } |
| 4331 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 4332 | static struct weston_view * |
Pekka Paalanen | 79346ab | 2013-05-22 18:03:09 +0300 | [diff] [blame] | 4333 | shell_fade_create_surface(struct desktop_shell *shell) |
Ander Conselvan de Oliveira | 19d10ef | 2013-02-21 18:35:20 +0200 | [diff] [blame] | 4334 | { |
| 4335 | struct weston_compositor *compositor = shell->compositor; |
| 4336 | struct weston_surface *surface; |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 4337 | struct weston_view *view; |
Pekka Paalanen | 79346ab | 2013-05-22 18:03:09 +0300 | [diff] [blame] | 4338 | |
| 4339 | surface = weston_surface_create(compositor); |
| 4340 | if (!surface) |
| 4341 | return NULL; |
| 4342 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 4343 | view = weston_view_create(surface); |
| 4344 | if (!view) { |
| 4345 | weston_surface_destroy(surface); |
| 4346 | return NULL; |
| 4347 | } |
| 4348 | |
Jason Ekstrand | 5c11a33 | 2013-12-04 20:32:03 -0600 | [diff] [blame] | 4349 | weston_surface_set_size(surface, 8192, 8192); |
Jason Ekstrand | 918f2dd | 2013-12-02 21:01:53 -0600 | [diff] [blame] | 4350 | weston_view_set_position(view, 0, 0); |
Pekka Paalanen | 79346ab | 2013-05-22 18:03:09 +0300 | [diff] [blame] | 4351 | 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] | 4352 | wl_list_insert(&compositor->fade_layer.view_list, |
| 4353 | &view->layer_link); |
Pekka Paalanen | 79346ab | 2013-05-22 18:03:09 +0300 | [diff] [blame] | 4354 | pixman_region32_init(&surface->input); |
| 4355 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 4356 | return view; |
Pekka Paalanen | 79346ab | 2013-05-22 18:03:09 +0300 | [diff] [blame] | 4357 | } |
| 4358 | |
| 4359 | static void |
| 4360 | shell_fade(struct desktop_shell *shell, enum fade_type type) |
| 4361 | { |
Ander Conselvan de Oliveira | 19d10ef | 2013-02-21 18:35:20 +0200 | [diff] [blame] | 4362 | float tint; |
| 4363 | |
| 4364 | switch (type) { |
| 4365 | case FADE_IN: |
| 4366 | tint = 0.0; |
| 4367 | break; |
| 4368 | case FADE_OUT: |
| 4369 | tint = 1.0; |
| 4370 | break; |
| 4371 | default: |
| 4372 | weston_log("shell: invalid fade type\n"); |
| 4373 | return; |
| 4374 | } |
| 4375 | |
| 4376 | shell->fade.type = type; |
| 4377 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 4378 | if (shell->fade.view == NULL) { |
| 4379 | shell->fade.view = shell_fade_create_surface(shell); |
| 4380 | if (!shell->fade.view) |
Ander Conselvan de Oliveira | 19d10ef | 2013-02-21 18:35:20 +0200 | [diff] [blame] | 4381 | return; |
| 4382 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 4383 | shell->fade.view->alpha = 1.0 - tint; |
| 4384 | weston_view_update_transform(shell->fade.view); |
Ander Conselvan de Oliveira | 19d10ef | 2013-02-21 18:35:20 +0200 | [diff] [blame] | 4385 | } |
| 4386 | |
| 4387 | if (shell->fade.animation) |
Kristian Høgsberg | 5281fb1 | 2013-06-17 10:10:28 -0400 | [diff] [blame] | 4388 | weston_fade_update(shell->fade.animation, tint); |
Ander Conselvan de Oliveira | 19d10ef | 2013-02-21 18:35:20 +0200 | [diff] [blame] | 4389 | else |
| 4390 | shell->fade.animation = |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 4391 | weston_fade_run(shell->fade.view, |
Kristian Høgsberg | 5281fb1 | 2013-06-17 10:10:28 -0400 | [diff] [blame] | 4392 | 1.0 - tint, tint, 300.0, |
Ander Conselvan de Oliveira | 19d10ef | 2013-02-21 18:35:20 +0200 | [diff] [blame] | 4393 | shell_fade_done, shell); |
| 4394 | } |
| 4395 | |
| 4396 | static void |
Pekka Paalanen | 79346ab | 2013-05-22 18:03:09 +0300 | [diff] [blame] | 4397 | do_shell_fade_startup(void *data) |
| 4398 | { |
| 4399 | struct desktop_shell *shell = data; |
| 4400 | |
Kristian Høgsberg | 724c8d9 | 2013-10-16 11:38:24 -0700 | [diff] [blame] | 4401 | if (shell->startup_animation_type == ANIMATION_FADE) |
| 4402 | shell_fade(shell, FADE_IN); |
| 4403 | else if (shell->startup_animation_type == ANIMATION_NONE) { |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 4404 | weston_surface_destroy(shell->fade.view->surface); |
| 4405 | shell->fade.view = NULL; |
Kristian Høgsberg | 724c8d9 | 2013-10-16 11:38:24 -0700 | [diff] [blame] | 4406 | } |
Pekka Paalanen | 79346ab | 2013-05-22 18:03:09 +0300 | [diff] [blame] | 4407 | } |
| 4408 | |
| 4409 | static void |
| 4410 | shell_fade_startup(struct desktop_shell *shell) |
| 4411 | { |
| 4412 | struct wl_event_loop *loop; |
| 4413 | |
| 4414 | if (!shell->fade.startup_timer) |
| 4415 | return; |
| 4416 | |
| 4417 | wl_event_source_remove(shell->fade.startup_timer); |
| 4418 | shell->fade.startup_timer = NULL; |
| 4419 | |
| 4420 | loop = wl_display_get_event_loop(shell->compositor->wl_display); |
| 4421 | wl_event_loop_add_idle(loop, do_shell_fade_startup, shell); |
| 4422 | } |
| 4423 | |
| 4424 | static int |
| 4425 | fade_startup_timeout(void *data) |
| 4426 | { |
| 4427 | struct desktop_shell *shell = data; |
| 4428 | |
| 4429 | shell_fade_startup(shell); |
| 4430 | return 0; |
| 4431 | } |
| 4432 | |
| 4433 | static void |
| 4434 | shell_fade_init(struct desktop_shell *shell) |
| 4435 | { |
| 4436 | /* Make compositor output all black, and wait for the desktop-shell |
| 4437 | * client to signal it is ready, then fade in. The timer triggers a |
| 4438 | * fade-in, in case the desktop-shell client takes too long. |
| 4439 | */ |
| 4440 | |
| 4441 | struct wl_event_loop *loop; |
| 4442 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 4443 | if (shell->fade.view != NULL) { |
Pekka Paalanen | 79346ab | 2013-05-22 18:03:09 +0300 | [diff] [blame] | 4444 | weston_log("%s: warning: fade surface already exists\n", |
| 4445 | __func__); |
| 4446 | return; |
| 4447 | } |
| 4448 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 4449 | shell->fade.view = shell_fade_create_surface(shell); |
| 4450 | if (!shell->fade.view) |
Pekka Paalanen | 79346ab | 2013-05-22 18:03:09 +0300 | [diff] [blame] | 4451 | return; |
| 4452 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 4453 | weston_view_update_transform(shell->fade.view); |
| 4454 | weston_surface_damage(shell->fade.view->surface); |
Pekka Paalanen | 79346ab | 2013-05-22 18:03:09 +0300 | [diff] [blame] | 4455 | |
| 4456 | loop = wl_display_get_event_loop(shell->compositor->wl_display); |
| 4457 | shell->fade.startup_timer = |
| 4458 | wl_event_loop_add_timer(loop, fade_startup_timeout, shell); |
| 4459 | wl_event_source_timer_update(shell->fade.startup_timer, 15000); |
| 4460 | } |
| 4461 | |
| 4462 | static void |
Ander Conselvan de Oliveira | a457563 | 2013-02-21 18:35:23 +0200 | [diff] [blame] | 4463 | idle_handler(struct wl_listener *listener, void *data) |
Ander Conselvan de Oliveira | 19d10ef | 2013-02-21 18:35:20 +0200 | [diff] [blame] | 4464 | { |
| 4465 | struct desktop_shell *shell = |
Ander Conselvan de Oliveira | a457563 | 2013-02-21 18:35:23 +0200 | [diff] [blame] | 4466 | container_of(listener, struct desktop_shell, idle_listener); |
Ander Conselvan de Oliveira | 19d10ef | 2013-02-21 18:35:20 +0200 | [diff] [blame] | 4467 | |
| 4468 | shell_fade(shell, FADE_OUT); |
| 4469 | /* lock() is called from shell_fade_done() */ |
| 4470 | } |
| 4471 | |
| 4472 | static void |
Ander Conselvan de Oliveira | a457563 | 2013-02-21 18:35:23 +0200 | [diff] [blame] | 4473 | wake_handler(struct wl_listener *listener, void *data) |
Ander Conselvan de Oliveira | 19d10ef | 2013-02-21 18:35:20 +0200 | [diff] [blame] | 4474 | { |
| 4475 | struct desktop_shell *shell = |
Ander Conselvan de Oliveira | a457563 | 2013-02-21 18:35:23 +0200 | [diff] [blame] | 4476 | container_of(listener, struct desktop_shell, wake_listener); |
Ander Conselvan de Oliveira | 19d10ef | 2013-02-21 18:35:20 +0200 | [diff] [blame] | 4477 | |
Ander Conselvan de Oliveira | 19d10ef | 2013-02-21 18:35:20 +0200 | [diff] [blame] | 4478 | unlock(shell); |
| 4479 | } |
| 4480 | |
| 4481 | static void |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 4482 | center_on_output(struct weston_view *view, struct weston_output *output) |
Pekka Paalanen | 77346a6 | 2011-11-30 16:26:35 +0200 | [diff] [blame] | 4483 | { |
Giulio Camuffo | b836664 | 2013-04-25 13:57:46 +0300 | [diff] [blame] | 4484 | int32_t surf_x, surf_y, width, height; |
Ander Conselvan de Oliveira | 012b4c7 | 2012-11-27 17:03:42 +0200 | [diff] [blame] | 4485 | float x, y; |
Pekka Paalanen | 77346a6 | 2011-11-30 16:26:35 +0200 | [diff] [blame] | 4486 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 4487 | surface_subsurfaces_boundingbox(view->surface, &surf_x, &surf_y, &width, &height); |
Giulio Camuffo | b836664 | 2013-04-25 13:57:46 +0300 | [diff] [blame] | 4488 | |
| 4489 | x = output->x + (output->width - width) / 2 - surf_x / 2; |
| 4490 | y = output->y + (output->height - height) / 2 - surf_y / 2; |
Ander Conselvan de Oliveira | 012b4c7 | 2012-11-27 17:03:42 +0200 | [diff] [blame] | 4491 | |
Jason Ekstrand | 918f2dd | 2013-12-02 21:01:53 -0600 | [diff] [blame] | 4492 | weston_view_set_position(view, x, y); |
Pekka Paalanen | 77346a6 | 2011-11-30 16:26:35 +0200 | [diff] [blame] | 4493 | } |
| 4494 | |
| 4495 | static void |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 4496 | weston_view_set_initial_position(struct weston_view *view, |
| 4497 | struct desktop_shell *shell) |
Rob Bradford | ac63e5b | 2012-08-13 14:07:52 +0100 | [diff] [blame] | 4498 | { |
| 4499 | struct weston_compositor *compositor = shell->compositor; |
| 4500 | int ix = 0, iy = 0; |
| 4501 | int range_x, range_y; |
| 4502 | int dx, dy, x, y, panel_height; |
| 4503 | struct weston_output *output, *target_output = NULL; |
| 4504 | struct weston_seat *seat; |
| 4505 | |
| 4506 | /* As a heuristic place the new window on the same output as the |
| 4507 | * pointer. Falling back to the output containing 0, 0. |
| 4508 | * |
| 4509 | * TODO: Do something clever for touch too? |
| 4510 | */ |
| 4511 | wl_list_for_each(seat, &compositor->seat_list, link) { |
Kristian Høgsberg | 2bf8762 | 2013-05-07 23:17:41 -0400 | [diff] [blame] | 4512 | if (seat->pointer) { |
Kristian Høgsberg | e314875 | 2013-05-06 23:19:49 -0400 | [diff] [blame] | 4513 | ix = wl_fixed_to_int(seat->pointer->x); |
| 4514 | iy = wl_fixed_to_int(seat->pointer->y); |
Rob Bradford | ac63e5b | 2012-08-13 14:07:52 +0100 | [diff] [blame] | 4515 | break; |
| 4516 | } |
| 4517 | } |
| 4518 | |
| 4519 | wl_list_for_each(output, &compositor->output_list, link) { |
| 4520 | if (pixman_region32_contains_point(&output->region, ix, iy, NULL)) { |
| 4521 | target_output = output; |
| 4522 | break; |
| 4523 | } |
| 4524 | } |
| 4525 | |
| 4526 | if (!target_output) { |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 4527 | weston_view_set_position(view, 10 + random() % 400, |
| 4528 | 10 + random() % 400); |
Rob Bradford | ac63e5b | 2012-08-13 14:07:52 +0100 | [diff] [blame] | 4529 | return; |
| 4530 | } |
| 4531 | |
| 4532 | /* Valid range within output where the surface will still be onscreen. |
| 4533 | * If this is negative it means that the surface is bigger than |
| 4534 | * output. |
| 4535 | */ |
| 4536 | panel_height = get_output_panel_height(shell, target_output); |
Jason Ekstrand | 918f2dd | 2013-12-02 21:01:53 -0600 | [diff] [blame] | 4537 | range_x = target_output->width - view->surface->width; |
Scott Moreau | 1bad5db | 2012-08-18 01:04:05 -0600 | [diff] [blame] | 4538 | range_y = (target_output->height - panel_height) - |
Jason Ekstrand | 918f2dd | 2013-12-02 21:01:53 -0600 | [diff] [blame] | 4539 | view->surface->height; |
Rob Bradford | ac63e5b | 2012-08-13 14:07:52 +0100 | [diff] [blame] | 4540 | |
Rob Bradford | 4cb88c7 | 2012-08-13 15:18:44 +0100 | [diff] [blame] | 4541 | if (range_x > 0) |
Rob Bradford | ac63e5b | 2012-08-13 14:07:52 +0100 | [diff] [blame] | 4542 | dx = random() % range_x; |
Rob Bradford | ac63e5b | 2012-08-13 14:07:52 +0100 | [diff] [blame] | 4543 | else |
Rob Bradford | 4cb88c7 | 2012-08-13 15:18:44 +0100 | [diff] [blame] | 4544 | dx = 0; |
| 4545 | |
| 4546 | if (range_y > 0) |
Rob Bradford | ac63e5b | 2012-08-13 14:07:52 +0100 | [diff] [blame] | 4547 | dy = panel_height + random() % range_y; |
Rob Bradford | 4cb88c7 | 2012-08-13 15:18:44 +0100 | [diff] [blame] | 4548 | else |
| 4549 | dy = panel_height; |
Rob Bradford | ac63e5b | 2012-08-13 14:07:52 +0100 | [diff] [blame] | 4550 | |
| 4551 | x = target_output->x + dx; |
| 4552 | y = target_output->y + dy; |
| 4553 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 4554 | weston_view_set_position(view, x, y); |
Rob Bradford | ac63e5b | 2012-08-13 14:07:52 +0100 | [diff] [blame] | 4555 | } |
| 4556 | |
| 4557 | static void |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 4558 | map(struct desktop_shell *shell, struct shell_surface *shsurf, |
Jason Ekstrand | 918f2dd | 2013-12-02 21:01:53 -0600 | [diff] [blame] | 4559 | int32_t sx, int32_t sy) |
Kristian Høgsberg | 02ec0a5 | 2011-04-23 13:04:11 -0400 | [diff] [blame] | 4560 | { |
Kristian Høgsberg | 8334bc1 | 2012-01-03 10:29:47 -0500 | [diff] [blame] | 4561 | struct weston_compositor *compositor = shell->compositor; |
Daniel Stone | b210468 | 2012-05-30 16:31:56 +0100 | [diff] [blame] | 4562 | struct weston_seat *seat; |
Juan Zhao | 96879df | 2012-02-07 08:45:41 +0800 | [diff] [blame] | 4563 | int panel_height = 0; |
Giulio Camuffo | b836664 | 2013-04-25 13:57:46 +0300 | [diff] [blame] | 4564 | int32_t surf_x, surf_y; |
Pekka Paalanen | 57da4a8 | 2011-11-23 16:42:16 +0200 | [diff] [blame] | 4565 | |
Pekka Paalanen | 77346a6 | 2011-11-30 16:26:35 +0200 | [diff] [blame] | 4566 | /* initial positioning, see also configure() */ |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 4567 | switch (shsurf->type) { |
Rafael Antognolli | ed207b4 | 2013-12-03 15:35:43 -0200 | [diff] [blame] | 4568 | case SHELL_SURFACE_TOPLEVEL: |
Rafael Antognolli | 03b1659 | 2013-12-03 15:35:42 -0200 | [diff] [blame] | 4569 | if (shsurf->state.fullscreen) { |
| 4570 | center_on_output(shsurf->view, shsurf->fullscreen_output); |
| 4571 | shell_map_fullscreen(shsurf); |
| 4572 | } else if (shsurf->state.maximized) { |
| 4573 | /* use surface configure to set the geometry */ |
| 4574 | panel_height = get_output_panel_height(shell, shsurf->output); |
| 4575 | surface_subsurfaces_boundingbox(shsurf->surface, |
| 4576 | &surf_x, &surf_y, NULL, NULL); |
| 4577 | weston_view_set_position(shsurf->view, |
| 4578 | shsurf->output->x - surf_x, |
| 4579 | shsurf->output->y + |
| 4580 | panel_height - surf_y); |
Rafael Antognolli | ed207b4 | 2013-12-03 15:35:43 -0200 | [diff] [blame] | 4581 | } else if (!shsurf->state.relative) { |
Rafael Antognolli | 03b1659 | 2013-12-03 15:35:42 -0200 | [diff] [blame] | 4582 | weston_view_set_initial_position(shsurf->view, shell); |
| 4583 | } |
Juan Zhao | 96879df | 2012-02-07 08:45:41 +0800 | [diff] [blame] | 4584 | break; |
Tiago Vignatti | 0f99701 | 2012-02-10 16:17:23 +0200 | [diff] [blame] | 4585 | case SHELL_SURFACE_POPUP: |
Kristian Høgsberg | 3730f36 | 2012-04-13 12:40:07 -0400 | [diff] [blame] | 4586 | shell_map_popup(shsurf); |
Rob Bradford | db99938 | 2012-12-06 12:07:48 +0000 | [diff] [blame] | 4587 | break; |
Ander Conselvan de Oliveira | e9e0515 | 2012-02-15 17:02:56 +0200 | [diff] [blame] | 4588 | case SHELL_SURFACE_NONE: |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 4589 | weston_view_set_position(shsurf->view, |
| 4590 | shsurf->view->geometry.x + sx, |
| 4591 | shsurf->view->geometry.y + sy); |
Tiago Vignatti | 0f99701 | 2012-02-10 16:17:23 +0200 | [diff] [blame] | 4592 | break; |
Philip Withnall | 0f640e2 | 2013-11-25 18:01:31 +0000 | [diff] [blame] | 4593 | case SHELL_SURFACE_XWAYLAND: |
Pekka Paalanen | 77346a6 | 2011-11-30 16:26:35 +0200 | [diff] [blame] | 4594 | default: |
| 4595 | ; |
| 4596 | } |
Kristian Høgsberg | 7584062 | 2011-09-06 13:48:16 -0400 | [diff] [blame] | 4597 | |
Philip Withnall | e1d75ae | 2013-11-25 18:01:41 +0000 | [diff] [blame] | 4598 | /* Surface stacking order, see also activate(). */ |
| 4599 | shell_surface_update_layer(shsurf); |
Pekka Paalanen | f0fc70d | 2011-11-15 13:34:54 +0200 | [diff] [blame] | 4600 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 4601 | if (shsurf->type != SHELL_SURFACE_NONE) { |
| 4602 | weston_view_update_transform(shsurf->view); |
Rafael Antognolli | 03b1659 | 2013-12-03 15:35:42 -0200 | [diff] [blame] | 4603 | if (shsurf->state.maximized) { |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 4604 | shsurf->surface->output = shsurf->output; |
| 4605 | shsurf->view->output = shsurf->output; |
| 4606 | } |
Ander Conselvan de Oliveira | de56c31 | 2012-03-05 15:39:23 +0200 | [diff] [blame] | 4607 | } |
Kristian Høgsberg | 2f88a40 | 2011-12-04 15:32:59 -0500 | [diff] [blame] | 4608 | |
Rafael Antognolli | ed207b4 | 2013-12-03 15:35:43 -0200 | [diff] [blame] | 4609 | if ((shsurf->type == SHELL_SURFACE_XWAYLAND || shsurf->state.relative) && |
| 4610 | shsurf->transient.flags == WL_SHELL_SURFACE_TRANSIENT_INACTIVE) { |
| 4611 | } |
| 4612 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 4613 | switch (shsurf->type) { |
Tiago Vignatti | fb2adba | 2013-06-12 15:43:21 -0300 | [diff] [blame] | 4614 | /* XXX: xwayland's using the same fields for transient type */ |
| 4615 | case SHELL_SURFACE_XWAYLAND: |
Tiago Vignatti | 99aeb1e | 2012-05-23 22:06:26 +0300 | [diff] [blame] | 4616 | if (shsurf->transient.flags == |
| 4617 | WL_SHELL_SURFACE_TRANSIENT_INACTIVE) |
| 4618 | break; |
| 4619 | case SHELL_SURFACE_TOPLEVEL: |
Rafael Antognolli | ed207b4 | 2013-12-03 15:35:43 -0200 | [diff] [blame] | 4620 | if (shsurf->state.relative && |
| 4621 | shsurf->transient.flags == WL_SHELL_SURFACE_TRANSIENT_INACTIVE) |
| 4622 | break; |
Rafael Antognolli | ba5d2d7 | 2013-12-04 17:49:55 -0200 | [diff] [blame] | 4623 | if (shell->locked) |
Rafael Antognolli | ed207b4 | 2013-12-03 15:35:43 -0200 | [diff] [blame] | 4624 | break; |
| 4625 | wl_list_for_each(seat, &compositor->seat_list, link) |
| 4626 | activate(shell, shsurf->surface, seat); |
Juan Zhao | 7bb92f0 | 2011-12-15 11:31:51 -0500 | [diff] [blame] | 4627 | break; |
Philip Withnall | 0f640e2 | 2013-11-25 18:01:31 +0000 | [diff] [blame] | 4628 | case SHELL_SURFACE_POPUP: |
| 4629 | case SHELL_SURFACE_NONE: |
Juan Zhao | 7bb92f0 | 2011-12-15 11:31:51 -0500 | [diff] [blame] | 4630 | default: |
| 4631 | break; |
| 4632 | } |
| 4633 | |
Rafael Antognolli | 03b1659 | 2013-12-03 15:35:42 -0200 | [diff] [blame] | 4634 | if (shsurf->type == SHELL_SURFACE_TOPLEVEL && |
| 4635 | !shsurf->state.maximized && !shsurf->state.fullscreen) |
Juan Zhao | e10d279 | 2012-04-25 19:09:52 +0800 | [diff] [blame] | 4636 | { |
| 4637 | switch (shell->win_animation_type) { |
| 4638 | case ANIMATION_FADE: |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 4639 | 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] | 4640 | break; |
| 4641 | case ANIMATION_ZOOM: |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 4642 | weston_zoom_run(shsurf->view, 0.5, 1.0, NULL, NULL); |
Juan Zhao | e10d279 | 2012-04-25 19:09:52 +0800 | [diff] [blame] | 4643 | break; |
Philip Withnall | 4a86a0a | 2013-11-25 18:01:32 +0000 | [diff] [blame] | 4644 | case ANIMATION_NONE: |
Juan Zhao | e10d279 | 2012-04-25 19:09:52 +0800 | [diff] [blame] | 4645 | default: |
| 4646 | break; |
| 4647 | } |
| 4648 | } |
Kristian Høgsberg | 32e24cc | 2011-11-09 12:07:35 -0500 | [diff] [blame] | 4649 | } |
| 4650 | |
| 4651 | static void |
Tiago Vignatti | be14326 | 2012-04-16 17:31:41 +0300 | [diff] [blame] | 4652 | configure(struct desktop_shell *shell, struct weston_surface *surface, |
Jason Ekstrand | 918f2dd | 2013-12-02 21:01:53 -0600 | [diff] [blame] | 4653 | float x, float y) |
Kristian Høgsberg | 32e24cc | 2011-11-09 12:07:35 -0500 | [diff] [blame] | 4654 | { |
Pekka Paalanen | 77346a6 | 2011-11-30 16:26:35 +0200 | [diff] [blame] | 4655 | struct shell_surface *shsurf; |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 4656 | struct weston_view *view; |
Jason Ekstrand | 918f2dd | 2013-12-02 21:01:53 -0600 | [diff] [blame] | 4657 | int32_t mx, my, surf_x, surf_y; |
Kristian Høgsberg | 32e24cc | 2011-11-09 12:07:35 -0500 | [diff] [blame] | 4658 | |
Pekka Paalanen | 77346a6 | 2011-11-30 16:26:35 +0200 | [diff] [blame] | 4659 | shsurf = get_shell_surface(surface); |
Pekka Paalanen | 77346a6 | 2011-11-30 16:26:35 +0200 | [diff] [blame] | 4660 | |
Rafael Antognolli | 03b1659 | 2013-12-03 15:35:42 -0200 | [diff] [blame] | 4661 | if (shsurf->state.fullscreen) |
Alex Wu | 4539b08 | 2012-03-01 12:57:46 +0800 | [diff] [blame] | 4662 | shell_configure_fullscreen(shsurf); |
Rafael Antognolli | 03b1659 | 2013-12-03 15:35:42 -0200 | [diff] [blame] | 4663 | else if (shsurf->state.maximized) { |
Alex Wu | 4539b08 | 2012-03-01 12:57:46 +0800 | [diff] [blame] | 4664 | /* setting x, y and using configure to change that geometry */ |
Giulio Camuffo | b836664 | 2013-04-25 13:57:46 +0300 | [diff] [blame] | 4665 | surface_subsurfaces_boundingbox(shsurf->surface, &surf_x, &surf_y, |
| 4666 | NULL, NULL); |
Jason Ekstrand | 918f2dd | 2013-12-02 21:01:53 -0600 | [diff] [blame] | 4667 | mx = shsurf->output->x - surf_x; |
| 4668 | my = shsurf->output->y + |
| 4669 | get_output_panel_height(shell,shsurf->output) - surf_y; |
| 4670 | weston_view_set_position(shsurf->view, mx, my); |
Rafael Antognolli | 03b1659 | 2013-12-03 15:35:42 -0200 | [diff] [blame] | 4671 | } else { |
Jason Ekstrand | 918f2dd | 2013-12-02 21:01:53 -0600 | [diff] [blame] | 4672 | weston_view_set_position(shsurf->view, x, y); |
Kristian Høgsberg | 7a5c979 | 2011-06-18 06:12:54 -0400 | [diff] [blame] | 4673 | } |
Kristian Høgsberg | 32e24cc | 2011-11-09 12:07:35 -0500 | [diff] [blame] | 4674 | |
Alex Wu | 4539b08 | 2012-03-01 12:57:46 +0800 | [diff] [blame] | 4675 | /* XXX: would a fullscreen surface need the same handling? */ |
Kristian Høgsberg | 6a8b553 | 2012-02-16 23:43:59 -0500 | [diff] [blame] | 4676 | if (surface->output) { |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 4677 | wl_list_for_each(view, &surface->views, surface_link) |
| 4678 | weston_view_update_transform(view); |
Pekka Paalanen | 77346a6 | 2011-11-30 16:26:35 +0200 | [diff] [blame] | 4679 | |
Rafael Antognolli | 03b1659 | 2013-12-03 15:35:42 -0200 | [diff] [blame] | 4680 | if (shsurf->state.maximized) |
Juan Zhao | 96879df | 2012-02-07 08:45:41 +0800 | [diff] [blame] | 4681 | surface->output = shsurf->output; |
Pekka Paalanen | 77346a6 | 2011-11-30 16:26:35 +0200 | [diff] [blame] | 4682 | } |
Kristian Høgsberg | 0793756 | 2011-04-12 17:25:42 -0400 | [diff] [blame] | 4683 | } |
| 4684 | |
Ander Conselvan de Oliveira | 093bfa3 | 2012-03-27 17:36:41 +0300 | [diff] [blame] | 4685 | static void |
Jason Ekstrand | 918f2dd | 2013-12-02 21:01:53 -0600 | [diff] [blame] | 4686 | 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] | 4687 | { |
Ander Conselvan de Oliveira | 7fb9f95 | 2012-03-27 17:36:42 +0300 | [diff] [blame] | 4688 | struct shell_surface *shsurf = get_shell_surface(es); |
Tiago Vignatti | be14326 | 2012-04-16 17:31:41 +0300 | [diff] [blame] | 4689 | struct desktop_shell *shell = shsurf->shell; |
Giulio Camuffo | 184df50 | 2013-02-21 11:29:21 +0100 | [diff] [blame] | 4690 | |
Tiago Vignatti | 70e5c9c | 2012-05-07 15:23:07 +0300 | [diff] [blame] | 4691 | int type_changed = 0; |
Ander Conselvan de Oliveira | 093bfa3 | 2012-03-27 17:36:41 +0300 | [diff] [blame] | 4692 | |
Kristian Høgsberg | 8eb0f4f | 2013-06-17 10:33:14 -0400 | [diff] [blame] | 4693 | if (!weston_surface_is_mapped(es) && |
| 4694 | !wl_list_empty(&shsurf->popup.grab_link)) { |
Giulio Camuffo | 5085a75 | 2013-03-25 21:42:45 +0100 | [diff] [blame] | 4695 | remove_popup_grab(shsurf); |
| 4696 | } |
| 4697 | |
Jason Ekstrand | 918f2dd | 2013-12-02 21:01:53 -0600 | [diff] [blame] | 4698 | if (es->width == 0) |
Giulio Camuffo | 184df50 | 2013-02-21 11:29:21 +0100 | [diff] [blame] | 4699 | return; |
| 4700 | |
Kristian Høgsberg | c8f8dd8 | 2013-12-05 23:20:33 -0800 | [diff] [blame] | 4701 | if (shsurf->state_changed) { |
Kristian Høgsberg | 7f366e7 | 2012-04-27 17:20:01 -0400 | [diff] [blame] | 4702 | set_surface_type(shsurf); |
Kristian Høgsberg | f7e23d5 | 2012-04-27 17:51:59 -0400 | [diff] [blame] | 4703 | type_changed = 1; |
| 4704 | } |
Kristian Høgsberg | 7f366e7 | 2012-04-27 17:20:01 -0400 | [diff] [blame] | 4705 | |
Ander Conselvan de Oliveira | 093bfa3 | 2012-03-27 17:36:41 +0300 | [diff] [blame] | 4706 | if (!weston_surface_is_mapped(es)) { |
Jason Ekstrand | 918f2dd | 2013-12-02 21:01:53 -0600 | [diff] [blame] | 4707 | map(shell, shsurf, sx, sy); |
Kristian Høgsberg | f7e23d5 | 2012-04-27 17:51:59 -0400 | [diff] [blame] | 4708 | } else if (type_changed || sx != 0 || sy != 0 || |
Jason Ekstrand | 918f2dd | 2013-12-02 21:01:53 -0600 | [diff] [blame] | 4709 | shsurf->last_width != es->width || |
| 4710 | shsurf->last_height != es->height) { |
| 4711 | shsurf->last_width = es->width; |
| 4712 | shsurf->last_height = es->height; |
John Kåre Alsaker | 490d02a | 2012-09-30 02:57:21 +0200 | [diff] [blame] | 4713 | float from_x, from_y; |
| 4714 | float to_x, to_y; |
Ander Conselvan de Oliveira | 093bfa3 | 2012-03-27 17:36:41 +0300 | [diff] [blame] | 4715 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 4716 | weston_view_to_global_float(shsurf->view, 0, 0, &from_x, &from_y); |
| 4717 | 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] | 4718 | configure(shell, es, |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 4719 | shsurf->view->geometry.x + to_x - from_x, |
Jason Ekstrand | 918f2dd | 2013-12-02 21:01:53 -0600 | [diff] [blame] | 4720 | shsurf->view->geometry.y + to_y - from_y); |
Ander Conselvan de Oliveira | 093bfa3 | 2012-03-27 17:36:41 +0300 | [diff] [blame] | 4721 | } |
| 4722 | } |
| 4723 | |
Zhang, Xiong Y | 3123693 | 2013-12-13 22:10:57 +0200 | [diff] [blame] | 4724 | static void |
| 4725 | shell_surface_output_destroyed(struct weston_surface *es) |
| 4726 | { |
| 4727 | struct shell_surface *shsurf = get_shell_surface(es); |
| 4728 | |
| 4729 | shsurf->saved_position_valid = false; |
Ander Conselvan de Oliveira | fc63fdd | 2013-12-13 22:10:58 +0200 | [diff] [blame] | 4730 | shsurf->next_state.maximized = false; |
| 4731 | shsurf->next_state.fullscreen = false; |
| 4732 | shsurf->state_changed = true; |
Zhang, Xiong Y | 3123693 | 2013-12-13 22:10:57 +0200 | [diff] [blame] | 4733 | } |
| 4734 | |
Tiago Vignatti | b7dbbd6 | 2012-09-25 17:57:01 +0300 | [diff] [blame] | 4735 | static void launch_desktop_shell_process(void *data); |
Pekka Paalanen | 4d733ee | 2012-01-17 14:36:27 +0200 | [diff] [blame] | 4736 | |
Kristian Høgsberg | 97d44aa | 2011-08-26 17:21:20 -0400 | [diff] [blame] | 4737 | static void |
Kristian Høgsberg | 8334bc1 | 2012-01-03 10:29:47 -0500 | [diff] [blame] | 4738 | desktop_shell_sigchld(struct weston_process *process, int status) |
Pekka Paalanen | 6cd281a | 2011-11-03 14:11:32 +0200 | [diff] [blame] | 4739 | { |
Pekka Paalanen | 4d733ee | 2012-01-17 14:36:27 +0200 | [diff] [blame] | 4740 | uint32_t time; |
Tiago Vignatti | be14326 | 2012-04-16 17:31:41 +0300 | [diff] [blame] | 4741 | struct desktop_shell *shell = |
| 4742 | container_of(process, struct desktop_shell, child.process); |
Pekka Paalanen | 6cd281a | 2011-11-03 14:11:32 +0200 | [diff] [blame] | 4743 | |
| 4744 | shell->child.process.pid = 0; |
| 4745 | shell->child.client = NULL; /* already destroyed by wayland */ |
Pekka Paalanen | 4d733ee | 2012-01-17 14:36:27 +0200 | [diff] [blame] | 4746 | |
| 4747 | /* if desktop-shell dies more than 5 times in 30 seconds, give up */ |
| 4748 | time = weston_compositor_get_time(); |
Kristian Høgsberg | f03a616 | 2012-01-17 11:07:42 -0500 | [diff] [blame] | 4749 | if (time - shell->child.deathstamp > 30000) { |
Pekka Paalanen | 4d733ee | 2012-01-17 14:36:27 +0200 | [diff] [blame] | 4750 | shell->child.deathstamp = time; |
| 4751 | shell->child.deathcount = 0; |
| 4752 | } |
| 4753 | |
| 4754 | shell->child.deathcount++; |
| 4755 | if (shell->child.deathcount > 5) { |
Emilio Pozuelo Monfort | 46ce798 | 2013-11-20 13:22:29 +0100 | [diff] [blame] | 4756 | weston_log("%s died, giving up.\n", shell->client); |
Pekka Paalanen | 4d733ee | 2012-01-17 14:36:27 +0200 | [diff] [blame] | 4757 | return; |
| 4758 | } |
| 4759 | |
Emilio Pozuelo Monfort | 46ce798 | 2013-11-20 13:22:29 +0100 | [diff] [blame] | 4760 | weston_log("%s died, respawning...\n", shell->client); |
Pekka Paalanen | 4d733ee | 2012-01-17 14:36:27 +0200 | [diff] [blame] | 4761 | launch_desktop_shell_process(shell); |
Pekka Paalanen | 79346ab | 2013-05-22 18:03:09 +0300 | [diff] [blame] | 4762 | shell_fade_startup(shell); |
Pekka Paalanen | 6cd281a | 2011-11-03 14:11:32 +0200 | [diff] [blame] | 4763 | } |
| 4764 | |
Tiago Vignatti | b7dbbd6 | 2012-09-25 17:57:01 +0300 | [diff] [blame] | 4765 | static void |
Ander Conselvan de Oliveira | 312ea4c | 2013-12-20 21:07:01 +0200 | [diff] [blame] | 4766 | desktop_shell_client_destroy(struct wl_listener *listener, void *data) |
| 4767 | { |
| 4768 | struct desktop_shell *shell; |
| 4769 | |
| 4770 | shell = container_of(listener, struct desktop_shell, |
| 4771 | child.client_destroy_listener); |
| 4772 | |
| 4773 | shell->child.client = NULL; |
| 4774 | } |
| 4775 | |
| 4776 | static void |
Tiago Vignatti | b7dbbd6 | 2012-09-25 17:57:01 +0300 | [diff] [blame] | 4777 | launch_desktop_shell_process(void *data) |
Pekka Paalanen | 6cd281a | 2011-11-03 14:11:32 +0200 | [diff] [blame] | 4778 | { |
Tiago Vignatti | b7dbbd6 | 2012-09-25 17:57:01 +0300 | [diff] [blame] | 4779 | struct desktop_shell *shell = data; |
Pekka Paalanen | 6cd281a | 2011-11-03 14:11:32 +0200 | [diff] [blame] | 4780 | |
Kristian Høgsberg | 8334bc1 | 2012-01-03 10:29:47 -0500 | [diff] [blame] | 4781 | shell->child.client = weston_client_launch(shell->compositor, |
Pekka Paalanen | 409ef0a | 2011-12-02 15:30:21 +0200 | [diff] [blame] | 4782 | &shell->child.process, |
Emilio Pozuelo Monfort | 46ce798 | 2013-11-20 13:22:29 +0100 | [diff] [blame] | 4783 | shell->client, |
Pekka Paalanen | 409ef0a | 2011-12-02 15:30:21 +0200 | [diff] [blame] | 4784 | desktop_shell_sigchld); |
| 4785 | |
| 4786 | if (!shell->child.client) |
Emilio Pozuelo Monfort | 46ce798 | 2013-11-20 13:22:29 +0100 | [diff] [blame] | 4787 | weston_log("not able to start %s\n", shell->client); |
Ander Conselvan de Oliveira | 312ea4c | 2013-12-20 21:07:01 +0200 | [diff] [blame] | 4788 | |
| 4789 | shell->child.client_destroy_listener.notify = |
| 4790 | desktop_shell_client_destroy; |
| 4791 | wl_client_add_destroy_listener(shell->child.client, |
| 4792 | &shell->child.client_destroy_listener); |
Pekka Paalanen | 6cd281a | 2011-11-03 14:11:32 +0200 | [diff] [blame] | 4793 | } |
| 4794 | |
| 4795 | static void |
Kristian Høgsberg | 97d44aa | 2011-08-26 17:21:20 -0400 | [diff] [blame] | 4796 | bind_shell(struct wl_client *client, void *data, uint32_t version, uint32_t id) |
| 4797 | { |
Tiago Vignatti | be14326 | 2012-04-16 17:31:41 +0300 | [diff] [blame] | 4798 | struct desktop_shell *shell = data; |
Jason Ekstrand | a85118c | 2013-06-27 20:17:02 -0500 | [diff] [blame] | 4799 | struct wl_resource *resource; |
Kristian Høgsberg | 97d44aa | 2011-08-26 17:21:20 -0400 | [diff] [blame] | 4800 | |
Jason Ekstrand | a85118c | 2013-06-27 20:17:02 -0500 | [diff] [blame] | 4801 | resource = wl_resource_create(client, &wl_shell_interface, 1, id); |
| 4802 | if (resource) |
| 4803 | wl_resource_set_implementation(resource, &shell_implementation, |
| 4804 | shell, NULL); |
Kristian Høgsberg | 97d44aa | 2011-08-26 17:21:20 -0400 | [diff] [blame] | 4805 | } |
| 4806 | |
Kristian Høgsberg | 7584062 | 2011-09-06 13:48:16 -0400 | [diff] [blame] | 4807 | static void |
Rafael Antognolli | e2a3455 | 2013-12-03 15:35:45 -0200 | [diff] [blame] | 4808 | bind_xdg_shell(struct wl_client *client, void *data, uint32_t version, uint32_t id) |
| 4809 | { |
| 4810 | struct desktop_shell *shell = data; |
| 4811 | struct wl_resource *resource; |
| 4812 | |
| 4813 | resource = wl_resource_create(client, &xdg_shell_interface, 1, id); |
| 4814 | if (resource) |
| 4815 | wl_resource_set_dispatcher(resource, |
| 4816 | xdg_shell_unversioned_dispatch, |
| 4817 | NULL, shell, NULL); |
| 4818 | } |
| 4819 | |
| 4820 | static void |
Pekka Paalanen | 9ef3e01 | 2011-11-15 13:34:48 +0200 | [diff] [blame] | 4821 | unbind_desktop_shell(struct wl_resource *resource) |
| 4822 | { |
Jason Ekstrand | 651f00e | 2013-06-14 10:07:54 -0500 | [diff] [blame] | 4823 | struct desktop_shell *shell = wl_resource_get_user_data(resource); |
Kristian Høgsberg | 1ec0c31 | 2011-11-15 16:39:55 -0500 | [diff] [blame] | 4824 | |
| 4825 | if (shell->locked) |
| 4826 | resume_desktop(shell); |
| 4827 | |
Pekka Paalanen | 9ef3e01 | 2011-11-15 13:34:48 +0200 | [diff] [blame] | 4828 | shell->child.desktop_shell = NULL; |
| 4829 | shell->prepare_event_sent = false; |
Pekka Paalanen | 9ef3e01 | 2011-11-15 13:34:48 +0200 | [diff] [blame] | 4830 | } |
| 4831 | |
| 4832 | static void |
Kristian Høgsberg | 7584062 | 2011-09-06 13:48:16 -0400 | [diff] [blame] | 4833 | bind_desktop_shell(struct wl_client *client, |
| 4834 | void *data, uint32_t version, uint32_t id) |
| 4835 | { |
Tiago Vignatti | be14326 | 2012-04-16 17:31:41 +0300 | [diff] [blame] | 4836 | struct desktop_shell *shell = data; |
Pekka Paalanen | bbe6052 | 2011-11-03 14:11:33 +0200 | [diff] [blame] | 4837 | struct wl_resource *resource; |
Kristian Høgsberg | 7584062 | 2011-09-06 13:48:16 -0400 | [diff] [blame] | 4838 | |
Jason Ekstrand | a85118c | 2013-06-27 20:17:02 -0500 | [diff] [blame] | 4839 | resource = wl_resource_create(client, &desktop_shell_interface, |
| 4840 | MIN(version, 2), id); |
Pekka Paalanen | bbe6052 | 2011-11-03 14:11:33 +0200 | [diff] [blame] | 4841 | |
Pekka Paalanen | 9ef3e01 | 2011-11-15 13:34:48 +0200 | [diff] [blame] | 4842 | if (client == shell->child.client) { |
Jason Ekstrand | a85118c | 2013-06-27 20:17:02 -0500 | [diff] [blame] | 4843 | wl_resource_set_implementation(resource, |
| 4844 | &desktop_shell_implementation, |
| 4845 | shell, unbind_desktop_shell); |
Pekka Paalanen | 9ef3e01 | 2011-11-15 13:34:48 +0200 | [diff] [blame] | 4846 | shell->child.desktop_shell = resource; |
Pekka Paalanen | 79346ab | 2013-05-22 18:03:09 +0300 | [diff] [blame] | 4847 | |
| 4848 | if (version < 2) |
| 4849 | shell_fade_startup(shell); |
| 4850 | |
Pekka Paalanen | bbe6052 | 2011-11-03 14:11:33 +0200 | [diff] [blame] | 4851 | return; |
Pekka Paalanen | 9ef3e01 | 2011-11-15 13:34:48 +0200 | [diff] [blame] | 4852 | } |
Pekka Paalanen | bbe6052 | 2011-11-03 14:11:33 +0200 | [diff] [blame] | 4853 | |
| 4854 | wl_resource_post_error(resource, WL_DISPLAY_ERROR_INVALID_OBJECT, |
| 4855 | "permission to bind desktop_shell denied"); |
Kristian Høgsberg | eae5de7 | 2012-04-11 22:42:15 -0400 | [diff] [blame] | 4856 | wl_resource_destroy(resource); |
Kristian Høgsberg | 7584062 | 2011-09-06 13:48:16 -0400 | [diff] [blame] | 4857 | } |
| 4858 | |
Pekka Paalanen | 6e16811 | 2011-11-24 11:34:05 +0200 | [diff] [blame] | 4859 | static void |
Jason Ekstrand | 918f2dd | 2013-12-02 21:01:53 -0600 | [diff] [blame] | 4860 | 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] | 4861 | { |
Giulio Camuffo | 7fe01b1 | 2013-03-28 18:02:42 +0100 | [diff] [blame] | 4862 | struct desktop_shell *shell = surface->configure_private; |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 4863 | struct weston_view *view; |
Kristian Høgsberg | 1a73a63 | 2012-06-26 22:15:53 -0400 | [diff] [blame] | 4864 | |
Jason Ekstrand | 918f2dd | 2013-12-02 21:01:53 -0600 | [diff] [blame] | 4865 | if (surface->width == 0) |
Giulio Camuffo | 184df50 | 2013-02-21 11:29:21 +0100 | [diff] [blame] | 4866 | return; |
| 4867 | |
Pekka Paalanen | 3a1d07d | 2012-12-20 14:02:13 +0200 | [diff] [blame] | 4868 | /* XXX: starting weston-screensaver beforehand does not work */ |
Kristian Høgsberg | 1a73a63 | 2012-06-26 22:15:53 -0400 | [diff] [blame] | 4869 | if (!shell->locked) |
| 4870 | return; |
| 4871 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 4872 | view = container_of(surface->views.next, struct weston_view, surface_link); |
| 4873 | center_on_output(view, surface->output); |
Kristian Høgsberg | 1a73a63 | 2012-06-26 22:15:53 -0400 | [diff] [blame] | 4874 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 4875 | if (wl_list_empty(&view->layer_link)) { |
| 4876 | wl_list_insert(shell->lock_layer.view_list.prev, |
| 4877 | &view->layer_link); |
| 4878 | weston_view_update_transform(view); |
Ander Conselvan de Oliveira | 859e885 | 2013-02-21 18:35:21 +0200 | [diff] [blame] | 4879 | wl_event_source_timer_update(shell->screensaver.timer, |
| 4880 | shell->screensaver.duration); |
Ander Conselvan de Oliveira | 19d10ef | 2013-02-21 18:35:20 +0200 | [diff] [blame] | 4881 | shell_fade(shell, FADE_IN); |
Kristian Høgsberg | 1a73a63 | 2012-06-26 22:15:53 -0400 | [diff] [blame] | 4882 | } |
| 4883 | } |
| 4884 | |
| 4885 | static void |
Pekka Paalanen | 6e16811 | 2011-11-24 11:34:05 +0200 | [diff] [blame] | 4886 | screensaver_set_surface(struct wl_client *client, |
| 4887 | struct wl_resource *resource, |
Kristian Høgsberg | 1a73a63 | 2012-06-26 22:15:53 -0400 | [diff] [blame] | 4888 | struct wl_resource *surface_resource, |
Pekka Paalanen | 6e16811 | 2011-11-24 11:34:05 +0200 | [diff] [blame] | 4889 | struct wl_resource *output_resource) |
| 4890 | { |
Jason Ekstrand | 651f00e | 2013-06-14 10:07:54 -0500 | [diff] [blame] | 4891 | struct desktop_shell *shell = wl_resource_get_user_data(resource); |
Jason Ekstrand | 0f2ef7e | 2013-06-14 10:07:53 -0500 | [diff] [blame] | 4892 | struct weston_surface *surface = |
| 4893 | wl_resource_get_user_data(surface_resource); |
Jason Ekstrand | a0d2dde | 2013-06-14 10:08:01 -0500 | [diff] [blame] | 4894 | struct weston_output *output = wl_resource_get_user_data(output_resource); |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 4895 | struct weston_view *view, *next; |
| 4896 | |
| 4897 | /* Make sure we only have one view */ |
| 4898 | wl_list_for_each_safe(view, next, &surface->views, surface_link) |
| 4899 | weston_view_destroy(view); |
| 4900 | weston_view_create(surface); |
Pekka Paalanen | 6e16811 | 2011-11-24 11:34:05 +0200 | [diff] [blame] | 4901 | |
Kristian Høgsberg | 1a73a63 | 2012-06-26 22:15:53 -0400 | [diff] [blame] | 4902 | surface->configure = screensaver_configure; |
Giulio Camuffo | 7fe01b1 | 2013-03-28 18:02:42 +0100 | [diff] [blame] | 4903 | surface->configure_private = shell; |
Pekka Paalanen | 77346a6 | 2011-11-30 16:26:35 +0200 | [diff] [blame] | 4904 | surface->output = output; |
Pekka Paalanen | 6e16811 | 2011-11-24 11:34:05 +0200 | [diff] [blame] | 4905 | } |
| 4906 | |
| 4907 | static const struct screensaver_interface screensaver_implementation = { |
| 4908 | screensaver_set_surface |
| 4909 | }; |
| 4910 | |
| 4911 | static void |
| 4912 | unbind_screensaver(struct wl_resource *resource) |
| 4913 | { |
Jason Ekstrand | 651f00e | 2013-06-14 10:07:54 -0500 | [diff] [blame] | 4914 | struct desktop_shell *shell = wl_resource_get_user_data(resource); |
Pekka Paalanen | 6e16811 | 2011-11-24 11:34:05 +0200 | [diff] [blame] | 4915 | |
Pekka Paalanen | 77346a6 | 2011-11-30 16:26:35 +0200 | [diff] [blame] | 4916 | shell->screensaver.binding = NULL; |
Pekka Paalanen | 6e16811 | 2011-11-24 11:34:05 +0200 | [diff] [blame] | 4917 | } |
| 4918 | |
| 4919 | static void |
| 4920 | bind_screensaver(struct wl_client *client, |
| 4921 | void *data, uint32_t version, uint32_t id) |
| 4922 | { |
Tiago Vignatti | be14326 | 2012-04-16 17:31:41 +0300 | [diff] [blame] | 4923 | struct desktop_shell *shell = data; |
Pekka Paalanen | 6e16811 | 2011-11-24 11:34:05 +0200 | [diff] [blame] | 4924 | struct wl_resource *resource; |
| 4925 | |
Jason Ekstrand | a85118c | 2013-06-27 20:17:02 -0500 | [diff] [blame] | 4926 | resource = wl_resource_create(client, &screensaver_interface, 1, id); |
Pekka Paalanen | 6e16811 | 2011-11-24 11:34:05 +0200 | [diff] [blame] | 4927 | |
Pekka Paalanen | 77346a6 | 2011-11-30 16:26:35 +0200 | [diff] [blame] | 4928 | if (shell->screensaver.binding == NULL) { |
Jason Ekstrand | a85118c | 2013-06-27 20:17:02 -0500 | [diff] [blame] | 4929 | wl_resource_set_implementation(resource, |
| 4930 | &screensaver_implementation, |
| 4931 | shell, unbind_screensaver); |
Pekka Paalanen | 77346a6 | 2011-11-30 16:26:35 +0200 | [diff] [blame] | 4932 | shell->screensaver.binding = resource; |
Pekka Paalanen | 6e16811 | 2011-11-24 11:34:05 +0200 | [diff] [blame] | 4933 | return; |
| 4934 | } |
| 4935 | |
| 4936 | wl_resource_post_error(resource, WL_DISPLAY_ERROR_INVALID_OBJECT, |
| 4937 | "interface object already bound"); |
Kristian Høgsberg | eae5de7 | 2012-04-11 22:42:15 -0400 | [diff] [blame] | 4938 | wl_resource_destroy(resource); |
Pekka Paalanen | 6e16811 | 2011-11-24 11:34:05 +0200 | [diff] [blame] | 4939 | } |
| 4940 | |
Kristian Høgsberg | 0704539 | 2012-02-19 18:52:44 -0500 | [diff] [blame] | 4941 | struct switcher { |
Tiago Vignatti | be14326 | 2012-04-16 17:31:41 +0300 | [diff] [blame] | 4942 | struct desktop_shell *shell; |
Kristian Høgsberg | 0704539 | 2012-02-19 18:52:44 -0500 | [diff] [blame] | 4943 | struct weston_surface *current; |
| 4944 | struct wl_listener listener; |
Kristian Høgsberg | 29139d4 | 2013-04-18 15:25:39 -0400 | [diff] [blame] | 4945 | struct weston_keyboard_grab grab; |
Kristian Høgsberg | 0704539 | 2012-02-19 18:52:44 -0500 | [diff] [blame] | 4946 | }; |
| 4947 | |
| 4948 | static void |
| 4949 | switcher_next(struct switcher *switcher) |
| 4950 | { |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 4951 | struct weston_view *view; |
Kristian Høgsberg | 0704539 | 2012-02-19 18:52:44 -0500 | [diff] [blame] | 4952 | struct weston_surface *first = NULL, *prev = NULL, *next = NULL; |
Kristian Høgsberg | 32e5686 | 2012-04-02 22:18:58 -0400 | [diff] [blame] | 4953 | struct shell_surface *shsurf; |
Kristian Høgsberg | b0d8e77 | 2012-06-18 16:34:58 -0400 | [diff] [blame] | 4954 | struct workspace *ws = get_current_workspace(switcher->shell); |
Kristian Høgsberg | 0704539 | 2012-02-19 18:52:44 -0500 | [diff] [blame] | 4955 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 4956 | wl_list_for_each(view, &ws->layer.view_list, layer_link) { |
Rafael Antognolli | ed207b4 | 2013-12-03 15:35:43 -0200 | [diff] [blame] | 4957 | shsurf = get_shell_surface(view->surface); |
Rafael Antognolli | 5031cbe | 2013-12-05 19:01:21 -0200 | [diff] [blame] | 4958 | if (shsurf && |
| 4959 | shsurf->type == SHELL_SURFACE_TOPLEVEL && |
| 4960 | shsurf->parent == NULL) { |
Kristian Høgsberg | 0704539 | 2012-02-19 18:52:44 -0500 | [diff] [blame] | 4961 | if (first == NULL) |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 4962 | first = view->surface; |
Kristian Høgsberg | 0704539 | 2012-02-19 18:52:44 -0500 | [diff] [blame] | 4963 | if (prev == switcher->current) |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 4964 | next = view->surface; |
| 4965 | prev = view->surface; |
| 4966 | view->alpha = 0.25; |
| 4967 | weston_view_geometry_dirty(view); |
| 4968 | weston_surface_damage(view->surface); |
Kristian Høgsberg | 0704539 | 2012-02-19 18:52:44 -0500 | [diff] [blame] | 4969 | } |
Alex Wu | 1659daa | 2012-04-01 20:13:09 +0800 | [diff] [blame] | 4970 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 4971 | if (is_black_surface(view->surface, NULL)) { |
| 4972 | view->alpha = 0.25; |
| 4973 | weston_view_geometry_dirty(view); |
| 4974 | weston_surface_damage(view->surface); |
Alex Wu | 1659daa | 2012-04-01 20:13:09 +0800 | [diff] [blame] | 4975 | } |
Kristian Høgsberg | 0704539 | 2012-02-19 18:52:44 -0500 | [diff] [blame] | 4976 | } |
| 4977 | |
| 4978 | if (next == NULL) |
| 4979 | next = first; |
| 4980 | |
Alex Wu | 07b2606 | 2012-03-12 16:06:01 +0800 | [diff] [blame] | 4981 | if (next == NULL) |
| 4982 | return; |
| 4983 | |
Kristian Høgsberg | 0704539 | 2012-02-19 18:52:44 -0500 | [diff] [blame] | 4984 | wl_list_remove(&switcher->listener.link); |
Jason Ekstrand | 26ed73c | 2013-06-06 22:34:41 -0500 | [diff] [blame] | 4985 | wl_signal_add(&next->destroy_signal, &switcher->listener); |
Kristian Høgsberg | 0704539 | 2012-02-19 18:52:44 -0500 | [diff] [blame] | 4986 | |
| 4987 | switcher->current = next; |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 4988 | wl_list_for_each(view, &next->views, surface_link) |
| 4989 | view->alpha = 1.0; |
Alex Wu | 1659daa | 2012-04-01 20:13:09 +0800 | [diff] [blame] | 4990 | |
Kristian Høgsberg | 32e5686 | 2012-04-02 22:18:58 -0400 | [diff] [blame] | 4991 | shsurf = get_shell_surface(switcher->current); |
Rafael Antognolli | 03b1659 | 2013-12-03 15:35:42 -0200 | [diff] [blame] | 4992 | if (shsurf && shsurf->state.fullscreen) |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 4993 | shsurf->fullscreen.black_view->alpha = 1.0; |
Kristian Høgsberg | 0704539 | 2012-02-19 18:52:44 -0500 | [diff] [blame] | 4994 | } |
| 4995 | |
| 4996 | static void |
Kristian Høgsberg | 27e3052 | 2012-04-11 23:18:23 -0400 | [diff] [blame] | 4997 | switcher_handle_surface_destroy(struct wl_listener *listener, void *data) |
Kristian Høgsberg | 0704539 | 2012-02-19 18:52:44 -0500 | [diff] [blame] | 4998 | { |
| 4999 | struct switcher *switcher = |
| 5000 | container_of(listener, struct switcher, listener); |
| 5001 | |
| 5002 | switcher_next(switcher); |
| 5003 | } |
| 5004 | |
| 5005 | static void |
Daniel Stone | 351eb61 | 2012-05-31 15:27:47 -0400 | [diff] [blame] | 5006 | switcher_destroy(struct switcher *switcher) |
Kristian Høgsberg | 0704539 | 2012-02-19 18:52:44 -0500 | [diff] [blame] | 5007 | { |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 5008 | struct weston_view *view; |
Kristian Høgsberg | 29139d4 | 2013-04-18 15:25:39 -0400 | [diff] [blame] | 5009 | struct weston_keyboard *keyboard = switcher->grab.keyboard; |
Kristian Høgsberg | b0d8e77 | 2012-06-18 16:34:58 -0400 | [diff] [blame] | 5010 | struct workspace *ws = get_current_workspace(switcher->shell); |
Kristian Høgsberg | 0704539 | 2012-02-19 18:52:44 -0500 | [diff] [blame] | 5011 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 5012 | 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] | 5013 | if (is_focus_view(view)) |
| 5014 | continue; |
| 5015 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 5016 | view->alpha = 1.0; |
| 5017 | weston_surface_damage(view->surface); |
Kristian Høgsberg | 0704539 | 2012-02-19 18:52:44 -0500 | [diff] [blame] | 5018 | } |
| 5019 | |
Alex Wu | 07b2606 | 2012-03-12 16:06:01 +0800 | [diff] [blame] | 5020 | if (switcher->current) |
Daniel Stone | 37816df | 2012-05-16 18:45:18 +0100 | [diff] [blame] | 5021 | activate(switcher->shell, switcher->current, |
| 5022 | (struct weston_seat *) keyboard->seat); |
Kristian Høgsberg | 0704539 | 2012-02-19 18:52:44 -0500 | [diff] [blame] | 5023 | wl_list_remove(&switcher->listener.link); |
Kristian Høgsberg | 29139d4 | 2013-04-18 15:25:39 -0400 | [diff] [blame] | 5024 | weston_keyboard_end_grab(keyboard); |
| 5025 | if (keyboard->input_method_resource) |
| 5026 | keyboard->grab = &keyboard->input_method_grab; |
Kristian Høgsberg | 0704539 | 2012-02-19 18:52:44 -0500 | [diff] [blame] | 5027 | free(switcher); |
| 5028 | } |
| 5029 | |
| 5030 | static void |
Kristian Høgsberg | 29139d4 | 2013-04-18 15:25:39 -0400 | [diff] [blame] | 5031 | switcher_key(struct weston_keyboard_grab *grab, |
Daniel Stone | c9785ea | 2012-05-30 16:31:52 +0100 | [diff] [blame] | 5032 | uint32_t time, uint32_t key, uint32_t state_w) |
Kristian Høgsberg | 0704539 | 2012-02-19 18:52:44 -0500 | [diff] [blame] | 5033 | { |
| 5034 | struct switcher *switcher = container_of(grab, struct switcher, grab); |
Daniel Stone | c9785ea | 2012-05-30 16:31:52 +0100 | [diff] [blame] | 5035 | enum wl_keyboard_key_state state = state_w; |
Daniel Stone | 351eb61 | 2012-05-31 15:27:47 -0400 | [diff] [blame] | 5036 | |
Daniel Stone | c9785ea | 2012-05-30 16:31:52 +0100 | [diff] [blame] | 5037 | if (key == KEY_TAB && state == WL_KEYBOARD_KEY_STATE_PRESSED) |
Daniel Stone | 351eb61 | 2012-05-31 15:27:47 -0400 | [diff] [blame] | 5038 | switcher_next(switcher); |
| 5039 | } |
| 5040 | |
| 5041 | static void |
Kristian Høgsberg | 29139d4 | 2013-04-18 15:25:39 -0400 | [diff] [blame] | 5042 | switcher_modifier(struct weston_keyboard_grab *grab, uint32_t serial, |
Daniel Stone | 351eb61 | 2012-05-31 15:27:47 -0400 | [diff] [blame] | 5043 | uint32_t mods_depressed, uint32_t mods_latched, |
| 5044 | uint32_t mods_locked, uint32_t group) |
| 5045 | { |
| 5046 | struct switcher *switcher = container_of(grab, struct switcher, grab); |
Daniel Stone | 37816df | 2012-05-16 18:45:18 +0100 | [diff] [blame] | 5047 | struct weston_seat *seat = (struct weston_seat *) grab->keyboard->seat; |
Kristian Høgsberg | 0704539 | 2012-02-19 18:52:44 -0500 | [diff] [blame] | 5048 | |
Daniel Stone | 351eb61 | 2012-05-31 15:27:47 -0400 | [diff] [blame] | 5049 | if ((seat->modifier_state & switcher->shell->binding_modifier) == 0) |
| 5050 | switcher_destroy(switcher); |
Kristian Høgsberg | b71302e | 2012-05-10 12:28:35 -0400 | [diff] [blame] | 5051 | } |
Kristian Høgsberg | 0704539 | 2012-02-19 18:52:44 -0500 | [diff] [blame] | 5052 | |
Jonas Ådahl | 1ea343e | 2013-10-25 23:18:05 +0200 | [diff] [blame] | 5053 | static void |
| 5054 | switcher_cancel(struct weston_keyboard_grab *grab) |
| 5055 | { |
| 5056 | struct switcher *switcher = container_of(grab, struct switcher, grab); |
| 5057 | |
| 5058 | switcher_destroy(switcher); |
| 5059 | } |
| 5060 | |
Kristian Høgsberg | 29139d4 | 2013-04-18 15:25:39 -0400 | [diff] [blame] | 5061 | static const struct weston_keyboard_grab_interface switcher_grab = { |
Daniel Stone | 351eb61 | 2012-05-31 15:27:47 -0400 | [diff] [blame] | 5062 | switcher_key, |
| 5063 | switcher_modifier, |
Jonas Ådahl | 1ea343e | 2013-10-25 23:18:05 +0200 | [diff] [blame] | 5064 | switcher_cancel, |
Kristian Høgsberg | 0704539 | 2012-02-19 18:52:44 -0500 | [diff] [blame] | 5065 | }; |
| 5066 | |
| 5067 | static void |
Kristian Høgsberg | e314875 | 2013-05-06 23:19:49 -0400 | [diff] [blame] | 5068 | switcher_binding(struct weston_seat *seat, uint32_t time, uint32_t key, |
Daniel Stone | 325fc2d | 2012-05-30 16:31:58 +0100 | [diff] [blame] | 5069 | void *data) |
Kristian Høgsberg | 0704539 | 2012-02-19 18:52:44 -0500 | [diff] [blame] | 5070 | { |
Tiago Vignatti | be14326 | 2012-04-16 17:31:41 +0300 | [diff] [blame] | 5071 | struct desktop_shell *shell = data; |
Kristian Høgsberg | 0704539 | 2012-02-19 18:52:44 -0500 | [diff] [blame] | 5072 | struct switcher *switcher; |
| 5073 | |
| 5074 | switcher = malloc(sizeof *switcher); |
Kristian Høgsberg | 02e79dc | 2012-04-12 09:55:26 -0400 | [diff] [blame] | 5075 | switcher->shell = shell; |
Kristian Høgsberg | 0704539 | 2012-02-19 18:52:44 -0500 | [diff] [blame] | 5076 | switcher->current = NULL; |
Kristian Høgsberg | 27e3052 | 2012-04-11 23:18:23 -0400 | [diff] [blame] | 5077 | switcher->listener.notify = switcher_handle_surface_destroy; |
Kristian Høgsberg | 0704539 | 2012-02-19 18:52:44 -0500 | [diff] [blame] | 5078 | wl_list_init(&switcher->listener.link); |
| 5079 | |
Alexander Larsson | f82b6ca | 2013-05-28 16:23:39 +0200 | [diff] [blame] | 5080 | restore_all_output_modes(shell->compositor); |
Kristian Høgsberg | b0d8e77 | 2012-06-18 16:34:58 -0400 | [diff] [blame] | 5081 | lower_fullscreen_layer(switcher->shell); |
Kristian Høgsberg | 0704539 | 2012-02-19 18:52:44 -0500 | [diff] [blame] | 5082 | switcher->grab.interface = &switcher_grab; |
Kristian Høgsberg | 29139d4 | 2013-04-18 15:25:39 -0400 | [diff] [blame] | 5083 | weston_keyboard_start_grab(seat->keyboard, &switcher->grab); |
| 5084 | weston_keyboard_set_focus(seat->keyboard, NULL); |
Kristian Høgsberg | 0704539 | 2012-02-19 18:52:44 -0500 | [diff] [blame] | 5085 | switcher_next(switcher); |
| 5086 | } |
| 5087 | |
Pekka Paalanen | 3c64723 | 2011-12-22 13:43:43 +0200 | [diff] [blame] | 5088 | static void |
Kristian Høgsberg | e314875 | 2013-05-06 23:19:49 -0400 | [diff] [blame] | 5089 | backlight_binding(struct weston_seat *seat, uint32_t time, uint32_t key, |
Daniel Stone | 325fc2d | 2012-05-30 16:31:58 +0100 | [diff] [blame] | 5090 | void *data) |
Tiago Vignatti | 8e53c7f | 2012-02-29 19:53:50 +0200 | [diff] [blame] | 5091 | { |
| 5092 | struct weston_compositor *compositor = data; |
| 5093 | struct weston_output *output; |
Tiago Vignatti | 5ab91ad | 2012-03-12 19:40:09 -0300 | [diff] [blame] | 5094 | long backlight_new = 0; |
Tiago Vignatti | 8e53c7f | 2012-02-29 19:53:50 +0200 | [diff] [blame] | 5095 | |
| 5096 | /* TODO: we're limiting to simple use cases, where we assume just |
| 5097 | * control on the primary display. We'd have to extend later if we |
| 5098 | * ever get support for setting backlights on random desktop LCD |
| 5099 | * panels though */ |
| 5100 | output = get_default_output(compositor); |
| 5101 | if (!output) |
| 5102 | return; |
| 5103 | |
| 5104 | if (!output->set_backlight) |
| 5105 | return; |
| 5106 | |
Tiago Vignatti | 5ab91ad | 2012-03-12 19:40:09 -0300 | [diff] [blame] | 5107 | if (key == KEY_F9 || key == KEY_BRIGHTNESSDOWN) |
| 5108 | backlight_new = output->backlight_current - 25; |
| 5109 | else if (key == KEY_F10 || key == KEY_BRIGHTNESSUP) |
| 5110 | backlight_new = output->backlight_current + 25; |
Tiago Vignatti | 8e53c7f | 2012-02-29 19:53:50 +0200 | [diff] [blame] | 5111 | |
Tiago Vignatti | 5ab91ad | 2012-03-12 19:40:09 -0300 | [diff] [blame] | 5112 | if (backlight_new < 5) |
| 5113 | backlight_new = 5; |
| 5114 | if (backlight_new > 255) |
| 5115 | backlight_new = 255; |
| 5116 | |
| 5117 | output->backlight_current = backlight_new; |
Tiago Vignatti | 8e53c7f | 2012-02-29 19:53:50 +0200 | [diff] [blame] | 5118 | output->set_backlight(output, output->backlight_current); |
| 5119 | } |
| 5120 | |
Ander Conselvan de Oliveira | c509d2b | 2012-11-08 17:20:45 +0200 | [diff] [blame] | 5121 | struct debug_binding_grab { |
Kristian Høgsberg | 29139d4 | 2013-04-18 15:25:39 -0400 | [diff] [blame] | 5122 | struct weston_keyboard_grab grab; |
Ander Conselvan de Oliveira | c509d2b | 2012-11-08 17:20:45 +0200 | [diff] [blame] | 5123 | struct weston_seat *seat; |
| 5124 | uint32_t key[2]; |
| 5125 | int key_released[2]; |
| 5126 | }; |
| 5127 | |
| 5128 | static void |
Kristian Høgsberg | 29139d4 | 2013-04-18 15:25:39 -0400 | [diff] [blame] | 5129 | 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] | 5130 | uint32_t key, uint32_t state) |
| 5131 | { |
| 5132 | struct debug_binding_grab *db = (struct debug_binding_grab *) grab; |
Rob Bradford | 880ebc7 | 2013-07-22 17:31:38 +0100 | [diff] [blame] | 5133 | struct weston_compositor *ec = db->seat->compositor; |
| 5134 | struct wl_display *display = ec->wl_display; |
Ander Conselvan de Oliveira | c509d2b | 2012-11-08 17:20:45 +0200 | [diff] [blame] | 5135 | struct wl_resource *resource; |
Ander Conselvan de Oliveira | c509d2b | 2012-11-08 17:20:45 +0200 | [diff] [blame] | 5136 | uint32_t serial; |
| 5137 | int send = 0, terminate = 0; |
| 5138 | int check_binding = 1; |
| 5139 | int i; |
Neil Roberts | 96d790e | 2013-09-19 17:32:00 +0100 | [diff] [blame] | 5140 | struct wl_list *resource_list; |
Ander Conselvan de Oliveira | c509d2b | 2012-11-08 17:20:45 +0200 | [diff] [blame] | 5141 | |
| 5142 | if (state == WL_KEYBOARD_KEY_STATE_RELEASED) { |
| 5143 | /* Do not run bindings on key releases */ |
| 5144 | check_binding = 0; |
| 5145 | |
| 5146 | for (i = 0; i < 2; i++) |
| 5147 | if (key == db->key[i]) |
| 5148 | db->key_released[i] = 1; |
| 5149 | |
| 5150 | if (db->key_released[0] && db->key_released[1]) { |
| 5151 | /* All key releases been swalled so end the grab */ |
| 5152 | terminate = 1; |
| 5153 | } else if (key != db->key[0] && key != db->key[1]) { |
| 5154 | /* Should not swallow release of other keys */ |
| 5155 | send = 1; |
| 5156 | } |
| 5157 | } else if (key == db->key[0] && !db->key_released[0]) { |
| 5158 | /* Do not check bindings for the first press of the binding |
| 5159 | * key. This allows it to be used as a debug shortcut. |
| 5160 | * We still need to swallow this event. */ |
| 5161 | check_binding = 0; |
| 5162 | } else if (db->key[1]) { |
| 5163 | /* If we already ran a binding don't process another one since |
| 5164 | * we can't keep track of all the binding keys that were |
| 5165 | * pressed in order to swallow the release events. */ |
| 5166 | send = 1; |
| 5167 | check_binding = 0; |
| 5168 | } |
| 5169 | |
| 5170 | if (check_binding) { |
Ander Conselvan de Oliveira | c509d2b | 2012-11-08 17:20:45 +0200 | [diff] [blame] | 5171 | if (weston_compositor_run_debug_binding(ec, db->seat, time, |
| 5172 | key, state)) { |
| 5173 | /* We ran a binding so swallow the press and keep the |
| 5174 | * grab to swallow the released too. */ |
| 5175 | send = 0; |
| 5176 | terminate = 0; |
| 5177 | db->key[1] = key; |
| 5178 | } else { |
| 5179 | /* Terminate the grab since the key pressed is not a |
| 5180 | * debug binding key. */ |
| 5181 | send = 1; |
| 5182 | terminate = 1; |
| 5183 | } |
| 5184 | } |
| 5185 | |
| 5186 | if (send) { |
Neil Roberts | 96d790e | 2013-09-19 17:32:00 +0100 | [diff] [blame] | 5187 | serial = wl_display_next_serial(display); |
| 5188 | resource_list = &grab->keyboard->focus_resource_list; |
| 5189 | wl_resource_for_each(resource, resource_list) { |
Ander Conselvan de Oliveira | c509d2b | 2012-11-08 17:20:45 +0200 | [diff] [blame] | 5190 | wl_keyboard_send_key(resource, serial, time, key, state); |
| 5191 | } |
| 5192 | } |
| 5193 | |
| 5194 | if (terminate) { |
Kristian Høgsberg | 29139d4 | 2013-04-18 15:25:39 -0400 | [diff] [blame] | 5195 | weston_keyboard_end_grab(grab->keyboard); |
| 5196 | if (grab->keyboard->input_method_resource) |
| 5197 | grab->keyboard->grab = &grab->keyboard->input_method_grab; |
Ander Conselvan de Oliveira | c509d2b | 2012-11-08 17:20:45 +0200 | [diff] [blame] | 5198 | free(db); |
| 5199 | } |
| 5200 | } |
| 5201 | |
| 5202 | static void |
Kristian Høgsberg | 29139d4 | 2013-04-18 15:25:39 -0400 | [diff] [blame] | 5203 | 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] | 5204 | uint32_t mods_depressed, uint32_t mods_latched, |
| 5205 | uint32_t mods_locked, uint32_t group) |
| 5206 | { |
| 5207 | struct wl_resource *resource; |
Neil Roberts | 96d790e | 2013-09-19 17:32:00 +0100 | [diff] [blame] | 5208 | struct wl_list *resource_list; |
Ander Conselvan de Oliveira | c509d2b | 2012-11-08 17:20:45 +0200 | [diff] [blame] | 5209 | |
Neil Roberts | 96d790e | 2013-09-19 17:32:00 +0100 | [diff] [blame] | 5210 | resource_list = &grab->keyboard->focus_resource_list; |
Ander Conselvan de Oliveira | c509d2b | 2012-11-08 17:20:45 +0200 | [diff] [blame] | 5211 | |
Neil Roberts | 96d790e | 2013-09-19 17:32:00 +0100 | [diff] [blame] | 5212 | wl_resource_for_each(resource, resource_list) { |
| 5213 | wl_keyboard_send_modifiers(resource, serial, mods_depressed, |
| 5214 | mods_latched, mods_locked, group); |
| 5215 | } |
Ander Conselvan de Oliveira | c509d2b | 2012-11-08 17:20:45 +0200 | [diff] [blame] | 5216 | } |
| 5217 | |
Jonas Ådahl | 1ea343e | 2013-10-25 23:18:05 +0200 | [diff] [blame] | 5218 | static void |
| 5219 | debug_binding_cancel(struct weston_keyboard_grab *grab) |
| 5220 | { |
| 5221 | struct debug_binding_grab *db = (struct debug_binding_grab *) grab; |
| 5222 | |
| 5223 | weston_keyboard_end_grab(grab->keyboard); |
| 5224 | free(db); |
| 5225 | } |
| 5226 | |
Kristian Høgsberg | 29139d4 | 2013-04-18 15:25:39 -0400 | [diff] [blame] | 5227 | struct weston_keyboard_grab_interface debug_binding_keyboard_grab = { |
Ander Conselvan de Oliveira | c509d2b | 2012-11-08 17:20:45 +0200 | [diff] [blame] | 5228 | debug_binding_key, |
Jonas Ådahl | 1ea343e | 2013-10-25 23:18:05 +0200 | [diff] [blame] | 5229 | debug_binding_modifiers, |
| 5230 | debug_binding_cancel, |
Ander Conselvan de Oliveira | c509d2b | 2012-11-08 17:20:45 +0200 | [diff] [blame] | 5231 | }; |
| 5232 | |
| 5233 | static void |
Kristian Høgsberg | e314875 | 2013-05-06 23:19:49 -0400 | [diff] [blame] | 5234 | 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] | 5235 | { |
| 5236 | struct debug_binding_grab *grab; |
| 5237 | |
| 5238 | grab = calloc(1, sizeof *grab); |
| 5239 | if (!grab) |
| 5240 | return; |
| 5241 | |
| 5242 | grab->seat = (struct weston_seat *) seat; |
| 5243 | grab->key[0] = key; |
| 5244 | grab->grab.interface = &debug_binding_keyboard_grab; |
Kristian Høgsberg | 29139d4 | 2013-04-18 15:25:39 -0400 | [diff] [blame] | 5245 | weston_keyboard_start_grab(seat->keyboard, &grab->grab); |
Ander Conselvan de Oliveira | c509d2b | 2012-11-08 17:20:45 +0200 | [diff] [blame] | 5246 | } |
| 5247 | |
Kristian Høgsberg | b41c081 | 2012-03-04 14:53:40 -0500 | [diff] [blame] | 5248 | static void |
Kristian Høgsberg | e314875 | 2013-05-06 23:19:49 -0400 | [diff] [blame] | 5249 | 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] | 5250 | void *data) |
Kristian Høgsberg | 92a57db | 2012-05-26 13:41:06 -0400 | [diff] [blame] | 5251 | { |
Kristian Høgsberg | fe7aa90 | 2013-05-08 09:54:37 -0400 | [diff] [blame] | 5252 | struct weston_surface *focus_surface; |
Kristian Høgsberg | 92a57db | 2012-05-26 13:41:06 -0400 | [diff] [blame] | 5253 | struct wl_client *client; |
Tiago Vignatti | 1d01b01 | 2012-09-27 17:48:36 +0300 | [diff] [blame] | 5254 | struct desktop_shell *shell = data; |
| 5255 | struct weston_compositor *compositor = shell->compositor; |
Kristian Høgsberg | 92a57db | 2012-05-26 13:41:06 -0400 | [diff] [blame] | 5256 | pid_t pid; |
Kristian Høgsberg | 92a57db | 2012-05-26 13:41:06 -0400 | [diff] [blame] | 5257 | |
Philipp Brüschweiler | 6cef009 | 2012-08-13 21:27:27 +0200 | [diff] [blame] | 5258 | focus_surface = seat->keyboard->focus; |
| 5259 | if (!focus_surface) |
| 5260 | return; |
| 5261 | |
Tiago Vignatti | 1d01b01 | 2012-09-27 17:48:36 +0300 | [diff] [blame] | 5262 | wl_signal_emit(&compositor->kill_signal, focus_surface); |
| 5263 | |
Jason Ekstrand | 26ed73c | 2013-06-06 22:34:41 -0500 | [diff] [blame] | 5264 | client = wl_resource_get_client(focus_surface->resource); |
Tiago Vignatti | 920f197 | 2012-09-27 17:48:35 +0300 | [diff] [blame] | 5265 | wl_client_get_credentials(client, &pid, NULL, NULL); |
| 5266 | |
| 5267 | /* Skip clients that we launched ourselves (the credentials of |
| 5268 | * the socketpair is ours) */ |
| 5269 | if (pid == getpid()) |
| 5270 | return; |
Kristian Høgsberg | 92a57db | 2012-05-26 13:41:06 -0400 | [diff] [blame] | 5271 | |
Daniel Stone | 325fc2d | 2012-05-30 16:31:58 +0100 | [diff] [blame] | 5272 | kill(pid, SIGKILL); |
Kristian Høgsberg | 92a57db | 2012-05-26 13:41:06 -0400 | [diff] [blame] | 5273 | } |
| 5274 | |
| 5275 | static void |
Kristian Høgsberg | e314875 | 2013-05-06 23:19:49 -0400 | [diff] [blame] | 5276 | workspace_up_binding(struct weston_seat *seat, uint32_t time, |
Jonas Ådahl | e3cddce | 2012-06-13 00:01:22 +0200 | [diff] [blame] | 5277 | uint32_t key, void *data) |
| 5278 | { |
| 5279 | struct desktop_shell *shell = data; |
| 5280 | unsigned int new_index = shell->workspaces.current; |
| 5281 | |
Kristian Høgsberg | ce345b0 | 2012-06-25 21:35:29 -0400 | [diff] [blame] | 5282 | if (shell->locked) |
Kristian Høgsberg | 4476aaf | 2012-06-25 14:03:13 -0400 | [diff] [blame] | 5283 | return; |
Jonas Ådahl | e3cddce | 2012-06-13 00:01:22 +0200 | [diff] [blame] | 5284 | if (new_index != 0) |
| 5285 | new_index--; |
| 5286 | |
| 5287 | change_workspace(shell, new_index); |
| 5288 | } |
| 5289 | |
| 5290 | static void |
Kristian Høgsberg | e314875 | 2013-05-06 23:19:49 -0400 | [diff] [blame] | 5291 | workspace_down_binding(struct weston_seat *seat, uint32_t time, |
Jonas Ådahl | e3cddce | 2012-06-13 00:01:22 +0200 | [diff] [blame] | 5292 | uint32_t key, void *data) |
| 5293 | { |
| 5294 | struct desktop_shell *shell = data; |
| 5295 | unsigned int new_index = shell->workspaces.current; |
| 5296 | |
Kristian Høgsberg | ce345b0 | 2012-06-25 21:35:29 -0400 | [diff] [blame] | 5297 | if (shell->locked) |
Kristian Høgsberg | 4476aaf | 2012-06-25 14:03:13 -0400 | [diff] [blame] | 5298 | return; |
Jonas Ådahl | e3cddce | 2012-06-13 00:01:22 +0200 | [diff] [blame] | 5299 | if (new_index < shell->workspaces.num - 1) |
| 5300 | new_index++; |
| 5301 | |
| 5302 | change_workspace(shell, new_index); |
| 5303 | } |
| 5304 | |
| 5305 | static void |
Kristian Høgsberg | e314875 | 2013-05-06 23:19:49 -0400 | [diff] [blame] | 5306 | workspace_f_binding(struct weston_seat *seat, uint32_t time, |
Jonas Ådahl | e3cddce | 2012-06-13 00:01:22 +0200 | [diff] [blame] | 5307 | uint32_t key, void *data) |
| 5308 | { |
| 5309 | struct desktop_shell *shell = data; |
| 5310 | unsigned int new_index; |
| 5311 | |
Kristian Høgsberg | ce345b0 | 2012-06-25 21:35:29 -0400 | [diff] [blame] | 5312 | if (shell->locked) |
Kristian Høgsberg | 4476aaf | 2012-06-25 14:03:13 -0400 | [diff] [blame] | 5313 | return; |
Jonas Ådahl | e3cddce | 2012-06-13 00:01:22 +0200 | [diff] [blame] | 5314 | new_index = key - KEY_F1; |
| 5315 | if (new_index >= shell->workspaces.num) |
| 5316 | new_index = shell->workspaces.num - 1; |
| 5317 | |
| 5318 | change_workspace(shell, new_index); |
| 5319 | } |
| 5320 | |
Jonas Ådahl | 8de6a1d | 2012-08-29 22:13:00 +0200 | [diff] [blame] | 5321 | static void |
Kristian Høgsberg | e314875 | 2013-05-06 23:19:49 -0400 | [diff] [blame] | 5322 | workspace_move_surface_up_binding(struct weston_seat *seat, uint32_t time, |
Jonas Ådahl | 8de6a1d | 2012-08-29 22:13:00 +0200 | [diff] [blame] | 5323 | uint32_t key, void *data) |
| 5324 | { |
| 5325 | struct desktop_shell *shell = data; |
| 5326 | unsigned int new_index = shell->workspaces.current; |
| 5327 | |
| 5328 | if (shell->locked) |
| 5329 | return; |
| 5330 | |
| 5331 | if (new_index != 0) |
| 5332 | new_index--; |
| 5333 | |
| 5334 | take_surface_to_workspace_by_seat(shell, seat, new_index); |
| 5335 | } |
| 5336 | |
| 5337 | static void |
Kristian Høgsberg | e314875 | 2013-05-06 23:19:49 -0400 | [diff] [blame] | 5338 | workspace_move_surface_down_binding(struct weston_seat *seat, uint32_t time, |
Jonas Ådahl | 8de6a1d | 2012-08-29 22:13:00 +0200 | [diff] [blame] | 5339 | uint32_t key, void *data) |
| 5340 | { |
| 5341 | struct desktop_shell *shell = data; |
| 5342 | unsigned int new_index = shell->workspaces.current; |
| 5343 | |
| 5344 | if (shell->locked) |
| 5345 | return; |
| 5346 | |
| 5347 | if (new_index < shell->workspaces.num - 1) |
| 5348 | new_index++; |
| 5349 | |
| 5350 | take_surface_to_workspace_by_seat(shell, seat, new_index); |
| 5351 | } |
Jonas Ådahl | e3cddce | 2012-06-13 00:01:22 +0200 | [diff] [blame] | 5352 | |
| 5353 | static void |
Xiong Zhang | 6b48142 | 2013-10-23 13:58:32 +0800 | [diff] [blame] | 5354 | handle_output_destroy(struct wl_listener *listener, void *data) |
| 5355 | { |
| 5356 | struct shell_output *output_listener = |
| 5357 | container_of(listener, struct shell_output, destroy_listener); |
| 5358 | |
| 5359 | wl_list_remove(&output_listener->destroy_listener.link); |
| 5360 | wl_list_remove(&output_listener->link); |
| 5361 | free(output_listener); |
| 5362 | } |
| 5363 | |
| 5364 | static void |
| 5365 | create_shell_output(struct desktop_shell *shell, |
| 5366 | struct weston_output *output) |
| 5367 | { |
| 5368 | struct shell_output *shell_output; |
| 5369 | |
| 5370 | shell_output = zalloc(sizeof *shell_output); |
| 5371 | if (shell_output == NULL) |
| 5372 | return; |
| 5373 | |
| 5374 | shell_output->output = output; |
| 5375 | shell_output->shell = shell; |
| 5376 | shell_output->destroy_listener.notify = handle_output_destroy; |
| 5377 | wl_signal_add(&output->destroy_signal, |
| 5378 | &shell_output->destroy_listener); |
Kristian Høgsberg | a3a0e18 | 2013-10-23 23:36:04 -0700 | [diff] [blame] | 5379 | wl_list_insert(shell->output_list.prev, &shell_output->link); |
Xiong Zhang | 6b48142 | 2013-10-23 13:58:32 +0800 | [diff] [blame] | 5380 | } |
| 5381 | |
| 5382 | static void |
| 5383 | handle_output_create(struct wl_listener *listener, void *data) |
| 5384 | { |
| 5385 | struct desktop_shell *shell = |
| 5386 | container_of(listener, struct desktop_shell, output_create_listener); |
| 5387 | struct weston_output *output = (struct weston_output *)data; |
| 5388 | |
| 5389 | create_shell_output(shell, output); |
| 5390 | } |
| 5391 | |
| 5392 | static void |
| 5393 | setup_output_destroy_handler(struct weston_compositor *ec, |
| 5394 | struct desktop_shell *shell) |
| 5395 | { |
| 5396 | struct weston_output *output; |
| 5397 | |
| 5398 | wl_list_init(&shell->output_list); |
| 5399 | wl_list_for_each(output, &ec->output_list, link) |
| 5400 | create_shell_output(shell, output); |
| 5401 | |
| 5402 | shell->output_create_listener.notify = handle_output_create; |
| 5403 | wl_signal_add(&ec->output_created_signal, |
| 5404 | &shell->output_create_listener); |
| 5405 | } |
| 5406 | |
| 5407 | static void |
Kristian Høgsberg | 02e79dc | 2012-04-12 09:55:26 -0400 | [diff] [blame] | 5408 | shell_destroy(struct wl_listener *listener, void *data) |
Pekka Paalanen | 3c64723 | 2011-12-22 13:43:43 +0200 | [diff] [blame] | 5409 | { |
Tiago Vignatti | be14326 | 2012-04-16 17:31:41 +0300 | [diff] [blame] | 5410 | struct desktop_shell *shell = |
| 5411 | container_of(listener, struct desktop_shell, destroy_listener); |
Jonas Ådahl | e3cddce | 2012-06-13 00:01:22 +0200 | [diff] [blame] | 5412 | struct workspace **ws; |
Xiong Zhang | 6b48142 | 2013-10-23 13:58:32 +0800 | [diff] [blame] | 5413 | struct shell_output *shell_output, *tmp; |
Pekka Paalanen | 3c64723 | 2011-12-22 13:43:43 +0200 | [diff] [blame] | 5414 | |
Pekka Paalanen | 9cf5cc8 | 2012-01-02 16:00:24 +0200 | [diff] [blame] | 5415 | if (shell->child.client) |
| 5416 | wl_client_destroy(shell->child.client); |
| 5417 | |
Ander Conselvan de Oliveira | a457563 | 2013-02-21 18:35:23 +0200 | [diff] [blame] | 5418 | wl_list_remove(&shell->idle_listener.link); |
| 5419 | wl_list_remove(&shell->wake_listener.link); |
Kristian Høgsberg | 677a5f5 | 2013-12-04 11:00:19 -0800 | [diff] [blame] | 5420 | |
| 5421 | input_panel_destroy(shell); |
Kristian Høgsberg | 88c1607 | 2012-05-16 08:04:19 -0400 | [diff] [blame] | 5422 | |
Xiong Zhang | 6b48142 | 2013-10-23 13:58:32 +0800 | [diff] [blame] | 5423 | wl_list_for_each_safe(shell_output, tmp, &shell->output_list, link) { |
| 5424 | wl_list_remove(&shell_output->destroy_listener.link); |
| 5425 | wl_list_remove(&shell_output->link); |
| 5426 | free(shell_output); |
| 5427 | } |
| 5428 | |
| 5429 | wl_list_remove(&shell->output_create_listener.link); |
| 5430 | |
Jonas Ådahl | e3cddce | 2012-06-13 00:01:22 +0200 | [diff] [blame] | 5431 | wl_array_for_each(ws, &shell->workspaces.array) |
| 5432 | workspace_destroy(*ws); |
| 5433 | wl_array_release(&shell->workspaces.array); |
| 5434 | |
Pekka Paalanen | 3c64723 | 2011-12-22 13:43:43 +0200 | [diff] [blame] | 5435 | free(shell->screensaver.path); |
Emilio Pozuelo Monfort | 46ce798 | 2013-11-20 13:22:29 +0100 | [diff] [blame] | 5436 | free(shell->client); |
Pekka Paalanen | 3c64723 | 2011-12-22 13:43:43 +0200 | [diff] [blame] | 5437 | free(shell); |
| 5438 | } |
| 5439 | |
Tiago Vignatti | 0b52d48 | 2012-04-20 18:54:25 +0300 | [diff] [blame] | 5440 | static void |
| 5441 | shell_add_bindings(struct weston_compositor *ec, struct desktop_shell *shell) |
| 5442 | { |
| 5443 | uint32_t mod; |
Jonas Ådahl | e3cddce | 2012-06-13 00:01:22 +0200 | [diff] [blame] | 5444 | int i, num_workspace_bindings; |
Tiago Vignatti | 0b52d48 | 2012-04-20 18:54:25 +0300 | [diff] [blame] | 5445 | |
| 5446 | /* fixed bindings */ |
Daniel Stone | 325fc2d | 2012-05-30 16:31:58 +0100 | [diff] [blame] | 5447 | weston_compositor_add_key_binding(ec, KEY_BACKSPACE, |
| 5448 | MODIFIER_CTRL | MODIFIER_ALT, |
| 5449 | terminate_binding, ec); |
| 5450 | weston_compositor_add_button_binding(ec, BTN_LEFT, 0, |
| 5451 | click_to_activate_binding, |
| 5452 | shell); |
Neil Roberts | a28c693 | 2013-10-03 16:43:04 +0100 | [diff] [blame] | 5453 | weston_compositor_add_touch_binding(ec, 0, |
| 5454 | touch_to_activate_binding, |
| 5455 | shell); |
Daniel Stone | 325fc2d | 2012-05-30 16:31:58 +0100 | [diff] [blame] | 5456 | weston_compositor_add_axis_binding(ec, WL_POINTER_AXIS_VERTICAL_SCROLL, |
| 5457 | MODIFIER_SUPER | MODIFIER_ALT, |
| 5458 | surface_opacity_binding, NULL); |
| 5459 | weston_compositor_add_axis_binding(ec, WL_POINTER_AXIS_VERTICAL_SCROLL, |
| 5460 | MODIFIER_SUPER, zoom_axis_binding, |
| 5461 | NULL); |
Tiago Vignatti | 0b52d48 | 2012-04-20 18:54:25 +0300 | [diff] [blame] | 5462 | |
| 5463 | /* configurable bindings */ |
| 5464 | mod = shell->binding_modifier; |
Daniel Stone | 325fc2d | 2012-05-30 16:31:58 +0100 | [diff] [blame] | 5465 | weston_compositor_add_key_binding(ec, KEY_PAGEUP, mod, |
| 5466 | zoom_key_binding, NULL); |
| 5467 | weston_compositor_add_key_binding(ec, KEY_PAGEDOWN, mod, |
| 5468 | zoom_key_binding, NULL); |
Rafael Antognolli | ea997ac | 2013-12-03 15:35:48 -0200 | [diff] [blame] | 5469 | weston_compositor_add_key_binding(ec, KEY_M, mod, maximize_binding, |
| 5470 | NULL); |
| 5471 | weston_compositor_add_key_binding(ec, KEY_F, mod, fullscreen_binding, |
| 5472 | NULL); |
Daniel Stone | 325fc2d | 2012-05-30 16:31:58 +0100 | [diff] [blame] | 5473 | weston_compositor_add_button_binding(ec, BTN_LEFT, mod, move_binding, |
| 5474 | shell); |
Neil Roberts | aba0f25 | 2013-10-03 16:43:05 +0100 | [diff] [blame] | 5475 | weston_compositor_add_touch_binding(ec, mod, touch_move_binding, shell); |
Daniel Stone | 325fc2d | 2012-05-30 16:31:58 +0100 | [diff] [blame] | 5476 | weston_compositor_add_button_binding(ec, BTN_MIDDLE, mod, |
| 5477 | resize_binding, shell); |
Pekka Paalanen | 7bb6510 | 2013-05-22 18:03:04 +0300 | [diff] [blame] | 5478 | |
| 5479 | if (ec->capabilities & WESTON_CAP_ROTATION_ANY) |
| 5480 | weston_compositor_add_button_binding(ec, BTN_RIGHT, mod, |
| 5481 | rotate_binding, NULL); |
| 5482 | |
Daniel Stone | 325fc2d | 2012-05-30 16:31:58 +0100 | [diff] [blame] | 5483 | weston_compositor_add_key_binding(ec, KEY_TAB, mod, switcher_binding, |
| 5484 | shell); |
| 5485 | weston_compositor_add_key_binding(ec, KEY_F9, mod, backlight_binding, |
| 5486 | ec); |
| 5487 | weston_compositor_add_key_binding(ec, KEY_BRIGHTNESSDOWN, 0, |
| 5488 | backlight_binding, ec); |
| 5489 | weston_compositor_add_key_binding(ec, KEY_F10, mod, backlight_binding, |
| 5490 | ec); |
| 5491 | weston_compositor_add_key_binding(ec, KEY_BRIGHTNESSUP, 0, |
| 5492 | backlight_binding, ec); |
Daniel Stone | 325fc2d | 2012-05-30 16:31:58 +0100 | [diff] [blame] | 5493 | weston_compositor_add_key_binding(ec, KEY_K, mod, |
| 5494 | force_kill_binding, shell); |
Jonas Ådahl | e3cddce | 2012-06-13 00:01:22 +0200 | [diff] [blame] | 5495 | weston_compositor_add_key_binding(ec, KEY_UP, mod, |
| 5496 | workspace_up_binding, shell); |
| 5497 | weston_compositor_add_key_binding(ec, KEY_DOWN, mod, |
| 5498 | workspace_down_binding, shell); |
Jonas Ådahl | 8de6a1d | 2012-08-29 22:13:00 +0200 | [diff] [blame] | 5499 | weston_compositor_add_key_binding(ec, KEY_UP, mod | MODIFIER_SHIFT, |
| 5500 | workspace_move_surface_up_binding, |
| 5501 | shell); |
| 5502 | weston_compositor_add_key_binding(ec, KEY_DOWN, mod | MODIFIER_SHIFT, |
| 5503 | workspace_move_surface_down_binding, |
| 5504 | shell); |
Jonas Ådahl | e3cddce | 2012-06-13 00:01:22 +0200 | [diff] [blame] | 5505 | |
Daniel Stone | df8133b | 2013-11-19 11:37:14 +0100 | [diff] [blame] | 5506 | weston_compositor_add_modifier_binding(ec, mod, exposay_binding, shell); |
| 5507 | |
Jonas Ådahl | e3cddce | 2012-06-13 00:01:22 +0200 | [diff] [blame] | 5508 | /* Add bindings for mod+F[1-6] for workspace 1 to 6. */ |
| 5509 | if (shell->workspaces.num > 1) { |
| 5510 | num_workspace_bindings = shell->workspaces.num; |
| 5511 | if (num_workspace_bindings > 6) |
| 5512 | num_workspace_bindings = 6; |
| 5513 | for (i = 0; i < num_workspace_bindings; i++) |
| 5514 | weston_compositor_add_key_binding(ec, KEY_F1 + i, mod, |
| 5515 | workspace_f_binding, |
| 5516 | shell); |
| 5517 | } |
Ander Conselvan de Oliveira | c509d2b | 2012-11-08 17:20:45 +0200 | [diff] [blame] | 5518 | |
| 5519 | /* Debug bindings */ |
| 5520 | weston_compositor_add_key_binding(ec, KEY_SPACE, mod | MODIFIER_SHIFT, |
| 5521 | debug_binding, shell); |
Tiago Vignatti | 0b52d48 | 2012-04-20 18:54:25 +0300 | [diff] [blame] | 5522 | } |
| 5523 | |
Kristian Høgsberg | 1c56218 | 2011-05-02 22:09:20 -0400 | [diff] [blame] | 5524 | WL_EXPORT int |
Kristian Høgsberg | cb4685b | 2013-02-20 15:37:49 -0500 | [diff] [blame] | 5525 | module_init(struct weston_compositor *ec, |
Ossama Othman | a50e6e4 | 2013-05-14 09:48:26 -0700 | [diff] [blame] | 5526 | int *argc, char *argv[]) |
Kristian Høgsberg | 4cca349 | 2011-01-18 07:53:49 -0500 | [diff] [blame] | 5527 | { |
Kristian Høgsberg | f4d2f23 | 2012-08-10 10:05:39 -0400 | [diff] [blame] | 5528 | struct weston_seat *seat; |
Tiago Vignatti | be14326 | 2012-04-16 17:31:41 +0300 | [diff] [blame] | 5529 | struct desktop_shell *shell; |
Jonas Ådahl | e3cddce | 2012-06-13 00:01:22 +0200 | [diff] [blame] | 5530 | struct workspace **pws; |
| 5531 | unsigned int i; |
Tiago Vignatti | b7dbbd6 | 2012-09-25 17:57:01 +0300 | [diff] [blame] | 5532 | struct wl_event_loop *loop; |
Kristian Høgsberg | 02ec0a5 | 2011-04-23 13:04:11 -0400 | [diff] [blame] | 5533 | |
Peter Hutterer | f3d6227 | 2013-08-08 11:57:05 +1000 | [diff] [blame] | 5534 | shell = zalloc(sizeof *shell); |
Kristian Høgsberg | 02ec0a5 | 2011-04-23 13:04:11 -0400 | [diff] [blame] | 5535 | if (shell == NULL) |
| 5536 | return -1; |
| 5537 | |
Kristian Høgsberg | 7584062 | 2011-09-06 13:48:16 -0400 | [diff] [blame] | 5538 | shell->compositor = ec; |
Kristian Høgsberg | 02e79dc | 2012-04-12 09:55:26 -0400 | [diff] [blame] | 5539 | |
| 5540 | shell->destroy_listener.notify = shell_destroy; |
| 5541 | wl_signal_add(&ec->destroy_signal, &shell->destroy_listener); |
Ander Conselvan de Oliveira | a457563 | 2013-02-21 18:35:23 +0200 | [diff] [blame] | 5542 | shell->idle_listener.notify = idle_handler; |
| 5543 | wl_signal_add(&ec->idle_signal, &shell->idle_listener); |
| 5544 | shell->wake_listener.notify = wake_handler; |
| 5545 | wl_signal_add(&ec->wake_signal, &shell->wake_listener); |
Kristian Høgsberg | 677a5f5 | 2013-12-04 11:00:19 -0800 | [diff] [blame] | 5546 | |
Scott Moreau | ff1db4a | 2012-04-17 19:06:18 -0600 | [diff] [blame] | 5547 | ec->ping_handler = ping_handler; |
Kristian Høgsberg | 82a1d11 | 2012-07-19 14:02:00 -0400 | [diff] [blame] | 5548 | ec->shell_interface.shell = shell; |
Tiago Vignatti | bc052c9 | 2012-04-19 16:18:18 +0300 | [diff] [blame] | 5549 | ec->shell_interface.create_shell_surface = create_shell_surface; |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 5550 | ec->shell_interface.get_primary_view = get_primary_view; |
Tiago Vignatti | bc052c9 | 2012-04-19 16:18:18 +0300 | [diff] [blame] | 5551 | ec->shell_interface.set_toplevel = set_toplevel; |
Tiago Vignatti | 491bac1 | 2012-05-18 16:37:43 -0400 | [diff] [blame] | 5552 | ec->shell_interface.set_transient = set_transient; |
Kristian Høgsberg | b810eb5 | 2013-02-12 20:07:05 -0500 | [diff] [blame] | 5553 | ec->shell_interface.set_fullscreen = set_fullscreen; |
Tiago Vignatti | fb2adba | 2013-06-12 15:43:21 -0300 | [diff] [blame] | 5554 | ec->shell_interface.set_xwayland = set_xwayland; |
Kristian Høgsberg | 938b8fa | 2012-05-18 13:46:27 -0400 | [diff] [blame] | 5555 | ec->shell_interface.move = surface_move; |
Kristian Høgsberg | c1693f2 | 2012-05-22 16:56:23 -0400 | [diff] [blame] | 5556 | ec->shell_interface.resize = surface_resize; |
Giulio Camuffo | 62942ad | 2013-09-11 18:20:47 +0200 | [diff] [blame] | 5557 | ec->shell_interface.set_title = set_title; |
Kristian Høgsberg | 4cca349 | 2011-01-18 07:53:49 -0500 | [diff] [blame] | 5558 | |
Kristian Høgsberg | 3be2ce9 | 2012-02-29 12:42:35 -0500 | [diff] [blame] | 5559 | weston_layer_init(&shell->fullscreen_layer, &ec->cursor_layer.link); |
| 5560 | weston_layer_init(&shell->panel_layer, &shell->fullscreen_layer.link); |
Jonas Ådahl | e3cddce | 2012-06-13 00:01:22 +0200 | [diff] [blame] | 5561 | weston_layer_init(&shell->background_layer, &shell->panel_layer.link); |
| 5562 | weston_layer_init(&shell->lock_layer, NULL); |
Philipp Brüschweiler | 711fda8 | 2012-08-09 18:50:43 +0200 | [diff] [blame] | 5563 | weston_layer_init(&shell->input_panel_layer, NULL); |
Jonas Ådahl | e3cddce | 2012-06-13 00:01:22 +0200 | [diff] [blame] | 5564 | |
| 5565 | wl_array_init(&shell->workspaces.array); |
Jonas Ådahl | e9d2250 | 2012-08-29 22:13:01 +0200 | [diff] [blame] | 5566 | wl_list_init(&shell->workspaces.client_list); |
Kristian Høgsberg | 3be2ce9 | 2012-02-29 12:42:35 -0500 | [diff] [blame] | 5567 | |
Kristian Høgsberg | 677a5f5 | 2013-12-04 11:00:19 -0800 | [diff] [blame] | 5568 | if (input_panel_setup(shell) < 0) |
| 5569 | return -1; |
| 5570 | |
Kristian Høgsberg | 14e438c | 2013-05-26 21:48:14 -0400 | [diff] [blame] | 5571 | shell_configuration(shell); |
Pekka Paalanen | e955f1e | 2011-12-07 11:49:52 +0200 | [diff] [blame] | 5572 | |
Daniel Stone | df8133b | 2013-11-19 11:37:14 +0100 | [diff] [blame] | 5573 | shell->exposay.state_cur = EXPOSAY_LAYOUT_INACTIVE; |
| 5574 | shell->exposay.state_target = EXPOSAY_TARGET_CANCEL; |
| 5575 | |
Jonas Ådahl | e3cddce | 2012-06-13 00:01:22 +0200 | [diff] [blame] | 5576 | for (i = 0; i < shell->workspaces.num; i++) { |
| 5577 | pws = wl_array_add(&shell->workspaces.array, sizeof *pws); |
| 5578 | if (pws == NULL) |
| 5579 | return -1; |
| 5580 | |
| 5581 | *pws = workspace_create(); |
| 5582 | if (*pws == NULL) |
| 5583 | return -1; |
| 5584 | } |
| 5585 | activate_workspace(shell, 0); |
| 5586 | |
Jonas Ådahl | 8de6a1d | 2012-08-29 22:13:00 +0200 | [diff] [blame] | 5587 | wl_list_init(&shell->workspaces.anim_sticky_list); |
Jonas Ådahl | 62fcd04 | 2012-06-13 00:01:23 +0200 | [diff] [blame] | 5588 | wl_list_init(&shell->workspaces.animation.link); |
| 5589 | shell->workspaces.animation.frame = animate_workspace_change_frame; |
| 5590 | |
Kristian Høgsberg | 919cddb | 2013-07-08 19:03:57 -0400 | [diff] [blame] | 5591 | if (wl_global_create(ec->wl_display, &wl_shell_interface, 1, |
Kristian Høgsberg | 97d44aa | 2011-08-26 17:21:20 -0400 | [diff] [blame] | 5592 | shell, bind_shell) == NULL) |
Kristian Høgsberg | 4cca349 | 2011-01-18 07:53:49 -0500 | [diff] [blame] | 5593 | return -1; |
| 5594 | |
Rafael Antognolli | e2a3455 | 2013-12-03 15:35:45 -0200 | [diff] [blame] | 5595 | if (wl_global_create(ec->wl_display, &xdg_shell_interface, 1, |
| 5596 | shell, bind_xdg_shell) == NULL) |
| 5597 | return -1; |
| 5598 | |
Kristian Høgsberg | 919cddb | 2013-07-08 19:03:57 -0400 | [diff] [blame] | 5599 | if (wl_global_create(ec->wl_display, |
| 5600 | &desktop_shell_interface, 2, |
| 5601 | shell, bind_desktop_shell) == NULL) |
Kristian Høgsberg | 7584062 | 2011-09-06 13:48:16 -0400 | [diff] [blame] | 5602 | return -1; |
| 5603 | |
Kristian Høgsberg | 919cddb | 2013-07-08 19:03:57 -0400 | [diff] [blame] | 5604 | if (wl_global_create(ec->wl_display, &screensaver_interface, 1, |
| 5605 | shell, bind_screensaver) == NULL) |
Pekka Paalanen | 6e16811 | 2011-11-24 11:34:05 +0200 | [diff] [blame] | 5606 | return -1; |
| 5607 | |
Kristian Høgsberg | 919cddb | 2013-07-08 19:03:57 -0400 | [diff] [blame] | 5608 | if (wl_global_create(ec->wl_display, &workspace_manager_interface, 1, |
| 5609 | shell, bind_workspace_manager) == NULL) |
Jonas Ådahl | e9d2250 | 2012-08-29 22:13:01 +0200 | [diff] [blame] | 5610 | return -1; |
| 5611 | |
Kristian Høgsberg | f03a616 | 2012-01-17 11:07:42 -0500 | [diff] [blame] | 5612 | shell->child.deathstamp = weston_compositor_get_time(); |
Tiago Vignatti | b7dbbd6 | 2012-09-25 17:57:01 +0300 | [diff] [blame] | 5613 | |
Xiong Zhang | 6b48142 | 2013-10-23 13:58:32 +0800 | [diff] [blame] | 5614 | setup_output_destroy_handler(ec, shell); |
| 5615 | |
Tiago Vignatti | b7dbbd6 | 2012-09-25 17:57:01 +0300 | [diff] [blame] | 5616 | loop = wl_display_get_event_loop(ec->wl_display); |
| 5617 | wl_event_loop_add_idle(loop, launch_desktop_shell_process, shell); |
Pekka Paalanen | 6cd281a | 2011-11-03 14:11:32 +0200 | [diff] [blame] | 5618 | |
Ander Conselvan de Oliveira | 859e885 | 2013-02-21 18:35:21 +0200 | [diff] [blame] | 5619 | shell->screensaver.timer = |
| 5620 | wl_event_loop_add_timer(loop, screensaver_timeout, shell); |
| 5621 | |
Kristian Høgsberg | f4d2f23 | 2012-08-10 10:05:39 -0400 | [diff] [blame] | 5622 | wl_list_for_each(seat, &ec->seat_list, link) |
| 5623 | create_pointer_focus_listener(seat); |
Kristian Høgsberg | d56bd90 | 2012-06-05 09:58:51 -0400 | [diff] [blame] | 5624 | |
Tiago Vignatti | 0b52d48 | 2012-04-20 18:54:25 +0300 | [diff] [blame] | 5625 | shell_add_bindings(ec, shell); |
Kristian Høgsberg | 0793756 | 2011-04-12 17:25:42 -0400 | [diff] [blame] | 5626 | |
Pekka Paalanen | 79346ab | 2013-05-22 18:03:09 +0300 | [diff] [blame] | 5627 | shell_fade_init(shell); |
Ander Conselvan de Oliveira | 19d10ef | 2013-02-21 18:35:20 +0200 | [diff] [blame] | 5628 | |
Kristian Høgsberg | 4cca349 | 2011-01-18 07:53:49 -0500 | [diff] [blame] | 5629 | return 0; |
| 5630 | } |