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 | |
Pekka Paalanen | 56cdea9 | 2011-11-23 16:14:12 +0200 | [diff] [blame] | 254 | struct shell_surface { |
Jason Ekstrand | 651f00e | 2013-06-14 10:07:54 -0500 | [diff] [blame] | 255 | struct wl_resource *resource; |
| 256 | struct wl_signal destroy_signal; |
Pekka Paalanen | 9d1613e | 2011-11-25 12:09:16 +0200 | [diff] [blame] | 257 | |
Kristian Høgsberg | 8334bc1 | 2012-01-03 10:29:47 -0500 | [diff] [blame] | 258 | struct weston_surface *surface; |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 259 | struct weston_view *view; |
Pekka Paalanen | 9d1613e | 2011-11-25 12:09:16 +0200 | [diff] [blame] | 260 | struct wl_listener surface_destroy_listener; |
Kristian Høgsberg | 8150b19 | 2012-06-27 10:22:58 -0400 | [diff] [blame] | 261 | struct weston_surface *parent; |
Tiago Vignatti | be14326 | 2012-04-16 17:31:41 +0300 | [diff] [blame] | 262 | struct desktop_shell *shell; |
Pekka Paalanen | 57da4a8 | 2011-11-23 16:42:16 +0200 | [diff] [blame] | 263 | |
Kristian Høgsberg | 7f366e7 | 2012-04-27 17:20:01 -0400 | [diff] [blame] | 264 | enum shell_surface_type type, next_type; |
Kristian Høgsberg | e7afd91 | 2012-05-02 09:47:44 -0400 | [diff] [blame] | 265 | char *title, *class; |
Kristian Høgsberg | d2abb83 | 2011-11-23 10:52:40 -0500 | [diff] [blame] | 266 | int32_t saved_x, saved_y; |
Alex Wu | 4539b08 | 2012-03-01 12:57:46 +0800 | [diff] [blame] | 267 | bool saved_position_valid; |
Alex Wu | 7bcb8bd | 2012-04-27 09:07:24 +0800 | [diff] [blame] | 268 | bool saved_rotation_valid; |
Kristian Høgsberg | c85f1d4 | 2013-10-24 16:52:00 -0700 | [diff] [blame] | 269 | int unresponsive, grabbed; |
Benjamin Franzke | d0f79ab | 2011-11-22 12:43:52 +0100 | [diff] [blame] | 270 | |
Kristian Høgsberg | b3cca0a | 2012-01-04 22:19:14 -0500 | [diff] [blame] | 271 | struct { |
Pekka Paalanen | 460099f | 2012-01-20 16:48:25 +0200 | [diff] [blame] | 272 | struct weston_transform transform; |
Kristian Høgsberg | 765e27b | 2012-01-27 13:36:13 -0500 | [diff] [blame] | 273 | struct weston_matrix rotation; |
Pekka Paalanen | 460099f | 2012-01-20 16:48:25 +0200 | [diff] [blame] | 274 | } rotation; |
| 275 | |
| 276 | struct { |
Giulio Camuffo | 5085a75 | 2013-03-25 21:42:45 +0100 | [diff] [blame] | 277 | struct wl_list grab_link; |
Kristian Høgsberg | b3cca0a | 2012-01-04 22:19:14 -0500 | [diff] [blame] | 278 | int32_t x, y; |
Giulio Camuffo | 5085a75 | 2013-03-25 21:42:45 +0100 | [diff] [blame] | 279 | struct shell_seat *shseat; |
Kristian Høgsberg | 3730f36 | 2012-04-13 12:40:07 -0400 | [diff] [blame] | 280 | uint32_t serial; |
Kristian Høgsberg | b3cca0a | 2012-01-04 22:19:14 -0500 | [diff] [blame] | 281 | } popup; |
| 282 | |
Alex Wu | 4539b08 | 2012-03-01 12:57:46 +0800 | [diff] [blame] | 283 | struct { |
Tiago Vignatti | 52e598c | 2012-05-07 15:23:08 +0300 | [diff] [blame] | 284 | int32_t x, y; |
Tiago Vignatti | 491bac1 | 2012-05-18 16:37:43 -0400 | [diff] [blame] | 285 | uint32_t flags; |
Tiago Vignatti | 52e598c | 2012-05-07 15:23:08 +0300 | [diff] [blame] | 286 | } transient; |
| 287 | |
| 288 | struct { |
Alex Wu | 4539b08 | 2012-03-01 12:57:46 +0800 | [diff] [blame] | 289 | enum wl_shell_surface_fullscreen_method type; |
| 290 | struct weston_transform transform; /* matrix from x, y */ |
| 291 | uint32_t framerate; |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 292 | struct weston_view *black_view; |
Alex Wu | 4539b08 | 2012-03-01 12:57:46 +0800 | [diff] [blame] | 293 | } fullscreen; |
| 294 | |
Scott Moreau | ff1db4a | 2012-04-17 19:06:18 -0600 | [diff] [blame] | 295 | struct ping_timer *ping_timer; |
| 296 | |
Jonas Ådahl | 62fcd04 | 2012-06-13 00:01:23 +0200 | [diff] [blame] | 297 | struct weston_transform workspace_transform; |
| 298 | |
Kristian Høgsberg | 1cbf326 | 2012-02-17 23:49:07 -0500 | [diff] [blame] | 299 | struct weston_output *fullscreen_output; |
Kristian Høgsberg | 8334bc1 | 2012-01-03 10:29:47 -0500 | [diff] [blame] | 300 | struct weston_output *output; |
Benjamin Franzke | d0f79ab | 2011-11-22 12:43:52 +0100 | [diff] [blame] | 301 | struct wl_list link; |
Kristian Høgsberg | a61ca06 | 2012-05-22 16:05:52 -0400 | [diff] [blame] | 302 | |
| 303 | const struct weston_shell_client *client; |
Pekka Paalanen | 56cdea9 | 2011-11-23 16:14:12 +0200 | [diff] [blame] | 304 | }; |
| 305 | |
Ander Conselvan de Oliveira | fe0444a | 2012-04-04 17:48:05 +0300 | [diff] [blame] | 306 | struct shell_grab { |
Kristian Høgsberg | 02bbabb | 2013-05-06 22:15:05 -0400 | [diff] [blame] | 307 | struct weston_pointer_grab grab; |
Ander Conselvan de Oliveira | fe0444a | 2012-04-04 17:48:05 +0300 | [diff] [blame] | 308 | struct shell_surface *shsurf; |
| 309 | struct wl_listener shsurf_destroy_listener; |
| 310 | }; |
| 311 | |
Rusty Lynch | 1084da5 | 2013-08-15 09:10:08 -0700 | [diff] [blame] | 312 | struct shell_touch_grab { |
| 313 | struct weston_touch_grab grab; |
| 314 | struct shell_surface *shsurf; |
| 315 | struct wl_listener shsurf_destroy_listener; |
| 316 | struct weston_touch *touch; |
| 317 | }; |
| 318 | |
Ander Conselvan de Oliveira | fe0444a | 2012-04-04 17:48:05 +0300 | [diff] [blame] | 319 | struct weston_move_grab { |
| 320 | struct shell_grab base; |
Daniel Stone | 103db7f | 2012-05-08 17:17:55 +0100 | [diff] [blame] | 321 | wl_fixed_t dx, dy; |
Kristian Høgsberg | 4cca349 | 2011-01-18 07:53:49 -0500 | [diff] [blame] | 322 | }; |
| 323 | |
Rusty Lynch | 1084da5 | 2013-08-15 09:10:08 -0700 | [diff] [blame] | 324 | struct weston_touch_move_grab { |
| 325 | struct shell_touch_grab base; |
| 326 | wl_fixed_t dx, dy; |
| 327 | }; |
| 328 | |
Pekka Paalanen | 460099f | 2012-01-20 16:48:25 +0200 | [diff] [blame] | 329 | struct rotate_grab { |
Ander Conselvan de Oliveira | fe0444a | 2012-04-04 17:48:05 +0300 | [diff] [blame] | 330 | struct shell_grab base; |
Kristian Høgsberg | 765e27b | 2012-01-27 13:36:13 -0500 | [diff] [blame] | 331 | struct weston_matrix rotation; |
Pekka Paalanen | 460099f | 2012-01-20 16:48:25 +0200 | [diff] [blame] | 332 | struct { |
John Kåre Alsaker | 490d02a | 2012-09-30 02:57:21 +0200 | [diff] [blame] | 333 | float x; |
| 334 | float y; |
Pekka Paalanen | 460099f | 2012-01-20 16:48:25 +0200 | [diff] [blame] | 335 | } center; |
| 336 | }; |
| 337 | |
Giulio Camuffo | 5085a75 | 2013-03-25 21:42:45 +0100 | [diff] [blame] | 338 | struct shell_seat { |
| 339 | struct weston_seat *seat; |
| 340 | struct wl_listener seat_destroy_listener; |
| 341 | |
| 342 | struct { |
Kristian Høgsberg | 02bbabb | 2013-05-06 22:15:05 -0400 | [diff] [blame] | 343 | struct weston_pointer_grab grab; |
Giulio Camuffo | 5085a75 | 2013-03-25 21:42:45 +0100 | [diff] [blame] | 344 | struct wl_list surfaces_list; |
| 345 | struct wl_client *client; |
| 346 | int32_t initial_up; |
| 347 | } popup_grab; |
| 348 | }; |
| 349 | |
Kristian Høgsberg | 2f5faff | 2012-07-31 16:36:34 -0400 | [diff] [blame] | 350 | static void |
| 351 | activate(struct desktop_shell *shell, struct weston_surface *es, |
| 352 | struct weston_seat *seat); |
| 353 | |
| 354 | static struct workspace * |
| 355 | get_current_workspace(struct desktop_shell *shell); |
| 356 | |
Alex Wu | bd3354b | 2012-04-17 17:20:49 +0800 | [diff] [blame] | 357 | static struct shell_surface * |
| 358 | get_shell_surface(struct weston_surface *surface); |
| 359 | |
| 360 | static struct desktop_shell * |
| 361 | shell_surface_get_shell(struct shell_surface *shsurf); |
| 362 | |
Kristian Høgsberg | 0c36903 | 2013-02-14 21:31:44 -0500 | [diff] [blame] | 363 | static void |
Kristian Høgsberg | e314875 | 2013-05-06 23:19:49 -0400 | [diff] [blame] | 364 | surface_rotate(struct shell_surface *surface, struct weston_seat *seat); |
Kristian Høgsberg | 0c36903 | 2013-02-14 21:31:44 -0500 | [diff] [blame] | 365 | |
Pekka Paalanen | 79346ab | 2013-05-22 18:03:09 +0300 | [diff] [blame] | 366 | static void |
| 367 | shell_fade_startup(struct desktop_shell *shell); |
| 368 | |
Alex Wu | bd3354b | 2012-04-17 17:20:49 +0800 | [diff] [blame] | 369 | static bool |
| 370 | shell_surface_is_top_fullscreen(struct shell_surface *shsurf) |
| 371 | { |
| 372 | struct desktop_shell *shell; |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 373 | struct weston_view *top_fs_ev; |
Alex Wu | bd3354b | 2012-04-17 17:20:49 +0800 | [diff] [blame] | 374 | |
| 375 | shell = shell_surface_get_shell(shsurf); |
Quentin Glidic | c0d79ce | 2013-01-29 14:16:13 +0100 | [diff] [blame] | 376 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 377 | if (wl_list_empty(&shell->fullscreen_layer.view_list)) |
Alex Wu | bd3354b | 2012-04-17 17:20:49 +0800 | [diff] [blame] | 378 | return false; |
| 379 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 380 | top_fs_ev = container_of(shell->fullscreen_layer.view_list.next, |
| 381 | struct weston_view, |
Alex Wu | bd3354b | 2012-04-17 17:20:49 +0800 | [diff] [blame] | 382 | layer_link); |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 383 | return (shsurf == get_shell_surface(top_fs_ev->surface)); |
Alex Wu | bd3354b | 2012-04-17 17:20:49 +0800 | [diff] [blame] | 384 | } |
| 385 | |
Kristian Høgsberg | 6af8eb9 | 2012-01-25 16:57:11 -0500 | [diff] [blame] | 386 | static void |
Kristian Høgsberg | 27e3052 | 2012-04-11 23:18:23 -0400 | [diff] [blame] | 387 | destroy_shell_grab_shsurf(struct wl_listener *listener, void *data) |
Ander Conselvan de Oliveira | fe0444a | 2012-04-04 17:48:05 +0300 | [diff] [blame] | 388 | { |
| 389 | struct shell_grab *grab; |
| 390 | |
| 391 | grab = container_of(listener, struct shell_grab, |
| 392 | shsurf_destroy_listener); |
| 393 | |
| 394 | grab->shsurf = NULL; |
| 395 | } |
| 396 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 397 | static struct weston_view * |
| 398 | get_default_view(struct weston_surface *surface) |
| 399 | { |
| 400 | struct shell_surface *shsurf; |
| 401 | struct weston_view *view; |
| 402 | |
| 403 | if (!surface || wl_list_empty(&surface->views)) |
| 404 | return NULL; |
| 405 | |
| 406 | shsurf = get_shell_surface(surface); |
| 407 | if (shsurf) |
| 408 | return shsurf->view; |
| 409 | |
| 410 | wl_list_for_each(view, &surface->views, surface_link) |
| 411 | if (weston_view_is_mapped(view)) |
| 412 | return view; |
| 413 | |
| 414 | return container_of(surface->views.next, struct weston_view, surface_link); |
| 415 | } |
| 416 | |
Ander Conselvan de Oliveira | fe0444a | 2012-04-04 17:48:05 +0300 | [diff] [blame] | 417 | static void |
Kristian Høgsberg | 02bbabb | 2013-05-06 22:15:05 -0400 | [diff] [blame] | 418 | popup_grab_end(struct weston_pointer *pointer); |
Kristian Høgsberg | 57e0907 | 2012-10-30 14:07:27 -0400 | [diff] [blame] | 419 | |
| 420 | static void |
Ander Conselvan de Oliveira | b9d2a0f | 2012-06-28 18:08:05 +0300 | [diff] [blame] | 421 | shell_grab_start(struct shell_grab *grab, |
Kristian Høgsberg | 02bbabb | 2013-05-06 22:15:05 -0400 | [diff] [blame] | 422 | const struct weston_pointer_grab_interface *interface, |
Ander Conselvan de Oliveira | b9d2a0f | 2012-06-28 18:08:05 +0300 | [diff] [blame] | 423 | struct shell_surface *shsurf, |
Kristian Høgsberg | 02bbabb | 2013-05-06 22:15:05 -0400 | [diff] [blame] | 424 | struct weston_pointer *pointer, |
Ander Conselvan de Oliveira | b9d2a0f | 2012-06-28 18:08:05 +0300 | [diff] [blame] | 425 | enum desktop_shell_cursor cursor) |
Ander Conselvan de Oliveira | fe0444a | 2012-04-04 17:48:05 +0300 | [diff] [blame] | 426 | { |
Ander Conselvan de Oliveira | b9d2a0f | 2012-06-28 18:08:05 +0300 | [diff] [blame] | 427 | struct desktop_shell *shell = shsurf->shell; |
| 428 | |
Kristian Høgsberg | 57e0907 | 2012-10-30 14:07:27 -0400 | [diff] [blame] | 429 | popup_grab_end(pointer); |
| 430 | |
Ander Conselvan de Oliveira | fe0444a | 2012-04-04 17:48:05 +0300 | [diff] [blame] | 431 | grab->grab.interface = interface; |
| 432 | grab->shsurf = shsurf; |
Kristian Høgsberg | 27e3052 | 2012-04-11 23:18:23 -0400 | [diff] [blame] | 433 | grab->shsurf_destroy_listener.notify = destroy_shell_grab_shsurf; |
Jason Ekstrand | 651f00e | 2013-06-14 10:07:54 -0500 | [diff] [blame] | 434 | wl_signal_add(&shsurf->destroy_signal, |
Kristian Høgsberg | 27e3052 | 2012-04-11 23:18:23 -0400 | [diff] [blame] | 435 | &grab->shsurf_destroy_listener); |
Ander Conselvan de Oliveira | fe0444a | 2012-04-04 17:48:05 +0300 | [diff] [blame] | 436 | |
Kristian Høgsberg | c85f1d4 | 2013-10-24 16:52:00 -0700 | [diff] [blame] | 437 | shsurf->grabbed = 1; |
Kristian Høgsberg | 02bbabb | 2013-05-06 22:15:05 -0400 | [diff] [blame] | 438 | weston_pointer_start_grab(pointer, &grab->grab); |
Kristian Høgsberg | c9974a0 | 2013-07-03 19:24:57 -0400 | [diff] [blame] | 439 | if (shell->child.desktop_shell) { |
| 440 | desktop_shell_send_grab_cursor(shell->child.desktop_shell, |
| 441 | cursor); |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 442 | weston_pointer_set_focus(pointer, |
| 443 | get_default_view(shell->grab_surface), |
Kristian Høgsberg | c9974a0 | 2013-07-03 19:24:57 -0400 | [diff] [blame] | 444 | wl_fixed_from_int(0), |
| 445 | wl_fixed_from_int(0)); |
| 446 | } |
Ander Conselvan de Oliveira | fe0444a | 2012-04-04 17:48:05 +0300 | [diff] [blame] | 447 | } |
| 448 | |
| 449 | static void |
Ander Conselvan de Oliveira | b9d2a0f | 2012-06-28 18:08:05 +0300 | [diff] [blame] | 450 | shell_grab_end(struct shell_grab *grab) |
Ander Conselvan de Oliveira | fe0444a | 2012-04-04 17:48:05 +0300 | [diff] [blame] | 451 | { |
Kristian Høgsberg | c85f1d4 | 2013-10-24 16:52:00 -0700 | [diff] [blame] | 452 | if (grab->shsurf) { |
Kristian Høgsberg | 47b5dca | 2012-06-07 18:08:04 -0400 | [diff] [blame] | 453 | wl_list_remove(&grab->shsurf_destroy_listener.link); |
Kristian Høgsberg | c85f1d4 | 2013-10-24 16:52:00 -0700 | [diff] [blame] | 454 | grab->shsurf->grabbed = 0; |
| 455 | } |
Ander Conselvan de Oliveira | b9d2a0f | 2012-06-28 18:08:05 +0300 | [diff] [blame] | 456 | |
Kristian Høgsberg | 9e5d7d1 | 2013-07-22 16:31:53 -0700 | [diff] [blame] | 457 | weston_pointer_end_grab(grab->grab.pointer); |
Ander Conselvan de Oliveira | fe0444a | 2012-04-04 17:48:05 +0300 | [diff] [blame] | 458 | } |
| 459 | |
| 460 | static void |
Rusty Lynch | 1084da5 | 2013-08-15 09:10:08 -0700 | [diff] [blame] | 461 | shell_touch_grab_start(struct shell_touch_grab *grab, |
| 462 | const struct weston_touch_grab_interface *interface, |
| 463 | struct shell_surface *shsurf, |
| 464 | struct weston_touch *touch) |
| 465 | { |
| 466 | struct desktop_shell *shell = shsurf->shell; |
| 467 | |
| 468 | grab->grab.interface = interface; |
| 469 | grab->shsurf = shsurf; |
| 470 | grab->shsurf_destroy_listener.notify = destroy_shell_grab_shsurf; |
| 471 | wl_signal_add(&shsurf->destroy_signal, |
| 472 | &grab->shsurf_destroy_listener); |
| 473 | |
| 474 | grab->touch = touch; |
Kristian Høgsberg | c85f1d4 | 2013-10-24 16:52:00 -0700 | [diff] [blame] | 475 | shsurf->grabbed = 1; |
Rusty Lynch | 1084da5 | 2013-08-15 09:10:08 -0700 | [diff] [blame] | 476 | |
| 477 | weston_touch_start_grab(touch, &grab->grab); |
| 478 | if (shell->child.desktop_shell) |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 479 | weston_touch_set_focus(touch->seat, |
| 480 | get_default_view(shell->grab_surface)); |
Rusty Lynch | 1084da5 | 2013-08-15 09:10:08 -0700 | [diff] [blame] | 481 | } |
| 482 | |
| 483 | static void |
| 484 | shell_touch_grab_end(struct shell_touch_grab *grab) |
| 485 | { |
Kristian Høgsberg | c85f1d4 | 2013-10-24 16:52:00 -0700 | [diff] [blame] | 486 | if (grab->shsurf) { |
Rusty Lynch | 1084da5 | 2013-08-15 09:10:08 -0700 | [diff] [blame] | 487 | wl_list_remove(&grab->shsurf_destroy_listener.link); |
Kristian Høgsberg | c85f1d4 | 2013-10-24 16:52:00 -0700 | [diff] [blame] | 488 | grab->shsurf->grabbed = 0; |
| 489 | } |
Rusty Lynch | 1084da5 | 2013-08-15 09:10:08 -0700 | [diff] [blame] | 490 | |
| 491 | weston_touch_end_grab(grab->touch); |
| 492 | } |
| 493 | |
| 494 | static void |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 495 | center_on_output(struct weston_view *view, |
Alex Wu | 4539b08 | 2012-03-01 12:57:46 +0800 | [diff] [blame] | 496 | struct weston_output *output); |
| 497 | |
Daniel Stone | 496ca17 | 2012-05-30 16:31:42 +0100 | [diff] [blame] | 498 | static enum weston_keyboard_modifier |
Tiago Vignatti | 0b52d48 | 2012-04-20 18:54:25 +0300 | [diff] [blame] | 499 | get_modifier(char *modifier) |
| 500 | { |
| 501 | if (!modifier) |
| 502 | return MODIFIER_SUPER; |
| 503 | |
| 504 | if (!strcmp("ctrl", modifier)) |
| 505 | return MODIFIER_CTRL; |
| 506 | else if (!strcmp("alt", modifier)) |
| 507 | return MODIFIER_ALT; |
| 508 | else if (!strcmp("super", modifier)) |
| 509 | return MODIFIER_SUPER; |
| 510 | else |
| 511 | return MODIFIER_SUPER; |
| 512 | } |
| 513 | |
Juan Zhao | e10d279 | 2012-04-25 19:09:52 +0800 | [diff] [blame] | 514 | static enum animation_type |
| 515 | get_animation_type(char *animation) |
| 516 | { |
Juan Zhao | e10d279 | 2012-04-25 19:09:52 +0800 | [diff] [blame] | 517 | if (!strcmp("zoom", animation)) |
| 518 | return ANIMATION_ZOOM; |
| 519 | else if (!strcmp("fade", animation)) |
| 520 | return ANIMATION_FADE; |
Louis-Francis Ratté-Boulianne | b482dbd | 2013-11-19 11:37:11 +0100 | [diff] [blame] | 521 | else if (!strcmp("dim-layer", animation)) |
| 522 | return ANIMATION_DIM_LAYER; |
Juan Zhao | e10d279 | 2012-04-25 19:09:52 +0800 | [diff] [blame] | 523 | else |
| 524 | return ANIMATION_NONE; |
| 525 | } |
| 526 | |
Alex Wu | 4539b08 | 2012-03-01 12:57:46 +0800 | [diff] [blame] | 527 | static void |
Kristian Høgsberg | 14e438c | 2013-05-26 21:48:14 -0400 | [diff] [blame] | 528 | shell_configuration(struct desktop_shell *shell) |
Pekka Paalanen | e955f1e | 2011-12-07 11:49:52 +0200 | [diff] [blame] | 529 | { |
Kristian Høgsberg | 673a889 | 2013-05-23 21:40:56 -0400 | [diff] [blame] | 530 | struct weston_config_section *section; |
| 531 | int duration; |
| 532 | char *s; |
Pekka Paalanen | e955f1e | 2011-12-07 11:49:52 +0200 | [diff] [blame] | 533 | |
Kristian Høgsberg | 673a889 | 2013-05-23 21:40:56 -0400 | [diff] [blame] | 534 | section = weston_config_get_section(shell->compositor->config, |
| 535 | "screensaver", NULL, NULL); |
| 536 | weston_config_section_get_string(section, |
| 537 | "path", &shell->screensaver.path, NULL); |
| 538 | weston_config_section_get_int(section, "duration", &duration, 60); |
Ander Conselvan de Oliveira | 859e885 | 2013-02-21 18:35:21 +0200 | [diff] [blame] | 539 | shell->screensaver.duration = duration * 1000; |
Kristian Høgsberg | 673a889 | 2013-05-23 21:40:56 -0400 | [diff] [blame] | 540 | |
| 541 | section = weston_config_get_section(shell->compositor->config, |
| 542 | "shell", NULL, NULL); |
| 543 | weston_config_section_get_string(section, |
Emilio Pozuelo Monfort | 46ce798 | 2013-11-20 13:22:29 +0100 | [diff] [blame] | 544 | "client", &s, LIBEXECDIR "/weston-desktop-shell"); |
| 545 | shell->client = s; |
| 546 | weston_config_section_get_string(section, |
Kristian Høgsberg | 673a889 | 2013-05-23 21:40:56 -0400 | [diff] [blame] | 547 | "binding-modifier", &s, "super"); |
| 548 | shell->binding_modifier = get_modifier(s); |
Quentin Glidic | 8418c29 | 2013-06-18 09:11:03 +0200 | [diff] [blame] | 549 | free(s); |
Kristian Høgsberg | 673a889 | 2013-05-23 21:40:56 -0400 | [diff] [blame] | 550 | weston_config_section_get_string(section, "animation", &s, "none"); |
| 551 | shell->win_animation_type = get_animation_type(s); |
Quentin Glidic | 8418c29 | 2013-06-18 09:11:03 +0200 | [diff] [blame] | 552 | free(s); |
Kristian Høgsberg | 724c8d9 | 2013-10-16 11:38:24 -0700 | [diff] [blame] | 553 | weston_config_section_get_string(section, |
| 554 | "startup-animation", &s, "fade"); |
| 555 | shell->startup_animation_type = get_animation_type(s); |
| 556 | free(s); |
Kristian Høgsberg | 912e0a1 | 2013-10-30 08:59:55 -0700 | [diff] [blame] | 557 | if (shell->startup_animation_type == ANIMATION_ZOOM) |
| 558 | shell->startup_animation_type = ANIMATION_NONE; |
Louis-Francis Ratté-Boulianne | b482dbd | 2013-11-19 11:37:11 +0100 | [diff] [blame] | 559 | weston_config_section_get_string(section, "focus-animation", &s, "none"); |
| 560 | shell->focus_animation_type = get_animation_type(s); |
| 561 | free(s); |
Kristian Høgsberg | 673a889 | 2013-05-23 21:40:56 -0400 | [diff] [blame] | 562 | weston_config_section_get_uint(section, "num-workspaces", |
| 563 | &shell->workspaces.num, |
| 564 | DEFAULT_NUM_WORKSPACES); |
Jonas Ådahl | e3cddce | 2012-06-13 00:01:22 +0200 | [diff] [blame] | 565 | } |
| 566 | |
Louis-Francis Ratté-Boulianne | b482dbd | 2013-11-19 11:37:11 +0100 | [diff] [blame] | 567 | static struct weston_output * |
| 568 | get_default_output(struct weston_compositor *compositor) |
| 569 | { |
| 570 | return container_of(compositor->output_list.next, |
| 571 | struct weston_output, link); |
| 572 | } |
| 573 | |
| 574 | |
| 575 | /* no-op func for checking focus surface */ |
| 576 | static void |
| 577 | focus_surface_configure(struct weston_surface *es, int32_t sx, int32_t sy, |
| 578 | int32_t width, int32_t height) |
| 579 | { |
| 580 | } |
| 581 | |
| 582 | static struct focus_surface * |
| 583 | get_focus_surface(struct weston_surface *surface) |
| 584 | { |
| 585 | if (surface->configure == focus_surface_configure) |
| 586 | return surface->configure_private; |
| 587 | else |
| 588 | return NULL; |
| 589 | } |
| 590 | |
| 591 | static bool |
| 592 | is_focus_surface (struct weston_surface *es) |
| 593 | { |
| 594 | return (es->configure == focus_surface_configure); |
| 595 | } |
| 596 | |
| 597 | static bool |
| 598 | is_focus_view (struct weston_view *view) |
| 599 | { |
| 600 | return is_focus_surface (view->surface); |
| 601 | } |
| 602 | |
| 603 | static struct focus_surface * |
| 604 | create_focus_surface(struct weston_compositor *ec, |
| 605 | struct weston_output *output) |
| 606 | { |
| 607 | struct focus_surface *fsurf = NULL; |
| 608 | struct weston_surface *surface = NULL; |
| 609 | |
| 610 | fsurf = malloc(sizeof *fsurf); |
| 611 | if (!fsurf) |
| 612 | return NULL; |
| 613 | |
| 614 | fsurf->surface = weston_surface_create(ec); |
| 615 | surface = fsurf->surface; |
| 616 | if (surface == NULL) { |
| 617 | free(fsurf); |
| 618 | return NULL; |
| 619 | } |
| 620 | |
| 621 | surface->configure = focus_surface_configure; |
| 622 | surface->output = output; |
| 623 | surface->configure_private = fsurf; |
| 624 | |
| 625 | fsurf->view = weston_view_create (surface); |
Emilio Pozuelo Monfort | da64426 | 2013-11-19 11:37:19 +0100 | [diff] [blame] | 626 | fsurf->view->output = output; |
Louis-Francis Ratté-Boulianne | b482dbd | 2013-11-19 11:37:11 +0100 | [diff] [blame] | 627 | |
| 628 | weston_view_configure(fsurf->view, output->x, output->y, |
| 629 | output->width, output->height); |
| 630 | weston_surface_set_color(surface, 0.0, 0.0, 0.0, 1.0); |
| 631 | pixman_region32_fini(&surface->opaque); |
| 632 | pixman_region32_init_rect(&surface->opaque, output->x, output->y, |
| 633 | output->width, output->height); |
| 634 | pixman_region32_fini(&surface->input); |
| 635 | pixman_region32_init(&surface->input); |
| 636 | |
| 637 | wl_list_init(&fsurf->workspace_transform.link); |
| 638 | |
| 639 | return fsurf; |
| 640 | } |
| 641 | |
| 642 | static void |
| 643 | focus_surface_destroy(struct focus_surface *fsurf) |
| 644 | { |
| 645 | weston_surface_destroy(fsurf->surface); |
| 646 | free(fsurf); |
| 647 | } |
| 648 | |
| 649 | static void |
| 650 | focus_animation_done(struct weston_view_animation *animation, void *data) |
| 651 | { |
| 652 | struct workspace *ws = data; |
| 653 | |
| 654 | ws->focus_animation = NULL; |
| 655 | } |
| 656 | |
Jonas Ådahl | e3cddce | 2012-06-13 00:01:22 +0200 | [diff] [blame] | 657 | static void |
Jonas Ådahl | 0476974 | 2012-06-13 00:01:24 +0200 | [diff] [blame] | 658 | focus_state_destroy(struct focus_state *state) |
| 659 | { |
| 660 | wl_list_remove(&state->seat_destroy_listener.link); |
| 661 | wl_list_remove(&state->surface_destroy_listener.link); |
| 662 | free(state); |
| 663 | } |
| 664 | |
| 665 | static void |
| 666 | focus_state_seat_destroy(struct wl_listener *listener, void *data) |
| 667 | { |
| 668 | struct focus_state *state = container_of(listener, |
| 669 | struct focus_state, |
| 670 | seat_destroy_listener); |
| 671 | |
| 672 | wl_list_remove(&state->link); |
| 673 | focus_state_destroy(state); |
| 674 | } |
| 675 | |
| 676 | static void |
| 677 | focus_state_surface_destroy(struct wl_listener *listener, void *data) |
| 678 | { |
| 679 | struct focus_state *state = container_of(listener, |
| 680 | struct focus_state, |
Kristian Høgsberg | b8e0d0f | 2012-07-31 10:30:26 -0400 | [diff] [blame] | 681 | surface_destroy_listener); |
Kristian Høgsberg | e377822 | 2012-07-31 17:29:30 -0400 | [diff] [blame] | 682 | struct desktop_shell *shell; |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 683 | struct weston_surface *main_surface, *next; |
| 684 | struct weston_view *view; |
Jonas Ådahl | 0476974 | 2012-06-13 00:01:24 +0200 | [diff] [blame] | 685 | |
Pekka Paalanen | 01388e2 | 2013-04-25 13:57:44 +0300 | [diff] [blame] | 686 | main_surface = weston_surface_get_main_surface(state->keyboard_focus); |
| 687 | |
Kristian Høgsberg | e377822 | 2012-07-31 17:29:30 -0400 | [diff] [blame] | 688 | next = NULL; |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 689 | wl_list_for_each(view, &state->ws->layer.view_list, layer_link) { |
| 690 | if (view->surface == main_surface) |
Kristian Høgsberg | e377822 | 2012-07-31 17:29:30 -0400 | [diff] [blame] | 691 | continue; |
Louis-Francis Ratté-Boulianne | b482dbd | 2013-11-19 11:37:11 +0100 | [diff] [blame] | 692 | if (is_focus_view(view)) |
| 693 | continue; |
Kristian Høgsberg | e377822 | 2012-07-31 17:29:30 -0400 | [diff] [blame] | 694 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 695 | next = view->surface; |
Kristian Høgsberg | e377822 | 2012-07-31 17:29:30 -0400 | [diff] [blame] | 696 | break; |
| 697 | } |
| 698 | |
Pekka Paalanen | 01388e2 | 2013-04-25 13:57:44 +0300 | [diff] [blame] | 699 | /* if the focus was a sub-surface, activate its main surface */ |
| 700 | if (main_surface != state->keyboard_focus) |
| 701 | next = main_surface; |
| 702 | |
Louis-Francis Ratté-Boulianne | b482dbd | 2013-11-19 11:37:11 +0100 | [diff] [blame] | 703 | shell = state->seat->compositor->shell_interface.shell; |
Kristian Høgsberg | e377822 | 2012-07-31 17:29:30 -0400 | [diff] [blame] | 704 | if (next) { |
Louis-Francis Ratté-Boulianne | b482dbd | 2013-11-19 11:37:11 +0100 | [diff] [blame] | 705 | state->keyboard_focus = NULL; |
Kristian Høgsberg | e377822 | 2012-07-31 17:29:30 -0400 | [diff] [blame] | 706 | activate(shell, next, state->seat); |
| 707 | } else { |
Louis-Francis Ratté-Boulianne | b482dbd | 2013-11-19 11:37:11 +0100 | [diff] [blame] | 708 | if (shell->focus_animation_type == ANIMATION_DIM_LAYER) { |
| 709 | if (state->ws->focus_animation) |
| 710 | weston_view_animation_destroy(state->ws->focus_animation); |
| 711 | |
| 712 | state->ws->focus_animation = weston_fade_run( |
| 713 | state->ws->fsurf_front->view, |
| 714 | state->ws->fsurf_front->view->alpha, 0.0, 300, |
| 715 | focus_animation_done, state->ws); |
| 716 | } |
| 717 | |
Kristian Høgsberg | e377822 | 2012-07-31 17:29:30 -0400 | [diff] [blame] | 718 | wl_list_remove(&state->link); |
| 719 | focus_state_destroy(state); |
| 720 | } |
Jonas Ådahl | 0476974 | 2012-06-13 00:01:24 +0200 | [diff] [blame] | 721 | } |
| 722 | |
| 723 | static struct focus_state * |
Kristian Høgsberg | 2f5faff | 2012-07-31 16:36:34 -0400 | [diff] [blame] | 724 | focus_state_create(struct weston_seat *seat, struct workspace *ws) |
Jonas Ådahl | 0476974 | 2012-06-13 00:01:24 +0200 | [diff] [blame] | 725 | { |
Jonas Ådahl | 0476974 | 2012-06-13 00:01:24 +0200 | [diff] [blame] | 726 | struct focus_state *state; |
Jonas Ådahl | 0476974 | 2012-06-13 00:01:24 +0200 | [diff] [blame] | 727 | |
| 728 | state = malloc(sizeof *state); |
| 729 | if (state == NULL) |
| 730 | return NULL; |
| 731 | |
Louis-Francis Ratté-Boulianne | b482dbd | 2013-11-19 11:37:11 +0100 | [diff] [blame] | 732 | state->keyboard_focus = NULL; |
Kristian Høgsberg | 2f5faff | 2012-07-31 16:36:34 -0400 | [diff] [blame] | 733 | state->ws = ws; |
Jonas Ådahl | 0476974 | 2012-06-13 00:01:24 +0200 | [diff] [blame] | 734 | state->seat = seat; |
Kristian Høgsberg | 2f5faff | 2012-07-31 16:36:34 -0400 | [diff] [blame] | 735 | wl_list_insert(&ws->focus_list, &state->link); |
Jonas Ådahl | 0476974 | 2012-06-13 00:01:24 +0200 | [diff] [blame] | 736 | |
| 737 | state->seat_destroy_listener.notify = focus_state_seat_destroy; |
| 738 | state->surface_destroy_listener.notify = focus_state_surface_destroy; |
Kristian Høgsberg | 4912454 | 2013-05-06 22:27:40 -0400 | [diff] [blame] | 739 | wl_signal_add(&seat->destroy_signal, |
Jonas Ådahl | 0476974 | 2012-06-13 00:01:24 +0200 | [diff] [blame] | 740 | &state->seat_destroy_listener); |
Kristian Høgsberg | 2f5faff | 2012-07-31 16:36:34 -0400 | [diff] [blame] | 741 | wl_list_init(&state->surface_destroy_listener.link); |
Jonas Ådahl | 0476974 | 2012-06-13 00:01:24 +0200 | [diff] [blame] | 742 | |
| 743 | return state; |
| 744 | } |
| 745 | |
Jonas Ådahl | 8538b22 | 2012-08-29 22:13:03 +0200 | [diff] [blame] | 746 | static struct focus_state * |
| 747 | ensure_focus_state(struct desktop_shell *shell, struct weston_seat *seat) |
| 748 | { |
| 749 | struct workspace *ws = get_current_workspace(shell); |
| 750 | struct focus_state *state; |
| 751 | |
| 752 | wl_list_for_each(state, &ws->focus_list, link) |
| 753 | if (state->seat == seat) |
| 754 | break; |
| 755 | |
| 756 | if (&state->link == &ws->focus_list) |
| 757 | state = focus_state_create(seat, ws); |
| 758 | |
| 759 | return state; |
| 760 | } |
| 761 | |
Jonas Ådahl | 0476974 | 2012-06-13 00:01:24 +0200 | [diff] [blame] | 762 | static void |
Kristian Høgsberg | 2f5faff | 2012-07-31 16:36:34 -0400 | [diff] [blame] | 763 | restore_focus_state(struct desktop_shell *shell, struct workspace *ws) |
Jonas Ådahl | 0476974 | 2012-06-13 00:01:24 +0200 | [diff] [blame] | 764 | { |
| 765 | struct focus_state *state, *next; |
Kristian Høgsberg | fe7aa90 | 2013-05-08 09:54:37 -0400 | [diff] [blame] | 766 | struct weston_surface *surface; |
Jonas Ådahl | 0476974 | 2012-06-13 00:01:24 +0200 | [diff] [blame] | 767 | |
| 768 | wl_list_for_each_safe(state, next, &ws->focus_list, link) { |
Kristian Høgsberg | fe7aa90 | 2013-05-08 09:54:37 -0400 | [diff] [blame] | 769 | surface = state->keyboard_focus; |
Jonas Ådahl | 5689944 | 2012-08-29 22:12:59 +0200 | [diff] [blame] | 770 | |
Kristian Høgsberg | e314875 | 2013-05-06 23:19:49 -0400 | [diff] [blame] | 771 | weston_keyboard_set_focus(state->seat->keyboard, surface); |
Jonas Ådahl | 0476974 | 2012-06-13 00:01:24 +0200 | [diff] [blame] | 772 | } |
| 773 | } |
| 774 | |
| 775 | static void |
Jonas Ådahl | 8de6a1d | 2012-08-29 22:13:00 +0200 | [diff] [blame] | 776 | replace_focus_state(struct desktop_shell *shell, struct workspace *ws, |
| 777 | struct weston_seat *seat) |
| 778 | { |
| 779 | struct focus_state *state; |
Kristian Høgsberg | fe7aa90 | 2013-05-08 09:54:37 -0400 | [diff] [blame] | 780 | struct weston_surface *surface; |
Jonas Ådahl | 8de6a1d | 2012-08-29 22:13:00 +0200 | [diff] [blame] | 781 | |
| 782 | wl_list_for_each(state, &ws->focus_list, link) { |
| 783 | if (state->seat == seat) { |
Kristian Høgsberg | e314875 | 2013-05-06 23:19:49 -0400 | [diff] [blame] | 784 | surface = seat->keyboard->focus; |
Jason Ekstrand | 651f00e | 2013-06-14 10:07:54 -0500 | [diff] [blame] | 785 | state->keyboard_focus = surface; |
Jonas Ådahl | 8de6a1d | 2012-08-29 22:13:00 +0200 | [diff] [blame] | 786 | return; |
| 787 | } |
| 788 | } |
| 789 | } |
| 790 | |
| 791 | static void |
| 792 | drop_focus_state(struct desktop_shell *shell, struct workspace *ws, |
| 793 | struct weston_surface *surface) |
| 794 | { |
| 795 | struct focus_state *state; |
| 796 | |
| 797 | wl_list_for_each(state, &ws->focus_list, link) |
| 798 | if (state->keyboard_focus == surface) |
| 799 | state->keyboard_focus = NULL; |
| 800 | } |
| 801 | |
| 802 | static void |
Louis-Francis Ratté-Boulianne | b482dbd | 2013-11-19 11:37:11 +0100 | [diff] [blame] | 803 | animate_focus_change(struct desktop_shell *shell, struct workspace *ws, |
| 804 | struct weston_view *from, struct weston_view *to) |
| 805 | { |
| 806 | struct weston_output *output; |
| 807 | bool focus_surface_created = false; |
| 808 | |
| 809 | /* FIXME: Only support dim animation using two layers */ |
| 810 | if (from == to || shell->focus_animation_type != ANIMATION_DIM_LAYER) |
| 811 | return; |
| 812 | |
| 813 | output = get_default_output(shell->compositor); |
| 814 | if (ws->fsurf_front == NULL && (from || to)) { |
| 815 | ws->fsurf_front = create_focus_surface(shell->compositor, output); |
| 816 | ws->fsurf_back = create_focus_surface(shell->compositor, output); |
| 817 | ws->fsurf_front->view->alpha = 0.0; |
| 818 | ws->fsurf_back->view->alpha = 0.0; |
| 819 | focus_surface_created = true; |
| 820 | } else { |
| 821 | wl_list_remove(&ws->fsurf_front->view->layer_link); |
| 822 | wl_list_remove(&ws->fsurf_back->view->layer_link); |
| 823 | } |
| 824 | |
| 825 | if (ws->focus_animation) { |
| 826 | weston_view_animation_destroy(ws->focus_animation); |
| 827 | ws->focus_animation = NULL; |
| 828 | } |
| 829 | |
| 830 | if (to) |
| 831 | wl_list_insert(&to->layer_link, |
| 832 | &ws->fsurf_front->view->layer_link); |
| 833 | else if (from) |
| 834 | wl_list_insert(&ws->layer.view_list, |
| 835 | &ws->fsurf_front->view->layer_link); |
| 836 | |
| 837 | if (focus_surface_created) { |
| 838 | ws->focus_animation = weston_fade_run( |
| 839 | ws->fsurf_front->view, |
| 840 | ws->fsurf_front->view->alpha, 0.6, 300, |
| 841 | focus_animation_done, ws); |
| 842 | } else if (from) { |
| 843 | wl_list_insert(&from->layer_link, |
| 844 | &ws->fsurf_back->view->layer_link); |
| 845 | ws->focus_animation = weston_stable_fade_run( |
| 846 | ws->fsurf_front->view, 0.0, |
| 847 | ws->fsurf_back->view, 0.6, |
| 848 | focus_animation_done, ws); |
| 849 | } else if (to) { |
| 850 | wl_list_insert(&ws->layer.view_list, |
| 851 | &ws->fsurf_back->view->layer_link); |
| 852 | ws->focus_animation = weston_stable_fade_run( |
| 853 | ws->fsurf_front->view, 0.0, |
| 854 | ws->fsurf_back->view, 0.6, |
| 855 | focus_animation_done, ws); |
| 856 | } |
| 857 | } |
| 858 | |
| 859 | static void |
Jonas Ådahl | e3cddce | 2012-06-13 00:01:22 +0200 | [diff] [blame] | 860 | workspace_destroy(struct workspace *ws) |
| 861 | { |
Jonas Ådahl | 0476974 | 2012-06-13 00:01:24 +0200 | [diff] [blame] | 862 | struct focus_state *state, *next; |
| 863 | |
| 864 | wl_list_for_each_safe(state, next, &ws->focus_list, link) |
| 865 | focus_state_destroy(state); |
| 866 | |
Louis-Francis Ratté-Boulianne | b482dbd | 2013-11-19 11:37:11 +0100 | [diff] [blame] | 867 | if (ws->fsurf_front) |
| 868 | focus_surface_destroy(ws->fsurf_front); |
| 869 | if (ws->fsurf_back) |
| 870 | focus_surface_destroy(ws->fsurf_back); |
| 871 | |
Jonas Ådahl | e3cddce | 2012-06-13 00:01:22 +0200 | [diff] [blame] | 872 | free(ws); |
| 873 | } |
| 874 | |
Jonas Ådahl | 0476974 | 2012-06-13 00:01:24 +0200 | [diff] [blame] | 875 | static void |
| 876 | seat_destroyed(struct wl_listener *listener, void *data) |
| 877 | { |
| 878 | struct weston_seat *seat = data; |
| 879 | struct focus_state *state, *next; |
| 880 | struct workspace *ws = container_of(listener, |
| 881 | struct workspace, |
| 882 | seat_destroyed_listener); |
| 883 | |
| 884 | wl_list_for_each_safe(state, next, &ws->focus_list, link) |
| 885 | if (state->seat == seat) |
| 886 | wl_list_remove(&state->link); |
| 887 | } |
| 888 | |
Jonas Ådahl | e3cddce | 2012-06-13 00:01:22 +0200 | [diff] [blame] | 889 | static struct workspace * |
| 890 | workspace_create(void) |
| 891 | { |
| 892 | struct workspace *ws = malloc(sizeof *ws); |
| 893 | if (ws == NULL) |
| 894 | return NULL; |
| 895 | |
| 896 | weston_layer_init(&ws->layer, NULL); |
| 897 | |
Jonas Ådahl | 0476974 | 2012-06-13 00:01:24 +0200 | [diff] [blame] | 898 | wl_list_init(&ws->focus_list); |
| 899 | wl_list_init(&ws->seat_destroyed_listener.link); |
| 900 | ws->seat_destroyed_listener.notify = seat_destroyed; |
Louis-Francis Ratté-Boulianne | b482dbd | 2013-11-19 11:37:11 +0100 | [diff] [blame] | 901 | ws->fsurf_front = NULL; |
| 902 | ws->fsurf_back = NULL; |
| 903 | ws->focus_animation = NULL; |
Jonas Ådahl | 0476974 | 2012-06-13 00:01:24 +0200 | [diff] [blame] | 904 | |
Jonas Ådahl | e3cddce | 2012-06-13 00:01:22 +0200 | [diff] [blame] | 905 | return ws; |
| 906 | } |
| 907 | |
Jonas Ådahl | 62fcd04 | 2012-06-13 00:01:23 +0200 | [diff] [blame] | 908 | static int |
| 909 | workspace_is_empty(struct workspace *ws) |
| 910 | { |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 911 | return wl_list_empty(&ws->layer.view_list); |
Jonas Ådahl | 62fcd04 | 2012-06-13 00:01:23 +0200 | [diff] [blame] | 912 | } |
| 913 | |
Jonas Ådahl | e3cddce | 2012-06-13 00:01:22 +0200 | [diff] [blame] | 914 | static struct workspace * |
| 915 | get_workspace(struct desktop_shell *shell, unsigned int index) |
| 916 | { |
| 917 | struct workspace **pws = shell->workspaces.array.data; |
Philipp Brüschweiler | 067abf6 | 2012-09-01 16:03:05 +0200 | [diff] [blame] | 918 | assert(index < shell->workspaces.num); |
Jonas Ådahl | e3cddce | 2012-06-13 00:01:22 +0200 | [diff] [blame] | 919 | pws += index; |
| 920 | return *pws; |
| 921 | } |
| 922 | |
| 923 | static struct workspace * |
| 924 | get_current_workspace(struct desktop_shell *shell) |
| 925 | { |
| 926 | return get_workspace(shell, shell->workspaces.current); |
| 927 | } |
| 928 | |
| 929 | static void |
| 930 | activate_workspace(struct desktop_shell *shell, unsigned int index) |
| 931 | { |
| 932 | struct workspace *ws; |
| 933 | |
| 934 | ws = get_workspace(shell, index); |
| 935 | wl_list_insert(&shell->panel_layer.link, &ws->layer.link); |
| 936 | |
| 937 | shell->workspaces.current = index; |
| 938 | } |
| 939 | |
Jonas Ådahl | 62fcd04 | 2012-06-13 00:01:23 +0200 | [diff] [blame] | 940 | static unsigned int |
| 941 | get_output_height(struct weston_output *output) |
| 942 | { |
| 943 | return abs(output->region.extents.y1 - output->region.extents.y2); |
| 944 | } |
| 945 | |
| 946 | static void |
Louis-Francis Ratté-Boulianne | b482dbd | 2013-11-19 11:37:11 +0100 | [diff] [blame] | 947 | view_translate(struct workspace *ws, struct weston_view *view, double d) |
Jonas Ådahl | 62fcd04 | 2012-06-13 00:01:23 +0200 | [diff] [blame] | 948 | { |
Jonas Ådahl | 62fcd04 | 2012-06-13 00:01:23 +0200 | [diff] [blame] | 949 | struct weston_transform *transform; |
| 950 | |
Louis-Francis Ratté-Boulianne | b482dbd | 2013-11-19 11:37:11 +0100 | [diff] [blame] | 951 | if (is_focus_view(view)) { |
| 952 | struct focus_surface *fsurf = get_focus_surface(view->surface); |
| 953 | transform = &fsurf->workspace_transform; |
| 954 | } else { |
| 955 | struct shell_surface *shsurf = get_shell_surface(view->surface); |
| 956 | transform = &shsurf->workspace_transform; |
| 957 | } |
| 958 | |
Jonas Ådahl | 62fcd04 | 2012-06-13 00:01:23 +0200 | [diff] [blame] | 959 | if (wl_list_empty(&transform->link)) |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 960 | wl_list_insert(view->geometry.transformation_list.prev, |
Louis-Francis Ratté-Boulianne | b482dbd | 2013-11-19 11:37:11 +0100 | [diff] [blame] | 961 | &transform->link); |
Jonas Ådahl | 62fcd04 | 2012-06-13 00:01:23 +0200 | [diff] [blame] | 962 | |
Louis-Francis Ratté-Boulianne | b482dbd | 2013-11-19 11:37:11 +0100 | [diff] [blame] | 963 | weston_matrix_init(&transform->matrix); |
| 964 | weston_matrix_translate(&transform->matrix, |
Jonas Ådahl | 62fcd04 | 2012-06-13 00:01:23 +0200 | [diff] [blame] | 965 | 0.0, d, 0.0); |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 966 | weston_view_geometry_dirty(view); |
Jonas Ådahl | 62fcd04 | 2012-06-13 00:01:23 +0200 | [diff] [blame] | 967 | } |
| 968 | |
| 969 | static void |
| 970 | workspace_translate_out(struct workspace *ws, double fraction) |
| 971 | { |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 972 | struct weston_view *view; |
Jonas Ådahl | 62fcd04 | 2012-06-13 00:01:23 +0200 | [diff] [blame] | 973 | unsigned int height; |
| 974 | double d; |
| 975 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 976 | wl_list_for_each(view, &ws->layer.view_list, layer_link) { |
| 977 | height = get_output_height(view->surface->output); |
Jonas Ådahl | 62fcd04 | 2012-06-13 00:01:23 +0200 | [diff] [blame] | 978 | d = height * fraction; |
| 979 | |
Louis-Francis Ratté-Boulianne | b482dbd | 2013-11-19 11:37:11 +0100 | [diff] [blame] | 980 | view_translate(ws, view, d); |
Jonas Ådahl | 62fcd04 | 2012-06-13 00:01:23 +0200 | [diff] [blame] | 981 | } |
| 982 | } |
| 983 | |
| 984 | static void |
| 985 | workspace_translate_in(struct workspace *ws, double fraction) |
| 986 | { |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 987 | struct weston_view *view; |
Jonas Ådahl | 62fcd04 | 2012-06-13 00:01:23 +0200 | [diff] [blame] | 988 | unsigned int height; |
| 989 | double d; |
| 990 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 991 | wl_list_for_each(view, &ws->layer.view_list, layer_link) { |
| 992 | height = get_output_height(view->surface->output); |
Jonas Ådahl | 62fcd04 | 2012-06-13 00:01:23 +0200 | [diff] [blame] | 993 | |
| 994 | if (fraction > 0) |
| 995 | d = -(height - height * fraction); |
| 996 | else |
| 997 | d = height + height * fraction; |
| 998 | |
Louis-Francis Ratté-Boulianne | b482dbd | 2013-11-19 11:37:11 +0100 | [diff] [blame] | 999 | view_translate(ws, view, d); |
Jonas Ådahl | 62fcd04 | 2012-06-13 00:01:23 +0200 | [diff] [blame] | 1000 | } |
| 1001 | } |
| 1002 | |
| 1003 | static void |
Jonas Ådahl | e9d2250 | 2012-08-29 22:13:01 +0200 | [diff] [blame] | 1004 | broadcast_current_workspace_state(struct desktop_shell *shell) |
| 1005 | { |
Kristian Høgsberg | 2e3c396 | 2013-09-11 12:00:47 -0700 | [diff] [blame] | 1006 | struct wl_resource *resource; |
Jonas Ådahl | e9d2250 | 2012-08-29 22:13:01 +0200 | [diff] [blame] | 1007 | |
Kristian Høgsberg | 2e3c396 | 2013-09-11 12:00:47 -0700 | [diff] [blame] | 1008 | wl_resource_for_each(resource, &shell->workspaces.client_list) |
| 1009 | workspace_manager_send_state(resource, |
Jonas Ådahl | e9d2250 | 2012-08-29 22:13:01 +0200 | [diff] [blame] | 1010 | shell->workspaces.current, |
| 1011 | shell->workspaces.num); |
| 1012 | } |
| 1013 | |
| 1014 | static void |
Jonas Ådahl | 62fcd04 | 2012-06-13 00:01:23 +0200 | [diff] [blame] | 1015 | reverse_workspace_change_animation(struct desktop_shell *shell, |
| 1016 | unsigned int index, |
| 1017 | struct workspace *from, |
| 1018 | struct workspace *to) |
| 1019 | { |
| 1020 | shell->workspaces.current = index; |
| 1021 | |
| 1022 | shell->workspaces.anim_to = to; |
| 1023 | shell->workspaces.anim_from = from; |
| 1024 | shell->workspaces.anim_dir = -1 * shell->workspaces.anim_dir; |
| 1025 | shell->workspaces.anim_timestamp = 0; |
| 1026 | |
Scott Moreau | 4272e63 | 2012-08-13 09:58:41 -0600 | [diff] [blame] | 1027 | weston_compositor_schedule_repaint(shell->compositor); |
Jonas Ådahl | 62fcd04 | 2012-06-13 00:01:23 +0200 | [diff] [blame] | 1028 | } |
| 1029 | |
| 1030 | static void |
| 1031 | workspace_deactivate_transforms(struct workspace *ws) |
| 1032 | { |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 1033 | struct weston_view *view; |
Louis-Francis Ratté-Boulianne | b482dbd | 2013-11-19 11:37:11 +0100 | [diff] [blame] | 1034 | struct weston_transform *transform; |
Jonas Ådahl | 62fcd04 | 2012-06-13 00:01:23 +0200 | [diff] [blame] | 1035 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 1036 | 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] | 1037 | if (is_focus_view(view)) { |
| 1038 | struct focus_surface *fsurf = get_focus_surface(view->surface); |
| 1039 | transform = &fsurf->workspace_transform; |
| 1040 | } else { |
| 1041 | struct shell_surface *shsurf = get_shell_surface(view->surface); |
| 1042 | transform = &shsurf->workspace_transform; |
| 1043 | } |
| 1044 | |
| 1045 | if (!wl_list_empty(&transform->link)) { |
| 1046 | wl_list_remove(&transform->link); |
| 1047 | wl_list_init(&transform->link); |
Jonas Ådahl | 8de6a1d | 2012-08-29 22:13:00 +0200 | [diff] [blame] | 1048 | } |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 1049 | weston_view_geometry_dirty(view); |
Jonas Ådahl | 62fcd04 | 2012-06-13 00:01:23 +0200 | [diff] [blame] | 1050 | } |
| 1051 | } |
| 1052 | |
| 1053 | static void |
| 1054 | finish_workspace_change_animation(struct desktop_shell *shell, |
| 1055 | struct workspace *from, |
| 1056 | struct workspace *to) |
| 1057 | { |
Scott Moreau | 4272e63 | 2012-08-13 09:58:41 -0600 | [diff] [blame] | 1058 | weston_compositor_schedule_repaint(shell->compositor); |
Jonas Ådahl | 62fcd04 | 2012-06-13 00:01:23 +0200 | [diff] [blame] | 1059 | |
| 1060 | wl_list_remove(&shell->workspaces.animation.link); |
| 1061 | workspace_deactivate_transforms(from); |
| 1062 | workspace_deactivate_transforms(to); |
| 1063 | shell->workspaces.anim_to = NULL; |
| 1064 | |
| 1065 | wl_list_remove(&shell->workspaces.anim_from->layer.link); |
| 1066 | } |
| 1067 | |
| 1068 | static void |
| 1069 | animate_workspace_change_frame(struct weston_animation *animation, |
| 1070 | struct weston_output *output, uint32_t msecs) |
| 1071 | { |
| 1072 | struct desktop_shell *shell = |
| 1073 | container_of(animation, struct desktop_shell, |
| 1074 | workspaces.animation); |
| 1075 | struct workspace *from = shell->workspaces.anim_from; |
| 1076 | struct workspace *to = shell->workspaces.anim_to; |
| 1077 | uint32_t t; |
| 1078 | double x, y; |
| 1079 | |
| 1080 | if (workspace_is_empty(from) && workspace_is_empty(to)) { |
| 1081 | finish_workspace_change_animation(shell, from, to); |
| 1082 | return; |
| 1083 | } |
| 1084 | |
| 1085 | if (shell->workspaces.anim_timestamp == 0) { |
| 1086 | if (shell->workspaces.anim_current == 0.0) |
| 1087 | shell->workspaces.anim_timestamp = msecs; |
| 1088 | else |
| 1089 | shell->workspaces.anim_timestamp = |
| 1090 | msecs - |
| 1091 | /* Invers of movement function 'y' below. */ |
| 1092 | (asin(1.0 - shell->workspaces.anim_current) * |
| 1093 | DEFAULT_WORKSPACE_CHANGE_ANIMATION_LENGTH * |
| 1094 | M_2_PI); |
| 1095 | } |
| 1096 | |
| 1097 | t = msecs - shell->workspaces.anim_timestamp; |
| 1098 | |
| 1099 | /* |
| 1100 | * x = [0, π/2] |
| 1101 | * y(x) = sin(x) |
| 1102 | */ |
| 1103 | x = t * (1.0/DEFAULT_WORKSPACE_CHANGE_ANIMATION_LENGTH) * M_PI_2; |
| 1104 | y = sin(x); |
| 1105 | |
| 1106 | if (t < DEFAULT_WORKSPACE_CHANGE_ANIMATION_LENGTH) { |
Scott Moreau | 4272e63 | 2012-08-13 09:58:41 -0600 | [diff] [blame] | 1107 | weston_compositor_schedule_repaint(shell->compositor); |
Jonas Ådahl | 62fcd04 | 2012-06-13 00:01:23 +0200 | [diff] [blame] | 1108 | |
| 1109 | workspace_translate_out(from, shell->workspaces.anim_dir * y); |
| 1110 | workspace_translate_in(to, shell->workspaces.anim_dir * y); |
| 1111 | shell->workspaces.anim_current = y; |
| 1112 | |
Scott Moreau | 4272e63 | 2012-08-13 09:58:41 -0600 | [diff] [blame] | 1113 | weston_compositor_schedule_repaint(shell->compositor); |
Jonas Ådahl | 62fcd04 | 2012-06-13 00:01:23 +0200 | [diff] [blame] | 1114 | } |
Jonas Ådahl | 0476974 | 2012-06-13 00:01:24 +0200 | [diff] [blame] | 1115 | else |
Jonas Ådahl | 62fcd04 | 2012-06-13 00:01:23 +0200 | [diff] [blame] | 1116 | finish_workspace_change_animation(shell, from, to); |
Jonas Ådahl | 62fcd04 | 2012-06-13 00:01:23 +0200 | [diff] [blame] | 1117 | } |
| 1118 | |
| 1119 | static void |
| 1120 | animate_workspace_change(struct desktop_shell *shell, |
| 1121 | unsigned int index, |
| 1122 | struct workspace *from, |
| 1123 | struct workspace *to) |
| 1124 | { |
| 1125 | struct weston_output *output; |
| 1126 | |
| 1127 | int dir; |
| 1128 | |
| 1129 | if (index > shell->workspaces.current) |
| 1130 | dir = -1; |
| 1131 | else |
| 1132 | dir = 1; |
| 1133 | |
| 1134 | shell->workspaces.current = index; |
| 1135 | |
| 1136 | shell->workspaces.anim_dir = dir; |
| 1137 | shell->workspaces.anim_from = from; |
| 1138 | shell->workspaces.anim_to = to; |
| 1139 | shell->workspaces.anim_current = 0.0; |
| 1140 | shell->workspaces.anim_timestamp = 0; |
| 1141 | |
| 1142 | output = container_of(shell->compositor->output_list.next, |
| 1143 | struct weston_output, link); |
| 1144 | wl_list_insert(&output->animation_list, |
| 1145 | &shell->workspaces.animation.link); |
| 1146 | |
Jonas Ådahl | 8de6a1d | 2012-08-29 22:13:00 +0200 | [diff] [blame] | 1147 | wl_list_insert(from->layer.link.prev, &to->layer.link); |
Jonas Ådahl | 62fcd04 | 2012-06-13 00:01:23 +0200 | [diff] [blame] | 1148 | |
| 1149 | workspace_translate_in(to, 0); |
| 1150 | |
Kristian Høgsberg | 2f5faff | 2012-07-31 16:36:34 -0400 | [diff] [blame] | 1151 | restore_focus_state(shell, to); |
Jonas Ådahl | 0476974 | 2012-06-13 00:01:24 +0200 | [diff] [blame] | 1152 | |
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 | |
Jonas Ådahl | e3cddce | 2012-06-13 00:01:22 +0200 | [diff] [blame] | 1156 | static void |
Jonas Ådahl | 8de6a1d | 2012-08-29 22:13:00 +0200 | [diff] [blame] | 1157 | update_workspace(struct desktop_shell *shell, unsigned int index, |
| 1158 | struct workspace *from, struct workspace *to) |
| 1159 | { |
| 1160 | shell->workspaces.current = index; |
| 1161 | wl_list_insert(&from->layer.link, &to->layer.link); |
| 1162 | wl_list_remove(&from->layer.link); |
| 1163 | } |
| 1164 | |
| 1165 | static void |
Jonas Ådahl | e3cddce | 2012-06-13 00:01:22 +0200 | [diff] [blame] | 1166 | change_workspace(struct desktop_shell *shell, unsigned int index) |
| 1167 | { |
| 1168 | struct workspace *from; |
| 1169 | struct workspace *to; |
Louis-Francis Ratté-Boulianne | b482dbd | 2013-11-19 11:37:11 +0100 | [diff] [blame] | 1170 | struct focus_state *state; |
Jonas Ådahl | e3cddce | 2012-06-13 00:01:22 +0200 | [diff] [blame] | 1171 | |
| 1172 | if (index == shell->workspaces.current) |
| 1173 | return; |
| 1174 | |
| 1175 | /* Don't change workspace when there is any fullscreen surfaces. */ |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 1176 | if (!wl_list_empty(&shell->fullscreen_layer.view_list)) |
Jonas Ådahl | e3cddce | 2012-06-13 00:01:22 +0200 | [diff] [blame] | 1177 | return; |
| 1178 | |
Jonas Ådahl | e3cddce | 2012-06-13 00:01:22 +0200 | [diff] [blame] | 1179 | from = get_current_workspace(shell); |
| 1180 | to = get_workspace(shell, index); |
| 1181 | |
Jonas Ådahl | 62fcd04 | 2012-06-13 00:01:23 +0200 | [diff] [blame] | 1182 | if (shell->workspaces.anim_from == to && |
| 1183 | shell->workspaces.anim_to == from) { |
Jonas Ådahl | 8de6a1d | 2012-08-29 22:13:00 +0200 | [diff] [blame] | 1184 | restore_focus_state(shell, to); |
Jonas Ådahl | 62fcd04 | 2012-06-13 00:01:23 +0200 | [diff] [blame] | 1185 | reverse_workspace_change_animation(shell, index, from, to); |
Jonas Ådahl | e9d2250 | 2012-08-29 22:13:01 +0200 | [diff] [blame] | 1186 | broadcast_current_workspace_state(shell); |
Jonas Ådahl | 62fcd04 | 2012-06-13 00:01:23 +0200 | [diff] [blame] | 1187 | return; |
| 1188 | } |
Jonas Ådahl | e3cddce | 2012-06-13 00:01:22 +0200 | [diff] [blame] | 1189 | |
Jonas Ådahl | 62fcd04 | 2012-06-13 00:01:23 +0200 | [diff] [blame] | 1190 | if (shell->workspaces.anim_to != NULL) |
| 1191 | finish_workspace_change_animation(shell, |
| 1192 | shell->workspaces.anim_from, |
| 1193 | shell->workspaces.anim_to); |
| 1194 | |
Jonas Ådahl | 8de6a1d | 2012-08-29 22:13:00 +0200 | [diff] [blame] | 1195 | restore_focus_state(shell, to); |
Jonas Ådahl | 0476974 | 2012-06-13 00:01:24 +0200 | [diff] [blame] | 1196 | |
Louis-Francis Ratté-Boulianne | b482dbd | 2013-11-19 11:37:11 +0100 | [diff] [blame] | 1197 | if (shell->focus_animation_type != ANIMATION_NONE) { |
| 1198 | wl_list_for_each(state, &from->focus_list, link) |
| 1199 | if (state->keyboard_focus) |
| 1200 | animate_focus_change(shell, from, |
| 1201 | get_default_view(state->keyboard_focus), NULL); |
| 1202 | |
| 1203 | wl_list_for_each(state, &to->focus_list, link) |
| 1204 | if (state->keyboard_focus) |
| 1205 | animate_focus_change(shell, to, |
| 1206 | NULL, get_default_view(state->keyboard_focus)); |
| 1207 | } |
| 1208 | |
Jonas Ådahl | 8de6a1d | 2012-08-29 22:13:00 +0200 | [diff] [blame] | 1209 | if (workspace_is_empty(to) && workspace_is_empty(from)) |
| 1210 | update_workspace(shell, index, from, to); |
Jonas Ådahl | 62fcd04 | 2012-06-13 00:01:23 +0200 | [diff] [blame] | 1211 | else |
| 1212 | animate_workspace_change(shell, index, from, to); |
Jonas Ådahl | e9d2250 | 2012-08-29 22:13:01 +0200 | [diff] [blame] | 1213 | |
| 1214 | broadcast_current_workspace_state(shell); |
Pekka Paalanen | e955f1e | 2011-12-07 11:49:52 +0200 | [diff] [blame] | 1215 | } |
| 1216 | |
Jonas Ådahl | 8de6a1d | 2012-08-29 22:13:00 +0200 | [diff] [blame] | 1217 | static bool |
| 1218 | workspace_has_only(struct workspace *ws, struct weston_surface *surface) |
| 1219 | { |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 1220 | struct wl_list *list = &ws->layer.view_list; |
Jonas Ådahl | 8de6a1d | 2012-08-29 22:13:00 +0200 | [diff] [blame] | 1221 | struct wl_list *e; |
| 1222 | |
| 1223 | if (wl_list_empty(list)) |
| 1224 | return false; |
| 1225 | |
| 1226 | e = list->next; |
| 1227 | |
| 1228 | if (e->next != list) |
| 1229 | return false; |
| 1230 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 1231 | return container_of(e, struct weston_view, layer_link)->surface == surface; |
Jonas Ådahl | 8de6a1d | 2012-08-29 22:13:00 +0200 | [diff] [blame] | 1232 | } |
| 1233 | |
| 1234 | static void |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 1235 | move_view_to_workspace(struct desktop_shell *shell, |
| 1236 | struct weston_view *view, |
| 1237 | uint32_t workspace) |
Jonas Ådahl | e9d2250 | 2012-08-29 22:13:01 +0200 | [diff] [blame] | 1238 | { |
| 1239 | struct workspace *from; |
| 1240 | struct workspace *to; |
| 1241 | struct weston_seat *seat; |
Pekka Paalanen | 01388e2 | 2013-04-25 13:57:44 +0300 | [diff] [blame] | 1242 | struct weston_surface *focus; |
| 1243 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 1244 | assert(weston_surface_get_main_surface(view->surface) == view->surface); |
Jonas Ådahl | e9d2250 | 2012-08-29 22:13:01 +0200 | [diff] [blame] | 1245 | |
| 1246 | if (workspace == shell->workspaces.current) |
| 1247 | return; |
| 1248 | |
Philipp Brüschweiler | 067abf6 | 2012-09-01 16:03:05 +0200 | [diff] [blame] | 1249 | if (workspace >= shell->workspaces.num) |
| 1250 | workspace = shell->workspaces.num - 1; |
| 1251 | |
Jonas Ådahl | e9d2250 | 2012-08-29 22:13:01 +0200 | [diff] [blame] | 1252 | from = get_current_workspace(shell); |
| 1253 | to = get_workspace(shell, workspace); |
| 1254 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 1255 | wl_list_remove(&view->layer_link); |
| 1256 | wl_list_insert(&to->layer.view_list, &view->layer_link); |
Jonas Ådahl | e9d2250 | 2012-08-29 22:13:01 +0200 | [diff] [blame] | 1257 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 1258 | drop_focus_state(shell, from, view->surface); |
Pekka Paalanen | 01388e2 | 2013-04-25 13:57:44 +0300 | [diff] [blame] | 1259 | wl_list_for_each(seat, &shell->compositor->seat_list, link) { |
| 1260 | if (!seat->keyboard) |
| 1261 | continue; |
| 1262 | |
| 1263 | focus = weston_surface_get_main_surface(seat->keyboard->focus); |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 1264 | if (focus == view->surface) |
Kristian Høgsberg | e314875 | 2013-05-06 23:19:49 -0400 | [diff] [blame] | 1265 | weston_keyboard_set_focus(seat->keyboard, NULL); |
Pekka Paalanen | 01388e2 | 2013-04-25 13:57:44 +0300 | [diff] [blame] | 1266 | } |
Jonas Ådahl | e9d2250 | 2012-08-29 22:13:01 +0200 | [diff] [blame] | 1267 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 1268 | weston_view_damage_below(view); |
Jonas Ådahl | e9d2250 | 2012-08-29 22:13:01 +0200 | [diff] [blame] | 1269 | } |
| 1270 | |
| 1271 | static void |
Jonas Ådahl | 8de6a1d | 2012-08-29 22:13:00 +0200 | [diff] [blame] | 1272 | take_surface_to_workspace_by_seat(struct desktop_shell *shell, |
Kristian Høgsberg | e314875 | 2013-05-06 23:19:49 -0400 | [diff] [blame] | 1273 | struct weston_seat *seat, |
Jonas Ådahl | 8de6a1d | 2012-08-29 22:13:00 +0200 | [diff] [blame] | 1274 | unsigned int index) |
| 1275 | { |
Pekka Paalanen | 01388e2 | 2013-04-25 13:57:44 +0300 | [diff] [blame] | 1276 | struct weston_surface *surface; |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 1277 | struct weston_view *view; |
Jonas Ådahl | 8de6a1d | 2012-08-29 22:13:00 +0200 | [diff] [blame] | 1278 | struct shell_surface *shsurf; |
| 1279 | struct workspace *from; |
| 1280 | struct workspace *to; |
Jonas Ådahl | 8538b22 | 2012-08-29 22:13:03 +0200 | [diff] [blame] | 1281 | struct focus_state *state; |
Jonas Ådahl | 8de6a1d | 2012-08-29 22:13:00 +0200 | [diff] [blame] | 1282 | |
Pekka Paalanen | 01388e2 | 2013-04-25 13:57:44 +0300 | [diff] [blame] | 1283 | surface = weston_surface_get_main_surface(seat->keyboard->focus); |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 1284 | view = get_default_view(surface); |
| 1285 | if (view == NULL || |
Louis-Francis Ratté-Boulianne | b482dbd | 2013-11-19 11:37:11 +0100 | [diff] [blame] | 1286 | index == shell->workspaces.current || |
| 1287 | is_focus_view(view)) |
Jonas Ådahl | 8de6a1d | 2012-08-29 22:13:00 +0200 | [diff] [blame] | 1288 | return; |
| 1289 | |
| 1290 | from = get_current_workspace(shell); |
| 1291 | to = get_workspace(shell, index); |
| 1292 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 1293 | wl_list_remove(&view->layer_link); |
| 1294 | wl_list_insert(&to->layer.view_list, &view->layer_link); |
Jonas Ådahl | 8de6a1d | 2012-08-29 22:13:00 +0200 | [diff] [blame] | 1295 | |
Jonas Ådahl | e9d2250 | 2012-08-29 22:13:01 +0200 | [diff] [blame] | 1296 | replace_focus_state(shell, to, seat); |
Jonas Ådahl | 8de6a1d | 2012-08-29 22:13:00 +0200 | [diff] [blame] | 1297 | drop_focus_state(shell, from, surface); |
| 1298 | |
| 1299 | if (shell->workspaces.anim_from == to && |
| 1300 | shell->workspaces.anim_to == from) { |
Jonas Ådahl | e9d2250 | 2012-08-29 22:13:01 +0200 | [diff] [blame] | 1301 | wl_list_remove(&to->layer.link); |
| 1302 | wl_list_insert(from->layer.link.prev, &to->layer.link); |
| 1303 | |
Jonas Ådahl | 8de6a1d | 2012-08-29 22:13:00 +0200 | [diff] [blame] | 1304 | reverse_workspace_change_animation(shell, index, from, to); |
Jonas Ådahl | e9d2250 | 2012-08-29 22:13:01 +0200 | [diff] [blame] | 1305 | broadcast_current_workspace_state(shell); |
| 1306 | |
Jonas Ådahl | 8de6a1d | 2012-08-29 22:13:00 +0200 | [diff] [blame] | 1307 | return; |
| 1308 | } |
| 1309 | |
| 1310 | if (shell->workspaces.anim_to != NULL) |
| 1311 | finish_workspace_change_animation(shell, |
| 1312 | shell->workspaces.anim_from, |
| 1313 | shell->workspaces.anim_to); |
| 1314 | |
| 1315 | if (workspace_is_empty(from) && |
| 1316 | workspace_has_only(to, surface)) |
| 1317 | update_workspace(shell, index, from, to); |
| 1318 | else { |
| 1319 | shsurf = get_shell_surface(surface); |
| 1320 | if (wl_list_empty(&shsurf->workspace_transform.link)) |
| 1321 | wl_list_insert(&shell->workspaces.anim_sticky_list, |
| 1322 | &shsurf->workspace_transform.link); |
| 1323 | |
| 1324 | animate_workspace_change(shell, index, from, to); |
| 1325 | } |
Jonas Ådahl | e9d2250 | 2012-08-29 22:13:01 +0200 | [diff] [blame] | 1326 | |
| 1327 | broadcast_current_workspace_state(shell); |
Jonas Ådahl | 8538b22 | 2012-08-29 22:13:03 +0200 | [diff] [blame] | 1328 | |
| 1329 | state = ensure_focus_state(shell, seat); |
| 1330 | if (state != NULL) |
| 1331 | state->keyboard_focus = surface; |
Jonas Ådahl | e9d2250 | 2012-08-29 22:13:01 +0200 | [diff] [blame] | 1332 | } |
| 1333 | |
| 1334 | static void |
| 1335 | workspace_manager_move_surface(struct wl_client *client, |
| 1336 | struct wl_resource *resource, |
| 1337 | struct wl_resource *surface_resource, |
| 1338 | uint32_t workspace) |
| 1339 | { |
Jason Ekstrand | 651f00e | 2013-06-14 10:07:54 -0500 | [diff] [blame] | 1340 | struct desktop_shell *shell = wl_resource_get_user_data(resource); |
Jonas Ådahl | e9d2250 | 2012-08-29 22:13:01 +0200 | [diff] [blame] | 1341 | struct weston_surface *surface = |
Jason Ekstrand | 0f2ef7e | 2013-06-14 10:07:53 -0500 | [diff] [blame] | 1342 | wl_resource_get_user_data(surface_resource); |
Pekka Paalanen | 01388e2 | 2013-04-25 13:57:44 +0300 | [diff] [blame] | 1343 | struct weston_surface *main_surface; |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 1344 | struct weston_view *view; |
Jonas Ådahl | e9d2250 | 2012-08-29 22:13:01 +0200 | [diff] [blame] | 1345 | |
Pekka Paalanen | 01388e2 | 2013-04-25 13:57:44 +0300 | [diff] [blame] | 1346 | main_surface = weston_surface_get_main_surface(surface); |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 1347 | view = get_default_view(main_surface); |
| 1348 | if (!view) |
| 1349 | return; |
| 1350 | move_view_to_workspace(shell, view, workspace); |
Jonas Ådahl | e9d2250 | 2012-08-29 22:13:01 +0200 | [diff] [blame] | 1351 | } |
| 1352 | |
| 1353 | static const struct workspace_manager_interface workspace_manager_implementation = { |
| 1354 | workspace_manager_move_surface, |
| 1355 | }; |
| 1356 | |
| 1357 | static void |
| 1358 | unbind_resource(struct wl_resource *resource) |
| 1359 | { |
Jason Ekstrand | 651f00e | 2013-06-14 10:07:54 -0500 | [diff] [blame] | 1360 | wl_list_remove(wl_resource_get_link(resource)); |
Jonas Ådahl | e9d2250 | 2012-08-29 22:13:01 +0200 | [diff] [blame] | 1361 | } |
| 1362 | |
| 1363 | static void |
| 1364 | bind_workspace_manager(struct wl_client *client, |
| 1365 | void *data, uint32_t version, uint32_t id) |
| 1366 | { |
| 1367 | struct desktop_shell *shell = data; |
| 1368 | struct wl_resource *resource; |
| 1369 | |
Jason Ekstrand | a85118c | 2013-06-27 20:17:02 -0500 | [diff] [blame] | 1370 | resource = wl_resource_create(client, |
| 1371 | &workspace_manager_interface, 1, id); |
Jonas Ådahl | e9d2250 | 2012-08-29 22:13:01 +0200 | [diff] [blame] | 1372 | |
| 1373 | if (resource == NULL) { |
| 1374 | weston_log("couldn't add workspace manager object"); |
| 1375 | return; |
| 1376 | } |
| 1377 | |
Jason Ekstrand | a85118c | 2013-06-27 20:17:02 -0500 | [diff] [blame] | 1378 | wl_resource_set_implementation(resource, |
| 1379 | &workspace_manager_implementation, |
| 1380 | shell, unbind_resource); |
Jason Ekstrand | 651f00e | 2013-06-14 10:07:54 -0500 | [diff] [blame] | 1381 | wl_list_insert(&shell->workspaces.client_list, |
| 1382 | wl_resource_get_link(resource)); |
Jonas Ådahl | e9d2250 | 2012-08-29 22:13:01 +0200 | [diff] [blame] | 1383 | |
| 1384 | workspace_manager_send_state(resource, |
| 1385 | shell->workspaces.current, |
| 1386 | shell->workspaces.num); |
Jonas Ådahl | 8de6a1d | 2012-08-29 22:13:00 +0200 | [diff] [blame] | 1387 | } |
| 1388 | |
Pekka Paalanen | 56cdea9 | 2011-11-23 16:14:12 +0200 | [diff] [blame] | 1389 | static void |
Rusty Lynch | 1084da5 | 2013-08-15 09:10:08 -0700 | [diff] [blame] | 1390 | touch_move_grab_down(struct weston_touch_grab *grab, uint32_t time, |
| 1391 | int touch_id, wl_fixed_t sx, wl_fixed_t sy) |
| 1392 | { |
| 1393 | } |
| 1394 | |
| 1395 | static void |
| 1396 | touch_move_grab_up(struct weston_touch_grab *grab, uint32_t time, int touch_id) |
| 1397 | { |
Jonas Ådahl | 1c6e63e | 2013-10-25 23:18:04 +0200 | [diff] [blame] | 1398 | struct weston_touch_move_grab *move = |
| 1399 | (struct weston_touch_move_grab *) container_of( |
| 1400 | grab, struct shell_touch_grab, grab); |
Neil Roberts | e14aa4f | 2013-10-03 16:43:07 +0100 | [diff] [blame] | 1401 | |
Jonas Ådahl | 1c6e63e | 2013-10-25 23:18:04 +0200 | [diff] [blame] | 1402 | if (grab->touch->seat->num_tp == 0) { |
| 1403 | shell_touch_grab_end(&move->base); |
| 1404 | free(move); |
| 1405 | } |
Rusty Lynch | 1084da5 | 2013-08-15 09:10:08 -0700 | [diff] [blame] | 1406 | } |
| 1407 | |
| 1408 | static void |
| 1409 | touch_move_grab_motion(struct weston_touch_grab *grab, uint32_t time, |
| 1410 | int touch_id, wl_fixed_t sx, wl_fixed_t sy) |
| 1411 | { |
| 1412 | struct weston_touch_move_grab *move = (struct weston_touch_move_grab *) grab; |
| 1413 | struct shell_surface *shsurf = move->base.shsurf; |
| 1414 | struct weston_surface *es; |
| 1415 | int dx = wl_fixed_to_int(grab->touch->grab_x + move->dx); |
| 1416 | int dy = wl_fixed_to_int(grab->touch->grab_y + move->dy); |
| 1417 | |
| 1418 | if (!shsurf) |
| 1419 | return; |
| 1420 | |
| 1421 | es = shsurf->surface; |
| 1422 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 1423 | weston_view_configure(shsurf->view, dx, dy, |
| 1424 | shsurf->view->geometry.width, |
| 1425 | shsurf->view->geometry.height); |
Rusty Lynch | 1084da5 | 2013-08-15 09:10:08 -0700 | [diff] [blame] | 1426 | |
| 1427 | weston_compositor_schedule_repaint(es->compositor); |
| 1428 | } |
| 1429 | |
Jonas Ådahl | 1ea343e | 2013-10-25 23:18:05 +0200 | [diff] [blame] | 1430 | static void |
| 1431 | touch_move_grab_cancel(struct weston_touch_grab *grab) |
| 1432 | { |
| 1433 | struct weston_touch_move_grab *move = |
| 1434 | (struct weston_touch_move_grab *) container_of( |
| 1435 | grab, struct shell_touch_grab, grab); |
| 1436 | |
| 1437 | shell_touch_grab_end(&move->base); |
| 1438 | free(move); |
| 1439 | } |
| 1440 | |
Rusty Lynch | 1084da5 | 2013-08-15 09:10:08 -0700 | [diff] [blame] | 1441 | static const struct weston_touch_grab_interface touch_move_grab_interface = { |
| 1442 | touch_move_grab_down, |
| 1443 | touch_move_grab_up, |
| 1444 | touch_move_grab_motion, |
Jonas Ådahl | 1ea343e | 2013-10-25 23:18:05 +0200 | [diff] [blame] | 1445 | touch_move_grab_cancel, |
Rusty Lynch | 1084da5 | 2013-08-15 09:10:08 -0700 | [diff] [blame] | 1446 | }; |
| 1447 | |
| 1448 | static int |
| 1449 | surface_touch_move(struct shell_surface *shsurf, struct weston_seat *seat) |
| 1450 | { |
| 1451 | struct weston_touch_move_grab *move; |
| 1452 | |
| 1453 | if (!shsurf) |
| 1454 | return -1; |
| 1455 | |
| 1456 | if (shsurf->type == SHELL_SURFACE_FULLSCREEN) |
| 1457 | return 0; |
Kristian Høgsberg | c85f1d4 | 2013-10-24 16:52:00 -0700 | [diff] [blame] | 1458 | if (shsurf->grabbed) |
| 1459 | return 0; |
Rusty Lynch | 1084da5 | 2013-08-15 09:10:08 -0700 | [diff] [blame] | 1460 | |
| 1461 | move = malloc(sizeof *move); |
| 1462 | if (!move) |
| 1463 | return -1; |
| 1464 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 1465 | move->dx = wl_fixed_from_double(shsurf->view->geometry.x) - |
Rusty Lynch | 1084da5 | 2013-08-15 09:10:08 -0700 | [diff] [blame] | 1466 | seat->touch->grab_x; |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 1467 | move->dy = wl_fixed_from_double(shsurf->view->geometry.y) - |
Rusty Lynch | 1084da5 | 2013-08-15 09:10:08 -0700 | [diff] [blame] | 1468 | seat->touch->grab_y; |
| 1469 | |
| 1470 | shell_touch_grab_start(&move->base, &touch_move_grab_interface, shsurf, |
| 1471 | seat->touch); |
| 1472 | |
| 1473 | return 0; |
| 1474 | } |
| 1475 | |
| 1476 | static void |
Kristian Høgsberg | 6848c25 | 2013-05-08 22:02:59 -0400 | [diff] [blame] | 1477 | noop_grab_focus(struct weston_pointer_grab *grab) |
Kristian Høgsberg | 9ddb826 | 2012-01-04 21:30:29 -0500 | [diff] [blame] | 1478 | { |
Kristian Høgsberg | 9ddb826 | 2012-01-04 21:30:29 -0500 | [diff] [blame] | 1479 | } |
| 1480 | |
| 1481 | static void |
Giulio Camuffo | 1959ab8 | 2013-11-14 23:42:52 +0100 | [diff] [blame] | 1482 | move_grab_motion(struct weston_pointer_grab *grab, uint32_t time, |
| 1483 | wl_fixed_t x, wl_fixed_t y) |
Kristian Høgsberg | 4cca349 | 2011-01-18 07:53:49 -0500 | [diff] [blame] | 1484 | { |
Kristian Høgsberg | 8334bc1 | 2012-01-03 10:29:47 -0500 | [diff] [blame] | 1485 | struct weston_move_grab *move = (struct weston_move_grab *) grab; |
Kristian Høgsberg | 02bbabb | 2013-05-06 22:15:05 -0400 | [diff] [blame] | 1486 | struct weston_pointer *pointer = grab->pointer; |
Ander Conselvan de Oliveira | fe0444a | 2012-04-04 17:48:05 +0300 | [diff] [blame] | 1487 | struct shell_surface *shsurf = move->base.shsurf; |
Giulio Camuffo | 1959ab8 | 2013-11-14 23:42:52 +0100 | [diff] [blame] | 1488 | int dx, dy; |
| 1489 | |
| 1490 | weston_pointer_move(pointer, x, y); |
| 1491 | dx = wl_fixed_to_int(pointer->x + move->dx); |
| 1492 | dy = wl_fixed_to_int(pointer->y + move->dy); |
Ander Conselvan de Oliveira | fe0444a | 2012-04-04 17:48:05 +0300 | [diff] [blame] | 1493 | |
| 1494 | if (!shsurf) |
| 1495 | return; |
| 1496 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 1497 | weston_view_configure(shsurf->view, dx, dy, |
| 1498 | shsurf->view->geometry.width, |
| 1499 | shsurf->view->geometry.height); |
Kristian Høgsberg | 4cca349 | 2011-01-18 07:53:49 -0500 | [diff] [blame] | 1500 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 1501 | weston_compositor_schedule_repaint(shsurf->surface->compositor); |
Kristian Høgsberg | 4cca349 | 2011-01-18 07:53:49 -0500 | [diff] [blame] | 1502 | } |
| 1503 | |
| 1504 | static void |
Kristian Høgsberg | 02bbabb | 2013-05-06 22:15:05 -0400 | [diff] [blame] | 1505 | move_grab_button(struct weston_pointer_grab *grab, |
Daniel Stone | 4dbadb1 | 2012-05-30 16:31:51 +0100 | [diff] [blame] | 1506 | uint32_t time, uint32_t button, uint32_t state_w) |
Kristian Høgsberg | 4cca349 | 2011-01-18 07:53:49 -0500 | [diff] [blame] | 1507 | { |
Ander Conselvan de Oliveira | fe0444a | 2012-04-04 17:48:05 +0300 | [diff] [blame] | 1508 | struct shell_grab *shell_grab = container_of(grab, struct shell_grab, |
| 1509 | grab); |
Kristian Høgsberg | 02bbabb | 2013-05-06 22:15:05 -0400 | [diff] [blame] | 1510 | struct weston_pointer *pointer = grab->pointer; |
Daniel Stone | 4dbadb1 | 2012-05-30 16:31:51 +0100 | [diff] [blame] | 1511 | enum wl_pointer_button_state state = state_w; |
Kristian Høgsberg | 4cca349 | 2011-01-18 07:53:49 -0500 | [diff] [blame] | 1512 | |
Daniel Stone | 4dbadb1 | 2012-05-30 16:31:51 +0100 | [diff] [blame] | 1513 | if (pointer->button_count == 0 && |
| 1514 | state == WL_POINTER_BUTTON_STATE_RELEASED) { |
Ander Conselvan de Oliveira | b9d2a0f | 2012-06-28 18:08:05 +0300 | [diff] [blame] | 1515 | shell_grab_end(shell_grab); |
Kristian Høgsberg | 9ddb826 | 2012-01-04 21:30:29 -0500 | [diff] [blame] | 1516 | free(grab); |
| 1517 | } |
Kristian Høgsberg | 4cca349 | 2011-01-18 07:53:49 -0500 | [diff] [blame] | 1518 | } |
| 1519 | |
Jonas Ådahl | 1ea343e | 2013-10-25 23:18:05 +0200 | [diff] [blame] | 1520 | static void |
| 1521 | move_grab_cancel(struct weston_pointer_grab *grab) |
| 1522 | { |
| 1523 | struct shell_grab *shell_grab = |
| 1524 | container_of(grab, struct shell_grab, grab); |
| 1525 | |
| 1526 | shell_grab_end(shell_grab); |
| 1527 | free(grab); |
| 1528 | } |
| 1529 | |
Kristian Høgsberg | 02bbabb | 2013-05-06 22:15:05 -0400 | [diff] [blame] | 1530 | static const struct weston_pointer_grab_interface move_grab_interface = { |
Kristian Høgsberg | 9ddb826 | 2012-01-04 21:30:29 -0500 | [diff] [blame] | 1531 | noop_grab_focus, |
Kristian Høgsberg | 4cca349 | 2011-01-18 07:53:49 -0500 | [diff] [blame] | 1532 | move_grab_motion, |
| 1533 | move_grab_button, |
Jonas Ådahl | 1ea343e | 2013-10-25 23:18:05 +0200 | [diff] [blame] | 1534 | move_grab_cancel, |
Kristian Høgsberg | 4cca349 | 2011-01-18 07:53:49 -0500 | [diff] [blame] | 1535 | }; |
| 1536 | |
Kristian Høgsberg | 9e31bff | 2012-08-01 00:08:07 -0400 | [diff] [blame] | 1537 | static int |
Kristian Høgsberg | e314875 | 2013-05-06 23:19:49 -0400 | [diff] [blame] | 1538 | surface_move(struct shell_surface *shsurf, struct weston_seat *seat) |
Kristian Høgsberg | 9e31bff | 2012-08-01 00:08:07 -0400 | [diff] [blame] | 1539 | { |
| 1540 | struct weston_move_grab *move; |
| 1541 | |
| 1542 | if (!shsurf) |
| 1543 | return -1; |
| 1544 | |
Kristian Høgsberg | c85f1d4 | 2013-10-24 16:52:00 -0700 | [diff] [blame] | 1545 | if (shsurf->grabbed) |
| 1546 | return 0; |
Kristian Høgsberg | 9e31bff | 2012-08-01 00:08:07 -0400 | [diff] [blame] | 1547 | if (shsurf->type == SHELL_SURFACE_FULLSCREEN) |
| 1548 | return 0; |
| 1549 | |
| 1550 | move = malloc(sizeof *move); |
| 1551 | if (!move) |
| 1552 | return -1; |
| 1553 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 1554 | move->dx = wl_fixed_from_double(shsurf->view->geometry.x) - |
Kristian Høgsberg | e314875 | 2013-05-06 23:19:49 -0400 | [diff] [blame] | 1555 | seat->pointer->grab_x; |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 1556 | move->dy = wl_fixed_from_double(shsurf->view->geometry.y) - |
Kristian Høgsberg | e314875 | 2013-05-06 23:19:49 -0400 | [diff] [blame] | 1557 | seat->pointer->grab_y; |
Kristian Høgsberg | 9e31bff | 2012-08-01 00:08:07 -0400 | [diff] [blame] | 1558 | |
| 1559 | shell_grab_start(&move->base, &move_grab_interface, shsurf, |
Kristian Høgsberg | e314875 | 2013-05-06 23:19:49 -0400 | [diff] [blame] | 1560 | seat->pointer, DESKTOP_SHELL_CURSOR_MOVE); |
Kristian Høgsberg | 9e31bff | 2012-08-01 00:08:07 -0400 | [diff] [blame] | 1561 | |
| 1562 | return 0; |
| 1563 | } |
| 1564 | |
| 1565 | static void |
| 1566 | shell_surface_move(struct wl_client *client, struct wl_resource *resource, |
| 1567 | struct wl_resource *seat_resource, uint32_t serial) |
| 1568 | { |
Jason Ekstrand | 44a3863 | 2013-06-14 10:08:00 -0500 | [diff] [blame] | 1569 | struct weston_seat *seat = wl_resource_get_user_data(seat_resource); |
Jason Ekstrand | 651f00e | 2013-06-14 10:07:54 -0500 | [diff] [blame] | 1570 | struct shell_surface *shsurf = wl_resource_get_user_data(resource); |
Giulio Camuffo | 61da3fc | 2013-04-25 13:57:45 +0300 | [diff] [blame] | 1571 | struct weston_surface *surface; |
Kristian Høgsberg | 9e31bff | 2012-08-01 00:08:07 -0400 | [diff] [blame] | 1572 | |
Kristian Høgsberg | e1b655d | 2013-08-28 23:16:20 -0700 | [diff] [blame] | 1573 | if (seat->pointer && |
| 1574 | seat->pointer->button_count > 0 && |
| 1575 | seat->pointer->grab_serial == serial) { |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 1576 | surface = weston_surface_get_main_surface(seat->pointer->focus->surface); |
Rusty Lynch | 1084da5 | 2013-08-15 09:10:08 -0700 | [diff] [blame] | 1577 | if ((surface == shsurf->surface) && |
| 1578 | (surface_move(shsurf, seat) < 0)) |
| 1579 | wl_resource_post_no_memory(resource); |
Kristian Høgsberg | e1b655d | 2013-08-28 23:16:20 -0700 | [diff] [blame] | 1580 | } else if (seat->touch && |
| 1581 | seat->touch->grab_serial == serial) { |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 1582 | surface = weston_surface_get_main_surface(seat->touch->focus->surface); |
Rusty Lynch | 1084da5 | 2013-08-15 09:10:08 -0700 | [diff] [blame] | 1583 | if ((surface == shsurf->surface) && |
| 1584 | (surface_touch_move(shsurf, seat) < 0)) |
| 1585 | wl_resource_post_no_memory(resource); |
| 1586 | } |
Kristian Høgsberg | 9e31bff | 2012-08-01 00:08:07 -0400 | [diff] [blame] | 1587 | } |
| 1588 | |
| 1589 | struct weston_resize_grab { |
| 1590 | struct shell_grab base; |
| 1591 | uint32_t edges; |
| 1592 | int32_t width, height; |
| 1593 | }; |
| 1594 | |
| 1595 | static void |
Giulio Camuffo | 1959ab8 | 2013-11-14 23:42:52 +0100 | [diff] [blame] | 1596 | resize_grab_motion(struct weston_pointer_grab *grab, uint32_t time, |
| 1597 | wl_fixed_t x, wl_fixed_t y) |
Kristian Høgsberg | 9e31bff | 2012-08-01 00:08:07 -0400 | [diff] [blame] | 1598 | { |
| 1599 | struct weston_resize_grab *resize = (struct weston_resize_grab *) grab; |
Kristian Høgsberg | 02bbabb | 2013-05-06 22:15:05 -0400 | [diff] [blame] | 1600 | struct weston_pointer *pointer = grab->pointer; |
Kristian Høgsberg | 9e31bff | 2012-08-01 00:08:07 -0400 | [diff] [blame] | 1601 | struct shell_surface *shsurf = resize->base.shsurf; |
| 1602 | int32_t width, height; |
| 1603 | wl_fixed_t from_x, from_y; |
| 1604 | wl_fixed_t to_x, to_y; |
| 1605 | |
Giulio Camuffo | 1959ab8 | 2013-11-14 23:42:52 +0100 | [diff] [blame] | 1606 | weston_pointer_move(pointer, x, y); |
| 1607 | |
Kristian Høgsberg | 9e31bff | 2012-08-01 00:08:07 -0400 | [diff] [blame] | 1608 | if (!shsurf) |
| 1609 | return; |
| 1610 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 1611 | weston_view_from_global_fixed(shsurf->view, |
| 1612 | pointer->grab_x, pointer->grab_y, |
| 1613 | &from_x, &from_y); |
| 1614 | weston_view_from_global_fixed(shsurf->view, |
| 1615 | pointer->x, pointer->y, &to_x, &to_y); |
Kristian Høgsberg | 9e31bff | 2012-08-01 00:08:07 -0400 | [diff] [blame] | 1616 | |
| 1617 | width = resize->width; |
| 1618 | if (resize->edges & WL_SHELL_SURFACE_RESIZE_LEFT) { |
| 1619 | width += wl_fixed_to_int(from_x - to_x); |
| 1620 | } else if (resize->edges & WL_SHELL_SURFACE_RESIZE_RIGHT) { |
| 1621 | width += wl_fixed_to_int(to_x - from_x); |
| 1622 | } |
| 1623 | |
| 1624 | height = resize->height; |
| 1625 | if (resize->edges & WL_SHELL_SURFACE_RESIZE_TOP) { |
| 1626 | height += wl_fixed_to_int(from_y - to_y); |
| 1627 | } else if (resize->edges & WL_SHELL_SURFACE_RESIZE_BOTTOM) { |
| 1628 | height += wl_fixed_to_int(to_y - from_y); |
| 1629 | } |
| 1630 | |
| 1631 | shsurf->client->send_configure(shsurf->surface, |
| 1632 | resize->edges, width, height); |
| 1633 | } |
| 1634 | |
| 1635 | static void |
| 1636 | send_configure(struct weston_surface *surface, |
| 1637 | uint32_t edges, int32_t width, int32_t height) |
| 1638 | { |
| 1639 | struct shell_surface *shsurf = get_shell_surface(surface); |
| 1640 | |
Jason Ekstrand | 651f00e | 2013-06-14 10:07:54 -0500 | [diff] [blame] | 1641 | wl_shell_surface_send_configure(shsurf->resource, |
Kristian Høgsberg | 9e31bff | 2012-08-01 00:08:07 -0400 | [diff] [blame] | 1642 | edges, width, height); |
| 1643 | } |
| 1644 | |
| 1645 | static const struct weston_shell_client shell_client = { |
| 1646 | send_configure |
| 1647 | }; |
| 1648 | |
| 1649 | static void |
Kristian Høgsberg | 02bbabb | 2013-05-06 22:15:05 -0400 | [diff] [blame] | 1650 | resize_grab_button(struct weston_pointer_grab *grab, |
Kristian Høgsberg | 9e31bff | 2012-08-01 00:08:07 -0400 | [diff] [blame] | 1651 | uint32_t time, uint32_t button, uint32_t state_w) |
| 1652 | { |
| 1653 | struct weston_resize_grab *resize = (struct weston_resize_grab *) grab; |
Kristian Høgsberg | 02bbabb | 2013-05-06 22:15:05 -0400 | [diff] [blame] | 1654 | struct weston_pointer *pointer = grab->pointer; |
Kristian Høgsberg | 9e31bff | 2012-08-01 00:08:07 -0400 | [diff] [blame] | 1655 | enum wl_pointer_button_state state = state_w; |
| 1656 | |
| 1657 | if (pointer->button_count == 0 && |
| 1658 | state == WL_POINTER_BUTTON_STATE_RELEASED) { |
| 1659 | shell_grab_end(&resize->base); |
| 1660 | free(grab); |
| 1661 | } |
| 1662 | } |
| 1663 | |
Jonas Ådahl | 1ea343e | 2013-10-25 23:18:05 +0200 | [diff] [blame] | 1664 | static void |
| 1665 | resize_grab_cancel(struct weston_pointer_grab *grab) |
| 1666 | { |
| 1667 | struct weston_resize_grab *resize = (struct weston_resize_grab *) grab; |
| 1668 | |
| 1669 | shell_grab_end(&resize->base); |
| 1670 | free(grab); |
| 1671 | } |
| 1672 | |
Kristian Høgsberg | 02bbabb | 2013-05-06 22:15:05 -0400 | [diff] [blame] | 1673 | static const struct weston_pointer_grab_interface resize_grab_interface = { |
Kristian Høgsberg | 9e31bff | 2012-08-01 00:08:07 -0400 | [diff] [blame] | 1674 | noop_grab_focus, |
| 1675 | resize_grab_motion, |
| 1676 | resize_grab_button, |
Jonas Ådahl | 1ea343e | 2013-10-25 23:18:05 +0200 | [diff] [blame] | 1677 | resize_grab_cancel, |
Kristian Høgsberg | 9e31bff | 2012-08-01 00:08:07 -0400 | [diff] [blame] | 1678 | }; |
| 1679 | |
Giulio Camuffo | b836664 | 2013-04-25 13:57:46 +0300 | [diff] [blame] | 1680 | /* |
| 1681 | * Returns the bounding box of a surface and all its sub-surfaces, |
| 1682 | * in the surface coordinates system. */ |
| 1683 | static void |
| 1684 | surface_subsurfaces_boundingbox(struct weston_surface *surface, int32_t *x, |
| 1685 | int32_t *y, int32_t *w, int32_t *h) { |
| 1686 | pixman_region32_t region; |
| 1687 | pixman_box32_t *box; |
| 1688 | struct weston_subsurface *subsurface; |
| 1689 | |
| 1690 | pixman_region32_init_rect(®ion, 0, 0, |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 1691 | surface->width, |
| 1692 | surface->height); |
Giulio Camuffo | b836664 | 2013-04-25 13:57:46 +0300 | [diff] [blame] | 1693 | |
| 1694 | wl_list_for_each(subsurface, &surface->subsurface_list, parent_link) { |
| 1695 | pixman_region32_union_rect(®ion, ®ion, |
| 1696 | subsurface->position.x, |
| 1697 | subsurface->position.y, |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 1698 | subsurface->surface->width, |
| 1699 | subsurface->surface->height); |
Giulio Camuffo | b836664 | 2013-04-25 13:57:46 +0300 | [diff] [blame] | 1700 | } |
| 1701 | |
| 1702 | box = pixman_region32_extents(®ion); |
| 1703 | if (x) |
| 1704 | *x = box->x1; |
| 1705 | if (y) |
| 1706 | *y = box->y1; |
| 1707 | if (w) |
| 1708 | *w = box->x2 - box->x1; |
| 1709 | if (h) |
| 1710 | *h = box->y2 - box->y1; |
| 1711 | |
| 1712 | pixman_region32_fini(®ion); |
| 1713 | } |
| 1714 | |
Kristian Høgsberg | 9e31bff | 2012-08-01 00:08:07 -0400 | [diff] [blame] | 1715 | static int |
| 1716 | surface_resize(struct shell_surface *shsurf, |
Kristian Høgsberg | e314875 | 2013-05-06 23:19:49 -0400 | [diff] [blame] | 1717 | struct weston_seat *seat, uint32_t edges) |
Kristian Høgsberg | 9e31bff | 2012-08-01 00:08:07 -0400 | [diff] [blame] | 1718 | { |
| 1719 | struct weston_resize_grab *resize; |
| 1720 | |
Rafal Mielniczuk | 23c6759 | 2013-03-11 19:26:53 +0100 | [diff] [blame] | 1721 | if (shsurf->type == SHELL_SURFACE_FULLSCREEN || |
| 1722 | shsurf->type == SHELL_SURFACE_MAXIMIZED) |
Kristian Høgsberg | 9e31bff | 2012-08-01 00:08:07 -0400 | [diff] [blame] | 1723 | return 0; |
| 1724 | |
| 1725 | if (edges == 0 || edges > 15 || |
| 1726 | (edges & 3) == 3 || (edges & 12) == 12) |
| 1727 | return 0; |
| 1728 | |
| 1729 | resize = malloc(sizeof *resize); |
| 1730 | if (!resize) |
| 1731 | return -1; |
| 1732 | |
| 1733 | resize->edges = edges; |
Giulio Camuffo | b836664 | 2013-04-25 13:57:46 +0300 | [diff] [blame] | 1734 | surface_subsurfaces_boundingbox(shsurf->surface, NULL, NULL, |
| 1735 | &resize->width, &resize->height); |
Kristian Høgsberg | 9e31bff | 2012-08-01 00:08:07 -0400 | [diff] [blame] | 1736 | |
| 1737 | shell_grab_start(&resize->base, &resize_grab_interface, shsurf, |
Kristian Høgsberg | e314875 | 2013-05-06 23:19:49 -0400 | [diff] [blame] | 1738 | seat->pointer, edges); |
Kristian Høgsberg | 9e31bff | 2012-08-01 00:08:07 -0400 | [diff] [blame] | 1739 | |
| 1740 | return 0; |
| 1741 | } |
| 1742 | |
| 1743 | static void |
| 1744 | shell_surface_resize(struct wl_client *client, struct wl_resource *resource, |
| 1745 | struct wl_resource *seat_resource, uint32_t serial, |
| 1746 | uint32_t edges) |
| 1747 | { |
Jason Ekstrand | 44a3863 | 2013-06-14 10:08:00 -0500 | [diff] [blame] | 1748 | struct weston_seat *seat = wl_resource_get_user_data(seat_resource); |
Jason Ekstrand | 651f00e | 2013-06-14 10:07:54 -0500 | [diff] [blame] | 1749 | struct shell_surface *shsurf = wl_resource_get_user_data(resource); |
Giulio Camuffo | 61da3fc | 2013-04-25 13:57:45 +0300 | [diff] [blame] | 1750 | struct weston_surface *surface; |
Kristian Høgsberg | 9e31bff | 2012-08-01 00:08:07 -0400 | [diff] [blame] | 1751 | |
| 1752 | if (shsurf->type == SHELL_SURFACE_FULLSCREEN) |
| 1753 | return; |
| 1754 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 1755 | surface = weston_surface_get_main_surface(seat->pointer->focus->surface); |
Kristian Høgsberg | e314875 | 2013-05-06 23:19:49 -0400 | [diff] [blame] | 1756 | if (seat->pointer->button_count == 0 || |
| 1757 | seat->pointer->grab_serial != serial || |
Giulio Camuffo | 61da3fc | 2013-04-25 13:57:45 +0300 | [diff] [blame] | 1758 | surface != shsurf->surface) |
Kristian Høgsberg | 9e31bff | 2012-08-01 00:08:07 -0400 | [diff] [blame] | 1759 | return; |
| 1760 | |
Kristian Høgsberg | e314875 | 2013-05-06 23:19:49 -0400 | [diff] [blame] | 1761 | if (surface_resize(shsurf, seat, edges) < 0) |
Kristian Høgsberg | 9e31bff | 2012-08-01 00:08:07 -0400 | [diff] [blame] | 1762 | wl_resource_post_no_memory(resource); |
| 1763 | } |
| 1764 | |
Scott Moreau | c3e54eb | 2012-04-17 19:06:20 -0600 | [diff] [blame] | 1765 | static void |
Kristian Høgsberg | 6780073 | 2013-07-04 01:12:17 -0400 | [diff] [blame] | 1766 | end_busy_cursor(struct shell_surface *shsurf, struct weston_pointer *pointer); |
| 1767 | |
| 1768 | static void |
Kristian Høgsberg | 6848c25 | 2013-05-08 22:02:59 -0400 | [diff] [blame] | 1769 | busy_cursor_grab_focus(struct weston_pointer_grab *base) |
Scott Moreau | c3e54eb | 2012-04-17 19:06:20 -0600 | [diff] [blame] | 1770 | { |
Kristian Høgsberg | d56bd90 | 2012-06-05 09:58:51 -0400 | [diff] [blame] | 1771 | struct shell_grab *grab = (struct shell_grab *) base; |
Kristian Høgsberg | 6848c25 | 2013-05-08 22:02:59 -0400 | [diff] [blame] | 1772 | struct weston_pointer *pointer = base->pointer; |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 1773 | struct weston_view *view; |
Kristian Høgsberg | 6848c25 | 2013-05-08 22:02:59 -0400 | [diff] [blame] | 1774 | wl_fixed_t sx, sy; |
| 1775 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 1776 | view = weston_compositor_pick_view(pointer->seat->compositor, |
| 1777 | pointer->x, pointer->y, |
| 1778 | &sx, &sy); |
Scott Moreau | c3e54eb | 2012-04-17 19:06:20 -0600 | [diff] [blame] | 1779 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 1780 | if (!grab->shsurf || grab->shsurf->surface != view->surface) |
Kristian Høgsberg | 6780073 | 2013-07-04 01:12:17 -0400 | [diff] [blame] | 1781 | end_busy_cursor(grab->shsurf, pointer); |
Scott Moreau | c3e54eb | 2012-04-17 19:06:20 -0600 | [diff] [blame] | 1782 | } |
| 1783 | |
| 1784 | static void |
Giulio Camuffo | 1959ab8 | 2013-11-14 23:42:52 +0100 | [diff] [blame] | 1785 | busy_cursor_grab_motion(struct weston_pointer_grab *grab, uint32_t time, |
| 1786 | wl_fixed_t x, wl_fixed_t y) |
Scott Moreau | c3e54eb | 2012-04-17 19:06:20 -0600 | [diff] [blame] | 1787 | { |
Giulio Camuffo | 1959ab8 | 2013-11-14 23:42:52 +0100 | [diff] [blame] | 1788 | weston_pointer_move(grab->pointer, x, y); |
Kristian Høgsberg | d56bd90 | 2012-06-05 09:58:51 -0400 | [diff] [blame] | 1789 | } |
Scott Moreau | c3e54eb | 2012-04-17 19:06:20 -0600 | [diff] [blame] | 1790 | |
Kristian Høgsberg | d56bd90 | 2012-06-05 09:58:51 -0400 | [diff] [blame] | 1791 | static void |
Kristian Høgsberg | 02bbabb | 2013-05-06 22:15:05 -0400 | [diff] [blame] | 1792 | busy_cursor_grab_button(struct weston_pointer_grab *base, |
Kristian Høgsberg | d56bd90 | 2012-06-05 09:58:51 -0400 | [diff] [blame] | 1793 | uint32_t time, uint32_t button, uint32_t state) |
| 1794 | { |
Kristian Høgsberg | bbe9839 | 2012-08-01 00:20:21 -0400 | [diff] [blame] | 1795 | struct shell_grab *grab = (struct shell_grab *) base; |
Kristian Høgsberg | e122b7b | 2013-05-08 16:47:00 -0400 | [diff] [blame] | 1796 | struct shell_surface *shsurf = grab->shsurf; |
Kristian Høgsberg | e314875 | 2013-05-06 23:19:49 -0400 | [diff] [blame] | 1797 | struct weston_seat *seat = grab->grab.pointer->seat; |
Kristian Høgsberg | bbe9839 | 2012-08-01 00:20:21 -0400 | [diff] [blame] | 1798 | |
Kristian Høgsberg | bbe9839 | 2012-08-01 00:20:21 -0400 | [diff] [blame] | 1799 | if (shsurf && button == BTN_LEFT && state) { |
| 1800 | activate(shsurf->shell, shsurf->surface, seat); |
| 1801 | surface_move(shsurf, seat); |
Kristian Høgsberg | 0c36903 | 2013-02-14 21:31:44 -0500 | [diff] [blame] | 1802 | } else if (shsurf && button == BTN_RIGHT && state) { |
| 1803 | activate(shsurf->shell, shsurf->surface, seat); |
Kristian Høgsberg | e314875 | 2013-05-06 23:19:49 -0400 | [diff] [blame] | 1804 | surface_rotate(shsurf, seat); |
Kristian Høgsberg | bbe9839 | 2012-08-01 00:20:21 -0400 | [diff] [blame] | 1805 | } |
Kristian Høgsberg | d56bd90 | 2012-06-05 09:58:51 -0400 | [diff] [blame] | 1806 | } |
| 1807 | |
Jonas Ådahl | 1ea343e | 2013-10-25 23:18:05 +0200 | [diff] [blame] | 1808 | static void |
| 1809 | busy_cursor_grab_cancel(struct weston_pointer_grab *base) |
| 1810 | { |
| 1811 | struct shell_grab *grab = (struct shell_grab *) base; |
| 1812 | |
| 1813 | shell_grab_end(grab); |
| 1814 | free(grab); |
| 1815 | } |
| 1816 | |
Kristian Høgsberg | 02bbabb | 2013-05-06 22:15:05 -0400 | [diff] [blame] | 1817 | static const struct weston_pointer_grab_interface busy_cursor_grab_interface = { |
Kristian Høgsberg | d56bd90 | 2012-06-05 09:58:51 -0400 | [diff] [blame] | 1818 | busy_cursor_grab_focus, |
| 1819 | busy_cursor_grab_motion, |
| 1820 | busy_cursor_grab_button, |
Jonas Ådahl | 1ea343e | 2013-10-25 23:18:05 +0200 | [diff] [blame] | 1821 | busy_cursor_grab_cancel, |
Kristian Høgsberg | d56bd90 | 2012-06-05 09:58:51 -0400 | [diff] [blame] | 1822 | }; |
| 1823 | |
| 1824 | static void |
Kristian Høgsberg | 02bbabb | 2013-05-06 22:15:05 -0400 | [diff] [blame] | 1825 | set_busy_cursor(struct shell_surface *shsurf, struct weston_pointer *pointer) |
Kristian Høgsberg | d56bd90 | 2012-06-05 09:58:51 -0400 | [diff] [blame] | 1826 | { |
| 1827 | struct shell_grab *grab; |
Kristian Høgsberg | d56bd90 | 2012-06-05 09:58:51 -0400 | [diff] [blame] | 1828 | |
| 1829 | grab = malloc(sizeof *grab); |
| 1830 | if (!grab) |
Scott Moreau | c3e54eb | 2012-04-17 19:06:20 -0600 | [diff] [blame] | 1831 | return; |
| 1832 | |
Ander Conselvan de Oliveira | b9d2a0f | 2012-06-28 18:08:05 +0300 | [diff] [blame] | 1833 | shell_grab_start(grab, &busy_cursor_grab_interface, shsurf, pointer, |
| 1834 | DESKTOP_SHELL_CURSOR_BUSY); |
Kristian Høgsberg | d56bd90 | 2012-06-05 09:58:51 -0400 | [diff] [blame] | 1835 | } |
Scott Moreau | c3e54eb | 2012-04-17 19:06:20 -0600 | [diff] [blame] | 1836 | |
Kristian Høgsberg | d56bd90 | 2012-06-05 09:58:51 -0400 | [diff] [blame] | 1837 | static void |
Kristian Høgsberg | 02bbabb | 2013-05-06 22:15:05 -0400 | [diff] [blame] | 1838 | end_busy_cursor(struct shell_surface *shsurf, struct weston_pointer *pointer) |
Kristian Høgsberg | d56bd90 | 2012-06-05 09:58:51 -0400 | [diff] [blame] | 1839 | { |
| 1840 | struct shell_grab *grab = (struct shell_grab *) pointer->grab; |
| 1841 | |
Kristian Høgsberg | e122b7b | 2013-05-08 16:47:00 -0400 | [diff] [blame] | 1842 | if (grab->grab.interface == &busy_cursor_grab_interface && |
| 1843 | grab->shsurf == shsurf) { |
Ander Conselvan de Oliveira | b9d2a0f | 2012-06-28 18:08:05 +0300 | [diff] [blame] | 1844 | shell_grab_end(grab); |
Kristian Høgsberg | d56bd90 | 2012-06-05 09:58:51 -0400 | [diff] [blame] | 1845 | free(grab); |
Scott Moreau | c3e54eb | 2012-04-17 19:06:20 -0600 | [diff] [blame] | 1846 | } |
Scott Moreau | c3e54eb | 2012-04-17 19:06:20 -0600 | [diff] [blame] | 1847 | } |
| 1848 | |
Scott Moreau | 9521d5e | 2012-04-19 13:06:17 -0600 | [diff] [blame] | 1849 | static void |
| 1850 | ping_timer_destroy(struct shell_surface *shsurf) |
| 1851 | { |
| 1852 | if (!shsurf || !shsurf->ping_timer) |
| 1853 | return; |
| 1854 | |
| 1855 | if (shsurf->ping_timer->source) |
| 1856 | wl_event_source_remove(shsurf->ping_timer->source); |
| 1857 | |
| 1858 | free(shsurf->ping_timer); |
| 1859 | shsurf->ping_timer = NULL; |
| 1860 | } |
| 1861 | |
Kristian Høgsberg | 97d44aa | 2011-08-26 17:21:20 -0400 | [diff] [blame] | 1862 | static int |
Scott Moreau | ff1db4a | 2012-04-17 19:06:18 -0600 | [diff] [blame] | 1863 | ping_timeout_handler(void *data) |
| 1864 | { |
| 1865 | struct shell_surface *shsurf = data; |
Kristian Høgsberg | d56bd90 | 2012-06-05 09:58:51 -0400 | [diff] [blame] | 1866 | struct weston_seat *seat; |
Scott Moreau | ff1db4a | 2012-04-17 19:06:18 -0600 | [diff] [blame] | 1867 | |
Scott Moreau | 9521d5e | 2012-04-19 13:06:17 -0600 | [diff] [blame] | 1868 | /* Client is not responding */ |
| 1869 | shsurf->unresponsive = 1; |
Kristian Høgsberg | d56bd90 | 2012-06-05 09:58:51 -0400 | [diff] [blame] | 1870 | |
| 1871 | wl_list_for_each(seat, &shsurf->surface->compositor->seat_list, link) |
Emilio Pozuelo Monfort | 3d0fc76 | 2013-11-22 16:21:20 +0100 | [diff] [blame] | 1872 | if (seat->pointer->focus && |
| 1873 | seat->pointer->focus->surface == shsurf->surface) |
Kristian Høgsberg | e314875 | 2013-05-06 23:19:49 -0400 | [diff] [blame] | 1874 | set_busy_cursor(shsurf, seat->pointer); |
Scott Moreau | ff1db4a | 2012-04-17 19:06:18 -0600 | [diff] [blame] | 1875 | |
| 1876 | return 1; |
| 1877 | } |
| 1878 | |
| 1879 | static void |
| 1880 | ping_handler(struct weston_surface *surface, uint32_t serial) |
| 1881 | { |
Kristian Høgsberg | b71302e | 2012-05-10 12:28:35 -0400 | [diff] [blame] | 1882 | struct shell_surface *shsurf = get_shell_surface(surface); |
Scott Moreau | ff1db4a | 2012-04-17 19:06:18 -0600 | [diff] [blame] | 1883 | struct wl_event_loop *loop; |
Kristian Høgsberg | d56bd90 | 2012-06-05 09:58:51 -0400 | [diff] [blame] | 1884 | int ping_timeout = 200; |
Scott Moreau | ff1db4a | 2012-04-17 19:06:18 -0600 | [diff] [blame] | 1885 | |
| 1886 | if (!shsurf) |
| 1887 | return; |
Jason Ekstrand | 651f00e | 2013-06-14 10:07:54 -0500 | [diff] [blame] | 1888 | if (!shsurf->resource) |
Kristian Høgsberg | ca535c1 | 2012-04-21 23:20:07 -0400 | [diff] [blame] | 1889 | return; |
Scott Moreau | ff1db4a | 2012-04-17 19:06:18 -0600 | [diff] [blame] | 1890 | |
Ander Conselvan de Oliveira | eac9a46 | 2012-07-16 14:15:48 +0300 | [diff] [blame] | 1891 | if (shsurf->surface == shsurf->shell->grab_surface) |
| 1892 | return; |
| 1893 | |
Scott Moreau | ff1db4a | 2012-04-17 19:06:18 -0600 | [diff] [blame] | 1894 | if (!shsurf->ping_timer) { |
Ander Conselvan de Oliveira | fb98089 | 2012-04-27 13:55:55 +0300 | [diff] [blame] | 1895 | shsurf->ping_timer = malloc(sizeof *shsurf->ping_timer); |
Scott Moreau | ff1db4a | 2012-04-17 19:06:18 -0600 | [diff] [blame] | 1896 | if (!shsurf->ping_timer) |
| 1897 | return; |
| 1898 | |
| 1899 | shsurf->ping_timer->serial = serial; |
Scott Moreau | ff1db4a | 2012-04-17 19:06:18 -0600 | [diff] [blame] | 1900 | loop = wl_display_get_event_loop(surface->compositor->wl_display); |
| 1901 | shsurf->ping_timer->source = |
| 1902 | wl_event_loop_add_timer(loop, ping_timeout_handler, shsurf); |
| 1903 | wl_event_source_timer_update(shsurf->ping_timer->source, ping_timeout); |
| 1904 | |
Jason Ekstrand | 651f00e | 2013-06-14 10:07:54 -0500 | [diff] [blame] | 1905 | wl_shell_surface_send_ping(shsurf->resource, serial); |
Scott Moreau | ff1db4a | 2012-04-17 19:06:18 -0600 | [diff] [blame] | 1906 | } |
| 1907 | } |
| 1908 | |
| 1909 | static void |
Kristian Høgsberg | d56bd90 | 2012-06-05 09:58:51 -0400 | [diff] [blame] | 1910 | handle_pointer_focus(struct wl_listener *listener, void *data) |
| 1911 | { |
Kristian Høgsberg | 02bbabb | 2013-05-06 22:15:05 -0400 | [diff] [blame] | 1912 | struct weston_pointer *pointer = data; |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 1913 | struct weston_view *view = pointer->focus; |
Kristian Høgsberg | d56bd90 | 2012-06-05 09:58:51 -0400 | [diff] [blame] | 1914 | struct weston_compositor *compositor; |
| 1915 | struct shell_surface *shsurf; |
| 1916 | uint32_t serial; |
| 1917 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 1918 | if (!view) |
Kristian Høgsberg | d56bd90 | 2012-06-05 09:58:51 -0400 | [diff] [blame] | 1919 | return; |
| 1920 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 1921 | compositor = view->surface->compositor; |
| 1922 | shsurf = get_shell_surface(view->surface); |
Kristian Høgsberg | d56bd90 | 2012-06-05 09:58:51 -0400 | [diff] [blame] | 1923 | |
Pekka Paalanen | 4e1f2ff | 2012-06-06 16:59:45 +0300 | [diff] [blame] | 1924 | if (shsurf && shsurf->unresponsive) { |
Kristian Høgsberg | d56bd90 | 2012-06-05 09:58:51 -0400 | [diff] [blame] | 1925 | set_busy_cursor(shsurf, pointer); |
| 1926 | } else { |
| 1927 | serial = wl_display_next_serial(compositor->wl_display); |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 1928 | ping_handler(view->surface, serial); |
Kristian Høgsberg | d56bd90 | 2012-06-05 09:58:51 -0400 | [diff] [blame] | 1929 | } |
| 1930 | } |
| 1931 | |
| 1932 | static void |
Kristian Høgsberg | f4d2f23 | 2012-08-10 10:05:39 -0400 | [diff] [blame] | 1933 | create_pointer_focus_listener(struct weston_seat *seat) |
| 1934 | { |
| 1935 | struct wl_listener *listener; |
| 1936 | |
Kristian Høgsberg | e314875 | 2013-05-06 23:19:49 -0400 | [diff] [blame] | 1937 | if (!seat->pointer) |
Kristian Høgsberg | f4d2f23 | 2012-08-10 10:05:39 -0400 | [diff] [blame] | 1938 | return; |
| 1939 | |
| 1940 | listener = malloc(sizeof *listener); |
| 1941 | listener->notify = handle_pointer_focus; |
Kristian Høgsberg | e314875 | 2013-05-06 23:19:49 -0400 | [diff] [blame] | 1942 | wl_signal_add(&seat->pointer->focus_signal, listener); |
Kristian Høgsberg | f4d2f23 | 2012-08-10 10:05:39 -0400 | [diff] [blame] | 1943 | } |
| 1944 | |
| 1945 | static void |
Scott Moreau | ff1db4a | 2012-04-17 19:06:18 -0600 | [diff] [blame] | 1946 | shell_surface_pong(struct wl_client *client, struct wl_resource *resource, |
| 1947 | uint32_t serial) |
| 1948 | { |
Jason Ekstrand | 651f00e | 2013-06-14 10:07:54 -0500 | [diff] [blame] | 1949 | struct shell_surface *shsurf = wl_resource_get_user_data(resource); |
Kristian Høgsberg | d56bd90 | 2012-06-05 09:58:51 -0400 | [diff] [blame] | 1950 | struct weston_seat *seat; |
| 1951 | struct weston_compositor *ec = shsurf->surface->compositor; |
Scott Moreau | ff1db4a | 2012-04-17 19:06:18 -0600 | [diff] [blame] | 1952 | |
Kristian Høgsberg | 92374e1 | 2012-08-11 22:39:12 -0400 | [diff] [blame] | 1953 | if (shsurf->ping_timer == NULL) |
| 1954 | /* Just ignore unsolicited pong. */ |
| 1955 | return; |
| 1956 | |
Scott Moreau | ff1db4a | 2012-04-17 19:06:18 -0600 | [diff] [blame] | 1957 | if (shsurf->ping_timer->serial == serial) { |
Scott Moreau | ff1db4a | 2012-04-17 19:06:18 -0600 | [diff] [blame] | 1958 | shsurf->unresponsive = 0; |
Hardening | eb1e130 | 2013-05-17 18:07:41 +0200 | [diff] [blame] | 1959 | wl_list_for_each(seat, &ec->seat_list, link) { |
| 1960 | if(seat->pointer) |
| 1961 | end_busy_cursor(shsurf, seat->pointer); |
| 1962 | } |
Scott Moreau | 9521d5e | 2012-04-19 13:06:17 -0600 | [diff] [blame] | 1963 | ping_timer_destroy(shsurf); |
Scott Moreau | ff1db4a | 2012-04-17 19:06:18 -0600 | [diff] [blame] | 1964 | } |
| 1965 | } |
| 1966 | |
Kristian Høgsberg | e7afd91 | 2012-05-02 09:47:44 -0400 | [diff] [blame] | 1967 | static void |
Giulio Camuffo | 62942ad | 2013-09-11 18:20:47 +0200 | [diff] [blame] | 1968 | set_title(struct shell_surface *shsurf, const char *title) |
| 1969 | { |
| 1970 | free(shsurf->title); |
| 1971 | shsurf->title = strdup(title); |
| 1972 | } |
| 1973 | |
| 1974 | static void |
Kristian Høgsberg | e7afd91 | 2012-05-02 09:47:44 -0400 | [diff] [blame] | 1975 | shell_surface_set_title(struct wl_client *client, |
| 1976 | struct wl_resource *resource, const char *title) |
| 1977 | { |
Jason Ekstrand | 651f00e | 2013-06-14 10:07:54 -0500 | [diff] [blame] | 1978 | struct shell_surface *shsurf = wl_resource_get_user_data(resource); |
Kristian Høgsberg | e7afd91 | 2012-05-02 09:47:44 -0400 | [diff] [blame] | 1979 | |
Giulio Camuffo | 62942ad | 2013-09-11 18:20:47 +0200 | [diff] [blame] | 1980 | set_title(shsurf, title); |
Kristian Høgsberg | e7afd91 | 2012-05-02 09:47:44 -0400 | [diff] [blame] | 1981 | } |
| 1982 | |
| 1983 | static void |
| 1984 | shell_surface_set_class(struct wl_client *client, |
| 1985 | struct wl_resource *resource, const char *class) |
| 1986 | { |
Jason Ekstrand | 651f00e | 2013-06-14 10:07:54 -0500 | [diff] [blame] | 1987 | struct shell_surface *shsurf = wl_resource_get_user_data(resource); |
Kristian Høgsberg | e7afd91 | 2012-05-02 09:47:44 -0400 | [diff] [blame] | 1988 | |
| 1989 | free(shsurf->class); |
| 1990 | shsurf->class = strdup(class); |
| 1991 | } |
| 1992 | |
Alex Wu | 4539b08 | 2012-03-01 12:57:46 +0800 | [diff] [blame] | 1993 | static void |
Alexander Larsson | f82b6ca | 2013-05-28 16:23:39 +0200 | [diff] [blame] | 1994 | restore_output_mode(struct weston_output *output) |
| 1995 | { |
Hardening | 57388e4 | 2013-09-18 23:56:36 +0200 | [diff] [blame] | 1996 | if (output->current_mode != output->original_mode || |
| 1997 | (int32_t)output->current_scale != output->original_scale) |
Alexander Larsson | f82b6ca | 2013-05-28 16:23:39 +0200 | [diff] [blame] | 1998 | weston_output_switch_mode(output, |
Hardening | 57388e4 | 2013-09-18 23:56:36 +0200 | [diff] [blame] | 1999 | output->original_mode, |
| 2000 | output->original_scale, |
| 2001 | WESTON_MODE_SWITCH_RESTORE_NATIVE); |
Alexander Larsson | f82b6ca | 2013-05-28 16:23:39 +0200 | [diff] [blame] | 2002 | } |
| 2003 | |
| 2004 | static void |
| 2005 | restore_all_output_modes(struct weston_compositor *compositor) |
| 2006 | { |
| 2007 | struct weston_output *output; |
| 2008 | |
| 2009 | wl_list_for_each(output, &compositor->output_list, link) |
| 2010 | restore_output_mode(output); |
| 2011 | } |
| 2012 | |
| 2013 | static void |
Alex Wu | 4539b08 | 2012-03-01 12:57:46 +0800 | [diff] [blame] | 2014 | shell_unset_fullscreen(struct shell_surface *shsurf) |
| 2015 | { |
Rafal Mielniczuk | 3e3862c | 2012-10-07 20:25:36 +0200 | [diff] [blame] | 2016 | struct workspace *ws; |
Alex Wu | 4539b08 | 2012-03-01 12:57:46 +0800 | [diff] [blame] | 2017 | /* undo all fullscreen things here */ |
Alex Wu | bd3354b | 2012-04-17 17:20:49 +0800 | [diff] [blame] | 2018 | if (shsurf->fullscreen.type == WL_SHELL_SURFACE_FULLSCREEN_METHOD_DRIVER && |
| 2019 | shell_surface_is_top_fullscreen(shsurf)) { |
Alexander Larsson | f82b6ca | 2013-05-28 16:23:39 +0200 | [diff] [blame] | 2020 | restore_output_mode(shsurf->fullscreen_output); |
Alex Wu | bd3354b | 2012-04-17 17:20:49 +0800 | [diff] [blame] | 2021 | } |
Alex Wu | 4539b08 | 2012-03-01 12:57:46 +0800 | [diff] [blame] | 2022 | shsurf->fullscreen.type = WL_SHELL_SURFACE_FULLSCREEN_METHOD_DEFAULT; |
| 2023 | shsurf->fullscreen.framerate = 0; |
| 2024 | wl_list_remove(&shsurf->fullscreen.transform.link); |
| 2025 | wl_list_init(&shsurf->fullscreen.transform.link); |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 2026 | if (shsurf->fullscreen.black_view) |
| 2027 | weston_surface_destroy(shsurf->fullscreen.black_view->surface); |
| 2028 | shsurf->fullscreen.black_view = NULL; |
Alex Wu | 4539b08 | 2012-03-01 12:57:46 +0800 | [diff] [blame] | 2029 | shsurf->fullscreen_output = NULL; |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 2030 | weston_view_set_position(shsurf->view, |
| 2031 | shsurf->saved_x, shsurf->saved_y); |
Alex Wu | 7bcb8bd | 2012-04-27 09:07:24 +0800 | [diff] [blame] | 2032 | if (shsurf->saved_rotation_valid) { |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 2033 | wl_list_insert(&shsurf->view->geometry.transformation_list, |
Alex Wu | 7bcb8bd | 2012-04-27 09:07:24 +0800 | [diff] [blame] | 2034 | &shsurf->rotation.transform.link); |
| 2035 | shsurf->saved_rotation_valid = false; |
| 2036 | } |
Rafal Mielniczuk | 3e3862c | 2012-10-07 20:25:36 +0200 | [diff] [blame] | 2037 | |
| 2038 | ws = get_current_workspace(shsurf->shell); |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 2039 | wl_list_remove(&shsurf->view->layer_link); |
| 2040 | wl_list_insert(&ws->layer.view_list, &shsurf->view->layer_link); |
Alex Wu | 4539b08 | 2012-03-01 12:57:46 +0800 | [diff] [blame] | 2041 | } |
| 2042 | |
Rafal Mielniczuk | fffdcdd | 2013-03-11 19:26:54 +0100 | [diff] [blame] | 2043 | static void |
| 2044 | shell_unset_maximized(struct shell_surface *shsurf) |
| 2045 | { |
| 2046 | struct workspace *ws; |
| 2047 | /* undo all maximized things here */ |
| 2048 | shsurf->output = get_default_output(shsurf->surface->compositor); |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 2049 | weston_view_set_position(shsurf->view, |
| 2050 | shsurf->saved_x, |
| 2051 | shsurf->saved_y); |
Rafal Mielniczuk | fffdcdd | 2013-03-11 19:26:54 +0100 | [diff] [blame] | 2052 | |
| 2053 | if (shsurf->saved_rotation_valid) { |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 2054 | wl_list_insert(&shsurf->view->geometry.transformation_list, |
| 2055 | &shsurf->rotation.transform.link); |
Rafal Mielniczuk | fffdcdd | 2013-03-11 19:26:54 +0100 | [diff] [blame] | 2056 | shsurf->saved_rotation_valid = false; |
| 2057 | } |
| 2058 | |
| 2059 | ws = get_current_workspace(shsurf->shell); |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 2060 | wl_list_remove(&shsurf->view->layer_link); |
| 2061 | wl_list_insert(&ws->layer.view_list, &shsurf->view->layer_link); |
Rafal Mielniczuk | fffdcdd | 2013-03-11 19:26:54 +0100 | [diff] [blame] | 2062 | } |
| 2063 | |
Pekka Paalanen | 9826223 | 2011-12-01 10:42:22 +0200 | [diff] [blame] | 2064 | static int |
| 2065 | reset_shell_surface_type(struct shell_surface *surface) |
| 2066 | { |
| 2067 | switch (surface->type) { |
| 2068 | case SHELL_SURFACE_FULLSCREEN: |
Alex Wu | 4539b08 | 2012-03-01 12:57:46 +0800 | [diff] [blame] | 2069 | shell_unset_fullscreen(surface); |
Pekka Paalanen | 9826223 | 2011-12-01 10:42:22 +0200 | [diff] [blame] | 2070 | break; |
Juan Zhao | 96879df | 2012-02-07 08:45:41 +0800 | [diff] [blame] | 2071 | case SHELL_SURFACE_MAXIMIZED: |
Rafal Mielniczuk | fffdcdd | 2013-03-11 19:26:54 +0100 | [diff] [blame] | 2072 | shell_unset_maximized(surface); |
Juan Zhao | 96879df | 2012-02-07 08:45:41 +0800 | [diff] [blame] | 2073 | break; |
Pekka Paalanen | 9826223 | 2011-12-01 10:42:22 +0200 | [diff] [blame] | 2074 | case SHELL_SURFACE_NONE: |
| 2075 | case SHELL_SURFACE_TOPLEVEL: |
| 2076 | case SHELL_SURFACE_TRANSIENT: |
Kristian Høgsberg | b3cca0a | 2012-01-04 22:19:14 -0500 | [diff] [blame] | 2077 | case SHELL_SURFACE_POPUP: |
Tiago Vignatti | fb2adba | 2013-06-12 15:43:21 -0300 | [diff] [blame] | 2078 | case SHELL_SURFACE_XWAYLAND: |
Pekka Paalanen | 9826223 | 2011-12-01 10:42:22 +0200 | [diff] [blame] | 2079 | break; |
| 2080 | } |
| 2081 | |
| 2082 | surface->type = SHELL_SURFACE_NONE; |
| 2083 | return 0; |
| 2084 | } |
| 2085 | |
Kristian Høgsberg | 4cca349 | 2011-01-18 07:53:49 -0500 | [diff] [blame] | 2086 | static void |
Kristian Høgsberg | 7f366e7 | 2012-04-27 17:20:01 -0400 | [diff] [blame] | 2087 | set_surface_type(struct shell_surface *shsurf) |
| 2088 | { |
Kristian Høgsberg | 8150b19 | 2012-06-27 10:22:58 -0400 | [diff] [blame] | 2089 | struct weston_surface *pes = shsurf->parent; |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 2090 | struct weston_view *pev = get_default_view(pes); |
Kristian Høgsberg | 7f366e7 | 2012-04-27 17:20:01 -0400 | [diff] [blame] | 2091 | |
| 2092 | reset_shell_surface_type(shsurf); |
| 2093 | |
| 2094 | shsurf->type = shsurf->next_type; |
| 2095 | shsurf->next_type = SHELL_SURFACE_NONE; |
| 2096 | |
| 2097 | switch (shsurf->type) { |
| 2098 | case SHELL_SURFACE_TOPLEVEL: |
| 2099 | break; |
| 2100 | case SHELL_SURFACE_TRANSIENT: |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 2101 | if (pev) |
| 2102 | weston_view_set_position(shsurf->view, |
| 2103 | pev->geometry.x + shsurf->transient.x, |
| 2104 | pev->geometry.y + shsurf->transient.y); |
Kristian Høgsberg | 7f366e7 | 2012-04-27 17:20:01 -0400 | [diff] [blame] | 2105 | break; |
| 2106 | |
| 2107 | case SHELL_SURFACE_MAXIMIZED: |
Kristian Høgsberg | 7f366e7 | 2012-04-27 17:20:01 -0400 | [diff] [blame] | 2108 | case SHELL_SURFACE_FULLSCREEN: |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 2109 | shsurf->saved_x = shsurf->view->geometry.x; |
| 2110 | shsurf->saved_y = shsurf->view->geometry.y; |
Kristian Høgsberg | 7f366e7 | 2012-04-27 17:20:01 -0400 | [diff] [blame] | 2111 | shsurf->saved_position_valid = true; |
| 2112 | |
| 2113 | if (!wl_list_empty(&shsurf->rotation.transform.link)) { |
| 2114 | wl_list_remove(&shsurf->rotation.transform.link); |
| 2115 | wl_list_init(&shsurf->rotation.transform.link); |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 2116 | weston_view_geometry_dirty(shsurf->view); |
Kristian Høgsberg | 7f366e7 | 2012-04-27 17:20:01 -0400 | [diff] [blame] | 2117 | shsurf->saved_rotation_valid = true; |
| 2118 | } |
| 2119 | break; |
| 2120 | |
Tiago Vignatti | fb2adba | 2013-06-12 15:43:21 -0300 | [diff] [blame] | 2121 | case SHELL_SURFACE_XWAYLAND: |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 2122 | weston_view_set_position(shsurf->view, shsurf->transient.x, |
| 2123 | shsurf->transient.y); |
Tiago Vignatti | fb2adba | 2013-06-12 15:43:21 -0300 | [diff] [blame] | 2124 | break; |
| 2125 | |
Kristian Høgsberg | 7f366e7 | 2012-04-27 17:20:01 -0400 | [diff] [blame] | 2126 | default: |
| 2127 | break; |
| 2128 | } |
| 2129 | } |
| 2130 | |
| 2131 | static void |
Tiago Vignatti | bc052c9 | 2012-04-19 16:18:18 +0300 | [diff] [blame] | 2132 | set_toplevel(struct shell_surface *shsurf) |
| 2133 | { |
Kristian Høgsberg | 7f366e7 | 2012-04-27 17:20:01 -0400 | [diff] [blame] | 2134 | shsurf->next_type = SHELL_SURFACE_TOPLEVEL; |
Tiago Vignatti | bc052c9 | 2012-04-19 16:18:18 +0300 | [diff] [blame] | 2135 | } |
| 2136 | |
| 2137 | static void |
Pekka Paalanen | 9d1613e | 2011-11-25 12:09:16 +0200 | [diff] [blame] | 2138 | shell_surface_set_toplevel(struct wl_client *client, |
| 2139 | struct wl_resource *resource) |
Kristian Høgsberg | 7a5c979 | 2011-06-18 06:12:54 -0400 | [diff] [blame] | 2140 | { |
Jason Ekstrand | 651f00e | 2013-06-14 10:07:54 -0500 | [diff] [blame] | 2141 | struct shell_surface *surface = wl_resource_get_user_data(resource); |
Kristian Høgsberg | 7a5c979 | 2011-06-18 06:12:54 -0400 | [diff] [blame] | 2142 | |
Tiago Vignatti | bc052c9 | 2012-04-19 16:18:18 +0300 | [diff] [blame] | 2143 | set_toplevel(surface); |
Kristian Høgsberg | 7a5c979 | 2011-06-18 06:12:54 -0400 | [diff] [blame] | 2144 | } |
| 2145 | |
| 2146 | static void |
Tiago Vignatti | 491bac1 | 2012-05-18 16:37:43 -0400 | [diff] [blame] | 2147 | set_transient(struct shell_surface *shsurf, |
Kristian Høgsberg | 8150b19 | 2012-06-27 10:22:58 -0400 | [diff] [blame] | 2148 | struct weston_surface *parent, int x, int y, uint32_t flags) |
Tiago Vignatti | 491bac1 | 2012-05-18 16:37:43 -0400 | [diff] [blame] | 2149 | { |
| 2150 | /* assign to parents output */ |
Kristian Høgsberg | 8150b19 | 2012-06-27 10:22:58 -0400 | [diff] [blame] | 2151 | shsurf->parent = parent; |
Tiago Vignatti | 491bac1 | 2012-05-18 16:37:43 -0400 | [diff] [blame] | 2152 | shsurf->transient.x = x; |
| 2153 | shsurf->transient.y = y; |
| 2154 | shsurf->transient.flags = flags; |
| 2155 | shsurf->next_type = SHELL_SURFACE_TRANSIENT; |
| 2156 | } |
| 2157 | |
| 2158 | static void |
Pekka Paalanen | 9d1613e | 2011-11-25 12:09:16 +0200 | [diff] [blame] | 2159 | shell_surface_set_transient(struct wl_client *client, |
| 2160 | struct wl_resource *resource, |
| 2161 | struct wl_resource *parent_resource, |
| 2162 | int x, int y, uint32_t flags) |
Kristian Høgsberg | 7a5c979 | 2011-06-18 06:12:54 -0400 | [diff] [blame] | 2163 | { |
Jason Ekstrand | 651f00e | 2013-06-14 10:07:54 -0500 | [diff] [blame] | 2164 | struct shell_surface *shsurf = wl_resource_get_user_data(resource); |
Jason Ekstrand | 0f2ef7e | 2013-06-14 10:07:53 -0500 | [diff] [blame] | 2165 | struct weston_surface *parent = |
| 2166 | wl_resource_get_user_data(parent_resource); |
Pekka Paalanen | 9826223 | 2011-12-01 10:42:22 +0200 | [diff] [blame] | 2167 | |
Kristian Høgsberg | 8150b19 | 2012-06-27 10:22:58 -0400 | [diff] [blame] | 2168 | set_transient(shsurf, parent, x, y, flags); |
Kristian Høgsberg | 7a5c979 | 2011-06-18 06:12:54 -0400 | [diff] [blame] | 2169 | } |
| 2170 | |
Tiago Vignatti | be14326 | 2012-04-16 17:31:41 +0300 | [diff] [blame] | 2171 | static struct desktop_shell * |
Juan Zhao | 96879df | 2012-02-07 08:45:41 +0800 | [diff] [blame] | 2172 | shell_surface_get_shell(struct shell_surface *shsurf) |
Pekka Paalanen | af0e34c | 2011-12-02 10:59:17 +0200 | [diff] [blame] | 2173 | { |
Kristian Høgsberg | 02e79dc | 2012-04-12 09:55:26 -0400 | [diff] [blame] | 2174 | return shsurf->shell; |
Juan Zhao | 96879df | 2012-02-07 08:45:41 +0800 | [diff] [blame] | 2175 | } |
| 2176 | |
| 2177 | static int |
Tiago Vignatti | be14326 | 2012-04-16 17:31:41 +0300 | [diff] [blame] | 2178 | get_output_panel_height(struct desktop_shell *shell, |
| 2179 | struct weston_output *output) |
Juan Zhao | 96879df | 2012-02-07 08:45:41 +0800 | [diff] [blame] | 2180 | { |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 2181 | struct weston_view *view; |
Juan Zhao | 96879df | 2012-02-07 08:45:41 +0800 | [diff] [blame] | 2182 | int panel_height = 0; |
| 2183 | |
| 2184 | if (!output) |
| 2185 | return 0; |
| 2186 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 2187 | wl_list_for_each(view, &shell->panel_layer.view_list, layer_link) { |
| 2188 | if (view->surface->output == output) { |
| 2189 | panel_height = view->geometry.height; |
Juan Zhao | 96879df | 2012-02-07 08:45:41 +0800 | [diff] [blame] | 2190 | break; |
| 2191 | } |
| 2192 | } |
Kristian Høgsberg | af7b1ff | 2012-06-26 21:19:23 -0400 | [diff] [blame] | 2193 | |
Juan Zhao | 96879df | 2012-02-07 08:45:41 +0800 | [diff] [blame] | 2194 | return panel_height; |
| 2195 | } |
| 2196 | |
| 2197 | static void |
| 2198 | shell_surface_set_maximized(struct wl_client *client, |
| 2199 | struct wl_resource *resource, |
| 2200 | struct wl_resource *output_resource ) |
| 2201 | { |
Jason Ekstrand | 651f00e | 2013-06-14 10:07:54 -0500 | [diff] [blame] | 2202 | struct shell_surface *shsurf = wl_resource_get_user_data(resource); |
Juan Zhao | 96879df | 2012-02-07 08:45:41 +0800 | [diff] [blame] | 2203 | struct weston_surface *es = shsurf->surface; |
Tiago Vignatti | be14326 | 2012-04-16 17:31:41 +0300 | [diff] [blame] | 2204 | struct desktop_shell *shell = NULL; |
Juan Zhao | 96879df | 2012-02-07 08:45:41 +0800 | [diff] [blame] | 2205 | uint32_t edges = 0, panel_height = 0; |
| 2206 | |
| 2207 | /* get the default output, if the client set it as NULL |
| 2208 | check whether the ouput is available */ |
| 2209 | if (output_resource) |
Jason Ekstrand | a0d2dde | 2013-06-14 10:08:01 -0500 | [diff] [blame] | 2210 | shsurf->output = wl_resource_get_user_data(output_resource); |
Kristian Høgsberg | 94de680 | 2012-07-18 09:54:04 -0400 | [diff] [blame] | 2211 | else if (es->output) |
| 2212 | shsurf->output = es->output; |
Juan Zhao | 96879df | 2012-02-07 08:45:41 +0800 | [diff] [blame] | 2213 | else |
| 2214 | shsurf->output = get_default_output(es->compositor); |
| 2215 | |
Tiago Vignatti | be14326 | 2012-04-16 17:31:41 +0300 | [diff] [blame] | 2216 | shell = shell_surface_get_shell(shsurf); |
Rob Bradford | 31b6862 | 2012-07-02 19:00:19 +0100 | [diff] [blame] | 2217 | panel_height = get_output_panel_height(shell, shsurf->output); |
Juan Zhao | 96879df | 2012-02-07 08:45:41 +0800 | [diff] [blame] | 2218 | edges = WL_SHELL_SURFACE_RESIZE_TOP|WL_SHELL_SURFACE_RESIZE_LEFT; |
Kristian Høgsberg | 0b5cd0c | 2012-03-04 21:57:37 -0500 | [diff] [blame] | 2219 | |
Kristian Høgsberg | a61ca06 | 2012-05-22 16:05:52 -0400 | [diff] [blame] | 2220 | shsurf->client->send_configure(shsurf->surface, edges, |
Scott Moreau | 1bad5db | 2012-08-18 01:04:05 -0600 | [diff] [blame] | 2221 | shsurf->output->width, |
| 2222 | shsurf->output->height - panel_height); |
Juan Zhao | 96879df | 2012-02-07 08:45:41 +0800 | [diff] [blame] | 2223 | |
Kristian Høgsberg | 7f366e7 | 2012-04-27 17:20:01 -0400 | [diff] [blame] | 2224 | shsurf->next_type = SHELL_SURFACE_MAXIMIZED; |
Pekka Paalanen | af0e34c | 2011-12-02 10:59:17 +0200 | [diff] [blame] | 2225 | } |
| 2226 | |
Alex Wu | 2185843 | 2012-04-01 20:13:08 +0800 | [diff] [blame] | 2227 | static void |
Giulio Camuffo | 184df50 | 2013-02-21 11:29:21 +0100 | [diff] [blame] | 2228 | 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] | 2229 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 2230 | static struct weston_view * |
Alex Wu | 4539b08 | 2012-03-01 12:57:46 +0800 | [diff] [blame] | 2231 | create_black_surface(struct weston_compositor *ec, |
Alex Wu | 2185843 | 2012-04-01 20:13:08 +0800 | [diff] [blame] | 2232 | struct weston_surface *fs_surface, |
John Kåre Alsaker | 490d02a | 2012-09-30 02:57:21 +0200 | [diff] [blame] | 2233 | float x, float y, int w, int h) |
Alex Wu | 4539b08 | 2012-03-01 12:57:46 +0800 | [diff] [blame] | 2234 | { |
| 2235 | struct weston_surface *surface = NULL; |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 2236 | struct weston_view *view; |
Alex Wu | 4539b08 | 2012-03-01 12:57:46 +0800 | [diff] [blame] | 2237 | |
| 2238 | surface = weston_surface_create(ec); |
| 2239 | if (surface == NULL) { |
Martin Minarik | 6d11836 | 2012-06-07 18:01:59 +0200 | [diff] [blame] | 2240 | weston_log("no memory\n"); |
Alex Wu | 4539b08 | 2012-03-01 12:57:46 +0800 | [diff] [blame] | 2241 | return NULL; |
| 2242 | } |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 2243 | view = weston_view_create(surface); |
| 2244 | if (surface == NULL) { |
| 2245 | weston_log("no memory\n"); |
| 2246 | weston_surface_destroy(surface); |
| 2247 | return NULL; |
| 2248 | } |
Alex Wu | 4539b08 | 2012-03-01 12:57:46 +0800 | [diff] [blame] | 2249 | |
Alex Wu | 2185843 | 2012-04-01 20:13:08 +0800 | [diff] [blame] | 2250 | surface->configure = black_surface_configure; |
Giulio Camuffo | 7fe01b1 | 2013-03-28 18:02:42 +0100 | [diff] [blame] | 2251 | surface->configure_private = fs_surface; |
Alex Wu | 4539b08 | 2012-03-01 12:57:46 +0800 | [diff] [blame] | 2252 | weston_surface_set_color(surface, 0.0, 0.0, 0.0, 1); |
Pekka Paalanen | 71f6f3b | 2012-10-10 12:49:26 +0300 | [diff] [blame] | 2253 | pixman_region32_fini(&surface->opaque); |
Kristian Høgsberg | 61f00f5 | 2012-08-03 16:31:36 -0400 | [diff] [blame] | 2254 | pixman_region32_init_rect(&surface->opaque, 0, 0, w, h); |
Jonas Ådahl | 33619a4 | 2013-01-15 21:25:55 +0100 | [diff] [blame] | 2255 | pixman_region32_fini(&surface->input); |
| 2256 | pixman_region32_init_rect(&surface->input, 0, 0, w, h); |
Kristian Høgsberg | 61f00f5 | 2012-08-03 16:31:36 -0400 | [diff] [blame] | 2257 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 2258 | weston_view_configure(view, x, y, w, h); |
| 2259 | |
| 2260 | return view; |
Alex Wu | 4539b08 | 2012-03-01 12:57:46 +0800 | [diff] [blame] | 2261 | } |
| 2262 | |
| 2263 | /* Create black surface and append it to the associated fullscreen surface. |
| 2264 | * Handle size dismatch and positioning according to the method. */ |
| 2265 | static void |
| 2266 | shell_configure_fullscreen(struct shell_surface *shsurf) |
| 2267 | { |
| 2268 | struct weston_output *output = shsurf->fullscreen_output; |
| 2269 | struct weston_surface *surface = shsurf->surface; |
| 2270 | struct weston_matrix *matrix; |
Kristian Høgsberg | 240dfeb | 2012-07-12 12:32:31 -0400 | [diff] [blame] | 2271 | float scale, output_aspect, surface_aspect, x, y; |
Giulio Camuffo | b836664 | 2013-04-25 13:57:46 +0300 | [diff] [blame] | 2272 | int32_t surf_x, surf_y, surf_width, surf_height; |
Alex Wu | 4539b08 | 2012-03-01 12:57:46 +0800 | [diff] [blame] | 2273 | |
Alexander Larsson | f82b6ca | 2013-05-28 16:23:39 +0200 | [diff] [blame] | 2274 | if (shsurf->fullscreen.type != WL_SHELL_SURFACE_FULLSCREEN_METHOD_DRIVER) |
| 2275 | restore_output_mode(output); |
| 2276 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 2277 | if (!shsurf->fullscreen.black_view) |
| 2278 | shsurf->fullscreen.black_view = |
Kristian Høgsberg | 3be2ce9 | 2012-02-29 12:42:35 -0500 | [diff] [blame] | 2279 | create_black_surface(surface->compositor, |
Alex Wu | 2185843 | 2012-04-01 20:13:08 +0800 | [diff] [blame] | 2280 | surface, |
Kristian Høgsberg | 3be2ce9 | 2012-02-29 12:42:35 -0500 | [diff] [blame] | 2281 | output->x, output->y, |
Scott Moreau | 1bad5db | 2012-08-18 01:04:05 -0600 | [diff] [blame] | 2282 | output->width, |
| 2283 | output->height); |
Kristian Høgsberg | 3be2ce9 | 2012-02-29 12:42:35 -0500 | [diff] [blame] | 2284 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 2285 | wl_list_remove(&shsurf->fullscreen.black_view->layer_link); |
| 2286 | wl_list_insert(&shsurf->view->layer_link, |
| 2287 | &shsurf->fullscreen.black_view->layer_link); |
| 2288 | shsurf->fullscreen.black_view->surface->output = output; |
| 2289 | shsurf->fullscreen.black_view->output = output; |
Alex Wu | 4539b08 | 2012-03-01 12:57:46 +0800 | [diff] [blame] | 2290 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 2291 | surface_subsurfaces_boundingbox(shsurf->surface, &surf_x, &surf_y, |
Giulio Camuffo | b836664 | 2013-04-25 13:57:46 +0300 | [diff] [blame] | 2292 | &surf_width, &surf_height); |
| 2293 | |
Alex Wu | 4539b08 | 2012-03-01 12:57:46 +0800 | [diff] [blame] | 2294 | switch (shsurf->fullscreen.type) { |
| 2295 | case WL_SHELL_SURFACE_FULLSCREEN_METHOD_DEFAULT: |
Pekka Paalanen | de685b8 | 2012-12-04 15:58:12 +0200 | [diff] [blame] | 2296 | if (surface->buffer_ref.buffer) |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 2297 | center_on_output(shsurf->view, shsurf->fullscreen_output); |
Alex Wu | 4539b08 | 2012-03-01 12:57:46 +0800 | [diff] [blame] | 2298 | break; |
| 2299 | case WL_SHELL_SURFACE_FULLSCREEN_METHOD_SCALE: |
Rob Bradford | 9f3dd15 | 2013-02-12 11:53:47 +0000 | [diff] [blame] | 2300 | /* 1:1 mapping between surface and output dimensions */ |
Giulio Camuffo | b836664 | 2013-04-25 13:57:46 +0300 | [diff] [blame] | 2301 | if (output->width == surf_width && |
| 2302 | output->height == surf_height) { |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 2303 | weston_view_set_position(shsurf->view, |
| 2304 | output->x - surf_x, |
| 2305 | output->y - surf_y); |
Rob Bradford | 9f3dd15 | 2013-02-12 11:53:47 +0000 | [diff] [blame] | 2306 | break; |
| 2307 | } |
| 2308 | |
Alex Wu | 4539b08 | 2012-03-01 12:57:46 +0800 | [diff] [blame] | 2309 | matrix = &shsurf->fullscreen.transform.matrix; |
| 2310 | weston_matrix_init(matrix); |
Kristian Høgsberg | 240dfeb | 2012-07-12 12:32:31 -0400 | [diff] [blame] | 2311 | |
Scott Moreau | 1bad5db | 2012-08-18 01:04:05 -0600 | [diff] [blame] | 2312 | output_aspect = (float) output->width / |
| 2313 | (float) output->height; |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 2314 | /* XXX: Use surf_width and surf_height here? */ |
| 2315 | surface_aspect = (float) surface->width / |
| 2316 | (float) surface->height; |
Kristian Høgsberg | 240dfeb | 2012-07-12 12:32:31 -0400 | [diff] [blame] | 2317 | if (output_aspect < surface_aspect) |
Scott Moreau | 1bad5db | 2012-08-18 01:04:05 -0600 | [diff] [blame] | 2318 | scale = (float) output->width / |
Giulio Camuffo | b836664 | 2013-04-25 13:57:46 +0300 | [diff] [blame] | 2319 | (float) surf_width; |
Kristian Høgsberg | 240dfeb | 2012-07-12 12:32:31 -0400 | [diff] [blame] | 2320 | else |
Scott Moreau | 1bad5db | 2012-08-18 01:04:05 -0600 | [diff] [blame] | 2321 | scale = (float) output->height / |
Giulio Camuffo | b836664 | 2013-04-25 13:57:46 +0300 | [diff] [blame] | 2322 | (float) surf_height; |
Kristian Høgsberg | 240dfeb | 2012-07-12 12:32:31 -0400 | [diff] [blame] | 2323 | |
Alex Wu | 4539b08 | 2012-03-01 12:57:46 +0800 | [diff] [blame] | 2324 | weston_matrix_scale(matrix, scale, scale, 1); |
| 2325 | wl_list_remove(&shsurf->fullscreen.transform.link); |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 2326 | wl_list_insert(&shsurf->view->geometry.transformation_list, |
Alex Wu | 4539b08 | 2012-03-01 12:57:46 +0800 | [diff] [blame] | 2327 | &shsurf->fullscreen.transform.link); |
Giulio Camuffo | b836664 | 2013-04-25 13:57:46 +0300 | [diff] [blame] | 2328 | x = output->x + (output->width - surf_width * scale) / 2 - surf_x; |
| 2329 | y = output->y + (output->height - surf_height * scale) / 2 - surf_y; |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 2330 | weston_view_set_position(shsurf->view, x, y); |
Kristian Høgsberg | 240dfeb | 2012-07-12 12:32:31 -0400 | [diff] [blame] | 2331 | |
Alex Wu | 4539b08 | 2012-03-01 12:57:46 +0800 | [diff] [blame] | 2332 | break; |
| 2333 | case WL_SHELL_SURFACE_FULLSCREEN_METHOD_DRIVER: |
Alex Wu | bd3354b | 2012-04-17 17:20:49 +0800 | [diff] [blame] | 2334 | if (shell_surface_is_top_fullscreen(shsurf)) { |
Quentin Glidic | c0d79ce | 2013-01-29 14:16:13 +0100 | [diff] [blame] | 2335 | struct weston_mode mode = {0, |
Pekka Paalanen | 1fd9c0f | 2013-11-26 18:19:41 +0100 | [diff] [blame^] | 2336 | surf_width * surface->buffer_viewport.scale, |
| 2337 | surf_height * surface->buffer_viewport.scale, |
Alex Wu | bd3354b | 2012-04-17 17:20:49 +0800 | [diff] [blame] | 2338 | shsurf->fullscreen.framerate}; |
| 2339 | |
Pekka Paalanen | 1fd9c0f | 2013-11-26 18:19:41 +0100 | [diff] [blame^] | 2340 | if (weston_output_switch_mode(output, &mode, surface->buffer_viewport.scale, |
Hardening | 57388e4 | 2013-09-18 23:56:36 +0200 | [diff] [blame] | 2341 | WESTON_MODE_SWITCH_SET_TEMPORARY) == 0) { |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 2342 | weston_view_set_position(shsurf->view, |
| 2343 | output->x - surf_x, |
| 2344 | output->y - surf_y); |
| 2345 | weston_view_configure(shsurf->fullscreen.black_view, |
| 2346 | output->x - surf_x, |
| 2347 | output->y - surf_y, |
| 2348 | output->width, |
| 2349 | output->height); |
Alex Wu | bd3354b | 2012-04-17 17:20:49 +0800 | [diff] [blame] | 2350 | break; |
Alexander Larsson | d622ed3 | 2013-05-28 16:23:40 +0200 | [diff] [blame] | 2351 | } else { |
Alexander Larsson | f82b6ca | 2013-05-28 16:23:39 +0200 | [diff] [blame] | 2352 | restore_output_mode(output); |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 2353 | center_on_output(shsurf->view, output); |
Alexander Larsson | d622ed3 | 2013-05-28 16:23:40 +0200 | [diff] [blame] | 2354 | } |
Alex Wu | bd3354b | 2012-04-17 17:20:49 +0800 | [diff] [blame] | 2355 | } |
Alex Wu | 4539b08 | 2012-03-01 12:57:46 +0800 | [diff] [blame] | 2356 | break; |
| 2357 | case WL_SHELL_SURFACE_FULLSCREEN_METHOD_FILL: |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 2358 | center_on_output(shsurf->view, output); |
Alex Wu | 4539b08 | 2012-03-01 12:57:46 +0800 | [diff] [blame] | 2359 | break; |
| 2360 | default: |
| 2361 | break; |
| 2362 | } |
| 2363 | } |
| 2364 | |
| 2365 | /* make the fullscreen and black surface at the top */ |
| 2366 | static void |
| 2367 | shell_stack_fullscreen(struct shell_surface *shsurf) |
| 2368 | { |
Alex Wu | bd3354b | 2012-04-17 17:20:49 +0800 | [diff] [blame] | 2369 | struct weston_output *output = shsurf->fullscreen_output; |
Tiago Vignatti | be14326 | 2012-04-16 17:31:41 +0300 | [diff] [blame] | 2370 | struct desktop_shell *shell = shell_surface_get_shell(shsurf); |
Alex Wu | 4539b08 | 2012-03-01 12:57:46 +0800 | [diff] [blame] | 2371 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 2372 | wl_list_remove(&shsurf->view->layer_link); |
| 2373 | wl_list_insert(&shell->fullscreen_layer.view_list, |
| 2374 | &shsurf->view->layer_link); |
| 2375 | weston_surface_damage(shsurf->surface); |
Alex Wu | bd3354b | 2012-04-17 17:20:49 +0800 | [diff] [blame] | 2376 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 2377 | if (!shsurf->fullscreen.black_view) |
| 2378 | shsurf->fullscreen.black_view = |
| 2379 | create_black_surface(shsurf->surface->compositor, |
| 2380 | shsurf->surface, |
Alex Wu | bd3354b | 2012-04-17 17:20:49 +0800 | [diff] [blame] | 2381 | output->x, output->y, |
Scott Moreau | 1bad5db | 2012-08-18 01:04:05 -0600 | [diff] [blame] | 2382 | output->width, |
| 2383 | output->height); |
Alex Wu | bd3354b | 2012-04-17 17:20:49 +0800 | [diff] [blame] | 2384 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 2385 | wl_list_remove(&shsurf->fullscreen.black_view->layer_link); |
| 2386 | wl_list_insert(&shsurf->view->layer_link, |
| 2387 | &shsurf->fullscreen.black_view->layer_link); |
| 2388 | weston_surface_damage(shsurf->fullscreen.black_view->surface); |
Alex Wu | 4539b08 | 2012-03-01 12:57:46 +0800 | [diff] [blame] | 2389 | } |
| 2390 | |
| 2391 | static void |
| 2392 | shell_map_fullscreen(struct shell_surface *shsurf) |
| 2393 | { |
Alex Wu | 4539b08 | 2012-03-01 12:57:46 +0800 | [diff] [blame] | 2394 | shell_stack_fullscreen(shsurf); |
Alex Wu | bd3354b | 2012-04-17 17:20:49 +0800 | [diff] [blame] | 2395 | shell_configure_fullscreen(shsurf); |
Alex Wu | 4539b08 | 2012-03-01 12:57:46 +0800 | [diff] [blame] | 2396 | } |
| 2397 | |
Kristian Høgsberg | 7a5c979 | 2011-06-18 06:12:54 -0400 | [diff] [blame] | 2398 | static void |
Kristian Høgsberg | b810eb5 | 2013-02-12 20:07:05 -0500 | [diff] [blame] | 2399 | set_fullscreen(struct shell_surface *shsurf, |
| 2400 | uint32_t method, |
| 2401 | uint32_t framerate, |
| 2402 | struct weston_output *output) |
Kristian Høgsberg | 7a5c979 | 2011-06-18 06:12:54 -0400 | [diff] [blame] | 2403 | { |
Kristian Høgsberg | 8334bc1 | 2012-01-03 10:29:47 -0500 | [diff] [blame] | 2404 | struct weston_surface *es = shsurf->surface; |
Alex Wu | 4539b08 | 2012-03-01 12:57:46 +0800 | [diff] [blame] | 2405 | |
Kristian Høgsberg | b810eb5 | 2013-02-12 20:07:05 -0500 | [diff] [blame] | 2406 | if (output) |
| 2407 | shsurf->output = output; |
Kristian Høgsberg | 94de680 | 2012-07-18 09:54:04 -0400 | [diff] [blame] | 2408 | else if (es->output) |
| 2409 | shsurf->output = es->output; |
Alex Wu | 4539b08 | 2012-03-01 12:57:46 +0800 | [diff] [blame] | 2410 | else |
| 2411 | shsurf->output = get_default_output(es->compositor); |
Kristian Høgsberg | 7a5c979 | 2011-06-18 06:12:54 -0400 | [diff] [blame] | 2412 | |
Alex Wu | 4539b08 | 2012-03-01 12:57:46 +0800 | [diff] [blame] | 2413 | shsurf->fullscreen_output = shsurf->output; |
| 2414 | shsurf->fullscreen.type = method; |
| 2415 | shsurf->fullscreen.framerate = framerate; |
Kristian Høgsberg | 7f366e7 | 2012-04-27 17:20:01 -0400 | [diff] [blame] | 2416 | shsurf->next_type = SHELL_SURFACE_FULLSCREEN; |
Alex Wu | 4539b08 | 2012-03-01 12:57:46 +0800 | [diff] [blame] | 2417 | |
Kristian Høgsberg | a61ca06 | 2012-05-22 16:05:52 -0400 | [diff] [blame] | 2418 | shsurf->client->send_configure(shsurf->surface, 0, |
Scott Moreau | 1bad5db | 2012-08-18 01:04:05 -0600 | [diff] [blame] | 2419 | shsurf->output->width, |
| 2420 | shsurf->output->height); |
Kristian Høgsberg | 7a5c979 | 2011-06-18 06:12:54 -0400 | [diff] [blame] | 2421 | } |
| 2422 | |
Kristian Høgsberg | b3cca0a | 2012-01-04 22:19:14 -0500 | [diff] [blame] | 2423 | static void |
Kristian Høgsberg | b810eb5 | 2013-02-12 20:07:05 -0500 | [diff] [blame] | 2424 | shell_surface_set_fullscreen(struct wl_client *client, |
| 2425 | struct wl_resource *resource, |
| 2426 | uint32_t method, |
| 2427 | uint32_t framerate, |
| 2428 | struct wl_resource *output_resource) |
| 2429 | { |
Jason Ekstrand | 651f00e | 2013-06-14 10:07:54 -0500 | [diff] [blame] | 2430 | struct shell_surface *shsurf = wl_resource_get_user_data(resource); |
Kristian Høgsberg | b810eb5 | 2013-02-12 20:07:05 -0500 | [diff] [blame] | 2431 | struct weston_output *output; |
| 2432 | |
| 2433 | if (output_resource) |
Jason Ekstrand | a0d2dde | 2013-06-14 10:08:01 -0500 | [diff] [blame] | 2434 | output = wl_resource_get_user_data(output_resource); |
Kristian Høgsberg | b810eb5 | 2013-02-12 20:07:05 -0500 | [diff] [blame] | 2435 | else |
| 2436 | output = NULL; |
| 2437 | |
| 2438 | set_fullscreen(shsurf, method, framerate, output); |
| 2439 | } |
| 2440 | |
Tiago Vignatti | fb2adba | 2013-06-12 15:43:21 -0300 | [diff] [blame] | 2441 | static void |
| 2442 | set_xwayland(struct shell_surface *shsurf, int x, int y, uint32_t flags) |
| 2443 | { |
| 2444 | /* XXX: using the same fields for transient type */ |
| 2445 | shsurf->transient.x = x; |
| 2446 | shsurf->transient.y = y; |
| 2447 | shsurf->transient.flags = flags; |
| 2448 | shsurf->next_type = SHELL_SURFACE_XWAYLAND; |
| 2449 | } |
| 2450 | |
Kristian Høgsberg | 02bbabb | 2013-05-06 22:15:05 -0400 | [diff] [blame] | 2451 | static const struct weston_pointer_grab_interface popup_grab_interface; |
Giulio Camuffo | 5085a75 | 2013-03-25 21:42:45 +0100 | [diff] [blame] | 2452 | |
| 2453 | static void |
| 2454 | destroy_shell_seat(struct wl_listener *listener, void *data) |
| 2455 | { |
| 2456 | struct shell_seat *shseat = |
| 2457 | container_of(listener, |
| 2458 | struct shell_seat, seat_destroy_listener); |
| 2459 | struct shell_surface *shsurf, *prev = NULL; |
| 2460 | |
| 2461 | if (shseat->popup_grab.grab.interface == &popup_grab_interface) { |
Kristian Høgsberg | 02bbabb | 2013-05-06 22:15:05 -0400 | [diff] [blame] | 2462 | weston_pointer_end_grab(shseat->popup_grab.grab.pointer); |
Giulio Camuffo | 5085a75 | 2013-03-25 21:42:45 +0100 | [diff] [blame] | 2463 | shseat->popup_grab.client = NULL; |
| 2464 | |
| 2465 | wl_list_for_each(shsurf, &shseat->popup_grab.surfaces_list, popup.grab_link) { |
| 2466 | shsurf->popup.shseat = NULL; |
| 2467 | if (prev) { |
| 2468 | wl_list_init(&prev->popup.grab_link); |
| 2469 | } |
| 2470 | prev = shsurf; |
| 2471 | } |
| 2472 | wl_list_init(&prev->popup.grab_link); |
| 2473 | } |
| 2474 | |
| 2475 | wl_list_remove(&shseat->seat_destroy_listener.link); |
| 2476 | free(shseat); |
| 2477 | } |
| 2478 | |
| 2479 | static struct shell_seat * |
| 2480 | create_shell_seat(struct weston_seat *seat) |
| 2481 | { |
| 2482 | struct shell_seat *shseat; |
| 2483 | |
| 2484 | shseat = calloc(1, sizeof *shseat); |
| 2485 | if (!shseat) { |
| 2486 | weston_log("no memory to allocate shell seat\n"); |
| 2487 | return NULL; |
| 2488 | } |
| 2489 | |
| 2490 | shseat->seat = seat; |
| 2491 | wl_list_init(&shseat->popup_grab.surfaces_list); |
| 2492 | |
| 2493 | shseat->seat_destroy_listener.notify = destroy_shell_seat; |
| 2494 | wl_signal_add(&seat->destroy_signal, |
| 2495 | &shseat->seat_destroy_listener); |
| 2496 | |
| 2497 | return shseat; |
| 2498 | } |
| 2499 | |
| 2500 | static struct shell_seat * |
| 2501 | get_shell_seat(struct weston_seat *seat) |
| 2502 | { |
| 2503 | struct wl_listener *listener; |
| 2504 | |
| 2505 | listener = wl_signal_get(&seat->destroy_signal, destroy_shell_seat); |
| 2506 | if (listener == NULL) |
| 2507 | return create_shell_seat(seat); |
| 2508 | |
| 2509 | return container_of(listener, |
| 2510 | struct shell_seat, seat_destroy_listener); |
| 2511 | } |
| 2512 | |
Kristian Høgsberg | b810eb5 | 2013-02-12 20:07:05 -0500 | [diff] [blame] | 2513 | static void |
Kristian Høgsberg | 6848c25 | 2013-05-08 22:02:59 -0400 | [diff] [blame] | 2514 | popup_grab_focus(struct weston_pointer_grab *grab) |
Kristian Høgsberg | b3cca0a | 2012-01-04 22:19:14 -0500 | [diff] [blame] | 2515 | { |
Kristian Høgsberg | 02bbabb | 2013-05-06 22:15:05 -0400 | [diff] [blame] | 2516 | struct weston_pointer *pointer = grab->pointer; |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 2517 | struct weston_view *view; |
Giulio Camuffo | 5085a75 | 2013-03-25 21:42:45 +0100 | [diff] [blame] | 2518 | struct shell_seat *shseat = |
| 2519 | container_of(grab, struct shell_seat, popup_grab.grab); |
| 2520 | struct wl_client *client = shseat->popup_grab.client; |
Kristian Høgsberg | 6848c25 | 2013-05-08 22:02:59 -0400 | [diff] [blame] | 2521 | wl_fixed_t sx, sy; |
| 2522 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 2523 | view = weston_compositor_pick_view(pointer->seat->compositor, |
| 2524 | pointer->x, pointer->y, |
| 2525 | &sx, &sy); |
Kristian Høgsberg | b3cca0a | 2012-01-04 22:19:14 -0500 | [diff] [blame] | 2526 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 2527 | if (view && view->surface->resource && |
| 2528 | wl_resource_get_client(view->surface->resource) == client) { |
| 2529 | weston_pointer_set_focus(pointer, view, sx, sy); |
Kristian Høgsberg | b3cca0a | 2012-01-04 22:19:14 -0500 | [diff] [blame] | 2530 | } else { |
Kristian Høgsberg | 02bbabb | 2013-05-06 22:15:05 -0400 | [diff] [blame] | 2531 | weston_pointer_set_focus(pointer, NULL, |
| 2532 | wl_fixed_from_int(0), |
| 2533 | wl_fixed_from_int(0)); |
Kristian Høgsberg | b3cca0a | 2012-01-04 22:19:14 -0500 | [diff] [blame] | 2534 | } |
| 2535 | } |
| 2536 | |
| 2537 | static void |
Giulio Camuffo | 1959ab8 | 2013-11-14 23:42:52 +0100 | [diff] [blame] | 2538 | popup_grab_motion(struct weston_pointer_grab *grab, uint32_t time, |
| 2539 | wl_fixed_t x, wl_fixed_t y) |
Kristian Høgsberg | b3cca0a | 2012-01-04 22:19:14 -0500 | [diff] [blame] | 2540 | { |
Kristian Høgsberg | be6403e | 2013-05-08 21:03:21 -0400 | [diff] [blame] | 2541 | struct weston_pointer *pointer = grab->pointer; |
Neil Roberts | 96d790e | 2013-09-19 17:32:00 +0100 | [diff] [blame] | 2542 | struct wl_resource *resource; |
Kristian Høgsberg | be6403e | 2013-05-08 21:03:21 -0400 | [diff] [blame] | 2543 | wl_fixed_t sx, sy; |
Kristian Høgsberg | b3cca0a | 2012-01-04 22:19:14 -0500 | [diff] [blame] | 2544 | |
Giulio Camuffo | 1959ab8 | 2013-11-14 23:42:52 +0100 | [diff] [blame] | 2545 | weston_pointer_move(pointer, x, y); |
| 2546 | |
Neil Roberts | 96d790e | 2013-09-19 17:32:00 +0100 | [diff] [blame] | 2547 | wl_resource_for_each(resource, &pointer->focus_resource_list) { |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 2548 | weston_view_from_global_fixed(pointer->focus, |
| 2549 | pointer->x, pointer->y, |
| 2550 | &sx, &sy); |
Neil Roberts | 96d790e | 2013-09-19 17:32:00 +0100 | [diff] [blame] | 2551 | wl_pointer_send_motion(resource, time, sx, sy); |
Kristian Høgsberg | be6403e | 2013-05-08 21:03:21 -0400 | [diff] [blame] | 2552 | } |
Kristian Høgsberg | b3cca0a | 2012-01-04 22:19:14 -0500 | [diff] [blame] | 2553 | } |
| 2554 | |
| 2555 | static void |
Kristian Høgsberg | 02bbabb | 2013-05-06 22:15:05 -0400 | [diff] [blame] | 2556 | popup_grab_button(struct weston_pointer_grab *grab, |
Daniel Stone | 4dbadb1 | 2012-05-30 16:31:51 +0100 | [diff] [blame] | 2557 | uint32_t time, uint32_t button, uint32_t state_w) |
Kristian Høgsberg | b3cca0a | 2012-01-04 22:19:14 -0500 | [diff] [blame] | 2558 | { |
| 2559 | struct wl_resource *resource; |
Giulio Camuffo | 5085a75 | 2013-03-25 21:42:45 +0100 | [diff] [blame] | 2560 | struct shell_seat *shseat = |
| 2561 | container_of(grab, struct shell_seat, popup_grab.grab); |
Rob Bradford | 880ebc7 | 2013-07-22 17:31:38 +0100 | [diff] [blame] | 2562 | struct wl_display *display = shseat->seat->compositor->wl_display; |
Daniel Stone | 4dbadb1 | 2012-05-30 16:31:51 +0100 | [diff] [blame] | 2563 | enum wl_pointer_button_state state = state_w; |
Kristian Høgsberg | eae5de7 | 2012-04-11 22:42:15 -0400 | [diff] [blame] | 2564 | uint32_t serial; |
Neil Roberts | 96d790e | 2013-09-19 17:32:00 +0100 | [diff] [blame] | 2565 | struct wl_list *resource_list; |
Kristian Høgsberg | b3cca0a | 2012-01-04 22:19:14 -0500 | [diff] [blame] | 2566 | |
Neil Roberts | 96d790e | 2013-09-19 17:32:00 +0100 | [diff] [blame] | 2567 | resource_list = &grab->pointer->focus_resource_list; |
| 2568 | if (!wl_list_empty(resource_list)) { |
Kristian Høgsberg | eae5de7 | 2012-04-11 22:42:15 -0400 | [diff] [blame] | 2569 | serial = wl_display_get_serial(display); |
Neil Roberts | 96d790e | 2013-09-19 17:32:00 +0100 | [diff] [blame] | 2570 | wl_resource_for_each(resource, resource_list) { |
| 2571 | wl_pointer_send_button(resource, serial, |
| 2572 | time, button, state); |
| 2573 | } |
Daniel Stone | 4dbadb1 | 2012-05-30 16:31:51 +0100 | [diff] [blame] | 2574 | } else if (state == WL_POINTER_BUTTON_STATE_RELEASED && |
Giulio Camuffo | 5085a75 | 2013-03-25 21:42:45 +0100 | [diff] [blame] | 2575 | (shseat->popup_grab.initial_up || |
Kristian Høgsberg | e314875 | 2013-05-06 23:19:49 -0400 | [diff] [blame] | 2576 | time - shseat->seat->pointer->grab_time > 500)) { |
Kristian Høgsberg | 57e0907 | 2012-10-30 14:07:27 -0400 | [diff] [blame] | 2577 | popup_grab_end(grab->pointer); |
Kristian Høgsberg | b3cca0a | 2012-01-04 22:19:14 -0500 | [diff] [blame] | 2578 | } |
| 2579 | |
Daniel Stone | 4dbadb1 | 2012-05-30 16:31:51 +0100 | [diff] [blame] | 2580 | if (state == WL_POINTER_BUTTON_STATE_RELEASED) |
Giulio Camuffo | 5085a75 | 2013-03-25 21:42:45 +0100 | [diff] [blame] | 2581 | shseat->popup_grab.initial_up = 1; |
Kristian Høgsberg | b3cca0a | 2012-01-04 22:19:14 -0500 | [diff] [blame] | 2582 | } |
| 2583 | |
Jonas Ådahl | 1ea343e | 2013-10-25 23:18:05 +0200 | [diff] [blame] | 2584 | static void |
| 2585 | popup_grab_cancel(struct weston_pointer_grab *grab) |
| 2586 | { |
| 2587 | popup_grab_end(grab->pointer); |
| 2588 | } |
| 2589 | |
Kristian Høgsberg | 02bbabb | 2013-05-06 22:15:05 -0400 | [diff] [blame] | 2590 | static const struct weston_pointer_grab_interface popup_grab_interface = { |
Kristian Høgsberg | b3cca0a | 2012-01-04 22:19:14 -0500 | [diff] [blame] | 2591 | popup_grab_focus, |
| 2592 | popup_grab_motion, |
| 2593 | popup_grab_button, |
Jonas Ådahl | 1ea343e | 2013-10-25 23:18:05 +0200 | [diff] [blame] | 2594 | popup_grab_cancel, |
Kristian Høgsberg | b3cca0a | 2012-01-04 22:19:14 -0500 | [diff] [blame] | 2595 | }; |
| 2596 | |
| 2597 | static void |
Kristian Høgsberg | 02bbabb | 2013-05-06 22:15:05 -0400 | [diff] [blame] | 2598 | popup_grab_end(struct weston_pointer *pointer) |
Kristian Høgsberg | 57e0907 | 2012-10-30 14:07:27 -0400 | [diff] [blame] | 2599 | { |
Kristian Høgsberg | 02bbabb | 2013-05-06 22:15:05 -0400 | [diff] [blame] | 2600 | struct weston_pointer_grab *grab = pointer->grab; |
Giulio Camuffo | 5085a75 | 2013-03-25 21:42:45 +0100 | [diff] [blame] | 2601 | struct shell_seat *shseat = |
| 2602 | container_of(grab, struct shell_seat, popup_grab.grab); |
| 2603 | struct shell_surface *shsurf; |
| 2604 | struct shell_surface *prev = NULL; |
Kristian Høgsberg | 57e0907 | 2012-10-30 14:07:27 -0400 | [diff] [blame] | 2605 | |
| 2606 | if (pointer->grab->interface == &popup_grab_interface) { |
Kristian Høgsberg | 02bbabb | 2013-05-06 22:15:05 -0400 | [diff] [blame] | 2607 | weston_pointer_end_grab(grab->pointer); |
Giulio Camuffo | 5085a75 | 2013-03-25 21:42:45 +0100 | [diff] [blame] | 2608 | shseat->popup_grab.client = NULL; |
Philipp Brüschweiler | 63e7be6 | 2013-04-15 21:09:54 +0200 | [diff] [blame] | 2609 | shseat->popup_grab.grab.interface = NULL; |
| 2610 | assert(!wl_list_empty(&shseat->popup_grab.surfaces_list)); |
Giulio Camuffo | 5085a75 | 2013-03-25 21:42:45 +0100 | [diff] [blame] | 2611 | /* Send the popup_done event to all the popups open */ |
| 2612 | 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] | 2613 | wl_shell_surface_send_popup_done(shsurf->resource); |
Giulio Camuffo | 5085a75 | 2013-03-25 21:42:45 +0100 | [diff] [blame] | 2614 | shsurf->popup.shseat = NULL; |
| 2615 | if (prev) { |
| 2616 | wl_list_init(&prev->popup.grab_link); |
| 2617 | } |
| 2618 | prev = shsurf; |
| 2619 | } |
| 2620 | wl_list_init(&prev->popup.grab_link); |
| 2621 | wl_list_init(&shseat->popup_grab.surfaces_list); |
| 2622 | } |
| 2623 | } |
| 2624 | |
| 2625 | static void |
| 2626 | add_popup_grab(struct shell_surface *shsurf, struct shell_seat *shseat) |
| 2627 | { |
Kristian Høgsberg | e314875 | 2013-05-06 23:19:49 -0400 | [diff] [blame] | 2628 | struct weston_seat *seat = shseat->seat; |
Giulio Camuffo | 5085a75 | 2013-03-25 21:42:45 +0100 | [diff] [blame] | 2629 | |
| 2630 | if (wl_list_empty(&shseat->popup_grab.surfaces_list)) { |
Jason Ekstrand | 651f00e | 2013-06-14 10:07:54 -0500 | [diff] [blame] | 2631 | shseat->popup_grab.client = wl_resource_get_client(shsurf->resource); |
Giulio Camuffo | 5085a75 | 2013-03-25 21:42:45 +0100 | [diff] [blame] | 2632 | shseat->popup_grab.grab.interface = &popup_grab_interface; |
Giulio Camuffo | 1b4b61a | 2013-03-27 18:05:26 +0100 | [diff] [blame] | 2633 | /* We must make sure here that this popup was opened after |
| 2634 | * a mouse press, and not just by moving around with other |
| 2635 | * popups already open. */ |
Kristian Høgsberg | e314875 | 2013-05-06 23:19:49 -0400 | [diff] [blame] | 2636 | if (shseat->seat->pointer->button_count > 0) |
Giulio Camuffo | 1b4b61a | 2013-03-27 18:05:26 +0100 | [diff] [blame] | 2637 | shseat->popup_grab.initial_up = 0; |
Giulio Camuffo | 5085a75 | 2013-03-25 21:42:45 +0100 | [diff] [blame] | 2638 | |
Rob Bradford | dfe3105 | 2013-06-26 19:49:11 +0100 | [diff] [blame] | 2639 | 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] | 2640 | weston_pointer_start_grab(seat->pointer, &shseat->popup_grab.grab); |
Rob Bradford | dfe3105 | 2013-06-26 19:49:11 +0100 | [diff] [blame] | 2641 | } else { |
| 2642 | wl_list_insert(&shseat->popup_grab.surfaces_list, &shsurf->popup.grab_link); |
Giulio Camuffo | 5085a75 | 2013-03-25 21:42:45 +0100 | [diff] [blame] | 2643 | } |
Giulio Camuffo | 5085a75 | 2013-03-25 21:42:45 +0100 | [diff] [blame] | 2644 | } |
| 2645 | |
| 2646 | static void |
| 2647 | remove_popup_grab(struct shell_surface *shsurf) |
| 2648 | { |
| 2649 | struct shell_seat *shseat = shsurf->popup.shseat; |
| 2650 | |
| 2651 | wl_list_remove(&shsurf->popup.grab_link); |
| 2652 | wl_list_init(&shsurf->popup.grab_link); |
| 2653 | if (wl_list_empty(&shseat->popup_grab.surfaces_list)) { |
Kristian Høgsberg | 02bbabb | 2013-05-06 22:15:05 -0400 | [diff] [blame] | 2654 | weston_pointer_end_grab(shseat->popup_grab.grab.pointer); |
Philipp Brüschweiler | 63e7be6 | 2013-04-15 21:09:54 +0200 | [diff] [blame] | 2655 | shseat->popup_grab.grab.interface = NULL; |
Kristian Høgsberg | 57e0907 | 2012-10-30 14:07:27 -0400 | [diff] [blame] | 2656 | } |
| 2657 | } |
| 2658 | |
| 2659 | static void |
Kristian Høgsberg | 3730f36 | 2012-04-13 12:40:07 -0400 | [diff] [blame] | 2660 | shell_map_popup(struct shell_surface *shsurf) |
Kristian Høgsberg | b3cca0a | 2012-01-04 22:19:14 -0500 | [diff] [blame] | 2661 | { |
Giulio Camuffo | 5085a75 | 2013-03-25 21:42:45 +0100 | [diff] [blame] | 2662 | struct shell_seat *shseat = shsurf->popup.shseat; |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 2663 | struct weston_view *parent_view = get_default_view(shsurf->parent); |
Kristian Høgsberg | b3cca0a | 2012-01-04 22:19:14 -0500 | [diff] [blame] | 2664 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 2665 | shsurf->surface->output = parent_view->output; |
| 2666 | shsurf->view->output = parent_view->output; |
Kristian Høgsberg | b3cca0a | 2012-01-04 22:19:14 -0500 | [diff] [blame] | 2667 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 2668 | weston_view_set_transform_parent(shsurf->view, parent_view); |
| 2669 | weston_view_set_position(shsurf->view, shsurf->popup.x, shsurf->popup.y); |
| 2670 | weston_view_update_transform(shsurf->view); |
Kristian Høgsberg | b3cca0a | 2012-01-04 22:19:14 -0500 | [diff] [blame] | 2671 | |
Kristian Høgsberg | e314875 | 2013-05-06 23:19:49 -0400 | [diff] [blame] | 2672 | if (shseat->seat->pointer->grab_serial == shsurf->popup.serial) { |
Giulio Camuffo | 5085a75 | 2013-03-25 21:42:45 +0100 | [diff] [blame] | 2673 | add_popup_grab(shsurf, shseat); |
Kristian Høgsberg | 3730f36 | 2012-04-13 12:40:07 -0400 | [diff] [blame] | 2674 | } else { |
Jason Ekstrand | 651f00e | 2013-06-14 10:07:54 -0500 | [diff] [blame] | 2675 | wl_shell_surface_send_popup_done(shsurf->resource); |
Giulio Camuffo | 5085a75 | 2013-03-25 21:42:45 +0100 | [diff] [blame] | 2676 | shseat->popup_grab.client = NULL; |
Kristian Høgsberg | 3730f36 | 2012-04-13 12:40:07 -0400 | [diff] [blame] | 2677 | } |
Kristian Høgsberg | b3cca0a | 2012-01-04 22:19:14 -0500 | [diff] [blame] | 2678 | } |
| 2679 | |
| 2680 | static void |
| 2681 | shell_surface_set_popup(struct wl_client *client, |
| 2682 | struct wl_resource *resource, |
Daniel Stone | 37816df | 2012-05-16 18:45:18 +0100 | [diff] [blame] | 2683 | struct wl_resource *seat_resource, |
Kristian Høgsberg | 3730f36 | 2012-04-13 12:40:07 -0400 | [diff] [blame] | 2684 | uint32_t serial, |
Kristian Høgsberg | b3cca0a | 2012-01-04 22:19:14 -0500 | [diff] [blame] | 2685 | struct wl_resource *parent_resource, |
| 2686 | int32_t x, int32_t y, uint32_t flags) |
| 2687 | { |
Jason Ekstrand | 651f00e | 2013-06-14 10:07:54 -0500 | [diff] [blame] | 2688 | struct shell_surface *shsurf = wl_resource_get_user_data(resource); |
Kristian Høgsberg | b3cca0a | 2012-01-04 22:19:14 -0500 | [diff] [blame] | 2689 | |
Kristian Høgsberg | b3cca0a | 2012-01-04 22:19:14 -0500 | [diff] [blame] | 2690 | shsurf->type = SHELL_SURFACE_POPUP; |
Jason Ekstrand | 651f00e | 2013-06-14 10:07:54 -0500 | [diff] [blame] | 2691 | shsurf->parent = wl_resource_get_user_data(parent_resource); |
Jason Ekstrand | 44a3863 | 2013-06-14 10:08:00 -0500 | [diff] [blame] | 2692 | shsurf->popup.shseat = get_shell_seat(wl_resource_get_user_data(seat_resource)); |
Kristian Høgsberg | 3730f36 | 2012-04-13 12:40:07 -0400 | [diff] [blame] | 2693 | shsurf->popup.serial = serial; |
Kristian Høgsberg | b3cca0a | 2012-01-04 22:19:14 -0500 | [diff] [blame] | 2694 | shsurf->popup.x = x; |
| 2695 | shsurf->popup.y = y; |
| 2696 | } |
| 2697 | |
Pekka Paalanen | 9d1613e | 2011-11-25 12:09:16 +0200 | [diff] [blame] | 2698 | static const struct wl_shell_surface_interface shell_surface_implementation = { |
Scott Moreau | ff1db4a | 2012-04-17 19:06:18 -0600 | [diff] [blame] | 2699 | shell_surface_pong, |
Pekka Paalanen | 9d1613e | 2011-11-25 12:09:16 +0200 | [diff] [blame] | 2700 | shell_surface_move, |
| 2701 | shell_surface_resize, |
| 2702 | shell_surface_set_toplevel, |
| 2703 | shell_surface_set_transient, |
Kristian Høgsberg | b3cca0a | 2012-01-04 22:19:14 -0500 | [diff] [blame] | 2704 | shell_surface_set_fullscreen, |
Juan Zhao | 96879df | 2012-02-07 08:45:41 +0800 | [diff] [blame] | 2705 | shell_surface_set_popup, |
Kristian Høgsberg | e7afd91 | 2012-05-02 09:47:44 -0400 | [diff] [blame] | 2706 | shell_surface_set_maximized, |
| 2707 | shell_surface_set_title, |
| 2708 | shell_surface_set_class |
Pekka Paalanen | 9d1613e | 2011-11-25 12:09:16 +0200 | [diff] [blame] | 2709 | }; |
| 2710 | |
| 2711 | static void |
Tiago Vignatti | bc052c9 | 2012-04-19 16:18:18 +0300 | [diff] [blame] | 2712 | destroy_shell_surface(struct shell_surface *shsurf) |
Pekka Paalanen | 9d1613e | 2011-11-25 12:09:16 +0200 | [diff] [blame] | 2713 | { |
Jason Ekstrand | 651f00e | 2013-06-14 10:07:54 -0500 | [diff] [blame] | 2714 | wl_signal_emit(&shsurf->destroy_signal, shsurf); |
| 2715 | |
Giulio Camuffo | 5085a75 | 2013-03-25 21:42:45 +0100 | [diff] [blame] | 2716 | if (!wl_list_empty(&shsurf->popup.grab_link)) { |
| 2717 | remove_popup_grab(shsurf); |
| 2718 | } |
Kristian Høgsberg | b3cca0a | 2012-01-04 22:19:14 -0500 | [diff] [blame] | 2719 | |
Alex Wu | bd3354b | 2012-04-17 17:20:49 +0800 | [diff] [blame] | 2720 | if (shsurf->fullscreen.type == WL_SHELL_SURFACE_FULLSCREEN_METHOD_DRIVER && |
Alexander Larsson | f82b6ca | 2013-05-28 16:23:39 +0200 | [diff] [blame] | 2721 | shell_surface_is_top_fullscreen(shsurf)) |
| 2722 | restore_output_mode (shsurf->fullscreen_output); |
Pekka Paalanen | 9d1613e | 2011-11-25 12:09:16 +0200 | [diff] [blame] | 2723 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 2724 | if (shsurf->fullscreen.black_view) |
| 2725 | weston_surface_destroy(shsurf->fullscreen.black_view->surface); |
Alex Wu | aa08e2d | 2012-03-05 11:01:40 +0800 | [diff] [blame] | 2726 | |
Alex Wu | bd3354b | 2012-04-17 17:20:49 +0800 | [diff] [blame] | 2727 | /* As destroy_resource() use wl_list_for_each_safe(), |
| 2728 | * we can always remove the listener. |
| 2729 | */ |
| 2730 | wl_list_remove(&shsurf->surface_destroy_listener.link); |
| 2731 | shsurf->surface->configure = NULL; |
Scott Moreau | 9521d5e | 2012-04-19 13:06:17 -0600 | [diff] [blame] | 2732 | ping_timer_destroy(shsurf); |
Scott Moreau | 976a050 | 2013-03-07 10:15:17 -0700 | [diff] [blame] | 2733 | free(shsurf->title); |
Alex Wu | bd3354b | 2012-04-17 17:20:49 +0800 | [diff] [blame] | 2734 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 2735 | weston_view_destroy(shsurf->view); |
| 2736 | |
Pekka Paalanen | 9d1613e | 2011-11-25 12:09:16 +0200 | [diff] [blame] | 2737 | wl_list_remove(&shsurf->link); |
| 2738 | free(shsurf); |
| 2739 | } |
| 2740 | |
| 2741 | static void |
Tiago Vignatti | bc052c9 | 2012-04-19 16:18:18 +0300 | [diff] [blame] | 2742 | shell_destroy_shell_surface(struct wl_resource *resource) |
| 2743 | { |
Jason Ekstrand | 651f00e | 2013-06-14 10:07:54 -0500 | [diff] [blame] | 2744 | struct shell_surface *shsurf = wl_resource_get_user_data(resource); |
Tiago Vignatti | bc052c9 | 2012-04-19 16:18:18 +0300 | [diff] [blame] | 2745 | |
| 2746 | destroy_shell_surface(shsurf); |
| 2747 | } |
| 2748 | |
| 2749 | static void |
Kristian Høgsberg | 27e3052 | 2012-04-11 23:18:23 -0400 | [diff] [blame] | 2750 | shell_handle_surface_destroy(struct wl_listener *listener, void *data) |
Pekka Paalanen | 9d1613e | 2011-11-25 12:09:16 +0200 | [diff] [blame] | 2751 | { |
| 2752 | struct shell_surface *shsurf = container_of(listener, |
| 2753 | struct shell_surface, |
| 2754 | surface_destroy_listener); |
| 2755 | |
Jason Ekstrand | 651f00e | 2013-06-14 10:07:54 -0500 | [diff] [blame] | 2756 | if (shsurf->resource) |
| 2757 | wl_resource_destroy(shsurf->resource); |
| 2758 | else |
Tiago Vignatti | bc052c9 | 2012-04-19 16:18:18 +0300 | [diff] [blame] | 2759 | destroy_shell_surface(shsurf); |
Pekka Paalanen | 9d1613e | 2011-11-25 12:09:16 +0200 | [diff] [blame] | 2760 | } |
| 2761 | |
Kristian Høgsberg | d813445 | 2012-06-21 12:49:02 -0400 | [diff] [blame] | 2762 | static void |
Giulio Camuffo | 184df50 | 2013-02-21 11:29:21 +0100 | [diff] [blame] | 2763 | 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] | 2764 | |
Pekka Paalanen | ec2b32f | 2011-11-28 15:12:34 +0200 | [diff] [blame] | 2765 | static struct shell_surface * |
Kristian Høgsberg | 8334bc1 | 2012-01-03 10:29:47 -0500 | [diff] [blame] | 2766 | get_shell_surface(struct weston_surface *surface) |
Pekka Paalanen | ec2b32f | 2011-11-28 15:12:34 +0200 | [diff] [blame] | 2767 | { |
Kristian Høgsberg | d813445 | 2012-06-21 12:49:02 -0400 | [diff] [blame] | 2768 | if (surface->configure == shell_surface_configure) |
Giulio Camuffo | 7fe01b1 | 2013-03-28 18:02:42 +0100 | [diff] [blame] | 2769 | return surface->configure_private; |
Kristian Høgsberg | d813445 | 2012-06-21 12:49:02 -0400 | [diff] [blame] | 2770 | else |
| 2771 | return NULL; |
Pekka Paalanen | ec2b32f | 2011-11-28 15:12:34 +0200 | [diff] [blame] | 2772 | } |
| 2773 | |
Kristian Høgsberg | 45ba869 | 2012-05-21 14:27:33 -0400 | [diff] [blame] | 2774 | static struct shell_surface * |
Kristian Høgsberg | a61ca06 | 2012-05-22 16:05:52 -0400 | [diff] [blame] | 2775 | create_shell_surface(void *shell, struct weston_surface *surface, |
| 2776 | const struct weston_shell_client *client) |
Pekka Paalanen | 9d1613e | 2011-11-25 12:09:16 +0200 | [diff] [blame] | 2777 | { |
Pekka Paalanen | 9d1613e | 2011-11-25 12:09:16 +0200 | [diff] [blame] | 2778 | struct shell_surface *shsurf; |
| 2779 | |
Ander Conselvan de Oliveira | 093bfa3 | 2012-03-27 17:36:41 +0300 | [diff] [blame] | 2780 | if (surface->configure) { |
Martin Minarik | 6d11836 | 2012-06-07 18:01:59 +0200 | [diff] [blame] | 2781 | weston_log("surface->configure already set\n"); |
Kristian Høgsberg | 45ba869 | 2012-05-21 14:27:33 -0400 | [diff] [blame] | 2782 | return NULL; |
Ander Conselvan de Oliveira | 093bfa3 | 2012-03-27 17:36:41 +0300 | [diff] [blame] | 2783 | } |
| 2784 | |
Pekka Paalanen | 9d1613e | 2011-11-25 12:09:16 +0200 | [diff] [blame] | 2785 | shsurf = calloc(1, sizeof *shsurf); |
| 2786 | if (!shsurf) { |
Martin Minarik | 6d11836 | 2012-06-07 18:01:59 +0200 | [diff] [blame] | 2787 | weston_log("no memory to allocate shell surface\n"); |
Kristian Høgsberg | 45ba869 | 2012-05-21 14:27:33 -0400 | [diff] [blame] | 2788 | return NULL; |
Pekka Paalanen | 9d1613e | 2011-11-25 12:09:16 +0200 | [diff] [blame] | 2789 | } |
| 2790 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 2791 | shsurf->view = weston_view_create(surface); |
| 2792 | if (!shsurf->view) { |
| 2793 | weston_log("no memory to allocate shell surface\n"); |
| 2794 | free(shsurf); |
| 2795 | return NULL; |
| 2796 | } |
| 2797 | |
Ander Conselvan de Oliveira | 093bfa3 | 2012-03-27 17:36:41 +0300 | [diff] [blame] | 2798 | surface->configure = shell_surface_configure; |
Giulio Camuffo | 7fe01b1 | 2013-03-28 18:02:42 +0100 | [diff] [blame] | 2799 | surface->configure_private = shsurf; |
Ander Conselvan de Oliveira | 093bfa3 | 2012-03-27 17:36:41 +0300 | [diff] [blame] | 2800 | |
Tiago Vignatti | bc052c9 | 2012-04-19 16:18:18 +0300 | [diff] [blame] | 2801 | shsurf->shell = (struct desktop_shell *) shell; |
Scott Moreau | ff1db4a | 2012-04-17 19:06:18 -0600 | [diff] [blame] | 2802 | shsurf->unresponsive = 0; |
Alex Wu | 4539b08 | 2012-03-01 12:57:46 +0800 | [diff] [blame] | 2803 | shsurf->saved_position_valid = false; |
Alex Wu | 7bcb8bd | 2012-04-27 09:07:24 +0800 | [diff] [blame] | 2804 | shsurf->saved_rotation_valid = false; |
Pekka Paalanen | 9d1613e | 2011-11-25 12:09:16 +0200 | [diff] [blame] | 2805 | shsurf->surface = surface; |
Alex Wu | 4539b08 | 2012-03-01 12:57:46 +0800 | [diff] [blame] | 2806 | shsurf->fullscreen.type = WL_SHELL_SURFACE_FULLSCREEN_METHOD_DEFAULT; |
| 2807 | shsurf->fullscreen.framerate = 0; |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 2808 | shsurf->fullscreen.black_view = NULL; |
Scott Moreau | ff1db4a | 2012-04-17 19:06:18 -0600 | [diff] [blame] | 2809 | shsurf->ping_timer = NULL; |
Alex Wu | 4539b08 | 2012-03-01 12:57:46 +0800 | [diff] [blame] | 2810 | wl_list_init(&shsurf->fullscreen.transform.link); |
| 2811 | |
Jason Ekstrand | 651f00e | 2013-06-14 10:07:54 -0500 | [diff] [blame] | 2812 | wl_signal_init(&shsurf->destroy_signal); |
Kristian Høgsberg | 27e3052 | 2012-04-11 23:18:23 -0400 | [diff] [blame] | 2813 | shsurf->surface_destroy_listener.notify = shell_handle_surface_destroy; |
Jason Ekstrand | 26ed73c | 2013-06-06 22:34:41 -0500 | [diff] [blame] | 2814 | wl_signal_add(&surface->destroy_signal, |
Kristian Høgsberg | 27e3052 | 2012-04-11 23:18:23 -0400 | [diff] [blame] | 2815 | &shsurf->surface_destroy_listener); |
Pekka Paalanen | 9d1613e | 2011-11-25 12:09:16 +0200 | [diff] [blame] | 2816 | |
| 2817 | /* init link so its safe to always remove it in destroy_shell_surface */ |
| 2818 | wl_list_init(&shsurf->link); |
Giulio Camuffo | 5085a75 | 2013-03-25 21:42:45 +0100 | [diff] [blame] | 2819 | wl_list_init(&shsurf->popup.grab_link); |
Pekka Paalanen | 9d1613e | 2011-11-25 12:09:16 +0200 | [diff] [blame] | 2820 | |
Pekka Paalanen | 460099f | 2012-01-20 16:48:25 +0200 | [diff] [blame] | 2821 | /* empty when not in use */ |
| 2822 | wl_list_init(&shsurf->rotation.transform.link); |
Kristian Høgsberg | 765e27b | 2012-01-27 13:36:13 -0500 | [diff] [blame] | 2823 | weston_matrix_init(&shsurf->rotation.rotation); |
Pekka Paalanen | 460099f | 2012-01-20 16:48:25 +0200 | [diff] [blame] | 2824 | |
Jonas Ådahl | 62fcd04 | 2012-06-13 00:01:23 +0200 | [diff] [blame] | 2825 | wl_list_init(&shsurf->workspace_transform.link); |
| 2826 | |
Pekka Paalanen | 9826223 | 2011-12-01 10:42:22 +0200 | [diff] [blame] | 2827 | shsurf->type = SHELL_SURFACE_NONE; |
Kristian Høgsberg | 7f366e7 | 2012-04-27 17:20:01 -0400 | [diff] [blame] | 2828 | shsurf->next_type = SHELL_SURFACE_NONE; |
Pekka Paalanen | 9d1613e | 2011-11-25 12:09:16 +0200 | [diff] [blame] | 2829 | |
Kristian Høgsberg | a61ca06 | 2012-05-22 16:05:52 -0400 | [diff] [blame] | 2830 | shsurf->client = client; |
| 2831 | |
Kristian Høgsberg | 45ba869 | 2012-05-21 14:27:33 -0400 | [diff] [blame] | 2832 | return shsurf; |
Tiago Vignatti | bc052c9 | 2012-04-19 16:18:18 +0300 | [diff] [blame] | 2833 | } |
| 2834 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 2835 | static struct weston_view * |
| 2836 | get_primary_view(void *shell, struct shell_surface *shsurf) |
| 2837 | { |
| 2838 | return shsurf->view; |
| 2839 | } |
| 2840 | |
Tiago Vignatti | bc052c9 | 2012-04-19 16:18:18 +0300 | [diff] [blame] | 2841 | static void |
| 2842 | shell_get_shell_surface(struct wl_client *client, |
| 2843 | struct wl_resource *resource, |
| 2844 | uint32_t id, |
| 2845 | struct wl_resource *surface_resource) |
| 2846 | { |
Jason Ekstrand | 0f2ef7e | 2013-06-14 10:07:53 -0500 | [diff] [blame] | 2847 | struct weston_surface *surface = |
| 2848 | wl_resource_get_user_data(surface_resource); |
Jason Ekstrand | 651f00e | 2013-06-14 10:07:54 -0500 | [diff] [blame] | 2849 | struct desktop_shell *shell = wl_resource_get_user_data(resource); |
Tiago Vignatti | bc052c9 | 2012-04-19 16:18:18 +0300 | [diff] [blame] | 2850 | struct shell_surface *shsurf; |
| 2851 | |
| 2852 | if (get_shell_surface(surface)) { |
| 2853 | wl_resource_post_error(surface_resource, |
Kristian Høgsberg | 9540ea6 | 2012-05-21 14:28:57 -0400 | [diff] [blame] | 2854 | WL_DISPLAY_ERROR_INVALID_OBJECT, |
| 2855 | "desktop_shell::get_shell_surface already requested"); |
Tiago Vignatti | bc052c9 | 2012-04-19 16:18:18 +0300 | [diff] [blame] | 2856 | return; |
| 2857 | } |
| 2858 | |
Kristian Høgsberg | a61ca06 | 2012-05-22 16:05:52 -0400 | [diff] [blame] | 2859 | shsurf = create_shell_surface(shell, surface, &shell_client); |
Kristian Høgsberg | 9540ea6 | 2012-05-21 14:28:57 -0400 | [diff] [blame] | 2860 | if (!shsurf) { |
| 2861 | wl_resource_post_error(surface_resource, |
| 2862 | WL_DISPLAY_ERROR_INVALID_OBJECT, |
| 2863 | "surface->configure already set"); |
| 2864 | return; |
| 2865 | } |
Tiago Vignatti | bc052c9 | 2012-04-19 16:18:18 +0300 | [diff] [blame] | 2866 | |
Jason Ekstrand | a85118c | 2013-06-27 20:17:02 -0500 | [diff] [blame] | 2867 | shsurf->resource = |
| 2868 | wl_resource_create(client, |
| 2869 | &wl_shell_surface_interface, 1, id); |
| 2870 | wl_resource_set_implementation(shsurf->resource, |
| 2871 | &shell_surface_implementation, |
| 2872 | shsurf, shell_destroy_shell_surface); |
Pekka Paalanen | 9d1613e | 2011-11-25 12:09:16 +0200 | [diff] [blame] | 2873 | } |
| 2874 | |
| 2875 | static const struct wl_shell_interface shell_implementation = { |
Pekka Paalanen | 4622967 | 2011-11-29 15:49:31 +0200 | [diff] [blame] | 2876 | shell_get_shell_surface |
Kristian Høgsberg | 4cca349 | 2011-01-18 07:53:49 -0500 | [diff] [blame] | 2877 | }; |
| 2878 | |
Kristian Høgsberg | 0793756 | 2011-04-12 17:25:42 -0400 | [diff] [blame] | 2879 | static void |
Ander Conselvan de Oliveira | 859e885 | 2013-02-21 18:35:21 +0200 | [diff] [blame] | 2880 | shell_fade(struct desktop_shell *shell, enum fade_type type); |
| 2881 | |
| 2882 | static int |
| 2883 | screensaver_timeout(void *data) |
| 2884 | { |
| 2885 | struct desktop_shell *shell = data; |
| 2886 | |
| 2887 | shell_fade(shell, FADE_OUT); |
| 2888 | |
| 2889 | return 1; |
| 2890 | } |
| 2891 | |
| 2892 | static void |
Kristian Høgsberg | 8334bc1 | 2012-01-03 10:29:47 -0500 | [diff] [blame] | 2893 | handle_screensaver_sigchld(struct weston_process *proc, int status) |
Pekka Paalanen | 18027e5 | 2011-12-02 16:31:49 +0200 | [diff] [blame] | 2894 | { |
Ander Conselvan de Oliveira | 18639f8 | 2013-02-15 18:44:19 +0200 | [diff] [blame] | 2895 | struct desktop_shell *shell = |
| 2896 | container_of(proc, struct desktop_shell, screensaver.process); |
Ander Conselvan de Oliveira | 18639f8 | 2013-02-15 18:44:19 +0200 | [diff] [blame] | 2897 | |
Pekka Paalanen | 18027e5 | 2011-12-02 16:31:49 +0200 | [diff] [blame] | 2898 | proc->pid = 0; |
Ander Conselvan de Oliveira | 18639f8 | 2013-02-15 18:44:19 +0200 | [diff] [blame] | 2899 | |
| 2900 | if (shell->locked) |
Ander Conselvan de Oliveira | b17537e | 2013-02-22 14:16:18 +0200 | [diff] [blame] | 2901 | weston_compositor_sleep(shell->compositor); |
Pekka Paalanen | 18027e5 | 2011-12-02 16:31:49 +0200 | [diff] [blame] | 2902 | } |
| 2903 | |
| 2904 | static void |
Tiago Vignatti | be14326 | 2012-04-16 17:31:41 +0300 | [diff] [blame] | 2905 | launch_screensaver(struct desktop_shell *shell) |
Pekka Paalanen | 77346a6 | 2011-11-30 16:26:35 +0200 | [diff] [blame] | 2906 | { |
| 2907 | if (shell->screensaver.binding) |
| 2908 | return; |
| 2909 | |
Ander Conselvan de Oliveira | dda9d78 | 2013-02-22 14:16:19 +0200 | [diff] [blame] | 2910 | if (!shell->screensaver.path) { |
| 2911 | weston_compositor_sleep(shell->compositor); |
Pekka Paalanen | e955f1e | 2011-12-07 11:49:52 +0200 | [diff] [blame] | 2912 | return; |
Ander Conselvan de Oliveira | dda9d78 | 2013-02-22 14:16:19 +0200 | [diff] [blame] | 2913 | } |
Pekka Paalanen | e955f1e | 2011-12-07 11:49:52 +0200 | [diff] [blame] | 2914 | |
Kristian Høgsberg | 32bed57 | 2012-03-01 17:11:36 -0500 | [diff] [blame] | 2915 | if (shell->screensaver.process.pid != 0) { |
Martin Minarik | 6d11836 | 2012-06-07 18:01:59 +0200 | [diff] [blame] | 2916 | weston_log("old screensaver still running\n"); |
Kristian Høgsberg | 32bed57 | 2012-03-01 17:11:36 -0500 | [diff] [blame] | 2917 | return; |
| 2918 | } |
| 2919 | |
Kristian Høgsberg | 8334bc1 | 2012-01-03 10:29:47 -0500 | [diff] [blame] | 2920 | weston_client_launch(shell->compositor, |
Pekka Paalanen | 18027e5 | 2011-12-02 16:31:49 +0200 | [diff] [blame] | 2921 | &shell->screensaver.process, |
Pekka Paalanen | e955f1e | 2011-12-07 11:49:52 +0200 | [diff] [blame] | 2922 | shell->screensaver.path, |
Pekka Paalanen | 18027e5 | 2011-12-02 16:31:49 +0200 | [diff] [blame] | 2923 | handle_screensaver_sigchld); |
Pekka Paalanen | 77346a6 | 2011-11-30 16:26:35 +0200 | [diff] [blame] | 2924 | } |
| 2925 | |
| 2926 | static void |
Tiago Vignatti | be14326 | 2012-04-16 17:31:41 +0300 | [diff] [blame] | 2927 | terminate_screensaver(struct desktop_shell *shell) |
Pekka Paalanen | 77346a6 | 2011-11-30 16:26:35 +0200 | [diff] [blame] | 2928 | { |
Pekka Paalanen | 18027e5 | 2011-12-02 16:31:49 +0200 | [diff] [blame] | 2929 | if (shell->screensaver.process.pid == 0) |
| 2930 | return; |
| 2931 | |
| 2932 | kill(shell->screensaver.process.pid, SIGTERM); |
Pekka Paalanen | 77346a6 | 2011-11-30 16:26:35 +0200 | [diff] [blame] | 2933 | } |
| 2934 | |
| 2935 | static void |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 2936 | 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] | 2937 | { |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 2938 | struct weston_view *v, *next; |
Kristian Høgsberg | 962342c | 2012-06-26 16:29:50 -0400 | [diff] [blame] | 2939 | |
Giulio Camuffo | 184df50 | 2013-02-21 11:29:21 +0100 | [diff] [blame] | 2940 | if (width == 0) |
| 2941 | return; |
| 2942 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 2943 | wl_list_for_each_safe(v, next, &layer->view_list, layer_link) { |
| 2944 | if (v->output == ev->output && v != ev) { |
| 2945 | weston_view_unmap(v); |
| 2946 | v->surface->configure = NULL; |
Kristian Høgsberg | 962342c | 2012-06-26 16:29:50 -0400 | [diff] [blame] | 2947 | } |
| 2948 | } |
| 2949 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 2950 | 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] | 2951 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 2952 | if (wl_list_empty(&ev->layer_link)) { |
| 2953 | wl_list_insert(&layer->view_list, &ev->layer_link); |
| 2954 | weston_compositor_schedule_repaint(ev->surface->compositor); |
Kristian Høgsberg | 962342c | 2012-06-26 16:29:50 -0400 | [diff] [blame] | 2955 | } |
| 2956 | } |
| 2957 | |
| 2958 | static void |
Giulio Camuffo | 184df50 | 2013-02-21 11:29:21 +0100 | [diff] [blame] | 2959 | 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] | 2960 | { |
Giulio Camuffo | 7fe01b1 | 2013-03-28 18:02:42 +0100 | [diff] [blame] | 2961 | struct desktop_shell *shell = es->configure_private; |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 2962 | struct weston_view *view; |
Kristian Høgsberg | af7b1ff | 2012-06-26 21:19:23 -0400 | [diff] [blame] | 2963 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 2964 | view = container_of(es->views.next, struct weston_view, surface_link); |
| 2965 | |
| 2966 | configure_static_view(view, &shell->background_layer, width, height); |
Kristian Høgsberg | af7b1ff | 2012-06-26 21:19:23 -0400 | [diff] [blame] | 2967 | } |
| 2968 | |
| 2969 | static void |
Kristian Høgsberg | 7584062 | 2011-09-06 13:48:16 -0400 | [diff] [blame] | 2970 | desktop_shell_set_background(struct wl_client *client, |
| 2971 | struct wl_resource *resource, |
Benjamin Franzke | d0f79ab | 2011-11-22 12:43:52 +0100 | [diff] [blame] | 2972 | struct wl_resource *output_resource, |
Kristian Høgsberg | 7584062 | 2011-09-06 13:48:16 -0400 | [diff] [blame] | 2973 | struct wl_resource *surface_resource) |
| 2974 | { |
Jason Ekstrand | 651f00e | 2013-06-14 10:07:54 -0500 | [diff] [blame] | 2975 | struct desktop_shell *shell = wl_resource_get_user_data(resource); |
Jason Ekstrand | 0f2ef7e | 2013-06-14 10:07:53 -0500 | [diff] [blame] | 2976 | struct weston_surface *surface = |
| 2977 | wl_resource_get_user_data(surface_resource); |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 2978 | struct weston_view *view, *next; |
Kristian Høgsberg | 7584062 | 2011-09-06 13:48:16 -0400 | [diff] [blame] | 2979 | |
Kristian Høgsberg | 962342c | 2012-06-26 16:29:50 -0400 | [diff] [blame] | 2980 | if (surface->configure) { |
| 2981 | wl_resource_post_error(surface_resource, |
| 2982 | WL_DISPLAY_ERROR_INVALID_OBJECT, |
| 2983 | "surface role already assigned"); |
| 2984 | return; |
| 2985 | } |
Benjamin Franzke | d0f79ab | 2011-11-22 12:43:52 +0100 | [diff] [blame] | 2986 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 2987 | wl_list_for_each_safe(view, next, &surface->views, surface_link) |
| 2988 | weston_view_destroy(view); |
| 2989 | view = weston_view_create(surface); |
| 2990 | |
Kristian Høgsberg | 962342c | 2012-06-26 16:29:50 -0400 | [diff] [blame] | 2991 | surface->configure = background_configure; |
Giulio Camuffo | 7fe01b1 | 2013-03-28 18:02:42 +0100 | [diff] [blame] | 2992 | surface->configure_private = shell; |
Jason Ekstrand | a0d2dde | 2013-06-14 10:08:01 -0500 | [diff] [blame] | 2993 | surface->output = wl_resource_get_user_data(output_resource); |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 2994 | view->output = surface->output; |
Kristian Høgsberg | eae5de7 | 2012-04-11 22:42:15 -0400 | [diff] [blame] | 2995 | desktop_shell_send_configure(resource, 0, |
Kristian Høgsberg | 0b5cd0c | 2012-03-04 21:57:37 -0500 | [diff] [blame] | 2996 | surface_resource, |
Scott Moreau | 1bad5db | 2012-08-18 01:04:05 -0600 | [diff] [blame] | 2997 | surface->output->width, |
| 2998 | surface->output->height); |
Kristian Høgsberg | 7584062 | 2011-09-06 13:48:16 -0400 | [diff] [blame] | 2999 | } |
| 3000 | |
| 3001 | static void |
Giulio Camuffo | 184df50 | 2013-02-21 11:29:21 +0100 | [diff] [blame] | 3002 | 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] | 3003 | { |
Giulio Camuffo | 7fe01b1 | 2013-03-28 18:02:42 +0100 | [diff] [blame] | 3004 | struct desktop_shell *shell = es->configure_private; |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 3005 | struct weston_view *view; |
Kristian Høgsberg | af7b1ff | 2012-06-26 21:19:23 -0400 | [diff] [blame] | 3006 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 3007 | view = container_of(es->views.next, struct weston_view, surface_link); |
| 3008 | |
| 3009 | configure_static_view(view, &shell->panel_layer, width, height); |
Kristian Høgsberg | af7b1ff | 2012-06-26 21:19:23 -0400 | [diff] [blame] | 3010 | } |
| 3011 | |
| 3012 | static void |
Kristian Høgsberg | 7584062 | 2011-09-06 13:48:16 -0400 | [diff] [blame] | 3013 | desktop_shell_set_panel(struct wl_client *client, |
| 3014 | struct wl_resource *resource, |
Benjamin Franzke | d0f79ab | 2011-11-22 12:43:52 +0100 | [diff] [blame] | 3015 | struct wl_resource *output_resource, |
Kristian Høgsberg | 7584062 | 2011-09-06 13:48:16 -0400 | [diff] [blame] | 3016 | struct wl_resource *surface_resource) |
| 3017 | { |
Jason Ekstrand | 651f00e | 2013-06-14 10:07:54 -0500 | [diff] [blame] | 3018 | struct desktop_shell *shell = wl_resource_get_user_data(resource); |
Jason Ekstrand | 0f2ef7e | 2013-06-14 10:07:53 -0500 | [diff] [blame] | 3019 | struct weston_surface *surface = |
| 3020 | wl_resource_get_user_data(surface_resource); |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 3021 | struct weston_view *view, *next; |
Kristian Høgsberg | 7584062 | 2011-09-06 13:48:16 -0400 | [diff] [blame] | 3022 | |
Kristian Høgsberg | af7b1ff | 2012-06-26 21:19:23 -0400 | [diff] [blame] | 3023 | if (surface->configure) { |
| 3024 | wl_resource_post_error(surface_resource, |
| 3025 | WL_DISPLAY_ERROR_INVALID_OBJECT, |
| 3026 | "surface role already assigned"); |
| 3027 | return; |
| 3028 | } |
Benjamin Franzke | d0f79ab | 2011-11-22 12:43:52 +0100 | [diff] [blame] | 3029 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 3030 | wl_list_for_each_safe(view, next, &surface->views, surface_link) |
| 3031 | weston_view_destroy(view); |
| 3032 | view = weston_view_create(surface); |
| 3033 | |
Kristian Høgsberg | af7b1ff | 2012-06-26 21:19:23 -0400 | [diff] [blame] | 3034 | surface->configure = panel_configure; |
Giulio Camuffo | 7fe01b1 | 2013-03-28 18:02:42 +0100 | [diff] [blame] | 3035 | surface->configure_private = shell; |
Jason Ekstrand | a0d2dde | 2013-06-14 10:08:01 -0500 | [diff] [blame] | 3036 | surface->output = wl_resource_get_user_data(output_resource); |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 3037 | view->output = surface->output; |
Kristian Høgsberg | eae5de7 | 2012-04-11 22:42:15 -0400 | [diff] [blame] | 3038 | desktop_shell_send_configure(resource, 0, |
Kristian Høgsberg | af7b1ff | 2012-06-26 21:19:23 -0400 | [diff] [blame] | 3039 | surface_resource, |
Scott Moreau | 1bad5db | 2012-08-18 01:04:05 -0600 | [diff] [blame] | 3040 | surface->output->width, |
| 3041 | surface->output->height); |
Kristian Høgsberg | 7584062 | 2011-09-06 13:48:16 -0400 | [diff] [blame] | 3042 | } |
| 3043 | |
Pekka Paalanen | 9ef3e01 | 2011-11-15 13:34:48 +0200 | [diff] [blame] | 3044 | static void |
Giulio Camuffo | 184df50 | 2013-02-21 11:29:21 +0100 | [diff] [blame] | 3045 | 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] | 3046 | { |
Giulio Camuffo | 7fe01b1 | 2013-03-28 18:02:42 +0100 | [diff] [blame] | 3047 | struct desktop_shell *shell = surface->configure_private; |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 3048 | struct weston_view *view; |
| 3049 | |
| 3050 | view = container_of(surface->views.next, struct weston_view, surface_link); |
Kristian Høgsberg | 730c94d | 2012-06-26 21:44:35 -0400 | [diff] [blame] | 3051 | |
Giulio Camuffo | 184df50 | 2013-02-21 11:29:21 +0100 | [diff] [blame] | 3052 | if (width == 0) |
| 3053 | return; |
| 3054 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 3055 | surface->width = width; |
| 3056 | surface->height = height; |
| 3057 | view->geometry.width = width; |
| 3058 | view->geometry.height = height; |
| 3059 | center_on_output(view, get_default_output(shell->compositor)); |
Kristian Høgsberg | 730c94d | 2012-06-26 21:44:35 -0400 | [diff] [blame] | 3060 | |
| 3061 | if (!weston_surface_is_mapped(surface)) { |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 3062 | wl_list_insert(&shell->lock_layer.view_list, |
| 3063 | &view->layer_link); |
| 3064 | weston_view_update_transform(view); |
Ander Conselvan de Oliveira | 87524b6 | 2013-02-21 18:35:22 +0200 | [diff] [blame] | 3065 | shell_fade(shell, FADE_IN); |
Kristian Høgsberg | 730c94d | 2012-06-26 21:44:35 -0400 | [diff] [blame] | 3066 | } |
| 3067 | } |
| 3068 | |
| 3069 | static void |
Kristian Høgsberg | 27e3052 | 2012-04-11 23:18:23 -0400 | [diff] [blame] | 3070 | handle_lock_surface_destroy(struct wl_listener *listener, void *data) |
Kristian Høgsberg | 1ec0c31 | 2011-11-15 16:39:55 -0500 | [diff] [blame] | 3071 | { |
Tiago Vignatti | be14326 | 2012-04-16 17:31:41 +0300 | [diff] [blame] | 3072 | struct desktop_shell *shell = |
| 3073 | container_of(listener, struct desktop_shell, lock_surface_listener); |
Kristian Høgsberg | 1ec0c31 | 2011-11-15 16:39:55 -0500 | [diff] [blame] | 3074 | |
Martin Minarik | 6d11836 | 2012-06-07 18:01:59 +0200 | [diff] [blame] | 3075 | weston_log("lock surface gone\n"); |
Kristian Høgsberg | 1ec0c31 | 2011-11-15 16:39:55 -0500 | [diff] [blame] | 3076 | shell->lock_surface = NULL; |
| 3077 | } |
| 3078 | |
| 3079 | static void |
Pekka Paalanen | 9ef3e01 | 2011-11-15 13:34:48 +0200 | [diff] [blame] | 3080 | desktop_shell_set_lock_surface(struct wl_client *client, |
| 3081 | struct wl_resource *resource, |
| 3082 | struct wl_resource *surface_resource) |
| 3083 | { |
Jason Ekstrand | 651f00e | 2013-06-14 10:07:54 -0500 | [diff] [blame] | 3084 | struct desktop_shell *shell = wl_resource_get_user_data(resource); |
Jason Ekstrand | 0f2ef7e | 2013-06-14 10:07:53 -0500 | [diff] [blame] | 3085 | struct weston_surface *surface = |
| 3086 | wl_resource_get_user_data(surface_resource); |
Pekka Paalanen | 9826223 | 2011-12-01 10:42:22 +0200 | [diff] [blame] | 3087 | |
Pekka Paalanen | f0fc70d | 2011-11-15 13:34:54 +0200 | [diff] [blame] | 3088 | shell->prepare_event_sent = false; |
Kristian Høgsberg | af867cc | 2011-11-15 13:34:49 +0200 | [diff] [blame] | 3089 | |
Pekka Paalanen | f0fc70d | 2011-11-15 13:34:54 +0200 | [diff] [blame] | 3090 | if (!shell->locked) |
| 3091 | return; |
| 3092 | |
Pekka Paalanen | 9826223 | 2011-12-01 10:42:22 +0200 | [diff] [blame] | 3093 | shell->lock_surface = surface; |
Pekka Paalanen | f0fc70d | 2011-11-15 13:34:54 +0200 | [diff] [blame] | 3094 | |
Kristian Høgsberg | 27e3052 | 2012-04-11 23:18:23 -0400 | [diff] [blame] | 3095 | shell->lock_surface_listener.notify = handle_lock_surface_destroy; |
Jason Ekstrand | 651f00e | 2013-06-14 10:07:54 -0500 | [diff] [blame] | 3096 | wl_signal_add(&surface->destroy_signal, |
Kristian Høgsberg | 27e3052 | 2012-04-11 23:18:23 -0400 | [diff] [blame] | 3097 | &shell->lock_surface_listener); |
Pekka Paalanen | 57da4a8 | 2011-11-23 16:42:16 +0200 | [diff] [blame] | 3098 | |
Kristian Høgsberg | aa2ee8b | 2013-10-30 15:49:45 -0700 | [diff] [blame] | 3099 | weston_view_create(surface); |
Kristian Høgsberg | 730c94d | 2012-06-26 21:44:35 -0400 | [diff] [blame] | 3100 | surface->configure = lock_surface_configure; |
Giulio Camuffo | 7fe01b1 | 2013-03-28 18:02:42 +0100 | [diff] [blame] | 3101 | surface->configure_private = shell; |
Pekka Paalanen | f0fc70d | 2011-11-15 13:34:54 +0200 | [diff] [blame] | 3102 | } |
| 3103 | |
| 3104 | static void |
Tiago Vignatti | be14326 | 2012-04-16 17:31:41 +0300 | [diff] [blame] | 3105 | resume_desktop(struct desktop_shell *shell) |
Pekka Paalanen | f0fc70d | 2011-11-15 13:34:54 +0200 | [diff] [blame] | 3106 | { |
Kristian Høgsberg | 4476aaf | 2012-06-25 14:03:13 -0400 | [diff] [blame] | 3107 | struct workspace *ws = get_current_workspace(shell); |
Pekka Paalanen | 77346a6 | 2011-11-30 16:26:35 +0200 | [diff] [blame] | 3108 | |
Pekka Paalanen | 77346a6 | 2011-11-30 16:26:35 +0200 | [diff] [blame] | 3109 | terminate_screensaver(shell); |
Pekka Paalanen | f0fc70d | 2011-11-15 13:34:54 +0200 | [diff] [blame] | 3110 | |
Kristian Høgsberg | 3be2ce9 | 2012-02-29 12:42:35 -0500 | [diff] [blame] | 3111 | wl_list_remove(&shell->lock_layer.link); |
| 3112 | wl_list_insert(&shell->compositor->cursor_layer.link, |
| 3113 | &shell->fullscreen_layer.link); |
| 3114 | wl_list_insert(&shell->fullscreen_layer.link, |
| 3115 | &shell->panel_layer.link); |
Philipp Brüschweiler | 711fda8 | 2012-08-09 18:50:43 +0200 | [diff] [blame] | 3116 | if (shell->showing_input_panels) { |
| 3117 | wl_list_insert(&shell->panel_layer.link, |
| 3118 | &shell->input_panel_layer.link); |
| 3119 | wl_list_insert(&shell->input_panel_layer.link, |
| 3120 | &ws->layer.link); |
| 3121 | } else { |
| 3122 | wl_list_insert(&shell->panel_layer.link, &ws->layer.link); |
| 3123 | } |
Pekka Paalanen | f0fc70d | 2011-11-15 13:34:54 +0200 | [diff] [blame] | 3124 | |
Kristian Høgsberg | 2f5faff | 2012-07-31 16:36:34 -0400 | [diff] [blame] | 3125 | restore_focus_state(shell, get_current_workspace(shell)); |
Jonas Ådahl | 0476974 | 2012-06-13 00:01:24 +0200 | [diff] [blame] | 3126 | |
Pekka Paalanen | f0fc70d | 2011-11-15 13:34:54 +0200 | [diff] [blame] | 3127 | shell->locked = false; |
Ander Conselvan de Oliveira | 87524b6 | 2013-02-21 18:35:22 +0200 | [diff] [blame] | 3128 | shell_fade(shell, FADE_IN); |
Pekka Paalanen | fc6d91a | 2012-02-10 15:33:10 +0200 | [diff] [blame] | 3129 | weston_compositor_damage_all(shell->compositor); |
Pekka Paalanen | 9ef3e01 | 2011-11-15 13:34:48 +0200 | [diff] [blame] | 3130 | } |
| 3131 | |
| 3132 | static void |
| 3133 | desktop_shell_unlock(struct wl_client *client, |
| 3134 | struct wl_resource *resource) |
| 3135 | { |
Jason Ekstrand | 651f00e | 2013-06-14 10:07:54 -0500 | [diff] [blame] | 3136 | struct desktop_shell *shell = wl_resource_get_user_data(resource); |
Pekka Paalanen | 9ef3e01 | 2011-11-15 13:34:48 +0200 | [diff] [blame] | 3137 | |
Pekka Paalanen | 9ef3e01 | 2011-11-15 13:34:48 +0200 | [diff] [blame] | 3138 | shell->prepare_event_sent = false; |
Pekka Paalanen | f0fc70d | 2011-11-15 13:34:54 +0200 | [diff] [blame] | 3139 | |
| 3140 | if (shell->locked) |
| 3141 | resume_desktop(shell); |
Pekka Paalanen | 9ef3e01 | 2011-11-15 13:34:48 +0200 | [diff] [blame] | 3142 | } |
| 3143 | |
Kristian Høgsberg | d56bd90 | 2012-06-05 09:58:51 -0400 | [diff] [blame] | 3144 | static void |
Ander Conselvan de Oliveira | b9d2a0f | 2012-06-28 18:08:05 +0300 | [diff] [blame] | 3145 | desktop_shell_set_grab_surface(struct wl_client *client, |
Kristian Høgsberg | d56bd90 | 2012-06-05 09:58:51 -0400 | [diff] [blame] | 3146 | struct wl_resource *resource, |
| 3147 | struct wl_resource *surface_resource) |
| 3148 | { |
Jason Ekstrand | 651f00e | 2013-06-14 10:07:54 -0500 | [diff] [blame] | 3149 | struct desktop_shell *shell = wl_resource_get_user_data(resource); |
Kristian Høgsberg | d56bd90 | 2012-06-05 09:58:51 -0400 | [diff] [blame] | 3150 | |
Jason Ekstrand | 0f2ef7e | 2013-06-14 10:07:53 -0500 | [diff] [blame] | 3151 | shell->grab_surface = wl_resource_get_user_data(surface_resource); |
Kristian Høgsberg | 48588f8 | 2013-10-24 15:51:35 -0700 | [diff] [blame] | 3152 | weston_view_create(shell->grab_surface); |
Kristian Høgsberg | d56bd90 | 2012-06-05 09:58:51 -0400 | [diff] [blame] | 3153 | } |
| 3154 | |
Pekka Paalanen | 79346ab | 2013-05-22 18:03:09 +0300 | [diff] [blame] | 3155 | static void |
| 3156 | desktop_shell_desktop_ready(struct wl_client *client, |
| 3157 | struct wl_resource *resource) |
| 3158 | { |
Jason Ekstrand | 651f00e | 2013-06-14 10:07:54 -0500 | [diff] [blame] | 3159 | struct desktop_shell *shell = wl_resource_get_user_data(resource); |
Pekka Paalanen | 79346ab | 2013-05-22 18:03:09 +0300 | [diff] [blame] | 3160 | |
| 3161 | shell_fade_startup(shell); |
| 3162 | } |
| 3163 | |
Kristian Høgsberg | 7584062 | 2011-09-06 13:48:16 -0400 | [diff] [blame] | 3164 | static const struct desktop_shell_interface desktop_shell_implementation = { |
| 3165 | desktop_shell_set_background, |
Pekka Paalanen | 9ef3e01 | 2011-11-15 13:34:48 +0200 | [diff] [blame] | 3166 | desktop_shell_set_panel, |
| 3167 | desktop_shell_set_lock_surface, |
Kristian Høgsberg | d56bd90 | 2012-06-05 09:58:51 -0400 | [diff] [blame] | 3168 | desktop_shell_unlock, |
Pekka Paalanen | 79346ab | 2013-05-22 18:03:09 +0300 | [diff] [blame] | 3169 | desktop_shell_set_grab_surface, |
| 3170 | desktop_shell_desktop_ready |
Kristian Høgsberg | 7584062 | 2011-09-06 13:48:16 -0400 | [diff] [blame] | 3171 | }; |
| 3172 | |
Pekka Paalanen | 92a0dc4 | 2011-11-28 15:34:13 +0200 | [diff] [blame] | 3173 | static enum shell_surface_type |
Kristian Høgsberg | 8334bc1 | 2012-01-03 10:29:47 -0500 | [diff] [blame] | 3174 | get_shell_surface_type(struct weston_surface *surface) |
Pekka Paalanen | 92a0dc4 | 2011-11-28 15:34:13 +0200 | [diff] [blame] | 3175 | { |
| 3176 | struct shell_surface *shsurf; |
| 3177 | |
| 3178 | shsurf = get_shell_surface(surface); |
| 3179 | if (!shsurf) |
Pekka Paalanen | 9826223 | 2011-12-01 10:42:22 +0200 | [diff] [blame] | 3180 | return SHELL_SURFACE_NONE; |
Pekka Paalanen | 92a0dc4 | 2011-11-28 15:34:13 +0200 | [diff] [blame] | 3181 | return shsurf->type; |
| 3182 | } |
| 3183 | |
Kristian Høgsberg | 7584062 | 2011-09-06 13:48:16 -0400 | [diff] [blame] | 3184 | static void |
Kristian Høgsberg | e314875 | 2013-05-06 23:19:49 -0400 | [diff] [blame] | 3185 | 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] | 3186 | { |
Kristian Høgsberg | 7ab139c | 2013-10-24 16:21:39 -0700 | [diff] [blame] | 3187 | struct weston_surface *focus = seat->pointer->focus->surface; |
Pekka Paalanen | 01388e2 | 2013-04-25 13:57:44 +0300 | [diff] [blame] | 3188 | struct weston_surface *surface; |
Kristian Høgsberg | 938b8fa | 2012-05-18 13:46:27 -0400 | [diff] [blame] | 3189 | struct shell_surface *shsurf; |
Kristian Høgsberg | d2abb83 | 2011-11-23 10:52:40 -0500 | [diff] [blame] | 3190 | |
Pekka Paalanen | 01388e2 | 2013-04-25 13:57:44 +0300 | [diff] [blame] | 3191 | surface = weston_surface_get_main_surface(focus); |
Benjamin Franzke | d0f79ab | 2011-11-22 12:43:52 +0100 | [diff] [blame] | 3192 | if (surface == NULL) |
| 3193 | return; |
Kristian Høgsberg | 0793756 | 2011-04-12 17:25:42 -0400 | [diff] [blame] | 3194 | |
Kristian Høgsberg | 938b8fa | 2012-05-18 13:46:27 -0400 | [diff] [blame] | 3195 | shsurf = get_shell_surface(surface); |
Rafal Mielniczuk | 23c6759 | 2013-03-11 19:26:53 +0100 | [diff] [blame] | 3196 | if (shsurf == NULL || shsurf->type == SHELL_SURFACE_FULLSCREEN || |
| 3197 | shsurf->type == SHELL_SURFACE_MAXIMIZED) |
Kristian Høgsberg | 938b8fa | 2012-05-18 13:46:27 -0400 | [diff] [blame] | 3198 | return; |
| 3199 | |
Kristian Høgsberg | 938b8fa | 2012-05-18 13:46:27 -0400 | [diff] [blame] | 3200 | surface_move(shsurf, (struct weston_seat *) seat); |
Kristian Høgsberg | 0793756 | 2011-04-12 17:25:42 -0400 | [diff] [blame] | 3201 | } |
| 3202 | |
| 3203 | static void |
Neil Roberts | aba0f25 | 2013-10-03 16:43:05 +0100 | [diff] [blame] | 3204 | touch_move_binding(struct weston_seat *seat, uint32_t time, void *data) |
| 3205 | { |
Kristian Høgsberg | 7ab139c | 2013-10-24 16:21:39 -0700 | [diff] [blame] | 3206 | struct weston_surface *focus = seat->touch->focus->surface; |
Neil Roberts | aba0f25 | 2013-10-03 16:43:05 +0100 | [diff] [blame] | 3207 | struct weston_surface *surface; |
| 3208 | struct shell_surface *shsurf; |
| 3209 | |
| 3210 | surface = weston_surface_get_main_surface(focus); |
| 3211 | if (surface == NULL) |
| 3212 | return; |
| 3213 | |
| 3214 | shsurf = get_shell_surface(surface); |
| 3215 | if (shsurf == NULL || shsurf->type == SHELL_SURFACE_FULLSCREEN || |
| 3216 | shsurf->type == SHELL_SURFACE_MAXIMIZED) |
| 3217 | return; |
| 3218 | |
| 3219 | surface_touch_move(shsurf, (struct weston_seat *) seat); |
| 3220 | } |
| 3221 | |
| 3222 | static void |
Kristian Høgsberg | e314875 | 2013-05-06 23:19:49 -0400 | [diff] [blame] | 3223 | 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] | 3224 | { |
Kristian Høgsberg | 7ab139c | 2013-10-24 16:21:39 -0700 | [diff] [blame] | 3225 | struct weston_surface *focus = seat->pointer->focus->surface; |
Pekka Paalanen | 01388e2 | 2013-04-25 13:57:44 +0300 | [diff] [blame] | 3226 | struct weston_surface *surface; |
Kristian Høgsberg | 0793756 | 2011-04-12 17:25:42 -0400 | [diff] [blame] | 3227 | uint32_t edges = 0; |
| 3228 | int32_t x, y; |
Pekka Paalanen | 9d1613e | 2011-11-25 12:09:16 +0200 | [diff] [blame] | 3229 | struct shell_surface *shsurf; |
Kristian Høgsberg | d2abb83 | 2011-11-23 10:52:40 -0500 | [diff] [blame] | 3230 | |
Pekka Paalanen | 01388e2 | 2013-04-25 13:57:44 +0300 | [diff] [blame] | 3231 | surface = weston_surface_get_main_surface(focus); |
Benjamin Franzke | d0f79ab | 2011-11-22 12:43:52 +0100 | [diff] [blame] | 3232 | if (surface == NULL) |
| 3233 | return; |
Pekka Paalanen | 92a0dc4 | 2011-11-28 15:34:13 +0200 | [diff] [blame] | 3234 | |
Pekka Paalanen | 9d1613e | 2011-11-25 12:09:16 +0200 | [diff] [blame] | 3235 | shsurf = get_shell_surface(surface); |
Rafal Mielniczuk | 23c6759 | 2013-03-11 19:26:53 +0100 | [diff] [blame] | 3236 | if (!shsurf || shsurf->type == SHELL_SURFACE_FULLSCREEN || |
| 3237 | shsurf->type == SHELL_SURFACE_MAXIMIZED) |
Pekka Paalanen | 92a0dc4 | 2011-11-28 15:34:13 +0200 | [diff] [blame] | 3238 | return; |
| 3239 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 3240 | weston_view_from_global(shsurf->view, |
| 3241 | wl_fixed_to_int(seat->pointer->grab_x), |
| 3242 | wl_fixed_to_int(seat->pointer->grab_y), |
| 3243 | &x, &y); |
Kristian Høgsberg | 0793756 | 2011-04-12 17:25:42 -0400 | [diff] [blame] | 3244 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 3245 | if (x < shsurf->view->geometry.width / 3) |
Pekka Paalanen | 9d1613e | 2011-11-25 12:09:16 +0200 | [diff] [blame] | 3246 | edges |= WL_SHELL_SURFACE_RESIZE_LEFT; |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 3247 | else if (x < 2 * shsurf->view->geometry.width / 3) |
Kristian Høgsberg | 0793756 | 2011-04-12 17:25:42 -0400 | [diff] [blame] | 3248 | edges |= 0; |
| 3249 | else |
Pekka Paalanen | 9d1613e | 2011-11-25 12:09:16 +0200 | [diff] [blame] | 3250 | edges |= WL_SHELL_SURFACE_RESIZE_RIGHT; |
Kristian Høgsberg | 0793756 | 2011-04-12 17:25:42 -0400 | [diff] [blame] | 3251 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 3252 | if (y < shsurf->view->geometry.height / 3) |
Pekka Paalanen | 9d1613e | 2011-11-25 12:09:16 +0200 | [diff] [blame] | 3253 | edges |= WL_SHELL_SURFACE_RESIZE_TOP; |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 3254 | else if (y < 2 * shsurf->view->geometry.height / 3) |
Kristian Høgsberg | 0793756 | 2011-04-12 17:25:42 -0400 | [diff] [blame] | 3255 | edges |= 0; |
| 3256 | else |
Pekka Paalanen | 9d1613e | 2011-11-25 12:09:16 +0200 | [diff] [blame] | 3257 | edges |= WL_SHELL_SURFACE_RESIZE_BOTTOM; |
Kristian Høgsberg | 0793756 | 2011-04-12 17:25:42 -0400 | [diff] [blame] | 3258 | |
Kristian Høgsberg | c1693f2 | 2012-05-22 16:56:23 -0400 | [diff] [blame] | 3259 | surface_resize(shsurf, (struct weston_seat *) seat, edges); |
Kristian Høgsberg | 02ec0a5 | 2011-04-23 13:04:11 -0400 | [diff] [blame] | 3260 | } |
| 3261 | |
| 3262 | static void |
Kristian Høgsberg | e314875 | 2013-05-06 23:19:49 -0400 | [diff] [blame] | 3263 | 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] | 3264 | wl_fixed_t value, void *data) |
Scott Moreau | a3aa9c9 | 2012-03-22 11:01:03 -0600 | [diff] [blame] | 3265 | { |
Jonas Ådahl | b0b87ba | 2012-09-27 18:40:42 +0200 | [diff] [blame] | 3266 | float step = 0.005; |
Scott Moreau | a3aa9c9 | 2012-03-22 11:01:03 -0600 | [diff] [blame] | 3267 | struct shell_surface *shsurf; |
Kristian Høgsberg | 7ab139c | 2013-10-24 16:21:39 -0700 | [diff] [blame] | 3268 | struct weston_surface *focus = seat->pointer->focus->surface; |
Pekka Paalanen | 01388e2 | 2013-04-25 13:57:44 +0300 | [diff] [blame] | 3269 | struct weston_surface *surface; |
Scott Moreau | a3aa9c9 | 2012-03-22 11:01:03 -0600 | [diff] [blame] | 3270 | |
Pekka Paalanen | 01388e2 | 2013-04-25 13:57:44 +0300 | [diff] [blame] | 3271 | /* XXX: broken for windows containing sub-surfaces */ |
| 3272 | surface = weston_surface_get_main_surface(focus); |
Scott Moreau | a3aa9c9 | 2012-03-22 11:01:03 -0600 | [diff] [blame] | 3273 | if (surface == NULL) |
| 3274 | return; |
| 3275 | |
| 3276 | shsurf = get_shell_surface(surface); |
| 3277 | if (!shsurf) |
| 3278 | return; |
| 3279 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 3280 | shsurf->view->alpha -= wl_fixed_to_double(value) * step; |
Scott Moreau | a3aa9c9 | 2012-03-22 11:01:03 -0600 | [diff] [blame] | 3281 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 3282 | if (shsurf->view->alpha > 1.0) |
| 3283 | shsurf->view->alpha = 1.0; |
| 3284 | if (shsurf->view->alpha < step) |
| 3285 | shsurf->view->alpha = step; |
Scott Moreau | a3aa9c9 | 2012-03-22 11:01:03 -0600 | [diff] [blame] | 3286 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 3287 | weston_view_geometry_dirty(shsurf->view); |
Scott Moreau | a3aa9c9 | 2012-03-22 11:01:03 -0600 | [diff] [blame] | 3288 | weston_surface_damage(surface); |
| 3289 | } |
| 3290 | |
| 3291 | static void |
Kristian Høgsberg | e314875 | 2013-05-06 23:19:49 -0400 | [diff] [blame] | 3292 | 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] | 3293 | wl_fixed_t value) |
Scott Moreau | ccbf29d | 2012-02-22 14:21:41 -0700 | [diff] [blame] | 3294 | { |
Daniel Stone | 37816df | 2012-05-16 18:45:18 +0100 | [diff] [blame] | 3295 | struct weston_seat *ws = (struct weston_seat *) seat; |
| 3296 | struct weston_compositor *compositor = ws->compositor; |
Scott Moreau | ccbf29d | 2012-02-22 14:21:41 -0700 | [diff] [blame] | 3297 | struct weston_output *output; |
Scott Moreau | e660398 | 2012-06-11 13:07:51 -0600 | [diff] [blame] | 3298 | float increment; |
Scott Moreau | ccbf29d | 2012-02-22 14:21:41 -0700 | [diff] [blame] | 3299 | |
| 3300 | wl_list_for_each(output, &compositor->output_list, link) { |
| 3301 | if (pixman_region32_contains_point(&output->region, |
Daniel Stone | 37816df | 2012-05-16 18:45:18 +0100 | [diff] [blame] | 3302 | wl_fixed_to_double(seat->pointer->x), |
| 3303 | wl_fixed_to_double(seat->pointer->y), |
Daniel Stone | 103db7f | 2012-05-08 17:17:55 +0100 | [diff] [blame] | 3304 | NULL)) { |
Daniel Stone | 325fc2d | 2012-05-30 16:31:58 +0100 | [diff] [blame] | 3305 | if (key == KEY_PAGEUP) |
Kristian Høgsberg | 9b68af0 | 2012-05-22 12:55:18 -0400 | [diff] [blame] | 3306 | increment = output->zoom.increment; |
Daniel Stone | 325fc2d | 2012-05-30 16:31:58 +0100 | [diff] [blame] | 3307 | else if (key == KEY_PAGEDOWN) |
Kristian Høgsberg | 9b68af0 | 2012-05-22 12:55:18 -0400 | [diff] [blame] | 3308 | increment = -output->zoom.increment; |
| 3309 | else if (axis == WL_POINTER_AXIS_VERTICAL_SCROLL) |
Jonas Ådahl | b0b87ba | 2012-09-27 18:40:42 +0200 | [diff] [blame] | 3310 | /* For every pixel zoom 20th of a step */ |
Daniel Stone | 0c1e46e | 2012-05-30 16:31:59 +0100 | [diff] [blame] | 3311 | increment = output->zoom.increment * |
Jonas Ådahl | b0b87ba | 2012-09-27 18:40:42 +0200 | [diff] [blame] | 3312 | -wl_fixed_to_double(value) / 20.0; |
Kristian Høgsberg | 9b68af0 | 2012-05-22 12:55:18 -0400 | [diff] [blame] | 3313 | else |
| 3314 | increment = 0; |
| 3315 | |
Kristian Høgsberg | 9b68af0 | 2012-05-22 12:55:18 -0400 | [diff] [blame] | 3316 | output->zoom.level += increment; |
Scott Moreau | c6d7f60 | 2012-02-23 22:28:37 -0700 | [diff] [blame] | 3317 | |
Scott Moreau | e660398 | 2012-06-11 13:07:51 -0600 | [diff] [blame] | 3318 | if (output->zoom.level < 0.0) |
Scott Moreau | 850ca42 | 2012-05-21 15:21:25 -0600 | [diff] [blame] | 3319 | output->zoom.level = 0.0; |
Scott Moreau | e660398 | 2012-06-11 13:07:51 -0600 | [diff] [blame] | 3320 | else if (output->zoom.level > output->zoom.max_level) |
| 3321 | output->zoom.level = output->zoom.max_level; |
Ville Syrjälä | aa628d0 | 2012-11-16 11:48:47 +0200 | [diff] [blame] | 3322 | else if (!output->zoom.active) { |
Giulio Camuffo | 412b024 | 2013-11-14 23:42:51 +0100 | [diff] [blame] | 3323 | weston_output_activate_zoom(output); |
Kristian Høgsberg | 79af73e | 2012-08-03 15:45:23 -0400 | [diff] [blame] | 3324 | } |
Scott Moreau | ccbf29d | 2012-02-22 14:21:41 -0700 | [diff] [blame] | 3325 | |
Scott Moreau | e660398 | 2012-06-11 13:07:51 -0600 | [diff] [blame] | 3326 | output->zoom.spring_z.target = output->zoom.level; |
Scott Moreau | ccbf29d | 2012-02-22 14:21:41 -0700 | [diff] [blame] | 3327 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 3328 | weston_output_update_zoom(output); |
Scott Moreau | ccbf29d | 2012-02-22 14:21:41 -0700 | [diff] [blame] | 3329 | } |
| 3330 | } |
| 3331 | } |
| 3332 | |
Scott Moreau | ccbf29d | 2012-02-22 14:21:41 -0700 | [diff] [blame] | 3333 | static void |
Kristian Høgsberg | e314875 | 2013-05-06 23:19:49 -0400 | [diff] [blame] | 3334 | 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] | 3335 | wl_fixed_t value, void *data) |
Daniel Stone | 325fc2d | 2012-05-30 16:31:58 +0100 | [diff] [blame] | 3336 | { |
| 3337 | do_zoom(seat, time, 0, axis, value); |
| 3338 | } |
| 3339 | |
| 3340 | static void |
Kristian Høgsberg | e314875 | 2013-05-06 23:19:49 -0400 | [diff] [blame] | 3341 | 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] | 3342 | void *data) |
| 3343 | { |
| 3344 | do_zoom(seat, time, key, 0, 0); |
| 3345 | } |
| 3346 | |
| 3347 | static void |
Kristian Høgsberg | e314875 | 2013-05-06 23:19:49 -0400 | [diff] [blame] | 3348 | terminate_binding(struct weston_seat *seat, uint32_t time, uint32_t key, |
Daniel Stone | 325fc2d | 2012-05-30 16:31:58 +0100 | [diff] [blame] | 3349 | void *data) |
Kristian Høgsberg | e1a850e | 2011-12-19 15:18:05 -0500 | [diff] [blame] | 3350 | { |
Kristian Høgsberg | 8334bc1 | 2012-01-03 10:29:47 -0500 | [diff] [blame] | 3351 | struct weston_compositor *compositor = data; |
Kristian Høgsberg | e1a850e | 2011-12-19 15:18:05 -0500 | [diff] [blame] | 3352 | |
Daniel Stone | 325fc2d | 2012-05-30 16:31:58 +0100 | [diff] [blame] | 3353 | wl_display_terminate(compositor->wl_display); |
Kristian Høgsberg | e1a850e | 2011-12-19 15:18:05 -0500 | [diff] [blame] | 3354 | } |
| 3355 | |
| 3356 | static void |
Emilio Pozuelo Monfort | 03251b6 | 2013-11-19 11:37:16 +0100 | [diff] [blame] | 3357 | lower_fullscreen_layer(struct desktop_shell *shell); |
| 3358 | |
| 3359 | struct alt_tab { |
| 3360 | struct desktop_shell *shell; |
| 3361 | struct weston_keyboard_grab grab; |
| 3362 | |
| 3363 | struct wl_list *current; |
| 3364 | |
| 3365 | struct wl_list preview_list; |
| 3366 | }; |
| 3367 | |
| 3368 | struct alt_tab_preview { |
| 3369 | struct alt_tab *alt_tab; |
| 3370 | |
| 3371 | struct weston_view *view; |
| 3372 | struct weston_transform transform; |
| 3373 | |
| 3374 | struct wl_listener listener; |
| 3375 | |
| 3376 | struct wl_list link; |
| 3377 | }; |
| 3378 | |
| 3379 | static void |
| 3380 | alt_tab_next(struct alt_tab *alt_tab) |
| 3381 | { |
| 3382 | alt_tab->current = alt_tab->current->next; |
| 3383 | |
| 3384 | /* Make sure we're not pointing to the list header e.g. after |
| 3385 | * cycling through the whole list. */ |
| 3386 | if (alt_tab->current->next == alt_tab->preview_list.next) |
| 3387 | alt_tab->current = alt_tab->current->next; |
| 3388 | } |
| 3389 | |
| 3390 | static void |
| 3391 | alt_tab_destroy(struct alt_tab *alt_tab) |
| 3392 | { |
| 3393 | struct alt_tab_preview *preview, *next; |
| 3394 | struct weston_keyboard *keyboard = alt_tab->grab.keyboard; |
| 3395 | |
| 3396 | if (alt_tab->current && alt_tab->current != &alt_tab->preview_list) { |
| 3397 | preview = wl_container_of(alt_tab->current, preview, link); |
| 3398 | |
| 3399 | activate(alt_tab->shell, preview->view->surface, |
| 3400 | (struct weston_seat *) keyboard->seat); |
| 3401 | } |
| 3402 | |
| 3403 | wl_list_for_each_safe(preview, next, &alt_tab->preview_list, link) { |
| 3404 | wl_list_remove(&preview->link); |
| 3405 | wl_list_remove(&preview->listener.link); |
| 3406 | weston_view_destroy(preview->view); |
| 3407 | free(preview); |
| 3408 | } |
| 3409 | |
| 3410 | weston_keyboard_end_grab(keyboard); |
| 3411 | if (keyboard->input_method_resource) |
| 3412 | keyboard->grab = &keyboard->input_method_grab; |
| 3413 | |
| 3414 | free(alt_tab); |
| 3415 | } |
| 3416 | |
| 3417 | static void |
| 3418 | alt_tab_handle_surface_destroy(struct wl_listener *listener, void *data) |
| 3419 | { |
| 3420 | struct alt_tab_preview *preview = |
| 3421 | container_of(listener, struct alt_tab_preview, listener); |
| 3422 | struct alt_tab *alt_tab = preview->alt_tab; |
| 3423 | int advance = 0; |
| 3424 | |
| 3425 | /* If the preview that we're removing is the currently selected one, |
| 3426 | * we want to move to the next one. So we move to ->prev and then |
| 3427 | * call _next() after removing the preview. */ |
| 3428 | if (alt_tab->current == &preview->link) { |
| 3429 | alt_tab->current = alt_tab->current->prev; |
| 3430 | advance = 1; |
| 3431 | } |
| 3432 | |
| 3433 | wl_list_remove(&preview->listener.link); |
| 3434 | wl_list_remove(&preview->link); |
| 3435 | |
| 3436 | free(preview); |
| 3437 | |
| 3438 | if (advance) |
| 3439 | alt_tab_next(alt_tab); |
| 3440 | |
| 3441 | /* If the last preview goes away, stop the alt-tab */ |
| 3442 | if (wl_list_empty(alt_tab->current)) |
| 3443 | alt_tab_destroy(alt_tab); |
| 3444 | } |
| 3445 | |
| 3446 | static void |
| 3447 | alt_tab_key(struct weston_keyboard_grab *grab, |
| 3448 | uint32_t time, uint32_t key, uint32_t state_w) |
| 3449 | { |
| 3450 | struct alt_tab *alt_tab = container_of(grab, struct alt_tab, grab); |
| 3451 | enum wl_keyboard_key_state state = state_w; |
| 3452 | |
| 3453 | if (key == KEY_TAB && state == WL_KEYBOARD_KEY_STATE_PRESSED) |
| 3454 | alt_tab_next(alt_tab); |
| 3455 | } |
| 3456 | |
| 3457 | static void |
| 3458 | alt_tab_modifier(struct weston_keyboard_grab *grab, uint32_t serial, |
| 3459 | uint32_t mods_depressed, uint32_t mods_latched, |
| 3460 | uint32_t mods_locked, uint32_t group) |
| 3461 | { |
| 3462 | struct alt_tab *alt_tab = container_of(grab, struct alt_tab, grab); |
| 3463 | struct weston_seat *seat = (struct weston_seat *) grab->keyboard->seat; |
| 3464 | |
| 3465 | if ((seat->modifier_state & MODIFIER_ALT) == 0) |
| 3466 | alt_tab_destroy(alt_tab); |
| 3467 | } |
| 3468 | |
| 3469 | static void |
| 3470 | alt_tab_cancel(struct weston_keyboard_grab *grab) |
| 3471 | { |
| 3472 | struct alt_tab *alt_tab = container_of(grab, struct alt_tab, grab); |
| 3473 | |
| 3474 | alt_tab_destroy(alt_tab); |
| 3475 | } |
| 3476 | |
| 3477 | static const struct weston_keyboard_grab_interface alt_tab_grab = { |
| 3478 | alt_tab_key, |
| 3479 | alt_tab_modifier, |
| 3480 | alt_tab_cancel, |
| 3481 | }; |
| 3482 | |
| 3483 | static int |
| 3484 | view_for_alt_tab(struct weston_view *view) |
| 3485 | { |
| 3486 | if (!get_shell_surface(view->surface)) |
| 3487 | return 0; |
| 3488 | |
| 3489 | if (get_shell_surface_type(view->surface) == SHELL_SURFACE_TRANSIENT) |
| 3490 | return 0; |
| 3491 | |
| 3492 | if (view != get_default_view(view->surface)) |
| 3493 | return 0; |
| 3494 | |
| 3495 | return 1; |
| 3496 | } |
| 3497 | |
| 3498 | static void |
| 3499 | alt_tab_binding(struct weston_seat *seat, uint32_t time, uint32_t key, |
| 3500 | void *data) |
| 3501 | { |
| 3502 | struct alt_tab *alt_tab; |
| 3503 | struct desktop_shell *shell = data; |
| 3504 | struct weston_output *output = get_default_output(shell->compositor); |
| 3505 | struct workspace *ws; |
| 3506 | struct weston_view *view; |
| 3507 | int num_surfaces = 0; |
| 3508 | int x, y, side, margin; |
| 3509 | |
| 3510 | wl_list_for_each(view, &shell->compositor->view_list, link) { |
| 3511 | |
| 3512 | if (view_for_alt_tab(view)) |
| 3513 | num_surfaces++; |
| 3514 | } |
| 3515 | |
| 3516 | if (!num_surfaces) |
| 3517 | return; |
| 3518 | |
| 3519 | alt_tab = malloc(sizeof *alt_tab); |
| 3520 | if (!alt_tab) |
| 3521 | return; |
| 3522 | |
| 3523 | alt_tab->shell = shell; |
| 3524 | wl_list_init(&alt_tab->preview_list); |
| 3525 | alt_tab->current = &alt_tab->preview_list; |
| 3526 | |
| 3527 | restore_all_output_modes(shell->compositor); |
| 3528 | lower_fullscreen_layer(alt_tab->shell); |
| 3529 | |
| 3530 | alt_tab->grab.interface = &alt_tab_grab; |
| 3531 | weston_keyboard_start_grab(seat->keyboard, &alt_tab->grab); |
| 3532 | weston_keyboard_set_focus(seat->keyboard, NULL); |
| 3533 | |
| 3534 | ws = get_current_workspace(shell); |
| 3535 | |
| 3536 | /* FIXME: add some visual candy e.g. prelight the selected view |
| 3537 | * and/or add a black surrounding background à la gnome-shell */ |
| 3538 | |
| 3539 | /* Determine the size for each preview */ |
| 3540 | side = output->width / num_surfaces; |
| 3541 | if (side > 200) |
| 3542 | side = 200; |
| 3543 | margin = side / 4; |
| 3544 | side -= margin; |
| 3545 | |
| 3546 | x = margin; |
| 3547 | y = (output->height - side) / 2; |
| 3548 | |
| 3549 | /* Create a view for each surface */ |
| 3550 | wl_list_for_each(view, &shell->compositor->view_list, link) { |
| 3551 | struct alt_tab_preview *preview; |
| 3552 | struct weston_view *v; |
| 3553 | float scale; |
| 3554 | |
| 3555 | if (!view_for_alt_tab(view)) |
| 3556 | continue; |
| 3557 | |
| 3558 | preview = malloc(sizeof *preview); |
| 3559 | if (!preview) { |
| 3560 | alt_tab_destroy(alt_tab); |
| 3561 | return; |
| 3562 | } |
| 3563 | |
| 3564 | preview->alt_tab = alt_tab; |
| 3565 | |
| 3566 | preview->view = v = weston_view_create(view->surface); |
| 3567 | v->output = view->output; |
| 3568 | weston_view_restack(v, &ws->layer.view_list); |
| 3569 | weston_view_configure(v, x, y, view->geometry.width, view->geometry.height); |
| 3570 | |
| 3571 | preview->listener.notify = alt_tab_handle_surface_destroy; |
| 3572 | wl_signal_add(&v->destroy_signal, &preview->listener); |
| 3573 | |
| 3574 | if (view->geometry.width > view->geometry.height) |
| 3575 | scale = side / (float) view->geometry.width; |
| 3576 | else |
| 3577 | scale = side / (float) view->geometry.height; |
| 3578 | |
| 3579 | wl_list_insert(&v->geometry.transformation_list, |
| 3580 | &preview->transform.link); |
| 3581 | weston_matrix_init(&preview->transform.matrix); |
| 3582 | weston_matrix_scale(&preview->transform.matrix, |
| 3583 | scale, scale, 1.0f); |
| 3584 | |
| 3585 | weston_view_geometry_dirty(v); |
| 3586 | weston_compositor_schedule_repaint(v->surface->compositor); |
| 3587 | |
| 3588 | /* Insert at the end of the list */ |
| 3589 | wl_list_insert(alt_tab->preview_list.prev, &preview->link); |
| 3590 | |
| 3591 | x += side + margin; |
| 3592 | } |
| 3593 | |
| 3594 | /* Start at the second preview so a simple <alt>tab changes window. |
| 3595 | * We set `current' to the first preview and not the second because |
| 3596 | * we're going to receive a key press callback for the initial |
| 3597 | * <alt>tab which will make `current' point to the second element. */ |
| 3598 | alt_tab_next(alt_tab); |
| 3599 | } |
| 3600 | |
| 3601 | static void |
Giulio Camuffo | 1959ab8 | 2013-11-14 23:42:52 +0100 | [diff] [blame] | 3602 | rotate_grab_motion(struct weston_pointer_grab *grab, uint32_t time, |
| 3603 | wl_fixed_t x, wl_fixed_t y) |
Pekka Paalanen | 460099f | 2012-01-20 16:48:25 +0200 | [diff] [blame] | 3604 | { |
| 3605 | struct rotate_grab *rotate = |
Ander Conselvan de Oliveira | fe0444a | 2012-04-04 17:48:05 +0300 | [diff] [blame] | 3606 | container_of(grab, struct rotate_grab, base.grab); |
Kristian Høgsberg | 02bbabb | 2013-05-06 22:15:05 -0400 | [diff] [blame] | 3607 | struct weston_pointer *pointer = grab->pointer; |
Ander Conselvan de Oliveira | fe0444a | 2012-04-04 17:48:05 +0300 | [diff] [blame] | 3608 | struct shell_surface *shsurf = rotate->base.shsurf; |
John Kåre Alsaker | 490d02a | 2012-09-30 02:57:21 +0200 | [diff] [blame] | 3609 | float cx, cy, dx, dy, cposx, cposy, dposx, dposy, r; |
Ander Conselvan de Oliveira | fe0444a | 2012-04-04 17:48:05 +0300 | [diff] [blame] | 3610 | |
Giulio Camuffo | 1959ab8 | 2013-11-14 23:42:52 +0100 | [diff] [blame] | 3611 | weston_pointer_move(pointer, x, y); |
| 3612 | |
Ander Conselvan de Oliveira | fe0444a | 2012-04-04 17:48:05 +0300 | [diff] [blame] | 3613 | if (!shsurf) |
| 3614 | return; |
| 3615 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 3616 | cx = 0.5f * shsurf->view->geometry.width; |
| 3617 | cy = 0.5f * shsurf->view->geometry.height; |
Pekka Paalanen | 460099f | 2012-01-20 16:48:25 +0200 | [diff] [blame] | 3618 | |
Daniel Stone | 37816df | 2012-05-16 18:45:18 +0100 | [diff] [blame] | 3619 | dx = wl_fixed_to_double(pointer->x) - rotate->center.x; |
| 3620 | dy = wl_fixed_to_double(pointer->y) - rotate->center.y; |
Pekka Paalanen | 460099f | 2012-01-20 16:48:25 +0200 | [diff] [blame] | 3621 | r = sqrtf(dx * dx + dy * dy); |
| 3622 | |
Ander Conselvan de Oliveira | fe0444a | 2012-04-04 17:48:05 +0300 | [diff] [blame] | 3623 | wl_list_remove(&shsurf->rotation.transform.link); |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 3624 | weston_view_geometry_dirty(shsurf->view); |
Pekka Paalanen | 460099f | 2012-01-20 16:48:25 +0200 | [diff] [blame] | 3625 | |
| 3626 | if (r > 20.0f) { |
Pekka Paalanen | 460099f | 2012-01-20 16:48:25 +0200 | [diff] [blame] | 3627 | struct weston_matrix *matrix = |
Ander Conselvan de Oliveira | fe0444a | 2012-04-04 17:48:05 +0300 | [diff] [blame] | 3628 | &shsurf->rotation.transform.matrix; |
Pekka Paalanen | 460099f | 2012-01-20 16:48:25 +0200 | [diff] [blame] | 3629 | |
Kristian Høgsberg | 765e27b | 2012-01-27 13:36:13 -0500 | [diff] [blame] | 3630 | weston_matrix_init(&rotate->rotation); |
Vasily Khoruzhick | 1bbf372 | 2013-01-28 22:40:28 +0300 | [diff] [blame] | 3631 | weston_matrix_rotate_xy(&rotate->rotation, dx / r, dy / r); |
Pekka Paalanen | 460099f | 2012-01-20 16:48:25 +0200 | [diff] [blame] | 3632 | |
| 3633 | weston_matrix_init(matrix); |
Pekka Paalanen | 7b3bd3d | 2012-01-30 14:16:34 +0200 | [diff] [blame] | 3634 | weston_matrix_translate(matrix, -cx, -cy, 0.0f); |
Ander Conselvan de Oliveira | fe0444a | 2012-04-04 17:48:05 +0300 | [diff] [blame] | 3635 | weston_matrix_multiply(matrix, &shsurf->rotation.rotation); |
Kristian Høgsberg | 765e27b | 2012-01-27 13:36:13 -0500 | [diff] [blame] | 3636 | weston_matrix_multiply(matrix, &rotate->rotation); |
Pekka Paalanen | 7b3bd3d | 2012-01-30 14:16:34 +0200 | [diff] [blame] | 3637 | weston_matrix_translate(matrix, cx, cy, 0.0f); |
Pekka Paalanen | 460099f | 2012-01-20 16:48:25 +0200 | [diff] [blame] | 3638 | |
Pekka Paalanen | bc0b7e7 | 2012-01-24 09:53:37 +0200 | [diff] [blame] | 3639 | wl_list_insert( |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 3640 | &shsurf->view->geometry.transformation_list, |
Ander Conselvan de Oliveira | fe0444a | 2012-04-04 17:48:05 +0300 | [diff] [blame] | 3641 | &shsurf->rotation.transform.link); |
Pekka Paalanen | 460099f | 2012-01-20 16:48:25 +0200 | [diff] [blame] | 3642 | } else { |
Ander Conselvan de Oliveira | fe0444a | 2012-04-04 17:48:05 +0300 | [diff] [blame] | 3643 | wl_list_init(&shsurf->rotation.transform.link); |
| 3644 | weston_matrix_init(&shsurf->rotation.rotation); |
Kristian Høgsberg | 765e27b | 2012-01-27 13:36:13 -0500 | [diff] [blame] | 3645 | weston_matrix_init(&rotate->rotation); |
Pekka Paalanen | 460099f | 2012-01-20 16:48:25 +0200 | [diff] [blame] | 3646 | } |
Pekka Paalanen | b45ac5e | 2012-02-09 15:58:44 +0200 | [diff] [blame] | 3647 | |
Rafal Mielniczuk | 2d7ab82 | 2012-03-22 22:22:04 +0100 | [diff] [blame] | 3648 | /* We need to adjust the position of the surface |
| 3649 | * in case it was resized in a rotated state before */ |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 3650 | cposx = shsurf->view->geometry.x + cx; |
| 3651 | cposy = shsurf->view->geometry.y + cy; |
Rafal Mielniczuk | 2d7ab82 | 2012-03-22 22:22:04 +0100 | [diff] [blame] | 3652 | dposx = rotate->center.x - cposx; |
| 3653 | dposy = rotate->center.y - cposy; |
| 3654 | if (dposx != 0.0f || dposy != 0.0f) { |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 3655 | weston_view_set_position(shsurf->view, |
| 3656 | shsurf->view->geometry.x + dposx, |
| 3657 | shsurf->view->geometry.y + dposy); |
Rafal Mielniczuk | 2d7ab82 | 2012-03-22 22:22:04 +0100 | [diff] [blame] | 3658 | } |
| 3659 | |
Pekka Paalanen | b45ac5e | 2012-02-09 15:58:44 +0200 | [diff] [blame] | 3660 | /* Repaint implies weston_surface_update_transform(), which |
| 3661 | * lazily applies the damage due to rotation update. |
| 3662 | */ |
Ander Conselvan de Oliveira | fe0444a | 2012-04-04 17:48:05 +0300 | [diff] [blame] | 3663 | weston_compositor_schedule_repaint(shsurf->surface->compositor); |
Pekka Paalanen | 460099f | 2012-01-20 16:48:25 +0200 | [diff] [blame] | 3664 | } |
| 3665 | |
| 3666 | static void |
Kristian Høgsberg | 02bbabb | 2013-05-06 22:15:05 -0400 | [diff] [blame] | 3667 | rotate_grab_button(struct weston_pointer_grab *grab, |
| 3668 | uint32_t time, uint32_t button, uint32_t state_w) |
Pekka Paalanen | 460099f | 2012-01-20 16:48:25 +0200 | [diff] [blame] | 3669 | { |
| 3670 | struct rotate_grab *rotate = |
Ander Conselvan de Oliveira | fe0444a | 2012-04-04 17:48:05 +0300 | [diff] [blame] | 3671 | container_of(grab, struct rotate_grab, base.grab); |
Kristian Høgsberg | 02bbabb | 2013-05-06 22:15:05 -0400 | [diff] [blame] | 3672 | struct weston_pointer *pointer = grab->pointer; |
Ander Conselvan de Oliveira | fe0444a | 2012-04-04 17:48:05 +0300 | [diff] [blame] | 3673 | struct shell_surface *shsurf = rotate->base.shsurf; |
Daniel Stone | 4dbadb1 | 2012-05-30 16:31:51 +0100 | [diff] [blame] | 3674 | enum wl_pointer_button_state state = state_w; |
Pekka Paalanen | 460099f | 2012-01-20 16:48:25 +0200 | [diff] [blame] | 3675 | |
Daniel Stone | 4dbadb1 | 2012-05-30 16:31:51 +0100 | [diff] [blame] | 3676 | if (pointer->button_count == 0 && |
| 3677 | state == WL_POINTER_BUTTON_STATE_RELEASED) { |
Ander Conselvan de Oliveira | fe0444a | 2012-04-04 17:48:05 +0300 | [diff] [blame] | 3678 | if (shsurf) |
| 3679 | weston_matrix_multiply(&shsurf->rotation.rotation, |
| 3680 | &rotate->rotation); |
Ander Conselvan de Oliveira | b9d2a0f | 2012-06-28 18:08:05 +0300 | [diff] [blame] | 3681 | shell_grab_end(&rotate->base); |
Pekka Paalanen | 460099f | 2012-01-20 16:48:25 +0200 | [diff] [blame] | 3682 | free(rotate); |
| 3683 | } |
| 3684 | } |
| 3685 | |
Jonas Ådahl | 1ea343e | 2013-10-25 23:18:05 +0200 | [diff] [blame] | 3686 | static void |
| 3687 | rotate_grab_cancel(struct weston_pointer_grab *grab) |
| 3688 | { |
| 3689 | struct rotate_grab *rotate = |
| 3690 | container_of(grab, struct rotate_grab, base.grab); |
| 3691 | |
| 3692 | shell_grab_end(&rotate->base); |
| 3693 | free(rotate); |
| 3694 | } |
| 3695 | |
Kristian Høgsberg | 02bbabb | 2013-05-06 22:15:05 -0400 | [diff] [blame] | 3696 | static const struct weston_pointer_grab_interface rotate_grab_interface = { |
Pekka Paalanen | 460099f | 2012-01-20 16:48:25 +0200 | [diff] [blame] | 3697 | noop_grab_focus, |
| 3698 | rotate_grab_motion, |
| 3699 | rotate_grab_button, |
Jonas Ådahl | 1ea343e | 2013-10-25 23:18:05 +0200 | [diff] [blame] | 3700 | rotate_grab_cancel, |
Pekka Paalanen | 460099f | 2012-01-20 16:48:25 +0200 | [diff] [blame] | 3701 | }; |
| 3702 | |
| 3703 | static void |
Kristian Høgsberg | e314875 | 2013-05-06 23:19:49 -0400 | [diff] [blame] | 3704 | surface_rotate(struct shell_surface *surface, struct weston_seat *seat) |
Pekka Paalanen | 460099f | 2012-01-20 16:48:25 +0200 | [diff] [blame] | 3705 | { |
Pekka Paalanen | 460099f | 2012-01-20 16:48:25 +0200 | [diff] [blame] | 3706 | struct rotate_grab *rotate; |
John Kåre Alsaker | 490d02a | 2012-09-30 02:57:21 +0200 | [diff] [blame] | 3707 | float dx, dy; |
| 3708 | float r; |
Pekka Paalanen | 460099f | 2012-01-20 16:48:25 +0200 | [diff] [blame] | 3709 | |
Pekka Paalanen | 460099f | 2012-01-20 16:48:25 +0200 | [diff] [blame] | 3710 | rotate = malloc(sizeof *rotate); |
| 3711 | if (!rotate) |
| 3712 | return; |
| 3713 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 3714 | weston_view_to_global_float(surface->view, |
| 3715 | surface->view->geometry.width * 0.5f, |
| 3716 | surface->view->geometry.height * 0.5f, |
| 3717 | &rotate->center.x, &rotate->center.y); |
Pekka Paalanen | 460099f | 2012-01-20 16:48:25 +0200 | [diff] [blame] | 3718 | |
Daniel Stone | 37816df | 2012-05-16 18:45:18 +0100 | [diff] [blame] | 3719 | dx = wl_fixed_to_double(seat->pointer->x) - rotate->center.x; |
| 3720 | dy = wl_fixed_to_double(seat->pointer->y) - rotate->center.y; |
Kristian Høgsberg | 765e27b | 2012-01-27 13:36:13 -0500 | [diff] [blame] | 3721 | r = sqrtf(dx * dx + dy * dy); |
| 3722 | if (r > 20.0f) { |
| 3723 | struct weston_matrix inverse; |
| 3724 | |
| 3725 | weston_matrix_init(&inverse); |
Vasily Khoruzhick | 1bbf372 | 2013-01-28 22:40:28 +0300 | [diff] [blame] | 3726 | weston_matrix_rotate_xy(&inverse, dx / r, -dy / r); |
Kristian Høgsberg | 765e27b | 2012-01-27 13:36:13 -0500 | [diff] [blame] | 3727 | weston_matrix_multiply(&surface->rotation.rotation, &inverse); |
Rafal Mielniczuk | 2d7ab82 | 2012-03-22 22:22:04 +0100 | [diff] [blame] | 3728 | |
| 3729 | weston_matrix_init(&rotate->rotation); |
Vasily Khoruzhick | 1bbf372 | 2013-01-28 22:40:28 +0300 | [diff] [blame] | 3730 | weston_matrix_rotate_xy(&rotate->rotation, dx / r, dy / r); |
Kristian Høgsberg | 765e27b | 2012-01-27 13:36:13 -0500 | [diff] [blame] | 3731 | } else { |
| 3732 | weston_matrix_init(&surface->rotation.rotation); |
| 3733 | weston_matrix_init(&rotate->rotation); |
| 3734 | } |
| 3735 | |
Ander Conselvan de Oliveira | b9d2a0f | 2012-06-28 18:08:05 +0300 | [diff] [blame] | 3736 | shell_grab_start(&rotate->base, &rotate_grab_interface, surface, |
| 3737 | seat->pointer, DESKTOP_SHELL_CURSOR_ARROW); |
Pekka Paalanen | 460099f | 2012-01-20 16:48:25 +0200 | [diff] [blame] | 3738 | } |
| 3739 | |
| 3740 | static void |
Kristian Høgsberg | e314875 | 2013-05-06 23:19:49 -0400 | [diff] [blame] | 3741 | 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] | 3742 | void *data) |
| 3743 | { |
Kristian Høgsberg | 7ab139c | 2013-10-24 16:21:39 -0700 | [diff] [blame] | 3744 | struct weston_surface *focus = seat->pointer->focus->surface; |
Pekka Paalanen | 01388e2 | 2013-04-25 13:57:44 +0300 | [diff] [blame] | 3745 | struct weston_surface *base_surface; |
Kristian Høgsberg | 0c36903 | 2013-02-14 21:31:44 -0500 | [diff] [blame] | 3746 | struct shell_surface *surface; |
| 3747 | |
Pekka Paalanen | 01388e2 | 2013-04-25 13:57:44 +0300 | [diff] [blame] | 3748 | base_surface = weston_surface_get_main_surface(focus); |
Kristian Høgsberg | 0c36903 | 2013-02-14 21:31:44 -0500 | [diff] [blame] | 3749 | if (base_surface == NULL) |
| 3750 | return; |
| 3751 | |
| 3752 | surface = get_shell_surface(base_surface); |
Rafal Mielniczuk | 23c6759 | 2013-03-11 19:26:53 +0100 | [diff] [blame] | 3753 | if (!surface || surface->type == SHELL_SURFACE_FULLSCREEN || |
| 3754 | surface->type == SHELL_SURFACE_MAXIMIZED) |
Kristian Høgsberg | 0c36903 | 2013-02-14 21:31:44 -0500 | [diff] [blame] | 3755 | return; |
| 3756 | |
| 3757 | surface_rotate(surface, seat); |
| 3758 | } |
| 3759 | |
| 3760 | static void |
Kristian Høgsberg | b0d8e77 | 2012-06-18 16:34:58 -0400 | [diff] [blame] | 3761 | lower_fullscreen_layer(struct desktop_shell *shell) |
| 3762 | { |
| 3763 | struct workspace *ws; |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 3764 | struct weston_view *view, *prev; |
Kristian Høgsberg | b0d8e77 | 2012-06-18 16:34:58 -0400 | [diff] [blame] | 3765 | |
| 3766 | ws = get_current_workspace(shell); |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 3767 | wl_list_for_each_reverse_safe(view, prev, |
| 3768 | &shell->fullscreen_layer.view_list, |
Kristian Høgsberg | b0d8e77 | 2012-06-18 16:34:58 -0400 | [diff] [blame] | 3769 | layer_link) |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 3770 | weston_view_restack(view, &ws->layer.view_list); |
Kristian Høgsberg | b0d8e77 | 2012-06-18 16:34:58 -0400 | [diff] [blame] | 3771 | } |
| 3772 | |
| 3773 | static void |
Tiago Vignatti | be14326 | 2012-04-16 17:31:41 +0300 | [diff] [blame] | 3774 | activate(struct desktop_shell *shell, struct weston_surface *es, |
Daniel Stone | 37816df | 2012-05-16 18:45:18 +0100 | [diff] [blame] | 3775 | struct weston_seat *seat) |
Kristian Høgsberg | 7584062 | 2011-09-06 13:48:16 -0400 | [diff] [blame] | 3776 | { |
Pekka Paalanen | 01388e2 | 2013-04-25 13:57:44 +0300 | [diff] [blame] | 3777 | struct weston_surface *main_surface; |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 3778 | struct weston_view *main_view; |
Kristian Høgsberg | 2f5faff | 2012-07-31 16:36:34 -0400 | [diff] [blame] | 3779 | struct focus_state *state; |
Jonas Ådahl | 8538b22 | 2012-08-29 22:13:03 +0200 | [diff] [blame] | 3780 | struct workspace *ws; |
Louis-Francis Ratté-Boulianne | b482dbd | 2013-11-19 11:37:11 +0100 | [diff] [blame] | 3781 | struct weston_surface *old_es; |
Kristian Høgsberg | 7584062 | 2011-09-06 13:48:16 -0400 | [diff] [blame] | 3782 | |
Pekka Paalanen | 01388e2 | 2013-04-25 13:57:44 +0300 | [diff] [blame] | 3783 | main_surface = weston_surface_get_main_surface(es); |
| 3784 | |
Daniel Stone | 37816df | 2012-05-16 18:45:18 +0100 | [diff] [blame] | 3785 | weston_surface_activate(es, seat); |
Kristian Høgsberg | 7584062 | 2011-09-06 13:48:16 -0400 | [diff] [blame] | 3786 | |
Jonas Ådahl | 8538b22 | 2012-08-29 22:13:03 +0200 | [diff] [blame] | 3787 | state = ensure_focus_state(shell, seat); |
| 3788 | if (state == NULL) |
| 3789 | return; |
Kristian Høgsberg | 2f5faff | 2012-07-31 16:36:34 -0400 | [diff] [blame] | 3790 | |
Louis-Francis Ratté-Boulianne | b482dbd | 2013-11-19 11:37:11 +0100 | [diff] [blame] | 3791 | old_es = state->keyboard_focus; |
Kristian Høgsberg | 2f5faff | 2012-07-31 16:36:34 -0400 | [diff] [blame] | 3792 | state->keyboard_focus = es; |
| 3793 | wl_list_remove(&state->surface_destroy_listener.link); |
Jason Ekstrand | 26ed73c | 2013-06-06 22:34:41 -0500 | [diff] [blame] | 3794 | wl_signal_add(&es->destroy_signal, &state->surface_destroy_listener); |
Kristian Høgsberg | 2f5faff | 2012-07-31 16:36:34 -0400 | [diff] [blame] | 3795 | |
Pekka Paalanen | 01388e2 | 2013-04-25 13:57:44 +0300 | [diff] [blame] | 3796 | switch (get_shell_surface_type(main_surface)) { |
Alex Wu | 4539b08 | 2012-03-01 12:57:46 +0800 | [diff] [blame] | 3797 | case SHELL_SURFACE_FULLSCREEN: |
| 3798 | /* should on top of panels */ |
Pekka Paalanen | 01388e2 | 2013-04-25 13:57:44 +0300 | [diff] [blame] | 3799 | shell_stack_fullscreen(get_shell_surface(main_surface)); |
| 3800 | shell_configure_fullscreen(get_shell_surface(main_surface)); |
Louis-Francis Ratté-Boulianne | b482dbd | 2013-11-19 11:37:11 +0100 | [diff] [blame] | 3801 | return; |
Pekka Paalanen | 57da4a8 | 2011-11-23 16:42:16 +0200 | [diff] [blame] | 3802 | default: |
Alexander Larsson | f82b6ca | 2013-05-28 16:23:39 +0200 | [diff] [blame] | 3803 | restore_all_output_modes(shell->compositor); |
Jonas Ådahl | e3cddce | 2012-06-13 00:01:22 +0200 | [diff] [blame] | 3804 | ws = get_current_workspace(shell); |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 3805 | main_view = get_default_view(main_surface); |
| 3806 | if (main_view) |
| 3807 | weston_view_restack(main_view, &ws->layer.view_list); |
Kristian Høgsberg | 3be2ce9 | 2012-02-29 12:42:35 -0500 | [diff] [blame] | 3808 | break; |
Kristian Høgsberg | 7584062 | 2011-09-06 13:48:16 -0400 | [diff] [blame] | 3809 | } |
Louis-Francis Ratté-Boulianne | b482dbd | 2013-11-19 11:37:11 +0100 | [diff] [blame] | 3810 | |
| 3811 | if (shell->focus_animation_type != ANIMATION_NONE) |
| 3812 | animate_focus_change(shell, ws, get_default_view(old_es), get_default_view(es)); |
Kristian Høgsberg | 7584062 | 2011-09-06 13:48:16 -0400 | [diff] [blame] | 3813 | } |
| 3814 | |
Alex Wu | 2185843 | 2012-04-01 20:13:08 +0800 | [diff] [blame] | 3815 | /* no-op func for checking black surface */ |
| 3816 | static void |
Giulio Camuffo | 184df50 | 2013-02-21 11:29:21 +0100 | [diff] [blame] | 3817 | 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] | 3818 | { |
| 3819 | } |
| 3820 | |
Quentin Glidic | c0d79ce | 2013-01-29 14:16:13 +0100 | [diff] [blame] | 3821 | static bool |
Alex Wu | 2185843 | 2012-04-01 20:13:08 +0800 | [diff] [blame] | 3822 | is_black_surface (struct weston_surface *es, struct weston_surface **fs_surface) |
| 3823 | { |
| 3824 | if (es->configure == black_surface_configure) { |
| 3825 | if (fs_surface) |
Giulio Camuffo | 7fe01b1 | 2013-03-28 18:02:42 +0100 | [diff] [blame] | 3826 | *fs_surface = (struct weston_surface *)es->configure_private; |
Alex Wu | 2185843 | 2012-04-01 20:13:08 +0800 | [diff] [blame] | 3827 | return true; |
| 3828 | } |
| 3829 | return false; |
| 3830 | } |
| 3831 | |
Kristian Høgsberg | 7584062 | 2011-09-06 13:48:16 -0400 | [diff] [blame] | 3832 | static void |
Neil Roberts | a28c693 | 2013-10-03 16:43:04 +0100 | [diff] [blame] | 3833 | activate_binding(struct weston_seat *seat, |
| 3834 | struct desktop_shell *shell, |
| 3835 | struct weston_surface *focus) |
Kristian Høgsberg | e1a850e | 2011-12-19 15:18:05 -0500 | [diff] [blame] | 3836 | { |
Pekka Paalanen | 01388e2 | 2013-04-25 13:57:44 +0300 | [diff] [blame] | 3837 | struct weston_surface *main_surface; |
Kristian Høgsberg | e1a850e | 2011-12-19 15:18:05 -0500 | [diff] [blame] | 3838 | |
Alex Wu | 9c35e6b | 2012-03-05 14:13:13 +0800 | [diff] [blame] | 3839 | if (!focus) |
| 3840 | return; |
| 3841 | |
Pekka Paalanen | 01388e2 | 2013-04-25 13:57:44 +0300 | [diff] [blame] | 3842 | if (is_black_surface(focus, &main_surface)) |
| 3843 | focus = main_surface; |
Alex Wu | 4539b08 | 2012-03-01 12:57:46 +0800 | [diff] [blame] | 3844 | |
Pekka Paalanen | 01388e2 | 2013-04-25 13:57:44 +0300 | [diff] [blame] | 3845 | main_surface = weston_surface_get_main_surface(focus); |
| 3846 | if (get_shell_surface_type(main_surface) == SHELL_SURFACE_NONE) |
Kristian Høgsberg | 0636ac3 | 2012-06-27 10:22:15 -0400 | [diff] [blame] | 3847 | return; |
Kristian Høgsberg | 85b2e4b | 2012-06-21 16:49:42 -0400 | [diff] [blame] | 3848 | |
Neil Roberts | a28c693 | 2013-10-03 16:43:04 +0100 | [diff] [blame] | 3849 | activate(shell, focus, seat); |
| 3850 | } |
| 3851 | |
| 3852 | static void |
| 3853 | click_to_activate_binding(struct weston_seat *seat, uint32_t time, uint32_t button, |
| 3854 | void *data) |
| 3855 | { |
| 3856 | if (seat->pointer->grab != &seat->pointer->default_grab) |
| 3857 | return; |
| 3858 | |
Kristian Høgsberg | 7ab139c | 2013-10-24 16:21:39 -0700 | [diff] [blame] | 3859 | activate_binding(seat, data, seat->pointer->focus->surface); |
Neil Roberts | a28c693 | 2013-10-03 16:43:04 +0100 | [diff] [blame] | 3860 | } |
| 3861 | |
| 3862 | static void |
| 3863 | touch_to_activate_binding(struct weston_seat *seat, uint32_t time, void *data) |
| 3864 | { |
| 3865 | if (seat->touch->grab != &seat->touch->default_grab) |
| 3866 | return; |
| 3867 | |
Kristian Høgsberg | 7ab139c | 2013-10-24 16:21:39 -0700 | [diff] [blame] | 3868 | activate_binding(seat, data, seat->touch->focus->surface); |
Kristian Høgsberg | e1a850e | 2011-12-19 15:18:05 -0500 | [diff] [blame] | 3869 | } |
| 3870 | |
| 3871 | static void |
Ander Conselvan de Oliveira | 19d10ef | 2013-02-21 18:35:20 +0200 | [diff] [blame] | 3872 | lock(struct desktop_shell *shell) |
Kristian Høgsberg | 02ec0a5 | 2011-04-23 13:04:11 -0400 | [diff] [blame] | 3873 | { |
Kristian Høgsberg | 4476aaf | 2012-06-25 14:03:13 -0400 | [diff] [blame] | 3874 | struct workspace *ws = get_current_workspace(shell); |
Pekka Paalanen | f0fc70d | 2011-11-15 13:34:54 +0200 | [diff] [blame] | 3875 | |
Tiago Vignatti | 8e53c7f | 2012-02-29 19:53:50 +0200 | [diff] [blame] | 3876 | if (shell->locked) { |
Ander Conselvan de Oliveira | 87524b6 | 2013-02-21 18:35:22 +0200 | [diff] [blame] | 3877 | weston_compositor_sleep(shell->compositor); |
Pekka Paalanen | f0fc70d | 2011-11-15 13:34:54 +0200 | [diff] [blame] | 3878 | return; |
Tiago Vignatti | 8e53c7f | 2012-02-29 19:53:50 +0200 | [diff] [blame] | 3879 | } |
Pekka Paalanen | 9ef3e01 | 2011-11-15 13:34:48 +0200 | [diff] [blame] | 3880 | |
| 3881 | shell->locked = true; |
Pekka Paalanen | f0fc70d | 2011-11-15 13:34:54 +0200 | [diff] [blame] | 3882 | |
Kristian Høgsberg | 3be2ce9 | 2012-02-29 12:42:35 -0500 | [diff] [blame] | 3883 | /* Hide all surfaces by removing the fullscreen, panel and |
| 3884 | * toplevel layers. This way nothing else can show or receive |
| 3885 | * input events while we are locked. */ |
Pekka Paalanen | f0fc70d | 2011-11-15 13:34:54 +0200 | [diff] [blame] | 3886 | |
Kristian Høgsberg | 3be2ce9 | 2012-02-29 12:42:35 -0500 | [diff] [blame] | 3887 | wl_list_remove(&shell->panel_layer.link); |
Kristian Høgsberg | 3be2ce9 | 2012-02-29 12:42:35 -0500 | [diff] [blame] | 3888 | wl_list_remove(&shell->fullscreen_layer.link); |
Philipp Brüschweiler | 711fda8 | 2012-08-09 18:50:43 +0200 | [diff] [blame] | 3889 | if (shell->showing_input_panels) |
| 3890 | wl_list_remove(&shell->input_panel_layer.link); |
Kristian Høgsberg | 4476aaf | 2012-06-25 14:03:13 -0400 | [diff] [blame] | 3891 | wl_list_remove(&ws->layer.link); |
Kristian Høgsberg | 3be2ce9 | 2012-02-29 12:42:35 -0500 | [diff] [blame] | 3892 | wl_list_insert(&shell->compositor->cursor_layer.link, |
| 3893 | &shell->lock_layer.link); |
Pekka Paalanen | f0fc70d | 2011-11-15 13:34:54 +0200 | [diff] [blame] | 3894 | |
Pekka Paalanen | 77346a6 | 2011-11-30 16:26:35 +0200 | [diff] [blame] | 3895 | launch_screensaver(shell); |
| 3896 | |
Pekka Paalanen | f0fc70d | 2011-11-15 13:34:54 +0200 | [diff] [blame] | 3897 | /* TODO: disable bindings that should not work while locked. */ |
| 3898 | |
| 3899 | /* All this must be undone in resume_desktop(). */ |
Pekka Paalanen | 9ef3e01 | 2011-11-15 13:34:48 +0200 | [diff] [blame] | 3900 | } |
| 3901 | |
| 3902 | static void |
Ander Conselvan de Oliveira | 19d10ef | 2013-02-21 18:35:20 +0200 | [diff] [blame] | 3903 | unlock(struct desktop_shell *shell) |
Pekka Paalanen | 9ef3e01 | 2011-11-15 13:34:48 +0200 | [diff] [blame] | 3904 | { |
Pekka Paalanen | d81c216 | 2011-11-16 13:47:34 +0200 | [diff] [blame] | 3905 | if (!shell->locked || shell->lock_surface) { |
Ander Conselvan de Oliveira | 87524b6 | 2013-02-21 18:35:22 +0200 | [diff] [blame] | 3906 | shell_fade(shell, FADE_IN); |
Pekka Paalanen | 9ef3e01 | 2011-11-15 13:34:48 +0200 | [diff] [blame] | 3907 | return; |
| 3908 | } |
| 3909 | |
| 3910 | /* If desktop-shell client has gone away, unlock immediately. */ |
| 3911 | if (!shell->child.desktop_shell) { |
Pekka Paalanen | f0fc70d | 2011-11-15 13:34:54 +0200 | [diff] [blame] | 3912 | resume_desktop(shell); |
Pekka Paalanen | 9ef3e01 | 2011-11-15 13:34:48 +0200 | [diff] [blame] | 3913 | return; |
| 3914 | } |
| 3915 | |
| 3916 | if (shell->prepare_event_sent) |
| 3917 | return; |
| 3918 | |
Kristian Høgsberg | 0b5cd0c | 2012-03-04 21:57:37 -0500 | [diff] [blame] | 3919 | desktop_shell_send_prepare_lock_surface(shell->child.desktop_shell); |
Pekka Paalanen | 9ef3e01 | 2011-11-15 13:34:48 +0200 | [diff] [blame] | 3920 | shell->prepare_event_sent = true; |
Kristian Høgsberg | 02ec0a5 | 2011-04-23 13:04:11 -0400 | [diff] [blame] | 3921 | } |
| 3922 | |
| 3923 | static void |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 3924 | shell_fade_done(struct weston_view_animation *animation, void *data) |
Ander Conselvan de Oliveira | 19d10ef | 2013-02-21 18:35:20 +0200 | [diff] [blame] | 3925 | { |
| 3926 | struct desktop_shell *shell = data; |
| 3927 | |
| 3928 | shell->fade.animation = NULL; |
| 3929 | |
| 3930 | switch (shell->fade.type) { |
| 3931 | case FADE_IN: |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 3932 | weston_surface_destroy(shell->fade.view->surface); |
| 3933 | shell->fade.view = NULL; |
Ander Conselvan de Oliveira | 19d10ef | 2013-02-21 18:35:20 +0200 | [diff] [blame] | 3934 | break; |
| 3935 | case FADE_OUT: |
Ander Conselvan de Oliveira | 19d10ef | 2013-02-21 18:35:20 +0200 | [diff] [blame] | 3936 | lock(shell); |
| 3937 | break; |
| 3938 | } |
| 3939 | } |
| 3940 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 3941 | static struct weston_view * |
Pekka Paalanen | 79346ab | 2013-05-22 18:03:09 +0300 | [diff] [blame] | 3942 | shell_fade_create_surface(struct desktop_shell *shell) |
Ander Conselvan de Oliveira | 19d10ef | 2013-02-21 18:35:20 +0200 | [diff] [blame] | 3943 | { |
| 3944 | struct weston_compositor *compositor = shell->compositor; |
| 3945 | struct weston_surface *surface; |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 3946 | struct weston_view *view; |
Pekka Paalanen | 79346ab | 2013-05-22 18:03:09 +0300 | [diff] [blame] | 3947 | |
| 3948 | surface = weston_surface_create(compositor); |
| 3949 | if (!surface) |
| 3950 | return NULL; |
| 3951 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 3952 | view = weston_view_create(surface); |
| 3953 | if (!view) { |
| 3954 | weston_surface_destroy(surface); |
| 3955 | return NULL; |
| 3956 | } |
| 3957 | |
| 3958 | weston_view_configure(view, 0, 0, 8192, 8192); |
Pekka Paalanen | 79346ab | 2013-05-22 18:03:09 +0300 | [diff] [blame] | 3959 | 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] | 3960 | wl_list_insert(&compositor->fade_layer.view_list, |
| 3961 | &view->layer_link); |
Pekka Paalanen | 79346ab | 2013-05-22 18:03:09 +0300 | [diff] [blame] | 3962 | pixman_region32_init(&surface->input); |
| 3963 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 3964 | return view; |
Pekka Paalanen | 79346ab | 2013-05-22 18:03:09 +0300 | [diff] [blame] | 3965 | } |
| 3966 | |
| 3967 | static void |
| 3968 | shell_fade(struct desktop_shell *shell, enum fade_type type) |
| 3969 | { |
Ander Conselvan de Oliveira | 19d10ef | 2013-02-21 18:35:20 +0200 | [diff] [blame] | 3970 | float tint; |
| 3971 | |
| 3972 | switch (type) { |
| 3973 | case FADE_IN: |
| 3974 | tint = 0.0; |
| 3975 | break; |
| 3976 | case FADE_OUT: |
| 3977 | tint = 1.0; |
| 3978 | break; |
| 3979 | default: |
| 3980 | weston_log("shell: invalid fade type\n"); |
| 3981 | return; |
| 3982 | } |
| 3983 | |
| 3984 | shell->fade.type = type; |
| 3985 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 3986 | if (shell->fade.view == NULL) { |
| 3987 | shell->fade.view = shell_fade_create_surface(shell); |
| 3988 | if (!shell->fade.view) |
Ander Conselvan de Oliveira | 19d10ef | 2013-02-21 18:35:20 +0200 | [diff] [blame] | 3989 | return; |
| 3990 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 3991 | shell->fade.view->alpha = 1.0 - tint; |
| 3992 | weston_view_update_transform(shell->fade.view); |
Ander Conselvan de Oliveira | 19d10ef | 2013-02-21 18:35:20 +0200 | [diff] [blame] | 3993 | } |
| 3994 | |
| 3995 | if (shell->fade.animation) |
Kristian Høgsberg | 5281fb1 | 2013-06-17 10:10:28 -0400 | [diff] [blame] | 3996 | weston_fade_update(shell->fade.animation, tint); |
Ander Conselvan de Oliveira | 19d10ef | 2013-02-21 18:35:20 +0200 | [diff] [blame] | 3997 | else |
| 3998 | shell->fade.animation = |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 3999 | weston_fade_run(shell->fade.view, |
Kristian Høgsberg | 5281fb1 | 2013-06-17 10:10:28 -0400 | [diff] [blame] | 4000 | 1.0 - tint, tint, 300.0, |
Ander Conselvan de Oliveira | 19d10ef | 2013-02-21 18:35:20 +0200 | [diff] [blame] | 4001 | shell_fade_done, shell); |
| 4002 | } |
| 4003 | |
| 4004 | static void |
Pekka Paalanen | 79346ab | 2013-05-22 18:03:09 +0300 | [diff] [blame] | 4005 | do_shell_fade_startup(void *data) |
| 4006 | { |
| 4007 | struct desktop_shell *shell = data; |
| 4008 | |
Kristian Høgsberg | 724c8d9 | 2013-10-16 11:38:24 -0700 | [diff] [blame] | 4009 | if (shell->startup_animation_type == ANIMATION_FADE) |
| 4010 | shell_fade(shell, FADE_IN); |
| 4011 | else if (shell->startup_animation_type == ANIMATION_NONE) { |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 4012 | weston_surface_destroy(shell->fade.view->surface); |
| 4013 | shell->fade.view = NULL; |
Kristian Høgsberg | 724c8d9 | 2013-10-16 11:38:24 -0700 | [diff] [blame] | 4014 | } |
Pekka Paalanen | 79346ab | 2013-05-22 18:03:09 +0300 | [diff] [blame] | 4015 | } |
| 4016 | |
| 4017 | static void |
| 4018 | shell_fade_startup(struct desktop_shell *shell) |
| 4019 | { |
| 4020 | struct wl_event_loop *loop; |
| 4021 | |
| 4022 | if (!shell->fade.startup_timer) |
| 4023 | return; |
| 4024 | |
| 4025 | wl_event_source_remove(shell->fade.startup_timer); |
| 4026 | shell->fade.startup_timer = NULL; |
| 4027 | |
| 4028 | loop = wl_display_get_event_loop(shell->compositor->wl_display); |
| 4029 | wl_event_loop_add_idle(loop, do_shell_fade_startup, shell); |
| 4030 | } |
| 4031 | |
| 4032 | static int |
| 4033 | fade_startup_timeout(void *data) |
| 4034 | { |
| 4035 | struct desktop_shell *shell = data; |
| 4036 | |
| 4037 | shell_fade_startup(shell); |
| 4038 | return 0; |
| 4039 | } |
| 4040 | |
| 4041 | static void |
| 4042 | shell_fade_init(struct desktop_shell *shell) |
| 4043 | { |
| 4044 | /* Make compositor output all black, and wait for the desktop-shell |
| 4045 | * client to signal it is ready, then fade in. The timer triggers a |
| 4046 | * fade-in, in case the desktop-shell client takes too long. |
| 4047 | */ |
| 4048 | |
| 4049 | struct wl_event_loop *loop; |
| 4050 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 4051 | if (shell->fade.view != NULL) { |
Pekka Paalanen | 79346ab | 2013-05-22 18:03:09 +0300 | [diff] [blame] | 4052 | weston_log("%s: warning: fade surface already exists\n", |
| 4053 | __func__); |
| 4054 | return; |
| 4055 | } |
| 4056 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 4057 | shell->fade.view = shell_fade_create_surface(shell); |
| 4058 | if (!shell->fade.view) |
Pekka Paalanen | 79346ab | 2013-05-22 18:03:09 +0300 | [diff] [blame] | 4059 | return; |
| 4060 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 4061 | weston_view_update_transform(shell->fade.view); |
| 4062 | weston_surface_damage(shell->fade.view->surface); |
Pekka Paalanen | 79346ab | 2013-05-22 18:03:09 +0300 | [diff] [blame] | 4063 | |
| 4064 | loop = wl_display_get_event_loop(shell->compositor->wl_display); |
| 4065 | shell->fade.startup_timer = |
| 4066 | wl_event_loop_add_timer(loop, fade_startup_timeout, shell); |
| 4067 | wl_event_source_timer_update(shell->fade.startup_timer, 15000); |
| 4068 | } |
| 4069 | |
| 4070 | static void |
Ander Conselvan de Oliveira | a457563 | 2013-02-21 18:35:23 +0200 | [diff] [blame] | 4071 | idle_handler(struct wl_listener *listener, void *data) |
Ander Conselvan de Oliveira | 19d10ef | 2013-02-21 18:35:20 +0200 | [diff] [blame] | 4072 | { |
| 4073 | struct desktop_shell *shell = |
Ander Conselvan de Oliveira | a457563 | 2013-02-21 18:35:23 +0200 | [diff] [blame] | 4074 | container_of(listener, struct desktop_shell, idle_listener); |
Ander Conselvan de Oliveira | 19d10ef | 2013-02-21 18:35:20 +0200 | [diff] [blame] | 4075 | |
| 4076 | shell_fade(shell, FADE_OUT); |
| 4077 | /* lock() is called from shell_fade_done() */ |
| 4078 | } |
| 4079 | |
| 4080 | static void |
Ander Conselvan de Oliveira | a457563 | 2013-02-21 18:35:23 +0200 | [diff] [blame] | 4081 | wake_handler(struct wl_listener *listener, void *data) |
Ander Conselvan de Oliveira | 19d10ef | 2013-02-21 18:35:20 +0200 | [diff] [blame] | 4082 | { |
| 4083 | struct desktop_shell *shell = |
Ander Conselvan de Oliveira | a457563 | 2013-02-21 18:35:23 +0200 | [diff] [blame] | 4084 | container_of(listener, struct desktop_shell, wake_listener); |
Ander Conselvan de Oliveira | 19d10ef | 2013-02-21 18:35:20 +0200 | [diff] [blame] | 4085 | |
Ander Conselvan de Oliveira | 19d10ef | 2013-02-21 18:35:20 +0200 | [diff] [blame] | 4086 | unlock(shell); |
| 4087 | } |
| 4088 | |
| 4089 | static void |
Jan Arne Petersen | 42feced | 2012-06-21 21:52:17 +0200 | [diff] [blame] | 4090 | show_input_panels(struct wl_listener *listener, void *data) |
| 4091 | { |
| 4092 | struct desktop_shell *shell = |
Philipp Brüschweiler | 711fda8 | 2012-08-09 18:50:43 +0200 | [diff] [blame] | 4093 | container_of(listener, struct desktop_shell, |
| 4094 | show_input_panel_listener); |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 4095 | struct input_panel_surface *ipsurf, *next; |
Jan Arne Petersen | 42feced | 2012-06-21 21:52:17 +0200 | [diff] [blame] | 4096 | |
Jan Arne Petersen | 14da96b | 2013-04-18 16:47:28 +0200 | [diff] [blame] | 4097 | shell->text_input.surface = (struct weston_surface*)data; |
| 4098 | |
Jan Arne Petersen | 451a971 | 2013-02-11 15:10:11 +0100 | [diff] [blame] | 4099 | if (shell->showing_input_panels) |
| 4100 | return; |
| 4101 | |
Philipp Brüschweiler | 711fda8 | 2012-08-09 18:50:43 +0200 | [diff] [blame] | 4102 | shell->showing_input_panels = true; |
| 4103 | |
Jan Arne Petersen | cf18a32 | 2012-11-07 15:32:54 +0100 | [diff] [blame] | 4104 | if (!shell->locked) |
| 4105 | wl_list_insert(&shell->panel_layer.link, |
| 4106 | &shell->input_panel_layer.link); |
Philipp Brüschweiler | 711fda8 | 2012-08-09 18:50:43 +0200 | [diff] [blame] | 4107 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 4108 | wl_list_for_each_safe(ipsurf, next, |
Philipp Brüschweiler | 8801357 | 2012-08-06 13:44:42 +0200 | [diff] [blame] | 4109 | &shell->input_panel.surfaces, link) { |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 4110 | if (!ipsurf->surface->buffer_ref.buffer) |
Jan Arne Petersen | 14da96b | 2013-04-18 16:47:28 +0200 | [diff] [blame] | 4111 | continue; |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 4112 | wl_list_insert(&shell->input_panel_layer.view_list, |
| 4113 | &ipsurf->view->layer_link); |
| 4114 | weston_view_geometry_dirty(ipsurf->view); |
| 4115 | weston_view_update_transform(ipsurf->view); |
| 4116 | weston_surface_damage(ipsurf->surface); |
| 4117 | weston_slide_run(ipsurf->view, ipsurf->view->geometry.height, |
| 4118 | 0, NULL, NULL); |
Jan Arne Petersen | 42feced | 2012-06-21 21:52:17 +0200 | [diff] [blame] | 4119 | } |
| 4120 | } |
| 4121 | |
| 4122 | static void |
| 4123 | hide_input_panels(struct wl_listener *listener, void *data) |
| 4124 | { |
| 4125 | struct desktop_shell *shell = |
Philipp Brüschweiler | 711fda8 | 2012-08-09 18:50:43 +0200 | [diff] [blame] | 4126 | container_of(listener, struct desktop_shell, |
| 4127 | hide_input_panel_listener); |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 4128 | struct weston_view *view, *next; |
Jan Arne Petersen | 42feced | 2012-06-21 21:52:17 +0200 | [diff] [blame] | 4129 | |
Jan Arne Petersen | 6138197 | 2013-01-31 15:52:21 +0100 | [diff] [blame] | 4130 | if (!shell->showing_input_panels) |
| 4131 | return; |
| 4132 | |
Philipp Brüschweiler | 711fda8 | 2012-08-09 18:50:43 +0200 | [diff] [blame] | 4133 | shell->showing_input_panels = false; |
| 4134 | |
Jan Arne Petersen | 82ec909 | 2012-12-03 15:36:02 +0100 | [diff] [blame] | 4135 | if (!shell->locked) |
| 4136 | wl_list_remove(&shell->input_panel_layer.link); |
Philipp Brüschweiler | 711fda8 | 2012-08-09 18:50:43 +0200 | [diff] [blame] | 4137 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 4138 | wl_list_for_each_safe(view, next, |
| 4139 | &shell->input_panel_layer.view_list, layer_link) |
| 4140 | weston_view_unmap(view); |
Jan Arne Petersen | 42feced | 2012-06-21 21:52:17 +0200 | [diff] [blame] | 4141 | } |
| 4142 | |
| 4143 | static void |
Jan Arne Petersen | 14da96b | 2013-04-18 16:47:28 +0200 | [diff] [blame] | 4144 | update_input_panels(struct wl_listener *listener, void *data) |
| 4145 | { |
| 4146 | struct desktop_shell *shell = |
| 4147 | container_of(listener, struct desktop_shell, |
| 4148 | update_input_panel_listener); |
| 4149 | |
| 4150 | memcpy(&shell->text_input.cursor_rectangle, data, sizeof(pixman_box32_t)); |
| 4151 | } |
| 4152 | |
| 4153 | static void |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 4154 | center_on_output(struct weston_view *view, struct weston_output *output) |
Pekka Paalanen | 77346a6 | 2011-11-30 16:26:35 +0200 | [diff] [blame] | 4155 | { |
Giulio Camuffo | b836664 | 2013-04-25 13:57:46 +0300 | [diff] [blame] | 4156 | int32_t surf_x, surf_y, width, height; |
Ander Conselvan de Oliveira | 012b4c7 | 2012-11-27 17:03:42 +0200 | [diff] [blame] | 4157 | float x, y; |
Pekka Paalanen | 77346a6 | 2011-11-30 16:26:35 +0200 | [diff] [blame] | 4158 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 4159 | surface_subsurfaces_boundingbox(view->surface, &surf_x, &surf_y, &width, &height); |
Giulio Camuffo | b836664 | 2013-04-25 13:57:46 +0300 | [diff] [blame] | 4160 | |
| 4161 | x = output->x + (output->width - width) / 2 - surf_x / 2; |
| 4162 | y = output->y + (output->height - height) / 2 - surf_y / 2; |
Ander Conselvan de Oliveira | 012b4c7 | 2012-11-27 17:03:42 +0200 | [diff] [blame] | 4163 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 4164 | weston_view_configure(view, x, y, width, height); |
Pekka Paalanen | 77346a6 | 2011-11-30 16:26:35 +0200 | [diff] [blame] | 4165 | } |
| 4166 | |
| 4167 | static void |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 4168 | weston_view_set_initial_position(struct weston_view *view, |
| 4169 | struct desktop_shell *shell) |
Rob Bradford | ac63e5b | 2012-08-13 14:07:52 +0100 | [diff] [blame] | 4170 | { |
| 4171 | struct weston_compositor *compositor = shell->compositor; |
| 4172 | int ix = 0, iy = 0; |
| 4173 | int range_x, range_y; |
| 4174 | int dx, dy, x, y, panel_height; |
| 4175 | struct weston_output *output, *target_output = NULL; |
| 4176 | struct weston_seat *seat; |
| 4177 | |
| 4178 | /* As a heuristic place the new window on the same output as the |
| 4179 | * pointer. Falling back to the output containing 0, 0. |
| 4180 | * |
| 4181 | * TODO: Do something clever for touch too? |
| 4182 | */ |
| 4183 | wl_list_for_each(seat, &compositor->seat_list, link) { |
Kristian Høgsberg | 2bf8762 | 2013-05-07 23:17:41 -0400 | [diff] [blame] | 4184 | if (seat->pointer) { |
Kristian Høgsberg | e314875 | 2013-05-06 23:19:49 -0400 | [diff] [blame] | 4185 | ix = wl_fixed_to_int(seat->pointer->x); |
| 4186 | iy = wl_fixed_to_int(seat->pointer->y); |
Rob Bradford | ac63e5b | 2012-08-13 14:07:52 +0100 | [diff] [blame] | 4187 | break; |
| 4188 | } |
| 4189 | } |
| 4190 | |
| 4191 | wl_list_for_each(output, &compositor->output_list, link) { |
| 4192 | if (pixman_region32_contains_point(&output->region, ix, iy, NULL)) { |
| 4193 | target_output = output; |
| 4194 | break; |
| 4195 | } |
| 4196 | } |
| 4197 | |
| 4198 | if (!target_output) { |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 4199 | weston_view_set_position(view, 10 + random() % 400, |
| 4200 | 10 + random() % 400); |
Rob Bradford | ac63e5b | 2012-08-13 14:07:52 +0100 | [diff] [blame] | 4201 | return; |
| 4202 | } |
| 4203 | |
| 4204 | /* Valid range within output where the surface will still be onscreen. |
| 4205 | * If this is negative it means that the surface is bigger than |
| 4206 | * output. |
| 4207 | */ |
| 4208 | panel_height = get_output_panel_height(shell, target_output); |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 4209 | range_x = target_output->width - view->geometry.width; |
Scott Moreau | 1bad5db | 2012-08-18 01:04:05 -0600 | [diff] [blame] | 4210 | range_y = (target_output->height - panel_height) - |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 4211 | view->geometry.height; |
Rob Bradford | ac63e5b | 2012-08-13 14:07:52 +0100 | [diff] [blame] | 4212 | |
Rob Bradford | 4cb88c7 | 2012-08-13 15:18:44 +0100 | [diff] [blame] | 4213 | if (range_x > 0) |
Rob Bradford | ac63e5b | 2012-08-13 14:07:52 +0100 | [diff] [blame] | 4214 | dx = random() % range_x; |
Rob Bradford | ac63e5b | 2012-08-13 14:07:52 +0100 | [diff] [blame] | 4215 | else |
Rob Bradford | 4cb88c7 | 2012-08-13 15:18:44 +0100 | [diff] [blame] | 4216 | dx = 0; |
| 4217 | |
| 4218 | if (range_y > 0) |
Rob Bradford | ac63e5b | 2012-08-13 14:07:52 +0100 | [diff] [blame] | 4219 | dy = panel_height + random() % range_y; |
Rob Bradford | 4cb88c7 | 2012-08-13 15:18:44 +0100 | [diff] [blame] | 4220 | else |
| 4221 | dy = panel_height; |
Rob Bradford | ac63e5b | 2012-08-13 14:07:52 +0100 | [diff] [blame] | 4222 | |
| 4223 | x = target_output->x + dx; |
| 4224 | y = target_output->y + dy; |
| 4225 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 4226 | weston_view_set_position(view, x, y); |
Rob Bradford | ac63e5b | 2012-08-13 14:07:52 +0100 | [diff] [blame] | 4227 | } |
| 4228 | |
| 4229 | static void |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 4230 | map(struct desktop_shell *shell, struct shell_surface *shsurf, |
Ander Conselvan de Oliveira | e9e0515 | 2012-02-15 17:02:56 +0200 | [diff] [blame] | 4231 | 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] | 4232 | { |
Kristian Høgsberg | 8334bc1 | 2012-01-03 10:29:47 -0500 | [diff] [blame] | 4233 | struct weston_compositor *compositor = shell->compositor; |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 4234 | struct weston_view *parent; |
Daniel Stone | b210468 | 2012-05-30 16:31:56 +0100 | [diff] [blame] | 4235 | struct weston_seat *seat; |
Jonas Ådahl | e3cddce | 2012-06-13 00:01:22 +0200 | [diff] [blame] | 4236 | struct workspace *ws; |
Juan Zhao | 96879df | 2012-02-07 08:45:41 +0800 | [diff] [blame] | 4237 | int panel_height = 0; |
Giulio Camuffo | b836664 | 2013-04-25 13:57:46 +0300 | [diff] [blame] | 4238 | int32_t surf_x, surf_y; |
Pekka Paalanen | 57da4a8 | 2011-11-23 16:42:16 +0200 | [diff] [blame] | 4239 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 4240 | shsurf->view->geometry.width = width; |
| 4241 | shsurf->view->geometry.height = height; |
| 4242 | weston_view_geometry_dirty(shsurf->view); |
Pekka Paalanen | 77346a6 | 2011-11-30 16:26:35 +0200 | [diff] [blame] | 4243 | |
| 4244 | /* initial positioning, see also configure() */ |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 4245 | switch (shsurf->type) { |
Pekka Paalanen | 77346a6 | 2011-11-30 16:26:35 +0200 | [diff] [blame] | 4246 | case SHELL_SURFACE_TOPLEVEL: |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 4247 | weston_view_set_initial_position(shsurf->view, shell); |
Pekka Paalanen | 77346a6 | 2011-11-30 16:26:35 +0200 | [diff] [blame] | 4248 | break; |
Alex Wu | 4539b08 | 2012-03-01 12:57:46 +0800 | [diff] [blame] | 4249 | case SHELL_SURFACE_FULLSCREEN: |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 4250 | center_on_output(shsurf->view, shsurf->fullscreen_output); |
Alex Wu | 4539b08 | 2012-03-01 12:57:46 +0800 | [diff] [blame] | 4251 | shell_map_fullscreen(shsurf); |
| 4252 | break; |
Juan Zhao | 96879df | 2012-02-07 08:45:41 +0800 | [diff] [blame] | 4253 | case SHELL_SURFACE_MAXIMIZED: |
Alex Wu | 4539b08 | 2012-03-01 12:57:46 +0800 | [diff] [blame] | 4254 | /* use surface configure to set the geometry */ |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 4255 | panel_height = get_output_panel_height(shell, shsurf->output); |
| 4256 | surface_subsurfaces_boundingbox(shsurf->surface, |
| 4257 | &surf_x, &surf_y, NULL, NULL); |
| 4258 | weston_view_set_position(shsurf->view, |
| 4259 | shsurf->output->x - surf_x, |
| 4260 | shsurf->output->y + panel_height - surf_y); |
Juan Zhao | 96879df | 2012-02-07 08:45:41 +0800 | [diff] [blame] | 4261 | break; |
Tiago Vignatti | 0f99701 | 2012-02-10 16:17:23 +0200 | [diff] [blame] | 4262 | case SHELL_SURFACE_POPUP: |
Kristian Høgsberg | 3730f36 | 2012-04-13 12:40:07 -0400 | [diff] [blame] | 4263 | shell_map_popup(shsurf); |
Rob Bradford | db99938 | 2012-12-06 12:07:48 +0000 | [diff] [blame] | 4264 | break; |
Ander Conselvan de Oliveira | e9e0515 | 2012-02-15 17:02:56 +0200 | [diff] [blame] | 4265 | case SHELL_SURFACE_NONE: |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 4266 | weston_view_set_position(shsurf->view, |
| 4267 | shsurf->view->geometry.x + sx, |
| 4268 | shsurf->view->geometry.y + sy); |
Tiago Vignatti | 0f99701 | 2012-02-10 16:17:23 +0200 | [diff] [blame] | 4269 | break; |
Pekka Paalanen | 77346a6 | 2011-11-30 16:26:35 +0200 | [diff] [blame] | 4270 | default: |
| 4271 | ; |
| 4272 | } |
Kristian Høgsberg | 7584062 | 2011-09-06 13:48:16 -0400 | [diff] [blame] | 4273 | |
Pekka Paalanen | d3dd6e1 | 2011-11-16 13:47:33 +0200 | [diff] [blame] | 4274 | /* surface stacking order, see also activate() */ |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 4275 | switch (shsurf->type) { |
Kristian Høgsberg | 60c4954 | 2012-03-05 20:51:34 -0500 | [diff] [blame] | 4276 | case SHELL_SURFACE_POPUP: |
| 4277 | case SHELL_SURFACE_TRANSIENT: |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 4278 | /* TODO: Handle a parent with multiple views */ |
| 4279 | parent = get_default_view(shsurf->parent); |
| 4280 | if (parent) { |
| 4281 | wl_list_remove(&shsurf->view->layer_link); |
| 4282 | wl_list_insert(parent->layer_link.prev, |
| 4283 | &shsurf->view->layer_link); |
| 4284 | } |
Kristian Høgsberg | 60c4954 | 2012-03-05 20:51:34 -0500 | [diff] [blame] | 4285 | break; |
Alex Wu | 4539b08 | 2012-03-01 12:57:46 +0800 | [diff] [blame] | 4286 | case SHELL_SURFACE_FULLSCREEN: |
Ander Conselvan de Oliveira | a1ff53b | 2012-02-15 17:02:54 +0200 | [diff] [blame] | 4287 | case SHELL_SURFACE_NONE: |
| 4288 | break; |
Tiago Vignatti | fb2adba | 2013-06-12 15:43:21 -0300 | [diff] [blame] | 4289 | case SHELL_SURFACE_XWAYLAND: |
Pekka Paalanen | 57da4a8 | 2011-11-23 16:42:16 +0200 | [diff] [blame] | 4290 | default: |
Jonas Ådahl | e3cddce | 2012-06-13 00:01:22 +0200 | [diff] [blame] | 4291 | ws = get_current_workspace(shell); |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 4292 | wl_list_remove(&shsurf->view->layer_link); |
| 4293 | wl_list_insert(&ws->layer.view_list, &shsurf->view->layer_link); |
Kristian Høgsberg | 3be2ce9 | 2012-02-29 12:42:35 -0500 | [diff] [blame] | 4294 | break; |
Pekka Paalanen | f0fc70d | 2011-11-15 13:34:54 +0200 | [diff] [blame] | 4295 | } |
| 4296 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 4297 | if (shsurf->type != SHELL_SURFACE_NONE) { |
| 4298 | weston_view_update_transform(shsurf->view); |
| 4299 | if (shsurf->type == SHELL_SURFACE_MAXIMIZED) { |
| 4300 | shsurf->surface->output = shsurf->output; |
| 4301 | shsurf->view->output = shsurf->output; |
| 4302 | } |
Ander Conselvan de Oliveira | de56c31 | 2012-03-05 15:39:23 +0200 | [diff] [blame] | 4303 | } |
Kristian Høgsberg | 2f88a40 | 2011-12-04 15:32:59 -0500 | [diff] [blame] | 4304 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 4305 | switch (shsurf->type) { |
Tiago Vignatti | fb2adba | 2013-06-12 15:43:21 -0300 | [diff] [blame] | 4306 | /* XXX: xwayland's using the same fields for transient type */ |
| 4307 | case SHELL_SURFACE_XWAYLAND: |
Juan Zhao | 7bb92f0 | 2011-12-15 11:31:51 -0500 | [diff] [blame] | 4308 | case SHELL_SURFACE_TRANSIENT: |
Tiago Vignatti | 99aeb1e | 2012-05-23 22:06:26 +0300 | [diff] [blame] | 4309 | if (shsurf->transient.flags == |
| 4310 | WL_SHELL_SURFACE_TRANSIENT_INACTIVE) |
| 4311 | break; |
| 4312 | case SHELL_SURFACE_TOPLEVEL: |
Juan Zhao | 7bb92f0 | 2011-12-15 11:31:51 -0500 | [diff] [blame] | 4313 | case SHELL_SURFACE_FULLSCREEN: |
Juan Zhao | 96879df | 2012-02-07 08:45:41 +0800 | [diff] [blame] | 4314 | case SHELL_SURFACE_MAXIMIZED: |
Daniel Stone | b210468 | 2012-05-30 16:31:56 +0100 | [diff] [blame] | 4315 | if (!shell->locked) { |
| 4316 | wl_list_for_each(seat, &compositor->seat_list, link) |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 4317 | activate(shell, shsurf->surface, seat); |
Daniel Stone | b210468 | 2012-05-30 16:31:56 +0100 | [diff] [blame] | 4318 | } |
Juan Zhao | 7bb92f0 | 2011-12-15 11:31:51 -0500 | [diff] [blame] | 4319 | break; |
| 4320 | default: |
| 4321 | break; |
| 4322 | } |
| 4323 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 4324 | if (shsurf->type == SHELL_SURFACE_TOPLEVEL) |
Juan Zhao | e10d279 | 2012-04-25 19:09:52 +0800 | [diff] [blame] | 4325 | { |
| 4326 | switch (shell->win_animation_type) { |
| 4327 | case ANIMATION_FADE: |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 4328 | 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] | 4329 | break; |
| 4330 | case ANIMATION_ZOOM: |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 4331 | weston_zoom_run(shsurf->view, 0.5, 1.0, NULL, NULL); |
Juan Zhao | e10d279 | 2012-04-25 19:09:52 +0800 | [diff] [blame] | 4332 | break; |
| 4333 | default: |
| 4334 | break; |
| 4335 | } |
| 4336 | } |
Kristian Høgsberg | 32e24cc | 2011-11-09 12:07:35 -0500 | [diff] [blame] | 4337 | } |
| 4338 | |
| 4339 | static void |
Tiago Vignatti | be14326 | 2012-04-16 17:31:41 +0300 | [diff] [blame] | 4340 | configure(struct desktop_shell *shell, struct weston_surface *surface, |
John Kåre Alsaker | 490d02a | 2012-09-30 02:57:21 +0200 | [diff] [blame] | 4341 | float x, float y, int32_t width, int32_t height) |
Kristian Høgsberg | 32e24cc | 2011-11-09 12:07:35 -0500 | [diff] [blame] | 4342 | { |
Pekka Paalanen | 77346a6 | 2011-11-30 16:26:35 +0200 | [diff] [blame] | 4343 | enum shell_surface_type surface_type = SHELL_SURFACE_NONE; |
| 4344 | struct shell_surface *shsurf; |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 4345 | struct weston_view *view; |
Giulio Camuffo | b836664 | 2013-04-25 13:57:46 +0300 | [diff] [blame] | 4346 | int32_t surf_x, surf_y; |
Kristian Høgsberg | 32e24cc | 2011-11-09 12:07:35 -0500 | [diff] [blame] | 4347 | |
Pekka Paalanen | 77346a6 | 2011-11-30 16:26:35 +0200 | [diff] [blame] | 4348 | shsurf = get_shell_surface(surface); |
| 4349 | if (shsurf) |
| 4350 | surface_type = shsurf->type; |
| 4351 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 4352 | /* TODO: |
| 4353 | * This should probably be changed to be more shell_surface |
| 4354 | * dependent |
| 4355 | */ |
| 4356 | wl_list_for_each(view, &surface->views, surface_link) |
| 4357 | weston_view_configure(view, x, y, width, height); |
Pekka Paalanen | 77346a6 | 2011-11-30 16:26:35 +0200 | [diff] [blame] | 4358 | |
| 4359 | switch (surface_type) { |
Alex Wu | 4539b08 | 2012-03-01 12:57:46 +0800 | [diff] [blame] | 4360 | case SHELL_SURFACE_FULLSCREEN: |
Alex Wu | bd3354b | 2012-04-17 17:20:49 +0800 | [diff] [blame] | 4361 | shell_stack_fullscreen(shsurf); |
Alex Wu | 4539b08 | 2012-03-01 12:57:46 +0800 | [diff] [blame] | 4362 | shell_configure_fullscreen(shsurf); |
Alex Wu | 4539b08 | 2012-03-01 12:57:46 +0800 | [diff] [blame] | 4363 | break; |
Juan Zhao | 96879df | 2012-02-07 08:45:41 +0800 | [diff] [blame] | 4364 | case SHELL_SURFACE_MAXIMIZED: |
Alex Wu | 4539b08 | 2012-03-01 12:57:46 +0800 | [diff] [blame] | 4365 | /* setting x, y and using configure to change that geometry */ |
Giulio Camuffo | b836664 | 2013-04-25 13:57:46 +0300 | [diff] [blame] | 4366 | surface_subsurfaces_boundingbox(shsurf->surface, &surf_x, &surf_y, |
| 4367 | NULL, NULL); |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 4368 | shsurf->view->geometry.x = shsurf->output->x - surf_x; |
| 4369 | shsurf->view->geometry.y = shsurf->output->y + |
| 4370 | get_output_panel_height(shell,shsurf->output) - surf_y; |
Juan Zhao | 96879df | 2012-02-07 08:45:41 +0800 | [diff] [blame] | 4371 | break; |
Alex Wu | 4539b08 | 2012-03-01 12:57:46 +0800 | [diff] [blame] | 4372 | case SHELL_SURFACE_TOPLEVEL: |
| 4373 | break; |
Kristian Høgsberg | d2abb83 | 2011-11-23 10:52:40 -0500 | [diff] [blame] | 4374 | default: |
| 4375 | break; |
Kristian Høgsberg | 7a5c979 | 2011-06-18 06:12:54 -0400 | [diff] [blame] | 4376 | } |
Kristian Høgsberg | 32e24cc | 2011-11-09 12:07:35 -0500 | [diff] [blame] | 4377 | |
Alex Wu | 4539b08 | 2012-03-01 12:57:46 +0800 | [diff] [blame] | 4378 | /* XXX: would a fullscreen surface need the same handling? */ |
Kristian Høgsberg | 6a8b553 | 2012-02-16 23:43:59 -0500 | [diff] [blame] | 4379 | if (surface->output) { |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 4380 | wl_list_for_each(view, &surface->views, surface_link) |
| 4381 | weston_view_update_transform(view); |
Pekka Paalanen | 77346a6 | 2011-11-30 16:26:35 +0200 | [diff] [blame] | 4382 | |
Kristian Høgsberg | 1a73a63 | 2012-06-26 22:15:53 -0400 | [diff] [blame] | 4383 | if (surface_type == SHELL_SURFACE_MAXIMIZED) |
Juan Zhao | 96879df | 2012-02-07 08:45:41 +0800 | [diff] [blame] | 4384 | surface->output = shsurf->output; |
Pekka Paalanen | 77346a6 | 2011-11-30 16:26:35 +0200 | [diff] [blame] | 4385 | } |
Kristian Høgsberg | 0793756 | 2011-04-12 17:25:42 -0400 | [diff] [blame] | 4386 | } |
| 4387 | |
Ander Conselvan de Oliveira | 093bfa3 | 2012-03-27 17:36:41 +0300 | [diff] [blame] | 4388 | static void |
Giulio Camuffo | 184df50 | 2013-02-21 11:29:21 +0100 | [diff] [blame] | 4389 | 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] | 4390 | { |
Ander Conselvan de Oliveira | 7fb9f95 | 2012-03-27 17:36:42 +0300 | [diff] [blame] | 4391 | struct shell_surface *shsurf = get_shell_surface(es); |
Tiago Vignatti | be14326 | 2012-04-16 17:31:41 +0300 | [diff] [blame] | 4392 | struct desktop_shell *shell = shsurf->shell; |
Giulio Camuffo | 184df50 | 2013-02-21 11:29:21 +0100 | [diff] [blame] | 4393 | |
Tiago Vignatti | 70e5c9c | 2012-05-07 15:23:07 +0300 | [diff] [blame] | 4394 | int type_changed = 0; |
Ander Conselvan de Oliveira | 093bfa3 | 2012-03-27 17:36:41 +0300 | [diff] [blame] | 4395 | |
Kristian Høgsberg | 8eb0f4f | 2013-06-17 10:33:14 -0400 | [diff] [blame] | 4396 | if (!weston_surface_is_mapped(es) && |
| 4397 | !wl_list_empty(&shsurf->popup.grab_link)) { |
Giulio Camuffo | 5085a75 | 2013-03-25 21:42:45 +0100 | [diff] [blame] | 4398 | remove_popup_grab(shsurf); |
| 4399 | } |
| 4400 | |
Giulio Camuffo | 184df50 | 2013-02-21 11:29:21 +0100 | [diff] [blame] | 4401 | if (width == 0) |
| 4402 | return; |
| 4403 | |
Kristian Høgsberg | 7f366e7 | 2012-04-27 17:20:01 -0400 | [diff] [blame] | 4404 | if (shsurf->next_type != SHELL_SURFACE_NONE && |
Kristian Høgsberg | f7e23d5 | 2012-04-27 17:51:59 -0400 | [diff] [blame] | 4405 | shsurf->type != shsurf->next_type) { |
Kristian Høgsberg | 7f366e7 | 2012-04-27 17:20:01 -0400 | [diff] [blame] | 4406 | set_surface_type(shsurf); |
Kristian Høgsberg | f7e23d5 | 2012-04-27 17:51:59 -0400 | [diff] [blame] | 4407 | type_changed = 1; |
| 4408 | } |
Kristian Høgsberg | 7f366e7 | 2012-04-27 17:20:01 -0400 | [diff] [blame] | 4409 | |
Ander Conselvan de Oliveira | 093bfa3 | 2012-03-27 17:36:41 +0300 | [diff] [blame] | 4410 | if (!weston_surface_is_mapped(es)) { |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 4411 | map(shell, shsurf, width, height, sx, sy); |
Kristian Høgsberg | f7e23d5 | 2012-04-27 17:51:59 -0400 | [diff] [blame] | 4412 | } else if (type_changed || sx != 0 || sy != 0 || |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 4413 | shsurf->view->geometry.width != width || |
| 4414 | shsurf->view->geometry.height != height) { |
John Kåre Alsaker | 490d02a | 2012-09-30 02:57:21 +0200 | [diff] [blame] | 4415 | float from_x, from_y; |
| 4416 | float to_x, to_y; |
Ander Conselvan de Oliveira | 093bfa3 | 2012-03-27 17:36:41 +0300 | [diff] [blame] | 4417 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 4418 | weston_view_to_global_float(shsurf->view, 0, 0, &from_x, &from_y); |
| 4419 | 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] | 4420 | configure(shell, es, |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 4421 | shsurf->view->geometry.x + to_x - from_x, |
| 4422 | shsurf->view->geometry.y + to_y - from_y, |
Ander Conselvan de Oliveira | 012b4c7 | 2012-11-27 17:03:42 +0200 | [diff] [blame] | 4423 | width, height); |
Ander Conselvan de Oliveira | 093bfa3 | 2012-03-27 17:36:41 +0300 | [diff] [blame] | 4424 | } |
| 4425 | } |
| 4426 | |
Tiago Vignatti | b7dbbd6 | 2012-09-25 17:57:01 +0300 | [diff] [blame] | 4427 | static void launch_desktop_shell_process(void *data); |
Pekka Paalanen | 4d733ee | 2012-01-17 14:36:27 +0200 | [diff] [blame] | 4428 | |
Kristian Høgsberg | 97d44aa | 2011-08-26 17:21:20 -0400 | [diff] [blame] | 4429 | static void |
Kristian Høgsberg | 8334bc1 | 2012-01-03 10:29:47 -0500 | [diff] [blame] | 4430 | desktop_shell_sigchld(struct weston_process *process, int status) |
Pekka Paalanen | 6cd281a | 2011-11-03 14:11:32 +0200 | [diff] [blame] | 4431 | { |
Pekka Paalanen | 4d733ee | 2012-01-17 14:36:27 +0200 | [diff] [blame] | 4432 | uint32_t time; |
Tiago Vignatti | be14326 | 2012-04-16 17:31:41 +0300 | [diff] [blame] | 4433 | struct desktop_shell *shell = |
| 4434 | container_of(process, struct desktop_shell, child.process); |
Pekka Paalanen | 6cd281a | 2011-11-03 14:11:32 +0200 | [diff] [blame] | 4435 | |
| 4436 | shell->child.process.pid = 0; |
| 4437 | shell->child.client = NULL; /* already destroyed by wayland */ |
Pekka Paalanen | 4d733ee | 2012-01-17 14:36:27 +0200 | [diff] [blame] | 4438 | |
| 4439 | /* if desktop-shell dies more than 5 times in 30 seconds, give up */ |
| 4440 | time = weston_compositor_get_time(); |
Kristian Høgsberg | f03a616 | 2012-01-17 11:07:42 -0500 | [diff] [blame] | 4441 | if (time - shell->child.deathstamp > 30000) { |
Pekka Paalanen | 4d733ee | 2012-01-17 14:36:27 +0200 | [diff] [blame] | 4442 | shell->child.deathstamp = time; |
| 4443 | shell->child.deathcount = 0; |
| 4444 | } |
| 4445 | |
| 4446 | shell->child.deathcount++; |
| 4447 | if (shell->child.deathcount > 5) { |
Emilio Pozuelo Monfort | 46ce798 | 2013-11-20 13:22:29 +0100 | [diff] [blame] | 4448 | weston_log("%s died, giving up.\n", shell->client); |
Pekka Paalanen | 4d733ee | 2012-01-17 14:36:27 +0200 | [diff] [blame] | 4449 | return; |
| 4450 | } |
| 4451 | |
Emilio Pozuelo Monfort | 46ce798 | 2013-11-20 13:22:29 +0100 | [diff] [blame] | 4452 | weston_log("%s died, respawning...\n", shell->client); |
Pekka Paalanen | 4d733ee | 2012-01-17 14:36:27 +0200 | [diff] [blame] | 4453 | launch_desktop_shell_process(shell); |
Pekka Paalanen | 79346ab | 2013-05-22 18:03:09 +0300 | [diff] [blame] | 4454 | shell_fade_startup(shell); |
Pekka Paalanen | 6cd281a | 2011-11-03 14:11:32 +0200 | [diff] [blame] | 4455 | } |
| 4456 | |
Tiago Vignatti | b7dbbd6 | 2012-09-25 17:57:01 +0300 | [diff] [blame] | 4457 | static void |
| 4458 | launch_desktop_shell_process(void *data) |
Pekka Paalanen | 6cd281a | 2011-11-03 14:11:32 +0200 | [diff] [blame] | 4459 | { |
Tiago Vignatti | b7dbbd6 | 2012-09-25 17:57:01 +0300 | [diff] [blame] | 4460 | struct desktop_shell *shell = data; |
Pekka Paalanen | 6cd281a | 2011-11-03 14:11:32 +0200 | [diff] [blame] | 4461 | |
Kristian Høgsberg | 8334bc1 | 2012-01-03 10:29:47 -0500 | [diff] [blame] | 4462 | shell->child.client = weston_client_launch(shell->compositor, |
Pekka Paalanen | 409ef0a | 2011-12-02 15:30:21 +0200 | [diff] [blame] | 4463 | &shell->child.process, |
Emilio Pozuelo Monfort | 46ce798 | 2013-11-20 13:22:29 +0100 | [diff] [blame] | 4464 | shell->client, |
Pekka Paalanen | 409ef0a | 2011-12-02 15:30:21 +0200 | [diff] [blame] | 4465 | desktop_shell_sigchld); |
| 4466 | |
| 4467 | if (!shell->child.client) |
Emilio Pozuelo Monfort | 46ce798 | 2013-11-20 13:22:29 +0100 | [diff] [blame] | 4468 | weston_log("not able to start %s\n", shell->client); |
Pekka Paalanen | 6cd281a | 2011-11-03 14:11:32 +0200 | [diff] [blame] | 4469 | } |
| 4470 | |
| 4471 | static void |
Kristian Høgsberg | 97d44aa | 2011-08-26 17:21:20 -0400 | [diff] [blame] | 4472 | bind_shell(struct wl_client *client, void *data, uint32_t version, uint32_t id) |
| 4473 | { |
Tiago Vignatti | be14326 | 2012-04-16 17:31:41 +0300 | [diff] [blame] | 4474 | struct desktop_shell *shell = data; |
Jason Ekstrand | a85118c | 2013-06-27 20:17:02 -0500 | [diff] [blame] | 4475 | struct wl_resource *resource; |
Kristian Høgsberg | 97d44aa | 2011-08-26 17:21:20 -0400 | [diff] [blame] | 4476 | |
Jason Ekstrand | a85118c | 2013-06-27 20:17:02 -0500 | [diff] [blame] | 4477 | resource = wl_resource_create(client, &wl_shell_interface, 1, id); |
| 4478 | if (resource) |
| 4479 | wl_resource_set_implementation(resource, &shell_implementation, |
| 4480 | shell, NULL); |
Kristian Høgsberg | 97d44aa | 2011-08-26 17:21:20 -0400 | [diff] [blame] | 4481 | } |
| 4482 | |
Kristian Høgsberg | 7584062 | 2011-09-06 13:48:16 -0400 | [diff] [blame] | 4483 | static void |
Pekka Paalanen | 9ef3e01 | 2011-11-15 13:34:48 +0200 | [diff] [blame] | 4484 | unbind_desktop_shell(struct wl_resource *resource) |
| 4485 | { |
Jason Ekstrand | 651f00e | 2013-06-14 10:07:54 -0500 | [diff] [blame] | 4486 | struct desktop_shell *shell = wl_resource_get_user_data(resource); |
Kristian Høgsberg | 1ec0c31 | 2011-11-15 16:39:55 -0500 | [diff] [blame] | 4487 | |
| 4488 | if (shell->locked) |
| 4489 | resume_desktop(shell); |
| 4490 | |
Pekka Paalanen | 9ef3e01 | 2011-11-15 13:34:48 +0200 | [diff] [blame] | 4491 | shell->child.desktop_shell = NULL; |
| 4492 | shell->prepare_event_sent = false; |
Pekka Paalanen | 9ef3e01 | 2011-11-15 13:34:48 +0200 | [diff] [blame] | 4493 | } |
| 4494 | |
| 4495 | static void |
Kristian Høgsberg | 7584062 | 2011-09-06 13:48:16 -0400 | [diff] [blame] | 4496 | bind_desktop_shell(struct wl_client *client, |
| 4497 | void *data, uint32_t version, uint32_t id) |
| 4498 | { |
Tiago Vignatti | be14326 | 2012-04-16 17:31:41 +0300 | [diff] [blame] | 4499 | struct desktop_shell *shell = data; |
Pekka Paalanen | bbe6052 | 2011-11-03 14:11:33 +0200 | [diff] [blame] | 4500 | struct wl_resource *resource; |
Kristian Høgsberg | 7584062 | 2011-09-06 13:48:16 -0400 | [diff] [blame] | 4501 | |
Jason Ekstrand | a85118c | 2013-06-27 20:17:02 -0500 | [diff] [blame] | 4502 | resource = wl_resource_create(client, &desktop_shell_interface, |
| 4503 | MIN(version, 2), id); |
Pekka Paalanen | bbe6052 | 2011-11-03 14:11:33 +0200 | [diff] [blame] | 4504 | |
Pekka Paalanen | 9ef3e01 | 2011-11-15 13:34:48 +0200 | [diff] [blame] | 4505 | if (client == shell->child.client) { |
Jason Ekstrand | a85118c | 2013-06-27 20:17:02 -0500 | [diff] [blame] | 4506 | wl_resource_set_implementation(resource, |
| 4507 | &desktop_shell_implementation, |
| 4508 | shell, unbind_desktop_shell); |
Pekka Paalanen | 9ef3e01 | 2011-11-15 13:34:48 +0200 | [diff] [blame] | 4509 | shell->child.desktop_shell = resource; |
Pekka Paalanen | 79346ab | 2013-05-22 18:03:09 +0300 | [diff] [blame] | 4510 | |
| 4511 | if (version < 2) |
| 4512 | shell_fade_startup(shell); |
| 4513 | |
Pekka Paalanen | bbe6052 | 2011-11-03 14:11:33 +0200 | [diff] [blame] | 4514 | return; |
Pekka Paalanen | 9ef3e01 | 2011-11-15 13:34:48 +0200 | [diff] [blame] | 4515 | } |
Pekka Paalanen | bbe6052 | 2011-11-03 14:11:33 +0200 | [diff] [blame] | 4516 | |
| 4517 | wl_resource_post_error(resource, WL_DISPLAY_ERROR_INVALID_OBJECT, |
| 4518 | "permission to bind desktop_shell denied"); |
Kristian Høgsberg | eae5de7 | 2012-04-11 22:42:15 -0400 | [diff] [blame] | 4519 | wl_resource_destroy(resource); |
Kristian Høgsberg | 7584062 | 2011-09-06 13:48:16 -0400 | [diff] [blame] | 4520 | } |
| 4521 | |
Pekka Paalanen | 6e16811 | 2011-11-24 11:34:05 +0200 | [diff] [blame] | 4522 | static void |
Giulio Camuffo | 184df50 | 2013-02-21 11:29:21 +0100 | [diff] [blame] | 4523 | 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] | 4524 | { |
Giulio Camuffo | 7fe01b1 | 2013-03-28 18:02:42 +0100 | [diff] [blame] | 4525 | struct desktop_shell *shell = surface->configure_private; |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 4526 | struct weston_view *view; |
Kristian Høgsberg | 1a73a63 | 2012-06-26 22:15:53 -0400 | [diff] [blame] | 4527 | |
Giulio Camuffo | 184df50 | 2013-02-21 11:29:21 +0100 | [diff] [blame] | 4528 | if (width == 0) |
| 4529 | return; |
| 4530 | |
Pekka Paalanen | 3a1d07d | 2012-12-20 14:02:13 +0200 | [diff] [blame] | 4531 | /* XXX: starting weston-screensaver beforehand does not work */ |
Kristian Høgsberg | 1a73a63 | 2012-06-26 22:15:53 -0400 | [diff] [blame] | 4532 | if (!shell->locked) |
| 4533 | return; |
| 4534 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 4535 | view = container_of(surface->views.next, struct weston_view, surface_link); |
| 4536 | center_on_output(view, surface->output); |
Kristian Høgsberg | 1a73a63 | 2012-06-26 22:15:53 -0400 | [diff] [blame] | 4537 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 4538 | if (wl_list_empty(&view->layer_link)) { |
| 4539 | wl_list_insert(shell->lock_layer.view_list.prev, |
| 4540 | &view->layer_link); |
| 4541 | weston_view_update_transform(view); |
Ander Conselvan de Oliveira | 859e885 | 2013-02-21 18:35:21 +0200 | [diff] [blame] | 4542 | wl_event_source_timer_update(shell->screensaver.timer, |
| 4543 | shell->screensaver.duration); |
Ander Conselvan de Oliveira | 19d10ef | 2013-02-21 18:35:20 +0200 | [diff] [blame] | 4544 | shell_fade(shell, FADE_IN); |
Kristian Høgsberg | 1a73a63 | 2012-06-26 22:15:53 -0400 | [diff] [blame] | 4545 | } |
| 4546 | } |
| 4547 | |
| 4548 | static void |
Pekka Paalanen | 6e16811 | 2011-11-24 11:34:05 +0200 | [diff] [blame] | 4549 | screensaver_set_surface(struct wl_client *client, |
| 4550 | struct wl_resource *resource, |
Kristian Høgsberg | 1a73a63 | 2012-06-26 22:15:53 -0400 | [diff] [blame] | 4551 | struct wl_resource *surface_resource, |
Pekka Paalanen | 6e16811 | 2011-11-24 11:34:05 +0200 | [diff] [blame] | 4552 | struct wl_resource *output_resource) |
| 4553 | { |
Jason Ekstrand | 651f00e | 2013-06-14 10:07:54 -0500 | [diff] [blame] | 4554 | struct desktop_shell *shell = wl_resource_get_user_data(resource); |
Jason Ekstrand | 0f2ef7e | 2013-06-14 10:07:53 -0500 | [diff] [blame] | 4555 | struct weston_surface *surface = |
| 4556 | wl_resource_get_user_data(surface_resource); |
Jason Ekstrand | a0d2dde | 2013-06-14 10:08:01 -0500 | [diff] [blame] | 4557 | struct weston_output *output = wl_resource_get_user_data(output_resource); |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 4558 | struct weston_view *view, *next; |
| 4559 | |
| 4560 | /* Make sure we only have one view */ |
| 4561 | wl_list_for_each_safe(view, next, &surface->views, surface_link) |
| 4562 | weston_view_destroy(view); |
| 4563 | weston_view_create(surface); |
Pekka Paalanen | 6e16811 | 2011-11-24 11:34:05 +0200 | [diff] [blame] | 4564 | |
Kristian Høgsberg | 1a73a63 | 2012-06-26 22:15:53 -0400 | [diff] [blame] | 4565 | surface->configure = screensaver_configure; |
Giulio Camuffo | 7fe01b1 | 2013-03-28 18:02:42 +0100 | [diff] [blame] | 4566 | surface->configure_private = shell; |
Pekka Paalanen | 77346a6 | 2011-11-30 16:26:35 +0200 | [diff] [blame] | 4567 | surface->output = output; |
Pekka Paalanen | 6e16811 | 2011-11-24 11:34:05 +0200 | [diff] [blame] | 4568 | } |
| 4569 | |
| 4570 | static const struct screensaver_interface screensaver_implementation = { |
| 4571 | screensaver_set_surface |
| 4572 | }; |
| 4573 | |
| 4574 | static void |
| 4575 | unbind_screensaver(struct wl_resource *resource) |
| 4576 | { |
Jason Ekstrand | 651f00e | 2013-06-14 10:07:54 -0500 | [diff] [blame] | 4577 | struct desktop_shell *shell = wl_resource_get_user_data(resource); |
Pekka Paalanen | 6e16811 | 2011-11-24 11:34:05 +0200 | [diff] [blame] | 4578 | |
Pekka Paalanen | 77346a6 | 2011-11-30 16:26:35 +0200 | [diff] [blame] | 4579 | shell->screensaver.binding = NULL; |
Pekka Paalanen | 6e16811 | 2011-11-24 11:34:05 +0200 | [diff] [blame] | 4580 | } |
| 4581 | |
| 4582 | static void |
| 4583 | bind_screensaver(struct wl_client *client, |
| 4584 | void *data, uint32_t version, uint32_t id) |
| 4585 | { |
Tiago Vignatti | be14326 | 2012-04-16 17:31:41 +0300 | [diff] [blame] | 4586 | struct desktop_shell *shell = data; |
Pekka Paalanen | 6e16811 | 2011-11-24 11:34:05 +0200 | [diff] [blame] | 4587 | struct wl_resource *resource; |
| 4588 | |
Jason Ekstrand | a85118c | 2013-06-27 20:17:02 -0500 | [diff] [blame] | 4589 | resource = wl_resource_create(client, &screensaver_interface, 1, id); |
Pekka Paalanen | 6e16811 | 2011-11-24 11:34:05 +0200 | [diff] [blame] | 4590 | |
Pekka Paalanen | 77346a6 | 2011-11-30 16:26:35 +0200 | [diff] [blame] | 4591 | if (shell->screensaver.binding == NULL) { |
Jason Ekstrand | a85118c | 2013-06-27 20:17:02 -0500 | [diff] [blame] | 4592 | wl_resource_set_implementation(resource, |
| 4593 | &screensaver_implementation, |
| 4594 | shell, unbind_screensaver); |
Pekka Paalanen | 77346a6 | 2011-11-30 16:26:35 +0200 | [diff] [blame] | 4595 | shell->screensaver.binding = resource; |
Pekka Paalanen | 6e16811 | 2011-11-24 11:34:05 +0200 | [diff] [blame] | 4596 | return; |
| 4597 | } |
| 4598 | |
| 4599 | wl_resource_post_error(resource, WL_DISPLAY_ERROR_INVALID_OBJECT, |
| 4600 | "interface object already bound"); |
Kristian Høgsberg | eae5de7 | 2012-04-11 22:42:15 -0400 | [diff] [blame] | 4601 | wl_resource_destroy(resource); |
Pekka Paalanen | 6e16811 | 2011-11-24 11:34:05 +0200 | [diff] [blame] | 4602 | } |
| 4603 | |
Jan Arne Petersen | 42feced | 2012-06-21 21:52:17 +0200 | [diff] [blame] | 4604 | static void |
Giulio Camuffo | 184df50 | 2013-02-21 11:29:21 +0100 | [diff] [blame] | 4605 | 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] | 4606 | { |
Jan Arne Petersen | 14da96b | 2013-04-18 16:47:28 +0200 | [diff] [blame] | 4607 | struct input_panel_surface *ip_surface = surface->configure_private; |
| 4608 | struct desktop_shell *shell = ip_surface->shell; |
Jan Arne Petersen | af7b6c9 | 2013-01-16 21:26:53 +0100 | [diff] [blame] | 4609 | float x, y; |
Jan Arne Petersen | 14da96b | 2013-04-18 16:47:28 +0200 | [diff] [blame] | 4610 | uint32_t show_surface = 0; |
Jan Arne Petersen | af7b6c9 | 2013-01-16 21:26:53 +0100 | [diff] [blame] | 4611 | |
Giulio Camuffo | 184df50 | 2013-02-21 11:29:21 +0100 | [diff] [blame] | 4612 | if (width == 0) |
| 4613 | return; |
| 4614 | |
Jan Arne Petersen | 14da96b | 2013-04-18 16:47:28 +0200 | [diff] [blame] | 4615 | if (!weston_surface_is_mapped(surface)) { |
| 4616 | if (!shell->showing_input_panels) |
| 4617 | return; |
| 4618 | |
Jan Arne Petersen | 14da96b | 2013-04-18 16:47:28 +0200 | [diff] [blame] | 4619 | show_surface = 1; |
| 4620 | } |
Jan Arne Petersen | af7b6c9 | 2013-01-16 21:26:53 +0100 | [diff] [blame] | 4621 | |
Jan Arne Petersen | 7cd29e1 | 2013-04-18 16:47:29 +0200 | [diff] [blame] | 4622 | 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] | 4623 | |
| 4624 | if (ip_surface->panel) { |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 4625 | x = get_default_view(shell->text_input.surface)->geometry.x + shell->text_input.cursor_rectangle.x2; |
| 4626 | 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] | 4627 | } else { |
Rob Bradford | bdeb5d2 | 2013-07-11 13:20:53 +0100 | [diff] [blame] | 4628 | x = ip_surface->output->x + (ip_surface->output->width - width) / 2; |
| 4629 | y = ip_surface->output->y + ip_surface->output->height - height; |
Jan Arne Petersen | 7cd29e1 | 2013-04-18 16:47:29 +0200 | [diff] [blame] | 4630 | } |
Kristian Høgsberg | 0636ac3 | 2012-06-27 10:22:15 -0400 | [diff] [blame] | 4631 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 4632 | weston_view_configure(ip_surface->view, x, y, width, height); |
Jan Arne Petersen | 14da96b | 2013-04-18 16:47:28 +0200 | [diff] [blame] | 4633 | |
| 4634 | if (show_surface) { |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 4635 | wl_list_insert(&shell->input_panel_layer.view_list, |
| 4636 | &ip_surface->view->layer_link); |
| 4637 | weston_view_update_transform(ip_surface->view); |
Jan Arne Petersen | 14da96b | 2013-04-18 16:47:28 +0200 | [diff] [blame] | 4638 | weston_surface_damage(surface); |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 4639 | 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] | 4640 | } |
Kristian Høgsberg | 0636ac3 | 2012-06-27 10:22:15 -0400 | [diff] [blame] | 4641 | } |
| 4642 | |
| 4643 | static void |
Jan Arne Petersen | ffbb20f | 2013-01-16 21:26:55 +0100 | [diff] [blame] | 4644 | destroy_input_panel_surface(struct input_panel_surface *input_panel_surface) |
Philipp Brüschweiler | 8801357 | 2012-08-06 13:44:42 +0200 | [diff] [blame] | 4645 | { |
Jason Ekstrand | 51e5b14 | 2013-06-14 10:07:58 -0500 | [diff] [blame] | 4646 | wl_signal_emit(&input_panel_surface->destroy_signal, input_panel_surface); |
| 4647 | |
Jan Arne Petersen | ffbb20f | 2013-01-16 21:26:55 +0100 | [diff] [blame] | 4648 | wl_list_remove(&input_panel_surface->surface_destroy_listener.link); |
Philipp Brüschweiler | 8801357 | 2012-08-06 13:44:42 +0200 | [diff] [blame] | 4649 | wl_list_remove(&input_panel_surface->link); |
| 4650 | |
Jan Arne Petersen | ffbb20f | 2013-01-16 21:26:55 +0100 | [diff] [blame] | 4651 | input_panel_surface->surface->configure = NULL; |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 4652 | weston_view_destroy(input_panel_surface->view); |
Jan Arne Petersen | ffbb20f | 2013-01-16 21:26:55 +0100 | [diff] [blame] | 4653 | |
Philipp Brüschweiler | 8801357 | 2012-08-06 13:44:42 +0200 | [diff] [blame] | 4654 | free(input_panel_surface); |
| 4655 | } |
| 4656 | |
Jan Arne Petersen | ffbb20f | 2013-01-16 21:26:55 +0100 | [diff] [blame] | 4657 | static struct input_panel_surface * |
| 4658 | get_input_panel_surface(struct weston_surface *surface) |
Jan Arne Petersen | 42feced | 2012-06-21 21:52:17 +0200 | [diff] [blame] | 4659 | { |
Jan Arne Petersen | ffbb20f | 2013-01-16 21:26:55 +0100 | [diff] [blame] | 4660 | if (surface->configure == input_panel_configure) { |
Giulio Camuffo | 7fe01b1 | 2013-03-28 18:02:42 +0100 | [diff] [blame] | 4661 | return surface->configure_private; |
Jan Arne Petersen | ffbb20f | 2013-01-16 21:26:55 +0100 | [diff] [blame] | 4662 | } else { |
| 4663 | return NULL; |
| 4664 | } |
| 4665 | } |
| 4666 | |
| 4667 | static void |
| 4668 | input_panel_handle_surface_destroy(struct wl_listener *listener, void *data) |
| 4669 | { |
| 4670 | struct input_panel_surface *ipsurface = container_of(listener, |
| 4671 | struct input_panel_surface, |
| 4672 | surface_destroy_listener); |
| 4673 | |
Jason Ekstrand | 51e5b14 | 2013-06-14 10:07:58 -0500 | [diff] [blame] | 4674 | if (ipsurface->resource) { |
| 4675 | wl_resource_destroy(ipsurface->resource); |
Jan Arne Petersen | ffbb20f | 2013-01-16 21:26:55 +0100 | [diff] [blame] | 4676 | } else { |
Jan Arne Petersen | ffbb20f | 2013-01-16 21:26:55 +0100 | [diff] [blame] | 4677 | destroy_input_panel_surface(ipsurface); |
| 4678 | } |
| 4679 | } |
Jason Ekstrand | 51e5b14 | 2013-06-14 10:07:58 -0500 | [diff] [blame] | 4680 | |
Jan Arne Petersen | ffbb20f | 2013-01-16 21:26:55 +0100 | [diff] [blame] | 4681 | static struct input_panel_surface * |
| 4682 | create_input_panel_surface(struct desktop_shell *shell, |
| 4683 | struct weston_surface *surface) |
| 4684 | { |
Philipp Brüschweiler | 8801357 | 2012-08-06 13:44:42 +0200 | [diff] [blame] | 4685 | struct input_panel_surface *input_panel_surface; |
Jan Arne Petersen | 42feced | 2012-06-21 21:52:17 +0200 | [diff] [blame] | 4686 | |
Jan Arne Petersen | ffbb20f | 2013-01-16 21:26:55 +0100 | [diff] [blame] | 4687 | input_panel_surface = calloc(1, sizeof *input_panel_surface); |
| 4688 | if (!input_panel_surface) |
| 4689 | return NULL; |
| 4690 | |
Kristian Høgsberg | 0636ac3 | 2012-06-27 10:22:15 -0400 | [diff] [blame] | 4691 | surface->configure = input_panel_configure; |
Giulio Camuffo | 7fe01b1 | 2013-03-28 18:02:42 +0100 | [diff] [blame] | 4692 | surface->configure_private = input_panel_surface; |
Philipp Brüschweiler | 8801357 | 2012-08-06 13:44:42 +0200 | [diff] [blame] | 4693 | |
Jan Arne Petersen | ffbb20f | 2013-01-16 21:26:55 +0100 | [diff] [blame] | 4694 | input_panel_surface->shell = shell; |
Philipp Brüschweiler | 8801357 | 2012-08-06 13:44:42 +0200 | [diff] [blame] | 4695 | |
| 4696 | input_panel_surface->surface = surface; |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 4697 | input_panel_surface->view = weston_view_create(surface); |
Philipp Brüschweiler | 8801357 | 2012-08-06 13:44:42 +0200 | [diff] [blame] | 4698 | |
Jason Ekstrand | 51e5b14 | 2013-06-14 10:07:58 -0500 | [diff] [blame] | 4699 | wl_signal_init(&input_panel_surface->destroy_signal); |
Jan Arne Petersen | ffbb20f | 2013-01-16 21:26:55 +0100 | [diff] [blame] | 4700 | input_panel_surface->surface_destroy_listener.notify = input_panel_handle_surface_destroy; |
Jason Ekstrand | 26ed73c | 2013-06-06 22:34:41 -0500 | [diff] [blame] | 4701 | wl_signal_add(&surface->destroy_signal, |
Jan Arne Petersen | ffbb20f | 2013-01-16 21:26:55 +0100 | [diff] [blame] | 4702 | &input_panel_surface->surface_destroy_listener); |
| 4703 | |
| 4704 | wl_list_init(&input_panel_surface->link); |
| 4705 | |
| 4706 | return input_panel_surface; |
| 4707 | } |
| 4708 | |
| 4709 | static void |
| 4710 | input_panel_surface_set_toplevel(struct wl_client *client, |
| 4711 | struct wl_resource *resource, |
Jan Arne Petersen | 7cd29e1 | 2013-04-18 16:47:29 +0200 | [diff] [blame] | 4712 | struct wl_resource *output_resource, |
Jan Arne Petersen | ffbb20f | 2013-01-16 21:26:55 +0100 | [diff] [blame] | 4713 | uint32_t position) |
| 4714 | { |
Jason Ekstrand | 51e5b14 | 2013-06-14 10:07:58 -0500 | [diff] [blame] | 4715 | struct input_panel_surface *input_panel_surface = |
| 4716 | wl_resource_get_user_data(resource); |
Jan Arne Petersen | ffbb20f | 2013-01-16 21:26:55 +0100 | [diff] [blame] | 4717 | struct desktop_shell *shell = input_panel_surface->shell; |
Philipp Brüschweiler | 8801357 | 2012-08-06 13:44:42 +0200 | [diff] [blame] | 4718 | |
| 4719 | wl_list_insert(&shell->input_panel.surfaces, |
| 4720 | &input_panel_surface->link); |
Jan Arne Petersen | 14da96b | 2013-04-18 16:47:28 +0200 | [diff] [blame] | 4721 | |
Jason Ekstrand | a0d2dde | 2013-06-14 10:08:01 -0500 | [diff] [blame] | 4722 | input_panel_surface->output = wl_resource_get_user_data(output_resource); |
Jan Arne Petersen | 14da96b | 2013-04-18 16:47:28 +0200 | [diff] [blame] | 4723 | input_panel_surface->panel = 0; |
| 4724 | } |
| 4725 | |
| 4726 | static void |
Jan Arne Petersen | 70d942b | 2013-04-18 16:47:37 +0200 | [diff] [blame] | 4727 | input_panel_surface_set_overlay_panel(struct wl_client *client, |
| 4728 | struct wl_resource *resource) |
Jan Arne Petersen | 14da96b | 2013-04-18 16:47:28 +0200 | [diff] [blame] | 4729 | { |
Jason Ekstrand | 51e5b14 | 2013-06-14 10:07:58 -0500 | [diff] [blame] | 4730 | struct input_panel_surface *input_panel_surface = |
| 4731 | wl_resource_get_user_data(resource); |
Jan Arne Petersen | 14da96b | 2013-04-18 16:47:28 +0200 | [diff] [blame] | 4732 | struct desktop_shell *shell = input_panel_surface->shell; |
| 4733 | |
| 4734 | wl_list_insert(&shell->input_panel.surfaces, |
| 4735 | &input_panel_surface->link); |
| 4736 | |
| 4737 | input_panel_surface->panel = 1; |
Jan Arne Petersen | 42feced | 2012-06-21 21:52:17 +0200 | [diff] [blame] | 4738 | } |
| 4739 | |
Jan Arne Petersen | cc75ec1 | 2013-04-18 16:47:39 +0200 | [diff] [blame] | 4740 | 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] | 4741 | input_panel_surface_set_toplevel, |
Jan Arne Petersen | 70d942b | 2013-04-18 16:47:37 +0200 | [diff] [blame] | 4742 | input_panel_surface_set_overlay_panel |
Jan Arne Petersen | ffbb20f | 2013-01-16 21:26:55 +0100 | [diff] [blame] | 4743 | }; |
| 4744 | |
| 4745 | static void |
| 4746 | destroy_input_panel_surface_resource(struct wl_resource *resource) |
| 4747 | { |
Jason Ekstrand | 51e5b14 | 2013-06-14 10:07:58 -0500 | [diff] [blame] | 4748 | struct input_panel_surface *ipsurf = |
| 4749 | wl_resource_get_user_data(resource); |
Jan Arne Petersen | ffbb20f | 2013-01-16 21:26:55 +0100 | [diff] [blame] | 4750 | |
| 4751 | destroy_input_panel_surface(ipsurf); |
| 4752 | } |
| 4753 | |
| 4754 | static void |
| 4755 | input_panel_get_input_panel_surface(struct wl_client *client, |
| 4756 | struct wl_resource *resource, |
| 4757 | uint32_t id, |
| 4758 | struct wl_resource *surface_resource) |
| 4759 | { |
Jason Ekstrand | 0f2ef7e | 2013-06-14 10:07:53 -0500 | [diff] [blame] | 4760 | struct weston_surface *surface = |
| 4761 | wl_resource_get_user_data(surface_resource); |
Jason Ekstrand | 651f00e | 2013-06-14 10:07:54 -0500 | [diff] [blame] | 4762 | struct desktop_shell *shell = wl_resource_get_user_data(resource); |
Jan Arne Petersen | ffbb20f | 2013-01-16 21:26:55 +0100 | [diff] [blame] | 4763 | struct input_panel_surface *ipsurf; |
| 4764 | |
| 4765 | if (get_input_panel_surface(surface)) { |
| 4766 | wl_resource_post_error(surface_resource, |
| 4767 | WL_DISPLAY_ERROR_INVALID_OBJECT, |
Jan Arne Petersen | cc75ec1 | 2013-04-18 16:47:39 +0200 | [diff] [blame] | 4768 | "wl_input_panel::get_input_panel_surface already requested"); |
Jan Arne Petersen | ffbb20f | 2013-01-16 21:26:55 +0100 | [diff] [blame] | 4769 | return; |
| 4770 | } |
| 4771 | |
| 4772 | ipsurf = create_input_panel_surface(shell, surface); |
| 4773 | if (!ipsurf) { |
| 4774 | wl_resource_post_error(surface_resource, |
| 4775 | WL_DISPLAY_ERROR_INVALID_OBJECT, |
| 4776 | "surface->configure already set"); |
| 4777 | return; |
| 4778 | } |
| 4779 | |
Jason Ekstrand | a85118c | 2013-06-27 20:17:02 -0500 | [diff] [blame] | 4780 | ipsurf->resource = |
| 4781 | wl_resource_create(client, |
| 4782 | &wl_input_panel_surface_interface, 1, id); |
| 4783 | wl_resource_set_implementation(ipsurf->resource, |
| 4784 | &input_panel_surface_implementation, |
| 4785 | ipsurf, |
| 4786 | destroy_input_panel_surface_resource); |
Jan Arne Petersen | ffbb20f | 2013-01-16 21:26:55 +0100 | [diff] [blame] | 4787 | } |
| 4788 | |
Jan Arne Petersen | cc75ec1 | 2013-04-18 16:47:39 +0200 | [diff] [blame] | 4789 | static const struct wl_input_panel_interface input_panel_implementation = { |
Jan Arne Petersen | ffbb20f | 2013-01-16 21:26:55 +0100 | [diff] [blame] | 4790 | input_panel_get_input_panel_surface |
Jan Arne Petersen | 42feced | 2012-06-21 21:52:17 +0200 | [diff] [blame] | 4791 | }; |
| 4792 | |
| 4793 | static void |
| 4794 | unbind_input_panel(struct wl_resource *resource) |
| 4795 | { |
Jason Ekstrand | 651f00e | 2013-06-14 10:07:54 -0500 | [diff] [blame] | 4796 | struct desktop_shell *shell = wl_resource_get_user_data(resource); |
Jan Arne Petersen | 42feced | 2012-06-21 21:52:17 +0200 | [diff] [blame] | 4797 | |
| 4798 | shell->input_panel.binding = NULL; |
Jan Arne Petersen | 42feced | 2012-06-21 21:52:17 +0200 | [diff] [blame] | 4799 | } |
| 4800 | |
| 4801 | static void |
| 4802 | bind_input_panel(struct wl_client *client, |
| 4803 | void *data, uint32_t version, uint32_t id) |
| 4804 | { |
| 4805 | struct desktop_shell *shell = data; |
| 4806 | struct wl_resource *resource; |
| 4807 | |
Jason Ekstrand | a85118c | 2013-06-27 20:17:02 -0500 | [diff] [blame] | 4808 | resource = wl_resource_create(client, |
| 4809 | &wl_input_panel_interface, 1, id); |
Jan Arne Petersen | 42feced | 2012-06-21 21:52:17 +0200 | [diff] [blame] | 4810 | |
| 4811 | if (shell->input_panel.binding == NULL) { |
Jason Ekstrand | a85118c | 2013-06-27 20:17:02 -0500 | [diff] [blame] | 4812 | wl_resource_set_implementation(resource, |
| 4813 | &input_panel_implementation, |
| 4814 | shell, unbind_input_panel); |
Jan Arne Petersen | 42feced | 2012-06-21 21:52:17 +0200 | [diff] [blame] | 4815 | shell->input_panel.binding = resource; |
| 4816 | return; |
| 4817 | } |
| 4818 | |
| 4819 | wl_resource_post_error(resource, WL_DISPLAY_ERROR_INVALID_OBJECT, |
| 4820 | "interface object already bound"); |
| 4821 | wl_resource_destroy(resource); |
| 4822 | } |
| 4823 | |
Kristian Høgsberg | 0704539 | 2012-02-19 18:52:44 -0500 | [diff] [blame] | 4824 | struct switcher { |
Tiago Vignatti | be14326 | 2012-04-16 17:31:41 +0300 | [diff] [blame] | 4825 | struct desktop_shell *shell; |
Kristian Høgsberg | 0704539 | 2012-02-19 18:52:44 -0500 | [diff] [blame] | 4826 | struct weston_surface *current; |
| 4827 | struct wl_listener listener; |
Kristian Høgsberg | 29139d4 | 2013-04-18 15:25:39 -0400 | [diff] [blame] | 4828 | struct weston_keyboard_grab grab; |
Kristian Høgsberg | 0704539 | 2012-02-19 18:52:44 -0500 | [diff] [blame] | 4829 | }; |
| 4830 | |
| 4831 | static void |
| 4832 | switcher_next(struct switcher *switcher) |
| 4833 | { |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 4834 | struct weston_view *view; |
Kristian Høgsberg | 0704539 | 2012-02-19 18:52:44 -0500 | [diff] [blame] | 4835 | struct weston_surface *first = NULL, *prev = NULL, *next = NULL; |
Kristian Høgsberg | 32e5686 | 2012-04-02 22:18:58 -0400 | [diff] [blame] | 4836 | struct shell_surface *shsurf; |
Kristian Høgsberg | b0d8e77 | 2012-06-18 16:34:58 -0400 | [diff] [blame] | 4837 | struct workspace *ws = get_current_workspace(switcher->shell); |
Kristian Høgsberg | 0704539 | 2012-02-19 18:52:44 -0500 | [diff] [blame] | 4838 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 4839 | wl_list_for_each(view, &ws->layer.view_list, layer_link) { |
| 4840 | switch (get_shell_surface_type(view->surface)) { |
Kristian Høgsberg | 0704539 | 2012-02-19 18:52:44 -0500 | [diff] [blame] | 4841 | case SHELL_SURFACE_TOPLEVEL: |
| 4842 | case SHELL_SURFACE_FULLSCREEN: |
| 4843 | case SHELL_SURFACE_MAXIMIZED: |
| 4844 | if (first == NULL) |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 4845 | first = view->surface; |
Kristian Høgsberg | 0704539 | 2012-02-19 18:52:44 -0500 | [diff] [blame] | 4846 | if (prev == switcher->current) |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 4847 | next = view->surface; |
| 4848 | prev = view->surface; |
| 4849 | view->alpha = 0.25; |
| 4850 | weston_view_geometry_dirty(view); |
| 4851 | weston_surface_damage(view->surface); |
Kristian Høgsberg | 0704539 | 2012-02-19 18:52:44 -0500 | [diff] [blame] | 4852 | break; |
| 4853 | default: |
| 4854 | break; |
| 4855 | } |
Alex Wu | 1659daa | 2012-04-01 20:13:09 +0800 | [diff] [blame] | 4856 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 4857 | if (is_black_surface(view->surface, NULL)) { |
| 4858 | view->alpha = 0.25; |
| 4859 | weston_view_geometry_dirty(view); |
| 4860 | weston_surface_damage(view->surface); |
Alex Wu | 1659daa | 2012-04-01 20:13:09 +0800 | [diff] [blame] | 4861 | } |
Kristian Høgsberg | 0704539 | 2012-02-19 18:52:44 -0500 | [diff] [blame] | 4862 | } |
| 4863 | |
| 4864 | if (next == NULL) |
| 4865 | next = first; |
| 4866 | |
Alex Wu | 07b2606 | 2012-03-12 16:06:01 +0800 | [diff] [blame] | 4867 | if (next == NULL) |
| 4868 | return; |
| 4869 | |
Kristian Høgsberg | 0704539 | 2012-02-19 18:52:44 -0500 | [diff] [blame] | 4870 | wl_list_remove(&switcher->listener.link); |
Jason Ekstrand | 26ed73c | 2013-06-06 22:34:41 -0500 | [diff] [blame] | 4871 | wl_signal_add(&next->destroy_signal, &switcher->listener); |
Kristian Høgsberg | 0704539 | 2012-02-19 18:52:44 -0500 | [diff] [blame] | 4872 | |
| 4873 | switcher->current = next; |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 4874 | wl_list_for_each(view, &next->views, surface_link) |
| 4875 | view->alpha = 1.0; |
Alex Wu | 1659daa | 2012-04-01 20:13:09 +0800 | [diff] [blame] | 4876 | |
Kristian Høgsberg | 32e5686 | 2012-04-02 22:18:58 -0400 | [diff] [blame] | 4877 | shsurf = get_shell_surface(switcher->current); |
| 4878 | if (shsurf && shsurf->type ==SHELL_SURFACE_FULLSCREEN) |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 4879 | shsurf->fullscreen.black_view->alpha = 1.0; |
Kristian Høgsberg | 0704539 | 2012-02-19 18:52:44 -0500 | [diff] [blame] | 4880 | } |
| 4881 | |
| 4882 | static void |
Kristian Høgsberg | 27e3052 | 2012-04-11 23:18:23 -0400 | [diff] [blame] | 4883 | switcher_handle_surface_destroy(struct wl_listener *listener, void *data) |
Kristian Høgsberg | 0704539 | 2012-02-19 18:52:44 -0500 | [diff] [blame] | 4884 | { |
| 4885 | struct switcher *switcher = |
| 4886 | container_of(listener, struct switcher, listener); |
| 4887 | |
| 4888 | switcher_next(switcher); |
| 4889 | } |
| 4890 | |
| 4891 | static void |
Daniel Stone | 351eb61 | 2012-05-31 15:27:47 -0400 | [diff] [blame] | 4892 | switcher_destroy(struct switcher *switcher) |
Kristian Høgsberg | 0704539 | 2012-02-19 18:52:44 -0500 | [diff] [blame] | 4893 | { |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 4894 | struct weston_view *view; |
Kristian Høgsberg | 29139d4 | 2013-04-18 15:25:39 -0400 | [diff] [blame] | 4895 | struct weston_keyboard *keyboard = switcher->grab.keyboard; |
Kristian Høgsberg | b0d8e77 | 2012-06-18 16:34:58 -0400 | [diff] [blame] | 4896 | struct workspace *ws = get_current_workspace(switcher->shell); |
Kristian Høgsberg | 0704539 | 2012-02-19 18:52:44 -0500 | [diff] [blame] | 4897 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 4898 | 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] | 4899 | if (is_focus_view(view)) |
| 4900 | continue; |
| 4901 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 4902 | view->alpha = 1.0; |
| 4903 | weston_surface_damage(view->surface); |
Kristian Høgsberg | 0704539 | 2012-02-19 18:52:44 -0500 | [diff] [blame] | 4904 | } |
| 4905 | |
Alex Wu | 07b2606 | 2012-03-12 16:06:01 +0800 | [diff] [blame] | 4906 | if (switcher->current) |
Daniel Stone | 37816df | 2012-05-16 18:45:18 +0100 | [diff] [blame] | 4907 | activate(switcher->shell, switcher->current, |
| 4908 | (struct weston_seat *) keyboard->seat); |
Kristian Høgsberg | 0704539 | 2012-02-19 18:52:44 -0500 | [diff] [blame] | 4909 | wl_list_remove(&switcher->listener.link); |
Kristian Høgsberg | 29139d4 | 2013-04-18 15:25:39 -0400 | [diff] [blame] | 4910 | weston_keyboard_end_grab(keyboard); |
| 4911 | if (keyboard->input_method_resource) |
| 4912 | keyboard->grab = &keyboard->input_method_grab; |
Kristian Høgsberg | 0704539 | 2012-02-19 18:52:44 -0500 | [diff] [blame] | 4913 | free(switcher); |
| 4914 | } |
| 4915 | |
| 4916 | static void |
Kristian Høgsberg | 29139d4 | 2013-04-18 15:25:39 -0400 | [diff] [blame] | 4917 | switcher_key(struct weston_keyboard_grab *grab, |
Daniel Stone | c9785ea | 2012-05-30 16:31:52 +0100 | [diff] [blame] | 4918 | uint32_t time, uint32_t key, uint32_t state_w) |
Kristian Høgsberg | 0704539 | 2012-02-19 18:52:44 -0500 | [diff] [blame] | 4919 | { |
| 4920 | struct switcher *switcher = container_of(grab, struct switcher, grab); |
Daniel Stone | c9785ea | 2012-05-30 16:31:52 +0100 | [diff] [blame] | 4921 | enum wl_keyboard_key_state state = state_w; |
Daniel Stone | 351eb61 | 2012-05-31 15:27:47 -0400 | [diff] [blame] | 4922 | |
Daniel Stone | c9785ea | 2012-05-30 16:31:52 +0100 | [diff] [blame] | 4923 | if (key == KEY_TAB && state == WL_KEYBOARD_KEY_STATE_PRESSED) |
Daniel Stone | 351eb61 | 2012-05-31 15:27:47 -0400 | [diff] [blame] | 4924 | switcher_next(switcher); |
| 4925 | } |
| 4926 | |
| 4927 | static void |
Kristian Høgsberg | 29139d4 | 2013-04-18 15:25:39 -0400 | [diff] [blame] | 4928 | switcher_modifier(struct weston_keyboard_grab *grab, uint32_t serial, |
Daniel Stone | 351eb61 | 2012-05-31 15:27:47 -0400 | [diff] [blame] | 4929 | uint32_t mods_depressed, uint32_t mods_latched, |
| 4930 | uint32_t mods_locked, uint32_t group) |
| 4931 | { |
| 4932 | struct switcher *switcher = container_of(grab, struct switcher, grab); |
Daniel Stone | 37816df | 2012-05-16 18:45:18 +0100 | [diff] [blame] | 4933 | struct weston_seat *seat = (struct weston_seat *) grab->keyboard->seat; |
Kristian Høgsberg | 0704539 | 2012-02-19 18:52:44 -0500 | [diff] [blame] | 4934 | |
Daniel Stone | 351eb61 | 2012-05-31 15:27:47 -0400 | [diff] [blame] | 4935 | if ((seat->modifier_state & switcher->shell->binding_modifier) == 0) |
| 4936 | switcher_destroy(switcher); |
Kristian Høgsberg | b71302e | 2012-05-10 12:28:35 -0400 | [diff] [blame] | 4937 | } |
Kristian Høgsberg | 0704539 | 2012-02-19 18:52:44 -0500 | [diff] [blame] | 4938 | |
Jonas Ådahl | 1ea343e | 2013-10-25 23:18:05 +0200 | [diff] [blame] | 4939 | static void |
| 4940 | switcher_cancel(struct weston_keyboard_grab *grab) |
| 4941 | { |
| 4942 | struct switcher *switcher = container_of(grab, struct switcher, grab); |
| 4943 | |
| 4944 | switcher_destroy(switcher); |
| 4945 | } |
| 4946 | |
Kristian Høgsberg | 29139d4 | 2013-04-18 15:25:39 -0400 | [diff] [blame] | 4947 | static const struct weston_keyboard_grab_interface switcher_grab = { |
Daniel Stone | 351eb61 | 2012-05-31 15:27:47 -0400 | [diff] [blame] | 4948 | switcher_key, |
| 4949 | switcher_modifier, |
Jonas Ådahl | 1ea343e | 2013-10-25 23:18:05 +0200 | [diff] [blame] | 4950 | switcher_cancel, |
Kristian Høgsberg | 0704539 | 2012-02-19 18:52:44 -0500 | [diff] [blame] | 4951 | }; |
| 4952 | |
| 4953 | static void |
Kristian Høgsberg | e314875 | 2013-05-06 23:19:49 -0400 | [diff] [blame] | 4954 | switcher_binding(struct weston_seat *seat, uint32_t time, uint32_t key, |
Daniel Stone | 325fc2d | 2012-05-30 16:31:58 +0100 | [diff] [blame] | 4955 | void *data) |
Kristian Høgsberg | 0704539 | 2012-02-19 18:52:44 -0500 | [diff] [blame] | 4956 | { |
Tiago Vignatti | be14326 | 2012-04-16 17:31:41 +0300 | [diff] [blame] | 4957 | struct desktop_shell *shell = data; |
Kristian Høgsberg | 0704539 | 2012-02-19 18:52:44 -0500 | [diff] [blame] | 4958 | struct switcher *switcher; |
| 4959 | |
| 4960 | switcher = malloc(sizeof *switcher); |
Kristian Høgsberg | 02e79dc | 2012-04-12 09:55:26 -0400 | [diff] [blame] | 4961 | switcher->shell = shell; |
Kristian Høgsberg | 0704539 | 2012-02-19 18:52:44 -0500 | [diff] [blame] | 4962 | switcher->current = NULL; |
Kristian Høgsberg | 27e3052 | 2012-04-11 23:18:23 -0400 | [diff] [blame] | 4963 | switcher->listener.notify = switcher_handle_surface_destroy; |
Kristian Høgsberg | 0704539 | 2012-02-19 18:52:44 -0500 | [diff] [blame] | 4964 | wl_list_init(&switcher->listener.link); |
| 4965 | |
Alexander Larsson | f82b6ca | 2013-05-28 16:23:39 +0200 | [diff] [blame] | 4966 | restore_all_output_modes(shell->compositor); |
Kristian Høgsberg | b0d8e77 | 2012-06-18 16:34:58 -0400 | [diff] [blame] | 4967 | lower_fullscreen_layer(switcher->shell); |
Kristian Høgsberg | 0704539 | 2012-02-19 18:52:44 -0500 | [diff] [blame] | 4968 | switcher->grab.interface = &switcher_grab; |
Kristian Høgsberg | 29139d4 | 2013-04-18 15:25:39 -0400 | [diff] [blame] | 4969 | weston_keyboard_start_grab(seat->keyboard, &switcher->grab); |
| 4970 | weston_keyboard_set_focus(seat->keyboard, NULL); |
Kristian Høgsberg | 0704539 | 2012-02-19 18:52:44 -0500 | [diff] [blame] | 4971 | switcher_next(switcher); |
| 4972 | } |
| 4973 | |
Daniel Stone | df8133b | 2013-11-19 11:37:14 +0100 | [diff] [blame] | 4974 | struct exposay_surface { |
| 4975 | struct desktop_shell *shell; |
| 4976 | struct weston_surface *surface; |
| 4977 | struct weston_view *view; |
| 4978 | struct wl_list link; |
| 4979 | |
| 4980 | int x; |
| 4981 | int y; |
| 4982 | int width; |
| 4983 | int height; |
| 4984 | double scale; |
| 4985 | |
| 4986 | int row; |
| 4987 | int column; |
| 4988 | |
| 4989 | /* The animations only apply a transformation for their own lifetime, |
| 4990 | * and don't have an option to indefinitely maintain the |
| 4991 | * transformation in a steady state - so, we apply our own once the |
| 4992 | * animation has finished. */ |
| 4993 | struct weston_transform transform; |
| 4994 | }; |
| 4995 | |
| 4996 | static void exposay_set_state(struct desktop_shell *shell, |
| 4997 | enum exposay_target_state state, |
| 4998 | struct weston_seat *seat); |
| 4999 | static void exposay_check_state(struct desktop_shell *shell); |
| 5000 | |
| 5001 | static void |
| 5002 | exposay_in_flight_inc(struct desktop_shell *shell) |
| 5003 | { |
| 5004 | shell->exposay.in_flight++; |
| 5005 | } |
| 5006 | |
| 5007 | static void |
| 5008 | exposay_in_flight_dec(struct desktop_shell *shell) |
| 5009 | { |
| 5010 | if (--shell->exposay.in_flight > 0) |
| 5011 | return; |
| 5012 | |
| 5013 | exposay_check_state(shell); |
| 5014 | } |
| 5015 | |
| 5016 | static void |
| 5017 | exposay_animate_in_done(struct weston_view_animation *animation, void *data) |
| 5018 | { |
| 5019 | struct exposay_surface *esurface = data; |
| 5020 | |
| 5021 | wl_list_insert(&esurface->view->geometry.transformation_list, |
| 5022 | &esurface->transform.link); |
| 5023 | weston_matrix_init(&esurface->transform.matrix); |
| 5024 | weston_matrix_scale(&esurface->transform.matrix, |
| 5025 | esurface->scale, esurface->scale, 1.0f); |
| 5026 | weston_matrix_translate(&esurface->transform.matrix, |
| 5027 | esurface->x - esurface->view->geometry.x, |
| 5028 | esurface->y - esurface->view->geometry.y, |
| 5029 | 0); |
| 5030 | |
| 5031 | weston_view_geometry_dirty(esurface->view); |
| 5032 | weston_compositor_schedule_repaint(esurface->view->surface->compositor); |
| 5033 | |
| 5034 | exposay_in_flight_dec(esurface->shell); |
| 5035 | } |
| 5036 | |
| 5037 | static void |
| 5038 | exposay_animate_in(struct exposay_surface *esurface) |
| 5039 | { |
| 5040 | exposay_in_flight_inc(esurface->shell); |
| 5041 | |
| 5042 | weston_move_scale_run(esurface->view, |
| 5043 | esurface->x - esurface->view->geometry.x, |
| 5044 | esurface->y - esurface->view->geometry.y, |
| 5045 | 1.0, esurface->scale, 0, |
| 5046 | exposay_animate_in_done, esurface); |
| 5047 | } |
| 5048 | |
| 5049 | static void |
| 5050 | exposay_animate_out_done(struct weston_view_animation *animation, void *data) |
| 5051 | { |
| 5052 | struct exposay_surface *esurface = data; |
| 5053 | struct desktop_shell *shell = esurface->shell; |
| 5054 | |
| 5055 | wl_list_remove(&esurface->link); |
| 5056 | free(esurface); |
| 5057 | |
| 5058 | exposay_in_flight_dec(shell); |
| 5059 | } |
| 5060 | |
| 5061 | static void |
| 5062 | exposay_animate_out(struct exposay_surface *esurface) |
| 5063 | { |
| 5064 | exposay_in_flight_inc(esurface->shell); |
| 5065 | |
| 5066 | /* Remove the static transformation set up by |
| 5067 | * exposay_transform_in_done(). */ |
| 5068 | wl_list_remove(&esurface->transform.link); |
| 5069 | weston_view_geometry_dirty(esurface->view); |
| 5070 | |
| 5071 | weston_move_scale_run(esurface->view, |
| 5072 | esurface->x - esurface->view->geometry.x, |
| 5073 | esurface->y - esurface->view->geometry.y, |
| 5074 | 1.0, esurface->scale, 1, |
| 5075 | exposay_animate_out_done, esurface); |
| 5076 | } |
| 5077 | |
| 5078 | static void |
| 5079 | exposay_highlight_surface(struct desktop_shell *shell, |
| 5080 | struct exposay_surface *esurface) |
| 5081 | { |
| 5082 | struct weston_view *view = NULL; |
| 5083 | |
| 5084 | if (esurface) { |
| 5085 | shell->exposay.row_current = esurface->row; |
| 5086 | shell->exposay.column_current = esurface->column; |
| 5087 | view = esurface->view; |
| 5088 | } |
| 5089 | |
Emilio Pozuelo Monfort | 5c22ce6 | 2013-11-19 11:37:18 +0100 | [diff] [blame] | 5090 | activate(shell, view->surface, shell->exposay.seat); |
Daniel Stone | df8133b | 2013-11-19 11:37:14 +0100 | [diff] [blame] | 5091 | shell->exposay.focus_current = view; |
| 5092 | } |
| 5093 | |
| 5094 | static int |
| 5095 | exposay_is_animating(struct desktop_shell *shell) |
| 5096 | { |
| 5097 | if (shell->exposay.state_cur == EXPOSAY_LAYOUT_INACTIVE || |
| 5098 | shell->exposay.state_cur == EXPOSAY_LAYOUT_OVERVIEW) |
| 5099 | return 0; |
| 5100 | |
| 5101 | return (shell->exposay.in_flight > 0); |
| 5102 | } |
| 5103 | |
| 5104 | static void |
| 5105 | exposay_pick(struct desktop_shell *shell, int x, int y) |
| 5106 | { |
| 5107 | struct exposay_surface *esurface; |
| 5108 | |
| 5109 | if (exposay_is_animating(shell)) |
| 5110 | return; |
| 5111 | |
| 5112 | wl_list_for_each(esurface, &shell->exposay.surface_list, link) { |
| 5113 | if (x < esurface->x || x > esurface->x + esurface->width) |
| 5114 | continue; |
| 5115 | if (y < esurface->y || y > esurface->y + esurface->height) |
| 5116 | continue; |
| 5117 | |
| 5118 | exposay_highlight_surface(shell, esurface); |
| 5119 | return; |
| 5120 | } |
| 5121 | } |
| 5122 | |
| 5123 | /* Pretty lame layout for now; just tries to make a square. Should take |
| 5124 | * aspect ratio into account really. Also needs to be notified of surface |
| 5125 | * addition and removal and adjust layout/animate accordingly. */ |
| 5126 | static enum exposay_layout_state |
| 5127 | exposay_layout(struct desktop_shell *shell) |
| 5128 | { |
| 5129 | struct workspace *workspace = shell->exposay.workspace; |
| 5130 | struct weston_compositor *compositor = shell->compositor; |
| 5131 | struct weston_output *output = get_default_output(compositor); |
| 5132 | struct weston_view *view; |
| 5133 | struct exposay_surface *esurface; |
| 5134 | int w, h; |
| 5135 | int i; |
| 5136 | int last_row_removed = 0; |
| 5137 | |
| 5138 | wl_list_init(&shell->exposay.surface_list); |
| 5139 | |
| 5140 | shell->exposay.num_surfaces = 0; |
| 5141 | wl_list_for_each(view, &workspace->layer.view_list, layer_link) { |
| 5142 | if (!get_shell_surface(view->surface)) |
| 5143 | continue; |
| 5144 | shell->exposay.num_surfaces++; |
| 5145 | } |
| 5146 | |
| 5147 | if (shell->exposay.num_surfaces == 0) { |
| 5148 | shell->exposay.grid_size = 0; |
| 5149 | shell->exposay.hpadding_outer = 0; |
| 5150 | shell->exposay.vpadding_outer = 0; |
| 5151 | shell->exposay.padding_inner = 0; |
| 5152 | shell->exposay.surface_size = 0; |
| 5153 | return EXPOSAY_LAYOUT_OVERVIEW; |
| 5154 | } |
| 5155 | |
| 5156 | /* Lay the grid out as square as possible, losing surfaces from the |
| 5157 | * bottom row if required. Start with fixed padding of a 10% margin |
| 5158 | * around the outside and 80px internal padding between surfaces, and |
| 5159 | * maximise the area made available to surfaces after this, but only |
| 5160 | * to a maximum of 1/3rd the total output size. |
| 5161 | * |
| 5162 | * If we can't make a square grid, add one extra row at the bottom |
| 5163 | * which will have a smaller number of columns. |
| 5164 | * |
| 5165 | * XXX: Surely there has to be a better way to express this maths, |
| 5166 | * right?! |
| 5167 | */ |
| 5168 | shell->exposay.grid_size = floor(sqrtf(shell->exposay.num_surfaces)); |
| 5169 | if (pow(shell->exposay.grid_size, 2) != shell->exposay.num_surfaces) |
| 5170 | shell->exposay.grid_size++; |
| 5171 | last_row_removed = pow(shell->exposay.grid_size, 2) - shell->exposay.num_surfaces; |
| 5172 | |
| 5173 | shell->exposay.hpadding_outer = (output->width / 10); |
| 5174 | shell->exposay.vpadding_outer = (output->height / 10); |
| 5175 | shell->exposay.padding_inner = 80; |
| 5176 | |
| 5177 | w = output->width - (shell->exposay.hpadding_outer * 2); |
| 5178 | w -= shell->exposay.padding_inner * (shell->exposay.grid_size - 1); |
| 5179 | w /= shell->exposay.grid_size; |
| 5180 | |
| 5181 | h = output->height - (shell->exposay.vpadding_outer * 2); |
| 5182 | h -= shell->exposay.padding_inner * (shell->exposay.grid_size - 1); |
| 5183 | h /= shell->exposay.grid_size; |
| 5184 | |
| 5185 | shell->exposay.surface_size = (w < h) ? w : h; |
| 5186 | if (shell->exposay.surface_size > (output->width / 2)) |
| 5187 | shell->exposay.surface_size = output->width / 2; |
| 5188 | if (shell->exposay.surface_size > (output->height / 2)) |
| 5189 | shell->exposay.surface_size = output->height / 2; |
| 5190 | |
| 5191 | i = 0; |
| 5192 | wl_list_for_each(view, &workspace->layer.view_list, layer_link) { |
| 5193 | int pad; |
| 5194 | |
| 5195 | pad = shell->exposay.surface_size + shell->exposay.padding_inner; |
| 5196 | |
| 5197 | if (!get_shell_surface(view->surface)) |
| 5198 | continue; |
| 5199 | |
| 5200 | esurface = malloc(sizeof(*esurface)); |
| 5201 | if (!esurface) { |
| 5202 | exposay_set_state(shell, EXPOSAY_TARGET_CANCEL, |
| 5203 | shell->exposay.seat); |
| 5204 | break; |
| 5205 | } |
| 5206 | |
| 5207 | wl_list_insert(&shell->exposay.surface_list, &esurface->link); |
| 5208 | esurface->shell = shell; |
| 5209 | esurface->view = view; |
| 5210 | |
| 5211 | esurface->row = i / shell->exposay.grid_size; |
| 5212 | esurface->column = i % shell->exposay.grid_size; |
| 5213 | |
| 5214 | esurface->x = shell->exposay.hpadding_outer; |
| 5215 | esurface->x += pad * esurface->column; |
| 5216 | esurface->y = shell->exposay.vpadding_outer; |
| 5217 | esurface->y += pad * esurface->row; |
| 5218 | |
| 5219 | if (esurface->row == shell->exposay.grid_size - 1) |
| 5220 | esurface->x += (shell->exposay.surface_size + shell->exposay.padding_inner) * last_row_removed / 2; |
| 5221 | |
| 5222 | if (view->geometry.width > view->geometry.height) |
| 5223 | esurface->scale = shell->exposay.surface_size / (float) view->geometry.width; |
| 5224 | else |
| 5225 | esurface->scale = shell->exposay.surface_size / (float) view->geometry.height; |
| 5226 | esurface->width = view->geometry.width * esurface->scale; |
| 5227 | esurface->height = view->geometry.height * esurface->scale; |
| 5228 | |
| 5229 | if (shell->exposay.focus_current == esurface->view) |
| 5230 | exposay_highlight_surface(shell, esurface); |
| 5231 | |
| 5232 | exposay_animate_in(esurface); |
| 5233 | |
| 5234 | i++; |
| 5235 | } |
| 5236 | |
| 5237 | weston_compositor_schedule_repaint(shell->compositor); |
| 5238 | |
| 5239 | return EXPOSAY_LAYOUT_ANIMATE_TO_OVERVIEW; |
| 5240 | } |
| 5241 | |
| 5242 | static void |
Emilio Pozuelo Monfort | 17467d6 | 2013-11-19 12:14:53 +0100 | [diff] [blame] | 5243 | exposay_motion(struct weston_pointer_grab *grab, uint32_t time, |
| 5244 | wl_fixed_t x, wl_fixed_t y) |
Daniel Stone | df8133b | 2013-11-19 11:37:14 +0100 | [diff] [blame] | 5245 | { |
| 5246 | struct desktop_shell *shell = |
| 5247 | container_of(grab, struct desktop_shell, exposay.grab_ptr); |
| 5248 | |
Emilio Pozuelo Monfort | 17467d6 | 2013-11-19 12:14:53 +0100 | [diff] [blame] | 5249 | weston_pointer_move(grab->pointer, x, y); |
| 5250 | |
Daniel Stone | df8133b | 2013-11-19 11:37:14 +0100 | [diff] [blame] | 5251 | exposay_pick(shell, |
| 5252 | wl_fixed_to_int(grab->pointer->x), |
| 5253 | wl_fixed_to_int(grab->pointer->y)); |
| 5254 | } |
| 5255 | |
| 5256 | static void |
| 5257 | exposay_button(struct weston_pointer_grab *grab, uint32_t time, uint32_t button, |
| 5258 | uint32_t state_w) |
| 5259 | { |
| 5260 | struct desktop_shell *shell = |
| 5261 | container_of(grab, struct desktop_shell, exposay.grab_ptr); |
| 5262 | struct weston_seat *seat = grab->pointer->seat; |
| 5263 | enum wl_pointer_button_state state = state_w; |
| 5264 | |
| 5265 | if (button != BTN_LEFT) |
| 5266 | return; |
| 5267 | |
| 5268 | /* Store the surface we clicked on, and don't do anything if we end up |
| 5269 | * releasing on a different surface. */ |
| 5270 | if (state == WL_POINTER_BUTTON_STATE_PRESSED) { |
| 5271 | shell->exposay.clicked = shell->exposay.focus_current; |
| 5272 | return; |
| 5273 | } |
| 5274 | |
| 5275 | if (shell->exposay.focus_current == shell->exposay.clicked) |
| 5276 | exposay_set_state(shell, EXPOSAY_TARGET_SWITCH, seat); |
| 5277 | else |
| 5278 | shell->exposay.clicked = NULL; |
| 5279 | } |
| 5280 | |
Emilio Pozuelo Monfort | 234c524 | 2013-11-26 13:32:08 +0100 | [diff] [blame] | 5281 | static void |
| 5282 | exposay_pointer_grab_cancel(struct weston_pointer_grab *grab) |
| 5283 | { |
| 5284 | struct desktop_shell *shell = |
| 5285 | container_of(grab, struct desktop_shell, exposay.grab_ptr); |
| 5286 | |
| 5287 | exposay_set_state(shell, EXPOSAY_TARGET_CANCEL, shell->exposay.seat); |
| 5288 | } |
| 5289 | |
Daniel Stone | df8133b | 2013-11-19 11:37:14 +0100 | [diff] [blame] | 5290 | static const struct weston_pointer_grab_interface exposay_ptr_grab = { |
| 5291 | noop_grab_focus, |
| 5292 | exposay_motion, |
| 5293 | exposay_button, |
Emilio Pozuelo Monfort | 234c524 | 2013-11-26 13:32:08 +0100 | [diff] [blame] | 5294 | exposay_pointer_grab_cancel, |
Daniel Stone | df8133b | 2013-11-19 11:37:14 +0100 | [diff] [blame] | 5295 | }; |
| 5296 | |
| 5297 | static int |
| 5298 | exposay_maybe_move(struct desktop_shell *shell, int row, int column) |
| 5299 | { |
| 5300 | struct exposay_surface *esurface; |
| 5301 | |
| 5302 | wl_list_for_each(esurface, &shell->exposay.surface_list, link) { |
| 5303 | if (esurface->row != row || esurface->column != column) |
| 5304 | continue; |
| 5305 | |
| 5306 | exposay_highlight_surface(shell, esurface); |
| 5307 | return 1; |
| 5308 | } |
| 5309 | |
| 5310 | return 0; |
| 5311 | } |
| 5312 | |
| 5313 | static void |
| 5314 | exposay_key(struct weston_keyboard_grab *grab, uint32_t time, uint32_t key, |
| 5315 | uint32_t state_w) |
| 5316 | { |
| 5317 | struct weston_seat *seat = grab->keyboard->seat; |
| 5318 | struct desktop_shell *shell = |
| 5319 | container_of(grab, struct desktop_shell, exposay.grab_kbd); |
| 5320 | enum wl_keyboard_key_state state = state_w; |
| 5321 | |
| 5322 | if (state != WL_KEYBOARD_KEY_STATE_RELEASED) |
| 5323 | return; |
| 5324 | |
| 5325 | switch (key) { |
| 5326 | case KEY_ESC: |
| 5327 | exposay_set_state(shell, EXPOSAY_TARGET_CANCEL, seat); |
| 5328 | break; |
| 5329 | case KEY_ENTER: |
| 5330 | exposay_set_state(shell, EXPOSAY_TARGET_SWITCH, seat); |
| 5331 | break; |
| 5332 | case KEY_UP: |
| 5333 | exposay_maybe_move(shell, shell->exposay.row_current - 1, |
| 5334 | shell->exposay.column_current); |
| 5335 | break; |
| 5336 | case KEY_DOWN: |
| 5337 | /* Special case for trying to move to the bottom row when it |
| 5338 | * has fewer items than all the others. */ |
| 5339 | if (!exposay_maybe_move(shell, shell->exposay.row_current + 1, |
| 5340 | shell->exposay.column_current) && |
| 5341 | shell->exposay.row_current < (shell->exposay.grid_size - 1)) { |
| 5342 | exposay_maybe_move(shell, shell->exposay.row_current + 1, |
| 5343 | (shell->exposay.num_surfaces % |
| 5344 | shell->exposay.grid_size) - 1); |
| 5345 | } |
| 5346 | break; |
| 5347 | case KEY_LEFT: |
| 5348 | exposay_maybe_move(shell, shell->exposay.row_current, |
| 5349 | shell->exposay.column_current - 1); |
| 5350 | break; |
| 5351 | case KEY_RIGHT: |
| 5352 | exposay_maybe_move(shell, shell->exposay.row_current, |
| 5353 | shell->exposay.column_current + 1); |
| 5354 | break; |
| 5355 | case KEY_TAB: |
| 5356 | /* Try to move right, then down (and to the leftmost column), |
| 5357 | * then if all else fails, to the top left. */ |
| 5358 | if (!exposay_maybe_move(shell, shell->exposay.row_current, |
| 5359 | shell->exposay.column_current + 1) && |
| 5360 | !exposay_maybe_move(shell, shell->exposay.row_current + 1, 0)) |
| 5361 | exposay_maybe_move(shell, 0, 0); |
| 5362 | break; |
| 5363 | default: |
| 5364 | break; |
| 5365 | } |
| 5366 | } |
| 5367 | |
| 5368 | static void |
| 5369 | exposay_modifier(struct weston_keyboard_grab *grab, uint32_t serial, |
| 5370 | uint32_t mods_depressed, uint32_t mods_latched, |
| 5371 | uint32_t mods_locked, uint32_t group) |
| 5372 | { |
Emilio Pozuelo Monfort | eed9344 | 2013-11-27 10:49:08 +0100 | [diff] [blame] | 5373 | struct desktop_shell *shell = |
| 5374 | container_of(grab, struct desktop_shell, exposay.grab_kbd); |
| 5375 | struct weston_seat *seat = (struct weston_seat *) grab->keyboard->seat; |
| 5376 | |
| 5377 | /* We want to know when mod has been pressed and released. |
| 5378 | * FIXME: There is a problem here: if mod is pressed, then a key |
| 5379 | * is pressed and released, then mod is released, we will treat that |
| 5380 | * as if only mod had been pressed and released. */ |
| 5381 | if (seat->modifier_state) { |
| 5382 | if (seat->modifier_state == shell->binding_modifier) { |
| 5383 | shell->exposay.mod_pressed = true; |
| 5384 | } else { |
| 5385 | shell->exposay.mod_invalid = true; |
| 5386 | } |
| 5387 | } else { |
| 5388 | if (shell->exposay.mod_pressed && !shell->exposay.mod_invalid) |
| 5389 | exposay_set_state(shell, EXPOSAY_TARGET_CANCEL, seat); |
| 5390 | |
| 5391 | shell->exposay.mod_invalid = false; |
| 5392 | shell->exposay.mod_pressed = false; |
| 5393 | } |
| 5394 | |
| 5395 | return; |
Daniel Stone | df8133b | 2013-11-19 11:37:14 +0100 | [diff] [blame] | 5396 | } |
| 5397 | |
Emilio Pozuelo Monfort | 8224309 | 2013-11-19 11:37:17 +0100 | [diff] [blame] | 5398 | static void |
| 5399 | exposay_cancel(struct weston_keyboard_grab *grab) |
| 5400 | { |
| 5401 | struct desktop_shell *shell = |
| 5402 | container_of(grab, struct desktop_shell, exposay.grab_kbd); |
| 5403 | |
| 5404 | exposay_set_state(shell, EXPOSAY_TARGET_CANCEL, shell->exposay.seat); |
| 5405 | } |
| 5406 | |
Daniel Stone | df8133b | 2013-11-19 11:37:14 +0100 | [diff] [blame] | 5407 | static const struct weston_keyboard_grab_interface exposay_kbd_grab = { |
| 5408 | exposay_key, |
| 5409 | exposay_modifier, |
Emilio Pozuelo Monfort | 8224309 | 2013-11-19 11:37:17 +0100 | [diff] [blame] | 5410 | exposay_cancel, |
Daniel Stone | df8133b | 2013-11-19 11:37:14 +0100 | [diff] [blame] | 5411 | }; |
| 5412 | |
| 5413 | /** |
| 5414 | * Called when the transition from overview -> inactive has completed. |
| 5415 | */ |
| 5416 | static enum exposay_layout_state |
| 5417 | exposay_set_inactive(struct desktop_shell *shell) |
| 5418 | { |
| 5419 | struct weston_seat *seat = shell->exposay.seat; |
| 5420 | |
| 5421 | weston_keyboard_end_grab(seat->keyboard); |
| 5422 | weston_pointer_end_grab(seat->pointer); |
| 5423 | if (seat->keyboard->input_method_resource) |
| 5424 | seat->keyboard->grab = &seat->keyboard->input_method_grab; |
| 5425 | |
| 5426 | return EXPOSAY_LAYOUT_INACTIVE; |
| 5427 | } |
| 5428 | |
| 5429 | /** |
| 5430 | * Begins the transition from overview to inactive. */ |
| 5431 | static enum exposay_layout_state |
| 5432 | exposay_transition_inactive(struct desktop_shell *shell, int switch_focus) |
| 5433 | { |
| 5434 | struct exposay_surface *esurface; |
| 5435 | |
| 5436 | /* Call activate() before we start the animations to avoid |
| 5437 | * animating back the old state and then immediately transitioning |
| 5438 | * to the new. */ |
| 5439 | if (switch_focus && shell->exposay.focus_current) |
| 5440 | activate(shell, shell->exposay.focus_current->surface, |
| 5441 | shell->exposay.seat); |
| 5442 | else if (shell->exposay.focus_prev) |
| 5443 | activate(shell, shell->exposay.focus_prev->surface, |
| 5444 | shell->exposay.seat); |
| 5445 | |
| 5446 | wl_list_for_each(esurface, &shell->exposay.surface_list, link) |
| 5447 | exposay_animate_out(esurface); |
| 5448 | weston_compositor_schedule_repaint(shell->compositor); |
| 5449 | |
| 5450 | return EXPOSAY_LAYOUT_ANIMATE_TO_INACTIVE; |
| 5451 | } |
| 5452 | |
| 5453 | static enum exposay_layout_state |
| 5454 | exposay_transition_active(struct desktop_shell *shell) |
| 5455 | { |
| 5456 | struct weston_seat *seat = shell->exposay.seat; |
| 5457 | |
| 5458 | shell->exposay.workspace = get_current_workspace(shell); |
| 5459 | shell->exposay.focus_prev = get_default_view (seat->keyboard->focus); |
| 5460 | shell->exposay.focus_current = get_default_view (seat->keyboard->focus); |
| 5461 | shell->exposay.clicked = NULL; |
| 5462 | wl_list_init(&shell->exposay.surface_list); |
| 5463 | |
| 5464 | lower_fullscreen_layer(shell); |
| 5465 | shell->exposay.grab_kbd.interface = &exposay_kbd_grab; |
| 5466 | weston_keyboard_start_grab(seat->keyboard, |
| 5467 | &shell->exposay.grab_kbd); |
| 5468 | weston_keyboard_set_focus(seat->keyboard, NULL); |
| 5469 | |
| 5470 | shell->exposay.grab_ptr.interface = &exposay_ptr_grab; |
| 5471 | weston_pointer_start_grab(seat->pointer, |
| 5472 | &shell->exposay.grab_ptr); |
| 5473 | weston_pointer_set_focus(seat->pointer, NULL, |
| 5474 | seat->pointer->x, seat->pointer->y); |
| 5475 | |
| 5476 | return exposay_layout(shell); |
| 5477 | } |
| 5478 | |
| 5479 | static void |
| 5480 | exposay_check_state(struct desktop_shell *shell) |
| 5481 | { |
| 5482 | enum exposay_layout_state state_new = shell->exposay.state_cur; |
| 5483 | int do_switch = 0; |
| 5484 | |
| 5485 | /* Don't do anything whilst animations are running, just store up |
| 5486 | * target state changes and only act on them when the animations have |
| 5487 | * completed. */ |
| 5488 | if (exposay_is_animating(shell)) |
| 5489 | return; |
| 5490 | |
| 5491 | switch (shell->exposay.state_target) { |
| 5492 | case EXPOSAY_TARGET_OVERVIEW: |
| 5493 | switch (shell->exposay.state_cur) { |
| 5494 | case EXPOSAY_LAYOUT_OVERVIEW: |
| 5495 | goto out; |
| 5496 | case EXPOSAY_LAYOUT_ANIMATE_TO_OVERVIEW: |
| 5497 | state_new = EXPOSAY_LAYOUT_OVERVIEW; |
| 5498 | break; |
| 5499 | default: |
| 5500 | state_new = exposay_transition_active(shell); |
| 5501 | break; |
| 5502 | } |
| 5503 | break; |
| 5504 | |
| 5505 | case EXPOSAY_TARGET_SWITCH: |
| 5506 | do_switch = 1; /* fallthrough */ |
| 5507 | case EXPOSAY_TARGET_CANCEL: |
| 5508 | switch (shell->exposay.state_cur) { |
| 5509 | case EXPOSAY_LAYOUT_INACTIVE: |
| 5510 | goto out; |
| 5511 | case EXPOSAY_LAYOUT_ANIMATE_TO_INACTIVE: |
| 5512 | state_new = exposay_set_inactive(shell); |
| 5513 | break; |
| 5514 | default: |
| 5515 | state_new = exposay_transition_inactive(shell, do_switch); |
| 5516 | break; |
| 5517 | } |
| 5518 | |
| 5519 | break; |
| 5520 | } |
| 5521 | |
| 5522 | out: |
| 5523 | shell->exposay.state_cur = state_new; |
| 5524 | } |
| 5525 | |
| 5526 | static void |
| 5527 | exposay_set_state(struct desktop_shell *shell, enum exposay_target_state state, |
| 5528 | struct weston_seat *seat) |
| 5529 | { |
| 5530 | shell->exposay.state_target = state; |
| 5531 | shell->exposay.seat = seat; |
| 5532 | exposay_check_state(shell); |
| 5533 | } |
| 5534 | |
| 5535 | static void |
| 5536 | exposay_binding(struct weston_seat *seat, enum weston_keyboard_modifier modifier, |
| 5537 | void *data) |
| 5538 | { |
| 5539 | struct desktop_shell *shell = data; |
| 5540 | |
Emilio Pozuelo Monfort | eed9344 | 2013-11-27 10:49:08 +0100 | [diff] [blame] | 5541 | exposay_set_state(shell, EXPOSAY_TARGET_OVERVIEW, seat); |
Daniel Stone | df8133b | 2013-11-19 11:37:14 +0100 | [diff] [blame] | 5542 | } |
| 5543 | |
Pekka Paalanen | 3c64723 | 2011-12-22 13:43:43 +0200 | [diff] [blame] | 5544 | static void |
Kristian Høgsberg | e314875 | 2013-05-06 23:19:49 -0400 | [diff] [blame] | 5545 | backlight_binding(struct weston_seat *seat, uint32_t time, uint32_t key, |
Daniel Stone | 325fc2d | 2012-05-30 16:31:58 +0100 | [diff] [blame] | 5546 | void *data) |
Tiago Vignatti | 8e53c7f | 2012-02-29 19:53:50 +0200 | [diff] [blame] | 5547 | { |
| 5548 | struct weston_compositor *compositor = data; |
| 5549 | struct weston_output *output; |
Tiago Vignatti | 5ab91ad | 2012-03-12 19:40:09 -0300 | [diff] [blame] | 5550 | long backlight_new = 0; |
Tiago Vignatti | 8e53c7f | 2012-02-29 19:53:50 +0200 | [diff] [blame] | 5551 | |
| 5552 | /* TODO: we're limiting to simple use cases, where we assume just |
| 5553 | * control on the primary display. We'd have to extend later if we |
| 5554 | * ever get support for setting backlights on random desktop LCD |
| 5555 | * panels though */ |
| 5556 | output = get_default_output(compositor); |
| 5557 | if (!output) |
| 5558 | return; |
| 5559 | |
| 5560 | if (!output->set_backlight) |
| 5561 | return; |
| 5562 | |
Tiago Vignatti | 5ab91ad | 2012-03-12 19:40:09 -0300 | [diff] [blame] | 5563 | if (key == KEY_F9 || key == KEY_BRIGHTNESSDOWN) |
| 5564 | backlight_new = output->backlight_current - 25; |
| 5565 | else if (key == KEY_F10 || key == KEY_BRIGHTNESSUP) |
| 5566 | backlight_new = output->backlight_current + 25; |
Tiago Vignatti | 8e53c7f | 2012-02-29 19:53:50 +0200 | [diff] [blame] | 5567 | |
Tiago Vignatti | 5ab91ad | 2012-03-12 19:40:09 -0300 | [diff] [blame] | 5568 | if (backlight_new < 5) |
| 5569 | backlight_new = 5; |
| 5570 | if (backlight_new > 255) |
| 5571 | backlight_new = 255; |
| 5572 | |
| 5573 | output->backlight_current = backlight_new; |
Tiago Vignatti | 8e53c7f | 2012-02-29 19:53:50 +0200 | [diff] [blame] | 5574 | output->set_backlight(output, output->backlight_current); |
| 5575 | } |
| 5576 | |
Ander Conselvan de Oliveira | c509d2b | 2012-11-08 17:20:45 +0200 | [diff] [blame] | 5577 | struct debug_binding_grab { |
Kristian Høgsberg | 29139d4 | 2013-04-18 15:25:39 -0400 | [diff] [blame] | 5578 | struct weston_keyboard_grab grab; |
Ander Conselvan de Oliveira | c509d2b | 2012-11-08 17:20:45 +0200 | [diff] [blame] | 5579 | struct weston_seat *seat; |
| 5580 | uint32_t key[2]; |
| 5581 | int key_released[2]; |
| 5582 | }; |
| 5583 | |
| 5584 | static void |
Kristian Høgsberg | 29139d4 | 2013-04-18 15:25:39 -0400 | [diff] [blame] | 5585 | 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] | 5586 | uint32_t key, uint32_t state) |
| 5587 | { |
| 5588 | struct debug_binding_grab *db = (struct debug_binding_grab *) grab; |
Rob Bradford | 880ebc7 | 2013-07-22 17:31:38 +0100 | [diff] [blame] | 5589 | struct weston_compositor *ec = db->seat->compositor; |
| 5590 | struct wl_display *display = ec->wl_display; |
Ander Conselvan de Oliveira | c509d2b | 2012-11-08 17:20:45 +0200 | [diff] [blame] | 5591 | struct wl_resource *resource; |
Ander Conselvan de Oliveira | c509d2b | 2012-11-08 17:20:45 +0200 | [diff] [blame] | 5592 | uint32_t serial; |
| 5593 | int send = 0, terminate = 0; |
| 5594 | int check_binding = 1; |
| 5595 | int i; |
Neil Roberts | 96d790e | 2013-09-19 17:32:00 +0100 | [diff] [blame] | 5596 | struct wl_list *resource_list; |
Ander Conselvan de Oliveira | c509d2b | 2012-11-08 17:20:45 +0200 | [diff] [blame] | 5597 | |
| 5598 | if (state == WL_KEYBOARD_KEY_STATE_RELEASED) { |
| 5599 | /* Do not run bindings on key releases */ |
| 5600 | check_binding = 0; |
| 5601 | |
| 5602 | for (i = 0; i < 2; i++) |
| 5603 | if (key == db->key[i]) |
| 5604 | db->key_released[i] = 1; |
| 5605 | |
| 5606 | if (db->key_released[0] && db->key_released[1]) { |
| 5607 | /* All key releases been swalled so end the grab */ |
| 5608 | terminate = 1; |
| 5609 | } else if (key != db->key[0] && key != db->key[1]) { |
| 5610 | /* Should not swallow release of other keys */ |
| 5611 | send = 1; |
| 5612 | } |
| 5613 | } else if (key == db->key[0] && !db->key_released[0]) { |
| 5614 | /* Do not check bindings for the first press of the binding |
| 5615 | * key. This allows it to be used as a debug shortcut. |
| 5616 | * We still need to swallow this event. */ |
| 5617 | check_binding = 0; |
| 5618 | } else if (db->key[1]) { |
| 5619 | /* If we already ran a binding don't process another one since |
| 5620 | * we can't keep track of all the binding keys that were |
| 5621 | * pressed in order to swallow the release events. */ |
| 5622 | send = 1; |
| 5623 | check_binding = 0; |
| 5624 | } |
| 5625 | |
| 5626 | if (check_binding) { |
Ander Conselvan de Oliveira | c509d2b | 2012-11-08 17:20:45 +0200 | [diff] [blame] | 5627 | if (weston_compositor_run_debug_binding(ec, db->seat, time, |
| 5628 | key, state)) { |
| 5629 | /* We ran a binding so swallow the press and keep the |
| 5630 | * grab to swallow the released too. */ |
| 5631 | send = 0; |
| 5632 | terminate = 0; |
| 5633 | db->key[1] = key; |
| 5634 | } else { |
| 5635 | /* Terminate the grab since the key pressed is not a |
| 5636 | * debug binding key. */ |
| 5637 | send = 1; |
| 5638 | terminate = 1; |
| 5639 | } |
| 5640 | } |
| 5641 | |
| 5642 | if (send) { |
Neil Roberts | 96d790e | 2013-09-19 17:32:00 +0100 | [diff] [blame] | 5643 | serial = wl_display_next_serial(display); |
| 5644 | resource_list = &grab->keyboard->focus_resource_list; |
| 5645 | wl_resource_for_each(resource, resource_list) { |
Ander Conselvan de Oliveira | c509d2b | 2012-11-08 17:20:45 +0200 | [diff] [blame] | 5646 | wl_keyboard_send_key(resource, serial, time, key, state); |
| 5647 | } |
| 5648 | } |
| 5649 | |
| 5650 | if (terminate) { |
Kristian Høgsberg | 29139d4 | 2013-04-18 15:25:39 -0400 | [diff] [blame] | 5651 | weston_keyboard_end_grab(grab->keyboard); |
| 5652 | if (grab->keyboard->input_method_resource) |
| 5653 | grab->keyboard->grab = &grab->keyboard->input_method_grab; |
Ander Conselvan de Oliveira | c509d2b | 2012-11-08 17:20:45 +0200 | [diff] [blame] | 5654 | free(db); |
| 5655 | } |
| 5656 | } |
| 5657 | |
| 5658 | static void |
Kristian Høgsberg | 29139d4 | 2013-04-18 15:25:39 -0400 | [diff] [blame] | 5659 | 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] | 5660 | uint32_t mods_depressed, uint32_t mods_latched, |
| 5661 | uint32_t mods_locked, uint32_t group) |
| 5662 | { |
| 5663 | struct wl_resource *resource; |
Neil Roberts | 96d790e | 2013-09-19 17:32:00 +0100 | [diff] [blame] | 5664 | struct wl_list *resource_list; |
Ander Conselvan de Oliveira | c509d2b | 2012-11-08 17:20:45 +0200 | [diff] [blame] | 5665 | |
Neil Roberts | 96d790e | 2013-09-19 17:32:00 +0100 | [diff] [blame] | 5666 | resource_list = &grab->keyboard->focus_resource_list; |
Ander Conselvan de Oliveira | c509d2b | 2012-11-08 17:20:45 +0200 | [diff] [blame] | 5667 | |
Neil Roberts | 96d790e | 2013-09-19 17:32:00 +0100 | [diff] [blame] | 5668 | wl_resource_for_each(resource, resource_list) { |
| 5669 | wl_keyboard_send_modifiers(resource, serial, mods_depressed, |
| 5670 | mods_latched, mods_locked, group); |
| 5671 | } |
Ander Conselvan de Oliveira | c509d2b | 2012-11-08 17:20:45 +0200 | [diff] [blame] | 5672 | } |
| 5673 | |
Jonas Ådahl | 1ea343e | 2013-10-25 23:18:05 +0200 | [diff] [blame] | 5674 | static void |
| 5675 | debug_binding_cancel(struct weston_keyboard_grab *grab) |
| 5676 | { |
| 5677 | struct debug_binding_grab *db = (struct debug_binding_grab *) grab; |
| 5678 | |
| 5679 | weston_keyboard_end_grab(grab->keyboard); |
| 5680 | free(db); |
| 5681 | } |
| 5682 | |
Kristian Høgsberg | 29139d4 | 2013-04-18 15:25:39 -0400 | [diff] [blame] | 5683 | struct weston_keyboard_grab_interface debug_binding_keyboard_grab = { |
Ander Conselvan de Oliveira | c509d2b | 2012-11-08 17:20:45 +0200 | [diff] [blame] | 5684 | debug_binding_key, |
Jonas Ådahl | 1ea343e | 2013-10-25 23:18:05 +0200 | [diff] [blame] | 5685 | debug_binding_modifiers, |
| 5686 | debug_binding_cancel, |
Ander Conselvan de Oliveira | c509d2b | 2012-11-08 17:20:45 +0200 | [diff] [blame] | 5687 | }; |
| 5688 | |
| 5689 | static void |
Kristian Høgsberg | e314875 | 2013-05-06 23:19:49 -0400 | [diff] [blame] | 5690 | 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] | 5691 | { |
| 5692 | struct debug_binding_grab *grab; |
| 5693 | |
| 5694 | grab = calloc(1, sizeof *grab); |
| 5695 | if (!grab) |
| 5696 | return; |
| 5697 | |
| 5698 | grab->seat = (struct weston_seat *) seat; |
| 5699 | grab->key[0] = key; |
| 5700 | grab->grab.interface = &debug_binding_keyboard_grab; |
Kristian Høgsberg | 29139d4 | 2013-04-18 15:25:39 -0400 | [diff] [blame] | 5701 | weston_keyboard_start_grab(seat->keyboard, &grab->grab); |
Ander Conselvan de Oliveira | c509d2b | 2012-11-08 17:20:45 +0200 | [diff] [blame] | 5702 | } |
| 5703 | |
Kristian Høgsberg | b41c081 | 2012-03-04 14:53:40 -0500 | [diff] [blame] | 5704 | static void |
Kristian Høgsberg | e314875 | 2013-05-06 23:19:49 -0400 | [diff] [blame] | 5705 | 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] | 5706 | void *data) |
Kristian Høgsberg | 92a57db | 2012-05-26 13:41:06 -0400 | [diff] [blame] | 5707 | { |
Kristian Høgsberg | fe7aa90 | 2013-05-08 09:54:37 -0400 | [diff] [blame] | 5708 | struct weston_surface *focus_surface; |
Kristian Høgsberg | 92a57db | 2012-05-26 13:41:06 -0400 | [diff] [blame] | 5709 | struct wl_client *client; |
Tiago Vignatti | 1d01b01 | 2012-09-27 17:48:36 +0300 | [diff] [blame] | 5710 | struct desktop_shell *shell = data; |
| 5711 | struct weston_compositor *compositor = shell->compositor; |
Kristian Høgsberg | 92a57db | 2012-05-26 13:41:06 -0400 | [diff] [blame] | 5712 | pid_t pid; |
Kristian Høgsberg | 92a57db | 2012-05-26 13:41:06 -0400 | [diff] [blame] | 5713 | |
Philipp Brüschweiler | 6cef009 | 2012-08-13 21:27:27 +0200 | [diff] [blame] | 5714 | focus_surface = seat->keyboard->focus; |
| 5715 | if (!focus_surface) |
| 5716 | return; |
| 5717 | |
Tiago Vignatti | 1d01b01 | 2012-09-27 17:48:36 +0300 | [diff] [blame] | 5718 | wl_signal_emit(&compositor->kill_signal, focus_surface); |
| 5719 | |
Jason Ekstrand | 26ed73c | 2013-06-06 22:34:41 -0500 | [diff] [blame] | 5720 | client = wl_resource_get_client(focus_surface->resource); |
Tiago Vignatti | 920f197 | 2012-09-27 17:48:35 +0300 | [diff] [blame] | 5721 | wl_client_get_credentials(client, &pid, NULL, NULL); |
| 5722 | |
| 5723 | /* Skip clients that we launched ourselves (the credentials of |
| 5724 | * the socketpair is ours) */ |
| 5725 | if (pid == getpid()) |
| 5726 | return; |
Kristian Høgsberg | 92a57db | 2012-05-26 13:41:06 -0400 | [diff] [blame] | 5727 | |
Daniel Stone | 325fc2d | 2012-05-30 16:31:58 +0100 | [diff] [blame] | 5728 | kill(pid, SIGKILL); |
Kristian Høgsberg | 92a57db | 2012-05-26 13:41:06 -0400 | [diff] [blame] | 5729 | } |
| 5730 | |
| 5731 | static void |
Kristian Høgsberg | e314875 | 2013-05-06 23:19:49 -0400 | [diff] [blame] | 5732 | workspace_up_binding(struct weston_seat *seat, uint32_t time, |
Jonas Ådahl | e3cddce | 2012-06-13 00:01:22 +0200 | [diff] [blame] | 5733 | uint32_t key, void *data) |
| 5734 | { |
| 5735 | struct desktop_shell *shell = data; |
| 5736 | unsigned int new_index = shell->workspaces.current; |
| 5737 | |
Kristian Høgsberg | ce345b0 | 2012-06-25 21:35:29 -0400 | [diff] [blame] | 5738 | if (shell->locked) |
Kristian Høgsberg | 4476aaf | 2012-06-25 14:03:13 -0400 | [diff] [blame] | 5739 | return; |
Jonas Ådahl | e3cddce | 2012-06-13 00:01:22 +0200 | [diff] [blame] | 5740 | if (new_index != 0) |
| 5741 | new_index--; |
| 5742 | |
| 5743 | change_workspace(shell, new_index); |
| 5744 | } |
| 5745 | |
| 5746 | static void |
Kristian Høgsberg | e314875 | 2013-05-06 23:19:49 -0400 | [diff] [blame] | 5747 | workspace_down_binding(struct weston_seat *seat, uint32_t time, |
Jonas Ådahl | e3cddce | 2012-06-13 00:01:22 +0200 | [diff] [blame] | 5748 | uint32_t key, void *data) |
| 5749 | { |
| 5750 | struct desktop_shell *shell = data; |
| 5751 | unsigned int new_index = shell->workspaces.current; |
| 5752 | |
Kristian Høgsberg | ce345b0 | 2012-06-25 21:35:29 -0400 | [diff] [blame] | 5753 | if (shell->locked) |
Kristian Høgsberg | 4476aaf | 2012-06-25 14:03:13 -0400 | [diff] [blame] | 5754 | return; |
Jonas Ådahl | e3cddce | 2012-06-13 00:01:22 +0200 | [diff] [blame] | 5755 | if (new_index < shell->workspaces.num - 1) |
| 5756 | new_index++; |
| 5757 | |
| 5758 | change_workspace(shell, new_index); |
| 5759 | } |
| 5760 | |
| 5761 | static void |
Kristian Høgsberg | e314875 | 2013-05-06 23:19:49 -0400 | [diff] [blame] | 5762 | workspace_f_binding(struct weston_seat *seat, uint32_t time, |
Jonas Ådahl | e3cddce | 2012-06-13 00:01:22 +0200 | [diff] [blame] | 5763 | uint32_t key, void *data) |
| 5764 | { |
| 5765 | struct desktop_shell *shell = data; |
| 5766 | unsigned int new_index; |
| 5767 | |
Kristian Høgsberg | ce345b0 | 2012-06-25 21:35:29 -0400 | [diff] [blame] | 5768 | if (shell->locked) |
Kristian Høgsberg | 4476aaf | 2012-06-25 14:03:13 -0400 | [diff] [blame] | 5769 | return; |
Jonas Ådahl | e3cddce | 2012-06-13 00:01:22 +0200 | [diff] [blame] | 5770 | new_index = key - KEY_F1; |
| 5771 | if (new_index >= shell->workspaces.num) |
| 5772 | new_index = shell->workspaces.num - 1; |
| 5773 | |
| 5774 | change_workspace(shell, new_index); |
| 5775 | } |
| 5776 | |
Jonas Ådahl | 8de6a1d | 2012-08-29 22:13:00 +0200 | [diff] [blame] | 5777 | static void |
Kristian Høgsberg | e314875 | 2013-05-06 23:19:49 -0400 | [diff] [blame] | 5778 | workspace_move_surface_up_binding(struct weston_seat *seat, uint32_t time, |
Jonas Ådahl | 8de6a1d | 2012-08-29 22:13:00 +0200 | [diff] [blame] | 5779 | uint32_t key, void *data) |
| 5780 | { |
| 5781 | struct desktop_shell *shell = data; |
| 5782 | unsigned int new_index = shell->workspaces.current; |
| 5783 | |
| 5784 | if (shell->locked) |
| 5785 | return; |
| 5786 | |
| 5787 | if (new_index != 0) |
| 5788 | new_index--; |
| 5789 | |
| 5790 | take_surface_to_workspace_by_seat(shell, seat, new_index); |
| 5791 | } |
| 5792 | |
| 5793 | static void |
Kristian Høgsberg | e314875 | 2013-05-06 23:19:49 -0400 | [diff] [blame] | 5794 | workspace_move_surface_down_binding(struct weston_seat *seat, uint32_t time, |
Jonas Ådahl | 8de6a1d | 2012-08-29 22:13:00 +0200 | [diff] [blame] | 5795 | uint32_t key, void *data) |
| 5796 | { |
| 5797 | struct desktop_shell *shell = data; |
| 5798 | unsigned int new_index = shell->workspaces.current; |
| 5799 | |
| 5800 | if (shell->locked) |
| 5801 | return; |
| 5802 | |
| 5803 | if (new_index < shell->workspaces.num - 1) |
| 5804 | new_index++; |
| 5805 | |
| 5806 | take_surface_to_workspace_by_seat(shell, seat, new_index); |
| 5807 | } |
Jonas Ådahl | e3cddce | 2012-06-13 00:01:22 +0200 | [diff] [blame] | 5808 | |
| 5809 | static void |
Xiong Zhang | 6b48142 | 2013-10-23 13:58:32 +0800 | [diff] [blame] | 5810 | handle_output_destroy(struct wl_listener *listener, void *data) |
| 5811 | { |
| 5812 | struct shell_output *output_listener = |
| 5813 | container_of(listener, struct shell_output, destroy_listener); |
| 5814 | |
| 5815 | wl_list_remove(&output_listener->destroy_listener.link); |
| 5816 | wl_list_remove(&output_listener->link); |
| 5817 | free(output_listener); |
| 5818 | } |
| 5819 | |
| 5820 | static void |
| 5821 | create_shell_output(struct desktop_shell *shell, |
| 5822 | struct weston_output *output) |
| 5823 | { |
| 5824 | struct shell_output *shell_output; |
| 5825 | |
| 5826 | shell_output = zalloc(sizeof *shell_output); |
| 5827 | if (shell_output == NULL) |
| 5828 | return; |
| 5829 | |
| 5830 | shell_output->output = output; |
| 5831 | shell_output->shell = shell; |
| 5832 | shell_output->destroy_listener.notify = handle_output_destroy; |
| 5833 | wl_signal_add(&output->destroy_signal, |
| 5834 | &shell_output->destroy_listener); |
Kristian Høgsberg | a3a0e18 | 2013-10-23 23:36:04 -0700 | [diff] [blame] | 5835 | wl_list_insert(shell->output_list.prev, &shell_output->link); |
Xiong Zhang | 6b48142 | 2013-10-23 13:58:32 +0800 | [diff] [blame] | 5836 | } |
| 5837 | |
| 5838 | static void |
| 5839 | handle_output_create(struct wl_listener *listener, void *data) |
| 5840 | { |
| 5841 | struct desktop_shell *shell = |
| 5842 | container_of(listener, struct desktop_shell, output_create_listener); |
| 5843 | struct weston_output *output = (struct weston_output *)data; |
| 5844 | |
| 5845 | create_shell_output(shell, output); |
| 5846 | } |
| 5847 | |
| 5848 | static void |
| 5849 | setup_output_destroy_handler(struct weston_compositor *ec, |
| 5850 | struct desktop_shell *shell) |
| 5851 | { |
| 5852 | struct weston_output *output; |
| 5853 | |
| 5854 | wl_list_init(&shell->output_list); |
| 5855 | wl_list_for_each(output, &ec->output_list, link) |
| 5856 | create_shell_output(shell, output); |
| 5857 | |
| 5858 | shell->output_create_listener.notify = handle_output_create; |
| 5859 | wl_signal_add(&ec->output_created_signal, |
| 5860 | &shell->output_create_listener); |
| 5861 | } |
| 5862 | |
| 5863 | static void |
Kristian Høgsberg | 02e79dc | 2012-04-12 09:55:26 -0400 | [diff] [blame] | 5864 | shell_destroy(struct wl_listener *listener, void *data) |
Pekka Paalanen | 3c64723 | 2011-12-22 13:43:43 +0200 | [diff] [blame] | 5865 | { |
Tiago Vignatti | be14326 | 2012-04-16 17:31:41 +0300 | [diff] [blame] | 5866 | struct desktop_shell *shell = |
| 5867 | container_of(listener, struct desktop_shell, destroy_listener); |
Jonas Ådahl | e3cddce | 2012-06-13 00:01:22 +0200 | [diff] [blame] | 5868 | struct workspace **ws; |
Xiong Zhang | 6b48142 | 2013-10-23 13:58:32 +0800 | [diff] [blame] | 5869 | struct shell_output *shell_output, *tmp; |
Pekka Paalanen | 3c64723 | 2011-12-22 13:43:43 +0200 | [diff] [blame] | 5870 | |
Pekka Paalanen | 9cf5cc8 | 2012-01-02 16:00:24 +0200 | [diff] [blame] | 5871 | if (shell->child.client) |
| 5872 | wl_client_destroy(shell->child.client); |
| 5873 | |
Ander Conselvan de Oliveira | a457563 | 2013-02-21 18:35:23 +0200 | [diff] [blame] | 5874 | wl_list_remove(&shell->idle_listener.link); |
| 5875 | wl_list_remove(&shell->wake_listener.link); |
Jan Arne Petersen | 42feced | 2012-06-21 21:52:17 +0200 | [diff] [blame] | 5876 | wl_list_remove(&shell->show_input_panel_listener.link); |
| 5877 | wl_list_remove(&shell->hide_input_panel_listener.link); |
Kristian Høgsberg | 88c1607 | 2012-05-16 08:04:19 -0400 | [diff] [blame] | 5878 | |
Xiong Zhang | 6b48142 | 2013-10-23 13:58:32 +0800 | [diff] [blame] | 5879 | wl_list_for_each_safe(shell_output, tmp, &shell->output_list, link) { |
| 5880 | wl_list_remove(&shell_output->destroy_listener.link); |
| 5881 | wl_list_remove(&shell_output->link); |
| 5882 | free(shell_output); |
| 5883 | } |
| 5884 | |
| 5885 | wl_list_remove(&shell->output_create_listener.link); |
| 5886 | |
Jonas Ådahl | e3cddce | 2012-06-13 00:01:22 +0200 | [diff] [blame] | 5887 | wl_array_for_each(ws, &shell->workspaces.array) |
| 5888 | workspace_destroy(*ws); |
| 5889 | wl_array_release(&shell->workspaces.array); |
| 5890 | |
Pekka Paalanen | 3c64723 | 2011-12-22 13:43:43 +0200 | [diff] [blame] | 5891 | free(shell->screensaver.path); |
Emilio Pozuelo Monfort | 46ce798 | 2013-11-20 13:22:29 +0100 | [diff] [blame] | 5892 | free(shell->client); |
Pekka Paalanen | 3c64723 | 2011-12-22 13:43:43 +0200 | [diff] [blame] | 5893 | free(shell); |
| 5894 | } |
| 5895 | |
Tiago Vignatti | 0b52d48 | 2012-04-20 18:54:25 +0300 | [diff] [blame] | 5896 | static void |
| 5897 | shell_add_bindings(struct weston_compositor *ec, struct desktop_shell *shell) |
| 5898 | { |
| 5899 | uint32_t mod; |
Jonas Ådahl | e3cddce | 2012-06-13 00:01:22 +0200 | [diff] [blame] | 5900 | int i, num_workspace_bindings; |
Tiago Vignatti | 0b52d48 | 2012-04-20 18:54:25 +0300 | [diff] [blame] | 5901 | |
| 5902 | /* fixed bindings */ |
Daniel Stone | 325fc2d | 2012-05-30 16:31:58 +0100 | [diff] [blame] | 5903 | weston_compositor_add_key_binding(ec, KEY_BACKSPACE, |
| 5904 | MODIFIER_CTRL | MODIFIER_ALT, |
| 5905 | terminate_binding, ec); |
Emilio Pozuelo Monfort | 03251b6 | 2013-11-19 11:37:16 +0100 | [diff] [blame] | 5906 | weston_compositor_add_key_binding(ec, KEY_TAB, |
| 5907 | MODIFIER_ALT, |
| 5908 | alt_tab_binding, shell); |
Daniel Stone | 325fc2d | 2012-05-30 16:31:58 +0100 | [diff] [blame] | 5909 | weston_compositor_add_button_binding(ec, BTN_LEFT, 0, |
| 5910 | click_to_activate_binding, |
| 5911 | shell); |
Neil Roberts | a28c693 | 2013-10-03 16:43:04 +0100 | [diff] [blame] | 5912 | weston_compositor_add_touch_binding(ec, 0, |
| 5913 | touch_to_activate_binding, |
| 5914 | shell); |
Daniel Stone | 325fc2d | 2012-05-30 16:31:58 +0100 | [diff] [blame] | 5915 | weston_compositor_add_axis_binding(ec, WL_POINTER_AXIS_VERTICAL_SCROLL, |
| 5916 | MODIFIER_SUPER | MODIFIER_ALT, |
| 5917 | surface_opacity_binding, NULL); |
| 5918 | weston_compositor_add_axis_binding(ec, WL_POINTER_AXIS_VERTICAL_SCROLL, |
| 5919 | MODIFIER_SUPER, zoom_axis_binding, |
| 5920 | NULL); |
Tiago Vignatti | 0b52d48 | 2012-04-20 18:54:25 +0300 | [diff] [blame] | 5921 | |
| 5922 | /* configurable bindings */ |
| 5923 | mod = shell->binding_modifier; |
Daniel Stone | 325fc2d | 2012-05-30 16:31:58 +0100 | [diff] [blame] | 5924 | weston_compositor_add_key_binding(ec, KEY_PAGEUP, mod, |
| 5925 | zoom_key_binding, NULL); |
| 5926 | weston_compositor_add_key_binding(ec, KEY_PAGEDOWN, mod, |
| 5927 | zoom_key_binding, NULL); |
| 5928 | weston_compositor_add_button_binding(ec, BTN_LEFT, mod, move_binding, |
| 5929 | shell); |
Neil Roberts | aba0f25 | 2013-10-03 16:43:05 +0100 | [diff] [blame] | 5930 | weston_compositor_add_touch_binding(ec, mod, touch_move_binding, shell); |
Daniel Stone | 325fc2d | 2012-05-30 16:31:58 +0100 | [diff] [blame] | 5931 | weston_compositor_add_button_binding(ec, BTN_MIDDLE, mod, |
| 5932 | resize_binding, shell); |
Pekka Paalanen | 7bb6510 | 2013-05-22 18:03:04 +0300 | [diff] [blame] | 5933 | |
| 5934 | if (ec->capabilities & WESTON_CAP_ROTATION_ANY) |
| 5935 | weston_compositor_add_button_binding(ec, BTN_RIGHT, mod, |
| 5936 | rotate_binding, NULL); |
| 5937 | |
Daniel Stone | 325fc2d | 2012-05-30 16:31:58 +0100 | [diff] [blame] | 5938 | weston_compositor_add_key_binding(ec, KEY_TAB, mod, switcher_binding, |
| 5939 | shell); |
| 5940 | weston_compositor_add_key_binding(ec, KEY_F9, mod, backlight_binding, |
| 5941 | ec); |
| 5942 | weston_compositor_add_key_binding(ec, KEY_BRIGHTNESSDOWN, 0, |
| 5943 | backlight_binding, ec); |
| 5944 | weston_compositor_add_key_binding(ec, KEY_F10, mod, backlight_binding, |
| 5945 | ec); |
| 5946 | weston_compositor_add_key_binding(ec, KEY_BRIGHTNESSUP, 0, |
| 5947 | backlight_binding, ec); |
Daniel Stone | 325fc2d | 2012-05-30 16:31:58 +0100 | [diff] [blame] | 5948 | weston_compositor_add_key_binding(ec, KEY_K, mod, |
| 5949 | force_kill_binding, shell); |
Jonas Ådahl | e3cddce | 2012-06-13 00:01:22 +0200 | [diff] [blame] | 5950 | weston_compositor_add_key_binding(ec, KEY_UP, mod, |
| 5951 | workspace_up_binding, shell); |
| 5952 | weston_compositor_add_key_binding(ec, KEY_DOWN, mod, |
| 5953 | workspace_down_binding, shell); |
Jonas Ådahl | 8de6a1d | 2012-08-29 22:13:00 +0200 | [diff] [blame] | 5954 | weston_compositor_add_key_binding(ec, KEY_UP, mod | MODIFIER_SHIFT, |
| 5955 | workspace_move_surface_up_binding, |
| 5956 | shell); |
| 5957 | weston_compositor_add_key_binding(ec, KEY_DOWN, mod | MODIFIER_SHIFT, |
| 5958 | workspace_move_surface_down_binding, |
| 5959 | shell); |
Jonas Ådahl | e3cddce | 2012-06-13 00:01:22 +0200 | [diff] [blame] | 5960 | |
Daniel Stone | df8133b | 2013-11-19 11:37:14 +0100 | [diff] [blame] | 5961 | weston_compositor_add_modifier_binding(ec, mod, exposay_binding, shell); |
| 5962 | |
Jonas Ådahl | e3cddce | 2012-06-13 00:01:22 +0200 | [diff] [blame] | 5963 | /* Add bindings for mod+F[1-6] for workspace 1 to 6. */ |
| 5964 | if (shell->workspaces.num > 1) { |
| 5965 | num_workspace_bindings = shell->workspaces.num; |
| 5966 | if (num_workspace_bindings > 6) |
| 5967 | num_workspace_bindings = 6; |
| 5968 | for (i = 0; i < num_workspace_bindings; i++) |
| 5969 | weston_compositor_add_key_binding(ec, KEY_F1 + i, mod, |
| 5970 | workspace_f_binding, |
| 5971 | shell); |
| 5972 | } |
Ander Conselvan de Oliveira | c509d2b | 2012-11-08 17:20:45 +0200 | [diff] [blame] | 5973 | |
| 5974 | /* Debug bindings */ |
| 5975 | weston_compositor_add_key_binding(ec, KEY_SPACE, mod | MODIFIER_SHIFT, |
| 5976 | debug_binding, shell); |
Tiago Vignatti | 0b52d48 | 2012-04-20 18:54:25 +0300 | [diff] [blame] | 5977 | } |
| 5978 | |
Kristian Høgsberg | 1c56218 | 2011-05-02 22:09:20 -0400 | [diff] [blame] | 5979 | WL_EXPORT int |
Kristian Høgsberg | cb4685b | 2013-02-20 15:37:49 -0500 | [diff] [blame] | 5980 | module_init(struct weston_compositor *ec, |
Ossama Othman | a50e6e4 | 2013-05-14 09:48:26 -0700 | [diff] [blame] | 5981 | int *argc, char *argv[]) |
Kristian Høgsberg | 4cca349 | 2011-01-18 07:53:49 -0500 | [diff] [blame] | 5982 | { |
Kristian Høgsberg | f4d2f23 | 2012-08-10 10:05:39 -0400 | [diff] [blame] | 5983 | struct weston_seat *seat; |
Tiago Vignatti | be14326 | 2012-04-16 17:31:41 +0300 | [diff] [blame] | 5984 | struct desktop_shell *shell; |
Jonas Ådahl | e3cddce | 2012-06-13 00:01:22 +0200 | [diff] [blame] | 5985 | struct workspace **pws; |
| 5986 | unsigned int i; |
Tiago Vignatti | b7dbbd6 | 2012-09-25 17:57:01 +0300 | [diff] [blame] | 5987 | struct wl_event_loop *loop; |
Kristian Høgsberg | 02ec0a5 | 2011-04-23 13:04:11 -0400 | [diff] [blame] | 5988 | |
Peter Hutterer | f3d6227 | 2013-08-08 11:57:05 +1000 | [diff] [blame] | 5989 | shell = zalloc(sizeof *shell); |
Kristian Høgsberg | 02ec0a5 | 2011-04-23 13:04:11 -0400 | [diff] [blame] | 5990 | if (shell == NULL) |
| 5991 | return -1; |
| 5992 | |
Kristian Høgsberg | 7584062 | 2011-09-06 13:48:16 -0400 | [diff] [blame] | 5993 | shell->compositor = ec; |
Kristian Høgsberg | 02e79dc | 2012-04-12 09:55:26 -0400 | [diff] [blame] | 5994 | |
| 5995 | shell->destroy_listener.notify = shell_destroy; |
| 5996 | wl_signal_add(&ec->destroy_signal, &shell->destroy_listener); |
Ander Conselvan de Oliveira | a457563 | 2013-02-21 18:35:23 +0200 | [diff] [blame] | 5997 | shell->idle_listener.notify = idle_handler; |
| 5998 | wl_signal_add(&ec->idle_signal, &shell->idle_listener); |
| 5999 | shell->wake_listener.notify = wake_handler; |
| 6000 | wl_signal_add(&ec->wake_signal, &shell->wake_listener); |
Jan Arne Petersen | 42feced | 2012-06-21 21:52:17 +0200 | [diff] [blame] | 6001 | shell->show_input_panel_listener.notify = show_input_panels; |
| 6002 | wl_signal_add(&ec->show_input_panel_signal, &shell->show_input_panel_listener); |
| 6003 | shell->hide_input_panel_listener.notify = hide_input_panels; |
| 6004 | 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] | 6005 | shell->update_input_panel_listener.notify = update_input_panels; |
| 6006 | 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] | 6007 | ec->ping_handler = ping_handler; |
Kristian Høgsberg | 82a1d11 | 2012-07-19 14:02:00 -0400 | [diff] [blame] | 6008 | ec->shell_interface.shell = shell; |
Tiago Vignatti | bc052c9 | 2012-04-19 16:18:18 +0300 | [diff] [blame] | 6009 | ec->shell_interface.create_shell_surface = create_shell_surface; |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 6010 | ec->shell_interface.get_primary_view = get_primary_view; |
Tiago Vignatti | bc052c9 | 2012-04-19 16:18:18 +0300 | [diff] [blame] | 6011 | ec->shell_interface.set_toplevel = set_toplevel; |
Tiago Vignatti | 491bac1 | 2012-05-18 16:37:43 -0400 | [diff] [blame] | 6012 | ec->shell_interface.set_transient = set_transient; |
Kristian Høgsberg | b810eb5 | 2013-02-12 20:07:05 -0500 | [diff] [blame] | 6013 | ec->shell_interface.set_fullscreen = set_fullscreen; |
Tiago Vignatti | fb2adba | 2013-06-12 15:43:21 -0300 | [diff] [blame] | 6014 | ec->shell_interface.set_xwayland = set_xwayland; |
Kristian Høgsberg | 938b8fa | 2012-05-18 13:46:27 -0400 | [diff] [blame] | 6015 | ec->shell_interface.move = surface_move; |
Kristian Høgsberg | c1693f2 | 2012-05-22 16:56:23 -0400 | [diff] [blame] | 6016 | ec->shell_interface.resize = surface_resize; |
Giulio Camuffo | 62942ad | 2013-09-11 18:20:47 +0200 | [diff] [blame] | 6017 | ec->shell_interface.set_title = set_title; |
Kristian Høgsberg | 4cca349 | 2011-01-18 07:53:49 -0500 | [diff] [blame] | 6018 | |
Jan Arne Petersen | 42feced | 2012-06-21 21:52:17 +0200 | [diff] [blame] | 6019 | wl_list_init(&shell->input_panel.surfaces); |
Pekka Paalanen | f0fc70d | 2011-11-15 13:34:54 +0200 | [diff] [blame] | 6020 | |
Kristian Høgsberg | 3be2ce9 | 2012-02-29 12:42:35 -0500 | [diff] [blame] | 6021 | weston_layer_init(&shell->fullscreen_layer, &ec->cursor_layer.link); |
| 6022 | weston_layer_init(&shell->panel_layer, &shell->fullscreen_layer.link); |
Jonas Ådahl | e3cddce | 2012-06-13 00:01:22 +0200 | [diff] [blame] | 6023 | weston_layer_init(&shell->background_layer, &shell->panel_layer.link); |
| 6024 | weston_layer_init(&shell->lock_layer, NULL); |
Philipp Brüschweiler | 711fda8 | 2012-08-09 18:50:43 +0200 | [diff] [blame] | 6025 | weston_layer_init(&shell->input_panel_layer, NULL); |
Jonas Ådahl | e3cddce | 2012-06-13 00:01:22 +0200 | [diff] [blame] | 6026 | |
| 6027 | wl_array_init(&shell->workspaces.array); |
Jonas Ådahl | e9d2250 | 2012-08-29 22:13:01 +0200 | [diff] [blame] | 6028 | wl_list_init(&shell->workspaces.client_list); |
Kristian Høgsberg | 3be2ce9 | 2012-02-29 12:42:35 -0500 | [diff] [blame] | 6029 | |
Kristian Høgsberg | 14e438c | 2013-05-26 21:48:14 -0400 | [diff] [blame] | 6030 | shell_configuration(shell); |
Pekka Paalanen | e955f1e | 2011-12-07 11:49:52 +0200 | [diff] [blame] | 6031 | |
Daniel Stone | df8133b | 2013-11-19 11:37:14 +0100 | [diff] [blame] | 6032 | shell->exposay.state_cur = EXPOSAY_LAYOUT_INACTIVE; |
| 6033 | shell->exposay.state_target = EXPOSAY_TARGET_CANCEL; |
| 6034 | |
Jonas Ådahl | e3cddce | 2012-06-13 00:01:22 +0200 | [diff] [blame] | 6035 | for (i = 0; i < shell->workspaces.num; i++) { |
| 6036 | pws = wl_array_add(&shell->workspaces.array, sizeof *pws); |
| 6037 | if (pws == NULL) |
| 6038 | return -1; |
| 6039 | |
| 6040 | *pws = workspace_create(); |
| 6041 | if (*pws == NULL) |
| 6042 | return -1; |
| 6043 | } |
| 6044 | activate_workspace(shell, 0); |
| 6045 | |
Jonas Ådahl | 8de6a1d | 2012-08-29 22:13:00 +0200 | [diff] [blame] | 6046 | wl_list_init(&shell->workspaces.anim_sticky_list); |
Jonas Ådahl | 62fcd04 | 2012-06-13 00:01:23 +0200 | [diff] [blame] | 6047 | wl_list_init(&shell->workspaces.animation.link); |
| 6048 | shell->workspaces.animation.frame = animate_workspace_change_frame; |
| 6049 | |
Kristian Høgsberg | 919cddb | 2013-07-08 19:03:57 -0400 | [diff] [blame] | 6050 | if (wl_global_create(ec->wl_display, &wl_shell_interface, 1, |
Kristian Høgsberg | 97d44aa | 2011-08-26 17:21:20 -0400 | [diff] [blame] | 6051 | shell, bind_shell) == NULL) |
Kristian Høgsberg | 4cca349 | 2011-01-18 07:53:49 -0500 | [diff] [blame] | 6052 | return -1; |
| 6053 | |
Kristian Høgsberg | 919cddb | 2013-07-08 19:03:57 -0400 | [diff] [blame] | 6054 | if (wl_global_create(ec->wl_display, |
| 6055 | &desktop_shell_interface, 2, |
| 6056 | shell, bind_desktop_shell) == NULL) |
Kristian Høgsberg | 7584062 | 2011-09-06 13:48:16 -0400 | [diff] [blame] | 6057 | return -1; |
| 6058 | |
Kristian Høgsberg | 919cddb | 2013-07-08 19:03:57 -0400 | [diff] [blame] | 6059 | if (wl_global_create(ec->wl_display, &screensaver_interface, 1, |
| 6060 | shell, bind_screensaver) == NULL) |
Pekka Paalanen | 6e16811 | 2011-11-24 11:34:05 +0200 | [diff] [blame] | 6061 | return -1; |
| 6062 | |
Kristian Høgsberg | 919cddb | 2013-07-08 19:03:57 -0400 | [diff] [blame] | 6063 | 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] | 6064 | shell, bind_input_panel) == NULL) |
| 6065 | return -1; |
| 6066 | |
Kristian Høgsberg | 919cddb | 2013-07-08 19:03:57 -0400 | [diff] [blame] | 6067 | if (wl_global_create(ec->wl_display, &workspace_manager_interface, 1, |
| 6068 | shell, bind_workspace_manager) == NULL) |
Jonas Ådahl | e9d2250 | 2012-08-29 22:13:01 +0200 | [diff] [blame] | 6069 | return -1; |
| 6070 | |
Kristian Høgsberg | f03a616 | 2012-01-17 11:07:42 -0500 | [diff] [blame] | 6071 | shell->child.deathstamp = weston_compositor_get_time(); |
Tiago Vignatti | b7dbbd6 | 2012-09-25 17:57:01 +0300 | [diff] [blame] | 6072 | |
Xiong Zhang | 6b48142 | 2013-10-23 13:58:32 +0800 | [diff] [blame] | 6073 | setup_output_destroy_handler(ec, shell); |
| 6074 | |
Tiago Vignatti | b7dbbd6 | 2012-09-25 17:57:01 +0300 | [diff] [blame] | 6075 | loop = wl_display_get_event_loop(ec->wl_display); |
| 6076 | wl_event_loop_add_idle(loop, launch_desktop_shell_process, shell); |
Pekka Paalanen | 6cd281a | 2011-11-03 14:11:32 +0200 | [diff] [blame] | 6077 | |
Ander Conselvan de Oliveira | 859e885 | 2013-02-21 18:35:21 +0200 | [diff] [blame] | 6078 | shell->screensaver.timer = |
| 6079 | wl_event_loop_add_timer(loop, screensaver_timeout, shell); |
| 6080 | |
Kristian Høgsberg | f4d2f23 | 2012-08-10 10:05:39 -0400 | [diff] [blame] | 6081 | wl_list_for_each(seat, &ec->seat_list, link) |
| 6082 | create_pointer_focus_listener(seat); |
Kristian Høgsberg | d56bd90 | 2012-06-05 09:58:51 -0400 | [diff] [blame] | 6083 | |
Tiago Vignatti | 0b52d48 | 2012-04-20 18:54:25 +0300 | [diff] [blame] | 6084 | shell_add_bindings(ec, shell); |
Kristian Høgsberg | 0793756 | 2011-04-12 17:25:42 -0400 | [diff] [blame] | 6085 | |
Pekka Paalanen | 79346ab | 2013-05-22 18:03:09 +0300 | [diff] [blame] | 6086 | shell_fade_init(shell); |
Ander Conselvan de Oliveira | 19d10ef | 2013-02-21 18:35:20 +0200 | [diff] [blame] | 6087 | |
Kristian Høgsberg | 4cca349 | 2011-01-18 07:53:49 -0500 | [diff] [blame] | 6088 | return 0; |
| 6089 | } |