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> |
Pekka Paalanen | 9ef3e01 | 2011-11-15 13:34:48 +0200 | [diff] [blame] | 29 | #include <stdbool.h> |
Kristian Høgsberg | 4cca349 | 2011-01-18 07:53:49 -0500 | [diff] [blame] | 30 | #include <string.h> |
| 31 | #include <unistd.h> |
Kristian Høgsberg | 0793756 | 2011-04-12 17:25:42 -0400 | [diff] [blame] | 32 | #include <linux/input.h> |
Pekka Paalanen | f0fc70d | 2011-11-15 13:34:54 +0200 | [diff] [blame] | 33 | #include <assert.h> |
Pekka Paalanen | 18027e5 | 2011-12-02 16:31:49 +0200 | [diff] [blame] | 34 | #include <signal.h> |
Pekka Paalanen | 460099f | 2012-01-20 16:48:25 +0200 | [diff] [blame] | 35 | #include <math.h> |
Kristian Høgsberg | 92a57db | 2012-05-26 13:41:06 -0400 | [diff] [blame] | 36 | #include <sys/types.h> |
Kristian Høgsberg | 4cca349 | 2011-01-18 07:53:49 -0500 | [diff] [blame] | 37 | |
Kristian Høgsberg | 4cca349 | 2011-01-18 07:53:49 -0500 | [diff] [blame] | 38 | #include "compositor.h" |
Kristian Høgsberg | 7584062 | 2011-09-06 13:48:16 -0400 | [diff] [blame] | 39 | #include "desktop-shell-server-protocol.h" |
Jan Arne Petersen | ffbb20f | 2013-01-16 21:26:55 +0100 | [diff] [blame] | 40 | #include "input-method-server-protocol.h" |
Jonas Ådahl | e9d2250 | 2012-08-29 22:13:01 +0200 | [diff] [blame] | 41 | #include "workspaces-server-protocol.h" |
Pekka Paalanen | e955f1e | 2011-12-07 11:49:52 +0200 | [diff] [blame] | 42 | #include "../shared/config-parser.h" |
Kristian Høgsberg | 4cca349 | 2011-01-18 07:53:49 -0500 | [diff] [blame] | 43 | |
Jonas Ådahl | e3cddce | 2012-06-13 00:01:22 +0200 | [diff] [blame] | 44 | #define DEFAULT_NUM_WORKSPACES 1 |
Jonas Ådahl | 62fcd04 | 2012-06-13 00:01:23 +0200 | [diff] [blame] | 45 | #define DEFAULT_WORKSPACE_CHANGE_ANIMATION_LENGTH 200 |
Jonas Ådahl | e3cddce | 2012-06-13 00:01:22 +0200 | [diff] [blame] | 46 | |
Juan Zhao | e10d279 | 2012-04-25 19:09:52 +0800 | [diff] [blame] | 47 | enum animation_type { |
| 48 | ANIMATION_NONE, |
| 49 | |
| 50 | ANIMATION_ZOOM, |
Louis-Francis Ratté-Boulianne | b482dbd | 2013-11-19 11:37:11 +0100 | [diff] [blame] | 51 | ANIMATION_FADE, |
| 52 | ANIMATION_DIM_LAYER, |
Juan Zhao | e10d279 | 2012-04-25 19:09:52 +0800 | [diff] [blame] | 53 | }; |
| 54 | |
Ander Conselvan de Oliveira | 19d10ef | 2013-02-21 18:35:20 +0200 | [diff] [blame] | 55 | enum fade_type { |
| 56 | FADE_IN, |
| 57 | FADE_OUT |
| 58 | }; |
| 59 | |
Daniel Stone | df8133b | 2013-11-19 11:37:14 +0100 | [diff] [blame] | 60 | enum exposay_target_state { |
| 61 | EXPOSAY_TARGET_OVERVIEW, /* show all windows */ |
| 62 | EXPOSAY_TARGET_CANCEL, /* return to normal, same focus */ |
| 63 | EXPOSAY_TARGET_SWITCH, /* return to normal, switch focus */ |
| 64 | }; |
| 65 | |
| 66 | enum exposay_layout_state { |
| 67 | EXPOSAY_LAYOUT_INACTIVE = 0, /* normal desktop */ |
| 68 | EXPOSAY_LAYOUT_ANIMATE_TO_INACTIVE, /* in transition to normal */ |
| 69 | EXPOSAY_LAYOUT_OVERVIEW, /* show all windows */ |
| 70 | EXPOSAY_LAYOUT_ANIMATE_TO_OVERVIEW, /* in transition to all windows */ |
| 71 | }; |
| 72 | |
Jonas Ådahl | 0476974 | 2012-06-13 00:01:24 +0200 | [diff] [blame] | 73 | struct focus_state { |
| 74 | struct weston_seat *seat; |
Kristian Høgsberg | 2f5faff | 2012-07-31 16:36:34 -0400 | [diff] [blame] | 75 | struct workspace *ws; |
Jonas Ådahl | 0476974 | 2012-06-13 00:01:24 +0200 | [diff] [blame] | 76 | struct weston_surface *keyboard_focus; |
| 77 | struct wl_list link; |
| 78 | struct wl_listener seat_destroy_listener; |
| 79 | struct wl_listener surface_destroy_listener; |
| 80 | }; |
| 81 | |
Louis-Francis Ratté-Boulianne | b482dbd | 2013-11-19 11:37:11 +0100 | [diff] [blame] | 82 | struct focus_surface { |
| 83 | struct weston_surface *surface; |
| 84 | struct weston_view *view; |
| 85 | struct weston_transform workspace_transform; |
| 86 | }; |
| 87 | |
Jonas Ådahl | e3cddce | 2012-06-13 00:01:22 +0200 | [diff] [blame] | 88 | struct workspace { |
| 89 | struct weston_layer layer; |
Jonas Ådahl | 0476974 | 2012-06-13 00:01:24 +0200 | [diff] [blame] | 90 | |
| 91 | struct wl_list focus_list; |
| 92 | struct wl_listener seat_destroyed_listener; |
Louis-Francis Ratté-Boulianne | b482dbd | 2013-11-19 11:37:11 +0100 | [diff] [blame] | 93 | |
| 94 | struct focus_surface *fsurf_front; |
| 95 | struct focus_surface *fsurf_back; |
| 96 | struct weston_view_animation *focus_animation; |
Jonas Ådahl | e3cddce | 2012-06-13 00:01:22 +0200 | [diff] [blame] | 97 | }; |
| 98 | |
Philipp Brüschweiler | 8801357 | 2012-08-06 13:44:42 +0200 | [diff] [blame] | 99 | struct input_panel_surface { |
Jason Ekstrand | 51e5b14 | 2013-06-14 10:07:58 -0500 | [diff] [blame] | 100 | struct wl_resource *resource; |
| 101 | struct wl_signal destroy_signal; |
Jan Arne Petersen | ffbb20f | 2013-01-16 21:26:55 +0100 | [diff] [blame] | 102 | |
| 103 | struct desktop_shell *shell; |
| 104 | |
Philipp Brüschweiler | 8801357 | 2012-08-06 13:44:42 +0200 | [diff] [blame] | 105 | struct wl_list link; |
| 106 | struct weston_surface *surface; |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 107 | struct weston_view *view; |
Jan Arne Petersen | ffbb20f | 2013-01-16 21:26:55 +0100 | [diff] [blame] | 108 | struct wl_listener surface_destroy_listener; |
Jan Arne Petersen | 14da96b | 2013-04-18 16:47:28 +0200 | [diff] [blame] | 109 | |
Jan Arne Petersen | 7cd29e1 | 2013-04-18 16:47:29 +0200 | [diff] [blame] | 110 | struct weston_output *output; |
Jan Arne Petersen | 14da96b | 2013-04-18 16:47:28 +0200 | [diff] [blame] | 111 | uint32_t panel; |
Philipp Brüschweiler | 8801357 | 2012-08-06 13:44:42 +0200 | [diff] [blame] | 112 | }; |
| 113 | |
Xiong Zhang | 6b48142 | 2013-10-23 13:58:32 +0800 | [diff] [blame] | 114 | struct shell_output { |
| 115 | struct desktop_shell *shell; |
| 116 | struct weston_output *output; |
| 117 | struct wl_listener destroy_listener; |
| 118 | struct wl_list link; |
| 119 | }; |
| 120 | |
Tiago Vignatti | be14326 | 2012-04-16 17:31:41 +0300 | [diff] [blame] | 121 | struct desktop_shell { |
Kristian Høgsberg | 8334bc1 | 2012-01-03 10:29:47 -0500 | [diff] [blame] | 122 | struct weston_compositor *compositor; |
Kristian Høgsberg | 02e79dc | 2012-04-12 09:55:26 -0400 | [diff] [blame] | 123 | |
Ander Conselvan de Oliveira | a457563 | 2013-02-21 18:35:23 +0200 | [diff] [blame] | 124 | struct wl_listener idle_listener; |
| 125 | struct wl_listener wake_listener; |
Kristian Høgsberg | 02e79dc | 2012-04-12 09:55:26 -0400 | [diff] [blame] | 126 | struct wl_listener destroy_listener; |
Jan Arne Petersen | 42feced | 2012-06-21 21:52:17 +0200 | [diff] [blame] | 127 | struct wl_listener show_input_panel_listener; |
| 128 | struct wl_listener hide_input_panel_listener; |
Jan Arne Petersen | 14da96b | 2013-04-18 16:47:28 +0200 | [diff] [blame] | 129 | struct wl_listener update_input_panel_listener; |
Pekka Paalanen | 6cd281a | 2011-11-03 14:11:32 +0200 | [diff] [blame] | 130 | |
Kristian Høgsberg | 3be2ce9 | 2012-02-29 12:42:35 -0500 | [diff] [blame] | 131 | struct weston_layer fullscreen_layer; |
| 132 | struct weston_layer panel_layer; |
Kristian Høgsberg | 3be2ce9 | 2012-02-29 12:42:35 -0500 | [diff] [blame] | 133 | struct weston_layer background_layer; |
| 134 | struct weston_layer lock_layer; |
Philipp Brüschweiler | 711fda8 | 2012-08-09 18:50:43 +0200 | [diff] [blame] | 135 | struct weston_layer input_panel_layer; |
Kristian Høgsberg | 3be2ce9 | 2012-02-29 12:42:35 -0500 | [diff] [blame] | 136 | |
Kristian Høgsberg | d56bd90 | 2012-06-05 09:58:51 -0400 | [diff] [blame] | 137 | struct wl_listener pointer_focus_listener; |
Ander Conselvan de Oliveira | b9d2a0f | 2012-06-28 18:08:05 +0300 | [diff] [blame] | 138 | struct weston_surface *grab_surface; |
Kristian Høgsberg | d56bd90 | 2012-06-05 09:58:51 -0400 | [diff] [blame] | 139 | |
Pekka Paalanen | 6cd281a | 2011-11-03 14:11:32 +0200 | [diff] [blame] | 140 | struct { |
Kristian Høgsberg | 8334bc1 | 2012-01-03 10:29:47 -0500 | [diff] [blame] | 141 | struct weston_process process; |
Pekka Paalanen | 6cd281a | 2011-11-03 14:11:32 +0200 | [diff] [blame] | 142 | struct wl_client *client; |
Pekka Paalanen | 9ef3e01 | 2011-11-15 13:34:48 +0200 | [diff] [blame] | 143 | struct wl_resource *desktop_shell; |
Pekka Paalanen | 4d733ee | 2012-01-17 14:36:27 +0200 | [diff] [blame] | 144 | |
| 145 | unsigned deathcount; |
| 146 | uint32_t deathstamp; |
Pekka Paalanen | 6cd281a | 2011-11-03 14:11:32 +0200 | [diff] [blame] | 147 | } child; |
Pekka Paalanen | 9ef3e01 | 2011-11-15 13:34:48 +0200 | [diff] [blame] | 148 | |
| 149 | bool locked; |
Philipp Brüschweiler | 711fda8 | 2012-08-09 18:50:43 +0200 | [diff] [blame] | 150 | bool showing_input_panels; |
Pekka Paalanen | 9ef3e01 | 2011-11-15 13:34:48 +0200 | [diff] [blame] | 151 | bool prepare_event_sent; |
Pekka Paalanen | f0fc70d | 2011-11-15 13:34:54 +0200 | [diff] [blame] | 152 | |
Jan Arne Petersen | 14da96b | 2013-04-18 16:47:28 +0200 | [diff] [blame] | 153 | struct { |
| 154 | struct weston_surface *surface; |
| 155 | pixman_box32_t cursor_rectangle; |
| 156 | } text_input; |
| 157 | |
Kristian Høgsberg | 730c94d | 2012-06-26 21:44:35 -0400 | [diff] [blame] | 158 | struct weston_surface *lock_surface; |
Kristian Høgsberg | 1ec0c31 | 2011-11-15 16:39:55 -0500 | [diff] [blame] | 159 | struct wl_listener lock_surface_listener; |
Benjamin Franzke | d0f79ab | 2011-11-22 12:43:52 +0100 | [diff] [blame] | 160 | |
Pekka Paalanen | 77346a6 | 2011-11-30 16:26:35 +0200 | [diff] [blame] | 161 | struct { |
Jonas Ådahl | e3cddce | 2012-06-13 00:01:22 +0200 | [diff] [blame] | 162 | struct wl_array array; |
| 163 | unsigned int current; |
| 164 | unsigned int num; |
Jonas Ådahl | 62fcd04 | 2012-06-13 00:01:23 +0200 | [diff] [blame] | 165 | |
Jonas Ådahl | e9d2250 | 2012-08-29 22:13:01 +0200 | [diff] [blame] | 166 | struct wl_list client_list; |
| 167 | |
Jonas Ådahl | 62fcd04 | 2012-06-13 00:01:23 +0200 | [diff] [blame] | 168 | struct weston_animation animation; |
Jonas Ådahl | 8de6a1d | 2012-08-29 22:13:00 +0200 | [diff] [blame] | 169 | struct wl_list anim_sticky_list; |
Jonas Ådahl | 62fcd04 | 2012-06-13 00:01:23 +0200 | [diff] [blame] | 170 | int anim_dir; |
| 171 | uint32_t anim_timestamp; |
| 172 | double anim_current; |
| 173 | struct workspace *anim_from; |
| 174 | struct workspace *anim_to; |
Jonas Ådahl | e3cddce | 2012-06-13 00:01:22 +0200 | [diff] [blame] | 175 | } workspaces; |
| 176 | |
| 177 | struct { |
Pekka Paalanen | 3c64723 | 2011-12-22 13:43:43 +0200 | [diff] [blame] | 178 | char *path; |
Pekka Paalanen | 7296e79 | 2011-12-07 16:22:00 +0200 | [diff] [blame] | 179 | int duration; |
Pekka Paalanen | 77346a6 | 2011-11-30 16:26:35 +0200 | [diff] [blame] | 180 | struct wl_resource *binding; |
Kristian Høgsberg | 8334bc1 | 2012-01-03 10:29:47 -0500 | [diff] [blame] | 181 | struct weston_process process; |
Ander Conselvan de Oliveira | 859e885 | 2013-02-21 18:35:21 +0200 | [diff] [blame] | 182 | struct wl_event_source *timer; |
Pekka Paalanen | 77346a6 | 2011-11-30 16:26:35 +0200 | [diff] [blame] | 183 | } screensaver; |
Kristian Høgsberg | b41c081 | 2012-03-04 14:53:40 -0500 | [diff] [blame] | 184 | |
Jan Arne Petersen | 42feced | 2012-06-21 21:52:17 +0200 | [diff] [blame] | 185 | struct { |
| 186 | struct wl_resource *binding; |
| 187 | struct wl_list surfaces; |
| 188 | } input_panel; |
| 189 | |
Ander Conselvan de Oliveira | 19d10ef | 2013-02-21 18:35:20 +0200 | [diff] [blame] | 190 | struct { |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 191 | struct weston_view *view; |
| 192 | struct weston_view_animation *animation; |
Ander Conselvan de Oliveira | 19d10ef | 2013-02-21 18:35:20 +0200 | [diff] [blame] | 193 | enum fade_type type; |
Pekka Paalanen | 79346ab | 2013-05-22 18:03:09 +0300 | [diff] [blame] | 194 | struct wl_event_source *startup_timer; |
Ander Conselvan de Oliveira | 19d10ef | 2013-02-21 18:35:20 +0200 | [diff] [blame] | 195 | } fade; |
| 196 | |
Daniel Stone | df8133b | 2013-11-19 11:37:14 +0100 | [diff] [blame] | 197 | struct exposay { |
| 198 | /* XXX: Make these exposay_surfaces. */ |
| 199 | struct weston_view *focus_prev; |
| 200 | struct weston_view *focus_current; |
| 201 | struct weston_view *clicked; |
| 202 | struct workspace *workspace; |
| 203 | struct weston_seat *seat; |
| 204 | struct wl_list surface_list; |
| 205 | |
| 206 | struct weston_keyboard_grab grab_kbd; |
| 207 | struct weston_pointer_grab grab_ptr; |
| 208 | |
| 209 | enum exposay_target_state state_target; |
| 210 | enum exposay_layout_state state_cur; |
| 211 | int in_flight; /* number of animations still running */ |
| 212 | |
| 213 | int num_surfaces; |
| 214 | int grid_size; |
| 215 | int surface_size; |
| 216 | |
| 217 | int hpadding_outer; |
| 218 | int vpadding_outer; |
| 219 | int padding_inner; |
| 220 | |
| 221 | int row_current; |
| 222 | int column_current; |
Emilio Pozuelo Monfort | eed9344 | 2013-11-27 10:49:08 +0100 | [diff] [blame] | 223 | |
| 224 | bool mod_pressed; |
| 225 | bool mod_invalid; |
Daniel Stone | df8133b | 2013-11-19 11:37:14 +0100 | [diff] [blame] | 226 | } exposay; |
| 227 | |
Tiago Vignatti | 0b52d48 | 2012-04-20 18:54:25 +0300 | [diff] [blame] | 228 | uint32_t binding_modifier; |
Juan Zhao | e10d279 | 2012-04-25 19:09:52 +0800 | [diff] [blame] | 229 | enum animation_type win_animation_type; |
Kristian Høgsberg | 724c8d9 | 2013-10-16 11:38:24 -0700 | [diff] [blame] | 230 | enum animation_type startup_animation_type; |
Louis-Francis Ratté-Boulianne | b482dbd | 2013-11-19 11:37:11 +0100 | [diff] [blame] | 231 | enum animation_type focus_animation_type; |
Xiong Zhang | 6b48142 | 2013-10-23 13:58:32 +0800 | [diff] [blame] | 232 | |
| 233 | struct wl_listener output_create_listener; |
| 234 | struct wl_list output_list; |
Emilio Pozuelo Monfort | 46ce798 | 2013-11-20 13:22:29 +0100 | [diff] [blame] | 235 | |
| 236 | char *client; |
Kristian Høgsberg | 02ec0a5 | 2011-04-23 13:04:11 -0400 | [diff] [blame] | 237 | }; |
| 238 | |
Kristian Høgsberg | d2abb83 | 2011-11-23 10:52:40 -0500 | [diff] [blame] | 239 | enum shell_surface_type { |
Pekka Paalanen | 9826223 | 2011-12-01 10:42:22 +0200 | [diff] [blame] | 240 | SHELL_SURFACE_NONE, |
Kristian Høgsberg | d2abb83 | 2011-11-23 10:52:40 -0500 | [diff] [blame] | 241 | SHELL_SURFACE_TOPLEVEL, |
Tiago Vignatti | fb2adba | 2013-06-12 15:43:21 -0300 | [diff] [blame] | 242 | SHELL_SURFACE_POPUP, |
| 243 | SHELL_SURFACE_XWAYLAND |
Pekka Paalanen | 57da4a8 | 2011-11-23 16:42:16 +0200 | [diff] [blame] | 244 | }; |
| 245 | |
Scott Moreau | ff1db4a | 2012-04-17 19:06:18 -0600 | [diff] [blame] | 246 | struct ping_timer { |
| 247 | struct wl_event_source *source; |
Scott Moreau | ff1db4a | 2012-04-17 19:06:18 -0600 | [diff] [blame] | 248 | uint32_t serial; |
| 249 | }; |
| 250 | |
Philip Withnall | 648a4dd | 2013-11-25 18:01:44 +0000 | [diff] [blame] | 251 | /* |
| 252 | * Surface stacking and ordering. |
| 253 | * |
| 254 | * This is handled using several linked lists of surfaces, organised into |
| 255 | * ‘layers’. The layers are ordered, and each of the surfaces in one layer are |
| 256 | * above all of the surfaces in the layer below. The set of layers is static and |
| 257 | * in the following order (top-most first): |
| 258 | * • Lock layer (only ever displayed on its own) |
| 259 | * • Cursor layer |
| 260 | * • Fullscreen layer |
| 261 | * • Panel layer |
| 262 | * • Input panel layer |
| 263 | * • Workspace layers |
| 264 | * • Background layer |
| 265 | * |
| 266 | * The list of layers may be manipulated to remove whole layers of surfaces from |
| 267 | * display. For example, when locking the screen, all layers except the lock |
| 268 | * layer are removed. |
| 269 | * |
| 270 | * A surface’s layer is modified on configuring the surface, in |
| 271 | * set_surface_type() (which is only called when the surface’s type change is |
| 272 | * _committed_). If a surface’s type changes (e.g. when making a window |
| 273 | * fullscreen) its layer changes too. |
| 274 | * |
| 275 | * In order to allow popup and transient surfaces to be correctly stacked above |
| 276 | * their parent surfaces, each surface tracks both its parent surface, and a |
| 277 | * linked list of its children. When a surface’s layer is updated, so are the |
| 278 | * layers of its children. Note that child surfaces are *not* the same as |
| 279 | * subsurfaces — child/parent surfaces are purely for maintaining stacking |
| 280 | * order. |
| 281 | * |
| 282 | * The children_link list of siblings of a surface (i.e. those surfaces which |
| 283 | * have the same parent) only contains weston_surfaces which have a |
| 284 | * shell_surface. Stacking is not implemented for non-shell_surface |
| 285 | * weston_surfaces. This means that the following implication does *not* hold: |
| 286 | * (shsurf->parent != NULL) ⇒ !wl_list_is_empty(shsurf->children_link) |
| 287 | */ |
| 288 | |
Pekka Paalanen | 56cdea9 | 2011-11-23 16:14:12 +0200 | [diff] [blame] | 289 | struct shell_surface { |
Jason Ekstrand | 651f00e | 2013-06-14 10:07:54 -0500 | [diff] [blame] | 290 | struct wl_resource *resource; |
| 291 | struct wl_signal destroy_signal; |
Pekka Paalanen | 9d1613e | 2011-11-25 12:09:16 +0200 | [diff] [blame] | 292 | |
Kristian Høgsberg | 8334bc1 | 2012-01-03 10:29:47 -0500 | [diff] [blame] | 293 | struct weston_surface *surface; |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 294 | struct weston_view *view; |
Jason Ekstrand | 918f2dd | 2013-12-02 21:01:53 -0600 | [diff] [blame] | 295 | int32_t last_width, last_height; |
Pekka Paalanen | 9d1613e | 2011-11-25 12:09:16 +0200 | [diff] [blame] | 296 | struct wl_listener surface_destroy_listener; |
Kristian Høgsberg | 8150b19 | 2012-06-27 10:22:58 -0400 | [diff] [blame] | 297 | struct weston_surface *parent; |
Philip Withnall | 648a4dd | 2013-11-25 18:01:44 +0000 | [diff] [blame] | 298 | struct wl_list children_list; /* child surfaces of this one */ |
| 299 | struct wl_list children_link; /* sibling surfaces of this one */ |
Tiago Vignatti | be14326 | 2012-04-16 17:31:41 +0300 | [diff] [blame] | 300 | struct desktop_shell *shell; |
Pekka Paalanen | 57da4a8 | 2011-11-23 16:42:16 +0200 | [diff] [blame] | 301 | |
Kristian Høgsberg | 7f366e7 | 2012-04-27 17:20:01 -0400 | [diff] [blame] | 302 | enum shell_surface_type type, next_type; |
Kristian Høgsberg | e7afd91 | 2012-05-02 09:47:44 -0400 | [diff] [blame] | 303 | char *title, *class; |
Kristian Høgsberg | d2abb83 | 2011-11-23 10:52:40 -0500 | [diff] [blame] | 304 | int32_t saved_x, saved_y; |
Alex Wu | 4539b08 | 2012-03-01 12:57:46 +0800 | [diff] [blame] | 305 | bool saved_position_valid; |
Alex Wu | 7bcb8bd | 2012-04-27 09:07:24 +0800 | [diff] [blame] | 306 | bool saved_rotation_valid; |
Kristian Høgsberg | c85f1d4 | 2013-10-24 16:52:00 -0700 | [diff] [blame] | 307 | int unresponsive, grabbed; |
Benjamin Franzke | d0f79ab | 2011-11-22 12:43:52 +0100 | [diff] [blame] | 308 | |
Kristian Høgsberg | b3cca0a | 2012-01-04 22:19:14 -0500 | [diff] [blame] | 309 | struct { |
Pekka Paalanen | 460099f | 2012-01-20 16:48:25 +0200 | [diff] [blame] | 310 | struct weston_transform transform; |
Kristian Høgsberg | 765e27b | 2012-01-27 13:36:13 -0500 | [diff] [blame] | 311 | struct weston_matrix rotation; |
Pekka Paalanen | 460099f | 2012-01-20 16:48:25 +0200 | [diff] [blame] | 312 | } rotation; |
| 313 | |
| 314 | struct { |
Giulio Camuffo | 5085a75 | 2013-03-25 21:42:45 +0100 | [diff] [blame] | 315 | struct wl_list grab_link; |
Kristian Høgsberg | b3cca0a | 2012-01-04 22:19:14 -0500 | [diff] [blame] | 316 | int32_t x, y; |
Giulio Camuffo | 5085a75 | 2013-03-25 21:42:45 +0100 | [diff] [blame] | 317 | struct shell_seat *shseat; |
Kristian Høgsberg | 3730f36 | 2012-04-13 12:40:07 -0400 | [diff] [blame] | 318 | uint32_t serial; |
Kristian Høgsberg | b3cca0a | 2012-01-04 22:19:14 -0500 | [diff] [blame] | 319 | } popup; |
| 320 | |
Alex Wu | 4539b08 | 2012-03-01 12:57:46 +0800 | [diff] [blame] | 321 | struct { |
Tiago Vignatti | 52e598c | 2012-05-07 15:23:08 +0300 | [diff] [blame] | 322 | int32_t x, y; |
Tiago Vignatti | 491bac1 | 2012-05-18 16:37:43 -0400 | [diff] [blame] | 323 | uint32_t flags; |
Tiago Vignatti | 52e598c | 2012-05-07 15:23:08 +0300 | [diff] [blame] | 324 | } transient; |
| 325 | |
| 326 | struct { |
Alex Wu | 4539b08 | 2012-03-01 12:57:46 +0800 | [diff] [blame] | 327 | enum wl_shell_surface_fullscreen_method type; |
| 328 | struct weston_transform transform; /* matrix from x, y */ |
| 329 | uint32_t framerate; |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 330 | struct weston_view *black_view; |
Alex Wu | 4539b08 | 2012-03-01 12:57:46 +0800 | [diff] [blame] | 331 | } fullscreen; |
| 332 | |
Scott Moreau | ff1db4a | 2012-04-17 19:06:18 -0600 | [diff] [blame] | 333 | struct ping_timer *ping_timer; |
| 334 | |
Jonas Ådahl | 62fcd04 | 2012-06-13 00:01:23 +0200 | [diff] [blame] | 335 | struct weston_transform workspace_transform; |
| 336 | |
Kristian Høgsberg | 1cbf326 | 2012-02-17 23:49:07 -0500 | [diff] [blame] | 337 | struct weston_output *fullscreen_output; |
Kristian Høgsberg | 8334bc1 | 2012-01-03 10:29:47 -0500 | [diff] [blame] | 338 | struct weston_output *output; |
Benjamin Franzke | d0f79ab | 2011-11-22 12:43:52 +0100 | [diff] [blame] | 339 | struct wl_list link; |
Kristian Høgsberg | a61ca06 | 2012-05-22 16:05:52 -0400 | [diff] [blame] | 340 | |
| 341 | const struct weston_shell_client *client; |
Rafael Antognolli | 03b1659 | 2013-12-03 15:35:42 -0200 | [diff] [blame] | 342 | |
| 343 | struct { |
| 344 | bool maximized; |
| 345 | bool fullscreen; |
Rafael Antognolli | ed207b4 | 2013-12-03 15:35:43 -0200 | [diff] [blame^] | 346 | bool relative; |
Rafael Antognolli | 03b1659 | 2013-12-03 15:35:42 -0200 | [diff] [blame] | 347 | } state, next_state; /* surface states */ |
| 348 | bool state_changed; |
Pekka Paalanen | 56cdea9 | 2011-11-23 16:14:12 +0200 | [diff] [blame] | 349 | }; |
| 350 | |
Ander Conselvan de Oliveira | fe0444a | 2012-04-04 17:48:05 +0300 | [diff] [blame] | 351 | struct shell_grab { |
Kristian Høgsberg | 02bbabb | 2013-05-06 22:15:05 -0400 | [diff] [blame] | 352 | struct weston_pointer_grab grab; |
Ander Conselvan de Oliveira | fe0444a | 2012-04-04 17:48:05 +0300 | [diff] [blame] | 353 | struct shell_surface *shsurf; |
| 354 | struct wl_listener shsurf_destroy_listener; |
| 355 | }; |
| 356 | |
Rusty Lynch | 1084da5 | 2013-08-15 09:10:08 -0700 | [diff] [blame] | 357 | struct shell_touch_grab { |
| 358 | struct weston_touch_grab grab; |
| 359 | struct shell_surface *shsurf; |
| 360 | struct wl_listener shsurf_destroy_listener; |
| 361 | struct weston_touch *touch; |
| 362 | }; |
| 363 | |
Ander Conselvan de Oliveira | fe0444a | 2012-04-04 17:48:05 +0300 | [diff] [blame] | 364 | struct weston_move_grab { |
| 365 | struct shell_grab base; |
Daniel Stone | 103db7f | 2012-05-08 17:17:55 +0100 | [diff] [blame] | 366 | wl_fixed_t dx, dy; |
Kristian Høgsberg | 4cca349 | 2011-01-18 07:53:49 -0500 | [diff] [blame] | 367 | }; |
| 368 | |
Rusty Lynch | 1084da5 | 2013-08-15 09:10:08 -0700 | [diff] [blame] | 369 | struct weston_touch_move_grab { |
| 370 | struct shell_touch_grab base; |
| 371 | wl_fixed_t dx, dy; |
| 372 | }; |
| 373 | |
Pekka Paalanen | 460099f | 2012-01-20 16:48:25 +0200 | [diff] [blame] | 374 | struct rotate_grab { |
Ander Conselvan de Oliveira | fe0444a | 2012-04-04 17:48:05 +0300 | [diff] [blame] | 375 | struct shell_grab base; |
Kristian Høgsberg | 765e27b | 2012-01-27 13:36:13 -0500 | [diff] [blame] | 376 | struct weston_matrix rotation; |
Pekka Paalanen | 460099f | 2012-01-20 16:48:25 +0200 | [diff] [blame] | 377 | struct { |
John Kåre Alsaker | 490d02a | 2012-09-30 02:57:21 +0200 | [diff] [blame] | 378 | float x; |
| 379 | float y; |
Pekka Paalanen | 460099f | 2012-01-20 16:48:25 +0200 | [diff] [blame] | 380 | } center; |
| 381 | }; |
| 382 | |
Giulio Camuffo | 5085a75 | 2013-03-25 21:42:45 +0100 | [diff] [blame] | 383 | struct shell_seat { |
| 384 | struct weston_seat *seat; |
| 385 | struct wl_listener seat_destroy_listener; |
| 386 | |
| 387 | struct { |
Kristian Høgsberg | 02bbabb | 2013-05-06 22:15:05 -0400 | [diff] [blame] | 388 | struct weston_pointer_grab grab; |
Giulio Camuffo | 5085a75 | 2013-03-25 21:42:45 +0100 | [diff] [blame] | 389 | struct wl_list surfaces_list; |
| 390 | struct wl_client *client; |
| 391 | int32_t initial_up; |
| 392 | } popup_grab; |
| 393 | }; |
| 394 | |
Kristian Høgsberg | 2f5faff | 2012-07-31 16:36:34 -0400 | [diff] [blame] | 395 | static void |
| 396 | activate(struct desktop_shell *shell, struct weston_surface *es, |
| 397 | struct weston_seat *seat); |
| 398 | |
| 399 | static struct workspace * |
| 400 | get_current_workspace(struct desktop_shell *shell); |
| 401 | |
Alex Wu | bd3354b | 2012-04-17 17:20:49 +0800 | [diff] [blame] | 402 | static struct shell_surface * |
| 403 | get_shell_surface(struct weston_surface *surface); |
| 404 | |
| 405 | static struct desktop_shell * |
| 406 | shell_surface_get_shell(struct shell_surface *shsurf); |
| 407 | |
Kristian Høgsberg | 0c36903 | 2013-02-14 21:31:44 -0500 | [diff] [blame] | 408 | static void |
Kristian Høgsberg | e314875 | 2013-05-06 23:19:49 -0400 | [diff] [blame] | 409 | surface_rotate(struct shell_surface *surface, struct weston_seat *seat); |
Kristian Høgsberg | 0c36903 | 2013-02-14 21:31:44 -0500 | [diff] [blame] | 410 | |
Pekka Paalanen | 79346ab | 2013-05-22 18:03:09 +0300 | [diff] [blame] | 411 | static void |
| 412 | shell_fade_startup(struct desktop_shell *shell); |
| 413 | |
Philip Withnall | becb77e | 2013-11-25 18:01:30 +0000 | [diff] [blame] | 414 | static struct shell_seat * |
| 415 | get_shell_seat(struct weston_seat *seat); |
| 416 | |
Philip Withnall | 648a4dd | 2013-11-25 18:01:44 +0000 | [diff] [blame] | 417 | static void |
| 418 | shell_surface_update_child_surface_layers(struct shell_surface *shsurf); |
| 419 | |
Alex Wu | bd3354b | 2012-04-17 17:20:49 +0800 | [diff] [blame] | 420 | static bool |
| 421 | shell_surface_is_top_fullscreen(struct shell_surface *shsurf) |
| 422 | { |
| 423 | struct desktop_shell *shell; |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 424 | struct weston_view *top_fs_ev; |
Alex Wu | bd3354b | 2012-04-17 17:20:49 +0800 | [diff] [blame] | 425 | |
| 426 | shell = shell_surface_get_shell(shsurf); |
Quentin Glidic | c0d79ce | 2013-01-29 14:16:13 +0100 | [diff] [blame] | 427 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 428 | if (wl_list_empty(&shell->fullscreen_layer.view_list)) |
Alex Wu | bd3354b | 2012-04-17 17:20:49 +0800 | [diff] [blame] | 429 | return false; |
| 430 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 431 | top_fs_ev = container_of(shell->fullscreen_layer.view_list.next, |
| 432 | struct weston_view, |
Alex Wu | bd3354b | 2012-04-17 17:20:49 +0800 | [diff] [blame] | 433 | layer_link); |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 434 | return (shsurf == get_shell_surface(top_fs_ev->surface)); |
Alex Wu | bd3354b | 2012-04-17 17:20:49 +0800 | [diff] [blame] | 435 | } |
| 436 | |
Kristian Høgsberg | 6af8eb9 | 2012-01-25 16:57:11 -0500 | [diff] [blame] | 437 | static void |
Kristian Høgsberg | 27e3052 | 2012-04-11 23:18:23 -0400 | [diff] [blame] | 438 | destroy_shell_grab_shsurf(struct wl_listener *listener, void *data) |
Ander Conselvan de Oliveira | fe0444a | 2012-04-04 17:48:05 +0300 | [diff] [blame] | 439 | { |
| 440 | struct shell_grab *grab; |
| 441 | |
| 442 | grab = container_of(listener, struct shell_grab, |
| 443 | shsurf_destroy_listener); |
| 444 | |
| 445 | grab->shsurf = NULL; |
| 446 | } |
| 447 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 448 | static struct weston_view * |
| 449 | get_default_view(struct weston_surface *surface) |
| 450 | { |
| 451 | struct shell_surface *shsurf; |
| 452 | struct weston_view *view; |
| 453 | |
| 454 | if (!surface || wl_list_empty(&surface->views)) |
| 455 | return NULL; |
| 456 | |
| 457 | shsurf = get_shell_surface(surface); |
| 458 | if (shsurf) |
| 459 | return shsurf->view; |
| 460 | |
| 461 | wl_list_for_each(view, &surface->views, surface_link) |
| 462 | if (weston_view_is_mapped(view)) |
| 463 | return view; |
| 464 | |
| 465 | return container_of(surface->views.next, struct weston_view, surface_link); |
| 466 | } |
| 467 | |
Ander Conselvan de Oliveira | fe0444a | 2012-04-04 17:48:05 +0300 | [diff] [blame] | 468 | static void |
Kristian Høgsberg | 02bbabb | 2013-05-06 22:15:05 -0400 | [diff] [blame] | 469 | popup_grab_end(struct weston_pointer *pointer); |
Kristian Høgsberg | 57e0907 | 2012-10-30 14:07:27 -0400 | [diff] [blame] | 470 | |
| 471 | static void |
Ander Conselvan de Oliveira | b9d2a0f | 2012-06-28 18:08:05 +0300 | [diff] [blame] | 472 | shell_grab_start(struct shell_grab *grab, |
Kristian Høgsberg | 02bbabb | 2013-05-06 22:15:05 -0400 | [diff] [blame] | 473 | const struct weston_pointer_grab_interface *interface, |
Ander Conselvan de Oliveira | b9d2a0f | 2012-06-28 18:08:05 +0300 | [diff] [blame] | 474 | struct shell_surface *shsurf, |
Kristian Høgsberg | 02bbabb | 2013-05-06 22:15:05 -0400 | [diff] [blame] | 475 | struct weston_pointer *pointer, |
Ander Conselvan de Oliveira | b9d2a0f | 2012-06-28 18:08:05 +0300 | [diff] [blame] | 476 | enum desktop_shell_cursor cursor) |
Ander Conselvan de Oliveira | fe0444a | 2012-04-04 17:48:05 +0300 | [diff] [blame] | 477 | { |
Ander Conselvan de Oliveira | b9d2a0f | 2012-06-28 18:08:05 +0300 | [diff] [blame] | 478 | struct desktop_shell *shell = shsurf->shell; |
| 479 | |
Kristian Høgsberg | 57e0907 | 2012-10-30 14:07:27 -0400 | [diff] [blame] | 480 | popup_grab_end(pointer); |
| 481 | |
Ander Conselvan de Oliveira | fe0444a | 2012-04-04 17:48:05 +0300 | [diff] [blame] | 482 | grab->grab.interface = interface; |
| 483 | grab->shsurf = shsurf; |
Kristian Høgsberg | 27e3052 | 2012-04-11 23:18:23 -0400 | [diff] [blame] | 484 | grab->shsurf_destroy_listener.notify = destroy_shell_grab_shsurf; |
Jason Ekstrand | 651f00e | 2013-06-14 10:07:54 -0500 | [diff] [blame] | 485 | wl_signal_add(&shsurf->destroy_signal, |
Kristian Høgsberg | 27e3052 | 2012-04-11 23:18:23 -0400 | [diff] [blame] | 486 | &grab->shsurf_destroy_listener); |
Ander Conselvan de Oliveira | fe0444a | 2012-04-04 17:48:05 +0300 | [diff] [blame] | 487 | |
Kristian Høgsberg | c85f1d4 | 2013-10-24 16:52:00 -0700 | [diff] [blame] | 488 | shsurf->grabbed = 1; |
Kristian Høgsberg | 02bbabb | 2013-05-06 22:15:05 -0400 | [diff] [blame] | 489 | weston_pointer_start_grab(pointer, &grab->grab); |
Kristian Høgsberg | c9974a0 | 2013-07-03 19:24:57 -0400 | [diff] [blame] | 490 | if (shell->child.desktop_shell) { |
| 491 | desktop_shell_send_grab_cursor(shell->child.desktop_shell, |
| 492 | cursor); |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 493 | weston_pointer_set_focus(pointer, |
| 494 | get_default_view(shell->grab_surface), |
Kristian Høgsberg | c9974a0 | 2013-07-03 19:24:57 -0400 | [diff] [blame] | 495 | wl_fixed_from_int(0), |
| 496 | wl_fixed_from_int(0)); |
| 497 | } |
Ander Conselvan de Oliveira | fe0444a | 2012-04-04 17:48:05 +0300 | [diff] [blame] | 498 | } |
| 499 | |
| 500 | static void |
Ander Conselvan de Oliveira | b9d2a0f | 2012-06-28 18:08:05 +0300 | [diff] [blame] | 501 | shell_grab_end(struct shell_grab *grab) |
Ander Conselvan de Oliveira | fe0444a | 2012-04-04 17:48:05 +0300 | [diff] [blame] | 502 | { |
Kristian Høgsberg | c85f1d4 | 2013-10-24 16:52:00 -0700 | [diff] [blame] | 503 | if (grab->shsurf) { |
Kristian Høgsberg | 47b5dca | 2012-06-07 18:08:04 -0400 | [diff] [blame] | 504 | wl_list_remove(&grab->shsurf_destroy_listener.link); |
Kristian Høgsberg | c85f1d4 | 2013-10-24 16:52:00 -0700 | [diff] [blame] | 505 | grab->shsurf->grabbed = 0; |
| 506 | } |
Ander Conselvan de Oliveira | b9d2a0f | 2012-06-28 18:08:05 +0300 | [diff] [blame] | 507 | |
Kristian Høgsberg | 9e5d7d1 | 2013-07-22 16:31:53 -0700 | [diff] [blame] | 508 | weston_pointer_end_grab(grab->grab.pointer); |
Ander Conselvan de Oliveira | fe0444a | 2012-04-04 17:48:05 +0300 | [diff] [blame] | 509 | } |
| 510 | |
| 511 | static void |
Rusty Lynch | 1084da5 | 2013-08-15 09:10:08 -0700 | [diff] [blame] | 512 | shell_touch_grab_start(struct shell_touch_grab *grab, |
| 513 | const struct weston_touch_grab_interface *interface, |
| 514 | struct shell_surface *shsurf, |
| 515 | struct weston_touch *touch) |
| 516 | { |
| 517 | struct desktop_shell *shell = shsurf->shell; |
| 518 | |
| 519 | grab->grab.interface = interface; |
| 520 | grab->shsurf = shsurf; |
| 521 | grab->shsurf_destroy_listener.notify = destroy_shell_grab_shsurf; |
| 522 | wl_signal_add(&shsurf->destroy_signal, |
| 523 | &grab->shsurf_destroy_listener); |
| 524 | |
| 525 | grab->touch = touch; |
Kristian Høgsberg | c85f1d4 | 2013-10-24 16:52:00 -0700 | [diff] [blame] | 526 | shsurf->grabbed = 1; |
Rusty Lynch | 1084da5 | 2013-08-15 09:10:08 -0700 | [diff] [blame] | 527 | |
| 528 | weston_touch_start_grab(touch, &grab->grab); |
| 529 | if (shell->child.desktop_shell) |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 530 | weston_touch_set_focus(touch->seat, |
| 531 | get_default_view(shell->grab_surface)); |
Rusty Lynch | 1084da5 | 2013-08-15 09:10:08 -0700 | [diff] [blame] | 532 | } |
| 533 | |
| 534 | static void |
| 535 | shell_touch_grab_end(struct shell_touch_grab *grab) |
| 536 | { |
Kristian Høgsberg | c85f1d4 | 2013-10-24 16:52:00 -0700 | [diff] [blame] | 537 | if (grab->shsurf) { |
Rusty Lynch | 1084da5 | 2013-08-15 09:10:08 -0700 | [diff] [blame] | 538 | wl_list_remove(&grab->shsurf_destroy_listener.link); |
Kristian Høgsberg | c85f1d4 | 2013-10-24 16:52:00 -0700 | [diff] [blame] | 539 | grab->shsurf->grabbed = 0; |
| 540 | } |
Rusty Lynch | 1084da5 | 2013-08-15 09:10:08 -0700 | [diff] [blame] | 541 | |
| 542 | weston_touch_end_grab(grab->touch); |
| 543 | } |
| 544 | |
| 545 | static void |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 546 | center_on_output(struct weston_view *view, |
Alex Wu | 4539b08 | 2012-03-01 12:57:46 +0800 | [diff] [blame] | 547 | struct weston_output *output); |
| 548 | |
Daniel Stone | 496ca17 | 2012-05-30 16:31:42 +0100 | [diff] [blame] | 549 | static enum weston_keyboard_modifier |
Tiago Vignatti | 0b52d48 | 2012-04-20 18:54:25 +0300 | [diff] [blame] | 550 | get_modifier(char *modifier) |
| 551 | { |
| 552 | if (!modifier) |
| 553 | return MODIFIER_SUPER; |
| 554 | |
| 555 | if (!strcmp("ctrl", modifier)) |
| 556 | return MODIFIER_CTRL; |
| 557 | else if (!strcmp("alt", modifier)) |
| 558 | return MODIFIER_ALT; |
| 559 | else if (!strcmp("super", modifier)) |
| 560 | return MODIFIER_SUPER; |
| 561 | else |
| 562 | return MODIFIER_SUPER; |
| 563 | } |
| 564 | |
Juan Zhao | e10d279 | 2012-04-25 19:09:52 +0800 | [diff] [blame] | 565 | static enum animation_type |
| 566 | get_animation_type(char *animation) |
| 567 | { |
Juan Zhao | e10d279 | 2012-04-25 19:09:52 +0800 | [diff] [blame] | 568 | if (!strcmp("zoom", animation)) |
| 569 | return ANIMATION_ZOOM; |
| 570 | else if (!strcmp("fade", animation)) |
| 571 | return ANIMATION_FADE; |
Louis-Francis Ratté-Boulianne | b482dbd | 2013-11-19 11:37:11 +0100 | [diff] [blame] | 572 | else if (!strcmp("dim-layer", animation)) |
| 573 | return ANIMATION_DIM_LAYER; |
Juan Zhao | e10d279 | 2012-04-25 19:09:52 +0800 | [diff] [blame] | 574 | else |
| 575 | return ANIMATION_NONE; |
| 576 | } |
| 577 | |
Alex Wu | 4539b08 | 2012-03-01 12:57:46 +0800 | [diff] [blame] | 578 | static void |
Kristian Høgsberg | 14e438c | 2013-05-26 21:48:14 -0400 | [diff] [blame] | 579 | shell_configuration(struct desktop_shell *shell) |
Pekka Paalanen | e955f1e | 2011-12-07 11:49:52 +0200 | [diff] [blame] | 580 | { |
Kristian Høgsberg | 673a889 | 2013-05-23 21:40:56 -0400 | [diff] [blame] | 581 | struct weston_config_section *section; |
| 582 | int duration; |
| 583 | char *s; |
Pekka Paalanen | e955f1e | 2011-12-07 11:49:52 +0200 | [diff] [blame] | 584 | |
Kristian Høgsberg | 673a889 | 2013-05-23 21:40:56 -0400 | [diff] [blame] | 585 | section = weston_config_get_section(shell->compositor->config, |
| 586 | "screensaver", NULL, NULL); |
| 587 | weston_config_section_get_string(section, |
| 588 | "path", &shell->screensaver.path, NULL); |
| 589 | weston_config_section_get_int(section, "duration", &duration, 60); |
Ander Conselvan de Oliveira | 859e885 | 2013-02-21 18:35:21 +0200 | [diff] [blame] | 590 | shell->screensaver.duration = duration * 1000; |
Kristian Høgsberg | 673a889 | 2013-05-23 21:40:56 -0400 | [diff] [blame] | 591 | |
| 592 | section = weston_config_get_section(shell->compositor->config, |
| 593 | "shell", NULL, NULL); |
| 594 | weston_config_section_get_string(section, |
Emilio Pozuelo Monfort | 8a81b83 | 2013-12-02 12:53:32 +0100 | [diff] [blame] | 595 | "client", &s, LIBEXECDIR "/" WESTON_SHELL_CLIENT); |
Emilio Pozuelo Monfort | 46ce798 | 2013-11-20 13:22:29 +0100 | [diff] [blame] | 596 | shell->client = s; |
| 597 | weston_config_section_get_string(section, |
Kristian Høgsberg | 673a889 | 2013-05-23 21:40:56 -0400 | [diff] [blame] | 598 | "binding-modifier", &s, "super"); |
| 599 | shell->binding_modifier = get_modifier(s); |
Quentin Glidic | 8418c29 | 2013-06-18 09:11:03 +0200 | [diff] [blame] | 600 | free(s); |
Kristian Høgsberg | 673a889 | 2013-05-23 21:40:56 -0400 | [diff] [blame] | 601 | weston_config_section_get_string(section, "animation", &s, "none"); |
| 602 | shell->win_animation_type = get_animation_type(s); |
Quentin Glidic | 8418c29 | 2013-06-18 09:11:03 +0200 | [diff] [blame] | 603 | free(s); |
Kristian Høgsberg | 724c8d9 | 2013-10-16 11:38:24 -0700 | [diff] [blame] | 604 | weston_config_section_get_string(section, |
| 605 | "startup-animation", &s, "fade"); |
| 606 | shell->startup_animation_type = get_animation_type(s); |
| 607 | free(s); |
Kristian Høgsberg | 912e0a1 | 2013-10-30 08:59:55 -0700 | [diff] [blame] | 608 | if (shell->startup_animation_type == ANIMATION_ZOOM) |
| 609 | shell->startup_animation_type = ANIMATION_NONE; |
Louis-Francis Ratté-Boulianne | b482dbd | 2013-11-19 11:37:11 +0100 | [diff] [blame] | 610 | weston_config_section_get_string(section, "focus-animation", &s, "none"); |
| 611 | shell->focus_animation_type = get_animation_type(s); |
| 612 | free(s); |
Kristian Høgsberg | 673a889 | 2013-05-23 21:40:56 -0400 | [diff] [blame] | 613 | weston_config_section_get_uint(section, "num-workspaces", |
| 614 | &shell->workspaces.num, |
| 615 | DEFAULT_NUM_WORKSPACES); |
Jonas Ådahl | e3cddce | 2012-06-13 00:01:22 +0200 | [diff] [blame] | 616 | } |
| 617 | |
Louis-Francis Ratté-Boulianne | b482dbd | 2013-11-19 11:37:11 +0100 | [diff] [blame] | 618 | static struct weston_output * |
| 619 | get_default_output(struct weston_compositor *compositor) |
| 620 | { |
| 621 | return container_of(compositor->output_list.next, |
| 622 | struct weston_output, link); |
| 623 | } |
| 624 | |
| 625 | |
| 626 | /* no-op func for checking focus surface */ |
| 627 | static void |
Jason Ekstrand | 918f2dd | 2013-12-02 21:01:53 -0600 | [diff] [blame] | 628 | 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] | 629 | { |
| 630 | } |
| 631 | |
| 632 | static struct focus_surface * |
| 633 | get_focus_surface(struct weston_surface *surface) |
| 634 | { |
| 635 | if (surface->configure == focus_surface_configure) |
| 636 | return surface->configure_private; |
| 637 | else |
| 638 | return NULL; |
| 639 | } |
| 640 | |
| 641 | static bool |
| 642 | is_focus_surface (struct weston_surface *es) |
| 643 | { |
| 644 | return (es->configure == focus_surface_configure); |
| 645 | } |
| 646 | |
| 647 | static bool |
| 648 | is_focus_view (struct weston_view *view) |
| 649 | { |
| 650 | return is_focus_surface (view->surface); |
| 651 | } |
| 652 | |
| 653 | static struct focus_surface * |
| 654 | create_focus_surface(struct weston_compositor *ec, |
| 655 | struct weston_output *output) |
| 656 | { |
| 657 | struct focus_surface *fsurf = NULL; |
| 658 | struct weston_surface *surface = NULL; |
| 659 | |
| 660 | fsurf = malloc(sizeof *fsurf); |
| 661 | if (!fsurf) |
| 662 | return NULL; |
| 663 | |
| 664 | fsurf->surface = weston_surface_create(ec); |
| 665 | surface = fsurf->surface; |
| 666 | if (surface == NULL) { |
| 667 | free(fsurf); |
| 668 | return NULL; |
| 669 | } |
| 670 | |
| 671 | surface->configure = focus_surface_configure; |
| 672 | surface->output = output; |
| 673 | surface->configure_private = fsurf; |
| 674 | |
| 675 | fsurf->view = weston_view_create (surface); |
Emilio Pozuelo Monfort | da64426 | 2013-11-19 11:37:19 +0100 | [diff] [blame] | 676 | fsurf->view->output = output; |
Louis-Francis Ratté-Boulianne | b482dbd | 2013-11-19 11:37:11 +0100 | [diff] [blame] | 677 | |
Jason Ekstrand | 918f2dd | 2013-12-02 21:01:53 -0600 | [diff] [blame] | 678 | surface->width = output->width; |
| 679 | surface->height = output->height; |
| 680 | weston_view_set_position(fsurf->view, output->x, output->y); |
Louis-Francis Ratté-Boulianne | b482dbd | 2013-11-19 11:37:11 +0100 | [diff] [blame] | 681 | weston_surface_set_color(surface, 0.0, 0.0, 0.0, 1.0); |
| 682 | pixman_region32_fini(&surface->opaque); |
| 683 | pixman_region32_init_rect(&surface->opaque, output->x, output->y, |
| 684 | output->width, output->height); |
| 685 | pixman_region32_fini(&surface->input); |
| 686 | pixman_region32_init(&surface->input); |
| 687 | |
| 688 | wl_list_init(&fsurf->workspace_transform.link); |
| 689 | |
| 690 | return fsurf; |
| 691 | } |
| 692 | |
| 693 | static void |
| 694 | focus_surface_destroy(struct focus_surface *fsurf) |
| 695 | { |
| 696 | weston_surface_destroy(fsurf->surface); |
| 697 | free(fsurf); |
| 698 | } |
| 699 | |
| 700 | static void |
| 701 | focus_animation_done(struct weston_view_animation *animation, void *data) |
| 702 | { |
| 703 | struct workspace *ws = data; |
| 704 | |
| 705 | ws->focus_animation = NULL; |
| 706 | } |
| 707 | |
Jonas Ådahl | e3cddce | 2012-06-13 00:01:22 +0200 | [diff] [blame] | 708 | static void |
Jonas Ådahl | 0476974 | 2012-06-13 00:01:24 +0200 | [diff] [blame] | 709 | focus_state_destroy(struct focus_state *state) |
| 710 | { |
| 711 | wl_list_remove(&state->seat_destroy_listener.link); |
| 712 | wl_list_remove(&state->surface_destroy_listener.link); |
| 713 | free(state); |
| 714 | } |
| 715 | |
| 716 | static void |
| 717 | focus_state_seat_destroy(struct wl_listener *listener, void *data) |
| 718 | { |
| 719 | struct focus_state *state = container_of(listener, |
| 720 | struct focus_state, |
| 721 | seat_destroy_listener); |
| 722 | |
| 723 | wl_list_remove(&state->link); |
| 724 | focus_state_destroy(state); |
| 725 | } |
| 726 | |
| 727 | static void |
| 728 | focus_state_surface_destroy(struct wl_listener *listener, void *data) |
| 729 | { |
| 730 | struct focus_state *state = container_of(listener, |
| 731 | struct focus_state, |
Kristian Høgsberg | b8e0d0f | 2012-07-31 10:30:26 -0400 | [diff] [blame] | 732 | surface_destroy_listener); |
Kristian Høgsberg | e377822 | 2012-07-31 17:29:30 -0400 | [diff] [blame] | 733 | struct desktop_shell *shell; |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 734 | struct weston_surface *main_surface, *next; |
| 735 | struct weston_view *view; |
Jonas Ådahl | 0476974 | 2012-06-13 00:01:24 +0200 | [diff] [blame] | 736 | |
Pekka Paalanen | 01388e2 | 2013-04-25 13:57:44 +0300 | [diff] [blame] | 737 | main_surface = weston_surface_get_main_surface(state->keyboard_focus); |
| 738 | |
Kristian Høgsberg | e377822 | 2012-07-31 17:29:30 -0400 | [diff] [blame] | 739 | next = NULL; |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 740 | wl_list_for_each(view, &state->ws->layer.view_list, layer_link) { |
| 741 | if (view->surface == main_surface) |
Kristian Høgsberg | e377822 | 2012-07-31 17:29:30 -0400 | [diff] [blame] | 742 | continue; |
Louis-Francis Ratté-Boulianne | b482dbd | 2013-11-19 11:37:11 +0100 | [diff] [blame] | 743 | if (is_focus_view(view)) |
| 744 | continue; |
Kristian Høgsberg | e377822 | 2012-07-31 17:29:30 -0400 | [diff] [blame] | 745 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 746 | next = view->surface; |
Kristian Høgsberg | e377822 | 2012-07-31 17:29:30 -0400 | [diff] [blame] | 747 | break; |
| 748 | } |
| 749 | |
Pekka Paalanen | 01388e2 | 2013-04-25 13:57:44 +0300 | [diff] [blame] | 750 | /* if the focus was a sub-surface, activate its main surface */ |
| 751 | if (main_surface != state->keyboard_focus) |
| 752 | next = main_surface; |
| 753 | |
Louis-Francis Ratté-Boulianne | b482dbd | 2013-11-19 11:37:11 +0100 | [diff] [blame] | 754 | shell = state->seat->compositor->shell_interface.shell; |
Kristian Høgsberg | e377822 | 2012-07-31 17:29:30 -0400 | [diff] [blame] | 755 | if (next) { |
Louis-Francis Ratté-Boulianne | b482dbd | 2013-11-19 11:37:11 +0100 | [diff] [blame] | 756 | state->keyboard_focus = NULL; |
Kristian Høgsberg | e377822 | 2012-07-31 17:29:30 -0400 | [diff] [blame] | 757 | activate(shell, next, state->seat); |
| 758 | } else { |
Louis-Francis Ratté-Boulianne | b482dbd | 2013-11-19 11:37:11 +0100 | [diff] [blame] | 759 | if (shell->focus_animation_type == ANIMATION_DIM_LAYER) { |
| 760 | if (state->ws->focus_animation) |
| 761 | weston_view_animation_destroy(state->ws->focus_animation); |
| 762 | |
| 763 | state->ws->focus_animation = weston_fade_run( |
| 764 | state->ws->fsurf_front->view, |
| 765 | state->ws->fsurf_front->view->alpha, 0.0, 300, |
| 766 | focus_animation_done, state->ws); |
| 767 | } |
| 768 | |
Kristian Høgsberg | e377822 | 2012-07-31 17:29:30 -0400 | [diff] [blame] | 769 | wl_list_remove(&state->link); |
| 770 | focus_state_destroy(state); |
| 771 | } |
Jonas Ådahl | 0476974 | 2012-06-13 00:01:24 +0200 | [diff] [blame] | 772 | } |
| 773 | |
| 774 | static struct focus_state * |
Kristian Høgsberg | 2f5faff | 2012-07-31 16:36:34 -0400 | [diff] [blame] | 775 | focus_state_create(struct weston_seat *seat, struct workspace *ws) |
Jonas Ådahl | 0476974 | 2012-06-13 00:01:24 +0200 | [diff] [blame] | 776 | { |
Jonas Ådahl | 0476974 | 2012-06-13 00:01:24 +0200 | [diff] [blame] | 777 | struct focus_state *state; |
Jonas Ådahl | 0476974 | 2012-06-13 00:01:24 +0200 | [diff] [blame] | 778 | |
| 779 | state = malloc(sizeof *state); |
| 780 | if (state == NULL) |
| 781 | return NULL; |
| 782 | |
Louis-Francis Ratté-Boulianne | b482dbd | 2013-11-19 11:37:11 +0100 | [diff] [blame] | 783 | state->keyboard_focus = NULL; |
Kristian Høgsberg | 2f5faff | 2012-07-31 16:36:34 -0400 | [diff] [blame] | 784 | state->ws = ws; |
Jonas Ådahl | 0476974 | 2012-06-13 00:01:24 +0200 | [diff] [blame] | 785 | state->seat = seat; |
Kristian Høgsberg | 2f5faff | 2012-07-31 16:36:34 -0400 | [diff] [blame] | 786 | wl_list_insert(&ws->focus_list, &state->link); |
Jonas Ådahl | 0476974 | 2012-06-13 00:01:24 +0200 | [diff] [blame] | 787 | |
| 788 | state->seat_destroy_listener.notify = focus_state_seat_destroy; |
| 789 | state->surface_destroy_listener.notify = focus_state_surface_destroy; |
Kristian Høgsberg | 4912454 | 2013-05-06 22:27:40 -0400 | [diff] [blame] | 790 | wl_signal_add(&seat->destroy_signal, |
Jonas Ådahl | 0476974 | 2012-06-13 00:01:24 +0200 | [diff] [blame] | 791 | &state->seat_destroy_listener); |
Kristian Høgsberg | 2f5faff | 2012-07-31 16:36:34 -0400 | [diff] [blame] | 792 | wl_list_init(&state->surface_destroy_listener.link); |
Jonas Ådahl | 0476974 | 2012-06-13 00:01:24 +0200 | [diff] [blame] | 793 | |
| 794 | return state; |
| 795 | } |
| 796 | |
Jonas Ådahl | 8538b22 | 2012-08-29 22:13:03 +0200 | [diff] [blame] | 797 | static struct focus_state * |
| 798 | ensure_focus_state(struct desktop_shell *shell, struct weston_seat *seat) |
| 799 | { |
| 800 | struct workspace *ws = get_current_workspace(shell); |
| 801 | struct focus_state *state; |
| 802 | |
| 803 | wl_list_for_each(state, &ws->focus_list, link) |
| 804 | if (state->seat == seat) |
| 805 | break; |
| 806 | |
| 807 | if (&state->link == &ws->focus_list) |
| 808 | state = focus_state_create(seat, ws); |
| 809 | |
| 810 | return state; |
| 811 | } |
| 812 | |
Jonas Ådahl | 0476974 | 2012-06-13 00:01:24 +0200 | [diff] [blame] | 813 | static void |
Kristian Høgsberg | 2f5faff | 2012-07-31 16:36:34 -0400 | [diff] [blame] | 814 | restore_focus_state(struct desktop_shell *shell, struct workspace *ws) |
Jonas Ådahl | 0476974 | 2012-06-13 00:01:24 +0200 | [diff] [blame] | 815 | { |
| 816 | struct focus_state *state, *next; |
Kristian Høgsberg | fe7aa90 | 2013-05-08 09:54:37 -0400 | [diff] [blame] | 817 | struct weston_surface *surface; |
Jonas Ådahl | 0476974 | 2012-06-13 00:01:24 +0200 | [diff] [blame] | 818 | |
| 819 | wl_list_for_each_safe(state, next, &ws->focus_list, link) { |
Kristian Høgsberg | fe7aa90 | 2013-05-08 09:54:37 -0400 | [diff] [blame] | 820 | surface = state->keyboard_focus; |
Jonas Ådahl | 5689944 | 2012-08-29 22:12:59 +0200 | [diff] [blame] | 821 | |
Kristian Høgsberg | e314875 | 2013-05-06 23:19:49 -0400 | [diff] [blame] | 822 | weston_keyboard_set_focus(state->seat->keyboard, surface); |
Jonas Ådahl | 0476974 | 2012-06-13 00:01:24 +0200 | [diff] [blame] | 823 | } |
| 824 | } |
| 825 | |
| 826 | static void |
Jonas Ådahl | 8de6a1d | 2012-08-29 22:13:00 +0200 | [diff] [blame] | 827 | replace_focus_state(struct desktop_shell *shell, struct workspace *ws, |
| 828 | struct weston_seat *seat) |
| 829 | { |
| 830 | struct focus_state *state; |
Kristian Høgsberg | fe7aa90 | 2013-05-08 09:54:37 -0400 | [diff] [blame] | 831 | struct weston_surface *surface; |
Jonas Ådahl | 8de6a1d | 2012-08-29 22:13:00 +0200 | [diff] [blame] | 832 | |
| 833 | wl_list_for_each(state, &ws->focus_list, link) { |
| 834 | if (state->seat == seat) { |
Kristian Høgsberg | e314875 | 2013-05-06 23:19:49 -0400 | [diff] [blame] | 835 | surface = seat->keyboard->focus; |
Jason Ekstrand | 651f00e | 2013-06-14 10:07:54 -0500 | [diff] [blame] | 836 | state->keyboard_focus = surface; |
Jonas Ådahl | 8de6a1d | 2012-08-29 22:13:00 +0200 | [diff] [blame] | 837 | return; |
| 838 | } |
| 839 | } |
| 840 | } |
| 841 | |
| 842 | static void |
| 843 | drop_focus_state(struct desktop_shell *shell, struct workspace *ws, |
| 844 | struct weston_surface *surface) |
| 845 | { |
| 846 | struct focus_state *state; |
| 847 | |
| 848 | wl_list_for_each(state, &ws->focus_list, link) |
| 849 | if (state->keyboard_focus == surface) |
| 850 | state->keyboard_focus = NULL; |
| 851 | } |
| 852 | |
| 853 | static void |
Louis-Francis Ratté-Boulianne | b482dbd | 2013-11-19 11:37:11 +0100 | [diff] [blame] | 854 | animate_focus_change(struct desktop_shell *shell, struct workspace *ws, |
| 855 | struct weston_view *from, struct weston_view *to) |
| 856 | { |
| 857 | struct weston_output *output; |
| 858 | bool focus_surface_created = false; |
| 859 | |
| 860 | /* FIXME: Only support dim animation using two layers */ |
| 861 | if (from == to || shell->focus_animation_type != ANIMATION_DIM_LAYER) |
| 862 | return; |
| 863 | |
| 864 | output = get_default_output(shell->compositor); |
| 865 | if (ws->fsurf_front == NULL && (from || to)) { |
| 866 | ws->fsurf_front = create_focus_surface(shell->compositor, output); |
| 867 | ws->fsurf_back = create_focus_surface(shell->compositor, output); |
| 868 | ws->fsurf_front->view->alpha = 0.0; |
| 869 | ws->fsurf_back->view->alpha = 0.0; |
| 870 | focus_surface_created = true; |
| 871 | } else { |
| 872 | wl_list_remove(&ws->fsurf_front->view->layer_link); |
| 873 | wl_list_remove(&ws->fsurf_back->view->layer_link); |
| 874 | } |
| 875 | |
| 876 | if (ws->focus_animation) { |
| 877 | weston_view_animation_destroy(ws->focus_animation); |
| 878 | ws->focus_animation = NULL; |
| 879 | } |
| 880 | |
| 881 | if (to) |
| 882 | wl_list_insert(&to->layer_link, |
| 883 | &ws->fsurf_front->view->layer_link); |
| 884 | else if (from) |
| 885 | wl_list_insert(&ws->layer.view_list, |
| 886 | &ws->fsurf_front->view->layer_link); |
| 887 | |
| 888 | if (focus_surface_created) { |
| 889 | ws->focus_animation = weston_fade_run( |
| 890 | ws->fsurf_front->view, |
| 891 | ws->fsurf_front->view->alpha, 0.6, 300, |
| 892 | focus_animation_done, ws); |
| 893 | } else if (from) { |
| 894 | wl_list_insert(&from->layer_link, |
| 895 | &ws->fsurf_back->view->layer_link); |
| 896 | ws->focus_animation = weston_stable_fade_run( |
| 897 | ws->fsurf_front->view, 0.0, |
| 898 | ws->fsurf_back->view, 0.6, |
| 899 | focus_animation_done, ws); |
| 900 | } else if (to) { |
| 901 | wl_list_insert(&ws->layer.view_list, |
| 902 | &ws->fsurf_back->view->layer_link); |
| 903 | ws->focus_animation = weston_stable_fade_run( |
| 904 | ws->fsurf_front->view, 0.0, |
| 905 | ws->fsurf_back->view, 0.6, |
| 906 | focus_animation_done, ws); |
| 907 | } |
| 908 | } |
| 909 | |
| 910 | static void |
Jonas Ådahl | e3cddce | 2012-06-13 00:01:22 +0200 | [diff] [blame] | 911 | workspace_destroy(struct workspace *ws) |
| 912 | { |
Jonas Ådahl | 0476974 | 2012-06-13 00:01:24 +0200 | [diff] [blame] | 913 | struct focus_state *state, *next; |
| 914 | |
| 915 | wl_list_for_each_safe(state, next, &ws->focus_list, link) |
| 916 | focus_state_destroy(state); |
| 917 | |
Louis-Francis Ratté-Boulianne | b482dbd | 2013-11-19 11:37:11 +0100 | [diff] [blame] | 918 | if (ws->fsurf_front) |
| 919 | focus_surface_destroy(ws->fsurf_front); |
| 920 | if (ws->fsurf_back) |
| 921 | focus_surface_destroy(ws->fsurf_back); |
| 922 | |
Jonas Ådahl | e3cddce | 2012-06-13 00:01:22 +0200 | [diff] [blame] | 923 | free(ws); |
| 924 | } |
| 925 | |
Jonas Ådahl | 0476974 | 2012-06-13 00:01:24 +0200 | [diff] [blame] | 926 | static void |
| 927 | seat_destroyed(struct wl_listener *listener, void *data) |
| 928 | { |
| 929 | struct weston_seat *seat = data; |
| 930 | struct focus_state *state, *next; |
| 931 | struct workspace *ws = container_of(listener, |
| 932 | struct workspace, |
| 933 | seat_destroyed_listener); |
| 934 | |
| 935 | wl_list_for_each_safe(state, next, &ws->focus_list, link) |
| 936 | if (state->seat == seat) |
| 937 | wl_list_remove(&state->link); |
| 938 | } |
| 939 | |
Jonas Ådahl | e3cddce | 2012-06-13 00:01:22 +0200 | [diff] [blame] | 940 | static struct workspace * |
| 941 | workspace_create(void) |
| 942 | { |
| 943 | struct workspace *ws = malloc(sizeof *ws); |
| 944 | if (ws == NULL) |
| 945 | return NULL; |
| 946 | |
| 947 | weston_layer_init(&ws->layer, NULL); |
| 948 | |
Jonas Ådahl | 0476974 | 2012-06-13 00:01:24 +0200 | [diff] [blame] | 949 | wl_list_init(&ws->focus_list); |
| 950 | wl_list_init(&ws->seat_destroyed_listener.link); |
| 951 | ws->seat_destroyed_listener.notify = seat_destroyed; |
Louis-Francis Ratté-Boulianne | b482dbd | 2013-11-19 11:37:11 +0100 | [diff] [blame] | 952 | ws->fsurf_front = NULL; |
| 953 | ws->fsurf_back = NULL; |
| 954 | ws->focus_animation = NULL; |
Jonas Ådahl | 0476974 | 2012-06-13 00:01:24 +0200 | [diff] [blame] | 955 | |
Jonas Ådahl | e3cddce | 2012-06-13 00:01:22 +0200 | [diff] [blame] | 956 | return ws; |
| 957 | } |
| 958 | |
Jonas Ådahl | 62fcd04 | 2012-06-13 00:01:23 +0200 | [diff] [blame] | 959 | static int |
| 960 | workspace_is_empty(struct workspace *ws) |
| 961 | { |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 962 | return wl_list_empty(&ws->layer.view_list); |
Jonas Ådahl | 62fcd04 | 2012-06-13 00:01:23 +0200 | [diff] [blame] | 963 | } |
| 964 | |
Jonas Ådahl | e3cddce | 2012-06-13 00:01:22 +0200 | [diff] [blame] | 965 | static struct workspace * |
| 966 | get_workspace(struct desktop_shell *shell, unsigned int index) |
| 967 | { |
| 968 | struct workspace **pws = shell->workspaces.array.data; |
Philipp Brüschweiler | 067abf6 | 2012-09-01 16:03:05 +0200 | [diff] [blame] | 969 | assert(index < shell->workspaces.num); |
Jonas Ådahl | e3cddce | 2012-06-13 00:01:22 +0200 | [diff] [blame] | 970 | pws += index; |
| 971 | return *pws; |
| 972 | } |
| 973 | |
| 974 | static struct workspace * |
| 975 | get_current_workspace(struct desktop_shell *shell) |
| 976 | { |
| 977 | return get_workspace(shell, shell->workspaces.current); |
| 978 | } |
| 979 | |
| 980 | static void |
| 981 | activate_workspace(struct desktop_shell *shell, unsigned int index) |
| 982 | { |
| 983 | struct workspace *ws; |
| 984 | |
| 985 | ws = get_workspace(shell, index); |
| 986 | wl_list_insert(&shell->panel_layer.link, &ws->layer.link); |
| 987 | |
| 988 | shell->workspaces.current = index; |
| 989 | } |
| 990 | |
Jonas Ådahl | 62fcd04 | 2012-06-13 00:01:23 +0200 | [diff] [blame] | 991 | static unsigned int |
| 992 | get_output_height(struct weston_output *output) |
| 993 | { |
| 994 | return abs(output->region.extents.y1 - output->region.extents.y2); |
| 995 | } |
| 996 | |
| 997 | static void |
Louis-Francis Ratté-Boulianne | b482dbd | 2013-11-19 11:37:11 +0100 | [diff] [blame] | 998 | view_translate(struct workspace *ws, struct weston_view *view, double d) |
Jonas Ådahl | 62fcd04 | 2012-06-13 00:01:23 +0200 | [diff] [blame] | 999 | { |
Jonas Ådahl | 62fcd04 | 2012-06-13 00:01:23 +0200 | [diff] [blame] | 1000 | struct weston_transform *transform; |
| 1001 | |
Louis-Francis Ratté-Boulianne | b482dbd | 2013-11-19 11:37:11 +0100 | [diff] [blame] | 1002 | if (is_focus_view(view)) { |
| 1003 | struct focus_surface *fsurf = get_focus_surface(view->surface); |
| 1004 | transform = &fsurf->workspace_transform; |
| 1005 | } else { |
| 1006 | struct shell_surface *shsurf = get_shell_surface(view->surface); |
| 1007 | transform = &shsurf->workspace_transform; |
| 1008 | } |
| 1009 | |
Jonas Ådahl | 62fcd04 | 2012-06-13 00:01:23 +0200 | [diff] [blame] | 1010 | if (wl_list_empty(&transform->link)) |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 1011 | wl_list_insert(view->geometry.transformation_list.prev, |
Louis-Francis Ratté-Boulianne | b482dbd | 2013-11-19 11:37:11 +0100 | [diff] [blame] | 1012 | &transform->link); |
Jonas Ådahl | 62fcd04 | 2012-06-13 00:01:23 +0200 | [diff] [blame] | 1013 | |
Louis-Francis Ratté-Boulianne | b482dbd | 2013-11-19 11:37:11 +0100 | [diff] [blame] | 1014 | weston_matrix_init(&transform->matrix); |
| 1015 | weston_matrix_translate(&transform->matrix, |
Jonas Ådahl | 62fcd04 | 2012-06-13 00:01:23 +0200 | [diff] [blame] | 1016 | 0.0, d, 0.0); |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 1017 | weston_view_geometry_dirty(view); |
Jonas Ådahl | 62fcd04 | 2012-06-13 00:01:23 +0200 | [diff] [blame] | 1018 | } |
| 1019 | |
| 1020 | static void |
| 1021 | workspace_translate_out(struct workspace *ws, double fraction) |
| 1022 | { |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 1023 | struct weston_view *view; |
Jonas Ådahl | 62fcd04 | 2012-06-13 00:01:23 +0200 | [diff] [blame] | 1024 | unsigned int height; |
| 1025 | double d; |
| 1026 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 1027 | wl_list_for_each(view, &ws->layer.view_list, layer_link) { |
| 1028 | height = get_output_height(view->surface->output); |
Jonas Ådahl | 62fcd04 | 2012-06-13 00:01:23 +0200 | [diff] [blame] | 1029 | d = height * fraction; |
| 1030 | |
Louis-Francis Ratté-Boulianne | b482dbd | 2013-11-19 11:37:11 +0100 | [diff] [blame] | 1031 | view_translate(ws, view, d); |
Jonas Ådahl | 62fcd04 | 2012-06-13 00:01:23 +0200 | [diff] [blame] | 1032 | } |
| 1033 | } |
| 1034 | |
| 1035 | static void |
| 1036 | workspace_translate_in(struct workspace *ws, double fraction) |
| 1037 | { |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 1038 | struct weston_view *view; |
Jonas Ådahl | 62fcd04 | 2012-06-13 00:01:23 +0200 | [diff] [blame] | 1039 | unsigned int height; |
| 1040 | double d; |
| 1041 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 1042 | wl_list_for_each(view, &ws->layer.view_list, layer_link) { |
| 1043 | height = get_output_height(view->surface->output); |
Jonas Ådahl | 62fcd04 | 2012-06-13 00:01:23 +0200 | [diff] [blame] | 1044 | |
| 1045 | if (fraction > 0) |
| 1046 | d = -(height - height * fraction); |
| 1047 | else |
| 1048 | d = height + height * fraction; |
| 1049 | |
Louis-Francis Ratté-Boulianne | b482dbd | 2013-11-19 11:37:11 +0100 | [diff] [blame] | 1050 | view_translate(ws, view, d); |
Jonas Ådahl | 62fcd04 | 2012-06-13 00:01:23 +0200 | [diff] [blame] | 1051 | } |
| 1052 | } |
| 1053 | |
| 1054 | static void |
Jonas Ådahl | e9d2250 | 2012-08-29 22:13:01 +0200 | [diff] [blame] | 1055 | broadcast_current_workspace_state(struct desktop_shell *shell) |
| 1056 | { |
Kristian Høgsberg | 2e3c396 | 2013-09-11 12:00:47 -0700 | [diff] [blame] | 1057 | struct wl_resource *resource; |
Jonas Ådahl | e9d2250 | 2012-08-29 22:13:01 +0200 | [diff] [blame] | 1058 | |
Kristian Høgsberg | 2e3c396 | 2013-09-11 12:00:47 -0700 | [diff] [blame] | 1059 | wl_resource_for_each(resource, &shell->workspaces.client_list) |
| 1060 | workspace_manager_send_state(resource, |
Jonas Ådahl | e9d2250 | 2012-08-29 22:13:01 +0200 | [diff] [blame] | 1061 | shell->workspaces.current, |
| 1062 | shell->workspaces.num); |
| 1063 | } |
| 1064 | |
| 1065 | static void |
Jonas Ådahl | 62fcd04 | 2012-06-13 00:01:23 +0200 | [diff] [blame] | 1066 | reverse_workspace_change_animation(struct desktop_shell *shell, |
| 1067 | unsigned int index, |
| 1068 | struct workspace *from, |
| 1069 | struct workspace *to) |
| 1070 | { |
| 1071 | shell->workspaces.current = index; |
| 1072 | |
| 1073 | shell->workspaces.anim_to = to; |
| 1074 | shell->workspaces.anim_from = from; |
| 1075 | shell->workspaces.anim_dir = -1 * shell->workspaces.anim_dir; |
| 1076 | shell->workspaces.anim_timestamp = 0; |
| 1077 | |
Scott Moreau | 4272e63 | 2012-08-13 09:58:41 -0600 | [diff] [blame] | 1078 | weston_compositor_schedule_repaint(shell->compositor); |
Jonas Ådahl | 62fcd04 | 2012-06-13 00:01:23 +0200 | [diff] [blame] | 1079 | } |
| 1080 | |
| 1081 | static void |
| 1082 | workspace_deactivate_transforms(struct workspace *ws) |
| 1083 | { |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 1084 | struct weston_view *view; |
Louis-Francis Ratté-Boulianne | b482dbd | 2013-11-19 11:37:11 +0100 | [diff] [blame] | 1085 | struct weston_transform *transform; |
Jonas Ådahl | 62fcd04 | 2012-06-13 00:01:23 +0200 | [diff] [blame] | 1086 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 1087 | 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] | 1088 | if (is_focus_view(view)) { |
| 1089 | struct focus_surface *fsurf = get_focus_surface(view->surface); |
| 1090 | transform = &fsurf->workspace_transform; |
| 1091 | } else { |
| 1092 | struct shell_surface *shsurf = get_shell_surface(view->surface); |
| 1093 | transform = &shsurf->workspace_transform; |
| 1094 | } |
| 1095 | |
| 1096 | if (!wl_list_empty(&transform->link)) { |
| 1097 | wl_list_remove(&transform->link); |
| 1098 | wl_list_init(&transform->link); |
Jonas Ådahl | 8de6a1d | 2012-08-29 22:13:00 +0200 | [diff] [blame] | 1099 | } |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 1100 | weston_view_geometry_dirty(view); |
Jonas Ådahl | 62fcd04 | 2012-06-13 00:01:23 +0200 | [diff] [blame] | 1101 | } |
| 1102 | } |
| 1103 | |
| 1104 | static void |
| 1105 | finish_workspace_change_animation(struct desktop_shell *shell, |
| 1106 | struct workspace *from, |
| 1107 | struct workspace *to) |
| 1108 | { |
Scott Moreau | 4272e63 | 2012-08-13 09:58:41 -0600 | [diff] [blame] | 1109 | weston_compositor_schedule_repaint(shell->compositor); |
Jonas Ådahl | 62fcd04 | 2012-06-13 00:01:23 +0200 | [diff] [blame] | 1110 | |
| 1111 | wl_list_remove(&shell->workspaces.animation.link); |
| 1112 | workspace_deactivate_transforms(from); |
| 1113 | workspace_deactivate_transforms(to); |
| 1114 | shell->workspaces.anim_to = NULL; |
| 1115 | |
| 1116 | wl_list_remove(&shell->workspaces.anim_from->layer.link); |
| 1117 | } |
| 1118 | |
| 1119 | static void |
| 1120 | animate_workspace_change_frame(struct weston_animation *animation, |
| 1121 | struct weston_output *output, uint32_t msecs) |
| 1122 | { |
| 1123 | struct desktop_shell *shell = |
| 1124 | container_of(animation, struct desktop_shell, |
| 1125 | workspaces.animation); |
| 1126 | struct workspace *from = shell->workspaces.anim_from; |
| 1127 | struct workspace *to = shell->workspaces.anim_to; |
| 1128 | uint32_t t; |
| 1129 | double x, y; |
| 1130 | |
| 1131 | if (workspace_is_empty(from) && workspace_is_empty(to)) { |
| 1132 | finish_workspace_change_animation(shell, from, to); |
| 1133 | return; |
| 1134 | } |
| 1135 | |
| 1136 | if (shell->workspaces.anim_timestamp == 0) { |
| 1137 | if (shell->workspaces.anim_current == 0.0) |
| 1138 | shell->workspaces.anim_timestamp = msecs; |
| 1139 | else |
| 1140 | shell->workspaces.anim_timestamp = |
| 1141 | msecs - |
| 1142 | /* Invers of movement function 'y' below. */ |
| 1143 | (asin(1.0 - shell->workspaces.anim_current) * |
| 1144 | DEFAULT_WORKSPACE_CHANGE_ANIMATION_LENGTH * |
| 1145 | M_2_PI); |
| 1146 | } |
| 1147 | |
| 1148 | t = msecs - shell->workspaces.anim_timestamp; |
| 1149 | |
| 1150 | /* |
| 1151 | * x = [0, π/2] |
| 1152 | * y(x) = sin(x) |
| 1153 | */ |
| 1154 | x = t * (1.0/DEFAULT_WORKSPACE_CHANGE_ANIMATION_LENGTH) * M_PI_2; |
| 1155 | y = sin(x); |
| 1156 | |
| 1157 | if (t < DEFAULT_WORKSPACE_CHANGE_ANIMATION_LENGTH) { |
Scott Moreau | 4272e63 | 2012-08-13 09:58:41 -0600 | [diff] [blame] | 1158 | weston_compositor_schedule_repaint(shell->compositor); |
Jonas Ådahl | 62fcd04 | 2012-06-13 00:01:23 +0200 | [diff] [blame] | 1159 | |
| 1160 | workspace_translate_out(from, shell->workspaces.anim_dir * y); |
| 1161 | workspace_translate_in(to, shell->workspaces.anim_dir * y); |
| 1162 | shell->workspaces.anim_current = y; |
| 1163 | |
Scott Moreau | 4272e63 | 2012-08-13 09:58:41 -0600 | [diff] [blame] | 1164 | weston_compositor_schedule_repaint(shell->compositor); |
Jonas Ådahl | 62fcd04 | 2012-06-13 00:01:23 +0200 | [diff] [blame] | 1165 | } |
Jonas Ådahl | 0476974 | 2012-06-13 00:01:24 +0200 | [diff] [blame] | 1166 | else |
Jonas Ådahl | 62fcd04 | 2012-06-13 00:01:23 +0200 | [diff] [blame] | 1167 | finish_workspace_change_animation(shell, from, to); |
Jonas Ådahl | 62fcd04 | 2012-06-13 00:01:23 +0200 | [diff] [blame] | 1168 | } |
| 1169 | |
| 1170 | static void |
| 1171 | animate_workspace_change(struct desktop_shell *shell, |
| 1172 | unsigned int index, |
| 1173 | struct workspace *from, |
| 1174 | struct workspace *to) |
| 1175 | { |
| 1176 | struct weston_output *output; |
| 1177 | |
| 1178 | int dir; |
| 1179 | |
| 1180 | if (index > shell->workspaces.current) |
| 1181 | dir = -1; |
| 1182 | else |
| 1183 | dir = 1; |
| 1184 | |
| 1185 | shell->workspaces.current = index; |
| 1186 | |
| 1187 | shell->workspaces.anim_dir = dir; |
| 1188 | shell->workspaces.anim_from = from; |
| 1189 | shell->workspaces.anim_to = to; |
| 1190 | shell->workspaces.anim_current = 0.0; |
| 1191 | shell->workspaces.anim_timestamp = 0; |
| 1192 | |
| 1193 | output = container_of(shell->compositor->output_list.next, |
| 1194 | struct weston_output, link); |
| 1195 | wl_list_insert(&output->animation_list, |
| 1196 | &shell->workspaces.animation.link); |
| 1197 | |
Jonas Ådahl | 8de6a1d | 2012-08-29 22:13:00 +0200 | [diff] [blame] | 1198 | wl_list_insert(from->layer.link.prev, &to->layer.link); |
Jonas Ådahl | 62fcd04 | 2012-06-13 00:01:23 +0200 | [diff] [blame] | 1199 | |
| 1200 | workspace_translate_in(to, 0); |
| 1201 | |
Kristian Høgsberg | 2f5faff | 2012-07-31 16:36:34 -0400 | [diff] [blame] | 1202 | restore_focus_state(shell, to); |
Jonas Ådahl | 0476974 | 2012-06-13 00:01:24 +0200 | [diff] [blame] | 1203 | |
Scott Moreau | 4272e63 | 2012-08-13 09:58:41 -0600 | [diff] [blame] | 1204 | weston_compositor_schedule_repaint(shell->compositor); |
Jonas Ådahl | 62fcd04 | 2012-06-13 00:01:23 +0200 | [diff] [blame] | 1205 | } |
| 1206 | |
Jonas Ådahl | e3cddce | 2012-06-13 00:01:22 +0200 | [diff] [blame] | 1207 | static void |
Jonas Ådahl | 8de6a1d | 2012-08-29 22:13:00 +0200 | [diff] [blame] | 1208 | update_workspace(struct desktop_shell *shell, unsigned int index, |
| 1209 | struct workspace *from, struct workspace *to) |
| 1210 | { |
| 1211 | shell->workspaces.current = index; |
| 1212 | wl_list_insert(&from->layer.link, &to->layer.link); |
| 1213 | wl_list_remove(&from->layer.link); |
| 1214 | } |
| 1215 | |
| 1216 | static void |
Jonas Ådahl | e3cddce | 2012-06-13 00:01:22 +0200 | [diff] [blame] | 1217 | change_workspace(struct desktop_shell *shell, unsigned int index) |
| 1218 | { |
| 1219 | struct workspace *from; |
| 1220 | struct workspace *to; |
Louis-Francis Ratté-Boulianne | b482dbd | 2013-11-19 11:37:11 +0100 | [diff] [blame] | 1221 | struct focus_state *state; |
Jonas Ådahl | e3cddce | 2012-06-13 00:01:22 +0200 | [diff] [blame] | 1222 | |
| 1223 | if (index == shell->workspaces.current) |
| 1224 | return; |
| 1225 | |
| 1226 | /* Don't change workspace when there is any fullscreen surfaces. */ |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 1227 | if (!wl_list_empty(&shell->fullscreen_layer.view_list)) |
Jonas Ådahl | e3cddce | 2012-06-13 00:01:22 +0200 | [diff] [blame] | 1228 | return; |
| 1229 | |
Jonas Ådahl | e3cddce | 2012-06-13 00:01:22 +0200 | [diff] [blame] | 1230 | from = get_current_workspace(shell); |
| 1231 | to = get_workspace(shell, index); |
| 1232 | |
Jonas Ådahl | 62fcd04 | 2012-06-13 00:01:23 +0200 | [diff] [blame] | 1233 | if (shell->workspaces.anim_from == to && |
| 1234 | shell->workspaces.anim_to == from) { |
Jonas Ådahl | 8de6a1d | 2012-08-29 22:13:00 +0200 | [diff] [blame] | 1235 | restore_focus_state(shell, to); |
Jonas Ådahl | 62fcd04 | 2012-06-13 00:01:23 +0200 | [diff] [blame] | 1236 | reverse_workspace_change_animation(shell, index, from, to); |
Jonas Ådahl | e9d2250 | 2012-08-29 22:13:01 +0200 | [diff] [blame] | 1237 | broadcast_current_workspace_state(shell); |
Jonas Ådahl | 62fcd04 | 2012-06-13 00:01:23 +0200 | [diff] [blame] | 1238 | return; |
| 1239 | } |
Jonas Ådahl | e3cddce | 2012-06-13 00:01:22 +0200 | [diff] [blame] | 1240 | |
Jonas Ådahl | 62fcd04 | 2012-06-13 00:01:23 +0200 | [diff] [blame] | 1241 | if (shell->workspaces.anim_to != NULL) |
| 1242 | finish_workspace_change_animation(shell, |
| 1243 | shell->workspaces.anim_from, |
| 1244 | shell->workspaces.anim_to); |
| 1245 | |
Jonas Ådahl | 8de6a1d | 2012-08-29 22:13:00 +0200 | [diff] [blame] | 1246 | restore_focus_state(shell, to); |
Jonas Ådahl | 0476974 | 2012-06-13 00:01:24 +0200 | [diff] [blame] | 1247 | |
Louis-Francis Ratté-Boulianne | b482dbd | 2013-11-19 11:37:11 +0100 | [diff] [blame] | 1248 | if (shell->focus_animation_type != ANIMATION_NONE) { |
| 1249 | wl_list_for_each(state, &from->focus_list, link) |
| 1250 | if (state->keyboard_focus) |
| 1251 | animate_focus_change(shell, from, |
| 1252 | get_default_view(state->keyboard_focus), NULL); |
| 1253 | |
| 1254 | wl_list_for_each(state, &to->focus_list, link) |
| 1255 | if (state->keyboard_focus) |
| 1256 | animate_focus_change(shell, to, |
| 1257 | NULL, get_default_view(state->keyboard_focus)); |
| 1258 | } |
| 1259 | |
Jonas Ådahl | 8de6a1d | 2012-08-29 22:13:00 +0200 | [diff] [blame] | 1260 | if (workspace_is_empty(to) && workspace_is_empty(from)) |
| 1261 | update_workspace(shell, index, from, to); |
Jonas Ådahl | 62fcd04 | 2012-06-13 00:01:23 +0200 | [diff] [blame] | 1262 | else |
| 1263 | animate_workspace_change(shell, index, from, to); |
Jonas Ådahl | e9d2250 | 2012-08-29 22:13:01 +0200 | [diff] [blame] | 1264 | |
| 1265 | broadcast_current_workspace_state(shell); |
Pekka Paalanen | e955f1e | 2011-12-07 11:49:52 +0200 | [diff] [blame] | 1266 | } |
| 1267 | |
Jonas Ådahl | 8de6a1d | 2012-08-29 22:13:00 +0200 | [diff] [blame] | 1268 | static bool |
| 1269 | workspace_has_only(struct workspace *ws, struct weston_surface *surface) |
| 1270 | { |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 1271 | struct wl_list *list = &ws->layer.view_list; |
Jonas Ådahl | 8de6a1d | 2012-08-29 22:13:00 +0200 | [diff] [blame] | 1272 | struct wl_list *e; |
| 1273 | |
| 1274 | if (wl_list_empty(list)) |
| 1275 | return false; |
| 1276 | |
| 1277 | e = list->next; |
| 1278 | |
| 1279 | if (e->next != list) |
| 1280 | return false; |
| 1281 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 1282 | return container_of(e, struct weston_view, layer_link)->surface == surface; |
Jonas Ådahl | 8de6a1d | 2012-08-29 22:13:00 +0200 | [diff] [blame] | 1283 | } |
| 1284 | |
| 1285 | static void |
Philip Withnall | 659163d | 2013-11-25 18:01:36 +0000 | [diff] [blame] | 1286 | move_surface_to_workspace(struct desktop_shell *shell, |
| 1287 | struct shell_surface *shsurf, |
| 1288 | uint32_t workspace) |
Jonas Ådahl | e9d2250 | 2012-08-29 22:13:01 +0200 | [diff] [blame] | 1289 | { |
| 1290 | struct workspace *from; |
| 1291 | struct workspace *to; |
| 1292 | struct weston_seat *seat; |
Pekka Paalanen | 01388e2 | 2013-04-25 13:57:44 +0300 | [diff] [blame] | 1293 | struct weston_surface *focus; |
Philip Withnall | 659163d | 2013-11-25 18:01:36 +0000 | [diff] [blame] | 1294 | struct weston_view *view; |
Jonas Ådahl | e9d2250 | 2012-08-29 22:13:01 +0200 | [diff] [blame] | 1295 | |
| 1296 | if (workspace == shell->workspaces.current) |
| 1297 | return; |
| 1298 | |
Philip Withnall | 659163d | 2013-11-25 18:01:36 +0000 | [diff] [blame] | 1299 | view = get_default_view(shsurf->surface); |
| 1300 | if (!view) |
| 1301 | return; |
| 1302 | |
| 1303 | assert(weston_surface_get_main_surface(view->surface) == view->surface); |
| 1304 | |
Philipp Brüschweiler | 067abf6 | 2012-09-01 16:03:05 +0200 | [diff] [blame] | 1305 | if (workspace >= shell->workspaces.num) |
| 1306 | workspace = shell->workspaces.num - 1; |
| 1307 | |
Jonas Ådahl | e9d2250 | 2012-08-29 22:13:01 +0200 | [diff] [blame] | 1308 | from = get_current_workspace(shell); |
| 1309 | to = get_workspace(shell, workspace); |
| 1310 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 1311 | wl_list_remove(&view->layer_link); |
| 1312 | wl_list_insert(&to->layer.view_list, &view->layer_link); |
Jonas Ådahl | e9d2250 | 2012-08-29 22:13:01 +0200 | [diff] [blame] | 1313 | |
Philip Withnall | 648a4dd | 2013-11-25 18:01:44 +0000 | [diff] [blame] | 1314 | shell_surface_update_child_surface_layers(shsurf); |
| 1315 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 1316 | drop_focus_state(shell, from, view->surface); |
Pekka Paalanen | 01388e2 | 2013-04-25 13:57:44 +0300 | [diff] [blame] | 1317 | wl_list_for_each(seat, &shell->compositor->seat_list, link) { |
| 1318 | if (!seat->keyboard) |
| 1319 | continue; |
| 1320 | |
| 1321 | focus = weston_surface_get_main_surface(seat->keyboard->focus); |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 1322 | if (focus == view->surface) |
Kristian Høgsberg | e314875 | 2013-05-06 23:19:49 -0400 | [diff] [blame] | 1323 | weston_keyboard_set_focus(seat->keyboard, NULL); |
Pekka Paalanen | 01388e2 | 2013-04-25 13:57:44 +0300 | [diff] [blame] | 1324 | } |
Jonas Ådahl | e9d2250 | 2012-08-29 22:13:01 +0200 | [diff] [blame] | 1325 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 1326 | weston_view_damage_below(view); |
Jonas Ådahl | e9d2250 | 2012-08-29 22:13:01 +0200 | [diff] [blame] | 1327 | } |
| 1328 | |
| 1329 | static void |
Jonas Ådahl | 8de6a1d | 2012-08-29 22:13:00 +0200 | [diff] [blame] | 1330 | take_surface_to_workspace_by_seat(struct desktop_shell *shell, |
Kristian Høgsberg | e314875 | 2013-05-06 23:19:49 -0400 | [diff] [blame] | 1331 | struct weston_seat *seat, |
Jonas Ådahl | 8de6a1d | 2012-08-29 22:13:00 +0200 | [diff] [blame] | 1332 | unsigned int index) |
| 1333 | { |
Pekka Paalanen | 01388e2 | 2013-04-25 13:57:44 +0300 | [diff] [blame] | 1334 | struct weston_surface *surface; |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 1335 | struct weston_view *view; |
Jonas Ådahl | 8de6a1d | 2012-08-29 22:13:00 +0200 | [diff] [blame] | 1336 | struct shell_surface *shsurf; |
| 1337 | struct workspace *from; |
| 1338 | struct workspace *to; |
Jonas Ådahl | 8538b22 | 2012-08-29 22:13:03 +0200 | [diff] [blame] | 1339 | struct focus_state *state; |
Jonas Ådahl | 8de6a1d | 2012-08-29 22:13:00 +0200 | [diff] [blame] | 1340 | |
Pekka Paalanen | 01388e2 | 2013-04-25 13:57:44 +0300 | [diff] [blame] | 1341 | surface = weston_surface_get_main_surface(seat->keyboard->focus); |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 1342 | view = get_default_view(surface); |
| 1343 | if (view == NULL || |
Louis-Francis Ratté-Boulianne | b482dbd | 2013-11-19 11:37:11 +0100 | [diff] [blame] | 1344 | index == shell->workspaces.current || |
| 1345 | is_focus_view(view)) |
Jonas Ådahl | 8de6a1d | 2012-08-29 22:13:00 +0200 | [diff] [blame] | 1346 | return; |
| 1347 | |
| 1348 | from = get_current_workspace(shell); |
| 1349 | to = get_workspace(shell, index); |
| 1350 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 1351 | wl_list_remove(&view->layer_link); |
| 1352 | wl_list_insert(&to->layer.view_list, &view->layer_link); |
Jonas Ådahl | 8de6a1d | 2012-08-29 22:13:00 +0200 | [diff] [blame] | 1353 | |
Philip Withnall | 659163d | 2013-11-25 18:01:36 +0000 | [diff] [blame] | 1354 | shsurf = get_shell_surface(surface); |
Philip Withnall | 648a4dd | 2013-11-25 18:01:44 +0000 | [diff] [blame] | 1355 | if (shsurf != NULL) |
| 1356 | shell_surface_update_child_surface_layers(shsurf); |
Philip Withnall | 659163d | 2013-11-25 18:01:36 +0000 | [diff] [blame] | 1357 | |
Jonas Ådahl | e9d2250 | 2012-08-29 22:13:01 +0200 | [diff] [blame] | 1358 | replace_focus_state(shell, to, seat); |
Jonas Ådahl | 8de6a1d | 2012-08-29 22:13:00 +0200 | [diff] [blame] | 1359 | drop_focus_state(shell, from, surface); |
| 1360 | |
| 1361 | if (shell->workspaces.anim_from == to && |
| 1362 | shell->workspaces.anim_to == from) { |
Jonas Ådahl | e9d2250 | 2012-08-29 22:13:01 +0200 | [diff] [blame] | 1363 | wl_list_remove(&to->layer.link); |
| 1364 | wl_list_insert(from->layer.link.prev, &to->layer.link); |
| 1365 | |
Jonas Ådahl | 8de6a1d | 2012-08-29 22:13:00 +0200 | [diff] [blame] | 1366 | reverse_workspace_change_animation(shell, index, from, to); |
Jonas Ådahl | e9d2250 | 2012-08-29 22:13:01 +0200 | [diff] [blame] | 1367 | broadcast_current_workspace_state(shell); |
| 1368 | |
Jonas Ådahl | 8de6a1d | 2012-08-29 22:13:00 +0200 | [diff] [blame] | 1369 | return; |
| 1370 | } |
| 1371 | |
| 1372 | if (shell->workspaces.anim_to != NULL) |
| 1373 | finish_workspace_change_animation(shell, |
| 1374 | shell->workspaces.anim_from, |
| 1375 | shell->workspaces.anim_to); |
| 1376 | |
| 1377 | if (workspace_is_empty(from) && |
| 1378 | workspace_has_only(to, surface)) |
| 1379 | update_workspace(shell, index, from, to); |
| 1380 | else { |
Philip Withnall | 2c3849b | 2013-11-25 18:01:45 +0000 | [diff] [blame] | 1381 | if (shsurf != NULL && |
| 1382 | wl_list_empty(&shsurf->workspace_transform.link)) |
Jonas Ådahl | 8de6a1d | 2012-08-29 22:13:00 +0200 | [diff] [blame] | 1383 | wl_list_insert(&shell->workspaces.anim_sticky_list, |
| 1384 | &shsurf->workspace_transform.link); |
| 1385 | |
| 1386 | animate_workspace_change(shell, index, from, to); |
| 1387 | } |
Jonas Ådahl | e9d2250 | 2012-08-29 22:13:01 +0200 | [diff] [blame] | 1388 | |
| 1389 | broadcast_current_workspace_state(shell); |
Jonas Ådahl | 8538b22 | 2012-08-29 22:13:03 +0200 | [diff] [blame] | 1390 | |
| 1391 | state = ensure_focus_state(shell, seat); |
| 1392 | if (state != NULL) |
| 1393 | state->keyboard_focus = surface; |
Jonas Ådahl | e9d2250 | 2012-08-29 22:13:01 +0200 | [diff] [blame] | 1394 | } |
| 1395 | |
| 1396 | static void |
| 1397 | workspace_manager_move_surface(struct wl_client *client, |
| 1398 | struct wl_resource *resource, |
| 1399 | struct wl_resource *surface_resource, |
| 1400 | uint32_t workspace) |
| 1401 | { |
Jason Ekstrand | 651f00e | 2013-06-14 10:07:54 -0500 | [diff] [blame] | 1402 | struct desktop_shell *shell = wl_resource_get_user_data(resource); |
Jonas Ådahl | e9d2250 | 2012-08-29 22:13:01 +0200 | [diff] [blame] | 1403 | struct weston_surface *surface = |
Jason Ekstrand | 0f2ef7e | 2013-06-14 10:07:53 -0500 | [diff] [blame] | 1404 | wl_resource_get_user_data(surface_resource); |
Pekka Paalanen | 01388e2 | 2013-04-25 13:57:44 +0300 | [diff] [blame] | 1405 | struct weston_surface *main_surface; |
Philip Withnall | 659163d | 2013-11-25 18:01:36 +0000 | [diff] [blame] | 1406 | struct shell_surface *shell_surface; |
Jonas Ådahl | e9d2250 | 2012-08-29 22:13:01 +0200 | [diff] [blame] | 1407 | |
Pekka Paalanen | 01388e2 | 2013-04-25 13:57:44 +0300 | [diff] [blame] | 1408 | main_surface = weston_surface_get_main_surface(surface); |
Philip Withnall | 659163d | 2013-11-25 18:01:36 +0000 | [diff] [blame] | 1409 | shell_surface = get_shell_surface(main_surface); |
| 1410 | if (shell_surface == NULL) |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 1411 | return; |
Philip Withnall | 659163d | 2013-11-25 18:01:36 +0000 | [diff] [blame] | 1412 | |
| 1413 | move_surface_to_workspace(shell, shell_surface, workspace); |
Jonas Ådahl | e9d2250 | 2012-08-29 22:13:01 +0200 | [diff] [blame] | 1414 | } |
| 1415 | |
| 1416 | static const struct workspace_manager_interface workspace_manager_implementation = { |
| 1417 | workspace_manager_move_surface, |
| 1418 | }; |
| 1419 | |
| 1420 | static void |
| 1421 | unbind_resource(struct wl_resource *resource) |
| 1422 | { |
Jason Ekstrand | 651f00e | 2013-06-14 10:07:54 -0500 | [diff] [blame] | 1423 | wl_list_remove(wl_resource_get_link(resource)); |
Jonas Ådahl | e9d2250 | 2012-08-29 22:13:01 +0200 | [diff] [blame] | 1424 | } |
| 1425 | |
| 1426 | static void |
| 1427 | bind_workspace_manager(struct wl_client *client, |
| 1428 | void *data, uint32_t version, uint32_t id) |
| 1429 | { |
| 1430 | struct desktop_shell *shell = data; |
| 1431 | struct wl_resource *resource; |
| 1432 | |
Jason Ekstrand | a85118c | 2013-06-27 20:17:02 -0500 | [diff] [blame] | 1433 | resource = wl_resource_create(client, |
| 1434 | &workspace_manager_interface, 1, id); |
Jonas Ådahl | e9d2250 | 2012-08-29 22:13:01 +0200 | [diff] [blame] | 1435 | |
| 1436 | if (resource == NULL) { |
| 1437 | weston_log("couldn't add workspace manager object"); |
| 1438 | return; |
| 1439 | } |
| 1440 | |
Jason Ekstrand | a85118c | 2013-06-27 20:17:02 -0500 | [diff] [blame] | 1441 | wl_resource_set_implementation(resource, |
| 1442 | &workspace_manager_implementation, |
| 1443 | shell, unbind_resource); |
Jason Ekstrand | 651f00e | 2013-06-14 10:07:54 -0500 | [diff] [blame] | 1444 | wl_list_insert(&shell->workspaces.client_list, |
| 1445 | wl_resource_get_link(resource)); |
Jonas Ådahl | e9d2250 | 2012-08-29 22:13:01 +0200 | [diff] [blame] | 1446 | |
| 1447 | workspace_manager_send_state(resource, |
| 1448 | shell->workspaces.current, |
| 1449 | shell->workspaces.num); |
Jonas Ådahl | 8de6a1d | 2012-08-29 22:13:00 +0200 | [diff] [blame] | 1450 | } |
| 1451 | |
Pekka Paalanen | 56cdea9 | 2011-11-23 16:14:12 +0200 | [diff] [blame] | 1452 | static void |
Rusty Lynch | 1084da5 | 2013-08-15 09:10:08 -0700 | [diff] [blame] | 1453 | touch_move_grab_down(struct weston_touch_grab *grab, uint32_t time, |
| 1454 | int touch_id, wl_fixed_t sx, wl_fixed_t sy) |
| 1455 | { |
| 1456 | } |
| 1457 | |
| 1458 | static void |
| 1459 | touch_move_grab_up(struct weston_touch_grab *grab, uint32_t time, int touch_id) |
| 1460 | { |
Jonas Ådahl | 1c6e63e | 2013-10-25 23:18:04 +0200 | [diff] [blame] | 1461 | struct weston_touch_move_grab *move = |
| 1462 | (struct weston_touch_move_grab *) container_of( |
| 1463 | grab, struct shell_touch_grab, grab); |
Neil Roberts | e14aa4f | 2013-10-03 16:43:07 +0100 | [diff] [blame] | 1464 | |
Jonas Ådahl | 9484b69 | 2013-12-02 22:05:03 +0100 | [diff] [blame] | 1465 | if (grab->touch->num_tp == 0) { |
Jonas Ådahl | 1c6e63e | 2013-10-25 23:18:04 +0200 | [diff] [blame] | 1466 | shell_touch_grab_end(&move->base); |
| 1467 | free(move); |
| 1468 | } |
Rusty Lynch | 1084da5 | 2013-08-15 09:10:08 -0700 | [diff] [blame] | 1469 | } |
| 1470 | |
| 1471 | static void |
| 1472 | touch_move_grab_motion(struct weston_touch_grab *grab, uint32_t time, |
| 1473 | int touch_id, wl_fixed_t sx, wl_fixed_t sy) |
| 1474 | { |
| 1475 | struct weston_touch_move_grab *move = (struct weston_touch_move_grab *) grab; |
| 1476 | struct shell_surface *shsurf = move->base.shsurf; |
| 1477 | struct weston_surface *es; |
| 1478 | int dx = wl_fixed_to_int(grab->touch->grab_x + move->dx); |
| 1479 | int dy = wl_fixed_to_int(grab->touch->grab_y + move->dy); |
| 1480 | |
| 1481 | if (!shsurf) |
| 1482 | return; |
| 1483 | |
| 1484 | es = shsurf->surface; |
| 1485 | |
Jason Ekstrand | 918f2dd | 2013-12-02 21:01:53 -0600 | [diff] [blame] | 1486 | weston_view_set_position(shsurf->view, dx, dy); |
Rusty Lynch | 1084da5 | 2013-08-15 09:10:08 -0700 | [diff] [blame] | 1487 | |
| 1488 | weston_compositor_schedule_repaint(es->compositor); |
| 1489 | } |
| 1490 | |
Jonas Ådahl | 1ea343e | 2013-10-25 23:18:05 +0200 | [diff] [blame] | 1491 | static void |
| 1492 | touch_move_grab_cancel(struct weston_touch_grab *grab) |
| 1493 | { |
| 1494 | struct weston_touch_move_grab *move = |
| 1495 | (struct weston_touch_move_grab *) container_of( |
| 1496 | grab, struct shell_touch_grab, grab); |
| 1497 | |
| 1498 | shell_touch_grab_end(&move->base); |
| 1499 | free(move); |
| 1500 | } |
| 1501 | |
Rusty Lynch | 1084da5 | 2013-08-15 09:10:08 -0700 | [diff] [blame] | 1502 | static const struct weston_touch_grab_interface touch_move_grab_interface = { |
| 1503 | touch_move_grab_down, |
| 1504 | touch_move_grab_up, |
| 1505 | touch_move_grab_motion, |
Jonas Ådahl | 1ea343e | 2013-10-25 23:18:05 +0200 | [diff] [blame] | 1506 | touch_move_grab_cancel, |
Rusty Lynch | 1084da5 | 2013-08-15 09:10:08 -0700 | [diff] [blame] | 1507 | }; |
| 1508 | |
| 1509 | static int |
| 1510 | surface_touch_move(struct shell_surface *shsurf, struct weston_seat *seat) |
| 1511 | { |
| 1512 | struct weston_touch_move_grab *move; |
| 1513 | |
| 1514 | if (!shsurf) |
| 1515 | return -1; |
| 1516 | |
Rafael Antognolli | 03b1659 | 2013-12-03 15:35:42 -0200 | [diff] [blame] | 1517 | if (shsurf->state.fullscreen) |
Rusty Lynch | 1084da5 | 2013-08-15 09:10:08 -0700 | [diff] [blame] | 1518 | return 0; |
Kristian Høgsberg | c85f1d4 | 2013-10-24 16:52:00 -0700 | [diff] [blame] | 1519 | if (shsurf->grabbed) |
| 1520 | return 0; |
Rusty Lynch | 1084da5 | 2013-08-15 09:10:08 -0700 | [diff] [blame] | 1521 | |
| 1522 | move = malloc(sizeof *move); |
| 1523 | if (!move) |
| 1524 | return -1; |
| 1525 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 1526 | move->dx = wl_fixed_from_double(shsurf->view->geometry.x) - |
Rusty Lynch | 1084da5 | 2013-08-15 09:10:08 -0700 | [diff] [blame] | 1527 | seat->touch->grab_x; |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 1528 | move->dy = wl_fixed_from_double(shsurf->view->geometry.y) - |
Rusty Lynch | 1084da5 | 2013-08-15 09:10:08 -0700 | [diff] [blame] | 1529 | seat->touch->grab_y; |
| 1530 | |
| 1531 | shell_touch_grab_start(&move->base, &touch_move_grab_interface, shsurf, |
| 1532 | seat->touch); |
| 1533 | |
| 1534 | return 0; |
| 1535 | } |
| 1536 | |
| 1537 | static void |
Kristian Høgsberg | 6848c25 | 2013-05-08 22:02:59 -0400 | [diff] [blame] | 1538 | noop_grab_focus(struct weston_pointer_grab *grab) |
Kristian Høgsberg | 9ddb826 | 2012-01-04 21:30:29 -0500 | [diff] [blame] | 1539 | { |
Kristian Høgsberg | 9ddb826 | 2012-01-04 21:30:29 -0500 | [diff] [blame] | 1540 | } |
| 1541 | |
| 1542 | static void |
Giulio Camuffo | 1959ab8 | 2013-11-14 23:42:52 +0100 | [diff] [blame] | 1543 | move_grab_motion(struct weston_pointer_grab *grab, uint32_t time, |
| 1544 | wl_fixed_t x, wl_fixed_t y) |
Kristian Høgsberg | 4cca349 | 2011-01-18 07:53:49 -0500 | [diff] [blame] | 1545 | { |
Kristian Høgsberg | 8334bc1 | 2012-01-03 10:29:47 -0500 | [diff] [blame] | 1546 | struct weston_move_grab *move = (struct weston_move_grab *) grab; |
Kristian Høgsberg | 02bbabb | 2013-05-06 22:15:05 -0400 | [diff] [blame] | 1547 | struct weston_pointer *pointer = grab->pointer; |
Ander Conselvan de Oliveira | fe0444a | 2012-04-04 17:48:05 +0300 | [diff] [blame] | 1548 | struct shell_surface *shsurf = move->base.shsurf; |
Giulio Camuffo | 1959ab8 | 2013-11-14 23:42:52 +0100 | [diff] [blame] | 1549 | int dx, dy; |
| 1550 | |
| 1551 | weston_pointer_move(pointer, x, y); |
| 1552 | dx = wl_fixed_to_int(pointer->x + move->dx); |
| 1553 | dy = wl_fixed_to_int(pointer->y + move->dy); |
Ander Conselvan de Oliveira | fe0444a | 2012-04-04 17:48:05 +0300 | [diff] [blame] | 1554 | |
| 1555 | if (!shsurf) |
| 1556 | return; |
| 1557 | |
Jason Ekstrand | 918f2dd | 2013-12-02 21:01:53 -0600 | [diff] [blame] | 1558 | weston_view_set_position(shsurf->view, dx, dy); |
Kristian Høgsberg | 4cca349 | 2011-01-18 07:53:49 -0500 | [diff] [blame] | 1559 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 1560 | weston_compositor_schedule_repaint(shsurf->surface->compositor); |
Kristian Høgsberg | 4cca349 | 2011-01-18 07:53:49 -0500 | [diff] [blame] | 1561 | } |
| 1562 | |
| 1563 | static void |
Kristian Høgsberg | 02bbabb | 2013-05-06 22:15:05 -0400 | [diff] [blame] | 1564 | move_grab_button(struct weston_pointer_grab *grab, |
Daniel Stone | 4dbadb1 | 2012-05-30 16:31:51 +0100 | [diff] [blame] | 1565 | uint32_t time, uint32_t button, uint32_t state_w) |
Kristian Høgsberg | 4cca349 | 2011-01-18 07:53:49 -0500 | [diff] [blame] | 1566 | { |
Ander Conselvan de Oliveira | fe0444a | 2012-04-04 17:48:05 +0300 | [diff] [blame] | 1567 | struct shell_grab *shell_grab = container_of(grab, struct shell_grab, |
| 1568 | grab); |
Kristian Høgsberg | 02bbabb | 2013-05-06 22:15:05 -0400 | [diff] [blame] | 1569 | struct weston_pointer *pointer = grab->pointer; |
Daniel Stone | 4dbadb1 | 2012-05-30 16:31:51 +0100 | [diff] [blame] | 1570 | enum wl_pointer_button_state state = state_w; |
Kristian Høgsberg | 4cca349 | 2011-01-18 07:53:49 -0500 | [diff] [blame] | 1571 | |
Daniel Stone | 4dbadb1 | 2012-05-30 16:31:51 +0100 | [diff] [blame] | 1572 | if (pointer->button_count == 0 && |
| 1573 | state == WL_POINTER_BUTTON_STATE_RELEASED) { |
Ander Conselvan de Oliveira | b9d2a0f | 2012-06-28 18:08:05 +0300 | [diff] [blame] | 1574 | shell_grab_end(shell_grab); |
Kristian Høgsberg | 9ddb826 | 2012-01-04 21:30:29 -0500 | [diff] [blame] | 1575 | free(grab); |
| 1576 | } |
Kristian Høgsberg | 4cca349 | 2011-01-18 07:53:49 -0500 | [diff] [blame] | 1577 | } |
| 1578 | |
Jonas Ådahl | 1ea343e | 2013-10-25 23:18:05 +0200 | [diff] [blame] | 1579 | static void |
| 1580 | move_grab_cancel(struct weston_pointer_grab *grab) |
| 1581 | { |
| 1582 | struct shell_grab *shell_grab = |
| 1583 | container_of(grab, struct shell_grab, grab); |
| 1584 | |
| 1585 | shell_grab_end(shell_grab); |
| 1586 | free(grab); |
| 1587 | } |
| 1588 | |
Kristian Høgsberg | 02bbabb | 2013-05-06 22:15:05 -0400 | [diff] [blame] | 1589 | static const struct weston_pointer_grab_interface move_grab_interface = { |
Kristian Høgsberg | 9ddb826 | 2012-01-04 21:30:29 -0500 | [diff] [blame] | 1590 | noop_grab_focus, |
Kristian Høgsberg | 4cca349 | 2011-01-18 07:53:49 -0500 | [diff] [blame] | 1591 | move_grab_motion, |
| 1592 | move_grab_button, |
Jonas Ådahl | 1ea343e | 2013-10-25 23:18:05 +0200 | [diff] [blame] | 1593 | move_grab_cancel, |
Kristian Høgsberg | 4cca349 | 2011-01-18 07:53:49 -0500 | [diff] [blame] | 1594 | }; |
| 1595 | |
Kristian Høgsberg | 9e31bff | 2012-08-01 00:08:07 -0400 | [diff] [blame] | 1596 | static int |
Kristian Høgsberg | e314875 | 2013-05-06 23:19:49 -0400 | [diff] [blame] | 1597 | surface_move(struct shell_surface *shsurf, struct weston_seat *seat) |
Kristian Høgsberg | 9e31bff | 2012-08-01 00:08:07 -0400 | [diff] [blame] | 1598 | { |
| 1599 | struct weston_move_grab *move; |
| 1600 | |
| 1601 | if (!shsurf) |
| 1602 | return -1; |
| 1603 | |
Kristian Høgsberg | c85f1d4 | 2013-10-24 16:52:00 -0700 | [diff] [blame] | 1604 | if (shsurf->grabbed) |
| 1605 | return 0; |
Rafael Antognolli | 03b1659 | 2013-12-03 15:35:42 -0200 | [diff] [blame] | 1606 | if (shsurf->state.fullscreen) |
Kristian Høgsberg | 9e31bff | 2012-08-01 00:08:07 -0400 | [diff] [blame] | 1607 | return 0; |
| 1608 | |
| 1609 | move = malloc(sizeof *move); |
| 1610 | if (!move) |
| 1611 | return -1; |
| 1612 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 1613 | move->dx = wl_fixed_from_double(shsurf->view->geometry.x) - |
Kristian Høgsberg | e314875 | 2013-05-06 23:19:49 -0400 | [diff] [blame] | 1614 | seat->pointer->grab_x; |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 1615 | move->dy = wl_fixed_from_double(shsurf->view->geometry.y) - |
Kristian Høgsberg | e314875 | 2013-05-06 23:19:49 -0400 | [diff] [blame] | 1616 | seat->pointer->grab_y; |
Kristian Høgsberg | 9e31bff | 2012-08-01 00:08:07 -0400 | [diff] [blame] | 1617 | |
| 1618 | shell_grab_start(&move->base, &move_grab_interface, shsurf, |
Kristian Høgsberg | e314875 | 2013-05-06 23:19:49 -0400 | [diff] [blame] | 1619 | seat->pointer, DESKTOP_SHELL_CURSOR_MOVE); |
Kristian Høgsberg | 9e31bff | 2012-08-01 00:08:07 -0400 | [diff] [blame] | 1620 | |
| 1621 | return 0; |
| 1622 | } |
| 1623 | |
| 1624 | static void |
| 1625 | shell_surface_move(struct wl_client *client, struct wl_resource *resource, |
| 1626 | struct wl_resource *seat_resource, uint32_t serial) |
| 1627 | { |
Jason Ekstrand | 44a3863 | 2013-06-14 10:08:00 -0500 | [diff] [blame] | 1628 | struct weston_seat *seat = wl_resource_get_user_data(seat_resource); |
Jason Ekstrand | 651f00e | 2013-06-14 10:07:54 -0500 | [diff] [blame] | 1629 | struct shell_surface *shsurf = wl_resource_get_user_data(resource); |
Giulio Camuffo | 61da3fc | 2013-04-25 13:57:45 +0300 | [diff] [blame] | 1630 | struct weston_surface *surface; |
Kristian Høgsberg | 9e31bff | 2012-08-01 00:08:07 -0400 | [diff] [blame] | 1631 | |
Kristian Høgsberg | e1b655d | 2013-08-28 23:16:20 -0700 | [diff] [blame] | 1632 | if (seat->pointer && |
| 1633 | seat->pointer->button_count > 0 && |
| 1634 | seat->pointer->grab_serial == serial) { |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 1635 | surface = weston_surface_get_main_surface(seat->pointer->focus->surface); |
Rusty Lynch | 1084da5 | 2013-08-15 09:10:08 -0700 | [diff] [blame] | 1636 | if ((surface == shsurf->surface) && |
| 1637 | (surface_move(shsurf, seat) < 0)) |
| 1638 | wl_resource_post_no_memory(resource); |
Kristian Høgsberg | e1b655d | 2013-08-28 23:16:20 -0700 | [diff] [blame] | 1639 | } else if (seat->touch && |
| 1640 | seat->touch->grab_serial == serial) { |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 1641 | surface = weston_surface_get_main_surface(seat->touch->focus->surface); |
Rusty Lynch | 1084da5 | 2013-08-15 09:10:08 -0700 | [diff] [blame] | 1642 | if ((surface == shsurf->surface) && |
| 1643 | (surface_touch_move(shsurf, seat) < 0)) |
| 1644 | wl_resource_post_no_memory(resource); |
| 1645 | } |
Kristian Høgsberg | 9e31bff | 2012-08-01 00:08:07 -0400 | [diff] [blame] | 1646 | } |
| 1647 | |
| 1648 | struct weston_resize_grab { |
| 1649 | struct shell_grab base; |
| 1650 | uint32_t edges; |
| 1651 | int32_t width, height; |
| 1652 | }; |
| 1653 | |
| 1654 | static void |
Giulio Camuffo | 1959ab8 | 2013-11-14 23:42:52 +0100 | [diff] [blame] | 1655 | resize_grab_motion(struct weston_pointer_grab *grab, uint32_t time, |
| 1656 | wl_fixed_t x, wl_fixed_t y) |
Kristian Høgsberg | 9e31bff | 2012-08-01 00:08:07 -0400 | [diff] [blame] | 1657 | { |
| 1658 | struct weston_resize_grab *resize = (struct weston_resize_grab *) grab; |
Kristian Høgsberg | 02bbabb | 2013-05-06 22:15:05 -0400 | [diff] [blame] | 1659 | struct weston_pointer *pointer = grab->pointer; |
Kristian Høgsberg | 9e31bff | 2012-08-01 00:08:07 -0400 | [diff] [blame] | 1660 | struct shell_surface *shsurf = resize->base.shsurf; |
| 1661 | int32_t width, height; |
| 1662 | wl_fixed_t from_x, from_y; |
| 1663 | wl_fixed_t to_x, to_y; |
| 1664 | |
Giulio Camuffo | 1959ab8 | 2013-11-14 23:42:52 +0100 | [diff] [blame] | 1665 | weston_pointer_move(pointer, x, y); |
| 1666 | |
Kristian Høgsberg | 9e31bff | 2012-08-01 00:08:07 -0400 | [diff] [blame] | 1667 | if (!shsurf) |
| 1668 | return; |
| 1669 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 1670 | weston_view_from_global_fixed(shsurf->view, |
| 1671 | pointer->grab_x, pointer->grab_y, |
| 1672 | &from_x, &from_y); |
| 1673 | weston_view_from_global_fixed(shsurf->view, |
| 1674 | pointer->x, pointer->y, &to_x, &to_y); |
Kristian Høgsberg | 9e31bff | 2012-08-01 00:08:07 -0400 | [diff] [blame] | 1675 | |
| 1676 | width = resize->width; |
| 1677 | if (resize->edges & WL_SHELL_SURFACE_RESIZE_LEFT) { |
| 1678 | width += wl_fixed_to_int(from_x - to_x); |
| 1679 | } else if (resize->edges & WL_SHELL_SURFACE_RESIZE_RIGHT) { |
| 1680 | width += wl_fixed_to_int(to_x - from_x); |
| 1681 | } |
| 1682 | |
| 1683 | height = resize->height; |
| 1684 | if (resize->edges & WL_SHELL_SURFACE_RESIZE_TOP) { |
| 1685 | height += wl_fixed_to_int(from_y - to_y); |
| 1686 | } else if (resize->edges & WL_SHELL_SURFACE_RESIZE_BOTTOM) { |
| 1687 | height += wl_fixed_to_int(to_y - from_y); |
| 1688 | } |
| 1689 | |
| 1690 | shsurf->client->send_configure(shsurf->surface, |
| 1691 | resize->edges, width, height); |
| 1692 | } |
| 1693 | |
| 1694 | static void |
| 1695 | send_configure(struct weston_surface *surface, |
| 1696 | uint32_t edges, int32_t width, int32_t height) |
| 1697 | { |
| 1698 | struct shell_surface *shsurf = get_shell_surface(surface); |
| 1699 | |
Jason Ekstrand | 651f00e | 2013-06-14 10:07:54 -0500 | [diff] [blame] | 1700 | wl_shell_surface_send_configure(shsurf->resource, |
Kristian Høgsberg | 9e31bff | 2012-08-01 00:08:07 -0400 | [diff] [blame] | 1701 | edges, width, height); |
| 1702 | } |
| 1703 | |
| 1704 | static const struct weston_shell_client shell_client = { |
| 1705 | send_configure |
| 1706 | }; |
| 1707 | |
| 1708 | static void |
Kristian Høgsberg | 02bbabb | 2013-05-06 22:15:05 -0400 | [diff] [blame] | 1709 | resize_grab_button(struct weston_pointer_grab *grab, |
Kristian Høgsberg | 9e31bff | 2012-08-01 00:08:07 -0400 | [diff] [blame] | 1710 | uint32_t time, uint32_t button, uint32_t state_w) |
| 1711 | { |
| 1712 | struct weston_resize_grab *resize = (struct weston_resize_grab *) grab; |
Kristian Høgsberg | 02bbabb | 2013-05-06 22:15:05 -0400 | [diff] [blame] | 1713 | struct weston_pointer *pointer = grab->pointer; |
Kristian Høgsberg | 9e31bff | 2012-08-01 00:08:07 -0400 | [diff] [blame] | 1714 | enum wl_pointer_button_state state = state_w; |
| 1715 | |
| 1716 | if (pointer->button_count == 0 && |
| 1717 | state == WL_POINTER_BUTTON_STATE_RELEASED) { |
| 1718 | shell_grab_end(&resize->base); |
| 1719 | free(grab); |
| 1720 | } |
| 1721 | } |
| 1722 | |
Jonas Ådahl | 1ea343e | 2013-10-25 23:18:05 +0200 | [diff] [blame] | 1723 | static void |
| 1724 | resize_grab_cancel(struct weston_pointer_grab *grab) |
| 1725 | { |
| 1726 | struct weston_resize_grab *resize = (struct weston_resize_grab *) grab; |
| 1727 | |
| 1728 | shell_grab_end(&resize->base); |
| 1729 | free(grab); |
| 1730 | } |
| 1731 | |
Kristian Høgsberg | 02bbabb | 2013-05-06 22:15:05 -0400 | [diff] [blame] | 1732 | static const struct weston_pointer_grab_interface resize_grab_interface = { |
Kristian Høgsberg | 9e31bff | 2012-08-01 00:08:07 -0400 | [diff] [blame] | 1733 | noop_grab_focus, |
| 1734 | resize_grab_motion, |
| 1735 | resize_grab_button, |
Jonas Ådahl | 1ea343e | 2013-10-25 23:18:05 +0200 | [diff] [blame] | 1736 | resize_grab_cancel, |
Kristian Høgsberg | 9e31bff | 2012-08-01 00:08:07 -0400 | [diff] [blame] | 1737 | }; |
| 1738 | |
Giulio Camuffo | b836664 | 2013-04-25 13:57:46 +0300 | [diff] [blame] | 1739 | /* |
| 1740 | * Returns the bounding box of a surface and all its sub-surfaces, |
| 1741 | * in the surface coordinates system. */ |
| 1742 | static void |
| 1743 | surface_subsurfaces_boundingbox(struct weston_surface *surface, int32_t *x, |
| 1744 | int32_t *y, int32_t *w, int32_t *h) { |
| 1745 | pixman_region32_t region; |
| 1746 | pixman_box32_t *box; |
| 1747 | struct weston_subsurface *subsurface; |
| 1748 | |
| 1749 | pixman_region32_init_rect(®ion, 0, 0, |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 1750 | surface->width, |
| 1751 | surface->height); |
Giulio Camuffo | b836664 | 2013-04-25 13:57:46 +0300 | [diff] [blame] | 1752 | |
| 1753 | wl_list_for_each(subsurface, &surface->subsurface_list, parent_link) { |
| 1754 | pixman_region32_union_rect(®ion, ®ion, |
| 1755 | subsurface->position.x, |
| 1756 | subsurface->position.y, |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 1757 | subsurface->surface->width, |
| 1758 | subsurface->surface->height); |
Giulio Camuffo | b836664 | 2013-04-25 13:57:46 +0300 | [diff] [blame] | 1759 | } |
| 1760 | |
| 1761 | box = pixman_region32_extents(®ion); |
| 1762 | if (x) |
| 1763 | *x = box->x1; |
| 1764 | if (y) |
| 1765 | *y = box->y1; |
| 1766 | if (w) |
| 1767 | *w = box->x2 - box->x1; |
| 1768 | if (h) |
| 1769 | *h = box->y2 - box->y1; |
| 1770 | |
| 1771 | pixman_region32_fini(®ion); |
| 1772 | } |
| 1773 | |
Kristian Høgsberg | 9e31bff | 2012-08-01 00:08:07 -0400 | [diff] [blame] | 1774 | static int |
| 1775 | surface_resize(struct shell_surface *shsurf, |
Kristian Høgsberg | e314875 | 2013-05-06 23:19:49 -0400 | [diff] [blame] | 1776 | struct weston_seat *seat, uint32_t edges) |
Kristian Høgsberg | 9e31bff | 2012-08-01 00:08:07 -0400 | [diff] [blame] | 1777 | { |
| 1778 | struct weston_resize_grab *resize; |
| 1779 | |
Rafael Antognolli | 03b1659 | 2013-12-03 15:35:42 -0200 | [diff] [blame] | 1780 | if (shsurf->state.fullscreen || shsurf->state.maximized) |
Kristian Høgsberg | 9e31bff | 2012-08-01 00:08:07 -0400 | [diff] [blame] | 1781 | return 0; |
| 1782 | |
| 1783 | if (edges == 0 || edges > 15 || |
| 1784 | (edges & 3) == 3 || (edges & 12) == 12) |
| 1785 | return 0; |
| 1786 | |
| 1787 | resize = malloc(sizeof *resize); |
| 1788 | if (!resize) |
| 1789 | return -1; |
| 1790 | |
| 1791 | resize->edges = edges; |
Giulio Camuffo | b836664 | 2013-04-25 13:57:46 +0300 | [diff] [blame] | 1792 | surface_subsurfaces_boundingbox(shsurf->surface, NULL, NULL, |
| 1793 | &resize->width, &resize->height); |
Kristian Høgsberg | 9e31bff | 2012-08-01 00:08:07 -0400 | [diff] [blame] | 1794 | |
| 1795 | shell_grab_start(&resize->base, &resize_grab_interface, shsurf, |
Kristian Høgsberg | e314875 | 2013-05-06 23:19:49 -0400 | [diff] [blame] | 1796 | seat->pointer, edges); |
Kristian Høgsberg | 9e31bff | 2012-08-01 00:08:07 -0400 | [diff] [blame] | 1797 | |
| 1798 | return 0; |
| 1799 | } |
| 1800 | |
| 1801 | static void |
| 1802 | shell_surface_resize(struct wl_client *client, struct wl_resource *resource, |
| 1803 | struct wl_resource *seat_resource, uint32_t serial, |
| 1804 | uint32_t edges) |
| 1805 | { |
Jason Ekstrand | 44a3863 | 2013-06-14 10:08:00 -0500 | [diff] [blame] | 1806 | struct weston_seat *seat = wl_resource_get_user_data(seat_resource); |
Jason Ekstrand | 651f00e | 2013-06-14 10:07:54 -0500 | [diff] [blame] | 1807 | struct shell_surface *shsurf = wl_resource_get_user_data(resource); |
Giulio Camuffo | 61da3fc | 2013-04-25 13:57:45 +0300 | [diff] [blame] | 1808 | struct weston_surface *surface; |
Kristian Høgsberg | 9e31bff | 2012-08-01 00:08:07 -0400 | [diff] [blame] | 1809 | |
Rafael Antognolli | 03b1659 | 2013-12-03 15:35:42 -0200 | [diff] [blame] | 1810 | if (shsurf->state.fullscreen) |
Kristian Høgsberg | 9e31bff | 2012-08-01 00:08:07 -0400 | [diff] [blame] | 1811 | return; |
| 1812 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 1813 | surface = weston_surface_get_main_surface(seat->pointer->focus->surface); |
Kristian Høgsberg | e314875 | 2013-05-06 23:19:49 -0400 | [diff] [blame] | 1814 | if (seat->pointer->button_count == 0 || |
| 1815 | seat->pointer->grab_serial != serial || |
Giulio Camuffo | 61da3fc | 2013-04-25 13:57:45 +0300 | [diff] [blame] | 1816 | surface != shsurf->surface) |
Kristian Høgsberg | 9e31bff | 2012-08-01 00:08:07 -0400 | [diff] [blame] | 1817 | return; |
| 1818 | |
Kristian Høgsberg | e314875 | 2013-05-06 23:19:49 -0400 | [diff] [blame] | 1819 | if (surface_resize(shsurf, seat, edges) < 0) |
Kristian Høgsberg | 9e31bff | 2012-08-01 00:08:07 -0400 | [diff] [blame] | 1820 | wl_resource_post_no_memory(resource); |
| 1821 | } |
| 1822 | |
Scott Moreau | c3e54eb | 2012-04-17 19:06:20 -0600 | [diff] [blame] | 1823 | static void |
Kristian Høgsberg | 6780073 | 2013-07-04 01:12:17 -0400 | [diff] [blame] | 1824 | end_busy_cursor(struct shell_surface *shsurf, struct weston_pointer *pointer); |
| 1825 | |
| 1826 | static void |
Kristian Høgsberg | 6848c25 | 2013-05-08 22:02:59 -0400 | [diff] [blame] | 1827 | busy_cursor_grab_focus(struct weston_pointer_grab *base) |
Scott Moreau | c3e54eb | 2012-04-17 19:06:20 -0600 | [diff] [blame] | 1828 | { |
Kristian Høgsberg | d56bd90 | 2012-06-05 09:58:51 -0400 | [diff] [blame] | 1829 | struct shell_grab *grab = (struct shell_grab *) base; |
Kristian Høgsberg | 6848c25 | 2013-05-08 22:02:59 -0400 | [diff] [blame] | 1830 | struct weston_pointer *pointer = base->pointer; |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 1831 | struct weston_view *view; |
Kristian Høgsberg | 6848c25 | 2013-05-08 22:02:59 -0400 | [diff] [blame] | 1832 | wl_fixed_t sx, sy; |
| 1833 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 1834 | view = weston_compositor_pick_view(pointer->seat->compositor, |
| 1835 | pointer->x, pointer->y, |
| 1836 | &sx, &sy); |
Scott Moreau | c3e54eb | 2012-04-17 19:06:20 -0600 | [diff] [blame] | 1837 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 1838 | if (!grab->shsurf || grab->shsurf->surface != view->surface) |
Kristian Høgsberg | 6780073 | 2013-07-04 01:12:17 -0400 | [diff] [blame] | 1839 | end_busy_cursor(grab->shsurf, pointer); |
Scott Moreau | c3e54eb | 2012-04-17 19:06:20 -0600 | [diff] [blame] | 1840 | } |
| 1841 | |
| 1842 | static void |
Giulio Camuffo | 1959ab8 | 2013-11-14 23:42:52 +0100 | [diff] [blame] | 1843 | busy_cursor_grab_motion(struct weston_pointer_grab *grab, uint32_t time, |
| 1844 | wl_fixed_t x, wl_fixed_t y) |
Scott Moreau | c3e54eb | 2012-04-17 19:06:20 -0600 | [diff] [blame] | 1845 | { |
Giulio Camuffo | 1959ab8 | 2013-11-14 23:42:52 +0100 | [diff] [blame] | 1846 | weston_pointer_move(grab->pointer, x, y); |
Kristian Høgsberg | d56bd90 | 2012-06-05 09:58:51 -0400 | [diff] [blame] | 1847 | } |
Scott Moreau | c3e54eb | 2012-04-17 19:06:20 -0600 | [diff] [blame] | 1848 | |
Kristian Høgsberg | d56bd90 | 2012-06-05 09:58:51 -0400 | [diff] [blame] | 1849 | static void |
Kristian Høgsberg | 02bbabb | 2013-05-06 22:15:05 -0400 | [diff] [blame] | 1850 | busy_cursor_grab_button(struct weston_pointer_grab *base, |
Kristian Høgsberg | d56bd90 | 2012-06-05 09:58:51 -0400 | [diff] [blame] | 1851 | uint32_t time, uint32_t button, uint32_t state) |
| 1852 | { |
Kristian Høgsberg | bbe9839 | 2012-08-01 00:20:21 -0400 | [diff] [blame] | 1853 | struct shell_grab *grab = (struct shell_grab *) base; |
Kristian Høgsberg | e122b7b | 2013-05-08 16:47:00 -0400 | [diff] [blame] | 1854 | struct shell_surface *shsurf = grab->shsurf; |
Kristian Høgsberg | e314875 | 2013-05-06 23:19:49 -0400 | [diff] [blame] | 1855 | struct weston_seat *seat = grab->grab.pointer->seat; |
Kristian Høgsberg | bbe9839 | 2012-08-01 00:20:21 -0400 | [diff] [blame] | 1856 | |
Kristian Høgsberg | bbe9839 | 2012-08-01 00:20:21 -0400 | [diff] [blame] | 1857 | if (shsurf && button == BTN_LEFT && state) { |
| 1858 | activate(shsurf->shell, shsurf->surface, seat); |
| 1859 | surface_move(shsurf, seat); |
Kristian Høgsberg | 0c36903 | 2013-02-14 21:31:44 -0500 | [diff] [blame] | 1860 | } else if (shsurf && button == BTN_RIGHT && state) { |
| 1861 | activate(shsurf->shell, shsurf->surface, seat); |
Kristian Høgsberg | e314875 | 2013-05-06 23:19:49 -0400 | [diff] [blame] | 1862 | surface_rotate(shsurf, seat); |
Kristian Høgsberg | bbe9839 | 2012-08-01 00:20:21 -0400 | [diff] [blame] | 1863 | } |
Kristian Høgsberg | d56bd90 | 2012-06-05 09:58:51 -0400 | [diff] [blame] | 1864 | } |
| 1865 | |
Jonas Ådahl | 1ea343e | 2013-10-25 23:18:05 +0200 | [diff] [blame] | 1866 | static void |
| 1867 | busy_cursor_grab_cancel(struct weston_pointer_grab *base) |
| 1868 | { |
| 1869 | struct shell_grab *grab = (struct shell_grab *) base; |
| 1870 | |
| 1871 | shell_grab_end(grab); |
| 1872 | free(grab); |
| 1873 | } |
| 1874 | |
Kristian Høgsberg | 02bbabb | 2013-05-06 22:15:05 -0400 | [diff] [blame] | 1875 | static const struct weston_pointer_grab_interface busy_cursor_grab_interface = { |
Kristian Høgsberg | d56bd90 | 2012-06-05 09:58:51 -0400 | [diff] [blame] | 1876 | busy_cursor_grab_focus, |
| 1877 | busy_cursor_grab_motion, |
| 1878 | busy_cursor_grab_button, |
Jonas Ådahl | 1ea343e | 2013-10-25 23:18:05 +0200 | [diff] [blame] | 1879 | busy_cursor_grab_cancel, |
Kristian Høgsberg | d56bd90 | 2012-06-05 09:58:51 -0400 | [diff] [blame] | 1880 | }; |
| 1881 | |
| 1882 | static void |
Kristian Høgsberg | 02bbabb | 2013-05-06 22:15:05 -0400 | [diff] [blame] | 1883 | set_busy_cursor(struct shell_surface *shsurf, struct weston_pointer *pointer) |
Kristian Høgsberg | d56bd90 | 2012-06-05 09:58:51 -0400 | [diff] [blame] | 1884 | { |
| 1885 | struct shell_grab *grab; |
Kristian Høgsberg | d56bd90 | 2012-06-05 09:58:51 -0400 | [diff] [blame] | 1886 | |
| 1887 | grab = malloc(sizeof *grab); |
| 1888 | if (!grab) |
Scott Moreau | c3e54eb | 2012-04-17 19:06:20 -0600 | [diff] [blame] | 1889 | return; |
| 1890 | |
Ander Conselvan de Oliveira | b9d2a0f | 2012-06-28 18:08:05 +0300 | [diff] [blame] | 1891 | shell_grab_start(grab, &busy_cursor_grab_interface, shsurf, pointer, |
| 1892 | DESKTOP_SHELL_CURSOR_BUSY); |
Kristian Høgsberg | d56bd90 | 2012-06-05 09:58:51 -0400 | [diff] [blame] | 1893 | } |
Scott Moreau | c3e54eb | 2012-04-17 19:06:20 -0600 | [diff] [blame] | 1894 | |
Kristian Høgsberg | d56bd90 | 2012-06-05 09:58:51 -0400 | [diff] [blame] | 1895 | static void |
Kristian Høgsberg | 02bbabb | 2013-05-06 22:15:05 -0400 | [diff] [blame] | 1896 | end_busy_cursor(struct shell_surface *shsurf, struct weston_pointer *pointer) |
Kristian Høgsberg | d56bd90 | 2012-06-05 09:58:51 -0400 | [diff] [blame] | 1897 | { |
| 1898 | struct shell_grab *grab = (struct shell_grab *) pointer->grab; |
| 1899 | |
Kristian Høgsberg | e122b7b | 2013-05-08 16:47:00 -0400 | [diff] [blame] | 1900 | if (grab->grab.interface == &busy_cursor_grab_interface && |
| 1901 | grab->shsurf == shsurf) { |
Ander Conselvan de Oliveira | b9d2a0f | 2012-06-28 18:08:05 +0300 | [diff] [blame] | 1902 | shell_grab_end(grab); |
Kristian Høgsberg | d56bd90 | 2012-06-05 09:58:51 -0400 | [diff] [blame] | 1903 | free(grab); |
Scott Moreau | c3e54eb | 2012-04-17 19:06:20 -0600 | [diff] [blame] | 1904 | } |
Scott Moreau | c3e54eb | 2012-04-17 19:06:20 -0600 | [diff] [blame] | 1905 | } |
| 1906 | |
Scott Moreau | 9521d5e | 2012-04-19 13:06:17 -0600 | [diff] [blame] | 1907 | static void |
| 1908 | ping_timer_destroy(struct shell_surface *shsurf) |
| 1909 | { |
| 1910 | if (!shsurf || !shsurf->ping_timer) |
| 1911 | return; |
| 1912 | |
| 1913 | if (shsurf->ping_timer->source) |
| 1914 | wl_event_source_remove(shsurf->ping_timer->source); |
| 1915 | |
| 1916 | free(shsurf->ping_timer); |
| 1917 | shsurf->ping_timer = NULL; |
| 1918 | } |
| 1919 | |
Kristian Høgsberg | 97d44aa | 2011-08-26 17:21:20 -0400 | [diff] [blame] | 1920 | static int |
Scott Moreau | ff1db4a | 2012-04-17 19:06:18 -0600 | [diff] [blame] | 1921 | ping_timeout_handler(void *data) |
| 1922 | { |
| 1923 | struct shell_surface *shsurf = data; |
Kristian Høgsberg | d56bd90 | 2012-06-05 09:58:51 -0400 | [diff] [blame] | 1924 | struct weston_seat *seat; |
Scott Moreau | ff1db4a | 2012-04-17 19:06:18 -0600 | [diff] [blame] | 1925 | |
Scott Moreau | 9521d5e | 2012-04-19 13:06:17 -0600 | [diff] [blame] | 1926 | /* Client is not responding */ |
| 1927 | shsurf->unresponsive = 1; |
Kristian Høgsberg | d56bd90 | 2012-06-05 09:58:51 -0400 | [diff] [blame] | 1928 | |
| 1929 | wl_list_for_each(seat, &shsurf->surface->compositor->seat_list, link) |
Emilio Pozuelo Monfort | 3d0fc76 | 2013-11-22 16:21:20 +0100 | [diff] [blame] | 1930 | if (seat->pointer->focus && |
| 1931 | seat->pointer->focus->surface == shsurf->surface) |
Kristian Høgsberg | e314875 | 2013-05-06 23:19:49 -0400 | [diff] [blame] | 1932 | set_busy_cursor(shsurf, seat->pointer); |
Scott Moreau | ff1db4a | 2012-04-17 19:06:18 -0600 | [diff] [blame] | 1933 | |
| 1934 | return 1; |
| 1935 | } |
| 1936 | |
| 1937 | static void |
| 1938 | ping_handler(struct weston_surface *surface, uint32_t serial) |
| 1939 | { |
Kristian Høgsberg | b71302e | 2012-05-10 12:28:35 -0400 | [diff] [blame] | 1940 | struct shell_surface *shsurf = get_shell_surface(surface); |
Scott Moreau | ff1db4a | 2012-04-17 19:06:18 -0600 | [diff] [blame] | 1941 | struct wl_event_loop *loop; |
Kristian Høgsberg | d56bd90 | 2012-06-05 09:58:51 -0400 | [diff] [blame] | 1942 | int ping_timeout = 200; |
Scott Moreau | ff1db4a | 2012-04-17 19:06:18 -0600 | [diff] [blame] | 1943 | |
| 1944 | if (!shsurf) |
| 1945 | return; |
Jason Ekstrand | 651f00e | 2013-06-14 10:07:54 -0500 | [diff] [blame] | 1946 | if (!shsurf->resource) |
Kristian Høgsberg | ca535c1 | 2012-04-21 23:20:07 -0400 | [diff] [blame] | 1947 | return; |
Scott Moreau | ff1db4a | 2012-04-17 19:06:18 -0600 | [diff] [blame] | 1948 | |
Ander Conselvan de Oliveira | eac9a46 | 2012-07-16 14:15:48 +0300 | [diff] [blame] | 1949 | if (shsurf->surface == shsurf->shell->grab_surface) |
| 1950 | return; |
| 1951 | |
Scott Moreau | ff1db4a | 2012-04-17 19:06:18 -0600 | [diff] [blame] | 1952 | if (!shsurf->ping_timer) { |
Ander Conselvan de Oliveira | fb98089 | 2012-04-27 13:55:55 +0300 | [diff] [blame] | 1953 | shsurf->ping_timer = malloc(sizeof *shsurf->ping_timer); |
Scott Moreau | ff1db4a | 2012-04-17 19:06:18 -0600 | [diff] [blame] | 1954 | if (!shsurf->ping_timer) |
| 1955 | return; |
| 1956 | |
| 1957 | shsurf->ping_timer->serial = serial; |
Scott Moreau | ff1db4a | 2012-04-17 19:06:18 -0600 | [diff] [blame] | 1958 | loop = wl_display_get_event_loop(surface->compositor->wl_display); |
| 1959 | shsurf->ping_timer->source = |
| 1960 | wl_event_loop_add_timer(loop, ping_timeout_handler, shsurf); |
| 1961 | wl_event_source_timer_update(shsurf->ping_timer->source, ping_timeout); |
| 1962 | |
Jason Ekstrand | 651f00e | 2013-06-14 10:07:54 -0500 | [diff] [blame] | 1963 | wl_shell_surface_send_ping(shsurf->resource, serial); |
Scott Moreau | ff1db4a | 2012-04-17 19:06:18 -0600 | [diff] [blame] | 1964 | } |
| 1965 | } |
| 1966 | |
| 1967 | static void |
Kristian Høgsberg | d56bd90 | 2012-06-05 09:58:51 -0400 | [diff] [blame] | 1968 | handle_pointer_focus(struct wl_listener *listener, void *data) |
| 1969 | { |
Kristian Høgsberg | 02bbabb | 2013-05-06 22:15:05 -0400 | [diff] [blame] | 1970 | struct weston_pointer *pointer = data; |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 1971 | struct weston_view *view = pointer->focus; |
Kristian Høgsberg | d56bd90 | 2012-06-05 09:58:51 -0400 | [diff] [blame] | 1972 | struct weston_compositor *compositor; |
| 1973 | struct shell_surface *shsurf; |
| 1974 | uint32_t serial; |
| 1975 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 1976 | if (!view) |
Kristian Høgsberg | d56bd90 | 2012-06-05 09:58:51 -0400 | [diff] [blame] | 1977 | return; |
| 1978 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 1979 | compositor = view->surface->compositor; |
| 1980 | shsurf = get_shell_surface(view->surface); |
Kristian Høgsberg | d56bd90 | 2012-06-05 09:58:51 -0400 | [diff] [blame] | 1981 | |
Pekka Paalanen | 4e1f2ff | 2012-06-06 16:59:45 +0300 | [diff] [blame] | 1982 | if (shsurf && shsurf->unresponsive) { |
Kristian Høgsberg | d56bd90 | 2012-06-05 09:58:51 -0400 | [diff] [blame] | 1983 | set_busy_cursor(shsurf, pointer); |
| 1984 | } else { |
| 1985 | serial = wl_display_next_serial(compositor->wl_display); |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 1986 | ping_handler(view->surface, serial); |
Kristian Høgsberg | d56bd90 | 2012-06-05 09:58:51 -0400 | [diff] [blame] | 1987 | } |
| 1988 | } |
| 1989 | |
| 1990 | static void |
Kristian Høgsberg | f4d2f23 | 2012-08-10 10:05:39 -0400 | [diff] [blame] | 1991 | create_pointer_focus_listener(struct weston_seat *seat) |
| 1992 | { |
| 1993 | struct wl_listener *listener; |
| 1994 | |
Kristian Høgsberg | e314875 | 2013-05-06 23:19:49 -0400 | [diff] [blame] | 1995 | if (!seat->pointer) |
Kristian Høgsberg | f4d2f23 | 2012-08-10 10:05:39 -0400 | [diff] [blame] | 1996 | return; |
| 1997 | |
| 1998 | listener = malloc(sizeof *listener); |
| 1999 | listener->notify = handle_pointer_focus; |
Kristian Høgsberg | e314875 | 2013-05-06 23:19:49 -0400 | [diff] [blame] | 2000 | wl_signal_add(&seat->pointer->focus_signal, listener); |
Kristian Høgsberg | f4d2f23 | 2012-08-10 10:05:39 -0400 | [diff] [blame] | 2001 | } |
| 2002 | |
| 2003 | static void |
Scott Moreau | ff1db4a | 2012-04-17 19:06:18 -0600 | [diff] [blame] | 2004 | shell_surface_pong(struct wl_client *client, struct wl_resource *resource, |
| 2005 | uint32_t serial) |
| 2006 | { |
Jason Ekstrand | 651f00e | 2013-06-14 10:07:54 -0500 | [diff] [blame] | 2007 | struct shell_surface *shsurf = wl_resource_get_user_data(resource); |
Kristian Høgsberg | d56bd90 | 2012-06-05 09:58:51 -0400 | [diff] [blame] | 2008 | struct weston_seat *seat; |
| 2009 | struct weston_compositor *ec = shsurf->surface->compositor; |
Scott Moreau | ff1db4a | 2012-04-17 19:06:18 -0600 | [diff] [blame] | 2010 | |
Kristian Høgsberg | 92374e1 | 2012-08-11 22:39:12 -0400 | [diff] [blame] | 2011 | if (shsurf->ping_timer == NULL) |
| 2012 | /* Just ignore unsolicited pong. */ |
| 2013 | return; |
| 2014 | |
Scott Moreau | ff1db4a | 2012-04-17 19:06:18 -0600 | [diff] [blame] | 2015 | if (shsurf->ping_timer->serial == serial) { |
Scott Moreau | ff1db4a | 2012-04-17 19:06:18 -0600 | [diff] [blame] | 2016 | shsurf->unresponsive = 0; |
Hardening | eb1e130 | 2013-05-17 18:07:41 +0200 | [diff] [blame] | 2017 | wl_list_for_each(seat, &ec->seat_list, link) { |
| 2018 | if(seat->pointer) |
| 2019 | end_busy_cursor(shsurf, seat->pointer); |
| 2020 | } |
Scott Moreau | 9521d5e | 2012-04-19 13:06:17 -0600 | [diff] [blame] | 2021 | ping_timer_destroy(shsurf); |
Scott Moreau | ff1db4a | 2012-04-17 19:06:18 -0600 | [diff] [blame] | 2022 | } |
| 2023 | } |
| 2024 | |
Kristian Høgsberg | e7afd91 | 2012-05-02 09:47:44 -0400 | [diff] [blame] | 2025 | static void |
Giulio Camuffo | 62942ad | 2013-09-11 18:20:47 +0200 | [diff] [blame] | 2026 | set_title(struct shell_surface *shsurf, const char *title) |
| 2027 | { |
| 2028 | free(shsurf->title); |
| 2029 | shsurf->title = strdup(title); |
| 2030 | } |
| 2031 | |
| 2032 | static void |
Kristian Høgsberg | e7afd91 | 2012-05-02 09:47:44 -0400 | [diff] [blame] | 2033 | shell_surface_set_title(struct wl_client *client, |
| 2034 | struct wl_resource *resource, const char *title) |
| 2035 | { |
Jason Ekstrand | 651f00e | 2013-06-14 10:07:54 -0500 | [diff] [blame] | 2036 | struct shell_surface *shsurf = wl_resource_get_user_data(resource); |
Kristian Høgsberg | e7afd91 | 2012-05-02 09:47:44 -0400 | [diff] [blame] | 2037 | |
Giulio Camuffo | 62942ad | 2013-09-11 18:20:47 +0200 | [diff] [blame] | 2038 | set_title(shsurf, title); |
Kristian Høgsberg | e7afd91 | 2012-05-02 09:47:44 -0400 | [diff] [blame] | 2039 | } |
| 2040 | |
| 2041 | static void |
| 2042 | shell_surface_set_class(struct wl_client *client, |
| 2043 | struct wl_resource *resource, const char *class) |
| 2044 | { |
Jason Ekstrand | 651f00e | 2013-06-14 10:07:54 -0500 | [diff] [blame] | 2045 | struct shell_surface *shsurf = wl_resource_get_user_data(resource); |
Kristian Høgsberg | e7afd91 | 2012-05-02 09:47:44 -0400 | [diff] [blame] | 2046 | |
| 2047 | free(shsurf->class); |
| 2048 | shsurf->class = strdup(class); |
| 2049 | } |
| 2050 | |
Alex Wu | 4539b08 | 2012-03-01 12:57:46 +0800 | [diff] [blame] | 2051 | static void |
Alexander Larsson | f82b6ca | 2013-05-28 16:23:39 +0200 | [diff] [blame] | 2052 | restore_output_mode(struct weston_output *output) |
| 2053 | { |
Hardening | 57388e4 | 2013-09-18 23:56:36 +0200 | [diff] [blame] | 2054 | if (output->current_mode != output->original_mode || |
| 2055 | (int32_t)output->current_scale != output->original_scale) |
Alexander Larsson | f82b6ca | 2013-05-28 16:23:39 +0200 | [diff] [blame] | 2056 | weston_output_switch_mode(output, |
Hardening | 57388e4 | 2013-09-18 23:56:36 +0200 | [diff] [blame] | 2057 | output->original_mode, |
| 2058 | output->original_scale, |
| 2059 | WESTON_MODE_SWITCH_RESTORE_NATIVE); |
Alexander Larsson | f82b6ca | 2013-05-28 16:23:39 +0200 | [diff] [blame] | 2060 | } |
| 2061 | |
| 2062 | static void |
| 2063 | restore_all_output_modes(struct weston_compositor *compositor) |
| 2064 | { |
| 2065 | struct weston_output *output; |
| 2066 | |
| 2067 | wl_list_for_each(output, &compositor->output_list, link) |
| 2068 | restore_output_mode(output); |
| 2069 | } |
| 2070 | |
Philip Withnall | becb77e | 2013-11-25 18:01:30 +0000 | [diff] [blame] | 2071 | static int |
| 2072 | get_output_panel_height(struct desktop_shell *shell, |
| 2073 | struct weston_output *output) |
| 2074 | { |
| 2075 | struct weston_view *view; |
| 2076 | int panel_height = 0; |
| 2077 | |
| 2078 | if (!output) |
| 2079 | return 0; |
| 2080 | |
| 2081 | wl_list_for_each(view, &shell->panel_layer.view_list, layer_link) { |
| 2082 | if (view->surface->output == output) { |
Jason Ekstrand | 918f2dd | 2013-12-02 21:01:53 -0600 | [diff] [blame] | 2083 | panel_height = view->surface->height; |
Philip Withnall | becb77e | 2013-11-25 18:01:30 +0000 | [diff] [blame] | 2084 | break; |
| 2085 | } |
| 2086 | } |
| 2087 | |
| 2088 | return panel_height; |
| 2089 | } |
| 2090 | |
Philip Withnall | 07926d9 | 2013-11-25 18:01:40 +0000 | [diff] [blame] | 2091 | /* The surface will be inserted into the list immediately after the link |
| 2092 | * returned by this function (i.e. will be stacked immediately above the |
| 2093 | * returned link). */ |
| 2094 | static struct wl_list * |
| 2095 | shell_surface_calculate_layer_link (struct shell_surface *shsurf) |
| 2096 | { |
| 2097 | struct workspace *ws; |
| 2098 | |
| 2099 | switch (shsurf->type) { |
Philip Withnall | da704d9 | 2013-11-25 18:01:46 +0000 | [diff] [blame] | 2100 | case SHELL_SURFACE_POPUP: { |
| 2101 | /* Popups should go at the front of the workspace of their |
| 2102 | * parent surface, rather than just in front of the parent. This |
| 2103 | * fixes the situation where there are two top-level windows: |
| 2104 | * - Above |
| 2105 | * - Below |
| 2106 | * and a pop-up menu is created for 'Below'. We want: |
| 2107 | * - Popup |
| 2108 | * - Above |
| 2109 | * - Below |
| 2110 | * not: |
| 2111 | * - Above |
| 2112 | * - Popup |
| 2113 | * - Below |
| 2114 | */ |
| 2115 | struct shell_surface *parent_shsurf; |
| 2116 | |
| 2117 | parent_shsurf = get_shell_surface(shsurf->parent); |
| 2118 | if (parent_shsurf != NULL) |
| 2119 | return shell_surface_calculate_layer_link(parent_shsurf); |
| 2120 | |
| 2121 | break; |
| 2122 | } |
| 2123 | |
Rafael Antognolli | 03b1659 | 2013-12-03 15:35:42 -0200 | [diff] [blame] | 2124 | case SHELL_SURFACE_TOPLEVEL: { |
Rafael Antognolli | ed207b4 | 2013-12-03 15:35:43 -0200 | [diff] [blame^] | 2125 | if (shsurf->state.fullscreen) { |
Rafael Antognolli | 03b1659 | 2013-12-03 15:35:42 -0200 | [diff] [blame] | 2126 | return &shsurf->shell->fullscreen_layer.view_list; |
Rafael Antognolli | ed207b4 | 2013-12-03 15:35:43 -0200 | [diff] [blame^] | 2127 | } else if (shsurf->parent) { |
| 2128 | /* Move the surface to its parent layer so that |
| 2129 | * surfaces which are transient for fullscreen surfaces |
| 2130 | * don't get hidden by the fullscreen surfaces. |
| 2131 | * However, unlike popups, transient surfaces are |
| 2132 | * stacked in front of their parent but not in front of |
| 2133 | * other surfaces of the same type. */ |
| 2134 | struct weston_view *parent; |
| 2135 | |
| 2136 | /* TODO: Handle a parent with multiple views */ |
| 2137 | parent = get_default_view(shsurf->parent); |
| 2138 | if (parent) |
| 2139 | return parent->layer_link.prev; |
| 2140 | } |
Rafael Antognolli | 03b1659 | 2013-12-03 15:35:42 -0200 | [diff] [blame] | 2141 | break; |
| 2142 | } |
Philip Withnall | 07926d9 | 2013-11-25 18:01:40 +0000 | [diff] [blame] | 2143 | |
| 2144 | case SHELL_SURFACE_XWAYLAND: |
Philip Withnall | 07926d9 | 2013-11-25 18:01:40 +0000 | [diff] [blame] | 2145 | case SHELL_SURFACE_NONE: |
| 2146 | default: |
| 2147 | /* Go to the fallback, below. */ |
| 2148 | break; |
| 2149 | } |
| 2150 | |
| 2151 | /* Move the surface to a normal workspace layer so that surfaces |
| 2152 | * which were previously fullscreen or transient are no longer |
| 2153 | * rendered on top. */ |
| 2154 | ws = get_current_workspace(shsurf->shell); |
| 2155 | return &ws->layer.view_list; |
| 2156 | } |
| 2157 | |
Philip Withnall | 648a4dd | 2013-11-25 18:01:44 +0000 | [diff] [blame] | 2158 | static void |
| 2159 | shell_surface_update_child_surface_layers (struct shell_surface *shsurf) |
| 2160 | { |
| 2161 | struct shell_surface *child; |
| 2162 | |
| 2163 | /* Move the child layers to the same workspace as shsurf. They will be |
| 2164 | * stacked above shsurf. */ |
| 2165 | wl_list_for_each_reverse(child, &shsurf->children_list, children_link) { |
| 2166 | if (shsurf->view->layer_link.prev != &child->view->layer_link) { |
| 2167 | weston_view_geometry_dirty(child->view); |
| 2168 | wl_list_remove(&child->view->layer_link); |
| 2169 | wl_list_insert(shsurf->view->layer_link.prev, |
| 2170 | &child->view->layer_link); |
| 2171 | weston_view_geometry_dirty(child->view); |
| 2172 | weston_surface_damage(child->surface); |
| 2173 | |
| 2174 | /* Recurse. We don’t expect this to recurse very far (if |
| 2175 | * at all) because that would imply we have transient |
| 2176 | * (or popup) children of transient surfaces, which |
| 2177 | * would be unusual. */ |
| 2178 | shell_surface_update_child_surface_layers(child); |
| 2179 | } |
| 2180 | } |
| 2181 | } |
| 2182 | |
Philip Withnall | e1d75ae | 2013-11-25 18:01:41 +0000 | [diff] [blame] | 2183 | /* 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] | 2184 | * geometry to ensure the changes are redrawn. |
| 2185 | * |
| 2186 | * If any child surfaces exist and are mapped, ensure they’re in the same layer |
| 2187 | * as this surface. */ |
Philip Withnall | e1d75ae | 2013-11-25 18:01:41 +0000 | [diff] [blame] | 2188 | static void |
| 2189 | shell_surface_update_layer(struct shell_surface *shsurf) |
| 2190 | { |
| 2191 | struct wl_list *new_layer_link; |
| 2192 | |
| 2193 | new_layer_link = shell_surface_calculate_layer_link(shsurf); |
| 2194 | |
| 2195 | if (new_layer_link == &shsurf->view->layer_link) |
| 2196 | return; |
| 2197 | |
| 2198 | weston_view_geometry_dirty(shsurf->view); |
| 2199 | wl_list_remove(&shsurf->view->layer_link); |
| 2200 | wl_list_insert(new_layer_link, &shsurf->view->layer_link); |
| 2201 | weston_view_geometry_dirty(shsurf->view); |
| 2202 | weston_surface_damage(shsurf->surface); |
Philip Withnall | 648a4dd | 2013-11-25 18:01:44 +0000 | [diff] [blame] | 2203 | |
| 2204 | shell_surface_update_child_surface_layers(shsurf); |
Philip Withnall | e1d75ae | 2013-11-25 18:01:41 +0000 | [diff] [blame] | 2205 | } |
| 2206 | |
Alexander Larsson | f82b6ca | 2013-05-28 16:23:39 +0200 | [diff] [blame] | 2207 | static void |
Philip Withnall | dc4332f | 2013-11-25 18:01:38 +0000 | [diff] [blame] | 2208 | shell_surface_set_parent(struct shell_surface *shsurf, |
| 2209 | struct weston_surface *parent) |
| 2210 | { |
| 2211 | shsurf->parent = parent; |
Philip Withnall | 648a4dd | 2013-11-25 18:01:44 +0000 | [diff] [blame] | 2212 | |
| 2213 | wl_list_remove(&shsurf->children_link); |
| 2214 | wl_list_init(&shsurf->children_link); |
| 2215 | |
| 2216 | /* Insert into the parent surface’s child list. */ |
| 2217 | if (parent != NULL) { |
| 2218 | struct shell_surface *parent_shsurf = get_shell_surface(parent); |
| 2219 | if (parent_shsurf != NULL) |
| 2220 | wl_list_insert(&parent_shsurf->children_list, |
| 2221 | &shsurf->children_link); |
| 2222 | } |
Philip Withnall | dc4332f | 2013-11-25 18:01:38 +0000 | [diff] [blame] | 2223 | } |
| 2224 | |
| 2225 | static void |
Philip Withnall | 352e7ed | 2013-11-25 18:01:35 +0000 | [diff] [blame] | 2226 | shell_surface_set_output(struct shell_surface *shsurf, |
| 2227 | struct weston_output *output) |
| 2228 | { |
| 2229 | struct weston_surface *es = shsurf->surface; |
| 2230 | |
| 2231 | /* get the default output, if the client set it as NULL |
| 2232 | check whether the ouput is available */ |
| 2233 | if (output) |
| 2234 | shsurf->output = output; |
| 2235 | else if (es->output) |
| 2236 | shsurf->output = es->output; |
| 2237 | else |
| 2238 | shsurf->output = get_default_output(es->compositor); |
| 2239 | } |
| 2240 | |
| 2241 | static void |
Rafael Antognolli | 03b1659 | 2013-12-03 15:35:42 -0200 | [diff] [blame] | 2242 | surface_clear_next_states(struct shell_surface *shsurf) |
| 2243 | { |
| 2244 | shsurf->next_state.maximized = false; |
| 2245 | shsurf->next_state.fullscreen = false; |
| 2246 | |
| 2247 | if ((shsurf->next_state.maximized != shsurf->state.maximized) || |
| 2248 | (shsurf->next_state.fullscreen != shsurf->state.fullscreen)) |
| 2249 | shsurf->state_changed = true; |
| 2250 | } |
| 2251 | |
| 2252 | static void |
Philip Withnall | becb77e | 2013-11-25 18:01:30 +0000 | [diff] [blame] | 2253 | set_toplevel(struct shell_surface *shsurf) |
| 2254 | { |
Philip Withnall | dc4332f | 2013-11-25 18:01:38 +0000 | [diff] [blame] | 2255 | shell_surface_set_parent(shsurf, NULL); |
| 2256 | |
Philip Withnall | becb77e | 2013-11-25 18:01:30 +0000 | [diff] [blame] | 2257 | shsurf->next_type = SHELL_SURFACE_TOPLEVEL; |
Philip Withnall | 648a4dd | 2013-11-25 18:01:44 +0000 | [diff] [blame] | 2258 | |
| 2259 | /* The layer_link is updated in set_surface_type(), |
| 2260 | * called from configure. */ |
Philip Withnall | becb77e | 2013-11-25 18:01:30 +0000 | [diff] [blame] | 2261 | } |
| 2262 | |
| 2263 | static void |
| 2264 | shell_surface_set_toplevel(struct wl_client *client, |
| 2265 | struct wl_resource *resource) |
| 2266 | { |
| 2267 | struct shell_surface *surface = wl_resource_get_user_data(resource); |
| 2268 | |
Rafael Antognolli | 03b1659 | 2013-12-03 15:35:42 -0200 | [diff] [blame] | 2269 | surface_clear_next_states(surface); |
Philip Withnall | becb77e | 2013-11-25 18:01:30 +0000 | [diff] [blame] | 2270 | set_toplevel(surface); |
| 2271 | } |
| 2272 | |
| 2273 | static void |
| 2274 | set_transient(struct shell_surface *shsurf, |
| 2275 | struct weston_surface *parent, int x, int y, uint32_t flags) |
| 2276 | { |
Philip Withnall | dc4332f | 2013-11-25 18:01:38 +0000 | [diff] [blame] | 2277 | assert(parent != NULL); |
| 2278 | |
Philip Withnall | becb77e | 2013-11-25 18:01:30 +0000 | [diff] [blame] | 2279 | shsurf->transient.x = x; |
| 2280 | shsurf->transient.y = y; |
| 2281 | shsurf->transient.flags = flags; |
Philip Withnall | dc4332f | 2013-11-25 18:01:38 +0000 | [diff] [blame] | 2282 | |
| 2283 | shell_surface_set_parent(shsurf, parent); |
| 2284 | |
Rafael Antognolli | ed207b4 | 2013-12-03 15:35:43 -0200 | [diff] [blame^] | 2285 | shsurf->next_state.relative = true; |
Philip Withnall | 648a4dd | 2013-11-25 18:01:44 +0000 | [diff] [blame] | 2286 | |
| 2287 | /* The layer_link is updated in set_surface_type(), |
| 2288 | * called from configure. */ |
Philip Withnall | becb77e | 2013-11-25 18:01:30 +0000 | [diff] [blame] | 2289 | } |
| 2290 | |
| 2291 | static void |
| 2292 | shell_surface_set_transient(struct wl_client *client, |
| 2293 | struct wl_resource *resource, |
| 2294 | struct wl_resource *parent_resource, |
| 2295 | int x, int y, uint32_t flags) |
| 2296 | { |
| 2297 | struct shell_surface *shsurf = wl_resource_get_user_data(resource); |
| 2298 | struct weston_surface *parent = |
| 2299 | wl_resource_get_user_data(parent_resource); |
| 2300 | |
Rafael Antognolli | 03b1659 | 2013-12-03 15:35:42 -0200 | [diff] [blame] | 2301 | surface_clear_next_states(shsurf); |
Philip Withnall | becb77e | 2013-11-25 18:01:30 +0000 | [diff] [blame] | 2302 | set_transient(shsurf, parent, x, y, flags); |
| 2303 | } |
| 2304 | |
| 2305 | static void |
| 2306 | set_fullscreen(struct shell_surface *shsurf, |
| 2307 | uint32_t method, |
| 2308 | uint32_t framerate, |
| 2309 | struct weston_output *output) |
| 2310 | { |
Philip Withnall | 352e7ed | 2013-11-25 18:01:35 +0000 | [diff] [blame] | 2311 | shell_surface_set_output(shsurf, output); |
Philip Withnall | becb77e | 2013-11-25 18:01:30 +0000 | [diff] [blame] | 2312 | |
| 2313 | shsurf->fullscreen_output = shsurf->output; |
| 2314 | shsurf->fullscreen.type = method; |
| 2315 | shsurf->fullscreen.framerate = framerate; |
Philip Withnall | dc4332f | 2013-11-25 18:01:38 +0000 | [diff] [blame] | 2316 | |
| 2317 | shell_surface_set_parent(shsurf, NULL); |
| 2318 | |
Rafael Antognolli | 03b1659 | 2013-12-03 15:35:42 -0200 | [diff] [blame] | 2319 | shsurf->next_type = shsurf->type; |
Philip Withnall | becb77e | 2013-11-25 18:01:30 +0000 | [diff] [blame] | 2320 | |
| 2321 | shsurf->client->send_configure(shsurf->surface, 0, |
| 2322 | shsurf->output->width, |
| 2323 | shsurf->output->height); |
Philip Withnall | 648a4dd | 2013-11-25 18:01:44 +0000 | [diff] [blame] | 2324 | |
| 2325 | /* The layer_link is updated in set_surface_type(), |
| 2326 | * called from configure. */ |
Philip Withnall | becb77e | 2013-11-25 18:01:30 +0000 | [diff] [blame] | 2327 | } |
| 2328 | |
| 2329 | static void |
| 2330 | unset_fullscreen(struct shell_surface *shsurf) |
Alex Wu | 4539b08 | 2012-03-01 12:57:46 +0800 | [diff] [blame] | 2331 | { |
Philip Withnall | f85fe84 | 2013-11-25 18:01:37 +0000 | [diff] [blame] | 2332 | /* Unset the fullscreen output, driver configuration and transforms. */ |
Alex Wu | bd3354b | 2012-04-17 17:20:49 +0800 | [diff] [blame] | 2333 | if (shsurf->fullscreen.type == WL_SHELL_SURFACE_FULLSCREEN_METHOD_DRIVER && |
| 2334 | shell_surface_is_top_fullscreen(shsurf)) { |
Alexander Larsson | f82b6ca | 2013-05-28 16:23:39 +0200 | [diff] [blame] | 2335 | restore_output_mode(shsurf->fullscreen_output); |
Alex Wu | bd3354b | 2012-04-17 17:20:49 +0800 | [diff] [blame] | 2336 | } |
Philip Withnall | f85fe84 | 2013-11-25 18:01:37 +0000 | [diff] [blame] | 2337 | shsurf->fullscreen_output = NULL; |
| 2338 | |
Alex Wu | 4539b08 | 2012-03-01 12:57:46 +0800 | [diff] [blame] | 2339 | shsurf->fullscreen.type = WL_SHELL_SURFACE_FULLSCREEN_METHOD_DEFAULT; |
| 2340 | shsurf->fullscreen.framerate = 0; |
Philip Withnall | f85fe84 | 2013-11-25 18:01:37 +0000 | [diff] [blame] | 2341 | |
Alex Wu | 4539b08 | 2012-03-01 12:57:46 +0800 | [diff] [blame] | 2342 | wl_list_remove(&shsurf->fullscreen.transform.link); |
| 2343 | wl_list_init(&shsurf->fullscreen.transform.link); |
Philip Withnall | f85fe84 | 2013-11-25 18:01:37 +0000 | [diff] [blame] | 2344 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 2345 | if (shsurf->fullscreen.black_view) |
| 2346 | weston_surface_destroy(shsurf->fullscreen.black_view->surface); |
| 2347 | shsurf->fullscreen.black_view = NULL; |
Philip Withnall | f85fe84 | 2013-11-25 18:01:37 +0000 | [diff] [blame] | 2348 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 2349 | weston_view_set_position(shsurf->view, |
| 2350 | shsurf->saved_x, shsurf->saved_y); |
Alex Wu | 7bcb8bd | 2012-04-27 09:07:24 +0800 | [diff] [blame] | 2351 | if (shsurf->saved_rotation_valid) { |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 2352 | wl_list_insert(&shsurf->view->geometry.transformation_list, |
Philip Withnall | becb77e | 2013-11-25 18:01:30 +0000 | [diff] [blame] | 2353 | &shsurf->rotation.transform.link); |
Alex Wu | 7bcb8bd | 2012-04-27 09:07:24 +0800 | [diff] [blame] | 2354 | shsurf->saved_rotation_valid = false; |
| 2355 | } |
Rafal Mielniczuk | 3e3862c | 2012-10-07 20:25:36 +0200 | [diff] [blame] | 2356 | |
Philip Withnall | e1d75ae | 2013-11-25 18:01:41 +0000 | [diff] [blame] | 2357 | /* Layer is updated in set_surface_type(). */ |
Alex Wu | 4539b08 | 2012-03-01 12:57:46 +0800 | [diff] [blame] | 2358 | } |
| 2359 | |
Rafal Mielniczuk | fffdcdd | 2013-03-11 19:26:54 +0100 | [diff] [blame] | 2360 | static void |
Philip Withnall | becb77e | 2013-11-25 18:01:30 +0000 | [diff] [blame] | 2361 | shell_surface_set_fullscreen(struct wl_client *client, |
| 2362 | struct wl_resource *resource, |
| 2363 | uint32_t method, |
| 2364 | uint32_t framerate, |
| 2365 | struct wl_resource *output_resource) |
| 2366 | { |
| 2367 | struct shell_surface *shsurf = wl_resource_get_user_data(resource); |
| 2368 | struct weston_output *output; |
| 2369 | |
| 2370 | if (output_resource) |
| 2371 | output = wl_resource_get_user_data(output_resource); |
| 2372 | else |
| 2373 | output = NULL; |
| 2374 | |
Rafael Antognolli | 03b1659 | 2013-12-03 15:35:42 -0200 | [diff] [blame] | 2375 | surface_clear_next_states(shsurf); |
| 2376 | shsurf->next_state.fullscreen = true; |
| 2377 | shsurf->state_changed = true; |
Philip Withnall | becb77e | 2013-11-25 18:01:30 +0000 | [diff] [blame] | 2378 | set_fullscreen(shsurf, method, framerate, output); |
| 2379 | } |
| 2380 | |
| 2381 | static void |
| 2382 | set_popup(struct shell_surface *shsurf, |
| 2383 | struct weston_surface *parent, |
| 2384 | struct weston_seat *seat, |
| 2385 | uint32_t serial, |
| 2386 | int32_t x, |
| 2387 | int32_t y) |
| 2388 | { |
Philip Withnall | dc4332f | 2013-11-25 18:01:38 +0000 | [diff] [blame] | 2389 | assert(parent != NULL); |
| 2390 | |
Philip Withnall | becb77e | 2013-11-25 18:01:30 +0000 | [diff] [blame] | 2391 | shsurf->popup.shseat = get_shell_seat(seat); |
| 2392 | shsurf->popup.serial = serial; |
| 2393 | shsurf->popup.x = x; |
| 2394 | shsurf->popup.y = y; |
Philip Withnall | dc4332f | 2013-11-25 18:01:38 +0000 | [diff] [blame] | 2395 | |
| 2396 | shell_surface_set_parent(shsurf, parent); |
Philip Withnall | b995e1d | 2013-11-25 18:01:39 +0000 | [diff] [blame] | 2397 | |
| 2398 | shsurf->next_type = SHELL_SURFACE_POPUP; |
Philip Withnall | becb77e | 2013-11-25 18:01:30 +0000 | [diff] [blame] | 2399 | } |
| 2400 | |
| 2401 | static void |
| 2402 | shell_surface_set_popup(struct wl_client *client, |
| 2403 | struct wl_resource *resource, |
| 2404 | struct wl_resource *seat_resource, |
| 2405 | uint32_t serial, |
| 2406 | struct wl_resource *parent_resource, |
| 2407 | int32_t x, int32_t y, uint32_t flags) |
| 2408 | { |
| 2409 | struct shell_surface *shsurf = wl_resource_get_user_data(resource); |
| 2410 | |
Rafael Antognolli | 03b1659 | 2013-12-03 15:35:42 -0200 | [diff] [blame] | 2411 | surface_clear_next_states(shsurf); |
Philip Withnall | becb77e | 2013-11-25 18:01:30 +0000 | [diff] [blame] | 2412 | set_popup(shsurf, |
| 2413 | wl_resource_get_user_data(parent_resource), |
| 2414 | wl_resource_get_user_data(seat_resource), |
| 2415 | serial, x, y); |
| 2416 | } |
| 2417 | |
| 2418 | static void |
| 2419 | set_maximized(struct shell_surface *shsurf, |
| 2420 | struct weston_output *output) |
| 2421 | { |
| 2422 | struct desktop_shell *shell; |
| 2423 | uint32_t edges = 0, panel_height = 0; |
Philip Withnall | becb77e | 2013-11-25 18:01:30 +0000 | [diff] [blame] | 2424 | |
Philip Withnall | 352e7ed | 2013-11-25 18:01:35 +0000 | [diff] [blame] | 2425 | shell_surface_set_output(shsurf, output); |
Philip Withnall | becb77e | 2013-11-25 18:01:30 +0000 | [diff] [blame] | 2426 | |
| 2427 | shell = shell_surface_get_shell(shsurf); |
| 2428 | panel_height = get_output_panel_height(shell, shsurf->output); |
| 2429 | edges = WL_SHELL_SURFACE_RESIZE_TOP | WL_SHELL_SURFACE_RESIZE_LEFT; |
| 2430 | |
| 2431 | shsurf->client->send_configure(shsurf->surface, edges, |
| 2432 | shsurf->output->width, |
| 2433 | shsurf->output->height - panel_height); |
| 2434 | |
Philip Withnall | dc4332f | 2013-11-25 18:01:38 +0000 | [diff] [blame] | 2435 | shell_surface_set_parent(shsurf, NULL); |
| 2436 | |
Rafael Antognolli | 03b1659 | 2013-12-03 15:35:42 -0200 | [diff] [blame] | 2437 | shsurf->next_type = shsurf->type; |
Philip Withnall | becb77e | 2013-11-25 18:01:30 +0000 | [diff] [blame] | 2438 | } |
| 2439 | |
| 2440 | static void |
| 2441 | unset_maximized(struct shell_surface *shsurf) |
Rafal Mielniczuk | fffdcdd | 2013-03-11 19:26:54 +0100 | [diff] [blame] | 2442 | { |
Rafal Mielniczuk | fffdcdd | 2013-03-11 19:26:54 +0100 | [diff] [blame] | 2443 | /* undo all maximized things here */ |
| 2444 | shsurf->output = get_default_output(shsurf->surface->compositor); |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 2445 | weston_view_set_position(shsurf->view, |
| 2446 | shsurf->saved_x, |
| 2447 | shsurf->saved_y); |
Rafal Mielniczuk | fffdcdd | 2013-03-11 19:26:54 +0100 | [diff] [blame] | 2448 | |
| 2449 | if (shsurf->saved_rotation_valid) { |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 2450 | wl_list_insert(&shsurf->view->geometry.transformation_list, |
| 2451 | &shsurf->rotation.transform.link); |
Rafal Mielniczuk | fffdcdd | 2013-03-11 19:26:54 +0100 | [diff] [blame] | 2452 | shsurf->saved_rotation_valid = false; |
| 2453 | } |
| 2454 | |
Philip Withnall | e1d75ae | 2013-11-25 18:01:41 +0000 | [diff] [blame] | 2455 | /* Layer is updated in set_surface_type(). */ |
Rafal Mielniczuk | fffdcdd | 2013-03-11 19:26:54 +0100 | [diff] [blame] | 2456 | } |
| 2457 | |
Philip Withnall | becb77e | 2013-11-25 18:01:30 +0000 | [diff] [blame] | 2458 | static void |
| 2459 | shell_surface_set_maximized(struct wl_client *client, |
| 2460 | struct wl_resource *resource, |
| 2461 | struct wl_resource *output_resource) |
| 2462 | { |
| 2463 | struct shell_surface *shsurf = wl_resource_get_user_data(resource); |
| 2464 | struct weston_output *output; |
| 2465 | |
| 2466 | if (output_resource) |
| 2467 | output = wl_resource_get_user_data(output_resource); |
| 2468 | else |
| 2469 | output = NULL; |
| 2470 | |
Rafael Antognolli | 03b1659 | 2013-12-03 15:35:42 -0200 | [diff] [blame] | 2471 | surface_clear_next_states(shsurf); |
| 2472 | shsurf->next_state.maximized = true; |
| 2473 | shsurf->state_changed = true; |
Philip Withnall | becb77e | 2013-11-25 18:01:30 +0000 | [diff] [blame] | 2474 | set_maximized(shsurf, output); |
| 2475 | } |
| 2476 | |
Philip Withnall | e1d75ae | 2013-11-25 18:01:41 +0000 | [diff] [blame] | 2477 | /* This is only ever called from set_surface_type(), so there’s no need to |
| 2478 | * update layer_links here, since they’ll be updated when we return. */ |
Pekka Paalanen | 9826223 | 2011-12-01 10:42:22 +0200 | [diff] [blame] | 2479 | static int |
Philip Withnall | becb77e | 2013-11-25 18:01:30 +0000 | [diff] [blame] | 2480 | reset_surface_type(struct shell_surface *surface) |
Pekka Paalanen | 9826223 | 2011-12-01 10:42:22 +0200 | [diff] [blame] | 2481 | { |
Rafael Antognolli | 03b1659 | 2013-12-03 15:35:42 -0200 | [diff] [blame] | 2482 | if (surface->state.fullscreen) |
Philip Withnall | becb77e | 2013-11-25 18:01:30 +0000 | [diff] [blame] | 2483 | unset_fullscreen(surface); |
Rafael Antognolli | 03b1659 | 2013-12-03 15:35:42 -0200 | [diff] [blame] | 2484 | if (surface->state.maximized) |
Philip Withnall | becb77e | 2013-11-25 18:01:30 +0000 | [diff] [blame] | 2485 | unset_maximized(surface); |
Pekka Paalanen | 9826223 | 2011-12-01 10:42:22 +0200 | [diff] [blame] | 2486 | |
| 2487 | surface->type = SHELL_SURFACE_NONE; |
| 2488 | return 0; |
| 2489 | } |
| 2490 | |
Kristian Høgsberg | 4cca349 | 2011-01-18 07:53:49 -0500 | [diff] [blame] | 2491 | static void |
Rafael Antognolli | 03b1659 | 2013-12-03 15:35:42 -0200 | [diff] [blame] | 2492 | set_full_output(struct shell_surface *shsurf) |
| 2493 | { |
| 2494 | shsurf->saved_x = shsurf->view->geometry.x; |
| 2495 | shsurf->saved_y = shsurf->view->geometry.y; |
| 2496 | shsurf->saved_position_valid = true; |
| 2497 | |
| 2498 | if (!wl_list_empty(&shsurf->rotation.transform.link)) { |
| 2499 | wl_list_remove(&shsurf->rotation.transform.link); |
| 2500 | wl_list_init(&shsurf->rotation.transform.link); |
| 2501 | weston_view_geometry_dirty(shsurf->view); |
| 2502 | shsurf->saved_rotation_valid = true; |
| 2503 | } |
| 2504 | } |
| 2505 | |
| 2506 | static void |
Kristian Høgsberg | 7f366e7 | 2012-04-27 17:20:01 -0400 | [diff] [blame] | 2507 | set_surface_type(struct shell_surface *shsurf) |
| 2508 | { |
Kristian Høgsberg | 8150b19 | 2012-06-27 10:22:58 -0400 | [diff] [blame] | 2509 | struct weston_surface *pes = shsurf->parent; |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 2510 | struct weston_view *pev = get_default_view(pes); |
Kristian Høgsberg | 7f366e7 | 2012-04-27 17:20:01 -0400 | [diff] [blame] | 2511 | |
Philip Withnall | becb77e | 2013-11-25 18:01:30 +0000 | [diff] [blame] | 2512 | reset_surface_type(shsurf); |
Kristian Høgsberg | 7f366e7 | 2012-04-27 17:20:01 -0400 | [diff] [blame] | 2513 | |
| 2514 | shsurf->type = shsurf->next_type; |
Rafael Antognolli | 03b1659 | 2013-12-03 15:35:42 -0200 | [diff] [blame] | 2515 | shsurf->state = shsurf->next_state; |
Kristian Høgsberg | 7f366e7 | 2012-04-27 17:20:01 -0400 | [diff] [blame] | 2516 | shsurf->next_type = SHELL_SURFACE_NONE; |
Rafael Antognolli | 03b1659 | 2013-12-03 15:35:42 -0200 | [diff] [blame] | 2517 | shsurf->state_changed = false; |
Kristian Høgsberg | 7f366e7 | 2012-04-27 17:20:01 -0400 | [diff] [blame] | 2518 | |
| 2519 | switch (shsurf->type) { |
| 2520 | case SHELL_SURFACE_TOPLEVEL: |
Rafael Antognolli | ed207b4 | 2013-12-03 15:35:43 -0200 | [diff] [blame^] | 2521 | if (shsurf->state.maximized || shsurf->state.fullscreen) { |
Rafael Antognolli | 03b1659 | 2013-12-03 15:35:42 -0200 | [diff] [blame] | 2522 | set_full_output(shsurf); |
Rafael Antognolli | ed207b4 | 2013-12-03 15:35:43 -0200 | [diff] [blame^] | 2523 | } else if (shsurf->state.relative && pev) { |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 2524 | weston_view_set_position(shsurf->view, |
| 2525 | pev->geometry.x + shsurf->transient.x, |
| 2526 | pev->geometry.y + shsurf->transient.y); |
Rafael Antognolli | ed207b4 | 2013-12-03 15:35:43 -0200 | [diff] [blame^] | 2527 | } |
Kristian Høgsberg | 7f366e7 | 2012-04-27 17:20:01 -0400 | [diff] [blame] | 2528 | |
Tiago Vignatti | fb2adba | 2013-06-12 15:43:21 -0300 | [diff] [blame] | 2529 | case SHELL_SURFACE_XWAYLAND: |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 2530 | weston_view_set_position(shsurf->view, shsurf->transient.x, |
| 2531 | shsurf->transient.y); |
Tiago Vignatti | fb2adba | 2013-06-12 15:43:21 -0300 | [diff] [blame] | 2532 | break; |
| 2533 | |
Philip Withnall | 0f640e2 | 2013-11-25 18:01:31 +0000 | [diff] [blame] | 2534 | case SHELL_SURFACE_POPUP: |
| 2535 | case SHELL_SURFACE_NONE: |
Kristian Høgsberg | 7f366e7 | 2012-04-27 17:20:01 -0400 | [diff] [blame] | 2536 | default: |
| 2537 | break; |
| 2538 | } |
Philip Withnall | e1d75ae | 2013-11-25 18:01:41 +0000 | [diff] [blame] | 2539 | |
| 2540 | /* Update the surface’s layer. */ |
| 2541 | shell_surface_update_layer(shsurf); |
Kristian Høgsberg | 7f366e7 | 2012-04-27 17:20:01 -0400 | [diff] [blame] | 2542 | } |
| 2543 | |
Tiago Vignatti | be14326 | 2012-04-16 17:31:41 +0300 | [diff] [blame] | 2544 | static struct desktop_shell * |
Juan Zhao | 96879df | 2012-02-07 08:45:41 +0800 | [diff] [blame] | 2545 | shell_surface_get_shell(struct shell_surface *shsurf) |
Pekka Paalanen | af0e34c | 2011-12-02 10:59:17 +0200 | [diff] [blame] | 2546 | { |
Kristian Høgsberg | 02e79dc | 2012-04-12 09:55:26 -0400 | [diff] [blame] | 2547 | return shsurf->shell; |
Juan Zhao | 96879df | 2012-02-07 08:45:41 +0800 | [diff] [blame] | 2548 | } |
| 2549 | |
Alex Wu | 2185843 | 2012-04-01 20:13:08 +0800 | [diff] [blame] | 2550 | static void |
Jason Ekstrand | 918f2dd | 2013-12-02 21:01:53 -0600 | [diff] [blame] | 2551 | 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] | 2552 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 2553 | static struct weston_view * |
Alex Wu | 4539b08 | 2012-03-01 12:57:46 +0800 | [diff] [blame] | 2554 | create_black_surface(struct weston_compositor *ec, |
Alex Wu | 2185843 | 2012-04-01 20:13:08 +0800 | [diff] [blame] | 2555 | struct weston_surface *fs_surface, |
John Kåre Alsaker | 490d02a | 2012-09-30 02:57:21 +0200 | [diff] [blame] | 2556 | float x, float y, int w, int h) |
Alex Wu | 4539b08 | 2012-03-01 12:57:46 +0800 | [diff] [blame] | 2557 | { |
| 2558 | struct weston_surface *surface = NULL; |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 2559 | struct weston_view *view; |
Alex Wu | 4539b08 | 2012-03-01 12:57:46 +0800 | [diff] [blame] | 2560 | |
| 2561 | surface = weston_surface_create(ec); |
| 2562 | if (surface == NULL) { |
Martin Minarik | 6d11836 | 2012-06-07 18:01:59 +0200 | [diff] [blame] | 2563 | weston_log("no memory\n"); |
Alex Wu | 4539b08 | 2012-03-01 12:57:46 +0800 | [diff] [blame] | 2564 | return NULL; |
| 2565 | } |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 2566 | view = weston_view_create(surface); |
| 2567 | if (surface == NULL) { |
| 2568 | weston_log("no memory\n"); |
| 2569 | weston_surface_destroy(surface); |
| 2570 | return NULL; |
| 2571 | } |
Alex Wu | 4539b08 | 2012-03-01 12:57:46 +0800 | [diff] [blame] | 2572 | |
Alex Wu | 2185843 | 2012-04-01 20:13:08 +0800 | [diff] [blame] | 2573 | surface->configure = black_surface_configure; |
Giulio Camuffo | 7fe01b1 | 2013-03-28 18:02:42 +0100 | [diff] [blame] | 2574 | surface->configure_private = fs_surface; |
Alex Wu | 4539b08 | 2012-03-01 12:57:46 +0800 | [diff] [blame] | 2575 | weston_surface_set_color(surface, 0.0, 0.0, 0.0, 1); |
Pekka Paalanen | 71f6f3b | 2012-10-10 12:49:26 +0300 | [diff] [blame] | 2576 | pixman_region32_fini(&surface->opaque); |
Kristian Høgsberg | 61f00f5 | 2012-08-03 16:31:36 -0400 | [diff] [blame] | 2577 | pixman_region32_init_rect(&surface->opaque, 0, 0, w, h); |
Jonas Ådahl | 33619a4 | 2013-01-15 21:25:55 +0100 | [diff] [blame] | 2578 | pixman_region32_fini(&surface->input); |
| 2579 | pixman_region32_init_rect(&surface->input, 0, 0, w, h); |
Jason Ekstrand | 918f2dd | 2013-12-02 21:01:53 -0600 | [diff] [blame] | 2580 | |
Xiong Zhang | becf5a3 | 2013-11-29 11:18:14 +0800 | [diff] [blame] | 2581 | surface->width = w; |
| 2582 | surface->height = h; |
Jason Ekstrand | 918f2dd | 2013-12-02 21:01:53 -0600 | [diff] [blame] | 2583 | weston_view_set_position(view, x, y); |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 2584 | |
| 2585 | return view; |
Alex Wu | 4539b08 | 2012-03-01 12:57:46 +0800 | [diff] [blame] | 2586 | } |
| 2587 | |
Philip Withnall | ed8f1a9 | 2013-11-25 18:01:43 +0000 | [diff] [blame] | 2588 | static void |
| 2589 | shell_ensure_fullscreen_black_view(struct shell_surface *shsurf) |
| 2590 | { |
| 2591 | struct weston_output *output = shsurf->fullscreen_output; |
| 2592 | |
Rafael Antognolli | 03b1659 | 2013-12-03 15:35:42 -0200 | [diff] [blame] | 2593 | assert(shsurf->state.fullscreen); |
Philip Withnall | ed8f1a9 | 2013-11-25 18:01:43 +0000 | [diff] [blame] | 2594 | |
| 2595 | if (!shsurf->fullscreen.black_view) |
| 2596 | shsurf->fullscreen.black_view = |
| 2597 | create_black_surface(shsurf->surface->compositor, |
| 2598 | shsurf->surface, |
| 2599 | output->x, output->y, |
| 2600 | output->width, |
| 2601 | output->height); |
| 2602 | |
| 2603 | weston_view_geometry_dirty(shsurf->fullscreen.black_view); |
| 2604 | wl_list_remove(&shsurf->fullscreen.black_view->layer_link); |
| 2605 | wl_list_insert(&shsurf->view->layer_link, |
| 2606 | &shsurf->fullscreen.black_view->layer_link); |
| 2607 | weston_view_geometry_dirty(shsurf->fullscreen.black_view); |
| 2608 | weston_surface_damage(shsurf->surface); |
| 2609 | } |
| 2610 | |
Alex Wu | 4539b08 | 2012-03-01 12:57:46 +0800 | [diff] [blame] | 2611 | /* Create black surface and append it to the associated fullscreen surface. |
| 2612 | * Handle size dismatch and positioning according to the method. */ |
| 2613 | static void |
| 2614 | shell_configure_fullscreen(struct shell_surface *shsurf) |
| 2615 | { |
| 2616 | struct weston_output *output = shsurf->fullscreen_output; |
| 2617 | struct weston_surface *surface = shsurf->surface; |
| 2618 | struct weston_matrix *matrix; |
Kristian Høgsberg | 240dfeb | 2012-07-12 12:32:31 -0400 | [diff] [blame] | 2619 | float scale, output_aspect, surface_aspect, x, y; |
Giulio Camuffo | b836664 | 2013-04-25 13:57:46 +0300 | [diff] [blame] | 2620 | int32_t surf_x, surf_y, surf_width, surf_height; |
Alex Wu | 4539b08 | 2012-03-01 12:57:46 +0800 | [diff] [blame] | 2621 | |
Alexander Larsson | f82b6ca | 2013-05-28 16:23:39 +0200 | [diff] [blame] | 2622 | if (shsurf->fullscreen.type != WL_SHELL_SURFACE_FULLSCREEN_METHOD_DRIVER) |
| 2623 | restore_output_mode(output); |
| 2624 | |
Philip Withnall | ed8f1a9 | 2013-11-25 18:01:43 +0000 | [diff] [blame] | 2625 | shell_ensure_fullscreen_black_view(shsurf); |
Alex Wu | 4539b08 | 2012-03-01 12:57:46 +0800 | [diff] [blame] | 2626 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 2627 | surface_subsurfaces_boundingbox(shsurf->surface, &surf_x, &surf_y, |
Giulio Camuffo | b836664 | 2013-04-25 13:57:46 +0300 | [diff] [blame] | 2628 | &surf_width, &surf_height); |
| 2629 | |
Alex Wu | 4539b08 | 2012-03-01 12:57:46 +0800 | [diff] [blame] | 2630 | switch (shsurf->fullscreen.type) { |
| 2631 | case WL_SHELL_SURFACE_FULLSCREEN_METHOD_DEFAULT: |
Pekka Paalanen | de685b8 | 2012-12-04 15:58:12 +0200 | [diff] [blame] | 2632 | if (surface->buffer_ref.buffer) |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 2633 | center_on_output(shsurf->view, shsurf->fullscreen_output); |
Alex Wu | 4539b08 | 2012-03-01 12:57:46 +0800 | [diff] [blame] | 2634 | break; |
| 2635 | case WL_SHELL_SURFACE_FULLSCREEN_METHOD_SCALE: |
Rob Bradford | 9f3dd15 | 2013-02-12 11:53:47 +0000 | [diff] [blame] | 2636 | /* 1:1 mapping between surface and output dimensions */ |
Giulio Camuffo | b836664 | 2013-04-25 13:57:46 +0300 | [diff] [blame] | 2637 | if (output->width == surf_width && |
| 2638 | output->height == surf_height) { |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 2639 | weston_view_set_position(shsurf->view, |
| 2640 | output->x - surf_x, |
| 2641 | output->y - surf_y); |
Rob Bradford | 9f3dd15 | 2013-02-12 11:53:47 +0000 | [diff] [blame] | 2642 | break; |
| 2643 | } |
| 2644 | |
Alex Wu | 4539b08 | 2012-03-01 12:57:46 +0800 | [diff] [blame] | 2645 | matrix = &shsurf->fullscreen.transform.matrix; |
| 2646 | weston_matrix_init(matrix); |
Kristian Høgsberg | 240dfeb | 2012-07-12 12:32:31 -0400 | [diff] [blame] | 2647 | |
Scott Moreau | 1bad5db | 2012-08-18 01:04:05 -0600 | [diff] [blame] | 2648 | output_aspect = (float) output->width / |
| 2649 | (float) output->height; |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 2650 | /* XXX: Use surf_width and surf_height here? */ |
| 2651 | surface_aspect = (float) surface->width / |
| 2652 | (float) surface->height; |
Kristian Høgsberg | 240dfeb | 2012-07-12 12:32:31 -0400 | [diff] [blame] | 2653 | if (output_aspect < surface_aspect) |
Scott Moreau | 1bad5db | 2012-08-18 01:04:05 -0600 | [diff] [blame] | 2654 | scale = (float) output->width / |
Giulio Camuffo | b836664 | 2013-04-25 13:57:46 +0300 | [diff] [blame] | 2655 | (float) surf_width; |
Kristian Høgsberg | 240dfeb | 2012-07-12 12:32:31 -0400 | [diff] [blame] | 2656 | else |
Scott Moreau | 1bad5db | 2012-08-18 01:04:05 -0600 | [diff] [blame] | 2657 | scale = (float) output->height / |
Giulio Camuffo | b836664 | 2013-04-25 13:57:46 +0300 | [diff] [blame] | 2658 | (float) surf_height; |
Kristian Høgsberg | 240dfeb | 2012-07-12 12:32:31 -0400 | [diff] [blame] | 2659 | |
Alex Wu | 4539b08 | 2012-03-01 12:57:46 +0800 | [diff] [blame] | 2660 | weston_matrix_scale(matrix, scale, scale, 1); |
| 2661 | wl_list_remove(&shsurf->fullscreen.transform.link); |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 2662 | wl_list_insert(&shsurf->view->geometry.transformation_list, |
Alex Wu | 4539b08 | 2012-03-01 12:57:46 +0800 | [diff] [blame] | 2663 | &shsurf->fullscreen.transform.link); |
Giulio Camuffo | b836664 | 2013-04-25 13:57:46 +0300 | [diff] [blame] | 2664 | x = output->x + (output->width - surf_width * scale) / 2 - surf_x; |
| 2665 | y = output->y + (output->height - surf_height * scale) / 2 - surf_y; |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 2666 | weston_view_set_position(shsurf->view, x, y); |
Kristian Høgsberg | 240dfeb | 2012-07-12 12:32:31 -0400 | [diff] [blame] | 2667 | |
Alex Wu | 4539b08 | 2012-03-01 12:57:46 +0800 | [diff] [blame] | 2668 | break; |
| 2669 | case WL_SHELL_SURFACE_FULLSCREEN_METHOD_DRIVER: |
Alex Wu | bd3354b | 2012-04-17 17:20:49 +0800 | [diff] [blame] | 2670 | if (shell_surface_is_top_fullscreen(shsurf)) { |
Quentin Glidic | c0d79ce | 2013-01-29 14:16:13 +0100 | [diff] [blame] | 2671 | struct weston_mode mode = {0, |
Pekka Paalanen | 1fd9c0f | 2013-11-26 18:19:41 +0100 | [diff] [blame] | 2672 | surf_width * surface->buffer_viewport.scale, |
| 2673 | surf_height * surface->buffer_viewport.scale, |
Alex Wu | bd3354b | 2012-04-17 17:20:49 +0800 | [diff] [blame] | 2674 | shsurf->fullscreen.framerate}; |
| 2675 | |
Pekka Paalanen | 1fd9c0f | 2013-11-26 18:19:41 +0100 | [diff] [blame] | 2676 | if (weston_output_switch_mode(output, &mode, surface->buffer_viewport.scale, |
Hardening | 57388e4 | 2013-09-18 23:56:36 +0200 | [diff] [blame] | 2677 | WESTON_MODE_SWITCH_SET_TEMPORARY) == 0) { |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 2678 | weston_view_set_position(shsurf->view, |
| 2679 | output->x - surf_x, |
| 2680 | output->y - surf_y); |
Jason Ekstrand | 918f2dd | 2013-12-02 21:01:53 -0600 | [diff] [blame] | 2681 | shsurf->fullscreen.black_view->surface->width = output->width; |
| 2682 | shsurf->fullscreen.black_view->surface->height = output->height; |
| 2683 | weston_view_set_position(shsurf->fullscreen.black_view, |
| 2684 | output->x - surf_x, |
| 2685 | output->y - surf_y); |
Alex Wu | bd3354b | 2012-04-17 17:20:49 +0800 | [diff] [blame] | 2686 | break; |
Alexander Larsson | d622ed3 | 2013-05-28 16:23:40 +0200 | [diff] [blame] | 2687 | } else { |
Alexander Larsson | f82b6ca | 2013-05-28 16:23:39 +0200 | [diff] [blame] | 2688 | restore_output_mode(output); |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 2689 | center_on_output(shsurf->view, output); |
Alexander Larsson | d622ed3 | 2013-05-28 16:23:40 +0200 | [diff] [blame] | 2690 | } |
Alex Wu | bd3354b | 2012-04-17 17:20:49 +0800 | [diff] [blame] | 2691 | } |
Alex Wu | 4539b08 | 2012-03-01 12:57:46 +0800 | [diff] [blame] | 2692 | break; |
| 2693 | case WL_SHELL_SURFACE_FULLSCREEN_METHOD_FILL: |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 2694 | center_on_output(shsurf->view, output); |
Alex Wu | 4539b08 | 2012-03-01 12:57:46 +0800 | [diff] [blame] | 2695 | break; |
| 2696 | default: |
| 2697 | break; |
| 2698 | } |
| 2699 | } |
| 2700 | |
Alex Wu | 4539b08 | 2012-03-01 12:57:46 +0800 | [diff] [blame] | 2701 | static void |
| 2702 | shell_map_fullscreen(struct shell_surface *shsurf) |
| 2703 | { |
Alex Wu | bd3354b | 2012-04-17 17:20:49 +0800 | [diff] [blame] | 2704 | shell_configure_fullscreen(shsurf); |
Alex Wu | 4539b08 | 2012-03-01 12:57:46 +0800 | [diff] [blame] | 2705 | } |
| 2706 | |
Kristian Høgsberg | 7a5c979 | 2011-06-18 06:12:54 -0400 | [diff] [blame] | 2707 | static void |
Tiago Vignatti | fb2adba | 2013-06-12 15:43:21 -0300 | [diff] [blame] | 2708 | set_xwayland(struct shell_surface *shsurf, int x, int y, uint32_t flags) |
| 2709 | { |
| 2710 | /* XXX: using the same fields for transient type */ |
Rafael Antognolli | 03b1659 | 2013-12-03 15:35:42 -0200 | [diff] [blame] | 2711 | surface_clear_next_states(shsurf); |
Tiago Vignatti | fb2adba | 2013-06-12 15:43:21 -0300 | [diff] [blame] | 2712 | shsurf->transient.x = x; |
| 2713 | shsurf->transient.y = y; |
| 2714 | shsurf->transient.flags = flags; |
Philip Withnall | dc4332f | 2013-11-25 18:01:38 +0000 | [diff] [blame] | 2715 | |
| 2716 | shell_surface_set_parent(shsurf, NULL); |
| 2717 | |
Tiago Vignatti | fb2adba | 2013-06-12 15:43:21 -0300 | [diff] [blame] | 2718 | shsurf->next_type = SHELL_SURFACE_XWAYLAND; |
| 2719 | } |
| 2720 | |
Kristian Høgsberg | 02bbabb | 2013-05-06 22:15:05 -0400 | [diff] [blame] | 2721 | static const struct weston_pointer_grab_interface popup_grab_interface; |
Giulio Camuffo | 5085a75 | 2013-03-25 21:42:45 +0100 | [diff] [blame] | 2722 | |
| 2723 | static void |
| 2724 | destroy_shell_seat(struct wl_listener *listener, void *data) |
| 2725 | { |
| 2726 | struct shell_seat *shseat = |
| 2727 | container_of(listener, |
| 2728 | struct shell_seat, seat_destroy_listener); |
| 2729 | struct shell_surface *shsurf, *prev = NULL; |
| 2730 | |
| 2731 | if (shseat->popup_grab.grab.interface == &popup_grab_interface) { |
Kristian Høgsberg | 02bbabb | 2013-05-06 22:15:05 -0400 | [diff] [blame] | 2732 | weston_pointer_end_grab(shseat->popup_grab.grab.pointer); |
Giulio Camuffo | 5085a75 | 2013-03-25 21:42:45 +0100 | [diff] [blame] | 2733 | shseat->popup_grab.client = NULL; |
| 2734 | |
| 2735 | wl_list_for_each(shsurf, &shseat->popup_grab.surfaces_list, popup.grab_link) { |
| 2736 | shsurf->popup.shseat = NULL; |
| 2737 | if (prev) { |
| 2738 | wl_list_init(&prev->popup.grab_link); |
| 2739 | } |
| 2740 | prev = shsurf; |
| 2741 | } |
| 2742 | wl_list_init(&prev->popup.grab_link); |
| 2743 | } |
| 2744 | |
| 2745 | wl_list_remove(&shseat->seat_destroy_listener.link); |
| 2746 | free(shseat); |
| 2747 | } |
| 2748 | |
| 2749 | static struct shell_seat * |
| 2750 | create_shell_seat(struct weston_seat *seat) |
| 2751 | { |
| 2752 | struct shell_seat *shseat; |
| 2753 | |
| 2754 | shseat = calloc(1, sizeof *shseat); |
| 2755 | if (!shseat) { |
| 2756 | weston_log("no memory to allocate shell seat\n"); |
| 2757 | return NULL; |
| 2758 | } |
| 2759 | |
| 2760 | shseat->seat = seat; |
| 2761 | wl_list_init(&shseat->popup_grab.surfaces_list); |
| 2762 | |
| 2763 | shseat->seat_destroy_listener.notify = destroy_shell_seat; |
| 2764 | wl_signal_add(&seat->destroy_signal, |
| 2765 | &shseat->seat_destroy_listener); |
| 2766 | |
| 2767 | return shseat; |
| 2768 | } |
| 2769 | |
| 2770 | static struct shell_seat * |
| 2771 | get_shell_seat(struct weston_seat *seat) |
| 2772 | { |
| 2773 | struct wl_listener *listener; |
| 2774 | |
| 2775 | listener = wl_signal_get(&seat->destroy_signal, destroy_shell_seat); |
| 2776 | if (listener == NULL) |
| 2777 | return create_shell_seat(seat); |
| 2778 | |
| 2779 | return container_of(listener, |
| 2780 | struct shell_seat, seat_destroy_listener); |
| 2781 | } |
| 2782 | |
Kristian Høgsberg | b810eb5 | 2013-02-12 20:07:05 -0500 | [diff] [blame] | 2783 | static void |
Kristian Høgsberg | 6848c25 | 2013-05-08 22:02:59 -0400 | [diff] [blame] | 2784 | popup_grab_focus(struct weston_pointer_grab *grab) |
Kristian Høgsberg | b3cca0a | 2012-01-04 22:19:14 -0500 | [diff] [blame] | 2785 | { |
Kristian Høgsberg | 02bbabb | 2013-05-06 22:15:05 -0400 | [diff] [blame] | 2786 | struct weston_pointer *pointer = grab->pointer; |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 2787 | struct weston_view *view; |
Giulio Camuffo | 5085a75 | 2013-03-25 21:42:45 +0100 | [diff] [blame] | 2788 | struct shell_seat *shseat = |
| 2789 | container_of(grab, struct shell_seat, popup_grab.grab); |
| 2790 | struct wl_client *client = shseat->popup_grab.client; |
Kristian Høgsberg | 6848c25 | 2013-05-08 22:02:59 -0400 | [diff] [blame] | 2791 | wl_fixed_t sx, sy; |
| 2792 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 2793 | view = weston_compositor_pick_view(pointer->seat->compositor, |
| 2794 | pointer->x, pointer->y, |
| 2795 | &sx, &sy); |
Kristian Høgsberg | b3cca0a | 2012-01-04 22:19:14 -0500 | [diff] [blame] | 2796 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 2797 | if (view && view->surface->resource && |
| 2798 | wl_resource_get_client(view->surface->resource) == client) { |
| 2799 | weston_pointer_set_focus(pointer, view, sx, sy); |
Kristian Høgsberg | b3cca0a | 2012-01-04 22:19:14 -0500 | [diff] [blame] | 2800 | } else { |
Kristian Høgsberg | 02bbabb | 2013-05-06 22:15:05 -0400 | [diff] [blame] | 2801 | weston_pointer_set_focus(pointer, NULL, |
| 2802 | wl_fixed_from_int(0), |
| 2803 | wl_fixed_from_int(0)); |
Kristian Høgsberg | b3cca0a | 2012-01-04 22:19:14 -0500 | [diff] [blame] | 2804 | } |
| 2805 | } |
| 2806 | |
| 2807 | static void |
Giulio Camuffo | 1959ab8 | 2013-11-14 23:42:52 +0100 | [diff] [blame] | 2808 | popup_grab_motion(struct weston_pointer_grab *grab, uint32_t time, |
| 2809 | wl_fixed_t x, wl_fixed_t y) |
Kristian Høgsberg | b3cca0a | 2012-01-04 22:19:14 -0500 | [diff] [blame] | 2810 | { |
Kristian Høgsberg | be6403e | 2013-05-08 21:03:21 -0400 | [diff] [blame] | 2811 | struct weston_pointer *pointer = grab->pointer; |
Neil Roberts | 96d790e | 2013-09-19 17:32:00 +0100 | [diff] [blame] | 2812 | struct wl_resource *resource; |
Kristian Høgsberg | be6403e | 2013-05-08 21:03:21 -0400 | [diff] [blame] | 2813 | wl_fixed_t sx, sy; |
Kristian Høgsberg | b3cca0a | 2012-01-04 22:19:14 -0500 | [diff] [blame] | 2814 | |
Giulio Camuffo | 1959ab8 | 2013-11-14 23:42:52 +0100 | [diff] [blame] | 2815 | weston_pointer_move(pointer, x, y); |
| 2816 | |
Neil Roberts | 96d790e | 2013-09-19 17:32:00 +0100 | [diff] [blame] | 2817 | wl_resource_for_each(resource, &pointer->focus_resource_list) { |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 2818 | weston_view_from_global_fixed(pointer->focus, |
| 2819 | pointer->x, pointer->y, |
| 2820 | &sx, &sy); |
Neil Roberts | 96d790e | 2013-09-19 17:32:00 +0100 | [diff] [blame] | 2821 | wl_pointer_send_motion(resource, time, sx, sy); |
Kristian Høgsberg | be6403e | 2013-05-08 21:03:21 -0400 | [diff] [blame] | 2822 | } |
Kristian Høgsberg | b3cca0a | 2012-01-04 22:19:14 -0500 | [diff] [blame] | 2823 | } |
| 2824 | |
| 2825 | static void |
Kristian Høgsberg | 02bbabb | 2013-05-06 22:15:05 -0400 | [diff] [blame] | 2826 | popup_grab_button(struct weston_pointer_grab *grab, |
Daniel Stone | 4dbadb1 | 2012-05-30 16:31:51 +0100 | [diff] [blame] | 2827 | uint32_t time, uint32_t button, uint32_t state_w) |
Kristian Høgsberg | b3cca0a | 2012-01-04 22:19:14 -0500 | [diff] [blame] | 2828 | { |
| 2829 | struct wl_resource *resource; |
Giulio Camuffo | 5085a75 | 2013-03-25 21:42:45 +0100 | [diff] [blame] | 2830 | struct shell_seat *shseat = |
| 2831 | container_of(grab, struct shell_seat, popup_grab.grab); |
Rob Bradford | 880ebc7 | 2013-07-22 17:31:38 +0100 | [diff] [blame] | 2832 | struct wl_display *display = shseat->seat->compositor->wl_display; |
Daniel Stone | 4dbadb1 | 2012-05-30 16:31:51 +0100 | [diff] [blame] | 2833 | enum wl_pointer_button_state state = state_w; |
Kristian Høgsberg | eae5de7 | 2012-04-11 22:42:15 -0400 | [diff] [blame] | 2834 | uint32_t serial; |
Neil Roberts | 96d790e | 2013-09-19 17:32:00 +0100 | [diff] [blame] | 2835 | struct wl_list *resource_list; |
Kristian Høgsberg | b3cca0a | 2012-01-04 22:19:14 -0500 | [diff] [blame] | 2836 | |
Neil Roberts | 96d790e | 2013-09-19 17:32:00 +0100 | [diff] [blame] | 2837 | resource_list = &grab->pointer->focus_resource_list; |
| 2838 | if (!wl_list_empty(resource_list)) { |
Kristian Høgsberg | eae5de7 | 2012-04-11 22:42:15 -0400 | [diff] [blame] | 2839 | serial = wl_display_get_serial(display); |
Neil Roberts | 96d790e | 2013-09-19 17:32:00 +0100 | [diff] [blame] | 2840 | wl_resource_for_each(resource, resource_list) { |
| 2841 | wl_pointer_send_button(resource, serial, |
| 2842 | time, button, state); |
| 2843 | } |
Daniel Stone | 4dbadb1 | 2012-05-30 16:31:51 +0100 | [diff] [blame] | 2844 | } else if (state == WL_POINTER_BUTTON_STATE_RELEASED && |
Giulio Camuffo | 5085a75 | 2013-03-25 21:42:45 +0100 | [diff] [blame] | 2845 | (shseat->popup_grab.initial_up || |
Kristian Høgsberg | e314875 | 2013-05-06 23:19:49 -0400 | [diff] [blame] | 2846 | time - shseat->seat->pointer->grab_time > 500)) { |
Kristian Høgsberg | 57e0907 | 2012-10-30 14:07:27 -0400 | [diff] [blame] | 2847 | popup_grab_end(grab->pointer); |
Kristian Høgsberg | b3cca0a | 2012-01-04 22:19:14 -0500 | [diff] [blame] | 2848 | } |
| 2849 | |
Daniel Stone | 4dbadb1 | 2012-05-30 16:31:51 +0100 | [diff] [blame] | 2850 | if (state == WL_POINTER_BUTTON_STATE_RELEASED) |
Giulio Camuffo | 5085a75 | 2013-03-25 21:42:45 +0100 | [diff] [blame] | 2851 | shseat->popup_grab.initial_up = 1; |
Kristian Høgsberg | b3cca0a | 2012-01-04 22:19:14 -0500 | [diff] [blame] | 2852 | } |
| 2853 | |
Jonas Ådahl | 1ea343e | 2013-10-25 23:18:05 +0200 | [diff] [blame] | 2854 | static void |
| 2855 | popup_grab_cancel(struct weston_pointer_grab *grab) |
| 2856 | { |
| 2857 | popup_grab_end(grab->pointer); |
| 2858 | } |
| 2859 | |
Kristian Høgsberg | 02bbabb | 2013-05-06 22:15:05 -0400 | [diff] [blame] | 2860 | static const struct weston_pointer_grab_interface popup_grab_interface = { |
Kristian Høgsberg | b3cca0a | 2012-01-04 22:19:14 -0500 | [diff] [blame] | 2861 | popup_grab_focus, |
| 2862 | popup_grab_motion, |
| 2863 | popup_grab_button, |
Jonas Ådahl | 1ea343e | 2013-10-25 23:18:05 +0200 | [diff] [blame] | 2864 | popup_grab_cancel, |
Kristian Høgsberg | b3cca0a | 2012-01-04 22:19:14 -0500 | [diff] [blame] | 2865 | }; |
| 2866 | |
| 2867 | static void |
Kristian Høgsberg | 02bbabb | 2013-05-06 22:15:05 -0400 | [diff] [blame] | 2868 | popup_grab_end(struct weston_pointer *pointer) |
Kristian Høgsberg | 57e0907 | 2012-10-30 14:07:27 -0400 | [diff] [blame] | 2869 | { |
Kristian Høgsberg | 02bbabb | 2013-05-06 22:15:05 -0400 | [diff] [blame] | 2870 | struct weston_pointer_grab *grab = pointer->grab; |
Giulio Camuffo | 5085a75 | 2013-03-25 21:42:45 +0100 | [diff] [blame] | 2871 | struct shell_seat *shseat = |
| 2872 | container_of(grab, struct shell_seat, popup_grab.grab); |
| 2873 | struct shell_surface *shsurf; |
| 2874 | struct shell_surface *prev = NULL; |
Kristian Høgsberg | 57e0907 | 2012-10-30 14:07:27 -0400 | [diff] [blame] | 2875 | |
| 2876 | if (pointer->grab->interface == &popup_grab_interface) { |
Kristian Høgsberg | 02bbabb | 2013-05-06 22:15:05 -0400 | [diff] [blame] | 2877 | weston_pointer_end_grab(grab->pointer); |
Giulio Camuffo | 5085a75 | 2013-03-25 21:42:45 +0100 | [diff] [blame] | 2878 | shseat->popup_grab.client = NULL; |
Philipp Brüschweiler | 63e7be6 | 2013-04-15 21:09:54 +0200 | [diff] [blame] | 2879 | shseat->popup_grab.grab.interface = NULL; |
| 2880 | assert(!wl_list_empty(&shseat->popup_grab.surfaces_list)); |
Giulio Camuffo | 5085a75 | 2013-03-25 21:42:45 +0100 | [diff] [blame] | 2881 | /* Send the popup_done event to all the popups open */ |
| 2882 | wl_list_for_each(shsurf, &shseat->popup_grab.surfaces_list, popup.grab_link) { |
Jason Ekstrand | 651f00e | 2013-06-14 10:07:54 -0500 | [diff] [blame] | 2883 | wl_shell_surface_send_popup_done(shsurf->resource); |
Giulio Camuffo | 5085a75 | 2013-03-25 21:42:45 +0100 | [diff] [blame] | 2884 | shsurf->popup.shseat = NULL; |
| 2885 | if (prev) { |
| 2886 | wl_list_init(&prev->popup.grab_link); |
| 2887 | } |
| 2888 | prev = shsurf; |
| 2889 | } |
| 2890 | wl_list_init(&prev->popup.grab_link); |
| 2891 | wl_list_init(&shseat->popup_grab.surfaces_list); |
| 2892 | } |
| 2893 | } |
| 2894 | |
| 2895 | static void |
| 2896 | add_popup_grab(struct shell_surface *shsurf, struct shell_seat *shseat) |
| 2897 | { |
Kristian Høgsberg | e314875 | 2013-05-06 23:19:49 -0400 | [diff] [blame] | 2898 | struct weston_seat *seat = shseat->seat; |
Giulio Camuffo | 5085a75 | 2013-03-25 21:42:45 +0100 | [diff] [blame] | 2899 | |
| 2900 | if (wl_list_empty(&shseat->popup_grab.surfaces_list)) { |
Jason Ekstrand | 651f00e | 2013-06-14 10:07:54 -0500 | [diff] [blame] | 2901 | shseat->popup_grab.client = wl_resource_get_client(shsurf->resource); |
Giulio Camuffo | 5085a75 | 2013-03-25 21:42:45 +0100 | [diff] [blame] | 2902 | shseat->popup_grab.grab.interface = &popup_grab_interface; |
Giulio Camuffo | 1b4b61a | 2013-03-27 18:05:26 +0100 | [diff] [blame] | 2903 | /* We must make sure here that this popup was opened after |
| 2904 | * a mouse press, and not just by moving around with other |
| 2905 | * popups already open. */ |
Kristian Høgsberg | e314875 | 2013-05-06 23:19:49 -0400 | [diff] [blame] | 2906 | if (shseat->seat->pointer->button_count > 0) |
Giulio Camuffo | 1b4b61a | 2013-03-27 18:05:26 +0100 | [diff] [blame] | 2907 | shseat->popup_grab.initial_up = 0; |
Giulio Camuffo | 5085a75 | 2013-03-25 21:42:45 +0100 | [diff] [blame] | 2908 | |
Rob Bradford | dfe3105 | 2013-06-26 19:49:11 +0100 | [diff] [blame] | 2909 | 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] | 2910 | weston_pointer_start_grab(seat->pointer, &shseat->popup_grab.grab); |
Rob Bradford | dfe3105 | 2013-06-26 19:49:11 +0100 | [diff] [blame] | 2911 | } else { |
| 2912 | wl_list_insert(&shseat->popup_grab.surfaces_list, &shsurf->popup.grab_link); |
Giulio Camuffo | 5085a75 | 2013-03-25 21:42:45 +0100 | [diff] [blame] | 2913 | } |
Giulio Camuffo | 5085a75 | 2013-03-25 21:42:45 +0100 | [diff] [blame] | 2914 | } |
| 2915 | |
| 2916 | static void |
| 2917 | remove_popup_grab(struct shell_surface *shsurf) |
| 2918 | { |
| 2919 | struct shell_seat *shseat = shsurf->popup.shseat; |
| 2920 | |
| 2921 | wl_list_remove(&shsurf->popup.grab_link); |
| 2922 | wl_list_init(&shsurf->popup.grab_link); |
| 2923 | if (wl_list_empty(&shseat->popup_grab.surfaces_list)) { |
Kristian Høgsberg | 02bbabb | 2013-05-06 22:15:05 -0400 | [diff] [blame] | 2924 | weston_pointer_end_grab(shseat->popup_grab.grab.pointer); |
Philipp Brüschweiler | 63e7be6 | 2013-04-15 21:09:54 +0200 | [diff] [blame] | 2925 | shseat->popup_grab.grab.interface = NULL; |
Kristian Høgsberg | 57e0907 | 2012-10-30 14:07:27 -0400 | [diff] [blame] | 2926 | } |
| 2927 | } |
| 2928 | |
| 2929 | static void |
Kristian Høgsberg | 3730f36 | 2012-04-13 12:40:07 -0400 | [diff] [blame] | 2930 | shell_map_popup(struct shell_surface *shsurf) |
Kristian Høgsberg | b3cca0a | 2012-01-04 22:19:14 -0500 | [diff] [blame] | 2931 | { |
Giulio Camuffo | 5085a75 | 2013-03-25 21:42:45 +0100 | [diff] [blame] | 2932 | struct shell_seat *shseat = shsurf->popup.shseat; |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 2933 | struct weston_view *parent_view = get_default_view(shsurf->parent); |
Kristian Høgsberg | b3cca0a | 2012-01-04 22:19:14 -0500 | [diff] [blame] | 2934 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 2935 | shsurf->surface->output = parent_view->output; |
| 2936 | shsurf->view->output = parent_view->output; |
Kristian Høgsberg | b3cca0a | 2012-01-04 22:19:14 -0500 | [diff] [blame] | 2937 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 2938 | weston_view_set_transform_parent(shsurf->view, parent_view); |
| 2939 | weston_view_set_position(shsurf->view, shsurf->popup.x, shsurf->popup.y); |
| 2940 | weston_view_update_transform(shsurf->view); |
Kristian Høgsberg | b3cca0a | 2012-01-04 22:19:14 -0500 | [diff] [blame] | 2941 | |
Kristian Høgsberg | e314875 | 2013-05-06 23:19:49 -0400 | [diff] [blame] | 2942 | if (shseat->seat->pointer->grab_serial == shsurf->popup.serial) { |
Giulio Camuffo | 5085a75 | 2013-03-25 21:42:45 +0100 | [diff] [blame] | 2943 | add_popup_grab(shsurf, shseat); |
Kristian Høgsberg | 3730f36 | 2012-04-13 12:40:07 -0400 | [diff] [blame] | 2944 | } else { |
Jason Ekstrand | 651f00e | 2013-06-14 10:07:54 -0500 | [diff] [blame] | 2945 | wl_shell_surface_send_popup_done(shsurf->resource); |
Giulio Camuffo | 5085a75 | 2013-03-25 21:42:45 +0100 | [diff] [blame] | 2946 | shseat->popup_grab.client = NULL; |
Kristian Høgsberg | 3730f36 | 2012-04-13 12:40:07 -0400 | [diff] [blame] | 2947 | } |
Kristian Høgsberg | b3cca0a | 2012-01-04 22:19:14 -0500 | [diff] [blame] | 2948 | } |
| 2949 | |
Pekka Paalanen | 9d1613e | 2011-11-25 12:09:16 +0200 | [diff] [blame] | 2950 | static const struct wl_shell_surface_interface shell_surface_implementation = { |
Scott Moreau | ff1db4a | 2012-04-17 19:06:18 -0600 | [diff] [blame] | 2951 | shell_surface_pong, |
Pekka Paalanen | 9d1613e | 2011-11-25 12:09:16 +0200 | [diff] [blame] | 2952 | shell_surface_move, |
| 2953 | shell_surface_resize, |
| 2954 | shell_surface_set_toplevel, |
| 2955 | shell_surface_set_transient, |
Kristian Høgsberg | b3cca0a | 2012-01-04 22:19:14 -0500 | [diff] [blame] | 2956 | shell_surface_set_fullscreen, |
Juan Zhao | 96879df | 2012-02-07 08:45:41 +0800 | [diff] [blame] | 2957 | shell_surface_set_popup, |
Kristian Høgsberg | e7afd91 | 2012-05-02 09:47:44 -0400 | [diff] [blame] | 2958 | shell_surface_set_maximized, |
| 2959 | shell_surface_set_title, |
| 2960 | shell_surface_set_class |
Pekka Paalanen | 9d1613e | 2011-11-25 12:09:16 +0200 | [diff] [blame] | 2961 | }; |
| 2962 | |
| 2963 | static void |
Tiago Vignatti | bc052c9 | 2012-04-19 16:18:18 +0300 | [diff] [blame] | 2964 | destroy_shell_surface(struct shell_surface *shsurf) |
Pekka Paalanen | 9d1613e | 2011-11-25 12:09:16 +0200 | [diff] [blame] | 2965 | { |
Jason Ekstrand | 651f00e | 2013-06-14 10:07:54 -0500 | [diff] [blame] | 2966 | wl_signal_emit(&shsurf->destroy_signal, shsurf); |
| 2967 | |
Giulio Camuffo | 5085a75 | 2013-03-25 21:42:45 +0100 | [diff] [blame] | 2968 | if (!wl_list_empty(&shsurf->popup.grab_link)) { |
| 2969 | remove_popup_grab(shsurf); |
| 2970 | } |
Kristian Høgsberg | b3cca0a | 2012-01-04 22:19:14 -0500 | [diff] [blame] | 2971 | |
Alex Wu | bd3354b | 2012-04-17 17:20:49 +0800 | [diff] [blame] | 2972 | if (shsurf->fullscreen.type == WL_SHELL_SURFACE_FULLSCREEN_METHOD_DRIVER && |
Alexander Larsson | f82b6ca | 2013-05-28 16:23:39 +0200 | [diff] [blame] | 2973 | shell_surface_is_top_fullscreen(shsurf)) |
| 2974 | restore_output_mode (shsurf->fullscreen_output); |
Pekka Paalanen | 9d1613e | 2011-11-25 12:09:16 +0200 | [diff] [blame] | 2975 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 2976 | if (shsurf->fullscreen.black_view) |
| 2977 | weston_surface_destroy(shsurf->fullscreen.black_view->surface); |
Alex Wu | aa08e2d | 2012-03-05 11:01:40 +0800 | [diff] [blame] | 2978 | |
Alex Wu | bd3354b | 2012-04-17 17:20:49 +0800 | [diff] [blame] | 2979 | /* As destroy_resource() use wl_list_for_each_safe(), |
| 2980 | * we can always remove the listener. |
| 2981 | */ |
| 2982 | wl_list_remove(&shsurf->surface_destroy_listener.link); |
| 2983 | shsurf->surface->configure = NULL; |
Scott Moreau | 9521d5e | 2012-04-19 13:06:17 -0600 | [diff] [blame] | 2984 | ping_timer_destroy(shsurf); |
Scott Moreau | 976a050 | 2013-03-07 10:15:17 -0700 | [diff] [blame] | 2985 | free(shsurf->title); |
Alex Wu | bd3354b | 2012-04-17 17:20:49 +0800 | [diff] [blame] | 2986 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 2987 | weston_view_destroy(shsurf->view); |
| 2988 | |
Philip Withnall | 648a4dd | 2013-11-25 18:01:44 +0000 | [diff] [blame] | 2989 | wl_list_remove(&shsurf->children_link); |
| 2990 | |
Pekka Paalanen | 9d1613e | 2011-11-25 12:09:16 +0200 | [diff] [blame] | 2991 | wl_list_remove(&shsurf->link); |
| 2992 | free(shsurf); |
| 2993 | } |
| 2994 | |
| 2995 | static void |
Tiago Vignatti | bc052c9 | 2012-04-19 16:18:18 +0300 | [diff] [blame] | 2996 | shell_destroy_shell_surface(struct wl_resource *resource) |
| 2997 | { |
Jason Ekstrand | 651f00e | 2013-06-14 10:07:54 -0500 | [diff] [blame] | 2998 | struct shell_surface *shsurf = wl_resource_get_user_data(resource); |
Tiago Vignatti | bc052c9 | 2012-04-19 16:18:18 +0300 | [diff] [blame] | 2999 | |
| 3000 | destroy_shell_surface(shsurf); |
| 3001 | } |
| 3002 | |
| 3003 | static void |
Kristian Høgsberg | 27e3052 | 2012-04-11 23:18:23 -0400 | [diff] [blame] | 3004 | shell_handle_surface_destroy(struct wl_listener *listener, void *data) |
Pekka Paalanen | 9d1613e | 2011-11-25 12:09:16 +0200 | [diff] [blame] | 3005 | { |
| 3006 | struct shell_surface *shsurf = container_of(listener, |
| 3007 | struct shell_surface, |
| 3008 | surface_destroy_listener); |
| 3009 | |
Jason Ekstrand | 651f00e | 2013-06-14 10:07:54 -0500 | [diff] [blame] | 3010 | if (shsurf->resource) |
| 3011 | wl_resource_destroy(shsurf->resource); |
| 3012 | else |
Tiago Vignatti | bc052c9 | 2012-04-19 16:18:18 +0300 | [diff] [blame] | 3013 | destroy_shell_surface(shsurf); |
Pekka Paalanen | 9d1613e | 2011-11-25 12:09:16 +0200 | [diff] [blame] | 3014 | } |
| 3015 | |
Kristian Høgsberg | d813445 | 2012-06-21 12:49:02 -0400 | [diff] [blame] | 3016 | static void |
Jason Ekstrand | 918f2dd | 2013-12-02 21:01:53 -0600 | [diff] [blame] | 3017 | shell_surface_configure(struct weston_surface *, int32_t, int32_t); |
Kristian Høgsberg | d813445 | 2012-06-21 12:49:02 -0400 | [diff] [blame] | 3018 | |
Pekka Paalanen | ec2b32f | 2011-11-28 15:12:34 +0200 | [diff] [blame] | 3019 | static struct shell_surface * |
Kristian Høgsberg | 8334bc1 | 2012-01-03 10:29:47 -0500 | [diff] [blame] | 3020 | get_shell_surface(struct weston_surface *surface) |
Pekka Paalanen | ec2b32f | 2011-11-28 15:12:34 +0200 | [diff] [blame] | 3021 | { |
Kristian Høgsberg | d813445 | 2012-06-21 12:49:02 -0400 | [diff] [blame] | 3022 | if (surface->configure == shell_surface_configure) |
Giulio Camuffo | 7fe01b1 | 2013-03-28 18:02:42 +0100 | [diff] [blame] | 3023 | return surface->configure_private; |
Kristian Høgsberg | d813445 | 2012-06-21 12:49:02 -0400 | [diff] [blame] | 3024 | else |
| 3025 | return NULL; |
Pekka Paalanen | ec2b32f | 2011-11-28 15:12:34 +0200 | [diff] [blame] | 3026 | } |
| 3027 | |
Kristian Høgsberg | 45ba869 | 2012-05-21 14:27:33 -0400 | [diff] [blame] | 3028 | static struct shell_surface * |
Kristian Høgsberg | a61ca06 | 2012-05-22 16:05:52 -0400 | [diff] [blame] | 3029 | create_shell_surface(void *shell, struct weston_surface *surface, |
| 3030 | const struct weston_shell_client *client) |
Pekka Paalanen | 9d1613e | 2011-11-25 12:09:16 +0200 | [diff] [blame] | 3031 | { |
Pekka Paalanen | 9d1613e | 2011-11-25 12:09:16 +0200 | [diff] [blame] | 3032 | struct shell_surface *shsurf; |
| 3033 | |
Ander Conselvan de Oliveira | 093bfa3 | 2012-03-27 17:36:41 +0300 | [diff] [blame] | 3034 | if (surface->configure) { |
Martin Minarik | 6d11836 | 2012-06-07 18:01:59 +0200 | [diff] [blame] | 3035 | weston_log("surface->configure already set\n"); |
Kristian Høgsberg | 45ba869 | 2012-05-21 14:27:33 -0400 | [diff] [blame] | 3036 | return NULL; |
Ander Conselvan de Oliveira | 093bfa3 | 2012-03-27 17:36:41 +0300 | [diff] [blame] | 3037 | } |
| 3038 | |
Pekka Paalanen | 9d1613e | 2011-11-25 12:09:16 +0200 | [diff] [blame] | 3039 | shsurf = calloc(1, sizeof *shsurf); |
| 3040 | if (!shsurf) { |
Martin Minarik | 6d11836 | 2012-06-07 18:01:59 +0200 | [diff] [blame] | 3041 | weston_log("no memory to allocate shell surface\n"); |
Kristian Høgsberg | 45ba869 | 2012-05-21 14:27:33 -0400 | [diff] [blame] | 3042 | return NULL; |
Pekka Paalanen | 9d1613e | 2011-11-25 12:09:16 +0200 | [diff] [blame] | 3043 | } |
| 3044 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 3045 | shsurf->view = weston_view_create(surface); |
| 3046 | if (!shsurf->view) { |
| 3047 | weston_log("no memory to allocate shell surface\n"); |
| 3048 | free(shsurf); |
| 3049 | return NULL; |
| 3050 | } |
| 3051 | |
Ander Conselvan de Oliveira | 093bfa3 | 2012-03-27 17:36:41 +0300 | [diff] [blame] | 3052 | surface->configure = shell_surface_configure; |
Giulio Camuffo | 7fe01b1 | 2013-03-28 18:02:42 +0100 | [diff] [blame] | 3053 | surface->configure_private = shsurf; |
Ander Conselvan de Oliveira | 093bfa3 | 2012-03-27 17:36:41 +0300 | [diff] [blame] | 3054 | |
Tiago Vignatti | bc052c9 | 2012-04-19 16:18:18 +0300 | [diff] [blame] | 3055 | shsurf->shell = (struct desktop_shell *) shell; |
Scott Moreau | ff1db4a | 2012-04-17 19:06:18 -0600 | [diff] [blame] | 3056 | shsurf->unresponsive = 0; |
Alex Wu | 4539b08 | 2012-03-01 12:57:46 +0800 | [diff] [blame] | 3057 | shsurf->saved_position_valid = false; |
Alex Wu | 7bcb8bd | 2012-04-27 09:07:24 +0800 | [diff] [blame] | 3058 | shsurf->saved_rotation_valid = false; |
Pekka Paalanen | 9d1613e | 2011-11-25 12:09:16 +0200 | [diff] [blame] | 3059 | shsurf->surface = surface; |
Alex Wu | 4539b08 | 2012-03-01 12:57:46 +0800 | [diff] [blame] | 3060 | shsurf->fullscreen.type = WL_SHELL_SURFACE_FULLSCREEN_METHOD_DEFAULT; |
| 3061 | shsurf->fullscreen.framerate = 0; |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 3062 | shsurf->fullscreen.black_view = NULL; |
Scott Moreau | ff1db4a | 2012-04-17 19:06:18 -0600 | [diff] [blame] | 3063 | shsurf->ping_timer = NULL; |
Alex Wu | 4539b08 | 2012-03-01 12:57:46 +0800 | [diff] [blame] | 3064 | wl_list_init(&shsurf->fullscreen.transform.link); |
| 3065 | |
Jason Ekstrand | 651f00e | 2013-06-14 10:07:54 -0500 | [diff] [blame] | 3066 | wl_signal_init(&shsurf->destroy_signal); |
Kristian Høgsberg | 27e3052 | 2012-04-11 23:18:23 -0400 | [diff] [blame] | 3067 | shsurf->surface_destroy_listener.notify = shell_handle_surface_destroy; |
Jason Ekstrand | 26ed73c | 2013-06-06 22:34:41 -0500 | [diff] [blame] | 3068 | wl_signal_add(&surface->destroy_signal, |
Kristian Høgsberg | 27e3052 | 2012-04-11 23:18:23 -0400 | [diff] [blame] | 3069 | &shsurf->surface_destroy_listener); |
Pekka Paalanen | 9d1613e | 2011-11-25 12:09:16 +0200 | [diff] [blame] | 3070 | |
| 3071 | /* init link so its safe to always remove it in destroy_shell_surface */ |
| 3072 | wl_list_init(&shsurf->link); |
Giulio Camuffo | 5085a75 | 2013-03-25 21:42:45 +0100 | [diff] [blame] | 3073 | wl_list_init(&shsurf->popup.grab_link); |
Pekka Paalanen | 9d1613e | 2011-11-25 12:09:16 +0200 | [diff] [blame] | 3074 | |
Pekka Paalanen | 460099f | 2012-01-20 16:48:25 +0200 | [diff] [blame] | 3075 | /* empty when not in use */ |
| 3076 | wl_list_init(&shsurf->rotation.transform.link); |
Kristian Høgsberg | 765e27b | 2012-01-27 13:36:13 -0500 | [diff] [blame] | 3077 | weston_matrix_init(&shsurf->rotation.rotation); |
Pekka Paalanen | 460099f | 2012-01-20 16:48:25 +0200 | [diff] [blame] | 3078 | |
Jonas Ådahl | 62fcd04 | 2012-06-13 00:01:23 +0200 | [diff] [blame] | 3079 | wl_list_init(&shsurf->workspace_transform.link); |
| 3080 | |
Philip Withnall | 648a4dd | 2013-11-25 18:01:44 +0000 | [diff] [blame] | 3081 | wl_list_init(&shsurf->children_link); |
| 3082 | wl_list_init(&shsurf->children_list); |
| 3083 | shsurf->parent = NULL; |
| 3084 | |
Pekka Paalanen | 9826223 | 2011-12-01 10:42:22 +0200 | [diff] [blame] | 3085 | shsurf->type = SHELL_SURFACE_NONE; |
Kristian Høgsberg | 7f366e7 | 2012-04-27 17:20:01 -0400 | [diff] [blame] | 3086 | shsurf->next_type = SHELL_SURFACE_NONE; |
Pekka Paalanen | 9d1613e | 2011-11-25 12:09:16 +0200 | [diff] [blame] | 3087 | |
Kristian Høgsberg | a61ca06 | 2012-05-22 16:05:52 -0400 | [diff] [blame] | 3088 | shsurf->client = client; |
| 3089 | |
Kristian Høgsberg | 45ba869 | 2012-05-21 14:27:33 -0400 | [diff] [blame] | 3090 | return shsurf; |
Tiago Vignatti | bc052c9 | 2012-04-19 16:18:18 +0300 | [diff] [blame] | 3091 | } |
| 3092 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 3093 | static struct weston_view * |
| 3094 | get_primary_view(void *shell, struct shell_surface *shsurf) |
| 3095 | { |
| 3096 | return shsurf->view; |
| 3097 | } |
| 3098 | |
Tiago Vignatti | bc052c9 | 2012-04-19 16:18:18 +0300 | [diff] [blame] | 3099 | static void |
| 3100 | shell_get_shell_surface(struct wl_client *client, |
| 3101 | struct wl_resource *resource, |
| 3102 | uint32_t id, |
| 3103 | struct wl_resource *surface_resource) |
| 3104 | { |
Jason Ekstrand | 0f2ef7e | 2013-06-14 10:07:53 -0500 | [diff] [blame] | 3105 | struct weston_surface *surface = |
| 3106 | wl_resource_get_user_data(surface_resource); |
Jason Ekstrand | 651f00e | 2013-06-14 10:07:54 -0500 | [diff] [blame] | 3107 | struct desktop_shell *shell = wl_resource_get_user_data(resource); |
Tiago Vignatti | bc052c9 | 2012-04-19 16:18:18 +0300 | [diff] [blame] | 3108 | struct shell_surface *shsurf; |
| 3109 | |
| 3110 | if (get_shell_surface(surface)) { |
| 3111 | wl_resource_post_error(surface_resource, |
Kristian Høgsberg | 9540ea6 | 2012-05-21 14:28:57 -0400 | [diff] [blame] | 3112 | WL_DISPLAY_ERROR_INVALID_OBJECT, |
| 3113 | "desktop_shell::get_shell_surface already requested"); |
Tiago Vignatti | bc052c9 | 2012-04-19 16:18:18 +0300 | [diff] [blame] | 3114 | return; |
| 3115 | } |
| 3116 | |
Kristian Høgsberg | a61ca06 | 2012-05-22 16:05:52 -0400 | [diff] [blame] | 3117 | shsurf = create_shell_surface(shell, surface, &shell_client); |
Kristian Høgsberg | 9540ea6 | 2012-05-21 14:28:57 -0400 | [diff] [blame] | 3118 | if (!shsurf) { |
| 3119 | wl_resource_post_error(surface_resource, |
| 3120 | WL_DISPLAY_ERROR_INVALID_OBJECT, |
| 3121 | "surface->configure already set"); |
| 3122 | return; |
| 3123 | } |
Tiago Vignatti | bc052c9 | 2012-04-19 16:18:18 +0300 | [diff] [blame] | 3124 | |
Jason Ekstrand | a85118c | 2013-06-27 20:17:02 -0500 | [diff] [blame] | 3125 | shsurf->resource = |
| 3126 | wl_resource_create(client, |
| 3127 | &wl_shell_surface_interface, 1, id); |
| 3128 | wl_resource_set_implementation(shsurf->resource, |
| 3129 | &shell_surface_implementation, |
| 3130 | shsurf, shell_destroy_shell_surface); |
Pekka Paalanen | 9d1613e | 2011-11-25 12:09:16 +0200 | [diff] [blame] | 3131 | } |
| 3132 | |
| 3133 | static const struct wl_shell_interface shell_implementation = { |
Pekka Paalanen | 4622967 | 2011-11-29 15:49:31 +0200 | [diff] [blame] | 3134 | shell_get_shell_surface |
Kristian Høgsberg | 4cca349 | 2011-01-18 07:53:49 -0500 | [diff] [blame] | 3135 | }; |
| 3136 | |
Kristian Høgsberg | 0793756 | 2011-04-12 17:25:42 -0400 | [diff] [blame] | 3137 | static void |
Ander Conselvan de Oliveira | 859e885 | 2013-02-21 18:35:21 +0200 | [diff] [blame] | 3138 | shell_fade(struct desktop_shell *shell, enum fade_type type); |
| 3139 | |
| 3140 | static int |
| 3141 | screensaver_timeout(void *data) |
| 3142 | { |
| 3143 | struct desktop_shell *shell = data; |
| 3144 | |
| 3145 | shell_fade(shell, FADE_OUT); |
| 3146 | |
| 3147 | return 1; |
| 3148 | } |
| 3149 | |
| 3150 | static void |
Kristian Høgsberg | 8334bc1 | 2012-01-03 10:29:47 -0500 | [diff] [blame] | 3151 | handle_screensaver_sigchld(struct weston_process *proc, int status) |
Pekka Paalanen | 18027e5 | 2011-12-02 16:31:49 +0200 | [diff] [blame] | 3152 | { |
Ander Conselvan de Oliveira | 18639f8 | 2013-02-15 18:44:19 +0200 | [diff] [blame] | 3153 | struct desktop_shell *shell = |
| 3154 | container_of(proc, struct desktop_shell, screensaver.process); |
Ander Conselvan de Oliveira | 18639f8 | 2013-02-15 18:44:19 +0200 | [diff] [blame] | 3155 | |
Pekka Paalanen | 18027e5 | 2011-12-02 16:31:49 +0200 | [diff] [blame] | 3156 | proc->pid = 0; |
Ander Conselvan de Oliveira | 18639f8 | 2013-02-15 18:44:19 +0200 | [diff] [blame] | 3157 | |
| 3158 | if (shell->locked) |
Ander Conselvan de Oliveira | b17537e | 2013-02-22 14:16:18 +0200 | [diff] [blame] | 3159 | weston_compositor_sleep(shell->compositor); |
Pekka Paalanen | 18027e5 | 2011-12-02 16:31:49 +0200 | [diff] [blame] | 3160 | } |
| 3161 | |
| 3162 | static void |
Tiago Vignatti | be14326 | 2012-04-16 17:31:41 +0300 | [diff] [blame] | 3163 | launch_screensaver(struct desktop_shell *shell) |
Pekka Paalanen | 77346a6 | 2011-11-30 16:26:35 +0200 | [diff] [blame] | 3164 | { |
| 3165 | if (shell->screensaver.binding) |
| 3166 | return; |
| 3167 | |
Ander Conselvan de Oliveira | dda9d78 | 2013-02-22 14:16:19 +0200 | [diff] [blame] | 3168 | if (!shell->screensaver.path) { |
| 3169 | weston_compositor_sleep(shell->compositor); |
Pekka Paalanen | e955f1e | 2011-12-07 11:49:52 +0200 | [diff] [blame] | 3170 | return; |
Ander Conselvan de Oliveira | dda9d78 | 2013-02-22 14:16:19 +0200 | [diff] [blame] | 3171 | } |
Pekka Paalanen | e955f1e | 2011-12-07 11:49:52 +0200 | [diff] [blame] | 3172 | |
Kristian Høgsberg | 32bed57 | 2012-03-01 17:11:36 -0500 | [diff] [blame] | 3173 | if (shell->screensaver.process.pid != 0) { |
Martin Minarik | 6d11836 | 2012-06-07 18:01:59 +0200 | [diff] [blame] | 3174 | weston_log("old screensaver still running\n"); |
Kristian Høgsberg | 32bed57 | 2012-03-01 17:11:36 -0500 | [diff] [blame] | 3175 | return; |
| 3176 | } |
| 3177 | |
Kristian Høgsberg | 8334bc1 | 2012-01-03 10:29:47 -0500 | [diff] [blame] | 3178 | weston_client_launch(shell->compositor, |
Pekka Paalanen | 18027e5 | 2011-12-02 16:31:49 +0200 | [diff] [blame] | 3179 | &shell->screensaver.process, |
Pekka Paalanen | e955f1e | 2011-12-07 11:49:52 +0200 | [diff] [blame] | 3180 | shell->screensaver.path, |
Pekka Paalanen | 18027e5 | 2011-12-02 16:31:49 +0200 | [diff] [blame] | 3181 | handle_screensaver_sigchld); |
Pekka Paalanen | 77346a6 | 2011-11-30 16:26:35 +0200 | [diff] [blame] | 3182 | } |
| 3183 | |
| 3184 | static void |
Tiago Vignatti | be14326 | 2012-04-16 17:31:41 +0300 | [diff] [blame] | 3185 | terminate_screensaver(struct desktop_shell *shell) |
Pekka Paalanen | 77346a6 | 2011-11-30 16:26:35 +0200 | [diff] [blame] | 3186 | { |
Pekka Paalanen | 18027e5 | 2011-12-02 16:31:49 +0200 | [diff] [blame] | 3187 | if (shell->screensaver.process.pid == 0) |
| 3188 | return; |
| 3189 | |
| 3190 | kill(shell->screensaver.process.pid, SIGTERM); |
Pekka Paalanen | 77346a6 | 2011-11-30 16:26:35 +0200 | [diff] [blame] | 3191 | } |
| 3192 | |
| 3193 | static void |
Jason Ekstrand | 918f2dd | 2013-12-02 21:01:53 -0600 | [diff] [blame] | 3194 | configure_static_view(struct weston_view *ev, struct weston_layer *layer) |
Kristian Høgsberg | 962342c | 2012-06-26 16:29:50 -0400 | [diff] [blame] | 3195 | { |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 3196 | struct weston_view *v, *next; |
Kristian Høgsberg | 962342c | 2012-06-26 16:29:50 -0400 | [diff] [blame] | 3197 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 3198 | wl_list_for_each_safe(v, next, &layer->view_list, layer_link) { |
| 3199 | if (v->output == ev->output && v != ev) { |
| 3200 | weston_view_unmap(v); |
| 3201 | v->surface->configure = NULL; |
Kristian Høgsberg | 962342c | 2012-06-26 16:29:50 -0400 | [diff] [blame] | 3202 | } |
| 3203 | } |
| 3204 | |
Jason Ekstrand | 918f2dd | 2013-12-02 21:01:53 -0600 | [diff] [blame] | 3205 | weston_view_set_position(ev, ev->output->x, ev->output->y); |
Kristian Høgsberg | 962342c | 2012-06-26 16:29:50 -0400 | [diff] [blame] | 3206 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 3207 | if (wl_list_empty(&ev->layer_link)) { |
| 3208 | wl_list_insert(&layer->view_list, &ev->layer_link); |
| 3209 | weston_compositor_schedule_repaint(ev->surface->compositor); |
Kristian Høgsberg | 962342c | 2012-06-26 16:29:50 -0400 | [diff] [blame] | 3210 | } |
| 3211 | } |
| 3212 | |
| 3213 | static void |
Jason Ekstrand | 918f2dd | 2013-12-02 21:01:53 -0600 | [diff] [blame] | 3214 | 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] | 3215 | { |
Giulio Camuffo | 7fe01b1 | 2013-03-28 18:02:42 +0100 | [diff] [blame] | 3216 | struct desktop_shell *shell = es->configure_private; |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 3217 | struct weston_view *view; |
Kristian Høgsberg | af7b1ff | 2012-06-26 21:19:23 -0400 | [diff] [blame] | 3218 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 3219 | view = container_of(es->views.next, struct weston_view, surface_link); |
| 3220 | |
Jason Ekstrand | 918f2dd | 2013-12-02 21:01:53 -0600 | [diff] [blame] | 3221 | configure_static_view(view, &shell->background_layer); |
Kristian Høgsberg | af7b1ff | 2012-06-26 21:19:23 -0400 | [diff] [blame] | 3222 | } |
| 3223 | |
| 3224 | static void |
Kristian Høgsberg | 7584062 | 2011-09-06 13:48:16 -0400 | [diff] [blame] | 3225 | desktop_shell_set_background(struct wl_client *client, |
| 3226 | struct wl_resource *resource, |
Benjamin Franzke | d0f79ab | 2011-11-22 12:43:52 +0100 | [diff] [blame] | 3227 | struct wl_resource *output_resource, |
Kristian Høgsberg | 7584062 | 2011-09-06 13:48:16 -0400 | [diff] [blame] | 3228 | struct wl_resource *surface_resource) |
| 3229 | { |
Jason Ekstrand | 651f00e | 2013-06-14 10:07:54 -0500 | [diff] [blame] | 3230 | struct desktop_shell *shell = wl_resource_get_user_data(resource); |
Jason Ekstrand | 0f2ef7e | 2013-06-14 10:07:53 -0500 | [diff] [blame] | 3231 | struct weston_surface *surface = |
| 3232 | wl_resource_get_user_data(surface_resource); |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 3233 | struct weston_view *view, *next; |
Kristian Høgsberg | 7584062 | 2011-09-06 13:48:16 -0400 | [diff] [blame] | 3234 | |
Kristian Høgsberg | 962342c | 2012-06-26 16:29:50 -0400 | [diff] [blame] | 3235 | if (surface->configure) { |
| 3236 | wl_resource_post_error(surface_resource, |
| 3237 | WL_DISPLAY_ERROR_INVALID_OBJECT, |
| 3238 | "surface role already assigned"); |
| 3239 | return; |
| 3240 | } |
Benjamin Franzke | d0f79ab | 2011-11-22 12:43:52 +0100 | [diff] [blame] | 3241 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 3242 | wl_list_for_each_safe(view, next, &surface->views, surface_link) |
| 3243 | weston_view_destroy(view); |
| 3244 | view = weston_view_create(surface); |
| 3245 | |
Kristian Høgsberg | 962342c | 2012-06-26 16:29:50 -0400 | [diff] [blame] | 3246 | surface->configure = background_configure; |
Giulio Camuffo | 7fe01b1 | 2013-03-28 18:02:42 +0100 | [diff] [blame] | 3247 | surface->configure_private = shell; |
Jason Ekstrand | a0d2dde | 2013-06-14 10:08:01 -0500 | [diff] [blame] | 3248 | surface->output = wl_resource_get_user_data(output_resource); |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 3249 | view->output = surface->output; |
Kristian Høgsberg | eae5de7 | 2012-04-11 22:42:15 -0400 | [diff] [blame] | 3250 | desktop_shell_send_configure(resource, 0, |
Kristian Høgsberg | 0b5cd0c | 2012-03-04 21:57:37 -0500 | [diff] [blame] | 3251 | surface_resource, |
Scott Moreau | 1bad5db | 2012-08-18 01:04:05 -0600 | [diff] [blame] | 3252 | surface->output->width, |
| 3253 | surface->output->height); |
Kristian Høgsberg | 7584062 | 2011-09-06 13:48:16 -0400 | [diff] [blame] | 3254 | } |
| 3255 | |
| 3256 | static void |
Jason Ekstrand | 918f2dd | 2013-12-02 21:01:53 -0600 | [diff] [blame] | 3257 | 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] | 3258 | { |
Giulio Camuffo | 7fe01b1 | 2013-03-28 18:02:42 +0100 | [diff] [blame] | 3259 | struct desktop_shell *shell = es->configure_private; |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 3260 | struct weston_view *view; |
Kristian Høgsberg | af7b1ff | 2012-06-26 21:19:23 -0400 | [diff] [blame] | 3261 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 3262 | view = container_of(es->views.next, struct weston_view, surface_link); |
| 3263 | |
Jason Ekstrand | 918f2dd | 2013-12-02 21:01:53 -0600 | [diff] [blame] | 3264 | configure_static_view(view, &shell->panel_layer); |
Kristian Høgsberg | af7b1ff | 2012-06-26 21:19:23 -0400 | [diff] [blame] | 3265 | } |
| 3266 | |
| 3267 | static void |
Kristian Høgsberg | 7584062 | 2011-09-06 13:48:16 -0400 | [diff] [blame] | 3268 | desktop_shell_set_panel(struct wl_client *client, |
| 3269 | struct wl_resource *resource, |
Benjamin Franzke | d0f79ab | 2011-11-22 12:43:52 +0100 | [diff] [blame] | 3270 | struct wl_resource *output_resource, |
Kristian Høgsberg | 7584062 | 2011-09-06 13:48:16 -0400 | [diff] [blame] | 3271 | struct wl_resource *surface_resource) |
| 3272 | { |
Jason Ekstrand | 651f00e | 2013-06-14 10:07:54 -0500 | [diff] [blame] | 3273 | struct desktop_shell *shell = wl_resource_get_user_data(resource); |
Jason Ekstrand | 0f2ef7e | 2013-06-14 10:07:53 -0500 | [diff] [blame] | 3274 | struct weston_surface *surface = |
| 3275 | wl_resource_get_user_data(surface_resource); |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 3276 | struct weston_view *view, *next; |
Kristian Høgsberg | 7584062 | 2011-09-06 13:48:16 -0400 | [diff] [blame] | 3277 | |
Kristian Høgsberg | af7b1ff | 2012-06-26 21:19:23 -0400 | [diff] [blame] | 3278 | if (surface->configure) { |
| 3279 | wl_resource_post_error(surface_resource, |
| 3280 | WL_DISPLAY_ERROR_INVALID_OBJECT, |
| 3281 | "surface role already assigned"); |
| 3282 | return; |
| 3283 | } |
Benjamin Franzke | d0f79ab | 2011-11-22 12:43:52 +0100 | [diff] [blame] | 3284 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 3285 | wl_list_for_each_safe(view, next, &surface->views, surface_link) |
| 3286 | weston_view_destroy(view); |
| 3287 | view = weston_view_create(surface); |
| 3288 | |
Kristian Høgsberg | af7b1ff | 2012-06-26 21:19:23 -0400 | [diff] [blame] | 3289 | surface->configure = panel_configure; |
Giulio Camuffo | 7fe01b1 | 2013-03-28 18:02:42 +0100 | [diff] [blame] | 3290 | surface->configure_private = shell; |
Jason Ekstrand | a0d2dde | 2013-06-14 10:08:01 -0500 | [diff] [blame] | 3291 | surface->output = wl_resource_get_user_data(output_resource); |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 3292 | view->output = surface->output; |
Kristian Høgsberg | eae5de7 | 2012-04-11 22:42:15 -0400 | [diff] [blame] | 3293 | desktop_shell_send_configure(resource, 0, |
Kristian Høgsberg | af7b1ff | 2012-06-26 21:19:23 -0400 | [diff] [blame] | 3294 | surface_resource, |
Scott Moreau | 1bad5db | 2012-08-18 01:04:05 -0600 | [diff] [blame] | 3295 | surface->output->width, |
| 3296 | surface->output->height); |
Kristian Høgsberg | 7584062 | 2011-09-06 13:48:16 -0400 | [diff] [blame] | 3297 | } |
| 3298 | |
Pekka Paalanen | 9ef3e01 | 2011-11-15 13:34:48 +0200 | [diff] [blame] | 3299 | static void |
Jason Ekstrand | 918f2dd | 2013-12-02 21:01:53 -0600 | [diff] [blame] | 3300 | 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] | 3301 | { |
Giulio Camuffo | 7fe01b1 | 2013-03-28 18:02:42 +0100 | [diff] [blame] | 3302 | struct desktop_shell *shell = surface->configure_private; |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 3303 | struct weston_view *view; |
| 3304 | |
| 3305 | view = container_of(surface->views.next, struct weston_view, surface_link); |
Kristian Høgsberg | 730c94d | 2012-06-26 21:44:35 -0400 | [diff] [blame] | 3306 | |
Jason Ekstrand | 918f2dd | 2013-12-02 21:01:53 -0600 | [diff] [blame] | 3307 | if (surface->width == 0) |
Giulio Camuffo | 184df50 | 2013-02-21 11:29:21 +0100 | [diff] [blame] | 3308 | return; |
| 3309 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 3310 | center_on_output(view, get_default_output(shell->compositor)); |
Kristian Høgsberg | 730c94d | 2012-06-26 21:44:35 -0400 | [diff] [blame] | 3311 | |
| 3312 | if (!weston_surface_is_mapped(surface)) { |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 3313 | wl_list_insert(&shell->lock_layer.view_list, |
| 3314 | &view->layer_link); |
| 3315 | weston_view_update_transform(view); |
Ander Conselvan de Oliveira | 87524b6 | 2013-02-21 18:35:22 +0200 | [diff] [blame] | 3316 | shell_fade(shell, FADE_IN); |
Kristian Høgsberg | 730c94d | 2012-06-26 21:44:35 -0400 | [diff] [blame] | 3317 | } |
| 3318 | } |
| 3319 | |
| 3320 | static void |
Kristian Høgsberg | 27e3052 | 2012-04-11 23:18:23 -0400 | [diff] [blame] | 3321 | handle_lock_surface_destroy(struct wl_listener *listener, void *data) |
Kristian Høgsberg | 1ec0c31 | 2011-11-15 16:39:55 -0500 | [diff] [blame] | 3322 | { |
Tiago Vignatti | be14326 | 2012-04-16 17:31:41 +0300 | [diff] [blame] | 3323 | struct desktop_shell *shell = |
| 3324 | container_of(listener, struct desktop_shell, lock_surface_listener); |
Kristian Høgsberg | 1ec0c31 | 2011-11-15 16:39:55 -0500 | [diff] [blame] | 3325 | |
Martin Minarik | 6d11836 | 2012-06-07 18:01:59 +0200 | [diff] [blame] | 3326 | weston_log("lock surface gone\n"); |
Kristian Høgsberg | 1ec0c31 | 2011-11-15 16:39:55 -0500 | [diff] [blame] | 3327 | shell->lock_surface = NULL; |
| 3328 | } |
| 3329 | |
| 3330 | static void |
Pekka Paalanen | 9ef3e01 | 2011-11-15 13:34:48 +0200 | [diff] [blame] | 3331 | desktop_shell_set_lock_surface(struct wl_client *client, |
| 3332 | struct wl_resource *resource, |
| 3333 | struct wl_resource *surface_resource) |
| 3334 | { |
Jason Ekstrand | 651f00e | 2013-06-14 10:07:54 -0500 | [diff] [blame] | 3335 | struct desktop_shell *shell = wl_resource_get_user_data(resource); |
Jason Ekstrand | 0f2ef7e | 2013-06-14 10:07:53 -0500 | [diff] [blame] | 3336 | struct weston_surface *surface = |
| 3337 | wl_resource_get_user_data(surface_resource); |
Pekka Paalanen | 9826223 | 2011-12-01 10:42:22 +0200 | [diff] [blame] | 3338 | |
Pekka Paalanen | f0fc70d | 2011-11-15 13:34:54 +0200 | [diff] [blame] | 3339 | shell->prepare_event_sent = false; |
Kristian Høgsberg | af867cc | 2011-11-15 13:34:49 +0200 | [diff] [blame] | 3340 | |
Pekka Paalanen | f0fc70d | 2011-11-15 13:34:54 +0200 | [diff] [blame] | 3341 | if (!shell->locked) |
| 3342 | return; |
| 3343 | |
Pekka Paalanen | 9826223 | 2011-12-01 10:42:22 +0200 | [diff] [blame] | 3344 | shell->lock_surface = surface; |
Pekka Paalanen | f0fc70d | 2011-11-15 13:34:54 +0200 | [diff] [blame] | 3345 | |
Kristian Høgsberg | 27e3052 | 2012-04-11 23:18:23 -0400 | [diff] [blame] | 3346 | shell->lock_surface_listener.notify = handle_lock_surface_destroy; |
Jason Ekstrand | 651f00e | 2013-06-14 10:07:54 -0500 | [diff] [blame] | 3347 | wl_signal_add(&surface->destroy_signal, |
Kristian Høgsberg | 27e3052 | 2012-04-11 23:18:23 -0400 | [diff] [blame] | 3348 | &shell->lock_surface_listener); |
Pekka Paalanen | 57da4a8 | 2011-11-23 16:42:16 +0200 | [diff] [blame] | 3349 | |
Kristian Høgsberg | aa2ee8b | 2013-10-30 15:49:45 -0700 | [diff] [blame] | 3350 | weston_view_create(surface); |
Kristian Høgsberg | 730c94d | 2012-06-26 21:44:35 -0400 | [diff] [blame] | 3351 | surface->configure = lock_surface_configure; |
Giulio Camuffo | 7fe01b1 | 2013-03-28 18:02:42 +0100 | [diff] [blame] | 3352 | surface->configure_private = shell; |
Pekka Paalanen | f0fc70d | 2011-11-15 13:34:54 +0200 | [diff] [blame] | 3353 | } |
| 3354 | |
| 3355 | static void |
Tiago Vignatti | be14326 | 2012-04-16 17:31:41 +0300 | [diff] [blame] | 3356 | resume_desktop(struct desktop_shell *shell) |
Pekka Paalanen | f0fc70d | 2011-11-15 13:34:54 +0200 | [diff] [blame] | 3357 | { |
Kristian Høgsberg | 4476aaf | 2012-06-25 14:03:13 -0400 | [diff] [blame] | 3358 | struct workspace *ws = get_current_workspace(shell); |
Pekka Paalanen | 77346a6 | 2011-11-30 16:26:35 +0200 | [diff] [blame] | 3359 | |
Pekka Paalanen | 77346a6 | 2011-11-30 16:26:35 +0200 | [diff] [blame] | 3360 | terminate_screensaver(shell); |
Pekka Paalanen | f0fc70d | 2011-11-15 13:34:54 +0200 | [diff] [blame] | 3361 | |
Kristian Høgsberg | 3be2ce9 | 2012-02-29 12:42:35 -0500 | [diff] [blame] | 3362 | wl_list_remove(&shell->lock_layer.link); |
| 3363 | wl_list_insert(&shell->compositor->cursor_layer.link, |
| 3364 | &shell->fullscreen_layer.link); |
| 3365 | wl_list_insert(&shell->fullscreen_layer.link, |
| 3366 | &shell->panel_layer.link); |
Philipp Brüschweiler | 711fda8 | 2012-08-09 18:50:43 +0200 | [diff] [blame] | 3367 | if (shell->showing_input_panels) { |
| 3368 | wl_list_insert(&shell->panel_layer.link, |
| 3369 | &shell->input_panel_layer.link); |
| 3370 | wl_list_insert(&shell->input_panel_layer.link, |
| 3371 | &ws->layer.link); |
| 3372 | } else { |
| 3373 | wl_list_insert(&shell->panel_layer.link, &ws->layer.link); |
| 3374 | } |
Pekka Paalanen | f0fc70d | 2011-11-15 13:34:54 +0200 | [diff] [blame] | 3375 | |
Kristian Høgsberg | 2f5faff | 2012-07-31 16:36:34 -0400 | [diff] [blame] | 3376 | restore_focus_state(shell, get_current_workspace(shell)); |
Jonas Ådahl | 0476974 | 2012-06-13 00:01:24 +0200 | [diff] [blame] | 3377 | |
Pekka Paalanen | f0fc70d | 2011-11-15 13:34:54 +0200 | [diff] [blame] | 3378 | shell->locked = false; |
Ander Conselvan de Oliveira | 87524b6 | 2013-02-21 18:35:22 +0200 | [diff] [blame] | 3379 | shell_fade(shell, FADE_IN); |
Pekka Paalanen | fc6d91a | 2012-02-10 15:33:10 +0200 | [diff] [blame] | 3380 | weston_compositor_damage_all(shell->compositor); |
Pekka Paalanen | 9ef3e01 | 2011-11-15 13:34:48 +0200 | [diff] [blame] | 3381 | } |
| 3382 | |
| 3383 | static void |
| 3384 | desktop_shell_unlock(struct wl_client *client, |
| 3385 | struct wl_resource *resource) |
| 3386 | { |
Jason Ekstrand | 651f00e | 2013-06-14 10:07:54 -0500 | [diff] [blame] | 3387 | struct desktop_shell *shell = wl_resource_get_user_data(resource); |
Pekka Paalanen | 9ef3e01 | 2011-11-15 13:34:48 +0200 | [diff] [blame] | 3388 | |
Pekka Paalanen | 9ef3e01 | 2011-11-15 13:34:48 +0200 | [diff] [blame] | 3389 | shell->prepare_event_sent = false; |
Pekka Paalanen | f0fc70d | 2011-11-15 13:34:54 +0200 | [diff] [blame] | 3390 | |
| 3391 | if (shell->locked) |
| 3392 | resume_desktop(shell); |
Pekka Paalanen | 9ef3e01 | 2011-11-15 13:34:48 +0200 | [diff] [blame] | 3393 | } |
| 3394 | |
Kristian Høgsberg | d56bd90 | 2012-06-05 09:58:51 -0400 | [diff] [blame] | 3395 | static void |
Ander Conselvan de Oliveira | b9d2a0f | 2012-06-28 18:08:05 +0300 | [diff] [blame] | 3396 | desktop_shell_set_grab_surface(struct wl_client *client, |
Kristian Høgsberg | d56bd90 | 2012-06-05 09:58:51 -0400 | [diff] [blame] | 3397 | struct wl_resource *resource, |
| 3398 | struct wl_resource *surface_resource) |
| 3399 | { |
Jason Ekstrand | 651f00e | 2013-06-14 10:07:54 -0500 | [diff] [blame] | 3400 | struct desktop_shell *shell = wl_resource_get_user_data(resource); |
Kristian Høgsberg | d56bd90 | 2012-06-05 09:58:51 -0400 | [diff] [blame] | 3401 | |
Jason Ekstrand | 0f2ef7e | 2013-06-14 10:07:53 -0500 | [diff] [blame] | 3402 | shell->grab_surface = wl_resource_get_user_data(surface_resource); |
Kristian Høgsberg | 48588f8 | 2013-10-24 15:51:35 -0700 | [diff] [blame] | 3403 | weston_view_create(shell->grab_surface); |
Kristian Høgsberg | d56bd90 | 2012-06-05 09:58:51 -0400 | [diff] [blame] | 3404 | } |
| 3405 | |
Pekka Paalanen | 79346ab | 2013-05-22 18:03:09 +0300 | [diff] [blame] | 3406 | static void |
| 3407 | desktop_shell_desktop_ready(struct wl_client *client, |
| 3408 | struct wl_resource *resource) |
| 3409 | { |
Jason Ekstrand | 651f00e | 2013-06-14 10:07:54 -0500 | [diff] [blame] | 3410 | struct desktop_shell *shell = wl_resource_get_user_data(resource); |
Pekka Paalanen | 79346ab | 2013-05-22 18:03:09 +0300 | [diff] [blame] | 3411 | |
| 3412 | shell_fade_startup(shell); |
| 3413 | } |
| 3414 | |
Kristian Høgsberg | 7584062 | 2011-09-06 13:48:16 -0400 | [diff] [blame] | 3415 | static const struct desktop_shell_interface desktop_shell_implementation = { |
| 3416 | desktop_shell_set_background, |
Pekka Paalanen | 9ef3e01 | 2011-11-15 13:34:48 +0200 | [diff] [blame] | 3417 | desktop_shell_set_panel, |
| 3418 | desktop_shell_set_lock_surface, |
Kristian Høgsberg | d56bd90 | 2012-06-05 09:58:51 -0400 | [diff] [blame] | 3419 | desktop_shell_unlock, |
Pekka Paalanen | 79346ab | 2013-05-22 18:03:09 +0300 | [diff] [blame] | 3420 | desktop_shell_set_grab_surface, |
| 3421 | desktop_shell_desktop_ready |
Kristian Høgsberg | 7584062 | 2011-09-06 13:48:16 -0400 | [diff] [blame] | 3422 | }; |
| 3423 | |
Pekka Paalanen | 92a0dc4 | 2011-11-28 15:34:13 +0200 | [diff] [blame] | 3424 | static enum shell_surface_type |
Kristian Høgsberg | 8334bc1 | 2012-01-03 10:29:47 -0500 | [diff] [blame] | 3425 | get_shell_surface_type(struct weston_surface *surface) |
Pekka Paalanen | 92a0dc4 | 2011-11-28 15:34:13 +0200 | [diff] [blame] | 3426 | { |
| 3427 | struct shell_surface *shsurf; |
| 3428 | |
| 3429 | shsurf = get_shell_surface(surface); |
| 3430 | if (!shsurf) |
Pekka Paalanen | 9826223 | 2011-12-01 10:42:22 +0200 | [diff] [blame] | 3431 | return SHELL_SURFACE_NONE; |
Pekka Paalanen | 92a0dc4 | 2011-11-28 15:34:13 +0200 | [diff] [blame] | 3432 | return shsurf->type; |
| 3433 | } |
| 3434 | |
Kristian Høgsberg | 7584062 | 2011-09-06 13:48:16 -0400 | [diff] [blame] | 3435 | static void |
Kristian Høgsberg | e314875 | 2013-05-06 23:19:49 -0400 | [diff] [blame] | 3436 | 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] | 3437 | { |
Kristian Høgsberg | 7ab139c | 2013-10-24 16:21:39 -0700 | [diff] [blame] | 3438 | struct weston_surface *focus = seat->pointer->focus->surface; |
Pekka Paalanen | 01388e2 | 2013-04-25 13:57:44 +0300 | [diff] [blame] | 3439 | struct weston_surface *surface; |
Kristian Høgsberg | 938b8fa | 2012-05-18 13:46:27 -0400 | [diff] [blame] | 3440 | struct shell_surface *shsurf; |
Kristian Høgsberg | d2abb83 | 2011-11-23 10:52:40 -0500 | [diff] [blame] | 3441 | |
Pekka Paalanen | 01388e2 | 2013-04-25 13:57:44 +0300 | [diff] [blame] | 3442 | surface = weston_surface_get_main_surface(focus); |
Benjamin Franzke | d0f79ab | 2011-11-22 12:43:52 +0100 | [diff] [blame] | 3443 | if (surface == NULL) |
| 3444 | return; |
Kristian Høgsberg | 0793756 | 2011-04-12 17:25:42 -0400 | [diff] [blame] | 3445 | |
Kristian Høgsberg | 938b8fa | 2012-05-18 13:46:27 -0400 | [diff] [blame] | 3446 | shsurf = get_shell_surface(surface); |
Rafael Antognolli | 03b1659 | 2013-12-03 15:35:42 -0200 | [diff] [blame] | 3447 | if (shsurf == NULL || shsurf->state.fullscreen || |
| 3448 | shsurf->state.maximized) |
Kristian Høgsberg | 938b8fa | 2012-05-18 13:46:27 -0400 | [diff] [blame] | 3449 | return; |
| 3450 | |
Kristian Høgsberg | 938b8fa | 2012-05-18 13:46:27 -0400 | [diff] [blame] | 3451 | surface_move(shsurf, (struct weston_seat *) seat); |
Kristian Høgsberg | 0793756 | 2011-04-12 17:25:42 -0400 | [diff] [blame] | 3452 | } |
| 3453 | |
| 3454 | static void |
Neil Roberts | aba0f25 | 2013-10-03 16:43:05 +0100 | [diff] [blame] | 3455 | touch_move_binding(struct weston_seat *seat, uint32_t time, void *data) |
| 3456 | { |
Kristian Høgsberg | 7ab139c | 2013-10-24 16:21:39 -0700 | [diff] [blame] | 3457 | struct weston_surface *focus = seat->touch->focus->surface; |
Neil Roberts | aba0f25 | 2013-10-03 16:43:05 +0100 | [diff] [blame] | 3458 | struct weston_surface *surface; |
| 3459 | struct shell_surface *shsurf; |
| 3460 | |
| 3461 | surface = weston_surface_get_main_surface(focus); |
| 3462 | if (surface == NULL) |
| 3463 | return; |
| 3464 | |
| 3465 | shsurf = get_shell_surface(surface); |
Rafael Antognolli | 03b1659 | 2013-12-03 15:35:42 -0200 | [diff] [blame] | 3466 | if (shsurf == NULL || shsurf->state.fullscreen || |
| 3467 | shsurf->state.maximized) |
Neil Roberts | aba0f25 | 2013-10-03 16:43:05 +0100 | [diff] [blame] | 3468 | return; |
| 3469 | |
| 3470 | surface_touch_move(shsurf, (struct weston_seat *) seat); |
| 3471 | } |
| 3472 | |
| 3473 | static void |
Kristian Høgsberg | e314875 | 2013-05-06 23:19:49 -0400 | [diff] [blame] | 3474 | 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] | 3475 | { |
Kristian Høgsberg | 7ab139c | 2013-10-24 16:21:39 -0700 | [diff] [blame] | 3476 | struct weston_surface *focus = seat->pointer->focus->surface; |
Pekka Paalanen | 01388e2 | 2013-04-25 13:57:44 +0300 | [diff] [blame] | 3477 | struct weston_surface *surface; |
Kristian Høgsberg | 0793756 | 2011-04-12 17:25:42 -0400 | [diff] [blame] | 3478 | uint32_t edges = 0; |
| 3479 | int32_t x, y; |
Pekka Paalanen | 9d1613e | 2011-11-25 12:09:16 +0200 | [diff] [blame] | 3480 | struct shell_surface *shsurf; |
Kristian Høgsberg | d2abb83 | 2011-11-23 10:52:40 -0500 | [diff] [blame] | 3481 | |
Pekka Paalanen | 01388e2 | 2013-04-25 13:57:44 +0300 | [diff] [blame] | 3482 | surface = weston_surface_get_main_surface(focus); |
Benjamin Franzke | d0f79ab | 2011-11-22 12:43:52 +0100 | [diff] [blame] | 3483 | if (surface == NULL) |
| 3484 | return; |
Pekka Paalanen | 92a0dc4 | 2011-11-28 15:34:13 +0200 | [diff] [blame] | 3485 | |
Pekka Paalanen | 9d1613e | 2011-11-25 12:09:16 +0200 | [diff] [blame] | 3486 | shsurf = get_shell_surface(surface); |
Rafael Antognolli | 03b1659 | 2013-12-03 15:35:42 -0200 | [diff] [blame] | 3487 | if (shsurf == NULL || shsurf->state.fullscreen || |
| 3488 | shsurf->state.maximized) |
Pekka Paalanen | 92a0dc4 | 2011-11-28 15:34:13 +0200 | [diff] [blame] | 3489 | return; |
| 3490 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 3491 | weston_view_from_global(shsurf->view, |
| 3492 | wl_fixed_to_int(seat->pointer->grab_x), |
| 3493 | wl_fixed_to_int(seat->pointer->grab_y), |
| 3494 | &x, &y); |
Kristian Høgsberg | 0793756 | 2011-04-12 17:25:42 -0400 | [diff] [blame] | 3495 | |
Jason Ekstrand | 918f2dd | 2013-12-02 21:01:53 -0600 | [diff] [blame] | 3496 | if (x < shsurf->surface->width / 3) |
Pekka Paalanen | 9d1613e | 2011-11-25 12:09:16 +0200 | [diff] [blame] | 3497 | edges |= WL_SHELL_SURFACE_RESIZE_LEFT; |
Jason Ekstrand | 918f2dd | 2013-12-02 21:01:53 -0600 | [diff] [blame] | 3498 | else if (x < 2 * shsurf->surface->width / 3) |
Kristian Høgsberg | 0793756 | 2011-04-12 17:25:42 -0400 | [diff] [blame] | 3499 | edges |= 0; |
| 3500 | else |
Pekka Paalanen | 9d1613e | 2011-11-25 12:09:16 +0200 | [diff] [blame] | 3501 | edges |= WL_SHELL_SURFACE_RESIZE_RIGHT; |
Kristian Høgsberg | 0793756 | 2011-04-12 17:25:42 -0400 | [diff] [blame] | 3502 | |
Jason Ekstrand | 918f2dd | 2013-12-02 21:01:53 -0600 | [diff] [blame] | 3503 | if (y < shsurf->surface->height / 3) |
Pekka Paalanen | 9d1613e | 2011-11-25 12:09:16 +0200 | [diff] [blame] | 3504 | edges |= WL_SHELL_SURFACE_RESIZE_TOP; |
Jason Ekstrand | 918f2dd | 2013-12-02 21:01:53 -0600 | [diff] [blame] | 3505 | else if (y < 2 * shsurf->surface->height / 3) |
Kristian Høgsberg | 0793756 | 2011-04-12 17:25:42 -0400 | [diff] [blame] | 3506 | edges |= 0; |
| 3507 | else |
Pekka Paalanen | 9d1613e | 2011-11-25 12:09:16 +0200 | [diff] [blame] | 3508 | edges |= WL_SHELL_SURFACE_RESIZE_BOTTOM; |
Kristian Høgsberg | 0793756 | 2011-04-12 17:25:42 -0400 | [diff] [blame] | 3509 | |
Kristian Høgsberg | c1693f2 | 2012-05-22 16:56:23 -0400 | [diff] [blame] | 3510 | surface_resize(shsurf, (struct weston_seat *) seat, edges); |
Kristian Høgsberg | 02ec0a5 | 2011-04-23 13:04:11 -0400 | [diff] [blame] | 3511 | } |
| 3512 | |
| 3513 | static void |
Kristian Høgsberg | e314875 | 2013-05-06 23:19:49 -0400 | [diff] [blame] | 3514 | 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] | 3515 | wl_fixed_t value, void *data) |
Scott Moreau | a3aa9c9 | 2012-03-22 11:01:03 -0600 | [diff] [blame] | 3516 | { |
Jonas Ådahl | b0b87ba | 2012-09-27 18:40:42 +0200 | [diff] [blame] | 3517 | float step = 0.005; |
Scott Moreau | a3aa9c9 | 2012-03-22 11:01:03 -0600 | [diff] [blame] | 3518 | struct shell_surface *shsurf; |
Kristian Høgsberg | 7ab139c | 2013-10-24 16:21:39 -0700 | [diff] [blame] | 3519 | struct weston_surface *focus = seat->pointer->focus->surface; |
Pekka Paalanen | 01388e2 | 2013-04-25 13:57:44 +0300 | [diff] [blame] | 3520 | struct weston_surface *surface; |
Scott Moreau | a3aa9c9 | 2012-03-22 11:01:03 -0600 | [diff] [blame] | 3521 | |
Pekka Paalanen | 01388e2 | 2013-04-25 13:57:44 +0300 | [diff] [blame] | 3522 | /* XXX: broken for windows containing sub-surfaces */ |
| 3523 | surface = weston_surface_get_main_surface(focus); |
Scott Moreau | a3aa9c9 | 2012-03-22 11:01:03 -0600 | [diff] [blame] | 3524 | if (surface == NULL) |
| 3525 | return; |
| 3526 | |
| 3527 | shsurf = get_shell_surface(surface); |
| 3528 | if (!shsurf) |
| 3529 | return; |
| 3530 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 3531 | shsurf->view->alpha -= wl_fixed_to_double(value) * step; |
Scott Moreau | a3aa9c9 | 2012-03-22 11:01:03 -0600 | [diff] [blame] | 3532 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 3533 | if (shsurf->view->alpha > 1.0) |
| 3534 | shsurf->view->alpha = 1.0; |
| 3535 | if (shsurf->view->alpha < step) |
| 3536 | shsurf->view->alpha = step; |
Scott Moreau | a3aa9c9 | 2012-03-22 11:01:03 -0600 | [diff] [blame] | 3537 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 3538 | weston_view_geometry_dirty(shsurf->view); |
Scott Moreau | a3aa9c9 | 2012-03-22 11:01:03 -0600 | [diff] [blame] | 3539 | weston_surface_damage(surface); |
| 3540 | } |
| 3541 | |
| 3542 | static void |
Kristian Høgsberg | e314875 | 2013-05-06 23:19:49 -0400 | [diff] [blame] | 3543 | 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] | 3544 | wl_fixed_t value) |
Scott Moreau | ccbf29d | 2012-02-22 14:21:41 -0700 | [diff] [blame] | 3545 | { |
Daniel Stone | 37816df | 2012-05-16 18:45:18 +0100 | [diff] [blame] | 3546 | struct weston_seat *ws = (struct weston_seat *) seat; |
| 3547 | struct weston_compositor *compositor = ws->compositor; |
Scott Moreau | ccbf29d | 2012-02-22 14:21:41 -0700 | [diff] [blame] | 3548 | struct weston_output *output; |
Scott Moreau | e660398 | 2012-06-11 13:07:51 -0600 | [diff] [blame] | 3549 | float increment; |
Scott Moreau | ccbf29d | 2012-02-22 14:21:41 -0700 | [diff] [blame] | 3550 | |
| 3551 | wl_list_for_each(output, &compositor->output_list, link) { |
| 3552 | if (pixman_region32_contains_point(&output->region, |
Daniel Stone | 37816df | 2012-05-16 18:45:18 +0100 | [diff] [blame] | 3553 | wl_fixed_to_double(seat->pointer->x), |
| 3554 | wl_fixed_to_double(seat->pointer->y), |
Daniel Stone | 103db7f | 2012-05-08 17:17:55 +0100 | [diff] [blame] | 3555 | NULL)) { |
Daniel Stone | 325fc2d | 2012-05-30 16:31:58 +0100 | [diff] [blame] | 3556 | if (key == KEY_PAGEUP) |
Kristian Høgsberg | 9b68af0 | 2012-05-22 12:55:18 -0400 | [diff] [blame] | 3557 | increment = output->zoom.increment; |
Daniel Stone | 325fc2d | 2012-05-30 16:31:58 +0100 | [diff] [blame] | 3558 | else if (key == KEY_PAGEDOWN) |
Kristian Høgsberg | 9b68af0 | 2012-05-22 12:55:18 -0400 | [diff] [blame] | 3559 | increment = -output->zoom.increment; |
| 3560 | else if (axis == WL_POINTER_AXIS_VERTICAL_SCROLL) |
Jonas Ådahl | b0b87ba | 2012-09-27 18:40:42 +0200 | [diff] [blame] | 3561 | /* For every pixel zoom 20th of a step */ |
Daniel Stone | 0c1e46e | 2012-05-30 16:31:59 +0100 | [diff] [blame] | 3562 | increment = output->zoom.increment * |
Jonas Ådahl | b0b87ba | 2012-09-27 18:40:42 +0200 | [diff] [blame] | 3563 | -wl_fixed_to_double(value) / 20.0; |
Kristian Høgsberg | 9b68af0 | 2012-05-22 12:55:18 -0400 | [diff] [blame] | 3564 | else |
| 3565 | increment = 0; |
| 3566 | |
Kristian Høgsberg | 9b68af0 | 2012-05-22 12:55:18 -0400 | [diff] [blame] | 3567 | output->zoom.level += increment; |
Scott Moreau | c6d7f60 | 2012-02-23 22:28:37 -0700 | [diff] [blame] | 3568 | |
Scott Moreau | e660398 | 2012-06-11 13:07:51 -0600 | [diff] [blame] | 3569 | if (output->zoom.level < 0.0) |
Scott Moreau | 850ca42 | 2012-05-21 15:21:25 -0600 | [diff] [blame] | 3570 | output->zoom.level = 0.0; |
Scott Moreau | e660398 | 2012-06-11 13:07:51 -0600 | [diff] [blame] | 3571 | else if (output->zoom.level > output->zoom.max_level) |
| 3572 | output->zoom.level = output->zoom.max_level; |
Ville Syrjälä | aa628d0 | 2012-11-16 11:48:47 +0200 | [diff] [blame] | 3573 | else if (!output->zoom.active) { |
Giulio Camuffo | 412b024 | 2013-11-14 23:42:51 +0100 | [diff] [blame] | 3574 | weston_output_activate_zoom(output); |
Kristian Høgsberg | 79af73e | 2012-08-03 15:45:23 -0400 | [diff] [blame] | 3575 | } |
Scott Moreau | ccbf29d | 2012-02-22 14:21:41 -0700 | [diff] [blame] | 3576 | |
Scott Moreau | e660398 | 2012-06-11 13:07:51 -0600 | [diff] [blame] | 3577 | output->zoom.spring_z.target = output->zoom.level; |
Scott Moreau | ccbf29d | 2012-02-22 14:21:41 -0700 | [diff] [blame] | 3578 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 3579 | weston_output_update_zoom(output); |
Scott Moreau | ccbf29d | 2012-02-22 14:21:41 -0700 | [diff] [blame] | 3580 | } |
| 3581 | } |
| 3582 | } |
| 3583 | |
Scott Moreau | ccbf29d | 2012-02-22 14:21:41 -0700 | [diff] [blame] | 3584 | static void |
Kristian Høgsberg | e314875 | 2013-05-06 23:19:49 -0400 | [diff] [blame] | 3585 | 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] | 3586 | wl_fixed_t value, void *data) |
Daniel Stone | 325fc2d | 2012-05-30 16:31:58 +0100 | [diff] [blame] | 3587 | { |
| 3588 | do_zoom(seat, time, 0, axis, value); |
| 3589 | } |
| 3590 | |
| 3591 | static void |
Kristian Høgsberg | e314875 | 2013-05-06 23:19:49 -0400 | [diff] [blame] | 3592 | 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] | 3593 | void *data) |
| 3594 | { |
| 3595 | do_zoom(seat, time, key, 0, 0); |
| 3596 | } |
| 3597 | |
| 3598 | static void |
Kristian Høgsberg | e314875 | 2013-05-06 23:19:49 -0400 | [diff] [blame] | 3599 | terminate_binding(struct weston_seat *seat, uint32_t time, uint32_t key, |
Daniel Stone | 325fc2d | 2012-05-30 16:31:58 +0100 | [diff] [blame] | 3600 | void *data) |
Kristian Høgsberg | e1a850e | 2011-12-19 15:18:05 -0500 | [diff] [blame] | 3601 | { |
Kristian Høgsberg | 8334bc1 | 2012-01-03 10:29:47 -0500 | [diff] [blame] | 3602 | struct weston_compositor *compositor = data; |
Kristian Høgsberg | e1a850e | 2011-12-19 15:18:05 -0500 | [diff] [blame] | 3603 | |
Daniel Stone | 325fc2d | 2012-05-30 16:31:58 +0100 | [diff] [blame] | 3604 | wl_display_terminate(compositor->wl_display); |
Kristian Høgsberg | e1a850e | 2011-12-19 15:18:05 -0500 | [diff] [blame] | 3605 | } |
| 3606 | |
| 3607 | static void |
Emilio Pozuelo Monfort | 03251b6 | 2013-11-19 11:37:16 +0100 | [diff] [blame] | 3608 | lower_fullscreen_layer(struct desktop_shell *shell); |
| 3609 | |
| 3610 | struct alt_tab { |
| 3611 | struct desktop_shell *shell; |
| 3612 | struct weston_keyboard_grab grab; |
| 3613 | |
| 3614 | struct wl_list *current; |
| 3615 | |
| 3616 | struct wl_list preview_list; |
| 3617 | }; |
| 3618 | |
| 3619 | struct alt_tab_preview { |
| 3620 | struct alt_tab *alt_tab; |
| 3621 | |
| 3622 | struct weston_view *view; |
| 3623 | struct weston_transform transform; |
| 3624 | |
| 3625 | struct wl_listener listener; |
| 3626 | |
| 3627 | struct wl_list link; |
| 3628 | }; |
| 3629 | |
| 3630 | static void |
| 3631 | alt_tab_next(struct alt_tab *alt_tab) |
| 3632 | { |
| 3633 | alt_tab->current = alt_tab->current->next; |
| 3634 | |
| 3635 | /* Make sure we're not pointing to the list header e.g. after |
| 3636 | * cycling through the whole list. */ |
| 3637 | if (alt_tab->current->next == alt_tab->preview_list.next) |
| 3638 | alt_tab->current = alt_tab->current->next; |
| 3639 | } |
| 3640 | |
| 3641 | static void |
| 3642 | alt_tab_destroy(struct alt_tab *alt_tab) |
| 3643 | { |
| 3644 | struct alt_tab_preview *preview, *next; |
| 3645 | struct weston_keyboard *keyboard = alt_tab->grab.keyboard; |
| 3646 | |
| 3647 | if (alt_tab->current && alt_tab->current != &alt_tab->preview_list) { |
| 3648 | preview = wl_container_of(alt_tab->current, preview, link); |
| 3649 | |
| 3650 | activate(alt_tab->shell, preview->view->surface, |
| 3651 | (struct weston_seat *) keyboard->seat); |
| 3652 | } |
| 3653 | |
| 3654 | wl_list_for_each_safe(preview, next, &alt_tab->preview_list, link) { |
| 3655 | wl_list_remove(&preview->link); |
| 3656 | wl_list_remove(&preview->listener.link); |
| 3657 | weston_view_destroy(preview->view); |
| 3658 | free(preview); |
| 3659 | } |
| 3660 | |
| 3661 | weston_keyboard_end_grab(keyboard); |
| 3662 | if (keyboard->input_method_resource) |
| 3663 | keyboard->grab = &keyboard->input_method_grab; |
| 3664 | |
| 3665 | free(alt_tab); |
| 3666 | } |
| 3667 | |
| 3668 | static void |
| 3669 | alt_tab_handle_surface_destroy(struct wl_listener *listener, void *data) |
| 3670 | { |
| 3671 | struct alt_tab_preview *preview = |
| 3672 | container_of(listener, struct alt_tab_preview, listener); |
| 3673 | struct alt_tab *alt_tab = preview->alt_tab; |
| 3674 | int advance = 0; |
| 3675 | |
| 3676 | /* If the preview that we're removing is the currently selected one, |
| 3677 | * we want to move to the next one. So we move to ->prev and then |
| 3678 | * call _next() after removing the preview. */ |
| 3679 | if (alt_tab->current == &preview->link) { |
| 3680 | alt_tab->current = alt_tab->current->prev; |
| 3681 | advance = 1; |
| 3682 | } |
| 3683 | |
| 3684 | wl_list_remove(&preview->listener.link); |
| 3685 | wl_list_remove(&preview->link); |
| 3686 | |
| 3687 | free(preview); |
| 3688 | |
| 3689 | if (advance) |
| 3690 | alt_tab_next(alt_tab); |
| 3691 | |
| 3692 | /* If the last preview goes away, stop the alt-tab */ |
| 3693 | if (wl_list_empty(alt_tab->current)) |
| 3694 | alt_tab_destroy(alt_tab); |
| 3695 | } |
| 3696 | |
| 3697 | static void |
| 3698 | alt_tab_key(struct weston_keyboard_grab *grab, |
| 3699 | uint32_t time, uint32_t key, uint32_t state_w) |
| 3700 | { |
| 3701 | struct alt_tab *alt_tab = container_of(grab, struct alt_tab, grab); |
| 3702 | enum wl_keyboard_key_state state = state_w; |
| 3703 | |
| 3704 | if (key == KEY_TAB && state == WL_KEYBOARD_KEY_STATE_PRESSED) |
| 3705 | alt_tab_next(alt_tab); |
| 3706 | } |
| 3707 | |
| 3708 | static void |
| 3709 | alt_tab_modifier(struct weston_keyboard_grab *grab, uint32_t serial, |
| 3710 | uint32_t mods_depressed, uint32_t mods_latched, |
| 3711 | uint32_t mods_locked, uint32_t group) |
| 3712 | { |
| 3713 | struct alt_tab *alt_tab = container_of(grab, struct alt_tab, grab); |
| 3714 | struct weston_seat *seat = (struct weston_seat *) grab->keyboard->seat; |
| 3715 | |
| 3716 | if ((seat->modifier_state & MODIFIER_ALT) == 0) |
| 3717 | alt_tab_destroy(alt_tab); |
| 3718 | } |
| 3719 | |
| 3720 | static void |
| 3721 | alt_tab_cancel(struct weston_keyboard_grab *grab) |
| 3722 | { |
| 3723 | struct alt_tab *alt_tab = container_of(grab, struct alt_tab, grab); |
| 3724 | |
| 3725 | alt_tab_destroy(alt_tab); |
| 3726 | } |
| 3727 | |
| 3728 | static const struct weston_keyboard_grab_interface alt_tab_grab = { |
| 3729 | alt_tab_key, |
| 3730 | alt_tab_modifier, |
| 3731 | alt_tab_cancel, |
| 3732 | }; |
| 3733 | |
| 3734 | static int |
| 3735 | view_for_alt_tab(struct weston_view *view) |
| 3736 | { |
Rafael Antognolli | ed207b4 | 2013-12-03 15:35:43 -0200 | [diff] [blame^] | 3737 | struct shell_surface *shsurf = get_shell_surface(view->surface); |
| 3738 | if (!shsurf) |
Emilio Pozuelo Monfort | 03251b6 | 2013-11-19 11:37:16 +0100 | [diff] [blame] | 3739 | return 0; |
| 3740 | |
Rafael Antognolli | ed207b4 | 2013-12-03 15:35:43 -0200 | [diff] [blame^] | 3741 | if (shsurf->parent) |
Emilio Pozuelo Monfort | 03251b6 | 2013-11-19 11:37:16 +0100 | [diff] [blame] | 3742 | return 0; |
| 3743 | |
| 3744 | if (view != get_default_view(view->surface)) |
| 3745 | return 0; |
| 3746 | |
| 3747 | return 1; |
| 3748 | } |
| 3749 | |
| 3750 | static void |
| 3751 | alt_tab_binding(struct weston_seat *seat, uint32_t time, uint32_t key, |
| 3752 | void *data) |
| 3753 | { |
| 3754 | struct alt_tab *alt_tab; |
| 3755 | struct desktop_shell *shell = data; |
| 3756 | struct weston_output *output = get_default_output(shell->compositor); |
| 3757 | struct workspace *ws; |
| 3758 | struct weston_view *view; |
| 3759 | int num_surfaces = 0; |
| 3760 | int x, y, side, margin; |
| 3761 | |
| 3762 | wl_list_for_each(view, &shell->compositor->view_list, link) { |
| 3763 | |
| 3764 | if (view_for_alt_tab(view)) |
| 3765 | num_surfaces++; |
| 3766 | } |
| 3767 | |
| 3768 | if (!num_surfaces) |
| 3769 | return; |
| 3770 | |
| 3771 | alt_tab = malloc(sizeof *alt_tab); |
| 3772 | if (!alt_tab) |
| 3773 | return; |
| 3774 | |
| 3775 | alt_tab->shell = shell; |
| 3776 | wl_list_init(&alt_tab->preview_list); |
| 3777 | alt_tab->current = &alt_tab->preview_list; |
| 3778 | |
| 3779 | restore_all_output_modes(shell->compositor); |
| 3780 | lower_fullscreen_layer(alt_tab->shell); |
| 3781 | |
| 3782 | alt_tab->grab.interface = &alt_tab_grab; |
| 3783 | weston_keyboard_start_grab(seat->keyboard, &alt_tab->grab); |
| 3784 | weston_keyboard_set_focus(seat->keyboard, NULL); |
| 3785 | |
| 3786 | ws = get_current_workspace(shell); |
| 3787 | |
| 3788 | /* FIXME: add some visual candy e.g. prelight the selected view |
| 3789 | * and/or add a black surrounding background à la gnome-shell */ |
| 3790 | |
| 3791 | /* Determine the size for each preview */ |
| 3792 | side = output->width / num_surfaces; |
| 3793 | if (side > 200) |
| 3794 | side = 200; |
| 3795 | margin = side / 4; |
| 3796 | side -= margin; |
| 3797 | |
| 3798 | x = margin; |
| 3799 | y = (output->height - side) / 2; |
| 3800 | |
| 3801 | /* Create a view for each surface */ |
| 3802 | wl_list_for_each(view, &shell->compositor->view_list, link) { |
| 3803 | struct alt_tab_preview *preview; |
| 3804 | struct weston_view *v; |
| 3805 | float scale; |
| 3806 | |
| 3807 | if (!view_for_alt_tab(view)) |
| 3808 | continue; |
| 3809 | |
| 3810 | preview = malloc(sizeof *preview); |
| 3811 | if (!preview) { |
| 3812 | alt_tab_destroy(alt_tab); |
| 3813 | return; |
| 3814 | } |
| 3815 | |
| 3816 | preview->alt_tab = alt_tab; |
| 3817 | |
| 3818 | preview->view = v = weston_view_create(view->surface); |
| 3819 | v->output = view->output; |
Philip Withnall | 83ffd9d | 2013-11-25 18:01:42 +0000 | [diff] [blame] | 3820 | |
| 3821 | wl_list_remove(&v->layer_link); |
| 3822 | wl_list_insert(&ws->layer.view_list, &v->layer_link); |
| 3823 | weston_view_damage_below(v); |
| 3824 | weston_surface_damage(v->surface); |
| 3825 | |
Jason Ekstrand | 918f2dd | 2013-12-02 21:01:53 -0600 | [diff] [blame] | 3826 | weston_view_set_position(v, x, y); |
Emilio Pozuelo Monfort | 03251b6 | 2013-11-19 11:37:16 +0100 | [diff] [blame] | 3827 | |
| 3828 | preview->listener.notify = alt_tab_handle_surface_destroy; |
| 3829 | wl_signal_add(&v->destroy_signal, &preview->listener); |
| 3830 | |
Jason Ekstrand | 918f2dd | 2013-12-02 21:01:53 -0600 | [diff] [blame] | 3831 | if (view->surface->width > view->surface->height) |
| 3832 | scale = side / (float) view->surface->width; |
Emilio Pozuelo Monfort | 03251b6 | 2013-11-19 11:37:16 +0100 | [diff] [blame] | 3833 | else |
Jason Ekstrand | 918f2dd | 2013-12-02 21:01:53 -0600 | [diff] [blame] | 3834 | scale = side / (float) view->surface->height; |
Emilio Pozuelo Monfort | 03251b6 | 2013-11-19 11:37:16 +0100 | [diff] [blame] | 3835 | |
| 3836 | wl_list_insert(&v->geometry.transformation_list, |
| 3837 | &preview->transform.link); |
| 3838 | weston_matrix_init(&preview->transform.matrix); |
| 3839 | weston_matrix_scale(&preview->transform.matrix, |
| 3840 | scale, scale, 1.0f); |
| 3841 | |
| 3842 | weston_view_geometry_dirty(v); |
| 3843 | weston_compositor_schedule_repaint(v->surface->compositor); |
| 3844 | |
| 3845 | /* Insert at the end of the list */ |
| 3846 | wl_list_insert(alt_tab->preview_list.prev, &preview->link); |
| 3847 | |
| 3848 | x += side + margin; |
| 3849 | } |
| 3850 | |
| 3851 | /* Start at the second preview so a simple <alt>tab changes window. |
| 3852 | * We set `current' to the first preview and not the second because |
| 3853 | * we're going to receive a key press callback for the initial |
| 3854 | * <alt>tab which will make `current' point to the second element. */ |
| 3855 | alt_tab_next(alt_tab); |
| 3856 | } |
| 3857 | |
| 3858 | static void |
Giulio Camuffo | 1959ab8 | 2013-11-14 23:42:52 +0100 | [diff] [blame] | 3859 | rotate_grab_motion(struct weston_pointer_grab *grab, uint32_t time, |
| 3860 | wl_fixed_t x, wl_fixed_t y) |
Pekka Paalanen | 460099f | 2012-01-20 16:48:25 +0200 | [diff] [blame] | 3861 | { |
| 3862 | struct rotate_grab *rotate = |
Ander Conselvan de Oliveira | fe0444a | 2012-04-04 17:48:05 +0300 | [diff] [blame] | 3863 | container_of(grab, struct rotate_grab, base.grab); |
Kristian Høgsberg | 02bbabb | 2013-05-06 22:15:05 -0400 | [diff] [blame] | 3864 | struct weston_pointer *pointer = grab->pointer; |
Ander Conselvan de Oliveira | fe0444a | 2012-04-04 17:48:05 +0300 | [diff] [blame] | 3865 | struct shell_surface *shsurf = rotate->base.shsurf; |
John Kåre Alsaker | 490d02a | 2012-09-30 02:57:21 +0200 | [diff] [blame] | 3866 | float cx, cy, dx, dy, cposx, cposy, dposx, dposy, r; |
Ander Conselvan de Oliveira | fe0444a | 2012-04-04 17:48:05 +0300 | [diff] [blame] | 3867 | |
Giulio Camuffo | 1959ab8 | 2013-11-14 23:42:52 +0100 | [diff] [blame] | 3868 | weston_pointer_move(pointer, x, y); |
| 3869 | |
Ander Conselvan de Oliveira | fe0444a | 2012-04-04 17:48:05 +0300 | [diff] [blame] | 3870 | if (!shsurf) |
| 3871 | return; |
| 3872 | |
Jason Ekstrand | 918f2dd | 2013-12-02 21:01:53 -0600 | [diff] [blame] | 3873 | cx = 0.5f * shsurf->surface->width; |
| 3874 | cy = 0.5f * shsurf->surface->height; |
Pekka Paalanen | 460099f | 2012-01-20 16:48:25 +0200 | [diff] [blame] | 3875 | |
Daniel Stone | 37816df | 2012-05-16 18:45:18 +0100 | [diff] [blame] | 3876 | dx = wl_fixed_to_double(pointer->x) - rotate->center.x; |
| 3877 | dy = wl_fixed_to_double(pointer->y) - rotate->center.y; |
Pekka Paalanen | 460099f | 2012-01-20 16:48:25 +0200 | [diff] [blame] | 3878 | r = sqrtf(dx * dx + dy * dy); |
| 3879 | |
Ander Conselvan de Oliveira | fe0444a | 2012-04-04 17:48:05 +0300 | [diff] [blame] | 3880 | wl_list_remove(&shsurf->rotation.transform.link); |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 3881 | weston_view_geometry_dirty(shsurf->view); |
Pekka Paalanen | 460099f | 2012-01-20 16:48:25 +0200 | [diff] [blame] | 3882 | |
| 3883 | if (r > 20.0f) { |
Pekka Paalanen | 460099f | 2012-01-20 16:48:25 +0200 | [diff] [blame] | 3884 | struct weston_matrix *matrix = |
Ander Conselvan de Oliveira | fe0444a | 2012-04-04 17:48:05 +0300 | [diff] [blame] | 3885 | &shsurf->rotation.transform.matrix; |
Pekka Paalanen | 460099f | 2012-01-20 16:48:25 +0200 | [diff] [blame] | 3886 | |
Kristian Høgsberg | 765e27b | 2012-01-27 13:36:13 -0500 | [diff] [blame] | 3887 | weston_matrix_init(&rotate->rotation); |
Vasily Khoruzhick | 1bbf372 | 2013-01-28 22:40:28 +0300 | [diff] [blame] | 3888 | weston_matrix_rotate_xy(&rotate->rotation, dx / r, dy / r); |
Pekka Paalanen | 460099f | 2012-01-20 16:48:25 +0200 | [diff] [blame] | 3889 | |
| 3890 | weston_matrix_init(matrix); |
Pekka Paalanen | 7b3bd3d | 2012-01-30 14:16:34 +0200 | [diff] [blame] | 3891 | weston_matrix_translate(matrix, -cx, -cy, 0.0f); |
Ander Conselvan de Oliveira | fe0444a | 2012-04-04 17:48:05 +0300 | [diff] [blame] | 3892 | weston_matrix_multiply(matrix, &shsurf->rotation.rotation); |
Kristian Høgsberg | 765e27b | 2012-01-27 13:36:13 -0500 | [diff] [blame] | 3893 | weston_matrix_multiply(matrix, &rotate->rotation); |
Pekka Paalanen | 7b3bd3d | 2012-01-30 14:16:34 +0200 | [diff] [blame] | 3894 | weston_matrix_translate(matrix, cx, cy, 0.0f); |
Pekka Paalanen | 460099f | 2012-01-20 16:48:25 +0200 | [diff] [blame] | 3895 | |
Pekka Paalanen | bc0b7e7 | 2012-01-24 09:53:37 +0200 | [diff] [blame] | 3896 | wl_list_insert( |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 3897 | &shsurf->view->geometry.transformation_list, |
Ander Conselvan de Oliveira | fe0444a | 2012-04-04 17:48:05 +0300 | [diff] [blame] | 3898 | &shsurf->rotation.transform.link); |
Pekka Paalanen | 460099f | 2012-01-20 16:48:25 +0200 | [diff] [blame] | 3899 | } else { |
Ander Conselvan de Oliveira | fe0444a | 2012-04-04 17:48:05 +0300 | [diff] [blame] | 3900 | wl_list_init(&shsurf->rotation.transform.link); |
| 3901 | weston_matrix_init(&shsurf->rotation.rotation); |
Kristian Høgsberg | 765e27b | 2012-01-27 13:36:13 -0500 | [diff] [blame] | 3902 | weston_matrix_init(&rotate->rotation); |
Pekka Paalanen | 460099f | 2012-01-20 16:48:25 +0200 | [diff] [blame] | 3903 | } |
Pekka Paalanen | b45ac5e | 2012-02-09 15:58:44 +0200 | [diff] [blame] | 3904 | |
Rafal Mielniczuk | 2d7ab82 | 2012-03-22 22:22:04 +0100 | [diff] [blame] | 3905 | /* We need to adjust the position of the surface |
| 3906 | * in case it was resized in a rotated state before */ |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 3907 | cposx = shsurf->view->geometry.x + cx; |
| 3908 | cposy = shsurf->view->geometry.y + cy; |
Rafal Mielniczuk | 2d7ab82 | 2012-03-22 22:22:04 +0100 | [diff] [blame] | 3909 | dposx = rotate->center.x - cposx; |
| 3910 | dposy = rotate->center.y - cposy; |
| 3911 | if (dposx != 0.0f || dposy != 0.0f) { |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 3912 | weston_view_set_position(shsurf->view, |
| 3913 | shsurf->view->geometry.x + dposx, |
| 3914 | shsurf->view->geometry.y + dposy); |
Rafal Mielniczuk | 2d7ab82 | 2012-03-22 22:22:04 +0100 | [diff] [blame] | 3915 | } |
| 3916 | |
Pekka Paalanen | b45ac5e | 2012-02-09 15:58:44 +0200 | [diff] [blame] | 3917 | /* Repaint implies weston_surface_update_transform(), which |
| 3918 | * lazily applies the damage due to rotation update. |
| 3919 | */ |
Ander Conselvan de Oliveira | fe0444a | 2012-04-04 17:48:05 +0300 | [diff] [blame] | 3920 | weston_compositor_schedule_repaint(shsurf->surface->compositor); |
Pekka Paalanen | 460099f | 2012-01-20 16:48:25 +0200 | [diff] [blame] | 3921 | } |
| 3922 | |
| 3923 | static void |
Kristian Høgsberg | 02bbabb | 2013-05-06 22:15:05 -0400 | [diff] [blame] | 3924 | rotate_grab_button(struct weston_pointer_grab *grab, |
| 3925 | uint32_t time, uint32_t button, uint32_t state_w) |
Pekka Paalanen | 460099f | 2012-01-20 16:48:25 +0200 | [diff] [blame] | 3926 | { |
| 3927 | struct rotate_grab *rotate = |
Ander Conselvan de Oliveira | fe0444a | 2012-04-04 17:48:05 +0300 | [diff] [blame] | 3928 | container_of(grab, struct rotate_grab, base.grab); |
Kristian Høgsberg | 02bbabb | 2013-05-06 22:15:05 -0400 | [diff] [blame] | 3929 | struct weston_pointer *pointer = grab->pointer; |
Ander Conselvan de Oliveira | fe0444a | 2012-04-04 17:48:05 +0300 | [diff] [blame] | 3930 | struct shell_surface *shsurf = rotate->base.shsurf; |
Daniel Stone | 4dbadb1 | 2012-05-30 16:31:51 +0100 | [diff] [blame] | 3931 | enum wl_pointer_button_state state = state_w; |
Pekka Paalanen | 460099f | 2012-01-20 16:48:25 +0200 | [diff] [blame] | 3932 | |
Daniel Stone | 4dbadb1 | 2012-05-30 16:31:51 +0100 | [diff] [blame] | 3933 | if (pointer->button_count == 0 && |
| 3934 | state == WL_POINTER_BUTTON_STATE_RELEASED) { |
Ander Conselvan de Oliveira | fe0444a | 2012-04-04 17:48:05 +0300 | [diff] [blame] | 3935 | if (shsurf) |
| 3936 | weston_matrix_multiply(&shsurf->rotation.rotation, |
| 3937 | &rotate->rotation); |
Ander Conselvan de Oliveira | b9d2a0f | 2012-06-28 18:08:05 +0300 | [diff] [blame] | 3938 | shell_grab_end(&rotate->base); |
Pekka Paalanen | 460099f | 2012-01-20 16:48:25 +0200 | [diff] [blame] | 3939 | free(rotate); |
| 3940 | } |
| 3941 | } |
| 3942 | |
Jonas Ådahl | 1ea343e | 2013-10-25 23:18:05 +0200 | [diff] [blame] | 3943 | static void |
| 3944 | rotate_grab_cancel(struct weston_pointer_grab *grab) |
| 3945 | { |
| 3946 | struct rotate_grab *rotate = |
| 3947 | container_of(grab, struct rotate_grab, base.grab); |
| 3948 | |
| 3949 | shell_grab_end(&rotate->base); |
| 3950 | free(rotate); |
| 3951 | } |
| 3952 | |
Kristian Høgsberg | 02bbabb | 2013-05-06 22:15:05 -0400 | [diff] [blame] | 3953 | static const struct weston_pointer_grab_interface rotate_grab_interface = { |
Pekka Paalanen | 460099f | 2012-01-20 16:48:25 +0200 | [diff] [blame] | 3954 | noop_grab_focus, |
| 3955 | rotate_grab_motion, |
| 3956 | rotate_grab_button, |
Jonas Ådahl | 1ea343e | 2013-10-25 23:18:05 +0200 | [diff] [blame] | 3957 | rotate_grab_cancel, |
Pekka Paalanen | 460099f | 2012-01-20 16:48:25 +0200 | [diff] [blame] | 3958 | }; |
| 3959 | |
| 3960 | static void |
Kristian Høgsberg | e314875 | 2013-05-06 23:19:49 -0400 | [diff] [blame] | 3961 | surface_rotate(struct shell_surface *surface, struct weston_seat *seat) |
Pekka Paalanen | 460099f | 2012-01-20 16:48:25 +0200 | [diff] [blame] | 3962 | { |
Pekka Paalanen | 460099f | 2012-01-20 16:48:25 +0200 | [diff] [blame] | 3963 | struct rotate_grab *rotate; |
John Kåre Alsaker | 490d02a | 2012-09-30 02:57:21 +0200 | [diff] [blame] | 3964 | float dx, dy; |
| 3965 | float r; |
Pekka Paalanen | 460099f | 2012-01-20 16:48:25 +0200 | [diff] [blame] | 3966 | |
Pekka Paalanen | 460099f | 2012-01-20 16:48:25 +0200 | [diff] [blame] | 3967 | rotate = malloc(sizeof *rotate); |
| 3968 | if (!rotate) |
| 3969 | return; |
| 3970 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 3971 | weston_view_to_global_float(surface->view, |
Jason Ekstrand | 918f2dd | 2013-12-02 21:01:53 -0600 | [diff] [blame] | 3972 | surface->surface->width * 0.5f, |
| 3973 | surface->surface->height * 0.5f, |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 3974 | &rotate->center.x, &rotate->center.y); |
Pekka Paalanen | 460099f | 2012-01-20 16:48:25 +0200 | [diff] [blame] | 3975 | |
Daniel Stone | 37816df | 2012-05-16 18:45:18 +0100 | [diff] [blame] | 3976 | dx = wl_fixed_to_double(seat->pointer->x) - rotate->center.x; |
| 3977 | dy = wl_fixed_to_double(seat->pointer->y) - rotate->center.y; |
Kristian Høgsberg | 765e27b | 2012-01-27 13:36:13 -0500 | [diff] [blame] | 3978 | r = sqrtf(dx * dx + dy * dy); |
| 3979 | if (r > 20.0f) { |
| 3980 | struct weston_matrix inverse; |
| 3981 | |
| 3982 | weston_matrix_init(&inverse); |
Vasily Khoruzhick | 1bbf372 | 2013-01-28 22:40:28 +0300 | [diff] [blame] | 3983 | weston_matrix_rotate_xy(&inverse, dx / r, -dy / r); |
Kristian Høgsberg | 765e27b | 2012-01-27 13:36:13 -0500 | [diff] [blame] | 3984 | weston_matrix_multiply(&surface->rotation.rotation, &inverse); |
Rafal Mielniczuk | 2d7ab82 | 2012-03-22 22:22:04 +0100 | [diff] [blame] | 3985 | |
| 3986 | weston_matrix_init(&rotate->rotation); |
Vasily Khoruzhick | 1bbf372 | 2013-01-28 22:40:28 +0300 | [diff] [blame] | 3987 | weston_matrix_rotate_xy(&rotate->rotation, dx / r, dy / r); |
Kristian Høgsberg | 765e27b | 2012-01-27 13:36:13 -0500 | [diff] [blame] | 3988 | } else { |
| 3989 | weston_matrix_init(&surface->rotation.rotation); |
| 3990 | weston_matrix_init(&rotate->rotation); |
| 3991 | } |
| 3992 | |
Ander Conselvan de Oliveira | b9d2a0f | 2012-06-28 18:08:05 +0300 | [diff] [blame] | 3993 | shell_grab_start(&rotate->base, &rotate_grab_interface, surface, |
| 3994 | seat->pointer, DESKTOP_SHELL_CURSOR_ARROW); |
Pekka Paalanen | 460099f | 2012-01-20 16:48:25 +0200 | [diff] [blame] | 3995 | } |
| 3996 | |
| 3997 | static void |
Kristian Høgsberg | e314875 | 2013-05-06 23:19:49 -0400 | [diff] [blame] | 3998 | 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] | 3999 | void *data) |
| 4000 | { |
Kristian Høgsberg | 7ab139c | 2013-10-24 16:21:39 -0700 | [diff] [blame] | 4001 | struct weston_surface *focus = seat->pointer->focus->surface; |
Pekka Paalanen | 01388e2 | 2013-04-25 13:57:44 +0300 | [diff] [blame] | 4002 | struct weston_surface *base_surface; |
Kristian Høgsberg | 0c36903 | 2013-02-14 21:31:44 -0500 | [diff] [blame] | 4003 | struct shell_surface *surface; |
| 4004 | |
Pekka Paalanen | 01388e2 | 2013-04-25 13:57:44 +0300 | [diff] [blame] | 4005 | base_surface = weston_surface_get_main_surface(focus); |
Kristian Høgsberg | 0c36903 | 2013-02-14 21:31:44 -0500 | [diff] [blame] | 4006 | if (base_surface == NULL) |
| 4007 | return; |
| 4008 | |
| 4009 | surface = get_shell_surface(base_surface); |
Rafael Antognolli | 03b1659 | 2013-12-03 15:35:42 -0200 | [diff] [blame] | 4010 | if (surface == NULL || surface->state.fullscreen || |
| 4011 | surface->state.maximized) |
Kristian Høgsberg | 0c36903 | 2013-02-14 21:31:44 -0500 | [diff] [blame] | 4012 | return; |
| 4013 | |
| 4014 | surface_rotate(surface, seat); |
| 4015 | } |
| 4016 | |
Philip Withnall | 83ffd9d | 2013-11-25 18:01:42 +0000 | [diff] [blame] | 4017 | /* Move all fullscreen layers down to the current workspace in a non-reversible |
| 4018 | * manner. This should be used when implementing shell-wide overlays, such as |
| 4019 | * the alt-tab switcher, which need to de-promote fullscreen layers. */ |
Kristian Høgsberg | 0c36903 | 2013-02-14 21:31:44 -0500 | [diff] [blame] | 4020 | static void |
Kristian Høgsberg | b0d8e77 | 2012-06-18 16:34:58 -0400 | [diff] [blame] | 4021 | lower_fullscreen_layer(struct desktop_shell *shell) |
| 4022 | { |
| 4023 | struct workspace *ws; |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 4024 | struct weston_view *view, *prev; |
Kristian Høgsberg | b0d8e77 | 2012-06-18 16:34:58 -0400 | [diff] [blame] | 4025 | |
| 4026 | ws = get_current_workspace(shell); |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 4027 | wl_list_for_each_reverse_safe(view, prev, |
| 4028 | &shell->fullscreen_layer.view_list, |
Philip Withnall | 83ffd9d | 2013-11-25 18:01:42 +0000 | [diff] [blame] | 4029 | layer_link) { |
| 4030 | wl_list_remove(&view->layer_link); |
| 4031 | wl_list_insert(&ws->layer.view_list, &view->layer_link); |
| 4032 | weston_view_damage_below(view); |
| 4033 | weston_surface_damage(view->surface); |
| 4034 | } |
Kristian Høgsberg | b0d8e77 | 2012-06-18 16:34:58 -0400 | [diff] [blame] | 4035 | } |
| 4036 | |
| 4037 | static void |
Tiago Vignatti | be14326 | 2012-04-16 17:31:41 +0300 | [diff] [blame] | 4038 | activate(struct desktop_shell *shell, struct weston_surface *es, |
Daniel Stone | 37816df | 2012-05-16 18:45:18 +0100 | [diff] [blame] | 4039 | struct weston_seat *seat) |
Kristian Høgsberg | 7584062 | 2011-09-06 13:48:16 -0400 | [diff] [blame] | 4040 | { |
Pekka Paalanen | 01388e2 | 2013-04-25 13:57:44 +0300 | [diff] [blame] | 4041 | struct weston_surface *main_surface; |
Kristian Høgsberg | 2f5faff | 2012-07-31 16:36:34 -0400 | [diff] [blame] | 4042 | struct focus_state *state; |
Jonas Ådahl | 8538b22 | 2012-08-29 22:13:03 +0200 | [diff] [blame] | 4043 | struct workspace *ws; |
Louis-Francis Ratté-Boulianne | b482dbd | 2013-11-19 11:37:11 +0100 | [diff] [blame] | 4044 | struct weston_surface *old_es; |
Rafael Antognolli | 03b1659 | 2013-12-03 15:35:42 -0200 | [diff] [blame] | 4045 | struct shell_surface *shsurf; |
Kristian Høgsberg | 7584062 | 2011-09-06 13:48:16 -0400 | [diff] [blame] | 4046 | |
Pekka Paalanen | 01388e2 | 2013-04-25 13:57:44 +0300 | [diff] [blame] | 4047 | main_surface = weston_surface_get_main_surface(es); |
| 4048 | |
Daniel Stone | 37816df | 2012-05-16 18:45:18 +0100 | [diff] [blame] | 4049 | weston_surface_activate(es, seat); |
Kristian Høgsberg | 7584062 | 2011-09-06 13:48:16 -0400 | [diff] [blame] | 4050 | |
Jonas Ådahl | 8538b22 | 2012-08-29 22:13:03 +0200 | [diff] [blame] | 4051 | state = ensure_focus_state(shell, seat); |
| 4052 | if (state == NULL) |
| 4053 | return; |
Kristian Høgsberg | 2f5faff | 2012-07-31 16:36:34 -0400 | [diff] [blame] | 4054 | |
Louis-Francis Ratté-Boulianne | b482dbd | 2013-11-19 11:37:11 +0100 | [diff] [blame] | 4055 | old_es = state->keyboard_focus; |
Kristian Høgsberg | 2f5faff | 2012-07-31 16:36:34 -0400 | [diff] [blame] | 4056 | state->keyboard_focus = es; |
| 4057 | wl_list_remove(&state->surface_destroy_listener.link); |
Jason Ekstrand | 26ed73c | 2013-06-06 22:34:41 -0500 | [diff] [blame] | 4058 | wl_signal_add(&es->destroy_signal, &state->surface_destroy_listener); |
Kristian Høgsberg | 2f5faff | 2012-07-31 16:36:34 -0400 | [diff] [blame] | 4059 | |
Rafael Antognolli | 03b1659 | 2013-12-03 15:35:42 -0200 | [diff] [blame] | 4060 | shsurf = get_shell_surface(main_surface); |
| 4061 | if (shsurf->state.fullscreen) |
| 4062 | shell_configure_fullscreen(shsurf); |
| 4063 | else |
Alexander Larsson | f82b6ca | 2013-05-28 16:23:39 +0200 | [diff] [blame] | 4064 | restore_all_output_modes(shell->compositor); |
Louis-Francis Ratté-Boulianne | b482dbd | 2013-11-19 11:37:11 +0100 | [diff] [blame] | 4065 | |
Philip Withnall | 83ffd9d | 2013-11-25 18:01:42 +0000 | [diff] [blame] | 4066 | if (shell->focus_animation_type != ANIMATION_NONE) { |
| 4067 | ws = get_current_workspace(shell); |
Louis-Francis Ratté-Boulianne | b482dbd | 2013-11-19 11:37:11 +0100 | [diff] [blame] | 4068 | 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] | 4069 | } |
| 4070 | |
| 4071 | /* Update the surface’s layer. This brings it to the top of the stacking |
| 4072 | * order as appropriate. */ |
| 4073 | shell_surface_update_layer(get_shell_surface(main_surface)); |
Kristian Høgsberg | 7584062 | 2011-09-06 13:48:16 -0400 | [diff] [blame] | 4074 | } |
| 4075 | |
Alex Wu | 2185843 | 2012-04-01 20:13:08 +0800 | [diff] [blame] | 4076 | /* no-op func for checking black surface */ |
| 4077 | static void |
Jason Ekstrand | 918f2dd | 2013-12-02 21:01:53 -0600 | [diff] [blame] | 4078 | 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] | 4079 | { |
| 4080 | } |
| 4081 | |
Quentin Glidic | c0d79ce | 2013-01-29 14:16:13 +0100 | [diff] [blame] | 4082 | static bool |
Alex Wu | 2185843 | 2012-04-01 20:13:08 +0800 | [diff] [blame] | 4083 | is_black_surface (struct weston_surface *es, struct weston_surface **fs_surface) |
| 4084 | { |
| 4085 | if (es->configure == black_surface_configure) { |
| 4086 | if (fs_surface) |
Giulio Camuffo | 7fe01b1 | 2013-03-28 18:02:42 +0100 | [diff] [blame] | 4087 | *fs_surface = (struct weston_surface *)es->configure_private; |
Alex Wu | 2185843 | 2012-04-01 20:13:08 +0800 | [diff] [blame] | 4088 | return true; |
| 4089 | } |
| 4090 | return false; |
| 4091 | } |
| 4092 | |
Kristian Høgsberg | 7584062 | 2011-09-06 13:48:16 -0400 | [diff] [blame] | 4093 | static void |
Neil Roberts | a28c693 | 2013-10-03 16:43:04 +0100 | [diff] [blame] | 4094 | activate_binding(struct weston_seat *seat, |
| 4095 | struct desktop_shell *shell, |
| 4096 | struct weston_surface *focus) |
Kristian Høgsberg | e1a850e | 2011-12-19 15:18:05 -0500 | [diff] [blame] | 4097 | { |
Pekka Paalanen | 01388e2 | 2013-04-25 13:57:44 +0300 | [diff] [blame] | 4098 | struct weston_surface *main_surface; |
Kristian Høgsberg | e1a850e | 2011-12-19 15:18:05 -0500 | [diff] [blame] | 4099 | |
Alex Wu | 9c35e6b | 2012-03-05 14:13:13 +0800 | [diff] [blame] | 4100 | if (!focus) |
| 4101 | return; |
| 4102 | |
Pekka Paalanen | 01388e2 | 2013-04-25 13:57:44 +0300 | [diff] [blame] | 4103 | if (is_black_surface(focus, &main_surface)) |
| 4104 | focus = main_surface; |
Alex Wu | 4539b08 | 2012-03-01 12:57:46 +0800 | [diff] [blame] | 4105 | |
Pekka Paalanen | 01388e2 | 2013-04-25 13:57:44 +0300 | [diff] [blame] | 4106 | main_surface = weston_surface_get_main_surface(focus); |
| 4107 | if (get_shell_surface_type(main_surface) == SHELL_SURFACE_NONE) |
Kristian Høgsberg | 0636ac3 | 2012-06-27 10:22:15 -0400 | [diff] [blame] | 4108 | return; |
Kristian Høgsberg | 85b2e4b | 2012-06-21 16:49:42 -0400 | [diff] [blame] | 4109 | |
Neil Roberts | a28c693 | 2013-10-03 16:43:04 +0100 | [diff] [blame] | 4110 | activate(shell, focus, seat); |
| 4111 | } |
| 4112 | |
| 4113 | static void |
| 4114 | click_to_activate_binding(struct weston_seat *seat, uint32_t time, uint32_t button, |
| 4115 | void *data) |
| 4116 | { |
| 4117 | if (seat->pointer->grab != &seat->pointer->default_grab) |
| 4118 | return; |
| 4119 | |
Kristian Høgsberg | 7ab139c | 2013-10-24 16:21:39 -0700 | [diff] [blame] | 4120 | activate_binding(seat, data, seat->pointer->focus->surface); |
Neil Roberts | a28c693 | 2013-10-03 16:43:04 +0100 | [diff] [blame] | 4121 | } |
| 4122 | |
| 4123 | static void |
| 4124 | touch_to_activate_binding(struct weston_seat *seat, uint32_t time, void *data) |
| 4125 | { |
| 4126 | if (seat->touch->grab != &seat->touch->default_grab) |
| 4127 | return; |
| 4128 | |
Kristian Høgsberg | 7ab139c | 2013-10-24 16:21:39 -0700 | [diff] [blame] | 4129 | activate_binding(seat, data, seat->touch->focus->surface); |
Kristian Høgsberg | e1a850e | 2011-12-19 15:18:05 -0500 | [diff] [blame] | 4130 | } |
| 4131 | |
| 4132 | static void |
Ander Conselvan de Oliveira | 19d10ef | 2013-02-21 18:35:20 +0200 | [diff] [blame] | 4133 | lock(struct desktop_shell *shell) |
Kristian Høgsberg | 02ec0a5 | 2011-04-23 13:04:11 -0400 | [diff] [blame] | 4134 | { |
Kristian Høgsberg | 4476aaf | 2012-06-25 14:03:13 -0400 | [diff] [blame] | 4135 | struct workspace *ws = get_current_workspace(shell); |
Pekka Paalanen | f0fc70d | 2011-11-15 13:34:54 +0200 | [diff] [blame] | 4136 | |
Tiago Vignatti | 8e53c7f | 2012-02-29 19:53:50 +0200 | [diff] [blame] | 4137 | if (shell->locked) { |
Ander Conselvan de Oliveira | 87524b6 | 2013-02-21 18:35:22 +0200 | [diff] [blame] | 4138 | weston_compositor_sleep(shell->compositor); |
Pekka Paalanen | f0fc70d | 2011-11-15 13:34:54 +0200 | [diff] [blame] | 4139 | return; |
Tiago Vignatti | 8e53c7f | 2012-02-29 19:53:50 +0200 | [diff] [blame] | 4140 | } |
Pekka Paalanen | 9ef3e01 | 2011-11-15 13:34:48 +0200 | [diff] [blame] | 4141 | |
| 4142 | shell->locked = true; |
Pekka Paalanen | f0fc70d | 2011-11-15 13:34:54 +0200 | [diff] [blame] | 4143 | |
Kristian Høgsberg | 3be2ce9 | 2012-02-29 12:42:35 -0500 | [diff] [blame] | 4144 | /* Hide all surfaces by removing the fullscreen, panel and |
| 4145 | * toplevel layers. This way nothing else can show or receive |
| 4146 | * input events while we are locked. */ |
Pekka Paalanen | f0fc70d | 2011-11-15 13:34:54 +0200 | [diff] [blame] | 4147 | |
Kristian Høgsberg | 3be2ce9 | 2012-02-29 12:42:35 -0500 | [diff] [blame] | 4148 | wl_list_remove(&shell->panel_layer.link); |
Kristian Høgsberg | 3be2ce9 | 2012-02-29 12:42:35 -0500 | [diff] [blame] | 4149 | wl_list_remove(&shell->fullscreen_layer.link); |
Philipp Brüschweiler | 711fda8 | 2012-08-09 18:50:43 +0200 | [diff] [blame] | 4150 | if (shell->showing_input_panels) |
| 4151 | wl_list_remove(&shell->input_panel_layer.link); |
Kristian Høgsberg | 4476aaf | 2012-06-25 14:03:13 -0400 | [diff] [blame] | 4152 | wl_list_remove(&ws->layer.link); |
Kristian Høgsberg | 3be2ce9 | 2012-02-29 12:42:35 -0500 | [diff] [blame] | 4153 | wl_list_insert(&shell->compositor->cursor_layer.link, |
| 4154 | &shell->lock_layer.link); |
Pekka Paalanen | f0fc70d | 2011-11-15 13:34:54 +0200 | [diff] [blame] | 4155 | |
Pekka Paalanen | 77346a6 | 2011-11-30 16:26:35 +0200 | [diff] [blame] | 4156 | launch_screensaver(shell); |
| 4157 | |
Pekka Paalanen | f0fc70d | 2011-11-15 13:34:54 +0200 | [diff] [blame] | 4158 | /* TODO: disable bindings that should not work while locked. */ |
| 4159 | |
| 4160 | /* All this must be undone in resume_desktop(). */ |
Pekka Paalanen | 9ef3e01 | 2011-11-15 13:34:48 +0200 | [diff] [blame] | 4161 | } |
| 4162 | |
| 4163 | static void |
Ander Conselvan de Oliveira | 19d10ef | 2013-02-21 18:35:20 +0200 | [diff] [blame] | 4164 | unlock(struct desktop_shell *shell) |
Pekka Paalanen | 9ef3e01 | 2011-11-15 13:34:48 +0200 | [diff] [blame] | 4165 | { |
Pekka Paalanen | d81c216 | 2011-11-16 13:47:34 +0200 | [diff] [blame] | 4166 | if (!shell->locked || shell->lock_surface) { |
Ander Conselvan de Oliveira | 87524b6 | 2013-02-21 18:35:22 +0200 | [diff] [blame] | 4167 | shell_fade(shell, FADE_IN); |
Pekka Paalanen | 9ef3e01 | 2011-11-15 13:34:48 +0200 | [diff] [blame] | 4168 | return; |
| 4169 | } |
| 4170 | |
| 4171 | /* If desktop-shell client has gone away, unlock immediately. */ |
| 4172 | if (!shell->child.desktop_shell) { |
Pekka Paalanen | f0fc70d | 2011-11-15 13:34:54 +0200 | [diff] [blame] | 4173 | resume_desktop(shell); |
Pekka Paalanen | 9ef3e01 | 2011-11-15 13:34:48 +0200 | [diff] [blame] | 4174 | return; |
| 4175 | } |
| 4176 | |
| 4177 | if (shell->prepare_event_sent) |
| 4178 | return; |
| 4179 | |
Kristian Høgsberg | 0b5cd0c | 2012-03-04 21:57:37 -0500 | [diff] [blame] | 4180 | desktop_shell_send_prepare_lock_surface(shell->child.desktop_shell); |
Pekka Paalanen | 9ef3e01 | 2011-11-15 13:34:48 +0200 | [diff] [blame] | 4181 | shell->prepare_event_sent = true; |
Kristian Høgsberg | 02ec0a5 | 2011-04-23 13:04:11 -0400 | [diff] [blame] | 4182 | } |
| 4183 | |
| 4184 | static void |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 4185 | shell_fade_done(struct weston_view_animation *animation, void *data) |
Ander Conselvan de Oliveira | 19d10ef | 2013-02-21 18:35:20 +0200 | [diff] [blame] | 4186 | { |
| 4187 | struct desktop_shell *shell = data; |
| 4188 | |
| 4189 | shell->fade.animation = NULL; |
| 4190 | |
| 4191 | switch (shell->fade.type) { |
| 4192 | case FADE_IN: |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 4193 | weston_surface_destroy(shell->fade.view->surface); |
| 4194 | shell->fade.view = NULL; |
Ander Conselvan de Oliveira | 19d10ef | 2013-02-21 18:35:20 +0200 | [diff] [blame] | 4195 | break; |
| 4196 | case FADE_OUT: |
Ander Conselvan de Oliveira | 19d10ef | 2013-02-21 18:35:20 +0200 | [diff] [blame] | 4197 | lock(shell); |
| 4198 | break; |
Philip Withnall | 4a86a0a | 2013-11-25 18:01:32 +0000 | [diff] [blame] | 4199 | default: |
| 4200 | break; |
Ander Conselvan de Oliveira | 19d10ef | 2013-02-21 18:35:20 +0200 | [diff] [blame] | 4201 | } |
| 4202 | } |
| 4203 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 4204 | static struct weston_view * |
Pekka Paalanen | 79346ab | 2013-05-22 18:03:09 +0300 | [diff] [blame] | 4205 | shell_fade_create_surface(struct desktop_shell *shell) |
Ander Conselvan de Oliveira | 19d10ef | 2013-02-21 18:35:20 +0200 | [diff] [blame] | 4206 | { |
| 4207 | struct weston_compositor *compositor = shell->compositor; |
| 4208 | struct weston_surface *surface; |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 4209 | struct weston_view *view; |
Pekka Paalanen | 79346ab | 2013-05-22 18:03:09 +0300 | [diff] [blame] | 4210 | |
| 4211 | surface = weston_surface_create(compositor); |
| 4212 | if (!surface) |
| 4213 | return NULL; |
| 4214 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 4215 | view = weston_view_create(surface); |
| 4216 | if (!view) { |
| 4217 | weston_surface_destroy(surface); |
| 4218 | return NULL; |
| 4219 | } |
| 4220 | |
Jason Ekstrand | 918f2dd | 2013-12-02 21:01:53 -0600 | [diff] [blame] | 4221 | surface->width = 8192; |
| 4222 | surface->height = 8192; |
| 4223 | weston_view_set_position(view, 0, 0); |
Pekka Paalanen | 79346ab | 2013-05-22 18:03:09 +0300 | [diff] [blame] | 4224 | 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] | 4225 | wl_list_insert(&compositor->fade_layer.view_list, |
| 4226 | &view->layer_link); |
Pekka Paalanen | 79346ab | 2013-05-22 18:03:09 +0300 | [diff] [blame] | 4227 | pixman_region32_init(&surface->input); |
| 4228 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 4229 | return view; |
Pekka Paalanen | 79346ab | 2013-05-22 18:03:09 +0300 | [diff] [blame] | 4230 | } |
| 4231 | |
| 4232 | static void |
| 4233 | shell_fade(struct desktop_shell *shell, enum fade_type type) |
| 4234 | { |
Ander Conselvan de Oliveira | 19d10ef | 2013-02-21 18:35:20 +0200 | [diff] [blame] | 4235 | float tint; |
| 4236 | |
| 4237 | switch (type) { |
| 4238 | case FADE_IN: |
| 4239 | tint = 0.0; |
| 4240 | break; |
| 4241 | case FADE_OUT: |
| 4242 | tint = 1.0; |
| 4243 | break; |
| 4244 | default: |
| 4245 | weston_log("shell: invalid fade type\n"); |
| 4246 | return; |
| 4247 | } |
| 4248 | |
| 4249 | shell->fade.type = type; |
| 4250 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 4251 | if (shell->fade.view == NULL) { |
| 4252 | shell->fade.view = shell_fade_create_surface(shell); |
| 4253 | if (!shell->fade.view) |
Ander Conselvan de Oliveira | 19d10ef | 2013-02-21 18:35:20 +0200 | [diff] [blame] | 4254 | return; |
| 4255 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 4256 | shell->fade.view->alpha = 1.0 - tint; |
| 4257 | weston_view_update_transform(shell->fade.view); |
Ander Conselvan de Oliveira | 19d10ef | 2013-02-21 18:35:20 +0200 | [diff] [blame] | 4258 | } |
| 4259 | |
| 4260 | if (shell->fade.animation) |
Kristian Høgsberg | 5281fb1 | 2013-06-17 10:10:28 -0400 | [diff] [blame] | 4261 | weston_fade_update(shell->fade.animation, tint); |
Ander Conselvan de Oliveira | 19d10ef | 2013-02-21 18:35:20 +0200 | [diff] [blame] | 4262 | else |
| 4263 | shell->fade.animation = |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 4264 | weston_fade_run(shell->fade.view, |
Kristian Høgsberg | 5281fb1 | 2013-06-17 10:10:28 -0400 | [diff] [blame] | 4265 | 1.0 - tint, tint, 300.0, |
Ander Conselvan de Oliveira | 19d10ef | 2013-02-21 18:35:20 +0200 | [diff] [blame] | 4266 | shell_fade_done, shell); |
| 4267 | } |
| 4268 | |
| 4269 | static void |
Pekka Paalanen | 79346ab | 2013-05-22 18:03:09 +0300 | [diff] [blame] | 4270 | do_shell_fade_startup(void *data) |
| 4271 | { |
| 4272 | struct desktop_shell *shell = data; |
| 4273 | |
Kristian Høgsberg | 724c8d9 | 2013-10-16 11:38:24 -0700 | [diff] [blame] | 4274 | if (shell->startup_animation_type == ANIMATION_FADE) |
| 4275 | shell_fade(shell, FADE_IN); |
| 4276 | else if (shell->startup_animation_type == ANIMATION_NONE) { |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 4277 | weston_surface_destroy(shell->fade.view->surface); |
| 4278 | shell->fade.view = NULL; |
Kristian Høgsberg | 724c8d9 | 2013-10-16 11:38:24 -0700 | [diff] [blame] | 4279 | } |
Pekka Paalanen | 79346ab | 2013-05-22 18:03:09 +0300 | [diff] [blame] | 4280 | } |
| 4281 | |
| 4282 | static void |
| 4283 | shell_fade_startup(struct desktop_shell *shell) |
| 4284 | { |
| 4285 | struct wl_event_loop *loop; |
| 4286 | |
| 4287 | if (!shell->fade.startup_timer) |
| 4288 | return; |
| 4289 | |
| 4290 | wl_event_source_remove(shell->fade.startup_timer); |
| 4291 | shell->fade.startup_timer = NULL; |
| 4292 | |
| 4293 | loop = wl_display_get_event_loop(shell->compositor->wl_display); |
| 4294 | wl_event_loop_add_idle(loop, do_shell_fade_startup, shell); |
| 4295 | } |
| 4296 | |
| 4297 | static int |
| 4298 | fade_startup_timeout(void *data) |
| 4299 | { |
| 4300 | struct desktop_shell *shell = data; |
| 4301 | |
| 4302 | shell_fade_startup(shell); |
| 4303 | return 0; |
| 4304 | } |
| 4305 | |
| 4306 | static void |
| 4307 | shell_fade_init(struct desktop_shell *shell) |
| 4308 | { |
| 4309 | /* Make compositor output all black, and wait for the desktop-shell |
| 4310 | * client to signal it is ready, then fade in. The timer triggers a |
| 4311 | * fade-in, in case the desktop-shell client takes too long. |
| 4312 | */ |
| 4313 | |
| 4314 | struct wl_event_loop *loop; |
| 4315 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 4316 | if (shell->fade.view != NULL) { |
Pekka Paalanen | 79346ab | 2013-05-22 18:03:09 +0300 | [diff] [blame] | 4317 | weston_log("%s: warning: fade surface already exists\n", |
| 4318 | __func__); |
| 4319 | return; |
| 4320 | } |
| 4321 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 4322 | shell->fade.view = shell_fade_create_surface(shell); |
| 4323 | if (!shell->fade.view) |
Pekka Paalanen | 79346ab | 2013-05-22 18:03:09 +0300 | [diff] [blame] | 4324 | return; |
| 4325 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 4326 | weston_view_update_transform(shell->fade.view); |
| 4327 | weston_surface_damage(shell->fade.view->surface); |
Pekka Paalanen | 79346ab | 2013-05-22 18:03:09 +0300 | [diff] [blame] | 4328 | |
| 4329 | loop = wl_display_get_event_loop(shell->compositor->wl_display); |
| 4330 | shell->fade.startup_timer = |
| 4331 | wl_event_loop_add_timer(loop, fade_startup_timeout, shell); |
| 4332 | wl_event_source_timer_update(shell->fade.startup_timer, 15000); |
| 4333 | } |
| 4334 | |
| 4335 | static void |
Ander Conselvan de Oliveira | a457563 | 2013-02-21 18:35:23 +0200 | [diff] [blame] | 4336 | idle_handler(struct wl_listener *listener, void *data) |
Ander Conselvan de Oliveira | 19d10ef | 2013-02-21 18:35:20 +0200 | [diff] [blame] | 4337 | { |
| 4338 | struct desktop_shell *shell = |
Ander Conselvan de Oliveira | a457563 | 2013-02-21 18:35:23 +0200 | [diff] [blame] | 4339 | container_of(listener, struct desktop_shell, idle_listener); |
Ander Conselvan de Oliveira | 19d10ef | 2013-02-21 18:35:20 +0200 | [diff] [blame] | 4340 | |
| 4341 | shell_fade(shell, FADE_OUT); |
| 4342 | /* lock() is called from shell_fade_done() */ |
| 4343 | } |
| 4344 | |
| 4345 | static void |
Ander Conselvan de Oliveira | a457563 | 2013-02-21 18:35:23 +0200 | [diff] [blame] | 4346 | wake_handler(struct wl_listener *listener, void *data) |
Ander Conselvan de Oliveira | 19d10ef | 2013-02-21 18:35:20 +0200 | [diff] [blame] | 4347 | { |
| 4348 | struct desktop_shell *shell = |
Ander Conselvan de Oliveira | a457563 | 2013-02-21 18:35:23 +0200 | [diff] [blame] | 4349 | container_of(listener, struct desktop_shell, wake_listener); |
Ander Conselvan de Oliveira | 19d10ef | 2013-02-21 18:35:20 +0200 | [diff] [blame] | 4350 | |
Ander Conselvan de Oliveira | 19d10ef | 2013-02-21 18:35:20 +0200 | [diff] [blame] | 4351 | unlock(shell); |
| 4352 | } |
| 4353 | |
| 4354 | static void |
Jan Arne Petersen | 42feced | 2012-06-21 21:52:17 +0200 | [diff] [blame] | 4355 | show_input_panels(struct wl_listener *listener, void *data) |
| 4356 | { |
| 4357 | struct desktop_shell *shell = |
Philipp Brüschweiler | 711fda8 | 2012-08-09 18:50:43 +0200 | [diff] [blame] | 4358 | container_of(listener, struct desktop_shell, |
| 4359 | show_input_panel_listener); |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 4360 | struct input_panel_surface *ipsurf, *next; |
Jan Arne Petersen | 42feced | 2012-06-21 21:52:17 +0200 | [diff] [blame] | 4361 | |
Jan Arne Petersen | 14da96b | 2013-04-18 16:47:28 +0200 | [diff] [blame] | 4362 | shell->text_input.surface = (struct weston_surface*)data; |
| 4363 | |
Jan Arne Petersen | 451a971 | 2013-02-11 15:10:11 +0100 | [diff] [blame] | 4364 | if (shell->showing_input_panels) |
| 4365 | return; |
| 4366 | |
Philipp Brüschweiler | 711fda8 | 2012-08-09 18:50:43 +0200 | [diff] [blame] | 4367 | shell->showing_input_panels = true; |
| 4368 | |
Jan Arne Petersen | cf18a32 | 2012-11-07 15:32:54 +0100 | [diff] [blame] | 4369 | if (!shell->locked) |
| 4370 | wl_list_insert(&shell->panel_layer.link, |
| 4371 | &shell->input_panel_layer.link); |
Philipp Brüschweiler | 711fda8 | 2012-08-09 18:50:43 +0200 | [diff] [blame] | 4372 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 4373 | wl_list_for_each_safe(ipsurf, next, |
Philipp Brüschweiler | 8801357 | 2012-08-06 13:44:42 +0200 | [diff] [blame] | 4374 | &shell->input_panel.surfaces, link) { |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 4375 | if (!ipsurf->surface->buffer_ref.buffer) |
Jan Arne Petersen | 14da96b | 2013-04-18 16:47:28 +0200 | [diff] [blame] | 4376 | continue; |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 4377 | wl_list_insert(&shell->input_panel_layer.view_list, |
| 4378 | &ipsurf->view->layer_link); |
| 4379 | weston_view_geometry_dirty(ipsurf->view); |
| 4380 | weston_view_update_transform(ipsurf->view); |
| 4381 | weston_surface_damage(ipsurf->surface); |
Jason Ekstrand | 918f2dd | 2013-12-02 21:01:53 -0600 | [diff] [blame] | 4382 | weston_slide_run(ipsurf->view, ipsurf->surface->height, |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 4383 | 0, NULL, NULL); |
Jan Arne Petersen | 42feced | 2012-06-21 21:52:17 +0200 | [diff] [blame] | 4384 | } |
| 4385 | } |
| 4386 | |
| 4387 | static void |
| 4388 | hide_input_panels(struct wl_listener *listener, void *data) |
| 4389 | { |
| 4390 | struct desktop_shell *shell = |
Philipp Brüschweiler | 711fda8 | 2012-08-09 18:50:43 +0200 | [diff] [blame] | 4391 | container_of(listener, struct desktop_shell, |
| 4392 | hide_input_panel_listener); |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 4393 | struct weston_view *view, *next; |
Jan Arne Petersen | 42feced | 2012-06-21 21:52:17 +0200 | [diff] [blame] | 4394 | |
Jan Arne Petersen | 6138197 | 2013-01-31 15:52:21 +0100 | [diff] [blame] | 4395 | if (!shell->showing_input_panels) |
| 4396 | return; |
| 4397 | |
Philipp Brüschweiler | 711fda8 | 2012-08-09 18:50:43 +0200 | [diff] [blame] | 4398 | shell->showing_input_panels = false; |
| 4399 | |
Jan Arne Petersen | 82ec909 | 2012-12-03 15:36:02 +0100 | [diff] [blame] | 4400 | if (!shell->locked) |
| 4401 | wl_list_remove(&shell->input_panel_layer.link); |
Philipp Brüschweiler | 711fda8 | 2012-08-09 18:50:43 +0200 | [diff] [blame] | 4402 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 4403 | wl_list_for_each_safe(view, next, |
| 4404 | &shell->input_panel_layer.view_list, layer_link) |
| 4405 | weston_view_unmap(view); |
Jan Arne Petersen | 42feced | 2012-06-21 21:52:17 +0200 | [diff] [blame] | 4406 | } |
| 4407 | |
| 4408 | static void |
Jan Arne Petersen | 14da96b | 2013-04-18 16:47:28 +0200 | [diff] [blame] | 4409 | update_input_panels(struct wl_listener *listener, void *data) |
| 4410 | { |
| 4411 | struct desktop_shell *shell = |
| 4412 | container_of(listener, struct desktop_shell, |
| 4413 | update_input_panel_listener); |
| 4414 | |
| 4415 | memcpy(&shell->text_input.cursor_rectangle, data, sizeof(pixman_box32_t)); |
| 4416 | } |
| 4417 | |
| 4418 | static void |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 4419 | center_on_output(struct weston_view *view, struct weston_output *output) |
Pekka Paalanen | 77346a6 | 2011-11-30 16:26:35 +0200 | [diff] [blame] | 4420 | { |
Giulio Camuffo | b836664 | 2013-04-25 13:57:46 +0300 | [diff] [blame] | 4421 | int32_t surf_x, surf_y, width, height; |
Ander Conselvan de Oliveira | 012b4c7 | 2012-11-27 17:03:42 +0200 | [diff] [blame] | 4422 | float x, y; |
Pekka Paalanen | 77346a6 | 2011-11-30 16:26:35 +0200 | [diff] [blame] | 4423 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 4424 | surface_subsurfaces_boundingbox(view->surface, &surf_x, &surf_y, &width, &height); |
Giulio Camuffo | b836664 | 2013-04-25 13:57:46 +0300 | [diff] [blame] | 4425 | |
| 4426 | x = output->x + (output->width - width) / 2 - surf_x / 2; |
| 4427 | y = output->y + (output->height - height) / 2 - surf_y / 2; |
Ander Conselvan de Oliveira | 012b4c7 | 2012-11-27 17:03:42 +0200 | [diff] [blame] | 4428 | |
Jason Ekstrand | 918f2dd | 2013-12-02 21:01:53 -0600 | [diff] [blame] | 4429 | weston_view_set_position(view, x, y); |
Pekka Paalanen | 77346a6 | 2011-11-30 16:26:35 +0200 | [diff] [blame] | 4430 | } |
| 4431 | |
| 4432 | static void |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 4433 | weston_view_set_initial_position(struct weston_view *view, |
| 4434 | struct desktop_shell *shell) |
Rob Bradford | ac63e5b | 2012-08-13 14:07:52 +0100 | [diff] [blame] | 4435 | { |
| 4436 | struct weston_compositor *compositor = shell->compositor; |
| 4437 | int ix = 0, iy = 0; |
| 4438 | int range_x, range_y; |
| 4439 | int dx, dy, x, y, panel_height; |
| 4440 | struct weston_output *output, *target_output = NULL; |
| 4441 | struct weston_seat *seat; |
| 4442 | |
| 4443 | /* As a heuristic place the new window on the same output as the |
| 4444 | * pointer. Falling back to the output containing 0, 0. |
| 4445 | * |
| 4446 | * TODO: Do something clever for touch too? |
| 4447 | */ |
| 4448 | wl_list_for_each(seat, &compositor->seat_list, link) { |
Kristian Høgsberg | 2bf8762 | 2013-05-07 23:17:41 -0400 | [diff] [blame] | 4449 | if (seat->pointer) { |
Kristian Høgsberg | e314875 | 2013-05-06 23:19:49 -0400 | [diff] [blame] | 4450 | ix = wl_fixed_to_int(seat->pointer->x); |
| 4451 | iy = wl_fixed_to_int(seat->pointer->y); |
Rob Bradford | ac63e5b | 2012-08-13 14:07:52 +0100 | [diff] [blame] | 4452 | break; |
| 4453 | } |
| 4454 | } |
| 4455 | |
| 4456 | wl_list_for_each(output, &compositor->output_list, link) { |
| 4457 | if (pixman_region32_contains_point(&output->region, ix, iy, NULL)) { |
| 4458 | target_output = output; |
| 4459 | break; |
| 4460 | } |
| 4461 | } |
| 4462 | |
| 4463 | if (!target_output) { |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 4464 | weston_view_set_position(view, 10 + random() % 400, |
| 4465 | 10 + random() % 400); |
Rob Bradford | ac63e5b | 2012-08-13 14:07:52 +0100 | [diff] [blame] | 4466 | return; |
| 4467 | } |
| 4468 | |
| 4469 | /* Valid range within output where the surface will still be onscreen. |
| 4470 | * If this is negative it means that the surface is bigger than |
| 4471 | * output. |
| 4472 | */ |
| 4473 | panel_height = get_output_panel_height(shell, target_output); |
Jason Ekstrand | 918f2dd | 2013-12-02 21:01:53 -0600 | [diff] [blame] | 4474 | range_x = target_output->width - view->surface->width; |
Scott Moreau | 1bad5db | 2012-08-18 01:04:05 -0600 | [diff] [blame] | 4475 | range_y = (target_output->height - panel_height) - |
Jason Ekstrand | 918f2dd | 2013-12-02 21:01:53 -0600 | [diff] [blame] | 4476 | view->surface->height; |
Rob Bradford | ac63e5b | 2012-08-13 14:07:52 +0100 | [diff] [blame] | 4477 | |
Rob Bradford | 4cb88c7 | 2012-08-13 15:18:44 +0100 | [diff] [blame] | 4478 | if (range_x > 0) |
Rob Bradford | ac63e5b | 2012-08-13 14:07:52 +0100 | [diff] [blame] | 4479 | dx = random() % range_x; |
Rob Bradford | ac63e5b | 2012-08-13 14:07:52 +0100 | [diff] [blame] | 4480 | else |
Rob Bradford | 4cb88c7 | 2012-08-13 15:18:44 +0100 | [diff] [blame] | 4481 | dx = 0; |
| 4482 | |
| 4483 | if (range_y > 0) |
Rob Bradford | ac63e5b | 2012-08-13 14:07:52 +0100 | [diff] [blame] | 4484 | dy = panel_height + random() % range_y; |
Rob Bradford | 4cb88c7 | 2012-08-13 15:18:44 +0100 | [diff] [blame] | 4485 | else |
| 4486 | dy = panel_height; |
Rob Bradford | ac63e5b | 2012-08-13 14:07:52 +0100 | [diff] [blame] | 4487 | |
| 4488 | x = target_output->x + dx; |
| 4489 | y = target_output->y + dy; |
| 4490 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 4491 | weston_view_set_position(view, x, y); |
Rob Bradford | ac63e5b | 2012-08-13 14:07:52 +0100 | [diff] [blame] | 4492 | } |
| 4493 | |
| 4494 | static void |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 4495 | map(struct desktop_shell *shell, struct shell_surface *shsurf, |
Jason Ekstrand | 918f2dd | 2013-12-02 21:01:53 -0600 | [diff] [blame] | 4496 | int32_t sx, int32_t sy) |
Kristian Høgsberg | 02ec0a5 | 2011-04-23 13:04:11 -0400 | [diff] [blame] | 4497 | { |
Kristian Høgsberg | 8334bc1 | 2012-01-03 10:29:47 -0500 | [diff] [blame] | 4498 | struct weston_compositor *compositor = shell->compositor; |
Daniel Stone | b210468 | 2012-05-30 16:31:56 +0100 | [diff] [blame] | 4499 | struct weston_seat *seat; |
Juan Zhao | 96879df | 2012-02-07 08:45:41 +0800 | [diff] [blame] | 4500 | int panel_height = 0; |
Giulio Camuffo | b836664 | 2013-04-25 13:57:46 +0300 | [diff] [blame] | 4501 | int32_t surf_x, surf_y; |
Pekka Paalanen | 57da4a8 | 2011-11-23 16:42:16 +0200 | [diff] [blame] | 4502 | |
Pekka Paalanen | 77346a6 | 2011-11-30 16:26:35 +0200 | [diff] [blame] | 4503 | /* initial positioning, see also configure() */ |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 4504 | switch (shsurf->type) { |
Rafael Antognolli | ed207b4 | 2013-12-03 15:35:43 -0200 | [diff] [blame^] | 4505 | case SHELL_SURFACE_TOPLEVEL: |
Rafael Antognolli | 03b1659 | 2013-12-03 15:35:42 -0200 | [diff] [blame] | 4506 | if (shsurf->state.fullscreen) { |
| 4507 | center_on_output(shsurf->view, shsurf->fullscreen_output); |
| 4508 | shell_map_fullscreen(shsurf); |
| 4509 | } else if (shsurf->state.maximized) { |
| 4510 | /* use surface configure to set the geometry */ |
| 4511 | panel_height = get_output_panel_height(shell, shsurf->output); |
| 4512 | surface_subsurfaces_boundingbox(shsurf->surface, |
| 4513 | &surf_x, &surf_y, NULL, NULL); |
| 4514 | weston_view_set_position(shsurf->view, |
| 4515 | shsurf->output->x - surf_x, |
| 4516 | shsurf->output->y + |
| 4517 | panel_height - surf_y); |
Rafael Antognolli | ed207b4 | 2013-12-03 15:35:43 -0200 | [diff] [blame^] | 4518 | } else if (!shsurf->state.relative) { |
Rafael Antognolli | 03b1659 | 2013-12-03 15:35:42 -0200 | [diff] [blame] | 4519 | weston_view_set_initial_position(shsurf->view, shell); |
| 4520 | } |
Juan Zhao | 96879df | 2012-02-07 08:45:41 +0800 | [diff] [blame] | 4521 | break; |
Tiago Vignatti | 0f99701 | 2012-02-10 16:17:23 +0200 | [diff] [blame] | 4522 | case SHELL_SURFACE_POPUP: |
Kristian Høgsberg | 3730f36 | 2012-04-13 12:40:07 -0400 | [diff] [blame] | 4523 | shell_map_popup(shsurf); |
Rob Bradford | db99938 | 2012-12-06 12:07:48 +0000 | [diff] [blame] | 4524 | break; |
Ander Conselvan de Oliveira | e9e0515 | 2012-02-15 17:02:56 +0200 | [diff] [blame] | 4525 | case SHELL_SURFACE_NONE: |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 4526 | weston_view_set_position(shsurf->view, |
| 4527 | shsurf->view->geometry.x + sx, |
| 4528 | shsurf->view->geometry.y + sy); |
Tiago Vignatti | 0f99701 | 2012-02-10 16:17:23 +0200 | [diff] [blame] | 4529 | break; |
Philip Withnall | 0f640e2 | 2013-11-25 18:01:31 +0000 | [diff] [blame] | 4530 | case SHELL_SURFACE_XWAYLAND: |
Pekka Paalanen | 77346a6 | 2011-11-30 16:26:35 +0200 | [diff] [blame] | 4531 | default: |
| 4532 | ; |
| 4533 | } |
Kristian Høgsberg | 7584062 | 2011-09-06 13:48:16 -0400 | [diff] [blame] | 4534 | |
Philip Withnall | e1d75ae | 2013-11-25 18:01:41 +0000 | [diff] [blame] | 4535 | /* Surface stacking order, see also activate(). */ |
| 4536 | shell_surface_update_layer(shsurf); |
Pekka Paalanen | f0fc70d | 2011-11-15 13:34:54 +0200 | [diff] [blame] | 4537 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 4538 | if (shsurf->type != SHELL_SURFACE_NONE) { |
| 4539 | weston_view_update_transform(shsurf->view); |
Rafael Antognolli | 03b1659 | 2013-12-03 15:35:42 -0200 | [diff] [blame] | 4540 | if (shsurf->state.maximized) { |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 4541 | shsurf->surface->output = shsurf->output; |
| 4542 | shsurf->view->output = shsurf->output; |
| 4543 | } |
Ander Conselvan de Oliveira | de56c31 | 2012-03-05 15:39:23 +0200 | [diff] [blame] | 4544 | } |
Kristian Høgsberg | 2f88a40 | 2011-12-04 15:32:59 -0500 | [diff] [blame] | 4545 | |
Rafael Antognolli | ed207b4 | 2013-12-03 15:35:43 -0200 | [diff] [blame^] | 4546 | if ((shsurf->type == SHELL_SURFACE_XWAYLAND || shsurf->state.relative) && |
| 4547 | shsurf->transient.flags == WL_SHELL_SURFACE_TRANSIENT_INACTIVE) { |
| 4548 | } |
| 4549 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 4550 | switch (shsurf->type) { |
Tiago Vignatti | fb2adba | 2013-06-12 15:43:21 -0300 | [diff] [blame] | 4551 | /* XXX: xwayland's using the same fields for transient type */ |
| 4552 | case SHELL_SURFACE_XWAYLAND: |
Tiago Vignatti | 99aeb1e | 2012-05-23 22:06:26 +0300 | [diff] [blame] | 4553 | if (shsurf->transient.flags == |
| 4554 | WL_SHELL_SURFACE_TRANSIENT_INACTIVE) |
| 4555 | break; |
| 4556 | case SHELL_SURFACE_TOPLEVEL: |
Rafael Antognolli | ed207b4 | 2013-12-03 15:35:43 -0200 | [diff] [blame^] | 4557 | if (shsurf->state.relative && |
| 4558 | shsurf->transient.flags == WL_SHELL_SURFACE_TRANSIENT_INACTIVE) |
| 4559 | break; |
| 4560 | if (!shell->locked) |
| 4561 | break; |
| 4562 | wl_list_for_each(seat, &compositor->seat_list, link) |
| 4563 | activate(shell, shsurf->surface, seat); |
Juan Zhao | 7bb92f0 | 2011-12-15 11:31:51 -0500 | [diff] [blame] | 4564 | break; |
Philip Withnall | 0f640e2 | 2013-11-25 18:01:31 +0000 | [diff] [blame] | 4565 | case SHELL_SURFACE_POPUP: |
| 4566 | case SHELL_SURFACE_NONE: |
Juan Zhao | 7bb92f0 | 2011-12-15 11:31:51 -0500 | [diff] [blame] | 4567 | default: |
| 4568 | break; |
| 4569 | } |
| 4570 | |
Rafael Antognolli | 03b1659 | 2013-12-03 15:35:42 -0200 | [diff] [blame] | 4571 | if (shsurf->type == SHELL_SURFACE_TOPLEVEL && |
| 4572 | !shsurf->state.maximized && !shsurf->state.fullscreen) |
Juan Zhao | e10d279 | 2012-04-25 19:09:52 +0800 | [diff] [blame] | 4573 | { |
| 4574 | switch (shell->win_animation_type) { |
| 4575 | case ANIMATION_FADE: |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 4576 | 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] | 4577 | break; |
| 4578 | case ANIMATION_ZOOM: |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 4579 | weston_zoom_run(shsurf->view, 0.5, 1.0, NULL, NULL); |
Juan Zhao | e10d279 | 2012-04-25 19:09:52 +0800 | [diff] [blame] | 4580 | break; |
Philip Withnall | 4a86a0a | 2013-11-25 18:01:32 +0000 | [diff] [blame] | 4581 | case ANIMATION_NONE: |
Juan Zhao | e10d279 | 2012-04-25 19:09:52 +0800 | [diff] [blame] | 4582 | default: |
| 4583 | break; |
| 4584 | } |
| 4585 | } |
Kristian Høgsberg | 32e24cc | 2011-11-09 12:07:35 -0500 | [diff] [blame] | 4586 | } |
| 4587 | |
| 4588 | static void |
Tiago Vignatti | be14326 | 2012-04-16 17:31:41 +0300 | [diff] [blame] | 4589 | configure(struct desktop_shell *shell, struct weston_surface *surface, |
Jason Ekstrand | 918f2dd | 2013-12-02 21:01:53 -0600 | [diff] [blame] | 4590 | float x, float y) |
Kristian Høgsberg | 32e24cc | 2011-11-09 12:07:35 -0500 | [diff] [blame] | 4591 | { |
Pekka Paalanen | 77346a6 | 2011-11-30 16:26:35 +0200 | [diff] [blame] | 4592 | struct shell_surface *shsurf; |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 4593 | struct weston_view *view; |
Jason Ekstrand | 918f2dd | 2013-12-02 21:01:53 -0600 | [diff] [blame] | 4594 | int32_t mx, my, surf_x, surf_y; |
Kristian Høgsberg | 32e24cc | 2011-11-09 12:07:35 -0500 | [diff] [blame] | 4595 | |
Pekka Paalanen | 77346a6 | 2011-11-30 16:26:35 +0200 | [diff] [blame] | 4596 | shsurf = get_shell_surface(surface); |
Pekka Paalanen | 77346a6 | 2011-11-30 16:26:35 +0200 | [diff] [blame] | 4597 | |
Rafael Antognolli | 03b1659 | 2013-12-03 15:35:42 -0200 | [diff] [blame] | 4598 | if (shsurf->state.fullscreen) |
Alex Wu | 4539b08 | 2012-03-01 12:57:46 +0800 | [diff] [blame] | 4599 | shell_configure_fullscreen(shsurf); |
Rafael Antognolli | 03b1659 | 2013-12-03 15:35:42 -0200 | [diff] [blame] | 4600 | else if (shsurf->state.maximized) { |
Alex Wu | 4539b08 | 2012-03-01 12:57:46 +0800 | [diff] [blame] | 4601 | /* setting x, y and using configure to change that geometry */ |
Giulio Camuffo | b836664 | 2013-04-25 13:57:46 +0300 | [diff] [blame] | 4602 | surface_subsurfaces_boundingbox(shsurf->surface, &surf_x, &surf_y, |
| 4603 | NULL, NULL); |
Jason Ekstrand | 918f2dd | 2013-12-02 21:01:53 -0600 | [diff] [blame] | 4604 | mx = shsurf->output->x - surf_x; |
| 4605 | my = shsurf->output->y + |
| 4606 | get_output_panel_height(shell,shsurf->output) - surf_y; |
| 4607 | weston_view_set_position(shsurf->view, mx, my); |
Rafael Antognolli | 03b1659 | 2013-12-03 15:35:42 -0200 | [diff] [blame] | 4608 | } else { |
Jason Ekstrand | 918f2dd | 2013-12-02 21:01:53 -0600 | [diff] [blame] | 4609 | weston_view_set_position(shsurf->view, x, y); |
Kristian Høgsberg | 7a5c979 | 2011-06-18 06:12:54 -0400 | [diff] [blame] | 4610 | } |
Kristian Høgsberg | 32e24cc | 2011-11-09 12:07:35 -0500 | [diff] [blame] | 4611 | |
Alex Wu | 4539b08 | 2012-03-01 12:57:46 +0800 | [diff] [blame] | 4612 | /* XXX: would a fullscreen surface need the same handling? */ |
Kristian Høgsberg | 6a8b553 | 2012-02-16 23:43:59 -0500 | [diff] [blame] | 4613 | if (surface->output) { |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 4614 | wl_list_for_each(view, &surface->views, surface_link) |
| 4615 | weston_view_update_transform(view); |
Pekka Paalanen | 77346a6 | 2011-11-30 16:26:35 +0200 | [diff] [blame] | 4616 | |
Rafael Antognolli | 03b1659 | 2013-12-03 15:35:42 -0200 | [diff] [blame] | 4617 | if (shsurf->state.maximized) |
Juan Zhao | 96879df | 2012-02-07 08:45:41 +0800 | [diff] [blame] | 4618 | surface->output = shsurf->output; |
Pekka Paalanen | 77346a6 | 2011-11-30 16:26:35 +0200 | [diff] [blame] | 4619 | } |
Kristian Høgsberg | 0793756 | 2011-04-12 17:25:42 -0400 | [diff] [blame] | 4620 | } |
| 4621 | |
Ander Conselvan de Oliveira | 093bfa3 | 2012-03-27 17:36:41 +0300 | [diff] [blame] | 4622 | static void |
Jason Ekstrand | 918f2dd | 2013-12-02 21:01:53 -0600 | [diff] [blame] | 4623 | 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] | 4624 | { |
Ander Conselvan de Oliveira | 7fb9f95 | 2012-03-27 17:36:42 +0300 | [diff] [blame] | 4625 | struct shell_surface *shsurf = get_shell_surface(es); |
Tiago Vignatti | be14326 | 2012-04-16 17:31:41 +0300 | [diff] [blame] | 4626 | struct desktop_shell *shell = shsurf->shell; |
Giulio Camuffo | 184df50 | 2013-02-21 11:29:21 +0100 | [diff] [blame] | 4627 | |
Tiago Vignatti | 70e5c9c | 2012-05-07 15:23:07 +0300 | [diff] [blame] | 4628 | int type_changed = 0; |
Ander Conselvan de Oliveira | 093bfa3 | 2012-03-27 17:36:41 +0300 | [diff] [blame] | 4629 | |
Kristian Høgsberg | 8eb0f4f | 2013-06-17 10:33:14 -0400 | [diff] [blame] | 4630 | if (!weston_surface_is_mapped(es) && |
| 4631 | !wl_list_empty(&shsurf->popup.grab_link)) { |
Giulio Camuffo | 5085a75 | 2013-03-25 21:42:45 +0100 | [diff] [blame] | 4632 | remove_popup_grab(shsurf); |
| 4633 | } |
| 4634 | |
Jason Ekstrand | 918f2dd | 2013-12-02 21:01:53 -0600 | [diff] [blame] | 4635 | if (es->width == 0) |
Giulio Camuffo | 184df50 | 2013-02-21 11:29:21 +0100 | [diff] [blame] | 4636 | return; |
| 4637 | |
Rafael Antognolli | 03b1659 | 2013-12-03 15:35:42 -0200 | [diff] [blame] | 4638 | if ((shsurf->next_type != SHELL_SURFACE_NONE && |
| 4639 | shsurf->type != shsurf->next_type) || |
| 4640 | shsurf->state_changed) { |
Kristian Høgsberg | 7f366e7 | 2012-04-27 17:20:01 -0400 | [diff] [blame] | 4641 | set_surface_type(shsurf); |
Kristian Høgsberg | f7e23d5 | 2012-04-27 17:51:59 -0400 | [diff] [blame] | 4642 | type_changed = 1; |
| 4643 | } |
Kristian Høgsberg | 7f366e7 | 2012-04-27 17:20:01 -0400 | [diff] [blame] | 4644 | |
Ander Conselvan de Oliveira | 093bfa3 | 2012-03-27 17:36:41 +0300 | [diff] [blame] | 4645 | if (!weston_surface_is_mapped(es)) { |
Jason Ekstrand | 918f2dd | 2013-12-02 21:01:53 -0600 | [diff] [blame] | 4646 | map(shell, shsurf, sx, sy); |
Kristian Høgsberg | f7e23d5 | 2012-04-27 17:51:59 -0400 | [diff] [blame] | 4647 | } else if (type_changed || sx != 0 || sy != 0 || |
Jason Ekstrand | 918f2dd | 2013-12-02 21:01:53 -0600 | [diff] [blame] | 4648 | shsurf->last_width != es->width || |
| 4649 | shsurf->last_height != es->height) { |
| 4650 | shsurf->last_width = es->width; |
| 4651 | shsurf->last_height = es->height; |
John Kåre Alsaker | 490d02a | 2012-09-30 02:57:21 +0200 | [diff] [blame] | 4652 | float from_x, from_y; |
| 4653 | float to_x, to_y; |
Ander Conselvan de Oliveira | 093bfa3 | 2012-03-27 17:36:41 +0300 | [diff] [blame] | 4654 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 4655 | weston_view_to_global_float(shsurf->view, 0, 0, &from_x, &from_y); |
| 4656 | 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] | 4657 | configure(shell, es, |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 4658 | shsurf->view->geometry.x + to_x - from_x, |
Jason Ekstrand | 918f2dd | 2013-12-02 21:01:53 -0600 | [diff] [blame] | 4659 | shsurf->view->geometry.y + to_y - from_y); |
Ander Conselvan de Oliveira | 093bfa3 | 2012-03-27 17:36:41 +0300 | [diff] [blame] | 4660 | } |
| 4661 | } |
| 4662 | |
Tiago Vignatti | b7dbbd6 | 2012-09-25 17:57:01 +0300 | [diff] [blame] | 4663 | static void launch_desktop_shell_process(void *data); |
Pekka Paalanen | 4d733ee | 2012-01-17 14:36:27 +0200 | [diff] [blame] | 4664 | |
Kristian Høgsberg | 97d44aa | 2011-08-26 17:21:20 -0400 | [diff] [blame] | 4665 | static void |
Kristian Høgsberg | 8334bc1 | 2012-01-03 10:29:47 -0500 | [diff] [blame] | 4666 | desktop_shell_sigchld(struct weston_process *process, int status) |
Pekka Paalanen | 6cd281a | 2011-11-03 14:11:32 +0200 | [diff] [blame] | 4667 | { |
Pekka Paalanen | 4d733ee | 2012-01-17 14:36:27 +0200 | [diff] [blame] | 4668 | uint32_t time; |
Tiago Vignatti | be14326 | 2012-04-16 17:31:41 +0300 | [diff] [blame] | 4669 | struct desktop_shell *shell = |
| 4670 | container_of(process, struct desktop_shell, child.process); |
Pekka Paalanen | 6cd281a | 2011-11-03 14:11:32 +0200 | [diff] [blame] | 4671 | |
| 4672 | shell->child.process.pid = 0; |
| 4673 | shell->child.client = NULL; /* already destroyed by wayland */ |
Pekka Paalanen | 4d733ee | 2012-01-17 14:36:27 +0200 | [diff] [blame] | 4674 | |
| 4675 | /* if desktop-shell dies more than 5 times in 30 seconds, give up */ |
| 4676 | time = weston_compositor_get_time(); |
Kristian Høgsberg | f03a616 | 2012-01-17 11:07:42 -0500 | [diff] [blame] | 4677 | if (time - shell->child.deathstamp > 30000) { |
Pekka Paalanen | 4d733ee | 2012-01-17 14:36:27 +0200 | [diff] [blame] | 4678 | shell->child.deathstamp = time; |
| 4679 | shell->child.deathcount = 0; |
| 4680 | } |
| 4681 | |
| 4682 | shell->child.deathcount++; |
| 4683 | if (shell->child.deathcount > 5) { |
Emilio Pozuelo Monfort | 46ce798 | 2013-11-20 13:22:29 +0100 | [diff] [blame] | 4684 | weston_log("%s died, giving up.\n", shell->client); |
Pekka Paalanen | 4d733ee | 2012-01-17 14:36:27 +0200 | [diff] [blame] | 4685 | return; |
| 4686 | } |
| 4687 | |
Emilio Pozuelo Monfort | 46ce798 | 2013-11-20 13:22:29 +0100 | [diff] [blame] | 4688 | weston_log("%s died, respawning...\n", shell->client); |
Pekka Paalanen | 4d733ee | 2012-01-17 14:36:27 +0200 | [diff] [blame] | 4689 | launch_desktop_shell_process(shell); |
Pekka Paalanen | 79346ab | 2013-05-22 18:03:09 +0300 | [diff] [blame] | 4690 | shell_fade_startup(shell); |
Pekka Paalanen | 6cd281a | 2011-11-03 14:11:32 +0200 | [diff] [blame] | 4691 | } |
| 4692 | |
Tiago Vignatti | b7dbbd6 | 2012-09-25 17:57:01 +0300 | [diff] [blame] | 4693 | static void |
| 4694 | launch_desktop_shell_process(void *data) |
Pekka Paalanen | 6cd281a | 2011-11-03 14:11:32 +0200 | [diff] [blame] | 4695 | { |
Tiago Vignatti | b7dbbd6 | 2012-09-25 17:57:01 +0300 | [diff] [blame] | 4696 | struct desktop_shell *shell = data; |
Pekka Paalanen | 6cd281a | 2011-11-03 14:11:32 +0200 | [diff] [blame] | 4697 | |
Kristian Høgsberg | 8334bc1 | 2012-01-03 10:29:47 -0500 | [diff] [blame] | 4698 | shell->child.client = weston_client_launch(shell->compositor, |
Pekka Paalanen | 409ef0a | 2011-12-02 15:30:21 +0200 | [diff] [blame] | 4699 | &shell->child.process, |
Emilio Pozuelo Monfort | 46ce798 | 2013-11-20 13:22:29 +0100 | [diff] [blame] | 4700 | shell->client, |
Pekka Paalanen | 409ef0a | 2011-12-02 15:30:21 +0200 | [diff] [blame] | 4701 | desktop_shell_sigchld); |
| 4702 | |
| 4703 | if (!shell->child.client) |
Emilio Pozuelo Monfort | 46ce798 | 2013-11-20 13:22:29 +0100 | [diff] [blame] | 4704 | weston_log("not able to start %s\n", shell->client); |
Pekka Paalanen | 6cd281a | 2011-11-03 14:11:32 +0200 | [diff] [blame] | 4705 | } |
| 4706 | |
| 4707 | static void |
Kristian Høgsberg | 97d44aa | 2011-08-26 17:21:20 -0400 | [diff] [blame] | 4708 | bind_shell(struct wl_client *client, void *data, uint32_t version, uint32_t id) |
| 4709 | { |
Tiago Vignatti | be14326 | 2012-04-16 17:31:41 +0300 | [diff] [blame] | 4710 | struct desktop_shell *shell = data; |
Jason Ekstrand | a85118c | 2013-06-27 20:17:02 -0500 | [diff] [blame] | 4711 | struct wl_resource *resource; |
Kristian Høgsberg | 97d44aa | 2011-08-26 17:21:20 -0400 | [diff] [blame] | 4712 | |
Jason Ekstrand | a85118c | 2013-06-27 20:17:02 -0500 | [diff] [blame] | 4713 | resource = wl_resource_create(client, &wl_shell_interface, 1, id); |
| 4714 | if (resource) |
| 4715 | wl_resource_set_implementation(resource, &shell_implementation, |
| 4716 | shell, NULL); |
Kristian Høgsberg | 97d44aa | 2011-08-26 17:21:20 -0400 | [diff] [blame] | 4717 | } |
| 4718 | |
Kristian Høgsberg | 7584062 | 2011-09-06 13:48:16 -0400 | [diff] [blame] | 4719 | static void |
Pekka Paalanen | 9ef3e01 | 2011-11-15 13:34:48 +0200 | [diff] [blame] | 4720 | unbind_desktop_shell(struct wl_resource *resource) |
| 4721 | { |
Jason Ekstrand | 651f00e | 2013-06-14 10:07:54 -0500 | [diff] [blame] | 4722 | struct desktop_shell *shell = wl_resource_get_user_data(resource); |
Kristian Høgsberg | 1ec0c31 | 2011-11-15 16:39:55 -0500 | [diff] [blame] | 4723 | |
| 4724 | if (shell->locked) |
| 4725 | resume_desktop(shell); |
| 4726 | |
Pekka Paalanen | 9ef3e01 | 2011-11-15 13:34:48 +0200 | [diff] [blame] | 4727 | shell->child.desktop_shell = NULL; |
| 4728 | shell->prepare_event_sent = false; |
Pekka Paalanen | 9ef3e01 | 2011-11-15 13:34:48 +0200 | [diff] [blame] | 4729 | } |
| 4730 | |
| 4731 | static void |
Kristian Høgsberg | 7584062 | 2011-09-06 13:48:16 -0400 | [diff] [blame] | 4732 | bind_desktop_shell(struct wl_client *client, |
| 4733 | void *data, uint32_t version, uint32_t id) |
| 4734 | { |
Tiago Vignatti | be14326 | 2012-04-16 17:31:41 +0300 | [diff] [blame] | 4735 | struct desktop_shell *shell = data; |
Pekka Paalanen | bbe6052 | 2011-11-03 14:11:33 +0200 | [diff] [blame] | 4736 | struct wl_resource *resource; |
Kristian Høgsberg | 7584062 | 2011-09-06 13:48:16 -0400 | [diff] [blame] | 4737 | |
Jason Ekstrand | a85118c | 2013-06-27 20:17:02 -0500 | [diff] [blame] | 4738 | resource = wl_resource_create(client, &desktop_shell_interface, |
| 4739 | MIN(version, 2), id); |
Pekka Paalanen | bbe6052 | 2011-11-03 14:11:33 +0200 | [diff] [blame] | 4740 | |
Pekka Paalanen | 9ef3e01 | 2011-11-15 13:34:48 +0200 | [diff] [blame] | 4741 | if (client == shell->child.client) { |
Jason Ekstrand | a85118c | 2013-06-27 20:17:02 -0500 | [diff] [blame] | 4742 | wl_resource_set_implementation(resource, |
| 4743 | &desktop_shell_implementation, |
| 4744 | shell, unbind_desktop_shell); |
Pekka Paalanen | 9ef3e01 | 2011-11-15 13:34:48 +0200 | [diff] [blame] | 4745 | shell->child.desktop_shell = resource; |
Pekka Paalanen | 79346ab | 2013-05-22 18:03:09 +0300 | [diff] [blame] | 4746 | |
| 4747 | if (version < 2) |
| 4748 | shell_fade_startup(shell); |
| 4749 | |
Pekka Paalanen | bbe6052 | 2011-11-03 14:11:33 +0200 | [diff] [blame] | 4750 | return; |
Pekka Paalanen | 9ef3e01 | 2011-11-15 13:34:48 +0200 | [diff] [blame] | 4751 | } |
Pekka Paalanen | bbe6052 | 2011-11-03 14:11:33 +0200 | [diff] [blame] | 4752 | |
| 4753 | wl_resource_post_error(resource, WL_DISPLAY_ERROR_INVALID_OBJECT, |
| 4754 | "permission to bind desktop_shell denied"); |
Kristian Høgsberg | eae5de7 | 2012-04-11 22:42:15 -0400 | [diff] [blame] | 4755 | wl_resource_destroy(resource); |
Kristian Høgsberg | 7584062 | 2011-09-06 13:48:16 -0400 | [diff] [blame] | 4756 | } |
| 4757 | |
Pekka Paalanen | 6e16811 | 2011-11-24 11:34:05 +0200 | [diff] [blame] | 4758 | static void |
Jason Ekstrand | 918f2dd | 2013-12-02 21:01:53 -0600 | [diff] [blame] | 4759 | 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] | 4760 | { |
Giulio Camuffo | 7fe01b1 | 2013-03-28 18:02:42 +0100 | [diff] [blame] | 4761 | struct desktop_shell *shell = surface->configure_private; |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 4762 | struct weston_view *view; |
Kristian Høgsberg | 1a73a63 | 2012-06-26 22:15:53 -0400 | [diff] [blame] | 4763 | |
Jason Ekstrand | 918f2dd | 2013-12-02 21:01:53 -0600 | [diff] [blame] | 4764 | if (surface->width == 0) |
Giulio Camuffo | 184df50 | 2013-02-21 11:29:21 +0100 | [diff] [blame] | 4765 | return; |
| 4766 | |
Pekka Paalanen | 3a1d07d | 2012-12-20 14:02:13 +0200 | [diff] [blame] | 4767 | /* XXX: starting weston-screensaver beforehand does not work */ |
Kristian Høgsberg | 1a73a63 | 2012-06-26 22:15:53 -0400 | [diff] [blame] | 4768 | if (!shell->locked) |
| 4769 | return; |
| 4770 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 4771 | view = container_of(surface->views.next, struct weston_view, surface_link); |
| 4772 | center_on_output(view, surface->output); |
Kristian Høgsberg | 1a73a63 | 2012-06-26 22:15:53 -0400 | [diff] [blame] | 4773 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 4774 | if (wl_list_empty(&view->layer_link)) { |
| 4775 | wl_list_insert(shell->lock_layer.view_list.prev, |
| 4776 | &view->layer_link); |
| 4777 | weston_view_update_transform(view); |
Ander Conselvan de Oliveira | 859e885 | 2013-02-21 18:35:21 +0200 | [diff] [blame] | 4778 | wl_event_source_timer_update(shell->screensaver.timer, |
| 4779 | shell->screensaver.duration); |
Ander Conselvan de Oliveira | 19d10ef | 2013-02-21 18:35:20 +0200 | [diff] [blame] | 4780 | shell_fade(shell, FADE_IN); |
Kristian Høgsberg | 1a73a63 | 2012-06-26 22:15:53 -0400 | [diff] [blame] | 4781 | } |
| 4782 | } |
| 4783 | |
| 4784 | static void |
Pekka Paalanen | 6e16811 | 2011-11-24 11:34:05 +0200 | [diff] [blame] | 4785 | screensaver_set_surface(struct wl_client *client, |
| 4786 | struct wl_resource *resource, |
Kristian Høgsberg | 1a73a63 | 2012-06-26 22:15:53 -0400 | [diff] [blame] | 4787 | struct wl_resource *surface_resource, |
Pekka Paalanen | 6e16811 | 2011-11-24 11:34:05 +0200 | [diff] [blame] | 4788 | struct wl_resource *output_resource) |
| 4789 | { |
Jason Ekstrand | 651f00e | 2013-06-14 10:07:54 -0500 | [diff] [blame] | 4790 | struct desktop_shell *shell = wl_resource_get_user_data(resource); |
Jason Ekstrand | 0f2ef7e | 2013-06-14 10:07:53 -0500 | [diff] [blame] | 4791 | struct weston_surface *surface = |
| 4792 | wl_resource_get_user_data(surface_resource); |
Jason Ekstrand | a0d2dde | 2013-06-14 10:08:01 -0500 | [diff] [blame] | 4793 | struct weston_output *output = wl_resource_get_user_data(output_resource); |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 4794 | struct weston_view *view, *next; |
| 4795 | |
| 4796 | /* Make sure we only have one view */ |
| 4797 | wl_list_for_each_safe(view, next, &surface->views, surface_link) |
| 4798 | weston_view_destroy(view); |
| 4799 | weston_view_create(surface); |
Pekka Paalanen | 6e16811 | 2011-11-24 11:34:05 +0200 | [diff] [blame] | 4800 | |
Kristian Høgsberg | 1a73a63 | 2012-06-26 22:15:53 -0400 | [diff] [blame] | 4801 | surface->configure = screensaver_configure; |
Giulio Camuffo | 7fe01b1 | 2013-03-28 18:02:42 +0100 | [diff] [blame] | 4802 | surface->configure_private = shell; |
Pekka Paalanen | 77346a6 | 2011-11-30 16:26:35 +0200 | [diff] [blame] | 4803 | surface->output = output; |
Pekka Paalanen | 6e16811 | 2011-11-24 11:34:05 +0200 | [diff] [blame] | 4804 | } |
| 4805 | |
| 4806 | static const struct screensaver_interface screensaver_implementation = { |
| 4807 | screensaver_set_surface |
| 4808 | }; |
| 4809 | |
| 4810 | static void |
| 4811 | unbind_screensaver(struct wl_resource *resource) |
| 4812 | { |
Jason Ekstrand | 651f00e | 2013-06-14 10:07:54 -0500 | [diff] [blame] | 4813 | struct desktop_shell *shell = wl_resource_get_user_data(resource); |
Pekka Paalanen | 6e16811 | 2011-11-24 11:34:05 +0200 | [diff] [blame] | 4814 | |
Pekka Paalanen | 77346a6 | 2011-11-30 16:26:35 +0200 | [diff] [blame] | 4815 | shell->screensaver.binding = NULL; |
Pekka Paalanen | 6e16811 | 2011-11-24 11:34:05 +0200 | [diff] [blame] | 4816 | } |
| 4817 | |
| 4818 | static void |
| 4819 | bind_screensaver(struct wl_client *client, |
| 4820 | void *data, uint32_t version, uint32_t id) |
| 4821 | { |
Tiago Vignatti | be14326 | 2012-04-16 17:31:41 +0300 | [diff] [blame] | 4822 | struct desktop_shell *shell = data; |
Pekka Paalanen | 6e16811 | 2011-11-24 11:34:05 +0200 | [diff] [blame] | 4823 | struct wl_resource *resource; |
| 4824 | |
Jason Ekstrand | a85118c | 2013-06-27 20:17:02 -0500 | [diff] [blame] | 4825 | resource = wl_resource_create(client, &screensaver_interface, 1, id); |
Pekka Paalanen | 6e16811 | 2011-11-24 11:34:05 +0200 | [diff] [blame] | 4826 | |
Pekka Paalanen | 77346a6 | 2011-11-30 16:26:35 +0200 | [diff] [blame] | 4827 | if (shell->screensaver.binding == NULL) { |
Jason Ekstrand | a85118c | 2013-06-27 20:17:02 -0500 | [diff] [blame] | 4828 | wl_resource_set_implementation(resource, |
| 4829 | &screensaver_implementation, |
| 4830 | shell, unbind_screensaver); |
Pekka Paalanen | 77346a6 | 2011-11-30 16:26:35 +0200 | [diff] [blame] | 4831 | shell->screensaver.binding = resource; |
Pekka Paalanen | 6e16811 | 2011-11-24 11:34:05 +0200 | [diff] [blame] | 4832 | return; |
| 4833 | } |
| 4834 | |
| 4835 | wl_resource_post_error(resource, WL_DISPLAY_ERROR_INVALID_OBJECT, |
| 4836 | "interface object already bound"); |
Kristian Høgsberg | eae5de7 | 2012-04-11 22:42:15 -0400 | [diff] [blame] | 4837 | wl_resource_destroy(resource); |
Pekka Paalanen | 6e16811 | 2011-11-24 11:34:05 +0200 | [diff] [blame] | 4838 | } |
| 4839 | |
Jan Arne Petersen | 42feced | 2012-06-21 21:52:17 +0200 | [diff] [blame] | 4840 | static void |
Jason Ekstrand | 918f2dd | 2013-12-02 21:01:53 -0600 | [diff] [blame] | 4841 | input_panel_configure(struct weston_surface *surface, int32_t sx, int32_t sy) |
Kristian Høgsberg | 0636ac3 | 2012-06-27 10:22:15 -0400 | [diff] [blame] | 4842 | { |
Jan Arne Petersen | 14da96b | 2013-04-18 16:47:28 +0200 | [diff] [blame] | 4843 | struct input_panel_surface *ip_surface = surface->configure_private; |
| 4844 | struct desktop_shell *shell = ip_surface->shell; |
Jan Arne Petersen | af7b6c9 | 2013-01-16 21:26:53 +0100 | [diff] [blame] | 4845 | float x, y; |
Jan Arne Petersen | 14da96b | 2013-04-18 16:47:28 +0200 | [diff] [blame] | 4846 | uint32_t show_surface = 0; |
Jan Arne Petersen | af7b6c9 | 2013-01-16 21:26:53 +0100 | [diff] [blame] | 4847 | |
Jason Ekstrand | 918f2dd | 2013-12-02 21:01:53 -0600 | [diff] [blame] | 4848 | if (surface->width == 0) |
Giulio Camuffo | 184df50 | 2013-02-21 11:29:21 +0100 | [diff] [blame] | 4849 | return; |
| 4850 | |
Jan Arne Petersen | 14da96b | 2013-04-18 16:47:28 +0200 | [diff] [blame] | 4851 | if (!weston_surface_is_mapped(surface)) { |
| 4852 | if (!shell->showing_input_panels) |
| 4853 | return; |
| 4854 | |
Jan Arne Petersen | 14da96b | 2013-04-18 16:47:28 +0200 | [diff] [blame] | 4855 | show_surface = 1; |
| 4856 | } |
Jan Arne Petersen | af7b6c9 | 2013-01-16 21:26:53 +0100 | [diff] [blame] | 4857 | |
Jan Arne Petersen | 7cd29e1 | 2013-04-18 16:47:29 +0200 | [diff] [blame] | 4858 | fprintf(stderr, "%s panel: %d, output: %p\n", __FUNCTION__, ip_surface->panel, ip_surface->output); |
Jan Arne Petersen | 14da96b | 2013-04-18 16:47:28 +0200 | [diff] [blame] | 4859 | |
| 4860 | if (ip_surface->panel) { |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 4861 | x = get_default_view(shell->text_input.surface)->geometry.x + shell->text_input.cursor_rectangle.x2; |
| 4862 | y = get_default_view(shell->text_input.surface)->geometry.y + shell->text_input.cursor_rectangle.y2; |
Jan Arne Petersen | 14da96b | 2013-04-18 16:47:28 +0200 | [diff] [blame] | 4863 | } else { |
Jason Ekstrand | 918f2dd | 2013-12-02 21:01:53 -0600 | [diff] [blame] | 4864 | x = ip_surface->output->x + (ip_surface->output->width - surface->width) / 2; |
| 4865 | y = ip_surface->output->y + ip_surface->output->height - surface->height; |
Jan Arne Petersen | 7cd29e1 | 2013-04-18 16:47:29 +0200 | [diff] [blame] | 4866 | } |
Kristian Høgsberg | 0636ac3 | 2012-06-27 10:22:15 -0400 | [diff] [blame] | 4867 | |
Jason Ekstrand | 918f2dd | 2013-12-02 21:01:53 -0600 | [diff] [blame] | 4868 | weston_view_set_position(ip_surface->view, x, y); |
Jan Arne Petersen | 14da96b | 2013-04-18 16:47:28 +0200 | [diff] [blame] | 4869 | |
| 4870 | if (show_surface) { |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 4871 | wl_list_insert(&shell->input_panel_layer.view_list, |
| 4872 | &ip_surface->view->layer_link); |
| 4873 | weston_view_update_transform(ip_surface->view); |
Jan Arne Petersen | 14da96b | 2013-04-18 16:47:28 +0200 | [diff] [blame] | 4874 | weston_surface_damage(surface); |
Jason Ekstrand | 918f2dd | 2013-12-02 21:01:53 -0600 | [diff] [blame] | 4875 | weston_slide_run(ip_surface->view, ip_surface->view->surface->height, 0, NULL, NULL); |
Jan Arne Petersen | 14da96b | 2013-04-18 16:47:28 +0200 | [diff] [blame] | 4876 | } |
Kristian Høgsberg | 0636ac3 | 2012-06-27 10:22:15 -0400 | [diff] [blame] | 4877 | } |
| 4878 | |
| 4879 | static void |
Jan Arne Petersen | ffbb20f | 2013-01-16 21:26:55 +0100 | [diff] [blame] | 4880 | destroy_input_panel_surface(struct input_panel_surface *input_panel_surface) |
Philipp Brüschweiler | 8801357 | 2012-08-06 13:44:42 +0200 | [diff] [blame] | 4881 | { |
Jason Ekstrand | 51e5b14 | 2013-06-14 10:07:58 -0500 | [diff] [blame] | 4882 | wl_signal_emit(&input_panel_surface->destroy_signal, input_panel_surface); |
| 4883 | |
Jan Arne Petersen | ffbb20f | 2013-01-16 21:26:55 +0100 | [diff] [blame] | 4884 | wl_list_remove(&input_panel_surface->surface_destroy_listener.link); |
Philipp Brüschweiler | 8801357 | 2012-08-06 13:44:42 +0200 | [diff] [blame] | 4885 | wl_list_remove(&input_panel_surface->link); |
| 4886 | |
Jan Arne Petersen | ffbb20f | 2013-01-16 21:26:55 +0100 | [diff] [blame] | 4887 | input_panel_surface->surface->configure = NULL; |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 4888 | weston_view_destroy(input_panel_surface->view); |
Jan Arne Petersen | ffbb20f | 2013-01-16 21:26:55 +0100 | [diff] [blame] | 4889 | |
Philipp Brüschweiler | 8801357 | 2012-08-06 13:44:42 +0200 | [diff] [blame] | 4890 | free(input_panel_surface); |
| 4891 | } |
| 4892 | |
Jan Arne Petersen | ffbb20f | 2013-01-16 21:26:55 +0100 | [diff] [blame] | 4893 | static struct input_panel_surface * |
| 4894 | get_input_panel_surface(struct weston_surface *surface) |
Jan Arne Petersen | 42feced | 2012-06-21 21:52:17 +0200 | [diff] [blame] | 4895 | { |
Jan Arne Petersen | ffbb20f | 2013-01-16 21:26:55 +0100 | [diff] [blame] | 4896 | if (surface->configure == input_panel_configure) { |
Giulio Camuffo | 7fe01b1 | 2013-03-28 18:02:42 +0100 | [diff] [blame] | 4897 | return surface->configure_private; |
Jan Arne Petersen | ffbb20f | 2013-01-16 21:26:55 +0100 | [diff] [blame] | 4898 | } else { |
| 4899 | return NULL; |
| 4900 | } |
| 4901 | } |
| 4902 | |
| 4903 | static void |
| 4904 | input_panel_handle_surface_destroy(struct wl_listener *listener, void *data) |
| 4905 | { |
| 4906 | struct input_panel_surface *ipsurface = container_of(listener, |
| 4907 | struct input_panel_surface, |
| 4908 | surface_destroy_listener); |
| 4909 | |
Jason Ekstrand | 51e5b14 | 2013-06-14 10:07:58 -0500 | [diff] [blame] | 4910 | if (ipsurface->resource) { |
| 4911 | wl_resource_destroy(ipsurface->resource); |
Jan Arne Petersen | ffbb20f | 2013-01-16 21:26:55 +0100 | [diff] [blame] | 4912 | } else { |
Jan Arne Petersen | ffbb20f | 2013-01-16 21:26:55 +0100 | [diff] [blame] | 4913 | destroy_input_panel_surface(ipsurface); |
| 4914 | } |
| 4915 | } |
Jason Ekstrand | 51e5b14 | 2013-06-14 10:07:58 -0500 | [diff] [blame] | 4916 | |
Jan Arne Petersen | ffbb20f | 2013-01-16 21:26:55 +0100 | [diff] [blame] | 4917 | static struct input_panel_surface * |
| 4918 | create_input_panel_surface(struct desktop_shell *shell, |
| 4919 | struct weston_surface *surface) |
| 4920 | { |
Philipp Brüschweiler | 8801357 | 2012-08-06 13:44:42 +0200 | [diff] [blame] | 4921 | struct input_panel_surface *input_panel_surface; |
Jan Arne Petersen | 42feced | 2012-06-21 21:52:17 +0200 | [diff] [blame] | 4922 | |
Jan Arne Petersen | ffbb20f | 2013-01-16 21:26:55 +0100 | [diff] [blame] | 4923 | input_panel_surface = calloc(1, sizeof *input_panel_surface); |
| 4924 | if (!input_panel_surface) |
| 4925 | return NULL; |
| 4926 | |
Kristian Høgsberg | 0636ac3 | 2012-06-27 10:22:15 -0400 | [diff] [blame] | 4927 | surface->configure = input_panel_configure; |
Giulio Camuffo | 7fe01b1 | 2013-03-28 18:02:42 +0100 | [diff] [blame] | 4928 | surface->configure_private = input_panel_surface; |
Philipp Brüschweiler | 8801357 | 2012-08-06 13:44:42 +0200 | [diff] [blame] | 4929 | |
Jan Arne Petersen | ffbb20f | 2013-01-16 21:26:55 +0100 | [diff] [blame] | 4930 | input_panel_surface->shell = shell; |
Philipp Brüschweiler | 8801357 | 2012-08-06 13:44:42 +0200 | [diff] [blame] | 4931 | |
| 4932 | input_panel_surface->surface = surface; |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 4933 | input_panel_surface->view = weston_view_create(surface); |
Philipp Brüschweiler | 8801357 | 2012-08-06 13:44:42 +0200 | [diff] [blame] | 4934 | |
Jason Ekstrand | 51e5b14 | 2013-06-14 10:07:58 -0500 | [diff] [blame] | 4935 | wl_signal_init(&input_panel_surface->destroy_signal); |
Jan Arne Petersen | ffbb20f | 2013-01-16 21:26:55 +0100 | [diff] [blame] | 4936 | input_panel_surface->surface_destroy_listener.notify = input_panel_handle_surface_destroy; |
Jason Ekstrand | 26ed73c | 2013-06-06 22:34:41 -0500 | [diff] [blame] | 4937 | wl_signal_add(&surface->destroy_signal, |
Jan Arne Petersen | ffbb20f | 2013-01-16 21:26:55 +0100 | [diff] [blame] | 4938 | &input_panel_surface->surface_destroy_listener); |
| 4939 | |
| 4940 | wl_list_init(&input_panel_surface->link); |
| 4941 | |
| 4942 | return input_panel_surface; |
| 4943 | } |
| 4944 | |
| 4945 | static void |
| 4946 | input_panel_surface_set_toplevel(struct wl_client *client, |
| 4947 | struct wl_resource *resource, |
Jan Arne Petersen | 7cd29e1 | 2013-04-18 16:47:29 +0200 | [diff] [blame] | 4948 | struct wl_resource *output_resource, |
Jan Arne Petersen | ffbb20f | 2013-01-16 21:26:55 +0100 | [diff] [blame] | 4949 | uint32_t position) |
| 4950 | { |
Jason Ekstrand | 51e5b14 | 2013-06-14 10:07:58 -0500 | [diff] [blame] | 4951 | struct input_panel_surface *input_panel_surface = |
| 4952 | wl_resource_get_user_data(resource); |
Jan Arne Petersen | ffbb20f | 2013-01-16 21:26:55 +0100 | [diff] [blame] | 4953 | struct desktop_shell *shell = input_panel_surface->shell; |
Philipp Brüschweiler | 8801357 | 2012-08-06 13:44:42 +0200 | [diff] [blame] | 4954 | |
| 4955 | wl_list_insert(&shell->input_panel.surfaces, |
| 4956 | &input_panel_surface->link); |
Jan Arne Petersen | 14da96b | 2013-04-18 16:47:28 +0200 | [diff] [blame] | 4957 | |
Jason Ekstrand | a0d2dde | 2013-06-14 10:08:01 -0500 | [diff] [blame] | 4958 | input_panel_surface->output = wl_resource_get_user_data(output_resource); |
Jan Arne Petersen | 14da96b | 2013-04-18 16:47:28 +0200 | [diff] [blame] | 4959 | input_panel_surface->panel = 0; |
| 4960 | } |
| 4961 | |
| 4962 | static void |
Jan Arne Petersen | 70d942b | 2013-04-18 16:47:37 +0200 | [diff] [blame] | 4963 | input_panel_surface_set_overlay_panel(struct wl_client *client, |
| 4964 | struct wl_resource *resource) |
Jan Arne Petersen | 14da96b | 2013-04-18 16:47:28 +0200 | [diff] [blame] | 4965 | { |
Jason Ekstrand | 51e5b14 | 2013-06-14 10:07:58 -0500 | [diff] [blame] | 4966 | struct input_panel_surface *input_panel_surface = |
| 4967 | wl_resource_get_user_data(resource); |
Jan Arne Petersen | 14da96b | 2013-04-18 16:47:28 +0200 | [diff] [blame] | 4968 | struct desktop_shell *shell = input_panel_surface->shell; |
| 4969 | |
| 4970 | wl_list_insert(&shell->input_panel.surfaces, |
| 4971 | &input_panel_surface->link); |
| 4972 | |
| 4973 | input_panel_surface->panel = 1; |
Jan Arne Petersen | 42feced | 2012-06-21 21:52:17 +0200 | [diff] [blame] | 4974 | } |
| 4975 | |
Jan Arne Petersen | cc75ec1 | 2013-04-18 16:47:39 +0200 | [diff] [blame] | 4976 | static const struct wl_input_panel_surface_interface input_panel_surface_implementation = { |
Jan Arne Petersen | 14da96b | 2013-04-18 16:47:28 +0200 | [diff] [blame] | 4977 | input_panel_surface_set_toplevel, |
Jan Arne Petersen | 70d942b | 2013-04-18 16:47:37 +0200 | [diff] [blame] | 4978 | input_panel_surface_set_overlay_panel |
Jan Arne Petersen | ffbb20f | 2013-01-16 21:26:55 +0100 | [diff] [blame] | 4979 | }; |
| 4980 | |
| 4981 | static void |
| 4982 | destroy_input_panel_surface_resource(struct wl_resource *resource) |
| 4983 | { |
Jason Ekstrand | 51e5b14 | 2013-06-14 10:07:58 -0500 | [diff] [blame] | 4984 | struct input_panel_surface *ipsurf = |
| 4985 | wl_resource_get_user_data(resource); |
Jan Arne Petersen | ffbb20f | 2013-01-16 21:26:55 +0100 | [diff] [blame] | 4986 | |
| 4987 | destroy_input_panel_surface(ipsurf); |
| 4988 | } |
| 4989 | |
| 4990 | static void |
| 4991 | input_panel_get_input_panel_surface(struct wl_client *client, |
| 4992 | struct wl_resource *resource, |
| 4993 | uint32_t id, |
| 4994 | struct wl_resource *surface_resource) |
| 4995 | { |
Jason Ekstrand | 0f2ef7e | 2013-06-14 10:07:53 -0500 | [diff] [blame] | 4996 | struct weston_surface *surface = |
| 4997 | wl_resource_get_user_data(surface_resource); |
Jason Ekstrand | 651f00e | 2013-06-14 10:07:54 -0500 | [diff] [blame] | 4998 | struct desktop_shell *shell = wl_resource_get_user_data(resource); |
Jan Arne Petersen | ffbb20f | 2013-01-16 21:26:55 +0100 | [diff] [blame] | 4999 | struct input_panel_surface *ipsurf; |
| 5000 | |
| 5001 | if (get_input_panel_surface(surface)) { |
| 5002 | wl_resource_post_error(surface_resource, |
| 5003 | WL_DISPLAY_ERROR_INVALID_OBJECT, |
Jan Arne Petersen | cc75ec1 | 2013-04-18 16:47:39 +0200 | [diff] [blame] | 5004 | "wl_input_panel::get_input_panel_surface already requested"); |
Jan Arne Petersen | ffbb20f | 2013-01-16 21:26:55 +0100 | [diff] [blame] | 5005 | return; |
| 5006 | } |
| 5007 | |
| 5008 | ipsurf = create_input_panel_surface(shell, surface); |
| 5009 | if (!ipsurf) { |
| 5010 | wl_resource_post_error(surface_resource, |
| 5011 | WL_DISPLAY_ERROR_INVALID_OBJECT, |
| 5012 | "surface->configure already set"); |
| 5013 | return; |
| 5014 | } |
| 5015 | |
Jason Ekstrand | a85118c | 2013-06-27 20:17:02 -0500 | [diff] [blame] | 5016 | ipsurf->resource = |
| 5017 | wl_resource_create(client, |
| 5018 | &wl_input_panel_surface_interface, 1, id); |
| 5019 | wl_resource_set_implementation(ipsurf->resource, |
| 5020 | &input_panel_surface_implementation, |
| 5021 | ipsurf, |
| 5022 | destroy_input_panel_surface_resource); |
Jan Arne Petersen | ffbb20f | 2013-01-16 21:26:55 +0100 | [diff] [blame] | 5023 | } |
| 5024 | |
Jan Arne Petersen | cc75ec1 | 2013-04-18 16:47:39 +0200 | [diff] [blame] | 5025 | static const struct wl_input_panel_interface input_panel_implementation = { |
Jan Arne Petersen | ffbb20f | 2013-01-16 21:26:55 +0100 | [diff] [blame] | 5026 | input_panel_get_input_panel_surface |
Jan Arne Petersen | 42feced | 2012-06-21 21:52:17 +0200 | [diff] [blame] | 5027 | }; |
| 5028 | |
| 5029 | static void |
| 5030 | unbind_input_panel(struct wl_resource *resource) |
| 5031 | { |
Jason Ekstrand | 651f00e | 2013-06-14 10:07:54 -0500 | [diff] [blame] | 5032 | struct desktop_shell *shell = wl_resource_get_user_data(resource); |
Jan Arne Petersen | 42feced | 2012-06-21 21:52:17 +0200 | [diff] [blame] | 5033 | |
| 5034 | shell->input_panel.binding = NULL; |
Jan Arne Petersen | 42feced | 2012-06-21 21:52:17 +0200 | [diff] [blame] | 5035 | } |
| 5036 | |
| 5037 | static void |
| 5038 | bind_input_panel(struct wl_client *client, |
| 5039 | void *data, uint32_t version, uint32_t id) |
| 5040 | { |
| 5041 | struct desktop_shell *shell = data; |
| 5042 | struct wl_resource *resource; |
| 5043 | |
Jason Ekstrand | a85118c | 2013-06-27 20:17:02 -0500 | [diff] [blame] | 5044 | resource = wl_resource_create(client, |
| 5045 | &wl_input_panel_interface, 1, id); |
Jan Arne Petersen | 42feced | 2012-06-21 21:52:17 +0200 | [diff] [blame] | 5046 | |
| 5047 | if (shell->input_panel.binding == NULL) { |
Jason Ekstrand | a85118c | 2013-06-27 20:17:02 -0500 | [diff] [blame] | 5048 | wl_resource_set_implementation(resource, |
| 5049 | &input_panel_implementation, |
| 5050 | shell, unbind_input_panel); |
Jan Arne Petersen | 42feced | 2012-06-21 21:52:17 +0200 | [diff] [blame] | 5051 | shell->input_panel.binding = resource; |
| 5052 | return; |
| 5053 | } |
| 5054 | |
| 5055 | wl_resource_post_error(resource, WL_DISPLAY_ERROR_INVALID_OBJECT, |
| 5056 | "interface object already bound"); |
| 5057 | wl_resource_destroy(resource); |
| 5058 | } |
| 5059 | |
Kristian Høgsberg | 0704539 | 2012-02-19 18:52:44 -0500 | [diff] [blame] | 5060 | struct switcher { |
Tiago Vignatti | be14326 | 2012-04-16 17:31:41 +0300 | [diff] [blame] | 5061 | struct desktop_shell *shell; |
Kristian Høgsberg | 0704539 | 2012-02-19 18:52:44 -0500 | [diff] [blame] | 5062 | struct weston_surface *current; |
| 5063 | struct wl_listener listener; |
Kristian Høgsberg | 29139d4 | 2013-04-18 15:25:39 -0400 | [diff] [blame] | 5064 | struct weston_keyboard_grab grab; |
Kristian Høgsberg | 0704539 | 2012-02-19 18:52:44 -0500 | [diff] [blame] | 5065 | }; |
| 5066 | |
| 5067 | static void |
| 5068 | switcher_next(struct switcher *switcher) |
| 5069 | { |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 5070 | struct weston_view *view; |
Kristian Høgsberg | 0704539 | 2012-02-19 18:52:44 -0500 | [diff] [blame] | 5071 | struct weston_surface *first = NULL, *prev = NULL, *next = NULL; |
Kristian Høgsberg | 32e5686 | 2012-04-02 22:18:58 -0400 | [diff] [blame] | 5072 | struct shell_surface *shsurf; |
Kristian Høgsberg | b0d8e77 | 2012-06-18 16:34:58 -0400 | [diff] [blame] | 5073 | struct workspace *ws = get_current_workspace(switcher->shell); |
Kristian Høgsberg | 0704539 | 2012-02-19 18:52:44 -0500 | [diff] [blame] | 5074 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 5075 | wl_list_for_each(view, &ws->layer.view_list, layer_link) { |
Rafael Antognolli | ed207b4 | 2013-12-03 15:35:43 -0200 | [diff] [blame^] | 5076 | shsurf = get_shell_surface(view->surface); |
| 5077 | switch (shsurf->type) { |
Kristian Høgsberg | 0704539 | 2012-02-19 18:52:44 -0500 | [diff] [blame] | 5078 | case SHELL_SURFACE_TOPLEVEL: |
Rafael Antognolli | ed207b4 | 2013-12-03 15:35:43 -0200 | [diff] [blame^] | 5079 | if (shsurf->parent) |
| 5080 | break; |
Kristian Høgsberg | 0704539 | 2012-02-19 18:52:44 -0500 | [diff] [blame] | 5081 | if (first == NULL) |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 5082 | first = view->surface; |
Kristian Høgsberg | 0704539 | 2012-02-19 18:52:44 -0500 | [diff] [blame] | 5083 | if (prev == switcher->current) |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 5084 | next = view->surface; |
| 5085 | prev = view->surface; |
| 5086 | view->alpha = 0.25; |
| 5087 | weston_view_geometry_dirty(view); |
| 5088 | weston_surface_damage(view->surface); |
Kristian Høgsberg | 0704539 | 2012-02-19 18:52:44 -0500 | [diff] [blame] | 5089 | break; |
Philip Withnall | 0f640e2 | 2013-11-25 18:01:31 +0000 | [diff] [blame] | 5090 | case SHELL_SURFACE_POPUP: |
| 5091 | case SHELL_SURFACE_XWAYLAND: |
| 5092 | case SHELL_SURFACE_NONE: |
Kristian Høgsberg | 0704539 | 2012-02-19 18:52:44 -0500 | [diff] [blame] | 5093 | default: |
| 5094 | break; |
| 5095 | } |
Alex Wu | 1659daa | 2012-04-01 20:13:09 +0800 | [diff] [blame] | 5096 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 5097 | if (is_black_surface(view->surface, NULL)) { |
| 5098 | view->alpha = 0.25; |
| 5099 | weston_view_geometry_dirty(view); |
| 5100 | weston_surface_damage(view->surface); |
Alex Wu | 1659daa | 2012-04-01 20:13:09 +0800 | [diff] [blame] | 5101 | } |
Kristian Høgsberg | 0704539 | 2012-02-19 18:52:44 -0500 | [diff] [blame] | 5102 | } |
| 5103 | |
| 5104 | if (next == NULL) |
| 5105 | next = first; |
| 5106 | |
Alex Wu | 07b2606 | 2012-03-12 16:06:01 +0800 | [diff] [blame] | 5107 | if (next == NULL) |
| 5108 | return; |
| 5109 | |
Kristian Høgsberg | 0704539 | 2012-02-19 18:52:44 -0500 | [diff] [blame] | 5110 | wl_list_remove(&switcher->listener.link); |
Jason Ekstrand | 26ed73c | 2013-06-06 22:34:41 -0500 | [diff] [blame] | 5111 | wl_signal_add(&next->destroy_signal, &switcher->listener); |
Kristian Høgsberg | 0704539 | 2012-02-19 18:52:44 -0500 | [diff] [blame] | 5112 | |
| 5113 | switcher->current = next; |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 5114 | wl_list_for_each(view, &next->views, surface_link) |
| 5115 | view->alpha = 1.0; |
Alex Wu | 1659daa | 2012-04-01 20:13:09 +0800 | [diff] [blame] | 5116 | |
Kristian Høgsberg | 32e5686 | 2012-04-02 22:18:58 -0400 | [diff] [blame] | 5117 | shsurf = get_shell_surface(switcher->current); |
Rafael Antognolli | 03b1659 | 2013-12-03 15:35:42 -0200 | [diff] [blame] | 5118 | if (shsurf && shsurf->state.fullscreen) |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 5119 | shsurf->fullscreen.black_view->alpha = 1.0; |
Kristian Høgsberg | 0704539 | 2012-02-19 18:52:44 -0500 | [diff] [blame] | 5120 | } |
| 5121 | |
| 5122 | static void |
Kristian Høgsberg | 27e3052 | 2012-04-11 23:18:23 -0400 | [diff] [blame] | 5123 | switcher_handle_surface_destroy(struct wl_listener *listener, void *data) |
Kristian Høgsberg | 0704539 | 2012-02-19 18:52:44 -0500 | [diff] [blame] | 5124 | { |
| 5125 | struct switcher *switcher = |
| 5126 | container_of(listener, struct switcher, listener); |
| 5127 | |
| 5128 | switcher_next(switcher); |
| 5129 | } |
| 5130 | |
| 5131 | static void |
Daniel Stone | 351eb61 | 2012-05-31 15:27:47 -0400 | [diff] [blame] | 5132 | switcher_destroy(struct switcher *switcher) |
Kristian Høgsberg | 0704539 | 2012-02-19 18:52:44 -0500 | [diff] [blame] | 5133 | { |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 5134 | struct weston_view *view; |
Kristian Høgsberg | 29139d4 | 2013-04-18 15:25:39 -0400 | [diff] [blame] | 5135 | struct weston_keyboard *keyboard = switcher->grab.keyboard; |
Kristian Høgsberg | b0d8e77 | 2012-06-18 16:34:58 -0400 | [diff] [blame] | 5136 | struct workspace *ws = get_current_workspace(switcher->shell); |
Kristian Høgsberg | 0704539 | 2012-02-19 18:52:44 -0500 | [diff] [blame] | 5137 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 5138 | 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] | 5139 | if (is_focus_view(view)) |
| 5140 | continue; |
| 5141 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 5142 | view->alpha = 1.0; |
| 5143 | weston_surface_damage(view->surface); |
Kristian Høgsberg | 0704539 | 2012-02-19 18:52:44 -0500 | [diff] [blame] | 5144 | } |
| 5145 | |
Alex Wu | 07b2606 | 2012-03-12 16:06:01 +0800 | [diff] [blame] | 5146 | if (switcher->current) |
Daniel Stone | 37816df | 2012-05-16 18:45:18 +0100 | [diff] [blame] | 5147 | activate(switcher->shell, switcher->current, |
| 5148 | (struct weston_seat *) keyboard->seat); |
Kristian Høgsberg | 0704539 | 2012-02-19 18:52:44 -0500 | [diff] [blame] | 5149 | wl_list_remove(&switcher->listener.link); |
Kristian Høgsberg | 29139d4 | 2013-04-18 15:25:39 -0400 | [diff] [blame] | 5150 | weston_keyboard_end_grab(keyboard); |
| 5151 | if (keyboard->input_method_resource) |
| 5152 | keyboard->grab = &keyboard->input_method_grab; |
Kristian Høgsberg | 0704539 | 2012-02-19 18:52:44 -0500 | [diff] [blame] | 5153 | free(switcher); |
| 5154 | } |
| 5155 | |
| 5156 | static void |
Kristian Høgsberg | 29139d4 | 2013-04-18 15:25:39 -0400 | [diff] [blame] | 5157 | switcher_key(struct weston_keyboard_grab *grab, |
Daniel Stone | c9785ea | 2012-05-30 16:31:52 +0100 | [diff] [blame] | 5158 | uint32_t time, uint32_t key, uint32_t state_w) |
Kristian Høgsberg | 0704539 | 2012-02-19 18:52:44 -0500 | [diff] [blame] | 5159 | { |
| 5160 | struct switcher *switcher = container_of(grab, struct switcher, grab); |
Daniel Stone | c9785ea | 2012-05-30 16:31:52 +0100 | [diff] [blame] | 5161 | enum wl_keyboard_key_state state = state_w; |
Daniel Stone | 351eb61 | 2012-05-31 15:27:47 -0400 | [diff] [blame] | 5162 | |
Daniel Stone | c9785ea | 2012-05-30 16:31:52 +0100 | [diff] [blame] | 5163 | if (key == KEY_TAB && state == WL_KEYBOARD_KEY_STATE_PRESSED) |
Daniel Stone | 351eb61 | 2012-05-31 15:27:47 -0400 | [diff] [blame] | 5164 | switcher_next(switcher); |
| 5165 | } |
| 5166 | |
| 5167 | static void |
Kristian Høgsberg | 29139d4 | 2013-04-18 15:25:39 -0400 | [diff] [blame] | 5168 | switcher_modifier(struct weston_keyboard_grab *grab, uint32_t serial, |
Daniel Stone | 351eb61 | 2012-05-31 15:27:47 -0400 | [diff] [blame] | 5169 | uint32_t mods_depressed, uint32_t mods_latched, |
| 5170 | uint32_t mods_locked, uint32_t group) |
| 5171 | { |
| 5172 | struct switcher *switcher = container_of(grab, struct switcher, grab); |
Daniel Stone | 37816df | 2012-05-16 18:45:18 +0100 | [diff] [blame] | 5173 | struct weston_seat *seat = (struct weston_seat *) grab->keyboard->seat; |
Kristian Høgsberg | 0704539 | 2012-02-19 18:52:44 -0500 | [diff] [blame] | 5174 | |
Daniel Stone | 351eb61 | 2012-05-31 15:27:47 -0400 | [diff] [blame] | 5175 | if ((seat->modifier_state & switcher->shell->binding_modifier) == 0) |
| 5176 | switcher_destroy(switcher); |
Kristian Høgsberg | b71302e | 2012-05-10 12:28:35 -0400 | [diff] [blame] | 5177 | } |
Kristian Høgsberg | 0704539 | 2012-02-19 18:52:44 -0500 | [diff] [blame] | 5178 | |
Jonas Ådahl | 1ea343e | 2013-10-25 23:18:05 +0200 | [diff] [blame] | 5179 | static void |
| 5180 | switcher_cancel(struct weston_keyboard_grab *grab) |
| 5181 | { |
| 5182 | struct switcher *switcher = container_of(grab, struct switcher, grab); |
| 5183 | |
| 5184 | switcher_destroy(switcher); |
| 5185 | } |
| 5186 | |
Kristian Høgsberg | 29139d4 | 2013-04-18 15:25:39 -0400 | [diff] [blame] | 5187 | static const struct weston_keyboard_grab_interface switcher_grab = { |
Daniel Stone | 351eb61 | 2012-05-31 15:27:47 -0400 | [diff] [blame] | 5188 | switcher_key, |
| 5189 | switcher_modifier, |
Jonas Ådahl | 1ea343e | 2013-10-25 23:18:05 +0200 | [diff] [blame] | 5190 | switcher_cancel, |
Kristian Høgsberg | 0704539 | 2012-02-19 18:52:44 -0500 | [diff] [blame] | 5191 | }; |
| 5192 | |
| 5193 | static void |
Kristian Høgsberg | e314875 | 2013-05-06 23:19:49 -0400 | [diff] [blame] | 5194 | switcher_binding(struct weston_seat *seat, uint32_t time, uint32_t key, |
Daniel Stone | 325fc2d | 2012-05-30 16:31:58 +0100 | [diff] [blame] | 5195 | void *data) |
Kristian Høgsberg | 0704539 | 2012-02-19 18:52:44 -0500 | [diff] [blame] | 5196 | { |
Tiago Vignatti | be14326 | 2012-04-16 17:31:41 +0300 | [diff] [blame] | 5197 | struct desktop_shell *shell = data; |
Kristian Høgsberg | 0704539 | 2012-02-19 18:52:44 -0500 | [diff] [blame] | 5198 | struct switcher *switcher; |
| 5199 | |
| 5200 | switcher = malloc(sizeof *switcher); |
Kristian Høgsberg | 02e79dc | 2012-04-12 09:55:26 -0400 | [diff] [blame] | 5201 | switcher->shell = shell; |
Kristian Høgsberg | 0704539 | 2012-02-19 18:52:44 -0500 | [diff] [blame] | 5202 | switcher->current = NULL; |
Kristian Høgsberg | 27e3052 | 2012-04-11 23:18:23 -0400 | [diff] [blame] | 5203 | switcher->listener.notify = switcher_handle_surface_destroy; |
Kristian Høgsberg | 0704539 | 2012-02-19 18:52:44 -0500 | [diff] [blame] | 5204 | wl_list_init(&switcher->listener.link); |
| 5205 | |
Alexander Larsson | f82b6ca | 2013-05-28 16:23:39 +0200 | [diff] [blame] | 5206 | restore_all_output_modes(shell->compositor); |
Kristian Høgsberg | b0d8e77 | 2012-06-18 16:34:58 -0400 | [diff] [blame] | 5207 | lower_fullscreen_layer(switcher->shell); |
Kristian Høgsberg | 0704539 | 2012-02-19 18:52:44 -0500 | [diff] [blame] | 5208 | switcher->grab.interface = &switcher_grab; |
Kristian Høgsberg | 29139d4 | 2013-04-18 15:25:39 -0400 | [diff] [blame] | 5209 | weston_keyboard_start_grab(seat->keyboard, &switcher->grab); |
| 5210 | weston_keyboard_set_focus(seat->keyboard, NULL); |
Kristian Høgsberg | 0704539 | 2012-02-19 18:52:44 -0500 | [diff] [blame] | 5211 | switcher_next(switcher); |
| 5212 | } |
| 5213 | |
Daniel Stone | df8133b | 2013-11-19 11:37:14 +0100 | [diff] [blame] | 5214 | struct exposay_surface { |
| 5215 | struct desktop_shell *shell; |
| 5216 | struct weston_surface *surface; |
| 5217 | struct weston_view *view; |
| 5218 | struct wl_list link; |
| 5219 | |
| 5220 | int x; |
| 5221 | int y; |
| 5222 | int width; |
| 5223 | int height; |
| 5224 | double scale; |
| 5225 | |
| 5226 | int row; |
| 5227 | int column; |
| 5228 | |
| 5229 | /* The animations only apply a transformation for their own lifetime, |
| 5230 | * and don't have an option to indefinitely maintain the |
| 5231 | * transformation in a steady state - so, we apply our own once the |
| 5232 | * animation has finished. */ |
| 5233 | struct weston_transform transform; |
| 5234 | }; |
| 5235 | |
| 5236 | static void exposay_set_state(struct desktop_shell *shell, |
| 5237 | enum exposay_target_state state, |
| 5238 | struct weston_seat *seat); |
| 5239 | static void exposay_check_state(struct desktop_shell *shell); |
| 5240 | |
| 5241 | static void |
| 5242 | exposay_in_flight_inc(struct desktop_shell *shell) |
| 5243 | { |
| 5244 | shell->exposay.in_flight++; |
| 5245 | } |
| 5246 | |
| 5247 | static void |
| 5248 | exposay_in_flight_dec(struct desktop_shell *shell) |
| 5249 | { |
| 5250 | if (--shell->exposay.in_flight > 0) |
| 5251 | return; |
| 5252 | |
| 5253 | exposay_check_state(shell); |
| 5254 | } |
| 5255 | |
| 5256 | static void |
| 5257 | exposay_animate_in_done(struct weston_view_animation *animation, void *data) |
| 5258 | { |
| 5259 | struct exposay_surface *esurface = data; |
| 5260 | |
| 5261 | wl_list_insert(&esurface->view->geometry.transformation_list, |
| 5262 | &esurface->transform.link); |
| 5263 | weston_matrix_init(&esurface->transform.matrix); |
| 5264 | weston_matrix_scale(&esurface->transform.matrix, |
| 5265 | esurface->scale, esurface->scale, 1.0f); |
| 5266 | weston_matrix_translate(&esurface->transform.matrix, |
| 5267 | esurface->x - esurface->view->geometry.x, |
| 5268 | esurface->y - esurface->view->geometry.y, |
| 5269 | 0); |
| 5270 | |
| 5271 | weston_view_geometry_dirty(esurface->view); |
| 5272 | weston_compositor_schedule_repaint(esurface->view->surface->compositor); |
| 5273 | |
| 5274 | exposay_in_flight_dec(esurface->shell); |
| 5275 | } |
| 5276 | |
| 5277 | static void |
| 5278 | exposay_animate_in(struct exposay_surface *esurface) |
| 5279 | { |
| 5280 | exposay_in_flight_inc(esurface->shell); |
| 5281 | |
| 5282 | weston_move_scale_run(esurface->view, |
| 5283 | esurface->x - esurface->view->geometry.x, |
| 5284 | esurface->y - esurface->view->geometry.y, |
| 5285 | 1.0, esurface->scale, 0, |
| 5286 | exposay_animate_in_done, esurface); |
| 5287 | } |
| 5288 | |
| 5289 | static void |
| 5290 | exposay_animate_out_done(struct weston_view_animation *animation, void *data) |
| 5291 | { |
| 5292 | struct exposay_surface *esurface = data; |
| 5293 | struct desktop_shell *shell = esurface->shell; |
| 5294 | |
| 5295 | wl_list_remove(&esurface->link); |
| 5296 | free(esurface); |
| 5297 | |
| 5298 | exposay_in_flight_dec(shell); |
| 5299 | } |
| 5300 | |
| 5301 | static void |
| 5302 | exposay_animate_out(struct exposay_surface *esurface) |
| 5303 | { |
| 5304 | exposay_in_flight_inc(esurface->shell); |
| 5305 | |
| 5306 | /* Remove the static transformation set up by |
| 5307 | * exposay_transform_in_done(). */ |
| 5308 | wl_list_remove(&esurface->transform.link); |
| 5309 | weston_view_geometry_dirty(esurface->view); |
| 5310 | |
| 5311 | weston_move_scale_run(esurface->view, |
| 5312 | esurface->x - esurface->view->geometry.x, |
| 5313 | esurface->y - esurface->view->geometry.y, |
| 5314 | 1.0, esurface->scale, 1, |
| 5315 | exposay_animate_out_done, esurface); |
| 5316 | } |
| 5317 | |
| 5318 | static void |
| 5319 | exposay_highlight_surface(struct desktop_shell *shell, |
| 5320 | struct exposay_surface *esurface) |
| 5321 | { |
| 5322 | struct weston_view *view = NULL; |
| 5323 | |
| 5324 | if (esurface) { |
| 5325 | shell->exposay.row_current = esurface->row; |
| 5326 | shell->exposay.column_current = esurface->column; |
| 5327 | view = esurface->view; |
| 5328 | } |
| 5329 | |
Emilio Pozuelo Monfort | 5c22ce6 | 2013-11-19 11:37:18 +0100 | [diff] [blame] | 5330 | activate(shell, view->surface, shell->exposay.seat); |
Daniel Stone | df8133b | 2013-11-19 11:37:14 +0100 | [diff] [blame] | 5331 | shell->exposay.focus_current = view; |
| 5332 | } |
| 5333 | |
| 5334 | static int |
| 5335 | exposay_is_animating(struct desktop_shell *shell) |
| 5336 | { |
| 5337 | if (shell->exposay.state_cur == EXPOSAY_LAYOUT_INACTIVE || |
| 5338 | shell->exposay.state_cur == EXPOSAY_LAYOUT_OVERVIEW) |
| 5339 | return 0; |
| 5340 | |
| 5341 | return (shell->exposay.in_flight > 0); |
| 5342 | } |
| 5343 | |
| 5344 | static void |
| 5345 | exposay_pick(struct desktop_shell *shell, int x, int y) |
| 5346 | { |
| 5347 | struct exposay_surface *esurface; |
| 5348 | |
| 5349 | if (exposay_is_animating(shell)) |
| 5350 | return; |
| 5351 | |
| 5352 | wl_list_for_each(esurface, &shell->exposay.surface_list, link) { |
| 5353 | if (x < esurface->x || x > esurface->x + esurface->width) |
| 5354 | continue; |
| 5355 | if (y < esurface->y || y > esurface->y + esurface->height) |
| 5356 | continue; |
| 5357 | |
| 5358 | exposay_highlight_surface(shell, esurface); |
| 5359 | return; |
| 5360 | } |
| 5361 | } |
| 5362 | |
| 5363 | /* Pretty lame layout for now; just tries to make a square. Should take |
| 5364 | * aspect ratio into account really. Also needs to be notified of surface |
| 5365 | * addition and removal and adjust layout/animate accordingly. */ |
| 5366 | static enum exposay_layout_state |
| 5367 | exposay_layout(struct desktop_shell *shell) |
| 5368 | { |
| 5369 | struct workspace *workspace = shell->exposay.workspace; |
| 5370 | struct weston_compositor *compositor = shell->compositor; |
| 5371 | struct weston_output *output = get_default_output(compositor); |
| 5372 | struct weston_view *view; |
| 5373 | struct exposay_surface *esurface; |
| 5374 | int w, h; |
| 5375 | int i; |
| 5376 | int last_row_removed = 0; |
| 5377 | |
| 5378 | wl_list_init(&shell->exposay.surface_list); |
| 5379 | |
| 5380 | shell->exposay.num_surfaces = 0; |
| 5381 | wl_list_for_each(view, &workspace->layer.view_list, layer_link) { |
| 5382 | if (!get_shell_surface(view->surface)) |
| 5383 | continue; |
| 5384 | shell->exposay.num_surfaces++; |
| 5385 | } |
| 5386 | |
| 5387 | if (shell->exposay.num_surfaces == 0) { |
| 5388 | shell->exposay.grid_size = 0; |
| 5389 | shell->exposay.hpadding_outer = 0; |
| 5390 | shell->exposay.vpadding_outer = 0; |
| 5391 | shell->exposay.padding_inner = 0; |
| 5392 | shell->exposay.surface_size = 0; |
| 5393 | return EXPOSAY_LAYOUT_OVERVIEW; |
| 5394 | } |
| 5395 | |
| 5396 | /* Lay the grid out as square as possible, losing surfaces from the |
| 5397 | * bottom row if required. Start with fixed padding of a 10% margin |
| 5398 | * around the outside and 80px internal padding between surfaces, and |
| 5399 | * maximise the area made available to surfaces after this, but only |
| 5400 | * to a maximum of 1/3rd the total output size. |
| 5401 | * |
| 5402 | * If we can't make a square grid, add one extra row at the bottom |
| 5403 | * which will have a smaller number of columns. |
| 5404 | * |
| 5405 | * XXX: Surely there has to be a better way to express this maths, |
| 5406 | * right?! |
| 5407 | */ |
| 5408 | shell->exposay.grid_size = floor(sqrtf(shell->exposay.num_surfaces)); |
| 5409 | if (pow(shell->exposay.grid_size, 2) != shell->exposay.num_surfaces) |
| 5410 | shell->exposay.grid_size++; |
| 5411 | last_row_removed = pow(shell->exposay.grid_size, 2) - shell->exposay.num_surfaces; |
| 5412 | |
| 5413 | shell->exposay.hpadding_outer = (output->width / 10); |
| 5414 | shell->exposay.vpadding_outer = (output->height / 10); |
| 5415 | shell->exposay.padding_inner = 80; |
| 5416 | |
| 5417 | w = output->width - (shell->exposay.hpadding_outer * 2); |
| 5418 | w -= shell->exposay.padding_inner * (shell->exposay.grid_size - 1); |
| 5419 | w /= shell->exposay.grid_size; |
| 5420 | |
| 5421 | h = output->height - (shell->exposay.vpadding_outer * 2); |
| 5422 | h -= shell->exposay.padding_inner * (shell->exposay.grid_size - 1); |
| 5423 | h /= shell->exposay.grid_size; |
| 5424 | |
| 5425 | shell->exposay.surface_size = (w < h) ? w : h; |
| 5426 | if (shell->exposay.surface_size > (output->width / 2)) |
| 5427 | shell->exposay.surface_size = output->width / 2; |
| 5428 | if (shell->exposay.surface_size > (output->height / 2)) |
| 5429 | shell->exposay.surface_size = output->height / 2; |
| 5430 | |
| 5431 | i = 0; |
| 5432 | wl_list_for_each(view, &workspace->layer.view_list, layer_link) { |
| 5433 | int pad; |
| 5434 | |
| 5435 | pad = shell->exposay.surface_size + shell->exposay.padding_inner; |
| 5436 | |
| 5437 | if (!get_shell_surface(view->surface)) |
| 5438 | continue; |
| 5439 | |
| 5440 | esurface = malloc(sizeof(*esurface)); |
| 5441 | if (!esurface) { |
| 5442 | exposay_set_state(shell, EXPOSAY_TARGET_CANCEL, |
| 5443 | shell->exposay.seat); |
| 5444 | break; |
| 5445 | } |
| 5446 | |
| 5447 | wl_list_insert(&shell->exposay.surface_list, &esurface->link); |
| 5448 | esurface->shell = shell; |
| 5449 | esurface->view = view; |
| 5450 | |
| 5451 | esurface->row = i / shell->exposay.grid_size; |
| 5452 | esurface->column = i % shell->exposay.grid_size; |
| 5453 | |
| 5454 | esurface->x = shell->exposay.hpadding_outer; |
| 5455 | esurface->x += pad * esurface->column; |
| 5456 | esurface->y = shell->exposay.vpadding_outer; |
| 5457 | esurface->y += pad * esurface->row; |
| 5458 | |
| 5459 | if (esurface->row == shell->exposay.grid_size - 1) |
| 5460 | esurface->x += (shell->exposay.surface_size + shell->exposay.padding_inner) * last_row_removed / 2; |
| 5461 | |
Jason Ekstrand | 918f2dd | 2013-12-02 21:01:53 -0600 | [diff] [blame] | 5462 | if (view->surface->width > view->surface->height) |
| 5463 | esurface->scale = shell->exposay.surface_size / (float) view->surface->width; |
Daniel Stone | df8133b | 2013-11-19 11:37:14 +0100 | [diff] [blame] | 5464 | else |
Jason Ekstrand | 918f2dd | 2013-12-02 21:01:53 -0600 | [diff] [blame] | 5465 | esurface->scale = shell->exposay.surface_size / (float) view->surface->height; |
| 5466 | esurface->width = view->surface->width * esurface->scale; |
| 5467 | esurface->height = view->surface->height * esurface->scale; |
Daniel Stone | df8133b | 2013-11-19 11:37:14 +0100 | [diff] [blame] | 5468 | |
| 5469 | if (shell->exposay.focus_current == esurface->view) |
| 5470 | exposay_highlight_surface(shell, esurface); |
| 5471 | |
| 5472 | exposay_animate_in(esurface); |
| 5473 | |
| 5474 | i++; |
| 5475 | } |
| 5476 | |
| 5477 | weston_compositor_schedule_repaint(shell->compositor); |
| 5478 | |
| 5479 | return EXPOSAY_LAYOUT_ANIMATE_TO_OVERVIEW; |
| 5480 | } |
| 5481 | |
| 5482 | static void |
Emilio Pozuelo Monfort | 17467d6 | 2013-11-19 12:14:53 +0100 | [diff] [blame] | 5483 | exposay_motion(struct weston_pointer_grab *grab, uint32_t time, |
| 5484 | wl_fixed_t x, wl_fixed_t y) |
Daniel Stone | df8133b | 2013-11-19 11:37:14 +0100 | [diff] [blame] | 5485 | { |
| 5486 | struct desktop_shell *shell = |
| 5487 | container_of(grab, struct desktop_shell, exposay.grab_ptr); |
| 5488 | |
Emilio Pozuelo Monfort | 17467d6 | 2013-11-19 12:14:53 +0100 | [diff] [blame] | 5489 | weston_pointer_move(grab->pointer, x, y); |
| 5490 | |
Daniel Stone | df8133b | 2013-11-19 11:37:14 +0100 | [diff] [blame] | 5491 | exposay_pick(shell, |
| 5492 | wl_fixed_to_int(grab->pointer->x), |
| 5493 | wl_fixed_to_int(grab->pointer->y)); |
| 5494 | } |
| 5495 | |
| 5496 | static void |
| 5497 | exposay_button(struct weston_pointer_grab *grab, uint32_t time, uint32_t button, |
| 5498 | uint32_t state_w) |
| 5499 | { |
| 5500 | struct desktop_shell *shell = |
| 5501 | container_of(grab, struct desktop_shell, exposay.grab_ptr); |
| 5502 | struct weston_seat *seat = grab->pointer->seat; |
| 5503 | enum wl_pointer_button_state state = state_w; |
| 5504 | |
| 5505 | if (button != BTN_LEFT) |
| 5506 | return; |
| 5507 | |
| 5508 | /* Store the surface we clicked on, and don't do anything if we end up |
| 5509 | * releasing on a different surface. */ |
| 5510 | if (state == WL_POINTER_BUTTON_STATE_PRESSED) { |
| 5511 | shell->exposay.clicked = shell->exposay.focus_current; |
| 5512 | return; |
| 5513 | } |
| 5514 | |
| 5515 | if (shell->exposay.focus_current == shell->exposay.clicked) |
| 5516 | exposay_set_state(shell, EXPOSAY_TARGET_SWITCH, seat); |
| 5517 | else |
| 5518 | shell->exposay.clicked = NULL; |
| 5519 | } |
| 5520 | |
Emilio Pozuelo Monfort | 234c524 | 2013-11-26 13:32:08 +0100 | [diff] [blame] | 5521 | static void |
| 5522 | exposay_pointer_grab_cancel(struct weston_pointer_grab *grab) |
| 5523 | { |
| 5524 | struct desktop_shell *shell = |
| 5525 | container_of(grab, struct desktop_shell, exposay.grab_ptr); |
| 5526 | |
| 5527 | exposay_set_state(shell, EXPOSAY_TARGET_CANCEL, shell->exposay.seat); |
| 5528 | } |
| 5529 | |
Daniel Stone | df8133b | 2013-11-19 11:37:14 +0100 | [diff] [blame] | 5530 | static const struct weston_pointer_grab_interface exposay_ptr_grab = { |
| 5531 | noop_grab_focus, |
| 5532 | exposay_motion, |
| 5533 | exposay_button, |
Emilio Pozuelo Monfort | 234c524 | 2013-11-26 13:32:08 +0100 | [diff] [blame] | 5534 | exposay_pointer_grab_cancel, |
Daniel Stone | df8133b | 2013-11-19 11:37:14 +0100 | [diff] [blame] | 5535 | }; |
| 5536 | |
| 5537 | static int |
| 5538 | exposay_maybe_move(struct desktop_shell *shell, int row, int column) |
| 5539 | { |
| 5540 | struct exposay_surface *esurface; |
| 5541 | |
| 5542 | wl_list_for_each(esurface, &shell->exposay.surface_list, link) { |
| 5543 | if (esurface->row != row || esurface->column != column) |
| 5544 | continue; |
| 5545 | |
| 5546 | exposay_highlight_surface(shell, esurface); |
| 5547 | return 1; |
| 5548 | } |
| 5549 | |
| 5550 | return 0; |
| 5551 | } |
| 5552 | |
| 5553 | static void |
| 5554 | exposay_key(struct weston_keyboard_grab *grab, uint32_t time, uint32_t key, |
| 5555 | uint32_t state_w) |
| 5556 | { |
| 5557 | struct weston_seat *seat = grab->keyboard->seat; |
| 5558 | struct desktop_shell *shell = |
| 5559 | container_of(grab, struct desktop_shell, exposay.grab_kbd); |
| 5560 | enum wl_keyboard_key_state state = state_w; |
| 5561 | |
| 5562 | if (state != WL_KEYBOARD_KEY_STATE_RELEASED) |
| 5563 | return; |
| 5564 | |
| 5565 | switch (key) { |
| 5566 | case KEY_ESC: |
| 5567 | exposay_set_state(shell, EXPOSAY_TARGET_CANCEL, seat); |
| 5568 | break; |
| 5569 | case KEY_ENTER: |
| 5570 | exposay_set_state(shell, EXPOSAY_TARGET_SWITCH, seat); |
| 5571 | break; |
| 5572 | case KEY_UP: |
| 5573 | exposay_maybe_move(shell, shell->exposay.row_current - 1, |
| 5574 | shell->exposay.column_current); |
| 5575 | break; |
| 5576 | case KEY_DOWN: |
| 5577 | /* Special case for trying to move to the bottom row when it |
| 5578 | * has fewer items than all the others. */ |
| 5579 | if (!exposay_maybe_move(shell, shell->exposay.row_current + 1, |
| 5580 | shell->exposay.column_current) && |
| 5581 | shell->exposay.row_current < (shell->exposay.grid_size - 1)) { |
| 5582 | exposay_maybe_move(shell, shell->exposay.row_current + 1, |
| 5583 | (shell->exposay.num_surfaces % |
| 5584 | shell->exposay.grid_size) - 1); |
| 5585 | } |
| 5586 | break; |
| 5587 | case KEY_LEFT: |
| 5588 | exposay_maybe_move(shell, shell->exposay.row_current, |
| 5589 | shell->exposay.column_current - 1); |
| 5590 | break; |
| 5591 | case KEY_RIGHT: |
| 5592 | exposay_maybe_move(shell, shell->exposay.row_current, |
| 5593 | shell->exposay.column_current + 1); |
| 5594 | break; |
| 5595 | case KEY_TAB: |
| 5596 | /* Try to move right, then down (and to the leftmost column), |
| 5597 | * then if all else fails, to the top left. */ |
| 5598 | if (!exposay_maybe_move(shell, shell->exposay.row_current, |
| 5599 | shell->exposay.column_current + 1) && |
| 5600 | !exposay_maybe_move(shell, shell->exposay.row_current + 1, 0)) |
| 5601 | exposay_maybe_move(shell, 0, 0); |
| 5602 | break; |
| 5603 | default: |
| 5604 | break; |
| 5605 | } |
| 5606 | } |
| 5607 | |
| 5608 | static void |
| 5609 | exposay_modifier(struct weston_keyboard_grab *grab, uint32_t serial, |
| 5610 | uint32_t mods_depressed, uint32_t mods_latched, |
| 5611 | uint32_t mods_locked, uint32_t group) |
| 5612 | { |
Emilio Pozuelo Monfort | eed9344 | 2013-11-27 10:49:08 +0100 | [diff] [blame] | 5613 | struct desktop_shell *shell = |
| 5614 | container_of(grab, struct desktop_shell, exposay.grab_kbd); |
| 5615 | struct weston_seat *seat = (struct weston_seat *) grab->keyboard->seat; |
| 5616 | |
| 5617 | /* We want to know when mod has been pressed and released. |
| 5618 | * FIXME: There is a problem here: if mod is pressed, then a key |
| 5619 | * is pressed and released, then mod is released, we will treat that |
| 5620 | * as if only mod had been pressed and released. */ |
| 5621 | if (seat->modifier_state) { |
| 5622 | if (seat->modifier_state == shell->binding_modifier) { |
| 5623 | shell->exposay.mod_pressed = true; |
| 5624 | } else { |
| 5625 | shell->exposay.mod_invalid = true; |
| 5626 | } |
| 5627 | } else { |
| 5628 | if (shell->exposay.mod_pressed && !shell->exposay.mod_invalid) |
| 5629 | exposay_set_state(shell, EXPOSAY_TARGET_CANCEL, seat); |
| 5630 | |
| 5631 | shell->exposay.mod_invalid = false; |
| 5632 | shell->exposay.mod_pressed = false; |
| 5633 | } |
| 5634 | |
| 5635 | return; |
Daniel Stone | df8133b | 2013-11-19 11:37:14 +0100 | [diff] [blame] | 5636 | } |
| 5637 | |
Emilio Pozuelo Monfort | 8224309 | 2013-11-19 11:37:17 +0100 | [diff] [blame] | 5638 | static void |
| 5639 | exposay_cancel(struct weston_keyboard_grab *grab) |
| 5640 | { |
| 5641 | struct desktop_shell *shell = |
| 5642 | container_of(grab, struct desktop_shell, exposay.grab_kbd); |
| 5643 | |
| 5644 | exposay_set_state(shell, EXPOSAY_TARGET_CANCEL, shell->exposay.seat); |
| 5645 | } |
| 5646 | |
Daniel Stone | df8133b | 2013-11-19 11:37:14 +0100 | [diff] [blame] | 5647 | static const struct weston_keyboard_grab_interface exposay_kbd_grab = { |
| 5648 | exposay_key, |
| 5649 | exposay_modifier, |
Emilio Pozuelo Monfort | 8224309 | 2013-11-19 11:37:17 +0100 | [diff] [blame] | 5650 | exposay_cancel, |
Daniel Stone | df8133b | 2013-11-19 11:37:14 +0100 | [diff] [blame] | 5651 | }; |
| 5652 | |
| 5653 | /** |
| 5654 | * Called when the transition from overview -> inactive has completed. |
| 5655 | */ |
| 5656 | static enum exposay_layout_state |
| 5657 | exposay_set_inactive(struct desktop_shell *shell) |
| 5658 | { |
| 5659 | struct weston_seat *seat = shell->exposay.seat; |
| 5660 | |
| 5661 | weston_keyboard_end_grab(seat->keyboard); |
| 5662 | weston_pointer_end_grab(seat->pointer); |
| 5663 | if (seat->keyboard->input_method_resource) |
| 5664 | seat->keyboard->grab = &seat->keyboard->input_method_grab; |
| 5665 | |
| 5666 | return EXPOSAY_LAYOUT_INACTIVE; |
| 5667 | } |
| 5668 | |
| 5669 | /** |
| 5670 | * Begins the transition from overview to inactive. */ |
| 5671 | static enum exposay_layout_state |
| 5672 | exposay_transition_inactive(struct desktop_shell *shell, int switch_focus) |
| 5673 | { |
| 5674 | struct exposay_surface *esurface; |
| 5675 | |
| 5676 | /* Call activate() before we start the animations to avoid |
| 5677 | * animating back the old state and then immediately transitioning |
| 5678 | * to the new. */ |
| 5679 | if (switch_focus && shell->exposay.focus_current) |
| 5680 | activate(shell, shell->exposay.focus_current->surface, |
| 5681 | shell->exposay.seat); |
| 5682 | else if (shell->exposay.focus_prev) |
| 5683 | activate(shell, shell->exposay.focus_prev->surface, |
| 5684 | shell->exposay.seat); |
| 5685 | |
| 5686 | wl_list_for_each(esurface, &shell->exposay.surface_list, link) |
| 5687 | exposay_animate_out(esurface); |
| 5688 | weston_compositor_schedule_repaint(shell->compositor); |
| 5689 | |
| 5690 | return EXPOSAY_LAYOUT_ANIMATE_TO_INACTIVE; |
| 5691 | } |
| 5692 | |
| 5693 | static enum exposay_layout_state |
| 5694 | exposay_transition_active(struct desktop_shell *shell) |
| 5695 | { |
| 5696 | struct weston_seat *seat = shell->exposay.seat; |
| 5697 | |
| 5698 | shell->exposay.workspace = get_current_workspace(shell); |
| 5699 | shell->exposay.focus_prev = get_default_view (seat->keyboard->focus); |
| 5700 | shell->exposay.focus_current = get_default_view (seat->keyboard->focus); |
| 5701 | shell->exposay.clicked = NULL; |
| 5702 | wl_list_init(&shell->exposay.surface_list); |
| 5703 | |
| 5704 | lower_fullscreen_layer(shell); |
| 5705 | shell->exposay.grab_kbd.interface = &exposay_kbd_grab; |
| 5706 | weston_keyboard_start_grab(seat->keyboard, |
| 5707 | &shell->exposay.grab_kbd); |
| 5708 | weston_keyboard_set_focus(seat->keyboard, NULL); |
| 5709 | |
| 5710 | shell->exposay.grab_ptr.interface = &exposay_ptr_grab; |
| 5711 | weston_pointer_start_grab(seat->pointer, |
| 5712 | &shell->exposay.grab_ptr); |
| 5713 | weston_pointer_set_focus(seat->pointer, NULL, |
| 5714 | seat->pointer->x, seat->pointer->y); |
| 5715 | |
| 5716 | return exposay_layout(shell); |
| 5717 | } |
| 5718 | |
| 5719 | static void |
| 5720 | exposay_check_state(struct desktop_shell *shell) |
| 5721 | { |
| 5722 | enum exposay_layout_state state_new = shell->exposay.state_cur; |
| 5723 | int do_switch = 0; |
| 5724 | |
| 5725 | /* Don't do anything whilst animations are running, just store up |
| 5726 | * target state changes and only act on them when the animations have |
| 5727 | * completed. */ |
| 5728 | if (exposay_is_animating(shell)) |
| 5729 | return; |
| 5730 | |
| 5731 | switch (shell->exposay.state_target) { |
| 5732 | case EXPOSAY_TARGET_OVERVIEW: |
| 5733 | switch (shell->exposay.state_cur) { |
| 5734 | case EXPOSAY_LAYOUT_OVERVIEW: |
| 5735 | goto out; |
| 5736 | case EXPOSAY_LAYOUT_ANIMATE_TO_OVERVIEW: |
| 5737 | state_new = EXPOSAY_LAYOUT_OVERVIEW; |
| 5738 | break; |
| 5739 | default: |
| 5740 | state_new = exposay_transition_active(shell); |
| 5741 | break; |
| 5742 | } |
| 5743 | break; |
| 5744 | |
| 5745 | case EXPOSAY_TARGET_SWITCH: |
| 5746 | do_switch = 1; /* fallthrough */ |
| 5747 | case EXPOSAY_TARGET_CANCEL: |
| 5748 | switch (shell->exposay.state_cur) { |
| 5749 | case EXPOSAY_LAYOUT_INACTIVE: |
| 5750 | goto out; |
| 5751 | case EXPOSAY_LAYOUT_ANIMATE_TO_INACTIVE: |
| 5752 | state_new = exposay_set_inactive(shell); |
| 5753 | break; |
| 5754 | default: |
| 5755 | state_new = exposay_transition_inactive(shell, do_switch); |
| 5756 | break; |
| 5757 | } |
| 5758 | |
| 5759 | break; |
| 5760 | } |
| 5761 | |
| 5762 | out: |
| 5763 | shell->exposay.state_cur = state_new; |
| 5764 | } |
| 5765 | |
| 5766 | static void |
| 5767 | exposay_set_state(struct desktop_shell *shell, enum exposay_target_state state, |
| 5768 | struct weston_seat *seat) |
| 5769 | { |
| 5770 | shell->exposay.state_target = state; |
| 5771 | shell->exposay.seat = seat; |
| 5772 | exposay_check_state(shell); |
| 5773 | } |
| 5774 | |
| 5775 | static void |
| 5776 | exposay_binding(struct weston_seat *seat, enum weston_keyboard_modifier modifier, |
| 5777 | void *data) |
| 5778 | { |
| 5779 | struct desktop_shell *shell = data; |
| 5780 | |
Emilio Pozuelo Monfort | eed9344 | 2013-11-27 10:49:08 +0100 | [diff] [blame] | 5781 | exposay_set_state(shell, EXPOSAY_TARGET_OVERVIEW, seat); |
Daniel Stone | df8133b | 2013-11-19 11:37:14 +0100 | [diff] [blame] | 5782 | } |
| 5783 | |
Pekka Paalanen | 3c64723 | 2011-12-22 13:43:43 +0200 | [diff] [blame] | 5784 | static void |
Kristian Høgsberg | e314875 | 2013-05-06 23:19:49 -0400 | [diff] [blame] | 5785 | backlight_binding(struct weston_seat *seat, uint32_t time, uint32_t key, |
Daniel Stone | 325fc2d | 2012-05-30 16:31:58 +0100 | [diff] [blame] | 5786 | void *data) |
Tiago Vignatti | 8e53c7f | 2012-02-29 19:53:50 +0200 | [diff] [blame] | 5787 | { |
| 5788 | struct weston_compositor *compositor = data; |
| 5789 | struct weston_output *output; |
Tiago Vignatti | 5ab91ad | 2012-03-12 19:40:09 -0300 | [diff] [blame] | 5790 | long backlight_new = 0; |
Tiago Vignatti | 8e53c7f | 2012-02-29 19:53:50 +0200 | [diff] [blame] | 5791 | |
| 5792 | /* TODO: we're limiting to simple use cases, where we assume just |
| 5793 | * control on the primary display. We'd have to extend later if we |
| 5794 | * ever get support for setting backlights on random desktop LCD |
| 5795 | * panels though */ |
| 5796 | output = get_default_output(compositor); |
| 5797 | if (!output) |
| 5798 | return; |
| 5799 | |
| 5800 | if (!output->set_backlight) |
| 5801 | return; |
| 5802 | |
Tiago Vignatti | 5ab91ad | 2012-03-12 19:40:09 -0300 | [diff] [blame] | 5803 | if (key == KEY_F9 || key == KEY_BRIGHTNESSDOWN) |
| 5804 | backlight_new = output->backlight_current - 25; |
| 5805 | else if (key == KEY_F10 || key == KEY_BRIGHTNESSUP) |
| 5806 | backlight_new = output->backlight_current + 25; |
Tiago Vignatti | 8e53c7f | 2012-02-29 19:53:50 +0200 | [diff] [blame] | 5807 | |
Tiago Vignatti | 5ab91ad | 2012-03-12 19:40:09 -0300 | [diff] [blame] | 5808 | if (backlight_new < 5) |
| 5809 | backlight_new = 5; |
| 5810 | if (backlight_new > 255) |
| 5811 | backlight_new = 255; |
| 5812 | |
| 5813 | output->backlight_current = backlight_new; |
Tiago Vignatti | 8e53c7f | 2012-02-29 19:53:50 +0200 | [diff] [blame] | 5814 | output->set_backlight(output, output->backlight_current); |
| 5815 | } |
| 5816 | |
Ander Conselvan de Oliveira | c509d2b | 2012-11-08 17:20:45 +0200 | [diff] [blame] | 5817 | struct debug_binding_grab { |
Kristian Høgsberg | 29139d4 | 2013-04-18 15:25:39 -0400 | [diff] [blame] | 5818 | struct weston_keyboard_grab grab; |
Ander Conselvan de Oliveira | c509d2b | 2012-11-08 17:20:45 +0200 | [diff] [blame] | 5819 | struct weston_seat *seat; |
| 5820 | uint32_t key[2]; |
| 5821 | int key_released[2]; |
| 5822 | }; |
| 5823 | |
| 5824 | static void |
Kristian Høgsberg | 29139d4 | 2013-04-18 15:25:39 -0400 | [diff] [blame] | 5825 | 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] | 5826 | uint32_t key, uint32_t state) |
| 5827 | { |
| 5828 | struct debug_binding_grab *db = (struct debug_binding_grab *) grab; |
Rob Bradford | 880ebc7 | 2013-07-22 17:31:38 +0100 | [diff] [blame] | 5829 | struct weston_compositor *ec = db->seat->compositor; |
| 5830 | struct wl_display *display = ec->wl_display; |
Ander Conselvan de Oliveira | c509d2b | 2012-11-08 17:20:45 +0200 | [diff] [blame] | 5831 | struct wl_resource *resource; |
Ander Conselvan de Oliveira | c509d2b | 2012-11-08 17:20:45 +0200 | [diff] [blame] | 5832 | uint32_t serial; |
| 5833 | int send = 0, terminate = 0; |
| 5834 | int check_binding = 1; |
| 5835 | int i; |
Neil Roberts | 96d790e | 2013-09-19 17:32:00 +0100 | [diff] [blame] | 5836 | struct wl_list *resource_list; |
Ander Conselvan de Oliveira | c509d2b | 2012-11-08 17:20:45 +0200 | [diff] [blame] | 5837 | |
| 5838 | if (state == WL_KEYBOARD_KEY_STATE_RELEASED) { |
| 5839 | /* Do not run bindings on key releases */ |
| 5840 | check_binding = 0; |
| 5841 | |
| 5842 | for (i = 0; i < 2; i++) |
| 5843 | if (key == db->key[i]) |
| 5844 | db->key_released[i] = 1; |
| 5845 | |
| 5846 | if (db->key_released[0] && db->key_released[1]) { |
| 5847 | /* All key releases been swalled so end the grab */ |
| 5848 | terminate = 1; |
| 5849 | } else if (key != db->key[0] && key != db->key[1]) { |
| 5850 | /* Should not swallow release of other keys */ |
| 5851 | send = 1; |
| 5852 | } |
| 5853 | } else if (key == db->key[0] && !db->key_released[0]) { |
| 5854 | /* Do not check bindings for the first press of the binding |
| 5855 | * key. This allows it to be used as a debug shortcut. |
| 5856 | * We still need to swallow this event. */ |
| 5857 | check_binding = 0; |
| 5858 | } else if (db->key[1]) { |
| 5859 | /* If we already ran a binding don't process another one since |
| 5860 | * we can't keep track of all the binding keys that were |
| 5861 | * pressed in order to swallow the release events. */ |
| 5862 | send = 1; |
| 5863 | check_binding = 0; |
| 5864 | } |
| 5865 | |
| 5866 | if (check_binding) { |
Ander Conselvan de Oliveira | c509d2b | 2012-11-08 17:20:45 +0200 | [diff] [blame] | 5867 | if (weston_compositor_run_debug_binding(ec, db->seat, time, |
| 5868 | key, state)) { |
| 5869 | /* We ran a binding so swallow the press and keep the |
| 5870 | * grab to swallow the released too. */ |
| 5871 | send = 0; |
| 5872 | terminate = 0; |
| 5873 | db->key[1] = key; |
| 5874 | } else { |
| 5875 | /* Terminate the grab since the key pressed is not a |
| 5876 | * debug binding key. */ |
| 5877 | send = 1; |
| 5878 | terminate = 1; |
| 5879 | } |
| 5880 | } |
| 5881 | |
| 5882 | if (send) { |
Neil Roberts | 96d790e | 2013-09-19 17:32:00 +0100 | [diff] [blame] | 5883 | serial = wl_display_next_serial(display); |
| 5884 | resource_list = &grab->keyboard->focus_resource_list; |
| 5885 | wl_resource_for_each(resource, resource_list) { |
Ander Conselvan de Oliveira | c509d2b | 2012-11-08 17:20:45 +0200 | [diff] [blame] | 5886 | wl_keyboard_send_key(resource, serial, time, key, state); |
| 5887 | } |
| 5888 | } |
| 5889 | |
| 5890 | if (terminate) { |
Kristian Høgsberg | 29139d4 | 2013-04-18 15:25:39 -0400 | [diff] [blame] | 5891 | weston_keyboard_end_grab(grab->keyboard); |
| 5892 | if (grab->keyboard->input_method_resource) |
| 5893 | grab->keyboard->grab = &grab->keyboard->input_method_grab; |
Ander Conselvan de Oliveira | c509d2b | 2012-11-08 17:20:45 +0200 | [diff] [blame] | 5894 | free(db); |
| 5895 | } |
| 5896 | } |
| 5897 | |
| 5898 | static void |
Kristian Høgsberg | 29139d4 | 2013-04-18 15:25:39 -0400 | [diff] [blame] | 5899 | 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] | 5900 | uint32_t mods_depressed, uint32_t mods_latched, |
| 5901 | uint32_t mods_locked, uint32_t group) |
| 5902 | { |
| 5903 | struct wl_resource *resource; |
Neil Roberts | 96d790e | 2013-09-19 17:32:00 +0100 | [diff] [blame] | 5904 | struct wl_list *resource_list; |
Ander Conselvan de Oliveira | c509d2b | 2012-11-08 17:20:45 +0200 | [diff] [blame] | 5905 | |
Neil Roberts | 96d790e | 2013-09-19 17:32:00 +0100 | [diff] [blame] | 5906 | resource_list = &grab->keyboard->focus_resource_list; |
Ander Conselvan de Oliveira | c509d2b | 2012-11-08 17:20:45 +0200 | [diff] [blame] | 5907 | |
Neil Roberts | 96d790e | 2013-09-19 17:32:00 +0100 | [diff] [blame] | 5908 | wl_resource_for_each(resource, resource_list) { |
| 5909 | wl_keyboard_send_modifiers(resource, serial, mods_depressed, |
| 5910 | mods_latched, mods_locked, group); |
| 5911 | } |
Ander Conselvan de Oliveira | c509d2b | 2012-11-08 17:20:45 +0200 | [diff] [blame] | 5912 | } |
| 5913 | |
Jonas Ådahl | 1ea343e | 2013-10-25 23:18:05 +0200 | [diff] [blame] | 5914 | static void |
| 5915 | debug_binding_cancel(struct weston_keyboard_grab *grab) |
| 5916 | { |
| 5917 | struct debug_binding_grab *db = (struct debug_binding_grab *) grab; |
| 5918 | |
| 5919 | weston_keyboard_end_grab(grab->keyboard); |
| 5920 | free(db); |
| 5921 | } |
| 5922 | |
Kristian Høgsberg | 29139d4 | 2013-04-18 15:25:39 -0400 | [diff] [blame] | 5923 | struct weston_keyboard_grab_interface debug_binding_keyboard_grab = { |
Ander Conselvan de Oliveira | c509d2b | 2012-11-08 17:20:45 +0200 | [diff] [blame] | 5924 | debug_binding_key, |
Jonas Ådahl | 1ea343e | 2013-10-25 23:18:05 +0200 | [diff] [blame] | 5925 | debug_binding_modifiers, |
| 5926 | debug_binding_cancel, |
Ander Conselvan de Oliveira | c509d2b | 2012-11-08 17:20:45 +0200 | [diff] [blame] | 5927 | }; |
| 5928 | |
| 5929 | static void |
Kristian Høgsberg | e314875 | 2013-05-06 23:19:49 -0400 | [diff] [blame] | 5930 | 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] | 5931 | { |
| 5932 | struct debug_binding_grab *grab; |
| 5933 | |
| 5934 | grab = calloc(1, sizeof *grab); |
| 5935 | if (!grab) |
| 5936 | return; |
| 5937 | |
| 5938 | grab->seat = (struct weston_seat *) seat; |
| 5939 | grab->key[0] = key; |
| 5940 | grab->grab.interface = &debug_binding_keyboard_grab; |
Kristian Høgsberg | 29139d4 | 2013-04-18 15:25:39 -0400 | [diff] [blame] | 5941 | weston_keyboard_start_grab(seat->keyboard, &grab->grab); |
Ander Conselvan de Oliveira | c509d2b | 2012-11-08 17:20:45 +0200 | [diff] [blame] | 5942 | } |
| 5943 | |
Kristian Høgsberg | b41c081 | 2012-03-04 14:53:40 -0500 | [diff] [blame] | 5944 | static void |
Kristian Høgsberg | e314875 | 2013-05-06 23:19:49 -0400 | [diff] [blame] | 5945 | 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] | 5946 | void *data) |
Kristian Høgsberg | 92a57db | 2012-05-26 13:41:06 -0400 | [diff] [blame] | 5947 | { |
Kristian Høgsberg | fe7aa90 | 2013-05-08 09:54:37 -0400 | [diff] [blame] | 5948 | struct weston_surface *focus_surface; |
Kristian Høgsberg | 92a57db | 2012-05-26 13:41:06 -0400 | [diff] [blame] | 5949 | struct wl_client *client; |
Tiago Vignatti | 1d01b01 | 2012-09-27 17:48:36 +0300 | [diff] [blame] | 5950 | struct desktop_shell *shell = data; |
| 5951 | struct weston_compositor *compositor = shell->compositor; |
Kristian Høgsberg | 92a57db | 2012-05-26 13:41:06 -0400 | [diff] [blame] | 5952 | pid_t pid; |
Kristian Høgsberg | 92a57db | 2012-05-26 13:41:06 -0400 | [diff] [blame] | 5953 | |
Philipp Brüschweiler | 6cef009 | 2012-08-13 21:27:27 +0200 | [diff] [blame] | 5954 | focus_surface = seat->keyboard->focus; |
| 5955 | if (!focus_surface) |
| 5956 | return; |
| 5957 | |
Tiago Vignatti | 1d01b01 | 2012-09-27 17:48:36 +0300 | [diff] [blame] | 5958 | wl_signal_emit(&compositor->kill_signal, focus_surface); |
| 5959 | |
Jason Ekstrand | 26ed73c | 2013-06-06 22:34:41 -0500 | [diff] [blame] | 5960 | client = wl_resource_get_client(focus_surface->resource); |
Tiago Vignatti | 920f197 | 2012-09-27 17:48:35 +0300 | [diff] [blame] | 5961 | wl_client_get_credentials(client, &pid, NULL, NULL); |
| 5962 | |
| 5963 | /* Skip clients that we launched ourselves (the credentials of |
| 5964 | * the socketpair is ours) */ |
| 5965 | if (pid == getpid()) |
| 5966 | return; |
Kristian Høgsberg | 92a57db | 2012-05-26 13:41:06 -0400 | [diff] [blame] | 5967 | |
Daniel Stone | 325fc2d | 2012-05-30 16:31:58 +0100 | [diff] [blame] | 5968 | kill(pid, SIGKILL); |
Kristian Høgsberg | 92a57db | 2012-05-26 13:41:06 -0400 | [diff] [blame] | 5969 | } |
| 5970 | |
| 5971 | static void |
Kristian Høgsberg | e314875 | 2013-05-06 23:19:49 -0400 | [diff] [blame] | 5972 | workspace_up_binding(struct weston_seat *seat, uint32_t time, |
Jonas Ådahl | e3cddce | 2012-06-13 00:01:22 +0200 | [diff] [blame] | 5973 | uint32_t key, void *data) |
| 5974 | { |
| 5975 | struct desktop_shell *shell = data; |
| 5976 | unsigned int new_index = shell->workspaces.current; |
| 5977 | |
Kristian Høgsberg | ce345b0 | 2012-06-25 21:35:29 -0400 | [diff] [blame] | 5978 | if (shell->locked) |
Kristian Høgsberg | 4476aaf | 2012-06-25 14:03:13 -0400 | [diff] [blame] | 5979 | return; |
Jonas Ådahl | e3cddce | 2012-06-13 00:01:22 +0200 | [diff] [blame] | 5980 | if (new_index != 0) |
| 5981 | new_index--; |
| 5982 | |
| 5983 | change_workspace(shell, new_index); |
| 5984 | } |
| 5985 | |
| 5986 | static void |
Kristian Høgsberg | e314875 | 2013-05-06 23:19:49 -0400 | [diff] [blame] | 5987 | workspace_down_binding(struct weston_seat *seat, uint32_t time, |
Jonas Ådahl | e3cddce | 2012-06-13 00:01:22 +0200 | [diff] [blame] | 5988 | uint32_t key, void *data) |
| 5989 | { |
| 5990 | struct desktop_shell *shell = data; |
| 5991 | unsigned int new_index = shell->workspaces.current; |
| 5992 | |
Kristian Høgsberg | ce345b0 | 2012-06-25 21:35:29 -0400 | [diff] [blame] | 5993 | if (shell->locked) |
Kristian Høgsberg | 4476aaf | 2012-06-25 14:03:13 -0400 | [diff] [blame] | 5994 | return; |
Jonas Ådahl | e3cddce | 2012-06-13 00:01:22 +0200 | [diff] [blame] | 5995 | if (new_index < shell->workspaces.num - 1) |
| 5996 | new_index++; |
| 5997 | |
| 5998 | change_workspace(shell, new_index); |
| 5999 | } |
| 6000 | |
| 6001 | static void |
Kristian Høgsberg | e314875 | 2013-05-06 23:19:49 -0400 | [diff] [blame] | 6002 | workspace_f_binding(struct weston_seat *seat, uint32_t time, |
Jonas Ådahl | e3cddce | 2012-06-13 00:01:22 +0200 | [diff] [blame] | 6003 | uint32_t key, void *data) |
| 6004 | { |
| 6005 | struct desktop_shell *shell = data; |
| 6006 | unsigned int new_index; |
| 6007 | |
Kristian Høgsberg | ce345b0 | 2012-06-25 21:35:29 -0400 | [diff] [blame] | 6008 | if (shell->locked) |
Kristian Høgsberg | 4476aaf | 2012-06-25 14:03:13 -0400 | [diff] [blame] | 6009 | return; |
Jonas Ådahl | e3cddce | 2012-06-13 00:01:22 +0200 | [diff] [blame] | 6010 | new_index = key - KEY_F1; |
| 6011 | if (new_index >= shell->workspaces.num) |
| 6012 | new_index = shell->workspaces.num - 1; |
| 6013 | |
| 6014 | change_workspace(shell, new_index); |
| 6015 | } |
| 6016 | |
Jonas Ådahl | 8de6a1d | 2012-08-29 22:13:00 +0200 | [diff] [blame] | 6017 | static void |
Kristian Høgsberg | e314875 | 2013-05-06 23:19:49 -0400 | [diff] [blame] | 6018 | workspace_move_surface_up_binding(struct weston_seat *seat, uint32_t time, |
Jonas Ådahl | 8de6a1d | 2012-08-29 22:13:00 +0200 | [diff] [blame] | 6019 | uint32_t key, void *data) |
| 6020 | { |
| 6021 | struct desktop_shell *shell = data; |
| 6022 | unsigned int new_index = shell->workspaces.current; |
| 6023 | |
| 6024 | if (shell->locked) |
| 6025 | return; |
| 6026 | |
| 6027 | if (new_index != 0) |
| 6028 | new_index--; |
| 6029 | |
| 6030 | take_surface_to_workspace_by_seat(shell, seat, new_index); |
| 6031 | } |
| 6032 | |
| 6033 | static void |
Kristian Høgsberg | e314875 | 2013-05-06 23:19:49 -0400 | [diff] [blame] | 6034 | workspace_move_surface_down_binding(struct weston_seat *seat, uint32_t time, |
Jonas Ådahl | 8de6a1d | 2012-08-29 22:13:00 +0200 | [diff] [blame] | 6035 | uint32_t key, void *data) |
| 6036 | { |
| 6037 | struct desktop_shell *shell = data; |
| 6038 | unsigned int new_index = shell->workspaces.current; |
| 6039 | |
| 6040 | if (shell->locked) |
| 6041 | return; |
| 6042 | |
| 6043 | if (new_index < shell->workspaces.num - 1) |
| 6044 | new_index++; |
| 6045 | |
| 6046 | take_surface_to_workspace_by_seat(shell, seat, new_index); |
| 6047 | } |
Jonas Ådahl | e3cddce | 2012-06-13 00:01:22 +0200 | [diff] [blame] | 6048 | |
| 6049 | static void |
Xiong Zhang | 6b48142 | 2013-10-23 13:58:32 +0800 | [diff] [blame] | 6050 | handle_output_destroy(struct wl_listener *listener, void *data) |
| 6051 | { |
| 6052 | struct shell_output *output_listener = |
| 6053 | container_of(listener, struct shell_output, destroy_listener); |
| 6054 | |
| 6055 | wl_list_remove(&output_listener->destroy_listener.link); |
| 6056 | wl_list_remove(&output_listener->link); |
| 6057 | free(output_listener); |
| 6058 | } |
| 6059 | |
| 6060 | static void |
| 6061 | create_shell_output(struct desktop_shell *shell, |
| 6062 | struct weston_output *output) |
| 6063 | { |
| 6064 | struct shell_output *shell_output; |
| 6065 | |
| 6066 | shell_output = zalloc(sizeof *shell_output); |
| 6067 | if (shell_output == NULL) |
| 6068 | return; |
| 6069 | |
| 6070 | shell_output->output = output; |
| 6071 | shell_output->shell = shell; |
| 6072 | shell_output->destroy_listener.notify = handle_output_destroy; |
| 6073 | wl_signal_add(&output->destroy_signal, |
| 6074 | &shell_output->destroy_listener); |
Kristian Høgsberg | a3a0e18 | 2013-10-23 23:36:04 -0700 | [diff] [blame] | 6075 | wl_list_insert(shell->output_list.prev, &shell_output->link); |
Xiong Zhang | 6b48142 | 2013-10-23 13:58:32 +0800 | [diff] [blame] | 6076 | } |
| 6077 | |
| 6078 | static void |
| 6079 | handle_output_create(struct wl_listener *listener, void *data) |
| 6080 | { |
| 6081 | struct desktop_shell *shell = |
| 6082 | container_of(listener, struct desktop_shell, output_create_listener); |
| 6083 | struct weston_output *output = (struct weston_output *)data; |
| 6084 | |
| 6085 | create_shell_output(shell, output); |
| 6086 | } |
| 6087 | |
| 6088 | static void |
| 6089 | setup_output_destroy_handler(struct weston_compositor *ec, |
| 6090 | struct desktop_shell *shell) |
| 6091 | { |
| 6092 | struct weston_output *output; |
| 6093 | |
| 6094 | wl_list_init(&shell->output_list); |
| 6095 | wl_list_for_each(output, &ec->output_list, link) |
| 6096 | create_shell_output(shell, output); |
| 6097 | |
| 6098 | shell->output_create_listener.notify = handle_output_create; |
| 6099 | wl_signal_add(&ec->output_created_signal, |
| 6100 | &shell->output_create_listener); |
| 6101 | } |
| 6102 | |
| 6103 | static void |
Kristian Høgsberg | 02e79dc | 2012-04-12 09:55:26 -0400 | [diff] [blame] | 6104 | shell_destroy(struct wl_listener *listener, void *data) |
Pekka Paalanen | 3c64723 | 2011-12-22 13:43:43 +0200 | [diff] [blame] | 6105 | { |
Tiago Vignatti | be14326 | 2012-04-16 17:31:41 +0300 | [diff] [blame] | 6106 | struct desktop_shell *shell = |
| 6107 | container_of(listener, struct desktop_shell, destroy_listener); |
Jonas Ådahl | e3cddce | 2012-06-13 00:01:22 +0200 | [diff] [blame] | 6108 | struct workspace **ws; |
Xiong Zhang | 6b48142 | 2013-10-23 13:58:32 +0800 | [diff] [blame] | 6109 | struct shell_output *shell_output, *tmp; |
Pekka Paalanen | 3c64723 | 2011-12-22 13:43:43 +0200 | [diff] [blame] | 6110 | |
Pekka Paalanen | 9cf5cc8 | 2012-01-02 16:00:24 +0200 | [diff] [blame] | 6111 | if (shell->child.client) |
| 6112 | wl_client_destroy(shell->child.client); |
| 6113 | |
Ander Conselvan de Oliveira | a457563 | 2013-02-21 18:35:23 +0200 | [diff] [blame] | 6114 | wl_list_remove(&shell->idle_listener.link); |
| 6115 | wl_list_remove(&shell->wake_listener.link); |
Jan Arne Petersen | 42feced | 2012-06-21 21:52:17 +0200 | [diff] [blame] | 6116 | wl_list_remove(&shell->show_input_panel_listener.link); |
| 6117 | wl_list_remove(&shell->hide_input_panel_listener.link); |
Kristian Høgsberg | 88c1607 | 2012-05-16 08:04:19 -0400 | [diff] [blame] | 6118 | |
Xiong Zhang | 6b48142 | 2013-10-23 13:58:32 +0800 | [diff] [blame] | 6119 | wl_list_for_each_safe(shell_output, tmp, &shell->output_list, link) { |
| 6120 | wl_list_remove(&shell_output->destroy_listener.link); |
| 6121 | wl_list_remove(&shell_output->link); |
| 6122 | free(shell_output); |
| 6123 | } |
| 6124 | |
| 6125 | wl_list_remove(&shell->output_create_listener.link); |
| 6126 | |
Jonas Ådahl | e3cddce | 2012-06-13 00:01:22 +0200 | [diff] [blame] | 6127 | wl_array_for_each(ws, &shell->workspaces.array) |
| 6128 | workspace_destroy(*ws); |
| 6129 | wl_array_release(&shell->workspaces.array); |
| 6130 | |
Pekka Paalanen | 3c64723 | 2011-12-22 13:43:43 +0200 | [diff] [blame] | 6131 | free(shell->screensaver.path); |
Emilio Pozuelo Monfort | 46ce798 | 2013-11-20 13:22:29 +0100 | [diff] [blame] | 6132 | free(shell->client); |
Pekka Paalanen | 3c64723 | 2011-12-22 13:43:43 +0200 | [diff] [blame] | 6133 | free(shell); |
| 6134 | } |
| 6135 | |
Tiago Vignatti | 0b52d48 | 2012-04-20 18:54:25 +0300 | [diff] [blame] | 6136 | static void |
| 6137 | shell_add_bindings(struct weston_compositor *ec, struct desktop_shell *shell) |
| 6138 | { |
| 6139 | uint32_t mod; |
Jonas Ådahl | e3cddce | 2012-06-13 00:01:22 +0200 | [diff] [blame] | 6140 | int i, num_workspace_bindings; |
Tiago Vignatti | 0b52d48 | 2012-04-20 18:54:25 +0300 | [diff] [blame] | 6141 | |
| 6142 | /* fixed bindings */ |
Daniel Stone | 325fc2d | 2012-05-30 16:31:58 +0100 | [diff] [blame] | 6143 | weston_compositor_add_key_binding(ec, KEY_BACKSPACE, |
| 6144 | MODIFIER_CTRL | MODIFIER_ALT, |
| 6145 | terminate_binding, ec); |
Emilio Pozuelo Monfort | 03251b6 | 2013-11-19 11:37:16 +0100 | [diff] [blame] | 6146 | weston_compositor_add_key_binding(ec, KEY_TAB, |
| 6147 | MODIFIER_ALT, |
| 6148 | alt_tab_binding, shell); |
Daniel Stone | 325fc2d | 2012-05-30 16:31:58 +0100 | [diff] [blame] | 6149 | weston_compositor_add_button_binding(ec, BTN_LEFT, 0, |
| 6150 | click_to_activate_binding, |
| 6151 | shell); |
Neil Roberts | a28c693 | 2013-10-03 16:43:04 +0100 | [diff] [blame] | 6152 | weston_compositor_add_touch_binding(ec, 0, |
| 6153 | touch_to_activate_binding, |
| 6154 | shell); |
Daniel Stone | 325fc2d | 2012-05-30 16:31:58 +0100 | [diff] [blame] | 6155 | weston_compositor_add_axis_binding(ec, WL_POINTER_AXIS_VERTICAL_SCROLL, |
| 6156 | MODIFIER_SUPER | MODIFIER_ALT, |
| 6157 | surface_opacity_binding, NULL); |
| 6158 | weston_compositor_add_axis_binding(ec, WL_POINTER_AXIS_VERTICAL_SCROLL, |
| 6159 | MODIFIER_SUPER, zoom_axis_binding, |
| 6160 | NULL); |
Tiago Vignatti | 0b52d48 | 2012-04-20 18:54:25 +0300 | [diff] [blame] | 6161 | |
| 6162 | /* configurable bindings */ |
| 6163 | mod = shell->binding_modifier; |
Daniel Stone | 325fc2d | 2012-05-30 16:31:58 +0100 | [diff] [blame] | 6164 | weston_compositor_add_key_binding(ec, KEY_PAGEUP, mod, |
| 6165 | zoom_key_binding, NULL); |
| 6166 | weston_compositor_add_key_binding(ec, KEY_PAGEDOWN, mod, |
| 6167 | zoom_key_binding, NULL); |
| 6168 | weston_compositor_add_button_binding(ec, BTN_LEFT, mod, move_binding, |
| 6169 | shell); |
Neil Roberts | aba0f25 | 2013-10-03 16:43:05 +0100 | [diff] [blame] | 6170 | weston_compositor_add_touch_binding(ec, mod, touch_move_binding, shell); |
Daniel Stone | 325fc2d | 2012-05-30 16:31:58 +0100 | [diff] [blame] | 6171 | weston_compositor_add_button_binding(ec, BTN_MIDDLE, mod, |
| 6172 | resize_binding, shell); |
Pekka Paalanen | 7bb6510 | 2013-05-22 18:03:04 +0300 | [diff] [blame] | 6173 | |
| 6174 | if (ec->capabilities & WESTON_CAP_ROTATION_ANY) |
| 6175 | weston_compositor_add_button_binding(ec, BTN_RIGHT, mod, |
| 6176 | rotate_binding, NULL); |
| 6177 | |
Daniel Stone | 325fc2d | 2012-05-30 16:31:58 +0100 | [diff] [blame] | 6178 | weston_compositor_add_key_binding(ec, KEY_TAB, mod, switcher_binding, |
| 6179 | shell); |
| 6180 | weston_compositor_add_key_binding(ec, KEY_F9, mod, backlight_binding, |
| 6181 | ec); |
| 6182 | weston_compositor_add_key_binding(ec, KEY_BRIGHTNESSDOWN, 0, |
| 6183 | backlight_binding, ec); |
| 6184 | weston_compositor_add_key_binding(ec, KEY_F10, mod, backlight_binding, |
| 6185 | ec); |
| 6186 | weston_compositor_add_key_binding(ec, KEY_BRIGHTNESSUP, 0, |
| 6187 | backlight_binding, ec); |
Daniel Stone | 325fc2d | 2012-05-30 16:31:58 +0100 | [diff] [blame] | 6188 | weston_compositor_add_key_binding(ec, KEY_K, mod, |
| 6189 | force_kill_binding, shell); |
Jonas Ådahl | e3cddce | 2012-06-13 00:01:22 +0200 | [diff] [blame] | 6190 | weston_compositor_add_key_binding(ec, KEY_UP, mod, |
| 6191 | workspace_up_binding, shell); |
| 6192 | weston_compositor_add_key_binding(ec, KEY_DOWN, mod, |
| 6193 | workspace_down_binding, shell); |
Jonas Ådahl | 8de6a1d | 2012-08-29 22:13:00 +0200 | [diff] [blame] | 6194 | weston_compositor_add_key_binding(ec, KEY_UP, mod | MODIFIER_SHIFT, |
| 6195 | workspace_move_surface_up_binding, |
| 6196 | shell); |
| 6197 | weston_compositor_add_key_binding(ec, KEY_DOWN, mod | MODIFIER_SHIFT, |
| 6198 | workspace_move_surface_down_binding, |
| 6199 | shell); |
Jonas Ådahl | e3cddce | 2012-06-13 00:01:22 +0200 | [diff] [blame] | 6200 | |
Daniel Stone | df8133b | 2013-11-19 11:37:14 +0100 | [diff] [blame] | 6201 | weston_compositor_add_modifier_binding(ec, mod, exposay_binding, shell); |
| 6202 | |
Jonas Ådahl | e3cddce | 2012-06-13 00:01:22 +0200 | [diff] [blame] | 6203 | /* Add bindings for mod+F[1-6] for workspace 1 to 6. */ |
| 6204 | if (shell->workspaces.num > 1) { |
| 6205 | num_workspace_bindings = shell->workspaces.num; |
| 6206 | if (num_workspace_bindings > 6) |
| 6207 | num_workspace_bindings = 6; |
| 6208 | for (i = 0; i < num_workspace_bindings; i++) |
| 6209 | weston_compositor_add_key_binding(ec, KEY_F1 + i, mod, |
| 6210 | workspace_f_binding, |
| 6211 | shell); |
| 6212 | } |
Ander Conselvan de Oliveira | c509d2b | 2012-11-08 17:20:45 +0200 | [diff] [blame] | 6213 | |
| 6214 | /* Debug bindings */ |
| 6215 | weston_compositor_add_key_binding(ec, KEY_SPACE, mod | MODIFIER_SHIFT, |
| 6216 | debug_binding, shell); |
Tiago Vignatti | 0b52d48 | 2012-04-20 18:54:25 +0300 | [diff] [blame] | 6217 | } |
| 6218 | |
Kristian Høgsberg | 1c56218 | 2011-05-02 22:09:20 -0400 | [diff] [blame] | 6219 | WL_EXPORT int |
Kristian Høgsberg | cb4685b | 2013-02-20 15:37:49 -0500 | [diff] [blame] | 6220 | module_init(struct weston_compositor *ec, |
Ossama Othman | a50e6e4 | 2013-05-14 09:48:26 -0700 | [diff] [blame] | 6221 | int *argc, char *argv[]) |
Kristian Høgsberg | 4cca349 | 2011-01-18 07:53:49 -0500 | [diff] [blame] | 6222 | { |
Kristian Høgsberg | f4d2f23 | 2012-08-10 10:05:39 -0400 | [diff] [blame] | 6223 | struct weston_seat *seat; |
Tiago Vignatti | be14326 | 2012-04-16 17:31:41 +0300 | [diff] [blame] | 6224 | struct desktop_shell *shell; |
Jonas Ådahl | e3cddce | 2012-06-13 00:01:22 +0200 | [diff] [blame] | 6225 | struct workspace **pws; |
| 6226 | unsigned int i; |
Tiago Vignatti | b7dbbd6 | 2012-09-25 17:57:01 +0300 | [diff] [blame] | 6227 | struct wl_event_loop *loop; |
Kristian Høgsberg | 02ec0a5 | 2011-04-23 13:04:11 -0400 | [diff] [blame] | 6228 | |
Peter Hutterer | f3d6227 | 2013-08-08 11:57:05 +1000 | [diff] [blame] | 6229 | shell = zalloc(sizeof *shell); |
Kristian Høgsberg | 02ec0a5 | 2011-04-23 13:04:11 -0400 | [diff] [blame] | 6230 | if (shell == NULL) |
| 6231 | return -1; |
| 6232 | |
Kristian Høgsberg | 7584062 | 2011-09-06 13:48:16 -0400 | [diff] [blame] | 6233 | shell->compositor = ec; |
Kristian Høgsberg | 02e79dc | 2012-04-12 09:55:26 -0400 | [diff] [blame] | 6234 | |
| 6235 | shell->destroy_listener.notify = shell_destroy; |
| 6236 | wl_signal_add(&ec->destroy_signal, &shell->destroy_listener); |
Ander Conselvan de Oliveira | a457563 | 2013-02-21 18:35:23 +0200 | [diff] [blame] | 6237 | shell->idle_listener.notify = idle_handler; |
| 6238 | wl_signal_add(&ec->idle_signal, &shell->idle_listener); |
| 6239 | shell->wake_listener.notify = wake_handler; |
| 6240 | wl_signal_add(&ec->wake_signal, &shell->wake_listener); |
Jan Arne Petersen | 42feced | 2012-06-21 21:52:17 +0200 | [diff] [blame] | 6241 | shell->show_input_panel_listener.notify = show_input_panels; |
| 6242 | wl_signal_add(&ec->show_input_panel_signal, &shell->show_input_panel_listener); |
| 6243 | shell->hide_input_panel_listener.notify = hide_input_panels; |
| 6244 | wl_signal_add(&ec->hide_input_panel_signal, &shell->hide_input_panel_listener); |
Jan Arne Petersen | 14da96b | 2013-04-18 16:47:28 +0200 | [diff] [blame] | 6245 | shell->update_input_panel_listener.notify = update_input_panels; |
| 6246 | wl_signal_add(&ec->update_input_panel_signal, &shell->update_input_panel_listener); |
Scott Moreau | ff1db4a | 2012-04-17 19:06:18 -0600 | [diff] [blame] | 6247 | ec->ping_handler = ping_handler; |
Kristian Høgsberg | 82a1d11 | 2012-07-19 14:02:00 -0400 | [diff] [blame] | 6248 | ec->shell_interface.shell = shell; |
Tiago Vignatti | bc052c9 | 2012-04-19 16:18:18 +0300 | [diff] [blame] | 6249 | ec->shell_interface.create_shell_surface = create_shell_surface; |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 6250 | ec->shell_interface.get_primary_view = get_primary_view; |
Tiago Vignatti | bc052c9 | 2012-04-19 16:18:18 +0300 | [diff] [blame] | 6251 | ec->shell_interface.set_toplevel = set_toplevel; |
Tiago Vignatti | 491bac1 | 2012-05-18 16:37:43 -0400 | [diff] [blame] | 6252 | ec->shell_interface.set_transient = set_transient; |
Kristian Høgsberg | b810eb5 | 2013-02-12 20:07:05 -0500 | [diff] [blame] | 6253 | ec->shell_interface.set_fullscreen = set_fullscreen; |
Tiago Vignatti | fb2adba | 2013-06-12 15:43:21 -0300 | [diff] [blame] | 6254 | ec->shell_interface.set_xwayland = set_xwayland; |
Kristian Høgsberg | 938b8fa | 2012-05-18 13:46:27 -0400 | [diff] [blame] | 6255 | ec->shell_interface.move = surface_move; |
Kristian Høgsberg | c1693f2 | 2012-05-22 16:56:23 -0400 | [diff] [blame] | 6256 | ec->shell_interface.resize = surface_resize; |
Giulio Camuffo | 62942ad | 2013-09-11 18:20:47 +0200 | [diff] [blame] | 6257 | ec->shell_interface.set_title = set_title; |
Kristian Høgsberg | 4cca349 | 2011-01-18 07:53:49 -0500 | [diff] [blame] | 6258 | |
Jan Arne Petersen | 42feced | 2012-06-21 21:52:17 +0200 | [diff] [blame] | 6259 | wl_list_init(&shell->input_panel.surfaces); |
Pekka Paalanen | f0fc70d | 2011-11-15 13:34:54 +0200 | [diff] [blame] | 6260 | |
Kristian Høgsberg | 3be2ce9 | 2012-02-29 12:42:35 -0500 | [diff] [blame] | 6261 | weston_layer_init(&shell->fullscreen_layer, &ec->cursor_layer.link); |
| 6262 | weston_layer_init(&shell->panel_layer, &shell->fullscreen_layer.link); |
Jonas Ådahl | e3cddce | 2012-06-13 00:01:22 +0200 | [diff] [blame] | 6263 | weston_layer_init(&shell->background_layer, &shell->panel_layer.link); |
| 6264 | weston_layer_init(&shell->lock_layer, NULL); |
Philipp Brüschweiler | 711fda8 | 2012-08-09 18:50:43 +0200 | [diff] [blame] | 6265 | weston_layer_init(&shell->input_panel_layer, NULL); |
Jonas Ådahl | e3cddce | 2012-06-13 00:01:22 +0200 | [diff] [blame] | 6266 | |
| 6267 | wl_array_init(&shell->workspaces.array); |
Jonas Ådahl | e9d2250 | 2012-08-29 22:13:01 +0200 | [diff] [blame] | 6268 | wl_list_init(&shell->workspaces.client_list); |
Kristian Høgsberg | 3be2ce9 | 2012-02-29 12:42:35 -0500 | [diff] [blame] | 6269 | |
Kristian Høgsberg | 14e438c | 2013-05-26 21:48:14 -0400 | [diff] [blame] | 6270 | shell_configuration(shell); |
Pekka Paalanen | e955f1e | 2011-12-07 11:49:52 +0200 | [diff] [blame] | 6271 | |
Daniel Stone | df8133b | 2013-11-19 11:37:14 +0100 | [diff] [blame] | 6272 | shell->exposay.state_cur = EXPOSAY_LAYOUT_INACTIVE; |
| 6273 | shell->exposay.state_target = EXPOSAY_TARGET_CANCEL; |
| 6274 | |
Jonas Ådahl | e3cddce | 2012-06-13 00:01:22 +0200 | [diff] [blame] | 6275 | for (i = 0; i < shell->workspaces.num; i++) { |
| 6276 | pws = wl_array_add(&shell->workspaces.array, sizeof *pws); |
| 6277 | if (pws == NULL) |
| 6278 | return -1; |
| 6279 | |
| 6280 | *pws = workspace_create(); |
| 6281 | if (*pws == NULL) |
| 6282 | return -1; |
| 6283 | } |
| 6284 | activate_workspace(shell, 0); |
| 6285 | |
Jonas Ådahl | 8de6a1d | 2012-08-29 22:13:00 +0200 | [diff] [blame] | 6286 | wl_list_init(&shell->workspaces.anim_sticky_list); |
Jonas Ådahl | 62fcd04 | 2012-06-13 00:01:23 +0200 | [diff] [blame] | 6287 | wl_list_init(&shell->workspaces.animation.link); |
| 6288 | shell->workspaces.animation.frame = animate_workspace_change_frame; |
| 6289 | |
Kristian Høgsberg | 919cddb | 2013-07-08 19:03:57 -0400 | [diff] [blame] | 6290 | if (wl_global_create(ec->wl_display, &wl_shell_interface, 1, |
Kristian Høgsberg | 97d44aa | 2011-08-26 17:21:20 -0400 | [diff] [blame] | 6291 | shell, bind_shell) == NULL) |
Kristian Høgsberg | 4cca349 | 2011-01-18 07:53:49 -0500 | [diff] [blame] | 6292 | return -1; |
| 6293 | |
Kristian Høgsberg | 919cddb | 2013-07-08 19:03:57 -0400 | [diff] [blame] | 6294 | if (wl_global_create(ec->wl_display, |
| 6295 | &desktop_shell_interface, 2, |
| 6296 | shell, bind_desktop_shell) == NULL) |
Kristian Høgsberg | 7584062 | 2011-09-06 13:48:16 -0400 | [diff] [blame] | 6297 | return -1; |
| 6298 | |
Kristian Høgsberg | 919cddb | 2013-07-08 19:03:57 -0400 | [diff] [blame] | 6299 | if (wl_global_create(ec->wl_display, &screensaver_interface, 1, |
| 6300 | shell, bind_screensaver) == NULL) |
Pekka Paalanen | 6e16811 | 2011-11-24 11:34:05 +0200 | [diff] [blame] | 6301 | return -1; |
| 6302 | |
Kristian Høgsberg | 919cddb | 2013-07-08 19:03:57 -0400 | [diff] [blame] | 6303 | if (wl_global_create(ec->wl_display, &wl_input_panel_interface, 1, |
Jan Arne Petersen | 42feced | 2012-06-21 21:52:17 +0200 | [diff] [blame] | 6304 | shell, bind_input_panel) == NULL) |
| 6305 | return -1; |
| 6306 | |
Kristian Høgsberg | 919cddb | 2013-07-08 19:03:57 -0400 | [diff] [blame] | 6307 | if (wl_global_create(ec->wl_display, &workspace_manager_interface, 1, |
| 6308 | shell, bind_workspace_manager) == NULL) |
Jonas Ådahl | e9d2250 | 2012-08-29 22:13:01 +0200 | [diff] [blame] | 6309 | return -1; |
| 6310 | |
Kristian Høgsberg | f03a616 | 2012-01-17 11:07:42 -0500 | [diff] [blame] | 6311 | shell->child.deathstamp = weston_compositor_get_time(); |
Tiago Vignatti | b7dbbd6 | 2012-09-25 17:57:01 +0300 | [diff] [blame] | 6312 | |
Xiong Zhang | 6b48142 | 2013-10-23 13:58:32 +0800 | [diff] [blame] | 6313 | setup_output_destroy_handler(ec, shell); |
| 6314 | |
Tiago Vignatti | b7dbbd6 | 2012-09-25 17:57:01 +0300 | [diff] [blame] | 6315 | loop = wl_display_get_event_loop(ec->wl_display); |
| 6316 | wl_event_loop_add_idle(loop, launch_desktop_shell_process, shell); |
Pekka Paalanen | 6cd281a | 2011-11-03 14:11:32 +0200 | [diff] [blame] | 6317 | |
Ander Conselvan de Oliveira | 859e885 | 2013-02-21 18:35:21 +0200 | [diff] [blame] | 6318 | shell->screensaver.timer = |
| 6319 | wl_event_loop_add_timer(loop, screensaver_timeout, shell); |
| 6320 | |
Kristian Høgsberg | f4d2f23 | 2012-08-10 10:05:39 -0400 | [diff] [blame] | 6321 | wl_list_for_each(seat, &ec->seat_list, link) |
| 6322 | create_pointer_focus_listener(seat); |
Kristian Høgsberg | d56bd90 | 2012-06-05 09:58:51 -0400 | [diff] [blame] | 6323 | |
Tiago Vignatti | 0b52d48 | 2012-04-20 18:54:25 +0300 | [diff] [blame] | 6324 | shell_add_bindings(ec, shell); |
Kristian Høgsberg | 0793756 | 2011-04-12 17:25:42 -0400 | [diff] [blame] | 6325 | |
Pekka Paalanen | 79346ab | 2013-05-22 18:03:09 +0300 | [diff] [blame] | 6326 | shell_fade_init(shell); |
Ander Conselvan de Oliveira | 19d10ef | 2013-02-21 18:35:20 +0200 | [diff] [blame] | 6327 | |
Kristian Høgsberg | 4cca349 | 2011-01-18 07:53:49 -0500 | [diff] [blame] | 6328 | return 0; |
| 6329 | } |