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, |
| 242 | SHELL_SURFACE_TRANSIENT, |
Kristian Høgsberg | b3cca0a | 2012-01-04 22:19:14 -0500 | [diff] [blame] | 243 | SHELL_SURFACE_FULLSCREEN, |
Juan Zhao | 96879df | 2012-02-07 08:45:41 +0800 | [diff] [blame] | 244 | SHELL_SURFACE_MAXIMIZED, |
Tiago Vignatti | fb2adba | 2013-06-12 15:43:21 -0300 | [diff] [blame] | 245 | SHELL_SURFACE_POPUP, |
| 246 | SHELL_SURFACE_XWAYLAND |
Pekka Paalanen | 57da4a8 | 2011-11-23 16:42:16 +0200 | [diff] [blame] | 247 | }; |
| 248 | |
Scott Moreau | ff1db4a | 2012-04-17 19:06:18 -0600 | [diff] [blame] | 249 | struct ping_timer { |
| 250 | struct wl_event_source *source; |
Scott Moreau | ff1db4a | 2012-04-17 19:06:18 -0600 | [diff] [blame] | 251 | uint32_t serial; |
| 252 | }; |
| 253 | |
Philip Withnall | 648a4dd | 2013-11-25 18:01:44 +0000 | [diff] [blame^] | 254 | /* |
| 255 | * Surface stacking and ordering. |
| 256 | * |
| 257 | * This is handled using several linked lists of surfaces, organised into |
| 258 | * ‘layers’. The layers are ordered, and each of the surfaces in one layer are |
| 259 | * above all of the surfaces in the layer below. The set of layers is static and |
| 260 | * in the following order (top-most first): |
| 261 | * • Lock layer (only ever displayed on its own) |
| 262 | * • Cursor layer |
| 263 | * • Fullscreen layer |
| 264 | * • Panel layer |
| 265 | * • Input panel layer |
| 266 | * • Workspace layers |
| 267 | * • Background layer |
| 268 | * |
| 269 | * The list of layers may be manipulated to remove whole layers of surfaces from |
| 270 | * display. For example, when locking the screen, all layers except the lock |
| 271 | * layer are removed. |
| 272 | * |
| 273 | * A surface’s layer is modified on configuring the surface, in |
| 274 | * set_surface_type() (which is only called when the surface’s type change is |
| 275 | * _committed_). If a surface’s type changes (e.g. when making a window |
| 276 | * fullscreen) its layer changes too. |
| 277 | * |
| 278 | * In order to allow popup and transient surfaces to be correctly stacked above |
| 279 | * their parent surfaces, each surface tracks both its parent surface, and a |
| 280 | * linked list of its children. When a surface’s layer is updated, so are the |
| 281 | * layers of its children. Note that child surfaces are *not* the same as |
| 282 | * subsurfaces — child/parent surfaces are purely for maintaining stacking |
| 283 | * order. |
| 284 | * |
| 285 | * The children_link list of siblings of a surface (i.e. those surfaces which |
| 286 | * have the same parent) only contains weston_surfaces which have a |
| 287 | * shell_surface. Stacking is not implemented for non-shell_surface |
| 288 | * weston_surfaces. This means that the following implication does *not* hold: |
| 289 | * (shsurf->parent != NULL) ⇒ !wl_list_is_empty(shsurf->children_link) |
| 290 | */ |
| 291 | |
Pekka Paalanen | 56cdea9 | 2011-11-23 16:14:12 +0200 | [diff] [blame] | 292 | struct shell_surface { |
Jason Ekstrand | 651f00e | 2013-06-14 10:07:54 -0500 | [diff] [blame] | 293 | struct wl_resource *resource; |
| 294 | struct wl_signal destroy_signal; |
Pekka Paalanen | 9d1613e | 2011-11-25 12:09:16 +0200 | [diff] [blame] | 295 | |
Kristian Høgsberg | 8334bc1 | 2012-01-03 10:29:47 -0500 | [diff] [blame] | 296 | struct weston_surface *surface; |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 297 | struct weston_view *view; |
Pekka Paalanen | 9d1613e | 2011-11-25 12:09:16 +0200 | [diff] [blame] | 298 | struct wl_listener surface_destroy_listener; |
Kristian Høgsberg | 8150b19 | 2012-06-27 10:22:58 -0400 | [diff] [blame] | 299 | struct weston_surface *parent; |
Philip Withnall | 648a4dd | 2013-11-25 18:01:44 +0000 | [diff] [blame^] | 300 | struct wl_list children_list; /* child surfaces of this one */ |
| 301 | struct wl_list children_link; /* sibling surfaces of this one */ |
Tiago Vignatti | be14326 | 2012-04-16 17:31:41 +0300 | [diff] [blame] | 302 | struct desktop_shell *shell; |
Pekka Paalanen | 57da4a8 | 2011-11-23 16:42:16 +0200 | [diff] [blame] | 303 | |
Kristian Høgsberg | 7f366e7 | 2012-04-27 17:20:01 -0400 | [diff] [blame] | 304 | enum shell_surface_type type, next_type; |
Kristian Høgsberg | e7afd91 | 2012-05-02 09:47:44 -0400 | [diff] [blame] | 305 | char *title, *class; |
Kristian Høgsberg | d2abb83 | 2011-11-23 10:52:40 -0500 | [diff] [blame] | 306 | int32_t saved_x, saved_y; |
Alex Wu | 4539b08 | 2012-03-01 12:57:46 +0800 | [diff] [blame] | 307 | bool saved_position_valid; |
Alex Wu | 7bcb8bd | 2012-04-27 09:07:24 +0800 | [diff] [blame] | 308 | bool saved_rotation_valid; |
Kristian Høgsberg | c85f1d4 | 2013-10-24 16:52:00 -0700 | [diff] [blame] | 309 | int unresponsive, grabbed; |
Benjamin Franzke | d0f79ab | 2011-11-22 12:43:52 +0100 | [diff] [blame] | 310 | |
Kristian Høgsberg | b3cca0a | 2012-01-04 22:19:14 -0500 | [diff] [blame] | 311 | struct { |
Pekka Paalanen | 460099f | 2012-01-20 16:48:25 +0200 | [diff] [blame] | 312 | struct weston_transform transform; |
Kristian Høgsberg | 765e27b | 2012-01-27 13:36:13 -0500 | [diff] [blame] | 313 | struct weston_matrix rotation; |
Pekka Paalanen | 460099f | 2012-01-20 16:48:25 +0200 | [diff] [blame] | 314 | } rotation; |
| 315 | |
| 316 | struct { |
Giulio Camuffo | 5085a75 | 2013-03-25 21:42:45 +0100 | [diff] [blame] | 317 | struct wl_list grab_link; |
Kristian Høgsberg | b3cca0a | 2012-01-04 22:19:14 -0500 | [diff] [blame] | 318 | int32_t x, y; |
Giulio Camuffo | 5085a75 | 2013-03-25 21:42:45 +0100 | [diff] [blame] | 319 | struct shell_seat *shseat; |
Kristian Høgsberg | 3730f36 | 2012-04-13 12:40:07 -0400 | [diff] [blame] | 320 | uint32_t serial; |
Kristian Høgsberg | b3cca0a | 2012-01-04 22:19:14 -0500 | [diff] [blame] | 321 | } popup; |
| 322 | |
Alex Wu | 4539b08 | 2012-03-01 12:57:46 +0800 | [diff] [blame] | 323 | struct { |
Tiago Vignatti | 52e598c | 2012-05-07 15:23:08 +0300 | [diff] [blame] | 324 | int32_t x, y; |
Tiago Vignatti | 491bac1 | 2012-05-18 16:37:43 -0400 | [diff] [blame] | 325 | uint32_t flags; |
Tiago Vignatti | 52e598c | 2012-05-07 15:23:08 +0300 | [diff] [blame] | 326 | } transient; |
| 327 | |
| 328 | struct { |
Alex Wu | 4539b08 | 2012-03-01 12:57:46 +0800 | [diff] [blame] | 329 | enum wl_shell_surface_fullscreen_method type; |
| 330 | struct weston_transform transform; /* matrix from x, y */ |
| 331 | uint32_t framerate; |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 332 | struct weston_view *black_view; |
Alex Wu | 4539b08 | 2012-03-01 12:57:46 +0800 | [diff] [blame] | 333 | } fullscreen; |
| 334 | |
Scott Moreau | ff1db4a | 2012-04-17 19:06:18 -0600 | [diff] [blame] | 335 | struct ping_timer *ping_timer; |
| 336 | |
Jonas Ådahl | 62fcd04 | 2012-06-13 00:01:23 +0200 | [diff] [blame] | 337 | struct weston_transform workspace_transform; |
| 338 | |
Kristian Høgsberg | 1cbf326 | 2012-02-17 23:49:07 -0500 | [diff] [blame] | 339 | struct weston_output *fullscreen_output; |
Kristian Høgsberg | 8334bc1 | 2012-01-03 10:29:47 -0500 | [diff] [blame] | 340 | struct weston_output *output; |
Benjamin Franzke | d0f79ab | 2011-11-22 12:43:52 +0100 | [diff] [blame] | 341 | struct wl_list link; |
Kristian Høgsberg | a61ca06 | 2012-05-22 16:05:52 -0400 | [diff] [blame] | 342 | |
| 343 | const struct weston_shell_client *client; |
Pekka Paalanen | 56cdea9 | 2011-11-23 16:14:12 +0200 | [diff] [blame] | 344 | }; |
| 345 | |
Ander Conselvan de Oliveira | fe0444a | 2012-04-04 17:48:05 +0300 | [diff] [blame] | 346 | struct shell_grab { |
Kristian Høgsberg | 02bbabb | 2013-05-06 22:15:05 -0400 | [diff] [blame] | 347 | struct weston_pointer_grab grab; |
Ander Conselvan de Oliveira | fe0444a | 2012-04-04 17:48:05 +0300 | [diff] [blame] | 348 | struct shell_surface *shsurf; |
| 349 | struct wl_listener shsurf_destroy_listener; |
| 350 | }; |
| 351 | |
Rusty Lynch | 1084da5 | 2013-08-15 09:10:08 -0700 | [diff] [blame] | 352 | struct shell_touch_grab { |
| 353 | struct weston_touch_grab grab; |
| 354 | struct shell_surface *shsurf; |
| 355 | struct wl_listener shsurf_destroy_listener; |
| 356 | struct weston_touch *touch; |
| 357 | }; |
| 358 | |
Ander Conselvan de Oliveira | fe0444a | 2012-04-04 17:48:05 +0300 | [diff] [blame] | 359 | struct weston_move_grab { |
| 360 | struct shell_grab base; |
Daniel Stone | 103db7f | 2012-05-08 17:17:55 +0100 | [diff] [blame] | 361 | wl_fixed_t dx, dy; |
Kristian Høgsberg | 4cca349 | 2011-01-18 07:53:49 -0500 | [diff] [blame] | 362 | }; |
| 363 | |
Rusty Lynch | 1084da5 | 2013-08-15 09:10:08 -0700 | [diff] [blame] | 364 | struct weston_touch_move_grab { |
| 365 | struct shell_touch_grab base; |
| 366 | wl_fixed_t dx, dy; |
| 367 | }; |
| 368 | |
Pekka Paalanen | 460099f | 2012-01-20 16:48:25 +0200 | [diff] [blame] | 369 | struct rotate_grab { |
Ander Conselvan de Oliveira | fe0444a | 2012-04-04 17:48:05 +0300 | [diff] [blame] | 370 | struct shell_grab base; |
Kristian Høgsberg | 765e27b | 2012-01-27 13:36:13 -0500 | [diff] [blame] | 371 | struct weston_matrix rotation; |
Pekka Paalanen | 460099f | 2012-01-20 16:48:25 +0200 | [diff] [blame] | 372 | struct { |
John Kåre Alsaker | 490d02a | 2012-09-30 02:57:21 +0200 | [diff] [blame] | 373 | float x; |
| 374 | float y; |
Pekka Paalanen | 460099f | 2012-01-20 16:48:25 +0200 | [diff] [blame] | 375 | } center; |
| 376 | }; |
| 377 | |
Giulio Camuffo | 5085a75 | 2013-03-25 21:42:45 +0100 | [diff] [blame] | 378 | struct shell_seat { |
| 379 | struct weston_seat *seat; |
| 380 | struct wl_listener seat_destroy_listener; |
| 381 | |
| 382 | struct { |
Kristian Høgsberg | 02bbabb | 2013-05-06 22:15:05 -0400 | [diff] [blame] | 383 | struct weston_pointer_grab grab; |
Giulio Camuffo | 5085a75 | 2013-03-25 21:42:45 +0100 | [diff] [blame] | 384 | struct wl_list surfaces_list; |
| 385 | struct wl_client *client; |
| 386 | int32_t initial_up; |
| 387 | } popup_grab; |
| 388 | }; |
| 389 | |
Kristian Høgsberg | 2f5faff | 2012-07-31 16:36:34 -0400 | [diff] [blame] | 390 | static void |
| 391 | activate(struct desktop_shell *shell, struct weston_surface *es, |
| 392 | struct weston_seat *seat); |
| 393 | |
| 394 | static struct workspace * |
| 395 | get_current_workspace(struct desktop_shell *shell); |
| 396 | |
Alex Wu | bd3354b | 2012-04-17 17:20:49 +0800 | [diff] [blame] | 397 | static struct shell_surface * |
| 398 | get_shell_surface(struct weston_surface *surface); |
| 399 | |
| 400 | static struct desktop_shell * |
| 401 | shell_surface_get_shell(struct shell_surface *shsurf); |
| 402 | |
Kristian Høgsberg | 0c36903 | 2013-02-14 21:31:44 -0500 | [diff] [blame] | 403 | static void |
Kristian Høgsberg | e314875 | 2013-05-06 23:19:49 -0400 | [diff] [blame] | 404 | surface_rotate(struct shell_surface *surface, struct weston_seat *seat); |
Kristian Høgsberg | 0c36903 | 2013-02-14 21:31:44 -0500 | [diff] [blame] | 405 | |
Pekka Paalanen | 79346ab | 2013-05-22 18:03:09 +0300 | [diff] [blame] | 406 | static void |
| 407 | shell_fade_startup(struct desktop_shell *shell); |
| 408 | |
Philip Withnall | becb77e | 2013-11-25 18:01:30 +0000 | [diff] [blame] | 409 | static struct shell_seat * |
| 410 | get_shell_seat(struct weston_seat *seat); |
| 411 | |
Philip Withnall | 648a4dd | 2013-11-25 18:01:44 +0000 | [diff] [blame^] | 412 | static void |
| 413 | shell_surface_update_child_surface_layers(struct shell_surface *shsurf); |
| 414 | |
Alex Wu | bd3354b | 2012-04-17 17:20:49 +0800 | [diff] [blame] | 415 | static bool |
| 416 | shell_surface_is_top_fullscreen(struct shell_surface *shsurf) |
| 417 | { |
| 418 | struct desktop_shell *shell; |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 419 | struct weston_view *top_fs_ev; |
Alex Wu | bd3354b | 2012-04-17 17:20:49 +0800 | [diff] [blame] | 420 | |
| 421 | shell = shell_surface_get_shell(shsurf); |
Quentin Glidic | c0d79ce | 2013-01-29 14:16:13 +0100 | [diff] [blame] | 422 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 423 | if (wl_list_empty(&shell->fullscreen_layer.view_list)) |
Alex Wu | bd3354b | 2012-04-17 17:20:49 +0800 | [diff] [blame] | 424 | return false; |
| 425 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 426 | top_fs_ev = container_of(shell->fullscreen_layer.view_list.next, |
| 427 | struct weston_view, |
Alex Wu | bd3354b | 2012-04-17 17:20:49 +0800 | [diff] [blame] | 428 | layer_link); |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 429 | return (shsurf == get_shell_surface(top_fs_ev->surface)); |
Alex Wu | bd3354b | 2012-04-17 17:20:49 +0800 | [diff] [blame] | 430 | } |
| 431 | |
Kristian Høgsberg | 6af8eb9 | 2012-01-25 16:57:11 -0500 | [diff] [blame] | 432 | static void |
Kristian Høgsberg | 27e3052 | 2012-04-11 23:18:23 -0400 | [diff] [blame] | 433 | destroy_shell_grab_shsurf(struct wl_listener *listener, void *data) |
Ander Conselvan de Oliveira | fe0444a | 2012-04-04 17:48:05 +0300 | [diff] [blame] | 434 | { |
| 435 | struct shell_grab *grab; |
| 436 | |
| 437 | grab = container_of(listener, struct shell_grab, |
| 438 | shsurf_destroy_listener); |
| 439 | |
| 440 | grab->shsurf = NULL; |
| 441 | } |
| 442 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 443 | static struct weston_view * |
| 444 | get_default_view(struct weston_surface *surface) |
| 445 | { |
| 446 | struct shell_surface *shsurf; |
| 447 | struct weston_view *view; |
| 448 | |
| 449 | if (!surface || wl_list_empty(&surface->views)) |
| 450 | return NULL; |
| 451 | |
| 452 | shsurf = get_shell_surface(surface); |
| 453 | if (shsurf) |
| 454 | return shsurf->view; |
| 455 | |
| 456 | wl_list_for_each(view, &surface->views, surface_link) |
| 457 | if (weston_view_is_mapped(view)) |
| 458 | return view; |
| 459 | |
| 460 | return container_of(surface->views.next, struct weston_view, surface_link); |
| 461 | } |
| 462 | |
Ander Conselvan de Oliveira | fe0444a | 2012-04-04 17:48:05 +0300 | [diff] [blame] | 463 | static void |
Kristian Høgsberg | 02bbabb | 2013-05-06 22:15:05 -0400 | [diff] [blame] | 464 | popup_grab_end(struct weston_pointer *pointer); |
Kristian Høgsberg | 57e0907 | 2012-10-30 14:07:27 -0400 | [diff] [blame] | 465 | |
| 466 | static void |
Ander Conselvan de Oliveira | b9d2a0f | 2012-06-28 18:08:05 +0300 | [diff] [blame] | 467 | shell_grab_start(struct shell_grab *grab, |
Kristian Høgsberg | 02bbabb | 2013-05-06 22:15:05 -0400 | [diff] [blame] | 468 | const struct weston_pointer_grab_interface *interface, |
Ander Conselvan de Oliveira | b9d2a0f | 2012-06-28 18:08:05 +0300 | [diff] [blame] | 469 | struct shell_surface *shsurf, |
Kristian Høgsberg | 02bbabb | 2013-05-06 22:15:05 -0400 | [diff] [blame] | 470 | struct weston_pointer *pointer, |
Ander Conselvan de Oliveira | b9d2a0f | 2012-06-28 18:08:05 +0300 | [diff] [blame] | 471 | enum desktop_shell_cursor cursor) |
Ander Conselvan de Oliveira | fe0444a | 2012-04-04 17:48:05 +0300 | [diff] [blame] | 472 | { |
Ander Conselvan de Oliveira | b9d2a0f | 2012-06-28 18:08:05 +0300 | [diff] [blame] | 473 | struct desktop_shell *shell = shsurf->shell; |
| 474 | |
Kristian Høgsberg | 57e0907 | 2012-10-30 14:07:27 -0400 | [diff] [blame] | 475 | popup_grab_end(pointer); |
| 476 | |
Ander Conselvan de Oliveira | fe0444a | 2012-04-04 17:48:05 +0300 | [diff] [blame] | 477 | grab->grab.interface = interface; |
| 478 | grab->shsurf = shsurf; |
Kristian Høgsberg | 27e3052 | 2012-04-11 23:18:23 -0400 | [diff] [blame] | 479 | grab->shsurf_destroy_listener.notify = destroy_shell_grab_shsurf; |
Jason Ekstrand | 651f00e | 2013-06-14 10:07:54 -0500 | [diff] [blame] | 480 | wl_signal_add(&shsurf->destroy_signal, |
Kristian Høgsberg | 27e3052 | 2012-04-11 23:18:23 -0400 | [diff] [blame] | 481 | &grab->shsurf_destroy_listener); |
Ander Conselvan de Oliveira | fe0444a | 2012-04-04 17:48:05 +0300 | [diff] [blame] | 482 | |
Kristian Høgsberg | c85f1d4 | 2013-10-24 16:52:00 -0700 | [diff] [blame] | 483 | shsurf->grabbed = 1; |
Kristian Høgsberg | 02bbabb | 2013-05-06 22:15:05 -0400 | [diff] [blame] | 484 | weston_pointer_start_grab(pointer, &grab->grab); |
Kristian Høgsberg | c9974a0 | 2013-07-03 19:24:57 -0400 | [diff] [blame] | 485 | if (shell->child.desktop_shell) { |
| 486 | desktop_shell_send_grab_cursor(shell->child.desktop_shell, |
| 487 | cursor); |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 488 | weston_pointer_set_focus(pointer, |
| 489 | get_default_view(shell->grab_surface), |
Kristian Høgsberg | c9974a0 | 2013-07-03 19:24:57 -0400 | [diff] [blame] | 490 | wl_fixed_from_int(0), |
| 491 | wl_fixed_from_int(0)); |
| 492 | } |
Ander Conselvan de Oliveira | fe0444a | 2012-04-04 17:48:05 +0300 | [diff] [blame] | 493 | } |
| 494 | |
| 495 | static void |
Ander Conselvan de Oliveira | b9d2a0f | 2012-06-28 18:08:05 +0300 | [diff] [blame] | 496 | shell_grab_end(struct shell_grab *grab) |
Ander Conselvan de Oliveira | fe0444a | 2012-04-04 17:48:05 +0300 | [diff] [blame] | 497 | { |
Kristian Høgsberg | c85f1d4 | 2013-10-24 16:52:00 -0700 | [diff] [blame] | 498 | if (grab->shsurf) { |
Kristian Høgsberg | 47b5dca | 2012-06-07 18:08:04 -0400 | [diff] [blame] | 499 | wl_list_remove(&grab->shsurf_destroy_listener.link); |
Kristian Høgsberg | c85f1d4 | 2013-10-24 16:52:00 -0700 | [diff] [blame] | 500 | grab->shsurf->grabbed = 0; |
| 501 | } |
Ander Conselvan de Oliveira | b9d2a0f | 2012-06-28 18:08:05 +0300 | [diff] [blame] | 502 | |
Kristian Høgsberg | 9e5d7d1 | 2013-07-22 16:31:53 -0700 | [diff] [blame] | 503 | weston_pointer_end_grab(grab->grab.pointer); |
Ander Conselvan de Oliveira | fe0444a | 2012-04-04 17:48:05 +0300 | [diff] [blame] | 504 | } |
| 505 | |
| 506 | static void |
Rusty Lynch | 1084da5 | 2013-08-15 09:10:08 -0700 | [diff] [blame] | 507 | shell_touch_grab_start(struct shell_touch_grab *grab, |
| 508 | const struct weston_touch_grab_interface *interface, |
| 509 | struct shell_surface *shsurf, |
| 510 | struct weston_touch *touch) |
| 511 | { |
| 512 | struct desktop_shell *shell = shsurf->shell; |
| 513 | |
| 514 | grab->grab.interface = interface; |
| 515 | grab->shsurf = shsurf; |
| 516 | grab->shsurf_destroy_listener.notify = destroy_shell_grab_shsurf; |
| 517 | wl_signal_add(&shsurf->destroy_signal, |
| 518 | &grab->shsurf_destroy_listener); |
| 519 | |
| 520 | grab->touch = touch; |
Kristian Høgsberg | c85f1d4 | 2013-10-24 16:52:00 -0700 | [diff] [blame] | 521 | shsurf->grabbed = 1; |
Rusty Lynch | 1084da5 | 2013-08-15 09:10:08 -0700 | [diff] [blame] | 522 | |
| 523 | weston_touch_start_grab(touch, &grab->grab); |
| 524 | if (shell->child.desktop_shell) |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 525 | weston_touch_set_focus(touch->seat, |
| 526 | get_default_view(shell->grab_surface)); |
Rusty Lynch | 1084da5 | 2013-08-15 09:10:08 -0700 | [diff] [blame] | 527 | } |
| 528 | |
| 529 | static void |
| 530 | shell_touch_grab_end(struct shell_touch_grab *grab) |
| 531 | { |
Kristian Høgsberg | c85f1d4 | 2013-10-24 16:52:00 -0700 | [diff] [blame] | 532 | if (grab->shsurf) { |
Rusty Lynch | 1084da5 | 2013-08-15 09:10:08 -0700 | [diff] [blame] | 533 | wl_list_remove(&grab->shsurf_destroy_listener.link); |
Kristian Høgsberg | c85f1d4 | 2013-10-24 16:52:00 -0700 | [diff] [blame] | 534 | grab->shsurf->grabbed = 0; |
| 535 | } |
Rusty Lynch | 1084da5 | 2013-08-15 09:10:08 -0700 | [diff] [blame] | 536 | |
| 537 | weston_touch_end_grab(grab->touch); |
| 538 | } |
| 539 | |
| 540 | static void |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 541 | center_on_output(struct weston_view *view, |
Alex Wu | 4539b08 | 2012-03-01 12:57:46 +0800 | [diff] [blame] | 542 | struct weston_output *output); |
| 543 | |
Daniel Stone | 496ca17 | 2012-05-30 16:31:42 +0100 | [diff] [blame] | 544 | static enum weston_keyboard_modifier |
Tiago Vignatti | 0b52d48 | 2012-04-20 18:54:25 +0300 | [diff] [blame] | 545 | get_modifier(char *modifier) |
| 546 | { |
| 547 | if (!modifier) |
| 548 | return MODIFIER_SUPER; |
| 549 | |
| 550 | if (!strcmp("ctrl", modifier)) |
| 551 | return MODIFIER_CTRL; |
| 552 | else if (!strcmp("alt", modifier)) |
| 553 | return MODIFIER_ALT; |
| 554 | else if (!strcmp("super", modifier)) |
| 555 | return MODIFIER_SUPER; |
| 556 | else |
| 557 | return MODIFIER_SUPER; |
| 558 | } |
| 559 | |
Juan Zhao | e10d279 | 2012-04-25 19:09:52 +0800 | [diff] [blame] | 560 | static enum animation_type |
| 561 | get_animation_type(char *animation) |
| 562 | { |
Juan Zhao | e10d279 | 2012-04-25 19:09:52 +0800 | [diff] [blame] | 563 | if (!strcmp("zoom", animation)) |
| 564 | return ANIMATION_ZOOM; |
| 565 | else if (!strcmp("fade", animation)) |
| 566 | return ANIMATION_FADE; |
Louis-Francis Ratté-Boulianne | b482dbd | 2013-11-19 11:37:11 +0100 | [diff] [blame] | 567 | else if (!strcmp("dim-layer", animation)) |
| 568 | return ANIMATION_DIM_LAYER; |
Juan Zhao | e10d279 | 2012-04-25 19:09:52 +0800 | [diff] [blame] | 569 | else |
| 570 | return ANIMATION_NONE; |
| 571 | } |
| 572 | |
Alex Wu | 4539b08 | 2012-03-01 12:57:46 +0800 | [diff] [blame] | 573 | static void |
Kristian Høgsberg | 14e438c | 2013-05-26 21:48:14 -0400 | [diff] [blame] | 574 | shell_configuration(struct desktop_shell *shell) |
Pekka Paalanen | e955f1e | 2011-12-07 11:49:52 +0200 | [diff] [blame] | 575 | { |
Kristian Høgsberg | 673a889 | 2013-05-23 21:40:56 -0400 | [diff] [blame] | 576 | struct weston_config_section *section; |
| 577 | int duration; |
| 578 | char *s; |
Pekka Paalanen | e955f1e | 2011-12-07 11:49:52 +0200 | [diff] [blame] | 579 | |
Kristian Høgsberg | 673a889 | 2013-05-23 21:40:56 -0400 | [diff] [blame] | 580 | section = weston_config_get_section(shell->compositor->config, |
| 581 | "screensaver", NULL, NULL); |
| 582 | weston_config_section_get_string(section, |
| 583 | "path", &shell->screensaver.path, NULL); |
| 584 | weston_config_section_get_int(section, "duration", &duration, 60); |
Ander Conselvan de Oliveira | 859e885 | 2013-02-21 18:35:21 +0200 | [diff] [blame] | 585 | shell->screensaver.duration = duration * 1000; |
Kristian Høgsberg | 673a889 | 2013-05-23 21:40:56 -0400 | [diff] [blame] | 586 | |
| 587 | section = weston_config_get_section(shell->compositor->config, |
| 588 | "shell", NULL, NULL); |
| 589 | weston_config_section_get_string(section, |
Emilio Pozuelo Monfort | 46ce798 | 2013-11-20 13:22:29 +0100 | [diff] [blame] | 590 | "client", &s, LIBEXECDIR "/weston-desktop-shell"); |
| 591 | shell->client = s; |
| 592 | weston_config_section_get_string(section, |
Kristian Høgsberg | 673a889 | 2013-05-23 21:40:56 -0400 | [diff] [blame] | 593 | "binding-modifier", &s, "super"); |
| 594 | shell->binding_modifier = get_modifier(s); |
Quentin Glidic | 8418c29 | 2013-06-18 09:11:03 +0200 | [diff] [blame] | 595 | free(s); |
Kristian Høgsberg | 673a889 | 2013-05-23 21:40:56 -0400 | [diff] [blame] | 596 | weston_config_section_get_string(section, "animation", &s, "none"); |
| 597 | shell->win_animation_type = get_animation_type(s); |
Quentin Glidic | 8418c29 | 2013-06-18 09:11:03 +0200 | [diff] [blame] | 598 | free(s); |
Kristian Høgsberg | 724c8d9 | 2013-10-16 11:38:24 -0700 | [diff] [blame] | 599 | weston_config_section_get_string(section, |
| 600 | "startup-animation", &s, "fade"); |
| 601 | shell->startup_animation_type = get_animation_type(s); |
| 602 | free(s); |
Kristian Høgsberg | 912e0a1 | 2013-10-30 08:59:55 -0700 | [diff] [blame] | 603 | if (shell->startup_animation_type == ANIMATION_ZOOM) |
| 604 | shell->startup_animation_type = ANIMATION_NONE; |
Louis-Francis Ratté-Boulianne | b482dbd | 2013-11-19 11:37:11 +0100 | [diff] [blame] | 605 | weston_config_section_get_string(section, "focus-animation", &s, "none"); |
| 606 | shell->focus_animation_type = get_animation_type(s); |
| 607 | free(s); |
Kristian Høgsberg | 673a889 | 2013-05-23 21:40:56 -0400 | [diff] [blame] | 608 | weston_config_section_get_uint(section, "num-workspaces", |
| 609 | &shell->workspaces.num, |
| 610 | DEFAULT_NUM_WORKSPACES); |
Jonas Ådahl | e3cddce | 2012-06-13 00:01:22 +0200 | [diff] [blame] | 611 | } |
| 612 | |
Louis-Francis Ratté-Boulianne | b482dbd | 2013-11-19 11:37:11 +0100 | [diff] [blame] | 613 | static struct weston_output * |
| 614 | get_default_output(struct weston_compositor *compositor) |
| 615 | { |
| 616 | return container_of(compositor->output_list.next, |
| 617 | struct weston_output, link); |
| 618 | } |
| 619 | |
| 620 | |
| 621 | /* no-op func for checking focus surface */ |
| 622 | static void |
| 623 | focus_surface_configure(struct weston_surface *es, int32_t sx, int32_t sy, |
| 624 | int32_t width, int32_t height) |
| 625 | { |
| 626 | } |
| 627 | |
| 628 | static struct focus_surface * |
| 629 | get_focus_surface(struct weston_surface *surface) |
| 630 | { |
| 631 | if (surface->configure == focus_surface_configure) |
| 632 | return surface->configure_private; |
| 633 | else |
| 634 | return NULL; |
| 635 | } |
| 636 | |
| 637 | static bool |
| 638 | is_focus_surface (struct weston_surface *es) |
| 639 | { |
| 640 | return (es->configure == focus_surface_configure); |
| 641 | } |
| 642 | |
| 643 | static bool |
| 644 | is_focus_view (struct weston_view *view) |
| 645 | { |
| 646 | return is_focus_surface (view->surface); |
| 647 | } |
| 648 | |
| 649 | static struct focus_surface * |
| 650 | create_focus_surface(struct weston_compositor *ec, |
| 651 | struct weston_output *output) |
| 652 | { |
| 653 | struct focus_surface *fsurf = NULL; |
| 654 | struct weston_surface *surface = NULL; |
| 655 | |
| 656 | fsurf = malloc(sizeof *fsurf); |
| 657 | if (!fsurf) |
| 658 | return NULL; |
| 659 | |
| 660 | fsurf->surface = weston_surface_create(ec); |
| 661 | surface = fsurf->surface; |
| 662 | if (surface == NULL) { |
| 663 | free(fsurf); |
| 664 | return NULL; |
| 665 | } |
| 666 | |
| 667 | surface->configure = focus_surface_configure; |
| 668 | surface->output = output; |
| 669 | surface->configure_private = fsurf; |
| 670 | |
| 671 | fsurf->view = weston_view_create (surface); |
Emilio Pozuelo Monfort | da64426 | 2013-11-19 11:37:19 +0100 | [diff] [blame] | 672 | fsurf->view->output = output; |
Louis-Francis Ratté-Boulianne | b482dbd | 2013-11-19 11:37:11 +0100 | [diff] [blame] | 673 | |
| 674 | weston_view_configure(fsurf->view, output->x, output->y, |
| 675 | output->width, output->height); |
| 676 | weston_surface_set_color(surface, 0.0, 0.0, 0.0, 1.0); |
| 677 | pixman_region32_fini(&surface->opaque); |
| 678 | pixman_region32_init_rect(&surface->opaque, output->x, output->y, |
| 679 | output->width, output->height); |
| 680 | pixman_region32_fini(&surface->input); |
| 681 | pixman_region32_init(&surface->input); |
| 682 | |
| 683 | wl_list_init(&fsurf->workspace_transform.link); |
| 684 | |
| 685 | return fsurf; |
| 686 | } |
| 687 | |
| 688 | static void |
| 689 | focus_surface_destroy(struct focus_surface *fsurf) |
| 690 | { |
| 691 | weston_surface_destroy(fsurf->surface); |
| 692 | free(fsurf); |
| 693 | } |
| 694 | |
| 695 | static void |
| 696 | focus_animation_done(struct weston_view_animation *animation, void *data) |
| 697 | { |
| 698 | struct workspace *ws = data; |
| 699 | |
| 700 | ws->focus_animation = NULL; |
| 701 | } |
| 702 | |
Jonas Ådahl | e3cddce | 2012-06-13 00:01:22 +0200 | [diff] [blame] | 703 | static void |
Jonas Ådahl | 0476974 | 2012-06-13 00:01:24 +0200 | [diff] [blame] | 704 | focus_state_destroy(struct focus_state *state) |
| 705 | { |
| 706 | wl_list_remove(&state->seat_destroy_listener.link); |
| 707 | wl_list_remove(&state->surface_destroy_listener.link); |
| 708 | free(state); |
| 709 | } |
| 710 | |
| 711 | static void |
| 712 | focus_state_seat_destroy(struct wl_listener *listener, void *data) |
| 713 | { |
| 714 | struct focus_state *state = container_of(listener, |
| 715 | struct focus_state, |
| 716 | seat_destroy_listener); |
| 717 | |
| 718 | wl_list_remove(&state->link); |
| 719 | focus_state_destroy(state); |
| 720 | } |
| 721 | |
| 722 | static void |
| 723 | focus_state_surface_destroy(struct wl_listener *listener, void *data) |
| 724 | { |
| 725 | struct focus_state *state = container_of(listener, |
| 726 | struct focus_state, |
Kristian Høgsberg | b8e0d0f | 2012-07-31 10:30:26 -0400 | [diff] [blame] | 727 | surface_destroy_listener); |
Kristian Høgsberg | e377822 | 2012-07-31 17:29:30 -0400 | [diff] [blame] | 728 | struct desktop_shell *shell; |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 729 | struct weston_surface *main_surface, *next; |
| 730 | struct weston_view *view; |
Jonas Ådahl | 0476974 | 2012-06-13 00:01:24 +0200 | [diff] [blame] | 731 | |
Pekka Paalanen | 01388e2 | 2013-04-25 13:57:44 +0300 | [diff] [blame] | 732 | main_surface = weston_surface_get_main_surface(state->keyboard_focus); |
| 733 | |
Kristian Høgsberg | e377822 | 2012-07-31 17:29:30 -0400 | [diff] [blame] | 734 | next = NULL; |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 735 | wl_list_for_each(view, &state->ws->layer.view_list, layer_link) { |
| 736 | if (view->surface == main_surface) |
Kristian Høgsberg | e377822 | 2012-07-31 17:29:30 -0400 | [diff] [blame] | 737 | continue; |
Louis-Francis Ratté-Boulianne | b482dbd | 2013-11-19 11:37:11 +0100 | [diff] [blame] | 738 | if (is_focus_view(view)) |
| 739 | continue; |
Kristian Høgsberg | e377822 | 2012-07-31 17:29:30 -0400 | [diff] [blame] | 740 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 741 | next = view->surface; |
Kristian Høgsberg | e377822 | 2012-07-31 17:29:30 -0400 | [diff] [blame] | 742 | break; |
| 743 | } |
| 744 | |
Pekka Paalanen | 01388e2 | 2013-04-25 13:57:44 +0300 | [diff] [blame] | 745 | /* if the focus was a sub-surface, activate its main surface */ |
| 746 | if (main_surface != state->keyboard_focus) |
| 747 | next = main_surface; |
| 748 | |
Louis-Francis Ratté-Boulianne | b482dbd | 2013-11-19 11:37:11 +0100 | [diff] [blame] | 749 | shell = state->seat->compositor->shell_interface.shell; |
Kristian Høgsberg | e377822 | 2012-07-31 17:29:30 -0400 | [diff] [blame] | 750 | if (next) { |
Louis-Francis Ratté-Boulianne | b482dbd | 2013-11-19 11:37:11 +0100 | [diff] [blame] | 751 | state->keyboard_focus = NULL; |
Kristian Høgsberg | e377822 | 2012-07-31 17:29:30 -0400 | [diff] [blame] | 752 | activate(shell, next, state->seat); |
| 753 | } else { |
Louis-Francis Ratté-Boulianne | b482dbd | 2013-11-19 11:37:11 +0100 | [diff] [blame] | 754 | if (shell->focus_animation_type == ANIMATION_DIM_LAYER) { |
| 755 | if (state->ws->focus_animation) |
| 756 | weston_view_animation_destroy(state->ws->focus_animation); |
| 757 | |
| 758 | state->ws->focus_animation = weston_fade_run( |
| 759 | state->ws->fsurf_front->view, |
| 760 | state->ws->fsurf_front->view->alpha, 0.0, 300, |
| 761 | focus_animation_done, state->ws); |
| 762 | } |
| 763 | |
Kristian Høgsberg | e377822 | 2012-07-31 17:29:30 -0400 | [diff] [blame] | 764 | wl_list_remove(&state->link); |
| 765 | focus_state_destroy(state); |
| 766 | } |
Jonas Ådahl | 0476974 | 2012-06-13 00:01:24 +0200 | [diff] [blame] | 767 | } |
| 768 | |
| 769 | static struct focus_state * |
Kristian Høgsberg | 2f5faff | 2012-07-31 16:36:34 -0400 | [diff] [blame] | 770 | focus_state_create(struct weston_seat *seat, struct workspace *ws) |
Jonas Ådahl | 0476974 | 2012-06-13 00:01:24 +0200 | [diff] [blame] | 771 | { |
Jonas Ådahl | 0476974 | 2012-06-13 00:01:24 +0200 | [diff] [blame] | 772 | struct focus_state *state; |
Jonas Ådahl | 0476974 | 2012-06-13 00:01:24 +0200 | [diff] [blame] | 773 | |
| 774 | state = malloc(sizeof *state); |
| 775 | if (state == NULL) |
| 776 | return NULL; |
| 777 | |
Louis-Francis Ratté-Boulianne | b482dbd | 2013-11-19 11:37:11 +0100 | [diff] [blame] | 778 | state->keyboard_focus = NULL; |
Kristian Høgsberg | 2f5faff | 2012-07-31 16:36:34 -0400 | [diff] [blame] | 779 | state->ws = ws; |
Jonas Ådahl | 0476974 | 2012-06-13 00:01:24 +0200 | [diff] [blame] | 780 | state->seat = seat; |
Kristian Høgsberg | 2f5faff | 2012-07-31 16:36:34 -0400 | [diff] [blame] | 781 | wl_list_insert(&ws->focus_list, &state->link); |
Jonas Ådahl | 0476974 | 2012-06-13 00:01:24 +0200 | [diff] [blame] | 782 | |
| 783 | state->seat_destroy_listener.notify = focus_state_seat_destroy; |
| 784 | state->surface_destroy_listener.notify = focus_state_surface_destroy; |
Kristian Høgsberg | 4912454 | 2013-05-06 22:27:40 -0400 | [diff] [blame] | 785 | wl_signal_add(&seat->destroy_signal, |
Jonas Ådahl | 0476974 | 2012-06-13 00:01:24 +0200 | [diff] [blame] | 786 | &state->seat_destroy_listener); |
Kristian Høgsberg | 2f5faff | 2012-07-31 16:36:34 -0400 | [diff] [blame] | 787 | wl_list_init(&state->surface_destroy_listener.link); |
Jonas Ådahl | 0476974 | 2012-06-13 00:01:24 +0200 | [diff] [blame] | 788 | |
| 789 | return state; |
| 790 | } |
| 791 | |
Jonas Ådahl | 8538b22 | 2012-08-29 22:13:03 +0200 | [diff] [blame] | 792 | static struct focus_state * |
| 793 | ensure_focus_state(struct desktop_shell *shell, struct weston_seat *seat) |
| 794 | { |
| 795 | struct workspace *ws = get_current_workspace(shell); |
| 796 | struct focus_state *state; |
| 797 | |
| 798 | wl_list_for_each(state, &ws->focus_list, link) |
| 799 | if (state->seat == seat) |
| 800 | break; |
| 801 | |
| 802 | if (&state->link == &ws->focus_list) |
| 803 | state = focus_state_create(seat, ws); |
| 804 | |
| 805 | return state; |
| 806 | } |
| 807 | |
Jonas Ådahl | 0476974 | 2012-06-13 00:01:24 +0200 | [diff] [blame] | 808 | static void |
Kristian Høgsberg | 2f5faff | 2012-07-31 16:36:34 -0400 | [diff] [blame] | 809 | restore_focus_state(struct desktop_shell *shell, struct workspace *ws) |
Jonas Ådahl | 0476974 | 2012-06-13 00:01:24 +0200 | [diff] [blame] | 810 | { |
| 811 | struct focus_state *state, *next; |
Kristian Høgsberg | fe7aa90 | 2013-05-08 09:54:37 -0400 | [diff] [blame] | 812 | struct weston_surface *surface; |
Jonas Ådahl | 0476974 | 2012-06-13 00:01:24 +0200 | [diff] [blame] | 813 | |
| 814 | wl_list_for_each_safe(state, next, &ws->focus_list, link) { |
Kristian Høgsberg | fe7aa90 | 2013-05-08 09:54:37 -0400 | [diff] [blame] | 815 | surface = state->keyboard_focus; |
Jonas Ådahl | 5689944 | 2012-08-29 22:12:59 +0200 | [diff] [blame] | 816 | |
Kristian Høgsberg | e314875 | 2013-05-06 23:19:49 -0400 | [diff] [blame] | 817 | weston_keyboard_set_focus(state->seat->keyboard, surface); |
Jonas Ådahl | 0476974 | 2012-06-13 00:01:24 +0200 | [diff] [blame] | 818 | } |
| 819 | } |
| 820 | |
| 821 | static void |
Jonas Ådahl | 8de6a1d | 2012-08-29 22:13:00 +0200 | [diff] [blame] | 822 | replace_focus_state(struct desktop_shell *shell, struct workspace *ws, |
| 823 | struct weston_seat *seat) |
| 824 | { |
| 825 | struct focus_state *state; |
Kristian Høgsberg | fe7aa90 | 2013-05-08 09:54:37 -0400 | [diff] [blame] | 826 | struct weston_surface *surface; |
Jonas Ådahl | 8de6a1d | 2012-08-29 22:13:00 +0200 | [diff] [blame] | 827 | |
| 828 | wl_list_for_each(state, &ws->focus_list, link) { |
| 829 | if (state->seat == seat) { |
Kristian Høgsberg | e314875 | 2013-05-06 23:19:49 -0400 | [diff] [blame] | 830 | surface = seat->keyboard->focus; |
Jason Ekstrand | 651f00e | 2013-06-14 10:07:54 -0500 | [diff] [blame] | 831 | state->keyboard_focus = surface; |
Jonas Ådahl | 8de6a1d | 2012-08-29 22:13:00 +0200 | [diff] [blame] | 832 | return; |
| 833 | } |
| 834 | } |
| 835 | } |
| 836 | |
| 837 | static void |
| 838 | drop_focus_state(struct desktop_shell *shell, struct workspace *ws, |
| 839 | struct weston_surface *surface) |
| 840 | { |
| 841 | struct focus_state *state; |
| 842 | |
| 843 | wl_list_for_each(state, &ws->focus_list, link) |
| 844 | if (state->keyboard_focus == surface) |
| 845 | state->keyboard_focus = NULL; |
| 846 | } |
| 847 | |
| 848 | static void |
Louis-Francis Ratté-Boulianne | b482dbd | 2013-11-19 11:37:11 +0100 | [diff] [blame] | 849 | animate_focus_change(struct desktop_shell *shell, struct workspace *ws, |
| 850 | struct weston_view *from, struct weston_view *to) |
| 851 | { |
| 852 | struct weston_output *output; |
| 853 | bool focus_surface_created = false; |
| 854 | |
| 855 | /* FIXME: Only support dim animation using two layers */ |
| 856 | if (from == to || shell->focus_animation_type != ANIMATION_DIM_LAYER) |
| 857 | return; |
| 858 | |
| 859 | output = get_default_output(shell->compositor); |
| 860 | if (ws->fsurf_front == NULL && (from || to)) { |
| 861 | ws->fsurf_front = create_focus_surface(shell->compositor, output); |
| 862 | ws->fsurf_back = create_focus_surface(shell->compositor, output); |
| 863 | ws->fsurf_front->view->alpha = 0.0; |
| 864 | ws->fsurf_back->view->alpha = 0.0; |
| 865 | focus_surface_created = true; |
| 866 | } else { |
| 867 | wl_list_remove(&ws->fsurf_front->view->layer_link); |
| 868 | wl_list_remove(&ws->fsurf_back->view->layer_link); |
| 869 | } |
| 870 | |
| 871 | if (ws->focus_animation) { |
| 872 | weston_view_animation_destroy(ws->focus_animation); |
| 873 | ws->focus_animation = NULL; |
| 874 | } |
| 875 | |
| 876 | if (to) |
| 877 | wl_list_insert(&to->layer_link, |
| 878 | &ws->fsurf_front->view->layer_link); |
| 879 | else if (from) |
| 880 | wl_list_insert(&ws->layer.view_list, |
| 881 | &ws->fsurf_front->view->layer_link); |
| 882 | |
| 883 | if (focus_surface_created) { |
| 884 | ws->focus_animation = weston_fade_run( |
| 885 | ws->fsurf_front->view, |
| 886 | ws->fsurf_front->view->alpha, 0.6, 300, |
| 887 | focus_animation_done, ws); |
| 888 | } else if (from) { |
| 889 | wl_list_insert(&from->layer_link, |
| 890 | &ws->fsurf_back->view->layer_link); |
| 891 | ws->focus_animation = weston_stable_fade_run( |
| 892 | ws->fsurf_front->view, 0.0, |
| 893 | ws->fsurf_back->view, 0.6, |
| 894 | focus_animation_done, ws); |
| 895 | } else if (to) { |
| 896 | wl_list_insert(&ws->layer.view_list, |
| 897 | &ws->fsurf_back->view->layer_link); |
| 898 | ws->focus_animation = weston_stable_fade_run( |
| 899 | ws->fsurf_front->view, 0.0, |
| 900 | ws->fsurf_back->view, 0.6, |
| 901 | focus_animation_done, ws); |
| 902 | } |
| 903 | } |
| 904 | |
| 905 | static void |
Jonas Ådahl | e3cddce | 2012-06-13 00:01:22 +0200 | [diff] [blame] | 906 | workspace_destroy(struct workspace *ws) |
| 907 | { |
Jonas Ådahl | 0476974 | 2012-06-13 00:01:24 +0200 | [diff] [blame] | 908 | struct focus_state *state, *next; |
| 909 | |
| 910 | wl_list_for_each_safe(state, next, &ws->focus_list, link) |
| 911 | focus_state_destroy(state); |
| 912 | |
Louis-Francis Ratté-Boulianne | b482dbd | 2013-11-19 11:37:11 +0100 | [diff] [blame] | 913 | if (ws->fsurf_front) |
| 914 | focus_surface_destroy(ws->fsurf_front); |
| 915 | if (ws->fsurf_back) |
| 916 | focus_surface_destroy(ws->fsurf_back); |
| 917 | |
Jonas Ådahl | e3cddce | 2012-06-13 00:01:22 +0200 | [diff] [blame] | 918 | free(ws); |
| 919 | } |
| 920 | |
Jonas Ådahl | 0476974 | 2012-06-13 00:01:24 +0200 | [diff] [blame] | 921 | static void |
| 922 | seat_destroyed(struct wl_listener *listener, void *data) |
| 923 | { |
| 924 | struct weston_seat *seat = data; |
| 925 | struct focus_state *state, *next; |
| 926 | struct workspace *ws = container_of(listener, |
| 927 | struct workspace, |
| 928 | seat_destroyed_listener); |
| 929 | |
| 930 | wl_list_for_each_safe(state, next, &ws->focus_list, link) |
| 931 | if (state->seat == seat) |
| 932 | wl_list_remove(&state->link); |
| 933 | } |
| 934 | |
Jonas Ådahl | e3cddce | 2012-06-13 00:01:22 +0200 | [diff] [blame] | 935 | static struct workspace * |
| 936 | workspace_create(void) |
| 937 | { |
| 938 | struct workspace *ws = malloc(sizeof *ws); |
| 939 | if (ws == NULL) |
| 940 | return NULL; |
| 941 | |
| 942 | weston_layer_init(&ws->layer, NULL); |
| 943 | |
Jonas Ådahl | 0476974 | 2012-06-13 00:01:24 +0200 | [diff] [blame] | 944 | wl_list_init(&ws->focus_list); |
| 945 | wl_list_init(&ws->seat_destroyed_listener.link); |
| 946 | ws->seat_destroyed_listener.notify = seat_destroyed; |
Louis-Francis Ratté-Boulianne | b482dbd | 2013-11-19 11:37:11 +0100 | [diff] [blame] | 947 | ws->fsurf_front = NULL; |
| 948 | ws->fsurf_back = NULL; |
| 949 | ws->focus_animation = NULL; |
Jonas Ådahl | 0476974 | 2012-06-13 00:01:24 +0200 | [diff] [blame] | 950 | |
Jonas Ådahl | e3cddce | 2012-06-13 00:01:22 +0200 | [diff] [blame] | 951 | return ws; |
| 952 | } |
| 953 | |
Jonas Ådahl | 62fcd04 | 2012-06-13 00:01:23 +0200 | [diff] [blame] | 954 | static int |
| 955 | workspace_is_empty(struct workspace *ws) |
| 956 | { |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 957 | return wl_list_empty(&ws->layer.view_list); |
Jonas Ådahl | 62fcd04 | 2012-06-13 00:01:23 +0200 | [diff] [blame] | 958 | } |
| 959 | |
Jonas Ådahl | e3cddce | 2012-06-13 00:01:22 +0200 | [diff] [blame] | 960 | static struct workspace * |
| 961 | get_workspace(struct desktop_shell *shell, unsigned int index) |
| 962 | { |
| 963 | struct workspace **pws = shell->workspaces.array.data; |
Philipp Brüschweiler | 067abf6 | 2012-09-01 16:03:05 +0200 | [diff] [blame] | 964 | assert(index < shell->workspaces.num); |
Jonas Ådahl | e3cddce | 2012-06-13 00:01:22 +0200 | [diff] [blame] | 965 | pws += index; |
| 966 | return *pws; |
| 967 | } |
| 968 | |
| 969 | static struct workspace * |
| 970 | get_current_workspace(struct desktop_shell *shell) |
| 971 | { |
| 972 | return get_workspace(shell, shell->workspaces.current); |
| 973 | } |
| 974 | |
| 975 | static void |
| 976 | activate_workspace(struct desktop_shell *shell, unsigned int index) |
| 977 | { |
| 978 | struct workspace *ws; |
| 979 | |
| 980 | ws = get_workspace(shell, index); |
| 981 | wl_list_insert(&shell->panel_layer.link, &ws->layer.link); |
| 982 | |
| 983 | shell->workspaces.current = index; |
| 984 | } |
| 985 | |
Jonas Ådahl | 62fcd04 | 2012-06-13 00:01:23 +0200 | [diff] [blame] | 986 | static unsigned int |
| 987 | get_output_height(struct weston_output *output) |
| 988 | { |
| 989 | return abs(output->region.extents.y1 - output->region.extents.y2); |
| 990 | } |
| 991 | |
| 992 | static void |
Louis-Francis Ratté-Boulianne | b482dbd | 2013-11-19 11:37:11 +0100 | [diff] [blame] | 993 | view_translate(struct workspace *ws, struct weston_view *view, double d) |
Jonas Ådahl | 62fcd04 | 2012-06-13 00:01:23 +0200 | [diff] [blame] | 994 | { |
Jonas Ådahl | 62fcd04 | 2012-06-13 00:01:23 +0200 | [diff] [blame] | 995 | struct weston_transform *transform; |
| 996 | |
Louis-Francis Ratté-Boulianne | b482dbd | 2013-11-19 11:37:11 +0100 | [diff] [blame] | 997 | if (is_focus_view(view)) { |
| 998 | struct focus_surface *fsurf = get_focus_surface(view->surface); |
| 999 | transform = &fsurf->workspace_transform; |
| 1000 | } else { |
| 1001 | struct shell_surface *shsurf = get_shell_surface(view->surface); |
| 1002 | transform = &shsurf->workspace_transform; |
| 1003 | } |
| 1004 | |
Jonas Ådahl | 62fcd04 | 2012-06-13 00:01:23 +0200 | [diff] [blame] | 1005 | if (wl_list_empty(&transform->link)) |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 1006 | wl_list_insert(view->geometry.transformation_list.prev, |
Louis-Francis Ratté-Boulianne | b482dbd | 2013-11-19 11:37:11 +0100 | [diff] [blame] | 1007 | &transform->link); |
Jonas Ådahl | 62fcd04 | 2012-06-13 00:01:23 +0200 | [diff] [blame] | 1008 | |
Louis-Francis Ratté-Boulianne | b482dbd | 2013-11-19 11:37:11 +0100 | [diff] [blame] | 1009 | weston_matrix_init(&transform->matrix); |
| 1010 | weston_matrix_translate(&transform->matrix, |
Jonas Ådahl | 62fcd04 | 2012-06-13 00:01:23 +0200 | [diff] [blame] | 1011 | 0.0, d, 0.0); |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 1012 | weston_view_geometry_dirty(view); |
Jonas Ådahl | 62fcd04 | 2012-06-13 00:01:23 +0200 | [diff] [blame] | 1013 | } |
| 1014 | |
| 1015 | static void |
| 1016 | workspace_translate_out(struct workspace *ws, double fraction) |
| 1017 | { |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 1018 | struct weston_view *view; |
Jonas Ådahl | 62fcd04 | 2012-06-13 00:01:23 +0200 | [diff] [blame] | 1019 | unsigned int height; |
| 1020 | double d; |
| 1021 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 1022 | wl_list_for_each(view, &ws->layer.view_list, layer_link) { |
| 1023 | height = get_output_height(view->surface->output); |
Jonas Ådahl | 62fcd04 | 2012-06-13 00:01:23 +0200 | [diff] [blame] | 1024 | d = height * fraction; |
| 1025 | |
Louis-Francis Ratté-Boulianne | b482dbd | 2013-11-19 11:37:11 +0100 | [diff] [blame] | 1026 | view_translate(ws, view, d); |
Jonas Ådahl | 62fcd04 | 2012-06-13 00:01:23 +0200 | [diff] [blame] | 1027 | } |
| 1028 | } |
| 1029 | |
| 1030 | static void |
| 1031 | workspace_translate_in(struct workspace *ws, double fraction) |
| 1032 | { |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 1033 | struct weston_view *view; |
Jonas Ådahl | 62fcd04 | 2012-06-13 00:01:23 +0200 | [diff] [blame] | 1034 | unsigned int height; |
| 1035 | double d; |
| 1036 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 1037 | wl_list_for_each(view, &ws->layer.view_list, layer_link) { |
| 1038 | height = get_output_height(view->surface->output); |
Jonas Ådahl | 62fcd04 | 2012-06-13 00:01:23 +0200 | [diff] [blame] | 1039 | |
| 1040 | if (fraction > 0) |
| 1041 | d = -(height - height * fraction); |
| 1042 | else |
| 1043 | d = height + height * fraction; |
| 1044 | |
Louis-Francis Ratté-Boulianne | b482dbd | 2013-11-19 11:37:11 +0100 | [diff] [blame] | 1045 | view_translate(ws, view, d); |
Jonas Ådahl | 62fcd04 | 2012-06-13 00:01:23 +0200 | [diff] [blame] | 1046 | } |
| 1047 | } |
| 1048 | |
| 1049 | static void |
Jonas Ådahl | e9d2250 | 2012-08-29 22:13:01 +0200 | [diff] [blame] | 1050 | broadcast_current_workspace_state(struct desktop_shell *shell) |
| 1051 | { |
Kristian Høgsberg | 2e3c396 | 2013-09-11 12:00:47 -0700 | [diff] [blame] | 1052 | struct wl_resource *resource; |
Jonas Ådahl | e9d2250 | 2012-08-29 22:13:01 +0200 | [diff] [blame] | 1053 | |
Kristian Høgsberg | 2e3c396 | 2013-09-11 12:00:47 -0700 | [diff] [blame] | 1054 | wl_resource_for_each(resource, &shell->workspaces.client_list) |
| 1055 | workspace_manager_send_state(resource, |
Jonas Ådahl | e9d2250 | 2012-08-29 22:13:01 +0200 | [diff] [blame] | 1056 | shell->workspaces.current, |
| 1057 | shell->workspaces.num); |
| 1058 | } |
| 1059 | |
| 1060 | static void |
Jonas Ådahl | 62fcd04 | 2012-06-13 00:01:23 +0200 | [diff] [blame] | 1061 | reverse_workspace_change_animation(struct desktop_shell *shell, |
| 1062 | unsigned int index, |
| 1063 | struct workspace *from, |
| 1064 | struct workspace *to) |
| 1065 | { |
| 1066 | shell->workspaces.current = index; |
| 1067 | |
| 1068 | shell->workspaces.anim_to = to; |
| 1069 | shell->workspaces.anim_from = from; |
| 1070 | shell->workspaces.anim_dir = -1 * shell->workspaces.anim_dir; |
| 1071 | shell->workspaces.anim_timestamp = 0; |
| 1072 | |
Scott Moreau | 4272e63 | 2012-08-13 09:58:41 -0600 | [diff] [blame] | 1073 | weston_compositor_schedule_repaint(shell->compositor); |
Jonas Ådahl | 62fcd04 | 2012-06-13 00:01:23 +0200 | [diff] [blame] | 1074 | } |
| 1075 | |
| 1076 | static void |
| 1077 | workspace_deactivate_transforms(struct workspace *ws) |
| 1078 | { |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 1079 | struct weston_view *view; |
Louis-Francis Ratté-Boulianne | b482dbd | 2013-11-19 11:37:11 +0100 | [diff] [blame] | 1080 | struct weston_transform *transform; |
Jonas Ådahl | 62fcd04 | 2012-06-13 00:01:23 +0200 | [diff] [blame] | 1081 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 1082 | 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] | 1083 | if (is_focus_view(view)) { |
| 1084 | struct focus_surface *fsurf = get_focus_surface(view->surface); |
| 1085 | transform = &fsurf->workspace_transform; |
| 1086 | } else { |
| 1087 | struct shell_surface *shsurf = get_shell_surface(view->surface); |
| 1088 | transform = &shsurf->workspace_transform; |
| 1089 | } |
| 1090 | |
| 1091 | if (!wl_list_empty(&transform->link)) { |
| 1092 | wl_list_remove(&transform->link); |
| 1093 | wl_list_init(&transform->link); |
Jonas Ådahl | 8de6a1d | 2012-08-29 22:13:00 +0200 | [diff] [blame] | 1094 | } |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 1095 | weston_view_geometry_dirty(view); |
Jonas Ådahl | 62fcd04 | 2012-06-13 00:01:23 +0200 | [diff] [blame] | 1096 | } |
| 1097 | } |
| 1098 | |
| 1099 | static void |
| 1100 | finish_workspace_change_animation(struct desktop_shell *shell, |
| 1101 | struct workspace *from, |
| 1102 | struct workspace *to) |
| 1103 | { |
Scott Moreau | 4272e63 | 2012-08-13 09:58:41 -0600 | [diff] [blame] | 1104 | weston_compositor_schedule_repaint(shell->compositor); |
Jonas Ådahl | 62fcd04 | 2012-06-13 00:01:23 +0200 | [diff] [blame] | 1105 | |
| 1106 | wl_list_remove(&shell->workspaces.animation.link); |
| 1107 | workspace_deactivate_transforms(from); |
| 1108 | workspace_deactivate_transforms(to); |
| 1109 | shell->workspaces.anim_to = NULL; |
| 1110 | |
| 1111 | wl_list_remove(&shell->workspaces.anim_from->layer.link); |
| 1112 | } |
| 1113 | |
| 1114 | static void |
| 1115 | animate_workspace_change_frame(struct weston_animation *animation, |
| 1116 | struct weston_output *output, uint32_t msecs) |
| 1117 | { |
| 1118 | struct desktop_shell *shell = |
| 1119 | container_of(animation, struct desktop_shell, |
| 1120 | workspaces.animation); |
| 1121 | struct workspace *from = shell->workspaces.anim_from; |
| 1122 | struct workspace *to = shell->workspaces.anim_to; |
| 1123 | uint32_t t; |
| 1124 | double x, y; |
| 1125 | |
| 1126 | if (workspace_is_empty(from) && workspace_is_empty(to)) { |
| 1127 | finish_workspace_change_animation(shell, from, to); |
| 1128 | return; |
| 1129 | } |
| 1130 | |
| 1131 | if (shell->workspaces.anim_timestamp == 0) { |
| 1132 | if (shell->workspaces.anim_current == 0.0) |
| 1133 | shell->workspaces.anim_timestamp = msecs; |
| 1134 | else |
| 1135 | shell->workspaces.anim_timestamp = |
| 1136 | msecs - |
| 1137 | /* Invers of movement function 'y' below. */ |
| 1138 | (asin(1.0 - shell->workspaces.anim_current) * |
| 1139 | DEFAULT_WORKSPACE_CHANGE_ANIMATION_LENGTH * |
| 1140 | M_2_PI); |
| 1141 | } |
| 1142 | |
| 1143 | t = msecs - shell->workspaces.anim_timestamp; |
| 1144 | |
| 1145 | /* |
| 1146 | * x = [0, π/2] |
| 1147 | * y(x) = sin(x) |
| 1148 | */ |
| 1149 | x = t * (1.0/DEFAULT_WORKSPACE_CHANGE_ANIMATION_LENGTH) * M_PI_2; |
| 1150 | y = sin(x); |
| 1151 | |
| 1152 | if (t < DEFAULT_WORKSPACE_CHANGE_ANIMATION_LENGTH) { |
Scott Moreau | 4272e63 | 2012-08-13 09:58:41 -0600 | [diff] [blame] | 1153 | weston_compositor_schedule_repaint(shell->compositor); |
Jonas Ådahl | 62fcd04 | 2012-06-13 00:01:23 +0200 | [diff] [blame] | 1154 | |
| 1155 | workspace_translate_out(from, shell->workspaces.anim_dir * y); |
| 1156 | workspace_translate_in(to, shell->workspaces.anim_dir * y); |
| 1157 | shell->workspaces.anim_current = y; |
| 1158 | |
Scott Moreau | 4272e63 | 2012-08-13 09:58:41 -0600 | [diff] [blame] | 1159 | weston_compositor_schedule_repaint(shell->compositor); |
Jonas Ådahl | 62fcd04 | 2012-06-13 00:01:23 +0200 | [diff] [blame] | 1160 | } |
Jonas Ådahl | 0476974 | 2012-06-13 00:01:24 +0200 | [diff] [blame] | 1161 | else |
Jonas Ådahl | 62fcd04 | 2012-06-13 00:01:23 +0200 | [diff] [blame] | 1162 | finish_workspace_change_animation(shell, from, to); |
Jonas Ådahl | 62fcd04 | 2012-06-13 00:01:23 +0200 | [diff] [blame] | 1163 | } |
| 1164 | |
| 1165 | static void |
| 1166 | animate_workspace_change(struct desktop_shell *shell, |
| 1167 | unsigned int index, |
| 1168 | struct workspace *from, |
| 1169 | struct workspace *to) |
| 1170 | { |
| 1171 | struct weston_output *output; |
| 1172 | |
| 1173 | int dir; |
| 1174 | |
| 1175 | if (index > shell->workspaces.current) |
| 1176 | dir = -1; |
| 1177 | else |
| 1178 | dir = 1; |
| 1179 | |
| 1180 | shell->workspaces.current = index; |
| 1181 | |
| 1182 | shell->workspaces.anim_dir = dir; |
| 1183 | shell->workspaces.anim_from = from; |
| 1184 | shell->workspaces.anim_to = to; |
| 1185 | shell->workspaces.anim_current = 0.0; |
| 1186 | shell->workspaces.anim_timestamp = 0; |
| 1187 | |
| 1188 | output = container_of(shell->compositor->output_list.next, |
| 1189 | struct weston_output, link); |
| 1190 | wl_list_insert(&output->animation_list, |
| 1191 | &shell->workspaces.animation.link); |
| 1192 | |
Jonas Ådahl | 8de6a1d | 2012-08-29 22:13:00 +0200 | [diff] [blame] | 1193 | wl_list_insert(from->layer.link.prev, &to->layer.link); |
Jonas Ådahl | 62fcd04 | 2012-06-13 00:01:23 +0200 | [diff] [blame] | 1194 | |
| 1195 | workspace_translate_in(to, 0); |
| 1196 | |
Kristian Høgsberg | 2f5faff | 2012-07-31 16:36:34 -0400 | [diff] [blame] | 1197 | restore_focus_state(shell, to); |
Jonas Ådahl | 0476974 | 2012-06-13 00:01:24 +0200 | [diff] [blame] | 1198 | |
Scott Moreau | 4272e63 | 2012-08-13 09:58:41 -0600 | [diff] [blame] | 1199 | weston_compositor_schedule_repaint(shell->compositor); |
Jonas Ådahl | 62fcd04 | 2012-06-13 00:01:23 +0200 | [diff] [blame] | 1200 | } |
| 1201 | |
Jonas Ådahl | e3cddce | 2012-06-13 00:01:22 +0200 | [diff] [blame] | 1202 | static void |
Jonas Ådahl | 8de6a1d | 2012-08-29 22:13:00 +0200 | [diff] [blame] | 1203 | update_workspace(struct desktop_shell *shell, unsigned int index, |
| 1204 | struct workspace *from, struct workspace *to) |
| 1205 | { |
| 1206 | shell->workspaces.current = index; |
| 1207 | wl_list_insert(&from->layer.link, &to->layer.link); |
| 1208 | wl_list_remove(&from->layer.link); |
| 1209 | } |
| 1210 | |
| 1211 | static void |
Jonas Ådahl | e3cddce | 2012-06-13 00:01:22 +0200 | [diff] [blame] | 1212 | change_workspace(struct desktop_shell *shell, unsigned int index) |
| 1213 | { |
| 1214 | struct workspace *from; |
| 1215 | struct workspace *to; |
Louis-Francis Ratté-Boulianne | b482dbd | 2013-11-19 11:37:11 +0100 | [diff] [blame] | 1216 | struct focus_state *state; |
Jonas Ådahl | e3cddce | 2012-06-13 00:01:22 +0200 | [diff] [blame] | 1217 | |
| 1218 | if (index == shell->workspaces.current) |
| 1219 | return; |
| 1220 | |
| 1221 | /* Don't change workspace when there is any fullscreen surfaces. */ |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 1222 | if (!wl_list_empty(&shell->fullscreen_layer.view_list)) |
Jonas Ådahl | e3cddce | 2012-06-13 00:01:22 +0200 | [diff] [blame] | 1223 | return; |
| 1224 | |
Jonas Ådahl | e3cddce | 2012-06-13 00:01:22 +0200 | [diff] [blame] | 1225 | from = get_current_workspace(shell); |
| 1226 | to = get_workspace(shell, index); |
| 1227 | |
Jonas Ådahl | 62fcd04 | 2012-06-13 00:01:23 +0200 | [diff] [blame] | 1228 | if (shell->workspaces.anim_from == to && |
| 1229 | shell->workspaces.anim_to == from) { |
Jonas Ådahl | 8de6a1d | 2012-08-29 22:13:00 +0200 | [diff] [blame] | 1230 | restore_focus_state(shell, to); |
Jonas Ådahl | 62fcd04 | 2012-06-13 00:01:23 +0200 | [diff] [blame] | 1231 | reverse_workspace_change_animation(shell, index, from, to); |
Jonas Ådahl | e9d2250 | 2012-08-29 22:13:01 +0200 | [diff] [blame] | 1232 | broadcast_current_workspace_state(shell); |
Jonas Ådahl | 62fcd04 | 2012-06-13 00:01:23 +0200 | [diff] [blame] | 1233 | return; |
| 1234 | } |
Jonas Ådahl | e3cddce | 2012-06-13 00:01:22 +0200 | [diff] [blame] | 1235 | |
Jonas Ådahl | 62fcd04 | 2012-06-13 00:01:23 +0200 | [diff] [blame] | 1236 | if (shell->workspaces.anim_to != NULL) |
| 1237 | finish_workspace_change_animation(shell, |
| 1238 | shell->workspaces.anim_from, |
| 1239 | shell->workspaces.anim_to); |
| 1240 | |
Jonas Ådahl | 8de6a1d | 2012-08-29 22:13:00 +0200 | [diff] [blame] | 1241 | restore_focus_state(shell, to); |
Jonas Ådahl | 0476974 | 2012-06-13 00:01:24 +0200 | [diff] [blame] | 1242 | |
Louis-Francis Ratté-Boulianne | b482dbd | 2013-11-19 11:37:11 +0100 | [diff] [blame] | 1243 | if (shell->focus_animation_type != ANIMATION_NONE) { |
| 1244 | wl_list_for_each(state, &from->focus_list, link) |
| 1245 | if (state->keyboard_focus) |
| 1246 | animate_focus_change(shell, from, |
| 1247 | get_default_view(state->keyboard_focus), NULL); |
| 1248 | |
| 1249 | wl_list_for_each(state, &to->focus_list, link) |
| 1250 | if (state->keyboard_focus) |
| 1251 | animate_focus_change(shell, to, |
| 1252 | NULL, get_default_view(state->keyboard_focus)); |
| 1253 | } |
| 1254 | |
Jonas Ådahl | 8de6a1d | 2012-08-29 22:13:00 +0200 | [diff] [blame] | 1255 | if (workspace_is_empty(to) && workspace_is_empty(from)) |
| 1256 | update_workspace(shell, index, from, to); |
Jonas Ådahl | 62fcd04 | 2012-06-13 00:01:23 +0200 | [diff] [blame] | 1257 | else |
| 1258 | animate_workspace_change(shell, index, from, to); |
Jonas Ådahl | e9d2250 | 2012-08-29 22:13:01 +0200 | [diff] [blame] | 1259 | |
| 1260 | broadcast_current_workspace_state(shell); |
Pekka Paalanen | e955f1e | 2011-12-07 11:49:52 +0200 | [diff] [blame] | 1261 | } |
| 1262 | |
Jonas Ådahl | 8de6a1d | 2012-08-29 22:13:00 +0200 | [diff] [blame] | 1263 | static bool |
| 1264 | workspace_has_only(struct workspace *ws, struct weston_surface *surface) |
| 1265 | { |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 1266 | struct wl_list *list = &ws->layer.view_list; |
Jonas Ådahl | 8de6a1d | 2012-08-29 22:13:00 +0200 | [diff] [blame] | 1267 | struct wl_list *e; |
| 1268 | |
| 1269 | if (wl_list_empty(list)) |
| 1270 | return false; |
| 1271 | |
| 1272 | e = list->next; |
| 1273 | |
| 1274 | if (e->next != list) |
| 1275 | return false; |
| 1276 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 1277 | return container_of(e, struct weston_view, layer_link)->surface == surface; |
Jonas Ådahl | 8de6a1d | 2012-08-29 22:13:00 +0200 | [diff] [blame] | 1278 | } |
| 1279 | |
| 1280 | static void |
Philip Withnall | 659163d | 2013-11-25 18:01:36 +0000 | [diff] [blame] | 1281 | move_surface_to_workspace(struct desktop_shell *shell, |
| 1282 | struct shell_surface *shsurf, |
| 1283 | uint32_t workspace) |
Jonas Ådahl | e9d2250 | 2012-08-29 22:13:01 +0200 | [diff] [blame] | 1284 | { |
| 1285 | struct workspace *from; |
| 1286 | struct workspace *to; |
| 1287 | struct weston_seat *seat; |
Pekka Paalanen | 01388e2 | 2013-04-25 13:57:44 +0300 | [diff] [blame] | 1288 | struct weston_surface *focus; |
Philip Withnall | 659163d | 2013-11-25 18:01:36 +0000 | [diff] [blame] | 1289 | struct weston_view *view; |
Jonas Ådahl | e9d2250 | 2012-08-29 22:13:01 +0200 | [diff] [blame] | 1290 | |
| 1291 | if (workspace == shell->workspaces.current) |
| 1292 | return; |
| 1293 | |
Philip Withnall | 659163d | 2013-11-25 18:01:36 +0000 | [diff] [blame] | 1294 | view = get_default_view(shsurf->surface); |
| 1295 | if (!view) |
| 1296 | return; |
| 1297 | |
| 1298 | assert(weston_surface_get_main_surface(view->surface) == view->surface); |
| 1299 | |
Philipp Brüschweiler | 067abf6 | 2012-09-01 16:03:05 +0200 | [diff] [blame] | 1300 | if (workspace >= shell->workspaces.num) |
| 1301 | workspace = shell->workspaces.num - 1; |
| 1302 | |
Jonas Ådahl | e9d2250 | 2012-08-29 22:13:01 +0200 | [diff] [blame] | 1303 | from = get_current_workspace(shell); |
| 1304 | to = get_workspace(shell, workspace); |
| 1305 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 1306 | wl_list_remove(&view->layer_link); |
| 1307 | wl_list_insert(&to->layer.view_list, &view->layer_link); |
Jonas Ådahl | e9d2250 | 2012-08-29 22:13:01 +0200 | [diff] [blame] | 1308 | |
Philip Withnall | 648a4dd | 2013-11-25 18:01:44 +0000 | [diff] [blame^] | 1309 | shell_surface_update_child_surface_layers(shsurf); |
| 1310 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 1311 | drop_focus_state(shell, from, view->surface); |
Pekka Paalanen | 01388e2 | 2013-04-25 13:57:44 +0300 | [diff] [blame] | 1312 | wl_list_for_each(seat, &shell->compositor->seat_list, link) { |
| 1313 | if (!seat->keyboard) |
| 1314 | continue; |
| 1315 | |
| 1316 | focus = weston_surface_get_main_surface(seat->keyboard->focus); |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 1317 | if (focus == view->surface) |
Kristian Høgsberg | e314875 | 2013-05-06 23:19:49 -0400 | [diff] [blame] | 1318 | weston_keyboard_set_focus(seat->keyboard, NULL); |
Pekka Paalanen | 01388e2 | 2013-04-25 13:57:44 +0300 | [diff] [blame] | 1319 | } |
Jonas Ådahl | e9d2250 | 2012-08-29 22:13:01 +0200 | [diff] [blame] | 1320 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 1321 | weston_view_damage_below(view); |
Jonas Ådahl | e9d2250 | 2012-08-29 22:13:01 +0200 | [diff] [blame] | 1322 | } |
| 1323 | |
| 1324 | static void |
Jonas Ådahl | 8de6a1d | 2012-08-29 22:13:00 +0200 | [diff] [blame] | 1325 | take_surface_to_workspace_by_seat(struct desktop_shell *shell, |
Kristian Høgsberg | e314875 | 2013-05-06 23:19:49 -0400 | [diff] [blame] | 1326 | struct weston_seat *seat, |
Jonas Ådahl | 8de6a1d | 2012-08-29 22:13:00 +0200 | [diff] [blame] | 1327 | unsigned int index) |
| 1328 | { |
Pekka Paalanen | 01388e2 | 2013-04-25 13:57:44 +0300 | [diff] [blame] | 1329 | struct weston_surface *surface; |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 1330 | struct weston_view *view; |
Jonas Ådahl | 8de6a1d | 2012-08-29 22:13:00 +0200 | [diff] [blame] | 1331 | struct shell_surface *shsurf; |
| 1332 | struct workspace *from; |
| 1333 | struct workspace *to; |
Jonas Ådahl | 8538b22 | 2012-08-29 22:13:03 +0200 | [diff] [blame] | 1334 | struct focus_state *state; |
Jonas Ådahl | 8de6a1d | 2012-08-29 22:13:00 +0200 | [diff] [blame] | 1335 | |
Pekka Paalanen | 01388e2 | 2013-04-25 13:57:44 +0300 | [diff] [blame] | 1336 | surface = weston_surface_get_main_surface(seat->keyboard->focus); |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 1337 | view = get_default_view(surface); |
| 1338 | if (view == NULL || |
Louis-Francis Ratté-Boulianne | b482dbd | 2013-11-19 11:37:11 +0100 | [diff] [blame] | 1339 | index == shell->workspaces.current || |
| 1340 | is_focus_view(view)) |
Jonas Ådahl | 8de6a1d | 2012-08-29 22:13:00 +0200 | [diff] [blame] | 1341 | return; |
| 1342 | |
| 1343 | from = get_current_workspace(shell); |
| 1344 | to = get_workspace(shell, index); |
| 1345 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 1346 | wl_list_remove(&view->layer_link); |
| 1347 | wl_list_insert(&to->layer.view_list, &view->layer_link); |
Jonas Ådahl | 8de6a1d | 2012-08-29 22:13:00 +0200 | [diff] [blame] | 1348 | |
Philip Withnall | 659163d | 2013-11-25 18:01:36 +0000 | [diff] [blame] | 1349 | shsurf = get_shell_surface(surface); |
Philip Withnall | 648a4dd | 2013-11-25 18:01:44 +0000 | [diff] [blame^] | 1350 | if (shsurf != NULL) |
| 1351 | shell_surface_update_child_surface_layers(shsurf); |
Philip Withnall | 659163d | 2013-11-25 18:01:36 +0000 | [diff] [blame] | 1352 | |
Jonas Ådahl | e9d2250 | 2012-08-29 22:13:01 +0200 | [diff] [blame] | 1353 | replace_focus_state(shell, to, seat); |
Jonas Ådahl | 8de6a1d | 2012-08-29 22:13:00 +0200 | [diff] [blame] | 1354 | drop_focus_state(shell, from, surface); |
| 1355 | |
| 1356 | if (shell->workspaces.anim_from == to && |
| 1357 | shell->workspaces.anim_to == from) { |
Jonas Ådahl | e9d2250 | 2012-08-29 22:13:01 +0200 | [diff] [blame] | 1358 | wl_list_remove(&to->layer.link); |
| 1359 | wl_list_insert(from->layer.link.prev, &to->layer.link); |
| 1360 | |
Jonas Ådahl | 8de6a1d | 2012-08-29 22:13:00 +0200 | [diff] [blame] | 1361 | reverse_workspace_change_animation(shell, index, from, to); |
Jonas Ådahl | e9d2250 | 2012-08-29 22:13:01 +0200 | [diff] [blame] | 1362 | broadcast_current_workspace_state(shell); |
| 1363 | |
Jonas Ådahl | 8de6a1d | 2012-08-29 22:13:00 +0200 | [diff] [blame] | 1364 | return; |
| 1365 | } |
| 1366 | |
| 1367 | if (shell->workspaces.anim_to != NULL) |
| 1368 | finish_workspace_change_animation(shell, |
| 1369 | shell->workspaces.anim_from, |
| 1370 | shell->workspaces.anim_to); |
| 1371 | |
| 1372 | if (workspace_is_empty(from) && |
| 1373 | workspace_has_only(to, surface)) |
| 1374 | update_workspace(shell, index, from, to); |
| 1375 | else { |
Jonas Ådahl | 8de6a1d | 2012-08-29 22:13:00 +0200 | [diff] [blame] | 1376 | if (wl_list_empty(&shsurf->workspace_transform.link)) |
| 1377 | wl_list_insert(&shell->workspaces.anim_sticky_list, |
| 1378 | &shsurf->workspace_transform.link); |
| 1379 | |
| 1380 | animate_workspace_change(shell, index, from, to); |
| 1381 | } |
Jonas Ådahl | e9d2250 | 2012-08-29 22:13:01 +0200 | [diff] [blame] | 1382 | |
| 1383 | broadcast_current_workspace_state(shell); |
Jonas Ådahl | 8538b22 | 2012-08-29 22:13:03 +0200 | [diff] [blame] | 1384 | |
| 1385 | state = ensure_focus_state(shell, seat); |
| 1386 | if (state != NULL) |
| 1387 | state->keyboard_focus = surface; |
Jonas Ådahl | e9d2250 | 2012-08-29 22:13:01 +0200 | [diff] [blame] | 1388 | } |
| 1389 | |
| 1390 | static void |
| 1391 | workspace_manager_move_surface(struct wl_client *client, |
| 1392 | struct wl_resource *resource, |
| 1393 | struct wl_resource *surface_resource, |
| 1394 | uint32_t workspace) |
| 1395 | { |
Jason Ekstrand | 651f00e | 2013-06-14 10:07:54 -0500 | [diff] [blame] | 1396 | struct desktop_shell *shell = wl_resource_get_user_data(resource); |
Jonas Ådahl | e9d2250 | 2012-08-29 22:13:01 +0200 | [diff] [blame] | 1397 | struct weston_surface *surface = |
Jason Ekstrand | 0f2ef7e | 2013-06-14 10:07:53 -0500 | [diff] [blame] | 1398 | wl_resource_get_user_data(surface_resource); |
Pekka Paalanen | 01388e2 | 2013-04-25 13:57:44 +0300 | [diff] [blame] | 1399 | struct weston_surface *main_surface; |
Philip Withnall | 659163d | 2013-11-25 18:01:36 +0000 | [diff] [blame] | 1400 | struct shell_surface *shell_surface; |
Jonas Ådahl | e9d2250 | 2012-08-29 22:13:01 +0200 | [diff] [blame] | 1401 | |
Pekka Paalanen | 01388e2 | 2013-04-25 13:57:44 +0300 | [diff] [blame] | 1402 | main_surface = weston_surface_get_main_surface(surface); |
Philip Withnall | 659163d | 2013-11-25 18:01:36 +0000 | [diff] [blame] | 1403 | shell_surface = get_shell_surface(main_surface); |
| 1404 | if (shell_surface == NULL) |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 1405 | return; |
Philip Withnall | 659163d | 2013-11-25 18:01:36 +0000 | [diff] [blame] | 1406 | |
| 1407 | move_surface_to_workspace(shell, shell_surface, workspace); |
Jonas Ådahl | e9d2250 | 2012-08-29 22:13:01 +0200 | [diff] [blame] | 1408 | } |
| 1409 | |
| 1410 | static const struct workspace_manager_interface workspace_manager_implementation = { |
| 1411 | workspace_manager_move_surface, |
| 1412 | }; |
| 1413 | |
| 1414 | static void |
| 1415 | unbind_resource(struct wl_resource *resource) |
| 1416 | { |
Jason Ekstrand | 651f00e | 2013-06-14 10:07:54 -0500 | [diff] [blame] | 1417 | wl_list_remove(wl_resource_get_link(resource)); |
Jonas Ådahl | e9d2250 | 2012-08-29 22:13:01 +0200 | [diff] [blame] | 1418 | } |
| 1419 | |
| 1420 | static void |
| 1421 | bind_workspace_manager(struct wl_client *client, |
| 1422 | void *data, uint32_t version, uint32_t id) |
| 1423 | { |
| 1424 | struct desktop_shell *shell = data; |
| 1425 | struct wl_resource *resource; |
| 1426 | |
Jason Ekstrand | a85118c | 2013-06-27 20:17:02 -0500 | [diff] [blame] | 1427 | resource = wl_resource_create(client, |
| 1428 | &workspace_manager_interface, 1, id); |
Jonas Ådahl | e9d2250 | 2012-08-29 22:13:01 +0200 | [diff] [blame] | 1429 | |
| 1430 | if (resource == NULL) { |
| 1431 | weston_log("couldn't add workspace manager object"); |
| 1432 | return; |
| 1433 | } |
| 1434 | |
Jason Ekstrand | a85118c | 2013-06-27 20:17:02 -0500 | [diff] [blame] | 1435 | wl_resource_set_implementation(resource, |
| 1436 | &workspace_manager_implementation, |
| 1437 | shell, unbind_resource); |
Jason Ekstrand | 651f00e | 2013-06-14 10:07:54 -0500 | [diff] [blame] | 1438 | wl_list_insert(&shell->workspaces.client_list, |
| 1439 | wl_resource_get_link(resource)); |
Jonas Ådahl | e9d2250 | 2012-08-29 22:13:01 +0200 | [diff] [blame] | 1440 | |
| 1441 | workspace_manager_send_state(resource, |
| 1442 | shell->workspaces.current, |
| 1443 | shell->workspaces.num); |
Jonas Ådahl | 8de6a1d | 2012-08-29 22:13:00 +0200 | [diff] [blame] | 1444 | } |
| 1445 | |
Pekka Paalanen | 56cdea9 | 2011-11-23 16:14:12 +0200 | [diff] [blame] | 1446 | static void |
Rusty Lynch | 1084da5 | 2013-08-15 09:10:08 -0700 | [diff] [blame] | 1447 | touch_move_grab_down(struct weston_touch_grab *grab, uint32_t time, |
| 1448 | int touch_id, wl_fixed_t sx, wl_fixed_t sy) |
| 1449 | { |
| 1450 | } |
| 1451 | |
| 1452 | static void |
| 1453 | touch_move_grab_up(struct weston_touch_grab *grab, uint32_t time, int touch_id) |
| 1454 | { |
Jonas Ådahl | 1c6e63e | 2013-10-25 23:18:04 +0200 | [diff] [blame] | 1455 | struct weston_touch_move_grab *move = |
| 1456 | (struct weston_touch_move_grab *) container_of( |
| 1457 | grab, struct shell_touch_grab, grab); |
Neil Roberts | e14aa4f | 2013-10-03 16:43:07 +0100 | [diff] [blame] | 1458 | |
Jonas Ådahl | 1c6e63e | 2013-10-25 23:18:04 +0200 | [diff] [blame] | 1459 | if (grab->touch->seat->num_tp == 0) { |
| 1460 | shell_touch_grab_end(&move->base); |
| 1461 | free(move); |
| 1462 | } |
Rusty Lynch | 1084da5 | 2013-08-15 09:10:08 -0700 | [diff] [blame] | 1463 | } |
| 1464 | |
| 1465 | static void |
| 1466 | touch_move_grab_motion(struct weston_touch_grab *grab, uint32_t time, |
| 1467 | int touch_id, wl_fixed_t sx, wl_fixed_t sy) |
| 1468 | { |
| 1469 | struct weston_touch_move_grab *move = (struct weston_touch_move_grab *) grab; |
| 1470 | struct shell_surface *shsurf = move->base.shsurf; |
| 1471 | struct weston_surface *es; |
| 1472 | int dx = wl_fixed_to_int(grab->touch->grab_x + move->dx); |
| 1473 | int dy = wl_fixed_to_int(grab->touch->grab_y + move->dy); |
| 1474 | |
| 1475 | if (!shsurf) |
| 1476 | return; |
| 1477 | |
| 1478 | es = shsurf->surface; |
| 1479 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 1480 | weston_view_configure(shsurf->view, dx, dy, |
| 1481 | shsurf->view->geometry.width, |
| 1482 | shsurf->view->geometry.height); |
Rusty Lynch | 1084da5 | 2013-08-15 09:10:08 -0700 | [diff] [blame] | 1483 | |
| 1484 | weston_compositor_schedule_repaint(es->compositor); |
| 1485 | } |
| 1486 | |
Jonas Ådahl | 1ea343e | 2013-10-25 23:18:05 +0200 | [diff] [blame] | 1487 | static void |
| 1488 | touch_move_grab_cancel(struct weston_touch_grab *grab) |
| 1489 | { |
| 1490 | struct weston_touch_move_grab *move = |
| 1491 | (struct weston_touch_move_grab *) container_of( |
| 1492 | grab, struct shell_touch_grab, grab); |
| 1493 | |
| 1494 | shell_touch_grab_end(&move->base); |
| 1495 | free(move); |
| 1496 | } |
| 1497 | |
Rusty Lynch | 1084da5 | 2013-08-15 09:10:08 -0700 | [diff] [blame] | 1498 | static const struct weston_touch_grab_interface touch_move_grab_interface = { |
| 1499 | touch_move_grab_down, |
| 1500 | touch_move_grab_up, |
| 1501 | touch_move_grab_motion, |
Jonas Ådahl | 1ea343e | 2013-10-25 23:18:05 +0200 | [diff] [blame] | 1502 | touch_move_grab_cancel, |
Rusty Lynch | 1084da5 | 2013-08-15 09:10:08 -0700 | [diff] [blame] | 1503 | }; |
| 1504 | |
| 1505 | static int |
| 1506 | surface_touch_move(struct shell_surface *shsurf, struct weston_seat *seat) |
| 1507 | { |
| 1508 | struct weston_touch_move_grab *move; |
| 1509 | |
| 1510 | if (!shsurf) |
| 1511 | return -1; |
| 1512 | |
| 1513 | if (shsurf->type == SHELL_SURFACE_FULLSCREEN) |
| 1514 | return 0; |
Kristian Høgsberg | c85f1d4 | 2013-10-24 16:52:00 -0700 | [diff] [blame] | 1515 | if (shsurf->grabbed) |
| 1516 | return 0; |
Rusty Lynch | 1084da5 | 2013-08-15 09:10:08 -0700 | [diff] [blame] | 1517 | |
| 1518 | move = malloc(sizeof *move); |
| 1519 | if (!move) |
| 1520 | return -1; |
| 1521 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 1522 | move->dx = wl_fixed_from_double(shsurf->view->geometry.x) - |
Rusty Lynch | 1084da5 | 2013-08-15 09:10:08 -0700 | [diff] [blame] | 1523 | seat->touch->grab_x; |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 1524 | move->dy = wl_fixed_from_double(shsurf->view->geometry.y) - |
Rusty Lynch | 1084da5 | 2013-08-15 09:10:08 -0700 | [diff] [blame] | 1525 | seat->touch->grab_y; |
| 1526 | |
| 1527 | shell_touch_grab_start(&move->base, &touch_move_grab_interface, shsurf, |
| 1528 | seat->touch); |
| 1529 | |
| 1530 | return 0; |
| 1531 | } |
| 1532 | |
| 1533 | static void |
Kristian Høgsberg | 6848c25 | 2013-05-08 22:02:59 -0400 | [diff] [blame] | 1534 | noop_grab_focus(struct weston_pointer_grab *grab) |
Kristian Høgsberg | 9ddb826 | 2012-01-04 21:30:29 -0500 | [diff] [blame] | 1535 | { |
Kristian Høgsberg | 9ddb826 | 2012-01-04 21:30:29 -0500 | [diff] [blame] | 1536 | } |
| 1537 | |
| 1538 | static void |
Giulio Camuffo | 1959ab8 | 2013-11-14 23:42:52 +0100 | [diff] [blame] | 1539 | move_grab_motion(struct weston_pointer_grab *grab, uint32_t time, |
| 1540 | wl_fixed_t x, wl_fixed_t y) |
Kristian Høgsberg | 4cca349 | 2011-01-18 07:53:49 -0500 | [diff] [blame] | 1541 | { |
Kristian Høgsberg | 8334bc1 | 2012-01-03 10:29:47 -0500 | [diff] [blame] | 1542 | struct weston_move_grab *move = (struct weston_move_grab *) grab; |
Kristian Høgsberg | 02bbabb | 2013-05-06 22:15:05 -0400 | [diff] [blame] | 1543 | struct weston_pointer *pointer = grab->pointer; |
Ander Conselvan de Oliveira | fe0444a | 2012-04-04 17:48:05 +0300 | [diff] [blame] | 1544 | struct shell_surface *shsurf = move->base.shsurf; |
Giulio Camuffo | 1959ab8 | 2013-11-14 23:42:52 +0100 | [diff] [blame] | 1545 | int dx, dy; |
| 1546 | |
| 1547 | weston_pointer_move(pointer, x, y); |
| 1548 | dx = wl_fixed_to_int(pointer->x + move->dx); |
| 1549 | dy = wl_fixed_to_int(pointer->y + move->dy); |
Ander Conselvan de Oliveira | fe0444a | 2012-04-04 17:48:05 +0300 | [diff] [blame] | 1550 | |
| 1551 | if (!shsurf) |
| 1552 | return; |
| 1553 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 1554 | weston_view_configure(shsurf->view, dx, dy, |
| 1555 | shsurf->view->geometry.width, |
| 1556 | shsurf->view->geometry.height); |
Kristian Høgsberg | 4cca349 | 2011-01-18 07:53:49 -0500 | [diff] [blame] | 1557 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 1558 | weston_compositor_schedule_repaint(shsurf->surface->compositor); |
Kristian Høgsberg | 4cca349 | 2011-01-18 07:53:49 -0500 | [diff] [blame] | 1559 | } |
| 1560 | |
| 1561 | static void |
Kristian Høgsberg | 02bbabb | 2013-05-06 22:15:05 -0400 | [diff] [blame] | 1562 | move_grab_button(struct weston_pointer_grab *grab, |
Daniel Stone | 4dbadb1 | 2012-05-30 16:31:51 +0100 | [diff] [blame] | 1563 | uint32_t time, uint32_t button, uint32_t state_w) |
Kristian Høgsberg | 4cca349 | 2011-01-18 07:53:49 -0500 | [diff] [blame] | 1564 | { |
Ander Conselvan de Oliveira | fe0444a | 2012-04-04 17:48:05 +0300 | [diff] [blame] | 1565 | struct shell_grab *shell_grab = container_of(grab, struct shell_grab, |
| 1566 | grab); |
Kristian Høgsberg | 02bbabb | 2013-05-06 22:15:05 -0400 | [diff] [blame] | 1567 | struct weston_pointer *pointer = grab->pointer; |
Daniel Stone | 4dbadb1 | 2012-05-30 16:31:51 +0100 | [diff] [blame] | 1568 | enum wl_pointer_button_state state = state_w; |
Kristian Høgsberg | 4cca349 | 2011-01-18 07:53:49 -0500 | [diff] [blame] | 1569 | |
Daniel Stone | 4dbadb1 | 2012-05-30 16:31:51 +0100 | [diff] [blame] | 1570 | if (pointer->button_count == 0 && |
| 1571 | state == WL_POINTER_BUTTON_STATE_RELEASED) { |
Ander Conselvan de Oliveira | b9d2a0f | 2012-06-28 18:08:05 +0300 | [diff] [blame] | 1572 | shell_grab_end(shell_grab); |
Kristian Høgsberg | 9ddb826 | 2012-01-04 21:30:29 -0500 | [diff] [blame] | 1573 | free(grab); |
| 1574 | } |
Kristian Høgsberg | 4cca349 | 2011-01-18 07:53:49 -0500 | [diff] [blame] | 1575 | } |
| 1576 | |
Jonas Ådahl | 1ea343e | 2013-10-25 23:18:05 +0200 | [diff] [blame] | 1577 | static void |
| 1578 | move_grab_cancel(struct weston_pointer_grab *grab) |
| 1579 | { |
| 1580 | struct shell_grab *shell_grab = |
| 1581 | container_of(grab, struct shell_grab, grab); |
| 1582 | |
| 1583 | shell_grab_end(shell_grab); |
| 1584 | free(grab); |
| 1585 | } |
| 1586 | |
Kristian Høgsberg | 02bbabb | 2013-05-06 22:15:05 -0400 | [diff] [blame] | 1587 | static const struct weston_pointer_grab_interface move_grab_interface = { |
Kristian Høgsberg | 9ddb826 | 2012-01-04 21:30:29 -0500 | [diff] [blame] | 1588 | noop_grab_focus, |
Kristian Høgsberg | 4cca349 | 2011-01-18 07:53:49 -0500 | [diff] [blame] | 1589 | move_grab_motion, |
| 1590 | move_grab_button, |
Jonas Ådahl | 1ea343e | 2013-10-25 23:18:05 +0200 | [diff] [blame] | 1591 | move_grab_cancel, |
Kristian Høgsberg | 4cca349 | 2011-01-18 07:53:49 -0500 | [diff] [blame] | 1592 | }; |
| 1593 | |
Kristian Høgsberg | 9e31bff | 2012-08-01 00:08:07 -0400 | [diff] [blame] | 1594 | static int |
Kristian Høgsberg | e314875 | 2013-05-06 23:19:49 -0400 | [diff] [blame] | 1595 | surface_move(struct shell_surface *shsurf, struct weston_seat *seat) |
Kristian Høgsberg | 9e31bff | 2012-08-01 00:08:07 -0400 | [diff] [blame] | 1596 | { |
| 1597 | struct weston_move_grab *move; |
| 1598 | |
| 1599 | if (!shsurf) |
| 1600 | return -1; |
| 1601 | |
Kristian Høgsberg | c85f1d4 | 2013-10-24 16:52:00 -0700 | [diff] [blame] | 1602 | if (shsurf->grabbed) |
| 1603 | return 0; |
Kristian Høgsberg | 9e31bff | 2012-08-01 00:08:07 -0400 | [diff] [blame] | 1604 | if (shsurf->type == SHELL_SURFACE_FULLSCREEN) |
| 1605 | return 0; |
| 1606 | |
| 1607 | move = malloc(sizeof *move); |
| 1608 | if (!move) |
| 1609 | return -1; |
| 1610 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 1611 | move->dx = wl_fixed_from_double(shsurf->view->geometry.x) - |
Kristian Høgsberg | e314875 | 2013-05-06 23:19:49 -0400 | [diff] [blame] | 1612 | seat->pointer->grab_x; |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 1613 | move->dy = wl_fixed_from_double(shsurf->view->geometry.y) - |
Kristian Høgsberg | e314875 | 2013-05-06 23:19:49 -0400 | [diff] [blame] | 1614 | seat->pointer->grab_y; |
Kristian Høgsberg | 9e31bff | 2012-08-01 00:08:07 -0400 | [diff] [blame] | 1615 | |
| 1616 | shell_grab_start(&move->base, &move_grab_interface, shsurf, |
Kristian Høgsberg | e314875 | 2013-05-06 23:19:49 -0400 | [diff] [blame] | 1617 | seat->pointer, DESKTOP_SHELL_CURSOR_MOVE); |
Kristian Høgsberg | 9e31bff | 2012-08-01 00:08:07 -0400 | [diff] [blame] | 1618 | |
| 1619 | return 0; |
| 1620 | } |
| 1621 | |
| 1622 | static void |
| 1623 | shell_surface_move(struct wl_client *client, struct wl_resource *resource, |
| 1624 | struct wl_resource *seat_resource, uint32_t serial) |
| 1625 | { |
Jason Ekstrand | 44a3863 | 2013-06-14 10:08:00 -0500 | [diff] [blame] | 1626 | struct weston_seat *seat = wl_resource_get_user_data(seat_resource); |
Jason Ekstrand | 651f00e | 2013-06-14 10:07:54 -0500 | [diff] [blame] | 1627 | struct shell_surface *shsurf = wl_resource_get_user_data(resource); |
Giulio Camuffo | 61da3fc | 2013-04-25 13:57:45 +0300 | [diff] [blame] | 1628 | struct weston_surface *surface; |
Kristian Høgsberg | 9e31bff | 2012-08-01 00:08:07 -0400 | [diff] [blame] | 1629 | |
Kristian Høgsberg | e1b655d | 2013-08-28 23:16:20 -0700 | [diff] [blame] | 1630 | if (seat->pointer && |
| 1631 | seat->pointer->button_count > 0 && |
| 1632 | seat->pointer->grab_serial == serial) { |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 1633 | surface = weston_surface_get_main_surface(seat->pointer->focus->surface); |
Rusty Lynch | 1084da5 | 2013-08-15 09:10:08 -0700 | [diff] [blame] | 1634 | if ((surface == shsurf->surface) && |
| 1635 | (surface_move(shsurf, seat) < 0)) |
| 1636 | wl_resource_post_no_memory(resource); |
Kristian Høgsberg | e1b655d | 2013-08-28 23:16:20 -0700 | [diff] [blame] | 1637 | } else if (seat->touch && |
| 1638 | seat->touch->grab_serial == serial) { |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 1639 | surface = weston_surface_get_main_surface(seat->touch->focus->surface); |
Rusty Lynch | 1084da5 | 2013-08-15 09:10:08 -0700 | [diff] [blame] | 1640 | if ((surface == shsurf->surface) && |
| 1641 | (surface_touch_move(shsurf, seat) < 0)) |
| 1642 | wl_resource_post_no_memory(resource); |
| 1643 | } |
Kristian Høgsberg | 9e31bff | 2012-08-01 00:08:07 -0400 | [diff] [blame] | 1644 | } |
| 1645 | |
| 1646 | struct weston_resize_grab { |
| 1647 | struct shell_grab base; |
| 1648 | uint32_t edges; |
| 1649 | int32_t width, height; |
| 1650 | }; |
| 1651 | |
| 1652 | static void |
Giulio Camuffo | 1959ab8 | 2013-11-14 23:42:52 +0100 | [diff] [blame] | 1653 | resize_grab_motion(struct weston_pointer_grab *grab, uint32_t time, |
| 1654 | wl_fixed_t x, wl_fixed_t y) |
Kristian Høgsberg | 9e31bff | 2012-08-01 00:08:07 -0400 | [diff] [blame] | 1655 | { |
| 1656 | struct weston_resize_grab *resize = (struct weston_resize_grab *) grab; |
Kristian Høgsberg | 02bbabb | 2013-05-06 22:15:05 -0400 | [diff] [blame] | 1657 | struct weston_pointer *pointer = grab->pointer; |
Kristian Høgsberg | 9e31bff | 2012-08-01 00:08:07 -0400 | [diff] [blame] | 1658 | struct shell_surface *shsurf = resize->base.shsurf; |
| 1659 | int32_t width, height; |
| 1660 | wl_fixed_t from_x, from_y; |
| 1661 | wl_fixed_t to_x, to_y; |
| 1662 | |
Giulio Camuffo | 1959ab8 | 2013-11-14 23:42:52 +0100 | [diff] [blame] | 1663 | weston_pointer_move(pointer, x, y); |
| 1664 | |
Kristian Høgsberg | 9e31bff | 2012-08-01 00:08:07 -0400 | [diff] [blame] | 1665 | if (!shsurf) |
| 1666 | return; |
| 1667 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 1668 | weston_view_from_global_fixed(shsurf->view, |
| 1669 | pointer->grab_x, pointer->grab_y, |
| 1670 | &from_x, &from_y); |
| 1671 | weston_view_from_global_fixed(shsurf->view, |
| 1672 | pointer->x, pointer->y, &to_x, &to_y); |
Kristian Høgsberg | 9e31bff | 2012-08-01 00:08:07 -0400 | [diff] [blame] | 1673 | |
| 1674 | width = resize->width; |
| 1675 | if (resize->edges & WL_SHELL_SURFACE_RESIZE_LEFT) { |
| 1676 | width += wl_fixed_to_int(from_x - to_x); |
| 1677 | } else if (resize->edges & WL_SHELL_SURFACE_RESIZE_RIGHT) { |
| 1678 | width += wl_fixed_to_int(to_x - from_x); |
| 1679 | } |
| 1680 | |
| 1681 | height = resize->height; |
| 1682 | if (resize->edges & WL_SHELL_SURFACE_RESIZE_TOP) { |
| 1683 | height += wl_fixed_to_int(from_y - to_y); |
| 1684 | } else if (resize->edges & WL_SHELL_SURFACE_RESIZE_BOTTOM) { |
| 1685 | height += wl_fixed_to_int(to_y - from_y); |
| 1686 | } |
| 1687 | |
| 1688 | shsurf->client->send_configure(shsurf->surface, |
| 1689 | resize->edges, width, height); |
| 1690 | } |
| 1691 | |
| 1692 | static void |
| 1693 | send_configure(struct weston_surface *surface, |
| 1694 | uint32_t edges, int32_t width, int32_t height) |
| 1695 | { |
| 1696 | struct shell_surface *shsurf = get_shell_surface(surface); |
| 1697 | |
Jason Ekstrand | 651f00e | 2013-06-14 10:07:54 -0500 | [diff] [blame] | 1698 | wl_shell_surface_send_configure(shsurf->resource, |
Kristian Høgsberg | 9e31bff | 2012-08-01 00:08:07 -0400 | [diff] [blame] | 1699 | edges, width, height); |
| 1700 | } |
| 1701 | |
| 1702 | static const struct weston_shell_client shell_client = { |
| 1703 | send_configure |
| 1704 | }; |
| 1705 | |
| 1706 | static void |
Kristian Høgsberg | 02bbabb | 2013-05-06 22:15:05 -0400 | [diff] [blame] | 1707 | resize_grab_button(struct weston_pointer_grab *grab, |
Kristian Høgsberg | 9e31bff | 2012-08-01 00:08:07 -0400 | [diff] [blame] | 1708 | uint32_t time, uint32_t button, uint32_t state_w) |
| 1709 | { |
| 1710 | struct weston_resize_grab *resize = (struct weston_resize_grab *) grab; |
Kristian Høgsberg | 02bbabb | 2013-05-06 22:15:05 -0400 | [diff] [blame] | 1711 | struct weston_pointer *pointer = grab->pointer; |
Kristian Høgsberg | 9e31bff | 2012-08-01 00:08:07 -0400 | [diff] [blame] | 1712 | enum wl_pointer_button_state state = state_w; |
| 1713 | |
| 1714 | if (pointer->button_count == 0 && |
| 1715 | state == WL_POINTER_BUTTON_STATE_RELEASED) { |
| 1716 | shell_grab_end(&resize->base); |
| 1717 | free(grab); |
| 1718 | } |
| 1719 | } |
| 1720 | |
Jonas Ådahl | 1ea343e | 2013-10-25 23:18:05 +0200 | [diff] [blame] | 1721 | static void |
| 1722 | resize_grab_cancel(struct weston_pointer_grab *grab) |
| 1723 | { |
| 1724 | struct weston_resize_grab *resize = (struct weston_resize_grab *) grab; |
| 1725 | |
| 1726 | shell_grab_end(&resize->base); |
| 1727 | free(grab); |
| 1728 | } |
| 1729 | |
Kristian Høgsberg | 02bbabb | 2013-05-06 22:15:05 -0400 | [diff] [blame] | 1730 | static const struct weston_pointer_grab_interface resize_grab_interface = { |
Kristian Høgsberg | 9e31bff | 2012-08-01 00:08:07 -0400 | [diff] [blame] | 1731 | noop_grab_focus, |
| 1732 | resize_grab_motion, |
| 1733 | resize_grab_button, |
Jonas Ådahl | 1ea343e | 2013-10-25 23:18:05 +0200 | [diff] [blame] | 1734 | resize_grab_cancel, |
Kristian Høgsberg | 9e31bff | 2012-08-01 00:08:07 -0400 | [diff] [blame] | 1735 | }; |
| 1736 | |
Giulio Camuffo | b836664 | 2013-04-25 13:57:46 +0300 | [diff] [blame] | 1737 | /* |
| 1738 | * Returns the bounding box of a surface and all its sub-surfaces, |
| 1739 | * in the surface coordinates system. */ |
| 1740 | static void |
| 1741 | surface_subsurfaces_boundingbox(struct weston_surface *surface, int32_t *x, |
| 1742 | int32_t *y, int32_t *w, int32_t *h) { |
| 1743 | pixman_region32_t region; |
| 1744 | pixman_box32_t *box; |
| 1745 | struct weston_subsurface *subsurface; |
| 1746 | |
| 1747 | pixman_region32_init_rect(®ion, 0, 0, |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 1748 | surface->width, |
| 1749 | surface->height); |
Giulio Camuffo | b836664 | 2013-04-25 13:57:46 +0300 | [diff] [blame] | 1750 | |
| 1751 | wl_list_for_each(subsurface, &surface->subsurface_list, parent_link) { |
| 1752 | pixman_region32_union_rect(®ion, ®ion, |
| 1753 | subsurface->position.x, |
| 1754 | subsurface->position.y, |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 1755 | subsurface->surface->width, |
| 1756 | subsurface->surface->height); |
Giulio Camuffo | b836664 | 2013-04-25 13:57:46 +0300 | [diff] [blame] | 1757 | } |
| 1758 | |
| 1759 | box = pixman_region32_extents(®ion); |
| 1760 | if (x) |
| 1761 | *x = box->x1; |
| 1762 | if (y) |
| 1763 | *y = box->y1; |
| 1764 | if (w) |
| 1765 | *w = box->x2 - box->x1; |
| 1766 | if (h) |
| 1767 | *h = box->y2 - box->y1; |
| 1768 | |
| 1769 | pixman_region32_fini(®ion); |
| 1770 | } |
| 1771 | |
Kristian Høgsberg | 9e31bff | 2012-08-01 00:08:07 -0400 | [diff] [blame] | 1772 | static int |
| 1773 | surface_resize(struct shell_surface *shsurf, |
Kristian Høgsberg | e314875 | 2013-05-06 23:19:49 -0400 | [diff] [blame] | 1774 | struct weston_seat *seat, uint32_t edges) |
Kristian Høgsberg | 9e31bff | 2012-08-01 00:08:07 -0400 | [diff] [blame] | 1775 | { |
| 1776 | struct weston_resize_grab *resize; |
| 1777 | |
Rafal Mielniczuk | 23c6759 | 2013-03-11 19:26:53 +0100 | [diff] [blame] | 1778 | if (shsurf->type == SHELL_SURFACE_FULLSCREEN || |
| 1779 | shsurf->type == SHELL_SURFACE_MAXIMIZED) |
Kristian Høgsberg | 9e31bff | 2012-08-01 00:08:07 -0400 | [diff] [blame] | 1780 | return 0; |
| 1781 | |
| 1782 | if (edges == 0 || edges > 15 || |
| 1783 | (edges & 3) == 3 || (edges & 12) == 12) |
| 1784 | return 0; |
| 1785 | |
| 1786 | resize = malloc(sizeof *resize); |
| 1787 | if (!resize) |
| 1788 | return -1; |
| 1789 | |
| 1790 | resize->edges = edges; |
Giulio Camuffo | b836664 | 2013-04-25 13:57:46 +0300 | [diff] [blame] | 1791 | surface_subsurfaces_boundingbox(shsurf->surface, NULL, NULL, |
| 1792 | &resize->width, &resize->height); |
Kristian Høgsberg | 9e31bff | 2012-08-01 00:08:07 -0400 | [diff] [blame] | 1793 | |
| 1794 | shell_grab_start(&resize->base, &resize_grab_interface, shsurf, |
Kristian Høgsberg | e314875 | 2013-05-06 23:19:49 -0400 | [diff] [blame] | 1795 | seat->pointer, edges); |
Kristian Høgsberg | 9e31bff | 2012-08-01 00:08:07 -0400 | [diff] [blame] | 1796 | |
| 1797 | return 0; |
| 1798 | } |
| 1799 | |
| 1800 | static void |
| 1801 | shell_surface_resize(struct wl_client *client, struct wl_resource *resource, |
| 1802 | struct wl_resource *seat_resource, uint32_t serial, |
| 1803 | uint32_t edges) |
| 1804 | { |
Jason Ekstrand | 44a3863 | 2013-06-14 10:08:00 -0500 | [diff] [blame] | 1805 | struct weston_seat *seat = wl_resource_get_user_data(seat_resource); |
Jason Ekstrand | 651f00e | 2013-06-14 10:07:54 -0500 | [diff] [blame] | 1806 | struct shell_surface *shsurf = wl_resource_get_user_data(resource); |
Giulio Camuffo | 61da3fc | 2013-04-25 13:57:45 +0300 | [diff] [blame] | 1807 | struct weston_surface *surface; |
Kristian Høgsberg | 9e31bff | 2012-08-01 00:08:07 -0400 | [diff] [blame] | 1808 | |
| 1809 | if (shsurf->type == SHELL_SURFACE_FULLSCREEN) |
| 1810 | return; |
| 1811 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 1812 | surface = weston_surface_get_main_surface(seat->pointer->focus->surface); |
Kristian Høgsberg | e314875 | 2013-05-06 23:19:49 -0400 | [diff] [blame] | 1813 | if (seat->pointer->button_count == 0 || |
| 1814 | seat->pointer->grab_serial != serial || |
Giulio Camuffo | 61da3fc | 2013-04-25 13:57:45 +0300 | [diff] [blame] | 1815 | surface != shsurf->surface) |
Kristian Høgsberg | 9e31bff | 2012-08-01 00:08:07 -0400 | [diff] [blame] | 1816 | return; |
| 1817 | |
Kristian Høgsberg | e314875 | 2013-05-06 23:19:49 -0400 | [diff] [blame] | 1818 | if (surface_resize(shsurf, seat, edges) < 0) |
Kristian Høgsberg | 9e31bff | 2012-08-01 00:08:07 -0400 | [diff] [blame] | 1819 | wl_resource_post_no_memory(resource); |
| 1820 | } |
| 1821 | |
Scott Moreau | c3e54eb | 2012-04-17 19:06:20 -0600 | [diff] [blame] | 1822 | static void |
Kristian Høgsberg | 6780073 | 2013-07-04 01:12:17 -0400 | [diff] [blame] | 1823 | end_busy_cursor(struct shell_surface *shsurf, struct weston_pointer *pointer); |
| 1824 | |
| 1825 | static void |
Kristian Høgsberg | 6848c25 | 2013-05-08 22:02:59 -0400 | [diff] [blame] | 1826 | busy_cursor_grab_focus(struct weston_pointer_grab *base) |
Scott Moreau | c3e54eb | 2012-04-17 19:06:20 -0600 | [diff] [blame] | 1827 | { |
Kristian Høgsberg | d56bd90 | 2012-06-05 09:58:51 -0400 | [diff] [blame] | 1828 | struct shell_grab *grab = (struct shell_grab *) base; |
Kristian Høgsberg | 6848c25 | 2013-05-08 22:02:59 -0400 | [diff] [blame] | 1829 | struct weston_pointer *pointer = base->pointer; |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 1830 | struct weston_view *view; |
Kristian Høgsberg | 6848c25 | 2013-05-08 22:02:59 -0400 | [diff] [blame] | 1831 | wl_fixed_t sx, sy; |
| 1832 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 1833 | view = weston_compositor_pick_view(pointer->seat->compositor, |
| 1834 | pointer->x, pointer->y, |
| 1835 | &sx, &sy); |
Scott Moreau | c3e54eb | 2012-04-17 19:06:20 -0600 | [diff] [blame] | 1836 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 1837 | if (!grab->shsurf || grab->shsurf->surface != view->surface) |
Kristian Høgsberg | 6780073 | 2013-07-04 01:12:17 -0400 | [diff] [blame] | 1838 | end_busy_cursor(grab->shsurf, pointer); |
Scott Moreau | c3e54eb | 2012-04-17 19:06:20 -0600 | [diff] [blame] | 1839 | } |
| 1840 | |
| 1841 | static void |
Giulio Camuffo | 1959ab8 | 2013-11-14 23:42:52 +0100 | [diff] [blame] | 1842 | busy_cursor_grab_motion(struct weston_pointer_grab *grab, uint32_t time, |
| 1843 | wl_fixed_t x, wl_fixed_t y) |
Scott Moreau | c3e54eb | 2012-04-17 19:06:20 -0600 | [diff] [blame] | 1844 | { |
Giulio Camuffo | 1959ab8 | 2013-11-14 23:42:52 +0100 | [diff] [blame] | 1845 | weston_pointer_move(grab->pointer, x, y); |
Kristian Høgsberg | d56bd90 | 2012-06-05 09:58:51 -0400 | [diff] [blame] | 1846 | } |
Scott Moreau | c3e54eb | 2012-04-17 19:06:20 -0600 | [diff] [blame] | 1847 | |
Kristian Høgsberg | d56bd90 | 2012-06-05 09:58:51 -0400 | [diff] [blame] | 1848 | static void |
Kristian Høgsberg | 02bbabb | 2013-05-06 22:15:05 -0400 | [diff] [blame] | 1849 | busy_cursor_grab_button(struct weston_pointer_grab *base, |
Kristian Høgsberg | d56bd90 | 2012-06-05 09:58:51 -0400 | [diff] [blame] | 1850 | uint32_t time, uint32_t button, uint32_t state) |
| 1851 | { |
Kristian Høgsberg | bbe9839 | 2012-08-01 00:20:21 -0400 | [diff] [blame] | 1852 | struct shell_grab *grab = (struct shell_grab *) base; |
Kristian Høgsberg | e122b7b | 2013-05-08 16:47:00 -0400 | [diff] [blame] | 1853 | struct shell_surface *shsurf = grab->shsurf; |
Kristian Høgsberg | e314875 | 2013-05-06 23:19:49 -0400 | [diff] [blame] | 1854 | struct weston_seat *seat = grab->grab.pointer->seat; |
Kristian Høgsberg | bbe9839 | 2012-08-01 00:20:21 -0400 | [diff] [blame] | 1855 | |
Kristian Høgsberg | bbe9839 | 2012-08-01 00:20:21 -0400 | [diff] [blame] | 1856 | if (shsurf && button == BTN_LEFT && state) { |
| 1857 | activate(shsurf->shell, shsurf->surface, seat); |
| 1858 | surface_move(shsurf, seat); |
Kristian Høgsberg | 0c36903 | 2013-02-14 21:31:44 -0500 | [diff] [blame] | 1859 | } else if (shsurf && button == BTN_RIGHT && state) { |
| 1860 | activate(shsurf->shell, shsurf->surface, seat); |
Kristian Høgsberg | e314875 | 2013-05-06 23:19:49 -0400 | [diff] [blame] | 1861 | surface_rotate(shsurf, seat); |
Kristian Høgsberg | bbe9839 | 2012-08-01 00:20:21 -0400 | [diff] [blame] | 1862 | } |
Kristian Høgsberg | d56bd90 | 2012-06-05 09:58:51 -0400 | [diff] [blame] | 1863 | } |
| 1864 | |
Jonas Ådahl | 1ea343e | 2013-10-25 23:18:05 +0200 | [diff] [blame] | 1865 | static void |
| 1866 | busy_cursor_grab_cancel(struct weston_pointer_grab *base) |
| 1867 | { |
| 1868 | struct shell_grab *grab = (struct shell_grab *) base; |
| 1869 | |
| 1870 | shell_grab_end(grab); |
| 1871 | free(grab); |
| 1872 | } |
| 1873 | |
Kristian Høgsberg | 02bbabb | 2013-05-06 22:15:05 -0400 | [diff] [blame] | 1874 | static const struct weston_pointer_grab_interface busy_cursor_grab_interface = { |
Kristian Høgsberg | d56bd90 | 2012-06-05 09:58:51 -0400 | [diff] [blame] | 1875 | busy_cursor_grab_focus, |
| 1876 | busy_cursor_grab_motion, |
| 1877 | busy_cursor_grab_button, |
Jonas Ådahl | 1ea343e | 2013-10-25 23:18:05 +0200 | [diff] [blame] | 1878 | busy_cursor_grab_cancel, |
Kristian Høgsberg | d56bd90 | 2012-06-05 09:58:51 -0400 | [diff] [blame] | 1879 | }; |
| 1880 | |
| 1881 | static void |
Kristian Høgsberg | 02bbabb | 2013-05-06 22:15:05 -0400 | [diff] [blame] | 1882 | set_busy_cursor(struct shell_surface *shsurf, struct weston_pointer *pointer) |
Kristian Høgsberg | d56bd90 | 2012-06-05 09:58:51 -0400 | [diff] [blame] | 1883 | { |
| 1884 | struct shell_grab *grab; |
Kristian Høgsberg | d56bd90 | 2012-06-05 09:58:51 -0400 | [diff] [blame] | 1885 | |
| 1886 | grab = malloc(sizeof *grab); |
| 1887 | if (!grab) |
Scott Moreau | c3e54eb | 2012-04-17 19:06:20 -0600 | [diff] [blame] | 1888 | return; |
| 1889 | |
Ander Conselvan de Oliveira | b9d2a0f | 2012-06-28 18:08:05 +0300 | [diff] [blame] | 1890 | shell_grab_start(grab, &busy_cursor_grab_interface, shsurf, pointer, |
| 1891 | DESKTOP_SHELL_CURSOR_BUSY); |
Kristian Høgsberg | d56bd90 | 2012-06-05 09:58:51 -0400 | [diff] [blame] | 1892 | } |
Scott Moreau | c3e54eb | 2012-04-17 19:06:20 -0600 | [diff] [blame] | 1893 | |
Kristian Høgsberg | d56bd90 | 2012-06-05 09:58:51 -0400 | [diff] [blame] | 1894 | static void |
Kristian Høgsberg | 02bbabb | 2013-05-06 22:15:05 -0400 | [diff] [blame] | 1895 | end_busy_cursor(struct shell_surface *shsurf, struct weston_pointer *pointer) |
Kristian Høgsberg | d56bd90 | 2012-06-05 09:58:51 -0400 | [diff] [blame] | 1896 | { |
| 1897 | struct shell_grab *grab = (struct shell_grab *) pointer->grab; |
| 1898 | |
Kristian Høgsberg | e122b7b | 2013-05-08 16:47:00 -0400 | [diff] [blame] | 1899 | if (grab->grab.interface == &busy_cursor_grab_interface && |
| 1900 | grab->shsurf == shsurf) { |
Ander Conselvan de Oliveira | b9d2a0f | 2012-06-28 18:08:05 +0300 | [diff] [blame] | 1901 | shell_grab_end(grab); |
Kristian Høgsberg | d56bd90 | 2012-06-05 09:58:51 -0400 | [diff] [blame] | 1902 | free(grab); |
Scott Moreau | c3e54eb | 2012-04-17 19:06:20 -0600 | [diff] [blame] | 1903 | } |
Scott Moreau | c3e54eb | 2012-04-17 19:06:20 -0600 | [diff] [blame] | 1904 | } |
| 1905 | |
Scott Moreau | 9521d5e | 2012-04-19 13:06:17 -0600 | [diff] [blame] | 1906 | static void |
| 1907 | ping_timer_destroy(struct shell_surface *shsurf) |
| 1908 | { |
| 1909 | if (!shsurf || !shsurf->ping_timer) |
| 1910 | return; |
| 1911 | |
| 1912 | if (shsurf->ping_timer->source) |
| 1913 | wl_event_source_remove(shsurf->ping_timer->source); |
| 1914 | |
| 1915 | free(shsurf->ping_timer); |
| 1916 | shsurf->ping_timer = NULL; |
| 1917 | } |
| 1918 | |
Kristian Høgsberg | 97d44aa | 2011-08-26 17:21:20 -0400 | [diff] [blame] | 1919 | static int |
Scott Moreau | ff1db4a | 2012-04-17 19:06:18 -0600 | [diff] [blame] | 1920 | ping_timeout_handler(void *data) |
| 1921 | { |
| 1922 | struct shell_surface *shsurf = data; |
Kristian Høgsberg | d56bd90 | 2012-06-05 09:58:51 -0400 | [diff] [blame] | 1923 | struct weston_seat *seat; |
Scott Moreau | ff1db4a | 2012-04-17 19:06:18 -0600 | [diff] [blame] | 1924 | |
Scott Moreau | 9521d5e | 2012-04-19 13:06:17 -0600 | [diff] [blame] | 1925 | /* Client is not responding */ |
| 1926 | shsurf->unresponsive = 1; |
Kristian Høgsberg | d56bd90 | 2012-06-05 09:58:51 -0400 | [diff] [blame] | 1927 | |
| 1928 | wl_list_for_each(seat, &shsurf->surface->compositor->seat_list, link) |
Emilio Pozuelo Monfort | 3d0fc76 | 2013-11-22 16:21:20 +0100 | [diff] [blame] | 1929 | if (seat->pointer->focus && |
| 1930 | seat->pointer->focus->surface == shsurf->surface) |
Kristian Høgsberg | e314875 | 2013-05-06 23:19:49 -0400 | [diff] [blame] | 1931 | set_busy_cursor(shsurf, seat->pointer); |
Scott Moreau | ff1db4a | 2012-04-17 19:06:18 -0600 | [diff] [blame] | 1932 | |
| 1933 | return 1; |
| 1934 | } |
| 1935 | |
| 1936 | static void |
| 1937 | ping_handler(struct weston_surface *surface, uint32_t serial) |
| 1938 | { |
Kristian Høgsberg | b71302e | 2012-05-10 12:28:35 -0400 | [diff] [blame] | 1939 | struct shell_surface *shsurf = get_shell_surface(surface); |
Scott Moreau | ff1db4a | 2012-04-17 19:06:18 -0600 | [diff] [blame] | 1940 | struct wl_event_loop *loop; |
Kristian Høgsberg | d56bd90 | 2012-06-05 09:58:51 -0400 | [diff] [blame] | 1941 | int ping_timeout = 200; |
Scott Moreau | ff1db4a | 2012-04-17 19:06:18 -0600 | [diff] [blame] | 1942 | |
| 1943 | if (!shsurf) |
| 1944 | return; |
Jason Ekstrand | 651f00e | 2013-06-14 10:07:54 -0500 | [diff] [blame] | 1945 | if (!shsurf->resource) |
Kristian Høgsberg | ca535c1 | 2012-04-21 23:20:07 -0400 | [diff] [blame] | 1946 | return; |
Scott Moreau | ff1db4a | 2012-04-17 19:06:18 -0600 | [diff] [blame] | 1947 | |
Ander Conselvan de Oliveira | eac9a46 | 2012-07-16 14:15:48 +0300 | [diff] [blame] | 1948 | if (shsurf->surface == shsurf->shell->grab_surface) |
| 1949 | return; |
| 1950 | |
Scott Moreau | ff1db4a | 2012-04-17 19:06:18 -0600 | [diff] [blame] | 1951 | if (!shsurf->ping_timer) { |
Ander Conselvan de Oliveira | fb98089 | 2012-04-27 13:55:55 +0300 | [diff] [blame] | 1952 | shsurf->ping_timer = malloc(sizeof *shsurf->ping_timer); |
Scott Moreau | ff1db4a | 2012-04-17 19:06:18 -0600 | [diff] [blame] | 1953 | if (!shsurf->ping_timer) |
| 1954 | return; |
| 1955 | |
| 1956 | shsurf->ping_timer->serial = serial; |
Scott Moreau | ff1db4a | 2012-04-17 19:06:18 -0600 | [diff] [blame] | 1957 | loop = wl_display_get_event_loop(surface->compositor->wl_display); |
| 1958 | shsurf->ping_timer->source = |
| 1959 | wl_event_loop_add_timer(loop, ping_timeout_handler, shsurf); |
| 1960 | wl_event_source_timer_update(shsurf->ping_timer->source, ping_timeout); |
| 1961 | |
Jason Ekstrand | 651f00e | 2013-06-14 10:07:54 -0500 | [diff] [blame] | 1962 | wl_shell_surface_send_ping(shsurf->resource, serial); |
Scott Moreau | ff1db4a | 2012-04-17 19:06:18 -0600 | [diff] [blame] | 1963 | } |
| 1964 | } |
| 1965 | |
| 1966 | static void |
Kristian Høgsberg | d56bd90 | 2012-06-05 09:58:51 -0400 | [diff] [blame] | 1967 | handle_pointer_focus(struct wl_listener *listener, void *data) |
| 1968 | { |
Kristian Høgsberg | 02bbabb | 2013-05-06 22:15:05 -0400 | [diff] [blame] | 1969 | struct weston_pointer *pointer = data; |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 1970 | struct weston_view *view = pointer->focus; |
Kristian Høgsberg | d56bd90 | 2012-06-05 09:58:51 -0400 | [diff] [blame] | 1971 | struct weston_compositor *compositor; |
| 1972 | struct shell_surface *shsurf; |
| 1973 | uint32_t serial; |
| 1974 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 1975 | if (!view) |
Kristian Høgsberg | d56bd90 | 2012-06-05 09:58:51 -0400 | [diff] [blame] | 1976 | return; |
| 1977 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 1978 | compositor = view->surface->compositor; |
| 1979 | shsurf = get_shell_surface(view->surface); |
Kristian Høgsberg | d56bd90 | 2012-06-05 09:58:51 -0400 | [diff] [blame] | 1980 | |
Pekka Paalanen | 4e1f2ff | 2012-06-06 16:59:45 +0300 | [diff] [blame] | 1981 | if (shsurf && shsurf->unresponsive) { |
Kristian Høgsberg | d56bd90 | 2012-06-05 09:58:51 -0400 | [diff] [blame] | 1982 | set_busy_cursor(shsurf, pointer); |
| 1983 | } else { |
| 1984 | serial = wl_display_next_serial(compositor->wl_display); |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 1985 | ping_handler(view->surface, serial); |
Kristian Høgsberg | d56bd90 | 2012-06-05 09:58:51 -0400 | [diff] [blame] | 1986 | } |
| 1987 | } |
| 1988 | |
| 1989 | static void |
Kristian Høgsberg | f4d2f23 | 2012-08-10 10:05:39 -0400 | [diff] [blame] | 1990 | create_pointer_focus_listener(struct weston_seat *seat) |
| 1991 | { |
| 1992 | struct wl_listener *listener; |
| 1993 | |
Kristian Høgsberg | e314875 | 2013-05-06 23:19:49 -0400 | [diff] [blame] | 1994 | if (!seat->pointer) |
Kristian Høgsberg | f4d2f23 | 2012-08-10 10:05:39 -0400 | [diff] [blame] | 1995 | return; |
| 1996 | |
| 1997 | listener = malloc(sizeof *listener); |
| 1998 | listener->notify = handle_pointer_focus; |
Kristian Høgsberg | e314875 | 2013-05-06 23:19:49 -0400 | [diff] [blame] | 1999 | wl_signal_add(&seat->pointer->focus_signal, listener); |
Kristian Høgsberg | f4d2f23 | 2012-08-10 10:05:39 -0400 | [diff] [blame] | 2000 | } |
| 2001 | |
| 2002 | static void |
Scott Moreau | ff1db4a | 2012-04-17 19:06:18 -0600 | [diff] [blame] | 2003 | shell_surface_pong(struct wl_client *client, struct wl_resource *resource, |
| 2004 | uint32_t serial) |
| 2005 | { |
Jason Ekstrand | 651f00e | 2013-06-14 10:07:54 -0500 | [diff] [blame] | 2006 | struct shell_surface *shsurf = wl_resource_get_user_data(resource); |
Kristian Høgsberg | d56bd90 | 2012-06-05 09:58:51 -0400 | [diff] [blame] | 2007 | struct weston_seat *seat; |
| 2008 | struct weston_compositor *ec = shsurf->surface->compositor; |
Scott Moreau | ff1db4a | 2012-04-17 19:06:18 -0600 | [diff] [blame] | 2009 | |
Kristian Høgsberg | 92374e1 | 2012-08-11 22:39:12 -0400 | [diff] [blame] | 2010 | if (shsurf->ping_timer == NULL) |
| 2011 | /* Just ignore unsolicited pong. */ |
| 2012 | return; |
| 2013 | |
Scott Moreau | ff1db4a | 2012-04-17 19:06:18 -0600 | [diff] [blame] | 2014 | if (shsurf->ping_timer->serial == serial) { |
Scott Moreau | ff1db4a | 2012-04-17 19:06:18 -0600 | [diff] [blame] | 2015 | shsurf->unresponsive = 0; |
Hardening | eb1e130 | 2013-05-17 18:07:41 +0200 | [diff] [blame] | 2016 | wl_list_for_each(seat, &ec->seat_list, link) { |
| 2017 | if(seat->pointer) |
| 2018 | end_busy_cursor(shsurf, seat->pointer); |
| 2019 | } |
Scott Moreau | 9521d5e | 2012-04-19 13:06:17 -0600 | [diff] [blame] | 2020 | ping_timer_destroy(shsurf); |
Scott Moreau | ff1db4a | 2012-04-17 19:06:18 -0600 | [diff] [blame] | 2021 | } |
| 2022 | } |
| 2023 | |
Kristian Høgsberg | e7afd91 | 2012-05-02 09:47:44 -0400 | [diff] [blame] | 2024 | static void |
Giulio Camuffo | 62942ad | 2013-09-11 18:20:47 +0200 | [diff] [blame] | 2025 | set_title(struct shell_surface *shsurf, const char *title) |
| 2026 | { |
| 2027 | free(shsurf->title); |
| 2028 | shsurf->title = strdup(title); |
| 2029 | } |
| 2030 | |
| 2031 | static void |
Kristian Høgsberg | e7afd91 | 2012-05-02 09:47:44 -0400 | [diff] [blame] | 2032 | shell_surface_set_title(struct wl_client *client, |
| 2033 | struct wl_resource *resource, const char *title) |
| 2034 | { |
Jason Ekstrand | 651f00e | 2013-06-14 10:07:54 -0500 | [diff] [blame] | 2035 | struct shell_surface *shsurf = wl_resource_get_user_data(resource); |
Kristian Høgsberg | e7afd91 | 2012-05-02 09:47:44 -0400 | [diff] [blame] | 2036 | |
Giulio Camuffo | 62942ad | 2013-09-11 18:20:47 +0200 | [diff] [blame] | 2037 | set_title(shsurf, title); |
Kristian Høgsberg | e7afd91 | 2012-05-02 09:47:44 -0400 | [diff] [blame] | 2038 | } |
| 2039 | |
| 2040 | static void |
| 2041 | shell_surface_set_class(struct wl_client *client, |
| 2042 | struct wl_resource *resource, const char *class) |
| 2043 | { |
Jason Ekstrand | 651f00e | 2013-06-14 10:07:54 -0500 | [diff] [blame] | 2044 | struct shell_surface *shsurf = wl_resource_get_user_data(resource); |
Kristian Høgsberg | e7afd91 | 2012-05-02 09:47:44 -0400 | [diff] [blame] | 2045 | |
| 2046 | free(shsurf->class); |
| 2047 | shsurf->class = strdup(class); |
| 2048 | } |
| 2049 | |
Alex Wu | 4539b08 | 2012-03-01 12:57:46 +0800 | [diff] [blame] | 2050 | static void |
Alexander Larsson | f82b6ca | 2013-05-28 16:23:39 +0200 | [diff] [blame] | 2051 | restore_output_mode(struct weston_output *output) |
| 2052 | { |
Hardening | 57388e4 | 2013-09-18 23:56:36 +0200 | [diff] [blame] | 2053 | if (output->current_mode != output->original_mode || |
| 2054 | (int32_t)output->current_scale != output->original_scale) |
Alexander Larsson | f82b6ca | 2013-05-28 16:23:39 +0200 | [diff] [blame] | 2055 | weston_output_switch_mode(output, |
Hardening | 57388e4 | 2013-09-18 23:56:36 +0200 | [diff] [blame] | 2056 | output->original_mode, |
| 2057 | output->original_scale, |
| 2058 | WESTON_MODE_SWITCH_RESTORE_NATIVE); |
Alexander Larsson | f82b6ca | 2013-05-28 16:23:39 +0200 | [diff] [blame] | 2059 | } |
| 2060 | |
| 2061 | static void |
| 2062 | restore_all_output_modes(struct weston_compositor *compositor) |
| 2063 | { |
| 2064 | struct weston_output *output; |
| 2065 | |
| 2066 | wl_list_for_each(output, &compositor->output_list, link) |
| 2067 | restore_output_mode(output); |
| 2068 | } |
| 2069 | |
Philip Withnall | becb77e | 2013-11-25 18:01:30 +0000 | [diff] [blame] | 2070 | static int |
| 2071 | get_output_panel_height(struct desktop_shell *shell, |
| 2072 | struct weston_output *output) |
| 2073 | { |
| 2074 | struct weston_view *view; |
| 2075 | int panel_height = 0; |
| 2076 | |
| 2077 | if (!output) |
| 2078 | return 0; |
| 2079 | |
| 2080 | wl_list_for_each(view, &shell->panel_layer.view_list, layer_link) { |
| 2081 | if (view->surface->output == output) { |
| 2082 | panel_height = view->geometry.height; |
| 2083 | break; |
| 2084 | } |
| 2085 | } |
| 2086 | |
| 2087 | return panel_height; |
| 2088 | } |
| 2089 | |
Philip Withnall | 07926d9 | 2013-11-25 18:01:40 +0000 | [diff] [blame] | 2090 | /* The surface will be inserted into the list immediately after the link |
| 2091 | * returned by this function (i.e. will be stacked immediately above the |
| 2092 | * returned link). */ |
| 2093 | static struct wl_list * |
| 2094 | shell_surface_calculate_layer_link (struct shell_surface *shsurf) |
| 2095 | { |
| 2096 | struct workspace *ws; |
| 2097 | |
| 2098 | switch (shsurf->type) { |
| 2099 | case SHELL_SURFACE_POPUP: |
| 2100 | case SHELL_SURFACE_TRANSIENT: { |
| 2101 | /* Move the surface to its parent layer so that surfaces which |
| 2102 | * are transient for fullscreen surfaces don't get hidden by the |
| 2103 | * fullscreen surfaces. */ |
| 2104 | struct weston_view *parent; |
| 2105 | |
| 2106 | /* TODO: Handle a parent with multiple views */ |
| 2107 | parent = get_default_view(shsurf->parent); |
| 2108 | if (parent) |
| 2109 | return parent->layer_link.prev; |
| 2110 | |
| 2111 | break; |
| 2112 | } |
| 2113 | |
| 2114 | case SHELL_SURFACE_FULLSCREEN: |
| 2115 | return &shsurf->shell->fullscreen_layer.view_list; |
| 2116 | |
| 2117 | case SHELL_SURFACE_XWAYLAND: |
| 2118 | case SHELL_SURFACE_TOPLEVEL: |
| 2119 | case SHELL_SURFACE_MAXIMIZED: |
| 2120 | case SHELL_SURFACE_NONE: |
| 2121 | default: |
| 2122 | /* Go to the fallback, below. */ |
| 2123 | break; |
| 2124 | } |
| 2125 | |
| 2126 | /* Move the surface to a normal workspace layer so that surfaces |
| 2127 | * which were previously fullscreen or transient are no longer |
| 2128 | * rendered on top. */ |
| 2129 | ws = get_current_workspace(shsurf->shell); |
| 2130 | return &ws->layer.view_list; |
| 2131 | } |
| 2132 | |
Philip Withnall | 648a4dd | 2013-11-25 18:01:44 +0000 | [diff] [blame^] | 2133 | static void |
| 2134 | shell_surface_update_child_surface_layers (struct shell_surface *shsurf) |
| 2135 | { |
| 2136 | struct shell_surface *child; |
| 2137 | |
| 2138 | /* Move the child layers to the same workspace as shsurf. They will be |
| 2139 | * stacked above shsurf. */ |
| 2140 | wl_list_for_each_reverse(child, &shsurf->children_list, children_link) { |
| 2141 | if (shsurf->view->layer_link.prev != &child->view->layer_link) { |
| 2142 | weston_view_geometry_dirty(child->view); |
| 2143 | wl_list_remove(&child->view->layer_link); |
| 2144 | wl_list_insert(shsurf->view->layer_link.prev, |
| 2145 | &child->view->layer_link); |
| 2146 | weston_view_geometry_dirty(child->view); |
| 2147 | weston_surface_damage(child->surface); |
| 2148 | |
| 2149 | /* Recurse. We don’t expect this to recurse very far (if |
| 2150 | * at all) because that would imply we have transient |
| 2151 | * (or popup) children of transient surfaces, which |
| 2152 | * would be unusual. */ |
| 2153 | shell_surface_update_child_surface_layers(child); |
| 2154 | } |
| 2155 | } |
| 2156 | } |
| 2157 | |
Philip Withnall | e1d75ae | 2013-11-25 18:01:41 +0000 | [diff] [blame] | 2158 | /* 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^] | 2159 | * geometry to ensure the changes are redrawn. |
| 2160 | * |
| 2161 | * If any child surfaces exist and are mapped, ensure they’re in the same layer |
| 2162 | * as this surface. */ |
Philip Withnall | e1d75ae | 2013-11-25 18:01:41 +0000 | [diff] [blame] | 2163 | static void |
| 2164 | shell_surface_update_layer(struct shell_surface *shsurf) |
| 2165 | { |
| 2166 | struct wl_list *new_layer_link; |
| 2167 | |
| 2168 | new_layer_link = shell_surface_calculate_layer_link(shsurf); |
| 2169 | |
| 2170 | if (new_layer_link == &shsurf->view->layer_link) |
| 2171 | return; |
| 2172 | |
| 2173 | weston_view_geometry_dirty(shsurf->view); |
| 2174 | wl_list_remove(&shsurf->view->layer_link); |
| 2175 | wl_list_insert(new_layer_link, &shsurf->view->layer_link); |
| 2176 | weston_view_geometry_dirty(shsurf->view); |
| 2177 | weston_surface_damage(shsurf->surface); |
Philip Withnall | 648a4dd | 2013-11-25 18:01:44 +0000 | [diff] [blame^] | 2178 | |
| 2179 | shell_surface_update_child_surface_layers(shsurf); |
Philip Withnall | e1d75ae | 2013-11-25 18:01:41 +0000 | [diff] [blame] | 2180 | } |
| 2181 | |
Alexander Larsson | f82b6ca | 2013-05-28 16:23:39 +0200 | [diff] [blame] | 2182 | static void |
Philip Withnall | dc4332f | 2013-11-25 18:01:38 +0000 | [diff] [blame] | 2183 | shell_surface_set_parent(struct shell_surface *shsurf, |
| 2184 | struct weston_surface *parent) |
| 2185 | { |
| 2186 | shsurf->parent = parent; |
Philip Withnall | 648a4dd | 2013-11-25 18:01:44 +0000 | [diff] [blame^] | 2187 | |
| 2188 | wl_list_remove(&shsurf->children_link); |
| 2189 | wl_list_init(&shsurf->children_link); |
| 2190 | |
| 2191 | /* Insert into the parent surface’s child list. */ |
| 2192 | if (parent != NULL) { |
| 2193 | struct shell_surface *parent_shsurf = get_shell_surface(parent); |
| 2194 | if (parent_shsurf != NULL) |
| 2195 | wl_list_insert(&parent_shsurf->children_list, |
| 2196 | &shsurf->children_link); |
| 2197 | } |
Philip Withnall | dc4332f | 2013-11-25 18:01:38 +0000 | [diff] [blame] | 2198 | } |
| 2199 | |
| 2200 | static void |
Philip Withnall | 352e7ed | 2013-11-25 18:01:35 +0000 | [diff] [blame] | 2201 | shell_surface_set_output(struct shell_surface *shsurf, |
| 2202 | struct weston_output *output) |
| 2203 | { |
| 2204 | struct weston_surface *es = shsurf->surface; |
| 2205 | |
| 2206 | /* get the default output, if the client set it as NULL |
| 2207 | check whether the ouput is available */ |
| 2208 | if (output) |
| 2209 | shsurf->output = output; |
| 2210 | else if (es->output) |
| 2211 | shsurf->output = es->output; |
| 2212 | else |
| 2213 | shsurf->output = get_default_output(es->compositor); |
| 2214 | } |
| 2215 | |
| 2216 | static void |
Philip Withnall | becb77e | 2013-11-25 18:01:30 +0000 | [diff] [blame] | 2217 | set_toplevel(struct shell_surface *shsurf) |
| 2218 | { |
Philip Withnall | dc4332f | 2013-11-25 18:01:38 +0000 | [diff] [blame] | 2219 | shell_surface_set_parent(shsurf, NULL); |
| 2220 | |
Philip Withnall | becb77e | 2013-11-25 18:01:30 +0000 | [diff] [blame] | 2221 | shsurf->next_type = SHELL_SURFACE_TOPLEVEL; |
Philip Withnall | 648a4dd | 2013-11-25 18:01:44 +0000 | [diff] [blame^] | 2222 | |
| 2223 | /* The layer_link is updated in set_surface_type(), |
| 2224 | * called from configure. */ |
Philip Withnall | becb77e | 2013-11-25 18:01:30 +0000 | [diff] [blame] | 2225 | } |
| 2226 | |
| 2227 | static void |
| 2228 | shell_surface_set_toplevel(struct wl_client *client, |
| 2229 | struct wl_resource *resource) |
| 2230 | { |
| 2231 | struct shell_surface *surface = wl_resource_get_user_data(resource); |
| 2232 | |
| 2233 | set_toplevel(surface); |
| 2234 | } |
| 2235 | |
| 2236 | static void |
| 2237 | set_transient(struct shell_surface *shsurf, |
| 2238 | struct weston_surface *parent, int x, int y, uint32_t flags) |
| 2239 | { |
Philip Withnall | dc4332f | 2013-11-25 18:01:38 +0000 | [diff] [blame] | 2240 | assert(parent != NULL); |
| 2241 | |
Philip Withnall | becb77e | 2013-11-25 18:01:30 +0000 | [diff] [blame] | 2242 | shsurf->transient.x = x; |
| 2243 | shsurf->transient.y = y; |
| 2244 | shsurf->transient.flags = flags; |
Philip Withnall | dc4332f | 2013-11-25 18:01:38 +0000 | [diff] [blame] | 2245 | |
| 2246 | shell_surface_set_parent(shsurf, parent); |
| 2247 | |
Philip Withnall | becb77e | 2013-11-25 18:01:30 +0000 | [diff] [blame] | 2248 | shsurf->next_type = SHELL_SURFACE_TRANSIENT; |
Philip Withnall | 648a4dd | 2013-11-25 18:01:44 +0000 | [diff] [blame^] | 2249 | |
| 2250 | /* The layer_link is updated in set_surface_type(), |
| 2251 | * called from configure. */ |
Philip Withnall | becb77e | 2013-11-25 18:01:30 +0000 | [diff] [blame] | 2252 | } |
| 2253 | |
| 2254 | static void |
| 2255 | shell_surface_set_transient(struct wl_client *client, |
| 2256 | struct wl_resource *resource, |
| 2257 | struct wl_resource *parent_resource, |
| 2258 | int x, int y, uint32_t flags) |
| 2259 | { |
| 2260 | struct shell_surface *shsurf = wl_resource_get_user_data(resource); |
| 2261 | struct weston_surface *parent = |
| 2262 | wl_resource_get_user_data(parent_resource); |
| 2263 | |
| 2264 | set_transient(shsurf, parent, x, y, flags); |
| 2265 | } |
| 2266 | |
| 2267 | static void |
| 2268 | set_fullscreen(struct shell_surface *shsurf, |
| 2269 | uint32_t method, |
| 2270 | uint32_t framerate, |
| 2271 | struct weston_output *output) |
| 2272 | { |
Philip Withnall | 352e7ed | 2013-11-25 18:01:35 +0000 | [diff] [blame] | 2273 | shell_surface_set_output(shsurf, output); |
Philip Withnall | becb77e | 2013-11-25 18:01:30 +0000 | [diff] [blame] | 2274 | |
| 2275 | shsurf->fullscreen_output = shsurf->output; |
| 2276 | shsurf->fullscreen.type = method; |
| 2277 | shsurf->fullscreen.framerate = framerate; |
Philip Withnall | dc4332f | 2013-11-25 18:01:38 +0000 | [diff] [blame] | 2278 | |
| 2279 | shell_surface_set_parent(shsurf, NULL); |
| 2280 | |
Philip Withnall | becb77e | 2013-11-25 18:01:30 +0000 | [diff] [blame] | 2281 | shsurf->next_type = SHELL_SURFACE_FULLSCREEN; |
| 2282 | |
| 2283 | shsurf->client->send_configure(shsurf->surface, 0, |
| 2284 | shsurf->output->width, |
| 2285 | shsurf->output->height); |
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 | unset_fullscreen(struct shell_surface *shsurf) |
Alex Wu | 4539b08 | 2012-03-01 12:57:46 +0800 | [diff] [blame] | 2293 | { |
Philip Withnall | f85fe84 | 2013-11-25 18:01:37 +0000 | [diff] [blame] | 2294 | /* Unset the fullscreen output, driver configuration and transforms. */ |
Alex Wu | bd3354b | 2012-04-17 17:20:49 +0800 | [diff] [blame] | 2295 | if (shsurf->fullscreen.type == WL_SHELL_SURFACE_FULLSCREEN_METHOD_DRIVER && |
| 2296 | shell_surface_is_top_fullscreen(shsurf)) { |
Alexander Larsson | f82b6ca | 2013-05-28 16:23:39 +0200 | [diff] [blame] | 2297 | restore_output_mode(shsurf->fullscreen_output); |
Alex Wu | bd3354b | 2012-04-17 17:20:49 +0800 | [diff] [blame] | 2298 | } |
Philip Withnall | f85fe84 | 2013-11-25 18:01:37 +0000 | [diff] [blame] | 2299 | shsurf->fullscreen_output = NULL; |
| 2300 | |
Alex Wu | 4539b08 | 2012-03-01 12:57:46 +0800 | [diff] [blame] | 2301 | shsurf->fullscreen.type = WL_SHELL_SURFACE_FULLSCREEN_METHOD_DEFAULT; |
| 2302 | shsurf->fullscreen.framerate = 0; |
Philip Withnall | f85fe84 | 2013-11-25 18:01:37 +0000 | [diff] [blame] | 2303 | |
Alex Wu | 4539b08 | 2012-03-01 12:57:46 +0800 | [diff] [blame] | 2304 | wl_list_remove(&shsurf->fullscreen.transform.link); |
| 2305 | wl_list_init(&shsurf->fullscreen.transform.link); |
Philip Withnall | f85fe84 | 2013-11-25 18:01:37 +0000 | [diff] [blame] | 2306 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 2307 | if (shsurf->fullscreen.black_view) |
| 2308 | weston_surface_destroy(shsurf->fullscreen.black_view->surface); |
| 2309 | shsurf->fullscreen.black_view = NULL; |
Philip Withnall | f85fe84 | 2013-11-25 18:01:37 +0000 | [diff] [blame] | 2310 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 2311 | weston_view_set_position(shsurf->view, |
| 2312 | shsurf->saved_x, shsurf->saved_y); |
Alex Wu | 7bcb8bd | 2012-04-27 09:07:24 +0800 | [diff] [blame] | 2313 | if (shsurf->saved_rotation_valid) { |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 2314 | wl_list_insert(&shsurf->view->geometry.transformation_list, |
Philip Withnall | becb77e | 2013-11-25 18:01:30 +0000 | [diff] [blame] | 2315 | &shsurf->rotation.transform.link); |
Alex Wu | 7bcb8bd | 2012-04-27 09:07:24 +0800 | [diff] [blame] | 2316 | shsurf->saved_rotation_valid = false; |
| 2317 | } |
Rafal Mielniczuk | 3e3862c | 2012-10-07 20:25:36 +0200 | [diff] [blame] | 2318 | |
Philip Withnall | e1d75ae | 2013-11-25 18:01:41 +0000 | [diff] [blame] | 2319 | /* Layer is updated in set_surface_type(). */ |
Alex Wu | 4539b08 | 2012-03-01 12:57:46 +0800 | [diff] [blame] | 2320 | } |
| 2321 | |
Rafal Mielniczuk | fffdcdd | 2013-03-11 19:26:54 +0100 | [diff] [blame] | 2322 | static void |
Philip Withnall | becb77e | 2013-11-25 18:01:30 +0000 | [diff] [blame] | 2323 | shell_surface_set_fullscreen(struct wl_client *client, |
| 2324 | struct wl_resource *resource, |
| 2325 | uint32_t method, |
| 2326 | uint32_t framerate, |
| 2327 | struct wl_resource *output_resource) |
| 2328 | { |
| 2329 | struct shell_surface *shsurf = wl_resource_get_user_data(resource); |
| 2330 | struct weston_output *output; |
| 2331 | |
| 2332 | if (output_resource) |
| 2333 | output = wl_resource_get_user_data(output_resource); |
| 2334 | else |
| 2335 | output = NULL; |
| 2336 | |
| 2337 | set_fullscreen(shsurf, method, framerate, output); |
| 2338 | } |
| 2339 | |
| 2340 | static void |
| 2341 | set_popup(struct shell_surface *shsurf, |
| 2342 | struct weston_surface *parent, |
| 2343 | struct weston_seat *seat, |
| 2344 | uint32_t serial, |
| 2345 | int32_t x, |
| 2346 | int32_t y) |
| 2347 | { |
Philip Withnall | dc4332f | 2013-11-25 18:01:38 +0000 | [diff] [blame] | 2348 | assert(parent != NULL); |
| 2349 | |
Philip Withnall | becb77e | 2013-11-25 18:01:30 +0000 | [diff] [blame] | 2350 | shsurf->popup.shseat = get_shell_seat(seat); |
| 2351 | shsurf->popup.serial = serial; |
| 2352 | shsurf->popup.x = x; |
| 2353 | shsurf->popup.y = y; |
Philip Withnall | dc4332f | 2013-11-25 18:01:38 +0000 | [diff] [blame] | 2354 | |
| 2355 | shell_surface_set_parent(shsurf, parent); |
Philip Withnall | b995e1d | 2013-11-25 18:01:39 +0000 | [diff] [blame] | 2356 | |
| 2357 | shsurf->next_type = SHELL_SURFACE_POPUP; |
Philip Withnall | becb77e | 2013-11-25 18:01:30 +0000 | [diff] [blame] | 2358 | } |
| 2359 | |
| 2360 | static void |
| 2361 | shell_surface_set_popup(struct wl_client *client, |
| 2362 | struct wl_resource *resource, |
| 2363 | struct wl_resource *seat_resource, |
| 2364 | uint32_t serial, |
| 2365 | struct wl_resource *parent_resource, |
| 2366 | int32_t x, int32_t y, uint32_t flags) |
| 2367 | { |
| 2368 | struct shell_surface *shsurf = wl_resource_get_user_data(resource); |
| 2369 | |
| 2370 | set_popup(shsurf, |
| 2371 | wl_resource_get_user_data(parent_resource), |
| 2372 | wl_resource_get_user_data(seat_resource), |
| 2373 | serial, x, y); |
| 2374 | } |
| 2375 | |
| 2376 | static void |
| 2377 | set_maximized(struct shell_surface *shsurf, |
| 2378 | struct weston_output *output) |
| 2379 | { |
| 2380 | struct desktop_shell *shell; |
| 2381 | uint32_t edges = 0, panel_height = 0; |
Philip Withnall | becb77e | 2013-11-25 18:01:30 +0000 | [diff] [blame] | 2382 | |
Philip Withnall | 352e7ed | 2013-11-25 18:01:35 +0000 | [diff] [blame] | 2383 | shell_surface_set_output(shsurf, output); |
Philip Withnall | becb77e | 2013-11-25 18:01:30 +0000 | [diff] [blame] | 2384 | |
| 2385 | shell = shell_surface_get_shell(shsurf); |
| 2386 | panel_height = get_output_panel_height(shell, shsurf->output); |
| 2387 | edges = WL_SHELL_SURFACE_RESIZE_TOP | WL_SHELL_SURFACE_RESIZE_LEFT; |
| 2388 | |
| 2389 | shsurf->client->send_configure(shsurf->surface, edges, |
| 2390 | shsurf->output->width, |
| 2391 | shsurf->output->height - panel_height); |
| 2392 | |
Philip Withnall | dc4332f | 2013-11-25 18:01:38 +0000 | [diff] [blame] | 2393 | shell_surface_set_parent(shsurf, NULL); |
| 2394 | |
Philip Withnall | becb77e | 2013-11-25 18:01:30 +0000 | [diff] [blame] | 2395 | shsurf->next_type = SHELL_SURFACE_MAXIMIZED; |
| 2396 | } |
| 2397 | |
| 2398 | static void |
| 2399 | unset_maximized(struct shell_surface *shsurf) |
Rafal Mielniczuk | fffdcdd | 2013-03-11 19:26:54 +0100 | [diff] [blame] | 2400 | { |
Rafal Mielniczuk | fffdcdd | 2013-03-11 19:26:54 +0100 | [diff] [blame] | 2401 | /* undo all maximized things here */ |
| 2402 | shsurf->output = get_default_output(shsurf->surface->compositor); |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 2403 | weston_view_set_position(shsurf->view, |
| 2404 | shsurf->saved_x, |
| 2405 | shsurf->saved_y); |
Rafal Mielniczuk | fffdcdd | 2013-03-11 19:26:54 +0100 | [diff] [blame] | 2406 | |
| 2407 | if (shsurf->saved_rotation_valid) { |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 2408 | wl_list_insert(&shsurf->view->geometry.transformation_list, |
| 2409 | &shsurf->rotation.transform.link); |
Rafal Mielniczuk | fffdcdd | 2013-03-11 19:26:54 +0100 | [diff] [blame] | 2410 | shsurf->saved_rotation_valid = false; |
| 2411 | } |
| 2412 | |
Philip Withnall | e1d75ae | 2013-11-25 18:01:41 +0000 | [diff] [blame] | 2413 | /* Layer is updated in set_surface_type(). */ |
Rafal Mielniczuk | fffdcdd | 2013-03-11 19:26:54 +0100 | [diff] [blame] | 2414 | } |
| 2415 | |
Philip Withnall | becb77e | 2013-11-25 18:01:30 +0000 | [diff] [blame] | 2416 | static void |
| 2417 | shell_surface_set_maximized(struct wl_client *client, |
| 2418 | struct wl_resource *resource, |
| 2419 | struct wl_resource *output_resource) |
| 2420 | { |
| 2421 | struct shell_surface *shsurf = wl_resource_get_user_data(resource); |
| 2422 | struct weston_output *output; |
| 2423 | |
| 2424 | if (output_resource) |
| 2425 | output = wl_resource_get_user_data(output_resource); |
| 2426 | else |
| 2427 | output = NULL; |
| 2428 | |
| 2429 | set_maximized(shsurf, output); |
| 2430 | } |
| 2431 | |
Philip Withnall | e1d75ae | 2013-11-25 18:01:41 +0000 | [diff] [blame] | 2432 | /* This is only ever called from set_surface_type(), so there’s no need to |
| 2433 | * update layer_links here, since they’ll be updated when we return. */ |
Pekka Paalanen | 9826223 | 2011-12-01 10:42:22 +0200 | [diff] [blame] | 2434 | static int |
Philip Withnall | becb77e | 2013-11-25 18:01:30 +0000 | [diff] [blame] | 2435 | reset_surface_type(struct shell_surface *surface) |
Pekka Paalanen | 9826223 | 2011-12-01 10:42:22 +0200 | [diff] [blame] | 2436 | { |
| 2437 | switch (surface->type) { |
| 2438 | case SHELL_SURFACE_FULLSCREEN: |
Philip Withnall | becb77e | 2013-11-25 18:01:30 +0000 | [diff] [blame] | 2439 | unset_fullscreen(surface); |
Pekka Paalanen | 9826223 | 2011-12-01 10:42:22 +0200 | [diff] [blame] | 2440 | break; |
Juan Zhao | 96879df | 2012-02-07 08:45:41 +0800 | [diff] [blame] | 2441 | case SHELL_SURFACE_MAXIMIZED: |
Philip Withnall | becb77e | 2013-11-25 18:01:30 +0000 | [diff] [blame] | 2442 | unset_maximized(surface); |
Juan Zhao | 96879df | 2012-02-07 08:45:41 +0800 | [diff] [blame] | 2443 | break; |
Pekka Paalanen | 9826223 | 2011-12-01 10:42:22 +0200 | [diff] [blame] | 2444 | case SHELL_SURFACE_NONE: |
| 2445 | case SHELL_SURFACE_TOPLEVEL: |
| 2446 | case SHELL_SURFACE_TRANSIENT: |
Kristian Høgsberg | b3cca0a | 2012-01-04 22:19:14 -0500 | [diff] [blame] | 2447 | case SHELL_SURFACE_POPUP: |
Tiago Vignatti | fb2adba | 2013-06-12 15:43:21 -0300 | [diff] [blame] | 2448 | case SHELL_SURFACE_XWAYLAND: |
Philip Withnall | 0f640e2 | 2013-11-25 18:01:31 +0000 | [diff] [blame] | 2449 | default: |
Pekka Paalanen | 9826223 | 2011-12-01 10:42:22 +0200 | [diff] [blame] | 2450 | break; |
| 2451 | } |
| 2452 | |
| 2453 | surface->type = SHELL_SURFACE_NONE; |
| 2454 | return 0; |
| 2455 | } |
| 2456 | |
Kristian Høgsberg | 4cca349 | 2011-01-18 07:53:49 -0500 | [diff] [blame] | 2457 | static void |
Kristian Høgsberg | 7f366e7 | 2012-04-27 17:20:01 -0400 | [diff] [blame] | 2458 | set_surface_type(struct shell_surface *shsurf) |
| 2459 | { |
Kristian Høgsberg | 8150b19 | 2012-06-27 10:22:58 -0400 | [diff] [blame] | 2460 | struct weston_surface *pes = shsurf->parent; |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 2461 | struct weston_view *pev = get_default_view(pes); |
Kristian Høgsberg | 7f366e7 | 2012-04-27 17:20:01 -0400 | [diff] [blame] | 2462 | |
Philip Withnall | becb77e | 2013-11-25 18:01:30 +0000 | [diff] [blame] | 2463 | reset_surface_type(shsurf); |
Kristian Høgsberg | 7f366e7 | 2012-04-27 17:20:01 -0400 | [diff] [blame] | 2464 | |
| 2465 | shsurf->type = shsurf->next_type; |
| 2466 | shsurf->next_type = SHELL_SURFACE_NONE; |
| 2467 | |
| 2468 | switch (shsurf->type) { |
| 2469 | case SHELL_SURFACE_TOPLEVEL: |
| 2470 | break; |
| 2471 | case SHELL_SURFACE_TRANSIENT: |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 2472 | if (pev) |
| 2473 | weston_view_set_position(shsurf->view, |
| 2474 | pev->geometry.x + shsurf->transient.x, |
| 2475 | pev->geometry.y + shsurf->transient.y); |
Kristian Høgsberg | 7f366e7 | 2012-04-27 17:20:01 -0400 | [diff] [blame] | 2476 | break; |
| 2477 | |
| 2478 | case SHELL_SURFACE_MAXIMIZED: |
Kristian Høgsberg | 7f366e7 | 2012-04-27 17:20:01 -0400 | [diff] [blame] | 2479 | case SHELL_SURFACE_FULLSCREEN: |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 2480 | shsurf->saved_x = shsurf->view->geometry.x; |
| 2481 | shsurf->saved_y = shsurf->view->geometry.y; |
Kristian Høgsberg | 7f366e7 | 2012-04-27 17:20:01 -0400 | [diff] [blame] | 2482 | shsurf->saved_position_valid = true; |
| 2483 | |
| 2484 | if (!wl_list_empty(&shsurf->rotation.transform.link)) { |
| 2485 | wl_list_remove(&shsurf->rotation.transform.link); |
| 2486 | wl_list_init(&shsurf->rotation.transform.link); |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 2487 | weston_view_geometry_dirty(shsurf->view); |
Kristian Høgsberg | 7f366e7 | 2012-04-27 17:20:01 -0400 | [diff] [blame] | 2488 | shsurf->saved_rotation_valid = true; |
| 2489 | } |
| 2490 | break; |
| 2491 | |
Tiago Vignatti | fb2adba | 2013-06-12 15:43:21 -0300 | [diff] [blame] | 2492 | case SHELL_SURFACE_XWAYLAND: |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 2493 | weston_view_set_position(shsurf->view, shsurf->transient.x, |
| 2494 | shsurf->transient.y); |
Tiago Vignatti | fb2adba | 2013-06-12 15:43:21 -0300 | [diff] [blame] | 2495 | break; |
| 2496 | |
Philip Withnall | 0f640e2 | 2013-11-25 18:01:31 +0000 | [diff] [blame] | 2497 | case SHELL_SURFACE_POPUP: |
| 2498 | case SHELL_SURFACE_NONE: |
Kristian Høgsberg | 7f366e7 | 2012-04-27 17:20:01 -0400 | [diff] [blame] | 2499 | default: |
| 2500 | break; |
| 2501 | } |
Philip Withnall | e1d75ae | 2013-11-25 18:01:41 +0000 | [diff] [blame] | 2502 | |
| 2503 | /* Update the surface’s layer. */ |
| 2504 | shell_surface_update_layer(shsurf); |
Kristian Høgsberg | 7f366e7 | 2012-04-27 17:20:01 -0400 | [diff] [blame] | 2505 | } |
| 2506 | |
Tiago Vignatti | be14326 | 2012-04-16 17:31:41 +0300 | [diff] [blame] | 2507 | static struct desktop_shell * |
Juan Zhao | 96879df | 2012-02-07 08:45:41 +0800 | [diff] [blame] | 2508 | shell_surface_get_shell(struct shell_surface *shsurf) |
Pekka Paalanen | af0e34c | 2011-12-02 10:59:17 +0200 | [diff] [blame] | 2509 | { |
Kristian Høgsberg | 02e79dc | 2012-04-12 09:55:26 -0400 | [diff] [blame] | 2510 | return shsurf->shell; |
Juan Zhao | 96879df | 2012-02-07 08:45:41 +0800 | [diff] [blame] | 2511 | } |
| 2512 | |
Alex Wu | 2185843 | 2012-04-01 20:13:08 +0800 | [diff] [blame] | 2513 | static void |
Giulio Camuffo | 184df50 | 2013-02-21 11:29:21 +0100 | [diff] [blame] | 2514 | black_surface_configure(struct weston_surface *es, int32_t sx, int32_t sy, int32_t width, int32_t height); |
Alex Wu | 2185843 | 2012-04-01 20:13:08 +0800 | [diff] [blame] | 2515 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 2516 | static struct weston_view * |
Alex Wu | 4539b08 | 2012-03-01 12:57:46 +0800 | [diff] [blame] | 2517 | create_black_surface(struct weston_compositor *ec, |
Alex Wu | 2185843 | 2012-04-01 20:13:08 +0800 | [diff] [blame] | 2518 | struct weston_surface *fs_surface, |
John Kåre Alsaker | 490d02a | 2012-09-30 02:57:21 +0200 | [diff] [blame] | 2519 | float x, float y, int w, int h) |
Alex Wu | 4539b08 | 2012-03-01 12:57:46 +0800 | [diff] [blame] | 2520 | { |
| 2521 | struct weston_surface *surface = NULL; |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 2522 | struct weston_view *view; |
Alex Wu | 4539b08 | 2012-03-01 12:57:46 +0800 | [diff] [blame] | 2523 | |
| 2524 | surface = weston_surface_create(ec); |
| 2525 | if (surface == NULL) { |
Martin Minarik | 6d11836 | 2012-06-07 18:01:59 +0200 | [diff] [blame] | 2526 | weston_log("no memory\n"); |
Alex Wu | 4539b08 | 2012-03-01 12:57:46 +0800 | [diff] [blame] | 2527 | return NULL; |
| 2528 | } |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 2529 | view = weston_view_create(surface); |
| 2530 | if (surface == NULL) { |
| 2531 | weston_log("no memory\n"); |
| 2532 | weston_surface_destroy(surface); |
| 2533 | return NULL; |
| 2534 | } |
Alex Wu | 4539b08 | 2012-03-01 12:57:46 +0800 | [diff] [blame] | 2535 | |
Alex Wu | 2185843 | 2012-04-01 20:13:08 +0800 | [diff] [blame] | 2536 | surface->configure = black_surface_configure; |
Giulio Camuffo | 7fe01b1 | 2013-03-28 18:02:42 +0100 | [diff] [blame] | 2537 | surface->configure_private = fs_surface; |
Alex Wu | 4539b08 | 2012-03-01 12:57:46 +0800 | [diff] [blame] | 2538 | weston_surface_set_color(surface, 0.0, 0.0, 0.0, 1); |
Pekka Paalanen | 71f6f3b | 2012-10-10 12:49:26 +0300 | [diff] [blame] | 2539 | pixman_region32_fini(&surface->opaque); |
Kristian Høgsberg | 61f00f5 | 2012-08-03 16:31:36 -0400 | [diff] [blame] | 2540 | pixman_region32_init_rect(&surface->opaque, 0, 0, w, h); |
Jonas Ådahl | 33619a4 | 2013-01-15 21:25:55 +0100 | [diff] [blame] | 2541 | pixman_region32_fini(&surface->input); |
| 2542 | pixman_region32_init_rect(&surface->input, 0, 0, w, h); |
Xiong Zhang | becf5a3 | 2013-11-29 11:18:14 +0800 | [diff] [blame] | 2543 | surface->width = w; |
| 2544 | surface->height = h; |
Kristian Høgsberg | 61f00f5 | 2012-08-03 16:31:36 -0400 | [diff] [blame] | 2545 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 2546 | weston_view_configure(view, x, y, w, h); |
| 2547 | |
| 2548 | return view; |
Alex Wu | 4539b08 | 2012-03-01 12:57:46 +0800 | [diff] [blame] | 2549 | } |
| 2550 | |
Philip Withnall | ed8f1a9 | 2013-11-25 18:01:43 +0000 | [diff] [blame] | 2551 | static void |
| 2552 | shell_ensure_fullscreen_black_view(struct shell_surface *shsurf) |
| 2553 | { |
| 2554 | struct weston_output *output = shsurf->fullscreen_output; |
| 2555 | |
| 2556 | assert(shsurf->type == SHELL_SURFACE_FULLSCREEN); |
| 2557 | |
| 2558 | if (!shsurf->fullscreen.black_view) |
| 2559 | shsurf->fullscreen.black_view = |
| 2560 | create_black_surface(shsurf->surface->compositor, |
| 2561 | shsurf->surface, |
| 2562 | output->x, output->y, |
| 2563 | output->width, |
| 2564 | output->height); |
| 2565 | |
| 2566 | weston_view_geometry_dirty(shsurf->fullscreen.black_view); |
| 2567 | wl_list_remove(&shsurf->fullscreen.black_view->layer_link); |
| 2568 | wl_list_insert(&shsurf->view->layer_link, |
| 2569 | &shsurf->fullscreen.black_view->layer_link); |
| 2570 | weston_view_geometry_dirty(shsurf->fullscreen.black_view); |
| 2571 | weston_surface_damage(shsurf->surface); |
| 2572 | } |
| 2573 | |
Alex Wu | 4539b08 | 2012-03-01 12:57:46 +0800 | [diff] [blame] | 2574 | /* Create black surface and append it to the associated fullscreen surface. |
| 2575 | * Handle size dismatch and positioning according to the method. */ |
| 2576 | static void |
| 2577 | shell_configure_fullscreen(struct shell_surface *shsurf) |
| 2578 | { |
| 2579 | struct weston_output *output = shsurf->fullscreen_output; |
| 2580 | struct weston_surface *surface = shsurf->surface; |
| 2581 | struct weston_matrix *matrix; |
Kristian Høgsberg | 240dfeb | 2012-07-12 12:32:31 -0400 | [diff] [blame] | 2582 | float scale, output_aspect, surface_aspect, x, y; |
Giulio Camuffo | b836664 | 2013-04-25 13:57:46 +0300 | [diff] [blame] | 2583 | int32_t surf_x, surf_y, surf_width, surf_height; |
Alex Wu | 4539b08 | 2012-03-01 12:57:46 +0800 | [diff] [blame] | 2584 | |
Alexander Larsson | f82b6ca | 2013-05-28 16:23:39 +0200 | [diff] [blame] | 2585 | if (shsurf->fullscreen.type != WL_SHELL_SURFACE_FULLSCREEN_METHOD_DRIVER) |
| 2586 | restore_output_mode(output); |
| 2587 | |
Philip Withnall | ed8f1a9 | 2013-11-25 18:01:43 +0000 | [diff] [blame] | 2588 | shell_ensure_fullscreen_black_view(shsurf); |
Alex Wu | 4539b08 | 2012-03-01 12:57:46 +0800 | [diff] [blame] | 2589 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 2590 | surface_subsurfaces_boundingbox(shsurf->surface, &surf_x, &surf_y, |
Giulio Camuffo | b836664 | 2013-04-25 13:57:46 +0300 | [diff] [blame] | 2591 | &surf_width, &surf_height); |
| 2592 | |
Alex Wu | 4539b08 | 2012-03-01 12:57:46 +0800 | [diff] [blame] | 2593 | switch (shsurf->fullscreen.type) { |
| 2594 | case WL_SHELL_SURFACE_FULLSCREEN_METHOD_DEFAULT: |
Pekka Paalanen | de685b8 | 2012-12-04 15:58:12 +0200 | [diff] [blame] | 2595 | if (surface->buffer_ref.buffer) |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 2596 | center_on_output(shsurf->view, shsurf->fullscreen_output); |
Alex Wu | 4539b08 | 2012-03-01 12:57:46 +0800 | [diff] [blame] | 2597 | break; |
| 2598 | case WL_SHELL_SURFACE_FULLSCREEN_METHOD_SCALE: |
Rob Bradford | 9f3dd15 | 2013-02-12 11:53:47 +0000 | [diff] [blame] | 2599 | /* 1:1 mapping between surface and output dimensions */ |
Giulio Camuffo | b836664 | 2013-04-25 13:57:46 +0300 | [diff] [blame] | 2600 | if (output->width == surf_width && |
| 2601 | output->height == surf_height) { |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 2602 | weston_view_set_position(shsurf->view, |
| 2603 | output->x - surf_x, |
| 2604 | output->y - surf_y); |
Rob Bradford | 9f3dd15 | 2013-02-12 11:53:47 +0000 | [diff] [blame] | 2605 | break; |
| 2606 | } |
| 2607 | |
Alex Wu | 4539b08 | 2012-03-01 12:57:46 +0800 | [diff] [blame] | 2608 | matrix = &shsurf->fullscreen.transform.matrix; |
| 2609 | weston_matrix_init(matrix); |
Kristian Høgsberg | 240dfeb | 2012-07-12 12:32:31 -0400 | [diff] [blame] | 2610 | |
Scott Moreau | 1bad5db | 2012-08-18 01:04:05 -0600 | [diff] [blame] | 2611 | output_aspect = (float) output->width / |
| 2612 | (float) output->height; |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 2613 | /* XXX: Use surf_width and surf_height here? */ |
| 2614 | surface_aspect = (float) surface->width / |
| 2615 | (float) surface->height; |
Kristian Høgsberg | 240dfeb | 2012-07-12 12:32:31 -0400 | [diff] [blame] | 2616 | if (output_aspect < surface_aspect) |
Scott Moreau | 1bad5db | 2012-08-18 01:04:05 -0600 | [diff] [blame] | 2617 | scale = (float) output->width / |
Giulio Camuffo | b836664 | 2013-04-25 13:57:46 +0300 | [diff] [blame] | 2618 | (float) surf_width; |
Kristian Høgsberg | 240dfeb | 2012-07-12 12:32:31 -0400 | [diff] [blame] | 2619 | else |
Scott Moreau | 1bad5db | 2012-08-18 01:04:05 -0600 | [diff] [blame] | 2620 | scale = (float) output->height / |
Giulio Camuffo | b836664 | 2013-04-25 13:57:46 +0300 | [diff] [blame] | 2621 | (float) surf_height; |
Kristian Høgsberg | 240dfeb | 2012-07-12 12:32:31 -0400 | [diff] [blame] | 2622 | |
Alex Wu | 4539b08 | 2012-03-01 12:57:46 +0800 | [diff] [blame] | 2623 | weston_matrix_scale(matrix, scale, scale, 1); |
| 2624 | wl_list_remove(&shsurf->fullscreen.transform.link); |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 2625 | wl_list_insert(&shsurf->view->geometry.transformation_list, |
Alex Wu | 4539b08 | 2012-03-01 12:57:46 +0800 | [diff] [blame] | 2626 | &shsurf->fullscreen.transform.link); |
Giulio Camuffo | b836664 | 2013-04-25 13:57:46 +0300 | [diff] [blame] | 2627 | x = output->x + (output->width - surf_width * scale) / 2 - surf_x; |
| 2628 | y = output->y + (output->height - surf_height * scale) / 2 - surf_y; |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 2629 | weston_view_set_position(shsurf->view, x, y); |
Kristian Høgsberg | 240dfeb | 2012-07-12 12:32:31 -0400 | [diff] [blame] | 2630 | |
Alex Wu | 4539b08 | 2012-03-01 12:57:46 +0800 | [diff] [blame] | 2631 | break; |
| 2632 | case WL_SHELL_SURFACE_FULLSCREEN_METHOD_DRIVER: |
Alex Wu | bd3354b | 2012-04-17 17:20:49 +0800 | [diff] [blame] | 2633 | if (shell_surface_is_top_fullscreen(shsurf)) { |
Quentin Glidic | c0d79ce | 2013-01-29 14:16:13 +0100 | [diff] [blame] | 2634 | struct weston_mode mode = {0, |
Pekka Paalanen | 1fd9c0f | 2013-11-26 18:19:41 +0100 | [diff] [blame] | 2635 | surf_width * surface->buffer_viewport.scale, |
| 2636 | surf_height * surface->buffer_viewport.scale, |
Alex Wu | bd3354b | 2012-04-17 17:20:49 +0800 | [diff] [blame] | 2637 | shsurf->fullscreen.framerate}; |
| 2638 | |
Pekka Paalanen | 1fd9c0f | 2013-11-26 18:19:41 +0100 | [diff] [blame] | 2639 | if (weston_output_switch_mode(output, &mode, surface->buffer_viewport.scale, |
Hardening | 57388e4 | 2013-09-18 23:56:36 +0200 | [diff] [blame] | 2640 | WESTON_MODE_SWITCH_SET_TEMPORARY) == 0) { |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 2641 | weston_view_set_position(shsurf->view, |
| 2642 | output->x - surf_x, |
| 2643 | output->y - surf_y); |
| 2644 | weston_view_configure(shsurf->fullscreen.black_view, |
| 2645 | output->x - surf_x, |
| 2646 | output->y - surf_y, |
| 2647 | output->width, |
| 2648 | output->height); |
Alex Wu | bd3354b | 2012-04-17 17:20:49 +0800 | [diff] [blame] | 2649 | break; |
Alexander Larsson | d622ed3 | 2013-05-28 16:23:40 +0200 | [diff] [blame] | 2650 | } else { |
Alexander Larsson | f82b6ca | 2013-05-28 16:23:39 +0200 | [diff] [blame] | 2651 | restore_output_mode(output); |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 2652 | center_on_output(shsurf->view, output); |
Alexander Larsson | d622ed3 | 2013-05-28 16:23:40 +0200 | [diff] [blame] | 2653 | } |
Alex Wu | bd3354b | 2012-04-17 17:20:49 +0800 | [diff] [blame] | 2654 | } |
Alex Wu | 4539b08 | 2012-03-01 12:57:46 +0800 | [diff] [blame] | 2655 | break; |
| 2656 | case WL_SHELL_SURFACE_FULLSCREEN_METHOD_FILL: |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 2657 | center_on_output(shsurf->view, output); |
Alex Wu | 4539b08 | 2012-03-01 12:57:46 +0800 | [diff] [blame] | 2658 | break; |
| 2659 | default: |
| 2660 | break; |
| 2661 | } |
| 2662 | } |
| 2663 | |
Alex Wu | 4539b08 | 2012-03-01 12:57:46 +0800 | [diff] [blame] | 2664 | static void |
| 2665 | shell_map_fullscreen(struct shell_surface *shsurf) |
| 2666 | { |
Alex Wu | bd3354b | 2012-04-17 17:20:49 +0800 | [diff] [blame] | 2667 | shell_configure_fullscreen(shsurf); |
Alex Wu | 4539b08 | 2012-03-01 12:57:46 +0800 | [diff] [blame] | 2668 | } |
| 2669 | |
Kristian Høgsberg | 7a5c979 | 2011-06-18 06:12:54 -0400 | [diff] [blame] | 2670 | static void |
Tiago Vignatti | fb2adba | 2013-06-12 15:43:21 -0300 | [diff] [blame] | 2671 | set_xwayland(struct shell_surface *shsurf, int x, int y, uint32_t flags) |
| 2672 | { |
| 2673 | /* XXX: using the same fields for transient type */ |
| 2674 | shsurf->transient.x = x; |
| 2675 | shsurf->transient.y = y; |
| 2676 | shsurf->transient.flags = flags; |
Philip Withnall | dc4332f | 2013-11-25 18:01:38 +0000 | [diff] [blame] | 2677 | |
| 2678 | shell_surface_set_parent(shsurf, NULL); |
| 2679 | |
Tiago Vignatti | fb2adba | 2013-06-12 15:43:21 -0300 | [diff] [blame] | 2680 | shsurf->next_type = SHELL_SURFACE_XWAYLAND; |
| 2681 | } |
| 2682 | |
Kristian Høgsberg | 02bbabb | 2013-05-06 22:15:05 -0400 | [diff] [blame] | 2683 | static const struct weston_pointer_grab_interface popup_grab_interface; |
Giulio Camuffo | 5085a75 | 2013-03-25 21:42:45 +0100 | [diff] [blame] | 2684 | |
| 2685 | static void |
| 2686 | destroy_shell_seat(struct wl_listener *listener, void *data) |
| 2687 | { |
| 2688 | struct shell_seat *shseat = |
| 2689 | container_of(listener, |
| 2690 | struct shell_seat, seat_destroy_listener); |
| 2691 | struct shell_surface *shsurf, *prev = NULL; |
| 2692 | |
| 2693 | if (shseat->popup_grab.grab.interface == &popup_grab_interface) { |
Kristian Høgsberg | 02bbabb | 2013-05-06 22:15:05 -0400 | [diff] [blame] | 2694 | weston_pointer_end_grab(shseat->popup_grab.grab.pointer); |
Giulio Camuffo | 5085a75 | 2013-03-25 21:42:45 +0100 | [diff] [blame] | 2695 | shseat->popup_grab.client = NULL; |
| 2696 | |
| 2697 | wl_list_for_each(shsurf, &shseat->popup_grab.surfaces_list, popup.grab_link) { |
| 2698 | shsurf->popup.shseat = NULL; |
| 2699 | if (prev) { |
| 2700 | wl_list_init(&prev->popup.grab_link); |
| 2701 | } |
| 2702 | prev = shsurf; |
| 2703 | } |
| 2704 | wl_list_init(&prev->popup.grab_link); |
| 2705 | } |
| 2706 | |
| 2707 | wl_list_remove(&shseat->seat_destroy_listener.link); |
| 2708 | free(shseat); |
| 2709 | } |
| 2710 | |
| 2711 | static struct shell_seat * |
| 2712 | create_shell_seat(struct weston_seat *seat) |
| 2713 | { |
| 2714 | struct shell_seat *shseat; |
| 2715 | |
| 2716 | shseat = calloc(1, sizeof *shseat); |
| 2717 | if (!shseat) { |
| 2718 | weston_log("no memory to allocate shell seat\n"); |
| 2719 | return NULL; |
| 2720 | } |
| 2721 | |
| 2722 | shseat->seat = seat; |
| 2723 | wl_list_init(&shseat->popup_grab.surfaces_list); |
| 2724 | |
| 2725 | shseat->seat_destroy_listener.notify = destroy_shell_seat; |
| 2726 | wl_signal_add(&seat->destroy_signal, |
| 2727 | &shseat->seat_destroy_listener); |
| 2728 | |
| 2729 | return shseat; |
| 2730 | } |
| 2731 | |
| 2732 | static struct shell_seat * |
| 2733 | get_shell_seat(struct weston_seat *seat) |
| 2734 | { |
| 2735 | struct wl_listener *listener; |
| 2736 | |
| 2737 | listener = wl_signal_get(&seat->destroy_signal, destroy_shell_seat); |
| 2738 | if (listener == NULL) |
| 2739 | return create_shell_seat(seat); |
| 2740 | |
| 2741 | return container_of(listener, |
| 2742 | struct shell_seat, seat_destroy_listener); |
| 2743 | } |
| 2744 | |
Kristian Høgsberg | b810eb5 | 2013-02-12 20:07:05 -0500 | [diff] [blame] | 2745 | static void |
Kristian Høgsberg | 6848c25 | 2013-05-08 22:02:59 -0400 | [diff] [blame] | 2746 | popup_grab_focus(struct weston_pointer_grab *grab) |
Kristian Høgsberg | b3cca0a | 2012-01-04 22:19:14 -0500 | [diff] [blame] | 2747 | { |
Kristian Høgsberg | 02bbabb | 2013-05-06 22:15:05 -0400 | [diff] [blame] | 2748 | struct weston_pointer *pointer = grab->pointer; |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 2749 | struct weston_view *view; |
Giulio Camuffo | 5085a75 | 2013-03-25 21:42:45 +0100 | [diff] [blame] | 2750 | struct shell_seat *shseat = |
| 2751 | container_of(grab, struct shell_seat, popup_grab.grab); |
| 2752 | struct wl_client *client = shseat->popup_grab.client; |
Kristian Høgsberg | 6848c25 | 2013-05-08 22:02:59 -0400 | [diff] [blame] | 2753 | wl_fixed_t sx, sy; |
| 2754 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 2755 | view = weston_compositor_pick_view(pointer->seat->compositor, |
| 2756 | pointer->x, pointer->y, |
| 2757 | &sx, &sy); |
Kristian Høgsberg | b3cca0a | 2012-01-04 22:19:14 -0500 | [diff] [blame] | 2758 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 2759 | if (view && view->surface->resource && |
| 2760 | wl_resource_get_client(view->surface->resource) == client) { |
| 2761 | weston_pointer_set_focus(pointer, view, sx, sy); |
Kristian Høgsberg | b3cca0a | 2012-01-04 22:19:14 -0500 | [diff] [blame] | 2762 | } else { |
Kristian Høgsberg | 02bbabb | 2013-05-06 22:15:05 -0400 | [diff] [blame] | 2763 | weston_pointer_set_focus(pointer, NULL, |
| 2764 | wl_fixed_from_int(0), |
| 2765 | wl_fixed_from_int(0)); |
Kristian Høgsberg | b3cca0a | 2012-01-04 22:19:14 -0500 | [diff] [blame] | 2766 | } |
| 2767 | } |
| 2768 | |
| 2769 | static void |
Giulio Camuffo | 1959ab8 | 2013-11-14 23:42:52 +0100 | [diff] [blame] | 2770 | popup_grab_motion(struct weston_pointer_grab *grab, uint32_t time, |
| 2771 | wl_fixed_t x, wl_fixed_t y) |
Kristian Høgsberg | b3cca0a | 2012-01-04 22:19:14 -0500 | [diff] [blame] | 2772 | { |
Kristian Høgsberg | be6403e | 2013-05-08 21:03:21 -0400 | [diff] [blame] | 2773 | struct weston_pointer *pointer = grab->pointer; |
Neil Roberts | 96d790e | 2013-09-19 17:32:00 +0100 | [diff] [blame] | 2774 | struct wl_resource *resource; |
Kristian Høgsberg | be6403e | 2013-05-08 21:03:21 -0400 | [diff] [blame] | 2775 | wl_fixed_t sx, sy; |
Kristian Høgsberg | b3cca0a | 2012-01-04 22:19:14 -0500 | [diff] [blame] | 2776 | |
Giulio Camuffo | 1959ab8 | 2013-11-14 23:42:52 +0100 | [diff] [blame] | 2777 | weston_pointer_move(pointer, x, y); |
| 2778 | |
Neil Roberts | 96d790e | 2013-09-19 17:32:00 +0100 | [diff] [blame] | 2779 | wl_resource_for_each(resource, &pointer->focus_resource_list) { |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 2780 | weston_view_from_global_fixed(pointer->focus, |
| 2781 | pointer->x, pointer->y, |
| 2782 | &sx, &sy); |
Neil Roberts | 96d790e | 2013-09-19 17:32:00 +0100 | [diff] [blame] | 2783 | wl_pointer_send_motion(resource, time, sx, sy); |
Kristian Høgsberg | be6403e | 2013-05-08 21:03:21 -0400 | [diff] [blame] | 2784 | } |
Kristian Høgsberg | b3cca0a | 2012-01-04 22:19:14 -0500 | [diff] [blame] | 2785 | } |
| 2786 | |
| 2787 | static void |
Kristian Høgsberg | 02bbabb | 2013-05-06 22:15:05 -0400 | [diff] [blame] | 2788 | popup_grab_button(struct weston_pointer_grab *grab, |
Daniel Stone | 4dbadb1 | 2012-05-30 16:31:51 +0100 | [diff] [blame] | 2789 | uint32_t time, uint32_t button, uint32_t state_w) |
Kristian Høgsberg | b3cca0a | 2012-01-04 22:19:14 -0500 | [diff] [blame] | 2790 | { |
| 2791 | struct wl_resource *resource; |
Giulio Camuffo | 5085a75 | 2013-03-25 21:42:45 +0100 | [diff] [blame] | 2792 | struct shell_seat *shseat = |
| 2793 | container_of(grab, struct shell_seat, popup_grab.grab); |
Rob Bradford | 880ebc7 | 2013-07-22 17:31:38 +0100 | [diff] [blame] | 2794 | struct wl_display *display = shseat->seat->compositor->wl_display; |
Daniel Stone | 4dbadb1 | 2012-05-30 16:31:51 +0100 | [diff] [blame] | 2795 | enum wl_pointer_button_state state = state_w; |
Kristian Høgsberg | eae5de7 | 2012-04-11 22:42:15 -0400 | [diff] [blame] | 2796 | uint32_t serial; |
Neil Roberts | 96d790e | 2013-09-19 17:32:00 +0100 | [diff] [blame] | 2797 | struct wl_list *resource_list; |
Kristian Høgsberg | b3cca0a | 2012-01-04 22:19:14 -0500 | [diff] [blame] | 2798 | |
Neil Roberts | 96d790e | 2013-09-19 17:32:00 +0100 | [diff] [blame] | 2799 | resource_list = &grab->pointer->focus_resource_list; |
| 2800 | if (!wl_list_empty(resource_list)) { |
Kristian Høgsberg | eae5de7 | 2012-04-11 22:42:15 -0400 | [diff] [blame] | 2801 | serial = wl_display_get_serial(display); |
Neil Roberts | 96d790e | 2013-09-19 17:32:00 +0100 | [diff] [blame] | 2802 | wl_resource_for_each(resource, resource_list) { |
| 2803 | wl_pointer_send_button(resource, serial, |
| 2804 | time, button, state); |
| 2805 | } |
Daniel Stone | 4dbadb1 | 2012-05-30 16:31:51 +0100 | [diff] [blame] | 2806 | } else if (state == WL_POINTER_BUTTON_STATE_RELEASED && |
Giulio Camuffo | 5085a75 | 2013-03-25 21:42:45 +0100 | [diff] [blame] | 2807 | (shseat->popup_grab.initial_up || |
Kristian Høgsberg | e314875 | 2013-05-06 23:19:49 -0400 | [diff] [blame] | 2808 | time - shseat->seat->pointer->grab_time > 500)) { |
Kristian Høgsberg | 57e0907 | 2012-10-30 14:07:27 -0400 | [diff] [blame] | 2809 | popup_grab_end(grab->pointer); |
Kristian Høgsberg | b3cca0a | 2012-01-04 22:19:14 -0500 | [diff] [blame] | 2810 | } |
| 2811 | |
Daniel Stone | 4dbadb1 | 2012-05-30 16:31:51 +0100 | [diff] [blame] | 2812 | if (state == WL_POINTER_BUTTON_STATE_RELEASED) |
Giulio Camuffo | 5085a75 | 2013-03-25 21:42:45 +0100 | [diff] [blame] | 2813 | shseat->popup_grab.initial_up = 1; |
Kristian Høgsberg | b3cca0a | 2012-01-04 22:19:14 -0500 | [diff] [blame] | 2814 | } |
| 2815 | |
Jonas Ådahl | 1ea343e | 2013-10-25 23:18:05 +0200 | [diff] [blame] | 2816 | static void |
| 2817 | popup_grab_cancel(struct weston_pointer_grab *grab) |
| 2818 | { |
| 2819 | popup_grab_end(grab->pointer); |
| 2820 | } |
| 2821 | |
Kristian Høgsberg | 02bbabb | 2013-05-06 22:15:05 -0400 | [diff] [blame] | 2822 | static const struct weston_pointer_grab_interface popup_grab_interface = { |
Kristian Høgsberg | b3cca0a | 2012-01-04 22:19:14 -0500 | [diff] [blame] | 2823 | popup_grab_focus, |
| 2824 | popup_grab_motion, |
| 2825 | popup_grab_button, |
Jonas Ådahl | 1ea343e | 2013-10-25 23:18:05 +0200 | [diff] [blame] | 2826 | popup_grab_cancel, |
Kristian Høgsberg | b3cca0a | 2012-01-04 22:19:14 -0500 | [diff] [blame] | 2827 | }; |
| 2828 | |
| 2829 | static void |
Kristian Høgsberg | 02bbabb | 2013-05-06 22:15:05 -0400 | [diff] [blame] | 2830 | popup_grab_end(struct weston_pointer *pointer) |
Kristian Høgsberg | 57e0907 | 2012-10-30 14:07:27 -0400 | [diff] [blame] | 2831 | { |
Kristian Høgsberg | 02bbabb | 2013-05-06 22:15:05 -0400 | [diff] [blame] | 2832 | struct weston_pointer_grab *grab = pointer->grab; |
Giulio Camuffo | 5085a75 | 2013-03-25 21:42:45 +0100 | [diff] [blame] | 2833 | struct shell_seat *shseat = |
| 2834 | container_of(grab, struct shell_seat, popup_grab.grab); |
| 2835 | struct shell_surface *shsurf; |
| 2836 | struct shell_surface *prev = NULL; |
Kristian Høgsberg | 57e0907 | 2012-10-30 14:07:27 -0400 | [diff] [blame] | 2837 | |
| 2838 | if (pointer->grab->interface == &popup_grab_interface) { |
Kristian Høgsberg | 02bbabb | 2013-05-06 22:15:05 -0400 | [diff] [blame] | 2839 | weston_pointer_end_grab(grab->pointer); |
Giulio Camuffo | 5085a75 | 2013-03-25 21:42:45 +0100 | [diff] [blame] | 2840 | shseat->popup_grab.client = NULL; |
Philipp Brüschweiler | 63e7be6 | 2013-04-15 21:09:54 +0200 | [diff] [blame] | 2841 | shseat->popup_grab.grab.interface = NULL; |
| 2842 | assert(!wl_list_empty(&shseat->popup_grab.surfaces_list)); |
Giulio Camuffo | 5085a75 | 2013-03-25 21:42:45 +0100 | [diff] [blame] | 2843 | /* Send the popup_done event to all the popups open */ |
| 2844 | 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] | 2845 | wl_shell_surface_send_popup_done(shsurf->resource); |
Giulio Camuffo | 5085a75 | 2013-03-25 21:42:45 +0100 | [diff] [blame] | 2846 | shsurf->popup.shseat = NULL; |
| 2847 | if (prev) { |
| 2848 | wl_list_init(&prev->popup.grab_link); |
| 2849 | } |
| 2850 | prev = shsurf; |
| 2851 | } |
| 2852 | wl_list_init(&prev->popup.grab_link); |
| 2853 | wl_list_init(&shseat->popup_grab.surfaces_list); |
| 2854 | } |
| 2855 | } |
| 2856 | |
| 2857 | static void |
| 2858 | add_popup_grab(struct shell_surface *shsurf, struct shell_seat *shseat) |
| 2859 | { |
Kristian Høgsberg | e314875 | 2013-05-06 23:19:49 -0400 | [diff] [blame] | 2860 | struct weston_seat *seat = shseat->seat; |
Giulio Camuffo | 5085a75 | 2013-03-25 21:42:45 +0100 | [diff] [blame] | 2861 | |
| 2862 | if (wl_list_empty(&shseat->popup_grab.surfaces_list)) { |
Jason Ekstrand | 651f00e | 2013-06-14 10:07:54 -0500 | [diff] [blame] | 2863 | shseat->popup_grab.client = wl_resource_get_client(shsurf->resource); |
Giulio Camuffo | 5085a75 | 2013-03-25 21:42:45 +0100 | [diff] [blame] | 2864 | shseat->popup_grab.grab.interface = &popup_grab_interface; |
Giulio Camuffo | 1b4b61a | 2013-03-27 18:05:26 +0100 | [diff] [blame] | 2865 | /* We must make sure here that this popup was opened after |
| 2866 | * a mouse press, and not just by moving around with other |
| 2867 | * popups already open. */ |
Kristian Høgsberg | e314875 | 2013-05-06 23:19:49 -0400 | [diff] [blame] | 2868 | if (shseat->seat->pointer->button_count > 0) |
Giulio Camuffo | 1b4b61a | 2013-03-27 18:05:26 +0100 | [diff] [blame] | 2869 | shseat->popup_grab.initial_up = 0; |
Giulio Camuffo | 5085a75 | 2013-03-25 21:42:45 +0100 | [diff] [blame] | 2870 | |
Rob Bradford | dfe3105 | 2013-06-26 19:49:11 +0100 | [diff] [blame] | 2871 | 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] | 2872 | weston_pointer_start_grab(seat->pointer, &shseat->popup_grab.grab); |
Rob Bradford | dfe3105 | 2013-06-26 19:49:11 +0100 | [diff] [blame] | 2873 | } else { |
| 2874 | wl_list_insert(&shseat->popup_grab.surfaces_list, &shsurf->popup.grab_link); |
Giulio Camuffo | 5085a75 | 2013-03-25 21:42:45 +0100 | [diff] [blame] | 2875 | } |
Giulio Camuffo | 5085a75 | 2013-03-25 21:42:45 +0100 | [diff] [blame] | 2876 | } |
| 2877 | |
| 2878 | static void |
| 2879 | remove_popup_grab(struct shell_surface *shsurf) |
| 2880 | { |
| 2881 | struct shell_seat *shseat = shsurf->popup.shseat; |
| 2882 | |
| 2883 | wl_list_remove(&shsurf->popup.grab_link); |
| 2884 | wl_list_init(&shsurf->popup.grab_link); |
| 2885 | if (wl_list_empty(&shseat->popup_grab.surfaces_list)) { |
Kristian Høgsberg | 02bbabb | 2013-05-06 22:15:05 -0400 | [diff] [blame] | 2886 | weston_pointer_end_grab(shseat->popup_grab.grab.pointer); |
Philipp Brüschweiler | 63e7be6 | 2013-04-15 21:09:54 +0200 | [diff] [blame] | 2887 | shseat->popup_grab.grab.interface = NULL; |
Kristian Høgsberg | 57e0907 | 2012-10-30 14:07:27 -0400 | [diff] [blame] | 2888 | } |
| 2889 | } |
| 2890 | |
| 2891 | static void |
Kristian Høgsberg | 3730f36 | 2012-04-13 12:40:07 -0400 | [diff] [blame] | 2892 | shell_map_popup(struct shell_surface *shsurf) |
Kristian Høgsberg | b3cca0a | 2012-01-04 22:19:14 -0500 | [diff] [blame] | 2893 | { |
Giulio Camuffo | 5085a75 | 2013-03-25 21:42:45 +0100 | [diff] [blame] | 2894 | struct shell_seat *shseat = shsurf->popup.shseat; |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 2895 | struct weston_view *parent_view = get_default_view(shsurf->parent); |
Kristian Høgsberg | b3cca0a | 2012-01-04 22:19:14 -0500 | [diff] [blame] | 2896 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 2897 | shsurf->surface->output = parent_view->output; |
| 2898 | shsurf->view->output = parent_view->output; |
Kristian Høgsberg | b3cca0a | 2012-01-04 22:19:14 -0500 | [diff] [blame] | 2899 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 2900 | weston_view_set_transform_parent(shsurf->view, parent_view); |
| 2901 | weston_view_set_position(shsurf->view, shsurf->popup.x, shsurf->popup.y); |
| 2902 | weston_view_update_transform(shsurf->view); |
Kristian Høgsberg | b3cca0a | 2012-01-04 22:19:14 -0500 | [diff] [blame] | 2903 | |
Kristian Høgsberg | e314875 | 2013-05-06 23:19:49 -0400 | [diff] [blame] | 2904 | if (shseat->seat->pointer->grab_serial == shsurf->popup.serial) { |
Giulio Camuffo | 5085a75 | 2013-03-25 21:42:45 +0100 | [diff] [blame] | 2905 | add_popup_grab(shsurf, shseat); |
Kristian Høgsberg | 3730f36 | 2012-04-13 12:40:07 -0400 | [diff] [blame] | 2906 | } else { |
Jason Ekstrand | 651f00e | 2013-06-14 10:07:54 -0500 | [diff] [blame] | 2907 | wl_shell_surface_send_popup_done(shsurf->resource); |
Giulio Camuffo | 5085a75 | 2013-03-25 21:42:45 +0100 | [diff] [blame] | 2908 | shseat->popup_grab.client = NULL; |
Kristian Høgsberg | 3730f36 | 2012-04-13 12:40:07 -0400 | [diff] [blame] | 2909 | } |
Kristian Høgsberg | b3cca0a | 2012-01-04 22:19:14 -0500 | [diff] [blame] | 2910 | } |
| 2911 | |
Pekka Paalanen | 9d1613e | 2011-11-25 12:09:16 +0200 | [diff] [blame] | 2912 | static const struct wl_shell_surface_interface shell_surface_implementation = { |
Scott Moreau | ff1db4a | 2012-04-17 19:06:18 -0600 | [diff] [blame] | 2913 | shell_surface_pong, |
Pekka Paalanen | 9d1613e | 2011-11-25 12:09:16 +0200 | [diff] [blame] | 2914 | shell_surface_move, |
| 2915 | shell_surface_resize, |
| 2916 | shell_surface_set_toplevel, |
| 2917 | shell_surface_set_transient, |
Kristian Høgsberg | b3cca0a | 2012-01-04 22:19:14 -0500 | [diff] [blame] | 2918 | shell_surface_set_fullscreen, |
Juan Zhao | 96879df | 2012-02-07 08:45:41 +0800 | [diff] [blame] | 2919 | shell_surface_set_popup, |
Kristian Høgsberg | e7afd91 | 2012-05-02 09:47:44 -0400 | [diff] [blame] | 2920 | shell_surface_set_maximized, |
| 2921 | shell_surface_set_title, |
| 2922 | shell_surface_set_class |
Pekka Paalanen | 9d1613e | 2011-11-25 12:09:16 +0200 | [diff] [blame] | 2923 | }; |
| 2924 | |
| 2925 | static void |
Tiago Vignatti | bc052c9 | 2012-04-19 16:18:18 +0300 | [diff] [blame] | 2926 | destroy_shell_surface(struct shell_surface *shsurf) |
Pekka Paalanen | 9d1613e | 2011-11-25 12:09:16 +0200 | [diff] [blame] | 2927 | { |
Jason Ekstrand | 651f00e | 2013-06-14 10:07:54 -0500 | [diff] [blame] | 2928 | wl_signal_emit(&shsurf->destroy_signal, shsurf); |
| 2929 | |
Giulio Camuffo | 5085a75 | 2013-03-25 21:42:45 +0100 | [diff] [blame] | 2930 | if (!wl_list_empty(&shsurf->popup.grab_link)) { |
| 2931 | remove_popup_grab(shsurf); |
| 2932 | } |
Kristian Høgsberg | b3cca0a | 2012-01-04 22:19:14 -0500 | [diff] [blame] | 2933 | |
Alex Wu | bd3354b | 2012-04-17 17:20:49 +0800 | [diff] [blame] | 2934 | if (shsurf->fullscreen.type == WL_SHELL_SURFACE_FULLSCREEN_METHOD_DRIVER && |
Alexander Larsson | f82b6ca | 2013-05-28 16:23:39 +0200 | [diff] [blame] | 2935 | shell_surface_is_top_fullscreen(shsurf)) |
| 2936 | restore_output_mode (shsurf->fullscreen_output); |
Pekka Paalanen | 9d1613e | 2011-11-25 12:09:16 +0200 | [diff] [blame] | 2937 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 2938 | if (shsurf->fullscreen.black_view) |
| 2939 | weston_surface_destroy(shsurf->fullscreen.black_view->surface); |
Alex Wu | aa08e2d | 2012-03-05 11:01:40 +0800 | [diff] [blame] | 2940 | |
Alex Wu | bd3354b | 2012-04-17 17:20:49 +0800 | [diff] [blame] | 2941 | /* As destroy_resource() use wl_list_for_each_safe(), |
| 2942 | * we can always remove the listener. |
| 2943 | */ |
| 2944 | wl_list_remove(&shsurf->surface_destroy_listener.link); |
| 2945 | shsurf->surface->configure = NULL; |
Scott Moreau | 9521d5e | 2012-04-19 13:06:17 -0600 | [diff] [blame] | 2946 | ping_timer_destroy(shsurf); |
Scott Moreau | 976a050 | 2013-03-07 10:15:17 -0700 | [diff] [blame] | 2947 | free(shsurf->title); |
Alex Wu | bd3354b | 2012-04-17 17:20:49 +0800 | [diff] [blame] | 2948 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 2949 | weston_view_destroy(shsurf->view); |
| 2950 | |
Philip Withnall | 648a4dd | 2013-11-25 18:01:44 +0000 | [diff] [blame^] | 2951 | wl_list_remove(&shsurf->children_link); |
| 2952 | |
Pekka Paalanen | 9d1613e | 2011-11-25 12:09:16 +0200 | [diff] [blame] | 2953 | wl_list_remove(&shsurf->link); |
| 2954 | free(shsurf); |
| 2955 | } |
| 2956 | |
| 2957 | static void |
Tiago Vignatti | bc052c9 | 2012-04-19 16:18:18 +0300 | [diff] [blame] | 2958 | shell_destroy_shell_surface(struct wl_resource *resource) |
| 2959 | { |
Jason Ekstrand | 651f00e | 2013-06-14 10:07:54 -0500 | [diff] [blame] | 2960 | struct shell_surface *shsurf = wl_resource_get_user_data(resource); |
Tiago Vignatti | bc052c9 | 2012-04-19 16:18:18 +0300 | [diff] [blame] | 2961 | |
| 2962 | destroy_shell_surface(shsurf); |
| 2963 | } |
| 2964 | |
| 2965 | static void |
Kristian Høgsberg | 27e3052 | 2012-04-11 23:18:23 -0400 | [diff] [blame] | 2966 | shell_handle_surface_destroy(struct wl_listener *listener, void *data) |
Pekka Paalanen | 9d1613e | 2011-11-25 12:09:16 +0200 | [diff] [blame] | 2967 | { |
| 2968 | struct shell_surface *shsurf = container_of(listener, |
| 2969 | struct shell_surface, |
| 2970 | surface_destroy_listener); |
| 2971 | |
Jason Ekstrand | 651f00e | 2013-06-14 10:07:54 -0500 | [diff] [blame] | 2972 | if (shsurf->resource) |
| 2973 | wl_resource_destroy(shsurf->resource); |
| 2974 | else |
Tiago Vignatti | bc052c9 | 2012-04-19 16:18:18 +0300 | [diff] [blame] | 2975 | destroy_shell_surface(shsurf); |
Pekka Paalanen | 9d1613e | 2011-11-25 12:09:16 +0200 | [diff] [blame] | 2976 | } |
| 2977 | |
Kristian Høgsberg | d813445 | 2012-06-21 12:49:02 -0400 | [diff] [blame] | 2978 | static void |
Giulio Camuffo | 184df50 | 2013-02-21 11:29:21 +0100 | [diff] [blame] | 2979 | shell_surface_configure(struct weston_surface *, int32_t, int32_t, int32_t, int32_t); |
Kristian Høgsberg | d813445 | 2012-06-21 12:49:02 -0400 | [diff] [blame] | 2980 | |
Pekka Paalanen | ec2b32f | 2011-11-28 15:12:34 +0200 | [diff] [blame] | 2981 | static struct shell_surface * |
Kristian Høgsberg | 8334bc1 | 2012-01-03 10:29:47 -0500 | [diff] [blame] | 2982 | get_shell_surface(struct weston_surface *surface) |
Pekka Paalanen | ec2b32f | 2011-11-28 15:12:34 +0200 | [diff] [blame] | 2983 | { |
Kristian Høgsberg | d813445 | 2012-06-21 12:49:02 -0400 | [diff] [blame] | 2984 | if (surface->configure == shell_surface_configure) |
Giulio Camuffo | 7fe01b1 | 2013-03-28 18:02:42 +0100 | [diff] [blame] | 2985 | return surface->configure_private; |
Kristian Høgsberg | d813445 | 2012-06-21 12:49:02 -0400 | [diff] [blame] | 2986 | else |
| 2987 | return NULL; |
Pekka Paalanen | ec2b32f | 2011-11-28 15:12:34 +0200 | [diff] [blame] | 2988 | } |
| 2989 | |
Kristian Høgsberg | 45ba869 | 2012-05-21 14:27:33 -0400 | [diff] [blame] | 2990 | static struct shell_surface * |
Kristian Høgsberg | a61ca06 | 2012-05-22 16:05:52 -0400 | [diff] [blame] | 2991 | create_shell_surface(void *shell, struct weston_surface *surface, |
| 2992 | const struct weston_shell_client *client) |
Pekka Paalanen | 9d1613e | 2011-11-25 12:09:16 +0200 | [diff] [blame] | 2993 | { |
Pekka Paalanen | 9d1613e | 2011-11-25 12:09:16 +0200 | [diff] [blame] | 2994 | struct shell_surface *shsurf; |
| 2995 | |
Ander Conselvan de Oliveira | 093bfa3 | 2012-03-27 17:36:41 +0300 | [diff] [blame] | 2996 | if (surface->configure) { |
Martin Minarik | 6d11836 | 2012-06-07 18:01:59 +0200 | [diff] [blame] | 2997 | weston_log("surface->configure already set\n"); |
Kristian Høgsberg | 45ba869 | 2012-05-21 14:27:33 -0400 | [diff] [blame] | 2998 | return NULL; |
Ander Conselvan de Oliveira | 093bfa3 | 2012-03-27 17:36:41 +0300 | [diff] [blame] | 2999 | } |
| 3000 | |
Pekka Paalanen | 9d1613e | 2011-11-25 12:09:16 +0200 | [diff] [blame] | 3001 | shsurf = calloc(1, sizeof *shsurf); |
| 3002 | if (!shsurf) { |
Martin Minarik | 6d11836 | 2012-06-07 18:01:59 +0200 | [diff] [blame] | 3003 | weston_log("no memory to allocate shell surface\n"); |
Kristian Høgsberg | 45ba869 | 2012-05-21 14:27:33 -0400 | [diff] [blame] | 3004 | return NULL; |
Pekka Paalanen | 9d1613e | 2011-11-25 12:09:16 +0200 | [diff] [blame] | 3005 | } |
| 3006 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 3007 | shsurf->view = weston_view_create(surface); |
| 3008 | if (!shsurf->view) { |
| 3009 | weston_log("no memory to allocate shell surface\n"); |
| 3010 | free(shsurf); |
| 3011 | return NULL; |
| 3012 | } |
| 3013 | |
Ander Conselvan de Oliveira | 093bfa3 | 2012-03-27 17:36:41 +0300 | [diff] [blame] | 3014 | surface->configure = shell_surface_configure; |
Giulio Camuffo | 7fe01b1 | 2013-03-28 18:02:42 +0100 | [diff] [blame] | 3015 | surface->configure_private = shsurf; |
Ander Conselvan de Oliveira | 093bfa3 | 2012-03-27 17:36:41 +0300 | [diff] [blame] | 3016 | |
Tiago Vignatti | bc052c9 | 2012-04-19 16:18:18 +0300 | [diff] [blame] | 3017 | shsurf->shell = (struct desktop_shell *) shell; |
Scott Moreau | ff1db4a | 2012-04-17 19:06:18 -0600 | [diff] [blame] | 3018 | shsurf->unresponsive = 0; |
Alex Wu | 4539b08 | 2012-03-01 12:57:46 +0800 | [diff] [blame] | 3019 | shsurf->saved_position_valid = false; |
Alex Wu | 7bcb8bd | 2012-04-27 09:07:24 +0800 | [diff] [blame] | 3020 | shsurf->saved_rotation_valid = false; |
Pekka Paalanen | 9d1613e | 2011-11-25 12:09:16 +0200 | [diff] [blame] | 3021 | shsurf->surface = surface; |
Alex Wu | 4539b08 | 2012-03-01 12:57:46 +0800 | [diff] [blame] | 3022 | shsurf->fullscreen.type = WL_SHELL_SURFACE_FULLSCREEN_METHOD_DEFAULT; |
| 3023 | shsurf->fullscreen.framerate = 0; |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 3024 | shsurf->fullscreen.black_view = NULL; |
Scott Moreau | ff1db4a | 2012-04-17 19:06:18 -0600 | [diff] [blame] | 3025 | shsurf->ping_timer = NULL; |
Alex Wu | 4539b08 | 2012-03-01 12:57:46 +0800 | [diff] [blame] | 3026 | wl_list_init(&shsurf->fullscreen.transform.link); |
| 3027 | |
Jason Ekstrand | 651f00e | 2013-06-14 10:07:54 -0500 | [diff] [blame] | 3028 | wl_signal_init(&shsurf->destroy_signal); |
Kristian Høgsberg | 27e3052 | 2012-04-11 23:18:23 -0400 | [diff] [blame] | 3029 | shsurf->surface_destroy_listener.notify = shell_handle_surface_destroy; |
Jason Ekstrand | 26ed73c | 2013-06-06 22:34:41 -0500 | [diff] [blame] | 3030 | wl_signal_add(&surface->destroy_signal, |
Kristian Høgsberg | 27e3052 | 2012-04-11 23:18:23 -0400 | [diff] [blame] | 3031 | &shsurf->surface_destroy_listener); |
Pekka Paalanen | 9d1613e | 2011-11-25 12:09:16 +0200 | [diff] [blame] | 3032 | |
| 3033 | /* init link so its safe to always remove it in destroy_shell_surface */ |
| 3034 | wl_list_init(&shsurf->link); |
Giulio Camuffo | 5085a75 | 2013-03-25 21:42:45 +0100 | [diff] [blame] | 3035 | wl_list_init(&shsurf->popup.grab_link); |
Pekka Paalanen | 9d1613e | 2011-11-25 12:09:16 +0200 | [diff] [blame] | 3036 | |
Pekka Paalanen | 460099f | 2012-01-20 16:48:25 +0200 | [diff] [blame] | 3037 | /* empty when not in use */ |
| 3038 | wl_list_init(&shsurf->rotation.transform.link); |
Kristian Høgsberg | 765e27b | 2012-01-27 13:36:13 -0500 | [diff] [blame] | 3039 | weston_matrix_init(&shsurf->rotation.rotation); |
Pekka Paalanen | 460099f | 2012-01-20 16:48:25 +0200 | [diff] [blame] | 3040 | |
Jonas Ådahl | 62fcd04 | 2012-06-13 00:01:23 +0200 | [diff] [blame] | 3041 | wl_list_init(&shsurf->workspace_transform.link); |
| 3042 | |
Philip Withnall | 648a4dd | 2013-11-25 18:01:44 +0000 | [diff] [blame^] | 3043 | wl_list_init(&shsurf->children_link); |
| 3044 | wl_list_init(&shsurf->children_list); |
| 3045 | shsurf->parent = NULL; |
| 3046 | |
Pekka Paalanen | 9826223 | 2011-12-01 10:42:22 +0200 | [diff] [blame] | 3047 | shsurf->type = SHELL_SURFACE_NONE; |
Kristian Høgsberg | 7f366e7 | 2012-04-27 17:20:01 -0400 | [diff] [blame] | 3048 | shsurf->next_type = SHELL_SURFACE_NONE; |
Pekka Paalanen | 9d1613e | 2011-11-25 12:09:16 +0200 | [diff] [blame] | 3049 | |
Kristian Høgsberg | a61ca06 | 2012-05-22 16:05:52 -0400 | [diff] [blame] | 3050 | shsurf->client = client; |
| 3051 | |
Kristian Høgsberg | 45ba869 | 2012-05-21 14:27:33 -0400 | [diff] [blame] | 3052 | return shsurf; |
Tiago Vignatti | bc052c9 | 2012-04-19 16:18:18 +0300 | [diff] [blame] | 3053 | } |
| 3054 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 3055 | static struct weston_view * |
| 3056 | get_primary_view(void *shell, struct shell_surface *shsurf) |
| 3057 | { |
| 3058 | return shsurf->view; |
| 3059 | } |
| 3060 | |
Tiago Vignatti | bc052c9 | 2012-04-19 16:18:18 +0300 | [diff] [blame] | 3061 | static void |
| 3062 | shell_get_shell_surface(struct wl_client *client, |
| 3063 | struct wl_resource *resource, |
| 3064 | uint32_t id, |
| 3065 | struct wl_resource *surface_resource) |
| 3066 | { |
Jason Ekstrand | 0f2ef7e | 2013-06-14 10:07:53 -0500 | [diff] [blame] | 3067 | struct weston_surface *surface = |
| 3068 | wl_resource_get_user_data(surface_resource); |
Jason Ekstrand | 651f00e | 2013-06-14 10:07:54 -0500 | [diff] [blame] | 3069 | struct desktop_shell *shell = wl_resource_get_user_data(resource); |
Tiago Vignatti | bc052c9 | 2012-04-19 16:18:18 +0300 | [diff] [blame] | 3070 | struct shell_surface *shsurf; |
| 3071 | |
| 3072 | if (get_shell_surface(surface)) { |
| 3073 | wl_resource_post_error(surface_resource, |
Kristian Høgsberg | 9540ea6 | 2012-05-21 14:28:57 -0400 | [diff] [blame] | 3074 | WL_DISPLAY_ERROR_INVALID_OBJECT, |
| 3075 | "desktop_shell::get_shell_surface already requested"); |
Tiago Vignatti | bc052c9 | 2012-04-19 16:18:18 +0300 | [diff] [blame] | 3076 | return; |
| 3077 | } |
| 3078 | |
Kristian Høgsberg | a61ca06 | 2012-05-22 16:05:52 -0400 | [diff] [blame] | 3079 | shsurf = create_shell_surface(shell, surface, &shell_client); |
Kristian Høgsberg | 9540ea6 | 2012-05-21 14:28:57 -0400 | [diff] [blame] | 3080 | if (!shsurf) { |
| 3081 | wl_resource_post_error(surface_resource, |
| 3082 | WL_DISPLAY_ERROR_INVALID_OBJECT, |
| 3083 | "surface->configure already set"); |
| 3084 | return; |
| 3085 | } |
Tiago Vignatti | bc052c9 | 2012-04-19 16:18:18 +0300 | [diff] [blame] | 3086 | |
Jason Ekstrand | a85118c | 2013-06-27 20:17:02 -0500 | [diff] [blame] | 3087 | shsurf->resource = |
| 3088 | wl_resource_create(client, |
| 3089 | &wl_shell_surface_interface, 1, id); |
| 3090 | wl_resource_set_implementation(shsurf->resource, |
| 3091 | &shell_surface_implementation, |
| 3092 | shsurf, shell_destroy_shell_surface); |
Pekka Paalanen | 9d1613e | 2011-11-25 12:09:16 +0200 | [diff] [blame] | 3093 | } |
| 3094 | |
| 3095 | static const struct wl_shell_interface shell_implementation = { |
Pekka Paalanen | 4622967 | 2011-11-29 15:49:31 +0200 | [diff] [blame] | 3096 | shell_get_shell_surface |
Kristian Høgsberg | 4cca349 | 2011-01-18 07:53:49 -0500 | [diff] [blame] | 3097 | }; |
| 3098 | |
Kristian Høgsberg | 0793756 | 2011-04-12 17:25:42 -0400 | [diff] [blame] | 3099 | static void |
Ander Conselvan de Oliveira | 859e885 | 2013-02-21 18:35:21 +0200 | [diff] [blame] | 3100 | shell_fade(struct desktop_shell *shell, enum fade_type type); |
| 3101 | |
| 3102 | static int |
| 3103 | screensaver_timeout(void *data) |
| 3104 | { |
| 3105 | struct desktop_shell *shell = data; |
| 3106 | |
| 3107 | shell_fade(shell, FADE_OUT); |
| 3108 | |
| 3109 | return 1; |
| 3110 | } |
| 3111 | |
| 3112 | static void |
Kristian Høgsberg | 8334bc1 | 2012-01-03 10:29:47 -0500 | [diff] [blame] | 3113 | handle_screensaver_sigchld(struct weston_process *proc, int status) |
Pekka Paalanen | 18027e5 | 2011-12-02 16:31:49 +0200 | [diff] [blame] | 3114 | { |
Ander Conselvan de Oliveira | 18639f8 | 2013-02-15 18:44:19 +0200 | [diff] [blame] | 3115 | struct desktop_shell *shell = |
| 3116 | container_of(proc, struct desktop_shell, screensaver.process); |
Ander Conselvan de Oliveira | 18639f8 | 2013-02-15 18:44:19 +0200 | [diff] [blame] | 3117 | |
Pekka Paalanen | 18027e5 | 2011-12-02 16:31:49 +0200 | [diff] [blame] | 3118 | proc->pid = 0; |
Ander Conselvan de Oliveira | 18639f8 | 2013-02-15 18:44:19 +0200 | [diff] [blame] | 3119 | |
| 3120 | if (shell->locked) |
Ander Conselvan de Oliveira | b17537e | 2013-02-22 14:16:18 +0200 | [diff] [blame] | 3121 | weston_compositor_sleep(shell->compositor); |
Pekka Paalanen | 18027e5 | 2011-12-02 16:31:49 +0200 | [diff] [blame] | 3122 | } |
| 3123 | |
| 3124 | static void |
Tiago Vignatti | be14326 | 2012-04-16 17:31:41 +0300 | [diff] [blame] | 3125 | launch_screensaver(struct desktop_shell *shell) |
Pekka Paalanen | 77346a6 | 2011-11-30 16:26:35 +0200 | [diff] [blame] | 3126 | { |
| 3127 | if (shell->screensaver.binding) |
| 3128 | return; |
| 3129 | |
Ander Conselvan de Oliveira | dda9d78 | 2013-02-22 14:16:19 +0200 | [diff] [blame] | 3130 | if (!shell->screensaver.path) { |
| 3131 | weston_compositor_sleep(shell->compositor); |
Pekka Paalanen | e955f1e | 2011-12-07 11:49:52 +0200 | [diff] [blame] | 3132 | return; |
Ander Conselvan de Oliveira | dda9d78 | 2013-02-22 14:16:19 +0200 | [diff] [blame] | 3133 | } |
Pekka Paalanen | e955f1e | 2011-12-07 11:49:52 +0200 | [diff] [blame] | 3134 | |
Kristian Høgsberg | 32bed57 | 2012-03-01 17:11:36 -0500 | [diff] [blame] | 3135 | if (shell->screensaver.process.pid != 0) { |
Martin Minarik | 6d11836 | 2012-06-07 18:01:59 +0200 | [diff] [blame] | 3136 | weston_log("old screensaver still running\n"); |
Kristian Høgsberg | 32bed57 | 2012-03-01 17:11:36 -0500 | [diff] [blame] | 3137 | return; |
| 3138 | } |
| 3139 | |
Kristian Høgsberg | 8334bc1 | 2012-01-03 10:29:47 -0500 | [diff] [blame] | 3140 | weston_client_launch(shell->compositor, |
Pekka Paalanen | 18027e5 | 2011-12-02 16:31:49 +0200 | [diff] [blame] | 3141 | &shell->screensaver.process, |
Pekka Paalanen | e955f1e | 2011-12-07 11:49:52 +0200 | [diff] [blame] | 3142 | shell->screensaver.path, |
Pekka Paalanen | 18027e5 | 2011-12-02 16:31:49 +0200 | [diff] [blame] | 3143 | handle_screensaver_sigchld); |
Pekka Paalanen | 77346a6 | 2011-11-30 16:26:35 +0200 | [diff] [blame] | 3144 | } |
| 3145 | |
| 3146 | static void |
Tiago Vignatti | be14326 | 2012-04-16 17:31:41 +0300 | [diff] [blame] | 3147 | terminate_screensaver(struct desktop_shell *shell) |
Pekka Paalanen | 77346a6 | 2011-11-30 16:26:35 +0200 | [diff] [blame] | 3148 | { |
Pekka Paalanen | 18027e5 | 2011-12-02 16:31:49 +0200 | [diff] [blame] | 3149 | if (shell->screensaver.process.pid == 0) |
| 3150 | return; |
| 3151 | |
| 3152 | kill(shell->screensaver.process.pid, SIGTERM); |
Pekka Paalanen | 77346a6 | 2011-11-30 16:26:35 +0200 | [diff] [blame] | 3153 | } |
| 3154 | |
| 3155 | static void |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 3156 | configure_static_view(struct weston_view *ev, struct weston_layer *layer, int32_t width, int32_t height) |
Kristian Høgsberg | 962342c | 2012-06-26 16:29:50 -0400 | [diff] [blame] | 3157 | { |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 3158 | struct weston_view *v, *next; |
Kristian Høgsberg | 962342c | 2012-06-26 16:29:50 -0400 | [diff] [blame] | 3159 | |
Giulio Camuffo | 184df50 | 2013-02-21 11:29:21 +0100 | [diff] [blame] | 3160 | if (width == 0) |
| 3161 | return; |
| 3162 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 3163 | wl_list_for_each_safe(v, next, &layer->view_list, layer_link) { |
| 3164 | if (v->output == ev->output && v != ev) { |
| 3165 | weston_view_unmap(v); |
| 3166 | v->surface->configure = NULL; |
Kristian Høgsberg | 962342c | 2012-06-26 16:29:50 -0400 | [diff] [blame] | 3167 | } |
| 3168 | } |
| 3169 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 3170 | weston_view_configure(ev, ev->output->x, ev->output->y, width, height); |
Kristian Høgsberg | 962342c | 2012-06-26 16:29:50 -0400 | [diff] [blame] | 3171 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 3172 | if (wl_list_empty(&ev->layer_link)) { |
| 3173 | wl_list_insert(&layer->view_list, &ev->layer_link); |
| 3174 | weston_compositor_schedule_repaint(ev->surface->compositor); |
Kristian Høgsberg | 962342c | 2012-06-26 16:29:50 -0400 | [diff] [blame] | 3175 | } |
| 3176 | } |
| 3177 | |
| 3178 | static void |
Giulio Camuffo | 184df50 | 2013-02-21 11:29:21 +0100 | [diff] [blame] | 3179 | background_configure(struct weston_surface *es, int32_t sx, int32_t sy, int32_t width, int32_t height) |
Kristian Høgsberg | af7b1ff | 2012-06-26 21:19:23 -0400 | [diff] [blame] | 3180 | { |
Giulio Camuffo | 7fe01b1 | 2013-03-28 18:02:42 +0100 | [diff] [blame] | 3181 | struct desktop_shell *shell = es->configure_private; |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 3182 | struct weston_view *view; |
Kristian Høgsberg | af7b1ff | 2012-06-26 21:19:23 -0400 | [diff] [blame] | 3183 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 3184 | view = container_of(es->views.next, struct weston_view, surface_link); |
| 3185 | |
| 3186 | configure_static_view(view, &shell->background_layer, width, height); |
Kristian Høgsberg | af7b1ff | 2012-06-26 21:19:23 -0400 | [diff] [blame] | 3187 | } |
| 3188 | |
| 3189 | static void |
Kristian Høgsberg | 7584062 | 2011-09-06 13:48:16 -0400 | [diff] [blame] | 3190 | desktop_shell_set_background(struct wl_client *client, |
| 3191 | struct wl_resource *resource, |
Benjamin Franzke | d0f79ab | 2011-11-22 12:43:52 +0100 | [diff] [blame] | 3192 | struct wl_resource *output_resource, |
Kristian Høgsberg | 7584062 | 2011-09-06 13:48:16 -0400 | [diff] [blame] | 3193 | struct wl_resource *surface_resource) |
| 3194 | { |
Jason Ekstrand | 651f00e | 2013-06-14 10:07:54 -0500 | [diff] [blame] | 3195 | struct desktop_shell *shell = wl_resource_get_user_data(resource); |
Jason Ekstrand | 0f2ef7e | 2013-06-14 10:07:53 -0500 | [diff] [blame] | 3196 | struct weston_surface *surface = |
| 3197 | wl_resource_get_user_data(surface_resource); |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 3198 | struct weston_view *view, *next; |
Kristian Høgsberg | 7584062 | 2011-09-06 13:48:16 -0400 | [diff] [blame] | 3199 | |
Kristian Høgsberg | 962342c | 2012-06-26 16:29:50 -0400 | [diff] [blame] | 3200 | if (surface->configure) { |
| 3201 | wl_resource_post_error(surface_resource, |
| 3202 | WL_DISPLAY_ERROR_INVALID_OBJECT, |
| 3203 | "surface role already assigned"); |
| 3204 | return; |
| 3205 | } |
Benjamin Franzke | d0f79ab | 2011-11-22 12:43:52 +0100 | [diff] [blame] | 3206 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 3207 | wl_list_for_each_safe(view, next, &surface->views, surface_link) |
| 3208 | weston_view_destroy(view); |
| 3209 | view = weston_view_create(surface); |
| 3210 | |
Kristian Høgsberg | 962342c | 2012-06-26 16:29:50 -0400 | [diff] [blame] | 3211 | surface->configure = background_configure; |
Giulio Camuffo | 7fe01b1 | 2013-03-28 18:02:42 +0100 | [diff] [blame] | 3212 | surface->configure_private = shell; |
Jason Ekstrand | a0d2dde | 2013-06-14 10:08:01 -0500 | [diff] [blame] | 3213 | surface->output = wl_resource_get_user_data(output_resource); |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 3214 | view->output = surface->output; |
Kristian Høgsberg | eae5de7 | 2012-04-11 22:42:15 -0400 | [diff] [blame] | 3215 | desktop_shell_send_configure(resource, 0, |
Kristian Høgsberg | 0b5cd0c | 2012-03-04 21:57:37 -0500 | [diff] [blame] | 3216 | surface_resource, |
Scott Moreau | 1bad5db | 2012-08-18 01:04:05 -0600 | [diff] [blame] | 3217 | surface->output->width, |
| 3218 | surface->output->height); |
Kristian Høgsberg | 7584062 | 2011-09-06 13:48:16 -0400 | [diff] [blame] | 3219 | } |
| 3220 | |
| 3221 | static void |
Giulio Camuffo | 184df50 | 2013-02-21 11:29:21 +0100 | [diff] [blame] | 3222 | panel_configure(struct weston_surface *es, int32_t sx, int32_t sy, int32_t width, int32_t height) |
Kristian Høgsberg | af7b1ff | 2012-06-26 21:19:23 -0400 | [diff] [blame] | 3223 | { |
Giulio Camuffo | 7fe01b1 | 2013-03-28 18:02:42 +0100 | [diff] [blame] | 3224 | struct desktop_shell *shell = es->configure_private; |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 3225 | struct weston_view *view; |
Kristian Høgsberg | af7b1ff | 2012-06-26 21:19:23 -0400 | [diff] [blame] | 3226 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 3227 | view = container_of(es->views.next, struct weston_view, surface_link); |
| 3228 | |
| 3229 | configure_static_view(view, &shell->panel_layer, width, height); |
Kristian Høgsberg | af7b1ff | 2012-06-26 21:19:23 -0400 | [diff] [blame] | 3230 | } |
| 3231 | |
| 3232 | static void |
Kristian Høgsberg | 7584062 | 2011-09-06 13:48:16 -0400 | [diff] [blame] | 3233 | desktop_shell_set_panel(struct wl_client *client, |
| 3234 | struct wl_resource *resource, |
Benjamin Franzke | d0f79ab | 2011-11-22 12:43:52 +0100 | [diff] [blame] | 3235 | struct wl_resource *output_resource, |
Kristian Høgsberg | 7584062 | 2011-09-06 13:48:16 -0400 | [diff] [blame] | 3236 | struct wl_resource *surface_resource) |
| 3237 | { |
Jason Ekstrand | 651f00e | 2013-06-14 10:07:54 -0500 | [diff] [blame] | 3238 | struct desktop_shell *shell = wl_resource_get_user_data(resource); |
Jason Ekstrand | 0f2ef7e | 2013-06-14 10:07:53 -0500 | [diff] [blame] | 3239 | struct weston_surface *surface = |
| 3240 | wl_resource_get_user_data(surface_resource); |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 3241 | struct weston_view *view, *next; |
Kristian Høgsberg | 7584062 | 2011-09-06 13:48:16 -0400 | [diff] [blame] | 3242 | |
Kristian Høgsberg | af7b1ff | 2012-06-26 21:19:23 -0400 | [diff] [blame] | 3243 | if (surface->configure) { |
| 3244 | wl_resource_post_error(surface_resource, |
| 3245 | WL_DISPLAY_ERROR_INVALID_OBJECT, |
| 3246 | "surface role already assigned"); |
| 3247 | return; |
| 3248 | } |
Benjamin Franzke | d0f79ab | 2011-11-22 12:43:52 +0100 | [diff] [blame] | 3249 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 3250 | wl_list_for_each_safe(view, next, &surface->views, surface_link) |
| 3251 | weston_view_destroy(view); |
| 3252 | view = weston_view_create(surface); |
| 3253 | |
Kristian Høgsberg | af7b1ff | 2012-06-26 21:19:23 -0400 | [diff] [blame] | 3254 | surface->configure = panel_configure; |
Giulio Camuffo | 7fe01b1 | 2013-03-28 18:02:42 +0100 | [diff] [blame] | 3255 | surface->configure_private = shell; |
Jason Ekstrand | a0d2dde | 2013-06-14 10:08:01 -0500 | [diff] [blame] | 3256 | surface->output = wl_resource_get_user_data(output_resource); |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 3257 | view->output = surface->output; |
Kristian Høgsberg | eae5de7 | 2012-04-11 22:42:15 -0400 | [diff] [blame] | 3258 | desktop_shell_send_configure(resource, 0, |
Kristian Høgsberg | af7b1ff | 2012-06-26 21:19:23 -0400 | [diff] [blame] | 3259 | surface_resource, |
Scott Moreau | 1bad5db | 2012-08-18 01:04:05 -0600 | [diff] [blame] | 3260 | surface->output->width, |
| 3261 | surface->output->height); |
Kristian Høgsberg | 7584062 | 2011-09-06 13:48:16 -0400 | [diff] [blame] | 3262 | } |
| 3263 | |
Pekka Paalanen | 9ef3e01 | 2011-11-15 13:34:48 +0200 | [diff] [blame] | 3264 | static void |
Giulio Camuffo | 184df50 | 2013-02-21 11:29:21 +0100 | [diff] [blame] | 3265 | lock_surface_configure(struct weston_surface *surface, int32_t sx, int32_t sy, int32_t width, int32_t height) |
Kristian Høgsberg | 730c94d | 2012-06-26 21:44:35 -0400 | [diff] [blame] | 3266 | { |
Giulio Camuffo | 7fe01b1 | 2013-03-28 18:02:42 +0100 | [diff] [blame] | 3267 | struct desktop_shell *shell = surface->configure_private; |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 3268 | struct weston_view *view; |
| 3269 | |
| 3270 | view = container_of(surface->views.next, struct weston_view, surface_link); |
Kristian Høgsberg | 730c94d | 2012-06-26 21:44:35 -0400 | [diff] [blame] | 3271 | |
Giulio Camuffo | 184df50 | 2013-02-21 11:29:21 +0100 | [diff] [blame] | 3272 | if (width == 0) |
| 3273 | return; |
| 3274 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 3275 | surface->width = width; |
| 3276 | surface->height = height; |
| 3277 | view->geometry.width = width; |
| 3278 | view->geometry.height = height; |
| 3279 | center_on_output(view, get_default_output(shell->compositor)); |
Kristian Høgsberg | 730c94d | 2012-06-26 21:44:35 -0400 | [diff] [blame] | 3280 | |
| 3281 | if (!weston_surface_is_mapped(surface)) { |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 3282 | wl_list_insert(&shell->lock_layer.view_list, |
| 3283 | &view->layer_link); |
| 3284 | weston_view_update_transform(view); |
Ander Conselvan de Oliveira | 87524b6 | 2013-02-21 18:35:22 +0200 | [diff] [blame] | 3285 | shell_fade(shell, FADE_IN); |
Kristian Høgsberg | 730c94d | 2012-06-26 21:44:35 -0400 | [diff] [blame] | 3286 | } |
| 3287 | } |
| 3288 | |
| 3289 | static void |
Kristian Høgsberg | 27e3052 | 2012-04-11 23:18:23 -0400 | [diff] [blame] | 3290 | handle_lock_surface_destroy(struct wl_listener *listener, void *data) |
Kristian Høgsberg | 1ec0c31 | 2011-11-15 16:39:55 -0500 | [diff] [blame] | 3291 | { |
Tiago Vignatti | be14326 | 2012-04-16 17:31:41 +0300 | [diff] [blame] | 3292 | struct desktop_shell *shell = |
| 3293 | container_of(listener, struct desktop_shell, lock_surface_listener); |
Kristian Høgsberg | 1ec0c31 | 2011-11-15 16:39:55 -0500 | [diff] [blame] | 3294 | |
Martin Minarik | 6d11836 | 2012-06-07 18:01:59 +0200 | [diff] [blame] | 3295 | weston_log("lock surface gone\n"); |
Kristian Høgsberg | 1ec0c31 | 2011-11-15 16:39:55 -0500 | [diff] [blame] | 3296 | shell->lock_surface = NULL; |
| 3297 | } |
| 3298 | |
| 3299 | static void |
Pekka Paalanen | 9ef3e01 | 2011-11-15 13:34:48 +0200 | [diff] [blame] | 3300 | desktop_shell_set_lock_surface(struct wl_client *client, |
| 3301 | struct wl_resource *resource, |
| 3302 | struct wl_resource *surface_resource) |
| 3303 | { |
Jason Ekstrand | 651f00e | 2013-06-14 10:07:54 -0500 | [diff] [blame] | 3304 | struct desktop_shell *shell = wl_resource_get_user_data(resource); |
Jason Ekstrand | 0f2ef7e | 2013-06-14 10:07:53 -0500 | [diff] [blame] | 3305 | struct weston_surface *surface = |
| 3306 | wl_resource_get_user_data(surface_resource); |
Pekka Paalanen | 9826223 | 2011-12-01 10:42:22 +0200 | [diff] [blame] | 3307 | |
Pekka Paalanen | f0fc70d | 2011-11-15 13:34:54 +0200 | [diff] [blame] | 3308 | shell->prepare_event_sent = false; |
Kristian Høgsberg | af867cc | 2011-11-15 13:34:49 +0200 | [diff] [blame] | 3309 | |
Pekka Paalanen | f0fc70d | 2011-11-15 13:34:54 +0200 | [diff] [blame] | 3310 | if (!shell->locked) |
| 3311 | return; |
| 3312 | |
Pekka Paalanen | 9826223 | 2011-12-01 10:42:22 +0200 | [diff] [blame] | 3313 | shell->lock_surface = surface; |
Pekka Paalanen | f0fc70d | 2011-11-15 13:34:54 +0200 | [diff] [blame] | 3314 | |
Kristian Høgsberg | 27e3052 | 2012-04-11 23:18:23 -0400 | [diff] [blame] | 3315 | shell->lock_surface_listener.notify = handle_lock_surface_destroy; |
Jason Ekstrand | 651f00e | 2013-06-14 10:07:54 -0500 | [diff] [blame] | 3316 | wl_signal_add(&surface->destroy_signal, |
Kristian Høgsberg | 27e3052 | 2012-04-11 23:18:23 -0400 | [diff] [blame] | 3317 | &shell->lock_surface_listener); |
Pekka Paalanen | 57da4a8 | 2011-11-23 16:42:16 +0200 | [diff] [blame] | 3318 | |
Kristian Høgsberg | aa2ee8b | 2013-10-30 15:49:45 -0700 | [diff] [blame] | 3319 | weston_view_create(surface); |
Kristian Høgsberg | 730c94d | 2012-06-26 21:44:35 -0400 | [diff] [blame] | 3320 | surface->configure = lock_surface_configure; |
Giulio Camuffo | 7fe01b1 | 2013-03-28 18:02:42 +0100 | [diff] [blame] | 3321 | surface->configure_private = shell; |
Pekka Paalanen | f0fc70d | 2011-11-15 13:34:54 +0200 | [diff] [blame] | 3322 | } |
| 3323 | |
| 3324 | static void |
Tiago Vignatti | be14326 | 2012-04-16 17:31:41 +0300 | [diff] [blame] | 3325 | resume_desktop(struct desktop_shell *shell) |
Pekka Paalanen | f0fc70d | 2011-11-15 13:34:54 +0200 | [diff] [blame] | 3326 | { |
Kristian Høgsberg | 4476aaf | 2012-06-25 14:03:13 -0400 | [diff] [blame] | 3327 | struct workspace *ws = get_current_workspace(shell); |
Pekka Paalanen | 77346a6 | 2011-11-30 16:26:35 +0200 | [diff] [blame] | 3328 | |
Pekka Paalanen | 77346a6 | 2011-11-30 16:26:35 +0200 | [diff] [blame] | 3329 | terminate_screensaver(shell); |
Pekka Paalanen | f0fc70d | 2011-11-15 13:34:54 +0200 | [diff] [blame] | 3330 | |
Kristian Høgsberg | 3be2ce9 | 2012-02-29 12:42:35 -0500 | [diff] [blame] | 3331 | wl_list_remove(&shell->lock_layer.link); |
| 3332 | wl_list_insert(&shell->compositor->cursor_layer.link, |
| 3333 | &shell->fullscreen_layer.link); |
| 3334 | wl_list_insert(&shell->fullscreen_layer.link, |
| 3335 | &shell->panel_layer.link); |
Philipp Brüschweiler | 711fda8 | 2012-08-09 18:50:43 +0200 | [diff] [blame] | 3336 | if (shell->showing_input_panels) { |
| 3337 | wl_list_insert(&shell->panel_layer.link, |
| 3338 | &shell->input_panel_layer.link); |
| 3339 | wl_list_insert(&shell->input_panel_layer.link, |
| 3340 | &ws->layer.link); |
| 3341 | } else { |
| 3342 | wl_list_insert(&shell->panel_layer.link, &ws->layer.link); |
| 3343 | } |
Pekka Paalanen | f0fc70d | 2011-11-15 13:34:54 +0200 | [diff] [blame] | 3344 | |
Kristian Høgsberg | 2f5faff | 2012-07-31 16:36:34 -0400 | [diff] [blame] | 3345 | restore_focus_state(shell, get_current_workspace(shell)); |
Jonas Ådahl | 0476974 | 2012-06-13 00:01:24 +0200 | [diff] [blame] | 3346 | |
Pekka Paalanen | f0fc70d | 2011-11-15 13:34:54 +0200 | [diff] [blame] | 3347 | shell->locked = false; |
Ander Conselvan de Oliveira | 87524b6 | 2013-02-21 18:35:22 +0200 | [diff] [blame] | 3348 | shell_fade(shell, FADE_IN); |
Pekka Paalanen | fc6d91a | 2012-02-10 15:33:10 +0200 | [diff] [blame] | 3349 | weston_compositor_damage_all(shell->compositor); |
Pekka Paalanen | 9ef3e01 | 2011-11-15 13:34:48 +0200 | [diff] [blame] | 3350 | } |
| 3351 | |
| 3352 | static void |
| 3353 | desktop_shell_unlock(struct wl_client *client, |
| 3354 | struct wl_resource *resource) |
| 3355 | { |
Jason Ekstrand | 651f00e | 2013-06-14 10:07:54 -0500 | [diff] [blame] | 3356 | struct desktop_shell *shell = wl_resource_get_user_data(resource); |
Pekka Paalanen | 9ef3e01 | 2011-11-15 13:34:48 +0200 | [diff] [blame] | 3357 | |
Pekka Paalanen | 9ef3e01 | 2011-11-15 13:34:48 +0200 | [diff] [blame] | 3358 | shell->prepare_event_sent = false; |
Pekka Paalanen | f0fc70d | 2011-11-15 13:34:54 +0200 | [diff] [blame] | 3359 | |
| 3360 | if (shell->locked) |
| 3361 | resume_desktop(shell); |
Pekka Paalanen | 9ef3e01 | 2011-11-15 13:34:48 +0200 | [diff] [blame] | 3362 | } |
| 3363 | |
Kristian Høgsberg | d56bd90 | 2012-06-05 09:58:51 -0400 | [diff] [blame] | 3364 | static void |
Ander Conselvan de Oliveira | b9d2a0f | 2012-06-28 18:08:05 +0300 | [diff] [blame] | 3365 | desktop_shell_set_grab_surface(struct wl_client *client, |
Kristian Høgsberg | d56bd90 | 2012-06-05 09:58:51 -0400 | [diff] [blame] | 3366 | struct wl_resource *resource, |
| 3367 | struct wl_resource *surface_resource) |
| 3368 | { |
Jason Ekstrand | 651f00e | 2013-06-14 10:07:54 -0500 | [diff] [blame] | 3369 | struct desktop_shell *shell = wl_resource_get_user_data(resource); |
Kristian Høgsberg | d56bd90 | 2012-06-05 09:58:51 -0400 | [diff] [blame] | 3370 | |
Jason Ekstrand | 0f2ef7e | 2013-06-14 10:07:53 -0500 | [diff] [blame] | 3371 | shell->grab_surface = wl_resource_get_user_data(surface_resource); |
Kristian Høgsberg | 48588f8 | 2013-10-24 15:51:35 -0700 | [diff] [blame] | 3372 | weston_view_create(shell->grab_surface); |
Kristian Høgsberg | d56bd90 | 2012-06-05 09:58:51 -0400 | [diff] [blame] | 3373 | } |
| 3374 | |
Pekka Paalanen | 79346ab | 2013-05-22 18:03:09 +0300 | [diff] [blame] | 3375 | static void |
| 3376 | desktop_shell_desktop_ready(struct wl_client *client, |
| 3377 | struct wl_resource *resource) |
| 3378 | { |
Jason Ekstrand | 651f00e | 2013-06-14 10:07:54 -0500 | [diff] [blame] | 3379 | struct desktop_shell *shell = wl_resource_get_user_data(resource); |
Pekka Paalanen | 79346ab | 2013-05-22 18:03:09 +0300 | [diff] [blame] | 3380 | |
| 3381 | shell_fade_startup(shell); |
| 3382 | } |
| 3383 | |
Kristian Høgsberg | 7584062 | 2011-09-06 13:48:16 -0400 | [diff] [blame] | 3384 | static const struct desktop_shell_interface desktop_shell_implementation = { |
| 3385 | desktop_shell_set_background, |
Pekka Paalanen | 9ef3e01 | 2011-11-15 13:34:48 +0200 | [diff] [blame] | 3386 | desktop_shell_set_panel, |
| 3387 | desktop_shell_set_lock_surface, |
Kristian Høgsberg | d56bd90 | 2012-06-05 09:58:51 -0400 | [diff] [blame] | 3388 | desktop_shell_unlock, |
Pekka Paalanen | 79346ab | 2013-05-22 18:03:09 +0300 | [diff] [blame] | 3389 | desktop_shell_set_grab_surface, |
| 3390 | desktop_shell_desktop_ready |
Kristian Høgsberg | 7584062 | 2011-09-06 13:48:16 -0400 | [diff] [blame] | 3391 | }; |
| 3392 | |
Pekka Paalanen | 92a0dc4 | 2011-11-28 15:34:13 +0200 | [diff] [blame] | 3393 | static enum shell_surface_type |
Kristian Høgsberg | 8334bc1 | 2012-01-03 10:29:47 -0500 | [diff] [blame] | 3394 | get_shell_surface_type(struct weston_surface *surface) |
Pekka Paalanen | 92a0dc4 | 2011-11-28 15:34:13 +0200 | [diff] [blame] | 3395 | { |
| 3396 | struct shell_surface *shsurf; |
| 3397 | |
| 3398 | shsurf = get_shell_surface(surface); |
| 3399 | if (!shsurf) |
Pekka Paalanen | 9826223 | 2011-12-01 10:42:22 +0200 | [diff] [blame] | 3400 | return SHELL_SURFACE_NONE; |
Pekka Paalanen | 92a0dc4 | 2011-11-28 15:34:13 +0200 | [diff] [blame] | 3401 | return shsurf->type; |
| 3402 | } |
| 3403 | |
Kristian Høgsberg | 7584062 | 2011-09-06 13:48:16 -0400 | [diff] [blame] | 3404 | static void |
Kristian Høgsberg | e314875 | 2013-05-06 23:19:49 -0400 | [diff] [blame] | 3405 | 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] | 3406 | { |
Kristian Høgsberg | 7ab139c | 2013-10-24 16:21:39 -0700 | [diff] [blame] | 3407 | struct weston_surface *focus = seat->pointer->focus->surface; |
Pekka Paalanen | 01388e2 | 2013-04-25 13:57:44 +0300 | [diff] [blame] | 3408 | struct weston_surface *surface; |
Kristian Høgsberg | 938b8fa | 2012-05-18 13:46:27 -0400 | [diff] [blame] | 3409 | struct shell_surface *shsurf; |
Kristian Høgsberg | d2abb83 | 2011-11-23 10:52:40 -0500 | [diff] [blame] | 3410 | |
Pekka Paalanen | 01388e2 | 2013-04-25 13:57:44 +0300 | [diff] [blame] | 3411 | surface = weston_surface_get_main_surface(focus); |
Benjamin Franzke | d0f79ab | 2011-11-22 12:43:52 +0100 | [diff] [blame] | 3412 | if (surface == NULL) |
| 3413 | return; |
Kristian Høgsberg | 0793756 | 2011-04-12 17:25:42 -0400 | [diff] [blame] | 3414 | |
Kristian Høgsberg | 938b8fa | 2012-05-18 13:46:27 -0400 | [diff] [blame] | 3415 | shsurf = get_shell_surface(surface); |
Rafal Mielniczuk | 23c6759 | 2013-03-11 19:26:53 +0100 | [diff] [blame] | 3416 | if (shsurf == NULL || shsurf->type == SHELL_SURFACE_FULLSCREEN || |
| 3417 | shsurf->type == SHELL_SURFACE_MAXIMIZED) |
Kristian Høgsberg | 938b8fa | 2012-05-18 13:46:27 -0400 | [diff] [blame] | 3418 | return; |
| 3419 | |
Kristian Høgsberg | 938b8fa | 2012-05-18 13:46:27 -0400 | [diff] [blame] | 3420 | surface_move(shsurf, (struct weston_seat *) seat); |
Kristian Høgsberg | 0793756 | 2011-04-12 17:25:42 -0400 | [diff] [blame] | 3421 | } |
| 3422 | |
| 3423 | static void |
Neil Roberts | aba0f25 | 2013-10-03 16:43:05 +0100 | [diff] [blame] | 3424 | touch_move_binding(struct weston_seat *seat, uint32_t time, void *data) |
| 3425 | { |
Kristian Høgsberg | 7ab139c | 2013-10-24 16:21:39 -0700 | [diff] [blame] | 3426 | struct weston_surface *focus = seat->touch->focus->surface; |
Neil Roberts | aba0f25 | 2013-10-03 16:43:05 +0100 | [diff] [blame] | 3427 | struct weston_surface *surface; |
| 3428 | struct shell_surface *shsurf; |
| 3429 | |
| 3430 | surface = weston_surface_get_main_surface(focus); |
| 3431 | if (surface == NULL) |
| 3432 | return; |
| 3433 | |
| 3434 | shsurf = get_shell_surface(surface); |
| 3435 | if (shsurf == NULL || shsurf->type == SHELL_SURFACE_FULLSCREEN || |
| 3436 | shsurf->type == SHELL_SURFACE_MAXIMIZED) |
| 3437 | return; |
| 3438 | |
| 3439 | surface_touch_move(shsurf, (struct weston_seat *) seat); |
| 3440 | } |
| 3441 | |
| 3442 | static void |
Kristian Høgsberg | e314875 | 2013-05-06 23:19:49 -0400 | [diff] [blame] | 3443 | 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] | 3444 | { |
Kristian Høgsberg | 7ab139c | 2013-10-24 16:21:39 -0700 | [diff] [blame] | 3445 | struct weston_surface *focus = seat->pointer->focus->surface; |
Pekka Paalanen | 01388e2 | 2013-04-25 13:57:44 +0300 | [diff] [blame] | 3446 | struct weston_surface *surface; |
Kristian Høgsberg | 0793756 | 2011-04-12 17:25:42 -0400 | [diff] [blame] | 3447 | uint32_t edges = 0; |
| 3448 | int32_t x, y; |
Pekka Paalanen | 9d1613e | 2011-11-25 12:09:16 +0200 | [diff] [blame] | 3449 | struct shell_surface *shsurf; |
Kristian Høgsberg | d2abb83 | 2011-11-23 10:52:40 -0500 | [diff] [blame] | 3450 | |
Pekka Paalanen | 01388e2 | 2013-04-25 13:57:44 +0300 | [diff] [blame] | 3451 | surface = weston_surface_get_main_surface(focus); |
Benjamin Franzke | d0f79ab | 2011-11-22 12:43:52 +0100 | [diff] [blame] | 3452 | if (surface == NULL) |
| 3453 | return; |
Pekka Paalanen | 92a0dc4 | 2011-11-28 15:34:13 +0200 | [diff] [blame] | 3454 | |
Pekka Paalanen | 9d1613e | 2011-11-25 12:09:16 +0200 | [diff] [blame] | 3455 | shsurf = get_shell_surface(surface); |
Rafal Mielniczuk | 23c6759 | 2013-03-11 19:26:53 +0100 | [diff] [blame] | 3456 | if (!shsurf || shsurf->type == SHELL_SURFACE_FULLSCREEN || |
| 3457 | shsurf->type == SHELL_SURFACE_MAXIMIZED) |
Pekka Paalanen | 92a0dc4 | 2011-11-28 15:34:13 +0200 | [diff] [blame] | 3458 | return; |
| 3459 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 3460 | weston_view_from_global(shsurf->view, |
| 3461 | wl_fixed_to_int(seat->pointer->grab_x), |
| 3462 | wl_fixed_to_int(seat->pointer->grab_y), |
| 3463 | &x, &y); |
Kristian Høgsberg | 0793756 | 2011-04-12 17:25:42 -0400 | [diff] [blame] | 3464 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 3465 | if (x < shsurf->view->geometry.width / 3) |
Pekka Paalanen | 9d1613e | 2011-11-25 12:09:16 +0200 | [diff] [blame] | 3466 | edges |= WL_SHELL_SURFACE_RESIZE_LEFT; |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 3467 | else if (x < 2 * shsurf->view->geometry.width / 3) |
Kristian Høgsberg | 0793756 | 2011-04-12 17:25:42 -0400 | [diff] [blame] | 3468 | edges |= 0; |
| 3469 | else |
Pekka Paalanen | 9d1613e | 2011-11-25 12:09:16 +0200 | [diff] [blame] | 3470 | edges |= WL_SHELL_SURFACE_RESIZE_RIGHT; |
Kristian Høgsberg | 0793756 | 2011-04-12 17:25:42 -0400 | [diff] [blame] | 3471 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 3472 | if (y < shsurf->view->geometry.height / 3) |
Pekka Paalanen | 9d1613e | 2011-11-25 12:09:16 +0200 | [diff] [blame] | 3473 | edges |= WL_SHELL_SURFACE_RESIZE_TOP; |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 3474 | else if (y < 2 * shsurf->view->geometry.height / 3) |
Kristian Høgsberg | 0793756 | 2011-04-12 17:25:42 -0400 | [diff] [blame] | 3475 | edges |= 0; |
| 3476 | else |
Pekka Paalanen | 9d1613e | 2011-11-25 12:09:16 +0200 | [diff] [blame] | 3477 | edges |= WL_SHELL_SURFACE_RESIZE_BOTTOM; |
Kristian Høgsberg | 0793756 | 2011-04-12 17:25:42 -0400 | [diff] [blame] | 3478 | |
Kristian Høgsberg | c1693f2 | 2012-05-22 16:56:23 -0400 | [diff] [blame] | 3479 | surface_resize(shsurf, (struct weston_seat *) seat, edges); |
Kristian Høgsberg | 02ec0a5 | 2011-04-23 13:04:11 -0400 | [diff] [blame] | 3480 | } |
| 3481 | |
| 3482 | static void |
Kristian Høgsberg | e314875 | 2013-05-06 23:19:49 -0400 | [diff] [blame] | 3483 | 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] | 3484 | wl_fixed_t value, void *data) |
Scott Moreau | a3aa9c9 | 2012-03-22 11:01:03 -0600 | [diff] [blame] | 3485 | { |
Jonas Ådahl | b0b87ba | 2012-09-27 18:40:42 +0200 | [diff] [blame] | 3486 | float step = 0.005; |
Scott Moreau | a3aa9c9 | 2012-03-22 11:01:03 -0600 | [diff] [blame] | 3487 | struct shell_surface *shsurf; |
Kristian Høgsberg | 7ab139c | 2013-10-24 16:21:39 -0700 | [diff] [blame] | 3488 | struct weston_surface *focus = seat->pointer->focus->surface; |
Pekka Paalanen | 01388e2 | 2013-04-25 13:57:44 +0300 | [diff] [blame] | 3489 | struct weston_surface *surface; |
Scott Moreau | a3aa9c9 | 2012-03-22 11:01:03 -0600 | [diff] [blame] | 3490 | |
Pekka Paalanen | 01388e2 | 2013-04-25 13:57:44 +0300 | [diff] [blame] | 3491 | /* XXX: broken for windows containing sub-surfaces */ |
| 3492 | surface = weston_surface_get_main_surface(focus); |
Scott Moreau | a3aa9c9 | 2012-03-22 11:01:03 -0600 | [diff] [blame] | 3493 | if (surface == NULL) |
| 3494 | return; |
| 3495 | |
| 3496 | shsurf = get_shell_surface(surface); |
| 3497 | if (!shsurf) |
| 3498 | return; |
| 3499 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 3500 | shsurf->view->alpha -= wl_fixed_to_double(value) * step; |
Scott Moreau | a3aa9c9 | 2012-03-22 11:01:03 -0600 | [diff] [blame] | 3501 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 3502 | if (shsurf->view->alpha > 1.0) |
| 3503 | shsurf->view->alpha = 1.0; |
| 3504 | if (shsurf->view->alpha < step) |
| 3505 | shsurf->view->alpha = step; |
Scott Moreau | a3aa9c9 | 2012-03-22 11:01:03 -0600 | [diff] [blame] | 3506 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 3507 | weston_view_geometry_dirty(shsurf->view); |
Scott Moreau | a3aa9c9 | 2012-03-22 11:01:03 -0600 | [diff] [blame] | 3508 | weston_surface_damage(surface); |
| 3509 | } |
| 3510 | |
| 3511 | static void |
Kristian Høgsberg | e314875 | 2013-05-06 23:19:49 -0400 | [diff] [blame] | 3512 | 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] | 3513 | wl_fixed_t value) |
Scott Moreau | ccbf29d | 2012-02-22 14:21:41 -0700 | [diff] [blame] | 3514 | { |
Daniel Stone | 37816df | 2012-05-16 18:45:18 +0100 | [diff] [blame] | 3515 | struct weston_seat *ws = (struct weston_seat *) seat; |
| 3516 | struct weston_compositor *compositor = ws->compositor; |
Scott Moreau | ccbf29d | 2012-02-22 14:21:41 -0700 | [diff] [blame] | 3517 | struct weston_output *output; |
Scott Moreau | e660398 | 2012-06-11 13:07:51 -0600 | [diff] [blame] | 3518 | float increment; |
Scott Moreau | ccbf29d | 2012-02-22 14:21:41 -0700 | [diff] [blame] | 3519 | |
| 3520 | wl_list_for_each(output, &compositor->output_list, link) { |
| 3521 | if (pixman_region32_contains_point(&output->region, |
Daniel Stone | 37816df | 2012-05-16 18:45:18 +0100 | [diff] [blame] | 3522 | wl_fixed_to_double(seat->pointer->x), |
| 3523 | wl_fixed_to_double(seat->pointer->y), |
Daniel Stone | 103db7f | 2012-05-08 17:17:55 +0100 | [diff] [blame] | 3524 | NULL)) { |
Daniel Stone | 325fc2d | 2012-05-30 16:31:58 +0100 | [diff] [blame] | 3525 | if (key == KEY_PAGEUP) |
Kristian Høgsberg | 9b68af0 | 2012-05-22 12:55:18 -0400 | [diff] [blame] | 3526 | increment = output->zoom.increment; |
Daniel Stone | 325fc2d | 2012-05-30 16:31:58 +0100 | [diff] [blame] | 3527 | else if (key == KEY_PAGEDOWN) |
Kristian Høgsberg | 9b68af0 | 2012-05-22 12:55:18 -0400 | [diff] [blame] | 3528 | increment = -output->zoom.increment; |
| 3529 | else if (axis == WL_POINTER_AXIS_VERTICAL_SCROLL) |
Jonas Ådahl | b0b87ba | 2012-09-27 18:40:42 +0200 | [diff] [blame] | 3530 | /* For every pixel zoom 20th of a step */ |
Daniel Stone | 0c1e46e | 2012-05-30 16:31:59 +0100 | [diff] [blame] | 3531 | increment = output->zoom.increment * |
Jonas Ådahl | b0b87ba | 2012-09-27 18:40:42 +0200 | [diff] [blame] | 3532 | -wl_fixed_to_double(value) / 20.0; |
Kristian Høgsberg | 9b68af0 | 2012-05-22 12:55:18 -0400 | [diff] [blame] | 3533 | else |
| 3534 | increment = 0; |
| 3535 | |
Kristian Høgsberg | 9b68af0 | 2012-05-22 12:55:18 -0400 | [diff] [blame] | 3536 | output->zoom.level += increment; |
Scott Moreau | c6d7f60 | 2012-02-23 22:28:37 -0700 | [diff] [blame] | 3537 | |
Scott Moreau | e660398 | 2012-06-11 13:07:51 -0600 | [diff] [blame] | 3538 | if (output->zoom.level < 0.0) |
Scott Moreau | 850ca42 | 2012-05-21 15:21:25 -0600 | [diff] [blame] | 3539 | output->zoom.level = 0.0; |
Scott Moreau | e660398 | 2012-06-11 13:07:51 -0600 | [diff] [blame] | 3540 | else if (output->zoom.level > output->zoom.max_level) |
| 3541 | output->zoom.level = output->zoom.max_level; |
Ville Syrjälä | aa628d0 | 2012-11-16 11:48:47 +0200 | [diff] [blame] | 3542 | else if (!output->zoom.active) { |
Giulio Camuffo | 412b024 | 2013-11-14 23:42:51 +0100 | [diff] [blame] | 3543 | weston_output_activate_zoom(output); |
Kristian Høgsberg | 79af73e | 2012-08-03 15:45:23 -0400 | [diff] [blame] | 3544 | } |
Scott Moreau | ccbf29d | 2012-02-22 14:21:41 -0700 | [diff] [blame] | 3545 | |
Scott Moreau | e660398 | 2012-06-11 13:07:51 -0600 | [diff] [blame] | 3546 | output->zoom.spring_z.target = output->zoom.level; |
Scott Moreau | ccbf29d | 2012-02-22 14:21:41 -0700 | [diff] [blame] | 3547 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 3548 | weston_output_update_zoom(output); |
Scott Moreau | ccbf29d | 2012-02-22 14:21:41 -0700 | [diff] [blame] | 3549 | } |
| 3550 | } |
| 3551 | } |
| 3552 | |
Scott Moreau | ccbf29d | 2012-02-22 14:21:41 -0700 | [diff] [blame] | 3553 | static void |
Kristian Høgsberg | e314875 | 2013-05-06 23:19:49 -0400 | [diff] [blame] | 3554 | 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] | 3555 | wl_fixed_t value, void *data) |
Daniel Stone | 325fc2d | 2012-05-30 16:31:58 +0100 | [diff] [blame] | 3556 | { |
| 3557 | do_zoom(seat, time, 0, axis, value); |
| 3558 | } |
| 3559 | |
| 3560 | static void |
Kristian Høgsberg | e314875 | 2013-05-06 23:19:49 -0400 | [diff] [blame] | 3561 | 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] | 3562 | void *data) |
| 3563 | { |
| 3564 | do_zoom(seat, time, key, 0, 0); |
| 3565 | } |
| 3566 | |
| 3567 | static void |
Kristian Høgsberg | e314875 | 2013-05-06 23:19:49 -0400 | [diff] [blame] | 3568 | terminate_binding(struct weston_seat *seat, uint32_t time, uint32_t key, |
Daniel Stone | 325fc2d | 2012-05-30 16:31:58 +0100 | [diff] [blame] | 3569 | void *data) |
Kristian Høgsberg | e1a850e | 2011-12-19 15:18:05 -0500 | [diff] [blame] | 3570 | { |
Kristian Høgsberg | 8334bc1 | 2012-01-03 10:29:47 -0500 | [diff] [blame] | 3571 | struct weston_compositor *compositor = data; |
Kristian Høgsberg | e1a850e | 2011-12-19 15:18:05 -0500 | [diff] [blame] | 3572 | |
Daniel Stone | 325fc2d | 2012-05-30 16:31:58 +0100 | [diff] [blame] | 3573 | wl_display_terminate(compositor->wl_display); |
Kristian Høgsberg | e1a850e | 2011-12-19 15:18:05 -0500 | [diff] [blame] | 3574 | } |
| 3575 | |
| 3576 | static void |
Emilio Pozuelo Monfort | 03251b6 | 2013-11-19 11:37:16 +0100 | [diff] [blame] | 3577 | lower_fullscreen_layer(struct desktop_shell *shell); |
| 3578 | |
| 3579 | struct alt_tab { |
| 3580 | struct desktop_shell *shell; |
| 3581 | struct weston_keyboard_grab grab; |
| 3582 | |
| 3583 | struct wl_list *current; |
| 3584 | |
| 3585 | struct wl_list preview_list; |
| 3586 | }; |
| 3587 | |
| 3588 | struct alt_tab_preview { |
| 3589 | struct alt_tab *alt_tab; |
| 3590 | |
| 3591 | struct weston_view *view; |
| 3592 | struct weston_transform transform; |
| 3593 | |
| 3594 | struct wl_listener listener; |
| 3595 | |
| 3596 | struct wl_list link; |
| 3597 | }; |
| 3598 | |
| 3599 | static void |
| 3600 | alt_tab_next(struct alt_tab *alt_tab) |
| 3601 | { |
| 3602 | alt_tab->current = alt_tab->current->next; |
| 3603 | |
| 3604 | /* Make sure we're not pointing to the list header e.g. after |
| 3605 | * cycling through the whole list. */ |
| 3606 | if (alt_tab->current->next == alt_tab->preview_list.next) |
| 3607 | alt_tab->current = alt_tab->current->next; |
| 3608 | } |
| 3609 | |
| 3610 | static void |
| 3611 | alt_tab_destroy(struct alt_tab *alt_tab) |
| 3612 | { |
| 3613 | struct alt_tab_preview *preview, *next; |
| 3614 | struct weston_keyboard *keyboard = alt_tab->grab.keyboard; |
| 3615 | |
| 3616 | if (alt_tab->current && alt_tab->current != &alt_tab->preview_list) { |
| 3617 | preview = wl_container_of(alt_tab->current, preview, link); |
| 3618 | |
| 3619 | activate(alt_tab->shell, preview->view->surface, |
| 3620 | (struct weston_seat *) keyboard->seat); |
| 3621 | } |
| 3622 | |
| 3623 | wl_list_for_each_safe(preview, next, &alt_tab->preview_list, link) { |
| 3624 | wl_list_remove(&preview->link); |
| 3625 | wl_list_remove(&preview->listener.link); |
| 3626 | weston_view_destroy(preview->view); |
| 3627 | free(preview); |
| 3628 | } |
| 3629 | |
| 3630 | weston_keyboard_end_grab(keyboard); |
| 3631 | if (keyboard->input_method_resource) |
| 3632 | keyboard->grab = &keyboard->input_method_grab; |
| 3633 | |
| 3634 | free(alt_tab); |
| 3635 | } |
| 3636 | |
| 3637 | static void |
| 3638 | alt_tab_handle_surface_destroy(struct wl_listener *listener, void *data) |
| 3639 | { |
| 3640 | struct alt_tab_preview *preview = |
| 3641 | container_of(listener, struct alt_tab_preview, listener); |
| 3642 | struct alt_tab *alt_tab = preview->alt_tab; |
| 3643 | int advance = 0; |
| 3644 | |
| 3645 | /* If the preview that we're removing is the currently selected one, |
| 3646 | * we want to move to the next one. So we move to ->prev and then |
| 3647 | * call _next() after removing the preview. */ |
| 3648 | if (alt_tab->current == &preview->link) { |
| 3649 | alt_tab->current = alt_tab->current->prev; |
| 3650 | advance = 1; |
| 3651 | } |
| 3652 | |
| 3653 | wl_list_remove(&preview->listener.link); |
| 3654 | wl_list_remove(&preview->link); |
| 3655 | |
| 3656 | free(preview); |
| 3657 | |
| 3658 | if (advance) |
| 3659 | alt_tab_next(alt_tab); |
| 3660 | |
| 3661 | /* If the last preview goes away, stop the alt-tab */ |
| 3662 | if (wl_list_empty(alt_tab->current)) |
| 3663 | alt_tab_destroy(alt_tab); |
| 3664 | } |
| 3665 | |
| 3666 | static void |
| 3667 | alt_tab_key(struct weston_keyboard_grab *grab, |
| 3668 | uint32_t time, uint32_t key, uint32_t state_w) |
| 3669 | { |
| 3670 | struct alt_tab *alt_tab = container_of(grab, struct alt_tab, grab); |
| 3671 | enum wl_keyboard_key_state state = state_w; |
| 3672 | |
| 3673 | if (key == KEY_TAB && state == WL_KEYBOARD_KEY_STATE_PRESSED) |
| 3674 | alt_tab_next(alt_tab); |
| 3675 | } |
| 3676 | |
| 3677 | static void |
| 3678 | alt_tab_modifier(struct weston_keyboard_grab *grab, uint32_t serial, |
| 3679 | uint32_t mods_depressed, uint32_t mods_latched, |
| 3680 | uint32_t mods_locked, uint32_t group) |
| 3681 | { |
| 3682 | struct alt_tab *alt_tab = container_of(grab, struct alt_tab, grab); |
| 3683 | struct weston_seat *seat = (struct weston_seat *) grab->keyboard->seat; |
| 3684 | |
| 3685 | if ((seat->modifier_state & MODIFIER_ALT) == 0) |
| 3686 | alt_tab_destroy(alt_tab); |
| 3687 | } |
| 3688 | |
| 3689 | static void |
| 3690 | alt_tab_cancel(struct weston_keyboard_grab *grab) |
| 3691 | { |
| 3692 | struct alt_tab *alt_tab = container_of(grab, struct alt_tab, grab); |
| 3693 | |
| 3694 | alt_tab_destroy(alt_tab); |
| 3695 | } |
| 3696 | |
| 3697 | static const struct weston_keyboard_grab_interface alt_tab_grab = { |
| 3698 | alt_tab_key, |
| 3699 | alt_tab_modifier, |
| 3700 | alt_tab_cancel, |
| 3701 | }; |
| 3702 | |
| 3703 | static int |
| 3704 | view_for_alt_tab(struct weston_view *view) |
| 3705 | { |
| 3706 | if (!get_shell_surface(view->surface)) |
| 3707 | return 0; |
| 3708 | |
| 3709 | if (get_shell_surface_type(view->surface) == SHELL_SURFACE_TRANSIENT) |
| 3710 | return 0; |
| 3711 | |
| 3712 | if (view != get_default_view(view->surface)) |
| 3713 | return 0; |
| 3714 | |
| 3715 | return 1; |
| 3716 | } |
| 3717 | |
| 3718 | static void |
| 3719 | alt_tab_binding(struct weston_seat *seat, uint32_t time, uint32_t key, |
| 3720 | void *data) |
| 3721 | { |
| 3722 | struct alt_tab *alt_tab; |
| 3723 | struct desktop_shell *shell = data; |
| 3724 | struct weston_output *output = get_default_output(shell->compositor); |
| 3725 | struct workspace *ws; |
| 3726 | struct weston_view *view; |
| 3727 | int num_surfaces = 0; |
| 3728 | int x, y, side, margin; |
| 3729 | |
| 3730 | wl_list_for_each(view, &shell->compositor->view_list, link) { |
| 3731 | |
| 3732 | if (view_for_alt_tab(view)) |
| 3733 | num_surfaces++; |
| 3734 | } |
| 3735 | |
| 3736 | if (!num_surfaces) |
| 3737 | return; |
| 3738 | |
| 3739 | alt_tab = malloc(sizeof *alt_tab); |
| 3740 | if (!alt_tab) |
| 3741 | return; |
| 3742 | |
| 3743 | alt_tab->shell = shell; |
| 3744 | wl_list_init(&alt_tab->preview_list); |
| 3745 | alt_tab->current = &alt_tab->preview_list; |
| 3746 | |
| 3747 | restore_all_output_modes(shell->compositor); |
| 3748 | lower_fullscreen_layer(alt_tab->shell); |
| 3749 | |
| 3750 | alt_tab->grab.interface = &alt_tab_grab; |
| 3751 | weston_keyboard_start_grab(seat->keyboard, &alt_tab->grab); |
| 3752 | weston_keyboard_set_focus(seat->keyboard, NULL); |
| 3753 | |
| 3754 | ws = get_current_workspace(shell); |
| 3755 | |
| 3756 | /* FIXME: add some visual candy e.g. prelight the selected view |
| 3757 | * and/or add a black surrounding background à la gnome-shell */ |
| 3758 | |
| 3759 | /* Determine the size for each preview */ |
| 3760 | side = output->width / num_surfaces; |
| 3761 | if (side > 200) |
| 3762 | side = 200; |
| 3763 | margin = side / 4; |
| 3764 | side -= margin; |
| 3765 | |
| 3766 | x = margin; |
| 3767 | y = (output->height - side) / 2; |
| 3768 | |
| 3769 | /* Create a view for each surface */ |
| 3770 | wl_list_for_each(view, &shell->compositor->view_list, link) { |
| 3771 | struct alt_tab_preview *preview; |
| 3772 | struct weston_view *v; |
| 3773 | float scale; |
| 3774 | |
| 3775 | if (!view_for_alt_tab(view)) |
| 3776 | continue; |
| 3777 | |
| 3778 | preview = malloc(sizeof *preview); |
| 3779 | if (!preview) { |
| 3780 | alt_tab_destroy(alt_tab); |
| 3781 | return; |
| 3782 | } |
| 3783 | |
| 3784 | preview->alt_tab = alt_tab; |
| 3785 | |
| 3786 | preview->view = v = weston_view_create(view->surface); |
| 3787 | v->output = view->output; |
Philip Withnall | 83ffd9d | 2013-11-25 18:01:42 +0000 | [diff] [blame] | 3788 | |
| 3789 | wl_list_remove(&v->layer_link); |
| 3790 | wl_list_insert(&ws->layer.view_list, &v->layer_link); |
| 3791 | weston_view_damage_below(v); |
| 3792 | weston_surface_damage(v->surface); |
| 3793 | |
Emilio Pozuelo Monfort | 03251b6 | 2013-11-19 11:37:16 +0100 | [diff] [blame] | 3794 | weston_view_configure(v, x, y, view->geometry.width, view->geometry.height); |
| 3795 | |
| 3796 | preview->listener.notify = alt_tab_handle_surface_destroy; |
| 3797 | wl_signal_add(&v->destroy_signal, &preview->listener); |
| 3798 | |
| 3799 | if (view->geometry.width > view->geometry.height) |
| 3800 | scale = side / (float) view->geometry.width; |
| 3801 | else |
| 3802 | scale = side / (float) view->geometry.height; |
| 3803 | |
| 3804 | wl_list_insert(&v->geometry.transformation_list, |
| 3805 | &preview->transform.link); |
| 3806 | weston_matrix_init(&preview->transform.matrix); |
| 3807 | weston_matrix_scale(&preview->transform.matrix, |
| 3808 | scale, scale, 1.0f); |
| 3809 | |
| 3810 | weston_view_geometry_dirty(v); |
| 3811 | weston_compositor_schedule_repaint(v->surface->compositor); |
| 3812 | |
| 3813 | /* Insert at the end of the list */ |
| 3814 | wl_list_insert(alt_tab->preview_list.prev, &preview->link); |
| 3815 | |
| 3816 | x += side + margin; |
| 3817 | } |
| 3818 | |
| 3819 | /* Start at the second preview so a simple <alt>tab changes window. |
| 3820 | * We set `current' to the first preview and not the second because |
| 3821 | * we're going to receive a key press callback for the initial |
| 3822 | * <alt>tab which will make `current' point to the second element. */ |
| 3823 | alt_tab_next(alt_tab); |
| 3824 | } |
| 3825 | |
| 3826 | static void |
Giulio Camuffo | 1959ab8 | 2013-11-14 23:42:52 +0100 | [diff] [blame] | 3827 | rotate_grab_motion(struct weston_pointer_grab *grab, uint32_t time, |
| 3828 | wl_fixed_t x, wl_fixed_t y) |
Pekka Paalanen | 460099f | 2012-01-20 16:48:25 +0200 | [diff] [blame] | 3829 | { |
| 3830 | struct rotate_grab *rotate = |
Ander Conselvan de Oliveira | fe0444a | 2012-04-04 17:48:05 +0300 | [diff] [blame] | 3831 | container_of(grab, struct rotate_grab, base.grab); |
Kristian Høgsberg | 02bbabb | 2013-05-06 22:15:05 -0400 | [diff] [blame] | 3832 | struct weston_pointer *pointer = grab->pointer; |
Ander Conselvan de Oliveira | fe0444a | 2012-04-04 17:48:05 +0300 | [diff] [blame] | 3833 | struct shell_surface *shsurf = rotate->base.shsurf; |
John Kåre Alsaker | 490d02a | 2012-09-30 02:57:21 +0200 | [diff] [blame] | 3834 | float cx, cy, dx, dy, cposx, cposy, dposx, dposy, r; |
Ander Conselvan de Oliveira | fe0444a | 2012-04-04 17:48:05 +0300 | [diff] [blame] | 3835 | |
Giulio Camuffo | 1959ab8 | 2013-11-14 23:42:52 +0100 | [diff] [blame] | 3836 | weston_pointer_move(pointer, x, y); |
| 3837 | |
Ander Conselvan de Oliveira | fe0444a | 2012-04-04 17:48:05 +0300 | [diff] [blame] | 3838 | if (!shsurf) |
| 3839 | return; |
| 3840 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 3841 | cx = 0.5f * shsurf->view->geometry.width; |
| 3842 | cy = 0.5f * shsurf->view->geometry.height; |
Pekka Paalanen | 460099f | 2012-01-20 16:48:25 +0200 | [diff] [blame] | 3843 | |
Daniel Stone | 37816df | 2012-05-16 18:45:18 +0100 | [diff] [blame] | 3844 | dx = wl_fixed_to_double(pointer->x) - rotate->center.x; |
| 3845 | dy = wl_fixed_to_double(pointer->y) - rotate->center.y; |
Pekka Paalanen | 460099f | 2012-01-20 16:48:25 +0200 | [diff] [blame] | 3846 | r = sqrtf(dx * dx + dy * dy); |
| 3847 | |
Ander Conselvan de Oliveira | fe0444a | 2012-04-04 17:48:05 +0300 | [diff] [blame] | 3848 | wl_list_remove(&shsurf->rotation.transform.link); |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 3849 | weston_view_geometry_dirty(shsurf->view); |
Pekka Paalanen | 460099f | 2012-01-20 16:48:25 +0200 | [diff] [blame] | 3850 | |
| 3851 | if (r > 20.0f) { |
Pekka Paalanen | 460099f | 2012-01-20 16:48:25 +0200 | [diff] [blame] | 3852 | struct weston_matrix *matrix = |
Ander Conselvan de Oliveira | fe0444a | 2012-04-04 17:48:05 +0300 | [diff] [blame] | 3853 | &shsurf->rotation.transform.matrix; |
Pekka Paalanen | 460099f | 2012-01-20 16:48:25 +0200 | [diff] [blame] | 3854 | |
Kristian Høgsberg | 765e27b | 2012-01-27 13:36:13 -0500 | [diff] [blame] | 3855 | weston_matrix_init(&rotate->rotation); |
Vasily Khoruzhick | 1bbf372 | 2013-01-28 22:40:28 +0300 | [diff] [blame] | 3856 | weston_matrix_rotate_xy(&rotate->rotation, dx / r, dy / r); |
Pekka Paalanen | 460099f | 2012-01-20 16:48:25 +0200 | [diff] [blame] | 3857 | |
| 3858 | weston_matrix_init(matrix); |
Pekka Paalanen | 7b3bd3d | 2012-01-30 14:16:34 +0200 | [diff] [blame] | 3859 | weston_matrix_translate(matrix, -cx, -cy, 0.0f); |
Ander Conselvan de Oliveira | fe0444a | 2012-04-04 17:48:05 +0300 | [diff] [blame] | 3860 | weston_matrix_multiply(matrix, &shsurf->rotation.rotation); |
Kristian Høgsberg | 765e27b | 2012-01-27 13:36:13 -0500 | [diff] [blame] | 3861 | weston_matrix_multiply(matrix, &rotate->rotation); |
Pekka Paalanen | 7b3bd3d | 2012-01-30 14:16:34 +0200 | [diff] [blame] | 3862 | weston_matrix_translate(matrix, cx, cy, 0.0f); |
Pekka Paalanen | 460099f | 2012-01-20 16:48:25 +0200 | [diff] [blame] | 3863 | |
Pekka Paalanen | bc0b7e7 | 2012-01-24 09:53:37 +0200 | [diff] [blame] | 3864 | wl_list_insert( |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 3865 | &shsurf->view->geometry.transformation_list, |
Ander Conselvan de Oliveira | fe0444a | 2012-04-04 17:48:05 +0300 | [diff] [blame] | 3866 | &shsurf->rotation.transform.link); |
Pekka Paalanen | 460099f | 2012-01-20 16:48:25 +0200 | [diff] [blame] | 3867 | } else { |
Ander Conselvan de Oliveira | fe0444a | 2012-04-04 17:48:05 +0300 | [diff] [blame] | 3868 | wl_list_init(&shsurf->rotation.transform.link); |
| 3869 | weston_matrix_init(&shsurf->rotation.rotation); |
Kristian Høgsberg | 765e27b | 2012-01-27 13:36:13 -0500 | [diff] [blame] | 3870 | weston_matrix_init(&rotate->rotation); |
Pekka Paalanen | 460099f | 2012-01-20 16:48:25 +0200 | [diff] [blame] | 3871 | } |
Pekka Paalanen | b45ac5e | 2012-02-09 15:58:44 +0200 | [diff] [blame] | 3872 | |
Rafal Mielniczuk | 2d7ab82 | 2012-03-22 22:22:04 +0100 | [diff] [blame] | 3873 | /* We need to adjust the position of the surface |
| 3874 | * in case it was resized in a rotated state before */ |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 3875 | cposx = shsurf->view->geometry.x + cx; |
| 3876 | cposy = shsurf->view->geometry.y + cy; |
Rafal Mielniczuk | 2d7ab82 | 2012-03-22 22:22:04 +0100 | [diff] [blame] | 3877 | dposx = rotate->center.x - cposx; |
| 3878 | dposy = rotate->center.y - cposy; |
| 3879 | if (dposx != 0.0f || dposy != 0.0f) { |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 3880 | weston_view_set_position(shsurf->view, |
| 3881 | shsurf->view->geometry.x + dposx, |
| 3882 | shsurf->view->geometry.y + dposy); |
Rafal Mielniczuk | 2d7ab82 | 2012-03-22 22:22:04 +0100 | [diff] [blame] | 3883 | } |
| 3884 | |
Pekka Paalanen | b45ac5e | 2012-02-09 15:58:44 +0200 | [diff] [blame] | 3885 | /* Repaint implies weston_surface_update_transform(), which |
| 3886 | * lazily applies the damage due to rotation update. |
| 3887 | */ |
Ander Conselvan de Oliveira | fe0444a | 2012-04-04 17:48:05 +0300 | [diff] [blame] | 3888 | weston_compositor_schedule_repaint(shsurf->surface->compositor); |
Pekka Paalanen | 460099f | 2012-01-20 16:48:25 +0200 | [diff] [blame] | 3889 | } |
| 3890 | |
| 3891 | static void |
Kristian Høgsberg | 02bbabb | 2013-05-06 22:15:05 -0400 | [diff] [blame] | 3892 | rotate_grab_button(struct weston_pointer_grab *grab, |
| 3893 | uint32_t time, uint32_t button, uint32_t state_w) |
Pekka Paalanen | 460099f | 2012-01-20 16:48:25 +0200 | [diff] [blame] | 3894 | { |
| 3895 | struct rotate_grab *rotate = |
Ander Conselvan de Oliveira | fe0444a | 2012-04-04 17:48:05 +0300 | [diff] [blame] | 3896 | container_of(grab, struct rotate_grab, base.grab); |
Kristian Høgsberg | 02bbabb | 2013-05-06 22:15:05 -0400 | [diff] [blame] | 3897 | struct weston_pointer *pointer = grab->pointer; |
Ander Conselvan de Oliveira | fe0444a | 2012-04-04 17:48:05 +0300 | [diff] [blame] | 3898 | struct shell_surface *shsurf = rotate->base.shsurf; |
Daniel Stone | 4dbadb1 | 2012-05-30 16:31:51 +0100 | [diff] [blame] | 3899 | enum wl_pointer_button_state state = state_w; |
Pekka Paalanen | 460099f | 2012-01-20 16:48:25 +0200 | [diff] [blame] | 3900 | |
Daniel Stone | 4dbadb1 | 2012-05-30 16:31:51 +0100 | [diff] [blame] | 3901 | if (pointer->button_count == 0 && |
| 3902 | state == WL_POINTER_BUTTON_STATE_RELEASED) { |
Ander Conselvan de Oliveira | fe0444a | 2012-04-04 17:48:05 +0300 | [diff] [blame] | 3903 | if (shsurf) |
| 3904 | weston_matrix_multiply(&shsurf->rotation.rotation, |
| 3905 | &rotate->rotation); |
Ander Conselvan de Oliveira | b9d2a0f | 2012-06-28 18:08:05 +0300 | [diff] [blame] | 3906 | shell_grab_end(&rotate->base); |
Pekka Paalanen | 460099f | 2012-01-20 16:48:25 +0200 | [diff] [blame] | 3907 | free(rotate); |
| 3908 | } |
| 3909 | } |
| 3910 | |
Jonas Ådahl | 1ea343e | 2013-10-25 23:18:05 +0200 | [diff] [blame] | 3911 | static void |
| 3912 | rotate_grab_cancel(struct weston_pointer_grab *grab) |
| 3913 | { |
| 3914 | struct rotate_grab *rotate = |
| 3915 | container_of(grab, struct rotate_grab, base.grab); |
| 3916 | |
| 3917 | shell_grab_end(&rotate->base); |
| 3918 | free(rotate); |
| 3919 | } |
| 3920 | |
Kristian Høgsberg | 02bbabb | 2013-05-06 22:15:05 -0400 | [diff] [blame] | 3921 | static const struct weston_pointer_grab_interface rotate_grab_interface = { |
Pekka Paalanen | 460099f | 2012-01-20 16:48:25 +0200 | [diff] [blame] | 3922 | noop_grab_focus, |
| 3923 | rotate_grab_motion, |
| 3924 | rotate_grab_button, |
Jonas Ådahl | 1ea343e | 2013-10-25 23:18:05 +0200 | [diff] [blame] | 3925 | rotate_grab_cancel, |
Pekka Paalanen | 460099f | 2012-01-20 16:48:25 +0200 | [diff] [blame] | 3926 | }; |
| 3927 | |
| 3928 | static void |
Kristian Høgsberg | e314875 | 2013-05-06 23:19:49 -0400 | [diff] [blame] | 3929 | surface_rotate(struct shell_surface *surface, struct weston_seat *seat) |
Pekka Paalanen | 460099f | 2012-01-20 16:48:25 +0200 | [diff] [blame] | 3930 | { |
Pekka Paalanen | 460099f | 2012-01-20 16:48:25 +0200 | [diff] [blame] | 3931 | struct rotate_grab *rotate; |
John Kåre Alsaker | 490d02a | 2012-09-30 02:57:21 +0200 | [diff] [blame] | 3932 | float dx, dy; |
| 3933 | float r; |
Pekka Paalanen | 460099f | 2012-01-20 16:48:25 +0200 | [diff] [blame] | 3934 | |
Pekka Paalanen | 460099f | 2012-01-20 16:48:25 +0200 | [diff] [blame] | 3935 | rotate = malloc(sizeof *rotate); |
| 3936 | if (!rotate) |
| 3937 | return; |
| 3938 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 3939 | weston_view_to_global_float(surface->view, |
| 3940 | surface->view->geometry.width * 0.5f, |
| 3941 | surface->view->geometry.height * 0.5f, |
| 3942 | &rotate->center.x, &rotate->center.y); |
Pekka Paalanen | 460099f | 2012-01-20 16:48:25 +0200 | [diff] [blame] | 3943 | |
Daniel Stone | 37816df | 2012-05-16 18:45:18 +0100 | [diff] [blame] | 3944 | dx = wl_fixed_to_double(seat->pointer->x) - rotate->center.x; |
| 3945 | dy = wl_fixed_to_double(seat->pointer->y) - rotate->center.y; |
Kristian Høgsberg | 765e27b | 2012-01-27 13:36:13 -0500 | [diff] [blame] | 3946 | r = sqrtf(dx * dx + dy * dy); |
| 3947 | if (r > 20.0f) { |
| 3948 | struct weston_matrix inverse; |
| 3949 | |
| 3950 | weston_matrix_init(&inverse); |
Vasily Khoruzhick | 1bbf372 | 2013-01-28 22:40:28 +0300 | [diff] [blame] | 3951 | weston_matrix_rotate_xy(&inverse, dx / r, -dy / r); |
Kristian Høgsberg | 765e27b | 2012-01-27 13:36:13 -0500 | [diff] [blame] | 3952 | weston_matrix_multiply(&surface->rotation.rotation, &inverse); |
Rafal Mielniczuk | 2d7ab82 | 2012-03-22 22:22:04 +0100 | [diff] [blame] | 3953 | |
| 3954 | weston_matrix_init(&rotate->rotation); |
Vasily Khoruzhick | 1bbf372 | 2013-01-28 22:40:28 +0300 | [diff] [blame] | 3955 | weston_matrix_rotate_xy(&rotate->rotation, dx / r, dy / r); |
Kristian Høgsberg | 765e27b | 2012-01-27 13:36:13 -0500 | [diff] [blame] | 3956 | } else { |
| 3957 | weston_matrix_init(&surface->rotation.rotation); |
| 3958 | weston_matrix_init(&rotate->rotation); |
| 3959 | } |
| 3960 | |
Ander Conselvan de Oliveira | b9d2a0f | 2012-06-28 18:08:05 +0300 | [diff] [blame] | 3961 | shell_grab_start(&rotate->base, &rotate_grab_interface, surface, |
| 3962 | seat->pointer, DESKTOP_SHELL_CURSOR_ARROW); |
Pekka Paalanen | 460099f | 2012-01-20 16:48:25 +0200 | [diff] [blame] | 3963 | } |
| 3964 | |
| 3965 | static void |
Kristian Høgsberg | e314875 | 2013-05-06 23:19:49 -0400 | [diff] [blame] | 3966 | 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] | 3967 | void *data) |
| 3968 | { |
Kristian Høgsberg | 7ab139c | 2013-10-24 16:21:39 -0700 | [diff] [blame] | 3969 | struct weston_surface *focus = seat->pointer->focus->surface; |
Pekka Paalanen | 01388e2 | 2013-04-25 13:57:44 +0300 | [diff] [blame] | 3970 | struct weston_surface *base_surface; |
Kristian Høgsberg | 0c36903 | 2013-02-14 21:31:44 -0500 | [diff] [blame] | 3971 | struct shell_surface *surface; |
| 3972 | |
Pekka Paalanen | 01388e2 | 2013-04-25 13:57:44 +0300 | [diff] [blame] | 3973 | base_surface = weston_surface_get_main_surface(focus); |
Kristian Høgsberg | 0c36903 | 2013-02-14 21:31:44 -0500 | [diff] [blame] | 3974 | if (base_surface == NULL) |
| 3975 | return; |
| 3976 | |
| 3977 | surface = get_shell_surface(base_surface); |
Rafal Mielniczuk | 23c6759 | 2013-03-11 19:26:53 +0100 | [diff] [blame] | 3978 | if (!surface || surface->type == SHELL_SURFACE_FULLSCREEN || |
| 3979 | surface->type == SHELL_SURFACE_MAXIMIZED) |
Kristian Høgsberg | 0c36903 | 2013-02-14 21:31:44 -0500 | [diff] [blame] | 3980 | return; |
| 3981 | |
| 3982 | surface_rotate(surface, seat); |
| 3983 | } |
| 3984 | |
Philip Withnall | 83ffd9d | 2013-11-25 18:01:42 +0000 | [diff] [blame] | 3985 | /* Move all fullscreen layers down to the current workspace in a non-reversible |
| 3986 | * manner. This should be used when implementing shell-wide overlays, such as |
| 3987 | * the alt-tab switcher, which need to de-promote fullscreen layers. */ |
Kristian Høgsberg | 0c36903 | 2013-02-14 21:31:44 -0500 | [diff] [blame] | 3988 | static void |
Kristian Høgsberg | b0d8e77 | 2012-06-18 16:34:58 -0400 | [diff] [blame] | 3989 | lower_fullscreen_layer(struct desktop_shell *shell) |
| 3990 | { |
| 3991 | struct workspace *ws; |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 3992 | struct weston_view *view, *prev; |
Kristian Høgsberg | b0d8e77 | 2012-06-18 16:34:58 -0400 | [diff] [blame] | 3993 | |
| 3994 | ws = get_current_workspace(shell); |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 3995 | wl_list_for_each_reverse_safe(view, prev, |
| 3996 | &shell->fullscreen_layer.view_list, |
Philip Withnall | 83ffd9d | 2013-11-25 18:01:42 +0000 | [diff] [blame] | 3997 | layer_link) { |
| 3998 | wl_list_remove(&view->layer_link); |
| 3999 | wl_list_insert(&ws->layer.view_list, &view->layer_link); |
| 4000 | weston_view_damage_below(view); |
| 4001 | weston_surface_damage(view->surface); |
| 4002 | } |
Kristian Høgsberg | b0d8e77 | 2012-06-18 16:34:58 -0400 | [diff] [blame] | 4003 | } |
| 4004 | |
| 4005 | static void |
Tiago Vignatti | be14326 | 2012-04-16 17:31:41 +0300 | [diff] [blame] | 4006 | activate(struct desktop_shell *shell, struct weston_surface *es, |
Daniel Stone | 37816df | 2012-05-16 18:45:18 +0100 | [diff] [blame] | 4007 | struct weston_seat *seat) |
Kristian Høgsberg | 7584062 | 2011-09-06 13:48:16 -0400 | [diff] [blame] | 4008 | { |
Pekka Paalanen | 01388e2 | 2013-04-25 13:57:44 +0300 | [diff] [blame] | 4009 | struct weston_surface *main_surface; |
Kristian Høgsberg | 2f5faff | 2012-07-31 16:36:34 -0400 | [diff] [blame] | 4010 | struct focus_state *state; |
Jonas Ådahl | 8538b22 | 2012-08-29 22:13:03 +0200 | [diff] [blame] | 4011 | struct workspace *ws; |
Louis-Francis Ratté-Boulianne | b482dbd | 2013-11-19 11:37:11 +0100 | [diff] [blame] | 4012 | struct weston_surface *old_es; |
Kristian Høgsberg | 7584062 | 2011-09-06 13:48:16 -0400 | [diff] [blame] | 4013 | |
Pekka Paalanen | 01388e2 | 2013-04-25 13:57:44 +0300 | [diff] [blame] | 4014 | main_surface = weston_surface_get_main_surface(es); |
| 4015 | |
Daniel Stone | 37816df | 2012-05-16 18:45:18 +0100 | [diff] [blame] | 4016 | weston_surface_activate(es, seat); |
Kristian Høgsberg | 7584062 | 2011-09-06 13:48:16 -0400 | [diff] [blame] | 4017 | |
Jonas Ådahl | 8538b22 | 2012-08-29 22:13:03 +0200 | [diff] [blame] | 4018 | state = ensure_focus_state(shell, seat); |
| 4019 | if (state == NULL) |
| 4020 | return; |
Kristian Høgsberg | 2f5faff | 2012-07-31 16:36:34 -0400 | [diff] [blame] | 4021 | |
Louis-Francis Ratté-Boulianne | b482dbd | 2013-11-19 11:37:11 +0100 | [diff] [blame] | 4022 | old_es = state->keyboard_focus; |
Kristian Høgsberg | 2f5faff | 2012-07-31 16:36:34 -0400 | [diff] [blame] | 4023 | state->keyboard_focus = es; |
| 4024 | wl_list_remove(&state->surface_destroy_listener.link); |
Jason Ekstrand | 26ed73c | 2013-06-06 22:34:41 -0500 | [diff] [blame] | 4025 | wl_signal_add(&es->destroy_signal, &state->surface_destroy_listener); |
Kristian Høgsberg | 2f5faff | 2012-07-31 16:36:34 -0400 | [diff] [blame] | 4026 | |
Pekka Paalanen | 01388e2 | 2013-04-25 13:57:44 +0300 | [diff] [blame] | 4027 | switch (get_shell_surface_type(main_surface)) { |
Alex Wu | 4539b08 | 2012-03-01 12:57:46 +0800 | [diff] [blame] | 4028 | case SHELL_SURFACE_FULLSCREEN: |
| 4029 | /* should on top of panels */ |
Pekka Paalanen | 01388e2 | 2013-04-25 13:57:44 +0300 | [diff] [blame] | 4030 | shell_configure_fullscreen(get_shell_surface(main_surface)); |
Louis-Francis Ratté-Boulianne | b482dbd | 2013-11-19 11:37:11 +0100 | [diff] [blame] | 4031 | return; |
Philip Withnall | 0f640e2 | 2013-11-25 18:01:31 +0000 | [diff] [blame] | 4032 | case SHELL_SURFACE_TOPLEVEL: |
| 4033 | case SHELL_SURFACE_TRANSIENT: |
| 4034 | case SHELL_SURFACE_MAXIMIZED: |
| 4035 | case SHELL_SURFACE_POPUP: |
| 4036 | case SHELL_SURFACE_XWAYLAND: |
| 4037 | case SHELL_SURFACE_NONE: |
Pekka Paalanen | 57da4a8 | 2011-11-23 16:42:16 +0200 | [diff] [blame] | 4038 | default: |
Alexander Larsson | f82b6ca | 2013-05-28 16:23:39 +0200 | [diff] [blame] | 4039 | restore_all_output_modes(shell->compositor); |
Kristian Høgsberg | 3be2ce9 | 2012-02-29 12:42:35 -0500 | [diff] [blame] | 4040 | break; |
Kristian Høgsberg | 7584062 | 2011-09-06 13:48:16 -0400 | [diff] [blame] | 4041 | } |
Louis-Francis Ratté-Boulianne | b482dbd | 2013-11-19 11:37:11 +0100 | [diff] [blame] | 4042 | |
Philip Withnall | 83ffd9d | 2013-11-25 18:01:42 +0000 | [diff] [blame] | 4043 | if (shell->focus_animation_type != ANIMATION_NONE) { |
| 4044 | ws = get_current_workspace(shell); |
Louis-Francis Ratté-Boulianne | b482dbd | 2013-11-19 11:37:11 +0100 | [diff] [blame] | 4045 | 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] | 4046 | } |
| 4047 | |
| 4048 | /* Update the surface’s layer. This brings it to the top of the stacking |
| 4049 | * order as appropriate. */ |
| 4050 | shell_surface_update_layer(get_shell_surface(main_surface)); |
Kristian Høgsberg | 7584062 | 2011-09-06 13:48:16 -0400 | [diff] [blame] | 4051 | } |
| 4052 | |
Alex Wu | 2185843 | 2012-04-01 20:13:08 +0800 | [diff] [blame] | 4053 | /* no-op func for checking black surface */ |
| 4054 | static void |
Giulio Camuffo | 184df50 | 2013-02-21 11:29:21 +0100 | [diff] [blame] | 4055 | black_surface_configure(struct weston_surface *es, int32_t sx, int32_t sy, int32_t width, int32_t height) |
Alex Wu | 2185843 | 2012-04-01 20:13:08 +0800 | [diff] [blame] | 4056 | { |
| 4057 | } |
| 4058 | |
Quentin Glidic | c0d79ce | 2013-01-29 14:16:13 +0100 | [diff] [blame] | 4059 | static bool |
Alex Wu | 2185843 | 2012-04-01 20:13:08 +0800 | [diff] [blame] | 4060 | is_black_surface (struct weston_surface *es, struct weston_surface **fs_surface) |
| 4061 | { |
| 4062 | if (es->configure == black_surface_configure) { |
| 4063 | if (fs_surface) |
Giulio Camuffo | 7fe01b1 | 2013-03-28 18:02:42 +0100 | [diff] [blame] | 4064 | *fs_surface = (struct weston_surface *)es->configure_private; |
Alex Wu | 2185843 | 2012-04-01 20:13:08 +0800 | [diff] [blame] | 4065 | return true; |
| 4066 | } |
| 4067 | return false; |
| 4068 | } |
| 4069 | |
Kristian Høgsberg | 7584062 | 2011-09-06 13:48:16 -0400 | [diff] [blame] | 4070 | static void |
Neil Roberts | a28c693 | 2013-10-03 16:43:04 +0100 | [diff] [blame] | 4071 | activate_binding(struct weston_seat *seat, |
| 4072 | struct desktop_shell *shell, |
| 4073 | struct weston_surface *focus) |
Kristian Høgsberg | e1a850e | 2011-12-19 15:18:05 -0500 | [diff] [blame] | 4074 | { |
Pekka Paalanen | 01388e2 | 2013-04-25 13:57:44 +0300 | [diff] [blame] | 4075 | struct weston_surface *main_surface; |
Kristian Høgsberg | e1a850e | 2011-12-19 15:18:05 -0500 | [diff] [blame] | 4076 | |
Alex Wu | 9c35e6b | 2012-03-05 14:13:13 +0800 | [diff] [blame] | 4077 | if (!focus) |
| 4078 | return; |
| 4079 | |
Pekka Paalanen | 01388e2 | 2013-04-25 13:57:44 +0300 | [diff] [blame] | 4080 | if (is_black_surface(focus, &main_surface)) |
| 4081 | focus = main_surface; |
Alex Wu | 4539b08 | 2012-03-01 12:57:46 +0800 | [diff] [blame] | 4082 | |
Pekka Paalanen | 01388e2 | 2013-04-25 13:57:44 +0300 | [diff] [blame] | 4083 | main_surface = weston_surface_get_main_surface(focus); |
| 4084 | if (get_shell_surface_type(main_surface) == SHELL_SURFACE_NONE) |
Kristian Høgsberg | 0636ac3 | 2012-06-27 10:22:15 -0400 | [diff] [blame] | 4085 | return; |
Kristian Høgsberg | 85b2e4b | 2012-06-21 16:49:42 -0400 | [diff] [blame] | 4086 | |
Neil Roberts | a28c693 | 2013-10-03 16:43:04 +0100 | [diff] [blame] | 4087 | activate(shell, focus, seat); |
| 4088 | } |
| 4089 | |
| 4090 | static void |
| 4091 | click_to_activate_binding(struct weston_seat *seat, uint32_t time, uint32_t button, |
| 4092 | void *data) |
| 4093 | { |
| 4094 | if (seat->pointer->grab != &seat->pointer->default_grab) |
| 4095 | return; |
| 4096 | |
Kristian Høgsberg | 7ab139c | 2013-10-24 16:21:39 -0700 | [diff] [blame] | 4097 | activate_binding(seat, data, seat->pointer->focus->surface); |
Neil Roberts | a28c693 | 2013-10-03 16:43:04 +0100 | [diff] [blame] | 4098 | } |
| 4099 | |
| 4100 | static void |
| 4101 | touch_to_activate_binding(struct weston_seat *seat, uint32_t time, void *data) |
| 4102 | { |
| 4103 | if (seat->touch->grab != &seat->touch->default_grab) |
| 4104 | return; |
| 4105 | |
Kristian Høgsberg | 7ab139c | 2013-10-24 16:21:39 -0700 | [diff] [blame] | 4106 | activate_binding(seat, data, seat->touch->focus->surface); |
Kristian Høgsberg | e1a850e | 2011-12-19 15:18:05 -0500 | [diff] [blame] | 4107 | } |
| 4108 | |
| 4109 | static void |
Ander Conselvan de Oliveira | 19d10ef | 2013-02-21 18:35:20 +0200 | [diff] [blame] | 4110 | lock(struct desktop_shell *shell) |
Kristian Høgsberg | 02ec0a5 | 2011-04-23 13:04:11 -0400 | [diff] [blame] | 4111 | { |
Kristian Høgsberg | 4476aaf | 2012-06-25 14:03:13 -0400 | [diff] [blame] | 4112 | struct workspace *ws = get_current_workspace(shell); |
Pekka Paalanen | f0fc70d | 2011-11-15 13:34:54 +0200 | [diff] [blame] | 4113 | |
Tiago Vignatti | 8e53c7f | 2012-02-29 19:53:50 +0200 | [diff] [blame] | 4114 | if (shell->locked) { |
Ander Conselvan de Oliveira | 87524b6 | 2013-02-21 18:35:22 +0200 | [diff] [blame] | 4115 | weston_compositor_sleep(shell->compositor); |
Pekka Paalanen | f0fc70d | 2011-11-15 13:34:54 +0200 | [diff] [blame] | 4116 | return; |
Tiago Vignatti | 8e53c7f | 2012-02-29 19:53:50 +0200 | [diff] [blame] | 4117 | } |
Pekka Paalanen | 9ef3e01 | 2011-11-15 13:34:48 +0200 | [diff] [blame] | 4118 | |
| 4119 | shell->locked = true; |
Pekka Paalanen | f0fc70d | 2011-11-15 13:34:54 +0200 | [diff] [blame] | 4120 | |
Kristian Høgsberg | 3be2ce9 | 2012-02-29 12:42:35 -0500 | [diff] [blame] | 4121 | /* Hide all surfaces by removing the fullscreen, panel and |
| 4122 | * toplevel layers. This way nothing else can show or receive |
| 4123 | * input events while we are locked. */ |
Pekka Paalanen | f0fc70d | 2011-11-15 13:34:54 +0200 | [diff] [blame] | 4124 | |
Kristian Høgsberg | 3be2ce9 | 2012-02-29 12:42:35 -0500 | [diff] [blame] | 4125 | wl_list_remove(&shell->panel_layer.link); |
Kristian Høgsberg | 3be2ce9 | 2012-02-29 12:42:35 -0500 | [diff] [blame] | 4126 | wl_list_remove(&shell->fullscreen_layer.link); |
Philipp Brüschweiler | 711fda8 | 2012-08-09 18:50:43 +0200 | [diff] [blame] | 4127 | if (shell->showing_input_panels) |
| 4128 | wl_list_remove(&shell->input_panel_layer.link); |
Kristian Høgsberg | 4476aaf | 2012-06-25 14:03:13 -0400 | [diff] [blame] | 4129 | wl_list_remove(&ws->layer.link); |
Kristian Høgsberg | 3be2ce9 | 2012-02-29 12:42:35 -0500 | [diff] [blame] | 4130 | wl_list_insert(&shell->compositor->cursor_layer.link, |
| 4131 | &shell->lock_layer.link); |
Pekka Paalanen | f0fc70d | 2011-11-15 13:34:54 +0200 | [diff] [blame] | 4132 | |
Pekka Paalanen | 77346a6 | 2011-11-30 16:26:35 +0200 | [diff] [blame] | 4133 | launch_screensaver(shell); |
| 4134 | |
Pekka Paalanen | f0fc70d | 2011-11-15 13:34:54 +0200 | [diff] [blame] | 4135 | /* TODO: disable bindings that should not work while locked. */ |
| 4136 | |
| 4137 | /* All this must be undone in resume_desktop(). */ |
Pekka Paalanen | 9ef3e01 | 2011-11-15 13:34:48 +0200 | [diff] [blame] | 4138 | } |
| 4139 | |
| 4140 | static void |
Ander Conselvan de Oliveira | 19d10ef | 2013-02-21 18:35:20 +0200 | [diff] [blame] | 4141 | unlock(struct desktop_shell *shell) |
Pekka Paalanen | 9ef3e01 | 2011-11-15 13:34:48 +0200 | [diff] [blame] | 4142 | { |
Pekka Paalanen | d81c216 | 2011-11-16 13:47:34 +0200 | [diff] [blame] | 4143 | if (!shell->locked || shell->lock_surface) { |
Ander Conselvan de Oliveira | 87524b6 | 2013-02-21 18:35:22 +0200 | [diff] [blame] | 4144 | shell_fade(shell, FADE_IN); |
Pekka Paalanen | 9ef3e01 | 2011-11-15 13:34:48 +0200 | [diff] [blame] | 4145 | return; |
| 4146 | } |
| 4147 | |
| 4148 | /* If desktop-shell client has gone away, unlock immediately. */ |
| 4149 | if (!shell->child.desktop_shell) { |
Pekka Paalanen | f0fc70d | 2011-11-15 13:34:54 +0200 | [diff] [blame] | 4150 | resume_desktop(shell); |
Pekka Paalanen | 9ef3e01 | 2011-11-15 13:34:48 +0200 | [diff] [blame] | 4151 | return; |
| 4152 | } |
| 4153 | |
| 4154 | if (shell->prepare_event_sent) |
| 4155 | return; |
| 4156 | |
Kristian Høgsberg | 0b5cd0c | 2012-03-04 21:57:37 -0500 | [diff] [blame] | 4157 | desktop_shell_send_prepare_lock_surface(shell->child.desktop_shell); |
Pekka Paalanen | 9ef3e01 | 2011-11-15 13:34:48 +0200 | [diff] [blame] | 4158 | shell->prepare_event_sent = true; |
Kristian Høgsberg | 02ec0a5 | 2011-04-23 13:04:11 -0400 | [diff] [blame] | 4159 | } |
| 4160 | |
| 4161 | static void |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 4162 | shell_fade_done(struct weston_view_animation *animation, void *data) |
Ander Conselvan de Oliveira | 19d10ef | 2013-02-21 18:35:20 +0200 | [diff] [blame] | 4163 | { |
| 4164 | struct desktop_shell *shell = data; |
| 4165 | |
| 4166 | shell->fade.animation = NULL; |
| 4167 | |
| 4168 | switch (shell->fade.type) { |
| 4169 | case FADE_IN: |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 4170 | weston_surface_destroy(shell->fade.view->surface); |
| 4171 | shell->fade.view = NULL; |
Ander Conselvan de Oliveira | 19d10ef | 2013-02-21 18:35:20 +0200 | [diff] [blame] | 4172 | break; |
| 4173 | case FADE_OUT: |
Ander Conselvan de Oliveira | 19d10ef | 2013-02-21 18:35:20 +0200 | [diff] [blame] | 4174 | lock(shell); |
| 4175 | break; |
Philip Withnall | 4a86a0a | 2013-11-25 18:01:32 +0000 | [diff] [blame] | 4176 | default: |
| 4177 | break; |
Ander Conselvan de Oliveira | 19d10ef | 2013-02-21 18:35:20 +0200 | [diff] [blame] | 4178 | } |
| 4179 | } |
| 4180 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 4181 | static struct weston_view * |
Pekka Paalanen | 79346ab | 2013-05-22 18:03:09 +0300 | [diff] [blame] | 4182 | shell_fade_create_surface(struct desktop_shell *shell) |
Ander Conselvan de Oliveira | 19d10ef | 2013-02-21 18:35:20 +0200 | [diff] [blame] | 4183 | { |
| 4184 | struct weston_compositor *compositor = shell->compositor; |
| 4185 | struct weston_surface *surface; |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 4186 | struct weston_view *view; |
Pekka Paalanen | 79346ab | 2013-05-22 18:03:09 +0300 | [diff] [blame] | 4187 | |
| 4188 | surface = weston_surface_create(compositor); |
| 4189 | if (!surface) |
| 4190 | return NULL; |
| 4191 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 4192 | view = weston_view_create(surface); |
| 4193 | if (!view) { |
| 4194 | weston_surface_destroy(surface); |
| 4195 | return NULL; |
| 4196 | } |
| 4197 | |
| 4198 | weston_view_configure(view, 0, 0, 8192, 8192); |
Pekka Paalanen | 79346ab | 2013-05-22 18:03:09 +0300 | [diff] [blame] | 4199 | 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] | 4200 | wl_list_insert(&compositor->fade_layer.view_list, |
| 4201 | &view->layer_link); |
Pekka Paalanen | 79346ab | 2013-05-22 18:03:09 +0300 | [diff] [blame] | 4202 | pixman_region32_init(&surface->input); |
| 4203 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 4204 | return view; |
Pekka Paalanen | 79346ab | 2013-05-22 18:03:09 +0300 | [diff] [blame] | 4205 | } |
| 4206 | |
| 4207 | static void |
| 4208 | shell_fade(struct desktop_shell *shell, enum fade_type type) |
| 4209 | { |
Ander Conselvan de Oliveira | 19d10ef | 2013-02-21 18:35:20 +0200 | [diff] [blame] | 4210 | float tint; |
| 4211 | |
| 4212 | switch (type) { |
| 4213 | case FADE_IN: |
| 4214 | tint = 0.0; |
| 4215 | break; |
| 4216 | case FADE_OUT: |
| 4217 | tint = 1.0; |
| 4218 | break; |
| 4219 | default: |
| 4220 | weston_log("shell: invalid fade type\n"); |
| 4221 | return; |
| 4222 | } |
| 4223 | |
| 4224 | shell->fade.type = type; |
| 4225 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 4226 | if (shell->fade.view == NULL) { |
| 4227 | shell->fade.view = shell_fade_create_surface(shell); |
| 4228 | if (!shell->fade.view) |
Ander Conselvan de Oliveira | 19d10ef | 2013-02-21 18:35:20 +0200 | [diff] [blame] | 4229 | return; |
| 4230 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 4231 | shell->fade.view->alpha = 1.0 - tint; |
| 4232 | weston_view_update_transform(shell->fade.view); |
Ander Conselvan de Oliveira | 19d10ef | 2013-02-21 18:35:20 +0200 | [diff] [blame] | 4233 | } |
| 4234 | |
| 4235 | if (shell->fade.animation) |
Kristian Høgsberg | 5281fb1 | 2013-06-17 10:10:28 -0400 | [diff] [blame] | 4236 | weston_fade_update(shell->fade.animation, tint); |
Ander Conselvan de Oliveira | 19d10ef | 2013-02-21 18:35:20 +0200 | [diff] [blame] | 4237 | else |
| 4238 | shell->fade.animation = |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 4239 | weston_fade_run(shell->fade.view, |
Kristian Høgsberg | 5281fb1 | 2013-06-17 10:10:28 -0400 | [diff] [blame] | 4240 | 1.0 - tint, tint, 300.0, |
Ander Conselvan de Oliveira | 19d10ef | 2013-02-21 18:35:20 +0200 | [diff] [blame] | 4241 | shell_fade_done, shell); |
| 4242 | } |
| 4243 | |
| 4244 | static void |
Pekka Paalanen | 79346ab | 2013-05-22 18:03:09 +0300 | [diff] [blame] | 4245 | do_shell_fade_startup(void *data) |
| 4246 | { |
| 4247 | struct desktop_shell *shell = data; |
| 4248 | |
Kristian Høgsberg | 724c8d9 | 2013-10-16 11:38:24 -0700 | [diff] [blame] | 4249 | if (shell->startup_animation_type == ANIMATION_FADE) |
| 4250 | shell_fade(shell, FADE_IN); |
| 4251 | else if (shell->startup_animation_type == ANIMATION_NONE) { |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 4252 | weston_surface_destroy(shell->fade.view->surface); |
| 4253 | shell->fade.view = NULL; |
Kristian Høgsberg | 724c8d9 | 2013-10-16 11:38:24 -0700 | [diff] [blame] | 4254 | } |
Pekka Paalanen | 79346ab | 2013-05-22 18:03:09 +0300 | [diff] [blame] | 4255 | } |
| 4256 | |
| 4257 | static void |
| 4258 | shell_fade_startup(struct desktop_shell *shell) |
| 4259 | { |
| 4260 | struct wl_event_loop *loop; |
| 4261 | |
| 4262 | if (!shell->fade.startup_timer) |
| 4263 | return; |
| 4264 | |
| 4265 | wl_event_source_remove(shell->fade.startup_timer); |
| 4266 | shell->fade.startup_timer = NULL; |
| 4267 | |
| 4268 | loop = wl_display_get_event_loop(shell->compositor->wl_display); |
| 4269 | wl_event_loop_add_idle(loop, do_shell_fade_startup, shell); |
| 4270 | } |
| 4271 | |
| 4272 | static int |
| 4273 | fade_startup_timeout(void *data) |
| 4274 | { |
| 4275 | struct desktop_shell *shell = data; |
| 4276 | |
| 4277 | shell_fade_startup(shell); |
| 4278 | return 0; |
| 4279 | } |
| 4280 | |
| 4281 | static void |
| 4282 | shell_fade_init(struct desktop_shell *shell) |
| 4283 | { |
| 4284 | /* Make compositor output all black, and wait for the desktop-shell |
| 4285 | * client to signal it is ready, then fade in. The timer triggers a |
| 4286 | * fade-in, in case the desktop-shell client takes too long. |
| 4287 | */ |
| 4288 | |
| 4289 | struct wl_event_loop *loop; |
| 4290 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 4291 | if (shell->fade.view != NULL) { |
Pekka Paalanen | 79346ab | 2013-05-22 18:03:09 +0300 | [diff] [blame] | 4292 | weston_log("%s: warning: fade surface already exists\n", |
| 4293 | __func__); |
| 4294 | return; |
| 4295 | } |
| 4296 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 4297 | shell->fade.view = shell_fade_create_surface(shell); |
| 4298 | if (!shell->fade.view) |
Pekka Paalanen | 79346ab | 2013-05-22 18:03:09 +0300 | [diff] [blame] | 4299 | return; |
| 4300 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 4301 | weston_view_update_transform(shell->fade.view); |
| 4302 | weston_surface_damage(shell->fade.view->surface); |
Pekka Paalanen | 79346ab | 2013-05-22 18:03:09 +0300 | [diff] [blame] | 4303 | |
| 4304 | loop = wl_display_get_event_loop(shell->compositor->wl_display); |
| 4305 | shell->fade.startup_timer = |
| 4306 | wl_event_loop_add_timer(loop, fade_startup_timeout, shell); |
| 4307 | wl_event_source_timer_update(shell->fade.startup_timer, 15000); |
| 4308 | } |
| 4309 | |
| 4310 | static void |
Ander Conselvan de Oliveira | a457563 | 2013-02-21 18:35:23 +0200 | [diff] [blame] | 4311 | idle_handler(struct wl_listener *listener, void *data) |
Ander Conselvan de Oliveira | 19d10ef | 2013-02-21 18:35:20 +0200 | [diff] [blame] | 4312 | { |
| 4313 | struct desktop_shell *shell = |
Ander Conselvan de Oliveira | a457563 | 2013-02-21 18:35:23 +0200 | [diff] [blame] | 4314 | container_of(listener, struct desktop_shell, idle_listener); |
Ander Conselvan de Oliveira | 19d10ef | 2013-02-21 18:35:20 +0200 | [diff] [blame] | 4315 | |
| 4316 | shell_fade(shell, FADE_OUT); |
| 4317 | /* lock() is called from shell_fade_done() */ |
| 4318 | } |
| 4319 | |
| 4320 | static void |
Ander Conselvan de Oliveira | a457563 | 2013-02-21 18:35:23 +0200 | [diff] [blame] | 4321 | wake_handler(struct wl_listener *listener, void *data) |
Ander Conselvan de Oliveira | 19d10ef | 2013-02-21 18:35:20 +0200 | [diff] [blame] | 4322 | { |
| 4323 | struct desktop_shell *shell = |
Ander Conselvan de Oliveira | a457563 | 2013-02-21 18:35:23 +0200 | [diff] [blame] | 4324 | container_of(listener, struct desktop_shell, wake_listener); |
Ander Conselvan de Oliveira | 19d10ef | 2013-02-21 18:35:20 +0200 | [diff] [blame] | 4325 | |
Ander Conselvan de Oliveira | 19d10ef | 2013-02-21 18:35:20 +0200 | [diff] [blame] | 4326 | unlock(shell); |
| 4327 | } |
| 4328 | |
| 4329 | static void |
Jan Arne Petersen | 42feced | 2012-06-21 21:52:17 +0200 | [diff] [blame] | 4330 | show_input_panels(struct wl_listener *listener, void *data) |
| 4331 | { |
| 4332 | struct desktop_shell *shell = |
Philipp Brüschweiler | 711fda8 | 2012-08-09 18:50:43 +0200 | [diff] [blame] | 4333 | container_of(listener, struct desktop_shell, |
| 4334 | show_input_panel_listener); |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 4335 | struct input_panel_surface *ipsurf, *next; |
Jan Arne Petersen | 42feced | 2012-06-21 21:52:17 +0200 | [diff] [blame] | 4336 | |
Jan Arne Petersen | 14da96b | 2013-04-18 16:47:28 +0200 | [diff] [blame] | 4337 | shell->text_input.surface = (struct weston_surface*)data; |
| 4338 | |
Jan Arne Petersen | 451a971 | 2013-02-11 15:10:11 +0100 | [diff] [blame] | 4339 | if (shell->showing_input_panels) |
| 4340 | return; |
| 4341 | |
Philipp Brüschweiler | 711fda8 | 2012-08-09 18:50:43 +0200 | [diff] [blame] | 4342 | shell->showing_input_panels = true; |
| 4343 | |
Jan Arne Petersen | cf18a32 | 2012-11-07 15:32:54 +0100 | [diff] [blame] | 4344 | if (!shell->locked) |
| 4345 | wl_list_insert(&shell->panel_layer.link, |
| 4346 | &shell->input_panel_layer.link); |
Philipp Brüschweiler | 711fda8 | 2012-08-09 18:50:43 +0200 | [diff] [blame] | 4347 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 4348 | wl_list_for_each_safe(ipsurf, next, |
Philipp Brüschweiler | 8801357 | 2012-08-06 13:44:42 +0200 | [diff] [blame] | 4349 | &shell->input_panel.surfaces, link) { |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 4350 | if (!ipsurf->surface->buffer_ref.buffer) |
Jan Arne Petersen | 14da96b | 2013-04-18 16:47:28 +0200 | [diff] [blame] | 4351 | continue; |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 4352 | wl_list_insert(&shell->input_panel_layer.view_list, |
| 4353 | &ipsurf->view->layer_link); |
| 4354 | weston_view_geometry_dirty(ipsurf->view); |
| 4355 | weston_view_update_transform(ipsurf->view); |
| 4356 | weston_surface_damage(ipsurf->surface); |
| 4357 | weston_slide_run(ipsurf->view, ipsurf->view->geometry.height, |
| 4358 | 0, NULL, NULL); |
Jan Arne Petersen | 42feced | 2012-06-21 21:52:17 +0200 | [diff] [blame] | 4359 | } |
| 4360 | } |
| 4361 | |
| 4362 | static void |
| 4363 | hide_input_panels(struct wl_listener *listener, void *data) |
| 4364 | { |
| 4365 | struct desktop_shell *shell = |
Philipp Brüschweiler | 711fda8 | 2012-08-09 18:50:43 +0200 | [diff] [blame] | 4366 | container_of(listener, struct desktop_shell, |
| 4367 | hide_input_panel_listener); |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 4368 | struct weston_view *view, *next; |
Jan Arne Petersen | 42feced | 2012-06-21 21:52:17 +0200 | [diff] [blame] | 4369 | |
Jan Arne Petersen | 6138197 | 2013-01-31 15:52:21 +0100 | [diff] [blame] | 4370 | if (!shell->showing_input_panels) |
| 4371 | return; |
| 4372 | |
Philipp Brüschweiler | 711fda8 | 2012-08-09 18:50:43 +0200 | [diff] [blame] | 4373 | shell->showing_input_panels = false; |
| 4374 | |
Jan Arne Petersen | 82ec909 | 2012-12-03 15:36:02 +0100 | [diff] [blame] | 4375 | if (!shell->locked) |
| 4376 | wl_list_remove(&shell->input_panel_layer.link); |
Philipp Brüschweiler | 711fda8 | 2012-08-09 18:50:43 +0200 | [diff] [blame] | 4377 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 4378 | wl_list_for_each_safe(view, next, |
| 4379 | &shell->input_panel_layer.view_list, layer_link) |
| 4380 | weston_view_unmap(view); |
Jan Arne Petersen | 42feced | 2012-06-21 21:52:17 +0200 | [diff] [blame] | 4381 | } |
| 4382 | |
| 4383 | static void |
Jan Arne Petersen | 14da96b | 2013-04-18 16:47:28 +0200 | [diff] [blame] | 4384 | update_input_panels(struct wl_listener *listener, void *data) |
| 4385 | { |
| 4386 | struct desktop_shell *shell = |
| 4387 | container_of(listener, struct desktop_shell, |
| 4388 | update_input_panel_listener); |
| 4389 | |
| 4390 | memcpy(&shell->text_input.cursor_rectangle, data, sizeof(pixman_box32_t)); |
| 4391 | } |
| 4392 | |
| 4393 | static void |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 4394 | center_on_output(struct weston_view *view, struct weston_output *output) |
Pekka Paalanen | 77346a6 | 2011-11-30 16:26:35 +0200 | [diff] [blame] | 4395 | { |
Giulio Camuffo | b836664 | 2013-04-25 13:57:46 +0300 | [diff] [blame] | 4396 | int32_t surf_x, surf_y, width, height; |
Ander Conselvan de Oliveira | 012b4c7 | 2012-11-27 17:03:42 +0200 | [diff] [blame] | 4397 | float x, y; |
Pekka Paalanen | 77346a6 | 2011-11-30 16:26:35 +0200 | [diff] [blame] | 4398 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 4399 | surface_subsurfaces_boundingbox(view->surface, &surf_x, &surf_y, &width, &height); |
Giulio Camuffo | b836664 | 2013-04-25 13:57:46 +0300 | [diff] [blame] | 4400 | |
| 4401 | x = output->x + (output->width - width) / 2 - surf_x / 2; |
| 4402 | y = output->y + (output->height - height) / 2 - surf_y / 2; |
Ander Conselvan de Oliveira | 012b4c7 | 2012-11-27 17:03:42 +0200 | [diff] [blame] | 4403 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 4404 | weston_view_configure(view, x, y, width, height); |
Pekka Paalanen | 77346a6 | 2011-11-30 16:26:35 +0200 | [diff] [blame] | 4405 | } |
| 4406 | |
| 4407 | static void |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 4408 | weston_view_set_initial_position(struct weston_view *view, |
| 4409 | struct desktop_shell *shell) |
Rob Bradford | ac63e5b | 2012-08-13 14:07:52 +0100 | [diff] [blame] | 4410 | { |
| 4411 | struct weston_compositor *compositor = shell->compositor; |
| 4412 | int ix = 0, iy = 0; |
| 4413 | int range_x, range_y; |
| 4414 | int dx, dy, x, y, panel_height; |
| 4415 | struct weston_output *output, *target_output = NULL; |
| 4416 | struct weston_seat *seat; |
| 4417 | |
| 4418 | /* As a heuristic place the new window on the same output as the |
| 4419 | * pointer. Falling back to the output containing 0, 0. |
| 4420 | * |
| 4421 | * TODO: Do something clever for touch too? |
| 4422 | */ |
| 4423 | wl_list_for_each(seat, &compositor->seat_list, link) { |
Kristian Høgsberg | 2bf8762 | 2013-05-07 23:17:41 -0400 | [diff] [blame] | 4424 | if (seat->pointer) { |
Kristian Høgsberg | e314875 | 2013-05-06 23:19:49 -0400 | [diff] [blame] | 4425 | ix = wl_fixed_to_int(seat->pointer->x); |
| 4426 | iy = wl_fixed_to_int(seat->pointer->y); |
Rob Bradford | ac63e5b | 2012-08-13 14:07:52 +0100 | [diff] [blame] | 4427 | break; |
| 4428 | } |
| 4429 | } |
| 4430 | |
| 4431 | wl_list_for_each(output, &compositor->output_list, link) { |
| 4432 | if (pixman_region32_contains_point(&output->region, ix, iy, NULL)) { |
| 4433 | target_output = output; |
| 4434 | break; |
| 4435 | } |
| 4436 | } |
| 4437 | |
| 4438 | if (!target_output) { |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 4439 | weston_view_set_position(view, 10 + random() % 400, |
| 4440 | 10 + random() % 400); |
Rob Bradford | ac63e5b | 2012-08-13 14:07:52 +0100 | [diff] [blame] | 4441 | return; |
| 4442 | } |
| 4443 | |
| 4444 | /* Valid range within output where the surface will still be onscreen. |
| 4445 | * If this is negative it means that the surface is bigger than |
| 4446 | * output. |
| 4447 | */ |
| 4448 | panel_height = get_output_panel_height(shell, target_output); |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 4449 | range_x = target_output->width - view->geometry.width; |
Scott Moreau | 1bad5db | 2012-08-18 01:04:05 -0600 | [diff] [blame] | 4450 | range_y = (target_output->height - panel_height) - |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 4451 | view->geometry.height; |
Rob Bradford | ac63e5b | 2012-08-13 14:07:52 +0100 | [diff] [blame] | 4452 | |
Rob Bradford | 4cb88c7 | 2012-08-13 15:18:44 +0100 | [diff] [blame] | 4453 | if (range_x > 0) |
Rob Bradford | ac63e5b | 2012-08-13 14:07:52 +0100 | [diff] [blame] | 4454 | dx = random() % range_x; |
Rob Bradford | ac63e5b | 2012-08-13 14:07:52 +0100 | [diff] [blame] | 4455 | else |
Rob Bradford | 4cb88c7 | 2012-08-13 15:18:44 +0100 | [diff] [blame] | 4456 | dx = 0; |
| 4457 | |
| 4458 | if (range_y > 0) |
Rob Bradford | ac63e5b | 2012-08-13 14:07:52 +0100 | [diff] [blame] | 4459 | dy = panel_height + random() % range_y; |
Rob Bradford | 4cb88c7 | 2012-08-13 15:18:44 +0100 | [diff] [blame] | 4460 | else |
| 4461 | dy = panel_height; |
Rob Bradford | ac63e5b | 2012-08-13 14:07:52 +0100 | [diff] [blame] | 4462 | |
| 4463 | x = target_output->x + dx; |
| 4464 | y = target_output->y + dy; |
| 4465 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 4466 | weston_view_set_position(view, x, y); |
Rob Bradford | ac63e5b | 2012-08-13 14:07:52 +0100 | [diff] [blame] | 4467 | } |
| 4468 | |
| 4469 | static void |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 4470 | map(struct desktop_shell *shell, struct shell_surface *shsurf, |
Ander Conselvan de Oliveira | e9e0515 | 2012-02-15 17:02:56 +0200 | [diff] [blame] | 4471 | int32_t width, int32_t height, int32_t sx, int32_t sy) |
Kristian Høgsberg | 02ec0a5 | 2011-04-23 13:04:11 -0400 | [diff] [blame] | 4472 | { |
Kristian Høgsberg | 8334bc1 | 2012-01-03 10:29:47 -0500 | [diff] [blame] | 4473 | struct weston_compositor *compositor = shell->compositor; |
Daniel Stone | b210468 | 2012-05-30 16:31:56 +0100 | [diff] [blame] | 4474 | struct weston_seat *seat; |
Juan Zhao | 96879df | 2012-02-07 08:45:41 +0800 | [diff] [blame] | 4475 | int panel_height = 0; |
Giulio Camuffo | b836664 | 2013-04-25 13:57:46 +0300 | [diff] [blame] | 4476 | int32_t surf_x, surf_y; |
Pekka Paalanen | 57da4a8 | 2011-11-23 16:42:16 +0200 | [diff] [blame] | 4477 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 4478 | shsurf->view->geometry.width = width; |
| 4479 | shsurf->view->geometry.height = height; |
| 4480 | weston_view_geometry_dirty(shsurf->view); |
Pekka Paalanen | 77346a6 | 2011-11-30 16:26:35 +0200 | [diff] [blame] | 4481 | |
| 4482 | /* initial positioning, see also configure() */ |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 4483 | switch (shsurf->type) { |
Pekka Paalanen | 77346a6 | 2011-11-30 16:26:35 +0200 | [diff] [blame] | 4484 | case SHELL_SURFACE_TOPLEVEL: |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 4485 | weston_view_set_initial_position(shsurf->view, shell); |
Pekka Paalanen | 77346a6 | 2011-11-30 16:26:35 +0200 | [diff] [blame] | 4486 | break; |
Alex Wu | 4539b08 | 2012-03-01 12:57:46 +0800 | [diff] [blame] | 4487 | case SHELL_SURFACE_FULLSCREEN: |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 4488 | center_on_output(shsurf->view, shsurf->fullscreen_output); |
Alex Wu | 4539b08 | 2012-03-01 12:57:46 +0800 | [diff] [blame] | 4489 | shell_map_fullscreen(shsurf); |
| 4490 | break; |
Juan Zhao | 96879df | 2012-02-07 08:45:41 +0800 | [diff] [blame] | 4491 | case SHELL_SURFACE_MAXIMIZED: |
Alex Wu | 4539b08 | 2012-03-01 12:57:46 +0800 | [diff] [blame] | 4492 | /* use surface configure to set the geometry */ |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 4493 | panel_height = get_output_panel_height(shell, shsurf->output); |
| 4494 | surface_subsurfaces_boundingbox(shsurf->surface, |
| 4495 | &surf_x, &surf_y, NULL, NULL); |
| 4496 | weston_view_set_position(shsurf->view, |
| 4497 | shsurf->output->x - surf_x, |
| 4498 | shsurf->output->y + panel_height - surf_y); |
Juan Zhao | 96879df | 2012-02-07 08:45:41 +0800 | [diff] [blame] | 4499 | break; |
Tiago Vignatti | 0f99701 | 2012-02-10 16:17:23 +0200 | [diff] [blame] | 4500 | case SHELL_SURFACE_POPUP: |
Kristian Høgsberg | 3730f36 | 2012-04-13 12:40:07 -0400 | [diff] [blame] | 4501 | shell_map_popup(shsurf); |
Rob Bradford | db99938 | 2012-12-06 12:07:48 +0000 | [diff] [blame] | 4502 | break; |
Ander Conselvan de Oliveira | e9e0515 | 2012-02-15 17:02:56 +0200 | [diff] [blame] | 4503 | case SHELL_SURFACE_NONE: |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 4504 | weston_view_set_position(shsurf->view, |
| 4505 | shsurf->view->geometry.x + sx, |
| 4506 | shsurf->view->geometry.y + sy); |
Tiago Vignatti | 0f99701 | 2012-02-10 16:17:23 +0200 | [diff] [blame] | 4507 | break; |
Philip Withnall | 0f640e2 | 2013-11-25 18:01:31 +0000 | [diff] [blame] | 4508 | case SHELL_SURFACE_TRANSIENT: |
| 4509 | case SHELL_SURFACE_XWAYLAND: |
Pekka Paalanen | 77346a6 | 2011-11-30 16:26:35 +0200 | [diff] [blame] | 4510 | default: |
| 4511 | ; |
| 4512 | } |
Kristian Høgsberg | 7584062 | 2011-09-06 13:48:16 -0400 | [diff] [blame] | 4513 | |
Philip Withnall | e1d75ae | 2013-11-25 18:01:41 +0000 | [diff] [blame] | 4514 | /* Surface stacking order, see also activate(). */ |
| 4515 | shell_surface_update_layer(shsurf); |
Pekka Paalanen | f0fc70d | 2011-11-15 13:34:54 +0200 | [diff] [blame] | 4516 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 4517 | if (shsurf->type != SHELL_SURFACE_NONE) { |
| 4518 | weston_view_update_transform(shsurf->view); |
| 4519 | if (shsurf->type == SHELL_SURFACE_MAXIMIZED) { |
| 4520 | shsurf->surface->output = shsurf->output; |
| 4521 | shsurf->view->output = shsurf->output; |
| 4522 | } |
Ander Conselvan de Oliveira | de56c31 | 2012-03-05 15:39:23 +0200 | [diff] [blame] | 4523 | } |
Kristian Høgsberg | 2f88a40 | 2011-12-04 15:32:59 -0500 | [diff] [blame] | 4524 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 4525 | switch (shsurf->type) { |
Tiago Vignatti | fb2adba | 2013-06-12 15:43:21 -0300 | [diff] [blame] | 4526 | /* XXX: xwayland's using the same fields for transient type */ |
| 4527 | case SHELL_SURFACE_XWAYLAND: |
Juan Zhao | 7bb92f0 | 2011-12-15 11:31:51 -0500 | [diff] [blame] | 4528 | case SHELL_SURFACE_TRANSIENT: |
Tiago Vignatti | 99aeb1e | 2012-05-23 22:06:26 +0300 | [diff] [blame] | 4529 | if (shsurf->transient.flags == |
| 4530 | WL_SHELL_SURFACE_TRANSIENT_INACTIVE) |
| 4531 | break; |
| 4532 | case SHELL_SURFACE_TOPLEVEL: |
Juan Zhao | 7bb92f0 | 2011-12-15 11:31:51 -0500 | [diff] [blame] | 4533 | case SHELL_SURFACE_FULLSCREEN: |
Juan Zhao | 96879df | 2012-02-07 08:45:41 +0800 | [diff] [blame] | 4534 | case SHELL_SURFACE_MAXIMIZED: |
Daniel Stone | b210468 | 2012-05-30 16:31:56 +0100 | [diff] [blame] | 4535 | if (!shell->locked) { |
| 4536 | wl_list_for_each(seat, &compositor->seat_list, link) |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 4537 | activate(shell, shsurf->surface, seat); |
Daniel Stone | b210468 | 2012-05-30 16:31:56 +0100 | [diff] [blame] | 4538 | } |
Juan Zhao | 7bb92f0 | 2011-12-15 11:31:51 -0500 | [diff] [blame] | 4539 | break; |
Philip Withnall | 0f640e2 | 2013-11-25 18:01:31 +0000 | [diff] [blame] | 4540 | case SHELL_SURFACE_POPUP: |
| 4541 | case SHELL_SURFACE_NONE: |
Juan Zhao | 7bb92f0 | 2011-12-15 11:31:51 -0500 | [diff] [blame] | 4542 | default: |
| 4543 | break; |
| 4544 | } |
| 4545 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 4546 | if (shsurf->type == SHELL_SURFACE_TOPLEVEL) |
Juan Zhao | e10d279 | 2012-04-25 19:09:52 +0800 | [diff] [blame] | 4547 | { |
| 4548 | switch (shell->win_animation_type) { |
| 4549 | case ANIMATION_FADE: |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 4550 | 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] | 4551 | break; |
| 4552 | case ANIMATION_ZOOM: |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 4553 | weston_zoom_run(shsurf->view, 0.5, 1.0, NULL, NULL); |
Juan Zhao | e10d279 | 2012-04-25 19:09:52 +0800 | [diff] [blame] | 4554 | break; |
Philip Withnall | 4a86a0a | 2013-11-25 18:01:32 +0000 | [diff] [blame] | 4555 | case ANIMATION_NONE: |
Juan Zhao | e10d279 | 2012-04-25 19:09:52 +0800 | [diff] [blame] | 4556 | default: |
| 4557 | break; |
| 4558 | } |
| 4559 | } |
Kristian Høgsberg | 32e24cc | 2011-11-09 12:07:35 -0500 | [diff] [blame] | 4560 | } |
| 4561 | |
| 4562 | static void |
Tiago Vignatti | be14326 | 2012-04-16 17:31:41 +0300 | [diff] [blame] | 4563 | configure(struct desktop_shell *shell, struct weston_surface *surface, |
John Kåre Alsaker | 490d02a | 2012-09-30 02:57:21 +0200 | [diff] [blame] | 4564 | float x, float y, int32_t width, int32_t height) |
Kristian Høgsberg | 32e24cc | 2011-11-09 12:07:35 -0500 | [diff] [blame] | 4565 | { |
Pekka Paalanen | 77346a6 | 2011-11-30 16:26:35 +0200 | [diff] [blame] | 4566 | enum shell_surface_type surface_type = SHELL_SURFACE_NONE; |
| 4567 | struct shell_surface *shsurf; |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 4568 | struct weston_view *view; |
Giulio Camuffo | b836664 | 2013-04-25 13:57:46 +0300 | [diff] [blame] | 4569 | int32_t surf_x, surf_y; |
Kristian Høgsberg | 32e24cc | 2011-11-09 12:07:35 -0500 | [diff] [blame] | 4570 | |
Pekka Paalanen | 77346a6 | 2011-11-30 16:26:35 +0200 | [diff] [blame] | 4571 | shsurf = get_shell_surface(surface); |
| 4572 | if (shsurf) |
| 4573 | surface_type = shsurf->type; |
| 4574 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 4575 | /* TODO: |
| 4576 | * This should probably be changed to be more shell_surface |
| 4577 | * dependent |
| 4578 | */ |
| 4579 | wl_list_for_each(view, &surface->views, surface_link) |
| 4580 | weston_view_configure(view, x, y, width, height); |
Pekka Paalanen | 77346a6 | 2011-11-30 16:26:35 +0200 | [diff] [blame] | 4581 | |
| 4582 | switch (surface_type) { |
Alex Wu | 4539b08 | 2012-03-01 12:57:46 +0800 | [diff] [blame] | 4583 | case SHELL_SURFACE_FULLSCREEN: |
| 4584 | shell_configure_fullscreen(shsurf); |
Alex Wu | 4539b08 | 2012-03-01 12:57:46 +0800 | [diff] [blame] | 4585 | break; |
Juan Zhao | 96879df | 2012-02-07 08:45:41 +0800 | [diff] [blame] | 4586 | case SHELL_SURFACE_MAXIMIZED: |
Alex Wu | 4539b08 | 2012-03-01 12:57:46 +0800 | [diff] [blame] | 4587 | /* setting x, y and using configure to change that geometry */ |
Giulio Camuffo | b836664 | 2013-04-25 13:57:46 +0300 | [diff] [blame] | 4588 | surface_subsurfaces_boundingbox(shsurf->surface, &surf_x, &surf_y, |
| 4589 | NULL, NULL); |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 4590 | shsurf->view->geometry.x = shsurf->output->x - surf_x; |
| 4591 | shsurf->view->geometry.y = shsurf->output->y + |
| 4592 | get_output_panel_height(shell,shsurf->output) - surf_y; |
Juan Zhao | 96879df | 2012-02-07 08:45:41 +0800 | [diff] [blame] | 4593 | break; |
Alex Wu | 4539b08 | 2012-03-01 12:57:46 +0800 | [diff] [blame] | 4594 | case SHELL_SURFACE_TOPLEVEL: |
Philip Withnall | 0f640e2 | 2013-11-25 18:01:31 +0000 | [diff] [blame] | 4595 | case SHELL_SURFACE_TRANSIENT: |
| 4596 | case SHELL_SURFACE_POPUP: |
| 4597 | case SHELL_SURFACE_XWAYLAND: |
| 4598 | case SHELL_SURFACE_NONE: |
Kristian Høgsberg | d2abb83 | 2011-11-23 10:52:40 -0500 | [diff] [blame] | 4599 | default: |
| 4600 | break; |
Kristian Høgsberg | 7a5c979 | 2011-06-18 06:12:54 -0400 | [diff] [blame] | 4601 | } |
Kristian Høgsberg | 32e24cc | 2011-11-09 12:07:35 -0500 | [diff] [blame] | 4602 | |
Alex Wu | 4539b08 | 2012-03-01 12:57:46 +0800 | [diff] [blame] | 4603 | /* XXX: would a fullscreen surface need the same handling? */ |
Kristian Høgsberg | 6a8b553 | 2012-02-16 23:43:59 -0500 | [diff] [blame] | 4604 | if (surface->output) { |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 4605 | wl_list_for_each(view, &surface->views, surface_link) |
| 4606 | weston_view_update_transform(view); |
Pekka Paalanen | 77346a6 | 2011-11-30 16:26:35 +0200 | [diff] [blame] | 4607 | |
Kristian Høgsberg | 1a73a63 | 2012-06-26 22:15:53 -0400 | [diff] [blame] | 4608 | if (surface_type == SHELL_SURFACE_MAXIMIZED) |
Juan Zhao | 96879df | 2012-02-07 08:45:41 +0800 | [diff] [blame] | 4609 | surface->output = shsurf->output; |
Pekka Paalanen | 77346a6 | 2011-11-30 16:26:35 +0200 | [diff] [blame] | 4610 | } |
Kristian Høgsberg | 0793756 | 2011-04-12 17:25:42 -0400 | [diff] [blame] | 4611 | } |
| 4612 | |
Ander Conselvan de Oliveira | 093bfa3 | 2012-03-27 17:36:41 +0300 | [diff] [blame] | 4613 | static void |
Giulio Camuffo | 184df50 | 2013-02-21 11:29:21 +0100 | [diff] [blame] | 4614 | shell_surface_configure(struct weston_surface *es, int32_t sx, int32_t sy, int32_t width, int32_t height) |
Ander Conselvan de Oliveira | 093bfa3 | 2012-03-27 17:36:41 +0300 | [diff] [blame] | 4615 | { |
Ander Conselvan de Oliveira | 7fb9f95 | 2012-03-27 17:36:42 +0300 | [diff] [blame] | 4616 | struct shell_surface *shsurf = get_shell_surface(es); |
Tiago Vignatti | be14326 | 2012-04-16 17:31:41 +0300 | [diff] [blame] | 4617 | struct desktop_shell *shell = shsurf->shell; |
Giulio Camuffo | 184df50 | 2013-02-21 11:29:21 +0100 | [diff] [blame] | 4618 | |
Tiago Vignatti | 70e5c9c | 2012-05-07 15:23:07 +0300 | [diff] [blame] | 4619 | int type_changed = 0; |
Ander Conselvan de Oliveira | 093bfa3 | 2012-03-27 17:36:41 +0300 | [diff] [blame] | 4620 | |
Kristian Høgsberg | 8eb0f4f | 2013-06-17 10:33:14 -0400 | [diff] [blame] | 4621 | if (!weston_surface_is_mapped(es) && |
| 4622 | !wl_list_empty(&shsurf->popup.grab_link)) { |
Giulio Camuffo | 5085a75 | 2013-03-25 21:42:45 +0100 | [diff] [blame] | 4623 | remove_popup_grab(shsurf); |
| 4624 | } |
| 4625 | |
Giulio Camuffo | 184df50 | 2013-02-21 11:29:21 +0100 | [diff] [blame] | 4626 | if (width == 0) |
| 4627 | return; |
| 4628 | |
Kristian Høgsberg | 7f366e7 | 2012-04-27 17:20:01 -0400 | [diff] [blame] | 4629 | if (shsurf->next_type != SHELL_SURFACE_NONE && |
Kristian Høgsberg | f7e23d5 | 2012-04-27 17:51:59 -0400 | [diff] [blame] | 4630 | shsurf->type != shsurf->next_type) { |
Kristian Høgsberg | 7f366e7 | 2012-04-27 17:20:01 -0400 | [diff] [blame] | 4631 | set_surface_type(shsurf); |
Kristian Høgsberg | f7e23d5 | 2012-04-27 17:51:59 -0400 | [diff] [blame] | 4632 | type_changed = 1; |
| 4633 | } |
Kristian Høgsberg | 7f366e7 | 2012-04-27 17:20:01 -0400 | [diff] [blame] | 4634 | |
Ander Conselvan de Oliveira | 093bfa3 | 2012-03-27 17:36:41 +0300 | [diff] [blame] | 4635 | if (!weston_surface_is_mapped(es)) { |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 4636 | map(shell, shsurf, width, height, sx, sy); |
Kristian Høgsberg | f7e23d5 | 2012-04-27 17:51:59 -0400 | [diff] [blame] | 4637 | } else if (type_changed || sx != 0 || sy != 0 || |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 4638 | shsurf->view->geometry.width != width || |
| 4639 | shsurf->view->geometry.height != height) { |
John Kåre Alsaker | 490d02a | 2012-09-30 02:57:21 +0200 | [diff] [blame] | 4640 | float from_x, from_y; |
| 4641 | float to_x, to_y; |
Ander Conselvan de Oliveira | 093bfa3 | 2012-03-27 17:36:41 +0300 | [diff] [blame] | 4642 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 4643 | weston_view_to_global_float(shsurf->view, 0, 0, &from_x, &from_y); |
| 4644 | 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] | 4645 | configure(shell, es, |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 4646 | shsurf->view->geometry.x + to_x - from_x, |
| 4647 | shsurf->view->geometry.y + to_y - from_y, |
Ander Conselvan de Oliveira | 012b4c7 | 2012-11-27 17:03:42 +0200 | [diff] [blame] | 4648 | width, height); |
Ander Conselvan de Oliveira | 093bfa3 | 2012-03-27 17:36:41 +0300 | [diff] [blame] | 4649 | } |
| 4650 | } |
| 4651 | |
Tiago Vignatti | b7dbbd6 | 2012-09-25 17:57:01 +0300 | [diff] [blame] | 4652 | static void launch_desktop_shell_process(void *data); |
Pekka Paalanen | 4d733ee | 2012-01-17 14:36:27 +0200 | [diff] [blame] | 4653 | |
Kristian Høgsberg | 97d44aa | 2011-08-26 17:21:20 -0400 | [diff] [blame] | 4654 | static void |
Kristian Høgsberg | 8334bc1 | 2012-01-03 10:29:47 -0500 | [diff] [blame] | 4655 | desktop_shell_sigchld(struct weston_process *process, int status) |
Pekka Paalanen | 6cd281a | 2011-11-03 14:11:32 +0200 | [diff] [blame] | 4656 | { |
Pekka Paalanen | 4d733ee | 2012-01-17 14:36:27 +0200 | [diff] [blame] | 4657 | uint32_t time; |
Tiago Vignatti | be14326 | 2012-04-16 17:31:41 +0300 | [diff] [blame] | 4658 | struct desktop_shell *shell = |
| 4659 | container_of(process, struct desktop_shell, child.process); |
Pekka Paalanen | 6cd281a | 2011-11-03 14:11:32 +0200 | [diff] [blame] | 4660 | |
| 4661 | shell->child.process.pid = 0; |
| 4662 | shell->child.client = NULL; /* already destroyed by wayland */ |
Pekka Paalanen | 4d733ee | 2012-01-17 14:36:27 +0200 | [diff] [blame] | 4663 | |
| 4664 | /* if desktop-shell dies more than 5 times in 30 seconds, give up */ |
| 4665 | time = weston_compositor_get_time(); |
Kristian Høgsberg | f03a616 | 2012-01-17 11:07:42 -0500 | [diff] [blame] | 4666 | if (time - shell->child.deathstamp > 30000) { |
Pekka Paalanen | 4d733ee | 2012-01-17 14:36:27 +0200 | [diff] [blame] | 4667 | shell->child.deathstamp = time; |
| 4668 | shell->child.deathcount = 0; |
| 4669 | } |
| 4670 | |
| 4671 | shell->child.deathcount++; |
| 4672 | if (shell->child.deathcount > 5) { |
Emilio Pozuelo Monfort | 46ce798 | 2013-11-20 13:22:29 +0100 | [diff] [blame] | 4673 | weston_log("%s died, giving up.\n", shell->client); |
Pekka Paalanen | 4d733ee | 2012-01-17 14:36:27 +0200 | [diff] [blame] | 4674 | return; |
| 4675 | } |
| 4676 | |
Emilio Pozuelo Monfort | 46ce798 | 2013-11-20 13:22:29 +0100 | [diff] [blame] | 4677 | weston_log("%s died, respawning...\n", shell->client); |
Pekka Paalanen | 4d733ee | 2012-01-17 14:36:27 +0200 | [diff] [blame] | 4678 | launch_desktop_shell_process(shell); |
Pekka Paalanen | 79346ab | 2013-05-22 18:03:09 +0300 | [diff] [blame] | 4679 | shell_fade_startup(shell); |
Pekka Paalanen | 6cd281a | 2011-11-03 14:11:32 +0200 | [diff] [blame] | 4680 | } |
| 4681 | |
Tiago Vignatti | b7dbbd6 | 2012-09-25 17:57:01 +0300 | [diff] [blame] | 4682 | static void |
| 4683 | launch_desktop_shell_process(void *data) |
Pekka Paalanen | 6cd281a | 2011-11-03 14:11:32 +0200 | [diff] [blame] | 4684 | { |
Tiago Vignatti | b7dbbd6 | 2012-09-25 17:57:01 +0300 | [diff] [blame] | 4685 | struct desktop_shell *shell = data; |
Pekka Paalanen | 6cd281a | 2011-11-03 14:11:32 +0200 | [diff] [blame] | 4686 | |
Kristian Høgsberg | 8334bc1 | 2012-01-03 10:29:47 -0500 | [diff] [blame] | 4687 | shell->child.client = weston_client_launch(shell->compositor, |
Pekka Paalanen | 409ef0a | 2011-12-02 15:30:21 +0200 | [diff] [blame] | 4688 | &shell->child.process, |
Emilio Pozuelo Monfort | 46ce798 | 2013-11-20 13:22:29 +0100 | [diff] [blame] | 4689 | shell->client, |
Pekka Paalanen | 409ef0a | 2011-12-02 15:30:21 +0200 | [diff] [blame] | 4690 | desktop_shell_sigchld); |
| 4691 | |
| 4692 | if (!shell->child.client) |
Emilio Pozuelo Monfort | 46ce798 | 2013-11-20 13:22:29 +0100 | [diff] [blame] | 4693 | weston_log("not able to start %s\n", shell->client); |
Pekka Paalanen | 6cd281a | 2011-11-03 14:11:32 +0200 | [diff] [blame] | 4694 | } |
| 4695 | |
| 4696 | static void |
Kristian Høgsberg | 97d44aa | 2011-08-26 17:21:20 -0400 | [diff] [blame] | 4697 | bind_shell(struct wl_client *client, void *data, uint32_t version, uint32_t id) |
| 4698 | { |
Tiago Vignatti | be14326 | 2012-04-16 17:31:41 +0300 | [diff] [blame] | 4699 | struct desktop_shell *shell = data; |
Jason Ekstrand | a85118c | 2013-06-27 20:17:02 -0500 | [diff] [blame] | 4700 | struct wl_resource *resource; |
Kristian Høgsberg | 97d44aa | 2011-08-26 17:21:20 -0400 | [diff] [blame] | 4701 | |
Jason Ekstrand | a85118c | 2013-06-27 20:17:02 -0500 | [diff] [blame] | 4702 | resource = wl_resource_create(client, &wl_shell_interface, 1, id); |
| 4703 | if (resource) |
| 4704 | wl_resource_set_implementation(resource, &shell_implementation, |
| 4705 | shell, NULL); |
Kristian Høgsberg | 97d44aa | 2011-08-26 17:21:20 -0400 | [diff] [blame] | 4706 | } |
| 4707 | |
Kristian Høgsberg | 7584062 | 2011-09-06 13:48:16 -0400 | [diff] [blame] | 4708 | static void |
Pekka Paalanen | 9ef3e01 | 2011-11-15 13:34:48 +0200 | [diff] [blame] | 4709 | unbind_desktop_shell(struct wl_resource *resource) |
| 4710 | { |
Jason Ekstrand | 651f00e | 2013-06-14 10:07:54 -0500 | [diff] [blame] | 4711 | struct desktop_shell *shell = wl_resource_get_user_data(resource); |
Kristian Høgsberg | 1ec0c31 | 2011-11-15 16:39:55 -0500 | [diff] [blame] | 4712 | |
| 4713 | if (shell->locked) |
| 4714 | resume_desktop(shell); |
| 4715 | |
Pekka Paalanen | 9ef3e01 | 2011-11-15 13:34:48 +0200 | [diff] [blame] | 4716 | shell->child.desktop_shell = NULL; |
| 4717 | shell->prepare_event_sent = false; |
Pekka Paalanen | 9ef3e01 | 2011-11-15 13:34:48 +0200 | [diff] [blame] | 4718 | } |
| 4719 | |
| 4720 | static void |
Kristian Høgsberg | 7584062 | 2011-09-06 13:48:16 -0400 | [diff] [blame] | 4721 | bind_desktop_shell(struct wl_client *client, |
| 4722 | void *data, uint32_t version, uint32_t id) |
| 4723 | { |
Tiago Vignatti | be14326 | 2012-04-16 17:31:41 +0300 | [diff] [blame] | 4724 | struct desktop_shell *shell = data; |
Pekka Paalanen | bbe6052 | 2011-11-03 14:11:33 +0200 | [diff] [blame] | 4725 | struct wl_resource *resource; |
Kristian Høgsberg | 7584062 | 2011-09-06 13:48:16 -0400 | [diff] [blame] | 4726 | |
Jason Ekstrand | a85118c | 2013-06-27 20:17:02 -0500 | [diff] [blame] | 4727 | resource = wl_resource_create(client, &desktop_shell_interface, |
| 4728 | MIN(version, 2), id); |
Pekka Paalanen | bbe6052 | 2011-11-03 14:11:33 +0200 | [diff] [blame] | 4729 | |
Pekka Paalanen | 9ef3e01 | 2011-11-15 13:34:48 +0200 | [diff] [blame] | 4730 | if (client == shell->child.client) { |
Jason Ekstrand | a85118c | 2013-06-27 20:17:02 -0500 | [diff] [blame] | 4731 | wl_resource_set_implementation(resource, |
| 4732 | &desktop_shell_implementation, |
| 4733 | shell, unbind_desktop_shell); |
Pekka Paalanen | 9ef3e01 | 2011-11-15 13:34:48 +0200 | [diff] [blame] | 4734 | shell->child.desktop_shell = resource; |
Pekka Paalanen | 79346ab | 2013-05-22 18:03:09 +0300 | [diff] [blame] | 4735 | |
| 4736 | if (version < 2) |
| 4737 | shell_fade_startup(shell); |
| 4738 | |
Pekka Paalanen | bbe6052 | 2011-11-03 14:11:33 +0200 | [diff] [blame] | 4739 | return; |
Pekka Paalanen | 9ef3e01 | 2011-11-15 13:34:48 +0200 | [diff] [blame] | 4740 | } |
Pekka Paalanen | bbe6052 | 2011-11-03 14:11:33 +0200 | [diff] [blame] | 4741 | |
| 4742 | wl_resource_post_error(resource, WL_DISPLAY_ERROR_INVALID_OBJECT, |
| 4743 | "permission to bind desktop_shell denied"); |
Kristian Høgsberg | eae5de7 | 2012-04-11 22:42:15 -0400 | [diff] [blame] | 4744 | wl_resource_destroy(resource); |
Kristian Høgsberg | 7584062 | 2011-09-06 13:48:16 -0400 | [diff] [blame] | 4745 | } |
| 4746 | |
Pekka Paalanen | 6e16811 | 2011-11-24 11:34:05 +0200 | [diff] [blame] | 4747 | static void |
Giulio Camuffo | 184df50 | 2013-02-21 11:29:21 +0100 | [diff] [blame] | 4748 | screensaver_configure(struct weston_surface *surface, int32_t sx, int32_t sy, int32_t width, int32_t height) |
Kristian Høgsberg | 1a73a63 | 2012-06-26 22:15:53 -0400 | [diff] [blame] | 4749 | { |
Giulio Camuffo | 7fe01b1 | 2013-03-28 18:02:42 +0100 | [diff] [blame] | 4750 | struct desktop_shell *shell = surface->configure_private; |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 4751 | struct weston_view *view; |
Kristian Høgsberg | 1a73a63 | 2012-06-26 22:15:53 -0400 | [diff] [blame] | 4752 | |
Giulio Camuffo | 184df50 | 2013-02-21 11:29:21 +0100 | [diff] [blame] | 4753 | if (width == 0) |
| 4754 | return; |
| 4755 | |
Pekka Paalanen | 3a1d07d | 2012-12-20 14:02:13 +0200 | [diff] [blame] | 4756 | /* XXX: starting weston-screensaver beforehand does not work */ |
Kristian Høgsberg | 1a73a63 | 2012-06-26 22:15:53 -0400 | [diff] [blame] | 4757 | if (!shell->locked) |
| 4758 | return; |
| 4759 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 4760 | view = container_of(surface->views.next, struct weston_view, surface_link); |
| 4761 | center_on_output(view, surface->output); |
Kristian Høgsberg | 1a73a63 | 2012-06-26 22:15:53 -0400 | [diff] [blame] | 4762 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 4763 | if (wl_list_empty(&view->layer_link)) { |
| 4764 | wl_list_insert(shell->lock_layer.view_list.prev, |
| 4765 | &view->layer_link); |
| 4766 | weston_view_update_transform(view); |
Ander Conselvan de Oliveira | 859e885 | 2013-02-21 18:35:21 +0200 | [diff] [blame] | 4767 | wl_event_source_timer_update(shell->screensaver.timer, |
| 4768 | shell->screensaver.duration); |
Ander Conselvan de Oliveira | 19d10ef | 2013-02-21 18:35:20 +0200 | [diff] [blame] | 4769 | shell_fade(shell, FADE_IN); |
Kristian Høgsberg | 1a73a63 | 2012-06-26 22:15:53 -0400 | [diff] [blame] | 4770 | } |
| 4771 | } |
| 4772 | |
| 4773 | static void |
Pekka Paalanen | 6e16811 | 2011-11-24 11:34:05 +0200 | [diff] [blame] | 4774 | screensaver_set_surface(struct wl_client *client, |
| 4775 | struct wl_resource *resource, |
Kristian Høgsberg | 1a73a63 | 2012-06-26 22:15:53 -0400 | [diff] [blame] | 4776 | struct wl_resource *surface_resource, |
Pekka Paalanen | 6e16811 | 2011-11-24 11:34:05 +0200 | [diff] [blame] | 4777 | struct wl_resource *output_resource) |
| 4778 | { |
Jason Ekstrand | 651f00e | 2013-06-14 10:07:54 -0500 | [diff] [blame] | 4779 | struct desktop_shell *shell = wl_resource_get_user_data(resource); |
Jason Ekstrand | 0f2ef7e | 2013-06-14 10:07:53 -0500 | [diff] [blame] | 4780 | struct weston_surface *surface = |
| 4781 | wl_resource_get_user_data(surface_resource); |
Jason Ekstrand | a0d2dde | 2013-06-14 10:08:01 -0500 | [diff] [blame] | 4782 | struct weston_output *output = wl_resource_get_user_data(output_resource); |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 4783 | struct weston_view *view, *next; |
| 4784 | |
| 4785 | /* Make sure we only have one view */ |
| 4786 | wl_list_for_each_safe(view, next, &surface->views, surface_link) |
| 4787 | weston_view_destroy(view); |
| 4788 | weston_view_create(surface); |
Pekka Paalanen | 6e16811 | 2011-11-24 11:34:05 +0200 | [diff] [blame] | 4789 | |
Kristian Høgsberg | 1a73a63 | 2012-06-26 22:15:53 -0400 | [diff] [blame] | 4790 | surface->configure = screensaver_configure; |
Giulio Camuffo | 7fe01b1 | 2013-03-28 18:02:42 +0100 | [diff] [blame] | 4791 | surface->configure_private = shell; |
Pekka Paalanen | 77346a6 | 2011-11-30 16:26:35 +0200 | [diff] [blame] | 4792 | surface->output = output; |
Pekka Paalanen | 6e16811 | 2011-11-24 11:34:05 +0200 | [diff] [blame] | 4793 | } |
| 4794 | |
| 4795 | static const struct screensaver_interface screensaver_implementation = { |
| 4796 | screensaver_set_surface |
| 4797 | }; |
| 4798 | |
| 4799 | static void |
| 4800 | unbind_screensaver(struct wl_resource *resource) |
| 4801 | { |
Jason Ekstrand | 651f00e | 2013-06-14 10:07:54 -0500 | [diff] [blame] | 4802 | struct desktop_shell *shell = wl_resource_get_user_data(resource); |
Pekka Paalanen | 6e16811 | 2011-11-24 11:34:05 +0200 | [diff] [blame] | 4803 | |
Pekka Paalanen | 77346a6 | 2011-11-30 16:26:35 +0200 | [diff] [blame] | 4804 | shell->screensaver.binding = NULL; |
Pekka Paalanen | 6e16811 | 2011-11-24 11:34:05 +0200 | [diff] [blame] | 4805 | } |
| 4806 | |
| 4807 | static void |
| 4808 | bind_screensaver(struct wl_client *client, |
| 4809 | void *data, uint32_t version, uint32_t id) |
| 4810 | { |
Tiago Vignatti | be14326 | 2012-04-16 17:31:41 +0300 | [diff] [blame] | 4811 | struct desktop_shell *shell = data; |
Pekka Paalanen | 6e16811 | 2011-11-24 11:34:05 +0200 | [diff] [blame] | 4812 | struct wl_resource *resource; |
| 4813 | |
Jason Ekstrand | a85118c | 2013-06-27 20:17:02 -0500 | [diff] [blame] | 4814 | resource = wl_resource_create(client, &screensaver_interface, 1, id); |
Pekka Paalanen | 6e16811 | 2011-11-24 11:34:05 +0200 | [diff] [blame] | 4815 | |
Pekka Paalanen | 77346a6 | 2011-11-30 16:26:35 +0200 | [diff] [blame] | 4816 | if (shell->screensaver.binding == NULL) { |
Jason Ekstrand | a85118c | 2013-06-27 20:17:02 -0500 | [diff] [blame] | 4817 | wl_resource_set_implementation(resource, |
| 4818 | &screensaver_implementation, |
| 4819 | shell, unbind_screensaver); |
Pekka Paalanen | 77346a6 | 2011-11-30 16:26:35 +0200 | [diff] [blame] | 4820 | shell->screensaver.binding = resource; |
Pekka Paalanen | 6e16811 | 2011-11-24 11:34:05 +0200 | [diff] [blame] | 4821 | return; |
| 4822 | } |
| 4823 | |
| 4824 | wl_resource_post_error(resource, WL_DISPLAY_ERROR_INVALID_OBJECT, |
| 4825 | "interface object already bound"); |
Kristian Høgsberg | eae5de7 | 2012-04-11 22:42:15 -0400 | [diff] [blame] | 4826 | wl_resource_destroy(resource); |
Pekka Paalanen | 6e16811 | 2011-11-24 11:34:05 +0200 | [diff] [blame] | 4827 | } |
| 4828 | |
Jan Arne Petersen | 42feced | 2012-06-21 21:52:17 +0200 | [diff] [blame] | 4829 | static void |
Giulio Camuffo | 184df50 | 2013-02-21 11:29:21 +0100 | [diff] [blame] | 4830 | input_panel_configure(struct weston_surface *surface, int32_t sx, int32_t sy, int32_t width, int32_t height) |
Kristian Høgsberg | 0636ac3 | 2012-06-27 10:22:15 -0400 | [diff] [blame] | 4831 | { |
Jan Arne Petersen | 14da96b | 2013-04-18 16:47:28 +0200 | [diff] [blame] | 4832 | struct input_panel_surface *ip_surface = surface->configure_private; |
| 4833 | struct desktop_shell *shell = ip_surface->shell; |
Jan Arne Petersen | af7b6c9 | 2013-01-16 21:26:53 +0100 | [diff] [blame] | 4834 | float x, y; |
Jan Arne Petersen | 14da96b | 2013-04-18 16:47:28 +0200 | [diff] [blame] | 4835 | uint32_t show_surface = 0; |
Jan Arne Petersen | af7b6c9 | 2013-01-16 21:26:53 +0100 | [diff] [blame] | 4836 | |
Giulio Camuffo | 184df50 | 2013-02-21 11:29:21 +0100 | [diff] [blame] | 4837 | if (width == 0) |
| 4838 | return; |
| 4839 | |
Jan Arne Petersen | 14da96b | 2013-04-18 16:47:28 +0200 | [diff] [blame] | 4840 | if (!weston_surface_is_mapped(surface)) { |
| 4841 | if (!shell->showing_input_panels) |
| 4842 | return; |
| 4843 | |
Jan Arne Petersen | 14da96b | 2013-04-18 16:47:28 +0200 | [diff] [blame] | 4844 | show_surface = 1; |
| 4845 | } |
Jan Arne Petersen | af7b6c9 | 2013-01-16 21:26:53 +0100 | [diff] [blame] | 4846 | |
Jan Arne Petersen | 7cd29e1 | 2013-04-18 16:47:29 +0200 | [diff] [blame] | 4847 | 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] | 4848 | |
| 4849 | if (ip_surface->panel) { |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 4850 | x = get_default_view(shell->text_input.surface)->geometry.x + shell->text_input.cursor_rectangle.x2; |
| 4851 | 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] | 4852 | } else { |
Rob Bradford | bdeb5d2 | 2013-07-11 13:20:53 +0100 | [diff] [blame] | 4853 | x = ip_surface->output->x + (ip_surface->output->width - width) / 2; |
| 4854 | y = ip_surface->output->y + ip_surface->output->height - height; |
Jan Arne Petersen | 7cd29e1 | 2013-04-18 16:47:29 +0200 | [diff] [blame] | 4855 | } |
Kristian Høgsberg | 0636ac3 | 2012-06-27 10:22:15 -0400 | [diff] [blame] | 4856 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 4857 | weston_view_configure(ip_surface->view, x, y, width, height); |
Jan Arne Petersen | 14da96b | 2013-04-18 16:47:28 +0200 | [diff] [blame] | 4858 | |
| 4859 | if (show_surface) { |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 4860 | wl_list_insert(&shell->input_panel_layer.view_list, |
| 4861 | &ip_surface->view->layer_link); |
| 4862 | weston_view_update_transform(ip_surface->view); |
Jan Arne Petersen | 14da96b | 2013-04-18 16:47:28 +0200 | [diff] [blame] | 4863 | weston_surface_damage(surface); |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 4864 | weston_slide_run(ip_surface->view, ip_surface->view->geometry.height, 0, NULL, NULL); |
Jan Arne Petersen | 14da96b | 2013-04-18 16:47:28 +0200 | [diff] [blame] | 4865 | } |
Kristian Høgsberg | 0636ac3 | 2012-06-27 10:22:15 -0400 | [diff] [blame] | 4866 | } |
| 4867 | |
| 4868 | static void |
Jan Arne Petersen | ffbb20f | 2013-01-16 21:26:55 +0100 | [diff] [blame] | 4869 | destroy_input_panel_surface(struct input_panel_surface *input_panel_surface) |
Philipp Brüschweiler | 8801357 | 2012-08-06 13:44:42 +0200 | [diff] [blame] | 4870 | { |
Jason Ekstrand | 51e5b14 | 2013-06-14 10:07:58 -0500 | [diff] [blame] | 4871 | wl_signal_emit(&input_panel_surface->destroy_signal, input_panel_surface); |
| 4872 | |
Jan Arne Petersen | ffbb20f | 2013-01-16 21:26:55 +0100 | [diff] [blame] | 4873 | wl_list_remove(&input_panel_surface->surface_destroy_listener.link); |
Philipp Brüschweiler | 8801357 | 2012-08-06 13:44:42 +0200 | [diff] [blame] | 4874 | wl_list_remove(&input_panel_surface->link); |
| 4875 | |
Jan Arne Petersen | ffbb20f | 2013-01-16 21:26:55 +0100 | [diff] [blame] | 4876 | input_panel_surface->surface->configure = NULL; |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 4877 | weston_view_destroy(input_panel_surface->view); |
Jan Arne Petersen | ffbb20f | 2013-01-16 21:26:55 +0100 | [diff] [blame] | 4878 | |
Philipp Brüschweiler | 8801357 | 2012-08-06 13:44:42 +0200 | [diff] [blame] | 4879 | free(input_panel_surface); |
| 4880 | } |
| 4881 | |
Jan Arne Petersen | ffbb20f | 2013-01-16 21:26:55 +0100 | [diff] [blame] | 4882 | static struct input_panel_surface * |
| 4883 | get_input_panel_surface(struct weston_surface *surface) |
Jan Arne Petersen | 42feced | 2012-06-21 21:52:17 +0200 | [diff] [blame] | 4884 | { |
Jan Arne Petersen | ffbb20f | 2013-01-16 21:26:55 +0100 | [diff] [blame] | 4885 | if (surface->configure == input_panel_configure) { |
Giulio Camuffo | 7fe01b1 | 2013-03-28 18:02:42 +0100 | [diff] [blame] | 4886 | return surface->configure_private; |
Jan Arne Petersen | ffbb20f | 2013-01-16 21:26:55 +0100 | [diff] [blame] | 4887 | } else { |
| 4888 | return NULL; |
| 4889 | } |
| 4890 | } |
| 4891 | |
| 4892 | static void |
| 4893 | input_panel_handle_surface_destroy(struct wl_listener *listener, void *data) |
| 4894 | { |
| 4895 | struct input_panel_surface *ipsurface = container_of(listener, |
| 4896 | struct input_panel_surface, |
| 4897 | surface_destroy_listener); |
| 4898 | |
Jason Ekstrand | 51e5b14 | 2013-06-14 10:07:58 -0500 | [diff] [blame] | 4899 | if (ipsurface->resource) { |
| 4900 | wl_resource_destroy(ipsurface->resource); |
Jan Arne Petersen | ffbb20f | 2013-01-16 21:26:55 +0100 | [diff] [blame] | 4901 | } else { |
Jan Arne Petersen | ffbb20f | 2013-01-16 21:26:55 +0100 | [diff] [blame] | 4902 | destroy_input_panel_surface(ipsurface); |
| 4903 | } |
| 4904 | } |
Jason Ekstrand | 51e5b14 | 2013-06-14 10:07:58 -0500 | [diff] [blame] | 4905 | |
Jan Arne Petersen | ffbb20f | 2013-01-16 21:26:55 +0100 | [diff] [blame] | 4906 | static struct input_panel_surface * |
| 4907 | create_input_panel_surface(struct desktop_shell *shell, |
| 4908 | struct weston_surface *surface) |
| 4909 | { |
Philipp Brüschweiler | 8801357 | 2012-08-06 13:44:42 +0200 | [diff] [blame] | 4910 | struct input_panel_surface *input_panel_surface; |
Jan Arne Petersen | 42feced | 2012-06-21 21:52:17 +0200 | [diff] [blame] | 4911 | |
Jan Arne Petersen | ffbb20f | 2013-01-16 21:26:55 +0100 | [diff] [blame] | 4912 | input_panel_surface = calloc(1, sizeof *input_panel_surface); |
| 4913 | if (!input_panel_surface) |
| 4914 | return NULL; |
| 4915 | |
Kristian Høgsberg | 0636ac3 | 2012-06-27 10:22:15 -0400 | [diff] [blame] | 4916 | surface->configure = input_panel_configure; |
Giulio Camuffo | 7fe01b1 | 2013-03-28 18:02:42 +0100 | [diff] [blame] | 4917 | surface->configure_private = input_panel_surface; |
Philipp Brüschweiler | 8801357 | 2012-08-06 13:44:42 +0200 | [diff] [blame] | 4918 | |
Jan Arne Petersen | ffbb20f | 2013-01-16 21:26:55 +0100 | [diff] [blame] | 4919 | input_panel_surface->shell = shell; |
Philipp Brüschweiler | 8801357 | 2012-08-06 13:44:42 +0200 | [diff] [blame] | 4920 | |
| 4921 | input_panel_surface->surface = surface; |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 4922 | input_panel_surface->view = weston_view_create(surface); |
Philipp Brüschweiler | 8801357 | 2012-08-06 13:44:42 +0200 | [diff] [blame] | 4923 | |
Jason Ekstrand | 51e5b14 | 2013-06-14 10:07:58 -0500 | [diff] [blame] | 4924 | wl_signal_init(&input_panel_surface->destroy_signal); |
Jan Arne Petersen | ffbb20f | 2013-01-16 21:26:55 +0100 | [diff] [blame] | 4925 | input_panel_surface->surface_destroy_listener.notify = input_panel_handle_surface_destroy; |
Jason Ekstrand | 26ed73c | 2013-06-06 22:34:41 -0500 | [diff] [blame] | 4926 | wl_signal_add(&surface->destroy_signal, |
Jan Arne Petersen | ffbb20f | 2013-01-16 21:26:55 +0100 | [diff] [blame] | 4927 | &input_panel_surface->surface_destroy_listener); |
| 4928 | |
| 4929 | wl_list_init(&input_panel_surface->link); |
| 4930 | |
| 4931 | return input_panel_surface; |
| 4932 | } |
| 4933 | |
| 4934 | static void |
| 4935 | input_panel_surface_set_toplevel(struct wl_client *client, |
| 4936 | struct wl_resource *resource, |
Jan Arne Petersen | 7cd29e1 | 2013-04-18 16:47:29 +0200 | [diff] [blame] | 4937 | struct wl_resource *output_resource, |
Jan Arne Petersen | ffbb20f | 2013-01-16 21:26:55 +0100 | [diff] [blame] | 4938 | uint32_t position) |
| 4939 | { |
Jason Ekstrand | 51e5b14 | 2013-06-14 10:07:58 -0500 | [diff] [blame] | 4940 | struct input_panel_surface *input_panel_surface = |
| 4941 | wl_resource_get_user_data(resource); |
Jan Arne Petersen | ffbb20f | 2013-01-16 21:26:55 +0100 | [diff] [blame] | 4942 | struct desktop_shell *shell = input_panel_surface->shell; |
Philipp Brüschweiler | 8801357 | 2012-08-06 13:44:42 +0200 | [diff] [blame] | 4943 | |
| 4944 | wl_list_insert(&shell->input_panel.surfaces, |
| 4945 | &input_panel_surface->link); |
Jan Arne Petersen | 14da96b | 2013-04-18 16:47:28 +0200 | [diff] [blame] | 4946 | |
Jason Ekstrand | a0d2dde | 2013-06-14 10:08:01 -0500 | [diff] [blame] | 4947 | input_panel_surface->output = wl_resource_get_user_data(output_resource); |
Jan Arne Petersen | 14da96b | 2013-04-18 16:47:28 +0200 | [diff] [blame] | 4948 | input_panel_surface->panel = 0; |
| 4949 | } |
| 4950 | |
| 4951 | static void |
Jan Arne Petersen | 70d942b | 2013-04-18 16:47:37 +0200 | [diff] [blame] | 4952 | input_panel_surface_set_overlay_panel(struct wl_client *client, |
| 4953 | struct wl_resource *resource) |
Jan Arne Petersen | 14da96b | 2013-04-18 16:47:28 +0200 | [diff] [blame] | 4954 | { |
Jason Ekstrand | 51e5b14 | 2013-06-14 10:07:58 -0500 | [diff] [blame] | 4955 | struct input_panel_surface *input_panel_surface = |
| 4956 | wl_resource_get_user_data(resource); |
Jan Arne Petersen | 14da96b | 2013-04-18 16:47:28 +0200 | [diff] [blame] | 4957 | struct desktop_shell *shell = input_panel_surface->shell; |
| 4958 | |
| 4959 | wl_list_insert(&shell->input_panel.surfaces, |
| 4960 | &input_panel_surface->link); |
| 4961 | |
| 4962 | input_panel_surface->panel = 1; |
Jan Arne Petersen | 42feced | 2012-06-21 21:52:17 +0200 | [diff] [blame] | 4963 | } |
| 4964 | |
Jan Arne Petersen | cc75ec1 | 2013-04-18 16:47:39 +0200 | [diff] [blame] | 4965 | 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] | 4966 | input_panel_surface_set_toplevel, |
Jan Arne Petersen | 70d942b | 2013-04-18 16:47:37 +0200 | [diff] [blame] | 4967 | input_panel_surface_set_overlay_panel |
Jan Arne Petersen | ffbb20f | 2013-01-16 21:26:55 +0100 | [diff] [blame] | 4968 | }; |
| 4969 | |
| 4970 | static void |
| 4971 | destroy_input_panel_surface_resource(struct wl_resource *resource) |
| 4972 | { |
Jason Ekstrand | 51e5b14 | 2013-06-14 10:07:58 -0500 | [diff] [blame] | 4973 | struct input_panel_surface *ipsurf = |
| 4974 | wl_resource_get_user_data(resource); |
Jan Arne Petersen | ffbb20f | 2013-01-16 21:26:55 +0100 | [diff] [blame] | 4975 | |
| 4976 | destroy_input_panel_surface(ipsurf); |
| 4977 | } |
| 4978 | |
| 4979 | static void |
| 4980 | input_panel_get_input_panel_surface(struct wl_client *client, |
| 4981 | struct wl_resource *resource, |
| 4982 | uint32_t id, |
| 4983 | struct wl_resource *surface_resource) |
| 4984 | { |
Jason Ekstrand | 0f2ef7e | 2013-06-14 10:07:53 -0500 | [diff] [blame] | 4985 | struct weston_surface *surface = |
| 4986 | wl_resource_get_user_data(surface_resource); |
Jason Ekstrand | 651f00e | 2013-06-14 10:07:54 -0500 | [diff] [blame] | 4987 | struct desktop_shell *shell = wl_resource_get_user_data(resource); |
Jan Arne Petersen | ffbb20f | 2013-01-16 21:26:55 +0100 | [diff] [blame] | 4988 | struct input_panel_surface *ipsurf; |
| 4989 | |
| 4990 | if (get_input_panel_surface(surface)) { |
| 4991 | wl_resource_post_error(surface_resource, |
| 4992 | WL_DISPLAY_ERROR_INVALID_OBJECT, |
Jan Arne Petersen | cc75ec1 | 2013-04-18 16:47:39 +0200 | [diff] [blame] | 4993 | "wl_input_panel::get_input_panel_surface already requested"); |
Jan Arne Petersen | ffbb20f | 2013-01-16 21:26:55 +0100 | [diff] [blame] | 4994 | return; |
| 4995 | } |
| 4996 | |
| 4997 | ipsurf = create_input_panel_surface(shell, surface); |
| 4998 | if (!ipsurf) { |
| 4999 | wl_resource_post_error(surface_resource, |
| 5000 | WL_DISPLAY_ERROR_INVALID_OBJECT, |
| 5001 | "surface->configure already set"); |
| 5002 | return; |
| 5003 | } |
| 5004 | |
Jason Ekstrand | a85118c | 2013-06-27 20:17:02 -0500 | [diff] [blame] | 5005 | ipsurf->resource = |
| 5006 | wl_resource_create(client, |
| 5007 | &wl_input_panel_surface_interface, 1, id); |
| 5008 | wl_resource_set_implementation(ipsurf->resource, |
| 5009 | &input_panel_surface_implementation, |
| 5010 | ipsurf, |
| 5011 | destroy_input_panel_surface_resource); |
Jan Arne Petersen | ffbb20f | 2013-01-16 21:26:55 +0100 | [diff] [blame] | 5012 | } |
| 5013 | |
Jan Arne Petersen | cc75ec1 | 2013-04-18 16:47:39 +0200 | [diff] [blame] | 5014 | static const struct wl_input_panel_interface input_panel_implementation = { |
Jan Arne Petersen | ffbb20f | 2013-01-16 21:26:55 +0100 | [diff] [blame] | 5015 | input_panel_get_input_panel_surface |
Jan Arne Petersen | 42feced | 2012-06-21 21:52:17 +0200 | [diff] [blame] | 5016 | }; |
| 5017 | |
| 5018 | static void |
| 5019 | unbind_input_panel(struct wl_resource *resource) |
| 5020 | { |
Jason Ekstrand | 651f00e | 2013-06-14 10:07:54 -0500 | [diff] [blame] | 5021 | struct desktop_shell *shell = wl_resource_get_user_data(resource); |
Jan Arne Petersen | 42feced | 2012-06-21 21:52:17 +0200 | [diff] [blame] | 5022 | |
| 5023 | shell->input_panel.binding = NULL; |
Jan Arne Petersen | 42feced | 2012-06-21 21:52:17 +0200 | [diff] [blame] | 5024 | } |
| 5025 | |
| 5026 | static void |
| 5027 | bind_input_panel(struct wl_client *client, |
| 5028 | void *data, uint32_t version, uint32_t id) |
| 5029 | { |
| 5030 | struct desktop_shell *shell = data; |
| 5031 | struct wl_resource *resource; |
| 5032 | |
Jason Ekstrand | a85118c | 2013-06-27 20:17:02 -0500 | [diff] [blame] | 5033 | resource = wl_resource_create(client, |
| 5034 | &wl_input_panel_interface, 1, id); |
Jan Arne Petersen | 42feced | 2012-06-21 21:52:17 +0200 | [diff] [blame] | 5035 | |
| 5036 | if (shell->input_panel.binding == NULL) { |
Jason Ekstrand | a85118c | 2013-06-27 20:17:02 -0500 | [diff] [blame] | 5037 | wl_resource_set_implementation(resource, |
| 5038 | &input_panel_implementation, |
| 5039 | shell, unbind_input_panel); |
Jan Arne Petersen | 42feced | 2012-06-21 21:52:17 +0200 | [diff] [blame] | 5040 | shell->input_panel.binding = resource; |
| 5041 | return; |
| 5042 | } |
| 5043 | |
| 5044 | wl_resource_post_error(resource, WL_DISPLAY_ERROR_INVALID_OBJECT, |
| 5045 | "interface object already bound"); |
| 5046 | wl_resource_destroy(resource); |
| 5047 | } |
| 5048 | |
Kristian Høgsberg | 0704539 | 2012-02-19 18:52:44 -0500 | [diff] [blame] | 5049 | struct switcher { |
Tiago Vignatti | be14326 | 2012-04-16 17:31:41 +0300 | [diff] [blame] | 5050 | struct desktop_shell *shell; |
Kristian Høgsberg | 0704539 | 2012-02-19 18:52:44 -0500 | [diff] [blame] | 5051 | struct weston_surface *current; |
| 5052 | struct wl_listener listener; |
Kristian Høgsberg | 29139d4 | 2013-04-18 15:25:39 -0400 | [diff] [blame] | 5053 | struct weston_keyboard_grab grab; |
Kristian Høgsberg | 0704539 | 2012-02-19 18:52:44 -0500 | [diff] [blame] | 5054 | }; |
| 5055 | |
| 5056 | static void |
| 5057 | switcher_next(struct switcher *switcher) |
| 5058 | { |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 5059 | struct weston_view *view; |
Kristian Høgsberg | 0704539 | 2012-02-19 18:52:44 -0500 | [diff] [blame] | 5060 | struct weston_surface *first = NULL, *prev = NULL, *next = NULL; |
Kristian Høgsberg | 32e5686 | 2012-04-02 22:18:58 -0400 | [diff] [blame] | 5061 | struct shell_surface *shsurf; |
Kristian Høgsberg | b0d8e77 | 2012-06-18 16:34:58 -0400 | [diff] [blame] | 5062 | struct workspace *ws = get_current_workspace(switcher->shell); |
Kristian Høgsberg | 0704539 | 2012-02-19 18:52:44 -0500 | [diff] [blame] | 5063 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 5064 | wl_list_for_each(view, &ws->layer.view_list, layer_link) { |
| 5065 | switch (get_shell_surface_type(view->surface)) { |
Kristian Høgsberg | 0704539 | 2012-02-19 18:52:44 -0500 | [diff] [blame] | 5066 | case SHELL_SURFACE_TOPLEVEL: |
| 5067 | case SHELL_SURFACE_FULLSCREEN: |
| 5068 | case SHELL_SURFACE_MAXIMIZED: |
| 5069 | if (first == NULL) |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 5070 | first = view->surface; |
Kristian Høgsberg | 0704539 | 2012-02-19 18:52:44 -0500 | [diff] [blame] | 5071 | if (prev == switcher->current) |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 5072 | next = view->surface; |
| 5073 | prev = view->surface; |
| 5074 | view->alpha = 0.25; |
| 5075 | weston_view_geometry_dirty(view); |
| 5076 | weston_surface_damage(view->surface); |
Kristian Høgsberg | 0704539 | 2012-02-19 18:52:44 -0500 | [diff] [blame] | 5077 | break; |
Philip Withnall | 0f640e2 | 2013-11-25 18:01:31 +0000 | [diff] [blame] | 5078 | case SHELL_SURFACE_TRANSIENT: |
| 5079 | case SHELL_SURFACE_POPUP: |
| 5080 | case SHELL_SURFACE_XWAYLAND: |
| 5081 | case SHELL_SURFACE_NONE: |
Kristian Høgsberg | 0704539 | 2012-02-19 18:52:44 -0500 | [diff] [blame] | 5082 | default: |
| 5083 | break; |
| 5084 | } |
Alex Wu | 1659daa | 2012-04-01 20:13:09 +0800 | [diff] [blame] | 5085 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 5086 | if (is_black_surface(view->surface, NULL)) { |
| 5087 | view->alpha = 0.25; |
| 5088 | weston_view_geometry_dirty(view); |
| 5089 | weston_surface_damage(view->surface); |
Alex Wu | 1659daa | 2012-04-01 20:13:09 +0800 | [diff] [blame] | 5090 | } |
Kristian Høgsberg | 0704539 | 2012-02-19 18:52:44 -0500 | [diff] [blame] | 5091 | } |
| 5092 | |
| 5093 | if (next == NULL) |
| 5094 | next = first; |
| 5095 | |
Alex Wu | 07b2606 | 2012-03-12 16:06:01 +0800 | [diff] [blame] | 5096 | if (next == NULL) |
| 5097 | return; |
| 5098 | |
Kristian Høgsberg | 0704539 | 2012-02-19 18:52:44 -0500 | [diff] [blame] | 5099 | wl_list_remove(&switcher->listener.link); |
Jason Ekstrand | 26ed73c | 2013-06-06 22:34:41 -0500 | [diff] [blame] | 5100 | wl_signal_add(&next->destroy_signal, &switcher->listener); |
Kristian Høgsberg | 0704539 | 2012-02-19 18:52:44 -0500 | [diff] [blame] | 5101 | |
| 5102 | switcher->current = next; |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 5103 | wl_list_for_each(view, &next->views, surface_link) |
| 5104 | view->alpha = 1.0; |
Alex Wu | 1659daa | 2012-04-01 20:13:09 +0800 | [diff] [blame] | 5105 | |
Kristian Høgsberg | 32e5686 | 2012-04-02 22:18:58 -0400 | [diff] [blame] | 5106 | shsurf = get_shell_surface(switcher->current); |
| 5107 | if (shsurf && shsurf->type ==SHELL_SURFACE_FULLSCREEN) |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 5108 | shsurf->fullscreen.black_view->alpha = 1.0; |
Kristian Høgsberg | 0704539 | 2012-02-19 18:52:44 -0500 | [diff] [blame] | 5109 | } |
| 5110 | |
| 5111 | static void |
Kristian Høgsberg | 27e3052 | 2012-04-11 23:18:23 -0400 | [diff] [blame] | 5112 | switcher_handle_surface_destroy(struct wl_listener *listener, void *data) |
Kristian Høgsberg | 0704539 | 2012-02-19 18:52:44 -0500 | [diff] [blame] | 5113 | { |
| 5114 | struct switcher *switcher = |
| 5115 | container_of(listener, struct switcher, listener); |
| 5116 | |
| 5117 | switcher_next(switcher); |
| 5118 | } |
| 5119 | |
| 5120 | static void |
Daniel Stone | 351eb61 | 2012-05-31 15:27:47 -0400 | [diff] [blame] | 5121 | switcher_destroy(struct switcher *switcher) |
Kristian Høgsberg | 0704539 | 2012-02-19 18:52:44 -0500 | [diff] [blame] | 5122 | { |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 5123 | struct weston_view *view; |
Kristian Høgsberg | 29139d4 | 2013-04-18 15:25:39 -0400 | [diff] [blame] | 5124 | struct weston_keyboard *keyboard = switcher->grab.keyboard; |
Kristian Høgsberg | b0d8e77 | 2012-06-18 16:34:58 -0400 | [diff] [blame] | 5125 | struct workspace *ws = get_current_workspace(switcher->shell); |
Kristian Høgsberg | 0704539 | 2012-02-19 18:52:44 -0500 | [diff] [blame] | 5126 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 5127 | 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] | 5128 | if (is_focus_view(view)) |
| 5129 | continue; |
| 5130 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 5131 | view->alpha = 1.0; |
| 5132 | weston_surface_damage(view->surface); |
Kristian Høgsberg | 0704539 | 2012-02-19 18:52:44 -0500 | [diff] [blame] | 5133 | } |
| 5134 | |
Alex Wu | 07b2606 | 2012-03-12 16:06:01 +0800 | [diff] [blame] | 5135 | if (switcher->current) |
Daniel Stone | 37816df | 2012-05-16 18:45:18 +0100 | [diff] [blame] | 5136 | activate(switcher->shell, switcher->current, |
| 5137 | (struct weston_seat *) keyboard->seat); |
Kristian Høgsberg | 0704539 | 2012-02-19 18:52:44 -0500 | [diff] [blame] | 5138 | wl_list_remove(&switcher->listener.link); |
Kristian Høgsberg | 29139d4 | 2013-04-18 15:25:39 -0400 | [diff] [blame] | 5139 | weston_keyboard_end_grab(keyboard); |
| 5140 | if (keyboard->input_method_resource) |
| 5141 | keyboard->grab = &keyboard->input_method_grab; |
Kristian Høgsberg | 0704539 | 2012-02-19 18:52:44 -0500 | [diff] [blame] | 5142 | free(switcher); |
| 5143 | } |
| 5144 | |
| 5145 | static void |
Kristian Høgsberg | 29139d4 | 2013-04-18 15:25:39 -0400 | [diff] [blame] | 5146 | switcher_key(struct weston_keyboard_grab *grab, |
Daniel Stone | c9785ea | 2012-05-30 16:31:52 +0100 | [diff] [blame] | 5147 | uint32_t time, uint32_t key, uint32_t state_w) |
Kristian Høgsberg | 0704539 | 2012-02-19 18:52:44 -0500 | [diff] [blame] | 5148 | { |
| 5149 | struct switcher *switcher = container_of(grab, struct switcher, grab); |
Daniel Stone | c9785ea | 2012-05-30 16:31:52 +0100 | [diff] [blame] | 5150 | enum wl_keyboard_key_state state = state_w; |
Daniel Stone | 351eb61 | 2012-05-31 15:27:47 -0400 | [diff] [blame] | 5151 | |
Daniel Stone | c9785ea | 2012-05-30 16:31:52 +0100 | [diff] [blame] | 5152 | if (key == KEY_TAB && state == WL_KEYBOARD_KEY_STATE_PRESSED) |
Daniel Stone | 351eb61 | 2012-05-31 15:27:47 -0400 | [diff] [blame] | 5153 | switcher_next(switcher); |
| 5154 | } |
| 5155 | |
| 5156 | static void |
Kristian Høgsberg | 29139d4 | 2013-04-18 15:25:39 -0400 | [diff] [blame] | 5157 | switcher_modifier(struct weston_keyboard_grab *grab, uint32_t serial, |
Daniel Stone | 351eb61 | 2012-05-31 15:27:47 -0400 | [diff] [blame] | 5158 | uint32_t mods_depressed, uint32_t mods_latched, |
| 5159 | uint32_t mods_locked, uint32_t group) |
| 5160 | { |
| 5161 | struct switcher *switcher = container_of(grab, struct switcher, grab); |
Daniel Stone | 37816df | 2012-05-16 18:45:18 +0100 | [diff] [blame] | 5162 | struct weston_seat *seat = (struct weston_seat *) grab->keyboard->seat; |
Kristian Høgsberg | 0704539 | 2012-02-19 18:52:44 -0500 | [diff] [blame] | 5163 | |
Daniel Stone | 351eb61 | 2012-05-31 15:27:47 -0400 | [diff] [blame] | 5164 | if ((seat->modifier_state & switcher->shell->binding_modifier) == 0) |
| 5165 | switcher_destroy(switcher); |
Kristian Høgsberg | b71302e | 2012-05-10 12:28:35 -0400 | [diff] [blame] | 5166 | } |
Kristian Høgsberg | 0704539 | 2012-02-19 18:52:44 -0500 | [diff] [blame] | 5167 | |
Jonas Ådahl | 1ea343e | 2013-10-25 23:18:05 +0200 | [diff] [blame] | 5168 | static void |
| 5169 | switcher_cancel(struct weston_keyboard_grab *grab) |
| 5170 | { |
| 5171 | struct switcher *switcher = container_of(grab, struct switcher, grab); |
| 5172 | |
| 5173 | switcher_destroy(switcher); |
| 5174 | } |
| 5175 | |
Kristian Høgsberg | 29139d4 | 2013-04-18 15:25:39 -0400 | [diff] [blame] | 5176 | static const struct weston_keyboard_grab_interface switcher_grab = { |
Daniel Stone | 351eb61 | 2012-05-31 15:27:47 -0400 | [diff] [blame] | 5177 | switcher_key, |
| 5178 | switcher_modifier, |
Jonas Ådahl | 1ea343e | 2013-10-25 23:18:05 +0200 | [diff] [blame] | 5179 | switcher_cancel, |
Kristian Høgsberg | 0704539 | 2012-02-19 18:52:44 -0500 | [diff] [blame] | 5180 | }; |
| 5181 | |
| 5182 | static void |
Kristian Høgsberg | e314875 | 2013-05-06 23:19:49 -0400 | [diff] [blame] | 5183 | switcher_binding(struct weston_seat *seat, uint32_t time, uint32_t key, |
Daniel Stone | 325fc2d | 2012-05-30 16:31:58 +0100 | [diff] [blame] | 5184 | void *data) |
Kristian Høgsberg | 0704539 | 2012-02-19 18:52:44 -0500 | [diff] [blame] | 5185 | { |
Tiago Vignatti | be14326 | 2012-04-16 17:31:41 +0300 | [diff] [blame] | 5186 | struct desktop_shell *shell = data; |
Kristian Høgsberg | 0704539 | 2012-02-19 18:52:44 -0500 | [diff] [blame] | 5187 | struct switcher *switcher; |
| 5188 | |
| 5189 | switcher = malloc(sizeof *switcher); |
Kristian Høgsberg | 02e79dc | 2012-04-12 09:55:26 -0400 | [diff] [blame] | 5190 | switcher->shell = shell; |
Kristian Høgsberg | 0704539 | 2012-02-19 18:52:44 -0500 | [diff] [blame] | 5191 | switcher->current = NULL; |
Kristian Høgsberg | 27e3052 | 2012-04-11 23:18:23 -0400 | [diff] [blame] | 5192 | switcher->listener.notify = switcher_handle_surface_destroy; |
Kristian Høgsberg | 0704539 | 2012-02-19 18:52:44 -0500 | [diff] [blame] | 5193 | wl_list_init(&switcher->listener.link); |
| 5194 | |
Alexander Larsson | f82b6ca | 2013-05-28 16:23:39 +0200 | [diff] [blame] | 5195 | restore_all_output_modes(shell->compositor); |
Kristian Høgsberg | b0d8e77 | 2012-06-18 16:34:58 -0400 | [diff] [blame] | 5196 | lower_fullscreen_layer(switcher->shell); |
Kristian Høgsberg | 0704539 | 2012-02-19 18:52:44 -0500 | [diff] [blame] | 5197 | switcher->grab.interface = &switcher_grab; |
Kristian Høgsberg | 29139d4 | 2013-04-18 15:25:39 -0400 | [diff] [blame] | 5198 | weston_keyboard_start_grab(seat->keyboard, &switcher->grab); |
| 5199 | weston_keyboard_set_focus(seat->keyboard, NULL); |
Kristian Høgsberg | 0704539 | 2012-02-19 18:52:44 -0500 | [diff] [blame] | 5200 | switcher_next(switcher); |
| 5201 | } |
| 5202 | |
Daniel Stone | df8133b | 2013-11-19 11:37:14 +0100 | [diff] [blame] | 5203 | struct exposay_surface { |
| 5204 | struct desktop_shell *shell; |
| 5205 | struct weston_surface *surface; |
| 5206 | struct weston_view *view; |
| 5207 | struct wl_list link; |
| 5208 | |
| 5209 | int x; |
| 5210 | int y; |
| 5211 | int width; |
| 5212 | int height; |
| 5213 | double scale; |
| 5214 | |
| 5215 | int row; |
| 5216 | int column; |
| 5217 | |
| 5218 | /* The animations only apply a transformation for their own lifetime, |
| 5219 | * and don't have an option to indefinitely maintain the |
| 5220 | * transformation in a steady state - so, we apply our own once the |
| 5221 | * animation has finished. */ |
| 5222 | struct weston_transform transform; |
| 5223 | }; |
| 5224 | |
| 5225 | static void exposay_set_state(struct desktop_shell *shell, |
| 5226 | enum exposay_target_state state, |
| 5227 | struct weston_seat *seat); |
| 5228 | static void exposay_check_state(struct desktop_shell *shell); |
| 5229 | |
| 5230 | static void |
| 5231 | exposay_in_flight_inc(struct desktop_shell *shell) |
| 5232 | { |
| 5233 | shell->exposay.in_flight++; |
| 5234 | } |
| 5235 | |
| 5236 | static void |
| 5237 | exposay_in_flight_dec(struct desktop_shell *shell) |
| 5238 | { |
| 5239 | if (--shell->exposay.in_flight > 0) |
| 5240 | return; |
| 5241 | |
| 5242 | exposay_check_state(shell); |
| 5243 | } |
| 5244 | |
| 5245 | static void |
| 5246 | exposay_animate_in_done(struct weston_view_animation *animation, void *data) |
| 5247 | { |
| 5248 | struct exposay_surface *esurface = data; |
| 5249 | |
| 5250 | wl_list_insert(&esurface->view->geometry.transformation_list, |
| 5251 | &esurface->transform.link); |
| 5252 | weston_matrix_init(&esurface->transform.matrix); |
| 5253 | weston_matrix_scale(&esurface->transform.matrix, |
| 5254 | esurface->scale, esurface->scale, 1.0f); |
| 5255 | weston_matrix_translate(&esurface->transform.matrix, |
| 5256 | esurface->x - esurface->view->geometry.x, |
| 5257 | esurface->y - esurface->view->geometry.y, |
| 5258 | 0); |
| 5259 | |
| 5260 | weston_view_geometry_dirty(esurface->view); |
| 5261 | weston_compositor_schedule_repaint(esurface->view->surface->compositor); |
| 5262 | |
| 5263 | exposay_in_flight_dec(esurface->shell); |
| 5264 | } |
| 5265 | |
| 5266 | static void |
| 5267 | exposay_animate_in(struct exposay_surface *esurface) |
| 5268 | { |
| 5269 | exposay_in_flight_inc(esurface->shell); |
| 5270 | |
| 5271 | weston_move_scale_run(esurface->view, |
| 5272 | esurface->x - esurface->view->geometry.x, |
| 5273 | esurface->y - esurface->view->geometry.y, |
| 5274 | 1.0, esurface->scale, 0, |
| 5275 | exposay_animate_in_done, esurface); |
| 5276 | } |
| 5277 | |
| 5278 | static void |
| 5279 | exposay_animate_out_done(struct weston_view_animation *animation, void *data) |
| 5280 | { |
| 5281 | struct exposay_surface *esurface = data; |
| 5282 | struct desktop_shell *shell = esurface->shell; |
| 5283 | |
| 5284 | wl_list_remove(&esurface->link); |
| 5285 | free(esurface); |
| 5286 | |
| 5287 | exposay_in_flight_dec(shell); |
| 5288 | } |
| 5289 | |
| 5290 | static void |
| 5291 | exposay_animate_out(struct exposay_surface *esurface) |
| 5292 | { |
| 5293 | exposay_in_flight_inc(esurface->shell); |
| 5294 | |
| 5295 | /* Remove the static transformation set up by |
| 5296 | * exposay_transform_in_done(). */ |
| 5297 | wl_list_remove(&esurface->transform.link); |
| 5298 | weston_view_geometry_dirty(esurface->view); |
| 5299 | |
| 5300 | weston_move_scale_run(esurface->view, |
| 5301 | esurface->x - esurface->view->geometry.x, |
| 5302 | esurface->y - esurface->view->geometry.y, |
| 5303 | 1.0, esurface->scale, 1, |
| 5304 | exposay_animate_out_done, esurface); |
| 5305 | } |
| 5306 | |
| 5307 | static void |
| 5308 | exposay_highlight_surface(struct desktop_shell *shell, |
| 5309 | struct exposay_surface *esurface) |
| 5310 | { |
| 5311 | struct weston_view *view = NULL; |
| 5312 | |
| 5313 | if (esurface) { |
| 5314 | shell->exposay.row_current = esurface->row; |
| 5315 | shell->exposay.column_current = esurface->column; |
| 5316 | view = esurface->view; |
| 5317 | } |
| 5318 | |
Emilio Pozuelo Monfort | 5c22ce6 | 2013-11-19 11:37:18 +0100 | [diff] [blame] | 5319 | activate(shell, view->surface, shell->exposay.seat); |
Daniel Stone | df8133b | 2013-11-19 11:37:14 +0100 | [diff] [blame] | 5320 | shell->exposay.focus_current = view; |
| 5321 | } |
| 5322 | |
| 5323 | static int |
| 5324 | exposay_is_animating(struct desktop_shell *shell) |
| 5325 | { |
| 5326 | if (shell->exposay.state_cur == EXPOSAY_LAYOUT_INACTIVE || |
| 5327 | shell->exposay.state_cur == EXPOSAY_LAYOUT_OVERVIEW) |
| 5328 | return 0; |
| 5329 | |
| 5330 | return (shell->exposay.in_flight > 0); |
| 5331 | } |
| 5332 | |
| 5333 | static void |
| 5334 | exposay_pick(struct desktop_shell *shell, int x, int y) |
| 5335 | { |
| 5336 | struct exposay_surface *esurface; |
| 5337 | |
| 5338 | if (exposay_is_animating(shell)) |
| 5339 | return; |
| 5340 | |
| 5341 | wl_list_for_each(esurface, &shell->exposay.surface_list, link) { |
| 5342 | if (x < esurface->x || x > esurface->x + esurface->width) |
| 5343 | continue; |
| 5344 | if (y < esurface->y || y > esurface->y + esurface->height) |
| 5345 | continue; |
| 5346 | |
| 5347 | exposay_highlight_surface(shell, esurface); |
| 5348 | return; |
| 5349 | } |
| 5350 | } |
| 5351 | |
| 5352 | /* Pretty lame layout for now; just tries to make a square. Should take |
| 5353 | * aspect ratio into account really. Also needs to be notified of surface |
| 5354 | * addition and removal and adjust layout/animate accordingly. */ |
| 5355 | static enum exposay_layout_state |
| 5356 | exposay_layout(struct desktop_shell *shell) |
| 5357 | { |
| 5358 | struct workspace *workspace = shell->exposay.workspace; |
| 5359 | struct weston_compositor *compositor = shell->compositor; |
| 5360 | struct weston_output *output = get_default_output(compositor); |
| 5361 | struct weston_view *view; |
| 5362 | struct exposay_surface *esurface; |
| 5363 | int w, h; |
| 5364 | int i; |
| 5365 | int last_row_removed = 0; |
| 5366 | |
| 5367 | wl_list_init(&shell->exposay.surface_list); |
| 5368 | |
| 5369 | shell->exposay.num_surfaces = 0; |
| 5370 | wl_list_for_each(view, &workspace->layer.view_list, layer_link) { |
| 5371 | if (!get_shell_surface(view->surface)) |
| 5372 | continue; |
| 5373 | shell->exposay.num_surfaces++; |
| 5374 | } |
| 5375 | |
| 5376 | if (shell->exposay.num_surfaces == 0) { |
| 5377 | shell->exposay.grid_size = 0; |
| 5378 | shell->exposay.hpadding_outer = 0; |
| 5379 | shell->exposay.vpadding_outer = 0; |
| 5380 | shell->exposay.padding_inner = 0; |
| 5381 | shell->exposay.surface_size = 0; |
| 5382 | return EXPOSAY_LAYOUT_OVERVIEW; |
| 5383 | } |
| 5384 | |
| 5385 | /* Lay the grid out as square as possible, losing surfaces from the |
| 5386 | * bottom row if required. Start with fixed padding of a 10% margin |
| 5387 | * around the outside and 80px internal padding between surfaces, and |
| 5388 | * maximise the area made available to surfaces after this, but only |
| 5389 | * to a maximum of 1/3rd the total output size. |
| 5390 | * |
| 5391 | * If we can't make a square grid, add one extra row at the bottom |
| 5392 | * which will have a smaller number of columns. |
| 5393 | * |
| 5394 | * XXX: Surely there has to be a better way to express this maths, |
| 5395 | * right?! |
| 5396 | */ |
| 5397 | shell->exposay.grid_size = floor(sqrtf(shell->exposay.num_surfaces)); |
| 5398 | if (pow(shell->exposay.grid_size, 2) != shell->exposay.num_surfaces) |
| 5399 | shell->exposay.grid_size++; |
| 5400 | last_row_removed = pow(shell->exposay.grid_size, 2) - shell->exposay.num_surfaces; |
| 5401 | |
| 5402 | shell->exposay.hpadding_outer = (output->width / 10); |
| 5403 | shell->exposay.vpadding_outer = (output->height / 10); |
| 5404 | shell->exposay.padding_inner = 80; |
| 5405 | |
| 5406 | w = output->width - (shell->exposay.hpadding_outer * 2); |
| 5407 | w -= shell->exposay.padding_inner * (shell->exposay.grid_size - 1); |
| 5408 | w /= shell->exposay.grid_size; |
| 5409 | |
| 5410 | h = output->height - (shell->exposay.vpadding_outer * 2); |
| 5411 | h -= shell->exposay.padding_inner * (shell->exposay.grid_size - 1); |
| 5412 | h /= shell->exposay.grid_size; |
| 5413 | |
| 5414 | shell->exposay.surface_size = (w < h) ? w : h; |
| 5415 | if (shell->exposay.surface_size > (output->width / 2)) |
| 5416 | shell->exposay.surface_size = output->width / 2; |
| 5417 | if (shell->exposay.surface_size > (output->height / 2)) |
| 5418 | shell->exposay.surface_size = output->height / 2; |
| 5419 | |
| 5420 | i = 0; |
| 5421 | wl_list_for_each(view, &workspace->layer.view_list, layer_link) { |
| 5422 | int pad; |
| 5423 | |
| 5424 | pad = shell->exposay.surface_size + shell->exposay.padding_inner; |
| 5425 | |
| 5426 | if (!get_shell_surface(view->surface)) |
| 5427 | continue; |
| 5428 | |
| 5429 | esurface = malloc(sizeof(*esurface)); |
| 5430 | if (!esurface) { |
| 5431 | exposay_set_state(shell, EXPOSAY_TARGET_CANCEL, |
| 5432 | shell->exposay.seat); |
| 5433 | break; |
| 5434 | } |
| 5435 | |
| 5436 | wl_list_insert(&shell->exposay.surface_list, &esurface->link); |
| 5437 | esurface->shell = shell; |
| 5438 | esurface->view = view; |
| 5439 | |
| 5440 | esurface->row = i / shell->exposay.grid_size; |
| 5441 | esurface->column = i % shell->exposay.grid_size; |
| 5442 | |
| 5443 | esurface->x = shell->exposay.hpadding_outer; |
| 5444 | esurface->x += pad * esurface->column; |
| 5445 | esurface->y = shell->exposay.vpadding_outer; |
| 5446 | esurface->y += pad * esurface->row; |
| 5447 | |
| 5448 | if (esurface->row == shell->exposay.grid_size - 1) |
| 5449 | esurface->x += (shell->exposay.surface_size + shell->exposay.padding_inner) * last_row_removed / 2; |
| 5450 | |
| 5451 | if (view->geometry.width > view->geometry.height) |
| 5452 | esurface->scale = shell->exposay.surface_size / (float) view->geometry.width; |
| 5453 | else |
| 5454 | esurface->scale = shell->exposay.surface_size / (float) view->geometry.height; |
| 5455 | esurface->width = view->geometry.width * esurface->scale; |
| 5456 | esurface->height = view->geometry.height * esurface->scale; |
| 5457 | |
| 5458 | if (shell->exposay.focus_current == esurface->view) |
| 5459 | exposay_highlight_surface(shell, esurface); |
| 5460 | |
| 5461 | exposay_animate_in(esurface); |
| 5462 | |
| 5463 | i++; |
| 5464 | } |
| 5465 | |
| 5466 | weston_compositor_schedule_repaint(shell->compositor); |
| 5467 | |
| 5468 | return EXPOSAY_LAYOUT_ANIMATE_TO_OVERVIEW; |
| 5469 | } |
| 5470 | |
| 5471 | static void |
Emilio Pozuelo Monfort | 17467d6 | 2013-11-19 12:14:53 +0100 | [diff] [blame] | 5472 | exposay_motion(struct weston_pointer_grab *grab, uint32_t time, |
| 5473 | wl_fixed_t x, wl_fixed_t y) |
Daniel Stone | df8133b | 2013-11-19 11:37:14 +0100 | [diff] [blame] | 5474 | { |
| 5475 | struct desktop_shell *shell = |
| 5476 | container_of(grab, struct desktop_shell, exposay.grab_ptr); |
| 5477 | |
Emilio Pozuelo Monfort | 17467d6 | 2013-11-19 12:14:53 +0100 | [diff] [blame] | 5478 | weston_pointer_move(grab->pointer, x, y); |
| 5479 | |
Daniel Stone | df8133b | 2013-11-19 11:37:14 +0100 | [diff] [blame] | 5480 | exposay_pick(shell, |
| 5481 | wl_fixed_to_int(grab->pointer->x), |
| 5482 | wl_fixed_to_int(grab->pointer->y)); |
| 5483 | } |
| 5484 | |
| 5485 | static void |
| 5486 | exposay_button(struct weston_pointer_grab *grab, uint32_t time, uint32_t button, |
| 5487 | uint32_t state_w) |
| 5488 | { |
| 5489 | struct desktop_shell *shell = |
| 5490 | container_of(grab, struct desktop_shell, exposay.grab_ptr); |
| 5491 | struct weston_seat *seat = grab->pointer->seat; |
| 5492 | enum wl_pointer_button_state state = state_w; |
| 5493 | |
| 5494 | if (button != BTN_LEFT) |
| 5495 | return; |
| 5496 | |
| 5497 | /* Store the surface we clicked on, and don't do anything if we end up |
| 5498 | * releasing on a different surface. */ |
| 5499 | if (state == WL_POINTER_BUTTON_STATE_PRESSED) { |
| 5500 | shell->exposay.clicked = shell->exposay.focus_current; |
| 5501 | return; |
| 5502 | } |
| 5503 | |
| 5504 | if (shell->exposay.focus_current == shell->exposay.clicked) |
| 5505 | exposay_set_state(shell, EXPOSAY_TARGET_SWITCH, seat); |
| 5506 | else |
| 5507 | shell->exposay.clicked = NULL; |
| 5508 | } |
| 5509 | |
Emilio Pozuelo Monfort | 234c524 | 2013-11-26 13:32:08 +0100 | [diff] [blame] | 5510 | static void |
| 5511 | exposay_pointer_grab_cancel(struct weston_pointer_grab *grab) |
| 5512 | { |
| 5513 | struct desktop_shell *shell = |
| 5514 | container_of(grab, struct desktop_shell, exposay.grab_ptr); |
| 5515 | |
| 5516 | exposay_set_state(shell, EXPOSAY_TARGET_CANCEL, shell->exposay.seat); |
| 5517 | } |
| 5518 | |
Daniel Stone | df8133b | 2013-11-19 11:37:14 +0100 | [diff] [blame] | 5519 | static const struct weston_pointer_grab_interface exposay_ptr_grab = { |
| 5520 | noop_grab_focus, |
| 5521 | exposay_motion, |
| 5522 | exposay_button, |
Emilio Pozuelo Monfort | 234c524 | 2013-11-26 13:32:08 +0100 | [diff] [blame] | 5523 | exposay_pointer_grab_cancel, |
Daniel Stone | df8133b | 2013-11-19 11:37:14 +0100 | [diff] [blame] | 5524 | }; |
| 5525 | |
| 5526 | static int |
| 5527 | exposay_maybe_move(struct desktop_shell *shell, int row, int column) |
| 5528 | { |
| 5529 | struct exposay_surface *esurface; |
| 5530 | |
| 5531 | wl_list_for_each(esurface, &shell->exposay.surface_list, link) { |
| 5532 | if (esurface->row != row || esurface->column != column) |
| 5533 | continue; |
| 5534 | |
| 5535 | exposay_highlight_surface(shell, esurface); |
| 5536 | return 1; |
| 5537 | } |
| 5538 | |
| 5539 | return 0; |
| 5540 | } |
| 5541 | |
| 5542 | static void |
| 5543 | exposay_key(struct weston_keyboard_grab *grab, uint32_t time, uint32_t key, |
| 5544 | uint32_t state_w) |
| 5545 | { |
| 5546 | struct weston_seat *seat = grab->keyboard->seat; |
| 5547 | struct desktop_shell *shell = |
| 5548 | container_of(grab, struct desktop_shell, exposay.grab_kbd); |
| 5549 | enum wl_keyboard_key_state state = state_w; |
| 5550 | |
| 5551 | if (state != WL_KEYBOARD_KEY_STATE_RELEASED) |
| 5552 | return; |
| 5553 | |
| 5554 | switch (key) { |
| 5555 | case KEY_ESC: |
| 5556 | exposay_set_state(shell, EXPOSAY_TARGET_CANCEL, seat); |
| 5557 | break; |
| 5558 | case KEY_ENTER: |
| 5559 | exposay_set_state(shell, EXPOSAY_TARGET_SWITCH, seat); |
| 5560 | break; |
| 5561 | case KEY_UP: |
| 5562 | exposay_maybe_move(shell, shell->exposay.row_current - 1, |
| 5563 | shell->exposay.column_current); |
| 5564 | break; |
| 5565 | case KEY_DOWN: |
| 5566 | /* Special case for trying to move to the bottom row when it |
| 5567 | * has fewer items than all the others. */ |
| 5568 | if (!exposay_maybe_move(shell, shell->exposay.row_current + 1, |
| 5569 | shell->exposay.column_current) && |
| 5570 | shell->exposay.row_current < (shell->exposay.grid_size - 1)) { |
| 5571 | exposay_maybe_move(shell, shell->exposay.row_current + 1, |
| 5572 | (shell->exposay.num_surfaces % |
| 5573 | shell->exposay.grid_size) - 1); |
| 5574 | } |
| 5575 | break; |
| 5576 | case KEY_LEFT: |
| 5577 | exposay_maybe_move(shell, shell->exposay.row_current, |
| 5578 | shell->exposay.column_current - 1); |
| 5579 | break; |
| 5580 | case KEY_RIGHT: |
| 5581 | exposay_maybe_move(shell, shell->exposay.row_current, |
| 5582 | shell->exposay.column_current + 1); |
| 5583 | break; |
| 5584 | case KEY_TAB: |
| 5585 | /* Try to move right, then down (and to the leftmost column), |
| 5586 | * then if all else fails, to the top left. */ |
| 5587 | if (!exposay_maybe_move(shell, shell->exposay.row_current, |
| 5588 | shell->exposay.column_current + 1) && |
| 5589 | !exposay_maybe_move(shell, shell->exposay.row_current + 1, 0)) |
| 5590 | exposay_maybe_move(shell, 0, 0); |
| 5591 | break; |
| 5592 | default: |
| 5593 | break; |
| 5594 | } |
| 5595 | } |
| 5596 | |
| 5597 | static void |
| 5598 | exposay_modifier(struct weston_keyboard_grab *grab, uint32_t serial, |
| 5599 | uint32_t mods_depressed, uint32_t mods_latched, |
| 5600 | uint32_t mods_locked, uint32_t group) |
| 5601 | { |
Emilio Pozuelo Monfort | eed9344 | 2013-11-27 10:49:08 +0100 | [diff] [blame] | 5602 | struct desktop_shell *shell = |
| 5603 | container_of(grab, struct desktop_shell, exposay.grab_kbd); |
| 5604 | struct weston_seat *seat = (struct weston_seat *) grab->keyboard->seat; |
| 5605 | |
| 5606 | /* We want to know when mod has been pressed and released. |
| 5607 | * FIXME: There is a problem here: if mod is pressed, then a key |
| 5608 | * is pressed and released, then mod is released, we will treat that |
| 5609 | * as if only mod had been pressed and released. */ |
| 5610 | if (seat->modifier_state) { |
| 5611 | if (seat->modifier_state == shell->binding_modifier) { |
| 5612 | shell->exposay.mod_pressed = true; |
| 5613 | } else { |
| 5614 | shell->exposay.mod_invalid = true; |
| 5615 | } |
| 5616 | } else { |
| 5617 | if (shell->exposay.mod_pressed && !shell->exposay.mod_invalid) |
| 5618 | exposay_set_state(shell, EXPOSAY_TARGET_CANCEL, seat); |
| 5619 | |
| 5620 | shell->exposay.mod_invalid = false; |
| 5621 | shell->exposay.mod_pressed = false; |
| 5622 | } |
| 5623 | |
| 5624 | return; |
Daniel Stone | df8133b | 2013-11-19 11:37:14 +0100 | [diff] [blame] | 5625 | } |
| 5626 | |
Emilio Pozuelo Monfort | 8224309 | 2013-11-19 11:37:17 +0100 | [diff] [blame] | 5627 | static void |
| 5628 | exposay_cancel(struct weston_keyboard_grab *grab) |
| 5629 | { |
| 5630 | struct desktop_shell *shell = |
| 5631 | container_of(grab, struct desktop_shell, exposay.grab_kbd); |
| 5632 | |
| 5633 | exposay_set_state(shell, EXPOSAY_TARGET_CANCEL, shell->exposay.seat); |
| 5634 | } |
| 5635 | |
Daniel Stone | df8133b | 2013-11-19 11:37:14 +0100 | [diff] [blame] | 5636 | static const struct weston_keyboard_grab_interface exposay_kbd_grab = { |
| 5637 | exposay_key, |
| 5638 | exposay_modifier, |
Emilio Pozuelo Monfort | 8224309 | 2013-11-19 11:37:17 +0100 | [diff] [blame] | 5639 | exposay_cancel, |
Daniel Stone | df8133b | 2013-11-19 11:37:14 +0100 | [diff] [blame] | 5640 | }; |
| 5641 | |
| 5642 | /** |
| 5643 | * Called when the transition from overview -> inactive has completed. |
| 5644 | */ |
| 5645 | static enum exposay_layout_state |
| 5646 | exposay_set_inactive(struct desktop_shell *shell) |
| 5647 | { |
| 5648 | struct weston_seat *seat = shell->exposay.seat; |
| 5649 | |
| 5650 | weston_keyboard_end_grab(seat->keyboard); |
| 5651 | weston_pointer_end_grab(seat->pointer); |
| 5652 | if (seat->keyboard->input_method_resource) |
| 5653 | seat->keyboard->grab = &seat->keyboard->input_method_grab; |
| 5654 | |
| 5655 | return EXPOSAY_LAYOUT_INACTIVE; |
| 5656 | } |
| 5657 | |
| 5658 | /** |
| 5659 | * Begins the transition from overview to inactive. */ |
| 5660 | static enum exposay_layout_state |
| 5661 | exposay_transition_inactive(struct desktop_shell *shell, int switch_focus) |
| 5662 | { |
| 5663 | struct exposay_surface *esurface; |
| 5664 | |
| 5665 | /* Call activate() before we start the animations to avoid |
| 5666 | * animating back the old state and then immediately transitioning |
| 5667 | * to the new. */ |
| 5668 | if (switch_focus && shell->exposay.focus_current) |
| 5669 | activate(shell, shell->exposay.focus_current->surface, |
| 5670 | shell->exposay.seat); |
| 5671 | else if (shell->exposay.focus_prev) |
| 5672 | activate(shell, shell->exposay.focus_prev->surface, |
| 5673 | shell->exposay.seat); |
| 5674 | |
| 5675 | wl_list_for_each(esurface, &shell->exposay.surface_list, link) |
| 5676 | exposay_animate_out(esurface); |
| 5677 | weston_compositor_schedule_repaint(shell->compositor); |
| 5678 | |
| 5679 | return EXPOSAY_LAYOUT_ANIMATE_TO_INACTIVE; |
| 5680 | } |
| 5681 | |
| 5682 | static enum exposay_layout_state |
| 5683 | exposay_transition_active(struct desktop_shell *shell) |
| 5684 | { |
| 5685 | struct weston_seat *seat = shell->exposay.seat; |
| 5686 | |
| 5687 | shell->exposay.workspace = get_current_workspace(shell); |
| 5688 | shell->exposay.focus_prev = get_default_view (seat->keyboard->focus); |
| 5689 | shell->exposay.focus_current = get_default_view (seat->keyboard->focus); |
| 5690 | shell->exposay.clicked = NULL; |
| 5691 | wl_list_init(&shell->exposay.surface_list); |
| 5692 | |
| 5693 | lower_fullscreen_layer(shell); |
| 5694 | shell->exposay.grab_kbd.interface = &exposay_kbd_grab; |
| 5695 | weston_keyboard_start_grab(seat->keyboard, |
| 5696 | &shell->exposay.grab_kbd); |
| 5697 | weston_keyboard_set_focus(seat->keyboard, NULL); |
| 5698 | |
| 5699 | shell->exposay.grab_ptr.interface = &exposay_ptr_grab; |
| 5700 | weston_pointer_start_grab(seat->pointer, |
| 5701 | &shell->exposay.grab_ptr); |
| 5702 | weston_pointer_set_focus(seat->pointer, NULL, |
| 5703 | seat->pointer->x, seat->pointer->y); |
| 5704 | |
| 5705 | return exposay_layout(shell); |
| 5706 | } |
| 5707 | |
| 5708 | static void |
| 5709 | exposay_check_state(struct desktop_shell *shell) |
| 5710 | { |
| 5711 | enum exposay_layout_state state_new = shell->exposay.state_cur; |
| 5712 | int do_switch = 0; |
| 5713 | |
| 5714 | /* Don't do anything whilst animations are running, just store up |
| 5715 | * target state changes and only act on them when the animations have |
| 5716 | * completed. */ |
| 5717 | if (exposay_is_animating(shell)) |
| 5718 | return; |
| 5719 | |
| 5720 | switch (shell->exposay.state_target) { |
| 5721 | case EXPOSAY_TARGET_OVERVIEW: |
| 5722 | switch (shell->exposay.state_cur) { |
| 5723 | case EXPOSAY_LAYOUT_OVERVIEW: |
| 5724 | goto out; |
| 5725 | case EXPOSAY_LAYOUT_ANIMATE_TO_OVERVIEW: |
| 5726 | state_new = EXPOSAY_LAYOUT_OVERVIEW; |
| 5727 | break; |
| 5728 | default: |
| 5729 | state_new = exposay_transition_active(shell); |
| 5730 | break; |
| 5731 | } |
| 5732 | break; |
| 5733 | |
| 5734 | case EXPOSAY_TARGET_SWITCH: |
| 5735 | do_switch = 1; /* fallthrough */ |
| 5736 | case EXPOSAY_TARGET_CANCEL: |
| 5737 | switch (shell->exposay.state_cur) { |
| 5738 | case EXPOSAY_LAYOUT_INACTIVE: |
| 5739 | goto out; |
| 5740 | case EXPOSAY_LAYOUT_ANIMATE_TO_INACTIVE: |
| 5741 | state_new = exposay_set_inactive(shell); |
| 5742 | break; |
| 5743 | default: |
| 5744 | state_new = exposay_transition_inactive(shell, do_switch); |
| 5745 | break; |
| 5746 | } |
| 5747 | |
| 5748 | break; |
| 5749 | } |
| 5750 | |
| 5751 | out: |
| 5752 | shell->exposay.state_cur = state_new; |
| 5753 | } |
| 5754 | |
| 5755 | static void |
| 5756 | exposay_set_state(struct desktop_shell *shell, enum exposay_target_state state, |
| 5757 | struct weston_seat *seat) |
| 5758 | { |
| 5759 | shell->exposay.state_target = state; |
| 5760 | shell->exposay.seat = seat; |
| 5761 | exposay_check_state(shell); |
| 5762 | } |
| 5763 | |
| 5764 | static void |
| 5765 | exposay_binding(struct weston_seat *seat, enum weston_keyboard_modifier modifier, |
| 5766 | void *data) |
| 5767 | { |
| 5768 | struct desktop_shell *shell = data; |
| 5769 | |
Emilio Pozuelo Monfort | eed9344 | 2013-11-27 10:49:08 +0100 | [diff] [blame] | 5770 | exposay_set_state(shell, EXPOSAY_TARGET_OVERVIEW, seat); |
Daniel Stone | df8133b | 2013-11-19 11:37:14 +0100 | [diff] [blame] | 5771 | } |
| 5772 | |
Pekka Paalanen | 3c64723 | 2011-12-22 13:43:43 +0200 | [diff] [blame] | 5773 | static void |
Kristian Høgsberg | e314875 | 2013-05-06 23:19:49 -0400 | [diff] [blame] | 5774 | backlight_binding(struct weston_seat *seat, uint32_t time, uint32_t key, |
Daniel Stone | 325fc2d | 2012-05-30 16:31:58 +0100 | [diff] [blame] | 5775 | void *data) |
Tiago Vignatti | 8e53c7f | 2012-02-29 19:53:50 +0200 | [diff] [blame] | 5776 | { |
| 5777 | struct weston_compositor *compositor = data; |
| 5778 | struct weston_output *output; |
Tiago Vignatti | 5ab91ad | 2012-03-12 19:40:09 -0300 | [diff] [blame] | 5779 | long backlight_new = 0; |
Tiago Vignatti | 8e53c7f | 2012-02-29 19:53:50 +0200 | [diff] [blame] | 5780 | |
| 5781 | /* TODO: we're limiting to simple use cases, where we assume just |
| 5782 | * control on the primary display. We'd have to extend later if we |
| 5783 | * ever get support for setting backlights on random desktop LCD |
| 5784 | * panels though */ |
| 5785 | output = get_default_output(compositor); |
| 5786 | if (!output) |
| 5787 | return; |
| 5788 | |
| 5789 | if (!output->set_backlight) |
| 5790 | return; |
| 5791 | |
Tiago Vignatti | 5ab91ad | 2012-03-12 19:40:09 -0300 | [diff] [blame] | 5792 | if (key == KEY_F9 || key == KEY_BRIGHTNESSDOWN) |
| 5793 | backlight_new = output->backlight_current - 25; |
| 5794 | else if (key == KEY_F10 || key == KEY_BRIGHTNESSUP) |
| 5795 | backlight_new = output->backlight_current + 25; |
Tiago Vignatti | 8e53c7f | 2012-02-29 19:53:50 +0200 | [diff] [blame] | 5796 | |
Tiago Vignatti | 5ab91ad | 2012-03-12 19:40:09 -0300 | [diff] [blame] | 5797 | if (backlight_new < 5) |
| 5798 | backlight_new = 5; |
| 5799 | if (backlight_new > 255) |
| 5800 | backlight_new = 255; |
| 5801 | |
| 5802 | output->backlight_current = backlight_new; |
Tiago Vignatti | 8e53c7f | 2012-02-29 19:53:50 +0200 | [diff] [blame] | 5803 | output->set_backlight(output, output->backlight_current); |
| 5804 | } |
| 5805 | |
Ander Conselvan de Oliveira | c509d2b | 2012-11-08 17:20:45 +0200 | [diff] [blame] | 5806 | struct debug_binding_grab { |
Kristian Høgsberg | 29139d4 | 2013-04-18 15:25:39 -0400 | [diff] [blame] | 5807 | struct weston_keyboard_grab grab; |
Ander Conselvan de Oliveira | c509d2b | 2012-11-08 17:20:45 +0200 | [diff] [blame] | 5808 | struct weston_seat *seat; |
| 5809 | uint32_t key[2]; |
| 5810 | int key_released[2]; |
| 5811 | }; |
| 5812 | |
| 5813 | static void |
Kristian Høgsberg | 29139d4 | 2013-04-18 15:25:39 -0400 | [diff] [blame] | 5814 | 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] | 5815 | uint32_t key, uint32_t state) |
| 5816 | { |
| 5817 | struct debug_binding_grab *db = (struct debug_binding_grab *) grab; |
Rob Bradford | 880ebc7 | 2013-07-22 17:31:38 +0100 | [diff] [blame] | 5818 | struct weston_compositor *ec = db->seat->compositor; |
| 5819 | struct wl_display *display = ec->wl_display; |
Ander Conselvan de Oliveira | c509d2b | 2012-11-08 17:20:45 +0200 | [diff] [blame] | 5820 | struct wl_resource *resource; |
Ander Conselvan de Oliveira | c509d2b | 2012-11-08 17:20:45 +0200 | [diff] [blame] | 5821 | uint32_t serial; |
| 5822 | int send = 0, terminate = 0; |
| 5823 | int check_binding = 1; |
| 5824 | int i; |
Neil Roberts | 96d790e | 2013-09-19 17:32:00 +0100 | [diff] [blame] | 5825 | struct wl_list *resource_list; |
Ander Conselvan de Oliveira | c509d2b | 2012-11-08 17:20:45 +0200 | [diff] [blame] | 5826 | |
| 5827 | if (state == WL_KEYBOARD_KEY_STATE_RELEASED) { |
| 5828 | /* Do not run bindings on key releases */ |
| 5829 | check_binding = 0; |
| 5830 | |
| 5831 | for (i = 0; i < 2; i++) |
| 5832 | if (key == db->key[i]) |
| 5833 | db->key_released[i] = 1; |
| 5834 | |
| 5835 | if (db->key_released[0] && db->key_released[1]) { |
| 5836 | /* All key releases been swalled so end the grab */ |
| 5837 | terminate = 1; |
| 5838 | } else if (key != db->key[0] && key != db->key[1]) { |
| 5839 | /* Should not swallow release of other keys */ |
| 5840 | send = 1; |
| 5841 | } |
| 5842 | } else if (key == db->key[0] && !db->key_released[0]) { |
| 5843 | /* Do not check bindings for the first press of the binding |
| 5844 | * key. This allows it to be used as a debug shortcut. |
| 5845 | * We still need to swallow this event. */ |
| 5846 | check_binding = 0; |
| 5847 | } else if (db->key[1]) { |
| 5848 | /* If we already ran a binding don't process another one since |
| 5849 | * we can't keep track of all the binding keys that were |
| 5850 | * pressed in order to swallow the release events. */ |
| 5851 | send = 1; |
| 5852 | check_binding = 0; |
| 5853 | } |
| 5854 | |
| 5855 | if (check_binding) { |
Ander Conselvan de Oliveira | c509d2b | 2012-11-08 17:20:45 +0200 | [diff] [blame] | 5856 | if (weston_compositor_run_debug_binding(ec, db->seat, time, |
| 5857 | key, state)) { |
| 5858 | /* We ran a binding so swallow the press and keep the |
| 5859 | * grab to swallow the released too. */ |
| 5860 | send = 0; |
| 5861 | terminate = 0; |
| 5862 | db->key[1] = key; |
| 5863 | } else { |
| 5864 | /* Terminate the grab since the key pressed is not a |
| 5865 | * debug binding key. */ |
| 5866 | send = 1; |
| 5867 | terminate = 1; |
| 5868 | } |
| 5869 | } |
| 5870 | |
| 5871 | if (send) { |
Neil Roberts | 96d790e | 2013-09-19 17:32:00 +0100 | [diff] [blame] | 5872 | serial = wl_display_next_serial(display); |
| 5873 | resource_list = &grab->keyboard->focus_resource_list; |
| 5874 | wl_resource_for_each(resource, resource_list) { |
Ander Conselvan de Oliveira | c509d2b | 2012-11-08 17:20:45 +0200 | [diff] [blame] | 5875 | wl_keyboard_send_key(resource, serial, time, key, state); |
| 5876 | } |
| 5877 | } |
| 5878 | |
| 5879 | if (terminate) { |
Kristian Høgsberg | 29139d4 | 2013-04-18 15:25:39 -0400 | [diff] [blame] | 5880 | weston_keyboard_end_grab(grab->keyboard); |
| 5881 | if (grab->keyboard->input_method_resource) |
| 5882 | grab->keyboard->grab = &grab->keyboard->input_method_grab; |
Ander Conselvan de Oliveira | c509d2b | 2012-11-08 17:20:45 +0200 | [diff] [blame] | 5883 | free(db); |
| 5884 | } |
| 5885 | } |
| 5886 | |
| 5887 | static void |
Kristian Høgsberg | 29139d4 | 2013-04-18 15:25:39 -0400 | [diff] [blame] | 5888 | 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] | 5889 | uint32_t mods_depressed, uint32_t mods_latched, |
| 5890 | uint32_t mods_locked, uint32_t group) |
| 5891 | { |
| 5892 | struct wl_resource *resource; |
Neil Roberts | 96d790e | 2013-09-19 17:32:00 +0100 | [diff] [blame] | 5893 | struct wl_list *resource_list; |
Ander Conselvan de Oliveira | c509d2b | 2012-11-08 17:20:45 +0200 | [diff] [blame] | 5894 | |
Neil Roberts | 96d790e | 2013-09-19 17:32:00 +0100 | [diff] [blame] | 5895 | resource_list = &grab->keyboard->focus_resource_list; |
Ander Conselvan de Oliveira | c509d2b | 2012-11-08 17:20:45 +0200 | [diff] [blame] | 5896 | |
Neil Roberts | 96d790e | 2013-09-19 17:32:00 +0100 | [diff] [blame] | 5897 | wl_resource_for_each(resource, resource_list) { |
| 5898 | wl_keyboard_send_modifiers(resource, serial, mods_depressed, |
| 5899 | mods_latched, mods_locked, group); |
| 5900 | } |
Ander Conselvan de Oliveira | c509d2b | 2012-11-08 17:20:45 +0200 | [diff] [blame] | 5901 | } |
| 5902 | |
Jonas Ådahl | 1ea343e | 2013-10-25 23:18:05 +0200 | [diff] [blame] | 5903 | static void |
| 5904 | debug_binding_cancel(struct weston_keyboard_grab *grab) |
| 5905 | { |
| 5906 | struct debug_binding_grab *db = (struct debug_binding_grab *) grab; |
| 5907 | |
| 5908 | weston_keyboard_end_grab(grab->keyboard); |
| 5909 | free(db); |
| 5910 | } |
| 5911 | |
Kristian Høgsberg | 29139d4 | 2013-04-18 15:25:39 -0400 | [diff] [blame] | 5912 | struct weston_keyboard_grab_interface debug_binding_keyboard_grab = { |
Ander Conselvan de Oliveira | c509d2b | 2012-11-08 17:20:45 +0200 | [diff] [blame] | 5913 | debug_binding_key, |
Jonas Ådahl | 1ea343e | 2013-10-25 23:18:05 +0200 | [diff] [blame] | 5914 | debug_binding_modifiers, |
| 5915 | debug_binding_cancel, |
Ander Conselvan de Oliveira | c509d2b | 2012-11-08 17:20:45 +0200 | [diff] [blame] | 5916 | }; |
| 5917 | |
| 5918 | static void |
Kristian Høgsberg | e314875 | 2013-05-06 23:19:49 -0400 | [diff] [blame] | 5919 | 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] | 5920 | { |
| 5921 | struct debug_binding_grab *grab; |
| 5922 | |
| 5923 | grab = calloc(1, sizeof *grab); |
| 5924 | if (!grab) |
| 5925 | return; |
| 5926 | |
| 5927 | grab->seat = (struct weston_seat *) seat; |
| 5928 | grab->key[0] = key; |
| 5929 | grab->grab.interface = &debug_binding_keyboard_grab; |
Kristian Høgsberg | 29139d4 | 2013-04-18 15:25:39 -0400 | [diff] [blame] | 5930 | weston_keyboard_start_grab(seat->keyboard, &grab->grab); |
Ander Conselvan de Oliveira | c509d2b | 2012-11-08 17:20:45 +0200 | [diff] [blame] | 5931 | } |
| 5932 | |
Kristian Høgsberg | b41c081 | 2012-03-04 14:53:40 -0500 | [diff] [blame] | 5933 | static void |
Kristian Høgsberg | e314875 | 2013-05-06 23:19:49 -0400 | [diff] [blame] | 5934 | 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] | 5935 | void *data) |
Kristian Høgsberg | 92a57db | 2012-05-26 13:41:06 -0400 | [diff] [blame] | 5936 | { |
Kristian Høgsberg | fe7aa90 | 2013-05-08 09:54:37 -0400 | [diff] [blame] | 5937 | struct weston_surface *focus_surface; |
Kristian Høgsberg | 92a57db | 2012-05-26 13:41:06 -0400 | [diff] [blame] | 5938 | struct wl_client *client; |
Tiago Vignatti | 1d01b01 | 2012-09-27 17:48:36 +0300 | [diff] [blame] | 5939 | struct desktop_shell *shell = data; |
| 5940 | struct weston_compositor *compositor = shell->compositor; |
Kristian Høgsberg | 92a57db | 2012-05-26 13:41:06 -0400 | [diff] [blame] | 5941 | pid_t pid; |
Kristian Høgsberg | 92a57db | 2012-05-26 13:41:06 -0400 | [diff] [blame] | 5942 | |
Philipp Brüschweiler | 6cef009 | 2012-08-13 21:27:27 +0200 | [diff] [blame] | 5943 | focus_surface = seat->keyboard->focus; |
| 5944 | if (!focus_surface) |
| 5945 | return; |
| 5946 | |
Tiago Vignatti | 1d01b01 | 2012-09-27 17:48:36 +0300 | [diff] [blame] | 5947 | wl_signal_emit(&compositor->kill_signal, focus_surface); |
| 5948 | |
Jason Ekstrand | 26ed73c | 2013-06-06 22:34:41 -0500 | [diff] [blame] | 5949 | client = wl_resource_get_client(focus_surface->resource); |
Tiago Vignatti | 920f197 | 2012-09-27 17:48:35 +0300 | [diff] [blame] | 5950 | wl_client_get_credentials(client, &pid, NULL, NULL); |
| 5951 | |
| 5952 | /* Skip clients that we launched ourselves (the credentials of |
| 5953 | * the socketpair is ours) */ |
| 5954 | if (pid == getpid()) |
| 5955 | return; |
Kristian Høgsberg | 92a57db | 2012-05-26 13:41:06 -0400 | [diff] [blame] | 5956 | |
Daniel Stone | 325fc2d | 2012-05-30 16:31:58 +0100 | [diff] [blame] | 5957 | kill(pid, SIGKILL); |
Kristian Høgsberg | 92a57db | 2012-05-26 13:41:06 -0400 | [diff] [blame] | 5958 | } |
| 5959 | |
| 5960 | static void |
Kristian Høgsberg | e314875 | 2013-05-06 23:19:49 -0400 | [diff] [blame] | 5961 | workspace_up_binding(struct weston_seat *seat, uint32_t time, |
Jonas Ådahl | e3cddce | 2012-06-13 00:01:22 +0200 | [diff] [blame] | 5962 | uint32_t key, void *data) |
| 5963 | { |
| 5964 | struct desktop_shell *shell = data; |
| 5965 | unsigned int new_index = shell->workspaces.current; |
| 5966 | |
Kristian Høgsberg | ce345b0 | 2012-06-25 21:35:29 -0400 | [diff] [blame] | 5967 | if (shell->locked) |
Kristian Høgsberg | 4476aaf | 2012-06-25 14:03:13 -0400 | [diff] [blame] | 5968 | return; |
Jonas Ådahl | e3cddce | 2012-06-13 00:01:22 +0200 | [diff] [blame] | 5969 | if (new_index != 0) |
| 5970 | new_index--; |
| 5971 | |
| 5972 | change_workspace(shell, new_index); |
| 5973 | } |
| 5974 | |
| 5975 | static void |
Kristian Høgsberg | e314875 | 2013-05-06 23:19:49 -0400 | [diff] [blame] | 5976 | workspace_down_binding(struct weston_seat *seat, uint32_t time, |
Jonas Ådahl | e3cddce | 2012-06-13 00:01:22 +0200 | [diff] [blame] | 5977 | uint32_t key, void *data) |
| 5978 | { |
| 5979 | struct desktop_shell *shell = data; |
| 5980 | unsigned int new_index = shell->workspaces.current; |
| 5981 | |
Kristian Høgsberg | ce345b0 | 2012-06-25 21:35:29 -0400 | [diff] [blame] | 5982 | if (shell->locked) |
Kristian Høgsberg | 4476aaf | 2012-06-25 14:03:13 -0400 | [diff] [blame] | 5983 | return; |
Jonas Ådahl | e3cddce | 2012-06-13 00:01:22 +0200 | [diff] [blame] | 5984 | if (new_index < shell->workspaces.num - 1) |
| 5985 | new_index++; |
| 5986 | |
| 5987 | change_workspace(shell, new_index); |
| 5988 | } |
| 5989 | |
| 5990 | static void |
Kristian Høgsberg | e314875 | 2013-05-06 23:19:49 -0400 | [diff] [blame] | 5991 | workspace_f_binding(struct weston_seat *seat, uint32_t time, |
Jonas Ådahl | e3cddce | 2012-06-13 00:01:22 +0200 | [diff] [blame] | 5992 | uint32_t key, void *data) |
| 5993 | { |
| 5994 | struct desktop_shell *shell = data; |
| 5995 | unsigned int new_index; |
| 5996 | |
Kristian Høgsberg | ce345b0 | 2012-06-25 21:35:29 -0400 | [diff] [blame] | 5997 | if (shell->locked) |
Kristian Høgsberg | 4476aaf | 2012-06-25 14:03:13 -0400 | [diff] [blame] | 5998 | return; |
Jonas Ådahl | e3cddce | 2012-06-13 00:01:22 +0200 | [diff] [blame] | 5999 | new_index = key - KEY_F1; |
| 6000 | if (new_index >= shell->workspaces.num) |
| 6001 | new_index = shell->workspaces.num - 1; |
| 6002 | |
| 6003 | change_workspace(shell, new_index); |
| 6004 | } |
| 6005 | |
Jonas Ådahl | 8de6a1d | 2012-08-29 22:13:00 +0200 | [diff] [blame] | 6006 | static void |
Kristian Høgsberg | e314875 | 2013-05-06 23:19:49 -0400 | [diff] [blame] | 6007 | workspace_move_surface_up_binding(struct weston_seat *seat, uint32_t time, |
Jonas Ådahl | 8de6a1d | 2012-08-29 22:13:00 +0200 | [diff] [blame] | 6008 | uint32_t key, void *data) |
| 6009 | { |
| 6010 | struct desktop_shell *shell = data; |
| 6011 | unsigned int new_index = shell->workspaces.current; |
| 6012 | |
| 6013 | if (shell->locked) |
| 6014 | return; |
| 6015 | |
| 6016 | if (new_index != 0) |
| 6017 | new_index--; |
| 6018 | |
| 6019 | take_surface_to_workspace_by_seat(shell, seat, new_index); |
| 6020 | } |
| 6021 | |
| 6022 | static void |
Kristian Høgsberg | e314875 | 2013-05-06 23:19:49 -0400 | [diff] [blame] | 6023 | workspace_move_surface_down_binding(struct weston_seat *seat, uint32_t time, |
Jonas Ådahl | 8de6a1d | 2012-08-29 22:13:00 +0200 | [diff] [blame] | 6024 | uint32_t key, void *data) |
| 6025 | { |
| 6026 | struct desktop_shell *shell = data; |
| 6027 | unsigned int new_index = shell->workspaces.current; |
| 6028 | |
| 6029 | if (shell->locked) |
| 6030 | return; |
| 6031 | |
| 6032 | if (new_index < shell->workspaces.num - 1) |
| 6033 | new_index++; |
| 6034 | |
| 6035 | take_surface_to_workspace_by_seat(shell, seat, new_index); |
| 6036 | } |
Jonas Ådahl | e3cddce | 2012-06-13 00:01:22 +0200 | [diff] [blame] | 6037 | |
| 6038 | static void |
Xiong Zhang | 6b48142 | 2013-10-23 13:58:32 +0800 | [diff] [blame] | 6039 | handle_output_destroy(struct wl_listener *listener, void *data) |
| 6040 | { |
| 6041 | struct shell_output *output_listener = |
| 6042 | container_of(listener, struct shell_output, destroy_listener); |
| 6043 | |
| 6044 | wl_list_remove(&output_listener->destroy_listener.link); |
| 6045 | wl_list_remove(&output_listener->link); |
| 6046 | free(output_listener); |
| 6047 | } |
| 6048 | |
| 6049 | static void |
| 6050 | create_shell_output(struct desktop_shell *shell, |
| 6051 | struct weston_output *output) |
| 6052 | { |
| 6053 | struct shell_output *shell_output; |
| 6054 | |
| 6055 | shell_output = zalloc(sizeof *shell_output); |
| 6056 | if (shell_output == NULL) |
| 6057 | return; |
| 6058 | |
| 6059 | shell_output->output = output; |
| 6060 | shell_output->shell = shell; |
| 6061 | shell_output->destroy_listener.notify = handle_output_destroy; |
| 6062 | wl_signal_add(&output->destroy_signal, |
| 6063 | &shell_output->destroy_listener); |
Kristian Høgsberg | a3a0e18 | 2013-10-23 23:36:04 -0700 | [diff] [blame] | 6064 | wl_list_insert(shell->output_list.prev, &shell_output->link); |
Xiong Zhang | 6b48142 | 2013-10-23 13:58:32 +0800 | [diff] [blame] | 6065 | } |
| 6066 | |
| 6067 | static void |
| 6068 | handle_output_create(struct wl_listener *listener, void *data) |
| 6069 | { |
| 6070 | struct desktop_shell *shell = |
| 6071 | container_of(listener, struct desktop_shell, output_create_listener); |
| 6072 | struct weston_output *output = (struct weston_output *)data; |
| 6073 | |
| 6074 | create_shell_output(shell, output); |
| 6075 | } |
| 6076 | |
| 6077 | static void |
| 6078 | setup_output_destroy_handler(struct weston_compositor *ec, |
| 6079 | struct desktop_shell *shell) |
| 6080 | { |
| 6081 | struct weston_output *output; |
| 6082 | |
| 6083 | wl_list_init(&shell->output_list); |
| 6084 | wl_list_for_each(output, &ec->output_list, link) |
| 6085 | create_shell_output(shell, output); |
| 6086 | |
| 6087 | shell->output_create_listener.notify = handle_output_create; |
| 6088 | wl_signal_add(&ec->output_created_signal, |
| 6089 | &shell->output_create_listener); |
| 6090 | } |
| 6091 | |
| 6092 | static void |
Kristian Høgsberg | 02e79dc | 2012-04-12 09:55:26 -0400 | [diff] [blame] | 6093 | shell_destroy(struct wl_listener *listener, void *data) |
Pekka Paalanen | 3c64723 | 2011-12-22 13:43:43 +0200 | [diff] [blame] | 6094 | { |
Tiago Vignatti | be14326 | 2012-04-16 17:31:41 +0300 | [diff] [blame] | 6095 | struct desktop_shell *shell = |
| 6096 | container_of(listener, struct desktop_shell, destroy_listener); |
Jonas Ådahl | e3cddce | 2012-06-13 00:01:22 +0200 | [diff] [blame] | 6097 | struct workspace **ws; |
Xiong Zhang | 6b48142 | 2013-10-23 13:58:32 +0800 | [diff] [blame] | 6098 | struct shell_output *shell_output, *tmp; |
Pekka Paalanen | 3c64723 | 2011-12-22 13:43:43 +0200 | [diff] [blame] | 6099 | |
Pekka Paalanen | 9cf5cc8 | 2012-01-02 16:00:24 +0200 | [diff] [blame] | 6100 | if (shell->child.client) |
| 6101 | wl_client_destroy(shell->child.client); |
| 6102 | |
Ander Conselvan de Oliveira | a457563 | 2013-02-21 18:35:23 +0200 | [diff] [blame] | 6103 | wl_list_remove(&shell->idle_listener.link); |
| 6104 | wl_list_remove(&shell->wake_listener.link); |
Jan Arne Petersen | 42feced | 2012-06-21 21:52:17 +0200 | [diff] [blame] | 6105 | wl_list_remove(&shell->show_input_panel_listener.link); |
| 6106 | wl_list_remove(&shell->hide_input_panel_listener.link); |
Kristian Høgsberg | 88c1607 | 2012-05-16 08:04:19 -0400 | [diff] [blame] | 6107 | |
Xiong Zhang | 6b48142 | 2013-10-23 13:58:32 +0800 | [diff] [blame] | 6108 | wl_list_for_each_safe(shell_output, tmp, &shell->output_list, link) { |
| 6109 | wl_list_remove(&shell_output->destroy_listener.link); |
| 6110 | wl_list_remove(&shell_output->link); |
| 6111 | free(shell_output); |
| 6112 | } |
| 6113 | |
| 6114 | wl_list_remove(&shell->output_create_listener.link); |
| 6115 | |
Jonas Ådahl | e3cddce | 2012-06-13 00:01:22 +0200 | [diff] [blame] | 6116 | wl_array_for_each(ws, &shell->workspaces.array) |
| 6117 | workspace_destroy(*ws); |
| 6118 | wl_array_release(&shell->workspaces.array); |
| 6119 | |
Pekka Paalanen | 3c64723 | 2011-12-22 13:43:43 +0200 | [diff] [blame] | 6120 | free(shell->screensaver.path); |
Emilio Pozuelo Monfort | 46ce798 | 2013-11-20 13:22:29 +0100 | [diff] [blame] | 6121 | free(shell->client); |
Pekka Paalanen | 3c64723 | 2011-12-22 13:43:43 +0200 | [diff] [blame] | 6122 | free(shell); |
| 6123 | } |
| 6124 | |
Tiago Vignatti | 0b52d48 | 2012-04-20 18:54:25 +0300 | [diff] [blame] | 6125 | static void |
| 6126 | shell_add_bindings(struct weston_compositor *ec, struct desktop_shell *shell) |
| 6127 | { |
| 6128 | uint32_t mod; |
Jonas Ådahl | e3cddce | 2012-06-13 00:01:22 +0200 | [diff] [blame] | 6129 | int i, num_workspace_bindings; |
Tiago Vignatti | 0b52d48 | 2012-04-20 18:54:25 +0300 | [diff] [blame] | 6130 | |
| 6131 | /* fixed bindings */ |
Daniel Stone | 325fc2d | 2012-05-30 16:31:58 +0100 | [diff] [blame] | 6132 | weston_compositor_add_key_binding(ec, KEY_BACKSPACE, |
| 6133 | MODIFIER_CTRL | MODIFIER_ALT, |
| 6134 | terminate_binding, ec); |
Emilio Pozuelo Monfort | 03251b6 | 2013-11-19 11:37:16 +0100 | [diff] [blame] | 6135 | weston_compositor_add_key_binding(ec, KEY_TAB, |
| 6136 | MODIFIER_ALT, |
| 6137 | alt_tab_binding, shell); |
Daniel Stone | 325fc2d | 2012-05-30 16:31:58 +0100 | [diff] [blame] | 6138 | weston_compositor_add_button_binding(ec, BTN_LEFT, 0, |
| 6139 | click_to_activate_binding, |
| 6140 | shell); |
Neil Roberts | a28c693 | 2013-10-03 16:43:04 +0100 | [diff] [blame] | 6141 | weston_compositor_add_touch_binding(ec, 0, |
| 6142 | touch_to_activate_binding, |
| 6143 | shell); |
Daniel Stone | 325fc2d | 2012-05-30 16:31:58 +0100 | [diff] [blame] | 6144 | weston_compositor_add_axis_binding(ec, WL_POINTER_AXIS_VERTICAL_SCROLL, |
| 6145 | MODIFIER_SUPER | MODIFIER_ALT, |
| 6146 | surface_opacity_binding, NULL); |
| 6147 | weston_compositor_add_axis_binding(ec, WL_POINTER_AXIS_VERTICAL_SCROLL, |
| 6148 | MODIFIER_SUPER, zoom_axis_binding, |
| 6149 | NULL); |
Tiago Vignatti | 0b52d48 | 2012-04-20 18:54:25 +0300 | [diff] [blame] | 6150 | |
| 6151 | /* configurable bindings */ |
| 6152 | mod = shell->binding_modifier; |
Daniel Stone | 325fc2d | 2012-05-30 16:31:58 +0100 | [diff] [blame] | 6153 | weston_compositor_add_key_binding(ec, KEY_PAGEUP, mod, |
| 6154 | zoom_key_binding, NULL); |
| 6155 | weston_compositor_add_key_binding(ec, KEY_PAGEDOWN, mod, |
| 6156 | zoom_key_binding, NULL); |
| 6157 | weston_compositor_add_button_binding(ec, BTN_LEFT, mod, move_binding, |
| 6158 | shell); |
Neil Roberts | aba0f25 | 2013-10-03 16:43:05 +0100 | [diff] [blame] | 6159 | weston_compositor_add_touch_binding(ec, mod, touch_move_binding, shell); |
Daniel Stone | 325fc2d | 2012-05-30 16:31:58 +0100 | [diff] [blame] | 6160 | weston_compositor_add_button_binding(ec, BTN_MIDDLE, mod, |
| 6161 | resize_binding, shell); |
Pekka Paalanen | 7bb6510 | 2013-05-22 18:03:04 +0300 | [diff] [blame] | 6162 | |
| 6163 | if (ec->capabilities & WESTON_CAP_ROTATION_ANY) |
| 6164 | weston_compositor_add_button_binding(ec, BTN_RIGHT, mod, |
| 6165 | rotate_binding, NULL); |
| 6166 | |
Daniel Stone | 325fc2d | 2012-05-30 16:31:58 +0100 | [diff] [blame] | 6167 | weston_compositor_add_key_binding(ec, KEY_TAB, mod, switcher_binding, |
| 6168 | shell); |
| 6169 | weston_compositor_add_key_binding(ec, KEY_F9, mod, backlight_binding, |
| 6170 | ec); |
| 6171 | weston_compositor_add_key_binding(ec, KEY_BRIGHTNESSDOWN, 0, |
| 6172 | backlight_binding, ec); |
| 6173 | weston_compositor_add_key_binding(ec, KEY_F10, mod, backlight_binding, |
| 6174 | ec); |
| 6175 | weston_compositor_add_key_binding(ec, KEY_BRIGHTNESSUP, 0, |
| 6176 | backlight_binding, ec); |
Daniel Stone | 325fc2d | 2012-05-30 16:31:58 +0100 | [diff] [blame] | 6177 | weston_compositor_add_key_binding(ec, KEY_K, mod, |
| 6178 | force_kill_binding, shell); |
Jonas Ådahl | e3cddce | 2012-06-13 00:01:22 +0200 | [diff] [blame] | 6179 | weston_compositor_add_key_binding(ec, KEY_UP, mod, |
| 6180 | workspace_up_binding, shell); |
| 6181 | weston_compositor_add_key_binding(ec, KEY_DOWN, mod, |
| 6182 | workspace_down_binding, shell); |
Jonas Ådahl | 8de6a1d | 2012-08-29 22:13:00 +0200 | [diff] [blame] | 6183 | weston_compositor_add_key_binding(ec, KEY_UP, mod | MODIFIER_SHIFT, |
| 6184 | workspace_move_surface_up_binding, |
| 6185 | shell); |
| 6186 | weston_compositor_add_key_binding(ec, KEY_DOWN, mod | MODIFIER_SHIFT, |
| 6187 | workspace_move_surface_down_binding, |
| 6188 | shell); |
Jonas Ådahl | e3cddce | 2012-06-13 00:01:22 +0200 | [diff] [blame] | 6189 | |
Daniel Stone | df8133b | 2013-11-19 11:37:14 +0100 | [diff] [blame] | 6190 | weston_compositor_add_modifier_binding(ec, mod, exposay_binding, shell); |
| 6191 | |
Jonas Ådahl | e3cddce | 2012-06-13 00:01:22 +0200 | [diff] [blame] | 6192 | /* Add bindings for mod+F[1-6] for workspace 1 to 6. */ |
| 6193 | if (shell->workspaces.num > 1) { |
| 6194 | num_workspace_bindings = shell->workspaces.num; |
| 6195 | if (num_workspace_bindings > 6) |
| 6196 | num_workspace_bindings = 6; |
| 6197 | for (i = 0; i < num_workspace_bindings; i++) |
| 6198 | weston_compositor_add_key_binding(ec, KEY_F1 + i, mod, |
| 6199 | workspace_f_binding, |
| 6200 | shell); |
| 6201 | } |
Ander Conselvan de Oliveira | c509d2b | 2012-11-08 17:20:45 +0200 | [diff] [blame] | 6202 | |
| 6203 | /* Debug bindings */ |
| 6204 | weston_compositor_add_key_binding(ec, KEY_SPACE, mod | MODIFIER_SHIFT, |
| 6205 | debug_binding, shell); |
Tiago Vignatti | 0b52d48 | 2012-04-20 18:54:25 +0300 | [diff] [blame] | 6206 | } |
| 6207 | |
Kristian Høgsberg | 1c56218 | 2011-05-02 22:09:20 -0400 | [diff] [blame] | 6208 | WL_EXPORT int |
Kristian Høgsberg | cb4685b | 2013-02-20 15:37:49 -0500 | [diff] [blame] | 6209 | module_init(struct weston_compositor *ec, |
Ossama Othman | a50e6e4 | 2013-05-14 09:48:26 -0700 | [diff] [blame] | 6210 | int *argc, char *argv[]) |
Kristian Høgsberg | 4cca349 | 2011-01-18 07:53:49 -0500 | [diff] [blame] | 6211 | { |
Kristian Høgsberg | f4d2f23 | 2012-08-10 10:05:39 -0400 | [diff] [blame] | 6212 | struct weston_seat *seat; |
Tiago Vignatti | be14326 | 2012-04-16 17:31:41 +0300 | [diff] [blame] | 6213 | struct desktop_shell *shell; |
Jonas Ådahl | e3cddce | 2012-06-13 00:01:22 +0200 | [diff] [blame] | 6214 | struct workspace **pws; |
| 6215 | unsigned int i; |
Tiago Vignatti | b7dbbd6 | 2012-09-25 17:57:01 +0300 | [diff] [blame] | 6216 | struct wl_event_loop *loop; |
Kristian Høgsberg | 02ec0a5 | 2011-04-23 13:04:11 -0400 | [diff] [blame] | 6217 | |
Peter Hutterer | f3d6227 | 2013-08-08 11:57:05 +1000 | [diff] [blame] | 6218 | shell = zalloc(sizeof *shell); |
Kristian Høgsberg | 02ec0a5 | 2011-04-23 13:04:11 -0400 | [diff] [blame] | 6219 | if (shell == NULL) |
| 6220 | return -1; |
| 6221 | |
Kristian Høgsberg | 7584062 | 2011-09-06 13:48:16 -0400 | [diff] [blame] | 6222 | shell->compositor = ec; |
Kristian Høgsberg | 02e79dc | 2012-04-12 09:55:26 -0400 | [diff] [blame] | 6223 | |
| 6224 | shell->destroy_listener.notify = shell_destroy; |
| 6225 | wl_signal_add(&ec->destroy_signal, &shell->destroy_listener); |
Ander Conselvan de Oliveira | a457563 | 2013-02-21 18:35:23 +0200 | [diff] [blame] | 6226 | shell->idle_listener.notify = idle_handler; |
| 6227 | wl_signal_add(&ec->idle_signal, &shell->idle_listener); |
| 6228 | shell->wake_listener.notify = wake_handler; |
| 6229 | wl_signal_add(&ec->wake_signal, &shell->wake_listener); |
Jan Arne Petersen | 42feced | 2012-06-21 21:52:17 +0200 | [diff] [blame] | 6230 | shell->show_input_panel_listener.notify = show_input_panels; |
| 6231 | wl_signal_add(&ec->show_input_panel_signal, &shell->show_input_panel_listener); |
| 6232 | shell->hide_input_panel_listener.notify = hide_input_panels; |
| 6233 | 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] | 6234 | shell->update_input_panel_listener.notify = update_input_panels; |
| 6235 | 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] | 6236 | ec->ping_handler = ping_handler; |
Kristian Høgsberg | 82a1d11 | 2012-07-19 14:02:00 -0400 | [diff] [blame] | 6237 | ec->shell_interface.shell = shell; |
Tiago Vignatti | bc052c9 | 2012-04-19 16:18:18 +0300 | [diff] [blame] | 6238 | ec->shell_interface.create_shell_surface = create_shell_surface; |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 6239 | ec->shell_interface.get_primary_view = get_primary_view; |
Tiago Vignatti | bc052c9 | 2012-04-19 16:18:18 +0300 | [diff] [blame] | 6240 | ec->shell_interface.set_toplevel = set_toplevel; |
Tiago Vignatti | 491bac1 | 2012-05-18 16:37:43 -0400 | [diff] [blame] | 6241 | ec->shell_interface.set_transient = set_transient; |
Kristian Høgsberg | b810eb5 | 2013-02-12 20:07:05 -0500 | [diff] [blame] | 6242 | ec->shell_interface.set_fullscreen = set_fullscreen; |
Tiago Vignatti | fb2adba | 2013-06-12 15:43:21 -0300 | [diff] [blame] | 6243 | ec->shell_interface.set_xwayland = set_xwayland; |
Kristian Høgsberg | 938b8fa | 2012-05-18 13:46:27 -0400 | [diff] [blame] | 6244 | ec->shell_interface.move = surface_move; |
Kristian Høgsberg | c1693f2 | 2012-05-22 16:56:23 -0400 | [diff] [blame] | 6245 | ec->shell_interface.resize = surface_resize; |
Giulio Camuffo | 62942ad | 2013-09-11 18:20:47 +0200 | [diff] [blame] | 6246 | ec->shell_interface.set_title = set_title; |
Kristian Høgsberg | 4cca349 | 2011-01-18 07:53:49 -0500 | [diff] [blame] | 6247 | |
Jan Arne Petersen | 42feced | 2012-06-21 21:52:17 +0200 | [diff] [blame] | 6248 | wl_list_init(&shell->input_panel.surfaces); |
Pekka Paalanen | f0fc70d | 2011-11-15 13:34:54 +0200 | [diff] [blame] | 6249 | |
Kristian Høgsberg | 3be2ce9 | 2012-02-29 12:42:35 -0500 | [diff] [blame] | 6250 | weston_layer_init(&shell->fullscreen_layer, &ec->cursor_layer.link); |
| 6251 | weston_layer_init(&shell->panel_layer, &shell->fullscreen_layer.link); |
Jonas Ådahl | e3cddce | 2012-06-13 00:01:22 +0200 | [diff] [blame] | 6252 | weston_layer_init(&shell->background_layer, &shell->panel_layer.link); |
| 6253 | weston_layer_init(&shell->lock_layer, NULL); |
Philipp Brüschweiler | 711fda8 | 2012-08-09 18:50:43 +0200 | [diff] [blame] | 6254 | weston_layer_init(&shell->input_panel_layer, NULL); |
Jonas Ådahl | e3cddce | 2012-06-13 00:01:22 +0200 | [diff] [blame] | 6255 | |
| 6256 | wl_array_init(&shell->workspaces.array); |
Jonas Ådahl | e9d2250 | 2012-08-29 22:13:01 +0200 | [diff] [blame] | 6257 | wl_list_init(&shell->workspaces.client_list); |
Kristian Høgsberg | 3be2ce9 | 2012-02-29 12:42:35 -0500 | [diff] [blame] | 6258 | |
Kristian Høgsberg | 14e438c | 2013-05-26 21:48:14 -0400 | [diff] [blame] | 6259 | shell_configuration(shell); |
Pekka Paalanen | e955f1e | 2011-12-07 11:49:52 +0200 | [diff] [blame] | 6260 | |
Daniel Stone | df8133b | 2013-11-19 11:37:14 +0100 | [diff] [blame] | 6261 | shell->exposay.state_cur = EXPOSAY_LAYOUT_INACTIVE; |
| 6262 | shell->exposay.state_target = EXPOSAY_TARGET_CANCEL; |
| 6263 | |
Jonas Ådahl | e3cddce | 2012-06-13 00:01:22 +0200 | [diff] [blame] | 6264 | for (i = 0; i < shell->workspaces.num; i++) { |
| 6265 | pws = wl_array_add(&shell->workspaces.array, sizeof *pws); |
| 6266 | if (pws == NULL) |
| 6267 | return -1; |
| 6268 | |
| 6269 | *pws = workspace_create(); |
| 6270 | if (*pws == NULL) |
| 6271 | return -1; |
| 6272 | } |
| 6273 | activate_workspace(shell, 0); |
| 6274 | |
Jonas Ådahl | 8de6a1d | 2012-08-29 22:13:00 +0200 | [diff] [blame] | 6275 | wl_list_init(&shell->workspaces.anim_sticky_list); |
Jonas Ådahl | 62fcd04 | 2012-06-13 00:01:23 +0200 | [diff] [blame] | 6276 | wl_list_init(&shell->workspaces.animation.link); |
| 6277 | shell->workspaces.animation.frame = animate_workspace_change_frame; |
| 6278 | |
Kristian Høgsberg | 919cddb | 2013-07-08 19:03:57 -0400 | [diff] [blame] | 6279 | if (wl_global_create(ec->wl_display, &wl_shell_interface, 1, |
Kristian Høgsberg | 97d44aa | 2011-08-26 17:21:20 -0400 | [diff] [blame] | 6280 | shell, bind_shell) == NULL) |
Kristian Høgsberg | 4cca349 | 2011-01-18 07:53:49 -0500 | [diff] [blame] | 6281 | return -1; |
| 6282 | |
Kristian Høgsberg | 919cddb | 2013-07-08 19:03:57 -0400 | [diff] [blame] | 6283 | if (wl_global_create(ec->wl_display, |
| 6284 | &desktop_shell_interface, 2, |
| 6285 | shell, bind_desktop_shell) == NULL) |
Kristian Høgsberg | 7584062 | 2011-09-06 13:48:16 -0400 | [diff] [blame] | 6286 | return -1; |
| 6287 | |
Kristian Høgsberg | 919cddb | 2013-07-08 19:03:57 -0400 | [diff] [blame] | 6288 | if (wl_global_create(ec->wl_display, &screensaver_interface, 1, |
| 6289 | shell, bind_screensaver) == NULL) |
Pekka Paalanen | 6e16811 | 2011-11-24 11:34:05 +0200 | [diff] [blame] | 6290 | return -1; |
| 6291 | |
Kristian Høgsberg | 919cddb | 2013-07-08 19:03:57 -0400 | [diff] [blame] | 6292 | 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] | 6293 | shell, bind_input_panel) == NULL) |
| 6294 | return -1; |
| 6295 | |
Kristian Høgsberg | 919cddb | 2013-07-08 19:03:57 -0400 | [diff] [blame] | 6296 | if (wl_global_create(ec->wl_display, &workspace_manager_interface, 1, |
| 6297 | shell, bind_workspace_manager) == NULL) |
Jonas Ådahl | e9d2250 | 2012-08-29 22:13:01 +0200 | [diff] [blame] | 6298 | return -1; |
| 6299 | |
Kristian Høgsberg | f03a616 | 2012-01-17 11:07:42 -0500 | [diff] [blame] | 6300 | shell->child.deathstamp = weston_compositor_get_time(); |
Tiago Vignatti | b7dbbd6 | 2012-09-25 17:57:01 +0300 | [diff] [blame] | 6301 | |
Xiong Zhang | 6b48142 | 2013-10-23 13:58:32 +0800 | [diff] [blame] | 6302 | setup_output_destroy_handler(ec, shell); |
| 6303 | |
Tiago Vignatti | b7dbbd6 | 2012-09-25 17:57:01 +0300 | [diff] [blame] | 6304 | loop = wl_display_get_event_loop(ec->wl_display); |
| 6305 | wl_event_loop_add_idle(loop, launch_desktop_shell_process, shell); |
Pekka Paalanen | 6cd281a | 2011-11-03 14:11:32 +0200 | [diff] [blame] | 6306 | |
Ander Conselvan de Oliveira | 859e885 | 2013-02-21 18:35:21 +0200 | [diff] [blame] | 6307 | shell->screensaver.timer = |
| 6308 | wl_event_loop_add_timer(loop, screensaver_timeout, shell); |
| 6309 | |
Kristian Høgsberg | f4d2f23 | 2012-08-10 10:05:39 -0400 | [diff] [blame] | 6310 | wl_list_for_each(seat, &ec->seat_list, link) |
| 6311 | create_pointer_focus_listener(seat); |
Kristian Høgsberg | d56bd90 | 2012-06-05 09:58:51 -0400 | [diff] [blame] | 6312 | |
Tiago Vignatti | 0b52d48 | 2012-04-20 18:54:25 +0300 | [diff] [blame] | 6313 | shell_add_bindings(ec, shell); |
Kristian Høgsberg | 0793756 | 2011-04-12 17:25:42 -0400 | [diff] [blame] | 6314 | |
Pekka Paalanen | 79346ab | 2013-05-22 18:03:09 +0300 | [diff] [blame] | 6315 | shell_fade_init(shell); |
Ander Conselvan de Oliveira | 19d10ef | 2013-02-21 18:35:20 +0200 | [diff] [blame] | 6316 | |
Kristian Høgsberg | 4cca349 | 2011-01-18 07:53:49 -0500 | [diff] [blame] | 6317 | return 0; |
| 6318 | } |