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