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