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 | |
Jonas Ådahl | 0476974 | 2012-06-13 00:01:24 +0200 | [diff] [blame] | 46 | struct focus_state { |
| 47 | struct weston_seat *seat; |
Kristian Høgsberg | 2f5faff | 2012-07-31 16:36:34 -0400 | [diff] [blame] | 48 | struct workspace *ws; |
Jonas Ådahl | 0476974 | 2012-06-13 00:01:24 +0200 | [diff] [blame] | 49 | struct weston_surface *keyboard_focus; |
| 50 | struct wl_list link; |
| 51 | struct wl_listener seat_destroy_listener; |
| 52 | struct wl_listener surface_destroy_listener; |
| 53 | }; |
| 54 | |
Xiong Zhang | 6b48142 | 2013-10-23 13:58:32 +0800 | [diff] [blame] | 55 | struct shell_output { |
| 56 | struct desktop_shell *shell; |
| 57 | struct weston_output *output; |
| 58 | struct wl_listener destroy_listener; |
| 59 | struct wl_list link; |
| 60 | }; |
| 61 | |
Kristian Høgsberg | d2abb83 | 2011-11-23 10:52:40 -0500 | [diff] [blame] | 62 | enum shell_surface_type { |
Pekka Paalanen | 9826223 | 2011-12-01 10:42:22 +0200 | [diff] [blame] | 63 | SHELL_SURFACE_NONE, |
Kristian Høgsberg | d2abb83 | 2011-11-23 10:52:40 -0500 | [diff] [blame] | 64 | SHELL_SURFACE_TOPLEVEL, |
Tiago Vignatti | fb2adba | 2013-06-12 15:43:21 -0300 | [diff] [blame] | 65 | SHELL_SURFACE_POPUP, |
| 66 | SHELL_SURFACE_XWAYLAND |
Pekka Paalanen | 57da4a8 | 2011-11-23 16:42:16 +0200 | [diff] [blame] | 67 | }; |
| 68 | |
Scott Moreau | ff1db4a | 2012-04-17 19:06:18 -0600 | [diff] [blame] | 69 | struct ping_timer { |
| 70 | struct wl_event_source *source; |
Scott Moreau | ff1db4a | 2012-04-17 19:06:18 -0600 | [diff] [blame] | 71 | uint32_t serial; |
| 72 | }; |
| 73 | |
Philip Withnall | 648a4dd | 2013-11-25 18:01:44 +0000 | [diff] [blame] | 74 | /* |
| 75 | * Surface stacking and ordering. |
| 76 | * |
| 77 | * This is handled using several linked lists of surfaces, organised into |
| 78 | * ‘layers’. The layers are ordered, and each of the surfaces in one layer are |
| 79 | * above all of the surfaces in the layer below. The set of layers is static and |
| 80 | * in the following order (top-most first): |
| 81 | * • Lock layer (only ever displayed on its own) |
| 82 | * • Cursor layer |
| 83 | * • Fullscreen layer |
| 84 | * • Panel layer |
| 85 | * • Input panel layer |
| 86 | * • Workspace layers |
| 87 | * • Background layer |
| 88 | * |
| 89 | * The list of layers may be manipulated to remove whole layers of surfaces from |
| 90 | * display. For example, when locking the screen, all layers except the lock |
| 91 | * layer are removed. |
| 92 | * |
| 93 | * A surface’s layer is modified on configuring the surface, in |
| 94 | * set_surface_type() (which is only called when the surface’s type change is |
| 95 | * _committed_). If a surface’s type changes (e.g. when making a window |
| 96 | * fullscreen) its layer changes too. |
| 97 | * |
| 98 | * In order to allow popup and transient surfaces to be correctly stacked above |
| 99 | * their parent surfaces, each surface tracks both its parent surface, and a |
| 100 | * linked list of its children. When a surface’s layer is updated, so are the |
| 101 | * layers of its children. Note that child surfaces are *not* the same as |
| 102 | * subsurfaces — child/parent surfaces are purely for maintaining stacking |
| 103 | * order. |
| 104 | * |
| 105 | * The children_link list of siblings of a surface (i.e. those surfaces which |
| 106 | * have the same parent) only contains weston_surfaces which have a |
| 107 | * shell_surface. Stacking is not implemented for non-shell_surface |
| 108 | * weston_surfaces. This means that the following implication does *not* hold: |
| 109 | * (shsurf->parent != NULL) ⇒ !wl_list_is_empty(shsurf->children_link) |
| 110 | */ |
| 111 | |
Pekka Paalanen | 56cdea9 | 2011-11-23 16:14:12 +0200 | [diff] [blame] | 112 | struct shell_surface { |
Jason Ekstrand | 651f00e | 2013-06-14 10:07:54 -0500 | [diff] [blame] | 113 | struct wl_resource *resource; |
| 114 | struct wl_signal destroy_signal; |
Pekka Paalanen | 9d1613e | 2011-11-25 12:09:16 +0200 | [diff] [blame] | 115 | |
Kristian Høgsberg | 8334bc1 | 2012-01-03 10:29:47 -0500 | [diff] [blame] | 116 | struct weston_surface *surface; |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 117 | struct weston_view *view; |
Jason Ekstrand | 918f2dd | 2013-12-02 21:01:53 -0600 | [diff] [blame] | 118 | int32_t last_width, last_height; |
Pekka Paalanen | 9d1613e | 2011-11-25 12:09:16 +0200 | [diff] [blame] | 119 | struct wl_listener surface_destroy_listener; |
Kristian Høgsberg | 8150b19 | 2012-06-27 10:22:58 -0400 | [diff] [blame] | 120 | struct weston_surface *parent; |
Philip Withnall | 648a4dd | 2013-11-25 18:01:44 +0000 | [diff] [blame] | 121 | struct wl_list children_list; /* child surfaces of this one */ |
| 122 | struct wl_list children_link; /* sibling surfaces of this one */ |
Tiago Vignatti | be14326 | 2012-04-16 17:31:41 +0300 | [diff] [blame] | 123 | struct desktop_shell *shell; |
Pekka Paalanen | 57da4a8 | 2011-11-23 16:42:16 +0200 | [diff] [blame] | 124 | |
Kristian Høgsberg | c8f8dd8 | 2013-12-05 23:20:33 -0800 | [diff] [blame] | 125 | enum shell_surface_type type; |
Kristian Høgsberg | e7afd91 | 2012-05-02 09:47:44 -0400 | [diff] [blame] | 126 | char *title, *class; |
Kristian Høgsberg | d2abb83 | 2011-11-23 10:52:40 -0500 | [diff] [blame] | 127 | int32_t saved_x, saved_y; |
Rafael Antognolli | 3c4e3f7 | 2013-12-03 15:35:46 -0200 | [diff] [blame] | 128 | int32_t saved_width, saved_height; |
Alex Wu | 4539b08 | 2012-03-01 12:57:46 +0800 | [diff] [blame] | 129 | bool saved_position_valid; |
Rafael Antognolli | 3c4e3f7 | 2013-12-03 15:35:46 -0200 | [diff] [blame] | 130 | bool saved_size_valid; |
Alex Wu | 7bcb8bd | 2012-04-27 09:07:24 +0800 | [diff] [blame] | 131 | bool saved_rotation_valid; |
Kristian Høgsberg | c85f1d4 | 2013-10-24 16:52:00 -0700 | [diff] [blame] | 132 | int unresponsive, grabbed; |
Benjamin Franzke | d0f79ab | 2011-11-22 12:43:52 +0100 | [diff] [blame] | 133 | |
Kristian Høgsberg | b3cca0a | 2012-01-04 22:19:14 -0500 | [diff] [blame] | 134 | struct { |
Pekka Paalanen | 460099f | 2012-01-20 16:48:25 +0200 | [diff] [blame] | 135 | struct weston_transform transform; |
Kristian Høgsberg | 765e27b | 2012-01-27 13:36:13 -0500 | [diff] [blame] | 136 | struct weston_matrix rotation; |
Pekka Paalanen | 460099f | 2012-01-20 16:48:25 +0200 | [diff] [blame] | 137 | } rotation; |
| 138 | |
| 139 | struct { |
Giulio Camuffo | 5085a75 | 2013-03-25 21:42:45 +0100 | [diff] [blame] | 140 | struct wl_list grab_link; |
Kristian Høgsberg | b3cca0a | 2012-01-04 22:19:14 -0500 | [diff] [blame] | 141 | int32_t x, y; |
Giulio Camuffo | 5085a75 | 2013-03-25 21:42:45 +0100 | [diff] [blame] | 142 | struct shell_seat *shseat; |
Kristian Høgsberg | 3730f36 | 2012-04-13 12:40:07 -0400 | [diff] [blame] | 143 | uint32_t serial; |
Kristian Høgsberg | b3cca0a | 2012-01-04 22:19:14 -0500 | [diff] [blame] | 144 | } popup; |
| 145 | |
Alex Wu | 4539b08 | 2012-03-01 12:57:46 +0800 | [diff] [blame] | 146 | struct { |
Tiago Vignatti | 52e598c | 2012-05-07 15:23:08 +0300 | [diff] [blame] | 147 | int32_t x, y; |
Tiago Vignatti | 491bac1 | 2012-05-18 16:37:43 -0400 | [diff] [blame] | 148 | uint32_t flags; |
Tiago Vignatti | 52e598c | 2012-05-07 15:23:08 +0300 | [diff] [blame] | 149 | } transient; |
| 150 | |
| 151 | struct { |
Alex Wu | 4539b08 | 2012-03-01 12:57:46 +0800 | [diff] [blame] | 152 | enum wl_shell_surface_fullscreen_method type; |
| 153 | struct weston_transform transform; /* matrix from x, y */ |
| 154 | uint32_t framerate; |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 155 | struct weston_view *black_view; |
Alex Wu | 4539b08 | 2012-03-01 12:57:46 +0800 | [diff] [blame] | 156 | } fullscreen; |
| 157 | |
Scott Moreau | ff1db4a | 2012-04-17 19:06:18 -0600 | [diff] [blame] | 158 | struct ping_timer *ping_timer; |
| 159 | |
Jonas Ådahl | 62fcd04 | 2012-06-13 00:01:23 +0200 | [diff] [blame] | 160 | struct weston_transform workspace_transform; |
| 161 | |
Kristian Høgsberg | 1cbf326 | 2012-02-17 23:49:07 -0500 | [diff] [blame] | 162 | struct weston_output *fullscreen_output; |
Kristian Høgsberg | 8334bc1 | 2012-01-03 10:29:47 -0500 | [diff] [blame] | 163 | struct weston_output *output; |
Rafael Antognolli | 65f98d8 | 2013-12-03 15:35:47 -0200 | [diff] [blame] | 164 | struct weston_output *recommended_output; |
Benjamin Franzke | d0f79ab | 2011-11-22 12:43:52 +0100 | [diff] [blame] | 165 | struct wl_list link; |
Kristian Høgsberg | a61ca06 | 2012-05-22 16:05:52 -0400 | [diff] [blame] | 166 | |
| 167 | const struct weston_shell_client *client; |
Rafael Antognolli | 03b1659 | 2013-12-03 15:35:42 -0200 | [diff] [blame] | 168 | |
| 169 | struct { |
| 170 | bool maximized; |
| 171 | bool fullscreen; |
Rafael Antognolli | ed207b4 | 2013-12-03 15:35:43 -0200 | [diff] [blame] | 172 | bool relative; |
Rafael Antognolli | 03b1659 | 2013-12-03 15:35:42 -0200 | [diff] [blame] | 173 | } state, next_state; /* surface states */ |
| 174 | bool state_changed; |
Pekka Paalanen | 56cdea9 | 2011-11-23 16:14:12 +0200 | [diff] [blame] | 175 | }; |
| 176 | |
Ander Conselvan de Oliveira | fe0444a | 2012-04-04 17:48:05 +0300 | [diff] [blame] | 177 | struct shell_grab { |
Kristian Høgsberg | 02bbabb | 2013-05-06 22:15:05 -0400 | [diff] [blame] | 178 | struct weston_pointer_grab grab; |
Ander Conselvan de Oliveira | fe0444a | 2012-04-04 17:48:05 +0300 | [diff] [blame] | 179 | struct shell_surface *shsurf; |
| 180 | struct wl_listener shsurf_destroy_listener; |
| 181 | }; |
| 182 | |
Rusty Lynch | 1084da5 | 2013-08-15 09:10:08 -0700 | [diff] [blame] | 183 | struct shell_touch_grab { |
| 184 | struct weston_touch_grab grab; |
| 185 | struct shell_surface *shsurf; |
| 186 | struct wl_listener shsurf_destroy_listener; |
| 187 | struct weston_touch *touch; |
| 188 | }; |
| 189 | |
Ander Conselvan de Oliveira | fe0444a | 2012-04-04 17:48:05 +0300 | [diff] [blame] | 190 | struct weston_move_grab { |
| 191 | struct shell_grab base; |
Daniel Stone | 103db7f | 2012-05-08 17:17:55 +0100 | [diff] [blame] | 192 | wl_fixed_t dx, dy; |
Kristian Høgsberg | 4cca349 | 2011-01-18 07:53:49 -0500 | [diff] [blame] | 193 | }; |
| 194 | |
Rusty Lynch | 1084da5 | 2013-08-15 09:10:08 -0700 | [diff] [blame] | 195 | struct weston_touch_move_grab { |
| 196 | struct shell_touch_grab base; |
| 197 | wl_fixed_t dx, dy; |
| 198 | }; |
| 199 | |
Pekka Paalanen | 460099f | 2012-01-20 16:48:25 +0200 | [diff] [blame] | 200 | struct rotate_grab { |
Ander Conselvan de Oliveira | fe0444a | 2012-04-04 17:48:05 +0300 | [diff] [blame] | 201 | struct shell_grab base; |
Kristian Høgsberg | 765e27b | 2012-01-27 13:36:13 -0500 | [diff] [blame] | 202 | struct weston_matrix rotation; |
Pekka Paalanen | 460099f | 2012-01-20 16:48:25 +0200 | [diff] [blame] | 203 | struct { |
John Kåre Alsaker | 490d02a | 2012-09-30 02:57:21 +0200 | [diff] [blame] | 204 | float x; |
| 205 | float y; |
Pekka Paalanen | 460099f | 2012-01-20 16:48:25 +0200 | [diff] [blame] | 206 | } center; |
| 207 | }; |
| 208 | |
Giulio Camuffo | 5085a75 | 2013-03-25 21:42:45 +0100 | [diff] [blame] | 209 | struct shell_seat { |
| 210 | struct weston_seat *seat; |
| 211 | struct wl_listener seat_destroy_listener; |
| 212 | |
| 213 | struct { |
Kristian Høgsberg | 02bbabb | 2013-05-06 22:15:05 -0400 | [diff] [blame] | 214 | struct weston_pointer_grab grab; |
Giulio Camuffo | 5085a75 | 2013-03-25 21:42:45 +0100 | [diff] [blame] | 215 | struct wl_list surfaces_list; |
| 216 | struct wl_client *client; |
| 217 | int32_t initial_up; |
| 218 | } popup_grab; |
| 219 | }; |
| 220 | |
Alex Wu | bd3354b | 2012-04-17 17:20:49 +0800 | [diff] [blame] | 221 | static struct desktop_shell * |
| 222 | shell_surface_get_shell(struct shell_surface *shsurf); |
| 223 | |
Kristian Høgsberg | 0c36903 | 2013-02-14 21:31:44 -0500 | [diff] [blame] | 224 | static void |
Kristian Høgsberg | e314875 | 2013-05-06 23:19:49 -0400 | [diff] [blame] | 225 | surface_rotate(struct shell_surface *surface, struct weston_seat *seat); |
Kristian Høgsberg | 0c36903 | 2013-02-14 21:31:44 -0500 | [diff] [blame] | 226 | |
Pekka Paalanen | 79346ab | 2013-05-22 18:03:09 +0300 | [diff] [blame] | 227 | static void |
| 228 | shell_fade_startup(struct desktop_shell *shell); |
| 229 | |
Philip Withnall | becb77e | 2013-11-25 18:01:30 +0000 | [diff] [blame] | 230 | static struct shell_seat * |
| 231 | get_shell_seat(struct weston_seat *seat); |
| 232 | |
Philip Withnall | 648a4dd | 2013-11-25 18:01:44 +0000 | [diff] [blame] | 233 | static void |
| 234 | shell_surface_update_child_surface_layers(struct shell_surface *shsurf); |
| 235 | |
Alex Wu | bd3354b | 2012-04-17 17:20:49 +0800 | [diff] [blame] | 236 | static bool |
Rafael Antognolli | e2a3455 | 2013-12-03 15:35:45 -0200 | [diff] [blame] | 237 | shell_surface_is_wl_shell_surface(struct shell_surface *shsurf); |
| 238 | |
| 239 | static bool |
| 240 | shell_surface_is_xdg_surface(struct shell_surface *shsurf); |
| 241 | |
| 242 | static bool |
| 243 | shell_surface_is_xdg_popup(struct shell_surface *shsurf); |
| 244 | |
| 245 | static void |
| 246 | shell_surface_set_parent(struct shell_surface *shsurf, |
| 247 | struct weston_surface *parent); |
| 248 | |
| 249 | static bool |
Alex Wu | bd3354b | 2012-04-17 17:20:49 +0800 | [diff] [blame] | 250 | shell_surface_is_top_fullscreen(struct shell_surface *shsurf) |
| 251 | { |
| 252 | struct desktop_shell *shell; |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 253 | struct weston_view *top_fs_ev; |
Alex Wu | bd3354b | 2012-04-17 17:20:49 +0800 | [diff] [blame] | 254 | |
| 255 | shell = shell_surface_get_shell(shsurf); |
Quentin Glidic | c0d79ce | 2013-01-29 14:16:13 +0100 | [diff] [blame] | 256 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 257 | if (wl_list_empty(&shell->fullscreen_layer.view_list)) |
Alex Wu | bd3354b | 2012-04-17 17:20:49 +0800 | [diff] [blame] | 258 | return false; |
| 259 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 260 | top_fs_ev = container_of(shell->fullscreen_layer.view_list.next, |
| 261 | struct weston_view, |
Alex Wu | bd3354b | 2012-04-17 17:20:49 +0800 | [diff] [blame] | 262 | layer_link); |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 263 | return (shsurf == get_shell_surface(top_fs_ev->surface)); |
Alex Wu | bd3354b | 2012-04-17 17:20:49 +0800 | [diff] [blame] | 264 | } |
| 265 | |
Kristian Høgsberg | 6af8eb9 | 2012-01-25 16:57:11 -0500 | [diff] [blame] | 266 | static void |
Kristian Høgsberg | 27e3052 | 2012-04-11 23:18:23 -0400 | [diff] [blame] | 267 | destroy_shell_grab_shsurf(struct wl_listener *listener, void *data) |
Ander Conselvan de Oliveira | fe0444a | 2012-04-04 17:48:05 +0300 | [diff] [blame] | 268 | { |
| 269 | struct shell_grab *grab; |
| 270 | |
| 271 | grab = container_of(listener, struct shell_grab, |
| 272 | shsurf_destroy_listener); |
| 273 | |
| 274 | grab->shsurf = NULL; |
| 275 | } |
| 276 | |
Kristian Høgsberg | 1ef2313 | 2013-12-04 00:20:01 -0800 | [diff] [blame] | 277 | struct weston_view * |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 278 | get_default_view(struct weston_surface *surface) |
| 279 | { |
| 280 | struct shell_surface *shsurf; |
| 281 | struct weston_view *view; |
| 282 | |
| 283 | if (!surface || wl_list_empty(&surface->views)) |
| 284 | return NULL; |
| 285 | |
| 286 | shsurf = get_shell_surface(surface); |
| 287 | if (shsurf) |
| 288 | return shsurf->view; |
| 289 | |
| 290 | wl_list_for_each(view, &surface->views, surface_link) |
| 291 | if (weston_view_is_mapped(view)) |
| 292 | return view; |
| 293 | |
| 294 | return container_of(surface->views.next, struct weston_view, surface_link); |
| 295 | } |
| 296 | |
Ander Conselvan de Oliveira | fe0444a | 2012-04-04 17:48:05 +0300 | [diff] [blame] | 297 | static void |
Kristian Høgsberg | 02bbabb | 2013-05-06 22:15:05 -0400 | [diff] [blame] | 298 | popup_grab_end(struct weston_pointer *pointer); |
Kristian Høgsberg | 57e0907 | 2012-10-30 14:07:27 -0400 | [diff] [blame] | 299 | |
| 300 | static void |
Ander Conselvan de Oliveira | b9d2a0f | 2012-06-28 18:08:05 +0300 | [diff] [blame] | 301 | shell_grab_start(struct shell_grab *grab, |
Kristian Høgsberg | 02bbabb | 2013-05-06 22:15:05 -0400 | [diff] [blame] | 302 | const struct weston_pointer_grab_interface *interface, |
Ander Conselvan de Oliveira | b9d2a0f | 2012-06-28 18:08:05 +0300 | [diff] [blame] | 303 | struct shell_surface *shsurf, |
Kristian Høgsberg | 02bbabb | 2013-05-06 22:15:05 -0400 | [diff] [blame] | 304 | struct weston_pointer *pointer, |
Ander Conselvan de Oliveira | b9d2a0f | 2012-06-28 18:08:05 +0300 | [diff] [blame] | 305 | enum desktop_shell_cursor cursor) |
Ander Conselvan de Oliveira | fe0444a | 2012-04-04 17:48:05 +0300 | [diff] [blame] | 306 | { |
Ander Conselvan de Oliveira | b9d2a0f | 2012-06-28 18:08:05 +0300 | [diff] [blame] | 307 | struct desktop_shell *shell = shsurf->shell; |
| 308 | |
Kristian Høgsberg | 57e0907 | 2012-10-30 14:07:27 -0400 | [diff] [blame] | 309 | popup_grab_end(pointer); |
| 310 | |
Ander Conselvan de Oliveira | fe0444a | 2012-04-04 17:48:05 +0300 | [diff] [blame] | 311 | grab->grab.interface = interface; |
| 312 | grab->shsurf = shsurf; |
Kristian Høgsberg | 27e3052 | 2012-04-11 23:18:23 -0400 | [diff] [blame] | 313 | grab->shsurf_destroy_listener.notify = destroy_shell_grab_shsurf; |
Jason Ekstrand | 651f00e | 2013-06-14 10:07:54 -0500 | [diff] [blame] | 314 | wl_signal_add(&shsurf->destroy_signal, |
Kristian Høgsberg | 27e3052 | 2012-04-11 23:18:23 -0400 | [diff] [blame] | 315 | &grab->shsurf_destroy_listener); |
Ander Conselvan de Oliveira | fe0444a | 2012-04-04 17:48:05 +0300 | [diff] [blame] | 316 | |
Kristian Høgsberg | c85f1d4 | 2013-10-24 16:52:00 -0700 | [diff] [blame] | 317 | shsurf->grabbed = 1; |
Kristian Høgsberg | 02bbabb | 2013-05-06 22:15:05 -0400 | [diff] [blame] | 318 | weston_pointer_start_grab(pointer, &grab->grab); |
Kristian Høgsberg | c9974a0 | 2013-07-03 19:24:57 -0400 | [diff] [blame] | 319 | if (shell->child.desktop_shell) { |
| 320 | desktop_shell_send_grab_cursor(shell->child.desktop_shell, |
| 321 | cursor); |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 322 | weston_pointer_set_focus(pointer, |
| 323 | get_default_view(shell->grab_surface), |
Kristian Høgsberg | c9974a0 | 2013-07-03 19:24:57 -0400 | [diff] [blame] | 324 | wl_fixed_from_int(0), |
| 325 | wl_fixed_from_int(0)); |
| 326 | } |
Ander Conselvan de Oliveira | fe0444a | 2012-04-04 17:48:05 +0300 | [diff] [blame] | 327 | } |
| 328 | |
| 329 | static void |
Ander Conselvan de Oliveira | b9d2a0f | 2012-06-28 18:08:05 +0300 | [diff] [blame] | 330 | shell_grab_end(struct shell_grab *grab) |
Ander Conselvan de Oliveira | fe0444a | 2012-04-04 17:48:05 +0300 | [diff] [blame] | 331 | { |
Kristian Høgsberg | c85f1d4 | 2013-10-24 16:52:00 -0700 | [diff] [blame] | 332 | if (grab->shsurf) { |
Kristian Høgsberg | 47b5dca | 2012-06-07 18:08:04 -0400 | [diff] [blame] | 333 | wl_list_remove(&grab->shsurf_destroy_listener.link); |
Kristian Høgsberg | c85f1d4 | 2013-10-24 16:52:00 -0700 | [diff] [blame] | 334 | grab->shsurf->grabbed = 0; |
| 335 | } |
Ander Conselvan de Oliveira | b9d2a0f | 2012-06-28 18:08:05 +0300 | [diff] [blame] | 336 | |
Kristian Høgsberg | 9e5d7d1 | 2013-07-22 16:31:53 -0700 | [diff] [blame] | 337 | weston_pointer_end_grab(grab->grab.pointer); |
Ander Conselvan de Oliveira | fe0444a | 2012-04-04 17:48:05 +0300 | [diff] [blame] | 338 | } |
| 339 | |
| 340 | static void |
Rusty Lynch | 1084da5 | 2013-08-15 09:10:08 -0700 | [diff] [blame] | 341 | shell_touch_grab_start(struct shell_touch_grab *grab, |
| 342 | const struct weston_touch_grab_interface *interface, |
| 343 | struct shell_surface *shsurf, |
| 344 | struct weston_touch *touch) |
| 345 | { |
| 346 | struct desktop_shell *shell = shsurf->shell; |
| 347 | |
| 348 | grab->grab.interface = interface; |
| 349 | grab->shsurf = shsurf; |
| 350 | grab->shsurf_destroy_listener.notify = destroy_shell_grab_shsurf; |
| 351 | wl_signal_add(&shsurf->destroy_signal, |
| 352 | &grab->shsurf_destroy_listener); |
| 353 | |
| 354 | grab->touch = touch; |
Kristian Høgsberg | c85f1d4 | 2013-10-24 16:52:00 -0700 | [diff] [blame] | 355 | shsurf->grabbed = 1; |
Rusty Lynch | 1084da5 | 2013-08-15 09:10:08 -0700 | [diff] [blame] | 356 | |
| 357 | weston_touch_start_grab(touch, &grab->grab); |
| 358 | if (shell->child.desktop_shell) |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 359 | weston_touch_set_focus(touch->seat, |
| 360 | get_default_view(shell->grab_surface)); |
Rusty Lynch | 1084da5 | 2013-08-15 09:10:08 -0700 | [diff] [blame] | 361 | } |
| 362 | |
| 363 | static void |
| 364 | shell_touch_grab_end(struct shell_touch_grab *grab) |
| 365 | { |
Kristian Høgsberg | c85f1d4 | 2013-10-24 16:52:00 -0700 | [diff] [blame] | 366 | if (grab->shsurf) { |
Rusty Lynch | 1084da5 | 2013-08-15 09:10:08 -0700 | [diff] [blame] | 367 | wl_list_remove(&grab->shsurf_destroy_listener.link); |
Kristian Høgsberg | c85f1d4 | 2013-10-24 16:52:00 -0700 | [diff] [blame] | 368 | grab->shsurf->grabbed = 0; |
| 369 | } |
Rusty Lynch | 1084da5 | 2013-08-15 09:10:08 -0700 | [diff] [blame] | 370 | |
| 371 | weston_touch_end_grab(grab->touch); |
| 372 | } |
| 373 | |
| 374 | static void |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 375 | center_on_output(struct weston_view *view, |
Alex Wu | 4539b08 | 2012-03-01 12:57:46 +0800 | [diff] [blame] | 376 | struct weston_output *output); |
| 377 | |
Daniel Stone | 496ca17 | 2012-05-30 16:31:42 +0100 | [diff] [blame] | 378 | static enum weston_keyboard_modifier |
Tiago Vignatti | 0b52d48 | 2012-04-20 18:54:25 +0300 | [diff] [blame] | 379 | get_modifier(char *modifier) |
| 380 | { |
| 381 | if (!modifier) |
| 382 | return MODIFIER_SUPER; |
| 383 | |
| 384 | if (!strcmp("ctrl", modifier)) |
| 385 | return MODIFIER_CTRL; |
| 386 | else if (!strcmp("alt", modifier)) |
| 387 | return MODIFIER_ALT; |
| 388 | else if (!strcmp("super", modifier)) |
| 389 | return MODIFIER_SUPER; |
| 390 | else |
| 391 | return MODIFIER_SUPER; |
| 392 | } |
| 393 | |
Juan Zhao | e10d279 | 2012-04-25 19:09:52 +0800 | [diff] [blame] | 394 | static enum animation_type |
| 395 | get_animation_type(char *animation) |
| 396 | { |
Juan Zhao | e10d279 | 2012-04-25 19:09:52 +0800 | [diff] [blame] | 397 | if (!strcmp("zoom", animation)) |
| 398 | return ANIMATION_ZOOM; |
| 399 | else if (!strcmp("fade", animation)) |
| 400 | return ANIMATION_FADE; |
Louis-Francis Ratté-Boulianne | b482dbd | 2013-11-19 11:37:11 +0100 | [diff] [blame] | 401 | else if (!strcmp("dim-layer", animation)) |
| 402 | return ANIMATION_DIM_LAYER; |
Juan Zhao | e10d279 | 2012-04-25 19:09:52 +0800 | [diff] [blame] | 403 | else |
| 404 | return ANIMATION_NONE; |
| 405 | } |
| 406 | |
Alex Wu | 4539b08 | 2012-03-01 12:57:46 +0800 | [diff] [blame] | 407 | static void |
Kristian Høgsberg | 14e438c | 2013-05-26 21:48:14 -0400 | [diff] [blame] | 408 | shell_configuration(struct desktop_shell *shell) |
Pekka Paalanen | e955f1e | 2011-12-07 11:49:52 +0200 | [diff] [blame] | 409 | { |
Kristian Høgsberg | 673a889 | 2013-05-23 21:40:56 -0400 | [diff] [blame] | 410 | struct weston_config_section *section; |
| 411 | int duration; |
| 412 | char *s; |
Pekka Paalanen | e955f1e | 2011-12-07 11:49:52 +0200 | [diff] [blame] | 413 | |
Kristian Høgsberg | 673a889 | 2013-05-23 21:40:56 -0400 | [diff] [blame] | 414 | section = weston_config_get_section(shell->compositor->config, |
| 415 | "screensaver", NULL, NULL); |
| 416 | weston_config_section_get_string(section, |
| 417 | "path", &shell->screensaver.path, NULL); |
| 418 | weston_config_section_get_int(section, "duration", &duration, 60); |
Ander Conselvan de Oliveira | 859e885 | 2013-02-21 18:35:21 +0200 | [diff] [blame] | 419 | shell->screensaver.duration = duration * 1000; |
Kristian Høgsberg | 673a889 | 2013-05-23 21:40:56 -0400 | [diff] [blame] | 420 | |
| 421 | section = weston_config_get_section(shell->compositor->config, |
| 422 | "shell", NULL, NULL); |
| 423 | weston_config_section_get_string(section, |
Emilio Pozuelo Monfort | 8a81b83 | 2013-12-02 12:53:32 +0100 | [diff] [blame] | 424 | "client", &s, LIBEXECDIR "/" WESTON_SHELL_CLIENT); |
Emilio Pozuelo Monfort | 46ce798 | 2013-11-20 13:22:29 +0100 | [diff] [blame] | 425 | shell->client = s; |
| 426 | weston_config_section_get_string(section, |
Kristian Høgsberg | 673a889 | 2013-05-23 21:40:56 -0400 | [diff] [blame] | 427 | "binding-modifier", &s, "super"); |
| 428 | shell->binding_modifier = get_modifier(s); |
Quentin Glidic | 8418c29 | 2013-06-18 09:11:03 +0200 | [diff] [blame] | 429 | free(s); |
Kristian Høgsberg | 673a889 | 2013-05-23 21:40:56 -0400 | [diff] [blame] | 430 | weston_config_section_get_string(section, "animation", &s, "none"); |
| 431 | shell->win_animation_type = get_animation_type(s); |
Quentin Glidic | 8418c29 | 2013-06-18 09:11:03 +0200 | [diff] [blame] | 432 | free(s); |
Kristian Høgsberg | 724c8d9 | 2013-10-16 11:38:24 -0700 | [diff] [blame] | 433 | weston_config_section_get_string(section, |
| 434 | "startup-animation", &s, "fade"); |
| 435 | shell->startup_animation_type = get_animation_type(s); |
| 436 | free(s); |
Kristian Høgsberg | 912e0a1 | 2013-10-30 08:59:55 -0700 | [diff] [blame] | 437 | if (shell->startup_animation_type == ANIMATION_ZOOM) |
| 438 | shell->startup_animation_type = ANIMATION_NONE; |
Louis-Francis Ratté-Boulianne | b482dbd | 2013-11-19 11:37:11 +0100 | [diff] [blame] | 439 | weston_config_section_get_string(section, "focus-animation", &s, "none"); |
| 440 | shell->focus_animation_type = get_animation_type(s); |
| 441 | free(s); |
Kristian Høgsberg | 673a889 | 2013-05-23 21:40:56 -0400 | [diff] [blame] | 442 | weston_config_section_get_uint(section, "num-workspaces", |
| 443 | &shell->workspaces.num, |
| 444 | DEFAULT_NUM_WORKSPACES); |
Jonas Ådahl | e3cddce | 2012-06-13 00:01:22 +0200 | [diff] [blame] | 445 | } |
| 446 | |
Kristian Høgsberg | 1ef2313 | 2013-12-04 00:20:01 -0800 | [diff] [blame] | 447 | struct weston_output * |
Louis-Francis Ratté-Boulianne | b482dbd | 2013-11-19 11:37:11 +0100 | [diff] [blame] | 448 | get_default_output(struct weston_compositor *compositor) |
| 449 | { |
| 450 | return container_of(compositor->output_list.next, |
| 451 | struct weston_output, link); |
| 452 | } |
| 453 | |
| 454 | |
| 455 | /* no-op func for checking focus surface */ |
| 456 | static void |
Jason Ekstrand | 918f2dd | 2013-12-02 21:01:53 -0600 | [diff] [blame] | 457 | 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] | 458 | { |
| 459 | } |
| 460 | |
| 461 | static struct focus_surface * |
| 462 | get_focus_surface(struct weston_surface *surface) |
| 463 | { |
| 464 | if (surface->configure == focus_surface_configure) |
| 465 | return surface->configure_private; |
| 466 | else |
| 467 | return NULL; |
| 468 | } |
| 469 | |
| 470 | static bool |
| 471 | is_focus_surface (struct weston_surface *es) |
| 472 | { |
| 473 | return (es->configure == focus_surface_configure); |
| 474 | } |
| 475 | |
| 476 | static bool |
| 477 | is_focus_view (struct weston_view *view) |
| 478 | { |
| 479 | return is_focus_surface (view->surface); |
| 480 | } |
| 481 | |
| 482 | static struct focus_surface * |
| 483 | create_focus_surface(struct weston_compositor *ec, |
| 484 | struct weston_output *output) |
| 485 | { |
| 486 | struct focus_surface *fsurf = NULL; |
| 487 | struct weston_surface *surface = NULL; |
| 488 | |
| 489 | fsurf = malloc(sizeof *fsurf); |
| 490 | if (!fsurf) |
| 491 | return NULL; |
| 492 | |
| 493 | fsurf->surface = weston_surface_create(ec); |
| 494 | surface = fsurf->surface; |
| 495 | if (surface == NULL) { |
| 496 | free(fsurf); |
| 497 | return NULL; |
| 498 | } |
| 499 | |
| 500 | surface->configure = focus_surface_configure; |
| 501 | surface->output = output; |
| 502 | surface->configure_private = fsurf; |
| 503 | |
| 504 | fsurf->view = weston_view_create (surface); |
Emilio Pozuelo Monfort | da64426 | 2013-11-19 11:37:19 +0100 | [diff] [blame] | 505 | fsurf->view->output = output; |
Louis-Francis Ratté-Boulianne | b482dbd | 2013-11-19 11:37:11 +0100 | [diff] [blame] | 506 | |
Jason Ekstrand | 918f2dd | 2013-12-02 21:01:53 -0600 | [diff] [blame] | 507 | surface->width = output->width; |
| 508 | surface->height = output->height; |
| 509 | weston_view_set_position(fsurf->view, output->x, output->y); |
Louis-Francis Ratté-Boulianne | b482dbd | 2013-11-19 11:37:11 +0100 | [diff] [blame] | 510 | weston_surface_set_color(surface, 0.0, 0.0, 0.0, 1.0); |
| 511 | pixman_region32_fini(&surface->opaque); |
| 512 | pixman_region32_init_rect(&surface->opaque, output->x, output->y, |
| 513 | output->width, output->height); |
| 514 | pixman_region32_fini(&surface->input); |
| 515 | pixman_region32_init(&surface->input); |
| 516 | |
| 517 | wl_list_init(&fsurf->workspace_transform.link); |
| 518 | |
| 519 | return fsurf; |
| 520 | } |
| 521 | |
| 522 | static void |
| 523 | focus_surface_destroy(struct focus_surface *fsurf) |
| 524 | { |
| 525 | weston_surface_destroy(fsurf->surface); |
| 526 | free(fsurf); |
| 527 | } |
| 528 | |
| 529 | static void |
| 530 | focus_animation_done(struct weston_view_animation *animation, void *data) |
| 531 | { |
| 532 | struct workspace *ws = data; |
| 533 | |
| 534 | ws->focus_animation = NULL; |
| 535 | } |
| 536 | |
Jonas Ådahl | e3cddce | 2012-06-13 00:01:22 +0200 | [diff] [blame] | 537 | static void |
Jonas Ådahl | 0476974 | 2012-06-13 00:01:24 +0200 | [diff] [blame] | 538 | focus_state_destroy(struct focus_state *state) |
| 539 | { |
| 540 | wl_list_remove(&state->seat_destroy_listener.link); |
| 541 | wl_list_remove(&state->surface_destroy_listener.link); |
| 542 | free(state); |
| 543 | } |
| 544 | |
| 545 | static void |
| 546 | focus_state_seat_destroy(struct wl_listener *listener, void *data) |
| 547 | { |
| 548 | struct focus_state *state = container_of(listener, |
| 549 | struct focus_state, |
| 550 | seat_destroy_listener); |
| 551 | |
| 552 | wl_list_remove(&state->link); |
| 553 | focus_state_destroy(state); |
| 554 | } |
| 555 | |
| 556 | static void |
| 557 | focus_state_surface_destroy(struct wl_listener *listener, void *data) |
| 558 | { |
| 559 | struct focus_state *state = container_of(listener, |
| 560 | struct focus_state, |
Kristian Høgsberg | b8e0d0f | 2012-07-31 10:30:26 -0400 | [diff] [blame] | 561 | surface_destroy_listener); |
Kristian Høgsberg | e377822 | 2012-07-31 17:29:30 -0400 | [diff] [blame] | 562 | struct desktop_shell *shell; |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 563 | struct weston_surface *main_surface, *next; |
| 564 | struct weston_view *view; |
Jonas Ådahl | 0476974 | 2012-06-13 00:01:24 +0200 | [diff] [blame] | 565 | |
Pekka Paalanen | 01388e2 | 2013-04-25 13:57:44 +0300 | [diff] [blame] | 566 | main_surface = weston_surface_get_main_surface(state->keyboard_focus); |
| 567 | |
Kristian Høgsberg | e377822 | 2012-07-31 17:29:30 -0400 | [diff] [blame] | 568 | next = NULL; |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 569 | wl_list_for_each(view, &state->ws->layer.view_list, layer_link) { |
| 570 | if (view->surface == main_surface) |
Kristian Høgsberg | e377822 | 2012-07-31 17:29:30 -0400 | [diff] [blame] | 571 | continue; |
Louis-Francis Ratté-Boulianne | b482dbd | 2013-11-19 11:37:11 +0100 | [diff] [blame] | 572 | if (is_focus_view(view)) |
| 573 | continue; |
Kristian Høgsberg | e377822 | 2012-07-31 17:29:30 -0400 | [diff] [blame] | 574 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 575 | next = view->surface; |
Kristian Høgsberg | e377822 | 2012-07-31 17:29:30 -0400 | [diff] [blame] | 576 | break; |
| 577 | } |
| 578 | |
Pekka Paalanen | 01388e2 | 2013-04-25 13:57:44 +0300 | [diff] [blame] | 579 | /* if the focus was a sub-surface, activate its main surface */ |
| 580 | if (main_surface != state->keyboard_focus) |
| 581 | next = main_surface; |
| 582 | |
Louis-Francis Ratté-Boulianne | b482dbd | 2013-11-19 11:37:11 +0100 | [diff] [blame] | 583 | shell = state->seat->compositor->shell_interface.shell; |
Kristian Høgsberg | e377822 | 2012-07-31 17:29:30 -0400 | [diff] [blame] | 584 | if (next) { |
Louis-Francis Ratté-Boulianne | b482dbd | 2013-11-19 11:37:11 +0100 | [diff] [blame] | 585 | state->keyboard_focus = NULL; |
Kristian Høgsberg | e377822 | 2012-07-31 17:29:30 -0400 | [diff] [blame] | 586 | activate(shell, next, state->seat); |
| 587 | } else { |
Louis-Francis Ratté-Boulianne | b482dbd | 2013-11-19 11:37:11 +0100 | [diff] [blame] | 588 | if (shell->focus_animation_type == ANIMATION_DIM_LAYER) { |
| 589 | if (state->ws->focus_animation) |
| 590 | weston_view_animation_destroy(state->ws->focus_animation); |
| 591 | |
| 592 | state->ws->focus_animation = weston_fade_run( |
| 593 | state->ws->fsurf_front->view, |
| 594 | state->ws->fsurf_front->view->alpha, 0.0, 300, |
| 595 | focus_animation_done, state->ws); |
| 596 | } |
| 597 | |
Kristian Høgsberg | e377822 | 2012-07-31 17:29:30 -0400 | [diff] [blame] | 598 | wl_list_remove(&state->link); |
| 599 | focus_state_destroy(state); |
| 600 | } |
Jonas Ådahl | 0476974 | 2012-06-13 00:01:24 +0200 | [diff] [blame] | 601 | } |
| 602 | |
| 603 | static struct focus_state * |
Kristian Høgsberg | 2f5faff | 2012-07-31 16:36:34 -0400 | [diff] [blame] | 604 | focus_state_create(struct weston_seat *seat, struct workspace *ws) |
Jonas Ådahl | 0476974 | 2012-06-13 00:01:24 +0200 | [diff] [blame] | 605 | { |
Jonas Ådahl | 0476974 | 2012-06-13 00:01:24 +0200 | [diff] [blame] | 606 | struct focus_state *state; |
Jonas Ådahl | 0476974 | 2012-06-13 00:01:24 +0200 | [diff] [blame] | 607 | |
| 608 | state = malloc(sizeof *state); |
| 609 | if (state == NULL) |
| 610 | return NULL; |
| 611 | |
Louis-Francis Ratté-Boulianne | b482dbd | 2013-11-19 11:37:11 +0100 | [diff] [blame] | 612 | state->keyboard_focus = NULL; |
Kristian Høgsberg | 2f5faff | 2012-07-31 16:36:34 -0400 | [diff] [blame] | 613 | state->ws = ws; |
Jonas Ådahl | 0476974 | 2012-06-13 00:01:24 +0200 | [diff] [blame] | 614 | state->seat = seat; |
Kristian Høgsberg | 2f5faff | 2012-07-31 16:36:34 -0400 | [diff] [blame] | 615 | wl_list_insert(&ws->focus_list, &state->link); |
Jonas Ådahl | 0476974 | 2012-06-13 00:01:24 +0200 | [diff] [blame] | 616 | |
| 617 | state->seat_destroy_listener.notify = focus_state_seat_destroy; |
| 618 | state->surface_destroy_listener.notify = focus_state_surface_destroy; |
Kristian Høgsberg | 4912454 | 2013-05-06 22:27:40 -0400 | [diff] [blame] | 619 | wl_signal_add(&seat->destroy_signal, |
Jonas Ådahl | 0476974 | 2012-06-13 00:01:24 +0200 | [diff] [blame] | 620 | &state->seat_destroy_listener); |
Kristian Høgsberg | 2f5faff | 2012-07-31 16:36:34 -0400 | [diff] [blame] | 621 | wl_list_init(&state->surface_destroy_listener.link); |
Jonas Ådahl | 0476974 | 2012-06-13 00:01:24 +0200 | [diff] [blame] | 622 | |
| 623 | return state; |
| 624 | } |
| 625 | |
Jonas Ådahl | 8538b22 | 2012-08-29 22:13:03 +0200 | [diff] [blame] | 626 | static struct focus_state * |
| 627 | ensure_focus_state(struct desktop_shell *shell, struct weston_seat *seat) |
| 628 | { |
| 629 | struct workspace *ws = get_current_workspace(shell); |
| 630 | struct focus_state *state; |
| 631 | |
| 632 | wl_list_for_each(state, &ws->focus_list, link) |
| 633 | if (state->seat == seat) |
| 634 | break; |
| 635 | |
| 636 | if (&state->link == &ws->focus_list) |
| 637 | state = focus_state_create(seat, ws); |
| 638 | |
| 639 | return state; |
| 640 | } |
| 641 | |
Jonas Ådahl | 0476974 | 2012-06-13 00:01:24 +0200 | [diff] [blame] | 642 | static void |
Kristian Høgsberg | 2f5faff | 2012-07-31 16:36:34 -0400 | [diff] [blame] | 643 | restore_focus_state(struct desktop_shell *shell, struct workspace *ws) |
Jonas Ådahl | 0476974 | 2012-06-13 00:01:24 +0200 | [diff] [blame] | 644 | { |
| 645 | struct focus_state *state, *next; |
Kristian Høgsberg | fe7aa90 | 2013-05-08 09:54:37 -0400 | [diff] [blame] | 646 | struct weston_surface *surface; |
Jonas Ådahl | 0476974 | 2012-06-13 00:01:24 +0200 | [diff] [blame] | 647 | |
| 648 | wl_list_for_each_safe(state, next, &ws->focus_list, link) { |
Kristian Høgsberg | fe7aa90 | 2013-05-08 09:54:37 -0400 | [diff] [blame] | 649 | surface = state->keyboard_focus; |
Jonas Ådahl | 5689944 | 2012-08-29 22:12:59 +0200 | [diff] [blame] | 650 | |
Kristian Høgsberg | e314875 | 2013-05-06 23:19:49 -0400 | [diff] [blame] | 651 | weston_keyboard_set_focus(state->seat->keyboard, surface); |
Jonas Ådahl | 0476974 | 2012-06-13 00:01:24 +0200 | [diff] [blame] | 652 | } |
| 653 | } |
| 654 | |
| 655 | static void |
Jonas Ådahl | 8de6a1d | 2012-08-29 22:13:00 +0200 | [diff] [blame] | 656 | replace_focus_state(struct desktop_shell *shell, struct workspace *ws, |
| 657 | struct weston_seat *seat) |
| 658 | { |
| 659 | struct focus_state *state; |
Kristian Høgsberg | fe7aa90 | 2013-05-08 09:54:37 -0400 | [diff] [blame] | 660 | struct weston_surface *surface; |
Jonas Ådahl | 8de6a1d | 2012-08-29 22:13:00 +0200 | [diff] [blame] | 661 | |
| 662 | wl_list_for_each(state, &ws->focus_list, link) { |
| 663 | if (state->seat == seat) { |
Kristian Høgsberg | e314875 | 2013-05-06 23:19:49 -0400 | [diff] [blame] | 664 | surface = seat->keyboard->focus; |
Jason Ekstrand | 651f00e | 2013-06-14 10:07:54 -0500 | [diff] [blame] | 665 | state->keyboard_focus = surface; |
Jonas Ådahl | 8de6a1d | 2012-08-29 22:13:00 +0200 | [diff] [blame] | 666 | return; |
| 667 | } |
| 668 | } |
| 669 | } |
| 670 | |
| 671 | static void |
| 672 | drop_focus_state(struct desktop_shell *shell, struct workspace *ws, |
| 673 | struct weston_surface *surface) |
| 674 | { |
| 675 | struct focus_state *state; |
| 676 | |
| 677 | wl_list_for_each(state, &ws->focus_list, link) |
| 678 | if (state->keyboard_focus == surface) |
| 679 | state->keyboard_focus = NULL; |
| 680 | } |
| 681 | |
| 682 | static void |
Louis-Francis Ratté-Boulianne | b482dbd | 2013-11-19 11:37:11 +0100 | [diff] [blame] | 683 | animate_focus_change(struct desktop_shell *shell, struct workspace *ws, |
| 684 | struct weston_view *from, struct weston_view *to) |
| 685 | { |
| 686 | struct weston_output *output; |
| 687 | bool focus_surface_created = false; |
| 688 | |
| 689 | /* FIXME: Only support dim animation using two layers */ |
| 690 | if (from == to || shell->focus_animation_type != ANIMATION_DIM_LAYER) |
| 691 | return; |
| 692 | |
| 693 | output = get_default_output(shell->compositor); |
| 694 | if (ws->fsurf_front == NULL && (from || to)) { |
| 695 | ws->fsurf_front = create_focus_surface(shell->compositor, output); |
| 696 | ws->fsurf_back = create_focus_surface(shell->compositor, output); |
| 697 | ws->fsurf_front->view->alpha = 0.0; |
| 698 | ws->fsurf_back->view->alpha = 0.0; |
| 699 | focus_surface_created = true; |
| 700 | } else { |
| 701 | wl_list_remove(&ws->fsurf_front->view->layer_link); |
| 702 | wl_list_remove(&ws->fsurf_back->view->layer_link); |
| 703 | } |
| 704 | |
| 705 | if (ws->focus_animation) { |
| 706 | weston_view_animation_destroy(ws->focus_animation); |
| 707 | ws->focus_animation = NULL; |
| 708 | } |
| 709 | |
| 710 | if (to) |
| 711 | wl_list_insert(&to->layer_link, |
| 712 | &ws->fsurf_front->view->layer_link); |
| 713 | else if (from) |
| 714 | wl_list_insert(&ws->layer.view_list, |
| 715 | &ws->fsurf_front->view->layer_link); |
| 716 | |
| 717 | if (focus_surface_created) { |
| 718 | ws->focus_animation = weston_fade_run( |
| 719 | ws->fsurf_front->view, |
| 720 | ws->fsurf_front->view->alpha, 0.6, 300, |
| 721 | focus_animation_done, ws); |
| 722 | } else if (from) { |
| 723 | wl_list_insert(&from->layer_link, |
| 724 | &ws->fsurf_back->view->layer_link); |
| 725 | ws->focus_animation = weston_stable_fade_run( |
| 726 | ws->fsurf_front->view, 0.0, |
| 727 | ws->fsurf_back->view, 0.6, |
| 728 | focus_animation_done, ws); |
| 729 | } else if (to) { |
| 730 | wl_list_insert(&ws->layer.view_list, |
| 731 | &ws->fsurf_back->view->layer_link); |
| 732 | ws->focus_animation = weston_stable_fade_run( |
| 733 | ws->fsurf_front->view, 0.0, |
| 734 | ws->fsurf_back->view, 0.6, |
| 735 | focus_animation_done, ws); |
| 736 | } |
| 737 | } |
| 738 | |
| 739 | static void |
Jonas Ådahl | e3cddce | 2012-06-13 00:01:22 +0200 | [diff] [blame] | 740 | workspace_destroy(struct workspace *ws) |
| 741 | { |
Jonas Ådahl | 0476974 | 2012-06-13 00:01:24 +0200 | [diff] [blame] | 742 | struct focus_state *state, *next; |
| 743 | |
| 744 | wl_list_for_each_safe(state, next, &ws->focus_list, link) |
| 745 | focus_state_destroy(state); |
| 746 | |
Louis-Francis Ratté-Boulianne | b482dbd | 2013-11-19 11:37:11 +0100 | [diff] [blame] | 747 | if (ws->fsurf_front) |
| 748 | focus_surface_destroy(ws->fsurf_front); |
| 749 | if (ws->fsurf_back) |
| 750 | focus_surface_destroy(ws->fsurf_back); |
| 751 | |
Jonas Ådahl | e3cddce | 2012-06-13 00:01:22 +0200 | [diff] [blame] | 752 | free(ws); |
| 753 | } |
| 754 | |
Jonas Ådahl | 0476974 | 2012-06-13 00:01:24 +0200 | [diff] [blame] | 755 | static void |
| 756 | seat_destroyed(struct wl_listener *listener, void *data) |
| 757 | { |
| 758 | struct weston_seat *seat = data; |
| 759 | struct focus_state *state, *next; |
| 760 | struct workspace *ws = container_of(listener, |
| 761 | struct workspace, |
| 762 | seat_destroyed_listener); |
| 763 | |
| 764 | wl_list_for_each_safe(state, next, &ws->focus_list, link) |
| 765 | if (state->seat == seat) |
| 766 | wl_list_remove(&state->link); |
| 767 | } |
| 768 | |
Jonas Ådahl | e3cddce | 2012-06-13 00:01:22 +0200 | [diff] [blame] | 769 | static struct workspace * |
| 770 | workspace_create(void) |
| 771 | { |
| 772 | struct workspace *ws = malloc(sizeof *ws); |
| 773 | if (ws == NULL) |
| 774 | return NULL; |
| 775 | |
| 776 | weston_layer_init(&ws->layer, NULL); |
| 777 | |
Jonas Ådahl | 0476974 | 2012-06-13 00:01:24 +0200 | [diff] [blame] | 778 | wl_list_init(&ws->focus_list); |
| 779 | wl_list_init(&ws->seat_destroyed_listener.link); |
| 780 | ws->seat_destroyed_listener.notify = seat_destroyed; |
Louis-Francis Ratté-Boulianne | b482dbd | 2013-11-19 11:37:11 +0100 | [diff] [blame] | 781 | ws->fsurf_front = NULL; |
| 782 | ws->fsurf_back = NULL; |
| 783 | ws->focus_animation = NULL; |
Jonas Ådahl | 0476974 | 2012-06-13 00:01:24 +0200 | [diff] [blame] | 784 | |
Jonas Ådahl | e3cddce | 2012-06-13 00:01:22 +0200 | [diff] [blame] | 785 | return ws; |
| 786 | } |
| 787 | |
Jonas Ådahl | 62fcd04 | 2012-06-13 00:01:23 +0200 | [diff] [blame] | 788 | static int |
| 789 | workspace_is_empty(struct workspace *ws) |
| 790 | { |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 791 | return wl_list_empty(&ws->layer.view_list); |
Jonas Ådahl | 62fcd04 | 2012-06-13 00:01:23 +0200 | [diff] [blame] | 792 | } |
| 793 | |
Jonas Ådahl | e3cddce | 2012-06-13 00:01:22 +0200 | [diff] [blame] | 794 | static struct workspace * |
| 795 | get_workspace(struct desktop_shell *shell, unsigned int index) |
| 796 | { |
| 797 | struct workspace **pws = shell->workspaces.array.data; |
Philipp Brüschweiler | 067abf6 | 2012-09-01 16:03:05 +0200 | [diff] [blame] | 798 | assert(index < shell->workspaces.num); |
Jonas Ådahl | e3cddce | 2012-06-13 00:01:22 +0200 | [diff] [blame] | 799 | pws += index; |
| 800 | return *pws; |
| 801 | } |
| 802 | |
Kristian Høgsberg | 1ef2313 | 2013-12-04 00:20:01 -0800 | [diff] [blame] | 803 | struct workspace * |
Jonas Ådahl | e3cddce | 2012-06-13 00:01:22 +0200 | [diff] [blame] | 804 | get_current_workspace(struct desktop_shell *shell) |
| 805 | { |
| 806 | return get_workspace(shell, shell->workspaces.current); |
| 807 | } |
| 808 | |
| 809 | static void |
| 810 | activate_workspace(struct desktop_shell *shell, unsigned int index) |
| 811 | { |
| 812 | struct workspace *ws; |
| 813 | |
| 814 | ws = get_workspace(shell, index); |
| 815 | wl_list_insert(&shell->panel_layer.link, &ws->layer.link); |
| 816 | |
| 817 | shell->workspaces.current = index; |
| 818 | } |
| 819 | |
Jonas Ådahl | 62fcd04 | 2012-06-13 00:01:23 +0200 | [diff] [blame] | 820 | static unsigned int |
| 821 | get_output_height(struct weston_output *output) |
| 822 | { |
| 823 | return abs(output->region.extents.y1 - output->region.extents.y2); |
| 824 | } |
| 825 | |
| 826 | static void |
Louis-Francis Ratté-Boulianne | b482dbd | 2013-11-19 11:37:11 +0100 | [diff] [blame] | 827 | view_translate(struct workspace *ws, struct weston_view *view, double d) |
Jonas Ådahl | 62fcd04 | 2012-06-13 00:01:23 +0200 | [diff] [blame] | 828 | { |
Jonas Ådahl | 62fcd04 | 2012-06-13 00:01:23 +0200 | [diff] [blame] | 829 | struct weston_transform *transform; |
| 830 | |
Louis-Francis Ratté-Boulianne | b482dbd | 2013-11-19 11:37:11 +0100 | [diff] [blame] | 831 | if (is_focus_view(view)) { |
| 832 | struct focus_surface *fsurf = get_focus_surface(view->surface); |
| 833 | transform = &fsurf->workspace_transform; |
| 834 | } else { |
| 835 | struct shell_surface *shsurf = get_shell_surface(view->surface); |
| 836 | transform = &shsurf->workspace_transform; |
| 837 | } |
| 838 | |
Jonas Ådahl | 62fcd04 | 2012-06-13 00:01:23 +0200 | [diff] [blame] | 839 | if (wl_list_empty(&transform->link)) |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 840 | wl_list_insert(view->geometry.transformation_list.prev, |
Louis-Francis Ratté-Boulianne | b482dbd | 2013-11-19 11:37:11 +0100 | [diff] [blame] | 841 | &transform->link); |
Jonas Ådahl | 62fcd04 | 2012-06-13 00:01:23 +0200 | [diff] [blame] | 842 | |
Louis-Francis Ratté-Boulianne | b482dbd | 2013-11-19 11:37:11 +0100 | [diff] [blame] | 843 | weston_matrix_init(&transform->matrix); |
| 844 | weston_matrix_translate(&transform->matrix, |
Jonas Ådahl | 62fcd04 | 2012-06-13 00:01:23 +0200 | [diff] [blame] | 845 | 0.0, d, 0.0); |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 846 | weston_view_geometry_dirty(view); |
Jonas Ådahl | 62fcd04 | 2012-06-13 00:01:23 +0200 | [diff] [blame] | 847 | } |
| 848 | |
| 849 | static void |
| 850 | workspace_translate_out(struct workspace *ws, double fraction) |
| 851 | { |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 852 | struct weston_view *view; |
Jonas Ådahl | 62fcd04 | 2012-06-13 00:01:23 +0200 | [diff] [blame] | 853 | unsigned int height; |
| 854 | double d; |
| 855 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 856 | wl_list_for_each(view, &ws->layer.view_list, layer_link) { |
| 857 | height = get_output_height(view->surface->output); |
Jonas Ådahl | 62fcd04 | 2012-06-13 00:01:23 +0200 | [diff] [blame] | 858 | d = height * fraction; |
| 859 | |
Louis-Francis Ratté-Boulianne | b482dbd | 2013-11-19 11:37:11 +0100 | [diff] [blame] | 860 | view_translate(ws, view, d); |
Jonas Ådahl | 62fcd04 | 2012-06-13 00:01:23 +0200 | [diff] [blame] | 861 | } |
| 862 | } |
| 863 | |
| 864 | static void |
| 865 | workspace_translate_in(struct workspace *ws, double fraction) |
| 866 | { |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 867 | struct weston_view *view; |
Jonas Ådahl | 62fcd04 | 2012-06-13 00:01:23 +0200 | [diff] [blame] | 868 | unsigned int height; |
| 869 | double d; |
| 870 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 871 | wl_list_for_each(view, &ws->layer.view_list, layer_link) { |
| 872 | height = get_output_height(view->surface->output); |
Jonas Ådahl | 62fcd04 | 2012-06-13 00:01:23 +0200 | [diff] [blame] | 873 | |
| 874 | if (fraction > 0) |
| 875 | d = -(height - height * fraction); |
| 876 | else |
| 877 | d = height + height * fraction; |
| 878 | |
Louis-Francis Ratté-Boulianne | b482dbd | 2013-11-19 11:37:11 +0100 | [diff] [blame] | 879 | view_translate(ws, view, d); |
Jonas Ådahl | 62fcd04 | 2012-06-13 00:01:23 +0200 | [diff] [blame] | 880 | } |
| 881 | } |
| 882 | |
| 883 | static void |
Jonas Ådahl | e9d2250 | 2012-08-29 22:13:01 +0200 | [diff] [blame] | 884 | broadcast_current_workspace_state(struct desktop_shell *shell) |
| 885 | { |
Kristian Høgsberg | 2e3c396 | 2013-09-11 12:00:47 -0700 | [diff] [blame] | 886 | struct wl_resource *resource; |
Jonas Ådahl | e9d2250 | 2012-08-29 22:13:01 +0200 | [diff] [blame] | 887 | |
Kristian Høgsberg | 2e3c396 | 2013-09-11 12:00:47 -0700 | [diff] [blame] | 888 | wl_resource_for_each(resource, &shell->workspaces.client_list) |
| 889 | workspace_manager_send_state(resource, |
Jonas Ådahl | e9d2250 | 2012-08-29 22:13:01 +0200 | [diff] [blame] | 890 | shell->workspaces.current, |
| 891 | shell->workspaces.num); |
| 892 | } |
| 893 | |
| 894 | static void |
Jonas Ådahl | 62fcd04 | 2012-06-13 00:01:23 +0200 | [diff] [blame] | 895 | reverse_workspace_change_animation(struct desktop_shell *shell, |
| 896 | unsigned int index, |
| 897 | struct workspace *from, |
| 898 | struct workspace *to) |
| 899 | { |
| 900 | shell->workspaces.current = index; |
| 901 | |
| 902 | shell->workspaces.anim_to = to; |
| 903 | shell->workspaces.anim_from = from; |
| 904 | shell->workspaces.anim_dir = -1 * shell->workspaces.anim_dir; |
| 905 | shell->workspaces.anim_timestamp = 0; |
| 906 | |
Scott Moreau | 4272e63 | 2012-08-13 09:58:41 -0600 | [diff] [blame] | 907 | weston_compositor_schedule_repaint(shell->compositor); |
Jonas Ådahl | 62fcd04 | 2012-06-13 00:01:23 +0200 | [diff] [blame] | 908 | } |
| 909 | |
| 910 | static void |
| 911 | workspace_deactivate_transforms(struct workspace *ws) |
| 912 | { |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 913 | struct weston_view *view; |
Louis-Francis Ratté-Boulianne | b482dbd | 2013-11-19 11:37:11 +0100 | [diff] [blame] | 914 | struct weston_transform *transform; |
Jonas Ådahl | 62fcd04 | 2012-06-13 00:01:23 +0200 | [diff] [blame] | 915 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 916 | 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] | 917 | if (is_focus_view(view)) { |
| 918 | struct focus_surface *fsurf = get_focus_surface(view->surface); |
| 919 | transform = &fsurf->workspace_transform; |
| 920 | } else { |
| 921 | struct shell_surface *shsurf = get_shell_surface(view->surface); |
| 922 | transform = &shsurf->workspace_transform; |
| 923 | } |
| 924 | |
| 925 | if (!wl_list_empty(&transform->link)) { |
| 926 | wl_list_remove(&transform->link); |
| 927 | wl_list_init(&transform->link); |
Jonas Ådahl | 8de6a1d | 2012-08-29 22:13:00 +0200 | [diff] [blame] | 928 | } |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 929 | weston_view_geometry_dirty(view); |
Jonas Ådahl | 62fcd04 | 2012-06-13 00:01:23 +0200 | [diff] [blame] | 930 | } |
| 931 | } |
| 932 | |
| 933 | static void |
| 934 | finish_workspace_change_animation(struct desktop_shell *shell, |
| 935 | struct workspace *from, |
| 936 | struct workspace *to) |
| 937 | { |
Scott Moreau | 4272e63 | 2012-08-13 09:58:41 -0600 | [diff] [blame] | 938 | weston_compositor_schedule_repaint(shell->compositor); |
Jonas Ådahl | 62fcd04 | 2012-06-13 00:01:23 +0200 | [diff] [blame] | 939 | |
| 940 | wl_list_remove(&shell->workspaces.animation.link); |
| 941 | workspace_deactivate_transforms(from); |
| 942 | workspace_deactivate_transforms(to); |
| 943 | shell->workspaces.anim_to = NULL; |
| 944 | |
| 945 | wl_list_remove(&shell->workspaces.anim_from->layer.link); |
| 946 | } |
| 947 | |
| 948 | static void |
| 949 | animate_workspace_change_frame(struct weston_animation *animation, |
| 950 | struct weston_output *output, uint32_t msecs) |
| 951 | { |
| 952 | struct desktop_shell *shell = |
| 953 | container_of(animation, struct desktop_shell, |
| 954 | workspaces.animation); |
| 955 | struct workspace *from = shell->workspaces.anim_from; |
| 956 | struct workspace *to = shell->workspaces.anim_to; |
| 957 | uint32_t t; |
| 958 | double x, y; |
| 959 | |
| 960 | if (workspace_is_empty(from) && workspace_is_empty(to)) { |
| 961 | finish_workspace_change_animation(shell, from, to); |
| 962 | return; |
| 963 | } |
| 964 | |
| 965 | if (shell->workspaces.anim_timestamp == 0) { |
| 966 | if (shell->workspaces.anim_current == 0.0) |
| 967 | shell->workspaces.anim_timestamp = msecs; |
| 968 | else |
| 969 | shell->workspaces.anim_timestamp = |
| 970 | msecs - |
| 971 | /* Invers of movement function 'y' below. */ |
| 972 | (asin(1.0 - shell->workspaces.anim_current) * |
| 973 | DEFAULT_WORKSPACE_CHANGE_ANIMATION_LENGTH * |
| 974 | M_2_PI); |
| 975 | } |
| 976 | |
| 977 | t = msecs - shell->workspaces.anim_timestamp; |
| 978 | |
| 979 | /* |
| 980 | * x = [0, π/2] |
| 981 | * y(x) = sin(x) |
| 982 | */ |
| 983 | x = t * (1.0/DEFAULT_WORKSPACE_CHANGE_ANIMATION_LENGTH) * M_PI_2; |
| 984 | y = sin(x); |
| 985 | |
| 986 | if (t < DEFAULT_WORKSPACE_CHANGE_ANIMATION_LENGTH) { |
Scott Moreau | 4272e63 | 2012-08-13 09:58:41 -0600 | [diff] [blame] | 987 | weston_compositor_schedule_repaint(shell->compositor); |
Jonas Ådahl | 62fcd04 | 2012-06-13 00:01:23 +0200 | [diff] [blame] | 988 | |
| 989 | workspace_translate_out(from, shell->workspaces.anim_dir * y); |
| 990 | workspace_translate_in(to, shell->workspaces.anim_dir * y); |
| 991 | shell->workspaces.anim_current = y; |
| 992 | |
Scott Moreau | 4272e63 | 2012-08-13 09:58:41 -0600 | [diff] [blame] | 993 | weston_compositor_schedule_repaint(shell->compositor); |
Jonas Ådahl | 62fcd04 | 2012-06-13 00:01:23 +0200 | [diff] [blame] | 994 | } |
Jonas Ådahl | 0476974 | 2012-06-13 00:01:24 +0200 | [diff] [blame] | 995 | else |
Jonas Ådahl | 62fcd04 | 2012-06-13 00:01:23 +0200 | [diff] [blame] | 996 | finish_workspace_change_animation(shell, from, to); |
Jonas Ådahl | 62fcd04 | 2012-06-13 00:01:23 +0200 | [diff] [blame] | 997 | } |
| 998 | |
| 999 | static void |
| 1000 | animate_workspace_change(struct desktop_shell *shell, |
| 1001 | unsigned int index, |
| 1002 | struct workspace *from, |
| 1003 | struct workspace *to) |
| 1004 | { |
| 1005 | struct weston_output *output; |
| 1006 | |
| 1007 | int dir; |
| 1008 | |
| 1009 | if (index > shell->workspaces.current) |
| 1010 | dir = -1; |
| 1011 | else |
| 1012 | dir = 1; |
| 1013 | |
| 1014 | shell->workspaces.current = index; |
| 1015 | |
| 1016 | shell->workspaces.anim_dir = dir; |
| 1017 | shell->workspaces.anim_from = from; |
| 1018 | shell->workspaces.anim_to = to; |
| 1019 | shell->workspaces.anim_current = 0.0; |
| 1020 | shell->workspaces.anim_timestamp = 0; |
| 1021 | |
| 1022 | output = container_of(shell->compositor->output_list.next, |
| 1023 | struct weston_output, link); |
| 1024 | wl_list_insert(&output->animation_list, |
| 1025 | &shell->workspaces.animation.link); |
| 1026 | |
Jonas Ådahl | 8de6a1d | 2012-08-29 22:13:00 +0200 | [diff] [blame] | 1027 | wl_list_insert(from->layer.link.prev, &to->layer.link); |
Jonas Ådahl | 62fcd04 | 2012-06-13 00:01:23 +0200 | [diff] [blame] | 1028 | |
| 1029 | workspace_translate_in(to, 0); |
| 1030 | |
Kristian Høgsberg | 2f5faff | 2012-07-31 16:36:34 -0400 | [diff] [blame] | 1031 | restore_focus_state(shell, to); |
Jonas Ådahl | 0476974 | 2012-06-13 00:01:24 +0200 | [diff] [blame] | 1032 | |
Scott Moreau | 4272e63 | 2012-08-13 09:58:41 -0600 | [diff] [blame] | 1033 | weston_compositor_schedule_repaint(shell->compositor); |
Jonas Ådahl | 62fcd04 | 2012-06-13 00:01:23 +0200 | [diff] [blame] | 1034 | } |
| 1035 | |
Jonas Ådahl | e3cddce | 2012-06-13 00:01:22 +0200 | [diff] [blame] | 1036 | static void |
Jonas Ådahl | 8de6a1d | 2012-08-29 22:13:00 +0200 | [diff] [blame] | 1037 | update_workspace(struct desktop_shell *shell, unsigned int index, |
| 1038 | struct workspace *from, struct workspace *to) |
| 1039 | { |
| 1040 | shell->workspaces.current = index; |
| 1041 | wl_list_insert(&from->layer.link, &to->layer.link); |
| 1042 | wl_list_remove(&from->layer.link); |
| 1043 | } |
| 1044 | |
| 1045 | static void |
Jonas Ådahl | e3cddce | 2012-06-13 00:01:22 +0200 | [diff] [blame] | 1046 | change_workspace(struct desktop_shell *shell, unsigned int index) |
| 1047 | { |
| 1048 | struct workspace *from; |
| 1049 | struct workspace *to; |
Louis-Francis Ratté-Boulianne | b482dbd | 2013-11-19 11:37:11 +0100 | [diff] [blame] | 1050 | struct focus_state *state; |
Jonas Ådahl | e3cddce | 2012-06-13 00:01:22 +0200 | [diff] [blame] | 1051 | |
| 1052 | if (index == shell->workspaces.current) |
| 1053 | return; |
| 1054 | |
| 1055 | /* Don't change workspace when there is any fullscreen surfaces. */ |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 1056 | if (!wl_list_empty(&shell->fullscreen_layer.view_list)) |
Jonas Ådahl | e3cddce | 2012-06-13 00:01:22 +0200 | [diff] [blame] | 1057 | return; |
| 1058 | |
Jonas Ådahl | e3cddce | 2012-06-13 00:01:22 +0200 | [diff] [blame] | 1059 | from = get_current_workspace(shell); |
| 1060 | to = get_workspace(shell, index); |
| 1061 | |
Jonas Ådahl | 62fcd04 | 2012-06-13 00:01:23 +0200 | [diff] [blame] | 1062 | if (shell->workspaces.anim_from == to && |
| 1063 | shell->workspaces.anim_to == from) { |
Jonas Ådahl | 8de6a1d | 2012-08-29 22:13:00 +0200 | [diff] [blame] | 1064 | restore_focus_state(shell, to); |
Jonas Ådahl | 62fcd04 | 2012-06-13 00:01:23 +0200 | [diff] [blame] | 1065 | reverse_workspace_change_animation(shell, index, from, to); |
Jonas Ådahl | e9d2250 | 2012-08-29 22:13:01 +0200 | [diff] [blame] | 1066 | broadcast_current_workspace_state(shell); |
Jonas Ådahl | 62fcd04 | 2012-06-13 00:01:23 +0200 | [diff] [blame] | 1067 | return; |
| 1068 | } |
Jonas Ådahl | e3cddce | 2012-06-13 00:01:22 +0200 | [diff] [blame] | 1069 | |
Jonas Ådahl | 62fcd04 | 2012-06-13 00:01:23 +0200 | [diff] [blame] | 1070 | if (shell->workspaces.anim_to != NULL) |
| 1071 | finish_workspace_change_animation(shell, |
| 1072 | shell->workspaces.anim_from, |
| 1073 | shell->workspaces.anim_to); |
| 1074 | |
Jonas Ådahl | 8de6a1d | 2012-08-29 22:13:00 +0200 | [diff] [blame] | 1075 | restore_focus_state(shell, to); |
Jonas Ådahl | 0476974 | 2012-06-13 00:01:24 +0200 | [diff] [blame] | 1076 | |
Louis-Francis Ratté-Boulianne | b482dbd | 2013-11-19 11:37:11 +0100 | [diff] [blame] | 1077 | if (shell->focus_animation_type != ANIMATION_NONE) { |
| 1078 | wl_list_for_each(state, &from->focus_list, link) |
| 1079 | if (state->keyboard_focus) |
| 1080 | animate_focus_change(shell, from, |
| 1081 | get_default_view(state->keyboard_focus), NULL); |
| 1082 | |
| 1083 | wl_list_for_each(state, &to->focus_list, link) |
| 1084 | if (state->keyboard_focus) |
| 1085 | animate_focus_change(shell, to, |
| 1086 | NULL, get_default_view(state->keyboard_focus)); |
| 1087 | } |
| 1088 | |
Jonas Ådahl | 8de6a1d | 2012-08-29 22:13:00 +0200 | [diff] [blame] | 1089 | if (workspace_is_empty(to) && workspace_is_empty(from)) |
| 1090 | update_workspace(shell, index, from, to); |
Jonas Ådahl | 62fcd04 | 2012-06-13 00:01:23 +0200 | [diff] [blame] | 1091 | else |
| 1092 | animate_workspace_change(shell, index, from, to); |
Jonas Ådahl | e9d2250 | 2012-08-29 22:13:01 +0200 | [diff] [blame] | 1093 | |
| 1094 | broadcast_current_workspace_state(shell); |
Pekka Paalanen | e955f1e | 2011-12-07 11:49:52 +0200 | [diff] [blame] | 1095 | } |
| 1096 | |
Jonas Ådahl | 8de6a1d | 2012-08-29 22:13:00 +0200 | [diff] [blame] | 1097 | static bool |
| 1098 | workspace_has_only(struct workspace *ws, struct weston_surface *surface) |
| 1099 | { |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 1100 | struct wl_list *list = &ws->layer.view_list; |
Jonas Ådahl | 8de6a1d | 2012-08-29 22:13:00 +0200 | [diff] [blame] | 1101 | struct wl_list *e; |
| 1102 | |
| 1103 | if (wl_list_empty(list)) |
| 1104 | return false; |
| 1105 | |
| 1106 | e = list->next; |
| 1107 | |
| 1108 | if (e->next != list) |
| 1109 | return false; |
| 1110 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 1111 | return container_of(e, struct weston_view, layer_link)->surface == surface; |
Jonas Ådahl | 8de6a1d | 2012-08-29 22:13:00 +0200 | [diff] [blame] | 1112 | } |
| 1113 | |
| 1114 | static void |
Philip Withnall | 659163d | 2013-11-25 18:01:36 +0000 | [diff] [blame] | 1115 | move_surface_to_workspace(struct desktop_shell *shell, |
| 1116 | struct shell_surface *shsurf, |
| 1117 | uint32_t workspace) |
Jonas Ådahl | e9d2250 | 2012-08-29 22:13:01 +0200 | [diff] [blame] | 1118 | { |
| 1119 | struct workspace *from; |
| 1120 | struct workspace *to; |
| 1121 | struct weston_seat *seat; |
Pekka Paalanen | 01388e2 | 2013-04-25 13:57:44 +0300 | [diff] [blame] | 1122 | struct weston_surface *focus; |
Philip Withnall | 659163d | 2013-11-25 18:01:36 +0000 | [diff] [blame] | 1123 | struct weston_view *view; |
Jonas Ådahl | e9d2250 | 2012-08-29 22:13:01 +0200 | [diff] [blame] | 1124 | |
| 1125 | if (workspace == shell->workspaces.current) |
| 1126 | return; |
| 1127 | |
Philip Withnall | 659163d | 2013-11-25 18:01:36 +0000 | [diff] [blame] | 1128 | view = get_default_view(shsurf->surface); |
| 1129 | if (!view) |
| 1130 | return; |
| 1131 | |
| 1132 | assert(weston_surface_get_main_surface(view->surface) == view->surface); |
| 1133 | |
Philipp Brüschweiler | 067abf6 | 2012-09-01 16:03:05 +0200 | [diff] [blame] | 1134 | if (workspace >= shell->workspaces.num) |
| 1135 | workspace = shell->workspaces.num - 1; |
| 1136 | |
Jonas Ådahl | e9d2250 | 2012-08-29 22:13:01 +0200 | [diff] [blame] | 1137 | from = get_current_workspace(shell); |
| 1138 | to = get_workspace(shell, workspace); |
| 1139 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 1140 | wl_list_remove(&view->layer_link); |
| 1141 | wl_list_insert(&to->layer.view_list, &view->layer_link); |
Jonas Ådahl | e9d2250 | 2012-08-29 22:13:01 +0200 | [diff] [blame] | 1142 | |
Philip Withnall | 648a4dd | 2013-11-25 18:01:44 +0000 | [diff] [blame] | 1143 | shell_surface_update_child_surface_layers(shsurf); |
| 1144 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 1145 | drop_focus_state(shell, from, view->surface); |
Pekka Paalanen | 01388e2 | 2013-04-25 13:57:44 +0300 | [diff] [blame] | 1146 | wl_list_for_each(seat, &shell->compositor->seat_list, link) { |
| 1147 | if (!seat->keyboard) |
| 1148 | continue; |
| 1149 | |
| 1150 | focus = weston_surface_get_main_surface(seat->keyboard->focus); |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 1151 | if (focus == view->surface) |
Kristian Høgsberg | e314875 | 2013-05-06 23:19:49 -0400 | [diff] [blame] | 1152 | weston_keyboard_set_focus(seat->keyboard, NULL); |
Pekka Paalanen | 01388e2 | 2013-04-25 13:57:44 +0300 | [diff] [blame] | 1153 | } |
Jonas Ådahl | e9d2250 | 2012-08-29 22:13:01 +0200 | [diff] [blame] | 1154 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 1155 | weston_view_damage_below(view); |
Jonas Ådahl | e9d2250 | 2012-08-29 22:13:01 +0200 | [diff] [blame] | 1156 | } |
| 1157 | |
| 1158 | static void |
Jonas Ådahl | 8de6a1d | 2012-08-29 22:13:00 +0200 | [diff] [blame] | 1159 | take_surface_to_workspace_by_seat(struct desktop_shell *shell, |
Kristian Høgsberg | e314875 | 2013-05-06 23:19:49 -0400 | [diff] [blame] | 1160 | struct weston_seat *seat, |
Jonas Ådahl | 8de6a1d | 2012-08-29 22:13:00 +0200 | [diff] [blame] | 1161 | unsigned int index) |
| 1162 | { |
Pekka Paalanen | 01388e2 | 2013-04-25 13:57:44 +0300 | [diff] [blame] | 1163 | struct weston_surface *surface; |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 1164 | struct weston_view *view; |
Jonas Ådahl | 8de6a1d | 2012-08-29 22:13:00 +0200 | [diff] [blame] | 1165 | struct shell_surface *shsurf; |
| 1166 | struct workspace *from; |
| 1167 | struct workspace *to; |
Jonas Ådahl | 8538b22 | 2012-08-29 22:13:03 +0200 | [diff] [blame] | 1168 | struct focus_state *state; |
Jonas Ådahl | 8de6a1d | 2012-08-29 22:13:00 +0200 | [diff] [blame] | 1169 | |
Pekka Paalanen | 01388e2 | 2013-04-25 13:57:44 +0300 | [diff] [blame] | 1170 | surface = weston_surface_get_main_surface(seat->keyboard->focus); |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 1171 | view = get_default_view(surface); |
| 1172 | if (view == NULL || |
Louis-Francis Ratté-Boulianne | b482dbd | 2013-11-19 11:37:11 +0100 | [diff] [blame] | 1173 | index == shell->workspaces.current || |
| 1174 | is_focus_view(view)) |
Jonas Ådahl | 8de6a1d | 2012-08-29 22:13:00 +0200 | [diff] [blame] | 1175 | return; |
| 1176 | |
| 1177 | from = get_current_workspace(shell); |
| 1178 | to = get_workspace(shell, index); |
| 1179 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 1180 | wl_list_remove(&view->layer_link); |
| 1181 | wl_list_insert(&to->layer.view_list, &view->layer_link); |
Jonas Ådahl | 8de6a1d | 2012-08-29 22:13:00 +0200 | [diff] [blame] | 1182 | |
Philip Withnall | 659163d | 2013-11-25 18:01:36 +0000 | [diff] [blame] | 1183 | shsurf = get_shell_surface(surface); |
Philip Withnall | 648a4dd | 2013-11-25 18:01:44 +0000 | [diff] [blame] | 1184 | if (shsurf != NULL) |
| 1185 | shell_surface_update_child_surface_layers(shsurf); |
Philip Withnall | 659163d | 2013-11-25 18:01:36 +0000 | [diff] [blame] | 1186 | |
Jonas Ådahl | e9d2250 | 2012-08-29 22:13:01 +0200 | [diff] [blame] | 1187 | replace_focus_state(shell, to, seat); |
Jonas Ådahl | 8de6a1d | 2012-08-29 22:13:00 +0200 | [diff] [blame] | 1188 | drop_focus_state(shell, from, surface); |
| 1189 | |
| 1190 | if (shell->workspaces.anim_from == to && |
| 1191 | shell->workspaces.anim_to == from) { |
Jonas Ådahl | e9d2250 | 2012-08-29 22:13:01 +0200 | [diff] [blame] | 1192 | wl_list_remove(&to->layer.link); |
| 1193 | wl_list_insert(from->layer.link.prev, &to->layer.link); |
| 1194 | |
Jonas Ådahl | 8de6a1d | 2012-08-29 22:13:00 +0200 | [diff] [blame] | 1195 | reverse_workspace_change_animation(shell, index, from, to); |
Jonas Ådahl | e9d2250 | 2012-08-29 22:13:01 +0200 | [diff] [blame] | 1196 | broadcast_current_workspace_state(shell); |
| 1197 | |
Jonas Ådahl | 8de6a1d | 2012-08-29 22:13:00 +0200 | [diff] [blame] | 1198 | return; |
| 1199 | } |
| 1200 | |
| 1201 | if (shell->workspaces.anim_to != NULL) |
| 1202 | finish_workspace_change_animation(shell, |
| 1203 | shell->workspaces.anim_from, |
| 1204 | shell->workspaces.anim_to); |
| 1205 | |
| 1206 | if (workspace_is_empty(from) && |
| 1207 | workspace_has_only(to, surface)) |
| 1208 | update_workspace(shell, index, from, to); |
| 1209 | else { |
Philip Withnall | 2c3849b | 2013-11-25 18:01:45 +0000 | [diff] [blame] | 1210 | if (shsurf != NULL && |
| 1211 | wl_list_empty(&shsurf->workspace_transform.link)) |
Jonas Ådahl | 8de6a1d | 2012-08-29 22:13:00 +0200 | [diff] [blame] | 1212 | wl_list_insert(&shell->workspaces.anim_sticky_list, |
| 1213 | &shsurf->workspace_transform.link); |
| 1214 | |
| 1215 | animate_workspace_change(shell, index, from, to); |
| 1216 | } |
Jonas Ådahl | e9d2250 | 2012-08-29 22:13:01 +0200 | [diff] [blame] | 1217 | |
| 1218 | broadcast_current_workspace_state(shell); |
Jonas Ådahl | 8538b22 | 2012-08-29 22:13:03 +0200 | [diff] [blame] | 1219 | |
| 1220 | state = ensure_focus_state(shell, seat); |
| 1221 | if (state != NULL) |
| 1222 | state->keyboard_focus = surface; |
Jonas Ådahl | e9d2250 | 2012-08-29 22:13:01 +0200 | [diff] [blame] | 1223 | } |
| 1224 | |
| 1225 | static void |
| 1226 | workspace_manager_move_surface(struct wl_client *client, |
| 1227 | struct wl_resource *resource, |
| 1228 | struct wl_resource *surface_resource, |
| 1229 | uint32_t workspace) |
| 1230 | { |
Jason Ekstrand | 651f00e | 2013-06-14 10:07:54 -0500 | [diff] [blame] | 1231 | struct desktop_shell *shell = wl_resource_get_user_data(resource); |
Jonas Ådahl | e9d2250 | 2012-08-29 22:13:01 +0200 | [diff] [blame] | 1232 | struct weston_surface *surface = |
Jason Ekstrand | 0f2ef7e | 2013-06-14 10:07:53 -0500 | [diff] [blame] | 1233 | wl_resource_get_user_data(surface_resource); |
Pekka Paalanen | 01388e2 | 2013-04-25 13:57:44 +0300 | [diff] [blame] | 1234 | struct weston_surface *main_surface; |
Philip Withnall | 659163d | 2013-11-25 18:01:36 +0000 | [diff] [blame] | 1235 | struct shell_surface *shell_surface; |
Jonas Ådahl | e9d2250 | 2012-08-29 22:13:01 +0200 | [diff] [blame] | 1236 | |
Pekka Paalanen | 01388e2 | 2013-04-25 13:57:44 +0300 | [diff] [blame] | 1237 | main_surface = weston_surface_get_main_surface(surface); |
Philip Withnall | 659163d | 2013-11-25 18:01:36 +0000 | [diff] [blame] | 1238 | shell_surface = get_shell_surface(main_surface); |
| 1239 | if (shell_surface == NULL) |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 1240 | return; |
Philip Withnall | 659163d | 2013-11-25 18:01:36 +0000 | [diff] [blame] | 1241 | |
| 1242 | move_surface_to_workspace(shell, shell_surface, workspace); |
Jonas Ådahl | e9d2250 | 2012-08-29 22:13:01 +0200 | [diff] [blame] | 1243 | } |
| 1244 | |
| 1245 | static const struct workspace_manager_interface workspace_manager_implementation = { |
| 1246 | workspace_manager_move_surface, |
| 1247 | }; |
| 1248 | |
| 1249 | static void |
| 1250 | unbind_resource(struct wl_resource *resource) |
| 1251 | { |
Jason Ekstrand | 651f00e | 2013-06-14 10:07:54 -0500 | [diff] [blame] | 1252 | wl_list_remove(wl_resource_get_link(resource)); |
Jonas Ådahl | e9d2250 | 2012-08-29 22:13:01 +0200 | [diff] [blame] | 1253 | } |
| 1254 | |
| 1255 | static void |
| 1256 | bind_workspace_manager(struct wl_client *client, |
| 1257 | void *data, uint32_t version, uint32_t id) |
| 1258 | { |
| 1259 | struct desktop_shell *shell = data; |
| 1260 | struct wl_resource *resource; |
| 1261 | |
Jason Ekstrand | a85118c | 2013-06-27 20:17:02 -0500 | [diff] [blame] | 1262 | resource = wl_resource_create(client, |
| 1263 | &workspace_manager_interface, 1, id); |
Jonas Ådahl | e9d2250 | 2012-08-29 22:13:01 +0200 | [diff] [blame] | 1264 | |
| 1265 | if (resource == NULL) { |
| 1266 | weston_log("couldn't add workspace manager object"); |
| 1267 | return; |
| 1268 | } |
| 1269 | |
Jason Ekstrand | a85118c | 2013-06-27 20:17:02 -0500 | [diff] [blame] | 1270 | wl_resource_set_implementation(resource, |
| 1271 | &workspace_manager_implementation, |
| 1272 | shell, unbind_resource); |
Jason Ekstrand | 651f00e | 2013-06-14 10:07:54 -0500 | [diff] [blame] | 1273 | wl_list_insert(&shell->workspaces.client_list, |
| 1274 | wl_resource_get_link(resource)); |
Jonas Ådahl | e9d2250 | 2012-08-29 22:13:01 +0200 | [diff] [blame] | 1275 | |
| 1276 | workspace_manager_send_state(resource, |
| 1277 | shell->workspaces.current, |
| 1278 | shell->workspaces.num); |
Jonas Ådahl | 8de6a1d | 2012-08-29 22:13:00 +0200 | [diff] [blame] | 1279 | } |
| 1280 | |
Pekka Paalanen | 56cdea9 | 2011-11-23 16:14:12 +0200 | [diff] [blame] | 1281 | static void |
Rusty Lynch | 1084da5 | 2013-08-15 09:10:08 -0700 | [diff] [blame] | 1282 | touch_move_grab_down(struct weston_touch_grab *grab, uint32_t time, |
| 1283 | int touch_id, wl_fixed_t sx, wl_fixed_t sy) |
| 1284 | { |
| 1285 | } |
| 1286 | |
| 1287 | static void |
| 1288 | touch_move_grab_up(struct weston_touch_grab *grab, uint32_t time, int touch_id) |
| 1289 | { |
Jonas Ådahl | 1c6e63e | 2013-10-25 23:18:04 +0200 | [diff] [blame] | 1290 | struct weston_touch_move_grab *move = |
| 1291 | (struct weston_touch_move_grab *) container_of( |
| 1292 | grab, struct shell_touch_grab, grab); |
Neil Roberts | e14aa4f | 2013-10-03 16:43:07 +0100 | [diff] [blame] | 1293 | |
Jonas Ådahl | 9484b69 | 2013-12-02 22:05:03 +0100 | [diff] [blame] | 1294 | if (grab->touch->num_tp == 0) { |
Jonas Ådahl | 1c6e63e | 2013-10-25 23:18:04 +0200 | [diff] [blame] | 1295 | shell_touch_grab_end(&move->base); |
| 1296 | free(move); |
| 1297 | } |
Rusty Lynch | 1084da5 | 2013-08-15 09:10:08 -0700 | [diff] [blame] | 1298 | } |
| 1299 | |
| 1300 | static void |
| 1301 | touch_move_grab_motion(struct weston_touch_grab *grab, uint32_t time, |
| 1302 | int touch_id, wl_fixed_t sx, wl_fixed_t sy) |
| 1303 | { |
| 1304 | struct weston_touch_move_grab *move = (struct weston_touch_move_grab *) grab; |
| 1305 | struct shell_surface *shsurf = move->base.shsurf; |
| 1306 | struct weston_surface *es; |
| 1307 | int dx = wl_fixed_to_int(grab->touch->grab_x + move->dx); |
| 1308 | int dy = wl_fixed_to_int(grab->touch->grab_y + move->dy); |
| 1309 | |
| 1310 | if (!shsurf) |
| 1311 | return; |
| 1312 | |
| 1313 | es = shsurf->surface; |
| 1314 | |
Jason Ekstrand | 918f2dd | 2013-12-02 21:01:53 -0600 | [diff] [blame] | 1315 | weston_view_set_position(shsurf->view, dx, dy); |
Rusty Lynch | 1084da5 | 2013-08-15 09:10:08 -0700 | [diff] [blame] | 1316 | |
| 1317 | weston_compositor_schedule_repaint(es->compositor); |
| 1318 | } |
| 1319 | |
Jonas Ådahl | 1ea343e | 2013-10-25 23:18:05 +0200 | [diff] [blame] | 1320 | static void |
| 1321 | touch_move_grab_cancel(struct weston_touch_grab *grab) |
| 1322 | { |
| 1323 | struct weston_touch_move_grab *move = |
| 1324 | (struct weston_touch_move_grab *) container_of( |
| 1325 | grab, struct shell_touch_grab, grab); |
| 1326 | |
| 1327 | shell_touch_grab_end(&move->base); |
| 1328 | free(move); |
| 1329 | } |
| 1330 | |
Rusty Lynch | 1084da5 | 2013-08-15 09:10:08 -0700 | [diff] [blame] | 1331 | static const struct weston_touch_grab_interface touch_move_grab_interface = { |
| 1332 | touch_move_grab_down, |
| 1333 | touch_move_grab_up, |
| 1334 | touch_move_grab_motion, |
Jonas Ådahl | 1ea343e | 2013-10-25 23:18:05 +0200 | [diff] [blame] | 1335 | touch_move_grab_cancel, |
Rusty Lynch | 1084da5 | 2013-08-15 09:10:08 -0700 | [diff] [blame] | 1336 | }; |
| 1337 | |
| 1338 | static int |
| 1339 | surface_touch_move(struct shell_surface *shsurf, struct weston_seat *seat) |
| 1340 | { |
| 1341 | struct weston_touch_move_grab *move; |
| 1342 | |
| 1343 | if (!shsurf) |
| 1344 | return -1; |
| 1345 | |
Rafael Antognolli | 03b1659 | 2013-12-03 15:35:42 -0200 | [diff] [blame] | 1346 | if (shsurf->state.fullscreen) |
Rusty Lynch | 1084da5 | 2013-08-15 09:10:08 -0700 | [diff] [blame] | 1347 | return 0; |
Kristian Høgsberg | c85f1d4 | 2013-10-24 16:52:00 -0700 | [diff] [blame] | 1348 | if (shsurf->grabbed) |
| 1349 | return 0; |
Rusty Lynch | 1084da5 | 2013-08-15 09:10:08 -0700 | [diff] [blame] | 1350 | |
| 1351 | move = malloc(sizeof *move); |
| 1352 | if (!move) |
| 1353 | return -1; |
| 1354 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 1355 | move->dx = wl_fixed_from_double(shsurf->view->geometry.x) - |
Rusty Lynch | 1084da5 | 2013-08-15 09:10:08 -0700 | [diff] [blame] | 1356 | seat->touch->grab_x; |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 1357 | move->dy = wl_fixed_from_double(shsurf->view->geometry.y) - |
Rusty Lynch | 1084da5 | 2013-08-15 09:10:08 -0700 | [diff] [blame] | 1358 | seat->touch->grab_y; |
| 1359 | |
| 1360 | shell_touch_grab_start(&move->base, &touch_move_grab_interface, shsurf, |
| 1361 | seat->touch); |
| 1362 | |
| 1363 | return 0; |
| 1364 | } |
| 1365 | |
| 1366 | static void |
Kristian Høgsberg | 6848c25 | 2013-05-08 22:02:59 -0400 | [diff] [blame] | 1367 | noop_grab_focus(struct weston_pointer_grab *grab) |
Kristian Høgsberg | 9ddb826 | 2012-01-04 21:30:29 -0500 | [diff] [blame] | 1368 | { |
Kristian Høgsberg | 9ddb826 | 2012-01-04 21:30:29 -0500 | [diff] [blame] | 1369 | } |
| 1370 | |
| 1371 | static void |
Giulio Camuffo | 1959ab8 | 2013-11-14 23:42:52 +0100 | [diff] [blame] | 1372 | move_grab_motion(struct weston_pointer_grab *grab, uint32_t time, |
| 1373 | wl_fixed_t x, wl_fixed_t y) |
Kristian Høgsberg | 4cca349 | 2011-01-18 07:53:49 -0500 | [diff] [blame] | 1374 | { |
Kristian Høgsberg | 8334bc1 | 2012-01-03 10:29:47 -0500 | [diff] [blame] | 1375 | struct weston_move_grab *move = (struct weston_move_grab *) grab; |
Kristian Høgsberg | 02bbabb | 2013-05-06 22:15:05 -0400 | [diff] [blame] | 1376 | struct weston_pointer *pointer = grab->pointer; |
Ander Conselvan de Oliveira | fe0444a | 2012-04-04 17:48:05 +0300 | [diff] [blame] | 1377 | struct shell_surface *shsurf = move->base.shsurf; |
Giulio Camuffo | 1959ab8 | 2013-11-14 23:42:52 +0100 | [diff] [blame] | 1378 | int dx, dy; |
| 1379 | |
| 1380 | weston_pointer_move(pointer, x, y); |
| 1381 | dx = wl_fixed_to_int(pointer->x + move->dx); |
| 1382 | dy = wl_fixed_to_int(pointer->y + move->dy); |
Ander Conselvan de Oliveira | fe0444a | 2012-04-04 17:48:05 +0300 | [diff] [blame] | 1383 | |
| 1384 | if (!shsurf) |
| 1385 | return; |
| 1386 | |
Jason Ekstrand | 918f2dd | 2013-12-02 21:01:53 -0600 | [diff] [blame] | 1387 | weston_view_set_position(shsurf->view, dx, dy); |
Kristian Høgsberg | 4cca349 | 2011-01-18 07:53:49 -0500 | [diff] [blame] | 1388 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 1389 | weston_compositor_schedule_repaint(shsurf->surface->compositor); |
Kristian Høgsberg | 4cca349 | 2011-01-18 07:53:49 -0500 | [diff] [blame] | 1390 | } |
| 1391 | |
| 1392 | static void |
Kristian Høgsberg | 02bbabb | 2013-05-06 22:15:05 -0400 | [diff] [blame] | 1393 | move_grab_button(struct weston_pointer_grab *grab, |
Daniel Stone | 4dbadb1 | 2012-05-30 16:31:51 +0100 | [diff] [blame] | 1394 | uint32_t time, uint32_t button, uint32_t state_w) |
Kristian Høgsberg | 4cca349 | 2011-01-18 07:53:49 -0500 | [diff] [blame] | 1395 | { |
Ander Conselvan de Oliveira | fe0444a | 2012-04-04 17:48:05 +0300 | [diff] [blame] | 1396 | struct shell_grab *shell_grab = container_of(grab, struct shell_grab, |
| 1397 | grab); |
Kristian Høgsberg | 02bbabb | 2013-05-06 22:15:05 -0400 | [diff] [blame] | 1398 | struct weston_pointer *pointer = grab->pointer; |
Daniel Stone | 4dbadb1 | 2012-05-30 16:31:51 +0100 | [diff] [blame] | 1399 | enum wl_pointer_button_state state = state_w; |
Kristian Høgsberg | 4cca349 | 2011-01-18 07:53:49 -0500 | [diff] [blame] | 1400 | |
Daniel Stone | 4dbadb1 | 2012-05-30 16:31:51 +0100 | [diff] [blame] | 1401 | if (pointer->button_count == 0 && |
| 1402 | state == WL_POINTER_BUTTON_STATE_RELEASED) { |
Ander Conselvan de Oliveira | b9d2a0f | 2012-06-28 18:08:05 +0300 | [diff] [blame] | 1403 | shell_grab_end(shell_grab); |
Kristian Høgsberg | 9ddb826 | 2012-01-04 21:30:29 -0500 | [diff] [blame] | 1404 | free(grab); |
| 1405 | } |
Kristian Høgsberg | 4cca349 | 2011-01-18 07:53:49 -0500 | [diff] [blame] | 1406 | } |
| 1407 | |
Jonas Ådahl | 1ea343e | 2013-10-25 23:18:05 +0200 | [diff] [blame] | 1408 | static void |
| 1409 | move_grab_cancel(struct weston_pointer_grab *grab) |
| 1410 | { |
| 1411 | struct shell_grab *shell_grab = |
| 1412 | container_of(grab, struct shell_grab, grab); |
| 1413 | |
| 1414 | shell_grab_end(shell_grab); |
| 1415 | free(grab); |
| 1416 | } |
| 1417 | |
Kristian Høgsberg | 02bbabb | 2013-05-06 22:15:05 -0400 | [diff] [blame] | 1418 | static const struct weston_pointer_grab_interface move_grab_interface = { |
Kristian Høgsberg | 9ddb826 | 2012-01-04 21:30:29 -0500 | [diff] [blame] | 1419 | noop_grab_focus, |
Kristian Høgsberg | 4cca349 | 2011-01-18 07:53:49 -0500 | [diff] [blame] | 1420 | move_grab_motion, |
| 1421 | move_grab_button, |
Jonas Ådahl | 1ea343e | 2013-10-25 23:18:05 +0200 | [diff] [blame] | 1422 | move_grab_cancel, |
Kristian Høgsberg | 4cca349 | 2011-01-18 07:53:49 -0500 | [diff] [blame] | 1423 | }; |
| 1424 | |
Kristian Høgsberg | 9e31bff | 2012-08-01 00:08:07 -0400 | [diff] [blame] | 1425 | static int |
Kristian Høgsberg | e314875 | 2013-05-06 23:19:49 -0400 | [diff] [blame] | 1426 | surface_move(struct shell_surface *shsurf, struct weston_seat *seat) |
Kristian Høgsberg | 9e31bff | 2012-08-01 00:08:07 -0400 | [diff] [blame] | 1427 | { |
| 1428 | struct weston_move_grab *move; |
| 1429 | |
| 1430 | if (!shsurf) |
| 1431 | return -1; |
| 1432 | |
Kristian Høgsberg | c85f1d4 | 2013-10-24 16:52:00 -0700 | [diff] [blame] | 1433 | if (shsurf->grabbed) |
| 1434 | return 0; |
Rafael Antognolli | 03b1659 | 2013-12-03 15:35:42 -0200 | [diff] [blame] | 1435 | if (shsurf->state.fullscreen) |
Kristian Høgsberg | 9e31bff | 2012-08-01 00:08:07 -0400 | [diff] [blame] | 1436 | return 0; |
| 1437 | |
| 1438 | move = malloc(sizeof *move); |
| 1439 | if (!move) |
| 1440 | return -1; |
| 1441 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 1442 | move->dx = wl_fixed_from_double(shsurf->view->geometry.x) - |
Kristian Høgsberg | e314875 | 2013-05-06 23:19:49 -0400 | [diff] [blame] | 1443 | seat->pointer->grab_x; |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 1444 | move->dy = wl_fixed_from_double(shsurf->view->geometry.y) - |
Kristian Høgsberg | e314875 | 2013-05-06 23:19:49 -0400 | [diff] [blame] | 1445 | seat->pointer->grab_y; |
Kristian Høgsberg | 9e31bff | 2012-08-01 00:08:07 -0400 | [diff] [blame] | 1446 | |
| 1447 | shell_grab_start(&move->base, &move_grab_interface, shsurf, |
Kristian Høgsberg | e314875 | 2013-05-06 23:19:49 -0400 | [diff] [blame] | 1448 | seat->pointer, DESKTOP_SHELL_CURSOR_MOVE); |
Kristian Høgsberg | 9e31bff | 2012-08-01 00:08:07 -0400 | [diff] [blame] | 1449 | |
| 1450 | return 0; |
| 1451 | } |
| 1452 | |
| 1453 | static void |
Rafael Antognolli | e2a3455 | 2013-12-03 15:35:45 -0200 | [diff] [blame] | 1454 | common_surface_move(struct wl_resource *resource, |
| 1455 | struct wl_resource *seat_resource, uint32_t serial) |
Kristian Høgsberg | 9e31bff | 2012-08-01 00:08:07 -0400 | [diff] [blame] | 1456 | { |
Jason Ekstrand | 44a3863 | 2013-06-14 10:08:00 -0500 | [diff] [blame] | 1457 | struct weston_seat *seat = wl_resource_get_user_data(seat_resource); |
Jason Ekstrand | 651f00e | 2013-06-14 10:07:54 -0500 | [diff] [blame] | 1458 | struct shell_surface *shsurf = wl_resource_get_user_data(resource); |
Giulio Camuffo | 61da3fc | 2013-04-25 13:57:45 +0300 | [diff] [blame] | 1459 | struct weston_surface *surface; |
Kristian Høgsberg | 9e31bff | 2012-08-01 00:08:07 -0400 | [diff] [blame] | 1460 | |
Kristian Høgsberg | e1b655d | 2013-08-28 23:16:20 -0700 | [diff] [blame] | 1461 | if (seat->pointer && |
| 1462 | seat->pointer->button_count > 0 && |
| 1463 | seat->pointer->grab_serial == serial) { |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 1464 | surface = weston_surface_get_main_surface(seat->pointer->focus->surface); |
Rusty Lynch | 1084da5 | 2013-08-15 09:10:08 -0700 | [diff] [blame] | 1465 | if ((surface == shsurf->surface) && |
| 1466 | (surface_move(shsurf, seat) < 0)) |
| 1467 | wl_resource_post_no_memory(resource); |
Kristian Høgsberg | e1b655d | 2013-08-28 23:16:20 -0700 | [diff] [blame] | 1468 | } else if (seat->touch && |
| 1469 | seat->touch->grab_serial == serial) { |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 1470 | surface = weston_surface_get_main_surface(seat->touch->focus->surface); |
Rusty Lynch | 1084da5 | 2013-08-15 09:10:08 -0700 | [diff] [blame] | 1471 | if ((surface == shsurf->surface) && |
| 1472 | (surface_touch_move(shsurf, seat) < 0)) |
| 1473 | wl_resource_post_no_memory(resource); |
| 1474 | } |
Kristian Høgsberg | 9e31bff | 2012-08-01 00:08:07 -0400 | [diff] [blame] | 1475 | } |
| 1476 | |
Rafael Antognolli | e2a3455 | 2013-12-03 15:35:45 -0200 | [diff] [blame] | 1477 | static void |
| 1478 | shell_surface_move(struct wl_client *client, struct wl_resource *resource, |
| 1479 | struct wl_resource *seat_resource, uint32_t serial) |
| 1480 | { |
| 1481 | common_surface_move(resource, seat_resource, serial); |
| 1482 | } |
| 1483 | |
Kristian Høgsberg | 9e31bff | 2012-08-01 00:08:07 -0400 | [diff] [blame] | 1484 | struct weston_resize_grab { |
| 1485 | struct shell_grab base; |
| 1486 | uint32_t edges; |
| 1487 | int32_t width, height; |
| 1488 | }; |
| 1489 | |
| 1490 | static void |
Giulio Camuffo | 1959ab8 | 2013-11-14 23:42:52 +0100 | [diff] [blame] | 1491 | resize_grab_motion(struct weston_pointer_grab *grab, uint32_t time, |
| 1492 | wl_fixed_t x, wl_fixed_t y) |
Kristian Høgsberg | 9e31bff | 2012-08-01 00:08:07 -0400 | [diff] [blame] | 1493 | { |
| 1494 | struct weston_resize_grab *resize = (struct weston_resize_grab *) grab; |
Kristian Høgsberg | 02bbabb | 2013-05-06 22:15:05 -0400 | [diff] [blame] | 1495 | struct weston_pointer *pointer = grab->pointer; |
Kristian Høgsberg | 9e31bff | 2012-08-01 00:08:07 -0400 | [diff] [blame] | 1496 | struct shell_surface *shsurf = resize->base.shsurf; |
| 1497 | int32_t width, height; |
| 1498 | wl_fixed_t from_x, from_y; |
| 1499 | wl_fixed_t to_x, to_y; |
| 1500 | |
Giulio Camuffo | 1959ab8 | 2013-11-14 23:42:52 +0100 | [diff] [blame] | 1501 | weston_pointer_move(pointer, x, y); |
| 1502 | |
Kristian Høgsberg | 9e31bff | 2012-08-01 00:08:07 -0400 | [diff] [blame] | 1503 | if (!shsurf) |
| 1504 | return; |
| 1505 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 1506 | weston_view_from_global_fixed(shsurf->view, |
| 1507 | pointer->grab_x, pointer->grab_y, |
| 1508 | &from_x, &from_y); |
| 1509 | weston_view_from_global_fixed(shsurf->view, |
| 1510 | pointer->x, pointer->y, &to_x, &to_y); |
Kristian Høgsberg | 9e31bff | 2012-08-01 00:08:07 -0400 | [diff] [blame] | 1511 | |
| 1512 | width = resize->width; |
| 1513 | if (resize->edges & WL_SHELL_SURFACE_RESIZE_LEFT) { |
| 1514 | width += wl_fixed_to_int(from_x - to_x); |
| 1515 | } else if (resize->edges & WL_SHELL_SURFACE_RESIZE_RIGHT) { |
| 1516 | width += wl_fixed_to_int(to_x - from_x); |
| 1517 | } |
| 1518 | |
| 1519 | height = resize->height; |
| 1520 | if (resize->edges & WL_SHELL_SURFACE_RESIZE_TOP) { |
| 1521 | height += wl_fixed_to_int(from_y - to_y); |
| 1522 | } else if (resize->edges & WL_SHELL_SURFACE_RESIZE_BOTTOM) { |
| 1523 | height += wl_fixed_to_int(to_y - from_y); |
| 1524 | } |
| 1525 | |
| 1526 | shsurf->client->send_configure(shsurf->surface, |
| 1527 | resize->edges, width, height); |
| 1528 | } |
| 1529 | |
| 1530 | static void |
| 1531 | send_configure(struct weston_surface *surface, |
| 1532 | uint32_t edges, int32_t width, int32_t height) |
| 1533 | { |
| 1534 | struct shell_surface *shsurf = get_shell_surface(surface); |
| 1535 | |
Jason Ekstrand | 651f00e | 2013-06-14 10:07:54 -0500 | [diff] [blame] | 1536 | wl_shell_surface_send_configure(shsurf->resource, |
Kristian Høgsberg | 9e31bff | 2012-08-01 00:08:07 -0400 | [diff] [blame] | 1537 | edges, width, height); |
| 1538 | } |
| 1539 | |
| 1540 | static const struct weston_shell_client shell_client = { |
| 1541 | send_configure |
| 1542 | }; |
| 1543 | |
| 1544 | static void |
Kristian Høgsberg | 02bbabb | 2013-05-06 22:15:05 -0400 | [diff] [blame] | 1545 | resize_grab_button(struct weston_pointer_grab *grab, |
Kristian Høgsberg | 9e31bff | 2012-08-01 00:08:07 -0400 | [diff] [blame] | 1546 | uint32_t time, uint32_t button, uint32_t state_w) |
| 1547 | { |
| 1548 | struct weston_resize_grab *resize = (struct weston_resize_grab *) grab; |
Kristian Høgsberg | 02bbabb | 2013-05-06 22:15:05 -0400 | [diff] [blame] | 1549 | struct weston_pointer *pointer = grab->pointer; |
Kristian Høgsberg | 9e31bff | 2012-08-01 00:08:07 -0400 | [diff] [blame] | 1550 | enum wl_pointer_button_state state = state_w; |
| 1551 | |
| 1552 | if (pointer->button_count == 0 && |
| 1553 | state == WL_POINTER_BUTTON_STATE_RELEASED) { |
| 1554 | shell_grab_end(&resize->base); |
| 1555 | free(grab); |
| 1556 | } |
| 1557 | } |
| 1558 | |
Jonas Ådahl | 1ea343e | 2013-10-25 23:18:05 +0200 | [diff] [blame] | 1559 | static void |
| 1560 | resize_grab_cancel(struct weston_pointer_grab *grab) |
| 1561 | { |
| 1562 | struct weston_resize_grab *resize = (struct weston_resize_grab *) grab; |
| 1563 | |
| 1564 | shell_grab_end(&resize->base); |
| 1565 | free(grab); |
| 1566 | } |
| 1567 | |
Kristian Høgsberg | 02bbabb | 2013-05-06 22:15:05 -0400 | [diff] [blame] | 1568 | static const struct weston_pointer_grab_interface resize_grab_interface = { |
Kristian Høgsberg | 9e31bff | 2012-08-01 00:08:07 -0400 | [diff] [blame] | 1569 | noop_grab_focus, |
| 1570 | resize_grab_motion, |
| 1571 | resize_grab_button, |
Jonas Ådahl | 1ea343e | 2013-10-25 23:18:05 +0200 | [diff] [blame] | 1572 | resize_grab_cancel, |
Kristian Høgsberg | 9e31bff | 2012-08-01 00:08:07 -0400 | [diff] [blame] | 1573 | }; |
| 1574 | |
Giulio Camuffo | b836664 | 2013-04-25 13:57:46 +0300 | [diff] [blame] | 1575 | /* |
| 1576 | * Returns the bounding box of a surface and all its sub-surfaces, |
| 1577 | * in the surface coordinates system. */ |
| 1578 | static void |
| 1579 | surface_subsurfaces_boundingbox(struct weston_surface *surface, int32_t *x, |
| 1580 | int32_t *y, int32_t *w, int32_t *h) { |
| 1581 | pixman_region32_t region; |
| 1582 | pixman_box32_t *box; |
| 1583 | struct weston_subsurface *subsurface; |
| 1584 | |
| 1585 | pixman_region32_init_rect(®ion, 0, 0, |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 1586 | surface->width, |
| 1587 | surface->height); |
Giulio Camuffo | b836664 | 2013-04-25 13:57:46 +0300 | [diff] [blame] | 1588 | |
| 1589 | wl_list_for_each(subsurface, &surface->subsurface_list, parent_link) { |
| 1590 | pixman_region32_union_rect(®ion, ®ion, |
| 1591 | subsurface->position.x, |
| 1592 | subsurface->position.y, |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 1593 | subsurface->surface->width, |
| 1594 | subsurface->surface->height); |
Giulio Camuffo | b836664 | 2013-04-25 13:57:46 +0300 | [diff] [blame] | 1595 | } |
| 1596 | |
| 1597 | box = pixman_region32_extents(®ion); |
| 1598 | if (x) |
| 1599 | *x = box->x1; |
| 1600 | if (y) |
| 1601 | *y = box->y1; |
| 1602 | if (w) |
| 1603 | *w = box->x2 - box->x1; |
| 1604 | if (h) |
| 1605 | *h = box->y2 - box->y1; |
| 1606 | |
| 1607 | pixman_region32_fini(®ion); |
| 1608 | } |
| 1609 | |
Kristian Høgsberg | 9e31bff | 2012-08-01 00:08:07 -0400 | [diff] [blame] | 1610 | static int |
| 1611 | surface_resize(struct shell_surface *shsurf, |
Kristian Høgsberg | e314875 | 2013-05-06 23:19:49 -0400 | [diff] [blame] | 1612 | struct weston_seat *seat, uint32_t edges) |
Kristian Høgsberg | 9e31bff | 2012-08-01 00:08:07 -0400 | [diff] [blame] | 1613 | { |
| 1614 | struct weston_resize_grab *resize; |
| 1615 | |
Rafael Antognolli | 03b1659 | 2013-12-03 15:35:42 -0200 | [diff] [blame] | 1616 | if (shsurf->state.fullscreen || shsurf->state.maximized) |
Kristian Høgsberg | 9e31bff | 2012-08-01 00:08:07 -0400 | [diff] [blame] | 1617 | return 0; |
| 1618 | |
| 1619 | if (edges == 0 || edges > 15 || |
| 1620 | (edges & 3) == 3 || (edges & 12) == 12) |
| 1621 | return 0; |
| 1622 | |
| 1623 | resize = malloc(sizeof *resize); |
| 1624 | if (!resize) |
| 1625 | return -1; |
| 1626 | |
| 1627 | resize->edges = edges; |
Giulio Camuffo | b836664 | 2013-04-25 13:57:46 +0300 | [diff] [blame] | 1628 | surface_subsurfaces_boundingbox(shsurf->surface, NULL, NULL, |
| 1629 | &resize->width, &resize->height); |
Kristian Høgsberg | 9e31bff | 2012-08-01 00:08:07 -0400 | [diff] [blame] | 1630 | |
| 1631 | shell_grab_start(&resize->base, &resize_grab_interface, shsurf, |
Kristian Høgsberg | e314875 | 2013-05-06 23:19:49 -0400 | [diff] [blame] | 1632 | seat->pointer, edges); |
Kristian Høgsberg | 9e31bff | 2012-08-01 00:08:07 -0400 | [diff] [blame] | 1633 | |
| 1634 | return 0; |
| 1635 | } |
| 1636 | |
| 1637 | static void |
Rafael Antognolli | e2a3455 | 2013-12-03 15:35:45 -0200 | [diff] [blame] | 1638 | common_surface_resize(struct wl_resource *resource, |
| 1639 | struct wl_resource *seat_resource, uint32_t serial, |
| 1640 | uint32_t edges) |
Kristian Høgsberg | 9e31bff | 2012-08-01 00:08:07 -0400 | [diff] [blame] | 1641 | { |
Jason Ekstrand | 44a3863 | 2013-06-14 10:08:00 -0500 | [diff] [blame] | 1642 | struct weston_seat *seat = wl_resource_get_user_data(seat_resource); |
Jason Ekstrand | 651f00e | 2013-06-14 10:07:54 -0500 | [diff] [blame] | 1643 | struct shell_surface *shsurf = wl_resource_get_user_data(resource); |
Giulio Camuffo | 61da3fc | 2013-04-25 13:57:45 +0300 | [diff] [blame] | 1644 | struct weston_surface *surface; |
Kristian Høgsberg | 9e31bff | 2012-08-01 00:08:07 -0400 | [diff] [blame] | 1645 | |
Rafael Antognolli | 03b1659 | 2013-12-03 15:35:42 -0200 | [diff] [blame] | 1646 | if (shsurf->state.fullscreen) |
Kristian Høgsberg | 9e31bff | 2012-08-01 00:08:07 -0400 | [diff] [blame] | 1647 | return; |
| 1648 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 1649 | surface = weston_surface_get_main_surface(seat->pointer->focus->surface); |
Kristian Høgsberg | e314875 | 2013-05-06 23:19:49 -0400 | [diff] [blame] | 1650 | if (seat->pointer->button_count == 0 || |
| 1651 | seat->pointer->grab_serial != serial || |
Giulio Camuffo | 61da3fc | 2013-04-25 13:57:45 +0300 | [diff] [blame] | 1652 | surface != shsurf->surface) |
Kristian Høgsberg | 9e31bff | 2012-08-01 00:08:07 -0400 | [diff] [blame] | 1653 | return; |
| 1654 | |
Kristian Høgsberg | e314875 | 2013-05-06 23:19:49 -0400 | [diff] [blame] | 1655 | if (surface_resize(shsurf, seat, edges) < 0) |
Kristian Høgsberg | 9e31bff | 2012-08-01 00:08:07 -0400 | [diff] [blame] | 1656 | wl_resource_post_no_memory(resource); |
| 1657 | } |
| 1658 | |
Scott Moreau | c3e54eb | 2012-04-17 19:06:20 -0600 | [diff] [blame] | 1659 | static void |
Rafael Antognolli | e2a3455 | 2013-12-03 15:35:45 -0200 | [diff] [blame] | 1660 | shell_surface_resize(struct wl_client *client, struct wl_resource *resource, |
| 1661 | struct wl_resource *seat_resource, uint32_t serial, |
| 1662 | uint32_t edges) |
| 1663 | { |
| 1664 | common_surface_resize(resource, seat_resource, serial, edges); |
| 1665 | } |
| 1666 | |
| 1667 | static void |
Kristian Høgsberg | 6780073 | 2013-07-04 01:12:17 -0400 | [diff] [blame] | 1668 | end_busy_cursor(struct shell_surface *shsurf, struct weston_pointer *pointer); |
| 1669 | |
| 1670 | static void |
Kristian Høgsberg | 6848c25 | 2013-05-08 22:02:59 -0400 | [diff] [blame] | 1671 | busy_cursor_grab_focus(struct weston_pointer_grab *base) |
Scott Moreau | c3e54eb | 2012-04-17 19:06:20 -0600 | [diff] [blame] | 1672 | { |
Kristian Høgsberg | d56bd90 | 2012-06-05 09:58:51 -0400 | [diff] [blame] | 1673 | struct shell_grab *grab = (struct shell_grab *) base; |
Kristian Høgsberg | 6848c25 | 2013-05-08 22:02:59 -0400 | [diff] [blame] | 1674 | struct weston_pointer *pointer = base->pointer; |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 1675 | struct weston_view *view; |
Kristian Høgsberg | 6848c25 | 2013-05-08 22:02:59 -0400 | [diff] [blame] | 1676 | wl_fixed_t sx, sy; |
| 1677 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 1678 | view = weston_compositor_pick_view(pointer->seat->compositor, |
| 1679 | pointer->x, pointer->y, |
| 1680 | &sx, &sy); |
Scott Moreau | c3e54eb | 2012-04-17 19:06:20 -0600 | [diff] [blame] | 1681 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 1682 | if (!grab->shsurf || grab->shsurf->surface != view->surface) |
Kristian Høgsberg | 6780073 | 2013-07-04 01:12:17 -0400 | [diff] [blame] | 1683 | end_busy_cursor(grab->shsurf, pointer); |
Scott Moreau | c3e54eb | 2012-04-17 19:06:20 -0600 | [diff] [blame] | 1684 | } |
| 1685 | |
| 1686 | static void |
Giulio Camuffo | 1959ab8 | 2013-11-14 23:42:52 +0100 | [diff] [blame] | 1687 | busy_cursor_grab_motion(struct weston_pointer_grab *grab, uint32_t time, |
| 1688 | wl_fixed_t x, wl_fixed_t y) |
Scott Moreau | c3e54eb | 2012-04-17 19:06:20 -0600 | [diff] [blame] | 1689 | { |
Giulio Camuffo | 1959ab8 | 2013-11-14 23:42:52 +0100 | [diff] [blame] | 1690 | weston_pointer_move(grab->pointer, x, y); |
Kristian Høgsberg | d56bd90 | 2012-06-05 09:58:51 -0400 | [diff] [blame] | 1691 | } |
Scott Moreau | c3e54eb | 2012-04-17 19:06:20 -0600 | [diff] [blame] | 1692 | |
Kristian Høgsberg | d56bd90 | 2012-06-05 09:58:51 -0400 | [diff] [blame] | 1693 | static void |
Kristian Høgsberg | 02bbabb | 2013-05-06 22:15:05 -0400 | [diff] [blame] | 1694 | busy_cursor_grab_button(struct weston_pointer_grab *base, |
Kristian Høgsberg | d56bd90 | 2012-06-05 09:58:51 -0400 | [diff] [blame] | 1695 | uint32_t time, uint32_t button, uint32_t state) |
| 1696 | { |
Kristian Høgsberg | bbe9839 | 2012-08-01 00:20:21 -0400 | [diff] [blame] | 1697 | struct shell_grab *grab = (struct shell_grab *) base; |
Kristian Høgsberg | e122b7b | 2013-05-08 16:47:00 -0400 | [diff] [blame] | 1698 | struct shell_surface *shsurf = grab->shsurf; |
Kristian Høgsberg | e314875 | 2013-05-06 23:19:49 -0400 | [diff] [blame] | 1699 | struct weston_seat *seat = grab->grab.pointer->seat; |
Kristian Høgsberg | bbe9839 | 2012-08-01 00:20:21 -0400 | [diff] [blame] | 1700 | |
Kristian Høgsberg | bbe9839 | 2012-08-01 00:20:21 -0400 | [diff] [blame] | 1701 | if (shsurf && button == BTN_LEFT && state) { |
| 1702 | activate(shsurf->shell, shsurf->surface, seat); |
| 1703 | surface_move(shsurf, seat); |
Kristian Høgsberg | 0c36903 | 2013-02-14 21:31:44 -0500 | [diff] [blame] | 1704 | } else if (shsurf && button == BTN_RIGHT && state) { |
| 1705 | activate(shsurf->shell, shsurf->surface, seat); |
Kristian Høgsberg | e314875 | 2013-05-06 23:19:49 -0400 | [diff] [blame] | 1706 | surface_rotate(shsurf, seat); |
Kristian Høgsberg | bbe9839 | 2012-08-01 00:20:21 -0400 | [diff] [blame] | 1707 | } |
Kristian Høgsberg | d56bd90 | 2012-06-05 09:58:51 -0400 | [diff] [blame] | 1708 | } |
| 1709 | |
Jonas Ådahl | 1ea343e | 2013-10-25 23:18:05 +0200 | [diff] [blame] | 1710 | static void |
| 1711 | busy_cursor_grab_cancel(struct weston_pointer_grab *base) |
| 1712 | { |
| 1713 | struct shell_grab *grab = (struct shell_grab *) base; |
| 1714 | |
| 1715 | shell_grab_end(grab); |
| 1716 | free(grab); |
| 1717 | } |
| 1718 | |
Kristian Høgsberg | 02bbabb | 2013-05-06 22:15:05 -0400 | [diff] [blame] | 1719 | static const struct weston_pointer_grab_interface busy_cursor_grab_interface = { |
Kristian Høgsberg | d56bd90 | 2012-06-05 09:58:51 -0400 | [diff] [blame] | 1720 | busy_cursor_grab_focus, |
| 1721 | busy_cursor_grab_motion, |
| 1722 | busy_cursor_grab_button, |
Jonas Ådahl | 1ea343e | 2013-10-25 23:18:05 +0200 | [diff] [blame] | 1723 | busy_cursor_grab_cancel, |
Kristian Høgsberg | d56bd90 | 2012-06-05 09:58:51 -0400 | [diff] [blame] | 1724 | }; |
| 1725 | |
| 1726 | static void |
Kristian Høgsberg | 02bbabb | 2013-05-06 22:15:05 -0400 | [diff] [blame] | 1727 | set_busy_cursor(struct shell_surface *shsurf, struct weston_pointer *pointer) |
Kristian Høgsberg | d56bd90 | 2012-06-05 09:58:51 -0400 | [diff] [blame] | 1728 | { |
| 1729 | struct shell_grab *grab; |
Kristian Høgsberg | d56bd90 | 2012-06-05 09:58:51 -0400 | [diff] [blame] | 1730 | |
| 1731 | grab = malloc(sizeof *grab); |
| 1732 | if (!grab) |
Scott Moreau | c3e54eb | 2012-04-17 19:06:20 -0600 | [diff] [blame] | 1733 | return; |
| 1734 | |
Ander Conselvan de Oliveira | b9d2a0f | 2012-06-28 18:08:05 +0300 | [diff] [blame] | 1735 | shell_grab_start(grab, &busy_cursor_grab_interface, shsurf, pointer, |
| 1736 | DESKTOP_SHELL_CURSOR_BUSY); |
Kristian Høgsberg | d56bd90 | 2012-06-05 09:58:51 -0400 | [diff] [blame] | 1737 | } |
Scott Moreau | c3e54eb | 2012-04-17 19:06:20 -0600 | [diff] [blame] | 1738 | |
Kristian Høgsberg | d56bd90 | 2012-06-05 09:58:51 -0400 | [diff] [blame] | 1739 | static void |
Kristian Høgsberg | 02bbabb | 2013-05-06 22:15:05 -0400 | [diff] [blame] | 1740 | end_busy_cursor(struct shell_surface *shsurf, struct weston_pointer *pointer) |
Kristian Høgsberg | d56bd90 | 2012-06-05 09:58:51 -0400 | [diff] [blame] | 1741 | { |
| 1742 | struct shell_grab *grab = (struct shell_grab *) pointer->grab; |
| 1743 | |
Kristian Høgsberg | e122b7b | 2013-05-08 16:47:00 -0400 | [diff] [blame] | 1744 | if (grab->grab.interface == &busy_cursor_grab_interface && |
| 1745 | grab->shsurf == shsurf) { |
Ander Conselvan de Oliveira | b9d2a0f | 2012-06-28 18:08:05 +0300 | [diff] [blame] | 1746 | shell_grab_end(grab); |
Kristian Høgsberg | d56bd90 | 2012-06-05 09:58:51 -0400 | [diff] [blame] | 1747 | free(grab); |
Scott Moreau | c3e54eb | 2012-04-17 19:06:20 -0600 | [diff] [blame] | 1748 | } |
Scott Moreau | c3e54eb | 2012-04-17 19:06:20 -0600 | [diff] [blame] | 1749 | } |
| 1750 | |
Scott Moreau | 9521d5e | 2012-04-19 13:06:17 -0600 | [diff] [blame] | 1751 | static void |
| 1752 | ping_timer_destroy(struct shell_surface *shsurf) |
| 1753 | { |
| 1754 | if (!shsurf || !shsurf->ping_timer) |
| 1755 | return; |
| 1756 | |
| 1757 | if (shsurf->ping_timer->source) |
| 1758 | wl_event_source_remove(shsurf->ping_timer->source); |
| 1759 | |
| 1760 | free(shsurf->ping_timer); |
| 1761 | shsurf->ping_timer = NULL; |
| 1762 | } |
| 1763 | |
Kristian Høgsberg | 97d44aa | 2011-08-26 17:21:20 -0400 | [diff] [blame] | 1764 | static int |
Scott Moreau | ff1db4a | 2012-04-17 19:06:18 -0600 | [diff] [blame] | 1765 | ping_timeout_handler(void *data) |
| 1766 | { |
| 1767 | struct shell_surface *shsurf = data; |
Kristian Høgsberg | d56bd90 | 2012-06-05 09:58:51 -0400 | [diff] [blame] | 1768 | struct weston_seat *seat; |
Scott Moreau | ff1db4a | 2012-04-17 19:06:18 -0600 | [diff] [blame] | 1769 | |
Scott Moreau | 9521d5e | 2012-04-19 13:06:17 -0600 | [diff] [blame] | 1770 | /* Client is not responding */ |
| 1771 | shsurf->unresponsive = 1; |
Kristian Høgsberg | d56bd90 | 2012-06-05 09:58:51 -0400 | [diff] [blame] | 1772 | |
| 1773 | wl_list_for_each(seat, &shsurf->surface->compositor->seat_list, link) |
Emilio Pozuelo Monfort | 3d0fc76 | 2013-11-22 16:21:20 +0100 | [diff] [blame] | 1774 | if (seat->pointer->focus && |
| 1775 | seat->pointer->focus->surface == shsurf->surface) |
Kristian Høgsberg | e314875 | 2013-05-06 23:19:49 -0400 | [diff] [blame] | 1776 | set_busy_cursor(shsurf, seat->pointer); |
Scott Moreau | ff1db4a | 2012-04-17 19:06:18 -0600 | [diff] [blame] | 1777 | |
| 1778 | return 1; |
| 1779 | } |
| 1780 | |
| 1781 | static void |
| 1782 | ping_handler(struct weston_surface *surface, uint32_t serial) |
| 1783 | { |
Kristian Høgsberg | b71302e | 2012-05-10 12:28:35 -0400 | [diff] [blame] | 1784 | struct shell_surface *shsurf = get_shell_surface(surface); |
Scott Moreau | ff1db4a | 2012-04-17 19:06:18 -0600 | [diff] [blame] | 1785 | struct wl_event_loop *loop; |
Kristian Høgsberg | d56bd90 | 2012-06-05 09:58:51 -0400 | [diff] [blame] | 1786 | int ping_timeout = 200; |
Scott Moreau | ff1db4a | 2012-04-17 19:06:18 -0600 | [diff] [blame] | 1787 | |
| 1788 | if (!shsurf) |
| 1789 | return; |
Jason Ekstrand | 651f00e | 2013-06-14 10:07:54 -0500 | [diff] [blame] | 1790 | if (!shsurf->resource) |
Kristian Høgsberg | ca535c1 | 2012-04-21 23:20:07 -0400 | [diff] [blame] | 1791 | return; |
Scott Moreau | ff1db4a | 2012-04-17 19:06:18 -0600 | [diff] [blame] | 1792 | |
Ander Conselvan de Oliveira | eac9a46 | 2012-07-16 14:15:48 +0300 | [diff] [blame] | 1793 | if (shsurf->surface == shsurf->shell->grab_surface) |
| 1794 | return; |
| 1795 | |
Scott Moreau | ff1db4a | 2012-04-17 19:06:18 -0600 | [diff] [blame] | 1796 | if (!shsurf->ping_timer) { |
Ander Conselvan de Oliveira | fb98089 | 2012-04-27 13:55:55 +0300 | [diff] [blame] | 1797 | shsurf->ping_timer = malloc(sizeof *shsurf->ping_timer); |
Scott Moreau | ff1db4a | 2012-04-17 19:06:18 -0600 | [diff] [blame] | 1798 | if (!shsurf->ping_timer) |
| 1799 | return; |
| 1800 | |
| 1801 | shsurf->ping_timer->serial = serial; |
Scott Moreau | ff1db4a | 2012-04-17 19:06:18 -0600 | [diff] [blame] | 1802 | loop = wl_display_get_event_loop(surface->compositor->wl_display); |
| 1803 | shsurf->ping_timer->source = |
| 1804 | wl_event_loop_add_timer(loop, ping_timeout_handler, shsurf); |
| 1805 | wl_event_source_timer_update(shsurf->ping_timer->source, ping_timeout); |
| 1806 | |
Rafael Antognolli | e2a3455 | 2013-12-03 15:35:45 -0200 | [diff] [blame] | 1807 | if (shell_surface_is_wl_shell_surface(shsurf)) |
| 1808 | wl_shell_surface_send_ping(shsurf->resource, serial); |
| 1809 | else if (shell_surface_is_xdg_surface(shsurf)) |
| 1810 | xdg_surface_send_ping(shsurf->resource, serial); |
| 1811 | else if (shell_surface_is_xdg_popup(shsurf)) |
| 1812 | xdg_popup_send_ping(shsurf->resource, serial); |
Scott Moreau | ff1db4a | 2012-04-17 19:06:18 -0600 | [diff] [blame] | 1813 | } |
| 1814 | } |
| 1815 | |
| 1816 | static void |
Kristian Høgsberg | d56bd90 | 2012-06-05 09:58:51 -0400 | [diff] [blame] | 1817 | handle_pointer_focus(struct wl_listener *listener, void *data) |
| 1818 | { |
Kristian Høgsberg | 02bbabb | 2013-05-06 22:15:05 -0400 | [diff] [blame] | 1819 | struct weston_pointer *pointer = data; |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 1820 | struct weston_view *view = pointer->focus; |
Kristian Høgsberg | d56bd90 | 2012-06-05 09:58:51 -0400 | [diff] [blame] | 1821 | struct weston_compositor *compositor; |
| 1822 | struct shell_surface *shsurf; |
| 1823 | uint32_t serial; |
| 1824 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 1825 | if (!view) |
Kristian Høgsberg | d56bd90 | 2012-06-05 09:58:51 -0400 | [diff] [blame] | 1826 | return; |
| 1827 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 1828 | compositor = view->surface->compositor; |
| 1829 | shsurf = get_shell_surface(view->surface); |
Kristian Høgsberg | d56bd90 | 2012-06-05 09:58:51 -0400 | [diff] [blame] | 1830 | |
Pekka Paalanen | 4e1f2ff | 2012-06-06 16:59:45 +0300 | [diff] [blame] | 1831 | if (shsurf && shsurf->unresponsive) { |
Kristian Høgsberg | d56bd90 | 2012-06-05 09:58:51 -0400 | [diff] [blame] | 1832 | set_busy_cursor(shsurf, pointer); |
| 1833 | } else { |
| 1834 | serial = wl_display_next_serial(compositor->wl_display); |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 1835 | ping_handler(view->surface, serial); |
Kristian Høgsberg | d56bd90 | 2012-06-05 09:58:51 -0400 | [diff] [blame] | 1836 | } |
| 1837 | } |
| 1838 | |
| 1839 | static void |
Kristian Høgsberg | f4d2f23 | 2012-08-10 10:05:39 -0400 | [diff] [blame] | 1840 | create_pointer_focus_listener(struct weston_seat *seat) |
| 1841 | { |
| 1842 | struct wl_listener *listener; |
| 1843 | |
Kristian Høgsberg | e314875 | 2013-05-06 23:19:49 -0400 | [diff] [blame] | 1844 | if (!seat->pointer) |
Kristian Høgsberg | f4d2f23 | 2012-08-10 10:05:39 -0400 | [diff] [blame] | 1845 | return; |
| 1846 | |
| 1847 | listener = malloc(sizeof *listener); |
| 1848 | listener->notify = handle_pointer_focus; |
Kristian Høgsberg | e314875 | 2013-05-06 23:19:49 -0400 | [diff] [blame] | 1849 | wl_signal_add(&seat->pointer->focus_signal, listener); |
Kristian Høgsberg | f4d2f23 | 2012-08-10 10:05:39 -0400 | [diff] [blame] | 1850 | } |
| 1851 | |
| 1852 | static void |
Rafael Antognolli | e2a3455 | 2013-12-03 15:35:45 -0200 | [diff] [blame] | 1853 | xdg_surface_set_transient_for(struct wl_client *client, |
| 1854 | struct wl_resource *resource, |
| 1855 | struct wl_resource *parent_resource) |
Scott Moreau | ff1db4a | 2012-04-17 19:06:18 -0600 | [diff] [blame] | 1856 | { |
Jason Ekstrand | 651f00e | 2013-06-14 10:07:54 -0500 | [diff] [blame] | 1857 | struct shell_surface *shsurf = wl_resource_get_user_data(resource); |
Jasper St. Pierre | 8f180d4 | 2013-12-07 13:49:28 -0500 | [diff] [blame^] | 1858 | struct weston_surface *parent; |
| 1859 | |
| 1860 | if (parent_resource) |
| 1861 | parent = wl_resource_get_user_data(parent_resource); |
| 1862 | else |
| 1863 | parent = NULL; |
Rafael Antognolli | e2a3455 | 2013-12-03 15:35:45 -0200 | [diff] [blame] | 1864 | |
| 1865 | shell_surface_set_parent(shsurf, parent); |
| 1866 | } |
| 1867 | |
| 1868 | static void |
| 1869 | surface_pong(struct shell_surface *shsurf, uint32_t serial) |
| 1870 | { |
Kristian Høgsberg | d56bd90 | 2012-06-05 09:58:51 -0400 | [diff] [blame] | 1871 | struct weston_compositor *ec = shsurf->surface->compositor; |
Rafael Antognolli | e2a3455 | 2013-12-03 15:35:45 -0200 | [diff] [blame] | 1872 | struct weston_seat *seat; |
Scott Moreau | ff1db4a | 2012-04-17 19:06:18 -0600 | [diff] [blame] | 1873 | |
Kristian Høgsberg | 92374e1 | 2012-08-11 22:39:12 -0400 | [diff] [blame] | 1874 | if (shsurf->ping_timer == NULL) |
| 1875 | /* Just ignore unsolicited pong. */ |
| 1876 | return; |
| 1877 | |
Scott Moreau | ff1db4a | 2012-04-17 19:06:18 -0600 | [diff] [blame] | 1878 | if (shsurf->ping_timer->serial == serial) { |
Scott Moreau | ff1db4a | 2012-04-17 19:06:18 -0600 | [diff] [blame] | 1879 | shsurf->unresponsive = 0; |
Hardening | eb1e130 | 2013-05-17 18:07:41 +0200 | [diff] [blame] | 1880 | wl_list_for_each(seat, &ec->seat_list, link) { |
| 1881 | if(seat->pointer) |
| 1882 | end_busy_cursor(shsurf, seat->pointer); |
| 1883 | } |
Scott Moreau | 9521d5e | 2012-04-19 13:06:17 -0600 | [diff] [blame] | 1884 | ping_timer_destroy(shsurf); |
Scott Moreau | ff1db4a | 2012-04-17 19:06:18 -0600 | [diff] [blame] | 1885 | } |
| 1886 | } |
| 1887 | |
Kristian Høgsberg | e7afd91 | 2012-05-02 09:47:44 -0400 | [diff] [blame] | 1888 | static void |
Rafael Antognolli | e2a3455 | 2013-12-03 15:35:45 -0200 | [diff] [blame] | 1889 | shell_surface_pong(struct wl_client *client, struct wl_resource *resource, |
| 1890 | uint32_t serial) |
| 1891 | { |
| 1892 | struct shell_surface *shsurf = wl_resource_get_user_data(resource); |
| 1893 | |
| 1894 | surface_pong(shsurf, serial); |
| 1895 | |
| 1896 | } |
| 1897 | |
| 1898 | static void |
Giulio Camuffo | 62942ad | 2013-09-11 18:20:47 +0200 | [diff] [blame] | 1899 | set_title(struct shell_surface *shsurf, const char *title) |
| 1900 | { |
| 1901 | free(shsurf->title); |
| 1902 | shsurf->title = strdup(title); |
| 1903 | } |
| 1904 | |
| 1905 | static void |
Kristian Høgsberg | e7afd91 | 2012-05-02 09:47:44 -0400 | [diff] [blame] | 1906 | shell_surface_set_title(struct wl_client *client, |
| 1907 | struct wl_resource *resource, const char *title) |
| 1908 | { |
Jason Ekstrand | 651f00e | 2013-06-14 10:07:54 -0500 | [diff] [blame] | 1909 | struct shell_surface *shsurf = wl_resource_get_user_data(resource); |
Kristian Høgsberg | e7afd91 | 2012-05-02 09:47:44 -0400 | [diff] [blame] | 1910 | |
Giulio Camuffo | 62942ad | 2013-09-11 18:20:47 +0200 | [diff] [blame] | 1911 | set_title(shsurf, title); |
Kristian Høgsberg | e7afd91 | 2012-05-02 09:47:44 -0400 | [diff] [blame] | 1912 | } |
| 1913 | |
| 1914 | static void |
| 1915 | shell_surface_set_class(struct wl_client *client, |
| 1916 | struct wl_resource *resource, const char *class) |
| 1917 | { |
Jason Ekstrand | 651f00e | 2013-06-14 10:07:54 -0500 | [diff] [blame] | 1918 | struct shell_surface *shsurf = wl_resource_get_user_data(resource); |
Kristian Høgsberg | e7afd91 | 2012-05-02 09:47:44 -0400 | [diff] [blame] | 1919 | |
| 1920 | free(shsurf->class); |
| 1921 | shsurf->class = strdup(class); |
| 1922 | } |
| 1923 | |
Alex Wu | 4539b08 | 2012-03-01 12:57:46 +0800 | [diff] [blame] | 1924 | static void |
Alexander Larsson | f82b6ca | 2013-05-28 16:23:39 +0200 | [diff] [blame] | 1925 | restore_output_mode(struct weston_output *output) |
| 1926 | { |
Hardening | 57388e4 | 2013-09-18 23:56:36 +0200 | [diff] [blame] | 1927 | if (output->current_mode != output->original_mode || |
| 1928 | (int32_t)output->current_scale != output->original_scale) |
Alexander Larsson | f82b6ca | 2013-05-28 16:23:39 +0200 | [diff] [blame] | 1929 | weston_output_switch_mode(output, |
Hardening | 57388e4 | 2013-09-18 23:56:36 +0200 | [diff] [blame] | 1930 | output->original_mode, |
| 1931 | output->original_scale, |
| 1932 | WESTON_MODE_SWITCH_RESTORE_NATIVE); |
Alexander Larsson | f82b6ca | 2013-05-28 16:23:39 +0200 | [diff] [blame] | 1933 | } |
| 1934 | |
| 1935 | static void |
| 1936 | restore_all_output_modes(struct weston_compositor *compositor) |
| 1937 | { |
| 1938 | struct weston_output *output; |
| 1939 | |
| 1940 | wl_list_for_each(output, &compositor->output_list, link) |
| 1941 | restore_output_mode(output); |
| 1942 | } |
| 1943 | |
Philip Withnall | becb77e | 2013-11-25 18:01:30 +0000 | [diff] [blame] | 1944 | static int |
| 1945 | get_output_panel_height(struct desktop_shell *shell, |
| 1946 | struct weston_output *output) |
| 1947 | { |
| 1948 | struct weston_view *view; |
| 1949 | int panel_height = 0; |
| 1950 | |
| 1951 | if (!output) |
| 1952 | return 0; |
| 1953 | |
| 1954 | wl_list_for_each(view, &shell->panel_layer.view_list, layer_link) { |
| 1955 | if (view->surface->output == output) { |
Jason Ekstrand | 918f2dd | 2013-12-02 21:01:53 -0600 | [diff] [blame] | 1956 | panel_height = view->surface->height; |
Philip Withnall | becb77e | 2013-11-25 18:01:30 +0000 | [diff] [blame] | 1957 | break; |
| 1958 | } |
| 1959 | } |
| 1960 | |
| 1961 | return panel_height; |
| 1962 | } |
| 1963 | |
Philip Withnall | 07926d9 | 2013-11-25 18:01:40 +0000 | [diff] [blame] | 1964 | /* The surface will be inserted into the list immediately after the link |
| 1965 | * returned by this function (i.e. will be stacked immediately above the |
| 1966 | * returned link). */ |
| 1967 | static struct wl_list * |
| 1968 | shell_surface_calculate_layer_link (struct shell_surface *shsurf) |
| 1969 | { |
| 1970 | struct workspace *ws; |
| 1971 | |
| 1972 | switch (shsurf->type) { |
Philip Withnall | da704d9 | 2013-11-25 18:01:46 +0000 | [diff] [blame] | 1973 | case SHELL_SURFACE_POPUP: { |
| 1974 | /* Popups should go at the front of the workspace of their |
| 1975 | * parent surface, rather than just in front of the parent. This |
| 1976 | * fixes the situation where there are two top-level windows: |
| 1977 | * - Above |
| 1978 | * - Below |
| 1979 | * and a pop-up menu is created for 'Below'. We want: |
| 1980 | * - Popup |
| 1981 | * - Above |
| 1982 | * - Below |
| 1983 | * not: |
| 1984 | * - Above |
| 1985 | * - Popup |
| 1986 | * - Below |
| 1987 | */ |
| 1988 | struct shell_surface *parent_shsurf; |
| 1989 | |
| 1990 | parent_shsurf = get_shell_surface(shsurf->parent); |
| 1991 | if (parent_shsurf != NULL) |
| 1992 | return shell_surface_calculate_layer_link(parent_shsurf); |
| 1993 | |
| 1994 | break; |
| 1995 | } |
| 1996 | |
Rafael Antognolli | 03b1659 | 2013-12-03 15:35:42 -0200 | [diff] [blame] | 1997 | case SHELL_SURFACE_TOPLEVEL: { |
Rafael Antognolli | ed207b4 | 2013-12-03 15:35:43 -0200 | [diff] [blame] | 1998 | if (shsurf->state.fullscreen) { |
Rafael Antognolli | 03b1659 | 2013-12-03 15:35:42 -0200 | [diff] [blame] | 1999 | return &shsurf->shell->fullscreen_layer.view_list; |
Rafael Antognolli | ed207b4 | 2013-12-03 15:35:43 -0200 | [diff] [blame] | 2000 | } else if (shsurf->parent) { |
| 2001 | /* Move the surface to its parent layer so that |
| 2002 | * surfaces which are transient for fullscreen surfaces |
| 2003 | * don't get hidden by the fullscreen surfaces. |
| 2004 | * However, unlike popups, transient surfaces are |
| 2005 | * stacked in front of their parent but not in front of |
| 2006 | * other surfaces of the same type. */ |
| 2007 | struct weston_view *parent; |
| 2008 | |
| 2009 | /* TODO: Handle a parent with multiple views */ |
| 2010 | parent = get_default_view(shsurf->parent); |
| 2011 | if (parent) |
| 2012 | return parent->layer_link.prev; |
| 2013 | } |
Rafael Antognolli | 03b1659 | 2013-12-03 15:35:42 -0200 | [diff] [blame] | 2014 | break; |
| 2015 | } |
Philip Withnall | 07926d9 | 2013-11-25 18:01:40 +0000 | [diff] [blame] | 2016 | |
| 2017 | case SHELL_SURFACE_XWAYLAND: |
Kristian Høgsberg | 4804a30 | 2013-12-05 22:43:03 -0800 | [diff] [blame] | 2018 | return &shsurf->shell->fullscreen_layer.view_list; |
| 2019 | |
Philip Withnall | 07926d9 | 2013-11-25 18:01:40 +0000 | [diff] [blame] | 2020 | case SHELL_SURFACE_NONE: |
| 2021 | default: |
| 2022 | /* Go to the fallback, below. */ |
| 2023 | break; |
| 2024 | } |
| 2025 | |
| 2026 | /* Move the surface to a normal workspace layer so that surfaces |
| 2027 | * which were previously fullscreen or transient are no longer |
| 2028 | * rendered on top. */ |
| 2029 | ws = get_current_workspace(shsurf->shell); |
| 2030 | return &ws->layer.view_list; |
| 2031 | } |
| 2032 | |
Philip Withnall | 648a4dd | 2013-11-25 18:01:44 +0000 | [diff] [blame] | 2033 | static void |
| 2034 | shell_surface_update_child_surface_layers (struct shell_surface *shsurf) |
| 2035 | { |
| 2036 | struct shell_surface *child; |
| 2037 | |
| 2038 | /* Move the child layers to the same workspace as shsurf. They will be |
| 2039 | * stacked above shsurf. */ |
| 2040 | wl_list_for_each_reverse(child, &shsurf->children_list, children_link) { |
| 2041 | if (shsurf->view->layer_link.prev != &child->view->layer_link) { |
| 2042 | weston_view_geometry_dirty(child->view); |
| 2043 | wl_list_remove(&child->view->layer_link); |
| 2044 | wl_list_insert(shsurf->view->layer_link.prev, |
| 2045 | &child->view->layer_link); |
| 2046 | weston_view_geometry_dirty(child->view); |
| 2047 | weston_surface_damage(child->surface); |
| 2048 | |
| 2049 | /* Recurse. We don’t expect this to recurse very far (if |
| 2050 | * at all) because that would imply we have transient |
| 2051 | * (or popup) children of transient surfaces, which |
| 2052 | * would be unusual. */ |
| 2053 | shell_surface_update_child_surface_layers(child); |
| 2054 | } |
| 2055 | } |
| 2056 | } |
| 2057 | |
Philip Withnall | e1d75ae | 2013-11-25 18:01:41 +0000 | [diff] [blame] | 2058 | /* 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] | 2059 | * geometry to ensure the changes are redrawn. |
| 2060 | * |
| 2061 | * If any child surfaces exist and are mapped, ensure they’re in the same layer |
| 2062 | * as this surface. */ |
Philip Withnall | e1d75ae | 2013-11-25 18:01:41 +0000 | [diff] [blame] | 2063 | static void |
| 2064 | shell_surface_update_layer(struct shell_surface *shsurf) |
| 2065 | { |
| 2066 | struct wl_list *new_layer_link; |
| 2067 | |
| 2068 | new_layer_link = shell_surface_calculate_layer_link(shsurf); |
| 2069 | |
| 2070 | if (new_layer_link == &shsurf->view->layer_link) |
| 2071 | return; |
| 2072 | |
| 2073 | weston_view_geometry_dirty(shsurf->view); |
| 2074 | wl_list_remove(&shsurf->view->layer_link); |
| 2075 | wl_list_insert(new_layer_link, &shsurf->view->layer_link); |
| 2076 | weston_view_geometry_dirty(shsurf->view); |
| 2077 | weston_surface_damage(shsurf->surface); |
Philip Withnall | 648a4dd | 2013-11-25 18:01:44 +0000 | [diff] [blame] | 2078 | |
| 2079 | shell_surface_update_child_surface_layers(shsurf); |
Philip Withnall | e1d75ae | 2013-11-25 18:01:41 +0000 | [diff] [blame] | 2080 | } |
| 2081 | |
Alexander Larsson | f82b6ca | 2013-05-28 16:23:39 +0200 | [diff] [blame] | 2082 | static void |
Philip Withnall | dc4332f | 2013-11-25 18:01:38 +0000 | [diff] [blame] | 2083 | shell_surface_set_parent(struct shell_surface *shsurf, |
| 2084 | struct weston_surface *parent) |
| 2085 | { |
| 2086 | shsurf->parent = parent; |
Philip Withnall | 648a4dd | 2013-11-25 18:01:44 +0000 | [diff] [blame] | 2087 | |
| 2088 | wl_list_remove(&shsurf->children_link); |
| 2089 | wl_list_init(&shsurf->children_link); |
| 2090 | |
| 2091 | /* Insert into the parent surface’s child list. */ |
| 2092 | if (parent != NULL) { |
| 2093 | struct shell_surface *parent_shsurf = get_shell_surface(parent); |
| 2094 | if (parent_shsurf != NULL) |
| 2095 | wl_list_insert(&parent_shsurf->children_list, |
| 2096 | &shsurf->children_link); |
| 2097 | } |
Philip Withnall | dc4332f | 2013-11-25 18:01:38 +0000 | [diff] [blame] | 2098 | } |
| 2099 | |
| 2100 | static void |
Philip Withnall | 352e7ed | 2013-11-25 18:01:35 +0000 | [diff] [blame] | 2101 | shell_surface_set_output(struct shell_surface *shsurf, |
| 2102 | struct weston_output *output) |
| 2103 | { |
| 2104 | struct weston_surface *es = shsurf->surface; |
| 2105 | |
| 2106 | /* get the default output, if the client set it as NULL |
| 2107 | check whether the ouput is available */ |
| 2108 | if (output) |
| 2109 | shsurf->output = output; |
| 2110 | else if (es->output) |
| 2111 | shsurf->output = es->output; |
| 2112 | else |
| 2113 | shsurf->output = get_default_output(es->compositor); |
| 2114 | } |
| 2115 | |
| 2116 | static void |
Rafael Antognolli | 03b1659 | 2013-12-03 15:35:42 -0200 | [diff] [blame] | 2117 | surface_clear_next_states(struct shell_surface *shsurf) |
| 2118 | { |
| 2119 | shsurf->next_state.maximized = false; |
| 2120 | shsurf->next_state.fullscreen = false; |
| 2121 | |
| 2122 | if ((shsurf->next_state.maximized != shsurf->state.maximized) || |
| 2123 | (shsurf->next_state.fullscreen != shsurf->state.fullscreen)) |
| 2124 | shsurf->state_changed = true; |
| 2125 | } |
| 2126 | |
| 2127 | static void |
Philip Withnall | becb77e | 2013-11-25 18:01:30 +0000 | [diff] [blame] | 2128 | set_toplevel(struct shell_surface *shsurf) |
| 2129 | { |
Kristian Høgsberg | 41fbf6f | 2013-12-05 22:31:25 -0800 | [diff] [blame] | 2130 | shell_surface_set_parent(shsurf, NULL); |
| 2131 | surface_clear_next_states(shsurf); |
Kristian Høgsberg | c8f8dd8 | 2013-12-05 23:20:33 -0800 | [diff] [blame] | 2132 | shsurf->type = SHELL_SURFACE_TOPLEVEL; |
Philip Withnall | 648a4dd | 2013-11-25 18:01:44 +0000 | [diff] [blame] | 2133 | |
| 2134 | /* The layer_link is updated in set_surface_type(), |
| 2135 | * called from configure. */ |
Philip Withnall | becb77e | 2013-11-25 18:01:30 +0000 | [diff] [blame] | 2136 | } |
| 2137 | |
| 2138 | static void |
| 2139 | shell_surface_set_toplevel(struct wl_client *client, |
| 2140 | struct wl_resource *resource) |
| 2141 | { |
| 2142 | struct shell_surface *surface = wl_resource_get_user_data(resource); |
| 2143 | |
| 2144 | set_toplevel(surface); |
| 2145 | } |
| 2146 | |
| 2147 | static void |
| 2148 | set_transient(struct shell_surface *shsurf, |
| 2149 | struct weston_surface *parent, int x, int y, uint32_t flags) |
| 2150 | { |
Philip Withnall | dc4332f | 2013-11-25 18:01:38 +0000 | [diff] [blame] | 2151 | assert(parent != NULL); |
| 2152 | |
Philip Withnall | becb77e | 2013-11-25 18:01:30 +0000 | [diff] [blame] | 2153 | shsurf->transient.x = x; |
| 2154 | shsurf->transient.y = y; |
| 2155 | shsurf->transient.flags = flags; |
Philip Withnall | dc4332f | 2013-11-25 18:01:38 +0000 | [diff] [blame] | 2156 | |
Rafael Antognolli | ed207b4 | 2013-12-03 15:35:43 -0200 | [diff] [blame] | 2157 | shsurf->next_state.relative = true; |
Kristian Høgsberg | c8f8dd8 | 2013-12-05 23:20:33 -0800 | [diff] [blame] | 2158 | shsurf->type = SHELL_SURFACE_TOPLEVEL; |
Philip Withnall | 648a4dd | 2013-11-25 18:01:44 +0000 | [diff] [blame] | 2159 | |
| 2160 | /* The layer_link is updated in set_surface_type(), |
| 2161 | * called from configure. */ |
Philip Withnall | becb77e | 2013-11-25 18:01:30 +0000 | [diff] [blame] | 2162 | } |
| 2163 | |
| 2164 | static void |
| 2165 | shell_surface_set_transient(struct wl_client *client, |
| 2166 | struct wl_resource *resource, |
| 2167 | struct wl_resource *parent_resource, |
| 2168 | int x, int y, uint32_t flags) |
| 2169 | { |
| 2170 | struct shell_surface *shsurf = wl_resource_get_user_data(resource); |
| 2171 | struct weston_surface *parent = |
| 2172 | wl_resource_get_user_data(parent_resource); |
| 2173 | |
Rafael Antognolli | 4b99a40 | 2013-12-03 15:35:44 -0200 | [diff] [blame] | 2174 | shell_surface_set_parent(shsurf, parent); |
| 2175 | |
Rafael Antognolli | 03b1659 | 2013-12-03 15:35:42 -0200 | [diff] [blame] | 2176 | surface_clear_next_states(shsurf); |
Philip Withnall | becb77e | 2013-11-25 18:01:30 +0000 | [diff] [blame] | 2177 | set_transient(shsurf, parent, x, y, flags); |
| 2178 | } |
| 2179 | |
| 2180 | static void |
| 2181 | set_fullscreen(struct shell_surface *shsurf, |
| 2182 | uint32_t method, |
| 2183 | uint32_t framerate, |
| 2184 | struct weston_output *output) |
| 2185 | { |
Philip Withnall | 352e7ed | 2013-11-25 18:01:35 +0000 | [diff] [blame] | 2186 | shell_surface_set_output(shsurf, output); |
Philip Withnall | becb77e | 2013-11-25 18:01:30 +0000 | [diff] [blame] | 2187 | |
| 2188 | shsurf->fullscreen_output = shsurf->output; |
| 2189 | shsurf->fullscreen.type = method; |
| 2190 | shsurf->fullscreen.framerate = framerate; |
Philip Withnall | dc4332f | 2013-11-25 18:01:38 +0000 | [diff] [blame] | 2191 | |
Kristian Høgsberg | e960b3f | 2013-12-05 22:04:42 -0800 | [diff] [blame] | 2192 | shsurf->next_state.fullscreen = true; |
| 2193 | shsurf->state_changed = true; |
Kristian Høgsberg | c8f8dd8 | 2013-12-05 23:20:33 -0800 | [diff] [blame] | 2194 | shsurf->type = SHELL_SURFACE_TOPLEVEL; |
Philip Withnall | becb77e | 2013-11-25 18:01:30 +0000 | [diff] [blame] | 2195 | |
| 2196 | shsurf->client->send_configure(shsurf->surface, 0, |
| 2197 | shsurf->output->width, |
| 2198 | shsurf->output->height); |
Philip Withnall | 648a4dd | 2013-11-25 18:01:44 +0000 | [diff] [blame] | 2199 | |
| 2200 | /* The layer_link is updated in set_surface_type(), |
| 2201 | * called from configure. */ |
Philip Withnall | becb77e | 2013-11-25 18:01:30 +0000 | [diff] [blame] | 2202 | } |
| 2203 | |
| 2204 | static void |
| 2205 | unset_fullscreen(struct shell_surface *shsurf) |
Alex Wu | 4539b08 | 2012-03-01 12:57:46 +0800 | [diff] [blame] | 2206 | { |
Philip Withnall | f85fe84 | 2013-11-25 18:01:37 +0000 | [diff] [blame] | 2207 | /* Unset the fullscreen output, driver configuration and transforms. */ |
Alex Wu | bd3354b | 2012-04-17 17:20:49 +0800 | [diff] [blame] | 2208 | if (shsurf->fullscreen.type == WL_SHELL_SURFACE_FULLSCREEN_METHOD_DRIVER && |
| 2209 | shell_surface_is_top_fullscreen(shsurf)) { |
Alexander Larsson | f82b6ca | 2013-05-28 16:23:39 +0200 | [diff] [blame] | 2210 | restore_output_mode(shsurf->fullscreen_output); |
Alex Wu | bd3354b | 2012-04-17 17:20:49 +0800 | [diff] [blame] | 2211 | } |
Philip Withnall | f85fe84 | 2013-11-25 18:01:37 +0000 | [diff] [blame] | 2212 | shsurf->fullscreen_output = NULL; |
| 2213 | |
Alex Wu | 4539b08 | 2012-03-01 12:57:46 +0800 | [diff] [blame] | 2214 | shsurf->fullscreen.type = WL_SHELL_SURFACE_FULLSCREEN_METHOD_DEFAULT; |
| 2215 | shsurf->fullscreen.framerate = 0; |
Philip Withnall | f85fe84 | 2013-11-25 18:01:37 +0000 | [diff] [blame] | 2216 | |
Alex Wu | 4539b08 | 2012-03-01 12:57:46 +0800 | [diff] [blame] | 2217 | wl_list_remove(&shsurf->fullscreen.transform.link); |
| 2218 | wl_list_init(&shsurf->fullscreen.transform.link); |
Philip Withnall | f85fe84 | 2013-11-25 18:01:37 +0000 | [diff] [blame] | 2219 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 2220 | if (shsurf->fullscreen.black_view) |
| 2221 | weston_surface_destroy(shsurf->fullscreen.black_view->surface); |
| 2222 | shsurf->fullscreen.black_view = NULL; |
Philip Withnall | f85fe84 | 2013-11-25 18:01:37 +0000 | [diff] [blame] | 2223 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 2224 | weston_view_set_position(shsurf->view, |
| 2225 | shsurf->saved_x, shsurf->saved_y); |
Alex Wu | 7bcb8bd | 2012-04-27 09:07:24 +0800 | [diff] [blame] | 2226 | if (shsurf->saved_rotation_valid) { |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 2227 | wl_list_insert(&shsurf->view->geometry.transformation_list, |
Philip Withnall | becb77e | 2013-11-25 18:01:30 +0000 | [diff] [blame] | 2228 | &shsurf->rotation.transform.link); |
Alex Wu | 7bcb8bd | 2012-04-27 09:07:24 +0800 | [diff] [blame] | 2229 | shsurf->saved_rotation_valid = false; |
| 2230 | } |
Rafal Mielniczuk | 3e3862c | 2012-10-07 20:25:36 +0200 | [diff] [blame] | 2231 | |
Philip Withnall | e1d75ae | 2013-11-25 18:01:41 +0000 | [diff] [blame] | 2232 | /* Layer is updated in set_surface_type(). */ |
Alex Wu | 4539b08 | 2012-03-01 12:57:46 +0800 | [diff] [blame] | 2233 | } |
| 2234 | |
Rafal Mielniczuk | fffdcdd | 2013-03-11 19:26:54 +0100 | [diff] [blame] | 2235 | static void |
Philip Withnall | becb77e | 2013-11-25 18:01:30 +0000 | [diff] [blame] | 2236 | shell_surface_set_fullscreen(struct wl_client *client, |
| 2237 | struct wl_resource *resource, |
| 2238 | uint32_t method, |
| 2239 | uint32_t framerate, |
| 2240 | struct wl_resource *output_resource) |
| 2241 | { |
| 2242 | struct shell_surface *shsurf = wl_resource_get_user_data(resource); |
| 2243 | struct weston_output *output; |
| 2244 | |
| 2245 | if (output_resource) |
| 2246 | output = wl_resource_get_user_data(output_resource); |
| 2247 | else |
| 2248 | output = NULL; |
| 2249 | |
Rafael Antognolli | 4b99a40 | 2013-12-03 15:35:44 -0200 | [diff] [blame] | 2250 | shell_surface_set_parent(shsurf, NULL); |
| 2251 | |
Rafael Antognolli | 03b1659 | 2013-12-03 15:35:42 -0200 | [diff] [blame] | 2252 | surface_clear_next_states(shsurf); |
Philip Withnall | becb77e | 2013-11-25 18:01:30 +0000 | [diff] [blame] | 2253 | set_fullscreen(shsurf, method, framerate, output); |
| 2254 | } |
| 2255 | |
| 2256 | static void |
| 2257 | set_popup(struct shell_surface *shsurf, |
| 2258 | struct weston_surface *parent, |
| 2259 | struct weston_seat *seat, |
| 2260 | uint32_t serial, |
| 2261 | int32_t x, |
| 2262 | int32_t y) |
| 2263 | { |
Philip Withnall | dc4332f | 2013-11-25 18:01:38 +0000 | [diff] [blame] | 2264 | assert(parent != NULL); |
| 2265 | |
Philip Withnall | becb77e | 2013-11-25 18:01:30 +0000 | [diff] [blame] | 2266 | shsurf->popup.shseat = get_shell_seat(seat); |
| 2267 | shsurf->popup.serial = serial; |
| 2268 | shsurf->popup.x = x; |
| 2269 | shsurf->popup.y = y; |
Philip Withnall | dc4332f | 2013-11-25 18:01:38 +0000 | [diff] [blame] | 2270 | |
Kristian Høgsberg | c8f8dd8 | 2013-12-05 23:20:33 -0800 | [diff] [blame] | 2271 | shsurf->type = SHELL_SURFACE_POPUP; |
Philip Withnall | becb77e | 2013-11-25 18:01:30 +0000 | [diff] [blame] | 2272 | } |
| 2273 | |
| 2274 | static void |
| 2275 | shell_surface_set_popup(struct wl_client *client, |
| 2276 | struct wl_resource *resource, |
| 2277 | struct wl_resource *seat_resource, |
| 2278 | uint32_t serial, |
| 2279 | struct wl_resource *parent_resource, |
| 2280 | int32_t x, int32_t y, uint32_t flags) |
| 2281 | { |
| 2282 | struct shell_surface *shsurf = wl_resource_get_user_data(resource); |
Rafael Antognolli | 4b99a40 | 2013-12-03 15:35:44 -0200 | [diff] [blame] | 2283 | struct weston_surface *parent = |
| 2284 | wl_resource_get_user_data(parent_resource); |
| 2285 | |
| 2286 | shell_surface_set_parent(shsurf, parent); |
Philip Withnall | becb77e | 2013-11-25 18:01:30 +0000 | [diff] [blame] | 2287 | |
Rafael Antognolli | 03b1659 | 2013-12-03 15:35:42 -0200 | [diff] [blame] | 2288 | surface_clear_next_states(shsurf); |
Philip Withnall | becb77e | 2013-11-25 18:01:30 +0000 | [diff] [blame] | 2289 | set_popup(shsurf, |
Rafael Antognolli | 4b99a40 | 2013-12-03 15:35:44 -0200 | [diff] [blame] | 2290 | parent, |
Philip Withnall | becb77e | 2013-11-25 18:01:30 +0000 | [diff] [blame] | 2291 | wl_resource_get_user_data(seat_resource), |
| 2292 | serial, x, y); |
| 2293 | } |
| 2294 | |
| 2295 | static void |
| 2296 | set_maximized(struct shell_surface *shsurf, |
| 2297 | struct weston_output *output) |
| 2298 | { |
| 2299 | struct desktop_shell *shell; |
| 2300 | uint32_t edges = 0, panel_height = 0; |
Philip Withnall | becb77e | 2013-11-25 18:01:30 +0000 | [diff] [blame] | 2301 | |
Philip Withnall | 352e7ed | 2013-11-25 18:01:35 +0000 | [diff] [blame] | 2302 | shell_surface_set_output(shsurf, output); |
Philip Withnall | becb77e | 2013-11-25 18:01:30 +0000 | [diff] [blame] | 2303 | |
| 2304 | shell = shell_surface_get_shell(shsurf); |
| 2305 | panel_height = get_output_panel_height(shell, shsurf->output); |
| 2306 | edges = WL_SHELL_SURFACE_RESIZE_TOP | WL_SHELL_SURFACE_RESIZE_LEFT; |
| 2307 | |
| 2308 | shsurf->client->send_configure(shsurf->surface, edges, |
| 2309 | shsurf->output->width, |
| 2310 | shsurf->output->height - panel_height); |
| 2311 | |
Kristian Høgsberg | c2745b1 | 2013-12-05 22:00:40 -0800 | [diff] [blame] | 2312 | shsurf->next_state.maximized = true; |
| 2313 | shsurf->state_changed = true; |
Kristian Høgsberg | c8f8dd8 | 2013-12-05 23:20:33 -0800 | [diff] [blame] | 2314 | shsurf->type = SHELL_SURFACE_TOPLEVEL; |
Philip Withnall | becb77e | 2013-11-25 18:01:30 +0000 | [diff] [blame] | 2315 | } |
| 2316 | |
| 2317 | static void |
| 2318 | unset_maximized(struct shell_surface *shsurf) |
Rafal Mielniczuk | fffdcdd | 2013-03-11 19:26:54 +0100 | [diff] [blame] | 2319 | { |
Rafal Mielniczuk | fffdcdd | 2013-03-11 19:26:54 +0100 | [diff] [blame] | 2320 | /* undo all maximized things here */ |
| 2321 | shsurf->output = get_default_output(shsurf->surface->compositor); |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 2322 | weston_view_set_position(shsurf->view, |
| 2323 | shsurf->saved_x, |
| 2324 | shsurf->saved_y); |
Rafal Mielniczuk | fffdcdd | 2013-03-11 19:26:54 +0100 | [diff] [blame] | 2325 | |
| 2326 | if (shsurf->saved_rotation_valid) { |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 2327 | wl_list_insert(&shsurf->view->geometry.transformation_list, |
| 2328 | &shsurf->rotation.transform.link); |
Rafal Mielniczuk | fffdcdd | 2013-03-11 19:26:54 +0100 | [diff] [blame] | 2329 | shsurf->saved_rotation_valid = false; |
| 2330 | } |
| 2331 | |
Philip Withnall | e1d75ae | 2013-11-25 18:01:41 +0000 | [diff] [blame] | 2332 | /* Layer is updated in set_surface_type(). */ |
Rafal Mielniczuk | fffdcdd | 2013-03-11 19:26:54 +0100 | [diff] [blame] | 2333 | } |
| 2334 | |
Philip Withnall | becb77e | 2013-11-25 18:01:30 +0000 | [diff] [blame] | 2335 | static void |
| 2336 | shell_surface_set_maximized(struct wl_client *client, |
| 2337 | struct wl_resource *resource, |
| 2338 | struct wl_resource *output_resource) |
| 2339 | { |
| 2340 | struct shell_surface *shsurf = wl_resource_get_user_data(resource); |
| 2341 | struct weston_output *output; |
| 2342 | |
| 2343 | if (output_resource) |
| 2344 | output = wl_resource_get_user_data(output_resource); |
| 2345 | else |
| 2346 | output = NULL; |
| 2347 | |
Rafael Antognolli | 4b99a40 | 2013-12-03 15:35:44 -0200 | [diff] [blame] | 2348 | shell_surface_set_parent(shsurf, NULL); |
| 2349 | |
Rafael Antognolli | 03b1659 | 2013-12-03 15:35:42 -0200 | [diff] [blame] | 2350 | surface_clear_next_states(shsurf); |
Philip Withnall | becb77e | 2013-11-25 18:01:30 +0000 | [diff] [blame] | 2351 | set_maximized(shsurf, output); |
| 2352 | } |
| 2353 | |
Philip Withnall | e1d75ae | 2013-11-25 18:01:41 +0000 | [diff] [blame] | 2354 | /* This is only ever called from set_surface_type(), so there’s no need to |
| 2355 | * update layer_links here, since they’ll be updated when we return. */ |
Pekka Paalanen | 9826223 | 2011-12-01 10:42:22 +0200 | [diff] [blame] | 2356 | static int |
Philip Withnall | becb77e | 2013-11-25 18:01:30 +0000 | [diff] [blame] | 2357 | reset_surface_type(struct shell_surface *surface) |
Pekka Paalanen | 9826223 | 2011-12-01 10:42:22 +0200 | [diff] [blame] | 2358 | { |
Rafael Antognolli | 03b1659 | 2013-12-03 15:35:42 -0200 | [diff] [blame] | 2359 | if (surface->state.fullscreen) |
Philip Withnall | becb77e | 2013-11-25 18:01:30 +0000 | [diff] [blame] | 2360 | unset_fullscreen(surface); |
Rafael Antognolli | 03b1659 | 2013-12-03 15:35:42 -0200 | [diff] [blame] | 2361 | if (surface->state.maximized) |
Philip Withnall | becb77e | 2013-11-25 18:01:30 +0000 | [diff] [blame] | 2362 | unset_maximized(surface); |
Pekka Paalanen | 9826223 | 2011-12-01 10:42:22 +0200 | [diff] [blame] | 2363 | |
Pekka Paalanen | 9826223 | 2011-12-01 10:42:22 +0200 | [diff] [blame] | 2364 | return 0; |
| 2365 | } |
| 2366 | |
Kristian Høgsberg | 4cca349 | 2011-01-18 07:53:49 -0500 | [diff] [blame] | 2367 | static void |
Rafael Antognolli | 03b1659 | 2013-12-03 15:35:42 -0200 | [diff] [blame] | 2368 | set_full_output(struct shell_surface *shsurf) |
| 2369 | { |
| 2370 | shsurf->saved_x = shsurf->view->geometry.x; |
| 2371 | shsurf->saved_y = shsurf->view->geometry.y; |
Rafael Antognolli | 3c4e3f7 | 2013-12-03 15:35:46 -0200 | [diff] [blame] | 2372 | shsurf->saved_width = shsurf->surface->width; |
| 2373 | shsurf->saved_height = shsurf->surface->height; |
| 2374 | shsurf->saved_size_valid = true; |
Rafael Antognolli | 03b1659 | 2013-12-03 15:35:42 -0200 | [diff] [blame] | 2375 | shsurf->saved_position_valid = true; |
| 2376 | |
| 2377 | if (!wl_list_empty(&shsurf->rotation.transform.link)) { |
| 2378 | wl_list_remove(&shsurf->rotation.transform.link); |
| 2379 | wl_list_init(&shsurf->rotation.transform.link); |
| 2380 | weston_view_geometry_dirty(shsurf->view); |
| 2381 | shsurf->saved_rotation_valid = true; |
| 2382 | } |
| 2383 | } |
| 2384 | |
| 2385 | static void |
Kristian Høgsberg | 7f366e7 | 2012-04-27 17:20:01 -0400 | [diff] [blame] | 2386 | set_surface_type(struct shell_surface *shsurf) |
| 2387 | { |
Kristian Høgsberg | 8150b19 | 2012-06-27 10:22:58 -0400 | [diff] [blame] | 2388 | struct weston_surface *pes = shsurf->parent; |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 2389 | struct weston_view *pev = get_default_view(pes); |
Kristian Høgsberg | 7f366e7 | 2012-04-27 17:20:01 -0400 | [diff] [blame] | 2390 | |
Philip Withnall | becb77e | 2013-11-25 18:01:30 +0000 | [diff] [blame] | 2391 | reset_surface_type(shsurf); |
Kristian Høgsberg | 7f366e7 | 2012-04-27 17:20:01 -0400 | [diff] [blame] | 2392 | |
Rafael Antognolli | 03b1659 | 2013-12-03 15:35:42 -0200 | [diff] [blame] | 2393 | shsurf->state = shsurf->next_state; |
Rafael Antognolli | 03b1659 | 2013-12-03 15:35:42 -0200 | [diff] [blame] | 2394 | shsurf->state_changed = false; |
Kristian Høgsberg | 7f366e7 | 2012-04-27 17:20:01 -0400 | [diff] [blame] | 2395 | |
| 2396 | switch (shsurf->type) { |
| 2397 | case SHELL_SURFACE_TOPLEVEL: |
Rafael Antognolli | ed207b4 | 2013-12-03 15:35:43 -0200 | [diff] [blame] | 2398 | if (shsurf->state.maximized || shsurf->state.fullscreen) { |
Rafael Antognolli | 03b1659 | 2013-12-03 15:35:42 -0200 | [diff] [blame] | 2399 | set_full_output(shsurf); |
Rafael Antognolli | ed207b4 | 2013-12-03 15:35:43 -0200 | [diff] [blame] | 2400 | } else if (shsurf->state.relative && pev) { |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 2401 | weston_view_set_position(shsurf->view, |
| 2402 | pev->geometry.x + shsurf->transient.x, |
| 2403 | pev->geometry.y + shsurf->transient.y); |
Rafael Antognolli | ed207b4 | 2013-12-03 15:35:43 -0200 | [diff] [blame] | 2404 | } |
Rafael Antognolli | 44a3162 | 2013-12-04 18:37:16 -0200 | [diff] [blame] | 2405 | break; |
Kristian Høgsberg | 7f366e7 | 2012-04-27 17:20:01 -0400 | [diff] [blame] | 2406 | |
Tiago Vignatti | fb2adba | 2013-06-12 15:43:21 -0300 | [diff] [blame] | 2407 | case SHELL_SURFACE_XWAYLAND: |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 2408 | weston_view_set_position(shsurf->view, shsurf->transient.x, |
| 2409 | shsurf->transient.y); |
Tiago Vignatti | fb2adba | 2013-06-12 15:43:21 -0300 | [diff] [blame] | 2410 | break; |
| 2411 | |
Philip Withnall | 0f640e2 | 2013-11-25 18:01:31 +0000 | [diff] [blame] | 2412 | case SHELL_SURFACE_POPUP: |
| 2413 | case SHELL_SURFACE_NONE: |
Kristian Høgsberg | 7f366e7 | 2012-04-27 17:20:01 -0400 | [diff] [blame] | 2414 | default: |
| 2415 | break; |
| 2416 | } |
Philip Withnall | e1d75ae | 2013-11-25 18:01:41 +0000 | [diff] [blame] | 2417 | |
| 2418 | /* Update the surface’s layer. */ |
| 2419 | shell_surface_update_layer(shsurf); |
Kristian Høgsberg | 7f366e7 | 2012-04-27 17:20:01 -0400 | [diff] [blame] | 2420 | } |
| 2421 | |
Tiago Vignatti | be14326 | 2012-04-16 17:31:41 +0300 | [diff] [blame] | 2422 | static struct desktop_shell * |
Juan Zhao | 96879df | 2012-02-07 08:45:41 +0800 | [diff] [blame] | 2423 | shell_surface_get_shell(struct shell_surface *shsurf) |
Pekka Paalanen | af0e34c | 2011-12-02 10:59:17 +0200 | [diff] [blame] | 2424 | { |
Kristian Høgsberg | 02e79dc | 2012-04-12 09:55:26 -0400 | [diff] [blame] | 2425 | return shsurf->shell; |
Juan Zhao | 96879df | 2012-02-07 08:45:41 +0800 | [diff] [blame] | 2426 | } |
| 2427 | |
Alex Wu | 2185843 | 2012-04-01 20:13:08 +0800 | [diff] [blame] | 2428 | static void |
Jason Ekstrand | 918f2dd | 2013-12-02 21:01:53 -0600 | [diff] [blame] | 2429 | 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] | 2430 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 2431 | static struct weston_view * |
Alex Wu | 4539b08 | 2012-03-01 12:57:46 +0800 | [diff] [blame] | 2432 | create_black_surface(struct weston_compositor *ec, |
Alex Wu | 2185843 | 2012-04-01 20:13:08 +0800 | [diff] [blame] | 2433 | struct weston_surface *fs_surface, |
John Kåre Alsaker | 490d02a | 2012-09-30 02:57:21 +0200 | [diff] [blame] | 2434 | float x, float y, int w, int h) |
Alex Wu | 4539b08 | 2012-03-01 12:57:46 +0800 | [diff] [blame] | 2435 | { |
| 2436 | struct weston_surface *surface = NULL; |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 2437 | struct weston_view *view; |
Alex Wu | 4539b08 | 2012-03-01 12:57:46 +0800 | [diff] [blame] | 2438 | |
| 2439 | surface = weston_surface_create(ec); |
| 2440 | if (surface == NULL) { |
Martin Minarik | 6d11836 | 2012-06-07 18:01:59 +0200 | [diff] [blame] | 2441 | weston_log("no memory\n"); |
Alex Wu | 4539b08 | 2012-03-01 12:57:46 +0800 | [diff] [blame] | 2442 | return NULL; |
| 2443 | } |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 2444 | view = weston_view_create(surface); |
| 2445 | if (surface == NULL) { |
| 2446 | weston_log("no memory\n"); |
| 2447 | weston_surface_destroy(surface); |
| 2448 | return NULL; |
| 2449 | } |
Alex Wu | 4539b08 | 2012-03-01 12:57:46 +0800 | [diff] [blame] | 2450 | |
Alex Wu | 2185843 | 2012-04-01 20:13:08 +0800 | [diff] [blame] | 2451 | surface->configure = black_surface_configure; |
Giulio Camuffo | 7fe01b1 | 2013-03-28 18:02:42 +0100 | [diff] [blame] | 2452 | surface->configure_private = fs_surface; |
Alex Wu | 4539b08 | 2012-03-01 12:57:46 +0800 | [diff] [blame] | 2453 | weston_surface_set_color(surface, 0.0, 0.0, 0.0, 1); |
Pekka Paalanen | 71f6f3b | 2012-10-10 12:49:26 +0300 | [diff] [blame] | 2454 | pixman_region32_fini(&surface->opaque); |
Kristian Høgsberg | 61f00f5 | 2012-08-03 16:31:36 -0400 | [diff] [blame] | 2455 | pixman_region32_init_rect(&surface->opaque, 0, 0, w, h); |
Jonas Ådahl | 33619a4 | 2013-01-15 21:25:55 +0100 | [diff] [blame] | 2456 | pixman_region32_fini(&surface->input); |
| 2457 | pixman_region32_init_rect(&surface->input, 0, 0, w, h); |
Jason Ekstrand | 918f2dd | 2013-12-02 21:01:53 -0600 | [diff] [blame] | 2458 | |
Xiong Zhang | becf5a3 | 2013-11-29 11:18:14 +0800 | [diff] [blame] | 2459 | surface->width = w; |
| 2460 | surface->height = h; |
Jason Ekstrand | 918f2dd | 2013-12-02 21:01:53 -0600 | [diff] [blame] | 2461 | weston_view_set_position(view, x, y); |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 2462 | |
| 2463 | return view; |
Alex Wu | 4539b08 | 2012-03-01 12:57:46 +0800 | [diff] [blame] | 2464 | } |
| 2465 | |
Philip Withnall | ed8f1a9 | 2013-11-25 18:01:43 +0000 | [diff] [blame] | 2466 | static void |
| 2467 | shell_ensure_fullscreen_black_view(struct shell_surface *shsurf) |
| 2468 | { |
| 2469 | struct weston_output *output = shsurf->fullscreen_output; |
| 2470 | |
Rafael Antognolli | 03b1659 | 2013-12-03 15:35:42 -0200 | [diff] [blame] | 2471 | assert(shsurf->state.fullscreen); |
Philip Withnall | ed8f1a9 | 2013-11-25 18:01:43 +0000 | [diff] [blame] | 2472 | |
| 2473 | if (!shsurf->fullscreen.black_view) |
| 2474 | shsurf->fullscreen.black_view = |
| 2475 | create_black_surface(shsurf->surface->compositor, |
| 2476 | shsurf->surface, |
| 2477 | output->x, output->y, |
| 2478 | output->width, |
| 2479 | output->height); |
| 2480 | |
| 2481 | weston_view_geometry_dirty(shsurf->fullscreen.black_view); |
| 2482 | wl_list_remove(&shsurf->fullscreen.black_view->layer_link); |
| 2483 | wl_list_insert(&shsurf->view->layer_link, |
| 2484 | &shsurf->fullscreen.black_view->layer_link); |
| 2485 | weston_view_geometry_dirty(shsurf->fullscreen.black_view); |
| 2486 | weston_surface_damage(shsurf->surface); |
| 2487 | } |
| 2488 | |
Alex Wu | 4539b08 | 2012-03-01 12:57:46 +0800 | [diff] [blame] | 2489 | /* Create black surface and append it to the associated fullscreen surface. |
| 2490 | * Handle size dismatch and positioning according to the method. */ |
| 2491 | static void |
| 2492 | shell_configure_fullscreen(struct shell_surface *shsurf) |
| 2493 | { |
| 2494 | struct weston_output *output = shsurf->fullscreen_output; |
| 2495 | struct weston_surface *surface = shsurf->surface; |
| 2496 | struct weston_matrix *matrix; |
Kristian Høgsberg | 240dfeb | 2012-07-12 12:32:31 -0400 | [diff] [blame] | 2497 | float scale, output_aspect, surface_aspect, x, y; |
Giulio Camuffo | b836664 | 2013-04-25 13:57:46 +0300 | [diff] [blame] | 2498 | int32_t surf_x, surf_y, surf_width, surf_height; |
Alex Wu | 4539b08 | 2012-03-01 12:57:46 +0800 | [diff] [blame] | 2499 | |
Alexander Larsson | f82b6ca | 2013-05-28 16:23:39 +0200 | [diff] [blame] | 2500 | if (shsurf->fullscreen.type != WL_SHELL_SURFACE_FULLSCREEN_METHOD_DRIVER) |
| 2501 | restore_output_mode(output); |
| 2502 | |
Philip Withnall | ed8f1a9 | 2013-11-25 18:01:43 +0000 | [diff] [blame] | 2503 | shell_ensure_fullscreen_black_view(shsurf); |
Alex Wu | 4539b08 | 2012-03-01 12:57:46 +0800 | [diff] [blame] | 2504 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 2505 | surface_subsurfaces_boundingbox(shsurf->surface, &surf_x, &surf_y, |
Giulio Camuffo | b836664 | 2013-04-25 13:57:46 +0300 | [diff] [blame] | 2506 | &surf_width, &surf_height); |
| 2507 | |
Alex Wu | 4539b08 | 2012-03-01 12:57:46 +0800 | [diff] [blame] | 2508 | switch (shsurf->fullscreen.type) { |
| 2509 | case WL_SHELL_SURFACE_FULLSCREEN_METHOD_DEFAULT: |
Pekka Paalanen | de685b8 | 2012-12-04 15:58:12 +0200 | [diff] [blame] | 2510 | if (surface->buffer_ref.buffer) |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 2511 | center_on_output(shsurf->view, shsurf->fullscreen_output); |
Alex Wu | 4539b08 | 2012-03-01 12:57:46 +0800 | [diff] [blame] | 2512 | break; |
| 2513 | case WL_SHELL_SURFACE_FULLSCREEN_METHOD_SCALE: |
Rob Bradford | 9f3dd15 | 2013-02-12 11:53:47 +0000 | [diff] [blame] | 2514 | /* 1:1 mapping between surface and output dimensions */ |
Giulio Camuffo | b836664 | 2013-04-25 13:57:46 +0300 | [diff] [blame] | 2515 | if (output->width == surf_width && |
| 2516 | output->height == surf_height) { |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 2517 | weston_view_set_position(shsurf->view, |
| 2518 | output->x - surf_x, |
| 2519 | output->y - surf_y); |
Rob Bradford | 9f3dd15 | 2013-02-12 11:53:47 +0000 | [diff] [blame] | 2520 | break; |
| 2521 | } |
| 2522 | |
Alex Wu | 4539b08 | 2012-03-01 12:57:46 +0800 | [diff] [blame] | 2523 | matrix = &shsurf->fullscreen.transform.matrix; |
| 2524 | weston_matrix_init(matrix); |
Kristian Høgsberg | 240dfeb | 2012-07-12 12:32:31 -0400 | [diff] [blame] | 2525 | |
Scott Moreau | 1bad5db | 2012-08-18 01:04:05 -0600 | [diff] [blame] | 2526 | output_aspect = (float) output->width / |
| 2527 | (float) output->height; |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 2528 | /* XXX: Use surf_width and surf_height here? */ |
| 2529 | surface_aspect = (float) surface->width / |
| 2530 | (float) surface->height; |
Kristian Høgsberg | 240dfeb | 2012-07-12 12:32:31 -0400 | [diff] [blame] | 2531 | if (output_aspect < surface_aspect) |
Scott Moreau | 1bad5db | 2012-08-18 01:04:05 -0600 | [diff] [blame] | 2532 | scale = (float) output->width / |
Giulio Camuffo | b836664 | 2013-04-25 13:57:46 +0300 | [diff] [blame] | 2533 | (float) surf_width; |
Kristian Høgsberg | 240dfeb | 2012-07-12 12:32:31 -0400 | [diff] [blame] | 2534 | else |
Scott Moreau | 1bad5db | 2012-08-18 01:04:05 -0600 | [diff] [blame] | 2535 | scale = (float) output->height / |
Giulio Camuffo | b836664 | 2013-04-25 13:57:46 +0300 | [diff] [blame] | 2536 | (float) surf_height; |
Kristian Høgsberg | 240dfeb | 2012-07-12 12:32:31 -0400 | [diff] [blame] | 2537 | |
Alex Wu | 4539b08 | 2012-03-01 12:57:46 +0800 | [diff] [blame] | 2538 | weston_matrix_scale(matrix, scale, scale, 1); |
| 2539 | wl_list_remove(&shsurf->fullscreen.transform.link); |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 2540 | wl_list_insert(&shsurf->view->geometry.transformation_list, |
Alex Wu | 4539b08 | 2012-03-01 12:57:46 +0800 | [diff] [blame] | 2541 | &shsurf->fullscreen.transform.link); |
Giulio Camuffo | b836664 | 2013-04-25 13:57:46 +0300 | [diff] [blame] | 2542 | x = output->x + (output->width - surf_width * scale) / 2 - surf_x; |
| 2543 | y = output->y + (output->height - surf_height * scale) / 2 - surf_y; |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 2544 | weston_view_set_position(shsurf->view, x, y); |
Kristian Høgsberg | 240dfeb | 2012-07-12 12:32:31 -0400 | [diff] [blame] | 2545 | |
Alex Wu | 4539b08 | 2012-03-01 12:57:46 +0800 | [diff] [blame] | 2546 | break; |
| 2547 | case WL_SHELL_SURFACE_FULLSCREEN_METHOD_DRIVER: |
Alex Wu | bd3354b | 2012-04-17 17:20:49 +0800 | [diff] [blame] | 2548 | if (shell_surface_is_top_fullscreen(shsurf)) { |
Quentin Glidic | c0d79ce | 2013-01-29 14:16:13 +0100 | [diff] [blame] | 2549 | struct weston_mode mode = {0, |
Pekka Paalanen | 1fd9c0f | 2013-11-26 18:19:41 +0100 | [diff] [blame] | 2550 | surf_width * surface->buffer_viewport.scale, |
| 2551 | surf_height * surface->buffer_viewport.scale, |
Alex Wu | bd3354b | 2012-04-17 17:20:49 +0800 | [diff] [blame] | 2552 | shsurf->fullscreen.framerate}; |
| 2553 | |
Pekka Paalanen | 1fd9c0f | 2013-11-26 18:19:41 +0100 | [diff] [blame] | 2554 | if (weston_output_switch_mode(output, &mode, surface->buffer_viewport.scale, |
Hardening | 57388e4 | 2013-09-18 23:56:36 +0200 | [diff] [blame] | 2555 | WESTON_MODE_SWITCH_SET_TEMPORARY) == 0) { |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 2556 | weston_view_set_position(shsurf->view, |
| 2557 | output->x - surf_x, |
| 2558 | output->y - surf_y); |
Jason Ekstrand | 918f2dd | 2013-12-02 21:01:53 -0600 | [diff] [blame] | 2559 | shsurf->fullscreen.black_view->surface->width = output->width; |
| 2560 | shsurf->fullscreen.black_view->surface->height = output->height; |
| 2561 | weston_view_set_position(shsurf->fullscreen.black_view, |
| 2562 | output->x - surf_x, |
| 2563 | output->y - surf_y); |
Alex Wu | bd3354b | 2012-04-17 17:20:49 +0800 | [diff] [blame] | 2564 | break; |
Alexander Larsson | d622ed3 | 2013-05-28 16:23:40 +0200 | [diff] [blame] | 2565 | } else { |
Alexander Larsson | f82b6ca | 2013-05-28 16:23:39 +0200 | [diff] [blame] | 2566 | restore_output_mode(output); |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 2567 | center_on_output(shsurf->view, output); |
Alexander Larsson | d622ed3 | 2013-05-28 16:23:40 +0200 | [diff] [blame] | 2568 | } |
Alex Wu | bd3354b | 2012-04-17 17:20:49 +0800 | [diff] [blame] | 2569 | } |
Alex Wu | 4539b08 | 2012-03-01 12:57:46 +0800 | [diff] [blame] | 2570 | break; |
| 2571 | case WL_SHELL_SURFACE_FULLSCREEN_METHOD_FILL: |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 2572 | center_on_output(shsurf->view, output); |
Alex Wu | 4539b08 | 2012-03-01 12:57:46 +0800 | [diff] [blame] | 2573 | break; |
| 2574 | default: |
| 2575 | break; |
| 2576 | } |
| 2577 | } |
| 2578 | |
Alex Wu | 4539b08 | 2012-03-01 12:57:46 +0800 | [diff] [blame] | 2579 | static void |
| 2580 | shell_map_fullscreen(struct shell_surface *shsurf) |
| 2581 | { |
Alex Wu | bd3354b | 2012-04-17 17:20:49 +0800 | [diff] [blame] | 2582 | shell_configure_fullscreen(shsurf); |
Alex Wu | 4539b08 | 2012-03-01 12:57:46 +0800 | [diff] [blame] | 2583 | } |
| 2584 | |
Kristian Høgsberg | 7a5c979 | 2011-06-18 06:12:54 -0400 | [diff] [blame] | 2585 | static void |
Tiago Vignatti | fb2adba | 2013-06-12 15:43:21 -0300 | [diff] [blame] | 2586 | set_xwayland(struct shell_surface *shsurf, int x, int y, uint32_t flags) |
| 2587 | { |
| 2588 | /* XXX: using the same fields for transient type */ |
Rafael Antognolli | 03b1659 | 2013-12-03 15:35:42 -0200 | [diff] [blame] | 2589 | surface_clear_next_states(shsurf); |
Tiago Vignatti | fb2adba | 2013-06-12 15:43:21 -0300 | [diff] [blame] | 2590 | shsurf->transient.x = x; |
| 2591 | shsurf->transient.y = y; |
| 2592 | shsurf->transient.flags = flags; |
Philip Withnall | dc4332f | 2013-11-25 18:01:38 +0000 | [diff] [blame] | 2593 | |
| 2594 | shell_surface_set_parent(shsurf, NULL); |
| 2595 | |
Kristian Høgsberg | c8f8dd8 | 2013-12-05 23:20:33 -0800 | [diff] [blame] | 2596 | shsurf->type = SHELL_SURFACE_XWAYLAND; |
Tiago Vignatti | fb2adba | 2013-06-12 15:43:21 -0300 | [diff] [blame] | 2597 | } |
| 2598 | |
Kristian Høgsberg | 02bbabb | 2013-05-06 22:15:05 -0400 | [diff] [blame] | 2599 | static const struct weston_pointer_grab_interface popup_grab_interface; |
Giulio Camuffo | 5085a75 | 2013-03-25 21:42:45 +0100 | [diff] [blame] | 2600 | |
| 2601 | static void |
| 2602 | destroy_shell_seat(struct wl_listener *listener, void *data) |
| 2603 | { |
| 2604 | struct shell_seat *shseat = |
| 2605 | container_of(listener, |
| 2606 | struct shell_seat, seat_destroy_listener); |
| 2607 | struct shell_surface *shsurf, *prev = NULL; |
| 2608 | |
| 2609 | if (shseat->popup_grab.grab.interface == &popup_grab_interface) { |
Kristian Høgsberg | 02bbabb | 2013-05-06 22:15:05 -0400 | [diff] [blame] | 2610 | weston_pointer_end_grab(shseat->popup_grab.grab.pointer); |
Giulio Camuffo | 5085a75 | 2013-03-25 21:42:45 +0100 | [diff] [blame] | 2611 | shseat->popup_grab.client = NULL; |
| 2612 | |
| 2613 | wl_list_for_each(shsurf, &shseat->popup_grab.surfaces_list, popup.grab_link) { |
| 2614 | shsurf->popup.shseat = NULL; |
| 2615 | if (prev) { |
| 2616 | wl_list_init(&prev->popup.grab_link); |
| 2617 | } |
| 2618 | prev = shsurf; |
| 2619 | } |
| 2620 | wl_list_init(&prev->popup.grab_link); |
| 2621 | } |
| 2622 | |
| 2623 | wl_list_remove(&shseat->seat_destroy_listener.link); |
| 2624 | free(shseat); |
| 2625 | } |
| 2626 | |
| 2627 | static struct shell_seat * |
| 2628 | create_shell_seat(struct weston_seat *seat) |
| 2629 | { |
| 2630 | struct shell_seat *shseat; |
| 2631 | |
| 2632 | shseat = calloc(1, sizeof *shseat); |
| 2633 | if (!shseat) { |
| 2634 | weston_log("no memory to allocate shell seat\n"); |
| 2635 | return NULL; |
| 2636 | } |
| 2637 | |
| 2638 | shseat->seat = seat; |
| 2639 | wl_list_init(&shseat->popup_grab.surfaces_list); |
| 2640 | |
| 2641 | shseat->seat_destroy_listener.notify = destroy_shell_seat; |
| 2642 | wl_signal_add(&seat->destroy_signal, |
| 2643 | &shseat->seat_destroy_listener); |
| 2644 | |
| 2645 | return shseat; |
| 2646 | } |
| 2647 | |
| 2648 | static struct shell_seat * |
| 2649 | get_shell_seat(struct weston_seat *seat) |
| 2650 | { |
| 2651 | struct wl_listener *listener; |
| 2652 | |
| 2653 | listener = wl_signal_get(&seat->destroy_signal, destroy_shell_seat); |
| 2654 | if (listener == NULL) |
| 2655 | return create_shell_seat(seat); |
| 2656 | |
| 2657 | return container_of(listener, |
| 2658 | struct shell_seat, seat_destroy_listener); |
| 2659 | } |
| 2660 | |
Kristian Høgsberg | b810eb5 | 2013-02-12 20:07:05 -0500 | [diff] [blame] | 2661 | static void |
Kristian Høgsberg | 6848c25 | 2013-05-08 22:02:59 -0400 | [diff] [blame] | 2662 | popup_grab_focus(struct weston_pointer_grab *grab) |
Kristian Høgsberg | b3cca0a | 2012-01-04 22:19:14 -0500 | [diff] [blame] | 2663 | { |
Kristian Høgsberg | 02bbabb | 2013-05-06 22:15:05 -0400 | [diff] [blame] | 2664 | struct weston_pointer *pointer = grab->pointer; |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 2665 | struct weston_view *view; |
Giulio Camuffo | 5085a75 | 2013-03-25 21:42:45 +0100 | [diff] [blame] | 2666 | struct shell_seat *shseat = |
| 2667 | container_of(grab, struct shell_seat, popup_grab.grab); |
| 2668 | struct wl_client *client = shseat->popup_grab.client; |
Kristian Høgsberg | 6848c25 | 2013-05-08 22:02:59 -0400 | [diff] [blame] | 2669 | wl_fixed_t sx, sy; |
| 2670 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 2671 | view = weston_compositor_pick_view(pointer->seat->compositor, |
| 2672 | pointer->x, pointer->y, |
| 2673 | &sx, &sy); |
Kristian Høgsberg | b3cca0a | 2012-01-04 22:19:14 -0500 | [diff] [blame] | 2674 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 2675 | if (view && view->surface->resource && |
| 2676 | wl_resource_get_client(view->surface->resource) == client) { |
| 2677 | weston_pointer_set_focus(pointer, view, sx, sy); |
Kristian Høgsberg | b3cca0a | 2012-01-04 22:19:14 -0500 | [diff] [blame] | 2678 | } else { |
Kristian Høgsberg | 02bbabb | 2013-05-06 22:15:05 -0400 | [diff] [blame] | 2679 | weston_pointer_set_focus(pointer, NULL, |
| 2680 | wl_fixed_from_int(0), |
| 2681 | wl_fixed_from_int(0)); |
Kristian Høgsberg | b3cca0a | 2012-01-04 22:19:14 -0500 | [diff] [blame] | 2682 | } |
| 2683 | } |
| 2684 | |
| 2685 | static void |
Giulio Camuffo | 1959ab8 | 2013-11-14 23:42:52 +0100 | [diff] [blame] | 2686 | popup_grab_motion(struct weston_pointer_grab *grab, uint32_t time, |
| 2687 | wl_fixed_t x, wl_fixed_t y) |
Kristian Høgsberg | b3cca0a | 2012-01-04 22:19:14 -0500 | [diff] [blame] | 2688 | { |
Kristian Høgsberg | be6403e | 2013-05-08 21:03:21 -0400 | [diff] [blame] | 2689 | struct weston_pointer *pointer = grab->pointer; |
Neil Roberts | 96d790e | 2013-09-19 17:32:00 +0100 | [diff] [blame] | 2690 | struct wl_resource *resource; |
Kristian Høgsberg | be6403e | 2013-05-08 21:03:21 -0400 | [diff] [blame] | 2691 | wl_fixed_t sx, sy; |
Kristian Høgsberg | b3cca0a | 2012-01-04 22:19:14 -0500 | [diff] [blame] | 2692 | |
Giulio Camuffo | 1959ab8 | 2013-11-14 23:42:52 +0100 | [diff] [blame] | 2693 | weston_pointer_move(pointer, x, y); |
| 2694 | |
Neil Roberts | 96d790e | 2013-09-19 17:32:00 +0100 | [diff] [blame] | 2695 | wl_resource_for_each(resource, &pointer->focus_resource_list) { |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 2696 | weston_view_from_global_fixed(pointer->focus, |
| 2697 | pointer->x, pointer->y, |
| 2698 | &sx, &sy); |
Neil Roberts | 96d790e | 2013-09-19 17:32:00 +0100 | [diff] [blame] | 2699 | wl_pointer_send_motion(resource, time, sx, sy); |
Kristian Høgsberg | be6403e | 2013-05-08 21:03:21 -0400 | [diff] [blame] | 2700 | } |
Kristian Høgsberg | b3cca0a | 2012-01-04 22:19:14 -0500 | [diff] [blame] | 2701 | } |
| 2702 | |
| 2703 | static void |
Kristian Høgsberg | 02bbabb | 2013-05-06 22:15:05 -0400 | [diff] [blame] | 2704 | popup_grab_button(struct weston_pointer_grab *grab, |
Daniel Stone | 4dbadb1 | 2012-05-30 16:31:51 +0100 | [diff] [blame] | 2705 | uint32_t time, uint32_t button, uint32_t state_w) |
Kristian Høgsberg | b3cca0a | 2012-01-04 22:19:14 -0500 | [diff] [blame] | 2706 | { |
| 2707 | struct wl_resource *resource; |
Giulio Camuffo | 5085a75 | 2013-03-25 21:42:45 +0100 | [diff] [blame] | 2708 | struct shell_seat *shseat = |
| 2709 | container_of(grab, struct shell_seat, popup_grab.grab); |
Rob Bradford | 880ebc7 | 2013-07-22 17:31:38 +0100 | [diff] [blame] | 2710 | struct wl_display *display = shseat->seat->compositor->wl_display; |
Daniel Stone | 4dbadb1 | 2012-05-30 16:31:51 +0100 | [diff] [blame] | 2711 | enum wl_pointer_button_state state = state_w; |
Kristian Høgsberg | eae5de7 | 2012-04-11 22:42:15 -0400 | [diff] [blame] | 2712 | uint32_t serial; |
Neil Roberts | 96d790e | 2013-09-19 17:32:00 +0100 | [diff] [blame] | 2713 | struct wl_list *resource_list; |
Kristian Høgsberg | b3cca0a | 2012-01-04 22:19:14 -0500 | [diff] [blame] | 2714 | |
Neil Roberts | 96d790e | 2013-09-19 17:32:00 +0100 | [diff] [blame] | 2715 | resource_list = &grab->pointer->focus_resource_list; |
| 2716 | if (!wl_list_empty(resource_list)) { |
Kristian Høgsberg | eae5de7 | 2012-04-11 22:42:15 -0400 | [diff] [blame] | 2717 | serial = wl_display_get_serial(display); |
Neil Roberts | 96d790e | 2013-09-19 17:32:00 +0100 | [diff] [blame] | 2718 | wl_resource_for_each(resource, resource_list) { |
| 2719 | wl_pointer_send_button(resource, serial, |
| 2720 | time, button, state); |
| 2721 | } |
Daniel Stone | 4dbadb1 | 2012-05-30 16:31:51 +0100 | [diff] [blame] | 2722 | } else if (state == WL_POINTER_BUTTON_STATE_RELEASED && |
Giulio Camuffo | 5085a75 | 2013-03-25 21:42:45 +0100 | [diff] [blame] | 2723 | (shseat->popup_grab.initial_up || |
Kristian Høgsberg | e314875 | 2013-05-06 23:19:49 -0400 | [diff] [blame] | 2724 | time - shseat->seat->pointer->grab_time > 500)) { |
Kristian Høgsberg | 57e0907 | 2012-10-30 14:07:27 -0400 | [diff] [blame] | 2725 | popup_grab_end(grab->pointer); |
Kristian Høgsberg | b3cca0a | 2012-01-04 22:19:14 -0500 | [diff] [blame] | 2726 | } |
| 2727 | |
Daniel Stone | 4dbadb1 | 2012-05-30 16:31:51 +0100 | [diff] [blame] | 2728 | if (state == WL_POINTER_BUTTON_STATE_RELEASED) |
Giulio Camuffo | 5085a75 | 2013-03-25 21:42:45 +0100 | [diff] [blame] | 2729 | shseat->popup_grab.initial_up = 1; |
Kristian Høgsberg | b3cca0a | 2012-01-04 22:19:14 -0500 | [diff] [blame] | 2730 | } |
| 2731 | |
Jonas Ådahl | 1ea343e | 2013-10-25 23:18:05 +0200 | [diff] [blame] | 2732 | static void |
| 2733 | popup_grab_cancel(struct weston_pointer_grab *grab) |
| 2734 | { |
| 2735 | popup_grab_end(grab->pointer); |
| 2736 | } |
| 2737 | |
Kristian Høgsberg | 02bbabb | 2013-05-06 22:15:05 -0400 | [diff] [blame] | 2738 | static const struct weston_pointer_grab_interface popup_grab_interface = { |
Kristian Høgsberg | b3cca0a | 2012-01-04 22:19:14 -0500 | [diff] [blame] | 2739 | popup_grab_focus, |
| 2740 | popup_grab_motion, |
| 2741 | popup_grab_button, |
Jonas Ådahl | 1ea343e | 2013-10-25 23:18:05 +0200 | [diff] [blame] | 2742 | popup_grab_cancel, |
Kristian Høgsberg | b3cca0a | 2012-01-04 22:19:14 -0500 | [diff] [blame] | 2743 | }; |
| 2744 | |
| 2745 | static void |
Rafael Antognolli | e2a3455 | 2013-12-03 15:35:45 -0200 | [diff] [blame] | 2746 | shell_surface_send_popup_done(struct shell_surface *shsurf) |
| 2747 | { |
| 2748 | if (shell_surface_is_wl_shell_surface(shsurf)) |
| 2749 | wl_shell_surface_send_popup_done(shsurf->resource); |
| 2750 | else if (shell_surface_is_xdg_popup(shsurf)) |
| 2751 | xdg_popup_send_popup_done(shsurf->resource, |
| 2752 | shsurf->popup.serial); |
| 2753 | } |
| 2754 | |
| 2755 | static void |
Kristian Høgsberg | 02bbabb | 2013-05-06 22:15:05 -0400 | [diff] [blame] | 2756 | popup_grab_end(struct weston_pointer *pointer) |
Kristian Høgsberg | 57e0907 | 2012-10-30 14:07:27 -0400 | [diff] [blame] | 2757 | { |
Kristian Høgsberg | 02bbabb | 2013-05-06 22:15:05 -0400 | [diff] [blame] | 2758 | struct weston_pointer_grab *grab = pointer->grab; |
Giulio Camuffo | 5085a75 | 2013-03-25 21:42:45 +0100 | [diff] [blame] | 2759 | struct shell_seat *shseat = |
| 2760 | container_of(grab, struct shell_seat, popup_grab.grab); |
| 2761 | struct shell_surface *shsurf; |
| 2762 | struct shell_surface *prev = NULL; |
Kristian Høgsberg | 57e0907 | 2012-10-30 14:07:27 -0400 | [diff] [blame] | 2763 | |
| 2764 | if (pointer->grab->interface == &popup_grab_interface) { |
Kristian Høgsberg | 02bbabb | 2013-05-06 22:15:05 -0400 | [diff] [blame] | 2765 | weston_pointer_end_grab(grab->pointer); |
Giulio Camuffo | 5085a75 | 2013-03-25 21:42:45 +0100 | [diff] [blame] | 2766 | shseat->popup_grab.client = NULL; |
Philipp Brüschweiler | 63e7be6 | 2013-04-15 21:09:54 +0200 | [diff] [blame] | 2767 | shseat->popup_grab.grab.interface = NULL; |
| 2768 | assert(!wl_list_empty(&shseat->popup_grab.surfaces_list)); |
Giulio Camuffo | 5085a75 | 2013-03-25 21:42:45 +0100 | [diff] [blame] | 2769 | /* Send the popup_done event to all the popups open */ |
| 2770 | 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] | 2771 | shell_surface_send_popup_done(shsurf); |
Giulio Camuffo | 5085a75 | 2013-03-25 21:42:45 +0100 | [diff] [blame] | 2772 | shsurf->popup.shseat = NULL; |
| 2773 | if (prev) { |
| 2774 | wl_list_init(&prev->popup.grab_link); |
| 2775 | } |
| 2776 | prev = shsurf; |
| 2777 | } |
| 2778 | wl_list_init(&prev->popup.grab_link); |
| 2779 | wl_list_init(&shseat->popup_grab.surfaces_list); |
| 2780 | } |
| 2781 | } |
| 2782 | |
| 2783 | static void |
| 2784 | add_popup_grab(struct shell_surface *shsurf, struct shell_seat *shseat) |
| 2785 | { |
Kristian Høgsberg | e314875 | 2013-05-06 23:19:49 -0400 | [diff] [blame] | 2786 | struct weston_seat *seat = shseat->seat; |
Giulio Camuffo | 5085a75 | 2013-03-25 21:42:45 +0100 | [diff] [blame] | 2787 | |
| 2788 | if (wl_list_empty(&shseat->popup_grab.surfaces_list)) { |
Jason Ekstrand | 651f00e | 2013-06-14 10:07:54 -0500 | [diff] [blame] | 2789 | shseat->popup_grab.client = wl_resource_get_client(shsurf->resource); |
Giulio Camuffo | 5085a75 | 2013-03-25 21:42:45 +0100 | [diff] [blame] | 2790 | shseat->popup_grab.grab.interface = &popup_grab_interface; |
Giulio Camuffo | 1b4b61a | 2013-03-27 18:05:26 +0100 | [diff] [blame] | 2791 | /* We must make sure here that this popup was opened after |
| 2792 | * a mouse press, and not just by moving around with other |
| 2793 | * popups already open. */ |
Kristian Høgsberg | e314875 | 2013-05-06 23:19:49 -0400 | [diff] [blame] | 2794 | if (shseat->seat->pointer->button_count > 0) |
Giulio Camuffo | 1b4b61a | 2013-03-27 18:05:26 +0100 | [diff] [blame] | 2795 | shseat->popup_grab.initial_up = 0; |
Giulio Camuffo | 5085a75 | 2013-03-25 21:42:45 +0100 | [diff] [blame] | 2796 | |
Rob Bradford | dfe3105 | 2013-06-26 19:49:11 +0100 | [diff] [blame] | 2797 | 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] | 2798 | weston_pointer_start_grab(seat->pointer, &shseat->popup_grab.grab); |
Rob Bradford | dfe3105 | 2013-06-26 19:49:11 +0100 | [diff] [blame] | 2799 | } else { |
| 2800 | wl_list_insert(&shseat->popup_grab.surfaces_list, &shsurf->popup.grab_link); |
Giulio Camuffo | 5085a75 | 2013-03-25 21:42:45 +0100 | [diff] [blame] | 2801 | } |
Giulio Camuffo | 5085a75 | 2013-03-25 21:42:45 +0100 | [diff] [blame] | 2802 | } |
| 2803 | |
| 2804 | static void |
| 2805 | remove_popup_grab(struct shell_surface *shsurf) |
| 2806 | { |
| 2807 | struct shell_seat *shseat = shsurf->popup.shseat; |
| 2808 | |
| 2809 | wl_list_remove(&shsurf->popup.grab_link); |
| 2810 | wl_list_init(&shsurf->popup.grab_link); |
| 2811 | if (wl_list_empty(&shseat->popup_grab.surfaces_list)) { |
Kristian Høgsberg | 02bbabb | 2013-05-06 22:15:05 -0400 | [diff] [blame] | 2812 | weston_pointer_end_grab(shseat->popup_grab.grab.pointer); |
Philipp Brüschweiler | 63e7be6 | 2013-04-15 21:09:54 +0200 | [diff] [blame] | 2813 | shseat->popup_grab.grab.interface = NULL; |
Kristian Høgsberg | 57e0907 | 2012-10-30 14:07:27 -0400 | [diff] [blame] | 2814 | } |
| 2815 | } |
| 2816 | |
| 2817 | static void |
Kristian Høgsberg | 3730f36 | 2012-04-13 12:40:07 -0400 | [diff] [blame] | 2818 | shell_map_popup(struct shell_surface *shsurf) |
Kristian Høgsberg | b3cca0a | 2012-01-04 22:19:14 -0500 | [diff] [blame] | 2819 | { |
Giulio Camuffo | 5085a75 | 2013-03-25 21:42:45 +0100 | [diff] [blame] | 2820 | struct shell_seat *shseat = shsurf->popup.shseat; |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 2821 | struct weston_view *parent_view = get_default_view(shsurf->parent); |
Kristian Høgsberg | b3cca0a | 2012-01-04 22:19:14 -0500 | [diff] [blame] | 2822 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 2823 | shsurf->surface->output = parent_view->output; |
| 2824 | shsurf->view->output = parent_view->output; |
Kristian Høgsberg | b3cca0a | 2012-01-04 22:19:14 -0500 | [diff] [blame] | 2825 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 2826 | weston_view_set_transform_parent(shsurf->view, parent_view); |
| 2827 | weston_view_set_position(shsurf->view, shsurf->popup.x, shsurf->popup.y); |
| 2828 | weston_view_update_transform(shsurf->view); |
Kristian Høgsberg | b3cca0a | 2012-01-04 22:19:14 -0500 | [diff] [blame] | 2829 | |
Kristian Høgsberg | e314875 | 2013-05-06 23:19:49 -0400 | [diff] [blame] | 2830 | if (shseat->seat->pointer->grab_serial == shsurf->popup.serial) { |
Giulio Camuffo | 5085a75 | 2013-03-25 21:42:45 +0100 | [diff] [blame] | 2831 | add_popup_grab(shsurf, shseat); |
Kristian Høgsberg | 3730f36 | 2012-04-13 12:40:07 -0400 | [diff] [blame] | 2832 | } else { |
Rafael Antognolli | e2a3455 | 2013-12-03 15:35:45 -0200 | [diff] [blame] | 2833 | shell_surface_send_popup_done(shsurf); |
Giulio Camuffo | 5085a75 | 2013-03-25 21:42:45 +0100 | [diff] [blame] | 2834 | shseat->popup_grab.client = NULL; |
Kristian Høgsberg | 3730f36 | 2012-04-13 12:40:07 -0400 | [diff] [blame] | 2835 | } |
Kristian Høgsberg | b3cca0a | 2012-01-04 22:19:14 -0500 | [diff] [blame] | 2836 | } |
| 2837 | |
Pekka Paalanen | 9d1613e | 2011-11-25 12:09:16 +0200 | [diff] [blame] | 2838 | static const struct wl_shell_surface_interface shell_surface_implementation = { |
Scott Moreau | ff1db4a | 2012-04-17 19:06:18 -0600 | [diff] [blame] | 2839 | shell_surface_pong, |
Pekka Paalanen | 9d1613e | 2011-11-25 12:09:16 +0200 | [diff] [blame] | 2840 | shell_surface_move, |
| 2841 | shell_surface_resize, |
| 2842 | shell_surface_set_toplevel, |
| 2843 | shell_surface_set_transient, |
Kristian Høgsberg | b3cca0a | 2012-01-04 22:19:14 -0500 | [diff] [blame] | 2844 | shell_surface_set_fullscreen, |
Juan Zhao | 96879df | 2012-02-07 08:45:41 +0800 | [diff] [blame] | 2845 | shell_surface_set_popup, |
Kristian Høgsberg | e7afd91 | 2012-05-02 09:47:44 -0400 | [diff] [blame] | 2846 | shell_surface_set_maximized, |
| 2847 | shell_surface_set_title, |
| 2848 | shell_surface_set_class |
Pekka Paalanen | 9d1613e | 2011-11-25 12:09:16 +0200 | [diff] [blame] | 2849 | }; |
| 2850 | |
| 2851 | static void |
Tiago Vignatti | bc052c9 | 2012-04-19 16:18:18 +0300 | [diff] [blame] | 2852 | destroy_shell_surface(struct shell_surface *shsurf) |
Pekka Paalanen | 9d1613e | 2011-11-25 12:09:16 +0200 | [diff] [blame] | 2853 | { |
Jason Ekstrand | 651f00e | 2013-06-14 10:07:54 -0500 | [diff] [blame] | 2854 | wl_signal_emit(&shsurf->destroy_signal, shsurf); |
| 2855 | |
Giulio Camuffo | 5085a75 | 2013-03-25 21:42:45 +0100 | [diff] [blame] | 2856 | if (!wl_list_empty(&shsurf->popup.grab_link)) { |
| 2857 | remove_popup_grab(shsurf); |
| 2858 | } |
Kristian Høgsberg | b3cca0a | 2012-01-04 22:19:14 -0500 | [diff] [blame] | 2859 | |
Alex Wu | bd3354b | 2012-04-17 17:20:49 +0800 | [diff] [blame] | 2860 | if (shsurf->fullscreen.type == WL_SHELL_SURFACE_FULLSCREEN_METHOD_DRIVER && |
Alexander Larsson | f82b6ca | 2013-05-28 16:23:39 +0200 | [diff] [blame] | 2861 | shell_surface_is_top_fullscreen(shsurf)) |
| 2862 | restore_output_mode (shsurf->fullscreen_output); |
Pekka Paalanen | 9d1613e | 2011-11-25 12:09:16 +0200 | [diff] [blame] | 2863 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 2864 | if (shsurf->fullscreen.black_view) |
| 2865 | weston_surface_destroy(shsurf->fullscreen.black_view->surface); |
Alex Wu | aa08e2d | 2012-03-05 11:01:40 +0800 | [diff] [blame] | 2866 | |
Alex Wu | bd3354b | 2012-04-17 17:20:49 +0800 | [diff] [blame] | 2867 | /* As destroy_resource() use wl_list_for_each_safe(), |
| 2868 | * we can always remove the listener. |
| 2869 | */ |
| 2870 | wl_list_remove(&shsurf->surface_destroy_listener.link); |
| 2871 | shsurf->surface->configure = NULL; |
Scott Moreau | 9521d5e | 2012-04-19 13:06:17 -0600 | [diff] [blame] | 2872 | ping_timer_destroy(shsurf); |
Scott Moreau | 976a050 | 2013-03-07 10:15:17 -0700 | [diff] [blame] | 2873 | free(shsurf->title); |
Alex Wu | bd3354b | 2012-04-17 17:20:49 +0800 | [diff] [blame] | 2874 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 2875 | weston_view_destroy(shsurf->view); |
| 2876 | |
Philip Withnall | 648a4dd | 2013-11-25 18:01:44 +0000 | [diff] [blame] | 2877 | wl_list_remove(&shsurf->children_link); |
| 2878 | |
Pekka Paalanen | 9d1613e | 2011-11-25 12:09:16 +0200 | [diff] [blame] | 2879 | wl_list_remove(&shsurf->link); |
| 2880 | free(shsurf); |
| 2881 | } |
| 2882 | |
| 2883 | static void |
Tiago Vignatti | bc052c9 | 2012-04-19 16:18:18 +0300 | [diff] [blame] | 2884 | shell_destroy_shell_surface(struct wl_resource *resource) |
| 2885 | { |
Jason Ekstrand | 651f00e | 2013-06-14 10:07:54 -0500 | [diff] [blame] | 2886 | struct shell_surface *shsurf = wl_resource_get_user_data(resource); |
Tiago Vignatti | bc052c9 | 2012-04-19 16:18:18 +0300 | [diff] [blame] | 2887 | |
| 2888 | destroy_shell_surface(shsurf); |
| 2889 | } |
| 2890 | |
| 2891 | static void |
Kristian Høgsberg | 27e3052 | 2012-04-11 23:18:23 -0400 | [diff] [blame] | 2892 | shell_handle_surface_destroy(struct wl_listener *listener, void *data) |
Pekka Paalanen | 9d1613e | 2011-11-25 12:09:16 +0200 | [diff] [blame] | 2893 | { |
| 2894 | struct shell_surface *shsurf = container_of(listener, |
| 2895 | struct shell_surface, |
| 2896 | surface_destroy_listener); |
| 2897 | |
Jason Ekstrand | 651f00e | 2013-06-14 10:07:54 -0500 | [diff] [blame] | 2898 | if (shsurf->resource) |
| 2899 | wl_resource_destroy(shsurf->resource); |
| 2900 | else |
Tiago Vignatti | bc052c9 | 2012-04-19 16:18:18 +0300 | [diff] [blame] | 2901 | destroy_shell_surface(shsurf); |
Pekka Paalanen | 9d1613e | 2011-11-25 12:09:16 +0200 | [diff] [blame] | 2902 | } |
| 2903 | |
Kristian Høgsberg | d813445 | 2012-06-21 12:49:02 -0400 | [diff] [blame] | 2904 | static void |
Jason Ekstrand | 918f2dd | 2013-12-02 21:01:53 -0600 | [diff] [blame] | 2905 | shell_surface_configure(struct weston_surface *, int32_t, int32_t); |
Kristian Høgsberg | d813445 | 2012-06-21 12:49:02 -0400 | [diff] [blame] | 2906 | |
Kristian Høgsberg | 1ef2313 | 2013-12-04 00:20:01 -0800 | [diff] [blame] | 2907 | struct shell_surface * |
Kristian Høgsberg | 8334bc1 | 2012-01-03 10:29:47 -0500 | [diff] [blame] | 2908 | get_shell_surface(struct weston_surface *surface) |
Pekka Paalanen | ec2b32f | 2011-11-28 15:12:34 +0200 | [diff] [blame] | 2909 | { |
Kristian Høgsberg | d813445 | 2012-06-21 12:49:02 -0400 | [diff] [blame] | 2910 | if (surface->configure == shell_surface_configure) |
Giulio Camuffo | 7fe01b1 | 2013-03-28 18:02:42 +0100 | [diff] [blame] | 2911 | return surface->configure_private; |
Kristian Høgsberg | d813445 | 2012-06-21 12:49:02 -0400 | [diff] [blame] | 2912 | else |
| 2913 | return NULL; |
Pekka Paalanen | ec2b32f | 2011-11-28 15:12:34 +0200 | [diff] [blame] | 2914 | } |
| 2915 | |
Rafael Antognolli | e2a3455 | 2013-12-03 15:35:45 -0200 | [diff] [blame] | 2916 | static struct shell_surface * |
| 2917 | create_common_surface(void *shell, struct weston_surface *surface, |
| 2918 | const struct weston_shell_client *client) |
Pekka Paalanen | 9d1613e | 2011-11-25 12:09:16 +0200 | [diff] [blame] | 2919 | { |
Pekka Paalanen | 9d1613e | 2011-11-25 12:09:16 +0200 | [diff] [blame] | 2920 | struct shell_surface *shsurf; |
| 2921 | |
Ander Conselvan de Oliveira | 093bfa3 | 2012-03-27 17:36:41 +0300 | [diff] [blame] | 2922 | if (surface->configure) { |
Martin Minarik | 6d11836 | 2012-06-07 18:01:59 +0200 | [diff] [blame] | 2923 | weston_log("surface->configure already set\n"); |
Kristian Høgsberg | 45ba869 | 2012-05-21 14:27:33 -0400 | [diff] [blame] | 2924 | return NULL; |
Ander Conselvan de Oliveira | 093bfa3 | 2012-03-27 17:36:41 +0300 | [diff] [blame] | 2925 | } |
| 2926 | |
Pekka Paalanen | 9d1613e | 2011-11-25 12:09:16 +0200 | [diff] [blame] | 2927 | shsurf = calloc(1, sizeof *shsurf); |
| 2928 | if (!shsurf) { |
Martin Minarik | 6d11836 | 2012-06-07 18:01:59 +0200 | [diff] [blame] | 2929 | weston_log("no memory to allocate shell surface\n"); |
Kristian Høgsberg | 45ba869 | 2012-05-21 14:27:33 -0400 | [diff] [blame] | 2930 | return NULL; |
Pekka Paalanen | 9d1613e | 2011-11-25 12:09:16 +0200 | [diff] [blame] | 2931 | } |
| 2932 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 2933 | shsurf->view = weston_view_create(surface); |
| 2934 | if (!shsurf->view) { |
| 2935 | weston_log("no memory to allocate shell surface\n"); |
| 2936 | free(shsurf); |
| 2937 | return NULL; |
| 2938 | } |
| 2939 | |
Ander Conselvan de Oliveira | 093bfa3 | 2012-03-27 17:36:41 +0300 | [diff] [blame] | 2940 | surface->configure = shell_surface_configure; |
Giulio Camuffo | 7fe01b1 | 2013-03-28 18:02:42 +0100 | [diff] [blame] | 2941 | surface->configure_private = shsurf; |
Ander Conselvan de Oliveira | 093bfa3 | 2012-03-27 17:36:41 +0300 | [diff] [blame] | 2942 | |
Tiago Vignatti | bc052c9 | 2012-04-19 16:18:18 +0300 | [diff] [blame] | 2943 | shsurf->shell = (struct desktop_shell *) shell; |
Scott Moreau | ff1db4a | 2012-04-17 19:06:18 -0600 | [diff] [blame] | 2944 | shsurf->unresponsive = 0; |
Alex Wu | 4539b08 | 2012-03-01 12:57:46 +0800 | [diff] [blame] | 2945 | shsurf->saved_position_valid = false; |
Rafael Antognolli | 3c4e3f7 | 2013-12-03 15:35:46 -0200 | [diff] [blame] | 2946 | shsurf->saved_size_valid = false; |
Alex Wu | 7bcb8bd | 2012-04-27 09:07:24 +0800 | [diff] [blame] | 2947 | shsurf->saved_rotation_valid = false; |
Pekka Paalanen | 9d1613e | 2011-11-25 12:09:16 +0200 | [diff] [blame] | 2948 | shsurf->surface = surface; |
Alex Wu | 4539b08 | 2012-03-01 12:57:46 +0800 | [diff] [blame] | 2949 | shsurf->fullscreen.type = WL_SHELL_SURFACE_FULLSCREEN_METHOD_DEFAULT; |
| 2950 | shsurf->fullscreen.framerate = 0; |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 2951 | shsurf->fullscreen.black_view = NULL; |
Scott Moreau | ff1db4a | 2012-04-17 19:06:18 -0600 | [diff] [blame] | 2952 | shsurf->ping_timer = NULL; |
Alex Wu | 4539b08 | 2012-03-01 12:57:46 +0800 | [diff] [blame] | 2953 | wl_list_init(&shsurf->fullscreen.transform.link); |
| 2954 | |
Jason Ekstrand | 651f00e | 2013-06-14 10:07:54 -0500 | [diff] [blame] | 2955 | wl_signal_init(&shsurf->destroy_signal); |
Kristian Høgsberg | 27e3052 | 2012-04-11 23:18:23 -0400 | [diff] [blame] | 2956 | shsurf->surface_destroy_listener.notify = shell_handle_surface_destroy; |
Jason Ekstrand | 26ed73c | 2013-06-06 22:34:41 -0500 | [diff] [blame] | 2957 | wl_signal_add(&surface->destroy_signal, |
Kristian Høgsberg | 27e3052 | 2012-04-11 23:18:23 -0400 | [diff] [blame] | 2958 | &shsurf->surface_destroy_listener); |
Pekka Paalanen | 9d1613e | 2011-11-25 12:09:16 +0200 | [diff] [blame] | 2959 | |
| 2960 | /* init link so its safe to always remove it in destroy_shell_surface */ |
| 2961 | wl_list_init(&shsurf->link); |
Giulio Camuffo | 5085a75 | 2013-03-25 21:42:45 +0100 | [diff] [blame] | 2962 | wl_list_init(&shsurf->popup.grab_link); |
Pekka Paalanen | 9d1613e | 2011-11-25 12:09:16 +0200 | [diff] [blame] | 2963 | |
Pekka Paalanen | 460099f | 2012-01-20 16:48:25 +0200 | [diff] [blame] | 2964 | /* empty when not in use */ |
| 2965 | wl_list_init(&shsurf->rotation.transform.link); |
Kristian Høgsberg | 765e27b | 2012-01-27 13:36:13 -0500 | [diff] [blame] | 2966 | weston_matrix_init(&shsurf->rotation.rotation); |
Pekka Paalanen | 460099f | 2012-01-20 16:48:25 +0200 | [diff] [blame] | 2967 | |
Jonas Ådahl | 62fcd04 | 2012-06-13 00:01:23 +0200 | [diff] [blame] | 2968 | wl_list_init(&shsurf->workspace_transform.link); |
| 2969 | |
Philip Withnall | 648a4dd | 2013-11-25 18:01:44 +0000 | [diff] [blame] | 2970 | wl_list_init(&shsurf->children_link); |
| 2971 | wl_list_init(&shsurf->children_list); |
| 2972 | shsurf->parent = NULL; |
| 2973 | |
Pekka Paalanen | 9826223 | 2011-12-01 10:42:22 +0200 | [diff] [blame] | 2974 | shsurf->type = SHELL_SURFACE_NONE; |
Pekka Paalanen | 9d1613e | 2011-11-25 12:09:16 +0200 | [diff] [blame] | 2975 | |
Kristian Høgsberg | a61ca06 | 2012-05-22 16:05:52 -0400 | [diff] [blame] | 2976 | shsurf->client = client; |
| 2977 | |
Kristian Høgsberg | 45ba869 | 2012-05-21 14:27:33 -0400 | [diff] [blame] | 2978 | return shsurf; |
Tiago Vignatti | bc052c9 | 2012-04-19 16:18:18 +0300 | [diff] [blame] | 2979 | } |
| 2980 | |
Rafael Antognolli | e2a3455 | 2013-12-03 15:35:45 -0200 | [diff] [blame] | 2981 | static struct shell_surface * |
| 2982 | create_shell_surface(void *shell, struct weston_surface *surface, |
| 2983 | const struct weston_shell_client *client) |
| 2984 | { |
Kristian Høgsberg | c8f8dd8 | 2013-12-05 23:20:33 -0800 | [diff] [blame] | 2985 | return create_common_surface(shell, surface, client); |
Rafael Antognolli | e2a3455 | 2013-12-03 15:35:45 -0200 | [diff] [blame] | 2986 | } |
| 2987 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 2988 | static struct weston_view * |
| 2989 | get_primary_view(void *shell, struct shell_surface *shsurf) |
| 2990 | { |
| 2991 | return shsurf->view; |
| 2992 | } |
| 2993 | |
Tiago Vignatti | bc052c9 | 2012-04-19 16:18:18 +0300 | [diff] [blame] | 2994 | static void |
| 2995 | shell_get_shell_surface(struct wl_client *client, |
| 2996 | struct wl_resource *resource, |
| 2997 | uint32_t id, |
| 2998 | struct wl_resource *surface_resource) |
| 2999 | { |
Jason Ekstrand | 0f2ef7e | 2013-06-14 10:07:53 -0500 | [diff] [blame] | 3000 | struct weston_surface *surface = |
| 3001 | wl_resource_get_user_data(surface_resource); |
Jason Ekstrand | 651f00e | 2013-06-14 10:07:54 -0500 | [diff] [blame] | 3002 | struct desktop_shell *shell = wl_resource_get_user_data(resource); |
Tiago Vignatti | bc052c9 | 2012-04-19 16:18:18 +0300 | [diff] [blame] | 3003 | struct shell_surface *shsurf; |
| 3004 | |
| 3005 | if (get_shell_surface(surface)) { |
| 3006 | wl_resource_post_error(surface_resource, |
Kristian Høgsberg | 9540ea6 | 2012-05-21 14:28:57 -0400 | [diff] [blame] | 3007 | WL_DISPLAY_ERROR_INVALID_OBJECT, |
| 3008 | "desktop_shell::get_shell_surface already requested"); |
Tiago Vignatti | bc052c9 | 2012-04-19 16:18:18 +0300 | [diff] [blame] | 3009 | return; |
| 3010 | } |
| 3011 | |
Kristian Høgsberg | a61ca06 | 2012-05-22 16:05:52 -0400 | [diff] [blame] | 3012 | shsurf = create_shell_surface(shell, surface, &shell_client); |
Kristian Høgsberg | 9540ea6 | 2012-05-21 14:28:57 -0400 | [diff] [blame] | 3013 | if (!shsurf) { |
| 3014 | wl_resource_post_error(surface_resource, |
| 3015 | WL_DISPLAY_ERROR_INVALID_OBJECT, |
| 3016 | "surface->configure already set"); |
| 3017 | return; |
| 3018 | } |
Tiago Vignatti | bc052c9 | 2012-04-19 16:18:18 +0300 | [diff] [blame] | 3019 | |
Jason Ekstrand | a85118c | 2013-06-27 20:17:02 -0500 | [diff] [blame] | 3020 | shsurf->resource = |
| 3021 | wl_resource_create(client, |
| 3022 | &wl_shell_surface_interface, 1, id); |
| 3023 | wl_resource_set_implementation(shsurf->resource, |
| 3024 | &shell_surface_implementation, |
| 3025 | shsurf, shell_destroy_shell_surface); |
Pekka Paalanen | 9d1613e | 2011-11-25 12:09:16 +0200 | [diff] [blame] | 3026 | } |
| 3027 | |
Rafael Antognolli | e2a3455 | 2013-12-03 15:35:45 -0200 | [diff] [blame] | 3028 | static bool |
| 3029 | shell_surface_is_wl_shell_surface(struct shell_surface *shsurf) |
| 3030 | { |
| 3031 | return wl_resource_instance_of(shsurf->resource, |
| 3032 | &wl_shell_surface_interface, |
| 3033 | &shell_surface_implementation); |
| 3034 | } |
| 3035 | |
Pekka Paalanen | 9d1613e | 2011-11-25 12:09:16 +0200 | [diff] [blame] | 3036 | static const struct wl_shell_interface shell_implementation = { |
Pekka Paalanen | 4622967 | 2011-11-29 15:49:31 +0200 | [diff] [blame] | 3037 | shell_get_shell_surface |
Kristian Høgsberg | 4cca349 | 2011-01-18 07:53:49 -0500 | [diff] [blame] | 3038 | }; |
| 3039 | |
Rafael Antognolli | e2a3455 | 2013-12-03 15:35:45 -0200 | [diff] [blame] | 3040 | /**************************** |
| 3041 | * xdg-shell implementation */ |
| 3042 | |
| 3043 | static void |
| 3044 | xdg_surface_destroy(struct wl_client *client, |
| 3045 | struct wl_resource *resource) |
| 3046 | { |
| 3047 | wl_resource_destroy(resource); |
| 3048 | } |
| 3049 | |
| 3050 | static void |
| 3051 | xdg_surface_pong(struct wl_client *client, |
| 3052 | struct wl_resource *resource, |
| 3053 | uint32_t serial) |
| 3054 | { |
| 3055 | struct shell_surface *shsurf = wl_resource_get_user_data(resource); |
| 3056 | |
| 3057 | surface_pong(shsurf, serial); |
| 3058 | } |
| 3059 | |
| 3060 | static void |
| 3061 | xdg_surface_set_app_id(struct wl_client *client, |
| 3062 | struct wl_resource *resource, |
| 3063 | const char *app_id) |
| 3064 | { |
| 3065 | struct shell_surface *shsurf = wl_resource_get_user_data(resource); |
| 3066 | |
| 3067 | free(shsurf->class); |
| 3068 | shsurf->class = strdup(app_id); |
| 3069 | } |
| 3070 | |
| 3071 | static void |
| 3072 | xdg_surface_set_title(struct wl_client *client, |
| 3073 | struct wl_resource *resource, const char *title) |
| 3074 | { |
| 3075 | struct shell_surface *shsurf = wl_resource_get_user_data(resource); |
| 3076 | |
| 3077 | set_title(shsurf, title); |
| 3078 | } |
| 3079 | |
| 3080 | static void |
| 3081 | xdg_surface_move(struct wl_client *client, struct wl_resource *resource, |
| 3082 | struct wl_resource *seat_resource, uint32_t serial) |
| 3083 | { |
| 3084 | common_surface_move(resource, seat_resource, serial); |
| 3085 | } |
| 3086 | |
| 3087 | static void |
| 3088 | xdg_surface_resize(struct wl_client *client, struct wl_resource *resource, |
| 3089 | struct wl_resource *seat_resource, uint32_t serial, |
| 3090 | uint32_t edges) |
| 3091 | { |
| 3092 | common_surface_resize(resource, seat_resource, serial, edges); |
| 3093 | } |
| 3094 | |
| 3095 | static void |
| 3096 | xdg_surface_set_output(struct wl_client *client, |
| 3097 | struct wl_resource *resource, |
| 3098 | struct wl_resource *output_resource) |
| 3099 | { |
| 3100 | struct shell_surface *shsurf = wl_resource_get_user_data(resource); |
| 3101 | struct weston_output *output; |
| 3102 | |
| 3103 | if (output_resource) |
| 3104 | output = wl_resource_get_user_data(output_resource); |
| 3105 | else |
| 3106 | output = NULL; |
| 3107 | |
Rafael Antognolli | 65f98d8 | 2013-12-03 15:35:47 -0200 | [diff] [blame] | 3108 | shsurf->recommended_output = output; |
Rafael Antognolli | e2a3455 | 2013-12-03 15:35:45 -0200 | [diff] [blame] | 3109 | } |
| 3110 | |
| 3111 | static void |
| 3112 | xdg_surface_set_fullscreen(struct wl_client *client, |
| 3113 | struct wl_resource *resource) |
| 3114 | { |
| 3115 | struct shell_surface *shsurf = wl_resource_get_user_data(resource); |
| 3116 | |
| 3117 | if (shsurf->type != SHELL_SURFACE_TOPLEVEL) |
| 3118 | return; |
| 3119 | |
Kristian Høgsberg | e960b3f | 2013-12-05 22:04:42 -0800 | [diff] [blame] | 3120 | if (!shsurf->next_state.fullscreen) |
Rafael Antognolli | e2a3455 | 2013-12-03 15:35:45 -0200 | [diff] [blame] | 3121 | set_fullscreen(shsurf, |
| 3122 | WL_SHELL_SURFACE_FULLSCREEN_METHOD_DEFAULT, |
Rafael Antognolli | 65f98d8 | 2013-12-03 15:35:47 -0200 | [diff] [blame] | 3123 | 0, shsurf->recommended_output); |
Rafael Antognolli | e2a3455 | 2013-12-03 15:35:45 -0200 | [diff] [blame] | 3124 | } |
| 3125 | |
| 3126 | static void |
| 3127 | xdg_surface_unset_fullscreen(struct wl_client *client, |
| 3128 | struct wl_resource *resource) |
| 3129 | { |
| 3130 | struct shell_surface *shsurf = wl_resource_get_user_data(resource); |
Rafael Antognolli | 3c4e3f7 | 2013-12-03 15:35:46 -0200 | [diff] [blame] | 3131 | int32_t width, height; |
Rafael Antognolli | e2a3455 | 2013-12-03 15:35:45 -0200 | [diff] [blame] | 3132 | |
| 3133 | if (shsurf->type != SHELL_SURFACE_TOPLEVEL) |
| 3134 | return; |
| 3135 | |
Rafael Antognolli | 3c4e3f7 | 2013-12-03 15:35:46 -0200 | [diff] [blame] | 3136 | if (!shsurf->next_state.fullscreen) |
| 3137 | return; |
| 3138 | |
Rafael Antognolli | e2a3455 | 2013-12-03 15:35:45 -0200 | [diff] [blame] | 3139 | shsurf->next_state.fullscreen = false; |
| 3140 | shsurf->state_changed = true; |
Rafael Antognolli | 3c4e3f7 | 2013-12-03 15:35:46 -0200 | [diff] [blame] | 3141 | |
| 3142 | if (shsurf->saved_size_valid) { |
| 3143 | width = shsurf->saved_width; |
| 3144 | height = shsurf->saved_height; |
| 3145 | shsurf->saved_size_valid = false; |
| 3146 | } else { |
| 3147 | width = shsurf->surface->width; |
| 3148 | height = shsurf->surface->height; |
| 3149 | } |
| 3150 | |
| 3151 | shsurf->client->send_configure(shsurf->surface, 0, width, height); |
Rafael Antognolli | e2a3455 | 2013-12-03 15:35:45 -0200 | [diff] [blame] | 3152 | } |
| 3153 | |
| 3154 | static void |
| 3155 | xdg_surface_set_maximized(struct wl_client *client, |
| 3156 | struct wl_resource *resource) |
| 3157 | { |
| 3158 | struct shell_surface *shsurf = wl_resource_get_user_data(resource); |
| 3159 | |
| 3160 | if (shsurf->type != SHELL_SURFACE_TOPLEVEL) |
| 3161 | return; |
| 3162 | |
Kristian Høgsberg | c2745b1 | 2013-12-05 22:00:40 -0800 | [diff] [blame] | 3163 | if (!shsurf->next_state.maximized) |
Rafael Antognolli | 65f98d8 | 2013-12-03 15:35:47 -0200 | [diff] [blame] | 3164 | set_maximized(shsurf, NULL); |
Rafael Antognolli | e2a3455 | 2013-12-03 15:35:45 -0200 | [diff] [blame] | 3165 | } |
| 3166 | |
| 3167 | static void |
| 3168 | xdg_surface_unset_maximized(struct wl_client *client, |
| 3169 | struct wl_resource *resource) |
| 3170 | { |
| 3171 | struct shell_surface *shsurf = wl_resource_get_user_data(resource); |
Rafael Antognolli | 3c4e3f7 | 2013-12-03 15:35:46 -0200 | [diff] [blame] | 3172 | int32_t width, height; |
Rafael Antognolli | e2a3455 | 2013-12-03 15:35:45 -0200 | [diff] [blame] | 3173 | |
| 3174 | if (shsurf->type != SHELL_SURFACE_TOPLEVEL) |
| 3175 | return; |
| 3176 | |
Rafael Antognolli | 3c4e3f7 | 2013-12-03 15:35:46 -0200 | [diff] [blame] | 3177 | if (!shsurf->next_state.maximized) |
| 3178 | return; |
| 3179 | |
Rafael Antognolli | e2a3455 | 2013-12-03 15:35:45 -0200 | [diff] [blame] | 3180 | shsurf->next_state.maximized = false; |
| 3181 | shsurf->state_changed = true; |
Rafael Antognolli | 3c4e3f7 | 2013-12-03 15:35:46 -0200 | [diff] [blame] | 3182 | |
| 3183 | if (shsurf->saved_size_valid) { |
| 3184 | width = shsurf->saved_width; |
| 3185 | height = shsurf->saved_height; |
| 3186 | shsurf->saved_size_valid = false; |
| 3187 | } else { |
| 3188 | width = shsurf->surface->width; |
| 3189 | height = shsurf->surface->height; |
| 3190 | } |
| 3191 | |
| 3192 | shsurf->client->send_configure(shsurf->surface, 0, width, height); |
Rafael Antognolli | e2a3455 | 2013-12-03 15:35:45 -0200 | [diff] [blame] | 3193 | } |
| 3194 | |
| 3195 | static const struct xdg_surface_interface xdg_surface_implementation = { |
| 3196 | xdg_surface_destroy, |
| 3197 | xdg_surface_set_transient_for, |
| 3198 | xdg_surface_set_title, |
| 3199 | xdg_surface_set_app_id, |
| 3200 | xdg_surface_pong, |
| 3201 | xdg_surface_move, |
| 3202 | xdg_surface_resize, |
| 3203 | xdg_surface_set_output, |
| 3204 | xdg_surface_set_fullscreen, |
| 3205 | xdg_surface_unset_fullscreen, |
| 3206 | xdg_surface_set_maximized, |
| 3207 | xdg_surface_unset_maximized, |
| 3208 | NULL /* set_minimized */ |
| 3209 | }; |
| 3210 | |
| 3211 | static void |
| 3212 | xdg_send_configure(struct weston_surface *surface, |
| 3213 | uint32_t edges, int32_t width, int32_t height) |
| 3214 | { |
| 3215 | struct shell_surface *shsurf = get_shell_surface(surface); |
| 3216 | |
| 3217 | xdg_surface_send_configure(shsurf->resource, edges, width, height); |
| 3218 | } |
| 3219 | |
| 3220 | static const struct weston_shell_client xdg_client = { |
| 3221 | xdg_send_configure |
| 3222 | }; |
| 3223 | |
| 3224 | static void |
| 3225 | xdg_use_unstable_version(struct wl_client *client, |
| 3226 | struct wl_resource *resource, |
| 3227 | int32_t version) |
| 3228 | { |
| 3229 | if (version > 1) { |
| 3230 | wl_resource_post_error(resource, |
| 3231 | 1, |
| 3232 | "xdg-shell:: version not implemented yet."); |
| 3233 | return; |
| 3234 | } |
| 3235 | } |
| 3236 | |
| 3237 | static struct shell_surface * |
| 3238 | create_xdg_surface(void *shell, struct weston_surface *surface, |
| 3239 | const struct weston_shell_client *client) |
| 3240 | { |
| 3241 | struct shell_surface *shsurf; |
Rafael Antognolli | e2a3455 | 2013-12-03 15:35:45 -0200 | [diff] [blame] | 3242 | |
Kristian Høgsberg | c8f8dd8 | 2013-12-05 23:20:33 -0800 | [diff] [blame] | 3243 | shsurf = create_common_surface(shell, surface, client); |
| 3244 | shsurf->type = SHELL_SURFACE_TOPLEVEL; |
Rafael Antognolli | e2a3455 | 2013-12-03 15:35:45 -0200 | [diff] [blame] | 3245 | |
| 3246 | return shsurf; |
| 3247 | } |
| 3248 | |
| 3249 | static void |
| 3250 | xdg_get_xdg_surface(struct wl_client *client, |
| 3251 | struct wl_resource *resource, |
| 3252 | uint32_t id, |
| 3253 | struct wl_resource *surface_resource) |
| 3254 | { |
| 3255 | struct weston_surface *surface = |
| 3256 | wl_resource_get_user_data(surface_resource); |
| 3257 | struct desktop_shell *shell = wl_resource_get_user_data(resource); |
| 3258 | struct shell_surface *shsurf; |
| 3259 | |
| 3260 | if (get_shell_surface(surface)) { |
| 3261 | wl_resource_post_error(surface_resource, |
| 3262 | WL_DISPLAY_ERROR_INVALID_OBJECT, |
| 3263 | "desktop_shell::get_shell_surface already requested"); |
| 3264 | return; |
| 3265 | } |
| 3266 | |
| 3267 | shsurf = create_xdg_surface(shell, surface, &xdg_client); |
| 3268 | if (!shsurf) { |
| 3269 | wl_resource_post_error(surface_resource, |
| 3270 | WL_DISPLAY_ERROR_INVALID_OBJECT, |
| 3271 | "surface->configure already set"); |
| 3272 | return; |
| 3273 | } |
| 3274 | |
| 3275 | shsurf->resource = |
| 3276 | wl_resource_create(client, |
| 3277 | &xdg_surface_interface, 1, id); |
| 3278 | wl_resource_set_implementation(shsurf->resource, |
| 3279 | &xdg_surface_implementation, |
| 3280 | shsurf, shell_destroy_shell_surface); |
| 3281 | } |
| 3282 | |
| 3283 | static bool |
| 3284 | shell_surface_is_xdg_surface(struct shell_surface *shsurf) |
| 3285 | { |
| 3286 | return wl_resource_instance_of(shsurf->resource, |
| 3287 | &xdg_surface_interface, |
| 3288 | &xdg_surface_implementation); |
| 3289 | } |
| 3290 | |
| 3291 | /* xdg-popup implementation */ |
| 3292 | |
| 3293 | static void |
| 3294 | xdg_popup_destroy(struct wl_client *client, |
| 3295 | struct wl_resource *resource) |
| 3296 | { |
| 3297 | wl_resource_destroy(resource); |
| 3298 | } |
| 3299 | |
| 3300 | static void |
| 3301 | xdg_popup_pong(struct wl_client *client, |
| 3302 | struct wl_resource *resource, |
| 3303 | uint32_t serial) |
| 3304 | { |
| 3305 | struct shell_surface *shsurf = wl_resource_get_user_data(resource); |
| 3306 | |
| 3307 | surface_pong(shsurf, serial); |
| 3308 | } |
| 3309 | |
| 3310 | static const struct xdg_popup_interface xdg_popup_implementation = { |
| 3311 | xdg_popup_destroy, |
| 3312 | xdg_popup_pong |
| 3313 | }; |
| 3314 | |
| 3315 | static void |
| 3316 | xdg_popup_send_configure(struct weston_surface *surface, |
| 3317 | uint32_t edges, int32_t width, int32_t height) |
| 3318 | { |
| 3319 | } |
| 3320 | |
| 3321 | static const struct weston_shell_client xdg_popup_client = { |
| 3322 | xdg_popup_send_configure |
| 3323 | }; |
| 3324 | |
| 3325 | static struct shell_surface * |
| 3326 | create_xdg_popup(void *shell, struct weston_surface *surface, |
| 3327 | const struct weston_shell_client *client, |
| 3328 | struct weston_surface *parent, |
| 3329 | struct shell_seat *seat, |
| 3330 | uint32_t serial, |
| 3331 | int32_t x, int32_t y) |
| 3332 | { |
| 3333 | struct shell_surface *shsurf; |
Rafael Antognolli | e2a3455 | 2013-12-03 15:35:45 -0200 | [diff] [blame] | 3334 | |
Kristian Høgsberg | c8f8dd8 | 2013-12-05 23:20:33 -0800 | [diff] [blame] | 3335 | shsurf = create_common_surface(shell, surface, client); |
| 3336 | shsurf->type = SHELL_SURFACE_POPUP; |
Rafael Antognolli | e2a3455 | 2013-12-03 15:35:45 -0200 | [diff] [blame] | 3337 | shsurf->popup.shseat = seat; |
| 3338 | shsurf->popup.serial = serial; |
| 3339 | shsurf->popup.x = x; |
| 3340 | shsurf->popup.y = y; |
| 3341 | shell_surface_set_parent(shsurf, parent); |
| 3342 | |
| 3343 | return shsurf; |
| 3344 | } |
| 3345 | |
| 3346 | static void |
| 3347 | xdg_get_xdg_popup(struct wl_client *client, |
| 3348 | struct wl_resource *resource, |
| 3349 | uint32_t id, |
| 3350 | struct wl_resource *surface_resource, |
| 3351 | struct wl_resource *parent_resource, |
| 3352 | struct wl_resource *seat_resource, |
| 3353 | uint32_t serial, |
| 3354 | int32_t x, int32_t y, uint32_t flags) |
| 3355 | { |
| 3356 | struct weston_surface *surface = |
| 3357 | wl_resource_get_user_data(surface_resource); |
| 3358 | struct desktop_shell *shell = wl_resource_get_user_data(resource); |
| 3359 | struct shell_surface *shsurf; |
| 3360 | struct weston_surface *parent; |
| 3361 | struct shell_seat *seat; |
| 3362 | |
| 3363 | if (get_shell_surface(surface)) { |
| 3364 | wl_resource_post_error(surface_resource, |
| 3365 | WL_DISPLAY_ERROR_INVALID_OBJECT, |
| 3366 | "desktop_shell::get_shell_surface already requested"); |
| 3367 | return; |
| 3368 | } |
| 3369 | |
| 3370 | if (!parent_resource) { |
| 3371 | wl_resource_post_error(surface_resource, |
| 3372 | WL_DISPLAY_ERROR_INVALID_OBJECT, |
| 3373 | "xdg_shell::get_xdg_popup requires a parent shell surface"); |
| 3374 | } |
| 3375 | |
| 3376 | parent = wl_resource_get_user_data(parent_resource); |
| 3377 | seat = get_shell_seat(wl_resource_get_user_data(seat_resource));; |
| 3378 | |
| 3379 | shsurf = create_xdg_popup(shell, surface, &xdg_popup_client, |
| 3380 | parent, seat, serial, x, y); |
| 3381 | if (!shsurf) { |
| 3382 | wl_resource_post_error(surface_resource, |
| 3383 | WL_DISPLAY_ERROR_INVALID_OBJECT, |
| 3384 | "surface->configure already set"); |
| 3385 | return; |
| 3386 | } |
| 3387 | |
| 3388 | shsurf->resource = |
| 3389 | wl_resource_create(client, |
| 3390 | &xdg_popup_interface, 1, id); |
| 3391 | wl_resource_set_implementation(shsurf->resource, |
| 3392 | &xdg_popup_implementation, |
| 3393 | shsurf, shell_destroy_shell_surface); |
| 3394 | } |
| 3395 | |
| 3396 | static bool |
| 3397 | shell_surface_is_xdg_popup(struct shell_surface *shsurf) |
| 3398 | { |
| 3399 | return wl_resource_instance_of(shsurf->resource, |
| 3400 | &xdg_popup_interface, |
| 3401 | &xdg_popup_implementation); |
| 3402 | } |
| 3403 | |
| 3404 | static const struct xdg_shell_interface xdg_implementation = { |
| 3405 | xdg_use_unstable_version, |
| 3406 | xdg_get_xdg_surface, |
| 3407 | xdg_get_xdg_popup |
| 3408 | }; |
| 3409 | |
| 3410 | static int |
| 3411 | xdg_shell_unversioned_dispatch(const void *implementation, |
| 3412 | void *_target, uint32_t opcode, |
| 3413 | const struct wl_message *message, |
| 3414 | union wl_argument *args) |
| 3415 | { |
| 3416 | struct wl_resource *resource = _target; |
| 3417 | struct desktop_shell *shell = wl_resource_get_user_data(resource); |
| 3418 | |
| 3419 | if (opcode != 0) { |
| 3420 | wl_resource_post_error(resource, |
| 3421 | WL_DISPLAY_ERROR_INVALID_OBJECT, |
| 3422 | "must call use_unstable_version first"); |
| 3423 | return 0; |
| 3424 | } |
| 3425 | |
| 3426 | #define XDG_SERVER_VERSION 1 |
| 3427 | |
Kristian Høgsberg | 8d344a0 | 2013-12-08 22:27:11 -0800 | [diff] [blame] | 3428 | static_assert(XDG_SERVER_VERSION == XDG_SHELL_VERSION_CURRENT, |
| 3429 | "shell implementation doesn't match protocol version"); |
| 3430 | |
Rafael Antognolli | e2a3455 | 2013-12-03 15:35:45 -0200 | [diff] [blame] | 3431 | if (args[0].i != XDG_SERVER_VERSION) { |
| 3432 | wl_resource_post_error(resource, |
| 3433 | WL_DISPLAY_ERROR_INVALID_OBJECT, |
| 3434 | "incompatible version, server is %d " |
| 3435 | "client wants %d", |
| 3436 | XDG_SERVER_VERSION, args[0].i); |
| 3437 | return 0; |
| 3438 | } |
| 3439 | |
| 3440 | wl_resource_set_implementation(resource, &xdg_implementation, |
| 3441 | shell, NULL); |
| 3442 | |
| 3443 | return 1; |
| 3444 | } |
| 3445 | |
| 3446 | /* end of xdg-shell implementation */ |
| 3447 | /***********************************/ |
| 3448 | |
Kristian Høgsberg | 0793756 | 2011-04-12 17:25:42 -0400 | [diff] [blame] | 3449 | static void |
Ander Conselvan de Oliveira | 859e885 | 2013-02-21 18:35:21 +0200 | [diff] [blame] | 3450 | shell_fade(struct desktop_shell *shell, enum fade_type type); |
| 3451 | |
| 3452 | static int |
| 3453 | screensaver_timeout(void *data) |
| 3454 | { |
| 3455 | struct desktop_shell *shell = data; |
| 3456 | |
| 3457 | shell_fade(shell, FADE_OUT); |
| 3458 | |
| 3459 | return 1; |
| 3460 | } |
| 3461 | |
| 3462 | static void |
Kristian Høgsberg | 8334bc1 | 2012-01-03 10:29:47 -0500 | [diff] [blame] | 3463 | handle_screensaver_sigchld(struct weston_process *proc, int status) |
Pekka Paalanen | 18027e5 | 2011-12-02 16:31:49 +0200 | [diff] [blame] | 3464 | { |
Ander Conselvan de Oliveira | 18639f8 | 2013-02-15 18:44:19 +0200 | [diff] [blame] | 3465 | struct desktop_shell *shell = |
| 3466 | container_of(proc, struct desktop_shell, screensaver.process); |
Ander Conselvan de Oliveira | 18639f8 | 2013-02-15 18:44:19 +0200 | [diff] [blame] | 3467 | |
Pekka Paalanen | 18027e5 | 2011-12-02 16:31:49 +0200 | [diff] [blame] | 3468 | proc->pid = 0; |
Ander Conselvan de Oliveira | 18639f8 | 2013-02-15 18:44:19 +0200 | [diff] [blame] | 3469 | |
| 3470 | if (shell->locked) |
Ander Conselvan de Oliveira | b17537e | 2013-02-22 14:16:18 +0200 | [diff] [blame] | 3471 | weston_compositor_sleep(shell->compositor); |
Pekka Paalanen | 18027e5 | 2011-12-02 16:31:49 +0200 | [diff] [blame] | 3472 | } |
| 3473 | |
| 3474 | static void |
Tiago Vignatti | be14326 | 2012-04-16 17:31:41 +0300 | [diff] [blame] | 3475 | launch_screensaver(struct desktop_shell *shell) |
Pekka Paalanen | 77346a6 | 2011-11-30 16:26:35 +0200 | [diff] [blame] | 3476 | { |
| 3477 | if (shell->screensaver.binding) |
| 3478 | return; |
| 3479 | |
Ander Conselvan de Oliveira | dda9d78 | 2013-02-22 14:16:19 +0200 | [diff] [blame] | 3480 | if (!shell->screensaver.path) { |
| 3481 | weston_compositor_sleep(shell->compositor); |
Pekka Paalanen | e955f1e | 2011-12-07 11:49:52 +0200 | [diff] [blame] | 3482 | return; |
Ander Conselvan de Oliveira | dda9d78 | 2013-02-22 14:16:19 +0200 | [diff] [blame] | 3483 | } |
Pekka Paalanen | e955f1e | 2011-12-07 11:49:52 +0200 | [diff] [blame] | 3484 | |
Kristian Høgsberg | 32bed57 | 2012-03-01 17:11:36 -0500 | [diff] [blame] | 3485 | if (shell->screensaver.process.pid != 0) { |
Martin Minarik | 6d11836 | 2012-06-07 18:01:59 +0200 | [diff] [blame] | 3486 | weston_log("old screensaver still running\n"); |
Kristian Høgsberg | 32bed57 | 2012-03-01 17:11:36 -0500 | [diff] [blame] | 3487 | return; |
| 3488 | } |
| 3489 | |
Kristian Høgsberg | 8334bc1 | 2012-01-03 10:29:47 -0500 | [diff] [blame] | 3490 | weston_client_launch(shell->compositor, |
Pekka Paalanen | 18027e5 | 2011-12-02 16:31:49 +0200 | [diff] [blame] | 3491 | &shell->screensaver.process, |
Pekka Paalanen | e955f1e | 2011-12-07 11:49:52 +0200 | [diff] [blame] | 3492 | shell->screensaver.path, |
Pekka Paalanen | 18027e5 | 2011-12-02 16:31:49 +0200 | [diff] [blame] | 3493 | handle_screensaver_sigchld); |
Pekka Paalanen | 77346a6 | 2011-11-30 16:26:35 +0200 | [diff] [blame] | 3494 | } |
| 3495 | |
| 3496 | static void |
Tiago Vignatti | be14326 | 2012-04-16 17:31:41 +0300 | [diff] [blame] | 3497 | terminate_screensaver(struct desktop_shell *shell) |
Pekka Paalanen | 77346a6 | 2011-11-30 16:26:35 +0200 | [diff] [blame] | 3498 | { |
Pekka Paalanen | 18027e5 | 2011-12-02 16:31:49 +0200 | [diff] [blame] | 3499 | if (shell->screensaver.process.pid == 0) |
| 3500 | return; |
| 3501 | |
| 3502 | kill(shell->screensaver.process.pid, SIGTERM); |
Pekka Paalanen | 77346a6 | 2011-11-30 16:26:35 +0200 | [diff] [blame] | 3503 | } |
| 3504 | |
| 3505 | static void |
Jason Ekstrand | 918f2dd | 2013-12-02 21:01:53 -0600 | [diff] [blame] | 3506 | configure_static_view(struct weston_view *ev, struct weston_layer *layer) |
Kristian Høgsberg | 962342c | 2012-06-26 16:29:50 -0400 | [diff] [blame] | 3507 | { |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 3508 | struct weston_view *v, *next; |
Kristian Høgsberg | 962342c | 2012-06-26 16:29:50 -0400 | [diff] [blame] | 3509 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 3510 | wl_list_for_each_safe(v, next, &layer->view_list, layer_link) { |
| 3511 | if (v->output == ev->output && v != ev) { |
| 3512 | weston_view_unmap(v); |
| 3513 | v->surface->configure = NULL; |
Kristian Høgsberg | 962342c | 2012-06-26 16:29:50 -0400 | [diff] [blame] | 3514 | } |
| 3515 | } |
| 3516 | |
Jason Ekstrand | 918f2dd | 2013-12-02 21:01:53 -0600 | [diff] [blame] | 3517 | weston_view_set_position(ev, ev->output->x, ev->output->y); |
Kristian Høgsberg | 962342c | 2012-06-26 16:29:50 -0400 | [diff] [blame] | 3518 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 3519 | if (wl_list_empty(&ev->layer_link)) { |
| 3520 | wl_list_insert(&layer->view_list, &ev->layer_link); |
| 3521 | weston_compositor_schedule_repaint(ev->surface->compositor); |
Kristian Høgsberg | 962342c | 2012-06-26 16:29:50 -0400 | [diff] [blame] | 3522 | } |
| 3523 | } |
| 3524 | |
| 3525 | static void |
Jason Ekstrand | 918f2dd | 2013-12-02 21:01:53 -0600 | [diff] [blame] | 3526 | background_configure(struct weston_surface *es, int32_t sx, int32_t sy) |
Kristian Høgsberg | af7b1ff | 2012-06-26 21:19:23 -0400 | [diff] [blame] | 3527 | { |
Giulio Camuffo | 7fe01b1 | 2013-03-28 18:02:42 +0100 | [diff] [blame] | 3528 | struct desktop_shell *shell = es->configure_private; |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 3529 | struct weston_view *view; |
Kristian Høgsberg | af7b1ff | 2012-06-26 21:19:23 -0400 | [diff] [blame] | 3530 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 3531 | view = container_of(es->views.next, struct weston_view, surface_link); |
| 3532 | |
Jason Ekstrand | 918f2dd | 2013-12-02 21:01:53 -0600 | [diff] [blame] | 3533 | configure_static_view(view, &shell->background_layer); |
Kristian Høgsberg | af7b1ff | 2012-06-26 21:19:23 -0400 | [diff] [blame] | 3534 | } |
| 3535 | |
| 3536 | static void |
Kristian Høgsberg | 7584062 | 2011-09-06 13:48:16 -0400 | [diff] [blame] | 3537 | desktop_shell_set_background(struct wl_client *client, |
| 3538 | struct wl_resource *resource, |
Benjamin Franzke | d0f79ab | 2011-11-22 12:43:52 +0100 | [diff] [blame] | 3539 | struct wl_resource *output_resource, |
Kristian Høgsberg | 7584062 | 2011-09-06 13:48:16 -0400 | [diff] [blame] | 3540 | struct wl_resource *surface_resource) |
| 3541 | { |
Jason Ekstrand | 651f00e | 2013-06-14 10:07:54 -0500 | [diff] [blame] | 3542 | struct desktop_shell *shell = wl_resource_get_user_data(resource); |
Jason Ekstrand | 0f2ef7e | 2013-06-14 10:07:53 -0500 | [diff] [blame] | 3543 | struct weston_surface *surface = |
| 3544 | wl_resource_get_user_data(surface_resource); |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 3545 | struct weston_view *view, *next; |
Kristian Høgsberg | 7584062 | 2011-09-06 13:48:16 -0400 | [diff] [blame] | 3546 | |
Kristian Høgsberg | 962342c | 2012-06-26 16:29:50 -0400 | [diff] [blame] | 3547 | if (surface->configure) { |
| 3548 | wl_resource_post_error(surface_resource, |
| 3549 | WL_DISPLAY_ERROR_INVALID_OBJECT, |
| 3550 | "surface role already assigned"); |
| 3551 | return; |
| 3552 | } |
Benjamin Franzke | d0f79ab | 2011-11-22 12:43:52 +0100 | [diff] [blame] | 3553 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 3554 | wl_list_for_each_safe(view, next, &surface->views, surface_link) |
| 3555 | weston_view_destroy(view); |
| 3556 | view = weston_view_create(surface); |
| 3557 | |
Kristian Høgsberg | 962342c | 2012-06-26 16:29:50 -0400 | [diff] [blame] | 3558 | surface->configure = background_configure; |
Giulio Camuffo | 7fe01b1 | 2013-03-28 18:02:42 +0100 | [diff] [blame] | 3559 | surface->configure_private = shell; |
Jason Ekstrand | a0d2dde | 2013-06-14 10:08:01 -0500 | [diff] [blame] | 3560 | surface->output = wl_resource_get_user_data(output_resource); |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 3561 | view->output = surface->output; |
Kristian Høgsberg | eae5de7 | 2012-04-11 22:42:15 -0400 | [diff] [blame] | 3562 | desktop_shell_send_configure(resource, 0, |
Kristian Høgsberg | 0b5cd0c | 2012-03-04 21:57:37 -0500 | [diff] [blame] | 3563 | surface_resource, |
Scott Moreau | 1bad5db | 2012-08-18 01:04:05 -0600 | [diff] [blame] | 3564 | surface->output->width, |
| 3565 | surface->output->height); |
Kristian Høgsberg | 7584062 | 2011-09-06 13:48:16 -0400 | [diff] [blame] | 3566 | } |
| 3567 | |
| 3568 | static void |
Jason Ekstrand | 918f2dd | 2013-12-02 21:01:53 -0600 | [diff] [blame] | 3569 | panel_configure(struct weston_surface *es, int32_t sx, int32_t sy) |
Kristian Høgsberg | af7b1ff | 2012-06-26 21:19:23 -0400 | [diff] [blame] | 3570 | { |
Giulio Camuffo | 7fe01b1 | 2013-03-28 18:02:42 +0100 | [diff] [blame] | 3571 | struct desktop_shell *shell = es->configure_private; |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 3572 | struct weston_view *view; |
Kristian Høgsberg | af7b1ff | 2012-06-26 21:19:23 -0400 | [diff] [blame] | 3573 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 3574 | view = container_of(es->views.next, struct weston_view, surface_link); |
| 3575 | |
Jason Ekstrand | 918f2dd | 2013-12-02 21:01:53 -0600 | [diff] [blame] | 3576 | configure_static_view(view, &shell->panel_layer); |
Kristian Høgsberg | af7b1ff | 2012-06-26 21:19:23 -0400 | [diff] [blame] | 3577 | } |
| 3578 | |
| 3579 | static void |
Kristian Høgsberg | 7584062 | 2011-09-06 13:48:16 -0400 | [diff] [blame] | 3580 | desktop_shell_set_panel(struct wl_client *client, |
| 3581 | struct wl_resource *resource, |
Benjamin Franzke | d0f79ab | 2011-11-22 12:43:52 +0100 | [diff] [blame] | 3582 | struct wl_resource *output_resource, |
Kristian Høgsberg | 7584062 | 2011-09-06 13:48:16 -0400 | [diff] [blame] | 3583 | struct wl_resource *surface_resource) |
| 3584 | { |
Jason Ekstrand | 651f00e | 2013-06-14 10:07:54 -0500 | [diff] [blame] | 3585 | struct desktop_shell *shell = wl_resource_get_user_data(resource); |
Jason Ekstrand | 0f2ef7e | 2013-06-14 10:07:53 -0500 | [diff] [blame] | 3586 | struct weston_surface *surface = |
| 3587 | wl_resource_get_user_data(surface_resource); |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 3588 | struct weston_view *view, *next; |
Kristian Høgsberg | 7584062 | 2011-09-06 13:48:16 -0400 | [diff] [blame] | 3589 | |
Kristian Høgsberg | af7b1ff | 2012-06-26 21:19:23 -0400 | [diff] [blame] | 3590 | if (surface->configure) { |
| 3591 | wl_resource_post_error(surface_resource, |
| 3592 | WL_DISPLAY_ERROR_INVALID_OBJECT, |
| 3593 | "surface role already assigned"); |
| 3594 | return; |
| 3595 | } |
Benjamin Franzke | d0f79ab | 2011-11-22 12:43:52 +0100 | [diff] [blame] | 3596 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 3597 | wl_list_for_each_safe(view, next, &surface->views, surface_link) |
| 3598 | weston_view_destroy(view); |
| 3599 | view = weston_view_create(surface); |
| 3600 | |
Kristian Høgsberg | af7b1ff | 2012-06-26 21:19:23 -0400 | [diff] [blame] | 3601 | surface->configure = panel_configure; |
Giulio Camuffo | 7fe01b1 | 2013-03-28 18:02:42 +0100 | [diff] [blame] | 3602 | surface->configure_private = shell; |
Jason Ekstrand | a0d2dde | 2013-06-14 10:08:01 -0500 | [diff] [blame] | 3603 | surface->output = wl_resource_get_user_data(output_resource); |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 3604 | view->output = surface->output; |
Kristian Høgsberg | eae5de7 | 2012-04-11 22:42:15 -0400 | [diff] [blame] | 3605 | desktop_shell_send_configure(resource, 0, |
Kristian Høgsberg | af7b1ff | 2012-06-26 21:19:23 -0400 | [diff] [blame] | 3606 | surface_resource, |
Scott Moreau | 1bad5db | 2012-08-18 01:04:05 -0600 | [diff] [blame] | 3607 | surface->output->width, |
| 3608 | surface->output->height); |
Kristian Høgsberg | 7584062 | 2011-09-06 13:48:16 -0400 | [diff] [blame] | 3609 | } |
| 3610 | |
Pekka Paalanen | 9ef3e01 | 2011-11-15 13:34:48 +0200 | [diff] [blame] | 3611 | static void |
Jason Ekstrand | 918f2dd | 2013-12-02 21:01:53 -0600 | [diff] [blame] | 3612 | lock_surface_configure(struct weston_surface *surface, int32_t sx, int32_t sy) |
Kristian Høgsberg | 730c94d | 2012-06-26 21:44:35 -0400 | [diff] [blame] | 3613 | { |
Giulio Camuffo | 7fe01b1 | 2013-03-28 18:02:42 +0100 | [diff] [blame] | 3614 | struct desktop_shell *shell = surface->configure_private; |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 3615 | struct weston_view *view; |
| 3616 | |
| 3617 | view = container_of(surface->views.next, struct weston_view, surface_link); |
Kristian Høgsberg | 730c94d | 2012-06-26 21:44:35 -0400 | [diff] [blame] | 3618 | |
Jason Ekstrand | 918f2dd | 2013-12-02 21:01:53 -0600 | [diff] [blame] | 3619 | if (surface->width == 0) |
Giulio Camuffo | 184df50 | 2013-02-21 11:29:21 +0100 | [diff] [blame] | 3620 | return; |
| 3621 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 3622 | center_on_output(view, get_default_output(shell->compositor)); |
Kristian Høgsberg | 730c94d | 2012-06-26 21:44:35 -0400 | [diff] [blame] | 3623 | |
| 3624 | if (!weston_surface_is_mapped(surface)) { |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 3625 | wl_list_insert(&shell->lock_layer.view_list, |
| 3626 | &view->layer_link); |
| 3627 | weston_view_update_transform(view); |
Ander Conselvan de Oliveira | 87524b6 | 2013-02-21 18:35:22 +0200 | [diff] [blame] | 3628 | shell_fade(shell, FADE_IN); |
Kristian Høgsberg | 730c94d | 2012-06-26 21:44:35 -0400 | [diff] [blame] | 3629 | } |
| 3630 | } |
| 3631 | |
| 3632 | static void |
Kristian Høgsberg | 27e3052 | 2012-04-11 23:18:23 -0400 | [diff] [blame] | 3633 | handle_lock_surface_destroy(struct wl_listener *listener, void *data) |
Kristian Høgsberg | 1ec0c31 | 2011-11-15 16:39:55 -0500 | [diff] [blame] | 3634 | { |
Tiago Vignatti | be14326 | 2012-04-16 17:31:41 +0300 | [diff] [blame] | 3635 | struct desktop_shell *shell = |
| 3636 | container_of(listener, struct desktop_shell, lock_surface_listener); |
Kristian Høgsberg | 1ec0c31 | 2011-11-15 16:39:55 -0500 | [diff] [blame] | 3637 | |
Martin Minarik | 6d11836 | 2012-06-07 18:01:59 +0200 | [diff] [blame] | 3638 | weston_log("lock surface gone\n"); |
Kristian Høgsberg | 1ec0c31 | 2011-11-15 16:39:55 -0500 | [diff] [blame] | 3639 | shell->lock_surface = NULL; |
| 3640 | } |
| 3641 | |
| 3642 | static void |
Pekka Paalanen | 9ef3e01 | 2011-11-15 13:34:48 +0200 | [diff] [blame] | 3643 | desktop_shell_set_lock_surface(struct wl_client *client, |
| 3644 | struct wl_resource *resource, |
| 3645 | struct wl_resource *surface_resource) |
| 3646 | { |
Jason Ekstrand | 651f00e | 2013-06-14 10:07:54 -0500 | [diff] [blame] | 3647 | struct desktop_shell *shell = wl_resource_get_user_data(resource); |
Jason Ekstrand | 0f2ef7e | 2013-06-14 10:07:53 -0500 | [diff] [blame] | 3648 | struct weston_surface *surface = |
| 3649 | wl_resource_get_user_data(surface_resource); |
Pekka Paalanen | 9826223 | 2011-12-01 10:42:22 +0200 | [diff] [blame] | 3650 | |
Pekka Paalanen | f0fc70d | 2011-11-15 13:34:54 +0200 | [diff] [blame] | 3651 | shell->prepare_event_sent = false; |
Kristian Høgsberg | af867cc | 2011-11-15 13:34:49 +0200 | [diff] [blame] | 3652 | |
Pekka Paalanen | f0fc70d | 2011-11-15 13:34:54 +0200 | [diff] [blame] | 3653 | if (!shell->locked) |
| 3654 | return; |
| 3655 | |
Pekka Paalanen | 9826223 | 2011-12-01 10:42:22 +0200 | [diff] [blame] | 3656 | shell->lock_surface = surface; |
Pekka Paalanen | f0fc70d | 2011-11-15 13:34:54 +0200 | [diff] [blame] | 3657 | |
Kristian Høgsberg | 27e3052 | 2012-04-11 23:18:23 -0400 | [diff] [blame] | 3658 | shell->lock_surface_listener.notify = handle_lock_surface_destroy; |
Jason Ekstrand | 651f00e | 2013-06-14 10:07:54 -0500 | [diff] [blame] | 3659 | wl_signal_add(&surface->destroy_signal, |
Kristian Høgsberg | 27e3052 | 2012-04-11 23:18:23 -0400 | [diff] [blame] | 3660 | &shell->lock_surface_listener); |
Pekka Paalanen | 57da4a8 | 2011-11-23 16:42:16 +0200 | [diff] [blame] | 3661 | |
Kristian Høgsberg | aa2ee8b | 2013-10-30 15:49:45 -0700 | [diff] [blame] | 3662 | weston_view_create(surface); |
Kristian Høgsberg | 730c94d | 2012-06-26 21:44:35 -0400 | [diff] [blame] | 3663 | surface->configure = lock_surface_configure; |
Giulio Camuffo | 7fe01b1 | 2013-03-28 18:02:42 +0100 | [diff] [blame] | 3664 | surface->configure_private = shell; |
Pekka Paalanen | f0fc70d | 2011-11-15 13:34:54 +0200 | [diff] [blame] | 3665 | } |
| 3666 | |
| 3667 | static void |
Tiago Vignatti | be14326 | 2012-04-16 17:31:41 +0300 | [diff] [blame] | 3668 | resume_desktop(struct desktop_shell *shell) |
Pekka Paalanen | f0fc70d | 2011-11-15 13:34:54 +0200 | [diff] [blame] | 3669 | { |
Kristian Høgsberg | 4476aaf | 2012-06-25 14:03:13 -0400 | [diff] [blame] | 3670 | struct workspace *ws = get_current_workspace(shell); |
Pekka Paalanen | 77346a6 | 2011-11-30 16:26:35 +0200 | [diff] [blame] | 3671 | |
Pekka Paalanen | 77346a6 | 2011-11-30 16:26:35 +0200 | [diff] [blame] | 3672 | terminate_screensaver(shell); |
Pekka Paalanen | f0fc70d | 2011-11-15 13:34:54 +0200 | [diff] [blame] | 3673 | |
Kristian Høgsberg | 3be2ce9 | 2012-02-29 12:42:35 -0500 | [diff] [blame] | 3674 | wl_list_remove(&shell->lock_layer.link); |
| 3675 | wl_list_insert(&shell->compositor->cursor_layer.link, |
| 3676 | &shell->fullscreen_layer.link); |
| 3677 | wl_list_insert(&shell->fullscreen_layer.link, |
| 3678 | &shell->panel_layer.link); |
Philipp Brüschweiler | 711fda8 | 2012-08-09 18:50:43 +0200 | [diff] [blame] | 3679 | if (shell->showing_input_panels) { |
| 3680 | wl_list_insert(&shell->panel_layer.link, |
| 3681 | &shell->input_panel_layer.link); |
| 3682 | wl_list_insert(&shell->input_panel_layer.link, |
| 3683 | &ws->layer.link); |
| 3684 | } else { |
| 3685 | wl_list_insert(&shell->panel_layer.link, &ws->layer.link); |
| 3686 | } |
Pekka Paalanen | f0fc70d | 2011-11-15 13:34:54 +0200 | [diff] [blame] | 3687 | |
Kristian Høgsberg | 2f5faff | 2012-07-31 16:36:34 -0400 | [diff] [blame] | 3688 | restore_focus_state(shell, get_current_workspace(shell)); |
Jonas Ådahl | 0476974 | 2012-06-13 00:01:24 +0200 | [diff] [blame] | 3689 | |
Pekka Paalanen | f0fc70d | 2011-11-15 13:34:54 +0200 | [diff] [blame] | 3690 | shell->locked = false; |
Ander Conselvan de Oliveira | 87524b6 | 2013-02-21 18:35:22 +0200 | [diff] [blame] | 3691 | shell_fade(shell, FADE_IN); |
Pekka Paalanen | fc6d91a | 2012-02-10 15:33:10 +0200 | [diff] [blame] | 3692 | weston_compositor_damage_all(shell->compositor); |
Pekka Paalanen | 9ef3e01 | 2011-11-15 13:34:48 +0200 | [diff] [blame] | 3693 | } |
| 3694 | |
| 3695 | static void |
| 3696 | desktop_shell_unlock(struct wl_client *client, |
| 3697 | struct wl_resource *resource) |
| 3698 | { |
Jason Ekstrand | 651f00e | 2013-06-14 10:07:54 -0500 | [diff] [blame] | 3699 | struct desktop_shell *shell = wl_resource_get_user_data(resource); |
Pekka Paalanen | 9ef3e01 | 2011-11-15 13:34:48 +0200 | [diff] [blame] | 3700 | |
Pekka Paalanen | 9ef3e01 | 2011-11-15 13:34:48 +0200 | [diff] [blame] | 3701 | shell->prepare_event_sent = false; |
Pekka Paalanen | f0fc70d | 2011-11-15 13:34:54 +0200 | [diff] [blame] | 3702 | |
| 3703 | if (shell->locked) |
| 3704 | resume_desktop(shell); |
Pekka Paalanen | 9ef3e01 | 2011-11-15 13:34:48 +0200 | [diff] [blame] | 3705 | } |
| 3706 | |
Kristian Høgsberg | d56bd90 | 2012-06-05 09:58:51 -0400 | [diff] [blame] | 3707 | static void |
Ander Conselvan de Oliveira | b9d2a0f | 2012-06-28 18:08:05 +0300 | [diff] [blame] | 3708 | desktop_shell_set_grab_surface(struct wl_client *client, |
Kristian Høgsberg | d56bd90 | 2012-06-05 09:58:51 -0400 | [diff] [blame] | 3709 | struct wl_resource *resource, |
| 3710 | struct wl_resource *surface_resource) |
| 3711 | { |
Jason Ekstrand | 651f00e | 2013-06-14 10:07:54 -0500 | [diff] [blame] | 3712 | struct desktop_shell *shell = wl_resource_get_user_data(resource); |
Kristian Høgsberg | d56bd90 | 2012-06-05 09:58:51 -0400 | [diff] [blame] | 3713 | |
Jason Ekstrand | 0f2ef7e | 2013-06-14 10:07:53 -0500 | [diff] [blame] | 3714 | shell->grab_surface = wl_resource_get_user_data(surface_resource); |
Kristian Høgsberg | 48588f8 | 2013-10-24 15:51:35 -0700 | [diff] [blame] | 3715 | weston_view_create(shell->grab_surface); |
Kristian Høgsberg | d56bd90 | 2012-06-05 09:58:51 -0400 | [diff] [blame] | 3716 | } |
| 3717 | |
Pekka Paalanen | 79346ab | 2013-05-22 18:03:09 +0300 | [diff] [blame] | 3718 | static void |
| 3719 | desktop_shell_desktop_ready(struct wl_client *client, |
| 3720 | struct wl_resource *resource) |
| 3721 | { |
Jason Ekstrand | 651f00e | 2013-06-14 10:07:54 -0500 | [diff] [blame] | 3722 | struct desktop_shell *shell = wl_resource_get_user_data(resource); |
Pekka Paalanen | 79346ab | 2013-05-22 18:03:09 +0300 | [diff] [blame] | 3723 | |
| 3724 | shell_fade_startup(shell); |
| 3725 | } |
| 3726 | |
Kristian Høgsberg | 7584062 | 2011-09-06 13:48:16 -0400 | [diff] [blame] | 3727 | static const struct desktop_shell_interface desktop_shell_implementation = { |
| 3728 | desktop_shell_set_background, |
Pekka Paalanen | 9ef3e01 | 2011-11-15 13:34:48 +0200 | [diff] [blame] | 3729 | desktop_shell_set_panel, |
| 3730 | desktop_shell_set_lock_surface, |
Kristian Høgsberg | d56bd90 | 2012-06-05 09:58:51 -0400 | [diff] [blame] | 3731 | desktop_shell_unlock, |
Pekka Paalanen | 79346ab | 2013-05-22 18:03:09 +0300 | [diff] [blame] | 3732 | desktop_shell_set_grab_surface, |
| 3733 | desktop_shell_desktop_ready |
Kristian Høgsberg | 7584062 | 2011-09-06 13:48:16 -0400 | [diff] [blame] | 3734 | }; |
| 3735 | |
Pekka Paalanen | 92a0dc4 | 2011-11-28 15:34:13 +0200 | [diff] [blame] | 3736 | static enum shell_surface_type |
Kristian Høgsberg | 8334bc1 | 2012-01-03 10:29:47 -0500 | [diff] [blame] | 3737 | get_shell_surface_type(struct weston_surface *surface) |
Pekka Paalanen | 92a0dc4 | 2011-11-28 15:34:13 +0200 | [diff] [blame] | 3738 | { |
| 3739 | struct shell_surface *shsurf; |
| 3740 | |
| 3741 | shsurf = get_shell_surface(surface); |
| 3742 | if (!shsurf) |
Pekka Paalanen | 9826223 | 2011-12-01 10:42:22 +0200 | [diff] [blame] | 3743 | return SHELL_SURFACE_NONE; |
Pekka Paalanen | 92a0dc4 | 2011-11-28 15:34:13 +0200 | [diff] [blame] | 3744 | return shsurf->type; |
| 3745 | } |
| 3746 | |
Kristian Høgsberg | 7584062 | 2011-09-06 13:48:16 -0400 | [diff] [blame] | 3747 | static void |
Kristian Høgsberg | e314875 | 2013-05-06 23:19:49 -0400 | [diff] [blame] | 3748 | move_binding(struct weston_seat *seat, uint32_t time, uint32_t button, void *data) |
Kristian Høgsberg | 0793756 | 2011-04-12 17:25:42 -0400 | [diff] [blame] | 3749 | { |
Kristian Høgsberg | 7ab139c | 2013-10-24 16:21:39 -0700 | [diff] [blame] | 3750 | struct weston_surface *focus = seat->pointer->focus->surface; |
Pekka Paalanen | 01388e2 | 2013-04-25 13:57:44 +0300 | [diff] [blame] | 3751 | struct weston_surface *surface; |
Kristian Høgsberg | 938b8fa | 2012-05-18 13:46:27 -0400 | [diff] [blame] | 3752 | struct shell_surface *shsurf; |
Kristian Høgsberg | d2abb83 | 2011-11-23 10:52:40 -0500 | [diff] [blame] | 3753 | |
Pekka Paalanen | 01388e2 | 2013-04-25 13:57:44 +0300 | [diff] [blame] | 3754 | surface = weston_surface_get_main_surface(focus); |
Benjamin Franzke | d0f79ab | 2011-11-22 12:43:52 +0100 | [diff] [blame] | 3755 | if (surface == NULL) |
| 3756 | return; |
Kristian Høgsberg | 0793756 | 2011-04-12 17:25:42 -0400 | [diff] [blame] | 3757 | |
Kristian Høgsberg | 938b8fa | 2012-05-18 13:46:27 -0400 | [diff] [blame] | 3758 | shsurf = get_shell_surface(surface); |
Rafael Antognolli | 03b1659 | 2013-12-03 15:35:42 -0200 | [diff] [blame] | 3759 | if (shsurf == NULL || shsurf->state.fullscreen || |
| 3760 | shsurf->state.maximized) |
Kristian Høgsberg | 938b8fa | 2012-05-18 13:46:27 -0400 | [diff] [blame] | 3761 | return; |
| 3762 | |
Kristian Høgsberg | 938b8fa | 2012-05-18 13:46:27 -0400 | [diff] [blame] | 3763 | surface_move(shsurf, (struct weston_seat *) seat); |
Kristian Høgsberg | 0793756 | 2011-04-12 17:25:42 -0400 | [diff] [blame] | 3764 | } |
| 3765 | |
| 3766 | static void |
Rafael Antognolli | ea997ac | 2013-12-03 15:35:48 -0200 | [diff] [blame] | 3767 | maximize_binding(struct weston_seat *seat, uint32_t time, uint32_t button, void *data) |
| 3768 | { |
| 3769 | struct weston_surface *focus = seat->pointer->focus->surface; |
| 3770 | struct weston_surface *surface; |
| 3771 | struct shell_surface *shsurf; |
| 3772 | |
| 3773 | surface = weston_surface_get_main_surface(focus); |
| 3774 | if (surface == NULL) |
| 3775 | return; |
| 3776 | |
| 3777 | shsurf = get_shell_surface(surface); |
| 3778 | if (shsurf == NULL) |
| 3779 | return; |
| 3780 | |
| 3781 | if (!shell_surface_is_xdg_surface(shsurf)) |
| 3782 | return; |
| 3783 | |
| 3784 | if (shsurf->state.maximized) |
| 3785 | xdg_surface_send_request_unset_maximized(shsurf->resource); |
| 3786 | else |
| 3787 | xdg_surface_send_request_set_maximized(shsurf->resource); |
| 3788 | } |
| 3789 | |
| 3790 | static void |
| 3791 | fullscreen_binding(struct weston_seat *seat, uint32_t time, uint32_t button, void *data) |
| 3792 | { |
| 3793 | struct weston_surface *focus = seat->pointer->focus->surface; |
| 3794 | struct weston_surface *surface; |
| 3795 | struct shell_surface *shsurf; |
| 3796 | |
| 3797 | surface = weston_surface_get_main_surface(focus); |
| 3798 | if (surface == NULL) |
| 3799 | return; |
| 3800 | |
| 3801 | shsurf = get_shell_surface(surface); |
| 3802 | if (shsurf == NULL) |
| 3803 | return; |
| 3804 | |
| 3805 | if (!shell_surface_is_xdg_surface(shsurf)) |
| 3806 | return; |
| 3807 | |
| 3808 | if (shsurf->state.fullscreen) |
| 3809 | xdg_surface_send_request_unset_fullscreen(shsurf->resource); |
| 3810 | else |
| 3811 | xdg_surface_send_request_set_fullscreen(shsurf->resource); |
| 3812 | } |
| 3813 | |
| 3814 | static void |
Neil Roberts | aba0f25 | 2013-10-03 16:43:05 +0100 | [diff] [blame] | 3815 | touch_move_binding(struct weston_seat *seat, uint32_t time, void *data) |
| 3816 | { |
Kristian Høgsberg | 7ab139c | 2013-10-24 16:21:39 -0700 | [diff] [blame] | 3817 | struct weston_surface *focus = seat->touch->focus->surface; |
Neil Roberts | aba0f25 | 2013-10-03 16:43:05 +0100 | [diff] [blame] | 3818 | struct weston_surface *surface; |
| 3819 | struct shell_surface *shsurf; |
| 3820 | |
| 3821 | surface = weston_surface_get_main_surface(focus); |
| 3822 | if (surface == NULL) |
| 3823 | return; |
| 3824 | |
| 3825 | shsurf = get_shell_surface(surface); |
Rafael Antognolli | 03b1659 | 2013-12-03 15:35:42 -0200 | [diff] [blame] | 3826 | if (shsurf == NULL || shsurf->state.fullscreen || |
| 3827 | shsurf->state.maximized) |
Neil Roberts | aba0f25 | 2013-10-03 16:43:05 +0100 | [diff] [blame] | 3828 | return; |
| 3829 | |
| 3830 | surface_touch_move(shsurf, (struct weston_seat *) seat); |
| 3831 | } |
| 3832 | |
| 3833 | static void |
Kristian Høgsberg | e314875 | 2013-05-06 23:19:49 -0400 | [diff] [blame] | 3834 | 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] | 3835 | { |
Kristian Høgsberg | 7ab139c | 2013-10-24 16:21:39 -0700 | [diff] [blame] | 3836 | struct weston_surface *focus = seat->pointer->focus->surface; |
Pekka Paalanen | 01388e2 | 2013-04-25 13:57:44 +0300 | [diff] [blame] | 3837 | struct weston_surface *surface; |
Kristian Høgsberg | 0793756 | 2011-04-12 17:25:42 -0400 | [diff] [blame] | 3838 | uint32_t edges = 0; |
| 3839 | int32_t x, y; |
Pekka Paalanen | 9d1613e | 2011-11-25 12:09:16 +0200 | [diff] [blame] | 3840 | struct shell_surface *shsurf; |
Kristian Høgsberg | d2abb83 | 2011-11-23 10:52:40 -0500 | [diff] [blame] | 3841 | |
Pekka Paalanen | 01388e2 | 2013-04-25 13:57:44 +0300 | [diff] [blame] | 3842 | surface = weston_surface_get_main_surface(focus); |
Benjamin Franzke | d0f79ab | 2011-11-22 12:43:52 +0100 | [diff] [blame] | 3843 | if (surface == NULL) |
| 3844 | return; |
Pekka Paalanen | 92a0dc4 | 2011-11-28 15:34:13 +0200 | [diff] [blame] | 3845 | |
Pekka Paalanen | 9d1613e | 2011-11-25 12:09:16 +0200 | [diff] [blame] | 3846 | shsurf = get_shell_surface(surface); |
Rafael Antognolli | 03b1659 | 2013-12-03 15:35:42 -0200 | [diff] [blame] | 3847 | if (shsurf == NULL || shsurf->state.fullscreen || |
| 3848 | shsurf->state.maximized) |
Pekka Paalanen | 92a0dc4 | 2011-11-28 15:34:13 +0200 | [diff] [blame] | 3849 | return; |
| 3850 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 3851 | weston_view_from_global(shsurf->view, |
| 3852 | wl_fixed_to_int(seat->pointer->grab_x), |
| 3853 | wl_fixed_to_int(seat->pointer->grab_y), |
| 3854 | &x, &y); |
Kristian Høgsberg | 0793756 | 2011-04-12 17:25:42 -0400 | [diff] [blame] | 3855 | |
Jason Ekstrand | 918f2dd | 2013-12-02 21:01:53 -0600 | [diff] [blame] | 3856 | if (x < shsurf->surface->width / 3) |
Pekka Paalanen | 9d1613e | 2011-11-25 12:09:16 +0200 | [diff] [blame] | 3857 | edges |= WL_SHELL_SURFACE_RESIZE_LEFT; |
Jason Ekstrand | 918f2dd | 2013-12-02 21:01:53 -0600 | [diff] [blame] | 3858 | else if (x < 2 * shsurf->surface->width / 3) |
Kristian Høgsberg | 0793756 | 2011-04-12 17:25:42 -0400 | [diff] [blame] | 3859 | edges |= 0; |
| 3860 | else |
Pekka Paalanen | 9d1613e | 2011-11-25 12:09:16 +0200 | [diff] [blame] | 3861 | edges |= WL_SHELL_SURFACE_RESIZE_RIGHT; |
Kristian Høgsberg | 0793756 | 2011-04-12 17:25:42 -0400 | [diff] [blame] | 3862 | |
Jason Ekstrand | 918f2dd | 2013-12-02 21:01:53 -0600 | [diff] [blame] | 3863 | if (y < shsurf->surface->height / 3) |
Pekka Paalanen | 9d1613e | 2011-11-25 12:09:16 +0200 | [diff] [blame] | 3864 | edges |= WL_SHELL_SURFACE_RESIZE_TOP; |
Jason Ekstrand | 918f2dd | 2013-12-02 21:01:53 -0600 | [diff] [blame] | 3865 | else if (y < 2 * shsurf->surface->height / 3) |
Kristian Høgsberg | 0793756 | 2011-04-12 17:25:42 -0400 | [diff] [blame] | 3866 | edges |= 0; |
| 3867 | else |
Pekka Paalanen | 9d1613e | 2011-11-25 12:09:16 +0200 | [diff] [blame] | 3868 | edges |= WL_SHELL_SURFACE_RESIZE_BOTTOM; |
Kristian Høgsberg | 0793756 | 2011-04-12 17:25:42 -0400 | [diff] [blame] | 3869 | |
Kristian Høgsberg | c1693f2 | 2012-05-22 16:56:23 -0400 | [diff] [blame] | 3870 | surface_resize(shsurf, (struct weston_seat *) seat, edges); |
Kristian Høgsberg | 02ec0a5 | 2011-04-23 13:04:11 -0400 | [diff] [blame] | 3871 | } |
| 3872 | |
| 3873 | static void |
Kristian Høgsberg | e314875 | 2013-05-06 23:19:49 -0400 | [diff] [blame] | 3874 | 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] | 3875 | wl_fixed_t value, void *data) |
Scott Moreau | a3aa9c9 | 2012-03-22 11:01:03 -0600 | [diff] [blame] | 3876 | { |
Jonas Ådahl | b0b87ba | 2012-09-27 18:40:42 +0200 | [diff] [blame] | 3877 | float step = 0.005; |
Scott Moreau | a3aa9c9 | 2012-03-22 11:01:03 -0600 | [diff] [blame] | 3878 | struct shell_surface *shsurf; |
Kristian Høgsberg | 7ab139c | 2013-10-24 16:21:39 -0700 | [diff] [blame] | 3879 | struct weston_surface *focus = seat->pointer->focus->surface; |
Pekka Paalanen | 01388e2 | 2013-04-25 13:57:44 +0300 | [diff] [blame] | 3880 | struct weston_surface *surface; |
Scott Moreau | a3aa9c9 | 2012-03-22 11:01:03 -0600 | [diff] [blame] | 3881 | |
Pekka Paalanen | 01388e2 | 2013-04-25 13:57:44 +0300 | [diff] [blame] | 3882 | /* XXX: broken for windows containing sub-surfaces */ |
| 3883 | surface = weston_surface_get_main_surface(focus); |
Scott Moreau | a3aa9c9 | 2012-03-22 11:01:03 -0600 | [diff] [blame] | 3884 | if (surface == NULL) |
| 3885 | return; |
| 3886 | |
| 3887 | shsurf = get_shell_surface(surface); |
| 3888 | if (!shsurf) |
| 3889 | return; |
| 3890 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 3891 | shsurf->view->alpha -= wl_fixed_to_double(value) * step; |
Scott Moreau | a3aa9c9 | 2012-03-22 11:01:03 -0600 | [diff] [blame] | 3892 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 3893 | if (shsurf->view->alpha > 1.0) |
| 3894 | shsurf->view->alpha = 1.0; |
| 3895 | if (shsurf->view->alpha < step) |
| 3896 | shsurf->view->alpha = step; |
Scott Moreau | a3aa9c9 | 2012-03-22 11:01:03 -0600 | [diff] [blame] | 3897 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 3898 | weston_view_geometry_dirty(shsurf->view); |
Scott Moreau | a3aa9c9 | 2012-03-22 11:01:03 -0600 | [diff] [blame] | 3899 | weston_surface_damage(surface); |
| 3900 | } |
| 3901 | |
| 3902 | static void |
Kristian Høgsberg | e314875 | 2013-05-06 23:19:49 -0400 | [diff] [blame] | 3903 | 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] | 3904 | wl_fixed_t value) |
Scott Moreau | ccbf29d | 2012-02-22 14:21:41 -0700 | [diff] [blame] | 3905 | { |
Daniel Stone | 37816df | 2012-05-16 18:45:18 +0100 | [diff] [blame] | 3906 | struct weston_seat *ws = (struct weston_seat *) seat; |
| 3907 | struct weston_compositor *compositor = ws->compositor; |
Scott Moreau | ccbf29d | 2012-02-22 14:21:41 -0700 | [diff] [blame] | 3908 | struct weston_output *output; |
Scott Moreau | e660398 | 2012-06-11 13:07:51 -0600 | [diff] [blame] | 3909 | float increment; |
Scott Moreau | ccbf29d | 2012-02-22 14:21:41 -0700 | [diff] [blame] | 3910 | |
| 3911 | wl_list_for_each(output, &compositor->output_list, link) { |
| 3912 | if (pixman_region32_contains_point(&output->region, |
Daniel Stone | 37816df | 2012-05-16 18:45:18 +0100 | [diff] [blame] | 3913 | wl_fixed_to_double(seat->pointer->x), |
| 3914 | wl_fixed_to_double(seat->pointer->y), |
Daniel Stone | 103db7f | 2012-05-08 17:17:55 +0100 | [diff] [blame] | 3915 | NULL)) { |
Daniel Stone | 325fc2d | 2012-05-30 16:31:58 +0100 | [diff] [blame] | 3916 | if (key == KEY_PAGEUP) |
Kristian Høgsberg | 9b68af0 | 2012-05-22 12:55:18 -0400 | [diff] [blame] | 3917 | increment = output->zoom.increment; |
Daniel Stone | 325fc2d | 2012-05-30 16:31:58 +0100 | [diff] [blame] | 3918 | else if (key == KEY_PAGEDOWN) |
Kristian Høgsberg | 9b68af0 | 2012-05-22 12:55:18 -0400 | [diff] [blame] | 3919 | increment = -output->zoom.increment; |
| 3920 | else if (axis == WL_POINTER_AXIS_VERTICAL_SCROLL) |
Jonas Ådahl | b0b87ba | 2012-09-27 18:40:42 +0200 | [diff] [blame] | 3921 | /* For every pixel zoom 20th of a step */ |
Daniel Stone | 0c1e46e | 2012-05-30 16:31:59 +0100 | [diff] [blame] | 3922 | increment = output->zoom.increment * |
Jonas Ådahl | b0b87ba | 2012-09-27 18:40:42 +0200 | [diff] [blame] | 3923 | -wl_fixed_to_double(value) / 20.0; |
Kristian Høgsberg | 9b68af0 | 2012-05-22 12:55:18 -0400 | [diff] [blame] | 3924 | else |
| 3925 | increment = 0; |
| 3926 | |
Kristian Høgsberg | 9b68af0 | 2012-05-22 12:55:18 -0400 | [diff] [blame] | 3927 | output->zoom.level += increment; |
Scott Moreau | c6d7f60 | 2012-02-23 22:28:37 -0700 | [diff] [blame] | 3928 | |
Scott Moreau | e660398 | 2012-06-11 13:07:51 -0600 | [diff] [blame] | 3929 | if (output->zoom.level < 0.0) |
Scott Moreau | 850ca42 | 2012-05-21 15:21:25 -0600 | [diff] [blame] | 3930 | output->zoom.level = 0.0; |
Scott Moreau | e660398 | 2012-06-11 13:07:51 -0600 | [diff] [blame] | 3931 | else if (output->zoom.level > output->zoom.max_level) |
| 3932 | output->zoom.level = output->zoom.max_level; |
Ville Syrjälä | aa628d0 | 2012-11-16 11:48:47 +0200 | [diff] [blame] | 3933 | else if (!output->zoom.active) { |
Giulio Camuffo | 412b024 | 2013-11-14 23:42:51 +0100 | [diff] [blame] | 3934 | weston_output_activate_zoom(output); |
Kristian Høgsberg | 79af73e | 2012-08-03 15:45:23 -0400 | [diff] [blame] | 3935 | } |
Scott Moreau | ccbf29d | 2012-02-22 14:21:41 -0700 | [diff] [blame] | 3936 | |
Scott Moreau | e660398 | 2012-06-11 13:07:51 -0600 | [diff] [blame] | 3937 | output->zoom.spring_z.target = output->zoom.level; |
Scott Moreau | ccbf29d | 2012-02-22 14:21:41 -0700 | [diff] [blame] | 3938 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 3939 | weston_output_update_zoom(output); |
Scott Moreau | ccbf29d | 2012-02-22 14:21:41 -0700 | [diff] [blame] | 3940 | } |
| 3941 | } |
| 3942 | } |
| 3943 | |
Scott Moreau | ccbf29d | 2012-02-22 14:21:41 -0700 | [diff] [blame] | 3944 | static void |
Kristian Høgsberg | e314875 | 2013-05-06 23:19:49 -0400 | [diff] [blame] | 3945 | 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] | 3946 | wl_fixed_t value, void *data) |
Daniel Stone | 325fc2d | 2012-05-30 16:31:58 +0100 | [diff] [blame] | 3947 | { |
| 3948 | do_zoom(seat, time, 0, axis, value); |
| 3949 | } |
| 3950 | |
| 3951 | static void |
Kristian Høgsberg | e314875 | 2013-05-06 23:19:49 -0400 | [diff] [blame] | 3952 | 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] | 3953 | void *data) |
| 3954 | { |
| 3955 | do_zoom(seat, time, key, 0, 0); |
| 3956 | } |
| 3957 | |
| 3958 | static void |
Kristian Høgsberg | e314875 | 2013-05-06 23:19:49 -0400 | [diff] [blame] | 3959 | terminate_binding(struct weston_seat *seat, uint32_t time, uint32_t key, |
Daniel Stone | 325fc2d | 2012-05-30 16:31:58 +0100 | [diff] [blame] | 3960 | void *data) |
Kristian Høgsberg | e1a850e | 2011-12-19 15:18:05 -0500 | [diff] [blame] | 3961 | { |
Kristian Høgsberg | 8334bc1 | 2012-01-03 10:29:47 -0500 | [diff] [blame] | 3962 | struct weston_compositor *compositor = data; |
Kristian Høgsberg | e1a850e | 2011-12-19 15:18:05 -0500 | [diff] [blame] | 3963 | |
Daniel Stone | 325fc2d | 2012-05-30 16:31:58 +0100 | [diff] [blame] | 3964 | wl_display_terminate(compositor->wl_display); |
Kristian Høgsberg | e1a850e | 2011-12-19 15:18:05 -0500 | [diff] [blame] | 3965 | } |
| 3966 | |
Emilio Pozuelo Monfort | 03251b6 | 2013-11-19 11:37:16 +0100 | [diff] [blame] | 3967 | struct alt_tab { |
| 3968 | struct desktop_shell *shell; |
| 3969 | struct weston_keyboard_grab grab; |
| 3970 | |
| 3971 | struct wl_list *current; |
| 3972 | |
| 3973 | struct wl_list preview_list; |
| 3974 | }; |
| 3975 | |
| 3976 | struct alt_tab_preview { |
| 3977 | struct alt_tab *alt_tab; |
| 3978 | |
| 3979 | struct weston_view *view; |
| 3980 | struct weston_transform transform; |
| 3981 | |
| 3982 | struct wl_listener listener; |
| 3983 | |
| 3984 | struct wl_list link; |
| 3985 | }; |
| 3986 | |
| 3987 | static void |
| 3988 | alt_tab_next(struct alt_tab *alt_tab) |
| 3989 | { |
| 3990 | alt_tab->current = alt_tab->current->next; |
| 3991 | |
| 3992 | /* Make sure we're not pointing to the list header e.g. after |
| 3993 | * cycling through the whole list. */ |
| 3994 | if (alt_tab->current->next == alt_tab->preview_list.next) |
| 3995 | alt_tab->current = alt_tab->current->next; |
| 3996 | } |
| 3997 | |
| 3998 | static void |
| 3999 | alt_tab_destroy(struct alt_tab *alt_tab) |
| 4000 | { |
| 4001 | struct alt_tab_preview *preview, *next; |
| 4002 | struct weston_keyboard *keyboard = alt_tab->grab.keyboard; |
| 4003 | |
| 4004 | if (alt_tab->current && alt_tab->current != &alt_tab->preview_list) { |
| 4005 | preview = wl_container_of(alt_tab->current, preview, link); |
| 4006 | |
| 4007 | activate(alt_tab->shell, preview->view->surface, |
| 4008 | (struct weston_seat *) keyboard->seat); |
| 4009 | } |
| 4010 | |
| 4011 | wl_list_for_each_safe(preview, next, &alt_tab->preview_list, link) { |
| 4012 | wl_list_remove(&preview->link); |
| 4013 | wl_list_remove(&preview->listener.link); |
| 4014 | weston_view_destroy(preview->view); |
| 4015 | free(preview); |
| 4016 | } |
| 4017 | |
| 4018 | weston_keyboard_end_grab(keyboard); |
| 4019 | if (keyboard->input_method_resource) |
| 4020 | keyboard->grab = &keyboard->input_method_grab; |
| 4021 | |
| 4022 | free(alt_tab); |
| 4023 | } |
| 4024 | |
| 4025 | static void |
| 4026 | alt_tab_handle_surface_destroy(struct wl_listener *listener, void *data) |
| 4027 | { |
| 4028 | struct alt_tab_preview *preview = |
| 4029 | container_of(listener, struct alt_tab_preview, listener); |
| 4030 | struct alt_tab *alt_tab = preview->alt_tab; |
| 4031 | int advance = 0; |
| 4032 | |
| 4033 | /* If the preview that we're removing is the currently selected one, |
| 4034 | * we want to move to the next one. So we move to ->prev and then |
| 4035 | * call _next() after removing the preview. */ |
| 4036 | if (alt_tab->current == &preview->link) { |
| 4037 | alt_tab->current = alt_tab->current->prev; |
| 4038 | advance = 1; |
| 4039 | } |
| 4040 | |
| 4041 | wl_list_remove(&preview->listener.link); |
| 4042 | wl_list_remove(&preview->link); |
| 4043 | |
| 4044 | free(preview); |
| 4045 | |
| 4046 | if (advance) |
| 4047 | alt_tab_next(alt_tab); |
| 4048 | |
| 4049 | /* If the last preview goes away, stop the alt-tab */ |
| 4050 | if (wl_list_empty(alt_tab->current)) |
| 4051 | alt_tab_destroy(alt_tab); |
| 4052 | } |
| 4053 | |
| 4054 | static void |
| 4055 | alt_tab_key(struct weston_keyboard_grab *grab, |
| 4056 | uint32_t time, uint32_t key, uint32_t state_w) |
| 4057 | { |
| 4058 | struct alt_tab *alt_tab = container_of(grab, struct alt_tab, grab); |
| 4059 | enum wl_keyboard_key_state state = state_w; |
| 4060 | |
| 4061 | if (key == KEY_TAB && state == WL_KEYBOARD_KEY_STATE_PRESSED) |
| 4062 | alt_tab_next(alt_tab); |
| 4063 | } |
| 4064 | |
| 4065 | static void |
| 4066 | alt_tab_modifier(struct weston_keyboard_grab *grab, uint32_t serial, |
| 4067 | uint32_t mods_depressed, uint32_t mods_latched, |
| 4068 | uint32_t mods_locked, uint32_t group) |
| 4069 | { |
| 4070 | struct alt_tab *alt_tab = container_of(grab, struct alt_tab, grab); |
| 4071 | struct weston_seat *seat = (struct weston_seat *) grab->keyboard->seat; |
| 4072 | |
| 4073 | if ((seat->modifier_state & MODIFIER_ALT) == 0) |
| 4074 | alt_tab_destroy(alt_tab); |
| 4075 | } |
| 4076 | |
| 4077 | static void |
| 4078 | alt_tab_cancel(struct weston_keyboard_grab *grab) |
| 4079 | { |
| 4080 | struct alt_tab *alt_tab = container_of(grab, struct alt_tab, grab); |
| 4081 | |
| 4082 | alt_tab_destroy(alt_tab); |
| 4083 | } |
| 4084 | |
| 4085 | static const struct weston_keyboard_grab_interface alt_tab_grab = { |
| 4086 | alt_tab_key, |
| 4087 | alt_tab_modifier, |
| 4088 | alt_tab_cancel, |
| 4089 | }; |
| 4090 | |
| 4091 | static int |
| 4092 | view_for_alt_tab(struct weston_view *view) |
| 4093 | { |
Rafael Antognolli | ed207b4 | 2013-12-03 15:35:43 -0200 | [diff] [blame] | 4094 | struct shell_surface *shsurf = get_shell_surface(view->surface); |
| 4095 | if (!shsurf) |
Emilio Pozuelo Monfort | 03251b6 | 2013-11-19 11:37:16 +0100 | [diff] [blame] | 4096 | return 0; |
| 4097 | |
Rafael Antognolli | ed207b4 | 2013-12-03 15:35:43 -0200 | [diff] [blame] | 4098 | if (shsurf->parent) |
Emilio Pozuelo Monfort | 03251b6 | 2013-11-19 11:37:16 +0100 | [diff] [blame] | 4099 | return 0; |
| 4100 | |
| 4101 | if (view != get_default_view(view->surface)) |
| 4102 | return 0; |
| 4103 | |
| 4104 | return 1; |
| 4105 | } |
| 4106 | |
| 4107 | static void |
| 4108 | alt_tab_binding(struct weston_seat *seat, uint32_t time, uint32_t key, |
| 4109 | void *data) |
| 4110 | { |
| 4111 | struct alt_tab *alt_tab; |
| 4112 | struct desktop_shell *shell = data; |
| 4113 | struct weston_output *output = get_default_output(shell->compositor); |
| 4114 | struct workspace *ws; |
| 4115 | struct weston_view *view; |
| 4116 | int num_surfaces = 0; |
| 4117 | int x, y, side, margin; |
| 4118 | |
| 4119 | wl_list_for_each(view, &shell->compositor->view_list, link) { |
| 4120 | |
| 4121 | if (view_for_alt_tab(view)) |
| 4122 | num_surfaces++; |
| 4123 | } |
| 4124 | |
| 4125 | if (!num_surfaces) |
| 4126 | return; |
| 4127 | |
| 4128 | alt_tab = malloc(sizeof *alt_tab); |
| 4129 | if (!alt_tab) |
| 4130 | return; |
| 4131 | |
| 4132 | alt_tab->shell = shell; |
| 4133 | wl_list_init(&alt_tab->preview_list); |
| 4134 | alt_tab->current = &alt_tab->preview_list; |
| 4135 | |
| 4136 | restore_all_output_modes(shell->compositor); |
| 4137 | lower_fullscreen_layer(alt_tab->shell); |
| 4138 | |
| 4139 | alt_tab->grab.interface = &alt_tab_grab; |
| 4140 | weston_keyboard_start_grab(seat->keyboard, &alt_tab->grab); |
| 4141 | weston_keyboard_set_focus(seat->keyboard, NULL); |
| 4142 | |
| 4143 | ws = get_current_workspace(shell); |
| 4144 | |
| 4145 | /* FIXME: add some visual candy e.g. prelight the selected view |
| 4146 | * and/or add a black surrounding background à la gnome-shell */ |
| 4147 | |
| 4148 | /* Determine the size for each preview */ |
| 4149 | side = output->width / num_surfaces; |
| 4150 | if (side > 200) |
| 4151 | side = 200; |
| 4152 | margin = side / 4; |
| 4153 | side -= margin; |
| 4154 | |
| 4155 | x = margin; |
| 4156 | y = (output->height - side) / 2; |
| 4157 | |
| 4158 | /* Create a view for each surface */ |
| 4159 | wl_list_for_each(view, &shell->compositor->view_list, link) { |
| 4160 | struct alt_tab_preview *preview; |
| 4161 | struct weston_view *v; |
| 4162 | float scale; |
| 4163 | |
| 4164 | if (!view_for_alt_tab(view)) |
| 4165 | continue; |
| 4166 | |
| 4167 | preview = malloc(sizeof *preview); |
| 4168 | if (!preview) { |
| 4169 | alt_tab_destroy(alt_tab); |
| 4170 | return; |
| 4171 | } |
| 4172 | |
| 4173 | preview->alt_tab = alt_tab; |
| 4174 | |
| 4175 | preview->view = v = weston_view_create(view->surface); |
| 4176 | v->output = view->output; |
Philip Withnall | 83ffd9d | 2013-11-25 18:01:42 +0000 | [diff] [blame] | 4177 | |
| 4178 | wl_list_remove(&v->layer_link); |
| 4179 | wl_list_insert(&ws->layer.view_list, &v->layer_link); |
| 4180 | weston_view_damage_below(v); |
| 4181 | weston_surface_damage(v->surface); |
| 4182 | |
Jason Ekstrand | 918f2dd | 2013-12-02 21:01:53 -0600 | [diff] [blame] | 4183 | weston_view_set_position(v, x, y); |
Emilio Pozuelo Monfort | 03251b6 | 2013-11-19 11:37:16 +0100 | [diff] [blame] | 4184 | |
| 4185 | preview->listener.notify = alt_tab_handle_surface_destroy; |
| 4186 | wl_signal_add(&v->destroy_signal, &preview->listener); |
| 4187 | |
Jason Ekstrand | 918f2dd | 2013-12-02 21:01:53 -0600 | [diff] [blame] | 4188 | if (view->surface->width > view->surface->height) |
| 4189 | scale = side / (float) view->surface->width; |
Emilio Pozuelo Monfort | 03251b6 | 2013-11-19 11:37:16 +0100 | [diff] [blame] | 4190 | else |
Jason Ekstrand | 918f2dd | 2013-12-02 21:01:53 -0600 | [diff] [blame] | 4191 | scale = side / (float) view->surface->height; |
Emilio Pozuelo Monfort | 03251b6 | 2013-11-19 11:37:16 +0100 | [diff] [blame] | 4192 | |
| 4193 | wl_list_insert(&v->geometry.transformation_list, |
| 4194 | &preview->transform.link); |
| 4195 | weston_matrix_init(&preview->transform.matrix); |
| 4196 | weston_matrix_scale(&preview->transform.matrix, |
| 4197 | scale, scale, 1.0f); |
| 4198 | |
| 4199 | weston_view_geometry_dirty(v); |
| 4200 | weston_compositor_schedule_repaint(v->surface->compositor); |
| 4201 | |
| 4202 | /* Insert at the end of the list */ |
| 4203 | wl_list_insert(alt_tab->preview_list.prev, &preview->link); |
| 4204 | |
| 4205 | x += side + margin; |
| 4206 | } |
| 4207 | |
| 4208 | /* Start at the second preview so a simple <alt>tab changes window. |
| 4209 | * We set `current' to the first preview and not the second because |
| 4210 | * we're going to receive a key press callback for the initial |
| 4211 | * <alt>tab which will make `current' point to the second element. */ |
| 4212 | alt_tab_next(alt_tab); |
| 4213 | } |
| 4214 | |
| 4215 | static void |
Giulio Camuffo | 1959ab8 | 2013-11-14 23:42:52 +0100 | [diff] [blame] | 4216 | rotate_grab_motion(struct weston_pointer_grab *grab, uint32_t time, |
| 4217 | wl_fixed_t x, wl_fixed_t y) |
Pekka Paalanen | 460099f | 2012-01-20 16:48:25 +0200 | [diff] [blame] | 4218 | { |
| 4219 | struct rotate_grab *rotate = |
Ander Conselvan de Oliveira | fe0444a | 2012-04-04 17:48:05 +0300 | [diff] [blame] | 4220 | container_of(grab, struct rotate_grab, base.grab); |
Kristian Høgsberg | 02bbabb | 2013-05-06 22:15:05 -0400 | [diff] [blame] | 4221 | struct weston_pointer *pointer = grab->pointer; |
Ander Conselvan de Oliveira | fe0444a | 2012-04-04 17:48:05 +0300 | [diff] [blame] | 4222 | struct shell_surface *shsurf = rotate->base.shsurf; |
John Kåre Alsaker | 490d02a | 2012-09-30 02:57:21 +0200 | [diff] [blame] | 4223 | float cx, cy, dx, dy, cposx, cposy, dposx, dposy, r; |
Ander Conselvan de Oliveira | fe0444a | 2012-04-04 17:48:05 +0300 | [diff] [blame] | 4224 | |
Giulio Camuffo | 1959ab8 | 2013-11-14 23:42:52 +0100 | [diff] [blame] | 4225 | weston_pointer_move(pointer, x, y); |
| 4226 | |
Ander Conselvan de Oliveira | fe0444a | 2012-04-04 17:48:05 +0300 | [diff] [blame] | 4227 | if (!shsurf) |
| 4228 | return; |
| 4229 | |
Jason Ekstrand | 918f2dd | 2013-12-02 21:01:53 -0600 | [diff] [blame] | 4230 | cx = 0.5f * shsurf->surface->width; |
| 4231 | cy = 0.5f * shsurf->surface->height; |
Pekka Paalanen | 460099f | 2012-01-20 16:48:25 +0200 | [diff] [blame] | 4232 | |
Daniel Stone | 37816df | 2012-05-16 18:45:18 +0100 | [diff] [blame] | 4233 | dx = wl_fixed_to_double(pointer->x) - rotate->center.x; |
| 4234 | dy = wl_fixed_to_double(pointer->y) - rotate->center.y; |
Pekka Paalanen | 460099f | 2012-01-20 16:48:25 +0200 | [diff] [blame] | 4235 | r = sqrtf(dx * dx + dy * dy); |
| 4236 | |
Ander Conselvan de Oliveira | fe0444a | 2012-04-04 17:48:05 +0300 | [diff] [blame] | 4237 | wl_list_remove(&shsurf->rotation.transform.link); |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 4238 | weston_view_geometry_dirty(shsurf->view); |
Pekka Paalanen | 460099f | 2012-01-20 16:48:25 +0200 | [diff] [blame] | 4239 | |
| 4240 | if (r > 20.0f) { |
Pekka Paalanen | 460099f | 2012-01-20 16:48:25 +0200 | [diff] [blame] | 4241 | struct weston_matrix *matrix = |
Ander Conselvan de Oliveira | fe0444a | 2012-04-04 17:48:05 +0300 | [diff] [blame] | 4242 | &shsurf->rotation.transform.matrix; |
Pekka Paalanen | 460099f | 2012-01-20 16:48:25 +0200 | [diff] [blame] | 4243 | |
Kristian Høgsberg | 765e27b | 2012-01-27 13:36:13 -0500 | [diff] [blame] | 4244 | weston_matrix_init(&rotate->rotation); |
Vasily Khoruzhick | 1bbf372 | 2013-01-28 22:40:28 +0300 | [diff] [blame] | 4245 | weston_matrix_rotate_xy(&rotate->rotation, dx / r, dy / r); |
Pekka Paalanen | 460099f | 2012-01-20 16:48:25 +0200 | [diff] [blame] | 4246 | |
| 4247 | weston_matrix_init(matrix); |
Pekka Paalanen | 7b3bd3d | 2012-01-30 14:16:34 +0200 | [diff] [blame] | 4248 | weston_matrix_translate(matrix, -cx, -cy, 0.0f); |
Ander Conselvan de Oliveira | fe0444a | 2012-04-04 17:48:05 +0300 | [diff] [blame] | 4249 | weston_matrix_multiply(matrix, &shsurf->rotation.rotation); |
Kristian Høgsberg | 765e27b | 2012-01-27 13:36:13 -0500 | [diff] [blame] | 4250 | weston_matrix_multiply(matrix, &rotate->rotation); |
Pekka Paalanen | 7b3bd3d | 2012-01-30 14:16:34 +0200 | [diff] [blame] | 4251 | weston_matrix_translate(matrix, cx, cy, 0.0f); |
Pekka Paalanen | 460099f | 2012-01-20 16:48:25 +0200 | [diff] [blame] | 4252 | |
Pekka Paalanen | bc0b7e7 | 2012-01-24 09:53:37 +0200 | [diff] [blame] | 4253 | wl_list_insert( |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 4254 | &shsurf->view->geometry.transformation_list, |
Ander Conselvan de Oliveira | fe0444a | 2012-04-04 17:48:05 +0300 | [diff] [blame] | 4255 | &shsurf->rotation.transform.link); |
Pekka Paalanen | 460099f | 2012-01-20 16:48:25 +0200 | [diff] [blame] | 4256 | } else { |
Ander Conselvan de Oliveira | fe0444a | 2012-04-04 17:48:05 +0300 | [diff] [blame] | 4257 | wl_list_init(&shsurf->rotation.transform.link); |
| 4258 | weston_matrix_init(&shsurf->rotation.rotation); |
Kristian Høgsberg | 765e27b | 2012-01-27 13:36:13 -0500 | [diff] [blame] | 4259 | weston_matrix_init(&rotate->rotation); |
Pekka Paalanen | 460099f | 2012-01-20 16:48:25 +0200 | [diff] [blame] | 4260 | } |
Pekka Paalanen | b45ac5e | 2012-02-09 15:58:44 +0200 | [diff] [blame] | 4261 | |
Rafal Mielniczuk | 2d7ab82 | 2012-03-22 22:22:04 +0100 | [diff] [blame] | 4262 | /* We need to adjust the position of the surface |
| 4263 | * in case it was resized in a rotated state before */ |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 4264 | cposx = shsurf->view->geometry.x + cx; |
| 4265 | cposy = shsurf->view->geometry.y + cy; |
Rafal Mielniczuk | 2d7ab82 | 2012-03-22 22:22:04 +0100 | [diff] [blame] | 4266 | dposx = rotate->center.x - cposx; |
| 4267 | dposy = rotate->center.y - cposy; |
| 4268 | if (dposx != 0.0f || dposy != 0.0f) { |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 4269 | weston_view_set_position(shsurf->view, |
| 4270 | shsurf->view->geometry.x + dposx, |
| 4271 | shsurf->view->geometry.y + dposy); |
Rafal Mielniczuk | 2d7ab82 | 2012-03-22 22:22:04 +0100 | [diff] [blame] | 4272 | } |
| 4273 | |
Pekka Paalanen | b45ac5e | 2012-02-09 15:58:44 +0200 | [diff] [blame] | 4274 | /* Repaint implies weston_surface_update_transform(), which |
| 4275 | * lazily applies the damage due to rotation update. |
| 4276 | */ |
Ander Conselvan de Oliveira | fe0444a | 2012-04-04 17:48:05 +0300 | [diff] [blame] | 4277 | weston_compositor_schedule_repaint(shsurf->surface->compositor); |
Pekka Paalanen | 460099f | 2012-01-20 16:48:25 +0200 | [diff] [blame] | 4278 | } |
| 4279 | |
| 4280 | static void |
Kristian Høgsberg | 02bbabb | 2013-05-06 22:15:05 -0400 | [diff] [blame] | 4281 | rotate_grab_button(struct weston_pointer_grab *grab, |
| 4282 | uint32_t time, uint32_t button, uint32_t state_w) |
Pekka Paalanen | 460099f | 2012-01-20 16:48:25 +0200 | [diff] [blame] | 4283 | { |
| 4284 | struct rotate_grab *rotate = |
Ander Conselvan de Oliveira | fe0444a | 2012-04-04 17:48:05 +0300 | [diff] [blame] | 4285 | container_of(grab, struct rotate_grab, base.grab); |
Kristian Høgsberg | 02bbabb | 2013-05-06 22:15:05 -0400 | [diff] [blame] | 4286 | struct weston_pointer *pointer = grab->pointer; |
Ander Conselvan de Oliveira | fe0444a | 2012-04-04 17:48:05 +0300 | [diff] [blame] | 4287 | struct shell_surface *shsurf = rotate->base.shsurf; |
Daniel Stone | 4dbadb1 | 2012-05-30 16:31:51 +0100 | [diff] [blame] | 4288 | enum wl_pointer_button_state state = state_w; |
Pekka Paalanen | 460099f | 2012-01-20 16:48:25 +0200 | [diff] [blame] | 4289 | |
Daniel Stone | 4dbadb1 | 2012-05-30 16:31:51 +0100 | [diff] [blame] | 4290 | if (pointer->button_count == 0 && |
| 4291 | state == WL_POINTER_BUTTON_STATE_RELEASED) { |
Ander Conselvan de Oliveira | fe0444a | 2012-04-04 17:48:05 +0300 | [diff] [blame] | 4292 | if (shsurf) |
| 4293 | weston_matrix_multiply(&shsurf->rotation.rotation, |
| 4294 | &rotate->rotation); |
Ander Conselvan de Oliveira | b9d2a0f | 2012-06-28 18:08:05 +0300 | [diff] [blame] | 4295 | shell_grab_end(&rotate->base); |
Pekka Paalanen | 460099f | 2012-01-20 16:48:25 +0200 | [diff] [blame] | 4296 | free(rotate); |
| 4297 | } |
| 4298 | } |
| 4299 | |
Jonas Ådahl | 1ea343e | 2013-10-25 23:18:05 +0200 | [diff] [blame] | 4300 | static void |
| 4301 | rotate_grab_cancel(struct weston_pointer_grab *grab) |
| 4302 | { |
| 4303 | struct rotate_grab *rotate = |
| 4304 | container_of(grab, struct rotate_grab, base.grab); |
| 4305 | |
| 4306 | shell_grab_end(&rotate->base); |
| 4307 | free(rotate); |
| 4308 | } |
| 4309 | |
Kristian Høgsberg | 02bbabb | 2013-05-06 22:15:05 -0400 | [diff] [blame] | 4310 | static const struct weston_pointer_grab_interface rotate_grab_interface = { |
Pekka Paalanen | 460099f | 2012-01-20 16:48:25 +0200 | [diff] [blame] | 4311 | noop_grab_focus, |
| 4312 | rotate_grab_motion, |
| 4313 | rotate_grab_button, |
Jonas Ådahl | 1ea343e | 2013-10-25 23:18:05 +0200 | [diff] [blame] | 4314 | rotate_grab_cancel, |
Pekka Paalanen | 460099f | 2012-01-20 16:48:25 +0200 | [diff] [blame] | 4315 | }; |
| 4316 | |
| 4317 | static void |
Kristian Høgsberg | e314875 | 2013-05-06 23:19:49 -0400 | [diff] [blame] | 4318 | surface_rotate(struct shell_surface *surface, struct weston_seat *seat) |
Pekka Paalanen | 460099f | 2012-01-20 16:48:25 +0200 | [diff] [blame] | 4319 | { |
Pekka Paalanen | 460099f | 2012-01-20 16:48:25 +0200 | [diff] [blame] | 4320 | struct rotate_grab *rotate; |
John Kåre Alsaker | 490d02a | 2012-09-30 02:57:21 +0200 | [diff] [blame] | 4321 | float dx, dy; |
| 4322 | float r; |
Pekka Paalanen | 460099f | 2012-01-20 16:48:25 +0200 | [diff] [blame] | 4323 | |
Pekka Paalanen | 460099f | 2012-01-20 16:48:25 +0200 | [diff] [blame] | 4324 | rotate = malloc(sizeof *rotate); |
| 4325 | if (!rotate) |
| 4326 | return; |
| 4327 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 4328 | weston_view_to_global_float(surface->view, |
Jason Ekstrand | 918f2dd | 2013-12-02 21:01:53 -0600 | [diff] [blame] | 4329 | surface->surface->width * 0.5f, |
| 4330 | surface->surface->height * 0.5f, |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 4331 | &rotate->center.x, &rotate->center.y); |
Pekka Paalanen | 460099f | 2012-01-20 16:48:25 +0200 | [diff] [blame] | 4332 | |
Daniel Stone | 37816df | 2012-05-16 18:45:18 +0100 | [diff] [blame] | 4333 | dx = wl_fixed_to_double(seat->pointer->x) - rotate->center.x; |
| 4334 | dy = wl_fixed_to_double(seat->pointer->y) - rotate->center.y; |
Kristian Høgsberg | 765e27b | 2012-01-27 13:36:13 -0500 | [diff] [blame] | 4335 | r = sqrtf(dx * dx + dy * dy); |
| 4336 | if (r > 20.0f) { |
| 4337 | struct weston_matrix inverse; |
| 4338 | |
| 4339 | weston_matrix_init(&inverse); |
Vasily Khoruzhick | 1bbf372 | 2013-01-28 22:40:28 +0300 | [diff] [blame] | 4340 | weston_matrix_rotate_xy(&inverse, dx / r, -dy / r); |
Kristian Høgsberg | 765e27b | 2012-01-27 13:36:13 -0500 | [diff] [blame] | 4341 | weston_matrix_multiply(&surface->rotation.rotation, &inverse); |
Rafal Mielniczuk | 2d7ab82 | 2012-03-22 22:22:04 +0100 | [diff] [blame] | 4342 | |
| 4343 | weston_matrix_init(&rotate->rotation); |
Vasily Khoruzhick | 1bbf372 | 2013-01-28 22:40:28 +0300 | [diff] [blame] | 4344 | weston_matrix_rotate_xy(&rotate->rotation, dx / r, dy / r); |
Kristian Høgsberg | 765e27b | 2012-01-27 13:36:13 -0500 | [diff] [blame] | 4345 | } else { |
| 4346 | weston_matrix_init(&surface->rotation.rotation); |
| 4347 | weston_matrix_init(&rotate->rotation); |
| 4348 | } |
| 4349 | |
Ander Conselvan de Oliveira | b9d2a0f | 2012-06-28 18:08:05 +0300 | [diff] [blame] | 4350 | shell_grab_start(&rotate->base, &rotate_grab_interface, surface, |
| 4351 | seat->pointer, DESKTOP_SHELL_CURSOR_ARROW); |
Pekka Paalanen | 460099f | 2012-01-20 16:48:25 +0200 | [diff] [blame] | 4352 | } |
| 4353 | |
| 4354 | static void |
Kristian Høgsberg | e314875 | 2013-05-06 23:19:49 -0400 | [diff] [blame] | 4355 | 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] | 4356 | void *data) |
| 4357 | { |
Kristian Høgsberg | 7ab139c | 2013-10-24 16:21:39 -0700 | [diff] [blame] | 4358 | struct weston_surface *focus = seat->pointer->focus->surface; |
Pekka Paalanen | 01388e2 | 2013-04-25 13:57:44 +0300 | [diff] [blame] | 4359 | struct weston_surface *base_surface; |
Kristian Høgsberg | 0c36903 | 2013-02-14 21:31:44 -0500 | [diff] [blame] | 4360 | struct shell_surface *surface; |
| 4361 | |
Pekka Paalanen | 01388e2 | 2013-04-25 13:57:44 +0300 | [diff] [blame] | 4362 | base_surface = weston_surface_get_main_surface(focus); |
Kristian Høgsberg | 0c36903 | 2013-02-14 21:31:44 -0500 | [diff] [blame] | 4363 | if (base_surface == NULL) |
| 4364 | return; |
| 4365 | |
| 4366 | surface = get_shell_surface(base_surface); |
Rafael Antognolli | 03b1659 | 2013-12-03 15:35:42 -0200 | [diff] [blame] | 4367 | if (surface == NULL || surface->state.fullscreen || |
| 4368 | surface->state.maximized) |
Kristian Høgsberg | 0c36903 | 2013-02-14 21:31:44 -0500 | [diff] [blame] | 4369 | return; |
| 4370 | |
| 4371 | surface_rotate(surface, seat); |
| 4372 | } |
| 4373 | |
Philip Withnall | 83ffd9d | 2013-11-25 18:01:42 +0000 | [diff] [blame] | 4374 | /* Move all fullscreen layers down to the current workspace in a non-reversible |
| 4375 | * manner. This should be used when implementing shell-wide overlays, such as |
| 4376 | * the alt-tab switcher, which need to de-promote fullscreen layers. */ |
Kristian Høgsberg | 1ef2313 | 2013-12-04 00:20:01 -0800 | [diff] [blame] | 4377 | void |
Kristian Høgsberg | b0d8e77 | 2012-06-18 16:34:58 -0400 | [diff] [blame] | 4378 | lower_fullscreen_layer(struct desktop_shell *shell) |
| 4379 | { |
| 4380 | struct workspace *ws; |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 4381 | struct weston_view *view, *prev; |
Kristian Høgsberg | b0d8e77 | 2012-06-18 16:34:58 -0400 | [diff] [blame] | 4382 | |
| 4383 | ws = get_current_workspace(shell); |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 4384 | wl_list_for_each_reverse_safe(view, prev, |
| 4385 | &shell->fullscreen_layer.view_list, |
Philip Withnall | 83ffd9d | 2013-11-25 18:01:42 +0000 | [diff] [blame] | 4386 | layer_link) { |
| 4387 | wl_list_remove(&view->layer_link); |
| 4388 | wl_list_insert(&ws->layer.view_list, &view->layer_link); |
| 4389 | weston_view_damage_below(view); |
| 4390 | weston_surface_damage(view->surface); |
| 4391 | } |
Kristian Høgsberg | b0d8e77 | 2012-06-18 16:34:58 -0400 | [diff] [blame] | 4392 | } |
| 4393 | |
Kristian Høgsberg | 1ef2313 | 2013-12-04 00:20:01 -0800 | [diff] [blame] | 4394 | void |
Tiago Vignatti | be14326 | 2012-04-16 17:31:41 +0300 | [diff] [blame] | 4395 | activate(struct desktop_shell *shell, struct weston_surface *es, |
Daniel Stone | 37816df | 2012-05-16 18:45:18 +0100 | [diff] [blame] | 4396 | struct weston_seat *seat) |
Kristian Høgsberg | 7584062 | 2011-09-06 13:48:16 -0400 | [diff] [blame] | 4397 | { |
Pekka Paalanen | 01388e2 | 2013-04-25 13:57:44 +0300 | [diff] [blame] | 4398 | struct weston_surface *main_surface; |
Kristian Høgsberg | 2f5faff | 2012-07-31 16:36:34 -0400 | [diff] [blame] | 4399 | struct focus_state *state; |
Jonas Ådahl | 8538b22 | 2012-08-29 22:13:03 +0200 | [diff] [blame] | 4400 | struct workspace *ws; |
Louis-Francis Ratté-Boulianne | b482dbd | 2013-11-19 11:37:11 +0100 | [diff] [blame] | 4401 | struct weston_surface *old_es; |
Rafael Antognolli | 03b1659 | 2013-12-03 15:35:42 -0200 | [diff] [blame] | 4402 | struct shell_surface *shsurf; |
Kristian Høgsberg | 7584062 | 2011-09-06 13:48:16 -0400 | [diff] [blame] | 4403 | |
Pekka Paalanen | 01388e2 | 2013-04-25 13:57:44 +0300 | [diff] [blame] | 4404 | main_surface = weston_surface_get_main_surface(es); |
| 4405 | |
Daniel Stone | 37816df | 2012-05-16 18:45:18 +0100 | [diff] [blame] | 4406 | weston_surface_activate(es, seat); |
Kristian Høgsberg | 7584062 | 2011-09-06 13:48:16 -0400 | [diff] [blame] | 4407 | |
Jonas Ådahl | 8538b22 | 2012-08-29 22:13:03 +0200 | [diff] [blame] | 4408 | state = ensure_focus_state(shell, seat); |
| 4409 | if (state == NULL) |
| 4410 | return; |
Kristian Høgsberg | 2f5faff | 2012-07-31 16:36:34 -0400 | [diff] [blame] | 4411 | |
Louis-Francis Ratté-Boulianne | b482dbd | 2013-11-19 11:37:11 +0100 | [diff] [blame] | 4412 | old_es = state->keyboard_focus; |
Kristian Høgsberg | 2f5faff | 2012-07-31 16:36:34 -0400 | [diff] [blame] | 4413 | state->keyboard_focus = es; |
| 4414 | wl_list_remove(&state->surface_destroy_listener.link); |
Jason Ekstrand | 26ed73c | 2013-06-06 22:34:41 -0500 | [diff] [blame] | 4415 | wl_signal_add(&es->destroy_signal, &state->surface_destroy_listener); |
Kristian Høgsberg | 2f5faff | 2012-07-31 16:36:34 -0400 | [diff] [blame] | 4416 | |
Rafael Antognolli | 03b1659 | 2013-12-03 15:35:42 -0200 | [diff] [blame] | 4417 | shsurf = get_shell_surface(main_surface); |
| 4418 | if (shsurf->state.fullscreen) |
| 4419 | shell_configure_fullscreen(shsurf); |
| 4420 | else |
Alexander Larsson | f82b6ca | 2013-05-28 16:23:39 +0200 | [diff] [blame] | 4421 | restore_all_output_modes(shell->compositor); |
Louis-Francis Ratté-Boulianne | b482dbd | 2013-11-19 11:37:11 +0100 | [diff] [blame] | 4422 | |
Philip Withnall | 83ffd9d | 2013-11-25 18:01:42 +0000 | [diff] [blame] | 4423 | if (shell->focus_animation_type != ANIMATION_NONE) { |
| 4424 | ws = get_current_workspace(shell); |
Louis-Francis Ratté-Boulianne | b482dbd | 2013-11-19 11:37:11 +0100 | [diff] [blame] | 4425 | 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] | 4426 | } |
| 4427 | |
| 4428 | /* Update the surface’s layer. This brings it to the top of the stacking |
| 4429 | * order as appropriate. */ |
| 4430 | shell_surface_update_layer(get_shell_surface(main_surface)); |
Kristian Høgsberg | 7584062 | 2011-09-06 13:48:16 -0400 | [diff] [blame] | 4431 | } |
| 4432 | |
Alex Wu | 2185843 | 2012-04-01 20:13:08 +0800 | [diff] [blame] | 4433 | /* no-op func for checking black surface */ |
| 4434 | static void |
Jason Ekstrand | 918f2dd | 2013-12-02 21:01:53 -0600 | [diff] [blame] | 4435 | 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] | 4436 | { |
| 4437 | } |
| 4438 | |
Quentin Glidic | c0d79ce | 2013-01-29 14:16:13 +0100 | [diff] [blame] | 4439 | static bool |
Alex Wu | 2185843 | 2012-04-01 20:13:08 +0800 | [diff] [blame] | 4440 | is_black_surface (struct weston_surface *es, struct weston_surface **fs_surface) |
| 4441 | { |
| 4442 | if (es->configure == black_surface_configure) { |
| 4443 | if (fs_surface) |
Giulio Camuffo | 7fe01b1 | 2013-03-28 18:02:42 +0100 | [diff] [blame] | 4444 | *fs_surface = (struct weston_surface *)es->configure_private; |
Alex Wu | 2185843 | 2012-04-01 20:13:08 +0800 | [diff] [blame] | 4445 | return true; |
| 4446 | } |
| 4447 | return false; |
| 4448 | } |
| 4449 | |
Kristian Høgsberg | 7584062 | 2011-09-06 13:48:16 -0400 | [diff] [blame] | 4450 | static void |
Neil Roberts | a28c693 | 2013-10-03 16:43:04 +0100 | [diff] [blame] | 4451 | activate_binding(struct weston_seat *seat, |
| 4452 | struct desktop_shell *shell, |
| 4453 | struct weston_surface *focus) |
Kristian Høgsberg | e1a850e | 2011-12-19 15:18:05 -0500 | [diff] [blame] | 4454 | { |
Pekka Paalanen | 01388e2 | 2013-04-25 13:57:44 +0300 | [diff] [blame] | 4455 | struct weston_surface *main_surface; |
Kristian Høgsberg | e1a850e | 2011-12-19 15:18:05 -0500 | [diff] [blame] | 4456 | |
Alex Wu | 9c35e6b | 2012-03-05 14:13:13 +0800 | [diff] [blame] | 4457 | if (!focus) |
| 4458 | return; |
| 4459 | |
Pekka Paalanen | 01388e2 | 2013-04-25 13:57:44 +0300 | [diff] [blame] | 4460 | if (is_black_surface(focus, &main_surface)) |
| 4461 | focus = main_surface; |
Alex Wu | 4539b08 | 2012-03-01 12:57:46 +0800 | [diff] [blame] | 4462 | |
Pekka Paalanen | 01388e2 | 2013-04-25 13:57:44 +0300 | [diff] [blame] | 4463 | main_surface = weston_surface_get_main_surface(focus); |
| 4464 | if (get_shell_surface_type(main_surface) == SHELL_SURFACE_NONE) |
Kristian Høgsberg | 0636ac3 | 2012-06-27 10:22:15 -0400 | [diff] [blame] | 4465 | return; |
Kristian Høgsberg | 85b2e4b | 2012-06-21 16:49:42 -0400 | [diff] [blame] | 4466 | |
Neil Roberts | a28c693 | 2013-10-03 16:43:04 +0100 | [diff] [blame] | 4467 | activate(shell, focus, seat); |
| 4468 | } |
| 4469 | |
| 4470 | static void |
| 4471 | click_to_activate_binding(struct weston_seat *seat, uint32_t time, uint32_t button, |
| 4472 | void *data) |
| 4473 | { |
| 4474 | if (seat->pointer->grab != &seat->pointer->default_grab) |
| 4475 | return; |
| 4476 | |
Kristian Høgsberg | 7ab139c | 2013-10-24 16:21:39 -0700 | [diff] [blame] | 4477 | activate_binding(seat, data, seat->pointer->focus->surface); |
Neil Roberts | a28c693 | 2013-10-03 16:43:04 +0100 | [diff] [blame] | 4478 | } |
| 4479 | |
| 4480 | static void |
| 4481 | touch_to_activate_binding(struct weston_seat *seat, uint32_t time, void *data) |
| 4482 | { |
| 4483 | if (seat->touch->grab != &seat->touch->default_grab) |
| 4484 | return; |
| 4485 | |
Kristian Høgsberg | 7ab139c | 2013-10-24 16:21:39 -0700 | [diff] [blame] | 4486 | activate_binding(seat, data, seat->touch->focus->surface); |
Kristian Høgsberg | e1a850e | 2011-12-19 15:18:05 -0500 | [diff] [blame] | 4487 | } |
| 4488 | |
| 4489 | static void |
Ander Conselvan de Oliveira | 19d10ef | 2013-02-21 18:35:20 +0200 | [diff] [blame] | 4490 | lock(struct desktop_shell *shell) |
Kristian Høgsberg | 02ec0a5 | 2011-04-23 13:04:11 -0400 | [diff] [blame] | 4491 | { |
Kristian Høgsberg | 4476aaf | 2012-06-25 14:03:13 -0400 | [diff] [blame] | 4492 | struct workspace *ws = get_current_workspace(shell); |
Pekka Paalanen | f0fc70d | 2011-11-15 13:34:54 +0200 | [diff] [blame] | 4493 | |
Tiago Vignatti | 8e53c7f | 2012-02-29 19:53:50 +0200 | [diff] [blame] | 4494 | if (shell->locked) { |
Ander Conselvan de Oliveira | 87524b6 | 2013-02-21 18:35:22 +0200 | [diff] [blame] | 4495 | weston_compositor_sleep(shell->compositor); |
Pekka Paalanen | f0fc70d | 2011-11-15 13:34:54 +0200 | [diff] [blame] | 4496 | return; |
Tiago Vignatti | 8e53c7f | 2012-02-29 19:53:50 +0200 | [diff] [blame] | 4497 | } |
Pekka Paalanen | 9ef3e01 | 2011-11-15 13:34:48 +0200 | [diff] [blame] | 4498 | |
| 4499 | shell->locked = true; |
Pekka Paalanen | f0fc70d | 2011-11-15 13:34:54 +0200 | [diff] [blame] | 4500 | |
Kristian Høgsberg | 3be2ce9 | 2012-02-29 12:42:35 -0500 | [diff] [blame] | 4501 | /* Hide all surfaces by removing the fullscreen, panel and |
| 4502 | * toplevel layers. This way nothing else can show or receive |
| 4503 | * input events while we are locked. */ |
Pekka Paalanen | f0fc70d | 2011-11-15 13:34:54 +0200 | [diff] [blame] | 4504 | |
Kristian Høgsberg | 3be2ce9 | 2012-02-29 12:42:35 -0500 | [diff] [blame] | 4505 | wl_list_remove(&shell->panel_layer.link); |
Kristian Høgsberg | 3be2ce9 | 2012-02-29 12:42:35 -0500 | [diff] [blame] | 4506 | wl_list_remove(&shell->fullscreen_layer.link); |
Philipp Brüschweiler | 711fda8 | 2012-08-09 18:50:43 +0200 | [diff] [blame] | 4507 | if (shell->showing_input_panels) |
| 4508 | wl_list_remove(&shell->input_panel_layer.link); |
Kristian Høgsberg | 4476aaf | 2012-06-25 14:03:13 -0400 | [diff] [blame] | 4509 | wl_list_remove(&ws->layer.link); |
Kristian Høgsberg | 3be2ce9 | 2012-02-29 12:42:35 -0500 | [diff] [blame] | 4510 | wl_list_insert(&shell->compositor->cursor_layer.link, |
| 4511 | &shell->lock_layer.link); |
Pekka Paalanen | f0fc70d | 2011-11-15 13:34:54 +0200 | [diff] [blame] | 4512 | |
Pekka Paalanen | 77346a6 | 2011-11-30 16:26:35 +0200 | [diff] [blame] | 4513 | launch_screensaver(shell); |
| 4514 | |
Pekka Paalanen | f0fc70d | 2011-11-15 13:34:54 +0200 | [diff] [blame] | 4515 | /* TODO: disable bindings that should not work while locked. */ |
| 4516 | |
| 4517 | /* All this must be undone in resume_desktop(). */ |
Pekka Paalanen | 9ef3e01 | 2011-11-15 13:34:48 +0200 | [diff] [blame] | 4518 | } |
| 4519 | |
| 4520 | static void |
Ander Conselvan de Oliveira | 19d10ef | 2013-02-21 18:35:20 +0200 | [diff] [blame] | 4521 | unlock(struct desktop_shell *shell) |
Pekka Paalanen | 9ef3e01 | 2011-11-15 13:34:48 +0200 | [diff] [blame] | 4522 | { |
Pekka Paalanen | d81c216 | 2011-11-16 13:47:34 +0200 | [diff] [blame] | 4523 | if (!shell->locked || shell->lock_surface) { |
Ander Conselvan de Oliveira | 87524b6 | 2013-02-21 18:35:22 +0200 | [diff] [blame] | 4524 | shell_fade(shell, FADE_IN); |
Pekka Paalanen | 9ef3e01 | 2011-11-15 13:34:48 +0200 | [diff] [blame] | 4525 | return; |
| 4526 | } |
| 4527 | |
| 4528 | /* If desktop-shell client has gone away, unlock immediately. */ |
| 4529 | if (!shell->child.desktop_shell) { |
Pekka Paalanen | f0fc70d | 2011-11-15 13:34:54 +0200 | [diff] [blame] | 4530 | resume_desktop(shell); |
Pekka Paalanen | 9ef3e01 | 2011-11-15 13:34:48 +0200 | [diff] [blame] | 4531 | return; |
| 4532 | } |
| 4533 | |
| 4534 | if (shell->prepare_event_sent) |
| 4535 | return; |
| 4536 | |
Kristian Høgsberg | 0b5cd0c | 2012-03-04 21:57:37 -0500 | [diff] [blame] | 4537 | desktop_shell_send_prepare_lock_surface(shell->child.desktop_shell); |
Pekka Paalanen | 9ef3e01 | 2011-11-15 13:34:48 +0200 | [diff] [blame] | 4538 | shell->prepare_event_sent = true; |
Kristian Høgsberg | 02ec0a5 | 2011-04-23 13:04:11 -0400 | [diff] [blame] | 4539 | } |
| 4540 | |
| 4541 | static void |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 4542 | shell_fade_done(struct weston_view_animation *animation, void *data) |
Ander Conselvan de Oliveira | 19d10ef | 2013-02-21 18:35:20 +0200 | [diff] [blame] | 4543 | { |
| 4544 | struct desktop_shell *shell = data; |
| 4545 | |
| 4546 | shell->fade.animation = NULL; |
| 4547 | |
| 4548 | switch (shell->fade.type) { |
| 4549 | case FADE_IN: |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 4550 | weston_surface_destroy(shell->fade.view->surface); |
| 4551 | shell->fade.view = NULL; |
Ander Conselvan de Oliveira | 19d10ef | 2013-02-21 18:35:20 +0200 | [diff] [blame] | 4552 | break; |
| 4553 | case FADE_OUT: |
Ander Conselvan de Oliveira | 19d10ef | 2013-02-21 18:35:20 +0200 | [diff] [blame] | 4554 | lock(shell); |
| 4555 | break; |
Philip Withnall | 4a86a0a | 2013-11-25 18:01:32 +0000 | [diff] [blame] | 4556 | default: |
| 4557 | break; |
Ander Conselvan de Oliveira | 19d10ef | 2013-02-21 18:35:20 +0200 | [diff] [blame] | 4558 | } |
| 4559 | } |
| 4560 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 4561 | static struct weston_view * |
Pekka Paalanen | 79346ab | 2013-05-22 18:03:09 +0300 | [diff] [blame] | 4562 | shell_fade_create_surface(struct desktop_shell *shell) |
Ander Conselvan de Oliveira | 19d10ef | 2013-02-21 18:35:20 +0200 | [diff] [blame] | 4563 | { |
| 4564 | struct weston_compositor *compositor = shell->compositor; |
| 4565 | struct weston_surface *surface; |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 4566 | struct weston_view *view; |
Pekka Paalanen | 79346ab | 2013-05-22 18:03:09 +0300 | [diff] [blame] | 4567 | |
| 4568 | surface = weston_surface_create(compositor); |
| 4569 | if (!surface) |
| 4570 | return NULL; |
| 4571 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 4572 | view = weston_view_create(surface); |
| 4573 | if (!view) { |
| 4574 | weston_surface_destroy(surface); |
| 4575 | return NULL; |
| 4576 | } |
| 4577 | |
Jason Ekstrand | 918f2dd | 2013-12-02 21:01:53 -0600 | [diff] [blame] | 4578 | surface->width = 8192; |
| 4579 | surface->height = 8192; |
| 4580 | weston_view_set_position(view, 0, 0); |
Pekka Paalanen | 79346ab | 2013-05-22 18:03:09 +0300 | [diff] [blame] | 4581 | 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] | 4582 | wl_list_insert(&compositor->fade_layer.view_list, |
| 4583 | &view->layer_link); |
Pekka Paalanen | 79346ab | 2013-05-22 18:03:09 +0300 | [diff] [blame] | 4584 | pixman_region32_init(&surface->input); |
| 4585 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 4586 | return view; |
Pekka Paalanen | 79346ab | 2013-05-22 18:03:09 +0300 | [diff] [blame] | 4587 | } |
| 4588 | |
| 4589 | static void |
| 4590 | shell_fade(struct desktop_shell *shell, enum fade_type type) |
| 4591 | { |
Ander Conselvan de Oliveira | 19d10ef | 2013-02-21 18:35:20 +0200 | [diff] [blame] | 4592 | float tint; |
| 4593 | |
| 4594 | switch (type) { |
| 4595 | case FADE_IN: |
| 4596 | tint = 0.0; |
| 4597 | break; |
| 4598 | case FADE_OUT: |
| 4599 | tint = 1.0; |
| 4600 | break; |
| 4601 | default: |
| 4602 | weston_log("shell: invalid fade type\n"); |
| 4603 | return; |
| 4604 | } |
| 4605 | |
| 4606 | shell->fade.type = type; |
| 4607 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 4608 | if (shell->fade.view == NULL) { |
| 4609 | shell->fade.view = shell_fade_create_surface(shell); |
| 4610 | if (!shell->fade.view) |
Ander Conselvan de Oliveira | 19d10ef | 2013-02-21 18:35:20 +0200 | [diff] [blame] | 4611 | return; |
| 4612 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 4613 | shell->fade.view->alpha = 1.0 - tint; |
| 4614 | weston_view_update_transform(shell->fade.view); |
Ander Conselvan de Oliveira | 19d10ef | 2013-02-21 18:35:20 +0200 | [diff] [blame] | 4615 | } |
| 4616 | |
| 4617 | if (shell->fade.animation) |
Kristian Høgsberg | 5281fb1 | 2013-06-17 10:10:28 -0400 | [diff] [blame] | 4618 | weston_fade_update(shell->fade.animation, tint); |
Ander Conselvan de Oliveira | 19d10ef | 2013-02-21 18:35:20 +0200 | [diff] [blame] | 4619 | else |
| 4620 | shell->fade.animation = |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 4621 | weston_fade_run(shell->fade.view, |
Kristian Høgsberg | 5281fb1 | 2013-06-17 10:10:28 -0400 | [diff] [blame] | 4622 | 1.0 - tint, tint, 300.0, |
Ander Conselvan de Oliveira | 19d10ef | 2013-02-21 18:35:20 +0200 | [diff] [blame] | 4623 | shell_fade_done, shell); |
| 4624 | } |
| 4625 | |
| 4626 | static void |
Pekka Paalanen | 79346ab | 2013-05-22 18:03:09 +0300 | [diff] [blame] | 4627 | do_shell_fade_startup(void *data) |
| 4628 | { |
| 4629 | struct desktop_shell *shell = data; |
| 4630 | |
Kristian Høgsberg | 724c8d9 | 2013-10-16 11:38:24 -0700 | [diff] [blame] | 4631 | if (shell->startup_animation_type == ANIMATION_FADE) |
| 4632 | shell_fade(shell, FADE_IN); |
| 4633 | else if (shell->startup_animation_type == ANIMATION_NONE) { |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 4634 | weston_surface_destroy(shell->fade.view->surface); |
| 4635 | shell->fade.view = NULL; |
Kristian Høgsberg | 724c8d9 | 2013-10-16 11:38:24 -0700 | [diff] [blame] | 4636 | } |
Pekka Paalanen | 79346ab | 2013-05-22 18:03:09 +0300 | [diff] [blame] | 4637 | } |
| 4638 | |
| 4639 | static void |
| 4640 | shell_fade_startup(struct desktop_shell *shell) |
| 4641 | { |
| 4642 | struct wl_event_loop *loop; |
| 4643 | |
| 4644 | if (!shell->fade.startup_timer) |
| 4645 | return; |
| 4646 | |
| 4647 | wl_event_source_remove(shell->fade.startup_timer); |
| 4648 | shell->fade.startup_timer = NULL; |
| 4649 | |
| 4650 | loop = wl_display_get_event_loop(shell->compositor->wl_display); |
| 4651 | wl_event_loop_add_idle(loop, do_shell_fade_startup, shell); |
| 4652 | } |
| 4653 | |
| 4654 | static int |
| 4655 | fade_startup_timeout(void *data) |
| 4656 | { |
| 4657 | struct desktop_shell *shell = data; |
| 4658 | |
| 4659 | shell_fade_startup(shell); |
| 4660 | return 0; |
| 4661 | } |
| 4662 | |
| 4663 | static void |
| 4664 | shell_fade_init(struct desktop_shell *shell) |
| 4665 | { |
| 4666 | /* Make compositor output all black, and wait for the desktop-shell |
| 4667 | * client to signal it is ready, then fade in. The timer triggers a |
| 4668 | * fade-in, in case the desktop-shell client takes too long. |
| 4669 | */ |
| 4670 | |
| 4671 | struct wl_event_loop *loop; |
| 4672 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 4673 | if (shell->fade.view != NULL) { |
Pekka Paalanen | 79346ab | 2013-05-22 18:03:09 +0300 | [diff] [blame] | 4674 | weston_log("%s: warning: fade surface already exists\n", |
| 4675 | __func__); |
| 4676 | return; |
| 4677 | } |
| 4678 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 4679 | shell->fade.view = shell_fade_create_surface(shell); |
| 4680 | if (!shell->fade.view) |
Pekka Paalanen | 79346ab | 2013-05-22 18:03:09 +0300 | [diff] [blame] | 4681 | return; |
| 4682 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 4683 | weston_view_update_transform(shell->fade.view); |
| 4684 | weston_surface_damage(shell->fade.view->surface); |
Pekka Paalanen | 79346ab | 2013-05-22 18:03:09 +0300 | [diff] [blame] | 4685 | |
| 4686 | loop = wl_display_get_event_loop(shell->compositor->wl_display); |
| 4687 | shell->fade.startup_timer = |
| 4688 | wl_event_loop_add_timer(loop, fade_startup_timeout, shell); |
| 4689 | wl_event_source_timer_update(shell->fade.startup_timer, 15000); |
| 4690 | } |
| 4691 | |
| 4692 | static void |
Ander Conselvan de Oliveira | a457563 | 2013-02-21 18:35:23 +0200 | [diff] [blame] | 4693 | idle_handler(struct wl_listener *listener, void *data) |
Ander Conselvan de Oliveira | 19d10ef | 2013-02-21 18:35:20 +0200 | [diff] [blame] | 4694 | { |
| 4695 | struct desktop_shell *shell = |
Ander Conselvan de Oliveira | a457563 | 2013-02-21 18:35:23 +0200 | [diff] [blame] | 4696 | container_of(listener, struct desktop_shell, idle_listener); |
Ander Conselvan de Oliveira | 19d10ef | 2013-02-21 18:35:20 +0200 | [diff] [blame] | 4697 | |
| 4698 | shell_fade(shell, FADE_OUT); |
| 4699 | /* lock() is called from shell_fade_done() */ |
| 4700 | } |
| 4701 | |
| 4702 | static void |
Ander Conselvan de Oliveira | a457563 | 2013-02-21 18:35:23 +0200 | [diff] [blame] | 4703 | wake_handler(struct wl_listener *listener, void *data) |
Ander Conselvan de Oliveira | 19d10ef | 2013-02-21 18:35:20 +0200 | [diff] [blame] | 4704 | { |
| 4705 | struct desktop_shell *shell = |
Ander Conselvan de Oliveira | a457563 | 2013-02-21 18:35:23 +0200 | [diff] [blame] | 4706 | container_of(listener, struct desktop_shell, wake_listener); |
Ander Conselvan de Oliveira | 19d10ef | 2013-02-21 18:35:20 +0200 | [diff] [blame] | 4707 | |
Ander Conselvan de Oliveira | 19d10ef | 2013-02-21 18:35:20 +0200 | [diff] [blame] | 4708 | unlock(shell); |
| 4709 | } |
| 4710 | |
| 4711 | static void |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 4712 | center_on_output(struct weston_view *view, struct weston_output *output) |
Pekka Paalanen | 77346a6 | 2011-11-30 16:26:35 +0200 | [diff] [blame] | 4713 | { |
Giulio Camuffo | b836664 | 2013-04-25 13:57:46 +0300 | [diff] [blame] | 4714 | int32_t surf_x, surf_y, width, height; |
Ander Conselvan de Oliveira | 012b4c7 | 2012-11-27 17:03:42 +0200 | [diff] [blame] | 4715 | float x, y; |
Pekka Paalanen | 77346a6 | 2011-11-30 16:26:35 +0200 | [diff] [blame] | 4716 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 4717 | surface_subsurfaces_boundingbox(view->surface, &surf_x, &surf_y, &width, &height); |
Giulio Camuffo | b836664 | 2013-04-25 13:57:46 +0300 | [diff] [blame] | 4718 | |
| 4719 | x = output->x + (output->width - width) / 2 - surf_x / 2; |
| 4720 | y = output->y + (output->height - height) / 2 - surf_y / 2; |
Ander Conselvan de Oliveira | 012b4c7 | 2012-11-27 17:03:42 +0200 | [diff] [blame] | 4721 | |
Jason Ekstrand | 918f2dd | 2013-12-02 21:01:53 -0600 | [diff] [blame] | 4722 | weston_view_set_position(view, x, y); |
Pekka Paalanen | 77346a6 | 2011-11-30 16:26:35 +0200 | [diff] [blame] | 4723 | } |
| 4724 | |
| 4725 | static void |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 4726 | weston_view_set_initial_position(struct weston_view *view, |
| 4727 | struct desktop_shell *shell) |
Rob Bradford | ac63e5b | 2012-08-13 14:07:52 +0100 | [diff] [blame] | 4728 | { |
| 4729 | struct weston_compositor *compositor = shell->compositor; |
| 4730 | int ix = 0, iy = 0; |
| 4731 | int range_x, range_y; |
| 4732 | int dx, dy, x, y, panel_height; |
| 4733 | struct weston_output *output, *target_output = NULL; |
| 4734 | struct weston_seat *seat; |
| 4735 | |
| 4736 | /* As a heuristic place the new window on the same output as the |
| 4737 | * pointer. Falling back to the output containing 0, 0. |
| 4738 | * |
| 4739 | * TODO: Do something clever for touch too? |
| 4740 | */ |
| 4741 | wl_list_for_each(seat, &compositor->seat_list, link) { |
Kristian Høgsberg | 2bf8762 | 2013-05-07 23:17:41 -0400 | [diff] [blame] | 4742 | if (seat->pointer) { |
Kristian Høgsberg | e314875 | 2013-05-06 23:19:49 -0400 | [diff] [blame] | 4743 | ix = wl_fixed_to_int(seat->pointer->x); |
| 4744 | iy = wl_fixed_to_int(seat->pointer->y); |
Rob Bradford | ac63e5b | 2012-08-13 14:07:52 +0100 | [diff] [blame] | 4745 | break; |
| 4746 | } |
| 4747 | } |
| 4748 | |
| 4749 | wl_list_for_each(output, &compositor->output_list, link) { |
| 4750 | if (pixman_region32_contains_point(&output->region, ix, iy, NULL)) { |
| 4751 | target_output = output; |
| 4752 | break; |
| 4753 | } |
| 4754 | } |
| 4755 | |
| 4756 | if (!target_output) { |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 4757 | weston_view_set_position(view, 10 + random() % 400, |
| 4758 | 10 + random() % 400); |
Rob Bradford | ac63e5b | 2012-08-13 14:07:52 +0100 | [diff] [blame] | 4759 | return; |
| 4760 | } |
| 4761 | |
| 4762 | /* Valid range within output where the surface will still be onscreen. |
| 4763 | * If this is negative it means that the surface is bigger than |
| 4764 | * output. |
| 4765 | */ |
| 4766 | panel_height = get_output_panel_height(shell, target_output); |
Jason Ekstrand | 918f2dd | 2013-12-02 21:01:53 -0600 | [diff] [blame] | 4767 | range_x = target_output->width - view->surface->width; |
Scott Moreau | 1bad5db | 2012-08-18 01:04:05 -0600 | [diff] [blame] | 4768 | range_y = (target_output->height - panel_height) - |
Jason Ekstrand | 918f2dd | 2013-12-02 21:01:53 -0600 | [diff] [blame] | 4769 | view->surface->height; |
Rob Bradford | ac63e5b | 2012-08-13 14:07:52 +0100 | [diff] [blame] | 4770 | |
Rob Bradford | 4cb88c7 | 2012-08-13 15:18:44 +0100 | [diff] [blame] | 4771 | if (range_x > 0) |
Rob Bradford | ac63e5b | 2012-08-13 14:07:52 +0100 | [diff] [blame] | 4772 | dx = random() % range_x; |
Rob Bradford | ac63e5b | 2012-08-13 14:07:52 +0100 | [diff] [blame] | 4773 | else |
Rob Bradford | 4cb88c7 | 2012-08-13 15:18:44 +0100 | [diff] [blame] | 4774 | dx = 0; |
| 4775 | |
| 4776 | if (range_y > 0) |
Rob Bradford | ac63e5b | 2012-08-13 14:07:52 +0100 | [diff] [blame] | 4777 | dy = panel_height + random() % range_y; |
Rob Bradford | 4cb88c7 | 2012-08-13 15:18:44 +0100 | [diff] [blame] | 4778 | else |
| 4779 | dy = panel_height; |
Rob Bradford | ac63e5b | 2012-08-13 14:07:52 +0100 | [diff] [blame] | 4780 | |
| 4781 | x = target_output->x + dx; |
| 4782 | y = target_output->y + dy; |
| 4783 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 4784 | weston_view_set_position(view, x, y); |
Rob Bradford | ac63e5b | 2012-08-13 14:07:52 +0100 | [diff] [blame] | 4785 | } |
| 4786 | |
| 4787 | static void |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 4788 | map(struct desktop_shell *shell, struct shell_surface *shsurf, |
Jason Ekstrand | 918f2dd | 2013-12-02 21:01:53 -0600 | [diff] [blame] | 4789 | int32_t sx, int32_t sy) |
Kristian Høgsberg | 02ec0a5 | 2011-04-23 13:04:11 -0400 | [diff] [blame] | 4790 | { |
Kristian Høgsberg | 8334bc1 | 2012-01-03 10:29:47 -0500 | [diff] [blame] | 4791 | struct weston_compositor *compositor = shell->compositor; |
Daniel Stone | b210468 | 2012-05-30 16:31:56 +0100 | [diff] [blame] | 4792 | struct weston_seat *seat; |
Juan Zhao | 96879df | 2012-02-07 08:45:41 +0800 | [diff] [blame] | 4793 | int panel_height = 0; |
Giulio Camuffo | b836664 | 2013-04-25 13:57:46 +0300 | [diff] [blame] | 4794 | int32_t surf_x, surf_y; |
Pekka Paalanen | 57da4a8 | 2011-11-23 16:42:16 +0200 | [diff] [blame] | 4795 | |
Pekka Paalanen | 77346a6 | 2011-11-30 16:26:35 +0200 | [diff] [blame] | 4796 | /* initial positioning, see also configure() */ |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 4797 | switch (shsurf->type) { |
Rafael Antognolli | ed207b4 | 2013-12-03 15:35:43 -0200 | [diff] [blame] | 4798 | case SHELL_SURFACE_TOPLEVEL: |
Rafael Antognolli | 03b1659 | 2013-12-03 15:35:42 -0200 | [diff] [blame] | 4799 | if (shsurf->state.fullscreen) { |
| 4800 | center_on_output(shsurf->view, shsurf->fullscreen_output); |
| 4801 | shell_map_fullscreen(shsurf); |
| 4802 | } else if (shsurf->state.maximized) { |
| 4803 | /* use surface configure to set the geometry */ |
| 4804 | panel_height = get_output_panel_height(shell, shsurf->output); |
| 4805 | surface_subsurfaces_boundingbox(shsurf->surface, |
| 4806 | &surf_x, &surf_y, NULL, NULL); |
| 4807 | weston_view_set_position(shsurf->view, |
| 4808 | shsurf->output->x - surf_x, |
| 4809 | shsurf->output->y + |
| 4810 | panel_height - surf_y); |
Rafael Antognolli | ed207b4 | 2013-12-03 15:35:43 -0200 | [diff] [blame] | 4811 | } else if (!shsurf->state.relative) { |
Rafael Antognolli | 03b1659 | 2013-12-03 15:35:42 -0200 | [diff] [blame] | 4812 | weston_view_set_initial_position(shsurf->view, shell); |
| 4813 | } |
Juan Zhao | 96879df | 2012-02-07 08:45:41 +0800 | [diff] [blame] | 4814 | break; |
Tiago Vignatti | 0f99701 | 2012-02-10 16:17:23 +0200 | [diff] [blame] | 4815 | case SHELL_SURFACE_POPUP: |
Kristian Høgsberg | 3730f36 | 2012-04-13 12:40:07 -0400 | [diff] [blame] | 4816 | shell_map_popup(shsurf); |
Rob Bradford | db99938 | 2012-12-06 12:07:48 +0000 | [diff] [blame] | 4817 | break; |
Ander Conselvan de Oliveira | e9e0515 | 2012-02-15 17:02:56 +0200 | [diff] [blame] | 4818 | case SHELL_SURFACE_NONE: |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 4819 | weston_view_set_position(shsurf->view, |
| 4820 | shsurf->view->geometry.x + sx, |
| 4821 | shsurf->view->geometry.y + sy); |
Tiago Vignatti | 0f99701 | 2012-02-10 16:17:23 +0200 | [diff] [blame] | 4822 | break; |
Philip Withnall | 0f640e2 | 2013-11-25 18:01:31 +0000 | [diff] [blame] | 4823 | case SHELL_SURFACE_XWAYLAND: |
Pekka Paalanen | 77346a6 | 2011-11-30 16:26:35 +0200 | [diff] [blame] | 4824 | default: |
| 4825 | ; |
| 4826 | } |
Kristian Høgsberg | 7584062 | 2011-09-06 13:48:16 -0400 | [diff] [blame] | 4827 | |
Philip Withnall | e1d75ae | 2013-11-25 18:01:41 +0000 | [diff] [blame] | 4828 | /* Surface stacking order, see also activate(). */ |
| 4829 | shell_surface_update_layer(shsurf); |
Pekka Paalanen | f0fc70d | 2011-11-15 13:34:54 +0200 | [diff] [blame] | 4830 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 4831 | if (shsurf->type != SHELL_SURFACE_NONE) { |
| 4832 | weston_view_update_transform(shsurf->view); |
Rafael Antognolli | 03b1659 | 2013-12-03 15:35:42 -0200 | [diff] [blame] | 4833 | if (shsurf->state.maximized) { |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 4834 | shsurf->surface->output = shsurf->output; |
| 4835 | shsurf->view->output = shsurf->output; |
| 4836 | } |
Ander Conselvan de Oliveira | de56c31 | 2012-03-05 15:39:23 +0200 | [diff] [blame] | 4837 | } |
Kristian Høgsberg | 2f88a40 | 2011-12-04 15:32:59 -0500 | [diff] [blame] | 4838 | |
Rafael Antognolli | ed207b4 | 2013-12-03 15:35:43 -0200 | [diff] [blame] | 4839 | if ((shsurf->type == SHELL_SURFACE_XWAYLAND || shsurf->state.relative) && |
| 4840 | shsurf->transient.flags == WL_SHELL_SURFACE_TRANSIENT_INACTIVE) { |
| 4841 | } |
| 4842 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 4843 | switch (shsurf->type) { |
Tiago Vignatti | fb2adba | 2013-06-12 15:43:21 -0300 | [diff] [blame] | 4844 | /* XXX: xwayland's using the same fields for transient type */ |
| 4845 | case SHELL_SURFACE_XWAYLAND: |
Tiago Vignatti | 99aeb1e | 2012-05-23 22:06:26 +0300 | [diff] [blame] | 4846 | if (shsurf->transient.flags == |
| 4847 | WL_SHELL_SURFACE_TRANSIENT_INACTIVE) |
| 4848 | break; |
| 4849 | case SHELL_SURFACE_TOPLEVEL: |
Rafael Antognolli | ed207b4 | 2013-12-03 15:35:43 -0200 | [diff] [blame] | 4850 | if (shsurf->state.relative && |
| 4851 | shsurf->transient.flags == WL_SHELL_SURFACE_TRANSIENT_INACTIVE) |
| 4852 | break; |
Rafael Antognolli | ba5d2d7 | 2013-12-04 17:49:55 -0200 | [diff] [blame] | 4853 | if (shell->locked) |
Rafael Antognolli | ed207b4 | 2013-12-03 15:35:43 -0200 | [diff] [blame] | 4854 | break; |
| 4855 | wl_list_for_each(seat, &compositor->seat_list, link) |
| 4856 | activate(shell, shsurf->surface, seat); |
Juan Zhao | 7bb92f0 | 2011-12-15 11:31:51 -0500 | [diff] [blame] | 4857 | break; |
Philip Withnall | 0f640e2 | 2013-11-25 18:01:31 +0000 | [diff] [blame] | 4858 | case SHELL_SURFACE_POPUP: |
| 4859 | case SHELL_SURFACE_NONE: |
Juan Zhao | 7bb92f0 | 2011-12-15 11:31:51 -0500 | [diff] [blame] | 4860 | default: |
| 4861 | break; |
| 4862 | } |
| 4863 | |
Rafael Antognolli | 03b1659 | 2013-12-03 15:35:42 -0200 | [diff] [blame] | 4864 | if (shsurf->type == SHELL_SURFACE_TOPLEVEL && |
| 4865 | !shsurf->state.maximized && !shsurf->state.fullscreen) |
Juan Zhao | e10d279 | 2012-04-25 19:09:52 +0800 | [diff] [blame] | 4866 | { |
| 4867 | switch (shell->win_animation_type) { |
| 4868 | case ANIMATION_FADE: |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 4869 | 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] | 4870 | break; |
| 4871 | case ANIMATION_ZOOM: |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 4872 | weston_zoom_run(shsurf->view, 0.5, 1.0, NULL, NULL); |
Juan Zhao | e10d279 | 2012-04-25 19:09:52 +0800 | [diff] [blame] | 4873 | break; |
Philip Withnall | 4a86a0a | 2013-11-25 18:01:32 +0000 | [diff] [blame] | 4874 | case ANIMATION_NONE: |
Juan Zhao | e10d279 | 2012-04-25 19:09:52 +0800 | [diff] [blame] | 4875 | default: |
| 4876 | break; |
| 4877 | } |
| 4878 | } |
Kristian Høgsberg | 32e24cc | 2011-11-09 12:07:35 -0500 | [diff] [blame] | 4879 | } |
| 4880 | |
| 4881 | static void |
Tiago Vignatti | be14326 | 2012-04-16 17:31:41 +0300 | [diff] [blame] | 4882 | configure(struct desktop_shell *shell, struct weston_surface *surface, |
Jason Ekstrand | 918f2dd | 2013-12-02 21:01:53 -0600 | [diff] [blame] | 4883 | float x, float y) |
Kristian Høgsberg | 32e24cc | 2011-11-09 12:07:35 -0500 | [diff] [blame] | 4884 | { |
Pekka Paalanen | 77346a6 | 2011-11-30 16:26:35 +0200 | [diff] [blame] | 4885 | struct shell_surface *shsurf; |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 4886 | struct weston_view *view; |
Jason Ekstrand | 918f2dd | 2013-12-02 21:01:53 -0600 | [diff] [blame] | 4887 | int32_t mx, my, surf_x, surf_y; |
Kristian Høgsberg | 32e24cc | 2011-11-09 12:07:35 -0500 | [diff] [blame] | 4888 | |
Pekka Paalanen | 77346a6 | 2011-11-30 16:26:35 +0200 | [diff] [blame] | 4889 | shsurf = get_shell_surface(surface); |
Pekka Paalanen | 77346a6 | 2011-11-30 16:26:35 +0200 | [diff] [blame] | 4890 | |
Rafael Antognolli | 03b1659 | 2013-12-03 15:35:42 -0200 | [diff] [blame] | 4891 | if (shsurf->state.fullscreen) |
Alex Wu | 4539b08 | 2012-03-01 12:57:46 +0800 | [diff] [blame] | 4892 | shell_configure_fullscreen(shsurf); |
Rafael Antognolli | 03b1659 | 2013-12-03 15:35:42 -0200 | [diff] [blame] | 4893 | else if (shsurf->state.maximized) { |
Alex Wu | 4539b08 | 2012-03-01 12:57:46 +0800 | [diff] [blame] | 4894 | /* setting x, y and using configure to change that geometry */ |
Giulio Camuffo | b836664 | 2013-04-25 13:57:46 +0300 | [diff] [blame] | 4895 | surface_subsurfaces_boundingbox(shsurf->surface, &surf_x, &surf_y, |
| 4896 | NULL, NULL); |
Jason Ekstrand | 918f2dd | 2013-12-02 21:01:53 -0600 | [diff] [blame] | 4897 | mx = shsurf->output->x - surf_x; |
| 4898 | my = shsurf->output->y + |
| 4899 | get_output_panel_height(shell,shsurf->output) - surf_y; |
| 4900 | weston_view_set_position(shsurf->view, mx, my); |
Rafael Antognolli | 03b1659 | 2013-12-03 15:35:42 -0200 | [diff] [blame] | 4901 | } else { |
Jason Ekstrand | 918f2dd | 2013-12-02 21:01:53 -0600 | [diff] [blame] | 4902 | weston_view_set_position(shsurf->view, x, y); |
Kristian Høgsberg | 7a5c979 | 2011-06-18 06:12:54 -0400 | [diff] [blame] | 4903 | } |
Kristian Høgsberg | 32e24cc | 2011-11-09 12:07:35 -0500 | [diff] [blame] | 4904 | |
Alex Wu | 4539b08 | 2012-03-01 12:57:46 +0800 | [diff] [blame] | 4905 | /* XXX: would a fullscreen surface need the same handling? */ |
Kristian Høgsberg | 6a8b553 | 2012-02-16 23:43:59 -0500 | [diff] [blame] | 4906 | if (surface->output) { |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 4907 | wl_list_for_each(view, &surface->views, surface_link) |
| 4908 | weston_view_update_transform(view); |
Pekka Paalanen | 77346a6 | 2011-11-30 16:26:35 +0200 | [diff] [blame] | 4909 | |
Rafael Antognolli | 03b1659 | 2013-12-03 15:35:42 -0200 | [diff] [blame] | 4910 | if (shsurf->state.maximized) |
Juan Zhao | 96879df | 2012-02-07 08:45:41 +0800 | [diff] [blame] | 4911 | surface->output = shsurf->output; |
Pekka Paalanen | 77346a6 | 2011-11-30 16:26:35 +0200 | [diff] [blame] | 4912 | } |
Kristian Høgsberg | 0793756 | 2011-04-12 17:25:42 -0400 | [diff] [blame] | 4913 | } |
| 4914 | |
Ander Conselvan de Oliveira | 093bfa3 | 2012-03-27 17:36:41 +0300 | [diff] [blame] | 4915 | static void |
Jason Ekstrand | 918f2dd | 2013-12-02 21:01:53 -0600 | [diff] [blame] | 4916 | 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] | 4917 | { |
Ander Conselvan de Oliveira | 7fb9f95 | 2012-03-27 17:36:42 +0300 | [diff] [blame] | 4918 | struct shell_surface *shsurf = get_shell_surface(es); |
Tiago Vignatti | be14326 | 2012-04-16 17:31:41 +0300 | [diff] [blame] | 4919 | struct desktop_shell *shell = shsurf->shell; |
Giulio Camuffo | 184df50 | 2013-02-21 11:29:21 +0100 | [diff] [blame] | 4920 | |
Tiago Vignatti | 70e5c9c | 2012-05-07 15:23:07 +0300 | [diff] [blame] | 4921 | int type_changed = 0; |
Ander Conselvan de Oliveira | 093bfa3 | 2012-03-27 17:36:41 +0300 | [diff] [blame] | 4922 | |
Kristian Høgsberg | 8eb0f4f | 2013-06-17 10:33:14 -0400 | [diff] [blame] | 4923 | if (!weston_surface_is_mapped(es) && |
| 4924 | !wl_list_empty(&shsurf->popup.grab_link)) { |
Giulio Camuffo | 5085a75 | 2013-03-25 21:42:45 +0100 | [diff] [blame] | 4925 | remove_popup_grab(shsurf); |
| 4926 | } |
| 4927 | |
Jason Ekstrand | 918f2dd | 2013-12-02 21:01:53 -0600 | [diff] [blame] | 4928 | if (es->width == 0) |
Giulio Camuffo | 184df50 | 2013-02-21 11:29:21 +0100 | [diff] [blame] | 4929 | return; |
| 4930 | |
Kristian Høgsberg | c8f8dd8 | 2013-12-05 23:20:33 -0800 | [diff] [blame] | 4931 | if (shsurf->state_changed) { |
Kristian Høgsberg | 7f366e7 | 2012-04-27 17:20:01 -0400 | [diff] [blame] | 4932 | set_surface_type(shsurf); |
Kristian Høgsberg | f7e23d5 | 2012-04-27 17:51:59 -0400 | [diff] [blame] | 4933 | type_changed = 1; |
| 4934 | } |
Kristian Høgsberg | 7f366e7 | 2012-04-27 17:20:01 -0400 | [diff] [blame] | 4935 | |
Ander Conselvan de Oliveira | 093bfa3 | 2012-03-27 17:36:41 +0300 | [diff] [blame] | 4936 | if (!weston_surface_is_mapped(es)) { |
Jason Ekstrand | 918f2dd | 2013-12-02 21:01:53 -0600 | [diff] [blame] | 4937 | map(shell, shsurf, sx, sy); |
Kristian Høgsberg | f7e23d5 | 2012-04-27 17:51:59 -0400 | [diff] [blame] | 4938 | } else if (type_changed || sx != 0 || sy != 0 || |
Jason Ekstrand | 918f2dd | 2013-12-02 21:01:53 -0600 | [diff] [blame] | 4939 | shsurf->last_width != es->width || |
| 4940 | shsurf->last_height != es->height) { |
| 4941 | shsurf->last_width = es->width; |
| 4942 | shsurf->last_height = es->height; |
John Kåre Alsaker | 490d02a | 2012-09-30 02:57:21 +0200 | [diff] [blame] | 4943 | float from_x, from_y; |
| 4944 | float to_x, to_y; |
Ander Conselvan de Oliveira | 093bfa3 | 2012-03-27 17:36:41 +0300 | [diff] [blame] | 4945 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 4946 | weston_view_to_global_float(shsurf->view, 0, 0, &from_x, &from_y); |
| 4947 | 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] | 4948 | configure(shell, es, |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 4949 | shsurf->view->geometry.x + to_x - from_x, |
Jason Ekstrand | 918f2dd | 2013-12-02 21:01:53 -0600 | [diff] [blame] | 4950 | shsurf->view->geometry.y + to_y - from_y); |
Ander Conselvan de Oliveira | 093bfa3 | 2012-03-27 17:36:41 +0300 | [diff] [blame] | 4951 | } |
| 4952 | } |
| 4953 | |
Tiago Vignatti | b7dbbd6 | 2012-09-25 17:57:01 +0300 | [diff] [blame] | 4954 | static void launch_desktop_shell_process(void *data); |
Pekka Paalanen | 4d733ee | 2012-01-17 14:36:27 +0200 | [diff] [blame] | 4955 | |
Kristian Høgsberg | 97d44aa | 2011-08-26 17:21:20 -0400 | [diff] [blame] | 4956 | static void |
Kristian Høgsberg | 8334bc1 | 2012-01-03 10:29:47 -0500 | [diff] [blame] | 4957 | desktop_shell_sigchld(struct weston_process *process, int status) |
Pekka Paalanen | 6cd281a | 2011-11-03 14:11:32 +0200 | [diff] [blame] | 4958 | { |
Pekka Paalanen | 4d733ee | 2012-01-17 14:36:27 +0200 | [diff] [blame] | 4959 | uint32_t time; |
Tiago Vignatti | be14326 | 2012-04-16 17:31:41 +0300 | [diff] [blame] | 4960 | struct desktop_shell *shell = |
| 4961 | container_of(process, struct desktop_shell, child.process); |
Pekka Paalanen | 6cd281a | 2011-11-03 14:11:32 +0200 | [diff] [blame] | 4962 | |
| 4963 | shell->child.process.pid = 0; |
| 4964 | shell->child.client = NULL; /* already destroyed by wayland */ |
Pekka Paalanen | 4d733ee | 2012-01-17 14:36:27 +0200 | [diff] [blame] | 4965 | |
| 4966 | /* if desktop-shell dies more than 5 times in 30 seconds, give up */ |
| 4967 | time = weston_compositor_get_time(); |
Kristian Høgsberg | f03a616 | 2012-01-17 11:07:42 -0500 | [diff] [blame] | 4968 | if (time - shell->child.deathstamp > 30000) { |
Pekka Paalanen | 4d733ee | 2012-01-17 14:36:27 +0200 | [diff] [blame] | 4969 | shell->child.deathstamp = time; |
| 4970 | shell->child.deathcount = 0; |
| 4971 | } |
| 4972 | |
| 4973 | shell->child.deathcount++; |
| 4974 | if (shell->child.deathcount > 5) { |
Emilio Pozuelo Monfort | 46ce798 | 2013-11-20 13:22:29 +0100 | [diff] [blame] | 4975 | weston_log("%s died, giving up.\n", shell->client); |
Pekka Paalanen | 4d733ee | 2012-01-17 14:36:27 +0200 | [diff] [blame] | 4976 | return; |
| 4977 | } |
| 4978 | |
Emilio Pozuelo Monfort | 46ce798 | 2013-11-20 13:22:29 +0100 | [diff] [blame] | 4979 | weston_log("%s died, respawning...\n", shell->client); |
Pekka Paalanen | 4d733ee | 2012-01-17 14:36:27 +0200 | [diff] [blame] | 4980 | launch_desktop_shell_process(shell); |
Pekka Paalanen | 79346ab | 2013-05-22 18:03:09 +0300 | [diff] [blame] | 4981 | shell_fade_startup(shell); |
Pekka Paalanen | 6cd281a | 2011-11-03 14:11:32 +0200 | [diff] [blame] | 4982 | } |
| 4983 | |
Tiago Vignatti | b7dbbd6 | 2012-09-25 17:57:01 +0300 | [diff] [blame] | 4984 | static void |
| 4985 | launch_desktop_shell_process(void *data) |
Pekka Paalanen | 6cd281a | 2011-11-03 14:11:32 +0200 | [diff] [blame] | 4986 | { |
Tiago Vignatti | b7dbbd6 | 2012-09-25 17:57:01 +0300 | [diff] [blame] | 4987 | struct desktop_shell *shell = data; |
Pekka Paalanen | 6cd281a | 2011-11-03 14:11:32 +0200 | [diff] [blame] | 4988 | |
Kristian Høgsberg | 8334bc1 | 2012-01-03 10:29:47 -0500 | [diff] [blame] | 4989 | shell->child.client = weston_client_launch(shell->compositor, |
Pekka Paalanen | 409ef0a | 2011-12-02 15:30:21 +0200 | [diff] [blame] | 4990 | &shell->child.process, |
Emilio Pozuelo Monfort | 46ce798 | 2013-11-20 13:22:29 +0100 | [diff] [blame] | 4991 | shell->client, |
Pekka Paalanen | 409ef0a | 2011-12-02 15:30:21 +0200 | [diff] [blame] | 4992 | desktop_shell_sigchld); |
| 4993 | |
| 4994 | if (!shell->child.client) |
Emilio Pozuelo Monfort | 46ce798 | 2013-11-20 13:22:29 +0100 | [diff] [blame] | 4995 | weston_log("not able to start %s\n", shell->client); |
Pekka Paalanen | 6cd281a | 2011-11-03 14:11:32 +0200 | [diff] [blame] | 4996 | } |
| 4997 | |
| 4998 | static void |
Kristian Høgsberg | 97d44aa | 2011-08-26 17:21:20 -0400 | [diff] [blame] | 4999 | bind_shell(struct wl_client *client, void *data, uint32_t version, uint32_t id) |
| 5000 | { |
Tiago Vignatti | be14326 | 2012-04-16 17:31:41 +0300 | [diff] [blame] | 5001 | struct desktop_shell *shell = data; |
Jason Ekstrand | a85118c | 2013-06-27 20:17:02 -0500 | [diff] [blame] | 5002 | struct wl_resource *resource; |
Kristian Høgsberg | 97d44aa | 2011-08-26 17:21:20 -0400 | [diff] [blame] | 5003 | |
Jason Ekstrand | a85118c | 2013-06-27 20:17:02 -0500 | [diff] [blame] | 5004 | resource = wl_resource_create(client, &wl_shell_interface, 1, id); |
| 5005 | if (resource) |
| 5006 | wl_resource_set_implementation(resource, &shell_implementation, |
| 5007 | shell, NULL); |
Kristian Høgsberg | 97d44aa | 2011-08-26 17:21:20 -0400 | [diff] [blame] | 5008 | } |
| 5009 | |
Kristian Høgsberg | 7584062 | 2011-09-06 13:48:16 -0400 | [diff] [blame] | 5010 | static void |
Rafael Antognolli | e2a3455 | 2013-12-03 15:35:45 -0200 | [diff] [blame] | 5011 | bind_xdg_shell(struct wl_client *client, void *data, uint32_t version, uint32_t id) |
| 5012 | { |
| 5013 | struct desktop_shell *shell = data; |
| 5014 | struct wl_resource *resource; |
| 5015 | |
| 5016 | resource = wl_resource_create(client, &xdg_shell_interface, 1, id); |
| 5017 | if (resource) |
| 5018 | wl_resource_set_dispatcher(resource, |
| 5019 | xdg_shell_unversioned_dispatch, |
| 5020 | NULL, shell, NULL); |
| 5021 | } |
| 5022 | |
| 5023 | static void |
Pekka Paalanen | 9ef3e01 | 2011-11-15 13:34:48 +0200 | [diff] [blame] | 5024 | unbind_desktop_shell(struct wl_resource *resource) |
| 5025 | { |
Jason Ekstrand | 651f00e | 2013-06-14 10:07:54 -0500 | [diff] [blame] | 5026 | struct desktop_shell *shell = wl_resource_get_user_data(resource); |
Kristian Høgsberg | 1ec0c31 | 2011-11-15 16:39:55 -0500 | [diff] [blame] | 5027 | |
| 5028 | if (shell->locked) |
| 5029 | resume_desktop(shell); |
| 5030 | |
Pekka Paalanen | 9ef3e01 | 2011-11-15 13:34:48 +0200 | [diff] [blame] | 5031 | shell->child.desktop_shell = NULL; |
| 5032 | shell->prepare_event_sent = false; |
Pekka Paalanen | 9ef3e01 | 2011-11-15 13:34:48 +0200 | [diff] [blame] | 5033 | } |
| 5034 | |
| 5035 | static void |
Kristian Høgsberg | 7584062 | 2011-09-06 13:48:16 -0400 | [diff] [blame] | 5036 | bind_desktop_shell(struct wl_client *client, |
| 5037 | void *data, uint32_t version, uint32_t id) |
| 5038 | { |
Tiago Vignatti | be14326 | 2012-04-16 17:31:41 +0300 | [diff] [blame] | 5039 | struct desktop_shell *shell = data; |
Pekka Paalanen | bbe6052 | 2011-11-03 14:11:33 +0200 | [diff] [blame] | 5040 | struct wl_resource *resource; |
Kristian Høgsberg | 7584062 | 2011-09-06 13:48:16 -0400 | [diff] [blame] | 5041 | |
Jason Ekstrand | a85118c | 2013-06-27 20:17:02 -0500 | [diff] [blame] | 5042 | resource = wl_resource_create(client, &desktop_shell_interface, |
| 5043 | MIN(version, 2), id); |
Pekka Paalanen | bbe6052 | 2011-11-03 14:11:33 +0200 | [diff] [blame] | 5044 | |
Pekka Paalanen | 9ef3e01 | 2011-11-15 13:34:48 +0200 | [diff] [blame] | 5045 | if (client == shell->child.client) { |
Jason Ekstrand | a85118c | 2013-06-27 20:17:02 -0500 | [diff] [blame] | 5046 | wl_resource_set_implementation(resource, |
| 5047 | &desktop_shell_implementation, |
| 5048 | shell, unbind_desktop_shell); |
Pekka Paalanen | 9ef3e01 | 2011-11-15 13:34:48 +0200 | [diff] [blame] | 5049 | shell->child.desktop_shell = resource; |
Pekka Paalanen | 79346ab | 2013-05-22 18:03:09 +0300 | [diff] [blame] | 5050 | |
| 5051 | if (version < 2) |
| 5052 | shell_fade_startup(shell); |
| 5053 | |
Pekka Paalanen | bbe6052 | 2011-11-03 14:11:33 +0200 | [diff] [blame] | 5054 | return; |
Pekka Paalanen | 9ef3e01 | 2011-11-15 13:34:48 +0200 | [diff] [blame] | 5055 | } |
Pekka Paalanen | bbe6052 | 2011-11-03 14:11:33 +0200 | [diff] [blame] | 5056 | |
| 5057 | wl_resource_post_error(resource, WL_DISPLAY_ERROR_INVALID_OBJECT, |
| 5058 | "permission to bind desktop_shell denied"); |
Kristian Høgsberg | eae5de7 | 2012-04-11 22:42:15 -0400 | [diff] [blame] | 5059 | wl_resource_destroy(resource); |
Kristian Høgsberg | 7584062 | 2011-09-06 13:48:16 -0400 | [diff] [blame] | 5060 | } |
| 5061 | |
Pekka Paalanen | 6e16811 | 2011-11-24 11:34:05 +0200 | [diff] [blame] | 5062 | static void |
Jason Ekstrand | 918f2dd | 2013-12-02 21:01:53 -0600 | [diff] [blame] | 5063 | 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] | 5064 | { |
Giulio Camuffo | 7fe01b1 | 2013-03-28 18:02:42 +0100 | [diff] [blame] | 5065 | struct desktop_shell *shell = surface->configure_private; |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 5066 | struct weston_view *view; |
Kristian Høgsberg | 1a73a63 | 2012-06-26 22:15:53 -0400 | [diff] [blame] | 5067 | |
Jason Ekstrand | 918f2dd | 2013-12-02 21:01:53 -0600 | [diff] [blame] | 5068 | if (surface->width == 0) |
Giulio Camuffo | 184df50 | 2013-02-21 11:29:21 +0100 | [diff] [blame] | 5069 | return; |
| 5070 | |
Pekka Paalanen | 3a1d07d | 2012-12-20 14:02:13 +0200 | [diff] [blame] | 5071 | /* XXX: starting weston-screensaver beforehand does not work */ |
Kristian Høgsberg | 1a73a63 | 2012-06-26 22:15:53 -0400 | [diff] [blame] | 5072 | if (!shell->locked) |
| 5073 | return; |
| 5074 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 5075 | view = container_of(surface->views.next, struct weston_view, surface_link); |
| 5076 | center_on_output(view, surface->output); |
Kristian Høgsberg | 1a73a63 | 2012-06-26 22:15:53 -0400 | [diff] [blame] | 5077 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 5078 | if (wl_list_empty(&view->layer_link)) { |
| 5079 | wl_list_insert(shell->lock_layer.view_list.prev, |
| 5080 | &view->layer_link); |
| 5081 | weston_view_update_transform(view); |
Ander Conselvan de Oliveira | 859e885 | 2013-02-21 18:35:21 +0200 | [diff] [blame] | 5082 | wl_event_source_timer_update(shell->screensaver.timer, |
| 5083 | shell->screensaver.duration); |
Ander Conselvan de Oliveira | 19d10ef | 2013-02-21 18:35:20 +0200 | [diff] [blame] | 5084 | shell_fade(shell, FADE_IN); |
Kristian Høgsberg | 1a73a63 | 2012-06-26 22:15:53 -0400 | [diff] [blame] | 5085 | } |
| 5086 | } |
| 5087 | |
| 5088 | static void |
Pekka Paalanen | 6e16811 | 2011-11-24 11:34:05 +0200 | [diff] [blame] | 5089 | screensaver_set_surface(struct wl_client *client, |
| 5090 | struct wl_resource *resource, |
Kristian Høgsberg | 1a73a63 | 2012-06-26 22:15:53 -0400 | [diff] [blame] | 5091 | struct wl_resource *surface_resource, |
Pekka Paalanen | 6e16811 | 2011-11-24 11:34:05 +0200 | [diff] [blame] | 5092 | struct wl_resource *output_resource) |
| 5093 | { |
Jason Ekstrand | 651f00e | 2013-06-14 10:07:54 -0500 | [diff] [blame] | 5094 | struct desktop_shell *shell = wl_resource_get_user_data(resource); |
Jason Ekstrand | 0f2ef7e | 2013-06-14 10:07:53 -0500 | [diff] [blame] | 5095 | struct weston_surface *surface = |
| 5096 | wl_resource_get_user_data(surface_resource); |
Jason Ekstrand | a0d2dde | 2013-06-14 10:08:01 -0500 | [diff] [blame] | 5097 | struct weston_output *output = wl_resource_get_user_data(output_resource); |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 5098 | struct weston_view *view, *next; |
| 5099 | |
| 5100 | /* Make sure we only have one view */ |
| 5101 | wl_list_for_each_safe(view, next, &surface->views, surface_link) |
| 5102 | weston_view_destroy(view); |
| 5103 | weston_view_create(surface); |
Pekka Paalanen | 6e16811 | 2011-11-24 11:34:05 +0200 | [diff] [blame] | 5104 | |
Kristian Høgsberg | 1a73a63 | 2012-06-26 22:15:53 -0400 | [diff] [blame] | 5105 | surface->configure = screensaver_configure; |
Giulio Camuffo | 7fe01b1 | 2013-03-28 18:02:42 +0100 | [diff] [blame] | 5106 | surface->configure_private = shell; |
Pekka Paalanen | 77346a6 | 2011-11-30 16:26:35 +0200 | [diff] [blame] | 5107 | surface->output = output; |
Pekka Paalanen | 6e16811 | 2011-11-24 11:34:05 +0200 | [diff] [blame] | 5108 | } |
| 5109 | |
| 5110 | static const struct screensaver_interface screensaver_implementation = { |
| 5111 | screensaver_set_surface |
| 5112 | }; |
| 5113 | |
| 5114 | static void |
| 5115 | unbind_screensaver(struct wl_resource *resource) |
| 5116 | { |
Jason Ekstrand | 651f00e | 2013-06-14 10:07:54 -0500 | [diff] [blame] | 5117 | struct desktop_shell *shell = wl_resource_get_user_data(resource); |
Pekka Paalanen | 6e16811 | 2011-11-24 11:34:05 +0200 | [diff] [blame] | 5118 | |
Pekka Paalanen | 77346a6 | 2011-11-30 16:26:35 +0200 | [diff] [blame] | 5119 | shell->screensaver.binding = NULL; |
Pekka Paalanen | 6e16811 | 2011-11-24 11:34:05 +0200 | [diff] [blame] | 5120 | } |
| 5121 | |
| 5122 | static void |
| 5123 | bind_screensaver(struct wl_client *client, |
| 5124 | void *data, uint32_t version, uint32_t id) |
| 5125 | { |
Tiago Vignatti | be14326 | 2012-04-16 17:31:41 +0300 | [diff] [blame] | 5126 | struct desktop_shell *shell = data; |
Pekka Paalanen | 6e16811 | 2011-11-24 11:34:05 +0200 | [diff] [blame] | 5127 | struct wl_resource *resource; |
| 5128 | |
Jason Ekstrand | a85118c | 2013-06-27 20:17:02 -0500 | [diff] [blame] | 5129 | resource = wl_resource_create(client, &screensaver_interface, 1, id); |
Pekka Paalanen | 6e16811 | 2011-11-24 11:34:05 +0200 | [diff] [blame] | 5130 | |
Pekka Paalanen | 77346a6 | 2011-11-30 16:26:35 +0200 | [diff] [blame] | 5131 | if (shell->screensaver.binding == NULL) { |
Jason Ekstrand | a85118c | 2013-06-27 20:17:02 -0500 | [diff] [blame] | 5132 | wl_resource_set_implementation(resource, |
| 5133 | &screensaver_implementation, |
| 5134 | shell, unbind_screensaver); |
Pekka Paalanen | 77346a6 | 2011-11-30 16:26:35 +0200 | [diff] [blame] | 5135 | shell->screensaver.binding = resource; |
Pekka Paalanen | 6e16811 | 2011-11-24 11:34:05 +0200 | [diff] [blame] | 5136 | return; |
| 5137 | } |
| 5138 | |
| 5139 | wl_resource_post_error(resource, WL_DISPLAY_ERROR_INVALID_OBJECT, |
| 5140 | "interface object already bound"); |
Kristian Høgsberg | eae5de7 | 2012-04-11 22:42:15 -0400 | [diff] [blame] | 5141 | wl_resource_destroy(resource); |
Pekka Paalanen | 6e16811 | 2011-11-24 11:34:05 +0200 | [diff] [blame] | 5142 | } |
| 5143 | |
Kristian Høgsberg | 0704539 | 2012-02-19 18:52:44 -0500 | [diff] [blame] | 5144 | struct switcher { |
Tiago Vignatti | be14326 | 2012-04-16 17:31:41 +0300 | [diff] [blame] | 5145 | struct desktop_shell *shell; |
Kristian Høgsberg | 0704539 | 2012-02-19 18:52:44 -0500 | [diff] [blame] | 5146 | struct weston_surface *current; |
| 5147 | struct wl_listener listener; |
Kristian Høgsberg | 29139d4 | 2013-04-18 15:25:39 -0400 | [diff] [blame] | 5148 | struct weston_keyboard_grab grab; |
Kristian Høgsberg | 0704539 | 2012-02-19 18:52:44 -0500 | [diff] [blame] | 5149 | }; |
| 5150 | |
| 5151 | static void |
| 5152 | switcher_next(struct switcher *switcher) |
| 5153 | { |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 5154 | struct weston_view *view; |
Kristian Høgsberg | 0704539 | 2012-02-19 18:52:44 -0500 | [diff] [blame] | 5155 | struct weston_surface *first = NULL, *prev = NULL, *next = NULL; |
Kristian Høgsberg | 32e5686 | 2012-04-02 22:18:58 -0400 | [diff] [blame] | 5156 | struct shell_surface *shsurf; |
Kristian Høgsberg | b0d8e77 | 2012-06-18 16:34:58 -0400 | [diff] [blame] | 5157 | struct workspace *ws = get_current_workspace(switcher->shell); |
Kristian Høgsberg | 0704539 | 2012-02-19 18:52:44 -0500 | [diff] [blame] | 5158 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 5159 | wl_list_for_each(view, &ws->layer.view_list, layer_link) { |
Rafael Antognolli | ed207b4 | 2013-12-03 15:35:43 -0200 | [diff] [blame] | 5160 | shsurf = get_shell_surface(view->surface); |
Rafael Antognolli | 5031cbe | 2013-12-05 19:01:21 -0200 | [diff] [blame] | 5161 | if (shsurf && |
| 5162 | shsurf->type == SHELL_SURFACE_TOPLEVEL && |
| 5163 | shsurf->parent == NULL) { |
Kristian Høgsberg | 0704539 | 2012-02-19 18:52:44 -0500 | [diff] [blame] | 5164 | if (first == NULL) |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 5165 | first = view->surface; |
Kristian Høgsberg | 0704539 | 2012-02-19 18:52:44 -0500 | [diff] [blame] | 5166 | if (prev == switcher->current) |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 5167 | next = view->surface; |
| 5168 | prev = view->surface; |
| 5169 | view->alpha = 0.25; |
| 5170 | weston_view_geometry_dirty(view); |
| 5171 | weston_surface_damage(view->surface); |
Kristian Høgsberg | 0704539 | 2012-02-19 18:52:44 -0500 | [diff] [blame] | 5172 | } |
Alex Wu | 1659daa | 2012-04-01 20:13:09 +0800 | [diff] [blame] | 5173 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 5174 | if (is_black_surface(view->surface, NULL)) { |
| 5175 | view->alpha = 0.25; |
| 5176 | weston_view_geometry_dirty(view); |
| 5177 | weston_surface_damage(view->surface); |
Alex Wu | 1659daa | 2012-04-01 20:13:09 +0800 | [diff] [blame] | 5178 | } |
Kristian Høgsberg | 0704539 | 2012-02-19 18:52:44 -0500 | [diff] [blame] | 5179 | } |
| 5180 | |
| 5181 | if (next == NULL) |
| 5182 | next = first; |
| 5183 | |
Alex Wu | 07b2606 | 2012-03-12 16:06:01 +0800 | [diff] [blame] | 5184 | if (next == NULL) |
| 5185 | return; |
| 5186 | |
Kristian Høgsberg | 0704539 | 2012-02-19 18:52:44 -0500 | [diff] [blame] | 5187 | wl_list_remove(&switcher->listener.link); |
Jason Ekstrand | 26ed73c | 2013-06-06 22:34:41 -0500 | [diff] [blame] | 5188 | wl_signal_add(&next->destroy_signal, &switcher->listener); |
Kristian Høgsberg | 0704539 | 2012-02-19 18:52:44 -0500 | [diff] [blame] | 5189 | |
| 5190 | switcher->current = next; |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 5191 | wl_list_for_each(view, &next->views, surface_link) |
| 5192 | view->alpha = 1.0; |
Alex Wu | 1659daa | 2012-04-01 20:13:09 +0800 | [diff] [blame] | 5193 | |
Kristian Høgsberg | 32e5686 | 2012-04-02 22:18:58 -0400 | [diff] [blame] | 5194 | shsurf = get_shell_surface(switcher->current); |
Rafael Antognolli | 03b1659 | 2013-12-03 15:35:42 -0200 | [diff] [blame] | 5195 | if (shsurf && shsurf->state.fullscreen) |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 5196 | shsurf->fullscreen.black_view->alpha = 1.0; |
Kristian Høgsberg | 0704539 | 2012-02-19 18:52:44 -0500 | [diff] [blame] | 5197 | } |
| 5198 | |
| 5199 | static void |
Kristian Høgsberg | 27e3052 | 2012-04-11 23:18:23 -0400 | [diff] [blame] | 5200 | switcher_handle_surface_destroy(struct wl_listener *listener, void *data) |
Kristian Høgsberg | 0704539 | 2012-02-19 18:52:44 -0500 | [diff] [blame] | 5201 | { |
| 5202 | struct switcher *switcher = |
| 5203 | container_of(listener, struct switcher, listener); |
| 5204 | |
| 5205 | switcher_next(switcher); |
| 5206 | } |
| 5207 | |
| 5208 | static void |
Daniel Stone | 351eb61 | 2012-05-31 15:27:47 -0400 | [diff] [blame] | 5209 | switcher_destroy(struct switcher *switcher) |
Kristian Høgsberg | 0704539 | 2012-02-19 18:52:44 -0500 | [diff] [blame] | 5210 | { |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 5211 | struct weston_view *view; |
Kristian Høgsberg | 29139d4 | 2013-04-18 15:25:39 -0400 | [diff] [blame] | 5212 | struct weston_keyboard *keyboard = switcher->grab.keyboard; |
Kristian Høgsberg | b0d8e77 | 2012-06-18 16:34:58 -0400 | [diff] [blame] | 5213 | struct workspace *ws = get_current_workspace(switcher->shell); |
Kristian Høgsberg | 0704539 | 2012-02-19 18:52:44 -0500 | [diff] [blame] | 5214 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 5215 | 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] | 5216 | if (is_focus_view(view)) |
| 5217 | continue; |
| 5218 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 5219 | view->alpha = 1.0; |
| 5220 | weston_surface_damage(view->surface); |
Kristian Høgsberg | 0704539 | 2012-02-19 18:52:44 -0500 | [diff] [blame] | 5221 | } |
| 5222 | |
Alex Wu | 07b2606 | 2012-03-12 16:06:01 +0800 | [diff] [blame] | 5223 | if (switcher->current) |
Daniel Stone | 37816df | 2012-05-16 18:45:18 +0100 | [diff] [blame] | 5224 | activate(switcher->shell, switcher->current, |
| 5225 | (struct weston_seat *) keyboard->seat); |
Kristian Høgsberg | 0704539 | 2012-02-19 18:52:44 -0500 | [diff] [blame] | 5226 | wl_list_remove(&switcher->listener.link); |
Kristian Høgsberg | 29139d4 | 2013-04-18 15:25:39 -0400 | [diff] [blame] | 5227 | weston_keyboard_end_grab(keyboard); |
| 5228 | if (keyboard->input_method_resource) |
| 5229 | keyboard->grab = &keyboard->input_method_grab; |
Kristian Høgsberg | 0704539 | 2012-02-19 18:52:44 -0500 | [diff] [blame] | 5230 | free(switcher); |
| 5231 | } |
| 5232 | |
| 5233 | static void |
Kristian Høgsberg | 29139d4 | 2013-04-18 15:25:39 -0400 | [diff] [blame] | 5234 | switcher_key(struct weston_keyboard_grab *grab, |
Daniel Stone | c9785ea | 2012-05-30 16:31:52 +0100 | [diff] [blame] | 5235 | uint32_t time, uint32_t key, uint32_t state_w) |
Kristian Høgsberg | 0704539 | 2012-02-19 18:52:44 -0500 | [diff] [blame] | 5236 | { |
| 5237 | struct switcher *switcher = container_of(grab, struct switcher, grab); |
Daniel Stone | c9785ea | 2012-05-30 16:31:52 +0100 | [diff] [blame] | 5238 | enum wl_keyboard_key_state state = state_w; |
Daniel Stone | 351eb61 | 2012-05-31 15:27:47 -0400 | [diff] [blame] | 5239 | |
Daniel Stone | c9785ea | 2012-05-30 16:31:52 +0100 | [diff] [blame] | 5240 | if (key == KEY_TAB && state == WL_KEYBOARD_KEY_STATE_PRESSED) |
Daniel Stone | 351eb61 | 2012-05-31 15:27:47 -0400 | [diff] [blame] | 5241 | switcher_next(switcher); |
| 5242 | } |
| 5243 | |
| 5244 | static void |
Kristian Høgsberg | 29139d4 | 2013-04-18 15:25:39 -0400 | [diff] [blame] | 5245 | switcher_modifier(struct weston_keyboard_grab *grab, uint32_t serial, |
Daniel Stone | 351eb61 | 2012-05-31 15:27:47 -0400 | [diff] [blame] | 5246 | uint32_t mods_depressed, uint32_t mods_latched, |
| 5247 | uint32_t mods_locked, uint32_t group) |
| 5248 | { |
| 5249 | struct switcher *switcher = container_of(grab, struct switcher, grab); |
Daniel Stone | 37816df | 2012-05-16 18:45:18 +0100 | [diff] [blame] | 5250 | struct weston_seat *seat = (struct weston_seat *) grab->keyboard->seat; |
Kristian Høgsberg | 0704539 | 2012-02-19 18:52:44 -0500 | [diff] [blame] | 5251 | |
Daniel Stone | 351eb61 | 2012-05-31 15:27:47 -0400 | [diff] [blame] | 5252 | if ((seat->modifier_state & switcher->shell->binding_modifier) == 0) |
| 5253 | switcher_destroy(switcher); |
Kristian Høgsberg | b71302e | 2012-05-10 12:28:35 -0400 | [diff] [blame] | 5254 | } |
Kristian Høgsberg | 0704539 | 2012-02-19 18:52:44 -0500 | [diff] [blame] | 5255 | |
Jonas Ådahl | 1ea343e | 2013-10-25 23:18:05 +0200 | [diff] [blame] | 5256 | static void |
| 5257 | switcher_cancel(struct weston_keyboard_grab *grab) |
| 5258 | { |
| 5259 | struct switcher *switcher = container_of(grab, struct switcher, grab); |
| 5260 | |
| 5261 | switcher_destroy(switcher); |
| 5262 | } |
| 5263 | |
Kristian Høgsberg | 29139d4 | 2013-04-18 15:25:39 -0400 | [diff] [blame] | 5264 | static const struct weston_keyboard_grab_interface switcher_grab = { |
Daniel Stone | 351eb61 | 2012-05-31 15:27:47 -0400 | [diff] [blame] | 5265 | switcher_key, |
| 5266 | switcher_modifier, |
Jonas Ådahl | 1ea343e | 2013-10-25 23:18:05 +0200 | [diff] [blame] | 5267 | switcher_cancel, |
Kristian Høgsberg | 0704539 | 2012-02-19 18:52:44 -0500 | [diff] [blame] | 5268 | }; |
| 5269 | |
| 5270 | static void |
Kristian Høgsberg | e314875 | 2013-05-06 23:19:49 -0400 | [diff] [blame] | 5271 | switcher_binding(struct weston_seat *seat, uint32_t time, uint32_t key, |
Daniel Stone | 325fc2d | 2012-05-30 16:31:58 +0100 | [diff] [blame] | 5272 | void *data) |
Kristian Høgsberg | 0704539 | 2012-02-19 18:52:44 -0500 | [diff] [blame] | 5273 | { |
Tiago Vignatti | be14326 | 2012-04-16 17:31:41 +0300 | [diff] [blame] | 5274 | struct desktop_shell *shell = data; |
Kristian Høgsberg | 0704539 | 2012-02-19 18:52:44 -0500 | [diff] [blame] | 5275 | struct switcher *switcher; |
| 5276 | |
| 5277 | switcher = malloc(sizeof *switcher); |
Kristian Høgsberg | 02e79dc | 2012-04-12 09:55:26 -0400 | [diff] [blame] | 5278 | switcher->shell = shell; |
Kristian Høgsberg | 0704539 | 2012-02-19 18:52:44 -0500 | [diff] [blame] | 5279 | switcher->current = NULL; |
Kristian Høgsberg | 27e3052 | 2012-04-11 23:18:23 -0400 | [diff] [blame] | 5280 | switcher->listener.notify = switcher_handle_surface_destroy; |
Kristian Høgsberg | 0704539 | 2012-02-19 18:52:44 -0500 | [diff] [blame] | 5281 | wl_list_init(&switcher->listener.link); |
| 5282 | |
Alexander Larsson | f82b6ca | 2013-05-28 16:23:39 +0200 | [diff] [blame] | 5283 | restore_all_output_modes(shell->compositor); |
Kristian Høgsberg | b0d8e77 | 2012-06-18 16:34:58 -0400 | [diff] [blame] | 5284 | lower_fullscreen_layer(switcher->shell); |
Kristian Høgsberg | 0704539 | 2012-02-19 18:52:44 -0500 | [diff] [blame] | 5285 | switcher->grab.interface = &switcher_grab; |
Kristian Høgsberg | 29139d4 | 2013-04-18 15:25:39 -0400 | [diff] [blame] | 5286 | weston_keyboard_start_grab(seat->keyboard, &switcher->grab); |
| 5287 | weston_keyboard_set_focus(seat->keyboard, NULL); |
Kristian Høgsberg | 0704539 | 2012-02-19 18:52:44 -0500 | [diff] [blame] | 5288 | switcher_next(switcher); |
| 5289 | } |
| 5290 | |
Pekka Paalanen | 3c64723 | 2011-12-22 13:43:43 +0200 | [diff] [blame] | 5291 | static void |
Kristian Høgsberg | e314875 | 2013-05-06 23:19:49 -0400 | [diff] [blame] | 5292 | backlight_binding(struct weston_seat *seat, uint32_t time, uint32_t key, |
Daniel Stone | 325fc2d | 2012-05-30 16:31:58 +0100 | [diff] [blame] | 5293 | void *data) |
Tiago Vignatti | 8e53c7f | 2012-02-29 19:53:50 +0200 | [diff] [blame] | 5294 | { |
| 5295 | struct weston_compositor *compositor = data; |
| 5296 | struct weston_output *output; |
Tiago Vignatti | 5ab91ad | 2012-03-12 19:40:09 -0300 | [diff] [blame] | 5297 | long backlight_new = 0; |
Tiago Vignatti | 8e53c7f | 2012-02-29 19:53:50 +0200 | [diff] [blame] | 5298 | |
| 5299 | /* TODO: we're limiting to simple use cases, where we assume just |
| 5300 | * control on the primary display. We'd have to extend later if we |
| 5301 | * ever get support for setting backlights on random desktop LCD |
| 5302 | * panels though */ |
| 5303 | output = get_default_output(compositor); |
| 5304 | if (!output) |
| 5305 | return; |
| 5306 | |
| 5307 | if (!output->set_backlight) |
| 5308 | return; |
| 5309 | |
Tiago Vignatti | 5ab91ad | 2012-03-12 19:40:09 -0300 | [diff] [blame] | 5310 | if (key == KEY_F9 || key == KEY_BRIGHTNESSDOWN) |
| 5311 | backlight_new = output->backlight_current - 25; |
| 5312 | else if (key == KEY_F10 || key == KEY_BRIGHTNESSUP) |
| 5313 | backlight_new = output->backlight_current + 25; |
Tiago Vignatti | 8e53c7f | 2012-02-29 19:53:50 +0200 | [diff] [blame] | 5314 | |
Tiago Vignatti | 5ab91ad | 2012-03-12 19:40:09 -0300 | [diff] [blame] | 5315 | if (backlight_new < 5) |
| 5316 | backlight_new = 5; |
| 5317 | if (backlight_new > 255) |
| 5318 | backlight_new = 255; |
| 5319 | |
| 5320 | output->backlight_current = backlight_new; |
Tiago Vignatti | 8e53c7f | 2012-02-29 19:53:50 +0200 | [diff] [blame] | 5321 | output->set_backlight(output, output->backlight_current); |
| 5322 | } |
| 5323 | |
Ander Conselvan de Oliveira | c509d2b | 2012-11-08 17:20:45 +0200 | [diff] [blame] | 5324 | struct debug_binding_grab { |
Kristian Høgsberg | 29139d4 | 2013-04-18 15:25:39 -0400 | [diff] [blame] | 5325 | struct weston_keyboard_grab grab; |
Ander Conselvan de Oliveira | c509d2b | 2012-11-08 17:20:45 +0200 | [diff] [blame] | 5326 | struct weston_seat *seat; |
| 5327 | uint32_t key[2]; |
| 5328 | int key_released[2]; |
| 5329 | }; |
| 5330 | |
| 5331 | static void |
Kristian Høgsberg | 29139d4 | 2013-04-18 15:25:39 -0400 | [diff] [blame] | 5332 | 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] | 5333 | uint32_t key, uint32_t state) |
| 5334 | { |
| 5335 | struct debug_binding_grab *db = (struct debug_binding_grab *) grab; |
Rob Bradford | 880ebc7 | 2013-07-22 17:31:38 +0100 | [diff] [blame] | 5336 | struct weston_compositor *ec = db->seat->compositor; |
| 5337 | struct wl_display *display = ec->wl_display; |
Ander Conselvan de Oliveira | c509d2b | 2012-11-08 17:20:45 +0200 | [diff] [blame] | 5338 | struct wl_resource *resource; |
Ander Conselvan de Oliveira | c509d2b | 2012-11-08 17:20:45 +0200 | [diff] [blame] | 5339 | uint32_t serial; |
| 5340 | int send = 0, terminate = 0; |
| 5341 | int check_binding = 1; |
| 5342 | int i; |
Neil Roberts | 96d790e | 2013-09-19 17:32:00 +0100 | [diff] [blame] | 5343 | struct wl_list *resource_list; |
Ander Conselvan de Oliveira | c509d2b | 2012-11-08 17:20:45 +0200 | [diff] [blame] | 5344 | |
| 5345 | if (state == WL_KEYBOARD_KEY_STATE_RELEASED) { |
| 5346 | /* Do not run bindings on key releases */ |
| 5347 | check_binding = 0; |
| 5348 | |
| 5349 | for (i = 0; i < 2; i++) |
| 5350 | if (key == db->key[i]) |
| 5351 | db->key_released[i] = 1; |
| 5352 | |
| 5353 | if (db->key_released[0] && db->key_released[1]) { |
| 5354 | /* All key releases been swalled so end the grab */ |
| 5355 | terminate = 1; |
| 5356 | } else if (key != db->key[0] && key != db->key[1]) { |
| 5357 | /* Should not swallow release of other keys */ |
| 5358 | send = 1; |
| 5359 | } |
| 5360 | } else if (key == db->key[0] && !db->key_released[0]) { |
| 5361 | /* Do not check bindings for the first press of the binding |
| 5362 | * key. This allows it to be used as a debug shortcut. |
| 5363 | * We still need to swallow this event. */ |
| 5364 | check_binding = 0; |
| 5365 | } else if (db->key[1]) { |
| 5366 | /* If we already ran a binding don't process another one since |
| 5367 | * we can't keep track of all the binding keys that were |
| 5368 | * pressed in order to swallow the release events. */ |
| 5369 | send = 1; |
| 5370 | check_binding = 0; |
| 5371 | } |
| 5372 | |
| 5373 | if (check_binding) { |
Ander Conselvan de Oliveira | c509d2b | 2012-11-08 17:20:45 +0200 | [diff] [blame] | 5374 | if (weston_compositor_run_debug_binding(ec, db->seat, time, |
| 5375 | key, state)) { |
| 5376 | /* We ran a binding so swallow the press and keep the |
| 5377 | * grab to swallow the released too. */ |
| 5378 | send = 0; |
| 5379 | terminate = 0; |
| 5380 | db->key[1] = key; |
| 5381 | } else { |
| 5382 | /* Terminate the grab since the key pressed is not a |
| 5383 | * debug binding key. */ |
| 5384 | send = 1; |
| 5385 | terminate = 1; |
| 5386 | } |
| 5387 | } |
| 5388 | |
| 5389 | if (send) { |
Neil Roberts | 96d790e | 2013-09-19 17:32:00 +0100 | [diff] [blame] | 5390 | serial = wl_display_next_serial(display); |
| 5391 | resource_list = &grab->keyboard->focus_resource_list; |
| 5392 | wl_resource_for_each(resource, resource_list) { |
Ander Conselvan de Oliveira | c509d2b | 2012-11-08 17:20:45 +0200 | [diff] [blame] | 5393 | wl_keyboard_send_key(resource, serial, time, key, state); |
| 5394 | } |
| 5395 | } |
| 5396 | |
| 5397 | if (terminate) { |
Kristian Høgsberg | 29139d4 | 2013-04-18 15:25:39 -0400 | [diff] [blame] | 5398 | weston_keyboard_end_grab(grab->keyboard); |
| 5399 | if (grab->keyboard->input_method_resource) |
| 5400 | grab->keyboard->grab = &grab->keyboard->input_method_grab; |
Ander Conselvan de Oliveira | c509d2b | 2012-11-08 17:20:45 +0200 | [diff] [blame] | 5401 | free(db); |
| 5402 | } |
| 5403 | } |
| 5404 | |
| 5405 | static void |
Kristian Høgsberg | 29139d4 | 2013-04-18 15:25:39 -0400 | [diff] [blame] | 5406 | 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] | 5407 | uint32_t mods_depressed, uint32_t mods_latched, |
| 5408 | uint32_t mods_locked, uint32_t group) |
| 5409 | { |
| 5410 | struct wl_resource *resource; |
Neil Roberts | 96d790e | 2013-09-19 17:32:00 +0100 | [diff] [blame] | 5411 | struct wl_list *resource_list; |
Ander Conselvan de Oliveira | c509d2b | 2012-11-08 17:20:45 +0200 | [diff] [blame] | 5412 | |
Neil Roberts | 96d790e | 2013-09-19 17:32:00 +0100 | [diff] [blame] | 5413 | resource_list = &grab->keyboard->focus_resource_list; |
Ander Conselvan de Oliveira | c509d2b | 2012-11-08 17:20:45 +0200 | [diff] [blame] | 5414 | |
Neil Roberts | 96d790e | 2013-09-19 17:32:00 +0100 | [diff] [blame] | 5415 | wl_resource_for_each(resource, resource_list) { |
| 5416 | wl_keyboard_send_modifiers(resource, serial, mods_depressed, |
| 5417 | mods_latched, mods_locked, group); |
| 5418 | } |
Ander Conselvan de Oliveira | c509d2b | 2012-11-08 17:20:45 +0200 | [diff] [blame] | 5419 | } |
| 5420 | |
Jonas Ådahl | 1ea343e | 2013-10-25 23:18:05 +0200 | [diff] [blame] | 5421 | static void |
| 5422 | debug_binding_cancel(struct weston_keyboard_grab *grab) |
| 5423 | { |
| 5424 | struct debug_binding_grab *db = (struct debug_binding_grab *) grab; |
| 5425 | |
| 5426 | weston_keyboard_end_grab(grab->keyboard); |
| 5427 | free(db); |
| 5428 | } |
| 5429 | |
Kristian Høgsberg | 29139d4 | 2013-04-18 15:25:39 -0400 | [diff] [blame] | 5430 | struct weston_keyboard_grab_interface debug_binding_keyboard_grab = { |
Ander Conselvan de Oliveira | c509d2b | 2012-11-08 17:20:45 +0200 | [diff] [blame] | 5431 | debug_binding_key, |
Jonas Ådahl | 1ea343e | 2013-10-25 23:18:05 +0200 | [diff] [blame] | 5432 | debug_binding_modifiers, |
| 5433 | debug_binding_cancel, |
Ander Conselvan de Oliveira | c509d2b | 2012-11-08 17:20:45 +0200 | [diff] [blame] | 5434 | }; |
| 5435 | |
| 5436 | static void |
Kristian Høgsberg | e314875 | 2013-05-06 23:19:49 -0400 | [diff] [blame] | 5437 | 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] | 5438 | { |
| 5439 | struct debug_binding_grab *grab; |
| 5440 | |
| 5441 | grab = calloc(1, sizeof *grab); |
| 5442 | if (!grab) |
| 5443 | return; |
| 5444 | |
| 5445 | grab->seat = (struct weston_seat *) seat; |
| 5446 | grab->key[0] = key; |
| 5447 | grab->grab.interface = &debug_binding_keyboard_grab; |
Kristian Høgsberg | 29139d4 | 2013-04-18 15:25:39 -0400 | [diff] [blame] | 5448 | weston_keyboard_start_grab(seat->keyboard, &grab->grab); |
Ander Conselvan de Oliveira | c509d2b | 2012-11-08 17:20:45 +0200 | [diff] [blame] | 5449 | } |
| 5450 | |
Kristian Høgsberg | b41c081 | 2012-03-04 14:53:40 -0500 | [diff] [blame] | 5451 | static void |
Kristian Høgsberg | e314875 | 2013-05-06 23:19:49 -0400 | [diff] [blame] | 5452 | 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] | 5453 | void *data) |
Kristian Høgsberg | 92a57db | 2012-05-26 13:41:06 -0400 | [diff] [blame] | 5454 | { |
Kristian Høgsberg | fe7aa90 | 2013-05-08 09:54:37 -0400 | [diff] [blame] | 5455 | struct weston_surface *focus_surface; |
Kristian Høgsberg | 92a57db | 2012-05-26 13:41:06 -0400 | [diff] [blame] | 5456 | struct wl_client *client; |
Tiago Vignatti | 1d01b01 | 2012-09-27 17:48:36 +0300 | [diff] [blame] | 5457 | struct desktop_shell *shell = data; |
| 5458 | struct weston_compositor *compositor = shell->compositor; |
Kristian Høgsberg | 92a57db | 2012-05-26 13:41:06 -0400 | [diff] [blame] | 5459 | pid_t pid; |
Kristian Høgsberg | 92a57db | 2012-05-26 13:41:06 -0400 | [diff] [blame] | 5460 | |
Philipp Brüschweiler | 6cef009 | 2012-08-13 21:27:27 +0200 | [diff] [blame] | 5461 | focus_surface = seat->keyboard->focus; |
| 5462 | if (!focus_surface) |
| 5463 | return; |
| 5464 | |
Tiago Vignatti | 1d01b01 | 2012-09-27 17:48:36 +0300 | [diff] [blame] | 5465 | wl_signal_emit(&compositor->kill_signal, focus_surface); |
| 5466 | |
Jason Ekstrand | 26ed73c | 2013-06-06 22:34:41 -0500 | [diff] [blame] | 5467 | client = wl_resource_get_client(focus_surface->resource); |
Tiago Vignatti | 920f197 | 2012-09-27 17:48:35 +0300 | [diff] [blame] | 5468 | wl_client_get_credentials(client, &pid, NULL, NULL); |
| 5469 | |
| 5470 | /* Skip clients that we launched ourselves (the credentials of |
| 5471 | * the socketpair is ours) */ |
| 5472 | if (pid == getpid()) |
| 5473 | return; |
Kristian Høgsberg | 92a57db | 2012-05-26 13:41:06 -0400 | [diff] [blame] | 5474 | |
Daniel Stone | 325fc2d | 2012-05-30 16:31:58 +0100 | [diff] [blame] | 5475 | kill(pid, SIGKILL); |
Kristian Høgsberg | 92a57db | 2012-05-26 13:41:06 -0400 | [diff] [blame] | 5476 | } |
| 5477 | |
| 5478 | static void |
Kristian Høgsberg | e314875 | 2013-05-06 23:19:49 -0400 | [diff] [blame] | 5479 | workspace_up_binding(struct weston_seat *seat, uint32_t time, |
Jonas Ådahl | e3cddce | 2012-06-13 00:01:22 +0200 | [diff] [blame] | 5480 | uint32_t key, void *data) |
| 5481 | { |
| 5482 | struct desktop_shell *shell = data; |
| 5483 | unsigned int new_index = shell->workspaces.current; |
| 5484 | |
Kristian Høgsberg | ce345b0 | 2012-06-25 21:35:29 -0400 | [diff] [blame] | 5485 | if (shell->locked) |
Kristian Høgsberg | 4476aaf | 2012-06-25 14:03:13 -0400 | [diff] [blame] | 5486 | return; |
Jonas Ådahl | e3cddce | 2012-06-13 00:01:22 +0200 | [diff] [blame] | 5487 | if (new_index != 0) |
| 5488 | new_index--; |
| 5489 | |
| 5490 | change_workspace(shell, new_index); |
| 5491 | } |
| 5492 | |
| 5493 | static void |
Kristian Høgsberg | e314875 | 2013-05-06 23:19:49 -0400 | [diff] [blame] | 5494 | workspace_down_binding(struct weston_seat *seat, uint32_t time, |
Jonas Ådahl | e3cddce | 2012-06-13 00:01:22 +0200 | [diff] [blame] | 5495 | uint32_t key, void *data) |
| 5496 | { |
| 5497 | struct desktop_shell *shell = data; |
| 5498 | unsigned int new_index = shell->workspaces.current; |
| 5499 | |
Kristian Høgsberg | ce345b0 | 2012-06-25 21:35:29 -0400 | [diff] [blame] | 5500 | if (shell->locked) |
Kristian Høgsberg | 4476aaf | 2012-06-25 14:03:13 -0400 | [diff] [blame] | 5501 | return; |
Jonas Ådahl | e3cddce | 2012-06-13 00:01:22 +0200 | [diff] [blame] | 5502 | if (new_index < shell->workspaces.num - 1) |
| 5503 | new_index++; |
| 5504 | |
| 5505 | change_workspace(shell, new_index); |
| 5506 | } |
| 5507 | |
| 5508 | static void |
Kristian Høgsberg | e314875 | 2013-05-06 23:19:49 -0400 | [diff] [blame] | 5509 | workspace_f_binding(struct weston_seat *seat, uint32_t time, |
Jonas Ådahl | e3cddce | 2012-06-13 00:01:22 +0200 | [diff] [blame] | 5510 | uint32_t key, void *data) |
| 5511 | { |
| 5512 | struct desktop_shell *shell = data; |
| 5513 | unsigned int new_index; |
| 5514 | |
Kristian Høgsberg | ce345b0 | 2012-06-25 21:35:29 -0400 | [diff] [blame] | 5515 | if (shell->locked) |
Kristian Høgsberg | 4476aaf | 2012-06-25 14:03:13 -0400 | [diff] [blame] | 5516 | return; |
Jonas Ådahl | e3cddce | 2012-06-13 00:01:22 +0200 | [diff] [blame] | 5517 | new_index = key - KEY_F1; |
| 5518 | if (new_index >= shell->workspaces.num) |
| 5519 | new_index = shell->workspaces.num - 1; |
| 5520 | |
| 5521 | change_workspace(shell, new_index); |
| 5522 | } |
| 5523 | |
Jonas Ådahl | 8de6a1d | 2012-08-29 22:13:00 +0200 | [diff] [blame] | 5524 | static void |
Kristian Høgsberg | e314875 | 2013-05-06 23:19:49 -0400 | [diff] [blame] | 5525 | workspace_move_surface_up_binding(struct weston_seat *seat, uint32_t time, |
Jonas Ådahl | 8de6a1d | 2012-08-29 22:13:00 +0200 | [diff] [blame] | 5526 | uint32_t key, void *data) |
| 5527 | { |
| 5528 | struct desktop_shell *shell = data; |
| 5529 | unsigned int new_index = shell->workspaces.current; |
| 5530 | |
| 5531 | if (shell->locked) |
| 5532 | return; |
| 5533 | |
| 5534 | if (new_index != 0) |
| 5535 | new_index--; |
| 5536 | |
| 5537 | take_surface_to_workspace_by_seat(shell, seat, new_index); |
| 5538 | } |
| 5539 | |
| 5540 | static void |
Kristian Høgsberg | e314875 | 2013-05-06 23:19:49 -0400 | [diff] [blame] | 5541 | workspace_move_surface_down_binding(struct weston_seat *seat, uint32_t time, |
Jonas Ådahl | 8de6a1d | 2012-08-29 22:13:00 +0200 | [diff] [blame] | 5542 | uint32_t key, void *data) |
| 5543 | { |
| 5544 | struct desktop_shell *shell = data; |
| 5545 | unsigned int new_index = shell->workspaces.current; |
| 5546 | |
| 5547 | if (shell->locked) |
| 5548 | return; |
| 5549 | |
| 5550 | if (new_index < shell->workspaces.num - 1) |
| 5551 | new_index++; |
| 5552 | |
| 5553 | take_surface_to_workspace_by_seat(shell, seat, new_index); |
| 5554 | } |
Jonas Ådahl | e3cddce | 2012-06-13 00:01:22 +0200 | [diff] [blame] | 5555 | |
| 5556 | static void |
Xiong Zhang | 6b48142 | 2013-10-23 13:58:32 +0800 | [diff] [blame] | 5557 | handle_output_destroy(struct wl_listener *listener, void *data) |
| 5558 | { |
| 5559 | struct shell_output *output_listener = |
| 5560 | container_of(listener, struct shell_output, destroy_listener); |
| 5561 | |
| 5562 | wl_list_remove(&output_listener->destroy_listener.link); |
| 5563 | wl_list_remove(&output_listener->link); |
| 5564 | free(output_listener); |
| 5565 | } |
| 5566 | |
| 5567 | static void |
| 5568 | create_shell_output(struct desktop_shell *shell, |
| 5569 | struct weston_output *output) |
| 5570 | { |
| 5571 | struct shell_output *shell_output; |
| 5572 | |
| 5573 | shell_output = zalloc(sizeof *shell_output); |
| 5574 | if (shell_output == NULL) |
| 5575 | return; |
| 5576 | |
| 5577 | shell_output->output = output; |
| 5578 | shell_output->shell = shell; |
| 5579 | shell_output->destroy_listener.notify = handle_output_destroy; |
| 5580 | wl_signal_add(&output->destroy_signal, |
| 5581 | &shell_output->destroy_listener); |
Kristian Høgsberg | a3a0e18 | 2013-10-23 23:36:04 -0700 | [diff] [blame] | 5582 | wl_list_insert(shell->output_list.prev, &shell_output->link); |
Xiong Zhang | 6b48142 | 2013-10-23 13:58:32 +0800 | [diff] [blame] | 5583 | } |
| 5584 | |
| 5585 | static void |
| 5586 | handle_output_create(struct wl_listener *listener, void *data) |
| 5587 | { |
| 5588 | struct desktop_shell *shell = |
| 5589 | container_of(listener, struct desktop_shell, output_create_listener); |
| 5590 | struct weston_output *output = (struct weston_output *)data; |
| 5591 | |
| 5592 | create_shell_output(shell, output); |
| 5593 | } |
| 5594 | |
| 5595 | static void |
| 5596 | setup_output_destroy_handler(struct weston_compositor *ec, |
| 5597 | struct desktop_shell *shell) |
| 5598 | { |
| 5599 | struct weston_output *output; |
| 5600 | |
| 5601 | wl_list_init(&shell->output_list); |
| 5602 | wl_list_for_each(output, &ec->output_list, link) |
| 5603 | create_shell_output(shell, output); |
| 5604 | |
| 5605 | shell->output_create_listener.notify = handle_output_create; |
| 5606 | wl_signal_add(&ec->output_created_signal, |
| 5607 | &shell->output_create_listener); |
| 5608 | } |
| 5609 | |
| 5610 | static void |
Kristian Høgsberg | 02e79dc | 2012-04-12 09:55:26 -0400 | [diff] [blame] | 5611 | shell_destroy(struct wl_listener *listener, void *data) |
Pekka Paalanen | 3c64723 | 2011-12-22 13:43:43 +0200 | [diff] [blame] | 5612 | { |
Tiago Vignatti | be14326 | 2012-04-16 17:31:41 +0300 | [diff] [blame] | 5613 | struct desktop_shell *shell = |
| 5614 | container_of(listener, struct desktop_shell, destroy_listener); |
Jonas Ådahl | e3cddce | 2012-06-13 00:01:22 +0200 | [diff] [blame] | 5615 | struct workspace **ws; |
Xiong Zhang | 6b48142 | 2013-10-23 13:58:32 +0800 | [diff] [blame] | 5616 | struct shell_output *shell_output, *tmp; |
Pekka Paalanen | 3c64723 | 2011-12-22 13:43:43 +0200 | [diff] [blame] | 5617 | |
Pekka Paalanen | 9cf5cc8 | 2012-01-02 16:00:24 +0200 | [diff] [blame] | 5618 | if (shell->child.client) |
| 5619 | wl_client_destroy(shell->child.client); |
| 5620 | |
Ander Conselvan de Oliveira | a457563 | 2013-02-21 18:35:23 +0200 | [diff] [blame] | 5621 | wl_list_remove(&shell->idle_listener.link); |
| 5622 | wl_list_remove(&shell->wake_listener.link); |
Kristian Høgsberg | 677a5f5 | 2013-12-04 11:00:19 -0800 | [diff] [blame] | 5623 | |
| 5624 | input_panel_destroy(shell); |
Kristian Høgsberg | 88c1607 | 2012-05-16 08:04:19 -0400 | [diff] [blame] | 5625 | |
Xiong Zhang | 6b48142 | 2013-10-23 13:58:32 +0800 | [diff] [blame] | 5626 | wl_list_for_each_safe(shell_output, tmp, &shell->output_list, link) { |
| 5627 | wl_list_remove(&shell_output->destroy_listener.link); |
| 5628 | wl_list_remove(&shell_output->link); |
| 5629 | free(shell_output); |
| 5630 | } |
| 5631 | |
| 5632 | wl_list_remove(&shell->output_create_listener.link); |
| 5633 | |
Jonas Ådahl | e3cddce | 2012-06-13 00:01:22 +0200 | [diff] [blame] | 5634 | wl_array_for_each(ws, &shell->workspaces.array) |
| 5635 | workspace_destroy(*ws); |
| 5636 | wl_array_release(&shell->workspaces.array); |
| 5637 | |
Pekka Paalanen | 3c64723 | 2011-12-22 13:43:43 +0200 | [diff] [blame] | 5638 | free(shell->screensaver.path); |
Emilio Pozuelo Monfort | 46ce798 | 2013-11-20 13:22:29 +0100 | [diff] [blame] | 5639 | free(shell->client); |
Pekka Paalanen | 3c64723 | 2011-12-22 13:43:43 +0200 | [diff] [blame] | 5640 | free(shell); |
| 5641 | } |
| 5642 | |
Tiago Vignatti | 0b52d48 | 2012-04-20 18:54:25 +0300 | [diff] [blame] | 5643 | static void |
| 5644 | shell_add_bindings(struct weston_compositor *ec, struct desktop_shell *shell) |
| 5645 | { |
| 5646 | uint32_t mod; |
Jonas Ådahl | e3cddce | 2012-06-13 00:01:22 +0200 | [diff] [blame] | 5647 | int i, num_workspace_bindings; |
Tiago Vignatti | 0b52d48 | 2012-04-20 18:54:25 +0300 | [diff] [blame] | 5648 | |
| 5649 | /* fixed bindings */ |
Daniel Stone | 325fc2d | 2012-05-30 16:31:58 +0100 | [diff] [blame] | 5650 | weston_compositor_add_key_binding(ec, KEY_BACKSPACE, |
| 5651 | MODIFIER_CTRL | MODIFIER_ALT, |
| 5652 | terminate_binding, ec); |
Emilio Pozuelo Monfort | 03251b6 | 2013-11-19 11:37:16 +0100 | [diff] [blame] | 5653 | weston_compositor_add_key_binding(ec, KEY_TAB, |
| 5654 | MODIFIER_ALT, |
| 5655 | alt_tab_binding, shell); |
Daniel Stone | 325fc2d | 2012-05-30 16:31:58 +0100 | [diff] [blame] | 5656 | weston_compositor_add_button_binding(ec, BTN_LEFT, 0, |
| 5657 | click_to_activate_binding, |
| 5658 | shell); |
Neil Roberts | a28c693 | 2013-10-03 16:43:04 +0100 | [diff] [blame] | 5659 | weston_compositor_add_touch_binding(ec, 0, |
| 5660 | touch_to_activate_binding, |
| 5661 | shell); |
Daniel Stone | 325fc2d | 2012-05-30 16:31:58 +0100 | [diff] [blame] | 5662 | weston_compositor_add_axis_binding(ec, WL_POINTER_AXIS_VERTICAL_SCROLL, |
| 5663 | MODIFIER_SUPER | MODIFIER_ALT, |
| 5664 | surface_opacity_binding, NULL); |
| 5665 | weston_compositor_add_axis_binding(ec, WL_POINTER_AXIS_VERTICAL_SCROLL, |
| 5666 | MODIFIER_SUPER, zoom_axis_binding, |
| 5667 | NULL); |
Tiago Vignatti | 0b52d48 | 2012-04-20 18:54:25 +0300 | [diff] [blame] | 5668 | |
| 5669 | /* configurable bindings */ |
| 5670 | mod = shell->binding_modifier; |
Daniel Stone | 325fc2d | 2012-05-30 16:31:58 +0100 | [diff] [blame] | 5671 | weston_compositor_add_key_binding(ec, KEY_PAGEUP, mod, |
| 5672 | zoom_key_binding, NULL); |
| 5673 | weston_compositor_add_key_binding(ec, KEY_PAGEDOWN, mod, |
| 5674 | zoom_key_binding, NULL); |
Rafael Antognolli | ea997ac | 2013-12-03 15:35:48 -0200 | [diff] [blame] | 5675 | weston_compositor_add_key_binding(ec, KEY_M, mod, maximize_binding, |
| 5676 | NULL); |
| 5677 | weston_compositor_add_key_binding(ec, KEY_F, mod, fullscreen_binding, |
| 5678 | NULL); |
Daniel Stone | 325fc2d | 2012-05-30 16:31:58 +0100 | [diff] [blame] | 5679 | weston_compositor_add_button_binding(ec, BTN_LEFT, mod, move_binding, |
| 5680 | shell); |
Neil Roberts | aba0f25 | 2013-10-03 16:43:05 +0100 | [diff] [blame] | 5681 | weston_compositor_add_touch_binding(ec, mod, touch_move_binding, shell); |
Daniel Stone | 325fc2d | 2012-05-30 16:31:58 +0100 | [diff] [blame] | 5682 | weston_compositor_add_button_binding(ec, BTN_MIDDLE, mod, |
| 5683 | resize_binding, shell); |
Pekka Paalanen | 7bb6510 | 2013-05-22 18:03:04 +0300 | [diff] [blame] | 5684 | |
| 5685 | if (ec->capabilities & WESTON_CAP_ROTATION_ANY) |
| 5686 | weston_compositor_add_button_binding(ec, BTN_RIGHT, mod, |
| 5687 | rotate_binding, NULL); |
| 5688 | |
Daniel Stone | 325fc2d | 2012-05-30 16:31:58 +0100 | [diff] [blame] | 5689 | weston_compositor_add_key_binding(ec, KEY_TAB, mod, switcher_binding, |
| 5690 | shell); |
| 5691 | weston_compositor_add_key_binding(ec, KEY_F9, mod, backlight_binding, |
| 5692 | ec); |
| 5693 | weston_compositor_add_key_binding(ec, KEY_BRIGHTNESSDOWN, 0, |
| 5694 | backlight_binding, ec); |
| 5695 | weston_compositor_add_key_binding(ec, KEY_F10, mod, backlight_binding, |
| 5696 | ec); |
| 5697 | weston_compositor_add_key_binding(ec, KEY_BRIGHTNESSUP, 0, |
| 5698 | backlight_binding, ec); |
Daniel Stone | 325fc2d | 2012-05-30 16:31:58 +0100 | [diff] [blame] | 5699 | weston_compositor_add_key_binding(ec, KEY_K, mod, |
| 5700 | force_kill_binding, shell); |
Jonas Ådahl | e3cddce | 2012-06-13 00:01:22 +0200 | [diff] [blame] | 5701 | weston_compositor_add_key_binding(ec, KEY_UP, mod, |
| 5702 | workspace_up_binding, shell); |
| 5703 | weston_compositor_add_key_binding(ec, KEY_DOWN, mod, |
| 5704 | workspace_down_binding, shell); |
Jonas Ådahl | 8de6a1d | 2012-08-29 22:13:00 +0200 | [diff] [blame] | 5705 | weston_compositor_add_key_binding(ec, KEY_UP, mod | MODIFIER_SHIFT, |
| 5706 | workspace_move_surface_up_binding, |
| 5707 | shell); |
| 5708 | weston_compositor_add_key_binding(ec, KEY_DOWN, mod | MODIFIER_SHIFT, |
| 5709 | workspace_move_surface_down_binding, |
| 5710 | shell); |
Jonas Ådahl | e3cddce | 2012-06-13 00:01:22 +0200 | [diff] [blame] | 5711 | |
Daniel Stone | df8133b | 2013-11-19 11:37:14 +0100 | [diff] [blame] | 5712 | weston_compositor_add_modifier_binding(ec, mod, exposay_binding, shell); |
| 5713 | |
Jonas Ådahl | e3cddce | 2012-06-13 00:01:22 +0200 | [diff] [blame] | 5714 | /* Add bindings for mod+F[1-6] for workspace 1 to 6. */ |
| 5715 | if (shell->workspaces.num > 1) { |
| 5716 | num_workspace_bindings = shell->workspaces.num; |
| 5717 | if (num_workspace_bindings > 6) |
| 5718 | num_workspace_bindings = 6; |
| 5719 | for (i = 0; i < num_workspace_bindings; i++) |
| 5720 | weston_compositor_add_key_binding(ec, KEY_F1 + i, mod, |
| 5721 | workspace_f_binding, |
| 5722 | shell); |
| 5723 | } |
Ander Conselvan de Oliveira | c509d2b | 2012-11-08 17:20:45 +0200 | [diff] [blame] | 5724 | |
| 5725 | /* Debug bindings */ |
| 5726 | weston_compositor_add_key_binding(ec, KEY_SPACE, mod | MODIFIER_SHIFT, |
| 5727 | debug_binding, shell); |
Tiago Vignatti | 0b52d48 | 2012-04-20 18:54:25 +0300 | [diff] [blame] | 5728 | } |
| 5729 | |
Kristian Høgsberg | 1c56218 | 2011-05-02 22:09:20 -0400 | [diff] [blame] | 5730 | WL_EXPORT int |
Kristian Høgsberg | cb4685b | 2013-02-20 15:37:49 -0500 | [diff] [blame] | 5731 | module_init(struct weston_compositor *ec, |
Ossama Othman | a50e6e4 | 2013-05-14 09:48:26 -0700 | [diff] [blame] | 5732 | int *argc, char *argv[]) |
Kristian Høgsberg | 4cca349 | 2011-01-18 07:53:49 -0500 | [diff] [blame] | 5733 | { |
Kristian Høgsberg | f4d2f23 | 2012-08-10 10:05:39 -0400 | [diff] [blame] | 5734 | struct weston_seat *seat; |
Tiago Vignatti | be14326 | 2012-04-16 17:31:41 +0300 | [diff] [blame] | 5735 | struct desktop_shell *shell; |
Jonas Ådahl | e3cddce | 2012-06-13 00:01:22 +0200 | [diff] [blame] | 5736 | struct workspace **pws; |
| 5737 | unsigned int i; |
Tiago Vignatti | b7dbbd6 | 2012-09-25 17:57:01 +0300 | [diff] [blame] | 5738 | struct wl_event_loop *loop; |
Kristian Høgsberg | 02ec0a5 | 2011-04-23 13:04:11 -0400 | [diff] [blame] | 5739 | |
Peter Hutterer | f3d6227 | 2013-08-08 11:57:05 +1000 | [diff] [blame] | 5740 | shell = zalloc(sizeof *shell); |
Kristian Høgsberg | 02ec0a5 | 2011-04-23 13:04:11 -0400 | [diff] [blame] | 5741 | if (shell == NULL) |
| 5742 | return -1; |
| 5743 | |
Kristian Høgsberg | 7584062 | 2011-09-06 13:48:16 -0400 | [diff] [blame] | 5744 | shell->compositor = ec; |
Kristian Høgsberg | 02e79dc | 2012-04-12 09:55:26 -0400 | [diff] [blame] | 5745 | |
| 5746 | shell->destroy_listener.notify = shell_destroy; |
| 5747 | wl_signal_add(&ec->destroy_signal, &shell->destroy_listener); |
Ander Conselvan de Oliveira | a457563 | 2013-02-21 18:35:23 +0200 | [diff] [blame] | 5748 | shell->idle_listener.notify = idle_handler; |
| 5749 | wl_signal_add(&ec->idle_signal, &shell->idle_listener); |
| 5750 | shell->wake_listener.notify = wake_handler; |
| 5751 | wl_signal_add(&ec->wake_signal, &shell->wake_listener); |
Kristian Høgsberg | 677a5f5 | 2013-12-04 11:00:19 -0800 | [diff] [blame] | 5752 | |
Scott Moreau | ff1db4a | 2012-04-17 19:06:18 -0600 | [diff] [blame] | 5753 | ec->ping_handler = ping_handler; |
Kristian Høgsberg | 82a1d11 | 2012-07-19 14:02:00 -0400 | [diff] [blame] | 5754 | ec->shell_interface.shell = shell; |
Tiago Vignatti | bc052c9 | 2012-04-19 16:18:18 +0300 | [diff] [blame] | 5755 | ec->shell_interface.create_shell_surface = create_shell_surface; |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 5756 | ec->shell_interface.get_primary_view = get_primary_view; |
Tiago Vignatti | bc052c9 | 2012-04-19 16:18:18 +0300 | [diff] [blame] | 5757 | ec->shell_interface.set_toplevel = set_toplevel; |
Tiago Vignatti | 491bac1 | 2012-05-18 16:37:43 -0400 | [diff] [blame] | 5758 | ec->shell_interface.set_transient = set_transient; |
Kristian Høgsberg | b810eb5 | 2013-02-12 20:07:05 -0500 | [diff] [blame] | 5759 | ec->shell_interface.set_fullscreen = set_fullscreen; |
Tiago Vignatti | fb2adba | 2013-06-12 15:43:21 -0300 | [diff] [blame] | 5760 | ec->shell_interface.set_xwayland = set_xwayland; |
Kristian Høgsberg | 938b8fa | 2012-05-18 13:46:27 -0400 | [diff] [blame] | 5761 | ec->shell_interface.move = surface_move; |
Kristian Høgsberg | c1693f2 | 2012-05-22 16:56:23 -0400 | [diff] [blame] | 5762 | ec->shell_interface.resize = surface_resize; |
Giulio Camuffo | 62942ad | 2013-09-11 18:20:47 +0200 | [diff] [blame] | 5763 | ec->shell_interface.set_title = set_title; |
Kristian Høgsberg | 4cca349 | 2011-01-18 07:53:49 -0500 | [diff] [blame] | 5764 | |
Kristian Høgsberg | 3be2ce9 | 2012-02-29 12:42:35 -0500 | [diff] [blame] | 5765 | weston_layer_init(&shell->fullscreen_layer, &ec->cursor_layer.link); |
| 5766 | weston_layer_init(&shell->panel_layer, &shell->fullscreen_layer.link); |
Jonas Ådahl | e3cddce | 2012-06-13 00:01:22 +0200 | [diff] [blame] | 5767 | weston_layer_init(&shell->background_layer, &shell->panel_layer.link); |
| 5768 | weston_layer_init(&shell->lock_layer, NULL); |
Philipp Brüschweiler | 711fda8 | 2012-08-09 18:50:43 +0200 | [diff] [blame] | 5769 | weston_layer_init(&shell->input_panel_layer, NULL); |
Jonas Ådahl | e3cddce | 2012-06-13 00:01:22 +0200 | [diff] [blame] | 5770 | |
| 5771 | wl_array_init(&shell->workspaces.array); |
Jonas Ådahl | e9d2250 | 2012-08-29 22:13:01 +0200 | [diff] [blame] | 5772 | wl_list_init(&shell->workspaces.client_list); |
Kristian Høgsberg | 3be2ce9 | 2012-02-29 12:42:35 -0500 | [diff] [blame] | 5773 | |
Kristian Høgsberg | 677a5f5 | 2013-12-04 11:00:19 -0800 | [diff] [blame] | 5774 | if (input_panel_setup(shell) < 0) |
| 5775 | return -1; |
| 5776 | |
Kristian Høgsberg | 14e438c | 2013-05-26 21:48:14 -0400 | [diff] [blame] | 5777 | shell_configuration(shell); |
Pekka Paalanen | e955f1e | 2011-12-07 11:49:52 +0200 | [diff] [blame] | 5778 | |
Daniel Stone | df8133b | 2013-11-19 11:37:14 +0100 | [diff] [blame] | 5779 | shell->exposay.state_cur = EXPOSAY_LAYOUT_INACTIVE; |
| 5780 | shell->exposay.state_target = EXPOSAY_TARGET_CANCEL; |
| 5781 | |
Jonas Ådahl | e3cddce | 2012-06-13 00:01:22 +0200 | [diff] [blame] | 5782 | for (i = 0; i < shell->workspaces.num; i++) { |
| 5783 | pws = wl_array_add(&shell->workspaces.array, sizeof *pws); |
| 5784 | if (pws == NULL) |
| 5785 | return -1; |
| 5786 | |
| 5787 | *pws = workspace_create(); |
| 5788 | if (*pws == NULL) |
| 5789 | return -1; |
| 5790 | } |
| 5791 | activate_workspace(shell, 0); |
| 5792 | |
Jonas Ådahl | 8de6a1d | 2012-08-29 22:13:00 +0200 | [diff] [blame] | 5793 | wl_list_init(&shell->workspaces.anim_sticky_list); |
Jonas Ådahl | 62fcd04 | 2012-06-13 00:01:23 +0200 | [diff] [blame] | 5794 | wl_list_init(&shell->workspaces.animation.link); |
| 5795 | shell->workspaces.animation.frame = animate_workspace_change_frame; |
| 5796 | |
Kristian Høgsberg | 919cddb | 2013-07-08 19:03:57 -0400 | [diff] [blame] | 5797 | if (wl_global_create(ec->wl_display, &wl_shell_interface, 1, |
Kristian Høgsberg | 97d44aa | 2011-08-26 17:21:20 -0400 | [diff] [blame] | 5798 | shell, bind_shell) == NULL) |
Kristian Høgsberg | 4cca349 | 2011-01-18 07:53:49 -0500 | [diff] [blame] | 5799 | return -1; |
| 5800 | |
Rafael Antognolli | e2a3455 | 2013-12-03 15:35:45 -0200 | [diff] [blame] | 5801 | if (wl_global_create(ec->wl_display, &xdg_shell_interface, 1, |
| 5802 | shell, bind_xdg_shell) == NULL) |
| 5803 | return -1; |
| 5804 | |
Kristian Høgsberg | 919cddb | 2013-07-08 19:03:57 -0400 | [diff] [blame] | 5805 | if (wl_global_create(ec->wl_display, |
| 5806 | &desktop_shell_interface, 2, |
| 5807 | shell, bind_desktop_shell) == NULL) |
Kristian Høgsberg | 7584062 | 2011-09-06 13:48:16 -0400 | [diff] [blame] | 5808 | return -1; |
| 5809 | |
Kristian Høgsberg | 919cddb | 2013-07-08 19:03:57 -0400 | [diff] [blame] | 5810 | if (wl_global_create(ec->wl_display, &screensaver_interface, 1, |
| 5811 | shell, bind_screensaver) == NULL) |
Pekka Paalanen | 6e16811 | 2011-11-24 11:34:05 +0200 | [diff] [blame] | 5812 | return -1; |
| 5813 | |
Kristian Høgsberg | 919cddb | 2013-07-08 19:03:57 -0400 | [diff] [blame] | 5814 | if (wl_global_create(ec->wl_display, &workspace_manager_interface, 1, |
| 5815 | shell, bind_workspace_manager) == NULL) |
Jonas Ådahl | e9d2250 | 2012-08-29 22:13:01 +0200 | [diff] [blame] | 5816 | return -1; |
| 5817 | |
Kristian Høgsberg | f03a616 | 2012-01-17 11:07:42 -0500 | [diff] [blame] | 5818 | shell->child.deathstamp = weston_compositor_get_time(); |
Tiago Vignatti | b7dbbd6 | 2012-09-25 17:57:01 +0300 | [diff] [blame] | 5819 | |
Xiong Zhang | 6b48142 | 2013-10-23 13:58:32 +0800 | [diff] [blame] | 5820 | setup_output_destroy_handler(ec, shell); |
| 5821 | |
Tiago Vignatti | b7dbbd6 | 2012-09-25 17:57:01 +0300 | [diff] [blame] | 5822 | loop = wl_display_get_event_loop(ec->wl_display); |
| 5823 | wl_event_loop_add_idle(loop, launch_desktop_shell_process, shell); |
Pekka Paalanen | 6cd281a | 2011-11-03 14:11:32 +0200 | [diff] [blame] | 5824 | |
Ander Conselvan de Oliveira | 859e885 | 2013-02-21 18:35:21 +0200 | [diff] [blame] | 5825 | shell->screensaver.timer = |
| 5826 | wl_event_loop_add_timer(loop, screensaver_timeout, shell); |
| 5827 | |
Kristian Høgsberg | f4d2f23 | 2012-08-10 10:05:39 -0400 | [diff] [blame] | 5828 | wl_list_for_each(seat, &ec->seat_list, link) |
| 5829 | create_pointer_focus_listener(seat); |
Kristian Høgsberg | d56bd90 | 2012-06-05 09:58:51 -0400 | [diff] [blame] | 5830 | |
Tiago Vignatti | 0b52d48 | 2012-04-20 18:54:25 +0300 | [diff] [blame] | 5831 | shell_add_bindings(ec, shell); |
Kristian Høgsberg | 0793756 | 2011-04-12 17:25:42 -0400 | [diff] [blame] | 5832 | |
Pekka Paalanen | 79346ab | 2013-05-22 18:03:09 +0300 | [diff] [blame] | 5833 | shell_fade_init(shell); |
Ander Conselvan de Oliveira | 19d10ef | 2013-02-21 18:35:20 +0200 | [diff] [blame] | 5834 | |
Kristian Høgsberg | 4cca349 | 2011-01-18 07:53:49 -0500 | [diff] [blame] | 5835 | return 0; |
| 5836 | } |