Kristian Høgsberg | 4cca349 | 2011-01-18 07:53:49 -0500 | [diff] [blame] | 1 | /* |
Kristian Høgsberg | 0704539 | 2012-02-19 18:52:44 -0500 | [diff] [blame] | 2 | * Copyright © 2010-2012 Intel Corporation |
Pekka Paalanen | d581a8f | 2012-01-27 16:25:16 +0200 | [diff] [blame] | 3 | * Copyright © 2011-2012 Collabora, Ltd. |
Daniel Stone | df8133b | 2013-11-19 11:37:14 +0100 | [diff] [blame] | 4 | * Copyright © 2013 Raspberry Pi Foundation |
Kristian Høgsberg | 4cca349 | 2011-01-18 07:53:49 -0500 | [diff] [blame] | 5 | * |
| 6 | * Permission to use, copy, modify, distribute, and sell this software and |
| 7 | * its documentation for any purpose is hereby granted without fee, provided |
| 8 | * that the above copyright notice appear in all copies and that both that |
| 9 | * copyright notice and this permission notice appear in supporting |
| 10 | * documentation, and that the name of the copyright holders not be used in |
| 11 | * advertising or publicity pertaining to distribution of the software |
| 12 | * without specific, written prior permission. The copyright holders make |
| 13 | * no representations about the suitability of this software for any |
| 14 | * purpose. It is provided "as is" without express or implied warranty. |
| 15 | * |
| 16 | * THE COPYRIGHT HOLDERS DISCLAIM ALL WARRANTIES WITH REGARD TO THIS |
| 17 | * SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND |
| 18 | * FITNESS, IN NO EVENT SHALL THE COPYRIGHT HOLDERS BE LIABLE FOR ANY |
| 19 | * SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER |
| 20 | * RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF |
| 21 | * CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN |
| 22 | * CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. |
| 23 | */ |
| 24 | |
Daniel Stone | c228e23 | 2013-05-22 18:03:19 +0300 | [diff] [blame] | 25 | #include "config.h" |
| 26 | |
Kristian Høgsberg | 4cca349 | 2011-01-18 07:53:49 -0500 | [diff] [blame] | 27 | #include <stdlib.h> |
Kristian Høgsberg | 7584062 | 2011-09-06 13:48:16 -0400 | [diff] [blame] | 28 | #include <stdio.h> |
Kristian Høgsberg | 4cca349 | 2011-01-18 07:53:49 -0500 | [diff] [blame] | 29 | #include <string.h> |
| 30 | #include <unistd.h> |
Kristian Høgsberg | 0793756 | 2011-04-12 17:25:42 -0400 | [diff] [blame] | 31 | #include <linux/input.h> |
Pekka Paalanen | f0fc70d | 2011-11-15 13:34:54 +0200 | [diff] [blame] | 32 | #include <assert.h> |
Pekka Paalanen | 18027e5 | 2011-12-02 16:31:49 +0200 | [diff] [blame] | 33 | #include <signal.h> |
Pekka Paalanen | 460099f | 2012-01-20 16:48:25 +0200 | [diff] [blame] | 34 | #include <math.h> |
Kristian Høgsberg | 92a57db | 2012-05-26 13:41:06 -0400 | [diff] [blame] | 35 | #include <sys/types.h> |
Kristian Høgsberg | 4cca349 | 2011-01-18 07:53:49 -0500 | [diff] [blame] | 36 | |
Kristian Høgsberg | 1ef2313 | 2013-12-04 00:20:01 -0800 | [diff] [blame] | 37 | #include "shell.h" |
Kristian Høgsberg | 7584062 | 2011-09-06 13:48:16 -0400 | [diff] [blame] | 38 | #include "desktop-shell-server-protocol.h" |
Jonas Ådahl | e9d2250 | 2012-08-29 22:13:01 +0200 | [diff] [blame] | 39 | #include "workspaces-server-protocol.h" |
Pekka Paalanen | e955f1e | 2011-12-07 11:49:52 +0200 | [diff] [blame] | 40 | #include "../shared/config-parser.h" |
Rafael Antognolli | e2a3455 | 2013-12-03 15:35:45 -0200 | [diff] [blame] | 41 | #include "xdg-shell-server-protocol.h" |
Kristian Høgsberg | 4cca349 | 2011-01-18 07:53:49 -0500 | [diff] [blame] | 42 | |
Jonas Ådahl | e3cddce | 2012-06-13 00:01:22 +0200 | [diff] [blame] | 43 | #define DEFAULT_NUM_WORKSPACES 1 |
Jonas Ådahl | 62fcd04 | 2012-06-13 00:01:23 +0200 | [diff] [blame] | 44 | #define DEFAULT_WORKSPACE_CHANGE_ANIMATION_LENGTH 200 |
Jonas Ådahl | e3cddce | 2012-06-13 00:01:22 +0200 | [diff] [blame] | 45 | |
Giulio Camuffo | 1aaf3e4 | 2013-12-09 22:47:58 +0100 | [diff] [blame^] | 46 | #ifndef static_assert |
| 47 | #define static_assert(cond, msg) |
| 48 | #endif |
| 49 | |
Jonas Ådahl | 0476974 | 2012-06-13 00:01:24 +0200 | [diff] [blame] | 50 | struct focus_state { |
| 51 | struct weston_seat *seat; |
Kristian Høgsberg | 2f5faff | 2012-07-31 16:36:34 -0400 | [diff] [blame] | 52 | struct workspace *ws; |
Jonas Ådahl | 0476974 | 2012-06-13 00:01:24 +0200 | [diff] [blame] | 53 | struct weston_surface *keyboard_focus; |
| 54 | struct wl_list link; |
| 55 | struct wl_listener seat_destroy_listener; |
| 56 | struct wl_listener surface_destroy_listener; |
| 57 | }; |
| 58 | |
Xiong Zhang | 6b48142 | 2013-10-23 13:58:32 +0800 | [diff] [blame] | 59 | struct shell_output { |
| 60 | struct desktop_shell *shell; |
| 61 | struct weston_output *output; |
| 62 | struct wl_listener destroy_listener; |
| 63 | struct wl_list link; |
| 64 | }; |
| 65 | |
Kristian Høgsberg | d2abb83 | 2011-11-23 10:52:40 -0500 | [diff] [blame] | 66 | enum shell_surface_type { |
Pekka Paalanen | 9826223 | 2011-12-01 10:42:22 +0200 | [diff] [blame] | 67 | SHELL_SURFACE_NONE, |
Kristian Høgsberg | d2abb83 | 2011-11-23 10:52:40 -0500 | [diff] [blame] | 68 | SHELL_SURFACE_TOPLEVEL, |
Tiago Vignatti | fb2adba | 2013-06-12 15:43:21 -0300 | [diff] [blame] | 69 | SHELL_SURFACE_POPUP, |
| 70 | SHELL_SURFACE_XWAYLAND |
Pekka Paalanen | 57da4a8 | 2011-11-23 16:42:16 +0200 | [diff] [blame] | 71 | }; |
| 72 | |
Scott Moreau | ff1db4a | 2012-04-17 19:06:18 -0600 | [diff] [blame] | 73 | struct ping_timer { |
| 74 | struct wl_event_source *source; |
Scott Moreau | ff1db4a | 2012-04-17 19:06:18 -0600 | [diff] [blame] | 75 | uint32_t serial; |
| 76 | }; |
| 77 | |
Philip Withnall | 648a4dd | 2013-11-25 18:01:44 +0000 | [diff] [blame] | 78 | /* |
| 79 | * Surface stacking and ordering. |
| 80 | * |
| 81 | * This is handled using several linked lists of surfaces, organised into |
| 82 | * ‘layers’. The layers are ordered, and each of the surfaces in one layer are |
| 83 | * above all of the surfaces in the layer below. The set of layers is static and |
| 84 | * in the following order (top-most first): |
| 85 | * • Lock layer (only ever displayed on its own) |
| 86 | * • Cursor layer |
| 87 | * • Fullscreen layer |
| 88 | * • Panel layer |
| 89 | * • Input panel layer |
| 90 | * • Workspace layers |
| 91 | * • Background layer |
| 92 | * |
| 93 | * The list of layers may be manipulated to remove whole layers of surfaces from |
| 94 | * display. For example, when locking the screen, all layers except the lock |
| 95 | * layer are removed. |
| 96 | * |
| 97 | * A surface’s layer is modified on configuring the surface, in |
| 98 | * set_surface_type() (which is only called when the surface’s type change is |
| 99 | * _committed_). If a surface’s type changes (e.g. when making a window |
| 100 | * fullscreen) its layer changes too. |
| 101 | * |
| 102 | * In order to allow popup and transient surfaces to be correctly stacked above |
| 103 | * their parent surfaces, each surface tracks both its parent surface, and a |
| 104 | * linked list of its children. When a surface’s layer is updated, so are the |
| 105 | * layers of its children. Note that child surfaces are *not* the same as |
| 106 | * subsurfaces — child/parent surfaces are purely for maintaining stacking |
| 107 | * order. |
| 108 | * |
| 109 | * The children_link list of siblings of a surface (i.e. those surfaces which |
| 110 | * have the same parent) only contains weston_surfaces which have a |
| 111 | * shell_surface. Stacking is not implemented for non-shell_surface |
| 112 | * weston_surfaces. This means that the following implication does *not* hold: |
| 113 | * (shsurf->parent != NULL) ⇒ !wl_list_is_empty(shsurf->children_link) |
| 114 | */ |
| 115 | |
Pekka Paalanen | 56cdea9 | 2011-11-23 16:14:12 +0200 | [diff] [blame] | 116 | struct shell_surface { |
Jason Ekstrand | 651f00e | 2013-06-14 10:07:54 -0500 | [diff] [blame] | 117 | struct wl_resource *resource; |
| 118 | struct wl_signal destroy_signal; |
Pekka Paalanen | 9d1613e | 2011-11-25 12:09:16 +0200 | [diff] [blame] | 119 | |
Kristian Høgsberg | 8334bc1 | 2012-01-03 10:29:47 -0500 | [diff] [blame] | 120 | struct weston_surface *surface; |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 121 | struct weston_view *view; |
Jason Ekstrand | 918f2dd | 2013-12-02 21:01:53 -0600 | [diff] [blame] | 122 | int32_t last_width, last_height; |
Pekka Paalanen | 9d1613e | 2011-11-25 12:09:16 +0200 | [diff] [blame] | 123 | struct wl_listener surface_destroy_listener; |
Kristian Høgsberg | 8150b19 | 2012-06-27 10:22:58 -0400 | [diff] [blame] | 124 | struct weston_surface *parent; |
Philip Withnall | 648a4dd | 2013-11-25 18:01:44 +0000 | [diff] [blame] | 125 | struct wl_list children_list; /* child surfaces of this one */ |
| 126 | struct wl_list children_link; /* sibling surfaces of this one */ |
Tiago Vignatti | be14326 | 2012-04-16 17:31:41 +0300 | [diff] [blame] | 127 | struct desktop_shell *shell; |
Pekka Paalanen | 57da4a8 | 2011-11-23 16:42:16 +0200 | [diff] [blame] | 128 | |
Kristian Høgsberg | c8f8dd8 | 2013-12-05 23:20:33 -0800 | [diff] [blame] | 129 | enum shell_surface_type type; |
Kristian Høgsberg | e7afd91 | 2012-05-02 09:47:44 -0400 | [diff] [blame] | 130 | char *title, *class; |
Kristian Høgsberg | d2abb83 | 2011-11-23 10:52:40 -0500 | [diff] [blame] | 131 | int32_t saved_x, saved_y; |
Rafael Antognolli | 3c4e3f7 | 2013-12-03 15:35:46 -0200 | [diff] [blame] | 132 | int32_t saved_width, saved_height; |
Alex Wu | 4539b08 | 2012-03-01 12:57:46 +0800 | [diff] [blame] | 133 | bool saved_position_valid; |
Rafael Antognolli | 3c4e3f7 | 2013-12-03 15:35:46 -0200 | [diff] [blame] | 134 | bool saved_size_valid; |
Alex Wu | 7bcb8bd | 2012-04-27 09:07:24 +0800 | [diff] [blame] | 135 | bool saved_rotation_valid; |
Kristian Høgsberg | c85f1d4 | 2013-10-24 16:52:00 -0700 | [diff] [blame] | 136 | int unresponsive, grabbed; |
Benjamin Franzke | d0f79ab | 2011-11-22 12:43:52 +0100 | [diff] [blame] | 137 | |
Kristian Høgsberg | b3cca0a | 2012-01-04 22:19:14 -0500 | [diff] [blame] | 138 | struct { |
Pekka Paalanen | 460099f | 2012-01-20 16:48:25 +0200 | [diff] [blame] | 139 | struct weston_transform transform; |
Kristian Høgsberg | 765e27b | 2012-01-27 13:36:13 -0500 | [diff] [blame] | 140 | struct weston_matrix rotation; |
Pekka Paalanen | 460099f | 2012-01-20 16:48:25 +0200 | [diff] [blame] | 141 | } rotation; |
| 142 | |
| 143 | struct { |
Giulio Camuffo | 5085a75 | 2013-03-25 21:42:45 +0100 | [diff] [blame] | 144 | struct wl_list grab_link; |
Kristian Høgsberg | b3cca0a | 2012-01-04 22:19:14 -0500 | [diff] [blame] | 145 | int32_t x, y; |
Giulio Camuffo | 5085a75 | 2013-03-25 21:42:45 +0100 | [diff] [blame] | 146 | struct shell_seat *shseat; |
Kristian Høgsberg | 3730f36 | 2012-04-13 12:40:07 -0400 | [diff] [blame] | 147 | uint32_t serial; |
Kristian Høgsberg | b3cca0a | 2012-01-04 22:19:14 -0500 | [diff] [blame] | 148 | } popup; |
| 149 | |
Alex Wu | 4539b08 | 2012-03-01 12:57:46 +0800 | [diff] [blame] | 150 | struct { |
Tiago Vignatti | 52e598c | 2012-05-07 15:23:08 +0300 | [diff] [blame] | 151 | int32_t x, y; |
Tiago Vignatti | 491bac1 | 2012-05-18 16:37:43 -0400 | [diff] [blame] | 152 | uint32_t flags; |
Tiago Vignatti | 52e598c | 2012-05-07 15:23:08 +0300 | [diff] [blame] | 153 | } transient; |
| 154 | |
| 155 | struct { |
Alex Wu | 4539b08 | 2012-03-01 12:57:46 +0800 | [diff] [blame] | 156 | enum wl_shell_surface_fullscreen_method type; |
| 157 | struct weston_transform transform; /* matrix from x, y */ |
| 158 | uint32_t framerate; |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 159 | struct weston_view *black_view; |
Alex Wu | 4539b08 | 2012-03-01 12:57:46 +0800 | [diff] [blame] | 160 | } fullscreen; |
| 161 | |
Scott Moreau | ff1db4a | 2012-04-17 19:06:18 -0600 | [diff] [blame] | 162 | struct ping_timer *ping_timer; |
| 163 | |
Jonas Ådahl | 62fcd04 | 2012-06-13 00:01:23 +0200 | [diff] [blame] | 164 | struct weston_transform workspace_transform; |
| 165 | |
Kristian Høgsberg | 1cbf326 | 2012-02-17 23:49:07 -0500 | [diff] [blame] | 166 | struct weston_output *fullscreen_output; |
Kristian Høgsberg | 8334bc1 | 2012-01-03 10:29:47 -0500 | [diff] [blame] | 167 | struct weston_output *output; |
Rafael Antognolli | 65f98d8 | 2013-12-03 15:35:47 -0200 | [diff] [blame] | 168 | struct weston_output *recommended_output; |
Benjamin Franzke | d0f79ab | 2011-11-22 12:43:52 +0100 | [diff] [blame] | 169 | struct wl_list link; |
Kristian Høgsberg | a61ca06 | 2012-05-22 16:05:52 -0400 | [diff] [blame] | 170 | |
| 171 | const struct weston_shell_client *client; |
Rafael Antognolli | 03b1659 | 2013-12-03 15:35:42 -0200 | [diff] [blame] | 172 | |
| 173 | struct { |
| 174 | bool maximized; |
| 175 | bool fullscreen; |
Rafael Antognolli | ed207b4 | 2013-12-03 15:35:43 -0200 | [diff] [blame] | 176 | bool relative; |
Rafael Antognolli | 03b1659 | 2013-12-03 15:35:42 -0200 | [diff] [blame] | 177 | } state, next_state; /* surface states */ |
| 178 | bool state_changed; |
Pekka Paalanen | 56cdea9 | 2011-11-23 16:14:12 +0200 | [diff] [blame] | 179 | }; |
| 180 | |
Ander Conselvan de Oliveira | fe0444a | 2012-04-04 17:48:05 +0300 | [diff] [blame] | 181 | struct shell_grab { |
Kristian Høgsberg | 02bbabb | 2013-05-06 22:15:05 -0400 | [diff] [blame] | 182 | struct weston_pointer_grab grab; |
Ander Conselvan de Oliveira | fe0444a | 2012-04-04 17:48:05 +0300 | [diff] [blame] | 183 | struct shell_surface *shsurf; |
| 184 | struct wl_listener shsurf_destroy_listener; |
| 185 | }; |
| 186 | |
Rusty Lynch | 1084da5 | 2013-08-15 09:10:08 -0700 | [diff] [blame] | 187 | struct shell_touch_grab { |
| 188 | struct weston_touch_grab grab; |
| 189 | struct shell_surface *shsurf; |
| 190 | struct wl_listener shsurf_destroy_listener; |
| 191 | struct weston_touch *touch; |
| 192 | }; |
| 193 | |
Ander Conselvan de Oliveira | fe0444a | 2012-04-04 17:48:05 +0300 | [diff] [blame] | 194 | struct weston_move_grab { |
| 195 | struct shell_grab base; |
Daniel Stone | 103db7f | 2012-05-08 17:17:55 +0100 | [diff] [blame] | 196 | wl_fixed_t dx, dy; |
Kristian Høgsberg | 4cca349 | 2011-01-18 07:53:49 -0500 | [diff] [blame] | 197 | }; |
| 198 | |
Rusty Lynch | 1084da5 | 2013-08-15 09:10:08 -0700 | [diff] [blame] | 199 | struct weston_touch_move_grab { |
| 200 | struct shell_touch_grab base; |
| 201 | wl_fixed_t dx, dy; |
| 202 | }; |
| 203 | |
Pekka Paalanen | 460099f | 2012-01-20 16:48:25 +0200 | [diff] [blame] | 204 | struct rotate_grab { |
Ander Conselvan de Oliveira | fe0444a | 2012-04-04 17:48:05 +0300 | [diff] [blame] | 205 | struct shell_grab base; |
Kristian Høgsberg | 765e27b | 2012-01-27 13:36:13 -0500 | [diff] [blame] | 206 | struct weston_matrix rotation; |
Pekka Paalanen | 460099f | 2012-01-20 16:48:25 +0200 | [diff] [blame] | 207 | struct { |
John Kåre Alsaker | 490d02a | 2012-09-30 02:57:21 +0200 | [diff] [blame] | 208 | float x; |
| 209 | float y; |
Pekka Paalanen | 460099f | 2012-01-20 16:48:25 +0200 | [diff] [blame] | 210 | } center; |
| 211 | }; |
| 212 | |
Giulio Camuffo | 5085a75 | 2013-03-25 21:42:45 +0100 | [diff] [blame] | 213 | struct shell_seat { |
| 214 | struct weston_seat *seat; |
| 215 | struct wl_listener seat_destroy_listener; |
| 216 | |
| 217 | struct { |
Kristian Høgsberg | 02bbabb | 2013-05-06 22:15:05 -0400 | [diff] [blame] | 218 | struct weston_pointer_grab grab; |
Giulio Camuffo | 5085a75 | 2013-03-25 21:42:45 +0100 | [diff] [blame] | 219 | struct wl_list surfaces_list; |
| 220 | struct wl_client *client; |
| 221 | int32_t initial_up; |
| 222 | } popup_grab; |
| 223 | }; |
| 224 | |
Alex Wu | bd3354b | 2012-04-17 17:20:49 +0800 | [diff] [blame] | 225 | static struct desktop_shell * |
| 226 | shell_surface_get_shell(struct shell_surface *shsurf); |
| 227 | |
Kristian Høgsberg | 0c36903 | 2013-02-14 21:31:44 -0500 | [diff] [blame] | 228 | static void |
Kristian Høgsberg | e314875 | 2013-05-06 23:19:49 -0400 | [diff] [blame] | 229 | surface_rotate(struct shell_surface *surface, struct weston_seat *seat); |
Kristian Høgsberg | 0c36903 | 2013-02-14 21:31:44 -0500 | [diff] [blame] | 230 | |
Pekka Paalanen | 79346ab | 2013-05-22 18:03:09 +0300 | [diff] [blame] | 231 | static void |
| 232 | shell_fade_startup(struct desktop_shell *shell); |
| 233 | |
Philip Withnall | becb77e | 2013-11-25 18:01:30 +0000 | [diff] [blame] | 234 | static struct shell_seat * |
| 235 | get_shell_seat(struct weston_seat *seat); |
| 236 | |
Philip Withnall | 648a4dd | 2013-11-25 18:01:44 +0000 | [diff] [blame] | 237 | static void |
| 238 | shell_surface_update_child_surface_layers(struct shell_surface *shsurf); |
| 239 | |
Alex Wu | bd3354b | 2012-04-17 17:20:49 +0800 | [diff] [blame] | 240 | static bool |
Rafael Antognolli | e2a3455 | 2013-12-03 15:35:45 -0200 | [diff] [blame] | 241 | shell_surface_is_wl_shell_surface(struct shell_surface *shsurf); |
| 242 | |
| 243 | static bool |
| 244 | shell_surface_is_xdg_surface(struct shell_surface *shsurf); |
| 245 | |
| 246 | static bool |
| 247 | shell_surface_is_xdg_popup(struct shell_surface *shsurf); |
| 248 | |
| 249 | static void |
| 250 | shell_surface_set_parent(struct shell_surface *shsurf, |
| 251 | struct weston_surface *parent); |
| 252 | |
| 253 | static bool |
Alex Wu | bd3354b | 2012-04-17 17:20:49 +0800 | [diff] [blame] | 254 | shell_surface_is_top_fullscreen(struct shell_surface *shsurf) |
| 255 | { |
| 256 | struct desktop_shell *shell; |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 257 | struct weston_view *top_fs_ev; |
Alex Wu | bd3354b | 2012-04-17 17:20:49 +0800 | [diff] [blame] | 258 | |
| 259 | shell = shell_surface_get_shell(shsurf); |
Quentin Glidic | c0d79ce | 2013-01-29 14:16:13 +0100 | [diff] [blame] | 260 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 261 | if (wl_list_empty(&shell->fullscreen_layer.view_list)) |
Alex Wu | bd3354b | 2012-04-17 17:20:49 +0800 | [diff] [blame] | 262 | return false; |
| 263 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 264 | top_fs_ev = container_of(shell->fullscreen_layer.view_list.next, |
| 265 | struct weston_view, |
Alex Wu | bd3354b | 2012-04-17 17:20:49 +0800 | [diff] [blame] | 266 | layer_link); |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 267 | return (shsurf == get_shell_surface(top_fs_ev->surface)); |
Alex Wu | bd3354b | 2012-04-17 17:20:49 +0800 | [diff] [blame] | 268 | } |
| 269 | |
Kristian Høgsberg | 6af8eb9 | 2012-01-25 16:57:11 -0500 | [diff] [blame] | 270 | static void |
Kristian Høgsberg | 27e3052 | 2012-04-11 23:18:23 -0400 | [diff] [blame] | 271 | destroy_shell_grab_shsurf(struct wl_listener *listener, void *data) |
Ander Conselvan de Oliveira | fe0444a | 2012-04-04 17:48:05 +0300 | [diff] [blame] | 272 | { |
| 273 | struct shell_grab *grab; |
| 274 | |
| 275 | grab = container_of(listener, struct shell_grab, |
| 276 | shsurf_destroy_listener); |
| 277 | |
| 278 | grab->shsurf = NULL; |
| 279 | } |
| 280 | |
Kristian Høgsberg | 1ef2313 | 2013-12-04 00:20:01 -0800 | [diff] [blame] | 281 | struct weston_view * |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 282 | get_default_view(struct weston_surface *surface) |
| 283 | { |
| 284 | struct shell_surface *shsurf; |
| 285 | struct weston_view *view; |
| 286 | |
| 287 | if (!surface || wl_list_empty(&surface->views)) |
| 288 | return NULL; |
| 289 | |
| 290 | shsurf = get_shell_surface(surface); |
| 291 | if (shsurf) |
| 292 | return shsurf->view; |
| 293 | |
| 294 | wl_list_for_each(view, &surface->views, surface_link) |
| 295 | if (weston_view_is_mapped(view)) |
| 296 | return view; |
| 297 | |
| 298 | return container_of(surface->views.next, struct weston_view, surface_link); |
| 299 | } |
| 300 | |
Ander Conselvan de Oliveira | fe0444a | 2012-04-04 17:48:05 +0300 | [diff] [blame] | 301 | static void |
Kristian Høgsberg | 02bbabb | 2013-05-06 22:15:05 -0400 | [diff] [blame] | 302 | popup_grab_end(struct weston_pointer *pointer); |
Kristian Høgsberg | 57e0907 | 2012-10-30 14:07:27 -0400 | [diff] [blame] | 303 | |
| 304 | static void |
Ander Conselvan de Oliveira | b9d2a0f | 2012-06-28 18:08:05 +0300 | [diff] [blame] | 305 | shell_grab_start(struct shell_grab *grab, |
Kristian Høgsberg | 02bbabb | 2013-05-06 22:15:05 -0400 | [diff] [blame] | 306 | const struct weston_pointer_grab_interface *interface, |
Ander Conselvan de Oliveira | b9d2a0f | 2012-06-28 18:08:05 +0300 | [diff] [blame] | 307 | struct shell_surface *shsurf, |
Kristian Høgsberg | 02bbabb | 2013-05-06 22:15:05 -0400 | [diff] [blame] | 308 | struct weston_pointer *pointer, |
Ander Conselvan de Oliveira | b9d2a0f | 2012-06-28 18:08:05 +0300 | [diff] [blame] | 309 | enum desktop_shell_cursor cursor) |
Ander Conselvan de Oliveira | fe0444a | 2012-04-04 17:48:05 +0300 | [diff] [blame] | 310 | { |
Ander Conselvan de Oliveira | b9d2a0f | 2012-06-28 18:08:05 +0300 | [diff] [blame] | 311 | struct desktop_shell *shell = shsurf->shell; |
| 312 | |
Kristian Høgsberg | 57e0907 | 2012-10-30 14:07:27 -0400 | [diff] [blame] | 313 | popup_grab_end(pointer); |
| 314 | |
Ander Conselvan de Oliveira | fe0444a | 2012-04-04 17:48:05 +0300 | [diff] [blame] | 315 | grab->grab.interface = interface; |
| 316 | grab->shsurf = shsurf; |
Kristian Høgsberg | 27e3052 | 2012-04-11 23:18:23 -0400 | [diff] [blame] | 317 | grab->shsurf_destroy_listener.notify = destroy_shell_grab_shsurf; |
Jason Ekstrand | 651f00e | 2013-06-14 10:07:54 -0500 | [diff] [blame] | 318 | wl_signal_add(&shsurf->destroy_signal, |
Kristian Høgsberg | 27e3052 | 2012-04-11 23:18:23 -0400 | [diff] [blame] | 319 | &grab->shsurf_destroy_listener); |
Ander Conselvan de Oliveira | fe0444a | 2012-04-04 17:48:05 +0300 | [diff] [blame] | 320 | |
Kristian Høgsberg | c85f1d4 | 2013-10-24 16:52:00 -0700 | [diff] [blame] | 321 | shsurf->grabbed = 1; |
Kristian Høgsberg | 02bbabb | 2013-05-06 22:15:05 -0400 | [diff] [blame] | 322 | weston_pointer_start_grab(pointer, &grab->grab); |
Kristian Høgsberg | c9974a0 | 2013-07-03 19:24:57 -0400 | [diff] [blame] | 323 | if (shell->child.desktop_shell) { |
| 324 | desktop_shell_send_grab_cursor(shell->child.desktop_shell, |
| 325 | cursor); |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 326 | weston_pointer_set_focus(pointer, |
| 327 | get_default_view(shell->grab_surface), |
Kristian Høgsberg | c9974a0 | 2013-07-03 19:24:57 -0400 | [diff] [blame] | 328 | wl_fixed_from_int(0), |
| 329 | wl_fixed_from_int(0)); |
| 330 | } |
Ander Conselvan de Oliveira | fe0444a | 2012-04-04 17:48:05 +0300 | [diff] [blame] | 331 | } |
| 332 | |
| 333 | static void |
Ander Conselvan de Oliveira | b9d2a0f | 2012-06-28 18:08:05 +0300 | [diff] [blame] | 334 | shell_grab_end(struct shell_grab *grab) |
Ander Conselvan de Oliveira | fe0444a | 2012-04-04 17:48:05 +0300 | [diff] [blame] | 335 | { |
Kristian Høgsberg | c85f1d4 | 2013-10-24 16:52:00 -0700 | [diff] [blame] | 336 | if (grab->shsurf) { |
Kristian Høgsberg | 47b5dca | 2012-06-07 18:08:04 -0400 | [diff] [blame] | 337 | wl_list_remove(&grab->shsurf_destroy_listener.link); |
Kristian Høgsberg | c85f1d4 | 2013-10-24 16:52:00 -0700 | [diff] [blame] | 338 | grab->shsurf->grabbed = 0; |
| 339 | } |
Ander Conselvan de Oliveira | b9d2a0f | 2012-06-28 18:08:05 +0300 | [diff] [blame] | 340 | |
Kristian Høgsberg | 9e5d7d1 | 2013-07-22 16:31:53 -0700 | [diff] [blame] | 341 | weston_pointer_end_grab(grab->grab.pointer); |
Ander Conselvan de Oliveira | fe0444a | 2012-04-04 17:48:05 +0300 | [diff] [blame] | 342 | } |
| 343 | |
| 344 | static void |
Rusty Lynch | 1084da5 | 2013-08-15 09:10:08 -0700 | [diff] [blame] | 345 | shell_touch_grab_start(struct shell_touch_grab *grab, |
| 346 | const struct weston_touch_grab_interface *interface, |
| 347 | struct shell_surface *shsurf, |
| 348 | struct weston_touch *touch) |
| 349 | { |
| 350 | struct desktop_shell *shell = shsurf->shell; |
| 351 | |
| 352 | grab->grab.interface = interface; |
| 353 | grab->shsurf = shsurf; |
| 354 | grab->shsurf_destroy_listener.notify = destroy_shell_grab_shsurf; |
| 355 | wl_signal_add(&shsurf->destroy_signal, |
| 356 | &grab->shsurf_destroy_listener); |
| 357 | |
| 358 | grab->touch = touch; |
Kristian Høgsberg | c85f1d4 | 2013-10-24 16:52:00 -0700 | [diff] [blame] | 359 | shsurf->grabbed = 1; |
Rusty Lynch | 1084da5 | 2013-08-15 09:10:08 -0700 | [diff] [blame] | 360 | |
| 361 | weston_touch_start_grab(touch, &grab->grab); |
| 362 | if (shell->child.desktop_shell) |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 363 | weston_touch_set_focus(touch->seat, |
| 364 | get_default_view(shell->grab_surface)); |
Rusty Lynch | 1084da5 | 2013-08-15 09:10:08 -0700 | [diff] [blame] | 365 | } |
| 366 | |
| 367 | static void |
| 368 | shell_touch_grab_end(struct shell_touch_grab *grab) |
| 369 | { |
Kristian Høgsberg | c85f1d4 | 2013-10-24 16:52:00 -0700 | [diff] [blame] | 370 | if (grab->shsurf) { |
Rusty Lynch | 1084da5 | 2013-08-15 09:10:08 -0700 | [diff] [blame] | 371 | wl_list_remove(&grab->shsurf_destroy_listener.link); |
Kristian Høgsberg | c85f1d4 | 2013-10-24 16:52:00 -0700 | [diff] [blame] | 372 | grab->shsurf->grabbed = 0; |
| 373 | } |
Rusty Lynch | 1084da5 | 2013-08-15 09:10:08 -0700 | [diff] [blame] | 374 | |
| 375 | weston_touch_end_grab(grab->touch); |
| 376 | } |
| 377 | |
| 378 | static void |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 379 | center_on_output(struct weston_view *view, |
Alex Wu | 4539b08 | 2012-03-01 12:57:46 +0800 | [diff] [blame] | 380 | struct weston_output *output); |
| 381 | |
Daniel Stone | 496ca17 | 2012-05-30 16:31:42 +0100 | [diff] [blame] | 382 | static enum weston_keyboard_modifier |
Tiago Vignatti | 0b52d48 | 2012-04-20 18:54:25 +0300 | [diff] [blame] | 383 | get_modifier(char *modifier) |
| 384 | { |
| 385 | if (!modifier) |
| 386 | return MODIFIER_SUPER; |
| 387 | |
| 388 | if (!strcmp("ctrl", modifier)) |
| 389 | return MODIFIER_CTRL; |
| 390 | else if (!strcmp("alt", modifier)) |
| 391 | return MODIFIER_ALT; |
| 392 | else if (!strcmp("super", modifier)) |
| 393 | return MODIFIER_SUPER; |
| 394 | else |
| 395 | return MODIFIER_SUPER; |
| 396 | } |
| 397 | |
Juan Zhao | e10d279 | 2012-04-25 19:09:52 +0800 | [diff] [blame] | 398 | static enum animation_type |
| 399 | get_animation_type(char *animation) |
| 400 | { |
Juan Zhao | e10d279 | 2012-04-25 19:09:52 +0800 | [diff] [blame] | 401 | if (!strcmp("zoom", animation)) |
| 402 | return ANIMATION_ZOOM; |
| 403 | else if (!strcmp("fade", animation)) |
| 404 | return ANIMATION_FADE; |
Louis-Francis Ratté-Boulianne | b482dbd | 2013-11-19 11:37:11 +0100 | [diff] [blame] | 405 | else if (!strcmp("dim-layer", animation)) |
| 406 | return ANIMATION_DIM_LAYER; |
Juan Zhao | e10d279 | 2012-04-25 19:09:52 +0800 | [diff] [blame] | 407 | else |
| 408 | return ANIMATION_NONE; |
| 409 | } |
| 410 | |
Alex Wu | 4539b08 | 2012-03-01 12:57:46 +0800 | [diff] [blame] | 411 | static void |
Kristian Høgsberg | 14e438c | 2013-05-26 21:48:14 -0400 | [diff] [blame] | 412 | shell_configuration(struct desktop_shell *shell) |
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 | struct weston_config_section *section; |
| 415 | int duration; |
| 416 | char *s; |
Pekka Paalanen | e955f1e | 2011-12-07 11:49:52 +0200 | [diff] [blame] | 417 | |
Kristian Høgsberg | 673a889 | 2013-05-23 21:40:56 -0400 | [diff] [blame] | 418 | section = weston_config_get_section(shell->compositor->config, |
| 419 | "screensaver", NULL, NULL); |
| 420 | weston_config_section_get_string(section, |
| 421 | "path", &shell->screensaver.path, NULL); |
| 422 | weston_config_section_get_int(section, "duration", &duration, 60); |
Ander Conselvan de Oliveira | 859e885 | 2013-02-21 18:35:21 +0200 | [diff] [blame] | 423 | shell->screensaver.duration = duration * 1000; |
Kristian Høgsberg | 673a889 | 2013-05-23 21:40:56 -0400 | [diff] [blame] | 424 | |
| 425 | section = weston_config_get_section(shell->compositor->config, |
| 426 | "shell", NULL, NULL); |
| 427 | weston_config_section_get_string(section, |
Emilio Pozuelo Monfort | 8a81b83 | 2013-12-02 12:53:32 +0100 | [diff] [blame] | 428 | "client", &s, LIBEXECDIR "/" WESTON_SHELL_CLIENT); |
Emilio Pozuelo Monfort | 46ce798 | 2013-11-20 13:22:29 +0100 | [diff] [blame] | 429 | shell->client = s; |
| 430 | weston_config_section_get_string(section, |
Kristian Høgsberg | 673a889 | 2013-05-23 21:40:56 -0400 | [diff] [blame] | 431 | "binding-modifier", &s, "super"); |
| 432 | shell->binding_modifier = get_modifier(s); |
Quentin Glidic | 8418c29 | 2013-06-18 09:11:03 +0200 | [diff] [blame] | 433 | free(s); |
Kristian Høgsberg | 673a889 | 2013-05-23 21:40:56 -0400 | [diff] [blame] | 434 | weston_config_section_get_string(section, "animation", &s, "none"); |
| 435 | shell->win_animation_type = get_animation_type(s); |
Quentin Glidic | 8418c29 | 2013-06-18 09:11:03 +0200 | [diff] [blame] | 436 | free(s); |
Kristian Høgsberg | 724c8d9 | 2013-10-16 11:38:24 -0700 | [diff] [blame] | 437 | weston_config_section_get_string(section, |
| 438 | "startup-animation", &s, "fade"); |
| 439 | shell->startup_animation_type = get_animation_type(s); |
| 440 | free(s); |
Kristian Høgsberg | 912e0a1 | 2013-10-30 08:59:55 -0700 | [diff] [blame] | 441 | if (shell->startup_animation_type == ANIMATION_ZOOM) |
| 442 | shell->startup_animation_type = ANIMATION_NONE; |
Louis-Francis Ratté-Boulianne | b482dbd | 2013-11-19 11:37:11 +0100 | [diff] [blame] | 443 | weston_config_section_get_string(section, "focus-animation", &s, "none"); |
| 444 | shell->focus_animation_type = get_animation_type(s); |
| 445 | free(s); |
Kristian Høgsberg | 673a889 | 2013-05-23 21:40:56 -0400 | [diff] [blame] | 446 | weston_config_section_get_uint(section, "num-workspaces", |
| 447 | &shell->workspaces.num, |
| 448 | DEFAULT_NUM_WORKSPACES); |
Jonas Ådahl | e3cddce | 2012-06-13 00:01:22 +0200 | [diff] [blame] | 449 | } |
| 450 | |
Kristian Høgsberg | 1ef2313 | 2013-12-04 00:20:01 -0800 | [diff] [blame] | 451 | struct weston_output * |
Louis-Francis Ratté-Boulianne | b482dbd | 2013-11-19 11:37:11 +0100 | [diff] [blame] | 452 | get_default_output(struct weston_compositor *compositor) |
| 453 | { |
| 454 | return container_of(compositor->output_list.next, |
| 455 | struct weston_output, link); |
| 456 | } |
| 457 | |
| 458 | |
| 459 | /* no-op func for checking focus surface */ |
| 460 | static void |
Jason Ekstrand | 918f2dd | 2013-12-02 21:01:53 -0600 | [diff] [blame] | 461 | 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] | 462 | { |
| 463 | } |
| 464 | |
| 465 | static struct focus_surface * |
| 466 | get_focus_surface(struct weston_surface *surface) |
| 467 | { |
| 468 | if (surface->configure == focus_surface_configure) |
| 469 | return surface->configure_private; |
| 470 | else |
| 471 | return NULL; |
| 472 | } |
| 473 | |
| 474 | static bool |
| 475 | is_focus_surface (struct weston_surface *es) |
| 476 | { |
| 477 | return (es->configure == focus_surface_configure); |
| 478 | } |
| 479 | |
| 480 | static bool |
| 481 | is_focus_view (struct weston_view *view) |
| 482 | { |
| 483 | return is_focus_surface (view->surface); |
| 484 | } |
| 485 | |
| 486 | static struct focus_surface * |
| 487 | create_focus_surface(struct weston_compositor *ec, |
| 488 | struct weston_output *output) |
| 489 | { |
| 490 | struct focus_surface *fsurf = NULL; |
| 491 | struct weston_surface *surface = NULL; |
| 492 | |
| 493 | fsurf = malloc(sizeof *fsurf); |
| 494 | if (!fsurf) |
| 495 | return NULL; |
| 496 | |
| 497 | fsurf->surface = weston_surface_create(ec); |
| 498 | surface = fsurf->surface; |
| 499 | if (surface == NULL) { |
| 500 | free(fsurf); |
| 501 | return NULL; |
| 502 | } |
| 503 | |
| 504 | surface->configure = focus_surface_configure; |
| 505 | surface->output = output; |
| 506 | surface->configure_private = fsurf; |
| 507 | |
| 508 | fsurf->view = weston_view_create (surface); |
Emilio Pozuelo Monfort | da64426 | 2013-11-19 11:37:19 +0100 | [diff] [blame] | 509 | fsurf->view->output = output; |
Louis-Francis Ratté-Boulianne | b482dbd | 2013-11-19 11:37:11 +0100 | [diff] [blame] | 510 | |
Jason Ekstrand | 918f2dd | 2013-12-02 21:01:53 -0600 | [diff] [blame] | 511 | surface->width = output->width; |
| 512 | surface->height = output->height; |
| 513 | weston_view_set_position(fsurf->view, output->x, output->y); |
Louis-Francis Ratté-Boulianne | b482dbd | 2013-11-19 11:37:11 +0100 | [diff] [blame] | 514 | weston_surface_set_color(surface, 0.0, 0.0, 0.0, 1.0); |
| 515 | pixman_region32_fini(&surface->opaque); |
| 516 | pixman_region32_init_rect(&surface->opaque, output->x, output->y, |
| 517 | output->width, output->height); |
| 518 | pixman_region32_fini(&surface->input); |
| 519 | pixman_region32_init(&surface->input); |
| 520 | |
| 521 | wl_list_init(&fsurf->workspace_transform.link); |
| 522 | |
| 523 | return fsurf; |
| 524 | } |
| 525 | |
| 526 | static void |
| 527 | focus_surface_destroy(struct focus_surface *fsurf) |
| 528 | { |
| 529 | weston_surface_destroy(fsurf->surface); |
| 530 | free(fsurf); |
| 531 | } |
| 532 | |
| 533 | static void |
| 534 | focus_animation_done(struct weston_view_animation *animation, void *data) |
| 535 | { |
| 536 | struct workspace *ws = data; |
| 537 | |
| 538 | ws->focus_animation = NULL; |
| 539 | } |
| 540 | |
Jonas Ådahl | e3cddce | 2012-06-13 00:01:22 +0200 | [diff] [blame] | 541 | static void |
Jonas Ådahl | 0476974 | 2012-06-13 00:01:24 +0200 | [diff] [blame] | 542 | focus_state_destroy(struct focus_state *state) |
| 543 | { |
| 544 | wl_list_remove(&state->seat_destroy_listener.link); |
| 545 | wl_list_remove(&state->surface_destroy_listener.link); |
| 546 | free(state); |
| 547 | } |
| 548 | |
| 549 | static void |
| 550 | focus_state_seat_destroy(struct wl_listener *listener, void *data) |
| 551 | { |
| 552 | struct focus_state *state = container_of(listener, |
| 553 | struct focus_state, |
| 554 | seat_destroy_listener); |
| 555 | |
| 556 | wl_list_remove(&state->link); |
| 557 | focus_state_destroy(state); |
| 558 | } |
| 559 | |
| 560 | static void |
| 561 | focus_state_surface_destroy(struct wl_listener *listener, void *data) |
| 562 | { |
| 563 | struct focus_state *state = container_of(listener, |
| 564 | struct focus_state, |
Kristian Høgsberg | b8e0d0f | 2012-07-31 10:30:26 -0400 | [diff] [blame] | 565 | surface_destroy_listener); |
Kristian Høgsberg | e377822 | 2012-07-31 17:29:30 -0400 | [diff] [blame] | 566 | struct desktop_shell *shell; |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 567 | struct weston_surface *main_surface, *next; |
| 568 | struct weston_view *view; |
Jonas Ådahl | 0476974 | 2012-06-13 00:01:24 +0200 | [diff] [blame] | 569 | |
Pekka Paalanen | 01388e2 | 2013-04-25 13:57:44 +0300 | [diff] [blame] | 570 | main_surface = weston_surface_get_main_surface(state->keyboard_focus); |
| 571 | |
Kristian Høgsberg | e377822 | 2012-07-31 17:29:30 -0400 | [diff] [blame] | 572 | next = NULL; |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 573 | wl_list_for_each(view, &state->ws->layer.view_list, layer_link) { |
| 574 | if (view->surface == main_surface) |
Kristian Høgsberg | e377822 | 2012-07-31 17:29:30 -0400 | [diff] [blame] | 575 | continue; |
Louis-Francis Ratté-Boulianne | b482dbd | 2013-11-19 11:37:11 +0100 | [diff] [blame] | 576 | if (is_focus_view(view)) |
| 577 | continue; |
Kristian Høgsberg | e377822 | 2012-07-31 17:29:30 -0400 | [diff] [blame] | 578 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 579 | next = view->surface; |
Kristian Høgsberg | e377822 | 2012-07-31 17:29:30 -0400 | [diff] [blame] | 580 | break; |
| 581 | } |
| 582 | |
Pekka Paalanen | 01388e2 | 2013-04-25 13:57:44 +0300 | [diff] [blame] | 583 | /* if the focus was a sub-surface, activate its main surface */ |
| 584 | if (main_surface != state->keyboard_focus) |
| 585 | next = main_surface; |
| 586 | |
Louis-Francis Ratté-Boulianne | b482dbd | 2013-11-19 11:37:11 +0100 | [diff] [blame] | 587 | shell = state->seat->compositor->shell_interface.shell; |
Kristian Høgsberg | e377822 | 2012-07-31 17:29:30 -0400 | [diff] [blame] | 588 | if (next) { |
Louis-Francis Ratté-Boulianne | b482dbd | 2013-11-19 11:37:11 +0100 | [diff] [blame] | 589 | state->keyboard_focus = NULL; |
Kristian Høgsberg | e377822 | 2012-07-31 17:29:30 -0400 | [diff] [blame] | 590 | activate(shell, next, state->seat); |
| 591 | } else { |
Louis-Francis Ratté-Boulianne | b482dbd | 2013-11-19 11:37:11 +0100 | [diff] [blame] | 592 | if (shell->focus_animation_type == ANIMATION_DIM_LAYER) { |
| 593 | if (state->ws->focus_animation) |
| 594 | weston_view_animation_destroy(state->ws->focus_animation); |
| 595 | |
| 596 | state->ws->focus_animation = weston_fade_run( |
| 597 | state->ws->fsurf_front->view, |
| 598 | state->ws->fsurf_front->view->alpha, 0.0, 300, |
| 599 | focus_animation_done, state->ws); |
| 600 | } |
| 601 | |
Kristian Høgsberg | e377822 | 2012-07-31 17:29:30 -0400 | [diff] [blame] | 602 | wl_list_remove(&state->link); |
| 603 | focus_state_destroy(state); |
| 604 | } |
Jonas Ådahl | 0476974 | 2012-06-13 00:01:24 +0200 | [diff] [blame] | 605 | } |
| 606 | |
| 607 | static struct focus_state * |
Kristian Høgsberg | 2f5faff | 2012-07-31 16:36:34 -0400 | [diff] [blame] | 608 | focus_state_create(struct weston_seat *seat, struct workspace *ws) |
Jonas Ådahl | 0476974 | 2012-06-13 00:01:24 +0200 | [diff] [blame] | 609 | { |
Jonas Ådahl | 0476974 | 2012-06-13 00:01:24 +0200 | [diff] [blame] | 610 | struct focus_state *state; |
Jonas Ådahl | 0476974 | 2012-06-13 00:01:24 +0200 | [diff] [blame] | 611 | |
| 612 | state = malloc(sizeof *state); |
| 613 | if (state == NULL) |
| 614 | return NULL; |
| 615 | |
Louis-Francis Ratté-Boulianne | b482dbd | 2013-11-19 11:37:11 +0100 | [diff] [blame] | 616 | state->keyboard_focus = NULL; |
Kristian Høgsberg | 2f5faff | 2012-07-31 16:36:34 -0400 | [diff] [blame] | 617 | state->ws = ws; |
Jonas Ådahl | 0476974 | 2012-06-13 00:01:24 +0200 | [diff] [blame] | 618 | state->seat = seat; |
Kristian Høgsberg | 2f5faff | 2012-07-31 16:36:34 -0400 | [diff] [blame] | 619 | wl_list_insert(&ws->focus_list, &state->link); |
Jonas Ådahl | 0476974 | 2012-06-13 00:01:24 +0200 | [diff] [blame] | 620 | |
| 621 | state->seat_destroy_listener.notify = focus_state_seat_destroy; |
| 622 | state->surface_destroy_listener.notify = focus_state_surface_destroy; |
Kristian Høgsberg | 4912454 | 2013-05-06 22:27:40 -0400 | [diff] [blame] | 623 | wl_signal_add(&seat->destroy_signal, |
Jonas Ådahl | 0476974 | 2012-06-13 00:01:24 +0200 | [diff] [blame] | 624 | &state->seat_destroy_listener); |
Kristian Høgsberg | 2f5faff | 2012-07-31 16:36:34 -0400 | [diff] [blame] | 625 | wl_list_init(&state->surface_destroy_listener.link); |
Jonas Ådahl | 0476974 | 2012-06-13 00:01:24 +0200 | [diff] [blame] | 626 | |
| 627 | return state; |
| 628 | } |
| 629 | |
Jonas Ådahl | 8538b22 | 2012-08-29 22:13:03 +0200 | [diff] [blame] | 630 | static struct focus_state * |
| 631 | ensure_focus_state(struct desktop_shell *shell, struct weston_seat *seat) |
| 632 | { |
| 633 | struct workspace *ws = get_current_workspace(shell); |
| 634 | struct focus_state *state; |
| 635 | |
| 636 | wl_list_for_each(state, &ws->focus_list, link) |
| 637 | if (state->seat == seat) |
| 638 | break; |
| 639 | |
| 640 | if (&state->link == &ws->focus_list) |
| 641 | state = focus_state_create(seat, ws); |
| 642 | |
| 643 | return state; |
| 644 | } |
| 645 | |
Jonas Ådahl | 0476974 | 2012-06-13 00:01:24 +0200 | [diff] [blame] | 646 | static void |
Kristian Høgsberg | 2f5faff | 2012-07-31 16:36:34 -0400 | [diff] [blame] | 647 | restore_focus_state(struct desktop_shell *shell, struct workspace *ws) |
Jonas Ådahl | 0476974 | 2012-06-13 00:01:24 +0200 | [diff] [blame] | 648 | { |
| 649 | struct focus_state *state, *next; |
Kristian Høgsberg | fe7aa90 | 2013-05-08 09:54:37 -0400 | [diff] [blame] | 650 | struct weston_surface *surface; |
Jonas Ådahl | 0476974 | 2012-06-13 00:01:24 +0200 | [diff] [blame] | 651 | |
| 652 | wl_list_for_each_safe(state, next, &ws->focus_list, link) { |
Kristian Høgsberg | fe7aa90 | 2013-05-08 09:54:37 -0400 | [diff] [blame] | 653 | surface = state->keyboard_focus; |
Jonas Ådahl | 5689944 | 2012-08-29 22:12:59 +0200 | [diff] [blame] | 654 | |
Kristian Høgsberg | e314875 | 2013-05-06 23:19:49 -0400 | [diff] [blame] | 655 | weston_keyboard_set_focus(state->seat->keyboard, surface); |
Jonas Ådahl | 0476974 | 2012-06-13 00:01:24 +0200 | [diff] [blame] | 656 | } |
| 657 | } |
| 658 | |
| 659 | static void |
Jonas Ådahl | 8de6a1d | 2012-08-29 22:13:00 +0200 | [diff] [blame] | 660 | replace_focus_state(struct desktop_shell *shell, struct workspace *ws, |
| 661 | struct weston_seat *seat) |
| 662 | { |
| 663 | struct focus_state *state; |
Kristian Høgsberg | fe7aa90 | 2013-05-08 09:54:37 -0400 | [diff] [blame] | 664 | struct weston_surface *surface; |
Jonas Ådahl | 8de6a1d | 2012-08-29 22:13:00 +0200 | [diff] [blame] | 665 | |
| 666 | wl_list_for_each(state, &ws->focus_list, link) { |
| 667 | if (state->seat == seat) { |
Kristian Høgsberg | e314875 | 2013-05-06 23:19:49 -0400 | [diff] [blame] | 668 | surface = seat->keyboard->focus; |
Jason Ekstrand | 651f00e | 2013-06-14 10:07:54 -0500 | [diff] [blame] | 669 | state->keyboard_focus = surface; |
Jonas Ådahl | 8de6a1d | 2012-08-29 22:13:00 +0200 | [diff] [blame] | 670 | return; |
| 671 | } |
| 672 | } |
| 673 | } |
| 674 | |
| 675 | static void |
| 676 | drop_focus_state(struct desktop_shell *shell, struct workspace *ws, |
| 677 | struct weston_surface *surface) |
| 678 | { |
| 679 | struct focus_state *state; |
| 680 | |
| 681 | wl_list_for_each(state, &ws->focus_list, link) |
| 682 | if (state->keyboard_focus == surface) |
| 683 | state->keyboard_focus = NULL; |
| 684 | } |
| 685 | |
| 686 | static void |
Louis-Francis Ratté-Boulianne | b482dbd | 2013-11-19 11:37:11 +0100 | [diff] [blame] | 687 | animate_focus_change(struct desktop_shell *shell, struct workspace *ws, |
| 688 | struct weston_view *from, struct weston_view *to) |
| 689 | { |
| 690 | struct weston_output *output; |
| 691 | bool focus_surface_created = false; |
| 692 | |
| 693 | /* FIXME: Only support dim animation using two layers */ |
| 694 | if (from == to || shell->focus_animation_type != ANIMATION_DIM_LAYER) |
| 695 | return; |
| 696 | |
| 697 | output = get_default_output(shell->compositor); |
| 698 | if (ws->fsurf_front == NULL && (from || to)) { |
| 699 | ws->fsurf_front = create_focus_surface(shell->compositor, output); |
| 700 | ws->fsurf_back = create_focus_surface(shell->compositor, output); |
| 701 | ws->fsurf_front->view->alpha = 0.0; |
| 702 | ws->fsurf_back->view->alpha = 0.0; |
| 703 | focus_surface_created = true; |
| 704 | } else { |
| 705 | wl_list_remove(&ws->fsurf_front->view->layer_link); |
| 706 | wl_list_remove(&ws->fsurf_back->view->layer_link); |
| 707 | } |
| 708 | |
| 709 | if (ws->focus_animation) { |
| 710 | weston_view_animation_destroy(ws->focus_animation); |
| 711 | ws->focus_animation = NULL; |
| 712 | } |
| 713 | |
| 714 | if (to) |
| 715 | wl_list_insert(&to->layer_link, |
| 716 | &ws->fsurf_front->view->layer_link); |
| 717 | else if (from) |
| 718 | wl_list_insert(&ws->layer.view_list, |
| 719 | &ws->fsurf_front->view->layer_link); |
| 720 | |
| 721 | if (focus_surface_created) { |
| 722 | ws->focus_animation = weston_fade_run( |
| 723 | ws->fsurf_front->view, |
| 724 | ws->fsurf_front->view->alpha, 0.6, 300, |
| 725 | focus_animation_done, ws); |
| 726 | } else if (from) { |
| 727 | wl_list_insert(&from->layer_link, |
| 728 | &ws->fsurf_back->view->layer_link); |
| 729 | ws->focus_animation = weston_stable_fade_run( |
| 730 | ws->fsurf_front->view, 0.0, |
| 731 | ws->fsurf_back->view, 0.6, |
| 732 | focus_animation_done, ws); |
| 733 | } else if (to) { |
| 734 | wl_list_insert(&ws->layer.view_list, |
| 735 | &ws->fsurf_back->view->layer_link); |
| 736 | ws->focus_animation = weston_stable_fade_run( |
| 737 | ws->fsurf_front->view, 0.0, |
| 738 | ws->fsurf_back->view, 0.6, |
| 739 | focus_animation_done, ws); |
| 740 | } |
| 741 | } |
| 742 | |
| 743 | static void |
Jonas Ådahl | e3cddce | 2012-06-13 00:01:22 +0200 | [diff] [blame] | 744 | workspace_destroy(struct workspace *ws) |
| 745 | { |
Jonas Ådahl | 0476974 | 2012-06-13 00:01:24 +0200 | [diff] [blame] | 746 | struct focus_state *state, *next; |
| 747 | |
| 748 | wl_list_for_each_safe(state, next, &ws->focus_list, link) |
| 749 | focus_state_destroy(state); |
| 750 | |
Louis-Francis Ratté-Boulianne | b482dbd | 2013-11-19 11:37:11 +0100 | [diff] [blame] | 751 | if (ws->fsurf_front) |
| 752 | focus_surface_destroy(ws->fsurf_front); |
| 753 | if (ws->fsurf_back) |
| 754 | focus_surface_destroy(ws->fsurf_back); |
| 755 | |
Jonas Ådahl | e3cddce | 2012-06-13 00:01:22 +0200 | [diff] [blame] | 756 | free(ws); |
| 757 | } |
| 758 | |
Jonas Ådahl | 0476974 | 2012-06-13 00:01:24 +0200 | [diff] [blame] | 759 | static void |
| 760 | seat_destroyed(struct wl_listener *listener, void *data) |
| 761 | { |
| 762 | struct weston_seat *seat = data; |
| 763 | struct focus_state *state, *next; |
| 764 | struct workspace *ws = container_of(listener, |
| 765 | struct workspace, |
| 766 | seat_destroyed_listener); |
| 767 | |
| 768 | wl_list_for_each_safe(state, next, &ws->focus_list, link) |
| 769 | if (state->seat == seat) |
| 770 | wl_list_remove(&state->link); |
| 771 | } |
| 772 | |
Jonas Ådahl | e3cddce | 2012-06-13 00:01:22 +0200 | [diff] [blame] | 773 | static struct workspace * |
| 774 | workspace_create(void) |
| 775 | { |
| 776 | struct workspace *ws = malloc(sizeof *ws); |
| 777 | if (ws == NULL) |
| 778 | return NULL; |
| 779 | |
| 780 | weston_layer_init(&ws->layer, NULL); |
| 781 | |
Jonas Ådahl | 0476974 | 2012-06-13 00:01:24 +0200 | [diff] [blame] | 782 | wl_list_init(&ws->focus_list); |
| 783 | wl_list_init(&ws->seat_destroyed_listener.link); |
| 784 | ws->seat_destroyed_listener.notify = seat_destroyed; |
Louis-Francis Ratté-Boulianne | b482dbd | 2013-11-19 11:37:11 +0100 | [diff] [blame] | 785 | ws->fsurf_front = NULL; |
| 786 | ws->fsurf_back = NULL; |
| 787 | ws->focus_animation = NULL; |
Jonas Ådahl | 0476974 | 2012-06-13 00:01:24 +0200 | [diff] [blame] | 788 | |
Jonas Ådahl | e3cddce | 2012-06-13 00:01:22 +0200 | [diff] [blame] | 789 | return ws; |
| 790 | } |
| 791 | |
Jonas Ådahl | 62fcd04 | 2012-06-13 00:01:23 +0200 | [diff] [blame] | 792 | static int |
| 793 | workspace_is_empty(struct workspace *ws) |
| 794 | { |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 795 | return wl_list_empty(&ws->layer.view_list); |
Jonas Ådahl | 62fcd04 | 2012-06-13 00:01:23 +0200 | [diff] [blame] | 796 | } |
| 797 | |
Jonas Ådahl | e3cddce | 2012-06-13 00:01:22 +0200 | [diff] [blame] | 798 | static struct workspace * |
| 799 | get_workspace(struct desktop_shell *shell, unsigned int index) |
| 800 | { |
| 801 | struct workspace **pws = shell->workspaces.array.data; |
Philipp Brüschweiler | 067abf6 | 2012-09-01 16:03:05 +0200 | [diff] [blame] | 802 | assert(index < shell->workspaces.num); |
Jonas Ådahl | e3cddce | 2012-06-13 00:01:22 +0200 | [diff] [blame] | 803 | pws += index; |
| 804 | return *pws; |
| 805 | } |
| 806 | |
Kristian Høgsberg | 1ef2313 | 2013-12-04 00:20:01 -0800 | [diff] [blame] | 807 | struct workspace * |
Jonas Ådahl | e3cddce | 2012-06-13 00:01:22 +0200 | [diff] [blame] | 808 | get_current_workspace(struct desktop_shell *shell) |
| 809 | { |
| 810 | return get_workspace(shell, shell->workspaces.current); |
| 811 | } |
| 812 | |
| 813 | static void |
| 814 | activate_workspace(struct desktop_shell *shell, unsigned int index) |
| 815 | { |
| 816 | struct workspace *ws; |
| 817 | |
| 818 | ws = get_workspace(shell, index); |
| 819 | wl_list_insert(&shell->panel_layer.link, &ws->layer.link); |
| 820 | |
| 821 | shell->workspaces.current = index; |
| 822 | } |
| 823 | |
Jonas Ådahl | 62fcd04 | 2012-06-13 00:01:23 +0200 | [diff] [blame] | 824 | static unsigned int |
| 825 | get_output_height(struct weston_output *output) |
| 826 | { |
| 827 | return abs(output->region.extents.y1 - output->region.extents.y2); |
| 828 | } |
| 829 | |
| 830 | static void |
Louis-Francis Ratté-Boulianne | b482dbd | 2013-11-19 11:37:11 +0100 | [diff] [blame] | 831 | view_translate(struct workspace *ws, struct weston_view *view, double d) |
Jonas Ådahl | 62fcd04 | 2012-06-13 00:01:23 +0200 | [diff] [blame] | 832 | { |
Jonas Ådahl | 62fcd04 | 2012-06-13 00:01:23 +0200 | [diff] [blame] | 833 | struct weston_transform *transform; |
| 834 | |
Louis-Francis Ratté-Boulianne | b482dbd | 2013-11-19 11:37:11 +0100 | [diff] [blame] | 835 | if (is_focus_view(view)) { |
| 836 | struct focus_surface *fsurf = get_focus_surface(view->surface); |
| 837 | transform = &fsurf->workspace_transform; |
| 838 | } else { |
| 839 | struct shell_surface *shsurf = get_shell_surface(view->surface); |
| 840 | transform = &shsurf->workspace_transform; |
| 841 | } |
| 842 | |
Jonas Ådahl | 62fcd04 | 2012-06-13 00:01:23 +0200 | [diff] [blame] | 843 | if (wl_list_empty(&transform->link)) |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 844 | wl_list_insert(view->geometry.transformation_list.prev, |
Louis-Francis Ratté-Boulianne | b482dbd | 2013-11-19 11:37:11 +0100 | [diff] [blame] | 845 | &transform->link); |
Jonas Ådahl | 62fcd04 | 2012-06-13 00:01:23 +0200 | [diff] [blame] | 846 | |
Louis-Francis Ratté-Boulianne | b482dbd | 2013-11-19 11:37:11 +0100 | [diff] [blame] | 847 | weston_matrix_init(&transform->matrix); |
| 848 | weston_matrix_translate(&transform->matrix, |
Jonas Ådahl | 62fcd04 | 2012-06-13 00:01:23 +0200 | [diff] [blame] | 849 | 0.0, d, 0.0); |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 850 | weston_view_geometry_dirty(view); |
Jonas Ådahl | 62fcd04 | 2012-06-13 00:01:23 +0200 | [diff] [blame] | 851 | } |
| 852 | |
| 853 | static void |
| 854 | workspace_translate_out(struct workspace *ws, double fraction) |
| 855 | { |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 856 | struct weston_view *view; |
Jonas Ådahl | 62fcd04 | 2012-06-13 00:01:23 +0200 | [diff] [blame] | 857 | unsigned int height; |
| 858 | double d; |
| 859 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 860 | wl_list_for_each(view, &ws->layer.view_list, layer_link) { |
| 861 | height = get_output_height(view->surface->output); |
Jonas Ådahl | 62fcd04 | 2012-06-13 00:01:23 +0200 | [diff] [blame] | 862 | d = height * fraction; |
| 863 | |
Louis-Francis Ratté-Boulianne | b482dbd | 2013-11-19 11:37:11 +0100 | [diff] [blame] | 864 | view_translate(ws, view, d); |
Jonas Ådahl | 62fcd04 | 2012-06-13 00:01:23 +0200 | [diff] [blame] | 865 | } |
| 866 | } |
| 867 | |
| 868 | static void |
| 869 | workspace_translate_in(struct workspace *ws, double fraction) |
| 870 | { |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 871 | struct weston_view *view; |
Jonas Ådahl | 62fcd04 | 2012-06-13 00:01:23 +0200 | [diff] [blame] | 872 | unsigned int height; |
| 873 | double d; |
| 874 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 875 | wl_list_for_each(view, &ws->layer.view_list, layer_link) { |
| 876 | height = get_output_height(view->surface->output); |
Jonas Ådahl | 62fcd04 | 2012-06-13 00:01:23 +0200 | [diff] [blame] | 877 | |
| 878 | if (fraction > 0) |
| 879 | d = -(height - height * fraction); |
| 880 | else |
| 881 | d = height + height * fraction; |
| 882 | |
Louis-Francis Ratté-Boulianne | b482dbd | 2013-11-19 11:37:11 +0100 | [diff] [blame] | 883 | view_translate(ws, view, d); |
Jonas Ådahl | 62fcd04 | 2012-06-13 00:01:23 +0200 | [diff] [blame] | 884 | } |
| 885 | } |
| 886 | |
| 887 | static void |
Jonas Ådahl | e9d2250 | 2012-08-29 22:13:01 +0200 | [diff] [blame] | 888 | broadcast_current_workspace_state(struct desktop_shell *shell) |
| 889 | { |
Kristian Høgsberg | 2e3c396 | 2013-09-11 12:00:47 -0700 | [diff] [blame] | 890 | struct wl_resource *resource; |
Jonas Ådahl | e9d2250 | 2012-08-29 22:13:01 +0200 | [diff] [blame] | 891 | |
Kristian Høgsberg | 2e3c396 | 2013-09-11 12:00:47 -0700 | [diff] [blame] | 892 | wl_resource_for_each(resource, &shell->workspaces.client_list) |
| 893 | workspace_manager_send_state(resource, |
Jonas Ådahl | e9d2250 | 2012-08-29 22:13:01 +0200 | [diff] [blame] | 894 | shell->workspaces.current, |
| 895 | shell->workspaces.num); |
| 896 | } |
| 897 | |
| 898 | static void |
Jonas Ådahl | 62fcd04 | 2012-06-13 00:01:23 +0200 | [diff] [blame] | 899 | reverse_workspace_change_animation(struct desktop_shell *shell, |
| 900 | unsigned int index, |
| 901 | struct workspace *from, |
| 902 | struct workspace *to) |
| 903 | { |
| 904 | shell->workspaces.current = index; |
| 905 | |
| 906 | shell->workspaces.anim_to = to; |
| 907 | shell->workspaces.anim_from = from; |
| 908 | shell->workspaces.anim_dir = -1 * shell->workspaces.anim_dir; |
| 909 | shell->workspaces.anim_timestamp = 0; |
| 910 | |
Scott Moreau | 4272e63 | 2012-08-13 09:58:41 -0600 | [diff] [blame] | 911 | weston_compositor_schedule_repaint(shell->compositor); |
Jonas Ådahl | 62fcd04 | 2012-06-13 00:01:23 +0200 | [diff] [blame] | 912 | } |
| 913 | |
| 914 | static void |
| 915 | workspace_deactivate_transforms(struct workspace *ws) |
| 916 | { |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 917 | struct weston_view *view; |
Louis-Francis Ratté-Boulianne | b482dbd | 2013-11-19 11:37:11 +0100 | [diff] [blame] | 918 | struct weston_transform *transform; |
Jonas Ådahl | 62fcd04 | 2012-06-13 00:01:23 +0200 | [diff] [blame] | 919 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 920 | 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] | 921 | if (is_focus_view(view)) { |
| 922 | struct focus_surface *fsurf = get_focus_surface(view->surface); |
| 923 | transform = &fsurf->workspace_transform; |
| 924 | } else { |
| 925 | struct shell_surface *shsurf = get_shell_surface(view->surface); |
| 926 | transform = &shsurf->workspace_transform; |
| 927 | } |
| 928 | |
| 929 | if (!wl_list_empty(&transform->link)) { |
| 930 | wl_list_remove(&transform->link); |
| 931 | wl_list_init(&transform->link); |
Jonas Ådahl | 8de6a1d | 2012-08-29 22:13:00 +0200 | [diff] [blame] | 932 | } |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 933 | weston_view_geometry_dirty(view); |
Jonas Ådahl | 62fcd04 | 2012-06-13 00:01:23 +0200 | [diff] [blame] | 934 | } |
| 935 | } |
| 936 | |
| 937 | static void |
| 938 | finish_workspace_change_animation(struct desktop_shell *shell, |
| 939 | struct workspace *from, |
| 940 | struct workspace *to) |
| 941 | { |
Scott Moreau | 4272e63 | 2012-08-13 09:58:41 -0600 | [diff] [blame] | 942 | weston_compositor_schedule_repaint(shell->compositor); |
Jonas Ådahl | 62fcd04 | 2012-06-13 00:01:23 +0200 | [diff] [blame] | 943 | |
| 944 | wl_list_remove(&shell->workspaces.animation.link); |
| 945 | workspace_deactivate_transforms(from); |
| 946 | workspace_deactivate_transforms(to); |
| 947 | shell->workspaces.anim_to = NULL; |
| 948 | |
| 949 | wl_list_remove(&shell->workspaces.anim_from->layer.link); |
| 950 | } |
| 951 | |
| 952 | static void |
| 953 | animate_workspace_change_frame(struct weston_animation *animation, |
| 954 | struct weston_output *output, uint32_t msecs) |
| 955 | { |
| 956 | struct desktop_shell *shell = |
| 957 | container_of(animation, struct desktop_shell, |
| 958 | workspaces.animation); |
| 959 | struct workspace *from = shell->workspaces.anim_from; |
| 960 | struct workspace *to = shell->workspaces.anim_to; |
| 961 | uint32_t t; |
| 962 | double x, y; |
| 963 | |
| 964 | if (workspace_is_empty(from) && workspace_is_empty(to)) { |
| 965 | finish_workspace_change_animation(shell, from, to); |
| 966 | return; |
| 967 | } |
| 968 | |
| 969 | if (shell->workspaces.anim_timestamp == 0) { |
| 970 | if (shell->workspaces.anim_current == 0.0) |
| 971 | shell->workspaces.anim_timestamp = msecs; |
| 972 | else |
| 973 | shell->workspaces.anim_timestamp = |
| 974 | msecs - |
| 975 | /* Invers of movement function 'y' below. */ |
| 976 | (asin(1.0 - shell->workspaces.anim_current) * |
| 977 | DEFAULT_WORKSPACE_CHANGE_ANIMATION_LENGTH * |
| 978 | M_2_PI); |
| 979 | } |
| 980 | |
| 981 | t = msecs - shell->workspaces.anim_timestamp; |
| 982 | |
| 983 | /* |
| 984 | * x = [0, π/2] |
| 985 | * y(x) = sin(x) |
| 986 | */ |
| 987 | x = t * (1.0/DEFAULT_WORKSPACE_CHANGE_ANIMATION_LENGTH) * M_PI_2; |
| 988 | y = sin(x); |
| 989 | |
| 990 | if (t < DEFAULT_WORKSPACE_CHANGE_ANIMATION_LENGTH) { |
Scott Moreau | 4272e63 | 2012-08-13 09:58:41 -0600 | [diff] [blame] | 991 | weston_compositor_schedule_repaint(shell->compositor); |
Jonas Ådahl | 62fcd04 | 2012-06-13 00:01:23 +0200 | [diff] [blame] | 992 | |
| 993 | workspace_translate_out(from, shell->workspaces.anim_dir * y); |
| 994 | workspace_translate_in(to, shell->workspaces.anim_dir * y); |
| 995 | shell->workspaces.anim_current = y; |
| 996 | |
Scott Moreau | 4272e63 | 2012-08-13 09:58:41 -0600 | [diff] [blame] | 997 | weston_compositor_schedule_repaint(shell->compositor); |
Jonas Ådahl | 62fcd04 | 2012-06-13 00:01:23 +0200 | [diff] [blame] | 998 | } |
Jonas Ådahl | 0476974 | 2012-06-13 00:01:24 +0200 | [diff] [blame] | 999 | else |
Jonas Ådahl | 62fcd04 | 2012-06-13 00:01:23 +0200 | [diff] [blame] | 1000 | finish_workspace_change_animation(shell, from, to); |
Jonas Ådahl | 62fcd04 | 2012-06-13 00:01:23 +0200 | [diff] [blame] | 1001 | } |
| 1002 | |
| 1003 | static void |
| 1004 | animate_workspace_change(struct desktop_shell *shell, |
| 1005 | unsigned int index, |
| 1006 | struct workspace *from, |
| 1007 | struct workspace *to) |
| 1008 | { |
| 1009 | struct weston_output *output; |
| 1010 | |
| 1011 | int dir; |
| 1012 | |
| 1013 | if (index > shell->workspaces.current) |
| 1014 | dir = -1; |
| 1015 | else |
| 1016 | dir = 1; |
| 1017 | |
| 1018 | shell->workspaces.current = index; |
| 1019 | |
| 1020 | shell->workspaces.anim_dir = dir; |
| 1021 | shell->workspaces.anim_from = from; |
| 1022 | shell->workspaces.anim_to = to; |
| 1023 | shell->workspaces.anim_current = 0.0; |
| 1024 | shell->workspaces.anim_timestamp = 0; |
| 1025 | |
| 1026 | output = container_of(shell->compositor->output_list.next, |
| 1027 | struct weston_output, link); |
| 1028 | wl_list_insert(&output->animation_list, |
| 1029 | &shell->workspaces.animation.link); |
| 1030 | |
Jonas Ådahl | 8de6a1d | 2012-08-29 22:13:00 +0200 | [diff] [blame] | 1031 | wl_list_insert(from->layer.link.prev, &to->layer.link); |
Jonas Ådahl | 62fcd04 | 2012-06-13 00:01:23 +0200 | [diff] [blame] | 1032 | |
| 1033 | workspace_translate_in(to, 0); |
| 1034 | |
Kristian Høgsberg | 2f5faff | 2012-07-31 16:36:34 -0400 | [diff] [blame] | 1035 | restore_focus_state(shell, to); |
Jonas Ådahl | 0476974 | 2012-06-13 00:01:24 +0200 | [diff] [blame] | 1036 | |
Scott Moreau | 4272e63 | 2012-08-13 09:58:41 -0600 | [diff] [blame] | 1037 | weston_compositor_schedule_repaint(shell->compositor); |
Jonas Ådahl | 62fcd04 | 2012-06-13 00:01:23 +0200 | [diff] [blame] | 1038 | } |
| 1039 | |
Jonas Ådahl | e3cddce | 2012-06-13 00:01:22 +0200 | [diff] [blame] | 1040 | static void |
Jonas Ådahl | 8de6a1d | 2012-08-29 22:13:00 +0200 | [diff] [blame] | 1041 | update_workspace(struct desktop_shell *shell, unsigned int index, |
| 1042 | struct workspace *from, struct workspace *to) |
| 1043 | { |
| 1044 | shell->workspaces.current = index; |
| 1045 | wl_list_insert(&from->layer.link, &to->layer.link); |
| 1046 | wl_list_remove(&from->layer.link); |
| 1047 | } |
| 1048 | |
| 1049 | static void |
Jonas Ådahl | e3cddce | 2012-06-13 00:01:22 +0200 | [diff] [blame] | 1050 | change_workspace(struct desktop_shell *shell, unsigned int index) |
| 1051 | { |
| 1052 | struct workspace *from; |
| 1053 | struct workspace *to; |
Louis-Francis Ratté-Boulianne | b482dbd | 2013-11-19 11:37:11 +0100 | [diff] [blame] | 1054 | struct focus_state *state; |
Jonas Ådahl | e3cddce | 2012-06-13 00:01:22 +0200 | [diff] [blame] | 1055 | |
| 1056 | if (index == shell->workspaces.current) |
| 1057 | return; |
| 1058 | |
| 1059 | /* Don't change workspace when there is any fullscreen surfaces. */ |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 1060 | if (!wl_list_empty(&shell->fullscreen_layer.view_list)) |
Jonas Ådahl | e3cddce | 2012-06-13 00:01:22 +0200 | [diff] [blame] | 1061 | return; |
| 1062 | |
Jonas Ådahl | e3cddce | 2012-06-13 00:01:22 +0200 | [diff] [blame] | 1063 | from = get_current_workspace(shell); |
| 1064 | to = get_workspace(shell, index); |
| 1065 | |
Jonas Ådahl | 62fcd04 | 2012-06-13 00:01:23 +0200 | [diff] [blame] | 1066 | if (shell->workspaces.anim_from == to && |
| 1067 | shell->workspaces.anim_to == from) { |
Jonas Ådahl | 8de6a1d | 2012-08-29 22:13:00 +0200 | [diff] [blame] | 1068 | restore_focus_state(shell, to); |
Jonas Ådahl | 62fcd04 | 2012-06-13 00:01:23 +0200 | [diff] [blame] | 1069 | reverse_workspace_change_animation(shell, index, from, to); |
Jonas Ådahl | e9d2250 | 2012-08-29 22:13:01 +0200 | [diff] [blame] | 1070 | broadcast_current_workspace_state(shell); |
Jonas Ådahl | 62fcd04 | 2012-06-13 00:01:23 +0200 | [diff] [blame] | 1071 | return; |
| 1072 | } |
Jonas Ådahl | e3cddce | 2012-06-13 00:01:22 +0200 | [diff] [blame] | 1073 | |
Jonas Ådahl | 62fcd04 | 2012-06-13 00:01:23 +0200 | [diff] [blame] | 1074 | if (shell->workspaces.anim_to != NULL) |
| 1075 | finish_workspace_change_animation(shell, |
| 1076 | shell->workspaces.anim_from, |
| 1077 | shell->workspaces.anim_to); |
| 1078 | |
Jonas Ådahl | 8de6a1d | 2012-08-29 22:13:00 +0200 | [diff] [blame] | 1079 | restore_focus_state(shell, to); |
Jonas Ådahl | 0476974 | 2012-06-13 00:01:24 +0200 | [diff] [blame] | 1080 | |
Louis-Francis Ratté-Boulianne | b482dbd | 2013-11-19 11:37:11 +0100 | [diff] [blame] | 1081 | if (shell->focus_animation_type != ANIMATION_NONE) { |
| 1082 | wl_list_for_each(state, &from->focus_list, link) |
| 1083 | if (state->keyboard_focus) |
| 1084 | animate_focus_change(shell, from, |
| 1085 | get_default_view(state->keyboard_focus), NULL); |
| 1086 | |
| 1087 | wl_list_for_each(state, &to->focus_list, link) |
| 1088 | if (state->keyboard_focus) |
| 1089 | animate_focus_change(shell, to, |
| 1090 | NULL, get_default_view(state->keyboard_focus)); |
| 1091 | } |
| 1092 | |
Jonas Ådahl | 8de6a1d | 2012-08-29 22:13:00 +0200 | [diff] [blame] | 1093 | if (workspace_is_empty(to) && workspace_is_empty(from)) |
| 1094 | update_workspace(shell, index, from, to); |
Jonas Ådahl | 62fcd04 | 2012-06-13 00:01:23 +0200 | [diff] [blame] | 1095 | else |
| 1096 | animate_workspace_change(shell, index, from, to); |
Jonas Ådahl | e9d2250 | 2012-08-29 22:13:01 +0200 | [diff] [blame] | 1097 | |
| 1098 | broadcast_current_workspace_state(shell); |
Pekka Paalanen | e955f1e | 2011-12-07 11:49:52 +0200 | [diff] [blame] | 1099 | } |
| 1100 | |
Jonas Ådahl | 8de6a1d | 2012-08-29 22:13:00 +0200 | [diff] [blame] | 1101 | static bool |
| 1102 | workspace_has_only(struct workspace *ws, struct weston_surface *surface) |
| 1103 | { |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 1104 | struct wl_list *list = &ws->layer.view_list; |
Jonas Ådahl | 8de6a1d | 2012-08-29 22:13:00 +0200 | [diff] [blame] | 1105 | struct wl_list *e; |
| 1106 | |
| 1107 | if (wl_list_empty(list)) |
| 1108 | return false; |
| 1109 | |
| 1110 | e = list->next; |
| 1111 | |
| 1112 | if (e->next != list) |
| 1113 | return false; |
| 1114 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 1115 | return container_of(e, struct weston_view, layer_link)->surface == surface; |
Jonas Ådahl | 8de6a1d | 2012-08-29 22:13:00 +0200 | [diff] [blame] | 1116 | } |
| 1117 | |
| 1118 | static void |
Philip Withnall | 659163d | 2013-11-25 18:01:36 +0000 | [diff] [blame] | 1119 | move_surface_to_workspace(struct desktop_shell *shell, |
| 1120 | struct shell_surface *shsurf, |
| 1121 | uint32_t workspace) |
Jonas Ådahl | e9d2250 | 2012-08-29 22:13:01 +0200 | [diff] [blame] | 1122 | { |
| 1123 | struct workspace *from; |
| 1124 | struct workspace *to; |
| 1125 | struct weston_seat *seat; |
Pekka Paalanen | 01388e2 | 2013-04-25 13:57:44 +0300 | [diff] [blame] | 1126 | struct weston_surface *focus; |
Philip Withnall | 659163d | 2013-11-25 18:01:36 +0000 | [diff] [blame] | 1127 | struct weston_view *view; |
Jonas Ådahl | e9d2250 | 2012-08-29 22:13:01 +0200 | [diff] [blame] | 1128 | |
| 1129 | if (workspace == shell->workspaces.current) |
| 1130 | return; |
| 1131 | |
Philip Withnall | 659163d | 2013-11-25 18:01:36 +0000 | [diff] [blame] | 1132 | view = get_default_view(shsurf->surface); |
| 1133 | if (!view) |
| 1134 | return; |
| 1135 | |
| 1136 | assert(weston_surface_get_main_surface(view->surface) == view->surface); |
| 1137 | |
Philipp Brüschweiler | 067abf6 | 2012-09-01 16:03:05 +0200 | [diff] [blame] | 1138 | if (workspace >= shell->workspaces.num) |
| 1139 | workspace = shell->workspaces.num - 1; |
| 1140 | |
Jonas Ådahl | e9d2250 | 2012-08-29 22:13:01 +0200 | [diff] [blame] | 1141 | from = get_current_workspace(shell); |
| 1142 | to = get_workspace(shell, workspace); |
| 1143 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 1144 | wl_list_remove(&view->layer_link); |
| 1145 | wl_list_insert(&to->layer.view_list, &view->layer_link); |
Jonas Ådahl | e9d2250 | 2012-08-29 22:13:01 +0200 | [diff] [blame] | 1146 | |
Philip Withnall | 648a4dd | 2013-11-25 18:01:44 +0000 | [diff] [blame] | 1147 | shell_surface_update_child_surface_layers(shsurf); |
| 1148 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 1149 | drop_focus_state(shell, from, view->surface); |
Pekka Paalanen | 01388e2 | 2013-04-25 13:57:44 +0300 | [diff] [blame] | 1150 | wl_list_for_each(seat, &shell->compositor->seat_list, link) { |
| 1151 | if (!seat->keyboard) |
| 1152 | continue; |
| 1153 | |
| 1154 | focus = weston_surface_get_main_surface(seat->keyboard->focus); |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 1155 | if (focus == view->surface) |
Kristian Høgsberg | e314875 | 2013-05-06 23:19:49 -0400 | [diff] [blame] | 1156 | weston_keyboard_set_focus(seat->keyboard, NULL); |
Pekka Paalanen | 01388e2 | 2013-04-25 13:57:44 +0300 | [diff] [blame] | 1157 | } |
Jonas Ådahl | e9d2250 | 2012-08-29 22:13:01 +0200 | [diff] [blame] | 1158 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 1159 | weston_view_damage_below(view); |
Jonas Ådahl | e9d2250 | 2012-08-29 22:13:01 +0200 | [diff] [blame] | 1160 | } |
| 1161 | |
| 1162 | static void |
Jonas Ådahl | 8de6a1d | 2012-08-29 22:13:00 +0200 | [diff] [blame] | 1163 | take_surface_to_workspace_by_seat(struct desktop_shell *shell, |
Kristian Høgsberg | e314875 | 2013-05-06 23:19:49 -0400 | [diff] [blame] | 1164 | struct weston_seat *seat, |
Jonas Ådahl | 8de6a1d | 2012-08-29 22:13:00 +0200 | [diff] [blame] | 1165 | unsigned int index) |
| 1166 | { |
Pekka Paalanen | 01388e2 | 2013-04-25 13:57:44 +0300 | [diff] [blame] | 1167 | struct weston_surface *surface; |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 1168 | struct weston_view *view; |
Jonas Ådahl | 8de6a1d | 2012-08-29 22:13:00 +0200 | [diff] [blame] | 1169 | struct shell_surface *shsurf; |
| 1170 | struct workspace *from; |
| 1171 | struct workspace *to; |
Jonas Ådahl | 8538b22 | 2012-08-29 22:13:03 +0200 | [diff] [blame] | 1172 | struct focus_state *state; |
Jonas Ådahl | 8de6a1d | 2012-08-29 22:13:00 +0200 | [diff] [blame] | 1173 | |
Pekka Paalanen | 01388e2 | 2013-04-25 13:57:44 +0300 | [diff] [blame] | 1174 | surface = weston_surface_get_main_surface(seat->keyboard->focus); |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 1175 | view = get_default_view(surface); |
| 1176 | if (view == NULL || |
Louis-Francis Ratté-Boulianne | b482dbd | 2013-11-19 11:37:11 +0100 | [diff] [blame] | 1177 | index == shell->workspaces.current || |
| 1178 | is_focus_view(view)) |
Jonas Ådahl | 8de6a1d | 2012-08-29 22:13:00 +0200 | [diff] [blame] | 1179 | return; |
| 1180 | |
| 1181 | from = get_current_workspace(shell); |
| 1182 | to = get_workspace(shell, index); |
| 1183 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 1184 | wl_list_remove(&view->layer_link); |
| 1185 | wl_list_insert(&to->layer.view_list, &view->layer_link); |
Jonas Ådahl | 8de6a1d | 2012-08-29 22:13:00 +0200 | [diff] [blame] | 1186 | |
Philip Withnall | 659163d | 2013-11-25 18:01:36 +0000 | [diff] [blame] | 1187 | shsurf = get_shell_surface(surface); |
Philip Withnall | 648a4dd | 2013-11-25 18:01:44 +0000 | [diff] [blame] | 1188 | if (shsurf != NULL) |
| 1189 | shell_surface_update_child_surface_layers(shsurf); |
Philip Withnall | 659163d | 2013-11-25 18:01:36 +0000 | [diff] [blame] | 1190 | |
Jonas Ådahl | e9d2250 | 2012-08-29 22:13:01 +0200 | [diff] [blame] | 1191 | replace_focus_state(shell, to, seat); |
Jonas Ådahl | 8de6a1d | 2012-08-29 22:13:00 +0200 | [diff] [blame] | 1192 | drop_focus_state(shell, from, surface); |
| 1193 | |
| 1194 | if (shell->workspaces.anim_from == to && |
| 1195 | shell->workspaces.anim_to == from) { |
Jonas Ådahl | e9d2250 | 2012-08-29 22:13:01 +0200 | [diff] [blame] | 1196 | wl_list_remove(&to->layer.link); |
| 1197 | wl_list_insert(from->layer.link.prev, &to->layer.link); |
| 1198 | |
Jonas Ådahl | 8de6a1d | 2012-08-29 22:13:00 +0200 | [diff] [blame] | 1199 | reverse_workspace_change_animation(shell, index, from, to); |
Jonas Ådahl | e9d2250 | 2012-08-29 22:13:01 +0200 | [diff] [blame] | 1200 | broadcast_current_workspace_state(shell); |
| 1201 | |
Jonas Ådahl | 8de6a1d | 2012-08-29 22:13:00 +0200 | [diff] [blame] | 1202 | return; |
| 1203 | } |
| 1204 | |
| 1205 | if (shell->workspaces.anim_to != NULL) |
| 1206 | finish_workspace_change_animation(shell, |
| 1207 | shell->workspaces.anim_from, |
| 1208 | shell->workspaces.anim_to); |
| 1209 | |
| 1210 | if (workspace_is_empty(from) && |
| 1211 | workspace_has_only(to, surface)) |
| 1212 | update_workspace(shell, index, from, to); |
| 1213 | else { |
Philip Withnall | 2c3849b | 2013-11-25 18:01:45 +0000 | [diff] [blame] | 1214 | if (shsurf != NULL && |
| 1215 | wl_list_empty(&shsurf->workspace_transform.link)) |
Jonas Ådahl | 8de6a1d | 2012-08-29 22:13:00 +0200 | [diff] [blame] | 1216 | wl_list_insert(&shell->workspaces.anim_sticky_list, |
| 1217 | &shsurf->workspace_transform.link); |
| 1218 | |
| 1219 | animate_workspace_change(shell, index, from, to); |
| 1220 | } |
Jonas Ådahl | e9d2250 | 2012-08-29 22:13:01 +0200 | [diff] [blame] | 1221 | |
| 1222 | broadcast_current_workspace_state(shell); |
Jonas Ådahl | 8538b22 | 2012-08-29 22:13:03 +0200 | [diff] [blame] | 1223 | |
| 1224 | state = ensure_focus_state(shell, seat); |
| 1225 | if (state != NULL) |
| 1226 | state->keyboard_focus = surface; |
Jonas Ådahl | e9d2250 | 2012-08-29 22:13:01 +0200 | [diff] [blame] | 1227 | } |
| 1228 | |
| 1229 | static void |
| 1230 | workspace_manager_move_surface(struct wl_client *client, |
| 1231 | struct wl_resource *resource, |
| 1232 | struct wl_resource *surface_resource, |
| 1233 | uint32_t workspace) |
| 1234 | { |
Jason Ekstrand | 651f00e | 2013-06-14 10:07:54 -0500 | [diff] [blame] | 1235 | struct desktop_shell *shell = wl_resource_get_user_data(resource); |
Jonas Ådahl | e9d2250 | 2012-08-29 22:13:01 +0200 | [diff] [blame] | 1236 | struct weston_surface *surface = |
Jason Ekstrand | 0f2ef7e | 2013-06-14 10:07:53 -0500 | [diff] [blame] | 1237 | wl_resource_get_user_data(surface_resource); |
Pekka Paalanen | 01388e2 | 2013-04-25 13:57:44 +0300 | [diff] [blame] | 1238 | struct weston_surface *main_surface; |
Philip Withnall | 659163d | 2013-11-25 18:01:36 +0000 | [diff] [blame] | 1239 | struct shell_surface *shell_surface; |
Jonas Ådahl | e9d2250 | 2012-08-29 22:13:01 +0200 | [diff] [blame] | 1240 | |
Pekka Paalanen | 01388e2 | 2013-04-25 13:57:44 +0300 | [diff] [blame] | 1241 | main_surface = weston_surface_get_main_surface(surface); |
Philip Withnall | 659163d | 2013-11-25 18:01:36 +0000 | [diff] [blame] | 1242 | shell_surface = get_shell_surface(main_surface); |
| 1243 | if (shell_surface == NULL) |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 1244 | return; |
Philip Withnall | 659163d | 2013-11-25 18:01:36 +0000 | [diff] [blame] | 1245 | |
| 1246 | move_surface_to_workspace(shell, shell_surface, workspace); |
Jonas Ådahl | e9d2250 | 2012-08-29 22:13:01 +0200 | [diff] [blame] | 1247 | } |
| 1248 | |
| 1249 | static const struct workspace_manager_interface workspace_manager_implementation = { |
| 1250 | workspace_manager_move_surface, |
| 1251 | }; |
| 1252 | |
| 1253 | static void |
| 1254 | unbind_resource(struct wl_resource *resource) |
| 1255 | { |
Jason Ekstrand | 651f00e | 2013-06-14 10:07:54 -0500 | [diff] [blame] | 1256 | wl_list_remove(wl_resource_get_link(resource)); |
Jonas Ådahl | e9d2250 | 2012-08-29 22:13:01 +0200 | [diff] [blame] | 1257 | } |
| 1258 | |
| 1259 | static void |
| 1260 | bind_workspace_manager(struct wl_client *client, |
| 1261 | void *data, uint32_t version, uint32_t id) |
| 1262 | { |
| 1263 | struct desktop_shell *shell = data; |
| 1264 | struct wl_resource *resource; |
| 1265 | |
Jason Ekstrand | a85118c | 2013-06-27 20:17:02 -0500 | [diff] [blame] | 1266 | resource = wl_resource_create(client, |
| 1267 | &workspace_manager_interface, 1, id); |
Jonas Ådahl | e9d2250 | 2012-08-29 22:13:01 +0200 | [diff] [blame] | 1268 | |
| 1269 | if (resource == NULL) { |
| 1270 | weston_log("couldn't add workspace manager object"); |
| 1271 | return; |
| 1272 | } |
| 1273 | |
Jason Ekstrand | a85118c | 2013-06-27 20:17:02 -0500 | [diff] [blame] | 1274 | wl_resource_set_implementation(resource, |
| 1275 | &workspace_manager_implementation, |
| 1276 | shell, unbind_resource); |
Jason Ekstrand | 651f00e | 2013-06-14 10:07:54 -0500 | [diff] [blame] | 1277 | wl_list_insert(&shell->workspaces.client_list, |
| 1278 | wl_resource_get_link(resource)); |
Jonas Ådahl | e9d2250 | 2012-08-29 22:13:01 +0200 | [diff] [blame] | 1279 | |
| 1280 | workspace_manager_send_state(resource, |
| 1281 | shell->workspaces.current, |
| 1282 | shell->workspaces.num); |
Jonas Ådahl | 8de6a1d | 2012-08-29 22:13:00 +0200 | [diff] [blame] | 1283 | } |
| 1284 | |
Pekka Paalanen | 56cdea9 | 2011-11-23 16:14:12 +0200 | [diff] [blame] | 1285 | static void |
Rusty Lynch | 1084da5 | 2013-08-15 09:10:08 -0700 | [diff] [blame] | 1286 | touch_move_grab_down(struct weston_touch_grab *grab, uint32_t time, |
| 1287 | int touch_id, wl_fixed_t sx, wl_fixed_t sy) |
| 1288 | { |
| 1289 | } |
| 1290 | |
| 1291 | static void |
| 1292 | touch_move_grab_up(struct weston_touch_grab *grab, uint32_t time, int touch_id) |
| 1293 | { |
Jonas Ådahl | 1c6e63e | 2013-10-25 23:18:04 +0200 | [diff] [blame] | 1294 | struct weston_touch_move_grab *move = |
| 1295 | (struct weston_touch_move_grab *) container_of( |
| 1296 | grab, struct shell_touch_grab, grab); |
Neil Roberts | e14aa4f | 2013-10-03 16:43:07 +0100 | [diff] [blame] | 1297 | |
Jonas Ådahl | 9484b69 | 2013-12-02 22:05:03 +0100 | [diff] [blame] | 1298 | if (grab->touch->num_tp == 0) { |
Jonas Ådahl | 1c6e63e | 2013-10-25 23:18:04 +0200 | [diff] [blame] | 1299 | shell_touch_grab_end(&move->base); |
| 1300 | free(move); |
| 1301 | } |
Rusty Lynch | 1084da5 | 2013-08-15 09:10:08 -0700 | [diff] [blame] | 1302 | } |
| 1303 | |
| 1304 | static void |
| 1305 | touch_move_grab_motion(struct weston_touch_grab *grab, uint32_t time, |
| 1306 | int touch_id, wl_fixed_t sx, wl_fixed_t sy) |
| 1307 | { |
| 1308 | struct weston_touch_move_grab *move = (struct weston_touch_move_grab *) grab; |
| 1309 | struct shell_surface *shsurf = move->base.shsurf; |
| 1310 | struct weston_surface *es; |
| 1311 | int dx = wl_fixed_to_int(grab->touch->grab_x + move->dx); |
| 1312 | int dy = wl_fixed_to_int(grab->touch->grab_y + move->dy); |
| 1313 | |
| 1314 | if (!shsurf) |
| 1315 | return; |
| 1316 | |
| 1317 | es = shsurf->surface; |
| 1318 | |
Jason Ekstrand | 918f2dd | 2013-12-02 21:01:53 -0600 | [diff] [blame] | 1319 | weston_view_set_position(shsurf->view, dx, dy); |
Rusty Lynch | 1084da5 | 2013-08-15 09:10:08 -0700 | [diff] [blame] | 1320 | |
| 1321 | weston_compositor_schedule_repaint(es->compositor); |
| 1322 | } |
| 1323 | |
Jonas Ådahl | 1ea343e | 2013-10-25 23:18:05 +0200 | [diff] [blame] | 1324 | static void |
| 1325 | touch_move_grab_cancel(struct weston_touch_grab *grab) |
| 1326 | { |
| 1327 | struct weston_touch_move_grab *move = |
| 1328 | (struct weston_touch_move_grab *) container_of( |
| 1329 | grab, struct shell_touch_grab, grab); |
| 1330 | |
| 1331 | shell_touch_grab_end(&move->base); |
| 1332 | free(move); |
| 1333 | } |
| 1334 | |
Rusty Lynch | 1084da5 | 2013-08-15 09:10:08 -0700 | [diff] [blame] | 1335 | static const struct weston_touch_grab_interface touch_move_grab_interface = { |
| 1336 | touch_move_grab_down, |
| 1337 | touch_move_grab_up, |
| 1338 | touch_move_grab_motion, |
Jonas Ådahl | 1ea343e | 2013-10-25 23:18:05 +0200 | [diff] [blame] | 1339 | touch_move_grab_cancel, |
Rusty Lynch | 1084da5 | 2013-08-15 09:10:08 -0700 | [diff] [blame] | 1340 | }; |
| 1341 | |
| 1342 | static int |
| 1343 | surface_touch_move(struct shell_surface *shsurf, struct weston_seat *seat) |
| 1344 | { |
| 1345 | struct weston_touch_move_grab *move; |
| 1346 | |
| 1347 | if (!shsurf) |
| 1348 | return -1; |
| 1349 | |
Rafael Antognolli | 03b1659 | 2013-12-03 15:35:42 -0200 | [diff] [blame] | 1350 | if (shsurf->state.fullscreen) |
Rusty Lynch | 1084da5 | 2013-08-15 09:10:08 -0700 | [diff] [blame] | 1351 | return 0; |
Kristian Høgsberg | c85f1d4 | 2013-10-24 16:52:00 -0700 | [diff] [blame] | 1352 | if (shsurf->grabbed) |
| 1353 | return 0; |
Rusty Lynch | 1084da5 | 2013-08-15 09:10:08 -0700 | [diff] [blame] | 1354 | |
| 1355 | move = malloc(sizeof *move); |
| 1356 | if (!move) |
| 1357 | return -1; |
| 1358 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 1359 | move->dx = wl_fixed_from_double(shsurf->view->geometry.x) - |
Rusty Lynch | 1084da5 | 2013-08-15 09:10:08 -0700 | [diff] [blame] | 1360 | seat->touch->grab_x; |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 1361 | move->dy = wl_fixed_from_double(shsurf->view->geometry.y) - |
Rusty Lynch | 1084da5 | 2013-08-15 09:10:08 -0700 | [diff] [blame] | 1362 | seat->touch->grab_y; |
| 1363 | |
| 1364 | shell_touch_grab_start(&move->base, &touch_move_grab_interface, shsurf, |
| 1365 | seat->touch); |
| 1366 | |
| 1367 | return 0; |
| 1368 | } |
| 1369 | |
| 1370 | static void |
Kristian Høgsberg | 6848c25 | 2013-05-08 22:02:59 -0400 | [diff] [blame] | 1371 | noop_grab_focus(struct weston_pointer_grab *grab) |
Kristian Høgsberg | 9ddb826 | 2012-01-04 21:30:29 -0500 | [diff] [blame] | 1372 | { |
Kristian Høgsberg | 9ddb826 | 2012-01-04 21:30:29 -0500 | [diff] [blame] | 1373 | } |
| 1374 | |
| 1375 | static void |
Giulio Camuffo | 1959ab8 | 2013-11-14 23:42:52 +0100 | [diff] [blame] | 1376 | move_grab_motion(struct weston_pointer_grab *grab, uint32_t time, |
| 1377 | wl_fixed_t x, wl_fixed_t y) |
Kristian Høgsberg | 4cca349 | 2011-01-18 07:53:49 -0500 | [diff] [blame] | 1378 | { |
Kristian Høgsberg | 8334bc1 | 2012-01-03 10:29:47 -0500 | [diff] [blame] | 1379 | struct weston_move_grab *move = (struct weston_move_grab *) grab; |
Kristian Høgsberg | 02bbabb | 2013-05-06 22:15:05 -0400 | [diff] [blame] | 1380 | struct weston_pointer *pointer = grab->pointer; |
Ander Conselvan de Oliveira | fe0444a | 2012-04-04 17:48:05 +0300 | [diff] [blame] | 1381 | struct shell_surface *shsurf = move->base.shsurf; |
Giulio Camuffo | 1959ab8 | 2013-11-14 23:42:52 +0100 | [diff] [blame] | 1382 | int dx, dy; |
| 1383 | |
| 1384 | weston_pointer_move(pointer, x, y); |
| 1385 | dx = wl_fixed_to_int(pointer->x + move->dx); |
| 1386 | dy = wl_fixed_to_int(pointer->y + move->dy); |
Ander Conselvan de Oliveira | fe0444a | 2012-04-04 17:48:05 +0300 | [diff] [blame] | 1387 | |
| 1388 | if (!shsurf) |
| 1389 | return; |
| 1390 | |
Jason Ekstrand | 918f2dd | 2013-12-02 21:01:53 -0600 | [diff] [blame] | 1391 | weston_view_set_position(shsurf->view, dx, dy); |
Kristian Høgsberg | 4cca349 | 2011-01-18 07:53:49 -0500 | [diff] [blame] | 1392 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 1393 | weston_compositor_schedule_repaint(shsurf->surface->compositor); |
Kristian Høgsberg | 4cca349 | 2011-01-18 07:53:49 -0500 | [diff] [blame] | 1394 | } |
| 1395 | |
| 1396 | static void |
Kristian Høgsberg | 02bbabb | 2013-05-06 22:15:05 -0400 | [diff] [blame] | 1397 | move_grab_button(struct weston_pointer_grab *grab, |
Daniel Stone | 4dbadb1 | 2012-05-30 16:31:51 +0100 | [diff] [blame] | 1398 | uint32_t time, uint32_t button, uint32_t state_w) |
Kristian Høgsberg | 4cca349 | 2011-01-18 07:53:49 -0500 | [diff] [blame] | 1399 | { |
Ander Conselvan de Oliveira | fe0444a | 2012-04-04 17:48:05 +0300 | [diff] [blame] | 1400 | struct shell_grab *shell_grab = container_of(grab, struct shell_grab, |
| 1401 | grab); |
Kristian Høgsberg | 02bbabb | 2013-05-06 22:15:05 -0400 | [diff] [blame] | 1402 | struct weston_pointer *pointer = grab->pointer; |
Daniel Stone | 4dbadb1 | 2012-05-30 16:31:51 +0100 | [diff] [blame] | 1403 | enum wl_pointer_button_state state = state_w; |
Kristian Høgsberg | 4cca349 | 2011-01-18 07:53:49 -0500 | [diff] [blame] | 1404 | |
Daniel Stone | 4dbadb1 | 2012-05-30 16:31:51 +0100 | [diff] [blame] | 1405 | if (pointer->button_count == 0 && |
| 1406 | state == WL_POINTER_BUTTON_STATE_RELEASED) { |
Ander Conselvan de Oliveira | b9d2a0f | 2012-06-28 18:08:05 +0300 | [diff] [blame] | 1407 | shell_grab_end(shell_grab); |
Kristian Høgsberg | 9ddb826 | 2012-01-04 21:30:29 -0500 | [diff] [blame] | 1408 | free(grab); |
| 1409 | } |
Kristian Høgsberg | 4cca349 | 2011-01-18 07:53:49 -0500 | [diff] [blame] | 1410 | } |
| 1411 | |
Jonas Ådahl | 1ea343e | 2013-10-25 23:18:05 +0200 | [diff] [blame] | 1412 | static void |
| 1413 | move_grab_cancel(struct weston_pointer_grab *grab) |
| 1414 | { |
| 1415 | struct shell_grab *shell_grab = |
| 1416 | container_of(grab, struct shell_grab, grab); |
| 1417 | |
| 1418 | shell_grab_end(shell_grab); |
| 1419 | free(grab); |
| 1420 | } |
| 1421 | |
Kristian Høgsberg | 02bbabb | 2013-05-06 22:15:05 -0400 | [diff] [blame] | 1422 | static const struct weston_pointer_grab_interface move_grab_interface = { |
Kristian Høgsberg | 9ddb826 | 2012-01-04 21:30:29 -0500 | [diff] [blame] | 1423 | noop_grab_focus, |
Kristian Høgsberg | 4cca349 | 2011-01-18 07:53:49 -0500 | [diff] [blame] | 1424 | move_grab_motion, |
| 1425 | move_grab_button, |
Jonas Ådahl | 1ea343e | 2013-10-25 23:18:05 +0200 | [diff] [blame] | 1426 | move_grab_cancel, |
Kristian Høgsberg | 4cca349 | 2011-01-18 07:53:49 -0500 | [diff] [blame] | 1427 | }; |
| 1428 | |
Kristian Høgsberg | 9e31bff | 2012-08-01 00:08:07 -0400 | [diff] [blame] | 1429 | static int |
Kristian Høgsberg | e314875 | 2013-05-06 23:19:49 -0400 | [diff] [blame] | 1430 | surface_move(struct shell_surface *shsurf, struct weston_seat *seat) |
Kristian Høgsberg | 9e31bff | 2012-08-01 00:08:07 -0400 | [diff] [blame] | 1431 | { |
| 1432 | struct weston_move_grab *move; |
| 1433 | |
| 1434 | if (!shsurf) |
| 1435 | return -1; |
| 1436 | |
Kristian Høgsberg | c85f1d4 | 2013-10-24 16:52:00 -0700 | [diff] [blame] | 1437 | if (shsurf->grabbed) |
| 1438 | return 0; |
Rafael Antognolli | 03b1659 | 2013-12-03 15:35:42 -0200 | [diff] [blame] | 1439 | if (shsurf->state.fullscreen) |
Kristian Høgsberg | 9e31bff | 2012-08-01 00:08:07 -0400 | [diff] [blame] | 1440 | return 0; |
| 1441 | |
| 1442 | move = malloc(sizeof *move); |
| 1443 | if (!move) |
| 1444 | return -1; |
| 1445 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 1446 | move->dx = wl_fixed_from_double(shsurf->view->geometry.x) - |
Kristian Høgsberg | e314875 | 2013-05-06 23:19:49 -0400 | [diff] [blame] | 1447 | seat->pointer->grab_x; |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 1448 | move->dy = wl_fixed_from_double(shsurf->view->geometry.y) - |
Kristian Høgsberg | e314875 | 2013-05-06 23:19:49 -0400 | [diff] [blame] | 1449 | seat->pointer->grab_y; |
Kristian Høgsberg | 9e31bff | 2012-08-01 00:08:07 -0400 | [diff] [blame] | 1450 | |
| 1451 | shell_grab_start(&move->base, &move_grab_interface, shsurf, |
Kristian Høgsberg | e314875 | 2013-05-06 23:19:49 -0400 | [diff] [blame] | 1452 | seat->pointer, DESKTOP_SHELL_CURSOR_MOVE); |
Kristian Høgsberg | 9e31bff | 2012-08-01 00:08:07 -0400 | [diff] [blame] | 1453 | |
| 1454 | return 0; |
| 1455 | } |
| 1456 | |
| 1457 | static void |
Rafael Antognolli | e2a3455 | 2013-12-03 15:35:45 -0200 | [diff] [blame] | 1458 | common_surface_move(struct wl_resource *resource, |
| 1459 | struct wl_resource *seat_resource, uint32_t serial) |
Kristian Høgsberg | 9e31bff | 2012-08-01 00:08:07 -0400 | [diff] [blame] | 1460 | { |
Jason Ekstrand | 44a3863 | 2013-06-14 10:08:00 -0500 | [diff] [blame] | 1461 | struct weston_seat *seat = wl_resource_get_user_data(seat_resource); |
Jason Ekstrand | 651f00e | 2013-06-14 10:07:54 -0500 | [diff] [blame] | 1462 | struct shell_surface *shsurf = wl_resource_get_user_data(resource); |
Giulio Camuffo | 61da3fc | 2013-04-25 13:57:45 +0300 | [diff] [blame] | 1463 | struct weston_surface *surface; |
Kristian Høgsberg | 9e31bff | 2012-08-01 00:08:07 -0400 | [diff] [blame] | 1464 | |
Kristian Høgsberg | e1b655d | 2013-08-28 23:16:20 -0700 | [diff] [blame] | 1465 | if (seat->pointer && |
| 1466 | seat->pointer->button_count > 0 && |
| 1467 | seat->pointer->grab_serial == serial) { |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 1468 | surface = weston_surface_get_main_surface(seat->pointer->focus->surface); |
Rusty Lynch | 1084da5 | 2013-08-15 09:10:08 -0700 | [diff] [blame] | 1469 | if ((surface == shsurf->surface) && |
| 1470 | (surface_move(shsurf, seat) < 0)) |
| 1471 | wl_resource_post_no_memory(resource); |
Kristian Høgsberg | e1b655d | 2013-08-28 23:16:20 -0700 | [diff] [blame] | 1472 | } else if (seat->touch && |
| 1473 | seat->touch->grab_serial == serial) { |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 1474 | surface = weston_surface_get_main_surface(seat->touch->focus->surface); |
Rusty Lynch | 1084da5 | 2013-08-15 09:10:08 -0700 | [diff] [blame] | 1475 | if ((surface == shsurf->surface) && |
| 1476 | (surface_touch_move(shsurf, seat) < 0)) |
| 1477 | wl_resource_post_no_memory(resource); |
| 1478 | } |
Kristian Høgsberg | 9e31bff | 2012-08-01 00:08:07 -0400 | [diff] [blame] | 1479 | } |
| 1480 | |
Rafael Antognolli | e2a3455 | 2013-12-03 15:35:45 -0200 | [diff] [blame] | 1481 | static void |
| 1482 | shell_surface_move(struct wl_client *client, struct wl_resource *resource, |
| 1483 | struct wl_resource *seat_resource, uint32_t serial) |
| 1484 | { |
| 1485 | common_surface_move(resource, seat_resource, serial); |
| 1486 | } |
| 1487 | |
Kristian Høgsberg | 9e31bff | 2012-08-01 00:08:07 -0400 | [diff] [blame] | 1488 | struct weston_resize_grab { |
| 1489 | struct shell_grab base; |
| 1490 | uint32_t edges; |
| 1491 | int32_t width, height; |
| 1492 | }; |
| 1493 | |
| 1494 | static void |
Giulio Camuffo | 1959ab8 | 2013-11-14 23:42:52 +0100 | [diff] [blame] | 1495 | resize_grab_motion(struct weston_pointer_grab *grab, uint32_t time, |
| 1496 | wl_fixed_t x, wl_fixed_t y) |
Kristian Høgsberg | 9e31bff | 2012-08-01 00:08:07 -0400 | [diff] [blame] | 1497 | { |
| 1498 | struct weston_resize_grab *resize = (struct weston_resize_grab *) grab; |
Kristian Høgsberg | 02bbabb | 2013-05-06 22:15:05 -0400 | [diff] [blame] | 1499 | struct weston_pointer *pointer = grab->pointer; |
Kristian Høgsberg | 9e31bff | 2012-08-01 00:08:07 -0400 | [diff] [blame] | 1500 | struct shell_surface *shsurf = resize->base.shsurf; |
| 1501 | int32_t width, height; |
| 1502 | wl_fixed_t from_x, from_y; |
| 1503 | wl_fixed_t to_x, to_y; |
| 1504 | |
Giulio Camuffo | 1959ab8 | 2013-11-14 23:42:52 +0100 | [diff] [blame] | 1505 | weston_pointer_move(pointer, x, y); |
| 1506 | |
Kristian Høgsberg | 9e31bff | 2012-08-01 00:08:07 -0400 | [diff] [blame] | 1507 | if (!shsurf) |
| 1508 | return; |
| 1509 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 1510 | weston_view_from_global_fixed(shsurf->view, |
| 1511 | pointer->grab_x, pointer->grab_y, |
| 1512 | &from_x, &from_y); |
| 1513 | weston_view_from_global_fixed(shsurf->view, |
| 1514 | pointer->x, pointer->y, &to_x, &to_y); |
Kristian Høgsberg | 9e31bff | 2012-08-01 00:08:07 -0400 | [diff] [blame] | 1515 | |
| 1516 | width = resize->width; |
| 1517 | if (resize->edges & WL_SHELL_SURFACE_RESIZE_LEFT) { |
| 1518 | width += wl_fixed_to_int(from_x - to_x); |
| 1519 | } else if (resize->edges & WL_SHELL_SURFACE_RESIZE_RIGHT) { |
| 1520 | width += wl_fixed_to_int(to_x - from_x); |
| 1521 | } |
| 1522 | |
| 1523 | height = resize->height; |
| 1524 | if (resize->edges & WL_SHELL_SURFACE_RESIZE_TOP) { |
| 1525 | height += wl_fixed_to_int(from_y - to_y); |
| 1526 | } else if (resize->edges & WL_SHELL_SURFACE_RESIZE_BOTTOM) { |
| 1527 | height += wl_fixed_to_int(to_y - from_y); |
| 1528 | } |
| 1529 | |
| 1530 | shsurf->client->send_configure(shsurf->surface, |
| 1531 | resize->edges, width, height); |
| 1532 | } |
| 1533 | |
| 1534 | static void |
| 1535 | send_configure(struct weston_surface *surface, |
| 1536 | uint32_t edges, int32_t width, int32_t height) |
| 1537 | { |
| 1538 | struct shell_surface *shsurf = get_shell_surface(surface); |
| 1539 | |
Jason Ekstrand | 651f00e | 2013-06-14 10:07:54 -0500 | [diff] [blame] | 1540 | wl_shell_surface_send_configure(shsurf->resource, |
Kristian Høgsberg | 9e31bff | 2012-08-01 00:08:07 -0400 | [diff] [blame] | 1541 | edges, width, height); |
| 1542 | } |
| 1543 | |
| 1544 | static const struct weston_shell_client shell_client = { |
| 1545 | send_configure |
| 1546 | }; |
| 1547 | |
| 1548 | static void |
Kristian Høgsberg | 02bbabb | 2013-05-06 22:15:05 -0400 | [diff] [blame] | 1549 | resize_grab_button(struct weston_pointer_grab *grab, |
Kristian Høgsberg | 9e31bff | 2012-08-01 00:08:07 -0400 | [diff] [blame] | 1550 | uint32_t time, uint32_t button, uint32_t state_w) |
| 1551 | { |
| 1552 | struct weston_resize_grab *resize = (struct weston_resize_grab *) grab; |
Kristian Høgsberg | 02bbabb | 2013-05-06 22:15:05 -0400 | [diff] [blame] | 1553 | struct weston_pointer *pointer = grab->pointer; |
Kristian Høgsberg | 9e31bff | 2012-08-01 00:08:07 -0400 | [diff] [blame] | 1554 | enum wl_pointer_button_state state = state_w; |
| 1555 | |
| 1556 | if (pointer->button_count == 0 && |
| 1557 | state == WL_POINTER_BUTTON_STATE_RELEASED) { |
| 1558 | shell_grab_end(&resize->base); |
| 1559 | free(grab); |
| 1560 | } |
| 1561 | } |
| 1562 | |
Jonas Ådahl | 1ea343e | 2013-10-25 23:18:05 +0200 | [diff] [blame] | 1563 | static void |
| 1564 | resize_grab_cancel(struct weston_pointer_grab *grab) |
| 1565 | { |
| 1566 | struct weston_resize_grab *resize = (struct weston_resize_grab *) grab; |
| 1567 | |
| 1568 | shell_grab_end(&resize->base); |
| 1569 | free(grab); |
| 1570 | } |
| 1571 | |
Kristian Høgsberg | 02bbabb | 2013-05-06 22:15:05 -0400 | [diff] [blame] | 1572 | static const struct weston_pointer_grab_interface resize_grab_interface = { |
Kristian Høgsberg | 9e31bff | 2012-08-01 00:08:07 -0400 | [diff] [blame] | 1573 | noop_grab_focus, |
| 1574 | resize_grab_motion, |
| 1575 | resize_grab_button, |
Jonas Ådahl | 1ea343e | 2013-10-25 23:18:05 +0200 | [diff] [blame] | 1576 | resize_grab_cancel, |
Kristian Høgsberg | 9e31bff | 2012-08-01 00:08:07 -0400 | [diff] [blame] | 1577 | }; |
| 1578 | |
Giulio Camuffo | b836664 | 2013-04-25 13:57:46 +0300 | [diff] [blame] | 1579 | /* |
| 1580 | * Returns the bounding box of a surface and all its sub-surfaces, |
| 1581 | * in the surface coordinates system. */ |
| 1582 | static void |
| 1583 | surface_subsurfaces_boundingbox(struct weston_surface *surface, int32_t *x, |
| 1584 | int32_t *y, int32_t *w, int32_t *h) { |
| 1585 | pixman_region32_t region; |
| 1586 | pixman_box32_t *box; |
| 1587 | struct weston_subsurface *subsurface; |
| 1588 | |
| 1589 | pixman_region32_init_rect(®ion, 0, 0, |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 1590 | surface->width, |
| 1591 | surface->height); |
Giulio Camuffo | b836664 | 2013-04-25 13:57:46 +0300 | [diff] [blame] | 1592 | |
| 1593 | wl_list_for_each(subsurface, &surface->subsurface_list, parent_link) { |
| 1594 | pixman_region32_union_rect(®ion, ®ion, |
| 1595 | subsurface->position.x, |
| 1596 | subsurface->position.y, |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 1597 | subsurface->surface->width, |
| 1598 | subsurface->surface->height); |
Giulio Camuffo | b836664 | 2013-04-25 13:57:46 +0300 | [diff] [blame] | 1599 | } |
| 1600 | |
| 1601 | box = pixman_region32_extents(®ion); |
| 1602 | if (x) |
| 1603 | *x = box->x1; |
| 1604 | if (y) |
| 1605 | *y = box->y1; |
| 1606 | if (w) |
| 1607 | *w = box->x2 - box->x1; |
| 1608 | if (h) |
| 1609 | *h = box->y2 - box->y1; |
| 1610 | |
| 1611 | pixman_region32_fini(®ion); |
| 1612 | } |
| 1613 | |
Kristian Høgsberg | 9e31bff | 2012-08-01 00:08:07 -0400 | [diff] [blame] | 1614 | static int |
| 1615 | surface_resize(struct shell_surface *shsurf, |
Kristian Høgsberg | e314875 | 2013-05-06 23:19:49 -0400 | [diff] [blame] | 1616 | struct weston_seat *seat, uint32_t edges) |
Kristian Høgsberg | 9e31bff | 2012-08-01 00:08:07 -0400 | [diff] [blame] | 1617 | { |
| 1618 | struct weston_resize_grab *resize; |
| 1619 | |
Rafael Antognolli | 03b1659 | 2013-12-03 15:35:42 -0200 | [diff] [blame] | 1620 | if (shsurf->state.fullscreen || shsurf->state.maximized) |
Kristian Høgsberg | 9e31bff | 2012-08-01 00:08:07 -0400 | [diff] [blame] | 1621 | return 0; |
| 1622 | |
| 1623 | if (edges == 0 || edges > 15 || |
| 1624 | (edges & 3) == 3 || (edges & 12) == 12) |
| 1625 | return 0; |
| 1626 | |
| 1627 | resize = malloc(sizeof *resize); |
| 1628 | if (!resize) |
| 1629 | return -1; |
| 1630 | |
| 1631 | resize->edges = edges; |
Giulio Camuffo | b836664 | 2013-04-25 13:57:46 +0300 | [diff] [blame] | 1632 | surface_subsurfaces_boundingbox(shsurf->surface, NULL, NULL, |
| 1633 | &resize->width, &resize->height); |
Kristian Høgsberg | 9e31bff | 2012-08-01 00:08:07 -0400 | [diff] [blame] | 1634 | |
| 1635 | shell_grab_start(&resize->base, &resize_grab_interface, shsurf, |
Kristian Høgsberg | e314875 | 2013-05-06 23:19:49 -0400 | [diff] [blame] | 1636 | seat->pointer, edges); |
Kristian Høgsberg | 9e31bff | 2012-08-01 00:08:07 -0400 | [diff] [blame] | 1637 | |
| 1638 | return 0; |
| 1639 | } |
| 1640 | |
| 1641 | static void |
Rafael Antognolli | e2a3455 | 2013-12-03 15:35:45 -0200 | [diff] [blame] | 1642 | common_surface_resize(struct wl_resource *resource, |
| 1643 | struct wl_resource *seat_resource, uint32_t serial, |
| 1644 | uint32_t edges) |
Kristian Høgsberg | 9e31bff | 2012-08-01 00:08:07 -0400 | [diff] [blame] | 1645 | { |
Jason Ekstrand | 44a3863 | 2013-06-14 10:08:00 -0500 | [diff] [blame] | 1646 | struct weston_seat *seat = wl_resource_get_user_data(seat_resource); |
Jason Ekstrand | 651f00e | 2013-06-14 10:07:54 -0500 | [diff] [blame] | 1647 | struct shell_surface *shsurf = wl_resource_get_user_data(resource); |
Giulio Camuffo | 61da3fc | 2013-04-25 13:57:45 +0300 | [diff] [blame] | 1648 | struct weston_surface *surface; |
Kristian Høgsberg | 9e31bff | 2012-08-01 00:08:07 -0400 | [diff] [blame] | 1649 | |
Rafael Antognolli | 03b1659 | 2013-12-03 15:35:42 -0200 | [diff] [blame] | 1650 | if (shsurf->state.fullscreen) |
Kristian Høgsberg | 9e31bff | 2012-08-01 00:08:07 -0400 | [diff] [blame] | 1651 | return; |
| 1652 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 1653 | surface = weston_surface_get_main_surface(seat->pointer->focus->surface); |
Kristian Høgsberg | e314875 | 2013-05-06 23:19:49 -0400 | [diff] [blame] | 1654 | if (seat->pointer->button_count == 0 || |
| 1655 | seat->pointer->grab_serial != serial || |
Giulio Camuffo | 61da3fc | 2013-04-25 13:57:45 +0300 | [diff] [blame] | 1656 | surface != shsurf->surface) |
Kristian Høgsberg | 9e31bff | 2012-08-01 00:08:07 -0400 | [diff] [blame] | 1657 | return; |
| 1658 | |
Kristian Høgsberg | e314875 | 2013-05-06 23:19:49 -0400 | [diff] [blame] | 1659 | if (surface_resize(shsurf, seat, edges) < 0) |
Kristian Høgsberg | 9e31bff | 2012-08-01 00:08:07 -0400 | [diff] [blame] | 1660 | wl_resource_post_no_memory(resource); |
| 1661 | } |
| 1662 | |
Scott Moreau | c3e54eb | 2012-04-17 19:06:20 -0600 | [diff] [blame] | 1663 | static void |
Rafael Antognolli | e2a3455 | 2013-12-03 15:35:45 -0200 | [diff] [blame] | 1664 | shell_surface_resize(struct wl_client *client, struct wl_resource *resource, |
| 1665 | struct wl_resource *seat_resource, uint32_t serial, |
| 1666 | uint32_t edges) |
| 1667 | { |
| 1668 | common_surface_resize(resource, seat_resource, serial, edges); |
| 1669 | } |
| 1670 | |
| 1671 | static void |
Kristian Høgsberg | 6780073 | 2013-07-04 01:12:17 -0400 | [diff] [blame] | 1672 | end_busy_cursor(struct shell_surface *shsurf, struct weston_pointer *pointer); |
| 1673 | |
| 1674 | static void |
Kristian Høgsberg | 6848c25 | 2013-05-08 22:02:59 -0400 | [diff] [blame] | 1675 | busy_cursor_grab_focus(struct weston_pointer_grab *base) |
Scott Moreau | c3e54eb | 2012-04-17 19:06:20 -0600 | [diff] [blame] | 1676 | { |
Kristian Høgsberg | d56bd90 | 2012-06-05 09:58:51 -0400 | [diff] [blame] | 1677 | struct shell_grab *grab = (struct shell_grab *) base; |
Kristian Høgsberg | 6848c25 | 2013-05-08 22:02:59 -0400 | [diff] [blame] | 1678 | struct weston_pointer *pointer = base->pointer; |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 1679 | struct weston_view *view; |
Kristian Høgsberg | 6848c25 | 2013-05-08 22:02:59 -0400 | [diff] [blame] | 1680 | wl_fixed_t sx, sy; |
| 1681 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 1682 | view = weston_compositor_pick_view(pointer->seat->compositor, |
| 1683 | pointer->x, pointer->y, |
| 1684 | &sx, &sy); |
Scott Moreau | c3e54eb | 2012-04-17 19:06:20 -0600 | [diff] [blame] | 1685 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 1686 | if (!grab->shsurf || grab->shsurf->surface != view->surface) |
Kristian Høgsberg | 6780073 | 2013-07-04 01:12:17 -0400 | [diff] [blame] | 1687 | end_busy_cursor(grab->shsurf, pointer); |
Scott Moreau | c3e54eb | 2012-04-17 19:06:20 -0600 | [diff] [blame] | 1688 | } |
| 1689 | |
| 1690 | static void |
Giulio Camuffo | 1959ab8 | 2013-11-14 23:42:52 +0100 | [diff] [blame] | 1691 | busy_cursor_grab_motion(struct weston_pointer_grab *grab, uint32_t time, |
| 1692 | wl_fixed_t x, wl_fixed_t y) |
Scott Moreau | c3e54eb | 2012-04-17 19:06:20 -0600 | [diff] [blame] | 1693 | { |
Giulio Camuffo | 1959ab8 | 2013-11-14 23:42:52 +0100 | [diff] [blame] | 1694 | weston_pointer_move(grab->pointer, x, y); |
Kristian Høgsberg | d56bd90 | 2012-06-05 09:58:51 -0400 | [diff] [blame] | 1695 | } |
Scott Moreau | c3e54eb | 2012-04-17 19:06:20 -0600 | [diff] [blame] | 1696 | |
Kristian Høgsberg | d56bd90 | 2012-06-05 09:58:51 -0400 | [diff] [blame] | 1697 | static void |
Kristian Høgsberg | 02bbabb | 2013-05-06 22:15:05 -0400 | [diff] [blame] | 1698 | busy_cursor_grab_button(struct weston_pointer_grab *base, |
Kristian Høgsberg | d56bd90 | 2012-06-05 09:58:51 -0400 | [diff] [blame] | 1699 | uint32_t time, uint32_t button, uint32_t state) |
| 1700 | { |
Kristian Høgsberg | bbe9839 | 2012-08-01 00:20:21 -0400 | [diff] [blame] | 1701 | struct shell_grab *grab = (struct shell_grab *) base; |
Kristian Høgsberg | e122b7b | 2013-05-08 16:47:00 -0400 | [diff] [blame] | 1702 | struct shell_surface *shsurf = grab->shsurf; |
Kristian Høgsberg | e314875 | 2013-05-06 23:19:49 -0400 | [diff] [blame] | 1703 | struct weston_seat *seat = grab->grab.pointer->seat; |
Kristian Høgsberg | bbe9839 | 2012-08-01 00:20:21 -0400 | [diff] [blame] | 1704 | |
Kristian Høgsberg | bbe9839 | 2012-08-01 00:20:21 -0400 | [diff] [blame] | 1705 | if (shsurf && button == BTN_LEFT && state) { |
| 1706 | activate(shsurf->shell, shsurf->surface, seat); |
| 1707 | surface_move(shsurf, seat); |
Kristian Høgsberg | 0c36903 | 2013-02-14 21:31:44 -0500 | [diff] [blame] | 1708 | } else if (shsurf && button == BTN_RIGHT && state) { |
| 1709 | activate(shsurf->shell, shsurf->surface, seat); |
Kristian Høgsberg | e314875 | 2013-05-06 23:19:49 -0400 | [diff] [blame] | 1710 | surface_rotate(shsurf, seat); |
Kristian Høgsberg | bbe9839 | 2012-08-01 00:20:21 -0400 | [diff] [blame] | 1711 | } |
Kristian Høgsberg | d56bd90 | 2012-06-05 09:58:51 -0400 | [diff] [blame] | 1712 | } |
| 1713 | |
Jonas Ådahl | 1ea343e | 2013-10-25 23:18:05 +0200 | [diff] [blame] | 1714 | static void |
| 1715 | busy_cursor_grab_cancel(struct weston_pointer_grab *base) |
| 1716 | { |
| 1717 | struct shell_grab *grab = (struct shell_grab *) base; |
| 1718 | |
| 1719 | shell_grab_end(grab); |
| 1720 | free(grab); |
| 1721 | } |
| 1722 | |
Kristian Høgsberg | 02bbabb | 2013-05-06 22:15:05 -0400 | [diff] [blame] | 1723 | static const struct weston_pointer_grab_interface busy_cursor_grab_interface = { |
Kristian Høgsberg | d56bd90 | 2012-06-05 09:58:51 -0400 | [diff] [blame] | 1724 | busy_cursor_grab_focus, |
| 1725 | busy_cursor_grab_motion, |
| 1726 | busy_cursor_grab_button, |
Jonas Ådahl | 1ea343e | 2013-10-25 23:18:05 +0200 | [diff] [blame] | 1727 | busy_cursor_grab_cancel, |
Kristian Høgsberg | d56bd90 | 2012-06-05 09:58:51 -0400 | [diff] [blame] | 1728 | }; |
| 1729 | |
| 1730 | static void |
Kristian Høgsberg | 02bbabb | 2013-05-06 22:15:05 -0400 | [diff] [blame] | 1731 | set_busy_cursor(struct shell_surface *shsurf, struct weston_pointer *pointer) |
Kristian Høgsberg | d56bd90 | 2012-06-05 09:58:51 -0400 | [diff] [blame] | 1732 | { |
| 1733 | struct shell_grab *grab; |
Kristian Høgsberg | d56bd90 | 2012-06-05 09:58:51 -0400 | [diff] [blame] | 1734 | |
| 1735 | grab = malloc(sizeof *grab); |
| 1736 | if (!grab) |
Scott Moreau | c3e54eb | 2012-04-17 19:06:20 -0600 | [diff] [blame] | 1737 | return; |
| 1738 | |
Ander Conselvan de Oliveira | b9d2a0f | 2012-06-28 18:08:05 +0300 | [diff] [blame] | 1739 | shell_grab_start(grab, &busy_cursor_grab_interface, shsurf, pointer, |
| 1740 | DESKTOP_SHELL_CURSOR_BUSY); |
Kristian Høgsberg | d56bd90 | 2012-06-05 09:58:51 -0400 | [diff] [blame] | 1741 | } |
Scott Moreau | c3e54eb | 2012-04-17 19:06:20 -0600 | [diff] [blame] | 1742 | |
Kristian Høgsberg | d56bd90 | 2012-06-05 09:58:51 -0400 | [diff] [blame] | 1743 | static void |
Kristian Høgsberg | 02bbabb | 2013-05-06 22:15:05 -0400 | [diff] [blame] | 1744 | end_busy_cursor(struct shell_surface *shsurf, struct weston_pointer *pointer) |
Kristian Høgsberg | d56bd90 | 2012-06-05 09:58:51 -0400 | [diff] [blame] | 1745 | { |
| 1746 | struct shell_grab *grab = (struct shell_grab *) pointer->grab; |
| 1747 | |
Kristian Høgsberg | e122b7b | 2013-05-08 16:47:00 -0400 | [diff] [blame] | 1748 | if (grab->grab.interface == &busy_cursor_grab_interface && |
| 1749 | grab->shsurf == shsurf) { |
Ander Conselvan de Oliveira | b9d2a0f | 2012-06-28 18:08:05 +0300 | [diff] [blame] | 1750 | shell_grab_end(grab); |
Kristian Høgsberg | d56bd90 | 2012-06-05 09:58:51 -0400 | [diff] [blame] | 1751 | free(grab); |
Scott Moreau | c3e54eb | 2012-04-17 19:06:20 -0600 | [diff] [blame] | 1752 | } |
Scott Moreau | c3e54eb | 2012-04-17 19:06:20 -0600 | [diff] [blame] | 1753 | } |
| 1754 | |
Scott Moreau | 9521d5e | 2012-04-19 13:06:17 -0600 | [diff] [blame] | 1755 | static void |
| 1756 | ping_timer_destroy(struct shell_surface *shsurf) |
| 1757 | { |
| 1758 | if (!shsurf || !shsurf->ping_timer) |
| 1759 | return; |
| 1760 | |
| 1761 | if (shsurf->ping_timer->source) |
| 1762 | wl_event_source_remove(shsurf->ping_timer->source); |
| 1763 | |
| 1764 | free(shsurf->ping_timer); |
| 1765 | shsurf->ping_timer = NULL; |
| 1766 | } |
| 1767 | |
Kristian Høgsberg | 97d44aa | 2011-08-26 17:21:20 -0400 | [diff] [blame] | 1768 | static int |
Scott Moreau | ff1db4a | 2012-04-17 19:06:18 -0600 | [diff] [blame] | 1769 | ping_timeout_handler(void *data) |
| 1770 | { |
| 1771 | struct shell_surface *shsurf = data; |
Kristian Høgsberg | d56bd90 | 2012-06-05 09:58:51 -0400 | [diff] [blame] | 1772 | struct weston_seat *seat; |
Scott Moreau | ff1db4a | 2012-04-17 19:06:18 -0600 | [diff] [blame] | 1773 | |
Scott Moreau | 9521d5e | 2012-04-19 13:06:17 -0600 | [diff] [blame] | 1774 | /* Client is not responding */ |
| 1775 | shsurf->unresponsive = 1; |
Kristian Høgsberg | d56bd90 | 2012-06-05 09:58:51 -0400 | [diff] [blame] | 1776 | |
| 1777 | wl_list_for_each(seat, &shsurf->surface->compositor->seat_list, link) |
Emilio Pozuelo Monfort | 3d0fc76 | 2013-11-22 16:21:20 +0100 | [diff] [blame] | 1778 | if (seat->pointer->focus && |
| 1779 | seat->pointer->focus->surface == shsurf->surface) |
Kristian Høgsberg | e314875 | 2013-05-06 23:19:49 -0400 | [diff] [blame] | 1780 | set_busy_cursor(shsurf, seat->pointer); |
Scott Moreau | ff1db4a | 2012-04-17 19:06:18 -0600 | [diff] [blame] | 1781 | |
| 1782 | return 1; |
| 1783 | } |
| 1784 | |
| 1785 | static void |
| 1786 | ping_handler(struct weston_surface *surface, uint32_t serial) |
| 1787 | { |
Kristian Høgsberg | b71302e | 2012-05-10 12:28:35 -0400 | [diff] [blame] | 1788 | struct shell_surface *shsurf = get_shell_surface(surface); |
Scott Moreau | ff1db4a | 2012-04-17 19:06:18 -0600 | [diff] [blame] | 1789 | struct wl_event_loop *loop; |
Kristian Høgsberg | d56bd90 | 2012-06-05 09:58:51 -0400 | [diff] [blame] | 1790 | int ping_timeout = 200; |
Scott Moreau | ff1db4a | 2012-04-17 19:06:18 -0600 | [diff] [blame] | 1791 | |
| 1792 | if (!shsurf) |
| 1793 | return; |
Jason Ekstrand | 651f00e | 2013-06-14 10:07:54 -0500 | [diff] [blame] | 1794 | if (!shsurf->resource) |
Kristian Høgsberg | ca535c1 | 2012-04-21 23:20:07 -0400 | [diff] [blame] | 1795 | return; |
Scott Moreau | ff1db4a | 2012-04-17 19:06:18 -0600 | [diff] [blame] | 1796 | |
Ander Conselvan de Oliveira | eac9a46 | 2012-07-16 14:15:48 +0300 | [diff] [blame] | 1797 | if (shsurf->surface == shsurf->shell->grab_surface) |
| 1798 | return; |
| 1799 | |
Scott Moreau | ff1db4a | 2012-04-17 19:06:18 -0600 | [diff] [blame] | 1800 | if (!shsurf->ping_timer) { |
Ander Conselvan de Oliveira | fb98089 | 2012-04-27 13:55:55 +0300 | [diff] [blame] | 1801 | shsurf->ping_timer = malloc(sizeof *shsurf->ping_timer); |
Scott Moreau | ff1db4a | 2012-04-17 19:06:18 -0600 | [diff] [blame] | 1802 | if (!shsurf->ping_timer) |
| 1803 | return; |
| 1804 | |
| 1805 | shsurf->ping_timer->serial = serial; |
Scott Moreau | ff1db4a | 2012-04-17 19:06:18 -0600 | [diff] [blame] | 1806 | loop = wl_display_get_event_loop(surface->compositor->wl_display); |
| 1807 | shsurf->ping_timer->source = |
| 1808 | wl_event_loop_add_timer(loop, ping_timeout_handler, shsurf); |
| 1809 | wl_event_source_timer_update(shsurf->ping_timer->source, ping_timeout); |
| 1810 | |
Rafael Antognolli | e2a3455 | 2013-12-03 15:35:45 -0200 | [diff] [blame] | 1811 | if (shell_surface_is_wl_shell_surface(shsurf)) |
| 1812 | wl_shell_surface_send_ping(shsurf->resource, serial); |
| 1813 | else if (shell_surface_is_xdg_surface(shsurf)) |
| 1814 | xdg_surface_send_ping(shsurf->resource, serial); |
| 1815 | else if (shell_surface_is_xdg_popup(shsurf)) |
| 1816 | xdg_popup_send_ping(shsurf->resource, serial); |
Scott Moreau | ff1db4a | 2012-04-17 19:06:18 -0600 | [diff] [blame] | 1817 | } |
| 1818 | } |
| 1819 | |
| 1820 | static void |
Kristian Høgsberg | d56bd90 | 2012-06-05 09:58:51 -0400 | [diff] [blame] | 1821 | handle_pointer_focus(struct wl_listener *listener, void *data) |
| 1822 | { |
Kristian Høgsberg | 02bbabb | 2013-05-06 22:15:05 -0400 | [diff] [blame] | 1823 | struct weston_pointer *pointer = data; |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 1824 | struct weston_view *view = pointer->focus; |
Kristian Høgsberg | d56bd90 | 2012-06-05 09:58:51 -0400 | [diff] [blame] | 1825 | struct weston_compositor *compositor; |
| 1826 | struct shell_surface *shsurf; |
| 1827 | uint32_t serial; |
| 1828 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 1829 | if (!view) |
Kristian Høgsberg | d56bd90 | 2012-06-05 09:58:51 -0400 | [diff] [blame] | 1830 | return; |
| 1831 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 1832 | compositor = view->surface->compositor; |
| 1833 | shsurf = get_shell_surface(view->surface); |
Kristian Høgsberg | d56bd90 | 2012-06-05 09:58:51 -0400 | [diff] [blame] | 1834 | |
Pekka Paalanen | 4e1f2ff | 2012-06-06 16:59:45 +0300 | [diff] [blame] | 1835 | if (shsurf && shsurf->unresponsive) { |
Kristian Høgsberg | d56bd90 | 2012-06-05 09:58:51 -0400 | [diff] [blame] | 1836 | set_busy_cursor(shsurf, pointer); |
| 1837 | } else { |
| 1838 | serial = wl_display_next_serial(compositor->wl_display); |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 1839 | ping_handler(view->surface, serial); |
Kristian Høgsberg | d56bd90 | 2012-06-05 09:58:51 -0400 | [diff] [blame] | 1840 | } |
| 1841 | } |
| 1842 | |
| 1843 | static void |
Kristian Høgsberg | f4d2f23 | 2012-08-10 10:05:39 -0400 | [diff] [blame] | 1844 | create_pointer_focus_listener(struct weston_seat *seat) |
| 1845 | { |
| 1846 | struct wl_listener *listener; |
| 1847 | |
Kristian Høgsberg | e314875 | 2013-05-06 23:19:49 -0400 | [diff] [blame] | 1848 | if (!seat->pointer) |
Kristian Høgsberg | f4d2f23 | 2012-08-10 10:05:39 -0400 | [diff] [blame] | 1849 | return; |
| 1850 | |
| 1851 | listener = malloc(sizeof *listener); |
| 1852 | listener->notify = handle_pointer_focus; |
Kristian Høgsberg | e314875 | 2013-05-06 23:19:49 -0400 | [diff] [blame] | 1853 | wl_signal_add(&seat->pointer->focus_signal, listener); |
Kristian Høgsberg | f4d2f23 | 2012-08-10 10:05:39 -0400 | [diff] [blame] | 1854 | } |
| 1855 | |
| 1856 | static void |
Rafael Antognolli | e2a3455 | 2013-12-03 15:35:45 -0200 | [diff] [blame] | 1857 | xdg_surface_set_transient_for(struct wl_client *client, |
| 1858 | struct wl_resource *resource, |
| 1859 | struct wl_resource *parent_resource) |
Scott Moreau | ff1db4a | 2012-04-17 19:06:18 -0600 | [diff] [blame] | 1860 | { |
Jason Ekstrand | 651f00e | 2013-06-14 10:07:54 -0500 | [diff] [blame] | 1861 | struct shell_surface *shsurf = wl_resource_get_user_data(resource); |
Jasper St. Pierre | 8f180d4 | 2013-12-07 13:49:28 -0500 | [diff] [blame] | 1862 | struct weston_surface *parent; |
| 1863 | |
| 1864 | if (parent_resource) |
| 1865 | parent = wl_resource_get_user_data(parent_resource); |
| 1866 | else |
| 1867 | parent = NULL; |
Rafael Antognolli | e2a3455 | 2013-12-03 15:35:45 -0200 | [diff] [blame] | 1868 | |
| 1869 | shell_surface_set_parent(shsurf, parent); |
| 1870 | } |
| 1871 | |
| 1872 | static void |
| 1873 | surface_pong(struct shell_surface *shsurf, uint32_t serial) |
| 1874 | { |
Kristian Høgsberg | d56bd90 | 2012-06-05 09:58:51 -0400 | [diff] [blame] | 1875 | struct weston_compositor *ec = shsurf->surface->compositor; |
Rafael Antognolli | e2a3455 | 2013-12-03 15:35:45 -0200 | [diff] [blame] | 1876 | struct weston_seat *seat; |
Scott Moreau | ff1db4a | 2012-04-17 19:06:18 -0600 | [diff] [blame] | 1877 | |
Kristian Høgsberg | 92374e1 | 2012-08-11 22:39:12 -0400 | [diff] [blame] | 1878 | if (shsurf->ping_timer == NULL) |
| 1879 | /* Just ignore unsolicited pong. */ |
| 1880 | return; |
| 1881 | |
Scott Moreau | ff1db4a | 2012-04-17 19:06:18 -0600 | [diff] [blame] | 1882 | if (shsurf->ping_timer->serial == serial) { |
Scott Moreau | ff1db4a | 2012-04-17 19:06:18 -0600 | [diff] [blame] | 1883 | shsurf->unresponsive = 0; |
Hardening | eb1e130 | 2013-05-17 18:07:41 +0200 | [diff] [blame] | 1884 | wl_list_for_each(seat, &ec->seat_list, link) { |
| 1885 | if(seat->pointer) |
| 1886 | end_busy_cursor(shsurf, seat->pointer); |
| 1887 | } |
Scott Moreau | 9521d5e | 2012-04-19 13:06:17 -0600 | [diff] [blame] | 1888 | ping_timer_destroy(shsurf); |
Scott Moreau | ff1db4a | 2012-04-17 19:06:18 -0600 | [diff] [blame] | 1889 | } |
| 1890 | } |
| 1891 | |
Kristian Høgsberg | e7afd91 | 2012-05-02 09:47:44 -0400 | [diff] [blame] | 1892 | static void |
Rafael Antognolli | e2a3455 | 2013-12-03 15:35:45 -0200 | [diff] [blame] | 1893 | shell_surface_pong(struct wl_client *client, struct wl_resource *resource, |
| 1894 | uint32_t serial) |
| 1895 | { |
| 1896 | struct shell_surface *shsurf = wl_resource_get_user_data(resource); |
| 1897 | |
| 1898 | surface_pong(shsurf, serial); |
| 1899 | |
| 1900 | } |
| 1901 | |
| 1902 | static void |
Giulio Camuffo | 62942ad | 2013-09-11 18:20:47 +0200 | [diff] [blame] | 1903 | set_title(struct shell_surface *shsurf, const char *title) |
| 1904 | { |
| 1905 | free(shsurf->title); |
| 1906 | shsurf->title = strdup(title); |
| 1907 | } |
| 1908 | |
| 1909 | static void |
Kristian Høgsberg | e7afd91 | 2012-05-02 09:47:44 -0400 | [diff] [blame] | 1910 | shell_surface_set_title(struct wl_client *client, |
| 1911 | struct wl_resource *resource, const char *title) |
| 1912 | { |
Jason Ekstrand | 651f00e | 2013-06-14 10:07:54 -0500 | [diff] [blame] | 1913 | struct shell_surface *shsurf = wl_resource_get_user_data(resource); |
Kristian Høgsberg | e7afd91 | 2012-05-02 09:47:44 -0400 | [diff] [blame] | 1914 | |
Giulio Camuffo | 62942ad | 2013-09-11 18:20:47 +0200 | [diff] [blame] | 1915 | set_title(shsurf, title); |
Kristian Høgsberg | e7afd91 | 2012-05-02 09:47:44 -0400 | [diff] [blame] | 1916 | } |
| 1917 | |
| 1918 | static void |
| 1919 | shell_surface_set_class(struct wl_client *client, |
| 1920 | struct wl_resource *resource, const char *class) |
| 1921 | { |
Jason Ekstrand | 651f00e | 2013-06-14 10:07:54 -0500 | [diff] [blame] | 1922 | struct shell_surface *shsurf = wl_resource_get_user_data(resource); |
Kristian Høgsberg | e7afd91 | 2012-05-02 09:47:44 -0400 | [diff] [blame] | 1923 | |
| 1924 | free(shsurf->class); |
| 1925 | shsurf->class = strdup(class); |
| 1926 | } |
| 1927 | |
Alex Wu | 4539b08 | 2012-03-01 12:57:46 +0800 | [diff] [blame] | 1928 | static void |
Alexander Larsson | f82b6ca | 2013-05-28 16:23:39 +0200 | [diff] [blame] | 1929 | restore_output_mode(struct weston_output *output) |
| 1930 | { |
Hardening | 57388e4 | 2013-09-18 23:56:36 +0200 | [diff] [blame] | 1931 | if (output->current_mode != output->original_mode || |
| 1932 | (int32_t)output->current_scale != output->original_scale) |
Alexander Larsson | f82b6ca | 2013-05-28 16:23:39 +0200 | [diff] [blame] | 1933 | weston_output_switch_mode(output, |
Hardening | 57388e4 | 2013-09-18 23:56:36 +0200 | [diff] [blame] | 1934 | output->original_mode, |
| 1935 | output->original_scale, |
| 1936 | WESTON_MODE_SWITCH_RESTORE_NATIVE); |
Alexander Larsson | f82b6ca | 2013-05-28 16:23:39 +0200 | [diff] [blame] | 1937 | } |
| 1938 | |
| 1939 | static void |
| 1940 | restore_all_output_modes(struct weston_compositor *compositor) |
| 1941 | { |
| 1942 | struct weston_output *output; |
| 1943 | |
| 1944 | wl_list_for_each(output, &compositor->output_list, link) |
| 1945 | restore_output_mode(output); |
| 1946 | } |
| 1947 | |
Philip Withnall | becb77e | 2013-11-25 18:01:30 +0000 | [diff] [blame] | 1948 | static int |
| 1949 | get_output_panel_height(struct desktop_shell *shell, |
| 1950 | struct weston_output *output) |
| 1951 | { |
| 1952 | struct weston_view *view; |
| 1953 | int panel_height = 0; |
| 1954 | |
| 1955 | if (!output) |
| 1956 | return 0; |
| 1957 | |
| 1958 | wl_list_for_each(view, &shell->panel_layer.view_list, layer_link) { |
| 1959 | if (view->surface->output == output) { |
Jason Ekstrand | 918f2dd | 2013-12-02 21:01:53 -0600 | [diff] [blame] | 1960 | panel_height = view->surface->height; |
Philip Withnall | becb77e | 2013-11-25 18:01:30 +0000 | [diff] [blame] | 1961 | break; |
| 1962 | } |
| 1963 | } |
| 1964 | |
| 1965 | return panel_height; |
| 1966 | } |
| 1967 | |
Philip Withnall | 07926d9 | 2013-11-25 18:01:40 +0000 | [diff] [blame] | 1968 | /* The surface will be inserted into the list immediately after the link |
| 1969 | * returned by this function (i.e. will be stacked immediately above the |
| 1970 | * returned link). */ |
| 1971 | static struct wl_list * |
| 1972 | shell_surface_calculate_layer_link (struct shell_surface *shsurf) |
| 1973 | { |
| 1974 | struct workspace *ws; |
| 1975 | |
| 1976 | switch (shsurf->type) { |
Philip Withnall | da704d9 | 2013-11-25 18:01:46 +0000 | [diff] [blame] | 1977 | case SHELL_SURFACE_POPUP: { |
| 1978 | /* Popups should go at the front of the workspace of their |
| 1979 | * parent surface, rather than just in front of the parent. This |
| 1980 | * fixes the situation where there are two top-level windows: |
| 1981 | * - Above |
| 1982 | * - Below |
| 1983 | * and a pop-up menu is created for 'Below'. We want: |
| 1984 | * - Popup |
| 1985 | * - Above |
| 1986 | * - Below |
| 1987 | * not: |
| 1988 | * - Above |
| 1989 | * - Popup |
| 1990 | * - Below |
| 1991 | */ |
| 1992 | struct shell_surface *parent_shsurf; |
| 1993 | |
| 1994 | parent_shsurf = get_shell_surface(shsurf->parent); |
| 1995 | if (parent_shsurf != NULL) |
| 1996 | return shell_surface_calculate_layer_link(parent_shsurf); |
| 1997 | |
| 1998 | break; |
| 1999 | } |
| 2000 | |
Rafael Antognolli | 03b1659 | 2013-12-03 15:35:42 -0200 | [diff] [blame] | 2001 | case SHELL_SURFACE_TOPLEVEL: { |
Rafael Antognolli | ed207b4 | 2013-12-03 15:35:43 -0200 | [diff] [blame] | 2002 | if (shsurf->state.fullscreen) { |
Rafael Antognolli | 03b1659 | 2013-12-03 15:35:42 -0200 | [diff] [blame] | 2003 | return &shsurf->shell->fullscreen_layer.view_list; |
Rafael Antognolli | ed207b4 | 2013-12-03 15:35:43 -0200 | [diff] [blame] | 2004 | } else if (shsurf->parent) { |
| 2005 | /* Move the surface to its parent layer so that |
| 2006 | * surfaces which are transient for fullscreen surfaces |
| 2007 | * don't get hidden by the fullscreen surfaces. |
| 2008 | * However, unlike popups, transient surfaces are |
| 2009 | * stacked in front of their parent but not in front of |
| 2010 | * other surfaces of the same type. */ |
| 2011 | struct weston_view *parent; |
| 2012 | |
| 2013 | /* TODO: Handle a parent with multiple views */ |
| 2014 | parent = get_default_view(shsurf->parent); |
| 2015 | if (parent) |
| 2016 | return parent->layer_link.prev; |
| 2017 | } |
Rafael Antognolli | 03b1659 | 2013-12-03 15:35:42 -0200 | [diff] [blame] | 2018 | break; |
| 2019 | } |
Philip Withnall | 07926d9 | 2013-11-25 18:01:40 +0000 | [diff] [blame] | 2020 | |
| 2021 | case SHELL_SURFACE_XWAYLAND: |
Kristian Høgsberg | 4804a30 | 2013-12-05 22:43:03 -0800 | [diff] [blame] | 2022 | return &shsurf->shell->fullscreen_layer.view_list; |
| 2023 | |
Philip Withnall | 07926d9 | 2013-11-25 18:01:40 +0000 | [diff] [blame] | 2024 | case SHELL_SURFACE_NONE: |
| 2025 | default: |
| 2026 | /* Go to the fallback, below. */ |
| 2027 | break; |
| 2028 | } |
| 2029 | |
| 2030 | /* Move the surface to a normal workspace layer so that surfaces |
| 2031 | * which were previously fullscreen or transient are no longer |
| 2032 | * rendered on top. */ |
| 2033 | ws = get_current_workspace(shsurf->shell); |
| 2034 | return &ws->layer.view_list; |
| 2035 | } |
| 2036 | |
Philip Withnall | 648a4dd | 2013-11-25 18:01:44 +0000 | [diff] [blame] | 2037 | static void |
| 2038 | shell_surface_update_child_surface_layers (struct shell_surface *shsurf) |
| 2039 | { |
| 2040 | struct shell_surface *child; |
| 2041 | |
| 2042 | /* Move the child layers to the same workspace as shsurf. They will be |
| 2043 | * stacked above shsurf. */ |
| 2044 | wl_list_for_each_reverse(child, &shsurf->children_list, children_link) { |
| 2045 | if (shsurf->view->layer_link.prev != &child->view->layer_link) { |
| 2046 | weston_view_geometry_dirty(child->view); |
| 2047 | wl_list_remove(&child->view->layer_link); |
| 2048 | wl_list_insert(shsurf->view->layer_link.prev, |
| 2049 | &child->view->layer_link); |
| 2050 | weston_view_geometry_dirty(child->view); |
| 2051 | weston_surface_damage(child->surface); |
| 2052 | |
| 2053 | /* Recurse. We don’t expect this to recurse very far (if |
| 2054 | * at all) because that would imply we have transient |
| 2055 | * (or popup) children of transient surfaces, which |
| 2056 | * would be unusual. */ |
| 2057 | shell_surface_update_child_surface_layers(child); |
| 2058 | } |
| 2059 | } |
| 2060 | } |
| 2061 | |
Philip Withnall | e1d75ae | 2013-11-25 18:01:41 +0000 | [diff] [blame] | 2062 | /* 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] | 2063 | * geometry to ensure the changes are redrawn. |
| 2064 | * |
| 2065 | * If any child surfaces exist and are mapped, ensure they’re in the same layer |
| 2066 | * as this surface. */ |
Philip Withnall | e1d75ae | 2013-11-25 18:01:41 +0000 | [diff] [blame] | 2067 | static void |
| 2068 | shell_surface_update_layer(struct shell_surface *shsurf) |
| 2069 | { |
| 2070 | struct wl_list *new_layer_link; |
| 2071 | |
| 2072 | new_layer_link = shell_surface_calculate_layer_link(shsurf); |
| 2073 | |
| 2074 | if (new_layer_link == &shsurf->view->layer_link) |
| 2075 | return; |
| 2076 | |
| 2077 | weston_view_geometry_dirty(shsurf->view); |
| 2078 | wl_list_remove(&shsurf->view->layer_link); |
| 2079 | wl_list_insert(new_layer_link, &shsurf->view->layer_link); |
| 2080 | weston_view_geometry_dirty(shsurf->view); |
| 2081 | weston_surface_damage(shsurf->surface); |
Philip Withnall | 648a4dd | 2013-11-25 18:01:44 +0000 | [diff] [blame] | 2082 | |
| 2083 | shell_surface_update_child_surface_layers(shsurf); |
Philip Withnall | e1d75ae | 2013-11-25 18:01:41 +0000 | [diff] [blame] | 2084 | } |
| 2085 | |
Alexander Larsson | f82b6ca | 2013-05-28 16:23:39 +0200 | [diff] [blame] | 2086 | static void |
Philip Withnall | dc4332f | 2013-11-25 18:01:38 +0000 | [diff] [blame] | 2087 | shell_surface_set_parent(struct shell_surface *shsurf, |
| 2088 | struct weston_surface *parent) |
| 2089 | { |
| 2090 | shsurf->parent = parent; |
Philip Withnall | 648a4dd | 2013-11-25 18:01:44 +0000 | [diff] [blame] | 2091 | |
| 2092 | wl_list_remove(&shsurf->children_link); |
| 2093 | wl_list_init(&shsurf->children_link); |
| 2094 | |
| 2095 | /* Insert into the parent surface’s child list. */ |
| 2096 | if (parent != NULL) { |
| 2097 | struct shell_surface *parent_shsurf = get_shell_surface(parent); |
| 2098 | if (parent_shsurf != NULL) |
| 2099 | wl_list_insert(&parent_shsurf->children_list, |
| 2100 | &shsurf->children_link); |
| 2101 | } |
Philip Withnall | dc4332f | 2013-11-25 18:01:38 +0000 | [diff] [blame] | 2102 | } |
| 2103 | |
| 2104 | static void |
Philip Withnall | 352e7ed | 2013-11-25 18:01:35 +0000 | [diff] [blame] | 2105 | shell_surface_set_output(struct shell_surface *shsurf, |
| 2106 | struct weston_output *output) |
| 2107 | { |
| 2108 | struct weston_surface *es = shsurf->surface; |
| 2109 | |
| 2110 | /* get the default output, if the client set it as NULL |
| 2111 | check whether the ouput is available */ |
| 2112 | if (output) |
| 2113 | shsurf->output = output; |
| 2114 | else if (es->output) |
| 2115 | shsurf->output = es->output; |
| 2116 | else |
| 2117 | shsurf->output = get_default_output(es->compositor); |
| 2118 | } |
| 2119 | |
| 2120 | static void |
Rafael Antognolli | 03b1659 | 2013-12-03 15:35:42 -0200 | [diff] [blame] | 2121 | surface_clear_next_states(struct shell_surface *shsurf) |
| 2122 | { |
| 2123 | shsurf->next_state.maximized = false; |
| 2124 | shsurf->next_state.fullscreen = false; |
| 2125 | |
| 2126 | if ((shsurf->next_state.maximized != shsurf->state.maximized) || |
| 2127 | (shsurf->next_state.fullscreen != shsurf->state.fullscreen)) |
| 2128 | shsurf->state_changed = true; |
| 2129 | } |
| 2130 | |
| 2131 | static void |
Philip Withnall | becb77e | 2013-11-25 18:01:30 +0000 | [diff] [blame] | 2132 | set_toplevel(struct shell_surface *shsurf) |
| 2133 | { |
Kristian Høgsberg | 41fbf6f | 2013-12-05 22:31:25 -0800 | [diff] [blame] | 2134 | shell_surface_set_parent(shsurf, NULL); |
| 2135 | surface_clear_next_states(shsurf); |
Kristian Høgsberg | c8f8dd8 | 2013-12-05 23:20:33 -0800 | [diff] [blame] | 2136 | shsurf->type = SHELL_SURFACE_TOPLEVEL; |
Philip Withnall | 648a4dd | 2013-11-25 18:01:44 +0000 | [diff] [blame] | 2137 | |
| 2138 | /* The layer_link is updated in set_surface_type(), |
| 2139 | * called from configure. */ |
Philip Withnall | becb77e | 2013-11-25 18:01:30 +0000 | [diff] [blame] | 2140 | } |
| 2141 | |
| 2142 | static void |
| 2143 | shell_surface_set_toplevel(struct wl_client *client, |
| 2144 | struct wl_resource *resource) |
| 2145 | { |
| 2146 | struct shell_surface *surface = wl_resource_get_user_data(resource); |
| 2147 | |
| 2148 | set_toplevel(surface); |
| 2149 | } |
| 2150 | |
| 2151 | static void |
| 2152 | set_transient(struct shell_surface *shsurf, |
| 2153 | struct weston_surface *parent, int x, int y, uint32_t flags) |
| 2154 | { |
Philip Withnall | dc4332f | 2013-11-25 18:01:38 +0000 | [diff] [blame] | 2155 | assert(parent != NULL); |
| 2156 | |
Philip Withnall | becb77e | 2013-11-25 18:01:30 +0000 | [diff] [blame] | 2157 | shsurf->transient.x = x; |
| 2158 | shsurf->transient.y = y; |
| 2159 | shsurf->transient.flags = flags; |
Philip Withnall | dc4332f | 2013-11-25 18:01:38 +0000 | [diff] [blame] | 2160 | |
Rafael Antognolli | ed207b4 | 2013-12-03 15:35:43 -0200 | [diff] [blame] | 2161 | shsurf->next_state.relative = true; |
Kristian Høgsberg | c8f8dd8 | 2013-12-05 23:20:33 -0800 | [diff] [blame] | 2162 | shsurf->type = SHELL_SURFACE_TOPLEVEL; |
Philip Withnall | 648a4dd | 2013-11-25 18:01:44 +0000 | [diff] [blame] | 2163 | |
| 2164 | /* The layer_link is updated in set_surface_type(), |
| 2165 | * called from configure. */ |
Philip Withnall | becb77e | 2013-11-25 18:01:30 +0000 | [diff] [blame] | 2166 | } |
| 2167 | |
| 2168 | static void |
| 2169 | shell_surface_set_transient(struct wl_client *client, |
| 2170 | struct wl_resource *resource, |
| 2171 | struct wl_resource *parent_resource, |
| 2172 | int x, int y, uint32_t flags) |
| 2173 | { |
| 2174 | struct shell_surface *shsurf = wl_resource_get_user_data(resource); |
| 2175 | struct weston_surface *parent = |
| 2176 | wl_resource_get_user_data(parent_resource); |
| 2177 | |
Rafael Antognolli | 4b99a40 | 2013-12-03 15:35:44 -0200 | [diff] [blame] | 2178 | shell_surface_set_parent(shsurf, parent); |
| 2179 | |
Rafael Antognolli | 03b1659 | 2013-12-03 15:35:42 -0200 | [diff] [blame] | 2180 | surface_clear_next_states(shsurf); |
Philip Withnall | becb77e | 2013-11-25 18:01:30 +0000 | [diff] [blame] | 2181 | set_transient(shsurf, parent, x, y, flags); |
| 2182 | } |
| 2183 | |
| 2184 | static void |
| 2185 | set_fullscreen(struct shell_surface *shsurf, |
| 2186 | uint32_t method, |
| 2187 | uint32_t framerate, |
| 2188 | struct weston_output *output) |
| 2189 | { |
Philip Withnall | 352e7ed | 2013-11-25 18:01:35 +0000 | [diff] [blame] | 2190 | shell_surface_set_output(shsurf, output); |
Philip Withnall | becb77e | 2013-11-25 18:01:30 +0000 | [diff] [blame] | 2191 | |
| 2192 | shsurf->fullscreen_output = shsurf->output; |
| 2193 | shsurf->fullscreen.type = method; |
| 2194 | shsurf->fullscreen.framerate = framerate; |
Philip Withnall | dc4332f | 2013-11-25 18:01:38 +0000 | [diff] [blame] | 2195 | |
Kristian Høgsberg | e960b3f | 2013-12-05 22:04:42 -0800 | [diff] [blame] | 2196 | shsurf->next_state.fullscreen = true; |
| 2197 | shsurf->state_changed = true; |
Kristian Høgsberg | c8f8dd8 | 2013-12-05 23:20:33 -0800 | [diff] [blame] | 2198 | shsurf->type = SHELL_SURFACE_TOPLEVEL; |
Philip Withnall | becb77e | 2013-11-25 18:01:30 +0000 | [diff] [blame] | 2199 | |
| 2200 | shsurf->client->send_configure(shsurf->surface, 0, |
| 2201 | shsurf->output->width, |
| 2202 | shsurf->output->height); |
Philip Withnall | 648a4dd | 2013-11-25 18:01:44 +0000 | [diff] [blame] | 2203 | |
| 2204 | /* The layer_link is updated in set_surface_type(), |
| 2205 | * called from configure. */ |
Philip Withnall | becb77e | 2013-11-25 18:01:30 +0000 | [diff] [blame] | 2206 | } |
| 2207 | |
| 2208 | static void |
| 2209 | unset_fullscreen(struct shell_surface *shsurf) |
Alex Wu | 4539b08 | 2012-03-01 12:57:46 +0800 | [diff] [blame] | 2210 | { |
Philip Withnall | f85fe84 | 2013-11-25 18:01:37 +0000 | [diff] [blame] | 2211 | /* Unset the fullscreen output, driver configuration and transforms. */ |
Alex Wu | bd3354b | 2012-04-17 17:20:49 +0800 | [diff] [blame] | 2212 | if (shsurf->fullscreen.type == WL_SHELL_SURFACE_FULLSCREEN_METHOD_DRIVER && |
| 2213 | shell_surface_is_top_fullscreen(shsurf)) { |
Alexander Larsson | f82b6ca | 2013-05-28 16:23:39 +0200 | [diff] [blame] | 2214 | restore_output_mode(shsurf->fullscreen_output); |
Alex Wu | bd3354b | 2012-04-17 17:20:49 +0800 | [diff] [blame] | 2215 | } |
Philip Withnall | f85fe84 | 2013-11-25 18:01:37 +0000 | [diff] [blame] | 2216 | shsurf->fullscreen_output = NULL; |
| 2217 | |
Alex Wu | 4539b08 | 2012-03-01 12:57:46 +0800 | [diff] [blame] | 2218 | shsurf->fullscreen.type = WL_SHELL_SURFACE_FULLSCREEN_METHOD_DEFAULT; |
| 2219 | shsurf->fullscreen.framerate = 0; |
Philip Withnall | f85fe84 | 2013-11-25 18:01:37 +0000 | [diff] [blame] | 2220 | |
Alex Wu | 4539b08 | 2012-03-01 12:57:46 +0800 | [diff] [blame] | 2221 | wl_list_remove(&shsurf->fullscreen.transform.link); |
| 2222 | wl_list_init(&shsurf->fullscreen.transform.link); |
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 | if (shsurf->fullscreen.black_view) |
| 2225 | weston_surface_destroy(shsurf->fullscreen.black_view->surface); |
| 2226 | shsurf->fullscreen.black_view = NULL; |
Philip Withnall | f85fe84 | 2013-11-25 18:01:37 +0000 | [diff] [blame] | 2227 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 2228 | weston_view_set_position(shsurf->view, |
| 2229 | shsurf->saved_x, shsurf->saved_y); |
Alex Wu | 7bcb8bd | 2012-04-27 09:07:24 +0800 | [diff] [blame] | 2230 | if (shsurf->saved_rotation_valid) { |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 2231 | wl_list_insert(&shsurf->view->geometry.transformation_list, |
Philip Withnall | becb77e | 2013-11-25 18:01:30 +0000 | [diff] [blame] | 2232 | &shsurf->rotation.transform.link); |
Alex Wu | 7bcb8bd | 2012-04-27 09:07:24 +0800 | [diff] [blame] | 2233 | shsurf->saved_rotation_valid = false; |
| 2234 | } |
Rafal Mielniczuk | 3e3862c | 2012-10-07 20:25:36 +0200 | [diff] [blame] | 2235 | |
Philip Withnall | e1d75ae | 2013-11-25 18:01:41 +0000 | [diff] [blame] | 2236 | /* Layer is updated in set_surface_type(). */ |
Alex Wu | 4539b08 | 2012-03-01 12:57:46 +0800 | [diff] [blame] | 2237 | } |
| 2238 | |
Rafal Mielniczuk | fffdcdd | 2013-03-11 19:26:54 +0100 | [diff] [blame] | 2239 | static void |
Philip Withnall | becb77e | 2013-11-25 18:01:30 +0000 | [diff] [blame] | 2240 | shell_surface_set_fullscreen(struct wl_client *client, |
| 2241 | struct wl_resource *resource, |
| 2242 | uint32_t method, |
| 2243 | uint32_t framerate, |
| 2244 | struct wl_resource *output_resource) |
| 2245 | { |
| 2246 | struct shell_surface *shsurf = wl_resource_get_user_data(resource); |
| 2247 | struct weston_output *output; |
| 2248 | |
| 2249 | if (output_resource) |
| 2250 | output = wl_resource_get_user_data(output_resource); |
| 2251 | else |
| 2252 | output = NULL; |
| 2253 | |
Rafael Antognolli | 4b99a40 | 2013-12-03 15:35:44 -0200 | [diff] [blame] | 2254 | shell_surface_set_parent(shsurf, NULL); |
| 2255 | |
Rafael Antognolli | 03b1659 | 2013-12-03 15:35:42 -0200 | [diff] [blame] | 2256 | surface_clear_next_states(shsurf); |
Philip Withnall | becb77e | 2013-11-25 18:01:30 +0000 | [diff] [blame] | 2257 | set_fullscreen(shsurf, method, framerate, output); |
| 2258 | } |
| 2259 | |
| 2260 | static void |
| 2261 | set_popup(struct shell_surface *shsurf, |
| 2262 | struct weston_surface *parent, |
| 2263 | struct weston_seat *seat, |
| 2264 | uint32_t serial, |
| 2265 | int32_t x, |
| 2266 | int32_t y) |
| 2267 | { |
Philip Withnall | dc4332f | 2013-11-25 18:01:38 +0000 | [diff] [blame] | 2268 | assert(parent != NULL); |
| 2269 | |
Philip Withnall | becb77e | 2013-11-25 18:01:30 +0000 | [diff] [blame] | 2270 | shsurf->popup.shseat = get_shell_seat(seat); |
| 2271 | shsurf->popup.serial = serial; |
| 2272 | shsurf->popup.x = x; |
| 2273 | shsurf->popup.y = y; |
Philip Withnall | dc4332f | 2013-11-25 18:01:38 +0000 | [diff] [blame] | 2274 | |
Kristian Høgsberg | c8f8dd8 | 2013-12-05 23:20:33 -0800 | [diff] [blame] | 2275 | shsurf->type = SHELL_SURFACE_POPUP; |
Philip Withnall | becb77e | 2013-11-25 18:01:30 +0000 | [diff] [blame] | 2276 | } |
| 2277 | |
| 2278 | static void |
| 2279 | shell_surface_set_popup(struct wl_client *client, |
| 2280 | struct wl_resource *resource, |
| 2281 | struct wl_resource *seat_resource, |
| 2282 | uint32_t serial, |
| 2283 | struct wl_resource *parent_resource, |
| 2284 | int32_t x, int32_t y, uint32_t flags) |
| 2285 | { |
| 2286 | struct shell_surface *shsurf = wl_resource_get_user_data(resource); |
Rafael Antognolli | 4b99a40 | 2013-12-03 15:35:44 -0200 | [diff] [blame] | 2287 | struct weston_surface *parent = |
| 2288 | wl_resource_get_user_data(parent_resource); |
| 2289 | |
| 2290 | shell_surface_set_parent(shsurf, parent); |
Philip Withnall | becb77e | 2013-11-25 18:01:30 +0000 | [diff] [blame] | 2291 | |
Rafael Antognolli | 03b1659 | 2013-12-03 15:35:42 -0200 | [diff] [blame] | 2292 | surface_clear_next_states(shsurf); |
Philip Withnall | becb77e | 2013-11-25 18:01:30 +0000 | [diff] [blame] | 2293 | set_popup(shsurf, |
Rafael Antognolli | 4b99a40 | 2013-12-03 15:35:44 -0200 | [diff] [blame] | 2294 | parent, |
Philip Withnall | becb77e | 2013-11-25 18:01:30 +0000 | [diff] [blame] | 2295 | wl_resource_get_user_data(seat_resource), |
| 2296 | serial, x, y); |
| 2297 | } |
| 2298 | |
| 2299 | static void |
| 2300 | set_maximized(struct shell_surface *shsurf, |
| 2301 | struct weston_output *output) |
| 2302 | { |
| 2303 | struct desktop_shell *shell; |
| 2304 | uint32_t edges = 0, panel_height = 0; |
Philip Withnall | becb77e | 2013-11-25 18:01:30 +0000 | [diff] [blame] | 2305 | |
Philip Withnall | 352e7ed | 2013-11-25 18:01:35 +0000 | [diff] [blame] | 2306 | shell_surface_set_output(shsurf, output); |
Philip Withnall | becb77e | 2013-11-25 18:01:30 +0000 | [diff] [blame] | 2307 | |
| 2308 | shell = shell_surface_get_shell(shsurf); |
| 2309 | panel_height = get_output_panel_height(shell, shsurf->output); |
| 2310 | edges = WL_SHELL_SURFACE_RESIZE_TOP | WL_SHELL_SURFACE_RESIZE_LEFT; |
| 2311 | |
| 2312 | shsurf->client->send_configure(shsurf->surface, edges, |
| 2313 | shsurf->output->width, |
| 2314 | shsurf->output->height - panel_height); |
| 2315 | |
Kristian Høgsberg | c2745b1 | 2013-12-05 22:00:40 -0800 | [diff] [blame] | 2316 | shsurf->next_state.maximized = true; |
| 2317 | shsurf->state_changed = true; |
Kristian Høgsberg | c8f8dd8 | 2013-12-05 23:20:33 -0800 | [diff] [blame] | 2318 | shsurf->type = SHELL_SURFACE_TOPLEVEL; |
Philip Withnall | becb77e | 2013-11-25 18:01:30 +0000 | [diff] [blame] | 2319 | } |
| 2320 | |
| 2321 | static void |
| 2322 | unset_maximized(struct shell_surface *shsurf) |
Rafal Mielniczuk | fffdcdd | 2013-03-11 19:26:54 +0100 | [diff] [blame] | 2323 | { |
Rafal Mielniczuk | fffdcdd | 2013-03-11 19:26:54 +0100 | [diff] [blame] | 2324 | /* undo all maximized things here */ |
| 2325 | shsurf->output = get_default_output(shsurf->surface->compositor); |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 2326 | weston_view_set_position(shsurf->view, |
| 2327 | shsurf->saved_x, |
| 2328 | shsurf->saved_y); |
Rafal Mielniczuk | fffdcdd | 2013-03-11 19:26:54 +0100 | [diff] [blame] | 2329 | |
| 2330 | if (shsurf->saved_rotation_valid) { |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 2331 | wl_list_insert(&shsurf->view->geometry.transformation_list, |
| 2332 | &shsurf->rotation.transform.link); |
Rafal Mielniczuk | fffdcdd | 2013-03-11 19:26:54 +0100 | [diff] [blame] | 2333 | shsurf->saved_rotation_valid = false; |
| 2334 | } |
| 2335 | |
Philip Withnall | e1d75ae | 2013-11-25 18:01:41 +0000 | [diff] [blame] | 2336 | /* Layer is updated in set_surface_type(). */ |
Rafal Mielniczuk | fffdcdd | 2013-03-11 19:26:54 +0100 | [diff] [blame] | 2337 | } |
| 2338 | |
Philip Withnall | becb77e | 2013-11-25 18:01:30 +0000 | [diff] [blame] | 2339 | static void |
| 2340 | shell_surface_set_maximized(struct wl_client *client, |
| 2341 | struct wl_resource *resource, |
| 2342 | struct wl_resource *output_resource) |
| 2343 | { |
| 2344 | struct shell_surface *shsurf = wl_resource_get_user_data(resource); |
| 2345 | struct weston_output *output; |
| 2346 | |
| 2347 | if (output_resource) |
| 2348 | output = wl_resource_get_user_data(output_resource); |
| 2349 | else |
| 2350 | output = NULL; |
| 2351 | |
Rafael Antognolli | 4b99a40 | 2013-12-03 15:35:44 -0200 | [diff] [blame] | 2352 | shell_surface_set_parent(shsurf, NULL); |
| 2353 | |
Rafael Antognolli | 03b1659 | 2013-12-03 15:35:42 -0200 | [diff] [blame] | 2354 | surface_clear_next_states(shsurf); |
Philip Withnall | becb77e | 2013-11-25 18:01:30 +0000 | [diff] [blame] | 2355 | set_maximized(shsurf, output); |
| 2356 | } |
| 2357 | |
Philip Withnall | e1d75ae | 2013-11-25 18:01:41 +0000 | [diff] [blame] | 2358 | /* This is only ever called from set_surface_type(), so there’s no need to |
| 2359 | * update layer_links here, since they’ll be updated when we return. */ |
Pekka Paalanen | 9826223 | 2011-12-01 10:42:22 +0200 | [diff] [blame] | 2360 | static int |
Philip Withnall | becb77e | 2013-11-25 18:01:30 +0000 | [diff] [blame] | 2361 | reset_surface_type(struct shell_surface *surface) |
Pekka Paalanen | 9826223 | 2011-12-01 10:42:22 +0200 | [diff] [blame] | 2362 | { |
Rafael Antognolli | 03b1659 | 2013-12-03 15:35:42 -0200 | [diff] [blame] | 2363 | if (surface->state.fullscreen) |
Philip Withnall | becb77e | 2013-11-25 18:01:30 +0000 | [diff] [blame] | 2364 | unset_fullscreen(surface); |
Rafael Antognolli | 03b1659 | 2013-12-03 15:35:42 -0200 | [diff] [blame] | 2365 | if (surface->state.maximized) |
Philip Withnall | becb77e | 2013-11-25 18:01:30 +0000 | [diff] [blame] | 2366 | unset_maximized(surface); |
Pekka Paalanen | 9826223 | 2011-12-01 10:42:22 +0200 | [diff] [blame] | 2367 | |
Pekka Paalanen | 9826223 | 2011-12-01 10:42:22 +0200 | [diff] [blame] | 2368 | return 0; |
| 2369 | } |
| 2370 | |
Kristian Høgsberg | 4cca349 | 2011-01-18 07:53:49 -0500 | [diff] [blame] | 2371 | static void |
Rafael Antognolli | 03b1659 | 2013-12-03 15:35:42 -0200 | [diff] [blame] | 2372 | set_full_output(struct shell_surface *shsurf) |
| 2373 | { |
| 2374 | shsurf->saved_x = shsurf->view->geometry.x; |
| 2375 | shsurf->saved_y = shsurf->view->geometry.y; |
Rafael Antognolli | 3c4e3f7 | 2013-12-03 15:35:46 -0200 | [diff] [blame] | 2376 | shsurf->saved_width = shsurf->surface->width; |
| 2377 | shsurf->saved_height = shsurf->surface->height; |
| 2378 | shsurf->saved_size_valid = true; |
Rafael Antognolli | 03b1659 | 2013-12-03 15:35:42 -0200 | [diff] [blame] | 2379 | shsurf->saved_position_valid = true; |
| 2380 | |
| 2381 | if (!wl_list_empty(&shsurf->rotation.transform.link)) { |
| 2382 | wl_list_remove(&shsurf->rotation.transform.link); |
| 2383 | wl_list_init(&shsurf->rotation.transform.link); |
| 2384 | weston_view_geometry_dirty(shsurf->view); |
| 2385 | shsurf->saved_rotation_valid = true; |
| 2386 | } |
| 2387 | } |
| 2388 | |
| 2389 | static void |
Kristian Høgsberg | 7f366e7 | 2012-04-27 17:20:01 -0400 | [diff] [blame] | 2390 | set_surface_type(struct shell_surface *shsurf) |
| 2391 | { |
Kristian Høgsberg | 8150b19 | 2012-06-27 10:22:58 -0400 | [diff] [blame] | 2392 | struct weston_surface *pes = shsurf->parent; |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 2393 | struct weston_view *pev = get_default_view(pes); |
Kristian Høgsberg | 7f366e7 | 2012-04-27 17:20:01 -0400 | [diff] [blame] | 2394 | |
Philip Withnall | becb77e | 2013-11-25 18:01:30 +0000 | [diff] [blame] | 2395 | reset_surface_type(shsurf); |
Kristian Høgsberg | 7f366e7 | 2012-04-27 17:20:01 -0400 | [diff] [blame] | 2396 | |
Rafael Antognolli | 03b1659 | 2013-12-03 15:35:42 -0200 | [diff] [blame] | 2397 | shsurf->state = shsurf->next_state; |
Rafael Antognolli | 03b1659 | 2013-12-03 15:35:42 -0200 | [diff] [blame] | 2398 | shsurf->state_changed = false; |
Kristian Høgsberg | 7f366e7 | 2012-04-27 17:20:01 -0400 | [diff] [blame] | 2399 | |
| 2400 | switch (shsurf->type) { |
| 2401 | case SHELL_SURFACE_TOPLEVEL: |
Rafael Antognolli | ed207b4 | 2013-12-03 15:35:43 -0200 | [diff] [blame] | 2402 | if (shsurf->state.maximized || shsurf->state.fullscreen) { |
Rafael Antognolli | 03b1659 | 2013-12-03 15:35:42 -0200 | [diff] [blame] | 2403 | set_full_output(shsurf); |
Rafael Antognolli | ed207b4 | 2013-12-03 15:35:43 -0200 | [diff] [blame] | 2404 | } else if (shsurf->state.relative && pev) { |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 2405 | weston_view_set_position(shsurf->view, |
| 2406 | pev->geometry.x + shsurf->transient.x, |
| 2407 | pev->geometry.y + shsurf->transient.y); |
Rafael Antognolli | ed207b4 | 2013-12-03 15:35:43 -0200 | [diff] [blame] | 2408 | } |
Rafael Antognolli | 44a3162 | 2013-12-04 18:37:16 -0200 | [diff] [blame] | 2409 | break; |
Kristian Høgsberg | 7f366e7 | 2012-04-27 17:20:01 -0400 | [diff] [blame] | 2410 | |
Tiago Vignatti | fb2adba | 2013-06-12 15:43:21 -0300 | [diff] [blame] | 2411 | case SHELL_SURFACE_XWAYLAND: |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 2412 | weston_view_set_position(shsurf->view, shsurf->transient.x, |
| 2413 | shsurf->transient.y); |
Tiago Vignatti | fb2adba | 2013-06-12 15:43:21 -0300 | [diff] [blame] | 2414 | break; |
| 2415 | |
Philip Withnall | 0f640e2 | 2013-11-25 18:01:31 +0000 | [diff] [blame] | 2416 | case SHELL_SURFACE_POPUP: |
| 2417 | case SHELL_SURFACE_NONE: |
Kristian Høgsberg | 7f366e7 | 2012-04-27 17:20:01 -0400 | [diff] [blame] | 2418 | default: |
| 2419 | break; |
| 2420 | } |
Philip Withnall | e1d75ae | 2013-11-25 18:01:41 +0000 | [diff] [blame] | 2421 | |
| 2422 | /* Update the surface’s layer. */ |
| 2423 | shell_surface_update_layer(shsurf); |
Kristian Høgsberg | 7f366e7 | 2012-04-27 17:20:01 -0400 | [diff] [blame] | 2424 | } |
| 2425 | |
Tiago Vignatti | be14326 | 2012-04-16 17:31:41 +0300 | [diff] [blame] | 2426 | static struct desktop_shell * |
Juan Zhao | 96879df | 2012-02-07 08:45:41 +0800 | [diff] [blame] | 2427 | shell_surface_get_shell(struct shell_surface *shsurf) |
Pekka Paalanen | af0e34c | 2011-12-02 10:59:17 +0200 | [diff] [blame] | 2428 | { |
Kristian Høgsberg | 02e79dc | 2012-04-12 09:55:26 -0400 | [diff] [blame] | 2429 | return shsurf->shell; |
Juan Zhao | 96879df | 2012-02-07 08:45:41 +0800 | [diff] [blame] | 2430 | } |
| 2431 | |
Alex Wu | 2185843 | 2012-04-01 20:13:08 +0800 | [diff] [blame] | 2432 | static void |
Jason Ekstrand | 918f2dd | 2013-12-02 21:01:53 -0600 | [diff] [blame] | 2433 | 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] | 2434 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 2435 | static struct weston_view * |
Alex Wu | 4539b08 | 2012-03-01 12:57:46 +0800 | [diff] [blame] | 2436 | create_black_surface(struct weston_compositor *ec, |
Alex Wu | 2185843 | 2012-04-01 20:13:08 +0800 | [diff] [blame] | 2437 | struct weston_surface *fs_surface, |
John Kåre Alsaker | 490d02a | 2012-09-30 02:57:21 +0200 | [diff] [blame] | 2438 | float x, float y, int w, int h) |
Alex Wu | 4539b08 | 2012-03-01 12:57:46 +0800 | [diff] [blame] | 2439 | { |
| 2440 | struct weston_surface *surface = NULL; |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 2441 | struct weston_view *view; |
Alex Wu | 4539b08 | 2012-03-01 12:57:46 +0800 | [diff] [blame] | 2442 | |
| 2443 | surface = weston_surface_create(ec); |
| 2444 | if (surface == NULL) { |
Martin Minarik | 6d11836 | 2012-06-07 18:01:59 +0200 | [diff] [blame] | 2445 | weston_log("no memory\n"); |
Alex Wu | 4539b08 | 2012-03-01 12:57:46 +0800 | [diff] [blame] | 2446 | return NULL; |
| 2447 | } |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 2448 | view = weston_view_create(surface); |
| 2449 | if (surface == NULL) { |
| 2450 | weston_log("no memory\n"); |
| 2451 | weston_surface_destroy(surface); |
| 2452 | return NULL; |
| 2453 | } |
Alex Wu | 4539b08 | 2012-03-01 12:57:46 +0800 | [diff] [blame] | 2454 | |
Alex Wu | 2185843 | 2012-04-01 20:13:08 +0800 | [diff] [blame] | 2455 | surface->configure = black_surface_configure; |
Giulio Camuffo | 7fe01b1 | 2013-03-28 18:02:42 +0100 | [diff] [blame] | 2456 | surface->configure_private = fs_surface; |
Alex Wu | 4539b08 | 2012-03-01 12:57:46 +0800 | [diff] [blame] | 2457 | weston_surface_set_color(surface, 0.0, 0.0, 0.0, 1); |
Pekka Paalanen | 71f6f3b | 2012-10-10 12:49:26 +0300 | [diff] [blame] | 2458 | pixman_region32_fini(&surface->opaque); |
Kristian Høgsberg | 61f00f5 | 2012-08-03 16:31:36 -0400 | [diff] [blame] | 2459 | pixman_region32_init_rect(&surface->opaque, 0, 0, w, h); |
Jonas Ådahl | 33619a4 | 2013-01-15 21:25:55 +0100 | [diff] [blame] | 2460 | pixman_region32_fini(&surface->input); |
| 2461 | pixman_region32_init_rect(&surface->input, 0, 0, w, h); |
Jason Ekstrand | 918f2dd | 2013-12-02 21:01:53 -0600 | [diff] [blame] | 2462 | |
Xiong Zhang | becf5a3 | 2013-11-29 11:18:14 +0800 | [diff] [blame] | 2463 | surface->width = w; |
| 2464 | surface->height = h; |
Jason Ekstrand | 918f2dd | 2013-12-02 21:01:53 -0600 | [diff] [blame] | 2465 | weston_view_set_position(view, x, y); |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 2466 | |
| 2467 | return view; |
Alex Wu | 4539b08 | 2012-03-01 12:57:46 +0800 | [diff] [blame] | 2468 | } |
| 2469 | |
Philip Withnall | ed8f1a9 | 2013-11-25 18:01:43 +0000 | [diff] [blame] | 2470 | static void |
| 2471 | shell_ensure_fullscreen_black_view(struct shell_surface *shsurf) |
| 2472 | { |
| 2473 | struct weston_output *output = shsurf->fullscreen_output; |
| 2474 | |
Rafael Antognolli | 03b1659 | 2013-12-03 15:35:42 -0200 | [diff] [blame] | 2475 | assert(shsurf->state.fullscreen); |
Philip Withnall | ed8f1a9 | 2013-11-25 18:01:43 +0000 | [diff] [blame] | 2476 | |
| 2477 | if (!shsurf->fullscreen.black_view) |
| 2478 | shsurf->fullscreen.black_view = |
| 2479 | create_black_surface(shsurf->surface->compositor, |
| 2480 | shsurf->surface, |
| 2481 | output->x, output->y, |
| 2482 | output->width, |
| 2483 | output->height); |
| 2484 | |
| 2485 | weston_view_geometry_dirty(shsurf->fullscreen.black_view); |
| 2486 | wl_list_remove(&shsurf->fullscreen.black_view->layer_link); |
| 2487 | wl_list_insert(&shsurf->view->layer_link, |
| 2488 | &shsurf->fullscreen.black_view->layer_link); |
| 2489 | weston_view_geometry_dirty(shsurf->fullscreen.black_view); |
| 2490 | weston_surface_damage(shsurf->surface); |
| 2491 | } |
| 2492 | |
Alex Wu | 4539b08 | 2012-03-01 12:57:46 +0800 | [diff] [blame] | 2493 | /* Create black surface and append it to the associated fullscreen surface. |
| 2494 | * Handle size dismatch and positioning according to the method. */ |
| 2495 | static void |
| 2496 | shell_configure_fullscreen(struct shell_surface *shsurf) |
| 2497 | { |
| 2498 | struct weston_output *output = shsurf->fullscreen_output; |
| 2499 | struct weston_surface *surface = shsurf->surface; |
| 2500 | struct weston_matrix *matrix; |
Kristian Høgsberg | 240dfeb | 2012-07-12 12:32:31 -0400 | [diff] [blame] | 2501 | float scale, output_aspect, surface_aspect, x, y; |
Giulio Camuffo | b836664 | 2013-04-25 13:57:46 +0300 | [diff] [blame] | 2502 | int32_t surf_x, surf_y, surf_width, surf_height; |
Alex Wu | 4539b08 | 2012-03-01 12:57:46 +0800 | [diff] [blame] | 2503 | |
Alexander Larsson | f82b6ca | 2013-05-28 16:23:39 +0200 | [diff] [blame] | 2504 | if (shsurf->fullscreen.type != WL_SHELL_SURFACE_FULLSCREEN_METHOD_DRIVER) |
| 2505 | restore_output_mode(output); |
| 2506 | |
Philip Withnall | ed8f1a9 | 2013-11-25 18:01:43 +0000 | [diff] [blame] | 2507 | shell_ensure_fullscreen_black_view(shsurf); |
Alex Wu | 4539b08 | 2012-03-01 12:57:46 +0800 | [diff] [blame] | 2508 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 2509 | surface_subsurfaces_boundingbox(shsurf->surface, &surf_x, &surf_y, |
Giulio Camuffo | b836664 | 2013-04-25 13:57:46 +0300 | [diff] [blame] | 2510 | &surf_width, &surf_height); |
| 2511 | |
Alex Wu | 4539b08 | 2012-03-01 12:57:46 +0800 | [diff] [blame] | 2512 | switch (shsurf->fullscreen.type) { |
| 2513 | case WL_SHELL_SURFACE_FULLSCREEN_METHOD_DEFAULT: |
Pekka Paalanen | de685b8 | 2012-12-04 15:58:12 +0200 | [diff] [blame] | 2514 | if (surface->buffer_ref.buffer) |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 2515 | center_on_output(shsurf->view, shsurf->fullscreen_output); |
Alex Wu | 4539b08 | 2012-03-01 12:57:46 +0800 | [diff] [blame] | 2516 | break; |
| 2517 | case WL_SHELL_SURFACE_FULLSCREEN_METHOD_SCALE: |
Rob Bradford | 9f3dd15 | 2013-02-12 11:53:47 +0000 | [diff] [blame] | 2518 | /* 1:1 mapping between surface and output dimensions */ |
Giulio Camuffo | b836664 | 2013-04-25 13:57:46 +0300 | [diff] [blame] | 2519 | if (output->width == surf_width && |
| 2520 | output->height == surf_height) { |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 2521 | weston_view_set_position(shsurf->view, |
| 2522 | output->x - surf_x, |
| 2523 | output->y - surf_y); |
Rob Bradford | 9f3dd15 | 2013-02-12 11:53:47 +0000 | [diff] [blame] | 2524 | break; |
| 2525 | } |
| 2526 | |
Alex Wu | 4539b08 | 2012-03-01 12:57:46 +0800 | [diff] [blame] | 2527 | matrix = &shsurf->fullscreen.transform.matrix; |
| 2528 | weston_matrix_init(matrix); |
Kristian Høgsberg | 240dfeb | 2012-07-12 12:32:31 -0400 | [diff] [blame] | 2529 | |
Scott Moreau | 1bad5db | 2012-08-18 01:04:05 -0600 | [diff] [blame] | 2530 | output_aspect = (float) output->width / |
| 2531 | (float) output->height; |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 2532 | /* XXX: Use surf_width and surf_height here? */ |
| 2533 | surface_aspect = (float) surface->width / |
| 2534 | (float) surface->height; |
Kristian Høgsberg | 240dfeb | 2012-07-12 12:32:31 -0400 | [diff] [blame] | 2535 | if (output_aspect < surface_aspect) |
Scott Moreau | 1bad5db | 2012-08-18 01:04:05 -0600 | [diff] [blame] | 2536 | scale = (float) output->width / |
Giulio Camuffo | b836664 | 2013-04-25 13:57:46 +0300 | [diff] [blame] | 2537 | (float) surf_width; |
Kristian Høgsberg | 240dfeb | 2012-07-12 12:32:31 -0400 | [diff] [blame] | 2538 | else |
Scott Moreau | 1bad5db | 2012-08-18 01:04:05 -0600 | [diff] [blame] | 2539 | scale = (float) output->height / |
Giulio Camuffo | b836664 | 2013-04-25 13:57:46 +0300 | [diff] [blame] | 2540 | (float) surf_height; |
Kristian Høgsberg | 240dfeb | 2012-07-12 12:32:31 -0400 | [diff] [blame] | 2541 | |
Alex Wu | 4539b08 | 2012-03-01 12:57:46 +0800 | [diff] [blame] | 2542 | weston_matrix_scale(matrix, scale, scale, 1); |
| 2543 | wl_list_remove(&shsurf->fullscreen.transform.link); |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 2544 | wl_list_insert(&shsurf->view->geometry.transformation_list, |
Alex Wu | 4539b08 | 2012-03-01 12:57:46 +0800 | [diff] [blame] | 2545 | &shsurf->fullscreen.transform.link); |
Giulio Camuffo | b836664 | 2013-04-25 13:57:46 +0300 | [diff] [blame] | 2546 | x = output->x + (output->width - surf_width * scale) / 2 - surf_x; |
| 2547 | y = output->y + (output->height - surf_height * scale) / 2 - surf_y; |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 2548 | weston_view_set_position(shsurf->view, x, y); |
Kristian Høgsberg | 240dfeb | 2012-07-12 12:32:31 -0400 | [diff] [blame] | 2549 | |
Alex Wu | 4539b08 | 2012-03-01 12:57:46 +0800 | [diff] [blame] | 2550 | break; |
| 2551 | case WL_SHELL_SURFACE_FULLSCREEN_METHOD_DRIVER: |
Alex Wu | bd3354b | 2012-04-17 17:20:49 +0800 | [diff] [blame] | 2552 | if (shell_surface_is_top_fullscreen(shsurf)) { |
Quentin Glidic | c0d79ce | 2013-01-29 14:16:13 +0100 | [diff] [blame] | 2553 | struct weston_mode mode = {0, |
Pekka Paalanen | 1fd9c0f | 2013-11-26 18:19:41 +0100 | [diff] [blame] | 2554 | surf_width * surface->buffer_viewport.scale, |
| 2555 | surf_height * surface->buffer_viewport.scale, |
Alex Wu | bd3354b | 2012-04-17 17:20:49 +0800 | [diff] [blame] | 2556 | shsurf->fullscreen.framerate}; |
| 2557 | |
Pekka Paalanen | 1fd9c0f | 2013-11-26 18:19:41 +0100 | [diff] [blame] | 2558 | if (weston_output_switch_mode(output, &mode, surface->buffer_viewport.scale, |
Hardening | 57388e4 | 2013-09-18 23:56:36 +0200 | [diff] [blame] | 2559 | WESTON_MODE_SWITCH_SET_TEMPORARY) == 0) { |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 2560 | weston_view_set_position(shsurf->view, |
| 2561 | output->x - surf_x, |
| 2562 | output->y - surf_y); |
Jason Ekstrand | 918f2dd | 2013-12-02 21:01:53 -0600 | [diff] [blame] | 2563 | shsurf->fullscreen.black_view->surface->width = output->width; |
| 2564 | shsurf->fullscreen.black_view->surface->height = output->height; |
| 2565 | weston_view_set_position(shsurf->fullscreen.black_view, |
| 2566 | output->x - surf_x, |
| 2567 | output->y - surf_y); |
Alex Wu | bd3354b | 2012-04-17 17:20:49 +0800 | [diff] [blame] | 2568 | break; |
Alexander Larsson | d622ed3 | 2013-05-28 16:23:40 +0200 | [diff] [blame] | 2569 | } else { |
Alexander Larsson | f82b6ca | 2013-05-28 16:23:39 +0200 | [diff] [blame] | 2570 | restore_output_mode(output); |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 2571 | center_on_output(shsurf->view, output); |
Alexander Larsson | d622ed3 | 2013-05-28 16:23:40 +0200 | [diff] [blame] | 2572 | } |
Alex Wu | bd3354b | 2012-04-17 17:20:49 +0800 | [diff] [blame] | 2573 | } |
Alex Wu | 4539b08 | 2012-03-01 12:57:46 +0800 | [diff] [blame] | 2574 | break; |
| 2575 | case WL_SHELL_SURFACE_FULLSCREEN_METHOD_FILL: |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 2576 | center_on_output(shsurf->view, output); |
Alex Wu | 4539b08 | 2012-03-01 12:57:46 +0800 | [diff] [blame] | 2577 | break; |
| 2578 | default: |
| 2579 | break; |
| 2580 | } |
| 2581 | } |
| 2582 | |
Alex Wu | 4539b08 | 2012-03-01 12:57:46 +0800 | [diff] [blame] | 2583 | static void |
| 2584 | shell_map_fullscreen(struct shell_surface *shsurf) |
| 2585 | { |
Alex Wu | bd3354b | 2012-04-17 17:20:49 +0800 | [diff] [blame] | 2586 | shell_configure_fullscreen(shsurf); |
Alex Wu | 4539b08 | 2012-03-01 12:57:46 +0800 | [diff] [blame] | 2587 | } |
| 2588 | |
Kristian Høgsberg | 7a5c979 | 2011-06-18 06:12:54 -0400 | [diff] [blame] | 2589 | static void |
Tiago Vignatti | fb2adba | 2013-06-12 15:43:21 -0300 | [diff] [blame] | 2590 | set_xwayland(struct shell_surface *shsurf, int x, int y, uint32_t flags) |
| 2591 | { |
| 2592 | /* XXX: using the same fields for transient type */ |
Rafael Antognolli | 03b1659 | 2013-12-03 15:35:42 -0200 | [diff] [blame] | 2593 | surface_clear_next_states(shsurf); |
Tiago Vignatti | fb2adba | 2013-06-12 15:43:21 -0300 | [diff] [blame] | 2594 | shsurf->transient.x = x; |
| 2595 | shsurf->transient.y = y; |
| 2596 | shsurf->transient.flags = flags; |
Philip Withnall | dc4332f | 2013-11-25 18:01:38 +0000 | [diff] [blame] | 2597 | |
| 2598 | shell_surface_set_parent(shsurf, NULL); |
| 2599 | |
Kristian Høgsberg | c8f8dd8 | 2013-12-05 23:20:33 -0800 | [diff] [blame] | 2600 | shsurf->type = SHELL_SURFACE_XWAYLAND; |
Tiago Vignatti | fb2adba | 2013-06-12 15:43:21 -0300 | [diff] [blame] | 2601 | } |
| 2602 | |
Kristian Høgsberg | 02bbabb | 2013-05-06 22:15:05 -0400 | [diff] [blame] | 2603 | static const struct weston_pointer_grab_interface popup_grab_interface; |
Giulio Camuffo | 5085a75 | 2013-03-25 21:42:45 +0100 | [diff] [blame] | 2604 | |
| 2605 | static void |
| 2606 | destroy_shell_seat(struct wl_listener *listener, void *data) |
| 2607 | { |
| 2608 | struct shell_seat *shseat = |
| 2609 | container_of(listener, |
| 2610 | struct shell_seat, seat_destroy_listener); |
| 2611 | struct shell_surface *shsurf, *prev = NULL; |
| 2612 | |
| 2613 | if (shseat->popup_grab.grab.interface == &popup_grab_interface) { |
Kristian Høgsberg | 02bbabb | 2013-05-06 22:15:05 -0400 | [diff] [blame] | 2614 | weston_pointer_end_grab(shseat->popup_grab.grab.pointer); |
Giulio Camuffo | 5085a75 | 2013-03-25 21:42:45 +0100 | [diff] [blame] | 2615 | shseat->popup_grab.client = NULL; |
| 2616 | |
| 2617 | wl_list_for_each(shsurf, &shseat->popup_grab.surfaces_list, popup.grab_link) { |
| 2618 | shsurf->popup.shseat = NULL; |
| 2619 | if (prev) { |
| 2620 | wl_list_init(&prev->popup.grab_link); |
| 2621 | } |
| 2622 | prev = shsurf; |
| 2623 | } |
| 2624 | wl_list_init(&prev->popup.grab_link); |
| 2625 | } |
| 2626 | |
| 2627 | wl_list_remove(&shseat->seat_destroy_listener.link); |
| 2628 | free(shseat); |
| 2629 | } |
| 2630 | |
| 2631 | static struct shell_seat * |
| 2632 | create_shell_seat(struct weston_seat *seat) |
| 2633 | { |
| 2634 | struct shell_seat *shseat; |
| 2635 | |
| 2636 | shseat = calloc(1, sizeof *shseat); |
| 2637 | if (!shseat) { |
| 2638 | weston_log("no memory to allocate shell seat\n"); |
| 2639 | return NULL; |
| 2640 | } |
| 2641 | |
| 2642 | shseat->seat = seat; |
| 2643 | wl_list_init(&shseat->popup_grab.surfaces_list); |
| 2644 | |
| 2645 | shseat->seat_destroy_listener.notify = destroy_shell_seat; |
| 2646 | wl_signal_add(&seat->destroy_signal, |
| 2647 | &shseat->seat_destroy_listener); |
| 2648 | |
| 2649 | return shseat; |
| 2650 | } |
| 2651 | |
| 2652 | static struct shell_seat * |
| 2653 | get_shell_seat(struct weston_seat *seat) |
| 2654 | { |
| 2655 | struct wl_listener *listener; |
| 2656 | |
| 2657 | listener = wl_signal_get(&seat->destroy_signal, destroy_shell_seat); |
| 2658 | if (listener == NULL) |
| 2659 | return create_shell_seat(seat); |
| 2660 | |
| 2661 | return container_of(listener, |
| 2662 | struct shell_seat, seat_destroy_listener); |
| 2663 | } |
| 2664 | |
Kristian Høgsberg | b810eb5 | 2013-02-12 20:07:05 -0500 | [diff] [blame] | 2665 | static void |
Kristian Høgsberg | 6848c25 | 2013-05-08 22:02:59 -0400 | [diff] [blame] | 2666 | popup_grab_focus(struct weston_pointer_grab *grab) |
Kristian Høgsberg | b3cca0a | 2012-01-04 22:19:14 -0500 | [diff] [blame] | 2667 | { |
Kristian Høgsberg | 02bbabb | 2013-05-06 22:15:05 -0400 | [diff] [blame] | 2668 | struct weston_pointer *pointer = grab->pointer; |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 2669 | struct weston_view *view; |
Giulio Camuffo | 5085a75 | 2013-03-25 21:42:45 +0100 | [diff] [blame] | 2670 | struct shell_seat *shseat = |
| 2671 | container_of(grab, struct shell_seat, popup_grab.grab); |
| 2672 | struct wl_client *client = shseat->popup_grab.client; |
Kristian Høgsberg | 6848c25 | 2013-05-08 22:02:59 -0400 | [diff] [blame] | 2673 | wl_fixed_t sx, sy; |
| 2674 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 2675 | view = weston_compositor_pick_view(pointer->seat->compositor, |
| 2676 | pointer->x, pointer->y, |
| 2677 | &sx, &sy); |
Kristian Høgsberg | b3cca0a | 2012-01-04 22:19:14 -0500 | [diff] [blame] | 2678 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 2679 | if (view && view->surface->resource && |
| 2680 | wl_resource_get_client(view->surface->resource) == client) { |
| 2681 | weston_pointer_set_focus(pointer, view, sx, sy); |
Kristian Høgsberg | b3cca0a | 2012-01-04 22:19:14 -0500 | [diff] [blame] | 2682 | } else { |
Kristian Høgsberg | 02bbabb | 2013-05-06 22:15:05 -0400 | [diff] [blame] | 2683 | weston_pointer_set_focus(pointer, NULL, |
| 2684 | wl_fixed_from_int(0), |
| 2685 | wl_fixed_from_int(0)); |
Kristian Høgsberg | b3cca0a | 2012-01-04 22:19:14 -0500 | [diff] [blame] | 2686 | } |
| 2687 | } |
| 2688 | |
| 2689 | static void |
Giulio Camuffo | 1959ab8 | 2013-11-14 23:42:52 +0100 | [diff] [blame] | 2690 | popup_grab_motion(struct weston_pointer_grab *grab, uint32_t time, |
| 2691 | wl_fixed_t x, wl_fixed_t y) |
Kristian Høgsberg | b3cca0a | 2012-01-04 22:19:14 -0500 | [diff] [blame] | 2692 | { |
Kristian Høgsberg | be6403e | 2013-05-08 21:03:21 -0400 | [diff] [blame] | 2693 | struct weston_pointer *pointer = grab->pointer; |
Neil Roberts | 96d790e | 2013-09-19 17:32:00 +0100 | [diff] [blame] | 2694 | struct wl_resource *resource; |
Kristian Høgsberg | be6403e | 2013-05-08 21:03:21 -0400 | [diff] [blame] | 2695 | wl_fixed_t sx, sy; |
Kristian Høgsberg | b3cca0a | 2012-01-04 22:19:14 -0500 | [diff] [blame] | 2696 | |
Giulio Camuffo | 1959ab8 | 2013-11-14 23:42:52 +0100 | [diff] [blame] | 2697 | weston_pointer_move(pointer, x, y); |
| 2698 | |
Neil Roberts | 96d790e | 2013-09-19 17:32:00 +0100 | [diff] [blame] | 2699 | wl_resource_for_each(resource, &pointer->focus_resource_list) { |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 2700 | weston_view_from_global_fixed(pointer->focus, |
| 2701 | pointer->x, pointer->y, |
| 2702 | &sx, &sy); |
Neil Roberts | 96d790e | 2013-09-19 17:32:00 +0100 | [diff] [blame] | 2703 | wl_pointer_send_motion(resource, time, sx, sy); |
Kristian Høgsberg | be6403e | 2013-05-08 21:03:21 -0400 | [diff] [blame] | 2704 | } |
Kristian Høgsberg | b3cca0a | 2012-01-04 22:19:14 -0500 | [diff] [blame] | 2705 | } |
| 2706 | |
| 2707 | static void |
Kristian Høgsberg | 02bbabb | 2013-05-06 22:15:05 -0400 | [diff] [blame] | 2708 | popup_grab_button(struct weston_pointer_grab *grab, |
Daniel Stone | 4dbadb1 | 2012-05-30 16:31:51 +0100 | [diff] [blame] | 2709 | uint32_t time, uint32_t button, uint32_t state_w) |
Kristian Høgsberg | b3cca0a | 2012-01-04 22:19:14 -0500 | [diff] [blame] | 2710 | { |
| 2711 | struct wl_resource *resource; |
Giulio Camuffo | 5085a75 | 2013-03-25 21:42:45 +0100 | [diff] [blame] | 2712 | struct shell_seat *shseat = |
| 2713 | container_of(grab, struct shell_seat, popup_grab.grab); |
Rob Bradford | 880ebc7 | 2013-07-22 17:31:38 +0100 | [diff] [blame] | 2714 | struct wl_display *display = shseat->seat->compositor->wl_display; |
Daniel Stone | 4dbadb1 | 2012-05-30 16:31:51 +0100 | [diff] [blame] | 2715 | enum wl_pointer_button_state state = state_w; |
Kristian Høgsberg | eae5de7 | 2012-04-11 22:42:15 -0400 | [diff] [blame] | 2716 | uint32_t serial; |
Neil Roberts | 96d790e | 2013-09-19 17:32:00 +0100 | [diff] [blame] | 2717 | struct wl_list *resource_list; |
Kristian Høgsberg | b3cca0a | 2012-01-04 22:19:14 -0500 | [diff] [blame] | 2718 | |
Neil Roberts | 96d790e | 2013-09-19 17:32:00 +0100 | [diff] [blame] | 2719 | resource_list = &grab->pointer->focus_resource_list; |
| 2720 | if (!wl_list_empty(resource_list)) { |
Kristian Høgsberg | eae5de7 | 2012-04-11 22:42:15 -0400 | [diff] [blame] | 2721 | serial = wl_display_get_serial(display); |
Neil Roberts | 96d790e | 2013-09-19 17:32:00 +0100 | [diff] [blame] | 2722 | wl_resource_for_each(resource, resource_list) { |
| 2723 | wl_pointer_send_button(resource, serial, |
| 2724 | time, button, state); |
| 2725 | } |
Daniel Stone | 4dbadb1 | 2012-05-30 16:31:51 +0100 | [diff] [blame] | 2726 | } else if (state == WL_POINTER_BUTTON_STATE_RELEASED && |
Giulio Camuffo | 5085a75 | 2013-03-25 21:42:45 +0100 | [diff] [blame] | 2727 | (shseat->popup_grab.initial_up || |
Kristian Høgsberg | e314875 | 2013-05-06 23:19:49 -0400 | [diff] [blame] | 2728 | time - shseat->seat->pointer->grab_time > 500)) { |
Kristian Høgsberg | 57e0907 | 2012-10-30 14:07:27 -0400 | [diff] [blame] | 2729 | popup_grab_end(grab->pointer); |
Kristian Høgsberg | b3cca0a | 2012-01-04 22:19:14 -0500 | [diff] [blame] | 2730 | } |
| 2731 | |
Daniel Stone | 4dbadb1 | 2012-05-30 16:31:51 +0100 | [diff] [blame] | 2732 | if (state == WL_POINTER_BUTTON_STATE_RELEASED) |
Giulio Camuffo | 5085a75 | 2013-03-25 21:42:45 +0100 | [diff] [blame] | 2733 | shseat->popup_grab.initial_up = 1; |
Kristian Høgsberg | b3cca0a | 2012-01-04 22:19:14 -0500 | [diff] [blame] | 2734 | } |
| 2735 | |
Jonas Ådahl | 1ea343e | 2013-10-25 23:18:05 +0200 | [diff] [blame] | 2736 | static void |
| 2737 | popup_grab_cancel(struct weston_pointer_grab *grab) |
| 2738 | { |
| 2739 | popup_grab_end(grab->pointer); |
| 2740 | } |
| 2741 | |
Kristian Høgsberg | 02bbabb | 2013-05-06 22:15:05 -0400 | [diff] [blame] | 2742 | static const struct weston_pointer_grab_interface popup_grab_interface = { |
Kristian Høgsberg | b3cca0a | 2012-01-04 22:19:14 -0500 | [diff] [blame] | 2743 | popup_grab_focus, |
| 2744 | popup_grab_motion, |
| 2745 | popup_grab_button, |
Jonas Ådahl | 1ea343e | 2013-10-25 23:18:05 +0200 | [diff] [blame] | 2746 | popup_grab_cancel, |
Kristian Høgsberg | b3cca0a | 2012-01-04 22:19:14 -0500 | [diff] [blame] | 2747 | }; |
| 2748 | |
| 2749 | static void |
Rafael Antognolli | e2a3455 | 2013-12-03 15:35:45 -0200 | [diff] [blame] | 2750 | shell_surface_send_popup_done(struct shell_surface *shsurf) |
| 2751 | { |
| 2752 | if (shell_surface_is_wl_shell_surface(shsurf)) |
| 2753 | wl_shell_surface_send_popup_done(shsurf->resource); |
| 2754 | else if (shell_surface_is_xdg_popup(shsurf)) |
| 2755 | xdg_popup_send_popup_done(shsurf->resource, |
| 2756 | shsurf->popup.serial); |
| 2757 | } |
| 2758 | |
| 2759 | static void |
Kristian Høgsberg | 02bbabb | 2013-05-06 22:15:05 -0400 | [diff] [blame] | 2760 | popup_grab_end(struct weston_pointer *pointer) |
Kristian Høgsberg | 57e0907 | 2012-10-30 14:07:27 -0400 | [diff] [blame] | 2761 | { |
Kristian Høgsberg | 02bbabb | 2013-05-06 22:15:05 -0400 | [diff] [blame] | 2762 | struct weston_pointer_grab *grab = pointer->grab; |
Giulio Camuffo | 5085a75 | 2013-03-25 21:42:45 +0100 | [diff] [blame] | 2763 | struct shell_seat *shseat = |
| 2764 | container_of(grab, struct shell_seat, popup_grab.grab); |
| 2765 | struct shell_surface *shsurf; |
| 2766 | struct shell_surface *prev = NULL; |
Kristian Høgsberg | 57e0907 | 2012-10-30 14:07:27 -0400 | [diff] [blame] | 2767 | |
| 2768 | if (pointer->grab->interface == &popup_grab_interface) { |
Kristian Høgsberg | 02bbabb | 2013-05-06 22:15:05 -0400 | [diff] [blame] | 2769 | weston_pointer_end_grab(grab->pointer); |
Giulio Camuffo | 5085a75 | 2013-03-25 21:42:45 +0100 | [diff] [blame] | 2770 | shseat->popup_grab.client = NULL; |
Philipp Brüschweiler | 63e7be6 | 2013-04-15 21:09:54 +0200 | [diff] [blame] | 2771 | shseat->popup_grab.grab.interface = NULL; |
| 2772 | assert(!wl_list_empty(&shseat->popup_grab.surfaces_list)); |
Giulio Camuffo | 5085a75 | 2013-03-25 21:42:45 +0100 | [diff] [blame] | 2773 | /* Send the popup_done event to all the popups open */ |
| 2774 | 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] | 2775 | shell_surface_send_popup_done(shsurf); |
Giulio Camuffo | 5085a75 | 2013-03-25 21:42:45 +0100 | [diff] [blame] | 2776 | shsurf->popup.shseat = NULL; |
| 2777 | if (prev) { |
| 2778 | wl_list_init(&prev->popup.grab_link); |
| 2779 | } |
| 2780 | prev = shsurf; |
| 2781 | } |
| 2782 | wl_list_init(&prev->popup.grab_link); |
| 2783 | wl_list_init(&shseat->popup_grab.surfaces_list); |
| 2784 | } |
| 2785 | } |
| 2786 | |
| 2787 | static void |
| 2788 | add_popup_grab(struct shell_surface *shsurf, struct shell_seat *shseat) |
| 2789 | { |
Kristian Høgsberg | e314875 | 2013-05-06 23:19:49 -0400 | [diff] [blame] | 2790 | struct weston_seat *seat = shseat->seat; |
Giulio Camuffo | 5085a75 | 2013-03-25 21:42:45 +0100 | [diff] [blame] | 2791 | |
| 2792 | if (wl_list_empty(&shseat->popup_grab.surfaces_list)) { |
Jason Ekstrand | 651f00e | 2013-06-14 10:07:54 -0500 | [diff] [blame] | 2793 | shseat->popup_grab.client = wl_resource_get_client(shsurf->resource); |
Giulio Camuffo | 5085a75 | 2013-03-25 21:42:45 +0100 | [diff] [blame] | 2794 | shseat->popup_grab.grab.interface = &popup_grab_interface; |
Giulio Camuffo | 1b4b61a | 2013-03-27 18:05:26 +0100 | [diff] [blame] | 2795 | /* We must make sure here that this popup was opened after |
| 2796 | * a mouse press, and not just by moving around with other |
| 2797 | * popups already open. */ |
Kristian Høgsberg | e314875 | 2013-05-06 23:19:49 -0400 | [diff] [blame] | 2798 | if (shseat->seat->pointer->button_count > 0) |
Giulio Camuffo | 1b4b61a | 2013-03-27 18:05:26 +0100 | [diff] [blame] | 2799 | shseat->popup_grab.initial_up = 0; |
Giulio Camuffo | 5085a75 | 2013-03-25 21:42:45 +0100 | [diff] [blame] | 2800 | |
Rob Bradford | dfe3105 | 2013-06-26 19:49:11 +0100 | [diff] [blame] | 2801 | 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] | 2802 | weston_pointer_start_grab(seat->pointer, &shseat->popup_grab.grab); |
Rob Bradford | dfe3105 | 2013-06-26 19:49:11 +0100 | [diff] [blame] | 2803 | } else { |
| 2804 | wl_list_insert(&shseat->popup_grab.surfaces_list, &shsurf->popup.grab_link); |
Giulio Camuffo | 5085a75 | 2013-03-25 21:42:45 +0100 | [diff] [blame] | 2805 | } |
Giulio Camuffo | 5085a75 | 2013-03-25 21:42:45 +0100 | [diff] [blame] | 2806 | } |
| 2807 | |
| 2808 | static void |
| 2809 | remove_popup_grab(struct shell_surface *shsurf) |
| 2810 | { |
| 2811 | struct shell_seat *shseat = shsurf->popup.shseat; |
| 2812 | |
| 2813 | wl_list_remove(&shsurf->popup.grab_link); |
| 2814 | wl_list_init(&shsurf->popup.grab_link); |
| 2815 | if (wl_list_empty(&shseat->popup_grab.surfaces_list)) { |
Kristian Høgsberg | 02bbabb | 2013-05-06 22:15:05 -0400 | [diff] [blame] | 2816 | weston_pointer_end_grab(shseat->popup_grab.grab.pointer); |
Philipp Brüschweiler | 63e7be6 | 2013-04-15 21:09:54 +0200 | [diff] [blame] | 2817 | shseat->popup_grab.grab.interface = NULL; |
Kristian Høgsberg | 57e0907 | 2012-10-30 14:07:27 -0400 | [diff] [blame] | 2818 | } |
| 2819 | } |
| 2820 | |
| 2821 | static void |
Kristian Høgsberg | 3730f36 | 2012-04-13 12:40:07 -0400 | [diff] [blame] | 2822 | shell_map_popup(struct shell_surface *shsurf) |
Kristian Høgsberg | b3cca0a | 2012-01-04 22:19:14 -0500 | [diff] [blame] | 2823 | { |
Giulio Camuffo | 5085a75 | 2013-03-25 21:42:45 +0100 | [diff] [blame] | 2824 | struct shell_seat *shseat = shsurf->popup.shseat; |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 2825 | struct weston_view *parent_view = get_default_view(shsurf->parent); |
Kristian Høgsberg | b3cca0a | 2012-01-04 22:19:14 -0500 | [diff] [blame] | 2826 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 2827 | shsurf->surface->output = parent_view->output; |
| 2828 | shsurf->view->output = parent_view->output; |
Kristian Høgsberg | b3cca0a | 2012-01-04 22:19:14 -0500 | [diff] [blame] | 2829 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 2830 | weston_view_set_transform_parent(shsurf->view, parent_view); |
| 2831 | weston_view_set_position(shsurf->view, shsurf->popup.x, shsurf->popup.y); |
| 2832 | weston_view_update_transform(shsurf->view); |
Kristian Høgsberg | b3cca0a | 2012-01-04 22:19:14 -0500 | [diff] [blame] | 2833 | |
Kristian Høgsberg | e314875 | 2013-05-06 23:19:49 -0400 | [diff] [blame] | 2834 | if (shseat->seat->pointer->grab_serial == shsurf->popup.serial) { |
Giulio Camuffo | 5085a75 | 2013-03-25 21:42:45 +0100 | [diff] [blame] | 2835 | add_popup_grab(shsurf, shseat); |
Kristian Høgsberg | 3730f36 | 2012-04-13 12:40:07 -0400 | [diff] [blame] | 2836 | } else { |
Rafael Antognolli | e2a3455 | 2013-12-03 15:35:45 -0200 | [diff] [blame] | 2837 | shell_surface_send_popup_done(shsurf); |
Giulio Camuffo | 5085a75 | 2013-03-25 21:42:45 +0100 | [diff] [blame] | 2838 | shseat->popup_grab.client = NULL; |
Kristian Høgsberg | 3730f36 | 2012-04-13 12:40:07 -0400 | [diff] [blame] | 2839 | } |
Kristian Høgsberg | b3cca0a | 2012-01-04 22:19:14 -0500 | [diff] [blame] | 2840 | } |
| 2841 | |
Pekka Paalanen | 9d1613e | 2011-11-25 12:09:16 +0200 | [diff] [blame] | 2842 | static const struct wl_shell_surface_interface shell_surface_implementation = { |
Scott Moreau | ff1db4a | 2012-04-17 19:06:18 -0600 | [diff] [blame] | 2843 | shell_surface_pong, |
Pekka Paalanen | 9d1613e | 2011-11-25 12:09:16 +0200 | [diff] [blame] | 2844 | shell_surface_move, |
| 2845 | shell_surface_resize, |
| 2846 | shell_surface_set_toplevel, |
| 2847 | shell_surface_set_transient, |
Kristian Høgsberg | b3cca0a | 2012-01-04 22:19:14 -0500 | [diff] [blame] | 2848 | shell_surface_set_fullscreen, |
Juan Zhao | 96879df | 2012-02-07 08:45:41 +0800 | [diff] [blame] | 2849 | shell_surface_set_popup, |
Kristian Høgsberg | e7afd91 | 2012-05-02 09:47:44 -0400 | [diff] [blame] | 2850 | shell_surface_set_maximized, |
| 2851 | shell_surface_set_title, |
| 2852 | shell_surface_set_class |
Pekka Paalanen | 9d1613e | 2011-11-25 12:09:16 +0200 | [diff] [blame] | 2853 | }; |
| 2854 | |
| 2855 | static void |
Tiago Vignatti | bc052c9 | 2012-04-19 16:18:18 +0300 | [diff] [blame] | 2856 | destroy_shell_surface(struct shell_surface *shsurf) |
Pekka Paalanen | 9d1613e | 2011-11-25 12:09:16 +0200 | [diff] [blame] | 2857 | { |
Jason Ekstrand | 651f00e | 2013-06-14 10:07:54 -0500 | [diff] [blame] | 2858 | wl_signal_emit(&shsurf->destroy_signal, shsurf); |
| 2859 | |
Giulio Camuffo | 5085a75 | 2013-03-25 21:42:45 +0100 | [diff] [blame] | 2860 | if (!wl_list_empty(&shsurf->popup.grab_link)) { |
| 2861 | remove_popup_grab(shsurf); |
| 2862 | } |
Kristian Høgsberg | b3cca0a | 2012-01-04 22:19:14 -0500 | [diff] [blame] | 2863 | |
Alex Wu | bd3354b | 2012-04-17 17:20:49 +0800 | [diff] [blame] | 2864 | if (shsurf->fullscreen.type == WL_SHELL_SURFACE_FULLSCREEN_METHOD_DRIVER && |
Alexander Larsson | f82b6ca | 2013-05-28 16:23:39 +0200 | [diff] [blame] | 2865 | shell_surface_is_top_fullscreen(shsurf)) |
| 2866 | restore_output_mode (shsurf->fullscreen_output); |
Pekka Paalanen | 9d1613e | 2011-11-25 12:09:16 +0200 | [diff] [blame] | 2867 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 2868 | if (shsurf->fullscreen.black_view) |
| 2869 | weston_surface_destroy(shsurf->fullscreen.black_view->surface); |
Alex Wu | aa08e2d | 2012-03-05 11:01:40 +0800 | [diff] [blame] | 2870 | |
Alex Wu | bd3354b | 2012-04-17 17:20:49 +0800 | [diff] [blame] | 2871 | /* As destroy_resource() use wl_list_for_each_safe(), |
| 2872 | * we can always remove the listener. |
| 2873 | */ |
| 2874 | wl_list_remove(&shsurf->surface_destroy_listener.link); |
| 2875 | shsurf->surface->configure = NULL; |
Scott Moreau | 9521d5e | 2012-04-19 13:06:17 -0600 | [diff] [blame] | 2876 | ping_timer_destroy(shsurf); |
Scott Moreau | 976a050 | 2013-03-07 10:15:17 -0700 | [diff] [blame] | 2877 | free(shsurf->title); |
Alex Wu | bd3354b | 2012-04-17 17:20:49 +0800 | [diff] [blame] | 2878 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 2879 | weston_view_destroy(shsurf->view); |
| 2880 | |
Philip Withnall | 648a4dd | 2013-11-25 18:01:44 +0000 | [diff] [blame] | 2881 | wl_list_remove(&shsurf->children_link); |
| 2882 | |
Pekka Paalanen | 9d1613e | 2011-11-25 12:09:16 +0200 | [diff] [blame] | 2883 | wl_list_remove(&shsurf->link); |
| 2884 | free(shsurf); |
| 2885 | } |
| 2886 | |
| 2887 | static void |
Tiago Vignatti | bc052c9 | 2012-04-19 16:18:18 +0300 | [diff] [blame] | 2888 | shell_destroy_shell_surface(struct wl_resource *resource) |
| 2889 | { |
Jason Ekstrand | 651f00e | 2013-06-14 10:07:54 -0500 | [diff] [blame] | 2890 | struct shell_surface *shsurf = wl_resource_get_user_data(resource); |
Tiago Vignatti | bc052c9 | 2012-04-19 16:18:18 +0300 | [diff] [blame] | 2891 | |
| 2892 | destroy_shell_surface(shsurf); |
| 2893 | } |
| 2894 | |
| 2895 | static void |
Kristian Høgsberg | 27e3052 | 2012-04-11 23:18:23 -0400 | [diff] [blame] | 2896 | shell_handle_surface_destroy(struct wl_listener *listener, void *data) |
Pekka Paalanen | 9d1613e | 2011-11-25 12:09:16 +0200 | [diff] [blame] | 2897 | { |
| 2898 | struct shell_surface *shsurf = container_of(listener, |
| 2899 | struct shell_surface, |
| 2900 | surface_destroy_listener); |
| 2901 | |
Jason Ekstrand | 651f00e | 2013-06-14 10:07:54 -0500 | [diff] [blame] | 2902 | if (shsurf->resource) |
| 2903 | wl_resource_destroy(shsurf->resource); |
| 2904 | else |
Tiago Vignatti | bc052c9 | 2012-04-19 16:18:18 +0300 | [diff] [blame] | 2905 | destroy_shell_surface(shsurf); |
Pekka Paalanen | 9d1613e | 2011-11-25 12:09:16 +0200 | [diff] [blame] | 2906 | } |
| 2907 | |
Kristian Høgsberg | d813445 | 2012-06-21 12:49:02 -0400 | [diff] [blame] | 2908 | static void |
Jason Ekstrand | 918f2dd | 2013-12-02 21:01:53 -0600 | [diff] [blame] | 2909 | shell_surface_configure(struct weston_surface *, int32_t, int32_t); |
Kristian Høgsberg | d813445 | 2012-06-21 12:49:02 -0400 | [diff] [blame] | 2910 | |
Kristian Høgsberg | 1ef2313 | 2013-12-04 00:20:01 -0800 | [diff] [blame] | 2911 | struct shell_surface * |
Kristian Høgsberg | 8334bc1 | 2012-01-03 10:29:47 -0500 | [diff] [blame] | 2912 | get_shell_surface(struct weston_surface *surface) |
Pekka Paalanen | ec2b32f | 2011-11-28 15:12:34 +0200 | [diff] [blame] | 2913 | { |
Kristian Høgsberg | d813445 | 2012-06-21 12:49:02 -0400 | [diff] [blame] | 2914 | if (surface->configure == shell_surface_configure) |
Giulio Camuffo | 7fe01b1 | 2013-03-28 18:02:42 +0100 | [diff] [blame] | 2915 | return surface->configure_private; |
Kristian Høgsberg | d813445 | 2012-06-21 12:49:02 -0400 | [diff] [blame] | 2916 | else |
| 2917 | return NULL; |
Pekka Paalanen | ec2b32f | 2011-11-28 15:12:34 +0200 | [diff] [blame] | 2918 | } |
| 2919 | |
Rafael Antognolli | e2a3455 | 2013-12-03 15:35:45 -0200 | [diff] [blame] | 2920 | static struct shell_surface * |
| 2921 | create_common_surface(void *shell, struct weston_surface *surface, |
| 2922 | const struct weston_shell_client *client) |
Pekka Paalanen | 9d1613e | 2011-11-25 12:09:16 +0200 | [diff] [blame] | 2923 | { |
Pekka Paalanen | 9d1613e | 2011-11-25 12:09:16 +0200 | [diff] [blame] | 2924 | struct shell_surface *shsurf; |
| 2925 | |
Ander Conselvan de Oliveira | 093bfa3 | 2012-03-27 17:36:41 +0300 | [diff] [blame] | 2926 | if (surface->configure) { |
Martin Minarik | 6d11836 | 2012-06-07 18:01:59 +0200 | [diff] [blame] | 2927 | weston_log("surface->configure already set\n"); |
Kristian Høgsberg | 45ba869 | 2012-05-21 14:27:33 -0400 | [diff] [blame] | 2928 | return NULL; |
Ander Conselvan de Oliveira | 093bfa3 | 2012-03-27 17:36:41 +0300 | [diff] [blame] | 2929 | } |
| 2930 | |
Pekka Paalanen | 9d1613e | 2011-11-25 12:09:16 +0200 | [diff] [blame] | 2931 | shsurf = calloc(1, sizeof *shsurf); |
| 2932 | if (!shsurf) { |
Martin Minarik | 6d11836 | 2012-06-07 18:01:59 +0200 | [diff] [blame] | 2933 | weston_log("no memory to allocate shell surface\n"); |
Kristian Høgsberg | 45ba869 | 2012-05-21 14:27:33 -0400 | [diff] [blame] | 2934 | return NULL; |
Pekka Paalanen | 9d1613e | 2011-11-25 12:09:16 +0200 | [diff] [blame] | 2935 | } |
| 2936 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 2937 | shsurf->view = weston_view_create(surface); |
| 2938 | if (!shsurf->view) { |
| 2939 | weston_log("no memory to allocate shell surface\n"); |
| 2940 | free(shsurf); |
| 2941 | return NULL; |
| 2942 | } |
| 2943 | |
Ander Conselvan de Oliveira | 093bfa3 | 2012-03-27 17:36:41 +0300 | [diff] [blame] | 2944 | surface->configure = shell_surface_configure; |
Giulio Camuffo | 7fe01b1 | 2013-03-28 18:02:42 +0100 | [diff] [blame] | 2945 | surface->configure_private = shsurf; |
Ander Conselvan de Oliveira | 093bfa3 | 2012-03-27 17:36:41 +0300 | [diff] [blame] | 2946 | |
Tiago Vignatti | bc052c9 | 2012-04-19 16:18:18 +0300 | [diff] [blame] | 2947 | shsurf->shell = (struct desktop_shell *) shell; |
Scott Moreau | ff1db4a | 2012-04-17 19:06:18 -0600 | [diff] [blame] | 2948 | shsurf->unresponsive = 0; |
Alex Wu | 4539b08 | 2012-03-01 12:57:46 +0800 | [diff] [blame] | 2949 | shsurf->saved_position_valid = false; |
Rafael Antognolli | 3c4e3f7 | 2013-12-03 15:35:46 -0200 | [diff] [blame] | 2950 | shsurf->saved_size_valid = false; |
Alex Wu | 7bcb8bd | 2012-04-27 09:07:24 +0800 | [diff] [blame] | 2951 | shsurf->saved_rotation_valid = false; |
Pekka Paalanen | 9d1613e | 2011-11-25 12:09:16 +0200 | [diff] [blame] | 2952 | shsurf->surface = surface; |
Alex Wu | 4539b08 | 2012-03-01 12:57:46 +0800 | [diff] [blame] | 2953 | shsurf->fullscreen.type = WL_SHELL_SURFACE_FULLSCREEN_METHOD_DEFAULT; |
| 2954 | shsurf->fullscreen.framerate = 0; |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 2955 | shsurf->fullscreen.black_view = NULL; |
Scott Moreau | ff1db4a | 2012-04-17 19:06:18 -0600 | [diff] [blame] | 2956 | shsurf->ping_timer = NULL; |
Alex Wu | 4539b08 | 2012-03-01 12:57:46 +0800 | [diff] [blame] | 2957 | wl_list_init(&shsurf->fullscreen.transform.link); |
| 2958 | |
Jason Ekstrand | 651f00e | 2013-06-14 10:07:54 -0500 | [diff] [blame] | 2959 | wl_signal_init(&shsurf->destroy_signal); |
Kristian Høgsberg | 27e3052 | 2012-04-11 23:18:23 -0400 | [diff] [blame] | 2960 | shsurf->surface_destroy_listener.notify = shell_handle_surface_destroy; |
Jason Ekstrand | 26ed73c | 2013-06-06 22:34:41 -0500 | [diff] [blame] | 2961 | wl_signal_add(&surface->destroy_signal, |
Kristian Høgsberg | 27e3052 | 2012-04-11 23:18:23 -0400 | [diff] [blame] | 2962 | &shsurf->surface_destroy_listener); |
Pekka Paalanen | 9d1613e | 2011-11-25 12:09:16 +0200 | [diff] [blame] | 2963 | |
| 2964 | /* init link so its safe to always remove it in destroy_shell_surface */ |
| 2965 | wl_list_init(&shsurf->link); |
Giulio Camuffo | 5085a75 | 2013-03-25 21:42:45 +0100 | [diff] [blame] | 2966 | wl_list_init(&shsurf->popup.grab_link); |
Pekka Paalanen | 9d1613e | 2011-11-25 12:09:16 +0200 | [diff] [blame] | 2967 | |
Pekka Paalanen | 460099f | 2012-01-20 16:48:25 +0200 | [diff] [blame] | 2968 | /* empty when not in use */ |
| 2969 | wl_list_init(&shsurf->rotation.transform.link); |
Kristian Høgsberg | 765e27b | 2012-01-27 13:36:13 -0500 | [diff] [blame] | 2970 | weston_matrix_init(&shsurf->rotation.rotation); |
Pekka Paalanen | 460099f | 2012-01-20 16:48:25 +0200 | [diff] [blame] | 2971 | |
Jonas Ådahl | 62fcd04 | 2012-06-13 00:01:23 +0200 | [diff] [blame] | 2972 | wl_list_init(&shsurf->workspace_transform.link); |
| 2973 | |
Philip Withnall | 648a4dd | 2013-11-25 18:01:44 +0000 | [diff] [blame] | 2974 | wl_list_init(&shsurf->children_link); |
| 2975 | wl_list_init(&shsurf->children_list); |
| 2976 | shsurf->parent = NULL; |
| 2977 | |
Pekka Paalanen | 9826223 | 2011-12-01 10:42:22 +0200 | [diff] [blame] | 2978 | shsurf->type = SHELL_SURFACE_NONE; |
Pekka Paalanen | 9d1613e | 2011-11-25 12:09:16 +0200 | [diff] [blame] | 2979 | |
Kristian Høgsberg | a61ca06 | 2012-05-22 16:05:52 -0400 | [diff] [blame] | 2980 | shsurf->client = client; |
| 2981 | |
Kristian Høgsberg | 45ba869 | 2012-05-21 14:27:33 -0400 | [diff] [blame] | 2982 | return shsurf; |
Tiago Vignatti | bc052c9 | 2012-04-19 16:18:18 +0300 | [diff] [blame] | 2983 | } |
| 2984 | |
Rafael Antognolli | e2a3455 | 2013-12-03 15:35:45 -0200 | [diff] [blame] | 2985 | static struct shell_surface * |
| 2986 | create_shell_surface(void *shell, struct weston_surface *surface, |
| 2987 | const struct weston_shell_client *client) |
| 2988 | { |
Kristian Høgsberg | c8f8dd8 | 2013-12-05 23:20:33 -0800 | [diff] [blame] | 2989 | return create_common_surface(shell, surface, client); |
Rafael Antognolli | e2a3455 | 2013-12-03 15:35:45 -0200 | [diff] [blame] | 2990 | } |
| 2991 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 2992 | static struct weston_view * |
| 2993 | get_primary_view(void *shell, struct shell_surface *shsurf) |
| 2994 | { |
| 2995 | return shsurf->view; |
| 2996 | } |
| 2997 | |
Tiago Vignatti | bc052c9 | 2012-04-19 16:18:18 +0300 | [diff] [blame] | 2998 | static void |
| 2999 | shell_get_shell_surface(struct wl_client *client, |
| 3000 | struct wl_resource *resource, |
| 3001 | uint32_t id, |
| 3002 | struct wl_resource *surface_resource) |
| 3003 | { |
Jason Ekstrand | 0f2ef7e | 2013-06-14 10:07:53 -0500 | [diff] [blame] | 3004 | struct weston_surface *surface = |
| 3005 | wl_resource_get_user_data(surface_resource); |
Jason Ekstrand | 651f00e | 2013-06-14 10:07:54 -0500 | [diff] [blame] | 3006 | struct desktop_shell *shell = wl_resource_get_user_data(resource); |
Tiago Vignatti | bc052c9 | 2012-04-19 16:18:18 +0300 | [diff] [blame] | 3007 | struct shell_surface *shsurf; |
| 3008 | |
| 3009 | if (get_shell_surface(surface)) { |
| 3010 | wl_resource_post_error(surface_resource, |
Kristian Høgsberg | 9540ea6 | 2012-05-21 14:28:57 -0400 | [diff] [blame] | 3011 | WL_DISPLAY_ERROR_INVALID_OBJECT, |
| 3012 | "desktop_shell::get_shell_surface already requested"); |
Tiago Vignatti | bc052c9 | 2012-04-19 16:18:18 +0300 | [diff] [blame] | 3013 | return; |
| 3014 | } |
| 3015 | |
Kristian Høgsberg | a61ca06 | 2012-05-22 16:05:52 -0400 | [diff] [blame] | 3016 | shsurf = create_shell_surface(shell, surface, &shell_client); |
Kristian Høgsberg | 9540ea6 | 2012-05-21 14:28:57 -0400 | [diff] [blame] | 3017 | if (!shsurf) { |
| 3018 | wl_resource_post_error(surface_resource, |
| 3019 | WL_DISPLAY_ERROR_INVALID_OBJECT, |
| 3020 | "surface->configure already set"); |
| 3021 | return; |
| 3022 | } |
Tiago Vignatti | bc052c9 | 2012-04-19 16:18:18 +0300 | [diff] [blame] | 3023 | |
Jason Ekstrand | a85118c | 2013-06-27 20:17:02 -0500 | [diff] [blame] | 3024 | shsurf->resource = |
| 3025 | wl_resource_create(client, |
| 3026 | &wl_shell_surface_interface, 1, id); |
| 3027 | wl_resource_set_implementation(shsurf->resource, |
| 3028 | &shell_surface_implementation, |
| 3029 | shsurf, shell_destroy_shell_surface); |
Pekka Paalanen | 9d1613e | 2011-11-25 12:09:16 +0200 | [diff] [blame] | 3030 | } |
| 3031 | |
Rafael Antognolli | e2a3455 | 2013-12-03 15:35:45 -0200 | [diff] [blame] | 3032 | static bool |
| 3033 | shell_surface_is_wl_shell_surface(struct shell_surface *shsurf) |
| 3034 | { |
| 3035 | return wl_resource_instance_of(shsurf->resource, |
| 3036 | &wl_shell_surface_interface, |
| 3037 | &shell_surface_implementation); |
| 3038 | } |
| 3039 | |
Pekka Paalanen | 9d1613e | 2011-11-25 12:09:16 +0200 | [diff] [blame] | 3040 | static const struct wl_shell_interface shell_implementation = { |
Pekka Paalanen | 4622967 | 2011-11-29 15:49:31 +0200 | [diff] [blame] | 3041 | shell_get_shell_surface |
Kristian Høgsberg | 4cca349 | 2011-01-18 07:53:49 -0500 | [diff] [blame] | 3042 | }; |
| 3043 | |
Rafael Antognolli | e2a3455 | 2013-12-03 15:35:45 -0200 | [diff] [blame] | 3044 | /**************************** |
| 3045 | * xdg-shell implementation */ |
| 3046 | |
| 3047 | static void |
| 3048 | xdg_surface_destroy(struct wl_client *client, |
| 3049 | struct wl_resource *resource) |
| 3050 | { |
| 3051 | wl_resource_destroy(resource); |
| 3052 | } |
| 3053 | |
| 3054 | static void |
| 3055 | xdg_surface_pong(struct wl_client *client, |
| 3056 | struct wl_resource *resource, |
| 3057 | uint32_t serial) |
| 3058 | { |
| 3059 | struct shell_surface *shsurf = wl_resource_get_user_data(resource); |
| 3060 | |
| 3061 | surface_pong(shsurf, serial); |
| 3062 | } |
| 3063 | |
| 3064 | static void |
| 3065 | xdg_surface_set_app_id(struct wl_client *client, |
| 3066 | struct wl_resource *resource, |
| 3067 | const char *app_id) |
| 3068 | { |
| 3069 | struct shell_surface *shsurf = wl_resource_get_user_data(resource); |
| 3070 | |
| 3071 | free(shsurf->class); |
| 3072 | shsurf->class = strdup(app_id); |
| 3073 | } |
| 3074 | |
| 3075 | static void |
| 3076 | xdg_surface_set_title(struct wl_client *client, |
| 3077 | struct wl_resource *resource, const char *title) |
| 3078 | { |
| 3079 | struct shell_surface *shsurf = wl_resource_get_user_data(resource); |
| 3080 | |
| 3081 | set_title(shsurf, title); |
| 3082 | } |
| 3083 | |
| 3084 | static void |
| 3085 | xdg_surface_move(struct wl_client *client, struct wl_resource *resource, |
| 3086 | struct wl_resource *seat_resource, uint32_t serial) |
| 3087 | { |
| 3088 | common_surface_move(resource, seat_resource, serial); |
| 3089 | } |
| 3090 | |
| 3091 | static void |
| 3092 | xdg_surface_resize(struct wl_client *client, struct wl_resource *resource, |
| 3093 | struct wl_resource *seat_resource, uint32_t serial, |
| 3094 | uint32_t edges) |
| 3095 | { |
| 3096 | common_surface_resize(resource, seat_resource, serial, edges); |
| 3097 | } |
| 3098 | |
| 3099 | static void |
| 3100 | xdg_surface_set_output(struct wl_client *client, |
| 3101 | struct wl_resource *resource, |
| 3102 | struct wl_resource *output_resource) |
| 3103 | { |
| 3104 | struct shell_surface *shsurf = wl_resource_get_user_data(resource); |
| 3105 | struct weston_output *output; |
| 3106 | |
| 3107 | if (output_resource) |
| 3108 | output = wl_resource_get_user_data(output_resource); |
| 3109 | else |
| 3110 | output = NULL; |
| 3111 | |
Rafael Antognolli | 65f98d8 | 2013-12-03 15:35:47 -0200 | [diff] [blame] | 3112 | shsurf->recommended_output = output; |
Rafael Antognolli | e2a3455 | 2013-12-03 15:35:45 -0200 | [diff] [blame] | 3113 | } |
| 3114 | |
| 3115 | static void |
| 3116 | xdg_surface_set_fullscreen(struct wl_client *client, |
| 3117 | struct wl_resource *resource) |
| 3118 | { |
| 3119 | struct shell_surface *shsurf = wl_resource_get_user_data(resource); |
| 3120 | |
| 3121 | if (shsurf->type != SHELL_SURFACE_TOPLEVEL) |
| 3122 | return; |
| 3123 | |
Kristian Høgsberg | e960b3f | 2013-12-05 22:04:42 -0800 | [diff] [blame] | 3124 | if (!shsurf->next_state.fullscreen) |
Rafael Antognolli | e2a3455 | 2013-12-03 15:35:45 -0200 | [diff] [blame] | 3125 | set_fullscreen(shsurf, |
| 3126 | WL_SHELL_SURFACE_FULLSCREEN_METHOD_DEFAULT, |
Rafael Antognolli | 65f98d8 | 2013-12-03 15:35:47 -0200 | [diff] [blame] | 3127 | 0, shsurf->recommended_output); |
Rafael Antognolli | e2a3455 | 2013-12-03 15:35:45 -0200 | [diff] [blame] | 3128 | } |
| 3129 | |
| 3130 | static void |
| 3131 | xdg_surface_unset_fullscreen(struct wl_client *client, |
| 3132 | struct wl_resource *resource) |
| 3133 | { |
| 3134 | struct shell_surface *shsurf = wl_resource_get_user_data(resource); |
Rafael Antognolli | 3c4e3f7 | 2013-12-03 15:35:46 -0200 | [diff] [blame] | 3135 | int32_t width, height; |
Rafael Antognolli | e2a3455 | 2013-12-03 15:35:45 -0200 | [diff] [blame] | 3136 | |
| 3137 | if (shsurf->type != SHELL_SURFACE_TOPLEVEL) |
| 3138 | return; |
| 3139 | |
Rafael Antognolli | 3c4e3f7 | 2013-12-03 15:35:46 -0200 | [diff] [blame] | 3140 | if (!shsurf->next_state.fullscreen) |
| 3141 | return; |
| 3142 | |
Rafael Antognolli | e2a3455 | 2013-12-03 15:35:45 -0200 | [diff] [blame] | 3143 | shsurf->next_state.fullscreen = false; |
| 3144 | shsurf->state_changed = true; |
Rafael Antognolli | 3c4e3f7 | 2013-12-03 15:35:46 -0200 | [diff] [blame] | 3145 | |
| 3146 | if (shsurf->saved_size_valid) { |
| 3147 | width = shsurf->saved_width; |
| 3148 | height = shsurf->saved_height; |
| 3149 | shsurf->saved_size_valid = false; |
| 3150 | } else { |
| 3151 | width = shsurf->surface->width; |
| 3152 | height = shsurf->surface->height; |
| 3153 | } |
| 3154 | |
| 3155 | shsurf->client->send_configure(shsurf->surface, 0, width, height); |
Rafael Antognolli | e2a3455 | 2013-12-03 15:35:45 -0200 | [diff] [blame] | 3156 | } |
| 3157 | |
| 3158 | static void |
| 3159 | xdg_surface_set_maximized(struct wl_client *client, |
| 3160 | struct wl_resource *resource) |
| 3161 | { |
| 3162 | struct shell_surface *shsurf = wl_resource_get_user_data(resource); |
| 3163 | |
| 3164 | if (shsurf->type != SHELL_SURFACE_TOPLEVEL) |
| 3165 | return; |
| 3166 | |
Kristian Høgsberg | c2745b1 | 2013-12-05 22:00:40 -0800 | [diff] [blame] | 3167 | if (!shsurf->next_state.maximized) |
Rafael Antognolli | 65f98d8 | 2013-12-03 15:35:47 -0200 | [diff] [blame] | 3168 | set_maximized(shsurf, NULL); |
Rafael Antognolli | e2a3455 | 2013-12-03 15:35:45 -0200 | [diff] [blame] | 3169 | } |
| 3170 | |
| 3171 | static void |
| 3172 | xdg_surface_unset_maximized(struct wl_client *client, |
| 3173 | struct wl_resource *resource) |
| 3174 | { |
| 3175 | struct shell_surface *shsurf = wl_resource_get_user_data(resource); |
Rafael Antognolli | 3c4e3f7 | 2013-12-03 15:35:46 -0200 | [diff] [blame] | 3176 | int32_t width, height; |
Rafael Antognolli | e2a3455 | 2013-12-03 15:35:45 -0200 | [diff] [blame] | 3177 | |
| 3178 | if (shsurf->type != SHELL_SURFACE_TOPLEVEL) |
| 3179 | return; |
| 3180 | |
Rafael Antognolli | 3c4e3f7 | 2013-12-03 15:35:46 -0200 | [diff] [blame] | 3181 | if (!shsurf->next_state.maximized) |
| 3182 | return; |
| 3183 | |
Rafael Antognolli | e2a3455 | 2013-12-03 15:35:45 -0200 | [diff] [blame] | 3184 | shsurf->next_state.maximized = false; |
| 3185 | shsurf->state_changed = true; |
Rafael Antognolli | 3c4e3f7 | 2013-12-03 15:35:46 -0200 | [diff] [blame] | 3186 | |
| 3187 | if (shsurf->saved_size_valid) { |
| 3188 | width = shsurf->saved_width; |
| 3189 | height = shsurf->saved_height; |
| 3190 | shsurf->saved_size_valid = false; |
| 3191 | } else { |
| 3192 | width = shsurf->surface->width; |
| 3193 | height = shsurf->surface->height; |
| 3194 | } |
| 3195 | |
| 3196 | shsurf->client->send_configure(shsurf->surface, 0, width, height); |
Rafael Antognolli | e2a3455 | 2013-12-03 15:35:45 -0200 | [diff] [blame] | 3197 | } |
| 3198 | |
| 3199 | static const struct xdg_surface_interface xdg_surface_implementation = { |
| 3200 | xdg_surface_destroy, |
| 3201 | xdg_surface_set_transient_for, |
| 3202 | xdg_surface_set_title, |
| 3203 | xdg_surface_set_app_id, |
| 3204 | xdg_surface_pong, |
| 3205 | xdg_surface_move, |
| 3206 | xdg_surface_resize, |
| 3207 | xdg_surface_set_output, |
| 3208 | xdg_surface_set_fullscreen, |
| 3209 | xdg_surface_unset_fullscreen, |
| 3210 | xdg_surface_set_maximized, |
| 3211 | xdg_surface_unset_maximized, |
| 3212 | NULL /* set_minimized */ |
| 3213 | }; |
| 3214 | |
| 3215 | static void |
| 3216 | xdg_send_configure(struct weston_surface *surface, |
| 3217 | uint32_t edges, int32_t width, int32_t height) |
| 3218 | { |
| 3219 | struct shell_surface *shsurf = get_shell_surface(surface); |
| 3220 | |
| 3221 | xdg_surface_send_configure(shsurf->resource, edges, width, height); |
| 3222 | } |
| 3223 | |
| 3224 | static const struct weston_shell_client xdg_client = { |
| 3225 | xdg_send_configure |
| 3226 | }; |
| 3227 | |
| 3228 | static void |
| 3229 | xdg_use_unstable_version(struct wl_client *client, |
| 3230 | struct wl_resource *resource, |
| 3231 | int32_t version) |
| 3232 | { |
| 3233 | if (version > 1) { |
| 3234 | wl_resource_post_error(resource, |
| 3235 | 1, |
| 3236 | "xdg-shell:: version not implemented yet."); |
| 3237 | return; |
| 3238 | } |
| 3239 | } |
| 3240 | |
| 3241 | static struct shell_surface * |
| 3242 | create_xdg_surface(void *shell, struct weston_surface *surface, |
| 3243 | const struct weston_shell_client *client) |
| 3244 | { |
| 3245 | struct shell_surface *shsurf; |
Rafael Antognolli | e2a3455 | 2013-12-03 15:35:45 -0200 | [diff] [blame] | 3246 | |
Kristian Høgsberg | c8f8dd8 | 2013-12-05 23:20:33 -0800 | [diff] [blame] | 3247 | shsurf = create_common_surface(shell, surface, client); |
| 3248 | shsurf->type = SHELL_SURFACE_TOPLEVEL; |
Rafael Antognolli | e2a3455 | 2013-12-03 15:35:45 -0200 | [diff] [blame] | 3249 | |
| 3250 | return shsurf; |
| 3251 | } |
| 3252 | |
| 3253 | static void |
| 3254 | xdg_get_xdg_surface(struct wl_client *client, |
| 3255 | struct wl_resource *resource, |
| 3256 | uint32_t id, |
| 3257 | struct wl_resource *surface_resource) |
| 3258 | { |
| 3259 | struct weston_surface *surface = |
| 3260 | wl_resource_get_user_data(surface_resource); |
| 3261 | struct desktop_shell *shell = wl_resource_get_user_data(resource); |
| 3262 | struct shell_surface *shsurf; |
| 3263 | |
| 3264 | if (get_shell_surface(surface)) { |
| 3265 | wl_resource_post_error(surface_resource, |
| 3266 | WL_DISPLAY_ERROR_INVALID_OBJECT, |
| 3267 | "desktop_shell::get_shell_surface already requested"); |
| 3268 | return; |
| 3269 | } |
| 3270 | |
| 3271 | shsurf = create_xdg_surface(shell, surface, &xdg_client); |
| 3272 | if (!shsurf) { |
| 3273 | wl_resource_post_error(surface_resource, |
| 3274 | WL_DISPLAY_ERROR_INVALID_OBJECT, |
| 3275 | "surface->configure already set"); |
| 3276 | return; |
| 3277 | } |
| 3278 | |
| 3279 | shsurf->resource = |
| 3280 | wl_resource_create(client, |
| 3281 | &xdg_surface_interface, 1, id); |
| 3282 | wl_resource_set_implementation(shsurf->resource, |
| 3283 | &xdg_surface_implementation, |
| 3284 | shsurf, shell_destroy_shell_surface); |
| 3285 | } |
| 3286 | |
| 3287 | static bool |
| 3288 | shell_surface_is_xdg_surface(struct shell_surface *shsurf) |
| 3289 | { |
| 3290 | return wl_resource_instance_of(shsurf->resource, |
| 3291 | &xdg_surface_interface, |
| 3292 | &xdg_surface_implementation); |
| 3293 | } |
| 3294 | |
| 3295 | /* xdg-popup implementation */ |
| 3296 | |
| 3297 | static void |
| 3298 | xdg_popup_destroy(struct wl_client *client, |
| 3299 | struct wl_resource *resource) |
| 3300 | { |
| 3301 | wl_resource_destroy(resource); |
| 3302 | } |
| 3303 | |
| 3304 | static void |
| 3305 | xdg_popup_pong(struct wl_client *client, |
| 3306 | struct wl_resource *resource, |
| 3307 | uint32_t serial) |
| 3308 | { |
| 3309 | struct shell_surface *shsurf = wl_resource_get_user_data(resource); |
| 3310 | |
| 3311 | surface_pong(shsurf, serial); |
| 3312 | } |
| 3313 | |
| 3314 | static const struct xdg_popup_interface xdg_popup_implementation = { |
| 3315 | xdg_popup_destroy, |
| 3316 | xdg_popup_pong |
| 3317 | }; |
| 3318 | |
| 3319 | static void |
| 3320 | xdg_popup_send_configure(struct weston_surface *surface, |
| 3321 | uint32_t edges, int32_t width, int32_t height) |
| 3322 | { |
| 3323 | } |
| 3324 | |
| 3325 | static const struct weston_shell_client xdg_popup_client = { |
| 3326 | xdg_popup_send_configure |
| 3327 | }; |
| 3328 | |
| 3329 | static struct shell_surface * |
| 3330 | create_xdg_popup(void *shell, struct weston_surface *surface, |
| 3331 | const struct weston_shell_client *client, |
| 3332 | struct weston_surface *parent, |
| 3333 | struct shell_seat *seat, |
| 3334 | uint32_t serial, |
| 3335 | int32_t x, int32_t y) |
| 3336 | { |
| 3337 | struct shell_surface *shsurf; |
Rafael Antognolli | e2a3455 | 2013-12-03 15:35:45 -0200 | [diff] [blame] | 3338 | |
Kristian Høgsberg | c8f8dd8 | 2013-12-05 23:20:33 -0800 | [diff] [blame] | 3339 | shsurf = create_common_surface(shell, surface, client); |
| 3340 | shsurf->type = SHELL_SURFACE_POPUP; |
Rafael Antognolli | e2a3455 | 2013-12-03 15:35:45 -0200 | [diff] [blame] | 3341 | shsurf->popup.shseat = seat; |
| 3342 | shsurf->popup.serial = serial; |
| 3343 | shsurf->popup.x = x; |
| 3344 | shsurf->popup.y = y; |
| 3345 | shell_surface_set_parent(shsurf, parent); |
| 3346 | |
| 3347 | return shsurf; |
| 3348 | } |
| 3349 | |
| 3350 | static void |
| 3351 | xdg_get_xdg_popup(struct wl_client *client, |
| 3352 | struct wl_resource *resource, |
| 3353 | uint32_t id, |
| 3354 | struct wl_resource *surface_resource, |
| 3355 | struct wl_resource *parent_resource, |
| 3356 | struct wl_resource *seat_resource, |
| 3357 | uint32_t serial, |
| 3358 | int32_t x, int32_t y, uint32_t flags) |
| 3359 | { |
| 3360 | struct weston_surface *surface = |
| 3361 | wl_resource_get_user_data(surface_resource); |
| 3362 | struct desktop_shell *shell = wl_resource_get_user_data(resource); |
| 3363 | struct shell_surface *shsurf; |
| 3364 | struct weston_surface *parent; |
| 3365 | struct shell_seat *seat; |
| 3366 | |
| 3367 | if (get_shell_surface(surface)) { |
| 3368 | wl_resource_post_error(surface_resource, |
| 3369 | WL_DISPLAY_ERROR_INVALID_OBJECT, |
| 3370 | "desktop_shell::get_shell_surface already requested"); |
| 3371 | return; |
| 3372 | } |
| 3373 | |
| 3374 | if (!parent_resource) { |
| 3375 | wl_resource_post_error(surface_resource, |
| 3376 | WL_DISPLAY_ERROR_INVALID_OBJECT, |
| 3377 | "xdg_shell::get_xdg_popup requires a parent shell surface"); |
| 3378 | } |
| 3379 | |
| 3380 | parent = wl_resource_get_user_data(parent_resource); |
| 3381 | seat = get_shell_seat(wl_resource_get_user_data(seat_resource));; |
| 3382 | |
| 3383 | shsurf = create_xdg_popup(shell, surface, &xdg_popup_client, |
| 3384 | parent, seat, serial, x, y); |
| 3385 | if (!shsurf) { |
| 3386 | wl_resource_post_error(surface_resource, |
| 3387 | WL_DISPLAY_ERROR_INVALID_OBJECT, |
| 3388 | "surface->configure already set"); |
| 3389 | return; |
| 3390 | } |
| 3391 | |
| 3392 | shsurf->resource = |
| 3393 | wl_resource_create(client, |
| 3394 | &xdg_popup_interface, 1, id); |
| 3395 | wl_resource_set_implementation(shsurf->resource, |
| 3396 | &xdg_popup_implementation, |
| 3397 | shsurf, shell_destroy_shell_surface); |
| 3398 | } |
| 3399 | |
| 3400 | static bool |
| 3401 | shell_surface_is_xdg_popup(struct shell_surface *shsurf) |
| 3402 | { |
| 3403 | return wl_resource_instance_of(shsurf->resource, |
| 3404 | &xdg_popup_interface, |
| 3405 | &xdg_popup_implementation); |
| 3406 | } |
| 3407 | |
| 3408 | static const struct xdg_shell_interface xdg_implementation = { |
| 3409 | xdg_use_unstable_version, |
| 3410 | xdg_get_xdg_surface, |
| 3411 | xdg_get_xdg_popup |
| 3412 | }; |
| 3413 | |
| 3414 | static int |
| 3415 | xdg_shell_unversioned_dispatch(const void *implementation, |
| 3416 | void *_target, uint32_t opcode, |
| 3417 | const struct wl_message *message, |
| 3418 | union wl_argument *args) |
| 3419 | { |
| 3420 | struct wl_resource *resource = _target; |
| 3421 | struct desktop_shell *shell = wl_resource_get_user_data(resource); |
| 3422 | |
| 3423 | if (opcode != 0) { |
| 3424 | wl_resource_post_error(resource, |
| 3425 | WL_DISPLAY_ERROR_INVALID_OBJECT, |
| 3426 | "must call use_unstable_version first"); |
| 3427 | return 0; |
| 3428 | } |
| 3429 | |
| 3430 | #define XDG_SERVER_VERSION 1 |
| 3431 | |
Kristian Høgsberg | 8d344a0 | 2013-12-08 22:27:11 -0800 | [diff] [blame] | 3432 | static_assert(XDG_SERVER_VERSION == XDG_SHELL_VERSION_CURRENT, |
| 3433 | "shell implementation doesn't match protocol version"); |
| 3434 | |
Rafael Antognolli | e2a3455 | 2013-12-03 15:35:45 -0200 | [diff] [blame] | 3435 | if (args[0].i != XDG_SERVER_VERSION) { |
| 3436 | wl_resource_post_error(resource, |
| 3437 | WL_DISPLAY_ERROR_INVALID_OBJECT, |
| 3438 | "incompatible version, server is %d " |
| 3439 | "client wants %d", |
| 3440 | XDG_SERVER_VERSION, args[0].i); |
| 3441 | return 0; |
| 3442 | } |
| 3443 | |
| 3444 | wl_resource_set_implementation(resource, &xdg_implementation, |
| 3445 | shell, NULL); |
| 3446 | |
| 3447 | return 1; |
| 3448 | } |
| 3449 | |
| 3450 | /* end of xdg-shell implementation */ |
| 3451 | /***********************************/ |
| 3452 | |
Kristian Høgsberg | 0793756 | 2011-04-12 17:25:42 -0400 | [diff] [blame] | 3453 | static void |
Ander Conselvan de Oliveira | 859e885 | 2013-02-21 18:35:21 +0200 | [diff] [blame] | 3454 | shell_fade(struct desktop_shell *shell, enum fade_type type); |
| 3455 | |
| 3456 | static int |
| 3457 | screensaver_timeout(void *data) |
| 3458 | { |
| 3459 | struct desktop_shell *shell = data; |
| 3460 | |
| 3461 | shell_fade(shell, FADE_OUT); |
| 3462 | |
| 3463 | return 1; |
| 3464 | } |
| 3465 | |
| 3466 | static void |
Kristian Høgsberg | 8334bc1 | 2012-01-03 10:29:47 -0500 | [diff] [blame] | 3467 | handle_screensaver_sigchld(struct weston_process *proc, int status) |
Pekka Paalanen | 18027e5 | 2011-12-02 16:31:49 +0200 | [diff] [blame] | 3468 | { |
Ander Conselvan de Oliveira | 18639f8 | 2013-02-15 18:44:19 +0200 | [diff] [blame] | 3469 | struct desktop_shell *shell = |
| 3470 | container_of(proc, struct desktop_shell, screensaver.process); |
Ander Conselvan de Oliveira | 18639f8 | 2013-02-15 18:44:19 +0200 | [diff] [blame] | 3471 | |
Pekka Paalanen | 18027e5 | 2011-12-02 16:31:49 +0200 | [diff] [blame] | 3472 | proc->pid = 0; |
Ander Conselvan de Oliveira | 18639f8 | 2013-02-15 18:44:19 +0200 | [diff] [blame] | 3473 | |
| 3474 | if (shell->locked) |
Ander Conselvan de Oliveira | b17537e | 2013-02-22 14:16:18 +0200 | [diff] [blame] | 3475 | weston_compositor_sleep(shell->compositor); |
Pekka Paalanen | 18027e5 | 2011-12-02 16:31:49 +0200 | [diff] [blame] | 3476 | } |
| 3477 | |
| 3478 | static void |
Tiago Vignatti | be14326 | 2012-04-16 17:31:41 +0300 | [diff] [blame] | 3479 | launch_screensaver(struct desktop_shell *shell) |
Pekka Paalanen | 77346a6 | 2011-11-30 16:26:35 +0200 | [diff] [blame] | 3480 | { |
| 3481 | if (shell->screensaver.binding) |
| 3482 | return; |
| 3483 | |
Ander Conselvan de Oliveira | dda9d78 | 2013-02-22 14:16:19 +0200 | [diff] [blame] | 3484 | if (!shell->screensaver.path) { |
| 3485 | weston_compositor_sleep(shell->compositor); |
Pekka Paalanen | e955f1e | 2011-12-07 11:49:52 +0200 | [diff] [blame] | 3486 | return; |
Ander Conselvan de Oliveira | dda9d78 | 2013-02-22 14:16:19 +0200 | [diff] [blame] | 3487 | } |
Pekka Paalanen | e955f1e | 2011-12-07 11:49:52 +0200 | [diff] [blame] | 3488 | |
Kristian Høgsberg | 32bed57 | 2012-03-01 17:11:36 -0500 | [diff] [blame] | 3489 | if (shell->screensaver.process.pid != 0) { |
Martin Minarik | 6d11836 | 2012-06-07 18:01:59 +0200 | [diff] [blame] | 3490 | weston_log("old screensaver still running\n"); |
Kristian Høgsberg | 32bed57 | 2012-03-01 17:11:36 -0500 | [diff] [blame] | 3491 | return; |
| 3492 | } |
| 3493 | |
Kristian Høgsberg | 8334bc1 | 2012-01-03 10:29:47 -0500 | [diff] [blame] | 3494 | weston_client_launch(shell->compositor, |
Pekka Paalanen | 18027e5 | 2011-12-02 16:31:49 +0200 | [diff] [blame] | 3495 | &shell->screensaver.process, |
Pekka Paalanen | e955f1e | 2011-12-07 11:49:52 +0200 | [diff] [blame] | 3496 | shell->screensaver.path, |
Pekka Paalanen | 18027e5 | 2011-12-02 16:31:49 +0200 | [diff] [blame] | 3497 | handle_screensaver_sigchld); |
Pekka Paalanen | 77346a6 | 2011-11-30 16:26:35 +0200 | [diff] [blame] | 3498 | } |
| 3499 | |
| 3500 | static void |
Tiago Vignatti | be14326 | 2012-04-16 17:31:41 +0300 | [diff] [blame] | 3501 | terminate_screensaver(struct desktop_shell *shell) |
Pekka Paalanen | 77346a6 | 2011-11-30 16:26:35 +0200 | [diff] [blame] | 3502 | { |
Pekka Paalanen | 18027e5 | 2011-12-02 16:31:49 +0200 | [diff] [blame] | 3503 | if (shell->screensaver.process.pid == 0) |
| 3504 | return; |
| 3505 | |
| 3506 | kill(shell->screensaver.process.pid, SIGTERM); |
Pekka Paalanen | 77346a6 | 2011-11-30 16:26:35 +0200 | [diff] [blame] | 3507 | } |
| 3508 | |
| 3509 | static void |
Jason Ekstrand | 918f2dd | 2013-12-02 21:01:53 -0600 | [diff] [blame] | 3510 | configure_static_view(struct weston_view *ev, struct weston_layer *layer) |
Kristian Høgsberg | 962342c | 2012-06-26 16:29:50 -0400 | [diff] [blame] | 3511 | { |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 3512 | struct weston_view *v, *next; |
Kristian Høgsberg | 962342c | 2012-06-26 16:29:50 -0400 | [diff] [blame] | 3513 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 3514 | wl_list_for_each_safe(v, next, &layer->view_list, layer_link) { |
| 3515 | if (v->output == ev->output && v != ev) { |
| 3516 | weston_view_unmap(v); |
| 3517 | v->surface->configure = NULL; |
Kristian Høgsberg | 962342c | 2012-06-26 16:29:50 -0400 | [diff] [blame] | 3518 | } |
| 3519 | } |
| 3520 | |
Jason Ekstrand | 918f2dd | 2013-12-02 21:01:53 -0600 | [diff] [blame] | 3521 | weston_view_set_position(ev, ev->output->x, ev->output->y); |
Kristian Høgsberg | 962342c | 2012-06-26 16:29:50 -0400 | [diff] [blame] | 3522 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 3523 | if (wl_list_empty(&ev->layer_link)) { |
| 3524 | wl_list_insert(&layer->view_list, &ev->layer_link); |
| 3525 | weston_compositor_schedule_repaint(ev->surface->compositor); |
Kristian Høgsberg | 962342c | 2012-06-26 16:29:50 -0400 | [diff] [blame] | 3526 | } |
| 3527 | } |
| 3528 | |
| 3529 | static void |
Jason Ekstrand | 918f2dd | 2013-12-02 21:01:53 -0600 | [diff] [blame] | 3530 | 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] | 3531 | { |
Giulio Camuffo | 7fe01b1 | 2013-03-28 18:02:42 +0100 | [diff] [blame] | 3532 | struct desktop_shell *shell = es->configure_private; |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 3533 | struct weston_view *view; |
Kristian Høgsberg | af7b1ff | 2012-06-26 21:19:23 -0400 | [diff] [blame] | 3534 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 3535 | view = container_of(es->views.next, struct weston_view, surface_link); |
| 3536 | |
Jason Ekstrand | 918f2dd | 2013-12-02 21:01:53 -0600 | [diff] [blame] | 3537 | configure_static_view(view, &shell->background_layer); |
Kristian Høgsberg | af7b1ff | 2012-06-26 21:19:23 -0400 | [diff] [blame] | 3538 | } |
| 3539 | |
| 3540 | static void |
Kristian Høgsberg | 7584062 | 2011-09-06 13:48:16 -0400 | [diff] [blame] | 3541 | desktop_shell_set_background(struct wl_client *client, |
| 3542 | struct wl_resource *resource, |
Benjamin Franzke | d0f79ab | 2011-11-22 12:43:52 +0100 | [diff] [blame] | 3543 | struct wl_resource *output_resource, |
Kristian Høgsberg | 7584062 | 2011-09-06 13:48:16 -0400 | [diff] [blame] | 3544 | struct wl_resource *surface_resource) |
| 3545 | { |
Jason Ekstrand | 651f00e | 2013-06-14 10:07:54 -0500 | [diff] [blame] | 3546 | struct desktop_shell *shell = wl_resource_get_user_data(resource); |
Jason Ekstrand | 0f2ef7e | 2013-06-14 10:07:53 -0500 | [diff] [blame] | 3547 | struct weston_surface *surface = |
| 3548 | wl_resource_get_user_data(surface_resource); |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 3549 | struct weston_view *view, *next; |
Kristian Høgsberg | 7584062 | 2011-09-06 13:48:16 -0400 | [diff] [blame] | 3550 | |
Kristian Høgsberg | 962342c | 2012-06-26 16:29:50 -0400 | [diff] [blame] | 3551 | if (surface->configure) { |
| 3552 | wl_resource_post_error(surface_resource, |
| 3553 | WL_DISPLAY_ERROR_INVALID_OBJECT, |
| 3554 | "surface role already assigned"); |
| 3555 | return; |
| 3556 | } |
Benjamin Franzke | d0f79ab | 2011-11-22 12:43:52 +0100 | [diff] [blame] | 3557 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 3558 | wl_list_for_each_safe(view, next, &surface->views, surface_link) |
| 3559 | weston_view_destroy(view); |
| 3560 | view = weston_view_create(surface); |
| 3561 | |
Kristian Høgsberg | 962342c | 2012-06-26 16:29:50 -0400 | [diff] [blame] | 3562 | surface->configure = background_configure; |
Giulio Camuffo | 7fe01b1 | 2013-03-28 18:02:42 +0100 | [diff] [blame] | 3563 | surface->configure_private = shell; |
Jason Ekstrand | a0d2dde | 2013-06-14 10:08:01 -0500 | [diff] [blame] | 3564 | surface->output = wl_resource_get_user_data(output_resource); |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 3565 | view->output = surface->output; |
Kristian Høgsberg | eae5de7 | 2012-04-11 22:42:15 -0400 | [diff] [blame] | 3566 | desktop_shell_send_configure(resource, 0, |
Kristian Høgsberg | 0b5cd0c | 2012-03-04 21:57:37 -0500 | [diff] [blame] | 3567 | surface_resource, |
Scott Moreau | 1bad5db | 2012-08-18 01:04:05 -0600 | [diff] [blame] | 3568 | surface->output->width, |
| 3569 | surface->output->height); |
Kristian Høgsberg | 7584062 | 2011-09-06 13:48:16 -0400 | [diff] [blame] | 3570 | } |
| 3571 | |
| 3572 | static void |
Jason Ekstrand | 918f2dd | 2013-12-02 21:01:53 -0600 | [diff] [blame] | 3573 | 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] | 3574 | { |
Giulio Camuffo | 7fe01b1 | 2013-03-28 18:02:42 +0100 | [diff] [blame] | 3575 | struct desktop_shell *shell = es->configure_private; |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 3576 | struct weston_view *view; |
Kristian Høgsberg | af7b1ff | 2012-06-26 21:19:23 -0400 | [diff] [blame] | 3577 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 3578 | view = container_of(es->views.next, struct weston_view, surface_link); |
| 3579 | |
Jason Ekstrand | 918f2dd | 2013-12-02 21:01:53 -0600 | [diff] [blame] | 3580 | configure_static_view(view, &shell->panel_layer); |
Kristian Høgsberg | af7b1ff | 2012-06-26 21:19:23 -0400 | [diff] [blame] | 3581 | } |
| 3582 | |
| 3583 | static void |
Kristian Høgsberg | 7584062 | 2011-09-06 13:48:16 -0400 | [diff] [blame] | 3584 | desktop_shell_set_panel(struct wl_client *client, |
| 3585 | struct wl_resource *resource, |
Benjamin Franzke | d0f79ab | 2011-11-22 12:43:52 +0100 | [diff] [blame] | 3586 | struct wl_resource *output_resource, |
Kristian Høgsberg | 7584062 | 2011-09-06 13:48:16 -0400 | [diff] [blame] | 3587 | struct wl_resource *surface_resource) |
| 3588 | { |
Jason Ekstrand | 651f00e | 2013-06-14 10:07:54 -0500 | [diff] [blame] | 3589 | struct desktop_shell *shell = wl_resource_get_user_data(resource); |
Jason Ekstrand | 0f2ef7e | 2013-06-14 10:07:53 -0500 | [diff] [blame] | 3590 | struct weston_surface *surface = |
| 3591 | wl_resource_get_user_data(surface_resource); |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 3592 | struct weston_view *view, *next; |
Kristian Høgsberg | 7584062 | 2011-09-06 13:48:16 -0400 | [diff] [blame] | 3593 | |
Kristian Høgsberg | af7b1ff | 2012-06-26 21:19:23 -0400 | [diff] [blame] | 3594 | if (surface->configure) { |
| 3595 | wl_resource_post_error(surface_resource, |
| 3596 | WL_DISPLAY_ERROR_INVALID_OBJECT, |
| 3597 | "surface role already assigned"); |
| 3598 | return; |
| 3599 | } |
Benjamin Franzke | d0f79ab | 2011-11-22 12:43:52 +0100 | [diff] [blame] | 3600 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 3601 | wl_list_for_each_safe(view, next, &surface->views, surface_link) |
| 3602 | weston_view_destroy(view); |
| 3603 | view = weston_view_create(surface); |
| 3604 | |
Kristian Høgsberg | af7b1ff | 2012-06-26 21:19:23 -0400 | [diff] [blame] | 3605 | surface->configure = panel_configure; |
Giulio Camuffo | 7fe01b1 | 2013-03-28 18:02:42 +0100 | [diff] [blame] | 3606 | surface->configure_private = shell; |
Jason Ekstrand | a0d2dde | 2013-06-14 10:08:01 -0500 | [diff] [blame] | 3607 | surface->output = wl_resource_get_user_data(output_resource); |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 3608 | view->output = surface->output; |
Kristian Høgsberg | eae5de7 | 2012-04-11 22:42:15 -0400 | [diff] [blame] | 3609 | desktop_shell_send_configure(resource, 0, |
Kristian Høgsberg | af7b1ff | 2012-06-26 21:19:23 -0400 | [diff] [blame] | 3610 | surface_resource, |
Scott Moreau | 1bad5db | 2012-08-18 01:04:05 -0600 | [diff] [blame] | 3611 | surface->output->width, |
| 3612 | surface->output->height); |
Kristian Høgsberg | 7584062 | 2011-09-06 13:48:16 -0400 | [diff] [blame] | 3613 | } |
| 3614 | |
Pekka Paalanen | 9ef3e01 | 2011-11-15 13:34:48 +0200 | [diff] [blame] | 3615 | static void |
Jason Ekstrand | 918f2dd | 2013-12-02 21:01:53 -0600 | [diff] [blame] | 3616 | 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] | 3617 | { |
Giulio Camuffo | 7fe01b1 | 2013-03-28 18:02:42 +0100 | [diff] [blame] | 3618 | struct desktop_shell *shell = surface->configure_private; |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 3619 | struct weston_view *view; |
| 3620 | |
| 3621 | view = container_of(surface->views.next, struct weston_view, surface_link); |
Kristian Høgsberg | 730c94d | 2012-06-26 21:44:35 -0400 | [diff] [blame] | 3622 | |
Jason Ekstrand | 918f2dd | 2013-12-02 21:01:53 -0600 | [diff] [blame] | 3623 | if (surface->width == 0) |
Giulio Camuffo | 184df50 | 2013-02-21 11:29:21 +0100 | [diff] [blame] | 3624 | return; |
| 3625 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 3626 | center_on_output(view, get_default_output(shell->compositor)); |
Kristian Høgsberg | 730c94d | 2012-06-26 21:44:35 -0400 | [diff] [blame] | 3627 | |
| 3628 | if (!weston_surface_is_mapped(surface)) { |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 3629 | wl_list_insert(&shell->lock_layer.view_list, |
| 3630 | &view->layer_link); |
| 3631 | weston_view_update_transform(view); |
Ander Conselvan de Oliveira | 87524b6 | 2013-02-21 18:35:22 +0200 | [diff] [blame] | 3632 | shell_fade(shell, FADE_IN); |
Kristian Høgsberg | 730c94d | 2012-06-26 21:44:35 -0400 | [diff] [blame] | 3633 | } |
| 3634 | } |
| 3635 | |
| 3636 | static void |
Kristian Høgsberg | 27e3052 | 2012-04-11 23:18:23 -0400 | [diff] [blame] | 3637 | handle_lock_surface_destroy(struct wl_listener *listener, void *data) |
Kristian Høgsberg | 1ec0c31 | 2011-11-15 16:39:55 -0500 | [diff] [blame] | 3638 | { |
Tiago Vignatti | be14326 | 2012-04-16 17:31:41 +0300 | [diff] [blame] | 3639 | struct desktop_shell *shell = |
| 3640 | container_of(listener, struct desktop_shell, lock_surface_listener); |
Kristian Høgsberg | 1ec0c31 | 2011-11-15 16:39:55 -0500 | [diff] [blame] | 3641 | |
Martin Minarik | 6d11836 | 2012-06-07 18:01:59 +0200 | [diff] [blame] | 3642 | weston_log("lock surface gone\n"); |
Kristian Høgsberg | 1ec0c31 | 2011-11-15 16:39:55 -0500 | [diff] [blame] | 3643 | shell->lock_surface = NULL; |
| 3644 | } |
| 3645 | |
| 3646 | static void |
Pekka Paalanen | 9ef3e01 | 2011-11-15 13:34:48 +0200 | [diff] [blame] | 3647 | desktop_shell_set_lock_surface(struct wl_client *client, |
| 3648 | struct wl_resource *resource, |
| 3649 | struct wl_resource *surface_resource) |
| 3650 | { |
Jason Ekstrand | 651f00e | 2013-06-14 10:07:54 -0500 | [diff] [blame] | 3651 | struct desktop_shell *shell = wl_resource_get_user_data(resource); |
Jason Ekstrand | 0f2ef7e | 2013-06-14 10:07:53 -0500 | [diff] [blame] | 3652 | struct weston_surface *surface = |
| 3653 | wl_resource_get_user_data(surface_resource); |
Pekka Paalanen | 9826223 | 2011-12-01 10:42:22 +0200 | [diff] [blame] | 3654 | |
Pekka Paalanen | f0fc70d | 2011-11-15 13:34:54 +0200 | [diff] [blame] | 3655 | shell->prepare_event_sent = false; |
Kristian Høgsberg | af867cc | 2011-11-15 13:34:49 +0200 | [diff] [blame] | 3656 | |
Pekka Paalanen | f0fc70d | 2011-11-15 13:34:54 +0200 | [diff] [blame] | 3657 | if (!shell->locked) |
| 3658 | return; |
| 3659 | |
Pekka Paalanen | 9826223 | 2011-12-01 10:42:22 +0200 | [diff] [blame] | 3660 | shell->lock_surface = surface; |
Pekka Paalanen | f0fc70d | 2011-11-15 13:34:54 +0200 | [diff] [blame] | 3661 | |
Kristian Høgsberg | 27e3052 | 2012-04-11 23:18:23 -0400 | [diff] [blame] | 3662 | shell->lock_surface_listener.notify = handle_lock_surface_destroy; |
Jason Ekstrand | 651f00e | 2013-06-14 10:07:54 -0500 | [diff] [blame] | 3663 | wl_signal_add(&surface->destroy_signal, |
Kristian Høgsberg | 27e3052 | 2012-04-11 23:18:23 -0400 | [diff] [blame] | 3664 | &shell->lock_surface_listener); |
Pekka Paalanen | 57da4a8 | 2011-11-23 16:42:16 +0200 | [diff] [blame] | 3665 | |
Kristian Høgsberg | aa2ee8b | 2013-10-30 15:49:45 -0700 | [diff] [blame] | 3666 | weston_view_create(surface); |
Kristian Høgsberg | 730c94d | 2012-06-26 21:44:35 -0400 | [diff] [blame] | 3667 | surface->configure = lock_surface_configure; |
Giulio Camuffo | 7fe01b1 | 2013-03-28 18:02:42 +0100 | [diff] [blame] | 3668 | surface->configure_private = shell; |
Pekka Paalanen | f0fc70d | 2011-11-15 13:34:54 +0200 | [diff] [blame] | 3669 | } |
| 3670 | |
| 3671 | static void |
Tiago Vignatti | be14326 | 2012-04-16 17:31:41 +0300 | [diff] [blame] | 3672 | resume_desktop(struct desktop_shell *shell) |
Pekka Paalanen | f0fc70d | 2011-11-15 13:34:54 +0200 | [diff] [blame] | 3673 | { |
Kristian Høgsberg | 4476aaf | 2012-06-25 14:03:13 -0400 | [diff] [blame] | 3674 | struct workspace *ws = get_current_workspace(shell); |
Pekka Paalanen | 77346a6 | 2011-11-30 16:26:35 +0200 | [diff] [blame] | 3675 | |
Pekka Paalanen | 77346a6 | 2011-11-30 16:26:35 +0200 | [diff] [blame] | 3676 | terminate_screensaver(shell); |
Pekka Paalanen | f0fc70d | 2011-11-15 13:34:54 +0200 | [diff] [blame] | 3677 | |
Kristian Høgsberg | 3be2ce9 | 2012-02-29 12:42:35 -0500 | [diff] [blame] | 3678 | wl_list_remove(&shell->lock_layer.link); |
| 3679 | wl_list_insert(&shell->compositor->cursor_layer.link, |
| 3680 | &shell->fullscreen_layer.link); |
| 3681 | wl_list_insert(&shell->fullscreen_layer.link, |
| 3682 | &shell->panel_layer.link); |
Philipp Brüschweiler | 711fda8 | 2012-08-09 18:50:43 +0200 | [diff] [blame] | 3683 | if (shell->showing_input_panels) { |
| 3684 | wl_list_insert(&shell->panel_layer.link, |
| 3685 | &shell->input_panel_layer.link); |
| 3686 | wl_list_insert(&shell->input_panel_layer.link, |
| 3687 | &ws->layer.link); |
| 3688 | } else { |
| 3689 | wl_list_insert(&shell->panel_layer.link, &ws->layer.link); |
| 3690 | } |
Pekka Paalanen | f0fc70d | 2011-11-15 13:34:54 +0200 | [diff] [blame] | 3691 | |
Kristian Høgsberg | 2f5faff | 2012-07-31 16:36:34 -0400 | [diff] [blame] | 3692 | restore_focus_state(shell, get_current_workspace(shell)); |
Jonas Ådahl | 0476974 | 2012-06-13 00:01:24 +0200 | [diff] [blame] | 3693 | |
Pekka Paalanen | f0fc70d | 2011-11-15 13:34:54 +0200 | [diff] [blame] | 3694 | shell->locked = false; |
Ander Conselvan de Oliveira | 87524b6 | 2013-02-21 18:35:22 +0200 | [diff] [blame] | 3695 | shell_fade(shell, FADE_IN); |
Pekka Paalanen | fc6d91a | 2012-02-10 15:33:10 +0200 | [diff] [blame] | 3696 | weston_compositor_damage_all(shell->compositor); |
Pekka Paalanen | 9ef3e01 | 2011-11-15 13:34:48 +0200 | [diff] [blame] | 3697 | } |
| 3698 | |
| 3699 | static void |
| 3700 | desktop_shell_unlock(struct wl_client *client, |
| 3701 | struct wl_resource *resource) |
| 3702 | { |
Jason Ekstrand | 651f00e | 2013-06-14 10:07:54 -0500 | [diff] [blame] | 3703 | struct desktop_shell *shell = wl_resource_get_user_data(resource); |
Pekka Paalanen | 9ef3e01 | 2011-11-15 13:34:48 +0200 | [diff] [blame] | 3704 | |
Pekka Paalanen | 9ef3e01 | 2011-11-15 13:34:48 +0200 | [diff] [blame] | 3705 | shell->prepare_event_sent = false; |
Pekka Paalanen | f0fc70d | 2011-11-15 13:34:54 +0200 | [diff] [blame] | 3706 | |
| 3707 | if (shell->locked) |
| 3708 | resume_desktop(shell); |
Pekka Paalanen | 9ef3e01 | 2011-11-15 13:34:48 +0200 | [diff] [blame] | 3709 | } |
| 3710 | |
Kristian Høgsberg | d56bd90 | 2012-06-05 09:58:51 -0400 | [diff] [blame] | 3711 | static void |
Ander Conselvan de Oliveira | b9d2a0f | 2012-06-28 18:08:05 +0300 | [diff] [blame] | 3712 | desktop_shell_set_grab_surface(struct wl_client *client, |
Kristian Høgsberg | d56bd90 | 2012-06-05 09:58:51 -0400 | [diff] [blame] | 3713 | struct wl_resource *resource, |
| 3714 | struct wl_resource *surface_resource) |
| 3715 | { |
Jason Ekstrand | 651f00e | 2013-06-14 10:07:54 -0500 | [diff] [blame] | 3716 | struct desktop_shell *shell = wl_resource_get_user_data(resource); |
Kristian Høgsberg | d56bd90 | 2012-06-05 09:58:51 -0400 | [diff] [blame] | 3717 | |
Jason Ekstrand | 0f2ef7e | 2013-06-14 10:07:53 -0500 | [diff] [blame] | 3718 | shell->grab_surface = wl_resource_get_user_data(surface_resource); |
Kristian Høgsberg | 48588f8 | 2013-10-24 15:51:35 -0700 | [diff] [blame] | 3719 | weston_view_create(shell->grab_surface); |
Kristian Høgsberg | d56bd90 | 2012-06-05 09:58:51 -0400 | [diff] [blame] | 3720 | } |
| 3721 | |
Pekka Paalanen | 79346ab | 2013-05-22 18:03:09 +0300 | [diff] [blame] | 3722 | static void |
| 3723 | desktop_shell_desktop_ready(struct wl_client *client, |
| 3724 | struct wl_resource *resource) |
| 3725 | { |
Jason Ekstrand | 651f00e | 2013-06-14 10:07:54 -0500 | [diff] [blame] | 3726 | struct desktop_shell *shell = wl_resource_get_user_data(resource); |
Pekka Paalanen | 79346ab | 2013-05-22 18:03:09 +0300 | [diff] [blame] | 3727 | |
| 3728 | shell_fade_startup(shell); |
| 3729 | } |
| 3730 | |
Kristian Høgsberg | 7584062 | 2011-09-06 13:48:16 -0400 | [diff] [blame] | 3731 | static const struct desktop_shell_interface desktop_shell_implementation = { |
| 3732 | desktop_shell_set_background, |
Pekka Paalanen | 9ef3e01 | 2011-11-15 13:34:48 +0200 | [diff] [blame] | 3733 | desktop_shell_set_panel, |
| 3734 | desktop_shell_set_lock_surface, |
Kristian Høgsberg | d56bd90 | 2012-06-05 09:58:51 -0400 | [diff] [blame] | 3735 | desktop_shell_unlock, |
Pekka Paalanen | 79346ab | 2013-05-22 18:03:09 +0300 | [diff] [blame] | 3736 | desktop_shell_set_grab_surface, |
| 3737 | desktop_shell_desktop_ready |
Kristian Høgsberg | 7584062 | 2011-09-06 13:48:16 -0400 | [diff] [blame] | 3738 | }; |
| 3739 | |
Pekka Paalanen | 92a0dc4 | 2011-11-28 15:34:13 +0200 | [diff] [blame] | 3740 | static enum shell_surface_type |
Kristian Høgsberg | 8334bc1 | 2012-01-03 10:29:47 -0500 | [diff] [blame] | 3741 | get_shell_surface_type(struct weston_surface *surface) |
Pekka Paalanen | 92a0dc4 | 2011-11-28 15:34:13 +0200 | [diff] [blame] | 3742 | { |
| 3743 | struct shell_surface *shsurf; |
| 3744 | |
| 3745 | shsurf = get_shell_surface(surface); |
| 3746 | if (!shsurf) |
Pekka Paalanen | 9826223 | 2011-12-01 10:42:22 +0200 | [diff] [blame] | 3747 | return SHELL_SURFACE_NONE; |
Pekka Paalanen | 92a0dc4 | 2011-11-28 15:34:13 +0200 | [diff] [blame] | 3748 | return shsurf->type; |
| 3749 | } |
| 3750 | |
Kristian Høgsberg | 7584062 | 2011-09-06 13:48:16 -0400 | [diff] [blame] | 3751 | static void |
Kristian Høgsberg | e314875 | 2013-05-06 23:19:49 -0400 | [diff] [blame] | 3752 | 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] | 3753 | { |
Kristian Høgsberg | 7ab139c | 2013-10-24 16:21:39 -0700 | [diff] [blame] | 3754 | struct weston_surface *focus = seat->pointer->focus->surface; |
Pekka Paalanen | 01388e2 | 2013-04-25 13:57:44 +0300 | [diff] [blame] | 3755 | struct weston_surface *surface; |
Kristian Høgsberg | 938b8fa | 2012-05-18 13:46:27 -0400 | [diff] [blame] | 3756 | struct shell_surface *shsurf; |
Kristian Høgsberg | d2abb83 | 2011-11-23 10:52:40 -0500 | [diff] [blame] | 3757 | |
Pekka Paalanen | 01388e2 | 2013-04-25 13:57:44 +0300 | [diff] [blame] | 3758 | surface = weston_surface_get_main_surface(focus); |
Benjamin Franzke | d0f79ab | 2011-11-22 12:43:52 +0100 | [diff] [blame] | 3759 | if (surface == NULL) |
| 3760 | return; |
Kristian Høgsberg | 0793756 | 2011-04-12 17:25:42 -0400 | [diff] [blame] | 3761 | |
Kristian Høgsberg | 938b8fa | 2012-05-18 13:46:27 -0400 | [diff] [blame] | 3762 | shsurf = get_shell_surface(surface); |
Rafael Antognolli | 03b1659 | 2013-12-03 15:35:42 -0200 | [diff] [blame] | 3763 | if (shsurf == NULL || shsurf->state.fullscreen || |
| 3764 | shsurf->state.maximized) |
Kristian Høgsberg | 938b8fa | 2012-05-18 13:46:27 -0400 | [diff] [blame] | 3765 | return; |
| 3766 | |
Kristian Høgsberg | 938b8fa | 2012-05-18 13:46:27 -0400 | [diff] [blame] | 3767 | surface_move(shsurf, (struct weston_seat *) seat); |
Kristian Høgsberg | 0793756 | 2011-04-12 17:25:42 -0400 | [diff] [blame] | 3768 | } |
| 3769 | |
| 3770 | static void |
Rafael Antognolli | ea997ac | 2013-12-03 15:35:48 -0200 | [diff] [blame] | 3771 | maximize_binding(struct weston_seat *seat, uint32_t time, uint32_t button, void *data) |
| 3772 | { |
| 3773 | struct weston_surface *focus = seat->pointer->focus->surface; |
| 3774 | struct weston_surface *surface; |
| 3775 | struct shell_surface *shsurf; |
| 3776 | |
| 3777 | surface = weston_surface_get_main_surface(focus); |
| 3778 | if (surface == NULL) |
| 3779 | return; |
| 3780 | |
| 3781 | shsurf = get_shell_surface(surface); |
| 3782 | if (shsurf == NULL) |
| 3783 | return; |
| 3784 | |
| 3785 | if (!shell_surface_is_xdg_surface(shsurf)) |
| 3786 | return; |
| 3787 | |
| 3788 | if (shsurf->state.maximized) |
| 3789 | xdg_surface_send_request_unset_maximized(shsurf->resource); |
| 3790 | else |
| 3791 | xdg_surface_send_request_set_maximized(shsurf->resource); |
| 3792 | } |
| 3793 | |
| 3794 | static void |
| 3795 | fullscreen_binding(struct weston_seat *seat, uint32_t time, uint32_t button, void *data) |
| 3796 | { |
| 3797 | struct weston_surface *focus = seat->pointer->focus->surface; |
| 3798 | struct weston_surface *surface; |
| 3799 | struct shell_surface *shsurf; |
| 3800 | |
| 3801 | surface = weston_surface_get_main_surface(focus); |
| 3802 | if (surface == NULL) |
| 3803 | return; |
| 3804 | |
| 3805 | shsurf = get_shell_surface(surface); |
| 3806 | if (shsurf == NULL) |
| 3807 | return; |
| 3808 | |
| 3809 | if (!shell_surface_is_xdg_surface(shsurf)) |
| 3810 | return; |
| 3811 | |
| 3812 | if (shsurf->state.fullscreen) |
| 3813 | xdg_surface_send_request_unset_fullscreen(shsurf->resource); |
| 3814 | else |
| 3815 | xdg_surface_send_request_set_fullscreen(shsurf->resource); |
| 3816 | } |
| 3817 | |
| 3818 | static void |
Neil Roberts | aba0f25 | 2013-10-03 16:43:05 +0100 | [diff] [blame] | 3819 | touch_move_binding(struct weston_seat *seat, uint32_t time, void *data) |
| 3820 | { |
Kristian Høgsberg | 7ab139c | 2013-10-24 16:21:39 -0700 | [diff] [blame] | 3821 | struct weston_surface *focus = seat->touch->focus->surface; |
Neil Roberts | aba0f25 | 2013-10-03 16:43:05 +0100 | [diff] [blame] | 3822 | struct weston_surface *surface; |
| 3823 | struct shell_surface *shsurf; |
| 3824 | |
| 3825 | surface = weston_surface_get_main_surface(focus); |
| 3826 | if (surface == NULL) |
| 3827 | return; |
| 3828 | |
| 3829 | shsurf = get_shell_surface(surface); |
Rafael Antognolli | 03b1659 | 2013-12-03 15:35:42 -0200 | [diff] [blame] | 3830 | if (shsurf == NULL || shsurf->state.fullscreen || |
| 3831 | shsurf->state.maximized) |
Neil Roberts | aba0f25 | 2013-10-03 16:43:05 +0100 | [diff] [blame] | 3832 | return; |
| 3833 | |
| 3834 | surface_touch_move(shsurf, (struct weston_seat *) seat); |
| 3835 | } |
| 3836 | |
| 3837 | static void |
Kristian Høgsberg | e314875 | 2013-05-06 23:19:49 -0400 | [diff] [blame] | 3838 | 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] | 3839 | { |
Kristian Høgsberg | 7ab139c | 2013-10-24 16:21:39 -0700 | [diff] [blame] | 3840 | struct weston_surface *focus = seat->pointer->focus->surface; |
Pekka Paalanen | 01388e2 | 2013-04-25 13:57:44 +0300 | [diff] [blame] | 3841 | struct weston_surface *surface; |
Kristian Høgsberg | 0793756 | 2011-04-12 17:25:42 -0400 | [diff] [blame] | 3842 | uint32_t edges = 0; |
| 3843 | int32_t x, y; |
Pekka Paalanen | 9d1613e | 2011-11-25 12:09:16 +0200 | [diff] [blame] | 3844 | struct shell_surface *shsurf; |
Kristian Høgsberg | d2abb83 | 2011-11-23 10:52:40 -0500 | [diff] [blame] | 3845 | |
Pekka Paalanen | 01388e2 | 2013-04-25 13:57:44 +0300 | [diff] [blame] | 3846 | surface = weston_surface_get_main_surface(focus); |
Benjamin Franzke | d0f79ab | 2011-11-22 12:43:52 +0100 | [diff] [blame] | 3847 | if (surface == NULL) |
| 3848 | return; |
Pekka Paalanen | 92a0dc4 | 2011-11-28 15:34:13 +0200 | [diff] [blame] | 3849 | |
Pekka Paalanen | 9d1613e | 2011-11-25 12:09:16 +0200 | [diff] [blame] | 3850 | shsurf = get_shell_surface(surface); |
Rafael Antognolli | 03b1659 | 2013-12-03 15:35:42 -0200 | [diff] [blame] | 3851 | if (shsurf == NULL || shsurf->state.fullscreen || |
| 3852 | shsurf->state.maximized) |
Pekka Paalanen | 92a0dc4 | 2011-11-28 15:34:13 +0200 | [diff] [blame] | 3853 | return; |
| 3854 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 3855 | weston_view_from_global(shsurf->view, |
| 3856 | wl_fixed_to_int(seat->pointer->grab_x), |
| 3857 | wl_fixed_to_int(seat->pointer->grab_y), |
| 3858 | &x, &y); |
Kristian Høgsberg | 0793756 | 2011-04-12 17:25:42 -0400 | [diff] [blame] | 3859 | |
Jason Ekstrand | 918f2dd | 2013-12-02 21:01:53 -0600 | [diff] [blame] | 3860 | if (x < shsurf->surface->width / 3) |
Pekka Paalanen | 9d1613e | 2011-11-25 12:09:16 +0200 | [diff] [blame] | 3861 | edges |= WL_SHELL_SURFACE_RESIZE_LEFT; |
Jason Ekstrand | 918f2dd | 2013-12-02 21:01:53 -0600 | [diff] [blame] | 3862 | else if (x < 2 * shsurf->surface->width / 3) |
Kristian Høgsberg | 0793756 | 2011-04-12 17:25:42 -0400 | [diff] [blame] | 3863 | edges |= 0; |
| 3864 | else |
Pekka Paalanen | 9d1613e | 2011-11-25 12:09:16 +0200 | [diff] [blame] | 3865 | edges |= WL_SHELL_SURFACE_RESIZE_RIGHT; |
Kristian Høgsberg | 0793756 | 2011-04-12 17:25:42 -0400 | [diff] [blame] | 3866 | |
Jason Ekstrand | 918f2dd | 2013-12-02 21:01:53 -0600 | [diff] [blame] | 3867 | if (y < shsurf->surface->height / 3) |
Pekka Paalanen | 9d1613e | 2011-11-25 12:09:16 +0200 | [diff] [blame] | 3868 | edges |= WL_SHELL_SURFACE_RESIZE_TOP; |
Jason Ekstrand | 918f2dd | 2013-12-02 21:01:53 -0600 | [diff] [blame] | 3869 | else if (y < 2 * shsurf->surface->height / 3) |
Kristian Høgsberg | 0793756 | 2011-04-12 17:25:42 -0400 | [diff] [blame] | 3870 | edges |= 0; |
| 3871 | else |
Pekka Paalanen | 9d1613e | 2011-11-25 12:09:16 +0200 | [diff] [blame] | 3872 | edges |= WL_SHELL_SURFACE_RESIZE_BOTTOM; |
Kristian Høgsberg | 0793756 | 2011-04-12 17:25:42 -0400 | [diff] [blame] | 3873 | |
Kristian Høgsberg | c1693f2 | 2012-05-22 16:56:23 -0400 | [diff] [blame] | 3874 | surface_resize(shsurf, (struct weston_seat *) seat, edges); |
Kristian Høgsberg | 02ec0a5 | 2011-04-23 13:04:11 -0400 | [diff] [blame] | 3875 | } |
| 3876 | |
| 3877 | static void |
Kristian Høgsberg | e314875 | 2013-05-06 23:19:49 -0400 | [diff] [blame] | 3878 | 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] | 3879 | wl_fixed_t value, void *data) |
Scott Moreau | a3aa9c9 | 2012-03-22 11:01:03 -0600 | [diff] [blame] | 3880 | { |
Jonas Ådahl | b0b87ba | 2012-09-27 18:40:42 +0200 | [diff] [blame] | 3881 | float step = 0.005; |
Scott Moreau | a3aa9c9 | 2012-03-22 11:01:03 -0600 | [diff] [blame] | 3882 | struct shell_surface *shsurf; |
Kristian Høgsberg | 7ab139c | 2013-10-24 16:21:39 -0700 | [diff] [blame] | 3883 | struct weston_surface *focus = seat->pointer->focus->surface; |
Pekka Paalanen | 01388e2 | 2013-04-25 13:57:44 +0300 | [diff] [blame] | 3884 | struct weston_surface *surface; |
Scott Moreau | a3aa9c9 | 2012-03-22 11:01:03 -0600 | [diff] [blame] | 3885 | |
Pekka Paalanen | 01388e2 | 2013-04-25 13:57:44 +0300 | [diff] [blame] | 3886 | /* XXX: broken for windows containing sub-surfaces */ |
| 3887 | surface = weston_surface_get_main_surface(focus); |
Scott Moreau | a3aa9c9 | 2012-03-22 11:01:03 -0600 | [diff] [blame] | 3888 | if (surface == NULL) |
| 3889 | return; |
| 3890 | |
| 3891 | shsurf = get_shell_surface(surface); |
| 3892 | if (!shsurf) |
| 3893 | return; |
| 3894 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 3895 | shsurf->view->alpha -= wl_fixed_to_double(value) * step; |
Scott Moreau | a3aa9c9 | 2012-03-22 11:01:03 -0600 | [diff] [blame] | 3896 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 3897 | if (shsurf->view->alpha > 1.0) |
| 3898 | shsurf->view->alpha = 1.0; |
| 3899 | if (shsurf->view->alpha < step) |
| 3900 | shsurf->view->alpha = step; |
Scott Moreau | a3aa9c9 | 2012-03-22 11:01:03 -0600 | [diff] [blame] | 3901 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 3902 | weston_view_geometry_dirty(shsurf->view); |
Scott Moreau | a3aa9c9 | 2012-03-22 11:01:03 -0600 | [diff] [blame] | 3903 | weston_surface_damage(surface); |
| 3904 | } |
| 3905 | |
| 3906 | static void |
Kristian Høgsberg | e314875 | 2013-05-06 23:19:49 -0400 | [diff] [blame] | 3907 | 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] | 3908 | wl_fixed_t value) |
Scott Moreau | ccbf29d | 2012-02-22 14:21:41 -0700 | [diff] [blame] | 3909 | { |
Daniel Stone | 37816df | 2012-05-16 18:45:18 +0100 | [diff] [blame] | 3910 | struct weston_seat *ws = (struct weston_seat *) seat; |
| 3911 | struct weston_compositor *compositor = ws->compositor; |
Scott Moreau | ccbf29d | 2012-02-22 14:21:41 -0700 | [diff] [blame] | 3912 | struct weston_output *output; |
Scott Moreau | e660398 | 2012-06-11 13:07:51 -0600 | [diff] [blame] | 3913 | float increment; |
Scott Moreau | ccbf29d | 2012-02-22 14:21:41 -0700 | [diff] [blame] | 3914 | |
| 3915 | wl_list_for_each(output, &compositor->output_list, link) { |
| 3916 | if (pixman_region32_contains_point(&output->region, |
Daniel Stone | 37816df | 2012-05-16 18:45:18 +0100 | [diff] [blame] | 3917 | wl_fixed_to_double(seat->pointer->x), |
| 3918 | wl_fixed_to_double(seat->pointer->y), |
Daniel Stone | 103db7f | 2012-05-08 17:17:55 +0100 | [diff] [blame] | 3919 | NULL)) { |
Daniel Stone | 325fc2d | 2012-05-30 16:31:58 +0100 | [diff] [blame] | 3920 | if (key == KEY_PAGEUP) |
Kristian Høgsberg | 9b68af0 | 2012-05-22 12:55:18 -0400 | [diff] [blame] | 3921 | increment = output->zoom.increment; |
Daniel Stone | 325fc2d | 2012-05-30 16:31:58 +0100 | [diff] [blame] | 3922 | else if (key == KEY_PAGEDOWN) |
Kristian Høgsberg | 9b68af0 | 2012-05-22 12:55:18 -0400 | [diff] [blame] | 3923 | increment = -output->zoom.increment; |
| 3924 | else if (axis == WL_POINTER_AXIS_VERTICAL_SCROLL) |
Jonas Ådahl | b0b87ba | 2012-09-27 18:40:42 +0200 | [diff] [blame] | 3925 | /* For every pixel zoom 20th of a step */ |
Daniel Stone | 0c1e46e | 2012-05-30 16:31:59 +0100 | [diff] [blame] | 3926 | increment = output->zoom.increment * |
Jonas Ådahl | b0b87ba | 2012-09-27 18:40:42 +0200 | [diff] [blame] | 3927 | -wl_fixed_to_double(value) / 20.0; |
Kristian Høgsberg | 9b68af0 | 2012-05-22 12:55:18 -0400 | [diff] [blame] | 3928 | else |
| 3929 | increment = 0; |
| 3930 | |
Kristian Høgsberg | 9b68af0 | 2012-05-22 12:55:18 -0400 | [diff] [blame] | 3931 | output->zoom.level += increment; |
Scott Moreau | c6d7f60 | 2012-02-23 22:28:37 -0700 | [diff] [blame] | 3932 | |
Scott Moreau | e660398 | 2012-06-11 13:07:51 -0600 | [diff] [blame] | 3933 | if (output->zoom.level < 0.0) |
Scott Moreau | 850ca42 | 2012-05-21 15:21:25 -0600 | [diff] [blame] | 3934 | output->zoom.level = 0.0; |
Scott Moreau | e660398 | 2012-06-11 13:07:51 -0600 | [diff] [blame] | 3935 | else if (output->zoom.level > output->zoom.max_level) |
| 3936 | output->zoom.level = output->zoom.max_level; |
Ville Syrjälä | aa628d0 | 2012-11-16 11:48:47 +0200 | [diff] [blame] | 3937 | else if (!output->zoom.active) { |
Giulio Camuffo | 412b024 | 2013-11-14 23:42:51 +0100 | [diff] [blame] | 3938 | weston_output_activate_zoom(output); |
Kristian Høgsberg | 79af73e | 2012-08-03 15:45:23 -0400 | [diff] [blame] | 3939 | } |
Scott Moreau | ccbf29d | 2012-02-22 14:21:41 -0700 | [diff] [blame] | 3940 | |
Scott Moreau | e660398 | 2012-06-11 13:07:51 -0600 | [diff] [blame] | 3941 | output->zoom.spring_z.target = output->zoom.level; |
Scott Moreau | ccbf29d | 2012-02-22 14:21:41 -0700 | [diff] [blame] | 3942 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 3943 | weston_output_update_zoom(output); |
Scott Moreau | ccbf29d | 2012-02-22 14:21:41 -0700 | [diff] [blame] | 3944 | } |
| 3945 | } |
| 3946 | } |
| 3947 | |
Scott Moreau | ccbf29d | 2012-02-22 14:21:41 -0700 | [diff] [blame] | 3948 | static void |
Kristian Høgsberg | e314875 | 2013-05-06 23:19:49 -0400 | [diff] [blame] | 3949 | 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] | 3950 | wl_fixed_t value, void *data) |
Daniel Stone | 325fc2d | 2012-05-30 16:31:58 +0100 | [diff] [blame] | 3951 | { |
| 3952 | do_zoom(seat, time, 0, axis, value); |
| 3953 | } |
| 3954 | |
| 3955 | static void |
Kristian Høgsberg | e314875 | 2013-05-06 23:19:49 -0400 | [diff] [blame] | 3956 | 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] | 3957 | void *data) |
| 3958 | { |
| 3959 | do_zoom(seat, time, key, 0, 0); |
| 3960 | } |
| 3961 | |
| 3962 | static void |
Kristian Høgsberg | e314875 | 2013-05-06 23:19:49 -0400 | [diff] [blame] | 3963 | terminate_binding(struct weston_seat *seat, uint32_t time, uint32_t key, |
Daniel Stone | 325fc2d | 2012-05-30 16:31:58 +0100 | [diff] [blame] | 3964 | void *data) |
Kristian Høgsberg | e1a850e | 2011-12-19 15:18:05 -0500 | [diff] [blame] | 3965 | { |
Kristian Høgsberg | 8334bc1 | 2012-01-03 10:29:47 -0500 | [diff] [blame] | 3966 | struct weston_compositor *compositor = data; |
Kristian Høgsberg | e1a850e | 2011-12-19 15:18:05 -0500 | [diff] [blame] | 3967 | |
Daniel Stone | 325fc2d | 2012-05-30 16:31:58 +0100 | [diff] [blame] | 3968 | wl_display_terminate(compositor->wl_display); |
Kristian Høgsberg | e1a850e | 2011-12-19 15:18:05 -0500 | [diff] [blame] | 3969 | } |
| 3970 | |
Emilio Pozuelo Monfort | 03251b6 | 2013-11-19 11:37:16 +0100 | [diff] [blame] | 3971 | struct alt_tab { |
| 3972 | struct desktop_shell *shell; |
| 3973 | struct weston_keyboard_grab grab; |
| 3974 | |
| 3975 | struct wl_list *current; |
| 3976 | |
| 3977 | struct wl_list preview_list; |
| 3978 | }; |
| 3979 | |
| 3980 | struct alt_tab_preview { |
| 3981 | struct alt_tab *alt_tab; |
| 3982 | |
| 3983 | struct weston_view *view; |
| 3984 | struct weston_transform transform; |
| 3985 | |
| 3986 | struct wl_listener listener; |
| 3987 | |
| 3988 | struct wl_list link; |
| 3989 | }; |
| 3990 | |
| 3991 | static void |
| 3992 | alt_tab_next(struct alt_tab *alt_tab) |
| 3993 | { |
| 3994 | alt_tab->current = alt_tab->current->next; |
| 3995 | |
| 3996 | /* Make sure we're not pointing to the list header e.g. after |
| 3997 | * cycling through the whole list. */ |
| 3998 | if (alt_tab->current->next == alt_tab->preview_list.next) |
| 3999 | alt_tab->current = alt_tab->current->next; |
| 4000 | } |
| 4001 | |
| 4002 | static void |
| 4003 | alt_tab_destroy(struct alt_tab *alt_tab) |
| 4004 | { |
| 4005 | struct alt_tab_preview *preview, *next; |
| 4006 | struct weston_keyboard *keyboard = alt_tab->grab.keyboard; |
| 4007 | |
| 4008 | if (alt_tab->current && alt_tab->current != &alt_tab->preview_list) { |
| 4009 | preview = wl_container_of(alt_tab->current, preview, link); |
| 4010 | |
| 4011 | activate(alt_tab->shell, preview->view->surface, |
| 4012 | (struct weston_seat *) keyboard->seat); |
| 4013 | } |
| 4014 | |
| 4015 | wl_list_for_each_safe(preview, next, &alt_tab->preview_list, link) { |
| 4016 | wl_list_remove(&preview->link); |
| 4017 | wl_list_remove(&preview->listener.link); |
| 4018 | weston_view_destroy(preview->view); |
| 4019 | free(preview); |
| 4020 | } |
| 4021 | |
| 4022 | weston_keyboard_end_grab(keyboard); |
| 4023 | if (keyboard->input_method_resource) |
| 4024 | keyboard->grab = &keyboard->input_method_grab; |
| 4025 | |
| 4026 | free(alt_tab); |
| 4027 | } |
| 4028 | |
| 4029 | static void |
| 4030 | alt_tab_handle_surface_destroy(struct wl_listener *listener, void *data) |
| 4031 | { |
| 4032 | struct alt_tab_preview *preview = |
| 4033 | container_of(listener, struct alt_tab_preview, listener); |
| 4034 | struct alt_tab *alt_tab = preview->alt_tab; |
| 4035 | int advance = 0; |
| 4036 | |
| 4037 | /* If the preview that we're removing is the currently selected one, |
| 4038 | * we want to move to the next one. So we move to ->prev and then |
| 4039 | * call _next() after removing the preview. */ |
| 4040 | if (alt_tab->current == &preview->link) { |
| 4041 | alt_tab->current = alt_tab->current->prev; |
| 4042 | advance = 1; |
| 4043 | } |
| 4044 | |
| 4045 | wl_list_remove(&preview->listener.link); |
| 4046 | wl_list_remove(&preview->link); |
| 4047 | |
| 4048 | free(preview); |
| 4049 | |
| 4050 | if (advance) |
| 4051 | alt_tab_next(alt_tab); |
| 4052 | |
| 4053 | /* If the last preview goes away, stop the alt-tab */ |
| 4054 | if (wl_list_empty(alt_tab->current)) |
| 4055 | alt_tab_destroy(alt_tab); |
| 4056 | } |
| 4057 | |
| 4058 | static void |
| 4059 | alt_tab_key(struct weston_keyboard_grab *grab, |
| 4060 | uint32_t time, uint32_t key, uint32_t state_w) |
| 4061 | { |
| 4062 | struct alt_tab *alt_tab = container_of(grab, struct alt_tab, grab); |
| 4063 | enum wl_keyboard_key_state state = state_w; |
| 4064 | |
| 4065 | if (key == KEY_TAB && state == WL_KEYBOARD_KEY_STATE_PRESSED) |
| 4066 | alt_tab_next(alt_tab); |
| 4067 | } |
| 4068 | |
| 4069 | static void |
| 4070 | alt_tab_modifier(struct weston_keyboard_grab *grab, uint32_t serial, |
| 4071 | uint32_t mods_depressed, uint32_t mods_latched, |
| 4072 | uint32_t mods_locked, uint32_t group) |
| 4073 | { |
| 4074 | struct alt_tab *alt_tab = container_of(grab, struct alt_tab, grab); |
| 4075 | struct weston_seat *seat = (struct weston_seat *) grab->keyboard->seat; |
| 4076 | |
| 4077 | if ((seat->modifier_state & MODIFIER_ALT) == 0) |
| 4078 | alt_tab_destroy(alt_tab); |
| 4079 | } |
| 4080 | |
| 4081 | static void |
| 4082 | alt_tab_cancel(struct weston_keyboard_grab *grab) |
| 4083 | { |
| 4084 | struct alt_tab *alt_tab = container_of(grab, struct alt_tab, grab); |
| 4085 | |
| 4086 | alt_tab_destroy(alt_tab); |
| 4087 | } |
| 4088 | |
| 4089 | static const struct weston_keyboard_grab_interface alt_tab_grab = { |
| 4090 | alt_tab_key, |
| 4091 | alt_tab_modifier, |
| 4092 | alt_tab_cancel, |
| 4093 | }; |
| 4094 | |
| 4095 | static int |
| 4096 | view_for_alt_tab(struct weston_view *view) |
| 4097 | { |
Rafael Antognolli | ed207b4 | 2013-12-03 15:35:43 -0200 | [diff] [blame] | 4098 | struct shell_surface *shsurf = get_shell_surface(view->surface); |
| 4099 | if (!shsurf) |
Emilio Pozuelo Monfort | 03251b6 | 2013-11-19 11:37:16 +0100 | [diff] [blame] | 4100 | return 0; |
| 4101 | |
Rafael Antognolli | ed207b4 | 2013-12-03 15:35:43 -0200 | [diff] [blame] | 4102 | if (shsurf->parent) |
Emilio Pozuelo Monfort | 03251b6 | 2013-11-19 11:37:16 +0100 | [diff] [blame] | 4103 | return 0; |
| 4104 | |
| 4105 | if (view != get_default_view(view->surface)) |
| 4106 | return 0; |
| 4107 | |
| 4108 | return 1; |
| 4109 | } |
| 4110 | |
| 4111 | static void |
| 4112 | alt_tab_binding(struct weston_seat *seat, uint32_t time, uint32_t key, |
| 4113 | void *data) |
| 4114 | { |
| 4115 | struct alt_tab *alt_tab; |
| 4116 | struct desktop_shell *shell = data; |
| 4117 | struct weston_output *output = get_default_output(shell->compositor); |
| 4118 | struct workspace *ws; |
| 4119 | struct weston_view *view; |
| 4120 | int num_surfaces = 0; |
| 4121 | int x, y, side, margin; |
| 4122 | |
| 4123 | wl_list_for_each(view, &shell->compositor->view_list, link) { |
| 4124 | |
| 4125 | if (view_for_alt_tab(view)) |
| 4126 | num_surfaces++; |
| 4127 | } |
| 4128 | |
| 4129 | if (!num_surfaces) |
| 4130 | return; |
| 4131 | |
| 4132 | alt_tab = malloc(sizeof *alt_tab); |
| 4133 | if (!alt_tab) |
| 4134 | return; |
| 4135 | |
| 4136 | alt_tab->shell = shell; |
| 4137 | wl_list_init(&alt_tab->preview_list); |
| 4138 | alt_tab->current = &alt_tab->preview_list; |
| 4139 | |
| 4140 | restore_all_output_modes(shell->compositor); |
| 4141 | lower_fullscreen_layer(alt_tab->shell); |
| 4142 | |
| 4143 | alt_tab->grab.interface = &alt_tab_grab; |
| 4144 | weston_keyboard_start_grab(seat->keyboard, &alt_tab->grab); |
| 4145 | weston_keyboard_set_focus(seat->keyboard, NULL); |
| 4146 | |
| 4147 | ws = get_current_workspace(shell); |
| 4148 | |
| 4149 | /* FIXME: add some visual candy e.g. prelight the selected view |
| 4150 | * and/or add a black surrounding background à la gnome-shell */ |
| 4151 | |
| 4152 | /* Determine the size for each preview */ |
| 4153 | side = output->width / num_surfaces; |
| 4154 | if (side > 200) |
| 4155 | side = 200; |
| 4156 | margin = side / 4; |
| 4157 | side -= margin; |
| 4158 | |
| 4159 | x = margin; |
| 4160 | y = (output->height - side) / 2; |
| 4161 | |
| 4162 | /* Create a view for each surface */ |
| 4163 | wl_list_for_each(view, &shell->compositor->view_list, link) { |
| 4164 | struct alt_tab_preview *preview; |
| 4165 | struct weston_view *v; |
| 4166 | float scale; |
| 4167 | |
| 4168 | if (!view_for_alt_tab(view)) |
| 4169 | continue; |
| 4170 | |
| 4171 | preview = malloc(sizeof *preview); |
| 4172 | if (!preview) { |
| 4173 | alt_tab_destroy(alt_tab); |
| 4174 | return; |
| 4175 | } |
| 4176 | |
| 4177 | preview->alt_tab = alt_tab; |
| 4178 | |
| 4179 | preview->view = v = weston_view_create(view->surface); |
| 4180 | v->output = view->output; |
Philip Withnall | 83ffd9d | 2013-11-25 18:01:42 +0000 | [diff] [blame] | 4181 | |
| 4182 | wl_list_remove(&v->layer_link); |
| 4183 | wl_list_insert(&ws->layer.view_list, &v->layer_link); |
| 4184 | weston_view_damage_below(v); |
| 4185 | weston_surface_damage(v->surface); |
| 4186 | |
Jason Ekstrand | 918f2dd | 2013-12-02 21:01:53 -0600 | [diff] [blame] | 4187 | weston_view_set_position(v, x, y); |
Emilio Pozuelo Monfort | 03251b6 | 2013-11-19 11:37:16 +0100 | [diff] [blame] | 4188 | |
| 4189 | preview->listener.notify = alt_tab_handle_surface_destroy; |
| 4190 | wl_signal_add(&v->destroy_signal, &preview->listener); |
| 4191 | |
Jason Ekstrand | 918f2dd | 2013-12-02 21:01:53 -0600 | [diff] [blame] | 4192 | if (view->surface->width > view->surface->height) |
| 4193 | scale = side / (float) view->surface->width; |
Emilio Pozuelo Monfort | 03251b6 | 2013-11-19 11:37:16 +0100 | [diff] [blame] | 4194 | else |
Jason Ekstrand | 918f2dd | 2013-12-02 21:01:53 -0600 | [diff] [blame] | 4195 | scale = side / (float) view->surface->height; |
Emilio Pozuelo Monfort | 03251b6 | 2013-11-19 11:37:16 +0100 | [diff] [blame] | 4196 | |
| 4197 | wl_list_insert(&v->geometry.transformation_list, |
| 4198 | &preview->transform.link); |
| 4199 | weston_matrix_init(&preview->transform.matrix); |
| 4200 | weston_matrix_scale(&preview->transform.matrix, |
| 4201 | scale, scale, 1.0f); |
| 4202 | |
| 4203 | weston_view_geometry_dirty(v); |
| 4204 | weston_compositor_schedule_repaint(v->surface->compositor); |
| 4205 | |
| 4206 | /* Insert at the end of the list */ |
| 4207 | wl_list_insert(alt_tab->preview_list.prev, &preview->link); |
| 4208 | |
| 4209 | x += side + margin; |
| 4210 | } |
| 4211 | |
| 4212 | /* Start at the second preview so a simple <alt>tab changes window. |
| 4213 | * We set `current' to the first preview and not the second because |
| 4214 | * we're going to receive a key press callback for the initial |
| 4215 | * <alt>tab which will make `current' point to the second element. */ |
| 4216 | alt_tab_next(alt_tab); |
| 4217 | } |
| 4218 | |
| 4219 | static void |
Giulio Camuffo | 1959ab8 | 2013-11-14 23:42:52 +0100 | [diff] [blame] | 4220 | rotate_grab_motion(struct weston_pointer_grab *grab, uint32_t time, |
| 4221 | wl_fixed_t x, wl_fixed_t y) |
Pekka Paalanen | 460099f | 2012-01-20 16:48:25 +0200 | [diff] [blame] | 4222 | { |
| 4223 | struct rotate_grab *rotate = |
Ander Conselvan de Oliveira | fe0444a | 2012-04-04 17:48:05 +0300 | [diff] [blame] | 4224 | container_of(grab, struct rotate_grab, base.grab); |
Kristian Høgsberg | 02bbabb | 2013-05-06 22:15:05 -0400 | [diff] [blame] | 4225 | struct weston_pointer *pointer = grab->pointer; |
Ander Conselvan de Oliveira | fe0444a | 2012-04-04 17:48:05 +0300 | [diff] [blame] | 4226 | struct shell_surface *shsurf = rotate->base.shsurf; |
John Kåre Alsaker | 490d02a | 2012-09-30 02:57:21 +0200 | [diff] [blame] | 4227 | float cx, cy, dx, dy, cposx, cposy, dposx, dposy, r; |
Ander Conselvan de Oliveira | fe0444a | 2012-04-04 17:48:05 +0300 | [diff] [blame] | 4228 | |
Giulio Camuffo | 1959ab8 | 2013-11-14 23:42:52 +0100 | [diff] [blame] | 4229 | weston_pointer_move(pointer, x, y); |
| 4230 | |
Ander Conselvan de Oliveira | fe0444a | 2012-04-04 17:48:05 +0300 | [diff] [blame] | 4231 | if (!shsurf) |
| 4232 | return; |
| 4233 | |
Jason Ekstrand | 918f2dd | 2013-12-02 21:01:53 -0600 | [diff] [blame] | 4234 | cx = 0.5f * shsurf->surface->width; |
| 4235 | cy = 0.5f * shsurf->surface->height; |
Pekka Paalanen | 460099f | 2012-01-20 16:48:25 +0200 | [diff] [blame] | 4236 | |
Daniel Stone | 37816df | 2012-05-16 18:45:18 +0100 | [diff] [blame] | 4237 | dx = wl_fixed_to_double(pointer->x) - rotate->center.x; |
| 4238 | dy = wl_fixed_to_double(pointer->y) - rotate->center.y; |
Pekka Paalanen | 460099f | 2012-01-20 16:48:25 +0200 | [diff] [blame] | 4239 | r = sqrtf(dx * dx + dy * dy); |
| 4240 | |
Ander Conselvan de Oliveira | fe0444a | 2012-04-04 17:48:05 +0300 | [diff] [blame] | 4241 | wl_list_remove(&shsurf->rotation.transform.link); |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 4242 | weston_view_geometry_dirty(shsurf->view); |
Pekka Paalanen | 460099f | 2012-01-20 16:48:25 +0200 | [diff] [blame] | 4243 | |
| 4244 | if (r > 20.0f) { |
Pekka Paalanen | 460099f | 2012-01-20 16:48:25 +0200 | [diff] [blame] | 4245 | struct weston_matrix *matrix = |
Ander Conselvan de Oliveira | fe0444a | 2012-04-04 17:48:05 +0300 | [diff] [blame] | 4246 | &shsurf->rotation.transform.matrix; |
Pekka Paalanen | 460099f | 2012-01-20 16:48:25 +0200 | [diff] [blame] | 4247 | |
Kristian Høgsberg | 765e27b | 2012-01-27 13:36:13 -0500 | [diff] [blame] | 4248 | weston_matrix_init(&rotate->rotation); |
Vasily Khoruzhick | 1bbf372 | 2013-01-28 22:40:28 +0300 | [diff] [blame] | 4249 | weston_matrix_rotate_xy(&rotate->rotation, dx / r, dy / r); |
Pekka Paalanen | 460099f | 2012-01-20 16:48:25 +0200 | [diff] [blame] | 4250 | |
| 4251 | weston_matrix_init(matrix); |
Pekka Paalanen | 7b3bd3d | 2012-01-30 14:16:34 +0200 | [diff] [blame] | 4252 | weston_matrix_translate(matrix, -cx, -cy, 0.0f); |
Ander Conselvan de Oliveira | fe0444a | 2012-04-04 17:48:05 +0300 | [diff] [blame] | 4253 | weston_matrix_multiply(matrix, &shsurf->rotation.rotation); |
Kristian Høgsberg | 765e27b | 2012-01-27 13:36:13 -0500 | [diff] [blame] | 4254 | weston_matrix_multiply(matrix, &rotate->rotation); |
Pekka Paalanen | 7b3bd3d | 2012-01-30 14:16:34 +0200 | [diff] [blame] | 4255 | weston_matrix_translate(matrix, cx, cy, 0.0f); |
Pekka Paalanen | 460099f | 2012-01-20 16:48:25 +0200 | [diff] [blame] | 4256 | |
Pekka Paalanen | bc0b7e7 | 2012-01-24 09:53:37 +0200 | [diff] [blame] | 4257 | wl_list_insert( |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 4258 | &shsurf->view->geometry.transformation_list, |
Ander Conselvan de Oliveira | fe0444a | 2012-04-04 17:48:05 +0300 | [diff] [blame] | 4259 | &shsurf->rotation.transform.link); |
Pekka Paalanen | 460099f | 2012-01-20 16:48:25 +0200 | [diff] [blame] | 4260 | } else { |
Ander Conselvan de Oliveira | fe0444a | 2012-04-04 17:48:05 +0300 | [diff] [blame] | 4261 | wl_list_init(&shsurf->rotation.transform.link); |
| 4262 | weston_matrix_init(&shsurf->rotation.rotation); |
Kristian Høgsberg | 765e27b | 2012-01-27 13:36:13 -0500 | [diff] [blame] | 4263 | weston_matrix_init(&rotate->rotation); |
Pekka Paalanen | 460099f | 2012-01-20 16:48:25 +0200 | [diff] [blame] | 4264 | } |
Pekka Paalanen | b45ac5e | 2012-02-09 15:58:44 +0200 | [diff] [blame] | 4265 | |
Rafal Mielniczuk | 2d7ab82 | 2012-03-22 22:22:04 +0100 | [diff] [blame] | 4266 | /* We need to adjust the position of the surface |
| 4267 | * in case it was resized in a rotated state before */ |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 4268 | cposx = shsurf->view->geometry.x + cx; |
| 4269 | cposy = shsurf->view->geometry.y + cy; |
Rafal Mielniczuk | 2d7ab82 | 2012-03-22 22:22:04 +0100 | [diff] [blame] | 4270 | dposx = rotate->center.x - cposx; |
| 4271 | dposy = rotate->center.y - cposy; |
| 4272 | if (dposx != 0.0f || dposy != 0.0f) { |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 4273 | weston_view_set_position(shsurf->view, |
| 4274 | shsurf->view->geometry.x + dposx, |
| 4275 | shsurf->view->geometry.y + dposy); |
Rafal Mielniczuk | 2d7ab82 | 2012-03-22 22:22:04 +0100 | [diff] [blame] | 4276 | } |
| 4277 | |
Pekka Paalanen | b45ac5e | 2012-02-09 15:58:44 +0200 | [diff] [blame] | 4278 | /* Repaint implies weston_surface_update_transform(), which |
| 4279 | * lazily applies the damage due to rotation update. |
| 4280 | */ |
Ander Conselvan de Oliveira | fe0444a | 2012-04-04 17:48:05 +0300 | [diff] [blame] | 4281 | weston_compositor_schedule_repaint(shsurf->surface->compositor); |
Pekka Paalanen | 460099f | 2012-01-20 16:48:25 +0200 | [diff] [blame] | 4282 | } |
| 4283 | |
| 4284 | static void |
Kristian Høgsberg | 02bbabb | 2013-05-06 22:15:05 -0400 | [diff] [blame] | 4285 | rotate_grab_button(struct weston_pointer_grab *grab, |
| 4286 | uint32_t time, uint32_t button, uint32_t state_w) |
Pekka Paalanen | 460099f | 2012-01-20 16:48:25 +0200 | [diff] [blame] | 4287 | { |
| 4288 | struct rotate_grab *rotate = |
Ander Conselvan de Oliveira | fe0444a | 2012-04-04 17:48:05 +0300 | [diff] [blame] | 4289 | container_of(grab, struct rotate_grab, base.grab); |
Kristian Høgsberg | 02bbabb | 2013-05-06 22:15:05 -0400 | [diff] [blame] | 4290 | struct weston_pointer *pointer = grab->pointer; |
Ander Conselvan de Oliveira | fe0444a | 2012-04-04 17:48:05 +0300 | [diff] [blame] | 4291 | struct shell_surface *shsurf = rotate->base.shsurf; |
Daniel Stone | 4dbadb1 | 2012-05-30 16:31:51 +0100 | [diff] [blame] | 4292 | enum wl_pointer_button_state state = state_w; |
Pekka Paalanen | 460099f | 2012-01-20 16:48:25 +0200 | [diff] [blame] | 4293 | |
Daniel Stone | 4dbadb1 | 2012-05-30 16:31:51 +0100 | [diff] [blame] | 4294 | if (pointer->button_count == 0 && |
| 4295 | state == WL_POINTER_BUTTON_STATE_RELEASED) { |
Ander Conselvan de Oliveira | fe0444a | 2012-04-04 17:48:05 +0300 | [diff] [blame] | 4296 | if (shsurf) |
| 4297 | weston_matrix_multiply(&shsurf->rotation.rotation, |
| 4298 | &rotate->rotation); |
Ander Conselvan de Oliveira | b9d2a0f | 2012-06-28 18:08:05 +0300 | [diff] [blame] | 4299 | shell_grab_end(&rotate->base); |
Pekka Paalanen | 460099f | 2012-01-20 16:48:25 +0200 | [diff] [blame] | 4300 | free(rotate); |
| 4301 | } |
| 4302 | } |
| 4303 | |
Jonas Ådahl | 1ea343e | 2013-10-25 23:18:05 +0200 | [diff] [blame] | 4304 | static void |
| 4305 | rotate_grab_cancel(struct weston_pointer_grab *grab) |
| 4306 | { |
| 4307 | struct rotate_grab *rotate = |
| 4308 | container_of(grab, struct rotate_grab, base.grab); |
| 4309 | |
| 4310 | shell_grab_end(&rotate->base); |
| 4311 | free(rotate); |
| 4312 | } |
| 4313 | |
Kristian Høgsberg | 02bbabb | 2013-05-06 22:15:05 -0400 | [diff] [blame] | 4314 | static const struct weston_pointer_grab_interface rotate_grab_interface = { |
Pekka Paalanen | 460099f | 2012-01-20 16:48:25 +0200 | [diff] [blame] | 4315 | noop_grab_focus, |
| 4316 | rotate_grab_motion, |
| 4317 | rotate_grab_button, |
Jonas Ådahl | 1ea343e | 2013-10-25 23:18:05 +0200 | [diff] [blame] | 4318 | rotate_grab_cancel, |
Pekka Paalanen | 460099f | 2012-01-20 16:48:25 +0200 | [diff] [blame] | 4319 | }; |
| 4320 | |
| 4321 | static void |
Kristian Høgsberg | e314875 | 2013-05-06 23:19:49 -0400 | [diff] [blame] | 4322 | surface_rotate(struct shell_surface *surface, struct weston_seat *seat) |
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 | struct rotate_grab *rotate; |
John Kåre Alsaker | 490d02a | 2012-09-30 02:57:21 +0200 | [diff] [blame] | 4325 | float dx, dy; |
| 4326 | float r; |
Pekka Paalanen | 460099f | 2012-01-20 16:48:25 +0200 | [diff] [blame] | 4327 | |
Pekka Paalanen | 460099f | 2012-01-20 16:48:25 +0200 | [diff] [blame] | 4328 | rotate = malloc(sizeof *rotate); |
| 4329 | if (!rotate) |
| 4330 | return; |
| 4331 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 4332 | weston_view_to_global_float(surface->view, |
Jason Ekstrand | 918f2dd | 2013-12-02 21:01:53 -0600 | [diff] [blame] | 4333 | surface->surface->width * 0.5f, |
| 4334 | surface->surface->height * 0.5f, |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 4335 | &rotate->center.x, &rotate->center.y); |
Pekka Paalanen | 460099f | 2012-01-20 16:48:25 +0200 | [diff] [blame] | 4336 | |
Daniel Stone | 37816df | 2012-05-16 18:45:18 +0100 | [diff] [blame] | 4337 | dx = wl_fixed_to_double(seat->pointer->x) - rotate->center.x; |
| 4338 | dy = wl_fixed_to_double(seat->pointer->y) - rotate->center.y; |
Kristian Høgsberg | 765e27b | 2012-01-27 13:36:13 -0500 | [diff] [blame] | 4339 | r = sqrtf(dx * dx + dy * dy); |
| 4340 | if (r > 20.0f) { |
| 4341 | struct weston_matrix inverse; |
| 4342 | |
| 4343 | weston_matrix_init(&inverse); |
Vasily Khoruzhick | 1bbf372 | 2013-01-28 22:40:28 +0300 | [diff] [blame] | 4344 | weston_matrix_rotate_xy(&inverse, dx / r, -dy / r); |
Kristian Høgsberg | 765e27b | 2012-01-27 13:36:13 -0500 | [diff] [blame] | 4345 | weston_matrix_multiply(&surface->rotation.rotation, &inverse); |
Rafal Mielniczuk | 2d7ab82 | 2012-03-22 22:22:04 +0100 | [diff] [blame] | 4346 | |
| 4347 | weston_matrix_init(&rotate->rotation); |
Vasily Khoruzhick | 1bbf372 | 2013-01-28 22:40:28 +0300 | [diff] [blame] | 4348 | weston_matrix_rotate_xy(&rotate->rotation, dx / r, dy / r); |
Kristian Høgsberg | 765e27b | 2012-01-27 13:36:13 -0500 | [diff] [blame] | 4349 | } else { |
| 4350 | weston_matrix_init(&surface->rotation.rotation); |
| 4351 | weston_matrix_init(&rotate->rotation); |
| 4352 | } |
| 4353 | |
Ander Conselvan de Oliveira | b9d2a0f | 2012-06-28 18:08:05 +0300 | [diff] [blame] | 4354 | shell_grab_start(&rotate->base, &rotate_grab_interface, surface, |
| 4355 | seat->pointer, DESKTOP_SHELL_CURSOR_ARROW); |
Pekka Paalanen | 460099f | 2012-01-20 16:48:25 +0200 | [diff] [blame] | 4356 | } |
| 4357 | |
| 4358 | static void |
Kristian Høgsberg | e314875 | 2013-05-06 23:19:49 -0400 | [diff] [blame] | 4359 | 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] | 4360 | void *data) |
| 4361 | { |
Kristian Høgsberg | 7ab139c | 2013-10-24 16:21:39 -0700 | [diff] [blame] | 4362 | struct weston_surface *focus = seat->pointer->focus->surface; |
Pekka Paalanen | 01388e2 | 2013-04-25 13:57:44 +0300 | [diff] [blame] | 4363 | struct weston_surface *base_surface; |
Kristian Høgsberg | 0c36903 | 2013-02-14 21:31:44 -0500 | [diff] [blame] | 4364 | struct shell_surface *surface; |
| 4365 | |
Pekka Paalanen | 01388e2 | 2013-04-25 13:57:44 +0300 | [diff] [blame] | 4366 | base_surface = weston_surface_get_main_surface(focus); |
Kristian Høgsberg | 0c36903 | 2013-02-14 21:31:44 -0500 | [diff] [blame] | 4367 | if (base_surface == NULL) |
| 4368 | return; |
| 4369 | |
| 4370 | surface = get_shell_surface(base_surface); |
Rafael Antognolli | 03b1659 | 2013-12-03 15:35:42 -0200 | [diff] [blame] | 4371 | if (surface == NULL || surface->state.fullscreen || |
| 4372 | surface->state.maximized) |
Kristian Høgsberg | 0c36903 | 2013-02-14 21:31:44 -0500 | [diff] [blame] | 4373 | return; |
| 4374 | |
| 4375 | surface_rotate(surface, seat); |
| 4376 | } |
| 4377 | |
Philip Withnall | 83ffd9d | 2013-11-25 18:01:42 +0000 | [diff] [blame] | 4378 | /* Move all fullscreen layers down to the current workspace in a non-reversible |
| 4379 | * manner. This should be used when implementing shell-wide overlays, such as |
| 4380 | * the alt-tab switcher, which need to de-promote fullscreen layers. */ |
Kristian Høgsberg | 1ef2313 | 2013-12-04 00:20:01 -0800 | [diff] [blame] | 4381 | void |
Kristian Høgsberg | b0d8e77 | 2012-06-18 16:34:58 -0400 | [diff] [blame] | 4382 | lower_fullscreen_layer(struct desktop_shell *shell) |
| 4383 | { |
| 4384 | struct workspace *ws; |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 4385 | struct weston_view *view, *prev; |
Kristian Høgsberg | b0d8e77 | 2012-06-18 16:34:58 -0400 | [diff] [blame] | 4386 | |
| 4387 | ws = get_current_workspace(shell); |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 4388 | wl_list_for_each_reverse_safe(view, prev, |
| 4389 | &shell->fullscreen_layer.view_list, |
Philip Withnall | 83ffd9d | 2013-11-25 18:01:42 +0000 | [diff] [blame] | 4390 | layer_link) { |
| 4391 | wl_list_remove(&view->layer_link); |
| 4392 | wl_list_insert(&ws->layer.view_list, &view->layer_link); |
| 4393 | weston_view_damage_below(view); |
| 4394 | weston_surface_damage(view->surface); |
| 4395 | } |
Kristian Høgsberg | b0d8e77 | 2012-06-18 16:34:58 -0400 | [diff] [blame] | 4396 | } |
| 4397 | |
Kristian Høgsberg | 1ef2313 | 2013-12-04 00:20:01 -0800 | [diff] [blame] | 4398 | void |
Tiago Vignatti | be14326 | 2012-04-16 17:31:41 +0300 | [diff] [blame] | 4399 | activate(struct desktop_shell *shell, struct weston_surface *es, |
Daniel Stone | 37816df | 2012-05-16 18:45:18 +0100 | [diff] [blame] | 4400 | struct weston_seat *seat) |
Kristian Høgsberg | 7584062 | 2011-09-06 13:48:16 -0400 | [diff] [blame] | 4401 | { |
Pekka Paalanen | 01388e2 | 2013-04-25 13:57:44 +0300 | [diff] [blame] | 4402 | struct weston_surface *main_surface; |
Kristian Høgsberg | 2f5faff | 2012-07-31 16:36:34 -0400 | [diff] [blame] | 4403 | struct focus_state *state; |
Jonas Ådahl | 8538b22 | 2012-08-29 22:13:03 +0200 | [diff] [blame] | 4404 | struct workspace *ws; |
Louis-Francis Ratté-Boulianne | b482dbd | 2013-11-19 11:37:11 +0100 | [diff] [blame] | 4405 | struct weston_surface *old_es; |
Rafael Antognolli | 03b1659 | 2013-12-03 15:35:42 -0200 | [diff] [blame] | 4406 | struct shell_surface *shsurf; |
Kristian Høgsberg | 7584062 | 2011-09-06 13:48:16 -0400 | [diff] [blame] | 4407 | |
Pekka Paalanen | 01388e2 | 2013-04-25 13:57:44 +0300 | [diff] [blame] | 4408 | main_surface = weston_surface_get_main_surface(es); |
| 4409 | |
Daniel Stone | 37816df | 2012-05-16 18:45:18 +0100 | [diff] [blame] | 4410 | weston_surface_activate(es, seat); |
Kristian Høgsberg | 7584062 | 2011-09-06 13:48:16 -0400 | [diff] [blame] | 4411 | |
Jonas Ådahl | 8538b22 | 2012-08-29 22:13:03 +0200 | [diff] [blame] | 4412 | state = ensure_focus_state(shell, seat); |
| 4413 | if (state == NULL) |
| 4414 | return; |
Kristian Høgsberg | 2f5faff | 2012-07-31 16:36:34 -0400 | [diff] [blame] | 4415 | |
Louis-Francis Ratté-Boulianne | b482dbd | 2013-11-19 11:37:11 +0100 | [diff] [blame] | 4416 | old_es = state->keyboard_focus; |
Kristian Høgsberg | 2f5faff | 2012-07-31 16:36:34 -0400 | [diff] [blame] | 4417 | state->keyboard_focus = es; |
| 4418 | wl_list_remove(&state->surface_destroy_listener.link); |
Jason Ekstrand | 26ed73c | 2013-06-06 22:34:41 -0500 | [diff] [blame] | 4419 | wl_signal_add(&es->destroy_signal, &state->surface_destroy_listener); |
Kristian Høgsberg | 2f5faff | 2012-07-31 16:36:34 -0400 | [diff] [blame] | 4420 | |
Rafael Antognolli | 03b1659 | 2013-12-03 15:35:42 -0200 | [diff] [blame] | 4421 | shsurf = get_shell_surface(main_surface); |
| 4422 | if (shsurf->state.fullscreen) |
| 4423 | shell_configure_fullscreen(shsurf); |
| 4424 | else |
Alexander Larsson | f82b6ca | 2013-05-28 16:23:39 +0200 | [diff] [blame] | 4425 | restore_all_output_modes(shell->compositor); |
Louis-Francis Ratté-Boulianne | b482dbd | 2013-11-19 11:37:11 +0100 | [diff] [blame] | 4426 | |
Philip Withnall | 83ffd9d | 2013-11-25 18:01:42 +0000 | [diff] [blame] | 4427 | if (shell->focus_animation_type != ANIMATION_NONE) { |
| 4428 | ws = get_current_workspace(shell); |
Louis-Francis Ratté-Boulianne | b482dbd | 2013-11-19 11:37:11 +0100 | [diff] [blame] | 4429 | 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] | 4430 | } |
| 4431 | |
| 4432 | /* Update the surface’s layer. This brings it to the top of the stacking |
| 4433 | * order as appropriate. */ |
| 4434 | shell_surface_update_layer(get_shell_surface(main_surface)); |
Kristian Høgsberg | 7584062 | 2011-09-06 13:48:16 -0400 | [diff] [blame] | 4435 | } |
| 4436 | |
Alex Wu | 2185843 | 2012-04-01 20:13:08 +0800 | [diff] [blame] | 4437 | /* no-op func for checking black surface */ |
| 4438 | static void |
Jason Ekstrand | 918f2dd | 2013-12-02 21:01:53 -0600 | [diff] [blame] | 4439 | 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] | 4440 | { |
| 4441 | } |
| 4442 | |
Quentin Glidic | c0d79ce | 2013-01-29 14:16:13 +0100 | [diff] [blame] | 4443 | static bool |
Alex Wu | 2185843 | 2012-04-01 20:13:08 +0800 | [diff] [blame] | 4444 | is_black_surface (struct weston_surface *es, struct weston_surface **fs_surface) |
| 4445 | { |
| 4446 | if (es->configure == black_surface_configure) { |
| 4447 | if (fs_surface) |
Giulio Camuffo | 7fe01b1 | 2013-03-28 18:02:42 +0100 | [diff] [blame] | 4448 | *fs_surface = (struct weston_surface *)es->configure_private; |
Alex Wu | 2185843 | 2012-04-01 20:13:08 +0800 | [diff] [blame] | 4449 | return true; |
| 4450 | } |
| 4451 | return false; |
| 4452 | } |
| 4453 | |
Kristian Høgsberg | 7584062 | 2011-09-06 13:48:16 -0400 | [diff] [blame] | 4454 | static void |
Neil Roberts | a28c693 | 2013-10-03 16:43:04 +0100 | [diff] [blame] | 4455 | activate_binding(struct weston_seat *seat, |
| 4456 | struct desktop_shell *shell, |
| 4457 | struct weston_surface *focus) |
Kristian Høgsberg | e1a850e | 2011-12-19 15:18:05 -0500 | [diff] [blame] | 4458 | { |
Pekka Paalanen | 01388e2 | 2013-04-25 13:57:44 +0300 | [diff] [blame] | 4459 | struct weston_surface *main_surface; |
Kristian Høgsberg | e1a850e | 2011-12-19 15:18:05 -0500 | [diff] [blame] | 4460 | |
Alex Wu | 9c35e6b | 2012-03-05 14:13:13 +0800 | [diff] [blame] | 4461 | if (!focus) |
| 4462 | return; |
| 4463 | |
Pekka Paalanen | 01388e2 | 2013-04-25 13:57:44 +0300 | [diff] [blame] | 4464 | if (is_black_surface(focus, &main_surface)) |
| 4465 | focus = main_surface; |
Alex Wu | 4539b08 | 2012-03-01 12:57:46 +0800 | [diff] [blame] | 4466 | |
Pekka Paalanen | 01388e2 | 2013-04-25 13:57:44 +0300 | [diff] [blame] | 4467 | main_surface = weston_surface_get_main_surface(focus); |
| 4468 | if (get_shell_surface_type(main_surface) == SHELL_SURFACE_NONE) |
Kristian Høgsberg | 0636ac3 | 2012-06-27 10:22:15 -0400 | [diff] [blame] | 4469 | return; |
Kristian Høgsberg | 85b2e4b | 2012-06-21 16:49:42 -0400 | [diff] [blame] | 4470 | |
Neil Roberts | a28c693 | 2013-10-03 16:43:04 +0100 | [diff] [blame] | 4471 | activate(shell, focus, seat); |
| 4472 | } |
| 4473 | |
| 4474 | static void |
| 4475 | click_to_activate_binding(struct weston_seat *seat, uint32_t time, uint32_t button, |
| 4476 | void *data) |
| 4477 | { |
| 4478 | if (seat->pointer->grab != &seat->pointer->default_grab) |
| 4479 | return; |
| 4480 | |
Kristian Høgsberg | 7ab139c | 2013-10-24 16:21:39 -0700 | [diff] [blame] | 4481 | activate_binding(seat, data, seat->pointer->focus->surface); |
Neil Roberts | a28c693 | 2013-10-03 16:43:04 +0100 | [diff] [blame] | 4482 | } |
| 4483 | |
| 4484 | static void |
| 4485 | touch_to_activate_binding(struct weston_seat *seat, uint32_t time, void *data) |
| 4486 | { |
| 4487 | if (seat->touch->grab != &seat->touch->default_grab) |
| 4488 | return; |
| 4489 | |
Kristian Høgsberg | 7ab139c | 2013-10-24 16:21:39 -0700 | [diff] [blame] | 4490 | activate_binding(seat, data, seat->touch->focus->surface); |
Kristian Høgsberg | e1a850e | 2011-12-19 15:18:05 -0500 | [diff] [blame] | 4491 | } |
| 4492 | |
| 4493 | static void |
Ander Conselvan de Oliveira | 19d10ef | 2013-02-21 18:35:20 +0200 | [diff] [blame] | 4494 | lock(struct desktop_shell *shell) |
Kristian Høgsberg | 02ec0a5 | 2011-04-23 13:04:11 -0400 | [diff] [blame] | 4495 | { |
Kristian Høgsberg | 4476aaf | 2012-06-25 14:03:13 -0400 | [diff] [blame] | 4496 | struct workspace *ws = get_current_workspace(shell); |
Pekka Paalanen | f0fc70d | 2011-11-15 13:34:54 +0200 | [diff] [blame] | 4497 | |
Tiago Vignatti | 8e53c7f | 2012-02-29 19:53:50 +0200 | [diff] [blame] | 4498 | if (shell->locked) { |
Ander Conselvan de Oliveira | 87524b6 | 2013-02-21 18:35:22 +0200 | [diff] [blame] | 4499 | weston_compositor_sleep(shell->compositor); |
Pekka Paalanen | f0fc70d | 2011-11-15 13:34:54 +0200 | [diff] [blame] | 4500 | return; |
Tiago Vignatti | 8e53c7f | 2012-02-29 19:53:50 +0200 | [diff] [blame] | 4501 | } |
Pekka Paalanen | 9ef3e01 | 2011-11-15 13:34:48 +0200 | [diff] [blame] | 4502 | |
| 4503 | shell->locked = true; |
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 | /* Hide all surfaces by removing the fullscreen, panel and |
| 4506 | * toplevel layers. This way nothing else can show or receive |
| 4507 | * input events while we are locked. */ |
Pekka Paalanen | f0fc70d | 2011-11-15 13:34:54 +0200 | [diff] [blame] | 4508 | |
Kristian Høgsberg | 3be2ce9 | 2012-02-29 12:42:35 -0500 | [diff] [blame] | 4509 | wl_list_remove(&shell->panel_layer.link); |
Kristian Høgsberg | 3be2ce9 | 2012-02-29 12:42:35 -0500 | [diff] [blame] | 4510 | wl_list_remove(&shell->fullscreen_layer.link); |
Philipp Brüschweiler | 711fda8 | 2012-08-09 18:50:43 +0200 | [diff] [blame] | 4511 | if (shell->showing_input_panels) |
| 4512 | wl_list_remove(&shell->input_panel_layer.link); |
Kristian Høgsberg | 4476aaf | 2012-06-25 14:03:13 -0400 | [diff] [blame] | 4513 | wl_list_remove(&ws->layer.link); |
Kristian Høgsberg | 3be2ce9 | 2012-02-29 12:42:35 -0500 | [diff] [blame] | 4514 | wl_list_insert(&shell->compositor->cursor_layer.link, |
| 4515 | &shell->lock_layer.link); |
Pekka Paalanen | f0fc70d | 2011-11-15 13:34:54 +0200 | [diff] [blame] | 4516 | |
Pekka Paalanen | 77346a6 | 2011-11-30 16:26:35 +0200 | [diff] [blame] | 4517 | launch_screensaver(shell); |
| 4518 | |
Pekka Paalanen | f0fc70d | 2011-11-15 13:34:54 +0200 | [diff] [blame] | 4519 | /* TODO: disable bindings that should not work while locked. */ |
| 4520 | |
| 4521 | /* All this must be undone in resume_desktop(). */ |
Pekka Paalanen | 9ef3e01 | 2011-11-15 13:34:48 +0200 | [diff] [blame] | 4522 | } |
| 4523 | |
| 4524 | static void |
Ander Conselvan de Oliveira | 19d10ef | 2013-02-21 18:35:20 +0200 | [diff] [blame] | 4525 | unlock(struct desktop_shell *shell) |
Pekka Paalanen | 9ef3e01 | 2011-11-15 13:34:48 +0200 | [diff] [blame] | 4526 | { |
Pekka Paalanen | d81c216 | 2011-11-16 13:47:34 +0200 | [diff] [blame] | 4527 | if (!shell->locked || shell->lock_surface) { |
Ander Conselvan de Oliveira | 87524b6 | 2013-02-21 18:35:22 +0200 | [diff] [blame] | 4528 | shell_fade(shell, FADE_IN); |
Pekka Paalanen | 9ef3e01 | 2011-11-15 13:34:48 +0200 | [diff] [blame] | 4529 | return; |
| 4530 | } |
| 4531 | |
| 4532 | /* If desktop-shell client has gone away, unlock immediately. */ |
| 4533 | if (!shell->child.desktop_shell) { |
Pekka Paalanen | f0fc70d | 2011-11-15 13:34:54 +0200 | [diff] [blame] | 4534 | resume_desktop(shell); |
Pekka Paalanen | 9ef3e01 | 2011-11-15 13:34:48 +0200 | [diff] [blame] | 4535 | return; |
| 4536 | } |
| 4537 | |
| 4538 | if (shell->prepare_event_sent) |
| 4539 | return; |
| 4540 | |
Kristian Høgsberg | 0b5cd0c | 2012-03-04 21:57:37 -0500 | [diff] [blame] | 4541 | desktop_shell_send_prepare_lock_surface(shell->child.desktop_shell); |
Pekka Paalanen | 9ef3e01 | 2011-11-15 13:34:48 +0200 | [diff] [blame] | 4542 | shell->prepare_event_sent = true; |
Kristian Høgsberg | 02ec0a5 | 2011-04-23 13:04:11 -0400 | [diff] [blame] | 4543 | } |
| 4544 | |
| 4545 | static void |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 4546 | shell_fade_done(struct weston_view_animation *animation, void *data) |
Ander Conselvan de Oliveira | 19d10ef | 2013-02-21 18:35:20 +0200 | [diff] [blame] | 4547 | { |
| 4548 | struct desktop_shell *shell = data; |
| 4549 | |
| 4550 | shell->fade.animation = NULL; |
| 4551 | |
| 4552 | switch (shell->fade.type) { |
| 4553 | case FADE_IN: |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 4554 | weston_surface_destroy(shell->fade.view->surface); |
| 4555 | shell->fade.view = NULL; |
Ander Conselvan de Oliveira | 19d10ef | 2013-02-21 18:35:20 +0200 | [diff] [blame] | 4556 | break; |
| 4557 | case FADE_OUT: |
Ander Conselvan de Oliveira | 19d10ef | 2013-02-21 18:35:20 +0200 | [diff] [blame] | 4558 | lock(shell); |
| 4559 | break; |
Philip Withnall | 4a86a0a | 2013-11-25 18:01:32 +0000 | [diff] [blame] | 4560 | default: |
| 4561 | break; |
Ander Conselvan de Oliveira | 19d10ef | 2013-02-21 18:35:20 +0200 | [diff] [blame] | 4562 | } |
| 4563 | } |
| 4564 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 4565 | static struct weston_view * |
Pekka Paalanen | 79346ab | 2013-05-22 18:03:09 +0300 | [diff] [blame] | 4566 | shell_fade_create_surface(struct desktop_shell *shell) |
Ander Conselvan de Oliveira | 19d10ef | 2013-02-21 18:35:20 +0200 | [diff] [blame] | 4567 | { |
| 4568 | struct weston_compositor *compositor = shell->compositor; |
| 4569 | struct weston_surface *surface; |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 4570 | struct weston_view *view; |
Pekka Paalanen | 79346ab | 2013-05-22 18:03:09 +0300 | [diff] [blame] | 4571 | |
| 4572 | surface = weston_surface_create(compositor); |
| 4573 | if (!surface) |
| 4574 | return NULL; |
| 4575 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 4576 | view = weston_view_create(surface); |
| 4577 | if (!view) { |
| 4578 | weston_surface_destroy(surface); |
| 4579 | return NULL; |
| 4580 | } |
| 4581 | |
Jason Ekstrand | 918f2dd | 2013-12-02 21:01:53 -0600 | [diff] [blame] | 4582 | surface->width = 8192; |
| 4583 | surface->height = 8192; |
| 4584 | weston_view_set_position(view, 0, 0); |
Pekka Paalanen | 79346ab | 2013-05-22 18:03:09 +0300 | [diff] [blame] | 4585 | 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] | 4586 | wl_list_insert(&compositor->fade_layer.view_list, |
| 4587 | &view->layer_link); |
Pekka Paalanen | 79346ab | 2013-05-22 18:03:09 +0300 | [diff] [blame] | 4588 | pixman_region32_init(&surface->input); |
| 4589 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 4590 | return view; |
Pekka Paalanen | 79346ab | 2013-05-22 18:03:09 +0300 | [diff] [blame] | 4591 | } |
| 4592 | |
| 4593 | static void |
| 4594 | shell_fade(struct desktop_shell *shell, enum fade_type type) |
| 4595 | { |
Ander Conselvan de Oliveira | 19d10ef | 2013-02-21 18:35:20 +0200 | [diff] [blame] | 4596 | float tint; |
| 4597 | |
| 4598 | switch (type) { |
| 4599 | case FADE_IN: |
| 4600 | tint = 0.0; |
| 4601 | break; |
| 4602 | case FADE_OUT: |
| 4603 | tint = 1.0; |
| 4604 | break; |
| 4605 | default: |
| 4606 | weston_log("shell: invalid fade type\n"); |
| 4607 | return; |
| 4608 | } |
| 4609 | |
| 4610 | shell->fade.type = type; |
| 4611 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 4612 | if (shell->fade.view == NULL) { |
| 4613 | shell->fade.view = shell_fade_create_surface(shell); |
| 4614 | if (!shell->fade.view) |
Ander Conselvan de Oliveira | 19d10ef | 2013-02-21 18:35:20 +0200 | [diff] [blame] | 4615 | return; |
| 4616 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 4617 | shell->fade.view->alpha = 1.0 - tint; |
| 4618 | weston_view_update_transform(shell->fade.view); |
Ander Conselvan de Oliveira | 19d10ef | 2013-02-21 18:35:20 +0200 | [diff] [blame] | 4619 | } |
| 4620 | |
| 4621 | if (shell->fade.animation) |
Kristian Høgsberg | 5281fb1 | 2013-06-17 10:10:28 -0400 | [diff] [blame] | 4622 | weston_fade_update(shell->fade.animation, tint); |
Ander Conselvan de Oliveira | 19d10ef | 2013-02-21 18:35:20 +0200 | [diff] [blame] | 4623 | else |
| 4624 | shell->fade.animation = |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 4625 | weston_fade_run(shell->fade.view, |
Kristian Høgsberg | 5281fb1 | 2013-06-17 10:10:28 -0400 | [diff] [blame] | 4626 | 1.0 - tint, tint, 300.0, |
Ander Conselvan de Oliveira | 19d10ef | 2013-02-21 18:35:20 +0200 | [diff] [blame] | 4627 | shell_fade_done, shell); |
| 4628 | } |
| 4629 | |
| 4630 | static void |
Pekka Paalanen | 79346ab | 2013-05-22 18:03:09 +0300 | [diff] [blame] | 4631 | do_shell_fade_startup(void *data) |
| 4632 | { |
| 4633 | struct desktop_shell *shell = data; |
| 4634 | |
Kristian Høgsberg | 724c8d9 | 2013-10-16 11:38:24 -0700 | [diff] [blame] | 4635 | if (shell->startup_animation_type == ANIMATION_FADE) |
| 4636 | shell_fade(shell, FADE_IN); |
| 4637 | else if (shell->startup_animation_type == ANIMATION_NONE) { |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 4638 | weston_surface_destroy(shell->fade.view->surface); |
| 4639 | shell->fade.view = NULL; |
Kristian Høgsberg | 724c8d9 | 2013-10-16 11:38:24 -0700 | [diff] [blame] | 4640 | } |
Pekka Paalanen | 79346ab | 2013-05-22 18:03:09 +0300 | [diff] [blame] | 4641 | } |
| 4642 | |
| 4643 | static void |
| 4644 | shell_fade_startup(struct desktop_shell *shell) |
| 4645 | { |
| 4646 | struct wl_event_loop *loop; |
| 4647 | |
| 4648 | if (!shell->fade.startup_timer) |
| 4649 | return; |
| 4650 | |
| 4651 | wl_event_source_remove(shell->fade.startup_timer); |
| 4652 | shell->fade.startup_timer = NULL; |
| 4653 | |
| 4654 | loop = wl_display_get_event_loop(shell->compositor->wl_display); |
| 4655 | wl_event_loop_add_idle(loop, do_shell_fade_startup, shell); |
| 4656 | } |
| 4657 | |
| 4658 | static int |
| 4659 | fade_startup_timeout(void *data) |
| 4660 | { |
| 4661 | struct desktop_shell *shell = data; |
| 4662 | |
| 4663 | shell_fade_startup(shell); |
| 4664 | return 0; |
| 4665 | } |
| 4666 | |
| 4667 | static void |
| 4668 | shell_fade_init(struct desktop_shell *shell) |
| 4669 | { |
| 4670 | /* Make compositor output all black, and wait for the desktop-shell |
| 4671 | * client to signal it is ready, then fade in. The timer triggers a |
| 4672 | * fade-in, in case the desktop-shell client takes too long. |
| 4673 | */ |
| 4674 | |
| 4675 | struct wl_event_loop *loop; |
| 4676 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 4677 | if (shell->fade.view != NULL) { |
Pekka Paalanen | 79346ab | 2013-05-22 18:03:09 +0300 | [diff] [blame] | 4678 | weston_log("%s: warning: fade surface already exists\n", |
| 4679 | __func__); |
| 4680 | return; |
| 4681 | } |
| 4682 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 4683 | shell->fade.view = shell_fade_create_surface(shell); |
| 4684 | if (!shell->fade.view) |
Pekka Paalanen | 79346ab | 2013-05-22 18:03:09 +0300 | [diff] [blame] | 4685 | return; |
| 4686 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 4687 | weston_view_update_transform(shell->fade.view); |
| 4688 | weston_surface_damage(shell->fade.view->surface); |
Pekka Paalanen | 79346ab | 2013-05-22 18:03:09 +0300 | [diff] [blame] | 4689 | |
| 4690 | loop = wl_display_get_event_loop(shell->compositor->wl_display); |
| 4691 | shell->fade.startup_timer = |
| 4692 | wl_event_loop_add_timer(loop, fade_startup_timeout, shell); |
| 4693 | wl_event_source_timer_update(shell->fade.startup_timer, 15000); |
| 4694 | } |
| 4695 | |
| 4696 | static void |
Ander Conselvan de Oliveira | a457563 | 2013-02-21 18:35:23 +0200 | [diff] [blame] | 4697 | idle_handler(struct wl_listener *listener, void *data) |
Ander Conselvan de Oliveira | 19d10ef | 2013-02-21 18:35:20 +0200 | [diff] [blame] | 4698 | { |
| 4699 | struct desktop_shell *shell = |
Ander Conselvan de Oliveira | a457563 | 2013-02-21 18:35:23 +0200 | [diff] [blame] | 4700 | container_of(listener, struct desktop_shell, idle_listener); |
Ander Conselvan de Oliveira | 19d10ef | 2013-02-21 18:35:20 +0200 | [diff] [blame] | 4701 | |
| 4702 | shell_fade(shell, FADE_OUT); |
| 4703 | /* lock() is called from shell_fade_done() */ |
| 4704 | } |
| 4705 | |
| 4706 | static void |
Ander Conselvan de Oliveira | a457563 | 2013-02-21 18:35:23 +0200 | [diff] [blame] | 4707 | wake_handler(struct wl_listener *listener, void *data) |
Ander Conselvan de Oliveira | 19d10ef | 2013-02-21 18:35:20 +0200 | [diff] [blame] | 4708 | { |
| 4709 | struct desktop_shell *shell = |
Ander Conselvan de Oliveira | a457563 | 2013-02-21 18:35:23 +0200 | [diff] [blame] | 4710 | container_of(listener, struct desktop_shell, wake_listener); |
Ander Conselvan de Oliveira | 19d10ef | 2013-02-21 18:35:20 +0200 | [diff] [blame] | 4711 | |
Ander Conselvan de Oliveira | 19d10ef | 2013-02-21 18:35:20 +0200 | [diff] [blame] | 4712 | unlock(shell); |
| 4713 | } |
| 4714 | |
| 4715 | static void |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 4716 | center_on_output(struct weston_view *view, struct weston_output *output) |
Pekka Paalanen | 77346a6 | 2011-11-30 16:26:35 +0200 | [diff] [blame] | 4717 | { |
Giulio Camuffo | b836664 | 2013-04-25 13:57:46 +0300 | [diff] [blame] | 4718 | int32_t surf_x, surf_y, width, height; |
Ander Conselvan de Oliveira | 012b4c7 | 2012-11-27 17:03:42 +0200 | [diff] [blame] | 4719 | float x, y; |
Pekka Paalanen | 77346a6 | 2011-11-30 16:26:35 +0200 | [diff] [blame] | 4720 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 4721 | surface_subsurfaces_boundingbox(view->surface, &surf_x, &surf_y, &width, &height); |
Giulio Camuffo | b836664 | 2013-04-25 13:57:46 +0300 | [diff] [blame] | 4722 | |
| 4723 | x = output->x + (output->width - width) / 2 - surf_x / 2; |
| 4724 | y = output->y + (output->height - height) / 2 - surf_y / 2; |
Ander Conselvan de Oliveira | 012b4c7 | 2012-11-27 17:03:42 +0200 | [diff] [blame] | 4725 | |
Jason Ekstrand | 918f2dd | 2013-12-02 21:01:53 -0600 | [diff] [blame] | 4726 | weston_view_set_position(view, x, y); |
Pekka Paalanen | 77346a6 | 2011-11-30 16:26:35 +0200 | [diff] [blame] | 4727 | } |
| 4728 | |
| 4729 | static void |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 4730 | weston_view_set_initial_position(struct weston_view *view, |
| 4731 | struct desktop_shell *shell) |
Rob Bradford | ac63e5b | 2012-08-13 14:07:52 +0100 | [diff] [blame] | 4732 | { |
| 4733 | struct weston_compositor *compositor = shell->compositor; |
| 4734 | int ix = 0, iy = 0; |
| 4735 | int range_x, range_y; |
| 4736 | int dx, dy, x, y, panel_height; |
| 4737 | struct weston_output *output, *target_output = NULL; |
| 4738 | struct weston_seat *seat; |
| 4739 | |
| 4740 | /* As a heuristic place the new window on the same output as the |
| 4741 | * pointer. Falling back to the output containing 0, 0. |
| 4742 | * |
| 4743 | * TODO: Do something clever for touch too? |
| 4744 | */ |
| 4745 | wl_list_for_each(seat, &compositor->seat_list, link) { |
Kristian Høgsberg | 2bf8762 | 2013-05-07 23:17:41 -0400 | [diff] [blame] | 4746 | if (seat->pointer) { |
Kristian Høgsberg | e314875 | 2013-05-06 23:19:49 -0400 | [diff] [blame] | 4747 | ix = wl_fixed_to_int(seat->pointer->x); |
| 4748 | iy = wl_fixed_to_int(seat->pointer->y); |
Rob Bradford | ac63e5b | 2012-08-13 14:07:52 +0100 | [diff] [blame] | 4749 | break; |
| 4750 | } |
| 4751 | } |
| 4752 | |
| 4753 | wl_list_for_each(output, &compositor->output_list, link) { |
| 4754 | if (pixman_region32_contains_point(&output->region, ix, iy, NULL)) { |
| 4755 | target_output = output; |
| 4756 | break; |
| 4757 | } |
| 4758 | } |
| 4759 | |
| 4760 | if (!target_output) { |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 4761 | weston_view_set_position(view, 10 + random() % 400, |
| 4762 | 10 + random() % 400); |
Rob Bradford | ac63e5b | 2012-08-13 14:07:52 +0100 | [diff] [blame] | 4763 | return; |
| 4764 | } |
| 4765 | |
| 4766 | /* Valid range within output where the surface will still be onscreen. |
| 4767 | * If this is negative it means that the surface is bigger than |
| 4768 | * output. |
| 4769 | */ |
| 4770 | panel_height = get_output_panel_height(shell, target_output); |
Jason Ekstrand | 918f2dd | 2013-12-02 21:01:53 -0600 | [diff] [blame] | 4771 | range_x = target_output->width - view->surface->width; |
Scott Moreau | 1bad5db | 2012-08-18 01:04:05 -0600 | [diff] [blame] | 4772 | range_y = (target_output->height - panel_height) - |
Jason Ekstrand | 918f2dd | 2013-12-02 21:01:53 -0600 | [diff] [blame] | 4773 | view->surface->height; |
Rob Bradford | ac63e5b | 2012-08-13 14:07:52 +0100 | [diff] [blame] | 4774 | |
Rob Bradford | 4cb88c7 | 2012-08-13 15:18:44 +0100 | [diff] [blame] | 4775 | if (range_x > 0) |
Rob Bradford | ac63e5b | 2012-08-13 14:07:52 +0100 | [diff] [blame] | 4776 | dx = random() % range_x; |
Rob Bradford | ac63e5b | 2012-08-13 14:07:52 +0100 | [diff] [blame] | 4777 | else |
Rob Bradford | 4cb88c7 | 2012-08-13 15:18:44 +0100 | [diff] [blame] | 4778 | dx = 0; |
| 4779 | |
| 4780 | if (range_y > 0) |
Rob Bradford | ac63e5b | 2012-08-13 14:07:52 +0100 | [diff] [blame] | 4781 | dy = panel_height + random() % range_y; |
Rob Bradford | 4cb88c7 | 2012-08-13 15:18:44 +0100 | [diff] [blame] | 4782 | else |
| 4783 | dy = panel_height; |
Rob Bradford | ac63e5b | 2012-08-13 14:07:52 +0100 | [diff] [blame] | 4784 | |
| 4785 | x = target_output->x + dx; |
| 4786 | y = target_output->y + dy; |
| 4787 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 4788 | weston_view_set_position(view, x, y); |
Rob Bradford | ac63e5b | 2012-08-13 14:07:52 +0100 | [diff] [blame] | 4789 | } |
| 4790 | |
| 4791 | static void |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 4792 | map(struct desktop_shell *shell, struct shell_surface *shsurf, |
Jason Ekstrand | 918f2dd | 2013-12-02 21:01:53 -0600 | [diff] [blame] | 4793 | int32_t sx, int32_t sy) |
Kristian Høgsberg | 02ec0a5 | 2011-04-23 13:04:11 -0400 | [diff] [blame] | 4794 | { |
Kristian Høgsberg | 8334bc1 | 2012-01-03 10:29:47 -0500 | [diff] [blame] | 4795 | struct weston_compositor *compositor = shell->compositor; |
Daniel Stone | b210468 | 2012-05-30 16:31:56 +0100 | [diff] [blame] | 4796 | struct weston_seat *seat; |
Juan Zhao | 96879df | 2012-02-07 08:45:41 +0800 | [diff] [blame] | 4797 | int panel_height = 0; |
Giulio Camuffo | b836664 | 2013-04-25 13:57:46 +0300 | [diff] [blame] | 4798 | int32_t surf_x, surf_y; |
Pekka Paalanen | 57da4a8 | 2011-11-23 16:42:16 +0200 | [diff] [blame] | 4799 | |
Pekka Paalanen | 77346a6 | 2011-11-30 16:26:35 +0200 | [diff] [blame] | 4800 | /* initial positioning, see also configure() */ |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 4801 | switch (shsurf->type) { |
Rafael Antognolli | ed207b4 | 2013-12-03 15:35:43 -0200 | [diff] [blame] | 4802 | case SHELL_SURFACE_TOPLEVEL: |
Rafael Antognolli | 03b1659 | 2013-12-03 15:35:42 -0200 | [diff] [blame] | 4803 | if (shsurf->state.fullscreen) { |
| 4804 | center_on_output(shsurf->view, shsurf->fullscreen_output); |
| 4805 | shell_map_fullscreen(shsurf); |
| 4806 | } else if (shsurf->state.maximized) { |
| 4807 | /* use surface configure to set the geometry */ |
| 4808 | panel_height = get_output_panel_height(shell, shsurf->output); |
| 4809 | surface_subsurfaces_boundingbox(shsurf->surface, |
| 4810 | &surf_x, &surf_y, NULL, NULL); |
| 4811 | weston_view_set_position(shsurf->view, |
| 4812 | shsurf->output->x - surf_x, |
| 4813 | shsurf->output->y + |
| 4814 | panel_height - surf_y); |
Rafael Antognolli | ed207b4 | 2013-12-03 15:35:43 -0200 | [diff] [blame] | 4815 | } else if (!shsurf->state.relative) { |
Rafael Antognolli | 03b1659 | 2013-12-03 15:35:42 -0200 | [diff] [blame] | 4816 | weston_view_set_initial_position(shsurf->view, shell); |
| 4817 | } |
Juan Zhao | 96879df | 2012-02-07 08:45:41 +0800 | [diff] [blame] | 4818 | break; |
Tiago Vignatti | 0f99701 | 2012-02-10 16:17:23 +0200 | [diff] [blame] | 4819 | case SHELL_SURFACE_POPUP: |
Kristian Høgsberg | 3730f36 | 2012-04-13 12:40:07 -0400 | [diff] [blame] | 4820 | shell_map_popup(shsurf); |
Rob Bradford | db99938 | 2012-12-06 12:07:48 +0000 | [diff] [blame] | 4821 | break; |
Ander Conselvan de Oliveira | e9e0515 | 2012-02-15 17:02:56 +0200 | [diff] [blame] | 4822 | case SHELL_SURFACE_NONE: |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 4823 | weston_view_set_position(shsurf->view, |
| 4824 | shsurf->view->geometry.x + sx, |
| 4825 | shsurf->view->geometry.y + sy); |
Tiago Vignatti | 0f99701 | 2012-02-10 16:17:23 +0200 | [diff] [blame] | 4826 | break; |
Philip Withnall | 0f640e2 | 2013-11-25 18:01:31 +0000 | [diff] [blame] | 4827 | case SHELL_SURFACE_XWAYLAND: |
Pekka Paalanen | 77346a6 | 2011-11-30 16:26:35 +0200 | [diff] [blame] | 4828 | default: |
| 4829 | ; |
| 4830 | } |
Kristian Høgsberg | 7584062 | 2011-09-06 13:48:16 -0400 | [diff] [blame] | 4831 | |
Philip Withnall | e1d75ae | 2013-11-25 18:01:41 +0000 | [diff] [blame] | 4832 | /* Surface stacking order, see also activate(). */ |
| 4833 | shell_surface_update_layer(shsurf); |
Pekka Paalanen | f0fc70d | 2011-11-15 13:34:54 +0200 | [diff] [blame] | 4834 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 4835 | if (shsurf->type != SHELL_SURFACE_NONE) { |
| 4836 | weston_view_update_transform(shsurf->view); |
Rafael Antognolli | 03b1659 | 2013-12-03 15:35:42 -0200 | [diff] [blame] | 4837 | if (shsurf->state.maximized) { |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 4838 | shsurf->surface->output = shsurf->output; |
| 4839 | shsurf->view->output = shsurf->output; |
| 4840 | } |
Ander Conselvan de Oliveira | de56c31 | 2012-03-05 15:39:23 +0200 | [diff] [blame] | 4841 | } |
Kristian Høgsberg | 2f88a40 | 2011-12-04 15:32:59 -0500 | [diff] [blame] | 4842 | |
Rafael Antognolli | ed207b4 | 2013-12-03 15:35:43 -0200 | [diff] [blame] | 4843 | if ((shsurf->type == SHELL_SURFACE_XWAYLAND || shsurf->state.relative) && |
| 4844 | shsurf->transient.flags == WL_SHELL_SURFACE_TRANSIENT_INACTIVE) { |
| 4845 | } |
| 4846 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 4847 | switch (shsurf->type) { |
Tiago Vignatti | fb2adba | 2013-06-12 15:43:21 -0300 | [diff] [blame] | 4848 | /* XXX: xwayland's using the same fields for transient type */ |
| 4849 | case SHELL_SURFACE_XWAYLAND: |
Tiago Vignatti | 99aeb1e | 2012-05-23 22:06:26 +0300 | [diff] [blame] | 4850 | if (shsurf->transient.flags == |
| 4851 | WL_SHELL_SURFACE_TRANSIENT_INACTIVE) |
| 4852 | break; |
| 4853 | case SHELL_SURFACE_TOPLEVEL: |
Rafael Antognolli | ed207b4 | 2013-12-03 15:35:43 -0200 | [diff] [blame] | 4854 | if (shsurf->state.relative && |
| 4855 | shsurf->transient.flags == WL_SHELL_SURFACE_TRANSIENT_INACTIVE) |
| 4856 | break; |
Rafael Antognolli | ba5d2d7 | 2013-12-04 17:49:55 -0200 | [diff] [blame] | 4857 | if (shell->locked) |
Rafael Antognolli | ed207b4 | 2013-12-03 15:35:43 -0200 | [diff] [blame] | 4858 | break; |
| 4859 | wl_list_for_each(seat, &compositor->seat_list, link) |
| 4860 | activate(shell, shsurf->surface, seat); |
Juan Zhao | 7bb92f0 | 2011-12-15 11:31:51 -0500 | [diff] [blame] | 4861 | break; |
Philip Withnall | 0f640e2 | 2013-11-25 18:01:31 +0000 | [diff] [blame] | 4862 | case SHELL_SURFACE_POPUP: |
| 4863 | case SHELL_SURFACE_NONE: |
Juan Zhao | 7bb92f0 | 2011-12-15 11:31:51 -0500 | [diff] [blame] | 4864 | default: |
| 4865 | break; |
| 4866 | } |
| 4867 | |
Rafael Antognolli | 03b1659 | 2013-12-03 15:35:42 -0200 | [diff] [blame] | 4868 | if (shsurf->type == SHELL_SURFACE_TOPLEVEL && |
| 4869 | !shsurf->state.maximized && !shsurf->state.fullscreen) |
Juan Zhao | e10d279 | 2012-04-25 19:09:52 +0800 | [diff] [blame] | 4870 | { |
| 4871 | switch (shell->win_animation_type) { |
| 4872 | case ANIMATION_FADE: |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 4873 | 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] | 4874 | break; |
| 4875 | case ANIMATION_ZOOM: |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 4876 | weston_zoom_run(shsurf->view, 0.5, 1.0, NULL, NULL); |
Juan Zhao | e10d279 | 2012-04-25 19:09:52 +0800 | [diff] [blame] | 4877 | break; |
Philip Withnall | 4a86a0a | 2013-11-25 18:01:32 +0000 | [diff] [blame] | 4878 | case ANIMATION_NONE: |
Juan Zhao | e10d279 | 2012-04-25 19:09:52 +0800 | [diff] [blame] | 4879 | default: |
| 4880 | break; |
| 4881 | } |
| 4882 | } |
Kristian Høgsberg | 32e24cc | 2011-11-09 12:07:35 -0500 | [diff] [blame] | 4883 | } |
| 4884 | |
| 4885 | static void |
Tiago Vignatti | be14326 | 2012-04-16 17:31:41 +0300 | [diff] [blame] | 4886 | configure(struct desktop_shell *shell, struct weston_surface *surface, |
Jason Ekstrand | 918f2dd | 2013-12-02 21:01:53 -0600 | [diff] [blame] | 4887 | float x, float 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 | struct shell_surface *shsurf; |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 4890 | struct weston_view *view; |
Jason Ekstrand | 918f2dd | 2013-12-02 21:01:53 -0600 | [diff] [blame] | 4891 | int32_t mx, my, surf_x, surf_y; |
Kristian Høgsberg | 32e24cc | 2011-11-09 12:07:35 -0500 | [diff] [blame] | 4892 | |
Pekka Paalanen | 77346a6 | 2011-11-30 16:26:35 +0200 | [diff] [blame] | 4893 | shsurf = get_shell_surface(surface); |
Pekka Paalanen | 77346a6 | 2011-11-30 16:26:35 +0200 | [diff] [blame] | 4894 | |
Rafael Antognolli | 03b1659 | 2013-12-03 15:35:42 -0200 | [diff] [blame] | 4895 | if (shsurf->state.fullscreen) |
Alex Wu | 4539b08 | 2012-03-01 12:57:46 +0800 | [diff] [blame] | 4896 | shell_configure_fullscreen(shsurf); |
Rafael Antognolli | 03b1659 | 2013-12-03 15:35:42 -0200 | [diff] [blame] | 4897 | else if (shsurf->state.maximized) { |
Alex Wu | 4539b08 | 2012-03-01 12:57:46 +0800 | [diff] [blame] | 4898 | /* setting x, y and using configure to change that geometry */ |
Giulio Camuffo | b836664 | 2013-04-25 13:57:46 +0300 | [diff] [blame] | 4899 | surface_subsurfaces_boundingbox(shsurf->surface, &surf_x, &surf_y, |
| 4900 | NULL, NULL); |
Jason Ekstrand | 918f2dd | 2013-12-02 21:01:53 -0600 | [diff] [blame] | 4901 | mx = shsurf->output->x - surf_x; |
| 4902 | my = shsurf->output->y + |
| 4903 | get_output_panel_height(shell,shsurf->output) - surf_y; |
| 4904 | weston_view_set_position(shsurf->view, mx, my); |
Rafael Antognolli | 03b1659 | 2013-12-03 15:35:42 -0200 | [diff] [blame] | 4905 | } else { |
Jason Ekstrand | 918f2dd | 2013-12-02 21:01:53 -0600 | [diff] [blame] | 4906 | weston_view_set_position(shsurf->view, x, y); |
Kristian Høgsberg | 7a5c979 | 2011-06-18 06:12:54 -0400 | [diff] [blame] | 4907 | } |
Kristian Høgsberg | 32e24cc | 2011-11-09 12:07:35 -0500 | [diff] [blame] | 4908 | |
Alex Wu | 4539b08 | 2012-03-01 12:57:46 +0800 | [diff] [blame] | 4909 | /* XXX: would a fullscreen surface need the same handling? */ |
Kristian Høgsberg | 6a8b553 | 2012-02-16 23:43:59 -0500 | [diff] [blame] | 4910 | if (surface->output) { |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 4911 | wl_list_for_each(view, &surface->views, surface_link) |
| 4912 | weston_view_update_transform(view); |
Pekka Paalanen | 77346a6 | 2011-11-30 16:26:35 +0200 | [diff] [blame] | 4913 | |
Rafael Antognolli | 03b1659 | 2013-12-03 15:35:42 -0200 | [diff] [blame] | 4914 | if (shsurf->state.maximized) |
Juan Zhao | 96879df | 2012-02-07 08:45:41 +0800 | [diff] [blame] | 4915 | surface->output = shsurf->output; |
Pekka Paalanen | 77346a6 | 2011-11-30 16:26:35 +0200 | [diff] [blame] | 4916 | } |
Kristian Høgsberg | 0793756 | 2011-04-12 17:25:42 -0400 | [diff] [blame] | 4917 | } |
| 4918 | |
Ander Conselvan de Oliveira | 093bfa3 | 2012-03-27 17:36:41 +0300 | [diff] [blame] | 4919 | static void |
Jason Ekstrand | 918f2dd | 2013-12-02 21:01:53 -0600 | [diff] [blame] | 4920 | 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] | 4921 | { |
Ander Conselvan de Oliveira | 7fb9f95 | 2012-03-27 17:36:42 +0300 | [diff] [blame] | 4922 | struct shell_surface *shsurf = get_shell_surface(es); |
Tiago Vignatti | be14326 | 2012-04-16 17:31:41 +0300 | [diff] [blame] | 4923 | struct desktop_shell *shell = shsurf->shell; |
Giulio Camuffo | 184df50 | 2013-02-21 11:29:21 +0100 | [diff] [blame] | 4924 | |
Tiago Vignatti | 70e5c9c | 2012-05-07 15:23:07 +0300 | [diff] [blame] | 4925 | int type_changed = 0; |
Ander Conselvan de Oliveira | 093bfa3 | 2012-03-27 17:36:41 +0300 | [diff] [blame] | 4926 | |
Kristian Høgsberg | 8eb0f4f | 2013-06-17 10:33:14 -0400 | [diff] [blame] | 4927 | if (!weston_surface_is_mapped(es) && |
| 4928 | !wl_list_empty(&shsurf->popup.grab_link)) { |
Giulio Camuffo | 5085a75 | 2013-03-25 21:42:45 +0100 | [diff] [blame] | 4929 | remove_popup_grab(shsurf); |
| 4930 | } |
| 4931 | |
Jason Ekstrand | 918f2dd | 2013-12-02 21:01:53 -0600 | [diff] [blame] | 4932 | if (es->width == 0) |
Giulio Camuffo | 184df50 | 2013-02-21 11:29:21 +0100 | [diff] [blame] | 4933 | return; |
| 4934 | |
Kristian Høgsberg | c8f8dd8 | 2013-12-05 23:20:33 -0800 | [diff] [blame] | 4935 | if (shsurf->state_changed) { |
Kristian Høgsberg | 7f366e7 | 2012-04-27 17:20:01 -0400 | [diff] [blame] | 4936 | set_surface_type(shsurf); |
Kristian Høgsberg | f7e23d5 | 2012-04-27 17:51:59 -0400 | [diff] [blame] | 4937 | type_changed = 1; |
| 4938 | } |
Kristian Høgsberg | 7f366e7 | 2012-04-27 17:20:01 -0400 | [diff] [blame] | 4939 | |
Ander Conselvan de Oliveira | 093bfa3 | 2012-03-27 17:36:41 +0300 | [diff] [blame] | 4940 | if (!weston_surface_is_mapped(es)) { |
Jason Ekstrand | 918f2dd | 2013-12-02 21:01:53 -0600 | [diff] [blame] | 4941 | map(shell, shsurf, sx, sy); |
Kristian Høgsberg | f7e23d5 | 2012-04-27 17:51:59 -0400 | [diff] [blame] | 4942 | } else if (type_changed || sx != 0 || sy != 0 || |
Jason Ekstrand | 918f2dd | 2013-12-02 21:01:53 -0600 | [diff] [blame] | 4943 | shsurf->last_width != es->width || |
| 4944 | shsurf->last_height != es->height) { |
| 4945 | shsurf->last_width = es->width; |
| 4946 | shsurf->last_height = es->height; |
John Kåre Alsaker | 490d02a | 2012-09-30 02:57:21 +0200 | [diff] [blame] | 4947 | float from_x, from_y; |
| 4948 | float to_x, to_y; |
Ander Conselvan de Oliveira | 093bfa3 | 2012-03-27 17:36:41 +0300 | [diff] [blame] | 4949 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 4950 | weston_view_to_global_float(shsurf->view, 0, 0, &from_x, &from_y); |
| 4951 | 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] | 4952 | configure(shell, es, |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 4953 | shsurf->view->geometry.x + to_x - from_x, |
Jason Ekstrand | 918f2dd | 2013-12-02 21:01:53 -0600 | [diff] [blame] | 4954 | shsurf->view->geometry.y + to_y - from_y); |
Ander Conselvan de Oliveira | 093bfa3 | 2012-03-27 17:36:41 +0300 | [diff] [blame] | 4955 | } |
| 4956 | } |
| 4957 | |
Tiago Vignatti | b7dbbd6 | 2012-09-25 17:57:01 +0300 | [diff] [blame] | 4958 | static void launch_desktop_shell_process(void *data); |
Pekka Paalanen | 4d733ee | 2012-01-17 14:36:27 +0200 | [diff] [blame] | 4959 | |
Kristian Høgsberg | 97d44aa | 2011-08-26 17:21:20 -0400 | [diff] [blame] | 4960 | static void |
Kristian Høgsberg | 8334bc1 | 2012-01-03 10:29:47 -0500 | [diff] [blame] | 4961 | desktop_shell_sigchld(struct weston_process *process, int status) |
Pekka Paalanen | 6cd281a | 2011-11-03 14:11:32 +0200 | [diff] [blame] | 4962 | { |
Pekka Paalanen | 4d733ee | 2012-01-17 14:36:27 +0200 | [diff] [blame] | 4963 | uint32_t time; |
Tiago Vignatti | be14326 | 2012-04-16 17:31:41 +0300 | [diff] [blame] | 4964 | struct desktop_shell *shell = |
| 4965 | container_of(process, struct desktop_shell, child.process); |
Pekka Paalanen | 6cd281a | 2011-11-03 14:11:32 +0200 | [diff] [blame] | 4966 | |
| 4967 | shell->child.process.pid = 0; |
| 4968 | shell->child.client = NULL; /* already destroyed by wayland */ |
Pekka Paalanen | 4d733ee | 2012-01-17 14:36:27 +0200 | [diff] [blame] | 4969 | |
| 4970 | /* if desktop-shell dies more than 5 times in 30 seconds, give up */ |
| 4971 | time = weston_compositor_get_time(); |
Kristian Høgsberg | f03a616 | 2012-01-17 11:07:42 -0500 | [diff] [blame] | 4972 | if (time - shell->child.deathstamp > 30000) { |
Pekka Paalanen | 4d733ee | 2012-01-17 14:36:27 +0200 | [diff] [blame] | 4973 | shell->child.deathstamp = time; |
| 4974 | shell->child.deathcount = 0; |
| 4975 | } |
| 4976 | |
| 4977 | shell->child.deathcount++; |
| 4978 | if (shell->child.deathcount > 5) { |
Emilio Pozuelo Monfort | 46ce798 | 2013-11-20 13:22:29 +0100 | [diff] [blame] | 4979 | weston_log("%s died, giving up.\n", shell->client); |
Pekka Paalanen | 4d733ee | 2012-01-17 14:36:27 +0200 | [diff] [blame] | 4980 | return; |
| 4981 | } |
| 4982 | |
Emilio Pozuelo Monfort | 46ce798 | 2013-11-20 13:22:29 +0100 | [diff] [blame] | 4983 | weston_log("%s died, respawning...\n", shell->client); |
Pekka Paalanen | 4d733ee | 2012-01-17 14:36:27 +0200 | [diff] [blame] | 4984 | launch_desktop_shell_process(shell); |
Pekka Paalanen | 79346ab | 2013-05-22 18:03:09 +0300 | [diff] [blame] | 4985 | shell_fade_startup(shell); |
Pekka Paalanen | 6cd281a | 2011-11-03 14:11:32 +0200 | [diff] [blame] | 4986 | } |
| 4987 | |
Tiago Vignatti | b7dbbd6 | 2012-09-25 17:57:01 +0300 | [diff] [blame] | 4988 | static void |
| 4989 | launch_desktop_shell_process(void *data) |
Pekka Paalanen | 6cd281a | 2011-11-03 14:11:32 +0200 | [diff] [blame] | 4990 | { |
Tiago Vignatti | b7dbbd6 | 2012-09-25 17:57:01 +0300 | [diff] [blame] | 4991 | struct desktop_shell *shell = data; |
Pekka Paalanen | 6cd281a | 2011-11-03 14:11:32 +0200 | [diff] [blame] | 4992 | |
Kristian Høgsberg | 8334bc1 | 2012-01-03 10:29:47 -0500 | [diff] [blame] | 4993 | shell->child.client = weston_client_launch(shell->compositor, |
Pekka Paalanen | 409ef0a | 2011-12-02 15:30:21 +0200 | [diff] [blame] | 4994 | &shell->child.process, |
Emilio Pozuelo Monfort | 46ce798 | 2013-11-20 13:22:29 +0100 | [diff] [blame] | 4995 | shell->client, |
Pekka Paalanen | 409ef0a | 2011-12-02 15:30:21 +0200 | [diff] [blame] | 4996 | desktop_shell_sigchld); |
| 4997 | |
| 4998 | if (!shell->child.client) |
Emilio Pozuelo Monfort | 46ce798 | 2013-11-20 13:22:29 +0100 | [diff] [blame] | 4999 | weston_log("not able to start %s\n", shell->client); |
Pekka Paalanen | 6cd281a | 2011-11-03 14:11:32 +0200 | [diff] [blame] | 5000 | } |
| 5001 | |
| 5002 | static void |
Kristian Høgsberg | 97d44aa | 2011-08-26 17:21:20 -0400 | [diff] [blame] | 5003 | bind_shell(struct wl_client *client, void *data, uint32_t version, uint32_t id) |
| 5004 | { |
Tiago Vignatti | be14326 | 2012-04-16 17:31:41 +0300 | [diff] [blame] | 5005 | struct desktop_shell *shell = data; |
Jason Ekstrand | a85118c | 2013-06-27 20:17:02 -0500 | [diff] [blame] | 5006 | struct wl_resource *resource; |
Kristian Høgsberg | 97d44aa | 2011-08-26 17:21:20 -0400 | [diff] [blame] | 5007 | |
Jason Ekstrand | a85118c | 2013-06-27 20:17:02 -0500 | [diff] [blame] | 5008 | resource = wl_resource_create(client, &wl_shell_interface, 1, id); |
| 5009 | if (resource) |
| 5010 | wl_resource_set_implementation(resource, &shell_implementation, |
| 5011 | shell, NULL); |
Kristian Høgsberg | 97d44aa | 2011-08-26 17:21:20 -0400 | [diff] [blame] | 5012 | } |
| 5013 | |
Kristian Høgsberg | 7584062 | 2011-09-06 13:48:16 -0400 | [diff] [blame] | 5014 | static void |
Rafael Antognolli | e2a3455 | 2013-12-03 15:35:45 -0200 | [diff] [blame] | 5015 | bind_xdg_shell(struct wl_client *client, void *data, uint32_t version, uint32_t id) |
| 5016 | { |
| 5017 | struct desktop_shell *shell = data; |
| 5018 | struct wl_resource *resource; |
| 5019 | |
| 5020 | resource = wl_resource_create(client, &xdg_shell_interface, 1, id); |
| 5021 | if (resource) |
| 5022 | wl_resource_set_dispatcher(resource, |
| 5023 | xdg_shell_unversioned_dispatch, |
| 5024 | NULL, shell, NULL); |
| 5025 | } |
| 5026 | |
| 5027 | static void |
Pekka Paalanen | 9ef3e01 | 2011-11-15 13:34:48 +0200 | [diff] [blame] | 5028 | unbind_desktop_shell(struct wl_resource *resource) |
| 5029 | { |
Jason Ekstrand | 651f00e | 2013-06-14 10:07:54 -0500 | [diff] [blame] | 5030 | struct desktop_shell *shell = wl_resource_get_user_data(resource); |
Kristian Høgsberg | 1ec0c31 | 2011-11-15 16:39:55 -0500 | [diff] [blame] | 5031 | |
| 5032 | if (shell->locked) |
| 5033 | resume_desktop(shell); |
| 5034 | |
Pekka Paalanen | 9ef3e01 | 2011-11-15 13:34:48 +0200 | [diff] [blame] | 5035 | shell->child.desktop_shell = NULL; |
| 5036 | shell->prepare_event_sent = false; |
Pekka Paalanen | 9ef3e01 | 2011-11-15 13:34:48 +0200 | [diff] [blame] | 5037 | } |
| 5038 | |
| 5039 | static void |
Kristian Høgsberg | 7584062 | 2011-09-06 13:48:16 -0400 | [diff] [blame] | 5040 | bind_desktop_shell(struct wl_client *client, |
| 5041 | void *data, uint32_t version, uint32_t id) |
| 5042 | { |
Tiago Vignatti | be14326 | 2012-04-16 17:31:41 +0300 | [diff] [blame] | 5043 | struct desktop_shell *shell = data; |
Pekka Paalanen | bbe6052 | 2011-11-03 14:11:33 +0200 | [diff] [blame] | 5044 | struct wl_resource *resource; |
Kristian Høgsberg | 7584062 | 2011-09-06 13:48:16 -0400 | [diff] [blame] | 5045 | |
Jason Ekstrand | a85118c | 2013-06-27 20:17:02 -0500 | [diff] [blame] | 5046 | resource = wl_resource_create(client, &desktop_shell_interface, |
| 5047 | MIN(version, 2), id); |
Pekka Paalanen | bbe6052 | 2011-11-03 14:11:33 +0200 | [diff] [blame] | 5048 | |
Pekka Paalanen | 9ef3e01 | 2011-11-15 13:34:48 +0200 | [diff] [blame] | 5049 | if (client == shell->child.client) { |
Jason Ekstrand | a85118c | 2013-06-27 20:17:02 -0500 | [diff] [blame] | 5050 | wl_resource_set_implementation(resource, |
| 5051 | &desktop_shell_implementation, |
| 5052 | shell, unbind_desktop_shell); |
Pekka Paalanen | 9ef3e01 | 2011-11-15 13:34:48 +0200 | [diff] [blame] | 5053 | shell->child.desktop_shell = resource; |
Pekka Paalanen | 79346ab | 2013-05-22 18:03:09 +0300 | [diff] [blame] | 5054 | |
| 5055 | if (version < 2) |
| 5056 | shell_fade_startup(shell); |
| 5057 | |
Pekka Paalanen | bbe6052 | 2011-11-03 14:11:33 +0200 | [diff] [blame] | 5058 | return; |
Pekka Paalanen | 9ef3e01 | 2011-11-15 13:34:48 +0200 | [diff] [blame] | 5059 | } |
Pekka Paalanen | bbe6052 | 2011-11-03 14:11:33 +0200 | [diff] [blame] | 5060 | |
| 5061 | wl_resource_post_error(resource, WL_DISPLAY_ERROR_INVALID_OBJECT, |
| 5062 | "permission to bind desktop_shell denied"); |
Kristian Høgsberg | eae5de7 | 2012-04-11 22:42:15 -0400 | [diff] [blame] | 5063 | wl_resource_destroy(resource); |
Kristian Høgsberg | 7584062 | 2011-09-06 13:48:16 -0400 | [diff] [blame] | 5064 | } |
| 5065 | |
Pekka Paalanen | 6e16811 | 2011-11-24 11:34:05 +0200 | [diff] [blame] | 5066 | static void |
Jason Ekstrand | 918f2dd | 2013-12-02 21:01:53 -0600 | [diff] [blame] | 5067 | 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] | 5068 | { |
Giulio Camuffo | 7fe01b1 | 2013-03-28 18:02:42 +0100 | [diff] [blame] | 5069 | struct desktop_shell *shell = surface->configure_private; |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 5070 | struct weston_view *view; |
Kristian Høgsberg | 1a73a63 | 2012-06-26 22:15:53 -0400 | [diff] [blame] | 5071 | |
Jason Ekstrand | 918f2dd | 2013-12-02 21:01:53 -0600 | [diff] [blame] | 5072 | if (surface->width == 0) |
Giulio Camuffo | 184df50 | 2013-02-21 11:29:21 +0100 | [diff] [blame] | 5073 | return; |
| 5074 | |
Pekka Paalanen | 3a1d07d | 2012-12-20 14:02:13 +0200 | [diff] [blame] | 5075 | /* XXX: starting weston-screensaver beforehand does not work */ |
Kristian Høgsberg | 1a73a63 | 2012-06-26 22:15:53 -0400 | [diff] [blame] | 5076 | if (!shell->locked) |
| 5077 | return; |
| 5078 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 5079 | view = container_of(surface->views.next, struct weston_view, surface_link); |
| 5080 | center_on_output(view, surface->output); |
Kristian Høgsberg | 1a73a63 | 2012-06-26 22:15:53 -0400 | [diff] [blame] | 5081 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 5082 | if (wl_list_empty(&view->layer_link)) { |
| 5083 | wl_list_insert(shell->lock_layer.view_list.prev, |
| 5084 | &view->layer_link); |
| 5085 | weston_view_update_transform(view); |
Ander Conselvan de Oliveira | 859e885 | 2013-02-21 18:35:21 +0200 | [diff] [blame] | 5086 | wl_event_source_timer_update(shell->screensaver.timer, |
| 5087 | shell->screensaver.duration); |
Ander Conselvan de Oliveira | 19d10ef | 2013-02-21 18:35:20 +0200 | [diff] [blame] | 5088 | shell_fade(shell, FADE_IN); |
Kristian Høgsberg | 1a73a63 | 2012-06-26 22:15:53 -0400 | [diff] [blame] | 5089 | } |
| 5090 | } |
| 5091 | |
| 5092 | static void |
Pekka Paalanen | 6e16811 | 2011-11-24 11:34:05 +0200 | [diff] [blame] | 5093 | screensaver_set_surface(struct wl_client *client, |
| 5094 | struct wl_resource *resource, |
Kristian Høgsberg | 1a73a63 | 2012-06-26 22:15:53 -0400 | [diff] [blame] | 5095 | struct wl_resource *surface_resource, |
Pekka Paalanen | 6e16811 | 2011-11-24 11:34:05 +0200 | [diff] [blame] | 5096 | struct wl_resource *output_resource) |
| 5097 | { |
Jason Ekstrand | 651f00e | 2013-06-14 10:07:54 -0500 | [diff] [blame] | 5098 | struct desktop_shell *shell = wl_resource_get_user_data(resource); |
Jason Ekstrand | 0f2ef7e | 2013-06-14 10:07:53 -0500 | [diff] [blame] | 5099 | struct weston_surface *surface = |
| 5100 | wl_resource_get_user_data(surface_resource); |
Jason Ekstrand | a0d2dde | 2013-06-14 10:08:01 -0500 | [diff] [blame] | 5101 | struct weston_output *output = wl_resource_get_user_data(output_resource); |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 5102 | struct weston_view *view, *next; |
| 5103 | |
| 5104 | /* Make sure we only have one view */ |
| 5105 | wl_list_for_each_safe(view, next, &surface->views, surface_link) |
| 5106 | weston_view_destroy(view); |
| 5107 | weston_view_create(surface); |
Pekka Paalanen | 6e16811 | 2011-11-24 11:34:05 +0200 | [diff] [blame] | 5108 | |
Kristian Høgsberg | 1a73a63 | 2012-06-26 22:15:53 -0400 | [diff] [blame] | 5109 | surface->configure = screensaver_configure; |
Giulio Camuffo | 7fe01b1 | 2013-03-28 18:02:42 +0100 | [diff] [blame] | 5110 | surface->configure_private = shell; |
Pekka Paalanen | 77346a6 | 2011-11-30 16:26:35 +0200 | [diff] [blame] | 5111 | surface->output = output; |
Pekka Paalanen | 6e16811 | 2011-11-24 11:34:05 +0200 | [diff] [blame] | 5112 | } |
| 5113 | |
| 5114 | static const struct screensaver_interface screensaver_implementation = { |
| 5115 | screensaver_set_surface |
| 5116 | }; |
| 5117 | |
| 5118 | static void |
| 5119 | unbind_screensaver(struct wl_resource *resource) |
| 5120 | { |
Jason Ekstrand | 651f00e | 2013-06-14 10:07:54 -0500 | [diff] [blame] | 5121 | struct desktop_shell *shell = wl_resource_get_user_data(resource); |
Pekka Paalanen | 6e16811 | 2011-11-24 11:34:05 +0200 | [diff] [blame] | 5122 | |
Pekka Paalanen | 77346a6 | 2011-11-30 16:26:35 +0200 | [diff] [blame] | 5123 | shell->screensaver.binding = NULL; |
Pekka Paalanen | 6e16811 | 2011-11-24 11:34:05 +0200 | [diff] [blame] | 5124 | } |
| 5125 | |
| 5126 | static void |
| 5127 | bind_screensaver(struct wl_client *client, |
| 5128 | void *data, uint32_t version, uint32_t id) |
| 5129 | { |
Tiago Vignatti | be14326 | 2012-04-16 17:31:41 +0300 | [diff] [blame] | 5130 | struct desktop_shell *shell = data; |
Pekka Paalanen | 6e16811 | 2011-11-24 11:34:05 +0200 | [diff] [blame] | 5131 | struct wl_resource *resource; |
| 5132 | |
Jason Ekstrand | a85118c | 2013-06-27 20:17:02 -0500 | [diff] [blame] | 5133 | resource = wl_resource_create(client, &screensaver_interface, 1, id); |
Pekka Paalanen | 6e16811 | 2011-11-24 11:34:05 +0200 | [diff] [blame] | 5134 | |
Pekka Paalanen | 77346a6 | 2011-11-30 16:26:35 +0200 | [diff] [blame] | 5135 | if (shell->screensaver.binding == NULL) { |
Jason Ekstrand | a85118c | 2013-06-27 20:17:02 -0500 | [diff] [blame] | 5136 | wl_resource_set_implementation(resource, |
| 5137 | &screensaver_implementation, |
| 5138 | shell, unbind_screensaver); |
Pekka Paalanen | 77346a6 | 2011-11-30 16:26:35 +0200 | [diff] [blame] | 5139 | shell->screensaver.binding = resource; |
Pekka Paalanen | 6e16811 | 2011-11-24 11:34:05 +0200 | [diff] [blame] | 5140 | return; |
| 5141 | } |
| 5142 | |
| 5143 | wl_resource_post_error(resource, WL_DISPLAY_ERROR_INVALID_OBJECT, |
| 5144 | "interface object already bound"); |
Kristian Høgsberg | eae5de7 | 2012-04-11 22:42:15 -0400 | [diff] [blame] | 5145 | wl_resource_destroy(resource); |
Pekka Paalanen | 6e16811 | 2011-11-24 11:34:05 +0200 | [diff] [blame] | 5146 | } |
| 5147 | |
Kristian Høgsberg | 0704539 | 2012-02-19 18:52:44 -0500 | [diff] [blame] | 5148 | struct switcher { |
Tiago Vignatti | be14326 | 2012-04-16 17:31:41 +0300 | [diff] [blame] | 5149 | struct desktop_shell *shell; |
Kristian Høgsberg | 0704539 | 2012-02-19 18:52:44 -0500 | [diff] [blame] | 5150 | struct weston_surface *current; |
| 5151 | struct wl_listener listener; |
Kristian Høgsberg | 29139d4 | 2013-04-18 15:25:39 -0400 | [diff] [blame] | 5152 | struct weston_keyboard_grab grab; |
Kristian Høgsberg | 0704539 | 2012-02-19 18:52:44 -0500 | [diff] [blame] | 5153 | }; |
| 5154 | |
| 5155 | static void |
| 5156 | switcher_next(struct switcher *switcher) |
| 5157 | { |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 5158 | struct weston_view *view; |
Kristian Høgsberg | 0704539 | 2012-02-19 18:52:44 -0500 | [diff] [blame] | 5159 | struct weston_surface *first = NULL, *prev = NULL, *next = NULL; |
Kristian Høgsberg | 32e5686 | 2012-04-02 22:18:58 -0400 | [diff] [blame] | 5160 | struct shell_surface *shsurf; |
Kristian Høgsberg | b0d8e77 | 2012-06-18 16:34:58 -0400 | [diff] [blame] | 5161 | struct workspace *ws = get_current_workspace(switcher->shell); |
Kristian Høgsberg | 0704539 | 2012-02-19 18:52:44 -0500 | [diff] [blame] | 5162 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 5163 | wl_list_for_each(view, &ws->layer.view_list, layer_link) { |
Rafael Antognolli | ed207b4 | 2013-12-03 15:35:43 -0200 | [diff] [blame] | 5164 | shsurf = get_shell_surface(view->surface); |
Rafael Antognolli | 5031cbe | 2013-12-05 19:01:21 -0200 | [diff] [blame] | 5165 | if (shsurf && |
| 5166 | shsurf->type == SHELL_SURFACE_TOPLEVEL && |
| 5167 | shsurf->parent == NULL) { |
Kristian Høgsberg | 0704539 | 2012-02-19 18:52:44 -0500 | [diff] [blame] | 5168 | if (first == NULL) |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 5169 | first = view->surface; |
Kristian Høgsberg | 0704539 | 2012-02-19 18:52:44 -0500 | [diff] [blame] | 5170 | if (prev == switcher->current) |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 5171 | next = view->surface; |
| 5172 | prev = view->surface; |
| 5173 | view->alpha = 0.25; |
| 5174 | weston_view_geometry_dirty(view); |
| 5175 | weston_surface_damage(view->surface); |
Kristian Høgsberg | 0704539 | 2012-02-19 18:52:44 -0500 | [diff] [blame] | 5176 | } |
Alex Wu | 1659daa | 2012-04-01 20:13:09 +0800 | [diff] [blame] | 5177 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 5178 | if (is_black_surface(view->surface, NULL)) { |
| 5179 | view->alpha = 0.25; |
| 5180 | weston_view_geometry_dirty(view); |
| 5181 | weston_surface_damage(view->surface); |
Alex Wu | 1659daa | 2012-04-01 20:13:09 +0800 | [diff] [blame] | 5182 | } |
Kristian Høgsberg | 0704539 | 2012-02-19 18:52:44 -0500 | [diff] [blame] | 5183 | } |
| 5184 | |
| 5185 | if (next == NULL) |
| 5186 | next = first; |
| 5187 | |
Alex Wu | 07b2606 | 2012-03-12 16:06:01 +0800 | [diff] [blame] | 5188 | if (next == NULL) |
| 5189 | return; |
| 5190 | |
Kristian Høgsberg | 0704539 | 2012-02-19 18:52:44 -0500 | [diff] [blame] | 5191 | wl_list_remove(&switcher->listener.link); |
Jason Ekstrand | 26ed73c | 2013-06-06 22:34:41 -0500 | [diff] [blame] | 5192 | wl_signal_add(&next->destroy_signal, &switcher->listener); |
Kristian Høgsberg | 0704539 | 2012-02-19 18:52:44 -0500 | [diff] [blame] | 5193 | |
| 5194 | switcher->current = next; |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 5195 | wl_list_for_each(view, &next->views, surface_link) |
| 5196 | view->alpha = 1.0; |
Alex Wu | 1659daa | 2012-04-01 20:13:09 +0800 | [diff] [blame] | 5197 | |
Kristian Høgsberg | 32e5686 | 2012-04-02 22:18:58 -0400 | [diff] [blame] | 5198 | shsurf = get_shell_surface(switcher->current); |
Rafael Antognolli | 03b1659 | 2013-12-03 15:35:42 -0200 | [diff] [blame] | 5199 | if (shsurf && shsurf->state.fullscreen) |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 5200 | shsurf->fullscreen.black_view->alpha = 1.0; |
Kristian Høgsberg | 0704539 | 2012-02-19 18:52:44 -0500 | [diff] [blame] | 5201 | } |
| 5202 | |
| 5203 | static void |
Kristian Høgsberg | 27e3052 | 2012-04-11 23:18:23 -0400 | [diff] [blame] | 5204 | switcher_handle_surface_destroy(struct wl_listener *listener, void *data) |
Kristian Høgsberg | 0704539 | 2012-02-19 18:52:44 -0500 | [diff] [blame] | 5205 | { |
| 5206 | struct switcher *switcher = |
| 5207 | container_of(listener, struct switcher, listener); |
| 5208 | |
| 5209 | switcher_next(switcher); |
| 5210 | } |
| 5211 | |
| 5212 | static void |
Daniel Stone | 351eb61 | 2012-05-31 15:27:47 -0400 | [diff] [blame] | 5213 | switcher_destroy(struct switcher *switcher) |
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 | struct weston_view *view; |
Kristian Høgsberg | 29139d4 | 2013-04-18 15:25:39 -0400 | [diff] [blame] | 5216 | struct weston_keyboard *keyboard = switcher->grab.keyboard; |
Kristian Høgsberg | b0d8e77 | 2012-06-18 16:34:58 -0400 | [diff] [blame] | 5217 | struct workspace *ws = get_current_workspace(switcher->shell); |
Kristian Høgsberg | 0704539 | 2012-02-19 18:52:44 -0500 | [diff] [blame] | 5218 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 5219 | 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] | 5220 | if (is_focus_view(view)) |
| 5221 | continue; |
| 5222 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 5223 | view->alpha = 1.0; |
| 5224 | weston_surface_damage(view->surface); |
Kristian Høgsberg | 0704539 | 2012-02-19 18:52:44 -0500 | [diff] [blame] | 5225 | } |
| 5226 | |
Alex Wu | 07b2606 | 2012-03-12 16:06:01 +0800 | [diff] [blame] | 5227 | if (switcher->current) |
Daniel Stone | 37816df | 2012-05-16 18:45:18 +0100 | [diff] [blame] | 5228 | activate(switcher->shell, switcher->current, |
| 5229 | (struct weston_seat *) keyboard->seat); |
Kristian Høgsberg | 0704539 | 2012-02-19 18:52:44 -0500 | [diff] [blame] | 5230 | wl_list_remove(&switcher->listener.link); |
Kristian Høgsberg | 29139d4 | 2013-04-18 15:25:39 -0400 | [diff] [blame] | 5231 | weston_keyboard_end_grab(keyboard); |
| 5232 | if (keyboard->input_method_resource) |
| 5233 | keyboard->grab = &keyboard->input_method_grab; |
Kristian Høgsberg | 0704539 | 2012-02-19 18:52:44 -0500 | [diff] [blame] | 5234 | free(switcher); |
| 5235 | } |
| 5236 | |
| 5237 | static void |
Kristian Høgsberg | 29139d4 | 2013-04-18 15:25:39 -0400 | [diff] [blame] | 5238 | switcher_key(struct weston_keyboard_grab *grab, |
Daniel Stone | c9785ea | 2012-05-30 16:31:52 +0100 | [diff] [blame] | 5239 | uint32_t time, uint32_t key, uint32_t state_w) |
Kristian Høgsberg | 0704539 | 2012-02-19 18:52:44 -0500 | [diff] [blame] | 5240 | { |
| 5241 | struct switcher *switcher = container_of(grab, struct switcher, grab); |
Daniel Stone | c9785ea | 2012-05-30 16:31:52 +0100 | [diff] [blame] | 5242 | enum wl_keyboard_key_state state = state_w; |
Daniel Stone | 351eb61 | 2012-05-31 15:27:47 -0400 | [diff] [blame] | 5243 | |
Daniel Stone | c9785ea | 2012-05-30 16:31:52 +0100 | [diff] [blame] | 5244 | if (key == KEY_TAB && state == WL_KEYBOARD_KEY_STATE_PRESSED) |
Daniel Stone | 351eb61 | 2012-05-31 15:27:47 -0400 | [diff] [blame] | 5245 | switcher_next(switcher); |
| 5246 | } |
| 5247 | |
| 5248 | static void |
Kristian Høgsberg | 29139d4 | 2013-04-18 15:25:39 -0400 | [diff] [blame] | 5249 | switcher_modifier(struct weston_keyboard_grab *grab, uint32_t serial, |
Daniel Stone | 351eb61 | 2012-05-31 15:27:47 -0400 | [diff] [blame] | 5250 | uint32_t mods_depressed, uint32_t mods_latched, |
| 5251 | uint32_t mods_locked, uint32_t group) |
| 5252 | { |
| 5253 | struct switcher *switcher = container_of(grab, struct switcher, grab); |
Daniel Stone | 37816df | 2012-05-16 18:45:18 +0100 | [diff] [blame] | 5254 | struct weston_seat *seat = (struct weston_seat *) grab->keyboard->seat; |
Kristian Høgsberg | 0704539 | 2012-02-19 18:52:44 -0500 | [diff] [blame] | 5255 | |
Daniel Stone | 351eb61 | 2012-05-31 15:27:47 -0400 | [diff] [blame] | 5256 | if ((seat->modifier_state & switcher->shell->binding_modifier) == 0) |
| 5257 | switcher_destroy(switcher); |
Kristian Høgsberg | b71302e | 2012-05-10 12:28:35 -0400 | [diff] [blame] | 5258 | } |
Kristian Høgsberg | 0704539 | 2012-02-19 18:52:44 -0500 | [diff] [blame] | 5259 | |
Jonas Ådahl | 1ea343e | 2013-10-25 23:18:05 +0200 | [diff] [blame] | 5260 | static void |
| 5261 | switcher_cancel(struct weston_keyboard_grab *grab) |
| 5262 | { |
| 5263 | struct switcher *switcher = container_of(grab, struct switcher, grab); |
| 5264 | |
| 5265 | switcher_destroy(switcher); |
| 5266 | } |
| 5267 | |
Kristian Høgsberg | 29139d4 | 2013-04-18 15:25:39 -0400 | [diff] [blame] | 5268 | static const struct weston_keyboard_grab_interface switcher_grab = { |
Daniel Stone | 351eb61 | 2012-05-31 15:27:47 -0400 | [diff] [blame] | 5269 | switcher_key, |
| 5270 | switcher_modifier, |
Jonas Ådahl | 1ea343e | 2013-10-25 23:18:05 +0200 | [diff] [blame] | 5271 | switcher_cancel, |
Kristian Høgsberg | 0704539 | 2012-02-19 18:52:44 -0500 | [diff] [blame] | 5272 | }; |
| 5273 | |
| 5274 | static void |
Kristian Høgsberg | e314875 | 2013-05-06 23:19:49 -0400 | [diff] [blame] | 5275 | switcher_binding(struct weston_seat *seat, uint32_t time, uint32_t key, |
Daniel Stone | 325fc2d | 2012-05-30 16:31:58 +0100 | [diff] [blame] | 5276 | void *data) |
Kristian Høgsberg | 0704539 | 2012-02-19 18:52:44 -0500 | [diff] [blame] | 5277 | { |
Tiago Vignatti | be14326 | 2012-04-16 17:31:41 +0300 | [diff] [blame] | 5278 | struct desktop_shell *shell = data; |
Kristian Høgsberg | 0704539 | 2012-02-19 18:52:44 -0500 | [diff] [blame] | 5279 | struct switcher *switcher; |
| 5280 | |
| 5281 | switcher = malloc(sizeof *switcher); |
Kristian Høgsberg | 02e79dc | 2012-04-12 09:55:26 -0400 | [diff] [blame] | 5282 | switcher->shell = shell; |
Kristian Høgsberg | 0704539 | 2012-02-19 18:52:44 -0500 | [diff] [blame] | 5283 | switcher->current = NULL; |
Kristian Høgsberg | 27e3052 | 2012-04-11 23:18:23 -0400 | [diff] [blame] | 5284 | switcher->listener.notify = switcher_handle_surface_destroy; |
Kristian Høgsberg | 0704539 | 2012-02-19 18:52:44 -0500 | [diff] [blame] | 5285 | wl_list_init(&switcher->listener.link); |
| 5286 | |
Alexander Larsson | f82b6ca | 2013-05-28 16:23:39 +0200 | [diff] [blame] | 5287 | restore_all_output_modes(shell->compositor); |
Kristian Høgsberg | b0d8e77 | 2012-06-18 16:34:58 -0400 | [diff] [blame] | 5288 | lower_fullscreen_layer(switcher->shell); |
Kristian Høgsberg | 0704539 | 2012-02-19 18:52:44 -0500 | [diff] [blame] | 5289 | switcher->grab.interface = &switcher_grab; |
Kristian Høgsberg | 29139d4 | 2013-04-18 15:25:39 -0400 | [diff] [blame] | 5290 | weston_keyboard_start_grab(seat->keyboard, &switcher->grab); |
| 5291 | weston_keyboard_set_focus(seat->keyboard, NULL); |
Kristian Høgsberg | 0704539 | 2012-02-19 18:52:44 -0500 | [diff] [blame] | 5292 | switcher_next(switcher); |
| 5293 | } |
| 5294 | |
Pekka Paalanen | 3c64723 | 2011-12-22 13:43:43 +0200 | [diff] [blame] | 5295 | static void |
Kristian Høgsberg | e314875 | 2013-05-06 23:19:49 -0400 | [diff] [blame] | 5296 | backlight_binding(struct weston_seat *seat, uint32_t time, uint32_t key, |
Daniel Stone | 325fc2d | 2012-05-30 16:31:58 +0100 | [diff] [blame] | 5297 | void *data) |
Tiago Vignatti | 8e53c7f | 2012-02-29 19:53:50 +0200 | [diff] [blame] | 5298 | { |
| 5299 | struct weston_compositor *compositor = data; |
| 5300 | struct weston_output *output; |
Tiago Vignatti | 5ab91ad | 2012-03-12 19:40:09 -0300 | [diff] [blame] | 5301 | long backlight_new = 0; |
Tiago Vignatti | 8e53c7f | 2012-02-29 19:53:50 +0200 | [diff] [blame] | 5302 | |
| 5303 | /* TODO: we're limiting to simple use cases, where we assume just |
| 5304 | * control on the primary display. We'd have to extend later if we |
| 5305 | * ever get support for setting backlights on random desktop LCD |
| 5306 | * panels though */ |
| 5307 | output = get_default_output(compositor); |
| 5308 | if (!output) |
| 5309 | return; |
| 5310 | |
| 5311 | if (!output->set_backlight) |
| 5312 | return; |
| 5313 | |
Tiago Vignatti | 5ab91ad | 2012-03-12 19:40:09 -0300 | [diff] [blame] | 5314 | if (key == KEY_F9 || key == KEY_BRIGHTNESSDOWN) |
| 5315 | backlight_new = output->backlight_current - 25; |
| 5316 | else if (key == KEY_F10 || key == KEY_BRIGHTNESSUP) |
| 5317 | backlight_new = output->backlight_current + 25; |
Tiago Vignatti | 8e53c7f | 2012-02-29 19:53:50 +0200 | [diff] [blame] | 5318 | |
Tiago Vignatti | 5ab91ad | 2012-03-12 19:40:09 -0300 | [diff] [blame] | 5319 | if (backlight_new < 5) |
| 5320 | backlight_new = 5; |
| 5321 | if (backlight_new > 255) |
| 5322 | backlight_new = 255; |
| 5323 | |
| 5324 | output->backlight_current = backlight_new; |
Tiago Vignatti | 8e53c7f | 2012-02-29 19:53:50 +0200 | [diff] [blame] | 5325 | output->set_backlight(output, output->backlight_current); |
| 5326 | } |
| 5327 | |
Ander Conselvan de Oliveira | c509d2b | 2012-11-08 17:20:45 +0200 | [diff] [blame] | 5328 | struct debug_binding_grab { |
Kristian Høgsberg | 29139d4 | 2013-04-18 15:25:39 -0400 | [diff] [blame] | 5329 | struct weston_keyboard_grab grab; |
Ander Conselvan de Oliveira | c509d2b | 2012-11-08 17:20:45 +0200 | [diff] [blame] | 5330 | struct weston_seat *seat; |
| 5331 | uint32_t key[2]; |
| 5332 | int key_released[2]; |
| 5333 | }; |
| 5334 | |
| 5335 | static void |
Kristian Høgsberg | 29139d4 | 2013-04-18 15:25:39 -0400 | [diff] [blame] | 5336 | 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] | 5337 | uint32_t key, uint32_t state) |
| 5338 | { |
| 5339 | struct debug_binding_grab *db = (struct debug_binding_grab *) grab; |
Rob Bradford | 880ebc7 | 2013-07-22 17:31:38 +0100 | [diff] [blame] | 5340 | struct weston_compositor *ec = db->seat->compositor; |
| 5341 | struct wl_display *display = ec->wl_display; |
Ander Conselvan de Oliveira | c509d2b | 2012-11-08 17:20:45 +0200 | [diff] [blame] | 5342 | struct wl_resource *resource; |
Ander Conselvan de Oliveira | c509d2b | 2012-11-08 17:20:45 +0200 | [diff] [blame] | 5343 | uint32_t serial; |
| 5344 | int send = 0, terminate = 0; |
| 5345 | int check_binding = 1; |
| 5346 | int i; |
Neil Roberts | 96d790e | 2013-09-19 17:32:00 +0100 | [diff] [blame] | 5347 | struct wl_list *resource_list; |
Ander Conselvan de Oliveira | c509d2b | 2012-11-08 17:20:45 +0200 | [diff] [blame] | 5348 | |
| 5349 | if (state == WL_KEYBOARD_KEY_STATE_RELEASED) { |
| 5350 | /* Do not run bindings on key releases */ |
| 5351 | check_binding = 0; |
| 5352 | |
| 5353 | for (i = 0; i < 2; i++) |
| 5354 | if (key == db->key[i]) |
| 5355 | db->key_released[i] = 1; |
| 5356 | |
| 5357 | if (db->key_released[0] && db->key_released[1]) { |
| 5358 | /* All key releases been swalled so end the grab */ |
| 5359 | terminate = 1; |
| 5360 | } else if (key != db->key[0] && key != db->key[1]) { |
| 5361 | /* Should not swallow release of other keys */ |
| 5362 | send = 1; |
| 5363 | } |
| 5364 | } else if (key == db->key[0] && !db->key_released[0]) { |
| 5365 | /* Do not check bindings for the first press of the binding |
| 5366 | * key. This allows it to be used as a debug shortcut. |
| 5367 | * We still need to swallow this event. */ |
| 5368 | check_binding = 0; |
| 5369 | } else if (db->key[1]) { |
| 5370 | /* If we already ran a binding don't process another one since |
| 5371 | * we can't keep track of all the binding keys that were |
| 5372 | * pressed in order to swallow the release events. */ |
| 5373 | send = 1; |
| 5374 | check_binding = 0; |
| 5375 | } |
| 5376 | |
| 5377 | if (check_binding) { |
Ander Conselvan de Oliveira | c509d2b | 2012-11-08 17:20:45 +0200 | [diff] [blame] | 5378 | if (weston_compositor_run_debug_binding(ec, db->seat, time, |
| 5379 | key, state)) { |
| 5380 | /* We ran a binding so swallow the press and keep the |
| 5381 | * grab to swallow the released too. */ |
| 5382 | send = 0; |
| 5383 | terminate = 0; |
| 5384 | db->key[1] = key; |
| 5385 | } else { |
| 5386 | /* Terminate the grab since the key pressed is not a |
| 5387 | * debug binding key. */ |
| 5388 | send = 1; |
| 5389 | terminate = 1; |
| 5390 | } |
| 5391 | } |
| 5392 | |
| 5393 | if (send) { |
Neil Roberts | 96d790e | 2013-09-19 17:32:00 +0100 | [diff] [blame] | 5394 | serial = wl_display_next_serial(display); |
| 5395 | resource_list = &grab->keyboard->focus_resource_list; |
| 5396 | wl_resource_for_each(resource, resource_list) { |
Ander Conselvan de Oliveira | c509d2b | 2012-11-08 17:20:45 +0200 | [diff] [blame] | 5397 | wl_keyboard_send_key(resource, serial, time, key, state); |
| 5398 | } |
| 5399 | } |
| 5400 | |
| 5401 | if (terminate) { |
Kristian Høgsberg | 29139d4 | 2013-04-18 15:25:39 -0400 | [diff] [blame] | 5402 | weston_keyboard_end_grab(grab->keyboard); |
| 5403 | if (grab->keyboard->input_method_resource) |
| 5404 | grab->keyboard->grab = &grab->keyboard->input_method_grab; |
Ander Conselvan de Oliveira | c509d2b | 2012-11-08 17:20:45 +0200 | [diff] [blame] | 5405 | free(db); |
| 5406 | } |
| 5407 | } |
| 5408 | |
| 5409 | static void |
Kristian Høgsberg | 29139d4 | 2013-04-18 15:25:39 -0400 | [diff] [blame] | 5410 | 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] | 5411 | uint32_t mods_depressed, uint32_t mods_latched, |
| 5412 | uint32_t mods_locked, uint32_t group) |
| 5413 | { |
| 5414 | struct wl_resource *resource; |
Neil Roberts | 96d790e | 2013-09-19 17:32:00 +0100 | [diff] [blame] | 5415 | struct wl_list *resource_list; |
Ander Conselvan de Oliveira | c509d2b | 2012-11-08 17:20:45 +0200 | [diff] [blame] | 5416 | |
Neil Roberts | 96d790e | 2013-09-19 17:32:00 +0100 | [diff] [blame] | 5417 | resource_list = &grab->keyboard->focus_resource_list; |
Ander Conselvan de Oliveira | c509d2b | 2012-11-08 17:20:45 +0200 | [diff] [blame] | 5418 | |
Neil Roberts | 96d790e | 2013-09-19 17:32:00 +0100 | [diff] [blame] | 5419 | wl_resource_for_each(resource, resource_list) { |
| 5420 | wl_keyboard_send_modifiers(resource, serial, mods_depressed, |
| 5421 | mods_latched, mods_locked, group); |
| 5422 | } |
Ander Conselvan de Oliveira | c509d2b | 2012-11-08 17:20:45 +0200 | [diff] [blame] | 5423 | } |
| 5424 | |
Jonas Ådahl | 1ea343e | 2013-10-25 23:18:05 +0200 | [diff] [blame] | 5425 | static void |
| 5426 | debug_binding_cancel(struct weston_keyboard_grab *grab) |
| 5427 | { |
| 5428 | struct debug_binding_grab *db = (struct debug_binding_grab *) grab; |
| 5429 | |
| 5430 | weston_keyboard_end_grab(grab->keyboard); |
| 5431 | free(db); |
| 5432 | } |
| 5433 | |
Kristian Høgsberg | 29139d4 | 2013-04-18 15:25:39 -0400 | [diff] [blame] | 5434 | struct weston_keyboard_grab_interface debug_binding_keyboard_grab = { |
Ander Conselvan de Oliveira | c509d2b | 2012-11-08 17:20:45 +0200 | [diff] [blame] | 5435 | debug_binding_key, |
Jonas Ådahl | 1ea343e | 2013-10-25 23:18:05 +0200 | [diff] [blame] | 5436 | debug_binding_modifiers, |
| 5437 | debug_binding_cancel, |
Ander Conselvan de Oliveira | c509d2b | 2012-11-08 17:20:45 +0200 | [diff] [blame] | 5438 | }; |
| 5439 | |
| 5440 | static void |
Kristian Høgsberg | e314875 | 2013-05-06 23:19:49 -0400 | [diff] [blame] | 5441 | 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] | 5442 | { |
| 5443 | struct debug_binding_grab *grab; |
| 5444 | |
| 5445 | grab = calloc(1, sizeof *grab); |
| 5446 | if (!grab) |
| 5447 | return; |
| 5448 | |
| 5449 | grab->seat = (struct weston_seat *) seat; |
| 5450 | grab->key[0] = key; |
| 5451 | grab->grab.interface = &debug_binding_keyboard_grab; |
Kristian Høgsberg | 29139d4 | 2013-04-18 15:25:39 -0400 | [diff] [blame] | 5452 | weston_keyboard_start_grab(seat->keyboard, &grab->grab); |
Ander Conselvan de Oliveira | c509d2b | 2012-11-08 17:20:45 +0200 | [diff] [blame] | 5453 | } |
| 5454 | |
Kristian Høgsberg | b41c081 | 2012-03-04 14:53:40 -0500 | [diff] [blame] | 5455 | static void |
Kristian Høgsberg | e314875 | 2013-05-06 23:19:49 -0400 | [diff] [blame] | 5456 | 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] | 5457 | void *data) |
Kristian Høgsberg | 92a57db | 2012-05-26 13:41:06 -0400 | [diff] [blame] | 5458 | { |
Kristian Høgsberg | fe7aa90 | 2013-05-08 09:54:37 -0400 | [diff] [blame] | 5459 | struct weston_surface *focus_surface; |
Kristian Høgsberg | 92a57db | 2012-05-26 13:41:06 -0400 | [diff] [blame] | 5460 | struct wl_client *client; |
Tiago Vignatti | 1d01b01 | 2012-09-27 17:48:36 +0300 | [diff] [blame] | 5461 | struct desktop_shell *shell = data; |
| 5462 | struct weston_compositor *compositor = shell->compositor; |
Kristian Høgsberg | 92a57db | 2012-05-26 13:41:06 -0400 | [diff] [blame] | 5463 | pid_t pid; |
Kristian Høgsberg | 92a57db | 2012-05-26 13:41:06 -0400 | [diff] [blame] | 5464 | |
Philipp Brüschweiler | 6cef009 | 2012-08-13 21:27:27 +0200 | [diff] [blame] | 5465 | focus_surface = seat->keyboard->focus; |
| 5466 | if (!focus_surface) |
| 5467 | return; |
| 5468 | |
Tiago Vignatti | 1d01b01 | 2012-09-27 17:48:36 +0300 | [diff] [blame] | 5469 | wl_signal_emit(&compositor->kill_signal, focus_surface); |
| 5470 | |
Jason Ekstrand | 26ed73c | 2013-06-06 22:34:41 -0500 | [diff] [blame] | 5471 | client = wl_resource_get_client(focus_surface->resource); |
Tiago Vignatti | 920f197 | 2012-09-27 17:48:35 +0300 | [diff] [blame] | 5472 | wl_client_get_credentials(client, &pid, NULL, NULL); |
| 5473 | |
| 5474 | /* Skip clients that we launched ourselves (the credentials of |
| 5475 | * the socketpair is ours) */ |
| 5476 | if (pid == getpid()) |
| 5477 | return; |
Kristian Høgsberg | 92a57db | 2012-05-26 13:41:06 -0400 | [diff] [blame] | 5478 | |
Daniel Stone | 325fc2d | 2012-05-30 16:31:58 +0100 | [diff] [blame] | 5479 | kill(pid, SIGKILL); |
Kristian Høgsberg | 92a57db | 2012-05-26 13:41:06 -0400 | [diff] [blame] | 5480 | } |
| 5481 | |
| 5482 | static void |
Kristian Høgsberg | e314875 | 2013-05-06 23:19:49 -0400 | [diff] [blame] | 5483 | workspace_up_binding(struct weston_seat *seat, uint32_t time, |
Jonas Ådahl | e3cddce | 2012-06-13 00:01:22 +0200 | [diff] [blame] | 5484 | uint32_t key, void *data) |
| 5485 | { |
| 5486 | struct desktop_shell *shell = data; |
| 5487 | unsigned int new_index = shell->workspaces.current; |
| 5488 | |
Kristian Høgsberg | ce345b0 | 2012-06-25 21:35:29 -0400 | [diff] [blame] | 5489 | if (shell->locked) |
Kristian Høgsberg | 4476aaf | 2012-06-25 14:03:13 -0400 | [diff] [blame] | 5490 | return; |
Jonas Ådahl | e3cddce | 2012-06-13 00:01:22 +0200 | [diff] [blame] | 5491 | if (new_index != 0) |
| 5492 | new_index--; |
| 5493 | |
| 5494 | change_workspace(shell, new_index); |
| 5495 | } |
| 5496 | |
| 5497 | static void |
Kristian Høgsberg | e314875 | 2013-05-06 23:19:49 -0400 | [diff] [blame] | 5498 | workspace_down_binding(struct weston_seat *seat, uint32_t time, |
Jonas Ådahl | e3cddce | 2012-06-13 00:01:22 +0200 | [diff] [blame] | 5499 | uint32_t key, void *data) |
| 5500 | { |
| 5501 | struct desktop_shell *shell = data; |
| 5502 | unsigned int new_index = shell->workspaces.current; |
| 5503 | |
Kristian Høgsberg | ce345b0 | 2012-06-25 21:35:29 -0400 | [diff] [blame] | 5504 | if (shell->locked) |
Kristian Høgsberg | 4476aaf | 2012-06-25 14:03:13 -0400 | [diff] [blame] | 5505 | return; |
Jonas Ådahl | e3cddce | 2012-06-13 00:01:22 +0200 | [diff] [blame] | 5506 | if (new_index < shell->workspaces.num - 1) |
| 5507 | new_index++; |
| 5508 | |
| 5509 | change_workspace(shell, new_index); |
| 5510 | } |
| 5511 | |
| 5512 | static void |
Kristian Høgsberg | e314875 | 2013-05-06 23:19:49 -0400 | [diff] [blame] | 5513 | workspace_f_binding(struct weston_seat *seat, uint32_t time, |
Jonas Ådahl | e3cddce | 2012-06-13 00:01:22 +0200 | [diff] [blame] | 5514 | uint32_t key, void *data) |
| 5515 | { |
| 5516 | struct desktop_shell *shell = data; |
| 5517 | unsigned int new_index; |
| 5518 | |
Kristian Høgsberg | ce345b0 | 2012-06-25 21:35:29 -0400 | [diff] [blame] | 5519 | if (shell->locked) |
Kristian Høgsberg | 4476aaf | 2012-06-25 14:03:13 -0400 | [diff] [blame] | 5520 | return; |
Jonas Ådahl | e3cddce | 2012-06-13 00:01:22 +0200 | [diff] [blame] | 5521 | new_index = key - KEY_F1; |
| 5522 | if (new_index >= shell->workspaces.num) |
| 5523 | new_index = shell->workspaces.num - 1; |
| 5524 | |
| 5525 | change_workspace(shell, new_index); |
| 5526 | } |
| 5527 | |
Jonas Ådahl | 8de6a1d | 2012-08-29 22:13:00 +0200 | [diff] [blame] | 5528 | static void |
Kristian Høgsberg | e314875 | 2013-05-06 23:19:49 -0400 | [diff] [blame] | 5529 | workspace_move_surface_up_binding(struct weston_seat *seat, uint32_t time, |
Jonas Ådahl | 8de6a1d | 2012-08-29 22:13:00 +0200 | [diff] [blame] | 5530 | uint32_t key, void *data) |
| 5531 | { |
| 5532 | struct desktop_shell *shell = data; |
| 5533 | unsigned int new_index = shell->workspaces.current; |
| 5534 | |
| 5535 | if (shell->locked) |
| 5536 | return; |
| 5537 | |
| 5538 | if (new_index != 0) |
| 5539 | new_index--; |
| 5540 | |
| 5541 | take_surface_to_workspace_by_seat(shell, seat, new_index); |
| 5542 | } |
| 5543 | |
| 5544 | static void |
Kristian Høgsberg | e314875 | 2013-05-06 23:19:49 -0400 | [diff] [blame] | 5545 | workspace_move_surface_down_binding(struct weston_seat *seat, uint32_t time, |
Jonas Ådahl | 8de6a1d | 2012-08-29 22:13:00 +0200 | [diff] [blame] | 5546 | uint32_t key, void *data) |
| 5547 | { |
| 5548 | struct desktop_shell *shell = data; |
| 5549 | unsigned int new_index = shell->workspaces.current; |
| 5550 | |
| 5551 | if (shell->locked) |
| 5552 | return; |
| 5553 | |
| 5554 | if (new_index < shell->workspaces.num - 1) |
| 5555 | new_index++; |
| 5556 | |
| 5557 | take_surface_to_workspace_by_seat(shell, seat, new_index); |
| 5558 | } |
Jonas Ådahl | e3cddce | 2012-06-13 00:01:22 +0200 | [diff] [blame] | 5559 | |
| 5560 | static void |
Xiong Zhang | 6b48142 | 2013-10-23 13:58:32 +0800 | [diff] [blame] | 5561 | handle_output_destroy(struct wl_listener *listener, void *data) |
| 5562 | { |
| 5563 | struct shell_output *output_listener = |
| 5564 | container_of(listener, struct shell_output, destroy_listener); |
| 5565 | |
| 5566 | wl_list_remove(&output_listener->destroy_listener.link); |
| 5567 | wl_list_remove(&output_listener->link); |
| 5568 | free(output_listener); |
| 5569 | } |
| 5570 | |
| 5571 | static void |
| 5572 | create_shell_output(struct desktop_shell *shell, |
| 5573 | struct weston_output *output) |
| 5574 | { |
| 5575 | struct shell_output *shell_output; |
| 5576 | |
| 5577 | shell_output = zalloc(sizeof *shell_output); |
| 5578 | if (shell_output == NULL) |
| 5579 | return; |
| 5580 | |
| 5581 | shell_output->output = output; |
| 5582 | shell_output->shell = shell; |
| 5583 | shell_output->destroy_listener.notify = handle_output_destroy; |
| 5584 | wl_signal_add(&output->destroy_signal, |
| 5585 | &shell_output->destroy_listener); |
Kristian Høgsberg | a3a0e18 | 2013-10-23 23:36:04 -0700 | [diff] [blame] | 5586 | wl_list_insert(shell->output_list.prev, &shell_output->link); |
Xiong Zhang | 6b48142 | 2013-10-23 13:58:32 +0800 | [diff] [blame] | 5587 | } |
| 5588 | |
| 5589 | static void |
| 5590 | handle_output_create(struct wl_listener *listener, void *data) |
| 5591 | { |
| 5592 | struct desktop_shell *shell = |
| 5593 | container_of(listener, struct desktop_shell, output_create_listener); |
| 5594 | struct weston_output *output = (struct weston_output *)data; |
| 5595 | |
| 5596 | create_shell_output(shell, output); |
| 5597 | } |
| 5598 | |
| 5599 | static void |
| 5600 | setup_output_destroy_handler(struct weston_compositor *ec, |
| 5601 | struct desktop_shell *shell) |
| 5602 | { |
| 5603 | struct weston_output *output; |
| 5604 | |
| 5605 | wl_list_init(&shell->output_list); |
| 5606 | wl_list_for_each(output, &ec->output_list, link) |
| 5607 | create_shell_output(shell, output); |
| 5608 | |
| 5609 | shell->output_create_listener.notify = handle_output_create; |
| 5610 | wl_signal_add(&ec->output_created_signal, |
| 5611 | &shell->output_create_listener); |
| 5612 | } |
| 5613 | |
| 5614 | static void |
Kristian Høgsberg | 02e79dc | 2012-04-12 09:55:26 -0400 | [diff] [blame] | 5615 | shell_destroy(struct wl_listener *listener, void *data) |
Pekka Paalanen | 3c64723 | 2011-12-22 13:43:43 +0200 | [diff] [blame] | 5616 | { |
Tiago Vignatti | be14326 | 2012-04-16 17:31:41 +0300 | [diff] [blame] | 5617 | struct desktop_shell *shell = |
| 5618 | container_of(listener, struct desktop_shell, destroy_listener); |
Jonas Ådahl | e3cddce | 2012-06-13 00:01:22 +0200 | [diff] [blame] | 5619 | struct workspace **ws; |
Xiong Zhang | 6b48142 | 2013-10-23 13:58:32 +0800 | [diff] [blame] | 5620 | struct shell_output *shell_output, *tmp; |
Pekka Paalanen | 3c64723 | 2011-12-22 13:43:43 +0200 | [diff] [blame] | 5621 | |
Pekka Paalanen | 9cf5cc8 | 2012-01-02 16:00:24 +0200 | [diff] [blame] | 5622 | if (shell->child.client) |
| 5623 | wl_client_destroy(shell->child.client); |
| 5624 | |
Ander Conselvan de Oliveira | a457563 | 2013-02-21 18:35:23 +0200 | [diff] [blame] | 5625 | wl_list_remove(&shell->idle_listener.link); |
| 5626 | wl_list_remove(&shell->wake_listener.link); |
Kristian Høgsberg | 677a5f5 | 2013-12-04 11:00:19 -0800 | [diff] [blame] | 5627 | |
| 5628 | input_panel_destroy(shell); |
Kristian Høgsberg | 88c1607 | 2012-05-16 08:04:19 -0400 | [diff] [blame] | 5629 | |
Xiong Zhang | 6b48142 | 2013-10-23 13:58:32 +0800 | [diff] [blame] | 5630 | wl_list_for_each_safe(shell_output, tmp, &shell->output_list, link) { |
| 5631 | wl_list_remove(&shell_output->destroy_listener.link); |
| 5632 | wl_list_remove(&shell_output->link); |
| 5633 | free(shell_output); |
| 5634 | } |
| 5635 | |
| 5636 | wl_list_remove(&shell->output_create_listener.link); |
| 5637 | |
Jonas Ådahl | e3cddce | 2012-06-13 00:01:22 +0200 | [diff] [blame] | 5638 | wl_array_for_each(ws, &shell->workspaces.array) |
| 5639 | workspace_destroy(*ws); |
| 5640 | wl_array_release(&shell->workspaces.array); |
| 5641 | |
Pekka Paalanen | 3c64723 | 2011-12-22 13:43:43 +0200 | [diff] [blame] | 5642 | free(shell->screensaver.path); |
Emilio Pozuelo Monfort | 46ce798 | 2013-11-20 13:22:29 +0100 | [diff] [blame] | 5643 | free(shell->client); |
Pekka Paalanen | 3c64723 | 2011-12-22 13:43:43 +0200 | [diff] [blame] | 5644 | free(shell); |
| 5645 | } |
| 5646 | |
Tiago Vignatti | 0b52d48 | 2012-04-20 18:54:25 +0300 | [diff] [blame] | 5647 | static void |
| 5648 | shell_add_bindings(struct weston_compositor *ec, struct desktop_shell *shell) |
| 5649 | { |
| 5650 | uint32_t mod; |
Jonas Ådahl | e3cddce | 2012-06-13 00:01:22 +0200 | [diff] [blame] | 5651 | int i, num_workspace_bindings; |
Tiago Vignatti | 0b52d48 | 2012-04-20 18:54:25 +0300 | [diff] [blame] | 5652 | |
| 5653 | /* fixed bindings */ |
Daniel Stone | 325fc2d | 2012-05-30 16:31:58 +0100 | [diff] [blame] | 5654 | weston_compositor_add_key_binding(ec, KEY_BACKSPACE, |
| 5655 | MODIFIER_CTRL | MODIFIER_ALT, |
| 5656 | terminate_binding, ec); |
Emilio Pozuelo Monfort | 03251b6 | 2013-11-19 11:37:16 +0100 | [diff] [blame] | 5657 | weston_compositor_add_key_binding(ec, KEY_TAB, |
| 5658 | MODIFIER_ALT, |
| 5659 | alt_tab_binding, shell); |
Daniel Stone | 325fc2d | 2012-05-30 16:31:58 +0100 | [diff] [blame] | 5660 | weston_compositor_add_button_binding(ec, BTN_LEFT, 0, |
| 5661 | click_to_activate_binding, |
| 5662 | shell); |
Neil Roberts | a28c693 | 2013-10-03 16:43:04 +0100 | [diff] [blame] | 5663 | weston_compositor_add_touch_binding(ec, 0, |
| 5664 | touch_to_activate_binding, |
| 5665 | shell); |
Daniel Stone | 325fc2d | 2012-05-30 16:31:58 +0100 | [diff] [blame] | 5666 | weston_compositor_add_axis_binding(ec, WL_POINTER_AXIS_VERTICAL_SCROLL, |
| 5667 | MODIFIER_SUPER | MODIFIER_ALT, |
| 5668 | surface_opacity_binding, NULL); |
| 5669 | weston_compositor_add_axis_binding(ec, WL_POINTER_AXIS_VERTICAL_SCROLL, |
| 5670 | MODIFIER_SUPER, zoom_axis_binding, |
| 5671 | NULL); |
Tiago Vignatti | 0b52d48 | 2012-04-20 18:54:25 +0300 | [diff] [blame] | 5672 | |
| 5673 | /* configurable bindings */ |
| 5674 | mod = shell->binding_modifier; |
Daniel Stone | 325fc2d | 2012-05-30 16:31:58 +0100 | [diff] [blame] | 5675 | weston_compositor_add_key_binding(ec, KEY_PAGEUP, mod, |
| 5676 | zoom_key_binding, NULL); |
| 5677 | weston_compositor_add_key_binding(ec, KEY_PAGEDOWN, mod, |
| 5678 | zoom_key_binding, NULL); |
Rafael Antognolli | ea997ac | 2013-12-03 15:35:48 -0200 | [diff] [blame] | 5679 | weston_compositor_add_key_binding(ec, KEY_M, mod, maximize_binding, |
| 5680 | NULL); |
| 5681 | weston_compositor_add_key_binding(ec, KEY_F, mod, fullscreen_binding, |
| 5682 | NULL); |
Daniel Stone | 325fc2d | 2012-05-30 16:31:58 +0100 | [diff] [blame] | 5683 | weston_compositor_add_button_binding(ec, BTN_LEFT, mod, move_binding, |
| 5684 | shell); |
Neil Roberts | aba0f25 | 2013-10-03 16:43:05 +0100 | [diff] [blame] | 5685 | weston_compositor_add_touch_binding(ec, mod, touch_move_binding, shell); |
Daniel Stone | 325fc2d | 2012-05-30 16:31:58 +0100 | [diff] [blame] | 5686 | weston_compositor_add_button_binding(ec, BTN_MIDDLE, mod, |
| 5687 | resize_binding, shell); |
Pekka Paalanen | 7bb6510 | 2013-05-22 18:03:04 +0300 | [diff] [blame] | 5688 | |
| 5689 | if (ec->capabilities & WESTON_CAP_ROTATION_ANY) |
| 5690 | weston_compositor_add_button_binding(ec, BTN_RIGHT, mod, |
| 5691 | rotate_binding, NULL); |
| 5692 | |
Daniel Stone | 325fc2d | 2012-05-30 16:31:58 +0100 | [diff] [blame] | 5693 | weston_compositor_add_key_binding(ec, KEY_TAB, mod, switcher_binding, |
| 5694 | shell); |
| 5695 | weston_compositor_add_key_binding(ec, KEY_F9, mod, backlight_binding, |
| 5696 | ec); |
| 5697 | weston_compositor_add_key_binding(ec, KEY_BRIGHTNESSDOWN, 0, |
| 5698 | backlight_binding, ec); |
| 5699 | weston_compositor_add_key_binding(ec, KEY_F10, mod, backlight_binding, |
| 5700 | ec); |
| 5701 | weston_compositor_add_key_binding(ec, KEY_BRIGHTNESSUP, 0, |
| 5702 | backlight_binding, ec); |
Daniel Stone | 325fc2d | 2012-05-30 16:31:58 +0100 | [diff] [blame] | 5703 | weston_compositor_add_key_binding(ec, KEY_K, mod, |
| 5704 | force_kill_binding, shell); |
Jonas Ådahl | e3cddce | 2012-06-13 00:01:22 +0200 | [diff] [blame] | 5705 | weston_compositor_add_key_binding(ec, KEY_UP, mod, |
| 5706 | workspace_up_binding, shell); |
| 5707 | weston_compositor_add_key_binding(ec, KEY_DOWN, mod, |
| 5708 | workspace_down_binding, shell); |
Jonas Ådahl | 8de6a1d | 2012-08-29 22:13:00 +0200 | [diff] [blame] | 5709 | weston_compositor_add_key_binding(ec, KEY_UP, mod | MODIFIER_SHIFT, |
| 5710 | workspace_move_surface_up_binding, |
| 5711 | shell); |
| 5712 | weston_compositor_add_key_binding(ec, KEY_DOWN, mod | MODIFIER_SHIFT, |
| 5713 | workspace_move_surface_down_binding, |
| 5714 | shell); |
Jonas Ådahl | e3cddce | 2012-06-13 00:01:22 +0200 | [diff] [blame] | 5715 | |
Daniel Stone | df8133b | 2013-11-19 11:37:14 +0100 | [diff] [blame] | 5716 | weston_compositor_add_modifier_binding(ec, mod, exposay_binding, shell); |
| 5717 | |
Jonas Ådahl | e3cddce | 2012-06-13 00:01:22 +0200 | [diff] [blame] | 5718 | /* Add bindings for mod+F[1-6] for workspace 1 to 6. */ |
| 5719 | if (shell->workspaces.num > 1) { |
| 5720 | num_workspace_bindings = shell->workspaces.num; |
| 5721 | if (num_workspace_bindings > 6) |
| 5722 | num_workspace_bindings = 6; |
| 5723 | for (i = 0; i < num_workspace_bindings; i++) |
| 5724 | weston_compositor_add_key_binding(ec, KEY_F1 + i, mod, |
| 5725 | workspace_f_binding, |
| 5726 | shell); |
| 5727 | } |
Ander Conselvan de Oliveira | c509d2b | 2012-11-08 17:20:45 +0200 | [diff] [blame] | 5728 | |
| 5729 | /* Debug bindings */ |
| 5730 | weston_compositor_add_key_binding(ec, KEY_SPACE, mod | MODIFIER_SHIFT, |
| 5731 | debug_binding, shell); |
Tiago Vignatti | 0b52d48 | 2012-04-20 18:54:25 +0300 | [diff] [blame] | 5732 | } |
| 5733 | |
Kristian Høgsberg | 1c56218 | 2011-05-02 22:09:20 -0400 | [diff] [blame] | 5734 | WL_EXPORT int |
Kristian Høgsberg | cb4685b | 2013-02-20 15:37:49 -0500 | [diff] [blame] | 5735 | module_init(struct weston_compositor *ec, |
Ossama Othman | a50e6e4 | 2013-05-14 09:48:26 -0700 | [diff] [blame] | 5736 | int *argc, char *argv[]) |
Kristian Høgsberg | 4cca349 | 2011-01-18 07:53:49 -0500 | [diff] [blame] | 5737 | { |
Kristian Høgsberg | f4d2f23 | 2012-08-10 10:05:39 -0400 | [diff] [blame] | 5738 | struct weston_seat *seat; |
Tiago Vignatti | be14326 | 2012-04-16 17:31:41 +0300 | [diff] [blame] | 5739 | struct desktop_shell *shell; |
Jonas Ådahl | e3cddce | 2012-06-13 00:01:22 +0200 | [diff] [blame] | 5740 | struct workspace **pws; |
| 5741 | unsigned int i; |
Tiago Vignatti | b7dbbd6 | 2012-09-25 17:57:01 +0300 | [diff] [blame] | 5742 | struct wl_event_loop *loop; |
Kristian Høgsberg | 02ec0a5 | 2011-04-23 13:04:11 -0400 | [diff] [blame] | 5743 | |
Peter Hutterer | f3d6227 | 2013-08-08 11:57:05 +1000 | [diff] [blame] | 5744 | shell = zalloc(sizeof *shell); |
Kristian Høgsberg | 02ec0a5 | 2011-04-23 13:04:11 -0400 | [diff] [blame] | 5745 | if (shell == NULL) |
| 5746 | return -1; |
| 5747 | |
Kristian Høgsberg | 7584062 | 2011-09-06 13:48:16 -0400 | [diff] [blame] | 5748 | shell->compositor = ec; |
Kristian Høgsberg | 02e79dc | 2012-04-12 09:55:26 -0400 | [diff] [blame] | 5749 | |
| 5750 | shell->destroy_listener.notify = shell_destroy; |
| 5751 | wl_signal_add(&ec->destroy_signal, &shell->destroy_listener); |
Ander Conselvan de Oliveira | a457563 | 2013-02-21 18:35:23 +0200 | [diff] [blame] | 5752 | shell->idle_listener.notify = idle_handler; |
| 5753 | wl_signal_add(&ec->idle_signal, &shell->idle_listener); |
| 5754 | shell->wake_listener.notify = wake_handler; |
| 5755 | wl_signal_add(&ec->wake_signal, &shell->wake_listener); |
Kristian Høgsberg | 677a5f5 | 2013-12-04 11:00:19 -0800 | [diff] [blame] | 5756 | |
Scott Moreau | ff1db4a | 2012-04-17 19:06:18 -0600 | [diff] [blame] | 5757 | ec->ping_handler = ping_handler; |
Kristian Høgsberg | 82a1d11 | 2012-07-19 14:02:00 -0400 | [diff] [blame] | 5758 | ec->shell_interface.shell = shell; |
Tiago Vignatti | bc052c9 | 2012-04-19 16:18:18 +0300 | [diff] [blame] | 5759 | ec->shell_interface.create_shell_surface = create_shell_surface; |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 5760 | ec->shell_interface.get_primary_view = get_primary_view; |
Tiago Vignatti | bc052c9 | 2012-04-19 16:18:18 +0300 | [diff] [blame] | 5761 | ec->shell_interface.set_toplevel = set_toplevel; |
Tiago Vignatti | 491bac1 | 2012-05-18 16:37:43 -0400 | [diff] [blame] | 5762 | ec->shell_interface.set_transient = set_transient; |
Kristian Høgsberg | b810eb5 | 2013-02-12 20:07:05 -0500 | [diff] [blame] | 5763 | ec->shell_interface.set_fullscreen = set_fullscreen; |
Tiago Vignatti | fb2adba | 2013-06-12 15:43:21 -0300 | [diff] [blame] | 5764 | ec->shell_interface.set_xwayland = set_xwayland; |
Kristian Høgsberg | 938b8fa | 2012-05-18 13:46:27 -0400 | [diff] [blame] | 5765 | ec->shell_interface.move = surface_move; |
Kristian Høgsberg | c1693f2 | 2012-05-22 16:56:23 -0400 | [diff] [blame] | 5766 | ec->shell_interface.resize = surface_resize; |
Giulio Camuffo | 62942ad | 2013-09-11 18:20:47 +0200 | [diff] [blame] | 5767 | ec->shell_interface.set_title = set_title; |
Kristian Høgsberg | 4cca349 | 2011-01-18 07:53:49 -0500 | [diff] [blame] | 5768 | |
Kristian Høgsberg | 3be2ce9 | 2012-02-29 12:42:35 -0500 | [diff] [blame] | 5769 | weston_layer_init(&shell->fullscreen_layer, &ec->cursor_layer.link); |
| 5770 | weston_layer_init(&shell->panel_layer, &shell->fullscreen_layer.link); |
Jonas Ådahl | e3cddce | 2012-06-13 00:01:22 +0200 | [diff] [blame] | 5771 | weston_layer_init(&shell->background_layer, &shell->panel_layer.link); |
| 5772 | weston_layer_init(&shell->lock_layer, NULL); |
Philipp Brüschweiler | 711fda8 | 2012-08-09 18:50:43 +0200 | [diff] [blame] | 5773 | weston_layer_init(&shell->input_panel_layer, NULL); |
Jonas Ådahl | e3cddce | 2012-06-13 00:01:22 +0200 | [diff] [blame] | 5774 | |
| 5775 | wl_array_init(&shell->workspaces.array); |
Jonas Ådahl | e9d2250 | 2012-08-29 22:13:01 +0200 | [diff] [blame] | 5776 | wl_list_init(&shell->workspaces.client_list); |
Kristian Høgsberg | 3be2ce9 | 2012-02-29 12:42:35 -0500 | [diff] [blame] | 5777 | |
Kristian Høgsberg | 677a5f5 | 2013-12-04 11:00:19 -0800 | [diff] [blame] | 5778 | if (input_panel_setup(shell) < 0) |
| 5779 | return -1; |
| 5780 | |
Kristian Høgsberg | 14e438c | 2013-05-26 21:48:14 -0400 | [diff] [blame] | 5781 | shell_configuration(shell); |
Pekka Paalanen | e955f1e | 2011-12-07 11:49:52 +0200 | [diff] [blame] | 5782 | |
Daniel Stone | df8133b | 2013-11-19 11:37:14 +0100 | [diff] [blame] | 5783 | shell->exposay.state_cur = EXPOSAY_LAYOUT_INACTIVE; |
| 5784 | shell->exposay.state_target = EXPOSAY_TARGET_CANCEL; |
| 5785 | |
Jonas Ådahl | e3cddce | 2012-06-13 00:01:22 +0200 | [diff] [blame] | 5786 | for (i = 0; i < shell->workspaces.num; i++) { |
| 5787 | pws = wl_array_add(&shell->workspaces.array, sizeof *pws); |
| 5788 | if (pws == NULL) |
| 5789 | return -1; |
| 5790 | |
| 5791 | *pws = workspace_create(); |
| 5792 | if (*pws == NULL) |
| 5793 | return -1; |
| 5794 | } |
| 5795 | activate_workspace(shell, 0); |
| 5796 | |
Jonas Ådahl | 8de6a1d | 2012-08-29 22:13:00 +0200 | [diff] [blame] | 5797 | wl_list_init(&shell->workspaces.anim_sticky_list); |
Jonas Ådahl | 62fcd04 | 2012-06-13 00:01:23 +0200 | [diff] [blame] | 5798 | wl_list_init(&shell->workspaces.animation.link); |
| 5799 | shell->workspaces.animation.frame = animate_workspace_change_frame; |
| 5800 | |
Kristian Høgsberg | 919cddb | 2013-07-08 19:03:57 -0400 | [diff] [blame] | 5801 | if (wl_global_create(ec->wl_display, &wl_shell_interface, 1, |
Kristian Høgsberg | 97d44aa | 2011-08-26 17:21:20 -0400 | [diff] [blame] | 5802 | shell, bind_shell) == NULL) |
Kristian Høgsberg | 4cca349 | 2011-01-18 07:53:49 -0500 | [diff] [blame] | 5803 | return -1; |
| 5804 | |
Rafael Antognolli | e2a3455 | 2013-12-03 15:35:45 -0200 | [diff] [blame] | 5805 | if (wl_global_create(ec->wl_display, &xdg_shell_interface, 1, |
| 5806 | shell, bind_xdg_shell) == NULL) |
| 5807 | return -1; |
| 5808 | |
Kristian Høgsberg | 919cddb | 2013-07-08 19:03:57 -0400 | [diff] [blame] | 5809 | if (wl_global_create(ec->wl_display, |
| 5810 | &desktop_shell_interface, 2, |
| 5811 | shell, bind_desktop_shell) == NULL) |
Kristian Høgsberg | 7584062 | 2011-09-06 13:48:16 -0400 | [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, &screensaver_interface, 1, |
| 5815 | shell, bind_screensaver) == NULL) |
Pekka Paalanen | 6e16811 | 2011-11-24 11:34:05 +0200 | [diff] [blame] | 5816 | return -1; |
| 5817 | |
Kristian Høgsberg | 919cddb | 2013-07-08 19:03:57 -0400 | [diff] [blame] | 5818 | if (wl_global_create(ec->wl_display, &workspace_manager_interface, 1, |
| 5819 | shell, bind_workspace_manager) == NULL) |
Jonas Ådahl | e9d2250 | 2012-08-29 22:13:01 +0200 | [diff] [blame] | 5820 | return -1; |
| 5821 | |
Kristian Høgsberg | f03a616 | 2012-01-17 11:07:42 -0500 | [diff] [blame] | 5822 | shell->child.deathstamp = weston_compositor_get_time(); |
Tiago Vignatti | b7dbbd6 | 2012-09-25 17:57:01 +0300 | [diff] [blame] | 5823 | |
Xiong Zhang | 6b48142 | 2013-10-23 13:58:32 +0800 | [diff] [blame] | 5824 | setup_output_destroy_handler(ec, shell); |
| 5825 | |
Tiago Vignatti | b7dbbd6 | 2012-09-25 17:57:01 +0300 | [diff] [blame] | 5826 | loop = wl_display_get_event_loop(ec->wl_display); |
| 5827 | wl_event_loop_add_idle(loop, launch_desktop_shell_process, shell); |
Pekka Paalanen | 6cd281a | 2011-11-03 14:11:32 +0200 | [diff] [blame] | 5828 | |
Ander Conselvan de Oliveira | 859e885 | 2013-02-21 18:35:21 +0200 | [diff] [blame] | 5829 | shell->screensaver.timer = |
| 5830 | wl_event_loop_add_timer(loop, screensaver_timeout, shell); |
| 5831 | |
Kristian Høgsberg | f4d2f23 | 2012-08-10 10:05:39 -0400 | [diff] [blame] | 5832 | wl_list_for_each(seat, &ec->seat_list, link) |
| 5833 | create_pointer_focus_listener(seat); |
Kristian Høgsberg | d56bd90 | 2012-06-05 09:58:51 -0400 | [diff] [blame] | 5834 | |
Tiago Vignatti | 0b52d48 | 2012-04-20 18:54:25 +0300 | [diff] [blame] | 5835 | shell_add_bindings(ec, shell); |
Kristian Høgsberg | 0793756 | 2011-04-12 17:25:42 -0400 | [diff] [blame] | 5836 | |
Pekka Paalanen | 79346ab | 2013-05-22 18:03:09 +0300 | [diff] [blame] | 5837 | shell_fade_init(shell); |
Ander Conselvan de Oliveira | 19d10ef | 2013-02-21 18:35:20 +0200 | [diff] [blame] | 5838 | |
Kristian Høgsberg | 4cca349 | 2011-01-18 07:53:49 -0500 | [diff] [blame] | 5839 | return 0; |
| 5840 | } |